@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,127 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
ZapierValidationError,
|
|
4
|
+
ZapierAppNotFoundError,
|
|
5
|
+
} from "../../types/errors";
|
|
6
|
+
import { getAppPlugin } from "./index";
|
|
7
|
+
import { createSdk } from "../../sdk";
|
|
8
|
+
import { apiPlugin } from "../api/index";
|
|
9
|
+
import { listAppsPlugin } from "../listApps";
|
|
10
|
+
|
|
11
|
+
function createTestSdk() {
|
|
12
|
+
return createSdk()
|
|
13
|
+
.addPlugin(apiPlugin, { fetch: global.fetch })
|
|
14
|
+
.addPlugin(listAppsPlugin)
|
|
15
|
+
.addPlugin(getAppPlugin);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
describe("getApp plugin", () => {
|
|
19
|
+
beforeEach(() => {
|
|
20
|
+
vi.clearAllMocks();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe("schema validation", () => {
|
|
24
|
+
it("should throw validation error for missing appKey", async () => {
|
|
25
|
+
const sdk = createTestSdk();
|
|
26
|
+
await expect(sdk.getApp({} as any)).rejects.toThrow(
|
|
27
|
+
ZapierValidationError,
|
|
28
|
+
);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("should throw validation error for invalid appKey type", async () => {
|
|
32
|
+
const sdk = createTestSdk();
|
|
33
|
+
await expect(
|
|
34
|
+
sdk.getApp({
|
|
35
|
+
appKey: 123 as any,
|
|
36
|
+
} as any),
|
|
37
|
+
).rejects.toThrow(ZapierValidationError);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("should throw validation error for empty string appKey", async () => {
|
|
41
|
+
const sdk = createTestSdk();
|
|
42
|
+
await expect(
|
|
43
|
+
sdk.getApp({
|
|
44
|
+
appKey: "",
|
|
45
|
+
}),
|
|
46
|
+
).rejects.toThrow(ZapierValidationError);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("should pass validation with valid appKey", async () => {
|
|
50
|
+
const sdk = createTestSdk();
|
|
51
|
+
const context = sdk.getContext();
|
|
52
|
+
|
|
53
|
+
// Mock the API client in context to respond to listApps implementation
|
|
54
|
+
(context.api as any).get = vi.fn().mockResolvedValue({
|
|
55
|
+
results: [
|
|
56
|
+
{
|
|
57
|
+
id: "SlackCLIAPI@1.0.0",
|
|
58
|
+
name: "Slack",
|
|
59
|
+
description: "Team communication",
|
|
60
|
+
primary_color: "#4A154B",
|
|
61
|
+
categories: ["communication"],
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
next: null,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const result = await sdk.getApp({
|
|
68
|
+
appKey: "slack",
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
expect(result.data.title).toBe("Slack");
|
|
72
|
+
expect(result.data.key).toBe("SlackCLIAPI");
|
|
73
|
+
expect(result.data.current_implementation_id).toBe("SlackCLIAPI@1.0.0");
|
|
74
|
+
expect(result.data.version).toBe("1.0.0");
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
describe("error handling", () => {
|
|
79
|
+
it("should throw ZapierAppNotFoundError when app does not exist", async () => {
|
|
80
|
+
const sdk = createTestSdk();
|
|
81
|
+
const context = sdk.getContext();
|
|
82
|
+
|
|
83
|
+
// Mock API to return empty results (app not found)
|
|
84
|
+
(context.api as any).get = vi.fn().mockResolvedValue({
|
|
85
|
+
results: [],
|
|
86
|
+
next: null,
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
await expect(
|
|
90
|
+
sdk.getApp({
|
|
91
|
+
appKey: "nonexistent-app",
|
|
92
|
+
}),
|
|
93
|
+
).rejects.toThrow(ZapierAppNotFoundError);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
describe("data mapping", () => {
|
|
98
|
+
it("should return essential app properties", async () => {
|
|
99
|
+
const sdk = createTestSdk();
|
|
100
|
+
const context = sdk.getContext();
|
|
101
|
+
|
|
102
|
+
// Mock the API client in context to respond to listApps implementation
|
|
103
|
+
(context.api as any).get = vi.fn().mockResolvedValue({
|
|
104
|
+
results: [
|
|
105
|
+
{
|
|
106
|
+
id: "TestCLIAPI@1.0.0",
|
|
107
|
+
name: "Test App",
|
|
108
|
+
description: "Test description",
|
|
109
|
+
primary_color: "#FF0000",
|
|
110
|
+
categories: ["testing"],
|
|
111
|
+
},
|
|
112
|
+
],
|
|
113
|
+
next: null,
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
const result = await sdk.getApp({
|
|
117
|
+
appKey: "test",
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
expect(result.data.title).toBeDefined();
|
|
121
|
+
expect(result.data.key).toBeDefined();
|
|
122
|
+
expect(result.data.current_implementation_id).toBeDefined();
|
|
123
|
+
expect(result.data.title).toBe("Test App");
|
|
124
|
+
expect(result.data.key).toBe("TestCLIAPI");
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { Plugin } from "../../types/plugin";
|
|
2
|
+
import { createFunction } from "../../utils/function-utils";
|
|
3
|
+
import { GetAppSchema } from "./schemas";
|
|
4
|
+
import type { GetAppOptions } from "./schemas";
|
|
5
|
+
import type { AppItem } from "../../types/domain";
|
|
6
|
+
import { ZapierAppNotFoundError } from "../../types/errors";
|
|
7
|
+
import type { ListAppsPluginProvides } from "../listApps";
|
|
8
|
+
import type { GetSdkType } from "../../types/plugin";
|
|
9
|
+
|
|
10
|
+
// GetApp plugin provides interface - getApp goes directly to SDK root
|
|
11
|
+
export interface GetAppPluginProvides {
|
|
12
|
+
getApp: (options: GetAppOptions) => Promise<{ data: AppItem }>;
|
|
13
|
+
context: {
|
|
14
|
+
meta: {
|
|
15
|
+
getApp: {
|
|
16
|
+
inputSchema: typeof GetAppSchema;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// GetApp plugin depends on listApps SDK function
|
|
23
|
+
export const getAppPlugin: Plugin<
|
|
24
|
+
GetSdkType<ListAppsPluginProvides>, // depends on listApps
|
|
25
|
+
{}, // no additional context dependencies
|
|
26
|
+
GetAppPluginProvides
|
|
27
|
+
> = ({ sdk }) => {
|
|
28
|
+
const getApp = createFunction(async function getApp(options: GetAppOptions) {
|
|
29
|
+
const { appKey } = options;
|
|
30
|
+
|
|
31
|
+
// Use listApps to get the app by key
|
|
32
|
+
const appsIterator = sdk
|
|
33
|
+
.listApps({
|
|
34
|
+
...options,
|
|
35
|
+
appKeys: [appKey],
|
|
36
|
+
})
|
|
37
|
+
.items();
|
|
38
|
+
|
|
39
|
+
// Get the first (and should be only) result
|
|
40
|
+
const apps = [];
|
|
41
|
+
for await (const app of appsIterator) {
|
|
42
|
+
apps.push(app);
|
|
43
|
+
break; // Only need the first result
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (apps.length === 0) {
|
|
47
|
+
throw new ZapierAppNotFoundError(appKey);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
data: apps[0],
|
|
52
|
+
};
|
|
53
|
+
}, GetAppSchema);
|
|
54
|
+
|
|
55
|
+
// Return flat structure - getApp goes directly to SDK
|
|
56
|
+
return {
|
|
57
|
+
getApp,
|
|
58
|
+
context: {
|
|
59
|
+
meta: {
|
|
60
|
+
getApp: {
|
|
61
|
+
inputSchema: GetAppSchema,
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { AppKeyPropertySchema } from "../../types/properties";
|
|
3
|
+
import { withOutputSchema } from "../../utils/schema-utils";
|
|
4
|
+
import { AppItemSchema } from "../../schemas/App";
|
|
5
|
+
import type { AppItem } from "../../types/domain";
|
|
6
|
+
import {
|
|
7
|
+
ZapierApiError,
|
|
8
|
+
ZapierAppNotFoundError,
|
|
9
|
+
ZapierValidationError,
|
|
10
|
+
} from "../../types/errors";
|
|
11
|
+
|
|
12
|
+
// Error types (now imported from types/errors)
|
|
13
|
+
|
|
14
|
+
// Union of all possible errors for getApp
|
|
15
|
+
export type GetAppError =
|
|
16
|
+
| ZapierAppNotFoundError
|
|
17
|
+
| ZapierApiError
|
|
18
|
+
| ZapierValidationError;
|
|
19
|
+
|
|
20
|
+
// Pure Zod schema - no resolver metadata!
|
|
21
|
+
export const GetAppSchema = withOutputSchema(
|
|
22
|
+
z
|
|
23
|
+
.object({
|
|
24
|
+
appKey: AppKeyPropertySchema.describe(
|
|
25
|
+
"App key of app to fetch (e.g., 'SlackCLIAPI')",
|
|
26
|
+
),
|
|
27
|
+
})
|
|
28
|
+
.describe("Get detailed information about a specific app"),
|
|
29
|
+
AppItemSchema,
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
// Type inferred from schema
|
|
33
|
+
export type GetAppOptions = z.infer<typeof GetAppSchema>;
|
|
34
|
+
|
|
35
|
+
// SDK function interface - ready to be mixed into main SDK interface
|
|
36
|
+
export interface GetAppSdkFunction {
|
|
37
|
+
getApp: (options: GetAppOptions) => Promise<{ data: AppItem }>;
|
|
38
|
+
}
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
ZapierValidationError,
|
|
4
|
+
ZapierAuthenticationError,
|
|
5
|
+
ZapierResourceNotFoundError,
|
|
6
|
+
} from "../../types/errors";
|
|
7
|
+
import { getAuthenticationPlugin } from "./index";
|
|
8
|
+
import { createSdk } from "../../sdk";
|
|
9
|
+
import type { ApiClient } from "../../api";
|
|
10
|
+
import type { GetAuthenticationOptions } from "./schemas";
|
|
11
|
+
import type { Authentication } from "../../api/types";
|
|
12
|
+
|
|
13
|
+
const mockAuthenticationResponse: Authentication = {
|
|
14
|
+
id: 123,
|
|
15
|
+
date: "2021-01-01",
|
|
16
|
+
account_id: 456 as any,
|
|
17
|
+
selected_api: "SlackCLIAPI@1.21.1",
|
|
18
|
+
is_invite_only: false,
|
|
19
|
+
is_private: false,
|
|
20
|
+
shared_with_all: false,
|
|
21
|
+
is_stale: "false",
|
|
22
|
+
marked_stale_at: null,
|
|
23
|
+
label: "My Slack Workspace",
|
|
24
|
+
title: "My Slack Workspace",
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
describe("getAuthentication plugin", () => {
|
|
28
|
+
let mockApiClient: ApiClient;
|
|
29
|
+
|
|
30
|
+
beforeEach(() => {
|
|
31
|
+
vi.clearAllMocks();
|
|
32
|
+
mockApiClient = {
|
|
33
|
+
get: vi.fn().mockResolvedValue(mockAuthenticationResponse),
|
|
34
|
+
} as Partial<ApiClient> as ApiClient;
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
function createTestSdk() {
|
|
38
|
+
return createSdk({}, { api: mockApiClient, meta: {} }).addPlugin(
|
|
39
|
+
getAuthenticationPlugin,
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
describe("schema validation", () => {
|
|
44
|
+
it("should throw validation error for missing authenticationId", async () => {
|
|
45
|
+
const sdk = createTestSdk();
|
|
46
|
+
await expect(
|
|
47
|
+
sdk.getAuthentication({} as GetAuthenticationOptions),
|
|
48
|
+
).rejects.toThrow(ZapierValidationError);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("should throw validation error for invalid authenticationId type", async () => {
|
|
52
|
+
const sdk = createTestSdk();
|
|
53
|
+
await expect(
|
|
54
|
+
sdk.getAuthentication({
|
|
55
|
+
authenticationId: "invalid" as any,
|
|
56
|
+
}),
|
|
57
|
+
).rejects.toThrow(ZapierValidationError);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("should throw validation error for negative authenticationId", async () => {
|
|
61
|
+
const sdk = createTestSdk();
|
|
62
|
+
await expect(
|
|
63
|
+
sdk.getAuthentication({
|
|
64
|
+
authenticationId: -1,
|
|
65
|
+
}),
|
|
66
|
+
).rejects.toThrow(ZapierValidationError);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("should throw validation error for zero authenticationId", async () => {
|
|
70
|
+
const sdk = createTestSdk();
|
|
71
|
+
await expect(
|
|
72
|
+
sdk.getAuthentication({
|
|
73
|
+
authenticationId: 0,
|
|
74
|
+
}),
|
|
75
|
+
).rejects.toThrow(ZapierValidationError);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("should pass validation with valid authenticationId", async () => {
|
|
79
|
+
const sdk = createTestSdk();
|
|
80
|
+
const result = await sdk.getAuthentication({
|
|
81
|
+
authenticationId: 123,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
expect(result.data).toBeDefined();
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
describe("API integration", () => {
|
|
89
|
+
it("should call the correct API endpoint", async () => {
|
|
90
|
+
const sdk = createTestSdk();
|
|
91
|
+
await sdk.getAuthentication({ authenticationId: 123 });
|
|
92
|
+
|
|
93
|
+
expect(mockApiClient.get).toHaveBeenCalledWith(
|
|
94
|
+
"/api/v4/authentications/123/",
|
|
95
|
+
expect.objectContaining({
|
|
96
|
+
authRequired: true,
|
|
97
|
+
customErrorHandler: expect.any(Function),
|
|
98
|
+
}),
|
|
99
|
+
);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it("should return normalized authentication data", async () => {
|
|
103
|
+
const sdk = createTestSdk();
|
|
104
|
+
const result = await sdk.getAuthentication({ authenticationId: 123 });
|
|
105
|
+
|
|
106
|
+
expect(result.data).toEqual({
|
|
107
|
+
id: 123,
|
|
108
|
+
date: "2021-01-01",
|
|
109
|
+
account_id: 456 as any,
|
|
110
|
+
implementation_id: "SlackCLIAPI@1.21.1",
|
|
111
|
+
is_invite_only: false,
|
|
112
|
+
is_private: false,
|
|
113
|
+
shared_with_all: false,
|
|
114
|
+
is_expired: "false",
|
|
115
|
+
expired_at: null,
|
|
116
|
+
label: "My Slack Workspace",
|
|
117
|
+
title: "My Slack Workspace",
|
|
118
|
+
app_key: "SlackCLIAPI",
|
|
119
|
+
version: "1.21.1",
|
|
120
|
+
user_id: undefined, // customuser_id wasn't in mock data
|
|
121
|
+
is_stale: "false", // Original field preserved
|
|
122
|
+
marked_stale_at: null, // Original field preserved
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
describe("error handling", () => {
|
|
128
|
+
it("should throw ZapierAuthenticationError for 401 responses", async () => {
|
|
129
|
+
const customErrorHandler = vi
|
|
130
|
+
.fn()
|
|
131
|
+
.mockReturnValue(
|
|
132
|
+
new ZapierAuthenticationError(
|
|
133
|
+
"Authentication failed. Your token may not have permission to access authentications or may be expired. (HTTP 401)",
|
|
134
|
+
{ statusCode: 401 },
|
|
135
|
+
),
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
mockApiClient.get = vi.fn().mockImplementation(() => {
|
|
139
|
+
const error = customErrorHandler({ status: 401 });
|
|
140
|
+
throw error;
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
const sdk = createTestSdk();
|
|
144
|
+
await expect(
|
|
145
|
+
sdk.getAuthentication({ authenticationId: 123 }),
|
|
146
|
+
).rejects.toThrow(ZapierAuthenticationError);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it("should throw ZapierAuthenticationError for 403 responses", async () => {
|
|
150
|
+
const customErrorHandler = vi
|
|
151
|
+
.fn()
|
|
152
|
+
.mockReturnValue(
|
|
153
|
+
new ZapierAuthenticationError(
|
|
154
|
+
"Access forbidden. Your token may not have the required scopes to get authentication 123. (HTTP 403)",
|
|
155
|
+
{ statusCode: 403 },
|
|
156
|
+
),
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
mockApiClient.get = vi.fn().mockImplementation(() => {
|
|
160
|
+
const error = customErrorHandler({ status: 403 });
|
|
161
|
+
throw error;
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
const sdk = createTestSdk();
|
|
165
|
+
await expect(
|
|
166
|
+
sdk.getAuthentication({ authenticationId: 123 }),
|
|
167
|
+
).rejects.toThrow(ZapierAuthenticationError);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it("should throw ZapierResourceNotFoundError for 404 responses", async () => {
|
|
171
|
+
const customErrorHandler = vi.fn().mockReturnValue(
|
|
172
|
+
new ZapierResourceNotFoundError(
|
|
173
|
+
"Authentication 123 not found. It may not exist or you may not have access to it. (HTTP 404)",
|
|
174
|
+
{
|
|
175
|
+
resourceType: "Authentication",
|
|
176
|
+
resourceId: "123",
|
|
177
|
+
},
|
|
178
|
+
),
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
mockApiClient.get = vi.fn().mockImplementation(() => {
|
|
182
|
+
const error = customErrorHandler({ status: 404 });
|
|
183
|
+
throw error;
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
const sdk = createTestSdk();
|
|
187
|
+
await expect(
|
|
188
|
+
sdk.getAuthentication({ authenticationId: 123 }),
|
|
189
|
+
).rejects.toThrow(ZapierResourceNotFoundError);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it("should handle network errors", async () => {
|
|
193
|
+
mockApiClient.get = vi.fn().mockRejectedValue(new Error("Network error"));
|
|
194
|
+
|
|
195
|
+
const sdk = createTestSdk();
|
|
196
|
+
await expect(
|
|
197
|
+
sdk.getAuthentication({ authenticationId: 123 }),
|
|
198
|
+
).rejects.toThrow("Network error");
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
describe("data transformation", () => {
|
|
203
|
+
it("should map is_stale to is_expired and marked_stale_at to expired_at", async () => {
|
|
204
|
+
const authWithExpiration = {
|
|
205
|
+
...mockAuthenticationResponse,
|
|
206
|
+
is_stale: "true",
|
|
207
|
+
marked_stale_at: "2021-06-01",
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
mockApiClient.get = vi.fn().mockResolvedValue(authWithExpiration);
|
|
211
|
+
|
|
212
|
+
const sdk = createTestSdk();
|
|
213
|
+
const result = await sdk.getAuthentication({ authenticationId: 123 });
|
|
214
|
+
|
|
215
|
+
expect(result.data.is_expired).toBe("true");
|
|
216
|
+
expect(result.data.expired_at).toBe("2021-06-01");
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it("should preserve all original authentication fields", async () => {
|
|
220
|
+
const authWithAllFields = {
|
|
221
|
+
id: 123,
|
|
222
|
+
date: "2021-01-01",
|
|
223
|
+
lastchanged: "2021-01-02",
|
|
224
|
+
account_id: 456 as any,
|
|
225
|
+
customuser_id: 789,
|
|
226
|
+
selected_api: "SlackCLIAPI@1.21.1",
|
|
227
|
+
destination_selected_api: "SlackDestAPI@1.0.0",
|
|
228
|
+
is_invite_only: true,
|
|
229
|
+
is_private: true,
|
|
230
|
+
shared_with_all: false,
|
|
231
|
+
is_stale: "true",
|
|
232
|
+
is_shared: "false",
|
|
233
|
+
marked_stale_at: "2021-06-01",
|
|
234
|
+
label: "Auth Label",
|
|
235
|
+
title: "Auth Title",
|
|
236
|
+
identifier: "auth-identifier",
|
|
237
|
+
url: "https://example.com",
|
|
238
|
+
groups: "group1,group2",
|
|
239
|
+
members: "user1,user2",
|
|
240
|
+
permissions: { read: true, write: false },
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
mockApiClient.get = vi.fn().mockResolvedValue(authWithAllFields);
|
|
244
|
+
|
|
245
|
+
const sdk = createTestSdk();
|
|
246
|
+
const result = await sdk.getAuthentication({ authenticationId: 123 });
|
|
247
|
+
const auth = result.data;
|
|
248
|
+
|
|
249
|
+
// Verify original fields are preserved
|
|
250
|
+
expect(auth.id).toBe(123);
|
|
251
|
+
expect(auth.date).toBe("2021-01-01");
|
|
252
|
+
expect(auth.lastchanged).toBe("2021-01-02");
|
|
253
|
+
expect(auth.account_id).toBe(456);
|
|
254
|
+
expect(auth.user_id).toBe(789);
|
|
255
|
+
expect(auth.implementation_id).toBe("SlackCLIAPI@1.21.1");
|
|
256
|
+
expect(auth.destination_selected_api).toBe("SlackDestAPI@1.0.0");
|
|
257
|
+
expect(auth.is_invite_only).toBe(true);
|
|
258
|
+
expect(auth.is_private).toBe(true);
|
|
259
|
+
expect(auth.shared_with_all).toBe(false);
|
|
260
|
+
expect(auth.is_shared).toBe("false");
|
|
261
|
+
expect(auth.label).toBe("Auth Label");
|
|
262
|
+
expect(auth.title).toBe("Auth Title");
|
|
263
|
+
expect(auth.identifier).toBe("auth-identifier");
|
|
264
|
+
expect(auth.url).toBe("https://example.com");
|
|
265
|
+
expect(auth.groups).toBe("group1,group2");
|
|
266
|
+
expect(auth.members).toBe("user1,user2");
|
|
267
|
+
expect(auth.permissions).toEqual({ read: true, write: false });
|
|
268
|
+
|
|
269
|
+
// Verify mapped fields
|
|
270
|
+
expect(auth.is_expired).toBe("true");
|
|
271
|
+
expect(auth.expired_at).toBe("2021-06-01");
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
describe("context and metadata", () => {
|
|
276
|
+
it("should provide context with meta information", () => {
|
|
277
|
+
const sdk = createTestSdk();
|
|
278
|
+
const context = sdk.getContext();
|
|
279
|
+
|
|
280
|
+
expect((context.meta as any).getAuthentication).toBeDefined();
|
|
281
|
+
expect((context.meta as any).getAuthentication.inputSchema).toBeDefined();
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
});
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { Plugin } from "../../types/plugin";
|
|
2
|
+
import type { ApiClient } from "../../api";
|
|
3
|
+
import type { Authentication } from "../../api/types";
|
|
4
|
+
import type { AuthenticationItem } from "../../types/domain";
|
|
5
|
+
import {
|
|
6
|
+
GetAuthenticationSchema,
|
|
7
|
+
type GetAuthenticationOptions,
|
|
8
|
+
} from "./schemas";
|
|
9
|
+
import {
|
|
10
|
+
ZapierAuthenticationError,
|
|
11
|
+
ZapierResourceNotFoundError,
|
|
12
|
+
} from "../../types/errors";
|
|
13
|
+
import { createFunction } from "../../utils/function-utils";
|
|
14
|
+
import { normalizeAuthenticationItem } from "../../utils/domain-utils";
|
|
15
|
+
|
|
16
|
+
export interface GetAuthenticationPluginProvides {
|
|
17
|
+
getAuthentication: (
|
|
18
|
+
options: GetAuthenticationOptions,
|
|
19
|
+
) => Promise<{ data: AuthenticationItem }>;
|
|
20
|
+
context: {
|
|
21
|
+
meta: {
|
|
22
|
+
getAuthentication: {
|
|
23
|
+
inputSchema: typeof GetAuthenticationSchema;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const getAuthenticationPlugin: Plugin<
|
|
30
|
+
{}, // no SDK dependencies
|
|
31
|
+
{ api: ApiClient }, // requires api in context
|
|
32
|
+
GetAuthenticationPluginProvides
|
|
33
|
+
> = ({ context }) => {
|
|
34
|
+
const getAuthentication = createFunction(async function getAuthentication(
|
|
35
|
+
options: GetAuthenticationOptions,
|
|
36
|
+
) {
|
|
37
|
+
const { api } = context;
|
|
38
|
+
const { authenticationId } = options;
|
|
39
|
+
|
|
40
|
+
const data: Authentication = await api.get(
|
|
41
|
+
`/api/v4/authentications/${authenticationId}/`,
|
|
42
|
+
{
|
|
43
|
+
customErrorHandler: ({ status }: { status: number }) => {
|
|
44
|
+
if (status === 401) {
|
|
45
|
+
return new ZapierAuthenticationError(
|
|
46
|
+
`Authentication failed. Your token may not have permission to access authentications or may be expired. (HTTP ${status})`,
|
|
47
|
+
{ statusCode: status },
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
if (status === 403) {
|
|
51
|
+
return new ZapierAuthenticationError(
|
|
52
|
+
`Access forbidden. Your token may not have the required scopes to get authentication ${authenticationId}. (HTTP ${status})`,
|
|
53
|
+
{ statusCode: status },
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
if (status === 404) {
|
|
57
|
+
return new ZapierResourceNotFoundError(
|
|
58
|
+
`Authentication ${authenticationId} not found. It may not exist or you may not have access to it. (HTTP ${status})`,
|
|
59
|
+
{
|
|
60
|
+
resourceType: "Authentication",
|
|
61
|
+
resourceId: String(authenticationId),
|
|
62
|
+
},
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
return undefined;
|
|
66
|
+
},
|
|
67
|
+
authRequired: true,
|
|
68
|
+
},
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
return {
|
|
72
|
+
data: normalizeAuthenticationItem(data),
|
|
73
|
+
};
|
|
74
|
+
}, GetAuthenticationSchema);
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
getAuthentication,
|
|
78
|
+
context: {
|
|
79
|
+
meta: {
|
|
80
|
+
getAuthentication: {
|
|
81
|
+
inputSchema: GetAuthenticationSchema,
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { AuthenticationItem } from "../../types/domain";
|
|
3
|
+
|
|
4
|
+
// Pure Zod schema - no resolver metadata!
|
|
5
|
+
export const GetAuthenticationSchema = z
|
|
6
|
+
.object({
|
|
7
|
+
authenticationId: z
|
|
8
|
+
.number()
|
|
9
|
+
.int()
|
|
10
|
+
.positive()
|
|
11
|
+
.describe("Authentication ID to retrieve"),
|
|
12
|
+
})
|
|
13
|
+
.describe("Get a specific authentication by ID");
|
|
14
|
+
|
|
15
|
+
// Type inferred from schema
|
|
16
|
+
export type GetAuthenticationOptions = z.infer<typeof GetAuthenticationSchema>;
|
|
17
|
+
|
|
18
|
+
// Error union for this function
|
|
19
|
+
export type GetAuthenticationError =
|
|
20
|
+
| import("../../types/errors").ZapierAuthenticationError
|
|
21
|
+
| import("../../types/errors").ZapierResourceNotFoundError
|
|
22
|
+
| import("../../types/errors").ZapierApiError
|
|
23
|
+
| import("../../types/errors").ZapierValidationError
|
|
24
|
+
| import("../../types/errors").ZapierUnknownError;
|
|
25
|
+
|
|
26
|
+
// SDK function interface - ready to be mixed into main SDK interface
|
|
27
|
+
export interface GetAuthenticationSdkFunction {
|
|
28
|
+
getAuthentication: (
|
|
29
|
+
options: GetAuthenticationOptions,
|
|
30
|
+
) => Promise<{ data: AuthenticationItem }>;
|
|
31
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { GetProfileOptions } from "./schemas";
|
|
2
|
+
import type { UserProfile, ApiClient } from "../../api/types";
|
|
3
|
+
import { createFunction } from "../../utils/function-utils";
|
|
4
|
+
import type { Plugin } from "../../types/plugin";
|
|
5
|
+
import type { UserProfileItem } from "../../types/domain";
|
|
6
|
+
import { GetProfileSchema } from "./schemas";
|
|
7
|
+
|
|
8
|
+
// GetProfile plugin provides interface - getProfile goes directly to SDK root
|
|
9
|
+
export interface GetProfilePluginProvides {
|
|
10
|
+
getProfile: (
|
|
11
|
+
options?: GetProfileOptions,
|
|
12
|
+
) => Promise<{ data: UserProfileItem }>;
|
|
13
|
+
context: {
|
|
14
|
+
meta: {
|
|
15
|
+
getProfile: {
|
|
16
|
+
inputSchema: typeof GetProfileSchema;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Direct plugin function - takes options + sdk + context in one object
|
|
23
|
+
export const getProfilePlugin: Plugin<
|
|
24
|
+
{}, // no SDK dependencies
|
|
25
|
+
{ api: ApiClient }, // requires api in context
|
|
26
|
+
GetProfilePluginProvides
|
|
27
|
+
> = ({ context }) => {
|
|
28
|
+
const getProfile = createFunction(async function getProfile() {
|
|
29
|
+
const profile: UserProfile = await context.api.get("/api/v4/profile/", {
|
|
30
|
+
authRequired: true,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// Remove user_id since that's our internal user ID which could confuse things!
|
|
34
|
+
const { user_id: _unusedUserId, ...data } = profile;
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
data: {
|
|
38
|
+
...data, // Pass through all API response fields
|
|
39
|
+
full_name: `${profile.first_name} ${profile.last_name}`, // Computed field
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}, GetProfileSchema);
|
|
43
|
+
|
|
44
|
+
// Return flat structure - getProfile goes directly to SDK
|
|
45
|
+
return {
|
|
46
|
+
getProfile,
|
|
47
|
+
context: {
|
|
48
|
+
meta: {
|
|
49
|
+
getProfile: {
|
|
50
|
+
inputSchema: GetProfileSchema,
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
};
|