@zapier/zapier-sdk 0.30.0 → 0.31.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.
Files changed (50) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +23 -9
  3. package/dist/api/schemas.d.ts +2 -2
  4. package/dist/index.cjs +120 -18
  5. package/dist/index.d.mts +206 -56
  6. package/dist/index.d.ts +1 -0
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +1 -0
  9. package/dist/index.mjs +114 -19
  10. package/dist/plugins/eventEmission/builders.js +3 -3
  11. package/dist/plugins/eventEmission/builders.test.d.ts +2 -0
  12. package/dist/plugins/eventEmission/builders.test.d.ts.map +1 -0
  13. package/dist/plugins/eventEmission/builders.test.js +56 -0
  14. package/dist/plugins/eventEmission/types.d.ts +3 -0
  15. package/dist/plugins/eventEmission/types.d.ts.map +1 -1
  16. package/dist/plugins/findFirstConnection/schemas.d.ts +1 -1
  17. package/dist/plugins/findUniqueConnection/schemas.d.ts +1 -1
  18. package/dist/plugins/getAction/index.d.ts.map +1 -1
  19. package/dist/plugins/getAction/index.js +7 -0
  20. package/dist/plugins/getInputFieldsSchema/index.d.ts.map +1 -1
  21. package/dist/plugins/getInputFieldsSchema/index.js +6 -0
  22. package/dist/plugins/listActions/index.d.ts.map +1 -1
  23. package/dist/plugins/listActions/index.js +6 -0
  24. package/dist/plugins/listConnections/index.d.ts.map +1 -1
  25. package/dist/plugins/listConnections/index.js +2 -0
  26. package/dist/plugins/listConnections/schemas.d.ts +1 -1
  27. package/dist/plugins/listInputFieldChoices/index.d.ts.map +1 -1
  28. package/dist/plugins/listInputFieldChoices/index.js +6 -0
  29. package/dist/plugins/listInputFields/index.d.ts.map +1 -1
  30. package/dist/plugins/listInputFields/index.js +6 -0
  31. package/dist/plugins/runAction/index.d.ts.map +1 -1
  32. package/dist/plugins/runAction/index.js +12 -8
  33. package/dist/schemas/Action.d.ts +2 -2
  34. package/dist/types/credentials.d.ts +137 -17
  35. package/dist/types/credentials.d.ts.map +1 -1
  36. package/dist/types/credentials.js +80 -0
  37. package/dist/types/meta.d.ts +9 -0
  38. package/dist/types/meta.d.ts.map +1 -0
  39. package/dist/types/meta.js +3 -0
  40. package/dist/types/sdk.d.ts +61 -35
  41. package/dist/types/sdk.d.ts.map +1 -1
  42. package/dist/types/sdk.js +55 -1
  43. package/dist/utils/telemetry-context.d.ts +12 -0
  44. package/dist/utils/telemetry-context.d.ts.map +1 -1
  45. package/dist/utils/telemetry-context.js +18 -0
  46. package/dist/utils/telemetry-context.test.js +63 -1
  47. package/dist/utils/telemetry-utils.d.ts.map +1 -1
  48. package/dist/utils/telemetry-utils.js +5 -0
  49. package/dist/utils/telemetry-utils.test.js +61 -0
  50. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @zapier/zapier-sdk
2
2
 
3
+ ## 0.31.1
4
+
5
+ ### Patch Changes
6
+
7
+ - b0f273f: Enrich MethodCalledEvent with selected_api, operation_type, operation_key
8
+
9
+ ## 0.31.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 4a874c6: Add Zod schema for base SDK options, autodoc generation for SDK factory options and CLI base command options
14
+
3
15
  ## 0.30.0
4
16
 
5
17
  ### Minor Changes
