@zapier/zapier-sdk 0.8.3 → 0.10.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 (222) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +17 -40
  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 +1149 -751
  15. package/dist/index.d.mts +2359 -2161
  16. package/dist/index.d.ts +3 -5
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +2 -4
  19. package/dist/index.mjs +1143 -743
  20. package/dist/plugins/apps/index.d.ts +4 -0
  21. package/dist/plugins/apps/index.d.ts.map +1 -1
  22. package/dist/plugins/findFirstAuthentication/index.d.ts +1 -1
  23. package/dist/plugins/findFirstAuthentication/index.d.ts.map +1 -1
  24. package/dist/plugins/findFirstAuthentication/index.js +9 -1
  25. package/dist/plugins/findFirstAuthentication/index.test.js +3 -4
  26. package/dist/plugins/findFirstAuthentication/schemas.d.ts +5 -3
  27. package/dist/plugins/findFirstAuthentication/schemas.d.ts.map +1 -1
  28. package/dist/plugins/findUniqueAuthentication/index.d.ts.map +1 -1
  29. package/dist/plugins/findUniqueAuthentication/index.js +4 -0
  30. package/dist/plugins/findUniqueAuthentication/schemas.d.ts +5 -3
  31. package/dist/plugins/findUniqueAuthentication/schemas.d.ts.map +1 -1
  32. package/dist/plugins/getAction/index.d.ts.map +1 -1
  33. package/dist/plugins/getAction/index.js +10 -0
  34. package/dist/plugins/getAction/schemas.d.ts +5 -3
  35. package/dist/plugins/getAction/schemas.d.ts.map +1 -1
  36. package/dist/plugins/getApp/index.d.ts +2 -7
  37. package/dist/plugins/getApp/index.d.ts.map +1 -1
  38. package/dist/plugins/getApp/index.js +17 -9
  39. package/dist/plugins/getApp/index.test.js +3 -3
  40. package/dist/plugins/getApp/schemas.d.ts +3 -1
  41. package/dist/plugins/getApp/schemas.d.ts.map +1 -1
  42. package/dist/plugins/getApp/schemas.js +2 -4
  43. package/dist/plugins/getAuthentication/index.d.ts.map +1 -1
  44. package/dist/plugins/getAuthentication/index.js +8 -0
  45. package/dist/plugins/getAuthentication/index.test.js +1 -1
  46. package/dist/plugins/getProfile/index.d.ts.map +1 -1
  47. package/dist/plugins/getProfile/index.js +4 -0
  48. package/dist/plugins/getProfile/schemas.d.ts.map +1 -1
  49. package/dist/plugins/getProfile/schemas.js +4 -3
  50. package/dist/plugins/listActions/index.d.ts +2 -4
  51. package/dist/plugins/listActions/index.d.ts.map +1 -1
  52. package/dist/plugins/listActions/index.js +10 -1
  53. package/dist/plugins/listActions/index.test.js +4 -4
  54. package/dist/plugins/listActions/schemas.d.ts +5 -3
  55. package/dist/plugins/listActions/schemas.d.ts.map +1 -1
  56. package/dist/plugins/listActions/schemas.js +2 -4
  57. package/dist/plugins/listApps/index.d.ts +4 -7
  58. package/dist/plugins/listApps/index.d.ts.map +1 -1
  59. package/dist/plugins/listApps/index.js +37 -17
  60. package/dist/plugins/listApps/index.test.js +23 -3
  61. package/dist/plugins/listApps/schemas.d.ts.map +1 -1
  62. package/dist/plugins/listApps/schemas.js +3 -9
  63. package/dist/plugins/listAuthentications/index.d.ts +2 -4
  64. package/dist/plugins/listAuthentications/index.d.ts.map +1 -1
  65. package/dist/plugins/listAuthentications/index.js +12 -0
  66. package/dist/plugins/listAuthentications/index.test.js +39 -13
  67. package/dist/plugins/listAuthentications/schemas.d.ts +8 -3
  68. package/dist/plugins/listAuthentications/schemas.d.ts.map +1 -1
  69. package/dist/plugins/listAuthentications/schemas.js +4 -0
  70. package/dist/plugins/listInputFieldChoices/index.d.ts.map +1 -1
  71. package/dist/plugins/listInputFieldChoices/index.js +14 -2
  72. package/dist/plugins/listInputFieldChoices/schemas.d.ts +5 -3
  73. package/dist/plugins/listInputFieldChoices/schemas.d.ts.map +1 -1
  74. package/dist/plugins/listInputFieldChoices/schemas.js +10 -19
  75. package/dist/plugins/listInputFields/index.d.ts.map +1 -1
  76. package/dist/plugins/listInputFields/index.js +14 -2
  77. package/dist/plugins/listInputFields/index.test.js +5 -9
  78. package/dist/plugins/listInputFields/schemas.d.ts +5 -3
  79. package/dist/plugins/listInputFields/schemas.d.ts.map +1 -1
  80. package/dist/plugins/manifest/index.d.ts +25 -9
  81. package/dist/plugins/manifest/index.d.ts.map +1 -1
  82. package/dist/plugins/manifest/index.js +239 -67
  83. package/dist/plugins/manifest/index.test.js +426 -171
  84. package/dist/plugins/manifest/schemas.d.ts +5 -1
  85. package/dist/plugins/manifest/schemas.d.ts.map +1 -1
  86. package/dist/plugins/manifest/schemas.js +1 -0
  87. package/dist/plugins/registry/index.d.ts.map +1 -1
  88. package/dist/plugins/registry/index.js +8 -2
  89. package/dist/plugins/request/index.d.ts.map +1 -1
  90. package/dist/plugins/request/index.js +1 -0
  91. package/dist/plugins/runAction/index.d.ts.map +1 -1
  92. package/dist/plugins/runAction/index.js +12 -0
  93. package/dist/plugins/runAction/schemas.d.ts +5 -3
  94. package/dist/plugins/runAction/schemas.d.ts.map +1 -1
  95. package/dist/resolvers/actionKey.d.ts +13 -7
  96. package/dist/resolvers/actionKey.d.ts.map +1 -1
  97. package/dist/resolvers/actionType.d.ts +8 -7
  98. package/dist/resolvers/actionType.d.ts.map +1 -1
  99. package/dist/resolvers/appKey.d.ts +2 -6
  100. package/dist/resolvers/appKey.d.ts.map +1 -1
  101. package/dist/resolvers/authenticationId.d.ts +7 -7
  102. package/dist/resolvers/authenticationId.d.ts.map +1 -1
  103. package/dist/resolvers/authenticationId.js +16 -7
  104. package/dist/resolvers/index.d.ts +3 -35
  105. package/dist/resolvers/index.d.ts.map +1 -1
  106. package/dist/resolvers/index.js +4 -87
  107. package/dist/resolvers/inputFieldKey.d.ts +11 -0
  108. package/dist/resolvers/inputFieldKey.d.ts.map +1 -0
  109. package/dist/resolvers/inputFieldKey.js +23 -0
  110. package/dist/resolvers/inputs.d.ts +11 -6
  111. package/dist/resolvers/inputs.d.ts.map +1 -1
  112. package/dist/resolvers/inputs.js +17 -0
  113. package/dist/schemas/Action.d.ts +8 -8
  114. package/dist/schemas/Action.d.ts.map +1 -1
  115. package/dist/schemas/Action.js +8 -3
  116. package/dist/schemas/App.d.ts +183 -11
  117. package/dist/schemas/App.d.ts.map +1 -1
  118. package/dist/schemas/App.js +7 -9
  119. package/dist/schemas/Auth.d.ts +12 -12
  120. package/dist/schemas/Auth.js +1 -1
  121. package/dist/schemas/Field.d.ts +5 -98
  122. package/dist/schemas/Field.d.ts.map +1 -1
  123. package/dist/schemas/Field.js +24 -52
  124. package/dist/schemas/Run.d.ts +3 -0
  125. package/dist/schemas/Run.d.ts.map +1 -0
  126. package/dist/schemas/Run.js +31 -0
  127. package/dist/schemas/UserProfile.d.ts +11 -11
  128. package/dist/schemas/UserProfile.d.ts.map +1 -1
  129. package/dist/schemas/UserProfile.js +21 -7
  130. package/dist/sdk.d.ts +15 -14
  131. package/dist/sdk.d.ts.map +1 -1
  132. package/dist/sdk.js +1 -4
  133. package/dist/types/plugin.d.ts +6 -0
  134. package/dist/types/plugin.d.ts.map +1 -1
  135. package/dist/types/properties.d.ts +3 -1
  136. package/dist/types/properties.d.ts.map +1 -1
  137. package/dist/types/sdk.d.ts +11 -3
  138. package/dist/types/sdk.d.ts.map +1 -1
  139. package/dist/utils/domain-utils.d.ts +17 -16
  140. package/dist/utils/domain-utils.d.ts.map +1 -1
  141. package/dist/utils/domain-utils.js +53 -78
  142. package/dist/utils/domain-utils.test.js +157 -3
  143. package/dist/utils/file-utils.d.ts +4 -0
  144. package/dist/utils/file-utils.d.ts.map +1 -0
  145. package/dist/utils/file-utils.js +74 -0
  146. package/dist/utils/file-utils.test.d.ts +2 -0
  147. package/dist/utils/file-utils.test.d.ts.map +1 -0
  148. package/dist/utils/file-utils.test.js +51 -0
  149. package/dist/utils/schema-utils.d.ts +44 -21
  150. package/dist/utils/schema-utils.d.ts.map +1 -1
  151. package/dist/utils/schema-utils.js +17 -11
  152. package/package.json +1 -1
  153. package/src/api/client.ts +12 -0
  154. package/src/api/debug.test.ts +76 -0
  155. package/src/api/debug.ts +46 -2
  156. package/src/api/schemas.ts +51 -29
  157. package/src/index.ts +5 -6
  158. package/src/plugins/apps/index.ts +9 -2
  159. package/src/plugins/findFirstAuthentication/index.test.ts +8 -5
  160. package/src/plugins/findFirstAuthentication/index.ts +14 -2
  161. package/src/plugins/findUniqueAuthentication/index.ts +4 -0
  162. package/src/plugins/getAction/index.ts +14 -0
  163. package/src/plugins/getApp/index.test.ts +3 -3
  164. package/src/plugins/getApp/index.ts +20 -14
  165. package/src/plugins/getApp/schemas.ts +7 -12
  166. package/src/plugins/getAuthentication/index.test.ts +1 -1
  167. package/src/plugins/getAuthentication/index.ts +8 -0
  168. package/src/plugins/getProfile/index.ts +4 -0
  169. package/src/plugins/getProfile/schemas.ts +4 -6
  170. package/src/plugins/listActions/index.test.ts +8 -7
  171. package/src/plugins/listActions/index.ts +12 -3
  172. package/src/plugins/listActions/schemas.ts +20 -25
  173. package/src/plugins/listApps/index.test.ts +24 -3
  174. package/src/plugins/listApps/index.ts +50 -25
  175. package/src/plugins/listApps/schemas.ts +17 -26
  176. package/src/plugins/listAuthentications/index.test.ts +52 -15
  177. package/src/plugins/listAuthentications/index.ts +15 -2
  178. package/src/plugins/listAuthentications/schemas.ts +4 -0
  179. package/src/plugins/listInputFieldChoices/index.ts +21 -1
  180. package/src/plugins/listInputFieldChoices/schemas.ts +61 -76
  181. package/src/plugins/listInputFields/index.test.ts +5 -9
  182. package/src/plugins/listInputFields/index.ts +20 -2
  183. package/src/plugins/manifest/index.test.ts +503 -197
  184. package/src/plugins/manifest/index.ts +338 -82
  185. package/src/plugins/manifest/schemas.ts +9 -2
  186. package/src/plugins/registry/index.ts +8 -2
  187. package/src/plugins/request/index.ts +1 -0
  188. package/src/plugins/runAction/index.ts +18 -0
  189. package/src/resolvers/actionKey.ts +15 -13
  190. package/src/resolvers/actionType.ts +10 -12
  191. package/src/resolvers/appKey.ts +2 -6
  192. package/src/resolvers/authenticationId.ts +25 -19
  193. package/src/resolvers/index.ts +7 -113
  194. package/src/resolvers/inputFieldKey.ts +38 -0
  195. package/src/resolvers/inputs.ts +28 -10
  196. package/src/schemas/Action.ts +8 -3
  197. package/src/schemas/App.ts +7 -9
  198. package/src/schemas/Auth.ts +1 -1
  199. package/src/schemas/Field.ts +24 -57
  200. package/src/schemas/Run.ts +40 -0
  201. package/src/schemas/UserProfile.ts +24 -7
  202. package/src/sdk.ts +18 -12
  203. package/src/types/plugin.ts +8 -0
  204. package/src/types/sdk.ts +31 -21
  205. package/src/utils/domain-utils.test.ts +196 -2
  206. package/src/utils/domain-utils.ts +77 -102
  207. package/src/utils/file-utils.test.ts +73 -0
  208. package/src/utils/file-utils.ts +94 -0
  209. package/src/utils/schema-utils.ts +96 -44
  210. package/tsconfig.tsbuildinfo +1 -1
  211. package/dist/plugins/lockVersion/index.d.ts +0 -24
  212. package/dist/plugins/lockVersion/index.d.ts.map +0 -1
  213. package/dist/plugins/lockVersion/index.js +0 -72
  214. package/dist/plugins/lockVersion/index.test.d.ts +0 -2
  215. package/dist/plugins/lockVersion/index.test.d.ts.map +0 -1
  216. package/dist/plugins/lockVersion/index.test.js +0 -129
  217. package/dist/plugins/lockVersion/schemas.d.ts +0 -10
  218. package/dist/plugins/lockVersion/schemas.d.ts.map +0 -1
  219. package/dist/plugins/lockVersion/schemas.js +0 -6
  220. package/src/plugins/lockVersion/index.test.ts +0 -176
  221. package/src/plugins/lockVersion/index.ts +0 -112
  222. package/src/plugins/lockVersion/schemas.ts +0 -9
