@zapier/zapier-sdk 0.0.3 → 0.1.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/dist/api/auth.d.ts +8 -0
- package/dist/api/auth.js +29 -0
- package/dist/api/client.d.ts +8 -0
- package/dist/api/client.js +102 -0
- package/dist/api/debug.d.ts +12 -0
- package/dist/api/debug.js +50 -0
- package/dist/api/index.d.ts +26 -0
- package/dist/api/index.js +51 -0
- package/dist/api/polling.d.ts +17 -0
- package/dist/api/polling.js +34 -0
- package/dist/{types.d.ts → api/types.d.ts} +37 -88
- package/dist/api/types.js +9 -0
- package/dist/functions/{bundleCode.d.ts → bundleCode/index.d.ts} +1 -8
- package/dist/functions/bundleCode/info.d.ts +27 -0
- package/dist/functions/bundleCode/info.js +11 -0
- package/dist/functions/bundleCode/schemas.d.ts +27 -0
- package/dist/functions/bundleCode/schemas.js +22 -0
- package/dist/functions/findFirstAuthentication/index.d.ts +12 -0
- package/dist/functions/findFirstAuthentication/index.js +21 -0
- package/dist/functions/findFirstAuthentication/info.d.ts +30 -0
- package/dist/functions/findFirstAuthentication/info.js +11 -0
- package/dist/functions/findFirstAuthentication/schemas.d.ts +42 -0
- package/dist/functions/findFirstAuthentication/schemas.js +25 -0
- package/dist/functions/findUniqueAuthentication/index.d.ts +13 -0
- package/dist/functions/findUniqueAuthentication/index.js +28 -0
- package/dist/functions/findUniqueAuthentication/info.d.ts +30 -0
- package/dist/functions/findUniqueAuthentication/info.js +11 -0
- package/dist/functions/findUniqueAuthentication/schemas.d.ts +42 -0
- package/dist/functions/findUniqueAuthentication/schemas.js +25 -0
- package/dist/functions/{generateTypes.d.ts → generateTypes/index.d.ts} +2 -7
- package/dist/functions/{generateTypes.js → generateTypes/index.js} +58 -24
- package/dist/functions/generateTypes/info.d.ts +21 -0
- package/dist/functions/generateTypes/info.js +11 -0
- package/dist/functions/generateTypes/schemas.d.ts +30 -0
- package/dist/functions/generateTypes/schemas.js +14 -0
- package/dist/functions/{getAction.d.ts → getAction/index.d.ts} +2 -6
- package/dist/functions/{getAction.js → getAction/index.js} +6 -5
- package/dist/functions/getAction/info.d.ts +18 -0
- package/dist/functions/getAction/info.js +11 -0
- package/dist/functions/getAction/schemas.d.ts +30 -0
- package/dist/functions/getAction/schemas.js +13 -0
- package/dist/functions/{getApp.d.ts → getApp/index.d.ts} +2 -4
- package/dist/functions/{getApp.js → getApp/index.js} +6 -10
- package/dist/functions/getApp/info.d.ts +12 -0
- package/dist/functions/getApp/info.js +11 -0
- package/dist/functions/getApp/schemas.d.ts +24 -0
- package/dist/functions/getApp/schemas.js +11 -0
- package/dist/functions/{listActions.d.ts → listActions/index.d.ts} +3 -6
- package/dist/functions/{listActions.js → listActions/index.js} +4 -3
- package/dist/functions/listActions/info.d.ts +15 -0
- package/dist/functions/listActions/info.js +11 -0
- package/dist/functions/listActions/schemas.d.ts +27 -0
- package/dist/functions/listActions/schemas.js +14 -0
- package/dist/functions/{listApps.d.ts → listApps/index.d.ts} +2 -6
- package/dist/functions/{listApps.js → listApps/index.js} +1 -1
- package/dist/functions/listApps/info.d.ts +18 -0
- package/dist/functions/listApps/info.js +11 -0
- package/dist/functions/listApps/schemas.d.ts +30 -0
- package/dist/functions/listApps/schemas.js +15 -0
- package/dist/functions/{listAuths.d.ts → listAuthentications/index.d.ts} +3 -9
- package/dist/functions/{listAuths.js → listAuthentications/index.js} +28 -12
- package/dist/functions/listAuthentications/info.d.ts +30 -0
- package/dist/functions/listAuthentications/info.js +11 -0
- package/dist/functions/listAuthentications/schemas.d.ts +42 -0
- package/dist/functions/listAuthentications/schemas.js +25 -0
- package/dist/functions/{listFields.d.ts → listFields/index.d.ts} +3 -9
- package/dist/functions/{listFields.js → listFields/index.js} +8 -10
- package/dist/functions/listFields/info.d.ts +24 -0
- package/dist/functions/listFields/info.js +11 -0
- package/dist/functions/listFields/schemas.d.ts +36 -0
- package/dist/functions/listFields/schemas.js +17 -0
- package/dist/functions/{runAction.d.ts → runAction/index.d.ts} +2 -8
- package/dist/functions/{runAction.js → runAction/index.js} +15 -14
- package/dist/functions/runAction/info.d.ts +24 -0
- package/dist/functions/runAction/info.js +11 -0
- package/dist/functions/runAction/schemas.d.ts +36 -0
- package/dist/functions/runAction/schemas.js +15 -0
- package/dist/index.d.ts +10 -4
- package/dist/index.js +17 -6
- package/dist/plugins/apps/index.d.ts +8 -0
- package/dist/plugins/apps/index.js +77 -0
- package/dist/plugins/apps/info.d.ts +6 -0
- package/dist/plugins/apps/info.js +13 -0
- package/dist/plugins/apps/types.d.ts +21 -0
- package/dist/plugins/apps/types.js +2 -0
- package/dist/resolvers/actionKey.d.ts +8 -0
- package/dist/resolvers/actionKey.js +20 -0
- package/dist/resolvers/actionType.d.ts +8 -0
- package/dist/resolvers/actionType.js +21 -0
- package/dist/resolvers/appKey.d.ts +6 -0
- package/dist/resolvers/appKey.js +8 -0
- package/dist/resolvers/authenticationId.d.ts +8 -0
- package/dist/resolvers/authenticationId.js +29 -0
- package/dist/resolvers/index.d.ts +39 -0
- package/dist/resolvers/index.js +105 -0
- package/dist/resolvers/inputs.d.ts +7 -0
- package/dist/resolvers/inputs.js +15 -0
- package/dist/schema-utils.d.ts +44 -0
- package/dist/schema-utils.js +76 -0
- package/dist/schemas/Action.d.ts +21 -0
- package/dist/schemas/Action.js +31 -0
- package/dist/schemas/App.d.ts +19 -0
- package/dist/schemas/App.js +32 -0
- package/dist/schemas/Auth.d.ts +27 -0
- package/dist/schemas/Auth.js +42 -0
- package/dist/schemas/Field.d.ts +15 -0
- package/dist/schemas/Field.js +25 -0
- package/dist/sdk.d.ts +3 -4
- package/dist/sdk.js +104 -11
- package/dist/types/domain.d.ts +22 -0
- package/dist/types/domain.js +21 -0
- package/dist/types/properties.d.ts +21 -0
- package/dist/types/properties.js +43 -0
- package/dist/types/sdk.d.ts +23 -0
- package/dist/types/sdk.js +2 -0
- package/package.json +4 -2
- package/src/api/auth.ts +28 -0
- package/src/api/client.ts +148 -0
- package/src/api/debug.ts +58 -0
- package/src/api/index.ts +83 -0
- package/src/api/polling.ts +56 -0
- package/src/api/types.ts +177 -0
- package/src/functions/{bundleCode.ts → bundleCode/index.ts} +1 -8
- package/src/functions/bundleCode/info.ts +9 -0
- package/src/functions/bundleCode/schemas.ts +30 -0
- package/src/functions/findFirstAuthentication/index.ts +24 -0
- package/src/functions/findFirstAuthentication/info.ts +9 -0
- package/src/functions/findFirstAuthentication/schemas.ts +60 -0
- package/src/functions/findUniqueAuthentication/index.ts +35 -0
- package/src/functions/findUniqueAuthentication/info.ts +9 -0
- package/src/functions/findUniqueAuthentication/schemas.ts +60 -0
- package/src/functions/{generateTypes.ts → generateTypes/index.ts} +70 -31
- package/src/functions/generateTypes/info.ts +9 -0
- package/src/functions/generateTypes/schemas.ts +38 -0
- package/src/functions/{getAction.ts → getAction/index.ts} +11 -12
- package/src/functions/getAction/info.ts +9 -0
- package/src/functions/getAction/schemas.ts +35 -0
- package/src/functions/{getApp.ts → getApp/index.ts} +9 -15
- package/src/functions/getApp/info.ts +9 -0
- package/src/functions/getApp/schemas.ts +31 -0
- package/src/functions/{listActions.ts → listActions/index.ts} +8 -10
- package/src/functions/listActions/info.ts +9 -0
- package/src/functions/listActions/schemas.ts +40 -0
- package/src/functions/{listApps.ts → listApps/index.ts} +3 -8
- package/src/functions/listApps/info.ts +9 -0
- package/src/functions/listApps/schemas.ts +43 -0
- package/src/functions/{listAuths.ts → listAuthentications/index.ts} +32 -23
- package/src/functions/listAuthentications/info.ts +9 -0
- package/src/functions/listAuthentications/schemas.ts +60 -0
- package/src/functions/{listFields.ts → listFields/index.ts} +11 -20
- package/src/functions/listFields/info.ts +9 -0
- package/src/functions/listFields/schemas.ts +46 -0
- package/src/functions/{runAction.ts → runAction/index.ts} +25 -23
- package/src/functions/runAction/info.ts +9 -0
- package/src/functions/runAction/schemas.ts +41 -0
- package/src/index.ts +19 -5
- package/src/plugins/apps/index.ts +144 -0
- package/src/plugins/apps/info.ts +12 -0
- package/src/plugins/apps/types.ts +34 -0
- package/src/resolvers/actionKey.ts +33 -0
- package/src/resolvers/actionType.ts +30 -0
- package/src/resolvers/appKey.ts +11 -0
- package/src/resolvers/authenticationId.ts +38 -0
- package/src/resolvers/index.ts +117 -0
- package/src/resolvers/inputs.ts +23 -0
- package/src/schema-utils.ts +154 -0
- package/src/schemas/Action.ts +40 -0
- package/src/schemas/App.ts +43 -0
- package/src/schemas/Auth.ts +54 -0
- package/src/schemas/Field.ts +34 -0
- package/src/sdk.ts +165 -19
- package/src/types/domain.ts +54 -0
- package/src/types/properties.ts +67 -0
- package/src/types/sdk.ts +46 -0
- package/dist/actions-sdk.d.ts +0 -47
- package/dist/actions-sdk.js +0 -208
- package/dist/api.d.ts +0 -62
- package/dist/api.js +0 -227
- package/dist/output-schemas.d.ts +0 -95
- package/dist/output-schemas.js +0 -138
- package/dist/schemas.d.ts +0 -338
- package/dist/schemas.js +0 -336
- package/dist/types.js +0 -41
- package/src/actions-sdk.ts +0 -356
- package/src/api.ts +0 -361
- package/src/output-schemas.ts +0 -196
- package/src/schemas.ts +0 -467
- package/src/types.ts +0 -257
- /package/dist/functions/{bundleCode.js → bundleCode/index.js} +0 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { OutputPropertySchema } from "../../types/properties";
|
|
3
|
+
|
|
4
|
+
// Pure Zod schema - no resolver metadata!
|
|
5
|
+
export const BundleCodeSchema = z
|
|
6
|
+
.object({
|
|
7
|
+
input: z.string().min(1).describe("Input TypeScript file path to bundle"),
|
|
8
|
+
output: OutputPropertySchema.optional().describe(
|
|
9
|
+
"Output file path (defaults to input with .js extension)",
|
|
10
|
+
),
|
|
11
|
+
string: z
|
|
12
|
+
.boolean()
|
|
13
|
+
.default(false)
|
|
14
|
+
.describe("Return bundled code as string instead of writing to file"),
|
|
15
|
+
minify: z.boolean().default(false).describe("Minify the bundled output"),
|
|
16
|
+
target: z.string().default("es2017").describe("ECMAScript target version"),
|
|
17
|
+
cjs: z
|
|
18
|
+
.boolean()
|
|
19
|
+
.default(false)
|
|
20
|
+
.describe("Output CommonJS format instead of ESM"),
|
|
21
|
+
})
|
|
22
|
+
.describe("Bundle TypeScript code into executable JavaScript");
|
|
23
|
+
|
|
24
|
+
// Type inferred from schema (no additional function config needed for bundleCode)
|
|
25
|
+
export type BundleCodeOptions = z.infer<typeof BundleCodeSchema>;
|
|
26
|
+
|
|
27
|
+
// SDK function interface - ready to be mixed into main SDK interface
|
|
28
|
+
export interface BundleCodeSdkFunction {
|
|
29
|
+
bundleCode: (options: BundleCodeOptions) => Promise<string>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Authentication } from "../../types/domain";
|
|
2
|
+
import { listAuthentications } from "../listAuthentications";
|
|
3
|
+
import type { FindFirstAuthenticationOptions } from "./schemas";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Find the first authentication matching the given criteria
|
|
7
|
+
*
|
|
8
|
+
* This function can be used standalone without instantiating a full SDK,
|
|
9
|
+
* which enables better tree-shaking in applications that only need this functionality.
|
|
10
|
+
*
|
|
11
|
+
* @param options - Filtering and API configuration options
|
|
12
|
+
* @returns Promise<Authentication | null> - First matching authentication or null if not found
|
|
13
|
+
*/
|
|
14
|
+
export async function findFirstAuthentication(
|
|
15
|
+
options: Partial<FindFirstAuthenticationOptions> = {},
|
|
16
|
+
): Promise<Authentication | null> {
|
|
17
|
+
// Use listAuthentications with limit 1 to get the first result
|
|
18
|
+
const auths = await listAuthentications({
|
|
19
|
+
...options,
|
|
20
|
+
limit: 1,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
return auths.length > 0 ? auths[0] : null;
|
|
24
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { findFirstAuthentication } from "./index";
|
|
2
|
+
import { FindFirstAuthenticationSchema } from "./schemas";
|
|
3
|
+
|
|
4
|
+
// Function registry info - imports both function and schema
|
|
5
|
+
export const findFirstAuthenticationInfo = {
|
|
6
|
+
name: findFirstAuthentication.name,
|
|
7
|
+
inputSchema: FindFirstAuthenticationSchema,
|
|
8
|
+
implementation: findFirstAuthentication,
|
|
9
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
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 } from "../../types/domain";
|
|
10
|
+
|
|
11
|
+
// Pure Zod schema - no resolver metadata!
|
|
12
|
+
export const FindFirstAuthenticationSchema = 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("Find the first authentication matching the criteria"),
|
|
36
|
+
AuthItemSchema,
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
// Type inferred from schema + function config
|
|
40
|
+
export type FindFirstAuthenticationOptions = z.infer<
|
|
41
|
+
typeof FindFirstAuthenticationSchema
|
|
42
|
+
> & {
|
|
43
|
+
/** Base URL for Zapier API */
|
|
44
|
+
baseUrl?: string;
|
|
45
|
+
/** Authentication token */
|
|
46
|
+
token?: string;
|
|
47
|
+
/** Optional pre-instantiated API client */
|
|
48
|
+
api?: any;
|
|
49
|
+
/** Enable debug logging */
|
|
50
|
+
debug?: boolean;
|
|
51
|
+
/** Custom fetch implementation */
|
|
52
|
+
fetch?: typeof globalThis.fetch;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// SDK function interface - ready to be mixed into main SDK interface
|
|
56
|
+
export interface FindFirstAuthenticationSdkFunction {
|
|
57
|
+
findFirstAuthentication: (
|
|
58
|
+
options?: Partial<FindFirstAuthenticationOptions>,
|
|
59
|
+
) => Promise<Authentication | null>;
|
|
60
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Authentication } from "../../types/domain";
|
|
2
|
+
import { listAuthentications } from "../listAuthentications";
|
|
3
|
+
import type { FindUniqueAuthenticationOptions } from "./schemas";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Find a unique authentication matching the given criteria
|
|
7
|
+
*
|
|
8
|
+
* This function can be used standalone without instantiating a full SDK,
|
|
9
|
+
* which enables better tree-shaking in applications that only need this functionality.
|
|
10
|
+
*
|
|
11
|
+
* @param options - Filtering and API configuration options
|
|
12
|
+
* @returns Promise<Authentication> - The unique matching authentication
|
|
13
|
+
* @throws Error if no authentication found or multiple authentications found
|
|
14
|
+
*/
|
|
15
|
+
export async function findUniqueAuthentication(
|
|
16
|
+
options: Partial<FindUniqueAuthenticationOptions> = {},
|
|
17
|
+
): Promise<Authentication> {
|
|
18
|
+
// Use listAuthentications with a reasonable limit to check for uniqueness
|
|
19
|
+
const auths = await listAuthentications({
|
|
20
|
+
...options,
|
|
21
|
+
limit: 2, // Get up to 2 to check for uniqueness
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
if (auths.length === 0) {
|
|
25
|
+
throw new Error("No authentication found matching the specified criteria");
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (auths.length > 1) {
|
|
29
|
+
throw new Error(
|
|
30
|
+
"Multiple authentications found matching the specified criteria. Expected exactly one.",
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return auths[0];
|
|
35
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { findUniqueAuthentication } from "./index";
|
|
2
|
+
import { FindUniqueAuthenticationSchema } from "./schemas";
|
|
3
|
+
|
|
4
|
+
// Function registry info - imports both function and schema
|
|
5
|
+
export const findUniqueAuthenticationInfo = {
|
|
6
|
+
name: findUniqueAuthentication.name,
|
|
7
|
+
inputSchema: FindUniqueAuthenticationSchema,
|
|
8
|
+
implementation: findUniqueAuthentication,
|
|
9
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
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 } from "../../types/domain";
|
|
10
|
+
|
|
11
|
+
// Pure Zod schema - no resolver metadata!
|
|
12
|
+
export const FindUniqueAuthenticationSchema = 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("Find a unique authentication matching the criteria"),
|
|
36
|
+
AuthItemSchema,
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
// Type inferred from schema + function config
|
|
40
|
+
export type FindUniqueAuthenticationOptions = z.infer<
|
|
41
|
+
typeof FindUniqueAuthenticationSchema
|
|
42
|
+
> & {
|
|
43
|
+
/** Base URL for Zapier API */
|
|
44
|
+
baseUrl?: string;
|
|
45
|
+
/** Authentication token */
|
|
46
|
+
token?: string;
|
|
47
|
+
/** Optional pre-instantiated API client */
|
|
48
|
+
api?: any;
|
|
49
|
+
/** Enable debug logging */
|
|
50
|
+
debug?: boolean;
|
|
51
|
+
/** Custom fetch implementation */
|
|
52
|
+
fetch?: typeof globalThis.fetch;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// SDK function interface - ready to be mixed into main SDK interface
|
|
56
|
+
export interface FindUniqueAuthenticationSdkFunction {
|
|
57
|
+
findUniqueAuthentication: (
|
|
58
|
+
options?: Partial<FindUniqueAuthenticationOptions>,
|
|
59
|
+
) => Promise<Authentication>;
|
|
60
|
+
}
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
import type { Action, ActionField
|
|
2
|
-
import { listActions } from "
|
|
3
|
-
import { listFields } from "
|
|
4
|
-
|
|
5
|
-
export interface GenerateTypesOptions extends FunctionConfig {
|
|
6
|
-
appKey: string;
|
|
7
|
-
authId?: number;
|
|
8
|
-
output?: string;
|
|
9
|
-
}
|
|
1
|
+
import type { Action, ActionField } from "../../types/domain";
|
|
2
|
+
import { listActions } from "../listActions";
|
|
3
|
+
import { listFields } from "../listFields";
|
|
4
|
+
import type { GenerateTypesOptions } from "./schemas";
|
|
10
5
|
|
|
11
6
|
interface ActionWithActionFields extends Omit<Action, "inputFields"> {
|
|
12
7
|
inputFields: ActionField[];
|
|
@@ -18,13 +13,17 @@ interface ActionWithActionFields extends Omit<Action, "inputFields"> {
|
|
|
18
13
|
* This function can be used standalone without instantiating a full SDK,
|
|
19
14
|
* which enables better tree-shaking in applications that only need this functionality.
|
|
20
15
|
*
|
|
21
|
-
* @param options - App key,
|
|
16
|
+
* @param options - App key, authentication ID, output path, and API configuration options
|
|
22
17
|
* @returns Promise<string> - Generated TypeScript code
|
|
23
18
|
*/
|
|
24
19
|
export async function generateTypes(
|
|
25
20
|
options: GenerateTypesOptions,
|
|
26
21
|
): Promise<string> {
|
|
27
|
-
const {
|
|
22
|
+
const {
|
|
23
|
+
appKey,
|
|
24
|
+
authenticationId,
|
|
25
|
+
output = `./types/${appKey}.d.ts`,
|
|
26
|
+
} = options;
|
|
28
27
|
|
|
29
28
|
// Parse app identifier (support app@version format)
|
|
30
29
|
const { app, version } = parseAppIdentifier(appKey);
|
|
@@ -51,15 +50,15 @@ export async function generateTypes(
|
|
|
51
50
|
// Fetch input fields for each action
|
|
52
51
|
const actionsWithFields: ActionWithActionFields[] = [];
|
|
53
52
|
|
|
54
|
-
if (
|
|
53
|
+
if (authenticationId) {
|
|
55
54
|
for (const action of actions) {
|
|
56
55
|
try {
|
|
57
56
|
const fields = await listFields({
|
|
58
57
|
...options,
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
58
|
+
appKey: action.appKey,
|
|
59
|
+
actionKey: action.key,
|
|
60
|
+
actionType: action.type,
|
|
61
|
+
authenticationId: authenticationId,
|
|
63
62
|
});
|
|
64
63
|
actionsWithFields.push({ ...action, inputFields: fields });
|
|
65
64
|
} catch {
|
|
@@ -137,8 +136,15 @@ ${versionComment}
|
|
|
137
136
|
* Generated on: ${new Date().toISOString()}
|
|
138
137
|
*
|
|
139
138
|
* Usage:
|
|
140
|
-
* import type { ${appName}
|
|
141
|
-
* const sdk
|
|
139
|
+
* import type { ${appName}Sdk } from './path/to/this/file'
|
|
140
|
+
* const sdk = createZapierSdk() as unknown as ${appName}Sdk
|
|
141
|
+
*
|
|
142
|
+
* // Direct usage (per-call auth):
|
|
143
|
+
* await sdk.apps.${appKey}.search.user_by_email({ authenticationId: 123, inputs: { email } })
|
|
144
|
+
*
|
|
145
|
+
* // Factory usage (pinned auth):
|
|
146
|
+
* const my${appName} = sdk.apps.${appKey}({ authenticationId: 123 })
|
|
147
|
+
* await my${appName}.search.user_by_email({ inputs: { email } })
|
|
142
148
|
*/
|
|
143
149
|
|
|
144
150
|
import type { ActionExecutionOptions, ActionExecutionResult } from '@zapier/zapier-sdk'
|
|
@@ -197,17 +203,28 @@ import type { ActionExecutionOptions, ActionExecutionResult } from '@zapier/zapi
|
|
|
197
203
|
output += `}\n\n`;
|
|
198
204
|
});
|
|
199
205
|
|
|
200
|
-
// Generate the main app
|
|
201
|
-
output += `export interface ${appName}Actions {\n`;
|
|
202
|
-
output += ` run: {\n`;
|
|
203
|
-
output += ` ${appKey}: {\n`;
|
|
206
|
+
// Generate the main app SDK interface with factory pattern support
|
|
204
207
|
|
|
208
|
+
// Generate the app proxy interface (actions grouped by type)
|
|
209
|
+
output += `interface ${appName}AppProxy {\n`;
|
|
205
210
|
Object.keys(actionsByType).forEach((actionType) => {
|
|
206
211
|
const typeName = `${appName}${capitalize(actionType)}Actions`;
|
|
207
|
-
output += `
|
|
212
|
+
output += ` ${actionType}: ${typeName}\n`;
|
|
208
213
|
});
|
|
214
|
+
output += `}\n\n`;
|
|
215
|
+
|
|
216
|
+
// Generate the factory function interface
|
|
217
|
+
output += `interface ${appName}AppFactory {\n`;
|
|
218
|
+
output += ` (options: { authenticationId: number }): ${appName}AppProxy\n`;
|
|
219
|
+
output += `}\n\n`;
|
|
209
220
|
|
|
210
|
-
|
|
221
|
+
// Combine factory and direct access
|
|
222
|
+
output += `type ${appName}AppWithFactory = ${appName}AppFactory & ${appName}AppProxy\n\n`;
|
|
223
|
+
|
|
224
|
+
// Generate the main SDK interface
|
|
225
|
+
output += `export interface ${appName}Sdk {\n`;
|
|
226
|
+
output += ` apps: {\n`;
|
|
227
|
+
output += ` ${appKey}: ${appName}AppWithFactory\n`;
|
|
211
228
|
output += ` }\n`;
|
|
212
229
|
output += `}\n`;
|
|
213
230
|
|
|
@@ -231,11 +248,19 @@ ${versionComment}
|
|
|
231
248
|
|
|
232
249
|
import type { ActionExecutionOptions, ActionExecutionResult } from '@zapier/zapier-sdk'
|
|
233
250
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
251
|
+
interface ${appName}AppProxy {
|
|
252
|
+
// No actions available
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
interface ${appName}AppFactory {
|
|
256
|
+
(options: { authenticationId: number }): ${appName}AppProxy
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
type ${appName}AppWithFactory = ${appName}AppFactory & ${appName}AppProxy
|
|
260
|
+
|
|
261
|
+
export interface ${appName}Sdk {
|
|
262
|
+
apps: {
|
|
263
|
+
${appKey}: ${appName}AppWithFactory
|
|
239
264
|
}
|
|
240
265
|
}
|
|
241
266
|
`;
|
|
@@ -247,12 +272,26 @@ function capitalize(str: string): string {
|
|
|
247
272
|
|
|
248
273
|
function sanitizeActionName(actionKey: string): string {
|
|
249
274
|
// Ensure the action name is a valid TypeScript identifier
|
|
250
|
-
|
|
275
|
+
let sanitized = actionKey.replace(/[^a-zA-Z0-9_$]/g, "_");
|
|
276
|
+
|
|
277
|
+
// If it starts with a number, prepend an underscore
|
|
278
|
+
if (/^[0-9]/.test(sanitized)) {
|
|
279
|
+
sanitized = "_" + sanitized;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
return sanitized;
|
|
251
283
|
}
|
|
252
284
|
|
|
253
285
|
function sanitizeFieldName(fieldKey: string): string {
|
|
254
286
|
// Ensure the field name is a valid TypeScript identifier
|
|
255
|
-
|
|
287
|
+
let sanitized = fieldKey.replace(/[^a-zA-Z0-9_$]/g, "_");
|
|
288
|
+
|
|
289
|
+
// If it starts with a number, prepend an underscore
|
|
290
|
+
if (/^[0-9]/.test(sanitized)) {
|
|
291
|
+
sanitized = "_" + sanitized;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
return sanitized;
|
|
256
295
|
}
|
|
257
296
|
|
|
258
297
|
function escapeComment(comment: string): string {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { generateTypes } from "./index";
|
|
2
|
+
import { GenerateTypesSchema } from "./schemas";
|
|
3
|
+
|
|
4
|
+
// Function registry info - imports both function and schema
|
|
5
|
+
export const generateTypesInfo = {
|
|
6
|
+
name: generateTypes.name,
|
|
7
|
+
inputSchema: GenerateTypesSchema,
|
|
8
|
+
implementation: generateTypes,
|
|
9
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import {
|
|
3
|
+
AppKeyPropertySchema,
|
|
4
|
+
AuthenticationIdPropertySchema,
|
|
5
|
+
OutputPropertySchema,
|
|
6
|
+
DebugPropertySchema,
|
|
7
|
+
} from "../../types/properties";
|
|
8
|
+
|
|
9
|
+
// Pure Zod schema - no resolver metadata!
|
|
10
|
+
export const GenerateTypesSchema = z
|
|
11
|
+
.object({
|
|
12
|
+
appKey: AppKeyPropertySchema.describe("App key to generate SDK code for"),
|
|
13
|
+
authenticationId: AuthenticationIdPropertySchema.optional(),
|
|
14
|
+
output: OutputPropertySchema.optional().describe(
|
|
15
|
+
"Output file path (defaults to generated/<appKey>.ts)",
|
|
16
|
+
),
|
|
17
|
+
debug: DebugPropertySchema.describe(
|
|
18
|
+
"Enable debug logging during generation",
|
|
19
|
+
),
|
|
20
|
+
})
|
|
21
|
+
.describe("Generate TypeScript SDK code for a specific app");
|
|
22
|
+
|
|
23
|
+
// Type inferred from schema + function config
|
|
24
|
+
export type GenerateTypesOptions = z.infer<typeof GenerateTypesSchema> & {
|
|
25
|
+
/** Base URL for Zapier API */
|
|
26
|
+
baseUrl?: string;
|
|
27
|
+
/** Authentication token */
|
|
28
|
+
token?: string;
|
|
29
|
+
/** Optional pre-instantiated API client */
|
|
30
|
+
api?: any;
|
|
31
|
+
/** Custom fetch implementation */
|
|
32
|
+
fetch?: typeof globalThis.fetch;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// SDK function interface - ready to be mixed into main SDK interface
|
|
36
|
+
export interface GenerateTypesSdkFunction {
|
|
37
|
+
generateTypes: (options: GenerateTypesOptions) => Promise<string>;
|
|
38
|
+
}
|
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
import type { Action
|
|
2
|
-
import { listActions } from "
|
|
3
|
-
|
|
4
|
-
export interface GetActionOptions extends FunctionConfig {
|
|
5
|
-
app: string;
|
|
6
|
-
action: string;
|
|
7
|
-
type: string;
|
|
8
|
-
}
|
|
1
|
+
import type { Action } from "../../types/domain";
|
|
2
|
+
import { listActions } from "../listActions";
|
|
3
|
+
import type { GetActionOptions } from "./schemas";
|
|
9
4
|
|
|
10
5
|
/**
|
|
11
6
|
* Get a specific action by app, action key, and type
|
|
@@ -17,18 +12,22 @@ export interface GetActionOptions extends FunctionConfig {
|
|
|
17
12
|
* @returns Promise<Action>
|
|
18
13
|
*/
|
|
19
14
|
export async function getAction(options: GetActionOptions): Promise<Action> {
|
|
20
|
-
const {
|
|
15
|
+
const { appKey, actionKey, actionType } = options;
|
|
21
16
|
|
|
22
17
|
const actions = await listActions({
|
|
23
18
|
...options,
|
|
24
|
-
appKey:
|
|
19
|
+
appKey: appKey,
|
|
25
20
|
});
|
|
26
21
|
|
|
27
|
-
const action = actions.find(
|
|
22
|
+
const action = actions.find(
|
|
23
|
+
(a) => a.key === actionKey && a.type === actionType,
|
|
24
|
+
);
|
|
28
25
|
|
|
29
26
|
if (!action) {
|
|
30
|
-
throw new Error(`Action not found: ${actionKey} with type ${
|
|
27
|
+
throw new Error(`Action not found: ${actionKey} with type ${actionType}`);
|
|
31
28
|
}
|
|
32
29
|
|
|
33
30
|
return action;
|
|
34
31
|
}
|
|
32
|
+
|
|
33
|
+
// No registry info here - moved to info.ts for proper tree-shaking
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { getAction } from "./index";
|
|
2
|
+
import { GetActionSchema } from "./schemas";
|
|
3
|
+
|
|
4
|
+
// Function registry info - imports both function and schema
|
|
5
|
+
export const getActionInfo = {
|
|
6
|
+
name: getAction.name,
|
|
7
|
+
inputSchema: GetActionSchema,
|
|
8
|
+
implementation: getAction,
|
|
9
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import {
|
|
3
|
+
AppKeyPropertySchema,
|
|
4
|
+
ActionTypePropertySchema,
|
|
5
|
+
ActionKeyPropertySchema,
|
|
6
|
+
} from "../../types/properties";
|
|
7
|
+
import type { Action } from "../../types/domain";
|
|
8
|
+
|
|
9
|
+
// Pure Zod schema - no resolver metadata!
|
|
10
|
+
export const GetActionSchema = z
|
|
11
|
+
.object({
|
|
12
|
+
appKey: AppKeyPropertySchema,
|
|
13
|
+
actionType: ActionTypePropertySchema,
|
|
14
|
+
actionKey: ActionKeyPropertySchema,
|
|
15
|
+
})
|
|
16
|
+
.describe("Get detailed information about a specific action");
|
|
17
|
+
|
|
18
|
+
// Type inferred from schema + function config
|
|
19
|
+
export type GetActionOptions = z.infer<typeof GetActionSchema> & {
|
|
20
|
+
/** Base URL for Zapier API */
|
|
21
|
+
baseUrl?: string;
|
|
22
|
+
/** Authentication token */
|
|
23
|
+
token?: string;
|
|
24
|
+
/** Optional pre-instantiated API client */
|
|
25
|
+
api?: any;
|
|
26
|
+
/** Enable debug logging */
|
|
27
|
+
debug?: boolean;
|
|
28
|
+
/** Custom fetch implementation */
|
|
29
|
+
fetch?: typeof globalThis.fetch;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// SDK function interface - ready to be mixed into main SDK interface
|
|
33
|
+
export interface GetActionSdkFunction {
|
|
34
|
+
getAction: (options: GetActionOptions) => Promise<Action>;
|
|
35
|
+
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { getOrCreateApiClient } from "
|
|
2
|
-
import type { Integration
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
key: string;
|
|
6
|
-
}
|
|
1
|
+
import { getOrCreateApiClient } from "../../api";
|
|
2
|
+
import type { Integration } from "../../types/domain";
|
|
3
|
+
import { AppNotFoundError } from "../../types/domain";
|
|
4
|
+
import type { GetAppOptions } from "./schemas";
|
|
7
5
|
|
|
8
6
|
/**
|
|
9
7
|
* Get a specific app by key
|
|
@@ -17,18 +15,12 @@ export interface GetAppOptions extends FunctionConfig {
|
|
|
17
15
|
export async function getApp(options: GetAppOptions): Promise<Integration> {
|
|
18
16
|
const api = getOrCreateApiClient(options);
|
|
19
17
|
|
|
20
|
-
const {
|
|
18
|
+
const { appKey } = options;
|
|
21
19
|
|
|
22
|
-
const app = await api.get(`/api/v4/apps/${
|
|
20
|
+
const app = await api.get(`/api/v4/apps/${appKey}/`, {
|
|
23
21
|
customErrorHandler: (response) => {
|
|
24
22
|
if (response.status === 404) {
|
|
25
|
-
|
|
26
|
-
constructor(appKey: string) {
|
|
27
|
-
super(`App not found: ${appKey}`);
|
|
28
|
-
this.name = "AppNotFoundError";
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
return new AppNotFoundError(key);
|
|
23
|
+
return new AppNotFoundError(appKey);
|
|
32
24
|
}
|
|
33
25
|
return undefined;
|
|
34
26
|
},
|
|
@@ -45,3 +37,5 @@ export async function getApp(options: GetAppOptions): Promise<Integration> {
|
|
|
45
37
|
current_implementation_id: app.current_implementation_id,
|
|
46
38
|
};
|
|
47
39
|
}
|
|
40
|
+
|
|
41
|
+
// No registry info here - moved to info.ts for proper tree-shaking
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { AppKeyPropertySchema } from "../../types/properties";
|
|
3
|
+
import type { Integration } from "../../types/domain";
|
|
4
|
+
|
|
5
|
+
// Pure Zod schema - no resolver metadata!
|
|
6
|
+
export const GetAppSchema = z
|
|
7
|
+
.object({
|
|
8
|
+
appKey: AppKeyPropertySchema.describe(
|
|
9
|
+
"App key or slug to fetch (e.g., google-sheets, slack, github)",
|
|
10
|
+
),
|
|
11
|
+
})
|
|
12
|
+
.describe("Get detailed information about a specific app");
|
|
13
|
+
|
|
14
|
+
// Type inferred from schema + function config
|
|
15
|
+
export type GetAppOptions = z.infer<typeof GetAppSchema> & {
|
|
16
|
+
/** Base URL for Zapier API */
|
|
17
|
+
baseUrl?: string;
|
|
18
|
+
/** Authentication token */
|
|
19
|
+
token?: string;
|
|
20
|
+
/** Optional pre-instantiated API client */
|
|
21
|
+
api?: any;
|
|
22
|
+
/** Enable debug logging */
|
|
23
|
+
debug?: boolean;
|
|
24
|
+
/** Custom fetch implementation */
|
|
25
|
+
fetch?: typeof globalThis.fetch;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// SDK function interface - ready to be mixed into main SDK interface
|
|
29
|
+
export interface GetAppSdkFunction {
|
|
30
|
+
getApp: (options: GetAppOptions) => Promise<Integration>;
|
|
31
|
+
}
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import { getOrCreateApiClient } from "
|
|
2
|
-
import type { Action
|
|
3
|
-
import { getApp } from "
|
|
4
|
-
|
|
5
|
-
export interface ListActionsOptions extends FunctionConfig {
|
|
6
|
-
appKey?: string;
|
|
7
|
-
type?: string;
|
|
8
|
-
}
|
|
1
|
+
import { getOrCreateApiClient } from "../../api";
|
|
2
|
+
import type { Action } from "../../types/domain";
|
|
3
|
+
import { getApp } from "../getApp";
|
|
4
|
+
import type { ListActionsOptions } from "./schemas";
|
|
9
5
|
|
|
10
6
|
/**
|
|
11
7
|
* List available actions with optional filtering
|
|
@@ -17,7 +13,7 @@ export interface ListActionsOptions extends FunctionConfig {
|
|
|
17
13
|
* @returns Promise<Action[]> with pagination metadata
|
|
18
14
|
*/
|
|
19
15
|
export async function listActions(
|
|
20
|
-
options: ListActionsOptions = {},
|
|
16
|
+
options: Partial<ListActionsOptions> = {},
|
|
21
17
|
): Promise<Action[]> {
|
|
22
18
|
const api = getOrCreateApiClient(options);
|
|
23
19
|
|
|
@@ -26,7 +22,7 @@ export async function listActions(
|
|
|
26
22
|
try {
|
|
27
23
|
// Use the standalone getApp function
|
|
28
24
|
const appData = await getApp({
|
|
29
|
-
|
|
25
|
+
appKey: options.appKey,
|
|
30
26
|
api,
|
|
31
27
|
token: options.token,
|
|
32
28
|
baseUrl: options.baseUrl,
|
|
@@ -149,3 +145,5 @@ export async function listActions(
|
|
|
149
145
|
|
|
150
146
|
return actions;
|
|
151
147
|
}
|
|
148
|
+
|
|
149
|
+
// No registry info here - moved to info.ts for proper tree-shaking
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { listActions } from "./index";
|
|
2
|
+
import { ListActionsSchema } from "./schemas";
|
|
3
|
+
|
|
4
|
+
// Function registry info - imports both function and schema
|
|
5
|
+
export const listActionsInfo = {
|
|
6
|
+
name: listActions.name,
|
|
7
|
+
inputSchema: ListActionsSchema,
|
|
8
|
+
implementation: listActions,
|
|
9
|
+
};
|