@zapier/zapier-sdk 0.88.0 → 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
  }
@@ -5828,7 +5999,7 @@ function parseDeprecationDate(value) {
5828
5999
  }
5829
6000
 
5830
6001
  // src/sdk-version.ts
5831
- var SDK_VERSION = (typeof process !== "undefined" && process.env ? "0.88.0" : void 0) || "unknown";
6002
+ var SDK_VERSION = (typeof process !== "undefined" && process.env ? "0.88.1" : void 0) || "unknown";
5832
6003
 
5833
6004
  // src/utils/open-url.ts
5834
6005
  var nodePrefix = "node:";
@@ -9758,18 +9929,6 @@ var tableSortResolver = defineResolver({
9758
9929
  }
9759
9930
  });
9760
9931
 
9761
- // src/plugins/eventEmission/method-metadata.ts
9762
- var SCOPE_KEY = "methodMetadata";
9763
- function setMethodMetadata(metadata) {
9764
- const scope2 = getCurrentScope();
9765
- if (!scope2) return;
9766
- const existing = scope2[SCOPE_KEY];
9767
- scope2[SCOPE_KEY] = { ...existing, ...metadata };
9768
- }
9769
- function getMethodMetadata() {
9770
- return getCurrentScope()?.[SCOPE_KEY];
9771
- }
9772
-
9773
9932
  // src/plugins/listActions/index.ts
