@zapier/zapier-sdk 0.0.3 → 0.1.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.
Files changed (171) 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/{generateTypes.d.ts → generateTypes/index.d.ts} +2 -7
  19. package/dist/functions/{generateTypes.js → generateTypes/index.js} +58 -24
  20. package/dist/functions/generateTypes/info.d.ts +21 -0
  21. package/dist/functions/generateTypes/info.js +11 -0
  22. package/dist/functions/generateTypes/schemas.d.ts +30 -0
  23. package/dist/functions/generateTypes/schemas.js +14 -0
  24. package/dist/functions/{getAction.d.ts → getAction/index.d.ts} +2 -6
  25. package/dist/functions/{getAction.js → getAction/index.js} +6 -5
  26. package/dist/functions/getAction/info.d.ts +18 -0
  27. package/dist/functions/getAction/info.js +11 -0
  28. package/dist/functions/getAction/schemas.d.ts +30 -0
  29. package/dist/functions/getAction/schemas.js +13 -0
  30. package/dist/functions/{getApp.d.ts → getApp/index.d.ts} +2 -4
  31. package/dist/functions/{getApp.js → getApp/index.js} +6 -10
  32. package/dist/functions/getApp/info.d.ts +12 -0
  33. package/dist/functions/getApp/info.js +11 -0
  34. package/dist/functions/getApp/schemas.d.ts +24 -0
  35. package/dist/functions/getApp/schemas.js +11 -0
  36. package/dist/functions/{listActions.d.ts → listActions/index.d.ts} +3 -6
  37. package/dist/functions/{listActions.js → listActions/index.js} +4 -3
  38. package/dist/functions/listActions/info.d.ts +15 -0
  39. package/dist/functions/listActions/info.js +11 -0
  40. package/dist/functions/listActions/schemas.d.ts +27 -0
  41. package/dist/functions/listActions/schemas.js +14 -0
  42. package/dist/functions/{listApps.d.ts → listApps/index.d.ts} +2 -6
  43. package/dist/functions/{listApps.js → listApps/index.js} +1 -1
  44. package/dist/functions/listApps/info.d.ts +18 -0
  45. package/dist/functions/listApps/info.js +11 -0
  46. package/dist/functions/listApps/schemas.d.ts +30 -0
  47. package/dist/functions/listApps/schemas.js +15 -0
  48. package/dist/functions/{listAuths.d.ts → listAuths/index.d.ts} +3 -9
  49. package/dist/functions/{listAuths.js → listAuths/index.js} +5 -5
  50. package/dist/functions/listAuths/info.d.ts +24 -0
  51. package/dist/functions/listAuths/info.js +11 -0
  52. package/dist/functions/listAuths/schemas.d.ts +36 -0
  53. package/dist/functions/listAuths/schemas.js +17 -0
  54. package/dist/functions/{listFields.d.ts → listFields/index.d.ts} +3 -9
  55. package/dist/functions/{listFields.js → listFields/index.js} +8 -10
  56. package/dist/functions/listFields/info.d.ts +24 -0
  57. package/dist/functions/listFields/info.js +11 -0
  58. package/dist/functions/listFields/schemas.d.ts +36 -0
  59. package/dist/functions/listFields/schemas.js +17 -0
  60. package/dist/functions/{runAction.d.ts → runAction/index.d.ts} +2 -8
  61. package/dist/functions/{runAction.js → runAction/index.js} +15 -14
  62. package/dist/functions/runAction/info.d.ts +24 -0
  63. package/dist/functions/runAction/info.js +11 -0
  64. package/dist/functions/runAction/schemas.d.ts +36 -0
  65. package/dist/functions/runAction/schemas.js +15 -0
  66. package/dist/index.d.ts +6 -3
  67. package/dist/index.js +7 -3
  68. package/dist/plugins/apps/index.d.ts +8 -0
  69. package/dist/plugins/apps/index.js +77 -0
  70. package/dist/plugins/apps/info.d.ts +6 -0
  71. package/dist/plugins/apps/info.js +13 -0
  72. package/dist/plugins/apps/types.d.ts +21 -0
  73. package/dist/plugins/apps/types.js +2 -0
  74. package/dist/resolvers/actionKey.d.ts +8 -0
  75. package/dist/resolvers/actionKey.js +20 -0
  76. package/dist/resolvers/actionType.d.ts +8 -0
  77. package/dist/resolvers/actionType.js +21 -0
  78. package/dist/resolvers/appKey.d.ts +6 -0
  79. package/dist/resolvers/appKey.js +8 -0
  80. package/dist/resolvers/authenticationId.d.ts +8 -0
  81. package/dist/resolvers/authenticationId.js +29 -0
  82. package/dist/resolvers/index.d.ts +39 -0
  83. package/dist/resolvers/index.js +105 -0
  84. package/dist/resolvers/inputs.d.ts +7 -0
  85. package/dist/resolvers/inputs.js +15 -0
  86. package/dist/schema-utils.d.ts +39 -0
  87. package/dist/schema-utils.js +52 -0
  88. package/dist/schemas/Action.d.ts +21 -0
  89. package/dist/schemas/Action.js +31 -0
  90. package/dist/schemas/App.d.ts +19 -0
  91. package/dist/schemas/App.js +32 -0
  92. package/dist/schemas/Auth.d.ts +30 -0
  93. package/dist/schemas/Auth.js +49 -0
  94. package/dist/schemas/Field.d.ts +15 -0
  95. package/dist/schemas/Field.js +25 -0
  96. package/dist/sdk.d.ts +3 -4
  97. package/dist/sdk.js +96 -11
  98. package/dist/types/domain.d.ts +22 -0
  99. package/dist/types/domain.js +21 -0
  100. package/dist/types/properties.d.ts +21 -0
  101. package/dist/types/properties.js +45 -0
  102. package/dist/types/sdk.d.ts +21 -0
  103. package/dist/types/sdk.js +2 -0
  104. package/package.json +4 -2
  105. package/src/api/auth.ts +28 -0
  106. package/src/api/client.ts +148 -0
  107. package/src/api/debug.ts +58 -0
  108. package/src/api/index.ts +83 -0
  109. package/src/api/polling.ts +56 -0
  110. package/src/api/types.ts +177 -0
  111. package/src/functions/{bundleCode.ts → bundleCode/index.ts} +1 -8
  112. package/src/functions/bundleCode/info.ts +9 -0
  113. package/src/functions/bundleCode/schemas.ts +30 -0
  114. package/src/functions/{generateTypes.ts → generateTypes/index.ts} +70 -31
  115. package/src/functions/generateTypes/info.ts +9 -0
  116. package/src/functions/generateTypes/schemas.ts +38 -0
  117. package/src/functions/{getAction.ts → getAction/index.ts} +11 -12
  118. package/src/functions/getAction/info.ts +9 -0
  119. package/src/functions/getAction/schemas.ts +35 -0
  120. package/src/functions/{getApp.ts → getApp/index.ts} +9 -15
  121. package/src/functions/getApp/info.ts +9 -0
  122. package/src/functions/getApp/schemas.ts +31 -0
  123. package/src/functions/{listActions.ts → listActions/index.ts} +8 -10
  124. package/src/functions/listActions/info.ts +9 -0
  125. package/src/functions/listActions/schemas.ts +40 -0
  126. package/src/functions/{listApps.ts → listApps/index.ts} +3 -8
  127. package/src/functions/listApps/info.ts +9 -0
  128. package/src/functions/listApps/schemas.ts +43 -0
  129. package/src/functions/{listAuths.ts → listAuths/index.ts} +8 -16
  130. package/src/functions/listAuths/info.ts +9 -0
  131. package/src/functions/listAuths/schemas.ts +48 -0
  132. package/src/functions/{listFields.ts → listFields/index.ts} +11 -20
  133. package/src/functions/listFields/info.ts +9 -0
  134. package/src/functions/listFields/schemas.ts +46 -0
  135. package/src/functions/{runAction.ts → runAction/index.ts} +25 -23
  136. package/src/functions/runAction/info.ts +9 -0
  137. package/src/functions/runAction/schemas.ts +41 -0
  138. package/src/index.ts +13 -4
  139. package/src/plugins/apps/index.ts +144 -0
  140. package/src/plugins/apps/info.ts +12 -0
  141. package/src/plugins/apps/types.ts +34 -0
  142. package/src/resolvers/actionKey.ts +33 -0
  143. package/src/resolvers/actionType.ts +30 -0
  144. package/src/resolvers/appKey.ts +11 -0
  145. package/src/resolvers/authenticationId.ts +38 -0
  146. package/src/resolvers/index.ts +117 -0
  147. package/src/resolvers/inputs.ts +23 -0
  148. package/src/schema-utils.ts +119 -0
  149. package/src/schemas/Action.ts +40 -0
  150. package/src/schemas/App.ts +43 -0
  151. package/src/schemas/Auth.ts +62 -0
  152. package/src/schemas/Field.ts +34 -0
  153. package/src/sdk.ts +153 -19
  154. package/src/types/domain.ts +54 -0
  155. package/src/types/properties.ts +67 -0
  156. package/src/types/sdk.ts +42 -0
  157. package/dist/actions-sdk.d.ts +0 -47
  158. package/dist/actions-sdk.js +0 -208
  159. package/dist/api.d.ts +0 -62
  160. package/dist/api.js +0 -227
  161. package/dist/output-schemas.d.ts +0 -95
  162. package/dist/output-schemas.js +0 -138
  163. package/dist/schemas.d.ts +0 -338
  164. package/dist/schemas.js +0 -336
  165. package/dist/types.js +0 -41
  166. package/src/actions-sdk.ts +0 -356
  167. package/src/api.ts +0 -361
  168. package/src/output-schemas.ts +0 -196
  169. package/src/schemas.ts +0 -467
  170. package/src/types.ts +0 -257
  171. /package/dist/functions/{bundleCode.js → bundleCode/index.js} +0 -0
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Zapier API Client Module
3
+ *
4
+ * This module provides a centralized API layer for all HTTP interactions
5
+ * with Zapier's various APIs. It handles authentication, error handling,
6
+ * polling, and provides consistent patterns across all services.
7
+ */
8
+
9
+ // Re-export all types
10
+ export type {
11
+ // API Client Infrastructure Types
12
+ ApiClient,
13
+ ApiClientOptions,
14
+ RequestOptions,
15
+ PollOptions,
16
+ DebugLogger,
17
+ // API Response Model Types
18
+ Integration,
19
+ Action,
20
+ Trigger,
21
+ Field,
22
+ Choice,
23
+ ActionExecutionResult,
24
+ ActionField,
25
+ ActionFieldChoice,
26
+ NeedsRequest,
27
+ NeedsResponse,
28
+ Authentication,
29
+ AuthenticationsResponse,
30
+ } from "./types";
31
+
32
+ // Re-export authentication utilities
33
+ export { isJwt, getAuthorizationHeader } from "./auth";
34
+
35
+ // Re-export debug utilities
36
+ export { createDebugLogger, createDebugFetch } from "./debug";
37
+
38
+ // Re-export polling utilities
39
+ export { pollUntilComplete } from "./polling";
40
+
41
+ // Re-export the main client factory
42
+ export { createZapierApi } from "./client";
43
+
44
+ // Utility Functions
45
+ export function generateRequestId(): string {
46
+ return Math.random().toString(36).substring(2) + Date.now().toString(36);
47
+ }
48
+
49
+ /**
50
+ * Utility function to get or create an API client for standalone functions
51
+ *
52
+ * @param config - Configuration that may include an existing API client
53
+ * @returns ApiClient instance
54
+ */
55
+ export function getOrCreateApiClient(config: {
56
+ baseUrl?: string;
57
+ token?: string;
58
+ api?: import("./types").ApiClient;
59
+ debug?: boolean;
60
+ fetch?: typeof globalThis.fetch;
61
+ }): import("./types").ApiClient {
62
+ const {
63
+ baseUrl = "https://zapier.com",
64
+ token = process.env.ZAPIER_TOKEN,
65
+ api: providedApi,
66
+ debug = false,
67
+ fetch: customFetch,
68
+ } = config;
69
+
70
+ // Use provided API client or create a new one
71
+ if (providedApi) {
72
+ return providedApi;
73
+ }
74
+
75
+ // Import createZapierApi locally to avoid circular imports
76
+ const { createZapierApi } = require("./client");
77
+ return createZapierApi({
78
+ baseUrl,
79
+ token,
80
+ debug,
81
+ fetch: customFetch,
82
+ });
83
+ }
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Polling Utilities
3
+ *
4
+ * This module provides utilities for polling HTTP endpoints until completion,
5
+ * with configurable retry logic and exponential backoff.
6
+ */
7
+
8
+ export async function pollUntilComplete(options: {
9
+ fetch: typeof globalThis.fetch;
10
+ url: string;
11
+ headers?: Record<string, string>;
12
+ maxAttempts?: number;
13
+ initialDelay?: number;
14
+ maxDelay?: number;
15
+ successStatus?: number;
16
+ pendingStatus?: number;
17
+ resultExtractor?: (response: any) => any;
18
+ }): Promise<any> {
19
+ const {
20
+ fetch,
21
+ url,
22
+ headers = {},
23
+ maxAttempts = 30,
24
+ initialDelay = 50,
25
+ maxDelay = 1000,
26
+ successStatus = 200,
27
+ pendingStatus = 202,
28
+ resultExtractor = (response) => response,
29
+ } = options;
30
+
31
+ let delay = initialDelay;
32
+
33
+ for (let attempt = 0; attempt < maxAttempts; attempt++) {
34
+ const response = await fetch(url, { headers });
35
+
36
+ if (response.status === successStatus) {
37
+ // Success - extract and return results
38
+ const result = await response.json();
39
+ return resultExtractor(result);
40
+ } else if (response.status === pendingStatus) {
41
+ // Still processing - wait and retry
42
+ if (attempt < maxAttempts - 1) {
43
+ await new Promise((resolve) => setTimeout(resolve, delay));
44
+ delay = Math.min(delay * 2, maxDelay); // Exponential backoff
45
+ continue;
46
+ }
47
+ } else {
48
+ // Error occurred
49
+ throw new Error(
50
+ `Request failed: GET ${url} - ${response.status} ${response.statusText}`,
51
+ );
52
+ }
53
+ }
54
+
55
+ throw new Error(`Operation timed out after ${maxAttempts} attempts`);
56
+ }
@@ -0,0 +1,177 @@
1
+ /**
2
+ * API Client Type Definitions
3
+ *
4
+ * This module contains all type definitions related to the Zapier API client,
5
+ * including configuration options, client interfaces, request/response types,
6
+ * and API response models.
7
+ */
8
+
9
+ // ============================================================================
10
+ // API Client Infrastructure Types
11
+ // ============================================================================
12
+
13
+ export interface ApiClientOptions {
14
+ baseUrl: string;
15
+ token?: string;
16
+ debug?: boolean;
17
+ fetch?: typeof globalThis.fetch;
18
+ }
19
+
20
+ export interface ApiClient {
21
+ get: (path: string, options?: RequestOptions) => Promise<any>;
22
+ post: (path: string, data?: any, options?: RequestOptions) => Promise<any>;
23
+ put: (path: string, data?: any, options?: RequestOptions) => Promise<any>;
24
+ delete: (path: string, options?: RequestOptions) => Promise<any>;
25
+ poll: (path: string, options?: PollOptions) => Promise<any>;
26
+ }
27
+
28
+ export interface RequestOptions {
29
+ headers?: Record<string, string>;
30
+ searchParams?: Record<string, string>;
31
+ authRequired?: boolean;
32
+ customErrorHandler?: (response: Response) => Error | undefined;
33
+ }
34
+
35
+ export interface PollOptions extends RequestOptions {
36
+ maxAttempts?: number;
37
+ initialDelay?: number;
38
+ maxDelay?: number;
39
+ successStatus?: number;
40
+ pendingStatus?: number;
41
+ resultExtractor?: (response: any) => any;
42
+ }
43
+
44
+ export interface DebugLogger {
45
+ (message: string, data?: any): void;
46
+ }
47
+
48
+ // ============================================================================
49
+ // API Response Models
50
+ // ============================================================================
51
+
52
+ export interface Integration {
53
+ key: string;
54
+ name: string;
55
+ description: string;
56
+ version: string;
57
+ category?: string;
58
+ actions: Action[];
59
+ triggers: Trigger[];
60
+ current_implementation_id?: string;
61
+ }
62
+
63
+ export interface Action {
64
+ key: string;
65
+ name: string;
66
+ description: string;
67
+ appKey: string;
68
+ type: "create" | "update" | "search" | "delete" | "read";
69
+ inputFields: Field[];
70
+ outputFields: Field[];
71
+ }
72
+
73
+ export interface Trigger {
74
+ key: string;
75
+ name: string;
76
+ description: string;
77
+ appKey: string;
78
+ type: "instant" | "polling" | "webhook";
79
+ outputFields: Field[];
80
+ }
81
+
82
+ export interface Field {
83
+ key: string;
84
+ label: string;
85
+ type:
86
+ | "string"
87
+ | "number"
88
+ | "boolean"
89
+ | "datetime"
90
+ | "file"
91
+ | "object"
92
+ | "array";
93
+ required: boolean;
94
+ description?: string;
95
+ choices?: Choice[];
96
+ }
97
+
98
+ export interface Choice {
99
+ value: string | number;
100
+ label: string;
101
+ }
102
+
103
+ export interface ActionExecutionResult {
104
+ success: boolean;
105
+ data?: any;
106
+ error?: string;
107
+ metadata?: {
108
+ executionTime?: number;
109
+ requestId?: string;
110
+ };
111
+ }
112
+
113
+ export interface ActionField {
114
+ key: string;
115
+ label?: string;
116
+ required: boolean;
117
+ type?: string;
118
+ helpText?: string;
119
+ helpTextHtml?: string;
120
+ choices?: ActionFieldChoice[];
121
+ default?: string;
122
+ placeholder?: string;
123
+ computed?: boolean;
124
+ customField?: boolean;
125
+ dependsOn?: string[];
126
+ format?: string;
127
+ inputFormat?: string[];
128
+ }
129
+
130
+ export interface ActionFieldChoice {
131
+ value: string | number;
132
+ label: string;
133
+ }
134
+
135
+ export interface NeedsRequest {
136
+ selected_api: string;
137
+ action: string;
138
+ type_of: string;
139
+ authentication_id?: number;
140
+ params?: Record<string, any>;
141
+ }
142
+
143
+ export interface NeedsResponse {
144
+ success: boolean;
145
+ needs?: ActionField[];
146
+ errors?: string[];
147
+ }
148
+
149
+ export interface Authentication {
150
+ id: number;
151
+ date: string;
152
+ lastchanged?: string;
153
+ account_id: number;
154
+ customuser_id?: number;
155
+ selected_api: string;
156
+ destination_selected_api?: string | null;
157
+ is_invite_only: boolean;
158
+ is_private: boolean;
159
+ shared_with_all: boolean;
160
+ is_stale?: string;
161
+ is_shared?: string;
162
+ marked_stale_at?: string | null;
163
+ label?: string | null;
164
+ identifier?: string | null;
165
+ title?: string | null;
166
+ url?: string;
167
+ groups?: string;
168
+ members?: string;
169
+ permissions?: Record<string, boolean>;
170
+ }
171
+
172
+ export interface AuthenticationsResponse {
173
+ count: number;
174
+ next?: string | null;
175
+ previous?: string | null;
176
+ results: Authentication[];
177
+ }
@@ -1,11 +1,4 @@
1
- export interface BundleCodeOptions {
2
- input: string;
3
- output?: string;
4
- target?: string;
5
- cjs?: boolean;
6
- minify?: boolean;
7
- string?: boolean;
8
- }
1
+ import type { BundleCodeOptions } from "./schemas";
9
2
 
10
3
  /**
11
4
  * Bundle TypeScript code into executable JavaScript
@@ -0,0 +1,9 @@
1
+ import { bundleCode } from "./index";
2
+ import { BundleCodeSchema } from "./schemas";
3
+
4
+ // Function registry info - imports both function and schema
5
+ export const bundleCodeInfo = {
6
+ name: bundleCode.name,
7
+ inputSchema: BundleCodeSchema,
8
+ implementation: bundleCode,
9
+ };
@@ -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
+ }
@@ -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
+ }