@zapier/zapier-sdk 0.0.2 → 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 (41) hide show
  1. package/dist/actions-sdk.d.ts +0 -4
  2. package/dist/actions-sdk.js +43 -1029
  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 +9 -0
  24. package/dist/index.js +20 -1
  25. package/dist/output-schemas.d.ts +4 -4
  26. package/dist/schemas.d.ts +24 -24
  27. package/dist/types.d.ts +12 -0
  28. package/package.json +1 -1
  29. package/src/actions-sdk.ts +47 -1376
  30. package/src/api.ts +361 -0
  31. package/src/functions/bundleCode.ts +85 -0
  32. package/src/functions/generateTypes.ts +309 -0
  33. package/src/functions/getAction.ts +34 -0
  34. package/src/functions/getApp.ts +47 -0
  35. package/src/functions/listActions.ts +151 -0
  36. package/src/functions/listApps.ts +65 -0
  37. package/src/functions/listAuths.ts +161 -0
  38. package/src/functions/listFields.ts +95 -0
  39. package/src/functions/runAction.ts +256 -0
  40. package/src/index.ts +11 -0
  41. package/src/types.ts +13 -0
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runAction = runAction;
4
+ const api_1 = require("../api");
5
+ const getAction_1 = require("./getAction");
6
+ const getApp_1 = require("./getApp");
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
+ async function runAction(options) {
17
+ const { app, type, action, inputs, authId: providedAuthId, token } = options;
18
+ if (!token && !process.env.ZAPIER_TOKEN) {
19
+ throw new Error("Authentication token is required to run actions. Please provide token in options or set ZAPIER_TOKEN environment variable.");
20
+ }
21
+ const api = (0, api_1.getOrCreateApiClient)(options);
22
+ // Validate that the action exists
23
+ const actionData = await (0, getAction_1.getAction)({
24
+ ...options,
25
+ app: app,
26
+ action: action,
27
+ type: type,
28
+ });
29
+ // Validate action type matches
30
+ if (actionData.type !== type) {
31
+ throw new Error(`Action type mismatch: expected ${type}, got ${actionData.type}`);
32
+ }
33
+ // Execute the action using the appropriate API based on action type
34
+ const startTime = Date.now();
35
+ const result = await executeActionWithStrategy({
36
+ api,
37
+ appSlug: app,
38
+ actionKey: action,
39
+ actionType: actionData.type,
40
+ executionOptions: { inputs: inputs || {} },
41
+ auth: token
42
+ ? { token: token, authentication_id: providedAuthId }
43
+ : undefined,
44
+ options,
45
+ });
46
+ const executionTime = Date.now() - startTime;
47
+ return {
48
+ success: true,
49
+ data: result,
50
+ metadata: {
51
+ executionTime,
52
+ requestId: (0, api_1.generateRequestId)(),
53
+ },
54
+ };
55
+ }
56
+ async function executeActionWithStrategy(strategyOptions) {
57
+ const { api, appSlug, actionKey, actionType, executionOptions, auth, options, } = strategyOptions;
58
+ // Actions API supports: read, read_bulk, write
59
+ // Invoke API supports: search, read, write, read_bulk, and more
60
+ const actionsApiTypes = ["read", "read_bulk", "write"];
61
+ const useActionsApi = actionsApiTypes.includes(actionType);
62
+ if (useActionsApi) {
63
+ return executeActionViaActionsApi({
64
+ api,
65
+ appSlug,
66
+ actionKey,
67
+ actionType,
68
+ executionOptions,
69
+ auth,
70
+ options,
71
+ });
72
+ }
73
+ else {
74
+ return executeActionViaInvokeApi({
75
+ api,
76
+ appSlug,
77
+ actionKey,
78
+ actionType,
79
+ executionOptions,
80
+ auth,
81
+ options,
82
+ });
83
+ }
84
+ }
85
+ async function executeActionViaActionsApi(apiOptions) {
86
+ const { api, appSlug, actionKey, actionType, executionOptions, auth, options, } = apiOptions;
87
+ // Use the standalone getApp function
88
+ const appData = await (0, getApp_1.getApp)({
89
+ key: appSlug,
90
+ api,
91
+ token: options.token,
92
+ baseUrl: options.baseUrl,
93
+ debug: options.debug,
94
+ fetch: options.fetch,
95
+ });
96
+ const selectedApi = appData.current_implementation_id;
97
+ if (!selectedApi) {
98
+ throw new Error("No current_implementation_id found for app");
99
+ }
100
+ if (!auth?.token) {
101
+ throw new Error("Authentication token is required. Please provide token when creating the SDK.");
102
+ }
103
+ // Step 1: POST to /actions/v1/runs to start execution
104
+ const runRequest = {
105
+ data: {
106
+ authentication_id: auth.authentication_id || 1,
107
+ selected_api: selectedApi,
108
+ action_key: actionKey,
109
+ action_type: actionType,
110
+ inputs: executionOptions.inputs || {},
111
+ },
112
+ };
113
+ const runData = await api.post("/api/actions/v1/runs", runRequest);
114
+ const runId = runData.data.id;
115
+ // Step 2: Poll GET /actions/v1/runs/{run_id} for results
116
+ return await api.poll(`/api/actions/v1/runs/${runId}`, {
117
+ successStatus: 200,
118
+ pendingStatus: 202,
119
+ resultExtractor: (result) => result.data,
120
+ });
121
+ }
122
+ async function executeActionViaInvokeApi(apiOptions) {
123
+ const { api, appSlug, actionKey, actionType, executionOptions, auth, options, } = apiOptions;
124
+ // Use the standalone getApp function
125
+ const appData = await (0, getApp_1.getApp)({
126
+ key: appSlug,
127
+ api,
128
+ token: options.token,
129
+ baseUrl: options.baseUrl,
130
+ debug: options.debug,
131
+ fetch: options.fetch,
132
+ });
133
+ const selectedApi = appData.current_implementation_id;
134
+ if (!selectedApi) {
135
+ throw new Error("No current_implementation_id found for app");
136
+ }
137
+ if (!auth?.token) {
138
+ throw new Error("Authentication token is required. Please provide token when creating the SDK.");
139
+ }
140
+ // Step 1: POST to /invoke/v1/invoke to start execution
141
+ const invokeRequest = {
142
+ selected_api: selectedApi,
143
+ action: actionKey,
144
+ type_of: actionType,
145
+ authentication_id: auth.authentication_id || 1,
146
+ params: executionOptions.inputs || {},
147
+ };
148
+ const invokeData = await api.post("/api/invoke/v1/invoke", invokeRequest);
149
+ const invocationId = invokeData.invocation_id;
150
+ // Step 2: Poll GET /invoke/v1/invoke/{invocation_id} for results
151
+ return await api.poll(`/api/invoke/v1/invoke/${invocationId}`, {
152
+ successStatus: 200,
153
+ pendingStatus: 202,
154
+ resultExtractor: (result) => result.results || result,
155
+ });
156
+ }
package/dist/index.d.ts CHANGED
@@ -1,3 +1,12 @@
1
1
  export * from "./types";
