@zapier/zapier-sdk 0.4.1 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/README.md +343 -0
- package/dist/api/auth.d.ts +9 -0
- package/dist/api/auth.d.ts.map +1 -0
- package/dist/api/auth.js +25 -0
- package/dist/api/client.d.ts +9 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/client.js +322 -0
- package/dist/api/debug.d.ts +13 -0
- package/dist/api/debug.d.ts.map +1 -0
- package/dist/api/debug.js +55 -0
- package/dist/api/index.d.ts +29 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +41 -0
- package/dist/api/polling.d.ts +16 -0
- package/dist/api/polling.d.ts.map +1 -0
- package/dist/api/polling.js +45 -0
- package/dist/api/schemas.d.ts +2473 -0
- package/dist/api/schemas.d.ts.map +1 -0
- package/dist/api/schemas.js +355 -0
- package/dist/api/types.d.ts +75 -0
- package/dist/api/types.d.ts.map +1 -0
- package/dist/api/types.js +11 -0
- package/dist/auth.d.ts +34 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +47 -0
- package/dist/constants.d.ts +10 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +9 -0
- package/dist/index.cjs +2108 -1379
- package/dist/index.d.mts +2440 -620
- package/dist/index.d.ts +17 -892
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.mjs +2093 -1362
- package/dist/plugins/api/index.d.ts +14 -0
- package/dist/plugins/api/index.d.ts.map +1 -0
- package/dist/plugins/api/index.js +21 -0
- package/dist/plugins/apps/index.d.ts +11 -0
- package/dist/plugins/apps/index.d.ts.map +1 -0
- package/dist/plugins/apps/index.js +91 -0
- package/dist/plugins/apps/types.d.ts +30 -0
- package/dist/plugins/apps/types.d.ts.map +1 -0
- package/dist/plugins/apps/types.js +2 -0
- package/dist/plugins/fetch/index.d.ts +21 -0
- package/dist/plugins/fetch/index.d.ts.map +1 -0
- package/dist/plugins/fetch/index.js +20 -0
- package/dist/plugins/findFirstAuthentication/index.d.ts +20 -0
- package/dist/plugins/findFirstAuthentication/index.d.ts.map +1 -0
- package/dist/plugins/findFirstAuthentication/index.js +24 -0
- package/dist/plugins/findFirstAuthentication/index.test.d.ts +2 -0
- package/dist/plugins/findFirstAuthentication/index.test.d.ts.map +1 -0
- package/dist/plugins/findFirstAuthentication/index.test.js +171 -0
- package/dist/plugins/findFirstAuthentication/schemas.d.ts +29 -0
- package/dist/plugins/findFirstAuthentication/schemas.d.ts.map +1 -0
- package/dist/plugins/findFirstAuthentication/schemas.js +18 -0
- package/dist/plugins/findUniqueAuthentication/index.d.ts +20 -0
- package/dist/plugins/findUniqueAuthentication/index.d.ts.map +1 -0
- package/dist/plugins/findUniqueAuthentication/index.js +31 -0
- package/dist/plugins/findUniqueAuthentication/index.test.d.ts +2 -0
- package/dist/plugins/findUniqueAuthentication/index.test.d.ts.map +1 -0
- package/dist/plugins/findUniqueAuthentication/index.test.js +152 -0
- package/dist/plugins/findUniqueAuthentication/schemas.d.ts +29 -0
- package/dist/plugins/findUniqueAuthentication/schemas.d.ts.map +1 -0
- package/dist/plugins/findUniqueAuthentication/schemas.js +18 -0
- package/dist/plugins/getAction/index.d.ts +23 -0
- package/dist/plugins/getAction/index.d.ts.map +1 -0
- package/dist/plugins/getAction/index.js +28 -0
- package/dist/plugins/getAction/index.test.d.ts +2 -0
- package/dist/plugins/getAction/index.test.d.ts.map +1 -0
- package/dist/plugins/getAction/index.test.js +186 -0
- package/dist/plugins/getAction/schemas.d.ts +23 -0
- package/dist/plugins/getAction/schemas.d.ts.map +1 -0
- package/dist/plugins/getAction/schemas.js +10 -0
- package/dist/plugins/getApp/index.d.ts +22 -0
- package/dist/plugins/getApp/index.d.ts.map +1 -0
- package/dist/plugins/getApp/index.js +39 -0
- package/dist/plugins/getApp/index.test.d.ts +2 -0
- package/dist/plugins/getApp/index.test.d.ts.map +1 -0
- package/dist/plugins/getApp/index.test.js +100 -0
- package/dist/plugins/getApp/schemas.d.ts +18 -0
- package/dist/plugins/getApp/schemas.d.ts.map +1 -0
- package/dist/plugins/getApp/schemas.js +10 -0
- package/dist/plugins/getAuthentication/index.d.ts +22 -0
- package/dist/plugins/getAuthentication/index.d.ts.map +1 -0
- package/dist/plugins/getAuthentication/index.js +41 -0
- package/dist/plugins/getAuthentication/index.test.d.ts +2 -0
- package/dist/plugins/getAuthentication/index.test.d.ts.map +1 -0
- package/dist/plugins/getAuthentication/index.test.js +205 -0
- package/dist/plugins/getAuthentication/schemas.d.ts +17 -0
- package/dist/plugins/getAuthentication/schemas.d.ts.map +1 -0
- package/dist/plugins/getAuthentication/schemas.js +11 -0
- package/dist/plugins/getProfile/index.d.ts +23 -0
- package/dist/plugins/getProfile/index.d.ts.map +1 -0
- package/dist/plugins/getProfile/index.js +29 -0
- package/dist/plugins/getProfile/schemas.d.ts +13 -0
- package/dist/plugins/getProfile/schemas.d.ts.map +1 -0
- package/dist/plugins/getProfile/schemas.js +5 -0
- package/dist/plugins/listActions/index.d.ts +28 -0
- package/dist/plugins/listActions/index.d.ts.map +1 -0
- package/dist/plugins/listActions/index.js +61 -0
- package/dist/plugins/listActions/index.test.d.ts +2 -0
- package/dist/plugins/listActions/index.test.d.ts.map +1 -0
- package/dist/plugins/listActions/index.test.js +467 -0
- package/dist/plugins/listActions/schemas.d.ts +29 -0
- package/dist/plugins/listActions/schemas.d.ts.map +1 -0
- package/dist/plugins/listActions/schemas.js +21 -0
- package/dist/plugins/listApps/index.d.ts +28 -0
- package/dist/plugins/listApps/index.d.ts.map +1 -0
- package/dist/plugins/listApps/index.js +62 -0
- package/dist/plugins/listApps/index.test.d.ts +2 -0
- package/dist/plugins/listApps/index.test.d.ts.map +1 -0
- package/dist/plugins/listApps/index.test.js +313 -0
- package/dist/plugins/listApps/schemas.d.ts +30 -0
- package/dist/plugins/listApps/schemas.d.ts.map +1 -0
- package/dist/plugins/listApps/schemas.js +23 -0
- package/dist/plugins/listAuthentications/index.d.ts +28 -0
- package/dist/plugins/listAuthentications/index.d.ts.map +1 -0
- package/dist/plugins/listAuthentications/index.js +77 -0
- package/dist/plugins/listAuthentications/index.test.d.ts +2 -0
- package/dist/plugins/listAuthentications/index.test.d.ts.map +1 -0
- package/dist/plugins/listAuthentications/index.test.js +564 -0
- package/dist/plugins/listAuthentications/schemas.d.ts +38 -0
- package/dist/plugins/listAuthentications/schemas.d.ts.map +1 -0
- package/dist/plugins/listAuthentications/schemas.js +28 -0
- package/dist/plugins/listInputFields/index.d.ts +28 -0
- package/dist/plugins/listInputFields/index.d.ts.map +1 -0
- package/dist/plugins/listInputFields/index.js +133 -0
- package/dist/plugins/listInputFields/index.test.d.ts +2 -0
- package/dist/plugins/listInputFields/index.test.d.ts.map +1 -0
- package/dist/plugins/listInputFields/index.test.js +325 -0
- package/dist/plugins/listInputFields/schemas.d.ts +38 -0
- package/dist/plugins/listInputFields/schemas.d.ts.map +1 -0
- package/dist/plugins/listInputFields/schemas.js +22 -0
- package/dist/plugins/registry/index.d.ts +11 -0
- package/dist/plugins/registry/index.d.ts.map +1 -0
- package/dist/plugins/registry/index.js +14 -0
- package/dist/plugins/request/index.d.ts +19 -0
- package/dist/plugins/request/index.d.ts.map +1 -0
- package/dist/plugins/request/index.js +62 -0
- package/dist/plugins/request/index.test.d.ts +2 -0
- package/dist/plugins/request/index.test.d.ts.map +1 -0
- package/dist/plugins/request/index.test.js +256 -0
- package/dist/plugins/request/schemas.d.ts +69 -0
- package/dist/plugins/request/schemas.d.ts.map +1 -0
- package/dist/plugins/request/schemas.js +42 -0
- package/dist/plugins/runAction/index.d.ts +28 -0
- package/dist/plugins/runAction/index.d.ts.map +1 -0
- package/dist/plugins/runAction/index.js +86 -0
- package/dist/plugins/runAction/index.test.d.ts +2 -0
- package/dist/plugins/runAction/index.test.d.ts.map +1 -0
- package/dist/plugins/runAction/index.test.js +320 -0
- package/dist/plugins/runAction/schemas.d.ts +37 -0
- package/dist/plugins/runAction/schemas.d.ts.map +1 -0
- package/dist/plugins/runAction/schemas.js +22 -0
- package/dist/resolvers/actionKey.d.ts +9 -0
- package/dist/resolvers/actionKey.d.ts.map +1 -0
- package/dist/resolvers/actionKey.js +19 -0
- package/dist/resolvers/actionType.d.ts +9 -0
- package/dist/resolvers/actionType.d.ts.map +1 -0
- package/dist/resolvers/actionType.js +22 -0
- package/dist/resolvers/appKey.d.ts +7 -0
- package/dist/resolvers/appKey.d.ts.map +1 -0
- package/dist/resolvers/appKey.js +5 -0
- package/dist/resolvers/authenticationId.d.ts +9 -0
- package/dist/resolvers/authenticationId.d.ts.map +1 -0
- package/dist/resolvers/authenticationId.js +33 -0
- package/dist/resolvers/index.d.ts +40 -0
- package/dist/resolvers/index.d.ts.map +1 -0
- package/dist/resolvers/index.js +91 -0
- package/dist/resolvers/inputs.d.ts +8 -0
- package/dist/resolvers/inputs.d.ts.map +1 -0
- package/dist/resolvers/inputs.js +14 -0
- package/dist/schemas/Action.d.ts +243 -0
- package/dist/schemas/Action.d.ts.map +1 -0
- package/dist/schemas/Action.js +34 -0
- package/dist/schemas/App.d.ts +26 -0
- package/dist/schemas/App.d.ts.map +1 -0
- package/dist/schemas/App.js +22 -0
- package/dist/schemas/Auth.d.ts +161 -0
- package/dist/schemas/Auth.d.ts.map +1 -0
- package/dist/schemas/Auth.js +41 -0
- package/dist/schemas/Field.d.ts +144 -0
- package/dist/schemas/Field.d.ts.map +1 -0
- package/dist/schemas/Field.js +105 -0
- package/dist/schemas/UserProfile.d.ts +163 -0
- package/dist/schemas/UserProfile.d.ts.map +1 -0
- package/dist/schemas/UserProfile.js +29 -0
- package/dist/sdk.d.ts +10 -0
- package/dist/sdk.d.ts.map +1 -0
- package/dist/sdk.js +94 -0
- package/dist/sdk.test.d.ts +2 -0
- package/dist/sdk.test.d.ts.map +1 -0
- package/dist/sdk.test.js +135 -0
- package/dist/types/domain.d.ts +36 -0
- package/dist/types/domain.d.ts.map +1 -0
- package/dist/types/domain.js +1 -0
- package/dist/types/domain.test.d.ts +2 -0
- package/dist/types/domain.test.d.ts.map +1 -0
- package/dist/types/domain.test.js +39 -0
- package/dist/types/errors.d.ts +143 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/errors.js +187 -0
- package/dist/types/events.d.ts +38 -0
- package/dist/types/events.d.ts.map +1 -0
- package/dist/types/events.js +7 -0
- package/dist/types/functions.d.ts +26 -0
- package/dist/types/functions.d.ts.map +1 -0
- package/dist/types/functions.js +4 -0
- package/dist/types/plugin.d.ts +61 -0
- package/dist/types/plugin.d.ts.map +1 -0
- package/dist/types/plugin.js +9 -0
- package/dist/types/properties.d.ts +22 -0
- package/dist/types/properties.d.ts.map +1 -0
- package/dist/types/properties.js +50 -0
- package/dist/types/sdk.d.ts +43 -0
- package/dist/types/sdk.d.ts.map +1 -0
- package/dist/types/sdk.js +4 -0
- package/dist/utils/array-utils.d.ts +31 -0
- package/dist/utils/array-utils.d.ts.map +1 -0
- package/dist/utils/array-utils.js +36 -0
- package/dist/utils/array-utils.test.d.ts +2 -0
- package/dist/utils/array-utils.test.d.ts.map +1 -0
- package/dist/utils/array-utils.test.js +107 -0
- package/dist/utils/domain-utils.d.ts +78 -0
- package/dist/utils/domain-utils.d.ts.map +1 -0
- package/dist/utils/domain-utils.js +218 -0
- package/dist/utils/domain-utils.test.d.ts +2 -0
- package/dist/utils/domain-utils.test.d.ts.map +1 -0
- package/dist/utils/domain-utils.test.js +192 -0
- package/dist/utils/function-utils.d.ts +45 -0
- package/dist/utils/function-utils.d.ts.map +1 -0
- package/dist/utils/function-utils.js +158 -0
- package/dist/utils/function-utils.test.d.ts +2 -0
- package/dist/utils/function-utils.test.d.ts.map +1 -0
- package/dist/utils/function-utils.test.js +110 -0
- package/dist/utils/pagination-utils.d.ts +37 -0
- package/dist/utils/pagination-utils.d.ts.map +1 -0
- package/dist/utils/pagination-utils.js +165 -0
- package/dist/utils/pagination-utils.test.d.ts +17 -0
- package/dist/utils/pagination-utils.test.d.ts.map +1 -0
- package/dist/utils/pagination-utils.test.js +461 -0
- package/dist/utils/schema-utils.d.ts +45 -0
- package/dist/utils/schema-utils.d.ts.map +1 -0
- package/dist/utils/schema-utils.js +65 -0
- package/dist/utils/validation.d.ts +4 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +30 -0
- package/dist/utils/validation.test.d.ts +2 -0
- package/dist/utils/validation.test.d.ts.map +1 -0
- package/dist/utils/validation.test.js +43 -0
- package/package.json +12 -3
- package/src/api/client.ts +394 -171
- package/src/api/debug.ts +10 -1
- package/src/api/index.ts +0 -2
- package/src/api/polling.ts +28 -7
- package/src/api/schemas.ts +387 -0
- package/src/api/types.ts +72 -136
- package/src/constants.ts +10 -0
- package/src/index.ts +40 -19
- package/src/plugins/api/index.ts +47 -0
- package/src/plugins/apps/index.ts +25 -19
- package/src/plugins/apps/types.ts +7 -11
- package/src/plugins/fetch/index.ts +48 -40
- package/src/plugins/findFirstAuthentication/index.test.ts +206 -0
- package/src/plugins/findFirstAuthentication/index.ts +55 -0
- package/src/plugins/findFirstAuthentication/schemas.ts +41 -0
- package/src/plugins/findUniqueAuthentication/index.test.ts +197 -0
- package/src/plugins/findUniqueAuthentication/index.ts +72 -0
- package/src/plugins/findUniqueAuthentication/schemas.ts +42 -0
- package/src/plugins/getAction/index.test.ts +239 -0
- package/src/plugins/getAction/index.ts +57 -0
- package/src/plugins/getAction/schemas.ts +33 -0
- package/src/plugins/getApp/index.test.ts +127 -0
- package/src/plugins/getApp/index.ts +66 -0
- package/src/plugins/getApp/schemas.ts +38 -0
- package/src/plugins/getAuthentication/index.test.ts +284 -0
- package/src/plugins/getAuthentication/index.ts +86 -0
- package/src/plugins/getAuthentication/schemas.ts +31 -0
- package/src/plugins/getProfile/index.ts +55 -0
- package/src/plugins/getProfile/schemas.ts +26 -0
- package/src/plugins/listActions/index.test.ts +582 -0
- package/src/plugins/listActions/index.ts +115 -0
- package/src/plugins/listActions/schemas.ts +54 -0
- package/src/plugins/listApps/index.test.ts +357 -0
- package/src/plugins/listApps/index.ts +121 -0
- package/src/plugins/listApps/schemas.ts +49 -0
- package/src/plugins/listAuthentications/index.test.ts +709 -0
- package/src/plugins/listAuthentications/index.ts +136 -0
- package/src/plugins/listAuthentications/schemas.ts +60 -0
- package/src/plugins/listInputFields/index.test.ts +408 -0
- package/src/plugins/listInputFields/index.ts +204 -0
- package/src/plugins/listInputFields/schemas.ts +56 -0
- package/src/plugins/registry/index.ts +30 -0
- package/src/plugins/request/index.test.ts +329 -0
- package/src/plugins/request/index.ts +103 -0
- package/src/{functions → plugins}/request/schemas.ts +20 -9
- package/src/plugins/runAction/index.test.ts +387 -0
- package/src/plugins/runAction/index.ts +176 -0
- package/src/plugins/runAction/schemas.ts +53 -0
- package/src/resolvers/actionKey.ts +6 -4
- package/src/resolvers/actionType.ts +7 -2
- package/src/resolvers/appKey.ts +1 -1
- package/src/resolvers/authenticationId.ts +12 -3
- package/src/resolvers/inputs.ts +3 -1
- package/src/schemas/Action.ts +18 -12
- package/src/schemas/App.ts +11 -19
- package/src/schemas/Auth.ts +18 -13
- package/src/schemas/Field.ts +106 -11
- package/src/schemas/UserProfile.ts +43 -0
- package/src/sdk.test.ts +212 -0
- package/src/sdk.ts +132 -102
- package/src/types/domain.test.ts +50 -0
- package/src/types/domain.ts +43 -75
- package/src/types/errors.ts +275 -0
- package/src/types/functions.ts +27 -0
- package/src/types/optional-zapier-sdk-cli-login.d.ts +37 -0
- package/src/types/plugin.ts +105 -0
- package/src/types/properties.ts +4 -3
- package/src/types/sdk.ts +70 -48
- package/src/utils/array-utils.test.ts +131 -0
- package/src/utils/array-utils.ts +41 -0
- package/src/utils/domain-utils.test.ts +239 -0
- package/src/utils/domain-utils.ts +283 -0
- package/src/utils/function-utils.test.ts +141 -0
- package/src/utils/function-utils.ts +245 -0
- package/src/utils/pagination-utils.test.ts +620 -0
- package/src/utils/pagination-utils.ts +242 -0
- package/src/utils/validation.test.ts +50 -0
- package/src/utils/validation.ts +44 -0
- package/tsconfig.build.json +16 -2
- package/tsconfig.json +3 -1
- package/tsconfig.tsbuildinfo +1 -0
- package/tsup.config.ts +2 -0
- package/src/functions/bundleCode/index.ts +0 -78
- package/src/functions/bundleCode/info.ts +0 -9
- package/src/functions/bundleCode/schemas.ts +0 -30
- package/src/functions/findFirstAuthentication/index.ts +0 -24
- package/src/functions/findFirstAuthentication/info.ts +0 -9
- package/src/functions/findFirstAuthentication/schemas.ts +0 -50
- package/src/functions/findUniqueAuthentication/index.ts +0 -35
- package/src/functions/findUniqueAuthentication/info.ts +0 -9
- package/src/functions/findUniqueAuthentication/schemas.ts +0 -50
- package/src/functions/generateTypes/index.ts +0 -363
- package/src/functions/generateTypes/info.ts +0 -9
- package/src/functions/generateTypes/schemas.ts +0 -31
- package/src/functions/getAction/index.ts +0 -33
- package/src/functions/getAction/info.ts +0 -9
- package/src/functions/getAction/schemas.ts +0 -25
- package/src/functions/getApp/index.ts +0 -41
- package/src/functions/getApp/info.ts +0 -9
- package/src/functions/getApp/schemas.ts +0 -20
- package/src/functions/getAuthentication/index.ts +0 -50
- package/src/functions/getAuthentication/info.ts +0 -9
- package/src/functions/getAuthentication/schemas.ts +0 -29
- package/src/functions/listActions/index.ts +0 -149
- package/src/functions/listActions/info.ts +0 -9
- package/src/functions/listActions/schemas.ts +0 -30
- package/src/functions/listApps/index.ts +0 -60
- package/src/functions/listApps/info.ts +0 -9
- package/src/functions/listApps/schemas.ts +0 -32
- package/src/functions/listAuthentications/index.ts +0 -162
- package/src/functions/listAuthentications/info.ts +0 -9
- package/src/functions/listAuthentications/schemas.ts +0 -50
- package/src/functions/listFields/index.ts +0 -86
- package/src/functions/listFields/info.ts +0 -9
- package/src/functions/listFields/schemas.ts +0 -36
- package/src/functions/request/index.ts +0 -150
- package/src/functions/request/info.ts +0 -11
- package/src/functions/runAction/index.ts +0 -127
- package/src/functions/runAction/info.ts +0 -9
- package/src/functions/runAction/schemas.ts +0 -34
- package/src/plugins/apps/info.ts +0 -12
- package/src/plugins/fetch/types.ts +0 -2
- /package/src/{schema-utils.ts → utils/schema-utils.ts} +0 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type { Plugin, GetSdkType } from "../../types/plugin";
|
|
2
|
+
import type { ApiClient } from "../../api";
|
|
3
|
+
import type { ActionItem } from "../../types/domain";
|
|
4
|
+
import { normalizeActionItem } from "../../utils/domain-utils";
|
|
5
|
+
import {
|
|
6
|
+
ListActionsSchema,
|
|
7
|
+
type ListActionsOptions,
|
|
8
|
+
type ListActionsPage,
|
|
9
|
+
} from "./schemas";
|
|
10
|
+
import {
|
|
11
|
+
ZapierConfigurationError,
|
|
12
|
+
ZapierAuthenticationError,
|
|
13
|
+
} from "../../types/errors";
|
|
14
|
+
import { createPaginatedFunction } from "../../utils/function-utils";
|
|
15
|
+
import type { GetAppPluginProvides } from "../getApp";
|
|
16
|
+
|
|
17
|
+
export interface ListActionsPluginProvides {
|
|
18
|
+
listActions: (options?: ListActionsOptions) => Promise<{
|
|
19
|
+
data: ActionItem[];
|
|
20
|
+
}> &
|
|
21
|
+
AsyncIterable<{ data: ActionItem[]; nextCursor?: string }> & {
|
|
22
|
+
items(): AsyncIterable<ActionItem>;
|
|
23
|
+
};
|
|
24
|
+
context: {
|
|
25
|
+
meta: {
|
|
26
|
+
listActions: {
|
|
27
|
+
inputSchema: typeof ListActionsSchema;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const listActionsPlugin: Plugin<
|
|
34
|
+
GetSdkType<GetAppPluginProvides>, // requires getApp in SDK
|
|
35
|
+
{ api: ApiClient }, // requires api in context
|
|
36
|
+
ListActionsPluginProvides
|
|
37
|
+
> = ({ sdk, context }) => {
|
|
38
|
+
const listActions = createPaginatedFunction(async function listActionsPage(
|
|
39
|
+
options: ListActionsOptions & { cursor?: string } & { pageSize: number },
|
|
40
|
+
): Promise<ListActionsPage> {
|
|
41
|
+
const { api } = context;
|
|
42
|
+
|
|
43
|
+
// Use the getApp function from the SDK (dependency injection)
|
|
44
|
+
const app = await sdk.getApp({ appKey: options.appKey });
|
|
45
|
+
|
|
46
|
+
const implementationId = app.data.current_implementation_id?.split("@")[0];
|
|
47
|
+
if (!implementationId) {
|
|
48
|
+
throw new ZapierConfigurationError(
|
|
49
|
+
"No current_implementation_id found for app",
|
|
50
|
+
{ configType: "current_implementation_id" },
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const searchParams: Record<string, string> = {
|
|
55
|
+
global: "true",
|
|
56
|
+
public_only: "true",
|
|
57
|
+
selected_apis: implementationId,
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const data = await api.get("/api/v4/implementations/", {
|
|
61
|
+
searchParams,
|
|
62
|
+
customErrorHandler: ({ status }) => {
|
|
63
|
+
if (status === 401) {
|
|
64
|
+
return new ZapierAuthenticationError(
|
|
65
|
+
`Authentication failed. Your token may not have permission to access implementations or may be expired. (HTTP ${status})`,
|
|
66
|
+
{ statusCode: status },
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
if (status === 403) {
|
|
70
|
+
return new ZapierAuthenticationError(
|
|
71
|
+
`Access forbidden. Your token may not have the required scopes to list implementations. (HTTP ${status})`,
|
|
72
|
+
{ statusCode: status },
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
return undefined;
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
let allActions: ActionItem[] = [];
|
|
80
|
+
|
|
81
|
+
for (const implementation of data.results || []) {
|
|
82
|
+
if (implementation.actions) {
|
|
83
|
+
for (const action of implementation.actions) {
|
|
84
|
+
const actionWithContext = {
|
|
85
|
+
...action,
|
|
86
|
+
selected_api: action.selected_api || implementation.selected_api,
|
|
87
|
+
};
|
|
88
|
+
allActions.push(normalizeActionItem(actionWithContext));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (options.actionType) {
|
|
94
|
+
allActions = allActions.filter(
|
|
95
|
+
(action) => action.action_type === options.actionType,
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return {
|
|
100
|
+
data: allActions,
|
|
101
|
+
nextCursor: undefined,
|
|
102
|
+
};
|
|
103
|
+
}, ListActionsSchema);
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
listActions,
|
|
107
|
+
context: {
|
|
108
|
+
meta: {
|
|
109
|
+
listActions: {
|
|
110
|
+
inputSchema: ListActionsSchema,
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import {
|
|
3
|
+
AppKeyPropertySchema,
|
|
4
|
+
ActionTypePropertySchema,
|
|
5
|
+
} from "../../types/properties";
|
|
6
|
+
import { withOutputSchema } from "../../utils/schema-utils";
|
|
7
|
+
import { ActionItemSchema } from "../../schemas/Action";
|
|
8
|
+
import type { ActionItem } from "../../types/domain";
|
|
9
|
+
import type { PaginatedSdkFunction } from "../../types/functions";
|
|
10
|
+
|
|
11
|
+
// Pure Zod schema - no resolver metadata!
|
|
12
|
+
export const ListActionsSchema = withOutputSchema(
|
|
13
|
+
z
|
|
14
|
+
.object({
|
|
15
|
+
appKey: AppKeyPropertySchema.describe(
|
|
16
|
+
"App key of actions to list (e.g., 'SlackCLIAPI')",
|
|
17
|
+
),
|
|
18
|
+
actionType: ActionTypePropertySchema.optional().describe(
|
|
19
|
+
"Filter actions by type",
|
|
20
|
+
),
|
|
21
|
+
pageSize: z
|
|
22
|
+
.number()
|
|
23
|
+
.min(1)
|
|
24
|
+
.optional()
|
|
25
|
+
.describe("Number of actions per page"),
|
|
26
|
+
maxItems: z
|
|
27
|
+
.number()
|
|
28
|
+
.min(1)
|
|
29
|
+
.optional()
|
|
30
|
+
.describe("Maximum total items to return across all pages"),
|
|
31
|
+
})
|
|
32
|
+
.describe("List all actions for a specific app"),
|
|
33
|
+
ActionItemSchema,
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
// Type inferred from schema
|
|
37
|
+
export type ListActionsOptions = z.infer<typeof ListActionsSchema>;
|
|
38
|
+
|
|
39
|
+
// Page result structure
|
|
40
|
+
export interface ListActionsPage {
|
|
41
|
+
data: ActionItem[];
|
|
42
|
+
nextCursor?: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Error union for this function
|
|
46
|
+
export type ListActionsError =
|
|
47
|
+
| import("../../types/errors").ZapierAuthenticationError
|
|
48
|
+
| import("../../types/errors").ZapierValidationError
|
|
49
|
+
| import("../../types/errors").ZapierUnknownError;
|
|
50
|
+
|
|
51
|
+
// SDK function interface
|
|
52
|
+
export interface ListActionsSdkFunction {
|
|
53
|
+
listActions: PaginatedSdkFunction<ListActionsOptions, ActionItem>;
|
|
54
|
+
}
|
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
+
import { ZapierValidationError } from "../../types/errors";
|
|
3
|
+
import { listAppsPlugin } from "./index";
|
|
4
|
+
import { createSdk } from "../../sdk";
|
|
5
|
+
import { apiPlugin } from "../api/index";
|
|
6
|
+
|
|
7
|
+
const mockAppsResponse = {
|
|
8
|
+
results: [
|
|
9
|
+
{
|
|
10
|
+
id: "SlackCLIAPI@1.0.0",
|
|
11
|
+
slug: "slack",
|
|
12
|
+
name: "Slack",
|
|
13
|
+
description: "Team communication",
|
|
14
|
+
primary_color: "#4A154B",
|
|
15
|
+
categories: ["communication"],
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
id: "GoogleSheetsCLIAPI@1.0.0",
|
|
19
|
+
slug: "google-sheets",
|
|
20
|
+
name: "Google Sheets",
|
|
21
|
+
description: "Online spreadsheets",
|
|
22
|
+
primary_color: "#34A853",
|
|
23
|
+
categories: ["productivity"],
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
meta: {
|
|
27
|
+
next_cursor: null,
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
function createTestSdk() {
|
|
32
|
+
return createSdk()
|
|
33
|
+
.addPlugin(apiPlugin, { fetch: global.fetch })
|
|
34
|
+
.addPlugin(listAppsPlugin as any);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
describe("listApps plugin", () => {
|
|
38
|
+
beforeEach(() => {
|
|
39
|
+
vi.clearAllMocks();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
describe("schema validation", () => {
|
|
43
|
+
it("should pass validation with empty options", async () => {
|
|
44
|
+
const mockServicesResponse = {
|
|
45
|
+
results: [
|
|
46
|
+
{
|
|
47
|
+
id: "slack_service_id",
|
|
48
|
+
slug: "slack",
|
|
49
|
+
name: "Slack",
|
|
50
|
+
description: "Team communication",
|
|
51
|
+
current_implementation_id: "SlackCLIAPI@1.0.0",
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
id: "sheets_service_id",
|
|
55
|
+
slug: "google-sheets",
|
|
56
|
+
name: "Google Sheets",
|
|
57
|
+
description: "Online spreadsheets",
|
|
58
|
+
current_implementation_id: "GoogleSheetsCLIAPI@1.0.0",
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
next: null,
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const sdk = createTestSdk();
|
|
65
|
+
const context = sdk.getContext();
|
|
66
|
+
// Mock the API client in context
|
|
67
|
+
(context.api as any).get = vi
|
|
68
|
+
.fn()
|
|
69
|
+
.mockResolvedValue(mockServicesResponse);
|
|
70
|
+
|
|
71
|
+
const result = await sdk.listApps({});
|
|
72
|
+
expect(result.data).toHaveLength(2);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("should handle undefined options by converting to empty object", async () => {
|
|
76
|
+
const sdk = createTestSdk();
|
|
77
|
+
const context = sdk.getContext();
|
|
78
|
+
|
|
79
|
+
// Mock the API client in context
|
|
80
|
+
(context.api as any).get = vi.fn().mockResolvedValueOnce({
|
|
81
|
+
results: [
|
|
82
|
+
{
|
|
83
|
+
id: "SlackCLIAPI@1.0.0",
|
|
84
|
+
name: "Slack",
|
|
85
|
+
description: "Team communication",
|
|
86
|
+
primary_color: "#4A154B",
|
|
87
|
+
categories: ["communication"],
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
next: null,
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const result = await sdk.listApps(undefined as any);
|
|
94
|
+
|
|
95
|
+
expect(result.data).toHaveLength(1);
|
|
96
|
+
expect(result.data[0]).toMatchObject({
|
|
97
|
+
key: "SlackCLIAPI",
|
|
98
|
+
title: "Slack",
|
|
99
|
+
});
|
|
100
|
+
expect((context.api as any).get).toHaveBeenCalledWith(
|
|
101
|
+
"/api/v4/implementations-meta/lookup/",
|
|
102
|
+
{
|
|
103
|
+
searchParams: { latest_only: "true", limit: "100" },
|
|
104
|
+
},
|
|
105
|
+
);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("should throw validation error for invalid pageSize", () => {
|
|
109
|
+
const sdk = createTestSdk();
|
|
110
|
+
expect(() => {
|
|
111
|
+
sdk.listApps({
|
|
112
|
+
pageSize: 0, // Should be >= 1
|
|
113
|
+
});
|
|
114
|
+
}).toThrow(ZapierValidationError);
|
|
115
|
+
|
|
116
|
+
expect(() => {
|
|
117
|
+
sdk.listApps({
|
|
118
|
+
pageSize: -5, // Should be >= 1
|
|
119
|
+
});
|
|
120
|
+
}).toThrow(ZapierValidationError);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it("should throw validation error for invalid maxItems", () => {
|
|
124
|
+
const sdk = createTestSdk();
|
|
125
|
+
expect(() => {
|
|
126
|
+
sdk.listApps({
|
|
127
|
+
maxItems: 0 as any, // Should be >= 1
|
|
128
|
+
});
|
|
129
|
+
}).toThrow(ZapierValidationError);
|
|
130
|
+
|
|
131
|
+
expect(() => {
|
|
132
|
+
sdk.listApps({
|
|
133
|
+
maxItems: -10 as any, // Should be >= 1
|
|
134
|
+
});
|
|
135
|
+
}).toThrow(ZapierValidationError);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it("should throw validation error for invalid appKeys type", () => {
|
|
139
|
+
const sdk = createTestSdk();
|
|
140
|
+
expect(() => {
|
|
141
|
+
sdk.listApps({
|
|
142
|
+
appKeys: 123 as any,
|
|
143
|
+
});
|
|
144
|
+
}).toThrow(ZapierValidationError);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it("should pass validation with all valid fields", async () => {
|
|
148
|
+
const sdk = createTestSdk();
|
|
149
|
+
const context = sdk.getContext();
|
|
150
|
+
|
|
151
|
+
// Mock the API client in context
|
|
152
|
+
(context.api as any).get = vi.fn().mockResolvedValueOnce({
|
|
153
|
+
results: [
|
|
154
|
+
{
|
|
155
|
+
id: "SlackCLIAPI@1.0.0",
|
|
156
|
+
name: "Slack",
|
|
157
|
+
description: "Team communication",
|
|
158
|
+
primary_color: "#4A154B",
|
|
159
|
+
categories: ["communication"],
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
id: "GitHubCLIAPI@1.0.0",
|
|
163
|
+
name: "GitHub",
|
|
164
|
+
description: "Code repository hosting",
|
|
165
|
+
primary_color: "#24292e",
|
|
166
|
+
categories: ["developer-tools"],
|
|
167
|
+
},
|
|
168
|
+
],
|
|
169
|
+
next: null,
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
const result = await sdk.listApps({
|
|
173
|
+
appKeys: ["SlackCLIAPI", "GitHubCLIAPI"],
|
|
174
|
+
pageSize: 10,
|
|
175
|
+
maxItems: 50,
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
expect(result.data).toHaveLength(2);
|
|
179
|
+
expect(result.data[0].key).toBe("SlackCLIAPI");
|
|
180
|
+
expect(result.data[1].key).toBe("GitHubCLIAPI");
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
describe("data mapping", () => {
|
|
185
|
+
it("should return essential app properties", async () => {
|
|
186
|
+
const mockServicesResponse = {
|
|
187
|
+
results: [
|
|
188
|
+
{
|
|
189
|
+
id: "slack_service_id",
|
|
190
|
+
slug: "slack",
|
|
191
|
+
name: "Slack",
|
|
192
|
+
description: "Team communication",
|
|
193
|
+
current_implementation_id: "SlackCLIAPI@1.0.0",
|
|
194
|
+
},
|
|
195
|
+
],
|
|
196
|
+
next: null,
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
const sdk = createTestSdk();
|
|
200
|
+
const context = sdk.getContext();
|
|
201
|
+
// Mock the API client in context
|
|
202
|
+
(context.api as any).get = vi
|
|
203
|
+
.fn()
|
|
204
|
+
.mockResolvedValue(mockServicesResponse);
|
|
205
|
+
|
|
206
|
+
const result = await sdk.listApps({});
|
|
207
|
+
|
|
208
|
+
expect(result.data[0]).toHaveProperty("title");
|
|
209
|
+
expect(result.data[0]).toHaveProperty("key");
|
|
210
|
+
expect(result.data[0]).toHaveProperty("current_implementation_id");
|
|
211
|
+
// Version is optional
|
|
212
|
+
expect(result.data[0]).toHaveProperty("version");
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
describe("pagination", () => {
|
|
217
|
+
it("should handle pagination with maxItems", async () => {
|
|
218
|
+
const mockServicesResponse = {
|
|
219
|
+
results: [
|
|
220
|
+
{
|
|
221
|
+
id: "slack_service_id",
|
|
222
|
+
slug: "slack",
|
|
223
|
+
name: "Slack",
|
|
224
|
+
description: "Team communication",
|
|
225
|
+
current_implementation_id: "SlackCLIAPI@1.0.0",
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
id: "sheets_service_id",
|
|
229
|
+
slug: "google-sheets",
|
|
230
|
+
name: "Google Sheets",
|
|
231
|
+
description: "Online spreadsheets",
|
|
232
|
+
current_implementation_id: "GoogleSheetsCLIAPI@1.0.0",
|
|
233
|
+
},
|
|
234
|
+
],
|
|
235
|
+
next: null,
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
const sdk = createTestSdk();
|
|
239
|
+
const context = sdk.getContext();
|
|
240
|
+
const mockGet = vi.fn().mockResolvedValue(mockServicesResponse);
|
|
241
|
+
(context.api as any).get = mockGet;
|
|
242
|
+
|
|
243
|
+
const result = await sdk.listApps({ maxItems: 5 });
|
|
244
|
+
|
|
245
|
+
// Should return all items since maxItems (5) is greater than available items (2)
|
|
246
|
+
expect(result.data).toHaveLength(2);
|
|
247
|
+
expect(mockGet).toHaveBeenCalledTimes(1);
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
it("should support async iteration over pages", async () => {
|
|
251
|
+
const sdk = createTestSdk();
|
|
252
|
+
const context = sdk.getContext();
|
|
253
|
+
const mockGet = vi
|
|
254
|
+
.fn()
|
|
255
|
+
.mockResolvedValueOnce({
|
|
256
|
+
results: [
|
|
257
|
+
{
|
|
258
|
+
id: "SlackCLIAPI@1.0.0",
|
|
259
|
+
slug: "slack",
|
|
260
|
+
name: "Slack",
|
|
261
|
+
description: "Team communication",
|
|
262
|
+
},
|
|
263
|
+
],
|
|
264
|
+
next: "https://zapier.com/api/v4/services/?offset=cursor-page-2",
|
|
265
|
+
})
|
|
266
|
+
.mockResolvedValueOnce({
|
|
267
|
+
results: [
|
|
268
|
+
{
|
|
269
|
+
id: "GoogleSheetsCLIAPI@1.0.0",
|
|
270
|
+
slug: "google-sheets",
|
|
271
|
+
name: "Google Sheets",
|
|
272
|
+
description: "Online spreadsheets",
|
|
273
|
+
},
|
|
274
|
+
],
|
|
275
|
+
next: null,
|
|
276
|
+
});
|
|
277
|
+
(context.api as any).get = mockGet;
|
|
278
|
+
|
|
279
|
+
const pages = [];
|
|
280
|
+
for await (const page of sdk.listApps({ pageSize: 1 })) {
|
|
281
|
+
pages.push(page);
|
|
282
|
+
if (pages.length >= 2) break;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
expect(pages).toHaveLength(2);
|
|
286
|
+
expect(pages[0].data).toHaveLength(1);
|
|
287
|
+
expect(pages[1].data).toHaveLength(1);
|
|
288
|
+
expect(pages[0].data[0].key).toBe("SlackCLIAPI");
|
|
289
|
+
expect(pages[1].data[0].key).toBe("GoogleSheetsCLIAPI");
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
it("should support async iteration over individual items", async () => {
|
|
293
|
+
const mockServicesResponse = {
|
|
294
|
+
results: [
|
|
295
|
+
{
|
|
296
|
+
id: "SlackCLIAPI@1.0.0",
|
|
297
|
+
slug: "slack",
|
|
298
|
+
name: "Slack",
|
|
299
|
+
description: "Team communication",
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
id: "GoogleSheetsCLIAPI@1.0.0",
|
|
303
|
+
slug: "google-sheets",
|
|
304
|
+
name: "Google Sheets",
|
|
305
|
+
description: "Online spreadsheets",
|
|
306
|
+
},
|
|
307
|
+
],
|
|
308
|
+
next: null,
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
const sdk = createTestSdk();
|
|
312
|
+
const context = sdk.getContext();
|
|
313
|
+
(context.api as any).get = vi
|
|
314
|
+
.fn()
|
|
315
|
+
.mockResolvedValue(mockServicesResponse);
|
|
316
|
+
|
|
317
|
+
const items = [];
|
|
318
|
+
for await (const item of sdk.listApps({ maxItems: 2 }).items()) {
|
|
319
|
+
items.push(item);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
expect(items).toHaveLength(2);
|
|
323
|
+
expect(items[0].key).toBe("SlackCLIAPI");
|
|
324
|
+
expect(items[1].key).toBe("GoogleSheetsCLIAPI");
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
describe("API integration", () => {
|
|
329
|
+
it("should pass appKeys filter to API", async () => {
|
|
330
|
+
const sdk = createTestSdk();
|
|
331
|
+
const context = sdk.getContext();
|
|
332
|
+
const mockGet = vi.fn().mockResolvedValue(mockAppsResponse);
|
|
333
|
+
(context.api as any).get = mockGet;
|
|
334
|
+
|
|
335
|
+
await sdk.listApps({ appKeys: ["SlackCLIAPI", "GitHubCLIAPI"] });
|
|
336
|
+
|
|
337
|
+
expect(mockGet).toHaveBeenCalledWith(
|
|
338
|
+
expect.stringContaining("implementations-meta"),
|
|
339
|
+
expect.objectContaining({
|
|
340
|
+
searchParams: expect.objectContaining({
|
|
341
|
+
selected_apis: "SlackCLIAPI,GitHubCLIAPI",
|
|
342
|
+
}),
|
|
343
|
+
}),
|
|
344
|
+
);
|
|
345
|
+
});
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
describe("plugin integration", () => {
|
|
349
|
+
it("should provide metadata in context", () => {
|
|
350
|
+
const sdk = createTestSdk();
|
|
351
|
+
const context = sdk.getContext();
|
|
352
|
+
|
|
353
|
+
expect((context.meta as any).listApps).toBeDefined();
|
|
354
|
+
expect((context.meta as any).listApps.inputSchema).toBeDefined();
|
|
355
|
+
});
|
|
356
|
+
});
|
|
357
|
+
});
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import type { Plugin } from "../../types/plugin";
|
|
2
|
+
import type { ApiClient } from "../../api/types";
|
|
3
|
+
import { createPaginatedFunction } from "../../utils/function-utils";
|
|
4
|
+
import { ListAppsSchema } from "./schemas";
|
|
5
|
+
import type { ListAppsOptions, ListAppsPage } from "./schemas";
|
|
6
|
+
import type { AppItem } from "../../types/domain";
|
|
7
|
+
import {
|
|
8
|
+
groupAppKeysByType,
|
|
9
|
+
normalizeImplementationMetaToAppItem,
|
|
10
|
+
splitVersionedKey,
|
|
11
|
+
} from "../../utils/domain-utils";
|
|
12
|
+
import { extractCursor } from "../../utils/function-utils";
|
|
13
|
+
import type { ImplementationsMetaResponse } from "../../api/types";
|
|
14
|
+
// ListApps plugin provides interface - listApps goes directly to SDK root
|
|
15
|
+
export interface ListAppsPluginProvides {
|
|
16
|
+
listApps: (options?: ListAppsOptions) => Promise<{ data: AppItem[] }> &
|
|
17
|
+
AsyncIterable<{ data: AppItem[]; nextCursor?: string }> & {
|
|
18
|
+
items(): AsyncIterable<AppItem>;
|
|
19
|
+
};
|
|
20
|
+
context: {
|
|
21
|
+
meta: {
|
|
22
|
+
listApps: {
|
|
23
|
+
inputSchema: typeof ListAppsSchema;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Direct plugin function - takes options + sdk + context in one object
|
|
30
|
+
export const listAppsPlugin: Plugin<
|
|
31
|
+
{}, // no SDK dependencies
|
|
32
|
+
{ api: ApiClient }, // requires api in context
|
|
33
|
+
ListAppsPluginProvides
|
|
34
|
+
> = ({ context }) => {
|
|
35
|
+
const listApps = createPaginatedFunction(async function listAppsPage(
|
|
36
|
+
options: ListAppsOptions & { cursor?: string } & { pageSize: number },
|
|
37
|
+
): Promise<ListAppsPage> {
|
|
38
|
+
const api = context.api;
|
|
39
|
+
const opts = options;
|
|
40
|
+
|
|
41
|
+
const appKeys = [...(opts.appKeys ?? [])].map(
|
|
42
|
+
(key) => splitVersionedKey(key)[0],
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
if (opts.search) {
|
|
46
|
+
const searchParams: Record<string, string> = {};
|
|
47
|
+
|
|
48
|
+
searchParams.term = opts.search;
|
|
49
|
+
|
|
50
|
+
const searchEnvelope: ImplementationsMetaResponse = await api.get(
|
|
51
|
+
"/api/v4/implementations-meta/search/",
|
|
52
|
+
{
|
|
53
|
+
searchParams,
|
|
54
|
+
},
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
const implementations = searchEnvelope.results.map(
|
|
58
|
+
normalizeImplementationMetaToAppItem,
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
const appKeysSet = new Set(appKeys);
|
|
62
|
+
|
|
63
|
+
for (const implementation of implementations) {
|
|
64
|
+
if (!appKeysSet.has(implementation.key)) {
|
|
65
|
+
appKeysSet.add(implementation.key);
|
|
66
|
+
appKeys.push(implementation.key);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const searchParams: Record<string, string> = {};
|
|
72
|
+
|
|
73
|
+
if (opts.pageSize) {
|
|
74
|
+
searchParams.limit = opts.pageSize.toString();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
searchParams.latest_only = "true";
|
|
78
|
+
|
|
79
|
+
if (opts.cursor) {
|
|
80
|
+
searchParams.offset = opts.cursor;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (appKeys.length > 0) {
|
|
84
|
+
const groupedAppKeys = groupAppKeysByType(appKeys);
|
|
85
|
+
|
|
86
|
+
if (groupedAppKeys.selectedApi.length > 0) {
|
|
87
|
+
searchParams.selected_apis = groupedAppKeys.selectedApi.join(",");
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (groupedAppKeys.slug.length > 0) {
|
|
91
|
+
searchParams.slugs = groupedAppKeys.slug.join(",");
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const implementationsEnvelope: ImplementationsMetaResponse = await api.get(
|
|
96
|
+
"/api/v4/implementations-meta/lookup/",
|
|
97
|
+
{
|
|
98
|
+
searchParams,
|
|
99
|
+
},
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
return {
|
|
103
|
+
data: implementationsEnvelope.results.map(
|
|
104
|
+
normalizeImplementationMetaToAppItem,
|
|
105
|
+
),
|
|
106
|
+
nextCursor: extractCursor(implementationsEnvelope),
|
|
107
|
+
};
|
|
108
|
+
}, ListAppsSchema);
|
|
109
|
+
|
|
110
|
+
// Return flat structure - listApps goes directly to SDK
|
|
111
|
+
return {
|
|
112
|
+
listApps,
|
|
113
|
+
context: {
|
|
114
|
+
meta: {
|
|
115
|
+
listApps: {
|
|
116
|
+
inputSchema: ListAppsSchema,
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { AppItem } from "../../types/domain";
|
|
3
|
+
import type { PaginatedSdkFunction } from "../../types/functions";
|
|
4
|
+
import { ZapierApiError, ZapierValidationError } from "../../types/errors";
|
|
5
|
+
import { AppItemSchema } from "../../schemas/App";
|
|
6
|
+
import { withOutputSchema } from "../../utils/schema-utils";
|
|
7
|
+
|
|
8
|
+
// Union of all possible errors for listApps
|
|
9
|
+
export type ListAppsError = ZapierApiError | ZapierValidationError;
|
|
10
|
+
|
|
11
|
+
// A page of results returned when awaiting listApps
|
|
12
|
+
export interface ListAppsPage {
|
|
13
|
+
data: AppItem[];
|
|
14
|
+
nextCursor?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Pure Zod schema - no pagination metadata exposed
|
|
18
|
+
export const ListAppsSchema = withOutputSchema(
|
|
19
|
+
z
|
|
20
|
+
.object({
|
|
21
|
+
appKeys: z
|
|
22
|
+
.array(z.string())
|
|
23
|
+
.optional()
|
|
24
|
+
.describe(
|
|
25
|
+
"Filter apps by app keys (e.g., 'SlackCLIAPI' or slug like 'github')",
|
|
26
|
+
),
|
|
27
|
+
search: z.string().optional().describe("Search for apps by name"),
|
|
28
|
+
pageSize: z
|
|
29
|
+
.number()
|
|
30
|
+
.min(1)
|
|
31
|
+
.optional()
|
|
32
|
+
.describe("Number of apps per page"),
|
|
33
|
+
maxItems: z
|
|
34
|
+
.number()
|
|
35
|
+
.min(1)
|
|
36
|
+
.optional()
|
|
37
|
+
.describe("Maximum total items to return across all pages"),
|
|
38
|
+
})
|
|
39
|
+
.describe("List all available apps with optional filtering"),
|
|
40
|
+
AppItemSchema,
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
// Type inferred from schema
|
|
44
|
+
export type ListAppsOptions = z.infer<typeof ListAppsSchema>;
|
|
45
|
+
|
|
46
|
+
// SDK function interface
|
|
47
|
+
export interface ListAppsSdkFunction {
|
|
48
|
+
listApps: PaginatedSdkFunction<ListAppsOptions | undefined, AppItem>;
|
|
49
|
+
}
|