@stewardhq/cli 0.9.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 +6 -1
- package/dist/bin.js +169 -19
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -34,13 +34,14 @@ ESM, Node ≥ 22. Its only runtime dependency is `@stewardhq/sdk`.
|
|
|
34
34
|
| `steward credits adjust <ref> <meter> --units=<n> --reason <text>` | A credit ledger entry; negative units = adjustment |
|
|
35
35
|
| `steward events redeliver <eventId>…` | Requeues every delivery of webhook events (admin) |
|
|
36
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) |
|
|
37
38
|
|
|
38
39
|
Exit codes: 0 success, 1 error (or doctor not ready), 2 incorrect usage.
|
|
39
40
|
|
|
40
41
|
## Connection settings
|
|
41
42
|
|
|
42
43
|
- Admin commands (`catalog`, `settings`, `endpoints`, `keys`, `dunning`, `reprice`, `credits`,
|
|
43
|
-
`bank-transfers`, `meters recompute|close-periods`, `events redeliver`): `STEWARD_ADMIN_URL` +
|
|
44
|
+
`bank-transfers`, `invoices`, `meters recompute|close-periods`, `events redeliver`): `STEWARD_ADMIN_URL` +
|
|
44
45
|
`STEWARD_ADMIN_API_KEY`. The URL is the address where your steward serves `/v1`, for example
|
|
45
46
|
`https://billing.example.com`: its public address if the deployment exposes `/v1` there,
|
|
46
47
|
otherwise an address inside its network. The key comes from the operator.
|
|
@@ -137,6 +138,10 @@ Release: bump the version in `cli/package.json` and push the `cli-v<version>` ta
|
|
|
137
138
|
be published on npm. **The first version on npmjs is 0.5.0** (2026-09-21); 0.4.0 was not
|
|
138
139
|
published.
|
|
139
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.
|
|
140
145
|
- **0.9.0** (`@stewardhq/sdk` 0.9, which adds `accounts.updateMetadata`):
|
|
141
146
|
`steward accounts get`, `steward accounts metadata set` and `unset` (single metadata keys, merged
|
|
142
147
|
by steward in one atomic write; requires the `account_metadata` capability). Also: the connection
|
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 { 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";
|
|
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";
|
|
@@ -806,7 +806,7 @@ async function endpointsCommand(ctx, out, args) {
|
|
|
806
806
|
...HELP_OPTION,
|
|
807
807
|
json: { type: "boolean" }
|
|
808
808
|
}, "endpoints");
|
|
809
|
-
if (values.help) return help$
|
|
809
|
+
if (values.help) return help$4(out);
|
|
810
810
|
expectPositionals(positionals, 0, 0, "endpoints");
|
|
811
811
|
const target = requireAdminTarget(await resolveEnv(ctx));
|
|
812
812
|
out.err(connectionLine(target));
|
|
@@ -841,7 +841,7 @@ async function endpointsCommand(ctx, out, args) {
|
|
|
841
841
|
description: { type: "string" },
|
|
842
842
|
force: { type: "boolean" }
|
|
843
843
|
}, ENDPOINTS_USAGE);
|
|
844
|
-
if (values.help) return help$
|
|
844
|
+
if (values.help) return help$4(out);
|
|
845
845
|
expectPositionals(positionals, 0, 0, "endpoints");
|
|
846
846
|
const url = requireOption(values.url, "--url", "endpoints");
|
|
847
847
|
const file = requireOption(values.out, "--out", "endpoints");
|
|
@@ -872,7 +872,7 @@ async function endpointsCommand(ctx, out, args) {
|
|
|
872
872
|
out: { type: "string" },
|
|
873
873
|
force: { type: "boolean" }
|
|
874
874
|
}, "endpoints");
|
|
875
|
-
if (values.help) return help$
|
|
875
|
+
if (values.help) return help$4(out);
|
|
876
876
|
expectPositionals(positionals, 1, 1, "endpoints");
|
|
877
877
|
const id = positionals[0];
|
|
878
878
|
const file = requireOption(values.out, "--out", "endpoints");
|
|
@@ -891,7 +891,7 @@ async function endpointsCommand(ctx, out, args) {
|
|
|
891
891
|
}
|
|
892
892
|
if (sub === "deactivate") {
|
|
893
893
|
const { values, positionals } = parse(rest, { ...HELP_OPTION }, "endpoints");
|
|
894
|
-
if (values.help) return help$
|
|
894
|
+
if (values.help) return help$4(out);
|
|
895
895
|
expectPositionals(positionals, 1, 1, "endpoints");
|
|
896
896
|
const target = requireAdminTarget(await resolveEnv(ctx));
|
|
897
897
|
out.err(connectionLine(target));
|
|
@@ -901,7 +901,7 @@ async function endpointsCommand(ctx, out, args) {
|
|
|
901
901
|
}
|
|
902
902
|
throw new UsageError(`unknown subcommand: endpoints ${sub} (details: steward endpoints --help)`);
|
|
903
903
|
}
|
|
904
|
-
function help$
|
|
904
|
+
function help$4(out) {
|
|
905
905
|
out.out(ENDPOINTS_USAGE);
|
|
906
906
|
return 0;
|
|
907
907
|
}
|
|
@@ -929,7 +929,9 @@ transfer and unpaid invoices of accounts with an order code, by deadline; expire
|
|
|
929
929
|
that expired in the last 30 days. --rate previews a transfer in another currency: next to each
|
|
930
930
|
item the product lets be paid in another currency (settings.billing.bankTransfer.settleIn) it
|
|
931
931
|
shows the amount expected at that rate (--currency names it when an item accepts several). It
|
|
932
|
-
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).
|
|
933
935
|
|
|
934
936
|
record: a transfer seen on the bank account. <code> is the order code from the transfer
|
|
935
937
|
description (case and dashes are forgiven). Only a checkout or unpaid invoice waiting for
|
|
@@ -953,7 +955,7 @@ amount received, the rate entered, received date), latest first; --from (inclusi
|
|
|
953
955
|
exchange-difference invoices, which steward does not issue.
|
|
954
956
|
|
|
955
957
|
Connection: STEWARD_ADMIN_URL + STEWARD_ADMIN_API_KEY (environment, otherwise ./.env.local).`;
|
|
956
|
-
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})$/;
|
|
957
959
|
async function bankTransfersCommand(ctx, out, args) {
|
|
958
960
|
const [sub, ...rest] = args;
|
|
959
961
|
if (sub === void 0 || sub === "--help" || sub === "-h" || sub === "help") {
|
|
@@ -968,7 +970,7 @@ async function bankTransfersCommand(ctx, out, args) {
|
|
|
968
970
|
currency: { type: "string" },
|
|
969
971
|
json: { type: "boolean" }
|
|
970
972
|
}, "bank-transfers");
|
|
971
|
-
if (values.help) return help$
|
|
973
|
+
if (values.help) return help$3(out);
|
|
972
974
|
expectPositionals(positionals, 0, 0, "bank-transfers");
|
|
973
975
|
const status = values.status ?? "pending";
|
|
974
976
|
if (status !== "pending" && status !== "expired") throw new UsageError("--status: pending or expired");
|
|
@@ -992,6 +994,7 @@ async function bankTransfersCommand(ctx, out, args) {
|
|
|
992
994
|
...rate !== void 0 ? [`EXPECTED @ ${rate}`] : [],
|
|
993
995
|
"DEADLINE",
|
|
994
996
|
"KIND",
|
|
997
|
+
"INVOICE NO",
|
|
995
998
|
"PLAN",
|
|
996
999
|
"ACCOUNT",
|
|
997
1000
|
"ID"
|
|
@@ -1002,6 +1005,7 @@ async function bankTransfersCommand(ctx, out, args) {
|
|
|
1002
1005
|
...rate !== void 0 ? [i.expectedMinor !== void 0 && i.expectedCurrency !== void 0 ? formatMinor(i.expectedMinor, i.expectedCurrency) : "-"] : [],
|
|
1003
1006
|
i.deadline ?? "-",
|
|
1004
1007
|
i.kind,
|
|
1008
|
+
i.invoiceNumber ?? "-",
|
|
1005
1009
|
i.planCode ?? "-",
|
|
1006
1010
|
i.accountRef,
|
|
1007
1011
|
i.id
|
|
@@ -1027,10 +1031,10 @@ async function bankTransfersCommand(ctx, out, args) {
|
|
|
1027
1031
|
},
|
|
1028
1032
|
json: { type: "boolean" }
|
|
1029
1033
|
}, "bank-transfers");
|
|
1030
|
-
if (values.help) return help$
|
|
1034
|
+
if (values.help) return help$3(out);
|
|
1031
1035
|
expectPositionals(positionals, 1, 1, "bank-transfers");
|
|
1032
1036
|
const receivedAt = requireOption(values["received-at"], "--received-at", "bank-transfers");
|
|
1033
|
-
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)");
|
|
1034
1038
|
const input = {
|
|
1035
1039
|
code: positionals[0],
|
|
1036
1040
|
amountMinor: parseNonNegativeInt(requireOption(values.amount, "--amount", "bank-transfers"), "--amount"),
|
|
@@ -1070,11 +1074,11 @@ async function bankTransfersCommand(ctx, out, args) {
|
|
|
1070
1074
|
json: { type: "boolean" },
|
|
1071
1075
|
csv: { type: "boolean" }
|
|
1072
1076
|
}, "bank-transfers");
|
|
1073
|
-
if (values.help) return help$
|
|
1077
|
+
if (values.help) return help$3(out);
|
|
1074
1078
|
expectPositionals(positionals, 0, 0, "bank-transfers");
|
|
1075
1079
|
if (values.json && values.csv) throw new UsageError("--json or --csv, not both");
|
|
1076
|
-
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)");
|
|
1077
|
-
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)");
|
|
1078
1082
|
const range = {
|
|
1079
1083
|
...values.from !== void 0 ? { from: values.from } : {},
|
|
1080
1084
|
...values.to !== void 0 ? { to: values.to } : {}
|
|
@@ -1135,7 +1139,7 @@ function csvField(value) {
|
|
|
1135
1139
|
const text = typeof value === "string" && /^[=+\-@]/.test(value) ? `'${value}` : String(value);
|
|
1136
1140
|
return /[",\n\r]/.test(text) ? `"${text.replace(/"/g, "\"\"")}"` : text;
|
|
1137
1141
|
}
|
|
1138
|
-
function help$
|
|
1142
|
+
function help$3(out) {
|
|
1139
1143
|
out.out(BANK_TRANSFERS_USAGE);
|
|
1140
1144
|
return 0;
|
|
1141
1145
|
}
|
|
@@ -1755,7 +1759,7 @@ async function dunningCommand(ctx, out, args) {
|
|
|
1755
1759
|
...HELP_OPTION,
|
|
1756
1760
|
json: { type: "boolean" }
|
|
1757
1761
|
}, "dunning");
|
|
1758
|
-
if (values.help) return help$
|
|
1762
|
+
if (values.help) return help$2(out);
|
|
1759
1763
|
expectPositionals(positionals, 0, 0, "dunning");
|
|
1760
1764
|
const target = requireAdminTarget(await resolveEnv(ctx));
|
|
1761
1765
|
out.err(connectionLine(target));
|
|
@@ -1772,7 +1776,7 @@ async function dunningCommand(ctx, out, args) {
|
|
|
1772
1776
|
short: "y"
|
|
1773
1777
|
}
|
|
1774
1778
|
}, "dunning");
|
|
1775
|
-
if (values.help) return help$
|
|
1779
|
+
if (values.help) return help$2(out);
|
|
1776
1780
|
expectPositionals(positionals, 1, 1, "dunning");
|
|
1777
1781
|
const file = positionals[0];
|
|
1778
1782
|
let json;
|
|
@@ -1805,7 +1809,7 @@ async function dunningCommand(ctx, out, args) {
|
|
|
1805
1809
|
}
|
|
1806
1810
|
throw new UsageError(`unknown subcommand: dunning ${sub} (see: steward dunning --help)`);
|
|
1807
1811
|
}
|
|
1808
|
-
function help$
|
|
1812
|
+
function help$2(out) {
|
|
1809
1813
|
out.out(DUNNING_USAGE);
|
|
1810
1814
|
return 0;
|
|
1811
1815
|
}
|
|
@@ -1937,6 +1941,150 @@ async function redeliverCommand(ctx, out, args) {
|
|
|
1937
1941
|
return 0;
|
|
1938
1942
|
}
|
|
1939
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
|
|
1940
2088
|
//#region src/commands/keys.ts
|
|
1941
2089
|
const KEYS_USAGE = `Usage:
|
|
1942
2090
|
steward keys list [--json]
|
|
@@ -2308,7 +2456,7 @@ async function settingsCommand(ctx, out, args) {
|
|
|
2308
2456
|
}
|
|
2309
2457
|
//#endregion
|
|
2310
2458
|
//#region src/main.ts
|
|
2311
|
-
const CLI_VERSION = "0.
|
|
2459
|
+
const CLI_VERSION = "0.10.0";
|
|
2312
2460
|
const USAGE = `steward — Steward CLI (@stewardhq/cli ${CLI_VERSION})
|
|
2313
2461
|
|
|
2314
2462
|
Usage: steward <command> [options]
|
|
@@ -2322,6 +2470,7 @@ Commands:
|
|
|
2322
2470
|
dunning get | set <policy.json> dunning policy (/v1/admin/dunning-policy)
|
|
2323
2471
|
reprice --plan <code> --notice-days <n> move a plan's subscribers to its current price
|
|
2324
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
|
|
2325
2474
|
credits adjust <ref> <meter> --units=<n> credit entry, negative = adjustment
|
|
2326
2475
|
accounts get | metadata set | unset read an account; set or remove metadata keys
|
|
2327
2476
|
meters get | recompute | close-periods an account's meters; metering repairs (admin)
|
|
@@ -2347,6 +2496,7 @@ const COMMANDS = {
|
|
|
2347
2496
|
dunning: dunningCommand,
|
|
2348
2497
|
reprice: repriceCommand,
|
|
2349
2498
|
"bank-transfers": bankTransfersCommand,
|
|
2499
|
+
invoices: invoicesCommand,
|
|
2350
2500
|
credits: creditsCommand
|
|
2351
2501
|
};
|
|
2352
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,7 +28,7 @@
|
|
|
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
34
|
"@types/node": "^26.6.4",
|