@carlonicora/nextjs-jsonapi 1.143.1 → 2.0.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.
@@ -26,7 +26,7 @@
26
26
 
27
27
 
28
28
 
29
- var _chunkF6PZZ4KIjs = require('../../chunk-F6PZZ4KI.js');
29
+ var _chunkR666YQGQjs = require('../../chunk-R666YQGQ.js');
30
30
  require('../../chunk-UXJAS6C5.js');
31
31
 
32
32
 
@@ -64,7 +64,7 @@ function TokenUsageAdminFilterBar({ granularity, companyId, metric, companies, o
64
64
  };
65
65
  return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex flex-wrap items-center gap-2", children: [
66
66
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
67
- _chunkF6PZZ4KIjs.DateRangeSelector,
67
+ _chunkR666YQGQjs.DateRangeSelector,
68
68
  {
69
69
  onDateChange: (range) => {
70
70
  if (!_optionalChain([range, 'optionalAccess', _ => _.from]) || !_optionalChain([range, 'optionalAccess', _2 => _2.to])) return;
@@ -99,16 +99,16 @@ function TokenUsageAdminFilterBar({ granularity, companyId, metric, companies, o
99
99
  }
100
100
  ),
101
101
  /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
102
- _chunkF6PZZ4KIjs.Select,
102
+ _chunkR666YQGQjs.Select,
103
103
  {
104
104
  items: companyItems,
105
105
  value: _nullishCoalesce(companyId, () => ( ALL_COMPANIES)),
106
106
  onValueChange: (value) => onChange({ companyId: !value || value === ALL_COMPANIES ? void 0 : value }),
107
107
  children: [
108
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkF6PZZ4KIjs.SelectTrigger, { className: "w-56", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkF6PZZ4KIjs.SelectValue, { placeholder: t("token_usage.admin.all_companies") }) }),
109
- /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkF6PZZ4KIjs.SelectContent, { children: [
110
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkF6PZZ4KIjs.SelectItem, { value: ALL_COMPANIES, children: t("token_usage.admin.all_companies") }),
111
- companies.map((company) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkF6PZZ4KIjs.SelectItem, { value: company.id, children: company.label }, company.id))
108
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkR666YQGQjs.SelectTrigger, { className: "w-56", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkR666YQGQjs.SelectValue, { placeholder: t("token_usage.admin.all_companies") }) }),
109
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkR666YQGQjs.SelectContent, { children: [
110
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkR666YQGQjs.SelectItem, { value: ALL_COMPANIES, children: t("token_usage.admin.all_companies") }),
111
+ companies.map((company) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkR666YQGQjs.SelectItem, { value: company.id, children: company.label }, company.id))
112
112
  ] })
113
113
  ]
114
114
  }
@@ -131,7 +131,7 @@ function Segmented({
131
131
  children: options.map((option) => {
132
132
  const selected = option.value === value;
133
133
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
134
- _chunkF6PZZ4KIjs.Button,
134
+ _chunkR666YQGQjs.Button,
135
135
  {
136
136
  type: "button",
137
137
  size: "sm",
@@ -212,7 +212,7 @@ var TokenUsageAdminProvider = /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void
212
212
  topN = DEFAULT_TOP_N
213
213
  }) => {
214
214
  const t = _nextintl.useTranslations.call(void 0, );
215
- const generateUrl = _chunkF6PZZ4KIjs.usePageUrlGenerator.call(void 0, );
215
+ const generateUrl = _chunkR666YQGQjs.usePageUrlGenerator.call(void 0, );
216
216
  const [filters, setFilterState] = _react.useState.call(void 0, () => {
217
217
  const range = defaultRange();
218
218
  return {
@@ -330,7 +330,7 @@ var TokenUsageAdminProvider = /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void
330
330
  error
331
331
  ]
332
332
  );
333
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkF6PZZ4KIjs.SharedProvider, { value: { breadcrumbs: breadcrumb(), title: title() }, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, TokenUsageAdminContext.Provider, { value: contextValue, children }) });
333
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkR666YQGQjs.SharedProvider, { value: { breadcrumbs: breadcrumb(), title: title() }, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, TokenUsageAdminContext.Provider, { value: contextValue, children }) });
334
334
  }, "TokenUsageAdminProvider");
