@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,204 @@
|
|
|
1
|
+
import type { Plugin, GetSdkType } from "../../types/plugin";
|
|
2
|
+
import type { ApiClient } from "../../api";
|
|
3
|
+
import type { NeedsRequest, NeedsResponse, Need } from "../../api/types";
|
|
4
|
+
import type { InputFieldItem } from "../../types/domain";
|
|
5
|
+
import {
|
|
6
|
+
ListInputFieldsSchema,
|
|
7
|
+
type ListInputFieldsOptions,
|
|
8
|
+
type ListInputFieldsPage,
|
|
9
|
+
} from "./schemas";
|
|
10
|
+
import { ZapierConfigurationError, ZapierApiError } from "../../types/errors";
|
|
11
|
+
import { createPaginatedFunction } from "../../utils/function-utils";
|
|
12
|
+
import type { GetAppPluginProvides } from "../getApp";
|
|
13
|
+
|
|
14
|
+
// Enums for input field transformation
|
|
15
|
+
enum InputFieldType {
|
|
16
|
+
STRING = "STRING",
|
|
17
|
+
NUMBER = "NUMBER",
|
|
18
|
+
INTEGER = "INTEGER",
|
|
19
|
+
BOOLEAN = "BOOLEAN",
|
|
20
|
+
OBJECT = "OBJECT",
|
|
21
|
+
ARRAY = "ARRAY",
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
enum InputFieldFormat {
|
|
25
|
+
DATETIME = "DATETIME",
|
|
26
|
+
SELECT = "SELECT",
|
|
27
|
+
MULTILINE = "MULTILINE",
|
|
28
|
+
FILE = "FILE",
|
|
29
|
+
PASSWORD = "PASSWORD",
|
|
30
|
+
CODE = "CODE",
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
enum ItemsType {
|
|
34
|
+
STRING = "STRING",
|
|
35
|
+
NUMBER = "NUMBER",
|
|
36
|
+
INTEGER = "INTEGER",
|
|
37
|
+
BOOLEAN = "BOOLEAN",
|
|
38
|
+
OBJECT = "OBJECT",
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Transformation helper functions
|
|
42
|
+
function getInputFieldTypeFromNeed(need: Need): InputFieldType {
|
|
43
|
+
if (need.list) {
|
|
44
|
+
return InputFieldType.ARRAY;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const typeMap: Record<string, InputFieldType> = {
|
|
48
|
+
string: InputFieldType.STRING,
|
|
49
|
+
decimal: InputFieldType.NUMBER,
|
|
50
|
+
integer: InputFieldType.INTEGER,
|
|
51
|
+
boolean: InputFieldType.BOOLEAN,
|
|
52
|
+
dict: InputFieldType.OBJECT,
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
return typeMap[need.type || ""] || InputFieldType.STRING;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function getInputFieldFormatFromNeed(need: Need): InputFieldFormat | undefined {
|
|
59
|
+
if (need.prefill || need.choices) {
|
|
60
|
+
return InputFieldFormat.SELECT;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const formatMap: Record<string, InputFieldFormat> = {
|
|
64
|
+
text: InputFieldFormat.MULTILINE,
|
|
65
|
+
datetime: InputFieldFormat.DATETIME,
|
|
66
|
+
file: InputFieldFormat.FILE,
|
|
67
|
+
password: InputFieldFormat.PASSWORD,
|
|
68
|
+
code: InputFieldFormat.CODE,
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
return formatMap[need.type || ""];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function getItemsTypeFromNeed(need: Need): ItemsType | undefined {
|
|
75
|
+
if (!need.list) {
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const typeMap: Record<string, ItemsType> = {
|
|
80
|
+
string: ItemsType.STRING,
|
|
81
|
+
decimal: ItemsType.NUMBER,
|
|
82
|
+
integer: ItemsType.INTEGER,
|
|
83
|
+
boolean: ItemsType.BOOLEAN,
|
|
84
|
+
dict: ItemsType.OBJECT,
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
return typeMap[need.type || ""] || ItemsType.STRING;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Transform Need to InputFieldItem
|
|
91
|
+
function transformNeedToInputFieldItem(need: Need): InputFieldItem {
|
|
92
|
+
const itemsType = getItemsTypeFromNeed(need);
|
|
93
|
+
|
|
94
|
+
return {
|
|
95
|
+
...need, // Pass through all original Need fields
|
|
96
|
+
id: need.key,
|
|
97
|
+
default_value: need.default || "",
|
|
98
|
+
depends_on: need.depends_on || [],
|
|
99
|
+
description: need.help_text || "",
|
|
100
|
+
invalidates_input_fields: need.alters_custom_fields || false,
|
|
101
|
+
is_required: need.required || false,
|
|
102
|
+
placeholder: need.placeholder || "",
|
|
103
|
+
title: need.label || "",
|
|
104
|
+
value_type: getInputFieldTypeFromNeed(need),
|
|
105
|
+
format: getInputFieldFormatFromNeed(need),
|
|
106
|
+
items: itemsType ? { type: itemsType } : undefined,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface ListInputFieldsPluginProvides {
|
|
111
|
+
listInputFields: (options?: ListInputFieldsOptions) => Promise<{
|
|
112
|
+
data: InputFieldItem[];
|
|
113
|
+
}> &
|
|
114
|
+
AsyncIterable<{ data: InputFieldItem[]; nextCursor?: string }> & {
|
|
115
|
+
items(): AsyncIterable<InputFieldItem>;
|
|
116
|
+
};
|
|
117
|
+
context: {
|
|
118
|
+
meta: {
|
|
119
|
+
listInputFields: {
|
|
120
|
+
inputSchema: typeof ListInputFieldsSchema;
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export const listInputFieldsPlugin: Plugin<
|
|
127
|
+
GetSdkType<GetAppPluginProvides>, // requires getApp in SDK
|
|
128
|
+
{ api: ApiClient }, // requires api in context
|
|
129
|
+
ListInputFieldsPluginProvides
|
|
130
|
+
> = ({ sdk, context }) => {
|
|
131
|
+
const listInputFields = createPaginatedFunction(
|
|
132
|
+
async function listInputFieldsPage(
|
|
133
|
+
options: ListInputFieldsOptions & { cursor?: string } & {
|
|
134
|
+
pageSize: number;
|
|
135
|
+
},
|
|
136
|
+
): Promise<ListInputFieldsPage> {
|
|
137
|
+
// Note: This function ignores pageSize and cursor since it's not actually paginated internally
|
|
138
|
+
const { api } = context;
|
|
139
|
+
|
|
140
|
+
// Extract parameters
|
|
141
|
+
const { appKey, actionKey, actionType, authenticationId, inputs } =
|
|
142
|
+
options;
|
|
143
|
+
|
|
144
|
+
// Use the getApp plugin
|
|
145
|
+
const appData = await sdk.getApp({ appKey });
|
|
146
|
+
const selectedApi = appData.data.current_implementation_id;
|
|
147
|
+
|
|
148
|
+
if (!selectedApi) {
|
|
149
|
+
throw new ZapierConfigurationError(
|
|
150
|
+
"No current_implementation_id found for app",
|
|
151
|
+
{ configType: "current_implementation_id" },
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Build needs request
|
|
156
|
+
const needsRequest: NeedsRequest = {
|
|
157
|
+
selected_api: selectedApi,
|
|
158
|
+
action: actionKey,
|
|
159
|
+
type_of: actionType,
|
|
160
|
+
params: inputs || {},
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
// Only include authentication_id if it's not null (skip authentication when null)
|
|
164
|
+
if (authenticationId !== null) {
|
|
165
|
+
needsRequest.authentication_id = authenticationId;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const needsData: NeedsResponse = await api.post(
|
|
169
|
+
"/api/v4/implementations/needs/",
|
|
170
|
+
needsRequest,
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
if (!needsData.success) {
|
|
174
|
+
throw new ZapierApiError(
|
|
175
|
+
`Failed to get action fields: ${
|
|
176
|
+
needsData.errors?.join(", ") || "Unknown error"
|
|
177
|
+
}`,
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// Transform Need objects to InputFieldItem objects
|
|
182
|
+
const inputFields: InputFieldItem[] = (needsData.needs || []).map(
|
|
183
|
+
transformNeedToInputFieldItem,
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
return {
|
|
187
|
+
data: inputFields,
|
|
188
|
+
nextCursor: undefined, // No pagination needed since we return all input fields
|
|
189
|
+
};
|
|
190
|
+
},
|
|
191
|
+
ListInputFieldsSchema,
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
return {
|
|
195
|
+
listInputFields,
|
|
196
|
+
context: {
|
|
197
|
+
meta: {
|
|
198
|
+
listInputFields: {
|
|
199
|
+
inputSchema: ListInputFieldsSchema,
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
};
|
|
204
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import {
|
|
3
|
+
AppKeyPropertySchema,
|
|
4
|
+
ActionTypePropertySchema,
|
|
5
|
+
ActionKeyPropertySchema,
|
|
6
|
+
AuthenticationIdPropertySchema,
|
|
7
|
+
InputsPropertySchema,
|
|
8
|
+
} from "../../types/properties";
|
|
9
|
+
import type { InputFieldItem } from "../../types/domain";
|
|
10
|
+
import type { PaginatedSdkFunction } from "../../types/functions";
|
|
11
|
+
|
|
12
|
+
// Pure Zod schema - no resolver metadata!
|
|
13
|
+
export const ListInputFieldsSchema = z
|
|
14
|
+
.object({
|
|
15
|
+
appKey: AppKeyPropertySchema,
|
|
16
|
+
actionType: ActionTypePropertySchema,
|
|
17
|
+
actionKey: ActionKeyPropertySchema,
|
|
18
|
+
authenticationId: AuthenticationIdPropertySchema.nullable().optional(),
|
|
19
|
+
inputs: InputsPropertySchema.optional().describe(
|
|
20
|
+
"Current input values that may affect available fields",
|
|
21
|
+
),
|
|
22
|
+
pageSize: z
|
|
23
|
+
.number()
|
|
24
|
+
.min(1)
|
|
25
|
+
.optional()
|
|
26
|
+
.describe("Number of input fields per page"),
|
|
27
|
+
maxItems: z
|
|
28
|
+
.number()
|
|
29
|
+
.min(1)
|
|
30
|
+
.optional()
|
|
31
|
+
.describe("Maximum total items to return across all pages"),
|
|
32
|
+
})
|
|
33
|
+
.describe("Get the input fields required for a specific action");
|
|
34
|
+
|
|
35
|
+
// Type inferred from schema
|
|
36
|
+
export type ListInputFieldsOptions = z.infer<typeof ListInputFieldsSchema>;
|
|
37
|
+
|
|
38
|
+
// Error union for this function
|
|
39
|
+
export type ListInputFieldsError =
|
|
40
|
+
| import("../../types/errors").ZapierConfigurationError
|
|
41
|
+
| import("../../types/errors").ZapierApiError
|
|
42
|
+
| import("../../types/errors").ZapierAuthenticationError
|
|
43
|
+
| import("../../types/errors").ZapierAppNotFoundError
|
|
44
|
+
| import("../../types/errors").ZapierValidationError
|
|
45
|
+
| import("../../types/errors").ZapierUnknownError;
|
|
46
|
+
|
|
47
|
+
// Page result structure
|
|
48
|
+
export interface ListInputFieldsPage {
|
|
49
|
+
data: InputFieldItem[];
|
|
50
|
+
nextCursor?: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// SDK function interface
|
|
54
|
+
export interface ListInputFieldsSdkFunction {
|
|
55
|
+
listInputFields: PaginatedSdkFunction<ListInputFieldsOptions, InputFieldItem>;
|
|
56
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Plugin } from "../../types/plugin";
|
|
2
|
+
import { FunctionRegistryEntry } from "../../types/sdk";
|
|
3
|
+
|
|
4
|
+
export interface RegisterPluginFunctionOptions {}
|
|
5
|
+
|
|
6
|
+
// Registry plugin creates and populates __registry for CLI backward compatibility
|
|
7
|
+
export interface RegistryPluginProvides {
|
|
8
|
+
__registry: FunctionRegistryEntry[];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// Registry plugin requires no context but collects SDK metadata
|
|
12
|
+
export const registryPlugin: Plugin<
|
|
13
|
+
{}, // accepts any SDK shape
|
|
14
|
+
{}, // requires no context
|
|
15
|
+
RegistryPluginProvides
|
|
16
|
+
> = ({ sdk, context }) => {
|
|
17
|
+
const metaKeys = Object.keys(context.meta || {});
|
|
18
|
+
|
|
19
|
+
const registryEntries = metaKeys.map((key) => {
|
|
20
|
+
return {
|
|
21
|
+
...context.meta[key],
|
|
22
|
+
name: key,
|
|
23
|
+
implementation: sdk[key as keyof typeof sdk],
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
__registry: registryEntries,
|
|
29
|
+
};
|
|
30
|
+
};
|
|
@@ -0,0 +1,329 @@
|
|
|
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
|
+
import type { ApiClient } from "../../api";
|
|
6
|
+
import type { RelayRequestOptions } from "./schemas";
|
|
7
|
+
|
|
8
|
+
describe("request plugin", () => {
|
|
9
|
+
let mockApiClient: ApiClient;
|
|
10
|
+
let mockFetch: any;
|
|
11
|
+
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
vi.clearAllMocks();
|
|
14
|
+
mockFetch = vi.fn().mockResolvedValue(
|
|
15
|
+
new Response('{"success": true}', {
|
|
16
|
+
status: 200,
|
|
17
|
+
headers: { "Content-Type": "application/json" },
|
|
18
|
+
}),
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
mockApiClient = {
|
|
22
|
+
fetch: mockFetch,
|
|
23
|
+
} as Partial<ApiClient> as ApiClient;
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
function createTestSdk() {
|
|
27
|
+
return createSdk({}, { api: mockApiClient, meta: {} }).addPlugin(
|
|
28
|
+
requestPlugin,
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
describe("schema validation", () => {
|
|
33
|
+
it("should throw validation error for missing url", async () => {
|
|
34
|
+
const sdk = createTestSdk();
|
|
35
|
+
await expect(sdk.request({} as RelayRequestOptions)).rejects.toThrow(
|
|
36
|
+
ZapierValidationError,
|
|
37
|
+
);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("should throw validation error for invalid url", async () => {
|
|
41
|
+
const sdk = createTestSdk();
|
|
42
|
+
await expect(sdk.request({ url: "not-a-url" })).rejects.toThrow(
|
|
43
|
+
ZapierValidationError,
|
|
44
|
+
);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("should throw validation error for invalid method", async () => {
|
|
48
|
+
const sdk = createTestSdk();
|
|
49
|
+
await expect(
|
|
50
|
+
sdk.request({
|
|
51
|
+
url: "https://api.example.com/data",
|
|
52
|
+
method: "INVALID" as any,
|
|
53
|
+
}),
|
|
54
|
+
).rejects.toThrow(ZapierValidationError);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("should throw validation error for invalid authenticationId type", async () => {
|
|
58
|
+
const sdk = createTestSdk();
|
|
59
|
+
await expect(
|
|
60
|
+
sdk.request({
|
|
61
|
+
url: "https://api.example.com/data",
|
|
62
|
+
authenticationId: "not-a-number" as any,
|
|
63
|
+
}),
|
|
64
|
+
).rejects.toThrow(ZapierValidationError);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("should throw validation error for invalid callbackUrl", async () => {
|
|
68
|
+
const sdk = createTestSdk();
|
|
69
|
+
await expect(
|
|
70
|
+
sdk.request({
|
|
71
|
+
url: "https://api.example.com/data",
|
|
72
|
+
callbackUrl: "not-a-url",
|
|
73
|
+
}),
|
|
74
|
+
).rejects.toThrow(ZapierValidationError);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("should pass validation with valid minimal options", async () => {
|
|
78
|
+
const sdk = createTestSdk();
|
|
79
|
+
await sdk.request({ url: "https://api.example.com/data" });
|
|
80
|
+
|
|
81
|
+
expect(mockFetch).toHaveBeenCalled();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("should pass validation with all valid options", async () => {
|
|
85
|
+
const sdk = createTestSdk();
|
|
86
|
+
await sdk.request({
|
|
87
|
+
url: "https://api.example.com/data",
|
|
88
|
+
method: "POST",
|
|
89
|
+
body: '{"test": true}',
|
|
90
|
+
headers: { "Content-Type": "application/json" },
|
|
91
|
+
authenticationId: 123,
|
|
92
|
+
callbackUrl: "https://webhook.example.com/callback",
|
|
93
|
+
authenticationTemplate: '{"token": "{{auth.token}}"}',
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
expect(mockFetch).toHaveBeenCalled();
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
describe("URL transformation", () => {
|
|
101
|
+
it("should transform full URLs to relay path format", async () => {
|
|
102
|
+
const sdk = createTestSdk();
|
|
103
|
+
await sdk.request({
|
|
104
|
+
url: "https://api.github.com/user",
|
|
105
|
+
method: "GET",
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
expect(mockFetch).toHaveBeenCalledWith(
|
|
109
|
+
"/relay/api.github.com/user",
|
|
110
|
+
expect.any(Object),
|
|
111
|
+
);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it("should preserve query parameters and fragments", async () => {
|
|
115
|
+
const sdk = createTestSdk();
|
|
116
|
+
await sdk.request({
|
|
117
|
+
url: "https://api.example.com/search?q=test&limit=10#section",
|
|
118
|
+
method: "GET",
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
expect(mockFetch).toHaveBeenCalledWith(
|
|
122
|
+
"/relay/api.example.com/search?q=test&limit=10#section",
|
|
123
|
+
expect.any(Object),
|
|
124
|
+
);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("should handle URLs with ports", async () => {
|
|
128
|
+
const sdk = createTestSdk();
|
|
129
|
+
await sdk.request({
|
|
130
|
+
url: "https://api.example.com:8443/data",
|
|
131
|
+
method: "GET",
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
expect(mockFetch).toHaveBeenCalledWith(
|
|
135
|
+
"/relay/api.example.com:8443/data",
|
|
136
|
+
expect.any(Object),
|
|
137
|
+
);
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
describe("headers handling", () => {
|
|
142
|
+
it("should pass through regular headers", async () => {
|
|
143
|
+
const sdk = createTestSdk();
|
|
144
|
+
const headers = {
|
|
145
|
+
"Content-Type": "application/json",
|
|
146
|
+
"X-Custom-Header": "test-value",
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
await sdk.request({
|
|
150
|
+
url: "https://api.example.com/data",
|
|
151
|
+
method: "POST",
|
|
152
|
+
headers,
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
expect(mockFetch).toHaveBeenCalledWith("/relay/api.example.com/data", {
|
|
156
|
+
method: "POST",
|
|
157
|
+
body: undefined,
|
|
158
|
+
headers: {
|
|
159
|
+
"Content-Type": "application/json",
|
|
160
|
+
"X-Custom-Header": "test-value",
|
|
161
|
+
},
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it("should add relay-specific headers when provided", async () => {
|
|
166
|
+
const sdk = createTestSdk();
|
|
167
|
+
await sdk.request({
|
|
168
|
+
url: "https://api.example.com/data",
|
|
169
|
+
method: "POST",
|
|
170
|
+
authenticationId: 123,
|
|
171
|
+
callbackUrl: "https://webhook.example.com/callback",
|
|
172
|
+
authenticationTemplate: '{"token": "{{auth.token}}"}',
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
expect(mockFetch).toHaveBeenCalledWith("/relay/api.example.com/data", {
|
|
176
|
+
method: "POST",
|
|
177
|
+
body: undefined,
|
|
178
|
+
headers: {
|
|
179
|
+
"X-Relay-Authentication-Id": "123",
|
|
180
|
+
"X-Relay-Callback-Url": "https://webhook.example.com/callback",
|
|
181
|
+
"X-Authentication-Template": '{"token": "{{auth.token}}"}',
|
|
182
|
+
},
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it("should handle Headers object", async () => {
|
|
187
|
+
const sdk = createTestSdk();
|
|
188
|
+
const headers = new Headers();
|
|
189
|
+
headers.set("Content-Type", "application/json");
|
|
190
|
+
headers.set("Authorization", "Bearer token");
|
|
191
|
+
|
|
192
|
+
await sdk.request({
|
|
193
|
+
url: "https://api.example.com/data",
|
|
194
|
+
headers,
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
expect(mockFetch).toHaveBeenCalledWith("/relay/api.example.com/data", {
|
|
198
|
+
method: "GET",
|
|
199
|
+
body: undefined,
|
|
200
|
+
headers: {
|
|
201
|
+
"content-type": "application/json", // Headers constructor lowercases names
|
|
202
|
+
authorization: "Bearer token", // Headers constructor lowercases names
|
|
203
|
+
},
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it("should handle headers as array of tuples", async () => {
|
|
208
|
+
const sdk = createTestSdk();
|
|
209
|
+
const headers: [string, string][] = [
|
|
210
|
+
["Content-Type", "application/json"],
|
|
211
|
+
["X-Api-Key", "secret"],
|
|
212
|
+
];
|
|
213
|
+
|
|
214
|
+
await sdk.request({
|
|
215
|
+
url: "https://api.example.com/data",
|
|
216
|
+
headers,
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
expect(mockFetch).toHaveBeenCalledWith("/relay/api.example.com/data", {
|
|
220
|
+
method: "GET",
|
|
221
|
+
body: undefined,
|
|
222
|
+
headers: {
|
|
223
|
+
"Content-Type": "application/json",
|
|
224
|
+
"X-Api-Key": "secret",
|
|
225
|
+
},
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
describe("HTTP methods", () => {
|
|
231
|
+
const methods = [
|
|
232
|
+
"GET",
|
|
233
|
+
"POST",
|
|
234
|
+
"PUT",
|
|
235
|
+
"DELETE",
|
|
236
|
+
"PATCH",
|
|
237
|
+
"HEAD",
|
|
238
|
+
"OPTIONS",
|
|
239
|
+
] as const;
|
|
240
|
+
|
|
241
|
+
methods.forEach((method) => {
|
|
242
|
+
it(`should support ${method} method`, async () => {
|
|
243
|
+
const sdk = createTestSdk();
|
|
244
|
+
await sdk.request({
|
|
245
|
+
url: "https://api.example.com/data",
|
|
246
|
+
method,
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
expect(mockFetch).toHaveBeenCalledWith("/relay/api.example.com/data", {
|
|
250
|
+
method,
|
|
251
|
+
body: undefined,
|
|
252
|
+
headers: {},
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
it("should default to GET method", async () => {
|
|
258
|
+
const sdk = createTestSdk();
|
|
259
|
+
await sdk.request({
|
|
260
|
+
url: "https://api.example.com/data",
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
expect(mockFetch).toHaveBeenCalledWith("/relay/api.example.com/data", {
|
|
264
|
+
method: "GET",
|
|
265
|
+
body: undefined,
|
|
266
|
+
headers: {},
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
describe("request body", () => {
|
|
272
|
+
it("should pass through request body", async () => {
|
|
273
|
+
const sdk = createTestSdk();
|
|
274
|
+
const body = '{"name": "test", "value": 42}';
|
|
275
|
+
|
|
276
|
+
await sdk.request({
|
|
277
|
+
url: "https://api.example.com/data",
|
|
278
|
+
method: "POST",
|
|
279
|
+
body,
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
expect(mockFetch).toHaveBeenCalledWith("/relay/api.example.com/data", {
|
|
283
|
+
method: "POST",
|
|
284
|
+
body,
|
|
285
|
+
headers: {},
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
describe("response handling", () => {
|
|
291
|
+
it("should return the response from api.fetch", async () => {
|
|
292
|
+
const mockResponse = new Response('{"result": "success"}', {
|
|
293
|
+
status: 200,
|
|
294
|
+
statusText: "OK",
|
|
295
|
+
headers: { "Content-Type": "application/json" },
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
mockFetch.mockResolvedValue(mockResponse);
|
|
299
|
+
|
|
300
|
+
const sdk = createTestSdk();
|
|
301
|
+
const response = await sdk.request({
|
|
302
|
+
url: "https://api.example.com/data",
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
expect(response).toBe(mockResponse);
|
|
306
|
+
expect(response.status).toBe(200);
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
it("should handle API errors", async () => {
|
|
310
|
+
const error = new Error("Network error");
|
|
311
|
+
mockFetch.mockRejectedValue(error);
|
|
312
|
+
|
|
313
|
+
const sdk = createTestSdk();
|
|
314
|
+
await expect(
|
|
315
|
+
sdk.request({ url: "https://api.example.com/data" }),
|
|
316
|
+
).rejects.toThrow("Network error");
|
|
317
|
+
});
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
describe("context and metadata", () => {
|
|
321
|
+
it("should provide context with meta information", () => {
|
|
322
|
+
const sdk = createTestSdk();
|
|
323
|
+
const context = sdk.getContext();
|
|
324
|
+
|
|
325
|
+
expect((context.meta as any).request).toBeDefined();
|
|
326
|
+
expect((context.meta as any).request.inputSchema).toBeDefined();
|
|
327
|
+
});
|
|
328
|
+
});
|
|
329
|
+
});
|