vercel 56.3.2 → 56.4.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.
Files changed (67) hide show
  1. package/dist/chunks/{add-2ITAPI7M.js → add-L3Z6PL54.js} +3 -3
  2. package/dist/chunks/{add-DVEAUH7N.js → add-RFEJCIBM.js} +2 -2
  3. package/dist/chunks/{chunk-BFFE4FAO.js → chunk-43B3LNUF.js} +1 -1
  4. package/dist/chunks/{chunk-FPMWXL3R.js → chunk-4M3ZQCYN.js} +63 -6
  5. package/dist/chunks/{chunk-TVLLFY7M.js → chunk-5EXIJBLL.js} +5 -5
  6. package/dist/chunks/{chunk-4Z5LC2CI.js → chunk-6RTK6BWX.js} +4 -96
  7. package/dist/chunks/{chunk-AVJRWFTM.js → chunk-A4XB42AB.js} +1 -1
  8. package/dist/chunks/{chunk-3OZQ7KHZ.js → chunk-CHZBEMLF.js} +2 -2
  9. package/dist/chunks/{chunk-O3UHQI3T.js → chunk-DXFSBJTA.js} +1 -1
  10. package/dist/chunks/{chunk-QW4XUBC3.js → chunk-F32B76CK.js} +1 -1
  11. package/dist/chunks/{query-K2TJKOAL.js → chunk-F5OMERHI.js} +65 -411
  12. package/dist/chunks/{chunk-5POUHPEH.js → chunk-GKVAAY2A.js} +1 -1
  13. package/dist/chunks/{chunk-HZAINEXG.js → chunk-GLAHGVBS.js} +6 -2
  14. package/dist/chunks/{chunk-573XYQ3D.js → chunk-HZKJMZEQ.js} +2 -2
  15. package/dist/chunks/{chunk-2CEGMXO6.js → chunk-IHQ7DPQI.js} +76 -2
  16. package/dist/chunks/{chunk-JQBH4QTB.js → chunk-J6KTUJHV.js} +1 -1
  17. package/dist/chunks/{chunk-WQN52QMS.js → chunk-MQRHJEBS.js} +2 -2
  18. package/dist/chunks/{chunk-GB3QQGZU.js → chunk-NLRIKNPX.js} +1 -1
  19. package/dist/chunks/{chunk-ZKKJEOQT.js → chunk-OOD67FAL.js} +1 -1
  20. package/dist/chunks/{chunk-5FF4WXVM.js → chunk-UHGAPG7O.js} +4 -4
  21. package/dist/chunks/{chunk-BZXHF66T.js → chunk-VLTQJKP6.js} +1 -1
  22. package/dist/chunks/{chunk-OK6EYKRX.js → chunk-XFGY3JAX.js} +1 -1
  23. package/dist/chunks/{chunk-SRIA62TV.js → chunk-Y7TVKRRJ.js} +3 -3
  24. package/dist/chunks/chunk-Z7NPYIZ6.js +116 -0
  25. package/dist/chunks/{compile-vercel-config-P3KRRAC6.js → compile-vercel-config-J2X5OV6K.js} +1 -1
  26. package/dist/chunks/{delete-OXEMVOQE.js → delete-57A44RN7.js} +2 -2
  27. package/dist/chunks/{disable-DZA53CJA.js → disable-DNZ52MEO.js} +2 -2
  28. package/dist/chunks/{discard-3E7Z7CKD.js → discard-HACSIZ74.js} +2 -2
  29. package/dist/chunks/{edit-UM6TWX2Z.js → edit-HJ47TQU3.js} +3 -3
  30. package/dist/chunks/{enable-3SH6X23Z.js → enable-BVLRVRYM.js} +2 -2
  31. package/dist/chunks/{export-TLQERLQP.js → export-7MJFGMG7.js} +2 -2
  32. package/dist/chunks/{image-YKGEEC2A.js → image-4UMD7UZP.js} +3 -3
  33. package/dist/chunks/{inspect-652QJ33O.js → inspect-4JD2QN67.js} +2 -2
  34. package/dist/chunks/{inspect-S6X6PCGS.js → inspect-5YZP7IWI.js} +2 -2
  35. package/dist/chunks/{inspect-34OE66PO.js → inspect-WBHUZC3R.js} +2 -2
  36. package/dist/chunks/{inspect-QW6RSV7Z.js → inspect-XX3OXSHC.js} +2 -2
  37. package/dist/chunks/{list-OVWTXBSN.js → list-5H57NTM4.js} +1 -1
  38. package/dist/chunks/{list-IWXFZBH7.js → list-AM6K2JCW.js} +2 -2
  39. package/dist/chunks/{login-S77F2DLW.js → login-YO34E4V5.js} +2 -2
  40. package/dist/chunks/{ls-SAY4VQIT.js → ls-44NPIO2N.js} +2 -2
  41. package/dist/chunks/{ls-J4HHGSFU.js → ls-MB74DIQV.js} +3 -3
  42. package/dist/chunks/{ls-FQIWFI4K.js → ls-P7ZLBWW2.js} +2 -2
  43. package/dist/chunks/{ls-PQPRURTJ.js → ls-YDUYTLXW.js} +2 -2
  44. package/dist/chunks/{publish-LWCEDLGX.js → publish-RXFUYSW3.js} +2 -2
  45. package/dist/chunks/query-ILJJL3BZ.js +391 -0
  46. package/dist/chunks/{reorder-J6OONT76.js → reorder-GBCOPZT4.js} +2 -2
  47. package/dist/chunks/{restore-3ME4ZHFW.js → restore-YK5DGGRX.js} +2 -2
  48. package/dist/chunks/{rm-XOUHC6CU.js → rm-FRZMXB2W.js} +3 -3
  49. package/dist/chunks/{rm-63AGQFIQ.js → rm-LK6P7XTA.js} +2 -2
  50. package/dist/chunks/{rm-EHEJRXQJ.js → rm-O474MI5C.js} +2 -2
  51. package/dist/chunks/{rule-inspect-3PRCEXIB.js → rule-inspect-YEZGYINZ.js} +3 -3
  52. package/dist/chunks/{rules-UBSIW5ZQ.js → rules-MZ2MP6KJ.js} +6 -6
  53. package/dist/chunks/{schema-I4SXEWLS.js → schema-FR6CCQIZ.js} +5 -5
  54. package/dist/chunks/{tags-HF2YOQ4V.js → tags-AKRTKFRV.js} +2 -2
  55. package/dist/chunks/{update-RRMAOQDP.js → update-W3CWQB2F.js} +3 -3
  56. package/dist/commands/build/index.js +9 -9
  57. package/dist/commands/deploy/index.js +9 -9
  58. package/dist/commands/dev/index.js +7 -7
  59. package/dist/commands/env/index.js +4 -4
  60. package/dist/commands/link/index.js +6 -6
  61. package/dist/commands/list/index.js +2 -2
  62. package/dist/commands-bulk.js +411 -48
  63. package/dist/index.js +7 -7
  64. package/dist/vc.js +6 -1
  65. package/dist/version.mjs +1 -1
  66. package/package.json +86 -6
  67. package/dist/chunks/chunk-A3NYPUKZ.js +0 -17
