@zapier/zapier-sdk 0.98.0 → 0.98.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @zapier/zapier-sdk
2
2
 
3
+ ## 0.98.1
4
+
5
+ ### Patch Changes
6
+
7
+ - cd0616e: _This release contains no user-facing changes._
8
+
3
9
  ## 0.98.0
4
10
 
5
11
  ### Minor Changes
@@ -2217,8 +2217,9 @@ function bindValue({
2217
2217
  frameworkOrigin = false
2218
2218
  }) {
2219
2219
  if (entry.pluginType === "property" && entry.getValue) {
2220
+ const getValue = entry.getValue;
2220
2221
  Object.defineProperty(target, key, {
2221
- get: entry.getValue,
2222
+ get: ctx ? () => getValue(ctx) : getValue,
2222
2223
  enumerable: true,
2223
2224
  configurable: true
2224
2225
  });
@@ -2756,9 +2757,14 @@ function buildEagerArtifacts(descriptors, context, states) {
2756
2757
  plugins[id] = {
2757
2758
  pluginType: "property",
2758
2759
  name: descriptor.name,
2759
- getValue: () => get({
2760
- imports: buildImports({ plugins, importBindings }),
2761
- state: states.get(id)
2760
+ getValue: (callContext) => get({
2761
+ imports: buildImports({
2762
+ plugins,
2763
+ importBindings,
2764
+ ctx: callContext
2765
+ }),
2766
+ state: states.get(id),
2767
+ callContext
2762
2768
  }),
2763
2769
  meta: descriptor.meta,
2764
2770
  dynamicMembers: descriptor.dynamicMembers
@@ -5664,6 +5670,11 @@ function createSemaphore(maxPermits) {
5664
5670
  }
5665
5671
  };
5666
5672
  }
5673
+
5674
+ // src/api/correlation.ts
5675
+ var CORRELATION_CALL_ID = Symbol(
5676
+ "zapier.correlationCallId"
5677
+ );
5667
5678
  var ClientCredentialsObjectSchema = z.object({
5668
5679
  type: z.enum(["client_credentials"]).optional().meta({ internal: true }),
5669
5680
  clientId: z.string().describe("OAuth client ID for authentication.").meta({ valueHint: "id" }),
@@ -6580,7 +6591,7 @@ function parseDeprecationDate(value) {
6580
6591
  }
6581
6592
 
6582
6593
  // src/sdk-version.ts
6583
- var SDK_VERSION = (typeof process !== "undefined" && process.env ? "0.98.0" : void 0) || "unknown";
6594
+ var SDK_VERSION = (typeof process !== "undefined" && process.env ? "0.98.1" : void 0) || "unknown";
6584
6595
 
6585
6596
  // src/utils/open-url.ts
6586
6597
  var nodePrefix = "node:";
@@ -6842,14 +6853,15 @@ var ZapierApiClient = class {
6842
6853
  * directly and drifting.
6843
6854
  */
6844
6855
  this.rawFetchUrl = async (url, init, pathConfig2) => {
6845
- if (init?.body && (isPlainObject(init.body) || Array.isArray(init.body))) {
6846
- init.body = JSON.stringify(init.body);
6856
+ const { [CORRELATION_CALL_ID]: callId, ...fetchInit } = init ?? {};
6857
+ if (fetchInit.body && (isPlainObject(fetchInit.body) || Array.isArray(fetchInit.body))) {
6858
+ fetchInit.body = JSON.stringify(fetchInit.body);
6847
6859
  }
6848
6860
  const builtHeaders = await this.buildHeaders(
6849
- init,
6861
+ fetchInit,
6850
6862
  pathConfig2
6851
6863
  );
6852
- const inputHeaders = new Headers(init?.headers ?? {});
6864
+ const inputHeaders = new Headers(fetchInit.headers ?? {});
6853
6865
  const mergedHeaders = new Headers();
6854
6866
  builtHeaders.forEach((value, key) => {
6855
6867
  mergedHeaders.set(key, value);
@@ -6857,11 +6869,11 @@ var ZapierApiClient = class {
6857
6869
  inputHeaders.forEach((value, key) => {
6858
6870
  mergedHeaders.set(key, value);
6859
6871
  });
6860
- this.applyTelemetryHeaders(mergedHeaders);
6872
+ this.applyTelemetryHeaders({ headers: mergedHeaders, callId });
6861
6873
  let retries = 0;
6862
6874
  while (true) {
6863
6875
  const response = await this.options.fetch(url, {
6864
- ...init,
6876
+ ...fetchInit,
6865
6877
  headers: mergedHeaders
6866
6878
  });
6867
6879
  if (response.status !== 429) {
@@ -6982,12 +6994,13 @@ var ZapierApiClient = class {
6982
6994
  );
6983
6995
  const askStatementIds = askStatementIdsHeader ? JSON.parse(askStatementIdsHeader) : void 0;
6984
6996
  try {
6985
- await this.runOneApprovalRound(
6986
- approvalContext,
6987
- approvalMode,
6988
- init?.signal ?? void 0,
6989
- askStatementIds
6990
- );
6997
+ await this.runOneApprovalRound({
6998
+ buildContext: approvalContext,
6999
+ mode: approvalMode,
7000
+ signal: init?.signal ?? void 0,
7001
+ askStatementIds,
7002
+ callId: init?.[CORRELATION_CALL_ID]
7003
+ });
6991
7004
  } catch (error) {
6992
7005
  return { response, approvalRoundError: error };
6993
7006
  }
@@ -7129,7 +7142,8 @@ var ZapierApiClient = class {
7129
7142
  method: "GET",
7130
7143
  searchParams: options.searchParams,
7131
7144
  authRequired: options.authRequired,
7132
- signal: options.signal
7145
+ signal: options.signal,
7146
+ [CORRELATION_CALL_ID]: options[CORRELATION_CALL_ID]
7133
7147
  }),
7134
7148
  initialDelay: options.initialDelayMilliseconds ?? options.initialDelay,
7135
7149
  timeoutMs: options.timeoutMilliseconds ?? options.timeoutMs,
@@ -7424,7 +7438,10 @@ var ZapierApiClient = class {
7424
7438
  // gateway now expects) and the legacy `x-zapier-*` names. The legacy names are
7425
7439
  // kept for backward compatibility with consumers that haven't migrated yet;
7426
7440
  // they can be removed once nothing reads them.
7427
- applyTelemetryHeaders(headers) {
7441
+ applyTelemetryHeaders({
7442
+ headers,
7443
+ callId
7444
+ }) {
7428
7445
  headers.set("zapier-sdk-version", SDK_VERSION);
7429
7446
  headers.set("x-zapier-sdk-version", SDK_VERSION);
7430
7447
  const sdkService = getZapierSdkService();
@@ -7447,6 +7464,11 @@ var ZapierApiClient = class {
7447
7464
  headers.set("zapier-sdk-package-operation", packageOperation);
7448
7465
  }
7449
7466
  }
7467
+ if (callId) {
7468
+ headers.set("zapier-correlation-id", callId);
7469
+ } else {
7470
+ headers.delete("zapier-correlation-id");
7471
+ }
7450
7472
  }
7451
7473
  // Helper to perform HTTP requests with JSON handling
7452
7474
  async fetchJson(method, path, data, options = {}) {
@@ -7589,7 +7611,13 @@ var ZapierApiClient = class {
7589
7611
  * Caller is responsible for passing a non-"disabled" mode; this method
7590
7612
  * unconditionally creates an approval.
7591
7613
  */
7592
- async runOneApprovalRound(buildContext, mode, signal, askStatementIds) {
7614
+ async runOneApprovalRound({
7615
+ buildContext,
7616
+ mode,
7617
+ signal,
7618
+ askStatementIds,
7619
+ callId
7620
+ }) {
7593
7621
  const context = buildContext();
7594
7622
  let approvalResponse;
7595
7623
  try {
@@ -7603,7 +7631,8 @@ var ZapierApiClient = class {
7603
7631
  context,
7604
7632
  ...askStatementIds?.length ? { ask_statement_ids: askStatementIds } : {}
7605
7633
  }),
7606
- signal
7634
+ signal,
7635
+ [CORRELATION_CALL_ID]: callId
7607
7636
  });
7608
7637
  } catch (err) {
7609
7638
  if (isAbortError(err)) throw err;
@@ -7739,7 +7768,10 @@ var ZapierApiClient = class {
7739
7768
  approvalId: approval.id,
7740
7769
  streamUrl,
7741
7770
  signal: streamAbortController.signal,
7742
- stream: (url, streamInit) => this.streamTrustedJsonUrl(url, streamInit),
7771
+ stream: (url, streamInit) => this.streamTrustedJsonUrl(url, {
7772
+ ...streamInit,
7773
+ [CORRELATION_CALL_ID]: callId
7774
+ }),
7743
7775
  emitEvent: (type, payload) => this.emitEvent(type, payload)
7744
7776
  });
7745
7777
  }
@@ -7748,7 +7780,8 @@ var ZapierApiClient = class {
7748
7780
  () => this.rawFetchUrl(approval.poll_url, {
7749
7781
  method: "GET",
7750
7782
  headers: { Accept: "application/json" },
7751
- signal
7783
+ signal,
7784
+ [CORRELATION_CALL_ID]: callId
7752
7785
  })
7753
7786
  );
7754
7787
  const pollApprovalUntilComplete = async (isPending, deadlineMs = approvalDeadline) => {
@@ -7940,6 +7973,23 @@ var API_ID = "zapier/api";
7940
7973
  var apiPluginRef = declareProperty({
7941
7974
  id: API_ID
7942
7975
  });
7976
+ function withCorrelationId({
7977
+ client,
7978
+ callId
7979
+ }) {
7980
+ const stamp = (options) => ({ ...options, [CORRELATION_CALL_ID]: callId });
7981
+ return {
7982
+ get: (path, options) => client.get(path, stamp(options)),
7983
+ post: (path, data, options) => client.post(path, data, stamp(options)),
7984
+ put: (path, data, options) => client.put(path, data, stamp(options)),
7985
+ patch: (path, data, options) => client.patch(path, data, stamp(options)),
7986
+ delete: (path, data, options) => client.delete(path, data, stamp(options)),
7987
+ poll: (path, options) => client.poll(path, stamp(options)),
7988
+ fetch: (path, init) => client.fetch(path, stamp(init)),
7989
+ fetchStream: (path, init) => client.fetchStream(path, stamp(init)),
7990
+ fetchJsonStream: (path, init) => client.fetchJsonStream(path, stamp(init))
7991
+ };
7992
+ }
7943
7993
  var apiPlugin = defineProperty({
7944
7994
  namespace: "zapier",
7945
7995
  name: "api",
@@ -7980,7 +8030,7 @@ var apiPlugin = defineProperty({
7980
8030
  callerPackage
7981
8031
  });
7982
8032
  },
7983
- get: ({ state }) => state
8033
+ get: ({ state, callContext }) => callContext?.callId ? withCorrelationId({ client: state, callId: callContext.callId }) : state
7984
8034
  });
7985
8035
  var RESOLVE_CREDENTIALS_ID = "zapier/resolveCredentials";
7986
8036
  var resolveCredentialsPluginRef = declareProperty({ id: RESOLVE_CREDENTIALS_ID });
@@ -8541,8 +8591,11 @@ var manifestPlugin = defineProperty({
8541
8591
  namespace: "zapier",
8542
8592
  name: "manifest",
8543
8593
  imports: [sdkOptionsPluginRef, apiPluginRef],
8594
+ // Deliberately does not read `imports.api`: at build time that resolves to the
8595
+ // bare shared client, and capturing it here would strip the correlation id off
8596
+ // every slug-resolution request. `get` supplies the reading call's client
8597
+ // instead.
8544
8598
  setup: ({ imports }) => {
8545
- const api = imports.api;
8546
8599
  const { manifestPath = DEFAULT_CONFIG_PATH, manifest } = imports.sdkOptions ?? {};
8547
8600
  let resolvedManifest;
8548
8601
  async function resolveManifest() {
@@ -8560,7 +8613,10 @@ var manifestPlugin = defineProperty({
8560
8613
  }
8561
8614
  return resolvedManifest;
8562
8615
  };
8563
- const getVersionedImplementationId = async (appKey) => {
8616
+ const getVersionedImplementationId = async ({
8617
+ appKey,
8618
+ api
8619
+ }) => {
8564
8620
  const resolvedApps = await resolveAppKeys({
8565
8621
  appKeys: [appKey],
8566
8622
  api,
@@ -8570,14 +8626,14 @@ var manifestPlugin = defineProperty({
8570
8626
  if (!resolvedApp) return null;
8571
8627
  return `${resolvedApp.implementationName}@${resolvedApp.version || "latest"}`;
8572
8628
  };
8573
- const updateManifestEntry = async (options) => {
8574
- const {
8575
- appKey,
8576
- entry,
8577
- configPath = DEFAULT_CONFIG_PATH,
8578
- skipWrite = false,
8579
- manifest: inputManifest
8580
- } = options;
8629
+ const updateManifestEntry = async ({
8630
+ api,
8631
+ appKey,
8632
+ entry,
8633
+ configPath = DEFAULT_CONFIG_PATH,
8634
+ skipWrite = false,
8635
+ manifest: inputManifest
8636
+ }) => {
8581
8637
  const manifest2 = inputManifest || await readManifestFromFile(configPath) || { apps: {} };
8582
8638
  let existingEntry = findManifestEntry({
8583
8639
  appKey,
@@ -8628,7 +8684,7 @@ var manifestPlugin = defineProperty({
8628
8684
  };
8629
8685
  return {
8630
8686
  getVersionedImplementationId,
8631
- resolveAppKeys: async ({ appKeys }) => resolveAppKeys({
8687
+ resolveAppKeys: async ({ appKeys, api }) => resolveAppKeys({
8632
8688
  appKeys,
8633
8689
  api,
8634
8690
  manifest: await getResolvedManifest() ?? { apps: {} }
@@ -8641,7 +8697,19 @@ var manifestPlugin = defineProperty({
8641
8697
  updateManifestEntry
8642
8698
  };
8643
8699
  },
8644
- get: ({ state }) => state
8700
+ // Bind the reading call's API client onto the slug-resolving entry points so
8701
+ // their requests carry that call's correlation id. The manifest-only reads pass
8702
+ // straight through.
8703
+ get: ({ imports, state }) => {
8704
+ const api = imports.api;
8705
+ return {
8706
+ getVersionedImplementationId: (appKey) => state.getVersionedImplementationId({ appKey, api }),
8707
+ resolveAppKeys: ({ appKeys }) => state.resolveAppKeys({ appKeys, api }),
8708
+ getResolvedManifest: state.getResolvedManifest,
8709
+ getManifestConnections: state.getManifestConnections,
8710
+ updateManifestEntry: (options) => state.updateManifestEntry({ ...options, api })
8711
+ };
8712
+ }
8645
8713
  });
8646
8714
 
8647
8715
  // src/plugins/connections/index.ts
@@ -15742,6 +15810,7 @@ function buildErrorEventWithContext(data, context = {}) {
15742
15810
  function buildMethodCalledEvent(data, context = {}) {
15743
15811
  return {
15744
15812
  ...createBaseEvent(context),
15813
+ correlation_id: data.correlation_id ?? context.correlation_id ?? null,
15745
15814
  method_name: data.method_name ?? null,
15746
15815
  method_module: data.method_module ?? null,
15747
15816
  execution_duration_ms: data.execution_duration_ms,
@@ -15799,6 +15868,7 @@ function makeMethodEndHook(emitMethodCalled) {
15799
15868
  args,
15800
15869
  isPaginated,
15801
15870
  depth,
15871
+ callId,
15802
15872
  callOrigin,
15803
15873
  annotations,
15804
15874
  durationMs,
@@ -15808,6 +15878,9 @@ function makeMethodEndHook(emitMethodCalled) {
15808
15878
  const metadata = readMethodMetadata(annotations);
15809
15879
  emitMethodCalled({
15810
15880
  method_name: methodName,
15881
+ // The per-call correlation id (also the `zapier-correlation-id` header on
15882
+ // this call's requests). Not the `call_context` surface label.
15883
+ correlation_id: callId ?? null,
15811
15884
  execution_duration_ms: durationMs,
15812
15885
  success_flag: !error,
15813
15886
  error_message: error?.message ?? null,
@@ -2219,8 +2219,9 @@ function bindValue({
2219
2219
  frameworkOrigin = false
2220
2220
  }) {
2221
2221
  if (entry.pluginType === "property" && entry.getValue) {
2222
+ const getValue = entry.getValue;
2222
2223
  Object.defineProperty(target, key, {
2223
- get: entry.getValue,
2224
+ get: ctx ? () => getValue(ctx) : getValue,
2224
2225
  enumerable: true,
2225
2226
  configurable: true
2226
2227
  });
@@ -2758,9 +2759,14 @@ function buildEagerArtifacts(descriptors, context, states) {
2758
2759
  plugins[id] = {
2759
2760
  pluginType: "property",
2760
2761
  name: descriptor.name,
2761
- getValue: () => get({
2762
- imports: buildImports({ plugins, importBindings }),
2763
- state: states.get(id)
2762
+ getValue: (callContext) => get({
2763
+ imports: buildImports({
2764
+ plugins,
2765
+ importBindings,
2766
+ ctx: callContext
2767
+ }),
2768
+ state: states.get(id),
2769
+ callContext
2764
2770
  }),
2765
2771
  meta: descriptor.meta,
2766
2772
  dynamicMembers: descriptor.dynamicMembers
@@ -5666,6 +5672,11 @@ function createSemaphore(maxPermits) {
5666
5672
  }
5667
5673
  };
5668
5674
  }
5675
+
5676
+ // src/api/correlation.ts
5677
+ var CORRELATION_CALL_ID = Symbol(
5678
+ "zapier.correlationCallId"
5679
+ );
5669
5680
  var ClientCredentialsObjectSchema = zod.z.object({
5670
5681
  type: zod.z.enum(["client_credentials"]).optional().meta({ internal: true }),
5671
5682
  clientId: zod.z.string().describe("OAuth client ID for authentication.").meta({ valueHint: "id" }),
@@ -6582,7 +6593,7 @@ function parseDeprecationDate(value) {
6582
6593
  }
6583
6594
 
6584
6595
  // src/sdk-version.ts
6585
- var SDK_VERSION = (typeof process !== "undefined" && process.env ? "0.98.0" : void 0) || "unknown";
6596
+ var SDK_VERSION = (typeof process !== "undefined" && process.env ? "0.98.1" : void 0) || "unknown";
6586
6597
 
6587
6598
  // src/utils/open-url.ts
6588
6599
  var nodePrefix = "node:";
@@ -6844,14 +6855,15 @@ var ZapierApiClient = class {
6844
6855
  * directly and drifting.
6845
6856
  */
6846
6857
  this.rawFetchUrl = async (url, init, pathConfig2) => {
6847
- if (init?.body && (isPlainObject(init.body) || Array.isArray(init.body))) {
6848
- init.body = JSON.stringify(init.body);
6858
+ const { [CORRELATION_CALL_ID]: callId, ...fetchInit } = init ?? {};
6859
+ if (fetchInit.body && (isPlainObject(fetchInit.body) || Array.isArray(fetchInit.body))) {
6860
+ fetchInit.body = JSON.stringify(fetchInit.body);
6849
6861
  }
6850
6862
  const builtHeaders = await this.buildHeaders(
6851
- init,
6863
+ fetchInit,
6852
6864
  pathConfig2
6853
6865
  );
6854
- const inputHeaders = new Headers(init?.headers ?? {});
6866
+ const inputHeaders = new Headers(fetchInit.headers ?? {});
6855
6867
  const mergedHeaders = new Headers();
6856
6868
  builtHeaders.forEach((value, key) => {
6857
6869
  mergedHeaders.set(key, value);
@@ -6859,11 +6871,11 @@ var ZapierApiClient = class {
6859
6871
  inputHeaders.forEach((value, key) => {
6860
6872
  mergedHeaders.set(key, value);
6861
6873
  });
6862
- this.applyTelemetryHeaders(mergedHeaders);
6874
+ this.applyTelemetryHeaders({ headers: mergedHeaders, callId });
6863
6875
  let retries = 0;
6864
6876
  while (true) {
6865
6877
  const response = await this.options.fetch(url, {
6866
- ...init,
6878
+ ...fetchInit,
6867
6879
  headers: mergedHeaders
6868
6880
  });
6869
6881
  if (response.status !== 429) {
@@ -6984,12 +6996,13 @@ var ZapierApiClient = class {
6984
6996
  );
6985
6997
  const askStatementIds = askStatementIdsHeader ? JSON.parse(askStatementIdsHeader) : void 0;
6986
6998
  try {
6987
- await this.runOneApprovalRound(
6988
- approvalContext,
6989
- approvalMode,
6990
- init?.signal ?? void 0,
6991
- askStatementIds
6992
- );
6999
+ await this.runOneApprovalRound({
7000
+ buildContext: approvalContext,
7001
+ mode: approvalMode,
7002
+ signal: init?.signal ?? void 0,
7003
+ askStatementIds,
7004
+ callId: init?.[CORRELATION_CALL_ID]
7005
+ });
6993
7006
  } catch (error) {
6994
7007
  return { response, approvalRoundError: error };
6995
7008
  }
@@ -7131,7 +7144,8 @@ var ZapierApiClient = class {
7131
7144
  method: "GET",
7132
7145
  searchParams: options.searchParams,
7133
7146
  authRequired: options.authRequired,
7134
- signal: options.signal
7147
+ signal: options.signal,
7148
+ [CORRELATION_CALL_ID]: options[CORRELATION_CALL_ID]
7135
7149
  }),
7136
7150
  initialDelay: options.initialDelayMilliseconds ?? options.initialDelay,
7137
7151
  timeoutMs: options.timeoutMilliseconds ?? options.timeoutMs,
@@ -7426,7 +7440,10 @@ var ZapierApiClient = class {
7426
7440
  // gateway now expects) and the legacy `x-zapier-*` names. The legacy names are
7427
7441
  // kept for backward compatibility with consumers that haven't migrated yet;
7428
7442
  // they can be removed once nothing reads them.
7429
- applyTelemetryHeaders(headers) {
7443
+ applyTelemetryHeaders({
7444
+ headers,
7445
+ callId
7446
+ }) {
7430
7447
  headers.set("zapier-sdk-version", SDK_VERSION);
7431
7448
  headers.set("x-zapier-sdk-version", SDK_VERSION);
7432
7449
  const sdkService = getZapierSdkService();
@@ -7449,6 +7466,11 @@ var ZapierApiClient = class {
7449
7466
  headers.set("zapier-sdk-package-operation", packageOperation);
7450
7467
  }
7451
7468
  }
7469
+ if (callId) {
7470
+ headers.set("zapier-correlation-id", callId);
7471
+ } else {
7472
+ headers.delete("zapier-correlation-id");
7473
+ }
7452
7474
  }
7453
7475
  // Helper to perform HTTP requests with JSON handling
7454
7476
  async fetchJson(method, path, data, options = {}) {
@@ -7591,7 +7613,13 @@ var ZapierApiClient = class {
7591
7613
  * Caller is responsible for passing a non-"disabled" mode; this method
7592
7614
  * unconditionally creates an approval.
7593
7615
  */
7594
- async runOneApprovalRound(buildContext, mode, signal, askStatementIds) {
7616
+ async runOneApprovalRound({
7617
+ buildContext,
7618
+ mode,
7619
+ signal,
7620
+ askStatementIds,
7621
+ callId
7622
+ }) {
7595
7623
  const context = buildContext();
7596
7624
  let approvalResponse;
7597
7625
  try {
@@ -7605,7 +7633,8 @@ var ZapierApiClient = class {
7605
7633
  context,
7606
7634
  ...askStatementIds?.length ? { ask_statement_ids: askStatementIds } : {}
7607
7635
  }),
7608
- signal
7636
+ signal,
7637
+ [CORRELATION_CALL_ID]: callId
7609
7638
  });
7610
7639
  } catch (err) {
7611
7640
  if (isAbortError(err)) throw err;
@@ -7741,7 +7770,10 @@ var ZapierApiClient = class {
7741
7770
  approvalId: approval.id,
7742
7771
  streamUrl,
7743
7772
  signal: streamAbortController.signal,
7744
- stream: (url, streamInit) => this.streamTrustedJsonUrl(url, streamInit),
7773
+ stream: (url, streamInit) => this.streamTrustedJsonUrl(url, {
7774
+ ...streamInit,
7775
+ [CORRELATION_CALL_ID]: callId
7776
+ }),
7745
7777
  emitEvent: (type, payload) => this.emitEvent(type, payload)
7746
7778
  });
7747
7779
  }
@@ -7750,7 +7782,8 @@ var ZapierApiClient = class {
7750
7782
  () => this.rawFetchUrl(approval.poll_url, {
7751
7783
  method: "GET",
7752
7784
  headers: { Accept: "application/json" },
7753
- signal
7785
+ signal,
7786
+ [CORRELATION_CALL_ID]: callId
7754
7787
  })
7755
7788
  );
7756
7789
  const pollApprovalUntilComplete = async (isPending, deadlineMs = approvalDeadline) => {
@@ -7942,6 +7975,23 @@ var API_ID = "zapier/api";
7942
7975
  var apiPluginRef = declareProperty({
7943
7976
  id: API_ID
7944
7977
  });
7978
+ function withCorrelationId({
7979
+ client,
7980
+ callId
7981
+ }) {
7982
+ const stamp = (options) => ({ ...options, [CORRELATION_CALL_ID]: callId });
7983
+ return {
7984
+ get: (path, options) => client.get(path, stamp(options)),
7985
+ post: (path, data, options) => client.post(path, data, stamp(options)),
7986
+ put: (path, data, options) => client.put(path, data, stamp(options)),
7987
+ patch: (path, data, options) => client.patch(path, data, stamp(options)),
7988
+ delete: (path, data, options) => client.delete(path, data, stamp(options)),
7989
+ poll: (path, options) => client.poll(path, stamp(options)),
7990
+ fetch: (path, init) => client.fetch(path, stamp(init)),
7991
+ fetchStream: (path, init) => client.fetchStream(path, stamp(init)),
7992
+ fetchJsonStream: (path, init) => client.fetchJsonStream(path, stamp(init))
7993
+ };
7994
+ }
7945
7995
  var apiPlugin = defineProperty({
7946
7996
  namespace: "zapier",
7947
7997
  name: "api",
@@ -7982,7 +8032,7 @@ var apiPlugin = defineProperty({
7982
8032
  callerPackage
7983
8033
  });
7984
8034
  },
7985
- get: ({ state }) => state
8035
+ get: ({ state, callContext }) => callContext?.callId ? withCorrelationId({ client: state, callId: callContext.callId }) : state
7986
8036
  });
7987
8037
  var RESOLVE_CREDENTIALS_ID = "zapier/resolveCredentials";
7988
8038
  var resolveCredentialsPluginRef = declareProperty({ id: RESOLVE_CREDENTIALS_ID });
@@ -8543,8 +8593,11 @@ var manifestPlugin = defineProperty({
8543
8593
  namespace: "zapier",
8544
8594
  name: "manifest",
8545
8595
  imports: [sdkOptionsPluginRef, apiPluginRef],
8596
+ // Deliberately does not read `imports.api`: at build time that resolves to the
8597
+ // bare shared client, and capturing it here would strip the correlation id off
8598
+ // every slug-resolution request. `get` supplies the reading call's client
8599
+ // instead.
8546
8600
  setup: ({ imports }) => {
8547
- const api = imports.api;
8548
8601
  const { manifestPath = DEFAULT_CONFIG_PATH, manifest } = imports.sdkOptions ?? {};
8549
8602
  let resolvedManifest;
8550
8603
  async function resolveManifest() {
@@ -8562,7 +8615,10 @@ var manifestPlugin = defineProperty({
8562
8615
  }
8563
8616
  return resolvedManifest;
8564
8617
  };
8565
- const getVersionedImplementationId = async (appKey) => {
8618
+ const getVersionedImplementationId = async ({
8619
+ appKey,
8620
+ api
8621
+ }) => {
8566
8622
  const resolvedApps = await resolveAppKeys({
8567
8623
  appKeys: [appKey],
8568
8624
  api,
@@ -8572,14 +8628,14 @@ var manifestPlugin = defineProperty({
8572
8628
  if (!resolvedApp) return null;
8573
8629
  return `${resolvedApp.implementationName}@${resolvedApp.version || "latest"}`;
8574
8630
  };
8575
- const updateManifestEntry = async (options) => {
8576
- const {
8577
- appKey,
8578
- entry,
8579
- configPath = DEFAULT_CONFIG_PATH,
8580
- skipWrite = false,
8581
- manifest: inputManifest
8582
- } = options;
8631
+ const updateManifestEntry = async ({
8632
+ api,
8633
+ appKey,
8634
+ entry,
8635
+ configPath = DEFAULT_CONFIG_PATH,
8636
+ skipWrite = false,
8637
+ manifest: inputManifest
8638
+ }) => {
8583
8639
  const manifest2 = inputManifest || await readManifestFromFile(configPath) || { apps: {} };
8584
8640
  let existingEntry = findManifestEntry({
8585
8641
  appKey,
@@ -8630,7 +8686,7 @@ var manifestPlugin = defineProperty({
8630
8686
  };
8631
8687
  return {
8632
8688
  getVersionedImplementationId,
8633
- resolveAppKeys: async ({ appKeys }) => resolveAppKeys({
8689
+ resolveAppKeys: async ({ appKeys, api }) => resolveAppKeys({
8634
8690
  appKeys,
8635
8691
  api,
8636
8692
  manifest: await getResolvedManifest() ?? { apps: {} }
@@ -8643,7 +8699,19 @@ var manifestPlugin = defineProperty({
8643
8699
  updateManifestEntry
8644
8700
  };
8645
8701
  },
8646
- get: ({ state }) => state
8702
+ // Bind the reading call's API client onto the slug-resolving entry points so
8703
+ // their requests carry that call's correlation id. The manifest-only reads pass
8704
+ // straight through.
8705
+ get: ({ imports, state }) => {
8706
+ const api = imports.api;
8707
+ return {
8708
+ getVersionedImplementationId: (appKey) => state.getVersionedImplementationId({ appKey, api }),
8709
+ resolveAppKeys: ({ appKeys }) => state.resolveAppKeys({ appKeys, api }),
8710
+ getResolvedManifest: state.getResolvedManifest,
8711
+ getManifestConnections: state.getManifestConnections,
8712
+ updateManifestEntry: (options) => state.updateManifestEntry({ ...options, api })
8713
+ };
8714
+ }
8647
8715
  });
8648
8716
 
8649
8717
  // src/plugins/connections/index.ts
@@ -15744,6 +15812,7 @@ function buildErrorEventWithContext(data, context = {}) {
15744
15812
  function buildMethodCalledEvent(data, context = {}) {
15745
15813
  return {
15746
15814
  ...createBaseEvent(context),
15815
+ correlation_id: data.correlation_id ?? context.correlation_id ?? null,
15747
15816
  method_name: data.method_name ?? null,
15748
15817
  method_module: data.method_module ?? null,
15749
15818
  execution_duration_ms: data.execution_duration_ms,
@@ -15801,6 +15870,7 @@ function makeMethodEndHook(emitMethodCalled) {
15801
15870
  args,
15802
15871
  isPaginated,
15803
15872
  depth,
15873
+ callId,
15804
15874
  callOrigin,
15805
15875
  annotations,
15806
15876
  durationMs,
@@ -15810,6 +15880,9 @@ function makeMethodEndHook(emitMethodCalled) {
15810
15880
  const metadata = readMethodMetadata(annotations);
15811
15881
  emitMethodCalled({
15812
15882
  method_name: methodName,
15883
+ // The per-call correlation id (also the `zapier-correlation-id` header on
15884
+ // this call's requests). Not the `call_context` surface label.
15885
+ correlation_id: callId ?? null,
15813
15886
  execution_duration_ms: durationMs,
15814
15887
  success_flag: !error,
15815
15888
  error_message: error?.message ?? null,