@zapier/zapier-sdk 0.76.2 โ†’ 0.77.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @zapier/zapier-sdk
2
2
 
3
+ ## 0.77.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 19303e0: `triggerWorkflow` (and `trigger-workflow`) now authenticates with Zapier credentials and runs the workflow as the authenticated account; triggering is limited to workflows that account can access. It now returns the trigger's `id`, `workflow_id`, and `created_at` on `data` (previously `{ workflow, status, body }`). The call is unchanged: pass the workflow id and optional `input`.
8
+
3
9
  ## 0.76.2
4
10
 
5
11
  ### Patch Changes
package/README.md CHANGED
@@ -1744,7 +1744,7 @@ const result = await zapier.runDurable({
1744
1744
 
1745
1745
  #### `triggerWorkflow` ๐Ÿงช _experimental_
1746
1746
 
1747
- Look up a workflow's trigger URL and fire it manually. The trigger endpoint is tokenized (the URL contains a secret) and takes no auth header, so the SDK uses a raw fetch rather than the api plugin.
1747
+ Look up a workflow's trigger URL and fire it manually, as the authenticated account.
1748
1748
 
1749
1749
  **Parameters:**
1750
1750
 
@@ -1756,12 +1756,12 @@ Look up a workflow's trigger URL and fire it manually. The trigger endpoint is t
1756
1756
 
1757
1757
  **Returns:** `Promise<WorkflowRunItem>`
1758
1758
 
1759
- | Name | Type | Required | Possible Values | Description |
1760
- | -------------- | --------- | -------- | --------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
1761
- | `data` | `object` | โœ… | โ€” | |
1762
- | โ€‹ย โ†ณย `workflow` | `string` | โœ… | โ€” | The workflow ID that was triggered |
1763
- | โ€‹ย โ†ณย `status` | `number` | โœ… | โ€” | HTTP status returned by the trigger endpoint |
1764
- | โ€‹ย โ†ณย `body` | `unknown` | โœ… | โ€” | Response body from the trigger endpoint. Parsed as JSON when the response body parses, otherwise returned as the raw response text. |
1759
+ | Name | Type | Required | Possible Values | Description |
1760
+ | ----------------- | -------- | -------- | --------------- | ---------------------------------------- |
1761
+ | `data` | `object` | โœ… | โ€” | |
1762
+ | โ€‹ย โ†ณย `id` | `string` | โœ… | โ€” | Trigger ID (UUID) |
1763
+ | โ€‹ย โ†ณย `workflow_id` | `string` | โœ… | โ€” | The workflow that was triggered (UUID) |
1764
+ | โ€‹ย โ†ณย `created_at` | `string` | โœ… | โ€” | When the trigger was received (ISO-8601) |
1765
1765
 
1766
1766
  **Example:**
1767
1767
 
@@ -3403,7 +3403,7 @@ function parseApprovalReviewStreamPayload(parsed, toolNames) {
3403
3403
  }
3404
3404
 
3405
3405
  // src/sdk-version.ts
3406
- var SDK_VERSION = (typeof process !== "undefined" && process.env ? "0.76.2" : void 0) || "unknown";
3406
+ var SDK_VERSION = (typeof process !== "undefined" && process.env ? "0.77.0" : void 0) || "unknown";
3407
3407
 
3408
3408
  // src/utils/open-url.ts
3409
3409
  var nodePrefix = "node:";
@@ -13099,14 +13099,12 @@ var TriggerWorkflowOptionsSchema = zod.z.object({
13099
13099
  "JSON payload delivered as the trigger body. Sent as `application/json`; omit to fire with an empty body."
13100
13100
  )
13101
13101
  }).describe(
13102
- "Look up a workflow's trigger URL and fire it manually. The trigger endpoint is tokenized (the URL contains a secret) and takes no auth header, so the SDK uses a raw fetch rather than the api plugin."
13102
+ "Look up a workflow's trigger URL and fire it manually, as the authenticated account."
13103
13103
  );
13104
13104
  var TriggerWorkflowResponseSchema = zod.z.object({
13105
- workflow: zod.z.string().describe("The workflow ID that was triggered"),
13106
- status: zod.z.number().int().describe("HTTP status returned by the trigger endpoint"),
13107
- body: zod.z.unknown().describe(
13108
- "Response body from the trigger endpoint. Parsed as JSON when the response body parses, otherwise returned as the raw response text."
13109
- )
13105
+ id: zod.z.string().describe("Trigger ID (UUID)"),
13106
+ workflow_id: zod.z.string().describe("The workflow that was triggered (UUID)"),
13107
+ created_at: zod.z.string().describe("When the trigger was received (ISO-8601)")
13110
13108
  });
13111
13109
 
13112
13110
  // src/plugins/codeSubstrate/triggerWorkflow/index.ts
@@ -13128,32 +13126,23 @@ var triggerWorkflowPlugin = definePlugin(
13128
13126
  }
13129
13127
  );
