@zapier/zapier-sdk 0.108.1 → 0.109.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @zapier/zapier-sdk
2
2
 
3
+ ## 0.109.0
4
+
5
+ ### Minor Changes
6
+
7
+ - f56765a: Deprecated `createZapierApi` and `getOrCreateApiClient` in favor of building an SDK with `createSdk` and accessing `apiPluginRef` with `resolvePlugin`. Both functions continue to work with a once-per-process warning.
8
+
9
+ ### Patch Changes
10
+
11
+ - f56765a: `createZapierSdk({ cache })` now uses the caller-supplied cache for client-credentials access tokens instead of silently falling back to the default cache (the CLI's filesystem and keychain cache when installed, otherwise in-memory).
12
+
3
13
  ## 0.108.1
4
14
 
5
15
  ### Patch Changes
@@ -1,6 +1,6 @@
1
1
  import { __require } from './chunk-Y6FXYEAI.mjs';
2
2
  import { z } from 'zod';
3
- import { withPositional, declareOptionalProperty, defineProperty, createDeprecationLogger, createAsyncContext, definePlugin, sendHttpRequestPlugin, retryHttpRequestPlugin, declareProperty, defineMethod, coreOptionsPluginRef, createValidator, defineFormatter, declareMethod, defineResolver, concatLists, openEnum, defineHook, getRegistryPlugin, paginate, toSnakeCase, isCoreError, toTitleCase, createSdk, RETRY_HTTP_REQUEST_OPTIONS_ID, CORE_ERROR_SYMBOL, CoreErrorCode, CORE_SIGNAL_SYMBOL, isCoreSignal, CORE_OPTIONS_ID } from '@zapier/kitcore';
3
+ import { withPositional, createDeprecationLogger, createAsyncContext, declareOptionalProperty, defineProperty, definePlugin, sendHttpRequestPlugin, retryHttpRequestPlugin, declareProperty, defineMethod, coreOptionsPluginRef, createValidator, defineFormatter, declareMethod, defineResolver, concatLists, openEnum, defineHook, getRegistryPlugin, paginate, toSnakeCase, isCoreError, toTitleCase, CORE_ERROR_SYMBOL, CoreErrorCode, CORE_SIGNAL_SYMBOL, isCoreSignal, createSdk, CORE_OPTIONS_ID, resolvePlugin } from '@zapier/kitcore';
4
4
  export { CONTEXT, CORE_ERROR_SYMBOL, CORE_OPTIONS_ID, CORE_SIGNAL_SYMBOL, CoreCancelledSignal, CoreDisposeError, CoreErrorCode, CoreSignal, addPlugin, composePlugins, createController, createCorePlugin, createFunction, createPaginatedFunction, createPaginatedPluginMethod, createPluginMethod, createPluginStack, createSdk, declareMethod, declareOptionalProperty, declarePlugin, declareProperty, defineFormatter, defineLegacyMerge, defineMethod, defineMethodOverride, defineOverride, definePlugin, defineProperty, defineResolver, disposeSdk, fromFunctionPlugin, getContext, getCoreErrorCause, getCoreErrorCode, getNegatable, getRegistryPlugin, isCoreCancelledSignal, isCoreError, isCoreSignal, isPositional, omitExports, resolvePlugin, runInMethodScope, runWithTelemetryContext, selectExports, toSnakeCase, toTitleCase } from '@zapier/kitcore';
5
5
  import { buildHttpRequestContext, buildActionRunContext } from '@zapier/policy-context';
6
6
  import { ListAppsQuerySchema, AppItemSchema as AppItemSchema$1 } from '@zapier/zapier-sdk-core/v0/schemas/apps';
@@ -605,6 +605,83 @@ function extractUserIdsFromJwt(token) {
605
605
  };
606
606
  }
607
607
 
