@zapier/zapier-sdk 0.0.1 → 0.0.3

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 (49) hide show
  1. package/dist/actions-sdk.d.ts +47 -0
  2. package/dist/actions-sdk.js +208 -0
  3. package/dist/api.d.ts +62 -0
  4. package/dist/api.js +227 -0
  5. package/dist/functions/bundleCode.d.ts +18 -0
  6. package/dist/functions/bundleCode.js +91 -0
  7. package/dist/functions/generateTypes.d.ts +16 -0
  8. package/dist/functions/generateTypes.js +271 -0
  9. package/dist/functions/getAction.d.ts +16 -0
  10. package/dist/functions/getAction.js +25 -0
  11. package/dist/functions/getApp.d.ts +14 -0
  12. package/dist/functions/getApp.js +41 -0
  13. package/dist/functions/listActions.d.ts +15 -0
  14. package/dist/functions/listActions.js +127 -0
  15. package/dist/functions/listApps.d.ts +16 -0
  16. package/dist/functions/listApps.js +50 -0
  17. package/dist/functions/listAuths.d.ts +18 -0
  18. package/dist/functions/listAuths.js +118 -0
  19. package/dist/functions/listFields.d.ts +18 -0
  20. package/dist/functions/listFields.js +67 -0
  21. package/dist/functions/runAction.d.ts +18 -0
  22. package/dist/functions/runAction.js +156 -0
  23. package/dist/index.d.ts +12 -3
  24. package/dist/index.js +24 -5
  25. package/dist/output-schemas.d.ts +95 -0
  26. package/dist/output-schemas.js +138 -0
  27. package/dist/schemas.d.ts +338 -0
  28. package/dist/schemas.js +336 -0
  29. package/dist/sdk.d.ts +5 -5
  30. package/dist/sdk.js +8 -8
  31. package/dist/types.d.ts +196 -0
  32. package/dist/types.js +41 -0
  33. package/package.json +5 -3
  34. package/src/actions-sdk.ts +356 -0
  35. package/src/api.ts +361 -0
  36. package/src/functions/bundleCode.ts +85 -0
  37. package/src/functions/generateTypes.ts +309 -0
  38. package/src/functions/getAction.ts +34 -0
  39. package/src/functions/getApp.ts +47 -0
  40. package/src/functions/listActions.ts +151 -0
  41. package/src/functions/listApps.ts +65 -0
  42. package/src/functions/listAuths.ts +161 -0
  43. package/src/functions/listFields.ts +95 -0
  44. package/src/functions/runAction.ts +256 -0
  45. package/src/index.ts +15 -4
  46. package/src/output-schemas.ts +196 -0
  47. package/src/schemas.ts +467 -0
  48. package/src/sdk.ts +13 -13
  49. package/src/types.ts +257 -0