13130
13128
  const workflow = TriggerWorkflowLookupResponseSchema.parse(rawWorkflow);
13131
- const fetch2 = sdk2.context.options.fetch ?? globalThis.fetch;
13132
- const response = await fetch2(workflow.trigger_url, {
13133
- method: "POST",
13134
- headers: { "Content-Type": "application/json" },
13135
- body: options.input === void 0 ? void 0 : JSON.stringify(options.input)
13136
- });
13137
- const text = await response.text().catch(() => "");
13138
- let body = text;
13139
- if (text) {
13140
- try {
13141
- body = JSON.parse(text);
13142
- } catch {
13143
- body = text;
13144
- }
13145
- }
13146
- if (!response.ok) {
13129
+ const segments = new URL(workflow.trigger_url).pathname.split("/");
13130
+ const triggerToken = segments[segments.length - 1];
13131
+ if (!triggerToken) {
13147
13132
  throw new ZapierApiError(
13148
- `Trigger failed: ${response.status} ${response.statusText}: ${text || "(empty body)"}`,
13149
- { statusCode: response.status, response: body }
13133
+ `Workflow ${options.workflow} returned a malformed trigger_url`,
13134
+ { statusCode: 0, response: workflow.trigger_url }
13150
13135
  );
13151
13136
  }
13152
- const data = {
13153
- workflow: options.workflow,
13154
- status: response.status,
13155
- body
13156
- };
13137
+ const raw = await sdk2.context.api.post(
13138
+ `/durableworkflowzaps/api/v0/workflows/trigger/${encodeURIComponent(triggerToken)}`,
13139
+ options.input,
13140
+ {
13141
+ authRequired: true,
13142
+ resource: { type: "workflow", id: options.workflow }
13143
+ }
13144
+ );
13145
+ const data = TriggerWorkflowResponseSchema.parse(raw);
13157
13146
  return { data };
13158
13147
  }
13159
13148
  })
@@ -3162,9 +3162,9 @@ declare function createZapierSdkStack(options?: ZapierSdkOptions): PluginStack<o
3162
3162
  input?: unknown;
3163
3163
  } | undefined) => Promise<{
3164
3164
  data: {
3165
- workflow: string;
3166
- status: number;
3167
- body: unknown;
3165
+ id: string;
3166
+ workflow_id: string;
3167
+ created_at: string;
3168
3168
  };
3169
3169
  }>;
3170
3170
  } & {
@@ -6365,9 +6365,9 @@ declare function createZapierSdk(options?: ZapierSdkOptions): WithAddPlugin<obje
6365
6365
  input?: unknown;
6366
6366
  } | undefined) => Promise<{
6367
6367
  data: {
6368
- workflow: string;
6369
- status: number;
6370
- body: unknown;
6368
+ id: string;
6369
+ workflow_id: string;
6370
+ created_at: string;
6371
6371
  };
6372
6372
  }>;
6373
6373
  } & {
@@ -3177,9 +3177,9 @@ export declare function createZapierSdkStack(options?: ZapierSdkOptions): import
3177
3177
  input?: unknown;
3178
3178
  } | undefined) => Promise<{
3179
3179
  data: {
3180
- workflow: string;
3181
- status: number;
3182
- body: unknown;
3180
+ id: string;
3181
+ workflow_id: string;
3182
+ created_at: string;
3183
3183
  };
3184
3184
  }>;
3185
3185
  } & {
@@ -6380,9 +6380,9 @@ export declare function createZapierSdk(options?: ZapierSdkOptions): import("kit
6380
6380
  input?: unknown;
6381
6381
  } | undefined) => Promise<{
6382
6382
  data: {
6383
- workflow: string;
6384
- status: number;
6385
- body: unknown;
6383
+ id: string;
6384
+ workflow_id: string;
6385
+ created_at: string;
6386
6386
  };
6387
6387
  }>;
