@zapier/zapier-sdk 0.87.1 → 0.88.1

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.
@@ -173,12 +173,19 @@ function composeVoid(existing, added) {
173
173
  isolated.add(composed);
174
174
  return composed;
175
175
  }
176
+ function composeAnnotators(existing, added) {
177
+ if (!existing) return added;
178
+ if (!added) return existing;
179
+ return (ctx) => ({ ...existing(ctx), ...added(ctx) });
180
+ }
176
181
  function buildHooks(existing, added) {
177
182
  const result = {};
178
183
  const start2 = composeVoid(existing.onMethodStart, added.onMethodStart);
179
184
  if (start2) result.onMethodStart = start2;
180
185
  const end = composeVoid(existing.onMethodEnd, added.onMethodEnd);
181
186
  if (end) result.onMethodEnd = end;
187
+ const annotator = composeAnnotators(existing.annotator, added.annotator);
188
+ if (annotator) result.annotator = annotator;
182
189
  return result;
183
190
  }
184
191
  function createDeprecationLogger(tag) {
@@ -580,11 +587,14 @@ function generateCallId() {
580
587
  }
581
588
  return null;
582
589
  }
583
- function rootCallContext() {
590
+ function rootCallContext({
591
+ callOrigin = "surface"
592
+ } = {}) {
584
593
  return {
585
594
  callId: generateCallId(),
586
595
  depth: 0,
587
596
  annotations: {},
597
+ callOrigin,
588
598
  [CALL_CONTEXT_BRAND]: true
589
599
  };
590
600
  }
@@ -593,6 +603,7 @@ function childCallContext(parent) {
593
603
  callId: parent.callId,
594
604
  depth: parent.depth + 1,
595
605
  annotations: {},
606
+ callOrigin: parent.callOrigin,
596
607
  [CALL_CONTEXT_BRAND]: true
597
608
  };
598
609
  }
@@ -614,6 +625,28 @@ var INTERNAL_CALL = Symbol("kitcore.internalCall");
614
625
  function resolveCallContext(secondArg) {
615
626
  return isCallContext(secondArg) ? secondArg : rootCallContext();
616
627
  }
628
+ var hookAnnotatorReentrancy = 0;
629
+ function applyAnnotations({
630
+ context,
631
+ methodName,
632
+ input,
633
+ hookAnnotator,
634
+ methodAnnotator
635
+ }) {
636
+ if (hookAnnotator && !isInsideObserver() && context.depth === 0 && context.callOrigin !== "internal" && hookAnnotatorReentrancy === 0) {
637
+ hookAnnotatorReentrancy++;
638
+ try {
639
+ Object.assign(context.annotations, hookAnnotator({ methodName, input }));
640
+ } catch {
641
+ } finally {
642
+ hookAnnotatorReentrancy--;
643
+ }
644
+ }
645
+ try {
646
+ Object.assign(context.annotations, methodAnnotator?.(input));
647
+ } catch {
648
+ }
649
+ }
617
650
  function signalDeprecation(context, methodName, getDeprecation) {
618
651
  if (isInsideObserver()) return;
619
652
  const deprecation = getDeprecation?.();
@@ -639,7 +672,7 @@ function normalizeError(error, adaptError) {
639
672
  );
640
673
  }
