@zapier/zapier-sdk 0.13.8 → 0.14.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 +14 -0
- package/dist/api/polling.d.ts.map +1 -1
- package/dist/api/polling.js +1 -11
- package/dist/index.cjs +219 -53
- package/dist/index.d.mts +73 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.mjs +219 -54
- package/dist/plugins/listInputFieldChoices/index.d.ts +3 -1
- package/dist/plugins/listInputFieldChoices/index.d.ts.map +1 -1
- package/dist/plugins/listInputFieldChoices/index.js +42 -21
- package/dist/plugins/listInputFieldChoices/index.test.js +183 -6
- package/dist/plugins/listInputFields/index.d.ts.map +1 -1
- package/dist/plugins/listInputFields/index.js +11 -16
- package/dist/plugins/listInputFields/index.test.js +4 -2
- package/dist/services/implementations.d.ts +63 -0
- package/dist/services/implementations.d.ts.map +1 -0
- package/dist/services/implementations.js +79 -0
- package/dist/utils/batch-utils.d.ts +72 -0
- package/dist/utils/batch-utils.d.ts.map +1 -0
- package/dist/utils/batch-utils.js +162 -0
- package/dist/utils/batch-utils.test.d.ts +2 -0
- package/dist/utils/batch-utils.test.d.ts.map +1 -0
- package/dist/utils/batch-utils.test.js +476 -0
- package/dist/utils/retry-utils.d.ts +45 -0
- package/dist/utils/retry-utils.d.ts.map +1 -0
- package/dist/utils/retry-utils.js +51 -0
- package/dist/utils/retry-utils.test.d.ts +2 -0
- package/dist/utils/retry-utils.test.d.ts.map +1 -0
- package/dist/utils/retry-utils.test.js +90 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @zapier/zapier-sdk
|
|
2
2
|
|
|
3
|
+
## 0.14.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 3f2f104: - Introduce a `services` layer for reusability between plugins
|
|
8
|
+
- `listInputFieldChoices` now supports returning static choices if they exist
|
|
9
|
+
|
|
10
|
+
## 0.13.9
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 492e2f9: - Add new `batch` utility method to handle concurency limits, retries, timeouts and exponential backoffs.
|
|
15
|
+
- Refactor `generateAppTypes` in CLI to use the new `batch` utility
|
|
16
|
+
|
|
3
17
|
## 0.13.8
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"polling.d.ts","sourceRoot":"","sources":["../../src/api/polling.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
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,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;AAwDF;;;;;;;GAOG;AACH,wBAAsB,iBAAiB,CAAC,OAAO,GAAG,OAAO,EACvD,OAAO,EAAE,WAAW,CAAC,OAAO,CAAC,GAC5B,OAAO,CAAC,OAAO,CAAC,CAyGlB"}
|
package/dist/api/polling.js
CHANGED
|
@@ -6,16 +6,14 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { ZapierTimeoutError, ZapierApiError, ZapierValidationError, } from "../types/errors";
|
|
8
8
|
import { setTimeout } from "timers/promises";
|
|
9
|
+
import { calculateWaitTime, MAX_CONSECUTIVE_ERRORS, } from "../utils/retry-utils";
|
|
9
10
|
// Constants
|
|
10
11
|
const DEFAULT_TIMEOUT_MS = 180000;
|
|
11
12
|
const DEFAULT_SUCCESS_STATUS = 200;
|
|
12
13
|
const DEFAULT_PENDING_STATUS = 202;
|
|
13
14
|
const DEFAULT_INITIAL_DELAY_MS = 50;
|
|
14
15
|
const DEFAULT_MAX_POLLING_INTERVAL_MS = 10000;
|
|
15
|
-
const MAX_CONSECUTIVE_ERRORS = 3;
|
|
16
16
|
const MAX_TIMEOUT_BUFFER_MS = 10000;
|
|
17
|
-
const BASE_ERROR_BACKOFF_MS = 1000;
|
|
18
|
-
const JITTER_FACTOR = 0.5;
|
|
19
17
|
// Polling stages: [threshold_ms, interval_ms]
|
|
20
18
|
// Note: These are default stages, actual hard timeout is enforced separately below
|
|
21
19
|
const DEFAULT_POLLING_STAGES = [
|
|
@@ -26,14 +24,6 @@ const DEFAULT_POLLING_STAGES = [
|
|
|
26
24
|
[30000, 2500], // Up to 30s: poll every 2.5s
|
|
27
25
|
[60000, 5000], // Up to 60s: poll every 5s
|
|
28
26
|
];
|
|
29
|
-
// Helper to calculate wait time with jitter and error backoff
|
|
30
|
-
const calculateWaitTime = (baseInterval, errorCount) => {
|
|
31
|
-
// Jitter to avoid thundering herd
|
|
32
|
-
const jitter = Math.random() * JITTER_FACTOR * baseInterval;
|
|
33
|
-
// More backoff added if errors are seen
|
|
34
|
-
const errorBackoff = Math.min(BASE_ERROR_BACKOFF_MS * (errorCount / 2), baseInterval * 2);
|
|
35
|
-
return Math.floor(baseInterval + jitter + errorBackoff);
|
|
36
|
-
};
|
|
37
27
|
const processResponse = async (response, successStatus, pendingStatus, resultExtractor, errorCount) => {
|
|
38
28
|
// Handle other error responses
|
|
39
29
|
if (!response.ok) {
|
package/dist/index.cjs
CHANGED
|
@@ -1812,6 +1812,64 @@ var RootFieldItemSchema = zod.z.union([
|
|
|
1812
1812
|
FieldsetItemSchema
|
|
1813
1813
|
]);
|
|
1814
1814
|
|
|
1815
|
+
// src/services/implementations.ts
|
|
1816
|
+
async function fetchImplementationNeeds({
|
|
1817
|
+
api,
|
|
1818
|
+
selectedApi,
|
|
1819
|
+
action,
|
|
1820
|
+
actionType,
|
|
1821
|
+
authenticationId,
|
|
1822
|
+
inputs
|
|
1823
|
+
}) {
|
|
1824
|
+
const request = {
|
|
1825
|
+
selected_api: selectedApi,
|
|
1826
|
+
action,
|
|
1827
|
+
type_of: actionType,
|
|
1828
|
+
params: inputs || {}
|
|
1829
|
+
};
|
|
1830
|
+
if (authenticationId !== null) {
|
|
1831
|
+
request.authentication_id = authenticationId;
|
|
1832
|
+
}
|
|
1833
|
+
const response = await api.post(
|
|
1834
|
+
"/api/v4/implementations/needs/",
|
|
1835
|
+
request
|
|
1836
|
+
);
|
|
1837
|
+
if (!response.success) {
|
|
1838
|
+
throw new ZapierApiError(
|
|
1839
|
+
`Failed to get input fields: ${response.errors?.join(", ") || "Unknown error"}`
|
|
1840
|
+
);
|
|
1841
|
+
}
|
|
1842
|
+
return response;
|
|
1843
|
+
}
|
|
1844
|
+
async function fetchImplementationChoices({
|
|
1845
|
+
api,
|
|
1846
|
+
actionId,
|
|
1847
|
+
inputFieldId,
|
|
1848
|
+
authenticationId,
|
|
1849
|
+
inputs,
|
|
1850
|
+
page
|
|
1851
|
+
}) {
|
|
1852
|
+
const request = {
|
|
1853
|
+
action_id: actionId,
|
|
1854
|
+
input_field_id: inputFieldId,
|
|
1855
|
+
page,
|
|
1856
|
+
params: inputs || {}
|
|
1857
|
+
};
|
|
1858
|
+
if (authenticationId !== null) {
|
|
1859
|
+
request.authentication_id = authenticationId;
|
|
1860
|
+
}
|
|
1861
|
+
const response = await api.post(
|
|
1862
|
+
"/api/v4/implementations/choices/",
|
|
1863
|
+
request
|
|
1864
|
+
);
|
|
1865
|
+
if (!response.success) {
|
|
1866
|
+
throw new ZapierApiError(
|
|
1867
|
+
`Failed to get input field choices: ${response.errors?.join(", ") || "Unknown error"}`
|
|
1868
|
+
);
|
|
1869
|
+
}
|
|
1870
|
+
return response;
|
|
1871
|
+
}
|
|
1872
|
+
|
|
1815
1873
|
// src/plugins/listInputFields/index.ts
|
|
1816
1874
|
function getInputFieldTypeFromNeed(need) {
|
|
1817
1875
|
if (need.list) {
|
|
@@ -1915,7 +1973,13 @@ var listInputFieldsPlugin = ({ sdk, context }) => {
|
|
|
1915
1973
|
const listInputFields = createPaginatedFunction(
|
|
1916
1974
|
async function listInputFieldsPage(options) {
|
|
1917
1975
|
const { api, getVersionedImplementationId } = context;
|
|
1918
|
-
const {
|
|
1976
|
+
const {
|
|
1977
|
+
appKey,
|
|
1978
|
+
actionKey,
|
|
1979
|
+
actionType,
|
|
1980
|
+
authenticationId = null,
|
|
1981
|
+
inputs
|
|
1982
|
+
} = options;
|
|
1919
1983
|
const selectedApi = await getVersionedImplementationId(appKey);
|
|
1920
1984
|
if (!selectedApi) {
|
|
1921
1985
|
throw new ZapierConfigurationError(
|
|
@@ -1928,24 +1992,14 @@ var listInputFieldsPlugin = ({ sdk, context }) => {
|
|
|
1928
1992
|
actionType,
|
|
1929
1993
|
actionKey
|
|
1930
1994
|
});
|
|
1931
|
-
const
|
|
1932
|
-
|
|
1995
|
+
const needsData = await fetchImplementationNeeds({
|
|
1996
|
+
api,
|
|
1997
|
+
selectedApi,
|
|
1933
1998
|
action: action.key,
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
needsRequest.authentication_id = authenticationId;
|
|
1939
|
-
}
|
|
1940
|
-
const needsData = await api.post(
|
|
1941
|
-
"/api/v4/implementations/needs/",
|
|
1942
|
-
needsRequest
|
|
1943
|
-
);
|
|
1944
|
-
if (!needsData.success) {
|
|
1945
|
-
throw new ZapierApiError(
|
|
1946
|
-
`Failed to get action fields: ${needsData.errors?.join(", ") || "Unknown error"}`
|
|
1947
|
-
);
|
|
1948
|
-
}
|
|
1999
|
+
actionType,
|
|
2000
|
+
authenticationId,
|
|
2001
|
+
inputs
|
|
2002
|
+
});
|
|
1949
2003
|
const rootFieldset = transformNeedsToFields(needsData.needs || []);
|
|
1950
2004
|
return {
|
|
1951
2005
|
data: rootFieldset,
|
|
@@ -3101,15 +3155,28 @@ function createDebugFetch(options) {
|
|
|
3101
3155
|
}
|
|
3102
3156
|
};
|
|
3103
3157
|
}
|
|
3158
|
+
|
|
3159
|
+
// src/utils/retry-utils.ts
|
|
3160
|
+
var MAX_CONSECUTIVE_ERRORS = 3;
|
|
3161
|
+
var BASE_ERROR_BACKOFF_MS = 1e3;
|
|
3162
|
+
var JITTER_FACTOR = 0.5;
|
|
3163
|
+
function calculateWaitTime(baseInterval, errorCount) {
|
|
3164
|
+
const jitter = Math.random() * JITTER_FACTOR * baseInterval;
|
|
3165
|
+
const errorBackoff = Math.min(
|
|
3166
|
+
BASE_ERROR_BACKOFF_MS * (errorCount / 2),
|
|
3167
|
+
baseInterval * 2
|
|
3168
|
+
// Cap error backoff at 2x the base interval
|
|
3169
|
+
);
|
|
3170
|
+
return Math.floor(baseInterval + jitter + errorBackoff);
|
|
3171
|
+
}
|
|
3172
|
+
|
|
3173
|
+
// src/api/polling.ts
|
|
3104
3174
|
var DEFAULT_TIMEOUT_MS = 18e4;
|
|
3105
3175
|
var DEFAULT_SUCCESS_STATUS = 200;
|
|
3106
3176
|
var DEFAULT_PENDING_STATUS = 202;
|
|
3107
3177
|
var DEFAULT_INITIAL_DELAY_MS = 50;
|
|
3108
3178
|
var DEFAULT_MAX_POLLING_INTERVAL_MS = 1e4;
|
|
3109
|
-
var MAX_CONSECUTIVE_ERRORS = 3;
|
|
3110
3179
|
var MAX_TIMEOUT_BUFFER_MS = 1e4;
|
|
3111
|
-
var BASE_ERROR_BACKOFF_MS = 1e3;
|
|
3112
|
-
var JITTER_FACTOR = 0.5;
|
|
3113
3180
|
var DEFAULT_POLLING_STAGES = [
|
|
3114
3181
|
[125, 125],
|
|
3115
3182
|
// Up to 125ms: poll every 125ms
|
|
@@ -3124,15 +3191,6 @@ var DEFAULT_POLLING_STAGES = [
|
|
|
3124
3191
|
[6e4, 5e3]
|
|
3125
3192
|
// Up to 60s: poll every 5s
|
|
3126
3193
|
];
|
|
3127
|
-
var calculateWaitTime = (baseInterval, errorCount) => {
|
|
3128
|
-
const jitter = Math.random() * JITTER_FACTOR * baseInterval;
|
|
3129
|
-
const errorBackoff = Math.min(
|
|
3130
|
-
BASE_ERROR_BACKOFF_MS * (errorCount / 2),
|
|
3131
|
-
baseInterval * 2
|
|
3132
|
-
// Cap error backoff at 2x the base interval
|
|
3133
|
-
);
|
|
3134
|
-
return Math.floor(baseInterval + jitter + errorBackoff);
|
|
3135
|
-
};
|
|
3136
3194
|
var processResponse = async (response, successStatus, pendingStatus, resultExtractor, errorCount) => {
|
|
3137
3195
|
if (!response.ok) {
|
|
3138
3196
|
return {
|
|
@@ -3613,6 +3671,94 @@ var apiPlugin = (params) => {
|
|
|
3613
3671
|
}
|
|
3614
3672
|
};
|
|
3615
3673
|
};
|
|
3674
|
+
var DEFAULT_CONCURRENCY = 10;
|
|
3675
|
+
var BATCH_START_DELAY_MS = 25;
|
|
3676
|
+
var DEFAULT_BATCH_TIMEOUT_MS = 18e4;
|
|
3677
|
+
async function batch(tasks, options = {}) {
|
|
3678
|
+
const {
|
|
3679
|
+
concurrency = DEFAULT_CONCURRENCY,
|
|
3680
|
+
retry = true,
|
|
3681
|
+
batchDelay = BATCH_START_DELAY_MS,
|
|
3682
|
+
timeoutMs = DEFAULT_BATCH_TIMEOUT_MS,
|
|
3683
|
+
taskTimeoutMs
|
|
3684
|
+
} = options;
|
|
3685
|
+
if (concurrency <= 0) {
|
|
3686
|
+
throw new Error("Concurrency must be greater than 0");
|
|
3687
|
+
}
|
|
3688
|
+
if (timeoutMs <= 0) {
|
|
3689
|
+
throw new Error("Timeout must be greater than 0");
|
|
3690
|
+
}
|
|
3691
|
+
if (taskTimeoutMs !== void 0 && taskTimeoutMs <= 0) {
|
|
3692
|
+
throw new Error("Task timeout must be greater than 0");
|
|
3693
|
+
}
|
|
3694
|
+
if (tasks.length === 0) {
|
|
3695
|
+
return [];
|
|
3696
|
+
}
|
|
3697
|
+
const startTime = Date.now();
|
|
3698
|
+
const results = new Array(tasks.length);
|
|
3699
|
+
const taskQueue = tasks.map((task, index) => ({
|
|
3700
|
+
index,
|
|
3701
|
+
task,
|
|
3702
|
+
errorCount: 0
|
|
3703
|
+
}));
|
|
3704
|
+
async function executeTask(taskState) {
|
|
3705
|
+
const { index, task, errorCount } = taskState;
|
|
3706
|
+
try {
|
|
3707
|
+
let result;
|
|
3708
|
+
if (taskTimeoutMs !== void 0) {
|
|
3709
|
+
const timeoutPromise = promises.setTimeout(taskTimeoutMs).then(() => {
|
|
3710
|
+
throw new ZapierTimeoutError(
|
|
3711
|
+
`Task timed out after ${taskTimeoutMs}ms`
|
|
3712
|
+
);
|
|
3713
|
+
});
|
|
3714
|
+
result = await Promise.race([task(), timeoutPromise]);
|
|
3715
|
+
} else {
|
|
3716
|
+
result = await task();
|
|
3717
|
+
}
|
|
3718
|
+
results[index] = { status: "fulfilled", value: result };
|
|
3719
|
+
} catch (error) {
|
|
3720
|
+
const newErrorCount = errorCount + 1;
|
|
3721
|
+
const isTimeout = error instanceof ZapierTimeoutError;
|
|
3722
|
+
if (retry && !isTimeout && newErrorCount < MAX_CONSECUTIVE_ERRORS) {
|
|
3723
|
+
const waitTime = calculateWaitTime(1e3, newErrorCount);
|
|
3724
|
+
await promises.setTimeout(waitTime);
|
|
3725
|
+
taskQueue.push({
|
|
3726
|
+
index,
|
|
3727
|
+
task,
|
|
3728
|
+
errorCount: newErrorCount
|
|
3729
|
+
});
|
|
3730
|
+
} else {
|
|
3731
|
+
results[index] = { status: "rejected", reason: error };
|
|
3732
|
+
}
|
|
3733
|
+
}
|
|
3734
|
+
}
|
|
3735
|
+
async function worker() {
|
|
3736
|
+
while (taskQueue.length > 0) {
|
|
3737
|
+
const elapsedTime = Date.now() - startTime;
|
|
3738
|
+
if (elapsedTime >= timeoutMs) {
|
|
3739
|
+
throw new ZapierTimeoutError(
|
|
3740
|
+
`Batch operation timed out after ${Math.floor(elapsedTime / 1e3)}s. ${taskQueue.length} task(s) not completed.`
|
|
3741
|
+
);
|
|
3742
|
+
}
|
|
3743
|
+
const taskState = taskQueue.shift();
|
|
3744
|
+
if (!taskState) break;
|
|
3745
|
+
await executeTask(taskState);
|
|
3746
|
+
if (taskQueue.length > 0 && batchDelay > 0) {
|
|
3747
|
+
await promises.setTimeout(batchDelay);
|
|
3748
|
+
}
|
|
3749
|
+
}
|
|
3750
|
+
}
|
|
3751
|
+
const workerCount = Math.min(concurrency, tasks.length);
|
|
3752
|
+
const workers = [];
|
|
3753
|
+
for (let i = 0; i < workerCount; i++) {
|
|
3754
|
+
workers.push(worker());
|
|
3755
|
+
if (i < workerCount - 1 && batchDelay > 0) {
|
|
3756
|
+
await promises.setTimeout(batchDelay / 10);
|
|
3757
|
+
}
|
|
3758
|
+
}
|
|
3759
|
+
await Promise.all(workers);
|
|
3760
|
+
return results;
|
|
3761
|
+
}
|
|
3616
3762
|
|
|
3617
3763
|
// src/plugins/registry/index.ts
|
|
3618
3764
|
var registryPlugin = ({ sdk, context }) => {
|
|
@@ -3763,43 +3909,62 @@ function transformNeedChoicesToInputFieldChoiceItem(choice) {
|
|
|
3763
3909
|
}
|
|
3764
3910
|
var listInputFieldChoicesPlugin = ({ context, sdk }) => {
|
|
3765
3911
|
const listInputFieldChoices = createPaginatedFunction(async function listInputFieldChoicesPage(options) {
|
|
3766
|
-
const { api } = context;
|
|
3912
|
+
const { api, getVersionedImplementationId } = context;
|
|
3767
3913
|
const {
|
|
3768
3914
|
appKey,
|
|
3769
3915
|
actionType,
|
|
3770
3916
|
actionKey,
|
|
3771
3917
|
inputFieldKey,
|
|
3772
|
-
authenticationId,
|
|
3918
|
+
authenticationId = null,
|
|
3773
3919
|
inputs,
|
|
3774
3920
|
page,
|
|
3775
3921
|
cursor
|
|
3776
3922
|
} = options;
|
|
3777
|
-
const
|
|
3778
|
-
|
|
3779
|
-
|
|
3780
|
-
|
|
3781
|
-
|
|
3923
|
+
const selectedApi = await getVersionedImplementationId(appKey);
|
|
3924
|
+
if (!selectedApi) {
|
|
3925
|
+
throw new ZapierConfigurationError(
|
|
3926
|
+
"No current_implementation_id found for app",
|
|
3927
|
+
{ configType: "current_implementation_id" }
|
|
3782
3928
|
);
|
|
3783
3929
|
}
|
|
3784
|
-
const
|
|
3785
|
-
|
|
3786
|
-
|
|
3787
|
-
|
|
3788
|
-
|
|
3789
|
-
|
|
3790
|
-
|
|
3791
|
-
|
|
3792
|
-
|
|
3793
|
-
|
|
3794
|
-
|
|
3795
|
-
|
|
3796
|
-
|
|
3930
|
+
const { data: action } = await sdk.getAction({
|
|
3931
|
+
appKey,
|
|
3932
|
+
actionType,
|
|
3933
|
+
actionKey
|
|
3934
|
+
});
|
|
3935
|
+
const needsData = await fetchImplementationNeeds({
|
|
3936
|
+
api,
|
|
3937
|
+
selectedApi,
|
|
3938
|
+
action: action.key,
|
|
3939
|
+
actionType,
|
|
3940
|
+
authenticationId,
|
|
3941
|
+
inputs
|
|
3942
|
+
});
|
|
3943
|
+
const targetNeed = needsData.needs?.find(
|
|
3944
|
+
(need) => need.key === inputFieldKey
|
|
3797
3945
|
);
|
|
3798
|
-
if (
|
|
3946
|
+
if (targetNeed?.choices && targetNeed.choices.length > 0) {
|
|
3947
|
+
return {
|
|
3948
|
+
data: targetNeed.choices.map(
|
|
3949
|
+
transformNeedChoicesToInputFieldChoiceItem
|
|
3950
|
+
),
|
|
3951
|
+
nextCursor: void 0
|
|
3952
|
+
};
|
|
3953
|
+
}
|
|
3954
|
+
if (!action.id) {
|
|
3799
3955
|
throw new ZapierApiError(
|
|
3800
|
-
`
|
|
3956
|
+
`Action ${actionKey} does not have an ID - cannot retrieve input field choices`
|
|
3801
3957
|
);
|
|
3802
3958
|
}
|
|
3959
|
+
const requestPage = cursor ? parseInt(cursor, 10) : page ?? 0;
|
|
3960
|
+
const choicesData = await fetchImplementationChoices({
|
|
3961
|
+
api,
|
|
3962
|
+
actionId: action.id,
|
|
3963
|
+
inputFieldId: inputFieldKey,
|
|
3964
|
+
authenticationId,
|
|
3965
|
+
inputs,
|
|
3966
|
+
page: requestPage
|
|
3967
|
+
});
|
|
3803
3968
|
const choices = (choicesData.choices || []).map(
|
|
3804
3969
|
transformNeedChoicesToInputFieldChoiceItem
|
|
3805
3970
|
);
|
|
@@ -3997,7 +4162,7 @@ function getCpuTime() {
|
|
|
3997
4162
|
|
|
3998
4163
|
// package.json
|
|
3999
4164
|
var package_default = {
|
|
4000
|
-
version: "0.
|
|
4165
|
+
version: "0.14.0"};
|
|
4001
4166
|
|
|
4002
4167
|
// src/plugins/eventEmission/builders.ts
|
|
4003
4168
|
function createBaseEvent(context = {}) {
|
|
@@ -4399,6 +4564,7 @@ exports.appKeyResolver = appKeyResolver;
|
|
|
4399
4564
|
exports.appsPlugin = appsPlugin;
|
|
4400
4565
|
exports.authenticationIdGenericResolver = authenticationIdGenericResolver;
|
|
4401
4566
|
exports.authenticationIdResolver = authenticationIdResolver;
|
|
4567
|
+
exports.batch = batch;
|
|
4402
4568
|
exports.buildApplicationLifecycleEvent = buildApplicationLifecycleEvent;
|
|
4403
4569
|
exports.buildErrorEvent = buildErrorEvent;
|
|
4404
4570
|
exports.buildErrorEventWithContext = buildErrorEventWithContext;
|
package/dist/index.d.mts
CHANGED
|
@@ -3133,6 +3133,78 @@ declare function toTitleCase(input: string): string;
|
|
|
3133
3133
|
*/
|
|
3134
3134
|
declare function toSnakeCase(input: string): string;
|
|
3135
3135
|
|
|
3136
|
+
/**
|
|
3137
|
+
* Batch Operation Utilities
|
|
3138
|
+
*
|
|
3139
|
+
* This module provides utilities for executing multiple async operations
|
|
3140
|
+
* with concurrency control and retry logic.
|
|
3141
|
+
*/
|
|
3142
|
+
/**
|
|
3143
|
+
* Options for batch execution
|
|
3144
|
+
*/
|
|
3145
|
+
interface BatchOptions {
|
|
3146
|
+
/**
|
|
3147
|
+
* Maximum number of concurrent operations (default: 10)
|
|
3148
|
+
* Lower values are more "polite" but slower
|
|
3149
|
+
* Higher values are faster but risk rate limits
|
|
3150
|
+
*/
|
|
3151
|
+
concurrency?: number;
|
|
3152
|
+
/**
|
|
3153
|
+
* Whether to retry failed operations (default: true)
|
|
3154
|
+
* When enabled, each operation gets up to MAX_CONSECUTIVE_ERRORS retries
|
|
3155
|
+
*/
|
|
3156
|
+
retry?: boolean;
|
|
3157
|
+
/**
|
|
3158
|
+
* Delay in milliseconds between starting batches (default: 100ms)
|
|
3159
|
+
* Adds a small delay between concurrent batches to avoid burst patterns
|
|
3160
|
+
*/
|
|
3161
|
+
batchDelay?: number;
|
|
3162
|
+
/**
|
|
3163
|
+
* Overall timeout for the entire batch operation in milliseconds (default: 180000ms / 3 minutes)
|
|
3164
|
+
* When exceeded, throws ZapierTimeoutError and stops processing remaining tasks
|
|
3165
|
+
*/
|
|
3166
|
+
timeoutMs?: number;
|
|
3167
|
+
/**
|
|
3168
|
+
* Timeout for individual tasks in milliseconds (default: none)
|
|
3169
|
+
* When set, each task will be cancelled if it exceeds this duration
|
|
3170
|
+
* Tasks that timeout will be marked as rejected in the results
|
|
3171
|
+
*/
|
|
3172
|
+
taskTimeoutMs?: number;
|
|
3173
|
+
}
|
|
3174
|
+
/**
|
|
3175
|
+
* Execute multiple async operations with concurrency limiting and retry logic
|
|
3176
|
+
*
|
|
3177
|
+
* This prevents overwhelming APIs by:
|
|
3178
|
+
* 1. Limiting concurrent operations (worker pool pattern)
|
|
3179
|
+
* 2. Adding small delays between batches to avoid burst detection
|
|
3180
|
+
* 3. Retrying failed operations with exponential backoff
|
|
3181
|
+
*
|
|
3182
|
+
* Problem Solved:
|
|
3183
|
+
* - Rate limit prevention: Steady stream instead of burst requests
|
|
3184
|
+
* - Connection pool management: Stays within browser/Node limits (~6-8 per domain)
|
|
3185
|
+
* - Resilience: Transient failures are retried automatically
|
|
3186
|
+
* - Observability: Returns detailed success/failure info for each operation
|
|
3187
|
+
*
|
|
3188
|
+
* Example Usage:
|
|
3189
|
+
* ```typescript
|
|
3190
|
+
* // Instead of Promise.allSettled (fires all at once):
|
|
3191
|
+
* const results = await Promise.allSettled(
|
|
3192
|
+
* actions.map(a => sdk.listInputFields(a))
|
|
3193
|
+
* );
|
|
3194
|
+
*
|
|
3195
|
+
* // Use batch (controlled concurrency):
|
|
3196
|
+
* const results = await batch(
|
|
3197
|
+
* actions.map(a => () => sdk.listInputFields(a)),
|
|
3198
|
+
* { concurrency: 10, retry: true }
|
|
3199
|
+
* );
|
|
3200
|
+
* ```
|
|
3201
|
+
*
|
|
3202
|
+
* @param tasks - Array of functions that return promises (NOT promises themselves!)
|
|
3203
|
+
* @param options - Configuration for concurrency and retry behavior
|
|
3204
|
+
* @returns Promise resolving to array of settled results (same as Promise.allSettled)
|
|
3205
|
+
*/
|
|
3206
|
+
declare function batch<T>(tasks: (() => Promise<T>)[], options?: BatchOptions): Promise<PromiseSettledResult<T>[]>;
|
|
3207
|
+
|
|
3136
3208
|
declare const appKeyResolver: StaticResolver;
|
|
3137
3209
|
|
|
3138
3210
|
interface ActionTypeItem {
|
|
@@ -3346,4 +3418,4 @@ declare function createZapierSdkWithoutRegistry(options?: ZapierSdkOptions): Sdk
|
|
|
3346
3418
|
}>;
|
|
3347
3419
|
declare function createZapierSdk(options?: ZapierSdkOptions): ZapierSdk;
|
|
3348
3420
|
|
|
3349
|
-
export { type Action, type ActionExecutionOptions, type ActionExecutionResult, type ActionField, type ActionFieldChoice, type ActionItem$1 as ActionItem, type ActionKeyProperty, ActionKeyPropertySchema, type ActionTypeProperty, ActionTypePropertySchema, type ApiError, type ApiEvent, type ApiPluginOptions, type ApiPluginProvides, type App, type AppItem, type AppKeyProperty, AppKeyPropertySchema, type ApplicationLifecycleEventData, type AppsPluginProvides, type AuthEvent, type AuthOptions, type Authentication, type AuthenticationIdProperty, AuthenticationIdPropertySchema, type AuthenticationItem, type AuthenticationsResponse, type BaseEvent, type Choice, DEFAULT_CONFIG_PATH, type DebugProperty, DebugPropertySchema, 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 ListInputFieldsPluginProvides, type LoadingEvent, MAX_PAGE_LIMIT, type Manifest, type ManifestEntry, type ManifestPluginOptions, type ManifestPluginProvides, type Need, type NeedsRequest, type NeedsResponse, type OffsetProperty, OffsetPropertySchema, type OutputProperty, OutputPropertySchema, type PaginatedSdkFunction, type ParamsProperty, ParamsPropertySchema, type Plugin, type PluginDependencies, type PluginOptions, type PluginProvides, type PositionalMetadata, RelayFetchSchema, RelayRequestSchema, type RequestPluginProvides, type RootFieldItem, type RunActionPluginProvides, type Sdk, type SdkEvent, type UpdateManifestEntryOptions, type UserProfile, type UserProfileItem, ZAPIER_BASE_URL, 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, buildApplicationLifecycleEvent, buildErrorEvent, buildErrorEventWithContext, createBaseEvent, createFunction, createSdk, createZapierSdk, createZapierSdkWithoutRegistry, fetchPlugin, findFirstAuthenticationPlugin, findManifestEntry, findUniqueAuthenticationPlugin, formatErrorMessage, generateEventId, getActionPlugin, getAppPlugin, getAuthenticationPlugin, getCiPlatform, getCpuTime, getCurrentTimestamp, getMemoryUsage, getOsInfo, getPlatformVersions, getPreferredManifestEntryKey, getProfilePlugin, getReleaseId, getTokenFromCliLogin, getTokenFromEnv, getTokenFromEnvOrConfig, inputFieldKeyResolver, inputsAllOptionalResolver, inputsResolver, isCi, isPositional, listActionsPlugin, listAppsPlugin, listAuthenticationsPlugin, listInputFieldsPlugin, manifestPlugin, readManifestFromFile, registryPlugin, requestPlugin, runActionPlugin, toSnakeCase, toTitleCase };
|
|
3421
|
+
export { type Action, type ActionExecutionOptions, type ActionExecutionResult, type ActionField, type ActionFieldChoice, type ActionItem$1 as ActionItem, type ActionKeyProperty, ActionKeyPropertySchema, type ActionTypeProperty, ActionTypePropertySchema, type ApiError, type ApiEvent, type ApiPluginOptions, type ApiPluginProvides, type App, type AppItem, type AppKeyProperty, AppKeyPropertySchema, type ApplicationLifecycleEventData, type AppsPluginProvides, type AuthEvent, type AuthOptions, type Authentication, type AuthenticationIdProperty, AuthenticationIdPropertySchema, type AuthenticationItem, type AuthenticationsResponse, type BaseEvent, type BatchOptions, type Choice, DEFAULT_CONFIG_PATH, type DebugProperty, DebugPropertySchema, 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 ListInputFieldsPluginProvides, type LoadingEvent, MAX_PAGE_LIMIT, type Manifest, type ManifestEntry, type ManifestPluginOptions, type ManifestPluginProvides, type Need, type NeedsRequest, type NeedsResponse, type OffsetProperty, OffsetPropertySchema, type OutputProperty, OutputPropertySchema, type PaginatedSdkFunction, type ParamsProperty, ParamsPropertySchema, type Plugin, type PluginDependencies, type PluginOptions, type PluginProvides, type PositionalMetadata, RelayFetchSchema, RelayRequestSchema, type RequestPluginProvides, type RootFieldItem, type RunActionPluginProvides, type Sdk, type SdkEvent, type UpdateManifestEntryOptions, type UserProfile, type UserProfileItem, ZAPIER_BASE_URL, 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, createBaseEvent, createFunction, createSdk, createZapierSdk, createZapierSdkWithoutRegistry, fetchPlugin, findFirstAuthenticationPlugin, findManifestEntry, findUniqueAuthenticationPlugin, formatErrorMessage, generateEventId, getActionPlugin, getAppPlugin, getAuthenticationPlugin, getCiPlatform, getCpuTime, getCurrentTimestamp, getMemoryUsage, getOsInfo, getPlatformVersions, getPreferredManifestEntryKey, getProfilePlugin, getReleaseId, getTokenFromCliLogin, getTokenFromEnv, getTokenFromEnvOrConfig, inputFieldKeyResolver, inputsAllOptionalResolver, inputsResolver, isCi, isPositional, listActionsPlugin, listAppsPlugin, listAuthenticationsPlugin, listInputFieldsPlugin, manifestPlugin, readManifestFromFile, registryPlugin, requestPlugin, runActionPlugin, toSnakeCase, toTitleCase };
|
package/dist/index.d.ts
CHANGED
|
@@ -23,6 +23,8 @@ export { isPositional, PositionalMetadata } from "./utils/schema-utils";
|
|
|
23
23
|
export { createFunction } from "./utils/function-utils";
|
|
24
24
|
export type { FormattedItem, FormatMetadata } from "./utils/schema-utils";
|
|
25
25
|
export { toSnakeCase, toTitleCase } from "./utils/string-utils";
|
|
26
|
+
export { batch } from "./utils/batch-utils";
|
|
27
|
+
export type { BatchOptions } from "./utils/batch-utils";
|
|
26
28
|
export * from "./resolvers";
|
|
27
29
|
export * from "./auth";
|
|
28
30
|
export * from "./constants";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,mCAAmC,CAAC;AAClD,cAAc,oCAAoC,CAAC;AACnD,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC;AAG9B,YAAY,EACV,MAAM,EACN,GAAG,EACH,IAAI,EACJ,KAAK,EACL,MAAM,EACN,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gBAAgB,GACjB,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EACL,eAAe,EACf,8BAA8B,EAC9B,SAAS,EACT,gBAAgB,GACjB,MAAM,OAAO,CAAC;AAGf,YAAY,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAGzD,YAAY,EACV,MAAM,EACN,cAAc,EACd,kBAAkB,EAClB,aAAa,EACb,UAAU,EACV,cAAc,EACd,GAAG,GACJ,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAGpD,YAAY,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAG7C,YAAY,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC1D,YAAY,EACV,oBAAoB,EACpB,YAAY,EACZ,6BAA6B,EAC7B,sBAAsB,GACvB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,YAAY,EACZ,SAAS,EACT,mBAAmB,EACnB,IAAI,EACJ,aAAa,EACb,cAAc,EACd,UAAU,EACV,8BAA8B,EAC9B,0BAA0B,EAC1B,eAAe,EACf,eAAe,GAChB,MAAM,yBAAyB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -24,6 +24,8 @@ export { isPositional } from "./utils/schema-utils";
|
|
|
24
24
|
export { createFunction } from "./utils/function-utils";
|
|
25
25
|
// Export string utilities
|
|
26
26
|
export { toSnakeCase, toTitleCase } from "./utils/string-utils";
|
|
27
|
+
// Export batch utilities
|
|
28
|
+
export { batch } from "./utils/batch-utils";
|
|
27
29
|
// Export resolver utilities for CLI
|
|
28
30
|
export * from "./resolvers";
|
|
29
31
|
// Export auth utilities for CLI use
|