@zapier/zapier-sdk 0.0.2 → 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 (167) 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 -76
  12. package/dist/api/types.js +9 -0
  13. package/dist/functions/bundleCode/index.d.ts +11 -0
  14. package/dist/functions/bundleCode/index.js +91 -0
  15. package/dist/functions/bundleCode/info.d.ts +27 -0
  16. package/dist/functions/bundleCode/info.js +11 -0
  17. package/dist/functions/bundleCode/schemas.d.ts +27 -0
  18. package/dist/functions/bundleCode/schemas.js +22 -0
  19. package/dist/functions/generateTypes/index.d.ts +11 -0
  20. package/dist/functions/generateTypes/index.js +305 -0
  21. package/dist/functions/generateTypes/info.d.ts +21 -0
  22. package/dist/functions/generateTypes/info.js +11 -0
  23. package/dist/functions/generateTypes/schemas.d.ts +30 -0
  24. package/dist/functions/generateTypes/schemas.js +14 -0
  25. package/dist/functions/getAction/index.d.ts +12 -0
  26. package/dist/functions/getAction/index.js +26 -0
  27. package/dist/functions/getAction/info.d.ts +18 -0
  28. package/dist/functions/getAction/info.js +11 -0
  29. package/dist/functions/getAction/schemas.d.ts +30 -0
  30. package/dist/functions/getAction/schemas.js +13 -0
  31. package/dist/functions/getApp/index.d.ts +12 -0
  32. package/dist/functions/getApp/index.js +37 -0
  33. package/dist/functions/getApp/info.d.ts +12 -0
  34. package/dist/functions/getApp/info.js +11 -0
  35. package/dist/functions/getApp/schemas.d.ts +24 -0
  36. package/dist/functions/getApp/schemas.js +11 -0
  37. package/dist/functions/listActions/index.d.ts +12 -0
  38. package/dist/functions/listActions/index.js +128 -0
  39. package/dist/functions/listActions/info.d.ts +15 -0
  40. package/dist/functions/listActions/info.js +11 -0
  41. package/dist/functions/listActions/schemas.d.ts +27 -0
  42. package/dist/functions/listActions/schemas.js +14 -0
  43. package/dist/functions/listApps/index.d.ts +12 -0
  44. package/dist/functions/listApps/index.js +50 -0
  45. package/dist/functions/listApps/info.d.ts +18 -0
  46. package/dist/functions/listApps/info.js +11 -0
  47. package/dist/functions/listApps/schemas.d.ts +30 -0
  48. package/dist/functions/listApps/schemas.js +15 -0
  49. package/dist/functions/listAuths/index.d.ts +12 -0
  50. package/dist/functions/listAuths/index.js +118 -0
  51. package/dist/functions/listAuths/info.d.ts +24 -0
  52. package/dist/functions/listAuths/info.js +11 -0
  53. package/dist/functions/listAuths/schemas.d.ts +36 -0
  54. package/dist/functions/listAuths/schemas.js +17 -0
  55. package/dist/functions/listFields/index.d.ts +12 -0
  56. package/dist/functions/listFields/index.js +65 -0
  57. package/dist/functions/listFields/info.d.ts +24 -0
  58. package/dist/functions/listFields/info.js +11 -0
  59. package/dist/functions/listFields/schemas.d.ts +36 -0
  60. package/dist/functions/listFields/schemas.js +17 -0
  61. package/dist/functions/runAction/index.d.ts +12 -0
  62. package/dist/functions/runAction/index.js +157 -0
  63. package/dist/functions/runAction/info.d.ts +24 -0
  64. package/dist/functions/runAction/info.js +11 -0
  65. package/dist/functions/runAction/schemas.d.ts +36 -0
  66. package/dist/functions/runAction/schemas.js +15 -0
  67. package/dist/index.d.ts +15 -3
  68. package/dist/index.js +27 -4
  69. package/dist/plugins/apps/index.d.ts +8 -0
  70. package/dist/plugins/apps/index.js +77 -0
  71. package/dist/plugins/apps/info.d.ts +6 -0
  72. package/dist/plugins/apps/info.js +13 -0
  73. package/dist/plugins/apps/types.d.ts +21 -0
  74. package/dist/plugins/apps/types.js +2 -0
  75. package/dist/resolvers/actionKey.d.ts +8 -0
  76. package/dist/resolvers/actionKey.js +20 -0
  77. package/dist/resolvers/actionType.d.ts +8 -0
  78. package/dist/resolvers/actionType.js +21 -0
  79. package/dist/resolvers/appKey.d.ts +6 -0
  80. package/dist/resolvers/appKey.js +8 -0
  81. package/dist/resolvers/authenticationId.d.ts +8 -0
  82. package/dist/resolvers/authenticationId.js +29 -0
  83. package/dist/resolvers/index.d.ts +39 -0
  84. package/dist/resolvers/index.js +105 -0
  85. package/dist/resolvers/inputs.d.ts +7 -0
  86. package/dist/resolvers/inputs.js +15 -0
  87. package/dist/schema-utils.d.ts +39 -0
  88. package/dist/schema-utils.js +52 -0
  89. package/dist/schemas/Action.d.ts +21 -0
  90. package/dist/schemas/Action.js +31 -0
  91. package/dist/schemas/App.d.ts +19 -0
  92. package/dist/schemas/App.js +32 -0
  93. package/dist/schemas/Auth.d.ts +30 -0
  94. package/dist/schemas/Auth.js +49 -0
  95. package/dist/schemas/Field.d.ts +15 -0
  96. package/dist/schemas/Field.js +25 -0
  97. package/dist/sdk.d.ts +3 -4
  98. package/dist/sdk.js +96 -11
  99. package/dist/types/domain.d.ts +22 -0
  100. package/dist/types/domain.js +21 -0
  101. package/dist/types/properties.d.ts +21 -0
  102. package/dist/types/properties.js +45 -0
  103. package/dist/types/sdk.d.ts +21 -0
  104. package/dist/types/sdk.js +2 -0
  105. package/package.json +4 -2
  106. package/src/api/auth.ts +28 -0
  107. package/src/api/client.ts +148 -0
  108. package/src/api/debug.ts +58 -0
  109. package/src/api/index.ts +83 -0
  110. package/src/api/polling.ts +56 -0
  111. package/src/{types.ts → api/types.ts} +51 -118
  112. package/src/functions/bundleCode/index.ts +78 -0
  113. package/src/functions/bundleCode/info.ts +9 -0
  114. package/src/functions/bundleCode/schemas.ts +30 -0
  115. package/src/functions/generateTypes/index.ts +348 -0
  116. package/src/functions/generateTypes/info.ts +9 -0
  117. package/src/functions/generateTypes/schemas.ts +38 -0
  118. package/src/functions/getAction/index.ts +33 -0
  119. package/src/functions/getAction/info.ts +9 -0
  120. package/src/functions/getAction/schemas.ts +35 -0
  121. package/src/functions/getApp/index.ts +41 -0
  122. package/src/functions/getApp/info.ts +9 -0
  123. package/src/functions/getApp/schemas.ts +31 -0
  124. package/src/functions/listActions/index.ts +149 -0
  125. package/src/functions/listActions/info.ts +9 -0
  126. package/src/functions/listActions/schemas.ts +40 -0
  127. package/src/functions/listApps/index.ts +60 -0
  128. package/src/functions/listApps/info.ts +9 -0
  129. package/src/functions/listApps/schemas.ts +43 -0
  130. package/src/functions/listAuths/index.ts +153 -0
  131. package/src/functions/listAuths/info.ts +9 -0
  132. package/src/functions/listAuths/schemas.ts +48 -0
  133. package/src/functions/listFields/index.ts +86 -0
  134. package/src/functions/listFields/info.ts +9 -0
  135. package/src/functions/listFields/schemas.ts +46 -0
  136. package/src/functions/runAction/index.ts +258 -0
  137. package/src/functions/runAction/info.ts +9 -0
  138. package/src/functions/runAction/schemas.ts +41 -0
  139. package/src/index.ts +24 -4
  140. package/src/plugins/apps/index.ts +144 -0
  141. package/src/plugins/apps/info.ts +12 -0
  142. package/src/plugins/apps/types.ts +34 -0
  143. package/src/resolvers/actionKey.ts +33 -0
  144. package/src/resolvers/actionType.ts +30 -0
  145. package/src/resolvers/appKey.ts +11 -0
  146. package/src/resolvers/authenticationId.ts +38 -0
  147. package/src/resolvers/index.ts +117 -0
  148. package/src/resolvers/inputs.ts +23 -0
  149. package/src/schema-utils.ts +119 -0
  150. package/src/schemas/Action.ts +40 -0
  151. package/src/schemas/App.ts +43 -0
  152. package/src/schemas/Auth.ts +62 -0
  153. package/src/schemas/Field.ts +34 -0
  154. package/src/sdk.ts +153 -19
  155. package/src/types/domain.ts +54 -0
  156. package/src/types/properties.ts +67 -0
  157. package/src/types/sdk.ts +42 -0
  158. package/dist/actions-sdk.d.ts +0 -51
  159. package/dist/actions-sdk.js +0 -1194
  160. package/dist/output-schemas.d.ts +0 -95
  161. package/dist/output-schemas.js +0 -138
  162. package/dist/schemas.d.ts +0 -338
  163. package/dist/schemas.js +0 -336
  164. package/dist/types.js +0 -41
  165. package/src/actions-sdk.ts +0 -1685
  166. package/src/output-schemas.ts +0 -196
  167. package/src/schemas.ts +0 -467