6388
6388
  } & {
@@ -3401,7 +3401,7 @@ function parseApprovalReviewStreamPayload(parsed, toolNames) {
3401
3401
  }
3402
3402
 
3403
3403
  // src/sdk-version.ts
3404
- var SDK_VERSION = (typeof process !== "undefined" && process.env ? "0.76.2" : void 0) || "unknown";
3404
+ var SDK_VERSION = (typeof process !== "undefined" && process.env ? "0.77.0" : void 0) || "unknown";
3405
3405
 
3406
3406
  // src/utils/open-url.ts
3407
3407
  var nodePrefix = "node:";
@@ -13097,14 +13097,12 @@ var TriggerWorkflowOptionsSchema = z.object({
13097
13097
  "JSON payload delivered as the trigger body. Sent as `application/json`; omit to fire with an empty body."
13098
13098
  )
13099
13099
  }).describe(
13100
- "Look up a workflow's trigger URL and fire it manually. The trigger endpoint is tokenized (the URL contains a secret) and takes no auth header, so the SDK uses a raw fetch rather than the api plugin."
13100
+ "Look up a workflow's trigger URL and fire it manually, as the authenticated account."
13101
13101
  );
13102
13102
  var TriggerWorkflowResponseSchema = z.object({
13103
- workflow: z.string().describe("The workflow ID that was triggered"),
13104
- status: z.number().int().describe("HTTP status returned by the trigger endpoint"),
13105
- body: z.unknown().describe(
13106
- "Response body from the trigger endpoint. Parsed as JSON when the response body parses, otherwise returned as the raw response text."
13107
- )
13103
+ id: z.string().describe("Trigger ID (UUID)"),
13104
+ workflow_id: z.string().describe("The workflow that was triggered (UUID)"),
13105
+ created_at: z.string().describe("When the trigger was received (ISO-8601)")
13108
13106
  });
13109
13107
 
13110
13108
  // src/plugins/codeSubstrate/triggerWorkflow/index.ts
@@ -13126,32 +13124,23 @@ var triggerWorkflowPlugin = definePlugin(
13126
13124
  }
13127
13125
  );
13128
13126
  const workflow = TriggerWorkflowLookupResponseSchema.parse(rawWorkflow);
13129
- const fetch2 = sdk2.context.options.fetch ?? globalThis.fetch;
13130
- const response = await fetch2(workflow.trigger_url, {
13131
- method: "POST",
13132
- headers: { "Content-Type": "application/json" },
13133
- body: options.input === void 0 ? void 0 : JSON.stringify(options.input)
13134
- });
13135
- const text = await response.text().catch(() => "");
13136
- let body = text;
13137
- if (text) {
13138
- try {
13139
- body = JSON.parse(text);
13140
- } catch {
13141
- body = text;
13142
- }
13143
- }
13144
- if (!response.ok) {
13127
+ const segments = new URL(workflow.trigger_url).pathname.split("/");
13128
+ const triggerToken = segments[segments.length - 1];
13129
+ if (!triggerToken) {
13145
13130
  throw new ZapierApiError(
13146
- `Trigger failed: ${response.status} ${response.statusText}: ${text || "(empty body)"}`,
13147
- { statusCode: response.status, response: body }
13131
+ `Workflow ${options.workflow} returned a malformed trigger_url`,
13132
+ { statusCode: 0, response: workflow.trigger_url }
13148
13133
  );
13149
13134
  }
13150
- const data = {
13151
- workflow: options.workflow,
13152
- status: response.status,
13153
- body
13154
- };
13135
+ const raw = await sdk2.context.api.post(
13136
+ `/durableworkflowzaps/api/v0/workflows/trigger/${encodeURIComponent(triggerToken)}`,
13137
+ options.input,
13138
+ {
13139
+ authRequired: true,
13140
+ resource: { type: "workflow", id: options.workflow }
13141
+ }
13142
+ );
13143
+ const data = TriggerWorkflowResponseSchema.parse(raw);
13155
13144
  return { data };
13156
13145
  }
13157
13146
  })
package/dist/index.cjs CHANGED
@@ -6996,7 +6996,7 @@ function parseApprovalReviewStreamPayload(parsed, toolNames) {
6996
6996
  }
6997
6997
 
6998
6998
  // src/sdk-version.ts
