@zapier/zapier-sdk 0.0.3 → 0.1.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 (189) 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 -88
  12. package/dist/api/types.js +9 -0
  13. package/dist/functions/{bundleCode.d.ts → bundleCode/index.d.ts} +1 -8
  14. package/dist/functions/bundleCode/info.d.ts +27 -0
  15. package/dist/functions/bundleCode/info.js +11 -0
  16. package/dist/functions/bundleCode/schemas.d.ts +27 -0
  17. package/dist/functions/bundleCode/schemas.js +22 -0
  18. package/dist/functions/findFirstAuthentication/index.d.ts +12 -0
  19. package/dist/functions/findFirstAuthentication/index.js +21 -0
  20. package/dist/functions/findFirstAuthentication/info.d.ts +30 -0
  21. package/dist/functions/findFirstAuthentication/info.js +11 -0
  22. package/dist/functions/findFirstAuthentication/schemas.d.ts +42 -0
  23. package/dist/functions/findFirstAuthentication/schemas.js +25 -0
  24. package/dist/functions/findUniqueAuthentication/index.d.ts +13 -0
  25. package/dist/functions/findUniqueAuthentication/index.js +28 -0
  26. package/dist/functions/findUniqueAuthentication/info.d.ts +30 -0
  27. package/dist/functions/findUniqueAuthentication/info.js +11 -0
  28. package/dist/functions/findUniqueAuthentication/schemas.d.ts +42 -0
  29. package/dist/functions/findUniqueAuthentication/schemas.js +25 -0
  30. package/dist/functions/{generateTypes.d.ts → generateTypes/index.d.ts} +2 -7
  31. package/dist/functions/{generateTypes.js → generateTypes/index.js} +58 -24
  32. package/dist/functions/generateTypes/info.d.ts +21 -0
  33. package/dist/functions/generateTypes/info.js +11 -0
  34. package/dist/functions/generateTypes/schemas.d.ts +30 -0
  35. package/dist/functions/generateTypes/schemas.js +14 -0
  36. package/dist/functions/{getAction.d.ts → getAction/index.d.ts} +2 -6
  37. package/dist/functions/{getAction.js → getAction/index.js} +6 -5
  38. package/dist/functions/getAction/info.d.ts +18 -0
  39. package/dist/functions/getAction/info.js +11 -0
  40. package/dist/functions/getAction/schemas.d.ts +30 -0
  41. package/dist/functions/getAction/schemas.js +13 -0
  42. package/dist/functions/{getApp.d.ts → getApp/index.d.ts} +2 -4
  43. package/dist/functions/{getApp.js → getApp/index.js} +6 -10
  44. package/dist/functions/getApp/info.d.ts +12 -0
  45. package/dist/functions/getApp/info.js +11 -0
  46. package/dist/functions/getApp/schemas.d.ts +24 -0
  47. package/dist/functions/getApp/schemas.js +11 -0
  48. package/dist/functions/{listActions.d.ts → listActions/index.d.ts} +3 -6
  49. package/dist/functions/{listActions.js → listActions/index.js} +4 -3
  50. package/dist/functions/listActions/info.d.ts +15 -0
  51. package/dist/functions/listActions/info.js +11 -0
  52. package/dist/functions/listActions/schemas.d.ts +27 -0
  53. package/dist/functions/listActions/schemas.js +14 -0
  54. package/dist/functions/{listApps.d.ts → listApps/index.d.ts} +2 -6
  55. package/dist/functions/{listApps.js → listApps/index.js} +1 -1
  56. package/dist/functions/listApps/info.d.ts +18 -0
  57. package/dist/functions/listApps/info.js +11 -0
  58. package/dist/functions/listApps/schemas.d.ts +30 -0
  59. package/dist/functions/listApps/schemas.js +15 -0
  60. package/dist/functions/{listAuths.d.ts → listAuthentications/index.d.ts} +3 -9
  61. package/dist/functions/{listAuths.js → listAuthentications/index.js} +28 -12
  62. package/dist/functions/listAuthentications/info.d.ts +30 -0
  63. package/dist/functions/listAuthentications/info.js +11 -0
  64. package/dist/functions/listAuthentications/schemas.d.ts +42 -0
  65. package/dist/functions/listAuthentications/schemas.js +25 -0
  66. package/dist/functions/{listFields.d.ts → listFields/index.d.ts} +3 -9
  67. package/dist/functions/{listFields.js → listFields/index.js} +8 -10
  68. package/dist/functions/listFields/info.d.ts +24 -0
  69. package/dist/functions/listFields/info.js +11 -0
  70. package/dist/functions/listFields/schemas.d.ts +36 -0
  71. package/dist/functions/listFields/schemas.js +17 -0
  72. package/dist/functions/{runAction.d.ts → runAction/index.d.ts} +2 -8
  73. package/dist/functions/{runAction.js → runAction/index.js} +15 -14
  74. package/dist/functions/runAction/info.d.ts +24 -0
  75. package/dist/functions/runAction/info.js +11 -0
  76. package/dist/functions/runAction/schemas.d.ts +36 -0
  77. package/dist/functions/runAction/schemas.js +15 -0
  78. package/dist/index.d.ts +10 -4
  79. package/dist/index.js +17 -6
  80. package/dist/plugins/apps/index.d.ts +8 -0
  81. package/dist/plugins/apps/index.js +77 -0
  82. package/dist/plugins/apps/info.d.ts +6 -0
  83. package/dist/plugins/apps/info.js +13 -0
  84. package/dist/plugins/apps/types.d.ts +21 -0
  85. package/dist/plugins/apps/types.js +2 -0
  86. package/dist/resolvers/actionKey.d.ts +8 -0
  87. package/dist/resolvers/actionKey.js +20 -0
  88. package/dist/resolvers/actionType.d.ts +8 -0
  89. package/dist/resolvers/actionType.js +21 -0
  90. package/dist/resolvers/appKey.d.ts +6 -0
  91. package/dist/resolvers/appKey.js +8 -0
  92. package/dist/resolvers/authenticationId.d.ts +8 -0
  93. package/dist/resolvers/authenticationId.js +29 -0
  94. package/dist/resolvers/index.d.ts +39 -0
  95. package/dist/resolvers/index.js +105 -0
  96. package/dist/resolvers/inputs.d.ts +7 -0
  97. package/dist/resolvers/inputs.js +15 -0
  98. package/dist/schema-utils.d.ts +44 -0
  99. package/dist/schema-utils.js +76 -0
  100. package/dist/schemas/Action.d.ts +21 -0
  101. package/dist/schemas/Action.js +31 -0
  102. package/dist/schemas/App.d.ts +19 -0
  103. package/dist/schemas/App.js +32 -0
  104. package/dist/schemas/Auth.d.ts +27 -0
  105. package/dist/schemas/Auth.js +42 -0
  106. package/dist/schemas/Field.d.ts +15 -0
  107. package/dist/schemas/Field.js +25 -0
  108. package/dist/sdk.d.ts +3 -4
  109. package/dist/sdk.js +104 -11
  110. package/dist/types/domain.d.ts +22 -0
  111. package/dist/types/domain.js +21 -0
  112. package/dist/types/properties.d.ts +21 -0
  113. package/dist/types/properties.js +43 -0
  114. package/dist/types/sdk.d.ts +23 -0
  115. package/dist/types/sdk.js +2 -0
  116. package/package.json +4 -2
  117. package/src/api/auth.ts +28 -0
  118. package/src/api/client.ts +148 -0
  119. package/src/api/debug.ts +58 -0
  120. package/src/api/index.ts +83 -0
  121. package/src/api/polling.ts +56 -0
  122. package/src/api/types.ts +177 -0
  123. package/src/functions/{bundleCode.ts → bundleCode/index.ts} +1 -8
  124. package/src/functions/bundleCode/info.ts +9 -0
  125. package/src/functions/bundleCode/schemas.ts +30 -0
  126. package/src/functions/findFirstAuthentication/index.ts +24 -0
  127. package/src/functions/findFirstAuthentication/info.ts +9 -0
  128. package/src/functions/findFirstAuthentication/schemas.ts +60 -0
  129. package/src/functions/findUniqueAuthentication/index.ts +35 -0
  130. package/src/functions/findUniqueAuthentication/info.ts +9 -0
  131. package/src/functions/findUniqueAuthentication/schemas.ts +60 -0
  132. package/src/functions/{generateTypes.ts → generateTypes/index.ts} +70 -31
  133. package/src/functions/generateTypes/info.ts +9 -0
  134. package/src/functions/generateTypes/schemas.ts +38 -0
  135. package/src/functions/{getAction.ts → getAction/index.ts} +11 -12
  136. package/src/functions/getAction/info.ts +9 -0
  137. package/src/functions/getAction/schemas.ts +35 -0
  138. package/src/functions/{getApp.ts → getApp/index.ts} +9 -15
  139. package/src/functions/getApp/info.ts +9 -0
  140. package/src/functions/getApp/schemas.ts +31 -0
  141. package/src/functions/{listActions.ts → listActions/index.ts} +8 -10
  142. package/src/functions/listActions/info.ts +9 -0
  143. package/src/functions/listActions/schemas.ts +40 -0
  144. package/src/functions/{listApps.ts → listApps/index.ts} +3 -8
  145. package/src/functions/listApps/info.ts +9 -0
  146. package/src/functions/listApps/schemas.ts +43 -0
  147. package/src/functions/{listAuths.ts → listAuthentications/index.ts} +32 -23
  148. package/src/functions/listAuthentications/info.ts +9 -0
  149. package/src/functions/listAuthentications/schemas.ts +60 -0
  150. package/src/functions/{listFields.ts → listFields/index.ts} +11 -20
  151. package/src/functions/listFields/info.ts +9 -0
  152. package/src/functions/listFields/schemas.ts +46 -0
  153. package/src/functions/{runAction.ts → runAction/index.ts} +25 -23
  154. package/src/functions/runAction/info.ts +9 -0
  155. package/src/functions/runAction/schemas.ts +41 -0
  156. package/src/index.ts +19 -5
  157. package/src/plugins/apps/index.ts +144 -0
  158. package/src/plugins/apps/info.ts +12 -0
  159. package/src/plugins/apps/types.ts +34 -0
  160. package/src/resolvers/actionKey.ts +33 -0
  161. package/src/resolvers/actionType.ts +30 -0
  162. package/src/resolvers/appKey.ts +11 -0
  163. package/src/resolvers/authenticationId.ts +38 -0
  164. package/src/resolvers/index.ts +117 -0
  165. package/src/resolvers/inputs.ts +23 -0
  166. package/src/schema-utils.ts +154 -0
  167. package/src/schemas/Action.ts +40 -0
  168. package/src/schemas/App.ts +43 -0
  169. package/src/schemas/Auth.ts +54 -0
  170. package/src/schemas/Field.ts +34 -0
  171. package/src/sdk.ts +165 -19
  172. package/src/types/domain.ts +54 -0
  173. package/src/types/properties.ts +67 -0
  174. package/src/types/sdk.ts +46 -0
  175. package/dist/actions-sdk.d.ts +0 -47
  176. package/dist/actions-sdk.js +0 -208
  177. package/dist/api.d.ts +0 -62
  178. package/dist/api.js +0 -227
  179. package/dist/output-schemas.d.ts +0 -95
  180. package/dist/output-schemas.js +0 -138
  181. package/dist/schemas.d.ts +0 -338
  182. package/dist/schemas.js +0 -336
  183. package/dist/types.js +0 -41
  184. package/src/actions-sdk.ts +0 -356
  185. package/src/api.ts +0 -361
  186. package/src/output-schemas.ts +0 -196
  187. package/src/schemas.ts +0 -467
  188. package/src/types.ts +0 -257
  189. /package/dist/functions/{bundleCode.js → bundleCode/index.js} +0 -0
