@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
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
+
import { ZapierValidationError, ZapierActionError } from "../../types/errors";
|
|
3
|
+
import { runActionPlugin } from "./index";
|
|
4
|
+
import { createSdk } from "../../sdk";
|
|
5
|
+
const mockAction = {
|
|
6
|
+
type: "action",
|
|
7
|
+
key: "send_message",
|
|
8
|
+
title: "Send Message",
|
|
9
|
+
description: "Send a message to a channel",
|
|
10
|
+
app_key: "slack",
|
|
11
|
+
action_type: "write",
|
|
12
|
+
};
|
|
13
|
+
const mockActionResponse = {
|
|
14
|
+
results: [
|
|
15
|
+
{
|
|
16
|
+
id: "msg_123",
|
|
17
|
+
text: "Hello, world!",
|
|
18
|
+
channel: "#general",
|
|
19
|
+
user: "user_456",
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
meta: {
|
|
23
|
+
next_cursor: null,
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
describe("runAction plugin", () => {
|
|
27
|
+
let mockApiClient;
|
|
28
|
+
let mockGetAction;
|
|
29
|
+
let mockGetApp;
|
|
30
|
+
beforeEach(() => {
|
|
31
|
+
vi.clearAllMocks();
|
|
32
|
+
mockApiClient = {
|
|
33
|
+
post: vi.fn().mockResolvedValue({ data: { id: "run_123" } }),
|
|
34
|
+
poll: vi.fn().mockResolvedValue({ results: mockActionResponse.results }),
|
|
35
|
+
};
|
|
36
|
+
mockGetAction = vi.fn().mockResolvedValue({
|
|
37
|
+
data: mockAction,
|
|
38
|
+
});
|
|
39
|
+
mockGetApp = vi.fn().mockResolvedValue({
|
|
40
|
+
data: { current_implementation_id: "SlackCLIAPI" },
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
function createTestSdk() {
|
|
44
|
+
return createSdk({ getAction: mockGetAction, getApp: mockGetApp }, // Provide getAction and getApp in SDK
|
|
45
|
+
{ api: mockApiClient, meta: {} }).addPlugin(runActionPlugin);
|
|
46
|
+
}
|
|
47
|
+
describe("schema validation", () => {
|
|
48
|
+
it("should throw validation error for missing appKey", () => {
|
|
49
|
+
const sdk = createTestSdk();
|
|
50
|
+
expect(() => {
|
|
51
|
+
sdk.runAction({
|
|
52
|
+
actionType: "write",
|
|
53
|
+
actionKey: "send_message",
|
|
54
|
+
inputs: { message: "Hello" },
|
|
55
|
+
});
|
|
56
|
+
}).toThrow(ZapierValidationError);
|
|
57
|
+
});
|
|
58
|
+
it("should throw validation error for missing actionType", () => {
|
|
59
|
+
const sdk = createTestSdk();
|
|
60
|
+
expect(() => {
|
|
61
|
+
sdk.runAction({
|
|
62
|
+
appKey: "slack",
|
|
63
|
+
actionKey: "send_message",
|
|
64
|
+
inputs: { message: "Hello" },
|
|
65
|
+
});
|
|
66
|
+
}).toThrow(ZapierValidationError);
|
|
67
|
+
});
|
|
68
|
+
it("should throw validation error for missing actionKey", () => {
|
|
69
|
+
const sdk = createTestSdk();
|
|
70
|
+
expect(() => {
|
|
71
|
+
sdk.runAction({
|
|
72
|
+
appKey: "slack",
|
|
73
|
+
actionType: "write",
|
|
74
|
+
inputs: { message: "Hello" },
|
|
75
|
+
});
|
|
76
|
+
}).toThrow(ZapierValidationError);
|
|
77
|
+
});
|
|
78
|
+
it("should pass validation with all required fields", async () => {
|
|
79
|
+
const sdk = createTestSdk();
|
|
80
|
+
const result = await sdk.runAction({
|
|
81
|
+
appKey: "slack",
|
|
82
|
+
actionType: "write",
|
|
83
|
+
actionKey: "send_message",
|
|
84
|
+
inputs: { message: "Hello" },
|
|
85
|
+
});
|
|
86
|
+
expect(result.data).toHaveLength(1);
|
|
87
|
+
expect(result.data[0]).toEqual(mockActionResponse.results[0]);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
describe("action execution", () => {
|
|
91
|
+
it("should validate action exists using getAction", async () => {
|
|
92
|
+
const sdk = createTestSdk();
|
|
93
|
+
await sdk.runAction({
|
|
94
|
+
appKey: "slack",
|
|
95
|
+
actionType: "write",
|
|
96
|
+
actionKey: "send_message",
|
|
97
|
+
inputs: { message: "Hello" },
|
|
98
|
+
});
|
|
99
|
+
expect(mockGetAction).toHaveBeenCalledWith({
|
|
100
|
+
appKey: "slack",
|
|
101
|
+
actionKey: "send_message",
|
|
102
|
+
actionType: "write",
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
it("should throw error when action type doesn't match", async () => {
|
|
106
|
+
// Mock getAction to return an action with different type
|
|
107
|
+
mockGetAction.mockResolvedValue({
|
|
108
|
+
data: { ...mockAction, action_type: "read" },
|
|
109
|
+
});
|
|
110
|
+
const sdk = createTestSdk();
|
|
111
|
+
await expect(sdk.runAction({
|
|
112
|
+
appKey: "slack",
|
|
113
|
+
actionType: "write", // Different from mocked action type
|
|
114
|
+
actionKey: "send_message",
|
|
115
|
+
inputs: { message: "Hello" },
|
|
116
|
+
})).rejects.toThrow(ZapierValidationError);
|
|
117
|
+
});
|
|
118
|
+
it("should execute action with correct API call", async () => {
|
|
119
|
+
const sdk = createTestSdk();
|
|
120
|
+
await sdk.runAction({
|
|
121
|
+
appKey: "slack",
|
|
122
|
+
actionType: "write",
|
|
123
|
+
actionKey: "send_message",
|
|
124
|
+
inputs: { message: "Hello", channel: "#general" },
|
|
125
|
+
authenticationId: 12345,
|
|
126
|
+
});
|
|
127
|
+
expect(mockApiClient.post).toHaveBeenCalledWith("/api/actions/v1/runs", {
|
|
128
|
+
data: {
|
|
129
|
+
selected_api: "SlackCLIAPI",
|
|
130
|
+
action_key: "send_message",
|
|
131
|
+
action_type: "write",
|
|
132
|
+
inputs: { message: "Hello", channel: "#general" },
|
|
133
|
+
authentication_id: 12345,
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
expect(mockApiClient.poll).toHaveBeenCalledWith("/api/actions/v1/runs/run_123", {
|
|
137
|
+
successStatus: 200,
|
|
138
|
+
pendingStatus: 202,
|
|
139
|
+
resultExtractor: expect.any(Function),
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
it("should execute action without authentication ID", async () => {
|
|
143
|
+
const sdk = createTestSdk();
|
|
144
|
+
await sdk.runAction({
|
|
145
|
+
appKey: "slack",
|
|
146
|
+
actionType: "write",
|
|
147
|
+
actionKey: "send_message",
|
|
148
|
+
inputs: { message: "Hello" },
|
|
149
|
+
});
|
|
150
|
+
expect(mockApiClient.post).toHaveBeenCalledWith("/api/actions/v1/runs", {
|
|
151
|
+
data: {
|
|
152
|
+
selected_api: "SlackCLIAPI",
|
|
153
|
+
action_key: "send_message",
|
|
154
|
+
action_type: "write",
|
|
155
|
+
inputs: { message: "Hello" },
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
it("should handle pagination cursor", async () => {
|
|
160
|
+
const sdk = createTestSdk();
|
|
161
|
+
const runActionResult = sdk.runAction({
|
|
162
|
+
appKey: "slack",
|
|
163
|
+
actionType: "write",
|
|
164
|
+
actionKey: "send_message",
|
|
165
|
+
inputs: { message: "Hello" },
|
|
166
|
+
});
|
|
167
|
+
// Simulate pagination by getting an iterator
|
|
168
|
+
const iterator = runActionResult[Symbol.asyncIterator]();
|
|
169
|
+
await iterator.next();
|
|
170
|
+
expect(mockApiClient.post).toHaveBeenCalledWith("/api/actions/v1/runs", expect.objectContaining({
|
|
171
|
+
data: expect.objectContaining({
|
|
172
|
+
inputs: { message: "Hello" },
|
|
173
|
+
selected_api: "SlackCLIAPI",
|
|
174
|
+
action_key: "send_message",
|
|
175
|
+
action_type: "write",
|
|
176
|
+
}),
|
|
177
|
+
}));
|
|
178
|
+
});
|
|
179
|
+
it("should return results in correct format", async () => {
|
|
180
|
+
const sdk = createTestSdk();
|
|
181
|
+
const result = await sdk.runAction({
|
|
182
|
+
appKey: "slack",
|
|
183
|
+
actionType: "write",
|
|
184
|
+
actionKey: "send_message",
|
|
185
|
+
inputs: { message: "Hello" },
|
|
186
|
+
});
|
|
187
|
+
expect(result.data).toEqual(mockActionResponse.results);
|
|
188
|
+
});
|
|
189
|
+
it("should handle single result (not array)", async () => {
|
|
190
|
+
const singleResult = { id: "msg_123", text: "Hello" };
|
|
191
|
+
mockApiClient.post = vi
|
|
192
|
+
.fn()
|
|
193
|
+
.mockResolvedValue({ data: { id: "run_123" } });
|
|
194
|
+
mockApiClient.poll = vi.fn().mockResolvedValue({
|
|
195
|
+
results: [singleResult], // Poll returns the actual results
|
|
196
|
+
});
|
|
197
|
+
const sdk = createTestSdk();
|
|
198
|
+
const result = await sdk.runAction({
|
|
199
|
+
appKey: "slack",
|
|
200
|
+
actionType: "write",
|
|
201
|
+
actionKey: "send_message",
|
|
202
|
+
inputs: { message: "Hello" },
|
|
203
|
+
});
|
|
204
|
+
expect(result.data).toEqual([singleResult]); // Should be wrapped in array
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
describe("error handling", () => {
|
|
208
|
+
it("should handle action execution errors", async () => {
|
|
209
|
+
mockApiClient.post = vi
|
|
210
|
+
.fn()
|
|
211
|
+
.mockResolvedValue({ data: { id: "run_123" } });
|
|
212
|
+
mockApiClient.poll = vi.fn().mockResolvedValue({
|
|
213
|
+
results: [],
|
|
214
|
+
errors: [
|
|
215
|
+
{ title: "Invalid inputs", detail: "Message cannot be empty" },
|
|
216
|
+
],
|
|
217
|
+
});
|
|
218
|
+
const sdk = createTestSdk();
|
|
219
|
+
await expect(sdk.runAction({
|
|
220
|
+
appKey: "slack",
|
|
221
|
+
actionType: "write",
|
|
222
|
+
actionKey: "send_message",
|
|
223
|
+
inputs: { message: "" }, // Invalid input
|
|
224
|
+
})).rejects.toThrow(ZapierActionError);
|
|
225
|
+
});
|
|
226
|
+
it("should handle server errors", async () => {
|
|
227
|
+
mockApiClient.post = vi.fn().mockImplementation((_url, options) => {
|
|
228
|
+
const error = options.customErrorHandler?.({
|
|
229
|
+
status: 500,
|
|
230
|
+
data: { message: "Internal server error" },
|
|
231
|
+
});
|
|
232
|
+
if (error)
|
|
233
|
+
throw error;
|
|
234
|
+
throw new Error("Server Error");
|
|
235
|
+
});
|
|
236
|
+
const sdk = createTestSdk();
|
|
237
|
+
await expect(sdk.runAction({
|
|
238
|
+
appKey: "slack",
|
|
239
|
+
actionType: "write",
|
|
240
|
+
actionKey: "send_message",
|
|
241
|
+
inputs: { message: "Hello" },
|
|
242
|
+
})).rejects.toThrow();
|
|
243
|
+
});
|
|
244
|
+
it("should propagate getAction errors", async () => {
|
|
245
|
+
mockGetAction.mockRejectedValue(new Error("Action not found"));
|
|
246
|
+
const sdk = createTestSdk();
|
|
247
|
+
await expect(sdk.runAction({
|
|
248
|
+
appKey: "slack",
|
|
249
|
+
actionType: "write",
|
|
250
|
+
actionKey: "nonexistent",
|
|
251
|
+
inputs: { message: "Hello" },
|
|
252
|
+
})).rejects.toThrow("Action not found");
|
|
253
|
+
});
|
|
254
|
+
it("should handle unexpected errors during execution", async () => {
|
|
255
|
+
mockApiClient.post = vi
|
|
256
|
+
.fn()
|
|
257
|
+
.mockRejectedValue(new Error("Network error"));
|
|
258
|
+
const sdk = createTestSdk();
|
|
259
|
+
await expect(sdk.runAction({
|
|
260
|
+
appKey: "slack",
|
|
261
|
+
actionType: "write",
|
|
262
|
+
actionKey: "send_message",
|
|
263
|
+
inputs: { message: "Hello" },
|
|
264
|
+
})).rejects.toThrow("Network error");
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
describe("pagination", () => {
|
|
268
|
+
it("should support maxItems limit", async () => {
|
|
269
|
+
const sdk = createTestSdk();
|
|
270
|
+
const result = await sdk.runAction({
|
|
271
|
+
appKey: "slack",
|
|
272
|
+
actionType: "write",
|
|
273
|
+
actionKey: "send_message",
|
|
274
|
+
inputs: { message: "Hello" },
|
|
275
|
+
maxItems: 1,
|
|
276
|
+
});
|
|
277
|
+
expect(result.data).toHaveLength(1);
|
|
278
|
+
});
|
|
279
|
+
it("should support async iteration over pages", async () => {
|
|
280
|
+
const sdk = createTestSdk();
|
|
281
|
+
const runActionResult = sdk.runAction({
|
|
282
|
+
appKey: "slack",
|
|
283
|
+
actionType: "write",
|
|
284
|
+
actionKey: "send_message",
|
|
285
|
+
inputs: { message: "Hello" },
|
|
286
|
+
});
|
|
287
|
+
const pages = [];
|
|
288
|
+
for await (const page of runActionResult) {
|
|
289
|
+
pages.push(page);
|
|
290
|
+
break; // Just get first page for testing
|
|
291
|
+
}
|
|
292
|
+
expect(pages).toHaveLength(1);
|
|
293
|
+
expect(pages[0].data).toEqual(mockActionResponse.results);
|
|
294
|
+
});
|
|
295
|
+
it("should support async iteration over individual items", async () => {
|
|
296
|
+
const sdk = createTestSdk();
|
|
297
|
+
const runActionResult = sdk.runAction({
|
|
298
|
+
appKey: "slack",
|
|
299
|
+
actionType: "write",
|
|
300
|
+
actionKey: "send_message",
|
|
301
|
+
inputs: { message: "Hello" },
|
|
302
|
+
maxItems: 1,
|
|
303
|
+
});
|
|
304
|
+
const items = [];
|
|
305
|
+
for await (const item of runActionResult.items()) {
|
|
306
|
+
items.push(item);
|
|
307
|
+
}
|
|
308
|
+
expect(items).toHaveLength(1);
|
|
309
|
+
expect(items[0]).toEqual(mockActionResponse.results[0]);
|
|
310
|
+
});
|
|
311
|
+
});
|
|
312
|
+
describe("context and metadata", () => {
|
|
313
|
+
it("should provide context with meta information", () => {
|
|
314
|
+
const sdk = createTestSdk();
|
|
315
|
+
const context = sdk.getContext();
|
|
316
|
+
expect(context.meta.runAction).toBeDefined();
|
|
317
|
+
expect(context.meta.runAction.inputSchema).toBeDefined();
|
|
318
|
+
});
|
|
319
|
+
});
|
|
320
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { PaginatedSdkFunction } from "../../types/functions";
|
|
3
|
+
export declare const RunActionSchema: z.ZodObject<{
|
|
4
|
+
appKey: z.ZodString;
|
|
5
|
+
actionType: z.ZodEnum<["read", "read_bulk", "write", "run", "search", "search_or_write", "search_and_write", "filter"]>;
|
|
6
|
+
actionKey: z.ZodString;
|
|
7
|
+
authenticationId: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
8
|
+
inputs: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
9
|
+
pageSize: z.ZodOptional<z.ZodNumber>;
|
|
10
|
+
maxItems: z.ZodOptional<z.ZodNumber>;
|
|
11
|
+
}, "strip", z.ZodTypeAny, {
|
|
12
|
+
appKey: string;
|
|
13
|
+
actionType: "filter" | "read" | "read_bulk" | "run" | "search" | "search_and_write" | "search_or_write" | "write";
|
|
14
|
+
actionKey: string;
|
|
15
|
+
authenticationId?: number | null | undefined;
|
|
16
|
+
maxItems?: number | undefined;
|
|
17
|
+
pageSize?: number | undefined;
|
|
18
|
+
inputs?: Record<string, any> | undefined;
|
|
19
|
+
}, {
|
|
20
|
+
appKey: string;
|
|
21
|
+
actionType: "filter" | "read" | "read_bulk" | "run" | "search" | "search_and_write" | "search_or_write" | "write";
|
|
22
|
+
actionKey: string;
|
|
23
|
+
authenticationId?: number | null | undefined;
|
|
24
|
+
maxItems?: number | undefined;
|
|
25
|
+
pageSize?: number | undefined;
|
|
26
|
+
inputs?: Record<string, any> | undefined;
|
|
27
|
+
}>;
|
|
28
|
+
export type RunActionOptions = z.infer<typeof RunActionSchema>;
|
|
29
|
+
export interface RunActionPage {
|
|
30
|
+
data: any[];
|
|
31
|
+
nextCursor?: string;
|
|
32
|
+
}
|
|
33
|
+
export type RunActionError = import("../../types/errors").ZapierActionError | import("../../types/errors").ZapierValidationError | import("../../types/errors").ZapierConfigurationError | import("../../types/errors").ZapierUnknownError;
|
|
34
|
+
export interface RunActionSdkFunction {
|
|
35
|
+
runAction: PaginatedSdkFunction<RunActionOptions, any>;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=schemas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../src/plugins/runAction/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAQxB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAGlE,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;EAoB0B,CAAC;AAGvD,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAG/D,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAGD,MAAM,MAAM,cAAc,GACtB,OAAO,oBAAoB,EAAE,iBAAiB,GAC9C,OAAO,oBAAoB,EAAE,qBAAqB,GAClD,OAAO,oBAAoB,EAAE,wBAAwB,GACrD,OAAO,oBAAoB,EAAE,kBAAkB,CAAC;AAGpD,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,oBAAoB,CAAC,gBAAgB,EAAE,GAAG,CAAC,CAAC;CACxD"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { AppKeyPropertySchema, ActionTypePropertySchema, ActionKeyPropertySchema, AuthenticationIdPropertySchema, InputsPropertySchema, } from "../../types/properties";
|
|
3
|
+
// Pure Zod schema - no resolver metadata!
|
|
4
|
+
export const RunActionSchema = z
|
|
5
|
+
.object({
|
|
6
|
+
appKey: AppKeyPropertySchema,
|
|
7
|
+
actionType: ActionTypePropertySchema,
|
|
8
|
+
actionKey: ActionKeyPropertySchema,
|
|
9
|
+
authenticationId: AuthenticationIdPropertySchema.nullable().optional(),
|
|
10
|
+
inputs: InputsPropertySchema.optional().describe("Input parameters for the action"),
|
|
11
|
+
pageSize: z
|
|
12
|
+
.number()
|
|
13
|
+
.min(1)
|
|
14
|
+
.optional()
|
|
15
|
+
.describe("Number of results per page"),
|
|
16
|
+
maxItems: z
|
|
17
|
+
.number()
|
|
18
|
+
.min(1)
|
|
19
|
+
.optional()
|
|
20
|
+
.describe("Maximum total items to return across all pages"),
|
|
21
|
+
})
|
|
22
|
+
.describe("Execute an action with the given inputs");
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ZapierSdk } from "../types/sdk";
|
|
2
|
+
export interface ActionKeyResolver {
|
|
3
|
+
type: "dynamic";
|
|
4
|
+
depends: readonly string[];
|
|
5
|
+
fetch: (sdk: ZapierSdk, resolvedParams: Record<string, any>) => Promise<any[]>;
|
|
6
|
+
prompt: (items: any[], params: Record<string, any>) => any;
|
|
7
|
+
}
|
|
8
|
+
export declare const actionKeyResolver: ActionKeyResolver;
|
|
9
|
+
//# sourceMappingURL=actionKey.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actionKey.d.ts","sourceRoot":"","sources":["../../src/resolvers/actionKey.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3B,KAAK,EAAE,CACL,GAAG,EAAE,SAAS,EACd,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAChC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IACpB,MAAM,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,GAAG,CAAC;CAC5D;AAED,eAAO,MAAM,iBAAiB,EAAE,iBAsB/B,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export const actionKeyResolver = {
|
|
2
|
+
type: "dynamic",
|
|
3
|
+
depends: ["appKey", "actionType"],
|
|
4
|
+
fetch: async (sdk, resolvedParams) => {
|
|
5
|
+
const actionsResponse = await sdk.listActions({
|
|
6
|
+
appKey: resolvedParams.appKey,
|
|
7
|
+
});
|
|
8
|
+
return actionsResponse.data.filter((action) => action.action_type === resolvedParams.actionType);
|
|
9
|
+
},
|
|
10
|
+
prompt: (actions) => ({
|
|
11
|
+
type: "list",
|
|
12
|
+
name: "actionKey",
|
|
13
|
+
message: "Select action:",
|
|
14
|
+
choices: actions.map((action) => ({
|
|
15
|
+
name: `${action.title || action.name || action.key} - ${action.description || "No description"}`,
|
|
16
|
+
value: action.key,
|
|
17
|
+
})),
|
|
18
|
+
}),
|
|
19
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ZapierSdk } from "../types/sdk";
|
|
2
|
+
export interface ActionTypeResolver {
|
|
3
|
+
type: "dynamic";
|
|
4
|
+
depends: readonly string[];
|
|
5
|
+
fetch: (sdk: ZapierSdk, resolvedParams: Record<string, any>) => Promise<any[]>;
|
|
6
|
+
prompt: (items: any[], params: Record<string, any>) => any;
|
|
7
|
+
}
|
|
8
|
+
export declare const actionTypeResolver: ActionTypeResolver;
|
|
9
|
+
//# sourceMappingURL=actionType.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actionType.d.ts","sourceRoot":"","sources":["../../src/resolvers/actionType.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3B,KAAK,EAAE,CACL,GAAG,EAAE,SAAS,EACd,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAChC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IACpB,MAAM,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,GAAG,CAAC;CAC5D;AAED,eAAO,MAAM,kBAAkB,EAAE,kBAsBhC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export const actionTypeResolver = {
|
|
2
|
+
type: "dynamic",
|
|
3
|
+
depends: ["appKey"],
|
|
4
|
+
fetch: async (sdk, resolvedParams) => {
|
|
5
|
+
const actionsResponse = await sdk.listActions({
|
|
6
|
+
appKey: resolvedParams.appKey,
|
|
7
|
+
});
|
|
8
|
+
const types = [
|
|
9
|
+
...new Set(actionsResponse.data.map((action) => action.action_type)),
|
|
10
|
+
];
|
|
11
|
+
return types.map((type) => ({ key: type, name: type }));
|
|
12
|
+
},
|
|
13
|
+
prompt: (types) => ({
|
|
14
|
+
type: "list",
|
|
15
|
+
name: "actionType",
|
|
16
|
+
message: "Select action type:",
|
|
17
|
+
choices: types.map((type) => ({
|
|
18
|
+
name: type.name,
|
|
19
|
+
value: type.key,
|
|
20
|
+
})),
|
|
21
|
+
}),
|
|
22
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"appKey.d.ts","sourceRoot":"","sources":["../../src/resolvers/appKey.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,QAAQ,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,CAAC;IAC1C,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,eAAO,MAAM,cAAc,EAAE,cAI5B,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ZapierSdk } from "../types/sdk";
|
|
2
|
+
export interface AuthenticationIdResolver {
|
|
3
|
+
type: "dynamic";
|
|
4
|
+
depends: readonly string[];
|
|
5
|
+
fetch: (sdk: ZapierSdk, resolvedParams: Record<string, any>) => Promise<any[]>;
|
|
6
|
+
prompt: (items: any[], params: Record<string, any>) => any;
|
|
7
|
+
}
|
|
8
|
+
export declare const authenticationIdResolver: AuthenticationIdResolver;
|
|
9
|
+
//# sourceMappingURL=authenticationId.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authenticationId.d.ts","sourceRoot":"","sources":["../../src/resolvers/authenticationId.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3B,KAAK,EAAE,CACL,GAAG,EAAE,SAAS,EACd,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAChC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IACpB,MAAM,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,GAAG,CAAC;CAC5D;AAED,eAAO,MAAM,wBAAwB,EAAE,wBAkCtC,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export const authenticationIdResolver = {
|
|
2
|
+
type: "dynamic",
|
|
3
|
+
depends: ["appKey"],
|
|
4
|
+
fetch: async (sdk, resolvedParams) => {
|
|
5
|
+
const myAuths = await sdk.listAuthentications({
|
|
6
|
+
appKey: resolvedParams.appKey,
|
|
7
|
+
maxItems: 1000,
|
|
8
|
+
owner: "me",
|
|
9
|
+
});
|
|
10
|
+
const allAuths = await sdk.listAuthentications({
|
|
11
|
+
appKey: resolvedParams.appKey,
|
|
12
|
+
maxItems: 1000,
|
|
13
|
+
});
|
|
14
|
+
// Filter out myAuths from allAuths
|
|
15
|
+
const otherAuths = allAuths.data.filter((auth) => !myAuths.data.some((myAuth) => myAuth.id === auth.id));
|
|
16
|
+
return [...myAuths.data, ...otherAuths];
|
|
17
|
+
},
|
|
18
|
+
prompt: (auths, params) => ({
|
|
19
|
+
type: "list",
|
|
20
|
+
name: "authenticationId",
|
|
21
|
+
message: `Select authentication for ${params.appKey}:`,
|
|
22
|
+
choices: [
|
|
23
|
+
...auths.map((auth) => ({
|
|
24
|
+
name: `${auth.title || auth.label || "Authentication"} (ID: ${auth.id})`,
|
|
25
|
+
value: auth.id,
|
|
26
|
+
})),
|
|
27
|
+
{
|
|
28
|
+
name: "↗ Skip authentication (may fail)",
|
|
29
|
+
value: null,
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
}),
|
|
33
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export declare const resolverRegistry: {
|
|
2
|
+
readonly appKey: import("./appKey").AppKeyResolver;
|
|
3
|
+
readonly actionType: import("./actionType").ActionTypeResolver;
|
|
4
|
+
readonly actionKey: import("./actionKey").ActionKeyResolver;
|
|
5
|
+
readonly authenticationId: import("./authenticationId").AuthenticationIdResolver;
|
|
6
|
+
readonly inputs: import("./inputs").InputsResolver;
|
|
7
|
+
};
|
|
8
|
+
export type ResolverName = keyof typeof resolverRegistry;
|
|
9
|
+
export type ResolverType = (typeof resolverRegistry)[ResolverName];
|
|
10
|
+
/**
|
|
11
|
+
* Get a resolver by name
|
|
12
|
+
*/
|
|
13
|
+
export declare function getResolver(name: string): ResolverType | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Get all resolvers for a list of missing parameters
|
|
16
|
+
*/
|
|
17
|
+
export declare function getResolversForMissingParams(missingParams: string[]): Record<string, ResolverType>;
|
|
18
|
+
/**
|
|
19
|
+
* Check if a parameter has a resolver
|
|
20
|
+
*/
|
|
21
|
+
export declare function hasResolver(paramName: string): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Get all parameter names that have resolvers
|
|
24
|
+
*/
|
|
25
|
+
export declare function getResolvableParams(): string[];
|
|
26
|
+
/**
|
|
27
|
+
* Resolve dependency chain for a parameter
|
|
28
|
+
* Returns parameters in the order they need to be resolved
|
|
29
|
+
*/
|
|
30
|
+
export declare function getResolutionOrder(paramName: string, resolved?: Set<string>): string[];
|
|
31
|
+
/**
|
|
32
|
+
* Get resolution order for multiple parameters
|
|
33
|
+
*/
|
|
34
|
+
export declare function getResolutionOrderForParams(paramNames: string[]): string[];
|
|
35
|
+
export { appKeyResolver } from "./appKey";
|
|
36
|
+
export { actionTypeResolver } from "./actionType";
|
|
37
|
+
export { actionKeyResolver } from "./actionKey";
|
|
38
|
+
export { authenticationIdResolver } from "./authenticationId";
|
|
39
|
+
export { inputsResolver } from "./inputs";
|
|
40
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/resolvers/index.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,gBAAgB;;;;;;CAMnB,CAAC;AAGX,MAAM,MAAM,YAAY,GAAG,MAAM,OAAO,gBAAgB,CAAC;AACzD,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,YAAY,CAAC,CAAC;AAInE;;GAEG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAElE;AAED;;GAEG;AACH,wBAAgB,4BAA4B,CAC1C,aAAa,EAAE,MAAM,EAAE,GACtB,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAW9B;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAEtD;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,EAAE,CAE9C;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,MAAM,EACjB,QAAQ,GAAE,GAAG,CAAC,MAAM,CAAa,GAChC,MAAM,EAAE,CAuBV;AAED;;GAEG;AACH,wBAAgB,2BAA2B,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAc1E;AAGD,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { appKeyResolver } from "./appKey";
|
|
2
|
+
import { actionTypeResolver } from "./actionType";
|
|
3
|
+
import { actionKeyResolver } from "./actionKey";
|
|
4
|
+
import { authenticationIdResolver } from "./authenticationId";
|
|
5
|
+
import { inputsResolver } from "./inputs";
|
|
6
|
+
// Centralized resolver registry
|
|
7
|
+
export const resolverRegistry = {
|
|
8
|
+
appKey: appKeyResolver,
|
|
9
|
+
actionType: actionTypeResolver,
|
|
10
|
+
actionKey: actionKeyResolver,
|
|
11
|
+
authenticationId: authenticationIdResolver,
|
|
12
|
+
inputs: inputsResolver,
|
|
13
|
+
};
|
|
14
|
+
// Utility functions for working with resolvers
|
|
15
|
+
/**
|
|
16
|
+
* Get a resolver by name
|
|
17
|
+
*/
|
|
18
|
+
export function getResolver(name) {
|
|
19
|
+
return resolverRegistry[name];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Get all resolvers for a list of missing parameters
|
|
23
|
+
*/
|
|
24
|
+
export function getResolversForMissingParams(missingParams) {
|
|
25
|
+
const resolvers = {};
|
|
26
|
+
for (const param of missingParams) {
|
|
27
|
+
const resolver = resolverRegistry[param];
|
|
28
|
+
if (resolver) {
|
|
29
|
+
resolvers[param] = resolver;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return resolvers;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Check if a parameter has a resolver
|
|
36
|
+
*/
|
|
37
|
+
export function hasResolver(paramName) {
|
|
38
|
+
return paramName in resolverRegistry;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Get all parameter names that have resolvers
|
|
42
|
+
*/
|
|
43
|
+
export function getResolvableParams() {
|
|
44
|
+
return Object.keys(resolverRegistry);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Resolve dependency chain for a parameter
|
|
48
|
+
* Returns parameters in the order they need to be resolved
|
|
49
|
+
*/
|
|
50
|
+
export function getResolutionOrder(paramName, resolved = new Set()) {
|
|
51
|
+
const resolver = getResolver(paramName);
|
|
52
|
+
if (!resolver || resolver.type === "static") {
|
|
53
|
+
return [paramName];
|
|
54
|
+
}
|
|
55
|
+
const order = [];
|
|
56
|
+
if ("depends" in resolver && resolver.depends) {
|
|
57
|
+
for (const dependency of resolver.depends) {
|
|
58
|
+
if (!resolved.has(dependency)) {
|
|
59
|
+
order.push(...getResolutionOrder(dependency, resolved));
|
|
60
|
+
resolved.add(dependency);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (!resolved.has(paramName)) {
|
|
65
|
+
order.push(paramName);
|
|
66
|
+
resolved.add(paramName);
|
|
67
|
+
}
|
|
68
|
+
return order;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Get resolution order for multiple parameters
|
|
72
|
+
*/
|
|
73
|
+
export function getResolutionOrderForParams(paramNames) {
|
|
74
|
+
const resolved = new Set();
|
|
75
|
+
const order = [];
|
|
76
|
+
for (const paramName of paramNames) {
|
|
77
|
+
const paramOrder = getResolutionOrder(paramName, resolved);
|
|
78
|
+
for (const param of paramOrder) {
|
|
79
|
+
if (!order.includes(param)) {
|
|
80
|
+
order.push(param);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return order;
|
|
85
|
+
}
|
|
86
|
+
// Re-export individual resolvers for direct access if needed
|
|
87
|
+
export { appKeyResolver } from "./appKey";
|
|
88
|
+
export { actionTypeResolver } from "./actionType";
|
|
89
|
+
export { actionKeyResolver } from "./actionKey";
|
|
90
|
+
export { authenticationIdResolver } from "./authenticationId";
|
|
91
|
+
export { inputsResolver } from "./inputs";
|