@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/dist/index.cjs
CHANGED
|
@@ -2,22 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var zod = require('zod');
|
|
4
4
|
|
|
5
|
-
// src/types/
|
|
6
|
-
var ZapierSdkError = class extends Error {
|
|
7
|
-
constructor(message, code) {
|
|
8
|
-
super(message);
|
|
9
|
-
this.code = code;
|
|
10
|
-
this.name = "ZapierSdkError";
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
var AppNotFoundError = class extends ZapierSdkError {
|
|
14
|
-
constructor(appKey) {
|
|
15
|
-
super(`App "${appKey}" not found`);
|
|
16
|
-
this.name = "AppNotFoundError";
|
|
17
|
-
this.code = "APP_NOT_FOUND";
|
|
18
|
-
this.appKey = appKey;
|
|
19
|
-
}
|
|
20
|
-
};
|
|
5
|
+
// src/types/properties.ts
|
|
21
6
|
function withFormatter(schema, formatMeta) {
|
|
22
7
|
schema._def.formatMeta = formatMeta;
|
|
23
8
|
return schema;
|
|
@@ -43,9 +28,12 @@ function isPositional(schema) {
|
|
|
43
28
|
return false;
|
|
44
29
|
}
|
|
45
30
|
|
|
31
|
+
// src/constants.ts
|
|
32
|
+
var MAX_PAGE_LIMIT = 1e4;
|
|
33
|
+
|
|
46
34
|
// src/types/properties.ts
|
|
47
35
|
var AppKeyPropertySchema = withPositional(
|
|
48
|
-
zod.z.string().min(1).describe("App
|
|
36
|
+
zod.z.string().min(1).describe("App key (e.g., 'SlackCLIAPI')")
|
|
49
37
|
);
|
|
50
38
|
var ActionTypePropertySchema = zod.z.enum([
|
|
51
39
|
"read",
|
|
@@ -60,20 +48,155 @@ var ActionTypePropertySchema = zod.z.enum([
|
|
|
60
48
|
var ActionKeyPropertySchema = zod.z.string().min(1).describe("Action key to execute");
|
|
61
49
|
var AuthenticationIdPropertySchema = zod.z.number().int().describe("Authentication ID to use for this action");
|
|
62
50
|
var InputsPropertySchema = zod.z.record(zod.z.any()).describe("Input parameters for the action");
|
|
63
|
-
var LimitPropertySchema = zod.z.number().int().min(1).max(
|
|
51
|
+
var LimitPropertySchema = zod.z.number().int().min(1).max(MAX_PAGE_LIMIT).default(50).describe("Maximum number of items to return");
|
|
64
52
|
var OffsetPropertySchema = zod.z.number().int().min(0).default(0).describe("Number of items to skip for pagination");
|
|
65
53
|
var OutputPropertySchema = zod.z.string().describe("Output file path");
|
|
66
54
|
var DebugPropertySchema = zod.z.boolean().default(false).describe("Enable debug logging");
|
|
67
55
|
var ParamsPropertySchema = zod.z.record(zod.z.any()).describe("Additional parameters");
|
|
68
56
|
|
|
57
|
+
// src/types/errors.ts
|
|
58
|
+
var ZapierError = class extends Error {
|
|
59
|
+
constructor(message, options = {}) {
|
|
60
|
+
super(message);
|
|
61
|
+
this.statusCode = options.statusCode;
|
|
62
|
+
this.errors = options.errors;
|
|
63
|
+
this.cause = options.cause;
|
|
64
|
+
this.response = options.response;
|
|
65
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
var ZapierApiError = class extends ZapierError {
|
|
69
|
+
constructor(message, options = {}) {
|
|
70
|
+
super(message, options);
|
|
71
|
+
this.name = "ZapierApiError";
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
var ZapierAppNotFoundError = class extends ZapierError {
|
|
75
|
+
constructor(message, options = {}) {
|
|
76
|
+
super(message, options);
|
|
77
|
+
this.name = "ZapierAppNotFoundError";
|
|
78
|
+
this.appKey = options.appKey;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
var ZapierValidationError = class extends ZapierError {
|
|
82
|
+
constructor(message, options = {}) {
|
|
83
|
+
super(message, options);
|
|
84
|
+
this.name = "ZapierValidationError";
|
|
85
|
+
this.details = options.details;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
var ZapierUnknownError = class extends ZapierError {
|
|
89
|
+
constructor(message, options = {}) {
|
|
90
|
+
super(message, options);
|
|
91
|
+
this.name = "ZapierUnknownError";
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
var ZapierAuthenticationError = class extends ZapierError {
|
|
95
|
+
constructor(message, options = {}) {
|
|
96
|
+
super(message, options);
|
|
97
|
+
this.name = "ZapierAuthenticationError";
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
var ZapierResourceNotFoundError = class extends ZapierError {
|
|
101
|
+
constructor(message, options = {}) {
|
|
102
|
+
super(message, options);
|
|
103
|
+
this.name = "ZapierResourceNotFoundError";
|
|
104
|
+
this.resourceType = options.resourceType;
|
|
105
|
+
this.resourceId = options.resourceId;
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
var ZapierConfigurationError = class extends ZapierError {
|
|
109
|
+
constructor(message, options = {}) {
|
|
110
|
+
super(message, options);
|
|
111
|
+
this.name = "ZapierConfigurationError";
|
|
112
|
+
this.configType = options.configType;
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
var ZapierBundleError = class extends ZapierError {
|
|
116
|
+
constructor(message, options = {}) {
|
|
117
|
+
super(message, options);
|
|
118
|
+
this.name = "ZapierBundleError";
|
|
119
|
+
this.buildErrors = options.buildErrors;
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
var ZapierTimeoutError = class extends ZapierError {
|
|
123
|
+
constructor(message, options = {}) {
|
|
124
|
+
super(message, options);
|
|
125
|
+
this.name = "ZapierTimeoutError";
|
|
126
|
+
this.attempts = options.attempts;
|
|
127
|
+
this.maxAttempts = options.maxAttempts;
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
var ZapierActionError = class extends ZapierError {
|
|
131
|
+
constructor(message, options = {}) {
|
|
132
|
+
super(message, options);
|
|
133
|
+
this.name = "ZapierActionError";
|
|
134
|
+
this.appKey = options.appKey;
|
|
135
|
+
this.actionKey = options.actionKey;
|
|
136
|
+
}
|
|
137
|
+
// Legacy accessor for backward compatibility
|
|
138
|
+
get actionErrors() {
|
|
139
|
+
return this.errors;
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
var ZapierNotFoundError = class extends ZapierError {
|
|
143
|
+
constructor(message, options = {}) {
|
|
144
|
+
super(message, options);
|
|
145
|
+
this.name = "ZapierNotFoundError";
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
function formatErrorMessage(error) {
|
|
149
|
+
let message = error.message;
|
|
150
|
+
if (error.errors && error.errors.length > 0) {
|
|
151
|
+
const additionalErrors = error.errors.slice(1);
|
|
152
|
+
if (additionalErrors.length > 0) {
|
|
153
|
+
const errorDetails = additionalErrors.map((err) => ` \u2022 ${err.detail || err.title || err.code}`).join("\n");
|
|
154
|
+
message += "\n\nAdditional errors:\n" + errorDetails;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (error instanceof ZapierAppNotFoundError && error.appKey) {
|
|
158
|
+
message += `
|
|
159
|
+
App key: ${error.appKey}`;
|
|
160
|
+
}
|
|
161
|
+
if (error instanceof ZapierActionError && (error.appKey || error.actionKey)) {
|
|
162
|
+
const context = [];
|
|
163
|
+
if (error.appKey) context.push(`App: ${error.appKey}`);
|
|
164
|
+
if (error.actionKey) context.push(`Action: ${error.actionKey}`);
|
|
165
|
+
message += `
|
|
166
|
+
${context.join(", ")}`;
|
|
167
|
+
}
|
|
168
|
+
if (error instanceof ZapierResourceNotFoundError && (error.resourceType || error.resourceId)) {
|
|
169
|
+
const context = [];
|
|
170
|
+
if (error.resourceType) context.push(`Type: ${error.resourceType}`);
|
|
171
|
+
if (error.resourceId) context.push(`ID: ${error.resourceId}`);
|
|
172
|
+
message += `
|
|
173
|
+
${context.join(", ")}`;
|
|
174
|
+
}
|
|
175
|
+
if (error instanceof ZapierTimeoutError && (error.attempts || error.maxAttempts)) {
|
|
176
|
+
const context = [];
|
|
177
|
+
if (error.attempts) context.push(`Attempts: ${error.attempts}`);
|
|
178
|
+
if (error.maxAttempts) context.push(`Max attempts: ${error.maxAttempts}`);
|
|
179
|
+
message += `
|
|
180
|
+
${context.join(", ")}`;
|
|
181
|
+
}
|
|
182
|
+
if (error instanceof ZapierBundleError && error.buildErrors && error.buildErrors.length > 0) {
|
|
183
|
+
message += "\n\nBuild errors:\n" + error.buildErrors.map((err) => ` \u2022 ${err}`).join("\n");
|
|
184
|
+
}
|
|
185
|
+
if (error.statusCode && !message.includes(`${error.statusCode}`)) {
|
|
186
|
+
message += `
|
|
187
|
+
HTTP Status: ${error.statusCode}`;
|
|
188
|
+
}
|
|
189
|
+
return message;
|
|
190
|
+
}
|
|
191
|
+
|
|
69
192
|
// src/plugins/apps/index.ts
|
|
70
193
|
function createActionFunction(appKey, actionType, actionKey, options, pinnedAuthId) {
|
|
71
|
-
return
|
|
194
|
+
return (actionOptions = {}) => {
|
|
72
195
|
const { sdk } = options;
|
|
73
196
|
const { inputs, authenticationId: providedAuthenticationId } = actionOptions;
|
|
74
197
|
const authenticationId = pinnedAuthId || providedAuthenticationId;
|
|
75
198
|
if (!authenticationId) {
|
|
76
|
-
throw new
|
|
199
|
+
throw new ZapierValidationError(
|
|
77
200
|
`Authentication ID is required. Either use the factory pattern: sdk.apps.${appKey}({ authenticationId }) or provide authenticationId in the action call.`
|
|
78
201
|
);
|
|
79
202
|
}
|
|
@@ -92,7 +215,7 @@ function createActionTypeProxy(appKey, actionType, options, pinnedAuthId) {
|
|
|
92
215
|
const { sdk } = options;
|
|
93
216
|
const authenticationId = pinnedAuthId || init?.authenticationId;
|
|
94
217
|
if (!authenticationId) {
|
|
95
|
-
throw new
|
|
218
|
+
throw new ZapierValidationError(
|
|
96
219
|
`Authentication ID is required for fetch. Either use the factory pattern: sdk.apps.${appKey}({ authenticationId }).fetch(...) or provide authenticationId in the fetch call.`
|
|
97
220
|
);
|
|
98
221
|
}
|
|
@@ -166,57 +289,40 @@ function createAppsProxy(options) {
|
|
|
166
289
|
});
|
|
167
290
|
return appsProxy;
|
|
168
291
|
}
|
|
169
|
-
|
|
170
|
-
return
|
|
171
|
-
}
|
|
292
|
+
var appsPlugin = ({ sdk }) => {
|
|
293
|
+
return {
|
|
294
|
+
apps: createAppsProxy({ sdk })
|
|
295
|
+
};
|
|
296
|
+
};
|
|
172
297
|
|
|
173
298
|
// src/plugins/fetch/index.ts
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
299
|
+
var fetchPlugin = ({ sdk }) => {
|
|
300
|
+
return {
|
|
301
|
+
fetch: async function fetch(url, init) {
|
|
302
|
+
const {
|
|
303
|
+
authenticationId,
|
|
304
|
+
callbackUrl,
|
|
305
|
+
authenticationTemplate,
|
|
306
|
+
...fetchInit
|
|
307
|
+
} = init || {};
|
|
308
|
+
return sdk.request({
|
|
309
|
+
url: url.toString(),
|
|
310
|
+
method: fetchInit.method,
|
|
311
|
+
body: fetchInit.body,
|
|
312
|
+
headers: fetchInit.headers,
|
|
313
|
+
authenticationId,
|
|
314
|
+
callbackUrl,
|
|
315
|
+
authenticationTemplate
|
|
316
|
+
});
|
|
317
|
+
}
|
|
192
318
|
};
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
// src/auth.ts
|
|
196
|
-
function getTokenFromEnv() {
|
|
197
|
-
return process.env.ZAPIER_TOKEN;
|
|
198
|
-
}
|
|
199
|
-
async function getTokenFromCliLogin(options = {}) {
|
|
200
|
-
try {
|
|
201
|
-
const { getToken } = await import('@zapier/zapier-sdk-cli-login');
|
|
202
|
-
return await getToken(options);
|
|
203
|
-
} catch {
|
|
204
|
-
return void 0;
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
async function getTokenFromEnvOrConfig(options = {}) {
|
|
208
|
-
const envToken = getTokenFromEnv();
|
|
209
|
-
if (envToken) {
|
|
210
|
-
return envToken;
|
|
211
|
-
}
|
|
212
|
-
return getTokenFromCliLogin(options);
|
|
213
|
-
}
|
|
319
|
+
};
|
|
214
320
|
|
|
215
321
|
// src/resolvers/appKey.ts
|
|
216
322
|
var appKeyResolver = {
|
|
217
323
|
type: "static",
|
|
218
324
|
inputType: "text",
|
|
219
|
-
placeholder: "Enter app
|
|
325
|
+
placeholder: "Enter app key (e.g., 'SlackCLIAPI' or slug like 'github')"
|
|
220
326
|
};
|
|
221
327
|
|
|
222
328
|
// src/resolvers/actionType.ts
|
|
@@ -224,8 +330,12 @@ var actionTypeResolver = {
|
|
|
224
330
|
type: "dynamic",
|
|
225
331
|
depends: ["appKey"],
|
|
226
332
|
fetch: async (sdk, resolvedParams) => {
|
|
227
|
-
const
|
|
228
|
-
|
|
333
|
+
const actionsResponse = await sdk.listActions({
|
|
334
|
+
appKey: resolvedParams.appKey
|
|
335
|
+
});
|
|
336
|
+
const types = [
|
|
337
|
+
...new Set(actionsResponse.data.map((action) => action.action_type))
|
|
338
|
+
];
|
|
229
339
|
return types.map((type) => ({ key: type, name: type }));
|
|
230
340
|
},
|
|
231
341
|
prompt: (types) => ({
|
|
@@ -244,9 +354,11 @@ var actionKeyResolver = {
|
|
|
244
354
|
type: "dynamic",
|
|
245
355
|
depends: ["appKey", "actionType"],
|
|
246
356
|
fetch: async (sdk, resolvedParams) => {
|
|
247
|
-
const
|
|
248
|
-
|
|
249
|
-
|
|
357
|
+
const actionsResponse = await sdk.listActions({
|
|
358
|
+
appKey: resolvedParams.appKey
|
|
359
|
+
});
|
|
360
|
+
return actionsResponse.data.filter(
|
|
361
|
+
(action) => action.action_type === resolvedParams.actionType
|
|
250
362
|
);
|
|
251
363
|
},
|
|
252
364
|
prompt: (actions) => ({
|
|
@@ -254,7 +366,7 @@ var actionKeyResolver = {
|
|
|
254
366
|
name: "actionKey",
|
|
255
367
|
message: "Select action:",
|
|
256
368
|
choices: actions.map((action) => ({
|
|
257
|
-
name: `${action.name || action.key} - ${action.description || "No description"}`,
|
|
369
|
+
name: `${action.title || action.name || action.key} - ${action.description || "No description"}`,
|
|
258
370
|
value: action.key
|
|
259
371
|
}))
|
|
260
372
|
})
|
|
@@ -265,10 +377,19 @@ var authenticationIdResolver = {
|
|
|
265
377
|
type: "dynamic",
|
|
266
378
|
depends: ["appKey"],
|
|
267
379
|
fetch: async (sdk, resolvedParams) => {
|
|
268
|
-
|
|
380
|
+
const myAuths = await sdk.listAuthentications({
|
|
381
|
+
appKey: resolvedParams.appKey,
|
|
382
|
+
maxItems: 1e3,
|
|
383
|
+
owner: "me"
|
|
384
|
+
});
|
|
385
|
+
const allAuths = await sdk.listAuthentications({
|
|
269
386
|
appKey: resolvedParams.appKey,
|
|
270
|
-
|
|
387
|
+
maxItems: 1e3
|
|
271
388
|
});
|
|
389
|
+
const otherAuths = allAuths.data.filter(
|
|
390
|
+
(auth) => !myAuths.data.some((myAuth) => myAuth.id === auth.id)
|
|
391
|
+
);
|
|
392
|
+
return [...myAuths.data, ...otherAuths];
|
|
272
393
|
},
|
|
273
394
|
prompt: (auths, params) => ({
|
|
274
395
|
type: "list",
|
|
@@ -292,12 +413,15 @@ var inputsResolver = {
|
|
|
292
413
|
type: "fields",
|
|
293
414
|
depends: ["appKey", "actionKey", "actionType", "authenticationId"],
|
|
294
415
|
fetch: async (sdk, resolvedParams) => {
|
|
295
|
-
|
|
416
|
+
const fieldsResponse = await sdk.listInputFields({
|
|
296
417
|
appKey: resolvedParams.appKey,
|
|
297
418
|
actionKey: resolvedParams.actionKey,
|
|
298
419
|
actionType: resolvedParams.actionType,
|
|
299
|
-
authenticationId: resolvedParams.authenticationId
|
|
420
|
+
authenticationId: resolvedParams.authenticationId,
|
|
421
|
+
inputs: resolvedParams.inputs
|
|
422
|
+
// Pass along currently resolved inputs
|
|
300
423
|
});
|
|
424
|
+
return fieldsResponse.data;
|
|
301
425
|
}
|
|
302
426
|
};
|
|
303
427
|
|
|
@@ -362,6 +486,59 @@ function getResolutionOrderForParams(paramNames) {
|
|
|
362
486
|
return order;
|
|
363
487
|
}
|
|
364
488
|
|
|
489
|
+
// src/auth.ts
|
|
490
|
+
function getTokenFromEnv() {
|
|
491
|
+
return process.env.ZAPIER_TOKEN;
|
|
492
|
+
}
|
|
493
|
+
async function getTokenFromCliLogin(options = {}) {
|
|
494
|
+
try {
|
|
495
|
+
const { getToken } = await import('@zapier/zapier-sdk-cli-login');
|
|
496
|
+
return await getToken(options);
|
|
497
|
+
} catch {
|
|
498
|
+
return void 0;
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
async function getTokenFromEnvOrConfig(options = {}) {
|
|
502
|
+
const envToken = getTokenFromEnv();
|
|
503
|
+
if (envToken) {
|
|
504
|
+
return envToken;
|
|
505
|
+
}
|
|
506
|
+
return getTokenFromCliLogin(options);
|
|
507
|
+
}
|
|
508
|
+
var RelayRequestSchema = zod.z.object({
|
|
509
|
+
url: zod.z.string().url().describe("The URL to request (will be proxied through Relay)"),
|
|
510
|
+
method: zod.z.enum(["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"]).optional().describe("HTTP method"),
|
|
511
|
+
body: zod.z.any().optional().describe("Request body as a string"),
|
|
512
|
+
authenticationId: zod.z.number().int().optional().describe("Zapier authentication ID to use for the request"),
|
|
513
|
+
callbackUrl: zod.z.string().url().optional().describe("URL to send async response to (makes request async)"),
|
|
514
|
+
authenticationTemplate: zod.z.string().optional().describe(
|
|
515
|
+
"Optional JSON string authentication template to bypass Notary lookup"
|
|
516
|
+
),
|
|
517
|
+
headers: zod.z.union([
|
|
518
|
+
zod.z.record(zod.z.string()),
|
|
519
|
+
zod.z.instanceof(Headers),
|
|
520
|
+
zod.z.array(zod.z.tuple([zod.z.string(), zod.z.string()]))
|
|
521
|
+
]).optional().describe("Request headers")
|
|
522
|
+
}).extend({
|
|
523
|
+
relayBaseUrl: zod.z.string().optional().describe("Base URL for Relay service")
|
|
524
|
+
}).describe("Make authenticated HTTP requests through Zapier's Relay service");
|
|
525
|
+
var RelayFetchSchema = RelayRequestSchema;
|
|
526
|
+
|
|
527
|
+
// src/plugins/registry/index.ts
|
|
528
|
+
var registryPlugin = ({ sdk, context }) => {
|
|
529
|
+
const metaKeys = Object.keys(context.meta || {});
|
|
530
|
+
const registryEntries = metaKeys.map((key) => {
|
|
531
|
+
return {
|
|
532
|
+
...context.meta[key],
|
|
533
|
+
name: key,
|
|
534
|
+
implementation: sdk[key]
|
|
535
|
+
};
|
|
536
|
+
});
|
|
537
|
+
return {
|
|
538
|
+
__registry: registryEntries
|
|
539
|
+
};
|
|
540
|
+
};
|
|
541
|
+
|
|
365
542
|
// src/api/auth.ts
|
|
366
543
|
function isJwt(token) {
|
|
367
544
|
const parts = token.split(".");
|
|
@@ -396,7 +573,13 @@ function createDebugFetch(options) {
|
|
|
396
573
|
const method = options2?.method || "GET";
|
|
397
574
|
debugLog(`\u2192 ${method} ${url}`, {
|
|
398
575
|
headers: options2?.headers,
|
|
399
|
-
body: options2?.body
|
|
576
|
+
body: options2?.body && typeof options2.body === "string" ? (() => {
|
|
577
|
+
try {
|
|
578
|
+
return JSON.parse(options2.body);
|
|
579
|
+
} catch {
|
|
580
|
+
return options2.body;
|
|
581
|
+
}
|
|
582
|
+
})() : options2?.body
|
|
400
583
|
});
|
|
401
584
|
try {
|
|
402
585
|
const response = await originalFetch(input, options2);
|
|
@@ -431,1168 +614,1360 @@ async function pollUntilComplete(options) {
|
|
|
431
614
|
resultExtractor = (response) => response
|
|
432
615
|
} = options;
|
|
433
616
|
let delay = initialDelay;
|
|
617
|
+
let errorCount = 0;
|
|
434
618
|
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
435
619
|
const response = await fetchPoll();
|
|
436
620
|
if (response.status === successStatus) {
|
|
621
|
+
errorCount = 0;
|
|
437
622
|
const result = await response.json();
|
|
438
623
|
return resultExtractor(result);
|
|
439
624
|
} else if (response.status === pendingStatus) {
|
|
625
|
+
errorCount = 0;
|
|
440
626
|
if (attempt < maxAttempts - 1) {
|
|
441
627
|
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
442
628
|
delay = Math.min(delay * 2, maxDelay);
|
|
443
629
|
continue;
|
|
444
630
|
}
|
|
445
631
|
} else {
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
632
|
+
errorCount++;
|
|
633
|
+
if (errorCount >= 3) {
|
|
634
|
+
throw new ZapierApiError(
|
|
635
|
+
`Poll request failed: ${response.status} ${response.statusText}`,
|
|
636
|
+
{ statusCode: response.status }
|
|
637
|
+
);
|
|
638
|
+
}
|
|
639
|
+
if (attempt < maxAttempts - 1) {
|
|
640
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
641
|
+
delay = Math.min(delay * 2, maxDelay);
|
|
642
|
+
continue;
|
|
643
|
+
}
|
|
449
644
|
}
|
|
450
645
|
}
|
|
451
|
-
throw new
|
|
646
|
+
throw new ZapierTimeoutError(
|
|
647
|
+
`Operation timed out after ${maxAttempts} attempts`,
|
|
648
|
+
{ attempts: maxAttempts, maxAttempts }
|
|
649
|
+
);
|
|
452
650
|
}
|
|
453
651
|
|
|
454
652
|
// src/api/client.ts
|
|
455
|
-
var
|
|
653
|
+
var SubdomainConfigMap = {
|
|
654
|
+
// e.g. https://relay.zapier.com
|
|
456
655
|
relay: {
|
|
457
656
|
authHeader: "X-Relay-Authorization"
|
|
458
657
|
}
|
|
459
658
|
};
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
659
|
+
var ZapierApiClient = class {
|
|
660
|
+
constructor(options) {
|
|
661
|
+
this.options = options;
|
|
662
|
+
this.fetch = async (path, init) => {
|
|
663
|
+
return this.plainFetch(path, init);
|
|
664
|
+
};
|
|
665
|
+
this.get = async (path, options = {}) => {
|
|
666
|
+
return this.fetchJson("GET", path, void 0, options);
|
|
667
|
+
};
|
|
668
|
+
this.post = async (path, data, options = {}) => {
|
|
669
|
+
return this.fetchJson("POST", path, data, options);
|
|
670
|
+
};
|
|
671
|
+
this.put = async (path, data, options = {}) => {
|
|
672
|
+
return this.fetchJson("PUT", path, data, options);
|
|
673
|
+
};
|
|
674
|
+
this.delete = async (path, options = {}) => {
|
|
675
|
+
return this.fetchJson("DELETE", path, void 0, options);
|
|
676
|
+
};
|
|
677
|
+
this.poll = async (path, options = {}) => {
|
|
678
|
+
return pollUntilComplete({
|
|
679
|
+
fetchPoll: () => this.plainFetch(path, {
|
|
680
|
+
method: "GET",
|
|
681
|
+
searchParams: options.searchParams,
|
|
682
|
+
authRequired: options.authRequired
|
|
683
|
+
}),
|
|
684
|
+
maxAttempts: options.maxAttempts,
|
|
685
|
+
initialDelay: options.initialDelay,
|
|
686
|
+
maxDelay: options.maxDelay,
|
|
687
|
+
successStatus: options.successStatus,
|
|
688
|
+
pendingStatus: options.pendingStatus,
|
|
689
|
+
resultExtractor: options.resultExtractor
|
|
487
690
|
});
|
|
691
|
+
};
|
|
692
|
+
}
|
|
693
|
+
// Helper to parse response data
|
|
694
|
+
async parseResult(response) {
|
|
695
|
+
try {
|
|
696
|
+
return { type: "json", data: await response.json() };
|
|
697
|
+
} catch {
|
|
698
|
+
return { type: "text", data: await response.text() };
|
|
488
699
|
}
|
|
489
|
-
return { url: url.toString(), subdomainConfig };
|
|
490
700
|
}
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
if (!resolvedToken) {
|
|
501
|
-
resolvedToken = await getTokenFromEnvOrConfig({
|
|
502
|
-
onEvent,
|
|
503
|
-
fetch: originalFetch
|
|
504
|
-
});
|
|
505
|
-
}
|
|
506
|
-
if (resolvedToken) {
|
|
507
|
-
const authHeaderName = subdomainConfig?.authHeader || "Authorization";
|
|
508
|
-
headers[authHeaderName] = getAuthorizationHeader(resolvedToken);
|
|
701
|
+
// Helper to get a token from the different places it could be gotten
|
|
702
|
+
async getAuthToken() {
|
|
703
|
+
if (this.options.token) {
|
|
704
|
+
return this.options.token;
|
|
705
|
+
}
|
|
706
|
+
if (this.options.getToken) {
|
|
707
|
+
const token = await this.options.getToken();
|
|
708
|
+
if (token) {
|
|
709
|
+
return token;
|
|
509
710
|
}
|
|
510
711
|
}
|
|
511
|
-
return
|
|
712
|
+
return getTokenFromEnvOrConfig({
|
|
713
|
+
onEvent: this.options.onEvent,
|
|
714
|
+
fetch: this.options.fetch
|
|
715
|
+
});
|
|
512
716
|
}
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
717
|
+
// Helper to handle responses
|
|
718
|
+
async handleResponse(params) {
|
|
719
|
+
const { response, customErrorHandler, wasMissingAuthToken } = params;
|
|
720
|
+
const { data: responseData } = await this.parseResult(response);
|
|
721
|
+
if (response.ok) {
|
|
722
|
+
return responseData;
|
|
723
|
+
}
|
|
724
|
+
const errorInfo = {
|
|
725
|
+
status: response.status,
|
|
726
|
+
statusText: response.statusText,
|
|
727
|
+
data: responseData
|
|
728
|
+
};
|
|
729
|
+
if (customErrorHandler) {
|
|
730
|
+
const customError = customErrorHandler(errorInfo);
|
|
731
|
+
if (customError) {
|
|
732
|
+
if (customError instanceof Error) {
|
|
518
733
|
throw customError;
|
|
734
|
+
} else {
|
|
735
|
+
throw new Error(
|
|
736
|
+
`customErrorHandler returned a non-Error: ${JSON.stringify(customError)}`
|
|
737
|
+
);
|
|
519
738
|
}
|
|
520
739
|
}
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
740
|
+
}
|
|
741
|
+
const { message, errors } = this.parseErrorResponse(errorInfo);
|
|
742
|
+
const errorOptions = {
|
|
743
|
+
statusCode: response.status,
|
|
744
|
+
errors
|
|
745
|
+
};
|
|
746
|
+
if (response.status === 404) {
|
|
747
|
+
throw new ZapierNotFoundError(message, errorOptions);
|
|
748
|
+
}
|
|
749
|
+
if (response.status === 401 || response.status === 403) {
|
|
750
|
+
if (wasMissingAuthToken) {
|
|
751
|
+
throw new ZapierAuthenticationError(
|
|
752
|
+
`Authentication required (HTTP ${response.status}). Please provide a token in options or set ZAPIER_TOKEN environment variable.`,
|
|
753
|
+
errorOptions
|
|
524
754
|
);
|
|
525
755
|
}
|
|
526
|
-
throw new
|
|
756
|
+
throw new ZapierAuthenticationError(message, errorOptions);
|
|
757
|
+
}
|
|
758
|
+
if (response.status === 400) {
|
|
759
|
+
throw new ZapierValidationError(message, errorOptions);
|
|
760
|
+
}
|
|
761
|
+
throw new ZapierApiError(message, errorOptions);
|
|
762
|
+
}
|
|
763
|
+
hasErrorArray(data) {
|
|
764
|
+
return typeof data === "object" && data !== null && "errors" in data && Array.isArray(data.errors);
|
|
765
|
+
}
|
|
766
|
+
// Helper to check if data has API errors
|
|
767
|
+
isApiErrorArray(dataArray) {
|
|
768
|
+
const data = dataArray[0];
|
|
769
|
+
return typeof data === "object" && data !== null && "message" in data && "code" in data && "title" in data && "detail" in data;
|
|
770
|
+
}
|
|
771
|
+
// Do our best to extract an error message from the response data
|
|
772
|
+
extractErrorMessage(data) {
|
|
773
|
+
if (typeof data === "string") {
|
|
774
|
+
return data;
|
|
775
|
+
}
|
|
776
|
+
if (typeof data === "object" && data !== null) {
|
|
777
|
+
if ("message" in data && typeof data.message === "string") {
|
|
778
|
+
return data.message;
|
|
779
|
+
}
|
|
780
|
+
if ("error" in data) {
|
|
781
|
+
if (typeof data.error === "string") {
|
|
782
|
+
return data.error;
|
|
783
|
+
}
|
|
784
|
+
if (typeof data.error === "object" && data.error !== null) {
|
|
785
|
+
if ("message" in data.error && typeof data.error.message === "string") {
|
|
786
|
+
return data.error.message;
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
try {
|
|
790
|
+
return JSON.stringify(data.error);
|
|
791
|
+
} catch {
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
if ("errors" in data && Array.isArray(data.errors)) {
|
|
795
|
+
if (this.isApiErrorArray(data.errors)) {
|
|
796
|
+
return data.errors[0].detail || data.errors[0].title;
|
|
797
|
+
}
|
|
798
|
+
}
|
|
527
799
|
}
|
|
800
|
+
return void 0;
|
|
801
|
+
}
|
|
802
|
+
// Helper to parse API error response
|
|
803
|
+
parseErrorResponse(errorInfo) {
|
|
804
|
+
const fallbackMessage = `HTTP ${errorInfo.status}: ${errorInfo.statusText}`;
|
|
528
805
|
try {
|
|
529
|
-
|
|
806
|
+
if (typeof errorInfo.data === "string") {
|
|
807
|
+
return { message: `${fallbackMessage}: ${errorInfo.data}` };
|
|
808
|
+
}
|
|
809
|
+
const errorMessage = this.extractErrorMessage(errorInfo.data) || fallbackMessage;
|
|
810
|
+
if (this.hasErrorArray(errorInfo.data)) {
|
|
811
|
+
if (this.isApiErrorArray(errorInfo.data.errors)) {
|
|
812
|
+
return {
|
|
813
|
+
message: errorMessage,
|
|
814
|
+
errors: errorInfo.data.errors
|
|
815
|
+
};
|
|
816
|
+
} else {
|
|
817
|
+
return {
|
|
818
|
+
message: errorMessage,
|
|
819
|
+
errors: errorInfo.data.errors.map((e) => ({
|
|
820
|
+
status: errorInfo.status,
|
|
821
|
+
code: String(errorInfo.status),
|
|
822
|
+
title: errorInfo.statusText,
|
|
823
|
+
detail: JSON.stringify(e)
|
|
824
|
+
}))
|
|
825
|
+
};
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
return { message: errorMessage };
|
|
530
829
|
} catch {
|
|
531
|
-
return
|
|
830
|
+
return { message: fallbackMessage };
|
|
532
831
|
}
|
|
533
832
|
}
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
833
|
+
// Check if this is a path that needs subdomain routing
|
|
834
|
+
// e.g. /relay/workflows -> relay.zapier.com/workflows
|
|
835
|
+
applySubdomainBehavior(path) {
|
|
836
|
+
const pathSegments = path.split("/").filter(Boolean);
|
|
837
|
+
if (pathSegments.length > 0 && pathSegments[0] in SubdomainConfigMap) {
|
|
838
|
+
const domainPrefix = pathSegments[0];
|
|
839
|
+
const subdomainConfig = SubdomainConfigMap[domainPrefix];
|
|
840
|
+
const originalBaseUrl = new URL(this.options.baseUrl);
|
|
841
|
+
const finalBaseUrl = `https://${domainPrefix}.${originalBaseUrl.hostname}`;
|
|
842
|
+
const pathWithoutPrefix = "/" + pathSegments.slice(1).join("/");
|
|
843
|
+
return { url: new URL(pathWithoutPrefix, finalBaseUrl), subdomainConfig };
|
|
539
844
|
}
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
...headers,
|
|
544
|
-
...init?.headers ? init.headers instanceof Headers ? Object.fromEntries(init.headers.entries()) : init.headers : {}
|
|
845
|
+
return {
|
|
846
|
+
url: new URL(path, this.options.baseUrl),
|
|
847
|
+
subdomainConfig: void 0
|
|
545
848
|
};
|
|
546
|
-
return await fetch(url, {
|
|
547
|
-
...init,
|
|
548
|
-
headers: finalHeaders
|
|
549
|
-
});
|
|
550
849
|
}
|
|
551
|
-
|
|
552
|
-
|
|
850
|
+
// Helper to build full URLs and return routing info
|
|
851
|
+
buildUrl(path, searchParams) {
|
|
852
|
+
const { url, subdomainConfig } = this.applySubdomainBehavior(path);
|
|
853
|
+
if (searchParams) {
|
|
854
|
+
Object.entries(searchParams).forEach(([key, value]) => {
|
|
855
|
+
url.searchParams.set(key, value);
|
|
856
|
+
});
|
|
857
|
+
}
|
|
858
|
+
return { url: url.toString(), subdomainConfig };
|
|
859
|
+
}
|
|
860
|
+
// Helper to build headers
|
|
861
|
+
async buildHeaders(options = {}, subdomainConfig) {
|
|
862
|
+
const headers = new Headers(options.headers ?? {});
|
|
863
|
+
const authToken = await this.getAuthToken();
|
|
864
|
+
if (authToken) {
|
|
865
|
+
const authHeaderName = subdomainConfig?.authHeader || "Authorization";
|
|
866
|
+
headers.set(authHeaderName, getAuthorizationHeader(authToken));
|
|
867
|
+
}
|
|
868
|
+
if (options.authRequired) {
|
|
869
|
+
if (headers.get("Authorization") == null && authToken == null) {
|
|
870
|
+
throw new ZapierAuthenticationError(
|
|
871
|
+
`Authentication required but no token available. Please set ZAPIER_TOKEN, or run the 'login' command with the CLI.`
|
|
872
|
+
);
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
return headers;
|
|
876
|
+
}
|
|
877
|
+
// Helper to perform HTTP requests with JSON handling
|
|
878
|
+
async fetchJson(method, path, data, options = {}) {
|
|
879
|
+
const headers = { ...options.headers };
|
|
553
880
|
if (data && typeof data === "object") {
|
|
554
881
|
headers["Content-Type"] = "application/json";
|
|
555
882
|
}
|
|
556
|
-
const
|
|
883
|
+
const wasMissingAuthToken = options.authRequired && await this.getAuthToken() == null;
|
|
884
|
+
const response = await this.plainFetch(path, {
|
|
885
|
+
...options,
|
|
557
886
|
method,
|
|
558
|
-
body: data ? JSON.stringify(data) : void 0,
|
|
559
|
-
headers
|
|
560
|
-
searchParams: options2.searchParams,
|
|
561
|
-
authRequired: options2.authRequired
|
|
887
|
+
body: data != null ? JSON.stringify(data) : void 0,
|
|
888
|
+
headers
|
|
562
889
|
});
|
|
563
|
-
|
|
890
|
+
const result = await this.handleResponse({
|
|
891
|
+
response,
|
|
892
|
+
customErrorHandler: options.customErrorHandler,
|
|
893
|
+
wasMissingAuthToken
|
|
894
|
+
});
|
|
895
|
+
if (typeof result === "string") {
|
|
896
|
+
throw new ZapierValidationError(
|
|
897
|
+
`Response could not be parsed as JSON: ${result}`
|
|
898
|
+
);
|
|
899
|
+
}
|
|
900
|
+
return result;
|
|
564
901
|
}
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
},
|
|
572
|
-
async put(path, data, options2 = {}) {
|
|
573
|
-
return fetchJson("PUT", path, data, options2);
|
|
574
|
-
},
|
|
575
|
-
async delete(path, options2 = {}) {
|
|
576
|
-
return fetchJson("DELETE", path, void 0, options2);
|
|
577
|
-
},
|
|
578
|
-
async poll(path, options2 = {}) {
|
|
579
|
-
return pollUntilComplete({
|
|
580
|
-
fetchPoll: () => plainFetch(path, {
|
|
581
|
-
method: "GET",
|
|
582
|
-
searchParams: options2.searchParams,
|
|
583
|
-
authRequired: options2.authRequired
|
|
584
|
-
}),
|
|
585
|
-
maxAttempts: options2.maxAttempts,
|
|
586
|
-
initialDelay: options2.initialDelay,
|
|
587
|
-
maxDelay: options2.maxDelay,
|
|
588
|
-
successStatus: options2.successStatus,
|
|
589
|
-
pendingStatus: options2.pendingStatus,
|
|
590
|
-
resultExtractor: options2.resultExtractor
|
|
591
|
-
});
|
|
592
|
-
},
|
|
593
|
-
async fetch(path, init) {
|
|
594
|
-
return plainFetch(path, init);
|
|
902
|
+
// Plain fetch method for API paths (must start with /)
|
|
903
|
+
async plainFetch(path, fetchOptions) {
|
|
904
|
+
if (!path.startsWith("/")) {
|
|
905
|
+
throw new ZapierValidationError(
|
|
906
|
+
`plainFetch expects a path starting with '/', got: ${path}`
|
|
907
|
+
);
|
|
595
908
|
}
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
909
|
+
if (fetchOptions?.body && typeof fetchOptions.body === "object") {
|
|
910
|
+
fetchOptions.body = JSON.stringify(fetchOptions.body);
|
|
911
|
+
}
|
|
912
|
+
const { url, subdomainConfig } = this.buildUrl(
|
|
913
|
+
path,
|
|
914
|
+
fetchOptions?.searchParams
|
|
915
|
+
);
|
|
916
|
+
const builtHeaders = await this.buildHeaders(
|
|
917
|
+
fetchOptions,
|
|
918
|
+
subdomainConfig
|
|
919
|
+
);
|
|
920
|
+
const inputHeaders = new Headers(fetchOptions?.headers ?? {});
|
|
921
|
+
const mergedHeaders = new Headers();
|
|
922
|
+
builtHeaders.forEach((value, key) => {
|
|
923
|
+
mergedHeaders.set(key, value);
|
|
924
|
+
});
|
|
925
|
+
inputHeaders.forEach((value, key) => {
|
|
926
|
+
mergedHeaders.set(key, value);
|
|
927
|
+
});
|
|
928
|
+
return await this.options.fetch(url, {
|
|
929
|
+
...fetchOptions,
|
|
930
|
+
headers: mergedHeaders
|
|
931
|
+
});
|
|
932
|
+
}
|
|
933
|
+
};
|
|
934
|
+
var createZapierApi = (options) => {
|
|
604
935
|
const {
|
|
605
|
-
baseUrl
|
|
936
|
+
baseUrl,
|
|
606
937
|
token,
|
|
607
938
|
getToken,
|
|
608
|
-
api: providedApi,
|
|
609
939
|
debug = false,
|
|
610
|
-
fetch:
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
}
|
|
615
|
-
return
|
|
940
|
+
fetch: originalFetch = globalThis.fetch,
|
|
941
|
+
onEvent
|
|
942
|
+
} = options;
|
|
943
|
+
const debugLog = createDebugLogger(debug);
|
|
944
|
+
const debugFetch = createDebugFetch({ originalFetch, debugLog });
|
|
945
|
+
return new ZapierApiClient({
|
|
616
946
|
baseUrl,
|
|
617
947
|
token,
|
|
618
948
|
getToken,
|
|
619
949
|
debug,
|
|
620
|
-
fetch:
|
|
621
|
-
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
// src/functions/getApp/index.ts
|
|
625
|
-
async function getApp(options) {
|
|
626
|
-
const api = getOrCreateApiClient(options);
|
|
627
|
-
const { appKey } = options;
|
|
628
|
-
const app = await api.get(`/api/v4/apps/${appKey}/`, {
|
|
629
|
-
customErrorHandler: (response) => {
|
|
630
|
-
if (response.status === 404) {
|
|
631
|
-
return new AppNotFoundError(appKey);
|
|
632
|
-
}
|
|
633
|
-
return void 0;
|
|
634
|
-
}
|
|
950
|
+
fetch: debugFetch,
|
|
951
|
+
onEvent
|
|
635
952
|
});
|
|
636
|
-
|
|
637
|
-
key: app.slug,
|
|
638
|
-
name: app.name,
|
|
639
|
-
description: app.description,
|
|
640
|
-
version: "1.0.0",
|
|
641
|
-
category: app.category?.name,
|
|
642
|
-
actions: [],
|
|
643
|
-
triggers: [],
|
|
644
|
-
current_implementation_id: app.current_implementation_id
|
|
645
|
-
};
|
|
646
|
-
}
|
|
953
|
+
};
|
|
647
954
|
|
|
648
|
-
// src/
|
|
649
|
-
|
|
650
|
-
const
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
throw error;
|
|
671
|
-
}
|
|
672
|
-
console.warn(
|
|
673
|
-
`Warning: Could not filter by app ${options2.appKey}:`,
|
|
674
|
-
error instanceof Error ? error.message : "Unknown error"
|
|
675
|
-
);
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
|
-
if (options2.search) {
|
|
679
|
-
searchParams.search = options2.search;
|
|
680
|
-
} else if (options2.title) {
|
|
681
|
-
searchParams.search = options2.title;
|
|
955
|
+
// src/plugins/api/index.ts
|
|
956
|
+
var apiPlugin = (params) => {
|
|
957
|
+
const {
|
|
958
|
+
fetch: customFetch = globalThis.fetch,
|
|
959
|
+
baseUrl = "https://zapier.com",
|
|
960
|
+
token,
|
|
961
|
+
getToken,
|
|
962
|
+
onEvent,
|
|
963
|
+
debug = false
|
|
964
|
+
} = params;
|
|
965
|
+
const api = createZapierApi({
|
|
966
|
+
baseUrl,
|
|
967
|
+
token,
|
|
968
|
+
getToken,
|
|
969
|
+
debug,
|
|
970
|
+
fetch: customFetch,
|
|
971
|
+
onEvent
|
|
972
|
+
});
|
|
973
|
+
return {
|
|
974
|
+
context: {
|
|
975
|
+
api
|
|
976
|
+
// Provide API client in context for other plugins to use
|
|
682
977
|
}
|
|
683
|
-
|
|
684
|
-
|
|
978
|
+
};
|
|
979
|
+
};
|
|
980
|
+
|
|
981
|
+
// src/utils/pagination-utils.ts
|
|
982
|
+
var offsetCursorMarker = "$$offset$$";
|
|
983
|
+
function splitOffsetCursor(cursor) {
|
|
984
|
+
if (!cursor) {
|
|
985
|
+
return [0, cursor];
|
|
986
|
+
}
|
|
987
|
+
try {
|
|
988
|
+
const parsedCursor = JSON.parse(cursor);
|
|
989
|
+
if (!Array.isArray(parsedCursor)) {
|
|
990
|
+
return [0, cursor];
|
|
685
991
|
}
|
|
686
|
-
|
|
687
|
-
|
|
992
|
+
const [marker, offset, currentCursor] = parsedCursor;
|
|
993
|
+
if (marker !== offsetCursorMarker) {
|
|
994
|
+
return [0, cursor];
|
|
688
995
|
}
|
|
689
|
-
if (
|
|
690
|
-
|
|
996
|
+
if (typeof offset !== "number") {
|
|
997
|
+
return [0, cursor];
|
|
691
998
|
}
|
|
692
|
-
|
|
693
|
-
|
|
999
|
+
return [offset, currentCursor];
|
|
1000
|
+
} catch {
|
|
1001
|
+
return [0, cursor];
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
function createOffsetCursor(offset, currentCursor) {
|
|
1005
|
+
return JSON.stringify([offsetCursorMarker, offset, currentCursor]);
|
|
1006
|
+
}
|
|
1007
|
+
async function* paginateMaxItems(pageFunction, pageOptions) {
|
|
1008
|
+
let cursor = pageOptions?.cursor;
|
|
1009
|
+
let totalItemsYielded = 0;
|
|
1010
|
+
const maxItems = pageOptions?.maxItems;
|
|
1011
|
+
const pageSize = pageOptions?.pageSize;
|
|
1012
|
+
do {
|
|
1013
|
+
const options = {
|
|
1014
|
+
...pageOptions || {},
|
|
1015
|
+
cursor,
|
|
1016
|
+
pageSize: maxItems !== void 0 && pageSize !== void 0 ? Math.min(pageSize, maxItems) : pageSize
|
|
1017
|
+
};
|
|
1018
|
+
const page = await pageFunction(options);
|
|
1019
|
+
if (maxItems !== void 0) {
|
|
1020
|
+
const remainingItems = maxItems - totalItemsYielded;
|
|
1021
|
+
if (page.data.length >= remainingItems) {
|
|
1022
|
+
const yieldedPage = {
|
|
1023
|
+
...page,
|
|
1024
|
+
data: page.data.slice(0, remainingItems),
|
|
1025
|
+
nextCursor: void 0
|
|
1026
|
+
};
|
|
1027
|
+
yield yieldedPage;
|
|
1028
|
+
break;
|
|
1029
|
+
}
|
|
694
1030
|
}
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
1031
|
+
yield page;
|
|
1032
|
+
totalItemsYielded += page.data.length;
|
|
1033
|
+
cursor = page.nextCursor;
|
|
1034
|
+
} while (cursor);
|
|
1035
|
+
}
|
|
1036
|
+
async function* paginateBuffered(pageFunction, pageOptions) {
|
|
1037
|
+
const pageSize = pageOptions?.pageSize;
|
|
1038
|
+
const [cursorOffset, currentCursor] = splitOffsetCursor(pageOptions?.cursor);
|
|
1039
|
+
const options = {
|
|
1040
|
+
...pageOptions || {},
|
|
1041
|
+
cursor: currentCursor
|
|
1042
|
+
};
|
|
1043
|
+
const iterator = paginateMaxItems(pageFunction, options);
|
|
1044
|
+
let bufferedPages = [];
|
|
1045
|
+
let isFirstPage = true;
|
|
1046
|
+
let cursor;
|
|
1047
|
+
for await (let page of iterator) {
|
|
1048
|
+
if (isFirstPage) {
|
|
1049
|
+
isFirstPage = false;
|
|
1050
|
+
if (cursorOffset) {
|
|
1051
|
+
page = {
|
|
1052
|
+
...page,
|
|
1053
|
+
data: page.data.slice(cursorOffset)
|
|
1054
|
+
};
|
|
712
1055
|
}
|
|
1056
|
+
}
|
|
1057
|
+
if (!pageSize) {
|
|
1058
|
+
yield page;
|
|
1059
|
+
cursor = page.nextCursor;
|
|
1060
|
+
continue;
|
|
1061
|
+
}
|
|
1062
|
+
const bufferedLength = bufferedPages.reduce(
|
|
1063
|
+
(acc, page2) => acc + page2.data.length,
|
|
1064
|
+
0
|
|
713
1065
|
);
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
}
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
previousUrl: data.previous
|
|
1066
|
+
if (bufferedLength + page.data.length < pageSize) {
|
|
1067
|
+
bufferedPages.push(page);
|
|
1068
|
+
cursor = page.nextCursor;
|
|
1069
|
+
continue;
|
|
1070
|
+
}
|
|
1071
|
+
const bufferedItems = bufferedPages.map((p) => p.data).flat();
|
|
1072
|
+
const allItems = [...bufferedItems, ...page.data];
|
|
1073
|
+
const pageItems = allItems.slice(0, pageSize);
|
|
1074
|
+
const remainingItems = allItems.slice(pageItems.length);
|
|
1075
|
+
if (remainingItems.length === 0) {
|
|
1076
|
+
yield {
|
|
1077
|
+
...page,
|
|
1078
|
+
data: pageItems,
|
|
1079
|
+
nextCursor: page.nextCursor
|
|
729
1080
|
};
|
|
1081
|
+
bufferedPages = [];
|
|
1082
|
+
cursor = page.nextCursor;
|
|
1083
|
+
continue;
|
|
730
1084
|
}
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
1085
|
+
yield {
|
|
1086
|
+
...page,
|
|
1087
|
+
data: pageItems,
|
|
1088
|
+
nextCursor: createOffsetCursor(
|
|
1089
|
+
page.data.length - remainingItems.length,
|
|
1090
|
+
cursor
|
|
1091
|
+
)
|
|
1092
|
+
};
|
|
1093
|
+
while (remainingItems.length > pageSize) {
|
|
1094
|
+
const pageItems2 = remainingItems.splice(0, pageSize);
|
|
1095
|
+
yield {
|
|
1096
|
+
...page,
|
|
1097
|
+
data: pageItems2,
|
|
1098
|
+
nextCursor: createOffsetCursor(
|
|
1099
|
+
page.data.length - remainingItems.length,
|
|
1100
|
+
cursor
|
|
1101
|
+
)
|
|
1102
|
+
};
|
|
740
1103
|
}
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
1104
|
+
bufferedPages = [
|
|
1105
|
+
{
|
|
1106
|
+
...page,
|
|
1107
|
+
data: remainingItems
|
|
1108
|
+
}
|
|
1109
|
+
];
|
|
1110
|
+
cursor = page.nextCursor;
|
|
1111
|
+
}
|
|
1112
|
+
if (bufferedPages.length > 0) {
|
|
1113
|
+
const lastBufferedPage = bufferedPages.slice(-1)[0];
|
|
1114
|
+
const bufferedItems = bufferedPages.map((p) => p.data).flat();
|
|
1115
|
+
yield {
|
|
1116
|
+
...lastBufferedPage,
|
|
1117
|
+
data: bufferedItems
|
|
1118
|
+
};
|
|
751
1119
|
}
|
|
752
|
-
return listAuthenticationsInternal(options);
|
|
753
1120
|
}
|
|
1121
|
+
var paginate = paginateBuffered;
|
|
754
1122
|
|
|
755
|
-
// src/
|
|
756
|
-
|
|
757
|
-
const
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
return new Error(
|
|
770
|
-
`Access forbidden. Your token may not have the required scopes to get authentication ${authenticationId}. (HTTP ${response.status})`
|
|
771
|
-
);
|
|
772
|
-
}
|
|
773
|
-
if (response.status === 404) {
|
|
774
|
-
return new Error(
|
|
775
|
-
`Authentication ${authenticationId} not found. It may not exist or you may not have access to it. (HTTP ${response.status})`
|
|
776
|
-
);
|
|
777
|
-
}
|
|
778
|
-
return void 0;
|
|
1123
|
+
// src/utils/validation.ts
|
|
1124
|
+
var validate = (schema, input) => {
|
|
1125
|
+
const result = schema.safeParse(input);
|
|
1126
|
+
if (!result.success) {
|
|
1127
|
+
const errorMessages = result.error.errors.map((error) => {
|
|
1128
|
+
const path = error.path.length > 0 ? error.path.join(".") : "input";
|
|
1129
|
+
return `${path}: ${error.message}`;
|
|
1130
|
+
});
|
|
1131
|
+
const message = `Validation failed:
|
|
1132
|
+
${errorMessages.join("\n ")}`;
|
|
1133
|
+
throw new ZapierValidationError(message, {
|
|
1134
|
+
details: {
|
|
1135
|
+
zodErrors: result.error.errors,
|
|
1136
|
+
input
|
|
779
1137
|
}
|
|
780
|
-
}
|
|
781
|
-
|
|
782
|
-
return
|
|
783
|
-
|
|
784
|
-
|
|
1138
|
+
});
|
|
1139
|
+
}
|
|
1140
|
+
return result.data;
|
|
1141
|
+
};
|
|
1142
|
+
function createValidator(schema) {
|
|
1143
|
+
return function validateFn(input) {
|
|
1144
|
+
return validate(schema, input);
|
|
785
1145
|
};
|
|
786
1146
|
}
|
|
1147
|
+
var validateOptions = (schema, options) => {
|
|
1148
|
+
return validate(schema, options);
|
|
1149
|
+
};
|
|
787
1150
|
|
|
788
|
-
// src/
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
limit: 1
|
|
793
|
-
});
|
|
794
|
-
return auths.length > 0 ? auths[0] : null;
|
|
795
|
-
}
|
|
796
|
-
|
|
797
|
-
// src/functions/findUniqueAuthentication/index.ts
|
|
798
|
-
async function findUniqueAuthentication(options = {}) {
|
|
799
|
-
const auths = await listAuthentications({
|
|
800
|
-
...options,
|
|
801
|
-
limit: 2
|
|
802
|
-
// Get up to 2 to check for uniqueness
|
|
803
|
-
});
|
|
804
|
-
if (auths.length === 0) {
|
|
805
|
-
throw new Error("No authentication found matching the specified criteria");
|
|
1151
|
+
// src/utils/function-utils.ts
|
|
1152
|
+
function extractCursor(data) {
|
|
1153
|
+
if (!data?.next) {
|
|
1154
|
+
return void 0;
|
|
806
1155
|
}
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
1156
|
+
try {
|
|
1157
|
+
const urlObj = new URL(data.next);
|
|
1158
|
+
const offset = urlObj.searchParams.get("offset");
|
|
1159
|
+
return offset || void 0;
|
|
1160
|
+
} catch {
|
|
1161
|
+
return void 0;
|
|
811
1162
|
}
|
|
812
|
-
return auths[0];
|
|
813
1163
|
}
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
const api = getOrCreateApiClient(options);
|
|
818
|
-
const searchParams = {};
|
|
819
|
-
if (options.category) {
|
|
820
|
-
searchParams.category = options.category;
|
|
821
|
-
}
|
|
822
|
-
if (options.limit) {
|
|
823
|
-
searchParams.limit = options.limit.toString();
|
|
824
|
-
}
|
|
825
|
-
if (options.offset) {
|
|
826
|
-
searchParams.offset = options.offset.toString();
|
|
827
|
-
}
|
|
828
|
-
const data = await api.get("/api/v4/apps/", { searchParams });
|
|
829
|
-
const apps = data.results?.map(
|
|
830
|
-
(app) => ({
|
|
831
|
-
key: app.slug,
|
|
832
|
-
name: app.name,
|
|
833
|
-
description: app.description,
|
|
834
|
-
version: "1.0.0",
|
|
835
|
-
// API doesn't provide version
|
|
836
|
-
category: app.category?.name,
|
|
837
|
-
actions: [],
|
|
838
|
-
// Will be populated separately
|
|
839
|
-
triggers: [],
|
|
840
|
-
current_implementation_id: app.current_implementation_id
|
|
841
|
-
})
|
|
842
|
-
) || [];
|
|
843
|
-
if (apps.length > 0) {
|
|
844
|
-
apps.__pagination = {
|
|
845
|
-
count: data.count,
|
|
846
|
-
hasNext: !!data.next,
|
|
847
|
-
hasPrevious: !!data.previous,
|
|
848
|
-
nextUrl: data.next,
|
|
849
|
-
previousUrl: data.previous
|
|
850
|
-
};
|
|
1164
|
+
function normalizeError(error) {
|
|
1165
|
+
if (error instanceof ZapierError) {
|
|
1166
|
+
return error;
|
|
851
1167
|
}
|
|
852
|
-
|
|
1168
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1169
|
+
return new ZapierUnknownError(`Unknown error: ${message}`, { cause: error });
|
|
853
1170
|
}
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
fetch: options.fetch
|
|
867
|
-
});
|
|
868
|
-
const implementationId = appData.current_implementation_id?.split("@")[0];
|
|
869
|
-
if (!implementationId) {
|
|
870
|
-
throw new Error("No current_implementation_id found for app");
|
|
871
|
-
}
|
|
872
|
-
const searchParams2 = {
|
|
873
|
-
global: "true",
|
|
874
|
-
public_only: "true",
|
|
875
|
-
selected_apis: implementationId
|
|
876
|
-
};
|
|
877
|
-
const data2 = await api.get("/api/v4/implementations/", {
|
|
878
|
-
searchParams: searchParams2
|
|
879
|
-
});
|
|
880
|
-
const actions2 = [];
|
|
881
|
-
for (const implementation of data2.results || []) {
|
|
882
|
-
if (implementation.actions) {
|
|
883
|
-
for (const action of implementation.actions) {
|
|
884
|
-
const transformedAction = {
|
|
885
|
-
key: action.key,
|
|
886
|
-
name: action.name || action.label,
|
|
887
|
-
description: action.description || "",
|
|
888
|
-
appKey: implementation.slug || "",
|
|
889
|
-
type: action.type || action.type_of || "read",
|
|
890
|
-
inputFields: [],
|
|
891
|
-
// Would need additional API call for detailed fields
|
|
892
|
-
outputFields: []
|
|
893
|
-
};
|
|
894
|
-
if (options?.type && transformedAction.type !== options.type) {
|
|
895
|
-
continue;
|
|
896
|
-
}
|
|
897
|
-
actions2.push(transformedAction);
|
|
898
|
-
}
|
|
1171
|
+
function createFunction(coreFn, schema) {
|
|
1172
|
+
const functionName = coreFn.name;
|
|
1173
|
+
const namedFunctions = {
|
|
1174
|
+
[functionName]: async function(options) {
|
|
1175
|
+
try {
|
|
1176
|
+
const normalizedOptions = options ?? {};
|
|
1177
|
+
if (schema) {
|
|
1178
|
+
const validatedOptions = validateOptions(schema, normalizedOptions);
|
|
1179
|
+
return await coreFn({
|
|
1180
|
+
...normalizedOptions,
|
|
1181
|
+
...validatedOptions
|
|
1182
|
+
});
|
|
899
1183
|
}
|
|
1184
|
+
return await coreFn(normalizedOptions);
|
|
1185
|
+
} catch (error) {
|
|
1186
|
+
throw normalizeError(error);
|
|
900
1187
|
}
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
1188
|
+
}
|
|
1189
|
+
};
|
|
1190
|
+
return namedFunctions[functionName];
|
|
1191
|
+
}
|
|
1192
|
+
function createPageFunction(coreFn) {
|
|
1193
|
+
const functionName = coreFn.name + "Page";
|
|
1194
|
+
const namedFunctions = {
|
|
1195
|
+
[functionName]: async function(options) {
|
|
1196
|
+
try {
|
|
1197
|
+
const result = await coreFn(options);
|
|
1198
|
+
if (result && typeof result === "object" && "data" in result) {
|
|
1199
|
+
const data = result.data;
|
|
1200
|
+
return {
|
|
1201
|
+
data: Array.isArray(data) ? data : [data],
|
|
1202
|
+
nextCursor: result.nextCursor
|
|
1203
|
+
};
|
|
1204
|
+
}
|
|
1205
|
+
if (Array.isArray(result)) {
|
|
1206
|
+
return { data: result };
|
|
1207
|
+
}
|
|
1208
|
+
return { data: [result] };
|
|
1209
|
+
} catch (error) {
|
|
1210
|
+
throw normalizeError(error);
|
|
914
1211
|
}
|
|
915
|
-
console.warn(
|
|
916
|
-
"Optimized app lookup failed, falling back to full scan:",
|
|
917
|
-
error
|
|
918
|
-
);
|
|
919
1212
|
}
|
|
920
|
-
}
|
|
921
|
-
const searchParams = {
|
|
922
|
-
global: "true",
|
|
923
|
-
public_only: "true"
|
|
924
1213
|
};
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
1214
|
+
return namedFunctions[functionName];
|
|
1215
|
+
}
|
|
1216
|
+
function createPaginatedFunction(coreFn, schema) {
|
|
1217
|
+
const pageFunction = createPageFunction(coreFn);
|
|
1218
|
+
const functionName = coreFn.name;
|
|
1219
|
+
const validator = schema ? createValidator(schema) : null;
|
|
1220
|
+
const namedFunctions = {
|
|
1221
|
+
[functionName]: function(options) {
|
|
1222
|
+
const normalizedOptions = options ?? {};
|
|
1223
|
+
const validatedOptions = {
|
|
1224
|
+
...normalizedOptions,
|
|
1225
|
+
...validator ? validator(normalizedOptions) : normalizedOptions
|
|
1226
|
+
};
|
|
1227
|
+
const pageSize = validatedOptions.pageSize || 100;
|
|
1228
|
+
const optimizedOptions = {
|
|
1229
|
+
...validatedOptions,
|
|
1230
|
+
pageSize
|
|
1231
|
+
};
|
|
1232
|
+
const iterator = paginate(pageFunction, optimizedOptions);
|
|
1233
|
+
const firstPagePromise = iterator.next().then((result) => {
|
|
1234
|
+
if (result.done) {
|
|
1235
|
+
throw new Error("Paginate should always iterate at least once");
|
|
942
1236
|
}
|
|
943
|
-
|
|
944
|
-
|
|
1237
|
+
return result.value;
|
|
1238
|
+
});
|
|
1239
|
+
return Object.assign(firstPagePromise, {
|
|
1240
|
+
[Symbol.asyncIterator]: async function* () {
|
|
1241
|
+
yield await firstPagePromise;
|
|
1242
|
+
for await (const page of iterator) {
|
|
1243
|
+
yield page;
|
|
1244
|
+
}
|
|
1245
|
+
},
|
|
1246
|
+
items: function() {
|
|
1247
|
+
return {
|
|
1248
|
+
[Symbol.asyncIterator]: async function* () {
|
|
1249
|
+
const firstPage = await firstPagePromise;
|
|
1250
|
+
for (const item of firstPage.data) {
|
|
1251
|
+
yield item;
|
|
1252
|
+
}
|
|
1253
|
+
for await (const page of iterator) {
|
|
1254
|
+
for (const item of page.data) {
|
|
1255
|
+
yield item;
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
};
|
|
945
1260
|
}
|
|
946
|
-
|
|
1261
|
+
});
|
|
1262
|
+
}
|
|
1263
|
+
};
|
|
1264
|
+
return namedFunctions[functionName];
|
|
1265
|
+
}
|
|
1266
|
+
var NeedChoicesSchema = zod.z.object({
|
|
1267
|
+
key: zod.z.string().optional(),
|
|
1268
|
+
label: zod.z.string().optional(),
|
|
1269
|
+
sample: zod.z.string().optional(),
|
|
1270
|
+
value: zod.z.string().optional()
|
|
1271
|
+
});
|
|
1272
|
+
var NeedSchema = zod.z.object({
|
|
1273
|
+
key: zod.z.string(),
|
|
1274
|
+
alters_custom_fields: zod.z.boolean().nullable().optional(),
|
|
1275
|
+
capabilities: zod.z.array(zod.z.string()).optional(),
|
|
1276
|
+
choices: zod.z.array(NeedChoicesSchema).optional(),
|
|
1277
|
+
computed: zod.z.boolean().nullable().optional(),
|
|
1278
|
+
custom_field: zod.z.boolean().optional(),
|
|
1279
|
+
default: zod.z.string().optional(),
|
|
1280
|
+
depends_on: zod.z.array(zod.z.string()).optional(),
|
|
1281
|
+
format: zod.z.literal("SELECT").optional(),
|
|
1282
|
+
from_search: zod.z.boolean().optional(),
|
|
1283
|
+
from_write: zod.z.boolean().optional(),
|
|
1284
|
+
help_text: zod.z.string().optional(),
|
|
1285
|
+
help_text_html: zod.z.string().optional(),
|
|
1286
|
+
input_format: zod.z.array(zod.z.string()).optional(),
|
|
1287
|
+
label: zod.z.string().optional(),
|
|
1288
|
+
language: zod.z.string().optional(),
|
|
1289
|
+
parent_key: zod.z.string().optional(),
|
|
1290
|
+
placeholder: zod.z.string().optional(),
|
|
1291
|
+
prefill: zod.z.string().optional(),
|
|
1292
|
+
required: zod.z.boolean().optional(),
|
|
1293
|
+
searchfill: zod.z.string().optional(),
|
|
1294
|
+
send_in_json: zod.z.boolean().optional(),
|
|
1295
|
+
regex: zod.z.string().optional(),
|
|
1296
|
+
type: zod.z.enum([
|
|
1297
|
+
"integer",
|
|
1298
|
+
"string",
|
|
1299
|
+
"text",
|
|
1300
|
+
"datetime",
|
|
1301
|
+
"boolean",
|
|
1302
|
+
"file",
|
|
1303
|
+
"decimal",
|
|
1304
|
+
"copy",
|
|
1305
|
+
"password",
|
|
1306
|
+
"dict",
|
|
1307
|
+
"code",
|
|
1308
|
+
"filter",
|
|
1309
|
+
"json"
|
|
1310
|
+
]).optional(),
|
|
1311
|
+
list: zod.z.boolean().optional()
|
|
1312
|
+
});
|
|
1313
|
+
var ActionLinksSchema = zod.z.object({
|
|
1314
|
+
action_url: zod.z.string().optional()
|
|
1315
|
+
});
|
|
1316
|
+
var ActionPermissionsSchema = zod.z.object({
|
|
1317
|
+
can_use: zod.z.boolean().optional()
|
|
1318
|
+
});
|
|
1319
|
+
var ActionSchema = zod.z.object({
|
|
1320
|
+
id: zod.z.string().optional(),
|
|
1321
|
+
type: zod.z.enum([
|
|
1322
|
+
"filter",
|
|
1323
|
+
"read",
|
|
1324
|
+
"read_bulk",
|
|
1325
|
+
"run",
|
|
1326
|
+
"search",
|
|
1327
|
+
"search_and_write",
|
|
1328
|
+
"search_or_write",
|
|
1329
|
+
"write"
|
|
1330
|
+
]),
|
|
1331
|
+
key: zod.z.string(),
|
|
1332
|
+
name: zod.z.string(),
|
|
1333
|
+
noun: zod.z.string().optional(),
|
|
1334
|
+
description: zod.z.string(),
|
|
1335
|
+
description_html: zod.z.string().optional(),
|
|
1336
|
+
is_important: zod.z.boolean().optional(),
|
|
1337
|
+
is_hidden: zod.z.boolean().optional(),
|
|
1338
|
+
needs: zod.z.array(NeedSchema).optional(),
|
|
1339
|
+
meta: zod.z.string().optional(),
|
|
1340
|
+
selected_api: zod.z.string().optional(),
|
|
1341
|
+
links: ActionLinksSchema.optional(),
|
|
1342
|
+
permissions: ActionPermissionsSchema.optional()
|
|
1343
|
+
});
|
|
1344
|
+
var ChoiceSchema = zod.z.object({
|
|
1345
|
+
value: zod.z.union([zod.z.string(), zod.z.number()]),
|
|
1346
|
+
label: zod.z.string()
|
|
1347
|
+
});
|
|
1348
|
+
zod.z.object({
|
|
1349
|
+
key: zod.z.string(),
|
|
1350
|
+
label: zod.z.string(),
|
|
1351
|
+
type: zod.z.enum([
|
|
1352
|
+
"string",
|
|
1353
|
+
"number",
|
|
1354
|
+
"boolean",
|
|
1355
|
+
"datetime",
|
|
1356
|
+
"file",
|
|
1357
|
+
"object",
|
|
1358
|
+
"array"
|
|
1359
|
+
]),
|
|
1360
|
+
required: zod.z.boolean(),
|
|
1361
|
+
description: zod.z.string().optional(),
|
|
1362
|
+
choices: zod.z.array(ChoiceSchema).optional()
|
|
1363
|
+
});
|
|
1364
|
+
zod.z.object({
|
|
1365
|
+
data: zod.z.array(zod.z.any())
|
|
1366
|
+
});
|
|
1367
|
+
var ActionFieldChoiceSchema = zod.z.object({
|
|
1368
|
+
value: zod.z.union([zod.z.string(), zod.z.number()]),
|
|
1369
|
+
label: zod.z.string()
|
|
1370
|
+
});
|
|
1371
|
+
zod.z.object({
|
|
1372
|
+
key: zod.z.string(),
|
|
1373
|
+
label: zod.z.string().optional(),
|
|
1374
|
+
required: zod.z.boolean(),
|
|
1375
|
+
type: zod.z.string().optional(),
|
|
1376
|
+
helpText: zod.z.string().optional(),
|
|
1377
|
+
helpTextHtml: zod.z.string().optional(),
|
|
1378
|
+
choices: zod.z.array(ActionFieldChoiceSchema).optional(),
|
|
1379
|
+
default: zod.z.string().optional(),
|
|
1380
|
+
placeholder: zod.z.string().optional(),
|
|
1381
|
+
computed: zod.z.boolean().optional(),
|
|
1382
|
+
customField: zod.z.boolean().optional(),
|
|
1383
|
+
dependsOn: zod.z.array(zod.z.string()).optional(),
|
|
1384
|
+
format: zod.z.string().optional(),
|
|
1385
|
+
inputFormat: zod.z.array(zod.z.string()).optional()
|
|
1386
|
+
});
|
|
1387
|
+
var AuthenticationSchema = zod.z.object({
|
|
1388
|
+
id: zod.z.number(),
|
|
1389
|
+
date: zod.z.string(),
|
|
1390
|
+
lastchanged: zod.z.string().optional(),
|
|
1391
|
+
account_id: zod.z.number(),
|
|
1392
|
+
customuser_id: zod.z.number().optional(),
|
|
1393
|
+
selected_api: zod.z.string(),
|
|
1394
|
+
destination_selected_api: zod.z.string().nullable().optional(),
|
|
1395
|
+
is_invite_only: zod.z.boolean(),
|
|
1396
|
+
is_private: zod.z.boolean(),
|
|
1397
|
+
shared_with_all: zod.z.boolean(),
|
|
1398
|
+
is_stale: zod.z.string().optional(),
|
|
1399
|
+
is_shared: zod.z.string().optional(),
|
|
1400
|
+
marked_stale_at: zod.z.string().nullable().optional(),
|
|
1401
|
+
label: zod.z.string().nullable().optional(),
|
|
1402
|
+
identifier: zod.z.string().nullable().optional(),
|
|
1403
|
+
title: zod.z.string().nullable().optional(),
|
|
1404
|
+
url: zod.z.string().optional(),
|
|
1405
|
+
groups: zod.z.string().optional(),
|
|
1406
|
+
members: zod.z.string().optional(),
|
|
1407
|
+
permissions: zod.z.record(zod.z.boolean()).optional()
|
|
1408
|
+
});
|
|
1409
|
+
zod.z.object({
|
|
1410
|
+
count: zod.z.number(),
|
|
1411
|
+
next: zod.z.string().nullable().optional(),
|
|
1412
|
+
previous: zod.z.string().nullable().optional(),
|
|
1413
|
+
results: zod.z.array(AuthenticationSchema)
|
|
1414
|
+
});
|
|
1415
|
+
var UserProfileSchema = zod.z.object({
|
|
1416
|
+
id: zod.z.number(),
|
|
1417
|
+
code: zod.z.string(),
|
|
1418
|
+
user_id: zod.z.number(),
|
|
1419
|
+
auto_provisioned: zod.z.boolean(),
|
|
1420
|
+
first_name: zod.z.string(),
|
|
1421
|
+
last_name: zod.z.string(),
|
|
1422
|
+
username: zod.z.string(),
|
|
1423
|
+
personas: zod.z.string(),
|
|
1424
|
+
user_generated_personas: zod.z.string(),
|
|
1425
|
+
last_login: zod.z.string(),
|
|
1426
|
+
email: zod.z.string(),
|
|
1427
|
+
email_hash: zod.z.string(),
|
|
1428
|
+
email_confirmed: zod.z.boolean(),
|
|
1429
|
+
timezone: zod.z.string(),
|
|
1430
|
+
photo_url: zod.z.string(),
|
|
1431
|
+
has_seen_notifications: zod.z.record(zod.z.boolean().nullable()),
|
|
1432
|
+
signup: zod.z.string(),
|
|
1433
|
+
since_signup: zod.z.string(),
|
|
1434
|
+
has_activated: zod.z.boolean(),
|
|
1435
|
+
enable_gz_creator: zod.z.boolean(),
|
|
1436
|
+
should_see_nps_survey: zod.z.boolean(),
|
|
1437
|
+
is_developer: zod.z.boolean(),
|
|
1438
|
+
is_expert: zod.z.boolean(),
|
|
1439
|
+
tos_agreement: zod.z.boolean(),
|
|
1440
|
+
should_renew_tos: zod.z.boolean(),
|
|
1441
|
+
is_gdpr_consented: zod.z.boolean(),
|
|
1442
|
+
disable_ssl_check: zod.z.boolean(),
|
|
1443
|
+
identity: zod.z.number(),
|
|
1444
|
+
summary_schedule: zod.z.string(),
|
|
1445
|
+
alert_triggers: zod.z.string(),
|
|
1446
|
+
alert_actions: zod.z.string(),
|
|
1447
|
+
is_staff: zod.z.boolean(),
|
|
1448
|
+
is_zt_reviewer: zod.z.boolean(),
|
|
1449
|
+
is_high_value: zod.z.boolean(),
|
|
1450
|
+
is_temporary: zod.z.boolean(),
|
|
1451
|
+
banner_message: zod.z.string(),
|
|
1452
|
+
enable_totp_2fa: zod.z.boolean(),
|
|
1453
|
+
viewed_help: zod.z.record(zod.z.boolean()),
|
|
1454
|
+
show_editor_migration_mesaging: zod.z.boolean(),
|
|
1455
|
+
switches: zod.z.record(zod.z.any()),
|
|
1456
|
+
organizations: zod.z.array(zod.z.any().nullable()),
|
|
1457
|
+
primary_organization: zod.z.any().nullable(),
|
|
1458
|
+
has_active_zaps: zod.z.boolean(),
|
|
1459
|
+
has_google_sso: zod.z.boolean(),
|
|
1460
|
+
auth_realm: zod.z.string(),
|
|
1461
|
+
roles: zod.z.array(
|
|
1462
|
+
zod.z.object({
|
|
1463
|
+
account_id: zod.z.number(),
|
|
1464
|
+
role: zod.z.string()
|
|
1465
|
+
})
|
|
1466
|
+
)
|
|
1467
|
+
});
|
|
1468
|
+
zod.z.object({
|
|
1469
|
+
age_in_days: zod.z.string().optional(),
|
|
1470
|
+
api_docs_url: zod.z.string().nullable().optional(),
|
|
1471
|
+
app_profile_url: zod.z.string(),
|
|
1472
|
+
banner: zod.z.string().optional(),
|
|
1473
|
+
categories: zod.z.array(zod.z.any()).optional(),
|
|
1474
|
+
// TODO: Define proper service_category type
|
|
1475
|
+
canonical_id: zod.z.string().optional(),
|
|
1476
|
+
current_implementation_id: zod.z.string(),
|
|
1477
|
+
days_since_last_update: zod.z.string().optional(),
|
|
1478
|
+
description: zod.z.string(),
|
|
1479
|
+
external_url: zod.z.string(),
|
|
1480
|
+
hashtag: zod.z.string().optional(),
|
|
1481
|
+
id: zod.z.number().optional(),
|
|
1482
|
+
image: zod.z.string().optional(),
|
|
1483
|
+
images: zod.z.string().optional(),
|
|
1484
|
+
integration_overview_html: zod.z.string().nullable().optional(),
|
|
1485
|
+
internal_id: zod.z.string(),
|
|
1486
|
+
invite_url: zod.z.string().nullable().optional(),
|
|
1487
|
+
is_beta: zod.z.string().optional(),
|
|
1488
|
+
is_built_in: zod.z.string().optional(),
|
|
1489
|
+
is_featured: zod.z.string().optional(),
|
|
1490
|
+
is_premium: zod.z.boolean().optional(),
|
|
1491
|
+
is_public: zod.z.string().optional(),
|
|
1492
|
+
is_upcoming: zod.z.string().optional(),
|
|
1493
|
+
learn_more_url: zod.z.string(),
|
|
1494
|
+
name: zod.z.string(),
|
|
1495
|
+
popularity: zod.z.number(),
|
|
1496
|
+
primary_color: zod.z.string(),
|
|
1497
|
+
request_count: zod.z.string().optional(),
|
|
1498
|
+
slug: zod.z.string(),
|
|
1499
|
+
zap_usage_count: zod.z.number().nullable().optional()
|
|
1500
|
+
});
|
|
1501
|
+
var ServiceSchema = zod.z.object({
|
|
1502
|
+
id: zod.z.number().optional(),
|
|
1503
|
+
canonical_id: zod.z.string().optional(),
|
|
1504
|
+
current_implementation_id: zod.z.string(),
|
|
1505
|
+
name: zod.z.string(),
|
|
1506
|
+
slug: zod.z.string(),
|
|
1507
|
+
app_url: zod.z.string().optional(),
|
|
1508
|
+
learn_more_url: zod.z.string().optional(),
|
|
1509
|
+
description: zod.z.string(),
|
|
1510
|
+
primary_color: zod.z.string(),
|
|
1511
|
+
popularity: zod.z.number(),
|
|
1512
|
+
image: zod.z.string().optional(),
|
|
1513
|
+
images: zod.z.string().optional()
|
|
1514
|
+
});
|
|
1515
|
+
zod.z.object({
|
|
1516
|
+
results: zod.z.array(ServiceSchema),
|
|
1517
|
+
next: zod.z.string().nullable().optional(),
|
|
1518
|
+
previous: zod.z.string().nullable().optional()
|
|
1519
|
+
});
|
|
1520
|
+
zod.z.object({
|
|
1521
|
+
selected_api: zod.z.string(),
|
|
1522
|
+
action: zod.z.string(),
|
|
1523
|
+
type_of: zod.z.string(),
|
|
1524
|
+
authentication_id: zod.z.number().optional(),
|
|
1525
|
+
params: zod.z.record(zod.z.any()).optional()
|
|
1526
|
+
});
|
|
1527
|
+
zod.z.object({
|
|
1528
|
+
success: zod.z.boolean(),
|
|
1529
|
+
needs: zod.z.array(NeedSchema).optional(),
|
|
1530
|
+
errors: zod.z.array(zod.z.string()).optional(),
|
|
1531
|
+
last_fetched_at: zod.z.string().optional()
|
|
1532
|
+
});
|
|
1533
|
+
var ImplementationSchema = zod.z.object({
|
|
1534
|
+
selected_api: zod.z.string(),
|
|
1535
|
+
app_id: zod.z.number().optional(),
|
|
1536
|
+
auth_type: zod.z.string().optional(),
|
|
1537
|
+
auth_fields: zod.z.string().optional(),
|
|
1538
|
+
actions: zod.z.array(ActionSchema).optional(),
|
|
1539
|
+
is_deprecated: zod.z.boolean().optional(),
|
|
1540
|
+
is_private_only: zod.z.boolean().optional(),
|
|
1541
|
+
is_invite_only: zod.z.boolean().optional(),
|
|
1542
|
+
is_beta: zod.z.boolean().optional().default(false),
|
|
1543
|
+
is_premium: zod.z.boolean().optional().default(false),
|
|
1544
|
+
is_hidden: zod.z.string().optional(),
|
|
1545
|
+
name: zod.z.string().optional(),
|
|
1546
|
+
slug: zod.z.string().optional(),
|
|
1547
|
+
images: zod.z.record(zod.z.string().nullable()).optional(),
|
|
1548
|
+
primary_color: zod.z.string().optional(),
|
|
1549
|
+
secondary_color: zod.z.string().optional(),
|
|
1550
|
+
current_implementation: zod.z.string().optional(),
|
|
1551
|
+
other_implementations: zod.z.string().optional()
|
|
1552
|
+
});
|
|
1553
|
+
zod.z.object({
|
|
1554
|
+
count: zod.z.number(),
|
|
1555
|
+
next: zod.z.string().nullable().optional(),
|
|
1556
|
+
previous: zod.z.string().nullable().optional(),
|
|
1557
|
+
results: zod.z.array(ImplementationSchema)
|
|
1558
|
+
});
|
|
1559
|
+
var ImplementationMetaSchema = zod.z.object({
|
|
1560
|
+
id: zod.z.string(),
|
|
1561
|
+
// e.g. "ZapierFormatterCLIAPI@1.0.7"
|
|
1562
|
+
name: zod.z.string(),
|
|
1563
|
+
slug: zod.z.string(),
|
|
1564
|
+
images: zod.z.object({
|
|
1565
|
+
url_16x16: zod.z.string().optional(),
|
|
1566
|
+
url_32x32: zod.z.string().optional(),
|
|
1567
|
+
url_64x64: zod.z.string().optional(),
|
|
1568
|
+
url_128x128: zod.z.string().optional()
|
|
1569
|
+
}).optional(),
|
|
1570
|
+
// Include other fields for completeness but we'll only use what we need
|
|
1571
|
+
ageInDays: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
|
|
1572
|
+
authType: zod.z.string().nullable().optional(),
|
|
1573
|
+
banner: zod.z.string().optional(),
|
|
1574
|
+
categories: zod.z.array(
|
|
1575
|
+
zod.z.object({
|
|
1576
|
+
id: zod.z.number(),
|
|
1577
|
+
name: zod.z.string(),
|
|
1578
|
+
slug: zod.z.string()
|
|
1579
|
+
})
|
|
1580
|
+
).optional(),
|
|
1581
|
+
isBeta: zod.z.boolean().optional(),
|
|
1582
|
+
isBuiltIn: zod.z.boolean().optional(),
|
|
1583
|
+
isDeprecated: zod.z.boolean().optional(),
|
|
1584
|
+
isFeatured: zod.z.boolean().optional(),
|
|
1585
|
+
isHidden: zod.z.boolean().optional(),
|
|
1586
|
+
isInvite: zod.z.boolean().optional(),
|
|
1587
|
+
isPremium: zod.z.boolean().optional(),
|
|
1588
|
+
isPublic: zod.z.boolean().optional(),
|
|
1589
|
+
isUpcoming: zod.z.boolean().optional(),
|
|
1590
|
+
popularity: zod.z.number().optional(),
|
|
1591
|
+
apiDocsUrl: zod.z.string().optional(),
|
|
1592
|
+
classification: zod.z.string().optional()
|
|
1593
|
+
});
|
|
1594
|
+
zod.z.object({
|
|
1595
|
+
count: zod.z.number(),
|
|
1596
|
+
next: zod.z.string().nullable().optional(),
|
|
1597
|
+
previous: zod.z.string().nullable().optional(),
|
|
1598
|
+
results: zod.z.array(ImplementationMetaSchema)
|
|
1599
|
+
});
|
|
1600
|
+
|
|
1601
|
+
// src/schemas/UserProfile.ts
|
|
1602
|
+
var UserProfileItemSchema = withFormatter(
|
|
1603
|
+
UserProfileSchema.omit({ user_id: true }).extend({
|
|
1604
|
+
full_name: zod.z.string()
|
|
1605
|
+
// Computed field: first_name + " " + last_name
|
|
1606
|
+
}),
|
|
1607
|
+
{
|
|
1608
|
+
format: (item) => {
|
|
1609
|
+
const details = [];
|
|
1610
|
+
details.push({ text: item.email, style: "dim" });
|
|
1611
|
+
if (item.timezone) {
|
|
1612
|
+
details.push({
|
|
1613
|
+
text: `Timezone: ${item.timezone}`,
|
|
1614
|
+
style: "accent"
|
|
1615
|
+
});
|
|
947
1616
|
}
|
|
1617
|
+
details.push({
|
|
1618
|
+
text: `Member since: ${item.since_signup}`,
|
|
1619
|
+
style: "dim"
|
|
1620
|
+
});
|
|
1621
|
+
return {
|
|
1622
|
+
title: item.full_name,
|
|
1623
|
+
subtitle: `@${item.username}`,
|
|
1624
|
+
details
|
|
1625
|
+
};
|
|
948
1626
|
}
|
|
949
1627
|
}
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
1628
|
+
);
|
|
1629
|
+
|
|
1630
|
+
// src/plugins/getProfile/schemas.ts
|
|
1631
|
+
var GetProfileSchema = withOutputSchema(
|
|
1632
|
+
zod.z.object({}).optional().describe("Get current user's profile information"),
|
|
1633
|
+
UserProfileItemSchema
|
|
1634
|
+
);
|
|
1635
|
+
|
|
1636
|
+
// src/plugins/getProfile/index.ts
|
|
1637
|
+
var getProfilePlugin = ({ context }) => {
|
|
1638
|
+
const getProfile = createFunction(async function getProfile2() {
|
|
1639
|
+
const profile = await context.api.get("/api/v4/profile/", {
|
|
1640
|
+
authRequired: true
|
|
1641
|
+
});
|
|
1642
|
+
const { user_id: _unusedUserId, ...data } = profile;
|
|
1643
|
+
return {
|
|
1644
|
+
data: {
|
|
1645
|
+
...data,
|
|
1646
|
+
// Pass through all API response fields
|
|
1647
|
+
full_name: `${profile.first_name} ${profile.last_name}`
|
|
1648
|
+
// Computed field
|
|
1649
|
+
}
|
|
957
1650
|
};
|
|
1651
|
+
}, GetProfileSchema);
|
|
1652
|
+
return {
|
|
1653
|
+
getProfile,
|
|
1654
|
+
context: {
|
|
1655
|
+
meta: {
|
|
1656
|
+
getProfile: {
|
|
1657
|
+
inputSchema: GetProfileSchema
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
}
|
|
1661
|
+
};
|
|
1662
|
+
};
|
|
1663
|
+
var AppItemSchema = withFormatter(
|
|
1664
|
+
zod.z.object({
|
|
1665
|
+
// Essential properties only
|
|
1666
|
+
title: zod.z.string(),
|
|
1667
|
+
// Mapped from name
|
|
1668
|
+
key: zod.z.string(),
|
|
1669
|
+
// Mapped from selected_api
|
|
1670
|
+
current_implementation_id: zod.z.string(),
|
|
1671
|
+
// From id, keeps the full version
|
|
1672
|
+
version: zod.z.string().optional(),
|
|
1673
|
+
// Extracted from implementation ID
|
|
1674
|
+
description: zod.z.string().optional(),
|
|
1675
|
+
slug: zod.z.string().optional()
|
|
1676
|
+
}),
|
|
1677
|
+
{
|
|
1678
|
+
format: (item) => {
|
|
1679
|
+
return {
|
|
1680
|
+
title: item.title,
|
|
1681
|
+
subtitle: `(${item.key})`,
|
|
1682
|
+
details: []
|
|
1683
|
+
};
|
|
1684
|
+
}
|
|
958
1685
|
}
|
|
959
|
-
|
|
960
|
-
}
|
|
1686
|
+
);
|
|
961
1687
|
|
|
962
|
-
// src/
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
(
|
|
971
|
-
)
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
}
|
|
975
|
-
return action;
|
|
976
|
-
}
|
|
1688
|
+
// src/plugins/listApps/schemas.ts
|
|
1689
|
+
var ListAppsSchema = withOutputSchema(
|
|
1690
|
+
zod.z.object({
|
|
1691
|
+
appKeys: zod.z.array(zod.z.string()).optional().describe(
|
|
1692
|
+
"Filter apps by app keys (e.g., 'SlackCLIAPI' or slug like 'github')"
|
|
1693
|
+
),
|
|
1694
|
+
search: zod.z.string().optional().describe("Search for apps by name"),
|
|
1695
|
+
pageSize: zod.z.number().min(1).optional().describe("Number of apps per page"),
|
|
1696
|
+
maxItems: zod.z.number().min(1).optional().describe("Maximum total items to return across all pages")
|
|
1697
|
+
}).describe("List all available apps with optional filtering"),
|
|
1698
|
+
AppItemSchema
|
|
1699
|
+
);
|
|
977
1700
|
|
|
978
|
-
// src/
|
|
979
|
-
|
|
980
|
-
const
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
authenticationId: providedAuthenticationId
|
|
986
|
-
} = options;
|
|
987
|
-
const api = getOrCreateApiClient(options);
|
|
988
|
-
const actionData = await getAction({
|
|
989
|
-
...options,
|
|
990
|
-
appKey,
|
|
991
|
-
actionKey,
|
|
992
|
-
actionType
|
|
993
|
-
});
|
|
994
|
-
if (actionData.type !== actionType) {
|
|
995
|
-
throw new Error(
|
|
996
|
-
`Action type mismatch: expected ${actionType}, got ${actionData.type}`
|
|
997
|
-
);
|
|
1701
|
+
// src/utils/domain-utils.ts
|
|
1702
|
+
function splitVersionedKey(versionedKey) {
|
|
1703
|
+
const parts = versionedKey.split("@");
|
|
1704
|
+
if (parts.length >= 2) {
|
|
1705
|
+
const baseKey = parts[0];
|
|
1706
|
+
const version = parts.slice(1).join("@");
|
|
1707
|
+
return [baseKey, version];
|
|
998
1708
|
}
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
actionKey,
|
|
1004
|
-
actionType: actionData.type,
|
|
1005
|
-
executionOptions: { inputs: inputs || {} },
|
|
1006
|
-
authenticationId: providedAuthenticationId,
|
|
1007
|
-
options
|
|
1008
|
-
});
|
|
1009
|
-
const executionTime = Date.now() - startTime;
|
|
1709
|
+
return [versionedKey, void 0];
|
|
1710
|
+
}
|
|
1711
|
+
function normalizeImplementationMetaToAppItem(implementationMeta) {
|
|
1712
|
+
const [selectedApi, appVersion] = splitVersionedKey(implementationMeta.id);
|
|
1010
1713
|
return {
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1714
|
+
title: implementationMeta.name,
|
|
1715
|
+
key: selectedApi,
|
|
1716
|
+
current_implementation_id: implementationMeta.id,
|
|
1717
|
+
// Keep the full versioned ID
|
|
1718
|
+
version: appVersion,
|
|
1719
|
+
// Extract version separately
|
|
1720
|
+
slug: implementationMeta.slug
|
|
1017
1721
|
};
|
|
1018
1722
|
}
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
api,
|
|
1032
|
-
token: options.token,
|
|
1033
|
-
baseUrl: options.baseUrl,
|
|
1034
|
-
debug: options.debug,
|
|
1035
|
-
fetch: options.fetch
|
|
1036
|
-
});
|
|
1037
|
-
const selectedApi = appData.current_implementation_id;
|
|
1038
|
-
if (!selectedApi) {
|
|
1039
|
-
throw new Error("No current_implementation_id found for app");
|
|
1040
|
-
}
|
|
1041
|
-
const runRequest = {
|
|
1042
|
-
data: {
|
|
1043
|
-
authentication_id: authenticationId || 1,
|
|
1044
|
-
selected_api: selectedApi,
|
|
1045
|
-
action_key: actionKey,
|
|
1046
|
-
action_type: actionType,
|
|
1047
|
-
inputs: executionOptions.inputs || {}
|
|
1723
|
+
function normalizeAuthenticationItem(auth, options = {}) {
|
|
1724
|
+
let appKey = options.app_key;
|
|
1725
|
+
let version = options.version;
|
|
1726
|
+
if (auth.selected_api) {
|
|
1727
|
+
const [extractedAppKey, extractedVersion] = splitVersionedKey(
|
|
1728
|
+
auth.selected_api
|
|
1729
|
+
);
|
|
1730
|
+
if (!appKey) {
|
|
1731
|
+
appKey = extractedAppKey;
|
|
1732
|
+
}
|
|
1733
|
+
if (!version) {
|
|
1734
|
+
version = extractedVersion;
|
|
1048
1735
|
}
|
|
1049
|
-
};
|
|
1050
|
-
const runData = await api.post("/api/actions/v1/runs", runRequest);
|
|
1051
|
-
const runId = runData.data.id;
|
|
1052
|
-
return await api.poll(`/api/actions/v1/runs/${runId}`, {
|
|
1053
|
-
successStatus: 200,
|
|
1054
|
-
pendingStatus: 202,
|
|
1055
|
-
resultExtractor: (result) => result.data
|
|
1056
|
-
});
|
|
1057
|
-
}
|
|
1058
|
-
|
|
1059
|
-
// src/functions/listFields/index.ts
|
|
1060
|
-
async function listFields(options) {
|
|
1061
|
-
const api = getOrCreateApiClient(options);
|
|
1062
|
-
const { appKey, actionKey, actionType, authenticationId, params } = options;
|
|
1063
|
-
const appData = await getApp({
|
|
1064
|
-
appKey,
|
|
1065
|
-
api,
|
|
1066
|
-
token: options.token,
|
|
1067
|
-
baseUrl: options.baseUrl,
|
|
1068
|
-
debug: options.debug,
|
|
1069
|
-
fetch: options.fetch
|
|
1070
|
-
});
|
|
1071
|
-
const selectedApi = appData.current_implementation_id;
|
|
1072
|
-
if (!selectedApi) {
|
|
1073
|
-
throw new Error("No current_implementation_id found for app");
|
|
1074
1736
|
}
|
|
1075
|
-
const
|
|
1737
|
+
const {
|
|
1076
1738
|
selected_api: selectedApi,
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1739
|
+
customuser_id: userId,
|
|
1740
|
+
...restOfAuth
|
|
1741
|
+
} = auth;
|
|
1742
|
+
return {
|
|
1743
|
+
...restOfAuth,
|
|
1744
|
+
// Pass through all other API response fields except selected_api
|
|
1745
|
+
implementation_id: selectedApi,
|
|
1746
|
+
// Rename selected_api to implementation_id
|
|
1747
|
+
title: auth.title || auth.label || void 0,
|
|
1748
|
+
// Coerce title from label if missing
|
|
1749
|
+
is_expired: auth.is_stale,
|
|
1750
|
+
// Map is_stale to is_expired
|
|
1751
|
+
expired_at: auth.marked_stale_at,
|
|
1752
|
+
// Map marked_stale_at to expired_at
|
|
1753
|
+
app_key: appKey,
|
|
1754
|
+
// App key from implementations endpoint or parsed from selected_api
|
|
1755
|
+
version,
|
|
1756
|
+
// Version from selected_api or provided
|
|
1757
|
+
user_id: userId
|
|
1758
|
+
// Map customuser_id to user_id
|
|
1081
1759
|
};
|
|
1082
|
-
const needsData = await api.post(
|
|
1083
|
-
"/api/v4/implementations/needs/",
|
|
1084
|
-
needsRequest
|
|
1085
|
-
);
|
|
1086
|
-
if (!needsData.success) {
|
|
1087
|
-
throw new Error(
|
|
1088
|
-
`Failed to get action fields: ${needsData.errors?.join(", ") || "Unknown error"}`
|
|
1089
|
-
);
|
|
1090
|
-
}
|
|
1091
|
-
return (needsData.needs || []).map((need) => ({
|
|
1092
|
-
key: need.key,
|
|
1093
|
-
label: need.label,
|
|
1094
|
-
required: need.required || false,
|
|
1095
|
-
type: need.type,
|
|
1096
|
-
helpText: need.help_text,
|
|
1097
|
-
helpTextHtml: need.help_text_html,
|
|
1098
|
-
choices: need.choices?.map((choice) => ({
|
|
1099
|
-
value: choice.value,
|
|
1100
|
-
label: choice.label
|
|
1101
|
-
})),
|
|
1102
|
-
default: need.default,
|
|
1103
|
-
placeholder: need.placeholder,
|
|
1104
|
-
computed: need.computed,
|
|
1105
|
-
customField: need.custom_field,
|
|
1106
|
-
dependsOn: need.depends_on,
|
|
1107
|
-
format: need.format,
|
|
1108
|
-
inputFormat: need.input_format
|
|
1109
|
-
}));
|
|
1110
1760
|
}
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1761
|
+
function normalizeActionItem(action) {
|
|
1762
|
+
const { name, type, selected_api: appKey, ...restOfAction } = action;
|
|
1763
|
+
return {
|
|
1764
|
+
...restOfAction,
|
|
1765
|
+
app_key: appKey || "",
|
|
1766
|
+
action_type: type,
|
|
1767
|
+
title: name,
|
|
1768
|
+
// Map name to title
|
|
1769
|
+
type: "action"
|
|
1770
|
+
};
|
|
1116
1771
|
}
|
|
1117
|
-
|
|
1118
|
-
const {
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
const
|
|
1124
|
-
const
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
const actionsWithFields = [];
|
|
1139
|
-
if (authenticationId) {
|
|
1140
|
-
for (const action of actions) {
|
|
1141
|
-
try {
|
|
1142
|
-
const fields = await listFields({
|
|
1143
|
-
...options,
|
|
1144
|
-
appKey: action.appKey,
|
|
1145
|
-
actionKey: action.key,
|
|
1146
|
-
actionType: action.type,
|
|
1147
|
-
authenticationId
|
|
1148
|
-
});
|
|
1149
|
-
actionsWithFields.push({ ...action, inputFields: fields });
|
|
1150
|
-
} catch {
|
|
1151
|
-
actionsWithFields.push({ ...action, inputFields: [] });
|
|
1772
|
+
function groupVersionedAppKeysByType(appKeys) {
|
|
1773
|
+
const result = {
|
|
1774
|
+
selectedApi: [],
|
|
1775
|
+
slug: []
|
|
1776
|
+
};
|
|
1777
|
+
const seenSelectedApi = /* @__PURE__ */ new Set();
|
|
1778
|
+
const seenSlugs = /* @__PURE__ */ new Set();
|
|
1779
|
+
for (const key of appKeys) {
|
|
1780
|
+
const [keyWithoutVersion, version] = splitVersionedKey(key);
|
|
1781
|
+
const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
1782
|
+
if (uuidRegex.test(keyWithoutVersion)) {
|
|
1783
|
+
throw new Error(
|
|
1784
|
+
`UUID app keys are not supported. Use app slug or implementation ID instead of: ${key}`
|
|
1785
|
+
);
|
|
1786
|
+
}
|
|
1787
|
+
if (isSnakeCasedSlug(keyWithoutVersion)) {
|
|
1788
|
+
const dashified = dashifySnakeCasedSlug(keyWithoutVersion);
|
|
1789
|
+
const slugWithVersion = version ? `${dashified}@${version}` : dashified;
|
|
1790
|
+
if (!seenSlugs.has(slugWithVersion)) {
|
|
1791
|
+
seenSlugs.add(slugWithVersion);
|
|
1792
|
+
result.slug.push(slugWithVersion);
|
|
1152
1793
|
}
|
|
1794
|
+
continue;
|
|
1795
|
+
}
|
|
1796
|
+
if (keyWithoutVersion.match(/^[a-z0-9]+(?:-[a-z0-9]+)*$/)) {
|
|
1797
|
+
seenSlugs.add(key);
|
|
1798
|
+
result.slug.push(key);
|
|
1799
|
+
continue;
|
|
1800
|
+
}
|
|
1801
|
+
if (!seenSelectedApi.has(key)) {
|
|
1802
|
+
seenSelectedApi.add(key);
|
|
1803
|
+
result.selectedApi.push(key);
|
|
1153
1804
|
}
|
|
1154
|
-
} else {
|
|
1155
|
-
actions.forEach((action) => {
|
|
1156
|
-
actionsWithFields.push({ ...action, inputFields: [] });
|
|
1157
|
-
});
|
|
1158
|
-
}
|
|
1159
|
-
const typeDefinitions = generateTypeDefinitions(
|
|
1160
|
-
app,
|
|
1161
|
-
actionsWithFields,
|
|
1162
|
-
version
|
|
1163
|
-
);
|
|
1164
|
-
if (output) {
|
|
1165
|
-
const fs = await import('fs');
|
|
1166
|
-
const path = await import('path');
|
|
1167
|
-
fs.mkdirSync(path.dirname(output), { recursive: true });
|
|
1168
|
-
fs.writeFileSync(output, typeDefinitions, "utf8");
|
|
1169
1805
|
}
|
|
1170
|
-
return
|
|
1806
|
+
return result;
|
|
1171
1807
|
}
|
|
1172
|
-
function
|
|
1173
|
-
const
|
|
1808
|
+
function groupAppKeysByType(appKeys) {
|
|
1809
|
+
const grouped = groupVersionedAppKeysByType(appKeys);
|
|
1174
1810
|
return {
|
|
1175
|
-
|
|
1176
|
-
|
|
1811
|
+
selectedApi: [
|
|
1812
|
+
...new Set(grouped.selectedApi.map((key) => key.split("@")[0]))
|
|
1813
|
+
],
|
|
1814
|
+
slug: [...new Set(grouped.slug.map((key) => key.split("@")[0]))]
|
|
1177
1815
|
};
|
|
1178
1816
|
}
|
|
1179
|
-
function
|
|
1180
|
-
if (
|
|
1181
|
-
|
|
1817
|
+
function isSnakeCasedSlug(slug) {
|
|
1818
|
+
if (slug.match(/^_[0-9]/)) {
|
|
1819
|
+
slug = slug.slice(1);
|
|
1182
1820
|
}
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
);
|
|
1193
|
-
|
|
1194
|
-
const versionComment = version ? ` * Generated for ${appKey}@${version}` : ` * Generated for ${appKey}`;
|
|
1195
|
-
let output = `/* eslint-disable @typescript-eslint/naming-convention */
|
|
1196
|
-
/**
|
|
1197
|
-
* Auto-generated TypeScript types for Zapier ${appKey} actions
|
|
1198
|
-
${versionComment}
|
|
1199
|
-
* Generated on: ${(/* @__PURE__ */ new Date()).toISOString()}
|
|
1200
|
-
*
|
|
1201
|
-
* Usage:
|
|
1202
|
-
* import type { ${appName}Sdk } from './path/to/this/file'
|
|
1203
|
-
* const sdk = createZapierSdk() as unknown as ${appName}Sdk
|
|
1204
|
-
*
|
|
1205
|
-
* // Direct usage (per-call auth):
|
|
1206
|
-
* await sdk.apps.${appKey}.search.user_by_email({ authenticationId: 123, inputs: { email } })
|
|
1207
|
-
*
|
|
1208
|
-
* // Factory usage (pinned auth):
|
|
1209
|
-
* const my${appName} = sdk.apps.${appKey}({ authenticationId: 123 })
|
|
1210
|
-
* await my${appName}.search.user_by_email({ inputs: { email } })
|
|
1211
|
-
*/
|
|
1212
|
-
|
|
1213
|
-
import type { ActionExecutionOptions, ActionExecutionResult } from '@zapier/zapier-sdk'
|
|
1214
|
-
import { z } from 'zod'
|
|
1215
|
-
import { RelayFetchSchema } from '@zapier/zapier-sdk'
|
|
1216
|
-
|
|
1217
|
-
`;
|
|
1218
|
-
actions.forEach((action) => {
|
|
1219
|
-
if (action.inputFields.length > 0) {
|
|
1220
|
-
const inputTypeName = `${appName}${capitalize(action.type)}${capitalize(
|
|
1221
|
-
sanitizeActionName(action.key)
|
|
1222
|
-
)}Inputs`;
|
|
1223
|
-
output += `interface ${inputTypeName} {
|
|
1224
|
-
`;
|
|
1225
|
-
action.inputFields.forEach((field) => {
|
|
1226
|
-
const isOptional = !field.required;
|
|
1227
|
-
const fieldType = mapFieldTypeToTypeScript(field);
|
|
1228
|
-
const description = field.helpText ? ` /** ${escapeComment(field.helpText)} */
|
|
1229
|
-
` : "";
|
|
1230
|
-
output += `${description} ${sanitizeFieldName(field.key)}${isOptional ? "?" : ""}: ${fieldType}
|
|
1231
|
-
`;
|
|
1232
|
-
});
|
|
1233
|
-
output += `}
|
|
1821
|
+
return !!slug.match(/^[a-z0-9]+(?:_[a-z0-9]+)*$/);
|
|
1822
|
+
}
|
|
1823
|
+
function dashifySnakeCasedSlug(slug) {
|
|
1824
|
+
if (!isSnakeCasedSlug(slug)) {
|
|
1825
|
+
return slug;
|
|
1826
|
+
}
|
|
1827
|
+
if (slug.startsWith("_")) {
|
|
1828
|
+
slug = slug.slice(1);
|
|
1829
|
+
}
|
|
1830
|
+
return slug.replace(/_/g, "-");
|
|
1831
|
+
}
|
|
1234
1832
|
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
const
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
typeActions.forEach((action) => {
|
|
1243
|
-
const actionName = sanitizeActionName(action.key);
|
|
1244
|
-
const description = action.description ? ` /** ${escapeComment(action.description)} */
|
|
1245
|
-
` : "";
|
|
1246
|
-
if (action.inputFields.length > 0) {
|
|
1247
|
-
const inputTypeName = `${appName}${capitalize(action.type)}${capitalize(
|
|
1248
|
-
sanitizeActionName(action.key)
|
|
1249
|
-
)}Inputs`;
|
|
1250
|
-
output += `${description} ${actionName}: (options: { inputs: ${inputTypeName} } & Omit<ActionExecutionOptions, 'inputs'>) => Promise<ActionExecutionResult>
|
|
1251
|
-
`;
|
|
1252
|
-
} else {
|
|
1253
|
-
output += `${description} ${actionName}: (options?: { inputs?: Record<string, any> } & ActionExecutionOptions) => Promise<ActionExecutionResult>
|
|
1254
|
-
`;
|
|
1255
|
-
}
|
|
1256
|
-
});
|
|
1257
|
-
output += `}
|
|
1258
|
-
|
|
1259
|
-
`;
|
|
1260
|
-
});
|
|
1261
|
-
output += `interface ${appName}AppProxy {
|
|
1262
|
-
`;
|
|
1263
|
-
Object.keys(actionsByType).forEach((actionType) => {
|
|
1264
|
-
const typeName = `${appName}${capitalize(actionType)}Actions`;
|
|
1265
|
-
output += ` ${actionType}: ${typeName}
|
|
1266
|
-
`;
|
|
1267
|
-
});
|
|
1268
|
-
output += generateFetchMethodSignature() + "\n";
|
|
1269
|
-
output += `}
|
|
1270
|
-
|
|
1271
|
-
`;
|
|
1272
|
-
output += `interface ${appName}AppFactory {
|
|
1273
|
-
`;
|
|
1274
|
-
output += ` (options: { authenticationId: number }): ${appName}AppProxy
|
|
1275
|
-
`;
|
|
1276
|
-
output += `}
|
|
1277
|
-
|
|
1278
|
-
`;
|
|
1279
|
-
output += `type ${appName}AppWithFactory = ${appName}AppFactory & ${appName}AppProxy
|
|
1280
|
-
|
|
1281
|
-
`;
|
|
1282
|
-
output += `export interface ${appName}Sdk {
|
|
1283
|
-
`;
|
|
1284
|
-
output += ` apps: {
|
|
1285
|
-
`;
|
|
1286
|
-
output += ` ${appKey}: ${appName}AppWithFactory
|
|
1287
|
-
`;
|
|
1288
|
-
output += ` }
|
|
1289
|
-
`;
|
|
1290
|
-
output += `}
|
|
1291
|
-
`;
|
|
1292
|
-
return output;
|
|
1293
|
-
}
|
|
1294
|
-
function generateEmptyTypesFile(appKey, version) {
|
|
1295
|
-
const appName = capitalize(appKey);
|
|
1296
|
-
const versionComment = version ? ` * Generated for ${appKey}@${version}` : ` * Generated for ${appKey}`;
|
|
1297
|
-
return `/* eslint-disable @typescript-eslint/naming-convention */
|
|
1298
|
-
/**
|
|
1299
|
-
* Auto-generated TypeScript types for Zapier ${appKey} actions
|
|
1300
|
-
${versionComment}
|
|
1301
|
-
* Generated on: ${(/* @__PURE__ */ new Date()).toISOString()}
|
|
1302
|
-
*
|
|
1303
|
-
* No actions found for this app.
|
|
1304
|
-
*/
|
|
1305
|
-
|
|
1306
|
-
import type { ActionExecutionOptions, ActionExecutionResult } from '@zapier/zapier-sdk'
|
|
1307
|
-
import { z } from 'zod'
|
|
1308
|
-
import { RelayFetchSchema } from '@zapier/zapier-sdk'
|
|
1309
|
-
|
|
1310
|
-
interface ${appName}AppProxy {
|
|
1311
|
-
// No actions available
|
|
1312
|
-
${generateFetchMethodSignature()}
|
|
1313
|
-
}
|
|
1314
|
-
|
|
1315
|
-
interface ${appName}AppFactory {
|
|
1316
|
-
(options: { authenticationId: number }): ${appName}AppProxy
|
|
1317
|
-
}
|
|
1318
|
-
|
|
1319
|
-
type ${appName}AppWithFactory = ${appName}AppFactory & ${appName}AppProxy
|
|
1320
|
-
|
|
1321
|
-
export interface ${appName}Sdk {
|
|
1322
|
-
apps: {
|
|
1323
|
-
${appKey}: ${appName}AppWithFactory
|
|
1324
|
-
}
|
|
1325
|
-
}
|
|
1326
|
-
`;
|
|
1327
|
-
}
|
|
1328
|
-
function capitalize(str) {
|
|
1329
|
-
return str.charAt(0).toUpperCase() + str.slice(1).replace(/[-_]/g, "");
|
|
1330
|
-
}
|
|
1331
|
-
function sanitizeActionName(actionKey) {
|
|
1332
|
-
let sanitized = actionKey.replace(/[^a-zA-Z0-9_$]/g, "_");
|
|
1333
|
-
if (/^[0-9]/.test(sanitized)) {
|
|
1334
|
-
sanitized = "_" + sanitized;
|
|
1335
|
-
}
|
|
1336
|
-
return sanitized;
|
|
1337
|
-
}
|
|
1338
|
-
function sanitizeFieldName(fieldKey) {
|
|
1339
|
-
let sanitized = fieldKey.replace(/[^a-zA-Z0-9_$]/g, "_");
|
|
1340
|
-
if (/^[0-9]/.test(sanitized)) {
|
|
1341
|
-
sanitized = "_" + sanitized;
|
|
1342
|
-
}
|
|
1343
|
-
return sanitized;
|
|
1344
|
-
}
|
|
1345
|
-
function escapeComment(comment) {
|
|
1346
|
-
return comment.replace(/\*\//g, "*\\/").replace(/\r?\n/g, " ");
|
|
1347
|
-
}
|
|
1348
|
-
function mapFieldTypeToTypeScript(field) {
|
|
1349
|
-
if (field.choices && field.choices.length > 0) {
|
|
1350
|
-
const choiceValues = field.choices.filter(
|
|
1351
|
-
(choice) => choice.value !== void 0 && choice.value !== null && choice.value !== ""
|
|
1352
|
-
).map(
|
|
1353
|
-
(choice) => typeof choice.value === "string" ? `"${choice.value}"` : choice.value
|
|
1833
|
+
// src/plugins/listApps/index.ts
|
|
1834
|
+
var listAppsPlugin = ({ context }) => {
|
|
1835
|
+
const listApps = createPaginatedFunction(async function listAppsPage(options) {
|
|
1836
|
+
const api = context.api;
|
|
1837
|
+
const opts = options;
|
|
1838
|
+
const appKeys = [...opts.appKeys ?? []].map(
|
|
1839
|
+
(key) => splitVersionedKey(key)[0]
|
|
1354
1840
|
);
|
|
1355
|
-
if (
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
case "url":
|
|
1364
|
-
case "password":
|
|
1365
|
-
return "string";
|
|
1366
|
-
case "integer":
|
|
1367
|
-
case "number":
|
|
1368
|
-
return "number";
|
|
1369
|
-
case "boolean":
|
|
1370
|
-
return "boolean";
|
|
1371
|
-
case "datetime":
|
|
1372
|
-
case "date":
|
|
1373
|
-
return "string";
|
|
1374
|
-
// ISO date strings
|
|
1375
|
-
case "file":
|
|
1376
|
-
return "string";
|
|
1377
|
-
// File URL or content
|
|
1378
|
-
case "array":
|
|
1379
|
-
return "any[]";
|
|
1380
|
-
case "object":
|
|
1381
|
-
return "Record<string, any>";
|
|
1382
|
-
default:
|
|
1383
|
-
return "string | number | boolean";
|
|
1384
|
-
}
|
|
1385
|
-
}
|
|
1386
|
-
|
|
1387
|
-
// src/functions/bundleCode/index.ts
|
|
1388
|
-
async function bundleCode(options) {
|
|
1389
|
-
const {
|
|
1390
|
-
input,
|
|
1391
|
-
output,
|
|
1392
|
-
target = "es2020",
|
|
1393
|
-
cjs = false,
|
|
1394
|
-
minify = false,
|
|
1395
|
-
string: returnString = false
|
|
1396
|
-
} = options;
|
|
1397
|
-
const { buildSync } = await import('esbuild');
|
|
1398
|
-
const fs = await import('fs');
|
|
1399
|
-
const path = await import('path');
|
|
1400
|
-
const resolvedInput = path.resolve(process.cwd(), input);
|
|
1401
|
-
try {
|
|
1402
|
-
const result = buildSync({
|
|
1403
|
-
entryPoints: [resolvedInput],
|
|
1404
|
-
bundle: true,
|
|
1405
|
-
platform: "node",
|
|
1406
|
-
target,
|
|
1407
|
-
format: cjs ? "cjs" : "esm",
|
|
1408
|
-
minify,
|
|
1409
|
-
write: false,
|
|
1410
|
-
external: [],
|
|
1411
|
-
// Bundle everything
|
|
1412
|
-
banner: {
|
|
1413
|
-
js: "#!/usr/bin/env node"
|
|
1414
|
-
}
|
|
1415
|
-
});
|
|
1416
|
-
if (result.errors.length > 0) {
|
|
1417
|
-
throw new Error(
|
|
1418
|
-
`Bundle failed: ${result.errors.map((e) => e.text).join(", ")}`
|
|
1841
|
+
if (opts.search) {
|
|
1842
|
+
const searchParams2 = {};
|
|
1843
|
+
searchParams2.term = opts.search;
|
|
1844
|
+
const searchEnvelope = await api.get(
|
|
1845
|
+
"/api/v4/implementations-meta/search/",
|
|
1846
|
+
{
|
|
1847
|
+
searchParams: searchParams2
|
|
1848
|
+
}
|
|
1419
1849
|
);
|
|
1850
|
+
const implementations = searchEnvelope.results.map(
|
|
1851
|
+
normalizeImplementationMetaToAppItem
|
|
1852
|
+
);
|
|
1853
|
+
const appKeysSet = new Set(appKeys);
|
|
1854
|
+
for (const implementation of implementations) {
|
|
1855
|
+
if (!appKeysSet.has(implementation.key)) {
|
|
1856
|
+
appKeysSet.add(implementation.key);
|
|
1857
|
+
appKeys.push(implementation.key);
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1420
1860
|
}
|
|
1421
|
-
const
|
|
1422
|
-
if (
|
|
1423
|
-
|
|
1424
|
-
}
|
|
1425
|
-
let finalOutput = bundledCode;
|
|
1426
|
-
if (returnString) {
|
|
1427
|
-
finalOutput = JSON.stringify(bundledCode);
|
|
1861
|
+
const searchParams = {};
|
|
1862
|
+
if (opts.pageSize) {
|
|
1863
|
+
searchParams.limit = opts.pageSize.toString();
|
|
1428
1864
|
}
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1865
|
+
searchParams.latest_only = "true";
|
|
1866
|
+
if (opts.cursor) {
|
|
1867
|
+
searchParams.offset = opts.cursor;
|
|
1432
1868
|
}
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
// src/functions/request/index.ts
|
|
1442
|
-
function transformUrlToRelayPath(url) {
|
|
1443
|
-
const targetUrl = new URL(url);
|
|
1444
|
-
const relayPath = `/relay/${targetUrl.hostname}${targetUrl.pathname}${targetUrl.search}${targetUrl.hash}`;
|
|
1445
|
-
return relayPath;
|
|
1446
|
-
}
|
|
1447
|
-
async function request(options) {
|
|
1448
|
-
const {
|
|
1449
|
-
url,
|
|
1450
|
-
method = "GET",
|
|
1451
|
-
body,
|
|
1452
|
-
headers,
|
|
1453
|
-
authenticationId,
|
|
1454
|
-
callbackUrl,
|
|
1455
|
-
authenticationTemplate,
|
|
1456
|
-
...config
|
|
1457
|
-
} = options;
|
|
1458
|
-
return relayFetch(
|
|
1459
|
-
url,
|
|
1460
|
-
{
|
|
1461
|
-
method,
|
|
1462
|
-
body,
|
|
1463
|
-
headers,
|
|
1464
|
-
authenticationId,
|
|
1465
|
-
callbackUrl,
|
|
1466
|
-
authenticationTemplate
|
|
1467
|
-
},
|
|
1468
|
-
config
|
|
1469
|
-
);
|
|
1470
|
-
}
|
|
1471
|
-
async function relayFetch(url, options = {}, config = {}) {
|
|
1472
|
-
const api = getOrCreateApiClient(config);
|
|
1473
|
-
const {
|
|
1474
|
-
authenticationId,
|
|
1475
|
-
callbackUrl,
|
|
1476
|
-
authenticationTemplate,
|
|
1477
|
-
method = "GET",
|
|
1478
|
-
body,
|
|
1479
|
-
...fetchOptions
|
|
1480
|
-
} = options;
|
|
1481
|
-
const relayPath = transformUrlToRelayPath(url);
|
|
1482
|
-
const headers = {};
|
|
1483
|
-
if (fetchOptions.headers) {
|
|
1484
|
-
const headerEntries = fetchOptions.headers instanceof Headers ? Array.from(fetchOptions.headers.entries()) : Object.entries(fetchOptions.headers);
|
|
1485
|
-
for (const [key, value] of headerEntries) {
|
|
1486
|
-
headers[key] = value;
|
|
1869
|
+
if (appKeys.length > 0) {
|
|
1870
|
+
const groupedAppKeys = groupAppKeysByType(appKeys);
|
|
1871
|
+
if (groupedAppKeys.selectedApi.length > 0) {
|
|
1872
|
+
searchParams.selected_apis = groupedAppKeys.selectedApi.join(",");
|
|
1873
|
+
}
|
|
1874
|
+
if (groupedAppKeys.slug.length > 0) {
|
|
1875
|
+
searchParams.slugs = groupedAppKeys.slug.join(",");
|
|
1876
|
+
}
|
|
1487
1877
|
}
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
if (callbackUrl) {
|
|
1493
|
-
headers["X-Relay-Callback-Url"] = callbackUrl;
|
|
1494
|
-
}
|
|
1495
|
-
if (authenticationTemplate) {
|
|
1496
|
-
headers["X-Authentication-Template"] = authenticationTemplate;
|
|
1497
|
-
}
|
|
1498
|
-
return await api.fetch(relayPath, {
|
|
1499
|
-
method,
|
|
1500
|
-
body,
|
|
1501
|
-
headers
|
|
1502
|
-
});
|
|
1503
|
-
}
|
|
1504
|
-
var RelayRequestSchema = zod.z.object({
|
|
1505
|
-
url: zod.z.string().url().describe("The URL to request (will be proxied through Relay)"),
|
|
1506
|
-
method: zod.z.enum(["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"]).optional().describe("HTTP method"),
|
|
1507
|
-
body: zod.z.string().optional().describe("Request body as a string"),
|
|
1508
|
-
authenticationId: zod.z.number().int().optional().describe("Zapier authentication ID to use for the request"),
|
|
1509
|
-
callbackUrl: zod.z.string().url().optional().describe("URL to send async response to (makes request async)"),
|
|
1510
|
-
authenticationTemplate: zod.z.string().optional().describe(
|
|
1511
|
-
"Optional JSON string authentication template to bypass Notary lookup"
|
|
1512
|
-
),
|
|
1513
|
-
headers: zod.z.record(zod.z.string()).optional().describe("Request headers")
|
|
1514
|
-
}).describe("Make authenticated HTTP requests through Zapier's Relay service");
|
|
1515
|
-
var RelayFetchSchema = RelayRequestSchema;
|
|
1516
|
-
var AppItemSchema = withFormatter(
|
|
1517
|
-
zod.z.object({
|
|
1518
|
-
key: zod.z.string(),
|
|
1519
|
-
name: zod.z.string().optional(),
|
|
1520
|
-
description: zod.z.string().optional(),
|
|
1521
|
-
category: zod.z.string().optional()
|
|
1522
|
-
}),
|
|
1523
|
-
{
|
|
1524
|
-
format: (item) => {
|
|
1525
|
-
const details = [];
|
|
1526
|
-
if (item.description) {
|
|
1527
|
-
details.push({ text: item.description, style: "dim" });
|
|
1878
|
+
const implementationsEnvelope = await api.get(
|
|
1879
|
+
"/api/v4/implementations-meta/lookup/",
|
|
1880
|
+
{
|
|
1881
|
+
searchParams
|
|
1528
1882
|
}
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1883
|
+
);
|
|
1884
|
+
return {
|
|
1885
|
+
data: implementationsEnvelope.results.map(
|
|
1886
|
+
normalizeImplementationMetaToAppItem
|
|
1887
|
+
),
|
|
1888
|
+
nextCursor: extractCursor(implementationsEnvelope)
|
|
1889
|
+
};
|
|
1890
|
+
}, ListAppsSchema);
|
|
1891
|
+
return {
|
|
1892
|
+
listApps,
|
|
1893
|
+
context: {
|
|
1894
|
+
meta: {
|
|
1895
|
+
listApps: {
|
|
1896
|
+
inputSchema: ListAppsSchema
|
|
1897
|
+
}
|
|
1534
1898
|
}
|
|
1535
|
-
return {
|
|
1536
|
-
title: item.name || item.key,
|
|
1537
|
-
subtitle: `(${item.key})`,
|
|
1538
|
-
details
|
|
1539
|
-
};
|
|
1540
1899
|
}
|
|
1541
|
-
}
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
// src/functions/listApps/schemas.ts
|
|
1545
|
-
var ListAppsSchema = withOutputSchema(
|
|
1900
|
+
};
|
|
1901
|
+
};
|
|
1902
|
+
var GetAppSchema = withOutputSchema(
|
|
1546
1903
|
zod.z.object({
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
"Maximum number of items to return (1-200)"
|
|
1550
|
-
),
|
|
1551
|
-
offset: OffsetPropertySchema.optional().describe(
|
|
1552
|
-
"Number of items to skip for pagination"
|
|
1904
|
+
appKey: AppKeyPropertySchema.describe(
|
|
1905
|
+
"App key of app to fetch (e.g., 'SlackCLIAPI')"
|
|
1553
1906
|
)
|
|
1554
|
-
}).describe("
|
|
1907
|
+
}).describe("Get detailed information about a specific app"),
|
|
1555
1908
|
AppItemSchema
|
|
1556
1909
|
);
|
|
1557
1910
|
|
|
1558
|
-
// src/
|
|
1559
|
-
var
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1911
|
+
// src/plugins/getApp/index.ts
|
|
1912
|
+
var getAppPlugin = ({ sdk }) => {
|
|
1913
|
+
const getApp = createFunction(async function getApp2(options) {
|
|
1914
|
+
const { appKey } = options;
|
|
1915
|
+
const appsIterator = sdk.listApps({
|
|
1916
|
+
...options,
|
|
1917
|
+
appKeys: [appKey]
|
|
1918
|
+
}).items();
|
|
1919
|
+
const apps = [];
|
|
1920
|
+
for await (const app of appsIterator) {
|
|
1921
|
+
apps.push(app);
|
|
1922
|
+
break;
|
|
1923
|
+
}
|
|
1924
|
+
if (apps.length === 0) {
|
|
1925
|
+
throw new ZapierAppNotFoundError(appKey);
|
|
1926
|
+
}
|
|
1927
|
+
return {
|
|
1928
|
+
data: apps[0]
|
|
1929
|
+
};
|
|
1930
|
+
}, GetAppSchema);
|
|
1931
|
+
return {
|
|
1932
|
+
getApp,
|
|
1933
|
+
context: {
|
|
1934
|
+
meta: {
|
|
1935
|
+
getApp: {
|
|
1936
|
+
inputSchema: GetAppSchema
|
|
1937
|
+
}
|
|
1938
|
+
}
|
|
1939
|
+
}
|
|
1940
|
+
};
|
|
1575
1941
|
};
|
|
1576
1942
|
var ActionItemSchema = withFormatter(
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1943
|
+
ActionSchema.omit({ type: true, name: true }).extend({
|
|
1944
|
+
app_key: zod.z.string(),
|
|
1945
|
+
// Mapped from selected_api
|
|
1946
|
+
action_type: ActionSchema.shape.type,
|
|
1947
|
+
// Mapped from original 'type' field
|
|
1948
|
+
title: zod.z.string(),
|
|
1949
|
+
// Mapped from original 'name' field
|
|
1950
|
+
type: zod.z.literal("action")
|
|
1951
|
+
// Fixed type identifier
|
|
1583
1952
|
}),
|
|
1584
1953
|
{
|
|
1585
1954
|
format: (item) => {
|
|
1586
1955
|
const details = [];
|
|
1587
|
-
details.push({
|
|
1588
|
-
|
|
1589
|
-
|
|
1956
|
+
details.push({
|
|
1957
|
+
text: `Type: ${item.action_type}`,
|
|
1958
|
+
style: "accent"
|
|
1959
|
+
});
|
|
1960
|
+
if (item.app_key) {
|
|
1961
|
+
details.push({
|
|
1962
|
+
text: `App: ${item.app_key}`,
|
|
1963
|
+
style: "normal"
|
|
1964
|
+
});
|
|
1590
1965
|
}
|
|
1591
1966
|
if (item.description) {
|
|
1592
1967
|
details.push({ text: item.description, style: "dim" });
|
|
1593
1968
|
}
|
|
1594
1969
|
return {
|
|
1595
|
-
title: item.name || item.key,
|
|
1970
|
+
title: item.title || item.name || item.key,
|
|
1596
1971
|
subtitle: `(${item.key})`,
|
|
1597
1972
|
details
|
|
1598
1973
|
};
|
|
@@ -1600,22 +1975,88 @@ var ActionItemSchema = withFormatter(
|
|
|
1600
1975
|
}
|
|
1601
1976
|
);
|
|
1602
1977
|
|
|
1603
|
-
// src/
|
|
1978
|
+
// src/plugins/listActions/schemas.ts
|
|
1604
1979
|
var ListActionsSchema = withOutputSchema(
|
|
1605
1980
|
zod.z.object({
|
|
1606
|
-
appKey: AppKeyPropertySchema.
|
|
1607
|
-
|
|
1981
|
+
appKey: AppKeyPropertySchema.describe(
|
|
1982
|
+
"App key of actions to list (e.g., 'SlackCLIAPI')"
|
|
1983
|
+
),
|
|
1984
|
+
actionType: ActionTypePropertySchema.optional().describe(
|
|
1608
1985
|
"Filter actions by type"
|
|
1609
|
-
)
|
|
1986
|
+
),
|
|
1987
|
+
pageSize: zod.z.number().min(1).optional().describe("Number of actions per page"),
|
|
1988
|
+
maxItems: zod.z.number().min(1).optional().describe("Maximum total items to return across all pages")
|
|
1610
1989
|
}).describe("List all actions for a specific app"),
|
|
1611
1990
|
ActionItemSchema
|
|
1612
1991
|
);
|
|
1613
1992
|
|
|
1614
|
-
// src/
|
|
1615
|
-
var
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1993
|
+
// src/plugins/listActions/index.ts
|
|
1994
|
+
var listActionsPlugin = ({ sdk, context }) => {
|
|
1995
|
+
const listActions = createPaginatedFunction(async function listActionsPage(options) {
|
|
1996
|
+
const { api } = context;
|
|
1997
|
+
const app = await sdk.getApp({ appKey: options.appKey });
|
|
1998
|
+
const implementationId = app.data.current_implementation_id?.split("@")[0];
|
|
1999
|
+
if (!implementationId) {
|
|
2000
|
+
throw new ZapierConfigurationError(
|
|
2001
|
+
"No current_implementation_id found for app",
|
|
2002
|
+
{ configType: "current_implementation_id" }
|
|
2003
|
+
);
|
|
2004
|
+
}
|
|
2005
|
+
const searchParams = {
|
|
2006
|
+
global: "true",
|
|
2007
|
+
public_only: "true",
|
|
2008
|
+
selected_apis: implementationId
|
|
2009
|
+
};
|
|
2010
|
+
const data = await api.get("/api/v4/implementations/", {
|
|
2011
|
+
searchParams,
|
|
2012
|
+
customErrorHandler: ({ status }) => {
|
|
2013
|
+
if (status === 401) {
|
|
2014
|
+
return new ZapierAuthenticationError(
|
|
2015
|
+
`Authentication failed. Your token may not have permission to access implementations or may be expired. (HTTP ${status})`,
|
|
2016
|
+
{ statusCode: status }
|
|
2017
|
+
);
|
|
2018
|
+
}
|
|
2019
|
+
if (status === 403) {
|
|
2020
|
+
return new ZapierAuthenticationError(
|
|
2021
|
+
`Access forbidden. Your token may not have the required scopes to list implementations. (HTTP ${status})`,
|
|
2022
|
+
{ statusCode: status }
|
|
2023
|
+
);
|
|
2024
|
+
}
|
|
2025
|
+
return void 0;
|
|
2026
|
+
}
|
|
2027
|
+
});
|
|
2028
|
+
let allActions = [];
|
|
2029
|
+
for (const implementation of data.results || []) {
|
|
2030
|
+
if (implementation.actions) {
|
|
2031
|
+
for (const action of implementation.actions) {
|
|
2032
|
+
const actionWithContext = {
|
|
2033
|
+
...action,
|
|
2034
|
+
selected_api: action.selected_api || implementation.selected_api
|
|
2035
|
+
};
|
|
2036
|
+
allActions.push(normalizeActionItem(actionWithContext));
|
|
2037
|
+
}
|
|
2038
|
+
}
|
|
2039
|
+
}
|
|
2040
|
+
if (options.actionType) {
|
|
2041
|
+
allActions = allActions.filter(
|
|
2042
|
+
(action) => action.action_type === options.actionType
|
|
2043
|
+
);
|
|
2044
|
+
}
|
|
2045
|
+
return {
|
|
2046
|
+
data: allActions,
|
|
2047
|
+
nextCursor: void 0
|
|
2048
|
+
};
|
|
2049
|
+
}, ListActionsSchema);
|
|
2050
|
+
return {
|
|
2051
|
+
listActions,
|
|
2052
|
+
context: {
|
|
2053
|
+
meta: {
|
|
2054
|
+
listActions: {
|
|
2055
|
+
inputSchema: ListActionsSchema
|
|
2056
|
+
}
|
|
2057
|
+
}
|
|
2058
|
+
}
|
|
2059
|
+
};
|
|
1619
2060
|
};
|
|
1620
2061
|
var GetActionSchema = zod.z.object({
|
|
1621
2062
|
appKey: AppKeyPropertySchema,
|
|
@@ -1623,300 +2064,589 @@ var GetActionSchema = zod.z.object({
|
|
|
1623
2064
|
actionKey: ActionKeyPropertySchema
|
|
1624
2065
|
}).describe("Get detailed information about a specific action");
|
|
1625
2066
|
|
|
1626
|
-
// src/
|
|
1627
|
-
var
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
2067
|
+
// src/plugins/getAction/index.ts
|
|
2068
|
+
var getActionPlugin = ({ sdk }) => {
|
|
2069
|
+
const getAction = createFunction(async function getAction2(options) {
|
|
2070
|
+
const { actionKey, actionType, appKey } = options;
|
|
2071
|
+
const actionsResult = await sdk.listActions({ appKey });
|
|
2072
|
+
for (const action of actionsResult.data) {
|
|
2073
|
+
if (action.key === actionKey && action.action_type === actionType) {
|
|
2074
|
+
return { data: action };
|
|
2075
|
+
}
|
|
2076
|
+
}
|
|
2077
|
+
throw new ZapierResourceNotFoundError(
|
|
2078
|
+
`Action not found: ${actionKey} with type ${actionType}`,
|
|
2079
|
+
{ resourceType: "Action", resourceId: `${actionKey} (${actionType})` }
|
|
2080
|
+
);
|
|
2081
|
+
}, GetActionSchema);
|
|
2082
|
+
return {
|
|
2083
|
+
getAction,
|
|
2084
|
+
context: {
|
|
2085
|
+
meta: {
|
|
2086
|
+
getAction: {
|
|
2087
|
+
inputSchema: GetActionSchema
|
|
2088
|
+
}
|
|
2089
|
+
}
|
|
2090
|
+
}
|
|
2091
|
+
};
|
|
1631
2092
|
};
|
|
1632
2093
|
var RunActionSchema = zod.z.object({
|
|
1633
2094
|
appKey: AppKeyPropertySchema,
|
|
1634
2095
|
actionType: ActionTypePropertySchema,
|
|
1635
2096
|
actionKey: ActionKeyPropertySchema,
|
|
2097
|
+
authenticationId: AuthenticationIdPropertySchema.nullable().optional(),
|
|
1636
2098
|
inputs: InputsPropertySchema.optional().describe(
|
|
1637
2099
|
"Input parameters for the action"
|
|
1638
2100
|
),
|
|
1639
|
-
|
|
2101
|
+
pageSize: zod.z.number().min(1).optional().describe("Number of results per page"),
|
|
2102
|
+
maxItems: zod.z.number().min(1).optional().describe("Maximum total items to return across all pages")
|
|
1640
2103
|
}).describe("Execute an action with the given inputs");
|
|
1641
2104
|
|
|
1642
|
-
// src/
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
2105
|
+
// src/plugins/runAction/index.ts
|
|
2106
|
+
async function executeAction(actionOptions) {
|
|
2107
|
+
const {
|
|
2108
|
+
api,
|
|
2109
|
+
sdk,
|
|
2110
|
+
appKey,
|
|
2111
|
+
actionKey,
|
|
2112
|
+
actionType,
|
|
2113
|
+
executionOptions,
|
|
2114
|
+
authenticationId
|
|
2115
|
+
} = actionOptions;
|
|
2116
|
+
const appData = await sdk.getApp({ appKey });
|
|
2117
|
+
const selectedApi = appData.data.current_implementation_id;
|
|
2118
|
+
if (!selectedApi) {
|
|
2119
|
+
throw new ZapierConfigurationError(
|
|
2120
|
+
"No current_implementation_id found for app",
|
|
2121
|
+
{ configType: "current_implementation_id" }
|
|
2122
|
+
);
|
|
2123
|
+
}
|
|
2124
|
+
const runRequestData = {
|
|
2125
|
+
selected_api: selectedApi,
|
|
2126
|
+
action_key: actionKey,
|
|
2127
|
+
action_type: actionType,
|
|
2128
|
+
inputs: executionOptions.inputs || {}
|
|
2129
|
+
};
|
|
2130
|
+
if (authenticationId !== null && authenticationId !== void 0) {
|
|
2131
|
+
runRequestData.authentication_id = authenticationId;
|
|
2132
|
+
}
|
|
2133
|
+
const runRequest = {
|
|
2134
|
+
data: runRequestData
|
|
2135
|
+
};
|
|
2136
|
+
const runData = await api.post("/api/actions/v1/runs", runRequest);
|
|
2137
|
+
const runId = runData.data.id;
|
|
2138
|
+
return await api.poll(`/api/actions/v1/runs/${runId}`, {
|
|
2139
|
+
successStatus: 200,
|
|
2140
|
+
pendingStatus: 202,
|
|
2141
|
+
resultExtractor: (result) => result.data
|
|
2142
|
+
});
|
|
2143
|
+
}
|
|
2144
|
+
var runActionPlugin = ({ sdk, context }) => {
|
|
2145
|
+
const runAction = createPaginatedFunction(async function runActionPage(options) {
|
|
2146
|
+
const { api } = context;
|
|
2147
|
+
const {
|
|
2148
|
+
appKey,
|
|
2149
|
+
actionKey,
|
|
2150
|
+
actionType,
|
|
2151
|
+
authenticationId,
|
|
2152
|
+
inputs = {}
|
|
2153
|
+
} = options;
|
|
2154
|
+
const actionData = await sdk.getAction({
|
|
2155
|
+
appKey,
|
|
2156
|
+
actionKey,
|
|
2157
|
+
actionType
|
|
2158
|
+
});
|
|
2159
|
+
if (actionData.data.action_type !== actionType) {
|
|
2160
|
+
throw new ZapierValidationError(
|
|
2161
|
+
`Action type mismatch: expected ${actionType}, got ${actionData.data.action_type}`
|
|
2162
|
+
);
|
|
2163
|
+
}
|
|
2164
|
+
const result = await executeAction({
|
|
2165
|
+
api,
|
|
2166
|
+
sdk,
|
|
2167
|
+
appKey,
|
|
2168
|
+
actionKey,
|
|
2169
|
+
actionType,
|
|
2170
|
+
executionOptions: { inputs },
|
|
2171
|
+
authenticationId});
|
|
2172
|
+
if (result.errors && result.errors.length > 0) {
|
|
2173
|
+
const errorMessage = result.errors.map(
|
|
2174
|
+
(error) => error.detail || error.title || "Unknown error"
|
|
2175
|
+
).join("; ");
|
|
2176
|
+
throw new ZapierActionError(`Action execution failed: ${errorMessage}`, {
|
|
2177
|
+
appKey,
|
|
2178
|
+
actionKey
|
|
2179
|
+
});
|
|
2180
|
+
}
|
|
2181
|
+
return {
|
|
2182
|
+
data: result.results || [],
|
|
2183
|
+
nextCursor: void 0
|
|
2184
|
+
// No pagination implemented yet
|
|
2185
|
+
};
|
|
2186
|
+
}, RunActionSchema);
|
|
2187
|
+
return {
|
|
2188
|
+
runAction,
|
|
2189
|
+
context: {
|
|
2190
|
+
meta: {
|
|
2191
|
+
runAction: {
|
|
2192
|
+
inputSchema: RunActionSchema
|
|
2193
|
+
}
|
|
2194
|
+
}
|
|
2195
|
+
}
|
|
2196
|
+
};
|
|
1647
2197
|
};
|
|
1648
|
-
var
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
2198
|
+
var ListAuthenticationsSchema = zod.z.object({
|
|
2199
|
+
appKey: AppKeyPropertySchema.optional().describe(
|
|
2200
|
+
"App key of authentications to list (e.g., 'SlackCLIAPI')"
|
|
2201
|
+
),
|
|
2202
|
+
search: zod.z.string().optional().describe("Search term to filter authentications by title"),
|
|
2203
|
+
title: zod.z.string().optional().describe("Filter authentications by exact title match"),
|
|
2204
|
+
account_id: zod.z.string().optional().describe("Filter by account ID"),
|
|
2205
|
+
owner: zod.z.string().optional().describe("Filter by owner"),
|
|
2206
|
+
pageSize: zod.z.number().min(1).optional().describe("Number of authentications per page"),
|
|
2207
|
+
maxItems: zod.z.number().min(1).optional().describe("Maximum total items to return across all pages")
|
|
2208
|
+
}).describe("List available authentications with optional filtering");
|
|
2209
|
+
|
|
2210
|
+
// src/plugins/listAuthentications/index.ts
|
|
2211
|
+
var listAuthenticationsPlugin = ({ sdk, context }) => {
|
|
2212
|
+
const listAuthentications = createPaginatedFunction(
|
|
2213
|
+
async function listAuthenticationsPage(options) {
|
|
2214
|
+
const { api } = context;
|
|
2215
|
+
const searchParams = {};
|
|
2216
|
+
if (options.appKey) {
|
|
2217
|
+
const app = await sdk.getApp({
|
|
2218
|
+
appKey: options.appKey
|
|
1665
2219
|
});
|
|
2220
|
+
const selectedApi = app.data.current_implementation_id;
|
|
2221
|
+
if (selectedApi) {
|
|
2222
|
+
const versionlessApi = selectedApi.split("@")[0];
|
|
2223
|
+
searchParams.versionless_selected_api = versionlessApi;
|
|
2224
|
+
}
|
|
1666
2225
|
}
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
2226
|
+
if (options.search) {
|
|
2227
|
+
searchParams.search = options.search;
|
|
2228
|
+
} else if (options.title) {
|
|
2229
|
+
searchParams.search = options.title;
|
|
2230
|
+
}
|
|
2231
|
+
if (options.account_id) {
|
|
2232
|
+
searchParams.account_id = options.account_id;
|
|
2233
|
+
}
|
|
2234
|
+
if (options.owner) {
|
|
2235
|
+
searchParams.owner = options.owner;
|
|
2236
|
+
}
|
|
2237
|
+
searchParams.limit = options.pageSize.toString();
|
|
2238
|
+
if (options.cursor) {
|
|
2239
|
+
searchParams.offset = options.cursor;
|
|
2240
|
+
}
|
|
2241
|
+
const data = await api.get(
|
|
2242
|
+
"/api/v4/authentications/",
|
|
2243
|
+
{
|
|
2244
|
+
searchParams,
|
|
2245
|
+
customErrorHandler: ({ status }) => {
|
|
2246
|
+
if (status === 401) {
|
|
2247
|
+
return new ZapierAuthenticationError(
|
|
2248
|
+
`Authentication failed. Your token may not have permission to access authentications or may be expired. (HTTP ${status})`,
|
|
2249
|
+
{ statusCode: status }
|
|
2250
|
+
);
|
|
2251
|
+
}
|
|
2252
|
+
if (status === 403) {
|
|
2253
|
+
return new ZapierAuthenticationError(
|
|
2254
|
+
`Access forbidden. Your token may not have the required scopes to list authentications. (HTTP ${status})`,
|
|
2255
|
+
{ statusCode: status }
|
|
2256
|
+
);
|
|
2257
|
+
}
|
|
2258
|
+
return void 0;
|
|
2259
|
+
},
|
|
2260
|
+
authRequired: true
|
|
2261
|
+
}
|
|
2262
|
+
);
|
|
2263
|
+
let auths = (data.results || []).map(
|
|
2264
|
+
(auth) => normalizeAuthenticationItem(auth)
|
|
2265
|
+
);
|
|
2266
|
+
if (options.title) {
|
|
2267
|
+
auths = auths.filter((auth) => auth.title === options.title);
|
|
1676
2268
|
}
|
|
1677
2269
|
return {
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
details
|
|
2270
|
+
data: auths,
|
|
2271
|
+
nextCursor: extractCursor(data)
|
|
1681
2272
|
};
|
|
2273
|
+
},
|
|
2274
|
+
ListAuthenticationsSchema
|
|
2275
|
+
);
|
|
2276
|
+
return {
|
|
2277
|
+
listAuthentications,
|
|
2278
|
+
context: {
|
|
2279
|
+
meta: {
|
|
2280
|
+
listAuthentications: {
|
|
2281
|
+
inputSchema: ListAuthenticationsSchema
|
|
2282
|
+
}
|
|
2283
|
+
}
|
|
1682
2284
|
}
|
|
1683
|
-
}
|
|
1684
|
-
);
|
|
1685
|
-
|
|
1686
|
-
// src/functions/listAuthentications/schemas.ts
|
|
1687
|
-
var ListAuthenticationsSchema = withOutputSchema(
|
|
1688
|
-
zod.z.object({
|
|
1689
|
-
appKey: AppKeyPropertySchema.optional().describe(
|
|
1690
|
-
"App slug to get authentications for (e.g., 'slack', 'github')"
|
|
1691
|
-
),
|
|
1692
|
-
search: zod.z.string().optional().describe("Search term to filter authentications by title"),
|
|
1693
|
-
title: zod.z.string().optional().describe("Filter authentications by exact title match"),
|
|
1694
|
-
account_id: zod.z.string().optional().describe("Filter by account ID"),
|
|
1695
|
-
owner: zod.z.string().optional().describe("Filter by owner"),
|
|
1696
|
-
limit: LimitPropertySchema.optional().describe(
|
|
1697
|
-
"Maximum number of items to return (1-200)"
|
|
1698
|
-
),
|
|
1699
|
-
offset: OffsetPropertySchema.optional().describe(
|
|
1700
|
-
"Number of items to skip for pagination"
|
|
1701
|
-
)
|
|
1702
|
-
}).describe("List available authentications with optional filtering"),
|
|
1703
|
-
AuthItemSchema
|
|
1704
|
-
);
|
|
1705
|
-
|
|
1706
|
-
// src/functions/listAuthentications/info.ts
|
|
1707
|
-
var listAuthenticationsInfo = {
|
|
1708
|
-
name: listAuthentications.name,
|
|
1709
|
-
inputSchema: ListAuthenticationsSchema,
|
|
1710
|
-
implementation: listAuthentications
|
|
2285
|
+
};
|
|
1711
2286
|
};
|
|
1712
|
-
var GetAuthenticationSchema =
|
|
1713
|
-
zod.z.
|
|
1714
|
-
|
|
1715
|
-
}).describe("Get a specific authentication by ID"),
|
|
1716
|
-
AuthItemSchema
|
|
1717
|
-
);
|
|
2287
|
+
var GetAuthenticationSchema = zod.z.object({
|
|
2288
|
+
authenticationId: zod.z.number().int().positive().describe("Authentication ID to retrieve")
|
|
2289
|
+
}).describe("Get a specific authentication by ID");
|
|
1718
2290
|
|
|
1719
|
-
// src/
|
|
1720
|
-
var
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
)
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
2291
|
+
// src/plugins/getAuthentication/index.ts
|
|
2292
|
+
var getAuthenticationPlugin = ({ context }) => {
|
|
2293
|
+
const getAuthentication = createFunction(async function getAuthentication2(options) {
|
|
2294
|
+
const { api } = context;
|
|
2295
|
+
const { authenticationId } = options;
|
|
2296
|
+
const data = await api.get(
|
|
2297
|
+
`/api/v4/authentications/${authenticationId}/`,
|
|
2298
|
+
{
|
|
2299
|
+
customErrorHandler: ({ status }) => {
|
|
2300
|
+
if (status === 401) {
|
|
2301
|
+
return new ZapierAuthenticationError(
|
|
2302
|
+
`Authentication failed. Your token may not have permission to access authentications or may be expired. (HTTP ${status})`,
|
|
2303
|
+
{ statusCode: status }
|
|
2304
|
+
);
|
|
2305
|
+
}
|
|
2306
|
+
if (status === 403) {
|
|
2307
|
+
return new ZapierAuthenticationError(
|
|
2308
|
+
`Access forbidden. Your token may not have the required scopes to get authentication ${authenticationId}. (HTTP ${status})`,
|
|
2309
|
+
{ statusCode: status }
|
|
2310
|
+
);
|
|
2311
|
+
}
|
|
2312
|
+
if (status === 404) {
|
|
2313
|
+
return new ZapierResourceNotFoundError(
|
|
2314
|
+
`Authentication ${authenticationId} not found. It may not exist or you may not have access to it. (HTTP ${status})`,
|
|
2315
|
+
{
|
|
2316
|
+
resourceType: "Authentication",
|
|
2317
|
+
resourceId: String(authenticationId)
|
|
2318
|
+
}
|
|
2319
|
+
);
|
|
2320
|
+
}
|
|
2321
|
+
return void 0;
|
|
2322
|
+
},
|
|
2323
|
+
authRequired: true
|
|
2324
|
+
}
|
|
2325
|
+
);
|
|
2326
|
+
return {
|
|
2327
|
+
data: normalizeAuthenticationItem(data)
|
|
2328
|
+
};
|
|
2329
|
+
}, GetAuthenticationSchema);
|
|
2330
|
+
return {
|
|
2331
|
+
getAuthentication,
|
|
2332
|
+
context: {
|
|
2333
|
+
meta: {
|
|
2334
|
+
getAuthentication: {
|
|
2335
|
+
inputSchema: GetAuthenticationSchema
|
|
2336
|
+
}
|
|
2337
|
+
}
|
|
2338
|
+
}
|
|
2339
|
+
};
|
|
1749
2340
|
};
|
|
1750
|
-
var
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
limit: LimitPropertySchema.optional().describe(
|
|
1760
|
-
"Maximum number of items to return (1-200)"
|
|
1761
|
-
),
|
|
1762
|
-
offset: OffsetPropertySchema.optional().describe(
|
|
1763
|
-
"Number of items to skip for pagination"
|
|
1764
|
-
)
|
|
1765
|
-
}).describe("Find a unique authentication matching the criteria"),
|
|
1766
|
-
AuthItemSchema
|
|
1767
|
-
);
|
|
2341
|
+
var FindFirstAuthenticationSchema = zod.z.object({
|
|
2342
|
+
appKey: AppKeyPropertySchema.optional().describe(
|
|
2343
|
+
"App key of authentication to find (e.g., 'SlackCLIAPI')"
|
|
2344
|
+
),
|
|
2345
|
+
search: zod.z.string().optional().describe("Search term to filter authentications by title"),
|
|
2346
|
+
title: zod.z.string().optional().describe("Filter authentications by exact title match"),
|
|
2347
|
+
account_id: zod.z.string().optional().describe("Filter by account ID"),
|
|
2348
|
+
owner: zod.z.string().optional().describe("Filter by owner")
|
|
2349
|
+
}).describe("Find the first authentication matching the criteria");
|
|
1768
2350
|
|
|
1769
|
-
// src/
|
|
1770
|
-
var
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
key: zod.z.string(),
|
|
1778
|
-
name: zod.z.string().optional(),
|
|
1779
|
-
description: zod.z.string().optional()
|
|
1780
|
-
}),
|
|
1781
|
-
{
|
|
1782
|
-
format: (item) => {
|
|
1783
|
-
const details = [];
|
|
1784
|
-
if (item.description) {
|
|
1785
|
-
details.push({ text: item.description, style: "dim" });
|
|
1786
|
-
}
|
|
2351
|
+
// src/plugins/findFirstAuthentication/index.ts
|
|
2352
|
+
var findFirstAuthenticationPlugin = ({ sdk }) => {
|
|
2353
|
+
const findFirstAuthentication = createFunction(
|
|
2354
|
+
async function findFirstAuthentication2(options = {}) {
|
|
2355
|
+
const authsResponse = await sdk.listAuthentications({
|
|
2356
|
+
...options,
|
|
2357
|
+
maxItems: 1
|
|
2358
|
+
});
|
|
1787
2359
|
return {
|
|
1788
|
-
|
|
1789
|
-
subtitle: `(${item.key})`,
|
|
1790
|
-
details
|
|
2360
|
+
data: authsResponse.data.length > 0 ? authsResponse.data[0] : null
|
|
1791
2361
|
};
|
|
2362
|
+
},
|
|
2363
|
+
FindFirstAuthenticationSchema
|
|
2364
|
+
);
|
|
2365
|
+
return {
|
|
2366
|
+
findFirstAuthentication,
|
|
2367
|
+
context: {
|
|
2368
|
+
meta: {
|
|
2369
|
+
findFirstAuthentication: {
|
|
2370
|
+
inputSchema: FindFirstAuthenticationSchema
|
|
2371
|
+
}
|
|
2372
|
+
}
|
|
1792
2373
|
}
|
|
1793
|
-
}
|
|
1794
|
-
);
|
|
1795
|
-
|
|
1796
|
-
// src/functions/listFields/schemas.ts
|
|
1797
|
-
var ListFieldsSchema = withOutputSchema(
|
|
1798
|
-
zod.z.object({
|
|
1799
|
-
appKey: AppKeyPropertySchema,
|
|
1800
|
-
actionType: ActionTypePropertySchema,
|
|
1801
|
-
actionKey: ActionKeyPropertySchema,
|
|
1802
|
-
authenticationId: AuthenticationIdPropertySchema.optional(),
|
|
1803
|
-
params: ParamsPropertySchema.optional().describe(
|
|
1804
|
-
"Additional parameters that may affect available fields"
|
|
1805
|
-
)
|
|
1806
|
-
}).describe("Get the input fields required for a specific action"),
|
|
1807
|
-
FieldItemSchema
|
|
1808
|
-
);
|
|
1809
|
-
|
|
1810
|
-
// src/functions/listFields/info.ts
|
|
1811
|
-
var listFieldsInfo = {
|
|
1812
|
-
name: listFields.name,
|
|
1813
|
-
inputSchema: ListFieldsSchema,
|
|
1814
|
-
implementation: listFields
|
|
2374
|
+
};
|
|
1815
2375
|
};
|
|
1816
|
-
var
|
|
1817
|
-
appKey: AppKeyPropertySchema.describe(
|
|
1818
|
-
|
|
1819
|
-
output: OutputPropertySchema.optional().describe(
|
|
1820
|
-
"Output file path (defaults to generated/<appKey>.ts)"
|
|
2376
|
+
var FindUniqueAuthenticationSchema = zod.z.object({
|
|
2377
|
+
appKey: AppKeyPropertySchema.optional().describe(
|
|
2378
|
+
"App key of authentication to find (e.g., 'SlackCLIAPI')"
|
|
1821
2379
|
),
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
)
|
|
1825
|
-
|
|
2380
|
+
search: zod.z.string().optional().describe("Search term to filter authentications by title"),
|
|
2381
|
+
title: zod.z.string().optional().describe("Filter authentications by exact title match"),
|
|
2382
|
+
account_id: zod.z.string().optional().describe("Filter by account ID"),
|
|
2383
|
+
owner: zod.z.string().optional().describe("Filter by owner")
|
|
2384
|
+
}).describe("Find a unique authentication matching the criteria");
|
|
1826
2385
|
|
|
1827
|
-
// src/
|
|
1828
|
-
var
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
2386
|
+
// src/plugins/findUniqueAuthentication/index.ts
|
|
2387
|
+
var findUniqueAuthenticationPlugin = ({ sdk }) => {
|
|
2388
|
+
const findUniqueAuthentication = createFunction(
|
|
2389
|
+
async function findUniqueAuthentication2(options = {}) {
|
|
2390
|
+
const authsResponse = await sdk.listAuthentications({
|
|
2391
|
+
...options,
|
|
2392
|
+
maxItems: 2
|
|
2393
|
+
// Get up to 2 to check for uniqueness
|
|
2394
|
+
});
|
|
2395
|
+
if (authsResponse.data.length === 0) {
|
|
2396
|
+
throw new ZapierResourceNotFoundError(
|
|
2397
|
+
"No authentication found matching the specified criteria",
|
|
2398
|
+
{ resourceType: "Authentication" }
|
|
2399
|
+
);
|
|
2400
|
+
}
|
|
2401
|
+
if (authsResponse.data.length > 1) {
|
|
2402
|
+
throw new ZapierValidationError(
|
|
2403
|
+
"Multiple authentications found matching the specified criteria. Expected exactly one."
|
|
2404
|
+
);
|
|
2405
|
+
}
|
|
2406
|
+
return {
|
|
2407
|
+
data: authsResponse.data[0]
|
|
2408
|
+
};
|
|
2409
|
+
},
|
|
2410
|
+
FindUniqueAuthenticationSchema
|
|
2411
|
+
);
|
|
2412
|
+
return {
|
|
2413
|
+
findUniqueAuthentication,
|
|
2414
|
+
context: {
|
|
2415
|
+
meta: {
|
|
2416
|
+
findUniqueAuthentication: {
|
|
2417
|
+
inputSchema: FindUniqueAuthenticationSchema
|
|
2418
|
+
}
|
|
2419
|
+
}
|
|
2420
|
+
}
|
|
2421
|
+
};
|
|
1832
2422
|
};
|
|
1833
|
-
var
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
2423
|
+
var ListInputFieldsSchema = zod.z.object({
|
|
2424
|
+
appKey: AppKeyPropertySchema,
|
|
2425
|
+
actionType: ActionTypePropertySchema,
|
|
2426
|
+
actionKey: ActionKeyPropertySchema,
|
|
2427
|
+
authenticationId: AuthenticationIdPropertySchema.nullable().optional(),
|
|
2428
|
+
inputs: InputsPropertySchema.optional().describe(
|
|
2429
|
+
"Current input values that may affect available fields"
|
|
1837
2430
|
),
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
cjs: zod.z.boolean().default(false).describe("Output CommonJS format instead of ESM")
|
|
1842
|
-
}).describe("Bundle TypeScript code into executable JavaScript");
|
|
2431
|
+
pageSize: zod.z.number().min(1).optional().describe("Number of input fields per page"),
|
|
2432
|
+
maxItems: zod.z.number().min(1).optional().describe("Maximum total items to return across all pages")
|
|
2433
|
+
}).describe("Get the input fields required for a specific action");
|
|
1843
2434
|
|
|
1844
|
-
// src/
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
2435
|
+
// src/plugins/listInputFields/index.ts
|
|
2436
|
+
function getInputFieldTypeFromNeed(need) {
|
|
2437
|
+
if (need.list) {
|
|
2438
|
+
return "ARRAY" /* ARRAY */;
|
|
2439
|
+
}
|
|
2440
|
+
const typeMap = {
|
|
2441
|
+
string: "STRING" /* STRING */,
|
|
2442
|
+
decimal: "NUMBER" /* NUMBER */,
|
|
2443
|
+
integer: "INTEGER" /* INTEGER */,
|
|
2444
|
+
boolean: "BOOLEAN" /* BOOLEAN */,
|
|
2445
|
+
dict: "OBJECT" /* OBJECT */
|
|
2446
|
+
};
|
|
2447
|
+
return typeMap[need.type || ""] || "STRING" /* STRING */;
|
|
2448
|
+
}
|
|
2449
|
+
function getInputFieldFormatFromNeed(need) {
|
|
2450
|
+
if (need.prefill || need.choices) {
|
|
2451
|
+
return "SELECT" /* SELECT */;
|
|
2452
|
+
}
|
|
2453
|
+
const formatMap = {
|
|
2454
|
+
text: "MULTILINE" /* MULTILINE */,
|
|
2455
|
+
datetime: "DATETIME" /* DATETIME */,
|
|
2456
|
+
file: "FILE" /* FILE */,
|
|
2457
|
+
password: "PASSWORD" /* PASSWORD */,
|
|
2458
|
+
code: "CODE" /* CODE */
|
|
2459
|
+
};
|
|
2460
|
+
return formatMap[need.type || ""];
|
|
2461
|
+
}
|
|
2462
|
+
function getItemsTypeFromNeed(need) {
|
|
2463
|
+
if (!need.list) {
|
|
2464
|
+
return void 0;
|
|
2465
|
+
}
|
|
2466
|
+
const typeMap = {
|
|
2467
|
+
string: "STRING" /* STRING */,
|
|
2468
|
+
decimal: "NUMBER" /* NUMBER */,
|
|
2469
|
+
integer: "INTEGER" /* INTEGER */,
|
|
2470
|
+
boolean: "BOOLEAN" /* BOOLEAN */,
|
|
2471
|
+
dict: "OBJECT" /* OBJECT */
|
|
2472
|
+
};
|
|
2473
|
+
return typeMap[need.type || ""] || "STRING" /* STRING */;
|
|
2474
|
+
}
|
|
2475
|
+
function transformNeedToInputFieldItem(need) {
|
|
2476
|
+
const itemsType = getItemsTypeFromNeed(need);
|
|
2477
|
+
return {
|
|
2478
|
+
...need,
|
|
2479
|
+
// Pass through all original Need fields
|
|
2480
|
+
id: need.key,
|
|
2481
|
+
default_value: need.default || "",
|
|
2482
|
+
depends_on: need.depends_on || [],
|
|
2483
|
+
description: need.help_text || "",
|
|
2484
|
+
invalidates_input_fields: need.alters_custom_fields || false,
|
|
2485
|
+
is_required: need.required || false,
|
|
2486
|
+
placeholder: need.placeholder || "",
|
|
2487
|
+
title: need.label || "",
|
|
2488
|
+
value_type: getInputFieldTypeFromNeed(need),
|
|
2489
|
+
format: getInputFieldFormatFromNeed(need),
|
|
2490
|
+
items: itemsType ? { type: itemsType } : void 0
|
|
2491
|
+
};
|
|
2492
|
+
}
|
|
2493
|
+
var listInputFieldsPlugin = ({ sdk, context }) => {
|
|
2494
|
+
const listInputFields = createPaginatedFunction(
|
|
2495
|
+
async function listInputFieldsPage(options) {
|
|
2496
|
+
const { api } = context;
|
|
2497
|
+
const { appKey, actionKey, actionType, authenticationId, inputs } = options;
|
|
2498
|
+
const appData = await sdk.getApp({ appKey });
|
|
2499
|
+
const selectedApi = appData.data.current_implementation_id;
|
|
2500
|
+
if (!selectedApi) {
|
|
2501
|
+
throw new ZapierConfigurationError(
|
|
2502
|
+
"No current_implementation_id found for app",
|
|
2503
|
+
{ configType: "current_implementation_id" }
|
|
2504
|
+
);
|
|
2505
|
+
}
|
|
2506
|
+
const needsRequest = {
|
|
2507
|
+
selected_api: selectedApi,
|
|
2508
|
+
action: actionKey,
|
|
2509
|
+
type_of: actionType,
|
|
2510
|
+
params: inputs || {}
|
|
2511
|
+
};
|
|
2512
|
+
if (authenticationId !== null) {
|
|
2513
|
+
needsRequest.authentication_id = authenticationId;
|
|
2514
|
+
}
|
|
2515
|
+
const needsData = await api.post(
|
|
2516
|
+
"/api/v4/implementations/needs/",
|
|
2517
|
+
needsRequest
|
|
2518
|
+
);
|
|
2519
|
+
if (!needsData.success) {
|
|
2520
|
+
throw new ZapierApiError(
|
|
2521
|
+
`Failed to get action fields: ${needsData.errors?.join(", ") || "Unknown error"}`
|
|
2522
|
+
);
|
|
2523
|
+
}
|
|
2524
|
+
const inputFields = (needsData.needs || []).map(
|
|
2525
|
+
transformNeedToInputFieldItem
|
|
2526
|
+
);
|
|
2527
|
+
return {
|
|
2528
|
+
data: inputFields,
|
|
2529
|
+
nextCursor: void 0
|
|
2530
|
+
// No pagination needed since we return all input fields
|
|
2531
|
+
};
|
|
2532
|
+
},
|
|
2533
|
+
ListInputFieldsSchema
|
|
2534
|
+
);
|
|
2535
|
+
return {
|
|
2536
|
+
listInputFields,
|
|
2537
|
+
context: {
|
|
2538
|
+
meta: {
|
|
2539
|
+
listInputFields: {
|
|
2540
|
+
inputSchema: ListInputFieldsSchema
|
|
2541
|
+
}
|
|
2542
|
+
}
|
|
2543
|
+
}
|
|
2544
|
+
};
|
|
1849
2545
|
};
|
|
1850
2546
|
|
|
1851
|
-
// src/
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
2547
|
+
// src/plugins/request/index.ts
|
|
2548
|
+
function transformUrlToRelayPath(url) {
|
|
2549
|
+
const targetUrl = new URL(url);
|
|
2550
|
+
const relayPath = `/relay/${targetUrl.host}${targetUrl.pathname}${targetUrl.search}${targetUrl.hash}`;
|
|
2551
|
+
return relayPath;
|
|
2552
|
+
}
|
|
2553
|
+
var requestPlugin = ({ context }) => {
|
|
2554
|
+
const request = createFunction(async function request2(options) {
|
|
2555
|
+
const { api } = context;
|
|
2556
|
+
const {
|
|
2557
|
+
url,
|
|
2558
|
+
method = "GET",
|
|
2559
|
+
body,
|
|
2560
|
+
headers: optionsHeaders,
|
|
2561
|
+
authenticationId,
|
|
2562
|
+
callbackUrl,
|
|
2563
|
+
authenticationTemplate
|
|
2564
|
+
} = options;
|
|
2565
|
+
const relayPath = transformUrlToRelayPath(url);
|
|
2566
|
+
const headers = {};
|
|
2567
|
+
if (optionsHeaders) {
|
|
2568
|
+
const headerEntries = optionsHeaders instanceof Headers ? Array.from(optionsHeaders.entries()) : Array.isArray(optionsHeaders) ? optionsHeaders : Object.entries(optionsHeaders);
|
|
2569
|
+
for (const [key, value] of headerEntries) {
|
|
2570
|
+
headers[key] = value;
|
|
2571
|
+
}
|
|
2572
|
+
}
|
|
2573
|
+
if (authenticationId) {
|
|
2574
|
+
headers["X-Relay-Authentication-Id"] = authenticationId.toString();
|
|
2575
|
+
}
|
|
2576
|
+
if (callbackUrl) {
|
|
2577
|
+
headers["X-Relay-Callback-Url"] = callbackUrl;
|
|
2578
|
+
}
|
|
2579
|
+
if (authenticationTemplate) {
|
|
2580
|
+
headers["X-Authentication-Template"] = authenticationTemplate;
|
|
2581
|
+
}
|
|
2582
|
+
return await api.fetch(relayPath, {
|
|
2583
|
+
method,
|
|
2584
|
+
body,
|
|
2585
|
+
headers
|
|
2586
|
+
});
|
|
2587
|
+
}, RelayRequestSchema);
|
|
2588
|
+
return {
|
|
2589
|
+
request,
|
|
2590
|
+
context: {
|
|
2591
|
+
meta: {
|
|
2592
|
+
request: {
|
|
2593
|
+
inputSchema: RelayRequestSchema
|
|
2594
|
+
}
|
|
2595
|
+
}
|
|
2596
|
+
}
|
|
2597
|
+
};
|
|
1856
2598
|
};
|
|
1857
2599
|
|
|
1858
2600
|
// src/sdk.ts
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
runAction: (options2) => runAction({ ...options2, api }),
|
|
1900
|
-
listAuthentications: (options2 = {}) => listAuthentications({ ...options2, api }),
|
|
1901
|
-
getAuthentication: (options2) => getAuthentication({ ...options2, api }),
|
|
1902
|
-
findFirstAuthentication: (options2 = {}) => findFirstAuthentication({ ...options2, api }),
|
|
1903
|
-
findUniqueAuthentication: (options2 = {}) => findUniqueAuthentication({ ...options2, api }),
|
|
1904
|
-
listFields: (options2) => listFields({ ...options2, api }),
|
|
1905
|
-
generateTypes: (options2) => generateTypes({ ...options2, api }),
|
|
1906
|
-
bundleCode: (options2) => bundleCode(options2),
|
|
1907
|
-
// No API config needed
|
|
1908
|
-
request: (options2) => request({ ...options2, api })
|
|
2601
|
+
function createSdk(initialSdk = {}, initialContext = { meta: {} }) {
|
|
2602
|
+
return {
|
|
2603
|
+
...initialSdk,
|
|
2604
|
+
getContext: () => initialContext,
|
|
2605
|
+
addPlugin(plugin, options = {}) {
|
|
2606
|
+
const currentSdkWithContext = {
|
|
2607
|
+
...initialSdk,
|
|
2608
|
+
getContext: () => initialContext
|
|
2609
|
+
};
|
|
2610
|
+
const pluginResult = plugin({
|
|
2611
|
+
sdk: currentSdkWithContext,
|
|
2612
|
+
context: initialContext,
|
|
2613
|
+
...options
|
|
2614
|
+
});
|
|
2615
|
+
const { context: pluginContext, ...sdkProperties } = pluginResult;
|
|
2616
|
+
const newSdk = { ...initialSdk, ...sdkProperties };
|
|
2617
|
+
let newContext = {
|
|
2618
|
+
...initialContext,
|
|
2619
|
+
meta: initialContext.meta || {}
|
|
2620
|
+
};
|
|
2621
|
+
if (pluginContext) {
|
|
2622
|
+
const { meta: pluginMeta, ...otherPluginContext } = pluginContext;
|
|
2623
|
+
newContext = {
|
|
2624
|
+
...newContext,
|
|
2625
|
+
...otherPluginContext
|
|
2626
|
+
};
|
|
2627
|
+
if (pluginMeta) {
|
|
2628
|
+
newContext = {
|
|
2629
|
+
...newContext,
|
|
2630
|
+
meta: {
|
|
2631
|
+
...newContext.meta,
|
|
2632
|
+
// Existing meta (now guaranteed to exist)
|
|
2633
|
+
...pluginMeta
|
|
2634
|
+
// New meta from plugin
|
|
2635
|
+
}
|
|
2636
|
+
};
|
|
2637
|
+
}
|
|
2638
|
+
}
|
|
2639
|
+
return createSdk(newSdk, newContext);
|
|
2640
|
+
}
|
|
1909
2641
|
};
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
return fullSdk;
|
|
2642
|
+
}
|
|
2643
|
+
function createZapierSdk(options = {}) {
|
|
2644
|
+
return createSdk().addPlugin(apiPlugin, options).addPlugin(listAppsPlugin).addPlugin(getAppPlugin).addPlugin(listActionsPlugin).addPlugin(getActionPlugin).addPlugin(listInputFieldsPlugin).addPlugin(runActionPlugin).addPlugin(listAuthenticationsPlugin).addPlugin(getAuthenticationPlugin).addPlugin(findFirstAuthenticationPlugin).addPlugin(findUniqueAuthenticationPlugin).addPlugin(requestPlugin).addPlugin(fetchPlugin).addPlugin(appsPlugin).addPlugin(getProfilePlugin).addPlugin(registryPlugin);
|
|
1914
2645
|
}
|
|
1915
2646
|
|
|
1916
2647
|
exports.ActionKeyPropertySchema = ActionKeyPropertySchema;
|
|
1917
2648
|
exports.ActionTypePropertySchema = ActionTypePropertySchema;
|
|
1918
2649
|
exports.AppKeyPropertySchema = AppKeyPropertySchema;
|
|
1919
|
-
exports.AppNotFoundError = AppNotFoundError;
|
|
1920
2650
|
exports.AuthenticationIdPropertySchema = AuthenticationIdPropertySchema;
|
|
1921
2651
|
exports.DebugPropertySchema = DebugPropertySchema;
|
|
1922
2652
|
exports.InputsPropertySchema = InputsPropertySchema;
|
|
@@ -1926,21 +2656,27 @@ exports.OutputPropertySchema = OutputPropertySchema;
|
|
|
1926
2656
|
exports.ParamsPropertySchema = ParamsPropertySchema;
|
|
1927
2657
|
exports.RelayFetchSchema = RelayFetchSchema;
|
|
1928
2658
|
exports.RelayRequestSchema = RelayRequestSchema;
|
|
1929
|
-
exports.
|
|
2659
|
+
exports.ZapierActionError = ZapierActionError;
|
|
2660
|
+
exports.ZapierApiError = ZapierApiError;
|
|
2661
|
+
exports.ZapierAppNotFoundError = ZapierAppNotFoundError;
|
|
2662
|
+
exports.ZapierAuthenticationError = ZapierAuthenticationError;
|
|
2663
|
+
exports.ZapierBundleError = ZapierBundleError;
|
|
2664
|
+
exports.ZapierConfigurationError = ZapierConfigurationError;
|
|
2665
|
+
exports.ZapierError = ZapierError;
|
|
2666
|
+
exports.ZapierNotFoundError = ZapierNotFoundError;
|
|
2667
|
+
exports.ZapierResourceNotFoundError = ZapierResourceNotFoundError;
|
|
2668
|
+
exports.ZapierTimeoutError = ZapierTimeoutError;
|
|
2669
|
+
exports.ZapierUnknownError = ZapierUnknownError;
|
|
2670
|
+
exports.ZapierValidationError = ZapierValidationError;
|
|
1930
2671
|
exports.actionKeyResolver = actionKeyResolver;
|
|
1931
2672
|
exports.actionTypeResolver = actionTypeResolver;
|
|
1932
2673
|
exports.appKeyResolver = appKeyResolver;
|
|
2674
|
+
exports.appsPlugin = appsPlugin;
|
|
1933
2675
|
exports.authenticationIdResolver = authenticationIdResolver;
|
|
1934
|
-
exports.
|
|
1935
|
-
exports.createAppsPlugin = createAppsPlugin;
|
|
1936
|
-
exports.createFetchPlugin = createFetchPlugin;
|
|
2676
|
+
exports.createSdk = createSdk;
|
|
1937
2677
|
exports.createZapierSdk = createZapierSdk;
|
|
1938
|
-
exports.
|
|
1939
|
-
exports.
|
|
1940
|
-
exports.generateTypes = generateTypes;
|
|
1941
|
-
exports.getAction = getAction;
|
|
1942
|
-
exports.getApp = getApp;
|
|
1943
|
-
exports.getAuthentication = getAuthentication;
|
|
2678
|
+
exports.fetchPlugin = fetchPlugin;
|
|
2679
|
+
exports.formatErrorMessage = formatErrorMessage;
|
|
1944
2680
|
exports.getResolutionOrder = getResolutionOrder;
|
|
1945
2681
|
exports.getResolutionOrderForParams = getResolutionOrderForParams;
|
|
1946
2682
|
exports.getResolvableParams = getResolvableParams;
|
|
@@ -1952,11 +2688,4 @@ exports.getTokenFromEnvOrConfig = getTokenFromEnvOrConfig;
|
|
|
1952
2688
|
exports.hasResolver = hasResolver;
|
|
1953
2689
|
exports.inputsResolver = inputsResolver;
|
|
1954
2690
|
exports.isPositional = isPositional;
|
|
1955
|
-
exports.listActions = listActions;
|
|
1956
|
-
exports.listApps = listApps;
|
|
1957
|
-
exports.listAuthentications = listAuthentications;
|
|
1958
|
-
exports.listFields = listFields;
|
|
1959
|
-
exports.relayFetch = relayFetch;
|
|
1960
|
-
exports.request = request;
|
|
1961
2691
|
exports.resolverRegistry = resolverRegistry;
|
|
1962
|
-
exports.runAction = runAction;
|