@zapier/zapier-sdk 0.24.0 → 0.25.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 +6 -0
- package/README.md +18 -16
- package/dist/api/polling.d.ts +7 -0
- package/dist/api/polling.d.ts.map +1 -1
- package/dist/api/polling.js +21 -19
- package/dist/api/polling.test.js +43 -1
- package/dist/constants.d.ts +4 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +4 -0
- package/dist/index.cjs +40 -25
- package/dist/index.d.mts +9 -1
- package/dist/index.mjs +39 -26
- package/dist/plugins/apps/index.d.ts.map +1 -1
- package/dist/plugins/apps/index.js +2 -1
- package/dist/plugins/apps/schemas.d.ts +1 -0
- package/dist/plugins/apps/schemas.d.ts.map +1 -1
- package/dist/plugins/apps/schemas.js +2 -1
- package/dist/plugins/runAction/index.d.ts.map +1 -1
- package/dist/plugins/runAction/index.js +5 -3
- package/dist/plugins/runAction/index.test.js +16 -0
- package/dist/plugins/runAction/schemas.d.ts +1 -0
- package/dist/plugins/runAction/schemas.d.ts.map +1 -1
- package/dist/plugins/runAction/schemas.js +2 -1
- package/dist/types/properties.d.ts +2 -0
- package/dist/types/properties.d.ts.map +1 -1
- package/dist/types/properties.js +6 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -453,17 +453,18 @@ Execute an action with the given inputs
|
|
|
453
453
|
|
|
454
454
|
**Parameters:**
|
|
455
455
|
|
|
456
|
-
| Name | Type | Required | Default | Possible Values | Description
|
|
457
|
-
| -------------------- | ---------------- | -------- | ------- | ---------------------------------------------------------------------------------------------- |
|
|
458
|
-
| `options` | `object` | ✅ | — | — |
|
|
459
|
-
| ↳ `appKey` | `string` | ✅ | — | — | App key (e.g., 'SlackCLIAPI' or slug like 'github')
|
|
460
|
-
| ↳ `actionType` | `string` | ✅ | — | `read`, `read_bulk`, `write`, `run`, `search`, `search_or_write`, `search_and_write`, `filter` | Action type that matches the action's defined type
|
|
461
|
-
| ↳ `actionKey` | `string` | ✅ | — | — | Action key to execute
|
|
462
|
-
| ↳ `authenticationId` | `string, number` | ❌ | — | — | Authentication ID to use for this action
|
|
463
|
-
| ↳ `inputs` | `object` | ❌ | — | — | Input parameters for the action
|
|
464
|
-
| ↳ `
|
|
465
|
-
| ↳ `
|
|
466
|
-
| ↳ `
|
|
456
|
+
| Name | Type | Required | Default | Possible Values | Description |
|
|
457
|
+
| -------------------- | ---------------- | -------- | ------- | ---------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
|
|
458
|
+
| `options` | `object` | ✅ | — | — | |
|
|
459
|
+
| ↳ `appKey` | `string` | ✅ | — | — | App key (e.g., 'SlackCLIAPI' or slug like 'github') |
|
|
460
|
+
| ↳ `actionType` | `string` | ✅ | — | `read`, `read_bulk`, `write`, `run`, `search`, `search_or_write`, `search_and_write`, `filter` | Action type that matches the action's defined type |
|
|
461
|
+
| ↳ `actionKey` | `string` | ✅ | — | — | Action key to execute |
|
|
462
|
+
| ↳ `authenticationId` | `string, number` | ❌ | — | — | Authentication ID to use for this action |
|
|
463
|
+
| ↳ `inputs` | `object` | ❌ | — | — | Input parameters for the action |
|
|
464
|
+
| ↳ `timeoutMs` | `number` | ❌ | — | — | Maximum time to wait for action completion in milliseconds (default: 180000) |
|
|
465
|
+
| ↳ `pageSize` | `number` | ❌ | — | — | Number of results per page |
|
|
466
|
+
| ↳ `maxItems` | `number` | ❌ | — | — | Maximum total items to return across all pages |
|
|
467
|
+
| ↳ `cursor` | `string` | ❌ | — | — | Cursor to start from |
|
|
467
468
|
|
|
468
469
|
**Returns:** `Promise<PaginatedResult<ActionResultItem>>`
|
|
469
470
|
|
|
@@ -527,11 +528,12 @@ Execute an action with the given inputs for the bound app, as an alternative to
|
|
|
527
528
|
|
|
528
529
|
**Parameters:**
|
|
529
530
|
|
|
530
|
-
| Name | Type | Required | Default | Possible Values | Description
|
|
531
|
-
| -------------------- | ---------------- | -------- | ------- | --------------- |
|
|
532
|
-
| `options` | `object` | ✅ | — | — |
|
|
533
|
-
| ↳ `inputs` | `object` | ❌ | — | — |
|
|
534
|
-
| ↳ `authenticationId` | `string, number` | ❌ | — | — | Authentication ID to use for this action
|
|
531
|
+
| Name | Type | Required | Default | Possible Values | Description |
|
|
532
|
+
| -------------------- | ---------------- | -------- | ------- | --------------- | ---------------------------------------------------------------------------- |
|
|
533
|
+
| `options` | `object` | ✅ | — | — | |
|
|
534
|
+
| ↳ `inputs` | `object` | ❌ | — | — | |
|
|
535
|
+
| ↳ `authenticationId` | `string, number` | ❌ | — | — | Authentication ID to use for this action |
|
|
536
|
+
| ↳ `timeoutMs` | `number` | ❌ | — | — | Maximum time to wait for action completion in milliseconds (default: 180000) |
|
|
535
537
|
|
|
536
538
|
**Returns:** `Promise<PaginatedResult<ActionResultItem>>`
|
|
537
539
|
|
package/dist/api/polling.d.ts
CHANGED
|
@@ -4,6 +4,13 @@
|
|
|
4
4
|
* This module provides utilities for polling HTTP endpoints until completion,
|
|
5
5
|
* with configurable retry logic and exponential backoff.
|
|
6
6
|
*/
|
|
7
|
+
/**
|
|
8
|
+
* Get the appropriate polling interval based on elapsed time.
|
|
9
|
+
* Starts with frequent polling and backs off as time passes.
|
|
10
|
+
* @param elapsedMs Time elapsed since polling started (in milliseconds)
|
|
11
|
+
* @returns The polling interval to use (in milliseconds)
|
|
12
|
+
*/
|
|
13
|
+
export declare function getPollingInterval(elapsedMs: number): number;
|
|
7
14
|
/**
|
|
8
15
|
* Options for the polling function
|
|
9
16
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"polling.d.ts","sourceRoot":"","sources":["../../src/api/polling.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAgCH;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,OAAO,GAAG,OAAO;IAC5C,8CAA8C;IAC9C,SAAS,EAAE,MAAM,OAAO,CAAC,QAAQ,CAAC,CAAC;IACnC,4DAA4D;IAC5D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,wDAAwD;IACxD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iEAAiE;IACjE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,uGAAuG;IACvG,SAAS,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,OAAO,CAAC;IAC3C,uDAAuD;IACvD,eAAe,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,OAAO,CAAC;IACjD,oEAAoE;IACpE,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,mBAAW,UAAU;IACnB,OAAO,YAAY;IACnB,QAAQ,aAAa;CACtB;AAED;;GAEG;AACH,MAAM,MAAM,UAAU,CAAC,OAAO,GAAG,OAAO,IAAI;IAC1C,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,UAAU,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAgEF;;;;;;;GAOG;AACH,wBAAsB,iBAAiB,CAAC,OAAO,GAAG,OAAO,EACvD,OAAO,EAAE,WAAW,CAAC,OAAO,CAAC,GAC5B,OAAO,CAAC,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"polling.d.ts","sourceRoot":"","sources":["../../src/api/polling.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAgCH;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAG5D;AAED;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,OAAO,GAAG,OAAO;IAC5C,8CAA8C;IAC9C,SAAS,EAAE,MAAM,OAAO,CAAC,QAAQ,CAAC,CAAC;IACnC,4DAA4D;IAC5D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,wDAAwD;IACxD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iEAAiE;IACjE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,uGAAuG;IACvG,SAAS,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,OAAO,CAAC;IAC3C,uDAAuD;IACvD,eAAe,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,OAAO,CAAC;IACjD,oEAAoE;IACpE,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,mBAAW,UAAU;IACnB,OAAO,YAAY;IACnB,QAAQ,aAAa;CACtB;AAED;;GAEG;AACH,MAAM,MAAM,UAAU,CAAC,OAAO,GAAG,OAAO,IAAI;IAC1C,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,UAAU,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAgEF;;;;;;;GAOG;AACH,wBAAsB,iBAAiB,CAAC,OAAO,GAAG,OAAO,EACvD,OAAO,EAAE,WAAW,CAAC,OAAO,CAAC,GAC5B,OAAO,CAAC,OAAO,CAAC,CAgGlB"}
|
package/dist/api/polling.js
CHANGED
|
@@ -12,18 +12,28 @@ const DEFAULT_TIMEOUT_MS = 180000;
|
|
|
12
12
|
const DEFAULT_SUCCESS_STATUS = 200;
|
|
13
13
|
const DEFAULT_PENDING_STATUS = 202;
|
|
14
14
|
const DEFAULT_INITIAL_DELAY_MS = 50;
|
|
15
|
-
const DEFAULT_MAX_POLLING_INTERVAL_MS =
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
// Note: These are default stages, actual hard timeout is enforced separately below
|
|
19
|
-
const DEFAULT_POLLING_STAGES = [
|
|
15
|
+
const DEFAULT_MAX_POLLING_INTERVAL_MS = 60000;
|
|
16
|
+
// Polling stages: [elapsed_time_threshold_ms, poll_interval_ms]
|
|
17
|
+
const POLLING_STAGES = [
|
|
20
18
|
[125, 125], // Up to 125ms: poll every 125ms
|
|
21
19
|
[375, 250], // Up to 375ms: poll every 250ms
|
|
22
20
|
[875, 500], // Up to 875ms: poll every 500ms
|
|
23
21
|
[10000, 1000], // Up to 10s: poll every 1s
|
|
24
22
|
[30000, 2500], // Up to 30s: poll every 2.5s
|
|
25
23
|
[60000, 5000], // Up to 60s: poll every 5s
|
|
24
|
+
[180000, 10000], // Up to 3min: poll every 10s
|
|
25
|
+
// Beyond 3min: use DEFAULT_MAX_POLLING_INTERVAL_MS (60s)
|
|
26
26
|
];
|
|
27
|
+
/**
|
|
28
|
+
* Get the appropriate polling interval based on elapsed time.
|
|
29
|
+
* Starts with frequent polling and backs off as time passes.
|
|
30
|
+
* @param elapsedMs Time elapsed since polling started (in milliseconds)
|
|
31
|
+
* @returns The polling interval to use (in milliseconds)
|
|
32
|
+
*/
|
|
33
|
+
export function getPollingInterval(elapsedMs) {
|
|
34
|
+
const stage = POLLING_STAGES.find(([threshold]) => elapsedMs < threshold);
|
|
35
|
+
return stage ? stage[1] : DEFAULT_MAX_POLLING_INTERVAL_MS;
|
|
36
|
+
}
|
|
27
37
|
const processResponse = async (response, successStatus, pendingStatus, isPending, resultExtractor, errorCount) => {
|
|
28
38
|
// Handle other error responses
|
|
29
39
|
if (!response.ok) {
|
|
@@ -93,33 +103,25 @@ export async function pollUntilComplete(options) {
|
|
|
93
103
|
const startTime = Date.now();
|
|
94
104
|
let attempts = 0;
|
|
95
105
|
let errorCount = 0;
|
|
96
|
-
// Build polling stages with the actual timeout appended
|
|
97
|
-
const pollingStages = [
|
|
98
|
-
...DEFAULT_POLLING_STAGES,
|
|
99
|
-
[timeoutMs + MAX_TIMEOUT_BUFFER_MS, DEFAULT_MAX_POLLING_INTERVAL_MS], // Up to timeout + 10s: poll every 10s
|
|
100
|
-
];
|
|
101
106
|
// Apply initial delay if specified
|
|
102
107
|
if (initialDelay > 0) {
|
|
103
108
|
await setTimeout(initialDelay);
|
|
104
109
|
}
|
|
105
110
|
while (true) {
|
|
106
|
-
attempts++;
|
|
107
111
|
const elapsedTime = Date.now() - startTime;
|
|
108
|
-
//
|
|
109
|
-
|
|
110
|
-
return elapsedTime < maxTimeForStage;
|
|
111
|
-
});
|
|
112
|
-
// If there isn't a current stage, throw timeout error
|
|
113
|
-
if (!pollingInterval) {
|
|
112
|
+
// Check if we've exceeded the timeout
|
|
113
|
+
if (elapsedTime >= timeoutMs) {
|
|
114
114
|
throw new ZapierTimeoutError(`Operation timed out after ${Math.floor(elapsedTime / 1000)}s (${attempts} attempts)`, {
|
|
115
115
|
attempts,
|
|
116
116
|
});
|
|
117
117
|
}
|
|
118
118
|
// Wait before polling (except on first attempt)
|
|
119
|
-
if (attempts >
|
|
120
|
-
const
|
|
119
|
+
if (attempts > 0) {
|
|
120
|
+
const interval = getPollingInterval(elapsedTime);
|
|
121
|
+
const waitTime = calculateWaitTime(interval, errorCount);
|
|
121
122
|
await setTimeout(waitTime);
|
|
122
123
|
}
|
|
124
|
+
attempts++;
|
|
123
125
|
// Perform the poll request
|
|
124
126
|
try {
|
|
125
127
|
const response = await fetchPoll();
|
package/dist/api/polling.test.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
2
|
-
import { pollUntilComplete } from "./polling";
|
|
2
|
+
import { pollUntilComplete, getPollingInterval } from "./polling";
|
|
3
3
|
import { ZapierTimeoutError, ZapierApiError, ZapierValidationError, } from "../types/errors";
|
|
4
4
|
// Mock the timers/promises module
|
|
5
5
|
vi.mock("timers/promises", () => ({
|
|
@@ -316,3 +316,45 @@ describe("pollUntilComplete", () => {
|
|
|
316
316
|
});
|
|
317
317
|
});
|
|
318
318
|
});
|
|
319
|
+
describe("getPollingInterval", () => {
|
|
320
|
+
it("should return 125ms for elapsed time under 125ms", () => {
|
|
321
|
+
expect(getPollingInterval(0)).toBe(125);
|
|
322
|
+
expect(getPollingInterval(50)).toBe(125);
|
|
323
|
+
expect(getPollingInterval(124)).toBe(125);
|
|
324
|
+
});
|
|
325
|
+
it("should return 250ms for elapsed time 125-375ms", () => {
|
|
326
|
+
expect(getPollingInterval(125)).toBe(250);
|
|
327
|
+
expect(getPollingInterval(200)).toBe(250);
|
|
328
|
+
expect(getPollingInterval(374)).toBe(250);
|
|
329
|
+
});
|
|
330
|
+
it("should return 500ms for elapsed time 375-875ms", () => {
|
|
331
|
+
expect(getPollingInterval(375)).toBe(500);
|
|
332
|
+
expect(getPollingInterval(600)).toBe(500);
|
|
333
|
+
expect(getPollingInterval(874)).toBe(500);
|
|
334
|
+
});
|
|
335
|
+
it("should return 1000ms for elapsed time 875ms-10s", () => {
|
|
336
|
+
expect(getPollingInterval(875)).toBe(1000);
|
|
337
|
+
expect(getPollingInterval(5000)).toBe(1000);
|
|
338
|
+
expect(getPollingInterval(9999)).toBe(1000);
|
|
339
|
+
});
|
|
340
|
+
it("should return 2500ms for elapsed time 10s-30s", () => {
|
|
341
|
+
expect(getPollingInterval(10000)).toBe(2500);
|
|
342
|
+
expect(getPollingInterval(20000)).toBe(2500);
|
|
343
|
+
expect(getPollingInterval(29999)).toBe(2500);
|
|
344
|
+
});
|
|
345
|
+
it("should return 5000ms for elapsed time 30s-60s", () => {
|
|
346
|
+
expect(getPollingInterval(30000)).toBe(5000);
|
|
347
|
+
expect(getPollingInterval(45000)).toBe(5000);
|
|
348
|
+
expect(getPollingInterval(59999)).toBe(5000);
|
|
349
|
+
});
|
|
350
|
+
it("should return 10000ms for elapsed time 60s-180s", () => {
|
|
351
|
+
expect(getPollingInterval(60000)).toBe(10000);
|
|
352
|
+
expect(getPollingInterval(120000)).toBe(10000);
|
|
353
|
+
expect(getPollingInterval(179999)).toBe(10000);
|
|
354
|
+
});
|
|
355
|
+
it("should return 60000ms (max interval) for elapsed time beyond 180s", () => {
|
|
356
|
+
expect(getPollingInterval(180000)).toBe(60000);
|
|
357
|
+
expect(getPollingInterval(300000)).toBe(60000);
|
|
358
|
+
expect(getPollingInterval(600000)).toBe(60000);
|
|
359
|
+
});
|
|
360
|
+
});
|
package/dist/constants.d.ts
CHANGED
|
@@ -11,6 +11,10 @@ export declare const ZAPIER_BASE_URL: string;
|
|
|
11
11
|
* Maximum number of items that can be requested per page across all paginated functions
|
|
12
12
|
*/
|
|
13
13
|
export declare const MAX_PAGE_LIMIT = 10000;
|
|
14
|
+
/**
|
|
15
|
+
* Default timeout for action execution (in milliseconds)
|
|
16
|
+
*/
|
|
17
|
+
export declare const DEFAULT_ACTION_TIMEOUT_MS = 180000;
|
|
14
18
|
/**
|
|
15
19
|
* Credentials from environment variables
|
|
16
20
|
*/
|
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,eAAO,MAAM,eAAe,QACyB,CAAC;AAEtD;;GAEG;AACH,eAAO,MAAM,cAAc,QAAQ,CAAC;AAEpC;;GAEG;AACH,eAAO,MAAM,kBAAkB,oBAAiC,CAAC;AACjE,eAAO,MAAM,4BAA4B,oBACC,CAAC;AAC3C,eAAO,MAAM,gCAAgC,oBACC,CAAC;AAC/C,eAAO,MAAM,2BAA2B,oBACC,CAAC;AAC1C,eAAO,MAAM,wBAAwB,oBAAuC,CAAC;AAE7E;;GAEG;AACH,eAAO,MAAM,YAAY,oBAA2B,CAAC;AACrD,eAAO,MAAM,oBAAoB,oBAAmC,CAAC;AACrE,eAAO,MAAM,qBAAqB,oBAAoC,CAAC"}
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,eAAO,MAAM,eAAe,QACyB,CAAC;AAEtD;;GAEG;AACH,eAAO,MAAM,cAAc,QAAQ,CAAC;AAEpC;;GAEG;AACH,eAAO,MAAM,yBAAyB,SAAU,CAAC;AAEjD;;GAEG;AACH,eAAO,MAAM,kBAAkB,oBAAiC,CAAC;AACjE,eAAO,MAAM,4BAA4B,oBACC,CAAC;AAC3C,eAAO,MAAM,gCAAgC,oBACC,CAAC;AAC/C,eAAO,MAAM,2BAA2B,oBACC,CAAC;AAC1C,eAAO,MAAM,wBAAwB,oBAAuC,CAAC;AAE7E;;GAEG;AACH,eAAO,MAAM,YAAY,oBAA2B,CAAC;AACrD,eAAO,MAAM,oBAAoB,oBAAmC,CAAC;AACrE,eAAO,MAAM,qBAAqB,oBAAoC,CAAC"}
|
package/dist/constants.js
CHANGED
|
@@ -11,6 +11,10 @@ export const ZAPIER_BASE_URL = process.env.ZAPIER_BASE_URL || "https://zapier.co
|
|
|
11
11
|
* Maximum number of items that can be requested per page across all paginated functions
|
|
12
12
|
*/
|
|
13
13
|
export const MAX_PAGE_LIMIT = 10000;
|
|
14
|
+
/**
|
|
15
|
+
* Default timeout for action execution (in milliseconds)
|
|
16
|
+
*/
|
|
17
|
+
export const DEFAULT_ACTION_TIMEOUT_MS = 180000;
|
|
14
18
|
/**
|
|
15
19
|
* Credentials from environment variables
|
|
16
20
|
*/
|
package/dist/index.cjs
CHANGED
|
@@ -59,6 +59,7 @@ function isPositional(schema) {
|
|
|
59
59
|
// src/constants.ts
|
|
60
60
|
var ZAPIER_BASE_URL = process.env.ZAPIER_BASE_URL || "https://zapier.com";
|
|
61
61
|
var MAX_PAGE_LIMIT = 1e4;
|
|
62
|
+
var DEFAULT_ACTION_TIMEOUT_MS = 18e4;
|
|
62
63
|
var ZAPIER_CREDENTIALS = process.env.ZAPIER_CREDENTIALS;
|
|
63
64
|
var ZAPIER_CREDENTIALS_CLIENT_ID = process.env.ZAPIER_CREDENTIALS_CLIENT_ID;
|
|
64
65
|
var ZAPIER_CREDENTIALS_CLIENT_SECRET = process.env.ZAPIER_CREDENTIALS_CLIENT_SECRET;
|
|
@@ -90,6 +91,9 @@ var OffsetPropertySchema = zod.z.number().int().min(0).default(0).describe("Numb
|
|
|
90
91
|
var OutputPropertySchema = zod.z.string().describe("Output file path");
|
|
91
92
|
var DebugPropertySchema = zod.z.boolean().default(false).describe("Enable debug logging");
|
|
92
93
|
var ParamsPropertySchema = zod.z.record(zod.z.string(), zod.z.unknown()).describe("Additional parameters");
|
|
94
|
+
var ActionTimeoutMsPropertySchema = zod.z.number().min(1e3).optional().describe(
|
|
95
|
+
`Maximum time to wait for action completion in milliseconds (default: ${DEFAULT_ACTION_TIMEOUT_MS})`
|
|
96
|
+
);
|
|
93
97
|
|
|
94
98
|
// src/types/errors.ts
|
|
95
99
|
var ZapierError = class extends Error {
|
|
@@ -227,7 +231,8 @@ HTTP Status: ${error.statusCode}`;
|
|
|
227
231
|
}
|
|
228
232
|
var ActionExecutionInputSchema = zod.z.object({
|
|
229
233
|
inputs: zod.z.record(zod.z.string(), zod.z.unknown()).optional(),
|
|
230
|
-
authenticationId: AuthenticationIdPropertySchema.optional()
|
|
234
|
+
authenticationId: AuthenticationIdPropertySchema.optional(),
|
|
235
|
+
timeoutMs: ActionTimeoutMsPropertySchema
|
|
231
236
|
}).describe(
|
|
232
237
|
"Execute an action with the given inputs for the bound app, as an alternative to runAction"
|
|
233
238
|
);
|
|
@@ -264,7 +269,11 @@ var ActionResultItemSchema = withFormatter(
|
|
|
264
269
|
function createActionFunction(appKey, actionType, actionKey, options, pinnedAuthId) {
|
|
265
270
|
return (actionOptions = {}) => {
|
|
266
271
|
const { sdk } = options;
|
|
267
|
-
const {
|
|
272
|
+
const {
|
|
273
|
+
inputs,
|
|
274
|
+
authenticationId: providedAuthenticationId,
|
|
275
|
+
timeoutMs
|
|
276
|
+
} = actionOptions;
|
|
268
277
|
const authenticationId = pinnedAuthId ?? providedAuthenticationId;
|
|
269
278
|
if (!authenticationId) {
|
|
270
279
|
throw new ZapierValidationError(
|
|
@@ -276,7 +285,8 @@ function createActionFunction(appKey, actionType, actionKey, options, pinnedAuth
|
|
|
276
285
|
actionType,
|
|
277
286
|
actionKey,
|
|
278
287
|
inputs,
|
|
279
|
-
authenticationId
|
|
288
|
+
authenticationId,
|
|
289
|
+
timeoutMs
|
|
280
290
|
});
|
|
281
291
|
};
|
|
282
292
|
}
|
|
@@ -2731,6 +2741,7 @@ var RunActionSchema = zod.z.object({
|
|
|
2731
2741
|
inputs: InputsPropertySchema.optional().describe(
|
|
2732
2742
|
"Input parameters for the action"
|
|
2733
2743
|
),
|
|
2744
|
+
timeoutMs: ActionTimeoutMsPropertySchema,
|
|
2734
2745
|
pageSize: zod.z.number().min(1).optional().describe("Number of results per page"),
|
|
2735
2746
|
maxItems: zod.z.number().min(1).optional().describe("Maximum total items to return across all pages"),
|
|
2736
2747
|
cursor: zod.z.string().optional().describe("Cursor to start from")
|
|
@@ -2746,7 +2757,8 @@ async function executeAction(actionOptions) {
|
|
|
2746
2757
|
actionKey,
|
|
2747
2758
|
actionType,
|
|
2748
2759
|
executionOptions,
|
|
2749
|
-
authenticationId
|
|
2760
|
+
authenticationId,
|
|
2761
|
+
timeoutMs
|
|
2750
2762
|
} = actionOptions;
|
|
2751
2763
|
const selectedApi = await context.getVersionedImplementationId(appKey);
|
|
2752
2764
|
if (!selectedApi) {
|
|
@@ -2776,6 +2788,7 @@ async function executeAction(actionOptions) {
|
|
|
2776
2788
|
return await api.poll(`/zapier/api/actions/v1/runs/${runId}`, {
|
|
2777
2789
|
successStatus: 200,
|
|
2778
2790
|
pendingStatus: 202,
|
|
2791
|
+
timeoutMs: timeoutMs ?? DEFAULT_ACTION_TIMEOUT_MS,
|
|
2779
2792
|
isPending: (result) => {
|
|
2780
2793
|
const data = result?.data;
|
|
2781
2794
|
return data?.status === "waiting";
|
|
@@ -2791,7 +2804,8 @@ var runActionPlugin = ({ sdk, context }) => {
|
|
|
2791
2804
|
actionKey,
|
|
2792
2805
|
actionType,
|
|
2793
2806
|
authenticationId,
|
|
2794
|
-
inputs = {}
|
|
2807
|
+
inputs = {},
|
|
2808
|
+
timeoutMs
|
|
2795
2809
|
} = options;
|
|
2796
2810
|
const actionData = await sdk.getAction({
|
|
2797
2811
|
appKey,
|
|
@@ -2815,7 +2829,9 @@ var runActionPlugin = ({ sdk, context }) => {
|
|
|
2815
2829
|
actionKey,
|
|
2816
2830
|
actionType,
|
|
2817
2831
|
executionOptions: { inputs },
|
|
2818
|
-
authenticationId
|
|
2832
|
+
authenticationId,
|
|
2833
|
+
timeoutMs
|
|
2834
|
+
});
|
|
2819
2835
|
if (result.errors && result.errors.length > 0) {
|
|
2820
2836
|
const errorMessage = result.errors.map(
|
|
2821
2837
|
(error) => error.detail || error.title || "Unknown error"
|
|
@@ -3634,9 +3650,8 @@ var DEFAULT_TIMEOUT_MS = 18e4;
|
|
|
3634
3650
|
var DEFAULT_SUCCESS_STATUS = 200;
|
|
3635
3651
|
var DEFAULT_PENDING_STATUS = 202;
|
|
3636
3652
|
var DEFAULT_INITIAL_DELAY_MS = 50;
|
|
3637
|
-
var DEFAULT_MAX_POLLING_INTERVAL_MS =
|
|
3638
|
-
var
|
|
3639
|
-
var DEFAULT_POLLING_STAGES = [
|
|
3653
|
+
var DEFAULT_MAX_POLLING_INTERVAL_MS = 6e4;
|
|
3654
|
+
var POLLING_STAGES = [
|
|
3640
3655
|
[125, 125],
|
|
3641
3656
|
// Up to 125ms: poll every 125ms
|
|
3642
3657
|
[375, 250],
|
|
@@ -3647,9 +3662,16 @@ var DEFAULT_POLLING_STAGES = [
|
|
|
3647
3662
|
// Up to 10s: poll every 1s
|
|
3648
3663
|
[3e4, 2500],
|
|
3649
3664
|
// Up to 30s: poll every 2.5s
|
|
3650
|
-
[6e4, 5e3]
|
|
3665
|
+
[6e4, 5e3],
|
|
3651
3666
|
// Up to 60s: poll every 5s
|
|
3667
|
+
[18e4, 1e4]
|
|
3668
|
+
// Up to 3min: poll every 10s
|
|
3669
|
+
// Beyond 3min: use DEFAULT_MAX_POLLING_INTERVAL_MS (60s)
|
|
3652
3670
|
];
|
|
3671
|
+
function getPollingInterval(elapsedMs) {
|
|
3672
|
+
const stage = POLLING_STAGES.find(([threshold]) => elapsedMs < threshold);
|
|
3673
|
+
return stage ? stage[1] : DEFAULT_MAX_POLLING_INTERVAL_MS;
|
|
3674
|
+
}
|
|
3653
3675
|
var processResponse = async (response, successStatus, pendingStatus, isPending, resultExtractor, errorCount) => {
|
|
3654
3676
|
if (!response.ok) {
|
|
3655
3677
|
return {
|
|
@@ -3718,23 +3740,12 @@ async function pollUntilComplete(options) {
|
|
|
3718
3740
|
const startTime = Date.now();
|
|
3719
3741
|
let attempts = 0;
|
|
3720
3742
|
let errorCount = 0;
|
|
3721
|
-
const pollingStages = [
|
|
3722
|
-
...DEFAULT_POLLING_STAGES,
|
|
3723
|
-
[timeoutMs + MAX_TIMEOUT_BUFFER_MS, DEFAULT_MAX_POLLING_INTERVAL_MS]
|
|
3724
|
-
// Up to timeout + 10s: poll every 10s
|
|
3725
|
-
];
|
|
3726
3743
|
if (initialDelay > 0) {
|
|
3727
3744
|
await promises.setTimeout(initialDelay);
|
|
3728
3745
|
}
|
|
3729
3746
|
while (true) {
|
|
3730
|
-
attempts++;
|
|
3731
3747
|
const elapsedTime = Date.now() - startTime;
|
|
3732
|
-
|
|
3733
|
-
([maxTimeForStage, _interval]) => {
|
|
3734
|
-
return elapsedTime < maxTimeForStage;
|
|
3735
|
-
}
|
|
3736
|
-
);
|
|
3737
|
-
if (!pollingInterval) {
|
|
3748
|
+
if (elapsedTime >= timeoutMs) {
|
|
3738
3749
|
throw new ZapierTimeoutError(
|
|
3739
3750
|
`Operation timed out after ${Math.floor(elapsedTime / 1e3)}s (${attempts} attempts)`,
|
|
3740
3751
|
{
|
|
@@ -3742,10 +3753,12 @@ async function pollUntilComplete(options) {
|
|
|
3742
3753
|
}
|
|
3743
3754
|
);
|
|
3744
3755
|
}
|
|
3745
|
-
if (attempts >
|
|
3746
|
-
const
|
|
3756
|
+
if (attempts > 0) {
|
|
3757
|
+
const interval = getPollingInterval(elapsedTime);
|
|
3758
|
+
const waitTime = calculateWaitTime(interval, errorCount);
|
|
3747
3759
|
await promises.setTimeout(waitTime);
|
|
3748
3760
|
}
|
|
3761
|
+
attempts++;
|
|
3749
3762
|
try {
|
|
3750
3763
|
const response = await fetchPoll();
|
|
3751
3764
|
const {
|
|
@@ -5116,7 +5129,7 @@ function getCpuTime() {
|
|
|
5116
5129
|
|
|
5117
5130
|
// package.json
|
|
5118
5131
|
var package_default = {
|
|
5119
|
-
version: "0.
|
|
5132
|
+
version: "0.25.0"};
|
|
5120
5133
|
|
|
5121
5134
|
// src/plugins/eventEmission/builders.ts
|
|
5122
5135
|
function createBaseEvent(context = {}) {
|
|
@@ -5577,9 +5590,11 @@ function createZapierSdk(options = {}) {
|
|
|
5577
5590
|
}
|
|
5578
5591
|
|
|
5579
5592
|
exports.ActionKeyPropertySchema = ActionKeyPropertySchema;
|
|
5593
|
+
exports.ActionTimeoutMsPropertySchema = ActionTimeoutMsPropertySchema;
|
|
5580
5594
|
exports.ActionTypePropertySchema = ActionTypePropertySchema;
|
|
5581
5595
|
exports.AppKeyPropertySchema = AppKeyPropertySchema;
|
|
5582
5596
|
exports.AuthenticationIdPropertySchema = AuthenticationIdPropertySchema;
|
|
5597
|
+
exports.DEFAULT_ACTION_TIMEOUT_MS = DEFAULT_ACTION_TIMEOUT_MS;
|
|
5583
5598
|
exports.DEFAULT_CONFIG_PATH = DEFAULT_CONFIG_PATH;
|
|
5584
5599
|
exports.DebugPropertySchema = DebugPropertySchema;
|
|
5585
5600
|
exports.InputsPropertySchema = InputsPropertySchema;
|
package/dist/index.d.mts
CHANGED
|
@@ -1230,6 +1230,7 @@ declare const OffsetPropertySchema: z.ZodDefault<z.ZodNumber>;
|
|
|
1230
1230
|
declare const OutputPropertySchema: z.ZodString;
|
|
1231
1231
|
declare const DebugPropertySchema: z.ZodDefault<z.ZodBoolean>;
|
|
1232
1232
|
declare const ParamsPropertySchema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
1233
|
+
declare const ActionTimeoutMsPropertySchema: z.ZodOptional<z.ZodNumber>;
|
|
1233
1234
|
type AppKeyProperty = z.infer<typeof AppKeyPropertySchema>;
|
|
1234
1235
|
type ActionTypeProperty = z.infer<typeof ActionTypePropertySchema>;
|
|
1235
1236
|
type ActionKeyProperty = z.infer<typeof ActionKeyPropertySchema>;
|
|
@@ -1240,10 +1241,12 @@ type OffsetProperty = z.infer<typeof OffsetPropertySchema>;
|
|
|
1240
1241
|
type OutputProperty = z.infer<typeof OutputPropertySchema>;
|
|
1241
1242
|
type DebugProperty = z.infer<typeof DebugPropertySchema>;
|
|
1242
1243
|
type ParamsProperty = z.infer<typeof ParamsPropertySchema>;
|
|
1244
|
+
type ActionTimeoutMsProperty = z.infer<typeof ActionTimeoutMsPropertySchema>;
|
|
1243
1245
|
|
|
1244
1246
|
declare const ActionExecutionInputSchema: z.ZodObject<{
|
|
1245
1247
|
inputs: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
1246
1248
|
authenticationId: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
1249
|
+
timeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
1247
1250
|
}, z.core.$strip>;
|
|
1248
1251
|
type ActionExecutionOptions = z.infer<typeof ActionExecutionInputSchema>;
|
|
1249
1252
|
declare const AppFactoryInputSchema: z.ZodObject<{
|
|
@@ -1337,6 +1340,7 @@ declare const RunActionSchema: z.ZodObject<{
|
|
|
1337
1340
|
actionKey: z.ZodString;
|
|
1338
1341
|
authenticationId: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
|
|
1339
1342
|
inputs: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
1343
|
+
timeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
1340
1344
|
pageSize: z.ZodOptional<z.ZodNumber>;
|
|
1341
1345
|
maxItems: z.ZodOptional<z.ZodNumber>;
|
|
1342
1346
|
cursor: z.ZodOptional<z.ZodString>;
|
|
@@ -2525,6 +2529,10 @@ declare const ZAPIER_BASE_URL: string;
|
|
|
2525
2529
|
* Maximum number of items that can be requested per page across all paginated functions
|
|
2526
2530
|
*/
|
|
2527
2531
|
declare const MAX_PAGE_LIMIT = 10000;
|
|
2532
|
+
/**
|
|
2533
|
+
* Default timeout for action execution (in milliseconds)
|
|
2534
|
+
*/
|
|
2535
|
+
declare const DEFAULT_ACTION_TIMEOUT_MS = 180000;
|
|
2528
2536
|
/**
|
|
2529
2537
|
* Credentials from environment variables
|
|
2530
2538
|
*/
|
|
@@ -2703,4 +2711,4 @@ declare function createZapierSdkWithoutRegistry(options?: ZapierSdkOptions): Sdk
|
|
|
2703
2711
|
}>;
|
|
2704
2712
|
declare function createZapierSdk(options?: ZapierSdkOptions): ZapierSdk;
|
|
2705
2713
|
|
|
2706
|
-
export { type Action, type ActionEntry, type ActionExecutionOptions, type ActionExecutionResult, type ActionField, type ActionFieldChoice, type ActionItem$1 as ActionItem, type ActionKeyProperty, ActionKeyPropertySchema, type ActionTypeProperty, ActionTypePropertySchema, type AddActionEntryOptions, type AddActionEntryResult, type ApiError, type ApiEvent, type ApiPluginOptions, type ApiPluginProvides, type App, type AppItem, type AppKeyProperty, AppKeyPropertySchema, type ApplicationLifecycleEventData, type AppsPluginProvides, type AuthEvent, type Authentication, type AuthenticationIdProperty, AuthenticationIdPropertySchema, type AuthenticationItem, type AuthenticationsResponse, type BaseEvent, type BatchOptions, type Choice, type ClientCredentialsObject, type CreateClientCredentialsPluginProvides, type Credentials, type CredentialsObject, DEFAULT_CONFIG_PATH, type DebugProperty, DebugPropertySchema, type DeleteClientCredentialsPluginProvides, type EnhancedErrorEventData, type ErrorOptions, type EventCallback, type EventContext, type EventEmissionContext, type FetchPluginProvides, type Field, type FieldsetItem, type FindFirstAuthenticationPluginProvides, type FindUniqueAuthenticationPluginProvides, type FormatMetadata, type FormattedItem, type FunctionOptions, type FunctionRegistryEntry, type GetActionPluginProvides, type GetAppPluginProvides, type GetAuthenticationPluginProvides, type GetContextType, type GetProfilePluginProvides, type GetSdkType, type InfoFieldItem, type InputFieldItem, type InputsProperty, InputsPropertySchema, type LimitProperty, LimitPropertySchema, type ListActionsPluginProvides, type ListAppsPluginProvides, type ListAuthenticationsPluginProvides, type ListClientCredentialsPluginProvides, type ListInputFieldsPluginProvides, type LoadingEvent, MAX_PAGE_LIMIT, type Manifest, type ManifestEntry, type ManifestPluginOptions, type ManifestPluginProvides, type MethodCalledEvent, type MethodCalledEventData, type Need, type NeedsRequest, type NeedsResponse, type OffsetProperty, OffsetPropertySchema, type OutputProperty, OutputPropertySchema, type PaginatedSdkFunction, type ParamsProperty, ParamsPropertySchema, type PkceCredentialsObject, type Plugin, type PluginDependencies, type PluginOptions, type PluginProvides, type PositionalMetadata, RelayFetchSchema, RelayRequestSchema, type RequestPluginProvides, type ResolveAuthTokenOptions, type ResolveCredentialsOptions, type ResolvedCredentials, type RootFieldItem, type RunActionPluginProvides, type Sdk, type SdkEvent, type UpdateManifestEntryOptions, type UpdateManifestEntryResult, type UserProfile, type UserProfileItem, ZAPIER_AUTH_BASE_URL, ZAPIER_AUTH_CLIENT_ID, ZAPIER_BASE_URL, ZAPIER_CREDENTIALS, ZAPIER_CREDENTIALS_BASE_URL, ZAPIER_CREDENTIALS_CLIENT_ID, ZAPIER_CREDENTIALS_CLIENT_SECRET, ZAPIER_CREDENTIALS_SCOPE, ZAPIER_TOKEN, ZapierActionError, ZapierApiError, ZapierAppNotFoundError, ZapierAuthenticationError, ZapierBundleError, ZapierConfigurationError, ZapierError, type ZapierFetchInitOptions, ZapierNotFoundError, ZapierResourceNotFoundError, type ZapierSdk, type ZapierSdkApps, type ZapierSdkOptions, ZapierTimeoutError, ZapierUnknownError, ZapierValidationError, actionKeyResolver, actionTypeResolver, apiPlugin, appKeyResolver, appsPlugin, authenticationIdGenericResolver, authenticationIdResolver, batch, buildApplicationLifecycleEvent, buildErrorEvent, buildErrorEventWithContext, buildMethodCalledEvent, clearTokenCache, clientCredentialsNameResolver, clientIdResolver, createBaseEvent, createClientCredentialsPlugin, createFunction, createSdk, createZapierSdk, createZapierSdkWithoutRegistry, deleteClientCredentialsPlugin, fetchPlugin, findFirstAuthenticationPlugin, findManifestEntry, findUniqueAuthenticationPlugin, formatErrorMessage, generateEventId, getActionPlugin, getAppPlugin, getAuthenticationPlugin, getBaseUrlFromCredentials, getCiPlatform, getClientIdFromCredentials, getCpuTime, getCurrentTimestamp, getMemoryUsage, getOsInfo, getPlatformVersions, getPreferredManifestEntryKey, getProfilePlugin, getReleaseId, getTokenFromCliLogin, inputFieldKeyResolver, inputsAllOptionalResolver, inputsResolver, invalidateCachedToken, invalidateCredentialsToken, isCi, isClientCredentials, isCredentialsFunction, isCredentialsObject, isPkceCredentials, isPositional, listActionsPlugin, listAppsPlugin, listAuthenticationsPlugin, listClientCredentialsPlugin, listInputFieldsPlugin, logDeprecation, manifestPlugin, readManifestFromFile, registryPlugin, requestPlugin, resetDeprecationWarnings, resolveAuthToken, resolveCredentials, resolveCredentialsFromEnv, runActionPlugin, toSnakeCase, toTitleCase };
|
|
2714
|
+
export { type Action, type ActionEntry, type ActionExecutionOptions, type ActionExecutionResult, type ActionField, type ActionFieldChoice, type ActionItem$1 as ActionItem, type ActionKeyProperty, ActionKeyPropertySchema, type ActionTimeoutMsProperty, ActionTimeoutMsPropertySchema, type ActionTypeProperty, ActionTypePropertySchema, type AddActionEntryOptions, type AddActionEntryResult, type ApiError, type ApiEvent, type ApiPluginOptions, type ApiPluginProvides, type App, type AppItem, type AppKeyProperty, AppKeyPropertySchema, type ApplicationLifecycleEventData, type AppsPluginProvides, type AuthEvent, type Authentication, type AuthenticationIdProperty, AuthenticationIdPropertySchema, type AuthenticationItem, type AuthenticationsResponse, type BaseEvent, type BatchOptions, type Choice, type ClientCredentialsObject, type CreateClientCredentialsPluginProvides, type Credentials, type CredentialsObject, DEFAULT_ACTION_TIMEOUT_MS, DEFAULT_CONFIG_PATH, type DebugProperty, DebugPropertySchema, type DeleteClientCredentialsPluginProvides, type EnhancedErrorEventData, type ErrorOptions, type EventCallback, type EventContext, type EventEmissionContext, type FetchPluginProvides, type Field, type FieldsetItem, type FindFirstAuthenticationPluginProvides, type FindUniqueAuthenticationPluginProvides, type FormatMetadata, type FormattedItem, type FunctionOptions, type FunctionRegistryEntry, type GetActionPluginProvides, type GetAppPluginProvides, type GetAuthenticationPluginProvides, type GetContextType, type GetProfilePluginProvides, type GetSdkType, type InfoFieldItem, type InputFieldItem, type InputsProperty, InputsPropertySchema, type LimitProperty, LimitPropertySchema, type ListActionsPluginProvides, type ListAppsPluginProvides, type ListAuthenticationsPluginProvides, type ListClientCredentialsPluginProvides, type ListInputFieldsPluginProvides, type LoadingEvent, MAX_PAGE_LIMIT, type Manifest, type ManifestEntry, type ManifestPluginOptions, type ManifestPluginProvides, type MethodCalledEvent, type MethodCalledEventData, type Need, type NeedsRequest, type NeedsResponse, type OffsetProperty, OffsetPropertySchema, type OutputProperty, OutputPropertySchema, type PaginatedSdkFunction, type ParamsProperty, ParamsPropertySchema, type PkceCredentialsObject, type Plugin, type PluginDependencies, type PluginOptions, type PluginProvides, type PositionalMetadata, RelayFetchSchema, RelayRequestSchema, type RequestPluginProvides, type ResolveAuthTokenOptions, type ResolveCredentialsOptions, type ResolvedCredentials, type RootFieldItem, type RunActionPluginProvides, type Sdk, type SdkEvent, type UpdateManifestEntryOptions, type UpdateManifestEntryResult, type UserProfile, type UserProfileItem, ZAPIER_AUTH_BASE_URL, ZAPIER_AUTH_CLIENT_ID, ZAPIER_BASE_URL, ZAPIER_CREDENTIALS, ZAPIER_CREDENTIALS_BASE_URL, ZAPIER_CREDENTIALS_CLIENT_ID, ZAPIER_CREDENTIALS_CLIENT_SECRET, ZAPIER_CREDENTIALS_SCOPE, ZAPIER_TOKEN, ZapierActionError, ZapierApiError, ZapierAppNotFoundError, ZapierAuthenticationError, ZapierBundleError, ZapierConfigurationError, ZapierError, type ZapierFetchInitOptions, ZapierNotFoundError, ZapierResourceNotFoundError, type ZapierSdk, type ZapierSdkApps, type ZapierSdkOptions, ZapierTimeoutError, ZapierUnknownError, ZapierValidationError, actionKeyResolver, actionTypeResolver, apiPlugin, appKeyResolver, appsPlugin, authenticationIdGenericResolver, authenticationIdResolver, batch, buildApplicationLifecycleEvent, buildErrorEvent, buildErrorEventWithContext, buildMethodCalledEvent, clearTokenCache, clientCredentialsNameResolver, clientIdResolver, createBaseEvent, createClientCredentialsPlugin, createFunction, createSdk, createZapierSdk, createZapierSdkWithoutRegistry, deleteClientCredentialsPlugin, fetchPlugin, findFirstAuthenticationPlugin, findManifestEntry, findUniqueAuthenticationPlugin, formatErrorMessage, generateEventId, getActionPlugin, getAppPlugin, getAuthenticationPlugin, getBaseUrlFromCredentials, getCiPlatform, getClientIdFromCredentials, getCpuTime, getCurrentTimestamp, getMemoryUsage, getOsInfo, getPlatformVersions, getPreferredManifestEntryKey, getProfilePlugin, getReleaseId, getTokenFromCliLogin, inputFieldKeyResolver, inputsAllOptionalResolver, inputsResolver, invalidateCachedToken, invalidateCredentialsToken, isCi, isClientCredentials, isCredentialsFunction, isCredentialsObject, isPkceCredentials, isPositional, listActionsPlugin, listAppsPlugin, listAuthenticationsPlugin, listClientCredentialsPlugin, listInputFieldsPlugin, logDeprecation, manifestPlugin, readManifestFromFile, registryPlugin, requestPlugin, resetDeprecationWarnings, resolveAuthToken, resolveCredentials, resolveCredentialsFromEnv, runActionPlugin, toSnakeCase, toTitleCase };
|
package/dist/index.mjs
CHANGED
|
@@ -37,6 +37,7 @@ function isPositional(schema) {
|
|
|
37
37
|
// src/constants.ts
|
|
38
38
|
var ZAPIER_BASE_URL = process.env.ZAPIER_BASE_URL || "https://zapier.com";
|
|
39
39
|
var MAX_PAGE_LIMIT = 1e4;
|
|
40
|
+
var DEFAULT_ACTION_TIMEOUT_MS = 18e4;
|
|
40
41
|
var ZAPIER_CREDENTIALS = process.env.ZAPIER_CREDENTIALS;
|
|
41
42
|
var ZAPIER_CREDENTIALS_CLIENT_ID = process.env.ZAPIER_CREDENTIALS_CLIENT_ID;
|
|
42
43
|
var ZAPIER_CREDENTIALS_CLIENT_SECRET = process.env.ZAPIER_CREDENTIALS_CLIENT_SECRET;
|
|
@@ -68,6 +69,9 @@ var OffsetPropertySchema = z.number().int().min(0).default(0).describe("Number o
|
|
|
68
69
|
var OutputPropertySchema = z.string().describe("Output file path");
|
|
69
70
|
var DebugPropertySchema = z.boolean().default(false).describe("Enable debug logging");
|
|
70
71
|
var ParamsPropertySchema = z.record(z.string(), z.unknown()).describe("Additional parameters");
|
|
72
|
+
var ActionTimeoutMsPropertySchema = z.number().min(1e3).optional().describe(
|
|
73
|
+
`Maximum time to wait for action completion in milliseconds (default: ${DEFAULT_ACTION_TIMEOUT_MS})`
|
|
74
|
+
);
|
|
71
75
|
|
|
72
76
|
// src/types/errors.ts
|
|
73
77
|
var ZapierError = class extends Error {
|
|
@@ -205,7 +209,8 @@ HTTP Status: ${error.statusCode}`;
|
|
|
205
209
|
}
|
|
206
210
|
var ActionExecutionInputSchema = z.object({
|
|
207
211
|
inputs: z.record(z.string(), z.unknown()).optional(),
|
|
208
|
-
authenticationId: AuthenticationIdPropertySchema.optional()
|
|
212
|
+
authenticationId: AuthenticationIdPropertySchema.optional(),
|
|
213
|
+
timeoutMs: ActionTimeoutMsPropertySchema
|
|
209
214
|
}).describe(
|
|
210
215
|
"Execute an action with the given inputs for the bound app, as an alternative to runAction"
|
|
211
216
|
);
|
|
@@ -242,7 +247,11 @@ var ActionResultItemSchema = withFormatter(
|
|
|
242
247
|
function createActionFunction(appKey, actionType, actionKey, options, pinnedAuthId) {
|
|
243
248
|
return (actionOptions = {}) => {
|
|
244
249
|
const { sdk } = options;
|
|
245
|
-
const {
|
|
250
|
+
const {
|
|
251
|
+
inputs,
|
|
252
|
+
authenticationId: providedAuthenticationId,
|
|
253
|
+
timeoutMs
|
|
254
|
+
} = actionOptions;
|
|
246
255
|
const authenticationId = pinnedAuthId ?? providedAuthenticationId;
|
|
247
256
|
if (!authenticationId) {
|
|
248
257
|
throw new ZapierValidationError(
|
|
@@ -254,7 +263,8 @@ function createActionFunction(appKey, actionType, actionKey, options, pinnedAuth
|
|
|
254
263
|
actionType,
|
|
255
264
|
actionKey,
|
|
256
265
|
inputs,
|
|
257
|
-
authenticationId
|
|
266
|
+
authenticationId,
|
|
267
|
+
timeoutMs
|
|
258
268
|
});
|
|
259
269
|
};
|
|
260
270
|
}
|
|
@@ -2709,6 +2719,7 @@ var RunActionSchema = z.object({
|
|
|
2709
2719
|
inputs: InputsPropertySchema.optional().describe(
|
|
2710
2720
|
"Input parameters for the action"
|
|
2711
2721
|
),
|
|
2722
|
+
timeoutMs: ActionTimeoutMsPropertySchema,
|
|
2712
2723
|
pageSize: z.number().min(1).optional().describe("Number of results per page"),
|
|
2713
2724
|
maxItems: z.number().min(1).optional().describe("Maximum total items to return across all pages"),
|
|
2714
2725
|
cursor: z.string().optional().describe("Cursor to start from")
|
|
@@ -2724,7 +2735,8 @@ async function executeAction(actionOptions) {
|
|
|
2724
2735
|
actionKey,
|
|
2725
2736
|
actionType,
|
|
2726
2737
|
executionOptions,
|
|
2727
|
-
authenticationId
|
|
2738
|
+
authenticationId,
|
|
2739
|
+
timeoutMs
|
|
2728
2740
|
} = actionOptions;
|
|
2729
2741
|
const selectedApi = await context.getVersionedImplementationId(appKey);
|
|
2730
2742
|
if (!selectedApi) {
|
|
@@ -2754,6 +2766,7 @@ async function executeAction(actionOptions) {
|
|
|
2754
2766
|
return await api.poll(`/zapier/api/actions/v1/runs/${runId}`, {
|
|
2755
2767
|
successStatus: 200,
|
|
2756
2768
|
pendingStatus: 202,
|
|
2769
|
+
timeoutMs: timeoutMs ?? DEFAULT_ACTION_TIMEOUT_MS,
|
|
2757
2770
|
isPending: (result) => {
|
|
2758
2771
|
const data = result?.data;
|
|
2759
2772
|
return data?.status === "waiting";
|
|
@@ -2769,7 +2782,8 @@ var runActionPlugin = ({ sdk, context }) => {
|
|
|
2769
2782
|
actionKey,
|
|
2770
2783
|
actionType,
|
|
2771
2784
|
authenticationId,
|
|
2772
|
-
inputs = {}
|
|
2785
|
+
inputs = {},
|
|
2786
|
+
timeoutMs
|
|
2773
2787
|
} = options;
|
|
2774
2788
|
const actionData = await sdk.getAction({
|
|
2775
2789
|
appKey,
|
|
@@ -2793,7 +2807,9 @@ var runActionPlugin = ({ sdk, context }) => {
|
|
|
2793
2807
|
actionKey,
|
|
2794
2808
|
actionType,
|
|
2795
2809
|
executionOptions: { inputs },
|
|
2796
|
-
authenticationId
|
|
2810
|
+
authenticationId,
|
|
2811
|
+
timeoutMs
|
|
2812
|
+
});
|
|
2797
2813
|
if (result.errors && result.errors.length > 0) {
|
|
2798
2814
|
const errorMessage = result.errors.map(
|
|
2799
2815
|
(error) => error.detail || error.title || "Unknown error"
|
|
@@ -3612,9 +3628,8 @@ var DEFAULT_TIMEOUT_MS = 18e4;
|
|
|
3612
3628
|
var DEFAULT_SUCCESS_STATUS = 200;
|
|
3613
3629
|
var DEFAULT_PENDING_STATUS = 202;
|
|
3614
3630
|
var DEFAULT_INITIAL_DELAY_MS = 50;
|
|
3615
|
-
var DEFAULT_MAX_POLLING_INTERVAL_MS =
|
|
3616
|
-
var
|
|
3617
|
-
var DEFAULT_POLLING_STAGES = [
|
|
3631
|
+
var DEFAULT_MAX_POLLING_INTERVAL_MS = 6e4;
|
|
3632
|
+
var POLLING_STAGES = [
|
|
3618
3633
|
[125, 125],
|
|
3619
3634
|
// Up to 125ms: poll every 125ms
|
|
3620
3635
|
[375, 250],
|
|
@@ -3625,9 +3640,16 @@ var DEFAULT_POLLING_STAGES = [
|
|
|
3625
3640
|
// Up to 10s: poll every 1s
|
|
3626
3641
|
[3e4, 2500],
|
|
3627
3642
|
// Up to 30s: poll every 2.5s
|
|
3628
|
-
[6e4, 5e3]
|
|
3643
|
+
[6e4, 5e3],
|
|
3629
3644
|
// Up to 60s: poll every 5s
|
|
3645
|
+
[18e4, 1e4]
|
|
3646
|
+
// Up to 3min: poll every 10s
|
|
3647
|
+
// Beyond 3min: use DEFAULT_MAX_POLLING_INTERVAL_MS (60s)
|
|
3630
3648
|
];
|
|
3649
|
+
function getPollingInterval(elapsedMs) {
|
|
3650
|
+
const stage = POLLING_STAGES.find(([threshold]) => elapsedMs < threshold);
|
|
3651
|
+
return stage ? stage[1] : DEFAULT_MAX_POLLING_INTERVAL_MS;
|
|
3652
|
+
}
|
|
3631
3653
|
var processResponse = async (response, successStatus, pendingStatus, isPending, resultExtractor, errorCount) => {
|
|
3632
3654
|
if (!response.ok) {
|
|
3633
3655
|
return {
|
|
@@ -3696,23 +3718,12 @@ async function pollUntilComplete(options) {
|
|
|
3696
3718
|
const startTime = Date.now();
|
|
3697
3719
|
let attempts = 0;
|
|
3698
3720
|
let errorCount = 0;
|
|
3699
|
-
const pollingStages = [
|
|
3700
|
-
...DEFAULT_POLLING_STAGES,
|
|
3701
|
-
[timeoutMs + MAX_TIMEOUT_BUFFER_MS, DEFAULT_MAX_POLLING_INTERVAL_MS]
|
|
3702
|
-
// Up to timeout + 10s: poll every 10s
|
|
3703
|
-
];
|
|
3704
3721
|
if (initialDelay > 0) {
|
|
3705
3722
|
await setTimeout$1(initialDelay);
|
|
3706
3723
|
}
|
|
3707
3724
|
while (true) {
|
|
3708
|
-
attempts++;
|
|
3709
3725
|
const elapsedTime = Date.now() - startTime;
|
|
3710
|
-
|
|
3711
|
-
([maxTimeForStage, _interval]) => {
|
|
3712
|
-
return elapsedTime < maxTimeForStage;
|
|
3713
|
-
}
|
|
3714
|
-
);
|
|
3715
|
-
if (!pollingInterval) {
|
|
3726
|
+
if (elapsedTime >= timeoutMs) {
|
|
3716
3727
|
throw new ZapierTimeoutError(
|
|
3717
3728
|
`Operation timed out after ${Math.floor(elapsedTime / 1e3)}s (${attempts} attempts)`,
|
|
3718
3729
|
{
|
|
@@ -3720,10 +3731,12 @@ async function pollUntilComplete(options) {
|
|
|
3720
3731
|
}
|
|
3721
3732
|
);
|
|
3722
3733
|
}
|
|
3723
|
-
if (attempts >
|
|
3724
|
-
const
|
|
3734
|
+
if (attempts > 0) {
|
|
3735
|
+
const interval = getPollingInterval(elapsedTime);
|
|
3736
|
+
const waitTime = calculateWaitTime(interval, errorCount);
|
|
3725
3737
|
await setTimeout$1(waitTime);
|
|
3726
3738
|
}
|
|
3739
|
+
attempts++;
|
|
3727
3740
|
try {
|
|
3728
3741
|
const response = await fetchPoll();
|
|
3729
3742
|
const {
|
|
@@ -5094,7 +5107,7 @@ function getCpuTime() {
|
|
|
5094
5107
|
|
|
5095
5108
|
// package.json
|
|
5096
5109
|
var package_default = {
|
|
5097
|
-
version: "0.
|
|
5110
|
+
version: "0.25.0"};
|
|
5098
5111
|
|
|
5099
5112
|
// src/plugins/eventEmission/builders.ts
|
|
5100
5113
|
function createBaseEvent(context = {}) {
|
|
@@ -5554,4 +5567,4 @@ function createZapierSdk(options = {}) {
|
|
|
5554
5567
|
return createZapierSdkWithoutRegistry(options).addPlugin(registryPlugin);
|
|
5555
5568
|
}
|
|
5556
5569
|
|
|
5557
|
-
export { ActionKeyPropertySchema, ActionTypePropertySchema, AppKeyPropertySchema, AuthenticationIdPropertySchema, DEFAULT_CONFIG_PATH, DebugPropertySchema, InputsPropertySchema, LimitPropertySchema, MAX_PAGE_LIMIT, OffsetPropertySchema, OutputPropertySchema, ParamsPropertySchema, RelayFetchSchema, RelayRequestSchema, ZAPIER_AUTH_BASE_URL, ZAPIER_AUTH_CLIENT_ID, ZAPIER_BASE_URL, ZAPIER_CREDENTIALS, ZAPIER_CREDENTIALS_BASE_URL, ZAPIER_CREDENTIALS_CLIENT_ID, ZAPIER_CREDENTIALS_CLIENT_SECRET, ZAPIER_CREDENTIALS_SCOPE, ZAPIER_TOKEN, ZapierActionError, ZapierApiError, ZapierAppNotFoundError, ZapierAuthenticationError, ZapierBundleError, ZapierConfigurationError, ZapierError, ZapierNotFoundError, ZapierResourceNotFoundError, ZapierTimeoutError, ZapierUnknownError, ZapierValidationError, actionKeyResolver, actionTypeResolver, apiPlugin, appKeyResolver, appsPlugin, authenticationIdGenericResolver, authenticationIdResolver, batch, buildApplicationLifecycleEvent, buildErrorEvent, buildErrorEventWithContext, buildMethodCalledEvent, clearTokenCache, clientCredentialsNameResolver, clientIdResolver, createBaseEvent, createClientCredentialsPlugin, createFunction, createSdk, createZapierSdk, createZapierSdkWithoutRegistry, deleteClientCredentialsPlugin, fetchPlugin, findFirstAuthenticationPlugin, findManifestEntry, findUniqueAuthenticationPlugin, formatErrorMessage, generateEventId, getActionPlugin, getAppPlugin, getAuthenticationPlugin, getBaseUrlFromCredentials, getCiPlatform, getClientIdFromCredentials, getCpuTime, getCurrentTimestamp, getMemoryUsage, getOsInfo, getPlatformVersions, getPreferredManifestEntryKey, getProfilePlugin, getReleaseId, getTokenFromCliLogin, inputFieldKeyResolver, inputsAllOptionalResolver, inputsResolver, invalidateCachedToken, invalidateCredentialsToken, isCi, isClientCredentials, isCredentialsFunction, isCredentialsObject, isPkceCredentials, isPositional, listActionsPlugin, listAppsPlugin, listAuthenticationsPlugin, listClientCredentialsPlugin, listInputFieldsPlugin, logDeprecation, manifestPlugin, readManifestFromFile, registryPlugin, requestPlugin, resetDeprecationWarnings, resolveAuthToken, resolveCredentials, resolveCredentialsFromEnv, runActionPlugin, toSnakeCase, toTitleCase };
|
|
5570
|
+
export { ActionKeyPropertySchema, ActionTimeoutMsPropertySchema, ActionTypePropertySchema, AppKeyPropertySchema, AuthenticationIdPropertySchema, DEFAULT_ACTION_TIMEOUT_MS, DEFAULT_CONFIG_PATH, DebugPropertySchema, InputsPropertySchema, LimitPropertySchema, MAX_PAGE_LIMIT, OffsetPropertySchema, OutputPropertySchema, ParamsPropertySchema, RelayFetchSchema, RelayRequestSchema, ZAPIER_AUTH_BASE_URL, ZAPIER_AUTH_CLIENT_ID, ZAPIER_BASE_URL, ZAPIER_CREDENTIALS, ZAPIER_CREDENTIALS_BASE_URL, ZAPIER_CREDENTIALS_CLIENT_ID, ZAPIER_CREDENTIALS_CLIENT_SECRET, ZAPIER_CREDENTIALS_SCOPE, ZAPIER_TOKEN, ZapierActionError, ZapierApiError, ZapierAppNotFoundError, ZapierAuthenticationError, ZapierBundleError, ZapierConfigurationError, ZapierError, ZapierNotFoundError, ZapierResourceNotFoundError, ZapierTimeoutError, ZapierUnknownError, ZapierValidationError, actionKeyResolver, actionTypeResolver, apiPlugin, appKeyResolver, appsPlugin, authenticationIdGenericResolver, authenticationIdResolver, batch, buildApplicationLifecycleEvent, buildErrorEvent, buildErrorEventWithContext, buildMethodCalledEvent, clearTokenCache, clientCredentialsNameResolver, clientIdResolver, createBaseEvent, createClientCredentialsPlugin, createFunction, createSdk, createZapierSdk, createZapierSdkWithoutRegistry, deleteClientCredentialsPlugin, fetchPlugin, findFirstAuthenticationPlugin, findManifestEntry, findUniqueAuthenticationPlugin, formatErrorMessage, generateEventId, getActionPlugin, getAppPlugin, getAuthenticationPlugin, getBaseUrlFromCredentials, getCiPlatform, getClientIdFromCredentials, getCpuTime, getCurrentTimestamp, getMemoryUsage, getOsInfo, getPlatformVersions, getPreferredManifestEntryKey, getProfilePlugin, getReleaseId, getTokenFromCliLogin, inputFieldKeyResolver, inputsAllOptionalResolver, inputsResolver, invalidateCachedToken, invalidateCredentialsToken, isCi, isClientCredentials, isCredentialsFunction, isCredentialsObject, isPkceCredentials, isPositional, listActionsPlugin, listAppsPlugin, listAuthenticationsPlugin, listClientCredentialsPlugin, listInputFieldsPlugin, logDeprecation, manifestPlugin, readManifestFromFile, registryPlugin, requestPlugin, resetDeprecationWarnings, resolveAuthToken, resolveCredentials, resolveCredentialsFromEnv, runActionPlugin, toSnakeCase, toTitleCase };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/apps/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,WAAW,EAEZ,MAAM,WAAW,CAAC;AAGnB,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAGlE,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,WAAW,CAAC;CACnB;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/apps/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,WAAW,EAEZ,MAAM,WAAW,CAAC;AAGnB,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAGlE,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,WAAW,CAAC;CACnB;AA4JD,eAAO,MAAM,UAAU,EAAE,MAAM,CAC7B,UAAU,CAAC,mBAAmB,GAAG,uBAAuB,CAAC,EAAE,oCAAoC;AAC/F,EAAE,EAAE,0BAA0B;AAC9B,kBAAkB,CAyBnB,CAAC;AAGF,YAAY,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACxD,YAAY,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAI7D,MAAM,WAAW,aAAa;CAAG"}
|
|
@@ -4,7 +4,7 @@ import { ActionResultItemSchema } from "../../schemas/Run";
|
|
|
4
4
|
function createActionFunction(appKey, actionType, actionKey, options, pinnedAuthId) {
|
|
5
5
|
return (actionOptions = {}) => {
|
|
6
6
|
const { sdk } = options;
|
|
7
|
-
const { inputs, authenticationId: providedAuthenticationId } = actionOptions;
|
|
7
|
+
const { inputs, authenticationId: providedAuthenticationId, timeoutMs, } = actionOptions;
|
|
8
8
|
// Use pinned auth ID first, then provided auth ID
|
|
9
9
|
const authenticationId = pinnedAuthId ?? providedAuthenticationId;
|
|
10
10
|
if (!authenticationId) {
|
|
@@ -17,6 +17,7 @@ function createActionFunction(appKey, actionType, actionKey, options, pinnedAuth
|
|
|
17
17
|
actionKey,
|
|
18
18
|
inputs,
|
|
19
19
|
authenticationId,
|
|
20
|
+
timeoutMs,
|
|
20
21
|
});
|
|
21
22
|
};
|
|
22
23
|
}
|
|
@@ -3,6 +3,7 @@ import { type AuthenticationIdProperty } from "../../types/properties";
|
|
|
3
3
|
export declare const ActionExecutionInputSchema: z.ZodObject<{
|
|
4
4
|
inputs: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
5
5
|
authenticationId: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
6
|
+
timeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
6
7
|
}, z.core.$strip>;
|
|
7
8
|
export type ActionExecutionOptions = z.infer<typeof ActionExecutionInputSchema>;
|
|
8
9
|
export declare const AppFactoryInputSchema: z.ZodObject<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../src/plugins/apps/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../src/plugins/apps/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAGL,KAAK,wBAAwB,EAC9B,MAAM,wBAAwB,CAAC;AAEhC,eAAO,MAAM,0BAA0B;;;;iBAQpC,CAAC;AAGJ,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,0BAA0B,CAAC,CAAC;AAEhF,eAAO,MAAM,qBAAqB;;iBAIgB,CAAC;AAEnD,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAGpE,UAAU,mBAAmB;IAC3B,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,OAAO,CAAC,EAAE,sBAAsB,KAAK,OAAO,CAAC;QAC9D,IAAI,EAAE,GAAG,EAAE,CAAC;QACZ,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,CAAC,GACA,aAAa,CAAC;QAAE,IAAI,EAAE,GAAG,EAAE,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG;QACpD,KAAK,IAAI,aAAa,CAAC,GAAG,CAAC,CAAC;KAC7B,CAAC;CACL;AAGD,UAAU,eAAe;IACvB,KAAK,EAAE,CACL,GAAG,EAAE,MAAM,GAAG,GAAG,EACjB,IAAI,CAAC,EAAE,WAAW,GAAG;QACnB,gBAAgB,CAAC,EAAE,wBAAwB,CAAC;QAC5C,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,sBAAsB,CAAC,EAAE,MAAM,CAAC;KACjC,KACE,OAAO,CAAC,QAAQ,CAAC,CAAC;CACxB;AAGD,KAAK,eAAe,GAAG,mBAAmB,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;AAEtE,UAAU,QAAQ;IAChB,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAAC;CACjC;AAED,UAAU,UAAU;IAClB,CAAC,OAAO,EAAE,eAAe,GAAG,QAAQ,CAAC;CACtC;AAGD,KAAK,mBAAmB,GAAG,UAAU,GAAG,QAAQ,CAAC;AAEjD,MAAM,WAAW,WAAW;IAC1B,CAAC,GAAG,EAAE,MAAM,GAAG,mBAAmB,CAAC;CACpC"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { AuthenticationIdPropertySchema, } from "../../types/properties";
|
|
2
|
+
import { AuthenticationIdPropertySchema, ActionTimeoutMsPropertySchema, } from "../../types/properties";
|
|
3
3
|
export const ActionExecutionInputSchema = z
|
|
4
4
|
.object({
|
|
5
5
|
inputs: z.record(z.string(), z.unknown()).optional(),
|
|
6
6
|
authenticationId: AuthenticationIdPropertySchema.optional(),
|
|
7
|
+
timeoutMs: ActionTimeoutMsPropertySchema,
|
|
7
8
|
})
|
|
8
9
|
.describe("Execute an action with the given inputs for the bound app, as an alternative to runAction");
|
|
9
10
|
export const AppFactoryInputSchema = z
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/runAction/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EACL,eAAe,EACf,KAAK,gBAAgB,EAEtB,MAAM,WAAW,CAAC;AAQnB,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAQtD,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,qBAAqB,CAAC;AAExE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/runAction/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EACL,eAAe,EACf,KAAK,gBAAgB,EAEtB,MAAM,WAAW,CAAC;AAQnB,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAQtD,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,qBAAqB,CAAC;AAExE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAI7D,MAAM,WAAW,uBAAuB;IACtC,SAAS,EAAE,CAAC,OAAO,CAAC,EAAE,gBAAgB,KAAK,OAAO,CAAC;QACjD,IAAI,EAAE,GAAG,EAAE,CAAC;QACZ,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,CAAC,GACA,aAAa,CAAC;QAAE,IAAI,EAAE,GAAG,EAAE,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG;QACpD,KAAK,IAAI,aAAa,CAAC,GAAG,CAAC,CAAC;KAC7B,CAAC;IACJ,OAAO,EAAE;QACP,IAAI,EAAE;YACJ,SAAS,EAAE;gBACT,WAAW,EAAE,OAAO,eAAe,CAAC;aACrC,CAAC;SACH,CAAC;KACH,CAAC;CACH;AAsFD,eAAO,MAAM,eAAe,EAAE,MAAM,CAClC,UAAU,CAAC,uBAAuB,GAAG,oBAAoB,CAAC,EAAE,uCAAuC;AACnG,AAD4D,uCAAuC;AACnG;IACE,GAAG,EAAE,SAAS,CAAC;IACf,4BAA4B,EAAE,4BAA4B,CAAC;CAC5D,GAAG,oBAAoB,EAAE,4CAA4C;AACtE,uBAAuB,CAmGxB,CAAC"}
|
|
@@ -5,8 +5,9 @@ import { createPaginatedFunction } from "../../utils/function-utils";
|
|
|
5
5
|
import { appKeyResolver, actionTypeResolver, actionKeyResolver, authenticationIdResolver, inputsResolver, } from "../../resolvers";
|
|
6
6
|
import { createTelemetryCallback } from "../../utils/telemetry-utils";
|
|
7
7
|
import { stripPageSuffix } from "../../utils/string-utils";
|
|
8
|
+
import { DEFAULT_ACTION_TIMEOUT_MS } from "../../constants";
|
|
8
9
|
async function executeAction(actionOptions) {
|
|
9
|
-
const { api, context, appKey, actionId, actionKey, actionType, executionOptions, authenticationId, } = actionOptions;
|
|
10
|
+
const { api, context, appKey, actionId, actionKey, actionType, executionOptions, authenticationId, timeoutMs, } = actionOptions;
|
|
10
11
|
// Use the manifest plugin to get the current implementation ID
|
|
11
12
|
const selectedApi = await context.getVersionedImplementationId(appKey);
|
|
12
13
|
if (!selectedApi) {
|
|
@@ -33,6 +34,7 @@ async function executeAction(actionOptions) {
|
|
|
33
34
|
return await api.poll(`/zapier/api/actions/v1/runs/${runId}`, {
|
|
34
35
|
successStatus: 200,
|
|
35
36
|
pendingStatus: 202,
|
|
37
|
+
timeoutMs: timeoutMs ?? DEFAULT_ACTION_TIMEOUT_MS,
|
|
36
38
|
isPending: (result) => {
|
|
37
39
|
const data = result?.data;
|
|
38
40
|
return data?.status === "waiting";
|
|
@@ -43,7 +45,7 @@ async function executeAction(actionOptions) {
|
|
|
43
45
|
export const runActionPlugin = ({ sdk, context }) => {
|
|
44
46
|
async function runActionPage(options) {
|
|
45
47
|
const { api } = context;
|
|
46
|
-
const { appKey, actionKey, actionType, authenticationId, inputs = {}, } = options;
|
|
48
|
+
const { appKey, actionKey, actionType, authenticationId, inputs = {}, timeoutMs, } = options;
|
|
47
49
|
// Validate that the action exists using the getAction plugin
|
|
48
50
|
const actionData = await sdk.getAction({
|
|
49
51
|
appKey: appKey,
|
|
@@ -68,7 +70,7 @@ export const runActionPlugin = ({ sdk, context }) => {
|
|
|
68
70
|
actionType,
|
|
69
71
|
executionOptions: { inputs },
|
|
70
72
|
authenticationId,
|
|
71
|
-
|
|
73
|
+
timeoutMs,
|
|
72
74
|
});
|
|
73
75
|
// Check for errors in the result and throw if present
|
|
74
76
|
if (result.errors && result.errors.length > 0) {
|
|
@@ -2,6 +2,7 @@ import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
|
2
2
|
import { ZapierValidationError, ZapierActionError } from "../../types/errors";
|
|
3
3
|
import { runActionPlugin } from "./index";
|
|
4
4
|
import { createSdk } from "../../sdk";
|
|
5
|
+
import { DEFAULT_ACTION_TIMEOUT_MS } from "../../constants";
|
|
5
6
|
const mockAction = {
|
|
6
7
|
type: "action",
|
|
7
8
|
key: "send_message",
|
|
@@ -149,6 +150,7 @@ describe("runAction plugin", () => {
|
|
|
149
150
|
expect(mockApiClient.poll).toHaveBeenCalledWith("/zapier/api/actions/v1/runs/run_123", {
|
|
150
151
|
successStatus: 200,
|
|
151
152
|
pendingStatus: 202,
|
|
153
|
+
timeoutMs: DEFAULT_ACTION_TIMEOUT_MS,
|
|
152
154
|
isPending: expect.any(Function),
|
|
153
155
|
resultExtractor: expect.any(Function),
|
|
154
156
|
});
|
|
@@ -170,6 +172,20 @@ describe("runAction plugin", () => {
|
|
|
170
172
|
},
|
|
171
173
|
});
|
|
172
174
|
});
|
|
175
|
+
it("should pass custom timeoutMs to poll", async () => {
|
|
176
|
+
const customTimeout = 300000; // 5 minutes
|
|
177
|
+
const sdk = createTestSdk();
|
|
178
|
+
await sdk.runAction({
|
|
179
|
+
appKey: "slack",
|
|
180
|
+
actionType: "write",
|
|
181
|
+
actionKey: "send_message",
|
|
182
|
+
inputs: { message: "Hello" },
|
|
183
|
+
timeoutMs: customTimeout,
|
|
184
|
+
});
|
|
185
|
+
expect(mockApiClient.poll).toHaveBeenCalledWith("/zapier/api/actions/v1/runs/run_123", expect.objectContaining({
|
|
186
|
+
timeoutMs: customTimeout,
|
|
187
|
+
}));
|
|
188
|
+
});
|
|
173
189
|
it("should handle pagination cursor", async () => {
|
|
174
190
|
const sdk = createTestSdk();
|
|
175
191
|
const runActionResult = sdk.runAction({
|
|
@@ -18,6 +18,7 @@ export declare const RunActionSchema: z.ZodObject<{
|
|
|
18
18
|
actionKey: z.ZodString;
|
|
19
19
|
authenticationId: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
|
|
20
20
|
inputs: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
21
|
+
timeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
21
22
|
pageSize: z.ZodOptional<z.ZodNumber>;
|
|
22
23
|
maxItems: z.ZodOptional<z.ZodNumber>;
|
|
23
24
|
cursor: z.ZodOptional<z.ZodString>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../src/plugins/runAction/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../src/plugins/runAction/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AASxB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,KAAK,EACV,iBAAiB,EACjB,qBAAqB,EACrB,wBAAwB,EACxB,kBAAkB,EACnB,MAAM,oBAAoB,CAAC;AAG5B,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;iBAsB0B,CAAC;AAGvD,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAG/D,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,OAAO,EAAE,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAGD,MAAM,MAAM,cAAc,GACtB,iBAAiB,GACjB,qBAAqB,GACrB,wBAAwB,GACxB,kBAAkB,CAAC;AAGvB,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,oBAAoB,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;CAC5D"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { AppKeyPropertySchema, ActionTypePropertySchema, ActionKeyPropertySchema, AuthenticationIdPropertySchema, InputsPropertySchema, } from "../../types/properties";
|
|
2
|
+
import { AppKeyPropertySchema, ActionTypePropertySchema, ActionKeyPropertySchema, AuthenticationIdPropertySchema, InputsPropertySchema, ActionTimeoutMsPropertySchema, } from "../../types/properties";
|
|
3
3
|
// Pure Zod schema - no resolver metadata!
|
|
4
4
|
export const RunActionSchema = z
|
|
5
5
|
.object({
|
|
@@ -8,6 +8,7 @@ export const RunActionSchema = z
|
|
|
8
8
|
actionKey: ActionKeyPropertySchema,
|
|
9
9
|
authenticationId: AuthenticationIdPropertySchema.nullable().optional(),
|
|
10
10
|
inputs: InputsPropertySchema.optional().describe("Input parameters for the action"),
|
|
11
|
+
timeoutMs: ActionTimeoutMsPropertySchema,
|
|
11
12
|
pageSize: z
|
|
12
13
|
.number()
|
|
13
14
|
.min(1)
|
|
@@ -20,6 +20,7 @@ export declare const OffsetPropertySchema: z.ZodDefault<z.ZodNumber>;
|
|
|
20
20
|
export declare const OutputPropertySchema: z.ZodString;
|
|
21
21
|
export declare const DebugPropertySchema: z.ZodDefault<z.ZodBoolean>;
|
|
22
22
|
export declare const ParamsPropertySchema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
23
|
+
export declare const ActionTimeoutMsPropertySchema: z.ZodOptional<z.ZodNumber>;
|
|
23
24
|
export type AppKeyProperty = z.infer<typeof AppKeyPropertySchema>;
|
|
24
25
|
export type ActionTypeProperty = z.infer<typeof ActionTypePropertySchema>;
|
|
25
26
|
export type ActionKeyProperty = z.infer<typeof ActionKeyPropertySchema>;
|
|
@@ -30,4 +31,5 @@ export type OffsetProperty = z.infer<typeof OffsetPropertySchema>;
|
|
|
30
31
|
export type OutputProperty = z.infer<typeof OutputPropertySchema>;
|
|
31
32
|
export type DebugProperty = z.infer<typeof DebugPropertySchema>;
|
|
32
33
|
export type ParamsProperty = z.infer<typeof ParamsPropertySchema>;
|
|
34
|
+
export type ActionTimeoutMsProperty = z.infer<typeof ActionTimeoutMsPropertySchema>;
|
|
33
35
|
//# sourceMappingURL=properties.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"properties.d.ts","sourceRoot":"","sources":["../../src/types/properties.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAOxB,eAAO,MAAM,oBAAoB;;CAKhC,CAAC;AAEF,eAAO,MAAM,wBAAwB;;;;;;;;;EAW4B,CAAC;AAElE,eAAO,MAAM,uBAAuB,aAGA,CAAC;AAErC,eAAO,MAAM,8BAA8B,iDAEY,CAAC;AAExD,eAAO,MAAM,oBAAoB,wCAEa,CAAC;AAE/C,eAAO,MAAM,mBAAmB,2BAMgB,CAAC;AAEjD,eAAO,MAAM,oBAAoB,2BAKoB,CAAC;AAEtD,eAAO,MAAM,oBAAoB,aAA0C,CAAC;AAE5E,eAAO,MAAM,mBAAmB,4BAGG,CAAC;AAEpC,eAAO,MAAM,oBAAoB,wCAEG,CAAC;
|
|
1
|
+
{"version":3,"file":"properties.d.ts","sourceRoot":"","sources":["../../src/types/properties.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAOxB,eAAO,MAAM,oBAAoB;;CAKhC,CAAC;AAEF,eAAO,MAAM,wBAAwB;;;;;;;;;EAW4B,CAAC;AAElE,eAAO,MAAM,uBAAuB,aAGA,CAAC;AAErC,eAAO,MAAM,8BAA8B,iDAEY,CAAC;AAExD,eAAO,MAAM,oBAAoB,wCAEa,CAAC;AAE/C,eAAO,MAAM,mBAAmB,2BAMgB,CAAC;AAEjD,eAAO,MAAM,oBAAoB,2BAKoB,CAAC;AAEtD,eAAO,MAAM,oBAAoB,aAA0C,CAAC;AAE5E,eAAO,MAAM,mBAAmB,4BAGG,CAAC;AAEpC,eAAO,MAAM,oBAAoB,wCAEG,CAAC;AAErC,eAAO,MAAM,6BAA6B,4BAMvC,CAAC;AAGJ,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAClE,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAC1E,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AACxE,MAAM,MAAM,wBAAwB,GAAG,CAAC,CAAC,KAAK,CAC5C,OAAO,8BAA8B,CACtC,CAAC;AACF,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAClE,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAChE,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAClE,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAClE,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAChE,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAClE,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAC3C,OAAO,6BAA6B,CACrC,CAAC"}
|
package/dist/types/properties.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { withPositional } from "../utils/schema-utils";
|
|
3
|
-
import { MAX_PAGE_LIMIT } from "../constants";
|
|
3
|
+
import { MAX_PAGE_LIMIT, DEFAULT_ACTION_TIMEOUT_MS } from "../constants";
|
|
4
4
|
// Shared property definitions for common parameters across functions
|
|
5
5
|
// These can be reused in function schemas without duplication
|
|
6
6
|
export const AppKeyPropertySchema = withPositional(z
|
|
@@ -50,3 +50,8 @@ export const DebugPropertySchema = z
|
|
|
50
50
|
export const ParamsPropertySchema = z
|
|
51
51
|
.record(z.string(), z.unknown())
|
|
52
52
|
.describe("Additional parameters");
|
|
53
|
+
export const ActionTimeoutMsPropertySchema = z
|
|
54
|
+
.number()
|
|
55
|
+
.min(1000)
|
|
56
|
+
.optional()
|
|
57
|
+
.describe(`Maximum time to wait for action completion in milliseconds (default: ${DEFAULT_ACTION_TIMEOUT_MS})`);
|