@zapier/zapier-sdk 0.49.0 → 0.51.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 +25 -0
- package/README.md +15 -12
- package/dist/api/auth.d.ts +1 -6
- package/dist/api/auth.d.ts.map +1 -1
- package/dist/api/auth.js +34 -27
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +20 -17
- package/dist/api/index.d.ts +1 -1
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +1 -1
- package/dist/api/schemas.d.ts +3 -3
- package/dist/api/types.d.ts +8 -7
- package/dist/api/types.d.ts.map +1 -1
- package/dist/auth.d.ts +13 -2
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +95 -11
- package/dist/constants.d.ts +8 -9
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +8 -11
- package/dist/experimental.cjs +184 -52
- package/dist/experimental.d.mts +2 -2
- package/dist/experimental.d.ts +26 -26
- package/dist/experimental.mjs +183 -52
- package/dist/{index-C2vsvjgN.d.mts → index-C52BjTXh.d.mts} +124 -18
- package/dist/{index-C2vsvjgN.d.ts → index-C52BjTXh.d.ts} +124 -18
- package/dist/index.cjs +184 -52
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.mjs +183 -52
- package/dist/plugins/api/index.d.ts.map +1 -1
- package/dist/plugins/api/index.js +1 -2
- package/dist/plugins/apps/index.d.ts +2 -2
- package/dist/plugins/deprecated/inputFields.d.ts +18 -18
- package/dist/plugins/getAction/index.d.ts +6 -6
- package/dist/plugins/getAction/schemas.d.ts +4 -4
- package/dist/plugins/getActionInputFieldsSchema/index.d.ts +5 -5
- package/dist/plugins/getActionInputFieldsSchema/schemas.d.ts +4 -4
- package/dist/plugins/listActionInputFieldChoices/index.d.ts +5 -5
- package/dist/plugins/listActionInputFieldChoices/schemas.d.ts +4 -4
- package/dist/plugins/listActionInputFields/index.d.ts +5 -5
- package/dist/plugins/listActionInputFields/schemas.d.ts +4 -4
- package/dist/plugins/listActions/index.d.ts +3 -3
- package/dist/plugins/listActions/schemas.d.ts +4 -4
- package/dist/plugins/runAction/index.d.ts +5 -5
- package/dist/plugins/runAction/schemas.d.ts +4 -4
- package/dist/plugins/triggers/getTriggerInputFieldsSchema/index.d.ts +2 -2
- package/dist/plugins/triggers/listTriggerInputFieldChoices/index.d.ts +2 -2
- package/dist/plugins/triggers/listTriggerInputFields/index.d.ts +2 -2
- package/dist/schemas/Action.d.ts +1 -1
- package/dist/sdk.d.ts +52 -52
- package/dist/types/errors.d.ts +5 -5
- package/dist/types/properties.d.ts +1 -1
- package/dist/types/sdk.d.ts +2 -2
- package/dist/types/sdk.d.ts.map +1 -1
- package/dist/types/sdk.js +4 -11
- package/dist/utils/telemetry.d.ts +11 -0
- package/dist/utils/telemetry.d.ts.map +1 -0
- package/dist/utils/telemetry.js +19 -0
- package/package.json +1 -1
package/dist/constants.d.ts
CHANGED
|
@@ -30,20 +30,19 @@ export declare const DEFAULT_ACTION_TIMEOUT_MS = 180000;
|
|
|
30
30
|
*/
|
|
31
31
|
export declare const ZAPIER_MAX_NETWORK_RETRIES: number;
|
|
32
32
|
export declare const ZAPIER_MAX_NETWORK_RETRY_DELAY_MS: number;
|
|
33
|
-
/**
|
|
34
|
-
* Whether this session is interactive (user can visit approval URLs).
|
|
35
|
-
*
|
|
36
|
-
* Read lazily so tests can set the env var after module import.
|
|
37
|
-
*/
|
|
38
|
-
export declare function getZapierIsInteractive(): boolean;
|
|
39
33
|
/**
|
|
40
34
|
* Approval flow behavior from environment variable.
|
|
41
|
-
* - "
|
|
42
|
-
*
|
|
35
|
+
* - "disabled": (default when env var is unset) Throw a ZapierApprovalError on
|
|
36
|
+
* approval-required responses without creating an approval. Callers must
|
|
37
|
+
* explicitly opt in to approvals via "poll" or "throw".
|
|
38
|
+
* - "poll": Create the approval, open the URL in a browser, poll until
|
|
39
|
+
* resolved, and retry the original request on success.
|
|
40
|
+
* - "throw": Create the approval and throw a ZapierApprovalError immediately
|
|
41
|
+
* with the approval URL so the caller can surface it.
|
|
43
42
|
*
|
|
44
43
|
* Read lazily so tests can set the env var after module import.
|
|
45
44
|
*/
|
|
46
|
-
export declare function getZapierApprovalMode(): "poll" | "
|
|
45
|
+
export declare function getZapierApprovalMode(): "disabled" | "poll" | "throw" | undefined;
|
|
47
46
|
/**
|
|
48
47
|
* Default timeout for approval polling (10 minutes)
|
|
49
48
|
*/
|
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,QACsC,CAAC;AAEnE;;;;GAIG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,GAAG,SAAS,CAExD;AAED;;GAEG;AACH,eAAO,MAAM,cAAc,QAAQ,CAAC;AAEpC;;GAEG;AACH,eAAO,MAAM,iBAAiB,MAAM,CAAC;AAErC;;GAEG;AACH,eAAO,MAAM,yBAAyB,SAAU,CAAC;AAejD;;GAEG;AACH,eAAO,MAAM,0BAA0B,QACY,CAAC;AACpD,eAAO,MAAM,iCAAiC,QACiB,CAAC;AAEhE
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,eAAO,MAAM,eAAe,QACsC,CAAC;AAEnE;;;;GAIG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,GAAG,SAAS,CAExD;AAED;;GAEG;AACH,eAAO,MAAM,cAAc,QAAQ,CAAC;AAEpC;;GAEG;AACH,eAAO,MAAM,iBAAiB,MAAM,CAAC;AAErC;;GAEG;AACH,eAAO,MAAM,yBAAyB,SAAU,CAAC;AAejD;;GAEG;AACH,eAAO,MAAM,0BAA0B,QACY,CAAC;AACpD,eAAO,MAAM,iCAAiC,QACiB,CAAC;AAEhE;;;;;;;;;;;GAWG;AACH,wBAAgB,qBAAqB,IACjC,UAAU,GACV,MAAM,GACN,OAAO,GACP,SAAS,CAKZ;AAED;;GAEG;AACH,eAAO,MAAM,2BAA2B,QAAiB,CAAC;AAE1D;;;;;GAKG;AACH,eAAO,MAAM,4BAA4B,IAAI,CAAC"}
|
package/dist/constants.js
CHANGED
|
@@ -43,24 +43,21 @@ function parseIntEnvVar(name) {
|
|
|
43
43
|
*/
|
|
44
44
|
export const ZAPIER_MAX_NETWORK_RETRIES = parseIntEnvVar("ZAPIER_MAX_NETWORK_RETRIES") ?? 3;
|
|
45
45
|
export const ZAPIER_MAX_NETWORK_RETRY_DELAY_MS = parseIntEnvVar("ZAPIER_MAX_NETWORK_RETRY_DELAY_MS") ?? 60000;
|
|
46
|
-
/**
|
|
47
|
-
* Whether this session is interactive (user can visit approval URLs).
|
|
48
|
-
*
|
|
49
|
-
* Read lazily so tests can set the env var after module import.
|
|
50
|
-
*/
|
|
51
|
-
export function getZapierIsInteractive() {
|
|
52
|
-
return globalThis.process?.env?.ZAPIER_IS_INTERACTIVE === "true";
|
|
53
|
-
}
|
|
54
46
|
/**
|
|
55
47
|
* Approval flow behavior from environment variable.
|
|
56
|
-
* - "
|
|
57
|
-
*
|
|
48
|
+
* - "disabled": (default when env var is unset) Throw a ZapierApprovalError on
|
|
49
|
+
* approval-required responses without creating an approval. Callers must
|
|
50
|
+
* explicitly opt in to approvals via "poll" or "throw".
|
|
51
|
+
* - "poll": Create the approval, open the URL in a browser, poll until
|
|
52
|
+
* resolved, and retry the original request on success.
|
|
53
|
+
* - "throw": Create the approval and throw a ZapierApprovalError immediately
|
|
54
|
+
* with the approval URL so the caller can surface it.
|
|
58
55
|
*
|
|
59
56
|
* Read lazily so tests can set the env var after module import.
|
|
60
57
|
*/
|
|
61
58
|
export function getZapierApprovalMode() {
|
|
62
59
|
const value = globalThis.process?.env?.ZAPIER_APPROVAL_MODE;
|
|
63
|
-
if (value === "poll" || value === "
|
|
60
|
+
if (value === "disabled" || value === "poll" || value === "throw")
|
|
64
61
|
return value;
|
|
65
62
|
return undefined;
|
|
66
63
|
}
|
package/dist/experimental.cjs
CHANGED
|
@@ -150,12 +150,10 @@ function parseIntEnvVar(name) {
|
|
|
150
150
|
}
|
|
151
151
|
var ZAPIER_MAX_NETWORK_RETRIES = parseIntEnvVar("ZAPIER_MAX_NETWORK_RETRIES") ?? 3;
|
|
152
152
|
var ZAPIER_MAX_NETWORK_RETRY_DELAY_MS = parseIntEnvVar("ZAPIER_MAX_NETWORK_RETRY_DELAY_MS") ?? 6e4;
|
|
153
|
-
function getZapierIsInteractive() {
|
|
154
|
-
return globalThis.process?.env?.ZAPIER_IS_INTERACTIVE === "true";
|
|
155
|
-
}
|
|
156
153
|
function getZapierApprovalMode() {
|
|
157
154
|
const value = globalThis.process?.env?.ZAPIER_APPROVAL_MODE;
|
|
158
|
-
if (value === "
|
|
155
|
+
if (value === "disabled" || value === "poll" || value === "throw")
|
|
156
|
+
return value;
|
|
159
157
|
return void 0;
|
|
160
158
|
}
|
|
161
159
|
var DEFAULT_APPROVAL_TIMEOUT_MS = 10 * 60 * 1e3;
|
|
@@ -1838,33 +1836,40 @@ function getAuthorizationHeader(token) {
|
|
|
1838
1836
|
}
|
|
1839
1837
|
return `Bearer ${token}`;
|
|
1840
1838
|
}
|
|
1841
|
-
function
|
|
1839
|
+
function readJwtPayload(token) {
|
|
1842
1840
|
const parts = parseJwt(token);
|
|
1843
|
-
if (!parts)
|
|
1844
|
-
|
|
1845
|
-
}
|
|
1841
|
+
if (!parts) return null;
|
|
1842
|
+
let payload;
|
|
1846
1843
|
try {
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1844
|
+
payload = JSON.parse(Buffer.from(parts[1], "base64url").toString("utf-8"));
|
|
1845
|
+
} catch {
|
|
1846
|
+
return null;
|
|
1847
|
+
}
|
|
1848
|
+
if (payload["sub_type"] === "service" && typeof payload["njwt"] === "string") {
|
|
1849
|
+
const nestedParts = parseJwt(payload["njwt"]);
|
|
1850
|
+
if (nestedParts) {
|
|
1851
|
+
try {
|
|
1852
|
+
return JSON.parse(
|
|
1855
1853
|
Buffer.from(nestedParts[1], "base64url").toString("utf-8")
|
|
1856
1854
|
);
|
|
1855
|
+
} catch {
|
|
1857
1856
|
}
|
|
1858
1857
|
}
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
} catch {
|
|
1858
|
+
}
|
|
1859
|
+
return payload;
|
|
1860
|
+
}
|
|
1861
|
+
function extractUserIdsFromJwt(token) {
|
|
1862
|
+
const payload = readJwtPayload(token);
|
|
1863
|
+
if (!payload) {
|
|
1866
1864
|
return { customuser_id: null, account_id: null };
|
|
1867
1865
|
}
|
|
1866
|
+
const accRaw = payload["zap:acc"];
|
|
1867
|
+
const accountId = accRaw != null ? parseInt(String(accRaw), 10) : null;
|
|
1868
|
+
const customUserId = payload["sub_type"] === "customuser" && payload["sub"] != null ? parseInt(String(payload["sub"]), 10) : null;
|
|
1869
|
+
return {
|
|
1870
|
+
customuser_id: customUserId !== null && !isNaN(customUserId) ? customUserId : null,
|
|
1871
|
+
account_id: accountId !== null && !isNaN(accountId) ? accountId : null
|
|
1872
|
+
};
|
|
1868
1873
|
}
|
|
1869
1874
|
|
|
1870
1875
|
// src/api/debug.ts
|
|
@@ -2213,6 +2218,19 @@ function isCredentialsFunction(credentials) {
|
|
|
2213
2218
|
return typeof credentials === "function";
|
|
2214
2219
|
}
|
|
2215
2220
|
|
|
2221
|
+
// src/utils/telemetry.ts
|
|
2222
|
+
var emittedOnce = /* @__PURE__ */ new WeakMap();
|
|
2223
|
+
function emitOnce(onEvent, event) {
|
|
2224
|
+
if (!emittedOnce.has(onEvent)) {
|
|
2225
|
+
emittedOnce.set(onEvent, /* @__PURE__ */ new Set());
|
|
2226
|
+
}
|
|
2227
|
+
const fired = emittedOnce.get(onEvent);
|
|
2228
|
+
if (!fired.has(event.type)) {
|
|
2229
|
+
fired.add(event.type);
|
|
2230
|
+
onEvent(event);
|
|
2231
|
+
}
|
|
2232
|
+
}
|
|
2233
|
+
|
|
2216
2234
|
// src/utils/url-utils.ts
|
|
2217
2235
|
function getZapierBaseUrl(baseUrl) {
|
|
2218
2236
|
if (!baseUrl) {
|
|
@@ -2435,8 +2453,10 @@ async function resolveCache(options) {
|
|
|
2435
2453
|
if (cliLogin?.createCache) {
|
|
2436
2454
|
try {
|
|
2437
2455
|
const cache = cliLogin.createCache();
|
|
2438
|
-
|
|
2439
|
-
|
|
2456
|
+
if (cache) {
|
|
2457
|
+
cachedDefaultCache = cache;
|
|
2458
|
+
return cache;
|
|
2459
|
+
}
|
|
2440
2460
|
} catch {
|
|
2441
2461
|
}
|
|
2442
2462
|
}
|
|
@@ -2448,6 +2468,11 @@ function entryIsValid(entry) {
|
|
|
2448
2468
|
if (entry.expiresAt === void 0) return true;
|
|
2449
2469
|
return entry.expiresAt > Date.now() + TOKEN_EXPIRATION_BUFFER_MS;
|
|
2450
2470
|
}
|
|
2471
|
+
async function readCachedToken(cacheKey, cache) {
|
|
2472
|
+
const cached = await cache.get(cacheKey);
|
|
2473
|
+
if (cached && entryIsValid(cached)) return cached.value;
|
|
2474
|
+
return void 0;
|
|
2475
|
+
}
|
|
2451
2476
|
async function invalidateCachedToken(options) {
|
|
2452
2477
|
const cacheKey = buildCacheKey(options);
|
|
2453
2478
|
pendingExchanges.delete(cacheKey);
|
|
@@ -2561,11 +2586,76 @@ function isCliLoginAvailable() {
|
|
|
2561
2586
|
if (cachedCliLogin === void 0) return void 0;
|
|
2562
2587
|
return cachedCliLogin !== false;
|
|
2563
2588
|
}
|
|
2589
|
+
function emitAuthResolved(onEvent, mechanism) {
|
|
2590
|
+
if (onEvent) {
|
|
2591
|
+
emitOnce(onEvent, {
|
|
2592
|
+
type: "auth_resolved",
|
|
2593
|
+
payload: { mechanism },
|
|
2594
|
+
timestamp: Date.now()
|
|
2595
|
+
});
|
|
2596
|
+
}
|
|
2597
|
+
}
|
|
2598
|
+
async function getActiveCredentialsFromCli(baseUrl) {
|
|
2599
|
+
const cliLogin = await getCliLogin();
|
|
2600
|
+
return cliLogin?.getActiveCredentials?.({ baseUrl });
|
|
2601
|
+
}
|
|
2602
|
+
async function getStoredClientCredentialsFromCli(baseUrl) {
|
|
2603
|
+
const cliLogin = await getCliLogin();
|
|
2604
|
+
return cliLogin?.getStoredClientCredentials?.({ baseUrl });
|
|
2605
|
+
}
|
|
2564
2606
|
async function getTokenFromCliLogin(options) {
|
|
2565
2607
|
const cliLogin = await getCliLogin();
|
|
2566
2608
|
if (!cliLogin) return void 0;
|
|
2567
2609
|
return await cliLogin.getToken(options);
|
|
2568
2610
|
}
|
|
2611
|
+
async function tryStoredClientCredentialToken(options) {
|
|
2612
|
+
const activeCredential = await getActiveCredentialsFromCli(options.baseUrl);
|
|
2613
|
+
if (!activeCredential) return void 0;
|
|
2614
|
+
const resolvedBaseUrl = activeCredential.baseUrl || options.baseUrl || DEFAULT_AUTH_BASE_URL;
|
|
2615
|
+
const mergedScopes = mergeScopes(
|
|
2616
|
+
activeCredential.scopes.join(" "),
|
|
2617
|
+
options.requiredScopes
|
|
2618
|
+
);
|
|
2619
|
+
const cacheKey = buildCacheKey({
|
|
2620
|
+
clientId: activeCredential.clientId,
|
|
2621
|
+
scopes: mergedScopes,
|
|
2622
|
+
baseUrl: resolvedBaseUrl
|
|
2623
|
+
});
|
|
2624
|
+
const cache = await resolveCache(options);
|
|
2625
|
+
const pending = pendingExchanges.get(cacheKey);
|
|
2626
|
+
if (pending) return pending;
|
|
2627
|
+
const cached = await readCachedToken(cacheKey, cache);
|
|
2628
|
+
if (cached !== void 0) {
|
|
2629
|
+
if (options.debug)
|
|
2630
|
+
console.log(
|
|
2631
|
+
`[auth] Using cached token (clientId: ${activeCredential.clientId})`
|
|
2632
|
+
);
|
|
2633
|
+
emitAuthResolved(options.onEvent, "client_credentials");
|
|
2634
|
+
return cached;
|
|
2635
|
+
}
|
|
2636
|
+
const storedCredential = await getStoredClientCredentialsFromCli(resolvedBaseUrl);
|
|
2637
|
+
if (!storedCredential) {
|
|
2638
|
+
await invalidateCachedToken({
|
|
2639
|
+
clientId: activeCredential.clientId,
|
|
2640
|
+
scopes: activeCredential.scopes,
|
|
2641
|
+
baseUrl: resolvedBaseUrl,
|
|
2642
|
+
cache: options.cache
|
|
2643
|
+
});
|
|
2644
|
+
throw new ZapierAuthenticationError(
|
|
2645
|
+
`Stored client credential is missing its secret (clientId: ${activeCredential.clientId}). Run \`zapier-sdk login\` to recreate it.`
|
|
2646
|
+
);
|
|
2647
|
+
}
|
|
2648
|
+
if (options.debug)
|
|
2649
|
+
console.log(
|
|
2650
|
+
`[auth] Using stored client credential (clientId: ${storedCredential.clientId})`
|
|
2651
|
+
);
|
|
2652
|
+
const token = await resolveAuthTokenFromCredentials(
|
|
2653
|
+
storedCredential,
|
|
2654
|
+
options
|
|
2655
|
+
);
|
|
2656
|
+
emitAuthResolved(options.onEvent, "client_credentials");
|
|
2657
|
+
return token;
|
|
2658
|
+
}
|
|
2569
2659
|
async function resolveAuthToken(options = {}) {
|
|
2570
2660
|
const credentials = await resolveCredentials({
|
|
2571
2661
|
credentials: options.credentials,
|
|
@@ -2575,14 +2665,24 @@ async function resolveAuthToken(options = {}) {
|
|
|
2575
2665
|
if (credentials !== void 0) {
|
|
2576
2666
|
return resolveAuthTokenFromCredentials(credentials, options);
|
|
2577
2667
|
}
|
|
2578
|
-
|
|
2668
|
+
const storedToken = await tryStoredClientCredentialToken(options);
|
|
2669
|
+
if (storedToken !== void 0) return storedToken;
|
|
2670
|
+
if (options.debug) {
|
|
2671
|
+
console.log("[auth] Using JWT (no stored client credential found)");
|
|
2672
|
+
}
|
|
2673
|
+
const jwtToken = await getTokenFromCliLogin({
|
|
2579
2674
|
onEvent: options.onEvent,
|
|
2580
2675
|
fetch: options.fetch,
|
|
2581
2676
|
debug: options.debug
|
|
2582
2677
|
});
|
|
2678
|
+
if (jwtToken !== void 0) {
|
|
2679
|
+
emitAuthResolved(options.onEvent, "jwt");
|
|
2680
|
+
}
|
|
2681
|
+
return jwtToken;
|
|
2583
2682
|
}
|
|
2584
2683
|
async function resolveAuthTokenFromCredentials(credentials, options) {
|
|
2585
2684
|
if (typeof credentials === "string") {
|
|
2685
|
+
emitAuthResolved(options.onEvent, "token");
|
|
2586
2686
|
return credentials;
|
|
2587
2687
|
}
|
|
2588
2688
|
if (isClientCredentials(credentials)) {
|
|
@@ -2595,15 +2695,25 @@ async function resolveAuthTokenFromCredentials(credentials, options) {
|
|
|
2595
2695
|
baseUrl: resolvedBaseUrl
|
|
2596
2696
|
});
|
|
2597
2697
|
const cache = await resolveCache(options);
|
|
2598
|
-
const cached = await
|
|
2599
|
-
if (cached
|
|
2600
|
-
|
|
2698
|
+
const cached = await readCachedToken(cacheKey, cache);
|
|
2699
|
+
if (cached !== void 0) {
|
|
2700
|
+
if (options.debug) {
|
|
2701
|
+
console.log(`[auth] Using cached token (clientId: ${clientId})`);
|
|
2702
|
+
}
|
|
2703
|
+
return cached;
|
|
2601
2704
|
}
|
|
2602
2705
|
const pending = pendingExchanges.get(cacheKey);
|
|
2603
2706
|
if (pending) return pending;
|
|
2604
2707
|
const runLocked = async () => {
|
|
2605
|
-
const recheck = await
|
|
2606
|
-
if (recheck
|
|
2708
|
+
const recheck = await readCachedToken(cacheKey, cache);
|
|
2709
|
+
if (recheck !== void 0) {
|
|
2710
|
+
if (options.debug) {
|
|
2711
|
+
console.log(
|
|
2712
|
+
`[auth] Using cached token (clientId: ${clientId}, locked recheck)`
|
|
2713
|
+
);
|
|
2714
|
+
}
|
|
2715
|
+
return recheck;
|
|
2716
|
+
}
|
|
2607
2717
|
const { accessToken, expiresIn } = await exchangeClientCredentials({
|
|
2608
2718
|
clientId: credentials.clientId,
|
|
2609
2719
|
clientSecret: credentials.clientSecret,
|
|
@@ -2661,7 +2771,7 @@ async function invalidateCredentialsToken(options) {
|
|
|
2661
2771
|
}
|
|
2662
2772
|
|
|
2663
2773
|
// src/sdk-version.ts
|
|
2664
|
-
var SDK_VERSION = (typeof process !== "undefined" && process.env ? "0.
|
|
2774
|
+
var SDK_VERSION = (typeof process !== "undefined" && process.env ? "0.51.0" : void 0) || "unknown";
|
|
2665
2775
|
|
|
2666
2776
|
// src/utils/open-url.ts
|
|
2667
2777
|
var nodePrefix = "node:";
|
|
@@ -2936,10 +3046,10 @@ var ZapierApiClient = class {
|
|
|
2936
3046
|
}
|
|
2937
3047
|
if (errorType !== "approval_required") return response;
|
|
2938
3048
|
if (attempt === maxRetries) break;
|
|
2939
|
-
const
|
|
2940
|
-
if (
|
|
3049
|
+
const mode = this.options.approvalMode ?? getZapierApprovalMode() ?? "disabled";
|
|
3050
|
+
if (mode === "disabled") {
|
|
2941
3051
|
throw new ZapierApprovalError(
|
|
2942
|
-
"
|
|
3052
|
+
"Approvals are disabled. Set approvalMode to 'poll' or 'throw' (or ZAPIER_APPROVAL_MODE) to enable.",
|
|
2943
3053
|
{ status: "approval_required" }
|
|
2944
3054
|
);
|
|
2945
3055
|
}
|
|
@@ -2949,7 +3059,7 @@ var ZapierApiClient = class {
|
|
|
2949
3059
|
{ statusCode: 403 }
|
|
2950
3060
|
);
|
|
2951
3061
|
}
|
|
2952
|
-
await this.runOneApprovalRound(init.approvalContext);
|
|
3062
|
+
await this.runOneApprovalRound(init.approvalContext, mode);
|
|
2953
3063
|
}
|
|
2954
3064
|
throw new ZapierApprovalError(
|
|
2955
3065
|
`Exceeded maximum approval retries (${maxRetries}) for ${path}`,
|
|
@@ -3242,7 +3352,9 @@ var ZapierApiClient = class {
|
|
|
3242
3352
|
if (data && typeof data === "object") {
|
|
3243
3353
|
headers["Content-Type"] = "application/json";
|
|
3244
3354
|
}
|
|
3245
|
-
const wasMissingAuthToken = options.authRequired && await this.getAuthToken({
|
|
3355
|
+
const wasMissingAuthToken = options.authRequired && await this.getAuthToken({
|
|
3356
|
+
requiredScopes: options.requiredScopes
|
|
3357
|
+
}) == null;
|
|
3246
3358
|
const response = await this.fetch(path, {
|
|
3247
3359
|
...options,
|
|
3248
3360
|
method,
|
|
@@ -3268,10 +3380,13 @@ var ZapierApiClient = class {
|
|
|
3268
3380
|
}
|
|
3269
3381
|
/**
|
|
3270
3382
|
* Run a single approval round: create the approval, open the URL (poll mode)
|
|
3271
|
-
* or throw (
|
|
3383
|
+
* or throw (throw mode), poll until resolved, and emit events. Throws on
|
|
3272
3384
|
* denied/timeout/unexpected status. Returns on approved.
|
|
3385
|
+
*
|
|
3386
|
+
* Caller is responsible for passing a non-"disabled" mode; this method
|
|
3387
|
+
* unconditionally creates an approval.
|
|
3273
3388
|
*/
|
|
3274
|
-
async runOneApprovalRound(buildContext) {
|
|
3389
|
+
async runOneApprovalRound(buildContext, mode) {
|
|
3275
3390
|
const context = buildContext();
|
|
3276
3391
|
let approvalResponse;
|
|
3277
3392
|
try {
|
|
@@ -3346,8 +3461,7 @@ var ZapierApiClient = class {
|
|
|
3346
3461
|
approvalId: approval.approval_id,
|
|
3347
3462
|
approvalUrl: approval.approval_url
|
|
3348
3463
|
});
|
|
3349
|
-
|
|
3350
|
-
if (approvalMode === "fail") {
|
|
3464
|
+
if (mode === "throw") {
|
|
3351
3465
|
throw new ZapierApprovalError("This request requires approval.", {
|
|
3352
3466
|
approvalId: approval.approval_id,
|
|
3353
3467
|
approvalUrl: approval.approval_url,
|
|
@@ -3434,6 +3548,28 @@ var createZapierApi = (options) => {
|
|
|
3434
3548
|
});
|
|
3435
3549
|
};
|
|
3436
3550
|
|
|
3551
|
+
// src/api/index.ts
|
|
3552
|
+
function getOrCreateApiClient(config) {
|
|
3553
|
+
const {
|
|
3554
|
+
baseUrl = ZAPIER_BASE_URL,
|
|
3555
|
+
credentials,
|
|
3556
|
+
token,
|
|
3557
|
+
api: providedApi,
|
|
3558
|
+
debug = false,
|
|
3559
|
+
fetch: customFetch
|
|
3560
|
+
} = config;
|
|
3561
|
+
if (providedApi) {
|
|
3562
|
+
return providedApi;
|
|
3563
|
+
}
|
|
3564
|
+
return createZapierApi({
|
|
3565
|
+
baseUrl,
|
|
3566
|
+
credentials,
|
|
3567
|
+
token,
|
|
3568
|
+
debug,
|
|
3569
|
+
fetch: customFetch
|
|
3570
|
+
});
|
|
3571
|
+
}
|
|
3572
|
+
|
|
3437
3573
|
// src/plugins/api/index.ts
|
|
3438
3574
|
var apiPlugin = definePlugin(
|
|
3439
3575
|
(sdk) => {
|
|
@@ -3446,7 +3582,6 @@ var apiPlugin = definePlugin(
|
|
|
3446
3582
|
debug = false,
|
|
3447
3583
|
maxNetworkRetries = ZAPIER_MAX_NETWORK_RETRIES,
|
|
3448
3584
|
maxNetworkRetryDelayMs = ZAPIER_MAX_NETWORK_RETRY_DELAY_MS,
|
|
3449
|
-
isInteractive,
|
|
3450
3585
|
approvalTimeoutMs,
|
|
3451
3586
|
maxApprovalRetries,
|
|
3452
3587
|
approvalMode,
|
|
@@ -3461,7 +3596,6 @@ var apiPlugin = definePlugin(
|
|
|
3461
3596
|
onEvent,
|
|
3462
3597
|
maxNetworkRetries,
|
|
3463
3598
|
maxNetworkRetryDelayMs,
|
|
3464
|
-
isInteractive,
|
|
3465
3599
|
approvalTimeoutMs,
|
|
3466
3600
|
maxApprovalRetries,
|
|
3467
3601
|
approvalMode,
|
|
@@ -10167,16 +10301,13 @@ var BaseSdkOptionsSchema = zod.z.object({
|
|
|
10167
10301
|
* Default is 60000 (60 seconds).
|
|
10168
10302
|
*/
|
|
10169
10303
|
maxNetworkRetryDelayMs: zod.z.number().optional().describe("Max delay in ms to wait for retry (default: 60000).").meta({ valueHint: "ms" }),
|
|
10170
|
-
|
|
10171
|
-
"Whether this session is interactive (user can visit approval URLs). Defaults to ZAPIER_IS_INTERACTIVE env var."
|
|
10172
|
-
).meta({ internal: true }),
|
|
10173
|
-
approvalTimeoutMs: zod.z.number().optional().describe("Timeout in ms for approval polling. Default: 600000 (10 min).").meta({ valueHint: "ms", internal: true }),
|
|
10304
|
+
approvalTimeoutMs: zod.z.number().optional().describe("Timeout in ms for approval polling. Default: 600000 (10 min).").meta({ valueHint: "ms" }),
|
|
10174
10305
|
maxApprovalRetries: zod.z.number().optional().describe(
|
|
10175
10306
|
"Maximum number of sequential approval rounds per request (one per gating policy) before giving up. Default: 2."
|
|
10176
|
-
)
|
|
10177
|
-
approvalMode: zod.z.enum(["poll", "
|
|
10178
|
-
'Approval flow behavior. "poll" opens browser and
|
|
10179
|
-
)
|
|
10307
|
+
),
|
|
10308
|
+
approvalMode: zod.z.enum(["disabled", "poll", "throw"]).optional().describe(
|
|
10309
|
+
'Approval flow behavior. "disabled" (default) throws a ZapierApprovalError on approval-required responses without creating an approval. "poll" creates the approval, opens it in a browser, polls until resolved, and retries the original request. "throw" creates the approval and throws a ZapierApprovalError with the approval URL so the caller can surface it. Defaults to the ZAPIER_APPROVAL_MODE env var, then "disabled".'
|
|
10310
|
+
),
|
|
10180
10311
|
// Internal
|
|
10181
10312
|
manifestPath: zod.z.string().optional().describe("Path to a .zapierrc manifest file for app version locking.").meta({ internal: true }),
|
|
10182
10313
|
manifest: zod.z.custom().optional().describe("Manifest for app version locking.").meta({ internal: true }),
|
|
@@ -10306,6 +10437,7 @@ exports.createSdk = createSdk;
|
|
|
10306
10437
|
exports.createTableFieldsPlugin = createTableFieldsPlugin;
|
|
10307
10438
|
exports.createTablePlugin = createTablePlugin;
|
|
10308
10439
|
exports.createTableRecordsPlugin = createTableRecordsPlugin;
|
|
10440
|
+
exports.createZapierApi = createZapierApi;
|
|
10309
10441
|
exports.createZapierSdk = createZapierSdk2;
|
|
10310
10442
|
exports.createZapierSdkWithoutRegistry = createZapierSdkWithoutRegistry;
|
|
10311
10443
|
exports.definePlugin = definePlugin;
|
|
@@ -10329,6 +10461,7 @@ exports.getConnectionPlugin = getConnectionPlugin;
|
|
|
10329
10461
|
exports.getCpuTime = getCpuTime;
|
|
10330
10462
|
exports.getCurrentTimestamp = getCurrentTimestamp;
|
|
10331
10463
|
exports.getMemoryUsage = getMemoryUsage;
|
|
10464
|
+
exports.getOrCreateApiClient = getOrCreateApiClient;
|
|
10332
10465
|
exports.getOsInfo = getOsInfo;
|
|
10333
10466
|
exports.getPlatformVersions = getPlatformVersions;
|
|
10334
10467
|
exports.getPreferredManifestEntryKey = getPreferredManifestEntryKey;
|
|
@@ -10338,7 +10471,6 @@ exports.getTablePlugin = getTablePlugin;
|
|
|
10338
10471
|
exports.getTableRecordPlugin = getTableRecordPlugin;
|
|
10339
10472
|
exports.getTokenFromCliLogin = getTokenFromCliLogin;
|
|
10340
10473
|
exports.getZapierApprovalMode = getZapierApprovalMode;
|
|
10341
|
-
exports.getZapierIsInteractive = getZapierIsInteractive;
|
|
10342
10474
|
exports.getZapierSdkService = getZapierSdkService;
|
|
10343
10475
|
exports.injectCliLogin = injectCliLogin;
|
|
10344
10476
|
exports.inputFieldKeyResolver = inputFieldKeyResolver;
|
package/dist/experimental.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { B as BaseSdkOptions, W as WithAddPlugin, P as PluginMeta, Z as ZapierSdkOptions$1, E as EventEmissionContext, A as ApiClient, M as Manifest, R as ResolvedAppLocator, U as UpdateManifestEntryOptions, a as UpdateManifestEntryResult, b as AddActionEntryOptions, c as AddActionEntryResult, d as ActionEntry, f as findManifestEntry, r as readManifestFromFile, C as CapabilitiesContext, e as PaginatedSdkResult, F as FieldsetItem, g as PositionalMetadata, h as ZapierFetchInitOptions, D as DrainTriggerInboxOptions, i as DynamicResolver, j as WatchTriggerInboxOptions, k as ActionProxy, l as ZapierSdkApps } from './index-
|
|
2
|
-
export { u as Action,
|
|
1
|
+
import { B as BaseSdkOptions, W as WithAddPlugin, P as PluginMeta, Z as ZapierSdkOptions$1, E as EventEmissionContext, A as ApiClient, M as Manifest, R as ResolvedAppLocator, U as UpdateManifestEntryOptions, a as UpdateManifestEntryResult, b as AddActionEntryOptions, c as AddActionEntryResult, d as ActionEntry, f as findManifestEntry, r as readManifestFromFile, C as CapabilitiesContext, e as PaginatedSdkResult, F as FieldsetItem, g as PositionalMetadata, h as ZapierFetchInitOptions, D as DrainTriggerInboxOptions, i as DynamicResolver, j as WatchTriggerInboxOptions, k as ActionProxy, l as ZapierSdkApps } from './index-C52BjTXh.mjs';
|
|
2
|
+
export { u as Action, cg as ActionExecutionOptions, y as ActionExecutionResult, z as ActionField, H as ActionFieldChoice, aU as ActionItem, bv as ActionKeyProperty, b3 as ActionKeyPropertySchema, bw as ActionProperty, b4 as ActionPropertySchema, aq as ActionResolverItem, bH as ActionTimeoutMsProperty, bf as ActionTimeoutMsPropertySchema, ar as ActionTypeItem, bu as ActionTypeProperty, b2 as ActionTypePropertySchema, bU as ApiError, dB as ApiEvent, c_ as ApiPluginOptions, d0 as ApiPluginProvides, v as App, ch as AppFactoryInput, aS as AppItem, bs as AppKeyProperty, b0 as AppKeyPropertySchema, bt as AppProperty, b1 as AppPropertySchema, aB as ApplicationLifecycleEventData, c9 as ApprovalStatus, cf as AppsPluginProvides, bM as AppsProperty, bk as AppsPropertySchema, a0 as ArrayResolver, dA as AuthEvent, bA as AuthenticationIdProperty, b7 as AuthenticationIdPropertySchema, ax as BaseEvent, aj as BaseSdkOptionsSchema, a8 as BatchOptions, cN as CONTEXT_CACHE_MAX_SIZE, cM as CONTEXT_CACHE_TTL_MS, x as Choice, dH as ClientCredentialsObject, dS as ClientCredentialsObjectSchema, K as Connection, d_ as ConnectionEntry, dZ as ConnectionEntrySchema, by as ConnectionIdProperty, b6 as ConnectionIdPropertySchema, aT as ConnectionItem, bz as ConnectionProperty, b8 as ConnectionPropertySchema, e0 as ConnectionsMap, d$ as ConnectionsMapSchema, e2 as ConnectionsPluginProvides, bO as ConnectionsProperty, bm as ConnectionsPropertySchema, O as ConnectionsResponse, cz as CreateClientCredentialsPluginProvides, eo as CreateTableFieldsPluginProvides, ei as CreateTablePluginProvides, ew as CreateTableRecordsPluginProvides, dE as Credentials, dX as CredentialsFunction, dW as CredentialsFunctionSchema, dG as CredentialsObject, dU as CredentialsObjectSchema, dY as CredentialsSchema, e7 as DEFAULT_ACTION_TIMEOUT_MS, eb as DEFAULT_APPROVAL_TIMEOUT_MS, cW as DEFAULT_CONFIG_PATH, ec as DEFAULT_MAX_APPROVAL_RETRIES, e6 as DEFAULT_PAGE_SIZE, bF as DebugProperty, bd as DebugPropertySchema, cB as DeleteClientCredentialsPluginProvides, eq as DeleteTableFieldsPluginProvides, ek as DeleteTablePluginProvides, ey as DeleteTableRecordsPluginProvides, o as DrainTriggerInboxCallback, p as DrainTriggerInboxErrorObserver, aC as EnhancedErrorEventData, bV as ErrorOptions, dD as EventCallback, aA as EventContext, az as EventEmissionProvides, cj as FetchPluginProvides, w as Field, bL as FieldsProperty, bj as FieldsPropertySchema, a3 as FieldsResolver, s as FindFirstAuthenticationPluginProvides, cJ as FindFirstConnectionPluginProvides, t as FindUniqueAuthenticationPluginProvides, cL as FindUniqueConnectionPluginProvides, Y as FormatMetadata, X as FormattedItem, ai as FunctionDeprecation, aZ as FunctionOptions, ah as FunctionRegistryEntry, ct as GetActionInputFieldsSchemaPluginProvides, cF as GetActionPluginProvides, cD as GetAppPluginProvides, G as GetAuthenticationPluginProvides, cH as GetConnectionPluginProvides, cZ as GetProfilePluginProvides, eg as GetTablePluginProvides, es as GetTableRecordPluginProvides, aW as InfoFieldItem, aV as InputFieldItem, bx as InputFieldProperty, b5 as InputFieldPropertySchema, bB as InputsProperty, b9 as InputsPropertySchema, bT as LeaseLimitProperty, br as LeaseLimitPropertySchema, bR as LeaseProperty, bp as LeasePropertySchema, bS as LeaseSecondsProperty, bq as LeaseSecondsPropertySchema, L as LeasedTriggerMessageItem, bC as LimitProperty, ba as LimitPropertySchema, cr as ListActionInputFieldChoicesPluginProvides, cp as ListActionInputFieldsPluginProvides, cn as ListActionsPluginProvides, cl as ListAppsPluginProvides, q as ListAuthenticationsPluginProvides, cx as ListClientCredentialsPluginProvides, cv as ListConnectionsPluginProvides, em as ListTableFieldsPluginProvides, eu as ListTableRecordsPluginProvides, ee as ListTablesPluginProvides, dC as LoadingEvent, e5 as MAX_PAGE_LIMIT, cX as ManifestEntry, cS as ManifestPluginOptions, cV as ManifestPluginProvides, ay as MethodCalledEvent, aD as MethodCalledEventData, N as Need, I as NeedsRequest, J as NeedsResponse, bD as OffsetProperty, bb as OffsetPropertySchema, _ as OutputFormatter, bE as OutputProperty, bc as OutputPropertySchema, a$ as PaginatedSdkFunction, bG as ParamsProperty, be as ParamsPropertySchema, dI as PkceCredentialsObject, dT as PkceCredentialsObjectSchema, ak as Plugin, al as PluginProvides, au as PollOptions, c7 as RateLimitInfo, bJ as RecordProperty, bh as RecordPropertySchema, bK as RecordsProperty, bi as RecordsPropertySchema, ad as RelayFetchSchema, ac as RelayRequestSchema, at as RequestOptions, cR as RequestPluginProvides, dm as ResolveAuthTokenOptions, dN as ResolveCredentialsOptions, dF as ResolvedCredentials, dV as ResolvedCredentialsSchema, $ as Resolver, a1 as ResolverMetadata, aX as RootFieldItem, cP as RunActionPluginProvides, dz as SdkEvent, a_ as SdkPage, a2 as StaticResolver, bI as TableProperty, bg as TablePropertySchema, bN as TablesProperty, bl as TablesPropertySchema, bQ as TriggerInboxNameProperty, bo as TriggerInboxNamePropertySchema, bP as TriggerInboxProperty, bn as TriggerInboxPropertySchema, T as TriggerMessageStatus, eA as UpdateTableRecordsPluginProvides, Q as UserProfile, aY as UserProfileItem, e3 as ZAPIER_BASE_URL, e8 as ZAPIER_MAX_NETWORK_RETRIES, e9 as ZAPIER_MAX_NETWORK_RETRY_DELAY_MS, m as ZapierAbortDrainSignal, c5 as ZapierActionError, bX as ZapierApiError, bY as ZapierAppNotFoundError, ca as ZapierApprovalError, b$ as ZapierAuthenticationError, c3 as ZapierBundleError, dv as ZapierCache, dw as ZapierCacheEntry, dx as ZapierCacheSetOptions, c2 as ZapierConfigurationError, c6 as ZapierConflictError, bW as ZapierError, c0 as ZapierNotFoundError, c8 as ZapierRateLimitError, cb as ZapierRelayError, n as ZapierReleaseTriggerMessageSignal, c1 as ZapierResourceNotFoundError, cd as ZapierSignal, c4 as ZapierTimeoutError, b_ as ZapierUnknownError, bZ as ZapierValidationError, d3 as actionKeyResolver, d2 as actionTypeResolver, c$ as apiPlugin, d1 as appKeyResolver, ce as appsPlugin, d5 as authenticationIdGenericResolver, d4 as authenticationIdResolver, a7 as batch, aN as buildApplicationLifecycleEvent, a9 as buildCapabilityMessage, aP as buildErrorEvent, aO as buildErrorEventWithContext, aR as buildMethodCalledEvent, dn as clearTokenCache, d9 as clientCredentialsNameResolver, da as clientIdResolver, ap as composePlugins, d5 as connectionIdGenericResolver, d4 as connectionIdResolver, e1 as connectionsPlugin, aQ as createBaseEvent, cy as createClientCredentialsPlugin, V as createFunction, dy as createMemoryCache, ag as createOptionsPlugin, ao as createPaginatedPluginMethod, an as createPluginMethod, af as createSdk, en as createTableFieldsPlugin, eh as createTablePlugin, ev as createTableRecordsPlugin, av as createZapierApi, ae as createZapierSdkWithoutRegistry, am as definePlugin, cA as deleteClientCredentialsPlugin, ep as deleteTableFieldsPlugin, ej as deleteTablePlugin, ex as deleteTableRecordsPlugin, ci as fetchPlugin, cI as findFirstConnectionPlugin, cK as findUniqueConnectionPlugin, cc as formatErrorMessage, aE as generateEventId, cs as getActionInputFieldsSchemaPlugin, cE as getActionPlugin, cC as getAppPlugin, dQ as getBaseUrlFromCredentials, aK as getCiPlatform, dR as getClientIdFromCredentials, cG as getConnectionPlugin, aM as getCpuTime, aF as getCurrentTimestamp, aL as getMemoryUsage, aw as getOrCreateApiClient, aH as getOsInfo, aI as getPlatformVersions, cT as getPreferredManifestEntryKey, cY as getProfilePlugin, aG as getReleaseId, ef as getTablePlugin, er as getTableRecordPlugin, ds as getTokenFromCliLogin, ea as getZapierApprovalMode, e4 as getZapierSdkService, dq as injectCliLogin, d8 as inputFieldKeyResolver, d7 as inputsAllOptionalResolver, d6 as inputsResolver, dp as invalidateCachedToken, du as invalidateCredentialsToken, aJ as isCi, dr as isCliLoginAvailable, dJ as isClientCredentials, dM as isCredentialsFunction, dL as isCredentialsObject, dK as isPkceCredentials, S as isPositional, cq as listActionInputFieldChoicesPlugin, co as listActionInputFieldsPlugin, cm as listActionsPlugin, ck as listAppsPlugin, cw as listClientCredentialsPlugin, cu as listConnectionsPlugin, el as listTableFieldsPlugin, et as listTableRecordsPlugin, ed as listTablesPlugin, aa as logDeprecation, cU as manifestPlugin, as as registryPlugin, cQ as requestPlugin, ab as resetDeprecationWarnings, dt as resolveAuthToken, dP as resolveCredentials, dO as resolveCredentialsFromEnv, cO as runActionPlugin, a4 as runWithTelemetryContext, df as tableFieldIdsResolver, dh as tableFieldsResolver, dk as tableFiltersResolver, db as tableIdResolver, dg as tableNameResolver, dd as tableRecordIdResolver, de as tableRecordIdsResolver, di as tableRecordsResolver, dl as tableSortResolver, dj as tableUpdateRecordsResolver, a5 as toSnakeCase, a6 as toTitleCase, dc as triggerInboxResolver, ez as updateTableRecordsPlugin } from './index-C52BjTXh.mjs';
|
|
3
3
|
import * as zod_v4_core from 'zod/v4/core';
|
|
4
4
|
import * as zod from 'zod';
|
|
5
5
|
import '@zapier/zapier-sdk-core/v0/schemas/connections';
|