6999
- var SDK_VERSION = (typeof process !== "undefined" && process.env ? "0.76.2" : void 0) || "unknown";
6999
+ var SDK_VERSION = (typeof process !== "undefined" && process.env ? "0.77.0" : void 0) || "unknown";
7000
7000
 
7001
7001
  // src/utils/open-url.ts
7002
7002
  var nodePrefix = "node:";
package/dist/index.mjs CHANGED
@@ -6994,7 +6994,7 @@ function parseApprovalReviewStreamPayload(parsed, toolNames) {
6994
6994
  }
6995
6995
 
6996
6996
  // src/sdk-version.ts
6997
- var SDK_VERSION = (typeof process !== "undefined" && process.env ? "0.76.2" : void 0) || "unknown";
6997
+ var SDK_VERSION = (typeof process !== "undefined" && process.env ? "0.77.0" : void 0) || "unknown";
6998
6998
 
6999
6999
  // src/utils/open-url.ts
7000
7000
  var nodePrefix = "node:";
@@ -52,12 +52,6 @@ export declare const triggerWorkflowPlugin: (sdk: {
52
52
  listWorkflows: import("kitcore").PluginMeta<unknown>;
53
53
  };
54
54
  };
55
- } & {
56
- context: {
57
- options: {
58
- fetch?: typeof globalThis.fetch;
59
- };
60
- };
61
55
  } & {
62
56
  context: {
63
57
  meta: Record<string, import("kitcore").PluginMeta>;
@@ -68,9 +62,9 @@ export declare const triggerWorkflowPlugin: (sdk: {
68
62
  input?: unknown;
69
63
  } | undefined) => Promise<{
70
64
  data: {
71
- workflow: string;
72
- status: number;
73
- body: unknown;
65
+ id: string;
66
+ workflow_id: string;
67
+ created_at: string;
74
68
  };
75
69
  }>;
76
70
  } & {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/codeSubstrate/triggerWorkflow/index.ts"],"names":[],"mappings":"AAcA,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aAKjB;QAAE,OAAO,EAAE;YAAE,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAA;SAAE,CAAA;KAAE;;;;;;;;;;;;;;;;;;;;;;CA4DhE,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG,UAAU,CACpD,OAAO,qBAAqB,CAC7B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/codeSubstrate/triggerWorkflow/index.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoDjC,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG,UAAU,CACpD,OAAO,qBAAqB,CAC7B,CAAC"}
@@ -12,41 +12,29 @@ export const triggerWorkflowPlugin = definePlugin((sdk) => createPluginMethod(sd
12
12
  outputSchema: TriggerWorkflowResponseSchema,
13
13
  resolvers: { workflow: workflowIdResolver },
14
14
  handler: async ({ sdk, options }) => {
15
- // Two-step: get the workflow's trigger_url via sdk.context.api
16
- // (authenticated), then POST the payload to that URL with no
17
- // auth header โ€” the URL itself embeds a secret token. Custom
18
- // fetch (e.g. tests) flows through sdk.context.options.fetch.
15
+ // Two-step: get the workflow's trigger_url, then fire it. Both go
16
+ // through the authenticated api client.
19
17
  const rawWorkflow = await sdk.context.api.get(`/durableworkflowzaps/api/v0/workflows/${encodeURIComponent(options.workflow)}`, {
20
18
  authRequired: true,
21
19
  resource: { type: "workflow", id: options.workflow },
22
20
  });
23
21
  const workflow = TriggerWorkflowLookupResponseSchema.parse(rawWorkflow);
24
- const fetch = sdk.context.options.fetch ?? globalThis.fetch;
25
- const response = await fetch(workflow.trigger_url, {
26
- method: "POST",
27
- headers: { "Content-Type": "application/json" },
28
- body: options.input === undefined
29
- ? undefined
30
- : JSON.stringify(options.input),
31
- });
32
- const text = await response.text().catch(() => "");
33
- let body = text;
34
- if (text) {
35
- try {
36
- body = JSON.parse(text);
37
- }
38
- catch {
39
- body = text;
40
- }
41
- }
42
- if (!response.ok) {
43
- throw new ZapierApiError(`Trigger failed: ${response.status} ${response.statusText}: ${text || "(empty body)"}`, { statusCode: response.status, response: body });
22
+ // trigger_url is an absolute URL. Take only the token (its last path
23
+ // segment) and rebuild the gateway path so the call routes through the
24
+ // authenticated proxy, the same as every other call here.
25
+ const segments = new URL(workflow.trigger_url).pathname.split("/");
26
+ const triggerToken = segments[segments.length - 1];
27
+ if (!triggerToken) {
28
+ throw new ZapierApiError(`Workflow ${options.workflow} returned a malformed trigger_url`, { statusCode: 0, response: workflow.trigger_url });
44
29
  }
45
- const data = {
46
- workflow: options.workflow,
47
- status: response.status,
48
- body,
49
- };
30
+ // Fire the trigger through the authenticated api client and return its
31
+ // response directly, the same as every other code-substrate method.
32
+ // api.post throws the SDK's typed errors on non-2xx.
33
+ const raw = await sdk.context.api.post(`/durableworkflowzaps/api/v0/workflows/trigger/${encodeURIComponent(triggerToken)}`, options.input, {
34
+ authRequired: true,
35
+ resource: { type: "workflow", id: options.workflow },
36
+ });
37
+ const data = TriggerWorkflowResponseSchema.parse(raw);
50
38
  return { data };
51
39
  },
52
40
  }));
@@ -8,9 +8,9 @@ export declare const TriggerWorkflowOptionsSchema: z.ZodObject<{
8
8
  }, z.core.$strip>;
9
9
  export type TriggerWorkflowOptions = z.infer<typeof TriggerWorkflowOptionsSchema>;
10
10
  export declare const TriggerWorkflowResponseSchema: z.ZodObject<{
11
- workflow: z.ZodString;
12
- status: z.ZodNumber;
13
- body: z.ZodUnknown;
11
+ id: z.ZodString;
12
+ workflow_id: z.ZodString;
13
+ created_at: z.ZodString;
14
14
  }, z.core.$strip>;
15
15
  export type TriggerWorkflowResponse = z.infer<typeof TriggerWorkflowResponseSchema>;
16
16
  //# sourceMappingURL=schemas.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../../src/plugins/codeSubstrate/triggerWorkflow/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAQxB,eAAO,MAAM,mCAAmC;;iBAIhC,CAAC;AAEjB,eAAO,MAAM,4BAA4B;;;iBAYtC,CAAC;AAEJ,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAC1C,OAAO,4BAA4B,CACpC,CAAC;AAEF,eAAO,MAAM,6BAA6B;;;;iBAWxC,CAAC;AAEH,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAC3C,OAAO,6BAA6B,CACrC,CAAC"}
1
+ {"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../../src/plugins/codeSubstrate/triggerWorkflow/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAQxB,eAAO,MAAM,mCAAmC;;iBAIhC,CAAC;AAEjB,eAAO,MAAM,4BAA4B;;;iBAYtC,CAAC;AAEJ,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAC1C,OAAO,4BAA4B,CACpC,CAAC;AAEF,eAAO,MAAM,6BAA6B;;;;iBAIxC,CAAC;AAEH,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAC3C,OAAO,6BAA6B,CACrC,CAAC"}
@@ -18,14 +18,9 @@ export const TriggerWorkflowOptionsSchema = z
18
18
  .optional()
19
19
  .describe("JSON payload delivered as the trigger body. Sent as `application/json`; omit to fire with an empty body."),
20
20
  })
21
- .describe("Look up a workflow's trigger URL and fire it manually. The trigger endpoint is tokenized (the URL contains a secret) and takes no auth header, so the SDK uses a raw fetch rather than the api plugin.");
21
+ .describe("Look up a workflow's trigger URL and fire it manually, as the authenticated account.");
22
22
  export const TriggerWorkflowResponseSchema = z.object({
23
- workflow: z.string().describe("The workflow ID that was triggered"),
24
- status: z
25
- .number()
26
- .int()
27
- .describe("HTTP status returned by the trigger endpoint"),
28
- body: z
29
- .unknown()
30
- .describe("Response body from the trigger endpoint. Parsed as JSON when the response body parses, otherwise returned as the raw response text."),
23
+ id: z.string().describe("Trigger ID (UUID)"),
24
+ workflow_id: z.string().describe("The workflow that was triggered (UUID)"),
25
+ created_at: z.string().describe("When the trigger was received (ISO-8601)"),
31
26
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zapier/zapier-sdk",
3
- "version": "0.76.2",
3
+ "version": "0.77.0",
4
4
  "description": "Complete Zapier SDK - combines all Zapier SDK packages",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",