@stewardhq/cli 0.8.0 → 0.9.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 +32 -8
- package/dist/bin.js +198 -19
- 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` |
|
|
@@ -39,21 +41,21 @@ Exit codes: 0 success, 1 error (or doctor not ready), 2 incorrect usage.
|
|
|
39
41
|
|
|
40
42
|
- Admin commands (`catalog`, `settings`, `endpoints`, `keys`, `dunning`, `reprice`, `credits`,
|
|
41
43
|
`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
|
+
`STEWARD_ADMIN_API_KEY`. The URL is the address where your steward serves `/v1`, for example
|
|
45
|
+
`https://billing.example.com`: its public address if the deployment exposes `/v1` there,
|
|
46
|
+
otherwise an address inside its network. The key comes from the operator.
|
|
47
|
+
- `doctor`, `accounts`, `meters`, `events`: `STEWARD_URL` + `STEWARD_API_KEY`; if neither is set, the admin
|
|
46
48
|
pair. A half pair (only the URL or only the key) does not fall back to the other pair — it
|
|
47
49
|
fails with a clear error.
|
|
48
50
|
- **The source is chosen as a whole.** If even one of `STEWARD_URL`, `STEWARD_API_KEY`,
|
|
49
51
|
`STEWARD_ADMIN_URL`, `STEWARD_ADMIN_API_KEY` is defined in the environment, the connection
|
|
50
52
|
values and `APP_URL` are read from the environment only, and the `.env.local` in the working
|
|
51
53
|
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
|
-
|
|
54
|
+
`.env.local`. That way, when the environment is set for a production target, a product repo's
|
|
55
|
+
`.env.local` cannot redirect it.
|
|
54
56
|
- Commands print the source they used to stderr (not the values — the pair names and the
|
|
55
57
|
origin), e.g. `connection: environment · STEWARD_ADMIN_URL + STEWARD_ADMIN_API_KEY →
|
|
56
|
-
|
|
58
|
+
https://billing.example.com` (the source is `environment` or `.env.local`).
|
|
57
59
|
- Changes carry `X-Actor-Ref: operator:<operating system user>`.
|
|
58
60
|
|
|
59
61
|
## Secrets
|
|
@@ -111,6 +113,23 @@ capability: an older steward would drop the key and offer the plan.
|
|
|
111
113
|
rollup job processes it (seconds).
|
|
112
114
|
- Details: [metering guide](https://github.com/z9cloud/steward/blob/main/docs/integrate/metering.md).
|
|
113
115
|
|
|
116
|
+
## Account metadata
|
|
117
|
+
|
|
118
|
+
- `steward accounts get <ref>` prints the account as the product sees it at `GET /v1/accounts/:ref`,
|
|
119
|
+
with its metadata keys and values.
|
|
120
|
+
- `steward accounts metadata set <ref> tier=gold --reason "moved to gold"` and
|
|
121
|
+
`steward accounts metadata unset <ref> tier` change single keys. `key=value` is split at the
|
|
122
|
+
first `=`; a key is at most 64 characters, a value at most 500. The command checks that steward
|
|
123
|
+
lists the `account_metadata` capability, reads the account, prints each key's value before and
|
|
124
|
+
after (`tier: silver → gold`, `tier: gold → (removed)`), then sends one `PATCH`. An invalid
|
|
125
|
+
key or value is exit 2 and nothing is sent.
|
|
126
|
+
- Steward merges the keys in one atomic write: a key the product (or another operator) changes at
|
|
127
|
+
the same time is not overwritten. The change is in steward's audit trail with the key names,
|
|
128
|
+
`--reason` and `operator:<user>`; the account state does not change and no event is sent, so
|
|
129
|
+
running it again is harmless and there is no confirmation prompt.
|
|
130
|
+
- The account must exist: the commands never create one (exit 1 on `account_not_found`). Do not
|
|
131
|
+
put personal data (name, email, phone) in metadata.
|
|
132
|
+
|
|
114
133
|
## Versions
|
|
115
134
|
|
|
116
135
|
Release: bump the version in `cli/package.json` and push the `cli-v<version>` tag
|
|
@@ -118,6 +137,11 @@ Release: bump the version in `cli/package.json` and push the `cli-v<version>` ta
|
|
|
118
137
|
be published on npm. **The first version on npmjs is 0.5.0** (2026-09-21); 0.4.0 was not
|
|
119
138
|
published.
|
|
120
139
|
|
|
140
|
+
- **0.9.0** (`@stewardhq/sdk` 0.9, which adds `accounts.updateMetadata`):
|
|
141
|
+
`steward accounts get`, `steward accounts metadata set` and `unset` (single metadata keys, merged
|
|
142
|
+
by steward in one atomic write; requires the `account_metadata` capability). Also: the connection
|
|
143
|
+
hint and the "could not reach steward" hint no longer name one deployment's host or assume a
|
|
144
|
+
particular way of reaching steward (messages only).
|
|
121
145
|
- **0.8.0** (`@stewardhq/sdk` 0.8, bank transfers in another currency, issue #55):
|
|
122
146
|
`bank-transfers record --rate`, `bank-transfers list --rate [--currency]`,
|
|
123
147
|
`bank-transfers fx-report [--from] [--to] [--json|--csv]`. Unlisted plans: `catalog push` shows
|
|
@@ -129,7 +153,7 @@ published.
|
|
|
129
153
|
`steward reprice`, `steward credits adjust`, `steward bank-transfers`, `steward meters recompute` and
|
|
130
154
|
`close-periods`, `steward events redeliver`, `settings set --provider`. These replace the pod CLI
|
|
131
155
|
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
|
|
156
|
+
connection hint names the public admin host.
|
|
133
157
|
- **0.5.0** (`@stewardhq/sdk` 0.5, metering phase 2): `steward meters get`, `steward events
|
|
134
158
|
send`; meter, credit and metered price diff in `catalog push` (a metered price change asks
|
|
135
159
|
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, 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);
|
|
@@ -2131,7 +2308,7 @@ async function settingsCommand(ctx, out, args) {
|
|
|
2131
2308
|
}
|
|
2132
2309
|
//#endregion
|
|
2133
2310
|
//#region src/main.ts
|
|
2134
|
-
const CLI_VERSION = "0.
|
|
2311
|
+
const CLI_VERSION = "0.9.0";
|
|
2135
2312
|
const USAGE = `steward — Steward CLI (@stewardhq/cli ${CLI_VERSION})
|
|
2136
2313
|
|
|
2137
2314
|
Usage: steward <command> [options]
|
|
@@ -2146,13 +2323,14 @@ Commands:
|
|
|
2146
2323
|
reprice --plan <code> --notice-days <n> move a plan's subscribers to its current price
|
|
2147
2324
|
bank-transfers list | record | fx-report bank transfer reconciliation (/v1/admin/bank-transfers)
|
|
2148
2325
|
credits adjust <ref> <meter> --units=<n> credit entry, negative = adjustment
|
|
2326
|
+
accounts get | metadata set | unset read an account; set or remove metadata keys
|
|
2149
2327
|
meters get | recompute | close-periods an account's meters; metering repairs (admin)
|
|
2150
2328
|
events send | redeliver send one event; redeliver webhook events (admin)
|
|
2151
2329
|
|
|
2152
2330
|
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
|
|
2331
|
+
accounts, meters and events use STEWARD_URL + STEWARD_API_KEY (or the admin pair). If even
|
|
2332
|
+
one of these four variables is in the environment, all of them (and APP_URL) are read from
|
|
2333
|
+
the environment and ./.env.local is not read at all; otherwise from ./.env.local. The source
|
|
2156
2334
|
in use is written to stderr (connection: …). Changes send X-Actor-Ref operator:<user>.
|
|
2157
2335
|
The CLI never writes secrets to the terminal and never calls kubectl.
|
|
2158
2336
|
|
|
@@ -2162,6 +2340,7 @@ const COMMANDS = {
|
|
|
2162
2340
|
catalog: catalogCommand,
|
|
2163
2341
|
settings: settingsCommand,
|
|
2164
2342
|
endpoints: endpointsCommand,
|
|
2343
|
+
accounts: accountsCommand,
|
|
2165
2344
|
meters: metersCommand,
|
|
2166
2345
|
events: eventsCommand,
|
|
2167
2346
|
keys: keysCommand,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stewardhq/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.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.9.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",
|