pipedream-connect
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
The codebase is currently using:
- SDK Version: v1.6.8 (server) and v1.6.8 (browser)
- Client Creation:
createBackendClient()
andcreateFrontendClient()
- Method Calls: Old v1.x method names like
actionRun()
,deployTrigger()
, etc. - Deno.json: Already has v2.0.12 mapped but code still uses v1.6.8
Current (v1.x):
import { createBackendClient } from "npm:@pipedream/sdk@1.6.8/server";
export const pd = createBackendClient({
environment: Deno.env.get("PIPEDREAM_PROJECT_ENVIRONMENT") as
| "development"
| "production",
credentials: {
clientId: Deno.env.get("PIPEDREAM_CLIENT_ID") as string,
clientSecret: Deno.env.get("PIPEDREAM_CLIENT_SECRET") as string,
},
projectId: Deno.env.get("PIPEDREAM_PROJECT_ID"),
});
Needs to become (v2.x):
import { PipedreamClient } from "@pipedream/sdk";
export const pd = new PipedreamClient({
clientId: Deno.env.get("PIPEDREAM_CLIENT_ID"),
clientSecret: Deno.env.get("PIPEDREAM_CLIENT_SECRET"),
projectId: Deno.env.get("PIPEDREAM_PROJECT_ID"),
projectEnvironment: Deno.env.get("PIPEDREAM_PROJECT_ENVIRONMENT"),
});
Current (v1.x):
import { createFrontendClient } from "https://esm.sh/@pipedream/sdk@1.6.8/browser";
const frontendClient = createFrontendClient({
environment: "production",
externalUserId: effectiveUserId,
tokenCallback: async () => {
const resp = await fetch("/api/pipedream/token", {
method: "POST",
});
const data = await resp.json();
return data;
},
});
Needs to become (v2.x):
import { PipedreamClient } from "https://esm.sh/@pipedream/sdk@2.0.12/browser";
const frontendClient = new PipedreamClient({
tokenCallback: async ({ externalUserId }) => {
const resp = await fetch("/api/pipedream/token", {
method: "POST",
});
const data = await resp.json();
return data;
},
projectId: "your-project-id", // Add your project ID
projectEnvironment: "production",
});
Current (v1.x) | New (v2.x) |
---|---|
pd.createConnectToken() | pd.tokens.create() |
pd.actionRun() | pd.actions.run() |
pd.makeProxyRequest() | pd.proxy.post() (or appropriate HTTP method) |
pd.getAccountById() | pd.accounts.retrieve() |
pd.deleteAccount() | pd.accounts.delete() |
pd.deleteTrigger() | pd.deployedTriggers.delete() |
Current (v1.x) | New (v2.x) |
---|---|
pd.getTriggers() | pd.deployedTriggers.list() |
pd.getTrigger() | pd.deployedTriggers.retrieve() |
pd.getTriggerEvents() | pd.deployedTriggers.listEvents() |
pd.getAccounts() | pd.accounts.list() |
Current (v1.x) | New (v2.x) |
---|---|
frontendClient.actionRun() | frontendClient.actions.run() |
frontendClient.deployTrigger() | frontendClient.triggers.deploy() |
Change from snake_case to camelCase in TypeScript code:
Current | New |
---|---|
external_user_id | externalUserId |
include_credentials | includeCredentials |
action_id | id (for actions) |
trigger_id | id (for triggers) |
const result = await pd.makeProxyRequest(
{
searchParams: {
account_id: args.account_id,
external_user_id: getLatestUserID(user),
},
},
args.fetch,
);
const result = await pd.proxy.post({
accountId: args.account_id,
externalUserId: getLatestUserID(user),
url: args.fetch.url,
body: args.fetch.body,
headers: args.fetch.headers,
});
Remove the explicit version pinning from imports:
npm:@pipedream/sdk@1.6.8/server
→@pipedream/sdk
(uses deno.json mapping)https://esm.sh/@pipedream/sdk@1.6.8/browser
→https://esm.sh/@pipedream/sdk@2.0.12/browser
backend/pipedream.tsx
- Complete rewrite of client initialization and all method callsbackend/main.tsx
- Update all Pipedream method calls
frontend/pages/NewActionPage.tsx
- Update client creation andactionRun()
callfrontend/pages/NewTriggerPage.tsx
- Update client creation anddeployTrigger()
callfrontend/pages/NewConnectionPage.tsx
- Update client creation
sdk/sdk.ts
- This appears to be a wrapper function that calls your backend, so it might not need changes
The v2.x SDK supports automatic environment variable loading, so you could potentially simplify the client initialization to just:
export const pd = new PipedreamClient();
Consider updating error handling to use the new PipedreamError
type from v2.x
for better error management:
import { PipedreamError } from "@pipedream/sdk";
try {
// ... SDK calls
} catch (error) {
if (error instanceof PipedreamError) {
console.error("API Error:", error.status, error.message);
}
}
- Update import statements from
createBackendClient
/createFrontendClient
toPipedreamClient
- Update client initialization to use
new PipedreamClient()
for both server-side and browser-side - Convert all method calls to use namespaced format (e.g.,
client.actions.run()
) - Keep parameter names in camelCase in your TypeScript/JavaScript code (the SDK handles conversion to snake_case automatically)
- Pass
externalUserId
to methods instead of setting it on the client - Update error handling to use
PipedreamError
type - Review and implement new features like pagination and request options where beneficial
- Replace any usage of removed methods with their alternatives
- Update any code using
rawAccessToken()
- for server-side code, you can accessclient.rawAccessToken
as a getter property that returns a Promise - For raw response access, use
.withRawResponse()
method chaining instead of passingincludeRawResponse
option - Test all migrated code thoroughly
- Remove the old SDK dependency once migration is complete
- High Priority: Backend client initialization and core method calls
- Medium Priority: Frontend client updates
- Low Priority: Error handling improvements and environment variable simplification
- The migration is straightforward but requires updating method calls across multiple files
- The good news is that your
deno.json
already has the v2.0.12 mapping, so you just need to update the code to use the new API - The v2.x SDK includes several new features not available in v1.x:
- Full TypeScript support
- Pagination support
- Enhanced error handling
- Request options
- Abort signals
- Raw response access