@zapier/zapier-sdk 0.4.1 → 0.5.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 +7 -0
- package/dist/api/auth.d.ts +9 -0
- package/dist/api/auth.d.ts.map +1 -0
- package/dist/api/auth.js +25 -0
- package/dist/api/client.d.ts +9 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/client.js +322 -0
- package/dist/api/debug.d.ts +13 -0
- package/dist/api/debug.d.ts.map +1 -0
- package/dist/api/debug.js +55 -0
- package/dist/api/index.d.ts +29 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +41 -0
- package/dist/api/polling.d.ts +16 -0
- package/dist/api/polling.d.ts.map +1 -0
- package/dist/api/polling.js +45 -0
- package/dist/api/schemas.d.ts +2473 -0
- package/dist/api/schemas.d.ts.map +1 -0
- package/dist/api/schemas.js +355 -0
- package/dist/api/types.d.ts +75 -0
- package/dist/api/types.d.ts.map +1 -0
- package/dist/api/types.js +11 -0
- package/dist/auth.d.ts +34 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +47 -0
- package/dist/constants.d.ts +10 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +9 -0
- package/dist/index.cjs +2108 -1379
- package/dist/index.d.mts +2440 -620
- package/dist/index.d.ts +17 -892
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.mjs +2093 -1362
- package/dist/plugins/api/index.d.ts +14 -0
- package/dist/plugins/api/index.d.ts.map +1 -0
- package/dist/plugins/api/index.js +21 -0
- package/dist/plugins/apps/index.d.ts +11 -0
- package/dist/plugins/apps/index.d.ts.map +1 -0
- package/dist/plugins/apps/index.js +91 -0
- package/dist/plugins/apps/types.d.ts +30 -0
- package/dist/plugins/apps/types.d.ts.map +1 -0
- package/dist/plugins/apps/types.js +2 -0
- package/dist/plugins/fetch/index.d.ts +21 -0
- package/dist/plugins/fetch/index.d.ts.map +1 -0
- package/dist/plugins/fetch/index.js +20 -0
- package/dist/plugins/findFirstAuthentication/index.d.ts +20 -0
- package/dist/plugins/findFirstAuthentication/index.d.ts.map +1 -0
- package/dist/plugins/findFirstAuthentication/index.js +24 -0
- package/dist/plugins/findFirstAuthentication/index.test.d.ts +2 -0
- package/dist/plugins/findFirstAuthentication/index.test.d.ts.map +1 -0
- package/dist/plugins/findFirstAuthentication/index.test.js +171 -0
- package/dist/plugins/findFirstAuthentication/schemas.d.ts +29 -0
- package/dist/plugins/findFirstAuthentication/schemas.d.ts.map +1 -0
- package/dist/plugins/findFirstAuthentication/schemas.js +18 -0
- package/dist/plugins/findUniqueAuthentication/index.d.ts +20 -0
- package/dist/plugins/findUniqueAuthentication/index.d.ts.map +1 -0
- package/dist/plugins/findUniqueAuthentication/index.js +31 -0
- package/dist/plugins/findUniqueAuthentication/index.test.d.ts +2 -0
- package/dist/plugins/findUniqueAuthentication/index.test.d.ts.map +1 -0
- package/dist/plugins/findUniqueAuthentication/index.test.js +152 -0
- package/dist/plugins/findUniqueAuthentication/schemas.d.ts +29 -0
- package/dist/plugins/findUniqueAuthentication/schemas.d.ts.map +1 -0
- package/dist/plugins/findUniqueAuthentication/schemas.js +18 -0
- package/dist/plugins/getAction/index.d.ts +23 -0
- package/dist/plugins/getAction/index.d.ts.map +1 -0
- package/dist/plugins/getAction/index.js +28 -0
- package/dist/plugins/getAction/index.test.d.ts +2 -0
- package/dist/plugins/getAction/index.test.d.ts.map +1 -0
- package/dist/plugins/getAction/index.test.js +186 -0
- package/dist/plugins/getAction/schemas.d.ts +23 -0
- package/dist/plugins/getAction/schemas.d.ts.map +1 -0
- package/dist/plugins/getAction/schemas.js +10 -0
- package/dist/plugins/getApp/index.d.ts +22 -0
- package/dist/plugins/getApp/index.d.ts.map +1 -0
- package/dist/plugins/getApp/index.js +39 -0
- package/dist/plugins/getApp/index.test.d.ts +2 -0
- package/dist/plugins/getApp/index.test.d.ts.map +1 -0
- package/dist/plugins/getApp/index.test.js +100 -0
- package/dist/plugins/getApp/schemas.d.ts +18 -0
- package/dist/plugins/getApp/schemas.d.ts.map +1 -0
- package/dist/plugins/getApp/schemas.js +10 -0
- package/dist/plugins/getAuthentication/index.d.ts +22 -0
- package/dist/plugins/getAuthentication/index.d.ts.map +1 -0
- package/dist/plugins/getAuthentication/index.js +41 -0
- package/dist/plugins/getAuthentication/index.test.d.ts +2 -0
- package/dist/plugins/getAuthentication/index.test.d.ts.map +1 -0
- package/dist/plugins/getAuthentication/index.test.js +205 -0
- package/dist/plugins/getAuthentication/schemas.d.ts +17 -0
- package/dist/plugins/getAuthentication/schemas.d.ts.map +1 -0
- package/dist/plugins/getAuthentication/schemas.js +11 -0
- package/dist/plugins/getProfile/index.d.ts +23 -0
- package/dist/plugins/getProfile/index.d.ts.map +1 -0
- package/dist/plugins/getProfile/index.js +29 -0
- package/dist/plugins/getProfile/schemas.d.ts +13 -0
- package/dist/plugins/getProfile/schemas.d.ts.map +1 -0
- package/dist/plugins/getProfile/schemas.js +5 -0
- package/dist/plugins/listActions/index.d.ts +28 -0
- package/dist/plugins/listActions/index.d.ts.map +1 -0
- package/dist/plugins/listActions/index.js +61 -0
- package/dist/plugins/listActions/index.test.d.ts +2 -0
- package/dist/plugins/listActions/index.test.d.ts.map +1 -0
- package/dist/plugins/listActions/index.test.js +467 -0
- package/dist/plugins/listActions/schemas.d.ts +29 -0
- package/dist/plugins/listActions/schemas.d.ts.map +1 -0
- package/dist/plugins/listActions/schemas.js +21 -0
- package/dist/plugins/listApps/index.d.ts +28 -0
- package/dist/plugins/listApps/index.d.ts.map +1 -0
- package/dist/plugins/listApps/index.js +62 -0
- package/dist/plugins/listApps/index.test.d.ts +2 -0
- package/dist/plugins/listApps/index.test.d.ts.map +1 -0
- package/dist/plugins/listApps/index.test.js +313 -0
- package/dist/plugins/listApps/schemas.d.ts +30 -0
- package/dist/plugins/listApps/schemas.d.ts.map +1 -0
- package/dist/plugins/listApps/schemas.js +23 -0
- package/dist/plugins/listAuthentications/index.d.ts +28 -0
- package/dist/plugins/listAuthentications/index.d.ts.map +1 -0
- package/dist/plugins/listAuthentications/index.js +77 -0
- package/dist/plugins/listAuthentications/index.test.d.ts +2 -0
- package/dist/plugins/listAuthentications/index.test.d.ts.map +1 -0
- package/dist/plugins/listAuthentications/index.test.js +564 -0
- package/dist/plugins/listAuthentications/schemas.d.ts +38 -0
- package/dist/plugins/listAuthentications/schemas.d.ts.map +1 -0
- package/dist/plugins/listAuthentications/schemas.js +28 -0
- package/dist/plugins/listInputFields/index.d.ts +28 -0
- package/dist/plugins/listInputFields/index.d.ts.map +1 -0
- package/dist/plugins/listInputFields/index.js +133 -0
- package/dist/plugins/listInputFields/index.test.d.ts +2 -0
- package/dist/plugins/listInputFields/index.test.d.ts.map +1 -0
- package/dist/plugins/listInputFields/index.test.js +325 -0
- package/dist/plugins/listInputFields/schemas.d.ts +38 -0
- package/dist/plugins/listInputFields/schemas.d.ts.map +1 -0
- package/dist/plugins/listInputFields/schemas.js +22 -0
- package/dist/plugins/registry/index.d.ts +11 -0
- package/dist/plugins/registry/index.d.ts.map +1 -0
- package/dist/plugins/registry/index.js +14 -0
- package/dist/plugins/request/index.d.ts +19 -0
- package/dist/plugins/request/index.d.ts.map +1 -0
- package/dist/plugins/request/index.js +62 -0
- package/dist/plugins/request/index.test.d.ts +2 -0
- package/dist/plugins/request/index.test.d.ts.map +1 -0
- package/dist/plugins/request/index.test.js +256 -0
- package/dist/plugins/request/schemas.d.ts +69 -0
- package/dist/plugins/request/schemas.d.ts.map +1 -0
- package/dist/plugins/request/schemas.js +42 -0
- package/dist/plugins/runAction/index.d.ts +28 -0
- package/dist/plugins/runAction/index.d.ts.map +1 -0
- package/dist/plugins/runAction/index.js +86 -0
- package/dist/plugins/runAction/index.test.d.ts +2 -0
- package/dist/plugins/runAction/index.test.d.ts.map +1 -0
- package/dist/plugins/runAction/index.test.js +320 -0
- package/dist/plugins/runAction/schemas.d.ts +37 -0
- package/dist/plugins/runAction/schemas.d.ts.map +1 -0
- package/dist/plugins/runAction/schemas.js +22 -0
- package/dist/resolvers/actionKey.d.ts +9 -0
- package/dist/resolvers/actionKey.d.ts.map +1 -0
- package/dist/resolvers/actionKey.js +19 -0
- package/dist/resolvers/actionType.d.ts +9 -0
- package/dist/resolvers/actionType.d.ts.map +1 -0
- package/dist/resolvers/actionType.js +22 -0
- package/dist/resolvers/appKey.d.ts +7 -0
- package/dist/resolvers/appKey.d.ts.map +1 -0
- package/dist/resolvers/appKey.js +5 -0
- package/dist/resolvers/authenticationId.d.ts +9 -0
- package/dist/resolvers/authenticationId.d.ts.map +1 -0
- package/dist/resolvers/authenticationId.js +33 -0
- package/dist/resolvers/index.d.ts +40 -0
- package/dist/resolvers/index.d.ts.map +1 -0
- package/dist/resolvers/index.js +91 -0
- package/dist/resolvers/inputs.d.ts +8 -0
- package/dist/resolvers/inputs.d.ts.map +1 -0
- package/dist/resolvers/inputs.js +14 -0
- package/dist/schemas/Action.d.ts +243 -0
- package/dist/schemas/Action.d.ts.map +1 -0
- package/dist/schemas/Action.js +34 -0
- package/dist/schemas/App.d.ts +26 -0
- package/dist/schemas/App.d.ts.map +1 -0
- package/dist/schemas/App.js +22 -0
- package/dist/schemas/Auth.d.ts +161 -0
- package/dist/schemas/Auth.d.ts.map +1 -0
- package/dist/schemas/Auth.js +41 -0
- package/dist/schemas/Field.d.ts +144 -0
- package/dist/schemas/Field.d.ts.map +1 -0
- package/dist/schemas/Field.js +105 -0
- package/dist/schemas/UserProfile.d.ts +163 -0
- package/dist/schemas/UserProfile.d.ts.map +1 -0
- package/dist/schemas/UserProfile.js +29 -0
- package/dist/sdk.d.ts +10 -0
- package/dist/sdk.d.ts.map +1 -0
- package/dist/sdk.js +94 -0
- package/dist/sdk.test.d.ts +2 -0
- package/dist/sdk.test.d.ts.map +1 -0
- package/dist/sdk.test.js +135 -0
- package/dist/types/domain.d.ts +36 -0
- package/dist/types/domain.d.ts.map +1 -0
- package/dist/types/domain.js +1 -0
- package/dist/types/domain.test.d.ts +2 -0
- package/dist/types/domain.test.d.ts.map +1 -0
- package/dist/types/domain.test.js +39 -0
- package/dist/types/errors.d.ts +143 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/errors.js +187 -0
- package/dist/types/events.d.ts +38 -0
- package/dist/types/events.d.ts.map +1 -0
- package/dist/types/events.js +7 -0
- package/dist/types/functions.d.ts +26 -0
- package/dist/types/functions.d.ts.map +1 -0
- package/dist/types/functions.js +4 -0
- package/dist/types/plugin.d.ts +61 -0
- package/dist/types/plugin.d.ts.map +1 -0
- package/dist/types/plugin.js +9 -0
- package/dist/types/properties.d.ts +22 -0
- package/dist/types/properties.d.ts.map +1 -0
- package/dist/types/properties.js +50 -0
- package/dist/types/sdk.d.ts +43 -0
- package/dist/types/sdk.d.ts.map +1 -0
- package/dist/types/sdk.js +4 -0
- package/dist/utils/array-utils.d.ts +31 -0
- package/dist/utils/array-utils.d.ts.map +1 -0
- package/dist/utils/array-utils.js +36 -0
- package/dist/utils/array-utils.test.d.ts +2 -0
- package/dist/utils/array-utils.test.d.ts.map +1 -0
- package/dist/utils/array-utils.test.js +107 -0
- package/dist/utils/domain-utils.d.ts +78 -0
- package/dist/utils/domain-utils.d.ts.map +1 -0
- package/dist/utils/domain-utils.js +218 -0
- package/dist/utils/domain-utils.test.d.ts +2 -0
- package/dist/utils/domain-utils.test.d.ts.map +1 -0
- package/dist/utils/domain-utils.test.js +192 -0
- package/dist/utils/function-utils.d.ts +45 -0
- package/dist/utils/function-utils.d.ts.map +1 -0
- package/dist/utils/function-utils.js +158 -0
- package/dist/utils/function-utils.test.d.ts +2 -0
- package/dist/utils/function-utils.test.d.ts.map +1 -0
- package/dist/utils/function-utils.test.js +110 -0
- package/dist/utils/pagination-utils.d.ts +37 -0
- package/dist/utils/pagination-utils.d.ts.map +1 -0
- package/dist/utils/pagination-utils.js +165 -0
- package/dist/utils/pagination-utils.test.d.ts +17 -0
- package/dist/utils/pagination-utils.test.d.ts.map +1 -0
- package/dist/utils/pagination-utils.test.js +461 -0
- package/dist/utils/schema-utils.d.ts +45 -0
- package/dist/utils/schema-utils.d.ts.map +1 -0
- package/dist/utils/schema-utils.js +65 -0
- package/dist/utils/validation.d.ts +4 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +30 -0
- package/dist/utils/validation.test.d.ts +2 -0
- package/dist/utils/validation.test.d.ts.map +1 -0
- package/dist/utils/validation.test.js +43 -0
- package/package.json +12 -3
- package/src/api/client.ts +394 -171
- package/src/api/debug.ts +10 -1
- package/src/api/index.ts +0 -2
- package/src/api/polling.ts +28 -7
- package/src/api/schemas.ts +387 -0
- package/src/api/types.ts +72 -136
- package/src/constants.ts +10 -0
- package/src/index.ts +40 -19
- package/src/plugins/api/index.ts +47 -0
- package/src/plugins/apps/index.ts +25 -19
- package/src/plugins/apps/types.ts +7 -11
- package/src/plugins/fetch/index.ts +48 -40
- package/src/plugins/findFirstAuthentication/index.test.ts +206 -0
- package/src/plugins/findFirstAuthentication/index.ts +55 -0
- package/src/plugins/findFirstAuthentication/schemas.ts +41 -0
- package/src/plugins/findUniqueAuthentication/index.test.ts +197 -0
- package/src/plugins/findUniqueAuthentication/index.ts +72 -0
- package/src/plugins/findUniqueAuthentication/schemas.ts +42 -0
- package/src/plugins/getAction/index.test.ts +239 -0
- package/src/plugins/getAction/index.ts +57 -0
- package/src/plugins/getAction/schemas.ts +33 -0
- package/src/plugins/getApp/index.test.ts +127 -0
- package/src/plugins/getApp/index.ts +66 -0
- package/src/plugins/getApp/schemas.ts +38 -0
- package/src/plugins/getAuthentication/index.test.ts +284 -0
- package/src/plugins/getAuthentication/index.ts +86 -0
- package/src/plugins/getAuthentication/schemas.ts +31 -0
- package/src/plugins/getProfile/index.ts +55 -0
- package/src/plugins/getProfile/schemas.ts +26 -0
- package/src/plugins/listActions/index.test.ts +582 -0
- package/src/plugins/listActions/index.ts +115 -0
- package/src/plugins/listActions/schemas.ts +54 -0
- package/src/plugins/listApps/index.test.ts +357 -0
- package/src/plugins/listApps/index.ts +121 -0
- package/src/plugins/listApps/schemas.ts +49 -0
- package/src/plugins/listAuthentications/index.test.ts +709 -0
- package/src/plugins/listAuthentications/index.ts +136 -0
- package/src/plugins/listAuthentications/schemas.ts +60 -0
- package/src/plugins/listInputFields/index.test.ts +408 -0
- package/src/plugins/listInputFields/index.ts +204 -0
- package/src/plugins/listInputFields/schemas.ts +56 -0
- package/src/plugins/registry/index.ts +30 -0
- package/src/plugins/request/index.test.ts +329 -0
- package/src/plugins/request/index.ts +103 -0
- package/src/{functions → plugins}/request/schemas.ts +20 -9
- package/src/plugins/runAction/index.test.ts +387 -0
- package/src/plugins/runAction/index.ts +176 -0
- package/src/plugins/runAction/schemas.ts +53 -0
- package/src/resolvers/actionKey.ts +6 -4
- package/src/resolvers/actionType.ts +7 -2
- package/src/resolvers/appKey.ts +1 -1
- package/src/resolvers/authenticationId.ts +12 -3
- package/src/resolvers/inputs.ts +3 -1
- package/src/schemas/Action.ts +18 -12
- package/src/schemas/App.ts +11 -19
- package/src/schemas/Auth.ts +18 -13
- package/src/schemas/Field.ts +106 -11
- package/src/schemas/UserProfile.ts +43 -0
- package/src/sdk.test.ts +212 -0
- package/src/sdk.ts +132 -102
- package/src/types/domain.test.ts +50 -0
- package/src/types/domain.ts +43 -75
- package/src/types/errors.ts +275 -0
- package/src/types/functions.ts +27 -0
- package/src/types/optional-zapier-sdk-cli-login.d.ts +37 -0
- package/src/types/plugin.ts +105 -0
- package/src/types/properties.ts +4 -3
- package/src/types/sdk.ts +70 -48
- package/src/utils/array-utils.test.ts +131 -0
- package/src/utils/array-utils.ts +41 -0
- package/src/utils/domain-utils.test.ts +239 -0
- package/src/utils/domain-utils.ts +283 -0
- package/src/utils/function-utils.test.ts +141 -0
- package/src/utils/function-utils.ts +245 -0
- package/src/utils/pagination-utils.test.ts +620 -0
- package/src/utils/pagination-utils.ts +242 -0
- package/src/utils/validation.test.ts +50 -0
- package/src/utils/validation.ts +44 -0
- package/tsconfig.build.json +16 -2
- package/tsconfig.json +3 -1
- package/tsconfig.tsbuildinfo +1 -0
- package/tsup.config.ts +2 -0
- package/src/functions/bundleCode/index.ts +0 -78
- package/src/functions/bundleCode/info.ts +0 -9
- package/src/functions/bundleCode/schemas.ts +0 -30
- package/src/functions/findFirstAuthentication/index.ts +0 -24
- package/src/functions/findFirstAuthentication/info.ts +0 -9
- package/src/functions/findFirstAuthentication/schemas.ts +0 -50
- package/src/functions/findUniqueAuthentication/index.ts +0 -35
- package/src/functions/findUniqueAuthentication/info.ts +0 -9
- package/src/functions/findUniqueAuthentication/schemas.ts +0 -50
- package/src/functions/generateTypes/index.ts +0 -363
- package/src/functions/generateTypes/info.ts +0 -9
- package/src/functions/generateTypes/schemas.ts +0 -31
- package/src/functions/getAction/index.ts +0 -33
- package/src/functions/getAction/info.ts +0 -9
- package/src/functions/getAction/schemas.ts +0 -25
- package/src/functions/getApp/index.ts +0 -41
- package/src/functions/getApp/info.ts +0 -9
- package/src/functions/getApp/schemas.ts +0 -20
- package/src/functions/getAuthentication/index.ts +0 -50
- package/src/functions/getAuthentication/info.ts +0 -9
- package/src/functions/getAuthentication/schemas.ts +0 -29
- package/src/functions/listActions/index.ts +0 -149
- package/src/functions/listActions/info.ts +0 -9
- package/src/functions/listActions/schemas.ts +0 -30
- package/src/functions/listApps/index.ts +0 -60
- package/src/functions/listApps/info.ts +0 -9
- package/src/functions/listApps/schemas.ts +0 -32
- package/src/functions/listAuthentications/index.ts +0 -162
- package/src/functions/listAuthentications/info.ts +0 -9
- package/src/functions/listAuthentications/schemas.ts +0 -50
- package/src/functions/listFields/index.ts +0 -86
- package/src/functions/listFields/info.ts +0 -9
- package/src/functions/listFields/schemas.ts +0 -36
- package/src/functions/request/index.ts +0 -150
- package/src/functions/request/info.ts +0 -11
- package/src/functions/runAction/index.ts +0 -127
- package/src/functions/runAction/info.ts +0 -9
- package/src/functions/runAction/schemas.ts +0 -34
- package/src/plugins/apps/info.ts +0 -12
- package/src/plugins/fetch/types.ts +0 -2
- /package/src/{schema-utils.ts → utils/schema-utils.ts} +0 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authentication Utilities
|
|
3
|
+
*
|
|
4
|
+
* This module provides utilities for handling authentication tokens,
|
|
5
|
+
* including JWT detection and authorization header generation.
|
|
6
|
+
*/
|
|
7
|
+
export declare function isJwt(token: string): boolean;
|
|
8
|
+
export declare function getAuthorizationHeader(token: string): string;
|
|
9
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/api/auth.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAW5C;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAO5D"}
|
package/dist/api/auth.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authentication Utilities
|
|
3
|
+
*
|
|
4
|
+
* This module provides utilities for handling authentication tokens,
|
|
5
|
+
* including JWT detection and authorization header generation.
|
|
6
|
+
*/
|
|
7
|
+
export function isJwt(token) {
|
|
8
|
+
// JWT tokens have exactly 3 parts separated by dots
|
|
9
|
+
const parts = token.split(".");
|
|
10
|
+
if (parts.length !== 3) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
// Each part should be base64url encoded (no padding)
|
|
14
|
+
// Basic validation - each part should be non-empty and contain valid base64url characters
|
|
15
|
+
const base64UrlPattern = /^[A-Za-z0-9_-]+$/;
|
|
16
|
+
return parts.every((part) => part.length > 0 && base64UrlPattern.test(part));
|
|
17
|
+
}
|
|
18
|
+
export function getAuthorizationHeader(token) {
|
|
19
|
+
// Check if token is a JWT (has 3 parts separated by dots)
|
|
20
|
+
if (isJwt(token)) {
|
|
21
|
+
return `JWT ${token}`;
|
|
22
|
+
}
|
|
23
|
+
// Default to Bearer for other token types
|
|
24
|
+
return `Bearer ${token}`;
|
|
25
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API Client Implementation
|
|
3
|
+
*
|
|
4
|
+
* This module contains the core API client implementation, including
|
|
5
|
+
* HTTP method handlers, response processing, and client factory functions.
|
|
6
|
+
*/
|
|
7
|
+
import type { ApiClient, ApiClientOptions } from "./types";
|
|
8
|
+
export declare const createZapierApi: (options: ApiClientOptions) => ApiClient;
|
|
9
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +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;AA4bjB,eAAO,MAAM,eAAe,GAAI,SAAS,gBAAgB,KAAG,SAqB3D,CAAC"}
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API Client Implementation
|
|
3
|
+
*
|
|
4
|
+
* This module contains the core API client implementation, including
|
|
5
|
+
* HTTP method handlers, response processing, and client factory functions.
|
|
6
|
+
*/
|
|
7
|
+
import { getAuthorizationHeader } from "./auth";
|
|
8
|
+
import { createDebugLogger, createDebugFetch } from "./debug";
|
|
9
|
+
import { pollUntilComplete } from "./polling";
|
|
10
|
+
import { getTokenFromEnvOrConfig } from "../auth";
|
|
11
|
+
import { ZapierApiError, ZapierAuthenticationError, ZapierValidationError, ZapierNotFoundError, } from "../types/errors";
|
|
12
|
+
const SubdomainConfigMap = {
|
|
13
|
+
// e.g. https://relay.zapier.com
|
|
14
|
+
relay: {
|
|
15
|
+
authHeader: "X-Relay-Authorization",
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
class ZapierApiClient {
|
|
19
|
+
constructor(options) {
|
|
20
|
+
this.options = options;
|
|
21
|
+
this.fetch = async (path, init) => {
|
|
22
|
+
return this.plainFetch(path, init);
|
|
23
|
+
};
|
|
24
|
+
this.get = async (path, options = {}) => {
|
|
25
|
+
return this.fetchJson("GET", path, undefined, options);
|
|
26
|
+
};
|
|
27
|
+
this.post = async (path, data, options = {}) => {
|
|
28
|
+
return this.fetchJson("POST", path, data, options);
|
|
29
|
+
};
|
|
30
|
+
this.put = async (path, data, options = {}) => {
|
|
31
|
+
return this.fetchJson("PUT", path, data, options);
|
|
32
|
+
};
|
|
33
|
+
this.delete = async (path, options = {}) => {
|
|
34
|
+
return this.fetchJson("DELETE", path, undefined, options);
|
|
35
|
+
};
|
|
36
|
+
this.poll = async (path, options = {}) => {
|
|
37
|
+
return pollUntilComplete({
|
|
38
|
+
fetchPoll: () => this.plainFetch(path, {
|
|
39
|
+
method: "GET",
|
|
40
|
+
searchParams: options.searchParams,
|
|
41
|
+
authRequired: options.authRequired,
|
|
42
|
+
}),
|
|
43
|
+
maxAttempts: options.maxAttempts,
|
|
44
|
+
initialDelay: options.initialDelay,
|
|
45
|
+
maxDelay: options.maxDelay,
|
|
46
|
+
successStatus: options.successStatus,
|
|
47
|
+
pendingStatus: options.pendingStatus,
|
|
48
|
+
resultExtractor: options.resultExtractor,
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
// Helper to parse response data
|
|
53
|
+
async parseResult(response) {
|
|
54
|
+
try {
|
|
55
|
+
return { type: "json", data: await response.json() };
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return { type: "text", data: await response.text() };
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// Helper to get a token from the different places it could be gotten
|
|
62
|
+
async getAuthToken() {
|
|
63
|
+
if (this.options.token) {
|
|
64
|
+
return this.options.token;
|
|
65
|
+
}
|
|
66
|
+
if (this.options.getToken) {
|
|
67
|
+
const token = await this.options.getToken();
|
|
68
|
+
if (token) {
|
|
69
|
+
return token;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return getTokenFromEnvOrConfig({
|
|
73
|
+
onEvent: this.options.onEvent,
|
|
74
|
+
fetch: this.options.fetch,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
// Helper to handle responses
|
|
78
|
+
async handleResponse(params) {
|
|
79
|
+
const { response, customErrorHandler, wasMissingAuthToken } = params;
|
|
80
|
+
const { data: responseData } = await this.parseResult(response);
|
|
81
|
+
if (response.ok) {
|
|
82
|
+
return responseData;
|
|
83
|
+
}
|
|
84
|
+
const errorInfo = {
|
|
85
|
+
status: response.status,
|
|
86
|
+
statusText: response.statusText,
|
|
87
|
+
data: responseData,
|
|
88
|
+
};
|
|
89
|
+
// Check for custom error handling first
|
|
90
|
+
if (customErrorHandler) {
|
|
91
|
+
const customError = customErrorHandler(errorInfo);
|
|
92
|
+
if (customError) {
|
|
93
|
+
// javascript may not respect customErrorHandler return type, so we need to throw a proper error if it's not an Error
|
|
94
|
+
if (customError instanceof Error) {
|
|
95
|
+
throw customError;
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
throw new Error(`customErrorHandler returned a non-Error: ${JSON.stringify(customError)}`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// Parse the error response
|
|
103
|
+
const { message, errors } = this.parseErrorResponse(errorInfo);
|
|
104
|
+
const errorOptions = {
|
|
105
|
+
statusCode: response.status,
|
|
106
|
+
errors,
|
|
107
|
+
};
|
|
108
|
+
// Use appropriate error type based on status code
|
|
109
|
+
if (response.status === 404) {
|
|
110
|
+
throw new ZapierNotFoundError(message, errorOptions);
|
|
111
|
+
}
|
|
112
|
+
if (response.status === 401 || response.status === 403) {
|
|
113
|
+
// If we get a 401/403 error and no auth token was provided, give helpful message
|
|
114
|
+
if (wasMissingAuthToken) {
|
|
115
|
+
throw new ZapierAuthenticationError(`Authentication required (HTTP ${response.status}). Please provide a token in options or set ZAPIER_TOKEN environment variable.`, errorOptions);
|
|
116
|
+
}
|
|
117
|
+
throw new ZapierAuthenticationError(message, errorOptions);
|
|
118
|
+
}
|
|
119
|
+
if (response.status === 400) {
|
|
120
|
+
throw new ZapierValidationError(message, errorOptions);
|
|
121
|
+
}
|
|
122
|
+
// Generic API error for other status codes
|
|
123
|
+
throw new ZapierApiError(message, errorOptions);
|
|
124
|
+
}
|
|
125
|
+
hasErrorArray(data) {
|
|
126
|
+
return (typeof data === "object" &&
|
|
127
|
+
data !== null &&
|
|
128
|
+
"errors" in data &&
|
|
129
|
+
Array.isArray(data.errors));
|
|
130
|
+
}
|
|
131
|
+
// Helper to check if data has API errors
|
|
132
|
+
isApiErrorArray(dataArray) {
|
|
133
|
+
const data = dataArray[0];
|
|
134
|
+
return (typeof data === "object" &&
|
|
135
|
+
data !== null &&
|
|
136
|
+
"message" in data &&
|
|
137
|
+
"code" in data &&
|
|
138
|
+
"title" in data &&
|
|
139
|
+
"detail" in data);
|
|
140
|
+
}
|
|
141
|
+
// Do our best to extract an error message from the response data
|
|
142
|
+
extractErrorMessage(data) {
|
|
143
|
+
if (typeof data === "string") {
|
|
144
|
+
return data;
|
|
145
|
+
}
|
|
146
|
+
if (typeof data === "object" && data !== null) {
|
|
147
|
+
if ("message" in data && typeof data.message === "string") {
|
|
148
|
+
return data.message;
|
|
149
|
+
}
|
|
150
|
+
if ("error" in data) {
|
|
151
|
+
if (typeof data.error === "string") {
|
|
152
|
+
return data.error;
|
|
153
|
+
}
|
|
154
|
+
if (typeof data.error === "object" && data.error !== null) {
|
|
155
|
+
if ("message" in data.error &&
|
|
156
|
+
typeof data.error.message === "string") {
|
|
157
|
+
return data.error.message;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
try {
|
|
161
|
+
return JSON.stringify(data.error);
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
/* defend against circular objects, even though they shouldn't be coming back from the wire */
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if ("errors" in data && Array.isArray(data.errors)) {
|
|
168
|
+
if (this.isApiErrorArray(data.errors)) {
|
|
169
|
+
return data.errors[0].detail || data.errors[0].title;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return undefined;
|
|
174
|
+
}
|
|
175
|
+
// Helper to parse API error response
|
|
176
|
+
parseErrorResponse(errorInfo) {
|
|
177
|
+
// If we can't parse data, use status text
|
|
178
|
+
const fallbackMessage = `HTTP ${errorInfo.status}: ${errorInfo.statusText}`;
|
|
179
|
+
try {
|
|
180
|
+
// Check if the response has the standard error format
|
|
181
|
+
if (typeof errorInfo.data === "string") {
|
|
182
|
+
return { message: `${fallbackMessage}: ${errorInfo.data}` };
|
|
183
|
+
}
|
|
184
|
+
const errorMessage = this.extractErrorMessage(errorInfo.data) || fallbackMessage;
|
|
185
|
+
if (this.hasErrorArray(errorInfo.data)) {
|
|
186
|
+
if (this.isApiErrorArray(errorInfo.data.errors)) {
|
|
187
|
+
return {
|
|
188
|
+
message: errorMessage,
|
|
189
|
+
errors: errorInfo.data.errors,
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
return {
|
|
194
|
+
message: errorMessage,
|
|
195
|
+
errors: errorInfo.data.errors.map((e) => ({
|
|
196
|
+
status: errorInfo.status,
|
|
197
|
+
code: String(errorInfo.status),
|
|
198
|
+
title: errorInfo.statusText,
|
|
199
|
+
detail: JSON.stringify(e),
|
|
200
|
+
})),
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return { message: errorMessage };
|
|
205
|
+
}
|
|
206
|
+
catch {
|
|
207
|
+
return { message: fallbackMessage };
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
// Check if this is a path that needs subdomain routing
|
|
211
|
+
// e.g. /relay/workflows -> relay.zapier.com/workflows
|
|
212
|
+
applySubdomainBehavior(path) {
|
|
213
|
+
const pathSegments = path.split("/").filter(Boolean);
|
|
214
|
+
if (pathSegments.length > 0 && pathSegments[0] in SubdomainConfigMap) {
|
|
215
|
+
// Transform paths to use subdomain routing
|
|
216
|
+
// /prefix/domain/path -> prefix.zapier.com/domain/path
|
|
217
|
+
const domainPrefix = pathSegments[0];
|
|
218
|
+
const subdomainConfig = SubdomainConfigMap[domainPrefix];
|
|
219
|
+
const originalBaseUrl = new URL(this.options.baseUrl);
|
|
220
|
+
const finalBaseUrl = `https://${domainPrefix}.${originalBaseUrl.hostname}`;
|
|
221
|
+
const pathWithoutPrefix = "/" + pathSegments.slice(1).join("/");
|
|
222
|
+
return { url: new URL(pathWithoutPrefix, finalBaseUrl), subdomainConfig };
|
|
223
|
+
}
|
|
224
|
+
return {
|
|
225
|
+
url: new URL(path, this.options.baseUrl),
|
|
226
|
+
subdomainConfig: undefined,
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
// Helper to build full URLs and return routing info
|
|
230
|
+
buildUrl(path, searchParams) {
|
|
231
|
+
const { url, subdomainConfig } = this.applySubdomainBehavior(path);
|
|
232
|
+
if (searchParams) {
|
|
233
|
+
Object.entries(searchParams).forEach(([key, value]) => {
|
|
234
|
+
url.searchParams.set(key, value);
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
return { url: url.toString(), subdomainConfig };
|
|
238
|
+
}
|
|
239
|
+
// Helper to build headers
|
|
240
|
+
async buildHeaders(options = {}, subdomainConfig) {
|
|
241
|
+
const headers = new Headers(options.headers ?? {});
|
|
242
|
+
// Even if auth is not required, we still want to add it in case it adds
|
|
243
|
+
// useful context to the API. The session is a good example of this. Auth
|
|
244
|
+
// is not required, but if we don't add auth, then we won't get the user's
|
|
245
|
+
// session!
|
|
246
|
+
const authToken = await this.getAuthToken();
|
|
247
|
+
if (authToken) {
|
|
248
|
+
const authHeaderName = subdomainConfig?.authHeader || "Authorization";
|
|
249
|
+
headers.set(authHeaderName, getAuthorizationHeader(authToken));
|
|
250
|
+
}
|
|
251
|
+
// If we know auth is required, and we don't have a token, throw an error
|
|
252
|
+
// before we even make a request.
|
|
253
|
+
if (options.authRequired) {
|
|
254
|
+
if (headers.get("Authorization") == null && authToken == null) {
|
|
255
|
+
throw new ZapierAuthenticationError(`Authentication required but no token available. Please set ZAPIER_TOKEN, or run the 'login' command with the CLI.`);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return headers;
|
|
259
|
+
}
|
|
260
|
+
// Helper to perform HTTP requests with JSON handling
|
|
261
|
+
async fetchJson(method, path, data, options = {}) {
|
|
262
|
+
const headers = { ...options.headers };
|
|
263
|
+
// Add Content-Type for JSON requests with body data
|
|
264
|
+
if (data && typeof data === "object") {
|
|
265
|
+
headers["Content-Type"] = "application/json";
|
|
266
|
+
}
|
|
267
|
+
// Check if we have an auth token available
|
|
268
|
+
const wasMissingAuthToken = options.authRequired && (await this.getAuthToken()) == null;
|
|
269
|
+
const response = await this.plainFetch(path, {
|
|
270
|
+
...options,
|
|
271
|
+
method,
|
|
272
|
+
body: data != null ? JSON.stringify(data) : undefined,
|
|
273
|
+
headers,
|
|
274
|
+
});
|
|
275
|
+
// plainFetch already handled all auth and headers
|
|
276
|
+
const result = await this.handleResponse({
|
|
277
|
+
response,
|
|
278
|
+
customErrorHandler: options.customErrorHandler,
|
|
279
|
+
wasMissingAuthToken,
|
|
280
|
+
});
|
|
281
|
+
if (typeof result === "string") {
|
|
282
|
+
throw new ZapierValidationError(`Response could not be parsed as JSON: ${result}`);
|
|
283
|
+
}
|
|
284
|
+
return result;
|
|
285
|
+
}
|
|
286
|
+
// Plain fetch method for API paths (must start with /)
|
|
287
|
+
async plainFetch(path, fetchOptions) {
|
|
288
|
+
if (!path.startsWith("/")) {
|
|
289
|
+
throw new ZapierValidationError(`plainFetch expects a path starting with '/', got: ${path}`);
|
|
290
|
+
}
|
|
291
|
+
if (fetchOptions?.body && typeof fetchOptions.body === "object") {
|
|
292
|
+
fetchOptions.body = JSON.stringify(fetchOptions.body);
|
|
293
|
+
}
|
|
294
|
+
const { url, subdomainConfig } = this.buildUrl(path, fetchOptions?.searchParams);
|
|
295
|
+
const builtHeaders = await this.buildHeaders(fetchOptions, subdomainConfig);
|
|
296
|
+
const inputHeaders = new Headers(fetchOptions?.headers ?? {});
|
|
297
|
+
const mergedHeaders = new Headers();
|
|
298
|
+
builtHeaders.forEach((value, key) => {
|
|
299
|
+
mergedHeaders.set(key, value);
|
|
300
|
+
});
|
|
301
|
+
inputHeaders.forEach((value, key) => {
|
|
302
|
+
mergedHeaders.set(key, value);
|
|
303
|
+
});
|
|
304
|
+
return await this.options.fetch(url, {
|
|
305
|
+
...fetchOptions,
|
|
306
|
+
headers: mergedHeaders,
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
export const createZapierApi = (options) => {
|
|
311
|
+
const { baseUrl, token, getToken, debug = false, fetch: originalFetch = globalThis.fetch, onEvent, } = options;
|
|
312
|
+
const debugLog = createDebugLogger(debug);
|
|
313
|
+
const debugFetch = createDebugFetch({ originalFetch, debugLog });
|
|
314
|
+
return new ZapierApiClient({
|
|
315
|
+
baseUrl,
|
|
316
|
+
token,
|
|
317
|
+
getToken,
|
|
318
|
+
debug,
|
|
319
|
+
fetch: debugFetch,
|
|
320
|
+
onEvent,
|
|
321
|
+
});
|
|
322
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Debug Logging Utilities
|
|
3
|
+
*
|
|
4
|
+
* This module provides debug logging capabilities for API requests and responses,
|
|
5
|
+
* including request timing and detailed logging of HTTP interactions.
|
|
6
|
+
*/
|
|
7
|
+
import type { DebugLogger } from "./types";
|
|
8
|
+
export declare function createDebugLogger(enabled: boolean): DebugLogger;
|
|
9
|
+
export declare function createDebugFetch(options: {
|
|
10
|
+
originalFetch: typeof globalThis.fetch;
|
|
11
|
+
debugLog: DebugLogger;
|
|
12
|
+
}): (input: RequestInfo | URL, options?: RequestInit) => Promise<Response>;
|
|
13
|
+
//# sourceMappingURL=debug.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../../src/api/debug.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,GAAG,WAAW,CAQ/D;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE;IACxC,aAAa,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IACvC,QAAQ,EAAE,WAAW,CAAC;CACvB,IAEe,OAAO,WAAW,GAAG,GAAG,EAAE,UAAU,WAAW,uBA0C9D"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Debug Logging Utilities
|
|
3
|
+
*
|
|
4
|
+
* This module provides debug logging capabilities for API requests and responses,
|
|
5
|
+
* including request timing and detailed logging of HTTP interactions.
|
|
6
|
+
*/
|
|
7
|
+
export function createDebugLogger(enabled) {
|
|
8
|
+
if (!enabled) {
|
|
9
|
+
return () => { }; // No-op function when debug is disabled
|
|
10
|
+
}
|
|
11
|
+
return (message, data) => {
|
|
12
|
+
console.log(`[Zapier SDK] ${message}`, data || "");
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export function createDebugFetch(options) {
|
|
16
|
+
const { originalFetch, debugLog } = options;
|
|
17
|
+
return async (input, options) => {
|
|
18
|
+
const startTime = Date.now();
|
|
19
|
+
// Convert input to URL string for logging
|
|
20
|
+
const url = typeof input === "string" ? input : input.toString();
|
|
21
|
+
const method = options?.method || "GET";
|
|
22
|
+
debugLog(`→ ${method} ${url}`, {
|
|
23
|
+
headers: options?.headers,
|
|
24
|
+
body: options?.body && typeof options.body === "string"
|
|
25
|
+
? (() => {
|
|
26
|
+
try {
|
|
27
|
+
return JSON.parse(options.body);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return options.body;
|
|
31
|
+
}
|
|
32
|
+
})()
|
|
33
|
+
: options?.body,
|
|
34
|
+
});
|
|
35
|
+
try {
|
|
36
|
+
const response = await originalFetch(input, options);
|
|
37
|
+
const duration = Date.now() - startTime;
|
|
38
|
+
debugLog(`← ${response.status} ${response.statusText} (${duration}ms)`, {
|
|
39
|
+
url,
|
|
40
|
+
method,
|
|
41
|
+
status: response.status,
|
|
42
|
+
});
|
|
43
|
+
return response;
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
const duration = Date.now() - startTime;
|
|
47
|
+
debugLog(`✖ Request failed (${duration}ms)`, {
|
|
48
|
+
url,
|
|
49
|
+
method,
|
|
50
|
+
error: error instanceof Error ? error.message : error,
|
|
51
|
+
});
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zapier API Client Module
|
|
3
|
+
*
|
|
4
|
+
* This module provides a centralized API layer for all HTTP interactions
|
|
5
|
+
* with Zapier's various APIs. It handles authentication, error handling,
|
|
6
|
+
* polling, and provides consistent patterns across all services.
|
|
7
|
+
*/
|
|
8
|
+
export type { ApiClient, ApiClientOptions, RequestOptions, PollOptions, DebugLogger, Action, Field, Choice, ActionExecutionResult, ActionField, ActionFieldChoice, NeedsRequest, NeedsResponse, Authentication, AuthenticationsResponse, } from "./types";
|
|
9
|
+
import type { ApiClient } from "./types";
|
|
10
|
+
export { isJwt, getAuthorizationHeader } from "./auth";
|
|
11
|
+
export { createDebugLogger, createDebugFetch } from "./debug";
|
|
12
|
+
export { pollUntilComplete } from "./polling";
|
|
13
|
+
export { createZapierApi } from "./client";
|
|
14
|
+
export declare function generateRequestId(): string;
|
|
15
|
+
/**
|
|
16
|
+
* Utility function to get or create an API client for standalone functions
|
|
17
|
+
*
|
|
18
|
+
* @param config - Configuration that may include an existing API client
|
|
19
|
+
* @returns ApiClient instance
|
|
20
|
+
*/
|
|
21
|
+
export declare function getOrCreateApiClient(config: {
|
|
22
|
+
baseUrl?: string;
|
|
23
|
+
token?: string;
|
|
24
|
+
getToken?: () => Promise<string | undefined>;
|
|
25
|
+
api?: ApiClient;
|
|
26
|
+
debug?: boolean;
|
|
27
|
+
fetch?: typeof globalThis.fetch;
|
|
28
|
+
}): ApiClient;
|
|
29
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,YAAY,EAEV,SAAS,EACT,gBAAgB,EAChB,cAAc,EACd,WAAW,EACX,WAAW,EAEX,MAAM,EACN,KAAK,EACL,MAAM,EACN,qBAAqB,EACrB,WAAW,EACX,iBAAiB,EACjB,YAAY,EACZ,aAAa,EACb,cAAc,EACd,uBAAuB,GACxB,MAAM,SAAS,CAAC;AAGjB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAGzC,OAAO,EAAE,KAAK,EAAE,sBAAsB,EAAE,MAAM,QAAQ,CAAC;AAGvD,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAG9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAG9C,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAM3C,wBAAgB,iBAAiB,IAAI,MAAM,CAE1C;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE;IAC3C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IAC7C,GAAG,CAAC,EAAE,SAAS,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;CACjC,GAAG,SAAS,CAsBZ"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zapier API Client Module
|
|
3
|
+
*
|
|
4
|
+
* This module provides a centralized API layer for all HTTP interactions
|
|
5
|
+
* with Zapier's various APIs. It handles authentication, error handling,
|
|
6
|
+
* polling, and provides consistent patterns across all services.
|
|
7
|
+
*/
|
|
8
|
+
// Re-export authentication utilities
|
|
9
|
+
export { isJwt, getAuthorizationHeader } from "./auth";
|
|
10
|
+
// Re-export debug utilities
|
|
11
|
+
export { createDebugLogger, createDebugFetch } from "./debug";
|
|
12
|
+
// Re-export polling utilities
|
|
13
|
+
export { pollUntilComplete } from "./polling";
|
|
14
|
+
// Re-export the main client factory
|
|
15
|
+
export { createZapierApi } from "./client";
|
|
16
|
+
// Import for local use
|
|
17
|
+
import { createZapierApi } from "./client";
|
|
18
|
+
// Utility Functions
|
|
19
|
+
export function generateRequestId() {
|
|
20
|
+
return Math.random().toString(36).substring(2) + Date.now().toString(36);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Utility function to get or create an API client for standalone functions
|
|
24
|
+
*
|
|
25
|
+
* @param config - Configuration that may include an existing API client
|
|
26
|
+
* @returns ApiClient instance
|
|
27
|
+
*/
|
|
28
|
+
export function getOrCreateApiClient(config) {
|
|
29
|
+
const { baseUrl = "https://zapier.com", token, getToken, api: providedApi, debug = false, fetch: customFetch, } = config;
|
|
30
|
+
// Use provided API client or create a new one
|
|
31
|
+
if (providedApi) {
|
|
32
|
+
return providedApi;
|
|
33
|
+
}
|
|
34
|
+
return createZapierApi({
|
|
35
|
+
baseUrl,
|
|
36
|
+
token,
|
|
37
|
+
getToken,
|
|
38
|
+
debug,
|
|
39
|
+
fetch: customFetch,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Polling Utilities
|
|
3
|
+
*
|
|
4
|
+
* This module provides utilities for polling HTTP endpoints until completion,
|
|
5
|
+
* with configurable retry logic and exponential backoff.
|
|
6
|
+
*/
|
|
7
|
+
export declare function pollUntilComplete(options: {
|
|
8
|
+
fetchPoll: () => Promise<Response>;
|
|
9
|
+
maxAttempts?: number;
|
|
10
|
+
initialDelay?: number;
|
|
11
|
+
maxDelay?: number;
|
|
12
|
+
successStatus?: number;
|
|
13
|
+
pendingStatus?: number;
|
|
14
|
+
resultExtractor?: (response: any) => any;
|
|
15
|
+
}): Promise<any>;
|
|
16
|
+
//# sourceMappingURL=polling.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"polling.d.ts","sourceRoot":"","sources":["../../src/api/polling.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,wBAAsB,iBAAiB,CAAC,OAAO,EAAE;IAC/C,SAAS,EAAE,MAAM,OAAO,CAAC,QAAQ,CAAC,CAAC;IACnC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,eAAe,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,KAAK,GAAG,CAAC;CAC1C,GAAG,OAAO,CAAC,GAAG,CAAC,CAuDf"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Polling Utilities
|
|
3
|
+
*
|
|
4
|
+
* This module provides utilities for polling HTTP endpoints until completion,
|
|
5
|
+
* with configurable retry logic and exponential backoff.
|
|
6
|
+
*/
|
|
7
|
+
import { ZapierTimeoutError, ZapierApiError } from "../types/errors";
|
|
8
|
+
export async function pollUntilComplete(options) {
|
|
9
|
+
const { fetchPoll, maxAttempts = 30, initialDelay = 50, maxDelay = 1000, successStatus = 200, pendingStatus = 202, resultExtractor = (response) => response, } = options;
|
|
10
|
+
let delay = initialDelay;
|
|
11
|
+
let errorCount = 0;
|
|
12
|
+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
13
|
+
const response = await fetchPoll();
|
|
14
|
+
if (response.status === successStatus) {
|
|
15
|
+
// Success - reset error count and return results
|
|
16
|
+
errorCount = 0;
|
|
17
|
+
const result = await response.json();
|
|
18
|
+
return resultExtractor(result);
|
|
19
|
+
}
|
|
20
|
+
else if (response.status === pendingStatus) {
|
|
21
|
+
// Still processing - reset error count and wait and retry
|
|
22
|
+
errorCount = 0;
|
|
23
|
+
if (attempt < maxAttempts - 1) {
|
|
24
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
25
|
+
delay = Math.min(delay * 2, maxDelay); // Exponential backoff
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
// Error occurred - increment error count
|
|
31
|
+
errorCount++;
|
|
32
|
+
if (errorCount >= 3) {
|
|
33
|
+
// Too many consecutive errors, fail
|
|
34
|
+
throw new ZapierApiError(`Poll request failed: ${response.status} ${response.statusText}`, { statusCode: response.status });
|
|
35
|
+
}
|
|
36
|
+
// Treat as pending for up to 3 errors - wait and retry
|
|
37
|
+
if (attempt < maxAttempts - 1) {
|
|
38
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
39
|
+
delay = Math.min(delay * 2, maxDelay); // Exponential backoff
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
throw new ZapierTimeoutError(`Operation timed out after ${maxAttempts} attempts`, { attempts: maxAttempts, maxAttempts: maxAttempts });
|
|
45
|
+
}
|