@letterstory/cli 0.175.28 → 0.176.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/lib/cli.mjs +3 -1
- package/lib/commands/admin.mjs +34 -1
- package/package.json +1 -1
package/lib/cli.mjs
CHANGED
|
@@ -80,7 +80,7 @@ import {
|
|
|
80
80
|
import { fetchParkedSections, withoutParked } from "./parked.mjs";
|
|
81
81
|
|
|
82
82
|
// Matches cli/package.json; publish-cli.yml rewrites both to the published version.
|
|
83
|
-
export const VERSION = "0.
|
|
83
|
+
export const VERSION = "0.176.0";
|
|
84
84
|
|
|
85
85
|
/** The exit code for a gate refusal (CARD_REQUIRED, PAYMENT_FAILED, OUT_OF_TOKENS): 1 is a plain error. */
|
|
86
86
|
export const EXIT_PAYMENT_REQUIRED = 3;
|
|
@@ -1128,6 +1128,8 @@ Admin (STAFF key — --staff-key / LETTERSTORY_STAFF_API_KEY; acts before an org
|
|
|
1128
1128
|
nightly reconcile, refusals, signups, grants
|
|
1129
1129
|
admin billing free preflight [--json] Who the paywall stops the moment it is enforced:
|
|
1130
1130
|
out of tokens, low, paying but covered, undecided
|
|
1131
|
+
admin billing org test <org-id> --why "…" [--off] Mark an org a test org (never gated or billed), or with
|
|
1132
|
+
--off not one; kept with who and why. Not for a payer.
|
|
1131
1133
|
admin billing emails [--bounced] [--org <org-id>] [--limit N]
|
|
1132
1134
|
The invoice and receipt emails we sent for Lago and
|
|
1133
1135
|
what became of each, bounced first (--bounced: only
|
package/lib/commands/admin.mjs
CHANGED
|
@@ -113,6 +113,7 @@ async function staffRequest(ctx, method, path, body) {
|
|
|
113
113
|
// The server's code and sentence, for a command that prints a refusal as it was said.
|
|
114
114
|
err.code = payload?.code ?? null;
|
|
115
115
|
err.serverMessage = payload?.error ?? null;
|
|
116
|
+
err.details = payload?.details ?? null;
|
|
116
117
|
throw err;
|
|
117
118
|
}
|
|
118
119
|
return payload ?? {};
|
|
@@ -4551,7 +4552,7 @@ async function cmdAdminSpend(ctx) {
|
|
|
4551
4552
|
const result = await staffRequest(ctx, "GET", `${SPEND}/usage-margin${params.size ? `?${params}` : ""}`);
|
|
4552
4553
|
printResult(io, flags, result, (m) =>
|
|
4553
4554
|
[
|
|
4554
|
-
`${m.range.from} → ${m.range.to}: ${m.totals.billableEvents} billable of ${m.totals.events} events · ${m.totals.tokens ?? "?"} tokens (${m.rateCards?.length > 1 ? `${m.rateCards.map((c) => c.version).join(" + ")}, each day on its own card` : (m.rateCard?.version ?? "no card")}) · cost ${usd(m.totals.cost?.totalUsd)} · margin ${m.totals.marginUsd === null ? "?" : usd(m.totals.marginUsd)}`,
|
|
4555
|
+
`${m.range.from} → ${m.range.to}: ${m.totals.billableEvents} billable of ${m.totals.events} events · ${m.totals.tokens ?? "?"} tokens (${m.rateCards?.length > 1 ? `${m.rateCards.map((c) => (c.effectiveFrom ? `${c.version} from ${c.effectiveFrom.slice(0, 10)}` : c.version)).join(" + ")}, each day on its own card` : (m.rateCard?.version ?? "no card")}) · cost ${usd(m.totals.cost?.totalUsd)} · margin ${m.totals.marginUsd === null ? "?" : usd(m.totals.marginUsd)}`,
|
|
4555
4556
|
"",
|
|
4556
4557
|
...m.rows.map(
|
|
4557
4558
|
(r) =>
|
|
@@ -5745,6 +5746,7 @@ async function cmdAdminRecipes(ctx) {
|
|
|
5745
5746
|
|
|
5746
5747
|
const LAGO = "/api/superadmin/billing/lago";
|
|
5747
5748
|
const LAGO_USAGE = `Usage: admin billing desk [--json] the Billing desk: switches, failed payments, reconcile, refusals, grants
|
|
5749
|
+
admin billing org test <org-id> --why "…" [--off] mark an org a test org (or not), kept with who and why
|
|
5748
5750
|
admin billing lago <command>
|
|
5749
5751
|
catalog [--apply] [--include-drafts] what the plan catalog would change in Lago; --apply makes it so
|
|
5750
5752
|
provision <org-id> --plan starter [--ratio 4] [--why "…" above 4x] [--complimentary 20000] [--stripe-customer cus_…] [--start 2026-11-02T00:00:00Z] [--review 2027-05-01]
|
|
@@ -5803,6 +5805,9 @@ async function cmdAdminBillingLegacy(ctx) {
|
|
|
5803
5805
|
decision,
|
|
5804
5806
|
why,
|
|
5805
5807
|
...(tokens ? { tokens: Number(tokens.replace(/[,_]/g, "")) } : {}),
|
|
5808
|
+
}).catch((err) => {
|
|
5809
|
+
if (err?.code !== "DECIDE_FAILED") throw err;
|
|
5810
|
+
throw new CliError(err.serverMessage);
|
|
5806
5811
|
});
|
|
5807
5812
|
const words = { keep: "kept legacy", free: "on free tokens", test: "marked a test org" };
|
|
5808
5813
|
printResult(io, flags, r, (x) => `${orgId}: ${words[x.decision]}${x.grantRef ? ` (${x.grantRef})` : ""}.`);
|
|
@@ -5965,6 +5970,13 @@ async function cmdAdminBillingFree(ctx) {
|
|
|
5965
5970
|
tokens,
|
|
5966
5971
|
why,
|
|
5967
5972
|
...(key ? { key } : {}),
|
|
5973
|
+
}).catch((err) => {
|
|
5974
|
+
// Didn't go through: the server's sentence and the exact retry, under the same key.
|
|
5975
|
+
if (err?.code !== "GRANT_FAILED") throw err;
|
|
5976
|
+
const retryKey = err.details?.key ?? key;
|
|
5977
|
+
throw new CliError(
|
|
5978
|
+
`${err.serverMessage}\nRetry: letterstory admin billing free grant ${orgId} ${tokens} --why ${JSON.stringify(why)}${retryKey ? ` --key ${retryKey}` : ""}`
|
|
5979
|
+
);
|
|
5968
5980
|
});
|
|
5969
5981
|
printResult(io, flags, r, (x) => {
|
|
5970
5982
|
const what = x.kind === "wallet" ? "as a one-off wallet on Lago" : "as a free-token grant";
|
|
@@ -6115,6 +6127,26 @@ async function cmdAdminBillingEmails(ctx) {
|
|
|
6115
6127
|
return 0;
|
|
6116
6128
|
}
|
|
6117
6129
|
|
|
6130
|
+
const ORG_TEST_USAGE = `Usage: admin billing org test <org-id> --why "…" [--off]
|
|
6131
|
+
Mark an org a test org (never gated or billed, out of the fleet's customer numbers), or with --off not
|
|
6132
|
+
one any more. Kept with who and why, posted to #billing. Refused for an org that pays us. Billing admins.`;
|
|
6133
|
+
|
|
6134
|
+
/** admin billing org test <org-id> --why "…" [--off] — setOrgTest (lib/billing/org-test.ts). */
|
|
6135
|
+
async function cmdAdminBillingOrg(ctx) {
|
|
6136
|
+
const { flags, positionals, io } = ctx;
|
|
6137
|
+
const orgId = positionals[2];
|
|
6138
|
+
if (positionals[1] !== "test" || !orgId) throw new CliError(ORG_TEST_USAGE);
|
|
6139
|
+
const why = flagStr(flags.why);
|
|
6140
|
+
if (!why) throw new CliError(`Say why (--why "…"): it is kept with the change.\n${ORG_TEST_USAGE}`);
|
|
6141
|
+
const r = await staffPost(ctx, "/api/superadmin/billing/orgs/test", { orgId, test: !flagBool(flags.off), why });
|
|
6142
|
+
printResult(io, flags, r, (x) =>
|
|
6143
|
+
!x.changed
|
|
6144
|
+
? `${orgId}: already ${x.isTest ? "a test org" : "not a test org"}; nothing changed.`
|
|
6145
|
+
: `${orgId}: ${x.isTest ? "now a test org (never gated or billed)" : "no longer a test org"}.`
|
|
6146
|
+
);
|
|
6147
|
+
return 0;
|
|
6148
|
+
}
|
|
6149
|
+
|
|
6118
6150
|
/** admin billing lago … — staff operations on Lago (docs/billing/lago-integration.md). */
|
|
6119
6151
|
async function cmdAdminBilling(ctx) {
|
|
6120
6152
|
const { flags, positionals, io } = ctx;
|
|
@@ -6122,6 +6154,7 @@ async function cmdAdminBilling(ctx) {
|
|
|
6122
6154
|
if (positionals[0] === "free") return cmdAdminBillingFree(ctx);
|
|
6123
6155
|
if (positionals[0] === "desk") return cmdAdminBillingDesk(ctx);
|
|
6124
6156
|
if (positionals[0] === "emails") return cmdAdminBillingEmails(ctx);
|
|
6157
|
+
if (positionals[0] === "org") return cmdAdminBillingOrg(ctx);
|
|
6125
6158
|
if (positionals[0] !== "lago") throw new CliError(LAGO_USAGE);
|
|
6126
6159
|
const sub = positionals[1];
|
|
6127
6160
|
switch (sub) {
|