@zapier/zapier-sdk 0.31.1 → 0.31.3

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,17 @@
1
1
  # @zapier/zapier-sdk
2
2
 
3
+ ## 0.31.3
4
+
5
+ ### Patch Changes
6
+
7
+ - c98008a: Add callContext option to EventEmissionConfig to track where SDK method calls originate. MethodCalledEvent telemetry events now populate call_context with "sdk", "cli", or "mcp" instead of null.
8
+
9
+ ## 0.31.2
10
+
11
+ ### Patch Changes
12
+
13
+ - 1ae0349: Improve error message when credentials can't be found. Also improve module resolution for login module.
14
+
3
15
  ## 0.31.1
4
16
 
5
17
  ### Patch 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<string | undefined>;
@@ -1 +1 @@
1
- {"version":3,"file":"auth.d.ts","sourceRoot":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ED
@@ -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
@@ -4168,6 +4168,7 @@ function buildCacheKey(clientId, scopes) {
4168
4168
  function clearTokenCache() {
4169
4169
  tokenCache.clear();
4170
4170
  pendingExchanges.clear();
4171
+ cachedCliLogin = void 0;
4171
4172
  }
4172
4173
  var TOKEN_EXPIRATION_BUFFER = 5 * 60 * 1e3;
4173
4174
  function getCachedToken(clientId, scopes) {
@@ -4272,13 +4273,31 @@ async function exchangeClientCredentials(options) {
4272
4273
  });
4273
4274
  return data.access_token;
4274
4275
  }
4275
- async function getTokenFromCliLogin(options) {
4276
- let cliLogin;
4276
+ var cachedCliLogin;
4277
+ async function getCliLogin() {
4278
+ if (cachedCliLogin !== void 0) {
4279
+ return cachedCliLogin || void 0;
4280
+ }
4281
+ try {
4282
+ cachedCliLogin = await import('@zapier/zapier-sdk-cli/login');
4283
+ return cachedCliLogin;
4284
+ } catch {
4285
+ }
4277
4286
  try {
4278
- cliLogin = await import('@zapier/zapier-sdk-cli-login');
4287
+ cachedCliLogin = await import('@zapier/zapier-sdk-cli-login');
4288
+ return cachedCliLogin;
4279
4289
  } catch {
4290
+ cachedCliLogin = false;
4280
4291
  return void 0;
4281
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;
4282
4301
  return await cliLogin.getToken(options);
4283
4302
  }
4284
4303
  async function resolveAuthToken(options = {}) {
@@ -4704,9 +4723,8 @@ var ZapierApiClient = class {
4704
4723
  }
4705
4724
  if (options.authRequired) {
4706
4725
  if (headers.get("Authorization") == null && authToken == null) {
4707
- throw new ZapierAuthenticationError(
4708
- `Authentication required but no credentials available. Please set ZAPIER_CREDENTIALS, or run the 'login' command with the CLI.`
4709
- );
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);
4710
4728
  }
4711
4729
  }
4712
4730
  return headers;
@@ -5469,7 +5487,7 @@ function getCpuTime() {
5469
5487
 
5470
5488
  // package.json
5471
5489
  var package_default = {
5472
- version: "0.31.1"};
5490
+ version: "0.31.3"};
5473
5491
 
5474
5492
  // src/plugins/eventEmission/builders.ts
5475
5493
  function createBaseEvent(context = {}) {
@@ -5648,6 +5666,7 @@ var eventEmissionPlugin = ({ context }) => {
5648
5666
  });
5649
5667
  const config = {
5650
5668
  enabled: context.options.eventEmission?.enabled ?? true,
5669
+ callContext: context.options.eventEmission?.callContext,
5651
5670
  transport: (
5652
5671
  // If env var is set, use it (defaultTransport will be from env)
5653
5672
  process?.env?.ZAPIER_SDK_TELEMETRY_TRANSPORT ? defaultTransport : (
@@ -5861,7 +5880,10 @@ var eventEmissionPlugin = ({ context }) => {
5861
5880
  },
5862
5881
  createBaseEvent: createBaseEventHelper,
5863
5882
  emitMethodCalled: (data) => {
5864
- const event = buildMethodCalledEvent(data);
5883
+ const event = {
5884
+ ...buildMethodCalledEvent(data),
5885
+ call_context: config.callContext ?? "sdk"
5886
+ };
5865
5887
  silentEmit(
5866
5888
  transport,
5867
5889
  METHOD_CALLED_EVENT_SUBJECT,
@@ -6056,6 +6078,7 @@ exports.inputsResolver = inputsResolver;
6056
6078
  exports.invalidateCachedToken = invalidateCachedToken;
6057
6079
  exports.invalidateCredentialsToken = invalidateCredentialsToken;
6058
6080
  exports.isCi = isCi;
6081
+ exports.isCliLoginAvailable = isCliLoginAvailable;
6059
6082
  exports.isClientCredentials = isClientCredentials;
6060
6083
  exports.isCredentialsFunction = isCredentialsFunction;
6061
6084
  exports.isCredentialsObject = isCredentialsObject;
package/dist/index.d.mts CHANGED
@@ -378,6 +378,7 @@ declare function getCpuTime(): number | null;
378
378
  interface EventEmissionConfig {
379
379
  enabled?: boolean;
380
380
  transport?: TransportConfig;
381
+ callContext?: "sdk" | "cli" | "mcp";
381
382
  }
382
383
  interface EventEmissionContext {
383
384
  eventEmission: {
@@ -2623,10 +2624,14 @@ interface CliLoginOptions {
2623
2624
  debug?: boolean;
2624
2625
  }
2625
2626
  /**
2626
- * Attempts to get a token by optionally importing from CLI login package.
2627
- * This provides a graceful fallback when the CLI login package is not available.
2627
+ * Returns whether a CLI login package is available.
2628
+ * `undefined` if no import has been attempted yet, `true` if found, `false` if not.
2629
+ */
2630
+ declare function isCliLoginAvailable(): boolean | undefined;
2631
+ /**
2632
+ * Attempts to get a token from the CLI login package.
2628
2633
  *
2629
- * Returns undefined if no valid token is found or CLI package is not available.
2634
+ * Returns undefined if no valid token is found or no login package is available.
2630
2635
  * Throws if there's an actual error (like token refresh failure).
2631
2636
  */
2632
2637
  declare function getTokenFromCliLogin(options: CliLoginOptions): Promise<string | undefined>;
@@ -2949,4 +2954,4 @@ declare function createZapierSdkWithoutRegistry(options?: ZapierSdkOptions): Sdk
2949
2954
  }>;
2950
2955
  declare function createZapierSdk(options?: ZapierSdkOptions): ZapierSdk;
2951
2956
 
2952
- 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 };
2957
+ 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 };
package/dist/index.mjs CHANGED
@@ -4146,6 +4146,7 @@ function buildCacheKey(clientId, scopes) {
4146
4146
  function clearTokenCache() {
4147
4147
  tokenCache.clear();
4148
4148
  pendingExchanges.clear();
4149
+ cachedCliLogin = void 0;
4149
4150
  }
4150
4151
  var TOKEN_EXPIRATION_BUFFER = 5 * 60 * 1e3;
4151
4152
  function getCachedToken(clientId, scopes) {
@@ -4250,13 +4251,31 @@ async function exchangeClientCredentials(options) {
4250
4251
  });
4251
4252
  return data.access_token;
4252
4253
  }
4253
- async function getTokenFromCliLogin(options) {
4254
- let cliLogin;
4254
+ var cachedCliLogin;
4255
+ async function getCliLogin() {
4256
+ if (cachedCliLogin !== void 0) {
4257
+ return cachedCliLogin || void 0;
4258
+ }
4259
+ try {
4260
+ cachedCliLogin = await import('@zapier/zapier-sdk-cli/login');
4261
+ return cachedCliLogin;
4262
+ } catch {
4263
+ }
4255
4264
  try {
4256
- cliLogin = await import('@zapier/zapier-sdk-cli-login');
4265
+ cachedCliLogin = await import('@zapier/zapier-sdk-cli-login');
4266
+ return cachedCliLogin;
4257
4267
  } catch {
4268
+ cachedCliLogin = false;
4258
4269
  return void 0;
4259
4270
  }
4271
+ }
4272
+ function isCliLoginAvailable() {
4273
+ if (cachedCliLogin === void 0) return void 0;
4274
+ return cachedCliLogin !== false;
4275
+ }
4276
+ async function getTokenFromCliLogin(options) {
4277
+ const cliLogin = await getCliLogin();
4278
+ if (!cliLogin) return void 0;
4260
4279
  return await cliLogin.getToken(options);
4261
4280
  }
4262
4281
  async function resolveAuthToken(options = {}) {
@@ -4682,9 +4701,8 @@ var ZapierApiClient = class {
4682
4701
  }
4683
4702
  if (options.authRequired) {
4684
4703
  if (headers.get("Authorization") == null && authToken == null) {
4685
- throw new ZapierAuthenticationError(
4686
- `Authentication required but no credentials available. Please set ZAPIER_CREDENTIALS, or run the 'login' command with the CLI.`
4687
- );
4704
+ 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.";
4705
+ throw new ZapierAuthenticationError(message);
4688
4706
  }
4689
4707
  }
4690
4708
  return headers;
@@ -5447,7 +5465,7 @@ function getCpuTime() {
5447
5465
 
5448
5466
  // package.json
5449
5467
  var package_default = {
5450
- version: "0.31.1"};
5468
+ version: "0.31.3"};
5451
5469
 
5452
5470
  // src/plugins/eventEmission/builders.ts
5453
5471
  function createBaseEvent(context = {}) {
@@ -5626,6 +5644,7 @@ var eventEmissionPlugin = ({ context }) => {
5626
5644
  });
5627
5645
  const config = {
5628
5646
  enabled: context.options.eventEmission?.enabled ?? true,
5647
+ callContext: context.options.eventEmission?.callContext,
5629
5648
  transport: (
5630
5649
  // If env var is set, use it (defaultTransport will be from env)
5631
5650
  process?.env?.ZAPIER_SDK_TELEMETRY_TRANSPORT ? defaultTransport : (
@@ -5839,7 +5858,10 @@ var eventEmissionPlugin = ({ context }) => {
5839
5858
  },
5840
5859
  createBaseEvent: createBaseEventHelper,
5841
5860
  emitMethodCalled: (data) => {
5842
- const event = buildMethodCalledEvent(data);
5861
+ const event = {
5862
+ ...buildMethodCalledEvent(data),
5863
+ call_context: config.callContext ?? "sdk"
5864
+ };
5843
5865
  silentEmit(
5844
5866
  transport,
5845
5867
  METHOD_CALLED_EVENT_SUBJECT,
@@ -5935,4 +5957,4 @@ var BaseSdkOptionsSchema = z.object({
5935
5957
  // Use credentials instead
5936
5958
  });
5937
5959
 
5938
- export { ActionKeyPropertySchema, ActionTimeoutMsPropertySchema, ActionTypePropertySchema, AppKeyPropertySchema, AuthenticationIdPropertySchema, BaseSdkOptionsSchema, ClientCredentialsObjectSchema, ConnectionIdPropertySchema, CredentialsFunctionSchema, CredentialsObjectSchema, CredentialsSchema, DEFAULT_ACTION_TIMEOUT_MS, DEFAULT_CONFIG_PATH, DebugPropertySchema, InputsPropertySchema, LimitPropertySchema, MAX_PAGE_LIMIT, OffsetPropertySchema, OutputPropertySchema, ParamsPropertySchema, PkceCredentialsObjectSchema, RelayFetchSchema, RelayRequestSchema, ResolvedCredentialsSchema, 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, ZapierNotFoundError, ZapierRateLimitError, ZapierResourceNotFoundError, 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 };
5960
+ export { ActionKeyPropertySchema, ActionTimeoutMsPropertySchema, ActionTypePropertySchema, AppKeyPropertySchema, AuthenticationIdPropertySchema, BaseSdkOptionsSchema, ClientCredentialsObjectSchema, ConnectionIdPropertySchema, CredentialsFunctionSchema, CredentialsObjectSchema, CredentialsSchema, DEFAULT_ACTION_TIMEOUT_MS, DEFAULT_CONFIG_PATH, DebugPropertySchema, InputsPropertySchema, LimitPropertySchema, MAX_PAGE_LIMIT, OffsetPropertySchema, OutputPropertySchema, ParamsPropertySchema, PkceCredentialsObjectSchema, RelayFetchSchema, RelayRequestSchema, ResolvedCredentialsSchema, 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, ZapierNotFoundError, ZapierRateLimitError, ZapierResourceNotFoundError, 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 };
@@ -53,4 +53,13 @@ describe("buildMethodCalledEvent", () => {
53
53
  }, { selected_api: "SlackCLIAPI@1.0.0" });
54
54
  expect(event.selected_api).toBe("SlackCLIAPI@1.0.0");
55
55
  });
56
+ it("should default call_context to null (plugin layer overrides this)", () => {
57
+ const event = buildMethodCalledEvent({
58
+ method_name: "listApps",
59
+ execution_duration_ms: 50,
60
+ success_flag: true,
61
+ argument_count: 0,
62
+ });
63
+ expect(event.call_context).toBeNull();
64
+ });
56
65
  });
@@ -16,6 +16,7 @@ export declare function cleanupEventListeners(): void;
16
16
  export interface EventEmissionConfig {
17
17
  enabled?: boolean;
18
18
  transport?: TransportConfig;
19
+ callContext?: "sdk" | "cli" | "mcp";
19
20
  }
20
21
  export interface EventEmissionContext {
21
22
  eventEmission: {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/eventEmission/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAWnE,OAAO,KAAK,EAAgB,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAsCnE;;;GAGG;AACH,wBAAgB,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}
@@ -110,6 +110,7 @@ export const eventEmissionPlugin = ({ context }) => {
110
110
  // Merge config: env var takes precedence over options, options take precedence over defaults
111
111
  const config = {
112
112
  enabled: context.options.eventEmission?.enabled ?? true,
113
+ callContext: context.options.eventEmission?.callContext,
113
114
  transport:
114
115
  // If env var is set, use it (defaultTransport will be from env)
115
116
  process?.env?.ZAPIER_SDK_TELEMETRY_TRANSPORT
@@ -354,7 +355,10 @@ export const eventEmissionPlugin = ({ context }) => {
354
355
  },
355
356
  createBaseEvent: createBaseEventHelper,
356
357
  emitMethodCalled: (data) => {
357
- const event = buildMethodCalledEvent(data);
358
+ const event = {
359
+ ...buildMethodCalledEvent(data),
360
+ call_context: config.callContext ?? "sdk",
361
+ };
358
362
  silentEmit(transport, METHOD_CALLED_EVENT_SUBJECT, event, getUserContext);
359
363
  },
360
364
  },
@@ -14,6 +14,9 @@ vi.mock("./transport", () => ({
14
14
  }));
15
15
  // Mock CLI login package - default to returning null context
16
16
  const mockGetToken = vi.fn().mockResolvedValue(undefined);
17
+ vi.mock("@zapier/zapier-sdk-cli/login", () => ({
18
+ getToken: mockGetToken,
19
+ }));
17
20
  vi.mock("@zapier/zapier-sdk-cli-login", () => ({
18
21
  getToken: mockGetToken,
19
22
  }));
@@ -576,6 +579,80 @@ describe("eventEmissionPlugin", () => {
576
579
  expect(mockGetToken).toHaveBeenCalled();
577
580
  });
578
581
  });
582
+ describe("emitMethodCalled call_context", () => {
583
+ beforeEach(() => {
584
+ vi.clearAllMocks();
585
+ mockGetToken.mockResolvedValue(undefined);
586
+ });
587
+ it("should default call_context to 'sdk' when callContext is not configured", async () => {
588
+ const plugin = eventEmissionPlugin({
589
+ sdk: {},
590
+ context: {
591
+ meta: {},
592
+ options: {
593
+ eventEmission: {
594
+ enabled: true,
595
+ transport: { type: "console" },
596
+ },
597
+ },
598
+ },
599
+ });
600
+ plugin.context.eventEmission.emitMethodCalled({
601
+ method_name: "listApps",
602
+ execution_duration_ms: 50,
603
+ success_flag: true,
604
+ argument_count: 0,
605
+ });
606
+ await new Promise((resolve) => setTimeout(resolve, 50));
607
+ expect(mockTransport.emit).toHaveBeenCalledWith("platform.sdk.MethodCalledEvent", expect.objectContaining({ call_context: "sdk" }));
608
+ });
609
+ it("should set call_context to 'cli' when callContext is 'cli'", async () => {
610
+ const plugin = eventEmissionPlugin({
611
+ sdk: {},
612
+ context: {
613
+ meta: {},
614
+ options: {
615
+ eventEmission: {
616
+ enabled: true,
617
+ transport: { type: "console" },
618
+ callContext: "cli",
619
+ },
620
+ },
621
+ },
622
+ });
623
+ plugin.context.eventEmission.emitMethodCalled({
624
+ method_name: "listApps",
625
+ execution_duration_ms: 50,
626
+ success_flag: true,
627
+ argument_count: 0,
628
+ });
629
+ await new Promise((resolve) => setTimeout(resolve, 50));
630
+ expect(mockTransport.emit).toHaveBeenCalledWith("platform.sdk.MethodCalledEvent", expect.objectContaining({ call_context: "cli" }));
631
+ });
632
+ it("should set call_context to 'mcp' when callContext is 'mcp'", async () => {
633
+ const plugin = eventEmissionPlugin({
634
+ sdk: {},
635
+ context: {
636
+ meta: {},
637
+ options: {
638
+ eventEmission: {
639
+ enabled: true,
640
+ transport: { type: "console" },
641
+ callContext: "mcp",
642
+ },
643
+ },
644
+ },
645
+ });
646
+ plugin.context.eventEmission.emitMethodCalled({
647
+ method_name: "listApps",
648
+ execution_duration_ms: 50,
649
+ success_flag: true,
650
+ argument_count: 0,
651
+ });
652
+ await new Promise((resolve) => setTimeout(resolve, 50));
653
+ expect(mockTransport.emit).toHaveBeenCalledWith("platform.sdk.MethodCalledEvent", expect.objectContaining({ call_context: "mcp" }));
654
+ });
655
+ });
579
656
  describe("Process Listener Cleanup", () => {
580
657
  beforeEach(() => {
581
658
  // Clean up any listeners from previous tests
@@ -11,7 +11,10 @@ const mockTransport = {
11
11
  vi.mock("../eventEmission/transport", () => ({
12
12
  createTransport: vi.fn(() => mockTransport),
13
13
  }));
14
- // Mock CLI login package - prevents real token resolution requests
14
+ // Mock CLI login packages - prevents real token resolution requests
15
+ vi.mock("@zapier/zapier-sdk-cli/login", () => ({
16
+ getToken: vi.fn().mockResolvedValue(undefined),
17
+ }));
15
18
  vi.mock("@zapier/zapier-sdk-cli-login", () => ({
16
19
  getToken: vi.fn().mockResolvedValue(undefined),
17
20
  }));
@@ -11,7 +11,10 @@ const mockTransport = {
11
11
  vi.mock("../eventEmission/transport", () => ({
12
12
  createTransport: vi.fn(() => mockTransport),
13
13
  }));
14
- // Mock CLI login package - prevents real token resolution requests
14
+ // Mock CLI login packages - prevents real token resolution requests
15
+ vi.mock("@zapier/zapier-sdk-cli/login", () => ({
16
+ getToken: vi.fn().mockResolvedValue(undefined),
17
+ }));
15
18
  vi.mock("@zapier/zapier-sdk-cli-login", () => ({
16
19
  getToken: vi.fn().mockResolvedValue(undefined),
17
20
  }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zapier/zapier-sdk",
3
- "version": "0.31.1",
3
+ "version": "0.31.3",
4
4
  "description": "Complete Zapier SDK - combines all Zapier SDK packages",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",