608
+ // src/api/concurrency.ts
609
+ var NO_OP_RELEASE = () => {
610
+ };
611
+ var NO_OP_SEMAPHORE = {
612
+ acquire: async () => NO_OP_RELEASE,
613
+ tryAcquire: () => NO_OP_RELEASE
614
+ };
615
+ function createSemaphore(maxPermits) {
616
+ if (maxPermits === Infinity) {
617
+ return NO_OP_SEMAPHORE;
618
+ }
619
+ if (!Number.isInteger(maxPermits) || maxPermits <= 0) {
620
+ throw new Error(
621
+ `maxPermits must be a positive integer or Infinity, got: ${maxPermits}`
622
+ );
623
+ }
624
+ let permits = maxPermits;
625
+ const waiters = [];
626
+ const release = () => {
627
+ const next = waiters.shift();
628
+ if (next) {
629
+ next.grant();
630
+ } else {
631
+ permits++;
632
+ }
633
+ };
634
+ const makeReleaseOnce = () => {
635
+ let released = false;
636
+ return () => {
637
+ if (released) return;
638
+ released = true;
639
+ release();
640
+ };
641
+ };
642
+ return {
643
+ tryAcquire() {
644
+ if (permits > 0) {
645
+ permits--;
646
+ return makeReleaseOnce();
647
+ }
648
+ return null;
649
+ },
650
+ async acquire(signal) {
651
+ if (signal?.aborted) {
652
+ throw signal.reason ?? new DOMException("Aborted", "AbortError");
653
+ }
654
+ if (permits > 0) {
655
+ permits--;
656
+ return makeReleaseOnce();
657
+ }
658
+ return new Promise((resolve2, reject) => {
659
+ const onAbort = () => {
660
+ const idx = waiters.indexOf(waiter);
661
+ if (idx !== -1) {
662
+ waiters.splice(idx, 1);
663
+ waiter.cancel(
664
+ signal?.reason ?? new DOMException("Aborted", "AbortError")
665
+ );
666
+ }
667
+ };
668
+ const waiter = {
669
+ grant: () => {
670
+ signal?.removeEventListener("abort", onAbort);
671
+ resolve2(makeReleaseOnce());
672
+ },
673
+ cancel: (reason) => {
674
+ signal?.removeEventListener("abort", onAbort);
675
+ reject(reason);
676
+ }
677
+ };
678
+ signal?.addEventListener("abort", onAbort);
679
+ waiters.push(waiter);
680
+ });
681
+ }
682
+ };
683
+ }
684
+
608
685
  // src/api/debug.ts
609
686
  var utilModule = null;
610
687
  var utilPromise = null;
@@ -997,86 +1074,21 @@ async function pollUntilComplete(options) {
997
1074
  }
998
1075
  }
999
1076
 
