@zapier/zapier-sdk 0.45.2 → 0.46.1
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 +12 -0
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +24 -7
- package/dist/api/schemas.d.ts +5 -5
- package/dist/api/types.d.ts +17 -0
- package/dist/api/types.d.ts.map +1 -1
- package/dist/auth.d.ts +27 -6
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +130 -92
- package/dist/cache.d.ts +50 -0
- package/dist/cache.d.ts.map +1 -0
- package/dist/cache.js +47 -0
- package/dist/index.cjs +3108 -3695
- package/dist/index.d.mts +6735 -2188
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.mjs +3105 -3696
- package/dist/plugins/api/index.d.ts +22 -10
- package/dist/plugins/api/index.d.ts.map +1 -1
- package/dist/plugins/api/index.js +4 -4
- package/dist/plugins/apps/index.d.ts +108 -7
- package/dist/plugins/apps/index.d.ts.map +1 -1
- package/dist/plugins/apps/index.js +3 -4
- package/dist/plugins/capabilities/index.d.ts +9 -6
- package/dist/plugins/capabilities/index.d.ts.map +1 -1
- package/dist/plugins/capabilities/index.js +3 -2
- package/dist/plugins/connections/index.d.ts +15 -9
- package/dist/plugins/connections/index.d.ts.map +1 -1
- package/dist/plugins/connections/index.js +3 -2
- package/dist/plugins/createClientCredentials/index.d.ts +26 -14
- package/dist/plugins/createClientCredentials/index.d.ts.map +1 -1
- package/dist/plugins/createClientCredentials/index.js +16 -39
- package/dist/plugins/createClientCredentials/schemas.d.ts +0 -2
- package/dist/plugins/createClientCredentials/schemas.d.ts.map +1 -1
- package/dist/plugins/deleteClientCredentials/index.d.ts +20 -14
- package/dist/plugins/deleteClientCredentials/index.d.ts.map +1 -1
- package/dist/plugins/deleteClientCredentials/index.js +18 -37
- package/dist/plugins/deleteClientCredentials/schemas.d.ts +0 -2
- package/dist/plugins/deleteClientCredentials/schemas.d.ts.map +1 -1
- package/dist/plugins/deprecated/authentications.d.ts +597 -41
- package/dist/plugins/deprecated/authentications.d.ts.map +1 -1
- package/dist/plugins/deprecated/authentications.js +9 -8
- package/dist/plugins/eventEmission/index.d.ts +9 -6
- package/dist/plugins/eventEmission/index.d.ts.map +1 -1
- package/dist/plugins/eventEmission/index.js +3 -2
- package/dist/plugins/fetch/index.d.ts +40 -17
- package/dist/plugins/fetch/index.d.ts.map +1 -1
- package/dist/plugins/fetch/index.js +6 -4
- package/dist/plugins/findFirstConnection/index.d.ts +109 -14
- package/dist/plugins/findFirstConnection/index.d.ts.map +1 -1
- package/dist/plugins/findFirstConnection/index.js +14 -26
- package/dist/plugins/findFirstConnection/schemas.d.ts +0 -2
- package/dist/plugins/findFirstConnection/schemas.d.ts.map +1 -1
- package/dist/plugins/findUniqueConnection/index.d.ts +109 -14
- package/dist/plugins/findUniqueConnection/index.d.ts.map +1 -1
- package/dist/plugins/findUniqueConnection/index.js +14 -26
- package/dist/plugins/findUniqueConnection/schemas.d.ts +0 -2
- package/dist/plugins/findUniqueConnection/schemas.d.ts.map +1 -1
- package/dist/plugins/getAction/index.d.ts +68 -15
- package/dist/plugins/getAction/index.d.ts.map +1 -1
- package/dist/plugins/getAction/index.js +21 -31
- package/dist/plugins/getAction/schemas.d.ts +4 -6
- package/dist/plugins/getAction/schemas.d.ts.map +1 -1
- package/dist/plugins/getApp/index.d.ts +140 -14
- package/dist/plugins/getApp/index.d.ts.map +1 -1
- package/dist/plugins/getApp/index.js +16 -38
- package/dist/plugins/getApp/schemas.d.ts +0 -2
- package/dist/plugins/getApp/schemas.d.ts.map +1 -1
- package/dist/plugins/getConnection/index.d.ts +50 -16
- package/dist/plugins/getConnection/index.d.ts.map +1 -1
- package/dist/plugins/getConnection/index.js +22 -29
- package/dist/plugins/getConnection/schemas.d.ts +0 -2
- package/dist/plugins/getConnection/schemas.d.ts.map +1 -1
- package/dist/plugins/getInputFieldsSchema/index.d.ts +59 -13
- package/dist/plugins/getInputFieldsSchema/index.d.ts.map +1 -1
- package/dist/plugins/getInputFieldsSchema/index.js +21 -32
- package/dist/plugins/getInputFieldsSchema/schemas.d.ts +4 -6
- package/dist/plugins/getInputFieldsSchema/schemas.d.ts.map +1 -1
- package/dist/plugins/getProfile/index.d.ts +25 -18
- package/dist/plugins/getProfile/index.d.ts.map +1 -1
- package/dist/plugins/getProfile/index.js +13 -26
- package/dist/plugins/getProfile/schemas.d.ts +0 -8
- package/dist/plugins/getProfile/schemas.d.ts.map +1 -1
- package/dist/plugins/getProfile/schemas.js +0 -1
- package/dist/plugins/listActions/index.d.ts +73 -23
- package/dist/plugins/listActions/index.d.ts.map +1 -1
- package/dist/plugins/listActions/index.js +25 -53
- package/dist/plugins/listActions/schemas.d.ts +4 -15
- package/dist/plugins/listActions/schemas.d.ts.map +1 -1
- package/dist/plugins/listApps/index.d.ts +121 -13
- package/dist/plugins/listApps/index.d.ts.map +1 -1
- package/dist/plugins/listApps/index.js +22 -31
- package/dist/plugins/listApps/schemas.d.ts +0 -2
- package/dist/plugins/listApps/schemas.d.ts.map +1 -1
- package/dist/plugins/listClientCredentials/index.d.ts +29 -16
- package/dist/plugins/listClientCredentials/index.d.ts.map +1 -1
- package/dist/plugins/listClientCredentials/index.js +17 -37
- package/dist/plugins/listClientCredentials/schemas.d.ts +0 -2
- package/dist/plugins/listClientCredentials/schemas.d.ts.map +1 -1
- package/dist/plugins/listConnections/index.d.ts +95 -17
- package/dist/plugins/listConnections/index.d.ts.map +1 -1
- package/dist/plugins/listConnections/index.js +25 -49
- package/dist/plugins/listConnections/schemas.d.ts +0 -2
- package/dist/plugins/listConnections/schemas.d.ts.map +1 -1
- package/dist/plugins/listInputFieldChoices/index.d.ts +77 -22
- package/dist/plugins/listInputFieldChoices/index.d.ts.map +1 -1
- package/dist/plugins/listInputFieldChoices/index.js +27 -50
- package/dist/plugins/listInputFieldChoices/schemas.d.ts +4 -6
- package/dist/plugins/listInputFieldChoices/schemas.d.ts.map +1 -1
- package/dist/plugins/listInputFields/index.d.ts +154 -22
- package/dist/plugins/listInputFields/index.d.ts.map +1 -1
- package/dist/plugins/listInputFields/index.js +28 -41
- package/dist/plugins/listInputFields/schemas.d.ts +4 -6
- package/dist/plugins/listInputFields/schemas.d.ts.map +1 -1
- package/dist/plugins/manifest/index.d.ts +40 -36
- package/dist/plugins/manifest/index.d.ts.map +1 -1
- package/dist/plugins/manifest/index.js +3 -2
- package/dist/plugins/registry/index.d.ts +11 -9
- package/dist/plugins/registry/index.d.ts.map +1 -1
- package/dist/plugins/registry/index.js +3 -2
- package/dist/plugins/request/index.d.ts +61 -15
- package/dist/plugins/request/index.d.ts.map +1 -1
- package/dist/plugins/request/index.js +14 -22
- package/dist/plugins/request/schemas.d.ts +0 -2
- package/dist/plugins/request/schemas.d.ts.map +1 -1
- package/dist/plugins/runAction/index.d.ts +137 -23
- package/dist/plugins/runAction/index.d.ts.map +1 -1
- package/dist/plugins/runAction/index.js +65 -78
- package/dist/plugins/runAction/schemas.d.ts +4 -14
- package/dist/plugins/runAction/schemas.d.ts.map +1 -1
- package/dist/plugins/tables/createTable/index.d.ts +43 -11
- package/dist/plugins/tables/createTable/index.d.ts.map +1 -1
- package/dist/plugins/tables/createTable/index.js +16 -44
- package/dist/plugins/tables/createTable/schemas.d.ts +0 -2
- package/dist/plugins/tables/createTable/schemas.d.ts.map +1 -1
- package/dist/plugins/tables/createTableFields/index.d.ts +54 -11
- package/dist/plugins/tables/createTableFields/index.d.ts.map +1 -1
- package/dist/plugins/tables/createTableFields/index.js +17 -41
- package/dist/plugins/tables/createTableFields/schemas.d.ts +21 -23
- package/dist/plugins/tables/createTableFields/schemas.d.ts.map +1 -1
- package/dist/plugins/tables/createTableRecords/index.d.ts +47 -11
- package/dist/plugins/tables/createTableRecords/index.d.ts.map +1 -1
- package/dist/plugins/tables/createTableRecords/index.js +17 -43
- package/dist/plugins/tables/createTableRecords/schemas.d.ts +0 -2
- package/dist/plugins/tables/createTableRecords/schemas.d.ts.map +1 -1
- package/dist/plugins/tables/deleteTable/index.d.ts +36 -13
- package/dist/plugins/tables/deleteTable/index.d.ts.map +1 -1
- package/dist/plugins/tables/deleteTable/index.js +18 -40
- package/dist/plugins/tables/deleteTable/schemas.d.ts +0 -2
- package/dist/plugins/tables/deleteTable/schemas.d.ts.map +1 -1
- package/dist/plugins/tables/deleteTableFields/index.d.ts +36 -11
- package/dist/plugins/tables/deleteTableFields/index.d.ts.map +1 -1
- package/dist/plugins/tables/deleteTableFields/index.js +17 -39
- package/dist/plugins/tables/deleteTableFields/schemas.d.ts +0 -2
- package/dist/plugins/tables/deleteTableFields/schemas.d.ts.map +1 -1
- package/dist/plugins/tables/deleteTableRecords/index.d.ts +36 -11
- package/dist/plugins/tables/deleteTableRecords/index.d.ts.map +1 -1
- package/dist/plugins/tables/deleteTableRecords/index.js +18 -41
- package/dist/plugins/tables/deleteTableRecords/schemas.d.ts +0 -2
- package/dist/plugins/tables/deleteTableRecords/schemas.d.ts.map +1 -1
- package/dist/plugins/tables/getTable/index.d.ts +43 -12
- package/dist/plugins/tables/getTable/index.d.ts.map +1 -1
- package/dist/plugins/tables/getTable/index.js +18 -43
- package/dist/plugins/tables/getTable/schemas.d.ts +0 -2
- package/dist/plugins/tables/getTable/schemas.d.ts.map +1 -1
- package/dist/plugins/tables/getTableRecord/index.d.ts +43 -11
- package/dist/plugins/tables/getTableRecord/index.d.ts.map +1 -1
- package/dist/plugins/tables/getTableRecord/index.js +18 -42
- package/dist/plugins/tables/getTableRecord/schemas.d.ts +0 -2
- package/dist/plugins/tables/getTableRecord/schemas.d.ts.map +1 -1
- package/dist/plugins/tables/listTableFields/index.d.ts +46 -11
- package/dist/plugins/tables/listTableFields/index.d.ts.map +1 -1
- package/dist/plugins/tables/listTableFields/index.js +17 -41
- package/dist/plugins/tables/listTableFields/schemas.d.ts +12 -14
- package/dist/plugins/tables/listTableFields/schemas.d.ts.map +1 -1
- package/dist/plugins/tables/listTableRecords/index.d.ts +66 -18
- package/dist/plugins/tables/listTableRecords/index.d.ts.map +1 -1
- package/dist/plugins/tables/listTableRecords/index.js +27 -50
- package/dist/plugins/tables/listTableRecords/schemas.d.ts +6 -8
- package/dist/plugins/tables/listTableRecords/schemas.d.ts.map +1 -1
- package/dist/plugins/tables/listTables/index.d.ts +53 -20
- package/dist/plugins/tables/listTables/index.d.ts.map +1 -1
- package/dist/plugins/tables/listTables/index.js +24 -51
- package/dist/plugins/tables/listTables/schemas.d.ts +0 -2
- package/dist/plugins/tables/listTables/schemas.d.ts.map +1 -1
- package/dist/plugins/tables/shared.d.ts +10 -0
- package/dist/plugins/tables/shared.d.ts.map +1 -0
- package/dist/plugins/tables/shared.js +9 -0
- package/dist/plugins/tables/updateTableRecords/index.d.ts +49 -11
- package/dist/plugins/tables/updateTableRecords/index.d.ts.map +1 -1
- package/dist/plugins/tables/updateTableRecords/index.js +20 -43
- package/dist/plugins/tables/updateTableRecords/schemas.d.ts +0 -2
- package/dist/plugins/tables/updateTableRecords/schemas.d.ts.map +1 -1
- package/dist/plugins/tables/utils.d.ts.map +1 -1
- package/dist/plugins/tables/utils.js +1 -0
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +21 -1
- package/dist/resolvers/actionKey.d.ts +1 -2
- package/dist/resolvers/actionKey.d.ts.map +1 -1
- package/dist/resolvers/actionType.d.ts +1 -2
- package/dist/resolvers/actionType.d.ts.map +1 -1
- package/dist/schemas/Action.d.ts +1 -1
- package/dist/sdk.d.ts +2942 -2
- package/dist/sdk.d.ts.map +1 -1
- package/dist/types/credentials.d.ts +2 -1
- package/dist/types/credentials.d.ts.map +1 -1
- package/dist/types/credentials.js +2 -1
- package/dist/types/errors.d.ts +13 -10
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/errors.js +15 -12
- package/dist/types/functions.d.ts +18 -2
- package/dist/types/functions.d.ts.map +1 -1
- package/dist/types/plugin.d.ts +1 -1
- package/dist/types/plugin.d.ts.map +1 -1
- package/dist/types/properties.d.ts +1 -1
- package/dist/types/registry.d.ts +1 -1
- package/dist/types/registry.d.ts.map +1 -1
- package/dist/types/sdk.d.ts +2 -0
- package/dist/types/sdk.d.ts.map +1 -1
- package/dist/types/sdk.js +1 -0
- package/dist/utils/function-utils.d.ts +11 -12
- package/dist/utils/function-utils.d.ts.map +1 -1
- package/dist/utils/plugin-utils.d.ts +168 -0
- package/dist/utils/plugin-utils.d.ts.map +1 -0
- package/dist/utils/plugin-utils.js +132 -0
- package/package.json +2 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @zapier/zapier-sdk
|
|
2
2
|
|
|
3
|
+
## 0.46.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 591ddb5: Removed custom error handlers and added definePlugin, createPluginMethod, and createPaginatedPluginMethod to reduce plugin boilerplate.
|
|
8
|
+
|
|
9
|
+
## 0.46.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- bd887ab: Rename the client credentials persistence seam from storage to cache and expose the CLI filesystem/keychain adapter as a best-effort cache.
|
|
14
|
+
|
|
3
15
|
## 0.45.2
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/api/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,SAAS,EACT,gBAAgB,EAGjB,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,SAAS,EACT,gBAAgB,EAGjB,MAAM,SAAS,CAAC;AAqiCjB,eAAO,MAAM,eAAe,GAAI,SAAS,gBAAgB,KAAG,SAW3D,CAAC"}
|
package/dist/api/client.js
CHANGED
|
@@ -11,7 +11,7 @@ import { resolveAuthToken, invalidateCredentialsToken, isCliLoginAvailable, } fr
|
|
|
11
11
|
import { getZapierBaseUrl } from "../utils/url-utils";
|
|
12
12
|
import { sleep, calculateExponentialBackoffMs } from "../utils/retry-utils";
|
|
13
13
|
import { isPlainObject } from "../utils/type-guard-utils";
|
|
14
|
-
import { ZapierApiError, ZapierApprovalError, ZapierAuthenticationError, ZapierTimeoutError, ZapierValidationError,
|
|
14
|
+
import { ZapierApiError, ZapierApprovalError, ZapierAuthenticationError, ZapierTimeoutError, ZapierValidationError, ZapierResourceNotFoundError, ZapierRateLimitError, } from "../types/errors";
|
|
15
15
|
import { ZAPIER_MAX_NETWORK_RETRIES, ZAPIER_MAX_NETWORK_RETRY_DELAY_MS, getZapierIsInteractive, getZapierApprovalMode, getZapierSdkService, DEFAULT_APPROVAL_TIMEOUT_MS, DEFAULT_MAX_APPROVAL_RETRIES, } from "../constants";
|
|
16
16
|
import { SDK_VERSION } from "../sdk-version";
|
|
17
17
|
import { openApproval } from "../utils/open-approval";
|
|
@@ -331,11 +331,12 @@ class ZapierApiClient {
|
|
|
331
331
|
baseUrl: this.options.baseUrl,
|
|
332
332
|
requiredScopes: options?.requiredScopes,
|
|
333
333
|
debug: this.options.debug,
|
|
334
|
+
cache: this.options.cache,
|
|
334
335
|
});
|
|
335
336
|
}
|
|
336
337
|
// Helper to handle responses
|
|
337
338
|
async handleResponse(params) {
|
|
338
|
-
const { response, customErrorHandler, wasMissingAuthToken, requiredScopes, } = params;
|
|
339
|
+
const { response, customErrorHandler, resource, wasMissingAuthToken, requiredScopes, } = params;
|
|
339
340
|
const { data: responseData } = await this.parseResult(response);
|
|
340
341
|
if (response.ok) {
|
|
341
342
|
return responseData;
|
|
@@ -345,7 +346,9 @@ class ZapierApiClient {
|
|
|
345
346
|
statusText: response.statusText,
|
|
346
347
|
data: responseData,
|
|
347
348
|
};
|
|
348
|
-
//
|
|
349
|
+
// Precedence: customErrorHandler runs first; if it returns an Error,
|
|
350
|
+
// throw it. If it returns undefined (or wasn't provided), fall through
|
|
351
|
+
// to the resource-enriched / bare defaults below.
|
|
349
352
|
if (customErrorHandler) {
|
|
350
353
|
const customError = customErrorHandler(errorInfo);
|
|
351
354
|
if (customError) {
|
|
@@ -364,21 +367,35 @@ class ZapierApiClient {
|
|
|
364
367
|
statusCode: response.status,
|
|
365
368
|
errors,
|
|
366
369
|
};
|
|
367
|
-
//
|
|
370
|
+
// 404: always throw ZapierResourceNotFoundError (subclass of
|
|
371
|
+
// ZapierNotFoundError, so existing instanceof checks still pass).
|
|
372
|
+
// resourceType/resourceId are populated when the caller passed a
|
|
373
|
+
// `resource` hint, otherwise left undefined. The message is the
|
|
374
|
+
// server's detail verbatim; formatErrorMessage surfaces the resource
|
|
375
|
+
// hint separately (Type: ..., ID: ...) so we don't duplicate it here.
|
|
368
376
|
if (response.status === 404) {
|
|
369
|
-
throw new
|
|
377
|
+
throw new ZapierResourceNotFoundError(message, {
|
|
378
|
+
...errorOptions,
|
|
379
|
+
resourceType: resource?.type,
|
|
380
|
+
resourceId: resource?.id !== undefined ? String(resource.id) : undefined,
|
|
381
|
+
});
|
|
370
382
|
}
|
|
371
383
|
if (response.status === 401 || response.status === 403) {
|
|
372
384
|
// If we get a 401/403 error and no auth token was provided, give helpful message
|
|
373
385
|
if (wasMissingAuthToken) {
|
|
374
386
|
throw new ZapierAuthenticationError(`Authentication required (HTTP ${response.status}). Please provide credentials in options or set ZAPIER_CREDENTIALS environment variable.`, errorOptions);
|
|
375
387
|
}
|
|
376
|
-
// On 401, invalidate cached token so next request
|
|
388
|
+
// On 401, invalidate the cached token so the next request fires
|
|
389
|
+
// a fresh exchange. Passing baseUrl + cache explicitly so the
|
|
390
|
+
// invalidation targets the same cache key the token was stored
|
|
391
|
+
// under (both are part of the key identity).
|
|
377
392
|
if (response.status === 401) {
|
|
378
393
|
await invalidateCredentialsToken({
|
|
379
394
|
credentials: this.options.credentials,
|
|
380
395
|
token: this.options.token,
|
|
396
|
+
baseUrl: this.options.baseUrl,
|
|
381
397
|
requiredScopes,
|
|
398
|
+
cache: this.options.cache,
|
|
382
399
|
});
|
|
383
400
|
}
|
|
384
401
|
throw new ZapierAuthenticationError(message, errorOptions);
|
|
@@ -400,7 +417,6 @@ class ZapierApiClient {
|
|
|
400
417
|
const data = dataArray[0];
|
|
401
418
|
return (typeof data === "object" &&
|
|
402
419
|
data !== null &&
|
|
403
|
-
"message" in data &&
|
|
404
420
|
"code" in data &&
|
|
405
421
|
"title" in data &&
|
|
406
422
|
"detail" in data);
|
|
@@ -611,6 +627,7 @@ class ZapierApiClient {
|
|
|
611
627
|
const result = await this.handleResponse({
|
|
612
628
|
response,
|
|
613
629
|
customErrorHandler: options.customErrorHandler,
|
|
630
|
+
resource: options.resource,
|
|
614
631
|
wasMissingAuthToken,
|
|
615
632
|
requiredScopes: options.requiredScopes,
|
|
616
633
|
});
|
package/dist/api/schemas.d.ts
CHANGED
|
@@ -43,8 +43,8 @@ export declare const NeedSchema: z.ZodObject<{
|
|
|
43
43
|
string: "string";
|
|
44
44
|
boolean: "boolean";
|
|
45
45
|
file: "file";
|
|
46
|
-
integer: "integer";
|
|
47
46
|
filter: "filter";
|
|
47
|
+
integer: "integer";
|
|
48
48
|
text: "text";
|
|
49
49
|
datetime: "datetime";
|
|
50
50
|
decimal: "decimal";
|
|
@@ -65,11 +65,11 @@ export declare const ActionPermissionsSchema: z.ZodObject<{
|
|
|
65
65
|
export declare const ActionSchema: z.ZodObject<{
|
|
66
66
|
id: z.ZodOptional<z.ZodString>;
|
|
67
67
|
type: z.ZodEnum<{
|
|
68
|
-
search: "search";
|
|
69
68
|
filter: "filter";
|
|
70
69
|
read: "read";
|
|
71
70
|
read_bulk: "read_bulk";
|
|
72
71
|
run: "run";
|
|
72
|
+
search: "search";
|
|
73
73
|
search_and_write: "search_and_write";
|
|
74
74
|
search_or_write: "search_or_write";
|
|
75
75
|
write: "write";
|
|
@@ -288,8 +288,8 @@ export declare const NeedsResponseSchema: z.ZodObject<{
|
|
|
288
288
|
string: "string";
|
|
289
289
|
boolean: "boolean";
|
|
290
290
|
file: "file";
|
|
291
|
-
integer: "integer";
|
|
292
291
|
filter: "filter";
|
|
292
|
+
integer: "integer";
|
|
293
293
|
text: "text";
|
|
294
294
|
datetime: "datetime";
|
|
295
295
|
decimal: "decimal";
|
|
@@ -313,11 +313,11 @@ export declare const ImplementationSchema: z.ZodObject<{
|
|
|
313
313
|
actions: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
314
314
|
id: z.ZodOptional<z.ZodString>;
|
|
315
315
|
type: z.ZodEnum<{
|
|
316
|
-
search: "search";
|
|
317
316
|
filter: "filter";
|
|
318
317
|
read: "read";
|
|
319
318
|
read_bulk: "read_bulk";
|
|
320
319
|
run: "run";
|
|
320
|
+
search: "search";
|
|
321
321
|
search_and_write: "search_and_write";
|
|
322
322
|
search_or_write: "search_or_write";
|
|
323
323
|
write: "write";
|
|
@@ -355,11 +355,11 @@ export declare const ImplementationsResponseSchema: z.ZodObject<{
|
|
|
355
355
|
actions: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
356
356
|
id: z.ZodOptional<z.ZodString>;
|
|
357
357
|
type: z.ZodEnum<{
|
|
358
|
-
search: "search";
|
|
359
358
|
filter: "filter";
|
|
360
359
|
read: "read";
|
|
361
360
|
read_bulk: "read_bulk";
|
|
362
361
|
run: "run";
|
|
362
|
+
search: "search";
|
|
363
363
|
search_and_write: "search_and_write";
|
|
364
364
|
search_or_write: "search_or_write";
|
|
365
365
|
write: "write";
|
package/dist/api/types.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ import type { ImplementationMetaSchema, ImplementationsMetaResponseSchema } from
|
|
|
13
13
|
import type { SdkEvent } from "../types/events";
|
|
14
14
|
import type { Credentials } from "../types/credentials";
|
|
15
15
|
import type { RequestContext } from "@zapier/policy-context";
|
|
16
|
+
import type { ZapierCache } from "../cache";
|
|
16
17
|
import type { z } from "zod";
|
|
17
18
|
import type { NeedChoicesSchema, NeedSchema, ActionLinksSchema, ActionPermissionsSchema, ActionSchema, ChoiceSchema, FieldSchema, ActionExecutionResultSchema, ActionFieldChoiceSchema, ActionFieldSchema, UserProfileSchema, AppSchema, NeedsRequestSchema, NeedsResponseSchema, ImplementationSchema, ImplementationsResponseSchema, ServiceSchema, ServicesResponseSchema, NeedChoicesRequestSchema, NeedChoicesResponseSchema, NeedChoicesResponseMetaSchema, NeedChoicesResponseLinksSchema } from "./schemas";
|
|
18
19
|
export interface ApiClientOptions {
|
|
@@ -71,6 +72,11 @@ export interface ApiClientOptions {
|
|
|
71
72
|
name: string;
|
|
72
73
|
version: string;
|
|
73
74
|
};
|
|
75
|
+
/**
|
|
76
|
+
* Pluggable key-value cache used to cache access tokens across
|
|
77
|
+
* invocations. See ZapierCache in ../cache.ts.
|
|
78
|
+
*/
|
|
79
|
+
cache?: ZapierCache;
|
|
74
80
|
}
|
|
75
81
|
export interface ApiClient {
|
|
76
82
|
get: <T = unknown>(path: string, options?: RequestOptions) => Promise<T>;
|
|
@@ -100,6 +106,17 @@ export interface RequestOptions {
|
|
|
100
106
|
statusText: string;
|
|
101
107
|
data: unknown;
|
|
102
108
|
}) => Error | undefined;
|
|
109
|
+
/**
|
|
110
|
+
* Optional metadata about what this request is fetching/affecting. When
|
|
111
|
+
* set, 404 responses throw `ZapierResourceNotFoundError` with
|
|
112
|
+
* `resourceType` / `resourceId` populated. The `type` is free-form;
|
|
113
|
+
* conventionally it matches how the resource appears in API URL segments
|
|
114
|
+
* (`"table"`, `"record"`, `"connection"`, etc.).
|
|
115
|
+
*/
|
|
116
|
+
resource?: {
|
|
117
|
+
type: string;
|
|
118
|
+
id?: string | number;
|
|
119
|
+
};
|
|
103
120
|
/**
|
|
104
121
|
* Builds the policy context for this request if it triggers the approval
|
|
105
122
|
* flow. Callers that may receive a 403 `approval_required` response MUST
|
package/dist/api/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
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AmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAC5E,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAC3C,OAAO,6BAA6B,CACrC,CAAC;AACF,MAAM,MAAM,wBAAwB,GAAG,CAAC,CAAC,KAAK,CAC5C,OAAO,8BAA8B,CACtC,CAAC"}
|
package/dist/auth.d.ts
CHANGED
|
@@ -6,10 +6,13 @@
|
|
|
6
6
|
* and handles different credential types appropriately.
|
|
7
7
|
*
|
|
8
8
|
* CLI-specific functionality like login/logout is handled by the
|
|
9
|
-
* @zapier/zapier-sdk-cli
|
|
9
|
+
* @zapier/zapier-sdk-cli package (imported via its `./login` subpath).
|
|
10
10
|
*/
|
|
11
11
|
import type { EventCallback } from "./types/events";
|
|
12
12
|
import type { Credentials } from "./types/credentials";
|
|
13
|
+
import { type ZapierCache } from "./cache";
|
|
14
|
+
export type { ZapierCache, ZapierCacheEntry, ZapierCacheSetOptions, } from "./cache";
|
|
15
|
+
export { createMemoryCache } from "./cache";
|
|
13
16
|
export type { SdkEvent, AuthEvent, ApiEvent, LoadingEvent, EventCallback, } from "./types/events";
|
|
14
17
|
export type { Credentials, ResolvedCredentials, CredentialsObject, ClientCredentialsObject, PkceCredentialsObject, } from "./types/credentials";
|
|
15
18
|
export { isClientCredentials, isPkceCredentials, isCredentialsObject, isCredentialsFunction, } from "./types/credentials";
|
|
@@ -31,16 +34,32 @@ export interface ResolveAuthTokenOptions {
|
|
|
31
34
|
requiredScopes?: string[];
|
|
32
35
|
/** Enable debug logging for auth operations. */
|
|
33
36
|
debug?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Pluggable key-value cache used to cache access tokens across
|
|
39
|
+
* process boundaries. When omitted, the SDK tries to load a default
|
|
40
|
+
* adapter from the cli-login package (file system + keychain) and
|
|
41
|
+
* falls back to in-memory cache if none is available.
|
|
42
|
+
*/
|
|
43
|
+
cache?: ZapierCache;
|
|
34
44
|
}
|
|
35
45
|
/**
|
|
36
|
-
* Clear
|
|
46
|
+
* Clear in-process caches. Useful for testing or to force the next
|
|
47
|
+
* resolve to re-import the default cache adapter. Does not touch
|
|
48
|
+
* persistent cache — use `invalidateCachedToken` for that.
|
|
37
49
|
*/
|
|
38
50
|
export declare function clearTokenCache(): void;
|
|
39
51
|
/**
|
|
40
|
-
* Invalidate
|
|
41
|
-
* Called
|
|
52
|
+
* Invalidate the cached token for a given client_credentials identity.
|
|
53
|
+
* Called on 401 so the next request re-exchanges. Clears both the
|
|
54
|
+
* in-process pending-exchange map and the persistent layer via the
|
|
55
|
+
* resolved cache adapter.
|
|
42
56
|
*/
|
|
43
|
-
export declare function invalidateCachedToken(
|
|
57
|
+
export declare function invalidateCachedToken(options: {
|
|
58
|
+
clientId: string;
|
|
59
|
+
scopes: string[];
|
|
60
|
+
baseUrl: string;
|
|
61
|
+
cache?: ZapierCache;
|
|
62
|
+
}): Promise<void>;
|
|
44
63
|
/**
|
|
45
64
|
* Options for getTokenFromCliLogin.
|
|
46
65
|
*/
|
|
@@ -55,7 +74,7 @@ interface CliLoginOptions {
|
|
|
55
74
|
};
|
|
56
75
|
debug?: boolean;
|
|
57
76
|
}
|
|
58
|
-
type CliLoginModule = typeof import("@zapier/zapier-sdk-cli
|
|
77
|
+
type CliLoginModule = typeof import("@zapier/zapier-sdk-cli/login");
|
|
59
78
|
/**
|
|
60
79
|
* Inject an already-loaded CLI login module so the SDK skips its dynamic import.
|
|
61
80
|
* This guarantees CLI and SDK share the same module instance in the same process.
|
|
@@ -97,6 +116,8 @@ export declare function resolveAuthToken(options?: ResolveAuthTokenOptions): Pro
|
|
|
97
116
|
export declare function invalidateCredentialsToken(options: {
|
|
98
117
|
credentials?: Credentials;
|
|
99
118
|
token?: string;
|
|
119
|
+
baseUrl?: string;
|
|
100
120
|
requiredScopes?: string[];
|
|
121
|
+
cache?: ZapierCache;
|
|
101
122
|
}): Promise<void>;
|
|
102
123
|
//# sourceMappingURL=auth.d.ts.map
|
package/dist/auth.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,KAAK,EAAE,WAAW,EAAuB,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,KAAK,EAAE,WAAW,EAAuB,MAAM,qBAAqB,CAAC;AAG5E,OAAO,EAAqB,KAAK,WAAW,EAAE,MAAM,SAAS,CAAC;AAG9D,YAAY,EACV,WAAW,EACX,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAG5C,YAAY,EACV,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,YAAY,EACZ,aAAa,GACd,MAAM,gBAAgB,CAAC;AAGxB,YAAY,EACV,WAAW,EACX,mBAAmB,EACnB,iBAAiB,EACjB,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,qBAAqB,CAAC;AAE7B;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,4CAA4C;IAC5C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,aAAa,CAAC;IACxB,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,cAAc,CAAC,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C,OAAO,EAAE;IACxD,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,KAAK,CAAC,EAAE,WAAW,CAAC;CACrB,GAAG,OAAO,CAAC,IAAI,CAAC,CAehB"}
|
package/dist/auth.js
CHANGED
|
@@ -6,80 +6,100 @@
|
|
|
6
6
|
* and handles different credential types appropriately.
|
|
7
7
|
*
|
|
8
8
|
* CLI-specific functionality like login/logout is handled by the
|
|
9
|
-
* @zapier/zapier-sdk-cli
|
|
9
|
+
* @zapier/zapier-sdk-cli package (imported via its `./login` subpath).
|
|
10
10
|
*/
|
|
11
11
|
import { isClientCredentials, isPkceCredentials } from "./types/credentials";
|
|
12
12
|
import { resolveCredentials, getClientIdFromCredentials } from "./credentials";
|
|
13
|
-
import {
|
|
13
|
+
import { createMemoryCache } from "./cache";
|
|
14
|
+
const DEFAULT_AUTH_BASE_URL = "https://zapier.com";
|
|
15
|
+
export { createMemoryCache } from "./cache";
|
|
14
16
|
export { isClientCredentials, isPkceCredentials, isCredentialsObject, isCredentialsFunction, } from "./types/credentials";
|
|
15
17
|
/**
|
|
16
|
-
* In-
|
|
17
|
-
*
|
|
18
|
+
* In-flight token exchange promises to prevent duplicate exchanges
|
|
19
|
+
* inside the same process. When an exchange is in progress, subsequent
|
|
20
|
+
* calls await the same promise. Cache backends are responsible for
|
|
21
|
+
* cross-process dedup via their optional `withLock` method.
|
|
18
22
|
*/
|
|
19
|
-
const
|
|
23
|
+
const pendingExchanges = new Map();
|
|
20
24
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* Keyed by clientId + sorted scopes.
|
|
25
|
+
* The resolved default cache adapter. Cached at module scope so
|
|
26
|
+
* repeated calls to `resolveAuthToken` reuse the same provider.
|
|
24
27
|
*/
|
|
25
|
-
|
|
28
|
+
let cachedDefaultCache;
|
|
26
29
|
/**
|
|
27
|
-
* Build
|
|
30
|
+
* Build the cache key for a client_credentials identity. baseUrl is
|
|
31
|
+
* part of the key so the same clientId+scopes against different auth
|
|
32
|
+
* hosts (prod vs staging) never alias.
|
|
28
33
|
*/
|
|
29
|
-
function buildCacheKey(
|
|
30
|
-
const sortedScopes = [...scopes].sort().join(",");
|
|
31
|
-
return
|
|
34
|
+
function buildCacheKey(options) {
|
|
35
|
+
const sortedScopes = [...options.scopes].sort().join(",");
|
|
36
|
+
return `zapier-sdk/client-credentials/${options.clientId}:${sortedScopes}:${options.baseUrl}`;
|
|
32
37
|
}
|
|
33
38
|
/**
|
|
34
|
-
* Clear
|
|
39
|
+
* Clear in-process caches. Useful for testing or to force the next
|
|
40
|
+
* resolve to re-import the default cache adapter. Does not touch
|
|
41
|
+
* persistent cache — use `invalidateCachedToken` for that.
|
|
35
42
|
*/
|
|
36
43
|
export function clearTokenCache() {
|
|
37
|
-
tokenCache.clear();
|
|
38
44
|
pendingExchanges.clear();
|
|
39
45
|
cachedCliLogin = undefined;
|
|
46
|
+
cachedDefaultCache = undefined;
|
|
40
47
|
}
|
|
41
|
-
const
|
|
48
|
+
const TOKEN_EXPIRATION_BUFFER_MS = 5 * 60 * 1000;
|
|
42
49
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
50
|
+
* Decide which cache adapter to use for this call. Priority:
|
|
51
|
+
* 1. explicit `options.cache`
|
|
52
|
+
* 2. CLI's default cache provider (if installed)
|
|
53
|
+
* 3. in-memory fallback
|
|
45
54
|
*/
|
|
46
|
-
function
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (
|
|
50
|
-
return
|
|
51
|
-
|
|
52
|
-
if (
|
|
53
|
-
|
|
55
|
+
async function resolveCache(options) {
|
|
56
|
+
if (options.cache)
|
|
57
|
+
return options.cache;
|
|
58
|
+
if (cachedDefaultCache !== undefined)
|
|
59
|
+
return cachedDefaultCache;
|
|
60
|
+
const cliLogin = await getCliLogin();
|
|
61
|
+
if (cliLogin?.createCache) {
|
|
62
|
+
try {
|
|
63
|
+
const cache = cliLogin.createCache();
|
|
64
|
+
cachedDefaultCache = cache;
|
|
65
|
+
return cache;
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
// Fall through to in-memory if the CLI provider can't be constructed.
|
|
69
|
+
}
|
|
54
70
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return
|
|
71
|
+
const fallback = createMemoryCache();
|
|
72
|
+
cachedDefaultCache = fallback;
|
|
73
|
+
return fallback;
|
|
58
74
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const cacheKey = buildCacheKey(clientId, scopes);
|
|
64
|
-
tokenCache.set(cacheKey, {
|
|
65
|
-
accessToken,
|
|
66
|
-
expiresAt: Date.now() + expiresIn * 1000,
|
|
67
|
-
});
|
|
75
|
+
function entryIsValid(entry) {
|
|
76
|
+
if (entry.expiresAt === undefined)
|
|
77
|
+
return true;
|
|
78
|
+
return entry.expiresAt > Date.now() + TOKEN_EXPIRATION_BUFFER_MS;
|
|
68
79
|
}
|
|
69
80
|
/**
|
|
70
|
-
* Invalidate
|
|
71
|
-
* Called
|
|
81
|
+
* Invalidate the cached token for a given client_credentials identity.
|
|
82
|
+
* Called on 401 so the next request re-exchanges. Clears both the
|
|
83
|
+
* in-process pending-exchange map and the persistent layer via the
|
|
84
|
+
* resolved cache adapter.
|
|
72
85
|
*/
|
|
73
|
-
export function invalidateCachedToken(
|
|
74
|
-
const cacheKey = buildCacheKey(
|
|
75
|
-
tokenCache.delete(cacheKey);
|
|
86
|
+
export async function invalidateCachedToken(options) {
|
|
87
|
+
const cacheKey = buildCacheKey(options);
|
|
76
88
|
pendingExchanges.delete(cacheKey);
|
|
89
|
+
const cache = await resolveCache({ cache: options.cache });
|
|
90
|
+
try {
|
|
91
|
+
await cache.delete(cacheKey);
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
// Best-effort: the caller is about to surface a 401 to its own
|
|
95
|
+
// caller; a failed invalidation shouldn't add noise on top of that.
|
|
96
|
+
}
|
|
77
97
|
}
|
|
78
98
|
/**
|
|
79
99
|
* Get the token endpoint URL for client credentials exchange.
|
|
80
100
|
*/
|
|
81
101
|
function getTokenEndpointUrl(baseUrl) {
|
|
82
|
-
const base = baseUrl ||
|
|
102
|
+
const base = baseUrl || DEFAULT_AUTH_BASE_URL;
|
|
83
103
|
return `${base}/oauth/token/`;
|
|
84
104
|
}
|
|
85
105
|
/**
|
|
@@ -109,9 +129,6 @@ function mergeScopes(credentialsScope, requiredScopes) {
|
|
|
109
129
|
}
|
|
110
130
|
return [...scopeSet].sort();
|
|
111
131
|
}
|
|
112
|
-
/**
|
|
113
|
-
* Exchange client credentials for an access token.
|
|
114
|
-
*/
|
|
115
132
|
async function exchangeClientCredentials(options) {
|
|
116
133
|
const { clientId, clientSecret, baseUrl, scope, requiredScopes, onEvent } = options;
|
|
117
134
|
const fetchFn = options.fetch || globalThis.fetch;
|
|
@@ -157,9 +174,6 @@ async function exchangeClientCredentials(options) {
|
|
|
157
174
|
if (!data.access_token) {
|
|
158
175
|
throw new Error("Client credentials response missing access_token");
|
|
159
176
|
}
|
|
160
|
-
// Cache the token with the scopes used
|
|
161
|
-
const expiresIn = data.expires_in || 3600; // Default to 1 hour
|
|
162
|
-
cacheToken(clientId, mergedScopes, data.access_token, expiresIn);
|
|
163
177
|
onEvent?.({
|
|
164
178
|
type: "auth_success",
|
|
165
179
|
payload: {
|
|
@@ -168,18 +182,17 @@ async function exchangeClientCredentials(options) {
|
|
|
168
182
|
},
|
|
169
183
|
timestamp: Date.now(),
|
|
170
184
|
});
|
|
171
|
-
return
|
|
185
|
+
return {
|
|
186
|
+
accessToken: data.access_token,
|
|
187
|
+
expiresIn: data.expires_in || 3600,
|
|
188
|
+
};
|
|
172
189
|
}
|
|
173
190
|
let cachedCliLogin;
|
|
174
191
|
/**
|
|
175
|
-
* Dynamically imports
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
* users who install the lightweight login package directly).
|
|
180
|
-
*
|
|
181
|
-
* Returns the module if found, or `undefined` if neither package is available.
|
|
182
|
-
* The result is cached after the first attempt.
|
|
192
|
+
* Dynamically imports the CLI's login/cache entrypoint with caching.
|
|
193
|
+
* Returns the module if the CLI package is installed in the consumer's
|
|
194
|
+
* environment, or `undefined` if not (e.g. in a browser or minimal
|
|
195
|
+
* server deployment). The result is cached after the first attempt.
|
|
183
196
|
*/
|
|
184
197
|
async function getCliLogin() {
|
|
185
198
|
if (cachedCliLogin !== undefined) {
|
|
@@ -193,17 +206,7 @@ async function getCliLogin() {
|
|
|
193
206
|
}
|
|
194
207
|
}
|
|
195
208
|
catch {
|
|
196
|
-
// Not available
|
|
197
|
-
}
|
|
198
|
-
try {
|
|
199
|
-
const mod = await import("@zapier/zapier-sdk-cli-login");
|
|
200
|
-
if (typeof mod.getToken === "function") {
|
|
201
|
-
cachedCliLogin = mod;
|
|
202
|
-
return cachedCliLogin;
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
catch {
|
|
206
|
-
// Not available
|
|
209
|
+
// Not available (no CLI installed in this environment).
|
|
207
210
|
}
|
|
208
211
|
cachedCliLogin = false;
|
|
209
212
|
return undefined;
|
|
@@ -277,33 +280,62 @@ async function resolveAuthTokenFromCredentials(credentials, options) {
|
|
|
277
280
|
if (typeof credentials === "string") {
|
|
278
281
|
return credentials;
|
|
279
282
|
}
|
|
280
|
-
// Client credentials: exchange
|
|
283
|
+
// Client credentials: exchange + cache through a pluggable cache
|
|
284
|
+
// adapter. Resolution order:
|
|
285
|
+
// 1. in-process pending exchange (dedup concurrent same-process calls)
|
|
286
|
+
// 2. cache.get (hits keychain + config under the filesystem adapter,
|
|
287
|
+
// RAM under the in-memory adapter, whatever the user adapter does)
|
|
288
|
+
// 3. cache.withLock (if available) -> re-read, exchange, persist
|
|
289
|
+
// (so N parallel processes collapse to 1 network exchange)
|
|
290
|
+
// 4. plain exchange + persist when no lock is available
|
|
281
291
|
if (isClientCredentials(credentials)) {
|
|
282
292
|
const { clientId } = credentials;
|
|
283
|
-
// Compute merged scopes for cache lookup
|
|
284
293
|
const mergedScopes = mergeScopes(credentials.scope, options.requiredScopes);
|
|
285
|
-
const
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
294
|
+
const resolvedBaseUrl = credentials.baseUrl || options.baseUrl || DEFAULT_AUTH_BASE_URL;
|
|
295
|
+
const cacheKey = buildCacheKey({
|
|
296
|
+
clientId,
|
|
297
|
+
scopes: mergedScopes,
|
|
298
|
+
baseUrl: resolvedBaseUrl,
|
|
299
|
+
});
|
|
300
|
+
const cache = await resolveCache(options);
|
|
301
|
+
// Fast-path read
|
|
302
|
+
const cached = await cache.get(cacheKey);
|
|
303
|
+
if (cached && entryIsValid(cached)) {
|
|
304
|
+
return cached.value;
|
|
290
305
|
}
|
|
291
|
-
//
|
|
306
|
+
// In-process dedup
|
|
292
307
|
const pending = pendingExchanges.get(cacheKey);
|
|
293
|
-
if (pending)
|
|
308
|
+
if (pending)
|
|
294
309
|
return pending;
|
|
295
|
-
|
|
296
|
-
//
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
310
|
+
// Serialize exchange + persist inside the lock (when the adapter
|
|
311
|
+
// supports cross-process locking). The second acquirer re-reads the
|
|
312
|
+
// cache under the lock and uses the first's token instead of firing
|
|
313
|
+
// another exchange.
|
|
314
|
+
const runLocked = async () => {
|
|
315
|
+
const recheck = await cache.get(cacheKey);
|
|
316
|
+
if (recheck && entryIsValid(recheck))
|
|
317
|
+
return recheck.value;
|
|
318
|
+
const { accessToken, expiresIn } = await exchangeClientCredentials({
|
|
319
|
+
clientId: credentials.clientId,
|
|
320
|
+
clientSecret: credentials.clientSecret,
|
|
321
|
+
baseUrl: credentials.baseUrl || options.baseUrl,
|
|
322
|
+
scope: credentials.scope,
|
|
323
|
+
requiredScopes: options.requiredScopes,
|
|
324
|
+
fetch: options.fetch,
|
|
325
|
+
onEvent: options.onEvent,
|
|
326
|
+
});
|
|
327
|
+
try {
|
|
328
|
+
await cache.set(cacheKey, accessToken, {
|
|
329
|
+
secret: true,
|
|
330
|
+
ttl: expiresIn,
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
catch {
|
|
334
|
+
// Best-effort persistence: next process will re-exchange.
|
|
335
|
+
}
|
|
336
|
+
return accessToken;
|
|
337
|
+
};
|
|
338
|
+
const exchangePromise = (cache.withLock ? cache.withLock(cacheKey, runLocked) : runLocked()).finally(() => {
|
|
307
339
|
pendingExchanges.delete(cacheKey);
|
|
308
340
|
});
|
|
309
341
|
pendingExchanges.set(cacheKey, exchangePromise);
|
|
@@ -340,6 +372,12 @@ export async function invalidateCredentialsToken(options) {
|
|
|
340
372
|
const clientId = getClientIdFromCredentials(resolved);
|
|
341
373
|
if (clientId && isClientCredentials(resolved)) {
|
|
342
374
|
const scopes = mergeScopes(resolved.scope, options.requiredScopes);
|
|
343
|
-
|
|
375
|
+
const baseUrl = resolved.baseUrl || options.baseUrl || DEFAULT_AUTH_BASE_URL;
|
|
376
|
+
await invalidateCachedToken({
|
|
377
|
+
clientId,
|
|
378
|
+
scopes,
|
|
379
|
+
baseUrl,
|
|
380
|
+
cache: options.cache,
|
|
381
|
+
});
|
|
344
382
|
}
|
|
345
383
|
}
|