@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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zapier/zapier-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Complete Zapier SDK - combines all Zapier SDK packages",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -31,13 +31,21 @@
|
|
|
31
31
|
"access": "restricted"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"esbuild": "^0.25.5",
|
|
35
34
|
"zod": "^3.25.67"
|
|
36
35
|
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"@zapier/zapier-sdk-cli-login": "*"
|
|
38
|
+
},
|
|
39
|
+
"peerDependenciesMeta": {
|
|
40
|
+
"@zapier/zapier-sdk-cli-login": {
|
|
41
|
+
"optional": true
|
|
42
|
+
}
|
|
43
|
+
},
|
|
37
44
|
"devDependencies": {
|
|
38
45
|
"@types/node": "^24.0.1",
|
|
39
46
|
"tsup": "^8.5.0",
|
|
40
47
|
"typescript": "^5.8.3",
|
|
48
|
+
"vitest": "^3.2.3",
|
|
41
49
|
"@zapier/zapier-sdk-cli-login": "0.3.1"
|
|
42
50
|
},
|
|
43
51
|
"scripts": {
|
|
@@ -45,6 +53,7 @@
|
|
|
45
53
|
"clean": "rm -rf dist",
|
|
46
54
|
"rebuild": "pnpm clean && pnpm build",
|
|
47
55
|
"dev": "tsc --watch",
|
|
48
|
-
"typecheck": "tsc --project tsconfig.build.json --noEmit"
|
|
56
|
+
"typecheck": "tsc --project tsconfig.build.json --noEmit",
|
|
57
|
+
"test": "vitest"
|
|
49
58
|
}
|
|
50
59
|
}
|
package/src/api/client.ts
CHANGED
|
@@ -15,172 +15,307 @@ import { getAuthorizationHeader } from "./auth";
|
|
|
15
15
|
import { createDebugLogger, createDebugFetch } from "./debug";
|
|
16
16
|
import { pollUntilComplete } from "./polling";
|
|
17
17
|
import { getTokenFromEnvOrConfig } from "../auth";
|
|
18
|
+
import {
|
|
19
|
+
ZapierApiError,
|
|
20
|
+
ZapierAuthenticationError,
|
|
21
|
+
ZapierValidationError,
|
|
22
|
+
ZapierNotFoundError,
|
|
23
|
+
type ApiError,
|
|
24
|
+
} from "../types/errors";
|
|
18
25
|
|
|
19
26
|
// Configuration for path prefixes that should be treated as subdomains
|
|
20
|
-
|
|
27
|
+
type SubdomainConfigMap = typeof SubdomainConfigMap;
|
|
28
|
+
type SubdomainConfig = SubdomainConfigMap[keyof SubdomainConfigMap];
|
|
29
|
+
const SubdomainConfigMap = {
|
|
30
|
+
// e.g. https://relay.zapier.com
|
|
21
31
|
relay: {
|
|
22
32
|
authHeader: "X-Relay-Authorization",
|
|
23
33
|
},
|
|
24
34
|
} as const;
|
|
25
35
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
debug = false,
|
|
32
|
-
fetch: originalFetch = globalThis.fetch,
|
|
33
|
-
onEvent,
|
|
34
|
-
} = options;
|
|
35
|
-
|
|
36
|
-
const debugLog = createDebugLogger(debug);
|
|
37
|
-
const fetch = createDebugFetch({ originalFetch, debugLog });
|
|
36
|
+
class ZapierApiClient implements ApiClient {
|
|
37
|
+
constructor(
|
|
38
|
+
private readonly options: ApiClientOptions &
|
|
39
|
+
Required<Pick<ApiClientOptions, "fetch">>,
|
|
40
|
+
) {}
|
|
38
41
|
|
|
39
|
-
// Helper to
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
// Check if this is a path that needs subdomain routing
|
|
48
|
-
const pathSegments = path.split("/").filter(Boolean);
|
|
49
|
-
let finalBaseUrl = baseUrl;
|
|
50
|
-
let subdomainConfig:
|
|
51
|
-
| (typeof SUBDOMAIN_PREFIXES)[keyof typeof SUBDOMAIN_PREFIXES]
|
|
52
|
-
| undefined;
|
|
53
|
-
|
|
54
|
-
if (pathSegments.length > 0 && pathSegments[0] in SUBDOMAIN_PREFIXES) {
|
|
55
|
-
// Transform paths to use subdomain routing
|
|
56
|
-
// /prefix/domain/path -> prefix.zapier.com/domain/path
|
|
57
|
-
const subdomain = pathSegments[0] as keyof typeof SUBDOMAIN_PREFIXES;
|
|
58
|
-
subdomainConfig = SUBDOMAIN_PREFIXES[subdomain];
|
|
59
|
-
const baseUrlObj = new URL(baseUrl);
|
|
60
|
-
baseUrlObj.hostname = `${subdomain}.${baseUrlObj.hostname}`;
|
|
61
|
-
finalBaseUrl = baseUrlObj.toString();
|
|
62
|
-
|
|
63
|
-
// Remove the subdomain prefix from the path
|
|
64
|
-
path = "/" + pathSegments.slice(1).join("/");
|
|
42
|
+
// Helper to parse response data
|
|
43
|
+
private async parseResult<TOutput = unknown>(
|
|
44
|
+
response: Response,
|
|
45
|
+
): Promise<{ type: "json"; data: TOutput } | { type: "text"; data: string }> {
|
|
46
|
+
try {
|
|
47
|
+
return { type: "json", data: await response.json() };
|
|
48
|
+
} catch {
|
|
49
|
+
return { type: "text", data: await response.text() };
|
|
65
50
|
}
|
|
51
|
+
}
|
|
66
52
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
});
|
|
53
|
+
// Helper to get a token from the different places it could be gotten
|
|
54
|
+
private async getAuthToken(): Promise<string | undefined> {
|
|
55
|
+
if (this.options.token) {
|
|
56
|
+
return this.options.token;
|
|
72
57
|
}
|
|
73
|
-
|
|
58
|
+
if (this.options.getToken) {
|
|
59
|
+
const token = await this.options.getToken();
|
|
60
|
+
if (token) {
|
|
61
|
+
return token;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return getTokenFromEnvOrConfig({
|
|
65
|
+
onEvent: this.options.onEvent,
|
|
66
|
+
fetch: this.options.fetch,
|
|
67
|
+
});
|
|
74
68
|
}
|
|
75
69
|
|
|
76
|
-
// Helper to
|
|
77
|
-
async
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
};
|
|
70
|
+
// Helper to handle responses
|
|
71
|
+
private async handleResponse<TOutput = unknown>(params: {
|
|
72
|
+
response: Response;
|
|
73
|
+
customErrorHandler?: RequestOptions["customErrorHandler"];
|
|
74
|
+
wasMissingAuthToken?: boolean;
|
|
75
|
+
}): Promise<string | TOutput> {
|
|
76
|
+
const { response, customErrorHandler, wasMissingAuthToken } = params;
|
|
77
|
+
const { data: responseData } = await this.parseResult<TOutput>(response);
|
|
78
|
+
if (response.ok) {
|
|
79
|
+
return responseData;
|
|
80
|
+
}
|
|
84
81
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
82
|
+
const errorInfo = {
|
|
83
|
+
status: response.status,
|
|
84
|
+
statusText: response.statusText,
|
|
85
|
+
data: responseData,
|
|
86
|
+
};
|
|
88
87
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
88
|
+
// Check for custom error handling first
|
|
89
|
+
if (customErrorHandler) {
|
|
90
|
+
const customError = customErrorHandler(errorInfo);
|
|
91
|
+
if (customError) {
|
|
92
|
+
// javascript may not respect customErrorHandler return type, so we need to throw a proper error if it's not an Error
|
|
93
|
+
if (customError instanceof Error) {
|
|
94
|
+
throw customError;
|
|
95
|
+
} else {
|
|
96
|
+
throw new Error(
|
|
97
|
+
`customErrorHandler returned a non-Error: ${JSON.stringify(customError)}`,
|
|
98
|
+
);
|
|
99
|
+
}
|
|
92
100
|
}
|
|
101
|
+
}
|
|
93
102
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
103
|
+
// Parse the error response
|
|
104
|
+
const { message, errors } = this.parseErrorResponse(errorInfo);
|
|
105
|
+
|
|
106
|
+
const errorOptions = {
|
|
107
|
+
statusCode: response.status,
|
|
108
|
+
errors,
|
|
109
|
+
};
|
|
100
110
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
111
|
+
// Use appropriate error type based on status code
|
|
112
|
+
if (response.status === 404) {
|
|
113
|
+
throw new ZapierNotFoundError(message, errorOptions);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (response.status === 401 || response.status === 403) {
|
|
117
|
+
// If we get a 401/403 error and no auth token was provided, give helpful message
|
|
118
|
+
if (wasMissingAuthToken) {
|
|
119
|
+
throw new ZapierAuthenticationError(
|
|
120
|
+
`Authentication required (HTTP ${response.status}). Please provide a token in options or set ZAPIER_TOKEN environment variable.`,
|
|
121
|
+
errorOptions,
|
|
122
|
+
);
|
|
104
123
|
}
|
|
124
|
+
throw new ZapierAuthenticationError(message, errorOptions);
|
|
105
125
|
}
|
|
106
126
|
|
|
107
|
-
|
|
127
|
+
if (response.status === 400) {
|
|
128
|
+
throw new ZapierValidationError(message, errorOptions);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Generic API error for other status codes
|
|
132
|
+
throw new ZapierApiError(message, errorOptions);
|
|
108
133
|
}
|
|
109
134
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
135
|
+
private hasErrorArray<TOutput = unknown>(
|
|
136
|
+
data: TOutput | string,
|
|
137
|
+
): data is { errors: unknown[] } & Exclude<TOutput, string> {
|
|
138
|
+
return (
|
|
139
|
+
typeof data === "object" &&
|
|
140
|
+
data !== null &&
|
|
141
|
+
"errors" in data &&
|
|
142
|
+
Array.isArray(data.errors)
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Helper to check if data has API errors
|
|
147
|
+
private isApiErrorArray(dataArray: unknown[]): dataArray is ApiError[] {
|
|
148
|
+
const data = dataArray[0];
|
|
149
|
+
return (
|
|
150
|
+
typeof data === "object" &&
|
|
151
|
+
data !== null &&
|
|
152
|
+
"message" in data &&
|
|
153
|
+
"code" in data &&
|
|
154
|
+
"title" in data &&
|
|
155
|
+
"detail" in data
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Do our best to extract an error message from the response data
|
|
160
|
+
private extractErrorMessage<TOutput = unknown>(
|
|
161
|
+
data: TOutput | string,
|
|
162
|
+
): string | undefined {
|
|
163
|
+
if (typeof data === "string") {
|
|
164
|
+
return data;
|
|
165
|
+
}
|
|
166
|
+
if (typeof data === "object" && data !== null) {
|
|
167
|
+
if ("message" in data && typeof data.message === "string") {
|
|
168
|
+
return data.message;
|
|
169
|
+
}
|
|
170
|
+
if ("error" in data) {
|
|
171
|
+
if (typeof data.error === "string") {
|
|
172
|
+
return data.error;
|
|
173
|
+
}
|
|
174
|
+
if (typeof data.error === "object" && data.error !== null) {
|
|
175
|
+
if (
|
|
176
|
+
"message" in data.error &&
|
|
177
|
+
typeof data.error.message === "string"
|
|
178
|
+
) {
|
|
179
|
+
return data.error.message;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
try {
|
|
183
|
+
return JSON.stringify(data.error);
|
|
184
|
+
} catch {
|
|
185
|
+
/* defend against circular objects, even though they shouldn't be coming back from the wire */
|
|
122
186
|
}
|
|
123
187
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
`Authentication required (HTTP ${response.status}). Please provide a token in options or set ZAPIER_TOKEN environment variable.`,
|
|
129
|
-
);
|
|
188
|
+
if ("errors" in data && Array.isArray(data.errors)) {
|
|
189
|
+
if (this.isApiErrorArray(data.errors)) {
|
|
190
|
+
return data.errors[0].detail || data.errors[0].title;
|
|
191
|
+
}
|
|
130
192
|
}
|
|
131
|
-
|
|
132
|
-
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
133
193
|
}
|
|
194
|
+
return undefined;
|
|
195
|
+
}
|
|
134
196
|
|
|
135
|
-
|
|
197
|
+
// Helper to parse API error response
|
|
198
|
+
private parseErrorResponse<TOutput = unknown>(errorInfo: {
|
|
199
|
+
status: number;
|
|
200
|
+
statusText: string;
|
|
201
|
+
data: TOutput | string;
|
|
202
|
+
}): { message: string; errors?: ApiError[] } {
|
|
203
|
+
// If we can't parse data, use status text
|
|
204
|
+
const fallbackMessage = `HTTP ${errorInfo.status}: ${errorInfo.statusText}`;
|
|
136
205
|
try {
|
|
137
|
-
|
|
206
|
+
// Check if the response has the standard error format
|
|
207
|
+
if (typeof errorInfo.data === "string") {
|
|
208
|
+
return { message: `${fallbackMessage}: ${errorInfo.data}` };
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const errorMessage =
|
|
212
|
+
this.extractErrorMessage(errorInfo.data) || fallbackMessage;
|
|
213
|
+
|
|
214
|
+
if (this.hasErrorArray(errorInfo.data)) {
|
|
215
|
+
if (this.isApiErrorArray(errorInfo.data.errors)) {
|
|
216
|
+
return {
|
|
217
|
+
message: errorMessage,
|
|
218
|
+
errors: errorInfo.data.errors,
|
|
219
|
+
};
|
|
220
|
+
} else {
|
|
221
|
+
return {
|
|
222
|
+
message: errorMessage,
|
|
223
|
+
errors: errorInfo.data.errors.map((e) => ({
|
|
224
|
+
status: errorInfo.status,
|
|
225
|
+
code: String(errorInfo.status),
|
|
226
|
+
title: errorInfo.statusText,
|
|
227
|
+
detail: JSON.stringify(e),
|
|
228
|
+
})),
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return { message: errorMessage };
|
|
138
234
|
} catch {
|
|
139
|
-
return
|
|
235
|
+
return { message: fallbackMessage };
|
|
140
236
|
}
|
|
141
237
|
}
|
|
142
238
|
|
|
143
|
-
//
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
if (
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
239
|
+
// Check if this is a path that needs subdomain routing
|
|
240
|
+
// e.g. /relay/workflows -> relay.zapier.com/workflows
|
|
241
|
+
private applySubdomainBehavior(path: string): {
|
|
242
|
+
url: URL;
|
|
243
|
+
subdomainConfig?: SubdomainConfig;
|
|
244
|
+
} {
|
|
245
|
+
const pathSegments = path.split("/").filter(Boolean);
|
|
246
|
+
|
|
247
|
+
if (pathSegments.length > 0 && pathSegments[0] in SubdomainConfigMap) {
|
|
248
|
+
// Transform paths to use subdomain routing
|
|
249
|
+
// /prefix/domain/path -> prefix.zapier.com/domain/path
|
|
250
|
+
const domainPrefix = pathSegments[0] as keyof typeof SubdomainConfigMap;
|
|
251
|
+
const subdomainConfig = SubdomainConfigMap[domainPrefix];
|
|
252
|
+
const originalBaseUrl = new URL(this.options.baseUrl);
|
|
253
|
+
const finalBaseUrl = `https://${domainPrefix}.${originalBaseUrl.hostname}`;
|
|
254
|
+
const pathWithoutPrefix = "/" + pathSegments.slice(1).join("/");
|
|
255
|
+
return { url: new URL(pathWithoutPrefix, finalBaseUrl), subdomainConfig };
|
|
155
256
|
}
|
|
156
257
|
|
|
157
|
-
|
|
258
|
+
return {
|
|
259
|
+
url: new URL(path, this.options.baseUrl),
|
|
260
|
+
subdomainConfig: undefined,
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// Helper to build full URLs and return routing info
|
|
265
|
+
private buildUrl(
|
|
266
|
+
path: string,
|
|
267
|
+
searchParams?: Record<string, string>,
|
|
268
|
+
): {
|
|
269
|
+
url: string;
|
|
270
|
+
subdomainConfig?: SubdomainConfig;
|
|
271
|
+
} {
|
|
272
|
+
const { url, subdomainConfig } = this.applySubdomainBehavior(path);
|
|
273
|
+
if (searchParams) {
|
|
274
|
+
Object.entries(searchParams).forEach(([key, value]) => {
|
|
275
|
+
url.searchParams.set(key, value);
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
return { url: url.toString(), subdomainConfig };
|
|
279
|
+
}
|
|
158
280
|
|
|
159
|
-
|
|
281
|
+
// Helper to build headers
|
|
282
|
+
private async buildHeaders(
|
|
283
|
+
options: RequestOptions = {},
|
|
284
|
+
subdomainConfig?: (typeof SubdomainConfigMap)[keyof typeof SubdomainConfigMap],
|
|
285
|
+
): Promise<Headers> {
|
|
286
|
+
const headers = new Headers(options.headers ?? {});
|
|
287
|
+
|
|
288
|
+
// Even if auth is not required, we still want to add it in case it adds
|
|
289
|
+
// useful context to the API. The session is a good example of this. Auth
|
|
290
|
+
// is not required, but if we don't add auth, then we won't get the user's
|
|
291
|
+
// session!
|
|
292
|
+
const authToken = await this.getAuthToken();
|
|
293
|
+
|
|
294
|
+
if (authToken) {
|
|
295
|
+
const authHeaderName = subdomainConfig?.authHeader || "Authorization";
|
|
296
|
+
headers.set(authHeaderName, getAuthorizationHeader(authToken));
|
|
297
|
+
}
|
|
160
298
|
|
|
161
|
-
//
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}
|
|
299
|
+
// If we know auth is required, and we don't have a token, throw an error
|
|
300
|
+
// before we even make a request.
|
|
301
|
+
if (options.authRequired) {
|
|
302
|
+
if (headers.get("Authorization") == null && authToken == null) {
|
|
303
|
+
throw new ZapierAuthenticationError(
|
|
304
|
+
`Authentication required but no token available. Please set ZAPIER_TOKEN, or run the 'login' command with the CLI.`,
|
|
305
|
+
);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
170
308
|
|
|
171
|
-
return
|
|
172
|
-
...init,
|
|
173
|
-
headers: finalHeaders,
|
|
174
|
-
});
|
|
309
|
+
return headers;
|
|
175
310
|
}
|
|
176
311
|
|
|
177
312
|
// Helper to perform HTTP requests with JSON handling
|
|
178
|
-
async
|
|
313
|
+
private async fetchJson<TOutput = unknown>(
|
|
179
314
|
method: string,
|
|
180
315
|
path: string,
|
|
181
|
-
data?:
|
|
316
|
+
data?: TOutput,
|
|
182
317
|
options: RequestOptions = {},
|
|
183
|
-
): Promise<
|
|
318
|
+
): Promise<TOutput> {
|
|
184
319
|
const headers = { ...options.headers };
|
|
185
320
|
|
|
186
321
|
// Add Content-Type for JSON requests with body data
|
|
@@ -188,68 +323,156 @@ export function createZapierApi(options: ApiClientOptions): ApiClient {
|
|
|
188
323
|
headers["Content-Type"] = "application/json";
|
|
189
324
|
}
|
|
190
325
|
|
|
191
|
-
|
|
326
|
+
// Check if we have an auth token available
|
|
327
|
+
const wasMissingAuthToken =
|
|
328
|
+
options.authRequired && (await this.getAuthToken()) == null;
|
|
329
|
+
|
|
330
|
+
const response = await this.plainFetch(path, {
|
|
331
|
+
...options,
|
|
192
332
|
method,
|
|
193
|
-
body: data ? JSON.stringify(data) : undefined,
|
|
333
|
+
body: data != null ? JSON.stringify(data) : undefined,
|
|
194
334
|
headers,
|
|
195
|
-
searchParams: options.searchParams,
|
|
196
|
-
authRequired: options.authRequired,
|
|
197
335
|
});
|
|
198
336
|
|
|
199
337
|
// plainFetch already handled all auth and headers
|
|
200
|
-
|
|
338
|
+
const result = await this.handleResponse<TOutput>({
|
|
339
|
+
response,
|
|
340
|
+
customErrorHandler: options.customErrorHandler,
|
|
341
|
+
wasMissingAuthToken,
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
if (typeof result === "string") {
|
|
345
|
+
throw new ZapierValidationError(
|
|
346
|
+
`Response could not be parsed as JSON: ${result}`,
|
|
347
|
+
);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
return result;
|
|
201
351
|
}
|
|
202
352
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
353
|
+
// Plain fetch method for API paths (must start with /)
|
|
354
|
+
private async plainFetch(
|
|
355
|
+
path: string,
|
|
356
|
+
fetchOptions?: RequestInit & {
|
|
357
|
+
searchParams?: Record<string, string>;
|
|
358
|
+
authRequired?: boolean;
|
|
206
359
|
},
|
|
360
|
+
): Promise<Response> {
|
|
361
|
+
if (!path.startsWith("/")) {
|
|
362
|
+
throw new ZapierValidationError(
|
|
363
|
+
`plainFetch expects a path starting with '/', got: ${path}`,
|
|
364
|
+
);
|
|
365
|
+
}
|
|
207
366
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
options: RequestOptions = {},
|
|
212
|
-
): Promise<any> {
|
|
213
|
-
return fetchJson("POST", path, data, options);
|
|
214
|
-
},
|
|
367
|
+
if (fetchOptions?.body && typeof fetchOptions.body === "object") {
|
|
368
|
+
fetchOptions.body = JSON.stringify(fetchOptions.body);
|
|
369
|
+
}
|
|
215
370
|
|
|
216
|
-
|
|
217
|
-
path
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
): Promise<any> {
|
|
221
|
-
return fetchJson("PUT", path, data, options);
|
|
222
|
-
},
|
|
371
|
+
const { url, subdomainConfig } = this.buildUrl(
|
|
372
|
+
path,
|
|
373
|
+
fetchOptions?.searchParams,
|
|
374
|
+
);
|
|
223
375
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
376
|
+
const builtHeaders = await this.buildHeaders(
|
|
377
|
+
fetchOptions as RequestOptions,
|
|
378
|
+
subdomainConfig,
|
|
379
|
+
);
|
|
380
|
+
const inputHeaders = new Headers(fetchOptions?.headers ?? {});
|
|
227
381
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
resultExtractor: options.resultExtractor,
|
|
242
|
-
});
|
|
243
|
-
},
|
|
382
|
+
const mergedHeaders = new Headers();
|
|
383
|
+
builtHeaders.forEach((value, key) => {
|
|
384
|
+
mergedHeaders.set(key, value);
|
|
385
|
+
});
|
|
386
|
+
inputHeaders.forEach((value, key) => {
|
|
387
|
+
mergedHeaders.set(key, value);
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
return await this.options.fetch(url, {
|
|
391
|
+
...fetchOptions,
|
|
392
|
+
headers: mergedHeaders,
|
|
393
|
+
});
|
|
394
|
+
}
|
|
244
395
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
},
|
|
251
|
-
): Promise<Response> {
|
|
252
|
-
return plainFetch(path, init);
|
|
396
|
+
public fetch = async (
|
|
397
|
+
path: string,
|
|
398
|
+
init?: RequestInit & {
|
|
399
|
+
searchParams?: Record<string, string>;
|
|
400
|
+
authRequired?: boolean;
|
|
253
401
|
},
|
|
402
|
+
): Promise<Response> => {
|
|
403
|
+
return this.plainFetch(path, init);
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
public get = async <TOutput = unknown>(
|
|
407
|
+
path: string,
|
|
408
|
+
options: RequestOptions = {},
|
|
409
|
+
): Promise<TOutput> => {
|
|
410
|
+
return this.fetchJson<TOutput>("GET", path, undefined, options);
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
public post = async <TOutput = unknown>(
|
|
414
|
+
path: string,
|
|
415
|
+
data?: TOutput,
|
|
416
|
+
options: RequestOptions = {},
|
|
417
|
+
): Promise<TOutput> => {
|
|
418
|
+
return this.fetchJson<TOutput>("POST", path, data, options);
|
|
419
|
+
};
|
|
420
|
+
|
|
421
|
+
public put = async <TOutput = unknown>(
|
|
422
|
+
path: string,
|
|
423
|
+
data?: TOutput,
|
|
424
|
+
options: RequestOptions = {},
|
|
425
|
+
): Promise<TOutput> => {
|
|
426
|
+
return this.fetchJson<TOutput>("PUT", path, data, options);
|
|
427
|
+
};
|
|
428
|
+
|
|
429
|
+
public delete = async <TOutput = unknown>(
|
|
430
|
+
path: string,
|
|
431
|
+
options: RequestOptions = {},
|
|
432
|
+
): Promise<TOutput> => {
|
|
433
|
+
return this.fetchJson<TOutput>("DELETE", path, undefined, options);
|
|
434
|
+
};
|
|
435
|
+
|
|
436
|
+
public poll = async <TOutput = unknown>(
|
|
437
|
+
path: string,
|
|
438
|
+
options: PollOptions = {},
|
|
439
|
+
): Promise<TOutput> => {
|
|
440
|
+
return pollUntilComplete({
|
|
441
|
+
fetchPoll: () =>
|
|
442
|
+
this.plainFetch(path, {
|
|
443
|
+
method: "GET",
|
|
444
|
+
searchParams: options.searchParams,
|
|
445
|
+
authRequired: options.authRequired,
|
|
446
|
+
}),
|
|
447
|
+
maxAttempts: options.maxAttempts,
|
|
448
|
+
initialDelay: options.initialDelay,
|
|
449
|
+
maxDelay: options.maxDelay,
|
|
450
|
+
successStatus: options.successStatus,
|
|
451
|
+
pendingStatus: options.pendingStatus,
|
|
452
|
+
resultExtractor: options.resultExtractor,
|
|
453
|
+
});
|
|
254
454
|
};
|
|
255
455
|
}
|
|
456
|
+
|
|
457
|
+
export const createZapierApi = (options: ApiClientOptions): ApiClient => {
|
|
458
|
+
const {
|
|
459
|
+
baseUrl,
|
|
460
|
+
token,
|
|
461
|
+
getToken,
|
|
462
|
+
debug = false,
|
|
463
|
+
fetch: originalFetch = globalThis.fetch,
|
|
464
|
+
onEvent,
|
|
465
|
+
} = options;
|
|
466
|
+
|
|
467
|
+
const debugLog = createDebugLogger(debug);
|
|
468
|
+
const debugFetch = createDebugFetch({ originalFetch, debugLog });
|
|
469
|
+
|
|
470
|
+
return new ZapierApiClient({
|
|
471
|
+
baseUrl,
|
|
472
|
+
token,
|
|
473
|
+
getToken,
|
|
474
|
+
debug,
|
|
475
|
+
fetch: debugFetch,
|
|
476
|
+
onEvent,
|
|
477
|
+
});
|
|
478
|
+
};
|