@zapier/zapier-sdk 0.18.3 → 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 (112) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +1 -1
  3. package/dist/api/client.d.ts.map +1 -1
  4. package/dist/api/client.js +11 -24
  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 -114
  10. package/dist/api/schemas.d.ts.map +1 -1
  11. package/dist/api/schemas.js +0 -67
  12. package/dist/api/types.d.ts +10 -4
  13. package/dist/api/types.d.ts.map +1 -1
  14. package/dist/auth.d.ts +54 -26
  15. package/dist/auth.d.ts.map +1 -1
  16. package/dist/auth.js +211 -39
  17. package/dist/auth.test.js +338 -64
  18. package/dist/constants.d.ts +14 -0
  19. package/dist/constants.d.ts.map +1 -1
  20. package/dist/constants.js +14 -0
  21. package/dist/credentials.d.ts +57 -0
  22. package/dist/credentials.d.ts.map +1 -0
  23. package/dist/credentials.js +174 -0
  24. package/dist/index.cjs +644 -685
  25. package/dist/index.d.mts +265 -134
  26. package/dist/index.d.ts +3 -0
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +5 -0
  29. package/dist/index.mjs +624 -684
  30. package/dist/plugins/api/index.d.ts +2 -0
  31. package/dist/plugins/api/index.d.ts.map +1 -1
  32. package/dist/plugins/api/index.js +8 -4
  33. package/dist/plugins/eventEmission/index.d.ts.map +1 -1
  34. package/dist/plugins/eventEmission/index.js +1 -3
  35. package/dist/plugins/eventEmission/index.test.js +14 -17
  36. package/dist/plugins/getAction/schemas.d.ts +1 -1
  37. package/dist/plugins/getInputFieldsSchema/schemas.d.ts +1 -1
  38. package/dist/plugins/listActions/index.test.js +1 -0
  39. package/dist/plugins/listActions/schemas.d.ts +1 -1
  40. package/dist/plugins/listApps/index.d.ts +2 -8
  41. package/dist/plugins/listApps/index.d.ts.map +1 -1
  42. package/dist/plugins/listApps/index.js +4 -6
  43. package/dist/plugins/listApps/index.test.js +62 -82
  44. package/dist/plugins/listApps/schemas.d.ts +35 -14
  45. package/dist/plugins/listApps/schemas.d.ts.map +1 -1
  46. package/dist/plugins/listApps/schemas.js +44 -14
  47. package/dist/plugins/listAuthentications/index.test.js +16 -0
  48. package/dist/plugins/listInputFieldChoices/schemas.d.ts +1 -1
  49. package/dist/plugins/listInputFields/schemas.d.ts +1 -1
  50. package/dist/plugins/runAction/schemas.d.ts +1 -1
  51. package/dist/schemas/Action.d.ts +1 -1
  52. package/dist/schemas/App.d.ts +28 -28
  53. package/dist/schemas/App.d.ts.map +1 -1
  54. package/dist/schemas/App.js +3 -8
  55. package/dist/sdk.d.ts +2 -1
  56. package/dist/sdk.d.ts.map +1 -1
  57. package/dist/sdk.test.js +17 -13
  58. package/dist/types/credentials.d.ts +65 -0
  59. package/dist/types/credentials.d.ts.map +1 -0
  60. package/dist/types/credentials.js +42 -0
  61. package/dist/types/properties.d.ts +1 -1
  62. package/dist/types/sdk.d.ts +12 -3
  63. package/dist/types/sdk.d.ts.map +1 -1
  64. package/dist/utils/logging.d.ts +13 -0
  65. package/dist/utils/logging.d.ts.map +1 -0
  66. package/dist/utils/logging.js +20 -0
  67. package/package.json +2 -2
  68. package/dist/api/client.integration.test.d.ts +0 -5
  69. package/dist/api/client.integration.test.d.ts.map +0 -1
  70. package/dist/api/client.integration.test.js +0 -318
  71. package/dist/api/client.methods.test.d.ts +0 -2
  72. package/dist/api/client.methods.test.d.ts.map +0 -1
  73. package/dist/api/client.methods.test.js +0 -158
  74. package/dist/api/router.d.ts +0 -16
  75. package/dist/api/router.d.ts.map +0 -1
  76. package/dist/api/router.js +0 -31
  77. package/dist/api/router.test.d.ts +0 -2
  78. package/dist/api/router.test.d.ts.map +0 -1
  79. package/dist/api/router.test.js +0 -103
  80. package/dist/temporary-internal-core/handlers/listApps.d.ts +0 -67
  81. package/dist/temporary-internal-core/handlers/listApps.d.ts.map +0 -1
  82. package/dist/temporary-internal-core/handlers/listApps.js +0 -134
  83. package/dist/temporary-internal-core/handlers/listApps.test.d.ts +0 -2
  84. package/dist/temporary-internal-core/handlers/listApps.test.d.ts.map +0 -1
  85. package/dist/temporary-internal-core/handlers/listApps.test.js +0 -367
  86. package/dist/temporary-internal-core/index.d.ts +0 -18
  87. package/dist/temporary-internal-core/index.d.ts.map +0 -1
  88. package/dist/temporary-internal-core/index.js +0 -18
  89. package/dist/temporary-internal-core/schemas/apps/index.d.ts +0 -175
  90. package/dist/temporary-internal-core/schemas/apps/index.d.ts.map +0 -1
  91. package/dist/temporary-internal-core/schemas/apps/index.js +0 -97
  92. package/dist/temporary-internal-core/schemas/errors/index.d.ts +0 -139
  93. package/dist/temporary-internal-core/schemas/errors/index.d.ts.map +0 -1
  94. package/dist/temporary-internal-core/schemas/errors/index.js +0 -129
  95. package/dist/temporary-internal-core/schemas/implementations/index.d.ts +0 -127
  96. package/dist/temporary-internal-core/schemas/implementations/index.d.ts.map +0 -1
  97. package/dist/temporary-internal-core/schemas/implementations/index.js +0 -79
  98. package/dist/temporary-internal-core/types/handler.d.ts +0 -51
  99. package/dist/temporary-internal-core/types/handler.d.ts.map +0 -1
  100. package/dist/temporary-internal-core/types/handler.js +0 -8
  101. package/dist/temporary-internal-core/types/index.d.ts +0 -5
  102. package/dist/temporary-internal-core/types/index.d.ts.map +0 -1
  103. package/dist/temporary-internal-core/types/index.js +0 -4
  104. package/dist/temporary-internal-core/utils/app-locators.d.ts +0 -34
  105. package/dist/temporary-internal-core/utils/app-locators.d.ts.map +0 -1
  106. package/dist/temporary-internal-core/utils/app-locators.js +0 -39
  107. package/dist/temporary-internal-core/utils/string-utils.d.ts +0 -28
  108. package/dist/temporary-internal-core/utils/string-utils.d.ts.map +0 -1
  109. package/dist/temporary-internal-core/utils/string-utils.js +0 -52
  110. package/dist/temporary-internal-core/utils/transformations.d.ts +0 -18
  111. package/dist/temporary-internal-core/utils/transformations.d.ts.map +0 -1
  112. package/dist/temporary-internal-core/utils/transformations.js +0 -36
