@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,197 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
ZapierValidationError,
|
|
4
|
+
ZapierResourceNotFoundError,
|
|
5
|
+
} from "../../types/errors";
|
|
6
|
+
import { findUniqueAuthenticationPlugin } from "./index";
|
|
7
|
+
import { createSdk } from "../../sdk";
|
|
8
|
+
import type { AuthenticationItem } from "../../types/domain";
|
|
9
|
+
import { ListAuthenticationsSchema } from "../listAuthentications/schemas";
|
|
10
|
+
|
|
11
|
+
const mockAuthentication: AuthenticationItem = {
|
|
12
|
+
id: 123,
|
|
13
|
+
title: "My Slack",
|
|
14
|
+
date: "2021-01-01",
|
|
15
|
+
account_id: 123,
|
|
16
|
+
implementation_id: "api_123",
|
|
17
|
+
is_expired: "false",
|
|
18
|
+
expired_at: null,
|
|
19
|
+
is_invite_only: false,
|
|
20
|
+
is_private: false,
|
|
21
|
+
shared_with_all: false,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const mockAuthentications: AuthenticationItem[] = [
|
|
25
|
+
mockAuthentication,
|
|
26
|
+
{
|
|
27
|
+
id: 456,
|
|
28
|
+
title: "Slack Workspace 2",
|
|
29
|
+
is_expired: "false",
|
|
30
|
+
expired_at: null,
|
|
31
|
+
date: "2021-01-01",
|
|
32
|
+
account_id: 123,
|
|
33
|
+
implementation_id: "api_123",
|
|
34
|
+
is_invite_only: false,
|
|
35
|
+
is_private: false,
|
|
36
|
+
shared_with_all: false,
|
|
37
|
+
},
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
describe("findUniqueAuthentication plugin", () => {
|
|
41
|
+
let mockListAuthentications: any;
|
|
42
|
+
|
|
43
|
+
beforeEach(() => {
|
|
44
|
+
vi.clearAllMocks();
|
|
45
|
+
mockListAuthentications = vi.fn().mockResolvedValue({
|
|
46
|
+
data: [mockAuthentication],
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
function createTestSdk() {
|
|
51
|
+
// Create a proper plugin chain: first add a mock listAuthentications plugin, then add findUniqueAuthentication
|
|
52
|
+
const mockListAuthenticationsPlugin = () => ({
|
|
53
|
+
listAuthentications: mockListAuthentications,
|
|
54
|
+
context: {
|
|
55
|
+
meta: {
|
|
56
|
+
listAuthentications: {
|
|
57
|
+
inputSchema: ListAuthenticationsSchema,
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// Build SDK with proper plugin composition
|
|
64
|
+
return createSdk()
|
|
65
|
+
.addPlugin(mockListAuthenticationsPlugin)
|
|
66
|
+
.addPlugin(findUniqueAuthenticationPlugin);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
describe("schema validation", () => {
|
|
70
|
+
it("should pass validation with empty options", async () => {
|
|
71
|
+
const sdk = createTestSdk();
|
|
72
|
+
const result = await sdk.findUniqueAuthentication({});
|
|
73
|
+
expect(result.data).toBeDefined();
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("should throw validation error for invalid appKey type", async () => {
|
|
77
|
+
const sdk = createTestSdk();
|
|
78
|
+
await expect(
|
|
79
|
+
sdk.findUniqueAuthentication({
|
|
80
|
+
appKey: 123 as any,
|
|
81
|
+
}),
|
|
82
|
+
).rejects.toThrow(ZapierValidationError);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("should throw validation error for invalid parameter types", async () => {
|
|
86
|
+
const sdk = createTestSdk();
|
|
87
|
+
await expect(
|
|
88
|
+
sdk.findUniqueAuthentication({
|
|
89
|
+
search: 123 as any,
|
|
90
|
+
title: 456 as any,
|
|
91
|
+
account_id: 789 as any,
|
|
92
|
+
owner: false as any,
|
|
93
|
+
}),
|
|
94
|
+
).rejects.toThrow(ZapierValidationError);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("should pass validation with all valid fields", async () => {
|
|
98
|
+
const sdk = createTestSdk();
|
|
99
|
+
const result = await sdk.findUniqueAuthentication({
|
|
100
|
+
appKey: "slack",
|
|
101
|
+
search: "Workspace",
|
|
102
|
+
title: "My Slack",
|
|
103
|
+
account_id: "acc_123",
|
|
104
|
+
owner: "me",
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
expect(result.data).toBeDefined();
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
describe("business logic", () => {
|
|
112
|
+
it("should return the first authentication when exactly one is found", async () => {
|
|
113
|
+
mockListAuthentications.mockResolvedValue({
|
|
114
|
+
data: [mockAuthentication],
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
const sdk = createTestSdk();
|
|
118
|
+
const result = await sdk.findUniqueAuthentication({
|
|
119
|
+
appKey: "slack",
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
expect(result.data).toEqual(mockAuthentication);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("should throw ZapierResourceNotFoundError when no authentications found", async () => {
|
|
126
|
+
mockListAuthentications.mockResolvedValue({
|
|
127
|
+
data: [],
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
const sdk = createTestSdk();
|
|
131
|
+
await expect(
|
|
132
|
+
sdk.findUniqueAuthentication({
|
|
133
|
+
appKey: "nonexistent",
|
|
134
|
+
}),
|
|
135
|
+
).rejects.toThrow(ZapierResourceNotFoundError);
|
|
136
|
+
|
|
137
|
+
await expect(
|
|
138
|
+
sdk.findUniqueAuthentication({
|
|
139
|
+
appKey: "nonexistent",
|
|
140
|
+
}),
|
|
141
|
+
).rejects.toThrow(
|
|
142
|
+
"No authentication found matching the specified criteria",
|
|
143
|
+
);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it("should throw ZapierValidationError when multiple authentications found", async () => {
|
|
147
|
+
mockListAuthentications.mockResolvedValue({
|
|
148
|
+
data: mockAuthentications, // Two authentications
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
const sdk = createTestSdk();
|
|
152
|
+
await expect(
|
|
153
|
+
sdk.findUniqueAuthentication({
|
|
154
|
+
search: "Workspace",
|
|
155
|
+
}),
|
|
156
|
+
).rejects.toThrow(ZapierValidationError);
|
|
157
|
+
|
|
158
|
+
await expect(
|
|
159
|
+
sdk.findUniqueAuthentication({
|
|
160
|
+
search: "Workspace",
|
|
161
|
+
}),
|
|
162
|
+
).rejects.toThrow(
|
|
163
|
+
"Multiple authentications found matching the specified criteria. Expected exactly one.",
|
|
164
|
+
);
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
describe("options forwarding", () => {
|
|
169
|
+
it("should forward all options to listAuthentications with maxItems=2", async () => {
|
|
170
|
+
const sdk = createTestSdk();
|
|
171
|
+
const options = {
|
|
172
|
+
appKey: "slack",
|
|
173
|
+
search: "workspace",
|
|
174
|
+
title: "My Slack Workspace",
|
|
175
|
+
account_id: "acc_123",
|
|
176
|
+
owner: "me",
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
await sdk.findUniqueAuthentication(options);
|
|
180
|
+
|
|
181
|
+
expect(mockListAuthentications).toHaveBeenCalledWith({
|
|
182
|
+
...options,
|
|
183
|
+
maxItems: 2,
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
describe("context and metadata", () => {
|
|
189
|
+
it("should provide context with meta information", () => {
|
|
190
|
+
const sdk = createTestSdk();
|
|
191
|
+
const context = sdk.getContext();
|
|
192
|
+
|
|
193
|
+
expect(context.meta.findUniqueAuthentication).toBeDefined();
|
|
194
|
+
expect(context.meta.findUniqueAuthentication.inputSchema).toBeDefined();
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
});
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { Plugin, GetSdkType } from "../../types/plugin";
|
|
2
|
+
import type { AuthenticationItem } from "../../types/domain";
|
|
3
|
+
import {
|
|
4
|
+
FindUniqueAuthenticationSchema,
|
|
5
|
+
type FindUniqueAuthenticationOptions,
|
|
6
|
+
} from "./schemas";
|
|
7
|
+
import {
|
|
8
|
+
ZapierResourceNotFoundError,
|
|
9
|
+
ZapierValidationError,
|
|
10
|
+
} from "../../types/errors";
|
|
11
|
+
import { createFunction } from "../../utils/function-utils";
|
|
12
|
+
import type { ListAuthenticationsPluginProvides } from "../listAuthentications";
|
|
13
|
+
|
|
14
|
+
export interface FindUniqueAuthenticationPluginProvides {
|
|
15
|
+
findUniqueAuthentication: (
|
|
16
|
+
options?: FindUniqueAuthenticationOptions,
|
|
17
|
+
) => Promise<{ data: AuthenticationItem }>;
|
|
18
|
+
context: {
|
|
19
|
+
meta: {
|
|
20
|
+
findUniqueAuthentication: {
|
|
21
|
+
inputSchema: typeof FindUniqueAuthenticationSchema;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const findUniqueAuthenticationPlugin: Plugin<
|
|
28
|
+
GetSdkType<ListAuthenticationsPluginProvides>, // requires listAuthentications in SDK
|
|
29
|
+
{}, // no context requirements
|
|
30
|
+
FindUniqueAuthenticationPluginProvides
|
|
31
|
+
> = ({ sdk }) => {
|
|
32
|
+
const findUniqueAuthentication = createFunction(
|
|
33
|
+
async function findUniqueAuthentication(
|
|
34
|
+
options: FindUniqueAuthenticationOptions = {},
|
|
35
|
+
) {
|
|
36
|
+
// Use listAuthentications with maxItems 2 to check for uniqueness
|
|
37
|
+
const authsResponse = await sdk.listAuthentications({
|
|
38
|
+
...options,
|
|
39
|
+
maxItems: 2, // Get up to 2 to check for uniqueness
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
if (authsResponse.data.length === 0) {
|
|
43
|
+
throw new ZapierResourceNotFoundError(
|
|
44
|
+
"No authentication found matching the specified criteria",
|
|
45
|
+
{ resourceType: "Authentication" },
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (authsResponse.data.length > 1) {
|
|
50
|
+
throw new ZapierValidationError(
|
|
51
|
+
"Multiple authentications found matching the specified criteria. Expected exactly one.",
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
data: authsResponse.data[0],
|
|
57
|
+
};
|
|
58
|
+
},
|
|
59
|
+
FindUniqueAuthenticationSchema,
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
findUniqueAuthentication,
|
|
64
|
+
context: {
|
|
65
|
+
meta: {
|
|
66
|
+
findUniqueAuthentication: {
|
|
67
|
+
inputSchema: FindUniqueAuthenticationSchema,
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { AppKeyPropertySchema } from "../../types/properties";
|
|
3
|
+
import type { AuthenticationItem } from "../../types/domain";
|
|
4
|
+
|
|
5
|
+
// Pure Zod schema - no resolver metadata!
|
|
6
|
+
export const FindUniqueAuthenticationSchema = z
|
|
7
|
+
.object({
|
|
8
|
+
appKey: AppKeyPropertySchema.optional().describe(
|
|
9
|
+
"App key of authentication to find (e.g., 'SlackCLIAPI')",
|
|
10
|
+
),
|
|
11
|
+
search: z
|
|
12
|
+
.string()
|
|
13
|
+
.optional()
|
|
14
|
+
.describe("Search term to filter authentications by title"),
|
|
15
|
+
title: z
|
|
16
|
+
.string()
|
|
17
|
+
.optional()
|
|
18
|
+
.describe("Filter authentications by exact title match"),
|
|
19
|
+
account_id: z.string().optional().describe("Filter by account ID"),
|
|
20
|
+
owner: z.string().optional().describe("Filter by owner"),
|
|
21
|
+
})
|
|
22
|
+
.describe("Find a unique authentication matching the criteria");
|
|
23
|
+
|
|
24
|
+
// Type inferred from schema
|
|
25
|
+
export type FindUniqueAuthenticationOptions = z.infer<
|
|
26
|
+
typeof FindUniqueAuthenticationSchema
|
|
27
|
+
>;
|
|
28
|
+
|
|
29
|
+
// Error union for this function
|
|
30
|
+
export type FindUniqueAuthenticationError =
|
|
31
|
+
| import("../../types/errors").ZapierAuthenticationError
|
|
32
|
+
| import("../../types/errors").ZapierApiError
|
|
33
|
+
| import("../../types/errors").ZapierResourceNotFoundError
|
|
34
|
+
| import("../../types/errors").ZapierValidationError
|
|
35
|
+
| import("../../types/errors").ZapierUnknownError;
|
|
36
|
+
|
|
37
|
+
// SDK function interface
|
|
38
|
+
export interface FindUniqueAuthenticationSdkFunction {
|
|
39
|
+
findUniqueAuthentication: (
|
|
40
|
+
options?: FindUniqueAuthenticationOptions,
|
|
41
|
+
) => Promise<{ data: AuthenticationItem }>;
|
|
42
|
+
}
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
ZapierValidationError,
|
|
4
|
+
ZapierResourceNotFoundError,
|
|
5
|
+
} from "../../types/errors";
|
|
6
|
+
import { getActionPlugin } from "./index";
|
|
7
|
+
import { createSdk } from "../../sdk";
|
|
8
|
+
import type { GetActionOptions } from "./schemas";
|
|
9
|
+
import type { ActionItem } from "../../types/domain";
|
|
10
|
+
import type { ApiClient } from "../../api";
|
|
11
|
+
import { ListActionsSchema } from "../listActions/schemas";
|
|
12
|
+
|
|
13
|
+
const mockActions: ActionItem[] = [
|
|
14
|
+
{
|
|
15
|
+
type: "action",
|
|
16
|
+
key: "user_by_email",
|
|
17
|
+
title: "Search User by Email",
|
|
18
|
+
description: "Find a user by email address",
|
|
19
|
+
app_key: "slack",
|
|
20
|
+
action_type: "search",
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
type: "action",
|
|
24
|
+
key: "search_messages",
|
|
25
|
+
title: "Search Messages",
|
|
26
|
+
description: "Search for messages in channels",
|
|
27
|
+
app_key: "slack",
|
|
28
|
+
action_type: "search",
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
type: "action",
|
|
32
|
+
key: "user_by_email",
|
|
33
|
+
title: "Search User by Email",
|
|
34
|
+
description: "Find a user by email address",
|
|
35
|
+
app_key: "slack",
|
|
36
|
+
action_type: "write", // Different action type for testing mismatch
|
|
37
|
+
},
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
describe("getAction plugin", () => {
|
|
41
|
+
let mockListActions: any;
|
|
42
|
+
let mockApiClient: ApiClient;
|
|
43
|
+
|
|
44
|
+
beforeEach(() => {
|
|
45
|
+
vi.clearAllMocks();
|
|
46
|
+
mockListActions = vi.fn().mockResolvedValue({
|
|
47
|
+
data: mockActions,
|
|
48
|
+
});
|
|
49
|
+
mockApiClient = {} as ApiClient;
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
function createTestSdk() {
|
|
53
|
+
// Create a proper plugin chain with context dependencies
|
|
54
|
+
const mockListActionsPlugin = () => ({
|
|
55
|
+
listActions: mockListActions,
|
|
56
|
+
context: {
|
|
57
|
+
meta: {
|
|
58
|
+
listActions: {
|
|
59
|
+
inputSchema: ListActionsSchema,
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// Build SDK with proper plugin composition, providing API in initial context
|
|
66
|
+
return createSdk({}, { api: mockApiClient, meta: {} })
|
|
67
|
+
.addPlugin(mockListActionsPlugin)
|
|
68
|
+
.addPlugin(getActionPlugin);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
describe("schema validation", () => {
|
|
72
|
+
it("should throw validation error for missing appKey", async () => {
|
|
73
|
+
const sdk = createTestSdk();
|
|
74
|
+
await expect(
|
|
75
|
+
sdk.getAction({
|
|
76
|
+
actionType: "search",
|
|
77
|
+
actionKey: "user_by_email",
|
|
78
|
+
} as Partial<GetActionOptions> as GetActionOptions),
|
|
79
|
+
).rejects.toThrow(ZapierValidationError);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("should throw validation error for missing actionType", async () => {
|
|
83
|
+
const sdk = createTestSdk();
|
|
84
|
+
await expect(
|
|
85
|
+
sdk.getAction({
|
|
86
|
+
appKey: "slack",
|
|
87
|
+
actionKey: "user_by_email",
|
|
88
|
+
} as Partial<GetActionOptions> as GetActionOptions),
|
|
89
|
+
).rejects.toThrow(ZapierValidationError);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("should throw validation error for missing actionKey", async () => {
|
|
93
|
+
const sdk = createTestSdk();
|
|
94
|
+
await expect(
|
|
95
|
+
sdk.getAction({
|
|
96
|
+
appKey: "slack",
|
|
97
|
+
actionType: "search",
|
|
98
|
+
} as Partial<GetActionOptions> as GetActionOptions),
|
|
99
|
+
).rejects.toThrow(ZapierValidationError);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it("should throw validation error for invalid appKey type", async () => {
|
|
103
|
+
const sdk = createTestSdk();
|
|
104
|
+
await expect(
|
|
105
|
+
sdk.getAction({
|
|
106
|
+
appKey: 123 as any,
|
|
107
|
+
actionType: "search",
|
|
108
|
+
actionKey: "user_by_email",
|
|
109
|
+
} as any),
|
|
110
|
+
).rejects.toThrow(ZapierValidationError);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it("should throw validation error for invalid actionType", async () => {
|
|
114
|
+
const sdk = createTestSdk();
|
|
115
|
+
await expect(
|
|
116
|
+
sdk.getAction({
|
|
117
|
+
appKey: "slack",
|
|
118
|
+
actionType: "invalid-type" as any,
|
|
119
|
+
actionKey: "user_by_email",
|
|
120
|
+
} as any),
|
|
121
|
+
).rejects.toThrow(ZapierValidationError);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("should throw validation error for invalid actionKey type", async () => {
|
|
125
|
+
const sdk = createTestSdk();
|
|
126
|
+
await expect(
|
|
127
|
+
sdk.getAction({
|
|
128
|
+
appKey: "slack",
|
|
129
|
+
actionType: "search",
|
|
130
|
+
actionKey: 123,
|
|
131
|
+
} as any),
|
|
132
|
+
).rejects.toThrow(ZapierValidationError);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it("should throw validation error for empty appKey", async () => {
|
|
136
|
+
const sdk = createTestSdk();
|
|
137
|
+
await expect(
|
|
138
|
+
sdk.getAction({
|
|
139
|
+
appKey: "",
|
|
140
|
+
actionType: "search",
|
|
141
|
+
actionKey: "user_by_email",
|
|
142
|
+
}),
|
|
143
|
+
).rejects.toThrow(ZapierValidationError);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it("should throw validation error for empty actionKey", async () => {
|
|
147
|
+
const sdk = createTestSdk();
|
|
148
|
+
await expect(
|
|
149
|
+
sdk.getAction({
|
|
150
|
+
appKey: "slack",
|
|
151
|
+
actionType: "search",
|
|
152
|
+
actionKey: "",
|
|
153
|
+
}),
|
|
154
|
+
).rejects.toThrow(ZapierValidationError);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it("should pass validation with all required fields", async () => {
|
|
158
|
+
const sdk = createTestSdk();
|
|
159
|
+
const result = await sdk.getAction({
|
|
160
|
+
appKey: "slack",
|
|
161
|
+
actionType: "search",
|
|
162
|
+
actionKey: "user_by_email",
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
expect(result.data).toEqual(mockActions[0]);
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
describe("action lookup", () => {
|
|
170
|
+
it("should call listActions with correct parameters", async () => {
|
|
171
|
+
const sdk = createTestSdk();
|
|
172
|
+
await sdk.getAction({
|
|
173
|
+
appKey: "slack",
|
|
174
|
+
actionType: "search",
|
|
175
|
+
actionKey: "user_by_email",
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
expect(mockListActions).toHaveBeenCalledWith({
|
|
179
|
+
appKey: "slack",
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it("should return the correct action when found", async () => {
|
|
184
|
+
const sdk = createTestSdk();
|
|
185
|
+
const result = await sdk.getAction({
|
|
186
|
+
appKey: "slack",
|
|
187
|
+
actionType: "search",
|
|
188
|
+
actionKey: "user_by_email",
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
expect(result.data).toEqual(mockActions[0]);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it("should throw error when action key not found", async () => {
|
|
195
|
+
const sdk = createTestSdk();
|
|
196
|
+
await expect(
|
|
197
|
+
sdk.getAction({
|
|
198
|
+
appKey: "slack",
|
|
199
|
+
actionType: "search",
|
|
200
|
+
actionKey: "nonexistent_action",
|
|
201
|
+
}),
|
|
202
|
+
).rejects.toThrow(ZapierResourceNotFoundError);
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it("should throw error when action type doesn't match", async () => {
|
|
206
|
+
const sdk = createTestSdk();
|
|
207
|
+
await expect(
|
|
208
|
+
sdk.getAction({
|
|
209
|
+
appKey: "slack",
|
|
210
|
+
actionType: "write",
|
|
211
|
+
actionKey: "search_messages", // This action is type "search" in mock
|
|
212
|
+
}),
|
|
213
|
+
).rejects.toThrow(ZapierResourceNotFoundError);
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it("should handle listActions errors", async () => {
|
|
217
|
+
mockListActions.mockRejectedValue(new Error("API Error"));
|
|
218
|
+
|
|
219
|
+
const sdk = createTestSdk();
|
|
220
|
+
await expect(
|
|
221
|
+
sdk.getAction({
|
|
222
|
+
appKey: "slack",
|
|
223
|
+
actionType: "search",
|
|
224
|
+
actionKey: "user_by_email",
|
|
225
|
+
}),
|
|
226
|
+
).rejects.toThrow("API Error");
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
describe("plugin integration", () => {
|
|
231
|
+
it("should provide metadata in context", () => {
|
|
232
|
+
const sdk = createTestSdk();
|
|
233
|
+
const context = sdk.getContext();
|
|
234
|
+
|
|
235
|
+
expect(context.meta.getAction).toBeDefined();
|
|
236
|
+
expect(context.meta.getAction.inputSchema).toBeDefined();
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { Plugin, GetSdkType } from "../../types/plugin";
|
|
2
|
+
import type { ApiClient } from "../../api";
|
|
3
|
+
import type { ActionItem } from "../../types/domain";
|
|
4
|
+
import { GetActionSchema, type GetActionOptions } from "./schemas";
|
|
5
|
+
import { ZapierResourceNotFoundError } from "../../types/errors";
|
|
6
|
+
import { createFunction } from "../../utils/function-utils";
|
|
7
|
+
import type { ListActionsPluginProvides } from "../listActions";
|
|
8
|
+
|
|
9
|
+
export interface GetActionPluginProvides {
|
|
10
|
+
getAction: (options: GetActionOptions) => Promise<{ data: ActionItem }>;
|
|
11
|
+
context: {
|
|
12
|
+
meta: {
|
|
13
|
+
getAction: {
|
|
14
|
+
inputSchema: typeof GetActionSchema;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const getActionPlugin: Plugin<
|
|
21
|
+
GetSdkType<ListActionsPluginProvides>, // requires listActions in SDK
|
|
22
|
+
{ api: ApiClient }, // requires api in context
|
|
23
|
+
GetActionPluginProvides
|
|
24
|
+
> = ({ sdk }) => {
|
|
25
|
+
const getAction = createFunction(async function getAction(
|
|
26
|
+
options: GetActionOptions,
|
|
27
|
+
) {
|
|
28
|
+
const { actionKey, actionType, appKey } = options;
|
|
29
|
+
|
|
30
|
+
// Use the listActions function from the SDK to search for the specific action
|
|
31
|
+
const actionsResult = await sdk.listActions({ appKey });
|
|
32
|
+
|
|
33
|
+
// Search through all actions to find the matching one
|
|
34
|
+
for (const action of actionsResult.data) {
|
|
35
|
+
if (action.key === actionKey && action.action_type === actionType) {
|
|
36
|
+
return { data: action };
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// If we get here, action was not found
|
|
41
|
+
throw new ZapierResourceNotFoundError(
|
|
42
|
+
`Action not found: ${actionKey} with type ${actionType}`,
|
|
43
|
+
{ resourceType: "Action", resourceId: `${actionKey} (${actionType})` },
|
|
44
|
+
);
|
|
45
|
+
}, GetActionSchema);
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
getAction,
|
|
49
|
+
context: {
|
|
50
|
+
meta: {
|
|
51
|
+
getAction: {
|
|
52
|
+
inputSchema: GetActionSchema,
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import {
|
|
3
|
+
AppKeyPropertySchema,
|
|
4
|
+
ActionTypePropertySchema,
|
|
5
|
+
ActionKeyPropertySchema,
|
|
6
|
+
} from "../../types/properties";
|
|
7
|
+
import type { ActionItem } from "../../types/domain";
|
|
8
|
+
|
|
9
|
+
// Pure Zod schema - no resolver metadata!
|
|
10
|
+
export const GetActionSchema = z
|
|
11
|
+
.object({
|
|
12
|
+
appKey: AppKeyPropertySchema,
|
|
13
|
+
actionType: ActionTypePropertySchema,
|
|
14
|
+
actionKey: ActionKeyPropertySchema,
|
|
15
|
+
})
|
|
16
|
+
.describe("Get detailed information about a specific action");
|
|
17
|
+
|
|
18
|
+
// Type inferred from schema
|
|
19
|
+
export type GetActionOptions = z.infer<typeof GetActionSchema>;
|
|
20
|
+
|
|
21
|
+
// Error union for this function (inherits from listActionsSafe + resource not found)
|
|
22
|
+
export type GetActionError =
|
|
23
|
+
| import("../../types/errors").ZapierAuthenticationError
|
|
24
|
+
| import("../../types/errors").ZapierApiError
|
|
25
|
+
| import("../../types/errors").ZapierAppNotFoundError
|
|
26
|
+
| import("../../types/errors").ZapierValidationError
|
|
27
|
+
| import("../../types/errors").ZapierResourceNotFoundError
|
|
28
|
+
| import("../../types/errors").ZapierUnknownError;
|
|
29
|
+
|
|
30
|
+
// SDK function interface
|
|
31
|
+
export interface GetActionSdkFunction {
|
|
32
|
+
getAction: (options: GetActionOptions) => Promise<{ data: ActionItem }>;
|
|
33
|
+
}
|