@zapier/zapier-sdk 0.18.4 → 1.0.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 (57) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +12 -3
  3. package/dist/api/client.d.ts.map +1 -1
  4. package/dist/api/client.js +11 -6
  5. package/dist/api/client.test.js +82 -27
  6. package/dist/api/index.d.ts +3 -2
  7. package/dist/api/index.d.ts.map +1 -1
  8. package/dist/api/index.js +2 -3
  9. package/dist/api/schemas.d.ts +5 -5
  10. package/dist/api/types.d.ts +8 -3
  11. package/dist/api/types.d.ts.map +1 -1
  12. package/dist/auth.d.ts +54 -26
  13. package/dist/auth.d.ts.map +1 -1
  14. package/dist/auth.js +211 -39
  15. package/dist/auth.test.js +338 -64
  16. package/dist/constants.d.ts +14 -0
  17. package/dist/constants.d.ts.map +1 -1
  18. package/dist/constants.js +14 -0
  19. package/dist/credentials.d.ts +57 -0
  20. package/dist/credentials.d.ts.map +1 -0
  21. package/dist/credentials.js +174 -0
  22. package/dist/index.cjs +346 -48
  23. package/dist/index.d.mts +213 -29
  24. package/dist/index.d.ts +3 -0
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +5 -0
  27. package/dist/index.mjs +326 -47
  28. package/dist/plugins/api/index.d.ts +2 -0
  29. package/dist/plugins/api/index.d.ts.map +1 -1
  30. package/dist/plugins/api/index.js +8 -4
  31. package/dist/plugins/eventEmission/index.d.ts.map +1 -1
  32. package/dist/plugins/eventEmission/index.js +1 -3
  33. package/dist/plugins/eventEmission/index.test.js +14 -17
  34. package/dist/plugins/getAction/schemas.d.ts +1 -1
  35. package/dist/plugins/getInputFieldsSchema/schemas.d.ts +1 -1
  36. package/dist/plugins/listActions/index.test.js +1 -0
  37. package/dist/plugins/listActions/schemas.d.ts +1 -1
  38. package/dist/plugins/listInputFieldChoices/schemas.d.ts +1 -1
  39. package/dist/plugins/listInputFields/schemas.d.ts +1 -1
  40. package/dist/plugins/manifest/index.d.ts.map +1 -1
  41. package/dist/plugins/manifest/index.js +10 -2
  42. package/dist/plugins/manifest/index.test.js +46 -6
  43. package/dist/plugins/runAction/schemas.d.ts +1 -1
  44. package/dist/schemas/Action.d.ts +1 -1
  45. package/dist/sdk.d.ts +1 -0
  46. package/dist/sdk.d.ts.map +1 -1
  47. package/dist/sdk.test.js +5 -4
  48. package/dist/types/credentials.d.ts +65 -0
  49. package/dist/types/credentials.d.ts.map +1 -0
  50. package/dist/types/credentials.js +42 -0
  51. package/dist/types/properties.d.ts +1 -1
  52. package/dist/types/sdk.d.ts +12 -3
  53. package/dist/types/sdk.d.ts.map +1 -1
  54. package/dist/utils/logging.d.ts +13 -0
  55. package/dist/utils/logging.d.ts.map +1 -0
  56. package/dist/utils/logging.js +20 -0
  57. 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(
@@ -2729,8 +2737,11 @@ async function readManifestFromFile(filePath) {
2729
2737
  const resolvedPath = await resolve(filePath);
2730
2738
  const content = await readFile(resolvedPath);
2731
2739
  return parseManifestContent(content, resolvedPath);
2732
- } catch {
2733
- console.warn(`\u26A0\uFE0F Failed to read manifest from ${filePath}`);
2740
+ } catch (error) {
2741
+ const isFileNotFound = error && typeof error === "object" && "code" in error && error.code === "ENOENT" || error instanceof Error && error.message.includes("File not found");
2742
+ if (!isFileNotFound) {
2743
+ console.warn(`\u26A0\uFE0F Failed to read manifest from ${filePath}`);
2744
+ }
2734
2745
  return null;
2735
2746
  }
2736
2747
  }
@@ -3443,36 +3454,29 @@ async function pollUntilComplete(options) {
3443
3454
  }
