@zapier/zapier-sdk 0.18.4 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/api/client.d.ts.map +1 -1
  3. package/dist/api/client.js +11 -6
  4. package/dist/api/client.test.js +82 -27
  5. package/dist/api/index.d.ts +3 -2
  6. package/dist/api/index.d.ts.map +1 -1
  7. package/dist/api/index.js +2 -3
  8. package/dist/api/schemas.d.ts +5 -5
  9. package/dist/api/types.d.ts +8 -3
  10. package/dist/api/types.d.ts.map +1 -1
  11. package/dist/auth.d.ts +54 -26
  12. package/dist/auth.d.ts.map +1 -1
  13. package/dist/auth.js +211 -39
  14. package/dist/auth.test.js +338 -64
  15. package/dist/constants.d.ts +14 -0
  16. package/dist/constants.d.ts.map +1 -1
  17. package/dist/constants.js +14 -0
  18. package/dist/credentials.d.ts +57 -0
  19. package/dist/credentials.d.ts.map +1 -0
  20. package/dist/credentials.js +174 -0
  21. package/dist/index.cjs +341 -46
  22. package/dist/index.d.mts +213 -29
  23. package/dist/index.d.ts +3 -0
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +5 -0
  26. package/dist/index.mjs +321 -45
  27. package/dist/plugins/api/index.d.ts +2 -0
  28. package/dist/plugins/api/index.d.ts.map +1 -1
  29. package/dist/plugins/api/index.js +8 -4
  30. package/dist/plugins/eventEmission/index.d.ts.map +1 -1
  31. package/dist/plugins/eventEmission/index.js +1 -3
  32. package/dist/plugins/eventEmission/index.test.js +14 -17
  33. package/dist/plugins/getAction/schemas.d.ts +1 -1
  34. package/dist/plugins/getInputFieldsSchema/schemas.d.ts +1 -1
  35. package/dist/plugins/listActions/index.test.js +1 -0
  36. package/dist/plugins/listActions/schemas.d.ts +1 -1
  37. package/dist/plugins/listInputFieldChoices/schemas.d.ts +1 -1
  38. package/dist/plugins/listInputFields/schemas.d.ts +1 -1
  39. package/dist/plugins/runAction/schemas.d.ts +1 -1
  40. package/dist/schemas/Action.d.ts +1 -1
  41. package/dist/sdk.d.ts +1 -0
  42. package/dist/sdk.d.ts.map +1 -1
  43. package/dist/sdk.test.js +5 -4
  44. package/dist/types/credentials.d.ts +65 -0
  45. package/dist/types/credentials.d.ts.map +1 -0
  46. package/dist/types/credentials.js +42 -0
  47. package/dist/types/properties.d.ts +1 -1
  48. package/dist/types/sdk.d.ts +12 -3
  49. package/dist/types/sdk.d.ts.map +1 -1
  50. package/dist/utils/logging.d.ts +13 -0
  51. package/dist/utils/logging.d.ts.map +1 -0
  52. package/dist/utils/logging.js +20 -0
  53. package/package.json +2 -2
