@zapier/zapier-sdk 0.98.0 → 0.99.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -35,6 +35,30 @@ function canonicalInputSchema(schema) {
35
35
  }
36
36
  return schema;
37
37
  }
38
+ function unwrapSchema(schema) {
39
+ let inner = schema;
40
+ let required = true;
41
+ for (; ; ) {
42
+ if (inner instanceof zod.z.ZodOptional || inner instanceof zod.z.ZodDefault) {
43
+ required = false;
44
+ inner = inner.unwrap();
45
+ } else if (inner instanceof zod.z.ZodNullable) {
46
+ inner = inner.unwrap();
47
+ } else {
48
+ break;
49
+ }
50
+ }
51
+ return { inner, required };
52
+ }
53
+ function objectShapeOf(schema) {
54
+ const canonical = canonicalInputSchema(schema);
55
+ if (!canonical) return void 0;
56
+ const { inner } = unwrapSchema(canonical);
57
+ if (inner instanceof zod.z.ZodObject) {
58
+ return inner.shape;
59
+ }
60
+ return void 0;
61
+ }
38
62
  function withPositional(schema) {
39
63
  Object.assign(schema._zod.def, {
40
64
  positionalMeta: { positional: true }
@@ -551,6 +575,117 @@ function createValidator(schema, { adaptError } = {}) {
551
575
  };
552
576
  }
553
577
  var validateOptions = (schema, options, { adaptError } = {}) => parseOrThrow(schema, options, { adaptError });
578
+ var CallFrameworkOptionsSchema = zod.z.object({
579
+ /** Page to fetch. Opaque to kitcore: the head's API defines the format. */
580
+ cursor: zod.z.string().optional(),
581
+ /** Items per page. */
582
+ pageSize: zod.z.number().int().min(1).optional(),
583
+ /** Stop after this many items, across pages. */
584
+ maxItems: zod.z.number().int().min(0).optional(),
585
+ /** Bypass output validation for this one call. */
586
+ skipOutputDataValidation: zod.z.boolean().optional()
587
+ });
588
+ var ITEM_FRAMEWORK_OPTIONS = {
589
+ claims: ["skipOutputDataValidation"],
590
+ injects: []
591
+ };
592
+ var LIST_FRAMEWORK_OPTIONS = {
593
+ claims: ["cursor", "pageSize", "maxItems", "skipOutputDataValidation"],
594
+ injects: ["cursor", "pageSize"]
595
+ };
596
+ var PAGE_FRAMEWORK_OPTIONS = {
597
+ claims: ["cursor", "pageSize", "maxItems"],
598
+ injects: ["cursor", "pageSize", "maxItems"]
599
+ };
600
+ var NO_FRAMEWORK_OPTIONS = {
601
+ claims: [],
602
+ injects: []
603
+ };
604
+ function isRecord(value) {
605
+ return typeof value === "object" && value !== null && !Array.isArray(value);
606
+ }
607
+ function strictlyRefused(error, claims) {
608
+ const refused = /* @__PURE__ */ new Set();
609
+ for (const issue of error.issues) {
610
+ if (issue.code !== "unrecognized_keys" || issue.path.length > 0) continue;
611
+ for (const key of issue.keys) {
612
+ if (claims.includes(key)) refused.add(key);
613
+ }
614
+ }
615
+ return [...refused];
616
+ }
617
+ function withoutKeys(options, keys) {
618
+ const next = {};
619
+ for (const [key, value] of Object.entries(options)) {
620
+ if (!keys.includes(key)) next[key] = value;
621
+ }
622
+ return next;
623
+ }
624
+ function parseCallOptions(options, {
625
+ schema,
626
+ policy = NO_FRAMEWORK_OPTIONS,
627
+ adaptError
628
+ } = {}) {
629
+ const claims = policy.claims;
630
+ const call = isRecord(options) ? options : void 0;
631
+ let framework = {};
632
+ if (call && claims.length > 0) {
633
+ const present = {};
634
+ for (const key of claims) {
635
+ if (key in call) present[key] = call[key];
636
+ }
637
+ framework = parseOrThrow2(CallFrameworkOptionsSchema, present, adaptError);
638
+ }
639
+ if (!schema) return { framework, domain: options, supplied: /* @__PURE__ */ new Set() };
640
+ const first = schema.safeParse(options);
641
+ if (first.success) {
642
+ return { framework, domain: first.data, supplied: /* @__PURE__ */ new Set() };
643
+ }
644
+ const refused = call ? strictlyRefused(first.error, claims) : [];
645
+ if (refused.length === 0) throw toCoreError(first.error, options, adaptError);
646
+ const retry = schema.safeParse(withoutKeys(call, refused));
647
+ if (!retry.success) {
648
+ throw toCoreError(retry.error, options, adaptError);
649
+ }
650
+ return { framework, domain: retry.data, supplied: new Set(refused) };
651
+ }
652
+ function mergeCallOptions({
653
+ framework,
654
+ domain
655
+ }) {
656
+ const claimed = Object.entries(framework);
657
+ if (!isRecord(domain) || claimed.length === 0) return domain;
658
+ return { ...domain, ...Object.fromEntries(claimed) };
659
+ }
660
+ function withheldFromRun(policy) {
661
+ return new Set(policy.claims.filter((key) => !policy.injects.includes(key)));
662
+ }
663
+ function stripFrameworkOnlyOptions(options, withheld) {
664
+ if (withheld.size === 0 || !isRecord(options)) return options;
665
+ const entries = Object.entries(options);
666
+ if (!entries.some(([key]) => withheld.has(key))) return options;
667
+ return Object.fromEntries(entries.filter(([key]) => !withheld.has(key)));
668
+ }
669
+ function parseOrThrow2(schema, input, adaptError) {
670
+ const result = schema.safeParse(input);
671
+ if (result.success) return result.data;
672
+ throw toCoreError(result.error, input, adaptError);
673
+ }
674
+ function toCoreError(error, input, adaptError) {
675
+ const messages = error.issues.map((issue) => {
676
+ const path = issue.path.length > 0 ? issue.path.join(".") : "input";
677
+ return `${path}: ${issue.message}`;
678
+ });
679
+ return createCoreError(
680
+ {
681
+ code: CoreErrorCode.Validation,
682
+ message: `Validation failed:
683
+ ${messages.join("\n ")}`,
684
+ details: { zodErrors: error.issues, input }
685
+ },
686
+ adaptError
687
+ );
688
+ }
554
689
  function createAsyncContext() {
555
690
  let store = null;
556
691
  try {
@@ -732,7 +867,15 @@ function normalizeError(error, adaptError) {
732
867
  );
733
868
  }
734
869
  function createFunction(coreFn, options) {
735
- const { sdk, schema, name, annotator, getDeprecation, getStability } = options;
870
+ const {
871
+ sdk,
872
+ schema,
873
+ name,
874
+ annotator,
875
+ frameworkOptions,
876
+ getDeprecation,
877
+ getStability
878
+ } = options;
736
879
  const functionName = name || coreFn.name;
737
880
  const namedFunctions = {
738
881
  [functionName]: async function(callOptions) {
@@ -768,25 +911,15 @@ function createFunction(coreFn, options) {
768
911
  };
769
912
  hooks?.onMethodStart?.({ ...hookBase });
770
913
  try {
771
- let result;
772
- if (schema) {
773
- const validatedOptions = validateOptions(
774
- schema,
775
- normalizedOptions,
776
- {
777
- adaptError
778
- }
779
- );
780
- result = await coreFn(
781
- {
782
- ...normalizedOptions,
783
- ...validatedOptions
784
- },
785
- context
786
- );
787
- } else {
788
- result = await coreFn(normalizedOptions, context);
789
- }
914
+ const parsed = parseCallOptions(normalizedOptions, {
915
+ schema,
916
+ policy: frameworkOptions,
917
+ adaptError
918
+ });
919
+ const result = await coreFn(
920
+ mergeCallOptions(parsed),
921
+ context
922
+ );
790
923
  hooks?.onMethodEnd?.({
791
924
  ...hookBase,
792
925
  durationMs: Date.now() - startTime
@@ -907,7 +1040,7 @@ function createPageFunction(coreFn, {
907
1040
  `${functionName}: paginated result must be exactly { data: TItem[], nextCursor? } (produced by the handler or its \`adaptPage\`); got keys [${page && typeof page === "object" ? Object.keys(page).join(", ") : typeof page}]. If the handler returns a raw shape, set \`adaptPage\` to translate it; if \`adaptPage\` already runs, it must return only \`data\`/\`nextCursor\`.`
908
1041
  );
909
1042
  }
910
- return finalizePage ? finalizePage(page) : page;
1043
+ return finalizePage ? finalizePage(page, options) : page;
911
1044
  } catch (error) {
912
1045
  throw normalizeError(
913
1046
  error,
@@ -927,6 +1060,7 @@ function createPaginatedFunction(coreFn, options) {
927
1060
  adaptPage,
928
1061
  annotator,
929
1062
  finalizePage,
1063
+ frameworkOptions,
930
1064
  getDeprecation,
931
1065
  getStability
932
1066
  } = options;
@@ -970,10 +1104,13 @@ function createPaginatedFunction(coreFn, options) {
970
1104
  };
971
1105
  hooks?.onMethodStart?.({ ...hookBase });
972
1106
  try {
973
- const validatedOptions = {
974
- ...normalizedOptions,
975
- ...schema ? createValidator(schema, { adaptError })(normalizedOptions) : normalizedOptions
976
- };
1107
+ const validatedOptions = mergeCallOptions(
1108
+ parseCallOptions(normalizedOptions, {
1109
+ schema,
1110
+ policy: frameworkOptions,
1111
+ adaptError
1112
+ })
1113
+ );
977
1114
  const pageSize = validatedOptions.pageSize ?? defaultPageSize;
978
1115
  const optimizedOptions = {
979
1116
  ...validatedOptions,
@@ -1097,6 +1234,10 @@ function createPaginatedPluginMethod(sdk, config) {
1097
1234
  sdk,
1098
1235
  schema: inputSchema,
1099
1236
  name,
1237
+ // The page loop reads the page controls out of the call object, so a
1238
+ // handler's schema does not have to declare them. It reads nothing else:
1239
+ // no legacy handler honors the caller's output skip.
1240
+ frameworkOptions: PAGE_FRAMEWORK_OPTIONS,
1100
1241
  defaultPageSize,
1101
1242
  adaptPage
1102
1243
  });
@@ -1338,6 +1479,7 @@ function buildPluginStack(head, callerLabel) {
1338
1479
  };
1339
1480
  return stack;
1340
1481
  }
1482
+ var CONTEXT = Symbol.for("kitcore.context");
1341
1483
  function parseId(id) {
1342
1484
  const at = id.lastIndexOf("/");
1343
1485
  return at === -1 ? { name: id, namespace: void 0 } : { name: id.slice(at + 1), namespace: id.slice(0, at) };
@@ -1442,7 +1584,12 @@ function collectDynamicMembers(members) {
1442
1584
  };
1443
1585
  });
1444
1586
  }
1445
- function defineMethod(config) {
1587
+ function defineMethod(configOrRef, refConfig) {
1588
+ const config = refConfig === void 0 ? configOrRef : {
1589
+ ...refConfig,
1590
+ name: configOrRef.name,
1591
+ namespace: configOrRef.namespace
1592
+ };
1446
1593
  const deps = normalizeImports(config.imports);
1447
1594
  return {
1448
1595
  pluginType: "method",
@@ -1465,8 +1612,27 @@ function defineMethod(config) {
1465
1612
  run: config.run
1466
1613
  };
1467
1614
  }
1468
- function defineMethodOverride(config) {
1469
- const { target, namespace, ...rest } = config;
1615
+ var OVERRIDABLE = [
1616
+ "description",
1617
+ "categories",
1618
+ "itemType",
1619
+ "returnType",
1620
+ "packages",
1621
+ "experimental",
1622
+ "deprecation",
1623
+ "supportsJsonOutput"
1624
+ ];
1625
+ function assertOverridable(target, fields) {
1626
+ const offered = Object.keys(fields).filter(
1627
+ (key) => !OVERRIDABLE.includes(key)
1628
+ );
1629
+ if (offered.length === 0) return;
1630
+ throw new Error(
1631
+ `defineOverride("${target}"): cannot override ${offered.join(", ")}. An override changes how a surface presents a method, never what it does. The method's declared type is fixed at \`defineMethod\` and nothing re-checks it afterwards, so patching behavior here would let a call fail against a contract its own return type says it satisfies. Overridable: ${OVERRIDABLE.join(", ")}.`
1632
+ );
1633
+ }
1634
+ function buildOverride(target, namespace, fields) {
1635
+ assertOverridable(target, fields);
1470
1636
  return {
1471
1637
  pluginType: "method-override",
1472
1638
  name: `override:${target}`,
@@ -1474,12 +1640,34 @@ function defineMethodOverride(config) {
1474
1640
  target,
1475
1641
  imports: [],
1476
1642
  importBindings: [],
1477
- meta: collectLeafMeta(rest)
1643
+ meta: collectLeafMeta(fields)
1478
1644
  };
1479
1645
  }
1646
+ function defineOverride(ref, config = {}) {
1647
+ const { namespace, ...fields } = config;
1648
+ return buildOverride(ref.id, namespace, fields);
1649
+ }
1650
+ function defineMethodOverride(config) {
1651
+ logDeprecation(
1652
+ "defineMethodOverride({ target }) is deprecated. Use defineOverride(method, { ... }), which takes the method or its declareMethod stand-in."
1653
+ );
1654
+ const { target, namespace, ...fields } = config;
1655
+ return buildOverride(target, namespace, fields);
1656
+ }
1657
+ function assertRequirementPaths(requirements) {
1658
+ if (!requirements) return;
1659
+ for (const requirement of requirements) {
1660
+ if (typeof requirement !== "string" && requirement.length === 0) {
1661
+ throw new Error(
1662
+ "defineResolver: a requireParameters path must name at least one segment. An empty path names no parameter, and the engine would read it as already satisfied."
1663
+ );
1664
+ }
1665
+ }
1666
+ }
1480
1667
  function defineResolver(config) {
1481
1668
  const deps = normalizeImports(config.imports);
1482
1669
  const base = { imports: deps.plugins, importBindings: deps.bindings };
1670
+ assertRequirementPaths(config.requireParameters);
1483
1671
  const gates = {
1484
1672
  requireParameters: config.requireParameters
1485
1673
  };
@@ -1560,21 +1748,26 @@ function declareMethod(config) {
1560
1748
  }
1561
1749
  };
1562
1750
  }
1563
- function defineProperty(config) {
1564
- const deps = normalizeImports(config.imports);
1751
+ function defineProperty(config, refConfig) {
1752
+ const cfg = refConfig === void 0 ? config : {
1753
+ ...refConfig,
1754
+ name: config.name,
1755
+ namespace: config.namespace
1756
+ };
1757
+ const deps = normalizeImports(cfg.imports);
1565
1758
  return {
1566
1759
  pluginType: "property",
1567
- name: config.name,
1568
- namespace: config.namespace,
1569
- id: makeId(config.name, config.namespace),
1760
+ name: cfg.name,
1761
+ namespace: cfg.namespace,
1762
+ id: makeId(cfg.name, cfg.namespace),
1570
1763
  imports: deps.plugins,
1571
1764
  importBindings: deps.bindings,
1572
- setup: config.setup,
1573
- dispose: config.dispose,
1574
- value: config.value,
1575
- get: config.get,
1576
- meta: collectLeafMeta(config),
1577
- dynamicMembers: collectDynamicMembers(config.dynamicMembers)
1765
+ setup: cfg.setup,
1766
+ dispose: cfg.dispose,
1767
+ value: cfg.value,
1768
+ get: cfg.get,
1769
+ meta: collectLeafMeta(cfg),
1770
+ dynamicMembers: collectDynamicMembers(cfg.dynamicMembers)
1578
1771
  };
1579
1772
  }
1580
1773
  function declareProperty(config) {
@@ -1869,6 +2062,34 @@ function collectSurfaceProjection(context, formatterSdk) {
1869
2062
  }
1870
2063
  return { meta, formatters, resolvers, positional, skipInputValidation };
1871
2064
  }
2065
+ var REGISTRY_CACHE = Symbol.for("kitcore.registryCache");
2066
+ function freezeContainers(registry) {
2067
+ Object.freeze(registry.functions);
2068
+ for (const category of registry.categories) {
2069
+ Object.freeze(category.functions);
2070
+ Object.freeze(category);
2071
+ }
2072
+ Object.freeze(registry.categories);
2073
+ return Object.freeze(registry);
2074
+ }
2075
+ function getCachedRegistry(context, packageFilter) {
2076
+ const key = packageFilter ?? "";
2077
+ const caching = context;
2078
+ let byFilter = caching[REGISTRY_CACHE];
2079
+ if (!byFilter) {
2080
+ byFilter = /* @__PURE__ */ new Map();
2081
+ caching[REGISTRY_CACHE] = byFilter;
2082
+ }
2083
+ let registry = byFilter.get(key);
2084
+ if (!registry) {
2085
+ registry = freezeContainers(buildSurfaceRegistry(context, packageFilter));
2086
+ byFilter.set(key, registry);
2087
+ }
2088
+ return registry;
2089
+ }
2090
+ function invalidateRegistryCache(context) {
2091
+ delete context[REGISTRY_CACHE];
2092
+ }
1872
2093
  function buildSurfaceRegistry(context, packageFilter) {
1873
2094
  const surface = {};
1874
2095
  for (const [binding, id] of Object.entries(context.surface)) {
@@ -1876,9 +2097,11 @@ function buildSurfaceRegistry(context, packageFilter) {
1876
2097
  if (!entry || entry.pluginType === "aggregate") continue;
1877
2098
  surface[binding] = entry.pluginType === "property" && entry.getValue ? entry.getValue() : entry.value;
1878
2099
  }
2100
+ const projection = collectSurfaceProjection(context, surface);
2101
+ Object.assign(projection.meta, context.meta);
1879
2102
  return buildRegistry({
1880
2103
  sdk: surface,
1881
- ...collectSurfaceProjection(context, surface),
2104
+ ...projection,
1882
2105
  packageFilter
1883
2106
  });
1884
2107
  }
@@ -1897,9 +2120,9 @@ var getRegistryPlugin = defineMethod({
1897
2120
  namespace: "kitcore",
1898
2121
  imports: [dangerousContextPlugin],
1899
2122
  inputSchema: zod.z.object({ package: zod.z.string().optional() }).optional(),
1900
- run: ({ imports, input }) => buildSurfaceRegistry(imports.context, input?.package)
2123
+ run: ({ imports, input }) => getCachedRegistry(imports.context, input?.package)
1901
2124
  });
1902
- function isRecord(value) {
2125
+ function isRecord2(value) {
1903
2126
  return typeof value === "object" && value !== null && !Array.isArray(value);
1904
2127
  }
1905
2128
  function diffDroppedPaths(raw, parsed, prefix = "") {
@@ -1922,7 +2145,7 @@ function walkDroppedPaths(raw, parsed, prefix, out) {
1922
2145
  }
1923
2146
  return;
1924
2147
  }
1925
- if (isRecord(raw) && isRecord(parsed)) {
2148
+ if (isRecord2(raw) && isRecord2(parsed)) {
1926
2149
  for (const key of Object.keys(raw)) {
1927
2150
  const path = prefix ? `${prefix}.${key}` : key;
1928
2151
  if (!(key in parsed)) {
@@ -1934,7 +2157,22 @@ function walkDroppedPaths(raw, parsed, prefix, out) {
1934
2157
  return;
1935
2158
  }
1936
2159
  }
1937
- function parseOutput(schema, value, policy, locator) {
2160
+ var SKIP_OUTPUT_DATA_VALIDATION = "skipOutputDataValidation";
2161
+ function readSkipOutputDataValidation(options) {
2162
+ return isRecord2(options) && options[SKIP_OUTPUT_DATA_VALIDATION] === true;
2163
+ }
2164
+ function resolveValidatingSchema(policy) {
2165
+ if (policy.skipOutputValidation || policy.skippedByCaller) return void 0;
2166
+ return policy.outputSchema;
2167
+ }
2168
+ function shouldReport(policy) {
2169
+ return policy.skippedByCaller === true && policy.outputSchema !== void 0 && !policy.skipOutputValidation;
2170
+ }
2171
+ function parseOutput(schema, value, policy, {
2172
+ locator,
2173
+ hint,
2174
+ callerCanSkip = true
2175
+ } = {}) {
1938
2176
  const result = schema.safeParse(value);
1939
2177
  if (result.success) return result.data;
1940
2178
  const issues = result.error.issues.map((issue) => {
@@ -1949,57 +2187,134 @@ function parseOutput(schema, value, policy, locator) {
1949
2187
  message: `Output validation failed${subject}${at}:
1950
2188
  ${issues.join("\n ")}
1951
2189
 
1952
- The response does not match the method's \`outputSchema\`. Correct the schema, or set \`skipOutputValidation: true\` on the method to pass the response through unvalidated.`,
2190
+ ` + (hint ? `${hint}
2191
+
2192
+ ` : "") + `The response does not match the method's \`outputSchema\`. Correct the schema, or set \`skipOutputValidation: true\` on the method to pass the response through unvalidated.` + (callerCanSkip ? ` A caller who cannot change the method can pass \`skipOutputDataValidation: true\` with the input to bypass this one call.` : ``),
1953
2193
  details: { zodErrors: result.error.issues, output: value }
1954
2194
  },
1955
2195
  policy.adaptError
1956
2196
  );
1957
2197
  }
1958
2198
  function applyItemOutputPolicy(result, policy) {
1959
- const schema = policy.outputSchema;
1960
- if (!schema || policy.skipOutputValidation) return result;
1961
- if (!isRecord(result) || !("data" in result)) return result;
2199
+ const schema = resolveValidatingSchema(policy);
2200
+ const report = shouldReport(policy);
2201
+ if (!schema && !report) return result;
2202
+ if (!isRecord2(result) || !("data" in result)) return result;
2203
+ if (!schema) {
2204
+ return {
2205
+ ...result,
2206
+ meta: withOutputValidation(result.meta, { skipped: true })
2207
+ };
2208
+ }
1962
2209
  const data = parseOutput(schema, result.data, policy);
2210
+ const validation = buildValidatedReport({
2211
+ policy,
2212
+ before: result.data,
2213
+ after: data
2214
+ });
1963
2215
  const next = { ...result, data };
1964
- if (policy.includeOutputValidationDroppedPaths) {
1965
- const droppedPaths = diffDroppedPaths(result.data, data);
1966
- if (droppedPaths.length > 0) {
1967
- next.meta = withOutputValidation(result.meta, droppedPaths);
1968
- }
1969
- }
2216
+ if (validation) next.meta = withOutputValidation(result.meta, validation);
1970
2217
  return next;
1971
2218
  }
1972
- function withOutputValidation(existing, droppedPaths) {
1973
- const base = isRecord(existing) ? existing : {};
1974
- return { ...base, outputValidation: { droppedPaths } };
2219
+ function applyRawOutputPolicy(result, policy) {
2220
+ const schema = resolveValidatingSchema(policy);
2221
+ if (!schema) return result;
2222
+ const looksLikeEnvelope = isRecord2(result) && "data" in result;
2223
+ parseOutput(schema, result, policy, {
2224
+ hint: looksLikeEnvelope ? 'This returned a `{ data }` envelope, and with no `output` mode the schema is matched against the WHOLE return. Did you mean `output: "item"` (or `"list"`)?' : void 0,
2225
+ // Raw reserves nothing in the caller's call object, so there is no per-call
2226
+ // skip to point at. Offering one would be advice that does nothing.
2227
+ callerCanSkip: false
2228
+ });
2229
+ return result;
2230
+ }
2231
+ function withOutputValidation(existing, outputDataValidation) {
2232
+ const base = isRecord2(existing) ? existing : {};
2233
+ const deprecated = outputDataValidation.skipped === false && outputDataValidation.droppedPaths ? {
2234
+ outputValidation: { droppedPaths: outputDataValidation.droppedPaths }
2235
+ } : {};
2236
+ return { ...base, outputDataValidation, ...deprecated };
2237
+ }
2238
+ function buildValidatedReport({
2239
+ policy,
2240
+ before,
2241
+ after
2242
+ }) {
2243
+ const droppedPaths = policy.includeOutputValidationDroppedPaths ? diffDroppedPaths(before, after) : [];
2244
+ if (droppedPaths.length === 0) return void 0;
2245
+ return {
2246
+ skipped: false,
2247
+ droppedPaths,
2248
+ instruction: `Some fields were removed from \`data\` by output validation. To receive the raw, unvalidated result instead, set \`${SKIP_OUTPUT_DATA_VALIDATION}\`.`
2249
+ };
1975
2250
  }
1976
2251
  function applyListOutputPolicy(page, policy) {
1977
- const schema = policy.outputSchema;
1978
- if (!schema || policy.skipOutputValidation) return page;
2252
+ const schema = resolveValidatingSchema(policy);
2253
+ const report = shouldReport(policy);
2254
+ if (!schema && !report) return page;
2255
+ if (!schema) {
2256
+ return {
2257
+ ...page,
2258
+ meta: withOutputValidation(page.meta, { skipped: true })
2259
+ };
2260
+ }
1979
2261
  const data = page.data.map(
1980
- (item, index) => parseOutput(schema, item, policy, `data[${index}]`)
2262
+ (item, index) => parseOutput(schema, item, policy, { locator: `data[${index}]` })
1981
2263
  );
2264
+ const validation = buildValidatedReport({
2265
+ policy,
2266
+ before: page.data,
2267
+ after: data
2268
+ });
1982
2269
  const next = { ...page, data };
1983
- if (policy.includeOutputValidationDroppedPaths) {
1984
- const droppedPaths = diffDroppedPaths(page.data, data);
1985
- if (droppedPaths.length > 0) {
1986
- next.meta = { ...page.meta, outputValidation: { droppedPaths } };
1987
- }
1988
- }
2270
+ if (validation)
2271
+ next.meta = withOutputValidation(
2272
+ page.meta,
2273
+ validation
2274
+ );
1989
2275
  return next;
1990
2276
  }
1991
2277
  var FRAMEWORK_CONFIGURATION_IDS = /* @__PURE__ */ new Set([
1992
2278
  CORE_OPTIONS_ID
1993
2279
  ]);
2280
+ function isPromiseLike(value) {
2281
+ return value !== null && typeof value === "object" && typeof value.then === "function";
2282
+ }
1994
2283
  function normalizeOutput(output) {
1995
2284
  if (output === void 0) return { type: "raw" };
1996
2285
  if (typeof output === "string") return { type: output };
1997
2286
  return output;
1998
2287
  }
1999
- var CONTEXT = Symbol.for("kitcore.context");
2000
2288
  function getContext(sdk) {
2001
2289
  return sdk[CONTEXT];
2002
2290
  }
2291
+ function assertDynamicMemberRoot(entry) {
2292
+ if (!entry.dynamicMembers?.length) return;
2293
+ const value = entry.getValue ? entry.getValue() : entry.value;
2294
+ if (typeof value === "object" && value !== null) return;
2295
+ throw new Error(
2296
+ `Property "${entry.name}" declares dynamicMembers, so its value must be an object when the SDK is built; got ${value === null ? "null" : typeof value}. Build the root in \`setup\` and return it from \`get\`, so members like "${entry.dynamicMembers[0].name}" are reportable from the first registry read.`
2297
+ );
2298
+ }
2299
+ function getRegistry(sdk, packageFilter) {
2300
+ if (typeof sdk !== "object" && typeof sdk !== "function" || sdk === null)
2301
+ throw createNoRegistryError();
2302
+ const context = getContext(sdk);
2303
+ if (context?.surface) return getCachedRegistry(context, packageFilter);
2304
+ const surfaced = sdk.getRegistry;
2305
+ if (typeof surfaced === "function") {
2306
+ return surfaced.call(
2307
+ sdk,
2308
+ void 0
2309
+ );
2310
+ }
2311
+ throw createNoRegistryError();
2312
+ }
2313
+ function createNoRegistryError() {
2314
+ return new Error(
2315
+ "getRegistry: sdk has no kitcore context and no surfaced getRegistry()."
2316
+ );
2317
+ }
2003
2318
  function isResolverRef(value) {
2004
2319
  return "ref" in value;
2005
2320
  }
@@ -2219,8 +2534,9 @@ function bindValue({
2219
2534
  frameworkOrigin = false
2220
2535
  }) {
2221
2536
  if (entry.pluginType === "property" && entry.getValue) {
2537
+ const getValue = entry.getValue;
2222
2538
  Object.defineProperty(target, key, {
2223
- get: entry.getValue,
2539
+ get: ctx ? () => getValue(ctx) : getValue,
2224
2540
  enumerable: true,
2225
2541
  configurable: true
2226
2542
  });
@@ -2504,22 +2820,16 @@ function runLegacyPass(descriptors, context) {
2504
2820
  Object.assign(context, contextRest);
2505
2821
  context.hooks = buildHooks(context.hooks, hooks);
2506
2822
  const exports = mirrorLegacyRootKeys(context, rootKeys, meta);
2823
+ for (const name of Object.keys(rootKeys)) context.surface[name] = name;
2507
2824
  if (!("getRegistry" in exports)) {
2508
- let getRegistry2 = function(options) {
2509
- const sdk = this ?? exports;
2510
- const projection = collectSurfaceProjection(context, sdk);
2511
- Object.assign(projection.meta, context.meta);
2512
- return buildRegistry({
2513
- sdk,
2514
- ...projection,
2515
- packageFilter: options?.package
2516
- });
2825
+ let getRegistry3 = function(options) {
2826
+ return getCachedRegistry(context, options?.package);
2517
2827
  };
2518
- exports.getRegistry = getRegistry2;
2828
+ exports.getRegistry = getRegistry3;
2519
2829
  plugins.getRegistry = {
2520
2830
  pluginType: "method",
2521
2831
  name: "getRegistry",
2522
- value: getRegistry2,
2832
+ value: getRegistry3,
2523
2833
  chain: []
2524
2834
  };
2525
2835
  }
@@ -2583,50 +2893,73 @@ function buildMethodEntries(descriptors, context, states) {
2583
2893
  const sdk = { context };
2584
2894
  const methodAnnotator = descriptor.annotator;
2585
2895
  const boundAnnotator = methodAnnotator ? (input) => methodAnnotator({ input }) : void 0;
2586
- const outputPolicy = () => {
2896
+ const outputPolicy = (callOptions) => {
2587
2897
  const core = resolveCoreOptions(context);
2588
2898
  return {
2589
2899
  outputSchema: descriptor.meta?.outputSchema,
2590
2900
  skipOutputValidation: descriptor.skipOutputValidation,
2901
+ skippedByCaller: readSkipOutputDataValidation(callOptions),
2591
2902
  includeOutputValidationDroppedPaths: core?.includeOutputValidationDroppedPaths,
2592
2903
  methodName: descriptor.name,
2593
2904
  adaptError: core?.adaptError
2594
2905
  };
2595
2906
  };
2907
+ const frameworkOptions = out.type === "list" ? LIST_FRAMEWORK_OPTIONS : ITEM_FRAMEWORK_OPTIONS;
2908
+ const withheld = withheldFromRun(frameworkOptions);
2596
2909
  if (out.type === "list") {
2597
2910
  entry.value = createPaginatedFunction(
2598
- fold(callRun),
2911
+ fold(
2912
+ (input, ctx) => callRun(stripFrameworkOnlyOptions(input, withheld), ctx)
2913
+ ),
2599
2914
  {
2600
2915
  sdk,
2601
2916
  schema: descriptor.inputSchema,
2602
2917
  name: descriptor.name,
2918
+ frameworkOptions,
2603
2919
  defaultPageSize: out.defaultPageSize,
2604
2920
  adaptPage: out.adaptPage,
2605
2921
  annotator: boundAnnotator,
2606
2922
  // Validate + strip each item against the item `outputSchema`
2607
2923
  // (item mode's sibling); dropped paths surface as `[].x` in the page's
2608
2924
  // `meta`, unioned across items.
2609
- finalizePage: (page) => applyListOutputPolicy(page, outputPolicy()),
2925
+ finalizePage: (page, callOptions) => applyListOutputPolicy(page, outputPolicy(callOptions)),
2610
2926
  getDeprecation: () => entry.meta?.deprecation,
2611
2927
  getStability: () => entry.meta ? normalizeStability(entry.meta) : void 0
2612
2928
  }
2613
2929
  );
2614
2930
  } else if (out.type === "item") {
2615
- const itemCore = async (input, ctx) => applyItemOutputPolicy(await callRun(input, ctx), outputPolicy());
2931
+ const itemCore = async (input, ctx) => applyItemOutputPolicy(
2932
+ await callRun(stripFrameworkOnlyOptions(input, withheld), ctx),
2933
+ outputPolicy(input)
2934
+ );
2616
2935
  entry.value = createFunction(
2617
2936
  fold(itemCore),
2618
2937
  {
2619
2938
  sdk,
2620
2939
  schema: descriptor.inputSchema,
2621
2940
  name: descriptor.name,
2941
+ frameworkOptions,
2622
2942
  annotator: boundAnnotator,
2623
2943
  getDeprecation: () => entry.meta?.deprecation,
2624
2944
  getStability: () => entry.meta ? normalizeStability(entry.meta) : void 0
2625
2945
  }
2626
2946
  );
2627
2947
  } else {
2948
+ const rawValidates = descriptor.meta?.outputSchema !== void 0 && !descriptor.skipOutputValidation;
2949
+ const validateRaw = (out2) => {
2950
+ const policy = outputPolicy(void 0);
2951
+ if (isPromiseLike(out2)) {
2952
+ return Promise.resolve(out2).then(
2953
+ (value) => applyRawOutputPolicy(value, policy)
2954
+ );
2955
+ }
2956
+ return applyRawOutputPolicy(out2, policy);
2957
+ };
2628
2958
  entry.value = createRawFunction(
2629
- (input, ctx) => fold(callRun)(input, ctx),
2959
+ (input, ctx) => {
2960
+ const out2 = fold(callRun)(input, ctx);
2961
+ return rawValidates ? validateRaw(out2) : out2;
2962
+ },
2630
2963
  {
2631
2964
  sdk,
2632
2965
  name: descriptor.name,
@@ -2758,9 +3091,14 @@ function buildEagerArtifacts(descriptors, context, states) {
2758
3091
  plugins[id] = {
2759
3092
  pluginType: "property",
2760
3093
  name: descriptor.name,
2761
- getValue: () => get({
2762
- imports: buildImports({ plugins, importBindings }),
2763
- state: states.get(id)
3094
+ getValue: (callContext) => get({
3095
+ imports: buildImports({
3096
+ plugins,
3097
+ importBindings,
3098
+ ctx: callContext
3099
+ }),
3100
+ state: states.get(id),
3101
+ callContext
2764
3102
  }),
2765
3103
  meta: descriptor.meta,
2766
3104
  dynamicMembers: descriptor.dynamicMembers
@@ -2774,6 +3112,7 @@ function buildEagerArtifacts(descriptors, context, states) {
2774
3112
  dynamicMembers: descriptor.dynamicMembers
2775
3113
  };
2776
3114
  }
3115
+ assertDynamicMemberRoot(plugins[id]);
2777
3116
  }
2778
3117
  recordDisposer();
2779
3118
  building.delete(id);
@@ -2997,34 +3336,29 @@ function addModelPlugin(sdk, plugin, options = {}) {
2997
3336
  }
2998
3337
  }
2999
3338
  function addPlugin(sdk, plugin, options) {
3000
- if (typeof plugin === "function") {
3001
- const record = sdk;
3002
- const contribution = applyPluginToSdk(
3003
- record,
3004
- plugin,
3005
- options ?? {}
3006
- );
3007
- const context = record[CONTEXT];
3008
- if (context) {
3009
- mirrorLegacyRootKeys(context, contribution.rootKeys, contribution.meta);
3010
- for (const name of Object.keys(contribution.rootKeys)) {
3011
- context.surface[name] = name;
3339
+ const record = sdk;
3340
+ const context = getContext(record);
3341
+ try {
3342
+ if (typeof plugin === "function") {
3343
+ const contribution = applyPluginToSdk(
3344
+ record,
3345
+ plugin,
3346
+ options ?? {}
3347
+ );
3348
+ if (context) {
3349
+ mirrorLegacyRootKeys(context, contribution.rootKeys, contribution.meta);
3350
+ for (const name of Object.keys(contribution.rootKeys)) {
3351
+ context.surface[name] = name;
3352
+ }
3012
3353
  }
3354
+ } else if (plugin.pluginType === "method-override") {
3355
+ applyMethodOverride(context, plugin);
3356
+ } else {
3357
+ addModelPlugin(record, plugin, options ?? {});
3013
3358
  }
3014
- return;
3015
- }
3016
- if (plugin.pluginType === "method-override") {
3017
- applyMethodOverride(
3018
- getContext(sdk),
3019
- plugin
3020
- );
3021
- return;
3359
+ } finally {
3360
+ if (context) invalidateRegistryCache(context);
3022
3361
  }
3023
- addModelPlugin(
3024
- sdk,
3025
- plugin,
3026
- options ?? {}
3027
- );
3028
3362
  }
3029
3363
  var CORE_SIGNAL_SYMBOL = Symbol.for("kitcore.signal");
3030
3364
  var CoreSignal = class extends Error {
@@ -3054,24 +3388,6 @@ var CoreCancelledSignal = class extends CoreSignal {
3054
3388
  function isCoreCancelledSignal(value) {
3055
3389
  return isCoreSignal(value) && value.code === "CANCELLED";
3056
3390
  }
3057
- function unwrap(schema) {
3058
- let inner = schema;
3059
- let required = true;
3060
- for (; ; ) {
3061
- if (inner instanceof zod.z.ZodOptional) {
3062
- required = false;
3063
- inner = inner._zod.def.innerType;
3064
- } else if (inner instanceof zod.z.ZodDefault) {
3065
- required = false;
3066
- inner = inner._zod.def.innerType;
3067
- } else if (inner instanceof zod.z.ZodNullable) {
3068
- inner = inner._zod.def.innerType;
3069
- } else {
3070
- break;
3071
- }
3072
- }
3073
- return { inner, required };
3074
- }
3075
3391
  function valueTypeOf(inner) {
3076
3392
  if (inner instanceof zod.z.ZodString) return "string";
3077
3393
  if (inner instanceof zod.z.ZodNumber) return "number";
@@ -3089,19 +3405,15 @@ function staticChoicesOf(inner) {
3089
3405
  }
3090
3406
  return void 0;
3091
3407
  }
3092
- function objectShape(schema) {
3093
- const canonical = canonicalInputSchema(schema);
3094
- const { inner } = canonical ? unwrap(canonical) : { inner: void 0 };
3095
- if (inner instanceof zod.z.ZodObject) {
3096
- return inner.shape;
3097
- }
3098
- return void 0;
3099
- }
3100
3408
  function topoOrder2(specs) {
3101
3409
  const byName = new Map(specs.map((s) => [s.name, s]));
3102
3410
  const placed = /* @__PURE__ */ new Set();
3103
3411
  const ordered = [];
3104
- const isReady = (spec) => spec.requires.every((r) => !byName.has(r) || placed.has(r));
3412
+ const topLevelNameOf = (r) => typeof r === "string" ? r : r.length === 1 && typeof r[0] === "string" ? r[0] : void 0;
3413
+ const isReady = (spec) => spec.requires.every((r) => {
3414
+ const name = topLevelNameOf(r);
3415
+ return name === void 0 || !byName.has(name) || placed.has(name);
3416
+ });
3105
3417
  for (; ; ) {
3106
3418
  const next = specs.find((s) => !placed.has(s.name) && isReady(s));
3107
3419
  if (!next) break;
@@ -3112,7 +3424,7 @@ function topoOrder2(specs) {
3112
3424
  return ordered;
3113
3425
  }
3114
3426
  function planParameters(entry) {
3115
- const shape = objectShape(entry.inputSchema);
3427
+ const shape = objectShapeOf(entry.inputSchema);
3116
3428
  const resolvers = entry.resolvers ?? {};
3117
3429
  const names = shape ? [
3118
3430
  ...Object.keys(shape),
@@ -3122,7 +3434,7 @@ function planParameters(entry) {
3122
3434
  ] : Object.keys(resolvers);
3123
3435
  const specs = names.map((name) => {
3124
3436
  const field = shape?.[name];
3125
- const { inner, required } = field ? unwrap(field) : { inner: void 0, required: false };
3437
+ const { inner, required } = field ? unwrapSchema(field) : { inner: void 0, required: false };
3126
3438
  const resolver = resolvers[name];
3127
3439
  return {
3128
3440
  name,
@@ -3765,9 +4077,13 @@ async function findNext(ctx, state, path = []) {
3765
4077
  const hasAskableRequired = children.some((c) => c.required && asksUser(c));
3766
4078
  for (const leaf of ordered) {
3767
4079
  const childPath = [...path, leaf.name];
3768
- if (!leaf.requires.every(
3769
- (r) => container[r] !== void 0 || getAtPath(state.resolved, [r]) !== void 0 || isSettled(state, [...path, r]) || isSettled(state, [r])
3770
- )) {
4080
+ if (!leaf.requires.every((r) => {
4081
+ if (typeof r !== "string") {
4082
+ if (getAtPath(state.resolved, [...r]) !== void 0) return true;
4083
+ return r.some((_, index) => isSettled(state, r.slice(0, index + 1)));
4084
+ }
4085
+ return container[r] !== void 0 || getAtPath(state.resolved, [r]) !== void 0 || isSettled(state, [...path, r]) || isSettled(state, [r]);
4086
+ })) {
3771
4087
  continue;
3772
4088
  }
3773
4089
  const inArrayItem = path.some((segment) => typeof segment === "number");
@@ -4207,7 +4523,7 @@ function projectMethod(entry) {
4207
4523
  }
4208
4524
  function createController(sdk) {
4209
4525
  function entryFor(method) {
4210
- const entry = sdk.getRegistry().functions.find((f) => f.name === method);
4526
+ const entry = getRegistry(sdk).functions.find((f) => f.name === method);
4211
4527
  if (!entry) throw new Error(`unknown method "${method}"`);
4212
4528
  return entry;
4213
4529
  }
@@ -4246,7 +4562,7 @@ function createController(sdk) {
4246
4562
  throw new Error(`invalid input for "${method}": ${detail}`);
4247
4563
  };
4248
4564
  const listMethods = () => ({
4249
- data: sdk.getRegistry().functions.map(projectSummary)
4565
+ data: getRegistry(sdk).functions.map(projectSummary)
4250
4566
  });
4251
4567
  const getMethod = ({ method }) => ({
4252
4568
  data: projectMethod(entryFor(method))
@@ -5666,6 +5982,11 @@ function createSemaphore(maxPermits) {
5666
5982
  }
5667
5983
  };
5668
5984
  }
5985
+
5986
+ // src/api/correlation.ts
5987
+ var CORRELATION_CALL_ID = Symbol(
5988
+ "zapier.correlationCallId"
5989
+ );
5669
5990
  var ClientCredentialsObjectSchema = zod.z.object({
5670
5991
  type: zod.z.enum(["client_credentials"]).optional().meta({ internal: true }),
5671
5992
  clientId: zod.z.string().describe("OAuth client ID for authentication.").meta({ valueHint: "id" }),
@@ -6565,13 +6886,13 @@ function sniffDeprecationNotice({
6565
6886
  payload: { ...payload },
6566
6887
  timestamp: Date.now()
6567
6888
  });
6568
- if (isPromiseLike(maybePromise)) {
6889
+ if (isPromiseLike2(maybePromise)) {
6569
6890
  void Promise.resolve(maybePromise).catch(() => {
6570
6891
  });
6571
6892
  }
6572
6893
  }
6573
6894
  }
6574
- function isPromiseLike(value) {
6895
+ function isPromiseLike2(value) {
6575
6896
  return (typeof value === "object" || typeof value === "function") && value !== null && "then" in value && typeof value.then === "function";
6576
6897
  }
6577
6898
  function parseDeprecationDate(value) {
@@ -6582,7 +6903,7 @@ function parseDeprecationDate(value) {
6582
6903
  }
6583
6904
 
6584
6905
  // src/sdk-version.ts
6585
- var SDK_VERSION = (typeof process !== "undefined" && process.env ? "0.98.0" : void 0) || "unknown";
6906
+ var SDK_VERSION = (typeof process !== "undefined" && process.env ? "0.99.0" : void 0) || "unknown";
6586
6907
 
6587
6908
  // src/utils/open-url.ts
6588
6909
  var nodePrefix = "node:";
@@ -6844,14 +7165,15 @@ var ZapierApiClient = class {
6844
7165
  * directly and drifting.
6845
7166
  */
6846
7167
  this.rawFetchUrl = async (url, init, pathConfig2) => {
6847
- if (init?.body && (isPlainObject(init.body) || Array.isArray(init.body))) {
6848
- init.body = JSON.stringify(init.body);
7168
+ const { [CORRELATION_CALL_ID]: callId, ...fetchInit } = init ?? {};
7169
+ if (fetchInit.body && (isPlainObject(fetchInit.body) || Array.isArray(fetchInit.body))) {
7170
+ fetchInit.body = JSON.stringify(fetchInit.body);
6849
7171
  }
6850
7172
  const builtHeaders = await this.buildHeaders(
6851
- init,
7173
+ fetchInit,
6852
7174
  pathConfig2
6853
7175
  );
6854
- const inputHeaders = new Headers(init?.headers ?? {});
7176
+ const inputHeaders = new Headers(fetchInit.headers ?? {});
6855
7177
  const mergedHeaders = new Headers();
6856
7178
  builtHeaders.forEach((value, key) => {
6857
7179
  mergedHeaders.set(key, value);
@@ -6859,11 +7181,11 @@ var ZapierApiClient = class {
6859
7181
  inputHeaders.forEach((value, key) => {
6860
7182
  mergedHeaders.set(key, value);
6861
7183
  });
6862
- this.applyTelemetryHeaders(mergedHeaders);
7184
+ this.applyTelemetryHeaders({ headers: mergedHeaders, callId });
6863
7185
  let retries = 0;
6864
7186
  while (true) {
6865
7187
  const response = await this.options.fetch(url, {
6866
- ...init,
7188
+ ...fetchInit,
6867
7189
  headers: mergedHeaders
6868
7190
  });
6869
7191
  if (response.status !== 429) {
@@ -6984,12 +7306,13 @@ var ZapierApiClient = class {
6984
7306
  );
6985
7307
  const askStatementIds = askStatementIdsHeader ? JSON.parse(askStatementIdsHeader) : void 0;
6986
7308
  try {
6987
- await this.runOneApprovalRound(
6988
- approvalContext,
6989
- approvalMode,
6990
- init?.signal ?? void 0,
6991
- askStatementIds
6992
- );
7309
+ await this.runOneApprovalRound({
7310
+ buildContext: approvalContext,
7311
+ mode: approvalMode,
7312
+ signal: init?.signal ?? void 0,
7313
+ askStatementIds,
7314
+ callId: init?.[CORRELATION_CALL_ID]
7315
+ });
6993
7316
  } catch (error) {
6994
7317
  return { response, approvalRoundError: error };
6995
7318
  }
@@ -7131,7 +7454,8 @@ var ZapierApiClient = class {
7131
7454
  method: "GET",
7132
7455
  searchParams: options.searchParams,
7133
7456
  authRequired: options.authRequired,
7134
- signal: options.signal
7457
+ signal: options.signal,
7458
+ [CORRELATION_CALL_ID]: options[CORRELATION_CALL_ID]
7135
7459
  }),
7136
7460
  initialDelay: options.initialDelayMilliseconds ?? options.initialDelay,
7137
7461
  timeoutMs: options.timeoutMilliseconds ?? options.timeoutMs,
@@ -7426,7 +7750,10 @@ var ZapierApiClient = class {
7426
7750
  // gateway now expects) and the legacy `x-zapier-*` names. The legacy names are
7427
7751
  // kept for backward compatibility with consumers that haven't migrated yet;
7428
7752
  // they can be removed once nothing reads them.
7429
- applyTelemetryHeaders(headers) {
7753
+ applyTelemetryHeaders({
7754
+ headers,
7755
+ callId
7756
+ }) {
7430
7757
  headers.set("zapier-sdk-version", SDK_VERSION);
7431
7758
  headers.set("x-zapier-sdk-version", SDK_VERSION);
7432
7759
  const sdkService = getZapierSdkService();
@@ -7449,6 +7776,11 @@ var ZapierApiClient = class {
7449
7776
  headers.set("zapier-sdk-package-operation", packageOperation);
7450
7777
  }
7451
7778
  }
7779
+ if (callId) {
7780
+ headers.set("zapier-correlation-id", callId);
7781
+ } else {
7782
+ headers.delete("zapier-correlation-id");
7783
+ }
7452
7784
  }
7453
7785
  // Helper to perform HTTP requests with JSON handling
7454
7786
  async fetchJson(method, path, data, options = {}) {
@@ -7591,7 +7923,13 @@ var ZapierApiClient = class {
7591
7923
  * Caller is responsible for passing a non-"disabled" mode; this method
7592
7924
  * unconditionally creates an approval.
7593
7925
  */
7594
- async runOneApprovalRound(buildContext, mode, signal, askStatementIds) {
7926
+ async runOneApprovalRound({
7927
+ buildContext,
7928
+ mode,
7929
+ signal,
7930
+ askStatementIds,
7931
+ callId
7932
+ }) {
7595
7933
  const context = buildContext();
7596
7934
  let approvalResponse;
7597
7935
  try {
@@ -7605,7 +7943,8 @@ var ZapierApiClient = class {
7605
7943
  context,
7606
7944
  ...askStatementIds?.length ? { ask_statement_ids: askStatementIds } : {}
7607
7945
  }),
7608
- signal
7946
+ signal,
7947
+ [CORRELATION_CALL_ID]: callId
7609
7948
  });
7610
7949
  } catch (err) {
7611
7950
  if (isAbortError(err)) throw err;
@@ -7741,7 +8080,10 @@ var ZapierApiClient = class {
7741
8080
  approvalId: approval.id,
7742
8081
  streamUrl,
7743
8082
  signal: streamAbortController.signal,
7744
- stream: (url, streamInit) => this.streamTrustedJsonUrl(url, streamInit),
8083
+ stream: (url, streamInit) => this.streamTrustedJsonUrl(url, {
8084
+ ...streamInit,
8085
+ [CORRELATION_CALL_ID]: callId
8086
+ }),
7745
8087
  emitEvent: (type, payload) => this.emitEvent(type, payload)
7746
8088
  });
7747
8089
  }
@@ -7750,7 +8092,8 @@ var ZapierApiClient = class {
7750
8092
  () => this.rawFetchUrl(approval.poll_url, {
7751
8093
  method: "GET",
7752
8094
  headers: { Accept: "application/json" },
7753
- signal
8095
+ signal,
8096
+ [CORRELATION_CALL_ID]: callId
7754
8097
  })
7755
8098
  );
7756
8099
  const pollApprovalUntilComplete = async (isPending, deadlineMs = approvalDeadline) => {
@@ -7942,6 +8285,23 @@ var API_ID = "zapier/api";
7942
8285
  var apiPluginRef = declareProperty({
7943
8286
  id: API_ID
7944
8287
  });
8288
+ function withCorrelationId({
8289
+ client,
8290
+ callId
8291
+ }) {
8292
+ const stamp = (options) => ({ ...options, [CORRELATION_CALL_ID]: callId });
8293
+ return {
8294
+ get: (path, options) => client.get(path, stamp(options)),
8295
+ post: (path, data, options) => client.post(path, data, stamp(options)),
8296
+ put: (path, data, options) => client.put(path, data, stamp(options)),
8297
+ patch: (path, data, options) => client.patch(path, data, stamp(options)),
8298
+ delete: (path, data, options) => client.delete(path, data, stamp(options)),
8299
+ poll: (path, options) => client.poll(path, stamp(options)),
8300
+ fetch: (path, init) => client.fetch(path, stamp(init)),
8301
+ fetchStream: (path, init) => client.fetchStream(path, stamp(init)),
8302
+ fetchJsonStream: (path, init) => client.fetchJsonStream(path, stamp(init))
8303
+ };
8304
+ }
7945
8305
  var apiPlugin = defineProperty({
7946
8306
  namespace: "zapier",
7947
8307
  name: "api",
@@ -7982,7 +8342,7 @@ var apiPlugin = defineProperty({
7982
8342
  callerPackage
7983
8343
  });
7984
8344
  },
7985
- get: ({ state }) => state
8345
+ get: ({ state, callContext }) => callContext?.callId ? withCorrelationId({ client: state, callId: callContext.callId }) : state
7986
8346
  });
7987
8347
  var RESOLVE_CREDENTIALS_ID = "zapier/resolveCredentials";
7988
8348
  var resolveCredentialsPluginRef = declareProperty({ id: RESOLVE_CREDENTIALS_ID });
@@ -8543,8 +8903,11 @@ var manifestPlugin = defineProperty({
8543
8903
  namespace: "zapier",
8544
8904
  name: "manifest",
8545
8905
  imports: [sdkOptionsPluginRef, apiPluginRef],
8906
+ // Deliberately does not read `imports.api`: at build time that resolves to the
8907
+ // bare shared client, and capturing it here would strip the correlation id off
8908
+ // every slug-resolution request. `get` supplies the reading call's client
8909
+ // instead.
8546
8910
  setup: ({ imports }) => {
8547
- const api = imports.api;
8548
8911
  const { manifestPath = DEFAULT_CONFIG_PATH, manifest } = imports.sdkOptions ?? {};
8549
8912
  let resolvedManifest;
8550
8913
  async function resolveManifest() {
@@ -8562,7 +8925,10 @@ var manifestPlugin = defineProperty({
8562
8925
  }
8563
8926
  return resolvedManifest;
8564
8927
  };
8565
- const getVersionedImplementationId = async (appKey) => {
8928
+ const getVersionedImplementationId = async ({
8929
+ appKey,
8930
+ api
8931
+ }) => {
8566
8932
  const resolvedApps = await resolveAppKeys({
8567
8933
  appKeys: [appKey],
8568
8934
  api,
@@ -8572,14 +8938,14 @@ var manifestPlugin = defineProperty({
8572
8938
  if (!resolvedApp) return null;
8573
8939
  return `${resolvedApp.implementationName}@${resolvedApp.version || "latest"}`;
8574
8940
  };
8575
- const updateManifestEntry = async (options) => {
8576
- const {
8577
- appKey,
8578
- entry,
8579
- configPath = DEFAULT_CONFIG_PATH,
8580
- skipWrite = false,
8581
- manifest: inputManifest
8582
- } = options;
8941
+ const updateManifestEntry = async ({
8942
+ api,
8943
+ appKey,
8944
+ entry,
8945
+ configPath = DEFAULT_CONFIG_PATH,
8946
+ skipWrite = false,
8947
+ manifest: inputManifest
8948
+ }) => {
8583
8949
  const manifest2 = inputManifest || await readManifestFromFile(configPath) || { apps: {} };
8584
8950
  let existingEntry = findManifestEntry({
8585
8951
  appKey,
@@ -8630,7 +8996,7 @@ var manifestPlugin = defineProperty({
8630
8996
  };
8631
8997
  return {
8632
8998
  getVersionedImplementationId,
8633
- resolveAppKeys: async ({ appKeys }) => resolveAppKeys({
8999
+ resolveAppKeys: async ({ appKeys, api }) => resolveAppKeys({
8634
9000
  appKeys,
8635
9001
  api,
8636
9002
  manifest: await getResolvedManifest() ?? { apps: {} }
@@ -8643,7 +9009,19 @@ var manifestPlugin = defineProperty({
8643
9009
  updateManifestEntry
8644
9010
  };
8645
9011
  },
8646
- get: ({ state }) => state
9012
+ // Bind the reading call's API client onto the slug-resolving entry points so
9013
+ // their requests carry that call's correlation id. The manifest-only reads pass
9014
+ // straight through.
9015
+ get: ({ imports, state }) => {
9016
+ const api = imports.api;
9017
+ return {
9018
+ getVersionedImplementationId: (appKey) => state.getVersionedImplementationId({ appKey, api }),
9019
+ resolveAppKeys: ({ appKeys }) => state.resolveAppKeys({ appKeys, api }),
9020
+ getResolvedManifest: state.getResolvedManifest,
9021
+ getManifestConnections: state.getManifestConnections,
9022
+ updateManifestEntry: (options) => state.updateManifestEntry({ ...options, api })
9023
+ };
9024
+ }
8647
9025
  });
8648
9026
 
8649
9027
  // src/plugins/connections/index.ts
@@ -15744,6 +16122,7 @@ function buildErrorEventWithContext(data, context = {}) {
15744
16122
  function buildMethodCalledEvent(data, context = {}) {
15745
16123
  return {
15746
16124
  ...createBaseEvent(context),
16125
+ correlation_id: data.correlation_id ?? context.correlation_id ?? null,
15747
16126
  method_name: data.method_name ?? null,
15748
16127
  method_module: data.method_module ?? null,
15749
16128
  execution_duration_ms: data.execution_duration_ms,
@@ -15801,6 +16180,7 @@ function makeMethodEndHook(emitMethodCalled) {
15801
16180
  args,
15802
16181
  isPaginated,
15803
16182
  depth,
16183
+ callId,
15804
16184
  callOrigin,
15805
16185
  annotations,
15806
16186
  durationMs,
@@ -15810,6 +16190,9 @@ function makeMethodEndHook(emitMethodCalled) {
15810
16190
  const metadata = readMethodMetadata(annotations);
15811
16191
  emitMethodCalled({
15812
16192
  method_name: methodName,
16193
+ // The per-call correlation id (also the `zapier-correlation-id` header on
16194
+ // this call's requests). Not the `call_context` surface label.
16195
+ correlation_id: callId ?? null,
15813
16196
  execution_duration_ms: durationMs,
15814
16197
  success_flag: !error,
15815
16198
  error_message: error?.message ?? null,
@@ -16636,6 +17019,7 @@ exports.defineFormatter = defineFormatter;
16636
17019
  exports.defineLegacyMerge = defineLegacyMerge;
16637
17020
  exports.defineMethod = defineMethod;
16638
17021
  exports.defineMethodOverride = defineMethodOverride;
17022
+ exports.defineOverride = defineOverride;
16639
17023
  exports.definePlugin = definePlugin;
16640
17024
  exports.defineProperty = defineProperty;
16641
17025
  exports.defineResolver = defineResolver;