@zapier/zapier-sdk 0.117.0 → 0.119.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.
@@ -119,6 +119,9 @@ var ActionTimeoutSecondsPropertySchema = zod.z.number().min(1).optional().descri
119
119
  var ActionTimeoutMillisecondsPropertySchema = zod.z.number().min(1e3).optional().describe(
120
120
  `Maximum time to wait for action completion in milliseconds (default: ${DEFAULT_ACTION_TIMEOUT_MILLISECONDS})`
121
121
  );
122
+ var ActionIdempotencyKeyPropertySchema = zod.z.string().min(1).max(255).optional().describe(
123
+ "Key that makes retrying a run safe. Another run with the same key within 72 hours returns the original run instead of starting a new one, even if its inputs differ, so use a fresh key per distinct run. A paged run is sent with a key derived from this key and the page, so one key covers every page and retrying a page replays that page's run."
124
+ );
122
125
  var TablePropertySchema = kitcore.withPositional(
123
126
  zod.z.string().regex(/^[A-Z0-9]{26}$/, "Table ID must be a valid ULID").describe("The unique identifier of the table")
124
127
  );
@@ -532,7 +535,8 @@ var ActionExecutionInputSchema = zod.z.object({
532
535
  /** @deprecated Use `timeoutSeconds` instead. */
533
536
  timeoutMs: ActionTimeoutMillisecondsPropertySchema.meta({
534
537
  deprecated: true
535
- })
538
+ }),
539
+ idempotencyKey: ActionIdempotencyKeyPropertySchema
536
540
  }).describe(
537
541
  "Execute an action with the given inputs for the bound app, as an alternative to runAction"
538
542
  ).meta({
@@ -2824,7 +2828,7 @@ function logRouteOverride({
2824
2828
  }
2825
2829
 
2826
2830
  // src/sdk-version.ts
2827
- var SDK_VERSION = (typeof process !== "undefined" && process.env ? "0.117.0" : void 0) || "unknown";
2831
+ var SDK_VERSION = (typeof process !== "undefined" && process.env ? "0.119.0" : void 0) || "unknown";
2828
2832
 
2829
2833
  // src/utils/open-url.ts
2830
2834
  var nodePrefix = "node:";
@@ -5499,6 +5503,7 @@ var RunActionBaseSchema = zod.z.object({
5499
5503
  timeoutSeconds: ActionTimeoutSecondsPropertySchema,
5500
5504
  /** @deprecated Use `timeoutSeconds` instead. */
5501
5505
  timeoutMs: ActionTimeoutMillisecondsPropertySchema.meta({ deprecated: true }),
5506
+ idempotencyKey: ActionIdempotencyKeyPropertySchema,
5502
5507
  pageSize: zod.z.number().min(1).optional().describe("Number of results per page"),
5503
5508
  maxItems: zod.z.number().min(1).optional().describe("Maximum total items to return across all pages"),
5504
5509
  cursor: zod.z.string().optional().describe("Cursor to start from")
@@ -7248,7 +7253,8 @@ var CreateActionRunSchema = zod.z.object({
7248
7253
  ),
7249
7254
  callbackUrl: zod.z.string().url().optional().describe(
7250
7255
  "URL Zapier posts the finished run to, so you do not have to poll for it. Must use HTTPS and resolve to a public host, so a local receiver needs a tunnel. The body matches what `getActionRun` returns. Verify the `Zapier-Callback-Signature` header, and expect the same run to arrive more than once."
7251
- ).meta({ valueHint: "url" })
7256
+ ).meta({ valueHint: "url" }),
7257
+ idempotencyKey: ActionIdempotencyKeyPropertySchema
7252
7258
  }).describe(
7253
7259
  "Start an action run and return its ID without waiting for the result. Running an action is asynchronous: this hands back a run ID immediately, and `getActionRun` fetches the outcome. Reach for this pair when you want to start work and collect it later (fan out many runs, hand the ID to another process, survive a restart). `runAction` is the one-call form that starts a run and waits for its result."
7254
7260
  );
@@ -7260,6 +7266,38 @@ var ActionRunStartedItemSchema = zod.z.object({
7260
7266
  "Versioned implementation ID the run was started against (e.g. 'SlackCLIAPI@1.21.1'). The versionless app key is the part before the `@`."
7261
7267
  )
7262
7268
  });
7269
+
7270
+ // src/utils/action-run-wire.ts
7271
+ var PAGE_IDEMPOTENCY_KEY_PREFIX = "sdk-page:";
7272
+ function actionRunPath(run) {
7273
+ return `${ACTION_RUNS_PATH}/${encodeURIComponent(run)}`;
7274
+ }
7275
+ function actionRunPayload(body) {
7276
+ return body?.data;
7277
+ }
7278
+ function isActionRunPending(body) {
7279
+ return actionRunPayload(body)?.status === "waiting";
7280
+ }
7281
+ async function derivePageIdempotencyKey({
7282
+ key,
7283
+ page
7284
+ }) {
7285
+ const subtle = globalThis.crypto?.subtle;
7286
+ if (!subtle) {
7287
+ throw new ZapierConfigurationError(
7288
+ "Paging an action run with an idempotencyKey requires Web Crypto (`crypto.subtle`): Node.js 19+, or a browser page served over HTTPS or localhost."
7289
+ );
7290
+ }
7291
+ const digest = await subtle.digest(
7292
+ "SHA-256",
7293
+ new TextEncoder().encode(`${key}\0${page}`)
7294
+ );
7295
+ const hex = Array.from(
7296
+ new Uint8Array(digest),
7297
+ (byte) => byte.toString(16).padStart(2, "0")
7298
+ ).join("");
7299
+ return `${PAGE_IDEMPOTENCY_KEY_PREFIX}${hex}`;
7300
+ }
7263
7301
  var CONTEXT_CACHE_TTL_MILLISECONDS = 6e4;
7264
7302
  var CONTEXT_CACHE_MAX_SIZE = 500;
7265
7303
  var createActionRunPlugin = kitcore.defineMethod({
@@ -7359,7 +7397,8 @@ var createActionRunPlugin = kitcore.defineMethod({
7359
7397
  connection,
7360
7398
  inputs = {},
7361
7399
  page,
7362
- callbackUrl
7400
+ callbackUrl,
7401
+ idempotencyKey
7363
7402
  } = input;
7364
7403
  const connectionId = await resolveConnectionId({
7365
7404
  connection,
@@ -7390,6 +7429,9 @@ var createActionRunPlugin = kitcore.defineMethod({
7390
7429
  if (callbackUrl) {
7391
7430
  runRequestData.callback_url = callbackUrl;
7392
7431
  }
7432
+ if (idempotencyKey) {
7433
+ runRequestData.idempotency_id = page ? await derivePageIdempotencyKey({ key: idempotencyKey, page }) : idempotencyKey;
7434
+ }
7393
7435
  const runData = await api.post(
7394
7436
  ACTION_RUNS_PATH,
7395
7437
  { data: runRequestData },
@@ -7415,17 +7457,6 @@ var createActionRunPlugin = kitcore.defineMethod({
7415
7457
  }
7416
7458
  });
7417
7459
 
7418
- // src/utils/action-run-wire.ts
7419
- function actionRunPath(run) {
7420
- return `${ACTION_RUNS_PATH}/${encodeURIComponent(run)}`;
7421
- }
7422
- function actionRunPayload(body) {
7423
- return body?.data;
7424
- }
7425
- function isActionRunPending(body) {
7426
- return actionRunPayload(body)?.status === "waiting";
7427
- }
7428
-
7429
7460
  // src/plugins/runAction/index.ts
7430
7461
  var runActionPlugin = kitcore.defineMethod({
7431
7462
  name: "runAction",
@@ -7455,7 +7486,8 @@ var runActionPlugin = kitcore.defineMethod({
7455
7486
  connection,
7456
7487
  authenticationId,
7457
7488
  inputs = {},
7458
- cursor
7489
+ cursor,
7490
+ idempotencyKey
7459
7491
  } = input;
7460
7492
  const timeoutMilliseconds = (input.timeoutSeconds != null ? input.timeoutSeconds * 1e3 : input.timeoutMs) ?? DEFAULT_ACTION_TIMEOUT_MILLISECONDS;
7461
7493
  const resolvedConnectionId = await resolveConnectionId({
@@ -7470,7 +7502,8 @@ var runActionPlugin = kitcore.defineMethod({
7470
7502
  action: actionKey,
7471
7503
  connection: resolvedConnectionId,
7472
7504
  inputs,
7473
- page: cursor
7505
+ page: cursor,
7506
+ idempotencyKey
7474
7507
  });
7475
7508
  annotate({ selectedApi: started.implementation_id });
7476
7509
  const run = await imports.api.poll(
@@ -7545,7 +7578,8 @@ function createActionFunction(appKey, actionType, actionKey, imports, pinnedAuth
7545
7578
  connection: providedConnection,
7546
7579
  authenticationId: providedAuthenticationId,
7547
7580
  timeoutSeconds,
7548
- timeoutMs
7581
+ timeoutMs,
7582
+ idempotencyKey
7549
7583
  } = actionOptions;
7550
7584
  const { connectionId, connection } = resolveProxyConnection({
7551
7585
  providedConnectionId,
@@ -7561,7 +7595,8 @@ function createActionFunction(appKey, actionType, actionKey, imports, pinnedAuth
7561
7595
  inputs,
7562
7596
  connection: connectionId ?? connection,
7563
7597
  timeoutSeconds,
7564
- timeoutMs
7598
+ timeoutMs,
7599
+ idempotencyKey
7565
7600
  });
7566
7601
  };
7567
7602
  }
@@ -13667,6 +13702,7 @@ Object.defineProperty(exports, "toTitleCase", {
13667
13702
  });
13668
13703
  exports.ACTION_RUNS_PATH = ACTION_RUNS_PATH;
13669
13704
  exports.API_ID = API_ID;
13705
+ exports.ActionIdempotencyKeyPropertySchema = ActionIdempotencyKeyPropertySchema;
13670
13706
  exports.ActionKeyPropertySchema = ActionKeyPropertySchema;
13671
13707
  exports.ActionPropertySchema = ActionPropertySchema;
13672
13708
  exports.ActionTimeoutMillisecondsPropertySchema = ActionTimeoutMillisecondsPropertySchema;
@@ -13882,6 +13918,7 @@ exports.resolveCredentialsPluginRef = resolveCredentialsPluginRef;
13882
13918
  exports.runActionPlugin = runActionPlugin;
13883
13919
  exports.runWithCallerContext = runWithCallerContext;
13884
13920
  exports.sdkOptionsPluginRef = sdkOptionsPluginRef;
13921
+ exports.sleep = sleep;
13885
13922
  exports.tableFieldIdsResolver = tableFieldIdsResolver;
13886
13923
  exports.tableFieldsResolver = tableFieldsResolver;
13887
13924
  exports.tableFiltersResolver = tableFiltersResolver;