package/dist/index.mjs CHANGED
@@ -36,6 +36,14 @@ function isPositional(schema) {
36
36
  // src/constants.ts
37
37
  var ZAPIER_BASE_URL = process.env.ZAPIER_BASE_URL || "https://zapier.com";
38
38
  var MAX_PAGE_LIMIT = 1e4;
39
+ var ZAPIER_CREDENTIALS = process.env.ZAPIER_CREDENTIALS;
40
+ var ZAPIER_CREDENTIALS_CLIENT_ID = process.env.ZAPIER_CREDENTIALS_CLIENT_ID;
41
+ var ZAPIER_CREDENTIALS_CLIENT_SECRET = process.env.ZAPIER_CREDENTIALS_CLIENT_SECRET;
42
+ var ZAPIER_CREDENTIALS_BASE_URL = process.env.ZAPIER_CREDENTIALS_BASE_URL;
43
+ var ZAPIER_CREDENTIALS_SCOPE = process.env.ZAPIER_CREDENTIALS_SCOPE;
44
+ var ZAPIER_TOKEN = process.env.ZAPIER_TOKEN;
45
+ var ZAPIER_AUTH_BASE_URL = process.env.ZAPIER_AUTH_BASE_URL;
46
+ var ZAPIER_AUTH_CLIENT_ID = process.env.ZAPIER_AUTH_CLIENT_ID;
39
47
 
40
48
  // src/types/properties.ts
41
49
  var AppKeyPropertySchema = withPositional(
@@ -3443,36 +3451,29 @@ async function pollUntilComplete(options) {
3443
3451
  }
3444
3452
  }
3445
3453
 
3446
- // src/auth.ts
3447
- function getTokenFromEnv() {
3448
- return process.env.ZAPIER_TOKEN;
3454
+ // src/types/credentials.ts
3455
+ function isClientCredentials(credentials) {
3456
+ return typeof credentials === "object" && credentials !== null && "clientId" in credentials && "clientSecret" in credentials;
3449
3457
  }
3450
- async function getTokenFromCliLogin(options = {}) {
3451
- try {
3452
- const { getToken } = await import('@zapier/zapier-sdk-cli-login');
3453
- return await getToken(options);
3454
- } catch {
3455
- return void 0;
3456
- }
3458
+ function isPkceCredentials(credentials) {
3459
+ return typeof credentials === "object" && credentials !== null && "clientId" in credentials && !("clientSecret" in credentials);
3457
3460
  }
3458
- async function getTokenFromEnvOrConfig(options = {}) {
3459
- const envToken = getTokenFromEnv();
3460
- if (envToken) {
3461
- return envToken;
3462
- }
3463
- return getTokenFromCliLogin(options);
3461
+ function isCredentialsObject(credentials) {
3462
+ return typeof credentials === "object" && credentials !== null && "clientId" in credentials;
3464
3463
  }
3465
- async function resolveAuthToken(options = {}) {
3466
- if (options.token) {
3467
- return options.token;
3468
- }
3469
- if (options.getToken) {
3470
- const token = await options.getToken();
3471
- if (token) {
3472
- return token;
3473
- }
3474
- }
3475
- return getTokenFromEnvOrConfig(options);
3464
+ function isCredentialsFunction(credentials) {
3465
+ return typeof credentials === "function";
3466
+ }
3467
+
3468
+ // src/utils/logging.ts
3469
+ var loggedDeprecations = /* @__PURE__ */ new Set();
3470
+ function logDeprecation(message) {
3471
+ if (loggedDeprecations.has(message)) return;
3472
+ loggedDeprecations.add(message);
3473
+ console.warn(`[zapier-sdk] Deprecation: ${message}`);
3474
+ }
3475
+ function resetDeprecationWarnings() {
3476
+ loggedDeprecations.clear();
3476
3477
  }
3477
3478
 
3478
3479
  // src/utils/url-utils.ts
@@ -3521,6 +3522,278 @@ function getTrackingBaseUrl({
3521
3522
  return ZAPIER_BASE_URL;
3522
3523
  }
3523
3524
 
3525
+ // src/credentials.ts
3526
+ function deriveAuthBaseUrl(sdkBaseUrl) {
3527
+ if (!sdkBaseUrl) return void 0;
3528
+ return getZapierBaseUrl(sdkBaseUrl);
3529
+ }
3530
+ function normalizeCredentialsObject(obj, sdkBaseUrl) {
3531
+ const resolvedBaseUrl = obj.baseUrl || deriveAuthBaseUrl(sdkBaseUrl);
3532
+ if (obj.type === "client_credentials" || "clientSecret" in obj && obj.clientSecret) {
3533
+ return {
3534
+ type: "client_credentials",
3535
+ clientId: obj.clientId,
3536
+ clientSecret: obj.clientSecret,
3537
+ baseUrl: resolvedBaseUrl,
3538
+ scope: obj.scope
3539
+ };
3540
+ }
3541
+ return {
3542
+ type: "pkce",
3543
+ clientId: obj.clientId,
3544
+ baseUrl: resolvedBaseUrl,
3545
+ scope: obj.scope
3546
+ };
3547
+ }
3548
+ function resolveCredentialsFromEnv(sdkBaseUrl) {
3549
+ if (ZAPIER_CREDENTIALS) {
3550
+ return ZAPIER_CREDENTIALS;
3551
+ }
3552
+ if (ZAPIER_CREDENTIALS_CLIENT_ID) {
3553
+ const resolvedBaseUrl = ZAPIER_CREDENTIALS_BASE_URL || deriveAuthBaseUrl(sdkBaseUrl);
3554
+ if (ZAPIER_CREDENTIALS_CLIENT_SECRET) {
3555
+ return {
3556
+ type: "client_credentials",
3557
+ clientId: ZAPIER_CREDENTIALS_CLIENT_ID,
3558
+ clientSecret: ZAPIER_CREDENTIALS_CLIENT_SECRET,
3559
+ baseUrl: resolvedBaseUrl,
3560
+ scope: ZAPIER_CREDENTIALS_SCOPE
3561
+ };
3562
+ } else {
3563
+ return {
3564
+ type: "pkce",
3565
+ clientId: ZAPIER_CREDENTIALS_CLIENT_ID,
3566
+ baseUrl: resolvedBaseUrl,
3567
+ scope: ZAPIER_CREDENTIALS_SCOPE
3568
+ };
3569
+ }
3570
+ }
3571
+ if (ZAPIER_TOKEN) {
3572
+ logDeprecation(
3573
+ "ZAPIER_TOKEN is deprecated. Use ZAPIER_CREDENTIALS instead."
3574
+ );
3575
+ return ZAPIER_TOKEN;
3576
+ }
3577
+ if (ZAPIER_AUTH_CLIENT_ID) {
3578
+ logDeprecation(
3579
+ "ZAPIER_AUTH_CLIENT_ID is deprecated. Use ZAPIER_CREDENTIALS_CLIENT_ID instead."
3580
+ );
3581
+ if (ZAPIER_AUTH_BASE_URL) {
3582
+ logDeprecation(
3583
+ "ZAPIER_AUTH_BASE_URL is deprecated. Use ZAPIER_CREDENTIALS_BASE_URL instead."
3584
+ );
3585
+ }
3586
+ const resolvedBaseUrl = ZAPIER_AUTH_BASE_URL || deriveAuthBaseUrl(sdkBaseUrl);
3587
+ return {
3588
+ type: "pkce",
3589
+ clientId: ZAPIER_AUTH_CLIENT_ID,
3590
+ baseUrl: resolvedBaseUrl
3591
+ };
3592
+ }
3593
+ return void 0;
3594
+ }
3595
+ async function resolveCredentials(options = {}) {
3596
+ const { baseUrl } = options;
3597
+ if (options.credentials !== void 0) {
3598
+ if (isCredentialsFunction(options.credentials)) {
3599
+ const resolved = await options.credentials();
3600
+ if (typeof resolved === "function") {
3601
+ throw new Error(
3602
+ "Credentials function returned another function. Credentials functions must return a string or credentials object."
3603
+ );
3604
+ }
3605
+ if (isCredentialsObject(resolved)) {
3606
+ return normalizeCredentialsObject(resolved, baseUrl);
3607
+ }
3608
+ return resolved;
3609
+ }
3610
+ if (isCredentialsObject(options.credentials)) {
3611
+ return normalizeCredentialsObject(options.credentials, baseUrl);
3612
+ }
3613
+ return options.credentials;
3614
+ }
3615
+ if (options.token !== void 0) {
3616
+ logDeprecation(
3617
+ "The `token` option is deprecated. Use `credentials` instead."
3618
+ );
3619
+ return options.token;
3620
+ }
3621
+ const envCredentials = resolveCredentialsFromEnv(baseUrl);
3622
+ if (envCredentials !== void 0) {
3623
+ return envCredentials;
3624
+ }
3625
+ return void 0;
3626
+ }
3627
+ function getBaseUrlFromCredentials(credentials) {
3628
+ if (credentials && isCredentialsObject(credentials)) {
3629
+ return credentials.baseUrl;
3630
+ }
3631
+ return void 0;
3632
+ }
3633
+ function getClientIdFromCredentials(credentials) {
3634
+ if (credentials && isCredentialsObject(credentials)) {
3635
+ return credentials.clientId;
3636
+ }
3637
+ return void 0;
3638
+ }
3639
+
3640
+ // src/auth.ts
3641
+ var tokenCache = /* @__PURE__ */ new Map();
3642
+ var pendingExchanges = /* @__PURE__ */ new Map();
3643
+ function clearTokenCache() {
3644
+ tokenCache.clear();
3645
+ pendingExchanges.clear();
3646
+ }
3647
+ var TOKEN_EXPIRATION_BUFFER = 5 * 60 * 1e3;
3648
+ function getCachedToken(clientId) {
3649
+ const cached = tokenCache.get(clientId);
3650
+ if (!cached) return void 0;
3651
+ if (cached.expiresAt > Date.now() + TOKEN_EXPIRATION_BUFFER) {
3652
+ return cached.accessToken;
3653
+ }
3654
+ tokenCache.delete(clientId);
3655
+ return void 0;
3656
+ }
3657
+ function cacheToken(clientId, accessToken, expiresIn) {
3658
+ tokenCache.set(clientId, {
3659
+ accessToken,
3660
+ expiresAt: Date.now() + expiresIn * 1e3
3661
+ });
3662
+ }
3663
+ function invalidateCachedToken(clientId) {
3664
+ tokenCache.delete(clientId);
3665
+ }
3666
+ function getTokenEndpointUrl(baseUrl) {
3667
+ const base = baseUrl || ZAPIER_BASE_URL;
3668
+ return `${base}/oauth/token/`;
3669
+ }
3670
+ async function exchangeClientCredentials(options) {
3671
+ const { clientId, clientSecret, baseUrl, scope, onEvent } = options;
3672
+ const fetchFn = options.fetch || globalThis.fetch;
3673
+ const tokenUrl = getTokenEndpointUrl(baseUrl);
3674
+ onEvent?.({
3675
+ type: "auth_exchanging",
3676
+ payload: {
3677
+ message: "Exchanging client credentials for token...",
3678
+ operation: "client_credentials"
3679
+ },
3680
+ timestamp: Date.now()
3681
+ });
3682
+ const response = await fetchFn(tokenUrl, {
3683
+ method: "POST",
3684
+ headers: {
3685
+ "Content-Type": "application/x-www-form-urlencoded"
3686
+ },
3687
+ body: new URLSearchParams({
3688
+ grant_type: "client_credentials",
3689
+ client_id: clientId,
3690
+ client_secret: clientSecret,
3691
+ scope: scope || "external",
3692
+ audience: "zapier.com"
3693
+ })
3694
+ });
3695
+ if (!response.ok) {
3696
+ const errorText = await response.text();
3697
+ onEvent?.({
3698
+ type: "auth_error",
3699
+ payload: {
3700
+ message: `Client credentials exchange failed: ${response.status}`,
3701
+ error: errorText,
3702
+ operation: "client_credentials"
3703
+ },
3704
+ timestamp: Date.now()
3705
+ });
3706
+ throw new Error(
3707
+ `Client credentials exchange failed: ${response.status} ${response.statusText}`
3708
+ );
3709
+ }
3710
+ const data = await response.json();
3711
+ if (!data.access_token) {
3712
+ throw new Error("Client credentials response missing access_token");
3713
+ }
3714
+ const expiresIn = data.expires_in || 3600;
3715
+ cacheToken(clientId, data.access_token, expiresIn);
3716
+ onEvent?.({
3717
+ type: "auth_success",
3718
+ payload: {
3719
+ message: "Client credentials exchange successful",
3720
+ operation: "client_credentials"
3721
+ },
3722
+ timestamp: Date.now()
3723
+ });
3724
+ return data.access_token;
3725
+ }
3726
+ async function getTokenFromCliLogin(options) {
3727
+ try {
3728
+ const cliLogin = await import('@zapier/zapier-sdk-cli-login');
3729
+ return await cliLogin.getToken(options);
3730
+ } catch {
3731
+ return void 0;
3732
+ }
3733
+ }
3734
+ async function resolveAuthToken(options = {}) {
3735
+ const credentials = await resolveCredentials({
3736
+ credentials: options.credentials,
3737
+ token: options.token
3738
+ });
3739
+ if (credentials !== void 0) {
3740
+ return resolveAuthTokenFromCredentials(credentials, options);
3741
+ }
3742
+ return getTokenFromCliLogin({
3743
+ onEvent: options.onEvent,
3744
+ fetch: options.fetch
3745
+ });
3746
+ }
3747
+ async function resolveAuthTokenFromCredentials(credentials, options) {
3748
+ if (typeof credentials === "string") {
3749
+ return credentials;
3750
+ }
3751
+ if (isClientCredentials(credentials)) {
3752
+ const { clientId } = credentials;
3753
+ const cached = getCachedToken(clientId);
3754
+ if (cached) {
3755
+ return cached;
3756
+ }
3757
+ const pending = pendingExchanges.get(clientId);
3758
+ if (pending) {
3759
+ return pending;
3760
+ }
3761
+ const exchangePromise = exchangeClientCredentials({
3762
+ clientId: credentials.clientId,
3763
+ clientSecret: credentials.clientSecret,
3764
+ baseUrl: credentials.baseUrl || options.baseUrl,
3765
+ scope: credentials.scope,
3766
+ fetch: options.fetch,
3767
+ onEvent: options.onEvent
3768
+ }).finally(() => {
3769
+ pendingExchanges.delete(clientId);
3770
+ });
3771
+ pendingExchanges.set(clientId, exchangePromise);
3772
+ return exchangePromise;
3773
+ }
3774
+ if (isPkceCredentials(credentials)) {
3775
+ const storedToken = await getTokenFromCliLogin({
3776
+ onEvent: options.onEvent,
3777
+ fetch: options.fetch,
3778
+ credentials
3779
+ });
3780
+ if (storedToken) {
3781
+ return storedToken;
3782
+ }
3783
+ throw new Error(
3784
+ "PKCE credentials require interactive login. Please run the 'login' command with the CLI first, or use client_credentials flow."
3785
+ );
3786
+ }
3787
+ throw new Error("Unknown credentials type");
3788
+ }
3789
+ async function invalidateCredentialsToken(options) {
3790
+ const resolved = await resolveCredentials(options);
3791
+ const clientId = getClientIdFromCredentials(resolved);
3792
+ if (clientId) {
3793
+ invalidateCachedToken(clientId);
3794
+ }
3795
+ }
3796
+
3524
3797
  // src/api/client.ts
3525
3798
  var pathConfig = {
3526
3799
  // e.g. /relay -> https://sdkapi.zapier.com/api/v0/sdk/relay/...
@@ -3578,13 +3851,11 @@ var ZapierApiClient = class {
3578
3851
  // Helper to get a token from the different places it could be gotten
3579
3852
  async getAuthToken() {
3580
3853
  return resolveAuthToken({
3854
+ credentials: this.options.credentials,
3581
3855
  token: this.options.token,
3582
- getToken: this.options.getToken,
3583
3856
  onEvent: this.options.onEvent,
3584
3857
  fetch: this.options.fetch,
3585
- baseUrl: this.options.baseUrl,
3586
- authBaseUrl: this.options.authBaseUrl,
3587
- authClientId: this.options.authClientId
3858
+ baseUrl: this.options.baseUrl
3588
3859
  });
3589
3860
  }
3590
3861
  // Helper to handle responses
@@ -3622,10 +3893,16 @@ var ZapierApiClient = class {
3622
3893
  if (response.status === 401 || response.status === 403) {
3623
3894
  if (wasMissingAuthToken) {
3624
3895
  throw new ZapierAuthenticationError(
3625
- `Authentication required (HTTP ${response.status}). Please provide a token in options or set ZAPIER_TOKEN environment variable.`,
3896
+ `Authentication required (HTTP ${response.status}). Please provide credentials in options or set ZAPIER_CREDENTIALS environment variable.`,
3626
3897
  errorOptions
3627
3898
  );
3628
3899
  }
3900
+ if (response.status === 401) {
3901
+ await invalidateCredentialsToken({
3902
+ credentials: this.options.credentials,
3903
+ token: this.options.token
3904
+ });
3905
+ }
3629
3906
  throw new ZapierAuthenticationError(message, errorOptions);
3630
3907
  }
3631
3908
  if (response.status === 400) {
@@ -3761,7 +4038,7 @@ var ZapierApiClient = class {
3761
4038
  if (options.authRequired) {
3762
4039
  if (headers.get("Authorization") == null && authToken == null) {
3763
4040
  throw new ZapierAuthenticationError(
3764
- `Authentication required but no token available. Please set ZAPIER_TOKEN, or run the 'login' command with the CLI.`
4041
+ `Authentication required but no credentials available. Please set ZAPIER_CREDENTIALS, or run the 'login' command with the CLI.`
3765
4042
  );
3766
4043
  }
3767
4044
  }
@@ -3837,27 +4114,28 @@ var apiPlugin = (params) => {
3837
4114
  const {
3838
4115
  fetch: customFetch = globalThis.fetch,
3839
4116
  baseUrl = ZAPIER_BASE_URL,
3840
- authBaseUrl,
3841
- authClientId,
4117
+ credentials,
3842
4118
  token,
3843
- getToken,
3844
4119
  onEvent,
3845
4120
  debug = false
3846
4121
  } = params.context.options;
3847
4122
  const api = createZapierApi({
3848
4123
  baseUrl,
3849
- authBaseUrl,
3850
- authClientId,
4124
+ credentials,
3851
4125
  token,
3852
- getToken,
3853
4126
  debug,
3854
4127
  fetch: customFetch,
3855
4128
  onEvent
3856
4129
  });
3857
4130
  return {
3858
4131
  context: {
3859
- api
4132
+ api,
3860
4133
  // Provide API client in context for other plugins to use
4134
+ resolveCredentials: () => resolveCredentials({
4135
+ credentials,
4136
+ token,
4137
+ baseUrl
4138
+ })
3861
4139
  }
3862
4140
  };
3863
4141
  };
@@ -4451,7 +4729,7 @@ function getCpuTime() {
4451
4729
 
4452
4730
  // package.json
4453
4731
  var package_default = {
4454
- version: "0.18.4"};
4732
+ version: "1.0.0"};
4455
4733
 
4456
4734
  // src/plugins/eventEmission/builders.ts
4457
4735
  function createBaseEvent(context = {}) {
@@ -4624,11 +4902,9 @@ var eventEmissionPlugin = ({ context }) => {
4624
4902
  const getUserContext = (async () => {
4625
4903
  try {
4626
4904
  const token = await resolveAuthToken({
4905
+ credentials: context.options.credentials,
4627
4906
  token: context.options.token,
4628
- getToken: context.options.getToken,
4629
4907
  baseUrl: context.options.baseUrl,
4630
- authBaseUrl: context.options.authBaseUrl,
4631
- authClientId: context.options.authClientId,
4632
4908
  onEvent: context.options.onEvent,
4633
4909
  fetch: context.options.fetch
4634
4910
  });
@@ -4893,4 +5169,4 @@ function createZapierSdk(options = {}) {
4893
5169
  return createZapierSdkWithoutRegistry(options).addPlugin(registryPlugin);
4894
5170
  }
4895
5171
 
4896
- export { ActionKeyPropertySchema, ActionTypePropertySchema, AppKeyPropertySchema, AuthenticationIdPropertySchema, DEFAULT_CONFIG_PATH, DebugPropertySchema, InputsPropertySchema, LimitPropertySchema, MAX_PAGE_LIMIT, OffsetPropertySchema, OutputPropertySchema, ParamsPropertySchema, RelayFetchSchema, RelayRequestSchema, ZAPIER_BASE_URL, ZapierActionError, ZapierApiError, ZapierAppNotFoundError, ZapierAuthenticationError, ZapierBundleError, ZapierConfigurationError, ZapierError, ZapierNotFoundError, ZapierResourceNotFoundError, ZapierTimeoutError, ZapierUnknownError, ZapierValidationError, actionKeyResolver, actionTypeResolver, apiPlugin, appKeyResolver, appsPlugin, authenticationIdGenericResolver, authenticationIdResolver, batch, buildApplicationLifecycleEvent, buildErrorEvent, buildErrorEventWithContext, buildMethodCalledEvent, createBaseEvent, createFunction, createSdk, createZapierSdk, createZapierSdkWithoutRegistry, fetchPlugin, findFirstAuthenticationPlugin, findManifestEntry, findUniqueAuthenticationPlugin, formatErrorMessage, generateEventId, getActionPlugin, getAppPlugin, getAuthenticationPlugin, getCiPlatform, getCpuTime, getCurrentTimestamp, getMemoryUsage, getOsInfo, getPlatformVersions, getPreferredManifestEntryKey, getProfilePlugin, getReleaseId, getTokenFromCliLogin, getTokenFromEnv, getTokenFromEnvOrConfig, inputFieldKeyResolver, inputsAllOptionalResolver, inputsResolver, isCi, isPositional, listActionsPlugin, listAppsPlugin, listAuthenticationsPlugin, listInputFieldsPlugin, manifestPlugin, readManifestFromFile, registryPlugin, requestPlugin, resolveAuthToken, runActionPlugin, toSnakeCase, toTitleCase };
5172
+ export { ActionKeyPropertySchema, ActionTypePropertySchema, AppKeyPropertySchema, AuthenticationIdPropertySchema, DEFAULT_CONFIG_PATH, DebugPropertySchema, InputsPropertySchema, LimitPropertySchema, MAX_PAGE_LIMIT, OffsetPropertySchema, OutputPropertySchema, ParamsPropertySchema, RelayFetchSchema, RelayRequestSchema, 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_TOKEN, ZapierActionError, ZapierApiError, ZapierAppNotFoundError, ZapierAuthenticationError, ZapierBundleError, ZapierConfigurationError, ZapierError, ZapierNotFoundError, ZapierResourceNotFoundError, ZapierTimeoutError, ZapierUnknownError, ZapierValidationError, actionKeyResolver, actionTypeResolver, apiPlugin, appKeyResolver, appsPlugin, authenticationIdGenericResolver, authenticationIdResolver, batch, buildApplicationLifecycleEvent, buildErrorEvent, buildErrorEventWithContext, buildMethodCalledEvent, clearTokenCache, createBaseEvent, createFunction, createSdk, createZapierSdk, createZapierSdkWithoutRegistry, fetchPlugin, findFirstAuthenticationPlugin, findManifestEntry, findUniqueAuthenticationPlugin, formatErrorMessage, generateEventId, getActionPlugin, getAppPlugin, getAuthenticationPlugin, getBaseUrlFromCredentials, getCiPlatform, getClientIdFromCredentials, getCpuTime, getCurrentTimestamp, getMemoryUsage, getOsInfo, getPlatformVersions, getPreferredManifestEntryKey, getProfilePlugin, getReleaseId, getTokenFromCliLogin, inputFieldKeyResolver, inputsAllOptionalResolver, inputsResolver, invalidateCachedToken, invalidateCredentialsToken, isCi, isClientCredentials, isCredentialsFunction, isCredentialsObject, isPkceCredentials, isPositional, listActionsPlugin, listAppsPlugin, listAuthenticationsPlugin, listInputFieldsPlugin, logDeprecation, manifestPlugin, readManifestFromFile, registryPlugin, requestPlugin, resetDeprecationWarnings, resolveAuthToken, resolveCredentials, resolveCredentialsFromEnv, runActionPlugin, toSnakeCase, toTitleCase };
@@ -1,11 +1,13 @@
1
1
  import type { ApiClient } from "../../api/types";
2
2
  import type { BaseSdkOptions } from "../../types/sdk";
3
3
  import type { Plugin } from "../../types/plugin";
4
+ import type { ResolvedCredentials } from "../../types/credentials";
4
5
  export interface ApiPluginOptions extends BaseSdkOptions {
5
6
  }
6
7
  export interface ApiPluginProvides {
7
8
  context: {
8
9
  api: ApiClient;
10
+ resolveCredentials: () => Promise<ResolvedCredentials | undefined>;
9
11
  };
10
12
  }
11
13
  export declare const apiPlugin: Plugin<{}, {}, ApiPluginProvides>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/api/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAGjD,MAAM,WAAW,gBAAiB,SAAQ,cAAc;CAAG;AAG3D,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE;QACP,GAAG,EAAE,SAAS,CAAC;KAChB,CAAC;CACH;AAGD,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,EAAE,EAAE,EAAE,EAAE,iBAAiB,CA+BvD,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/api/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAInE,MAAM,WAAW,gBAAiB,SAAQ,cAAc;CAAG;AAG3D,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE;QACP,GAAG,EAAE,SAAS,CAAC;QACf,kBAAkB,EAAE,MAAM,OAAO,CAAC,mBAAmB,GAAG,SAAS,CAAC,CAAC;KACpE,CAAC;CACH;AAGD,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,EAAE,EAAE,EAAE,EAAE,iBAAiB,CAiCvD,CAAC"}
@@ -1,16 +1,15 @@
1
1
  import { createZapierApi } from "../../api";
2
+ import { resolveCredentials } from "../../credentials";
2
3
  import { ZAPIER_BASE_URL } from "../../constants";
3
4
  // API plugin requires no context and provides api in context
4
5
  export const apiPlugin = (params) => {
5
6
  // Extract all options - everything passed to the plugin
6
- const { fetch: customFetch = globalThis.fetch, baseUrl = ZAPIER_BASE_URL, authBaseUrl, authClientId, token, getToken, onEvent, debug = false, } = params.context.options;
7
+ const { fetch: customFetch = globalThis.fetch, baseUrl = ZAPIER_BASE_URL, credentials, token, onEvent, debug = false, } = params.context.options;
7
8
  // Create the API client - it will handle token resolution internally
8
9
  const api = createZapierApi({
9
10
  baseUrl,
10
- authBaseUrl,
11
- authClientId,
11
+ credentials,
12
12
  token,
13
- getToken,
14
13
  debug,
15
14
  fetch: customFetch,
16
15
  onEvent,
@@ -19,6 +18,11 @@ export const apiPlugin = (params) => {
19
18
  return {
20
19
  context: {
21
20
  api, // Provide API client in context for other plugins to use
21
+ resolveCredentials: () => resolveCredentials({
22
+ credentials,
23
+ token,
24
+ baseUrl,
25
+ }),
22
26
  },
23
27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,6BAA6B,EAC7B,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,8BAA8B,EAC9B,0BAA0B,EAC1B,eAAe,EACf,eAAe,EACf,sBAAsB,GACvB,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAC9D,cAAc,SAAS,CAAC"}
@@ -97,11 +97,9 @@ export const eventEmissionPlugin = ({ context }) => {
97
97
  const getUserContext = (async () => {
98
98
  try {
99
99
  const token = await resolveAuthToken({
100
+ credentials: context.options.credentials,
100
101
  token: context.options.token,
101
- getToken: context.options.getToken,
102
102
  baseUrl: context.options.baseUrl,
103
- authBaseUrl: context.options.authBaseUrl,
104
- authClientId: context.options.authClientId,
105
103
  onEvent: context.options.onEvent,
106
104
  fetch: context.options.fetch,
107
105
  });
@@ -448,7 +448,7 @@ describe("eventEmissionPlugin", () => {
448
448
  // CLI login package should not be called when token is in options
449
449
  expect(mockGetToken).not.toHaveBeenCalled();
450
450
  });
451
- it("should extract user IDs from getToken function in SDK options", async () => {
451
+ it("should extract user IDs from credentials function in SDK options", async () => {
452
452
  // Create a test JWT token
453
453
  const header = { alg: "HS256", typ: "JWT" };
454
454
  const payload = {
@@ -459,13 +459,13 @@ describe("eventEmissionPlugin", () => {
459
459
  const encodedHeader = Buffer.from(JSON.stringify(header)).toString("base64url");
460
460
  const encodedPayload = Buffer.from(JSON.stringify(payload)).toString("base64url");
461
461
  const testJwt = `${encodedHeader}.${encodedPayload}.custom-signature`;
462
- const customGetToken = vi.fn().mockResolvedValue(testJwt);
462
+ const credentialsFn = vi.fn().mockResolvedValue(testJwt);
463
463
  const plugin = eventEmissionPlugin({
464
464
  sdk: {},
465
465
  context: {
466
466
  meta: {},
467
467
  options: {
468
- getToken: customGetToken,
468
+ credentials: credentialsFn,
469
469
  eventEmission: {
470
470
  enabled: true,
471
471
  transport: { type: "console" },
@@ -474,14 +474,14 @@ describe("eventEmissionPlugin", () => {
474
474
  },
475
475
  });
476
476
  const baseEvent = await plugin.context.eventEmission.createBaseEvent();
477
- // Should extract from custom getToken function
477
+ // Should extract from custom credentials function
478
478
  expect(baseEvent.customuser_id).toBe(44444);
479
479
  expect(baseEvent.account_id).toBe(33333);
480
- expect(customGetToken).toHaveBeenCalled();
481
- // CLI login package should not be called when getToken is in options
480
+ expect(credentialsFn).toHaveBeenCalled();
481
+ // CLI login package should not be called when credentials is in options
482
482
  expect(mockGetToken).not.toHaveBeenCalled();
483
483
  });
484
- it("should prioritize static token over getToken function", async () => {
484
+ it("should prioritize string credentials over credentials function", async () => {
485
485
  // Create test JWT tokens
486
486
  const staticHeader = { alg: "HS256", typ: "JWT" };
487
487
  const staticPayload = {
@@ -492,14 +492,12 @@ describe("eventEmissionPlugin", () => {
492
492
  const staticEncodedHeader = Buffer.from(JSON.stringify(staticHeader)).toString("base64url");
493
493
  const staticEncodedPayload = Buffer.from(JSON.stringify(staticPayload)).toString("base64url");
494
494
  const staticJwt = `${staticEncodedHeader}.${staticEncodedPayload}.static-sig`;
495
- const customGetToken = vi.fn().mockResolvedValue("should-not-be-used");
496
495
  const plugin = eventEmissionPlugin({
497
496
  sdk: {},
498
497
  context: {
499
498
  meta: {},
500
499
  options: {
501
- token: staticJwt,
502
- getToken: customGetToken,
500
+ credentials: staticJwt,
503
501
  eventEmission: {
504
502
  enabled: true,
505
503
  transport: { type: "console" },
@@ -508,10 +506,9 @@ describe("eventEmissionPlugin", () => {
508
506
  },
509
507
  });
510
508
  const baseEvent = await plugin.context.eventEmission.createBaseEvent();
511
- // Should use static token, not getToken
509
+ // Should use string credentials
512
510
  expect(baseEvent.customuser_id).toBe(66666);
513
511
  expect(baseEvent.account_id).toBe(55555);
514
- expect(customGetToken).not.toHaveBeenCalled();
515
512
  expect(mockGetToken).not.toHaveBeenCalled();
516
513
  });
517
514
  it("should fall back to CLI login when SDK options have no token", async () => {
@@ -545,8 +542,8 @@ describe("eventEmissionPlugin", () => {
545
542
  expect(baseEvent.account_id).toBe(77777);
546
543
  expect(mockGetToken).toHaveBeenCalled();
547
544
  });
548
- it("should handle custom getToken returning undefined", async () => {
549
- const customGetToken = vi.fn().mockResolvedValue(undefined);
545
+ it("should handle credentials function returning undefined and fall back to CLI login", async () => {
546
+ const credentialsFn = vi.fn().mockResolvedValue(undefined);
550
547
  // Also mock CLI login to return a token
551
548
  const header = { alg: "HS256", typ: "JWT" };
552
549
  const payload = {
@@ -563,7 +560,7 @@ describe("eventEmissionPlugin", () => {
563
560
  context: {
564
561
  meta: {},
565
562
  options: {
566
- getToken: customGetToken,
563
+ credentials: credentialsFn,
567
564
  eventEmission: {
568
565
  enabled: true,
569
566
  transport: { type: "console" },
@@ -572,10 +569,10 @@ describe("eventEmissionPlugin", () => {
572
569
  },
573
570
  });
574
571
  const baseEvent = await plugin.context.eventEmission.createBaseEvent();
575
- // Should fall back to CLI login when custom getToken returns undefined
572
+ // Since credentials function returns undefined, SDK falls back to CLI login
576
573
  expect(baseEvent.customuser_id).toBe(10101);
577
574
  expect(baseEvent.account_id).toBe(99999);
578
- expect(customGetToken).toHaveBeenCalled();
575
+ expect(credentialsFn).toHaveBeenCalled();
579
576
  expect(mockGetToken).toHaveBeenCalled();
580
577
  });
581
578
  });
@@ -6,8 +6,8 @@ export declare const GetActionSchema: z.ZodObject<{
6
6
  _def: z.core.$ZodStringDef & import("../..").PositionalMetadata;
7
7
  };
8
8
  actionType: z.ZodEnum<{
9
- search: "search";
10
9
  filter: "filter";
10
+ search: "search";
11
11
  read: "read";
12
12
  read_bulk: "read_bulk";
13
13
  run: "run";
@@ -5,8 +5,8 @@ export declare const GetInputFieldsSchemaSchema: z.ZodObject<{
5
5
  _def: z.core.$ZodStringDef & import("../..").PositionalMetadata;
6
6
  };
7
7
  actionType: z.ZodEnum<{
8
- search: "search";
9
8
  filter: "filter";
9
+ search: "search";
10
10
  read: "read";
11
11
  read_bulk: "read_bulk";
12
12
  run: "run";
@@ -69,6 +69,7 @@ describe("listActions plugin", () => {
69
69
  .addPlugin(() => ({
70
70
  context: {
71
71
  api: mockApiClient,
72
+ resolveCredentials: vi.fn().mockResolvedValue(undefined),
72
73
  },
73
74
  }))
74
75
  .addPlugin(eventEmissionPlugin)