@streamoid/settings 0.14.0 → 0.15.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.
- package/dist/index.d.mts +214 -5
- package/dist/index.d.ts +214 -5
- package/dist/index.js +543 -67
- package/dist/index.mjs +544 -67
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -7676,6 +7676,7 @@ import {
|
|
|
7676
7676
|
useEffect as useEffect18,
|
|
7677
7677
|
useCallback as useCallback8,
|
|
7678
7678
|
useMemo as useMemo4,
|
|
7679
|
+
useReducer,
|
|
7679
7680
|
useRef as useRef10
|
|
7680
7681
|
} from "react";
|
|
7681
7682
|
import {
|
|
@@ -7826,7 +7827,10 @@ function formatDateRange(date) {
|
|
|
7826
7827
|
function ExportDateModal({
|
|
7827
7828
|
title,
|
|
7828
7829
|
onClose,
|
|
7829
|
-
onExport
|
|
7830
|
+
onExport,
|
|
7831
|
+
busy = false,
|
|
7832
|
+
busyText,
|
|
7833
|
+
notice = null
|
|
7830
7834
|
}) {
|
|
7831
7835
|
useOverlayOpen(true, onClose);
|
|
7832
7836
|
const now = /* @__PURE__ */ new Date();
|
|
@@ -7913,6 +7917,7 @@ function ExportDateModal({
|
|
|
7913
7917
|
[rangeStart, rangeEnd, isFuture]
|
|
7914
7918
|
);
|
|
7915
7919
|
const handleExport = () => {
|
|
7920
|
+
if (busy) return;
|
|
7916
7921
|
if (rangeStart && rangeEnd) onExport(rangeStart, rangeEnd);
|
|
7917
7922
|
};
|
|
7918
7923
|
const getCellVisuals = (cell, idx) => {
|
|
@@ -8134,24 +8139,42 @@ function ExportDateModal({
|
|
|
8134
8139
|
borderTop: "1px solid var(--alias-border-subtle)"
|
|
8135
8140
|
},
|
|
8136
8141
|
children: [
|
|
8137
|
-
/* @__PURE__ */
|
|
8138
|
-
|
|
8139
|
-
|
|
8140
|
-
|
|
8141
|
-
|
|
8142
|
-
|
|
8143
|
-
|
|
8144
|
-
|
|
8145
|
-
|
|
8146
|
-
|
|
8147
|
-
|
|
8148
|
-
|
|
8149
|
-
|
|
8150
|
-
|
|
8142
|
+
/* @__PURE__ */ jsxs18("div", { className: "flex-1 min-w-0 flex flex-col", children: [
|
|
8143
|
+
/* @__PURE__ */ jsx21(
|
|
8144
|
+
"p",
|
|
8145
|
+
{
|
|
8146
|
+
className: "min-w-0 truncate",
|
|
8147
|
+
style: {
|
|
8148
|
+
fontFamily: "var(--font-family-font-family-body)",
|
|
8149
|
+
fontSize: "var(--font-size-font-size-md)",
|
|
8150
|
+
fontWeight: 400,
|
|
8151
|
+
lineHeight: "var(--line-height-line-height-md)",
|
|
8152
|
+
color: "var(--alias-text---icons-primary)"
|
|
8153
|
+
},
|
|
8154
|
+
"aria-live": "polite",
|
|
8155
|
+
children: busy && busyText ? busyText : rangeStart && rangeEnd ? `${formatDateRange(rangeStart)} - ${formatDateRange(rangeEnd)}` : rangeStart ? `${formatDateRange(rangeStart)} - Select end date` : "Select date range"
|
|
8156
|
+
}
|
|
8157
|
+
),
|
|
8158
|
+
notice && !busy && /* @__PURE__ */ jsx21(
|
|
8159
|
+
"p",
|
|
8160
|
+
{
|
|
8161
|
+
role: "alert",
|
|
8162
|
+
style: {
|
|
8163
|
+
fontFamily: "var(--font-family-font-family-body)",
|
|
8164
|
+
fontSize: "var(--font-size-font-size-sm)",
|
|
8165
|
+
fontWeight: 400,
|
|
8166
|
+
lineHeight: "var(--line-height-line-height-sm)",
|
|
8167
|
+
color: "var(--alias-text---icons-error)"
|
|
8168
|
+
},
|
|
8169
|
+
children: notice
|
|
8170
|
+
}
|
|
8171
|
+
)
|
|
8172
|
+
] }),
|
|
8151
8173
|
/* @__PURE__ */ jsx21(
|
|
8152
8174
|
"div",
|
|
8153
8175
|
{
|
|
8154
|
-
className: `flex items-center justify-center shrink-0 ${rangeStart && rangeEnd ? "cursor-pointer" : "opacity-50 cursor-not-allowed"}`,
|
|
8176
|
+
className: `flex items-center justify-center shrink-0 ${rangeStart && rangeEnd && !busy ? "cursor-pointer" : "opacity-50 cursor-not-allowed"}`,
|
|
8177
|
+
"aria-disabled": busy || !(rangeStart && rangeEnd),
|
|
8155
8178
|
style: {
|
|
8156
8179
|
backgroundColor: "var(--alias-text---icons-primary)",
|
|
8157
8180
|
borderRadius: "var(--radius-xl)",
|
|
@@ -8169,7 +8192,7 @@ function ExportDateModal({
|
|
|
8169
8192
|
lineHeight: "var(--line-height-line-height-sm)",
|
|
8170
8193
|
color: "var(--alias-text---icons-inverse)"
|
|
8171
8194
|
},
|
|
8172
|
-
children: "Export"
|
|
8195
|
+
children: busy ? "Exporting\u2026" : "Export"
|
|
8173
8196
|
}
|
|
8174
8197
|
)
|
|
8175
8198
|
}
|
|
@@ -10588,6 +10611,199 @@ async function loadCurrentPlan(fetchCurrentPlan) {
|
|
|
10588
10611
|
return { subscription, entitlement, paid: hasPaidFeatures({ entitlement, subscription }) };
|
|
10589
10612
|
}
|
|
10590
10613
|
|
|
10614
|
+
// src/usage-logs.ts
|
|
10615
|
+
var USAGE_LOGS_PAGE_SIZE = 50;
|
|
10616
|
+
var USAGE_LOGS_EXPORT_BATCH_SIZE = 100;
|
|
10617
|
+
var USAGE_LOGS_EXPORT_MAX_ROWS = 2e4;
|
|
10618
|
+
var USAGE_LOGS_EXPORT_EXTRA_REQUESTS = 10;
|
|
10619
|
+
function rowsOf(res) {
|
|
10620
|
+
return Array.isArray(res?.data) ? res.data : [];
|
|
10621
|
+
}
|
|
10622
|
+
function sliceUsageLogsPage(all, page, pageSize = USAGE_LOGS_PAGE_SIZE) {
|
|
10623
|
+
const total = all.length;
|
|
10624
|
+
const totalPages = Math.max(1, Math.ceil(total / pageSize));
|
|
10625
|
+
const safePage = Math.min(Math.max(1, Math.floor(page) || 1), totalPages);
|
|
10626
|
+
return {
|
|
10627
|
+
rows: all.slice((safePage - 1) * pageSize, safePage * pageSize),
|
|
10628
|
+
page: safePage,
|
|
10629
|
+
totalPages,
|
|
10630
|
+
total,
|
|
10631
|
+
unpaged: all
|
|
10632
|
+
};
|
|
10633
|
+
}
|
|
10634
|
+
function usageLogsPage(res, page, pageSize = USAGE_LOGS_PAGE_SIZE) {
|
|
10635
|
+
const data = rowsOf(res);
|
|
10636
|
+
const pagination = res?.pagination;
|
|
10637
|
+
if (!pagination || !Number.isFinite(pagination.total)) {
|
|
10638
|
+
return sliceUsageLogsPage(data, page, pageSize);
|
|
10639
|
+
}
|
|
10640
|
+
const total = Math.max(0, pagination.total);
|
|
10641
|
+
const limit = pagination.limit > 0 ? pagination.limit : pageSize;
|
|
10642
|
+
const totalPages = Math.max(
|
|
10643
|
+
1,
|
|
10644
|
+
pagination.totalPages > 0 ? pagination.totalPages : Math.ceil(total / limit)
|
|
10645
|
+
);
|
|
10646
|
+
return {
|
|
10647
|
+
rows: data.slice(0, pageSize),
|
|
10648
|
+
page: pagination.page > 0 ? pagination.page : page,
|
|
10649
|
+
totalPages,
|
|
10650
|
+
total,
|
|
10651
|
+
unpaged: null
|
|
10652
|
+
};
|
|
10653
|
+
}
|
|
10654
|
+
var EMPTY_USAGE_LOGS_PAGE = {
|
|
10655
|
+
rows: [],
|
|
10656
|
+
page: 1,
|
|
10657
|
+
totalPages: 1,
|
|
10658
|
+
total: 0,
|
|
10659
|
+
unpaged: null
|
|
10660
|
+
};
|
|
10661
|
+
var INITIAL_USAGE_LOGS_STATE = {
|
|
10662
|
+
logs: EMPTY_USAGE_LOGS_PAGE,
|
|
10663
|
+
requestedPage: 1,
|
|
10664
|
+
loading: false,
|
|
10665
|
+
error: null
|
|
10666
|
+
};
|
|
10667
|
+
function usageLogsReducer(state, action) {
|
|
10668
|
+
switch (action.type) {
|
|
10669
|
+
case "request":
|
|
10670
|
+
return { ...state, requestedPage: action.page, loading: true, error: null };
|
|
10671
|
+
case "loaded":
|
|
10672
|
+
return {
|
|
10673
|
+
logs: action.logs,
|
|
10674
|
+
requestedPage: action.logs.page,
|
|
10675
|
+
loading: false,
|
|
10676
|
+
error: null
|
|
10677
|
+
};
|
|
10678
|
+
case "failed":
|
|
10679
|
+
return { ...state, loading: false, error: action.error };
|
|
10680
|
+
case "turn": {
|
|
10681
|
+
if (!state.logs.unpaged || state.error) return state;
|
|
10682
|
+
const logs = sliceUsageLogsPage(state.logs.unpaged, action.page);
|
|
10683
|
+
return { ...state, logs, requestedPage: logs.page };
|
|
10684
|
+
}
|
|
10685
|
+
case "reset":
|
|
10686
|
+
return INITIAL_USAGE_LOGS_STATE;
|
|
10687
|
+
}
|
|
10688
|
+
}
|
|
10689
|
+
function usageLogsReloadPage(state) {
|
|
10690
|
+
return Math.max(1, Math.floor(state.requestedPage) || 1);
|
|
10691
|
+
}
|
|
10692
|
+
function usageLogsSpentByOthers(logs, workspaceId) {
|
|
10693
|
+
return (logs.unpaged ?? logs.rows).some(
|
|
10694
|
+
(log) => usedByWorkspaceKey(log, workspaceId) !== null
|
|
10695
|
+
);
|
|
10696
|
+
}
|
|
10697
|
+
function createUsedByNamesLoader(save) {
|
|
10698
|
+
let savedFor = null;
|
|
10699
|
+
let inFlight = null;
|
|
10700
|
+
return {
|
|
10701
|
+
async load(workspaceId, fetchCreditPool) {
|
|
10702
|
+
if (savedFor === workspaceId || inFlight?.workspaceId === workspaceId) {
|
|
10703
|
+
return;
|
|
10704
|
+
}
|
|
10705
|
+
const lookup = { workspaceId };
|
|
10706
|
+
inFlight = lookup;
|
|
10707
|
+
try {
|
|
10708
|
+
const pool = await fetchCreditPool();
|
|
10709
|
+
if (inFlight !== lookup) return;
|
|
10710
|
+
if (save(workspaceId, usedByNamesFrom(pool))) savedFor = workspaceId;
|
|
10711
|
+
} catch {
|
|
10712
|
+
} finally {
|
|
10713
|
+
if (inFlight === lookup) inFlight = null;
|
|
10714
|
+
}
|
|
10715
|
+
},
|
|
10716
|
+
reset() {
|
|
10717
|
+
savedFor = null;
|
|
10718
|
+
inFlight = null;
|
|
10719
|
+
}
|
|
10720
|
+
};
|
|
10721
|
+
}
|
|
10722
|
+
function usageLogsExportFileName(start, end) {
|
|
10723
|
+
return `usage_logs_${toLocalDateInput(start)}_${toLocalDateInput(end)}.csv`;
|
|
10724
|
+
}
|
|
10725
|
+
function usageLogsDateRange(start, end) {
|
|
10726
|
+
const from = new Date(start);
|
|
10727
|
+
from.setHours(0, 0, 0, 0);
|
|
10728
|
+
const to = new Date(end);
|
|
10729
|
+
to.setHours(23, 59, 59, 999);
|
|
10730
|
+
return { startDate: from.toISOString(), endDate: to.toISOString() };
|
|
10731
|
+
}
|
|
10732
|
+
async function fetchUsageLogsInRange(fetchUsageLogs, range, {
|
|
10733
|
+
batchSize = USAGE_LOGS_EXPORT_BATCH_SIZE,
|
|
10734
|
+
maxRows = USAGE_LOGS_EXPORT_MAX_ROWS,
|
|
10735
|
+
maxRequests,
|
|
10736
|
+
onProgress,
|
|
10737
|
+
signal
|
|
10738
|
+
} = {}) {
|
|
10739
|
+
const first = await fetchUsageLogs({ ...range, page: 1, limit: batchSize });
|
|
10740
|
+
if (signal?.aborted) return { status: "cancelled" };
|
|
10741
|
+
if (!first?.pagination || !Number.isFinite(first.pagination.total)) {
|
|
10742
|
+
const from = Date.parse(range.startDate);
|
|
10743
|
+
const to = Date.parse(range.endDate);
|
|
10744
|
+
const rows2 = rowsOf(first).filter((row) => {
|
|
10745
|
+
const at = Date.parse(row.createdAt);
|
|
10746
|
+
return at >= from && at <= to;
|
|
10747
|
+
});
|
|
10748
|
+
if (rows2.length > maxRows) return { status: "too-large", total: rows2.length };
|
|
10749
|
+
onProgress?.(rows2.length, rows2.length);
|
|
10750
|
+
return { status: "ok", rows: rows2, total: rows2.length };
|
|
10751
|
+
}
|
|
10752
|
+
let total = Math.max(0, first.pagination.total);
|
|
10753
|
+
if (total > maxRows) return { status: "too-large", total };
|
|
10754
|
+
const limit = first.pagination.limit > 0 ? first.pagination.limit : batchSize;
|
|
10755
|
+
const requestCap = maxRequests ?? Math.ceil(maxRows / limit) + USAGE_LOGS_EXPORT_EXTRA_REQUESTS;
|
|
10756
|
+
const seen = /* @__PURE__ */ new Set();
|
|
10757
|
+
const rows = [];
|
|
10758
|
+
const add = (batch) => {
|
|
10759
|
+
for (const row of batch) {
|
|
10760
|
+
if (rows.length >= maxRows) return;
|
|
10761
|
+
if (seen.has(row._id)) continue;
|
|
10762
|
+
seen.add(row._id);
|
|
10763
|
+
rows.push(row);
|
|
10764
|
+
}
|
|
10765
|
+
};
|
|
10766
|
+
const hasNextAfter = (pagination, page) => typeof pagination?.hasNextPage === "boolean" ? pagination.hasNextPage : page * limit < total;
|
|
10767
|
+
add(rowsOf(first));
|
|
10768
|
+
onProgress?.(rows.length, total);
|
|
10769
|
+
let hasNext = hasNextAfter(first.pagination, 1);
|
|
10770
|
+
let requests = 1;
|
|
10771
|
+
for (let page = 2; hasNext && rows.length < total; page++) {
|
|
10772
|
+
if (requests >= requestCap) {
|
|
10773
|
+
return { status: "incomplete", fetched: rows.length, total };
|
|
10774
|
+
}
|
|
10775
|
+
if (signal?.aborted) return { status: "cancelled" };
|
|
10776
|
+
const res = await fetchUsageLogs({ ...range, page, limit });
|
|
10777
|
+
requests++;
|
|
10778
|
+
if (signal?.aborted) return { status: "cancelled" };
|
|
10779
|
+
if (res?.pagination && Number.isFinite(res.pagination.total)) {
|
|
10780
|
+
total = Math.max(0, res.pagination.total);
|
|
10781
|
+
if (total > maxRows) return { status: "too-large", total };
|
|
10782
|
+
}
|
|
10783
|
+
const batch = rowsOf(res);
|
|
10784
|
+
if (batch.length === 0) break;
|
|
10785
|
+
add(batch);
|
|
10786
|
+
onProgress?.(rows.length, total);
|
|
10787
|
+
hasNext = hasNextAfter(res?.pagination, page);
|
|
10788
|
+
}
|
|
10789
|
+
return { status: "ok", rows, total };
|
|
10790
|
+
}
|
|
10791
|
+
function usageLogsCsvRows(logs, userMap, formatDate5) {
|
|
10792
|
+
return [
|
|
10793
|
+
["Date", "Type", "Credits", "Service", "User ID"],
|
|
10794
|
+
...logs.map((log) => [
|
|
10795
|
+
formatDate5(log.createdAt),
|
|
10796
|
+
log.type,
|
|
10797
|
+
log.amount.toLocaleString("en-US"),
|
|
10798
|
+
log.service?.serviceGroupName ?? log.meta?.info ?? "",
|
|
10799
|
+
log.triggeredByUserId != null ? userMap[log.triggeredByUserId] ?? log.triggeredByUserId : ""
|
|
10800
|
+
])
|
|
10801
|
+
];
|
|
10802
|
+
}
|
|
10803
|
+
function toCsv(rows) {
|
|
10804
|
+
return rows.map((r) => r.map((cell) => `"${String(cell).replace(/"/g, '""')}"`).join(",")).join("\n");
|
|
10805
|
+
}
|
|
10806
|
+
|
|
10591
10807
|
// src/billing-content.tsx
|
|
10592
10808
|
import { Fragment as Fragment11, jsx as jsx29, jsxs as jsxs26 } from "react/jsx-runtime";
|
|
10593
10809
|
var DEFAULT_TOPUP_SERVICE = "catalogix";
|
|
@@ -11338,6 +11554,7 @@ function BillingTabBar({
|
|
|
11338
11554
|
}
|
|
11339
11555
|
);
|
|
11340
11556
|
}
|
|
11557
|
+
var BILLING_TABLE_MIN_HEIGHT = 300;
|
|
11341
11558
|
function InvoiceHistoryTable({
|
|
11342
11559
|
invoices,
|
|
11343
11560
|
loading,
|
|
@@ -11416,6 +11633,7 @@ function InvoiceHistoryTable({
|
|
|
11416
11633
|
{
|
|
11417
11634
|
className: "flex-1 min-h-0 w-full relative",
|
|
11418
11635
|
style: {
|
|
11636
|
+
minHeight: BILLING_TABLE_MIN_HEIGHT,
|
|
11419
11637
|
backgroundColor: "var(--alias-surface-base)",
|
|
11420
11638
|
borderRadius: "var(--radius-3xl)",
|
|
11421
11639
|
border: "1px solid var(--alias-border-subtle)",
|
|
@@ -11473,6 +11691,8 @@ function UsageLogsTable({
|
|
|
11473
11691
|
logs,
|
|
11474
11692
|
userMap,
|
|
11475
11693
|
loading,
|
|
11694
|
+
error = null,
|
|
11695
|
+
onRetry,
|
|
11476
11696
|
currentWorkspaceId = null,
|
|
11477
11697
|
usedByNames = {}
|
|
11478
11698
|
}) {
|
|
@@ -11503,11 +11723,56 @@ function UsageLogsTable({
|
|
|
11503
11723
|
}
|
|
11504
11724
|
);
|
|
11505
11725
|
}
|
|
11726
|
+
if (error) {
|
|
11727
|
+
return /* @__PURE__ */ jsxs26(
|
|
11728
|
+
"div",
|
|
11729
|
+
{
|
|
11730
|
+
role: "alert",
|
|
11731
|
+
className: "flex flex-col items-center justify-center w-full",
|
|
11732
|
+
style: {
|
|
11733
|
+
backgroundColor: "var(--alias-surface-base)",
|
|
11734
|
+
borderRadius: "var(--radius-3xl)",
|
|
11735
|
+
border: "1px solid var(--alias-border-subtle)",
|
|
11736
|
+
padding: "var(--spacing-6xl)",
|
|
11737
|
+
gap: "var(--spacing-md)"
|
|
11738
|
+
},
|
|
11739
|
+
children: [
|
|
11740
|
+
/* @__PURE__ */ jsxs26(
|
|
11741
|
+
"span",
|
|
11742
|
+
{
|
|
11743
|
+
style: {
|
|
11744
|
+
fontFamily: "var(--font-family-font-family-body)",
|
|
11745
|
+
fontSize: "var(--font-size-font-size-sm)",
|
|
11746
|
+
fontWeight: 400,
|
|
11747
|
+
lineHeight: "var(--line-height-line-height-sm)",
|
|
11748
|
+
color: "var(--alias-text---icons-muted)",
|
|
11749
|
+
textAlign: "center"
|
|
11750
|
+
},
|
|
11751
|
+
children: [
|
|
11752
|
+
"Couldn't load usage logs. ",
|
|
11753
|
+
error
|
|
11754
|
+
]
|
|
11755
|
+
}
|
|
11756
|
+
),
|
|
11757
|
+
onRetry && /* @__PURE__ */ jsx29(
|
|
11758
|
+
ScButton14,
|
|
11759
|
+
{
|
|
11760
|
+
text: "Try again",
|
|
11761
|
+
variant: "tertiary",
|
|
11762
|
+
size: "sm",
|
|
11763
|
+
onClick: onRetry
|
|
11764
|
+
}
|
|
11765
|
+
)
|
|
11766
|
+
]
|
|
11767
|
+
}
|
|
11768
|
+
);
|
|
11769
|
+
}
|
|
11506
11770
|
return /* @__PURE__ */ jsxs26(
|
|
11507
11771
|
"div",
|
|
11508
11772
|
{
|
|
11509
11773
|
className: "flex-1 min-h-0 w-full relative",
|
|
11510
11774
|
style: {
|
|
11775
|
+
minHeight: BILLING_TABLE_MIN_HEIGHT,
|
|
11511
11776
|
backgroundColor: "var(--alias-surface-base)",
|
|
11512
11777
|
borderRadius: "var(--radius-3xl)",
|
|
11513
11778
|
border: "1px solid var(--alias-border-subtle)",
|
|
@@ -11678,6 +11943,71 @@ function UsageLogsTable({
|
|
|
11678
11943
|
}
|
|
11679
11944
|
);
|
|
11680
11945
|
}
|
|
11946
|
+
function UsageLogsPager({
|
|
11947
|
+
page,
|
|
11948
|
+
totalPages,
|
|
11949
|
+
total,
|
|
11950
|
+
loading = false,
|
|
11951
|
+
onPageChange
|
|
11952
|
+
}) {
|
|
11953
|
+
if (total <= 0) return null;
|
|
11954
|
+
const canPrevious = !loading && page > 1;
|
|
11955
|
+
const canNext = !loading && page < totalPages;
|
|
11956
|
+
return /* @__PURE__ */ jsxs26(
|
|
11957
|
+
"div",
|
|
11958
|
+
{
|
|
11959
|
+
className: "flex items-center justify-between shrink-0 w-full",
|
|
11960
|
+
style: { gap: "var(--spacing-md)" },
|
|
11961
|
+
children: [
|
|
11962
|
+
/* @__PURE__ */ jsxs26(
|
|
11963
|
+
"span",
|
|
11964
|
+
{
|
|
11965
|
+
style: {
|
|
11966
|
+
color: "var(--alias-text---icons-muted)",
|
|
11967
|
+
fontFamily: "var(--font-family-font-family-body)",
|
|
11968
|
+
fontSize: "var(--font-size-font-size-sm)",
|
|
11969
|
+
lineHeight: "var(--line-height-line-height-sm)"
|
|
11970
|
+
},
|
|
11971
|
+
children: [
|
|
11972
|
+
"Page ",
|
|
11973
|
+
page.toLocaleString("en-US"),
|
|
11974
|
+
" of",
|
|
11975
|
+
" ",
|
|
11976
|
+
totalPages.toLocaleString("en-US"),
|
|
11977
|
+
" \xB7",
|
|
11978
|
+
" ",
|
|
11979
|
+
total.toLocaleString("en-US"),
|
|
11980
|
+
" ",
|
|
11981
|
+
total === 1 ? "log" : "logs"
|
|
11982
|
+
]
|
|
11983
|
+
}
|
|
11984
|
+
),
|
|
11985
|
+
totalPages > 1 && /* @__PURE__ */ jsxs26("div", { className: "flex items-center", style: { gap: "var(--spacing-md)" }, children: [
|
|
11986
|
+
/* @__PURE__ */ jsx29(
|
|
11987
|
+
ScButton14,
|
|
11988
|
+
{
|
|
11989
|
+
text: "Previous",
|
|
11990
|
+
variant: "tertiary",
|
|
11991
|
+
size: "sm",
|
|
11992
|
+
state: canPrevious ? "default" : "disabled",
|
|
11993
|
+
onClick: canPrevious ? () => onPageChange(page - 1) : void 0
|
|
11994
|
+
}
|
|
11995
|
+
),
|
|
11996
|
+
/* @__PURE__ */ jsx29(
|
|
11997
|
+
ScButton14,
|
|
11998
|
+
{
|
|
11999
|
+
text: "Next",
|
|
12000
|
+
variant: "tertiary",
|
|
12001
|
+
size: "sm",
|
|
12002
|
+
state: canNext ? "default" : "disabled",
|
|
12003
|
+
onClick: canNext ? () => onPageChange(page + 1) : void 0
|
|
12004
|
+
}
|
|
12005
|
+
)
|
|
12006
|
+
] })
|
|
12007
|
+
]
|
|
12008
|
+
}
|
|
12009
|
+
);
|
|
12010
|
+
}
|
|
11681
12011
|
function BackToBilling({ onClick }) {
|
|
11682
12012
|
return /* @__PURE__ */ jsxs26(
|
|
11683
12013
|
"div",
|
|
@@ -11757,6 +12087,9 @@ function BillingContent({
|
|
|
11757
12087
|
else setShowSharedCreditsInternal(next);
|
|
11758
12088
|
};
|
|
11759
12089
|
const [showExportModal, setShowExportModal] = useState21(false);
|
|
12090
|
+
const [exportProgress, setExportProgress] = useState21(null);
|
|
12091
|
+
const [exportNotice, setExportNotice] = useState21(null);
|
|
12092
|
+
const exportAbortRef = useRef10(null);
|
|
11760
12093
|
const [showBuyCreditsModal, setShowBuyCreditsModal] = useState21(false);
|
|
11761
12094
|
const [subscription, setSubscription] = useState21(null);
|
|
11762
12095
|
const [entitlement, setEntitlement] = useState21(
|
|
@@ -11768,7 +12101,26 @@ function BillingContent({
|
|
|
11768
12101
|
const [products, setProducts] = useState21([]);
|
|
11769
12102
|
const [invoices, setInvoices] = useState21([]);
|
|
11770
12103
|
const [totalCredits, setTotalCredits] = useState21(null);
|
|
11771
|
-
const [
|
|
12104
|
+
const [usageLogsState, dispatchUsageLogs] = useReducer(
|
|
12105
|
+
usageLogsReducer,
|
|
12106
|
+
INITIAL_USAGE_LOGS_STATE
|
|
12107
|
+
);
|
|
12108
|
+
const {
|
|
12109
|
+
logs: usageLogs,
|
|
12110
|
+
loading: loadingUsageLogs,
|
|
12111
|
+
error: usageLogsError
|
|
12112
|
+
} = usageLogsState;
|
|
12113
|
+
const usageLogsRequestRef = useRef10(0);
|
|
12114
|
+
const usageLogsStateRef = useRef10(usageLogsState);
|
|
12115
|
+
usageLogsStateRef.current = usageLogsState;
|
|
12116
|
+
const workspaceIdRef = useRef10(workspaceId);
|
|
12117
|
+
workspaceIdRef.current = workspaceId;
|
|
12118
|
+
const loadUsedByNamesRef = useRef10(null);
|
|
12119
|
+
loadUsedByNamesRef.current ??= createUsedByNamesLoader((forWorkspace, names) => {
|
|
12120
|
+
if (forWorkspace !== workspaceIdRef.current) return false;
|
|
12121
|
+
setUsedByNames(names);
|
|
12122
|
+
return true;
|
|
12123
|
+
});
|
|
11772
12124
|
const [userMap, setUserMap] = useState21({});
|
|
11773
12125
|
const [customPlanCredits, setCustomPlanCredits] = useState21(
|
|
11774
12126
|
null
|
|
@@ -11852,8 +12204,68 @@ function BillingContent({
|
|
|
11852
12204
|
} catch {
|
|
11853
12205
|
}
|
|
11854
12206
|
}, [api]);
|
|
12207
|
+
const ensureUsedByNames = useCallback8(
|
|
12208
|
+
(logs) => {
|
|
12209
|
+
const fetchCreditPool = api.fetchCreditPool;
|
|
12210
|
+
if (!fetchCreditPool || !workspaceId || !usageLogsSpentByOthers(logs, workspaceId)) {
|
|
12211
|
+
return;
|
|
12212
|
+
}
|
|
12213
|
+
void loadUsedByNamesRef.current?.load(
|
|
12214
|
+
workspaceId,
|
|
12215
|
+
() => fetchCreditPool.call(api)
|
|
12216
|
+
);
|
|
12217
|
+
},
|
|
12218
|
+
[api, workspaceId]
|
|
12219
|
+
);
|
|
12220
|
+
const loadUsageLogsPage = useCallback8(
|
|
12221
|
+
async (page) => {
|
|
12222
|
+
const request = ++usageLogsRequestRef.current;
|
|
12223
|
+
if (!api.fetchUsageLogs) {
|
|
12224
|
+
dispatchUsageLogs({ type: "loaded", logs: EMPTY_USAGE_LOGS_PAGE });
|
|
12225
|
+
return;
|
|
12226
|
+
}
|
|
12227
|
+
dispatchUsageLogs({ type: "request", page });
|
|
12228
|
+
try {
|
|
12229
|
+
const res = await api.fetchUsageLogs({
|
|
12230
|
+
page,
|
|
12231
|
+
limit: USAGE_LOGS_PAGE_SIZE
|
|
12232
|
+
});
|
|
12233
|
+
if (request !== usageLogsRequestRef.current) return;
|
|
12234
|
+
const next = usageLogsPage(res, page);
|
|
12235
|
+
dispatchUsageLogs({ type: "loaded", logs: next });
|
|
12236
|
+
ensureUsedByNames(next);
|
|
12237
|
+
} catch (err) {
|
|
12238
|
+
if (request !== usageLogsRequestRef.current) return;
|
|
12239
|
+
dispatchUsageLogs({
|
|
12240
|
+
type: "failed",
|
|
12241
|
+
error: errorMessage(err, { method: "GET" })
|
|
12242
|
+
});
|
|
12243
|
+
}
|
|
12244
|
+
},
|
|
12245
|
+
[api, ensureUsedByNames]
|
|
12246
|
+
);
|
|
12247
|
+
const goToUsageLogsPage = useCallback8(
|
|
12248
|
+
(page) => {
|
|
12249
|
+
if (usageLogs.unpaged && !usageLogsError) {
|
|
12250
|
+
dispatchUsageLogs({ type: "turn", page });
|
|
12251
|
+
ensureUsedByNames(usageLogs);
|
|
12252
|
+
return;
|
|
12253
|
+
}
|
|
12254
|
+
void loadUsageLogsPage(page);
|
|
12255
|
+
},
|
|
12256
|
+
[usageLogs, usageLogsError, loadUsageLogsPage, ensureUsedByNames]
|
|
12257
|
+
);
|
|
12258
|
+
useEffect18(() => {
|
|
12259
|
+
if (!loadingUsageLogs && !usageLogsError && usageLogs.unpaged === null && usageLogs.rows.length === 0 && usageLogs.total > 0 && usageLogs.page > usageLogs.totalPages) {
|
|
12260
|
+
void loadUsageLogsPage(usageLogs.totalPages);
|
|
12261
|
+
}
|
|
12262
|
+
}, [usageLogs, loadingUsageLogs, usageLogsError, loadUsageLogsPage]);
|
|
11855
12263
|
const fetchTableData = useCallback8(
|
|
11856
12264
|
async (tab) => {
|
|
12265
|
+
if (tab === "usage") {
|
|
12266
|
+
await loadUsageLogsPage(usageLogsReloadPage(usageLogsStateRef.current));
|
|
12267
|
+
return;
|
|
12268
|
+
}
|
|
11857
12269
|
setLoadingTable(true);
|
|
11858
12270
|
try {
|
|
11859
12271
|
if (tab === "invoice") {
|
|
@@ -11865,25 +12277,14 @@ function BillingContent({
|
|
|
11865
12277
|
(item) => item.expiresAt && item.expiresAt.split("T")[0] > today
|
|
11866
12278
|
).reduce((total, item) => total + item.amount, 0)
|
|
11867
12279
|
);
|
|
11868
|
-
} else if (api.fetchUsageLogs) {
|
|
11869
|
-
const res = await api.fetchUsageLogs();
|
|
11870
|
-
const logs = res.data?.length ? res.data : [];
|
|
11871
|
-
setUsageLogs(logs);
|
|
11872
|
-
if (api.fetchCreditPool && logs.some((log) => usedByWorkspaceKey(log, workspaceId))) {
|
|
11873
|
-
const pool = await api.fetchCreditPool().catch(() => null);
|
|
11874
|
-
setUsedByNames(usedByNamesFrom(pool));
|
|
11875
|
-
}
|
|
11876
|
-
} else {
|
|
11877
|
-
setUsageLogs([]);
|
|
11878
12280
|
}
|
|
11879
12281
|
} catch {
|
|
11880
|
-
|
|
11881
|
-
else setUsageLogs([]);
|
|
12282
|
+
setInvoices([]);
|
|
11882
12283
|
} finally {
|
|
11883
12284
|
setLoadingTable(false);
|
|
11884
12285
|
}
|
|
11885
12286
|
},
|
|
11886
|
-
[api,
|
|
12287
|
+
[api, loadUsageLogsPage]
|
|
11887
12288
|
);
|
|
11888
12289
|
const handlePlanAction = useCallback8(
|
|
11889
12290
|
async ({ productId, priceId, planName: planName2 }) => {
|
|
@@ -11990,6 +12391,11 @@ function BillingContent({
|
|
|
11990
12391
|
setProducts([]);
|
|
11991
12392
|
setTotalCredits(null);
|
|
11992
12393
|
setCustomPlanCredits(null);
|
|
12394
|
+
usageLogsRequestRef.current++;
|
|
12395
|
+
dispatchUsageLogs({ type: "reset" });
|
|
12396
|
+
usageLogsStateRef.current = INITIAL_USAGE_LOGS_STATE;
|
|
12397
|
+
loadUsedByNamesRef.current?.reset();
|
|
12398
|
+
setUsedByNames({});
|
|
11993
12399
|
}, [workspaceId]);
|
|
11994
12400
|
useEffect18(() => {
|
|
11995
12401
|
setInitialFetchTriggered(true);
|
|
@@ -12092,35 +12498,74 @@ function BillingContent({
|
|
|
12092
12498
|
toast.success(`Opened ${successCount} invoice PDF(s).`);
|
|
12093
12499
|
}
|
|
12094
12500
|
} else {
|
|
12095
|
-
|
|
12096
|
-
|
|
12097
|
-
|
|
12501
|
+
await exportUsageLogs(startDate, endDate);
|
|
12502
|
+
}
|
|
12503
|
+
};
|
|
12504
|
+
const closeExportModal = () => {
|
|
12505
|
+
exportAbortRef.current?.abort();
|
|
12506
|
+
exportAbortRef.current = null;
|
|
12507
|
+
setExportProgress(null);
|
|
12508
|
+
setExportNotice(null);
|
|
12509
|
+
setShowExportModal(false);
|
|
12510
|
+
};
|
|
12511
|
+
useEffect18(() => () => exportAbortRef.current?.abort(), []);
|
|
12512
|
+
const exportUsageLogs = async (startDate, endDate) => {
|
|
12513
|
+
if (!api.fetchUsageLogs) {
|
|
12514
|
+
toast.info?.("Usage logs are not available in this workspace.");
|
|
12515
|
+
closeExportModal();
|
|
12516
|
+
return;
|
|
12517
|
+
}
|
|
12518
|
+
exportAbortRef.current?.abort();
|
|
12519
|
+
const controller = new AbortController();
|
|
12520
|
+
exportAbortRef.current = controller;
|
|
12521
|
+
setExportNotice(null);
|
|
12522
|
+
setExportProgress({ fetched: 0, total: 0 });
|
|
12523
|
+
const range = usageLogsDateRange(startDate, endDate);
|
|
12524
|
+
try {
|
|
12525
|
+
const result = await fetchUsageLogsInRange(api.fetchUsageLogs, range, {
|
|
12526
|
+
signal: controller.signal,
|
|
12527
|
+
onProgress: (fetched, total) => {
|
|
12528
|
+
if (!controller.signal.aborted) setExportProgress({ fetched, total });
|
|
12529
|
+
}
|
|
12098
12530
|
});
|
|
12099
|
-
if (
|
|
12531
|
+
if (result.status === "cancelled" || controller.signal.aborted) return;
|
|
12532
|
+
if (result.status === "too-large") {
|
|
12533
|
+
setExportNotice(
|
|
12534
|
+
`${result.total.toLocaleString("en-US")} logs in this range; an export holds up to ${USAGE_LOGS_EXPORT_MAX_ROWS.toLocaleString("en-US")}. Choose a shorter range.`
|
|
12535
|
+
);
|
|
12536
|
+
return;
|
|
12537
|
+
}
|
|
12538
|
+
if (result.status === "incomplete") {
|
|
12539
|
+
setExportNotice(
|
|
12540
|
+
"Usage logs kept changing while exporting, so some were missed. Try again."
|
|
12541
|
+
);
|
|
12542
|
+
return;
|
|
12543
|
+
}
|
|
12544
|
+
if (result.rows.length === 0) {
|
|
12100
12545
|
toast.info?.("No usage logs found in the selected date range.");
|
|
12101
|
-
|
|
12546
|
+
closeExportModal();
|
|
12102
12547
|
return;
|
|
12103
12548
|
}
|
|
12104
|
-
const headers = ["Date", "Type", "Credits", "Service", "User ID"];
|
|
12105
|
-
const rows = filtered.map((log) => [
|
|
12106
|
-
formatDate3(log.createdAt),
|
|
12107
|
-
log.type,
|
|
12108
|
-
log.amount.toLocaleString("en-US"),
|
|
12109
|
-
log.service?.serviceGroupName ?? log.meta?.info ?? "",
|
|
12110
|
-
log.triggeredByUserId != null ? userMap[log.triggeredByUserId] ?? log.triggeredByUserId : ""
|
|
12111
|
-
]);
|
|
12112
12549
|
downloadCsv(
|
|
12113
|
-
|
|
12114
|
-
|
|
12550
|
+
usageLogsCsvRows(result.rows, userMap, formatDate3),
|
|
12551
|
+
usageLogsExportFileName(startDate, endDate)
|
|
12115
12552
|
);
|
|
12116
|
-
toast.success(`Exported ${
|
|
12117
|
-
|
|
12553
|
+
toast.success(`Exported ${result.rows.length.toLocaleString("en-US")} log(s).`);
|
|
12554
|
+
closeExportModal();
|
|
12555
|
+
} catch (err) {
|
|
12556
|
+
if (controller.signal.aborted) return;
|
|
12557
|
+
setExportNotice(
|
|
12558
|
+
`Couldn't export usage logs. ${errorMessage(err, { method: "GET" })}`
|
|
12559
|
+
);
|
|
12560
|
+
} finally {
|
|
12561
|
+
if (exportAbortRef.current === controller) {
|
|
12562
|
+
exportAbortRef.current = null;
|
|
12563
|
+
setExportProgress(null);
|
|
12564
|
+
}
|
|
12118
12565
|
}
|
|
12119
12566
|
};
|
|
12120
12567
|
function downloadCsv(rows, filename) {
|
|
12121
|
-
const csv = rows
|
|
12122
|
-
(r) => r.map((cell) => `"${String(cell).replace(/"/g, '""')}"`).join(",")
|
|
12123
|
-
).join("\n");
|
|
12568
|
+
const csv = toCsv(rows);
|
|
12124
12569
|
const blob = new Blob([csv], { type: "text/csv;charset=utf-8;" });
|
|
12125
12570
|
const url = URL.createObjectURL(blob);
|
|
12126
12571
|
const a = document.createElement("a");
|
|
@@ -12131,9 +12576,6 @@ function BillingContent({
|
|
|
12131
12576
|
document.body.removeChild(a);
|
|
12132
12577
|
URL.revokeObjectURL(url);
|
|
12133
12578
|
}
|
|
12134
|
-
function fmtFilename(d) {
|
|
12135
|
-
return d.toISOString().slice(0, 10);
|
|
12136
|
-
}
|
|
12137
12579
|
async function handleBuyCredits(credits2, price) {
|
|
12138
12580
|
if (!workspaceId) {
|
|
12139
12581
|
toast.error("Missing workspace details for credit top-up");
|
|
@@ -12586,22 +13028,39 @@ function BillingContent({
|
|
|
12586
13028
|
loading: loadingTable,
|
|
12587
13029
|
workspaceCountry: workspace.current?.country
|
|
12588
13030
|
}
|
|
12589
|
-
) : /* @__PURE__ */
|
|
12590
|
-
|
|
12591
|
-
|
|
12592
|
-
|
|
12593
|
-
|
|
12594
|
-
|
|
12595
|
-
|
|
12596
|
-
|
|
12597
|
-
|
|
12598
|
-
|
|
13031
|
+
) : /* @__PURE__ */ jsxs26(Fragment11, { children: [
|
|
13032
|
+
/* @__PURE__ */ jsx29(
|
|
13033
|
+
UsageLogsTable,
|
|
13034
|
+
{
|
|
13035
|
+
logs: usageLogs.rows,
|
|
13036
|
+
userMap,
|
|
13037
|
+
loading: loadingUsageLogs,
|
|
13038
|
+
error: usageLogsError,
|
|
13039
|
+
onRetry: () => void loadUsageLogsPage(usageLogsState.requestedPage),
|
|
13040
|
+
currentWorkspaceId: workspaceId,
|
|
13041
|
+
usedByNames
|
|
13042
|
+
}
|
|
13043
|
+
),
|
|
13044
|
+
!usageLogsError && /* @__PURE__ */ jsx29(
|
|
13045
|
+
UsageLogsPager,
|
|
13046
|
+
{
|
|
13047
|
+
page: usageLogs.page,
|
|
13048
|
+
totalPages: usageLogs.totalPages,
|
|
13049
|
+
total: usageLogs.total,
|
|
13050
|
+
loading: loadingUsageLogs,
|
|
13051
|
+
onPageChange: goToUsageLogsPage
|
|
13052
|
+
}
|
|
13053
|
+
)
|
|
13054
|
+
] }),
|
|
12599
13055
|
showExportModal && /* @__PURE__ */ jsx29(
|
|
12600
13056
|
ExportDateModal,
|
|
12601
13057
|
{
|
|
12602
13058
|
title: activeTab === "invoice" ? "Export invoices" : "Export log",
|
|
12603
|
-
onClose:
|
|
12604
|
-
onExport: handleExport
|
|
13059
|
+
onClose: closeExportModal,
|
|
13060
|
+
onExport: handleExport,
|
|
13061
|
+
busy: exportProgress !== null,
|
|
13062
|
+
busyText: exportProgress && exportProgress.total > 0 ? `Fetched ${exportProgress.fetched.toLocaleString("en-US")} of ${exportProgress.total.toLocaleString("en-US")} logs\u2026` : "Fetching logs\u2026",
|
|
13063
|
+
notice: exportNotice
|
|
12605
13064
|
}
|
|
12606
13065
|
),
|
|
12607
13066
|
showBuyCreditsModal && /* @__PURE__ */ jsx29(
|
|
@@ -12623,7 +13082,7 @@ function BillingContent({
|
|
|
12623
13082
|
"div",
|
|
12624
13083
|
{
|
|
12625
13084
|
className: "flex flex-col flex-1 min-w-0 min-h-0 w-full",
|
|
12626
|
-
style: { gap: 12 },
|
|
13085
|
+
style: { gap: 12, overflowY: "auto" },
|
|
12627
13086
|
children: billingInnerContent
|
|
12628
13087
|
}
|
|
12629
13088
|
);
|
|
@@ -16972,7 +17431,9 @@ export {
|
|
|
16972
17431
|
CreditPoolMemberModal,
|
|
16973
17432
|
DEFAULT_PERMISSIONS,
|
|
16974
17433
|
DEFAULT_USER_LANGUAGE,
|
|
17434
|
+
EMPTY_USAGE_LOGS_PAGE,
|
|
16975
17435
|
ExportDateModal,
|
|
17436
|
+
INITIAL_USAGE_LOGS_STATE,
|
|
16976
17437
|
InviteUpdateModal,
|
|
16977
17438
|
MemberCreditLimitModal,
|
|
16978
17439
|
MemberListFrame,
|
|
@@ -17005,7 +17466,12 @@ export {
|
|
|
17005
17466
|
TeamsContent,
|
|
17006
17467
|
TokensContent,
|
|
17007
17468
|
URL_TO_TAB,
|
|
17469
|
+
USAGE_LOGS_EXPORT_BATCH_SIZE,
|
|
17470
|
+
USAGE_LOGS_EXPORT_EXTRA_REQUESTS,
|
|
17471
|
+
USAGE_LOGS_EXPORT_MAX_ROWS,
|
|
17472
|
+
USAGE_LOGS_PAGE_SIZE,
|
|
17008
17473
|
USER_LANGUAGES,
|
|
17474
|
+
UsageLogsPager,
|
|
17009
17475
|
WORKSPACE_LIST_PAGE_SIZE,
|
|
17010
17476
|
WorkspaceGeneralTab,
|
|
17011
17477
|
WorkspaceListTab,
|
|
@@ -17017,6 +17483,7 @@ export {
|
|
|
17017
17483
|
cleanCreditLimitInput,
|
|
17018
17484
|
cleanPoolValueInput,
|
|
17019
17485
|
countLabel,
|
|
17486
|
+
createUsedByNamesLoader,
|
|
17020
17487
|
creditCycleUnit,
|
|
17021
17488
|
creditsMeter,
|
|
17022
17489
|
deriveWorkspaceInvitePermission,
|
|
@@ -17026,6 +17493,7 @@ export {
|
|
|
17026
17493
|
entitlementFromBody,
|
|
17027
17494
|
entitlementFromFailure,
|
|
17028
17495
|
expiryChoiceFor,
|
|
17496
|
+
fetchUsageLogsInRange,
|
|
17029
17497
|
findBillingError,
|
|
17030
17498
|
findPoolError,
|
|
17031
17499
|
formatCreditLimit,
|
|
@@ -17060,8 +17528,17 @@ export {
|
|
|
17060
17528
|
settingsReturnTarget,
|
|
17061
17529
|
sharedPoolBannerText,
|
|
17062
17530
|
sharedPoolEndsText,
|
|
17531
|
+
sliceUsageLogsPage,
|
|
17063
17532
|
sponsoredCreditsText,
|
|
17533
|
+
toCsv,
|
|
17064
17534
|
toLocalDateInput,
|
|
17535
|
+
usageLogsCsvRows,
|
|
17536
|
+
usageLogsDateRange,
|
|
17537
|
+
usageLogsExportFileName,
|
|
17538
|
+
usageLogsPage,
|
|
17539
|
+
usageLogsReducer,
|
|
17540
|
+
usageLogsReloadPage,
|
|
17541
|
+
usageLogsSpentByOthers,
|
|
17065
17542
|
useBillingEntitlement,
|
|
17066
17543
|
useSettingsAdapters,
|
|
17067
17544
|
useWorkspaceInvitePermission,
|