package/dist/sdk.js CHANGED
@@ -1,17 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createZapierSDK = createZapierSDK;
4
- const dist_1 = require("../../actions-sdk/dist");
5
- function createZapierSDK(options = {}) {
3
+ exports.createZapierSdk = createZapierSdk;
4
+ const actions_sdk_1 = require("./actions-sdk");
5
+ function createZapierSdk(options = {}) {
6
6
  // Create individual SDKs
7
- const actionsSDK = (0, dist_1.createActionsSDK)(options);
7
+ const actionsSdk = (0, actions_sdk_1.createActionsSdk)(options);
8
8
  // For now, we just return the actions SDK
9
9
  // Later we'll combine multiple SDKs here
10
10
  return {
11
- ...actionsSDK,
11
+ ...actionsSdk,
12
12
  // Future SDKs will be spread here:
13
- // ...workflowsSDK,
14
- // ...interfacesSDK,
15
- // ...tablesSDK,
13
+ // ...workflowsSdk,
14
+ // ...interfacesSdk,
15
+ // ...tablesSdk,
16
16
  };
17
17
  }
@@ -0,0 +1,196 @@
1
+ export interface Integration {
2
+ key: string;
3
+ name: string;
4
+ description: string;
5
+ version: string;
6
+ category?: string;
7
+ actions: Action[];
8
+ triggers: Trigger[];
9
+ current_implementation_id?: string;
10
+ }
11
+ export interface Action {
12
+ key: string;
13
+ name: string;
14
+ description: string;
15
+ appKey: string;
16
+ type: "create" | "update" | "search" | "delete" | "read";
17
+ inputFields: Field[];
18
+ outputFields: Field[];
19
+ }
20
+ export interface Trigger {
21
+ key: string;
22
+ name: string;
23
+ description: string;
24
+ appKey: string;
25
+ type: "instant" | "polling" | "webhook";
26
+ outputFields: Field[];
27
+ }
28
+ export interface Field {
29
+ key: string;
30
+ label: string;
31
+ type: "string" | "number" | "boolean" | "datetime" | "file" | "object" | "array";
32
+ required: boolean;
33
+ description?: string;
34
+ choices?: Choice[];
35
+ }
36
+ export interface Choice {
37
+ value: string | number;
38
+ label: string;
39
+ }
40
+ export interface ListOptions {
41
+ category?: string;
42
+ appKey?: string;
43
+ type?: string;
44
+ limit?: number;
45
+ offset?: number;
46
+ }
47
+ export interface ActionExecutionOptions {
48
+ inputs?: Record<string, any>;
49
+ authId?: number;
50
+ }
51
+ export interface ActionExecutionResult {
52
+ success: boolean;
53
+ data?: any;
54
+ error?: string;
55
+ metadata?: {
56
+ executionTime?: number;
57
+ requestId?: string;
58
+ };
59
+ }
60
+ export interface ActionField {
61
+ key: string;
62
+ label?: string;
63
+ required: boolean;
64
+ type?: string;
65
+ helpText?: string;
66
+ helpTextHtml?: string;
67
+ choices?: ActionFieldChoice[];
68
+ default?: string;
69
+ placeholder?: string;
70
+ computed?: boolean;
71
+ customField?: boolean;
72
+ dependsOn?: string[];
73
+ format?: string;
74
+ inputFormat?: string[];
75
+ }
76
+ export interface ActionFieldChoice {
77
+ value: string | number;
78
+ label: string;
79
+ }
80
+ export interface NeedsRequest {
81
+ selected_api: string;
82
+ action: string;
83
+ type_of: string;
84
+ authentication_id?: number;
85
+ params?: Record<string, any>;
86
+ }
87
+ export interface NeedsResponse {
88
+ success: boolean;
89
+ needs?: ActionField[];
90
+ errors?: string[];
91
+ }
92
+ export interface Workflow {
93
+ id: string;
94
+ name: string;
95
+ description: string;
96
+ steps: WorkflowStep[];
97
+ }
98
+ export interface WorkflowStep {
99
+ id: string;
100
+ type: "trigger" | "action";
101
+ appKey: string;
102
+ actionKey?: string;
103
+ triggerKey?: string;
104
+ }
105
+ export interface Interface {
106
+ key: string;
107
+ name: string;
108
+ fields: Field[];
109
+ }
110
+ export interface Table {
111
+ key: string;
112
+ name: string;
113
+ columns: TableColumn[];
114
+ }
115
+ export interface TableColumn {
116
+ key: string;
117
+ name: string;
118
+ type: string;
119
+ }
120
+ export interface Authentication {
121
+ id: number;
122
+ date: string;
123
+ lastchanged?: string;
124
+ account_id: number;
125
+ customuser_id?: number;
126
+ selected_api: string;
127
+ destination_selected_api?: string | null;
128
+ is_invite_only: boolean;
129
+ is_private: boolean;
130
+ shared_with_all: boolean;
131
+ is_stale?: string;
132
+ is_shared?: string;
133
+ marked_stale_at?: string | null;
134
+ label?: string | null;
135
+ identifier?: string | null;
136
+ title?: string | null;
137
+ url?: string;
138
+ groups?: string;
139
+ members?: string;
140
+ permissions?: Record<string, boolean>;
141
+ }
142
+ export interface AuthenticationsResponse {
143
+ count: number;
144
+ next?: string | null;
145
+ previous?: string | null;
146
+ results: Authentication[];
147
+ }
148
+ export interface AuthenticationListOptions {
149
+ account_id?: string;
150
+ owner?: string;
151
+ appKey?: string;
152
+ limit?: number;
153
+ offset?: number;
154
+ }
155
+ export declare class ZapierSdkError extends Error {
156
+ code?: string | undefined;
157
+ constructor(message: string, code?: string | undefined);
158
+ }
159
+ export declare class AppNotFoundError extends ZapierSdkError {
160
+ constructor(appKey: string);
161
+ }
162
+ export declare class ActionNotFoundError extends ZapierSdkError {
163
+ constructor(appKey: string, actionKey: string);
164
+ }
165
+ export declare class AuthenticationError extends ZapierSdkError {
166
+ constructor(message: string);
167
+ }
168
+ export interface AuthObject {
169
+ id: number;
170
+ }
171
+ export interface BaseSdkOptions {
172
+ token?: string;
173
+ authentications?: {
174
+ [appKey: string]: AuthObject[];
175
+ };
176
+ fetch?: typeof fetch;
177
+ baseUrl?: string;
178
+ debug?: boolean;
179
+ }
180
+ export interface FunctionConfig {
181
+ /** Base URL for Zapier API */
182
+ baseUrl?: string;
183
+ /** Authentication token */
184
+ token?: string;
185
+ /** Optional pre-instantiated API client */
186
+ api?: any;
187
+ /** Enable debug logging */
188
+ debug?: boolean;
189
+ /** Custom fetch implementation */
190
+ fetch?: typeof globalThis.fetch;
191
+ }
192
+ export interface CombinedSdk {
193
+ [namespace: string]: any;
194
+ }
195
+ export type SdkFactory<T = any> = (options: BaseSdkOptions) => T;
196
+ export declare function combineSdks(sdks: Record<string, any>): CombinedSdk;
package/dist/types.js ADDED
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AuthenticationError = exports.ActionNotFoundError = exports.AppNotFoundError = exports.ZapierSdkError = void 0;
4
+ exports.combineSdks = combineSdks;
5
+ // Custom error classes for better error handling
6
+ class ZapierSdkError extends Error {
7
+ constructor(message, code) {
8
+ super(message);
9
+ this.code = code;
10
+ this.name = "ZapierSdkError";
11
+ }
12
+ }
13
+ exports.ZapierSdkError = ZapierSdkError;
14
+ class AppNotFoundError extends ZapierSdkError {
15
+ constructor(appKey) {
16
+ super(`App "${appKey}" not found`);
17
+ this.name = "AppNotFoundError";
18
+ this.code = "APP_NOT_FOUND";
19
+ }
20
+ }
21
+ exports.AppNotFoundError = AppNotFoundError;
22
+ class ActionNotFoundError extends ZapierSdkError {
23
+ constructor(appKey, actionKey) {
24
+ super(`Action "${actionKey}" not found in app "${appKey}"`);
25
+ this.name = "ActionNotFoundError";
26
+ this.code = "ACTION_NOT_FOUND";
27
+ }
28
+ }
29
+ exports.ActionNotFoundError = ActionNotFoundError;
30
+ class AuthenticationError extends ZapierSdkError {
31
+ constructor(message) {
32
+ super(message);
33
+ this.name = "AuthenticationError";
34
+ this.code = "AUTHENTICATION_ERROR";
35
+ }
36
+ }
37
+ exports.AuthenticationError = AuthenticationError;
38
+ // Utility function to combine multiple SDKs
39
+ function combineSdks(sdks) {
40
+ return { ...sdks };
41
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zapier/zapier-sdk",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "Complete Zapier SDK - combines all Zapier SDK packages",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -18,8 +18,10 @@
18
18
  "access": "restricted"
19
19
  },
20
20
  "dependencies": {
21
- "@zapier/actions-sdk": "0.0.1",
22
- "@zapier/shared-sdk": "0.0.1"
21
+ "dotenv": "^17.0.0",
22
+ "esbuild": "^0.25.5",
23
+ "find-up": "^7.0.0",
24
+ "zod": "^3.25.67"
23
25
  },
24
26
  "devDependencies": {
25
27
  "@types/node": "^24.0.1",
@@ -0,0 +1,356 @@
1
+ import {
2
+ Integration,
3
+ Action,
4
+ ActionExecutionOptions,
5
+ ActionExecutionResult,
6
+ ActionField,
7
+ Authentication,
8
+ BaseSdkOptions,
9
+ } from "./types";
10
+ import { createZapierApi, type ApiClient } from "./api";
11
+ import { listAuths } from "./functions/listAuths";
12
+ import { listApps } from "./functions/listApps";
13
+ import { getApp } from "./functions/getApp";
14
+ import { listActions } from "./functions/listActions";
15
+ import { getAction } from "./functions/getAction";
16
+ import { runAction } from "./functions/runAction";
17
+ import { listFields } from "./functions/listFields";
18
+ import { generateTypes as generateTypesFunction } from "./functions/generateTypes";
19
+ import { bundleCode as bundleCodeFunction } from "./functions/bundleCode";
20
+ import {
21
+ AppsListOptions,
22
+ AppsGetOptions,
23
+ ActionsListOptions,
24
+ ActionsGetOptions,
25
+ ActionsRunOptions,
26
+ AuthsListOptions,
27
+ AuthsFindOptions,
28
+ FieldsListOptions,
29
+ GenerateOptions,
30
+ BundleOptions,
31
+ } from "./schemas";
32
+ export * from "./schemas";
33
+ export * from "./output-schemas";
34
+
35
+ export interface ActionsSdk {
36
+ // Resource namespaces
37
+ apps: AppsService;
38
+ actions: ActionsService;
39
+ auths: AuthsService;
40
+ fields: FieldsService;
41
+
42
+ // Root namespace tools
43
+ generate: GenerateFunction;
44
+ bundle: BundleFunction;
45
+ }
46
+
47
+ export interface AppsService {
48
+ list(options?: AppsListOptions): Promise<Integration[]>;
49
+ get(options: AppsGetOptions): Promise<Integration>;
50
+ }
51
+
52
+ interface ActionRunner {
53
+ (params: ActionsRunOptions): Promise<ActionExecutionResult>;
54
+ }
55
+
56
+ interface ActionProxy {
57
+ [app: string]: {
58
+ [type: string]: {
59
+ [action: string]: (
60
+ options?: ActionExecutionOptions,
61
+ ) => Promise<ActionExecutionResult>;
62
+ };
63
+ };
64
+ }
65
+
66
+ export interface GenerateFunction {
67
+ (options: GenerateOptions): Promise<string>;
68
+ }
69
+
70
+ export interface BundleFunction {
71
+ (options: BundleOptions): Promise<string>;
72
+ }
73
+
74
+ export interface ActionsService {
75
+ list(options?: ActionsListOptions): Promise<Action[]>;
76
+ get(options: ActionsGetOptions): Promise<Action>;
77
+ run: ActionRunner & ActionProxy;
78
+ }
79
+
80
+ export interface AuthsService {
81
+ list(options?: AuthsListOptions): Promise<Authentication[]>;
82
+ find(options: AuthsFindOptions): number;
83
+ }
84
+
85
+ export interface FieldsService {
86
+ list(options: FieldsListOptions): Promise<ActionField[]>;
87
+ }
88
+
89
+ export interface ActionsSdkOptions extends BaseSdkOptions {}
90
+
91
+ export function createActionsSdk(options: ActionsSdkOptions = {}): ActionsSdk {
92
+ // Auto-load .env files (searches up directory tree)
93
+ try {
94
+ const { findUpSync } = require("find-up");
95
+ const envPath = findUpSync(".env");
96
+ if (envPath) {
97
+ require("dotenv").config({ path: envPath, quiet: true });
98
+ }
99
+ } catch {
100
+ // Silently fail if dotenv/find-up not available or .env not found
101
+ }
102
+
103
+ const {
104
+ fetch: customFetch = globalThis.fetch,
105
+ baseUrl = "https://zapier.com",
106
+ token,
107
+ authentications = {},
108
+ debug = false,
109
+ } = options;
110
+
111
+ // If no token provided, try to get it from environment variable
112
+ const finalToken = token || process.env.ZAPIER_TOKEN;
113
+
114
+ // Create the API client
115
+ const api = createZapierApi({
116
+ baseUrl,
117
+ token: finalToken,
118
+ debug,
119
+ fetch: customFetch,
120
+ });
121
+
122
+ // Create SDK object - we'll populate services after creation to avoid circular dependency
123
+ const sdk: ActionsSdk = {} as ActionsSdk;
124
+
125
+ const appsService = createAppsService({
126
+ api,
127
+ token: finalToken,
128
+ authentications,
129
+ sdk,
130
+ });
131
+
132
+ const actionsService = createActionsService({
133
+ api,
134
+ token: finalToken,
135
+ authentications,
136
+ sdk,
137
+ });
138
+
139
+ const authsService = createAuthsService({
140
+ api,
141
+ token: finalToken,
142
+ authentications,
143
+ sdk,
144
+ });
145
+
146
+ const fieldsService = createFieldsService({
147
+ api,
148
+ token: finalToken,
149
+ authentications,
150
+ sdk,
151
+ });
152
+
153
+ // Create root namespace tools
154
+ const generateFunction: GenerateFunction = async (
155
+ options: GenerateOptions,
156
+ ) => {
157
+ return generateTypesFunction({ ...options, api, token: finalToken });
158
+ };
159
+
160
+ const bundleFunction: BundleFunction = async (options: BundleOptions) => {
161
+ return bundleCodeFunction(options);
162
+ };
163
+
164
+ // Populate the SDK object
165
+ sdk.apps = appsService;
166
+ sdk.actions = actionsService;
167
+ sdk.auths = authsService;
168
+ sdk.fields = fieldsService;
169
+ sdk.generate = generateFunction;
170
+ sdk.bundle = bundleFunction;
171
+
172
+ // Note: Debug logging for SDK initialization is now handled by the API client
173
+
174
+ return sdk;
175
+ }
176
+
177
+ interface AppsServiceOptions {
178
+ api: ApiClient;
179
+ token?: string;
180
+ authentications?: { [appKey: string]: { id: number }[] };
181
+ sdk: ActionsSdk;
182
+ }
183
+
184
+ interface AuthsServiceOptions {
185
+ api: ApiClient;
186
+ token?: string;
187
+ authentications?: { [appKey: string]: { id: number }[] };
188
+ sdk: ActionsSdk;
189
+ }
190
+
191
+ interface ActionsServiceOptions {
192
+ api: ApiClient;
193
+ token?: string;
194
+ authentications?: { [appKey: string]: { id: number }[] };
195
+ sdk: ActionsSdk;
196
+ }
197
+
198
+ interface FieldsServiceOptions {
199
+ api: ApiClient;
200
+ token?: string;
201
+ authentications?: { [appKey: string]: { id: number }[] };
202
+ sdk: ActionsSdk;
203
+ }
204
+
205
+ function createAppsService(options: AppsServiceOptions): AppsService {
206
+ const { api, token } = options;
207
+
208
+ return {
209
+ async list(options?: AppsListOptions): Promise<Integration[]> {
210
+ return listApps({ ...options, api, token });
211
+ },
212
+
213
+ async get(options: AppsGetOptions): Promise<Integration> {
214
+ return getApp({ ...options, api, token });
215
+ },
216
+ };
217
+ }
218
+
219
+ function createAuthsService(options: AuthsServiceOptions): AuthsService {
220
+ const { api, token, authentications } = options;
221
+
222
+ return {
223
+ async list(options?: AuthsListOptions): Promise<Authentication[]> {
224
+ return listAuths({ ...options, api, token });
225
+ },
226
+
227
+ find(options: { appKey: string }): number {
228
+ if (!authentications) {
229
+ throw new Error(`No authentication configured`);
230
+ }
231
+
232
+ const auths = authentications[options.appKey] || [];
233
+
234
+ if (auths.length === 0) {
235
+ throw new Error(
236
+ `No authentication configured for app "${options.appKey}"`,
237
+ );
238
+ }
239
+
240
+ if (auths.length > 1) {
241
+ throw new Error(
242
+ `Multiple authentications found for app "${options.appKey}". Please specify which one to use.`,
243
+ );
244
+ }
245
+
246
+ return auths[0].id;
247
+ },
248
+ };
249
+ }
250
+
251
+ function createFieldsService(options: FieldsServiceOptions): FieldsService {
252
+ const { api, token } = options;
253
+
254
+ return {
255
+ async list(options: FieldsListOptions): Promise<ActionField[]> {
256
+ return listFields({ ...options, api, token });
257
+ },
258
+ };
259
+ }
260
+
261
+ function createActionsService(options: ActionsServiceOptions): ActionsService {
262
+ const { api, token, authentications } = options;
263
+
264
+ // Create the base service with named methods
265
+ const baseService: ActionsService = {
266
+ async list(options?: ActionsListOptions): Promise<Action[]> {
267
+ return listActions({ ...options, api, token });
268
+ },
269
+
270
+ async get(options: ActionsGetOptions): Promise<Action> {
271
+ return getAction({ ...options, api, token });
272
+ },
273
+
274
+ // run will be replaced with function/proxy pattern below
275
+ } as ActionsService;
276
+
277
+ // Create the run function with proxy capabilities
278
+ const runFunction = async (
279
+ params: ActionsRunOptions,
280
+ ): Promise<ActionExecutionResult> => {
281
+ const { app, type, action, inputs, authId: providedAuthId } = params;
282
+
283
+ // Resolve auth ID for this specific app
284
+ let authId: number | undefined = providedAuthId;
285
+
286
+ if (!authId && authentications) {
287
+ const auths = authentications[app] || [];
288
+ if (auths.length === 0) {
289
+ throw new Error(`No authentication configured for app "${app}"`);
290
+ }
291
+ if (auths.length > 1) {
292
+ throw new Error(
293
+ `Multiple authentications found for app "${app}". Please specify which one to use.`,
294
+ );
295
+ }
296
+ authId = auths[0].id;
297
+ }
298
+
299
+ // Delegate to standalone runAction function
300
+ return runAction({
301
+ app,
302
+ type,
303
+ action,
304
+ inputs,
305
+ authId,
306
+ api,
307
+ token,
308
+ });
309
+ };
310
+
311
+ // Create proxy wrapper for the run function
312
+ const runWithProxy = new Proxy(runFunction, {
313
+ get(target, prop: string) {
314
+ if (typeof prop === "string") {
315
+ // Return app-level proxy
316
+ return new Proxy(
317
+ {},
318
+ {
319
+ get(_target, actionType: string) {
320
+ if (typeof actionType !== "string") return undefined;
321
+
322
+ return new Proxy(
323
+ {},
324
+ {
325
+ get(_target, actionKey: string) {
326
+ if (typeof actionKey !== "string") return undefined;
327
+
328
+ // Return function that calls the main run function
329
+ return async (
330
+ options: ActionExecutionOptions = {},
331
+ ): Promise<ActionExecutionResult> => {
332
+ return await runFunction({
333
+ app: prop,
334
+ type: actionType as any, // Cast because proxy string can't be typed as enum
335
+ action: actionKey,
336
+ inputs: options.inputs,
337
+ authId: options.authId,
338
+ });
339
+ };
340
+ },
341
+ },
342
+ );
343
+ },
344
+ },
345
+ );
346
+ }
347
+ return target[prop];
348
+ },
349
+ });
350
+
351
+ // Add the run function/proxy to the base service
352
+ baseService.run = runWithProxy as ActionRunner & ActionProxy;
353
+
354
+ // Return the service with the new run function/proxy
355
+ return baseService;
356
+ }