@zapier/zapier-sdk-cli 0.4.4 → 0.5.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zapier/zapier-sdk-cli",
3
- "version": "0.4.4",
3
+ "version": "0.5.0",
4
4
  "description": "Command line interface for Zapier SDK",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -31,9 +31,9 @@
31
31
  "ora": "^8.2.0",
32
32
  "pkce-challenge": "^5.0.0",
33
33
  "zod": "^3.25.67",
34
- "@zapier/zapier-sdk": "0.5.1",
35
- "@zapier/zapier-sdk-mcp": "0.1.3",
36
- "@zapier/zapier-sdk-cli-login": "0.3.1"
34
+ "@zapier/zapier-sdk": "0.5.2",
35
+ "@zapier/zapier-sdk-cli-login": "0.3.2",
36
+ "@zapier/zapier-sdk-mcp": "0.1.4"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@types/express": "^5.0.3",
@@ -46,7 +46,11 @@ export function createBundleCodeCommand(): Command {
46
46
  command.option(flags.join(", "), param.description);
47
47
  } else {
48
48
  const flagSignature = flags.join(", ") + ` <${param.type}>`;
49
- command.option(flagSignature, param.description, param.default);
49
+ command.option(
50
+ flagSignature,
51
+ param.description || "",
52
+ param.default as string | boolean | string[] | undefined,
53
+ );
50
54
  }
51
55
  }
52
56
  });