335
335
  var useTokenUsageAdmin = /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void 0, () => {
336
336
  const ctx = _react.useContext.call(void 0, TokenUsageAdminContext);
@@ -458,7 +458,7 @@ function LeadTile({
458
458
  delta,
459
459
  previousLabel
460
460
  }) {
461
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkF6PZZ4KIjs.Card, { "data-testid": testId, children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkF6PZZ4KIjs.CardContent, { className: "grid gap-1", children: [
461
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkR666YQGQjs.Card, { "data-testid": testId, children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkR666YQGQjs.CardContent, { className: "grid gap-1", children: [
462
462
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "text-muted-foreground text-xs", children: label }),
463
463
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "text-primary text-xl font-semibold tabular-nums", children: value }),
464
464
  /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "span", { className: "flex items-center gap-1", children: [
@@ -474,7 +474,7 @@ function SupportingTile({
474
474
  value,
475
475
  delta
476
476
  }) {
477
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkF6PZZ4KIjs.Card, { "data-testid": testId, size: "sm", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkF6PZZ4KIjs.CardContent, { className: "grid gap-1", children: [
477
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkR666YQGQjs.Card, { "data-testid": testId, size: "sm", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkR666YQGQjs.CardContent, { className: "grid gap-1", children: [
478
478
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "text-muted-foreground text-xs", children: label }),
479
479
  /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "span", { className: "flex items-center gap-2", children: [
480
480
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "text-sm font-medium tabular-nums", children: value }),
@@ -566,8 +566,8 @@ function TokenUsageBreakdownTable({ rows, metric }) {
566
566
  // The package's <Table> wraps itself in an `overflow-x-clip` container, which
567
567
  // would swallow the overflow before this scroller ever saw it — hence the
568
568
  // child override. Wide metric tables must scroll, never widen the page.
569
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "overflow-x-auto [&_[data-slot=table-container]]:overflow-x-visible", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkF6PZZ4KIjs.Table, { children: [
570
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkF6PZZ4KIjs.TableHeader, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkF6PZZ4KIjs.TableRow, { children: columns.map((column) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkF6PZZ4KIjs.TableHead, { className: _chunkDS4IBFWAjs.cn.call(void 0, column.numeric && "text-right"), children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
569
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "overflow-x-auto [&_[data-slot=table-container]]:overflow-x-visible", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkR666YQGQjs.Table, { children: [
570
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkR666YQGQjs.TableHeader, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkR666YQGQjs.TableRow, { children: columns.map((column) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkR666YQGQjs.TableHead, { className: _chunkDS4IBFWAjs.cn.call(void 0, column.numeric && "text-right"), children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
571
571
  "button",
572
572
  {
573
573
  type: "button",
@@ -582,20 +582,20 @@ function TokenUsageBreakdownTable({ rows, metric }) {
582
582
  ]
583
583
  }
584
584
  ) }, column.key)) }) }),
585
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkF6PZZ4KIjs.TableBody, { children: sortedRows.map((row) => {
585
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkR666YQGQjs.TableBody, { children: sortedRows.map((row) => {
586
586
  const value = metricValue(row, metric);
587
587
  const share = total > 0 ? value / total * 100 : 0;
588
- return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkF6PZZ4KIjs.TableRow, { "data-testid": `breakdown-row-${row.id}`, children: [
589
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkF6PZZ4KIjs.TableCell, { className: "text-xs", children: row.id === "other" ? t("token_usage.admin.other") : row.label }),
590
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkF6PZZ4KIjs.TableCell, { className: "text-muted-foreground text-xs", children: _nullishCoalesce(row.sublabel, () => ( "")) }),
591
- showActiveUsers && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkF6PZZ4KIjs.TableCell, { className: "text-right text-xs tabular-nums", children: row.activeUsers === void 0 ? "" : formatDecimal(row.activeUsers, 0) }),
592
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkF6PZZ4KIjs.TableCell, { className: "text-right text-xs tabular-nums", children: formatDecimal(row.calls, 0) }),
593
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkF6PZZ4KIjs.TableCell, { className: "text-right text-xs tabular-nums", children: formatDecimal(row.tokensIn, 0) }),
594
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkF6PZZ4KIjs.TableCell, { className: "text-right text-xs tabular-nums", children: formatDecimal(row.tokensOut, 0) }),
595
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkF6PZZ4KIjs.TableCell, { className: "text-right text-xs tabular-nums", children: formatPercent(cacheHitPercentage(row.cached, row.tokensIn)) }),
596
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkF6PZZ4KIjs.TableCell, { className: "text-right text-xs tabular-nums", children: formatMetricValue(row.cost, "cost") }),
597
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkF6PZZ4KIjs.TableCell, { className: "text-right text-xs tabular-nums", children: formatMetricValue(row.credits, "credits") }),
598
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkF6PZZ4KIjs.TableCell, { className: "text-right text-xs tabular-nums", children: formatPercent(share) })
588
+ return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkR666YQGQjs.TableRow, { "data-testid": `breakdown-row-${row.id}`, children: [
589
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkR666YQGQjs.TableCell, { className: "text-xs", children: row.id === "other" ? t("token_usage.admin.other") : row.label }),
590
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkR666YQGQjs.TableCell, { className: "text-muted-foreground text-xs", children: _nullishCoalesce(row.sublabel, () => ( "")) }),
591
+ showActiveUsers && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkR666YQGQjs.TableCell, { className: "text-right text-xs tabular-nums", children: row.activeUsers === void 0 ? "" : formatDecimal(row.activeUsers, 0) }),
592
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkR666YQGQjs.TableCell, { className: "text-right text-xs tabular-nums", children: formatDecimal(row.calls, 0) }),
593
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkR666YQGQjs.TableCell, { className: "text-right text-xs tabular-nums", children: formatDecimal(row.tokensIn, 0) }),
594
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkR666YQGQjs.TableCell, { className: "text-right text-xs tabular-nums", children: formatDecimal(row.tokensOut, 0) }),
595
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkR666YQGQjs.TableCell, { className: "text-right text-xs tabular-nums", children: formatPercent(cacheHitPercentage(row.cached, row.tokensIn)) }),
596
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkR666YQGQjs.TableCell, { className: "text-right text-xs tabular-nums", children: formatMetricValue(row.cost, "cost") }),
597
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkR666YQGQjs.TableCell, { className: "text-right text-xs tabular-nums", children: formatMetricValue(row.credits, "credits") }),
598
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkR666YQGQjs.TableCell, { className: "text-right text-xs tabular-nums", children: formatPercent(share) })
599
599
  ] }, row.id);
600
600
  }) })