@@ -0,0 +1,48 @@
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 ListAuthsSchema = withOutputSchema(
13
+ z
14
+ .object({
15
+ appKey: AppKeyPropertySchema.optional().describe(
16
+ "App slug to get authentications for (e.g., 'slack', 'github')",
17
+ ),
18
+ account_id: z.string().optional().describe("Filter by account ID"),
19
+ owner: z.string().optional().describe("Filter by owner"),
20
+ limit: LimitPropertySchema.optional().describe(
21
+ "Maximum number of items to return (1-200)",
22
+ ),
23
+ offset: OffsetPropertySchema.optional().describe(
24
+ "Number of items to skip for pagination",
25
+ ),
26
+ })
27
+ .describe("List available authentications with optional filtering"),
28
+ AuthItemSchema,
29
+ );
30
+
31
+ // Type inferred from schema + function config
32
+ export type ListAuthsOptions = z.infer<typeof ListAuthsSchema> & {
33
+ /** Base URL for Zapier API */
34
+ baseUrl?: string;
35
+ /** Authentication token */
36
+ token?: string;
37
+ /** Optional pre-instantiated API client */
38
+ api?: any;
39
+ /** Enable debug logging */
40
+ debug?: boolean;
41
+ /** Custom fetch implementation */
42
+ fetch?: typeof globalThis.fetch;
43
+ };
44
+
45
+ // SDK function interface - ready to be mixed into main SDK interface
46
+ export interface ListAuthsSdkFunction {
47
+ listAuths: (options?: Partial<ListAuthsOptions>) => Promise<Authentication[]>;
48
+ }
@@ -0,0 +1,86 @@
1
+ import { getOrCreateApiClient } from "../../api";
2
+ import type {
3
+ ActionField,
4
+ NeedsRequest,
5
+ NeedsResponse,
6
+ } from "../../types/domain";
7
+ import { getApp } from "../getApp";
8
+ import type { ListFieldsOptions } from "./schemas";
9
+
10
+ /**
11
+ * List available fields for an action
12
+ *
13
+ * This function can be used standalone without instantiating a full SDK,
14
+ * which enables better tree-shaking in applications that only need this functionality.
15
+ *
16
+ * @param options - Action details, authentication ID, params, and API configuration options
17
+ * @returns Promise<ActionField[]>
18
+ */
19
+ export async function listFields(
20
+ options: ListFieldsOptions,
21
+ ): Promise<ActionField[]> {
22
+ const api = getOrCreateApiClient(options);
23
+
24
+ // Extract parameters
25
+ const { appKey, actionKey, actionType, authenticationId, params } = options;
26
+
27
+ // Use the standalone getApp function
28
+ const appData = await getApp({
29
+ appKey,
30
+ api,
31
+ token: options.token,
32
+ baseUrl: options.baseUrl,
33
+ debug: options.debug,
34
+ fetch: options.fetch,
35
+ });
36
+ const selectedApi = appData.current_implementation_id;
37
+
38
+ if (!selectedApi) {
39
+ throw new Error("No current_implementation_id found for app");
40
+ }
41
+
42
+ // Build needs request
43
+ const needsRequest: NeedsRequest = {
44
+ selected_api: selectedApi,
45
+ action: actionKey,
46
+ type_of: actionType,
47
+ authentication_id: authenticationId,
48
+ params: params || {},
49
+ };
50
+
51
+ const needsData: NeedsResponse = await api.post(
52
+ "/api/v4/implementations/needs/",
53
+ needsRequest,
54
+ );
55
+
56
+ if (!needsData.success) {
57
+ throw new Error(
58
+ `Failed to get action fields: ${
59
+ needsData.errors?.join(", ") || "Unknown error"
60
+ }`,
61
+ );
62
+ }
63
+
64
+ // Transform API response to our ActionField interface
65
+ return (needsData.needs || []).map((need: any) => ({
66
+ key: need.key,
67
+ label: need.label,
68
+ required: need.required || false,
69
+ type: need.type,
70
+ helpText: need.help_text,
71
+ helpTextHtml: need.help_text_html,
72
+ choices: need.choices?.map((choice: any) => ({
73
+ value: choice.value,
74
+ label: choice.label,
75
+ })),
76
+ default: need.default,
77
+ placeholder: need.placeholder,
78
+ computed: need.computed,
79
+ customField: need.custom_field,
80
+ dependsOn: need.depends_on,
81
+ format: need.format,
82
+ inputFormat: need.input_format,
83
+ }));
84
+ }
85
+
86
+ // No registry info here - moved to info.ts for proper tree-shaking
@@ -0,0 +1,9 @@
1
+ import { listFields } from "./index";
2
+ import { ListFieldsSchema } from "./schemas";
3
+
4
+ // Function registry info - imports both function and schema
5
+ export const listFieldsInfo = {
6
+ name: listFields.name,
7
+ inputSchema: ListFieldsSchema,
8
+ implementation: listFields,
9
+ };
@@ -0,0 +1,46 @@
1
+ import { z } from "zod";
2
+ import {
3
+ AppKeyPropertySchema,
4
+ ActionTypePropertySchema,
5
+ ActionKeyPropertySchema,
6
+ AuthenticationIdPropertySchema,
7
+ ParamsPropertySchema,
8
+ } from "../../types/properties";
9
+ import { withOutputSchema } from "../../schema-utils";
10
+ import { FieldItemSchema } from "../../schemas/Field";
11
+ import type { ActionField } from "../../types/domain";
12
+
13
+ // Pure Zod schema - no resolver metadata!
14
+ export const ListFieldsSchema = withOutputSchema(
15
+ z
16
+ .object({
17
+ appKey: AppKeyPropertySchema,
18
+ actionType: ActionTypePropertySchema,
19
+ actionKey: ActionKeyPropertySchema,
20
+ authenticationId: AuthenticationIdPropertySchema.optional(),
21
+ params: ParamsPropertySchema.optional().describe(
22
+ "Additional parameters that may affect available fields",
23
+ ),
24
+ })
25
+ .describe("Get the input fields required for a specific action"),
26
+ FieldItemSchema,
27
+ );
28
+
29
+ // Type inferred from schema + function config
30
+ export type ListFieldsOptions = z.infer<typeof ListFieldsSchema> & {
31
+ /** Base URL for Zapier API */
32
+ baseUrl?: string;
33
+ /** Authentication token */
34
+ token?: string;
35
+ /** Optional pre-instantiated API client */
36
+ api?: any;
37
+ /** Enable debug logging */
38
+ debug?: boolean;
39
+ /** Custom fetch implementation */
40
+ fetch?: typeof globalThis.fetch;
41
+ };
42
+
43
+ // SDK function interface - ready to be mixed into main SDK interface
44
+ export interface ListFieldsSdkFunction {
45
+ listFields: (options: ListFieldsOptions) => Promise<ActionField[]>;
46
+ }
@@ -0,0 +1,258 @@
1
+ import { getOrCreateApiClient, generateRequestId } from "../../api";
2
+ import type { ActionExecutionResult } from "../../types/domain";
3
+ import { getAction } from "../getAction";
4
+ import { getApp } from "../getApp";
5
+ import type { RunActionOptions } from "./schemas";
6
+
7
+ /**
8
+ * Execute an action
9
+ *
10
+ * This function can be used standalone without instantiating a full SDK,
11
+ * which enables better tree-shaking in applications that only need this functionality.
12
+ *
13
+ * @param options - Action execution parameters and API configuration options
14
+ * @returns Promise<ActionExecutionResult>
15
+ */
16
+ export async function runAction(
17
+ options: RunActionOptions,
18
+ ): Promise<ActionExecutionResult> {
19
+ const {
20
+ appKey,
21
+ actionType,
22
+ actionKey,
23
+ inputs,
24
+ authenticationId: providedAuthenticationId,
25
+ token,
26
+ } = options;
27
+
28
+ if (!token && !process.env.ZAPIER_TOKEN) {
29
+ throw new Error(
30
+ "Authentication token is required to run actions. Please provide token in options or set ZAPIER_TOKEN environment variable.",
31
+ );
32
+ }
33
+
34
+ const api = getOrCreateApiClient(options);
35
+
36
+ // Validate that the action exists
37
+ const actionData = await getAction({
38
+ ...options,
39
+ appKey: appKey,
40
+ actionKey: actionKey,
41
+ actionType: actionType,
42
+ });
43
+
44
+ // Validate action type matches
45
+ if (actionData.type !== actionType) {
46
+ throw new Error(
47
+ `Action type mismatch: expected ${actionType}, got ${actionData.type}`,
48
+ );
49
+ }
50
+
51
+ // Execute the action using the appropriate API based on action type
52
+ const startTime = Date.now();
53
+ const result = await executeActionWithStrategy({
54
+ api,
55
+ appSlug: appKey,
56
+ actionKey: actionKey,
57
+ actionType: actionData.type,
58
+ executionOptions: { inputs: inputs || {} },
59
+ auth: token
60
+ ? { token: token, authentication_id: providedAuthenticationId }
61
+ : undefined,
62
+ options,
63
+ });
64
+ const executionTime = Date.now() - startTime;
65
+
66
+ return {
67
+ success: true,
68
+ data: result,
69
+ metadata: {
70
+ executionTime,
71
+ requestId: generateRequestId(),
72
+ },
73
+ };
74
+ }
75
+
76
+ interface ExecuteActionStrategyOptions {
77
+ api: any;
78
+ appSlug: string;
79
+ actionKey: string;
80
+ actionType: string;
81
+ executionOptions: { inputs: Record<string, any> };
82
+ auth?: { token: string; authentication_id?: number };
83
+ options: RunActionOptions;
84
+ }
85
+
86
+ async function executeActionWithStrategy(
87
+ strategyOptions: ExecuteActionStrategyOptions,
88
+ ): Promise<any> {
89
+ const {
90
+ api,
91
+ appSlug,
92
+ actionKey,
93
+ actionType,
94
+ executionOptions,
95
+ auth,
96
+ options,
97
+ } = strategyOptions;
98
+
99
+ // Actions API supports: read, read_bulk, write
100
+ // Invoke API supports: search, read, write, read_bulk, and more
101
+
102
+ const actionsApiTypes = ["read", "read_bulk", "write"];
103
+ const useActionsApi = actionsApiTypes.includes(actionType);
104
+
105
+ if (useActionsApi) {
106
+ return executeActionViaActionsApi({
107
+ api,
108
+ appSlug,
109
+ actionKey,
110
+ actionType,
111
+ executionOptions,
112
+ auth,
113
+ options,
114
+ });
115
+ } else {
116
+ return executeActionViaInvokeApi({
117
+ api,
118
+ appSlug,
119
+ actionKey,
120
+ actionType,
121
+ executionOptions,
122
+ auth,
123
+ options,
124
+ });
125
+ }
126
+ }
127
+
128
+ interface ExecuteActionViaActionsApiOptions {
129
+ api: any;
130
+ appSlug: string;
131
+ actionKey: string;
132
+ actionType: string;
133
+ executionOptions: { inputs: Record<string, any> };
134
+ auth?: { token: string; authentication_id?: number };
135
+ options: RunActionOptions;
136
+ }
137
+
138
+ async function executeActionViaActionsApi(
139
+ apiOptions: ExecuteActionViaActionsApiOptions,
140
+ ): Promise<any> {
141
+ const {
142
+ api,
143
+ appSlug,
144
+ actionKey,
145
+ actionType,
146
+ executionOptions,
147
+ auth,
148
+ options,
149
+ } = apiOptions;
150
+
151
+ // Use the standalone getApp function
152
+ const appData = await getApp({
153
+ appKey: appSlug,
154
+ api,
155
+ token: options.token,
156
+ baseUrl: options.baseUrl,
157
+ debug: options.debug,
158
+ fetch: options.fetch,
159
+ });
160
+ const selectedApi = appData.current_implementation_id;
161
+
162
+ if (!selectedApi) {
163
+ throw new Error("No current_implementation_id found for app");
164
+ }
165
+
166
+ if (!auth?.token) {
167
+ throw new Error(
168
+ "Authentication token is required. Please provide token when creating the SDK.",
169
+ );
170
+ }
171
+
172
+ // Step 1: POST to /actions/v1/runs to start execution
173
+ const runRequest = {
174
+ data: {
175
+ authentication_id: auth.authentication_id || 1,
176
+ selected_api: selectedApi,
177
+ action_key: actionKey,
178
+ action_type: actionType,
179
+ inputs: executionOptions.inputs || {},
180
+ },
181
+ };
182
+
183
+ const runData = await api.post("/api/actions/v1/runs", runRequest);
184
+ const runId = runData.data.id;
185
+
186
+ // Step 2: Poll GET /actions/v1/runs/{run_id} for results
187
+ return await api.poll(`/api/actions/v1/runs/${runId}`, {
188
+ successStatus: 200,
189
+ pendingStatus: 202,
190
+ resultExtractor: (result: any) => result.data,
191
+ });
192
+ }
193
+
194
+ interface ExecuteActionViaInvokeApiOptions {
195
+ api: any;
196
+ appSlug: string;
197
+ actionKey: string;
198
+ actionType: string;
199
+ executionOptions: { inputs: Record<string, any> };
200
+ auth?: { token: string; authentication_id?: number };
201
+ options: RunActionOptions;
202
+ }
203
+
204
+ async function executeActionViaInvokeApi(
205
+ apiOptions: ExecuteActionViaInvokeApiOptions,
206
+ ): Promise<any> {
207
+ const {
208
+ api,
209
+ appSlug,
210
+ actionKey,
211
+ actionType,
212
+ executionOptions,
213
+ auth,
214
+ options,
215
+ } = apiOptions;
216
+
217
+ // Use the standalone getApp function
218
+ const appData = await getApp({
219
+ appKey: appSlug,
220
+ api,
221
+ token: options.token,
222
+ baseUrl: options.baseUrl,
223
+ debug: options.debug,
224
+ fetch: options.fetch,
225
+ });
226
+ const selectedApi = appData.current_implementation_id;
227
+
228
+ if (!selectedApi) {
229
+ throw new Error("No current_implementation_id found for app");
230
+ }
231
+
232
+ if (!auth?.token) {
233
+ throw new Error(
234
+ "Authentication token is required. Please provide token when creating the SDK.",
235
+ );
236
+ }
237
+
238
+ // Step 1: POST to /invoke/v1/invoke to start execution
239
+ const invokeRequest = {
240
+ selected_api: selectedApi,
241
+ action: actionKey,
242
+ type_of: actionType,
243
+ authentication_id: auth.authentication_id || 1,
244
+ params: executionOptions.inputs || {},
245
+ };
246
+
247
+ const invokeData = await api.post("/api/invoke/v1/invoke", invokeRequest);
248
+ const invocationId = invokeData.invocation_id;
249
+
250
+ // Step 2: Poll GET /invoke/v1/invoke/{invocation_id} for results
251
+ return await api.poll(`/api/invoke/v1/invoke/${invocationId}`, {
252
+ successStatus: 200,
253
+ pendingStatus: 202,
254
+ resultExtractor: (result: any) => result.results || result,
255
+ });
256
+ }
257
+
258
+ // No registry info here - moved to info.ts for proper tree-shaking
@@ -0,0 +1,9 @@
1
+ import { runAction } from "./index";
2
+ import { RunActionSchema } from "./schemas";
3
+
4
+ // Function registry info - imports both function and schema
5
+ export const runActionInfo = {
6
+ name: runAction.name,
7
+ inputSchema: RunActionSchema,
8
+ implementation: runAction,
9
+ };
@@ -0,0 +1,41 @@
1
+ import { z } from "zod";
2
+ import {
3
+ AppKeyPropertySchema,
4
+ ActionTypePropertySchema,
5
+ ActionKeyPropertySchema,
6
+ AuthenticationIdPropertySchema,
7
+ InputsPropertySchema,
8
+ } from "../../types/properties";
9
+ import type { ActionExecutionResult } from "../../types/domain";
10
+
11
+ // Pure Zod schema - no resolver metadata!
12
+ export const RunActionSchema = z
13
+ .object({
14
+ appKey: AppKeyPropertySchema,
15
+ actionType: ActionTypePropertySchema,
16
+ actionKey: ActionKeyPropertySchema,
17
+ inputs: InputsPropertySchema.optional().describe(
18
+ "Input parameters for the action",
19
+ ),
20
+ authenticationId: AuthenticationIdPropertySchema.optional(),
21
+ })
22
+ .describe("Execute an action with the given inputs");
23
+
24
+ // Type inferred from schema + function config
25
+ export type RunActionOptions = z.infer<typeof RunActionSchema> & {
26
+ /** Base URL for Zapier API */
27
+ baseUrl?: string;
28
+ /** Authentication token */
29
+ token?: string;
30
+ /** Optional pre-instantiated API client */
31
+ api?: any;
32
+ /** Enable debug logging */
33
+ debug?: boolean;
34
+ /** Custom fetch implementation */
35
+ fetch?: typeof globalThis.fetch;
36
+ };
37
+
38
+ // SDK function interface - ready to be mixed into main SDK interface
39
+ export interface RunActionSdkFunction {
40
+ runAction: (options: RunActionOptions) => Promise<ActionExecutionResult>;
41
+ }
package/src/index.ts CHANGED
@@ -1,6 +1,26 @@
1
- // Export everything from types and actions-sdk
2
- export * from "./types";
3
- export * from "./actions-sdk";
1
+ // Export everything from types and plugins
2
+ export * from "./types/domain";
3
+ export * from "./types/properties";
4
+ export * from "./plugins/apps";
5
+
6
+ // Export resolvers for CLI use
7
+ export * from "./resolvers";
8
+
9
+ // Note: SdkSchemas is now available via SDK.__registry
10
+
11
+ // Export individual functions for tree-shaking
12
+ export { listAuths } from "./functions/listAuths";
13
+ export { listApps } from "./functions/listApps";
14
+ export { getApp } from "./functions/getApp";
15
+ export { listActions } from "./functions/listActions";
16
+ export { getAction } from "./functions/getAction";
17
+ export { runAction } from "./functions/runAction";
18
+ export { listFields } from "./functions/listFields";
19
+ export { generateTypes } from "./functions/generateTypes";
20
+ export { bundleCode } from "./functions/bundleCode";
4
21
 
