@zapier/zapier-sdk 0.31.0 → 0.31.2

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 (41) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/api/client.d.ts.map +1 -1
  3. package/dist/api/client.js +15 -2
  4. package/dist/auth.d.ts +7 -3
  5. package/dist/auth.d.ts.map +1 -1
  6. package/dist/auth.js +43 -12
  7. package/dist/auth.test.js +10 -1
  8. package/dist/index.cjs +82 -22
  9. package/dist/index.d.mts +11 -4
  10. package/dist/index.mjs +82 -23
  11. package/dist/plugins/eventEmission/builders.js +3 -3
  12. package/dist/plugins/eventEmission/builders.test.d.ts +2 -0
  13. package/dist/plugins/eventEmission/builders.test.d.ts.map +1 -0
  14. package/dist/plugins/eventEmission/builders.test.js +56 -0
  15. package/dist/plugins/eventEmission/index.test.js +3 -0
  16. package/dist/plugins/eventEmission/types.d.ts +3 -0
  17. package/dist/plugins/eventEmission/types.d.ts.map +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/listApps/index.test.js +4 -1
  25. package/dist/plugins/listConnections/index.d.ts.map +1 -1
  26. package/dist/plugins/listConnections/index.js +2 -0
  27. package/dist/plugins/listConnections/index.test.js +4 -1
  28. package/dist/plugins/listInputFieldChoices/index.d.ts.map +1 -1
  29. package/dist/plugins/listInputFieldChoices/index.js +6 -0
  30. package/dist/plugins/listInputFields/index.d.ts.map +1 -1
  31. package/dist/plugins/listInputFields/index.js +6 -0
  32. package/dist/plugins/runAction/index.d.ts.map +1 -1
  33. package/dist/plugins/runAction/index.js +12 -8
  34. package/dist/utils/telemetry-context.d.ts +12 -0
  35. package/dist/utils/telemetry-context.d.ts.map +1 -1
  36. package/dist/utils/telemetry-context.js +18 -0
  37. package/dist/utils/telemetry-context.test.js +63 -1
  38. package/dist/utils/telemetry-utils.d.ts.map +1 -1
  39. package/dist/utils/telemetry-utils.js +5 -0
  40. package/dist/utils/telemetry-utils.test.js +61 -0
  41. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @zapier/zapier-sdk
2
2
 
3
+ ## 0.31.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 1ae0349: Improve error message when credentials can't be found. Also improve module resolution for login module.
8
+
9
+ ## 0.31.1
10
+
11
+ ### Patch Changes
12
+
13
+ - b0f273f: Enrich MethodCalledEvent with selected_api, operation_type, operation_key
14
+
3
15
  ## 0.31.0
4
16
 
5
17
  ### Minor Changes
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,SAAS,EACT,gBAAgB,EAGjB,MAAM,SAAS,CAAC;AA2nBjB,eAAO,MAAM,eAAe,GAAI,SAAS,gBAAgB,KAAG,SAW3D,CAAC"}
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,SAAS,EACT,gBAAgB,EAGjB,MAAM,SAAS,CAAC;AA2oBjB,eAAO,MAAM,eAAe,GAAI,SAAS,gBAAgB,KAAG,SAW3D,CAAC"}
@@ -7,7 +7,7 @@
7
7
  import { getAuthorizationHeader } from "./auth";
8
8
  import { createDebugLogger, createDebugFetch } from "./debug";
9
9
  import { pollUntilComplete } from "./polling";
10
- import { resolveAuthToken, invalidateCredentialsToken } from "../auth";
10
+ import { resolveAuthToken, invalidateCredentialsToken, isCliLoginAvailable, } from "../auth";
11
11
  import { getZapierBaseUrl } from "../utils/url-utils";
12
12
  import { sleep, calculateExponentialBackoffMs } from "../utils/retry-utils";
13
13
  import { isPlainObject } from "../utils/type-guard-utils";