601
601
  ] }) })
@@ -789,7 +789,7 @@ function TokenUsageTimelineChart({ rows, metric, stackBy, className }) {
789
789
  return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className, children: [
790
790
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "sr-only", "data-testid": "timeline-data", children: JSON.stringify(chartData) }),
791
791
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "sr-only", "data-testid": "timeline-series", children: JSON.stringify(seriesKeys) }),
792
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkF6PZZ4KIjs.ChartContainer, { config: chartConfig, className: "aspect-auto h-72 w-full", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _recharts.BarChart, { accessibilityLayer: true, data: chartData, margin: { top: 8, right: 8, bottom: 0, left: 0 }, children: [
792
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkR666YQGQjs.ChartContainer, { config: chartConfig, className: "aspect-auto h-72 w-full", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _recharts.BarChart, { accessibilityLayer: true, data: chartData, margin: { top: 8, right: 8, bottom: 0, left: 0 }, children: [
793
793
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _recharts.CartesianGrid, { vertical: false }),
794
794
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
795
795
  _recharts.XAxis,
@@ -813,17 +813,17 @@ function TokenUsageTimelineChart({ rows, metric, stackBy, className }) {
813
813
  }
814
814
  ),
815
815
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
816
- _chunkF6PZZ4KIjs.ChartTooltip,
816
+ _chunkR666YQGQjs.ChartTooltip,
817
817
  {
818
818
  content: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
819
- _chunkF6PZZ4KIjs.ChartTooltipContent,
819
+ _chunkR666YQGQjs.ChartTooltipContent,
820
820
  {
821
821
  labelFormatter: (value) => formatBucket.format(/* @__PURE__ */ new Date(`${String(value)}T00:00:00.000Z`))
822
822
  }
823
823
  )
824
824
  }
825
825
  ),
826
- seriesKeys.length >= 2 ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkF6PZZ4KIjs.ChartLegend, { content: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkF6PZZ4KIjs.ChartLegendContent, {}) }) : null,
826
+ seriesKeys.length >= 2 ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkR666YQGQjs.ChartLegend, { content: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkR666YQGQjs.ChartLegendContent, {}) }) : null,
827
827
  seriesKeys.map((series, index) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
828
828
  _recharts.Bar,
829
829
  {
@@ -869,19 +869,19 @@ function TokenUsageAdminContainer() {
869
869
  [t]
870
870
  );
871
871
  if (error) {
872
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkF6PZZ4KIjs.RoundPageContainer, { fullWidth: true, forceHeader: true, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "p-4", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkF6PZZ4KIjs.Card, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkF6PZZ4KIjs.CardContent, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "text-destructive text-xs/relaxed", children: error }) }) }) }) });
872
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkR666YQGQjs.RoundPageContainer, { fullWidth: true, forceHeader: true, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "p-4", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkR666YQGQjs.Card, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkR666YQGQjs.CardContent, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "text-destructive text-xs/relaxed", children: error }) }) }) }) });
873
873
  }