1000
- // src/api/concurrency.ts
1001
- var NO_OP_RELEASE = () => {
1002
- };
1003
- var NO_OP_SEMAPHORE = {
1004
- acquire: async () => NO_OP_RELEASE,
1005
- tryAcquire: () => NO_OP_RELEASE
1006
- };
1007
- function createSemaphore(maxPermits) {
1008
- if (maxPermits === Infinity) {
1009
- return NO_OP_SEMAPHORE;
1010
- }
1011
- if (!Number.isInteger(maxPermits) || maxPermits <= 0) {
1012
- throw new Error(
1013
- `maxPermits must be a positive integer or Infinity, got: ${maxPermits}`
1014
- );
1015
- }
1016
- let permits = maxPermits;
1017
- const waiters = [];
1018
- const release = () => {
1019
- const next = waiters.shift();
1020
- if (next) {
1021
- next.grant();
1022
- } else {
1023
- permits++;
1024
- }
1025
- };
1026
- const makeReleaseOnce = () => {
1027
- let released = false;
1028
- return () => {
1029
- if (released) return;
1030
- released = true;
1031
- release();
1032
- };
1033
- };
1034
- return {
1035
- tryAcquire() {
1036
- if (permits > 0) {
1037
- permits--;
1038
- return makeReleaseOnce();
1039
- }
1040
- return null;
1041
- },
1042
- async acquire(signal) {
1043
- if (signal?.aborted) {
1044
- throw signal.reason ?? new DOMException("Aborted", "AbortError");
1045
- }
1046
- if (permits > 0) {
1047
- permits--;
1048
- return makeReleaseOnce();
1049
- }
1050
- return new Promise((resolve2, reject) => {
1051
- const onAbort = () => {
1052
- const idx = waiters.indexOf(waiter);
1053
- if (idx !== -1) {
1054
- waiters.splice(idx, 1);
1055
- waiter.cancel(
1056
- signal?.reason ?? new DOMException("Aborted", "AbortError")
1057
- );
1058
- }
1059
- };
1060
- const waiter = {
1061
- grant: () => {
1062
- signal?.removeEventListener("abort", onAbort);
1063
- resolve2(makeReleaseOnce());
1064
- },
1065
- cancel: (reason) => {
1066
- signal?.removeEventListener("abort", onAbort);
1067
- reject(reason);
1068
- }
1069
- };
1070
- signal?.addEventListener("abort", onAbort);
1071
- waiters.push(waiter);
1072
- });
1073
- }
1074
- };
1077
+ // src/api/correlation.ts
1078
+ var CORRELATION_CALL_ID = Symbol(
1079
+ "zapier.correlationCallId"
1080
+ );
1081
+ function resolveCorrelationId({
1082
+ options,
1083
+ callId
1084
+ }) {
1085
+ return options?.correlationId || getZapierCorrelationId() || callId || void 0;
1086
+ }
1087
+ function resolveCausationId({
1088
+ options
1089
+ }) {
1090
+ return options?.causationId || getZapierCausationId();
1075
1091
  }
1076
- var SDK_OPTIONS_ID = "zapier/sdkOptions";
1077
- var sdkOptionsPluginRef = declareOptionalProperty({
1078
- id: SDK_OPTIONS_ID
1079
- });
1080
1092
 
1081
1093
  // src/api/rate-limit.ts
1082
1094
  var EPOCH_THRESHOLD_SECONDS = 1e9;
@@ -1162,99 +1174,6 @@ function createRetryObserver({
1162
1174
  }
1163
1175
  };
1164
1176
  }