641
674
  function createFunction(coreFn, options) {
642
- const { sdk, schema, name, getDeprecation } = options;
675
+ const { sdk, schema, name, annotator, getDeprecation } = options;
643
676
  const functionName = name || coreFn.name;
644
677
  const namedFunctions = {
645
678
  [functionName]: async function(callOptions) {
@@ -653,14 +686,26 @@ function createFunction(coreFn, options) {
653
686
  const normalizedOptions = callOptions ?? {};
654
687
  const args = [normalizedOptions];
655
688
  const depth = Math.max(context.depth, getCurrentDepth());
656
- const hooks = isInsideObserver() ? void 0 : sdk.context.hooks;
689
+ const insideObserver = isInsideObserver();
690
+ const hooks = insideObserver ? void 0 : sdk.context.hooks;
657
691
  const adaptError = resolveCoreOptions(sdk.context)?.adaptError;
658
- hooks?.onMethodStart?.({
692
+ applyAnnotations({
693
+ context,
694
+ methodName: functionName,
695
+ input: normalizedOptions,
696
+ hookAnnotator: hooks?.annotator,
697
+ methodAnnotator: annotator
698
+ });
699
+ const hookBase = {
659
700
  methodName: functionName,
660
701
  args,
661
702
  isPaginated: false,
662
- depth
663
- });
703
+ depth,
704
+ callId: context.callId,
705
+ callOrigin: context.callOrigin,
706
+ annotations: context.annotations
707
+ };
708
+ hooks?.onMethodStart?.({ ...hookBase });
664
709
  try {
665
710
  let result;
666
711
  if (schema) {
@@ -682,20 +727,14 @@ function createFunction(coreFn, options) {
682
727
  result = await coreFn(normalizedOptions, context);
683
728
  }
684
729
  hooks?.onMethodEnd?.({
685
- methodName: functionName,
686
- args,
687
- isPaginated: false,
688
- depth,
730
+ ...hookBase,
689
731
  durationMs: Date.now() - startTime
690
732
  });
691
733
  return result;
692
734
  } catch (error) {
693
735
  const normalizedError = normalizeError(error, adaptError);
694
736
  hooks?.onMethodEnd?.({
695
- methodName: functionName,
696
- args,
697
- isPaginated: false,
698
- depth,
737
+ ...hookBase,
699
738
  durationMs: Date.now() - startTime,
700
739
  error: normalizedError
701
740
  });
@@ -707,7 +746,7 @@ function createFunction(coreFn, options) {
707
746
  return namedFunctions[functionName];
708
747
  }
709
748
  function createRawFunction(coreFn, options) {
710
- const { sdk, name, schema, positional, getDeprecation } = options;
749
+ const { sdk, name, schema, positional, annotator, getDeprecation } = options;
711
750
  return function(rawInput) {
712
751
  const internal = arguments[1];
713
752
  const context = resolveCallContext(internal);
@@ -717,23 +756,32 @@ function createRawFunction(coreFn, options) {
717
756
  return runInMethodScope(() => {
718
757
  const startTime = Date.now();
719
758
  const depth = Math.max(context.depth, getCurrentDepth());
720
- const hooks = isInsideObserver() ? void 0 : sdk.context.hooks;
759
+ const insideObserver = isInsideObserver();
760
+ const hooks = insideObserver ? void 0 : sdk.context.hooks;
721
761
  const adaptError = resolveCoreOptions(sdk.context)?.adaptError;
722
762
  const input = schema ? rawInput ?? {} : rawInput;
763
+ applyAnnotations({
764
+ context,
765
+ methodName: name,
766
+ input,
767
+ hookAnnotator: hooks?.annotator,
768
+ methodAnnotator: annotator
769
+ });
723
770
  const record = input;
724
771
  const args = positional ? positional.filter((key) => record?.[key] !== void 0).map((key) => record?.[key]) : [input];
725
- hooks?.onMethodStart?.({
772
+ const hookBase = {
726
773
  methodName: name,
727
774
  args,
728
775
  isPaginated: false,
729
- depth
730
- });
776
+ depth,
777
+ callId: context.callId,
778
+ callOrigin: context.callOrigin,
779
+ annotations: context.annotations
780
+ };
781
+ hooks?.onMethodStart?.({ ...hookBase });
731
782
  const fireEnd = (error) => {
732
783
  hooks?.onMethodEnd?.({
733
- methodName: name,
734
- args,
735
- isPaginated: false,
736
- depth,
784
+ ...hookBase,
737
785
  durationMs: Date.now() - startTime,
738
786
  ...error ? { error } : {}
739
787
  });
@@ -800,7 +848,15 @@ function createPageFunction(coreFn, {
800
848
  return namedFunctions[functionName];
801
849
  }
802
850
  function createPaginatedFunction(coreFn, options) {
803
- const { sdk, schema, name, defaultPageSize, adaptPage, getDeprecation } = options;
851
+ const {
852
+ sdk,
853
+ schema,
854
+ name,
855
+ defaultPageSize,
856
+ adaptPage,
857
+ annotator,
858
+ getDeprecation
859
+ } = options;
804
860
  const pageFunction = createPageFunction(coreFn, { sdk, adaptPage });
805
861
  const functionName = name || coreFn.name;
806
862
  const namedFunctions = {
@@ -815,14 +871,26 @@ function createPaginatedFunction(coreFn, options) {
815
871
  const normalizedOptions = callOptions ?? {};
816
872
  const args = [normalizedOptions];
817
873
  const depth = Math.max(context.depth, getCurrentDepth());
818
- const hooks = isInsideObserver() ? void 0 : sdk.context.hooks;
874
+ const insideObserver = isInsideObserver();
875
+ const hooks = insideObserver ? void 0 : sdk.context.hooks;
819
876
  const adaptError = resolveCoreOptions(sdk.context)?.adaptError;
820
- hooks?.onMethodStart?.({
877
+ applyAnnotations({
878
+ context,
879
+ methodName: functionName,
880
+ input: normalizedOptions,
881
+ hookAnnotator: hooks?.annotator,
882
+ methodAnnotator: annotator
883
+ });
884
+ const hookBase = {
821
885
  methodName: functionName,
822
886
  args,
823
887
  isPaginated: true,
824
- depth
825
- });
888
+ depth,
889
+ callId: context.callId,
890
+ callOrigin: context.callOrigin,
891
+ annotations: context.annotations
892
+ };
893
+ hooks?.onMethodStart?.({ ...hookBase });
826
894
  try {
827
895
  const validatedOptions = {
828
896
  ...normalizedOptions,
@@ -848,19 +916,13 @@ function createPaginatedFunction(coreFn, options) {
848
916
  firstPagePromise.then(
849
917
  () => {
850
918
  hooks.onMethodEnd({
851
- methodName: functionName,
852
- args,
853
- isPaginated: true,
854
- depth,
919
+ ...hookBase,
855
920
  durationMs: Date.now() - startTime
856
921
  });
857
922
  },
858
923
  (error) => {
859
924
  hooks.onMethodEnd({
860
- methodName: functionName,
861
- args,
862
- isPaginated: true,
863
- depth,
925
+ ...hookBase,
864
926
  durationMs: Date.now() - startTime,
865
927
  error: error instanceof Error ? error : new Error(String(error))
866
928
  });
@@ -899,10 +961,7 @@ function createPaginatedFunction(coreFn, options) {
899
961
  } catch (error) {
900
962
  const normalizedError = normalizeError(error, adaptError);
901
963
  hooks?.onMethodEnd?.({
902
- methodName: functionName,
903
- args,
904
- isPaginated: true,
905
- depth,
964
+ ...hookBase,
906
965
  durationMs: Date.now() - startTime,
907
966
  error: normalizedError
908
967
  });
@@ -1318,6 +1377,7 @@ function defineMethod(config) {
1318
1377
  meta: collectLeafMeta(config),
1319
1378
  resolvers: config.resolvers,
1320
1379
  formatter: config.formatter,
1380
+ annotator: config.annotator,
1321
1381
  output: config.output,
1322
1382
  positional: config.positional,
1323
1383
  setup: config.setup,
@@ -1477,7 +1537,8 @@ function defineHook(config) {
1477
1537
  setup: config.setup,
1478
1538
  dispose: config.dispose,
1479
1539
  wrap: config.wrap,
1480
- observe: config.observe
1540
+ observe: config.observe,
1541
+ annotator: config.annotator
1481
1542
  };
1482
1543
  }
1483
1544
  function declarePlugin(config) {
@@ -1903,7 +1964,14 @@ function collectPlugins(root, materialized = /* @__PURE__ */ new Set(), configur
1903
1964
  }
1904
1965
  return byId;
1905
1966
  }
1906
- function bindValue(target, key, entry, callType = "surface", ctx) {
1967
+ function bindValue({
1968
+ target,
1969
+ key,
1970
+ entry,
1971
+ bindMode = "surface",
1972
+ ctx,
1973
+ frameworkOrigin = false
1974
+ }) {
1907
1975
  if (entry.pluginType === "property" && entry.getValue) {
1908
1976
  Object.defineProperty(target, key, {
1909
1977
  get: entry.getValue,
@@ -1911,7 +1979,7 @@ function bindValue(target, key, entry, callType = "surface", ctx) {
1911
1979
  configurable: true
1912
1980
  });
1913
1981
  } else {
1914
- const value = callType === "internal" && entry.pluginType === "method" ? entry.bindInternal?.(ctx) ?? entry.internalValue ?? entry.value : entry.value;
1982
+ const value = bindMode === "internal" && entry.pluginType === "method" ? entry.bindInternal?.({ ctx, frameworkOrigin }) ?? entry.internalValue ?? entry.value : entry.value;
1915
1983
  Object.defineProperty(target, key, {
1916
1984
  value,
1917
1985
  writable: true,
@@ -1929,7 +1997,12 @@ function buildSurface(context, ...maps) {
1929
1997
  sdk[CONTEXT] = context;
1930
1998
  return sdk;
1931
1999
  }
1932
- function buildImports(plugins, importBindings, ctx) {
2000
+ function buildImports({
2001
+ plugins,
2002
+ importBindings,
2003
+ ctx,
2004
+ frameworkOrigin = false
2005
+ }) {
1933
2006
  const imports = {};
1934
2007
  for (const { binding, id, optional } of importBindings) {
1935
2008
  const entry = plugins[id];
@@ -1942,10 +2015,31 @@ function buildImports(plugins, importBindings, ctx) {
1942
2015
  });
1943
2016
  continue;
1944
2017
  }
1945
- bindValue(imports, binding, entry, "internal", ctx);
2018
+ bindValue({
2019
+ target: imports,
2020
+ key: binding,
2021
+ entry,
2022
+ bindMode: "internal",
2023
+ ctx,
2024
+ frameworkOrigin
2025
+ });
1946
2026
  }
1947
2027
  return imports;
1948
2028
  }
2029
+ function bindInternalTwin({
2030
+ ctx,
2031
+ frameworkOrigin,
2032
+ withContext,
2033
+ internalValue
2034
+ }) {
2035
+ if (ctx) {
2036
+ return (...args) => withContext(childCallContext(ctx))(...args);
2037
+ }
2038
+ if (frameworkOrigin) {
2039
+ return (...args) => withContext(rootCallContext({ callOrigin: "internal" }))(...args);
2040
+ }
2041
+ return internalValue;
2042
+ }
1949
2043
  function mirrorLegacyRootKeys(context, rootKeys, meta) {
1950
2044
  const exports = {};
1951
2045
  for (const [name, value] of Object.entries(rootKeys)) {
@@ -2009,7 +2103,11 @@ function bindResolver(resolver, plugins) {
2009
2103
  case "info":
2010
2104
  return { type: "info", text: resolver.text };
2011
2105
  case "object": {
2012
- const imports = buildImports(plugins, resolver.importBindings);
2106
+ const imports = buildImports({
2107
+ plugins,
2108
+ importBindings: resolver.importBindings,
2109
+ frameworkOrigin: true
2110
+ });
2013
2111
  const bound = {
2014
2112
  type: "object",
2015
2113
  requireParameters: resolver.requireParameters
@@ -2050,7 +2148,11 @@ function bindResolver(resolver, plugins) {
2050
2148
  return bound;
2051
2149
  }
2052
2150
  case "dynamic": {
2053
- const imports = buildImports(plugins, resolver.importBindings);
2151
+ const imports = buildImports({
2152
+ plugins,
2153
+ importBindings: resolver.importBindings,
2154
+ frameworkOrigin: true
2155
+ });
2054
2156
  const {
2055
2157
  getContext: getContext2,
2056
2158
  listItems,
@@ -2105,7 +2207,11 @@ function bindDefinitions(definitions, plugins) {
2105
2207
  return out;
2106
2208
  }
2107
2209
  function bindFormatter(formatter, plugins) {
2108
- const imports = buildImports(plugins, formatter.importBindings);
2210
+ const imports = buildImports({
2211
+ plugins,
2212
+ importBindings: formatter.importBindings,
2213
+ frameworkOrigin: true
2214
+ });
2109
2215
  const bound = { format: formatter.format };
2110
2216
  const { getContext: getContext2 } = formatter;
2111
2217
  if (getContext2)
@@ -2192,17 +2298,32 @@ function buildMethodEntries(descriptors, context, states) {
2192
2298
  // Replaced below; never called.
2193
2299
  value: () => void 0
2194
2300
  };
2195
- const callRun = (input, ctx) => descriptor.run({
2196
- imports: buildImports(plugins, descriptor.importBindings, ctx),
2197
- state: states.get(id),
2198
- input
2199
- });
2301
+ const callRun = (input, ctx) => {
2302
+ const callContext = ctx ?? rootCallContext();
2303
+ return descriptor.run({
2304
+ imports: buildImports({
2305
+ plugins,
2306
+ importBindings: descriptor.importBindings,
2307
+ ctx: callContext
2308
+ }),
2309
+ state: states.get(id),
2310
+ input,
2311
+ callContext,
2312
+ annotate: (metadata) => {
2313
+ Object.assign(callContext.annotations, metadata);
2314
+ }
2315
+ });
2316
+ };
2200
2317
  const fold = (coreFn) => (input, ctx) => {
2201
2318
  let next = (i) => coreFn(i, ctx);
2202
2319
  for (const wrap of entry.chain) {
2203
2320
  const inner = next;
2204
2321
  next = (i) => wrap.run({
2205
- imports: buildImports(plugins, wrap.owner.importBindings, ctx),
2322
+ imports: buildImports({
2323
+ plugins,
2324
+ importBindings: wrap.owner.importBindings,
2325
+ ctx
2326
+ }),
2206
2327
  next: inner,
2207
2328
  input: i,
2208
2329
  // Overwritten by the chain item's own closure with the owning
@@ -2213,6 +2334,8 @@ function buildMethodEntries(descriptors, context, states) {
2213
2334
  return next(input);
2214
2335
  };
2215
2336
  const sdk = { context };
2337
+ const methodAnnotator = descriptor.annotator;
2338
+ const boundAnnotator = methodAnnotator ? (input) => methodAnnotator({ input }) : void 0;
2216
2339
  if (out.type === "list") {
2217
2340
  entry.value = createPaginatedFunction(
2218
2341
  fold(callRun),
@@ -2222,6 +2345,7 @@ function buildMethodEntries(descriptors, context, states) {
2222
2345
  name: descriptor.name,
2223
2346
  defaultPageSize: out.defaultPageSize,
2224
2347
  adaptPage: out.adaptPage,
2348
+ annotator: boundAnnotator,
2225
2349
  getDeprecation: () => entry.meta?.deprecation
2226
2350
  }
2227
2351
  );
@@ -2233,6 +2357,7 @@ function buildMethodEntries(descriptors, context, states) {
2233
2357
  sdk,
2234
2358
  schema: descriptor.inputSchema,
2235
2359
  name: descriptor.name,
2360
+ annotator: boundAnnotator,
2236
2361
  getDeprecation: () => entry.meta?.deprecation
2237
2362
  }
2238
2363
  );
@@ -2244,6 +2369,7 @@ function buildMethodEntries(descriptors, context, states) {
2244
2369
  name: descriptor.name,
2245
2370
  schema: descriptor.skipInputValidation ? void 0 : descriptor.inputSchema,
2246
2371
  positional: descriptor.positional,
2372
+ annotator: boundAnnotator,
2247
2373
  // The boundary reads the deprecation LIVE off the entry, so a
2248
2374
  // deprecation merged after build (defineMethodOverride, addPlugin)
2249
2375
  // fires too.
@@ -2264,12 +2390,22 @@ function buildMethodEntries(descriptors, context, states) {
2264
2390
  const internalValue = (...args) => canonicalValue(pack(args), INTERNAL_CALL);
2265
2391
  entry.value = (...args) => canonicalValue(pack(args));
2266
2392
  entry.internalValue = internalValue;
2267
- entry.bindInternal = (ctx) => ctx ? (...args) => canonicalValue(pack(args), childCallContext(ctx)) : internalValue;
2393
+ entry.bindInternal = (opts) => bindInternalTwin({
2394
+ ...opts,
2395
+ withContext: (context2) => {
2396
+ return (...args) => canonicalValue(pack(args), context2);
2397
+ },
2398
+ internalValue
2399
+ });
2268
2400
  entry.positional = names;
2269
2401
  } else {
2270
2402
  const internalValue = (input) => canonicalValue(input, INTERNAL_CALL);
2271
2403
  entry.internalValue = internalValue;
2272
- entry.bindInternal = (ctx) => ctx ? (input) => canonicalValue(input, childCallContext(ctx)) : internalValue;
2404
+ entry.bindInternal = (opts) => bindInternalTwin({
2405
+ ...opts,
2406
+ withContext: (context2) => (input) => canonicalValue(input, context2),
2407
+ internalValue
2408
+ });
2273
2409
  }
2274
2410
  plugins[id] = entry;
2275
2411
  }
@@ -2295,8 +2431,14 @@ function buildEagerArtifacts(descriptors, context, states) {
2295
2431
  if (!dispose) return;
2296
2432
  context.disposers?.push({
2297
2433
  id,
2434
+ // Teardown is framework-internal: an SDK method a `dispose` calls runs
2435
+ // on an internal-origin root (dropped from telemetry).
2298
2436
  dispose: (input) => dispose({
2299
- imports: buildImports(plugins, descriptor.importBindings),
2437
+ imports: buildImports({
2438
+ plugins,
2439
+ importBindings: descriptor.importBindings,
2440
+ frameworkOrigin: true
2441
+ }),
2300
2442
  state: states.get(id),
2301
2443
  input
2302
2444
  })
@@ -2306,7 +2448,10 @@ function buildEagerArtifacts(descriptors, context, states) {
2306
2448
  states.set(
2307
2449
  id,
2308
2450
  descriptor.setup ? descriptor.setup({
2309
- imports: buildImports(plugins, descriptor.importBindings)
2451
+ imports: buildImports({
2452
+ plugins,
2453
+ importBindings: descriptor.importBindings
2454
+ })
2310
2455
  }) : void 0
2311
2456
  );
2312
2457
  recordDisposer();
@@ -2318,14 +2463,20 @@ function buildEagerArtifacts(descriptors, context, states) {
2318
2463
  states.set(
2319
2464
  id,
2320
2465
  descriptor.setup ? descriptor.setup({
2321
- imports: buildImports(plugins, descriptor.importBindings)
2466
+ imports: buildImports({
2467
+ plugins,
2468
+ importBindings: descriptor.importBindings
2469
+ })
2322
2470
  }) : void 0
2323
2471
  );
2324
2472
  } else {
2325
2473
  states.set(
2326
2474
  id,
2327
2475
  descriptor.setup ? descriptor.setup({
2328
- imports: buildImports(plugins, descriptor.importBindings)
2476
+ imports: buildImports({
2477
+ plugins,
2478
+ importBindings: descriptor.importBindings
2479
+ })
2329
2480
  }) : void 0
2330
2481
  );
2331
2482
  if (descriptor.privileged) {
@@ -2343,7 +2494,7 @@ function buildEagerArtifacts(descriptors, context, states) {
2343
2494
  pluginType: "property",
2344
2495
  name: descriptor.name,
2345
2496
  getValue: () => get({
2346
- imports: buildImports(plugins, importBindings),
2497
+ imports: buildImports({ plugins, importBindings }),
2347
2498
  state: states.get(id)
2348
2499
  }),
2349
2500
  meta: descriptor.meta,
@@ -2379,7 +2530,7 @@ function resolvePlugin(sdk, ref) {
2379
2530
  return entry.getValue();
2380
2531
  }
2381
2532
  if (entry.pluginType === "method" && entry.internalValue) {
2382
- return entry.internalValue;
2533
+ return entry.bindInternal?.({ frameworkOrigin: true }) ?? entry.internalValue;
2383
2534
  }
2384
2535
  return entry.value;
2385
2536
  }
@@ -2414,7 +2565,7 @@ function resolveAggregates(descriptors, context) {
2414
2565
  if (descriptor.pluginType !== "aggregate") continue;
2415
2566
  const exports = {};
2416
2567
  for (const [binding, child] of Object.entries(descriptor.exports)) {
2417
- bindValue(exports, binding, plugins[child.id]);
2568
+ bindValue({ target: exports, key: binding, entry: plugins[child.id] });
2418
2569
  }
2419
2570
  plugins[id] = { pluginType: "aggregate", name: descriptor.name, exports };
2420
2571
  }
@@ -2457,23 +2608,39 @@ function assembleHooks(descriptors, context, states) {
2457
2608
  const plugins = context.plugins;
2458
2609
  for (const id of topoOrder(descriptors)) {
2459
2610
  const descriptor = descriptors.get(id);
2460
- if (!descriptor || descriptor.pluginType !== "hook" || !descriptor.observe) {
2611
+ if (!descriptor || descriptor.pluginType !== "hook" || !descriptor.observe && !descriptor.annotator) {
2461
2612
  continue;
2462
2613
  }
2463
- const { observe } = descriptor;
2464
- const imports = buildImports(plugins, descriptor.importBindings);
2614
+ const { observe, annotator } = descriptor;
2465
2615
  const state = states.get(id);
2466
2616
  const contributed = {};
2467
- if (observe.onMethodStart) {
2468
- const onStart = observe.onMethodStart;
2469
- contributed.onMethodStart = (input) => {
2470
- runIsolatedObserver(() => onStart({ imports, input, state }));
2471
- };
2617
+ if (observe?.onMethodStart || observe?.onMethodEnd) {
2618
+ const imports = buildImports({
2619
+ plugins,
2620
+ importBindings: descriptor.importBindings,
2621
+ frameworkOrigin: true
2622
+ });
2623
+ if (observe.onMethodStart) {
2624
+ const onStart = observe.onMethodStart;
2625
+ contributed.onMethodStart = (input) => {
2626
+ runIsolatedObserver(() => onStart({ imports, input, state }));
2627
+ };
2628
+ }
2629
+ if (observe.onMethodEnd) {
2630
+ const onEnd = observe.onMethodEnd;
2631
+ contributed.onMethodEnd = (input) => {
2632
+ runIsolatedObserver(() => onEnd({ imports, input, state }));
2633
+ };
2634
+ }
2472
2635
  }
2473
- if (observe.onMethodEnd) {
2474
- const onEnd = observe.onMethodEnd;
2475
- contributed.onMethodEnd = (input) => {
2476
- runIsolatedObserver(() => onEnd({ imports, input, state }));
2636
+ if (annotator) {
2637
+ const annotatorFn = annotator;
2638
+ contributed.annotator = ({ methodName, input }) => {
2639
+ try {
2640
+ return annotatorFn({ methodName, input, state });
2641
+ } catch {
2642
+ return {};
2643
+ }
2477
2644
  };
2478
2645
  }
2479
2646
  context.hooks = buildHooks(context.hooks, contributed);
@@ -2507,7 +2674,11 @@ function createSdk(root, options) {
2507
2674
  pluginSurface = plugins2[plugin.id].exports;
2508
2675
  } else {
2509
2676
  pluginSurface = {};
2510
- bindValue(pluginSurface, plugin.name, plugins2[plugin.id]);
2677
+ bindValue({
2678
+ target: pluginSurface,
2679
+ key: plugin.name,
2680
+ entry: plugins2[plugin.id]
2681
+ });
2511
2682
  }
2512
2683
  for (const key of Object.keys(legacyExports)) context.surface[key] = key;
2513
2684
  if (plugin.pluginType === "aggregate") {
@@ -2524,7 +2695,7 @@ function createSdk(root, options) {
2524
2695
  if (root.pluginType === "method" || root.pluginType === "property") {
2525
2696
  context.surface[root.name] = root.id;
2526
2697
  const sdk = buildSurface(context);
2527
- bindValue(sdk, root.name, plugins[root.id]);
2698
+ bindValue({ target: sdk, key: root.name, entry: plugins[root.id] });
2528
2699
  return sdk;
2529
2700
  }
2530
2701
  if (root.pluginType === "aggregate")
@@ -2556,7 +2727,7 @@ function addModelPlugin(sdk, plugin, options = {}) {
2556
2727
  context.surface[binding] = child.id;
2557
2728
  }
2558
2729
  } else {
2559
- bindValue(sdk, plugin.name, entry);
2730
+ bindValue({ target: sdk, key: plugin.name, entry });
2560
2731
  context.surface[plugin.name] = plugin.id;
2561
2732
  }
2562
2733
  }
@@ -3855,7 +4026,7 @@ function getZapierSdkService() {
3855
4026
  }
3856
4027
  var MAX_PAGE_LIMIT = 1e4;
3857
4028
  var DEFAULT_PAGE_SIZE = 100;
3858
- var DEFAULT_ACTION_TIMEOUT_MS = 18e4;
4029
+ var DEFAULT_ACTION_TIMEOUT_MILLISECONDS = 18e4;
3859
4030
  function parseIntEnvVar(name) {
3860
4031
  const value = globalThis.process?.env?.[name];
3861
4032
  if (value === void 0) return void 0;
@@ -3869,7 +4040,10 @@ function parseIntEnvVar(name) {
3869
4040
  return parsed;
3870
4041
  }
3871
4042
  var ZAPIER_MAX_NETWORK_RETRIES = parseIntEnvVar("ZAPIER_MAX_NETWORK_RETRIES") ?? 3;
3872
- var ZAPIER_MAX_NETWORK_RETRY_DELAY_MS = parseIntEnvVar("ZAPIER_MAX_NETWORK_RETRY_DELAY_MS") ?? 6e4;
4043
+ var maxNetworkRetryDelaySecondsEnv = parseIntEnvVar(
4044
+ "ZAPIER_MAX_NETWORK_RETRY_DELAY_SECONDS"
4045
+ );
4046
+ var ZAPIER_MAX_NETWORK_RETRY_DELAY_MILLISECONDS = (maxNetworkRetryDelaySecondsEnv != null ? maxNetworkRetryDelaySecondsEnv * 1e3 : void 0) ?? parseIntEnvVar("ZAPIER_MAX_NETWORK_RETRY_DELAY_MS") ?? 6e4;
3873
4047
  var MAX_CONCURRENCY_LIMIT = 1e4;
3874
4048
  function parseConcurrencyEnvVar(name) {
3875
4049
  const value = globalThis.process?.env?.[name];
@@ -3900,7 +4074,7 @@ function getZapierDefaultApprovalMode() {
3900
4074
  const isInteractive = !!globalThis.process?.stdin?.isTTY && !!globalThis.process?.stdout?.isTTY;
3901
4075
  return isInteractive ? "poll" : "throw";
3902
4076
  }
3903
- var DEFAULT_APPROVAL_TIMEOUT_MS = 10 * 60 * 1e3;
4077
+ var DEFAULT_APPROVAL_TIMEOUT_MILLISECONDS = 10 * 60 * 1e3;
3904
4078
  var DEFAULT_MAX_APPROVAL_RETRIES = 2;
3905
4079
 
3906
4080
  // src/types/properties.ts
@@ -3942,8 +4116,11 @@ var OffsetPropertySchema = zod.z.number().int().min(0).default(0).describe("Numb
3942
4116
  var OutputPropertySchema = zod.z.string().describe("Output file path");
3943
4117
  var DebugPropertySchema = zod.z.boolean().default(false).describe("Enable debug logging");
3944
4118
  var ParamsPropertySchema = zod.z.record(zod.z.string(), zod.z.unknown()).describe("Additional parameters");
3945
- var ActionTimeoutMsPropertySchema = zod.z.number().min(1e3).optional().describe(
3946
- `Maximum time to wait for action completion in milliseconds (default: ${DEFAULT_ACTION_TIMEOUT_MS})`
4119
+ var ActionTimeoutSecondsPropertySchema = zod.z.number().min(1).optional().describe(
4120
+ `Maximum time to wait for action completion in seconds (default: ${DEFAULT_ACTION_TIMEOUT_MILLISECONDS / 1e3})`
4121
+ );
4122
+ var ActionTimeoutMillisecondsPropertySchema = zod.z.number().min(1e3).optional().describe(
4123
+ `Maximum time to wait for action completion in milliseconds (default: ${DEFAULT_ACTION_TIMEOUT_MILLISECONDS})`
3947
4124
  );
3948
4125
  var TablePropertySchema = withPositional(
3949
4126
  zod.z.string().regex(/^[A-Z0-9]{26}$/, "Table ID must be a valid ULID").describe("The unique identifier of the table")
@@ -4351,11 +4528,18 @@ var ActionExecutionInputSchema = zod.z.object({
4351
4528
  authenticationId: AuthenticationIdPropertySchema.optional().meta({
4352
4529
  deprecated: true
4353
4530
  }),
4354
- timeoutMs: ActionTimeoutMsPropertySchema
4531
+ timeoutSeconds: ActionTimeoutSecondsPropertySchema,
4532
+ /** @deprecated Use `timeoutSeconds` instead. */
4533
+ timeoutMs: ActionTimeoutMillisecondsPropertySchema.meta({
4534
+ deprecated: true
4535
+ })
4355
4536
  }).describe(
4356
4537
  "Execute an action with the given inputs for the bound app, as an alternative to runAction"
4357
4538
  ).meta({
4358
- aliases: { connectionId: "connection", authenticationId: "connection" }
4539
+ aliases: {
4540
+ connectionId: "connection",
4541
+ authenticationId: "connection"
4542
+ }
4359
4543
  });
4360
4544
  var AppFactoryInputSchema = zod.z.object({
4361
4545
  /** @deprecated Use `connection` instead. */
@@ -4533,19 +4717,19 @@ function createDebugFetch(options) {
4533
4717
 
4534
4718
  // src/utils/retry-utils.ts
4535
4719
  var MAX_CONSECUTIVE_ERRORS = 3;
4536
- var BASE_ERROR_BACKOFF_MS = 1e3;
4537
- var BASE_EXPONENTIAL_BACKOFF_MS = 1e3;
4720
+ var BASE_ERROR_BACKOFF_MILLISECONDS = 1e3;
4721
+ var BASE_EXPONENTIAL_BACKOFF_MILLISECONDS = 1e3;
4538
4722
  var JITTER_FACTOR = 0.5;
4539
4723
  function calculateErrorBackoffMs(baseInterval, errorCount) {
4540
4724
  const jitter = Math.random() * JITTER_FACTOR * baseInterval;
4541
4725
  const errorBackoff = Math.min(
4542
- BASE_ERROR_BACKOFF_MS * (errorCount / 2),
4726
+ BASE_ERROR_BACKOFF_MILLISECONDS * (errorCount / 2),
4543
4727
  baseInterval * 2
4544
4728
  // Cap error backoff at 2x the base interval
4545
4729
  );
4546
4730
  return Math.floor(baseInterval + jitter + errorBackoff);
4547
4731
  }
4548
- function calculateExponentialBackoffMs(attempt, baseDelayMs = BASE_EXPONENTIAL_BACKOFF_MS) {
4732
+ function calculateExponentialBackoffMs(attempt, baseDelayMs = BASE_EXPONENTIAL_BACKOFF_MILLISECONDS) {
4549
4733
  const baseDelay = baseDelayMs * Math.pow(2, attempt - 1);
4550
4734
  const jitter = Math.random() * JITTER_FACTOR * baseDelay;
4551
4735
  return Math.floor(baseDelay + jitter);
@@ -4648,11 +4832,11 @@ function combineAbortSignals({
4648
4832
  }
4649
4833
 
4650
4834
  // src/api/polling.ts
4651
- var DEFAULT_TIMEOUT_MS = 18e4;
4835
+ var DEFAULT_TIMEOUT_MILLISECONDS = 18e4;
4652
4836
  var DEFAULT_SUCCESS_STATUS = 200;
4653
4837
  var DEFAULT_PENDING_STATUS = 202;
4654
- var DEFAULT_INITIAL_DELAY_MS = 50;
4655
- var DEFAULT_MAX_POLLING_INTERVAL_MS = 6e4;
4838
+ var DEFAULT_INITIAL_DELAY_MILLISECONDS = 50;
4839
+ var DEFAULT_MAX_POLLING_INTERVAL_MILLISECONDS = 6e4;
4656
4840
  var POLLING_STAGES = [
4657
4841
  [125, 125],
4658
4842
  // Up to 125ms: poll every 125ms
@@ -4668,11 +4852,11 @@ var POLLING_STAGES = [
4668
4852
  // Up to 60s: poll every 5s
4669
4853
  [18e4, 1e4]
4670
4854
  // Up to 3min: poll every 10s
4671
- // Beyond 3min: use DEFAULT_MAX_POLLING_INTERVAL_MS (60s)
4855
+ // Beyond 3min: use DEFAULT_MAX_POLLING_INTERVAL_MILLISECONDS (60s)
4672
4856
  ];
4673
4857
  function getPollingInterval(elapsedMs) {
4674
4858
  const stage = POLLING_STAGES.find(([threshold]) => elapsedMs < threshold);
4675
- return stage ? stage[1] : DEFAULT_MAX_POLLING_INTERVAL_MS;
4859
+ return stage ? stage[1] : DEFAULT_MAX_POLLING_INTERVAL_MILLISECONDS;
4676
4860
  }
4677
4861
  function makeAbortError() {
4678
4862
  if (typeof DOMException !== "undefined") {
@@ -4730,8 +4914,8 @@ var processResponse = async (response, successStatus, pendingStatus, isPending,
4730
4914
  async function pollUntilComplete(options) {
4731
4915
  const {
4732
4916
  fetchPoll,
4733
- timeoutMs = DEFAULT_TIMEOUT_MS,
4734
- initialDelay = DEFAULT_INITIAL_DELAY_MS,
4917
+ timeoutMs = DEFAULT_TIMEOUT_MILLISECONDS,
4918
+ initialDelay = DEFAULT_INITIAL_DELAY_MILLISECONDS,
4735
4919
  successStatus = DEFAULT_SUCCESS_STATUS,
4736
4920
  pendingStatus = DEFAULT_PENDING_STATUS,
4737
4921
  isPending,
@@ -5178,7 +5362,7 @@ function clearTokenCache() {
5178
5362
  cachedCliLogin = void 0;
5179
5363
  cachedDefaultCache = void 0;
5180
5364
  }
5181
- var TOKEN_EXPIRATION_BUFFER_MS = 5 * 60 * 1e3;
5365
+ var TOKEN_EXPIRATION_BUFFER_MILLISECONDS = 5 * 60 * 1e3;
5182
5366
  async function resolveCache(options) {
5183
5367
  if (options.cache) return options.cache;
5184
5368
  if (cachedDefaultCache !== void 0) return cachedDefaultCache;
@@ -5199,7 +5383,7 @@ async function resolveCache(options) {
5199
5383
  }
5200
5384
  function entryIsValid(entry) {
5201
5385
  if (entry.expiresAt === void 0) return true;
5202
- return entry.expiresAt > Date.now() + TOKEN_EXPIRATION_BUFFER_MS;
5386
+ return entry.expiresAt > Date.now() + TOKEN_EXPIRATION_BUFFER_MILLISECONDS;
5203
5387
  }
5204
5388
  async function readCachedToken(cacheKey, cache) {
5205
5389
  const cached = await cache.get(cacheKey);
@@ -5815,7 +5999,7 @@ function parseDeprecationDate(value) {
5815
5999
  }
5816
6000
 
5817
6001
  // src/sdk-version.ts
5818
- var SDK_VERSION = (typeof process !== "undefined" && process.env ? "0.87.1" : void 0) || "unknown";
6002
+ var SDK_VERSION = (typeof process !== "undefined" && process.env ? "0.88.1" : void 0) || "unknown";
5819
6003
 
5820
6004
  // src/utils/open-url.ts
5821
6005
  var nodePrefix = "node:";
@@ -5926,7 +6110,7 @@ var PollApprovalResponseSchema = zod.z.object({
5926
6110
  mode: ApprovalModeSchema.optional(),
5927
6111
  reason: zod.z.string().optional()
5928
6112
  });
5929
- var APPROVAL_MAX_POLLING_INTERVAL_MS = 5e3;
6113
+ var APPROVAL_MAX_POLLING_INTERVAL_MILLISECONDS = 5e3;
5930
6114
  function validateSdkPath(path) {
5931
6115
  if (!path.startsWith("/") || path.startsWith("//")) {
5932
6116
  throw new ZapierValidationError(
@@ -6091,7 +6275,7 @@ var ZapierApiClient = class {
6091
6275
  }
6092
6276
  const rateLimitInfo = parseRateLimitHeaders(response);
6093
6277
  const delayMs = rateLimitInfo.retryAfterMs ?? calculateExponentialBackoffMs(retries + 1);
6094
- if (delayMs > this.maxNetworkRetryDelayMs || retries >= this.maxNetworkRetries) {
6278
+ if (delayMs > this.maxNetworkRetryDelayMilliseconds || retries >= this.maxNetworkRetries) {
6095
6279
  throw new ZapierRateLimitError("Rate limited", {
6096
6280
  statusCode: 429,
6097
6281
  rateLimit: rateLimitInfo,
@@ -6348,8 +6532,8 @@ var ZapierApiClient = class {
6348
6532
  authRequired: options.authRequired,
6349
6533
  signal: options.signal
6350
6534
  }),
6351
- initialDelay: options.initialDelay,
6352
- timeoutMs: options.timeoutMs,
6535
+ initialDelay: options.initialDelayMilliseconds ?? options.initialDelay,
6536
+ timeoutMs: options.timeoutMilliseconds ?? options.timeoutMs,
6353
6537
  successStatus: options.successStatus,
6354
6538
  pendingStatus: options.pendingStatus,
6355
6539
  isPending: options.isPending,
@@ -6358,7 +6542,7 @@ var ZapierApiClient = class {
6358
6542
  });
6359
6543
  };
6360
6544
  this.maxNetworkRetries = options.maxNetworkRetries ?? ZAPIER_MAX_NETWORK_RETRIES;
6361
- this.maxNetworkRetryDelayMs = options.maxNetworkRetryDelayMs ?? ZAPIER_MAX_NETWORK_RETRY_DELAY_MS;
6545
+ this.maxNetworkRetryDelayMilliseconds = options.maxNetworkRetryDelayMilliseconds ?? options.maxNetworkRetryDelayMs ?? ZAPIER_MAX_NETWORK_RETRY_DELAY_MILLISECONDS;
6362
6546
  const requested = options.maxConcurrentRequests;
6363
6547
  const limit = requested === void 0 || Number.isNaN(requested) ? ZAPIER_MAX_CONCURRENT_REQUESTS : requested;
6364
6548
  if (limit !== Infinity && (!Number.isInteger(limit) || limit < 1 || limit > MAX_CONCURRENCY_LIMIT)) {
@@ -6933,7 +7117,7 @@ var ZapierApiClient = class {
6933
7117
  }
6934
7118
  await openApproval(approval.approval_url);
6935
7119
  }
6936
- const timeoutMs = this.options.approvalTimeoutMs ?? DEFAULT_APPROVAL_TIMEOUT_MS;
7120
+ const timeoutMs = this.options.approvalTimeoutMilliseconds ?? this.options.approvalTimeoutMs ?? DEFAULT_APPROVAL_TIMEOUT_MILLISECONDS;
6937
7121
  let streamAbortController;
6938
7122
  let streamPromise;
6939
7123
  let removeStreamAbortListener;
@@ -6973,7 +7157,7 @@ var ZapierApiClient = class {
6973
7157
  })
6974
7158
  ),
6975
7159
  timeoutMs,
6976
- maxPollingIntervalMs: APPROVAL_MAX_POLLING_INTERVAL_MS,
7160
+ maxPollingIntervalMs: APPROVAL_MAX_POLLING_INTERVAL_MILLISECONDS,
6977
7161
  signal,
6978
7162
  isPending: (body2) => {
6979
7163
  const parsed = PollApprovalResponseSchema.safeParse(body2);
@@ -7153,8 +7337,10 @@ var apiPlugin = defineProperty({
7153
7337
  onEvent,
7154
7338
  debug = false,
7155
7339
  maxNetworkRetries = ZAPIER_MAX_NETWORK_RETRIES,
7156
- maxNetworkRetryDelayMs = ZAPIER_MAX_NETWORK_RETRY_DELAY_MS,
7340
+ maxNetworkRetryDelaySeconds,
7341
+ maxNetworkRetryDelayMs,
7157
7342
  maxConcurrentRequests = ZAPIER_MAX_CONCURRENT_REQUESTS,
7343
+ approvalTimeoutSeconds,
7158
7344
  approvalTimeoutMs,
7159
7345
  maxApprovalRetries,
7160
7346
  approvalMode,
@@ -7169,9 +7355,9 @@ var apiPlugin = defineProperty({
7169
7355
  fetch: customFetch,
7170
7356
  onEvent,
7171
7357
  maxNetworkRetries,
7172
- maxNetworkRetryDelayMs,
7358
+ maxNetworkRetryDelayMilliseconds: (maxNetworkRetryDelaySeconds != null ? maxNetworkRetryDelaySeconds * 1e3 : maxNetworkRetryDelayMs) ?? ZAPIER_MAX_NETWORK_RETRY_DELAY_MILLISECONDS,
7173
7359
  maxConcurrentRequests,
7174
- approvalTimeoutMs,
7360
+ approvalTimeoutMilliseconds: approvalTimeoutSeconds != null ? approvalTimeoutSeconds * 1e3 : approvalTimeoutMs,
7175
7361
  maxApprovalRetries,
7176
7362
  approvalMode,
7177
7363
  openAutoModeApprovalsInBrowser,
@@ -7879,9 +8065,13 @@ var FetchInitZapierFieldsSchema = zod.z.object({
7879
8065
  deprecated: true
7880
8066
  }),
7881
8067
  callbackUrl: zod.z.string().optional().describe("URL to send async response to (makes request async)"),
8068
+ maxTimeSeconds: zod.z.number().int().positive().optional().describe(
8069
+ "Maximum seconds to wait for a response. Honored on a best-effort basis; the server may silently enforce a lower ceiling."
8070
+ ),
8071
+ /** @deprecated Use `maxTimeSeconds` instead. */
7882
8072
  maxTime: zod.z.number().int().positive().optional().describe(
7883
8073
  "Maximum seconds to wait for a response. Honored on a best-effort basis; the server may silently enforce a lower ceiling."
7884
- )
8074
+ ).meta({ deprecated: true })
7885
8075
  });
7886
8076
  var FetchInitSchema = zod.z.object({
7887
8077
  method: zod.z.enum(["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"]).optional().describe("HTTP method for the request (defaults to GET)"),
@@ -7897,7 +8087,11 @@ var FetchInitSchema = zod.z.object({
7897
8087
  }).extend(FetchInitZapierFieldsSchema.shape).optional().describe(
7898
8088
  "Request options including method, headers, body, and authentication"
7899
8089
  ).meta({
7900
- aliases: { connectionId: "connection", authenticationId: "connection" }
8090
+ aliases: {
8091
+ connectionId: "connection",
8092
+ authenticationId: "connection",
8093
+ maxTime: "maxTimeSeconds"
8094
+ }
7901
8095
  });
7902
8096
  var FetchInputSchema = zod.z.object({
7903
8097
  url: FetchUrlSchema,
@@ -7948,7 +8142,7 @@ function rewrapIfMaxTimeTimeout({
7948
8142
  const reason = abortSignal.reason;
7949
8143
  if (!reason || reason.name !== "TimeoutError") return error;
7950
8144
  return new ZapierTimeoutError(
7951
- `fetch timed out after ${maxTimeSeconds}s (maxTime)`,
8145
+ `fetch timed out after ${maxTimeSeconds}s (maxTimeSeconds)`,
7952
8146
  { cause: error }
7953
8147
  );
7954
8148
  }
@@ -8013,9 +8207,11 @@ var fetchPlugin = defineMethod({
8013
8207
  connection,
8014
8208
  authenticationId,
8015
8209
  callbackUrl,
8210
+ maxTimeSeconds: maxTimeSecondsInput,
8016
8211
  maxTime,
8017
8212
  ...fetchInit
8018
8213
  } = init || {};
8214
+ const maxTimeSeconds = maxTimeSecondsInput ?? maxTime;
8019
8215
  const resolvedConnectionId = await resolveConnectionId({
8020
8216
  connectionId,
8021
8217
  connection,
@@ -8044,13 +8240,13 @@ var fetchPlugin = defineMethod({
8044
8240
  if (callbackUrl) {
8045
8241
  headers["X-Relay-Callback-Url"] = callbackUrl;
8046
8242
  }
8047
- if (maxTime !== void 0) {
8048
- headers["X-Zapier-Sdk-Max-Time"] = String(maxTime);
8243
+ if (maxTimeSeconds !== void 0) {
8244
+ headers["X-Zapier-Sdk-Max-Time"] = String(maxTimeSeconds);
8049
8245
  }
8050
8246
  const upstreamUrl = new URL(url).toString();
8051
8247
  const method = (fetchInit.method ?? "GET").toUpperCase();
8052
8248
  const abortHandle = buildAbortHandle({
8053
- maxTimeSeconds: maxTime,
8249
+ maxTimeSeconds,
8054
8250
  callerSignal: fetchInit.signal
8055
8251
  });
8056
8252
  try {
@@ -8080,7 +8276,7 @@ var fetchPlugin = defineMethod({
8080
8276
  throw rewrapIfMaxTimeTimeout({
8081
8277
  error,
8082
8278
  abortSignal: abortHandle?.signal,
8083
- maxTimeSeconds: maxTime
8279
+ maxTimeSeconds
8084
8280
  });
8085
8281
  } finally {
8086
8282
  abortHandle?.dispose();
@@ -8100,7 +8296,9 @@ var RunActionBaseSchema = zod.z.object({
8100
8296
  inputs: InputsPropertySchema.optional().describe(
8101
8297
  "Input parameters for the action"
8102
8298
  ),
8103
- timeoutMs: ActionTimeoutMsPropertySchema,
8299
+ timeoutSeconds: ActionTimeoutSecondsPropertySchema,
8300
+ /** @deprecated Use `timeoutSeconds` instead. */
8301
+ timeoutMs: ActionTimeoutMillisecondsPropertySchema.meta({ deprecated: true }),
8104
8302
  pageSize: zod.z.number().min(1).optional().describe("Number of results per page"),
8105
8303
  maxItems: zod.z.number().min(1).optional().describe("Maximum total items to return across all pages"),
8106
8304
  cursor: zod.z.string().optional().describe("Cursor to start from")
@@ -9731,18 +9929,6 @@ var tableSortResolver = defineResolver({
9731
9929
  }
9732
9930
  });
9733
9931
 
9734
- // src/plugins/eventEmission/method-metadata.ts
9735
- var SCOPE_KEY = "methodMetadata";
9736
- function setMethodMetadata(metadata) {
9737
- const scope2 = getCurrentScope();
9738
- if (!scope2) return;
9739
- const existing = scope2[SCOPE_KEY];
9740
- scope2[SCOPE_KEY] = { ...existing, ...metadata };
9741
- }
9742
- function getMethodMetadata() {
9743
- return getCurrentScope()?.[SCOPE_KEY];
9744
- }
9745
-
9746
9932
  // src/plugins/listActions/index.ts
9747
9933
  var listActionsPlugin = defineMethod({
9748
9934
  name: "listActions",
@@ -9760,7 +9946,7 @@ var listActionsPlugin = defineMethod({
9760
9946
  // of listing every action. `getAction` (where `actionType` is required) keeps
9761
9947
  // the resolver.
9762
9948
  resolvers: { app: appKeyResolver },
9763
- run: async ({ imports, input }) => {
9949
+ run: async ({ imports, input, annotate }) => {
9764
9950
  const api = imports.api;
9765
9951
  const getVersionedImplementationId = imports.manifest.getVersionedImplementationId;
9766
9952
  const appKey = "app" in input ? input.app : input.appKey;
@@ -9771,10 +9957,7 @@ var listActionsPlugin = defineMethod({
9771
9957
  { configType: "current_implementation_id" }
9772
9958
  );
9773
9959
  }
9774
- setMethodMetadata({
9775
- selectedApi,
9776
- operationType: input.actionType ?? null
9777
- });
9960
+ annotate({ selectedApi });
9778
9961
  const data = await api.get(
9779
9962
  "/zapier/api/v4/implementations/",
9780
9963
  {
@@ -9829,10 +10012,6 @@ var getActionPlugin = defineMethod({
9829
10012
  const appKey = "app" in input ? input.app : input.appKey;
9830
10013
  const actionKey = "action" in input ? input.action : input.actionKey;
9831
10014
  const { actionType } = input;
9832
- setMethodMetadata({
9833
- operationType: actionType,
9834
- operationKey: actionKey
9835
- });
9836
10015
  for await (const action of imports.listActions({ app: appKey }).items()) {
9837
10016
  if ((action.key === actionKey || action.id === actionKey) && action.action_type === actionType) {
9838
10017
  return { data: action };
@@ -9854,7 +10033,7 @@ async function executeAction(actionOptions) {
9854
10033
  executionOptions,
9855
10034
  cursor,
9856
10035
  connectionId,
9857
- timeoutMs
10036
+ timeoutMilliseconds
9858
10037
  } = actionOptions;
9859
10038
  const runRequestData = {
9860
10039
  selected_api: selectedApi,
@@ -9890,7 +10069,7 @@ async function executeAction(actionOptions) {
9890
10069
  return await api.poll(`/zapier/api/actions/v1/runs/${runId}`, {
9891
10070
  successStatus: 200,
9892
10071
  pendingStatus: 202,
9893
- timeoutMs: timeoutMs ?? DEFAULT_ACTION_TIMEOUT_MS,
10072
+ timeoutMilliseconds: timeoutMilliseconds ?? DEFAULT_ACTION_TIMEOUT_MILLISECONDS,
9894
10073
  resource: { type: "run", id: runId },
9895
10074
  isPending: (result) => {
9896
10075
  const data = result?.data;
@@ -9899,7 +10078,7 @@ async function executeAction(actionOptions) {
9899
10078
  resultExtractor: (result) => result.data
9900
10079
  });
9901
10080
  }
9902
- var CONTEXT_CACHE_TTL_MS = 6e4;
10081
+ var CONTEXT_CACHE_TTL_MILLISECONDS = 6e4;
9903
10082
  var CONTEXT_CACHE_MAX_SIZE = 500;
9904
10083
  var runActionPlugin = defineMethod({
9905
10084
  name: "runAction",
@@ -9925,9 +10104,10 @@ var runActionPlugin = defineMethod({
9925
10104
  inputs: inputsResolver
9926
10105
  },
9927
10106
  // A per-SDK-instance TTL cache of resolved (selectedApi, actionId), built once
9928
- // in setup so it persists across calls. Reads getVersionedImplementationId
9929
- // (`imports.manifest`) and getAction (an import).
9930
- setup: ({ imports }) => {
10107
+ // in setup so it persists across calls. The imports it resolves through
10108
+ // (`manifest.getVersionedImplementationId`, `getAction`) are threaded in per
10109
+ // call from `run`, not captured here.
10110
+ setup: () => {
9931
10111
  const cache = /* @__PURE__ */ new Map();
9932
10112
  function evictIfNeeded() {
9933
10113
  if (cache.size < CONTEXT_CACHE_MAX_SIZE) return;
@@ -9947,7 +10127,7 @@ var runActionPlugin = defineMethod({
9947
10127
  if (!evictedAny && oldestKey) cache.delete(oldestKey);
9948
10128
  }
9949
10129
  async function resolveRunActionContext(options) {
9950
- const { appKey, actionKey, actionType } = options;
10130
+ const { imports, appKey, actionKey, actionType } = options;
9951
10131
  const getVersionedImplementationId = imports.manifest.getVersionedImplementationId;
9952
10132
  const selectedApi = await getVersionedImplementationId(appKey);
9953
10133
  if (!selectedApi) {
@@ -9980,13 +10160,13 @@ var runActionPlugin = defineMethod({
9980
10160
  evictIfNeeded();
9981
10161
  cache.set(contextKey, {
9982
10162
  promise: pending,
9983
- expiresAt: Date.now() + CONTEXT_CACHE_TTL_MS
10163
+ expiresAt: Date.now() + CONTEXT_CACHE_TTL_MILLISECONDS
9984
10164
  });
9985
10165
  return pending;
9986
10166
  }
9987
10167
  return { getRunActionContext };
9988
10168
  },
9989
- run: async ({ imports, input, state }) => {
10169
+ run: async ({ imports, input, state, annotate }) => {
9990
10170
  const api = imports.api;
9991
10171
  const resolveConnection = imports.connections.resolveConnection;
9992
10172
  const appKey = "app" in input ? input.app : input.appKey;
@@ -9997,9 +10177,9 @@ var runActionPlugin = defineMethod({
9997
10177
  connection,
9998
10178
  authenticationId,
9999
10179
  inputs = {},
10000
- cursor,
10001
- timeoutMs
10180
+ cursor
10002
10181
  } = input;
10182
+ const timeoutMilliseconds = input.timeoutSeconds != null ? input.timeoutSeconds * 1e3 : input.timeoutMs;
10003
10183
  const resolvedConnectionId = await resolveConnectionId({
10004
10184
  connectionId,
10005
10185
  connection,
@@ -10007,15 +10187,12 @@ var runActionPlugin = defineMethod({
10007
10187
  resolveConnection
10008
10188
  });
10009
10189
  const { selectedApi, actionId } = await state.getRunActionContext({
10190
+ imports,
10010
10191
  appKey,
10011
10192
  actionKey,
10012
10193
  actionType
10013
10194
  });
10014
- setMethodMetadata({
10015
- selectedApi,
10016
- operationType: actionType,
10017
- operationKey: actionKey
10018
- });
10195
+ annotate({ selectedApi });
10019
10196
  const result = await executeAction({
10020
10197
  api,
10021
10198
  selectedApi,
@@ -10027,7 +10204,7 @@ var runActionPlugin = defineMethod({
10027
10204
  executionOptions: { inputs },
10028
10205
  cursor,
10029
10206
  connectionId: resolvedConnectionId,
10030
- timeoutMs
10207
+ timeoutMilliseconds
10031
10208
  });
10032
10209
  if (result.errors && result.errors.length > 0) {
10033
10210
  const errorMessage2 = result.errors.map(
@@ -10084,6 +10261,7 @@ function createActionFunction(appKey, actionType, actionKey, imports, pinnedAuth
10084
10261
  connectionId: providedConnectionId,
10085
10262
  connection: providedConnection,
10086
10263
  authenticationId: providedAuthenticationId,
10264
+ timeoutSeconds,
10087
10265
  timeoutMs
10088
10266
  } = actionOptions;
10089
10267
  const { connectionId, connection } = resolveProxyConnection({
@@ -10100,6 +10278,7 @@ function createActionFunction(appKey, actionType, actionKey, imports, pinnedAuth
10100
10278
  action: actionKey,
10101
10279
  inputs,
10102
10280
  connection: connectionId ?? connection,
10281
+ timeoutSeconds,
10103
10282
  timeoutMs
10104
10283
  });
10105
10284
  };
@@ -10649,7 +10828,11 @@ var listActionInputFieldsPlugin = defineMethod({
10649
10828
  // metadata; the engine permits a resolver importing its host.
10650
10829
  inputs: inputsAllOptionalResolver
10651
10830
  },
10652
- run: async ({ imports, input }) => {
10831
+ run: async ({
10832
+ imports,
10833
+ input,
10834
+ annotate
10835
+ }) => {
10653
10836
  const api = imports.api;
10654
10837
  const getVersionedImplementationId = imports.manifest.getVersionedImplementationId;
10655
10838
  const resolveConnection = imports.connections.resolveConnection;
@@ -10669,11 +10852,7 @@ var listActionInputFieldsPlugin = defineMethod({
10669
10852
  { configType: "current_implementation_id" }
10670
10853
  );
10671
10854
  }
10672
- setMethodMetadata({
10673
- selectedApi,
10674
- operationType: actionType,
10675
- operationKey: actionKey
10676
- });
10855
+ annotate({ selectedApi });
10677
10856
  const { data: action } = await imports.getAction({
10678
10857
  app: appKey,
10679
10858
  actionType,
@@ -10784,7 +10963,11 @@ var listActionInputFieldChoicesPlugin = defineMethod({
10784
10963
  inputField: inputFieldKeyResolver,
10785
10964
  inputs: inputsAllOptionalResolver
10786
10965
  },
10787
- run: async ({ imports, input }) => {
10966
+ run: async ({
10967
+ imports,
10968
+ input,
10969
+ annotate
10970
+ }) => {
10788
10971
  const api = imports.api;
10789
10972
  const getVersionedImplementationId = imports.manifest.getVersionedImplementationId;
10790
10973
  const resolveConnection = imports.connections.resolveConnection;
@@ -10813,11 +10996,7 @@ var listActionInputFieldChoicesPlugin = defineMethod({
10813
10996
  { configType: "current_implementation_id" }
10814
10997
  );
10815
10998
  }
10816
- setMethodMetadata({
10817
- selectedApi,
10818
- operationType: actionType,
10819
- operationKey: actionKey
10820
- });
10999
+ annotate({ selectedApi });
10821
11000
  const { data: action } = await imports.getAction({
10822
11001
  app: appKey,
10823
11002
  actionType,
@@ -10946,7 +11125,8 @@ var getActionInputFieldsSchemaPlugin = defineMethod({
10946
11125
  },
10947
11126
  run: async ({
10948
11127
  imports,
10949
- input
11128
+ input,
11129
+ annotate
10950
11130
  }) => {
10951
11131
  const api = imports.api;
10952
11132
  const getVersionedImplementationId = imports.manifest.getVersionedImplementationId;
@@ -10967,11 +11147,7 @@ var getActionInputFieldsSchemaPlugin = defineMethod({
10967
11147
  { configType: "current_implementation_id" }
10968
11148
  );
10969
11149
  }
10970
- setMethodMetadata({
10971
- selectedApi,
10972
- operationType: actionType,
10973
- operationKey: actionKey
10974
- });
11150
+ annotate({ selectedApi });
10975
11151
  const { data: action } = await imports.getAction({
10976
11152
  app: appKey,
10977
11153
  actionType,
@@ -11094,7 +11270,11 @@ var listConnectionsPlugin = defineMethod({
11094
11270
  adaptPage: adaptZapierPage,
11095
11271
  defaultPageSize: DEFAULT_PAGE_SIZE
11096
11272
  },
11097
- run: async ({ imports, input }) => {
11273
+ run: async ({
11274
+ imports,
11275
+ input,
11276
+ annotate
11277
+ }) => {
11098
11278
  const resolveConnection = imports.connections.resolveConnection;
11099
11279
  const api = imports.api;
11100
11280
  const getVersionedImplementationId = imports.manifest.getVersionedImplementationId;
@@ -11109,7 +11289,7 @@ var listConnectionsPlugin = defineMethod({
11109
11289
  if (appKey) {
11110
11290
  const implementationId = await getVersionedImplementationId(appKey);
11111
11291
  if (implementationId) {
11112
- setMethodMetadata({ selectedApi: implementationId });
11292
+ annotate({ selectedApi: implementationId });
11113
11293
  const [versionlessSelectedApi] = splitVersionedKey(implementationId);
11114
11294
  searchParams.app_key = versionlessSelectedApi;
11115
11295
  } else {
@@ -11625,12 +11805,12 @@ var getConnectionStartUrlPlugin = defineMethod({
11625
11805
  outputSchema: GetConnectionStartUrlItemSchema,
11626
11806
  output: "item",
11627
11807
  resolvers: { app: appKeyResolver },
11628
- run: async ({ imports, input }) => {
11808
+ run: async ({ imports, input, annotate }) => {
11629
11809
  const api = imports.api;
11630
11810
  const getVersionedImplementationId = imports.manifest.getVersionedImplementationId;
11631
11811
  const versionedKey = await getVersionedImplementationId(input.app);
11632
11812
  const selectedApi = versionedKey ? versionedKey.split("@")[0] : input.app;
11633
- setMethodMetadata({ selectedApi });
11813
+ annotate({ selectedApi });
11634
11814
  const response = await api.post(
11635
11815
  START_PATH,
11636
11816
  { selected_api: selectedApi },
@@ -11651,12 +11831,18 @@ var WaitForNewConnectionSchema = zod.z.object({
11651
11831
  startedAt: zod.z.number().int().nonnegative().describe(
11652
11832
  "Unix timestamp (seconds). Only connections whose `date` is at or after this value count as 'new'. Prefer the `startedAt` returned by `get-connection-start-url` \u2014 it's server-stamped, so the comparison isn't thrown off by client clock skew. If you mint the timestamp yourself, capture it *before* showing the start URL so a fast OAuth completion isn't missed."
11653
11833
  ),
11834
+ timeoutSeconds: zod.z.number().int().positive().optional().describe("How long to wait before giving up. Default 5 minutes (300)."),
11835
+ /** @deprecated Use `timeoutSeconds` instead. */
11654
11836
  timeoutMs: zod.z.number().int().positive().optional().describe(
11655
11837
  "How long to wait before giving up. Default 5 minutes (300_000)."
11838
+ ).meta({ deprecated: true }),
11839
+ pollIntervalMilliseconds: zod.z.number().int().positive().optional().describe(
11840
+ "Delay before the first poll request, in ms. Default 3 seconds (3_000). Subsequent polling cadence is managed by the SDK's polling primitive (backoff with sane defaults)."
11656
11841
  ),
11842
+ /** @deprecated Use `pollIntervalMilliseconds` instead. */
11657
11843
  pollIntervalMs: zod.z.number().int().positive().optional().describe(
11658
11844
  "Delay before the first poll request, in ms. Default 3 seconds (3_000). Subsequent polling cadence is managed by the SDK's polling primitive (backoff with sane defaults)."
11659
- )
11845
+ ).meta({ deprecated: true })
11660
11846
  }).describe(
11661
11847
  "Wait for a new connection to appear for the given app. Polls `/api/v0/connections` with server-side `ordering=-date` until the most recent matching row's `date` is at or after the started-at timestamp, then returns it. Pair with `get-connection-start-url` \u2014 that mints the URL the user opens, this waits for the resulting connection to land. Errors with a timeout after the configured timeout (default 5 min). Example (JS):\n\n```ts\nconst { data: { url, app, startedAt } } = await zapier.getConnectionStartUrl({ app: 'slack' });\n// show `url` to the user via the channel they're reading from\nconst { data: conn } = await zapier.waitForNewConnection({ app, startedAt });\n```"
11662
11848
  );
@@ -11683,12 +11869,12 @@ var waitForNewConnectionPlugin = defineMethod({
11683
11869
  outputSchema: WaitForNewConnectionItemSchema,
11684
11870
  output: "item",
11685
11871
  resolvers: { app: appKeyResolver },
11686
- run: async ({ imports, input }) => {
11872
+ run: async ({ imports, input, annotate }) => {
11687
11873
  const api = imports.api;
11688
11874
  const getVersionedImplementationId = imports.manifest.getVersionedImplementationId;
11689
11875
  const versionedKey = await getVersionedImplementationId(input.app);
11690
11876
  const appKey = versionedKey ? versionedKey.split("@")[0] : input.app;
11691
- setMethodMetadata({ selectedApi: appKey });
11877
+ annotate({ selectedApi: appKey });
11692
11878
  try {
11693
11879
  const top = await api.poll(CONNECTIONS_PATH, {
11694
11880
  searchParams: {
@@ -11703,8 +11889,8 @@ var waitForNewConnectionPlugin = defineMethod({
11703
11889
  page_size: "1"
11704
11890
  },
11705
11891
  authRequired: true,
11706
- timeoutMs: input.timeoutMs ?? 3e5,
11707
- initialDelay: input.pollIntervalMs ?? 3e3,
11892
+ timeoutMilliseconds: input.timeoutSeconds != null ? input.timeoutSeconds * 1e3 : input.timeoutMs ?? 3e5,
11893
+ initialDelayMilliseconds: input.pollIntervalMilliseconds ?? input.pollIntervalMs ?? 3e3,
11708
11894
  isPending: (body) => {
11709
11895
  const rows = body.data ?? [];
11710
11896
  const head = rows[0];
@@ -11754,12 +11940,20 @@ var CreateConnectionSchema = zod.z.object({
11754
11940
  browser: zod.z.enum(["auto", "always", "never"]).default("auto").describe(
11755
11941
  "When to auto-open the URL in a browser. `auto` (default) opens in local sessions and skips opening in CI / SSH / headless-Linux. `always` forces the open attempt. `never` skips it. The URL is always printed to stderr regardless \u2014 a failed or skipped open degrades gracefully to copy-paste."
11756
11942
  ),
11943
+ timeoutSeconds: zod.z.number().int().positive().optional().describe(
11944
+ "How long to wait for the user to complete the connection flow before giving up. Default 5 minutes (300)."
11945
+ ),
11946
+ /** @deprecated Use `timeoutSeconds` instead. */
11757
11947
  timeoutMs: zod.z.number().int().positive().optional().describe(
11758
11948
  "How long to wait for the user to complete the connection flow before giving up. Default 5 minutes (300_000)."
11949
+ ).meta({ deprecated: true }),
11950
+ pollIntervalMilliseconds: zod.z.number().int().positive().optional().describe(
11951
+ "Delay before the first poll request, in ms. Default 3 seconds (3_000). Subsequent polling cadence is managed by the SDK's polling primitive (backoff with sane defaults)."
11759
11952
  ),
11953
+ /** @deprecated Use `pollIntervalMilliseconds` instead. */
11760
11954
  pollIntervalMs: zod.z.number().int().positive().optional().describe(
11761
11955
  "Delay before the first poll request, in ms. Default 3 seconds (3_000). Subsequent polling cadence is managed by the SDK's polling primitive (backoff with sane defaults)."
11762
- )
11956
+ ).meta({ deprecated: true })
11763
11957
  }).describe(
11764
11958
  "Create a new app connection, end-to-end. Mints the start URL via `get-connection-start-url`, prints it to stderr, opportunistically opens it in a browser when it looks safe to do so (skipping CI / SSH / headless-Linux by default \u2014 pass `--browser always` to force, `--browser never` to suppress), then polls via `wait-for-new-connection` until the user completes OAuth and the new connection appears. Returns the connection.\n\nThis is the right command for most callers. Reach for the lower-level building blocks when you want either of: (a) hand off the URL and *not* block on completion \u2014 call `get-connection-start-url` alone, no `wait-for-new-connection` needed, or (b) do something custom between minting the URL and waiting \u2014 call `get-connection-start-url`, do your work (email or DM the URL, render a QR code, etc.), then `wait-for-new-connection`."
11765
11959
  );
@@ -11798,11 +11992,11 @@ var createConnectionPlugin = defineMethod({
11798
11992
  ]
11799
11993
  })
11800
11994
  }),
11801
- run: async ({ imports, input }) => {
11995
+ run: async ({ imports, input, annotate }) => {
11802
11996
  const { data: start2 } = await imports.getConnectionStartUrl({
11803
11997
  app: input.app
11804
11998
  });
11805
- setMethodMetadata({ selectedApi: start2.app });
11999
+ annotate({ selectedApi: start2.app });
11806
12000
  console.error(
11807
12001
  `
11808
12002
  Open this URL to complete the connection:
@@ -11821,8 +12015,9 @@ Open this URL to complete the connection:
11821
12015
  // Server-stamped mint time: measured on the same clock as a connection's
11822
12016
  // `date`, so the freshness check is immune to client/server clock skew.
11823
12017
  startedAt: start2.startedAt,
12018
+ timeoutSeconds: input.timeoutSeconds,
11824
12019
  timeoutMs: input.timeoutMs,
11825
- pollIntervalMs: input.pollIntervalMs
12020
+ pollIntervalMilliseconds: input.pollIntervalMilliseconds ?? input.pollIntervalMs
11826
12021
  });
11827
12022
  return {
11828
12023
  data: CreateConnectionItemSchema.parse({
@@ -12056,6 +12251,10 @@ var triggerInboxItemFormatter = defineFormatter({
12056
12251
 
12057
12252
  // src/plugins/triggers/shared.ts
12058
12253
  var triggerCategories = ["trigger"];
12254
+ function deriveReadOperation() {
12255
+ const annotations = { operationType: "read" };
12256
+ return { ...annotations };
12257
+ }
12059
12258
 
12060
12259
  // src/plugins/triggers/utils.ts
12061
12260
  var UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
@@ -12101,6 +12300,7 @@ var createTriggerInboxPlugin = defineMethod({
12101
12300
  outputSchema: TriggerInboxItemSchema,
12102
12301
  output: "item",
12103
12302
  formatter: triggerInboxItemFormatter,
12303
+ annotator: deriveReadOperation,
12104
12304
  // actionKeyResolver and inputsResolver depend on actionType, which is always
12105
12305
  // "read" for triggers. Pin it as a constant resolver so it's seeded into
12106
12306
  // resolvedParams without polluting the user-facing schema (where it would
@@ -12205,6 +12405,7 @@ var ensureTriggerInboxPlugin = defineMethod({
12205
12405
  outputSchema: TriggerInboxItemSchema,
12206
12406
  output: "item",
12207
12407
  formatter: triggerInboxItemFormatter,
12408
+ annotator: deriveReadOperation,
12208
12409
  // actionKeyResolver and inputsResolver depend on actionType, which is always
12209
12410
  // "read" for triggers. Pin it as a constant resolver so it's seeded into
12210
12411
  // resolvedParams without polluting the user-facing schema.
@@ -13181,9 +13382,9 @@ async function* readInboxEvents({
13181
13382
  }
13182
13383
 
13183
13384
  // src/plugins/triggers/watchTriggerInbox/index.ts
13184
- var SSE_RECONNECT_BACKOFF_MS = [500, 1e3, 2e3, 5e3];
13185
- var DEFAULT_SAFETY_DRAIN_INTERVAL_MS = 3e5;
13186
- var SSE_HEALTHY_CONNECTION_MS = 5e3;
13385
+ var SSE_RECONNECT_BACKOFF_MILLISECONDS = [500, 1e3, 2e3, 5e3];
13386
+ var DEFAULT_SAFETY_DRAIN_INTERVAL_MILLISECONDS = 3e5;
13387
+ var SSE_HEALTHY_CONNECTION_MILLISECONDS = 5e3;
13187
13388
  var ERROR_BACKOFF_CAP = 4;
13188
13389
  function createDrainLatch() {
13189
13390
  let pending = false;
@@ -13241,7 +13442,7 @@ async function drainRunner({
13241
13442
  consecutiveErrors = Math.min(consecutiveErrors + 1, ERROR_BACKOFF_CAP);
13242
13443
  errorAttempts += 1;
13243
13444
  const delay = calculateErrorBackoffMs(
13244
- BASE_ERROR_BACKOFF_MS,
13445
+ BASE_ERROR_BACKOFF_MILLISECONDS,
13245
13446
  consecutiveErrors
13246
13447
  );
13247
13448
  const statusCode = errorStatusCode(error);
@@ -13307,7 +13508,7 @@ async function sseLoop({
13307
13508
  })) {
13308
13509
  drainRequest.request();
13309
13510
  }
13310
- if (connected && Date.now() - connectedAt >= SSE_HEALTHY_CONNECTION_MS) {
13511
+ if (connected && Date.now() - connectedAt >= SSE_HEALTHY_CONNECTION_MILLISECONDS) {
13311
13512
  attempt = 0;
13312
13513
  }
13313
13514
  } catch (err) {
@@ -13331,8 +13532,11 @@ async function sseLoop({
13331
13532
  transientError = err;
13332
13533
  }
13333
13534
  if (signal.aborted) return;
13334
- const delay = SSE_RECONNECT_BACKOFF_MS[Math.min(attempt, SSE_RECONNECT_BACKOFF_MS.length - 1)];
13335
- attempt = Math.min(attempt + 1, SSE_RECONNECT_BACKOFF_MS.length - 1);
13535
+ const delay = SSE_RECONNECT_BACKOFF_MILLISECONDS[Math.min(attempt, SSE_RECONNECT_BACKOFF_MILLISECONDS.length - 1)];
13536
+ attempt = Math.min(
13537
+ attempt + 1,
13538
+ SSE_RECONNECT_BACKOFF_MILLISECONDS.length - 1
13539
+ );
13336
13540
  if (transientError !== void 0 && debug) {
13337
13541
  const statusCode = errorStatusCode(transientError);
13338
13542
  const errorMsg = errorMessage(transientError);
@@ -13389,7 +13593,7 @@ var watchTriggerInboxPlugin = defineMethod({
13389
13593
  const { concurrency, leaseLimit } = resolveConcurrencyAndLease(input);
13390
13594
  const inboxId = await resolveTriggerInboxId({ api, inbox: input.inbox });
13391
13595
  if (input.signal?.aborted) return;
13392
- const safetyDrainMs = input.maxDrainIntervalSeconds !== void 0 ? input.maxDrainIntervalSeconds * 1e3 : DEFAULT_SAFETY_DRAIN_INTERVAL_MS;
13596
+ const safetyDrainMs = input.maxDrainIntervalSeconds !== void 0 ? input.maxDrainIntervalSeconds * 1e3 : DEFAULT_SAFETY_DRAIN_INTERVAL_MILLISECONDS;
13393
13597
  const stop = new AbortController();
13394
13598
  const combined = combineAbortSignals({
13395
13599
  handles: [
@@ -13506,6 +13710,7 @@ var listTriggerInputFieldsPlugin = defineMethod({
13506
13710
  outputSchema: RootFieldItemSchema,
13507
13711
  output: { type: "list", defaultPageSize: DEFAULT_PAGE_SIZE },
13508
13712
  formatter: rootFieldItemFormatter,
13713
+ annotator: deriveReadOperation,
13509
13714
  // actionKeyResolver and inputsAllOptionalResolver depend on actionType. Pin it
13510
13715
  // to "read" so they resolve correctly without the user setting it.
13511
13716
  resolvers: {
@@ -13552,6 +13757,7 @@ var listTriggerInputFieldChoicesPlugin = defineMethod({
13552
13757
  outputSchema: InputFieldChoiceItemSchema,
13553
13758
  output: { type: "list", defaultPageSize: DEFAULT_PAGE_SIZE },
13554
13759
  formatter: inputFieldChoiceItemFormatter,
13760
+ annotator: deriveReadOperation,
13555
13761
  resolvers: {
13556
13762
  app: appKeyResolver,
13557
13763
  action: actionKeyResolver,
@@ -13595,6 +13801,7 @@ var getTriggerInputFieldsSchemaPlugin = defineMethod({
13595
13801
  // Passthrough: getActionInputFieldsSchema already returns `{ data }`, so
13596
13802
  // `output: "raw"` surfaces that envelope unchanged.
13597
13803
  output: "raw",
13804
+ annotator: deriveReadOperation,
13598
13805
  resolvers: {
13599
13806
  app: appKeyResolver,
13600
13807
  action: actionKeyResolver,
@@ -14418,7 +14625,7 @@ var updateTableRecordsPlugin = defineMethod({
14418
14625
 
14419
14626
  // src/plugins/eventEmission/transport.ts
14420
14627
  var DEFAULT_RETRY_ATTEMPTS = 2;
14421
- var DEFAULT_RETRY_DELAY_MS = 300;
14628
+ var DEFAULT_RETRY_DELAY_MILLISECONDS = 300;
14422
14629
  function createHttpTransport(config) {
14423
14630
  const delay = async (ms) => {
14424
14631
  return new Promise((resolve2) => {
@@ -14443,12 +14650,12 @@ function createHttpTransport(config) {
14443
14650
  body: JSON.stringify(payload)
14444
14651
  });
14445
14652
  if (!response.ok && attemptsLeft > 1) {
14446
- await delay(config.retryDelayMs || DEFAULT_RETRY_DELAY_MS);
14653
+ await delay(config.retryDelayMs || DEFAULT_RETRY_DELAY_MILLISECONDS);
14447
14654
  return emitWithRetry(subject, event, attemptsLeft - 1);
14448
14655
  }
14449
14656
  } catch (error) {
14450
14657
  if (attemptsLeft > 1) {
14451
- await delay(config.retryDelayMs || DEFAULT_RETRY_DELAY_MS);
14658
+ await delay(config.retryDelayMs || DEFAULT_RETRY_DELAY_MILLISECONDS);
14452
14659
  return emitWithRetry(subject, event, attemptsLeft - 1);
14453
14660
  }
14454
14661
  throw error;
@@ -14712,6 +14919,14 @@ function buildMethodCalledEvent(data, context = {}) {
14712
14919
  }
14713
14920
 
14714
14921
  // src/plugins/eventEmission/event-emission-hook.ts
14922
+ function readMethodMetadata(annotations) {
14923
+ const readString = (value) => typeof value === "string" ? value : null;
14924
+ return {
14925
+ selectedApi: readString(annotations.selectedApi),
14926
+ operationType: readString(annotations.operationType),
14927
+ operationKey: readString(annotations.operationKey)
14928
+ };
14929
+ }
14715
14930
  function computeArgumentCount(args) {
14716
14931
  if (args.length === 1) {
14717
14932
  const arg0 = args[0];
@@ -14722,9 +14937,18 @@ function computeArgumentCount(args) {
14722
14937
  return args.filter((a) => a !== void 0).length;
14723
14938
  }
14724
14939
  function makeMethodEndHook(emitMethodCalled) {
14725
- return ({ methodName, args, isPaginated, depth, durationMs, error }) => {
14726
- if (depth > 0) return;
14727
- const metadata = getMethodMetadata();
14940
+ return ({
14941
+ methodName,
14942
+ args,
14943
+ isPaginated,
14944
+ depth,
14945
+ callOrigin,
14946
+ annotations,
14947
+ durationMs,
14948
+ error
14949
+ }) => {
14950
+ if (callOrigin === "internal" || depth > 0) return;
14951
+ const metadata = readMethodMetadata(annotations);
14728
14952
  emitMethodCalled({
14729
14953
  method_name: methodName,
14730
14954
  execution_duration_ms: durationMs,
@@ -14733,15 +14957,36 @@ function makeMethodEndHook(emitMethodCalled) {
14733
14957
  error_type: error?.constructor.name ?? null,
14734
14958
  argument_count: computeArgumentCount(args),
14735
14959
  is_paginated: isPaginated,
14736
- selected_api: metadata?.selectedApi ?? null,
14737
- operation_type: metadata?.operationType ?? null,
14738
- operation_key: metadata?.operationKey ?? null
14960
+ selected_api: metadata.selectedApi ?? null,
14961
+ operation_type: metadata.operationType ?? null,
14962
+ operation_key: metadata.operationKey ?? null
14739
14963
  });
14740
14964
  };
14741
14965
  }
14742
14966
 
14967
+ // src/plugins/eventEmission/annotator.ts
14968
+ function zapierAnnotate({ input }) {
14969
+ const annotations = {};
14970
+ if (typeof input === "object" && input !== null) {
14971
+ const record = input;
14972
+ if (typeof record.actionType === "string") {
14973
+ annotations.operationType = record.actionType;
14974
+ }
14975
+ const operationKey = record.action ?? record.actionKey;
14976
+ if (typeof operationKey === "string") {
14977
+ annotations.operationKey = operationKey;
14978
+ }
14979
+ }
14980
+ return { ...annotations };
14981
+ }
14982
+ var operationAnnotatorPlugin = defineHook({
14983
+ namespace: "zapier",
14984
+ name: "operationAnnotator",
14985
+ annotator: ({ input }) => zapierAnnotate({ input })
14986
+ });
14987
+
14743
14988
  // src/plugins/eventEmission/index.ts
14744
- var TELEMETRY_EMIT_TIMEOUT_MS = 300;
14989
+ var TELEMETRY_EMIT_TIMEOUT_MILLISECONDS = 300;
14745
14990
  var registeredListeners = {};
14746
14991
  function removeExistingListeners() {
14747
14992
  const events = [
@@ -14787,7 +15032,7 @@ async function emitWithTimeout(transport, subject, event) {
14787
15032
  await Promise.race([
14788
15033
  transport.emit(subject, event),
14789
15034
  new Promise((resolve2) => {
14790
- const timer = setTimeout(resolve2, TELEMETRY_EMIT_TIMEOUT_MS);
15035
+ const timer = setTimeout(resolve2, TELEMETRY_EMIT_TIMEOUT_MILLISECONDS);
14791
15036
  if (typeof timer.unref === "function") {
14792
15037
  timer.unref();
14793
15038
  }
@@ -15140,7 +15385,8 @@ var zapierSdkPlugin = definePlugin({
15140
15385
  connectionsPlugin,
15141
15386
  capabilitiesPlugin,
15142
15387
  eventEmissionPlugin,
15143
- eventEmissionHookPlugin
15388
+ eventEmissionHookPlugin,
15389
+ operationAnnotatorPlugin
15144
15390
  ],
15145
15391
  exports: [
15146
15392
  // The registry reporter: previously synthesized by the legacy merge,
@@ -15226,14 +15472,14 @@ function createZapierSdk(options = {}) {
15226
15472
 
15227
15473
  // src/utils/batch-utils.ts
15228
15474
  var DEFAULT_CONCURRENCY = 10;
15229
- var BATCH_START_DELAY_MS = 25;
15230
- var DEFAULT_BATCH_TIMEOUT_MS = 18e4;
15475
+ var BATCH_START_DELAY_MILLISECONDS = 25;
15476
+ var DEFAULT_BATCH_TIMEOUT_MILLISECONDS = 18e4;
15231
15477
  async function batch(tasks, options = {}) {
15232
15478
  const {
15233
15479
  concurrency = DEFAULT_CONCURRENCY,
15234
15480
  retry = true,
15235
- batchDelay = BATCH_START_DELAY_MS,
15236
- timeoutMs = DEFAULT_BATCH_TIMEOUT_MS,
15481
+ batchDelay = BATCH_START_DELAY_MILLISECONDS,
15482
+ timeoutMs = DEFAULT_BATCH_TIMEOUT_MILLISECONDS,
15237
15483
  taskTimeoutMs
15238
15484
  } = options;
15239
15485
  if (concurrency <= 0) {
@@ -15326,11 +15572,15 @@ var BaseSdkOptionsSchema = zod.z.object({
15326
15572
  */
15327
15573
  maxNetworkRetries: zod.z.number().optional().describe("Max retries for rate-limited requests (default: 3).").meta({ valueHint: "count" }),
15328
15574
  /**
15329
- * Maximum delay in milliseconds to wait for a rate limit retry.
15575
+ * Maximum delay in seconds to wait for a rate-limit retry.
15330
15576
  * If the server requests a longer delay, the request fails immediately.
15331
- * Default is 60000 (60 seconds).
15577
+ * Default is 60 (60 seconds).
15332
15578
  */
15333
- maxNetworkRetryDelayMs: zod.z.number().optional().describe("Max delay in ms to wait for retry (default: 60000).").meta({ valueHint: "ms" }),
15579
+ maxNetworkRetryDelaySeconds: zod.z.number().optional().describe(
15580
+ "Max delay in seconds to wait for a rate-limit retry (default: 60)."
15581
+ ).meta({ valueHint: "seconds" }),
15582
+ /** @deprecated Use `maxNetworkRetryDelaySeconds` instead. */
15583
+ maxNetworkRetryDelayMs: zod.z.number().optional().describe("Max delay in ms to wait for retry (default: 60000).").meta({ valueHint: "ms", deprecated: true }),
15334
15584
  /**
15335
15585
  * Maximum number of concurrent in-flight HTTP requests per client.
15336
15586
  * Requests beyond this limit queue in FIFO order until a slot frees.
@@ -15349,7 +15599,9 @@ var BaseSdkOptionsSchema = zod.z.object({
15349
15599
  ]).optional().describe(
15350
15600
  `Max concurrent in-flight HTTP requests (default: 200, max: ${MAX_CONCURRENCY_LIMIT}).`
15351
15601
  ).meta({ valueHint: "count" }),
15352
- approvalTimeoutMs: zod.z.number().optional().describe("Timeout in ms for approval polling. Default: 600000 (10 min).").meta({ valueHint: "ms" }),
15602
+ approvalTimeoutSeconds: zod.z.number().optional().describe("Timeout in seconds for approval polling. Default: 600 (10 min).").meta({ valueHint: "seconds" }),
15603
+ /** @deprecated Use `approvalTimeoutSeconds` instead. */
15604
+ approvalTimeoutMs: zod.z.number().optional().describe("Timeout in ms for approval polling. Default: 600000 (10 min).").meta({ valueHint: "ms", deprecated: true }),
15353
15605
  maxApprovalRetries: zod.z.number().optional().describe(
15354
15606
  "Maximum number of sequential approval rounds per request (one per gating policy) before giving up. Default: 2."
15355
15607
  ),
@@ -15386,7 +15638,8 @@ var registryPlugin = (_sdk) => {
15386
15638
  exports.API_ID = API_ID;
15387
15639
  exports.ActionKeyPropertySchema = ActionKeyPropertySchema;
15388
15640
  exports.ActionPropertySchema = ActionPropertySchema;
15389
- exports.ActionTimeoutMsPropertySchema = ActionTimeoutMsPropertySchema;
15641
+ exports.ActionTimeoutMillisecondsPropertySchema = ActionTimeoutMillisecondsPropertySchema;
15642
+ exports.ActionTimeoutSecondsPropertySchema = ActionTimeoutSecondsPropertySchema;
15390
15643
  exports.ActionTypePropertySchema = ActionTypePropertySchema;
15391
15644
  exports.AppKeyPropertySchema = AppKeyPropertySchema;
15392
15645
  exports.AppPropertySchema = AppPropertySchema;
@@ -15397,7 +15650,7 @@ exports.BaseSdkOptionsSchema = BaseSdkOptionsSchema;
15397
15650
  exports.CONNECTIONS_ID = CONNECTIONS_ID;
15398
15651
  exports.CONTEXT = CONTEXT;
15399
15652
  exports.CONTEXT_CACHE_MAX_SIZE = CONTEXT_CACHE_MAX_SIZE;
15400
- exports.CONTEXT_CACHE_TTL_MS = CONTEXT_CACHE_TTL_MS;
15653
+ exports.CONTEXT_CACHE_TTL_MILLISECONDS = CONTEXT_CACHE_TTL_MILLISECONDS;
15401
15654
  exports.CORE_ERROR_SYMBOL = CORE_ERROR_SYMBOL;
15402
15655
  exports.CORE_OPTIONS_ID = CORE_OPTIONS_ID;
15403
15656
  exports.CORE_SIGNAL_SYMBOL = CORE_SIGNAL_SYMBOL;
@@ -15414,8 +15667,8 @@ exports.CoreSignal = CoreSignal;
15414
15667
  exports.CredentialsFunctionSchema = CredentialsFunctionSchema;
15415
15668
  exports.CredentialsObjectSchema = CredentialsObjectSchema;
15416
15669
  exports.CredentialsSchema = CredentialsSchema;
15417
- exports.DEFAULT_ACTION_TIMEOUT_MS = DEFAULT_ACTION_TIMEOUT_MS;
15418
- exports.DEFAULT_APPROVAL_TIMEOUT_MS = DEFAULT_APPROVAL_TIMEOUT_MS;
15670
+ exports.DEFAULT_ACTION_TIMEOUT_MILLISECONDS = DEFAULT_ACTION_TIMEOUT_MILLISECONDS;
15671
+ exports.DEFAULT_APPROVAL_TIMEOUT_MILLISECONDS = DEFAULT_APPROVAL_TIMEOUT_MILLISECONDS;
15419
15672
  exports.DEFAULT_CONFIG_PATH = DEFAULT_CONFIG_PATH;
15420
15673
  exports.DEFAULT_MAX_APPROVAL_RETRIES = DEFAULT_MAX_APPROVAL_RETRIES;
15421
15674
  exports.DEFAULT_PAGE_SIZE = DEFAULT_PAGE_SIZE;
@@ -15453,7 +15706,7 @@ exports.WatchTriggerInboxSchema = WatchTriggerInboxSchema;
15453
15706
  exports.ZAPIER_BASE_URL = ZAPIER_BASE_URL;
15454
15707
  exports.ZAPIER_MAX_CONCURRENT_REQUESTS = ZAPIER_MAX_CONCURRENT_REQUESTS;
15455
15708
  exports.ZAPIER_MAX_NETWORK_RETRIES = ZAPIER_MAX_NETWORK_RETRIES;
15456
- exports.ZAPIER_MAX_NETWORK_RETRY_DELAY_MS = ZAPIER_MAX_NETWORK_RETRY_DELAY_MS;
15709
+ exports.ZAPIER_MAX_NETWORK_RETRY_DELAY_MILLISECONDS = ZAPIER_MAX_NETWORK_RETRY_DELAY_MILLISECONDS;
15457
15710
  exports.ZapierAbortDrainSignal = ZapierAbortDrainSignal;
15458
15711
  exports.ZapierActionError = ZapierActionError;
15459
15712
  exports.ZapierApiError = ZapierApiError;
@@ -15615,6 +15868,7 @@ exports.manifestPlugin = manifestPlugin;
15615
15868
  exports.manifestPluginRef = manifestPluginRef;
15616
15869
  exports.omitExports = omitExports;
15617
15870
  exports.openEnum = openEnum;
15871
+ exports.operationAnnotatorPlugin = operationAnnotatorPlugin;
15618
15872
  exports.parseConcurrencyEnvVar = parseConcurrencyEnvVar;
15619
15873
  exports.readManifestFromFile = readManifestFromFile;
15620
15874
  exports.registryPlugin = registryPlugin;