@zapier/zapier-sdk 0.1.1 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dist/api/client.js +23 -6
  2. package/dist/api/index.d.ts +4 -2
  3. package/dist/api/index.js +5 -4
  4. package/dist/api/types.d.ts +3 -1
  5. package/dist/auth.d.ts +59 -0
  6. package/dist/auth.js +261 -0
  7. package/dist/functions/getAction/info.d.ts +3 -3
  8. package/dist/functions/getAction/schemas.d.ts +3 -3
  9. package/dist/functions/getAuthentication/index.d.ts +13 -0
  10. package/dist/functions/getAuthentication/index.js +38 -0
  11. package/dist/functions/getAuthentication/info.d.ts +12 -0
  12. package/dist/functions/getAuthentication/info.js +11 -0
  13. package/dist/functions/getAuthentication/schemas.d.ts +26 -0
  14. package/dist/functions/getAuthentication/schemas.js +16 -0
  15. package/dist/functions/listActions/info.d.ts +3 -3
  16. package/dist/functions/listActions/schemas.d.ts +3 -3
  17. package/dist/functions/listAuthentications/index.js +1 -4
  18. package/dist/functions/listAuthentications/schemas.d.ts +2 -0
  19. package/dist/functions/listFields/info.d.ts +3 -3
  20. package/dist/functions/listFields/schemas.d.ts +3 -3
  21. package/dist/functions/runAction/index.js +8 -79
  22. package/dist/functions/runAction/info.d.ts +3 -3
  23. package/dist/functions/runAction/schemas.d.ts +5 -3
  24. package/dist/index.d.ts +2 -0
  25. package/dist/index.js +5 -1
  26. package/dist/sdk.js +40 -60
  27. package/dist/types/domain.d.ts +3 -0
  28. package/dist/types/events.d.ts +37 -0
  29. package/dist/types/events.js +8 -0
  30. package/dist/types/properties.d.ts +1 -1
  31. package/dist/types/properties.js +10 -1
  32. package/dist/types/sdk.d.ts +2 -1
  33. package/package.json +4 -3
  34. package/src/api/client.ts +31 -5
  35. package/src/api/index.ts +12 -5
  36. package/src/api/types.ts +11 -1
  37. package/src/auth.ts +340 -0
  38. package/src/functions/getAuthentication/index.ts +51 -0
  39. package/src/functions/getAuthentication/info.ts +9 -0
  40. package/src/functions/getAuthentication/schemas.ts +43 -0
  41. package/src/functions/listAuthentications/index.ts +1 -8
  42. package/src/functions/listAuthentications/schemas.ts +2 -0
  43. package/src/functions/runAction/index.ts +11 -141
  44. package/src/functions/runAction/schemas.ts +2 -0
  45. package/src/index.ts +4 -0
  46. package/src/sdk.ts +35 -87
  47. package/src/types/domain.ts +5 -0
  48. package/src/types/events.ts +43 -0
  49. package/src/types/properties.ts +10 -1
  50. package/src/types/sdk.ts +2 -0
@@ -13,11 +13,8 @@ const getApp_1 = require("../getApp");
13
13
  * @returns Promise<Authentication[]> with pagination metadata
14
14
  */