1165
-
1166
- // src/plugins/transport/options.ts
1167
- var RETRYABLE_STATUSES = [429, 500, 502, 503, 504];
1168
- var NON_IDEMPOTENT_RETRYABLE_STATUSES = [429];
1169
- function resolveRetryHttpRequestOptions({
1170
- maxNetworkRetries,
1171
- maxNetworkRetryDelayMilliseconds,
1172
- onEvent
1173
- }) {
1174
- const retries = maxNetworkRetries ?? ZAPIER_MAX_NETWORK_RETRIES;
1175
- return {
1176
- maxAttempts: retries + 1,
1177
- maxDelayMilliseconds: maxNetworkRetryDelayMilliseconds ?? ZAPIER_MAX_NETWORK_RETRY_DELAY_MILLISECONDS,
1178
- retryStatuses: RETRYABLE_STATUSES,
1179
- nonIdempotentRetryStatuses: NON_IDEMPOTENT_RETRYABLE_STATUSES,
1180
- onRetry: createRetryObserver({ onEvent, maxNetworkRetries: retries })
1181
- };
1182
- }
1183
- function resolveNetworkRetryDelayMilliseconds({
1184
- maxNetworkRetryDelaySeconds,
1185
- maxNetworkRetryDelayMs
1186
- }) {
1187
- return maxNetworkRetryDelaySeconds != null ? maxNetworkRetryDelaySeconds * 1e3 : maxNetworkRetryDelayMs;
1188
- }
1189
- function resolveTransportFetch({
1190
- fetch: customFetch,
1191
- debug = false
1192
- }) {
1193
- const originalFetch = customFetch ?? ((input, init) => globalThis.fetch(input, init));
1194
- if (!debug) return originalFetch;
1195
- return createDebugFetch({
1196
- originalFetch,
1197
- debugLog: createDebugLogger(debug)
1198
- });
1199
- }
1200
-
1201
- // src/plugins/transport/http-fetch.ts
1202
- var httpFetchPlugin = defineProperty({
1203
- namespace: "kitcore",
1204
- name: "httpFetch",
1205
- imports: [sdkOptionsPluginRef],
1206
- setup: ({ imports }) => resolveTransportFetch({
1207
- fetch: imports.sdkOptions?.fetch,
1208
- debug: imports.sdkOptions?.debug
1209
- }),
1210
- get: ({ state }) => state
1211
- });
1212
-
1213
- // src/plugins/transport/standalone.ts
1214
- function createZapierSendHttpRequest({
1215
- fetch: customFetch,
1216
- debug,
1217
- maxNetworkRetries,
1218
- maxNetworkRetryDelayMilliseconds,
1219
- onEvent
1220
- }) {
1221
- const sdk = createSdk(
1222
- definePlugin({
1223
- name: "zapierStandaloneHttpTransport",
1224
- imports: [sendHttpRequestPlugin, retryHttpRequestPlugin, httpFetchPlugin],
1225
- exports: [sendHttpRequestPlugin]
1226
- }),
1227
- {
1228
- configuration: {
1229
- [SDK_OPTIONS_ID]: { fetch: customFetch, debug },
1230
- // Filled by configuration rather than the graph's property plugin: the
1231
- // caller here holds client-shaped ms options, not SDK options.
1232
- [RETRY_HTTP_REQUEST_OPTIONS_ID]: resolveRetryHttpRequestOptions({
1233
- maxNetworkRetries,
1234
- maxNetworkRetryDelayMilliseconds,
1235
- onEvent
1236
- })
1237
- }
1238
- }
1239
- );
1240
- return sdk.sendHttpRequest;
1241
- }
1242
-
1243
- // src/api/correlation.ts
1244
- var CORRELATION_CALL_ID = Symbol(
1245
- "zapier.correlationCallId"
1246
- );
1247
- function resolveCorrelationId({
1248
- options,
1249
- callId
1250
- }) {
1251
- return options?.correlationId || getZapierCorrelationId() || callId || void 0;
1252
- }
1253
- function resolveCausationId({
1254
- options
1255
- }) {
1256
- return options?.causationId || getZapierCausationId();
1257
- }
1258
1177
  var ClientCredentialsObjectSchema = z.object({
1259
1178
  type: z.enum(["client_credentials"]).optional().meta({ internal: true }),
1260
1179
  clientId: z.string().describe("OAuth client ID for authentication.").meta({ valueHint: "id" }),
@@ -2878,7 +2797,7 @@ function logRouteOverride({
2878
2797
  }
2879
2798
 
2880
2799
  // src/sdk-version.ts
2881
- var SDK_VERSION = (typeof process !== "undefined" && process.env ? "0.108.1" : void 0) || "unknown";
2800
+ var SDK_VERSION = (typeof process !== "undefined" && process.env ? "0.109.0" : void 0) || "unknown";
2882
2801
 
2883
2802
  // src/utils/open-url.ts
2884
2803
  var nodePrefix = "node:";
@@ -3897,7 +3816,7 @@ var ZapierApiClient = class {
3897
3816
  }
3898
3817
  await openApproval(approval.approval_url);
3899
3818
  }
3900
- const timeoutMs = this.options.approvalTimeoutMilliseconds ?? this.options.approvalTimeoutMs ?? DEFAULT_APPROVAL_TIMEOUT_MILLISECONDS;
3819
+ const timeoutMs = this.options.approvalTimeoutMilliseconds ?? DEFAULT_APPROVAL_TIMEOUT_MILLISECONDS;
3901
3820
  const approvalDeadline = Date.now() + timeoutMs;
3902
3821
  let streamAbortController;
3903
3822
  let streamPromise;
@@ -4065,7 +3984,7 @@ var ZapierApiClient = class {
4065
3984
  );
4066
3985
  }
4067
3986
  };
