@zapier/zapier-sdk-cli 0.34.0 → 0.34.3

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.
@@ -6,6 +6,41 @@ import chalk from "chalk";
6
6
  import inquirer from "inquirer";
7
7
  import { ZapierCliError, ZapierCliExitError } from "./errors";
8
8
  import { SHARED_COMMAND_CLI_OPTIONS } from "./cli-options";
9
+ import { buildCliCommandExecutedEvent } from "../telemetry/builders";
10
+ const CLI_COMMAND_EXECUTED_EVENT_SUBJECT = "platform.sdk.CliCommandExecutedEvent";
11
+ // Flags whose values may contain secrets and must not appear in telemetry
12
+ const SENSITIVE_FLAGS = [
13
+ "--credentials",
14
+ "--credentials-client-secret",
15
+ "--credentials-client-id",
16
+ "--credentials-base-url",
17
+ "--user",
18
+ "--header",
19
+ "-H",
20
+ "-u",
21
+ ];
22
+ export function sanitizeCliArguments(args) {
23
+ const sanitized = [];
24
+ let skipNext = false;
25
+ for (const arg of args) {
26
+ if (skipNext) {
27
+ skipNext = false;
28
+ sanitized.push("[REDACTED]");
29
+ continue;
30
+ }
31
+ if (SENSITIVE_FLAGS.some((flag) => arg.startsWith(flag + "="))) {
32
+ sanitized.push(arg.split("=")[0] + "=[REDACTED]");
33
+ }
34
+ else if (SENSITIVE_FLAGS.includes(arg)) {
35
+ sanitized.push(arg);
36
+ skipNext = true;
37
+ }
38
+ else {
39
+ sanitized.push(arg);
40
+ }
41
+ }
42
+ return sanitized;
43
+ }
9
44
  const CONFIRM_MESSAGES = {
10
45
  "create-secret": {
11
46
  messageBefore: "You are about to create a sensitive secret that will be displayed as plain text.\n" +
@@ -299,6 +334,10 @@ function createCommandConfig(cliCommandName, functionInfo, sdk) {
299
334
  schema?.description ||
300
335
  `${cliCommandName} command`;
301
336
  const handler = async (...args) => {
337
+ const startTime = Date.now();
338
+ let success = true;
339
+ let errorMessage = null;
340
+ let resolvedParams = {};
302
341
  try {
303
342
  // The last argument is always the command object with parsed options
304
343
  const commandObj = args[args.length - 1];
@@ -312,7 +351,6 @@ function createCommandConfig(cliCommandName, functionInfo, sdk) {
312
351
  const rawParams = convertCliArgsToSdkParams(parameters, args.slice(0, -1), options);
313
352
  // Resolve missing parameters interactively using schema metadata
314
353
  // (only available for inputSchema-based functions)
315
- let resolvedParams;
316
354
  if (schema && !usesInputParameters) {
317
355
  const resolver = new SchemaParameterResolver();
318
356
  resolvedParams = (await resolver.resolveParameters(schema, rawParams, sdk, functionInfo.name));
@@ -401,6 +439,8 @@ function createCommandConfig(cliCommandName, functionInfo, sdk) {
401
439
  }
402
440
  }
403
441
  catch (error) {
442
+ success = false;
443
+ errorMessage = error instanceof Error ? error.message : String(error);
404
444
  // Handle Zod validation errors more gracefully
405
445
  if (error instanceof Error && error.message.includes('"code"')) {
406
446
  try {
@@ -431,9 +471,34 @@ function createCommandConfig(cliCommandName, functionInfo, sdk) {
431
471
  }
432
472
  else {
433
473
  // Handle other errors
434
- const errorMessage = error instanceof Error ? error.message : "Unknown error";
435
- console.error(chalk.red("❌ Error:"), errorMessage);
436
- throw new ZapierCliExitError(errorMessage, 1);
474
+ const msg = error instanceof Error ? error.message : "Unknown error";
475
+ console.error(chalk.red("❌ Error:"), msg);
476
+ throw new ZapierCliExitError(msg, 1);
477
+ }
478
+ }
479
+ finally {
480
+ try {
481
+ const event = buildCliCommandExecutedEvent({
482
+ data: {
483
+ cli_primary_command: cliCommandName,
484
+ success_flag: success,
485
+ execution_duration_ms: Date.now() - startTime,
486
+ exit_code: success ? 0 : 1,
487
+ error_message: errorMessage,
488
+ command_category: functionInfo.categories?.[0] ?? null,
489
+ requires_auth: null,
490
+ cli_arguments: sanitizeCliArguments(process.argv.slice(2)),
491
+ },
492
+ context: {
493
+ selected_api: resolvedParams.appKey ?? null,
494
+ },
495
+ });
496
+ sdk
497
+ .getContext()
498
+ .eventEmission.emit(CLI_COMMAND_EXECUTED_EVENT_SUBJECT, event);
499
+ }
500
+ catch {
501
+ // Never let telemetry failures affect command execution
437
502
  }
438
503
  }
439
504
  };