874
- if (isLoading) return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkF6PZZ4KIjs.RoundPageContainer, { fullWidth: true, forceHeader: true });
874
+ if (isLoading) return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkR666YQGQjs.RoundPageContainer, { fullWidth: true, forceHeader: true });
875
875
  const emptyLabel = t("token_usage.admin.no_data");
876
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkF6PZZ4KIjs.RoundPageContainer, { fullWidth: true, forceHeader: true, children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex w-full flex-col gap-4 p-4", children: [
876
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkR666YQGQjs.RoundPageContainer, { fullWidth: true, forceHeader: true, children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex w-full flex-col gap-4 p-4", children: [
877
877
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, TokenUsageAdminTiles, { summary, metric: filters.metric, singleCustomerMode }),
878
- /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkF6PZZ4KIjs.Card, { children: [
879
- /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkF6PZZ4KIjs.CardHeader, { children: [
880
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkF6PZZ4KIjs.CardTitle, { children: t("token_usage.admin.usage_over_time") }),
881
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkF6PZZ4KIjs.CardAction, { children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex items-center gap-2", children: [
878
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkR666YQGQjs.Card, { children: [
879
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkR666YQGQjs.CardHeader, { children: [
880
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkR666YQGQjs.CardTitle, { children: t("token_usage.admin.usage_over_time") }),
881
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkR666YQGQjs.CardAction, { children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex items-center gap-2", children: [
882
882
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "text-muted-foreground text-xs", children: t("token_usage.admin.stack_by") }),
883
883
  /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
884
- _chunkF6PZZ4KIjs.Select,
884
+ _chunkR666YQGQjs.Select,
885
885
  {
886
886
  items: stackByItems,
887
887
  value: filters.stackBy,
@@ -889,29 +889,29 @@ function TokenUsageAdminContainer() {
889
889
  if (value) setFilters({ stackBy: value });
890
890
  },
891
891
  children: [
892
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkF6PZZ4KIjs.SelectTrigger, { size: "sm", className: "w-36", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkF6PZZ4KIjs.SelectValue, {}) }),
893
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkF6PZZ4KIjs.SelectContent, { children: STACK_BY_VALUES.map((value) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkF6PZZ4KIjs.SelectItem, { value, children: stackByItems[value] }, value)) })
892
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkR666YQGQjs.SelectTrigger, { size: "sm", className: "w-36", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkR666YQGQjs.SelectValue, {}) }),
893
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkR666YQGQjs.SelectContent, { children: STACK_BY_VALUES.map((value) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkR666YQGQjs.SelectItem, { value, children: stackByItems[value] }, value)) })
894
894
  ]