5
22
  // Export the main combined SDK
6
- export { createZapierSdk, ZapierSdk, ZapierSdkOptions } from "./sdk";
23
+ export { createZapierSdk, ZapierSdkOptions } from "./sdk";
24
+
25
+ // Export SDK type from types (not sdk.ts to avoid circular imports)
26
+ export type { ZapierSdk } from "./types/sdk";
@@ -0,0 +1,144 @@
1
+ import {
2
+ ActionExecutionOptions,
3
+ ActionExecutionResult,
4
+ } from "../../types/domain";
5
+ import { type ApiClient } from "../../api";
6
+ import { runAction } from "../../functions/runAction";
7
+ import type { ActionProxy } from "./types";
8
+
9
+ export interface AppsPluginOptions {
10
+ api: ApiClient;
11
+ token?: string;
12
+ }
13
+
14
+ interface AppFactoryOptions {
15
+ authenticationId: number;
16
+ }
17
+
18
+ function createActionFunction(
19
+ appKey: string,
20
+ actionType: string,
21
+ actionKey: string,
22
+ options: AppsPluginOptions,
23
+ pinnedAuthId?: number,
24
+ ) {
25
+ return async (
26
+ actionOptions: ActionExecutionOptions = {},
27
+ ): Promise<ActionExecutionResult> => {
28
+ const { api, token } = options;
29
+ const { inputs, authenticationId: providedAuthenticationId } =
30
+ actionOptions;
31
+
32
+ // Use pinned auth ID first, then provided auth ID
33
+ const authenticationId = pinnedAuthId || providedAuthenticationId;
34
+
35
+ if (!authenticationId) {
36
+ throw new Error(
37
+ `Authentication ID is required. Either use the factory pattern: sdk.apps.${appKey}({ authenticationId }) or provide authenticationId in the action call.`,
38
+ );
39
+ }
40
+
41
+ // Call runAction with the resolved parameters
42
+ return runAction({
43
+ appKey,
44
+ actionType: actionType as any,
45
+ actionKey,
46
+ inputs,
47
+ authenticationId,
48
+ api: api,
49
+ token,
50
+ });
51
+ };
52
+ }
53
+
54
+ function createActionTypeProxy(
55
+ appKey: string,
56
+ actionType: string,
57
+ options: AppsPluginOptions,
58
+ pinnedAuthId?: number,
59
+ ) {
60
+ return new Proxy(
61
+ {},
62
+ {
63
+ get(_, actionKey) {
64
+ if (typeof actionKey === "string") {
65
+ return createActionFunction(
66
+ appKey,
67
+ actionType,
68
+ actionKey,
69
+ options,
70
+ pinnedAuthId,
71
+ );
72
+ }
73
+ return undefined;
74
+ },
75
+ },
76
+ );
77
+ }
78
+
79
+ function createPinnedAppProxy(
80
+ appKey: string,
81
+ options: AppsPluginOptions,
82
+ pinnedAuthId: number,
83
+ ) {
84
+ return new Proxy(
85
+ {},
86
+ {
87
+ get(_, actionType) {
88
+ if (typeof actionType === "string") {
89
+ return createActionTypeProxy(
90
+ appKey,
91
+ actionType,
92
+ options,
93
+ pinnedAuthId,
94
+ );
95
+ }
96
+ return undefined;
97
+ },
98
+ },
99
+ );
100
+ }
101
+
102
+ function createAppProxy(appKey: string, options: AppsPluginOptions) {
103
+ // Create the factory function that returns a pinned version
104
+ const appFactory = (factoryOptions: AppFactoryOptions) => {
105
+ return createPinnedAppProxy(
106
+ appKey,
107
+ options,
108
+ factoryOptions.authenticationId,
109
+ );
110
+ };
111
+
112
+ // Add properties for direct usage (backward compatibility)
113
+ return new Proxy(appFactory, {
114
+ get(_, actionType) {
115
+ if (typeof actionType === "string") {
116
+ return createActionTypeProxy(appKey, actionType, options);
117
+ }
118
+ return undefined;
119
+ },
120
+ });
121
+ }
122
+
123
+ function createAppsProxy(options: AppsPluginOptions): ActionProxy {
124
+ // Create a proxy object that intercepts property access
125
+ const appsProxy = new Proxy({} as ActionProxy, {
126
+ get(_, prop) {
127
+ if (typeof prop === "string") {
128
+ // First level: App names (e.g., 'slack')
129
+ return createAppProxy(prop, options);
130
+ }
131
+ return undefined;
132
+ },
133
+ });
134
+
135
+ return appsProxy;
136
+ }
137
+
138
+ // Export the plugin creation function
139
+ export function createAppsPlugin(options: AppsPluginOptions): ActionProxy {
140
+ return createAppsProxy(options);
141
+ }
142
+
143
+ // Re-export types
144
+ export type { ActionProxy, AppsPluginSdkExtension } from "./types";
@@ -0,0 +1,12 @@
1
+ import { createAppsPlugin } from "./index";
2
+ import type { AppsPluginOptions } from "./index";
3
+
4
+ // Plugin info object for registry (keeping for compatibility)
5
+ export const appsPluginInfo = {
6
+ plugin: (_sdk: any, options: AppsPluginOptions) => {
7
+ const appsProxy = createAppsPlugin(options);
8
+ return {
9
+ apps: appsProxy,
10
+ };
11
+ },
12
+ };