@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,100 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
+
import { ZapierValidationError, ZapierAppNotFoundError, } from "../../types/errors";
|
|
3
|
+
import { getAppPlugin } from "./index";
|
|
4
|
+
import { createSdk } from "../../sdk";
|
|
5
|
+
import { apiPlugin } from "../api/index";
|
|
6
|
+
import { listAppsPlugin } from "../listApps";
|
|
7
|
+
function createTestSdk() {
|
|
8
|
+
return createSdk()
|
|
9
|
+
.addPlugin(apiPlugin, { fetch: global.fetch })
|
|
10
|
+
.addPlugin(listAppsPlugin)
|
|
11
|
+
.addPlugin(getAppPlugin);
|
|
12
|
+
}
|
|
13
|
+
describe("getApp plugin", () => {
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
vi.clearAllMocks();
|
|
16
|
+
});
|
|
17
|
+
describe("schema validation", () => {
|
|
18
|
+
it("should throw validation error for missing appKey", async () => {
|
|
19
|
+
const sdk = createTestSdk();
|
|
20
|
+
await expect(sdk.getApp({})).rejects.toThrow(ZapierValidationError);
|
|
21
|
+
});
|
|
22
|
+
it("should throw validation error for invalid appKey type", async () => {
|
|
23
|
+
const sdk = createTestSdk();
|
|
24
|
+
await expect(sdk.getApp({
|
|
25
|
+
appKey: 123,
|
|
26
|
+
})).rejects.toThrow(ZapierValidationError);
|
|
27
|
+
});
|
|
28
|
+
it("should throw validation error for empty string appKey", async () => {
|
|
29
|
+
const sdk = createTestSdk();
|
|
30
|
+
await expect(sdk.getApp({
|
|
31
|
+
appKey: "",
|
|
32
|
+
})).rejects.toThrow(ZapierValidationError);
|
|
33
|
+
});
|
|
34
|
+
it("should pass validation with valid appKey", async () => {
|
|
35
|
+
const sdk = createTestSdk();
|
|
36
|
+
const context = sdk.getContext();
|
|
37
|
+
// Mock the API client in context to respond to listApps implementation
|
|
38
|
+
context.api.get = vi.fn().mockResolvedValue({
|
|
39
|
+
results: [
|
|
40
|
+
{
|
|
41
|
+
id: "SlackCLIAPI@1.0.0",
|
|
42
|
+
name: "Slack",
|
|
43
|
+
description: "Team communication",
|
|
44
|
+
primary_color: "#4A154B",
|
|
45
|
+
categories: ["communication"],
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
next: null,
|
|
49
|
+
});
|
|
50
|
+
const result = await sdk.getApp({
|
|
51
|
+
appKey: "slack",
|
|
52
|
+
});
|
|
53
|
+
expect(result.data.title).toBe("Slack");
|
|
54
|
+
expect(result.data.key).toBe("SlackCLIAPI");
|
|
55
|
+
expect(result.data.current_implementation_id).toBe("SlackCLIAPI@1.0.0");
|
|
56
|
+
expect(result.data.version).toBe("1.0.0");
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
describe("error handling", () => {
|
|
60
|
+
it("should throw ZapierAppNotFoundError when app does not exist", async () => {
|
|
61
|
+
const sdk = createTestSdk();
|
|
62
|
+
const context = sdk.getContext();
|
|
63
|
+
// Mock API to return empty results (app not found)
|
|
64
|
+
context.api.get = vi.fn().mockResolvedValue({
|
|
65
|
+
results: [],
|
|
66
|
+
next: null,
|
|
67
|
+
});
|
|
68
|
+
await expect(sdk.getApp({
|
|
69
|
+
appKey: "nonexistent-app",
|
|
70
|
+
})).rejects.toThrow(ZapierAppNotFoundError);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
describe("data mapping", () => {
|
|
74
|
+
it("should return essential app properties", async () => {
|
|
75
|
+
const sdk = createTestSdk();
|
|
76
|
+
const context = sdk.getContext();
|
|
77
|
+
// Mock the API client in context to respond to listApps implementation
|
|
78
|
+
context.api.get = vi.fn().mockResolvedValue({
|
|
79
|
+
results: [
|
|
80
|
+
{
|
|
81
|
+
id: "TestCLIAPI@1.0.0",
|
|
82
|
+
name: "Test App",
|
|
83
|
+
description: "Test description",
|
|
84
|
+
primary_color: "#FF0000",
|
|
85
|
+
categories: ["testing"],
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
next: null,
|
|
89
|
+
});
|
|
90
|
+
const result = await sdk.getApp({
|
|
91
|
+
appKey: "test",
|
|
92
|
+
});
|
|
93
|
+
expect(result.data.title).toBeDefined();
|
|
94
|
+
expect(result.data.key).toBeDefined();
|
|
95
|
+
expect(result.data.current_implementation_id).toBeDefined();
|
|
96
|
+
expect(result.data.title).toBe("Test App");
|
|
97
|
+
expect(result.data.key).toBe("TestCLIAPI");
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { AppItem } from "../../types/domain";
|
|
3
|
+
import { ZapierApiError, ZapierAppNotFoundError, ZapierValidationError } from "../../types/errors";
|
|
4
|
+
export type GetAppError = ZapierAppNotFoundError | ZapierApiError | ZapierValidationError;
|
|
5
|
+
export declare const GetAppSchema: z.ZodObject<{
|
|
6
|
+
appKey: z.ZodString;
|
|
7
|
+
}, "strip", z.ZodTypeAny, {
|
|
8
|
+
appKey: string;
|
|
9
|
+
}, {
|
|
10
|
+
appKey: string;
|
|
11
|
+
}>;
|
|
12
|
+
export type GetAppOptions = z.infer<typeof GetAppSchema>;
|
|
13
|
+
export interface GetAppSdkFunction {
|
|
14
|
+
getApp: (options: GetAppOptions) => Promise<{
|
|
15
|
+
data: AppItem;
|
|
16
|
+
}>;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=schemas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../src/plugins/getApp/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EACL,cAAc,EACd,sBAAsB,EACtB,qBAAqB,EACtB,MAAM,oBAAoB,CAAC;AAK5B,MAAM,MAAM,WAAW,GACnB,sBAAsB,GACtB,cAAc,GACd,qBAAqB,CAAC;AAG1B,eAAO,MAAM,YAAY;;;;;;EASxB,CAAC;AAGF,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AAGzD,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,CAAC,OAAO,EAAE,aAAa,KAAK,OAAO,CAAC;QAAE,IAAI,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;CAChE"}
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
// Pure Zod schema - no resolver metadata!
|
|
6
|
+
export const GetAppSchema = withOutputSchema(z
|
|
7
|
+
.object({
|
|
8
|
+
appKey: AppKeyPropertySchema.describe("App key of app to fetch (e.g., 'SlackCLIAPI')"),
|
|
9
|
+
})
|
|
10
|
+
.describe("Get detailed information about a specific app"), AppItemSchema);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Plugin } from "../../types/plugin";
|
|
2
|
+
import type { ApiClient } from "../../api";
|
|
3
|
+
import type { AuthenticationItem } from "../../types/domain";
|
|
4
|
+
import { GetAuthenticationSchema, type GetAuthenticationOptions } from "./schemas";
|
|
5
|
+
export interface GetAuthenticationPluginProvides {
|
|
6
|
+
getAuthentication: (options: GetAuthenticationOptions) => Promise<{
|
|
7
|
+
data: AuthenticationItem;
|
|
8
|
+
}>;
|
|
9
|
+
context: {
|
|
10
|
+
meta: {
|
|
11
|
+
getAuthentication: {
|
|
12
|
+
inputSchema: typeof GetAuthenticationSchema;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export declare const getAuthenticationPlugin: Plugin<{}, // no SDK dependencies
|
|
18
|
+
{
|
|
19
|
+
api: ApiClient;
|
|
20
|
+
}, // requires api in context
|
|
21
|
+
GetAuthenticationPluginProvides>;
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/getAuthentication/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EACL,uBAAuB,EACvB,KAAK,wBAAwB,EAC9B,MAAM,WAAW,CAAC;AAQnB,MAAM,WAAW,+BAA+B;IAC9C,iBAAiB,EAAE,CACjB,OAAO,EAAE,wBAAwB,KAC9B,OAAO,CAAC;QAAE,IAAI,EAAE,kBAAkB,CAAA;KAAE,CAAC,CAAC;IAC3C,OAAO,EAAE;QACP,IAAI,EAAE;YACJ,iBAAiB,EAAE;gBACjB,WAAW,EAAE,OAAO,uBAAuB,CAAC;aAC7C,CAAC;SACH,CAAC;KACH,CAAC;CACH;AAED,eAAO,MAAM,uBAAuB,EAAE,MAAM,CAC1C,EAAE,EAAE,sBAAsB;AAC1B;IAAE,GAAG,EAAE,SAAS,CAAA;CAAE,EAAE,0BAA0B;AAC9C,+BAA+B,CAsDhC,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { GetAuthenticationSchema, } from "./schemas";
|
|
2
|
+
import { ZapierAuthenticationError, ZapierResourceNotFoundError, } from "../../types/errors";
|
|
3
|
+
import { createFunction } from "../../utils/function-utils";
|
|
4
|
+
import { normalizeAuthenticationItem } from "../../utils/domain-utils";
|
|
5
|
+
export const getAuthenticationPlugin = ({ context }) => {
|
|
6
|
+
const getAuthentication = createFunction(async function getAuthentication(options) {
|
|
7
|
+
const { api } = context;
|
|
8
|
+
const { authenticationId } = options;
|
|
9
|
+
const data = await api.get(`/api/v4/authentications/${authenticationId}/`, {
|
|
10
|
+
customErrorHandler: ({ status }) => {
|
|
11
|
+
if (status === 401) {
|
|
12
|
+
return new ZapierAuthenticationError(`Authentication failed. Your token may not have permission to access authentications or may be expired. (HTTP ${status})`, { statusCode: status });
|
|
13
|
+
}
|
|
14
|
+
if (status === 403) {
|
|
15
|
+
return new ZapierAuthenticationError(`Access forbidden. Your token may not have the required scopes to get authentication ${authenticationId}. (HTTP ${status})`, { statusCode: status });
|
|
16
|
+
}
|
|
17
|
+
if (status === 404) {
|
|
18
|
+
return new ZapierResourceNotFoundError(`Authentication ${authenticationId} not found. It may not exist or you may not have access to it. (HTTP ${status})`, {
|
|
19
|
+
resourceType: "Authentication",
|
|
20
|
+
resourceId: String(authenticationId),
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return undefined;
|
|
24
|
+
},
|
|
25
|
+
authRequired: true,
|
|
26
|
+
});
|
|
27
|
+
return {
|
|
28
|
+
data: normalizeAuthenticationItem(data),
|
|
29
|
+
};
|
|
30
|
+
}, GetAuthenticationSchema);
|
|
31
|
+
return {
|
|
32
|
+
getAuthentication,
|
|
33
|
+
context: {
|
|
34
|
+
meta: {
|
|
35
|
+
getAuthentication: {
|
|
36
|
+
inputSchema: GetAuthenticationSchema,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../../src/plugins/getAuthentication/index.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
+
import { ZapierValidationError, ZapierAuthenticationError, ZapierResourceNotFoundError, } from "../../types/errors";
|
|
3
|
+
import { getAuthenticationPlugin } from "./index";
|
|
4
|
+
import { createSdk } from "../../sdk";
|
|
5
|
+
const mockAuthenticationResponse = {
|
|
6
|
+
id: 123,
|
|
7
|
+
date: "2021-01-01",
|
|
8
|
+
account_id: 456,
|
|
9
|
+
selected_api: "SlackCLIAPI@1.21.1",
|
|
10
|
+
is_invite_only: false,
|
|
11
|
+
is_private: false,
|
|
12
|
+
shared_with_all: false,
|
|
13
|
+
is_stale: "false",
|
|
14
|
+
marked_stale_at: null,
|
|
15
|
+
label: "My Slack Workspace",
|
|
16
|
+
title: "My Slack Workspace",
|
|
17
|
+
};
|
|
18
|
+
describe("getAuthentication plugin", () => {
|
|
19
|
+
let mockApiClient;
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
vi.clearAllMocks();
|
|
22
|
+
mockApiClient = {
|
|
23
|
+
get: vi.fn().mockResolvedValue(mockAuthenticationResponse),
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
function createTestSdk() {
|
|
27
|
+
return createSdk({}, { api: mockApiClient, meta: {} }).addPlugin(getAuthenticationPlugin);
|
|
28
|
+
}
|
|
29
|
+
describe("schema validation", () => {
|
|
30
|
+
it("should throw validation error for missing authenticationId", async () => {
|
|
31
|
+
const sdk = createTestSdk();
|
|
32
|
+
await expect(sdk.getAuthentication({})).rejects.toThrow(ZapierValidationError);
|
|
33
|
+
});
|
|
34
|
+
it("should throw validation error for invalid authenticationId type", async () => {
|
|
35
|
+
const sdk = createTestSdk();
|
|
36
|
+
await expect(sdk.getAuthentication({
|
|
37
|
+
authenticationId: "invalid",
|
|
38
|
+
})).rejects.toThrow(ZapierValidationError);
|
|
39
|
+
});
|
|
40
|
+
it("should throw validation error for negative authenticationId", async () => {
|
|
41
|
+
const sdk = createTestSdk();
|
|
42
|
+
await expect(sdk.getAuthentication({
|
|
43
|
+
authenticationId: -1,
|
|
44
|
+
})).rejects.toThrow(ZapierValidationError);
|
|
45
|
+
});
|
|
46
|
+
it("should throw validation error for zero authenticationId", async () => {
|
|
47
|
+
const sdk = createTestSdk();
|
|
48
|
+
await expect(sdk.getAuthentication({
|
|
49
|
+
authenticationId: 0,
|
|
50
|
+
})).rejects.toThrow(ZapierValidationError);
|
|
51
|
+
});
|
|
52
|
+
it("should pass validation with valid authenticationId", async () => {
|
|
53
|
+
const sdk = createTestSdk();
|
|
54
|
+
const result = await sdk.getAuthentication({
|
|
55
|
+
authenticationId: 123,
|
|
56
|
+
});
|
|
57
|
+
expect(result.data).toBeDefined();
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
describe("API integration", () => {
|
|
61
|
+
it("should call the correct API endpoint", async () => {
|
|
62
|
+
const sdk = createTestSdk();
|
|
63
|
+
await sdk.getAuthentication({ authenticationId: 123 });
|
|
64
|
+
expect(mockApiClient.get).toHaveBeenCalledWith("/api/v4/authentications/123/", expect.objectContaining({
|
|
65
|
+
authRequired: true,
|
|
66
|
+
customErrorHandler: expect.any(Function),
|
|
67
|
+
}));
|
|
68
|
+
});
|
|
69
|
+
it("should return normalized authentication data", async () => {
|
|
70
|
+
const sdk = createTestSdk();
|
|
71
|
+
const result = await sdk.getAuthentication({ authenticationId: 123 });
|
|
72
|
+
expect(result.data).toEqual({
|
|
73
|
+
id: 123,
|
|
74
|
+
date: "2021-01-01",
|
|
75
|
+
account_id: 456,
|
|
76
|
+
implementation_id: "SlackCLIAPI@1.21.1",
|
|
77
|
+
is_invite_only: false,
|
|
78
|
+
is_private: false,
|
|
79
|
+
shared_with_all: false,
|
|
80
|
+
is_expired: "false",
|
|
81
|
+
expired_at: null,
|
|
82
|
+
label: "My Slack Workspace",
|
|
83
|
+
title: "My Slack Workspace",
|
|
84
|
+
app_key: "SlackCLIAPI",
|
|
85
|
+
version: "1.21.1",
|
|
86
|
+
user_id: undefined, // customuser_id wasn't in mock data
|
|
87
|
+
is_stale: "false", // Original field preserved
|
|
88
|
+
marked_stale_at: null, // Original field preserved
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
describe("error handling", () => {
|
|
93
|
+
it("should throw ZapierAuthenticationError for 401 responses", async () => {
|
|
94
|
+
const customErrorHandler = vi
|
|
95
|
+
.fn()
|
|
96
|
+
.mockReturnValue(new ZapierAuthenticationError("Authentication failed. Your token may not have permission to access authentications or may be expired. (HTTP 401)", { statusCode: 401 }));
|
|
97
|
+
mockApiClient.get = vi.fn().mockImplementation(() => {
|
|
98
|
+
const error = customErrorHandler({ status: 401 });
|
|
99
|
+
throw error;
|
|
100
|
+
});
|
|
101
|
+
const sdk = createTestSdk();
|
|
102
|
+
await expect(sdk.getAuthentication({ authenticationId: 123 })).rejects.toThrow(ZapierAuthenticationError);
|
|
103
|
+
});
|
|
104
|
+
it("should throw ZapierAuthenticationError for 403 responses", async () => {
|
|
105
|
+
const customErrorHandler = vi
|
|
106
|
+
.fn()
|
|
107
|
+
.mockReturnValue(new ZapierAuthenticationError("Access forbidden. Your token may not have the required scopes to get authentication 123. (HTTP 403)", { statusCode: 403 }));
|
|
108
|
+
mockApiClient.get = vi.fn().mockImplementation(() => {
|
|
109
|
+
const error = customErrorHandler({ status: 403 });
|
|
110
|
+
throw error;
|
|
111
|
+
});
|
|
112
|
+
const sdk = createTestSdk();
|
|
113
|
+
await expect(sdk.getAuthentication({ authenticationId: 123 })).rejects.toThrow(ZapierAuthenticationError);
|
|
114
|
+
});
|
|
115
|
+
it("should throw ZapierResourceNotFoundError for 404 responses", async () => {
|
|
116
|
+
const customErrorHandler = vi.fn().mockReturnValue(new ZapierResourceNotFoundError("Authentication 123 not found. It may not exist or you may not have access to it. (HTTP 404)", {
|
|
117
|
+
resourceType: "Authentication",
|
|
118
|
+
resourceId: "123",
|
|
119
|
+
}));
|
|
120
|
+
mockApiClient.get = vi.fn().mockImplementation(() => {
|
|
121
|
+
const error = customErrorHandler({ status: 404 });
|
|
122
|
+
throw error;
|
|
123
|
+
});
|
|
124
|
+
const sdk = createTestSdk();
|
|
125
|
+
await expect(sdk.getAuthentication({ authenticationId: 123 })).rejects.toThrow(ZapierResourceNotFoundError);
|
|
126
|
+
});
|
|
127
|
+
it("should handle network errors", async () => {
|
|
128
|
+
mockApiClient.get = vi.fn().mockRejectedValue(new Error("Network error"));
|
|
129
|
+
const sdk = createTestSdk();
|
|
130
|
+
await expect(sdk.getAuthentication({ authenticationId: 123 })).rejects.toThrow("Network error");
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
describe("data transformation", () => {
|
|
134
|
+
it("should map is_stale to is_expired and marked_stale_at to expired_at", async () => {
|
|
135
|
+
const authWithExpiration = {
|
|
136
|
+
...mockAuthenticationResponse,
|
|
137
|
+
is_stale: "true",
|
|
138
|
+
marked_stale_at: "2021-06-01",
|
|
139
|
+
};
|
|
140
|
+
mockApiClient.get = vi.fn().mockResolvedValue(authWithExpiration);
|
|
141
|
+
const sdk = createTestSdk();
|
|
142
|
+
const result = await sdk.getAuthentication({ authenticationId: 123 });
|
|
143
|
+
expect(result.data.is_expired).toBe("true");
|
|
144
|
+
expect(result.data.expired_at).toBe("2021-06-01");
|
|
145
|
+
});
|
|
146
|
+
it("should preserve all original authentication fields", async () => {
|
|
147
|
+
const authWithAllFields = {
|
|
148
|
+
id: 123,
|
|
149
|
+
date: "2021-01-01",
|
|
150
|
+
lastchanged: "2021-01-02",
|
|
151
|
+
account_id: 456,
|
|
152
|
+
customuser_id: 789,
|
|
153
|
+
selected_api: "SlackCLIAPI@1.21.1",
|
|
154
|
+
destination_selected_api: "SlackDestAPI@1.0.0",
|
|
155
|
+
is_invite_only: true,
|
|
156
|
+
is_private: true,
|
|
157
|
+
shared_with_all: false,
|
|
158
|
+
is_stale: "true",
|
|
159
|
+
is_shared: "false",
|
|
160
|
+
marked_stale_at: "2021-06-01",
|
|
161
|
+
label: "Auth Label",
|
|
162
|
+
title: "Auth Title",
|
|
163
|
+
identifier: "auth-identifier",
|
|
164
|
+
url: "https://example.com",
|
|
165
|
+
groups: "group1,group2",
|
|
166
|
+
members: "user1,user2",
|
|
167
|
+
permissions: { read: true, write: false },
|
|
168
|
+
};
|
|
169
|
+
mockApiClient.get = vi.fn().mockResolvedValue(authWithAllFields);
|
|
170
|
+
const sdk = createTestSdk();
|
|
171
|
+
const result = await sdk.getAuthentication({ authenticationId: 123 });
|
|
172
|
+
const auth = result.data;
|
|
173
|
+
// Verify original fields are preserved
|
|
174
|
+
expect(auth.id).toBe(123);
|
|
175
|
+
expect(auth.date).toBe("2021-01-01");
|
|
176
|
+
expect(auth.lastchanged).toBe("2021-01-02");
|
|
177
|
+
expect(auth.account_id).toBe(456);
|
|
178
|
+
expect(auth.user_id).toBe(789);
|
|
179
|
+
expect(auth.implementation_id).toBe("SlackCLIAPI@1.21.1");
|
|
180
|
+
expect(auth.destination_selected_api).toBe("SlackDestAPI@1.0.0");
|
|
181
|
+
expect(auth.is_invite_only).toBe(true);
|
|
182
|
+
expect(auth.is_private).toBe(true);
|
|
183
|
+
expect(auth.shared_with_all).toBe(false);
|
|
184
|
+
expect(auth.is_shared).toBe("false");
|
|
185
|
+
expect(auth.label).toBe("Auth Label");
|
|
186
|
+
expect(auth.title).toBe("Auth Title");
|
|
187
|
+
expect(auth.identifier).toBe("auth-identifier");
|
|
188
|
+
expect(auth.url).toBe("https://example.com");
|
|
189
|
+
expect(auth.groups).toBe("group1,group2");
|
|
190
|
+
expect(auth.members).toBe("user1,user2");
|
|
191
|
+
expect(auth.permissions).toEqual({ read: true, write: false });
|
|
192
|
+
// Verify mapped fields
|
|
193
|
+
expect(auth.is_expired).toBe("true");
|
|
194
|
+
expect(auth.expired_at).toBe("2021-06-01");
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
describe("context and metadata", () => {
|
|
198
|
+
it("should provide context with meta information", () => {
|
|
199
|
+
const sdk = createTestSdk();
|
|
200
|
+
const context = sdk.getContext();
|
|
201
|
+
expect(context.meta.getAuthentication).toBeDefined();
|
|
202
|
+
expect(context.meta.getAuthentication.inputSchema).toBeDefined();
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { AuthenticationItem } from "../../types/domain";
|
|
3
|
+
export declare const GetAuthenticationSchema: z.ZodObject<{
|
|
4
|
+
authenticationId: z.ZodNumber;
|
|
5
|
+
}, "strip", z.ZodTypeAny, {
|
|
6
|
+
authenticationId: number;
|
|
7
|
+
}, {
|
|
8
|
+
authenticationId: number;
|
|
9
|
+
}>;
|
|
10
|
+
export type GetAuthenticationOptions = z.infer<typeof GetAuthenticationSchema>;
|
|
11
|
+
export type GetAuthenticationError = import("../../types/errors").ZapierAuthenticationError | import("../../types/errors").ZapierResourceNotFoundError | import("../../types/errors").ZapierApiError | import("../../types/errors").ZapierValidationError | import("../../types/errors").ZapierUnknownError;
|
|
12
|
+
export interface GetAuthenticationSdkFunction {
|
|
13
|
+
getAuthentication: (options: GetAuthenticationOptions) => Promise<{
|
|
14
|
+
data: AuthenticationItem;
|
|
15
|
+
}>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=schemas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../src/plugins/getAuthentication/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAG7D,eAAO,MAAM,uBAAuB;;;;;;EAQc,CAAC;AAGnD,MAAM,MAAM,wBAAwB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAG/E,MAAM,MAAM,sBAAsB,GAC9B,OAAO,oBAAoB,EAAE,yBAAyB,GACtD,OAAO,oBAAoB,EAAE,2BAA2B,GACxD,OAAO,oBAAoB,EAAE,cAAc,GAC3C,OAAO,oBAAoB,EAAE,qBAAqB,GAClD,OAAO,oBAAoB,EAAE,kBAAkB,CAAC;AAGpD,MAAM,WAAW,4BAA4B;IAC3C,iBAAiB,EAAE,CACjB,OAAO,EAAE,wBAAwB,KAC9B,OAAO,CAAC;QAAE,IAAI,EAAE,kBAAkB,CAAA;KAAE,CAAC,CAAC;CAC5C"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
// Pure Zod schema - no resolver metadata!
|
|
3
|
+
export const GetAuthenticationSchema = z
|
|
4
|
+
.object({
|
|
5
|
+
authenticationId: z
|
|
6
|
+
.number()
|
|
7
|
+
.int()
|
|
8
|
+
.positive()
|
|
9
|
+
.describe("Authentication ID to retrieve"),
|
|
10
|
+
})
|
|
11
|
+
.describe("Get a specific authentication by ID");
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { GetProfileOptions } from "./schemas";
|
|
2
|
+
import type { ApiClient } from "../../api/types";
|
|
3
|
+
import type { Plugin } from "../../types/plugin";
|
|
4
|
+
import type { UserProfileItem } from "../../types/domain";
|
|
5
|
+
import { GetProfileSchema } from "./schemas";
|
|
6
|
+
export interface GetProfilePluginProvides {
|
|
7
|
+
getProfile: (options?: GetProfileOptions) => Promise<{
|
|
8
|
+
data: UserProfileItem;
|
|
9
|
+
}>;
|
|
10
|
+
context: {
|
|
11
|
+
meta: {
|
|
12
|
+
getProfile: {
|
|
13
|
+
inputSchema: typeof GetProfileSchema;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export declare const getProfilePlugin: Plugin<{}, // no SDK dependencies
|
|
19
|
+
{
|
|
20
|
+
api: ApiClient;
|
|
21
|
+
}, // requires api in context
|
|
22
|
+
GetProfilePluginProvides>;
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/getProfile/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,KAAK,EAAe,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE9D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAG7C,MAAM,WAAW,wBAAwB;IACvC,UAAU,EAAE,CACV,OAAO,CAAC,EAAE,iBAAiB,KACxB,OAAO,CAAC;QAAE,IAAI,EAAE,eAAe,CAAA;KAAE,CAAC,CAAC;IACxC,OAAO,EAAE;QACP,IAAI,EAAE;YACJ,UAAU,EAAE;gBACV,WAAW,EAAE,OAAO,gBAAgB,CAAC;aACtC,CAAC;SACH,CAAC;KACH,CAAC;CACH;AAGD,eAAO,MAAM,gBAAgB,EAAE,MAAM,CACnC,EAAE,EAAE,sBAAsB;AAC1B;IAAE,GAAG,EAAE,SAAS,CAAA;CAAE,EAAE,0BAA0B;AAC9C,wBAAwB,CA6BzB,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { createFunction } from "../../utils/function-utils";
|
|
2
|
+
import { GetProfileSchema } from "./schemas";
|
|
3
|
+
// Direct plugin function - takes options + sdk + context in one object
|
|
4
|
+
export const getProfilePlugin = ({ context }) => {
|
|
5
|
+
const getProfile = createFunction(async function getProfile() {
|
|
6
|
+
const profile = await context.api.get("/api/v4/profile/", {
|
|
7
|
+
authRequired: true,
|
|
8
|
+
});
|
|
9
|
+
// Remove user_id since that's our internal user ID which could confuse things!
|
|
10
|
+
const { user_id: _unusedUserId, ...data } = profile;
|
|
11
|
+
return {
|
|
12
|
+
data: {
|
|
13
|
+
...data, // Pass through all API response fields
|
|
14
|
+
full_name: `${profile.first_name} ${profile.last_name}`, // Computed field
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
}, GetProfileSchema);
|
|
18
|
+
// Return flat structure - getProfile goes directly to SDK
|
|
19
|
+
return {
|
|
20
|
+
getProfile,
|
|
21
|
+
context: {
|
|
22
|
+
meta: {
|
|
23
|
+
getProfile: {
|
|
24
|
+
inputSchema: GetProfileSchema,
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { FunctionOptions } from "../../types/functions";
|
|
3
|
+
import type { UserProfileItem } from "../../types/domain";
|
|
4
|
+
import { ZapierApiError, ZapierValidationError } from "../../types/errors";
|
|
5
|
+
export type GetProfileError = ZapierApiError | ZapierValidationError;
|
|
6
|
+
export declare const GetProfileSchema: z.ZodOptional<z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>>;
|
|
7
|
+
export type GetProfileOptions = z.infer<typeof GetProfileSchema> & FunctionOptions;
|
|
8
|
+
export interface GetProfileSdkFunction {
|
|
9
|
+
getProfile: (options?: GetProfileOptions) => Promise<{
|
|
10
|
+
data: UserProfileItem;
|
|
11
|
+
}>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=schemas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../src/plugins/getProfile/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAG3E,MAAM,MAAM,eAAe,GAAG,cAAc,GAAG,qBAAqB,CAAC;AAGrE,eAAO,MAAM,gBAAgB,+DAG5B,CAAC;AAGF,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,GAC9D,eAAe,CAAC;AAGlB,MAAM,WAAW,qBAAqB;IACpC,UAAU,EAAE,CACV,OAAO,CAAC,EAAE,iBAAiB,KACxB,OAAO,CAAC;QAAE,IAAI,EAAE,eAAe,CAAA;KAAE,CAAC,CAAC;CACzC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { withOutputSchema } from "../../utils/schema-utils";
|
|
3
|
+
import { UserProfileItemSchema } from "../../schemas/UserProfile";
|
|
4
|
+
// Pure Zod schema - no resolver metadata!
|
|
5
|
+
export const GetProfileSchema = withOutputSchema(z.object({}).optional().describe("Get current user's profile information"), UserProfileItemSchema);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Plugin, GetSdkType } from "../../types/plugin";
|
|
2
|
+
import type { ApiClient } from "../../api";
|
|
3
|
+
import type { ActionItem } from "../../types/domain";
|
|
4
|
+
import { ListActionsSchema, type ListActionsOptions } from "./schemas";
|
|
5
|
+
import type { GetAppPluginProvides } from "../getApp";
|
|
6
|
+
export interface ListActionsPluginProvides {
|
|
7
|
+
listActions: (options?: ListActionsOptions) => Promise<{
|
|
8
|
+
data: ActionItem[];
|
|
9
|
+
}> & AsyncIterable<{
|
|
10
|
+
data: ActionItem[];
|
|
11
|
+
nextCursor?: string;
|
|
12
|
+
}> & {
|
|
13
|
+
items(): AsyncIterable<ActionItem>;
|
|
14
|
+
};
|
|
15
|
+
context: {
|
|
16
|
+
meta: {
|
|
17
|
+
listActions: {
|
|
18
|
+
inputSchema: typeof ListActionsSchema;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export declare const listActionsPlugin: Plugin<GetSdkType<GetAppPluginProvides>, // requires getApp in SDK
|
|
24
|
+
{
|
|
25
|
+
api: ApiClient;
|
|
26
|
+
}, // requires api in context
|
|
27
|
+
ListActionsPluginProvides>;
|
|
28
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/listActions/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD,OAAO,EACL,iBAAiB,EACjB,KAAK,kBAAkB,EAExB,MAAM,WAAW,CAAC;AAMnB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAEtD,MAAM,WAAW,yBAAyB;IACxC,WAAW,EAAE,CAAC,OAAO,CAAC,EAAE,kBAAkB,KAAK,OAAO,CAAC;QACrD,IAAI,EAAE,UAAU,EAAE,CAAC;KACpB,CAAC,GACA,aAAa,CAAC;QAAE,IAAI,EAAE,UAAU,EAAE,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG;QAC3D,KAAK,IAAI,aAAa,CAAC,UAAU,CAAC,CAAC;KACpC,CAAC;IACJ,OAAO,EAAE;QACP,IAAI,EAAE;YACJ,WAAW,EAAE;gBACX,WAAW,EAAE,OAAO,iBAAiB,CAAC;aACvC,CAAC;SACH,CAAC;KACH,CAAC;CACH;AAED,eAAO,MAAM,iBAAiB,EAAE,MAAM,CACpC,UAAU,CAAC,oBAAoB,CAAC,EAAE,yBAAyB;AAC3D;IAAE,GAAG,EAAE,SAAS,CAAA;CAAE,EAAE,0BAA0B;AAC9C,yBAAyB,CA+E1B,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { normalizeActionItem } from "../../utils/domain-utils";
|
|
2
|
+
import { ListActionsSchema, } from "./schemas";
|
|
3
|
+
import { ZapierConfigurationError, ZapierAuthenticationError, } from "../../types/errors";
|
|
4
|
+
import { createPaginatedFunction } from "../../utils/function-utils";
|
|
5
|
+
export const listActionsPlugin = ({ sdk, context }) => {
|
|
6
|
+
const listActions = createPaginatedFunction(async function listActionsPage(options) {
|
|
7
|
+
const { api } = context;
|
|
8
|
+
// Use the getApp function from the SDK (dependency injection)
|
|
9
|
+
const app = await sdk.getApp({ appKey: options.appKey });
|
|
10
|
+
const implementationId = app.data.current_implementation_id?.split("@")[0];
|
|
11
|
+
if (!implementationId) {
|
|
12
|
+
throw new ZapierConfigurationError("No current_implementation_id found for app", { configType: "current_implementation_id" });
|
|
13
|
+
}
|
|
14
|
+
const searchParams = {
|
|
15
|
+
global: "true",
|
|
16
|
+
public_only: "true",
|
|
17
|
+
selected_apis: implementationId,
|
|
18
|
+
};
|
|
19
|
+
const data = await api.get("/api/v4/implementations/", {
|
|
20
|
+
searchParams,
|
|
21
|
+
customErrorHandler: ({ status }) => {
|
|
22
|
+
if (status === 401) {
|
|
23
|
+
return new ZapierAuthenticationError(`Authentication failed. Your token may not have permission to access implementations or may be expired. (HTTP ${status})`, { statusCode: status });
|
|
24
|
+
}
|
|
25
|
+
if (status === 403) {
|
|
26
|
+
return new ZapierAuthenticationError(`Access forbidden. Your token may not have the required scopes to list implementations. (HTTP ${status})`, { statusCode: status });
|
|
27
|
+
}
|
|
28
|
+
return undefined;
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
let allActions = [];
|
|
32
|
+
for (const implementation of data.results || []) {
|
|
33
|
+
if (implementation.actions) {
|
|
34
|
+
for (const action of implementation.actions) {
|
|
35
|
+
const actionWithContext = {
|
|
36
|
+
...action,
|
|
37
|
+
selected_api: action.selected_api || implementation.selected_api,
|
|
38
|
+
};
|
|
39
|
+
allActions.push(normalizeActionItem(actionWithContext));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (options.actionType) {
|
|
44
|
+
allActions = allActions.filter((action) => action.action_type === options.actionType);
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
data: allActions,
|
|
48
|
+
nextCursor: undefined,
|
|
49
|
+
};
|
|
50
|
+
}, ListActionsSchema);
|
|
51
|
+
return {
|
|
52
|
+
listActions,
|
|
53
|
+
context: {
|
|
54
|
+
meta: {
|
|
55
|
+
listActions: {
|
|
56
|
+
inputSchema: ListActionsSchema,
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../../src/plugins/listActions/index.test.ts"],"names":[],"mappings":""}
|