@@ -5,51 +5,19 @@ const require = __createRequire(import.meta.url);
5
5
  const __filename = __fileURLToPath(import.meta.url);
6
6
  const __dirname = __dirname_(__filename);
7
7
  import {
8
- fetchMetricDetailOrExit,
9
- formatErrorJson,
10
- formatQueryJson,
11
- getDefaultAggregation,
12
8
  getResolvedOrderMetadata,
13
9
  getRollupColumnName,
14
- handleApiError
15
- } from "./chunk-4Z5LC2CI.js";
16
- import {
17
10
  indent_default
18
- } from "./chunk-A3NYPUKZ.js";
19
- import {
20
- resolveTimeRange,
21
- validateAllProjectMutualExclusivity
22
- } from "./chunk-BUZRVER7.js";
23
- import {
24
- validateJsonOutput
25
- } from "./chunk-XPKWKPWA.js";
11
+ } from "./chunk-Z7NPYIZ6.js";
26
12
  import {
27
- metricsCommand
28
- } from "./chunk-4G6QZSBL.js";
13
+ elapsed
14
+ } from "./chunk-VXYGCOKL.js";
29
15
  import {
30
16
  table
31
17
  } from "./chunk-NZRWTCRM.js";
32
18
  import {
33
- getLinkedProject,
34
- getProjectByNameOrId,
35
- getScope
36
- } from "./chunk-HZAINEXG.js";
37
- import "./chunk-UDWRZXIT.js";
38
- import "./chunk-ECCWJHC6.js";
39
- import {
40
- parseArguments,
41
- printError
19
+ require_strip_ansi
42
20
  } from "./chunk-SZXT3PDQ.js";
