@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.
Files changed (189) hide show
  1. package/dist/api/auth.d.ts +8 -0
  2. package/dist/api/auth.js +29 -0
  3. package/dist/api/client.d.ts +8 -0
  4. package/dist/api/client.js +102 -0
  5. package/dist/api/debug.d.ts +12 -0
  6. package/dist/api/debug.js +50 -0
  7. package/dist/api/index.d.ts +26 -0
  8. package/dist/api/index.js +51 -0
  9. package/dist/api/polling.d.ts +17 -0
  10. package/dist/api/polling.js +34 -0
  11. package/dist/{types.d.ts → api/types.d.ts} +37 -88
  12. package/dist/api/types.js +9 -0
  13. package/dist/functions/{bundleCode.d.ts → bundleCode/index.d.ts} +1 -8
  14. package/dist/functions/bundleCode/info.d.ts +27 -0
  15. package/dist/functions/bundleCode/info.js +11 -0
  16. package/dist/functions/bundleCode/schemas.d.ts +27 -0
  17. package/dist/functions/bundleCode/schemas.js +22 -0
  18. package/dist/functions/findFirstAuthentication/index.d.ts +12 -0
  19. package/dist/functions/findFirstAuthentication/index.js +21 -0
  20. package/dist/functions/findFirstAuthentication/info.d.ts +30 -0
  21. package/dist/functions/findFirstAuthentication/info.js +11 -0
  22. package/dist/functions/findFirstAuthentication/schemas.d.ts +42 -0
  23. package/dist/functions/findFirstAuthentication/schemas.js +25 -0
  24. package/dist/functions/findUniqueAuthentication/index.d.ts +13 -0
  25. package/dist/functions/findUniqueAuthentication/index.js +28 -0
  26. package/dist/functions/findUniqueAuthentication/info.d.ts +30 -0
  27. package/dist/functions/findUniqueAuthentication/info.js +11 -0
  28. package/dist/functions/findUniqueAuthentication/schemas.d.ts +42 -0
  29. package/dist/functions/findUniqueAuthentication/schemas.js +25 -0
  30. package/dist/functions/{generateTypes.d.ts → generateTypes/index.d.ts} +2 -7
  31. package/dist/functions/{generateTypes.js → generateTypes/index.js} +58 -24
  32. package/dist/functions/generateTypes/info.d.ts +21 -0
  33. package/dist/functions/generateTypes/info.js +11 -0
  34. package/dist/functions/generateTypes/schemas.d.ts +30 -0
  35. package/dist/functions/generateTypes/schemas.js +14 -0
  36. package/dist/functions/{getAction.d.ts → getAction/index.d.ts} +2 -6
  37. package/dist/functions/{getAction.js → getAction/index.js} +6 -5
  38. package/dist/functions/getAction/info.d.ts +18 -0
  39. package/dist/functions/getAction/info.js +11 -0
  40. package/dist/functions/getAction/schemas.d.ts +30 -0
  41. package/dist/functions/getAction/schemas.js +13 -0
  42. package/dist/functions/{getApp.d.ts → getApp/index.d.ts} +2 -4
  43. package/dist/functions/{getApp.js → getApp/index.js} +6 -10
  44. package/dist/functions/getApp/info.d.ts +12 -0
  45. package/dist/functions/getApp/info.js +11 -0
  46. package/dist/functions/getApp/schemas.d.ts +24 -0
  47. package/dist/functions/getApp/schemas.js +11 -0
  48. package/dist/functions/{listActions.d.ts → listActions/index.d.ts} +3 -6
  49. package/dist/functions/{listActions.js → listActions/index.js} +4 -3
  50. package/dist/functions/listActions/info.d.ts +15 -0
  51. package/dist/functions/listActions/info.js +11 -0
  52. package/dist/functions/listActions/schemas.d.ts +27 -0
  53. package/dist/functions/listActions/schemas.js +14 -0
  54. package/dist/functions/{listApps.d.ts → listApps/index.d.ts} +2 -6
  55. package/dist/functions/{listApps.js → listApps/index.js} +1 -1
  56. package/dist/functions/listApps/info.d.ts +18 -0
  57. package/dist/functions/listApps/info.js +11 -0
  58. package/dist/functions/listApps/schemas.d.ts +30 -0
  59. package/dist/functions/listApps/schemas.js +15 -0
  60. package/dist/functions/{listAuths.d.ts → listAuthentications/index.d.ts} +3 -9
  61. package/dist/functions/{listAuths.js → listAuthentications/index.js} +28 -12
  62. package/dist/functions/listAuthentications/info.d.ts +30 -0
  63. package/dist/functions/listAuthentications/info.js +11 -0
  64. package/dist/functions/listAuthentications/schemas.d.ts +42 -0
  65. package/dist/functions/listAuthentications/schemas.js +25 -0
  66. package/dist/functions/{listFields.d.ts → listFields/index.d.ts} +3 -9
  67. package/dist/functions/{listFields.js → listFields/index.js} +8 -10
  68. package/dist/functions/listFields/info.d.ts +24 -0
  69. package/dist/functions/listFields/info.js +11 -0
  70. package/dist/functions/listFields/schemas.d.ts +36 -0
  71. package/dist/functions/listFields/schemas.js +17 -0
  72. package/dist/functions/{runAction.d.ts → runAction/index.d.ts} +2 -8
  73. package/dist/functions/{runAction.js → runAction/index.js} +15 -14
  74. package/dist/functions/runAction/info.d.ts +24 -0
  75. package/dist/functions/runAction/info.js +11 -0
  76. package/dist/functions/runAction/schemas.d.ts +36 -0
  77. package/dist/functions/runAction/schemas.js +15 -0
  78. package/dist/index.d.ts +10 -4
  79. package/dist/index.js +17 -6
  80. package/dist/plugins/apps/index.d.ts +8 -0
  81. package/dist/plugins/apps/index.js +77 -0
  82. package/dist/plugins/apps/info.d.ts +6 -0
  83. package/dist/plugins/apps/info.js +13 -0
  84. package/dist/plugins/apps/types.d.ts +21 -0
  85. package/dist/plugins/apps/types.js +2 -0
  86. package/dist/resolvers/actionKey.d.ts +8 -0
  87. package/dist/resolvers/actionKey.js +20 -0
  88. package/dist/resolvers/actionType.d.ts +8 -0
  89. package/dist/resolvers/actionType.js +21 -0
  90. package/dist/resolvers/appKey.d.ts +6 -0
  91. package/dist/resolvers/appKey.js +8 -0
  92. package/dist/resolvers/authenticationId.d.ts +8 -0
  93. package/dist/resolvers/authenticationId.js +29 -0
  94. package/dist/resolvers/index.d.ts +39 -0
  95. package/dist/resolvers/index.js +105 -0
  96. package/dist/resolvers/inputs.d.ts +7 -0
  97. package/dist/resolvers/inputs.js +15 -0
  98. package/dist/schema-utils.d.ts +44 -0
  99. package/dist/schema-utils.js +76 -0
  100. package/dist/schemas/Action.d.ts +21 -0
  101. package/dist/schemas/Action.js +31 -0
  102. package/dist/schemas/App.d.ts +19 -0
  103. package/dist/schemas/App.js +32 -0
  104. package/dist/schemas/Auth.d.ts +27 -0
  105. package/dist/schemas/Auth.js +42 -0
  106. package/dist/schemas/Field.d.ts +15 -0
  107. package/dist/schemas/Field.js +25 -0
  108. package/dist/sdk.d.ts +3 -4
  109. package/dist/sdk.js +104 -11
  110. package/dist/types/domain.d.ts +22 -0
  111. package/dist/types/domain.js +21 -0
  112. package/dist/types/properties.d.ts +21 -0
  113. package/dist/types/properties.js +43 -0
  114. package/dist/types/sdk.d.ts +23 -0
  115. package/dist/types/sdk.js +2 -0
  116. package/package.json +4 -2
  117. package/src/api/auth.ts +28 -0
  118. package/src/api/client.ts +148 -0
  119. package/src/api/debug.ts +58 -0
  120. package/src/api/index.ts +83 -0
  121. package/src/api/polling.ts +56 -0
  122. package/src/api/types.ts +177 -0
  123. package/src/functions/{bundleCode.ts → bundleCode/index.ts} +1 -8
  124. package/src/functions/bundleCode/info.ts +9 -0
  125. package/src/functions/bundleCode/schemas.ts +30 -0
  126. package/src/functions/findFirstAuthentication/index.ts +24 -0
  127. package/src/functions/findFirstAuthentication/info.ts +9 -0
  128. package/src/functions/findFirstAuthentication/schemas.ts +60 -0
  129. package/src/functions/findUniqueAuthentication/index.ts +35 -0
  130. package/src/functions/findUniqueAuthentication/info.ts +9 -0
  131. package/src/functions/findUniqueAuthentication/schemas.ts +60 -0
  132. package/src/functions/{generateTypes.ts → generateTypes/index.ts} +70 -31
  133. package/src/functions/generateTypes/info.ts +9 -0
  134. package/src/functions/generateTypes/schemas.ts +38 -0
  135. package/src/functions/{getAction.ts → getAction/index.ts} +11 -12
  136. package/src/functions/getAction/info.ts +9 -0
  137. package/src/functions/getAction/schemas.ts +35 -0
  138. package/src/functions/{getApp.ts → getApp/index.ts} +9 -15
  139. package/src/functions/getApp/info.ts +9 -0
  140. package/src/functions/getApp/schemas.ts +31 -0
  141. package/src/functions/{listActions.ts → listActions/index.ts} +8 -10
  142. package/src/functions/listActions/info.ts +9 -0
  143. package/src/functions/listActions/schemas.ts +40 -0
  144. package/src/functions/{listApps.ts → listApps/index.ts} +3 -8
  145. package/src/functions/listApps/info.ts +9 -0
  146. package/src/functions/listApps/schemas.ts +43 -0
  147. package/src/functions/{listAuths.ts → listAuthentications/index.ts} +32 -23
  148. package/src/functions/listAuthentications/info.ts +9 -0
  149. package/src/functions/listAuthentications/schemas.ts +60 -0
  150. package/src/functions/{listFields.ts → listFields/index.ts} +11 -20
  151. package/src/functions/listFields/info.ts +9 -0
  152. package/src/functions/listFields/schemas.ts +46 -0
  153. package/src/functions/{runAction.ts → runAction/index.ts} +25 -23
  154. package/src/functions/runAction/info.ts +9 -0
  155. package/src/functions/runAction/schemas.ts +41 -0
  156. package/src/index.ts +19 -5
  157. package/src/plugins/apps/index.ts +144 -0
  158. package/src/plugins/apps/info.ts +12 -0
  159. package/src/plugins/apps/types.ts +34 -0
  160. package/src/resolvers/actionKey.ts +33 -0
  161. package/src/resolvers/actionType.ts +30 -0
  162. package/src/resolvers/appKey.ts +11 -0
  163. package/src/resolvers/authenticationId.ts +38 -0
  164. package/src/resolvers/index.ts +117 -0
  165. package/src/resolvers/inputs.ts +23 -0
  166. package/src/schema-utils.ts +154 -0
  167. package/src/schemas/Action.ts +40 -0
  168. package/src/schemas/App.ts +43 -0
  169. package/src/schemas/Auth.ts +54 -0
  170. package/src/schemas/Field.ts +34 -0
  171. package/src/sdk.ts +165 -19
  172. package/src/types/domain.ts +54 -0
  173. package/src/types/properties.ts +67 -0
  174. package/src/types/sdk.ts +46 -0
  175. package/dist/actions-sdk.d.ts +0 -47
  176. package/dist/actions-sdk.js +0 -208
  177. package/dist/api.d.ts +0 -62
  178. package/dist/api.js +0 -227
  179. package/dist/output-schemas.d.ts +0 -95
  180. package/dist/output-schemas.js +0 -138
  181. package/dist/schemas.d.ts +0 -338
  182. package/dist/schemas.js +0 -336
  183. package/dist/types.js +0 -41
  184. package/src/actions-sdk.ts +0 -356
  185. package/src/api.ts +0 -361
  186. package/src/output-schemas.ts +0 -196
  187. package/src/schemas.ts +0 -467
  188. package/src/types.ts +0 -257
  189. /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, FunctionConfig } from "../types";