4068
- var createZapierApi = (options) => {
3987
+ var createApiClient = (options) => {
4069
3988
  const { debug = false, fetch: originalFetch = globalThis.fetch } = options;
4070
3989
  const routingOptions = parseRoutingOptions({ options });
4071
3990
  const debugLog = createDebugLogger(debug);
@@ -4076,62 +3995,94 @@ var createZapierApi = (options) => {
4076
3995
  // The credential-exchange transport. Debug-wrapped here rather than in the
4077
3996
  // pipeline because `resolveAuthToken` is issued outside it.
4078
3997
  fetch: debugFetch,
4079
- // Built from the caller's own `fetch`, not `debugFetch`: the pipeline wraps
4080
- // for debug itself, and passing the wrapped one would log twice.
4081
- sendHttpRequest: options.sendHttpRequest ?? createZapierSendHttpRequest({
4082
- fetch: options.fetch,
4083
- debug,
4084
- onEvent: options.onEvent,
4085
- maxNetworkRetries: options.maxNetworkRetries,
4086
- maxNetworkRetryDelayMilliseconds: options.maxNetworkRetryDelayMilliseconds ?? options.maxNetworkRetryDelayMs
4087
- }),
3998
+ sendHttpRequest: options.sendHttpRequest,
4088
3999
  debugLog,
4089
4000
  routingOptions
4090
4001
  });
4091
4002
  };