15
15
  async function listAuthentications(options = {}) {
16
- const { token } = options;
17
- if (!token && !process.env.ZAPIER_TOKEN) {
18
- throw new Error("Authentication token is required to list authentications. Please provide token in options or set ZAPIER_TOKEN environment variable.");
19
- }
20
16
  const api = (0, api_1.getOrCreateApiClient)(options);
17
+ api.requireAuthTo("list authentications");
21
18
  // Local function to handle the actual API fetching
22
19
  const listAuthenticationsInternal = async (options = {}) => {
23
20
  // Build search parameters
@@ -30,6 +30,8 @@ export type ListAuthenticationsOptions = z.infer<typeof ListAuthenticationsSchem
30
30
  baseUrl?: string;
31
31
  /** Authentication token */
32
32
  token?: string;
33
+ /** Function to dynamically resolve authentication token */
34
+ getToken?: () => Promise<string | undefined>;
33
35
  /** Optional pre-instantiated API client */
34
36
  api?: any;
35
37
  /** Enable debug logging */
@@ -3,19 +3,19 @@ export declare const listFieldsInfo: {
3
3
  name: string;
4
4
  inputSchema: import("zod").ZodObject<{
5
5
  appKey: import("zod").ZodString;
6
- actionType: import("zod").ZodEnum<["read", "write", "search", "create", "update", "delete"]>;
6
+ actionType: import("zod").ZodEnum<["read", "read_bulk", "write", "run", "search", "search_or_write", "search_and_write", "filter"]>;
7
7
  actionKey: import("zod").ZodString;
8
8
  authenticationId: import("zod").ZodOptional<import("zod").ZodNumber>;
9
9
  params: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodAny>>;
10
10
  }, "strip", import("zod").ZodTypeAny, {
11
11
  appKey: string;
12
- actionType: "create" | "update" | "search" | "delete" | "read" | "write";
12
+ actionType: "read" | "read_bulk" | "write" | "run" | "search" | "search_or_write" | "search_and_write" | "filter";
13
13
  actionKey: string;
14
14
  params?: Record<string, any> | undefined;
15
15
  authenticationId?: number | undefined;
16
16
  }, {
17
17
  appKey: string;
18
- actionType: "create" | "update" | "search" | "delete" | "read" | "write";
18
+ actionType: "read" | "read_bulk" | "write" | "run" | "search" | "search_or_write" | "search_and_write" | "filter";
19
19
  actionKey: string;
20
20
  params?: Record<string, any> | undefined;
21
21
  authenticationId?: number | undefined;
@@ -2,19 +2,19 @@ import { z } from "zod";
2
2
  import type { ActionField } from "../../types/domain";
3
3
  export declare const ListFieldsSchema: z.ZodObject<{
4
4
  appKey: z.ZodString;
5
- actionType: z.ZodEnum<["read", "write", "search", "create", "update", "delete"]>;
5
+ actionType: z.ZodEnum<["read", "read_bulk", "write", "run", "search", "search_or_write", "search_and_write", "filter"]>;
6
6
  actionKey: z.ZodString;
7
7
  authenticationId: z.ZodOptional<z.ZodNumber>;
8
8
  params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
9
9
  }, "strip", z.ZodTypeAny, {
10
10
  appKey: string;
11
- actionType: "create" | "update" | "search" | "delete" | "read" | "write";
11
+ actionType: "read" | "read_bulk" | "write" | "run" | "search" | "search_or_write" | "search_and_write" | "filter";
12
12
  actionKey: string;
13
13
  params?: Record<string, any> | undefined;
14
14
  authenticationId?: number | undefined;
15
15
  }, {
16
16
  appKey: string;
17
- actionType: "create" | "update" | "search" | "delete" | "read" | "write";
17
+ actionType: "read" | "read_bulk" | "write" | "run" | "search" | "search_or_write" | "search_and_write" | "filter";
18
18
  actionKey: string;
19
19
  params?: Record<string, any> | undefined;
20
20
  authenticationId?: number | undefined;
@@ -14,11 +14,9 @@ const getApp_1 = require("../getApp");
14
14
  * @returns Promise<ActionExecutionResult>
15
15
  */
16
16
  async function runAction(options) {
17
- const { appKey, actionType, actionKey, inputs, authenticationId: providedAuthenticationId, 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
- }
17
+ const { appKey, actionType, actionKey, inputs, authenticationId: providedAuthenticationId, } = options;
21
18
  const api = (0, api_1.getOrCreateApiClient)(options);
19
+ api.requireAuthTo("run actions");
22
20
  // Validate that the action exists
23
21
  const actionData = await (0, getAction_1.getAction)({
24
22
  ...options,
@@ -30,17 +28,15 @@ async function runAction(options) {
30
28
  if (actionData.type !== actionType) {
31
29
  throw new Error(`Action type mismatch: expected ${actionType}, got ${actionData.type}`);
32
30
  }
33
- // Execute the action using the appropriate API based on action type
31
+ // Execute the action using the Actions API (supports all action types)
34
32
  const startTime = Date.now();
35
- const result = await executeActionWithStrategy({
33
+ const result = await executeAction({
36
34
  api,
37
35
  appSlug: appKey,
38
36
  actionKey: actionKey,
39
37
  actionType: actionData.type,
40
38
  executionOptions: { inputs: inputs || {} },
41
- auth: token
42
- ? { token: token, authentication_id: providedAuthenticationId }
43
- : undefined,
39
+ authenticationId: providedAuthenticationId,
44
40
  options,
45
41
  });
46
42
  const executionTime = Date.now() - startTime;
@@ -53,37 +49,8 @@ async function runAction(options) {
53
49
  },
54
50
  };
55
51
  }
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;
52
+ async function executeAction(actionOptions) {
53
+ const { api, appSlug, actionKey, actionType, executionOptions, authenticationId, options, } = actionOptions;
87
54
  // Use the standalone getApp function
88
55
  const appData = await (0, getApp_1.getApp)({
89
56
  appKey: appSlug,
@@ -97,13 +64,10 @@ async function executeActionViaActionsApi(apiOptions) {
97
64
  if (!selectedApi) {
98
65
  throw new Error("No current_implementation_id found for app");
99
66
  }
100
- if (!auth?.token) {
101
- throw new Error("Authentication token is required. Please provide token when creating the SDK.");
102
- }
103
67
  // Step 1: POST to /actions/v1/runs to start execution
104
68
  const runRequest = {
105
69
  data: {
106
- authentication_id: auth.authentication_id || 1,
70
+ authentication_id: authenticationId || 1,
107
71
  selected_api: selectedApi,
108
72
  action_key: actionKey,
109
73
  action_type: actionType,
@@ -119,39 +83,4 @@ async function executeActionViaActionsApi(apiOptions) {
119
83
  resultExtractor: (result) => result.data,
120
84
  });
121
85
  }
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
- appKey: 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
- }
157
86
  // No registry info here - moved to info.ts for proper tree-shaking
@@ -3,19 +3,19 @@ export declare const runActionInfo: {
3
3
  name: string;
4
4
  inputSchema: import("zod").ZodObject<{
5
5
  appKey: import("zod").ZodString;
6
- actionType: import("zod").ZodEnum<["read", "write", "search", "create", "update", "delete"]>;
6
+ actionType: import("zod").ZodEnum<["read", "read_bulk", "write", "run", "search", "search_or_write", "search_and_write", "filter"]>;
7
7
  actionKey: import("zod").ZodString;
8
8
  inputs: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodAny>>;
9
9
  authenticationId: import("zod").ZodOptional<import("zod").ZodNumber>;
10
10
  }, "strip", import("zod").ZodTypeAny, {
11
11
  appKey: string;
12
- actionType: "create" | "update" | "search" | "delete" | "read" | "write";
12
+ actionType: "read" | "read_bulk" | "write" | "run" | "search" | "search_or_write" | "search_and_write" | "filter";
13
13
  actionKey: string;
14
14
  inputs?: Record<string, any> | undefined;
15
15
  authenticationId?: number | undefined;
16
16
  }, {
17
17
  appKey: string;
18
- actionType: "create" | "update" | "search" | "delete" | "read" | "write";
18
+ actionType: "read" | "read_bulk" | "write" | "run" | "search" | "search_or_write" | "search_and_write" | "filter";
19
19
  actionKey: string;
20
20
  inputs?: Record<string, any> | undefined;
21
21
  authenticationId?: number | undefined;
@@ -2,19 +2,19 @@ import { z } from "zod";
2
2
  import type { ActionExecutionResult } from "../../types/domain";
3
3
  export declare const RunActionSchema: z.ZodObject<{
4
4
  appKey: z.ZodString;
5
- actionType: z.ZodEnum<["read", "write", "search", "create", "update", "delete"]>;
5
+ actionType: z.ZodEnum<["read", "read_bulk", "write", "run", "search", "search_or_write", "search_and_write", "filter"]>;
6
6
  actionKey: z.ZodString;
7
7
  inputs: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
8
8
  authenticationId: z.ZodOptional<z.ZodNumber>;
9
9
  }, "strip", z.ZodTypeAny, {
10
10
  appKey: string;
11
- actionType: "create" | "update" | "search" | "delete" | "read" | "write";
11
+ actionType: "read" | "read_bulk" | "write" | "run" | "search" | "search_or_write" | "search_and_write" | "filter";
12
12
  actionKey: string;
13
13
  inputs?: Record<string, any> | undefined;
14
14
  authenticationId?: number | undefined;
15
15
  }, {
16
16
  appKey: string;
17
- actionType: "create" | "update" | "search" | "delete" | "read" | "write";
17
+ actionType: "read" | "read_bulk" | "write" | "run" | "search" | "search_or_write" | "search_and_write" | "filter";
18
18
  actionKey: string;
19
19
  inputs?: Record<string, any> | undefined;
20
20
  authenticationId?: number | undefined;
@@ -24,6 +24,8 @@ export type RunActionOptions = z.infer<typeof RunActionSchema> & {
24
24
  baseUrl?: string;
25
25
  /** Authentication token */
26
26
  token?: string;
27
+ /** Function to dynamically resolve authentication token */
28
+ getToken?: () => Promise<string | undefined>;
27
29
  /** Optional pre-instantiated API client */
28
30
  api?: any;
29
31
  /** Enable debug logging */
package/dist/index.d.ts CHANGED
@@ -2,8 +2,10 @@ export * from "./types/domain";
2
2
  export * from "./types/properties";
3
3
  export * from "./plugins/apps";
4
4
  export { isPositional } from "./schema-utils";
5
+ export * from "./auth";
5
6
  export * from "./resolvers";
6
7
  export { listAuthentications } from "./functions/listAuthentications";
8
+ export { getAuthentication } from "./functions/getAuthentication";
7
9
  export { findFirstAuthentication } from "./functions/findFirstAuthentication";
8
10
  export { findUniqueAuthentication } from "./functions/findUniqueAuthentication";
9
11
  export { listApps } from "./functions/listApps";
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ 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 = exports.bundleCode = exports.generateTypes = exports.listFields = exports.runAction = exports.getAction = exports.listActions = exports.getApp = exports.listApps = exports.findUniqueAuthentication = exports.findFirstAuthentication = exports.listAuthentications = exports.isPositional = void 0;
17
+ exports.createZapierSdk = exports.bundleCode = exports.generateTypes = exports.listFields = exports.runAction = exports.getAction = exports.listActions = exports.getApp = exports.listApps = exports.findUniqueAuthentication = exports.findFirstAuthentication = exports.getAuthentication = exports.listAuthentications = exports.isPositional = void 0;
18
18
  // Export everything from types and plugins
19
19
  __exportStar(require("./types/domain"), exports);
20
20
  __exportStar(require("./types/properties"), exports);
@@ -22,12 +22,16 @@ __exportStar(require("./plugins/apps"), exports);
22
22
  // Export schema utilities for CLI
23
23
  var schema_utils_1 = require("./schema-utils");
24
24
  Object.defineProperty(exports, "isPositional", { enumerable: true, get: function () { return schema_utils_1.isPositional; } });
25
+ // Export auth utilities for CLI use
26
+ __exportStar(require("./auth"), exports);
25
27
  // Export resolvers for CLI use
26
28
  __exportStar(require("./resolvers"), exports);
27
29
  // Note: SdkSchemas is now available via SDK.__registry
28
30
  // Export individual functions for tree-shaking
29
31
  var listAuthentications_1 = require("./functions/listAuthentications");
30
32
  Object.defineProperty(exports, "listAuthentications", { enumerable: true, get: function () { return listAuthentications_1.listAuthentications; } });
33
+ var getAuthentication_1 = require("./functions/getAuthentication");
34
+ Object.defineProperty(exports, "getAuthentication", { enumerable: true, get: function () { return getAuthentication_1.getAuthentication; } });
31
35
  var findFirstAuthentication_1 = require("./functions/findFirstAuthentication");
32
36
  Object.defineProperty(exports, "findFirstAuthentication", { enumerable: true, get: function () { return findFirstAuthentication_1.findFirstAuthentication; } });
33
37
  var findUniqueAuthentication_1 = require("./functions/findUniqueAuthentication");
package/dist/sdk.js CHANGED
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createZapierSdk = createZapierSdk;
4
4
  const api_1 = require("./api");
5
+ const auth_1 = require("./auth");
5
6
  // Import function implementations
6
7
  const listApps_1 = require("./functions/listApps");
7
8
  const getApp_1 = require("./functions/getApp");
@@ -9,6 +10,7 @@ const listActions_1 = require("./functions/listActions");
9
10
  const getAction_1 = require("./functions/getAction");
10
11
  const runAction_1 = require("./functions/runAction");
11
12
  const listAuthentications_1 = require("./functions/listAuthentications");
13
+ const getAuthentication_1 = require("./functions/getAuthentication");
12
14
  const findFirstAuthentication_1 = require("./functions/findFirstAuthentication");
13
15
  const findUniqueAuthentication_1 = require("./functions/findUniqueAuthentication");
14
16
  const listFields_1 = require("./functions/listFields");
@@ -21,11 +23,12 @@ const info_3 = require("./functions/listActions/info");
21
23
  const info_4 = require("./functions/getAction/info");
22
24
  const info_5 = require("./functions/runAction/info");
23
25
  const info_6 = require("./functions/listAuthentications/info");
24
- const info_7 = require("./functions/findFirstAuthentication/info");
25
- const info_8 = require("./functions/findUniqueAuthentication/info");
26
- const info_9 = require("./functions/listFields/info");
27
- const info_10 = require("./functions/generateTypes/info");
28
- const info_11 = require("./functions/bundleCode/info");
26
+ const info_7 = require("./functions/getAuthentication/info");
27
+ const info_8 = require("./functions/findFirstAuthentication/info");
28
+ const info_9 = require("./functions/findUniqueAuthentication/info");
29
+ const info_10 = require("./functions/listFields/info");
30
+ const info_11 = require("./functions/generateTypes/info");
31
+ const info_12 = require("./functions/bundleCode/info");
29
32
  // Function registry as array - uses names from function info objects
30
33
  const functionRegistry = [
31
34
  info_1.listAppsInfo,
@@ -34,76 +37,53 @@ const functionRegistry = [
34
37
  info_4.getActionInfo,
35
38
  info_5.runActionInfo,
36
39
  info_6.listAuthenticationsInfo,
37
- info_7.findFirstAuthenticationInfo,
38
- info_8.findUniqueAuthenticationInfo,
39
- info_9.listFieldsInfo,
40
- info_10.generateTypesInfo,
41
- info_11.bundleCodeInfo,
40
+ info_7.getAuthenticationInfo,
41
+ info_8.findFirstAuthenticationInfo,
42
+ info_9.findUniqueAuthenticationInfo,
43
+ info_10.listFieldsInfo,
44
+ info_11.generateTypesInfo,
45
+ info_12.bundleCodeInfo,
42
46
  ];
43
47
  // Import plugin functions
44
48
  const index_1 = require("./plugins/apps/index");
45
- function createBaseZapierSdk(options = {}) {
46
- // Auto-load .env files (searches up directory tree)
47
- try {
48
- const { findUpSync } = require("find-up");
49
- const envPath = findUpSync(".env");
50
- if (envPath) {
51
- require("dotenv").config({ path: envPath, quiet: true });
52
- }
53
- }
54
- catch {
55
- // Silently fail if dotenv/find-up not available or .env not found
56
- }
57
- const { fetch: customFetch = globalThis.fetch, baseUrl = "https://zapier.com", token, debug = false, } = options;
58
- // If no token provided, try to get it from environment variable
59
- const finalToken = token || process.env.ZAPIER_TOKEN;
60
- // Create the API client
61
- const api = (0, api_1.createZapierApi)({
62
- baseUrl,
63
- token: finalToken,
64
- debug,
65
- fetch: customFetch,
66
- });
67
- // Build SDK directly - TypeScript will enforce correct implementation
68
- const sdk = {
69
- // Registry for CLI
70
- __registry: functionRegistry,
71
- // Function implementations with API config injection
72
- listApps: (options = {}) => (0, listApps_1.listApps)({ ...options, api, token: finalToken }),
73
- getApp: (options) => (0, getApp_1.getApp)({ ...options, api, token: finalToken }),
74
- listActions: (options = {}) => (0, listActions_1.listActions)({ ...options, api, token: finalToken }),
75
- getAction: (options) => (0, getAction_1.getAction)({ ...options, api, token: finalToken }),
76
- runAction: (options) => (0, runAction_1.runAction)({ ...options, api, token: finalToken }),
77
- listAuthentications: (options = {}) => (0, listAuthentications_1.listAuthentications)({ ...options, api, token: finalToken }),
78
- findFirstAuthentication: (options = {}) => (0, findFirstAuthentication_1.findFirstAuthentication)({ ...options, api, token: finalToken }),
79
- findUniqueAuthentication: (options = {}) => (0, findUniqueAuthentication_1.findUniqueAuthentication)({ ...options, api, token: finalToken }),
80
- listFields: (options) => (0, listFields_1.listFields)({ ...options, api, token: finalToken }),
81
- generateTypes: (options) => (0, generateTypes_1.generateTypes)({ ...options, api, token: finalToken }),
82
- bundleCode: (options) => (0, bundleCode_1.bundleCode)(options), // No API config needed
83
- };
84
- return sdk;
85
- }
86
49
  function createZapierSdk(options = {}) {
87
- // Create base SDK
88
- const baseSdk = createBaseZapierSdk(options);
89
- // Extract options needed for plugins
90
- const { fetch: customFetch = globalThis.fetch, baseUrl = "https://zapier.com", token, debug = false, } = options;
91
- const finalToken = token || process.env.ZAPIER_TOKEN;
92
- // Create the API client for plugins
50
+ const { fetch: customFetch = globalThis.fetch, baseUrl = "https://zapier.com", token, getToken, onEvent, debug = false, } = options;
51
+ // If no explicit token or getToken provided, try env var then CLI config with event callbacks
52
+ const resolvedGetToken = getToken ||
53
+ (!token
54
+ ? () => (0, auth_1.getTokenFromEnvOrConfig)({ onEvent, fetch: customFetch })
55
+ : undefined);
56
+ // Create the API client
93
57
  const api = (0, api_1.createZapierApi)({
94
58
  baseUrl,
95
- token: finalToken,
59
+ token,
60
+ getToken: resolvedGetToken,
96
61
  debug,
97
62
  fetch: customFetch,
98
63
  });
99
64
  // Create plugins directly - TypeScript will enforce correct implementation
100
65
  const appsPlugin = (0, index_1.createAppsPlugin)({
101
66
  api,
102
- token: finalToken,
67
+ token,
103
68
  });
104
69
  // Compose final SDK - TypeScript will enforce we have all required properties
105
70
  const fullSdk = {
106
- ...baseSdk,
71
+ // Registry for CLI
72
+ __registry: functionRegistry,
73
+ // Function implementations with API config injection
74
+ listApps: (options = {}) => (0, listApps_1.listApps)({ ...options, api }),
75
+ getApp: (options) => (0, getApp_1.getApp)({ ...options, api }),
76
+ listActions: (options = {}) => (0, listActions_1.listActions)({ ...options, api }),
77
+ getAction: (options) => (0, getAction_1.getAction)({ ...options, api }),
78
+ runAction: (options) => (0, runAction_1.runAction)({ ...options, api }),
79
+ listAuthentications: (options = {}) => (0, listAuthentications_1.listAuthentications)({ ...options, api }),
80
+ getAuthentication: (options) => (0, getAuthentication_1.getAuthentication)({ ...options, api }),
81
+ findFirstAuthentication: (options = {}) => (0, findFirstAuthentication_1.findFirstAuthentication)({ ...options, api }),
82
+ findUniqueAuthentication: (options = {}) => (0, findUniqueAuthentication_1.findUniqueAuthentication)({ ...options, api }),
83
+ listFields: (options) => (0, listFields_1.listFields)({ ...options, api }),
84
+ generateTypes: (options) => (0, generateTypes_1.generateTypes)({ ...options, api }),
85
+ bundleCode: (options) => (0, bundleCode_1.bundleCode)(options), // No API config needed
86
+ // Add plugins
107
87
  apps: appsPlugin,
108
88
  };
109
89
  return fullSdk;
@@ -1,4 +1,5 @@
1
1
  export type { Integration, Action, Trigger, Field, Choice, ActionExecutionResult, ActionField, ActionFieldChoice, NeedsRequest, NeedsResponse, Authentication, AuthenticationsResponse, } from "../api/types";
2
+ import type { EventCallback } from "./events";
2
3
  export interface ActionExecutionOptions {
3
4
  inputs?: Record<string, any>;
4
5
  authenticationId?: number;
@@ -8,6 +9,8 @@ export interface AuthObject {
8
9
  }
9
10
  export interface BaseSdkOptions {
10
11
  token?: string;
12
+ getToken?: () => Promise<string | undefined>;
13
+ onEvent?: EventCallback;
11
14
  fetch?: typeof fetch;
12
15
  baseUrl?: string;
13
16
  debug?: boolean;
@@ -0,0 +1,37 @@
1
+ /**
2
+ * SDK Event System
3
+ *
4
+ * This module provides common event type definitions for the SDK's
5
+ * event system, including authentication, API, and loading events.
6
+ */
7
+ export interface SdkEvent {
8
+ type: string;
9
+ payload?: Record<string, any>;
10
+ timestamp?: number;
11
+ }
12
+ export interface AuthEvent extends SdkEvent {
13
+ type: "auth_refreshing" | "auth_success" | "auth_error" | "auth_logout";
14
+ payload?: {
15
+ message?: string;
16
+ error?: string;
17
+ operation?: string;
18
+ };
19
+ }
20
+ export interface ApiEvent extends SdkEvent {
21
+ type: "api_request" | "api_response" | "api_error";
22
+ payload?: {
23
+ url?: string;
24
+ method?: string;
25
+ status?: number;
26
+ duration?: number;
27
+ error?: string;
28
+ };
29
+ }
30
+ export interface LoadingEvent extends SdkEvent {
31
+ type: "loading_start" | "loading_end";
32
+ payload?: {
33
+ operation?: string;
34
+ resource?: string;
35
+ };
36
+ }
37
+ export type EventCallback = (event: SdkEvent) => void;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ /**
3
+ * SDK Event System
4
+ *
5
+ * This module provides common event type definitions for the SDK's
6
+ * event system, including authentication, API, and loading events.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
2
  export declare const AppKeyPropertySchema: z.ZodString;
3
- export declare const ActionTypePropertySchema: z.ZodEnum<["read", "write", "search", "create", "update", "delete"]>;
3
+ export declare const ActionTypePropertySchema: z.ZodEnum<["read", "read_bulk", "write", "run", "search", "search_or_write", "search_and_write", "filter"]>;
4
4
  export declare const ActionKeyPropertySchema: z.ZodString;
5
5
  export declare const AuthenticationIdPropertySchema: z.ZodNumber;
6
6
  export declare const InputsPropertySchema: z.ZodRecord<z.ZodString, z.ZodAny>;
@@ -7,7 +7,16 @@ const schema_utils_1 = require("../schema-utils");
7
7
  // These can be reused in function schemas without duplication
8
8
  exports.AppKeyPropertySchema = (0, schema_utils_1.withPositional)(zod_1.z.string().min(1).describe("App slug (e.g., 'slack', 'github')"));
9
9
  exports.ActionTypePropertySchema = zod_1.z
10
- .enum(["read", "write", "search", "create", "update", "delete"])
10
+ .enum([
11
+ "read",
12
+ "read_bulk",
13
+ "write",
14
+ "run",
15
+ "search",
16
+ "search_or_write",
17
+ "search_and_write",
18
+ "filter",
19
+ ])
11
20
  .describe("Action type that matches the action's defined type");
12
21
  exports.ActionKeyPropertySchema = zod_1.z
13
22
  .string()
@@ -4,13 +4,14 @@ import type { GetAppSdkFunction } from "../functions/getApp/schemas";
4
4
  import type { RunActionSdkFunction } from "../functions/runAction/schemas";
5
5
  import type { ListFieldsSdkFunction } from "../functions/listFields/schemas";
6
6
  import type { ListAuthenticationsSdkFunction } from "../functions/listAuthentications/schemas";
7
+ import type { GetAuthenticationSdkFunction } from "../functions/getAuthentication/schemas";
7
8
  import type { FindFirstAuthenticationSdkFunction } from "../functions/findFirstAuthentication/schemas";
8
9
  import type { FindUniqueAuthenticationSdkFunction } from "../functions/findUniqueAuthentication/schemas";
9
10
  import type { GenerateTypesSdkFunction } from "../functions/generateTypes/schemas";
10
11
  import type { ListAppsSdkFunction } from "../functions/listApps/schemas";
11
12
  import type { BundleCodeSdkFunction } from "../functions/bundleCode/schemas";
12
13
  import type { AppsPluginSdkExtension } from "../plugins/apps/types";
13
- export interface ZapierSdkFunctions extends ListActionsSdkFunction, GetActionSdkFunction, GetAppSdkFunction, RunActionSdkFunction, ListFieldsSdkFunction, ListAuthenticationsSdkFunction, FindFirstAuthenticationSdkFunction, FindUniqueAuthenticationSdkFunction, GenerateTypesSdkFunction, ListAppsSdkFunction, BundleCodeSdkFunction {
14
+ export interface ZapierSdkFunctions extends ListActionsSdkFunction, GetActionSdkFunction, GetAppSdkFunction, RunActionSdkFunction, ListFieldsSdkFunction, ListAuthenticationsSdkFunction, GetAuthenticationSdkFunction, FindFirstAuthenticationSdkFunction, FindUniqueAuthenticationSdkFunction, GenerateTypesSdkFunction, ListAppsSdkFunction, BundleCodeSdkFunction {
14
15
  }
15
16
  export interface ZapierSdkPlugins extends AppsPluginSdkExtension {
16
17
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zapier/zapier-sdk",
3
- "version": "0.1.1",
3
+ "version": "0.2.1",
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,12 +18,13 @@
18
18
  "access": "restricted"
19
19
  },
20
20
  "dependencies": {
21
- "dotenv": "^17.0.0",
21
+ "conf": "^14.0.0",
22
22
  "esbuild": "^0.25.5",
23
- "find-up": "^7.0.0",
23
+ "jsonwebtoken": "^9.0.2",
24
24
  "zod": "^3.25.67"
25
25
  },
26
26
  "devDependencies": {
27
+ "@types/jsonwebtoken": "^9.0.10",
27
28
  "@types/node": "^24.0.1",
28
29
  "typescript": "^5.8.3"
29
30
  },