@zapier/zapier-sdk 0.4.1 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/README.md +343 -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,256 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
+
import { ZapierValidationError } from "../../types/errors";
|
|
3
|
+
import { requestPlugin } from "./index";
|
|
4
|
+
import { createSdk } from "../../sdk";
|
|
5
|
+
describe("request plugin", () => {
|
|
6
|
+
let mockApiClient;
|
|
7
|
+
let mockFetch;
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
vi.clearAllMocks();
|
|
10
|
+
mockFetch = vi.fn().mockResolvedValue(new Response('{"success": true}', {
|
|
11
|
+
status: 200,
|
|
12
|
+
headers: { "Content-Type": "application/json" },
|
|
13
|
+
}));
|
|
14
|
+
mockApiClient = {
|
|
15
|
+
fetch: mockFetch,
|
|
16
|
+
};
|
|
17
|
+
});
|
|
18
|
+
function createTestSdk() {
|
|
19
|
+
return createSdk({}, { api: mockApiClient, meta: {} }).addPlugin(requestPlugin);
|
|
20
|
+
}
|
|
21
|
+
describe("schema validation", () => {
|
|
22
|
+
it("should throw validation error for missing url", async () => {
|
|
23
|
+
const sdk = createTestSdk();
|
|
24
|
+
await expect(sdk.request({})).rejects.toThrow(ZapierValidationError);
|
|
25
|
+
});
|
|
26
|
+
it("should throw validation error for invalid url", async () => {
|
|
27
|
+
const sdk = createTestSdk();
|
|
28
|
+
await expect(sdk.request({ url: "not-a-url" })).rejects.toThrow(ZapierValidationError);
|
|
29
|
+
});
|
|
30
|
+
it("should throw validation error for invalid method", async () => {
|
|
31
|
+
const sdk = createTestSdk();
|
|
32
|
+
await expect(sdk.request({
|
|
33
|
+
url: "https://api.example.com/data",
|
|
34
|
+
method: "INVALID",
|
|
35
|
+
})).rejects.toThrow(ZapierValidationError);
|
|
36
|
+
});
|
|
37
|
+
it("should throw validation error for invalid authenticationId type", async () => {
|
|
38
|
+
const sdk = createTestSdk();
|
|
39
|
+
await expect(sdk.request({
|
|
40
|
+
url: "https://api.example.com/data",
|
|
41
|
+
authenticationId: "not-a-number",
|
|
42
|
+
})).rejects.toThrow(ZapierValidationError);
|
|
43
|
+
});
|
|
44
|
+
it("should throw validation error for invalid callbackUrl", async () => {
|
|
45
|
+
const sdk = createTestSdk();
|
|
46
|
+
await expect(sdk.request({
|
|
47
|
+
url: "https://api.example.com/data",
|
|
48
|
+
callbackUrl: "not-a-url",
|
|
49
|
+
})).rejects.toThrow(ZapierValidationError);
|
|
50
|
+
});
|
|
51
|
+
it("should pass validation with valid minimal options", async () => {
|
|
52
|
+
const sdk = createTestSdk();
|
|
53
|
+
await sdk.request({ url: "https://api.example.com/data" });
|
|
54
|
+
expect(mockFetch).toHaveBeenCalled();
|
|
55
|
+
});
|
|
56
|
+
it("should pass validation with all valid options", async () => {
|
|
57
|
+
const sdk = createTestSdk();
|
|
58
|
+
await sdk.request({
|
|
59
|
+
url: "https://api.example.com/data",
|
|
60
|
+
method: "POST",
|
|
61
|
+
body: '{"test": true}',
|
|
62
|
+
headers: { "Content-Type": "application/json" },
|
|
63
|
+
authenticationId: 123,
|
|
64
|
+
callbackUrl: "https://webhook.example.com/callback",
|
|
65
|
+
authenticationTemplate: '{"token": "{{auth.token}}"}',
|
|
66
|
+
});
|
|
67
|
+
expect(mockFetch).toHaveBeenCalled();
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
describe("URL transformation", () => {
|
|
71
|
+
it("should transform full URLs to relay path format", async () => {
|
|
72
|
+
const sdk = createTestSdk();
|
|
73
|
+
await sdk.request({
|
|
74
|
+
url: "https://api.github.com/user",
|
|
75
|
+
method: "GET",
|
|
76
|
+
});
|
|
77
|
+
expect(mockFetch).toHaveBeenCalledWith("/relay/api.github.com/user", expect.any(Object));
|
|
78
|
+
});
|
|
79
|
+
it("should preserve query parameters and fragments", async () => {
|
|
80
|
+
const sdk = createTestSdk();
|
|
81
|
+
await sdk.request({
|
|
82
|
+
url: "https://api.example.com/search?q=test&limit=10#section",
|
|
83
|
+
method: "GET",
|
|
84
|
+
});
|
|
85
|
+
expect(mockFetch).toHaveBeenCalledWith("/relay/api.example.com/search?q=test&limit=10#section", expect.any(Object));
|
|
86
|
+
});
|
|
87
|
+
it("should handle URLs with ports", async () => {
|
|
88
|
+
const sdk = createTestSdk();
|
|
89
|
+
await sdk.request({
|
|
90
|
+
url: "https://api.example.com:8443/data",
|
|
91
|
+
method: "GET",
|
|
92
|
+
});
|
|
93
|
+
expect(mockFetch).toHaveBeenCalledWith("/relay/api.example.com:8443/data", expect.any(Object));
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
describe("headers handling", () => {
|
|
97
|
+
it("should pass through regular headers", async () => {
|
|
98
|
+
const sdk = createTestSdk();
|
|
99
|
+
const headers = {
|
|
100
|
+
"Content-Type": "application/json",
|
|
101
|
+
"X-Custom-Header": "test-value",
|
|
102
|
+
};
|
|
103
|
+
await sdk.request({
|
|
104
|
+
url: "https://api.example.com/data",
|
|
105
|
+
method: "POST",
|
|
106
|
+
headers,
|
|
107
|
+
});
|
|
108
|
+
expect(mockFetch).toHaveBeenCalledWith("/relay/api.example.com/data", {
|
|
109
|
+
method: "POST",
|
|
110
|
+
body: undefined,
|
|
111
|
+
headers: {
|
|
112
|
+
"Content-Type": "application/json",
|
|
113
|
+
"X-Custom-Header": "test-value",
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
it("should add relay-specific headers when provided", async () => {
|
|
118
|
+
const sdk = createTestSdk();
|
|
119
|
+
await sdk.request({
|
|
120
|
+
url: "https://api.example.com/data",
|
|
121
|
+
method: "POST",
|
|
122
|
+
authenticationId: 123,
|
|
123
|
+
callbackUrl: "https://webhook.example.com/callback",
|
|
124
|
+
authenticationTemplate: '{"token": "{{auth.token}}"}',
|
|
125
|
+
});
|
|
126
|
+
expect(mockFetch).toHaveBeenCalledWith("/relay/api.example.com/data", {
|
|
127
|
+
method: "POST",
|
|
128
|
+
body: undefined,
|
|
129
|
+
headers: {
|
|
130
|
+
"X-Relay-Authentication-Id": "123",
|
|
131
|
+
"X-Relay-Callback-Url": "https://webhook.example.com/callback",
|
|
132
|
+
"X-Authentication-Template": '{"token": "{{auth.token}}"}',
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
it("should handle Headers object", async () => {
|
|
137
|
+
const sdk = createTestSdk();
|
|
138
|
+
const headers = new Headers();
|
|
139
|
+
headers.set("Content-Type", "application/json");
|
|
140
|
+
headers.set("Authorization", "Bearer token");
|
|
141
|
+
await sdk.request({
|
|
142
|
+
url: "https://api.example.com/data",
|
|
143
|
+
headers,
|
|
144
|
+
});
|
|
145
|
+
expect(mockFetch).toHaveBeenCalledWith("/relay/api.example.com/data", {
|
|
146
|
+
method: "GET",
|
|
147
|
+
body: undefined,
|
|
148
|
+
headers: {
|
|
149
|
+
"content-type": "application/json", // Headers constructor lowercases names
|
|
150
|
+
authorization: "Bearer token", // Headers constructor lowercases names
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
it("should handle headers as array of tuples", async () => {
|
|
155
|
+
const sdk = createTestSdk();
|
|
156
|
+
const headers = [
|
|
157
|
+
["Content-Type", "application/json"],
|
|
158
|
+
["X-Api-Key", "secret"],
|
|
159
|
+
];
|
|
160
|
+
await sdk.request({
|
|
161
|
+
url: "https://api.example.com/data",
|
|
162
|
+
headers,
|
|
163
|
+
});
|
|
164
|
+
expect(mockFetch).toHaveBeenCalledWith("/relay/api.example.com/data", {
|
|
165
|
+
method: "GET",
|
|
166
|
+
body: undefined,
|
|
167
|
+
headers: {
|
|
168
|
+
"Content-Type": "application/json",
|
|
169
|
+
"X-Api-Key": "secret",
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
describe("HTTP methods", () => {
|
|
175
|
+
const methods = [
|
|
176
|
+
"GET",
|
|
177
|
+
"POST",
|
|
178
|
+
"PUT",
|
|
179
|
+
"DELETE",
|
|
180
|
+
"PATCH",
|
|
181
|
+
"HEAD",
|
|
182
|
+
"OPTIONS",
|
|
183
|
+
];
|
|
184
|
+
methods.forEach((method) => {
|
|
185
|
+
it(`should support ${method} method`, async () => {
|
|
186
|
+
const sdk = createTestSdk();
|
|
187
|
+
await sdk.request({
|
|
188
|
+
url: "https://api.example.com/data",
|
|
189
|
+
method,
|
|
190
|
+
});
|
|
191
|
+
expect(mockFetch).toHaveBeenCalledWith("/relay/api.example.com/data", {
|
|
192
|
+
method,
|
|
193
|
+
body: undefined,
|
|
194
|
+
headers: {},
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
it("should default to GET method", async () => {
|
|
199
|
+
const sdk = createTestSdk();
|
|
200
|
+
await sdk.request({
|
|
201
|
+
url: "https://api.example.com/data",
|
|
202
|
+
});
|
|
203
|
+
expect(mockFetch).toHaveBeenCalledWith("/relay/api.example.com/data", {
|
|
204
|
+
method: "GET",
|
|
205
|
+
body: undefined,
|
|
206
|
+
headers: {},
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
describe("request body", () => {
|
|
211
|
+
it("should pass through request body", async () => {
|
|
212
|
+
const sdk = createTestSdk();
|
|
213
|
+
const body = '{"name": "test", "value": 42}';
|
|
214
|
+
await sdk.request({
|
|
215
|
+
url: "https://api.example.com/data",
|
|
216
|
+
method: "POST",
|
|
217
|
+
body,
|
|
218
|
+
});
|
|
219
|
+
expect(mockFetch).toHaveBeenCalledWith("/relay/api.example.com/data", {
|
|
220
|
+
method: "POST",
|
|
221
|
+
body,
|
|
222
|
+
headers: {},
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
describe("response handling", () => {
|
|
227
|
+
it("should return the response from api.fetch", async () => {
|
|
228
|
+
const mockResponse = new Response('{"result": "success"}', {
|
|
229
|
+
status: 200,
|
|
230
|
+
statusText: "OK",
|
|
231
|
+
headers: { "Content-Type": "application/json" },
|
|
232
|
+
});
|
|
233
|
+
mockFetch.mockResolvedValue(mockResponse);
|
|
234
|
+
const sdk = createTestSdk();
|
|
235
|
+
const response = await sdk.request({
|
|
236
|
+
url: "https://api.example.com/data",
|
|
237
|
+
});
|
|
238
|
+
expect(response).toBe(mockResponse);
|
|
239
|
+
expect(response.status).toBe(200);
|
|
240
|
+
});
|
|
241
|
+
it("should handle API errors", async () => {
|
|
242
|
+
const error = new Error("Network error");
|
|
243
|
+
mockFetch.mockRejectedValue(error);
|
|
244
|
+
const sdk = createTestSdk();
|
|
245
|
+
await expect(sdk.request({ url: "https://api.example.com/data" })).rejects.toThrow("Network error");
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
describe("context and metadata", () => {
|
|
249
|
+
it("should provide context with meta information", () => {
|
|
250
|
+
const sdk = createTestSdk();
|
|
251
|
+
const context = sdk.getContext();
|
|
252
|
+
expect(context.meta.request).toBeDefined();
|
|
253
|
+
expect(context.meta.request.inputSchema).toBeDefined();
|
|
254
|
+
});
|
|
255
|
+
});
|
|
256
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const RelayRequestSchema: z.ZodObject<{
|
|
3
|
+
url: z.ZodString;
|
|
4
|
+
method: z.ZodOptional<z.ZodEnum<["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"]>>;
|
|
5
|
+
body: z.ZodOptional<z.ZodAny>;
|
|
6
|
+
authenticationId: z.ZodOptional<z.ZodNumber>;
|
|
7
|
+
callbackUrl: z.ZodOptional<z.ZodString>;
|
|
8
|
+
authenticationTemplate: z.ZodOptional<z.ZodString>;
|
|
9
|
+
headers: z.ZodOptional<z.ZodUnion<[z.ZodRecord<z.ZodString, z.ZodString>, z.ZodType<Headers, z.ZodTypeDef, Headers>, z.ZodArray<z.ZodTuple<[z.ZodString, z.ZodString], null>, "many">]>>;
|
|
10
|
+
} & {
|
|
11
|
+
relayBaseUrl: z.ZodOptional<z.ZodString>;
|
|
12
|
+
}, "strip", z.ZodTypeAny, {
|
|
13
|
+
url: string;
|
|
14
|
+
method?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "HEAD" | "OPTIONS" | undefined;
|
|
15
|
+
body?: any;
|
|
16
|
+
authenticationId?: number | undefined;
|
|
17
|
+
callbackUrl?: string | undefined;
|
|
18
|
+
authenticationTemplate?: string | undefined;
|
|
19
|
+
headers?: Record<string, string> | [string, string][] | Headers | undefined;
|
|
20
|
+
relayBaseUrl?: string | undefined;
|
|
21
|
+
}, {
|
|
22
|
+
url: string;
|
|
23
|
+
method?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "HEAD" | "OPTIONS" | undefined;
|
|
24
|
+
body?: any;
|
|
25
|
+
authenticationId?: number | undefined;
|
|
26
|
+
callbackUrl?: string | undefined;
|
|
27
|
+
authenticationTemplate?: string | undefined;
|
|
28
|
+
headers?: Record<string, string> | [string, string][] | Headers | undefined;
|
|
29
|
+
relayBaseUrl?: string | undefined;
|
|
30
|
+
}>;
|
|
31
|
+
export type RelayRequestOptions = z.infer<typeof RelayRequestSchema>;
|
|
32
|
+
export type RelayRequestError = import("../../types/errors").ZapierApiError | import("../../types/errors").ZapierValidationError | import("../../types/errors").ZapierUnknownError;
|
|
33
|
+
export interface RelayRequestSdkFunction {
|
|
34
|
+
request: (options: RelayRequestOptions) => Promise<Response>;
|
|
35
|
+
}
|
|
36
|
+
export declare const RelayFetchSchema: z.ZodObject<{
|
|
37
|
+
url: z.ZodString;
|
|
38
|
+
method: z.ZodOptional<z.ZodEnum<["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"]>>;
|
|
39
|
+
body: z.ZodOptional<z.ZodAny>;
|
|
40
|
+
authenticationId: z.ZodOptional<z.ZodNumber>;
|
|
41
|
+
callbackUrl: z.ZodOptional<z.ZodString>;
|
|
42
|
+
authenticationTemplate: z.ZodOptional<z.ZodString>;
|
|
43
|
+
headers: z.ZodOptional<z.ZodUnion<[z.ZodRecord<z.ZodString, z.ZodString>, z.ZodType<Headers, z.ZodTypeDef, Headers>, z.ZodArray<z.ZodTuple<[z.ZodString, z.ZodString], null>, "many">]>>;
|
|
44
|
+
} & {
|
|
45
|
+
relayBaseUrl: z.ZodOptional<z.ZodString>;
|
|
46
|
+
}, "strip", z.ZodTypeAny, {
|
|
47
|
+
url: string;
|
|
48
|
+
method?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "HEAD" | "OPTIONS" | undefined;
|
|
49
|
+
body?: any;
|
|
50
|
+
authenticationId?: number | undefined;
|
|
51
|
+
callbackUrl?: string | undefined;
|
|
52
|
+
authenticationTemplate?: string | undefined;
|
|
53
|
+
headers?: Record<string, string> | [string, string][] | Headers | undefined;
|
|
54
|
+
relayBaseUrl?: string | undefined;
|
|
55
|
+
}, {
|
|
56
|
+
url: string;
|
|
57
|
+
method?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "HEAD" | "OPTIONS" | undefined;
|
|
58
|
+
body?: any;
|
|
59
|
+
authenticationId?: number | undefined;
|
|
60
|
+
callbackUrl?: string | undefined;
|
|
61
|
+
authenticationTemplate?: string | undefined;
|
|
62
|
+
headers?: Record<string, string> | [string, string][] | Headers | undefined;
|
|
63
|
+
relayBaseUrl?: string | undefined;
|
|
64
|
+
}>;
|
|
65
|
+
export type RelayFetchOptions = RelayRequestOptions;
|
|
66
|
+
export interface RelayFetchSdkFunction {
|
|
67
|
+
fetch: (options: RelayFetchOptions) => Promise<Response>;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=schemas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../src/plugins/request/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuC+C,CAAC;AAG/E,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAGrE,MAAM,MAAM,iBAAiB,GACzB,OAAO,oBAAoB,EAAE,cAAc,GAC3C,OAAO,oBAAoB,EAAE,qBAAqB,GAClD,OAAO,oBAAoB,EAAE,kBAAkB,CAAC;AAGpD,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,CAAC,OAAO,EAAE,mBAAmB,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;CAC9D;AAGD,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAAqB,CAAC;AACnD,MAAM,MAAM,iBAAiB,GAAG,mBAAmB,CAAC;AACpD,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,CAAC,OAAO,EAAE,iBAAiB,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;CAC1D"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
// Pure Zod schema for the request function
|
|
3
|
+
export const RelayRequestSchema = z
|
|
4
|
+
.object({
|
|
5
|
+
url: z
|
|
6
|
+
.string()
|
|
7
|
+
.url()
|
|
8
|
+
.describe("The URL to request (will be proxied through Relay)"),
|
|
9
|
+
method: z
|
|
10
|
+
.enum(["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"])
|
|
11
|
+
.optional()
|
|
12
|
+
.describe("HTTP method"),
|
|
13
|
+
body: z.any().optional().describe("Request body as a string"),
|
|
14
|
+
authenticationId: z
|
|
15
|
+
.number()
|
|
16
|
+
.int()
|
|
17
|
+
.optional()
|
|
18
|
+
.describe("Zapier authentication ID to use for the request"),
|
|
19
|
+
callbackUrl: z
|
|
20
|
+
.string()
|
|
21
|
+
.url()
|
|
22
|
+
.optional()
|
|
23
|
+
.describe("URL to send async response to (makes request async)"),
|
|
24
|
+
authenticationTemplate: z
|
|
25
|
+
.string()
|
|
26
|
+
.optional()
|
|
27
|
+
.describe("Optional JSON string authentication template to bypass Notary lookup"),
|
|
28
|
+
headers: z
|
|
29
|
+
.union([
|
|
30
|
+
z.record(z.string()),
|
|
31
|
+
z.instanceof(Headers),
|
|
32
|
+
z.array(z.tuple([z.string(), z.string()])),
|
|
33
|
+
])
|
|
34
|
+
.optional()
|
|
35
|
+
.describe("Request headers"),
|
|
36
|
+
})
|
|
37
|
+
.extend({
|
|
38
|
+
relayBaseUrl: z.string().optional().describe("Base URL for Relay service"),
|
|
39
|
+
})
|
|
40
|
+
.describe("Make authenticated HTTP requests through Zapier's Relay service");
|
|
41
|
+
// Legacy exports for compatibility
|
|
42
|
+
export const RelayFetchSchema = RelayRequestSchema;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Plugin, GetSdkType } from "../../types/plugin";
|
|
2
|
+
import type { ApiClient } from "../../api";
|
|
3
|
+
import { RunActionSchema, type RunActionOptions } from "./schemas";
|
|
4
|
+
import type { GetActionPluginProvides } from "../getAction";
|
|
5
|
+
import type { GetAppPluginProvides } from "../getApp";
|
|
6
|
+
export interface RunActionPluginProvides {
|
|
7
|
+
runAction: (options?: RunActionOptions) => Promise<{
|
|
8
|
+
data: any[];
|
|
9
|
+
}> & AsyncIterable<{
|
|
10
|
+
data: any[];
|
|
11
|
+
nextCursor?: string;
|
|
12
|
+
}> & {
|
|
13
|
+
items(): AsyncIterable<any>;
|
|
14
|
+
};
|
|
15
|
+
context: {
|
|
16
|
+
meta: {
|
|
17
|
+
runAction: {
|
|
18
|
+
inputSchema: typeof RunActionSchema;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export declare const runActionPlugin: Plugin<GetSdkType<GetActionPluginProvides & GetAppPluginProvides>, // requires getAction and getApp in SDK
|
|
24
|
+
{
|
|
25
|
+
api: ApiClient;
|
|
26
|
+
}, // requires api in context
|
|
27
|
+
RunActionPluginProvides>;
|
|
28
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/runAction/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EACL,eAAe,EACf,KAAK,gBAAgB,EAEtB,MAAM,WAAW,CAAC;AAOnB,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAEtD,MAAM,WAAW,uBAAuB;IACtC,SAAS,EAAE,CAAC,OAAO,CAAC,EAAE,gBAAgB,KAAK,OAAO,CAAC;QAAE,IAAI,EAAE,GAAG,EAAE,CAAA;KAAE,CAAC,GACjE,aAAa,CAAC;QAAE,IAAI,EAAE,GAAG,EAAE,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG;QACpD,KAAK,IAAI,aAAa,CAAC,GAAG,CAAC,CAAC;KAC7B,CAAC;IACJ,OAAO,EAAE;QACP,IAAI,EAAE;YACJ,SAAS,EAAE;gBACT,WAAW,EAAE,OAAO,eAAe,CAAC;aACrC,CAAC;SACH,CAAC;KACH,CAAC;CACH;AAwED,eAAO,MAAM,eAAe,EAAE,MAAM,CAClC,UAAU,CAAC,uBAAuB,GAAG,oBAAoB,CAAC,EAAE,uCAAuC;AACnG;IAAE,GAAG,EAAE,SAAS,CAAA;CAAE,EAAE,0BAA0B;AAC9C,uBAAuB,CAwExB,CAAC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { RunActionSchema, } from "./schemas";
|
|
2
|
+
import { ZapierValidationError, ZapierConfigurationError, ZapierActionError, } from "../../types/errors";
|
|
3
|
+
import { createPaginatedFunction } from "../../utils/function-utils";
|
|
4
|
+
async function executeAction(actionOptions) {
|
|
5
|
+
const { api, sdk, appKey, actionKey, actionType, executionOptions, authenticationId, } = actionOptions;
|
|
6
|
+
// Use the getApp plugin to get the current implementation ID
|
|
7
|
+
const appData = await sdk.getApp({ appKey });
|
|
8
|
+
const selectedApi = appData.data.current_implementation_id;
|
|
9
|
+
if (!selectedApi) {
|
|
10
|
+
throw new ZapierConfigurationError("No current_implementation_id found for app", { configType: "current_implementation_id" });
|
|
11
|
+
}
|
|
12
|
+
// Step 1: POST to /actions/v1/runs to start execution
|
|
13
|
+
const runRequestData = {
|
|
14
|
+
selected_api: selectedApi,
|
|
15
|
+
action_key: actionKey,
|
|
16
|
+
action_type: actionType,
|
|
17
|
+
inputs: executionOptions.inputs || {},
|
|
18
|
+
};
|
|
19
|
+
// Only include authentication_id if it's provided
|
|
20
|
+
if (authenticationId !== null && authenticationId !== undefined) {
|
|
21
|
+
runRequestData.authentication_id = authenticationId;
|
|
22
|
+
}
|
|
23
|
+
const runRequest = {
|
|
24
|
+
data: runRequestData,
|
|
25
|
+
};
|
|
26
|
+
const runData = await api.post("/api/actions/v1/runs", runRequest);
|
|
27
|
+
const runId = runData.data.id;
|
|
28
|
+
// Step 2: Poll GET /actions/v1/runs/{run_id} for results
|
|
29
|
+
return await api.poll(`/api/actions/v1/runs/${runId}`, {
|
|
30
|
+
successStatus: 200,
|
|
31
|
+
pendingStatus: 202,
|
|
32
|
+
resultExtractor: (result) => result.data,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
export const runActionPlugin = ({ sdk, context }) => {
|
|
36
|
+
const runAction = createPaginatedFunction(async function runActionPage(options) {
|
|
37
|
+
const { api } = context;
|
|
38
|
+
const { appKey, actionKey, actionType, authenticationId, inputs = {}, } = options;
|
|
39
|
+
// Validate that the action exists using the getAction plugin
|
|
40
|
+
const actionData = await sdk.getAction({
|
|
41
|
+
appKey: appKey,
|
|
42
|
+
actionKey: actionKey,
|
|
43
|
+
actionType: actionType,
|
|
44
|
+
});
|
|
45
|
+
// Validate action type matches
|
|
46
|
+
if (actionData.data.action_type !== actionType) {
|
|
47
|
+
throw new ZapierValidationError(`Action type mismatch: expected ${actionType}, got ${actionData.data.action_type}`);
|
|
48
|
+
}
|
|
49
|
+
// Execute the action using the Actions API (supports all action types)
|
|
50
|
+
const result = await executeAction({
|
|
51
|
+
api,
|
|
52
|
+
sdk,
|
|
53
|
+
appKey,
|
|
54
|
+
actionKey,
|
|
55
|
+
actionType,
|
|
56
|
+
executionOptions: { inputs },
|
|
57
|
+
authenticationId,
|
|
58
|
+
options,
|
|
59
|
+
});
|
|
60
|
+
// Check for errors in the result and throw if present
|
|
61
|
+
if (result.errors && result.errors.length > 0) {
|
|
62
|
+
const errorMessage = result.errors
|
|
63
|
+
.map((error) => error.detail || error.title || "Unknown error")
|
|
64
|
+
.join("; ");
|
|
65
|
+
throw new ZapierActionError(`Action execution failed: ${errorMessage}`, {
|
|
66
|
+
appKey,
|
|
67
|
+
actionKey,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
// Return the results array wrapped in data with empty nextCursor (no pagination for action execution)
|
|
71
|
+
return {
|
|
72
|
+
data: result.results || [],
|
|
73
|
+
nextCursor: undefined, // No pagination implemented yet
|
|
74
|
+
};
|
|
75
|
+
}, RunActionSchema);
|
|
76
|
+
return {
|
|
77
|
+
runAction,
|
|
78
|
+
context: {
|
|
79
|
+
meta: {
|
|
80
|
+
runAction: {
|
|
81
|
+
inputSchema: RunActionSchema,
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../../src/plugins/runAction/index.test.ts"],"names":[],"mappings":""}
|