4092
-
4093
- // src/api/error-classification.ts
4094
- function isPermanentHttpError(err) {
4095
- if (!isZapierError(err)) return false;
4096
- if (isZapierAuthenticationError(err) && err.statusCode === void 0) {
4097
- return true;
4003
+ var API_CLIENT_DURATIONS_ID = "zapier/apiClientDurations";
4004
+ var apiClientDurationsPluginRef = declareOptionalProperty({
4005
+ id: API_CLIENT_DURATIONS_ID
4006
+ });
4007
+ function resolveNetworkRetryDelayMilliseconds({
4008
+ apiClientDurations,
4009
+ sdkOptions
4010
+ }) {
4011
+ if (apiClientDurations?.maxNetworkRetryDelayMilliseconds != null) {
4012
+ return apiClientDurations.maxNetworkRetryDelayMilliseconds;
4098
4013
  }
4099
- const { statusCode } = err;
4100
- return statusCode !== void 0 && statusCode >= 400 && statusCode < 500 && statusCode !== 429;
4014
+ if (sdkOptions?.maxNetworkRetryDelaySeconds != null) {
4015
+ return sdkOptions.maxNetworkRetryDelaySeconds * 1e3;
4016
+ }
4017
+ return sdkOptions?.maxNetworkRetryDelayMs;
4101
4018
  }
4102
-
4103
- // src/api/index.ts
4104
- function getOrCreateApiClient(config) {
4105
- const {
4106
- baseUrl = ZAPIER_BASE_URL,
4107
- credentials,
4108
- token,
4109
- api: providedApi,
4110
- debug = false,
4111
- fetch: customFetch,
4112
- callerPackage
4113
- } = config;
4114
- if (providedApi) {
4115
- return providedApi;
4019
+ function resolveApprovalTimeoutMilliseconds({
4020
+ apiClientDurations,
4021
+ sdkOptions
4022
+ }) {
4023
+ if (apiClientDurations?.approvalTimeoutMilliseconds != null) {
4024
+ return apiClientDurations.approvalTimeoutMilliseconds;
4116
4025
  }
4117
- return createZapierApi({
4118
- baseUrl,
4119
- credentials,
4120
- token,
4121
- debug,
4122
- fetch: customFetch,
4123
- callerPackage
4026
+ if (sdkOptions?.approvalTimeoutSeconds != null) {
4027
+ return sdkOptions.approvalTimeoutSeconds * 1e3;
4028
+ }
4029
+ return sdkOptions?.approvalTimeoutMs;
4030
+ }
4031
+ var SDK_OPTIONS_ID = "zapier/sdkOptions";
4032
+ var sdkOptionsPluginRef = declareOptionalProperty({
4033
+ id: SDK_OPTIONS_ID
4034
+ });
4035
+
4036
+ // src/plugins/transport/options.ts
4037
+ var RETRYABLE_STATUSES = [429, 500, 502, 503, 504];
4038
+ var NON_IDEMPOTENT_RETRYABLE_STATUSES = [429];
4039
+ function resolveRetryHttpRequestOptions({
4040
+ maxNetworkRetries,
4041
+ maxNetworkRetryDelayMilliseconds,
4042
+ onEvent
4043
+ }) {
4044
+ const retries = maxNetworkRetries ?? ZAPIER_MAX_NETWORK_RETRIES;
4045
+ return {
4046
+ maxAttempts: retries + 1,
4047
+ maxDelayMilliseconds: maxNetworkRetryDelayMilliseconds ?? ZAPIER_MAX_NETWORK_RETRY_DELAY_MILLISECONDS,
4048
+ retryStatuses: RETRYABLE_STATUSES,
4049
+ nonIdempotentRetryStatuses: NON_IDEMPOTENT_RETRYABLE_STATUSES,
4050
+ onRetry: createRetryObserver({ onEvent, maxNetworkRetries: retries })
4051
+ };
4052
+ }
4053
+ function resolveTransportFetch({
4054
+ fetch: customFetch,
4055
+ debug = false
4056
+ }) {
4057
+ const originalFetch = customFetch ?? ((input, init) => globalThis.fetch(input, init));
4058
+ if (!debug) return originalFetch;
4059
+ return createDebugFetch({
4060
+ originalFetch,
4061
+ debugLog: createDebugLogger(debug)
4124
4062
  });
4125
4063
  }
4064
+
4065
+ // src/plugins/transport/http-fetch.ts
4066
+ var httpFetchPlugin = defineProperty({
4067
+ namespace: "kitcore",
4068
+ name: "httpFetch",
4069
+ imports: [sdkOptionsPluginRef],
4070
+ setup: ({ imports }) => resolveTransportFetch({
4071
+ fetch: imports.sdkOptions?.fetch,
4072
+ debug: imports.sdkOptions?.debug
4073
+ }),
4074
+ get: ({ state }) => state
4075
+ });
4126
4076
  var retryHttpRequestOptionsPlugin = defineProperty({
4127
4077
  namespace: "kitcore",
4128
4078
  name: "retryHttpRequestOptions",
4129
- imports: [sdkOptionsPluginRef],
4079
+ imports: [sdkOptionsPluginRef, apiClientDurationsPluginRef],
4130
4080
  setup: ({ imports }) => resolveRetryHttpRequestOptions({
4131
4081
  maxNetworkRetries: imports.sdkOptions?.maxNetworkRetries,
4132
- maxNetworkRetryDelayMilliseconds: resolveNetworkRetryDelayMilliseconds(
4133
- imports.sdkOptions ?? {}
4134
- ),
4082
+ maxNetworkRetryDelayMilliseconds: resolveNetworkRetryDelayMilliseconds({
4083
+ apiClientDurations: imports.apiClientDurations,
4084
+ sdkOptions: imports.sdkOptions
4085
+ }),
4135
4086
  onEvent: imports.sdkOptions?.onEvent
4136
4087
  }),
4137
4088
  get: ({ state }) => state
@@ -4175,10 +4126,14 @@ function withCorrelationId({
4175
4126
  var apiPlugin = defineProperty({
4176
4127
  namespace: "zapier",
4177
4128
  name: "api",
4178
- // Import the aggregate so it also provides `kitcore/httpFetch`; importing
4179
- // `sendHttpRequestPlugin` alone would bypass `sdkOptions.fetch`.
4180
- imports: [sdkOptionsPluginRef, zapierHttpTransportPlugin],
4129
+ // Import the aggregate so SDK options and host transport wraps are applied.
4130
+ imports: [
4131
+ sdkOptionsPluginRef,
4132
+ apiClientDurationsPluginRef,
4133
+ zapierHttpTransportPlugin
4134
+ ],
4181
4135
  setup: ({ imports }) => {
4136
+ const sdkOptions = imports.sdkOptions ?? {};
4182
4137
  const {
4183
4138
  fetch: customFetch = globalThis.fetch,
4184
4139
  baseUrl = ZAPIER_BASE_URL,
@@ -4186,38 +4141,33 @@ var apiPlugin = defineProperty({
4186
4141
  token,
4187
4142
  onEvent,
4188
4143
  debug = false,
4189
- maxNetworkRetries = ZAPIER_MAX_NETWORK_RETRIES,
4190
- maxNetworkRetryDelaySeconds,
4191
- maxNetworkRetryDelayMs,
4192
4144
  maxConcurrentRequests = ZAPIER_MAX_CONCURRENT_REQUESTS,
4193
- approvalTimeoutSeconds,
4194
- approvalTimeoutMs,
4195
4145
  maxApprovalRetries,
4196
4146
  approvalMode,
4197
4147
  openAutoModeApprovalsInBrowser,
4198
4148
  callerPackage,
4149
+ cache,
4199
4150
  routeOverrides,
4200
4151
  correlationId,
4201
4152
  causationId
4202
- } = imports.sdkOptions ?? {};
4203
- return createZapierApi({
4153
+ } = sdkOptions;
4154
+ return createApiClient({
4204
4155
  baseUrl,
4205
4156
  credentials,
4206
4157
  token,
4207
4158
  debug,
4208
4159
  fetch: customFetch,
4209
4160
  onEvent,
4210
- maxNetworkRetries,
4211
- maxNetworkRetryDelayMilliseconds: resolveNetworkRetryDelayMilliseconds({
4212
- maxNetworkRetryDelaySeconds,
4213
- maxNetworkRetryDelayMs
4214
- }) ?? ZAPIER_MAX_NETWORK_RETRY_DELAY_MILLISECONDS,
4215
4161
  maxConcurrentRequests,
4216
- approvalTimeoutMilliseconds: approvalTimeoutSeconds != null ? approvalTimeoutSeconds * 1e3 : approvalTimeoutMs,
4162
+ approvalTimeoutMilliseconds: resolveApprovalTimeoutMilliseconds({
4163
+ apiClientDurations: imports.apiClientDurations,
4164
+ sdkOptions
4165
+ }),
4217
4166
  maxApprovalRetries,
4218
4167
  approvalMode,
4219
4168
  openAutoModeApprovalsInBrowser,
4220
4169
  callerPackage,
4170
+ cache,
4221
4171
  routeOverrides,
4222
4172
  // Inject the graph-composed transport so host `dispatchHttpRequest` wraps
4223
4173
  // apply.
@@ -10517,6 +10467,112 @@ var drainTriggerInboxPlugin = defineMethod({
10517
10467
  });
10518
10468
  }
10519
10469
  });
10470
+ var apiClientRootPlugin = definePlugin({
10471
+ namespace: "zapier",
10472
+ name: "apiClientRoot",
10473
+ imports: [apiPlugin],
10474
+ exports: []
10475
+ });
10476
+ function hasStringUrl(request) {
10477
+ return typeof request.url === "string";
10478
+ }
10479
+ function createApiClientGraphConfiguration(options) {
10480
+ const {
10481
+ maxNetworkRetryDelayMilliseconds,
10482
+ maxNetworkRetryDelayMs,
10483
+ approvalTimeoutMilliseconds,
10484
+ approvalTimeoutMs,
10485
+ sendHttpRequest: _sendHttpRequest,
10486
+ ...sdkOptions
10487
+ } = options;
10488
+ return {
10489
+ [SDK_OPTIONS_ID]: sdkOptions,
10490
+ [API_CLIENT_DURATIONS_ID]: {
10491
+ maxNetworkRetryDelayMilliseconds: maxNetworkRetryDelayMilliseconds ?? maxNetworkRetryDelayMs,
10492
+ approvalTimeoutMilliseconds: approvalTimeoutMilliseconds ?? approvalTimeoutMs
10493
+ }
10494
+ };
10495
+ }
10496
+ function createApiClientFromSdkGraph(options) {
10497
+ parseRoutingOptions({ options });
10498
+ const configuration = createApiClientGraphConfiguration(options);
10499
+ const { sendHttpRequest } = options;
10500
+ if (!sendHttpRequest) {
10501
+ const sdk2 = createSdk(apiClientRootPlugin, { configuration });
10502
+ return resolvePlugin(sdk2, apiPluginRef);
10503
+ }
10504
+ const replaceSendHttpRequestPlugin = defineHook({
10505
+ namespace: "zapier",
10506
+ name: "replaceApiClientSendHttpRequest",
10507
+ imports: [sendHttpRequestPlugin],
10508
+ wrap: {
10509
+ // Replaces the pipeline rather than wrapping it: `next` is deliberately
10510
+ // unused. A transport supplied through `sendHttpRequest` owns its retry
10511
+ // policy, so running the SDK's stages underneath would nest the caller's
10512
+ // retry loop inside a second one. Dropping them is only safe because the
10513
+ // SDK's retry hook wraps `attemptHttpRequest`, a stage below this seam,
10514
+ // so replacing `sendHttpRequest` removes that loop instead of nesting
10515
+ // inside it. The cost is that the SDK cannot observe retries the caller
10516
+ // performs, and so reports a terminal 429 as zero.
10517
+ sendHttpRequest: ({ input }) => sendHttpRequest(
10518
+ hasStringUrl(input) ? input : { ...input, url: input.url.toString() }
10519
+ )
10520
+ }
10521
+ });
10522
+ const sdk = createSdk(
10523
+ definePlugin({
10524
+ namespace: "zapier",
10525
+ name: "standaloneApiClientRoot",
10526
+ imports: [apiPlugin, replaceSendHttpRequestPlugin],
10527
+ exports: []
10528
+ }),
10529
+ { configuration }
10530
+ );
10531
+ return resolvePlugin(sdk, apiPluginRef);
10532
+ }
10533
+
10534
+ // src/api/error-classification.ts
10535
+ function isPermanentHttpError(err) {
10536
+ if (!isZapierError(err)) return false;
10537
+ if (isZapierAuthenticationError(err) && err.statusCode === void 0) {
10538
+ return true;
10539
+ }
10540
+ const { statusCode } = err;
10541
+ return statusCode !== void 0 && statusCode >= 400 && statusCode < 500 && statusCode !== 429;
10542
+ }
10543
+
10544
+ // src/api/index.ts
10545
+ function createZapierApi(options) {
10546
+ logDeprecation(
10547
+ "createZapierApi is deprecated and will be removed in a future release. Build an SDK with createSdk and access apiPluginRef with resolvePlugin instead."
10548
+ );
10549
+ return createApiClientFromSdkGraph(options);
10550
+ }
10551
+ function getOrCreateApiClient(config) {
10552
+ logDeprecation(
10553
+ "getOrCreateApiClient is deprecated and will be removed in a future release. Use a provided API client directly, or build an SDK with createSdk and access apiPluginRef with resolvePlugin."
10554
+ );
10555
+ const {
10556
+ baseUrl = ZAPIER_BASE_URL,
10557
+ credentials,
10558
+ token,
10559
+ api: providedApi,
10560
+ debug = false,
10561
+ fetch: customFetch,
10562
+ callerPackage
10563
+ } = config;
10564
+ if (providedApi) {
10565
+ return providedApi;
10566
+ }
10567
+ return createApiClientFromSdkGraph({
10568
+ baseUrl,
10569
+ credentials,
10570
+ token,
10571
+ debug,
10572
+ fetch: customFetch,
10573
+ callerPackage
10574
+ });
10575
+ }
10520
10576
 
10521
10577
  // src/plugins/triggers/watchTriggerInbox/sse.ts
10522
10578
  async function* readInboxEvents({