package/README.md CHANGED
@@ -6,6 +6,7 @@
6
6
  - [Documentation](#documentation)
7
7
  - [Installation](#installation)
8
8
  - [Quick Start](#quick-start)
9
+ - [Factory](#factory)
9
10
  - [Available Functions](#available-functions)
10
11
  - [Accounts](#accounts)
11
12
  - [`getProfile`](#getprofile)
@@ -289,6 +290,19 @@ const emojiData = await emojiResponse.json();
289
290
  console.log(emojiData.emoji);
290
291
  ```
291
292
 
293
+ ## Factory
294
+
295
+ The `createZapierSdk(...)` factory function is the main entry point for the SDK. It provides methods for managing connections, listing apps, running actions, and more.
296
+
297
+ | Name | Type | Required | Default | Possible Values | Description |
298
+ | ------------------------ | -------------------------- | -------- | ------- | --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
299
+ | `credentials` | `string, object, function` | ❌ | — | — | Authentication credentials. Can be a string (token or API key), a client credentials object ({ clientId, clientSecret }), a PKCE object ({ clientId }), or a function returning any of those. |
300
+ | `debug` | `boolean` | ❌ | — | — | Enable debug logging. |
301
+ | `baseUrl` | `string` | ❌ | — | — | Base URL for Zapier API endpoints. |
302
+ | `trackingBaseUrl` | `string` | ❌ | — | — | Base URL for Zapier tracking endpoints. |
303
+ | `maxNetworkRetries` | `number` | ❌ | — | — | Max retries for rate-limited requests (default: 3). |
304
+ | `maxNetworkRetryDelayMs` | `number` | ❌ | — | — | Max delay in ms to wait for retry (default: 60000). |
305
+
292
306
  ## Available Functions
293
307
 
294
308
  ### Accounts
@@ -872,15 +886,15 @@ Make authenticated HTTP requests to any API through Zapier. Pass a connectionId
872
886
 
873
887
  **Parameters:**
874
888
 
875
- | Name | Type | Required | Default | Possible Values | Description |
876
- | ---------------- | -------------------------------- | -------- | ------- | ---------------------------------------------------------- | --------------------------------------------------------------------------------------------------- |
877
- | `url` | `string, custom` | ✅ | — | — | The full URL of the API endpoint to call (proxied through Zapier's Relay service) |
878
- | `init` | `object` | ❌ | — | — | Request options including method, headers, body, and authentication |
879
- | ↳ `method` | `string` | ❌ | — | `GET`, `POST`, `PUT`, `DELETE`, `PATCH`, `HEAD`, `OPTIONS` | HTTP method for the request (defaults to GET) |
880
- | ↳ `headers` | `object` | ❌ | — | — | HTTP headers to include in the request |
881
- | ↳ `body` | `string, custom, custom, record` | ❌ | — | — | Request body — plain objects and JSON strings are auto-detected and Content-Type is set accordingly |
882
- | ↳ `connectionId` | `string, number` | ❌ | — | — | Connection ID to use for this action |
883
- | ↳ `callbackUrl` | `string` | ❌ | — | — | URL to send async response to (makes request async) |
889
+ | Name | Type | Required | Default | Possible Values | Description |
890
+ | ---------------- | ------------------------ | -------- | ------- | ---------------------------------------------------------- | --------------------------------------------------------------------------------------------------- |
891
+ | `url` | `string, custom` | ✅ | — | — | The full URL of the API endpoint to call (proxied through Zapier's Relay service) |
892
+ | `init` | `object` | ❌ | — | — | Request options including method, headers, body, and authentication |
893
+ | ↳ `method` | `string` | ❌ | — | `GET`, `POST`, `PUT`, `DELETE`, `PATCH`, `HEAD`, `OPTIONS` | HTTP method for the request (defaults to GET) |
894
+ | ↳ `headers` | `object` | ❌ | — | — | HTTP headers to include in the request |
895
+ | ↳ `body` | `string, custom, record` | ❌ | — | — | Request body — plain objects and JSON strings are auto-detected and Content-Type is set accordingly |
896
+ | ↳ `connectionId` | `string, number` | ❌ | — | — | Connection ID to use for this action |
897
+ | ↳ `callbackUrl` | `string` | ❌ | — | — | URL to send async response to (makes request async) |
884
898
 
885
899
  **Returns:** `Promise<Response>`
886
900
 
@@ -42,8 +42,8 @@ export declare const NeedSchema: z.ZodObject<{
42
42
  type: z.ZodOptional<z.ZodEnum<{
43
43
  string: "string";
44
44
  boolean: "boolean";
45
- filter: "filter";
46
45
  file: "file";
46
+ filter: "filter";
47
47
  integer: "integer";
48
48
  text: "text";
49
49
  datetime: "datetime";
@@ -286,8 +286,8 @@ export declare const NeedsResponseSchema: z.ZodObject<{
286
286
  type: z.ZodOptional<z.ZodEnum<{
287
287
  string: "string";
288
288
  boolean: "boolean";
289
- filter: "filter";
290
289
  file: "file";
290
+ filter: "filter";
291
291
  integer: "integer";
292
292
  text: "text";
293
293
  datetime: "datetime";
package/dist/index.cjs CHANGED
@@ -491,6 +491,16 @@ function runWithTelemetryContext(fn) {
491
491
  const currentDepth = telemetryStore.getStore()?.depth ?? -1;
492
492
  return telemetryStore.run({ depth: currentDepth + 1 }, fn);
493
493
  }
494
+ function setMethodMetadata(metadata) {
495
+ if (!telemetryStore) return;
496
+ const store = telemetryStore.getStore();
497
+ if (!store) return;
498
+ store.methodMetadata = { ...store.methodMetadata, ...metadata };
499
+ }
500
+ function getMethodMetadata() {
501
+ if (!telemetryStore) return void 0;
502
+ return telemetryStore.getStore()?.methodMetadata;
503
+ }
494
504
 
495
505
  // src/plugins/fetch/index.ts
496
506
  function transformUrlToRelayPath(url) {
@@ -1043,6 +1053,7 @@ var AppItemSchema = withFormatter(apps.AppItemSchema, {
1043
1053
  function createTelemetryCallback(emitMethodCalled, methodName) {
1044
1054
  return {
1045
1055
  onMethodCalled: (data) => {
1056
+ const metadata = getMethodMetadata();
1046
1057
  emitMethodCalled({
1047
1058
  method_name: methodName,
1048
1059
  execution_duration_ms: data.durationMs,
@@ -1050,7 +1061,10 @@ function createTelemetryCallback(emitMethodCalled, methodName) {
1050
1061
  error_message: data.error?.message ?? null,
1051
1062
  error_type: data.error?.constructor.name ?? null,
1052
1063
  argument_count: data.argumentCount,
1053
- is_paginated: data.isPaginated
1064
+ is_paginated: data.isPaginated,
1065
+ selected_api: metadata?.selectedApi ?? null,
1066
+ operation_type: metadata?.operationType ?? null,
1067
+ operation_key: metadata?.operationKey ?? null
1054
1068
  });
1055
1069
  }
1056
1070
  };
@@ -1790,6 +1804,10 @@ var listActionsPlugin = ({ context }) => {
1790
1804
  { configType: "current_implementation_id" }
1791
1805
  );
1792
1806
  }
1807
+ setMethodMetadata({
1808
+ selectedApi,
1809
+ operationType: options.actionType ?? null
1810
+ });
1793
1811
  const searchParams = {
1794
1812
  global: "true",
1795
1813
  public_only: "true",
@@ -2168,6 +2186,11 @@ var listInputFieldsPlugin = ({ sdk, context }) => {
2168
2186
  { configType: "current_implementation_id" }
2169
2187
  );
2170
2188
  }
2189
+ setMethodMetadata({
2190
+ selectedApi,
2191
+ operationType: actionType,
2192
+ operationKey: actionKey
2193
+ });
2171
2194
  const { data: action } = await sdk.getAction({
2172
2195
  appKey,
2173
2196
  actionType,
@@ -2287,6 +2310,7 @@ var listConnectionsPlugin = ({ context }) => {
2287
2310
  options.appKey
2288
2311
  );
2289
2312
  if (implementationId) {
2313
+ setMethodMetadata({ selectedApi: implementationId });
2290
2314
  const [versionlessSelectedApi] = splitVersionedKey(implementationId);
2291
2315
  searchParams.app_key = versionlessSelectedApi;
2292
2316
  } else {
@@ -2653,6 +2677,10 @@ var GetActionSchema = zod.z.object({
2653
2677
  var getActionPlugin = ({ sdk, context }) => {
2654
2678
  async function getAction(options) {
2655
2679
  const { actionKey, actionType, appKey } = options;
2680
+ setMethodMetadata({
2681
+ operationType: actionType,
2682
+ operationKey: actionKey
2683
+ });
2656
2684
  for await (const action of sdk.listActions({ appKey }).items()) {
2657
2685
  if ((action.key === actionKey || action.id === actionKey) && action.action_type === actionType) {
2658
2686
  return { data: action };
@@ -2862,8 +2890,7 @@ var RunActionSchema = zod.z.object({
2862
2890
  async function executeAction(actionOptions) {
2863
2891
  const {
2864
2892
  api,
2865
- context,
2866
- appKey,
2893
+ selectedApi,
2867
2894
  actionId,
2868
2895
  actionKey,
2869
2896
  actionType,
@@ -2871,13 +2898,6 @@ async function executeAction(actionOptions) {
2871
2898
  connectionId,
2872
2899
  timeoutMs
2873
2900
  } = actionOptions;
2874
- const selectedApi = await context.getVersionedImplementationId(appKey);
2875
- if (!selectedApi) {
2876
- throw new ZapierConfigurationError(
2877
- "No current_implementation_id found for app",
2878
- { configType: "current_implementation_id" }
2879
- );
2880
- }
2881
2901
  const runRequestData = {
2882
2902
  selected_api: selectedApi,
2883
2903
  action_id: actionId,
@@ -2920,6 +2940,18 @@ var runActionPlugin = ({ sdk, context }) => {
2920
2940
  timeoutMs
2921
2941
  } = options;
2922
2942
  const resolvedConnectionId = connectionId ?? authenticationId;
2943
+ const selectedApi = await context.getVersionedImplementationId(appKey);
2944
+ if (!selectedApi) {
2945
+ throw new ZapierConfigurationError(
2946
+ "No current_implementation_id found for app",
2947
+ { configType: "current_implementation_id" }
2948
+ );
2949
+ }
2950
+ setMethodMetadata({
2951
+ selectedApi,
2952
+ operationType: actionType,
2953
+ operationKey: actionKey
2954
+ });
2923
2955
  const actionData = await sdk.getAction({
2924
2956
  appKey,
2925
2957
  actionKey,
@@ -2933,8 +2965,7 @@ var runActionPlugin = ({ sdk, context }) => {
2933
2965
  const actionId = actionData.data.id;
2934
2966
  const result = await executeAction({
2935
2967
  api,
2936
- context,
2937
- appKey,
2968
+ selectedApi,
2938
2969
  // Some actions require the action ID to run them, but technically the ID is not guaranteed to be available when
2939
2970
  // we retrieve actions (probably legacy reasons), so we just pass along all the things!
2940
2971
  actionId,
@@ -3919,8 +3950,34 @@ async function pollUntilComplete(options) {
3919
3950
  }
3920
3951
  }
3921
3952
  }
3922
-
3923
- // src/types/credentials.ts
3953
+ var ClientCredentialsObjectSchema = zod.z.object({
3954
+ type: zod.z.enum(["client_credentials"]).optional().meta({ internal: true }),
3955
+ clientId: zod.z.string().describe("OAuth client ID for authentication.").meta({ valueHint: "id" }),
3956
+ clientSecret: zod.z.string().describe("OAuth client secret for authentication.").meta({ valueHint: "secret" }),
3957
+ baseUrl: zod.z.string().optional().describe("Override authentication base URL.").meta({ valueHint: "url" }),
3958
+ scope: zod.z.string().optional().describe("Authentication scope.").meta({ internal: true })
3959
+ });
3960
+ var PkceCredentialsObjectSchema = zod.z.object({
3961
+ type: zod.z.enum(["pkce"]).optional().meta({ internal: true }),
3962
+ clientId: zod.z.string().describe("OAuth client ID for authentication.").meta({ valueHint: "id" }),
3963
+ baseUrl: zod.z.string().optional().describe("Override authentication base URL.").meta({ valueHint: "url" }),
3964
+ scope: zod.z.string().optional().describe("Authentication scope.").meta({ internal: true })
3965
+ });
3966
+ var CredentialsObjectSchema = zod.z.union([
3967
+ ClientCredentialsObjectSchema,
3968
+ PkceCredentialsObjectSchema
3969
+ ]);
3970
+ var ResolvedCredentialsSchema = zod.z.union([
3971
+ zod.z.string().describe("Authentication token.").meta({ valueHint: "token" }),
3972
+ CredentialsObjectSchema
3973
+ ]);
3974
+ var CredentialsFunctionSchema = zod.z.function().input([]).output(
3975
+ zod.z.union([ResolvedCredentialsSchema, zod.z.promise(ResolvedCredentialsSchema)])
3976
+ );
3977
+ var CredentialsSchema = zod.z.union([
3978
+ ResolvedCredentialsSchema,
3979
+ CredentialsFunctionSchema
3980
+ ]);
3924
3981
  function isClientCredentials(credentials) {
3925
3982
  return typeof credentials === "object" && credentials !== null && "clientId" in credentials && "clientSecret" in credentials;
3926
3983
  }
@@ -5032,6 +5089,11 @@ var getInputFieldsSchemaPlugin = ({ sdk, context }) => {
5032
5089
  { configType: "current_implementation_id" }
5033
5090
  );
5034
5091
  }
5092
+ setMethodMetadata({
5093
+ selectedApi,
5094
+ operationType: actionType,
5095
+ operationKey: actionKey
5096
+ });
5035
5097
  const { data: action } = await sdk.getAction({
5036
5098
  appKey,
5037
5099
  actionType,
@@ -5151,6 +5213,11 @@ var listInputFieldChoicesPlugin = ({ context, sdk }) => {
5151
5213
  { configType: "current_implementation_id" }
5152
5214
  );
5153
5215
  }
5216
+ setMethodMetadata({
5217
+ selectedApi,
5218
+ operationType: actionType,
5219
+ operationKey: actionKey
5220
+ });
5154
5221
  const { data: action } = await sdk.getAction({
5155
5222
  appKey,
5156
5223
  actionType,
@@ -5402,7 +5469,7 @@ function getCpuTime() {
5402
5469
 
5403
5470
  // package.json
5404
5471
  var package_default = {
5405
- version: "0.30.0"};
5472
+ version: "0.31.1"};
5406
5473
 
5407
5474
  // src/plugins/eventEmission/builders.ts
5408
5475
  function createBaseEvent(context = {}) {
@@ -5483,13 +5550,13 @@ function buildMethodCalledEvent(data, context = {}) {
5483
5550
  is_paginated: data.is_paginated ?? false,
5484
5551
  sdk_version: package_default.version,
5485
5552
  environment: context.environment ?? (process?.env?.NODE_ENV || null),
5486
- selected_api: context.selected_api ?? null,
5553
+ selected_api: data.selected_api ?? context.selected_api ?? null,
5487
5554
  app_id: context.app_id ?? null,
5488
5555
  app_version_id: context.app_version_id ?? null,
5489
5556
  zap_id: context.zap_id ?? null,
5490
5557
  node_id: context.node_id ?? null,
5491
- operation_type: null,
5492
- operation_key: null,
5558
+ operation_type: data.operation_type ?? null,
5559
+ operation_key: data.operation_key ?? null,
5493
5560
  call_context: null,
5494
5561
  is_retry: false,
5495
5562
  retry_attempt: null,
@@ -5861,13 +5928,46 @@ function createZapierSdkWithoutRegistry(options = {}) {
5861
5928
  function createZapierSdk(options = {}) {
5862
5929
  return createZapierSdkWithoutRegistry(options).addPlugin(registryPlugin);
5863
5930
  }
5931
+ var BaseSdkOptionsSchema = zod.z.object({
5932
+ credentials: CredentialsSchema.optional().describe(
5933
+ "Authentication credentials. Can be a string (token or API key), a client credentials object ({ clientId, clientSecret }), a PKCE object ({ clientId }), or a function returning any of those."
5934
+ ),
5935
+ debug: zod.z.boolean().optional().describe("Enable debug logging."),
5936
+ baseUrl: zod.z.string().optional().describe("Base URL for Zapier API endpoints.").meta({ valueHint: "url" }),
5937
+ trackingBaseUrl: zod.z.string().optional().describe("Base URL for Zapier tracking endpoints.").meta({ valueHint: "url" }),
5938
+ /**
5939
+ * Maximum number of retries for rate-limited requests (429 responses).
5940
+ * Set to 0 to disable retries. Default is 3.
5941
+ */
5942
+ maxNetworkRetries: zod.z.number().optional().describe("Max retries for rate-limited requests (default: 3).").meta({ valueHint: "count" }),
5943
+ /**
5944
+ * Maximum delay in milliseconds to wait for a rate limit retry.
5945
+ * If the server requests a longer delay, the request fails immediately.
5946
+ * Default is 60000 (60 seconds).
5947
+ */
5948
+ maxNetworkRetryDelayMs: zod.z.number().optional().describe("Max delay in ms to wait for retry (default: 60000).").meta({ valueHint: "ms" }),
5949
+ // Internal
5950
+ manifestPath: zod.z.string().optional().describe("Path to a .zapierrc manifest file for app version locking.").meta({ internal: true }),
5951
+ manifest: zod.z.custom().optional().describe("Manifest for app version locking.").meta({ internal: true }),
5952
+ onEvent: zod.z.custom().optional().meta({ internal: true }),
5953
+ fetch: zod.z.custom().optional().meta({ internal: true }),
5954
+ eventEmission: zod.z.custom().optional().meta({ internal: true }),
5955
+ // Deprecated
5956
+ token: zod.z.string().optional().meta({ deprecated: true })
5957
+ // Use credentials instead
5958
+ });
5864
5959
 
5865
5960
  exports.ActionKeyPropertySchema = ActionKeyPropertySchema;
5866
5961
  exports.ActionTimeoutMsPropertySchema = ActionTimeoutMsPropertySchema;
5867
5962
  exports.ActionTypePropertySchema = ActionTypePropertySchema;
5868
5963
  exports.AppKeyPropertySchema = AppKeyPropertySchema;
5869
5964
  exports.AuthenticationIdPropertySchema = AuthenticationIdPropertySchema;
5965
+ exports.BaseSdkOptionsSchema = BaseSdkOptionsSchema;
5966
+ exports.ClientCredentialsObjectSchema = ClientCredentialsObjectSchema;
5870
5967
  exports.ConnectionIdPropertySchema = ConnectionIdPropertySchema;
5968
+ exports.CredentialsFunctionSchema = CredentialsFunctionSchema;
5969
+ exports.CredentialsObjectSchema = CredentialsObjectSchema;
5970
+ exports.CredentialsSchema = CredentialsSchema;
5871
5971
  exports.DEFAULT_ACTION_TIMEOUT_MS = DEFAULT_ACTION_TIMEOUT_MS;
5872
5972
  exports.DEFAULT_CONFIG_PATH = DEFAULT_CONFIG_PATH;
5873
5973
  exports.DebugPropertySchema = DebugPropertySchema;
@@ -5877,8 +5977,10 @@ exports.MAX_PAGE_LIMIT = MAX_PAGE_LIMIT;
5877
5977
  exports.OffsetPropertySchema = OffsetPropertySchema;
5878
5978
  exports.OutputPropertySchema = OutputPropertySchema;
5879
5979
  exports.ParamsPropertySchema = ParamsPropertySchema;
5980
+ exports.PkceCredentialsObjectSchema = PkceCredentialsObjectSchema;
5880
5981
  exports.RelayFetchSchema = RelayFetchSchema;
5881
5982
  exports.RelayRequestSchema = RelayRequestSchema;
5983
+ exports.ResolvedCredentialsSchema = ResolvedCredentialsSchema;
5882
5984
  exports.ZAPIER_AUTH_BASE_URL = ZAPIER_AUTH_BASE_URL;
5883
5985
  exports.ZAPIER_AUTH_CLIENT_ID = ZAPIER_AUTH_CLIENT_ID;
5884
5986
  exports.ZAPIER_BASE_URL = ZAPIER_BASE_URL;