3444
3455
  }
3445
3456
 
3446
- // src/auth.ts
3447
- function getTokenFromEnv() {
3448
- return process.env.ZAPIER_TOKEN;
3457
+ // src/types/credentials.ts
3458
+ function isClientCredentials(credentials) {
3459
+ return typeof credentials === "object" && credentials !== null && "clientId" in credentials && "clientSecret" in credentials;
3449
3460
  }
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
- }
3461
+ function isPkceCredentials(credentials) {
3462
+ return typeof credentials === "object" && credentials !== null && "clientId" in credentials && !("clientSecret" in credentials);
3457
3463
  }
3458
- async function getTokenFromEnvOrConfig(options = {}) {
3459
- const envToken = getTokenFromEnv();
3460
- if (envToken) {
3461
- return envToken;
3462
- }
3463
- return getTokenFromCliLogin(options);
3464
+ function isCredentialsObject(credentials) {
3465
+ return typeof credentials === "object" && credentials !== null && "clientId" in credentials;
3464
3466
  }
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);
3467
+ function isCredentialsFunction(credentials) {
3468
+ return typeof credentials === "function";
3469
+ }
3470
+
3471
+ // src/utils/logging.ts
3472
+ var loggedDeprecations = /* @__PURE__ */ new Set();
3473
+ function logDeprecation(message) {
3474
+ if (loggedDeprecations.has(message)) return;
3475
+ loggedDeprecations.add(message);
3476
+ console.warn(`[zapier-sdk] Deprecation: ${message}`);
3477
+ }
3478
+ function resetDeprecationWarnings() {
3479
+ loggedDeprecations.clear();
3476
3480
  }
3477
3481
 
3478
3482
  // src/utils/url-utils.ts
