@zapier/zapier-sdk 0.9.0 → 0.11.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 (187) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +7 -7
  3. package/dist/api/client.d.ts.map +1 -1
  4. package/dist/api/client.js +14 -0
  5. package/dist/api/debug.d.ts +1 -0
  6. package/dist/api/debug.d.ts.map +1 -1
  7. package/dist/api/debug.js +42 -1
  8. package/dist/api/debug.test.d.ts +2 -0
  9. package/dist/api/debug.test.d.ts.map +1 -0
  10. package/dist/api/debug.test.js +59 -0
  11. package/dist/api/schemas.d.ts +451 -251
  12. package/dist/api/schemas.d.ts.map +1 -1
  13. package/dist/api/schemas.js +51 -29
  14. package/dist/index.cjs +968 -582
  15. package/dist/index.d.mts +2537 -2229
  16. package/dist/index.d.ts +2 -3
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +2 -3
  19. package/dist/index.mjs +966 -576
  20. package/dist/plugins/findFirstAuthentication/index.d.ts +1 -1
  21. package/dist/plugins/findFirstAuthentication/index.d.ts.map +1 -1
  22. package/dist/plugins/findFirstAuthentication/index.js +9 -1
  23. package/dist/plugins/findFirstAuthentication/index.test.js +3 -4
  24. package/dist/plugins/findFirstAuthentication/schemas.d.ts +5 -3
  25. package/dist/plugins/findFirstAuthentication/schemas.d.ts.map +1 -1
  26. package/dist/plugins/findUniqueAuthentication/index.d.ts.map +1 -1
  27. package/dist/plugins/findUniqueAuthentication/index.js +4 -0
  28. package/dist/plugins/findUniqueAuthentication/schemas.d.ts +5 -3
  29. package/dist/plugins/findUniqueAuthentication/schemas.d.ts.map +1 -1
  30. package/dist/plugins/getAction/index.d.ts.map +1 -1
  31. package/dist/plugins/getAction/index.js +10 -0
  32. package/dist/plugins/getAction/schemas.d.ts +5 -3
  33. package/dist/plugins/getAction/schemas.d.ts.map +1 -1
  34. package/dist/plugins/getApp/index.d.ts.map +1 -1
  35. package/dist/plugins/getApp/index.js +8 -0
  36. package/dist/plugins/getApp/index.test.js +2 -2
  37. package/dist/plugins/getApp/schemas.d.ts +3 -1
  38. package/dist/plugins/getApp/schemas.d.ts.map +1 -1
  39. package/dist/plugins/getApp/schemas.js +2 -4
  40. package/dist/plugins/getAuthentication/index.d.ts.map +1 -1
  41. package/dist/plugins/getAuthentication/index.js +8 -0
  42. package/dist/plugins/getProfile/index.d.ts.map +1 -1
  43. package/dist/plugins/getProfile/index.js +4 -0
  44. package/dist/plugins/getProfile/schemas.d.ts.map +1 -1
  45. package/dist/plugins/getProfile/schemas.js +4 -3
  46. package/dist/plugins/listActions/index.d.ts.map +1 -1
  47. package/dist/plugins/listActions/index.js +9 -0
  48. package/dist/plugins/listActions/schemas.d.ts +5 -3
  49. package/dist/plugins/listActions/schemas.d.ts.map +1 -1
  50. package/dist/plugins/listActions/schemas.js +2 -4
  51. package/dist/plugins/listApps/index.d.ts.map +1 -1
  52. package/dist/plugins/listApps/index.js +4 -0
  53. package/dist/plugins/listApps/index.test.js +1 -1
  54. package/dist/plugins/listApps/schemas.d.ts.map +1 -1
  55. package/dist/plugins/listApps/schemas.js +3 -9
  56. package/dist/plugins/listAuthentications/index.d.ts.map +1 -1
  57. package/dist/plugins/listAuthentications/index.js +8 -0
  58. package/dist/plugins/listAuthentications/schemas.d.ts +5 -3
  59. package/dist/plugins/listAuthentications/schemas.d.ts.map +1 -1
  60. package/dist/plugins/listInputFieldChoices/index.d.ts.map +1 -1
  61. package/dist/plugins/listInputFieldChoices/index.js +14 -2
  62. package/dist/plugins/listInputFieldChoices/schemas.d.ts +5 -3
  63. package/dist/plugins/listInputFieldChoices/schemas.d.ts.map +1 -1
  64. package/dist/plugins/listInputFieldChoices/schemas.js +10 -19
  65. package/dist/plugins/listInputFields/index.d.ts +4 -4
  66. package/dist/plugins/listInputFields/index.d.ts.map +1 -1
  67. package/dist/plugins/listInputFields/index.js +71 -5
  68. package/dist/plugins/listInputFields/index.test.js +5 -9
  69. package/dist/plugins/listInputFields/schemas.d.ts +8 -6
  70. package/dist/plugins/listInputFields/schemas.d.ts.map +1 -1
  71. package/dist/plugins/registry/index.d.ts.map +1 -1
  72. package/dist/plugins/registry/index.js +8 -2
  73. package/dist/plugins/request/index.d.ts.map +1 -1
  74. package/dist/plugins/request/index.js +1 -0
  75. package/dist/plugins/runAction/index.d.ts.map +1 -1
  76. package/dist/plugins/runAction/index.js +12 -0
  77. package/dist/plugins/runAction/schemas.d.ts +5 -3
  78. package/dist/plugins/runAction/schemas.d.ts.map +1 -1
  79. package/dist/resolvers/actionKey.d.ts +13 -7
  80. package/dist/resolvers/actionKey.d.ts.map +1 -1
  81. package/dist/resolvers/actionType.d.ts +8 -7
  82. package/dist/resolvers/actionType.d.ts.map +1 -1
  83. package/dist/resolvers/appKey.d.ts +2 -6
  84. package/dist/resolvers/appKey.d.ts.map +1 -1
  85. package/dist/resolvers/authenticationId.d.ts +7 -7
  86. package/dist/resolvers/authenticationId.d.ts.map +1 -1
  87. package/dist/resolvers/authenticationId.js +16 -7
  88. package/dist/resolvers/index.d.ts +3 -35
  89. package/dist/resolvers/index.d.ts.map +1 -1
  90. package/dist/resolvers/index.js +4 -87
  91. package/dist/resolvers/inputFieldKey.d.ts +11 -0
  92. package/dist/resolvers/inputFieldKey.d.ts.map +1 -0
  93. package/dist/resolvers/inputFieldKey.js +47 -0
  94. package/dist/resolvers/inputs.d.ts +13 -4
  95. package/dist/resolvers/inputs.d.ts.map +1 -1
  96. package/dist/resolvers/inputs.js +36 -0
  97. package/dist/schemas/Action.d.ts +8 -8
  98. package/dist/schemas/Action.d.ts.map +1 -1
  99. package/dist/schemas/Action.js +8 -3
  100. package/dist/schemas/App.d.ts +183 -11
  101. package/dist/schemas/App.d.ts.map +1 -1
  102. package/dist/schemas/App.js +7 -9
  103. package/dist/schemas/Auth.d.ts +12 -12
  104. package/dist/schemas/Auth.js +1 -1
  105. package/dist/schemas/Field.d.ts +112 -97
  106. package/dist/schemas/Field.d.ts.map +1 -1
  107. package/dist/schemas/Field.js +63 -52
  108. package/dist/schemas/Run.d.ts +3 -0
  109. package/dist/schemas/Run.d.ts.map +1 -0
  110. package/dist/schemas/Run.js +31 -0
  111. package/dist/schemas/UserProfile.d.ts +11 -11
  112. package/dist/schemas/UserProfile.d.ts.map +1 -1
  113. package/dist/schemas/UserProfile.js +21 -7
  114. package/dist/sdk.d.ts +11 -4
  115. package/dist/sdk.d.ts.map +1 -1
  116. package/dist/types/domain.d.ts +17 -1
  117. package/dist/types/domain.d.ts.map +1 -1
  118. package/dist/types/plugin.d.ts +5 -0
  119. package/dist/types/plugin.d.ts.map +1 -1
  120. package/dist/types/properties.d.ts +3 -1
  121. package/dist/types/properties.d.ts.map +1 -1
  122. package/dist/types/sdk.d.ts +5 -0
  123. package/dist/types/sdk.d.ts.map +1 -1
  124. package/dist/utils/domain-utils.d.ts +1 -16
  125. package/dist/utils/domain-utils.d.ts.map +1 -1
  126. package/dist/utils/domain-utils.js +7 -51
  127. package/dist/utils/schema-utils.d.ts +44 -21
  128. package/dist/utils/schema-utils.d.ts.map +1 -1
  129. package/dist/utils/schema-utils.js +17 -11
  130. package/dist/utils/string-utils.d.ts +12 -0
  131. package/dist/utils/string-utils.d.ts.map +1 -0
  132. package/dist/utils/string-utils.js +23 -0
  133. package/dist/utils/string-utils.test.d.ts +2 -0
  134. package/dist/utils/string-utils.test.d.ts.map +1 -0
  135. package/dist/utils/string-utils.test.js +36 -0
  136. package/package.json +1 -1
  137. package/src/api/client.ts +12 -0
  138. package/src/api/debug.test.ts +76 -0
  139. package/src/api/debug.ts +46 -2
  140. package/src/api/schemas.ts +51 -29
  141. package/src/index.ts +4 -5
  142. package/src/plugins/findFirstAuthentication/index.test.ts +8 -5
  143. package/src/plugins/findFirstAuthentication/index.ts +14 -2
  144. package/src/plugins/findUniqueAuthentication/index.ts +4 -0
  145. package/src/plugins/getAction/index.ts +14 -0
  146. package/src/plugins/getApp/index.test.ts +2 -2
  147. package/src/plugins/getApp/index.ts +8 -0
  148. package/src/plugins/getApp/schemas.ts +7 -12
  149. package/src/plugins/getAuthentication/index.ts +8 -0
  150. package/src/plugins/getProfile/index.ts +4 -0
  151. package/src/plugins/getProfile/schemas.ts +4 -6
  152. package/src/plugins/listActions/index.ts +9 -0
  153. package/src/plugins/listActions/schemas.ts +20 -25
  154. package/src/plugins/listApps/index.test.ts +1 -1
  155. package/src/plugins/listApps/index.ts +4 -0
  156. package/src/plugins/listApps/schemas.ts +17 -26
  157. package/src/plugins/listAuthentications/index.ts +8 -0
  158. package/src/plugins/listInputFieldChoices/index.ts +21 -1
  159. package/src/plugins/listInputFieldChoices/schemas.ts +61 -76
  160. package/src/plugins/listInputFields/index.test.ts +5 -9
  161. package/src/plugins/listInputFields/index.ts +89 -11
  162. package/src/plugins/listInputFields/schemas.ts +6 -3
  163. package/src/plugins/registry/index.ts +8 -2
  164. package/src/plugins/request/index.ts +1 -0
  165. package/src/plugins/runAction/index.ts +18 -0
  166. package/src/resolvers/actionKey.ts +15 -13
  167. package/src/resolvers/actionType.ts +10 -12
  168. package/src/resolvers/appKey.ts +2 -6
  169. package/src/resolvers/authenticationId.ts +25 -19
  170. package/src/resolvers/index.ts +7 -113
  171. package/src/resolvers/inputFieldKey.ts +70 -0
  172. package/src/resolvers/inputs.ts +51 -7
  173. package/src/schemas/Action.ts +8 -3
  174. package/src/schemas/App.ts +7 -9
  175. package/src/schemas/Auth.ts +1 -1
  176. package/src/schemas/Field.ts +97 -60
  177. package/src/schemas/Run.ts +40 -0
  178. package/src/schemas/UserProfile.ts +24 -7
  179. package/src/sdk.ts +17 -7
  180. package/src/types/domain.ts +24 -1
  181. package/src/types/plugin.ts +5 -0
  182. package/src/types/sdk.ts +5 -0
  183. package/src/utils/domain-utils.ts +9 -67
  184. package/src/utils/schema-utils.ts +96 -44
  185. package/src/utils/string-utils.test.ts +45 -0
  186. package/src/utils/string-utils.ts +26 -0
  187. package/tsconfig.tsbuildinfo +1 -1