895
895
  }
896
896
  )
897
897
  ] }) })
898
898
  ] }),
899
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkF6PZZ4KIjs.CardContent, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, TokenUsageTimelineChart, { rows: timeline, metric: filters.metric, stackBy: filters.stackBy }) })
899
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkR666YQGQjs.CardContent, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, TokenUsageTimelineChart, { rows: timeline, metric: filters.metric, stackBy: filters.stackBy }) })
900
900
  ] }),
901
901
  /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "grid gap-4 md:grid-cols-2", children: [
902
- /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkF6PZZ4KIjs.Card, { children: [
903
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkF6PZZ4KIjs.CardHeader, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkF6PZZ4KIjs.CardTitle, { children: t("token_usage.admin.by_company") }) }),
904
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkF6PZZ4KIjs.CardContent, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, TokenUsageRankedBar, { rows: byCompany, metric: filters.metric, emptyLabel }) })
902
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkR666YQGQjs.Card, { children: [
903
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkR666YQGQjs.CardHeader, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkR666YQGQjs.CardTitle, { children: t("token_usage.admin.by_company") }) }),
904
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkR666YQGQjs.CardContent, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, TokenUsageRankedBar, { rows: byCompany, metric: filters.metric, emptyLabel }) })
905
905
  ] }),
906
- /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkF6PZZ4KIjs.Card, { children: [
907
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkF6PZZ4KIjs.CardHeader, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkF6PZZ4KIjs.CardTitle, { children: t("token_usage.admin.by_user") }) }),
908
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkF6PZZ4KIjs.CardContent, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, TokenUsageRankedBar, { rows: byUser, metric: filters.metric, emptyLabel }) })
906
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkR666YQGQjs.Card, { children: [
907
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkR666YQGQjs.CardHeader, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkR666YQGQjs.CardTitle, { children: t("token_usage.admin.by_user") }) }),
908
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkR666YQGQjs.CardContent, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, TokenUsageRankedBar, { rows: byUser, metric: filters.metric, emptyLabel }) })
909
909
  ] })
910
910
  ] }),
911
911
  /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: _chunkDS4IBFWAjs.cn.call(void 0, "grid gap-4", !singleCustomerMode && "md:grid-cols-2"), children: [
912
- /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkF6PZZ4KIjs.Card, { children: [
913
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkF6PZZ4KIjs.CardHeader, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkF6PZZ4KIjs.CardTitle, { children: t("token_usage.admin.customer_by_operation") }) }),
914
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkF6PZZ4KIjs.CardContent, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
912
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkR666YQGQjs.Card, { children: [
913
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkR666YQGQjs.CardHeader, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkR666YQGQjs.CardTitle, { children: t("token_usage.admin.customer_by_operation") }) }),
914
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkR666YQGQjs.CardContent, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
915
915
  TokenUsageRankedBar,
916
916
  {
917
917
  rows: byCustomerOperation,
@@ -921,9 +921,9 @@ function TokenUsageAdminContainer() {
921
921
  }
922
922
  ) })
923
923
  ] }),