@@ -3521,6 +3525,278 @@ function getTrackingBaseUrl({
3521
3525
  return ZAPIER_BASE_URL;
3522
3526
  }
3523
3527
 
3528
+ // src/credentials.ts
3529
+ function deriveAuthBaseUrl(sdkBaseUrl) {
3530
+ if (!sdkBaseUrl) return void 0;
3531
+ return getZapierBaseUrl(sdkBaseUrl);
3532
+ }
3533
+ function normalizeCredentialsObject(obj, sdkBaseUrl) {
3534
+ const resolvedBaseUrl = obj.baseUrl || deriveAuthBaseUrl(sdkBaseUrl);
3535
+ if (obj.type === "client_credentials" || "clientSecret" in obj && obj.clientSecret) {
3536
+ return {
3537
+ type: "client_credentials",
3538
+ clientId: obj.clientId,
3539
+ clientSecret: obj.clientSecret,
3540
+ baseUrl: resolvedBaseUrl,
3541
+ scope: obj.scope
3542
+ };
3543
+ }
3544
+ return {
3545
+ type: "pkce",
3546
+ clientId: obj.clientId,
3547
+ baseUrl: resolvedBaseUrl,
3548
+ scope: obj.scope
3549
+ };
3550
+ }
3551
+ function resolveCredentialsFromEnv(sdkBaseUrl) {
3552
+ if (ZAPIER_CREDENTIALS) {
3553
+ return ZAPIER_CREDENTIALS;
3554
+ }
3555
+ if (ZAPIER_CREDENTIALS_CLIENT_ID) {
3556
+ const resolvedBaseUrl = ZAPIER_CREDENTIALS_BASE_URL || deriveAuthBaseUrl(sdkBaseUrl);
3557
+ if (ZAPIER_CREDENTIALS_CLIENT_SECRET) {
3558
+ return {
3559
+ type: "client_credentials",
3560
+ clientId: ZAPIER_CREDENTIALS_CLIENT_ID,
3561
+ clientSecret: ZAPIER_CREDENTIALS_CLIENT_SECRET,
3562
+ baseUrl: resolvedBaseUrl,
3563
+ scope: ZAPIER_CREDENTIALS_SCOPE
3564
+ };
3565
+ } else {
3566
+ return {
3567
+ type: "pkce",
3568
+ clientId: ZAPIER_CREDENTIALS_CLIENT_ID,
3569
+ baseUrl: resolvedBaseUrl,
3570
+ scope: ZAPIER_CREDENTIALS_SCOPE
3571
+ };
3572
+ }
3573
+ }
3574
+ if (ZAPIER_TOKEN) {
3575
+ logDeprecation(
3576
+ "ZAPIER_TOKEN is deprecated. Use ZAPIER_CREDENTIALS instead."
3577
+ );
3578
+ return ZAPIER_TOKEN;
3579
+ }
3580
+ if (ZAPIER_AUTH_CLIENT_ID) {
3581
+ logDeprecation(
3582
+ "ZAPIER_AUTH_CLIENT_ID is deprecated. Use ZAPIER_CREDENTIALS_CLIENT_ID instead."
3583
+ );
3584
+ if (ZAPIER_AUTH_BASE_URL) {
3585
+ logDeprecation(
3586
+ "ZAPIER_AUTH_BASE_URL is deprecated. Use ZAPIER_CREDENTIALS_BASE_URL instead."
3587
+ );
3588
+ }
3589
+ const resolvedBaseUrl = ZAPIER_AUTH_BASE_URL || deriveAuthBaseUrl(sdkBaseUrl);
3590
+ return {
3591
+ type: "pkce",
3592
+ clientId: ZAPIER_AUTH_CLIENT_ID,
3593
+ baseUrl: resolvedBaseUrl
3594
+ };
3595
+ }
3596
+ return void 0;
3597
+ }
3598
+ async function resolveCredentials(options = {}) {
3599
+ const { baseUrl } = options;
3600
+ if (options.credentials !== void 0) {
3601
+ if (isCredentialsFunction(options.credentials)) {
3602
+ const resolved = await options.credentials();
3603
+ if (typeof resolved === "function") {
3604
+ throw new Error(
3605
+ "Credentials function returned another function. Credentials functions must return a string or credentials object."
3606
+ );
3607
+ }
3608
+ if (isCredentialsObject(resolved)) {
3609
+ return normalizeCredentialsObject(resolved, baseUrl);
3610
+ }
3611
+ return resolved;
3612
+ }
3613
+ if (isCredentialsObject(options.credentials)) {
3614
+ return normalizeCredentialsObject(options.credentials, baseUrl);
3615
+ }
3616
+ return options.credentials;
3617
+ }
3618
+ if (options.token !== void 0) {
3619
+ logDeprecation(
3620
+ "The `token` option is deprecated. Use `credentials` instead."
3621
+ );
3622
+ return options.token;
3623
+ }
3624
+ const envCredentials = resolveCredentialsFromEnv(baseUrl);
3625
+ if (envCredentials !== void 0) {
3626
+ return envCredentials;
3627
+ }
3628
+ return void 0;
3629
+ }
3630
+ function getBaseUrlFromCredentials(credentials) {
3631
+ if (credentials && isCredentialsObject(credentials)) {
3632
+ return credentials.baseUrl;
3633
+ }
3634
+ return void 0;
3635
+ }
3636
+ function getClientIdFromCredentials(credentials) {
3637
+ if (credentials && isCredentialsObject(credentials)) {
3638
+ return credentials.clientId;
3639
+ }
3640
+ return void 0;
3641
+ }
3642
+
3643
+ // src/auth.ts
3644
+ var tokenCache = /* @__PURE__ */ new Map();
3645
+ var pendingExchanges = /* @__PURE__ */ new Map();
3646
+ function clearTokenCache() {
3647
+ tokenCache.clear();
3648
+ pendingExchanges.clear();
3649
+ }
3650
+ var TOKEN_EXPIRATION_BUFFER = 5 * 60 * 1e3;
3651
+ function getCachedToken(clientId) {
3652
+ const cached = tokenCache.get(clientId);
3653
+ if (!cached) return void 0;
3654
+ if (cached.expiresAt > Date.now() + TOKEN_EXPIRATION_BUFFER) {
3655
+ return cached.accessToken;
3656
+ }
3657
+ tokenCache.delete(clientId);
3658
+ return void 0;
3659
+ }
3660
+ function cacheToken(clientId, accessToken, expiresIn) {
3661
+ tokenCache.set(clientId, {
3662
+ accessToken,
3663
+ expiresAt: Date.now() + expiresIn * 1e3
3664
+ });
3665
+ }
3666
+ function invalidateCachedToken(clientId) {
3667
+ tokenCache.delete(clientId);
3668
+ }
3669
+ function getTokenEndpointUrl(baseUrl) {
3670
+ const base = baseUrl || ZAPIER_BASE_URL;
3671
+ return `${base}/oauth/token/`;
3672
+ }
3673
+ async function exchangeClientCredentials(options) {
3674
+ const { clientId, clientSecret, baseUrl, scope, onEvent } = options;
3675
+ const fetchFn = options.fetch || globalThis.fetch;
3676
+ const tokenUrl = getTokenEndpointUrl(baseUrl);
3677
+ onEvent?.({
3678
+ type: "auth_exchanging",
3679
+ payload: {
3680
+ message: "Exchanging client credentials for token...",
3681
+ operation: "client_credentials"
3682
+ },
3683
+ timestamp: Date.now()
3684
+ });
3685
+ const response = await fetchFn(tokenUrl, {
3686
+ method: "POST",
3687
+ headers: {
3688
+ "Content-Type": "application/x-www-form-urlencoded"
3689
+ },
3690
+ body: new URLSearchParams({
3691
+ grant_type: "client_credentials",
3692
+ client_id: clientId,
3693
+ client_secret: clientSecret,
3694
+ scope: scope || "external",
3695
+ audience: "zapier.com"
3696
+ })
3697
+ });
3698
+ if (!response.ok) {
3699
+ const errorText = await response.text();
3700
+ onEvent?.({
3701
+ type: "auth_error",
3702
+ payload: {
3703
+ message: `Client credentials exchange failed: ${response.status}`,
3704
+ error: errorText,
3705
+ operation: "client_credentials"
3706
+ },
3707
+ timestamp: Date.now()
3708
+ });
3709
+ throw new Error(
3710
+ `Client credentials exchange failed: ${response.status} ${response.statusText}`
3711
+ );
3712
+ }
3713
+ const data = await response.json();
3714
+ if (!data.access_token) {
3715
+ throw new Error("Client credentials response missing access_token");
3716
+ }
3717
+ const expiresIn = data.expires_in || 3600;
3718
+ cacheToken(clientId, data.access_token, expiresIn);
3719
+ onEvent?.({
3720
+ type: "auth_success",
3721
+ payload: {
3722
+ message: "Client credentials exchange successful",
3723
+ operation: "client_credentials"
3724
+ },
3725
+ timestamp: Date.now()
3726
+ });
3727
+ return data.access_token;
3728
+ }
3729
+ async function getTokenFromCliLogin(options) {
3730
+ try {
3731
+ const cliLogin = await import('@zapier/zapier-sdk-cli-login');
3732
+ return await cliLogin.getToken(options);
3733
+ } catch {
3734
+ return void 0;
3735
+ }
3736
+ }
3737
+ async function resolveAuthToken(options = {}) {
3738
+ const credentials = await resolveCredentials({
3739
+ credentials: options.credentials,
3740
+ token: options.token
3741
+ });
3742
+ if (credentials !== void 0) {
3743
+ return resolveAuthTokenFromCredentials(credentials, options);
3744
+ }
3745
+ return getTokenFromCliLogin({
3746
+ onEvent: options.onEvent,
3747
+ fetch: options.fetch
3748
+ });
3749
+ }
3750
+ async function resolveAuthTokenFromCredentials(credentials, options) {
3751
+ if (typeof credentials === "string") {
3752
+ return credentials;
3753
+ }
3754
+ if (isClientCredentials(credentials)) {
3755
+ const { clientId } = credentials;
3756
+ const cached = getCachedToken(clientId);
3757
+ if (cached) {
3758
+ return cached;
3759
+ }
3760
+ const pending = pendingExchanges.get(clientId);
3761
+ if (pending) {
3762
+ return pending;
3763
+ }
3764
+ const exchangePromise = exchangeClientCredentials({
3765
+ clientId: credentials.clientId,
3766
+ clientSecret: credentials.clientSecret,
3767
+ baseUrl: credentials.baseUrl || options.baseUrl,
3768
+ scope: credentials.scope,
3769
+ fetch: options.fetch,
3770
+ onEvent: options.onEvent
3771
+ }).finally(() => {
3772
+ pendingExchanges.delete(clientId);
3773
+ });
3774
+ pendingExchanges.set(clientId, exchangePromise);
3775
+ return exchangePromise;
3776
+ }
3777
+ if (isPkceCredentials(credentials)) {
3778
+ const storedToken = await getTokenFromCliLogin({
3779
+ onEvent: options.onEvent,
3780
+ fetch: options.fetch,
3781
+ credentials
3782
+ });
3783
+ if (storedToken) {
3784
+ return storedToken;
3785
+ }
3786
+ throw new Error(
3787
+ "PKCE credentials require interactive login. Please run the 'login' command with the CLI first, or use client_credentials flow."
3788
+ );
3789
+ }
3790
+ throw new Error("Unknown credentials type");
3791
+ }
3792
+ async function invalidateCredentialsToken(options) {
3793
+ const resolved = await resolveCredentials(options);
3794
+ const clientId = getClientIdFromCredentials(resolved);
3795
+ if (clientId) {
3796
+ invalidateCachedToken(clientId);
3797
+ }
3798
+ }
3799
+
3524
3800
  // src/api/client.ts
3525
3801
  var pathConfig = {
3526
3802
  // e.g. /relay -> https://sdkapi.zapier.com/api/v0/sdk/relay/...
@@ -3578,13 +3854,11 @@ var ZapierApiClient = class {
3578
3854
  // Helper to get a token from the different places it could be gotten
3579
3855
  async getAuthToken() {
3580
3856
  return resolveAuthToken({
3857
+ credentials: this.options.credentials,
3581
3858
  token: this.options.token,
3582
- getToken: this.options.getToken,
3583
3859
  onEvent: this.options.onEvent,
3584
3860
  fetch: this.options.fetch,
3585
- baseUrl: this.options.baseUrl,
3586
- authBaseUrl: this.options.authBaseUrl,
3587
- authClientId: this.options.authClientId
3861
+ baseUrl: this.options.baseUrl
3588
3862
  });
3589
3863
  }
3590
3864
  // Helper to handle responses
@@ -3622,10 +3896,16 @@ var ZapierApiClient = class {
3622
3896
  if (response.status === 401 || response.status === 403) {
3623
3897
  if (wasMissingAuthToken) {
3624
3898
  throw new ZapierAuthenticationError(
3625
- `Authentication required (HTTP ${response.status}). Please provide a token in options or set ZAPIER_TOKEN environment variable.`,
3899
+ `Authentication required (HTTP ${response.status}). Please provide credentials in options or set ZAPIER_CREDENTIALS environment variable.`,
3626
3900
  errorOptions
3627
3901
  );
3628
3902
  }
3903
+ if (response.status === 401) {
3904
+ await invalidateCredentialsToken({
3905
+ credentials: this.options.credentials,
3906
+ token: this.options.token
3907
+ });
3908
+ }
3629
3909
  throw new ZapierAuthenticationError(message, errorOptions);
3630
3910
  }
3631
3911
  if (response.status === 400) {
@@ -3761,7 +4041,7 @@ var ZapierApiClient = class {
3761
4041
  if (options.authRequired) {
3762
4042
  if (headers.get("Authorization") == null && authToken == null) {
3763
4043
  throw new ZapierAuthenticationError(
3764
- `Authentication required but no token available. Please set ZAPIER_TOKEN, or run the 'login' command with the CLI.`
4044
+ `Authentication required but no credentials available. Please set ZAPIER_CREDENTIALS, or run the 'login' command with the CLI.`
3765
4045
  );
3766
4046
  }
3767
4047
  }
@@ -3837,27 +4117,28 @@ var apiPlugin = (params) => {
3837
4117
  const {
3838
4118
  fetch: customFetch = globalThis.fetch,
3839
4119
  baseUrl = ZAPIER_BASE_URL,
3840
- authBaseUrl,
3841
- authClientId,
4120
+ credentials,
3842
4121
  token,
3843
- getToken,
3844
4122
  onEvent,
3845
4123
  debug = false
3846
4124
  } = params.context.options;
3847
4125
  const api = createZapierApi({
3848
4126
  baseUrl,
3849
- authBaseUrl,
3850
- authClientId,
4127
+ credentials,
3851
4128
  token,
3852
- getToken,
3853
4129
  debug,
3854
4130
  fetch: customFetch,
3855
4131
  onEvent
3856
4132
  });
3857
4133
  return {
3858
4134
  context: {
3859
- api
4135
+ api,
3860
4136
  // Provide API client in context for other plugins to use
4137
+ resolveCredentials: () => resolveCredentials({
4138
+ credentials,
4139
+ token,
4140
+ baseUrl
4141
+ })
3861
4142
  }
3862
4143
  };
3863
4144
  };
@@ -4451,7 +4732,7 @@ function getCpuTime() {
4451
4732
 
4452
4733
  // package.json
4453
4734
  var package_default = {
4454
- version: "0.18.4"};
4735
+ version: "1.0.2"};
4455
4736
 
4456
4737
  // src/plugins/eventEmission/builders.ts
4457
4738
  function createBaseEvent(context = {}) {
@@ -4624,11 +4905,9 @@ var eventEmissionPlugin = ({ context }) => {
4624
4905
  const getUserContext = (async () => {
4625
4906
  try {
4626
4907
  const token = await resolveAuthToken({
4908
+ credentials: context.options.credentials,
4627
4909
  token: context.options.token,
4628
- getToken: context.options.getToken,
4629
4910
  baseUrl: context.options.baseUrl,
4630
- authBaseUrl: context.options.authBaseUrl,
4631
- authClientId: context.options.authClientId,
4632
4911
  onEvent: context.options.onEvent,
4633
4912
  fetch: context.options.fetch
4634
4913
  });
@@ -4893,4 +5172,4 @@ function createZapierSdk(options = {}) {
4893
5172
  return createZapierSdkWithoutRegistry(options).addPlugin(registryPlugin);
4894
5173
  }
4895
5174
 
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 };
5175
+ 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
  };
24
28
  };
@@ -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;AAMnE,MAAM,WAAW,mBAAmB;IAClC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,eAAe,CAAC;CAC7B;AAGD,MAAM,WAAW,oBAAoB;IACnC,aAAa,EAAE;QACb,SAAS,EAAE,cAAc,CAAC;QAC1B,MAAM,EAAE,mBAAmB,CAAC;QAE5B,IAAI,CAAC,CAAC,SAAS,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;QAErD,eAAe,IAAI,OAAO,CAAC,SAAS,CAAC,CAAC;QAEtC,gBAAgB,CAAC,IAAI,EAAE,qBAAqB,GAAG,IAAI,CAAC;KACrD,CAAC;CACH;AAED,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,oBAAoB,CAAC;CAC/B;AA6FD,eAAO,MAAM,mBAAmB,EAAE,MAAM,CACtC,EAAE,EACF;IACE,OAAO,EAAE;QACP,aAAa,CAAC,EAAE,mBAAmB,CAAC;QACpC,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC;CACH,EACD,qBAAqB,CAkStB,CAAC;AAGF,YAAY,EACV,YAAY,EACZ,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"}
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;AAMnE,MAAM,WAAW,mBAAmB;IAClC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,eAAe,CAAC;CAC7B;AAGD,MAAM,WAAW,oBAAoB;IACnC,aAAa,EAAE;QACb,SAAS,EAAE,cAAc,CAAC;QAC1B,MAAM,EAAE,mBAAmB,CAAC;QAE5B,IAAI,CAAC,CAAC,SAAS,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;QAErD,eAAe,IAAI,OAAO,CAAC,SAAS,CAAC,CAAC;QAEtC,gBAAgB,CAAC,IAAI,EAAE,qBAAqB,GAAG,IAAI,CAAC;KACrD,CAAC;CACH;AAED,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,oBAAoB,CAAC;CAC/B;AA6FD,eAAO,MAAM,mBAAmB,EAAE,MAAM,CACtC,EAAE,EACF;IACE,OAAO,EAAE;QACP,aAAa,CAAC,EAAE,mBAAmB,CAAC;QACpC,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC;CACH,EACD,qBAAqB,CAgStB,CAAC;AAGF,YAAY,EACV,YAAY,EACZ,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";