@@ -1,19 +1,17 @@
1
- import type { ZapierSdk } from "../types/sdk";
1
+ import type { DynamicResolver } from "../utils/schema-utils";
2
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;
3
+ interface ActionTypeItem {
4
+ key: string;
5
+ name: string;
11
6
  }
12
7
 
13
- export const actionTypeResolver: ActionTypeResolver = {
8
+ export const actionTypeResolver: DynamicResolver<
9
+ ActionTypeItem,
10
+ { appKey: string }
11
+ > = {
14
12
  type: "dynamic",
15
13
  depends: ["appKey"] as const,
16
- fetch: async (sdk: ZapierSdk, resolvedParams: Record<string, any>) => {
14
+ fetch: async (sdk, resolvedParams) => {
17
15
  const actionsResponse = await sdk.listActions({
18
16
  appKey: resolvedParams.appKey,
19
17
  });
@@ -23,7 +21,7 @@ export const actionTypeResolver: ActionTypeResolver = {
23
21
  ];
24
22
  return types.map((type) => ({ key: type, name: type }));
25
23
  },
26
- prompt: (types: any[]) => ({
24
+ prompt: (types) => ({
27
25
  type: "list",
28
26
  name: "actionType",
29
27
  message: "Select action type:",
@@ -1,10 +1,6 @@
1
- export interface AppKeyResolver {
2
- type: "static";
3
- inputType?: "text" | "password" | "email";
4
- placeholder?: string;
5
- }
1
+ import type { StaticResolver } from "../utils/schema-utils";
6
2
 
7
- export const appKeyResolver: AppKeyResolver = {
3
+ export const appKeyResolver: StaticResolver = {
8
4
  type: "static",
9
5
  inputType: "text",
10
6
  placeholder: "Enter app key (e.g., 'SlackCLIAPI' or slug like 'github')",
@@ -1,38 +1,38 @@
1
- import type { ZapierSdk } from "../types/sdk";
1
+ import type { DynamicResolver } from "../utils/schema-utils";
2
+ import type { AuthItem } from "../schemas/Auth";
2
3
 
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
- }
4
+ type AuthenticationIdResolver = DynamicResolver<AuthItem, { appKey?: string }>;
12
5
 
13
6
  export const authenticationIdResolver: AuthenticationIdResolver = {
14
7
  type: "dynamic",
15
8
  depends: ["appKey"] as const,
16
- fetch: async (sdk: ZapierSdk, resolvedParams: Record<string, any>) => {
17
- const myAuths = await sdk.listAuthentications({
18
- appKey: resolvedParams.appKey,
9
+ fetch: async (sdk, resolvedParams) => {
10
+ const listOptions: { maxItems: number; appKey?: string } = {
19
11
  maxItems: 1000,
12
+ };
13
+
14
+ if (resolvedParams.appKey) {
15
+ listOptions.appKey = resolvedParams.appKey;
16
+ }
17
+
18
+ const myAuths = await sdk.listAuthentications({
19
+ ...listOptions,
20
20
  owner: "me",
21
21
  });
22
- const allAuths = await sdk.listAuthentications({
23
- appKey: resolvedParams.appKey,
24
- maxItems: 1000,
25
- });
22
+ const allAuths = await sdk.listAuthentications(listOptions);
23
+
26
24
  // Filter out myAuths from allAuths
27
25
  const otherAuths = allAuths.data.filter(
28
26
  (auth) => !myAuths.data.some((myAuth) => myAuth.id === auth.id),
29
27
  );
30
28
  return [...myAuths.data, ...otherAuths];
31
29
  },
32
- prompt: (auths: any[], params: Record<string, any>) => ({
30
+ prompt: (auths, params) => ({
33
31
  type: "list",
34
32
  name: "authenticationId",
35
- message: `Select authentication for ${params.appKey}:`,
33
+ message: params.appKey
34
+ ? `Select authentication for ${params.appKey}:`
35
+ : "Select authentication:",
36
36
  choices: [
37
37
  ...auths.map((auth) => ({
38
38
  name: `${auth.title || auth.label || "Authentication"} (ID: ${auth.id})`,
@@ -45,3 +45,9 @@ export const authenticationIdResolver: AuthenticationIdResolver = {
45
45
  ],
46
46
  }),
47
47
  };
48
+
49
+ // Generic version without appKey dependency
50
+ export const authenticationIdGenericResolver: AuthenticationIdResolver = {
51
+ ...authenticationIdResolver,
52
+ depends: [] as const,
53
+ };
@@ -1,117 +1,11 @@
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
1
+ // Re-export individual resolvers for plugin use
113
2
  export { appKeyResolver } from "./appKey";
114
3
  export { actionTypeResolver } from "./actionType";
115
4
  export { actionKeyResolver } from "./actionKey";
116
- export { authenticationIdResolver } from "./authenticationId";
5
+ export {
6
+ authenticationIdResolver,
7
+ authenticationIdGenericResolver,
8
+ } from "./authenticationId";
117
9
  export { inputsResolver } from "./inputs";
10
+ export { inputFieldKeyResolver } from "./inputFieldKey";
11
+ export { inputsAllOptionalResolver } from "./inputs";
@@ -0,0 +1,70 @@
1
+ import type { DynamicResolver } from "../utils/schema-utils";
2
+ import type { InputFieldItem } from "../schemas/Field";
3
+ import type { ActionTypeProperty } from "../types/properties";
4
+ import type {
5
+ RootFieldItem,
6
+ InfoFieldItem,
7
+ FieldsetItem,
8
+ } from "../types/domain";
9
+
10
+ /**
11
+ * Helper function to flatten fieldsets into a flat array of input fields.
12
+ * Used to extract all input fields from nested fieldset structure for field selection.
13
+ */
14
+ function flattenRootFieldset(rootFieldset: RootFieldItem[]): InputFieldItem[] {
15
+ const result: InputFieldItem[] = [];
16
+
17
+ function processItem(item: InputFieldItem | InfoFieldItem | FieldsetItem) {
18
+ if (item.type === "input_field") {
19
+ result.push(item);
20
+ } else if (item.type === "fieldset") {
21
+ // Recursively process fields in the fieldset
22
+ for (const field of item.fields) {
23
+ processItem(field);
24
+ }
25
+ }
26
+ // Skip info fields as they're not input fields
27
+ }
28
+
29
+ for (const item of rootFieldset) {
30
+ processItem(item);
31
+ }
32
+
33
+ return result;
34
+ }
35
+
36
+ export const inputFieldKeyResolver: DynamicResolver<
37
+ InputFieldItem,
38
+ {
39
+ appKey: string;
40
+ actionKey: string;
41
+ actionType: ActionTypeProperty;
42
+ authenticationId: number;
43
+ inputs?: Record<string, unknown>;
44
+ }
45
+ > = {
46
+ type: "dynamic",
47
+ depends: ["appKey", "actionKey", "actionType", "authenticationId"] as const,
48
+ fetch: async (sdk, resolvedParams) => {
49
+ const fieldsResponse = await sdk.listInputFields({
50
+ appKey: resolvedParams.appKey,
51
+ actionKey: resolvedParams.actionKey,
52
+ actionType: resolvedParams.actionType,
53
+ authenticationId: resolvedParams.authenticationId,
54
+ inputs: resolvedParams.inputs, // Pass along currently resolved inputs
55
+ });
56
+ // Flatten the fieldset structure for field selection
57
+ return flattenRootFieldset(fieldsResponse.data);
58
+ },
59
+ prompt: (fields) => ({
60
+ type: "list",
61
+ name: "inputFieldKey",
62
+ message: "Select input field:",
63
+ choices: fields.map((field) => ({
64
+ name: `${field.title || field.key} - ${
65
+ field.value_type || "No type"
66
+ } ${field.is_required ? "(required)" : "(optional)"}`,
67
+ value: field.key,
68
+ })),
69
+ }),
70
+ };
@@ -1,18 +1,46 @@
1
- import type { ZapierSdk } from "../types/sdk";
1
+ import type { ActionTypeProperty } from "../types/properties";
2
+ import type { RootFieldItem } from "../types/domain";
2
3
 
3
- export interface InputsResolver {
4
+ // Helper function to recursively make all input fields optional while preserving structure
5
+ function makeFieldsOptional(fields: RootFieldItem[]): RootFieldItem[] {
6
+ return fields.map((field) => {
7
+ if (field.type === "input_field") {
8
+ return {
9
+ ...field,
10
+ is_required: false,
11
+ };
12
+ } else if (field.type === "fieldset") {
13
+ return {
14
+ ...field,
15
+ fields: makeFieldsOptional(field.fields),
16
+ };
17
+ } else {
18
+ // Info fields remain unchanged
19
+ return field;
20
+ }
21
+ });
22
+ }
23
+
24
+ // Custom resolver type for fieldsets - returns the nested structure
25
+ type InputsResolver = {
4
26
  type: "fields";
5
27
  depends: readonly string[];
6
28
  fetch: (
7
- sdk: ZapierSdk,
8
- resolvedParams: Record<string, any>,
9
- ) => Promise<any[]>;
10
- }
29
+ sdk: any,
30
+ resolvedParams: {
31
+ appKey: string;
32
+ actionKey: string;
33
+ actionType: ActionTypeProperty;
34
+ authenticationId: number;
35
+ inputs?: Record<string, unknown>;
36
+ },
37
+ ) => Promise<RootFieldItem[]>;
38
+ };
11
39
 
12
40
  export const inputsResolver: InputsResolver = {
13
41
  type: "fields",
14
42
  depends: ["appKey", "actionKey", "actionType", "authenticationId"] as const,
15
- fetch: async (sdk: ZapierSdk, resolvedParams: Record<string, any>) => {
43
+ fetch: async (sdk, resolvedParams) => {
16
44
  const fieldsResponse = await sdk.listInputFields({
17
45
  appKey: resolvedParams.appKey,
18
46
  actionKey: resolvedParams.actionKey,
@@ -23,3 +51,19 @@ export const inputsResolver: InputsResolver = {
23
51
  return fieldsResponse.data;
24
52
  },
25
53
  };
54
+
55
+ export const inputsAllOptionalResolver: InputsResolver = {
56
+ type: "fields",
57
+ depends: ["appKey", "actionKey", "actionType", "authenticationId"] as const,
58
+ fetch: async (sdk, resolvedParams) => {
59
+ const fieldsResponse = await sdk.listInputFields({
60
+ appKey: resolvedParams.appKey,
61
+ actionKey: resolvedParams.actionKey,
62
+ actionType: resolvedParams.actionType,
63
+ authenticationId: resolvedParams.authenticationId,
64
+ inputs: resolvedParams.inputs, // Pass along currently resolved inputs
65
+ });
66
+ // Return nested structure with all fields marked as optional.
67
+ return makeFieldsOptional(fieldsResponse.data);
68
+ },
69
+ };
@@ -27,12 +27,17 @@ export const ActionItemSchema = withFormatter(
27
27
  });
28
28
  }
29
29
  if (item.description) {
30
- details.push({ text: item.description, style: "dim" as const });
30
+ details.push({
31
+ text: item.description,
32
+ style: "dim" as const,
33
+ });
31
34
  }
32
35
 
33
36
  return {
34
- title: item.title || item.name || item.key,
35
- subtitle: `(${item.key})`,
37
+ title: item.title || item.key,
38
+ id: item.id,
39
+ key: item.key,
40
+ description: item.description,
36
41
  details,
37
42
  };
38
43
  },
@@ -1,27 +1,25 @@
1
1
  import { z } from "zod";
2
2
  import { withFormatter } from "../utils/schema-utils";
3
+ import { ImplementationMetaSchema } from "../api/schemas";
3
4
 
4
5
  export { FormattedItem, FormatMetadata } from "../utils/schema-utils";
5
6
 
6
7
  // ============================================================================
7
- // App Item Schema (extends API schema with computed fields and formatting)
8
+ // App Item Schema (extends ImplementationMetaSchema with transformed fields)
8
9
  // ============================================================================
9
10
 
10
11
  export const AppItemSchema = withFormatter(
11
- z.object({
12
- // Essential properties only
12
+ ImplementationMetaSchema.omit({ name: true, id: true }).extend({
13
13
  title: z.string(), // Mapped from name
14
- key: z.string(), // Mapped from selected_api
15
- current_implementation_id: z.string(), // From id, keeps the full version
16
- version: z.string().optional(), // Extracted from implementation ID
17
- description: z.string().optional(),
18
- slug: z.string().optional(),
14
+ key: z.string(), // Extracted from id (base part without version)
15
+ implementation_id: z.string(), // Mapped from id (full versioned ID)
19
16
  }),
20
17
  {
21
18
  format: (item) => {
22
19
  return {
23
20
  title: item.title,
24
- subtitle: `(${item.key})`,
21
+ key: item.key,
22
+ description: item.description,
25
23
  details: [],
26
24
  };
27
25
  },
@@ -42,7 +42,7 @@ export const AuthenticationItemSchema = withFormatter(
42
42
 
43
43
  return {
44
44
  title: item.title || `Authentication ${item.id}`,
45
- subtitle: `(ID: ${item.id})`,
45
+ id: item.id?.toString(),
46
46
  details,
47
47
  };
48
48
  },
@@ -1,28 +1,31 @@
1
1
  import { z } from "zod";
2
2
  import { withFormatter } from "../utils/schema-utils";
3
- import { NeedSchema } from "../api/schemas";
3
+
4
+ // ============================================================================
5
+ // Base Field Schema
6
+ // ============================================================================
7
+
8
+ export const BaseFieldItemSchema = z.object({
9
+ type: z.string(), // "input_field", "info_field", or "fieldset"
10
+ key: z.string(), // From need.key
11
+ });
4
12
 
5
13
  // ============================================================================
6
14
  // Input Field Item Schema (extends API Need schema with computed fields and formatting)
7
15
  // ============================================================================
8
16
 
9
17
  export const InputFieldItemSchema = withFormatter(
10
- NeedSchema.omit({
11
- depends_on: true,
12
- placeholder: true,
13
- required: true,
14
- format: true,
15
- }).extend({
16
- id: z.string(), // Mapped from 'key'
18
+ BaseFieldItemSchema.extend({
19
+ type: z.literal("input_field"),
17
20
  default_value: z.string(), // Mapped from 'default' with fallback to ""
18
- depends_on: z.array(z.string()), // Override: mapped from 'depends_on' with fallback to []
21
+ depends_on: z.array(z.string()), // Mapped from 'depends_on' with fallback to []
19
22
  description: z.string(), // Mapped from 'help_text' with fallback to ""
20
23
  invalidates_input_fields: z.boolean(), // Mapped from 'alters_custom_fields' with fallback to false
21
- is_required: z.boolean(), // Override: mapped from 'required' with fallback to false
22
- placeholder: z.string(), // Override: mapped from 'placeholder' with fallback to ""
24
+ is_required: z.boolean(), // Mapped from 'required' with fallback to false
25
+ placeholder: z.string(), // Mapped from 'placeholder' with fallback to ""
23
26
  title: z.string(), // Mapped from 'label' with fallback to ""
24
27
  value_type: z.string(), // Computed from InputFieldType enum
25
- format: z.string().optional(), // Override: computed from InputFieldFormat enum (optional)
28
+ format: z.string().optional(), // Computed from InputFieldFormat enum (optional)
26
29
  items: z.object({ type: z.string() }).optional(), // Computed from ItemsType enum (optional, only for arrays)
27
30
  }),
28
31
  {
@@ -31,8 +34,8 @@ export const InputFieldItemSchema = withFormatter(
31
34
 
32
35
  // Type and required status
33
36
  const typeInfo = [
34
- item.type && `Type: ${item.type}`,
35
- `Required: ${item.required ? "Yes" : "No"}`,
37
+ item.value_type && `Type: ${item.value_type}`,
38
+ `Required: ${item.is_required ? "Yes" : "No"}`,
36
39
  ]
37
40
  .filter(Boolean)
38
41
  .join(" | ");
@@ -40,15 +43,18 @@ export const InputFieldItemSchema = withFormatter(
40
43
  details.push({ text: typeInfo, style: "dim" as const });
41
44
  }
42
45
 
43
- // Help text
44
- if (item.helpText) {
45
- details.push({ text: item.helpText, style: "normal" as const });
46
+ // Description
47
+ if (item.description) {
48
+ details.push({
49
+ text: item.description,
50
+ style: "normal" as const,
51
+ });
46
52
  }
47
53
 
48
54
  // Default value
49
- if (item.default !== undefined) {
55
+ if (item.default_value) {
50
56
  details.push({
51
- text: `Default: ${item.default}`,
57
+ text: `Default: ${item.default_value}`,
52
58
  style: "accent" as const,
53
59
  });
54
60
  }
@@ -61,25 +67,10 @@ export const InputFieldItemSchema = withFormatter(
61
67
  });
62
68
  }
63
69
 
64
- // Choices
65
- if (item.choices && item.choices.length > 0) {
66
- const choiceText =
67
- item.choices.length <= 3
68
- ? `Choices: ${item.choices.map((c: { label?: string; value: string | number }) => c.label || c.value).join(", ")}`
69
- : `Choices: ${item.choices
70
- .slice(0, 3)
71
- .map(
72
- (c: { label?: string; value: string | number }) =>
73
- c.label || c.value,
74
- )
75
- .join(", ")} (+${item.choices.length - 3} more)`;
76
- details.push({ text: choiceText, style: "accent" as const });
77
- }
78
-
79
70
  // Dependencies
80
- if (item.dependsOn && item.dependsOn.length > 0) {
71
+ if (item.depends_on && item.depends_on.length > 0) {
81
72
  details.push({
82
- text: `Depends on: ${item.dependsOn.join(", ")}`,
73
+ text: `Depends on: ${item.depends_on.join(", ")}`,
83
74
  style: "warning" as const,
84
75
  });
85
76
  }
@@ -89,44 +80,90 @@ export const InputFieldItemSchema = withFormatter(
89
80
  details.push({ text: `Format: ${item.format}`, style: "dim" as const });
90
81
  }
91
82
 
92
- // Input format
93
- if (item.inputFormat && item.inputFormat.length > 0) {
83
+ // Items type for arrays
84
+ if (item.items) {
94
85
  details.push({
95
- text: `Input formats: ${item.inputFormat.join(", ")}`,
86
+ text: `Items type: ${item.items.type}`,
96
87
  style: "dim" as const,
97
88
  });
98
89
  }
99
90
 
100
- // Special field flags
101
- const flags = [];
102
- if (item.computed) flags.push("computed");
103
- if (item.customField) flags.push("custom");
104
- if (flags.length > 0) {
105
- details.push({
106
- text: `Flags: ${flags.join(", ")}`,
107
- style: "success" as const,
108
- });
109
- }
110
-
111
- // Backwards compatibility: show description if no helpText
112
- if (item.description && !item.helpText) {
113
- details.push({ text: item.description, style: "normal" as const });
114
- }
115
-
116
91
  return {
117
- title: item.label || item.name || item.key,
118
- subtitle: `(${item.key})`,
92
+ title: item.title || item.key,
93
+ key: item.key,
94
+ description: item.description,
119
95
  details,
120
96
  };
121
97
  },
122
98
  },
123
99
  );
124
100
 
101
+ // ============================================================================
102
+ // Info Field Item Schema (for help text and copy fields)
103
+ // ============================================================================
104
+
105
+ export const InfoFieldItemSchema = withFormatter(
106
+ BaseFieldItemSchema.extend({
107
+ type: z.literal("info_field"),
108
+ description: z.string(), // From need.help_text
109
+ title: z.string().optional(), // Optional title
110
+ }),
111
+ {
112
+ format: (item) => ({
113
+ title: item.title || "Info",
114
+ key: item.key,
115
+ description: item.description,
116
+ details: [{ text: item.description, style: "normal" as const }],
117
+ }),
118
+ },
119
+ );
120
+
121
+ // ============================================================================
122
+ // Fieldset Schema (for grouping fields)
123
+ // ============================================================================
124
+
125
+ // Forward reference for recursive type
126
+ type FieldsetItemType =
127
+ | z.infer<typeof InputFieldItemSchema>
128
+ | z.infer<typeof InfoFieldItemSchema>
129
+ | FieldsetItem;
130
+
131
+ export interface FieldsetItem {
132
+ type: "fieldset";
133
+ key: string;
134
+ title: string;
135
+ fields: FieldsetItemType[];
136
+ }
137
+
138
+ export const FieldsetItemSchema: z.ZodType<FieldsetItem> =
139
+ BaseFieldItemSchema.extend({
140
+ type: z.literal("fieldset"),
141
+ title: z.string(),
142
+ fields: z.lazy(() =>
143
+ z.array(
144
+ z.union([
145
+ InputFieldItemSchema,
146
+ InfoFieldItemSchema,
147
+ FieldsetItemSchema,
148
+ ]),
149
+ ),
150
+ ),
151
+ });
152
+
153
+ // ============================================================================
154
+ // Root Field Item Schema (union of all possible field types)
155
+ // ============================================================================
156
+
157
+ export const RootFieldItemSchema = z.union([
158
+ InputFieldItemSchema,
159
+ InfoFieldItemSchema,
160
+ FieldsetItemSchema,
161
+ ]);
162
+
125
163
  // ============================================================================
126
164
  // Type Exports
127
165
  // ============================================================================
128
166
 
129
167
  export type InputFieldItem = z.infer<typeof InputFieldItemSchema>;
130
-
131
- // Legacy alias for backward compatibility
132
- export type FieldItem = InputFieldItem;
168
+ export type InfoFieldItem = z.infer<typeof InfoFieldItemSchema>;
169
+ export type RootFieldItem = z.infer<typeof RootFieldItemSchema>;