924
- !singleCustomerMode && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkF6PZZ4KIjs.Card, { children: [
925
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkF6PZZ4KIjs.CardHeader, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkF6PZZ4KIjs.CardTitle, { children: t("token_usage.admin.platform_by_operation") }) }),
926
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkF6PZZ4KIjs.CardContent, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
924
+ !singleCustomerMode && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkR666YQGQjs.Card, { children: [
925
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkR666YQGQjs.CardHeader, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkR666YQGQjs.CardTitle, { children: t("token_usage.admin.platform_by_operation") }) }),
926
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkR666YQGQjs.CardContent, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
927
927
  TokenUsageRankedBar,
928
928
  {
929
929
  rows: byOperation,
@@ -934,9 +934,9 @@ function TokenUsageAdminContainer() {
934
934
  ) })
935
935
  ] })
936
936
  ] }),
937
- /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkF6PZZ4KIjs.Card, { children: [
938
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkF6PZZ4KIjs.CardHeader, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkF6PZZ4KIjs.CardTitle, { children: t("token_usage.admin.detail") }) }),
939
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkF6PZZ4KIjs.CardContent, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, TokenUsageBreakdownTable, { rows: byCompany, metric: filters.metric }) })
937
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkR666YQGQjs.Card, { children: [
938
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkR666YQGQjs.CardHeader, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkR666YQGQjs.CardTitle, { children: t("token_usage.admin.detail") }) }),
939
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkR666YQGQjs.CardContent, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, TokenUsageBreakdownTable, { rows: byCompany, metric: filters.metric }) })
940
940
  ] })
941
941
  ] }) });
942
942
  }
@@ -26,7 +26,7 @@ import {
26
26
  TableHeader,
27
27
  TableRow,
28
28
  usePageUrlGenerator
29
- } from "../../chunk-UGSOBBZH.mjs";
29
+ } from "../../chunk-RVGBVVRD.mjs";
30
30
  import "../../chunk-HN5ED7OF.mjs";
