@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.
- package/CHANGELOG.md +17 -0
- package/README.md +1 -1
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +11 -24
- package/dist/api/client.test.js +82 -27
- package/dist/api/index.d.ts +3 -2
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +2 -3
- package/dist/api/schemas.d.ts +5 -114
- package/dist/api/schemas.d.ts.map +1 -1
- package/dist/api/schemas.js +0 -67
- package/dist/api/types.d.ts +10 -4
- package/dist/api/types.d.ts.map +1 -1
- package/dist/auth.d.ts +54 -26
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +211 -39
- package/dist/auth.test.js +338 -64
- package/dist/constants.d.ts +14 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +14 -0
- package/dist/credentials.d.ts +57 -0
- package/dist/credentials.d.ts.map +1 -0
- package/dist/credentials.js +174 -0
- package/dist/index.cjs +644 -685
- package/dist/index.d.mts +265 -134
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.mjs +624 -684
- package/dist/plugins/api/index.d.ts +2 -0
- package/dist/plugins/api/index.d.ts.map +1 -1
- package/dist/plugins/api/index.js +8 -4
- package/dist/plugins/eventEmission/index.d.ts.map +1 -1
- package/dist/plugins/eventEmission/index.js +1 -3
- package/dist/plugins/eventEmission/index.test.js +14 -17
- package/dist/plugins/getAction/schemas.d.ts +1 -1
- package/dist/plugins/getInputFieldsSchema/schemas.d.ts +1 -1
- package/dist/plugins/listActions/index.test.js +1 -0
- package/dist/plugins/listActions/schemas.d.ts +1 -1
- package/dist/plugins/listApps/index.d.ts +2 -8
- package/dist/plugins/listApps/index.d.ts.map +1 -1
- package/dist/plugins/listApps/index.js +4 -6
- package/dist/plugins/listApps/index.test.js +62 -82
- package/dist/plugins/listApps/schemas.d.ts +35 -14
- package/dist/plugins/listApps/schemas.d.ts.map +1 -1
- package/dist/plugins/listApps/schemas.js +44 -14
- package/dist/plugins/listAuthentications/index.test.js +16 -0
- package/dist/plugins/listInputFieldChoices/schemas.d.ts +1 -1
- package/dist/plugins/listInputFields/schemas.d.ts +1 -1
- package/dist/plugins/runAction/schemas.d.ts +1 -1
- package/dist/schemas/Action.d.ts +1 -1
- package/dist/schemas/App.d.ts +28 -28
- package/dist/schemas/App.d.ts.map +1 -1
- package/dist/schemas/App.js +3 -8
- package/dist/sdk.d.ts +2 -1
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.test.js +17 -13
- package/dist/types/credentials.d.ts +65 -0
- package/dist/types/credentials.d.ts.map +1 -0
- package/dist/types/credentials.js +42 -0
- package/dist/types/properties.d.ts +1 -1
- package/dist/types/sdk.d.ts +12 -3
- package/dist/types/sdk.d.ts.map +1 -1
- package/dist/utils/logging.d.ts +13 -0
- package/dist/utils/logging.d.ts.map +1 -0
- package/dist/utils/logging.js +20 -0
- package/package.json +2 -2
- package/dist/api/client.integration.test.d.ts +0 -5
- package/dist/api/client.integration.test.d.ts.map +0 -1
- package/dist/api/client.integration.test.js +0 -318
- package/dist/api/client.methods.test.d.ts +0 -2
- package/dist/api/client.methods.test.d.ts.map +0 -1
- package/dist/api/client.methods.test.js +0 -158
- package/dist/api/router.d.ts +0 -16
- package/dist/api/router.d.ts.map +0 -1
- package/dist/api/router.js +0 -31
- package/dist/api/router.test.d.ts +0 -2
- package/dist/api/router.test.d.ts.map +0 -1
- package/dist/api/router.test.js +0 -103
- package/dist/temporary-internal-core/handlers/listApps.d.ts +0 -67
- package/dist/temporary-internal-core/handlers/listApps.d.ts.map +0 -1
- package/dist/temporary-internal-core/handlers/listApps.js +0 -134
- package/dist/temporary-internal-core/handlers/listApps.test.d.ts +0 -2
- package/dist/temporary-internal-core/handlers/listApps.test.d.ts.map +0 -1
- package/dist/temporary-internal-core/handlers/listApps.test.js +0 -367
- package/dist/temporary-internal-core/index.d.ts +0 -18
- package/dist/temporary-internal-core/index.d.ts.map +0 -1
- package/dist/temporary-internal-core/index.js +0 -18
- package/dist/temporary-internal-core/schemas/apps/index.d.ts +0 -175
- package/dist/temporary-internal-core/schemas/apps/index.d.ts.map +0 -1
- package/dist/temporary-internal-core/schemas/apps/index.js +0 -97
- package/dist/temporary-internal-core/schemas/errors/index.d.ts +0 -139
- package/dist/temporary-internal-core/schemas/errors/index.d.ts.map +0 -1
- package/dist/temporary-internal-core/schemas/errors/index.js +0 -129
- package/dist/temporary-internal-core/schemas/implementations/index.d.ts +0 -127
- package/dist/temporary-internal-core/schemas/implementations/index.d.ts.map +0 -1
- package/dist/temporary-internal-core/schemas/implementations/index.js +0 -79
- package/dist/temporary-internal-core/types/handler.d.ts +0 -51
- package/dist/temporary-internal-core/types/handler.d.ts.map +0 -1
- package/dist/temporary-internal-core/types/handler.js +0 -8
- package/dist/temporary-internal-core/types/index.d.ts +0 -5
- package/dist/temporary-internal-core/types/index.d.ts.map +0 -1
- package/dist/temporary-internal-core/types/index.js +0 -4
- package/dist/temporary-internal-core/utils/app-locators.d.ts +0 -34
- package/dist/temporary-internal-core/utils/app-locators.d.ts.map +0 -1
- package/dist/temporary-internal-core/utils/app-locators.js +0 -39
- package/dist/temporary-internal-core/utils/string-utils.d.ts +0 -28
- package/dist/temporary-internal-core/utils/string-utils.d.ts.map +0 -1
- package/dist/temporary-internal-core/utils/string-utils.js +0 -52
- package/dist/temporary-internal-core/utils/transformations.d.ts +0 -18
- package/dist/temporary-internal-core/utils/transformations.d.ts.map +0 -1
- 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
|
+
}
|