@secondlayer/cli 21.1.0 → 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 +76 -7
- package/dist/cli.js.map +4 -4
- package/package.json +5 -5
package/dist/cli.js
CHANGED
|
@@ -29469,7 +29469,7 @@ var init_git_status = () => {};
|
|
|
29469
29469
|
|
|
29470
29470
|
// ../../node_modules/typescript/lib/typescript.js
|
|
29471
29471
|
var require_typescript = __commonJS(function(exports, module) {
|
|
29472
|
-
var __dirname = "/
|
|
29472
|
+
var __dirname = "/Users/ryan/projects/secondlayer/node_modules/typescript/lib", __filename = "/Users/ryan/projects/secondlayer/node_modules/typescript/lib/typescript.js";
|
|
29473
29473
|
/*! *****************************************************************************
|
|
29474
29474
|
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
29475
29475
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
@@ -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",
|
|
@@ -202731,10 +202731,10 @@ var package_default = {
|
|
|
202731
202731
|
"@inquirer/prompts": "^8.2.0",
|
|
202732
202732
|
"@secondlayer/bundler": "^0.7.1",
|
|
202733
202733
|
"@secondlayer/scaffold": "^1.6.2",
|
|
202734
|
-
"@secondlayer/sdk": "^15.0
|
|
202735
|
-
"@secondlayer/shared": "^13.
|
|
202736
|
-
"@secondlayer/stacks": "^6.
|
|
202737
|
-
"@secondlayer/subgraphs": "^7.
|
|
202734
|
+
"@secondlayer/sdk": "^15.1.0",
|
|
202735
|
+
"@secondlayer/shared": "^13.1.0",
|
|
202736
|
+
"@secondlayer/stacks": "^6.4.0",
|
|
202737
|
+
"@secondlayer/subgraphs": "^7.2.0",
|
|
202738
202738
|
"@secondlayer/verify": "^0.6.0",
|
|
202739
202739
|
esbuild: "^0.28.2",
|
|
202740
202740
|
"smol-toml": "^1.9.1",
|
|
@@ -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) {
|
|
@@ -205714,6 +205782,7 @@ function addWebhooksCreateCommand(parent) {
|
|
|
205714
205782
|
parent.command("create <name>").description("Create a webhook on raw chain events").option("-u, --url <url>", "Webhook URL").option("--auth-token <token>", "Bearer token for receiver API auth; a flag lands in shell history and ps, so set it in the receiver's env and pass it here only for a throwaway token").option("--trigger <json...>", `Chain trigger as JSON (repeatable), e.g. '{"type":"sbtc_deposit"}'`).option("--triggers-file <path>", "Chain triggers as a JSON array file").option("--format <format>", "Delivery format (default standard-webhooks)").addHelpText("after", `
|
|
205715
205783
|
Examples:
|
|
205716
205784
|
$ secondlayer webhooks create my-hook -u https://example.com/webhook --trigger '{"type":"sbtc_deposit"}'
|
|
205785
|
+
$ secondlayer webhooks create my-hook -u https://example.com/webhook --trigger '{"type":"print_event","contractId":"SP000000000000000000002Q6VF78.pox-5","where":{"signer":"SP21YTSM60CAY6D011EZVEVNKXVW8FVZE198XEFFP.fastpool-1-signer-manager"}}'
|
|
205717
205786
|
$ secondlayer webhooks create my-hook -u https://example.com/webhook --triggers-file triggers.json`).action(createChainWebhook);
|
|
205718
205787
|
}
|
|
205719
205788
|
|
|
@@ -208474,5 +208543,5 @@ registerCreditsCommand(program);
|
|
|
208474
208543
|
registerArchiveCommand(program);
|
|
208475
208544
|
program.parse();
|
|
208476
208545
|
|
|
208477
|
-
//# debugId=
|
|
208546
|
+
//# debugId=FA7A9048A9D4FA1264756E2164756E21
|
|
208478
208547
|
//# sourceMappingURL=cli.js.map
|