2
2
  export * from "./actions-sdk";
3
+ export { listAuths } from "./functions/listAuths";
4
+ export { listApps } from "./functions/listApps";
5
+ export { getApp } from "./functions/getApp";
6
+ export { listActions } from "./functions/listActions";
7
+ export { getAction } from "./functions/getAction";
8
+ export { runAction } from "./functions/runAction";
9
+ export { listFields } from "./functions/listFields";
10
+ export { generateTypes } from "./functions/generateTypes";
11
+ export { bundleCode } from "./functions/bundleCode";
3
12
  export { createZapierSdk, ZapierSdk, ZapierSdkOptions } from "./sdk";
package/dist/index.js CHANGED
@@ -14,10 +14,29 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.createZapierSdk = void 0;
17
+ exports.createZapierSdk = exports.bundleCode = exports.generateTypes = exports.listFields = exports.runAction = exports.getAction = exports.listActions = exports.getApp = exports.listApps = exports.listAuths = void 0;
18
18
  // Export everything from types and actions-sdk
19
19
  __exportStar(require("./types"), exports);
20
20
  __exportStar(require("./actions-sdk"), exports);
21
+ // Export individual functions for tree-shaking
22
+ var listAuths_1 = require("./functions/listAuths");
23
+ Object.defineProperty(exports, "listAuths", { enumerable: true, get: function () { return listAuths_1.listAuths; } });
24
+ var listApps_1 = require("./functions/listApps");
25
+ Object.defineProperty(exports, "listApps", { enumerable: true, get: function () { return listApps_1.listApps; } });
26
+ var getApp_1 = require("./functions/getApp");
27
+ Object.defineProperty(exports, "getApp", { enumerable: true, get: function () { return getApp_1.getApp; } });
28
+ var listActions_1 = require("./functions/listActions");
29
+ Object.defineProperty(exports, "listActions", { enumerable: true, get: function () { return listActions_1.listActions; } });
30
+ var getAction_1 = require("./functions/getAction");
31
+ Object.defineProperty(exports, "getAction", { enumerable: true, get: function () { return getAction_1.getAction; } });
32
+ var runAction_1 = require("./functions/runAction");
33
+ Object.defineProperty(exports, "runAction", { enumerable: true, get: function () { return runAction_1.runAction; } });
34
+ var listFields_1 = require("./functions/listFields");
35
+ Object.defineProperty(exports, "listFields", { enumerable: true, get: function () { return listFields_1.listFields; } });
36
+ var generateTypes_1 = require("./functions/generateTypes");
37
+ Object.defineProperty(exports, "generateTypes", { enumerable: true, get: function () { return generateTypes_1.generateTypes; } });
38
+ var bundleCode_1 = require("./functions/bundleCode");
39
+ Object.defineProperty(exports, "bundleCode", { enumerable: true, get: function () { return bundleCode_1.bundleCode; } });
21
40
  // Export the main combined SDK