2
- import { listActions } from "./listActions";
3
- import { listFields } from "./listFields";
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, auth ID, output path, and API configuration options
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 { appKey, authId, output = `./types/${appKey}.d.ts` } = options;
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 (authId) {
53
+ if (authenticationId) {
55
54
  for (const action of actions) {
56
55
  try {
57
56
  const fields = await listFields({
58
57
  ...options,
59
- app: action.appKey,
60
- action: action.key,
61
- type: action.type,
62
- authId: authId,
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}Actions } from './path/to/this/file'
141
- * const sdk: ActionsSdk & { actions: ${appName}Actions } = createActionsSdk(...)
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 actions interface
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 += ` ${actionType}: ${typeName}\n`;
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
- output += ` }\n`;
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
- export interface ${appName}Actions {
235
- run: {
236
- ${appKey}: {
237
- // No actions available
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
- return actionKey.replace(/[^a-zA-Z0-9_$]/g, "_");
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
- return fieldKey.replace(/[^a-zA-Z0-9_$]/g, "_");
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, FunctionConfig } from "../types";
2
- import { listActions } from "./listActions";
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 { app, action: actionKey, type } = options;
15
+ const { appKey, actionKey, actionType } = options;
21
16
 
22
17
  const actions = await listActions({
23
18
  ...options,
24
- appKey: app,
19
+ appKey: appKey,
25
20
  });
26
21
 
27
- const action = actions.find((a) => a.key === actionKey && a.type === type);
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 ${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 "../api";
2
- import type { Integration, FunctionConfig } from "../types";
3
-
4
- export interface GetAppOptions extends FunctionConfig {
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 { key } = options;
18
+ const { appKey } = options;
21
19
 
22
- const app = await api.get(`/api/v4/apps/${key}/`, {
20
+ const app = await api.get(`/api/v4/apps/${appKey}/`, {
23
21
  customErrorHandler: (response) => {
24
22
  if (response.status === 404) {
25
- const AppNotFoundError = class extends Error {
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,9 @@
1
+ import { getApp } from "./index";
2
+ import { GetAppSchema } from "./schemas";
3
+
4
+ // Function registry info - imports both function and schema
5
+ export const getAppInfo = {
6
+ name: getApp.name,
7
+ inputSchema: GetAppSchema,
8
+ implementation: getApp,
9
+ };
@@ -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 "../api";
2
- import type { Action, FunctionConfig } from "../types";
3
- import { getApp } from "./getApp";
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
- key: options.appKey,
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
+ };