@@ -0,0 +1,94 @@
1
+ // In-memory filesystem fallback for browser environments
2
+ const inMemoryFiles: { [path: string]: string } = {};
3
+
4
+ // Lazy-loaded modules
5
+ let fsPromises: any = null;
6
+ let pathModule: any = null;
7
+
8
+ async function loadFsPromises() {
9
+ if (fsPromises) return fsPromises;
10
+
11
+ try {
12
+ fsPromises = await import("fs/promises");
13
+ return fsPromises;
14
+ } catch {
15
+ return null;
16
+ }
17
+ }
18
+
19
+ async function loadPathModule() {
20
+ if (pathModule) return pathModule;
21
+
22
+ try {
23
+ pathModule = await import("path");
24
+ return pathModule;
25
+ } catch {
26
+ return null;
27
+ }
28
+ }
29
+
30
+ export async function resolve(
31
+ path: string,
32
+ basePath: string = "/",
33
+ ): Promise<string> {
34
+ const pathModule = await loadPathModule();
35
+
36
+ if (pathModule) {
37
+ return pathModule.resolve(path);
38
+ }
39
+
40
+ // Simple fallback path resolution assuming root "/" location
41
+ if (path.startsWith("/")) {
42
+ return path;
43
+ }
44
+
45
+ if (path.startsWith("./")) {
46
+ // Remove ./ prefix and join to base
47
+ const cleanPath = path.slice(2);
48
+ return basePath.endsWith("/")
49
+ ? basePath + cleanPath
50
+ : basePath + "/" + cleanPath;
51
+ }
52
+
53
+ if (path.startsWith("../")) {
54
+ // Remove ../ prefix since we're already at root
55
+ const cleanPath = path.replace(/^(\.\.\/)+/, "");
56
+ return basePath.endsWith("/")
57
+ ? basePath + cleanPath
58
+ : basePath + "/" + cleanPath;
59
+ }
60
+
61
+ // No slash prefix, join to base
62
+ return basePath.endsWith("/") ? basePath + path : basePath + "/" + path;
63
+ }
64
+
65
+ export async function writeFile(
66
+ filePath: string,
67
+ content: string,
68
+ ): Promise<void> {
69
+ const fs = await loadFsPromises();
70
+
71
+ if (fs) {
72
+ await fs.writeFile(filePath, content, "utf8");
73
+ return;
74
+ }
75
+
76
+ // Fallback to in-memory filesystem
77
+ inMemoryFiles[filePath] = content;
78
+ }
79
+
80
+ export async function readFile(filePath: string): Promise<string> {
81
+ const fs = await loadFsPromises();
82
+
83
+ if (fs) {
84
+ return await fs.readFile(filePath, "utf8");
85
+ }
86
+
87
+ // Fallback to in-memory filesystem
88
+ const content = inMemoryFiles[filePath];
89
+ if (content !== undefined) {
90
+ return content;
91
+ }
92
+
93
+ throw new Error(`File not found: ${filePath}`);
94
+ }
@@ -1,4 +1,6 @@
1
1
  import { z } from "zod";