@@ -0,0 +1,144 @@
1
+ import {
2
+ ActionExecutionOptions,
3
+ ActionExecutionResult,
4
+ } from "../../types/domain";
5
+ import { type ApiClient } from "../../api";
6
+ import { runAction } from "../../functions/runAction";
7
+ import type { ActionProxy } from "./types";
8
+
9
+ export interface AppsPluginOptions {
10
+ api: ApiClient;
11
+ token?: string;
12
+ }
13
+
14
+ interface AppFactoryOptions {
15
+ authenticationId: number;
16
+ }
17
+
18
+ function createActionFunction(
19
+ appKey: string,
20
+ actionType: string,
21
+ actionKey: string,
22
+ options: AppsPluginOptions,
23
+ pinnedAuthId?: number,
24
+ ) {
25
+ return async (
26
+ actionOptions: ActionExecutionOptions = {},
27
+ ): Promise<ActionExecutionResult> => {
28
+ const { api, token } = options;
29
+ const { inputs, authenticationId: providedAuthenticationId } =
30
+ actionOptions;
31
+
32
+ // Use pinned auth ID first, then provided auth ID
33
+ const authenticationId = pinnedAuthId || providedAuthenticationId;
34
+
35
+ if (!authenticationId) {
36
+ throw new Error(
37
+ `Authentication ID is required. Either use the factory pattern: sdk.apps.${appKey}({ authenticationId }) or provide authenticationId in the action call.`,
38
+ );
39
+ }
40
+
41
+ // Call runAction with the resolved parameters
42
+ return runAction({
43
+ appKey,
44
+ actionType: actionType as any,
45
+ actionKey,
46
+ inputs,
47
+ authenticationId,
48
+ api: api,
49
+ token,
50
+ });
51
+ };
52
+ }
53
+
54
+ function createActionTypeProxy(
55
+ appKey: string,
56
+ actionType: string,
57
+ options: AppsPluginOptions,
58
+ pinnedAuthId?: number,
59
+ ) {
60
+ return new Proxy(
61
+ {},
62
+ {
63
+ get(_, actionKey) {
64
+ if (typeof actionKey === "string") {
65
+ return createActionFunction(
66
+ appKey,
67
+ actionType,
68
+ actionKey,
69
+ options,
70
+ pinnedAuthId,
71
+ );
72
+ }
73
+ return undefined;
74
+ },
75
+ },
76
+ );
77
+ }
78
+
79
+ function createPinnedAppProxy(
80
+ appKey: string,
81
+ options: AppsPluginOptions,
82
+ pinnedAuthId: number,
83
+ ) {
84
+ return new Proxy(
85
+ {},
86
+ {
87
+ get(_, actionType) {
88
+ if (typeof actionType === "string") {
89
+ return createActionTypeProxy(
90
+ appKey,
91
+ actionType,
92
+ options,
93
+ pinnedAuthId,
94
+ );
95
+ }
96
+ return undefined;
97
+ },
98
+ },
99
+ );
100
+ }
101
+
102
+ function createAppProxy(appKey: string, options: AppsPluginOptions) {
103
+ // Create the factory function that returns a pinned version
104
+ const appFactory = (factoryOptions: AppFactoryOptions) => {
105
+ return createPinnedAppProxy(
106
+ appKey,
107
+ options,
108
+ factoryOptions.authenticationId,
109
+ );
110
+ };
111
+
112
+ // Add properties for direct usage (backward compatibility)
113
+ return new Proxy(appFactory, {
114
+ get(_, actionType) {
115
+ if (typeof actionType === "string") {
116
+ return createActionTypeProxy(appKey, actionType, options);
117
+ }
118
+ return undefined;
119
+ },
120
+ });
121
+ }
122
+
123
+ function createAppsProxy(options: AppsPluginOptions): ActionProxy {
124
+ // Create a proxy object that intercepts property access
125
+ const appsProxy = new Proxy({} as ActionProxy, {
126
+ get(_, prop) {
127
+ if (typeof prop === "string") {
128
+ // First level: App names (e.g., 'slack')
129
+ return createAppProxy(prop, options);
130
+ }
131
+ return undefined;
132
+ },
133
+ });
134
+
135
+ return appsProxy;
136
+ }
137
+
138
+ // Export the plugin creation function
139
+ export function createAppsPlugin(options: AppsPluginOptions): ActionProxy {
140
+ return createAppsProxy(options);
141
+ }
142
+
143
+ // Re-export types
144
+ export type { ActionProxy, AppsPluginSdkExtension } from "./types";
@@ -0,0 +1,12 @@
1
+ import { createAppsPlugin } from "./index";
2
+ import type { AppsPluginOptions } from "./index";
3
+
4
+ // Plugin info object for registry (keeping for compatibility)
5
+ export const appsPluginInfo = {
6
+ plugin: (_sdk: any, options: AppsPluginOptions) => {
7
+ const appsProxy = createAppsPlugin(options);
8
+ return {
9
+ apps: appsProxy,
10
+ };
11
+ },
12
+ };
@@ -0,0 +1,34 @@
1
+ import type {
2
+ ActionExecutionOptions,
3
+ ActionExecutionResult,
4
+ } from "../../types/domain";
5
+
6
+ interface AppFactoryOptions {
7
+ authenticationId: number;
8
+ }
9
+
10
+ interface ActionTypeProxy {
11
+ [action: string]: (
12
+ options?: ActionExecutionOptions,
13
+ ) => Promise<ActionExecutionResult>;
14
+ }
15
+
16
+ interface AppProxy {
17
+ [type: string]: ActionTypeProxy;
18
+ }
19
+
20
+ interface AppFactory {
21
+ (options: AppFactoryOptions): AppProxy;
22
+ }
23
+
24
+ // An app can be both a factory function and have properties for direct access
25
+ type AppProxyWithFactory = AppFactory & AppProxy;
26
+
27
+ export interface ActionProxy {
28
+ [app: string]: AppProxyWithFactory;
29
+ }
30
+
31
+ // Plugin interface - ready to be mixed into main SDK interface
32
+ export interface AppsPluginSdkExtension {
33
+ apps: ActionProxy;
34
+ }
@@ -0,0 +1,33 @@
1
+ import type { ZapierSdk } from "../types/sdk";
2
+
3
+ export interface ActionKeyResolver {
4
+ type: "dynamic";
5
+ depends: readonly string[];
6
+ fetch: (
7
+ sdk: ZapierSdk,
8
+ resolvedParams: Record<string, any>,
9
+ ) => Promise<any[]>;
10
+ prompt: (items: any[], params: Record<string, any>) => any;
11
+ }
12
+
13
+ export const actionKeyResolver: ActionKeyResolver = {
14
+ type: "dynamic",
15
+ depends: ["appKey", "actionType"] as const,
16
+ fetch: async (sdk: ZapierSdk, resolvedParams: Record<string, any>) => {
17
+ const actions = await sdk.listActions({ appKey: resolvedParams.appKey });
18
+ return actions.filter(
19
+ (action: any) => action.type === resolvedParams.actionType,
20
+ );
21
+ },
22
+ prompt: (actions: any[]) => ({
23
+ type: "list",
24
+ name: "actionKey",
25
+ message: "Select action:",
26
+ choices: actions.map((action) => ({
27
+ name: `${action.name || action.key} - ${
28
+ action.description || "No description"
29
+ }`,
30
+ value: action.key,
31
+ })),
32
+ }),
33
+ };
@@ -0,0 +1,30 @@
1
+ import type { ZapierSdk } from "../types/sdk";
2
+
3
+ export interface ActionTypeResolver {
4
+ type: "dynamic";
5
+ depends: readonly string[];
6
+ fetch: (
7
+ sdk: ZapierSdk,
8
+ resolvedParams: Record<string, any>,
9
+ ) => Promise<any[]>;
10
+ prompt: (items: any[], params: Record<string, any>) => any;
11
+ }
12
+
13
+ export const actionTypeResolver: ActionTypeResolver = {
14
+ type: "dynamic",
15
+ depends: ["appKey"] as const,
16
+ fetch: async (sdk: ZapierSdk, resolvedParams: Record<string, any>) => {
17
+ const actions = await sdk.listActions({ appKey: resolvedParams.appKey });
18
+ const types = [...new Set(actions.map((action: any) => action.type))];
19
+ return types.map((type) => ({ key: type, name: type }));
20
+ },
21
+ prompt: (types: any[]) => ({
22
+ type: "list",
23
+ name: "actionType",
24
+ message: "Select action type:",
25
+ choices: types.map((type) => ({
26
+ name: type.name,
27
+ value: type.key,
28
+ })),
29
+ }),
30
+ };
@@ -0,0 +1,11 @@
1
+ export interface AppKeyResolver {
2
+ type: "static";
3
+ inputType?: "text" | "password" | "email";
4
+ placeholder?: string;
5
+ }
6
+
7
+ export const appKeyResolver: AppKeyResolver = {
8
+ type: "static",
9
+ inputType: "text",
10
+ placeholder: "Enter app slug (e.g., 'slack', 'github')",
11
+ };
@@ -0,0 +1,38 @@
1
+ import type { ZapierSdk } from "../types/sdk";
2
+
3
+ export interface AuthenticationIdResolver {
4
+ type: "dynamic";
5
+ depends: readonly string[];
6
+ fetch: (
7
+ sdk: ZapierSdk,
8
+ resolvedParams: Record<string, any>,
9
+ ) => Promise<any[]>;
10
+ prompt: (items: any[], params: Record<string, any>) => any;
11
+ }
12
+
13
+ export const authenticationIdResolver: AuthenticationIdResolver = {
14
+ type: "dynamic",
15
+ depends: ["appKey"] as const,
16
+ fetch: async (sdk: ZapierSdk, resolvedParams: Record<string, any>) => {
17
+ // Get auths for the specific app (owned auths will be prioritized automatically)
18
+ return await sdk.listAuthentications({
19
+ appKey: resolvedParams.appKey,
20
+ limit: 1000,
21
+ });
22
+ },
23
+ prompt: (auths: any[], params: Record<string, any>) => ({
24
+ type: "list",
25
+ name: "authenticationId",
26
+ message: `Select authentication for ${params.appKey}:`,
27
+ choices: [
28
+ ...auths.map((auth) => ({
29
+ name: `${auth.title || auth.label || "Authentication"} (ID: ${auth.id})`,
30
+ value: auth.id,
31
+ })),
32
+ {
33
+ name: "↗ Skip authentication (may fail)",
34
+ value: null,
35
+ },
36
+ ],
37
+ }),
38
+ };
@@ -0,0 +1,117 @@
1
+ import { appKeyResolver } from "./appKey";
2
+ import { actionTypeResolver } from "./actionType";
3
+ import { actionKeyResolver } from "./actionKey";
4
+ import { authenticationIdResolver } from "./authenticationId";
5
+ import { inputsResolver } from "./inputs";
6
+
7
+ // Centralized resolver registry
8
+ export const resolverRegistry = {
9
+ appKey: appKeyResolver,
10
+ actionType: actionTypeResolver,
11
+ actionKey: actionKeyResolver,
12
+ authenticationId: authenticationIdResolver,
13
+ inputs: inputsResolver,
14
+ } as const;
15
+
16
+ // Type definitions
17
+ export type ResolverName = keyof typeof resolverRegistry;
18
+ export type ResolverType = (typeof resolverRegistry)[ResolverName];
19
+
20
+ // Utility functions for working with resolvers
21
+
22
+ /**
23
+ * Get a resolver by name
24
+ */
25
+ export function getResolver(name: string): ResolverType | undefined {
26
+ return resolverRegistry[name as ResolverName];
27
+ }
28
+
29
+ /**
30
+ * Get all resolvers for a list of missing parameters
31
+ */
32
+ export function getResolversForMissingParams(
33
+ missingParams: string[],
34
+ ): Record<string, ResolverType> {
35
+ const resolvers: Record<string, ResolverType> = {};
36
+
37
+ for (const param of missingParams) {
38
+ const resolver = resolverRegistry[param as ResolverName];
39
+ if (resolver) {
40
+ resolvers[param] = resolver;
41
+ }
42
+ }
43
+
44
+ return resolvers;
45
+ }
46
+
47
+ /**
48
+ * Check if a parameter has a resolver
49
+ */
50
+ export function hasResolver(paramName: string): boolean {
51
+ return paramName in resolverRegistry;
52
+ }
53
+
54
+ /**
55
+ * Get all parameter names that have resolvers
56
+ */
57
+ export function getResolvableParams(): string[] {
58
+ return Object.keys(resolverRegistry);
59
+ }
60
+
61
+ /**
62
+ * Resolve dependency chain for a parameter
63
+ * Returns parameters in the order they need to be resolved
64
+ */
65
+ export function getResolutionOrder(
66
+ paramName: string,
67
+ resolved: Set<string> = new Set(),
68
+ ): string[] {
69
+ const resolver = getResolver(paramName);
70
+ if (!resolver || resolver.type === "static") {
71
+ return [paramName];
72
+ }
73
+
74
+ const order: string[] = [];
75
+
76
+ if ("depends" in resolver && resolver.depends) {
77
+ for (const dependency of resolver.depends) {
78
+ if (!resolved.has(dependency)) {
79
+ order.push(...getResolutionOrder(dependency, resolved));
80
+ resolved.add(dependency);
81
+ }
82
+ }
83
+ }
84
+
85
+ if (!resolved.has(paramName)) {
86
+ order.push(paramName);
87
+ resolved.add(paramName);
88
+ }
89
+
90
+ return order;
91
+ }
92
+
93
+ /**
94
+ * Get resolution order for multiple parameters
95
+ */
96
+ export function getResolutionOrderForParams(paramNames: string[]): string[] {
97
+ const resolved = new Set<string>();
98
+ const order: string[] = [];
99
+
100
+ for (const paramName of paramNames) {
101
+ const paramOrder = getResolutionOrder(paramName, resolved);
102
+ for (const param of paramOrder) {
103
+ if (!order.includes(param)) {
104
+ order.push(param);
105
+ }
106
+ }
107
+ }
108
+
109
+ return order;
110
+ }
111
+
112
+ // Re-export individual resolvers for direct access if needed
113
+ export { appKeyResolver } from "./appKey";
114
+ export { actionTypeResolver } from "./actionType";
115
+ export { actionKeyResolver } from "./actionKey";
116
+ export { authenticationIdResolver } from "./authenticationId";
117
+ export { inputsResolver } from "./inputs";
@@ -0,0 +1,23 @@
1
+ import type { ZapierSdk } from "../types/sdk";
2
+
3
+ export interface InputsResolver {
4
+ type: "fields";
5
+ depends: readonly string[];
6
+ fetch: (
7
+ sdk: ZapierSdk,
8
+ resolvedParams: Record<string, any>,
9
+ ) => Promise<any[]>;
10
+ }
11
+
12
+ export const inputsResolver: InputsResolver = {
13
+ type: "fields",
14
+ depends: ["appKey", "actionKey", "actionType", "authenticationId"] as const,
15
+ fetch: async (sdk: ZapierSdk, resolvedParams: Record<string, any>) => {
16
+ return await sdk.listFields({
17
+ appKey: resolvedParams.appKey,
18
+ actionKey: resolvedParams.actionKey,
19
+ actionType: resolvedParams.actionType,
20
+ authenticationId: resolvedParams.authenticationId,
21
+ });
22
+ },
23
+ };
@@ -0,0 +1,154 @@
1
+ import { z } from "zod";
2
+
3
+ // ============================================================================
4
+ // Format Metadata Types
5
+ // ============================================================================
6
+
7
+ export interface FormattedItem {
8
+ title: string;
9
+ subtitle?: string;
10
+ details: Array<{
11
+ text: string;
12
+ style: "normal" | "dim" | "accent" | "warning" | "success";
13
+ }>;
14
+ }
15
+
16
+ export interface FormatMetadata {
17
+ format: (item: any) => FormattedItem;
18
+ }
19
+
20
+ // Helper function to add format metadata to schemas
21
+ export function withFormatter<T extends z.ZodType>(
22
+ schema: T,
23
+ formatMeta: FormatMetadata,
24
+ ): T {
25
+ // Store format metadata on the schema definition
26
+ (schema._def as any).formatMeta = formatMeta;
27
+ return schema;
28
+ }
29
+
30
+ // Helper function to get format metadata from a schema
31
+ export function getFormatMetadata(
32
+ schema: z.ZodType,
33
+ ): FormatMetadata | undefined {
34
+ return (schema._def as any).formatMeta;
35
+ }
36
+
37
+ // Helper function to link input schemas to output schemas
38
+ export function withOutputSchema<T extends z.ZodType>(
39
+ inputSchema: T,
40
+ outputSchema: z.ZodType,
41
+ ): T {
42
+ // Store output schema reference on the input schema
43
+ (inputSchema._def as any).outputSchema = outputSchema;
44
+ return inputSchema;
45
+ }
46
+
47
+ // Helper function to get output schema from an input schema
48
+ export function getOutputSchema(inputSchema: z.ZodType): z.ZodType | undefined {
49
+ return (inputSchema._def as any).outputSchema;
50
+ }
51
+
52
+ // ============================================================================
53
+ // Resolution Metadata Types
54
+ // ============================================================================
55
+
56
+ export interface StaticResolver {
57
+ type: "static";
58
+ inputType?: "text" | "password" | "email";
59
+ placeholder?: string;
60
+ }
61
+
62
+ export interface DynamicResolver {
63
+ type: "dynamic";
64
+ fetch: (sdk: any, resolvedParams: any) => Promise<any[]>; // Function to fetch data using SDK
65
+ prompt: (items: any[], params: any) => any;
66
+ depends?: string[]; // Parameters this resolver depends on
67
+ }
68
+
69
+ export interface FieldsResolver {
70
+ type: "fields";
71
+ fetch: (sdk: any, resolvedParams: any) => Promise<any[]>; // Function to fetch fields using SDK
72
+ depends?: string[]; // Parameters this resolver depends on
73
+ }
74
+
75
+ export type ResolverMetadata =
76
+ | StaticResolver
77
+ | DynamicResolver
78
+ | FieldsResolver;
79
+
80
+ // Wrapper interface for resolver metadata to allow future extensibility
81
+ export interface ResolverConfig {
82
+ resolver: ResolverMetadata;
83
+ // Future metadata types can be added here:
84
+ // validation?: ValidationMetadata;
85
+ // display?: DisplayMetadata;
86
+ }
87
+
88
+ // Helper function to add resolver metadata to schemas
89
+ export function withResolver<T extends z.ZodType>(
90
+ schema: T,
91
+ config: ResolverConfig,
92
+ ): T {
93
+ // Store resolver metadata on the schema definition
94
+ (schema._def as any).resolverMeta = config;
95
+ return schema;
96
+ }
97
+
98
+ // ============================================================================
99
+ // Schema Description Utilities
100
+ // ============================================================================
101
+
102
+ export function getSchemaDescription(schema: z.ZodSchema): string | undefined {
103
+ return schema.description;
104
+ }
105
+
106
+ export function getFieldDescriptions(
107
+ schema: z.ZodObject<any>,
108
+ ): Record<string, string> {
109
+ const descriptions: Record<string, string> = {};
110
+ const shape = schema.shape;
111
+
112
+ for (const [key, fieldSchema] of Object.entries(shape)) {
113
+ if (fieldSchema instanceof z.ZodType && fieldSchema.description) {
114
+ descriptions[key] = fieldSchema.description;
115
+ }
116
+ }
117
+
118
+ return descriptions;
119
+ }
120
+
121
+ // ============================================================================
122
+ // Positional Parameter Metadata
123
+ // ============================================================================
124
+
125
+ export interface PositionalMetadata {
126
+ positional: true;
127
+ }
128
+
129
+ // Helper function to mark a parameter as positional for CLI
130
+ export function withPositional<T extends z.ZodType>(schema: T): T {
131
+ // Store positional metadata on the schema definition
132
+ (schema._def as any).positionalMeta = { positional: true };
133
+ return schema;
134
+ }
135
+
136
+ // Helper function to check if a parameter should be positional
137
+ export function isPositional(schema: z.ZodType): boolean {
138
+ // Check the current schema first
139
+ if ((schema._def as any).positionalMeta?.positional) {
140
+ return true;
141
+ }
142
+
143
+ // If this is a ZodOptional, check the inner type
144
+ if (schema instanceof z.ZodOptional) {
145
+ return isPositional(schema._def.innerType);
146
+ }
147
+
148
+ // If this is a ZodDefault, check the inner type
149
+ if (schema instanceof z.ZodDefault) {
150
+ return isPositional(schema._def.innerType);
151
+ }
152
+
153
+ return false;
154
+ }
@@ -0,0 +1,40 @@
1
+ import { z } from "zod";
2
+ import { withFormatter } from "../schema-utils";
3
+
4
+ // ============================================================================
5
+ // Action Schemas
6
+ // ============================================================================
7
+
8
+ export const ActionItemSchema = withFormatter(
9
+ z.object({
10
+ key: z.string(),
11
+ name: z.string().optional(),
12
+ type: z.string(),
13
+ appKey: z.string().optional(),
14
+ description: z.string().optional(),
15
+ }),
16
+ {
17
+ format: (item) => {
18
+ const details = [];
19
+ details.push({ text: `Type: ${item.type}`, style: "accent" as const });
20
+ if (item.appKey) {
21
+ details.push({ text: `App: ${item.appKey}`, style: "normal" as const });
22
+ }
23
+ if (item.description) {
24
+ details.push({ text: item.description, style: "dim" as const });
25
+ }
26
+
27
+ return {
28
+ title: item.name || item.key,
29
+ subtitle: `(${item.key})`,
30
+ details,
31
+ };
32
+ },
33
+ },
34
+ );
35
+
36
+ // ============================================================================
37
+ // Type Exports
38
+ // ============================================================================
39
+
40
+ export type ActionItem = z.infer<typeof ActionItemSchema>;
@@ -0,0 +1,43 @@
1
+ import { z } from "zod";
2
+ import { withFormatter } from "../schema-utils";
3
+
4
+ export { FormattedItem, FormatMetadata } from "../schema-utils";
5
+
6
+ // ============================================================================
7
+ // App Schemas
8
+ // ============================================================================
9
+
10
+ export const AppItemSchema = withFormatter(
11
+ z.object({
12
+ key: z.string(),
13
+ name: z.string().optional(),
14
+ description: z.string().optional(),
15
+ category: z.string().optional(),
16
+ }),
17
+ {
18
+ format: (item) => {
19
+ const details = [];
20
+ if (item.description) {
21
+ details.push({ text: item.description, style: "dim" as const });
22
+ }
23
+ if (item.category) {
24
+ details.push({
25
+ text: `Category: ${item.category}`,
26
+ style: "accent" as const,
27
+ });
28
+ }
29
+
30
+ return {
31
+ title: item.name || item.key,
32
+ subtitle: `(${item.key})`,
33
+ details,
34
+ };
35
+ },
36
+ },
37
+ );
38
+
39
+ // ============================================================================
40
+ // Type Exports
41
+ // ============================================================================
42
+
43
+ export type AppItem = z.infer<typeof AppItemSchema>;