@secondlayer/cli 21.1.1 → 21.2.0
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/cli.js +70 -2
- package/dist/cli.js.map +3 -3
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -202692,7 +202692,7 @@ var {
|
|
|
202692
202692
|
// package.json
|
|
202693
202693
|
var package_default = {
|
|
202694
202694
|
name: "@secondlayer/cli",
|
|
202695
|
-
version: "21.
|
|
202695
|
+
version: "21.2.0",
|
|
202696
202696
|
description: "Run a Stacks index on your own hardware — set it up, restore verified history, and keep it current.",
|
|
202697
202697
|
repository: {
|
|
202698
202698
|
type: "git",
|
|
@@ -204926,6 +204926,35 @@ function registerArchiveCommand(program) {
|
|
|
204926
204926
|
init_http();
|
|
204927
204927
|
init_output();
|
|
204928
204928
|
var PACKS = [10, 25, 50, 100];
|
|
204929
|
+
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
204930
|
+
function rowsUsageDays(daily, days, now) {
|
|
204931
|
+
const byDate = new Map;
|
|
204932
|
+
for (const d of daily) {
|
|
204933
|
+
const day = byDate.get(d.date) ?? {
|
|
204934
|
+
date: d.date,
|
|
204935
|
+
rows: 0,
|
|
204936
|
+
free: 0,
|
|
204937
|
+
paid: 0
|
|
204938
|
+
};
|
|
204939
|
+
day.rows += d.rows;
|
|
204940
|
+
day.free += d.freeRows;
|
|
204941
|
+
day.paid += d.paidRows;
|
|
204942
|
+
byDate.set(d.date, day);
|
|
204943
|
+
}
|
|
204944
|
+
const today = Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate());
|
|
204945
|
+
return Array.from({ length: days }, (_, i) => {
|
|
204946
|
+
const date = new Date(today - (days - 1 - i) * DAY_MS).toISOString().slice(0, 10);
|
|
204947
|
+
return byDate.get(date) ?? { date, rows: 0, free: 0, paid: 0 };
|
|
204948
|
+
});
|
|
204949
|
+
}
|
|
204950
|
+
function parseDays(raw) {
|
|
204951
|
+
const n = Number(raw);
|
|
204952
|
+
if (!Number.isInteger(n) || n < 1 || n > 30) {
|
|
204953
|
+
error("--days must be a whole number from 1 to 30");
|
|
204954
|
+
process.exit(1);
|
|
204955
|
+
}
|
|
204956
|
+
return n;
|
|
204957
|
+
}
|
|
204929
204958
|
function parsePack(raw) {
|
|
204930
204959
|
const n = Number(raw);
|
|
204931
204960
|
if (!PACKS.includes(n)) {
|
|
@@ -204993,10 +205022,49 @@ async function runBalance(opts) {
|
|
|
204993
205022
|
}
|
|
204994
205023
|
});
|
|
204995
205024
|
}
|
|
205025
|
+
async function runUsage(opts) {
|
|
205026
|
+
const days = parseDays(opts.days);
|
|
205027
|
+
let res;
|
|
205028
|
+
try {
|
|
205029
|
+
res = await httpArchiveOps("/api/billing/rows");
|
|
205030
|
+
} catch (err) {
|
|
205031
|
+
if (err instanceof CliHttpError) {
|
|
205032
|
+
error(err.message);
|
|
205033
|
+
process.exit(1);
|
|
205034
|
+
}
|
|
205035
|
+
throw err;
|
|
205036
|
+
}
|
|
205037
|
+
output({
|
|
205038
|
+
json: opts.json,
|
|
205039
|
+
data: res,
|
|
205040
|
+
human: () => {
|
|
205041
|
+
const n = (v) => v.toLocaleString("en-US");
|
|
205042
|
+
const lines = rowsUsageDays(res.daily, days, new Date);
|
|
205043
|
+
console.log(formatTable(["Date", "Rows", "Free", "Paid"], lines.map((d) => [d.date, n(d.rows), n(d.free), n(d.paid)])));
|
|
205044
|
+
console.log();
|
|
205045
|
+
const { allowance } = res;
|
|
205046
|
+
const pairs = [
|
|
205047
|
+
[
|
|
205048
|
+
"This month",
|
|
205049
|
+
`${n(allowance.usedThisMonth)} rows, ${n(allowance.monthly)} free${allowance.exhaustedOn ? ` (used up ${allowance.exhaustedOn})` : ""}`
|
|
205050
|
+
]
|
|
205051
|
+
];
|
|
205052
|
+
for (const source of res.bySource) {
|
|
205053
|
+
const name = source.source === "streams" ? "Streams" : "Index";
|
|
205054
|
+
pairs.push([
|
|
205055
|
+
name,
|
|
205056
|
+
`${n(source.rows)} rows, ${n(source.calls)} calls, 30 days`
|
|
205057
|
+
]);
|
|
205058
|
+
}
|
|
205059
|
+
console.log(formatKeyValue(pairs));
|
|
205060
|
+
}
|
|
205061
|
+
});
|
|
205062
|
+
}
|
|
204996
205063
|
function registerCreditsCommand(program) {
|
|
204997
205064
|
const credits = program.command("credits").description("Buy and check archive credits");
|
|
204998
205065
|
credits.command("buy").description("Open a one-time Stripe checkout for archive credits").requiredOption("--email <email>", "Receipt email; becomes the account").option("--pack <usd>", `One of ${PACKS.join(", ")}`, "25").option("--json", "Output as JSON").action((opts) => runBuy(opts));
|
|
204999
205066
|
credits.command("balance").description("Show prepaid archive credit balance").option("--json", "Output as JSON").action((opts) => runBalance(opts));
|
|
205067
|
+
credits.command("usage").description("Rows delivered per day: free vs paid, by source").option("--days <n>", "Days to show (max 30)", "30").option("--json", "Output as JSON").action((opts) => runUsage(opts));
|
|
205000
205068
|
credits.command("refill").description("Opt-in auto-refill when the balance drops under a threshold").option("--below <usd>", "Trigger when balance is under this USD amount").option("--pack <usd>", `Pack to buy (${PACKS.join(", ")})`, "25").option("--off", "Turn auto-refill off").option("--json", "Output as JSON").action((opts) => runRefill(opts));
|
|
205001
205069
|
}
|
|
205002
205070
|
async function runRefill(opts) {
|
|
@@ -208475,5 +208543,5 @@ registerCreditsCommand(program);
|
|
|
208475
208543
|
registerArchiveCommand(program);
|
|
208476
208544
|
program.parse();
|
|
208477
208545
|
|
|
208478
|
-
//# debugId=
|
|
208546
|
+
//# debugId=FA7A9048A9D4FA1264756E2164756E21
|
|
208479
208547
|
//# sourceMappingURL=cli.js.map
|