@vertaaux/cli 0.3.0 → 0.3.2

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.
@@ -16,6 +16,7 @@ export interface AuditCommandOptions {
16
16
  timeout?: number;
17
17
  interval?: number;
18
18
  format?: string;
19
+ json?: boolean;
19
20
  output?: string;
20
21
  groupBy?: "severity" | "category" | "route";
21
22
  severity?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"audit.d.ts","sourceRoot":"","sources":["../../src/commands/audit.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAyFpC,MAAM,WAAW,mBAAmB;IAElC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IAGrB,IAAI,CAAC,EAAE,OAAO,GAAG,UAAU,GAAG,MAAM,CAAC;IACrC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAGlB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,UAAU,GAAG,UAAU,GAAG,OAAO,CAAC;IAG5C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAGlB,MAAM,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC;IAC/C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,YAAY,CA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AM,CAAC;IAGf,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IAGpB,MAAM,CAAC,EAAE,OAAO,GAAG,UAAU,GAAG,MAAM,CAAC;IAGvC,MAAM,CAAC,EAAE,MAAM,CAAC;IAGhB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,YAAY,CAAC,EAAE,OAAO,CAAC;IAGvB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAGlB,QAAQ,CAAC,EAAE,OAAO,CAAC;IAGnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAGlB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAw5BD;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAmT3D"}
@@ -380,8 +380,9 @@ async function executeAudit(targetUrl, options, config) {
380
380
  const base = resolveApiBase(options.base);
381
381
  const apiKey = getApiKey(config.apiKey);
382
382
  // Resolve output format using per-command registry
383
+ // --json flag is a shorthand for --format json (convenient for piping)
383
384
  const machineMode = options.machine || false;
384
- const explicitFormat = options.format || config.output?.format;
385
+ const explicitFormat = options.json ? "json" : (options.format || config.output?.format);
385
386
  const validatedFormat = resolveCommandFormat("audit", explicitFormat, machineMode);
386
387
  const format = validatedFormat;
387
388
  const formatter = createOutput(format);
@@ -412,7 +413,7 @@ async function executeAudit(targetUrl, options, config) {
412
413
  try {
413
414
  // Start spinner (dashboard renders on first update)
414
415
  spinner?.start();
415
- // Create audit job
416
+ // Create audit job (server runs audit synchronously and returns results)
416
417
  const created = await apiRequest(base, "/audit", {
417
418
  method: "POST",
418
419
  body: { url: targetUrl, mode },
@@ -447,34 +448,48 @@ async function executeAudit(targetUrl, options, config) {
447
448
  }
448
449
  return;
449
450
  }
450
- // Wait for completion with progress updates
451
- if (!created.job_id) {
452
- throw new Error("Audit response missing job_id");
453
- }
454
- const result = await waitForAudit(base, created.job_id, timeout, interval, apiKey, (progress, status) => {
455
- if (aborted)
456
- return;
457
- if (renderer) {
458
- const phase = mapStatusToPhase(status);
459
- const state = {
460
- phase,
461
- phaseIndex: phaseIndex(phase),
462
- phaseTotal: phaseTotal(),
463
- url: targetUrl,
464
- mode,
465
- progress: { audit: progress },
466
- totals: { audit: 100 },
467
- issueCount: 0,
468
- scorePreview: null,
469
- verbose: false,
470
- elapsed: Date.now() - auditStartTime,
471
- };
472
- renderer.update(state);
473
- }
474
- if (spinner) {
475
- updateSpinner(spinner, `Auditing ${targetUrl}`, progress, 100);
451
+ // Determine if the server returned results synchronously (status 200)
452
+ // or queued the job for background processing (status 202, legacy servers)
453
+ const isSyncResponse = created.status === "completed" && created.scores;
454
+ let result;
455
+ if (created.status === "failed") {
456
+ // Server ran the audit synchronously but it failed
457
+ throw new Error(created.error || "Audit failed on server");
458
+ }
459
+ if (isSyncResponse) {
460
+ // Server already ran the audit — use the response directly
461
+ result = created;
462
+ }
463
+ else {
464
+ // Legacy/async path: poll for completion
465
+ if (!created.job_id) {
466
+ throw new Error("Audit response missing job_id");
476
467
  }
477
- });
468
+ result = await waitForAudit(base, created.job_id, timeout, interval, apiKey, (progress, status) => {
469
+ if (aborted)
470
+ return;
471
+ if (renderer) {
472
+ const phase = mapStatusToPhase(status);
473
+ const state = {
474
+ phase,
475
+ phaseIndex: phaseIndex(phase),
476
+ phaseTotal: phaseTotal(),
477
+ url: targetUrl,
478
+ mode,
479
+ progress: { audit: progress },
480
+ totals: { audit: 100 },
481
+ issueCount: 0,
482
+ scorePreview: null,
483
+ verbose: false,
484
+ elapsed: Date.now() - auditStartTime,
485
+ };
486
+ renderer.update(state);
487
+ }
488
+ if (spinner) {
489
+ updateSpinner(spinner, `Auditing ${targetUrl}`, progress, 100);
490
+ }
491
+ });
492
+ }
478
493
  // Finish dashboard or spinner
479
494
  if (renderer) {
480
495
  const overallScore = getOverallScoreFromResult(result);
@@ -774,6 +789,7 @@ export function registerAuditCommand(program) {
774
789
  .option("--auth-profile <profile>", "Authentication profile for protected pages")
775
790
  .option("--mode <mode>", "Audit depth: basic|standard|deep", parseMode, "basic")
776
791
  .option("--format <format>", "Output format: json|sarif|junit|html|human (default: human in terminal, auto-detected in CI)")
792
+ .option("--json", "Shorthand for --format json (convenient for piping)")
777
793
  .option("-o, --output <path>", "Output file path")
778
794
  .option("--group-by <field>", "Group issues by: severity|category|route", parseGroupBy)
779
795
  .option("--wait", "Wait for audit completion (default)")
@@ -925,7 +941,7 @@ export function registerAuditCommand(program) {
925
941
  // Aggregate and output results
926
942
  const aggregated = aggregateResults(results);
927
943
  aggregated.totalDuration = Date.now() - startTime;
928
- if (cmdOptions.format === "json") {
944
+ if (cmdOptions.json || cmdOptions.format === "json") {
929
945
  writeJsonOutput(aggregated, "audit");
930
946
  }
931
947
  else {