31
31
  import {
32
32
  AbstractService,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@carlonicora/nextjs-jsonapi",
3
- "version": "1.143.1",
3
+ "version": "2.0.1",
4
4
  "description": "Next.js JSON:API client with server/client support and caching",
5
5
  "author": "Carlo Nicora",
6
6
  "license": "GPL-3.0-or-later",
@@ -175,6 +175,8 @@
175
175
  "@eslint/js": "^9.39.5",
176
176
  "@semantic-release/changelog": "^7.0.0",
177
177
  "@semantic-release/git": "^11.0.1",
178
+ "@stripe/react-stripe-js": "^6.8.0",
179
+ "@stripe/stripe-js": "^9.13.0",
178
180
  "@tanstack/react-table": "^8.21.3",
179
181
  "@testing-library/dom": "^10.4.1",
180
182
  "@testing-library/jest-dom": "^7.0.0",
@@ -197,11 +199,12 @@
197
199
  "eslint-plugin-prettier": "^5.5.6",
198
200
  "globals": "^17.8.0",
199
201
  "jsdom": "^30.0.1",
200
- "next": "^16.2.12",
202
+ "next": "16.3.0",
201
203
  "next-intl": "^4.13.4",
202
204
  "prettier": "^3.9.6",
203
205
  "react": "19.2.8",
204
206
  "react-dom": "19.2.8",
207
+ "react-hook-form": "7.83.0",
205
208
  "semantic-release": "^25.0.8",
206
209
  "tsup": "^8.5.1",
207
210
  "typescript": "^5.9.3",
@@ -0,0 +1,130 @@
1
+ import { describe, it, expect, beforeEach, vi } from "vitest";
2
+ import { renderHook } from "@testing-library/react";
3
+
4
+ // Mutable mocks the individual tests below configure per case, mirroring the
5
+ // vi.hoisted + vi.mock pattern used by NotificationContext.spec.tsx for the
6
+ // same CurrentUserContext dependency.
7
+ const userMock = vi.hoisted(() => ({ currentUser: null as any, company: null as any }));
8
+ const configMock = vi.hoisted(() => ({ stripeKey: "pk_test_123" as string | undefined }));
9
+
10
+ vi.mock("../../user/contexts/CurrentUserContext", () => ({
11
+ useCurrentUserContext: () => userMock,
12
+ }));
13
+
14
+ vi.mock("../../../roles", () => ({
15
+ isRolesConfigured: () => true,
16
+ getRoleId: () => ({ Administrator: "admin-role-id" }),
17
+ }));
18
+
19
+ vi.mock("../../../client/config", () => ({
20
+ getStripePublishableKey: () => configMock.stripeKey,
21
+ }));
22
+
23
+ import { useSubscriptionStatus } from "./useSubscriptionStatus";
24
+
25
+ describe("useSubscriptionStatus", () => {
26
+ beforeEach(() => {
27
+ userMock.currentUser = null;
28
+ userMock.company = null;
29
+ configMock.stripeKey = "pk_test_123";
30
+ });
31
+
32
+ it("reports loading while currentUser is still null", () => {
33
+ userMock.currentUser = null;
34
+
35
+ const { result } = renderHook(() => useSubscriptionStatus());
36
+
37
+ expect(result.current.status).toBe("loading");
38
+ expect(result.current.isBlocked).toBe(false);
39
+ });
40
+
41
+ it("treats a missing Stripe key as an active subscription", () => {
42
+ userMock.currentUser = { roles: [] };
43
+ configMock.stripeKey = undefined;
44
+
45
+ const { result } = renderHook(() => useSubscriptionStatus());
46
+
47
+ expect(result.current.status).toBe("active");
48
+ expect(result.current.isBlocked).toBe(false);
49
+ });
50
+
51
+ it("never blocks an administrator", () => {
52
+ userMock.currentUser = { roles: [{ id: "admin-role-id" }] };
53
+
54
+ const { result } = renderHook(() => useSubscriptionStatus());
55
+
56
+ expect(result.current.status).toBe("active");
57
+ expect(result.current.isBlocked).toBe(false);
58
+ });
59
+
60
+ it("does not block when company is undefined after loading (an authentication fault, not a billing one)", () => {
61
+ userMock.currentUser = { roles: [] };
62
+ userMock.company = undefined;
63
+
64
+ const { result } = renderHook(() => useSubscriptionStatus());
65
+
66
+ expect(result.current.status).toBe("expired");
67
+ expect(result.current.isBlocked).toBe(false);
68
+ });
69
+
70
+ it("is never blocked when the company has an active subscription", () => {
71
+ userMock.currentUser = { roles: [] };
72
+ userMock.company = { isActiveSubscription: true, createdAt: new Date() };
73
+
74
+ const { result } = renderHook(() => useSubscriptionStatus());
75
+
76
+ expect(result.current.status).toBe("active");
77
+ expect(result.current.isBlocked).toBe(false);
78
+ });
79
+
80
+ it("does NOT block an unsubscribed company that is still inside its trial window", () => {
81
+ userMock.currentUser = { roles: [] };
82
+ const createdAt = new Date();
83
+ createdAt.setDate(createdAt.getDate() - 1); // 1 day old — squarely inside the 14-day trial
84
+ userMock.company = { isActiveSubscription: false, createdAt };
85
+
86
+ const { result } = renderHook(() => useSubscriptionStatus());
87
+
88
+ // Regression guard. Blocking on the flag alone locked a zero-day-old company
89
+ // out of its own trial, because TrialService can leave the Stripe
90
+ // subscription at status "incomplete" and never write the flag at all.
91
+ expect(result.current.status).toBe("trial");
92
+ expect(result.current.isBlocked).toBe(false);
93
+ });
94
+
95
+ it("blocks once the trial window has elapsed with no active subscription", () => {
96
+ userMock.currentUser = { roles: [] };
97
+ const createdAt = new Date();
98
+ createdAt.setDate(createdAt.getDate() - 15); // past the 14-day trial
99
+ userMock.company = { isActiveSubscription: false, createdAt };
100
+
101
+ const { result } = renderHook(() => useSubscriptionStatus());
102
+
103
+ expect(result.current.status).toBe("expired");
104
+ expect(result.current.isBlocked).toBe(true);
105
+ });
106
+
107
+ it("keeps daysRemaining counting down from createdAt, unaffected by the isBlocked change (1 day old)", () => {
108
+ userMock.currentUser = { roles: [] };
109
+ const createdAt = new Date();
110
+ createdAt.setDate(createdAt.getDate() - 1);
111
+ userMock.company = { isActiveSubscription: false, createdAt };
112
+
113
+ const { result } = renderHook(() => useSubscriptionStatus());
114
+
115
+ expect(result.current.daysRemaining).toBe(13);
116
+ expect(result.current.isGracePeriod).toBe(false);
117
+ });
118
+
119
+ it("keeps isGracePeriod true once daysRemaining is inside GRACE_DAYS (12 days old)", () => {
120
+ userMock.currentUser = { roles: [] };
121
+ const createdAt = new Date();
122
+ createdAt.setDate(createdAt.getDate() - 12);
123
+ userMock.company = { isActiveSubscription: false, createdAt };
124
+
125
+ const { result } = renderHook(() => useSubscriptionStatus());
126
+
127
+ expect(result.current.daysRemaining).toBe(2);
128
+ expect(result.current.isGracePeriod).toBe(true);
129
+ });
130
+ });
@@ -59,14 +59,16 @@ export function useSubscriptionStatus(): TrialSubscriptionStatus {
59
59
  };
60
60
  }
