@zapier/zapier-sdk-cli 0.4.3 → 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.
@@ -13,7 +13,9 @@ function formatJsonOutput(data) {
13
13
  if (data &&
14
14
  typeof data === "object" &&
15
15
  !Array.isArray(data) &&
16
- (data.success !== undefined || data.id || data.status)) {
16
+ (data.success !== undefined ||
17
+ data.id ||
18
+ data.status)) {
17
19
  console.log(chalk.green("✅ Action completed successfully!\n"));
18
20
  }
19
21
  // Use util.inspect for colored output
@@ -140,28 +142,33 @@ function createCommandConfig(cliCommandName, sdkMethodName, schema, sdk) {
140
142
  // Resolve missing parameters interactively using schema metadata
141
143
  const resolver = new SchemaParameterResolver();
142
144
  const resolvedParams = await resolver.resolveParameters(schema, rawParams, sdk);
143
- // Special handling for commands that write to files
144
- const hasOutputFile = resolvedParams.output;
145
- if (hasOutputFile) {
146
- // Call the SDK method for file output commands
147
- await sdk[sdkMethodName](resolvedParams);
148
- console.log(chalk.green(`✅ ${cliCommandName} completed successfully!`));
149
- console.log(chalk.gray(`Output written to: ${resolvedParams.output}`));
150
- return;
151
- }
152
145
  // Handle paginated list commands with async iteration
153
146
  if (isListCommand &&
154
147
  hasPaginationParams &&
155
148
  !shouldUseJson &&
156
149
  !hasUserSpecifiedMaxItems) {
157
150
  // Get the async iterator directly from the SDK method call
158
- const sdkIterator = sdk[sdkMethodName](resolvedParams);
151
+ const sdkObj = sdk;
152
+ const sdkIterator = await sdkObj[sdkMethodName](resolvedParams);
159
153
  await handlePaginatedListWithAsyncIteration(sdkMethodName, sdkIterator, schema);
160
154
  }
161
155
  else {
156
+ // Special handling for commands that write to files
157
+ const hasOutputFile = resolvedParams.output;
158
+ if (hasOutputFile) {
159
+ // Call the SDK method for file output commands
160
+ const sdkObj = sdk;
161
+ await sdkObj[sdkMethodName](resolvedParams);
162
+ console.log(chalk.green(`✅ ${cliCommandName} completed successfully!`));
163
+ console.log(chalk.gray(`Output written to: ${hasOutputFile}`));
164
+ return;
165
+ }
162
166
  // Call the SDK method and handle non-paginated results
163
- const result = await sdk[sdkMethodName](resolvedParams);
164
- const items = result?.data ? result.data : result;
167
+ const sdkObj = sdk;
168
+ const result = await sdkObj[sdkMethodName](resolvedParams);
169
+ const items = result?.data
170
+ ? result.data
171
+ : result;
165
172
  if (shouldUseJson) {
166
173
  console.log(JSON.stringify(items, null, 2));
167
174
  }
@@ -180,8 +187,9 @@ function createCommandConfig(cliCommandName, sdkMethodName, schema, sdk) {
180
187
  const validationErrors = JSON.parse(error.message);
181
188
  console.error(chalk.red("❌ Validation Error:"));
182
189
  validationErrors.forEach((err) => {
183
- const field = err.path?.join(".") || "unknown";
184
- console.error(chalk.yellow(` • ${field}: ${err.message}`));
190
+ const errorObj = err;
191
+ const field = errorObj?.path?.join(".") || "unknown";
192
+ console.error(chalk.yellow(` • ${field}: ${errorObj?.message || "Unknown error"}`));
185
193
  });
186
194
  console.error("\n" + chalk.dim(`Use --help to see available options`));
187
195
  }
@@ -239,7 +247,7 @@ function addCommand(program, commandName, config) {
239
247
  }
240
248
  else {
241
249
  const flagSignature = flags.join(", ") + ` <${param.type}>`;
242
- command.option(flagSignature, param.description, param.default);
250
+ command.option(flagSignature, param.description || "", param.default);
243
251
  }
244
252
  }
245
253
  });
