@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,103 @@
|
|
|
1
|
+
import type { Plugin } from "../../types/plugin";
|
|
2
|
+
import type { ApiClient } from "../../api";
|
|
3
|
+
import { RelayRequestSchema, type RelayRequestOptions } from "./schemas";
|
|
4
|
+
import { createFunction } from "../../utils/function-utils";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Transforms full URLs into Relay format: /relay/{domain}/{path}
|
|
8
|
+
*
|
|
9
|
+
* @param url - The full URL to transform (e.g., "https://api.github.com/user")
|
|
10
|
+
* @returns The relay path format (e.g., "/relay/api.github.com/user")
|
|
11
|
+
*/
|
|
12
|
+
function transformUrlToRelayPath(url: string | URL): string {
|
|
13
|
+
const targetUrl = new URL(url);
|
|
14
|
+
|
|
15
|
+
// Build the Relay path: /relay/{host}{pathname}{search}{hash}
|
|
16
|
+
// Use host instead of hostname to include port if present
|
|
17
|
+
const relayPath = `/relay/${targetUrl.host}${targetUrl.pathname}${targetUrl.search}${targetUrl.hash}`;
|
|
18
|
+
|
|
19
|
+
return relayPath;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface RequestPluginProvides {
|
|
23
|
+
request: (options: RelayRequestOptions) => Promise<Response>;
|
|
24
|
+
context: {
|
|
25
|
+
meta: {
|
|
26
|
+
request: {
|
|
27
|
+
inputSchema: typeof RelayRequestSchema;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const requestPlugin: Plugin<
|
|
34
|
+
{}, // no SDK dependencies
|
|
35
|
+
{ api: ApiClient }, // requires api in context
|
|
36
|
+
RequestPluginProvides
|
|
37
|
+
> = ({ context }) => {
|
|
38
|
+
const request = createFunction(async function request(
|
|
39
|
+
options: RelayRequestOptions,
|
|
40
|
+
): Promise<Response> {
|
|
41
|
+
const { api } = context;
|
|
42
|
+
const {
|
|
43
|
+
url,
|
|
44
|
+
method = "GET",
|
|
45
|
+
body,
|
|
46
|
+
headers: optionsHeaders,
|
|
47
|
+
authenticationId,
|
|
48
|
+
callbackUrl,
|
|
49
|
+
authenticationTemplate,
|
|
50
|
+
} = options;
|
|
51
|
+
|
|
52
|
+
// Transform full URL to relay path format
|
|
53
|
+
const relayPath = transformUrlToRelayPath(url);
|
|
54
|
+
|
|
55
|
+
// Build headers for the request
|
|
56
|
+
const headers: Record<string, string> = {};
|
|
57
|
+
|
|
58
|
+
// Copy existing headers
|
|
59
|
+
if (optionsHeaders) {
|
|
60
|
+
const headerEntries =
|
|
61
|
+
optionsHeaders instanceof Headers
|
|
62
|
+
? Array.from(optionsHeaders.entries())
|
|
63
|
+
: Array.isArray(optionsHeaders)
|
|
64
|
+
? optionsHeaders
|
|
65
|
+
: Object.entries(optionsHeaders);
|
|
66
|
+
|
|
67
|
+
for (const [key, value] of headerEntries) {
|
|
68
|
+
headers[key] = value;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Add Relay-specific headers
|
|
73
|
+
if (authenticationId) {
|
|
74
|
+
headers["X-Relay-Authentication-Id"] = authenticationId.toString();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (callbackUrl) {
|
|
78
|
+
headers["X-Relay-Callback-Url"] = callbackUrl;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (authenticationTemplate) {
|
|
82
|
+
headers["X-Authentication-Template"] = authenticationTemplate;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Use the API client's fetch method directly - let it handle auth automatically
|
|
86
|
+
return await api.fetch(relayPath, {
|
|
87
|
+
method,
|
|
88
|
+
body,
|
|
89
|
+
headers,
|
|
90
|
+
});
|
|
91
|
+
}, RelayRequestSchema);
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
request,
|
|
95
|
+
context: {
|
|
96
|
+
meta: {
|
|
97
|
+
request: {
|
|
98
|
+
inputSchema: RelayRequestSchema,
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import type { FunctionOptions } from "../../types/domain";
|
|
3
2
|
|
|
4
3
|
// Pure Zod schema for the request function
|
|
5
4
|
export const RelayRequestSchema = z
|
|
@@ -12,7 +11,7 @@ export const RelayRequestSchema = z
|
|
|
12
11
|
.enum(["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"])
|
|
13
12
|
.optional()
|
|
14
13
|
.describe("HTTP method"),
|
|
15
|
-
body: z.
|
|
14
|
+
body: z.any().optional().describe("Request body as a string"),
|
|
16
15
|
authenticationId: z
|
|
17
16
|
.number()
|
|
18
17
|
.int()
|
|
@@ -29,16 +28,28 @@ export const RelayRequestSchema = z
|
|
|
29
28
|
.describe(
|
|
30
29
|
"Optional JSON string authentication template to bypass Notary lookup",
|
|
31
30
|
),
|
|
32
|
-
headers: z
|
|
31
|
+
headers: z
|
|
32
|
+
.union([
|
|
33
|
+
z.record(z.string()),
|
|
34
|
+
z.instanceof(Headers),
|
|
35
|
+
z.array(z.tuple([z.string(), z.string()])),
|
|
36
|
+
])
|
|
37
|
+
.optional()
|
|
38
|
+
.describe("Request headers"),
|
|
39
|
+
})
|
|
40
|
+
.extend({
|
|
41
|
+
relayBaseUrl: z.string().optional().describe("Base URL for Relay service"),
|
|
33
42
|
})
|
|
34
43
|
.describe("Make authenticated HTTP requests through Zapier's Relay service");
|
|
35
44
|
|
|
36
|
-
// Type inferred from schema
|
|
37
|
-
export type RelayRequestOptions = z.infer<typeof RelayRequestSchema
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
45
|
+
// Type inferred from schema
|
|
46
|
+
export type RelayRequestOptions = z.infer<typeof RelayRequestSchema>;
|
|
47
|
+
|
|
48
|
+
// Error union for this function
|
|
49
|
+
export type RelayRequestError =
|
|
50
|
+
| import("../../types/errors").ZapierApiError
|
|
51
|
+
| import("../../types/errors").ZapierValidationError
|
|
52
|
+
| import("../../types/errors").ZapierUnknownError;
|
|
42
53
|
|
|
43
54
|
// SDK function interface
|
|
44
55
|
export interface RelayRequestSdkFunction {
|
|
@@ -0,0 +1,387 @@
|
|
|
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
|
+
import type { ApiClient } from "../../api";
|
|
6
|
+
import type { RunActionOptions } from "./schemas";
|
|
7
|
+
import type { ActionItem } from "../../types/domain";
|
|
8
|
+
|
|
9
|
+
const mockAction: ActionItem = {
|
|
10
|
+
type: "action",
|
|
11
|
+
key: "send_message",
|
|
12
|
+
title: "Send Message",
|
|
13
|
+
description: "Send a message to a channel",
|
|
14
|
+
app_key: "slack",
|
|
15
|
+
action_type: "write",
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const mockActionResponse = {
|
|
19
|
+
results: [
|
|
20
|
+
{
|
|
21
|
+
id: "msg_123",
|
|
22
|
+
text: "Hello, world!",
|
|
23
|
+
channel: "#general",
|
|
24
|
+
user: "user_456",
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
meta: {
|
|
28
|
+
next_cursor: null,
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
describe("runAction plugin", () => {
|
|
33
|
+
let mockApiClient: ApiClient;
|
|
34
|
+
let mockGetAction: any;
|
|
35
|
+
let mockGetApp: any;
|
|
36
|
+
|
|
37
|
+
beforeEach(() => {
|
|
38
|
+
vi.clearAllMocks();
|
|
39
|
+
mockApiClient = {
|
|
40
|
+
post: vi.fn().mockResolvedValue({ data: { id: "run_123" } }),
|
|
41
|
+
poll: vi.fn().mockResolvedValue({ results: mockActionResponse.results }),
|
|
42
|
+
} as Partial<ApiClient> as ApiClient;
|
|
43
|
+
|
|
44
|
+
mockGetAction = vi.fn().mockResolvedValue({
|
|
45
|
+
data: mockAction,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
mockGetApp = vi.fn().mockResolvedValue({
|
|
49
|
+
data: { current_implementation_id: "SlackCLIAPI" },
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
function createTestSdk() {
|
|
54
|
+
return createSdk(
|
|
55
|
+
{ getAction: mockGetAction, getApp: mockGetApp }, // Provide getAction and getApp in SDK
|
|
56
|
+
{ api: mockApiClient, meta: {} },
|
|
57
|
+
).addPlugin(runActionPlugin as any);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
describe("schema validation", () => {
|
|
61
|
+
it("should throw validation error for missing appKey", () => {
|
|
62
|
+
const sdk = createTestSdk();
|
|
63
|
+
expect(() => {
|
|
64
|
+
sdk.runAction({
|
|
65
|
+
actionType: "write",
|
|
66
|
+
actionKey: "send_message",
|
|
67
|
+
inputs: { message: "Hello" },
|
|
68
|
+
} as Partial<RunActionOptions> as RunActionOptions);
|
|
69
|
+
}).toThrow(ZapierValidationError);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("should throw validation error for missing actionType", () => {
|
|
73
|
+
const sdk = createTestSdk();
|
|
74
|
+
expect(() => {
|
|
75
|
+
sdk.runAction({
|
|
76
|
+
appKey: "slack",
|
|
77
|
+
actionKey: "send_message",
|
|
78
|
+
inputs: { message: "Hello" },
|
|
79
|
+
} as Partial<RunActionOptions> as RunActionOptions);
|
|
80
|
+
}).toThrow(ZapierValidationError);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("should throw validation error for missing actionKey", () => {
|
|
84
|
+
const sdk = createTestSdk();
|
|
85
|
+
expect(() => {
|
|
86
|
+
sdk.runAction({
|
|
87
|
+
appKey: "slack",
|
|
88
|
+
actionType: "write",
|
|
89
|
+
inputs: { message: "Hello" },
|
|
90
|
+
} as Partial<RunActionOptions> as RunActionOptions);
|
|
91
|
+
}).toThrow(ZapierValidationError);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("should pass validation with all required fields", async () => {
|
|
95
|
+
const sdk = createTestSdk();
|
|
96
|
+
const result = await sdk.runAction({
|
|
97
|
+
appKey: "slack",
|
|
98
|
+
actionType: "write",
|
|
99
|
+
actionKey: "send_message",
|
|
100
|
+
inputs: { message: "Hello" },
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
expect(result.data).toHaveLength(1);
|
|
104
|
+
expect(result.data[0]).toEqual(mockActionResponse.results[0]);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
describe("action execution", () => {
|
|
109
|
+
it("should validate action exists using getAction", async () => {
|
|
110
|
+
const sdk = createTestSdk();
|
|
111
|
+
await sdk.runAction({
|
|
112
|
+
appKey: "slack",
|
|
113
|
+
actionType: "write",
|
|
114
|
+
actionKey: "send_message",
|
|
115
|
+
inputs: { message: "Hello" },
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
expect(mockGetAction).toHaveBeenCalledWith({
|
|
119
|
+
appKey: "slack",
|
|
120
|
+
actionKey: "send_message",
|
|
121
|
+
actionType: "write",
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("should throw error when action type doesn't match", async () => {
|
|
126
|
+
// Mock getAction to return an action with different type
|
|
127
|
+
mockGetAction.mockResolvedValue({
|
|
128
|
+
data: { ...mockAction, action_type: "read" },
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
const sdk = createTestSdk();
|
|
132
|
+
await expect(
|
|
133
|
+
sdk.runAction({
|
|
134
|
+
appKey: "slack",
|
|
135
|
+
actionType: "write", // Different from mocked action type
|
|
136
|
+
actionKey: "send_message",
|
|
137
|
+
inputs: { message: "Hello" },
|
|
138
|
+
}),
|
|
139
|
+
).rejects.toThrow(ZapierValidationError);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it("should execute action with correct API call", async () => {
|
|
143
|
+
const sdk = createTestSdk();
|
|
144
|
+
await sdk.runAction({
|
|
145
|
+
appKey: "slack",
|
|
146
|
+
actionType: "write",
|
|
147
|
+
actionKey: "send_message",
|
|
148
|
+
inputs: { message: "Hello", channel: "#general" },
|
|
149
|
+
authenticationId: 12345,
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
expect(mockApiClient.post).toHaveBeenCalledWith("/api/actions/v1/runs", {
|
|
153
|
+
data: {
|
|
154
|
+
selected_api: "SlackCLIAPI",
|
|
155
|
+
action_key: "send_message",
|
|
156
|
+
action_type: "write",
|
|
157
|
+
inputs: { message: "Hello", channel: "#general" },
|
|
158
|
+
authentication_id: 12345,
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
expect(mockApiClient.poll).toHaveBeenCalledWith(
|
|
163
|
+
"/api/actions/v1/runs/run_123",
|
|
164
|
+
{
|
|
165
|
+
successStatus: 200,
|
|
166
|
+
pendingStatus: 202,
|
|
167
|
+
resultExtractor: expect.any(Function),
|
|
168
|
+
},
|
|
169
|
+
);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("should execute action without authentication ID", async () => {
|
|
173
|
+
const sdk = createTestSdk();
|
|
174
|
+
await sdk.runAction({
|
|
175
|
+
appKey: "slack",
|
|
176
|
+
actionType: "write",
|
|
177
|
+
actionKey: "send_message",
|
|
178
|
+
inputs: { message: "Hello" },
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
expect(mockApiClient.post).toHaveBeenCalledWith("/api/actions/v1/runs", {
|
|
182
|
+
data: {
|
|
183
|
+
selected_api: "SlackCLIAPI",
|
|
184
|
+
action_key: "send_message",
|
|
185
|
+
action_type: "write",
|
|
186
|
+
inputs: { message: "Hello" },
|
|
187
|
+
},
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it("should handle pagination cursor", async () => {
|
|
192
|
+
const sdk = createTestSdk();
|
|
193
|
+
const runActionResult = sdk.runAction({
|
|
194
|
+
appKey: "slack",
|
|
195
|
+
actionType: "write",
|
|
196
|
+
actionKey: "send_message",
|
|
197
|
+
inputs: { message: "Hello" },
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
// Simulate pagination by getting an iterator
|
|
201
|
+
const iterator = runActionResult[Symbol.asyncIterator]();
|
|
202
|
+
await iterator.next();
|
|
203
|
+
|
|
204
|
+
expect(mockApiClient.post).toHaveBeenCalledWith(
|
|
205
|
+
"/api/actions/v1/runs",
|
|
206
|
+
expect.objectContaining({
|
|
207
|
+
data: expect.objectContaining({
|
|
208
|
+
inputs: { message: "Hello" },
|
|
209
|
+
selected_api: "SlackCLIAPI",
|
|
210
|
+
action_key: "send_message",
|
|
211
|
+
action_type: "write",
|
|
212
|
+
}),
|
|
213
|
+
}),
|
|
214
|
+
);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
it("should return results in correct format", async () => {
|
|
218
|
+
const sdk = createTestSdk();
|
|
219
|
+
const result = await sdk.runAction({
|
|
220
|
+
appKey: "slack",
|
|
221
|
+
actionType: "write",
|
|
222
|
+
actionKey: "send_message",
|
|
223
|
+
inputs: { message: "Hello" },
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
expect(result.data).toEqual(mockActionResponse.results);
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
it("should handle single result (not array)", async () => {
|
|
230
|
+
const singleResult = { id: "msg_123", text: "Hello" };
|
|
231
|
+
mockApiClient.post = vi
|
|
232
|
+
.fn()
|
|
233
|
+
.mockResolvedValue({ data: { id: "run_123" } });
|
|
234
|
+
mockApiClient.poll = vi.fn().mockResolvedValue({
|
|
235
|
+
results: [singleResult], // Poll returns the actual results
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
const sdk = createTestSdk();
|
|
239
|
+
const result = await sdk.runAction({
|
|
240
|
+
appKey: "slack",
|
|
241
|
+
actionType: "write",
|
|
242
|
+
actionKey: "send_message",
|
|
243
|
+
inputs: { message: "Hello" },
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
expect(result.data).toEqual([singleResult]); // Should be wrapped in array
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
describe("error handling", () => {
|
|
251
|
+
it("should handle action execution errors", async () => {
|
|
252
|
+
mockApiClient.post = vi
|
|
253
|
+
.fn()
|
|
254
|
+
.mockResolvedValue({ data: { id: "run_123" } });
|
|
255
|
+
mockApiClient.poll = vi.fn().mockResolvedValue({
|
|
256
|
+
results: [],
|
|
257
|
+
errors: [
|
|
258
|
+
{ title: "Invalid inputs", detail: "Message cannot be empty" },
|
|
259
|
+
],
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
const sdk = createTestSdk();
|
|
263
|
+
await expect(
|
|
264
|
+
sdk.runAction({
|
|
265
|
+
appKey: "slack",
|
|
266
|
+
actionType: "write",
|
|
267
|
+
actionKey: "send_message",
|
|
268
|
+
inputs: { message: "" }, // Invalid input
|
|
269
|
+
}),
|
|
270
|
+
).rejects.toThrow(ZapierActionError);
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
it("should handle server errors", async () => {
|
|
274
|
+
mockApiClient.post = vi.fn().mockImplementation((_url, options) => {
|
|
275
|
+
const error = options.customErrorHandler?.({
|
|
276
|
+
status: 500,
|
|
277
|
+
data: { message: "Internal server error" },
|
|
278
|
+
});
|
|
279
|
+
if (error) throw error;
|
|
280
|
+
throw new Error("Server Error");
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
const sdk = createTestSdk();
|
|
284
|
+
await expect(
|
|
285
|
+
sdk.runAction({
|
|
286
|
+
appKey: "slack",
|
|
287
|
+
actionType: "write",
|
|
288
|
+
actionKey: "send_message",
|
|
289
|
+
inputs: { message: "Hello" },
|
|
290
|
+
}),
|
|
291
|
+
).rejects.toThrow();
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
it("should propagate getAction errors", async () => {
|
|
295
|
+
mockGetAction.mockRejectedValue(new Error("Action not found"));
|
|
296
|
+
|
|
297
|
+
const sdk = createTestSdk();
|
|
298
|
+
await expect(
|
|
299
|
+
sdk.runAction({
|
|
300
|
+
appKey: "slack",
|
|
301
|
+
actionType: "write",
|
|
302
|
+
actionKey: "nonexistent",
|
|
303
|
+
inputs: { message: "Hello" },
|
|
304
|
+
}),
|
|
305
|
+
).rejects.toThrow("Action not found");
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
it("should handle unexpected errors during execution", async () => {
|
|
309
|
+
mockApiClient.post = vi
|
|
310
|
+
.fn()
|
|
311
|
+
.mockRejectedValue(new Error("Network error"));
|
|
312
|
+
|
|
313
|
+
const sdk = createTestSdk();
|
|
314
|
+
await expect(
|
|
315
|
+
sdk.runAction({
|
|
316
|
+
appKey: "slack",
|
|
317
|
+
actionType: "write",
|
|
318
|
+
actionKey: "send_message",
|
|
319
|
+
inputs: { message: "Hello" },
|
|
320
|
+
}),
|
|
321
|
+
).rejects.toThrow("Network error");
|
|
322
|
+
});
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
describe("pagination", () => {
|
|
326
|
+
it("should support maxItems limit", async () => {
|
|
327
|
+
const sdk = createTestSdk();
|
|
328
|
+
const result = await sdk.runAction({
|
|
329
|
+
appKey: "slack",
|
|
330
|
+
actionType: "write",
|
|
331
|
+
actionKey: "send_message",
|
|
332
|
+
inputs: { message: "Hello" },
|
|
333
|
+
maxItems: 1,
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
expect(result.data).toHaveLength(1);
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
it("should support async iteration over pages", async () => {
|
|
340
|
+
const sdk = createTestSdk();
|
|
341
|
+
const runActionResult = sdk.runAction({
|
|
342
|
+
appKey: "slack",
|
|
343
|
+
actionType: "write",
|
|
344
|
+
actionKey: "send_message",
|
|
345
|
+
inputs: { message: "Hello" },
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
const pages = [];
|
|
349
|
+
for await (const page of runActionResult) {
|
|
350
|
+
pages.push(page);
|
|
351
|
+
break; // Just get first page for testing
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
expect(pages).toHaveLength(1);
|
|
355
|
+
expect(pages[0].data).toEqual(mockActionResponse.results);
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
it("should support async iteration over individual items", async () => {
|
|
359
|
+
const sdk = createTestSdk();
|
|
360
|
+
const runActionResult = sdk.runAction({
|
|
361
|
+
appKey: "slack",
|
|
362
|
+
actionType: "write",
|
|
363
|
+
actionKey: "send_message",
|
|
364
|
+
inputs: { message: "Hello" },
|
|
365
|
+
maxItems: 1,
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
const items = [];
|
|
369
|
+
for await (const item of runActionResult.items()) {
|
|
370
|
+
items.push(item);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
expect(items).toHaveLength(1);
|
|
374
|
+
expect(items[0]).toEqual(mockActionResponse.results[0]);
|
|
375
|
+
});
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
describe("context and metadata", () => {
|
|
379
|
+
it("should provide context with meta information", () => {
|
|
380
|
+
const sdk = createTestSdk();
|
|
381
|
+
const context = sdk.getContext();
|
|
382
|
+
|
|
383
|
+
expect((context.meta as any).runAction).toBeDefined();
|
|
384
|
+
expect((context.meta as any).runAction.inputSchema).toBeDefined();
|
|
385
|
+
});
|
|
386
|
+
});
|
|
387
|
+
});
|