9774
9933
  var listActionsPlugin = defineMethod({
9775
9934
  name: "listActions",
@@ -9787,7 +9946,7 @@ var listActionsPlugin = defineMethod({
9787
9946
  // of listing every action. `getAction` (where `actionType` is required) keeps
9788
9947
  // the resolver.
9789
9948
  resolvers: { app: appKeyResolver },
9790
- run: async ({ imports, input }) => {
9949
+ run: async ({ imports, input, annotate }) => {
9791
9950
  const api = imports.api;
9792
9951
  const getVersionedImplementationId = imports.manifest.getVersionedImplementationId;
9793
9952
  const appKey = "app" in input ? input.app : input.appKey;
@@ -9798,10 +9957,7 @@ var listActionsPlugin = defineMethod({
9798
9957
  { configType: "current_implementation_id" }
9799
9958
  );
9800
9959
  }
9801
- setMethodMetadata({
9802
- selectedApi,
9803
- operationType: input.actionType ?? null
9804
- });
9960
+ annotate({ selectedApi });
9805
9961
  const data = await api.get(
9806
9962
  "/zapier/api/v4/implementations/",
9807
9963
  {
@@ -9856,10 +10012,6 @@ var getActionPlugin = defineMethod({
9856
10012
  const appKey = "app" in input ? input.app : input.appKey;
9857
10013
  const actionKey = "action" in input ? input.action : input.actionKey;
9858
10014
  const { actionType } = input;
9859
- setMethodMetadata({
9860
- operationType: actionType,
9861
- operationKey: actionKey
9862
- });
9863
10015
  for await (const action of imports.listActions({ app: appKey }).items()) {
9864
10016
  if ((action.key === actionKey || action.id === actionKey) && action.action_type === actionType) {
9865
10017
  return { data: action };
@@ -9952,9 +10104,10 @@ var runActionPlugin = defineMethod({
9952
10104
  inputs: inputsResolver
9953
10105
  },
9954
10106
  // A per-SDK-instance TTL cache of resolved (selectedApi, actionId), built once
9955
- // in setup so it persists across calls. Reads getVersionedImplementationId
9956
- // (`imports.manifest`) and getAction (an import).
9957
- 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: () => {
9958
10111
  const cache = /* @__PURE__ */ new Map();
9959
10112
  function evictIfNeeded() {
9960
10113
  if (cache.size < CONTEXT_CACHE_MAX_SIZE) return;
@@ -9974,7 +10127,7 @@ var runActionPlugin = defineMethod({
9974
10127
  if (!evictedAny && oldestKey) cache.delete(oldestKey);
9975
10128
  }
9976
10129
  async function resolveRunActionContext(options) {
9977
- const { appKey, actionKey, actionType } = options;
10130
+ const { imports, appKey, actionKey, actionType } = options;
9978
10131
  const getVersionedImplementationId = imports.manifest.getVersionedImplementationId;
9979
10132
  const selectedApi = await getVersionedImplementationId(appKey);
9980
10133
  if (!selectedApi) {
@@ -10013,7 +10166,7 @@ var runActionPlugin = defineMethod({
10013
10166
  }
10014
10167
  return { getRunActionContext };
10015
10168
  },
10016
- run: async ({ imports, input, state }) => {
10169
+ run: async ({ imports, input, state, annotate }) => {
10017
10170
  const api = imports.api;
10018
10171
  const resolveConnection = imports.connections.resolveConnection;
10019
10172
  const appKey = "app" in input ? input.app : input.appKey;
@@ -10034,15 +10187,12 @@ var runActionPlugin = defineMethod({
10034
10187
  resolveConnection
10035
10188
  });
10036
10189
  const { selectedApi, actionId } = await state.getRunActionContext({
10190
+ imports,
10037
10191
  appKey,
10038
10192
  actionKey,
10039
10193
  actionType
10040
10194
  });
10041
- setMethodMetadata({
10042
- selectedApi,
10043
- operationType: actionType,
10044
- operationKey: actionKey
10045
- });
10195
+ annotate({ selectedApi });
10046
10196
  const result = await executeAction({
10047
10197
  api,
10048
10198
  selectedApi,
@@ -10678,7 +10828,11 @@ var listActionInputFieldsPlugin = defineMethod({
10678
10828
  // metadata; the engine permits a resolver importing its host.
10679
10829
  inputs: inputsAllOptionalResolver
10680
10830
  },
10681
- run: async ({ imports, input }) => {
10831
+ run: async ({
10832
+ imports,
10833
+ input,
10834
+ annotate
10835
+ }) => {
10682
10836
  const api = imports.api;
10683
10837
  const getVersionedImplementationId = imports.manifest.getVersionedImplementationId;
10684
10838
  const resolveConnection = imports.connections.resolveConnection;
@@ -10698,11 +10852,7 @@ var listActionInputFieldsPlugin = defineMethod({
10698
10852
  { configType: "current_implementation_id" }
10699
10853
  );
10700
10854
  }
10701
- setMethodMetadata({
10702
- selectedApi,
10703
- operationType: actionType,
10704
- operationKey: actionKey
10705
- });
10855
+ annotate({ selectedApi });
10706
10856
  const { data: action } = await imports.getAction({
10707
10857
  app: appKey,
10708
10858
  actionType,
@@ -10813,7 +10963,11 @@ var listActionInputFieldChoicesPlugin = defineMethod({
10813
10963
  inputField: inputFieldKeyResolver,
10814
10964
  inputs: inputsAllOptionalResolver
10815
10965
  },
10816
- run: async ({ imports, input }) => {
10966
+ run: async ({
10967
+ imports,
10968
+ input,
10969
+ annotate
10970
+ }) => {
10817
10971
  const api = imports.api;
10818
10972
  const getVersionedImplementationId = imports.manifest.getVersionedImplementationId;
10819
10973
  const resolveConnection = imports.connections.resolveConnection;
@@ -10842,11 +10996,7 @@ var listActionInputFieldChoicesPlugin = defineMethod({
10842
10996
  { configType: "current_implementation_id" }
10843
10997
  );
10844
10998
  }
10845
- setMethodMetadata({
10846
- selectedApi,
10847
- operationType: actionType,
10848
- operationKey: actionKey
10849
- });
10999
+ annotate({ selectedApi });
10850
11000
  const { data: action } = await imports.getAction({
10851
11001
  app: appKey,
10852
11002
  actionType,
@@ -10975,7 +11125,8 @@ var getActionInputFieldsSchemaPlugin = defineMethod({
10975
11125
  },
10976
11126
  run: async ({
10977
11127
  imports,
10978
- input
11128
+ input,
11129
+ annotate
10979
11130
  }) => {
10980
11131
  const api = imports.api;
10981
11132
  const getVersionedImplementationId = imports.manifest.getVersionedImplementationId;
@@ -10996,11 +11147,7 @@ var getActionInputFieldsSchemaPlugin = defineMethod({
10996
11147
  { configType: "current_implementation_id" }
10997
11148
  );
10998
11149
  }
10999
- setMethodMetadata({
11000
- selectedApi,
11001
- operationType: actionType,
11002
- operationKey: actionKey
11003
- });
11150
+ annotate({ selectedApi });
11004
11151
  const { data: action } = await imports.getAction({
11005
11152
  app: appKey,
11006
11153
  actionType,
@@ -11123,7 +11270,11 @@ var listConnectionsPlugin = defineMethod({
11123
11270
  adaptPage: adaptZapierPage,
11124
11271
  defaultPageSize: DEFAULT_PAGE_SIZE
11125
11272
  },
11126
- run: async ({ imports, input }) => {
11273
+ run: async ({
11274
+ imports,
11275
+ input,
11276
+ annotate
11277
+ }) => {
11127
11278
  const resolveConnection = imports.connections.resolveConnection;
11128
11279
  const api = imports.api;
11129
11280
  const getVersionedImplementationId = imports.manifest.getVersionedImplementationId;
@@ -11138,7 +11289,7 @@ var listConnectionsPlugin = defineMethod({
11138
11289
  if (appKey) {
11139
11290
  const implementationId = await getVersionedImplementationId(appKey);
11140
11291
  if (implementationId) {
11141
- setMethodMetadata({ selectedApi: implementationId });
11292
+ annotate({ selectedApi: implementationId });
11142
11293
  const [versionlessSelectedApi] = splitVersionedKey(implementationId);
11143
11294
  searchParams.app_key = versionlessSelectedApi;
11144
11295
  } else {
@@ -11654,12 +11805,12 @@ var getConnectionStartUrlPlugin = defineMethod({
11654
11805
  outputSchema: GetConnectionStartUrlItemSchema,
11655
11806
  output: "item",
11656
11807
  resolvers: { app: appKeyResolver },
11657
- run: async ({ imports, input }) => {
11808
+ run: async ({ imports, input, annotate }) => {
11658
11809
  const api = imports.api;
11659
11810
  const getVersionedImplementationId = imports.manifest.getVersionedImplementationId;
11660
11811
  const versionedKey = await getVersionedImplementationId(input.app);
11661
11812
  const selectedApi = versionedKey ? versionedKey.split("@")[0] : input.app;
11662
- setMethodMetadata({ selectedApi });
11813
+ annotate({ selectedApi });
11663
11814
  const response = await api.post(
11664
11815
  START_PATH,
11665
11816
  { selected_api: selectedApi },
@@ -11718,12 +11869,12 @@ var waitForNewConnectionPlugin = defineMethod({
11718
11869
  outputSchema: WaitForNewConnectionItemSchema,
11719
11870
  output: "item",
11720
11871
  resolvers: { app: appKeyResolver },
11721
- run: async ({ imports, input }) => {
11872
+ run: async ({ imports, input, annotate }) => {
11722
11873
  const api = imports.api;
11723
11874
  const getVersionedImplementationId = imports.manifest.getVersionedImplementationId;
11724
11875
  const versionedKey = await getVersionedImplementationId(input.app);
11725
11876
  const appKey = versionedKey ? versionedKey.split("@")[0] : input.app;
11726
- setMethodMetadata({ selectedApi: appKey });
11877
+ annotate({ selectedApi: appKey });
11727
11878
  try {
11728
11879
  const top = await api.poll(CONNECTIONS_PATH, {
11729
11880
  searchParams: {
@@ -11841,11 +11992,11 @@ var createConnectionPlugin = defineMethod({
11841
11992
  ]
11842
11993
  })
11843
11994
  }),
11844
- run: async ({ imports, input }) => {
11995
+ run: async ({ imports, input, annotate }) => {
11845
11996
  const { data: start2 } = await imports.getConnectionStartUrl({
11846
11997
  app: input.app
11847
11998
  });
11848
- setMethodMetadata({ selectedApi: start2.app });
11999
+ annotate({ selectedApi: start2.app });
11849
12000
  console.error(
11850
12001
  `
11851
12002
  Open this URL to complete the connection:
@@ -12100,6 +12251,10 @@ var triggerInboxItemFormatter = defineFormatter({
12100
12251
 
12101
12252
  // src/plugins/triggers/shared.ts
12102
12253
  var triggerCategories = ["trigger"];
12254
+ function deriveReadOperation() {
12255
+ const annotations = { operationType: "read" };
12256
+ return { ...annotations };
12257
+ }
12103
12258
 
12104
12259
  // src/plugins/triggers/utils.ts
12105
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;
@@ -12145,6 +12300,7 @@ var createTriggerInboxPlugin = defineMethod({
12145
12300
  outputSchema: TriggerInboxItemSchema,
12146
12301
  output: "item",
12147
12302
  formatter: triggerInboxItemFormatter,
12303
+ annotator: deriveReadOperation,
12148
12304
  // actionKeyResolver and inputsResolver depend on actionType, which is always
12149
12305
  // "read" for triggers. Pin it as a constant resolver so it's seeded into
12150
12306
  // resolvedParams without polluting the user-facing schema (where it would
@@ -12249,6 +12405,7 @@ var ensureTriggerInboxPlugin = defineMethod({
12249
12405
  outputSchema: TriggerInboxItemSchema,
12250
12406
  output: "item",
12251
12407
  formatter: triggerInboxItemFormatter,
12408
+ annotator: deriveReadOperation,
12252
12409
  // actionKeyResolver and inputsResolver depend on actionType, which is always
12253
12410
  // "read" for triggers. Pin it as a constant resolver so it's seeded into
12254
12411
  // resolvedParams without polluting the user-facing schema.
@@ -13553,6 +13710,7 @@ var listTriggerInputFieldsPlugin = defineMethod({
13553
13710
  outputSchema: RootFieldItemSchema,
13554
13711
  output: { type: "list", defaultPageSize: DEFAULT_PAGE_SIZE },
13555
13712
  formatter: rootFieldItemFormatter,
13713
+ annotator: deriveReadOperation,
13556
13714
  // actionKeyResolver and inputsAllOptionalResolver depend on actionType. Pin it
13557
13715
  // to "read" so they resolve correctly without the user setting it.
13558
13716
  resolvers: {
@@ -13599,6 +13757,7 @@ var listTriggerInputFieldChoicesPlugin = defineMethod({
13599
13757
  outputSchema: InputFieldChoiceItemSchema,
13600
13758
  output: { type: "list", defaultPageSize: DEFAULT_PAGE_SIZE },
13601
13759
  formatter: inputFieldChoiceItemFormatter,
13760
+ annotator: deriveReadOperation,
13602
13761
  resolvers: {
13603
13762
  app: appKeyResolver,
13604
13763
  action: actionKeyResolver,
@@ -13642,6 +13801,7 @@ var getTriggerInputFieldsSchemaPlugin = defineMethod({
13642
13801
  // Passthrough: getActionInputFieldsSchema already returns `{ data }`, so
13643
13802
  // `output: "raw"` surfaces that envelope unchanged.
13644
13803
  output: "raw",
13804
+ annotator: deriveReadOperation,
13645
13805
  resolvers: {
13646
13806
  app: appKeyResolver,
13647
13807
  action: actionKeyResolver,
@@ -14759,6 +14919,14 @@ function buildMethodCalledEvent(data, context = {}) {
14759
14919
  }
14760
14920
 
14761
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
+ }
14762
14930
  function computeArgumentCount(args) {
14763
14931
  if (args.length === 1) {
14764
14932
  const arg0 = args[0];
@@ -14769,9 +14937,18 @@ function computeArgumentCount(args) {
14769
14937
  return args.filter((a) => a !== void 0).length;
14770
14938
  }
14771
14939
  function makeMethodEndHook(emitMethodCalled) {
14772
- return ({ methodName, args, isPaginated, depth, durationMs, error }) => {
14773
- if (depth > 0) return;
14774
- 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);
14775
14952
  emitMethodCalled({
14776
14953
  method_name: methodName,
14777
14954
  execution_duration_ms: durationMs,
@@ -14780,13 +14957,34 @@ function makeMethodEndHook(emitMethodCalled) {
14780
14957
  error_type: error?.constructor.name ?? null,
14781
14958
  argument_count: computeArgumentCount(args),
14782
14959
  is_paginated: isPaginated,
14783
- selected_api: metadata?.selectedApi ?? null,
14784
- operation_type: metadata?.operationType ?? null,
14785
- operation_key: metadata?.operationKey ?? null
14960
+ selected_api: metadata.selectedApi ?? null,
14961
+ operation_type: metadata.operationType ?? null,
14962
+ operation_key: metadata.operationKey ?? null
14786
14963
  });
14787
14964
  };
14788
14965
  }
14789
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
+
14790
14988
  // src/plugins/eventEmission/index.ts
14791
14989
  var TELEMETRY_EMIT_TIMEOUT_MILLISECONDS = 300;
14792
14990
  var registeredListeners = {};
@@ -15187,7 +15385,8 @@ var zapierSdkPlugin = definePlugin({
15187
15385
  connectionsPlugin,
15188
15386
  capabilitiesPlugin,
15189
15387
  eventEmissionPlugin,
15190
- eventEmissionHookPlugin
15388
+ eventEmissionHookPlugin,
15389
+ operationAnnotatorPlugin
15191
15390
  ],
15192
15391
  exports: [
15193
15392
  // The registry reporter: previously synthesized by the legacy merge,
@@ -15669,6 +15868,7 @@ exports.manifestPlugin = manifestPlugin;
15669
15868
  exports.manifestPluginRef = manifestPluginRef;
15670
15869
  exports.omitExports = omitExports;
15671
15870
  exports.openEnum = openEnum;
15871
+ exports.operationAnnotatorPlugin = operationAnnotatorPlugin;
15672
15872
  exports.parseConcurrencyEnvVar = parseConcurrencyEnvVar;
15673
15873
  exports.readManifestFromFile = readManifestFromFile;
15674
15874
  exports.registryPlugin = registryPlugin;