61
61
 
62
- // No company after loading = blocked
62
+ // No company after loading is an AUTHENTICATION fault, not a billing one.
63
+ // Reporting it as a block would hide the real problem, so fail open — the
64
+ // same reasoning CreditsGuard documents on the API side.
63
65
  if (!company) {
64
66
  return {
65
67
  status: "expired",
66
68
  trialEndsAt: null,
67
69
  daysRemaining: 0,
68
70
  isGracePeriod: false,
69
- isBlocked: true,
71
+ isBlocked: false,
70
72
  };
71
73
  }
72
74
 
@@ -81,7 +83,16 @@ export function useSubscriptionStatus(): TrialSubscriptionStatus {
81
83
  };
82
84
  }
83
85
 
84
- // Calculate trial status from createdAt
86
+ // No active subscription but that alone is NOT a block. The trial window
87
+ // has to have elapsed too, and this mirrors the server rule in
88
+ // apps/api .../campaign/entities/campaign-lock.cypher.ts. Keep the two in
89
+ // step: if TRIAL_DAYS changes here it must change there.
90
+ //
91
+ // Blocking on the flag alone is wrong in practice. isActiveSubscription is
92
+ // only written true once a Stripe subscription actually reaches
93
+ // trialing/active, and that is not guaranteed — a real signup produced a
94
+ // StripeSubscription stuck at status "incomplete", leaving the flag NULL and
95
+ // a zero-day-old company blocked out of its own trial.
85
96
  const createdAt = new Date(company.createdAt);
86
97
  const trialEndsAt = new Date(createdAt);
87
98
  trialEndsAt.setDate(trialEndsAt.getDate() + TRIAL_DAYS);
@@ -89,13 +100,14 @@ export function useSubscriptionStatus(): TrialSubscriptionStatus {
89
100
  const now = new Date();
90
101
  const msRemaining = trialEndsAt.getTime() - now.getTime();
91
102
  const daysRemaining = Math.ceil(msRemaining / (1000 * 60 * 60 * 24));
103
+ const trialElapsed = daysRemaining <= 0;
92
104
 
93
105
  return {
94
- status: daysRemaining > 0 ? "trial" : "expired",
106
+ status: trialElapsed ? "expired" : "trial",
95
107
  trialEndsAt,
96
108
  daysRemaining: Math.max(0, daysRemaining),
97
109
  isGracePeriod: daysRemaining > 0 && daysRemaining <= GRACE_DAYS,
98
- isBlocked: daysRemaining <= 0,
110
+ isBlocked: trialElapsed,
99
111
  };
100
112
  }, [company, currentUser]);
101
113
  }