@@ -415,10 +423,11 @@ function formatNonPaginatedResults(result, requestedMaxItems, userSpecifiedMaxIt
415
423
  function formatItemsGeneric(items) {
416
424
  // Fallback formatting for items without schema metadata
417
425
  items.forEach((item, index) => {
418
- const name = item.title || item.name || item.key || item.id || "Item";
419
- console.log(`${chalk.gray(`${index + 1}.`)} ${chalk.cyan(name)}`);
420
- if (item.description) {
421
- console.log(` ${chalk.dim(item.description)}`);
426
+ const itemObj = item;
427
+ const name = itemObj?.name || itemObj?.key || itemObj?.id || "Item";
428
+ console.log(`${chalk.gray(`${index + 1}.`)} ${chalk.cyan(String(name))}`);
429
+ if (itemObj?.description) {
430
+ console.log(` ${chalk.dim(String(itemObj.description))}`);
422
431
  }
423
432
  console.log();
424
433
  });
@@ -1,7 +1,7 @@
1
1
  declare const log: {
2
- info: (message: string, ...args: any[]) => void;
3
- error: (message: string, ...args: any[]) => void;
4
- success: (message: string, ...args: any[]) => void;
5
- warn: (message: string, ...args: any[]) => void;
2
+ info: (message: string, ...args: unknown[]) => void;
3
+ error: (message: string, ...args: unknown[]) => void;
4
+ success: (message: string, ...args: unknown[]) => void;
5
+ warn: (message: string, ...args: unknown[]) => void;
6
6
  };
7
7
  export default log;
@@ -1,7 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import { ZapierSdk } from "@zapier/zapier-sdk";
3
3
  export declare class SchemaParameterResolver {
4
- resolveParameters(schema: z.ZodSchema, providedParams: any, sdk: ZapierSdk): Promise<any>;
4
+ resolveParameters(schema: z.ZodSchema, providedParams: unknown, sdk: ZapierSdk): Promise<unknown>;
5
5
  private extractParametersFromSchema;
6
6
  private analyzeFieldSchema;
7
7
  private createResolvableParameter;
@@ -55,7 +55,7 @@ export class SchemaParameterResolver {
55
55
  }
56
56
  return parseResult.data;
57
57
  }
58
- // 2. Resolve functionally required parameters and their dependencies first
58
+ // 2. Resolve functionally required parameters first
59
59
  const resolvedParams = { ...providedParams };
60
60
  const context = {
61
61
  sdk,
@@ -274,7 +274,8 @@ export class SchemaParameterResolver {
274
274
  break;
275
275
  }
276
276
  // Find new fields that we haven't processed yet
277
- const newFields = fields.filter((field) => !processedFieldKeys.has(field.key));
277
+ const newFields = fields.filter((field) => !(field.key &&
278
+ processedFieldKeys.has(field.key)));
278
279
  if (newFields.length === 0) {
279
280
  // No new fields, we're done
280
281
  break;
@@ -340,35 +341,44 @@ export class SchemaParameterResolver {
340
341
  setNestedValue(obj, path, value) {
341
342
  const lastKey = path[path.length - 1];
342
343
  const parent = path.slice(0, -1).reduce((current, key) => {
343
- if (!(key in current)) {
344
- current[key] = {};
344
+ const currentObj = current;
345
+ if (!(key in currentObj)) {
346
+ currentObj[key] = {};
345
347
  }
346
- return current[key];
348
+ return currentObj[key];
347
349
  }, obj);
348
350
  parent[lastKey] = value;
349
351
  }
350
352
  async promptForField(field, inputs) {
353
+ const fieldObj = field;
351
354
  const fieldPrompt = {
352
- type: field.type === "boolean" ? "confirm" : "input",
353
- name: field.key,
354
- message: `${field.label || field.key}${field.required ? " (required)" : " (optional)"}:`,
355
- ...(field.helpText && { prefix: chalk.gray(`ℹ ${field.helpText}\n`) }),
356
- ...(field.default && { default: field.default }),
355
+ type: fieldObj.type === "boolean" ? "confirm" : "input",
356
+ name: fieldObj.key,
357
+ message: `${fieldObj.label || fieldObj.key}${fieldObj.required ? " (required)" : " (optional)"}:`,
357
358
  };
358
- if (field.choices && field.choices.length > 0) {
359
+ if (fieldObj.helpText) {
360
+ fieldPrompt.prefix = chalk.gray(`ℹ ${fieldObj.helpText}\n`);
361
+ }
362
+ if (fieldObj.default !== undefined) {
363
+ fieldPrompt.default = fieldObj.default;
364
+ }
365
+ if (fieldObj.choices && fieldObj.choices.length > 0) {
359
366
  fieldPrompt.type = "list";
360
- fieldPrompt.choices = field.choices.map((choice) => ({
361
- name: choice.label || choice.value,
362
- value: choice.value,
363
- }));
367
+ fieldPrompt.choices = fieldObj.choices.map((choice) => {
368
+ const choiceObj = choice;
369
+ return {
370
+ name: choiceObj.label || choiceObj.value,
371
+ value: choiceObj.value,
372
+ };
373
+ });
364
374
  }
365
375
  try {
366
376
  const answer = await inquirer.prompt([fieldPrompt]);
367
- if (answer[field.key] !== undefined && answer[field.key] !== "") {
368
- inputs[field.key] = answer[field.key];
377
+ if (answer[fieldObj.key] !== undefined && answer[fieldObj.key] !== "") {
378
+ inputs[fieldObj.key] = answer[fieldObj.key];
369
379
  }
370
- else if (field.required) {
371
- throw new Error(`Required field ${field.key} cannot be empty`);
380
+ else if (fieldObj.required) {
381
+ throw new Error(`Required field ${fieldObj.key} cannot be empty`);
372
382
  }
373
383
  }
374
384
  catch (error) {
@@ -380,8 +390,9 @@ export class SchemaParameterResolver {
380
390
  }
381
391
  }
382
392
  isUserCancellation(error) {
383
- return (error?.name === "ExitPromptError" ||
384
- error?.message?.includes("User force closed") ||
385
- error?.isTTYError);
393
+ const errorObj = error;
394
+ return (errorObj?.name === "ExitPromptError" ||
395
+ errorObj?.message?.includes("User force closed") ||
396
+ errorObj?.isTTYError === true);
386
397
  }
387
398
  }