@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,24 @@
1
+ import { listFields } from "./index";
2
+ export declare const listFieldsInfo: {
3
+ name: string;
4
+ inputSchema: import("zod").ZodObject<{
5
+ appKey: import("zod").ZodString;
6
+ actionType: import("zod").ZodEnum<["read", "write", "search", "create", "update", "delete"]>;
7
+ actionKey: import("zod").ZodString;
8
+ authenticationId: import("zod").ZodOptional<import("zod").ZodNumber>;
9
+ params: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodAny>>;
10
+ }, "strip", import("zod").ZodTypeAny, {
11
+ appKey: string;
12
+ actionType: "create" | "update" | "search" | "delete" | "read" | "write";
13
+ actionKey: string;
14
+ params?: Record<string, any> | undefined;
15
+ authenticationId?: number | undefined;
16
+ }, {
17
+ appKey: string;
18
+ actionType: "create" | "update" | "search" | "delete" | "read" | "write";
19
+ actionKey: string;
20
+ params?: Record<string, any> | undefined;
21
+ authenticationId?: number | undefined;
22
+ }>;
23
+ implementation: typeof listFields;
24
+ };
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.listFieldsInfo = void 0;
4
+ const index_1 = require("./index");
5
+ const schemas_1 = require("./schemas");
6
+ // Function registry info - imports both function and schema
7
+ exports.listFieldsInfo = {
8
+ name: index_1.listFields.name,
9
+ inputSchema: schemas_1.ListFieldsSchema,
10
+ implementation: index_1.listFields,
11
+ };
@@ -0,0 +1,36 @@
1
+ import { z } from "zod";
2
+ import type { ActionField } from "../../types/domain";
3
+ export declare const ListFieldsSchema: z.ZodObject<{
4
+ appKey: z.ZodString;
5
+ actionType: z.ZodEnum<["read", "write", "search", "create", "update", "delete"]>;
6
+ actionKey: z.ZodString;
7
+ authenticationId: z.ZodOptional<z.ZodNumber>;
8
+ params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
9
+ }, "strip", z.ZodTypeAny, {
10
+ appKey: string;
11
+ actionType: "create" | "update" | "search" | "delete" | "read" | "write";
12
+ actionKey: string;
13
+ params?: Record<string, any> | undefined;
14
+ authenticationId?: number | undefined;
15
+ }, {
16
+ appKey: string;
17
+ actionType: "create" | "update" | "search" | "delete" | "read" | "write";
18
+ actionKey: string;
19
+ params?: Record<string, any> | undefined;
20
+ authenticationId?: number | undefined;
21
+ }>;
22
+ export type ListFieldsOptions = z.infer<typeof ListFieldsSchema> & {
23
+ /** Base URL for Zapier API */
24
+ baseUrl?: string;
25
+ /** Authentication token */
26
+ token?: string;
27
+ /** Optional pre-instantiated API client */
28
+ api?: any;
29
+ /** Enable debug logging */
30
+ debug?: boolean;
31
+ /** Custom fetch implementation */
32
+ fetch?: typeof globalThis.fetch;
33
+ };
34
+ export interface ListFieldsSdkFunction {
35
+ listFields: (options: ListFieldsOptions) => Promise<ActionField[]>;
36
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ListFieldsSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ const properties_1 = require("../../types/properties");
6
+ const schema_utils_1 = require("../../schema-utils");
7
+ const Field_1 = require("../../schemas/Field");
8
+ // Pure Zod schema - no resolver metadata!
9
+ exports.ListFieldsSchema = (0, schema_utils_1.withOutputSchema)(zod_1.z
10
+ .object({
11
+ appKey: properties_1.AppKeyPropertySchema,
12
+ actionType: properties_1.ActionTypePropertySchema,
13
+ actionKey: properties_1.ActionKeyPropertySchema,
14
+ authenticationId: properties_1.AuthenticationIdPropertySchema.optional(),
15
+ params: properties_1.ParamsPropertySchema.optional().describe("Additional parameters that may affect available fields"),
16
+ })
17
+ .describe("Get the input fields required for a specific action"), Field_1.FieldItemSchema);
@@ -0,0 +1,12 @@
1
+ import type { ActionExecutionResult } from "../../types/domain";
2
+ import type { RunActionOptions } from "./schemas";
3
+ /**
4
+ * Execute an action
5
+ *
6
+ * This function can be used standalone without instantiating a full SDK,
7
+ * which enables better tree-shaking in applications that only need this functionality.
8
+ *
9
+ * @param options - Action execution parameters and API configuration options
10
+ * @returns Promise<ActionExecutionResult>
11
+ */
12
+ export declare function runAction(options: RunActionOptions): Promise<ActionExecutionResult>;
@@ -0,0 +1,157 @@
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 { 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
+ }
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
+ appKey: appKey,
26
+ actionKey: actionKey,
27
+ actionType: actionType,
28
+ });
29
+ // Validate action type matches
30
+ if (actionData.type !== actionType) {
31
+ throw new Error(`Action type mismatch: expected ${actionType}, 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: appKey,
38
+ actionKey: actionKey,
39
+ actionType: actionData.type,
40
+ executionOptions: { inputs: inputs || {} },
41
+ auth: token
42
+ ? { token: token, authentication_id: providedAuthenticationId }
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
+ appKey: 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
+ 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
+ // No registry info here - moved to info.ts for proper tree-shaking
@@ -0,0 +1,24 @@
1
+ import { runAction } from "./index";
2
+ export declare const runActionInfo: {
3
+ name: string;
4
+ inputSchema: import("zod").ZodObject<{
5
+ appKey: import("zod").ZodString;
6
+ actionType: import("zod").ZodEnum<["read", "write", "search", "create", "update", "delete"]>;
7
+ actionKey: import("zod").ZodString;
8
+ inputs: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodAny>>;
9
+ authenticationId: import("zod").ZodOptional<import("zod").ZodNumber>;
10
+ }, "strip", import("zod").ZodTypeAny, {
11
+ appKey: string;
12
+ actionType: "create" | "update" | "search" | "delete" | "read" | "write";
13
+ actionKey: string;
14
+ inputs?: Record<string, any> | undefined;
15
+ authenticationId?: number | undefined;
16
+ }, {
17
+ appKey: string;
18
+ actionType: "create" | "update" | "search" | "delete" | "read" | "write";
19
+ actionKey: string;
20
+ inputs?: Record<string, any> | undefined;
21
+ authenticationId?: number | undefined;
22
+ }>;
23
+ implementation: typeof runAction;
24
+ };
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runActionInfo = void 0;
4
+ const index_1 = require("./index");
5
+ const schemas_1 = require("./schemas");
6
+ // Function registry info - imports both function and schema
7
+ exports.runActionInfo = {
8
+ name: index_1.runAction.name,
9
+ inputSchema: schemas_1.RunActionSchema,
10
+ implementation: index_1.runAction,
11
+ };
@@ -0,0 +1,36 @@
1
+ import { z } from "zod";
2
+ import type { ActionExecutionResult } from "../../types/domain";
3
+ export declare const RunActionSchema: z.ZodObject<{
4
+ appKey: z.ZodString;
5
+ actionType: z.ZodEnum<["read", "write", "search", "create", "update", "delete"]>;
6
+ actionKey: z.ZodString;
7
+ inputs: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
8
+ authenticationId: z.ZodOptional<z.ZodNumber>;
9
+ }, "strip", z.ZodTypeAny, {
10
+ appKey: string;
11
+ actionType: "create" | "update" | "search" | "delete" | "read" | "write";
12
+ actionKey: string;
13
+ inputs?: Record<string, any> | undefined;
14
+ authenticationId?: number | undefined;
15
+ }, {
16
+ appKey: string;
17
+ actionType: "create" | "update" | "search" | "delete" | "read" | "write";
18
+ actionKey: string;
19
+ inputs?: Record<string, any> | undefined;
20
+ authenticationId?: number | undefined;
21
+ }>;
22
+ export type RunActionOptions = z.infer<typeof RunActionSchema> & {
23
+ /** Base URL for Zapier API */
24
+ baseUrl?: string;
25
+ /** Authentication token */
26
+ token?: string;
27
+ /** Optional pre-instantiated API client */
28
+ api?: any;
29
+ /** Enable debug logging */
30
+ debug?: boolean;
31
+ /** Custom fetch implementation */
32
+ fetch?: typeof globalThis.fetch;
33
+ };
34
+ export interface RunActionSdkFunction {
35
+ runAction: (options: RunActionOptions) => Promise<ActionExecutionResult>;
36
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RunActionSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ const properties_1 = require("../../types/properties");
6
+ // Pure Zod schema - no resolver metadata!
7
+ exports.RunActionSchema = zod_1.z
8
+ .object({
9
+ appKey: properties_1.AppKeyPropertySchema,
10
+ actionType: properties_1.ActionTypePropertySchema,
11
+ actionKey: properties_1.ActionKeyPropertySchema,
12
+ inputs: properties_1.InputsPropertySchema.optional().describe("Input parameters for the action"),
13
+ authenticationId: properties_1.AuthenticationIdPropertySchema.optional(),
14
+ })
15
+ .describe("Execute an action with the given inputs");
package/dist/index.d.ts CHANGED
@@ -1,3 +1,15 @@
1
- export * from "./types";
2
- export * from "./actions-sdk";
3
- export { createZapierSdk, ZapierSdk, ZapierSdkOptions } from "./sdk";
1
+ export * from "./types/domain";
2
+ export * from "./types/properties";
3
+ export * from "./plugins/apps";
4
+ export * from "./resolvers";
5
+ export { listAuths } from "./functions/listAuths";
6
+ export { listApps } from "./functions/listApps";
7
+ export { getApp } from "./functions/getApp";
8
+ export { listActions } from "./functions/listActions";
9
+ export { getAction } from "./functions/getAction";
10
+ export { runAction } from "./functions/runAction";
11
+ export { listFields } from "./functions/listFields";
12
+ export { generateTypes } from "./functions/generateTypes";
13
+ export { bundleCode } from "./functions/bundleCode";
14
+ export { createZapierSdk, ZapierSdkOptions } from "./sdk";
15
+ export type { ZapierSdk } from "./types/sdk";
package/dist/index.js CHANGED
@@ -14,10 +14,33 @@ 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;
18
- // Export everything from types and actions-sdk
19
- __exportStar(require("./types"), exports);
20
- __exportStar(require("./actions-sdk"), exports);
17
+ exports.createZapierSdk = exports.bundleCode = exports.generateTypes = exports.listFields = exports.runAction = exports.getAction = exports.listActions = exports.getApp = exports.listApps = exports.listAuths = void 0;
18
+ // Export everything from types and plugins
19
+ __exportStar(require("./types/domain"), exports);
20
+ __exportStar(require("./types/properties"), exports);
21
+ __exportStar(require("./plugins/apps"), exports);
22
+ // Export resolvers for CLI use
23
+ __exportStar(require("./resolvers"), exports);
24
+ // Note: SdkSchemas is now available via SDK.__registry
25
+ // Export individual functions for tree-shaking
26
+ var listAuths_1 = require("./functions/listAuths");
27
+ Object.defineProperty(exports, "listAuths", { enumerable: true, get: function () { return listAuths_1.listAuths; } });
28
+ var listApps_1 = require("./functions/listApps");
29
+ Object.defineProperty(exports, "listApps", { enumerable: true, get: function () { return listApps_1.listApps; } });
30
+ var getApp_1 = require("./functions/getApp");
31
+ Object.defineProperty(exports, "getApp", { enumerable: true, get: function () { return getApp_1.getApp; } });
32
+ var listActions_1 = require("./functions/listActions");
33
+ Object.defineProperty(exports, "listActions", { enumerable: true, get: function () { return listActions_1.listActions; } });
34
+ var getAction_1 = require("./functions/getAction");
35
+ Object.defineProperty(exports, "getAction", { enumerable: true, get: function () { return getAction_1.getAction; } });
36
+ var runAction_1 = require("./functions/runAction");
37
+ Object.defineProperty(exports, "runAction", { enumerable: true, get: function () { return runAction_1.runAction; } });
38
+ var listFields_1 = require("./functions/listFields");
39
+ Object.defineProperty(exports, "listFields", { enumerable: true, get: function () { return listFields_1.listFields; } });
40
+ var generateTypes_1 = require("./functions/generateTypes");
41
+ Object.defineProperty(exports, "generateTypes", { enumerable: true, get: function () { return generateTypes_1.generateTypes; } });
42
+ var bundleCode_1 = require("./functions/bundleCode");
43
+ Object.defineProperty(exports, "bundleCode", { enumerable: true, get: function () { return bundleCode_1.bundleCode; } });
21
44
  // Export the main combined SDK
22
45
  var sdk_1 = require("./sdk");
23
46
  Object.defineProperty(exports, "createZapierSdk", { enumerable: true, get: function () { return sdk_1.createZapierSdk; } });
@@ -0,0 +1,8 @@
1
+ import { type ApiClient } from "../../api";
2
+ import type { ActionProxy } from "./types";
3
+ export interface AppsPluginOptions {
4
+ api: ApiClient;
5
+ token?: string;
6
+ }
7
+ export declare function createAppsPlugin(options: AppsPluginOptions): ActionProxy;
8
+ export type { ActionProxy, AppsPluginSdkExtension } from "./types";
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createAppsPlugin = createAppsPlugin;
4
+ const runAction_1 = require("../../functions/runAction");
5
+ function createActionFunction(appKey, actionType, actionKey, options, pinnedAuthId) {
6
+ return async (actionOptions = {}) => {
7
+ const { api, token } = options;
8
+ const { inputs, authenticationId: providedAuthenticationId } = actionOptions;
9
+ // Use pinned auth ID first, then provided auth ID
10
+ const authenticationId = pinnedAuthId || providedAuthenticationId;
11
+ if (!authenticationId) {
12
+ throw new Error(`Authentication ID is required. Either use the factory pattern: sdk.apps.${appKey}({ authenticationId }) or provide authenticationId in the action call.`);
13
+ }
14
+ // Call runAction with the resolved parameters
15
+ return (0, runAction_1.runAction)({
16
+ appKey,
17
+ actionType: actionType,
18
+ actionKey,
19
+ inputs,
20
+ authenticationId,
21
+ api: api,
22
+ token,
23
+ });
24
+ };
25
+ }
26
+ function createActionTypeProxy(appKey, actionType, options, pinnedAuthId) {
27
+ return new Proxy({}, {
28
+ get(_, actionKey) {
29
+ if (typeof actionKey === "string") {
30
+ return createActionFunction(appKey, actionType, actionKey, options, pinnedAuthId);
31
+ }
32
+ return undefined;
33
+ },
34
+ });
35
+ }
36
+ function createPinnedAppProxy(appKey, options, pinnedAuthId) {
37
+ return new Proxy({}, {
38
+ get(_, actionType) {
39
+ if (typeof actionType === "string") {
40
+ return createActionTypeProxy(appKey, actionType, options, pinnedAuthId);
41
+ }
42
+ return undefined;
43
+ },
44
+ });
45
+ }
46
+ function createAppProxy(appKey, options) {
47
+ // Create the factory function that returns a pinned version
48
+ const appFactory = (factoryOptions) => {
49
+ return createPinnedAppProxy(appKey, options, factoryOptions.authenticationId);
50
+ };
51
+ // Add properties for direct usage (backward compatibility)
52
+ return new Proxy(appFactory, {
53
+ get(_, actionType) {
54
+ if (typeof actionType === "string") {
55
+ return createActionTypeProxy(appKey, actionType, options);
56
+ }
57
+ return undefined;
58
+ },
59
+ });
60
+ }
61
+ function createAppsProxy(options) {
62
+ // Create a proxy object that intercepts property access
63
+ const appsProxy = new Proxy({}, {
64
+ get(_, prop) {
65
+ if (typeof prop === "string") {
66
+ // First level: App names (e.g., 'slack')
67
+ return createAppProxy(prop, options);
68
+ }
69
+ return undefined;
70
+ },
71
+ });
72
+ return appsProxy;
73
+ }
74
+ // Export the plugin creation function
75
+ function createAppsPlugin(options) {
76
+ return createAppsProxy(options);
77
+ }
@@ -0,0 +1,6 @@
1
+ import type { AppsPluginOptions } from "./index";
2
+ export declare const appsPluginInfo: {
3
+ plugin: (_sdk: any, options: AppsPluginOptions) => {
4
+ apps: import("./types").ActionProxy;
5
+ };
6
+ };
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.appsPluginInfo = void 0;
4
+ const index_1 = require("./index");
5
+ // Plugin info object for registry (keeping for compatibility)
6
+ exports.appsPluginInfo = {
7
+ plugin: (_sdk, options) => {
8
+ const appsProxy = (0, index_1.createAppsPlugin)(options);
9
+ return {
10
+ apps: appsProxy,
11
+ };
12
+ },
13
+ };
@@ -0,0 +1,21 @@
1
+ import type { ActionExecutionOptions, ActionExecutionResult } from "../../types/domain";
2
+ interface AppFactoryOptions {
3
+ authenticationId: number;
4
+ }
5
+ interface ActionTypeProxy {
6
+ [action: string]: (options?: ActionExecutionOptions) => Promise<ActionExecutionResult>;
7
+ }
8
+ interface AppProxy {
9
+ [type: string]: ActionTypeProxy;
10
+ }
11
+ interface AppFactory {
12
+ (options: AppFactoryOptions): AppProxy;
13
+ }
14
+ type AppProxyWithFactory = AppFactory & AppProxy;
15
+ export interface ActionProxy {
16
+ [app: string]: AppProxyWithFactory;
17
+ }
18
+ export interface AppsPluginSdkExtension {
19
+ apps: ActionProxy;
20
+ }
21
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ import type { ZapierSdk } from "../types/sdk";
2
+ export interface ActionKeyResolver {
3
+ type: "dynamic";
4
+ depends: readonly string[];
5
+ fetch: (sdk: ZapierSdk, resolvedParams: Record<string, any>) => Promise<any[]>;
6
+ prompt: (items: any[], params: Record<string, any>) => any;
7
+ }
8
+ export declare const actionKeyResolver: ActionKeyResolver;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.actionKeyResolver = void 0;
4
+ exports.actionKeyResolver = {
5
+ type: "dynamic",
6
+ depends: ["appKey", "actionType"],
7
+ fetch: async (sdk, resolvedParams) => {
8
+ const actions = await sdk.listActions({ appKey: resolvedParams.appKey });
9
+ return actions.filter((action) => action.type === resolvedParams.actionType);
10
+ },
11
+ prompt: (actions) => ({
12
+ type: "list",
13
+ name: "actionKey",
14
+ message: "Select action:",
15
+ choices: actions.map((action) => ({
16
+ name: `${action.name || action.key} - ${action.description || "No description"}`,
17
+ value: action.key,
18
+ })),
19
+ }),
20
+ };
@@ -0,0 +1,8 @@
1
+ import type { ZapierSdk } from "../types/sdk";
2
+ export interface ActionTypeResolver {
3
+ type: "dynamic";
4
+ depends: readonly string[];
5
+ fetch: (sdk: ZapierSdk, resolvedParams: Record<string, any>) => Promise<any[]>;
6
+ prompt: (items: any[], params: Record<string, any>) => any;
7
+ }
8
+ export declare const actionTypeResolver: ActionTypeResolver;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.actionTypeResolver = void 0;
4
+ exports.actionTypeResolver = {
5
+ type: "dynamic",
6
+ depends: ["appKey"],
7
+ fetch: async (sdk, resolvedParams) => {
8
+ const actions = await sdk.listActions({ appKey: resolvedParams.appKey });
9
+ const types = [...new Set(actions.map((action) => action.type))];
10
+ return types.map((type) => ({ key: type, name: type }));
11
+ },
12
+ prompt: (types) => ({
13
+ type: "list",
14
+ name: "actionType",
15
+ message: "Select action type:",
16
+ choices: types.map((type) => ({
17
+ name: type.name,
18
+ value: type.key,
19
+ })),
20
+ }),
21
+ };
@@ -0,0 +1,6 @@
1
+ export interface AppKeyResolver {
2
+ type: "static";
3
+ inputType?: "text" | "password" | "email";
4
+ placeholder?: string;
5
+ }
6
+ export declare const appKeyResolver: AppKeyResolver;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.appKeyResolver = void 0;
4
+ exports.appKeyResolver = {
5
+ type: "static",
6
+ inputType: "text",
7
+ placeholder: "Enter app slug (e.g., 'slack', 'github')",
8
+ };
@@ -0,0 +1,8 @@
1
+ import type { ZapierSdk } from "../types/sdk";
2
+ export interface AuthenticationIdResolver {
3
+ type: "dynamic";
4
+ depends: readonly string[];
5
+ fetch: (sdk: ZapierSdk, resolvedParams: Record<string, any>) => Promise<any[]>;
6
+ prompt: (items: any[], params: Record<string, any>) => any;
7
+ }
8
+ export declare const authenticationIdResolver: AuthenticationIdResolver;