@zapier/zapier-sdk 0.122.2 → 0.124.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 +47 -0
- package/dist/beta.cjs +291 -287
- package/dist/beta.d.mts +6 -6
- package/dist/beta.d.ts +6 -6
- package/dist/beta.mjs +2 -2
- package/dist/{chunk-YVMXEARO.cjs → chunk-AXVD22XH.cjs} +245 -196
- package/dist/{chunk-7NTLOQZI.mjs → chunk-DQALS345.mjs} +3 -6
- package/dist/{chunk-3WRZWB3X.mjs → chunk-EWFUUFGE.mjs} +243 -198
- package/dist/{chunk-W7TKBIW6.cjs → chunk-NRDB2MRP.cjs} +87 -90
- package/dist/experimental.cjs +321 -320
- package/dist/experimental.d.mts +47 -47
- package/dist/experimental.d.ts +47 -47
- package/dist/experimental.mjs +6 -9
- package/dist/{index-BnMxdUcw.d.mts → index-CJ0cHgVT.d.mts} +38 -54
- package/dist/{index-BnMxdUcw.d.ts → index-CJ0cHgVT.d.ts} +38 -54
- package/dist/index.cjs +285 -281
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +1 -1
- package/package.json +2 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __require } from './chunk-Y6FXYEAI.mjs';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import { withPositional, createDeprecationLogger, createStabilityNoticeLogger, createAsyncContext, declareOptionalProperty, defineProperty, definePlugin, sendHttpRequestPlugin, retryHttpRequestPlugin, declareProperty, defineMethod, coreOptionsPluginRef, createValidator, defineFormatter, declareMethod, defineResolver, concatLists, openEnum,
|
|
4
|
-
export { CONTEXT, CORE_ERROR_SYMBOL, CORE_OPTIONS_ID, CORE_SIGNAL_SYMBOL, CoreCancelledSignal, CoreDisposeError, CoreErrorCode, CoreSignal, STABILITY_LEVELS, STABILITY_TITLES, addPlugin, applyStabilityLabel, createController, createSdk, declareMethod, declareOptionalProperty, declarePlugin, declareProperty, defineFormatter, defineMethod, defineMethodOverride, defineOverride, definePlugin, defineProperty, defineResolver, disposeSdk, getContext, getCoreErrorCause, getCoreErrorCode, getNegatable, getRegistry, getRegistryPlugin, isCoreCancelledSignal, isCoreError, isCoreSignal, isPositional, omitExports, resolvePlugin, runInMethodScope, runWithTelemetryContext, selectExports, toSnakeCase, toTitleCase } from '@zapier/kitcore';
|
|
3
|
+
import { withPositional, createDeprecationLogger, createStabilityNoticeLogger, createAsyncContext, declareOptionalProperty, defineHook, prepareHttpRequestPlugin, receiveHttpResponsePlugin, defineProperty, definePlugin, sendHttpRequestPlugin, retryHttpRequestPlugin, declareProperty, defineMethod, coreOptionsPluginRef, createValidator, defineFormatter, declareMethod, defineResolver, concatLists, openEnum, declareDefault, getRegistryPlugin, paginate, toSnakeCase, isCoreError, toTitleCase, CoreErrorCode, CORE_ERROR_SYMBOL, CORE_SIGNAL_SYMBOL, isCoreSignal, createSdk, resolvePlugin } from '@zapier/kitcore';
|
|
4
|
+
export { CONTEXT, CORE_ERROR_SYMBOL, CORE_OPTIONS_ID, CORE_SIGNAL_SYMBOL, CoreCancelledSignal, CoreDisposeError, CoreErrorCode, CoreSignal, STABILITY_LEVELS, STABILITY_TITLES, addPlugin, applyStabilityLabel, coreOptionsPluginRef, createController, createSdk, declareMethod, declareOptionalProperty, declarePlugin, declareProperty, defineFormatter, defineMethod, defineMethodOverride, defineOverride, definePlugin, defineProperty, defineResolver, disposeSdk, getContext, getCoreErrorCause, getCoreErrorCode, getNegatable, getRegistry, getRegistryPlugin, isCoreCancelledSignal, isCoreError, isCoreSignal, isPositional, omitExports, resolvePlugin, runInMethodScope, runWithTelemetryContext, selectExports, toSnakeCase, toTitleCase } from '@zapier/kitcore';
|
|
5
5
|
import { ConnectionItemSchema as ConnectionItemSchema$1, ConnectionSchema, ConnectionsResponseSchema, ListConnectionsQuerySchema as ListConnectionsQuerySchema$1 } from '@zapier/zapier-sdk-core/v0/schemas/connections';
|
|
6
6
|
import { buildHttpRequestContext, buildActionRunContext } from '@zapier/policy-context';
|
|
7
7
|
import { ListAppsQuerySchema, AppItemSchema as AppItemSchema$1 } from '@zapier/zapier-sdk-core/v0/schemas/apps';
|
|
@@ -1241,15 +1241,12 @@ var { logDeprecation, resetDeprecationWarnings } = createDeprecationLogger("zapi
|
|
|
1241
1241
|
var { logStabilityNotice, resetStabilityNotices } = createStabilityNoticeLogger("zapier-sdk");
|
|
1242
1242
|
|
|
1243
1243
|
// src/utils/url-utils.ts
|
|
1244
|
-
function
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
for (const [key, value] of Object.entries(searchParams ?? {})) {
|
|
1250
|
-
result.searchParams.set(key, value);
|
|
1244
|
+
function validateSdkPath(path) {
|
|
1245
|
+
if (!path.startsWith("/") || path.startsWith("//")) {
|
|
1246
|
+
throw new ZapierValidationError(
|
|
1247
|
+
`fetch expects a path starting with a single '/', got: ${path}`
|
|
1248
|
+
);
|
|
1251
1249
|
}
|
|
1252
|
-
return result.toString();
|
|
1253
1250
|
}
|
|
1254
1251
|
function getZapierBaseUrl(baseUrl) {
|
|
1255
1252
|
if (!baseUrl) {
|
|
@@ -2069,58 +2066,6 @@ function parseApprovalReviewStreamPayload(parsed, toolNames) {
|
|
|
2069
2066
|
}
|
|
2070
2067
|
}
|
|
2071
2068
|
}
|
|
2072
|
-
|
|
2073
|
-
// src/api/deprecation.ts
|
|
2074
|
-
var DEPRECATION_MESSAGE_HEADER = "zapier-sdk-deprecation-message";
|
|
2075
|
-
var DEPRECATION_ID_HEADER = "zapier-sdk-deprecation-id";
|
|
2076
|
-
var DEPRECATION_NOTICE_EVENT = "api:deprecation_notice";
|
|
2077
|
-
var displayedNoticeIds = /* @__PURE__ */ new Set();
|
|
2078
|
-
function handleDeprecationNotice({
|
|
2079
|
-
response,
|
|
2080
|
-
canSendDeprecationMessaging,
|
|
2081
|
-
onEvent
|
|
2082
|
-
}) {
|
|
2083
|
-
try {
|
|
2084
|
-
sniffDeprecationNotice({ response, canSendDeprecationMessaging, onEvent });
|
|
2085
|
-
} catch {
|
|
2086
|
-
}
|
|
2087
|
-
}
|
|
2088
|
-
function sniffDeprecationNotice({
|
|
2089
|
-
response,
|
|
2090
|
-
canSendDeprecationMessaging,
|
|
2091
|
-
onEvent
|
|
2092
|
-
}) {
|
|
2093
|
-
if (!canSendDeprecationMessaging) return;
|
|
2094
|
-
const message = response.headers?.get(DEPRECATION_MESSAGE_HEADER);
|
|
2095
|
-
if (!message) return;
|
|
2096
|
-
const id = response.headers.get(DEPRECATION_ID_HEADER) ?? message;
|
|
2097
|
-
if (!displayedNoticeIds.has(id)) {
|
|
2098
|
-
displayedNoticeIds.add(id);
|
|
2099
|
-
console.warn(`[zapier-sdk] Deprecation: ${message}`);
|
|
2100
|
-
}
|
|
2101
|
-
if (onEvent) {
|
|
2102
|
-
const payload = { id, message };
|
|
2103
|
-
const deprecation = parseDeprecationDate(
|
|
2104
|
-
response.headers.get("deprecation")
|
|
2105
|
-
);
|
|
2106
|
-
if (deprecation !== void 0) payload.deprecation = deprecation;
|
|
2107
|
-
const maybePromise = onEvent({
|
|
2108
|
-
type: DEPRECATION_NOTICE_EVENT,
|
|
2109
|
-
payload: { ...payload },
|
|
2110
|
-
timestamp: Date.now()
|
|
2111
|
-
});
|
|
2112
|
-
if (isPromiseLike(maybePromise)) {
|
|
2113
|
-
void Promise.resolve(maybePromise).catch(() => {
|
|
2114
|
-
});
|
|
2115
|
-
}
|
|
2116
|
-
}
|
|
2117
|
-
}
|
|
2118
|
-
function parseDeprecationDate(value) {
|
|
2119
|
-
if (!value) return void 0;
|
|
2120
|
-
const match = /^@(-?\d+)$/.exec(value.trim());
|
|
2121
|
-
if (!match) return void 0;
|
|
2122
|
-
return Number(match[1]) * 1e3;
|
|
2123
|
-
}
|
|
2124
2069
|
var RELAY_ERROR_HEADER = "x-relay-error";
|
|
2125
2070
|
var RELAY_TIMEOUT_HEADER = "x-relay-extended-timeout";
|
|
2126
2071
|
var SDK_CORRELATION_HEADER = "zapier-correlation-id";
|
|
@@ -2451,36 +2396,14 @@ function buildRouteOverrideMap({
|
|
|
2451
2396
|
}
|
|
2452
2397
|
return routeOverrideMap;
|
|
2453
2398
|
}
|
|
2454
|
-
function collectRouteOverrideSources({
|
|
2455
|
-
routingOptions,
|
|
2456
|
-
environment,
|
|
2457
|
-
routingConfig: routingConfig2
|
|
2458
|
-
}) {
|
|
2459
|
-
try {
|
|
2460
|
-
const optionEntries = routingOptions?.routeOverrideEntries ?? [];
|
|
2461
|
-
const environmentEntries = readEnvironmentRouteOverrideEntries({
|
|
2462
|
-
environment,
|
|
2463
|
-
routingConfig: routingConfig2
|
|
2464
|
-
});
|
|
2465
|
-
if (optionEntries.length === 0 && environmentEntries.length === 0) {
|
|
2466
|
-
return void 0;
|
|
2467
|
-
}
|
|
2468
|
-
return { optionEntries, environmentEntries };
|
|
2469
|
-
} catch (error) {
|
|
2470
|
-
if (isZapierError(error) && error.code === "ZAPIER_CONFIGURATION_ERROR") {
|
|
2471
|
-
throw error;
|
|
2472
|
-
}
|
|
2473
|
-
return void 0;
|
|
2474
|
-
}
|
|
2475
|
-
}
|
|
2476
2399
|
function findRouteOverrideMatch({
|
|
2477
2400
|
path,
|
|
2478
|
-
|
|
2401
|
+
routeOverrideEntries,
|
|
2479
2402
|
routingConfig: routingConfig2
|
|
2480
2403
|
}) {
|
|
2481
2404
|
let bestMatch;
|
|
2482
2405
|
const { pathname } = splitPathReference({ path });
|
|
2483
|
-
for (const override of
|
|
2406
|
+
for (const override of routeOverrideEntries) {
|
|
2484
2407
|
const { route } = override;
|
|
2485
2408
|
for (const candidate of getRouteCandidates({
|
|
2486
2409
|
route,
|
|
@@ -2524,16 +2447,18 @@ function deriveDirectPath({
|
|
|
2524
2447
|
if (!pathPrefix) {
|
|
2525
2448
|
return path;
|
|
2526
2449
|
}
|
|
2527
|
-
const
|
|
2450
|
+
const { pathname, search, hash } = splitPathReference({ path });
|
|
2451
|
+
const remainingPath = pathname.slice(matchedPrefix.length) || "/";
|
|
2528
2452
|
const override = routeConfig.override;
|
|
2529
2453
|
const pathPrefixMode = override?.enabled === false ? "strip" : override?.pathPrefixMode ?? "strip";
|
|
2530
|
-
|
|
2454
|
+
const directPathname = pathPrefixMode === "preserve" ? `${pathPrefix}${remainingPath}` : remainingPath;
|
|
2455
|
+
return `${directPathname}${search}${hash}`;
|
|
2531
2456
|
}
|
|
2532
2457
|
function readEnvironmentRouteOverrideEntries({
|
|
2533
|
-
environment,
|
|
2534
2458
|
routingConfig: routingConfig2
|
|
2535
2459
|
}) {
|
|
2536
2460
|
const entries = [];
|
|
2461
|
+
const environment = globalThis.process?.env;
|
|
2537
2462
|
if (!environment) {
|
|
2538
2463
|
return entries;
|
|
2539
2464
|
}
|
|
@@ -2797,33 +2722,52 @@ function parseRoutingOptions({
|
|
|
2797
2722
|
});
|
|
2798
2723
|
}
|
|
2799
2724
|
}
|
|
2725
|
+
function withEnvironmentRouteOverrides({
|
|
2726
|
+
routingOptions
|
|
2727
|
+
}) {
|
|
2728
|
+
let environmentEntries;
|
|
2729
|
+
try {
|
|
2730
|
+
environmentEntries = readEnvironmentRouteOverrideEntries({ routingConfig });
|
|
2731
|
+
} catch (error) {
|
|
2732
|
+
if (isZapierError(error) && error.code === "ZAPIER_CONFIGURATION_ERROR") {
|
|
2733
|
+
throw error;
|
|
2734
|
+
}
|
|
2735
|
+
return routingOptions;
|
|
2736
|
+
}
|
|
2737
|
+
if (environmentEntries.length === 0) {
|
|
2738
|
+
return routingOptions;
|
|
2739
|
+
}
|
|
2740
|
+
const routeOverrideMap = buildRouteOverrideMap({
|
|
2741
|
+
environmentEntries,
|
|
2742
|
+
optionEntries: routingOptions.routeOverrideEntries
|
|
2743
|
+
});
|
|
2744
|
+
return { routeOverrideEntries: [...routeOverrideMap.values()] };
|
|
2745
|
+
}
|
|
2800
2746
|
function resolveRoute({
|
|
2801
2747
|
path,
|
|
2802
2748
|
baseUrl,
|
|
2803
2749
|
routingOptions = { routeOverrideEntries: [] },
|
|
2804
|
-
environment,
|
|
2805
2750
|
debugLog
|
|
2806
2751
|
}) {
|
|
2807
|
-
const overrideSources = collectRouteOverrideSources({
|
|
2808
|
-
routingOptions,
|
|
2809
|
-
environment,
|
|
2810
|
-
routingConfig
|
|
2811
|
-
});
|
|
2812
|
-
if (!overrideSources) {
|
|
2813
|
-
return resolveDefaultRoute({ path, baseUrl });
|
|
2814
|
-
}
|
|
2815
|
-
const routeOverrideMap = buildRouteOverrideMap(overrideSources);
|
|
2816
2752
|
const overrideMatch = findRouteOverrideMatch({
|
|
2817
2753
|
path,
|
|
2818
|
-
|
|
2754
|
+
routeOverrideEntries: routingOptions.routeOverrideEntries,
|
|
2819
2755
|
routingConfig
|
|
2820
2756
|
});
|
|
2821
2757
|
if (overrideMatch) {
|
|
2822
|
-
const
|
|
2823
|
-
logRouteOverride({ path, resolved, overrideMatch, debugLog });
|
|
2758
|
+
const resolved2 = resolveOverrideRoute({ overrideMatch, path });
|
|
2759
|
+
logRouteOverride({ path, resolved: resolved2, overrideMatch, debugLog });
|
|
2760
|
+
return resolved2;
|
|
2761
|
+
}
|
|
2762
|
+
const { pathname, search, hash } = splitPathReference({ path });
|
|
2763
|
+
const resolved = resolveDefaultRoute({ path: pathname, baseUrl });
|
|
2764
|
+
if (!search && !hash) {
|
|
2824
2765
|
return resolved;
|
|
2825
2766
|
}
|
|
2826
|
-
|
|
2767
|
+
const url = new URL(resolved.url);
|
|
2768
|
+
url.search = search;
|
|
2769
|
+
url.hash = hash;
|
|
2770
|
+
return { ...resolved, url };
|
|
2827
2771
|
}
|
|
2828
2772
|
function logRouteOverride({
|
|
2829
2773
|
path,
|
|
@@ -2842,7 +2786,7 @@ function logRouteOverride({
|
|
|
2842
2786
|
}
|
|
2843
2787
|
|
|
2844
2788
|
// src/sdk-version.ts
|
|
2845
|
-
var SDK_VERSION = (typeof process !== "undefined" && process.env ? "0.
|
|
2789
|
+
var SDK_VERSION = (typeof process !== "undefined" && process.env ? "0.124.0" : void 0) || "unknown";
|
|
2846
2790
|
|
|
2847
2791
|
// src/utils/open-url.ts
|
|
2848
2792
|
var nodePrefix = "node:";
|
|
@@ -2969,24 +2913,37 @@ var PollApprovalResponseSchema = z.object({
|
|
|
2969
2913
|
approval_url: z.string().optional()
|
|
2970
2914
|
});
|
|
2971
2915
|
var APPROVAL_MAX_POLLING_INTERVAL_MILLISECONDS = 5e3;
|
|
2972
|
-
function
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2916
|
+
function mergeSearchParams({
|
|
2917
|
+
path,
|
|
2918
|
+
searchParams
|
|
2919
|
+
}) {
|
|
2920
|
+
const { pathname, search, hash } = splitPathReference({ path });
|
|
2921
|
+
if (!searchParams || Object.keys(searchParams).length === 0) {
|
|
2922
|
+
return `${pathname}${search}${hash}`;
|
|
2923
|
+
}
|
|
2924
|
+
const query = new URLSearchParams(search);
|
|
2925
|
+
for (const [key, value] of Object.entries(searchParams)) {
|
|
2926
|
+
query.set(key, value);
|
|
2977
2927
|
}
|
|
2928
|
+
const queryString = query.toString();
|
|
2929
|
+
return `${pathname}${queryString ? `?${queryString}` : ""}${hash}`;
|
|
2978
2930
|
}
|
|
2979
2931
|
var ZapierApiClient = class {
|
|
2980
2932
|
constructor(options) {
|
|
2981
2933
|
this.options = options;
|
|
2982
2934
|
/**
|
|
2983
|
-
* Perform a request
|
|
2935
|
+
* Perform a request given a destination: either an already
|
|
2936
|
+
* resolved absolute URL, or a Zapier logical path (plus its query string,
|
|
2937
|
+
* since there is no separate `searchParams` slot once a request enters the
|
|
2938
|
+
* pipeline). `zapierRouteHttpRequestPlugin`'s `prepareHttpRequest` wrap
|
|
2939
|
+
* resolves a logical path against `pathConfig` before dispatch; an
|
|
2940
|
+
* absolute URL passes through that wrap untouched.
|
|
2984
2941
|
*
|
|
2985
2942
|
* Does auth and header merging, and converts a terminal 429 into
|
|
2986
2943
|
* `ZapierRateLimitError` — the cross-cutting concerns that every
|
|
2987
2944
|
* Zapier-bound HTTP call needs and that the transport does not own. Callers
|
|
2988
2945
|
* that have a path (e.g. `/relay/...`) should use `rawFetch` instead, which
|
|
2989
|
-
*
|
|
2946
|
+
* merges `searchParams` into the path and delegates here.
|
|
2990
2947
|
*
|
|
2991
2948
|
* Exposed as a separate helper so call sites with a server-supplied
|
|
2992
2949
|
* absolute URL (e.g. an approval poll URL) can still share the same
|
|
@@ -3102,10 +3059,13 @@ var ZapierApiClient = class {
|
|
|
3102
3059
|
*/
|
|
3103
3060
|
this.rawFetch = async (path, init) => {
|
|
3104
3061
|
validateSdkPath(path);
|
|
3105
|
-
const { url, resolvedRoute } = this.buildUrl(
|
|
3062
|
+
const { url, resolvedRoute, requestPath } = this.buildUrl(
|
|
3063
|
+
path,
|
|
3064
|
+
init?.searchParams
|
|
3065
|
+
);
|
|
3106
3066
|
return this.withSemaphore(
|
|
3107
3067
|
{ url, method: init?.method ?? "GET", signal: init?.signal },
|
|
3108
|
-
() => this.rawFetchUrl(
|
|
3068
|
+
() => this.rawFetchUrl(requestPath, init, resolvedRoute)
|
|
3109
3069
|
);
|
|
3110
3070
|
};
|
|
3111
3071
|
this.runApprovalFetchLoop = async ({
|
|
@@ -3210,10 +3170,6 @@ var ZapierApiClient = class {
|
|
|
3210
3170
|
this.fetch = async (path, init) => {
|
|
3211
3171
|
validateSdkPath(path);
|
|
3212
3172
|
const maxRetries = this.options.maxApprovalRetries ?? DEFAULT_MAX_APPROVAL_RETRIES;
|
|
3213
|
-
const { canSendDeprecationMessaging } = this.buildUrl(
|
|
3214
|
-
path,
|
|
3215
|
-
init?.searchParams
|
|
3216
|
-
);
|
|
3217
3173
|
const approvalMode = this.options.approvalMode ?? getZapierApprovalMode() ?? getZapierDefaultApprovalMode();
|
|
3218
3174
|
const approvalContext = init?.approvalContext;
|
|
3219
3175
|
const { response, approvalRoundError } = await this.runApprovalFetchLoop({
|
|
@@ -3223,11 +3179,6 @@ var ZapierApiClient = class {
|
|
|
3223
3179
|
approvalMode,
|
|
3224
3180
|
approvalContext
|
|
3225
3181
|
});
|
|
3226
|
-
handleDeprecationNotice({
|
|
3227
|
-
response,
|
|
3228
|
-
canSendDeprecationMessaging,
|
|
3229
|
-
onEvent: this.options.onEvent
|
|
3230
|
-
});
|
|
3231
3182
|
if (response.status !== 403) {
|
|
3232
3183
|
return response;
|
|
3233
3184
|
}
|
|
@@ -3536,23 +3487,28 @@ var ZapierApiClient = class {
|
|
|
3536
3487
|
return { message: fallbackMessage };
|
|
3537
3488
|
}
|
|
3538
3489
|
}
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
|
|
3542
|
-
|
|
3490
|
+
/**
|
|
3491
|
+
* Build the path `rawFetch` hands the pipeline, alongside the route it
|
|
3492
|
+
* resolves to. The resolution is the client's own: it supplies the
|
|
3493
|
+
* auth-header name, the Relay header transforms, and the URL the
|
|
3494
|
+
* concurrency events report. The transport resolves the same path
|
|
3495
|
+
* independently to pick the destination, so both go through `resolveRoute`
|
|
3496
|
+
* with the same overrides — a path that routed one way here and another way
|
|
3497
|
+
* there would authenticate against the wrong host.
|
|
3498
|
+
*
|
|
3499
|
+
* No `debugLog`: the transport's resolution logs the override decision.
|
|
3500
|
+
* Passing one here would print every route override twice.
|
|
3501
|
+
*/
|
|
3502
|
+
buildUrl(path, searchParams) {
|
|
3503
|
+
const requestPath = mergeSearchParams({ path, searchParams });
|
|
3504
|
+
const resolvedRoute = resolveRoute({
|
|
3505
|
+
path: requestPath,
|
|
3543
3506
|
baseUrl: this.options.baseUrl,
|
|
3544
|
-
routingOptions:
|
|
3545
|
-
|
|
3546
|
-
|
|
3507
|
+
routingOptions: withEnvironmentRouteOverrides({
|
|
3508
|
+
routingOptions: this.options.routingOptions
|
|
3509
|
+
})
|
|
3547
3510
|
});
|
|
3548
|
-
|
|
3549
|
-
buildUrl(path, searchParams) {
|
|
3550
|
-
const resolvedRoute = this.applyPathConfiguration(path);
|
|
3551
|
-
return {
|
|
3552
|
-
url: withSearchParams({ url: resolvedRoute.url, searchParams }),
|
|
3553
|
-
resolvedRoute,
|
|
3554
|
-
canSendDeprecationMessaging: resolvedRoute.canSendDeprecationMessaging
|
|
3555
|
-
};
|
|
3511
|
+
return { url: resolvedRoute.url.toString(), resolvedRoute, requestPath };
|
|
3556
3512
|
}
|
|
3557
3513
|
// Helper to build headers
|
|
3558
3514
|
async buildHeaders(options = {}, pathConfig2) {
|
|
@@ -4192,9 +4148,124 @@ function resolveApprovalTimeoutMilliseconds({
|
|
|
4192
4148
|
}
|
|
4193
4149
|
return sdkOptions?.approvalTimeoutMs;
|
|
4194
4150
|
}
|
|
4195
|
-
var
|
|
4196
|
-
var
|
|
4197
|
-
|
|
4151
|
+
var sdkOptionsPluginRef = declareOptionalProperty({ id: "zapier/sdkOptions" });
|
|
4152
|
+
var SDK_OPTIONS_ID = sdkOptionsPluginRef.id;
|
|
4153
|
+
|
|
4154
|
+
// src/api/deprecation.ts
|
|
4155
|
+
var DEPRECATION_MESSAGE_HEADER = "zapier-sdk-deprecation-message";
|
|
4156
|
+
var DEPRECATION_ID_HEADER = "zapier-sdk-deprecation-id";
|
|
4157
|
+
var DEPRECATION_NOTICE_EVENT = "api:deprecation_notice";
|
|
4158
|
+
var displayedNoticeIds = /* @__PURE__ */ new Set();
|
|
4159
|
+
function handleDeprecationNotice({
|
|
4160
|
+
response,
|
|
4161
|
+
canSendDeprecationMessaging,
|
|
4162
|
+
onEvent
|
|
4163
|
+
}) {
|
|
4164
|
+
try {
|
|
4165
|
+
sniffDeprecationNotice({ response, canSendDeprecationMessaging, onEvent });
|
|
4166
|
+
} catch {
|
|
4167
|
+
}
|
|
4168
|
+
}
|
|
4169
|
+
function sniffDeprecationNotice({
|
|
4170
|
+
response,
|
|
4171
|
+
canSendDeprecationMessaging,
|
|
4172
|
+
onEvent
|
|
4173
|
+
}) {
|
|
4174
|
+
if (!canSendDeprecationMessaging) return;
|
|
4175
|
+
const message = response.headers?.get(DEPRECATION_MESSAGE_HEADER);
|
|
4176
|
+
if (!message) return;
|
|
4177
|
+
const id = response.headers.get(DEPRECATION_ID_HEADER) ?? message;
|
|
4178
|
+
if (!displayedNoticeIds.has(id)) {
|
|
4179
|
+
displayedNoticeIds.add(id);
|
|
4180
|
+
console.warn(`[zapier-sdk] Deprecation: ${message}`);
|
|
4181
|
+
}
|
|
4182
|
+
if (onEvent) {
|
|
4183
|
+
const payload = { id, message };
|
|
4184
|
+
const deprecation = parseDeprecationDate(
|
|
4185
|
+
response.headers.get("deprecation")
|
|
4186
|
+
);
|
|
4187
|
+
if (deprecation !== void 0) payload.deprecation = deprecation;
|
|
4188
|
+
const maybePromise = onEvent({
|
|
4189
|
+
type: DEPRECATION_NOTICE_EVENT,
|
|
4190
|
+
payload: { ...payload },
|
|
4191
|
+
timestamp: Date.now()
|
|
4192
|
+
});
|
|
4193
|
+
if (isPromiseLike(maybePromise)) {
|
|
4194
|
+
void Promise.resolve(maybePromise).catch(() => {
|
|
4195
|
+
});
|
|
4196
|
+
}
|
|
4197
|
+
}
|
|
4198
|
+
}
|
|
4199
|
+
function parseDeprecationDate(value) {
|
|
4200
|
+
if (!value) return void 0;
|
|
4201
|
+
const match = /^@(-?\d+)$/.exec(value.trim());
|
|
4202
|
+
if (!match) return void 0;
|
|
4203
|
+
return Number(match[1]) * 1e3;
|
|
4204
|
+
}
|
|
4205
|
+
var ZAPIER_RESOLVED_ROUTE_STATE = Symbol("zapierResolvedRoute");
|
|
4206
|
+
function isAbsoluteUrl(url) {
|
|
4207
|
+
try {
|
|
4208
|
+
new URL(url);
|
|
4209
|
+
return true;
|
|
4210
|
+
} catch {
|
|
4211
|
+
return false;
|
|
4212
|
+
}
|
|
4213
|
+
}
|
|
4214
|
+
var zapierRouteHttpRequestPlugin = defineHook({
|
|
4215
|
+
name: "routeHttpRequest",
|
|
4216
|
+
namespace: "zapier",
|
|
4217
|
+
imports: [prepareHttpRequestPlugin, sdkOptionsPluginRef],
|
|
4218
|
+
setup: ({ imports }) => {
|
|
4219
|
+
const sdkOptions = imports.sdkOptions ?? {};
|
|
4220
|
+
return {
|
|
4221
|
+
baseUrl: sdkOptions.baseUrl ?? ZAPIER_BASE_URL,
|
|
4222
|
+
routingOptions: parseRoutingOptions({ options: sdkOptions }),
|
|
4223
|
+
debugLog: createDebugLogger(sdkOptions.debug ?? false)
|
|
4224
|
+
};
|
|
4225
|
+
},
|
|
4226
|
+
wrap: {
|
|
4227
|
+
prepareHttpRequest: ({ input, state, next }) => {
|
|
4228
|
+
const { url } = input.request;
|
|
4229
|
+
if (isAbsoluteUrl(url)) {
|
|
4230
|
+
return next(input);
|
|
4231
|
+
}
|
|
4232
|
+
validateSdkPath(url);
|
|
4233
|
+
const resolvedRoute = resolveRoute({
|
|
4234
|
+
path: url,
|
|
4235
|
+
baseUrl: state.baseUrl,
|
|
4236
|
+
routingOptions: withEnvironmentRouteOverrides({
|
|
4237
|
+
routingOptions: state.routingOptions
|
|
4238
|
+
}),
|
|
4239
|
+
debugLog: state.debugLog
|
|
4240
|
+
});
|
|
4241
|
+
input.attempt.state[ZAPIER_RESOLVED_ROUTE_STATE] = resolvedRoute;
|
|
4242
|
+
return next({
|
|
4243
|
+
...input,
|
|
4244
|
+
request: { ...input.request, url: resolvedRoute.url.toString() }
|
|
4245
|
+
});
|
|
4246
|
+
}
|
|
4247
|
+
}
|
|
4248
|
+
});
|
|
4249
|
+
|
|
4250
|
+
// src/plugins/transport/deprecation.ts
|
|
4251
|
+
var zapierDeprecationHttpResponsePlugin = defineHook({
|
|
4252
|
+
name: "deprecationHttpResponse",
|
|
4253
|
+
namespace: "zapier",
|
|
4254
|
+
imports: [receiveHttpResponsePlugin, sdkOptionsPluginRef],
|
|
4255
|
+
wrap: {
|
|
4256
|
+
receiveHttpResponse: async ({ input, imports, next }) => {
|
|
4257
|
+
const resolvedRoute = input.attempt.state[ZAPIER_RESOLVED_ROUTE_STATE];
|
|
4258
|
+
const response = await next(input);
|
|
4259
|
+
if (resolvedRoute) {
|
|
4260
|
+
handleDeprecationNotice({
|
|
4261
|
+
response,
|
|
4262
|
+
canSendDeprecationMessaging: resolvedRoute.canSendDeprecationMessaging,
|
|
4263
|
+
onEvent: imports.sdkOptions?.onEvent
|
|
4264
|
+
});
|
|
4265
|
+
}
|
|
4266
|
+
return response;
|
|
4267
|
+
}
|
|
4268
|
+
}
|
|
4198
4269
|
});
|
|
4199
4270
|
|
|
4200
4271
|
// src/plugins/transport/options.ts
|
|
@@ -4260,16 +4331,18 @@ var zapierHttpTransportPlugin = definePlugin({
|
|
|
4260
4331
|
sendHttpRequestPlugin,
|
|
4261
4332
|
retryHttpRequestPlugin,
|
|
4262
4333
|
retryHttpRequestOptionsPlugin,
|
|
4263
|
-
httpFetchPlugin
|
|
4334
|
+
httpFetchPlugin,
|
|
4335
|
+
zapierRouteHttpRequestPlugin,
|
|
4336
|
+
zapierDeprecationHttpResponsePlugin
|
|
4264
4337
|
],
|
|
4265
4338
|
exports: [sendHttpRequestPlugin]
|
|
4266
4339
|
});
|
|
4267
4340
|
|
|
4268
4341
|
// src/plugins/api/index.ts
|
|
4269
|
-
var API_ID = "zapier/api";
|
|
4270
4342
|
var apiPluginRef = declareProperty({
|
|
4271
|
-
id:
|
|
4343
|
+
id: "zapier/api"
|
|
4272
4344
|
});
|
|
4345
|
+
var API_ID = apiPluginRef.id;
|
|
4273
4346
|
function withCorrelationId({
|
|
4274
4347
|
client,
|
|
4275
4348
|
callId
|
|
@@ -4345,8 +4418,8 @@ var apiPlugin = defineProperty({
|
|
|
4345
4418
|
},
|
|
4346
4419
|
get: ({ state, callContext }) => callContext?.callId ? withCorrelationId({ client: state, callId: callContext.callId }) : state
|
|
4347
4420
|
});
|
|
4348
|
-
var
|
|
4349
|
-
var
|
|
4421
|
+
var resolveCredentialsPluginRef = declareProperty({ id: "zapier/resolveCredentials" });
|
|
4422
|
+
var RESOLVE_CREDENTIALS_ID = resolveCredentialsPluginRef.id;
|
|
4350
4423
|
var resolveCredentialsPlugin = defineProperty({
|
|
4351
4424
|
namespace: "zapier",
|
|
4352
4425
|
name: "resolveCredentials",
|
|
@@ -5035,8 +5108,8 @@ async function resolveAppKeys({
|
|
|
5035
5108
|
});
|
|
5036
5109
|
return slugResolvedLocators.filter(isResolvedAppLocator);
|
|
5037
5110
|
}
|
|
5038
|
-
var
|
|
5039
|
-
var
|
|
5111
|
+
var manifestPluginRef = declareProperty({ id: "zapier/manifest" });
|
|
5112
|
+
var MANIFEST_ID = manifestPluginRef.id;
|
|
5040
5113
|
var manifestPlugin = defineProperty({
|
|
5041
5114
|
namespace: "zapier",
|
|
5042
5115
|
name: "manifest",
|
|
@@ -5163,8 +5236,8 @@ var manifestPlugin = defineProperty({
|
|
|
5163
5236
|
});
|
|
5164
5237
|
|
|
5165
5238
|
// src/plugins/connections/index.ts
|
|
5166
|
-
var
|
|
5167
|
-
var
|
|
5239
|
+
var connectionsPluginRef = declareProperty({ id: "zapier/connections" });
|
|
5240
|
+
var CONNECTIONS_ID = connectionsPluginRef.id;
|
|
5168
5241
|
var connectionsPlugin = defineProperty({
|
|
5169
5242
|
namespace: "zapier",
|
|
5170
5243
|
name: "connections",
|
|
@@ -9486,6 +9559,9 @@ var zapierCoreOptions = {
|
|
|
9486
9559
|
);
|
|
9487
9560
|
}
|
|
9488
9561
|
};
|
|
9562
|
+
var zapierCoreOptionsPlugin = declareDefault({
|
|
9563
|
+
plugin: defineProperty(coreOptionsPluginRef, { value: zapierCoreOptions })
|
|
9564
|
+
});
|
|
9489
9565
|
var GetConnectionStartUrlSchema = z.object({
|
|
9490
9566
|
app: AppPropertySchema
|
|
9491
9567
|
}).describe(
|
|
@@ -11124,21 +11200,17 @@ var apiClientRootPlugin = definePlugin({
|
|
|
11124
11200
|
imports: [apiPlugin],
|
|
11125
11201
|
exports: []
|
|
11126
11202
|
});
|
|
11127
|
-
function
|
|
11128
|
-
return typeof request.url === "string";
|
|
11129
|
-
}
|
|
11130
|
-
function createApiClientGraphConfiguration(options) {
|
|
11203
|
+
function splitApiClientOptions(options) {
|
|
11131
11204
|
const {
|
|
11132
11205
|
maxNetworkRetryDelayMilliseconds,
|
|
11133
11206
|
maxNetworkRetryDelayMs,
|
|
11134
11207
|
approvalTimeoutMilliseconds,
|
|
11135
11208
|
approvalTimeoutMs,
|
|
11136
|
-
sendHttpRequest: _sendHttpRequest,
|
|
11137
11209
|
...sdkOptions
|
|
11138
11210
|
} = options;
|
|
11139
11211
|
return {
|
|
11140
|
-
|
|
11141
|
-
|
|
11212
|
+
sdkOptions,
|
|
11213
|
+
durations: {
|
|
11142
11214
|
maxNetworkRetryDelayMilliseconds: maxNetworkRetryDelayMilliseconds ?? maxNetworkRetryDelayMs,
|
|
11143
11215
|
approvalTimeoutMilliseconds: approvalTimeoutMilliseconds ?? approvalTimeoutMs
|
|
11144
11216
|
}
|
|
@@ -11146,39 +11218,13 @@ function createApiClientGraphConfiguration(options) {
|
|
|
11146
11218
|
}
|
|
11147
11219
|
function createApiClientFromSdkGraph(options) {
|
|
11148
11220
|
parseRoutingOptions({ options });
|
|
11149
|
-
const
|
|
11150
|
-
const
|
|
11151
|
-
|
|
11152
|
-
|
|
11153
|
-
|
|
11154
|
-
|
|
11155
|
-
const replaceSendHttpRequestPlugin = defineHook({
|
|
11156
|
-
namespace: "zapier",
|
|
11157
|
-
name: "replaceApiClientSendHttpRequest",
|
|
11158
|
-
imports: [sendHttpRequestPlugin],
|
|
11159
|
-
wrap: {
|
|
11160
|
-
// Replaces the pipeline rather than wrapping it: `next` is deliberately
|
|
11161
|
-
// unused. A transport supplied through `sendHttpRequest` owns its retry
|
|
11162
|
-
// policy, so running the SDK's stages underneath would nest the caller's
|
|
11163
|
-
// retry loop inside a second one. Dropping them is only safe because the
|
|
11164
|
-
// SDK's retry hook wraps `attemptHttpRequest`, a stage below this seam,
|
|
11165
|
-
// so replacing `sendHttpRequest` removes that loop instead of nesting
|
|
11166
|
-
// inside it. The cost is that the SDK cannot observe retries the caller
|
|
11167
|
-
// performs, and so reports a terminal 429 as zero.
|
|
11168
|
-
sendHttpRequest: ({ input }) => sendHttpRequest(
|
|
11169
|
-
hasStringUrl(input) ? input : { ...input, url: input.url.toString() }
|
|
11170
|
-
)
|
|
11171
|
-
}
|
|
11221
|
+
const { sdkOptions, durations } = splitApiClientOptions(options);
|
|
11222
|
+
const sdk = createSdk(apiClientRootPlugin, {
|
|
11223
|
+
imports: [
|
|
11224
|
+
defineProperty(sdkOptionsPluginRef, { value: sdkOptions }),
|
|
11225
|
+
defineProperty(apiClientDurationsPluginRef, { value: durations })
|
|
11226
|
+
]
|
|
11172
11227
|
});
|
|
11173
|
-
const sdk = createSdk(
|
|
11174
|
-
definePlugin({
|
|
11175
|
-
namespace: "zapier",
|
|
11176
|
-
name: "standaloneApiClientRoot",
|
|
11177
|
-
imports: [apiPlugin, replaceSendHttpRequestPlugin],
|
|
11178
|
-
exports: []
|
|
11179
|
-
}),
|
|
11180
|
-
{ configuration }
|
|
11181
|
-
);
|
|
11182
11228
|
return resolvePlugin(sdk, apiPluginRef);
|
|
11183
11229
|
}
|
|
11184
11230
|
|
|
@@ -13220,8 +13266,8 @@ function createEventEmitter(options) {
|
|
|
13220
13266
|
};
|
|
13221
13267
|
}
|
|
13222
13268
|
}
|
|
13223
|
-
var
|
|
13224
|
-
var
|
|
13269
|
+
var eventEmissionPluginRef = declareProperty({ id: "zapier/eventEmission" });
|
|
13270
|
+
var EVENT_EMISSION_ID = eventEmissionPluginRef.id;
|
|
13225
13271
|
var eventEmissionPlugin = defineProperty({
|
|
13226
13272
|
namespace: "zapier",
|
|
13227
13273
|
name: "eventEmission",
|
|
@@ -13263,12 +13309,14 @@ var zapierSdkPlugin = definePlugin({
|
|
|
13263
13309
|
name: "sdk",
|
|
13264
13310
|
// Foundation providers are internal imports (not surfaced exports): module
|
|
13265
13311
|
// plugins resolve `apiPluginRef` etc. to them; each BUILDS its value from
|
|
13266
|
-
// the
|
|
13267
|
-
// provider: importing the stand-in declares the configurable id, and
|
|
13268
|
-
// factory
|
|
13269
|
-
// `
|
|
13312
|
+
// the provided options (and sibling providers). `sdkOptions` has no
|
|
13313
|
+
// provider here: importing the stand-in declares the configurable id, and
|
|
13314
|
+
// each factory provides the caller's options in `createSdk`'s `imports`
|
|
13315
|
+
// with `defineProperty(sdkOptionsPluginRef, { value })`. Core options have a
|
|
13316
|
+
// default provider that a factory can outrank with its own.
|
|
13270
13317
|
imports: [
|
|
13271
13318
|
sdkOptionsPluginRef,
|
|
13319
|
+
zapierCoreOptionsPlugin,
|
|
13272
13320
|
apiPlugin,
|
|
13273
13321
|
resolveCredentialsPlugin,
|
|
13274
13322
|
manifestPlugin,
|
|
@@ -13355,10 +13403,7 @@ var zapierSdkPlugin = definePlugin({
|
|
|
13355
13403
|
});
|
|
13356
13404
|
function createZapierSdk(options = {}) {
|
|
13357
13405
|
return createSdk(zapierSdkPlugin, {
|
|
13358
|
-
|
|
13359
|
-
[SDK_OPTIONS_ID]: options,
|
|
13360
|
-
[CORE_OPTIONS_ID]: zapierCoreOptions
|
|
13361
|
-
}
|
|
13406
|
+
imports: [defineProperty(sdkOptionsPluginRef, { value: options })]
|
|
13362
13407
|
});
|
|
13363
13408
|
}
|
|
13364
13409
|
|