2
+ import type { ZapierSdk } from "../types/sdk";
3
+ import type { InputFieldItem } from "../schemas/Field";
2
4
 
3
5
  // ============================================================================
4
6
  // Format Metadata Types
@@ -6,92 +8,121 @@ import { z } from "zod";
6
8
 
7
9
  export interface FormattedItem {
8
10
  title: string;
9
- subtitle?: string;
11
+ id?: string;
12
+ key?: string;
13
+ description?: string;
14
+ data?: unknown; // Optional: if provided, CLI will use formatJsonOutput instead of details
10
15
  details: Array<{
11
16
  text: string;
12
17
  style: "normal" | "dim" | "accent" | "warning" | "success";
13
18
  }>;
14
19
  }
15
20
 
16
- export interface FormatMetadata {
17
- format: (item: any) => FormattedItem;
21
+ export interface FormatMetadata<TItem = unknown> {
22
+ format: (item: TItem) => FormattedItem;
18
23
  }
19
24
 
20
25
  // Helper function to add format metadata to schemas
21
26
  export function withFormatter<T extends z.ZodType>(
22
27
  schema: T,
23
- formatMeta: FormatMetadata,
28
+ formatMeta: FormatMetadata<z.infer<T>>,
24
29
  ): T {
25
30
  // Store format metadata on the schema definition
26
- (schema._def as any).formatMeta = formatMeta;
27
- return schema;
31
+ Object.assign(schema._def, {
32
+ formatMeta: formatMeta,
33
+ });
34
+ return schema as T & {
35
+ _def: T["_def"] & { formatMeta: FormatMetadata<z.infer<T>> };
36
+ };
28
37
  }
29
38
 
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;
39
+ // Helper function to get output schema from an input schema
40
+ export function getOutputSchema(inputSchema: z.ZodType): z.ZodType | undefined {
41
+ return (inputSchema._def as { outputSchema?: z.ZodType }).outputSchema;
35
42
  }
36
43
 
37
44
  // Helper function to link input schemas to output schemas
38
45
  export function withOutputSchema<T extends z.ZodType>(
39
46
  inputSchema: T,
40
47
  outputSchema: z.ZodType,
41
- ): T {
48
+ ): T & {
49
+ _def: T["_def"] & { outputSchema: z.ZodType };
50
+ } {
42
51
  // 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;
52
+ Object.assign(inputSchema._def, {
53
+ outputSchema,
54
+ });
55
+ return inputSchema as T & {
56
+ _def: T["_def"] & { outputSchema: z.ZodType };
57
+ };
50
58
  }
51
59
 
52
60
  // ============================================================================
53
61
  // Resolution Metadata Types
54
62
  // ============================================================================
55
63
 
56
- export interface StaticResolver {
64
+ export interface PromptConfig {
65
+ type: "list";
66
+ name: string;
67
+ message: string;
68
+ choices: Array<{
69
+ name: string;
70
+ value: unknown;
71
+ }>;
72
+ }
73
+
74
+ export interface Resolver {
75
+ type: string;
76
+ depends?: readonly string[] | string[]; // Parameters this resolver depends on
77
+ }
78
+
79
+ export interface StaticResolver extends Resolver {
57
80
  type: "static";
58
81
  inputType?: "text" | "password" | "email";
59
82
  placeholder?: string;
60
83
  }
61
84
 
62
- export interface DynamicResolver {
85
+ export interface DynamicResolver<
86
+ TItem = unknown,
87
+ TParams = Record<string, unknown>,
88
+ > extends Resolver {
63
89
  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
90
+ fetch: (sdk: ZapierSdk, resolvedParams: TParams) => Promise<TItem[]>; // Function to fetch data using SDK
91
+ prompt: (items: TItem[], params: TParams) => PromptConfig;
67
92
  }
68
93
 
69
- export interface FieldsResolver {
94
+ export interface FieldsResolver<TParams = Record<string, unknown>>
95
+ extends Resolver {
70
96
  type: "fields";
71
- fetch: (sdk: any, resolvedParams: any) => Promise<any[]>; // Function to fetch fields using SDK
72
- depends?: string[]; // Parameters this resolver depends on
97
+ fetch: (sdk: ZapierSdk, resolvedParams: TParams) => Promise<InputFieldItem[]>; // Function to fetch fields using SDK
73
98
  }
74
99
 
75
- export type ResolverMetadata =
76
- | StaticResolver
77
- | DynamicResolver
78
- | FieldsResolver;
100
+ export type ResolverMetadata<
101
+ TItem = unknown,
102
+ TParams = Record<string, unknown>,
103
+ > = StaticResolver | DynamicResolver<TItem, TParams> | FieldsResolver<TParams>;
79
104
 
80
105
  // Wrapper interface for resolver metadata to allow future extensibility
81
- export interface ResolverConfig {
82
- resolver: ResolverMetadata;
106
+ export interface ResolverConfig<
107
+ TItem = unknown,
108
+ TParams = Record<string, unknown>,
109
+ > {
110
+ resolver: ResolverMetadata<TItem, TParams>;
83
111
  // Future metadata types can be added here:
84
112
  // validation?: ValidationMetadata;
85
113
  // display?: DisplayMetadata;
86
114
  }
87
115
 
88
116
  // Helper function to add resolver metadata to schemas
89
- export function withResolver<T extends z.ZodType>(
90
- schema: T,
91
- config: ResolverConfig,
92
- ): T {
117
+ export function withResolver<
118
+ T extends z.ZodType,
119
+ TItem = unknown,
120
+ TParams = Record<string, unknown>,
121
+ >(schema: T, config: ResolverConfig<TItem, TParams>): T {
93
122
  // Store resolver metadata on the schema definition
94
- (schema._def as any).resolverMeta = config;
123
+ (
124
+ schema._def as { resolverMeta?: ResolverConfig<TItem, TParams> }
125
+ ).resolverMeta = config;
95
126
  return schema;
96
127
  }
97
128
 
@@ -104,7 +135,7 @@ export function getSchemaDescription(schema: z.ZodSchema): string | undefined {
104
135
  }
105
136
 
106
137
  export function getFieldDescriptions(
107
- schema: z.ZodObject<any>,
138
+ schema: z.ZodObject<z.ZodRawShape>,
108
139
  ): Record<string, string> {
109
140
  const descriptions: Record<string, string> = {};
110
141
  const shape = schema.shape;
@@ -123,20 +154,41 @@ export function getFieldDescriptions(
123
154
  // ============================================================================
124
155
 
125
156
  export interface PositionalMetadata {
126
- positional: true;
157
+ positionalMeta: {
158
+ positional: true;
159
+ };
127
160
  }
128
161
 
129
162
  // Helper function to mark a parameter as positional for CLI
130
- export function withPositional<T extends z.ZodType>(schema: T): T {
163
+ export function withPositional<T extends z.ZodType>(
164
+ schema: T,
165
+ ): T & {
166
+ _def: T["_def"] & PositionalMetadata;
167
+ } {
131
168
  // Store positional metadata on the schema definition
132
- (schema._def as any).positionalMeta = { positional: true };
133
- return schema;
169
+ Object.assign(schema._def, {
170
+ positionalMeta: { positional: true },
171
+ } satisfies PositionalMetadata);
172
+ return schema as T & {
173
+ _def: T["_def"] & PositionalMetadata;
174
+ };
175
+ }
176
+
177
+ function schemaHasPositionalMeta<T extends z.ZodType>(
178
+ schema: T,
179
+ ): schema is T & {
180
+ _def: T["_def"] & PositionalMetadata;
181
+ } {
182
+ return "positionalMeta" in schema._def;
134
183
  }
135
184
 
136
185
  // Helper function to check if a parameter should be positional
137
186
  export function isPositional(schema: z.ZodType): boolean {
138
187
  // Check the current schema first
139
- if ((schema._def as any).positionalMeta?.positional) {
188
+ if (
189
+ schemaHasPositionalMeta(schema) &&
190
+ schema._def.positionalMeta?.positional
191
+ ) {
140
192
  return true;
141
193
  }
142
194