@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
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
import { getOrCreateApiClient } from "../../api";
|
|
2
|
-
import type {
|
|
3
|
-
Authentication,
|
|
4
|
-
AuthenticationsResponse,
|
|
5
|
-
} from "../../types/domain";
|
|
6
|
-
import { getApp } from "../getApp";
|
|
7
|
-
import type { ListAuthenticationsOptions } from "./schemas";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* List available authentications with optional filtering
|
|
11
|
-
*
|
|
12
|
-
* This function can be used standalone without instantiating a full SDK,
|
|
13
|
-
* which enables better tree-shaking in applications that only need this functionality.
|
|
14
|
-
*
|
|
15
|
-
* @param options - Filtering, pagination, and API configuration options
|
|
16
|
-
* @returns Promise<Authentication[]> with pagination metadata
|
|
17
|
-
*/
|
|
18
|
-
export async function listAuthentications(
|
|
19
|
-
options: Partial<ListAuthenticationsOptions> = {},
|
|
20
|
-
): Promise<Authentication[]> {
|
|
21
|
-
const api = getOrCreateApiClient(options);
|
|
22
|
-
|
|
23
|
-
// Local function to handle the actual API fetching
|
|
24
|
-
const listAuthenticationsInternal = async (
|
|
25
|
-
options: ListAuthenticationsOptions = {},
|
|
26
|
-
): Promise<Authentication[]> => {
|
|
27
|
-
// Build search parameters
|
|
28
|
-
const searchParams: Record<string, string> = {};
|
|
29
|
-
|
|
30
|
-
// Handle appKey filtering by getting the selected_api first
|
|
31
|
-
if (options.appKey) {
|
|
32
|
-
try {
|
|
33
|
-
// Use the standalone getApp function
|
|
34
|
-
const app = await getApp({
|
|
35
|
-
appKey: options.appKey,
|
|
36
|
-
api,
|
|
37
|
-
token: options.token,
|
|
38
|
-
baseUrl: options.baseUrl,
|
|
39
|
-
debug: options.debug,
|
|
40
|
-
fetch: options.fetch,
|
|
41
|
-
});
|
|
42
|
-
const selectedApi = app.current_implementation_id;
|
|
43
|
-
if (selectedApi) {
|
|
44
|
-
// Use versionless_selected_api to find auths across all app versions
|
|
45
|
-
// Extract the base name without the version (e.g., "SlackCLIAPI" from "SlackCLIAPI@1.21.1")
|
|
46
|
-
const versionlessApi = selectedApi.split("@")[0];
|
|
47
|
-
searchParams.versionless_selected_api = versionlessApi;
|
|
48
|
-
}
|
|
49
|
-
} catch (error) {
|
|
50
|
-
// If it's an AppNotFoundError, re-throw it
|
|
51
|
-
if (error instanceof Error && error.name === "AppNotFoundError") {
|
|
52
|
-
throw error;
|
|
53
|
-
}
|
|
54
|
-
// For other errors, continue without app filtering
|
|
55
|
-
console.warn(
|
|
56
|
-
`Warning: Could not filter by app ${options.appKey}:`,
|
|
57
|
-
error instanceof Error ? error.message : "Unknown error",
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// Add other query parameters if provided
|
|
63
|
-
// Use title as search if no explicit search provided
|
|
64
|
-
if (options.search) {
|
|
65
|
-
searchParams.search = options.search;
|
|
66
|
-
} else if (options.title) {
|
|
67
|
-
searchParams.search = options.title;
|
|
68
|
-
}
|
|
69
|
-
if (options.account_id) {
|
|
70
|
-
searchParams.account_id = options.account_id;
|
|
71
|
-
}
|
|
72
|
-
if (options.owner) {
|
|
73
|
-
searchParams.owner = options.owner;
|
|
74
|
-
}
|
|
75
|
-
if (options.limit) {
|
|
76
|
-
searchParams.limit = options.limit.toString();
|
|
77
|
-
}
|
|
78
|
-
if (options.offset) {
|
|
79
|
-
searchParams.offset = options.offset.toString();
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const data: AuthenticationsResponse = await api.get(
|
|
83
|
-
"/api/v4/authentications/",
|
|
84
|
-
{
|
|
85
|
-
searchParams,
|
|
86
|
-
customErrorHandler: (response) => {
|
|
87
|
-
if (response.status === 401) {
|
|
88
|
-
return new Error(
|
|
89
|
-
`Authentication failed. Your token may not have permission to access authentications or may be expired. (HTTP ${response.status})`,
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
if (response.status === 403) {
|
|
93
|
-
return new Error(
|
|
94
|
-
`Access forbidden. Your token may not have the required scopes to list authentications. (HTTP ${response.status})`,
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
return undefined;
|
|
98
|
-
},
|
|
99
|
-
},
|
|
100
|
-
);
|
|
101
|
-
|
|
102
|
-
// Transform API response
|
|
103
|
-
let auths = data.results || [];
|
|
104
|
-
|
|
105
|
-
// Coerce title from label if title is missing (API cleanup)
|
|
106
|
-
auths = auths.map((auth) => ({
|
|
107
|
-
...auth,
|
|
108
|
-
title: auth.title || (auth as any).label || undefined,
|
|
109
|
-
}));
|
|
110
|
-
|
|
111
|
-
// Filter by exact title match if specified
|
|
112
|
-
if (options.title) {
|
|
113
|
-
auths = auths.filter((auth) => auth.title === options.title);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// Add pagination metadata to the response
|
|
117
|
-
if (auths.length > 0) {
|
|
118
|
-
(auths as any).__pagination = {
|
|
119
|
-
count: data.count,
|
|
120
|
-
hasNext: !!data.next,
|
|
121
|
-
hasPrevious: !!data.previous,
|
|
122
|
-
nextUrl: data.next,
|
|
123
|
-
previousUrl: data.previous,
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return auths;
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
// If a limit is provided and no specific owner filter, prioritize owned auths
|
|
131
|
-
if (options.limit && options.owner === undefined) {
|
|
132
|
-
// First get owned auths
|
|
133
|
-
const ownedAuths = await listAuthenticationsInternal({
|
|
134
|
-
...options,
|
|
135
|
-
owner: "me",
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
// If we have enough owned auths, just slice and return
|
|
139
|
-
if (ownedAuths.length >= options.limit) {
|
|
140
|
-
return ownedAuths.slice(0, options.limit);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// Get all auths up to the original limit to fill remaining slots
|
|
144
|
-
const allAuths = await listAuthenticationsInternal({
|
|
145
|
-
...options,
|
|
146
|
-
owner: undefined,
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
// Filter out auths the user already owns to avoid duplicates
|
|
150
|
-
const ownedAuthenticationIds = new Set(ownedAuths.map((auth) => auth.id));
|
|
151
|
-
const additionalAuths = allAuths.filter(
|
|
152
|
-
(auth) => !ownedAuthenticationIds.has(auth.id),
|
|
153
|
-
);
|
|
154
|
-
|
|
155
|
-
// Combine and slice to the requested limit
|
|
156
|
-
const combined = [...ownedAuths, ...additionalAuths];
|
|
157
|
-
return combined.slice(0, options.limit);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// Standard implementation for non-prioritized requests
|
|
161
|
-
return listAuthenticationsInternal(options);
|
|
162
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { listAuthentications } from "./index";
|
|
2
|
-
import { ListAuthenticationsSchema } from "./schemas";
|
|
3
|
-
|
|
4
|
-
// Function registry info - imports both function and schema
|
|
5
|
-
export const listAuthenticationsInfo = {
|
|
6
|
-
name: listAuthentications.name,
|
|
7
|
-
inputSchema: ListAuthenticationsSchema,
|
|
8
|
-
implementation: listAuthentications,
|
|
9
|
-
};
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import {
|
|
3
|
-
AppKeyPropertySchema,
|
|
4
|
-
LimitPropertySchema,
|
|
5
|
-
OffsetPropertySchema,
|
|
6
|
-
} from "../../types/properties";
|
|
7
|
-
import { withOutputSchema } from "../../schema-utils";
|
|
8
|
-
import { AuthItemSchema } from "../../schemas/Auth";
|
|
9
|
-
import type { Authentication, FunctionOptions } from "../../types/domain";
|
|
10
|
-
|
|
11
|
-
// Pure Zod schema - no resolver metadata!
|
|
12
|
-
export const ListAuthenticationsSchema = withOutputSchema(
|
|
13
|
-
z
|
|
14
|
-
.object({
|
|
15
|
-
appKey: AppKeyPropertySchema.optional().describe(
|
|
16
|
-
"App slug to get authentications for (e.g., 'slack', 'github')",
|
|
17
|
-
),
|
|
18
|
-
search: z
|
|
19
|
-
.string()
|
|
20
|
-
.optional()
|
|
21
|
-
.describe("Search term to filter authentications by title"),
|
|
22
|
-
title: z
|
|
23
|
-
.string()
|
|
24
|
-
.optional()
|
|
25
|
-
.describe("Filter authentications by exact title match"),
|
|
26
|
-
account_id: z.string().optional().describe("Filter by account ID"),
|
|
27
|
-
owner: z.string().optional().describe("Filter by owner"),
|
|
28
|
-
limit: LimitPropertySchema.optional().describe(
|
|
29
|
-
"Maximum number of items to return (1-200)",
|
|
30
|
-
),
|
|
31
|
-
offset: OffsetPropertySchema.optional().describe(
|
|
32
|
-
"Number of items to skip for pagination",
|
|
33
|
-
),
|
|
34
|
-
})
|
|
35
|
-
.describe("List available authentications with optional filtering"),
|
|
36
|
-
AuthItemSchema,
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
// Type inferred from schema + function config
|
|
40
|
-
export type ListAuthenticationsOptions = z.infer<
|
|
41
|
-
typeof ListAuthenticationsSchema
|
|
42
|
-
> &
|
|
43
|
-
FunctionOptions;
|
|
44
|
-
|
|
45
|
-
// SDK function interface - ready to be mixed into main SDK interface
|
|
46
|
-
export interface ListAuthenticationsSdkFunction {
|
|
47
|
-
listAuthentications: (
|
|
48
|
-
options?: Partial<ListAuthenticationsOptions>,
|
|
49
|
-
) => Promise<Authentication[]>;
|
|
50
|
-
}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { getOrCreateApiClient } from "../../api";
|
|
2
|
-
import type {
|
|
3
|
-
ActionField,
|
|
4
|
-
NeedsRequest,
|
|
5
|
-
NeedsResponse,
|
|
6
|
-
} from "../../types/domain";
|
|
7
|
-
import { getApp } from "../getApp";
|
|
8
|
-
import type { ListFieldsOptions } from "./schemas";
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* List available fields for an action
|
|
12
|
-
*
|
|
13
|
-
* This function can be used standalone without instantiating a full SDK,
|
|
14
|
-
* which enables better tree-shaking in applications that only need this functionality.
|
|
15
|
-
*
|
|
16
|
-
* @param options - Action details, authentication ID, params, and API configuration options
|
|
17
|
-
* @returns Promise<ActionField[]>
|
|
18
|
-
*/
|
|
19
|
-
export async function listFields(
|
|
20
|
-
options: ListFieldsOptions,
|
|
21
|
-
): Promise<ActionField[]> {
|
|
22
|
-
const api = getOrCreateApiClient(options);
|
|
23
|
-
|
|
24
|
-
// Extract parameters
|
|
25
|
-
const { appKey, actionKey, actionType, authenticationId, params } = options;
|
|
26
|
-
|
|
27
|
-
// Use the standalone getApp function
|
|
28
|
-
const appData = await getApp({
|
|
29
|
-
appKey,
|
|
30
|
-
api,
|
|
31
|
-
token: options.token,
|
|
32
|
-
baseUrl: options.baseUrl,
|
|
33
|
-
debug: options.debug,
|
|
34
|
-
fetch: options.fetch,
|
|
35
|
-
});
|
|
36
|
-
const selectedApi = appData.current_implementation_id;
|
|
37
|
-
|
|
38
|
-
if (!selectedApi) {
|
|
39
|
-
throw new Error("No current_implementation_id found for app");
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Build needs request
|
|
43
|
-
const needsRequest: NeedsRequest = {
|
|
44
|
-
selected_api: selectedApi,
|
|
45
|
-
action: actionKey,
|
|
46
|
-
type_of: actionType,
|
|
47
|
-
authentication_id: authenticationId,
|
|
48
|
-
params: params || {},
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const needsData: NeedsResponse = await api.post(
|
|
52
|
-
"/api/v4/implementations/needs/",
|
|
53
|
-
needsRequest,
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
if (!needsData.success) {
|
|
57
|
-
throw new Error(
|
|
58
|
-
`Failed to get action fields: ${
|
|
59
|
-
needsData.errors?.join(", ") || "Unknown error"
|
|
60
|
-
}`,
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// Transform API response to our ActionField interface
|
|
65
|
-
return (needsData.needs || []).map((need: any) => ({
|
|
66
|
-
key: need.key,
|
|
67
|
-
label: need.label,
|
|
68
|
-
required: need.required || false,
|
|
69
|
-
type: need.type,
|
|
70
|
-
helpText: need.help_text,
|
|
71
|
-
helpTextHtml: need.help_text_html,
|
|
72
|
-
choices: need.choices?.map((choice: any) => ({
|
|
73
|
-
value: choice.value,
|
|
74
|
-
label: choice.label,
|
|
75
|
-
})),
|
|
76
|
-
default: need.default,
|
|
77
|
-
placeholder: need.placeholder,
|
|
78
|
-
computed: need.computed,
|
|
79
|
-
customField: need.custom_field,
|
|
80
|
-
dependsOn: need.depends_on,
|
|
81
|
-
format: need.format,
|
|
82
|
-
inputFormat: need.input_format,
|
|
83
|
-
}));
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// No registry info here - moved to info.ts for proper tree-shaking
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { listFields } from "./index";
|
|
2
|
-
import { ListFieldsSchema } from "./schemas";
|
|
3
|
-
|
|
4
|
-
// Function registry info - imports both function and schema
|
|
5
|
-
export const listFieldsInfo = {
|
|
6
|
-
name: listFields.name,
|
|
7
|
-
inputSchema: ListFieldsSchema,
|
|
8
|
-
implementation: listFields,
|
|
9
|
-
};
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import {
|
|
3
|
-
AppKeyPropertySchema,
|
|
4
|
-
ActionTypePropertySchema,
|
|
5
|
-
ActionKeyPropertySchema,
|
|
6
|
-
AuthenticationIdPropertySchema,
|
|
7
|
-
ParamsPropertySchema,
|
|
8
|
-
} from "../../types/properties";
|
|
9
|
-
import { withOutputSchema } from "../../schema-utils";
|
|
10
|
-
import { FieldItemSchema } from "../../schemas/Field";
|
|
11
|
-
import type { ActionField, FunctionOptions } from "../../types/domain";
|
|
12
|
-
|
|
13
|
-
// Pure Zod schema - no resolver metadata!
|
|
14
|
-
export const ListFieldsSchema = withOutputSchema(
|
|
15
|
-
z
|
|
16
|
-
.object({
|
|
17
|
-
appKey: AppKeyPropertySchema,
|
|
18
|
-
actionType: ActionTypePropertySchema,
|
|
19
|
-
actionKey: ActionKeyPropertySchema,
|
|
20
|
-
authenticationId: AuthenticationIdPropertySchema.optional(),
|
|
21
|
-
params: ParamsPropertySchema.optional().describe(
|
|
22
|
-
"Additional parameters that may affect available fields",
|
|
23
|
-
),
|
|
24
|
-
})
|
|
25
|
-
.describe("Get the input fields required for a specific action"),
|
|
26
|
-
FieldItemSchema,
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
// Type inferred from schema + function config
|
|
30
|
-
export type ListFieldsOptions = z.infer<typeof ListFieldsSchema> &
|
|
31
|
-
FunctionOptions;
|
|
32
|
-
|
|
33
|
-
// SDK function interface - ready to be mixed into main SDK interface
|
|
34
|
-
export interface ListFieldsSdkFunction {
|
|
35
|
-
listFields: (options: ListFieldsOptions) => Promise<ActionField[]>;
|
|
36
|
-
}
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import { getOrCreateApiClient } from "../../api";
|
|
2
|
-
import type { FunctionOptions } from "../../types/domain";
|
|
3
|
-
|
|
4
|
-
export interface RelayRequestOptions {
|
|
5
|
-
/** HTTP method */
|
|
6
|
-
method?: string;
|
|
7
|
-
/** Request body (can be string, FormData, Blob, etc.) */
|
|
8
|
-
body?: BodyInit | null;
|
|
9
|
-
/** Request headers */
|
|
10
|
-
headers?: HeadersInit;
|
|
11
|
-
/** Zapier authentication ID to use for the request */
|
|
12
|
-
authenticationId?: number;
|
|
13
|
-
/** URL to send async response to (makes request async) */
|
|
14
|
-
callbackUrl?: string;
|
|
15
|
-
/** Optional JSON string authentication template to bypass Notary lookup */
|
|
16
|
-
authenticationTemplate?: string;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// Legacy type alias
|
|
20
|
-
export type RelayFetchOptions = RelayRequestOptions;
|
|
21
|
-
|
|
22
|
-
export interface RelayFetchConfig extends FunctionOptions {
|
|
23
|
-
/** Event callback function */
|
|
24
|
-
onEvent?: (event: any) => void;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Transforms full URLs into Relay format: /relay/{domain}/{path}
|
|
29
|
-
*
|
|
30
|
-
* @param url - The full URL to transform (e.g., "https://api.github.com/user")
|
|
31
|
-
* @returns The relay path format (e.g., "/relay/api.github.com/user")
|
|
32
|
-
*/
|
|
33
|
-
function transformUrlToRelayPath(url: string | URL): string {
|
|
34
|
-
const targetUrl = new URL(url);
|
|
35
|
-
|
|
36
|
-
// Build the Relay path: /relay/{domain}{pathname}{search}{hash}
|
|
37
|
-
const relayPath = `/relay/${targetUrl.hostname}${targetUrl.pathname}${targetUrl.search}${targetUrl.hash}`;
|
|
38
|
-
|
|
39
|
-
return relayPath;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Fetch function that can make requests to external APIs through Zapier's Relay service
|
|
44
|
-
*
|
|
45
|
-
* This function takes full URLs (like https://api.github.com/user) and transforms them
|
|
46
|
-
* into the relay format (/relay/api.github.com/user) for the API client to route
|
|
47
|
-
* to relay.zapier.com.
|
|
48
|
-
*
|
|
49
|
-
* @param url - The full URL to fetch
|
|
50
|
-
* @param options - Fetch options with additional Relay-specific parameters
|
|
51
|
-
* @param config - SDK configuration options
|
|
52
|
-
* @returns Promise<Response> - The response from the request
|
|
53
|
-
*/
|
|
54
|
-
/**
|
|
55
|
-
* Schema-compatible wrapper function for the request functionality
|
|
56
|
-
*/
|
|
57
|
-
export async function request(
|
|
58
|
-
options: {
|
|
59
|
-
url: string;
|
|
60
|
-
method?: string;
|
|
61
|
-
body?: BodyInit | null;
|
|
62
|
-
headers?: HeadersInit;
|
|
63
|
-
authenticationId?: number;
|
|
64
|
-
callbackUrl?: string;
|
|
65
|
-
authenticationTemplate?: string;
|
|
66
|
-
} & FunctionOptions,
|
|
67
|
-
): Promise<Response> {
|
|
68
|
-
const {
|
|
69
|
-
url,
|
|
70
|
-
method = "GET",
|
|
71
|
-
body,
|
|
72
|
-
headers,
|
|
73
|
-
authenticationId,
|
|
74
|
-
callbackUrl,
|
|
75
|
-
authenticationTemplate,
|
|
76
|
-
...config
|
|
77
|
-
} = options;
|
|
78
|
-
|
|
79
|
-
return relayFetch(
|
|
80
|
-
url,
|
|
81
|
-
{
|
|
82
|
-
method,
|
|
83
|
-
body,
|
|
84
|
-
headers,
|
|
85
|
-
authenticationId,
|
|
86
|
-
callbackUrl,
|
|
87
|
-
authenticationTemplate,
|
|
88
|
-
},
|
|
89
|
-
config,
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Internal fetch implementation
|
|
95
|
-
*/
|
|
96
|
-
export async function relayFetch(
|
|
97
|
-
url: string | URL,
|
|
98
|
-
options: RelayRequestOptions = {},
|
|
99
|
-
config: RelayFetchConfig = {},
|
|
100
|
-
): Promise<Response> {
|
|
101
|
-
const api = getOrCreateApiClient(config);
|
|
102
|
-
|
|
103
|
-
// Extract Relay-specific options
|
|
104
|
-
const {
|
|
105
|
-
authenticationId,
|
|
106
|
-
callbackUrl,
|
|
107
|
-
authenticationTemplate,
|
|
108
|
-
method = "GET",
|
|
109
|
-
body,
|
|
110
|
-
...fetchOptions
|
|
111
|
-
} = options;
|
|
112
|
-
|
|
113
|
-
// Transform full URL to relay path format
|
|
114
|
-
const relayPath = transformUrlToRelayPath(url);
|
|
115
|
-
|
|
116
|
-
// Build headers for the request
|
|
117
|
-
const headers: Record<string, string> = {};
|
|
118
|
-
|
|
119
|
-
// Copy existing headers
|
|
120
|
-
if (fetchOptions.headers) {
|
|
121
|
-
const headerEntries =
|
|
122
|
-
fetchOptions.headers instanceof Headers
|
|
123
|
-
? Array.from(fetchOptions.headers.entries())
|
|
124
|
-
: Object.entries(fetchOptions.headers);
|
|
125
|
-
|
|
126
|
-
for (const [key, value] of headerEntries) {
|
|
127
|
-
headers[key] = value;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// Add Relay-specific headers
|
|
132
|
-
if (authenticationId) {
|
|
133
|
-
headers["X-Relay-Authentication-Id"] = authenticationId.toString();
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (callbackUrl) {
|
|
137
|
-
headers["X-Relay-Callback-Url"] = callbackUrl;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
if (authenticationTemplate) {
|
|
141
|
-
headers["X-Authentication-Template"] = authenticationTemplate;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// Use the API client's fetch method directly - let it handle auth automatically
|
|
145
|
-
return await api.fetch(relayPath, {
|
|
146
|
-
method,
|
|
147
|
-
body,
|
|
148
|
-
headers,
|
|
149
|
-
});
|
|
150
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { request } from "./index";
|
|
2
|
-
import { RelayRequestSchema } from "./schemas";
|
|
3
|
-
|
|
4
|
-
export const requestInfo = {
|
|
5
|
-
name: "request",
|
|
6
|
-
inputSchema: RelayRequestSchema,
|
|
7
|
-
implementation: request,
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
// Legacy export for compatibility
|
|
11
|
-
export const fetchInfo = requestInfo;
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { getOrCreateApiClient, generateRequestId } from "../../api";
|
|
2
|
-
import type { ActionExecutionResult } from "../../types/domain";
|
|
3
|
-
import { getAction } from "../getAction";
|
|
4
|
-
import { getApp } from "../getApp";
|
|
5
|
-
import type { RunActionOptions } from "./schemas";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Execute an action
|
|
9
|
-
*
|
|
10
|
-
* This function can be used standalone without instantiating a full SDK,
|
|
11
|
-
* which enables better tree-shaking in applications that only need this functionality.
|
|
12
|
-
*
|
|
13
|
-
* @param options - Action execution parameters and API configuration options
|
|
14
|
-
* @returns Promise<ActionExecutionResult>
|
|
15
|
-
*/
|
|
16
|
-
export async function runAction(
|
|
17
|
-
options: RunActionOptions,
|
|
18
|
-
): Promise<ActionExecutionResult> {
|
|
19
|
-
const {
|
|
20
|
-
appKey,
|
|
21
|
-
actionType,
|
|
22
|
-
actionKey,
|
|
23
|
-
inputs,
|
|
24
|
-
authenticationId: providedAuthenticationId,
|
|
25
|
-
} = options;
|
|
26
|
-
|
|
27
|
-
const api = getOrCreateApiClient(options);
|
|
28
|
-
|
|
29
|
-
// Validate that the action exists
|
|
30
|
-
const actionData = await getAction({
|
|
31
|
-
...options,
|
|
32
|
-
appKey: appKey,
|
|
33
|
-
actionKey: actionKey,
|
|
34
|
-
actionType: actionType,
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
// Validate action type matches
|
|
38
|
-
if (actionData.type !== actionType) {
|
|
39
|
-
throw new Error(
|
|
40
|
-
`Action type mismatch: expected ${actionType}, got ${actionData.type}`,
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// Execute the action using the Actions API (supports all action types)
|
|
45
|
-
const startTime = Date.now();
|
|
46
|
-
const result = await executeAction({
|
|
47
|
-
api,
|
|
48
|
-
appSlug: appKey,
|
|
49
|
-
actionKey: actionKey,
|
|
50
|
-
actionType: actionData.type,
|
|
51
|
-
executionOptions: { inputs: inputs || {} },
|
|
52
|
-
authenticationId: providedAuthenticationId,
|
|
53
|
-
options,
|
|
54
|
-
});
|
|
55
|
-
const executionTime = Date.now() - startTime;
|
|
56
|
-
|
|
57
|
-
return {
|
|
58
|
-
success: true,
|
|
59
|
-
data: result,
|
|
60
|
-
metadata: {
|
|
61
|
-
executionTime,
|
|
62
|
-
requestId: generateRequestId(),
|
|
63
|
-
},
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
interface ExecuteActionOptions {
|
|
68
|
-
api: any;
|
|
69
|
-
appSlug: string;
|
|
70
|
-
actionKey: string;
|
|
71
|
-
actionType: string;
|
|
72
|
-
executionOptions: { inputs: Record<string, any> };
|
|
73
|
-
authenticationId?: number;
|
|
74
|
-
options: RunActionOptions;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
async function executeAction(
|
|
78
|
-
actionOptions: ExecuteActionOptions,
|
|
79
|
-
): Promise<any> {
|
|
80
|
-
const {
|
|
81
|
-
api,
|
|
82
|
-
appSlug,
|
|
83
|
-
actionKey,
|
|
84
|
-
actionType,
|
|
85
|
-
executionOptions,
|
|
86
|
-
authenticationId,
|
|
87
|
-
options,
|
|
88
|
-
} = actionOptions;
|
|
89
|
-
|
|
90
|
-
// Use the standalone getApp function
|
|
91
|
-
const appData = await getApp({
|
|
92
|
-
appKey: appSlug,
|
|
93
|
-
api,
|
|
94
|
-
token: options.token,
|
|
95
|
-
baseUrl: options.baseUrl,
|
|
96
|
-
debug: options.debug,
|
|
97
|
-
fetch: options.fetch,
|
|
98
|
-
});
|
|
99
|
-
const selectedApi = appData.current_implementation_id;
|
|
100
|
-
|
|
101
|
-
if (!selectedApi) {
|
|
102
|
-
throw new Error("No current_implementation_id found for app");
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// Step 1: POST to /actions/v1/runs to start execution
|
|
106
|
-
const runRequest = {
|
|
107
|
-
data: {
|
|
108
|
-
authentication_id: authenticationId || 1,
|
|
109
|
-
selected_api: selectedApi,
|
|
110
|
-
action_key: actionKey,
|
|
111
|
-
action_type: actionType,
|
|
112
|
-
inputs: executionOptions.inputs || {},
|
|
113
|
-
},
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
const runData = await api.post("/api/actions/v1/runs", runRequest);
|
|
117
|
-
const runId = runData.data.id;
|
|
118
|
-
|
|
119
|
-
// Step 2: Poll GET /actions/v1/runs/{run_id} for results
|
|
120
|
-
return await api.poll(`/api/actions/v1/runs/${runId}`, {
|
|
121
|
-
successStatus: 200,
|
|
122
|
-
pendingStatus: 202,
|
|
123
|
-
resultExtractor: (result: any) => result.data,
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// No registry info here - moved to info.ts for proper tree-shaking
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { runAction } from "./index";
|
|
2
|
-
import { RunActionSchema } from "./schemas";
|
|
3
|
-
|
|
4
|
-
// Function registry info - imports both function and schema
|
|
5
|
-
export const runActionInfo = {
|
|
6
|
-
name: runAction.name,
|
|
7
|
-
inputSchema: RunActionSchema,
|
|
8
|
-
implementation: runAction,
|
|
9
|
-
};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import {
|
|
3
|
-
AppKeyPropertySchema,
|
|
4
|
-
ActionTypePropertySchema,
|
|
5
|
-
ActionKeyPropertySchema,
|
|
6
|
-
AuthenticationIdPropertySchema,
|
|
7
|
-
InputsPropertySchema,
|
|
8
|
-
} from "../../types/properties";
|
|
9
|
-
import type {
|
|
10
|
-
ActionExecutionResult,
|
|
11
|
-
FunctionOptions,
|
|
12
|
-
} from "../../types/domain";
|
|
13
|
-
|
|
14
|
-
// Pure Zod schema - no resolver metadata!
|
|
15
|
-
export const RunActionSchema = z
|
|
16
|
-
.object({
|
|
17
|
-
appKey: AppKeyPropertySchema,
|
|
18
|
-
actionType: ActionTypePropertySchema,
|
|
19
|
-
actionKey: ActionKeyPropertySchema,
|
|
20
|
-
inputs: InputsPropertySchema.optional().describe(
|
|
21
|
-
"Input parameters for the action",
|
|
22
|
-
),
|
|
23
|
-
authenticationId: AuthenticationIdPropertySchema.optional(),
|
|
24
|
-
})
|
|
25
|
-
.describe("Execute an action with the given inputs");
|
|
26
|
-
|
|
27
|
-
// Type inferred from schema + function config
|
|
28
|
-
export type RunActionOptions = z.infer<typeof RunActionSchema> &
|
|
29
|
-
FunctionOptions;
|
|
30
|
-
|
|
31
|
-
// SDK function interface - ready to be mixed into main SDK interface
|
|
32
|
-
export interface RunActionSdkFunction {
|
|
33
|
-
runAction: (options: RunActionOptions) => Promise<ActionExecutionResult>;
|
|
34
|
-
}
|