@stewardhq/cli 0.8.0 → 0.10.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/README.md +38 -9
- package/dist/bin.js +365 -36
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -15,6 +15,8 @@ ESM, Node ≥ 22. Its only runtime dependency is `@stewardhq/sdk`.
|
|
|
15
15
|
| --- | --- |
|
|
16
16
|
| `steward doctor [--json]` | `GET /v1/doctor`; `APP_URL` ↔ steward `appUrl` / return origins. Exits 1 when not ready. For a product with meters, a `metering` line (the catalog's meters and metered prices, and steward's `events`, `meters`, `overage` capabilities) plus the report's `events` section (backlog, rollup lag, unmatched event names in the last 7 days' sample, invalid values, meters receiving no events) and `overage` section (`chargeMode`, metered price, subscriptions with no locked rate, rolled-over records) |
|
|
17
17
|
| `steward catalog push <file> [--yes]` | `PUT /v1/admin/catalog`; version and counts. Before the push: benefit, price, meter, credit and metered price diff against the current catalog; price and metered price changes need confirmation (prompt, or `--yes`); a catalog with benefits needs the `benefits` capability, one with meters the `meters` capability, one with an unlisted plan the `unlisted_plans` capability (`GET /v1/me`) |
|
|
18
|
+
| `steward accounts get <ref> [--include a,b] [--json]` | `GET /v1/accounts/:ref`: name, plan, the primary subscription and the metadata; `--include` adds `profile`, `subscriptions`, `checkouts`, `payments`, `invoices`, `grants` |
|
|
19
|
+
| `steward accounts metadata set <ref> <key>=<value>… [--reason <text>] [--json]` / `steward accounts metadata unset <ref> <key>… [--reason <text>] [--json]` | `PATCH /v1/accounts/:ref/metadata`: sets or removes single metadata keys and leaves the others as they are; prints each key before → after. Needs the `account_metadata` capability (`GET /v1/me`); never creates an account |
|
|
18
20
|
| `steward meters get <ref> [--periods <n>] [--json]` | `GET /v1/accounts/:ref/meters`: per meter the open period, usage, credit, balance, standing and estimated overage; `--periods` adds the most recent closed periods |
|
|
19
21
|
| `steward events send <ref> <name> [--meta k=v]… [--external-id <id>] [--timestamp <iso>] [--json]` | A single event via `POST /v1/events/ingest` (for local trials); when `externalId` is omitted one is generated and printed. Exits 1 on a rejected event |
|
|
20
22
|
| `steward settings get` | `GET /v1/admin/settings` |
|
|
@@ -32,28 +34,29 @@ ESM, Node ≥ 22. Its only runtime dependency is `@stewardhq/sdk`.
|
|
|
32
34
|
| `steward credits adjust <ref> <meter> --units=<n> --reason <text>` | A credit ledger entry; negative units = adjustment |
|
|
33
35
|
| `steward events redeliver <eventId>…` | Requeues every delivery of webhook events (admin) |
|
|
34
36
|
| `steward bank-transfers list [--status pending\|expired] [--rate <rate>]` / `steward bank-transfers record <code> --amount <minor> --currency <CUR> --received-at <iso> --bank-ref <ref> [--rate <rate>] […] [--yes]` / `steward bank-transfers fx-report [--from <iso>] [--to <iso>] [--json\|--csv]` | Bank transfer reconciliation; recording asks for confirmation. `--rate`: a transfer in another currency than the item's, at the exchange rate you enter (`list --rate` previews the expected amounts); `fx-report`: those payments for the accountant |
|
|
37
|
+
| `steward invoices list [--status draft\|issued\|void\|all] [--payment-status <status>] [--limit <n>] [--json]` / `steward invoices issue <id> --number <number> [--external-ref <ref>] [--issued-at <iso>] [--document <file.pdf>] [--yes]` | `GET /v1/admin/invoices`: the invoices not cut in the external system yet (`draft`, the default), oldest first; `POST /v1/invoices/:id/issue`: writes the external invoice number and marks the invoice issued (once; asks for confirmation, the customer is emailed) |
|
|
35
38
|
|
|
36
39
|
Exit codes: 0 success, 1 error (or doctor not ready), 2 incorrect usage.
|
|
37
40
|
|
|
38
41
|
## Connection settings
|
|
39
42
|
|
|
40
43
|
- Admin commands (`catalog`, `settings`, `endpoints`, `keys`, `dunning`, `reprice`, `credits`,
|
|
41
|
-
`bank-transfers`, `meters recompute|close-periods`, `events redeliver`): `STEWARD_ADMIN_URL` +
|
|
42
|
-
`STEWARD_ADMIN_API_KEY`. The
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
- `doctor`, `meters`, `events`: `STEWARD_URL` + `STEWARD_API_KEY`; if neither is set, the admin
|
|
44
|
+
`bank-transfers`, `invoices`, `meters recompute|close-periods`, `events redeliver`): `STEWARD_ADMIN_URL` +
|
|
45
|
+
`STEWARD_ADMIN_API_KEY`. The URL is the address where your steward serves `/v1`, for example
|
|
46
|
+
`https://billing.example.com`: its public address if the deployment exposes `/v1` there,
|
|
47
|
+
otherwise an address inside its network. The key comes from the operator.
|
|
48
|
+
- `doctor`, `accounts`, `meters`, `events`: `STEWARD_URL` + `STEWARD_API_KEY`; if neither is set, the admin
|
|
46
49
|
pair. A half pair (only the URL or only the key) does not fall back to the other pair — it
|
|
47
50
|
fails with a clear error.
|
|
48
51
|
- **The source is chosen as a whole.** If even one of `STEWARD_URL`, `STEWARD_API_KEY`,
|
|
49
52
|
`STEWARD_ADMIN_URL`, `STEWARD_ADMIN_API_KEY` is defined in the environment, the connection
|
|
50
53
|
values and `APP_URL` are read from the environment only, and the `.env.local` in the working
|
|
51
54
|
directory is not read at all. If none of them is in the environment, all of them come from
|
|
52
|
-
`.env.local`. That way, when the environment is set for a
|
|
53
|
-
|
|
55
|
+
`.env.local`. That way, when the environment is set for a production target, a product repo's
|
|
56
|
+
`.env.local` cannot redirect it.
|
|
54
57
|
- Commands print the source they used to stderr (not the values — the pair names and the
|
|
55
58
|
origin), e.g. `connection: environment · STEWARD_ADMIN_URL + STEWARD_ADMIN_API_KEY →
|
|
56
|
-
|
|
59
|
+
https://billing.example.com` (the source is `environment` or `.env.local`).
|
|
57
60
|
- Changes carry `X-Actor-Ref: operator:<operating system user>`.
|
|
58
61
|
|
|
59
62
|
## Secrets
|
|
@@ -111,6 +114,23 @@ capability: an older steward would drop the key and offer the plan.
|
|
|
111
114
|
rollup job processes it (seconds).
|
|
112
115
|
- Details: [metering guide](https://github.com/z9cloud/steward/blob/main/docs/integrate/metering.md).
|
|
113
116
|
|
|
117
|
+
## Account metadata
|
|
118
|
+
|
|
119
|
+
- `steward accounts get <ref>` prints the account as the product sees it at `GET /v1/accounts/:ref`,
|
|
120
|
+
with its metadata keys and values.
|
|
121
|
+
- `steward accounts metadata set <ref> tier=gold --reason "moved to gold"` and
|
|
122
|
+
`steward accounts metadata unset <ref> tier` change single keys. `key=value` is split at the
|
|
123
|
+
first `=`; a key is at most 64 characters, a value at most 500. The command checks that steward
|
|
124
|
+
lists the `account_metadata` capability, reads the account, prints each key's value before and
|
|
125
|
+
after (`tier: silver → gold`, `tier: gold → (removed)`), then sends one `PATCH`. An invalid
|
|
126
|
+
key or value is exit 2 and nothing is sent.
|
|
127
|
+
- Steward merges the keys in one atomic write: a key the product (or another operator) changes at
|
|
128
|
+
the same time is not overwritten. The change is in steward's audit trail with the key names,
|
|
129
|
+
`--reason` and `operator:<user>`; the account state does not change and no event is sent, so
|
|
130
|
+
running it again is harmless and there is no confirmation prompt.
|
|
131
|
+
- The account must exist: the commands never create one (exit 1 on `account_not_found`). Do not
|
|
132
|
+
put personal data (name, email, phone) in metadata.
|
|
133
|
+
|
|
114
134
|
## Versions
|
|
115
135
|
|
|
116
136
|
Release: bump the version in `cli/package.json` and push the `cli-v<version>` tag
|
|
@@ -118,6 +138,15 @@ Release: bump the version in `cli/package.json` and push the `cli-v<version>` ta
|
|
|
118
138
|
be published on npm. **The first version on npmjs is 0.5.0** (2026-09-21); 0.4.0 was not
|
|
119
139
|
published.
|
|
120
140
|
|
|
141
|
+
- **0.10.0** (`@stewardhq/sdk` 0.10, which adds `admin.invoices.list`):
|
|
142
|
+
`steward invoices list` (the invoices not issued yet, i.e. without the external system's number)
|
|
143
|
+
and `steward invoices issue <id> --number <number>` (writes that number). `bank-transfers list`
|
|
144
|
+
shows an `INVOICE NO` column.
|
|
145
|
+
- **0.9.0** (`@stewardhq/sdk` 0.9, which adds `accounts.updateMetadata`):
|
|
146
|
+
`steward accounts get`, `steward accounts metadata set` and `unset` (single metadata keys, merged
|
|
147
|
+
by steward in one atomic write; requires the `account_metadata` capability). Also: the connection
|
|
148
|
+
hint and the "could not reach steward" hint no longer name one deployment's host or assume a
|
|
149
|
+
particular way of reaching steward (messages only).
|
|
121
150
|
- **0.8.0** (`@stewardhq/sdk` 0.8, bank transfers in another currency, issue #55):
|
|
122
151
|
`bank-transfers record --rate`, `bank-transfers list --rate [--currency]`,
|
|
123
152
|
`bank-transfers fx-report [--from] [--to] [--json|--csv]`. Unlisted plans: `catalog push` shows
|
|
@@ -129,7 +158,7 @@ published.
|
|
|
129
158
|
`steward reprice`, `steward credits adjust`, `steward bank-transfers`, `steward meters recompute` and
|
|
130
159
|
`close-periods`, `steward events redeliver`, `settings set --provider`. These replace the pod CLI
|
|
131
160
|
commands of the same jobs. `doctor` lists the active API keys with age, last use and expiry; the
|
|
132
|
-
connection hint names the public admin host
|
|
161
|
+
connection hint names the public admin host.
|
|
133
162
|
- **0.5.0** (`@stewardhq/sdk` 0.5, metering phase 2): `steward meters get`, `steward events
|
|
134
163
|
send`; meter, credit and metered price diff in `catalog push` (a metered price change asks
|
|
135
164
|
for confirmation; a catalog with meters is not pushed without the `meters` capability);
|
package/dist/bin.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { userInfo } from "node:os";
|
|
3
3
|
import { createInterface } from "node:readline/promises";
|
|
4
4
|
import { setTimeout } from "node:timers/promises";
|
|
5
|
-
import { ApiKeyCreateInputSchema, BankTransferRecordInputSchema, CatalogSyncInputSchema, CreditAdjustmentInputSchema, DunningPolicySchema, EventsIngestInputSchema, FxRateSchema, METER_CHARGE_MODES, MeterCreditPropertiesSchema, ProductSettingsPatchSchema, RepriceInputSchema, StewardApiError, StewardConfigError, StewardError, StewardNetworkError, WebhookEndpointCreateInputSchema, WebhookEndpointRotateInputSchema, createSteward, generateApiKeyToken, generateWebhookSecret, plainDecimalOf } from "@stewardhq/sdk";
|
|
5
|
+
import { ACCOUNT_INCLUDES, AccountMetadataPatchInputSchema, ApiKeyCreateInputSchema, BankTransferRecordInputSchema, CatalogSyncInputSchema, CreditAdjustmentInputSchema, DunningPolicySchema, EventsIngestInputSchema, FxRateSchema, InvoiceIssueInputSchema, InvoicePaymentStatusSchema, InvoiceStatusSchema, METER_CHARGE_MODES, MeterCreditPropertiesSchema, ProductSettingsPatchSchema, RepriceInputSchema, StewardApiError, StewardConfigError, StewardError, StewardNetworkError, WebhookEndpointCreateInputSchema, WebhookEndpointRotateInputSchema, createSteward, generateApiKeyToken, generateWebhookSecret, plainDecimalOf } from "@stewardhq/sdk";
|
|
6
6
|
import { parseArgs } from "node:util";
|
|
7
7
|
import { basename, dirname, extname, join, relative, resolve } from "node:path";
|
|
8
8
|
import { link, lstat, readFile, rename, unlink, writeFile } from "node:fs/promises";
|
|
@@ -360,18 +360,6 @@ function priceChangeCount(diff) {
|
|
|
360
360
|
return diff.prices.changed.length + diff.meteredPrices.changed.length;
|
|
361
361
|
}
|
|
362
362
|
//#endregion
|
|
363
|
-
//#region src/confirm.ts
|
|
364
|
-
/**
|
|
365
|
-
* Asks before a change that cannot be taken back; `yes` (`--yes`) skips the question. Without a
|
|
366
|
-
* terminal (CI, pipes) the command needs `--yes`: `notConfirmed` says what was not done.
|
|
367
|
-
*/
|
|
368
|
-
async function confirm(ctx, question, options) {
|
|
369
|
-
if (options.yes) return true;
|
|
370
|
-
const answer = await ctx.prompt(`${question} [y/N] `);
|
|
371
|
-
if (answer === null) throw new CliError(`confirmation needed: run again with --yes (${options.notConfirmed})`);
|
|
372
|
-
return /^y(es)?$/i.test(answer.trim());
|
|
373
|
-
}
|
|
374
|
-
//#endregion
|
|
375
363
|
//#region src/dotenv.ts
|
|
376
364
|
const LINE = /^(\s*)(export\s+)?([A-Za-z_][A-Za-z0-9_.-]*)\s*=(.*)$/;
|
|
377
365
|
function unquote(rest) {
|
|
@@ -458,7 +446,7 @@ function whereMissing(env) {
|
|
|
458
446
|
case "missing": return `not set (environment variable or ./${ENV_LOCAL}; no such file)`;
|
|
459
447
|
}
|
|
460
448
|
}
|
|
461
|
-
const ADMIN_HINT = "Set them as environment variables or in ./.env.local.
|
|
449
|
+
const ADMIN_HINT = "Set them as environment variables or in ./.env.local. STEWARD_ADMIN_URL is the address where your steward serves /v1 (for example https://billing.example.com); the admin key comes from its operator.";
|
|
462
450
|
function pairError(names, missing, env) {
|
|
463
451
|
return new CliError(`${names.url} + ${names.key} required: ${missing.join(" and ")} ${whereMissing(env)}.\n${ADMIN_HINT}`);
|
|
464
452
|
}
|
|
@@ -529,7 +517,7 @@ const CODE_HINTS = {
|
|
|
529
517
|
function describeStewardError(error, target) {
|
|
530
518
|
const where = target ? ` (${originOf(target.url)})` : "";
|
|
531
519
|
const request = error.requestId !== void 0 ? ` [request ${error.requestId}]` : "";
|
|
532
|
-
if (error instanceof StewardNetworkError) return `could not reach steward${where}: ${error.code === "timeout" ? "timed out" : "could not connect"}. Is the address right
|
|
520
|
+
if (error instanceof StewardNetworkError) return `could not reach steward${where}: ${error.code === "timeout" ? "timed out" : "could not connect"}. Is the address right and reachable from this machine?`;
|
|
533
521
|
if (error instanceof StewardConfigError) return `configuration error: ${error.message}`;
|
|
534
522
|
if (error instanceof StewardApiError) {
|
|
535
523
|
const hint = error.httpStatus === 401 ? " — the key is invalid or revoked" : error.httpStatus === 403 ? " — this operation needs an admin-scoped key" : Object.hasOwn(CODE_HINTS, error.code) ? CODE_HINTS[error.code] : "";
|
|
@@ -539,6 +527,195 @@ function describeStewardError(error, target) {
|
|
|
539
527
|
return `steward response does not match the contract${where}: ${error.code} (HTTP ${error.httpStatus}) — the CLI and steward versions may be incompatible${request}`;
|
|
540
528
|
}
|
|
541
529
|
//#endregion
|
|
530
|
+
//#region src/commands/accounts.ts
|
|
531
|
+
const ACCOUNTS_USAGE = `Usage:
|
|
532
|
+
steward accounts get <ref> [--include <a,b>] [--json]
|
|
533
|
+
steward accounts metadata set <ref> <key>=<value>… [--reason <text>] [--json]
|
|
534
|
+
steward accounts metadata unset <ref> <key>… [--reason <text>] [--json]
|
|
535
|
+
|
|
536
|
+
get reads an account (GET /v1/accounts/:ref): name, plan, the primary subscription and the
|
|
537
|
+
metadata. Nothing is written.
|
|
538
|
+
|
|
539
|
+
--include <a,b> also read profile, subscriptions, checkouts, payments, invoices, grants
|
|
540
|
+
(comma separated). Subscriptions are listed, the others are counted; --json
|
|
541
|
+
prints the whole response.
|
|
542
|
+
--json print the response as JSON
|
|
543
|
+
|
|
544
|
+
metadata set / unset change single metadata keys (PATCH /v1/accounts/:ref/metadata) and leave
|
|
545
|
+
every other key as it is. Steward merges them in one atomic write, so the change cannot
|
|
546
|
+
overwrite a key another writer (the product, another operator) changes at the same time. The
|
|
547
|
+
command reads the account first, prints each key's value before and after, then sends the
|
|
548
|
+
change. Steward records it in the audit trail with the key names, --reason and the operator;
|
|
549
|
+
the account state does not change and no event is emitted. Running it again is harmless.
|
|
550
|
+
|
|
551
|
+
<key>=<value> split at the first "="; key at most 64 characters, value at most 500. An
|
|
552
|
+
empty value (key=) is stored as empty text; unset removes the key.
|
|
553
|
+
--reason <text> why (3–500 characters); kept in the audit trail only
|
|
554
|
+
--json print the updated account as JSON (the before → after lines go to stderr)
|
|
555
|
+
|
|
556
|
+
The account must exist: these commands never create one (404 account_not_found). Metadata
|
|
557
|
+
must not carry personal data (names, e-mail addresses, phone numbers): use opaque ids and
|
|
558
|
+
flags. set and unset need a steward whose GET /v1/me lists the "account_metadata" capability.
|
|
559
|
+
|
|
560
|
+
Connection: STEWARD_URL + STEWARD_API_KEY (or, when neither is set, STEWARD_ADMIN_URL +
|
|
561
|
+
STEWARD_ADMIN_API_KEY). Environment, otherwise ./.env.local. Changes are sent with
|
|
562
|
+
X-Actor-Ref operator:<user>.
|
|
563
|
+
Exit code 1: steward refused (unknown or deleted account, no capability); 2: wrong usage,
|
|
564
|
+
nothing was sent.`;
|
|
565
|
+
const GET_OPTIONS$1 = {
|
|
566
|
+
...HELP_OPTION,
|
|
567
|
+
include: { type: "string" },
|
|
568
|
+
json: { type: "boolean" }
|
|
569
|
+
};
|
|
570
|
+
const METADATA_OPTIONS = {
|
|
571
|
+
...HELP_OPTION,
|
|
572
|
+
reason: { type: "string" },
|
|
573
|
+
json: { type: "boolean" }
|
|
574
|
+
};
|
|
575
|
+
/** A metadata value on one terminal line: as is, or JSON-quoted when empty, padded or with control characters. */
|
|
576
|
+
function show(value) {
|
|
577
|
+
return value === "" || value !== value.trim() || /\p{Cc}/u.test(value) ? JSON.stringify(value) : value;
|
|
578
|
+
}
|
|
579
|
+
/** Human-readable account read: name, plan, primary subscription, metadata, and the included parts. */
|
|
580
|
+
function formatAccount(account) {
|
|
581
|
+
const { snapshot } = account;
|
|
582
|
+
const lines = [
|
|
583
|
+
`account ${account.ref} · ${account.displayName}`,
|
|
584
|
+
` created ${account.createdAt}`,
|
|
585
|
+
` plan ${snapshot.planCode} · access ${snapshot.accessState}`
|
|
586
|
+
];
|
|
587
|
+
const sub = snapshot.subscription;
|
|
588
|
+
if (sub === null) lines.push(" subscription none");
|
|
589
|
+
else {
|
|
590
|
+
const ends = sub.cancelAt !== null ? `cancels at ${sub.cancelAt}` : `period ends ${sub.currentPeriodEnd ?? "-"}`;
|
|
591
|
+
lines.push(` subscription ${sub.status} · ${sub.planCode} ${sub.interval} · ${formatMinor(sub.amountMinor, sub.currency)} · ${ends}`);
|
|
592
|
+
}
|
|
593
|
+
const keys = Object.keys(account.metadata);
|
|
594
|
+
if (keys.length === 0) lines.push(" metadata none");
|
|
595
|
+
else {
|
|
596
|
+
lines.push(" metadata");
|
|
597
|
+
const width = Math.max(...keys.map((key) => key.length));
|
|
598
|
+
for (const key of keys) lines.push(` ${key.padEnd(width)} ${show(account.metadata[key])}`);
|
|
599
|
+
}
|
|
600
|
+
if (account.profile !== void 0) lines.push(` profile ${account.profile === null ? "none" : account.profile.kind}`);
|
|
601
|
+
if (account.subscriptions !== void 0) {
|
|
602
|
+
lines.push(` subscriptions ${account.subscriptions.length}`);
|
|
603
|
+
for (const s of account.subscriptions) lines.push(` ${s.id} ${s.status} · ${s.planCode} ${s.interval} · ${formatMinor(s.amountMinor, s.currency)} · period ends ${s.currentPeriodEnd ?? "-"}`);
|
|
604
|
+
}
|
|
605
|
+
for (const part of [
|
|
606
|
+
"checkouts",
|
|
607
|
+
"payments",
|
|
608
|
+
"invoices",
|
|
609
|
+
"grants"
|
|
610
|
+
]) {
|
|
611
|
+
const items = account[part];
|
|
612
|
+
if (items !== void 0) lines.push(` ${part.padEnd(13)} ${items.length}${items.length > 0 ? " (--json for the details)" : ""}`);
|
|
613
|
+
}
|
|
614
|
+
return lines;
|
|
615
|
+
}
|
|
616
|
+
async function getCommand(ctx, out, args) {
|
|
617
|
+
const { values, positionals } = parse(args, GET_OPTIONS$1, "accounts");
|
|
618
|
+
if (values.help) {
|
|
619
|
+
out.out(ACCOUNTS_USAGE);
|
|
620
|
+
return 0;
|
|
621
|
+
}
|
|
622
|
+
expectPositionals(positionals, 1, 1, "accounts");
|
|
623
|
+
const ref = positionals[0];
|
|
624
|
+
const include = values.include === void 0 ? [] : parseList(values.include);
|
|
625
|
+
const unknown = include.filter((item) => !ACCOUNT_INCLUDES.includes(item));
|
|
626
|
+
if (unknown.length > 0) throw new UsageError(`--include: unknown ${unknown.join(", ")} (one of: ${ACCOUNT_INCLUDES.join(", ")})`);
|
|
627
|
+
const target = requireReadTarget(await resolveEnv(ctx));
|
|
628
|
+
out.err(connectionLine(target));
|
|
629
|
+
const account = await callSteward(target, () => clientFor(ctx, target).accounts.get(ref, { include }));
|
|
630
|
+
if (values.json) out.out(JSON.stringify(account, null, 2));
|
|
631
|
+
else for (const line of formatAccount(account)) out.out(line);
|
|
632
|
+
return 0;
|
|
633
|
+
}
|
|
634
|
+
/** `key=value` arguments (split at the first `=`) or bare keys → the patch: a value sets, `null` removes. */
|
|
635
|
+
function parseMetadataChange(action, items) {
|
|
636
|
+
const change = /* @__PURE__ */ new Map();
|
|
637
|
+
for (const item of items) {
|
|
638
|
+
const at = action === "set" ? item.indexOf("=") : item.length;
|
|
639
|
+
if (at <= 0) throw new UsageError(action === "set" ? `expected key=value, got "${item}"` : "a key cannot be empty");
|
|
640
|
+
const key = item.slice(0, at);
|
|
641
|
+
if (key === "__proto__") throw new UsageError("key \"__proto__\" is not accepted");
|
|
642
|
+
if (change.has(key)) throw new UsageError(`key "${key}" given twice`);
|
|
643
|
+
change.set(key, action === "set" ? item.slice(at + 1) : null);
|
|
644
|
+
}
|
|
645
|
+
return Object.fromEntries(change);
|
|
646
|
+
}
|
|
647
|
+
/** One line per key of the patch: its value now and after the patch. */
|
|
648
|
+
function changeLines(current, change) {
|
|
649
|
+
return Object.entries(change).map(([key, value]) => {
|
|
650
|
+
const before = Object.hasOwn(current, key) ? current[key] : null;
|
|
651
|
+
const from = before === null ? "(none)" : show(before);
|
|
652
|
+
if (value === null) return ` ${key}: ${from} → ${before === null ? "(none) (unchanged)" : "(removed)"}`;
|
|
653
|
+
return ` ${key}: ${from} → ${show(value)}${before === value ? " (unchanged)" : ""}`;
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
/** An older steward has no metadata patch endpoint: its 404 would read like a missing account. */
|
|
657
|
+
async function requireMetadataCapability(steward, target) {
|
|
658
|
+
if (((await callSteward(target, () => steward.me())).capabilities ?? []).includes("account_metadata")) return;
|
|
659
|
+
throw new CliError(`steward at ${originOf(target.url)} does not support changing single metadata keys (GET /v1/me capabilities has no "account_metadata"). Update steward first; nothing was sent.`);
|
|
660
|
+
}
|
|
661
|
+
async function metadataCommand(ctx, out, args) {
|
|
662
|
+
const [action, ...rest] = args;
|
|
663
|
+
if (action === void 0 || action === "--help" || action === "-h" || action === "help") {
|
|
664
|
+
out.out(ACCOUNTS_USAGE);
|
|
665
|
+
return action === void 0 ? 2 : 0;
|
|
666
|
+
}
|
|
667
|
+
if (action !== "set" && action !== "unset") throw new UsageError(`unknown subcommand: accounts metadata ${action} (see: steward accounts --help)`);
|
|
668
|
+
const { values, positionals } = parse(rest, METADATA_OPTIONS, "accounts");
|
|
669
|
+
if (values.help) {
|
|
670
|
+
out.out(ACCOUNTS_USAGE);
|
|
671
|
+
return 0;
|
|
672
|
+
}
|
|
673
|
+
expectPositionals(positionals, 2, 101, "accounts");
|
|
674
|
+
const [ref, ...items] = positionals;
|
|
675
|
+
const input = AccountMetadataPatchInputSchema.safeParse({
|
|
676
|
+
metadata: parseMetadataChange(action, items),
|
|
677
|
+
...values.reason !== void 0 ? { reason: values.reason } : {}
|
|
678
|
+
});
|
|
679
|
+
if (!input.success) throw new UsageError(`invalid metadata change (nothing was sent)\n${input.error.issues.map((issue) => ` - ${issue.path.map(String).join(".") || "(root)"}: ${issue.message}`).join("\n")}`);
|
|
680
|
+
const target = requireReadTarget(await resolveEnv(ctx));
|
|
681
|
+
out.err(connectionLine(target));
|
|
682
|
+
const steward = clientFor(ctx, target);
|
|
683
|
+
await requireMetadataCapability(steward, target);
|
|
684
|
+
const current = await callSteward(target, () => steward.accounts.get(ref));
|
|
685
|
+
const say = values.json ? out.err : out.out;
|
|
686
|
+
say(`metadata of ${ref}:`);
|
|
687
|
+
for (const line of changeLines(current.metadata, input.data.metadata)) say(line);
|
|
688
|
+
const updated = await callSteward(target, () => steward.accounts.updateMetadata(ref, input.data));
|
|
689
|
+
if (values.json) out.out(JSON.stringify(updated, null, 2));
|
|
690
|
+
else {
|
|
691
|
+
const count = Object.keys(updated.metadata).length;
|
|
692
|
+
out.out(`written → ${originOf(target.url)}: ${ref} now has ${count} metadata key${count === 1 ? "" : "s"}`);
|
|
693
|
+
}
|
|
694
|
+
return 0;
|
|
695
|
+
}
|
|
696
|
+
async function accountsCommand(ctx, out, args) {
|
|
697
|
+
const [sub, ...rest] = args;
|
|
698
|
+
if (sub === void 0 || sub === "--help" || sub === "-h" || sub === "help") {
|
|
699
|
+
out.out(ACCOUNTS_USAGE);
|
|
700
|
+
return sub === void 0 ? 2 : 0;
|
|
701
|
+
}
|
|
702
|
+
if (sub === "get") return getCommand(ctx, out, rest);
|
|
703
|
+
if (sub === "metadata") return metadataCommand(ctx, out, rest);
|
|
704
|
+
throw new UsageError(`unknown subcommand: accounts ${sub} (see: steward accounts --help)`);
|
|
705
|
+
}
|
|
706
|
+
//#endregion
|
|
707
|
+
//#region src/confirm.ts
|
|
708
|
+
/**
|
|
709
|
+
* Asks before a change that cannot be taken back; `yes` (`--yes`) skips the question. Without a
|
|
710
|
+
* terminal (CI, pipes) the command needs `--yes`: `notConfirmed` says what was not done.
|
|
711
|
+
*/
|
|
712
|
+
async function confirm(ctx, question, options) {
|
|
713
|
+
if (options.yes) return true;
|
|
714
|
+
const answer = await ctx.prompt(`${question} [y/N] `);
|
|
715
|
+
if (answer === null) throw new CliError(`confirmation needed: run again with --yes (${options.notConfirmed})`);
|
|
716
|
+
return /^y(es)?$/i.test(answer.trim());
|
|
717
|
+
}
|
|
718
|
+
//#endregion
|
|
542
719
|
//#region src/secret-file.ts
|
|
543
720
|
async function withSecretFile(cwd, out, secret, options, action) {
|
|
544
721
|
const target = resolve(cwd, out);
|
|
@@ -629,7 +806,7 @@ async function endpointsCommand(ctx, out, args) {
|
|
|
629
806
|
...HELP_OPTION,
|
|
630
807
|
json: { type: "boolean" }
|
|
631
808
|
}, "endpoints");
|
|
632
|
-
if (values.help) return help$
|
|
809
|
+
if (values.help) return help$4(out);
|
|
633
810
|
expectPositionals(positionals, 0, 0, "endpoints");
|
|
634
811
|
const target = requireAdminTarget(await resolveEnv(ctx));
|
|
635
812
|
out.err(connectionLine(target));
|
|
@@ -664,7 +841,7 @@ async function endpointsCommand(ctx, out, args) {
|
|
|
664
841
|
description: { type: "string" },
|
|
665
842
|
force: { type: "boolean" }
|
|
666
843
|
}, ENDPOINTS_USAGE);
|
|
667
|
-
if (values.help) return help$
|
|
844
|
+
if (values.help) return help$4(out);
|
|
668
845
|
expectPositionals(positionals, 0, 0, "endpoints");
|
|
669
846
|
const url = requireOption(values.url, "--url", "endpoints");
|
|
670
847
|
const file = requireOption(values.out, "--out", "endpoints");
|
|
@@ -695,7 +872,7 @@ async function endpointsCommand(ctx, out, args) {
|
|
|
695
872
|
out: { type: "string" },
|
|
696
873
|
force: { type: "boolean" }
|
|
697
874
|
}, "endpoints");
|
|
698
|
-
if (values.help) return help$
|
|
875
|
+
if (values.help) return help$4(out);
|
|
699
876
|
expectPositionals(positionals, 1, 1, "endpoints");
|
|
700
877
|
const id = positionals[0];
|
|
701
878
|
const file = requireOption(values.out, "--out", "endpoints");
|
|
@@ -714,7 +891,7 @@ async function endpointsCommand(ctx, out, args) {
|
|
|
714
891
|
}
|
|
715
892
|
if (sub === "deactivate") {
|
|
716
893
|
const { values, positionals } = parse(rest, { ...HELP_OPTION }, "endpoints");
|
|
717
|
-
if (values.help) return help$
|
|
894
|
+
if (values.help) return help$4(out);
|
|
718
895
|
expectPositionals(positionals, 1, 1, "endpoints");
|
|
719
896
|
const target = requireAdminTarget(await resolveEnv(ctx));
|
|
720
897
|
out.err(connectionLine(target));
|
|
@@ -724,7 +901,7 @@ async function endpointsCommand(ctx, out, args) {
|
|
|
724
901
|
}
|
|
725
902
|
throw new UsageError(`unknown subcommand: endpoints ${sub} (details: steward endpoints --help)`);
|
|
726
903
|
}
|
|
727
|
-
function help$
|
|
904
|
+
function help$4(out) {
|
|
728
905
|
out.out(ENDPOINTS_USAGE);
|
|
729
906
|
return 0;
|
|
730
907
|
}
|
|
@@ -752,7 +929,9 @@ transfer and unpaid invoices of accounts with an order code, by deadline; expire
|
|
|
752
929
|
that expired in the last 30 days. --rate previews a transfer in another currency: next to each
|
|
753
930
|
item the product lets be paid in another currency (settings.billing.bankTransfer.settleIn) it
|
|
754
931
|
shows the amount expected at that rate (--currency names it when an item accepts several). It
|
|
755
|
-
writes nothing.
|
|
932
|
+
writes nothing. INVOICE NO is the number an invoice was issued with in the external system
|
|
933
|
+
(- : not issued yet, or a checkout, whose invoice is written when the transfer is recorded;
|
|
934
|
+
see steward invoices --help).
|
|
756
935
|
|
|
757
936
|
record: a transfer seen on the bank account. <code> is the order code from the transfer
|
|
758
937
|
description (case and dashes are forgiven). Only a checkout or unpaid invoice waiting for
|
|
@@ -776,7 +955,7 @@ amount received, the rate entered, received date), latest first; --from (inclusi
|
|
|
776
955
|
exchange-difference invoices, which steward does not issue.
|
|
777
956
|
|
|
778
957
|
Connection: STEWARD_ADMIN_URL + STEWARD_ADMIN_API_KEY (environment, otherwise ./.env.local).`;
|
|
779
|
-
const WITH_OFFSET = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2})$/;
|
|
958
|
+
const WITH_OFFSET$1 = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2})$/;
|
|
780
959
|
async function bankTransfersCommand(ctx, out, args) {
|
|
781
960
|
const [sub, ...rest] = args;
|
|
782
961
|
if (sub === void 0 || sub === "--help" || sub === "-h" || sub === "help") {
|
|
@@ -791,7 +970,7 @@ async function bankTransfersCommand(ctx, out, args) {
|
|
|
791
970
|
currency: { type: "string" },
|
|
792
971
|
json: { type: "boolean" }
|
|
793
972
|
}, "bank-transfers");
|
|
794
|
-
if (values.help) return help$
|
|
973
|
+
if (values.help) return help$3(out);
|
|
795
974
|
expectPositionals(positionals, 0, 0, "bank-transfers");
|
|
796
975
|
const status = values.status ?? "pending";
|
|
797
976
|
if (status !== "pending" && status !== "expired") throw new UsageError("--status: pending or expired");
|
|
@@ -815,6 +994,7 @@ async function bankTransfersCommand(ctx, out, args) {
|
|
|
815
994
|
...rate !== void 0 ? [`EXPECTED @ ${rate}`] : [],
|
|
816
995
|
"DEADLINE",
|
|
817
996
|
"KIND",
|
|
997
|
+
"INVOICE NO",
|
|
818
998
|
"PLAN",
|
|
819
999
|
"ACCOUNT",
|
|
820
1000
|
"ID"
|
|
@@ -825,6 +1005,7 @@ async function bankTransfersCommand(ctx, out, args) {
|
|
|
825
1005
|
...rate !== void 0 ? [i.expectedMinor !== void 0 && i.expectedCurrency !== void 0 ? formatMinor(i.expectedMinor, i.expectedCurrency) : "-"] : [],
|
|
826
1006
|
i.deadline ?? "-",
|
|
827
1007
|
i.kind,
|
|
1008
|
+
i.invoiceNumber ?? "-",
|
|
828
1009
|
i.planCode ?? "-",
|
|
829
1010
|
i.accountRef,
|
|
830
1011
|
i.id
|
|
@@ -850,10 +1031,10 @@ async function bankTransfersCommand(ctx, out, args) {
|
|
|
850
1031
|
},
|
|
851
1032
|
json: { type: "boolean" }
|
|
852
1033
|
}, "bank-transfers");
|
|
853
|
-
if (values.help) return help$
|
|
1034
|
+
if (values.help) return help$3(out);
|
|
854
1035
|
expectPositionals(positionals, 1, 1, "bank-transfers");
|
|
855
1036
|
const receivedAt = requireOption(values["received-at"], "--received-at", "bank-transfers");
|
|
856
|
-
if (!WITH_OFFSET.test(receivedAt)) throw new UsageError("--received-at: ISO-8601 with an offset (2026-09-28T10:15:00+03:00)");
|
|
1037
|
+
if (!WITH_OFFSET$1.test(receivedAt)) throw new UsageError("--received-at: ISO-8601 with an offset (2026-09-28T10:15:00+03:00)");
|
|
857
1038
|
const input = {
|
|
858
1039
|
code: positionals[0],
|
|
859
1040
|
amountMinor: parseNonNegativeInt(requireOption(values.amount, "--amount", "bank-transfers"), "--amount"),
|
|
@@ -893,11 +1074,11 @@ async function bankTransfersCommand(ctx, out, args) {
|
|
|
893
1074
|
json: { type: "boolean" },
|
|
894
1075
|
csv: { type: "boolean" }
|
|
895
1076
|
}, "bank-transfers");
|
|
896
|
-
if (values.help) return help$
|
|
1077
|
+
if (values.help) return help$3(out);
|
|
897
1078
|
expectPositionals(positionals, 0, 0, "bank-transfers");
|
|
898
1079
|
if (values.json && values.csv) throw new UsageError("--json or --csv, not both");
|
|
899
|
-
if (values.from !== void 0 && !WITH_OFFSET.test(values.from)) throw new UsageError("--from: ISO-8601 with an offset (2026-09-01T00:00:00+03:00)");
|
|
900
|
-
if (values.to !== void 0 && !WITH_OFFSET.test(values.to)) throw new UsageError("--to: ISO-8601 with an offset (2026-10-01T00:00:00+03:00)");
|
|
1080
|
+
if (values.from !== void 0 && !WITH_OFFSET$1.test(values.from)) throw new UsageError("--from: ISO-8601 with an offset (2026-09-01T00:00:00+03:00)");
|
|
1081
|
+
if (values.to !== void 0 && !WITH_OFFSET$1.test(values.to)) throw new UsageError("--to: ISO-8601 with an offset (2026-10-01T00:00:00+03:00)");
|
|
901
1082
|
const range = {
|
|
902
1083
|
...values.from !== void 0 ? { from: values.from } : {},
|
|
903
1084
|
...values.to !== void 0 ? { to: values.to } : {}
|
|
@@ -958,7 +1139,7 @@ function csvField(value) {
|
|
|
958
1139
|
const text = typeof value === "string" && /^[=+\-@]/.test(value) ? `'${value}` : String(value);
|
|
959
1140
|
return /[",\n\r]/.test(text) ? `"${text.replace(/"/g, "\"\"")}"` : text;
|
|
960
1141
|
}
|
|
961
|
-
function help$
|
|
1142
|
+
function help$3(out) {
|
|
962
1143
|
out.out(BANK_TRANSFERS_USAGE);
|
|
963
1144
|
return 0;
|
|
964
1145
|
}
|
|
@@ -1578,7 +1759,7 @@ async function dunningCommand(ctx, out, args) {
|
|
|
1578
1759
|
...HELP_OPTION,
|
|
1579
1760
|
json: { type: "boolean" }
|
|
1580
1761
|
}, "dunning");
|
|
1581
|
-
if (values.help) return help$
|
|
1762
|
+
if (values.help) return help$2(out);
|
|
1582
1763
|
expectPositionals(positionals, 0, 0, "dunning");
|
|
1583
1764
|
const target = requireAdminTarget(await resolveEnv(ctx));
|
|
1584
1765
|
out.err(connectionLine(target));
|
|
@@ -1595,7 +1776,7 @@ async function dunningCommand(ctx, out, args) {
|
|
|
1595
1776
|
short: "y"
|
|
1596
1777
|
}
|
|
1597
1778
|
}, "dunning");
|
|
1598
|
-
if (values.help) return help$
|
|
1779
|
+
if (values.help) return help$2(out);
|
|
1599
1780
|
expectPositionals(positionals, 1, 1, "dunning");
|
|
1600
1781
|
const file = positionals[0];
|
|
1601
1782
|
let json;
|
|
@@ -1628,7 +1809,7 @@ async function dunningCommand(ctx, out, args) {
|
|
|
1628
1809
|
}
|
|
1629
1810
|
throw new UsageError(`unknown subcommand: dunning ${sub} (see: steward dunning --help)`);
|
|
1630
1811
|
}
|
|
1631
|
-
function help$
|
|
1812
|
+
function help$2(out) {
|
|
1632
1813
|
out.out(DUNNING_USAGE);
|
|
1633
1814
|
return 0;
|
|
1634
1815
|
}
|
|
@@ -1760,6 +1941,150 @@ async function redeliverCommand(ctx, out, args) {
|
|
|
1760
1941
|
return 0;
|
|
1761
1942
|
}
|
|
1762
1943
|
//#endregion
|
|
1944
|
+
//#region src/commands/invoices.ts
|
|
1945
|
+
const INVOICES_USAGE = `Usage:
|
|
1946
|
+
steward invoices list [--status draft|issued|void|all] [--payment-status <status>]
|
|
1947
|
+
[--limit <n>] [--json]
|
|
1948
|
+
steward invoices issue <id> --number <number> [--external-ref <ref>] [--issued-at <iso>]
|
|
1949
|
+
[--document <file.pdf>] [--yes] [--json]
|
|
1950
|
+
|
|
1951
|
+
Tracking which invoices have been cut in the external system (e-Arşiv, the accountant's software).
|
|
1952
|
+
|
|
1953
|
+
list: the product's invoices, oldest first (GET /v1/admin/invoices). draft (default): the ones
|
|
1954
|
+
not issued yet, i.e. with no number of the external system; issued: the ones that have it; all:
|
|
1955
|
+
every status. --payment-status narrows it (unpaid, paid, …). --limit: 1–500, default 100; a
|
|
1956
|
+
cut list says so on stderr.
|
|
1957
|
+
|
|
1958
|
+
issue: writes the number the invoice got in the external system and marks it issued
|
|
1959
|
+
(POST /v1/invoices/:id/issue). --number is unique within the product. --external-ref is any
|
|
1960
|
+
further reference of that system; --document attaches the PDF (at most 5 MB); --issued-at is
|
|
1961
|
+
ISO-8601 with an offset (default: now). Issuing needs confirmation (a prompt on a terminal,
|
|
1962
|
+
otherwise --yes): it is written once and cannot be changed, the customer gets the "invoice
|
|
1963
|
+
issued" email and the product an invoice.issued event.
|
|
1964
|
+
|
|
1965
|
+
Connection: STEWARD_ADMIN_URL + STEWARD_ADMIN_API_KEY (environment, otherwise ./.env.local).`;
|
|
1966
|
+
const WITH_OFFSET = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2})$/;
|
|
1967
|
+
const MAX_DOCUMENT_BYTES = 5242880;
|
|
1968
|
+
async function invoicesCommand(ctx, out, args) {
|
|
1969
|
+
const [sub, ...rest] = args;
|
|
1970
|
+
if (sub === void 0 || sub === "--help" || sub === "-h" || sub === "help") {
|
|
1971
|
+
out.out(INVOICES_USAGE);
|
|
1972
|
+
return sub === void 0 ? 2 : 0;
|
|
1973
|
+
}
|
|
1974
|
+
if (sub === "list") {
|
|
1975
|
+
const { values, positionals } = parse(rest, {
|
|
1976
|
+
...HELP_OPTION,
|
|
1977
|
+
status: { type: "string" },
|
|
1978
|
+
"payment-status": { type: "string" },
|
|
1979
|
+
limit: { type: "string" },
|
|
1980
|
+
json: { type: "boolean" }
|
|
1981
|
+
}, "invoices");
|
|
1982
|
+
if (values.help) return help$1(out);
|
|
1983
|
+
expectPositionals(positionals, 0, 0, "invoices");
|
|
1984
|
+
const statusText = values.status ?? "draft";
|
|
1985
|
+
const status = statusText === "all" ? void 0 : InvoiceStatusSchema.safeParse(statusText).data;
|
|
1986
|
+
if (statusText !== "all" && status === void 0) throw new UsageError("--status: draft, issued, void or all");
|
|
1987
|
+
const paymentStatus = InvoicePaymentStatusSchema.optional().safeParse(values["payment-status"]);
|
|
1988
|
+
if (!paymentStatus.success) throw new UsageError(`--payment-status: one of ${InvoicePaymentStatusSchema.options.join(", ")}`);
|
|
1989
|
+
const limit = values.limit !== void 0 ? parsePositiveInt(values.limit, "--limit", { max: 500 }) : void 0;
|
|
1990
|
+
const filter = {
|
|
1991
|
+
...status !== void 0 ? { status } : {},
|
|
1992
|
+
...paymentStatus.data !== void 0 ? { paymentStatus: paymentStatus.data } : {},
|
|
1993
|
+
...limit !== void 0 ? { limit } : {}
|
|
1994
|
+
};
|
|
1995
|
+
const target = requireAdminTarget(await resolveEnv(ctx));
|
|
1996
|
+
out.err(connectionLine(target));
|
|
1997
|
+
const { items, hasMore } = await callSteward(target, () => clientFor(ctx, target).admin.invoices.list(filter));
|
|
1998
|
+
if (values.json) out.out(JSON.stringify(items, null, 2));
|
|
1999
|
+
else if (items.length === 0) out.out(`no ${status ?? ""} invoices`.replace(" ", " "));
|
|
2000
|
+
else {
|
|
2001
|
+
const rows = [[
|
|
2002
|
+
"CREATED",
|
|
2003
|
+
"STATUS",
|
|
2004
|
+
"NUMBER",
|
|
2005
|
+
"TOTAL",
|
|
2006
|
+
"PAYMENT",
|
|
2007
|
+
"ACCOUNT",
|
|
2008
|
+
"ID"
|
|
2009
|
+
]];
|
|
2010
|
+
for (const i of items) rows.push([
|
|
2011
|
+
i.createdAt,
|
|
2012
|
+
i.status,
|
|
2013
|
+
i.number ?? "-",
|
|
2014
|
+
formatMinor(i.totalMinor, i.currency),
|
|
2015
|
+
i.paymentStatus ?? "-",
|
|
2016
|
+
i.accountRef,
|
|
2017
|
+
i.id
|
|
2018
|
+
]);
|
|
2019
|
+
for (const line of table(rows)) out.out(line);
|
|
2020
|
+
}
|
|
2021
|
+
if (hasMore) out.err(`more invoices than the ${limit ?? 100} listed (--limit, at most 500)`);
|
|
2022
|
+
return 0;
|
|
2023
|
+
}
|
|
2024
|
+
if (sub === "issue") {
|
|
2025
|
+
const { values, positionals } = parse(rest, {
|
|
2026
|
+
...HELP_OPTION,
|
|
2027
|
+
number: { type: "string" },
|
|
2028
|
+
"external-ref": { type: "string" },
|
|
2029
|
+
"issued-at": { type: "string" },
|
|
2030
|
+
document: { type: "string" },
|
|
2031
|
+
yes: {
|
|
2032
|
+
type: "boolean",
|
|
2033
|
+
short: "y"
|
|
2034
|
+
},
|
|
2035
|
+
json: { type: "boolean" }
|
|
2036
|
+
}, "invoices");
|
|
2037
|
+
if (values.help) return help$1(out);
|
|
2038
|
+
expectPositionals(positionals, 1, 1, "invoices");
|
|
2039
|
+
const id = positionals[0];
|
|
2040
|
+
const number = requireOption(values.number, "--number", "invoices").trim();
|
|
2041
|
+
if (values["issued-at"] !== void 0 && !WITH_OFFSET.test(values["issued-at"])) throw new UsageError("--issued-at: ISO-8601 with an offset (2026-09-28T10:15:00+03:00)");
|
|
2042
|
+
const document = values.document !== void 0 ? await readDocument(ctx, values.document) : void 0;
|
|
2043
|
+
const input = {
|
|
2044
|
+
number,
|
|
2045
|
+
...values["external-ref"] !== void 0 ? { externalRef: values["external-ref"] } : {},
|
|
2046
|
+
...values["issued-at"] !== void 0 ? { issuedAt: values["issued-at"] } : {},
|
|
2047
|
+
...document !== void 0 ? { documentBase64: document.toString("base64") } : {}
|
|
2048
|
+
};
|
|
2049
|
+
const parsed = InvoiceIssueInputSchema.safeParse(input);
|
|
2050
|
+
if (!parsed.success) throw new UsageError(`invalid input (nothing was sent)\n${parsed.error.issues.map((issue) => ` - ${issue.path.map(String).join(".") || "(root)"}: ${issue.message}`).join("\n")}`);
|
|
2051
|
+
const target = requireAdminTarget(await resolveEnv(ctx));
|
|
2052
|
+
out.err(connectionLine(target));
|
|
2053
|
+
if (!await confirm(ctx, `Issue invoice ${id} with the number ${number}${document !== void 0 ? " and its document" : ""}? It cannot be changed afterwards and the customer is emailed.`, {
|
|
2054
|
+
yes: values.yes === true,
|
|
2055
|
+
notConfirmed: "nothing was issued"
|
|
2056
|
+
})) {
|
|
2057
|
+
out.err("not confirmed; nothing was issued");
|
|
2058
|
+
return 1;
|
|
2059
|
+
}
|
|
2060
|
+
const issued = await callSteward(target, () => clientFor(ctx, target).invoices.issue(id, input));
|
|
2061
|
+
if (values.json) {
|
|
2062
|
+
const { account: _account, ...invoice } = issued;
|
|
2063
|
+
out.out(JSON.stringify(invoice, null, 2));
|
|
2064
|
+
return 0;
|
|
2065
|
+
}
|
|
2066
|
+
out.out(`issued → ${originOf(target.url)}: invoice ${issued.id} of account ${issued.accountRef}, number ${issued.number}${issued.externalRef !== null ? `, external ref ${issued.externalRef}` : ""}${issued.hasDocument ? ", document stored" : ""}`);
|
|
2067
|
+
return 0;
|
|
2068
|
+
}
|
|
2069
|
+
throw new UsageError(`unknown subcommand: invoices ${sub} (see: steward invoices --help)`);
|
|
2070
|
+
}
|
|
2071
|
+
/** Reads the PDF to attach; the same checks as steward's (PDF signature, at most 5 MB) before anything is sent. */
|
|
2072
|
+
async function readDocument(ctx, file) {
|
|
2073
|
+
let bytes;
|
|
2074
|
+
try {
|
|
2075
|
+
bytes = await readFile(resolve(ctx.cwd, file));
|
|
2076
|
+
} catch (error) {
|
|
2077
|
+
throw new UsageError(`--document: cannot read ${file} (${errnoCode(error) ?? "error"})`);
|
|
2078
|
+
}
|
|
2079
|
+
if (bytes.subarray(0, 5).toString("latin1") !== "%PDF-") throw new UsageError(`--document: ${file} is not a PDF`);
|
|
2080
|
+
if (bytes.length > MAX_DOCUMENT_BYTES) throw new UsageError(`--document: ${file} is larger than 5 MB`);
|
|
2081
|
+
return bytes;
|
|
2082
|
+
}
|
|
2083
|
+
function help$1(out) {
|
|
2084
|
+
out.out(INVOICES_USAGE);
|
|
2085
|
+
return 0;
|
|
2086
|
+
}
|
|
2087
|
+
//#endregion
|
|
1763
2088
|
//#region src/commands/keys.ts
|
|
1764
2089
|
const KEYS_USAGE = `Usage:
|
|
1765
2090
|
steward keys list [--json]
|
|
@@ -2131,7 +2456,7 @@ async function settingsCommand(ctx, out, args) {
|
|
|
2131
2456
|
}
|
|
2132
2457
|
//#endregion
|
|
2133
2458
|
//#region src/main.ts
|
|
2134
|
-
const CLI_VERSION = "0.
|
|
2459
|
+
const CLI_VERSION = "0.10.0";
|
|
2135
2460
|
const USAGE = `steward — Steward CLI (@stewardhq/cli ${CLI_VERSION})
|
|
2136
2461
|
|
|
2137
2462
|
Usage: steward <command> [options]
|
|
@@ -2145,14 +2470,16 @@ Commands:
|
|
|
2145
2470
|
dunning get | set <policy.json> dunning policy (/v1/admin/dunning-policy)
|
|
2146
2471
|
reprice --plan <code> --notice-days <n> move a plan's subscribers to its current price
|
|
2147
2472
|
bank-transfers list | record | fx-report bank transfer reconciliation (/v1/admin/bank-transfers)
|
|
2473
|
+
invoices list | issue invoices not issued yet; write the external invoice number
|
|
2148
2474
|
credits adjust <ref> <meter> --units=<n> credit entry, negative = adjustment
|
|
2475
|
+
accounts get | metadata set | unset read an account; set or remove metadata keys
|
|
2149
2476
|
meters get | recompute | close-periods an account's meters; metering repairs (admin)
|
|
2150
2477
|
events send | redeliver send one event; redeliver webhook events (admin)
|
|
2151
2478
|
|
|
2152
2479
|
Connection: admin commands use STEWARD_ADMIN_URL + STEWARD_ADMIN_API_KEY; doctor,
|
|
2153
|
-
meters and events use STEWARD_URL + STEWARD_API_KEY (or the admin pair). If even
|
|
2154
|
-
these four variables is in the environment, all of them (and APP_URL) are read from
|
|
2155
|
-
environment and ./.env.local is not read at all; otherwise from ./.env.local. The source
|
|
2480
|
+
accounts, meters and events use STEWARD_URL + STEWARD_API_KEY (or the admin pair). If even
|
|
2481
|
+
one of these four variables is in the environment, all of them (and APP_URL) are read from
|
|
2482
|
+
the environment and ./.env.local is not read at all; otherwise from ./.env.local. The source
|
|
2156
2483
|
in use is written to stderr (connection: …). Changes send X-Actor-Ref operator:<user>.
|
|
2157
2484
|
The CLI never writes secrets to the terminal and never calls kubectl.
|
|
2158
2485
|
|
|
@@ -2162,12 +2489,14 @@ const COMMANDS = {
|
|
|
2162
2489
|
catalog: catalogCommand,
|
|
2163
2490
|
settings: settingsCommand,
|
|
2164
2491
|
endpoints: endpointsCommand,
|
|
2492
|
+
accounts: accountsCommand,
|
|
2165
2493
|
meters: metersCommand,
|
|
2166
2494
|
events: eventsCommand,
|
|
2167
2495
|
keys: keysCommand,
|
|
2168
2496
|
dunning: dunningCommand,
|
|
2169
2497
|
reprice: repriceCommand,
|
|
2170
2498
|
"bank-transfers": bankTransfersCommand,
|
|
2499
|
+
invoices: invoicesCommand,
|
|
2171
2500
|
credits: creditsCommand
|
|
2172
2501
|
};
|
|
2173
2502
|
async function main(argv, ctx) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stewardhq/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Steward CLI: doctor, catalog push, settings and webhook endpoint management.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://github.com/z9cloud/steward/tree/main/cli#readme",
|
|
@@ -28,14 +28,14 @@
|
|
|
28
28
|
"registry": "https://registry.npmjs.org"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@stewardhq/sdk": "^0.
|
|
31
|
+
"@stewardhq/sdk": "^0.10.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@types/node": "^
|
|
34
|
+
"@types/node": "^26.6.4",
|
|
35
35
|
"tsdown": "^0.23.0",
|
|
36
36
|
"tsx": "^4.23.15",
|
|
37
37
|
"typescript": "^7.0.2",
|
|
38
|
-
"vitest": "^5.0.
|
|
38
|
+
"vitest": "^5.0.3"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
41
|
"build": "tsdown",
|