43
- import {
44
- ProjectNotFound,
45
- getFlagsSpecification,
46
- isAPIError
47
- } from "./chunk-KSSNLCL4.js";
48
- import "./chunk-P4QNYOFB.js";
49
- import "./chunk-52QYYTM5.js";
50
- import {
51
- output_manager_default
52
- } from "./chunk-OX7KI3LF.js";
53
21
  import {
54
22
  require_ms
55
23
  } from "./chunk-GGP5R3FU.js";
@@ -60,52 +28,6 @@ import {
60
28
  __toESM
61
29
  } from "./chunk-TZ2YI2VH.js";
62
30
 
63
- // src/commands/metrics/validation.ts
64
- function validateMutualExclusivity(all, project) {
65
- return validateAllProjectMutualExclusivity(all, project);
66
- }
67
- function validateRequiredMetric(metric) {
68
- if (metric) {
69
- return { valid: true, value: metric };
70
- }
71
- return {
72
- valid: false,
73
- code: "MISSING_METRIC",
74
- message: "Missing required metric. Specify the metric to query.\n\nRun 'vercel metrics schema' to see available metrics."
75
- };
76
- }
77
- function validateOrderDirection(orderDirection) {
78
- if (orderDirection === void 0) {
79
- return { valid: true, value: void 0 };
80
- }
81
- if (orderDirection === "asc" || orderDirection === "desc") {
82
- return { valid: true, value: orderDirection };
83
- }
84
- return {
85
- valid: false,
86
- code: "INVALID_ORDER",
87
- message: `Invalid order "${orderDirection}". Use "asc" or "desc".`,
88
- allowedValues: ["asc", "desc"]
89
- };
90
- }
91
- function validateOrderBy(orderBy) {
92
- if (orderBy === void 0) {
93
- return { valid: true, value: void 0 };
94
- }
95
- if (orderBy === "value" || orderBy === "count") {
96
- return { valid: true, value: orderBy };
97
- }
98
- return {
99
- valid: false,
100
- code: "INVALID_ORDER_BY",
101
- message: `Invalid order-by "${orderBy}". Use "value" or "count".`,
102
- allowedValues: ["value", "count"]
103
- };
104
- }
105
-
106
- // src/commands/metrics/text-output.ts
107
- var import_chalk = __toESM(require_source(), 1);
108
-
109
31
  // src/commands/metrics/time-utils.ts
110
32
  var import_ms = __toESM(require_ms(), 1);
111
33
  var MINUTE_MS = 60 * 1e3;
@@ -199,6 +121,8 @@ function toGranularityMsFromDuration(duration) {
199
121
  }
200
122
 
201
123
  // src/commands/metrics/text-output.ts
124
+ var import_chalk = __toESM(require_source(), 1);
125
+ var import_strip_ansi = __toESM(require_strip_ansi(), 1);
202
126
  var GROUP_KEY_DELIMITER = "";
203
127
  var MAX_SPARKLINE_LENGTH = 120;
204
128
  var COUNT_UNITS = /* @__PURE__ */ new Set(["count", "usd", "us dollars", "dollars"]);
@@ -243,6 +167,15 @@ function formatPeriodBound(input) {
243
167
  }
244
168
  return formatHumanMinute(date);
245
169
  }