@@ -0,0 +1,174 @@
1
+ /**
2
+ * Credentials Resolution
3
+ *
4
+ * This module provides the core logic for resolving credentials from various sources:
5
+ * - Explicit credentials option
6
+ * - Deprecated token option
7
+ * - Environment variables (new and deprecated)
8
+ * - CLI login stored tokens
9
+ */
10
+ import { isCredentialsFunction, isCredentialsObject, } from "./types/credentials";
11
+ import { logDeprecation } from "./utils/logging";
12
+ import { getZapierBaseUrl } from "./utils/url-utils";
13
+ import { ZAPIER_CREDENTIALS, ZAPIER_CREDENTIALS_CLIENT_ID, ZAPIER_CREDENTIALS_CLIENT_SECRET, ZAPIER_CREDENTIALS_BASE_URL, ZAPIER_CREDENTIALS_SCOPE, ZAPIER_TOKEN, ZAPIER_AUTH_BASE_URL, ZAPIER_AUTH_CLIENT_ID, } from "./constants";
14
+ /**
15
+ * Derive the auth base URL from the SDK base URL.
16
+ * Returns the Zapier root domain (e.g., https://zapier.com from https://api.zapier.com).
17
+ */
18
+ function deriveAuthBaseUrl(sdkBaseUrl) {
19
+ if (!sdkBaseUrl)
20
+ return undefined;
21
+ return getZapierBaseUrl(sdkBaseUrl);
22
+ }
23
+ /**
24
+ * Normalize a credentials object by ensuring it has a type and resolved baseUrl.
25
+ */
26
+ function normalizeCredentialsObject(obj, sdkBaseUrl) {
27
+ // Resolve baseUrl: use credentials baseUrl, or derive from SDK baseUrl
28
+ const resolvedBaseUrl = obj.baseUrl || deriveAuthBaseUrl(sdkBaseUrl);
29
+ // Explicitly construct the correct typed object to satisfy TypeScript
30
+ if (obj.type === "client_credentials" ||
31
+ ("clientSecret" in obj && obj.clientSecret)) {
32
+ return {
33
+ type: "client_credentials",
34
+ clientId: obj.clientId,
35
+ clientSecret: obj.clientSecret,
36
+ baseUrl: resolvedBaseUrl,
37
+ scope: obj.scope,
38
+ };
39
+ }
40
+ return {
41
+ type: "pkce",
42
+ clientId: obj.clientId,
43
+ baseUrl: resolvedBaseUrl,
44
+ scope: obj.scope,
45
+ };
46
+ }
47
+ /**
48
+ * Resolve credentials from environment variables.
49
+ *
50
+ * Precedence:
51
+ * 1. ZAPIER_CREDENTIALS (string token)
52
+ * 2. ZAPIER_CREDENTIALS_CLIENT_ID + ZAPIER_CREDENTIALS_CLIENT_SECRET (client credentials)
53
+ * 3. ZAPIER_CREDENTIALS_CLIENT_ID alone (PKCE)
54
+ * 4. Deprecated ZAPIER_TOKEN, ZAPIER_AUTH_* vars (with warnings)
55
+ *
56
+ * @param sdkBaseUrl - SDK base URL used to derive auth base URL if not specified
57
+ */
58
+ export function resolveCredentialsFromEnv(sdkBaseUrl) {
59
+ // 1. Check ZAPIER_CREDENTIALS (string token only)
60
+ if (ZAPIER_CREDENTIALS) {
61
+ return ZAPIER_CREDENTIALS;
62
+ }
63
+ // 2. Check ZAPIER_CREDENTIALS_* individual vars
64
+ if (ZAPIER_CREDENTIALS_CLIENT_ID) {
65
+ const resolvedBaseUrl = ZAPIER_CREDENTIALS_BASE_URL || deriveAuthBaseUrl(sdkBaseUrl);
66
+ // Infer type from presence of clientSecret
67
+ if (ZAPIER_CREDENTIALS_CLIENT_SECRET) {
68
+ return {
69
+ type: "client_credentials",
70
+ clientId: ZAPIER_CREDENTIALS_CLIENT_ID,
71
+ clientSecret: ZAPIER_CREDENTIALS_CLIENT_SECRET,
72
+ baseUrl: resolvedBaseUrl,
73
+ scope: ZAPIER_CREDENTIALS_SCOPE,
74
+ };
75
+ }
76
+ else {
77
+ return {
78
+ type: "pkce",
79
+ clientId: ZAPIER_CREDENTIALS_CLIENT_ID,
80
+ baseUrl: resolvedBaseUrl,
81
+ scope: ZAPIER_CREDENTIALS_SCOPE,
82
+ };
83
+ }
84
+ }
85
+ // 3. Check deprecated env vars (with warnings)
86
+ if (ZAPIER_TOKEN) {
87
+ logDeprecation("ZAPIER_TOKEN is deprecated. Use ZAPIER_CREDENTIALS instead.");
88
+ return ZAPIER_TOKEN;
89
+ }
90
+ if (ZAPIER_AUTH_CLIENT_ID) {
91
+ logDeprecation("ZAPIER_AUTH_CLIENT_ID is deprecated. Use ZAPIER_CREDENTIALS_CLIENT_ID instead.");
92
+ if (ZAPIER_AUTH_BASE_URL) {
93
+ logDeprecation("ZAPIER_AUTH_BASE_URL is deprecated. Use ZAPIER_CREDENTIALS_BASE_URL instead.");
94
+ }
95
+ const resolvedBaseUrl = ZAPIER_AUTH_BASE_URL || deriveAuthBaseUrl(sdkBaseUrl);
96
+ return {
97
+ type: "pkce",
98
+ clientId: ZAPIER_AUTH_CLIENT_ID,
99
+ baseUrl: resolvedBaseUrl,
100
+ };
101
+ }
102
+ return undefined;
103
+ }
104
+ /**
105
+ * Resolve credentials from all possible sources.
106
+ *
107
+ * Precedence:
108
+ * 1. Explicit credentials option
109
+ * 2. Deprecated token option (with warning)
110
+ * 3. Environment variables
111
+ * 4. CLI login stored token (handled separately in auth.ts)
112
+ *
113
+ * If credentials is a function, it is called and must return
114
+ * a string or credentials object (not another function).
115
+ *
116
+ * The baseUrl option is used to derive the auth base URL if not
117
+ * specified in credentials.
118
+ */
119
+ export async function resolveCredentials(options = {}) {
120
+ const { baseUrl } = options;
121
+ // 1. Check explicit credentials option
122
+ if (options.credentials !== undefined) {
123
+ // If it's a function, call it
124
+ if (isCredentialsFunction(options.credentials)) {
125
+ const resolved = await options.credentials();
126
+ // Validate that the function didn't return another function
127
+ if (typeof resolved === "function") {
128
+ throw new Error("Credentials function returned another function. " +
129
+ "Credentials functions must return a string or credentials object.");
130
+ }
131
+ // Normalize object if needed
132
+ if (isCredentialsObject(resolved)) {
133
+ return normalizeCredentialsObject(resolved, baseUrl);
134
+ }
135
+ return resolved;
136
+ }
137
+ // If it's an object, normalize it
138
+ if (isCredentialsObject(options.credentials)) {
139
+ return normalizeCredentialsObject(options.credentials, baseUrl);
140
+ }
141
+ // It's a string token
142
+ return options.credentials;
143
+ }
144
+ // 2. Check deprecated token option (with warning)
145
+ if (options.token !== undefined) {
146
+ logDeprecation("The `token` option is deprecated. Use `credentials` instead.");
147
+ return options.token;
148
+ }
149
+ // 3. Check environment variables
150
+ const envCredentials = resolveCredentialsFromEnv(baseUrl);
151
+ if (envCredentials !== undefined) {
152
+ return envCredentials;
153
+ }
154
+ // 4. CLI login is handled separately in auth.ts
155
+ return undefined;
156
+ }
157
+ /**
158
+ * Extract the base URL from credentials for use in auth flows.
159
+ */
160
+ export function getBaseUrlFromCredentials(credentials) {
161
+ if (credentials && isCredentialsObject(credentials)) {
162
+ return credentials.baseUrl;
163
+ }
164
+ return undefined;
165
+ }
166
+ /**
167
+ * Extract the client ID from credentials for use in auth flows.
168
+ */
169
+ export function getClientIdFromCredentials(credentials) {
170
+ if (credentials && isCredentialsObject(credentials)) {
171
+ return credentials.clientId;
172
+ }
173
+ return undefined;
174
+ }