@@ -421,7 +421,20 @@ class ZapierApiClient {
421
421
  // before we even make a request.
422
422
  if (options.authRequired) {
423
423
  if (headers.get("Authorization") == null && authToken == null) {
424
- throw new ZapierAuthenticationError(`Authentication required but no credentials available. Please set ZAPIER_CREDENTIALS, or run the 'login' command with the CLI.`);
424
+ const message = isCliLoginAvailable() === false
425
+ ? "Authentication required but no credentials available. " +
426
+ "To use CLI login, install the CLI as a dev dependency " +
427
+ "(e.g. `npm install -D @zapier/zapier-sdk-cli`) and " +
428
+ "log in (e.g. `npx zapier-sdk login`). " +
429
+ "Alternatively, set the ZAPIER_CREDENTIALS environment variable " +
430
+ "or ZAPIER_CREDENTIALS_CLIENT_ID and " +
431
+ "ZAPIER_CREDENTIALS_CLIENT_SECRET environment variables."
432
+ : "Authentication required but no credentials available. " +
433
+ "Please log in (e.g. `npx zapier-sdk login`) or set the " +
434
+ "ZAPIER_CREDENTIALS environment variable or " +
435
+ "ZAPIER_CREDENTIALS_CLIENT_ID and " +
436
+ "ZAPIER_CREDENTIALS_CLIENT_SECRET environment variables.";
437
+ throw new ZapierAuthenticationError(message);
425
438
  }
426
439
  }
427
440
  return headers;
package/dist/auth.d.ts CHANGED
@@ -56,10 +56,14 @@ interface CliLoginOptions {
56
56
  debug?: boolean;
57
57
  }
58
58
  /**
59
- * Attempts to get a token by optionally importing from CLI login package.
60
- * This provides a graceful fallback when the CLI login package is not available.
59
+ * Returns whether a CLI login package is available.
60
+ * `undefined` if no import has been attempted yet, `true` if found, `false` if not.
61
+ */
62
+ export declare function isCliLoginAvailable(): boolean | undefined;
63
+ /**
64
+ * Attempts to get a token from the CLI login package.
61
65
  *
62
- * Returns undefined if no valid token is found or CLI package is not available.
66
+ * Returns undefined if no valid token is found or no login package is available.
63
67
  * Throws if there's an actual error (like token refresh failure).
64
68
  */
65
69
  export declare function getTokenFromCliLogin(options: CliLoginOptions): Promise<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B,GAAG,OAAO,CAAC,IAAI,CAAC,CAQhB"}
package/dist/auth.js CHANGED
@@ -36,6 +36,7 @@ function buildCacheKey(clientId, scopes) {
36
36
  export function clearTokenCache() {
37
37
  tokenCache.clear();
38
38
  pendingExchanges.clear();
39
+ cachedCliLogin = undefined;
39
40
  }
40
41
  const TOKEN_EXPIRATION_BUFFER = 5 * 60 * 1000; // 5 minutes
41
42
  /**
@@ -169,26 +170,56 @@ async function exchangeClientCredentials(options) {
169
170
  });
170
171
  return data.access_token;
171
172
  }
173
+ let cachedCliLogin;
172
174
  /**
173
- * Attempts to get a token by optionally importing from CLI login package.
174
- * This provides a graceful fallback when the CLI login package is not available.
175
+ * Dynamically imports a CLI login package with caching.
175
176
  *
176
- * Returns undefined if no valid token is found or CLI package is not available.
177
- * Throws if there's an actual error (like token refresh failure).
177
+ * Tries `@zapier/zapier-sdk-cli/login` first (available when the CLI is a
178
+ * direct dependency), then falls back to `@zapier/zapier-sdk-cli-login` (for
179
+ * users who install the lightweight login package directly).
180
+ *
181
+ * Returns the module if found, or `undefined` if neither package is available.
182
+ * The result is cached after the first attempt.
178
183
  */
179
- export async function getTokenFromCliLogin(options) {
180
- // Dynamically import the CLI login package if available.
181
- // This is intentionally an async import because this module is a dependency
182
- // of the CLI and is only available when the CLI is installed!
183
- let cliLogin;
184
+ async function getCliLogin() {
185
+ if (cachedCliLogin !== undefined) {
186
+ return cachedCliLogin || undefined;
187
+ }
188
+ try {
189
+ cachedCliLogin = await import("@zapier/zapier-sdk-cli/login");
190
+ return cachedCliLogin;
191
+ }
192
+ catch {
193
+ // First path not available, try fallback
194
+ }
184
195
  try {
185
- cliLogin = await import("@zapier/zapier-sdk-cli-login");
196
+ cachedCliLogin = await import("@zapier/zapier-sdk-cli-login");
197
+ return cachedCliLogin;
186
198
  }
187
199
  catch {
188
- // CLI login package is not available, return undefined
200
+ cachedCliLogin = false;
189
201
  return undefined;
190
202
  }
191
- // Call getToken - let any errors (like refresh failures) propagate
203
+ }
204
+ /**
205
+ * Returns whether a CLI login package is available.
206
+ * `undefined` if no import has been attempted yet, `true` if found, `false` if not.
207
+ */
208
+ export function isCliLoginAvailable() {
209
+ if (cachedCliLogin === undefined)
210
+ return undefined;
211
+ return cachedCliLogin !== false;
212
+ }
213
+ /**
214
+ * Attempts to get a token from the CLI login package.
215
+ *
216
+ * Returns undefined if no valid token is found or no login package is available.
217
+ * Throws if there's an actual error (like token refresh failure).
218
+ */
219
+ export async function getTokenFromCliLogin(options) {
220
+ const cliLogin = await getCliLogin();
221
+ if (!cliLogin)
222
+ return undefined;
192
223
  return await cliLogin.getToken(options);
193
224
  }
194
225
  /**
package/dist/auth.test.js CHANGED
@@ -1,8 +1,12 @@
1
1
  import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
2
2
  import * as auth from "./auth";
3
3
  import { resetDeprecationWarnings } from "./utils/logging";
4
- // Mock the CLI login package
4
+ // Mock both CLI login import paths (SDK tries @zapier/zapier-sdk-cli/login
5
+ // first, then falls back to @zapier/zapier-sdk-cli-login)
5
6
  const mockGetToken = vi.fn();
7
+ vi.mock("@zapier/zapier-sdk-cli/login", () => ({
8
+ getToken: mockGetToken,
9
+ }));
6
10
  vi.mock("@zapier/zapier-sdk-cli-login", () => ({
7
11
  getToken: mockGetToken,
8
12
  }));
@@ -41,6 +45,11 @@ describe("auth", () => {
41
45
  mockGetToken.mockRejectedValue(new Error("Token refresh failed"));
42
46
  await expect(auth.getTokenFromCliLogin({})).rejects.toThrow("Token refresh failed");
43
47
  });
48
+ it("should set isCliLoginAvailable to true when import succeeds", async () => {
49
+ mockGetToken.mockResolvedValue("cli-token");
50
+ await auth.getTokenFromCliLogin({});
51
+ expect(auth.isCliLoginAvailable()).toBe(true);
52
+ });
44
53
  });
45
54
  describe("resolveAuthToken", () => {
46
55
  it("should return string credentials directly", async () => {
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,
@@ -4137,6 +4168,7 @@ function buildCacheKey(clientId, scopes) {
4137
4168
  function clearTokenCache() {
4138
4169
  tokenCache.clear();
4139
4170
  pendingExchanges.clear();
4171
+ cachedCliLogin = void 0;
4140
4172
  }
4141
4173
  var TOKEN_EXPIRATION_BUFFER = 5 * 60 * 1e3;
4142
4174
  function getCachedToken(clientId, scopes) {
@@ -4241,13 +4273,31 @@ async function exchangeClientCredentials(options) {
4241
4273
  });
4242
4274
  return data.access_token;
4243
4275
  }
4244
- async function getTokenFromCliLogin(options) {
4245
- let cliLogin;
4276
+ var cachedCliLogin;
4277
+ async function getCliLogin() {
4278
+ if (cachedCliLogin !== void 0) {
4279
+ return cachedCliLogin || void 0;
4280
+ }
4246
4281
  try {
4247
- cliLogin = await import('@zapier/zapier-sdk-cli-login');
4282
+ cachedCliLogin = await import('@zapier/zapier-sdk-cli/login');
4283
+ return cachedCliLogin;
4248
4284
  } catch {
4285
+ }
4286
+ try {
4287
+ cachedCliLogin = await import('@zapier/zapier-sdk-cli-login');
4288
+ return cachedCliLogin;
4289
+ } catch {
4290
+ cachedCliLogin = false;
4249
4291
  return void 0;
4250
4292
  }
4293
+ }
4294
+ function isCliLoginAvailable() {
4295
+ if (cachedCliLogin === void 0) return void 0;
4296
+ return cachedCliLogin !== false;
4297
+ }
4298
+ async function getTokenFromCliLogin(options) {
4299
+ const cliLogin = await getCliLogin();
4300
+ if (!cliLogin) return void 0;
4251
4301
  return await cliLogin.getToken(options);
4252
4302
  }
4253
4303
  async function resolveAuthToken(options = {}) {
@@ -4673,9 +4723,8 @@ var ZapierApiClient = class {
4673
4723
  }
4674
4724
  if (options.authRequired) {
4675
4725
  if (headers.get("Authorization") == null && authToken == null) {
4676
- throw new ZapierAuthenticationError(
4677
- `Authentication required but no credentials available. Please set ZAPIER_CREDENTIALS, or run the 'login' command with the CLI.`
4678
- );
4726
+ const message = isCliLoginAvailable() === false ? "Authentication required but no credentials available. To use CLI login, install the CLI as a dev dependency (e.g. `npm install -D @zapier/zapier-sdk-cli`) and log in (e.g. `npx zapier-sdk login`). Alternatively, set the ZAPIER_CREDENTIALS environment variable or ZAPIER_CREDENTIALS_CLIENT_ID and ZAPIER_CREDENTIALS_CLIENT_SECRET environment variables." : "Authentication required but no credentials available. Please log in (e.g. `npx zapier-sdk login`) or set the ZAPIER_CREDENTIALS environment variable or ZAPIER_CREDENTIALS_CLIENT_ID and ZAPIER_CREDENTIALS_CLIENT_SECRET environment variables.";
4727
+ throw new ZapierAuthenticationError(message);
4679
4728
  }
4680
4729
  }
4681
4730
  return headers;
@@ -5058,6 +5107,11 @@ var getInputFieldsSchemaPlugin = ({ sdk, context }) => {
5058
5107
  { configType: "current_implementation_id" }
5059
5108
  );
5060
5109
  }
5110
+ setMethodMetadata({
5111
+ selectedApi,
5112
+ operationType: actionType,
5113
+ operationKey: actionKey
5114
+ });
5061
5115
  const { data: action } = await sdk.getAction({
5062
5116
  appKey,
5063
5117
  actionType,
@@ -5177,6 +5231,11 @@ var listInputFieldChoicesPlugin = ({ context, sdk }) => {
5177
5231
  { configType: "current_implementation_id" }
5178
5232
  );
5179
5233
  }
5234
+ setMethodMetadata({
5235
+ selectedApi,
5236
+ operationType: actionType,
5237
+ operationKey: actionKey
5238
+ });
5180
5239
  const { data: action } = await sdk.getAction({
5181
5240
  appKey,
5182
5241
  actionType,
@@ -5428,7 +5487,7 @@ function getCpuTime() {
5428
5487
 
5429
5488
  // package.json
5430
5489
  var package_default = {
5431
- version: "0.31.0"};
5490
+ version: "0.31.2"};
5432
5491
 
5433
5492
  // src/plugins/eventEmission/builders.ts
5434
5493
  function createBaseEvent(context = {}) {
@@ -5509,13 +5568,13 @@ function buildMethodCalledEvent(data, context = {}) {
5509
5568
  is_paginated: data.is_paginated ?? false,
5510
5569
  sdk_version: package_default.version,
5511
5570
  environment: context.environment ?? (process?.env?.NODE_ENV || null),
5512
- selected_api: context.selected_api ?? null,
5571
+ selected_api: data.selected_api ?? context.selected_api ?? null,
5513
5572
  app_id: context.app_id ?? null,
5514
5573
  app_version_id: context.app_version_id ?? null,
5515
5574
  zap_id: context.zap_id ?? null,
5516
5575
  node_id: context.node_id ?? null,
5517
- operation_type: null,
5518
- operation_key: null,
5576
+ operation_type: data.operation_type ?? null,
5577
+ operation_key: data.operation_key ?? null,
5519
5578
  call_context: null,
5520
5579
  is_retry: false,
5521
5580
  retry_attempt: null,
@@ -6015,6 +6074,7 @@ exports.inputsResolver = inputsResolver;
6015
6074
  exports.invalidateCachedToken = invalidateCachedToken;
6016
6075
  exports.invalidateCredentialsToken = invalidateCredentialsToken;
6017
6076
  exports.isCi = isCi;
6077
+ exports.isCliLoginAvailable = isCliLoginAvailable;
6018
6078
  exports.isClientCredentials = isClientCredentials;
6019
6079
  exports.isCredentialsFunction = isCredentialsFunction;
6020
6080
  exports.isCredentialsObject = isCredentialsObject;
package/dist/index.d.mts CHANGED
@@ -305,6 +305,9 @@ interface MethodCalledEventData {
305
305
  error_type?: string | null;
306
306
  argument_count: number;
307
307
  is_paginated?: boolean;
308
+ selected_api?: string | null;
309
+ operation_type?: string | null;
310
+ operation_key?: string | null;
308
311
  }
309
312
 
310
313
  /**
@@ -2620,10 +2623,14 @@ interface CliLoginOptions {
2620
2623
  debug?: boolean;
2621
2624
  }
2622
2625
  /**
2623
- * Attempts to get a token by optionally importing from CLI login package.
2624
- * This provides a graceful fallback when the CLI login package is not available.
2626
+ * Returns whether a CLI login package is available.
2627
+ * `undefined` if no import has been attempted yet, `true` if found, `false` if not.
2628
+ */
2629
+ declare function isCliLoginAvailable(): boolean | undefined;
2630
+ /**
2631
+ * Attempts to get a token from the CLI login package.
2625
2632
  *
2626
- * Returns undefined if no valid token is found or CLI package is not available.
2633
+ * Returns undefined if no valid token is found or no login package is available.
2627
2634
  * Throws if there's an actual error (like token refresh failure).
2628
2635
  */
2629
2636
  declare function getTokenFromCliLogin(options: CliLoginOptions): Promise<string | undefined>;
@@ -2946,4 +2953,4 @@ declare function createZapierSdkWithoutRegistry(options?: ZapierSdkOptions): Sdk
2946
2953
  }>;
2947
2954
  declare function createZapierSdk(options?: ZapierSdkOptions): ZapierSdk;
2948
2955
 
2949
- export { type Action, type ActionEntry, type ActionExecutionOptions, type ActionExecutionResult, type ActionField, type ActionFieldChoice, type ActionItem$1 as ActionItem, type ActionKeyProperty, ActionKeyPropertySchema, type ActionTimeoutMsProperty, ActionTimeoutMsPropertySchema, type ActionTypeProperty, ActionTypePropertySchema, type AddActionEntryOptions, type AddActionEntryResult, type ApiError, type ApiEvent, type ApiPluginOptions, type ApiPluginProvides, type App, type AppItem, type AppKeyProperty, AppKeyPropertySchema, type ApplicationLifecycleEventData, type AppsPluginProvides, type AuthEvent, type AuthenticationIdProperty, AuthenticationIdPropertySchema, type BaseEvent, BaseSdkOptionsSchema, type BatchOptions, type Choice, type ClientCredentialsObject, ClientCredentialsObjectSchema, type Connection, type ConnectionIdProperty, ConnectionIdPropertySchema, type ConnectionItem, type ConnectionsResponse, type CreateClientCredentialsPluginProvides, type Credentials, type CredentialsFunction, CredentialsFunctionSchema, type CredentialsObject, CredentialsObjectSchema, CredentialsSchema, DEFAULT_ACTION_TIMEOUT_MS, DEFAULT_CONFIG_PATH, type DebugProperty, DebugPropertySchema, type DeleteClientCredentialsPluginProvides, type EnhancedErrorEventData, type ErrorOptions, type EventCallback, type EventContext, type EventEmissionContext, type FetchPluginProvides, type Field, type FieldsetItem, type FindFirstAuthenticationPluginProvides, type FindFirstConnectionPluginProvides, type FindUniqueAuthenticationPluginProvides, type FindUniqueConnectionPluginProvides, type FormatMetadata, type FormattedItem, type FunctionOptions, type FunctionRegistryEntry, type GetActionPluginProvides, type GetAppPluginProvides, type GetAuthenticationPluginProvides, type GetConnectionPluginProvides, type GetContextType, type GetProfilePluginProvides, type GetSdkType, type InfoFieldItem, type InputFieldItem, type InputsProperty, InputsPropertySchema, type LimitProperty, LimitPropertySchema, type ListActionsPluginProvides, type ListAppsPluginProvides, type ListAuthenticationsPluginProvides, type ListClientCredentialsPluginProvides, type ListConnectionsPluginProvides, type ListInputFieldsPluginProvides, type LoadingEvent, MAX_PAGE_LIMIT, type Manifest, type ManifestEntry, type ManifestPluginOptions, type ManifestPluginProvides, type MethodCalledEvent, type MethodCalledEventData, type Need, type NeedsRequest, type NeedsResponse, type OffsetProperty, OffsetPropertySchema, type OutputProperty, OutputPropertySchema, type PaginatedSdkFunction, type ParamsProperty, ParamsPropertySchema, type PkceCredentialsObject, PkceCredentialsObjectSchema, type Plugin, type PluginDependencies, type PluginOptions, type PluginProvides, type PositionalMetadata, type RateLimitInfo, RelayFetchSchema, RelayRequestSchema, type RequestPluginProvides, type ResolveAuthTokenOptions, type ResolveCredentialsOptions, type ResolvedCredentials, ResolvedCredentialsSchema, type RootFieldItem, type RunActionPluginProvides, type Sdk, type SdkEvent, type StaticResolver, type UpdateManifestEntryOptions, type UpdateManifestEntryResult, type UserProfile, type UserProfileItem, ZAPIER_AUTH_BASE_URL, ZAPIER_AUTH_CLIENT_ID, ZAPIER_BASE_URL, ZAPIER_CREDENTIALS, ZAPIER_CREDENTIALS_BASE_URL, ZAPIER_CREDENTIALS_CLIENT_ID, ZAPIER_CREDENTIALS_CLIENT_SECRET, ZAPIER_CREDENTIALS_SCOPE, ZAPIER_MAX_NETWORK_RETRIES, ZAPIER_MAX_NETWORK_RETRY_DELAY_MS, ZAPIER_TOKEN, ZapierActionError, ZapierApiError, ZapierAppNotFoundError, ZapierAuthenticationError, ZapierBundleError, ZapierConfigurationError, ZapierError, type ZapierFetchInitOptions, ZapierNotFoundError, ZapierRateLimitError, ZapierResourceNotFoundError, type ZapierSdk, type ZapierSdkApps, type ZapierSdkOptions, ZapierTimeoutError, ZapierUnknownError, ZapierValidationError, actionKeyResolver, actionTypeResolver, apiPlugin, appKeyResolver, appsPlugin, connectionIdGenericResolver as authenticationIdGenericResolver, connectionIdResolver as authenticationIdResolver, batch, buildApplicationLifecycleEvent, buildErrorEvent, buildErrorEventWithContext, buildMethodCalledEvent, clearTokenCache, clientCredentialsNameResolver, clientIdResolver, connectionIdGenericResolver, connectionIdResolver, createBaseEvent, createClientCredentialsPlugin, createFunction, createSdk, createZapierSdk, createZapierSdkWithoutRegistry, deleteClientCredentialsPlugin, fetchPlugin, findFirstConnectionPlugin, findManifestEntry, findUniqueConnectionPlugin, formatErrorMessage, generateEventId, getActionPlugin, getAppPlugin, getBaseUrlFromCredentials, getCiPlatform, getClientIdFromCredentials, getConnectionPlugin, getCpuTime, getCurrentTimestamp, getMemoryUsage, getOsInfo, getPlatformVersions, getPreferredManifestEntryKey, getProfilePlugin, getReleaseId, getTokenFromCliLogin, inputFieldKeyResolver, inputsAllOptionalResolver, inputsResolver, invalidateCachedToken, invalidateCredentialsToken, isCi, isClientCredentials, isCredentialsFunction, isCredentialsObject, isPkceCredentials, isPositional, listActionsPlugin, listAppsPlugin, listClientCredentialsPlugin, listConnectionsPlugin, listInputFieldsPlugin, logDeprecation, manifestPlugin, readManifestFromFile, registryPlugin, requestPlugin, resetDeprecationWarnings, resolveAuthToken, resolveCredentials, resolveCredentialsFromEnv, runActionPlugin, toSnakeCase, toTitleCase };
2956
+ export { type Action, type ActionEntry, type ActionExecutionOptions, type ActionExecutionResult, type ActionField, type ActionFieldChoice, type ActionItem$1 as ActionItem, type ActionKeyProperty, ActionKeyPropertySchema, type ActionTimeoutMsProperty, ActionTimeoutMsPropertySchema, type ActionTypeProperty, ActionTypePropertySchema, type AddActionEntryOptions, type AddActionEntryResult, type ApiError, type ApiEvent, type ApiPluginOptions, type ApiPluginProvides, type App, type AppItem, type AppKeyProperty, AppKeyPropertySchema, type ApplicationLifecycleEventData, type AppsPluginProvides, type AuthEvent, type AuthenticationIdProperty, AuthenticationIdPropertySchema, type BaseEvent, BaseSdkOptionsSchema, type BatchOptions, type Choice, type ClientCredentialsObject, ClientCredentialsObjectSchema, type Connection, type ConnectionIdProperty, ConnectionIdPropertySchema, type ConnectionItem, type ConnectionsResponse, type CreateClientCredentialsPluginProvides, type Credentials, type CredentialsFunction, CredentialsFunctionSchema, type CredentialsObject, CredentialsObjectSchema, CredentialsSchema, DEFAULT_ACTION_TIMEOUT_MS, DEFAULT_CONFIG_PATH, type DebugProperty, DebugPropertySchema, type DeleteClientCredentialsPluginProvides, type EnhancedErrorEventData, type ErrorOptions, type EventCallback, type EventContext, type EventEmissionContext, type FetchPluginProvides, type Field, type FieldsetItem, type FindFirstAuthenticationPluginProvides, type FindFirstConnectionPluginProvides, type FindUniqueAuthenticationPluginProvides, type FindUniqueConnectionPluginProvides, type FormatMetadata, type FormattedItem, type FunctionOptions, type FunctionRegistryEntry, type GetActionPluginProvides, type GetAppPluginProvides, type GetAuthenticationPluginProvides, type GetConnectionPluginProvides, type GetContextType, type GetProfilePluginProvides, type GetSdkType, type InfoFieldItem, type InputFieldItem, type InputsProperty, InputsPropertySchema, type LimitProperty, LimitPropertySchema, type ListActionsPluginProvides, type ListAppsPluginProvides, type ListAuthenticationsPluginProvides, type ListClientCredentialsPluginProvides, type ListConnectionsPluginProvides, type ListInputFieldsPluginProvides, type LoadingEvent, MAX_PAGE_LIMIT, type Manifest, type ManifestEntry, type ManifestPluginOptions, type ManifestPluginProvides, type MethodCalledEvent, type MethodCalledEventData, type Need, type NeedsRequest, type NeedsResponse, type OffsetProperty, OffsetPropertySchema, type OutputProperty, OutputPropertySchema, type PaginatedSdkFunction, type ParamsProperty, ParamsPropertySchema, type PkceCredentialsObject, PkceCredentialsObjectSchema, type Plugin, type PluginDependencies, type PluginOptions, type PluginProvides, type PositionalMetadata, type RateLimitInfo, RelayFetchSchema, RelayRequestSchema, type RequestPluginProvides, type ResolveAuthTokenOptions, type ResolveCredentialsOptions, type ResolvedCredentials, ResolvedCredentialsSchema, type RootFieldItem, type RunActionPluginProvides, type Sdk, type SdkEvent, type StaticResolver, type UpdateManifestEntryOptions, type UpdateManifestEntryResult, type UserProfile, type UserProfileItem, ZAPIER_AUTH_BASE_URL, ZAPIER_AUTH_CLIENT_ID, ZAPIER_BASE_URL, ZAPIER_CREDENTIALS, ZAPIER_CREDENTIALS_BASE_URL, ZAPIER_CREDENTIALS_CLIENT_ID, ZAPIER_CREDENTIALS_CLIENT_SECRET, ZAPIER_CREDENTIALS_SCOPE, ZAPIER_MAX_NETWORK_RETRIES, ZAPIER_MAX_NETWORK_RETRY_DELAY_MS, ZAPIER_TOKEN, ZapierActionError, ZapierApiError, ZapierAppNotFoundError, ZapierAuthenticationError, ZapierBundleError, ZapierConfigurationError, ZapierError, type ZapierFetchInitOptions, ZapierNotFoundError, ZapierRateLimitError, ZapierResourceNotFoundError, type ZapierSdk, type ZapierSdkApps, type ZapierSdkOptions, ZapierTimeoutError, ZapierUnknownError, ZapierValidationError, actionKeyResolver, actionTypeResolver, apiPlugin, appKeyResolver, appsPlugin, connectionIdGenericResolver as authenticationIdGenericResolver, connectionIdResolver as authenticationIdResolver, batch, buildApplicationLifecycleEvent, buildErrorEvent, buildErrorEventWithContext, buildMethodCalledEvent, clearTokenCache, clientCredentialsNameResolver, clientIdResolver, connectionIdGenericResolver, connectionIdResolver, createBaseEvent, createClientCredentialsPlugin, createFunction, createSdk, createZapierSdk, createZapierSdkWithoutRegistry, deleteClientCredentialsPlugin, fetchPlugin, findFirstConnectionPlugin, findManifestEntry, findUniqueConnectionPlugin, formatErrorMessage, generateEventId, getActionPlugin, getAppPlugin, getBaseUrlFromCredentials, getCiPlatform, getClientIdFromCredentials, getConnectionPlugin, getCpuTime, getCurrentTimestamp, getMemoryUsage, getOsInfo, getPlatformVersions, getPreferredManifestEntryKey, getProfilePlugin, getReleaseId, getTokenFromCliLogin, inputFieldKeyResolver, inputsAllOptionalResolver, inputsResolver, invalidateCachedToken, invalidateCredentialsToken, isCi, isCliLoginAvailable, isClientCredentials, isCredentialsFunction, isCredentialsObject, isPkceCredentials, isPositional, listActionsPlugin, listAppsPlugin, listClientCredentialsPlugin, listConnectionsPlugin, listInputFieldsPlugin, logDeprecation, manifestPlugin, readManifestFromFile, registryPlugin, requestPlugin, resetDeprecationWarnings, resolveAuthToken, resolveCredentials, resolveCredentialsFromEnv, runActionPlugin, toSnakeCase, toTitleCase };