22
41
  var sdk_1 = require("./sdk");
23
42
  Object.defineProperty(exports, "createZapierSdk", { enumerable: true, get: function () { return sdk_1.createZapierSdk; } });
@@ -36,14 +36,14 @@ export declare const ActionItemSchema: z.ZodObject<{
36
36
  appKey: z.ZodOptional<z.ZodString>;
37
37
  description: z.ZodOptional<z.ZodString>;
38
38
  }, "strip", z.ZodTypeAny, {
39
- type: string;
40
39
  key: string;
40
+ type: string;
41
41
  name?: string | undefined;
42
42
  description?: string | undefined;
43
43
  appKey?: string | undefined;
44
44
  }, {
45
- type: string;
46
45
  key: string;
46
+ type: string;
47
47
  name?: string | undefined;
48
48
  description?: string | undefined;
49
49
  appKey?: string | undefined;
@@ -59,19 +59,19 @@ export declare const AuthItemSchema: z.ZodObject<{
59
59
  marked_stale_at: z.ZodOptional<z.ZodString>;
60
60
  }, "strip", z.ZodTypeAny, {
61
61
  id: number;
62
+ account_id?: string | undefined;
62
63
  title?: string | undefined;
63
64
  label?: string | undefined;
64
65
  identifier?: string | undefined;
65
- account_id?: string | undefined;
66
66
  is_private?: boolean | undefined;
67
67
  shared_with_all?: boolean | undefined;
68
68
  marked_stale_at?: string | undefined;
69
69
  }, {
70
70
  id: number;
71
+ account_id?: string | undefined;
71
72
  title?: string | undefined;
72
73
  label?: string | undefined;
73
74
  identifier?: string | undefined;
74
- account_id?: string | undefined;
75
75
  is_private?: boolean | undefined;
76
76
  shared_with_all?: boolean | undefined;
77
77
  marked_stale_at?: string | undefined;
package/dist/schemas.d.ts CHANGED
@@ -48,14 +48,14 @@ export declare const FieldsListSchema: z.ZodObject<{
48
48
  action: string;
49
49
  type: "create" | "update" | "search" | "delete" | "read" | "write";
50
50
  app: string;
51
- params?: Record<string, any> | undefined;
52
51
  authId?: number | undefined;
52
+ params?: Record<string, any> | undefined;
53
53
  }, {
54
54
  action: string;
55
55
  type: "create" | "update" | "search" | "delete" | "read" | "write";
56
56
  app: string;
57
- params?: Record<string, any> | undefined;
58
57
  authId?: number | undefined;
58
+ params?: Record<string, any> | undefined;
59
59
  }>;
60
60
  export declare const ActionsListSchema: z.ZodObject<{
61
61
  appKey: z.ZodString;
@@ -90,14 +90,14 @@ export declare const ActionsRunSchema: z.ZodObject<{
90
90
  action: string;
91
91
  type: "create" | "update" | "search" | "delete" | "read" | "write";
92
92
  app: string;
93
- authId?: number | undefined;
94
93
  inputs?: Record<string, any> | undefined;
94
+ authId?: number | undefined;
95
95
  }, {
96
96
  action: string;
97
97
  type: "create" | "update" | "search" | "delete" | "read" | "write";
98
98
  app: string;
99
- authId?: number | undefined;
100
99
  inputs?: Record<string, any> | undefined;
100
+ authId?: number | undefined;
101
101
  }>;
102
102
  export declare const AuthsListSchema: z.ZodObject<{
103
103
  limit: z.ZodOptional<z.ZodNumber>;
@@ -108,15 +108,15 @@ export declare const AuthsListSchema: z.ZodObject<{
108
108
  }, "strip", z.ZodTypeAny, {
109
109
  appKey: string;
110
110
  account_id?: string | undefined;
111
+ owner?: string | undefined;
111
112
  limit?: number | undefined;
112
113
  offset?: number | undefined;
113
- owner?: string | undefined;
114
114
  }, {
115
115
  appKey: string;
116
116
  account_id?: string | undefined;
117
+ owner?: string | undefined;
117
118
  limit?: number | undefined;
118
119
  offset?: number | undefined;
119
- owner?: string | undefined;
120
120
  }>;
121
121
  export declare const AuthsFindSchema: z.ZodObject<{
122
122
  appKey: z.ZodString;
@@ -132,17 +132,17 @@ export declare const GenerateSchema: z.ZodObject<{
132
132
  output: z.ZodOptional<z.ZodString>;
133
133
  debug: z.ZodDefault<z.ZodBoolean>;
134
134
  }, "strip", z.ZodTypeAny, {
135
- appKey: string;
136
135
  debug: boolean;
137
- authId?: number | undefined;
136
+ appKey: string;
138
137
  token?: string | undefined;
138
+ authId?: number | undefined;
139
139
  output?: string | undefined;
140
140
  }, {
141
141
  appKey: string;
142
- authId?: number | undefined;
143
142
  token?: string | undefined;
144
- output?: string | undefined;
145
143
  debug?: boolean | undefined;
144
+ authId?: number | undefined;
145
+ output?: string | undefined;
146
146
  }>;
147
147
  export declare const BundleSchema: z.ZodObject<{
148
148
  input: z.ZodString;
@@ -154,17 +154,17 @@ export declare const BundleSchema: z.ZodObject<{
154
154
  }, "strip", z.ZodTypeAny, {
155
155
  string: boolean;
156
156
  input: string;
157
- minify: boolean;
158
157
  target: string;
159
158
  cjs: boolean;
159
+ minify: boolean;
160
160
  output?: string | undefined;
161
161
  }, {
162
162
  input: string;
163
163
  string?: boolean | undefined;
164
164
  output?: string | undefined;
165
- minify?: boolean | undefined;
166
165
  target?: string | undefined;
167
166
  cjs?: boolean | undefined;
167
+ minify?: boolean | undefined;
168
168
  }>;
169
169
  export declare const SdkSchemas: {
170
170
  readonly apps: {
@@ -223,14 +223,14 @@ export declare const SdkSchemas: {
223
223
  action: string;
224
224
  type: "create" | "update" | "search" | "delete" | "read" | "write";
225
225
  app: string;
226
- authId?: number | undefined;
227
226
  inputs?: Record<string, any> | undefined;
227
+ authId?: number | undefined;
228
228
  }, {
229
229
  action: string;
230
230
  type: "create" | "update" | "search" | "delete" | "read" | "write";
231
231
  app: string;
232
- authId?: number | undefined;
233
232
  inputs?: Record<string, any> | undefined;
233
+ authId?: number | undefined;
234
234
  }>;
235
235
  };
236
236
  readonly auths: {
@@ -243,15 +243,15 @@ export declare const SdkSchemas: {
243
243
  }, "strip", z.ZodTypeAny, {
244
244
  appKey: string;
245
245
  account_id?: string | undefined;
246
+ owner?: string | undefined;
246
247
  limit?: number | undefined;
247
248
  offset?: number | undefined;
248
- owner?: string | undefined;
249
249
  }, {
250
250
  appKey: string;
251
251
  account_id?: string | undefined;
252
+ owner?: string | undefined;
252
253
  limit?: number | undefined;
253
254
  offset?: number | undefined;
254
- owner?: string | undefined;
255
255
  }>;
256
256
  readonly find: z.ZodObject<{
257
257
  appKey: z.ZodString;
@@ -272,14 +272,14 @@ export declare const SdkSchemas: {
272
272
  action: string;
273
273
  type: "create" | "update" | "search" | "delete" | "read" | "write";
274
274
  app: string;
275
- params?: Record<string, any> | undefined;
276
275
  authId?: number | undefined;
276
+ params?: Record<string, any> | undefined;
277
277
  }, {
278
278
  action: string;
279
279
  type: "create" | "update" | "search" | "delete" | "read" | "write";
280
280
  app: string;
281
- params?: Record<string, any> | undefined;
282
281
  authId?: number | undefined;
282
+ params?: Record<string, any> | undefined;
283
283
  }>;
284
284
  };
285
285
  readonly generate: z.ZodObject<{
@@ -289,17 +289,17 @@ export declare const SdkSchemas: {
289
289
  output: z.ZodOptional<z.ZodString>;
290
290
  debug: z.ZodDefault<z.ZodBoolean>;
291
291
  }, "strip", z.ZodTypeAny, {
292
- appKey: string;
293
292
  debug: boolean;
294
- authId?: number | undefined;
293
+ appKey: string;
295
294
  token?: string | undefined;
295
+ authId?: number | undefined;
296
296
  output?: string | undefined;
297
297
  }, {
298
298
  appKey: string;
299
- authId?: number | undefined;
300
299
  token?: string | undefined;
301
- output?: string | undefined;
302
300
  debug?: boolean | undefined;
301
+ authId?: number | undefined;
302
+ output?: string | undefined;
303
303
  }>;
304
304
  readonly bundle: z.ZodObject<{
305
305
  input: z.ZodString;
@@ -311,17 +311,17 @@ export declare const SdkSchemas: {
311
311
  }, "strip", z.ZodTypeAny, {
312
312
  string: boolean;
313
313
  input: string;
314
- minify: boolean;
315
314
  target: string;
316
315
  cjs: boolean;
316
+ minify: boolean;
317
317
  output?: string | undefined;
318
318
  }, {
319
319
  input: string;
320
320
  string?: boolean | undefined;
321
321
  output?: string | undefined;
322
- minify?: boolean | undefined;
323
322
  target?: string | undefined;
324
323
  cjs?: boolean | undefined;
324
+ minify?: boolean | undefined;
325
325
  }>;
326
326
  };
327
327
  export type AppsListOptions = z.infer<typeof AppsListSchema>;
package/dist/types.d.ts CHANGED
@@ -177,6 +177,18 @@ export interface BaseSdkOptions {
177
177
  baseUrl?: string;
178
178
  debug?: boolean;
179
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
+ }
180
192
  export interface CombinedSdk {
181
193
  [namespace: string]: any;
182
194
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zapier/zapier-sdk",
3
- "version": "0.0.2",
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",