170
+ function formatPeriodSpan(startInput, endInput) {
171
+ const start = Date.parse(startInput);
172
+ const end = Date.parse(endInput);
173
+ const durationMs = end - start;
174
+ if (!Number.isFinite(durationMs) || durationMs <= 0) {
175
+ return null;
176
+ }
177
+ return elapsed(durationMs);
178
+ }
246
179
  function formatGranularity(granularity) {
247
180
  if ("minutes" in granularity) {
248
181
  return `${granularity.minutes}m`;
@@ -511,12 +444,13 @@ function computeGroupStats(points) {
511
444
  };
512
445
  }
513
446
  var MAX_GROUP_VALUE_LENGTH = 60;
514
- function ellipsizeMiddle(str, maxLength) {
515
- if (str.length <= maxLength)
447
+ function ellipsizeMiddle(str, maxLength, useVisibleLength = false) {
448
+ const comparable = useVisibleLength ? (0, import_strip_ansi.default)(str) : str;
449
+ if (comparable.length <= maxLength)
516
450
  return str;
517
451
  const endLength = Math.floor((maxLength - 1) / 2);
518
452
  const startLength = maxLength - 1 - endLength;
519
- return `${str.slice(0, startLength)}\u2026${str.slice(str.length - endLength)}`;
453
+ return `${comparable.slice(0, startLength)}\u2026${comparable.slice(comparable.length - endLength)}`;
520
454
  }
521
455
  function downsample(values, maxLen) {
522
456
  if (maxLen <= 0) {
@@ -570,17 +504,21 @@ function generateSparkline(values) {
570
504
  }).join("");
571
505
  }
572
506
  function formatMetadataHeader(opts) {
573
- const rows = [
574
- {
507
+ const periodSpan = opts.compact ? formatPeriodSpan(opts.periodStart, opts.periodEnd) : null;
508
+ const rows = [];
509
+ if (!opts.compact) {
510
+ rows.push({
575
511
  key: "Metric",
576
512
  value: `${opts.metric} ${opts.aggregation}`
577
- },
513
+ });
514
+ }
515
+ rows.push(
578
516
  {
579
517
  // Period bounds are always UTC; annotate them so the boundary is
580
518
  // unambiguous when the Interval below reports a different
581
519
  // --bucket-timezone.
582
520
  key: "Period",
583
- value: `${formatPeriodBound(opts.periodStart)} to ${formatPeriodBound(opts.periodEnd)} (UTC)`
521
+ value: `${formatPeriodBound(opts.periodStart)} to ${formatPeriodBound(opts.periodEnd)} (UTC)${periodSpan ? ` ${periodSpan}` : ""}`
584
522
  },
585
523
  {
586
524
  // Period bounds are always UTC; the timezone only controls calendar
@@ -590,17 +528,17 @@ function formatMetadataHeader(opts) {
590
528
  key: "Interval",
591
529
  value: "days" in opts.granularity ? `${formatGranularity(opts.granularity)} (${opts.bucketTimezone ?? "UTC"})` : formatGranularity(opts.granularity)
592
530
  }
593
- ];
531
+ );
594
532
  if (typeof opts.periodUnique === "number") {
595
533
  rows.push({
596
534
  key: "Unique (period)",
597
535
  value: formatCount(opts.periodUnique)
598
536
  });
599
537
  }
600
- if (opts.filter) {
538
+ if (!opts.compact && opts.filter) {
601
539
  rows.push({ key: "Filter", value: opts.filter });
602
540
  }
603
- if (opts.orderBy && opts.orderDirection) {
541
+ if (!opts.compact && opts.orderBy && opts.orderDirection) {
604
542
  rows.push({
605
543
  key: "Order By",
606
544
  value: `${opts.orderBy} ${opts.orderDirection}${opts.orderBy === "count" ? " (default)" : ""}`
@@ -620,7 +558,7 @@ function formatMetadataHeader(opts) {
620
558
  if (opts.unit && normalizeUnit(opts.unit) !== "count") {
621
559
  rows.push({ key: "Units", value: formatUnitLabel(opts.unit) });
622
560
  }
623
- if (typeof opts.groupCount === "number") {
561
+ if (!opts.compact && typeof opts.groupCount === "number") {
624
562
  rows.push({ key: "Groups", value: String(opts.groupCount) });
625
563
  }
626
564
  return rows.map((row) => `> ${import_chalk.default.gray(`${row.key}:`)} ${row.value}`).join("\n");
@@ -631,7 +569,7 @@ function formatSummaryTable(opts) {
631
569
  const rows = [header.map((name) => import_chalk.default.bold(import_chalk.default.cyan(name)))];
632
570
  for (const row of opts.rows) {
633
571
  const nextRow = row.groupValues.map(
634
- (v) => ellipsizeMiddle(v, MAX_GROUP_VALUE_LENGTH)
572
+ (v) => ellipsizeMiddle(v, MAX_GROUP_VALUE_LENGTH, opts.ansiAwareGroupValues)
635
573
  );
636
574
  if (row.stats.allMissing) {
637
575
  nextRow.push(...statColumns.map(() => "--"));
@@ -664,38 +602,33 @@ function formatSummaryTable(opts) {
664
602
  2
665
603
  );
666
604
  }
667
- function formatSparklineSection(groupRows, sparklines, groupByFields) {
668
- const lines = ["sparklines:"];
605
+ function formatSparklineSection(groupRows, sparklines, groupByFields, compact = false) {
669
606
  if (groupRows.length === 0) {
670
607
  const sparkline = sparklines[0];
671
- if (sparkline) {
672
- lines.push(indent_default(sparkline, 2));
673
- }
674
- return lines.join("\n");
608
+ const chart2 = sparkline ? indent_default(sparkline, 2) : "";
609
+ return compact ? chart2 : ["sparklines:", chart2].filter(Boolean).join("\n");
675
610
  }
676
- const rowsWithSparklines = groupRows.map((groupValues, index) => ({
677
- groupValues,
678
- sparkline: sparklines[index] ?? ""
679
- }));
611
+ const header = [...groupByFields, compact ? "" : "sparkline"];
680
612
  const rows = [
681
- [...groupByFields, "sparkline"].map((name) => import_chalk.default.bold(import_chalk.default.cyan(name))),
682
- ...rowsWithSparklines.map(({ groupValues, sparkline }) => [
683
- ...groupValues.map((v) => ellipsizeMiddle(v, MAX_GROUP_VALUE_LENGTH)),
684
- sparkline
613
+ header.map((name) => import_chalk.default.bold(import_chalk.default.cyan(name))),
614
+ ...groupRows.map((groupValues, index) => [
615
+ ...groupValues.map(
616
+ (v) => ellipsizeMiddle(v, MAX_GROUP_VALUE_LENGTH, compact)
617
+ ),
618
+ sparklines[index] ?? ""
685
619
  ])
686
620
  ];
687
621
  const align = groupByFields.map(() => "r");
688
622
  align.push("l");
689
- lines.push(
690
- indent_default(
691
- table(rows, {
692
- align,
693
- hsep: 2
694
- }),
695
- 2
696
- )
623
+ const chart = indent_default(
624
+ table(rows, {
625
+ align,
626
+ hsep: 2
627
+ }),
628
+ 2
697
629
  );
698
- return lines.join("\n");
630
+ return compact ? chart : `sparklines:
631
+ ${chart}`;
699
632
  }
700
633
  function getEffectiveDisplay(baseUnit, aggregation) {
701
634
  if (isAggregationWithDimension(aggregation)) {
@@ -755,7 +688,8 @@ function formatText(response, opts) {
755
688
  projectName: opts.projectName,
756
689
  teamName: opts.teamName,
757
690
  unit: displayUnit,
758
- groupCount: opts.groupBy.length > 0 ? groups.length : void 0
691
+ groupCount: opts.groupBy.length > 0 ? groups.length : void 0,
692
+ compact: opts.presentation?.compact
759
693
  });
760
694
  if (groups.length === 0) {
761
695
  return `${metadata}
@@ -770,11 +704,15 @@ No data found for this period.
770
704
  const points = series.get(key) ?? [];
771
705
  const values = points.map((point) => point.value);
772
706
  const currentGroupValues = groupValues.get(key) ?? [];
707
+ const displayGroupValues = currentGroupValues.map((value, index) => {
708
+ const field = opts.groupBy[index];
709
+ return opts.presentation?.formatGroupValue?.(field, value) ?? value;
710
+ });
773
711
  summaryRows.push({
774
- groupValues: currentGroupValues,
712
+ groupValues: displayGroupValues,
775
713
  stats: computeGroupStats(points)
776
714
  });
777
- groupRows.push(currentGroupValues);
715
+ groupRows.push(displayGroupValues);
778
716
  sparklineRows.push(generateSparkline(values));
779
717
  }
780
718
  const summaryTable = formatSummaryTable({
@@ -783,307 +721,23 @@ No data found for this period.
783
721
  measureType,
784
722
  aggregation: opts.aggregation,
785
723
  periodStart: new Date(opts.periodStart),
786
- periodEnd: new Date(opts.periodEnd)
724
+ periodEnd: new Date(opts.periodEnd),
725
+ ansiAwareGroupValues: opts.presentation?.compact
787
726
  });
788
727
  const groupedOutput = opts.groupBy.length > 0;
789
728
  const sparklineSection = formatSparklineSection(
790
729
  groupedOutput ? groupRows : [],
791
730
  sparklineRows,
792
- opts.groupBy
731
+ opts.groupBy,
732
+ opts.presentation?.compact
793
733
  );
794
734
  const sections = [metadata, summaryTable, sparklineSection];
795
735
  return `${sections.join("\n\n")}
796
736
  `;
797
737
  }
798
738
 
799
- // src/commands/metrics/query.ts
800
- function handleValidationError(result, jsonOutput, client) {
801
- if (jsonOutput) {
802
- client.stdout.write(
803
- formatErrorJson(result.code, result.message, result.allowedValues)
804
- );
805
- } else {
806
- output_manager_default.error(result.message);
807
- if (result.allowedValues && result.allowedValues.length > 0) {
808
- output_manager_default.print(`
809
- Available values: ${result.allowedValues.join(", ")}
810
- `);
811
- }
812
- }
813
- return 1;
814
- }
815
- var PRODUCTION_ENVIRONMENT_FILTER = "environment eq 'production'";
816
- function combineFilters(filters, prod) {
817
- const nonEmptyFilters = [
818
- ...filters?.filter((filter) => filter.length > 0) ?? [],
819
- ...prod ? [PRODUCTION_ENVIRONMENT_FILTER] : []
820
- ];
821
- if (nonEmptyFilters.length === 0) {
822
- return void 0;
823
- }
824
- if (nonEmptyFilters.length === 1) {
825
- return nonEmptyFilters[0];
826
- }
827
- return nonEmptyFilters.map((filter) => `(${filter})`).join(" and ");
828
- }
829
- function getRequestOrderBy(metric, aggregation, orderBy) {
830
- return orderBy === "value" ? getRollupColumnName(metric, aggregation) : void 0;
831
- }
832
- async function resolveQueryScope(client, opts) {
833
- if (opts.project || opts.all) {
834
- const { team } = await getScope(client);
835
- if (!team) {
836
- const errMsg = "No team context found. Run `vercel switch` to select a team, or use `vercel link` in a project directory.";
837
- if (opts.jsonOutput) {
838
- client.stdout.write(formatErrorJson("NO_TEAM", errMsg));
839
- } else {
840
- output_manager_default.error(errMsg);
841
- }
842
- return 1;
843
- }
844
- if (opts.all) {
845
- return {
846
- scope: { type: "owner", ownerId: team.id },
847
- accountId: team.id,
848
- teamName: team.slug
849
- };
850
- }
851
- const project = await getProjectByNameOrId(client, opts.project, team.id);
852
- if (project instanceof ProjectNotFound) {
853
- const errMsg = `Project "${opts.project}" was not found in team "${team.slug}".`;
854
- if (opts.jsonOutput) {
855
- client.stdout.write(formatErrorJson("PROJECT_NOT_FOUND", errMsg));
856
- } else {
857
- output_manager_default.error(errMsg);
858
- }
859
- return 1;
860
- }
861
- return {
862
- scope: {
863
- type: "project",
864
- ownerId: team.id,
865
- projectIds: [project.id]
866
- },
867
- accountId: team.id,
868
- teamName: team.slug,
869
- projectName: project.name
870
- };
871
- }
872
- const linkedProject = await getLinkedProject(client);
873
- if (linkedProject.status === "error") {
874
- return linkedProject.exitCode;
875
- }
876
- if (linkedProject.status === "not_linked") {
877
- const errMsg = "No linked project found. Run `vercel link` to link a project, or use --project <name-or-id> or --all.";
878
- if (opts.jsonOutput) {
879
- client.stdout.write(formatErrorJson("NOT_LINKED", errMsg));
880
- } else {
881
- output_manager_default.error(errMsg);
882
- }
883
- return 1;
884
- }
885
- return {
886
- scope: {
887
- type: "project",
888
- ownerId: linkedProject.org.id,
889
- projectIds: [linkedProject.project.id]
890
- },
891
- accountId: linkedProject.org.id,
892
- teamName: linkedProject.org.slug,
893
- projectName: linkedProject.project.name
894
- };
895
- }
896
- async function query(client, telemetry) {
897
- let parsedArgs;
898
- const flagsSpecification = getFlagsSpecification(metricsCommand.options);
899
- try {
900
- parsedArgs = parseArguments(client.argv.slice(2), flagsSpecification);
901
- } catch (err) {
902
- printError(err);
903
- return 1;
904
- }
905
- const flags = parsedArgs.flags;
906
- const positionalArgs = parsedArgs.args.slice(1);
907
- const positionalMetric = positionalArgs[0] === "query" ? positionalArgs[1] : positionalArgs[0];
908
- const formatResult = validateJsonOutput(flags);
909
- if (!formatResult.valid) {
910
- output_manager_default.error(formatResult.error);
911
- return 1;
912
- }
913
- const jsonOutput = formatResult.jsonOutput;
914
- const metricFlag = positionalMetric;
915
- const aggregationFlag = flags["--aggregation"];
916
- const groupBy = flags["--group-by"] ?? [];
917
- const limit = flags["--limit"];
918
- const orderByInput = typeof flags["--order-by"] === "string" ? flags["--order-by"].trim().toLowerCase() : void 0;
919
- const orderInput = typeof flags["--order"] === "string" ? flags["--order"].trim().toLowerCase() : void 0;
920
- const filters = flags["--filter"];
921
- const prod = flags["--prod"];
922
- const filter = combineFilters(filters, prod);
923
- const since = flags["--since"];
924
- const until = flags["--until"];
925
- const granularity = flags["--granularity"];
926
- const bucketTimezone = flags["--bucket-timezone"]?.trim();
927
- const project = flags["--project"];
928
- const all = flags["--all"];
929
- telemetry.trackCliArgumentMetricId(metricFlag);
930
- telemetry.trackCliOptionAggregation(aggregationFlag);
931
- telemetry.trackCliOptionGroupBy(groupBy.length > 0 ? groupBy : void 0);
932
- telemetry.trackCliOptionLimit(limit);
933
- telemetry.trackCliOptionOrderBy(orderByInput);
934
- telemetry.trackCliOptionOrder(orderInput);
935
- telemetry.trackCliOptionFilter(filters);
936
- telemetry.trackCliFlagProd(prod);
937
- telemetry.trackCliOptionSince(since);
938
- telemetry.trackCliOptionUntil(until);
939
- telemetry.trackCliOptionGranularity(granularity);
940
- telemetry.trackCliOptionBucketTimezone(bucketTimezone);
941
- telemetry.trackCliOptionProject(project);
942
- telemetry.trackCliFlagAll(all);
943
- telemetry.trackCliOptionFormat(flags["--format"]);
944
- const orderByResult = validateOrderBy(orderByInput);
945
- if (!orderByResult.valid) {
946
- return handleValidationError(orderByResult, jsonOutput, client);
947
- }
948
- const orderByMode = orderByResult.value;
949
- const requiredMetric = validateRequiredMetric(metricFlag);
950
- if (!requiredMetric.valid) {
951
- return handleValidationError(requiredMetric, jsonOutput, client);
952
- }
953
- const metric = requiredMetric.value;
954
- const mutualResult = validateMutualExclusivity(all, project);
955
- if (!mutualResult.valid) {
956
- return handleValidationError(mutualResult, jsonOutput, client);
957
- }
958
- const orderDirectionResult = validateOrderDirection(orderInput);
959
- if (!orderDirectionResult.valid) {
960
- return handleValidationError(orderDirectionResult, jsonOutput, client);
961
- }
962
- const orderDirection = orderDirectionResult.value;
963
- const scopeResult = await resolveQueryScope(client, {
964
- project,
965
- all,
966
- jsonOutput
967
- });
968
- if (typeof scopeResult === "number") {
969
- return scopeResult;
970
- }
971
- const { scope, accountId, teamName, projectName } = scopeResult;
972
- const detailOrExitCode = await fetchMetricDetailOrExit(
973
- client,
974
- accountId,
975
- metric,
976
- jsonOutput
977
- );
978
- if (typeof detailOrExitCode === "number") {
979
- return detailOrExitCode;
980
- }
981
- const aggregationInput = aggregationFlag ?? getDefaultAggregation(detailOrExitCode, metric) ?? "sum";
982
- const aggregation = aggregationInput;
983
- const orderBy = getRequestOrderBy(metric, aggregation, orderByMode);
984
- let startTime;
985
- let endTime;
986
- try {
987
- ({ startTime, endTime } = resolveTimeRange(since, until));
988
- } catch (err) {
989
- const errMsg = err instanceof Error ? err.message : String(err);
990
- if (jsonOutput) {
991
- client.stdout.write(formatErrorJson("INVALID_TIME", errMsg));
992
- } else {
993
- output_manager_default.error(errMsg);
994
- }
995
- return 1;
996
- }
997
- const rangeMs = endTime.getTime() - startTime.getTime();
998
- const granResult = computeGranularity(rangeMs, granularity);
999
- if (!jsonOutput && granResult.adjusted && granResult.notice) {
1000
- output_manager_default.log(`Notice: ${granResult.notice}`);
1001
- }
1002
- const body = {
1003
- scope,
1004
- metric,
1005
- aggregation,
1006
- startTime: startTime.toISOString(),
1007
- endTime: endTime.toISOString(),
1008
- granularity: granResult.duration,
1009
- ...bucketTimezone ? { bucketTimezone } : {},
1010
- ...groupBy.length > 0 ? { groupBy } : {},
1011
- ...filter ? { filter } : {},
1012
- limit: limit ?? 10,
1013
- ...orderBy ? { orderBy } : {},
1014
- ...orderDirection ? { orderDirection } : {}
1015
- };
1016
- if (!jsonOutput) {
1017
- output_manager_default.spinner("Querying metrics...");
1018
- }
1019
- let response;
1020
- try {
1021
- response = await client.fetch(
1022
- "/v2/observability/query",
1023
- {
1024
- method: "POST",
1025
- body: JSON.stringify(body),
1026
- headers: { "Content-Type": "application/json" },
1027
- accountId,
1028
- bailOn429: true
1029
- }
1030
- );
1031
- } catch (err) {
1032
- if (isAPIError(err)) {
1033
- return handleApiError(err, jsonOutput, client);
1034
- }
1035
- const errMsg = err instanceof Error ? err.message : String(err);
1036
- if (jsonOutput) {
1037
- client.stdout.write(formatErrorJson("NETWORK_ERROR", errMsg));
1038
- } else {
1039
- output_manager_default.error(errMsg);
1040
- }
1041
- return 1;
1042
- } finally {
1043
- if (!jsonOutput) {
1044
- output_manager_default.stopSpinner();
1045
- }
1046
- }
1047
- if (jsonOutput) {
1048
- client.stdout.write(
1049
- formatQueryJson(
1050
- {
1051
- metric,
1052
- aggregation,
1053
- groupBy,
1054
- filter,
1055
- startTime: startTime.toISOString(),
1056
- endTime: endTime.toISOString(),
1057
- granularity: granResult.duration,
1058
- ...bucketTimezone ? { bucketTimezone } : {},
1059
- ...orderByMode ? { orderBy: orderByMode } : {},
1060
- ...orderDirection ? { orderDirection } : {}
1061
- },
1062
- response
1063
- )
1064
- );
1065
- } else {
1066
- client.stdout.write(
1067
- formatText(response, {
1068
- metric,
1069
- metricUnit: detailOrExitCode.find((item) => item.id === metric)?.unit ?? "count",
1070
- aggregation,
1071
- groupBy,
1072
- filter,
1073
- scope,
1074
- projectName,
1075
- teamName,
1076
- periodStart: startTime.toISOString(),
1077
- periodEnd: endTime.toISOString(),
1078
- granularity: granResult.duration,
1079
- bucketTimezone,
1080
- orderBy: orderByMode,
1081
- orderDirection
1082
- })
1083
- );
1084
- }
1085
- return 0;
1086
- }
1087
739
  export {
1088
- query as default
740
+ computeGranularity,
741
+ toGranularityMsFromDuration,
742
+ formatText
1089
743
  };
@@ -6,7 +6,7 @@ const __filename = __fileURLToPath(import.meta.url);
6
6
  const __dirname = __dirname_(__filename);
7
7
  import {
8
8
  resolveProjectContext
9
- } from "./chunk-HZAINEXG.js";
9
+ } from "./chunk-GLAHGVBS.js";
10
10
  import {
11
11
  AGENT_REASON,
12
12
  AGENT_STATUS,
@@ -56898,7 +56898,8 @@ async function resolveProjectContext({
56898
56898
  client,
56899
56899
  cwd = client.cwd,
56900
56900
  projectNameOrId,
56901
- commandName = ""
56901
+ commandName = "",
56902
+ projectNotFoundHandling = "report"
56902
56903
  }) {
56903
56904
  const context = await getLinkedProject(client, {
56904
56905
  cwd,
@@ -56906,7 +56907,7 @@ async function resolveProjectContext({
56906
56907
  projectNameIsExplicit: Boolean(projectNameOrId),
56907
56908
  scopeIsExplicit: detectExplicitScope(client)
56908
56909
  });
56909
- if (context.status === "not_linked" && projectNameOrId) {
56910
+ if (context.status === "not_linked" && projectNameOrId && projectNotFoundHandling === "report") {
56910
56911
  await printProjectNotFoundError(
56911
56912
  client,
56912
56913
  projectNameOrId,
@@ -57709,6 +57710,9 @@ async function pullEnvRecordsForEnvPull(client, pullId, source, options) {
57709
57710
  userId: void 0,
57710
57711
  expiresAt: Math.floor(Date.now() / 1e3) + tokens.expires_in
57711
57712
  });
57713
+ if (tokens.refresh_token) {
57714
+ client.updateAuthConfig({ refreshToken: tokens.refresh_token });
57715
+ }
57712
57716
  client.persistAuthConfig();
57713
57717
  output_manager_default.spinner("Downloading");
57714
57718
  return await pullEnvRecords(client, pullId, source, options);
@@ -6,14 +6,14 @@ const __filename = __fileURLToPath(import.meta.url);
6
6
  const __dirname = __dirname_(__filename);
7
7
  import {
8
8
  setupAndLink
9
- } from "./chunk-WQN52QMS.js";
9
+ } from "./chunk-MQRHJEBS.js";
10
10
  import {
11
11
  detectExplicitScope,
12
12
  getLinkedProject,
13
13
  param,
14
14
  printProjectNotFoundError,
15
15
  resolveProjectCwd
16
- } from "./chunk-HZAINEXG.js";
16
+ } from "./chunk-GLAHGVBS.js";
17
17
  import {
18
18
  buildCommandWithYes,
19
19
  outputActionRequired