@@ -54,10 +58,12 @@ export function createBundleCodeCommand(): Command {
54
58
  // Add formatting options like other commands
55
59
  command.option("--json", "Output raw JSON instead of formatted results");
56
60
 
57
- command.action(async (...args: any[]) => {
61
+ command.action(async (...args: unknown[]) => {
58
62
  try {
59
63
  // The last argument is always the command object with parsed options
60
- const commandObj = args[args.length - 1];
64
+ const commandObj = args[args.length - 1] as {
65
+ opts(): Record<string, unknown>;
66
+ };
61
67
  const options = commandObj.opts();
62
68
 
63
69
  // Convert CLI args to SDK method parameters
@@ -76,7 +82,16 @@ export function createBundleCodeCommand(): Command {
76
82
  console.log(chalk.blue(`šŸ“¦ Bundling ${rawParams.input}...`));
77
83
 
78
84
  // Call our implementation
79
- const result = await bundleCode(rawParams as any);
85
+ const result = await bundleCode(
86
+ rawParams as {
87
+ string: boolean;
88
+ input: string;
89
+ minify: boolean;
90
+ target: string;
91
+ cjs: boolean;
92
+ output?: string | undefined;
93
+ },
94
+ );
80
95
 
81
96
  if (options.json) {
82
97
  console.log(JSON.stringify({ result }, null, 2));
@@ -48,7 +48,11 @@ export function createGenerateTypesCommand(): Command {
48
48
  command.option(flags.join(", "), param.description);
49
49
  } else {
50
50
  const flagSignature = flags.join(", ") + ` <${param.type}>`;
51
- command.option(flagSignature, param.description, param.default);
51
+ command.option(
52
+ flagSignature,
53
+ param.description || "",
54
+ param.default as string | boolean | string[] | undefined,
55
+ );
52
56
  }
53
57
  }
54
58
  });
@@ -56,10 +60,12 @@ export function createGenerateTypesCommand(): Command {
56
60
  // Add formatting options like other commands
57
61
  command.option("--json", "Output raw JSON instead of formatted results");
58
62
 
59
- command.action(async (...args: any[]) => {
63
+ command.action(async (...args: unknown[]) => {
60
64
  try {
61
65
  // The last argument is always the command object with parsed options
62
- const commandObj = args[args.length - 1];
66
+ const commandObj = args[args.length - 1] as {
67
+ opts(): Record<string, unknown>;
68
+ };
63
69
  const options = commandObj.opts();
64
70
 
65
71
  // Convert CLI args to SDK method parameters
@@ -80,20 +86,29 @@ export function createGenerateTypesCommand(): Command {
80
86
  sdk,
81
87
  );
82
88
 
89
+ const params = resolvedParams as Record<string, unknown>;
83
90
  console.log(
84
91
  chalk.blue(
85
- `šŸ”§ Generating TypeScript types for ${resolvedParams.appKey}...`,
92
+ `šŸ”§ Generating TypeScript types for ${params.appKey as string}...`,
86
93
  ),
87
94
  );
88
95
 
89
96
  // Call our implementation
90
- const result = await generateTypes({ ...resolvedParams, sdk });
97
+ const generateTypesParams = {
98
+ appKey: params.appKey as string,
99
+ debug: (params.debug as boolean) ?? false,
100
+ authenticationId: params.authenticationId as number | undefined,
101
+ output: params.output as string | undefined,
102
+ sdk,
103
+ };
104
+ const result = await generateTypes(generateTypesParams);
91
105
 
92
106
  if (options.json) {
93
107
  console.log(JSON.stringify({ result }, null, 2));
94
108
  } else {
95
109
  const output =
96
- resolvedParams.output || `./types/${resolvedParams.appKey}.d.ts`;
110
+ (params.output as string) ||
111
+ `./types/${params.appKey as string}.d.ts`;
97
112
  console.log(chalk.green("āœ… TypeScript types generated successfully!"));
98
113
  console.log(chalk.gray(`Output written to: ${output}`));
99
114
  }
@@ -1,13 +1,13 @@
1
1
  // Simple HTTP client for OAuth authentication
2
- export interface ApiResponse<T = any> {
2
+ export interface ApiResponse<T = unknown> {
3
3
  data: T;
4
4
  status: number;
5
5
  }
6
6
 
7
7
  export const createApiClient = () => {
8
- const post = async <T = any>(
8
+ const post = async <T = unknown>(
9
9
  url: string,
10
- data: any,
10
+ data: Record<string, string>,
11
11
  options: {
12
12
  headers?: Record<string, string>;
13
13
  } = {},
@@ -10,7 +10,7 @@ export interface CliParameter {
10
10
  type: "string" | "number" | "boolean" | "array";
11
11
  required: boolean;
12
12
  description?: string;
13
- default?: any;
13
+ default?: unknown;
14
14
  choices?: string[];
15
15
  hasResolver?: boolean;
16
16
  isPositional?: boolean;
@@ -43,7 +43,7 @@ function analyzeZodField(
43
43
  ): CliParameter | null {
44
44
  let baseSchema = schema;
45
45
  let required = true;
46
- let defaultValue: any = undefined;
46
+ let defaultValue: unknown = undefined;
47
47
 
48
48
  // Unwrap optional and default wrappers
49
49
  if (baseSchema instanceof z.ZodOptional) {
@@ -96,10 +96,10 @@ function analyzeZodField(
96
96
 
97
97
  export function convertCliArgsToSdkParams(
98
98
  parameters: CliParameter[],
99
- positionalArgs: any[],
100
- options: Record<string, any>,
101
- ): Record<string, any> {
102
- const sdkParams: Record<string, any> = {};
99
+ positionalArgs: unknown[],
100
+ options: Record<string, unknown>,
101
+ ): Record<string, unknown> {
102
+ const sdkParams: Record<string, unknown> = {};
103
103
 
104
104
  // Handle positional arguments (required parameters or optional positional parameters)
105
105
  let argIndex = 0;
@@ -131,7 +131,7 @@ export function convertCliArgsToSdkParams(
131
131
  return sdkParams;
132
132
  }
133
133
 
134
- function convertValue(value: any, type: CliParameter["type"]): any {
134
+ function convertValue(value: unknown, type: CliParameter["type"]): unknown {
135
135
  switch (type) {
136
136
  case "number":
137
137
  return Number(value);
@@ -17,13 +17,15 @@ import inquirer from "inquirer";
17
17
  // JSON Formatting
18
18
  // ============================================================================
19
19
 
20
- function formatJsonOutput(data: any): void {
20
+ function formatJsonOutput(data: unknown): void {
21
21
  // Show success message for action results
22
22
  if (
23
23
  data &&
24
24
  typeof data === "object" &&
25
25
  !Array.isArray(data) &&
26
- (data.success !== undefined || data.id || data.status)
26
+ ((data as Record<string, unknown>).success !== undefined ||
27
+ (data as Record<string, unknown>).id ||
28
+ (data as Record<string, unknown>).status)
27
29
  ) {
28
30
  console.log(chalk.green("āœ… Action completed successfully!\n"));
29
31
  }
@@ -41,7 +43,7 @@ function formatJsonOutput(data: any): void {
41
43
  interface CliCommandConfig {
42
44
  description: string;
43
45
  parameters: CliParameter[];
44
- handler: (...args: any[]) => Promise<void>;
46
+ handler: (...args: unknown[]) => Promise<void>;
45
47
  }
46
48
 
47
49
  interface CliParameter {
@@ -49,7 +51,7 @@ interface CliParameter {
49
51
  type: "string" | "number" | "boolean" | "array";
50
52
  required: boolean;
51
53
  description?: string;
52
- default?: any;
54
+ default?: unknown;
53
55
  choices?: string[];
54
56
  hasResolver?: boolean;
55
57
  isPositional?: boolean;
@@ -82,7 +84,7 @@ function analyzeZodField(
82
84
  ): CliParameter | null {
83
85
  let baseSchema = schema;
84
86
  let required = true;
85
- let defaultValue: any = undefined;
87
+ let defaultValue: unknown = undefined;
86
88
 
87
89
  // Unwrap optional and default wrappers
88
90
  if (baseSchema instanceof z.ZodOptional) {
@@ -190,10 +192,12 @@ function createCommandConfig(
190
192
  const parameters = analyzeZodSchema(schema);
191
193
  const description = schema.description || `${cliCommandName} command`;
192
194
 
193
- const handler = async (...args: any[]) => {
195
+ const handler = async (...args: unknown[]) => {
194
196
  try {
195
197
  // The last argument is always the command object with parsed options
196
- const commandObj = args[args.length - 1];
198
+ const commandObj = args[args.length - 1] as {
199
+ opts(): Record<string, unknown>;
200
+ };
197
201
  const options = commandObj.opts();
198
202
 
199
203
  // Check if this is a list command for pagination
@@ -201,7 +205,7 @@ function createCommandConfig(
201
205
  const hasPaginationParams = parameters.some(
202
206
  (p) => p.name === "maxItems" || p.name === "pageSize",
203
207
  );
204
- const hasUserSpecifiedMaxItems =
208
+ const hasUserSpecifiedMaxItems: boolean =
205
209
  "maxItems" in options && options.maxItems !== undefined;
206
210
  const shouldUseJson = options.json;
207
211
 
@@ -220,18 +224,6 @@ function createCommandConfig(
220
224
  sdk,
221
225
  );
222
226
 
223
- // Special handling for commands that write to files
224
- const hasOutputFile = resolvedParams.output;
225
- if (hasOutputFile) {
226
- // Call the SDK method for file output commands
227
- await (sdk as any)[sdkMethodName](resolvedParams);
228
- console.log(
229
- chalk.green(`āœ… ${cliCommandName} completed successfully!`),
230
- );
231
- console.log(chalk.gray(`Output written to: ${resolvedParams.output}`));
232
- return;
233
- }
234
-
235
227
  // Handle paginated list commands with async iteration
236
228
  if (
237
229
  isListCommand &&
@@ -240,25 +232,51 @@ function createCommandConfig(
240
232
  !hasUserSpecifiedMaxItems
241
233
  ) {
242
234
  // Get the async iterator directly from the SDK method call
243
- const sdkIterator = (sdk as any)[sdkMethodName](resolvedParams);
235
+ const sdkObj = sdk as unknown as Record<
236
+ string,
237
+ (params: unknown) => Promise<unknown>
238
+ >;
239
+ const sdkIterator = await sdkObj[sdkMethodName](resolvedParams);
244
240
  await handlePaginatedListWithAsyncIteration(
245
241
  sdkMethodName,
246
242
  sdkIterator,
247
243
  schema,
248
244
  );
249
245
  } else {
246
+ // Special handling for commands that write to files
247
+ const hasOutputFile = (resolvedParams as { output?: unknown }).output;
248
+ if (hasOutputFile) {
249
+ // Call the SDK method for file output commands
250
+ const sdkObj = sdk as unknown as Record<
251
+ string,
252
+ (params: unknown) => Promise<unknown>
253
+ >;
254
+ await sdkObj[sdkMethodName](resolvedParams);
255
+ console.log(
256
+ chalk.green(`āœ… ${cliCommandName} completed successfully!`),
257
+ );
258
+ console.log(chalk.gray(`Output written to: ${hasOutputFile}`));
259
+ return;
260
+ }
261
+
250
262
  // Call the SDK method and handle non-paginated results
251
- const result = await (sdk as any)[sdkMethodName](resolvedParams);
252
- const items = result?.data ? result.data : result;
263
+ const sdkObj = sdk as unknown as Record<
264
+ string,
265
+ (params: unknown) => Promise<unknown>
266
+ >;
267
+ const result: unknown = await sdkObj[sdkMethodName](resolvedParams);
268
+ const items = (result as { data?: unknown })?.data
269
+ ? (result as { data: unknown }).data
270
+ : result;
253
271
 
254
272
  if (shouldUseJson) {
255
273
  console.log(JSON.stringify(items, null, 2));
256
274
  } else if (isListCommand) {
257
275
  formatNonPaginatedResults(
258
- items,
259
- resolvedParams.maxItems,
276
+ items as unknown[],
277
+ (resolvedParams as { maxItems?: number }).maxItems,
260
278
  hasUserSpecifiedMaxItems,
261
- shouldUseJson,
279
+ shouldUseJson as boolean,
262
280
  schema,
263
281
  sdkMethodName,
264
282
  );
@@ -272,9 +290,14 @@ function createCommandConfig(
272
290
  try {
273
291
  const validationErrors = JSON.parse(error.message);
274
292
  console.error(chalk.red("āŒ Validation Error:"));
275
- validationErrors.forEach((err: any) => {
276
- const field = err.path?.join(".") || "unknown";
277
- console.error(chalk.yellow(` • ${field}: ${err.message}`));
293
+ validationErrors.forEach((err: unknown) => {
294
+ const errorObj = err as { path?: string[]; message?: string };
295
+ const field = errorObj?.path?.join(".") || "unknown";
296
+ console.error(
297
+ chalk.yellow(
298
+ ` • ${field}: ${errorObj?.message || "Unknown error"}`,
299
+ ),
300
+ );
278
301
  });
279
302
  console.error(
280
303
  "\n" + chalk.dim(`Use --help to see available options`),
@@ -342,10 +365,18 @@ function addCommand(
342
365
  } else if (param.type === "array") {
343
366
  // For arrays, use variadic syntax to collect multiple values
344
367
  const flagSignature = flags.join(", ") + ` <values...>`;
345
- command.option(flagSignature, param.description, param.default);
368
+ command.option(
369
+ flagSignature,
370
+ param.description,
371
+ param.default as string[] | undefined,
372
+ );
346
373
  } else {
347
374
  const flagSignature = flags.join(", ") + ` <${param.type}>`;
348
- command.option(flagSignature, param.description, param.default);
375
+ command.option(
376
+ flagSignature,
377
+ param.description || "",
378
+ param.default as string | boolean | string[] | undefined,
379
+ );
349
380
  }
350
381
  }
351
382
  });
@@ -362,10 +393,10 @@ function addCommand(
362
393
 
363
394
  function convertCliArgsToSdkParams(
364
395
  parameters: CliParameter[],
365
- positionalArgs: any[],
366
- options: Record<string, any>,
367
- ): Record<string, any> {
368
- const sdkParams: Record<string, any> = {};
396
+ positionalArgs: unknown[],
397
+ options: Record<string, unknown>,
398
+ ): Record<string, unknown> {
399
+ const sdkParams: Record<string, unknown> = {};
369
400
 
370
401
  // Handle positional arguments (required parameters or optional positional parameters)
371
402
  let argIndex = 0;
@@ -397,7 +428,7 @@ function convertCliArgsToSdkParams(
397
428
  return sdkParams;
398
429
  }
399
430
 
400
- function convertValue(value: any, type: CliParameter["type"]): any {
431
+ function convertValue(value: unknown, type: CliParameter["type"]): unknown {
401
432
  switch (type) {
402
433
  case "number":
403
434
  return Number(value);
@@ -428,7 +459,7 @@ function convertValue(value: any, type: CliParameter["type"]): any {
428
459
 
429
460
  async function handlePaginatedListWithAsyncIteration(
430
461
  sdkMethodName: string,
431
- sdkResult: any,
462
+ sdkResult: unknown,
432
463
  schema: z.ZodSchema,
433
464
  ): Promise<void> {
434
465
  const itemName = getItemNameFromMethod(sdkMethodName);
@@ -439,7 +470,10 @@ async function handlePaginatedListWithAsyncIteration(
439
470
 
440
471
  try {
441
472
  // Use async iteration to go through pages
442
- for await (const page of sdkResult) {
473
+ for await (const page of sdkResult as AsyncIterable<{
474
+ data?: unknown[];
475
+ nextCursor?: string;
476
+ }>) {
443
477
  const items = page.data || page;
444
478
  pageCount++;
445
479
 
@@ -502,7 +536,7 @@ async function handlePaginatedListWithAsyncIteration(
502
536
  console.log(chalk.gray(`\nšŸ“„ Finished browsing ${itemName}`));
503
537
  } catch (error) {
504
538
  // If the result is not async iterable, fall back to showing the first page
505
- const items = sdkResult?.data || sdkResult;
539
+ const items = (sdkResult as { data?: unknown[] })?.data || sdkResult;
506
540
  if (Array.isArray(items)) {
507
541
  if (items.length === 0) {
508
542
  console.log(chalk.yellow(`No ${itemName} found.`));
@@ -523,7 +557,7 @@ async function handlePaginatedListWithAsyncIteration(
523
557
  }
524
558
 
525
559
  function formatNonPaginatedResults(
526
- result: any[],
560
+ result: unknown[],
527
561
  requestedMaxItems?: number,
528
562
  userSpecifiedMaxItems?: boolean,
529
563
  useRawJson?: boolean,
@@ -573,13 +607,14 @@ function formatNonPaginatedResults(
573
607
  }
574
608
  }
575
609
 
576
- function formatItemsGeneric(items: any[]): void {
610
+ function formatItemsGeneric(items: unknown[]): void {
577
611
  // Fallback formatting for items without schema metadata
578
612
  items.forEach((item, index) => {
579
- const name = item.title || item.name || item.key || item.id || "Item";
580
- console.log(`${chalk.gray(`${index + 1}.`)} ${chalk.cyan(name)}`);
581
- if (item.description) {
582
- console.log(` ${chalk.dim(item.description)}`);
613
+ const itemObj = item as Record<string, unknown>;
614
+ const name = itemObj?.name || itemObj?.key || itemObj?.id || "Item";
615
+ console.log(`${chalk.gray(`${index + 1}.`)} ${chalk.cyan(String(name))}`);
616
+ if (itemObj?.description) {
617
+ console.log(` ${chalk.dim(String(itemObj.description))}`);
583
618
  }
584
619
  console.log();
585
620
  });
package/src/utils/log.ts CHANGED
@@ -1,16 +1,16 @@
1
1
  import chalk from "chalk";
2
2
 
3
3
  const log = {
4
- info: (message: string, ...args: any[]) => {
4
+ info: (message: string, ...args: unknown[]) => {
5
5
  console.log(chalk.blue("ℹ"), message, ...args);
6
6
  },
7
- error: (message: string, ...args: any[]) => {
7
+ error: (message: string, ...args: unknown[]) => {
8
8
  console.error(chalk.red("āœ–"), message, ...args);
9
9
  },
10
- success: (message: string, ...args: any[]) => {
10
+ success: (message: string, ...args: unknown[]) => {
11
11
  console.log(chalk.green("āœ“"), message, ...args);
12
12
  },
13
- warn: (message: string, ...args: any[]) => {
13
+ warn: (message: string, ...args: unknown[]) => {
14
14
  console.log(chalk.yellow("⚠"), message, ...args);
15
15
  },
16
16
  };