@zapier/zapier-sdk-cli 0.30.0 → 0.31.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.
@@ -105,8 +105,8 @@ function analyzeZodField(name, schema, functionInfo) {
105
105
  choices = baseSchema.options;
106
106
  }
107
107
  else if (baseSchema instanceof z.ZodRecord) {
108
- // Handle Record<string, any> as JSON string input
109
- paramType = "string";
108
+ // Handle Record<string, any> - user passes JSON string, we parse to object
109
+ paramType = "object";
110
110
  }
111
111
  // Check if this parameter has a resolver
112
112
  let paramHasResolver = false;
@@ -441,8 +441,14 @@ function createCommandConfig(cliCommandName, functionInfo, sdk) {
441
441
  parameters,
442
442
  handler,
443
443
  hidden: functionInfo.categories?.includes("deprecated") ?? false,
444
+ aliases: functionInfo.aliases,
444
445
  };
445
446
  }
447
+ // Collect function for repeatable options (e.g., -d foo -d bar → ['foo', 'bar'])
448
+ function collect(value, previous = []) {
449
+ previous.push(value);
450
+ return previous;
451
+ }
446
452
  function addCommand(program, commandName, config) {
447
453
  const command = program
448
454
  .command(commandName, { hidden: config.hidden ?? false })
@@ -465,10 +471,10 @@ function addCommand(program, commandName, config) {
465
471
  command.argument(`<${kebabName}...>`, param.description || `${kebabName} parameter`);
466
472
  }
467
473
  else if (param.required && param.type === "array") {
468
- // Subsequent required array parameters become required flags
474
+ // Subsequent required array parameters become required flags (repeatable)
469
475
  const flags = [`--${kebabName}`];
470
- const flagSignature = flags.join(", ") + ` <values...>`;
471
- command.requiredOption(flagSignature, param.description || `${kebabName} parameter (required)`);
476
+ const flagSignature = flags.join(", ") + ` <value>`;
477
+ command.requiredOption(flagSignature, param.description || `${kebabName} parameter (required, repeatable)`, collect, []);
472
478
  }
473
479
  else if (param.required) {
474
480
  // Required parameters without resolvers become required positional arguments
@@ -480,14 +486,20 @@ function addCommand(program, commandName, config) {
480
486
  }
481
487
  else {
482
488
  // Optional parameters become flags (whether they have resolvers or not)
483
- const flags = [`--${kebabName}`];
489
+ const flags = [];
490
+ // Add short alias if defined (single-letter aliases only)
491
+ const alias = config.aliases?.[param.name];
492
+ if (alias && alias.length === 1) {
493
+ flags.push(`-${alias}`);
494
+ }
495
+ flags.push(`--${kebabName}`);
484
496
  if (param.type === "boolean") {
485
497
  command.option(flags.join(", "), param.description);
486
498
  }
487
499
  else if (param.type === "array") {
488
- // For arrays, use variadic syntax to collect multiple values
489
- const flagSignature = flags.join(", ") + ` <values...>`;
490
- command.option(flagSignature, param.description, param.default);
500
+ // For arrays, use collect pattern for repeatable flags (e.g., -d foo -d bar)
501
+ const flagSignature = flags.join(", ") + ` <value>`;
502
+ command.option(flagSignature, param.description || "", collect, []);
491
503
  }
492
504
  else {
493
505
  const flagSignature = flags.join(", ") + ` <${param.type}>`;
@@ -495,8 +507,11 @@ function addCommand(program, commandName, config) {
495
507
  }
496
508
  }
497
509
  });
498
- // Add formatting options for all commands
499
- command.option("--json", "Output raw JSON instead of formatted results");
510
+ // Add formatting options for all commands (skip if schema already defines json)
511
+ const hasJsonParam = config.parameters.some((p) => p.name === "json");
512
+ if (!hasJsonParam) {
513
+ command.option("--json", "Output raw JSON instead of formatted results");
514
+ }
500
515
  command.action(config.handler);
501
516
  }
502
517
  // ============================================================================
@@ -520,6 +535,14 @@ function convertCliArgsToSdkParams(parameters, positionalArgs, options) {
520
535
  const camelKey = key.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
521
536
  const param = parameters.find((p) => p.name === camelKey);
522
537
  if (param && value !== undefined) {
538
+ // Skip empty arrays — Commander initializes repeatable options with []
539
+ // so an empty array means the user didn't pass the flag. Omitting it
540
+ // lets Zod's .default() supply the intended default value.
541
+ if (param.type === "array" &&
542
+ Array.isArray(value) &&
543
+ value.length === 0) {
544
+ return;
545
+ }
523
546
  sdkParams[camelKey] = convertValue(value, param.type);
524
547
  }
525
548
  });
@@ -538,8 +561,20 @@ function convertValue(value, type) {
538
561
  case "array":
539
562
  return Array.isArray(value) ? value : [value];
540
563
  case "string":
564
+ return value;
565
+ case "object":
566
+ // Parse JSON string to object for z.record() and similar types
567
+ if (typeof value === "string") {
568
+ try {
569
+ return JSON.parse(value);
570
+ }
571
+ catch {
572
+ return value;
573
+ }
574
+ }
575
+ return value;
541
576
  default:
542
- // Handle JSON string for objects
577
+ // Unknown schema types - try to parse if it looks like JSON
543
578
  if (typeof value === "string" &&
544
579
  (value.startsWith("{") || value.startsWith("["))) {
545
580
  try {