@stewardhq/cli 0.11.0 → 0.12.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 +9 -2
- package/dist/bin.js +161 -18
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -25,6 +25,7 @@ ESM, Node ≥ 22. Its only runtime dependency is `@stewardhq/sdk`.
|
|
|
25
25
|
| `steward endpoints add --url <url> --out <file> [--event-types a,b] [--description <text>] [--force]` | Generates the secret locally and writes it only to `--out` |
|
|
26
26
|
| `steward endpoints rotate <id> --out <file> [--force]` | New secret to `--out`; the product transitions with `new,old` |
|
|
27
27
|
| `steward endpoints deactivate <id>` | Not reversible |
|
|
28
|
+
| `steward email-smtp get [--json]` / `steward email-smtp set --file <path> \| --stdin` / `steward email-smtp clear [--yes]` / `steward email-smtp verify [--to <address>] [--json]` | The product's own SMTP account for its billing emails (`/v1/admin/email-smtp`; otherwise the installation's). `set` reads the URL (`smtp://user:pass@host:587` or `smtps://…:465`) from a file or a pipe, never from an argument or a terminal; steward never returns it (`get` shows the host). `verify` asks `MAIL FROM` (the product's sender) and `RCPT TO`, stops before `DATA`, and exits 1 with the failed step and the server's reply when the account refuses |
|
|
28
29
|
| `steward keys list [--json]` | The product's API keys: prefix, scope, status (active, expired, revoked), expiry, last use |
|
|
29
30
|
| `steward keys create --name <n> --scope product\|checkout\|admin --out <file> [--expires-days <n> \| --no-expiry] [--force]` | Generates the key locally and writes it only to `--out`; steward stores its hash. An admin key always expires (default 90 days) |
|
|
30
31
|
| `steward keys revoke <prefix>` | A key cannot revoke itself (use another admin key) |
|
|
@@ -42,7 +43,7 @@ Exit codes: 0 success, 1 error (or doctor not ready), 2 incorrect usage.
|
|
|
42
43
|
|
|
43
44
|
## Connection settings
|
|
44
45
|
|
|
45
|
-
- Admin commands (`catalog`, `settings`, `endpoints`, `keys`, `dunning`, `reprice`, `credits`,
|
|
46
|
+
- Admin commands (`catalog`, `settings`, `endpoints`, `email-smtp`, `keys`, `dunning`, `reprice`, `credits`,
|
|
46
47
|
`bank-transfers`, `invoices`, `meters recompute|close-periods`, `events redeliver`): `STEWARD_ADMIN_URL` +
|
|
47
48
|
`STEWARD_ADMIN_API_KEY`. The URL is the address where your steward serves `/v1`, for example
|
|
48
49
|
`https://billing.example.com`: its public address if the deployment exposes `/v1` there,
|
|
@@ -69,6 +70,9 @@ Exit codes: 0 success, 1 error (or doctor not ready), 2 incorrect usage.
|
|
|
69
70
|
newline). If the file exists, no request is sent without `--force`; if the request fails, no
|
|
70
71
|
secret file is left behind. The operator moves the secret into the product's Secret and
|
|
71
72
|
deletes the file.
|
|
73
|
+
- `email-smtp set`: the SMTP URL (it carries the mailbox password) is read from `--file` or `--stdin`, never
|
|
74
|
+
from an argument (shell history) or an interactive terminal (echo); it is validated before the request and
|
|
75
|
+
never printed. Delete the file afterwards.
|
|
72
76
|
- The CLI does not call `kubectl`; creating Secrets and rolling out is the operator's job.
|
|
73
77
|
|
|
74
78
|
## Catalog file
|
|
@@ -140,6 +144,9 @@ Release: bump the version in `cli/package.json` and push the `cli-v<version>` ta
|
|
|
140
144
|
be published on npm. The notes of 0.4.0 to 0.10.0 are in
|
|
141
145
|
[this file at `cli-v0.10.0`](https://github.com/z9cloud/steward/blob/cli-v0.10.0/cli/README.md#versions).
|
|
142
146
|
|
|
147
|
+
- **0.12.0** (`@stewardhq/sdk` 0.12): `steward email-smtp get|set --file|--stdin|clear|verify` (the product's own
|
|
148
|
+
SMTP account for its billing emails; needs a steward with `/v1/admin/email-smtp`). `steward doctor` shows which
|
|
149
|
+
SMTP the emails go through, the product account's host and its recent failures.
|
|
143
150
|
- **0.11.0** (`@stewardhq/sdk` 0.11, which removes the contract names steward no longer produces):
|
|
144
151
|
`steward grants list` (the product's active grants and their accounts' live subscriptions; needs a steward with
|
|
145
152
|
`GET /v1/admin/grants`). `steward settings set --display-time-zone <iana>` (the zone of customer-facing dates;
|
|
@@ -152,7 +159,7 @@ be published on npm. The notes of 0.4.0 to 0.10.0 are in
|
|
|
152
159
|
the provider's webhook, automatic renewal and the legal settings.
|
|
153
160
|
|
|
154
161
|
When packed, the `@stewardhq/sdk` dependency turns from `workspace:^` into the range of the
|
|
155
|
-
SDK version current at that time (0.
|
|
162
|
+
SDK version current at that time (0.12.0 → `^0.12.0`).
|
|
156
163
|
|
|
157
164
|
## License
|
|
158
165
|
|
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, CodeSchema, CreditAdjustmentInputSchema, DateTimeSchema, DunningPolicySchema, EventsIngestInputSchema, FxRateSchema, GRANT_LIST_DEFAULT_LIMIT, GRANT_LIST_MAX_LIMIT, GrantListSubscriptionFilterSchema, INVOICE_LINE_TEXTS, IdSchema, InvoiceIssueInputSchema, InvoicePaymentStatusSchema, InvoiceStatusSchema, METER_CHARGE_MODES, MeterCreditPropertiesSchema, ProductSettingsPatchSchema, RepriceInputSchema, SALES_REPORT_MAX_MONTHS, StewardApiError, StewardConfigError, StewardError, StewardNetworkError, TAX_PROVIDERS, TAX_THRESHOLD_PERIODS, TAX_THRESHOLD_SCOPES, TaxThresholdInputSchema, WebhookEndpointCreateInputSchema, WebhookEndpointRotateInputSchema, createSteward, generateApiKeyToken, generateWebhookSecret, plainDecimalOf, taxIdTypeOf } from "@stewardhq/sdk";
|
|
5
|
+
import { ACCOUNT_INCLUDES, AccountMetadataPatchInputSchema, ApiKeyCreateInputSchema, BankTransferRecordInputSchema, CatalogSyncInputSchema, CodeSchema, CreditAdjustmentInputSchema, DateTimeSchema, DunningPolicySchema, EmailSmtpVerifyInputSchema, EventsIngestInputSchema, FxRateSchema, GRANT_LIST_DEFAULT_LIMIT, GRANT_LIST_MAX_LIMIT, GrantListSubscriptionFilterSchema, INVOICE_LINE_TEXTS, IdSchema, InvoiceIssueInputSchema, InvoicePaymentStatusSchema, InvoiceStatusSchema, METER_CHARGE_MODES, MeterCreditPropertiesSchema, ProductSettingsPatchSchema, RepriceInputSchema, SALES_REPORT_MAX_MONTHS, SmtpUrlSchema, StewardApiError, StewardConfigError, StewardError, StewardNetworkError, TAX_PROVIDERS, TAX_THRESHOLD_PERIODS, TAX_THRESHOLD_SCOPES, TaxThresholdInputSchema, WebhookEndpointCreateInputSchema, WebhookEndpointRotateInputSchema, createSteward, generateApiKeyToken, generateWebhookSecret, plainDecimalOf, taxIdTypeOf } 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";
|
|
@@ -773,7 +773,7 @@ product moves over with a "new,old" list. Delete the file after moving it. Witho
|
|
|
773
773
|
endpoint).
|
|
774
774
|
|
|
775
775
|
Connection: STEWARD_ADMIN_URL + STEWARD_ADMIN_API_KEY (environment, otherwise ./.env.local).`;
|
|
776
|
-
function schemaProblems(issues) {
|
|
776
|
+
function schemaProblems$1(issues) {
|
|
777
777
|
return issues.map((issue) => ` - ${issue.path.map(String).join(".") || "(root)"}: ${issue.message}`).join("\n");
|
|
778
778
|
}
|
|
779
779
|
const lastDeliveryText = (endpoint) => {
|
|
@@ -798,7 +798,7 @@ async function endpointsCommand(ctx, out, args) {
|
|
|
798
798
|
...HELP_OPTION,
|
|
799
799
|
json: { type: "boolean" }
|
|
800
800
|
}, "endpoints");
|
|
801
|
-
if (values.help) return help$
|
|
801
|
+
if (values.help) return help$6(out);
|
|
802
802
|
expectPositionals(positionals, 0, 0, "endpoints");
|
|
803
803
|
const target = requireAdminTarget(await resolveEnv(ctx));
|
|
804
804
|
out.err(connectionLine(target));
|
|
@@ -833,7 +833,7 @@ async function endpointsCommand(ctx, out, args) {
|
|
|
833
833
|
description: { type: "string" },
|
|
834
834
|
force: { type: "boolean" }
|
|
835
835
|
}, ENDPOINTS_USAGE);
|
|
836
|
-
if (values.help) return help$
|
|
836
|
+
if (values.help) return help$6(out);
|
|
837
837
|
expectPositionals(positionals, 0, 0, "endpoints");
|
|
838
838
|
const url = requireOption(values.url, "--url", "endpoints");
|
|
839
839
|
const file = requireOption(values.out, "--out", "endpoints");
|
|
@@ -845,7 +845,7 @@ async function endpointsCommand(ctx, out, args) {
|
|
|
845
845
|
...values.description !== void 0 ? { description: values.description } : {}
|
|
846
846
|
};
|
|
847
847
|
const parsed = WebhookEndpointCreateInputSchema.safeParse(input);
|
|
848
|
-
if (!parsed.success) throw new UsageError(`invalid endpoint (no request was sent)\n${schemaProblems(parsed.error.issues)}`);
|
|
848
|
+
if (!parsed.success) throw new UsageError(`invalid endpoint (no request was sent)\n${schemaProblems$1(parsed.error.issues)}`);
|
|
849
849
|
const target = requireAdminTarget(await resolveEnv(ctx));
|
|
850
850
|
out.err(connectionLine(target));
|
|
851
851
|
const steward = clientFor(ctx, target);
|
|
@@ -864,13 +864,13 @@ async function endpointsCommand(ctx, out, args) {
|
|
|
864
864
|
out: { type: "string" },
|
|
865
865
|
force: { type: "boolean" }
|
|
866
866
|
}, "endpoints");
|
|
867
|
-
if (values.help) return help$
|
|
867
|
+
if (values.help) return help$6(out);
|
|
868
868
|
expectPositionals(positionals, 1, 1, "endpoints");
|
|
869
869
|
const id = positionals[0];
|
|
870
870
|
const file = requireOption(values.out, "--out", "endpoints");
|
|
871
871
|
const secret = generateWebhookSecret();
|
|
872
872
|
const parsed = WebhookEndpointRotateInputSchema.safeParse({ secret });
|
|
873
|
-
if (!parsed.success) throw new UsageError(`invalid secret\n${schemaProblems(parsed.error.issues)}`);
|
|
873
|
+
if (!parsed.success) throw new UsageError(`invalid secret\n${schemaProblems$1(parsed.error.issues)}`);
|
|
874
874
|
const target = requireAdminTarget(await resolveEnv(ctx));
|
|
875
875
|
out.err(connectionLine(target));
|
|
876
876
|
const steward = clientFor(ctx, target);
|
|
@@ -883,7 +883,7 @@ async function endpointsCommand(ctx, out, args) {
|
|
|
883
883
|
}
|
|
884
884
|
if (sub === "deactivate") {
|
|
885
885
|
const { values, positionals } = parse(rest, { ...HELP_OPTION }, "endpoints");
|
|
886
|
-
if (values.help) return help$
|
|
886
|
+
if (values.help) return help$6(out);
|
|
887
887
|
expectPositionals(positionals, 1, 1, "endpoints");
|
|
888
888
|
const target = requireAdminTarget(await resolveEnv(ctx));
|
|
889
889
|
out.err(connectionLine(target));
|
|
@@ -893,7 +893,7 @@ async function endpointsCommand(ctx, out, args) {
|
|
|
893
893
|
}
|
|
894
894
|
throw new UsageError(`unknown subcommand: endpoints ${sub} (details: steward endpoints --help)`);
|
|
895
895
|
}
|
|
896
|
-
function help$
|
|
896
|
+
function help$6(out) {
|
|
897
897
|
out.out(ENDPOINTS_USAGE);
|
|
898
898
|
return 0;
|
|
899
899
|
}
|
|
@@ -965,7 +965,7 @@ async function bankTransfersCommand(ctx, out, args) {
|
|
|
965
965
|
currency: { type: "string" },
|
|
966
966
|
json: { type: "boolean" }
|
|
967
967
|
}, "bank-transfers");
|
|
968
|
-
if (values.help) return help$
|
|
968
|
+
if (values.help) return help$5(out);
|
|
969
969
|
expectPositionals(positionals, 0, 0, "bank-transfers");
|
|
970
970
|
const status = values.status ?? "pending";
|
|
971
971
|
if (status !== "pending" && status !== "expired") throw new UsageError("--status: pending or expired");
|
|
@@ -1027,7 +1027,7 @@ async function bankTransfersCommand(ctx, out, args) {
|
|
|
1027
1027
|
},
|
|
1028
1028
|
json: { type: "boolean" }
|
|
1029
1029
|
}, "bank-transfers");
|
|
1030
|
-
if (values.help) return help$
|
|
1030
|
+
if (values.help) return help$5(out);
|
|
1031
1031
|
expectPositionals(positionals, 1, 1, "bank-transfers");
|
|
1032
1032
|
const receivedAt = requireOption(values["received-at"], "--received-at", "bank-transfers");
|
|
1033
1033
|
if (!WITH_OFFSET$1.test(receivedAt)) throw new UsageError("--received-at: ISO-8601 with an offset (2026-09-28T10:15:00+03:00)");
|
|
@@ -1071,7 +1071,7 @@ async function bankTransfersCommand(ctx, out, args) {
|
|
|
1071
1071
|
json: { type: "boolean" },
|
|
1072
1072
|
csv: { type: "boolean" }
|
|
1073
1073
|
}, "bank-transfers");
|
|
1074
|
-
if (values.help) return help$
|
|
1074
|
+
if (values.help) return help$5(out);
|
|
1075
1075
|
expectPositionals(positionals, 0, 0, "bank-transfers");
|
|
1076
1076
|
if (values.json && values.csv) throw new UsageError("--json or --csv, not both");
|
|
1077
1077
|
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)");
|
|
@@ -1136,7 +1136,7 @@ function csvField(value) {
|
|
|
1136
1136
|
const text = typeof value === "string" && /^[=+\-@]/.test(value) ? `'${value}` : String(value);
|
|
1137
1137
|
return /[",\n\r]/.test(text) ? `"${text.replace(/"/g, "\"\"")}"` : text;
|
|
1138
1138
|
}
|
|
1139
|
-
function help$
|
|
1139
|
+
function help$5(out) {
|
|
1140
1140
|
out.out(BANK_TRANSFERS_USAGE);
|
|
1141
1141
|
return 0;
|
|
1142
1142
|
}
|
|
@@ -1681,7 +1681,8 @@ function formatDoctorReport(report, cliWarnings, metering = null) {
|
|
|
1681
1681
|
const { emails } = report;
|
|
1682
1682
|
const problems = [...emails.transportConfigured ? [] : ["no transport"], ...emails.senderConfigured ? [] : ["no sender"]];
|
|
1683
1683
|
const disabled = emails.disabledTemplates.length > 0 ? ` · disabled: ${emails.disabledTemplates.join(", ")}` : "";
|
|
1684
|
-
|
|
1684
|
+
const via = emails.transport === "product" ? ` · own SMTP ${emails.smtpHost ?? ""}${emails.smtpRecentFailures ? ` (${emails.smtpRecentFailures} failed in 24 h, last ${emails.smtpLastFailure ?? "?"})` : ""}` : emails.transport === "installation" ? " · installation's SMTP" : "";
|
|
1685
|
+
lines.push(`emails ${emails.ready ? "ready ✓" : `not sending ✗${problems.length > 0 ? ` (${problems.join(", ")})` : ""}`}${via}${disabled}`);
|
|
1685
1686
|
}
|
|
1686
1687
|
if (report.apiKeys) {
|
|
1687
1688
|
lines.push(report.apiKeys.length === 0 ? "api keys none active" : "api keys");
|
|
@@ -1757,7 +1758,7 @@ async function dunningCommand(ctx, out, args) {
|
|
|
1757
1758
|
...HELP_OPTION,
|
|
1758
1759
|
json: { type: "boolean" }
|
|
1759
1760
|
}, "dunning");
|
|
1760
|
-
if (values.help) return help$
|
|
1761
|
+
if (values.help) return help$4(out);
|
|
1761
1762
|
expectPositionals(positionals, 0, 0, "dunning");
|
|
1762
1763
|
const target = requireAdminTarget(await resolveEnv(ctx));
|
|
1763
1764
|
out.err(connectionLine(target));
|
|
@@ -1774,7 +1775,7 @@ async function dunningCommand(ctx, out, args) {
|
|
|
1774
1775
|
short: "y"
|
|
1775
1776
|
}
|
|
1776
1777
|
}, "dunning");
|
|
1777
|
-
if (values.help) return help$
|
|
1778
|
+
if (values.help) return help$4(out);
|
|
1778
1779
|
expectPositionals(positionals, 1, 1, "dunning");
|
|
1779
1780
|
const file = positionals[0];
|
|
1780
1781
|
let json;
|
|
@@ -1807,10 +1808,144 @@ async function dunningCommand(ctx, out, args) {
|
|
|
1807
1808
|
}
|
|
1808
1809
|
throw new UsageError(`unknown subcommand: dunning ${sub} (see: steward dunning --help)`);
|
|
1809
1810
|
}
|
|
1810
|
-
function help$
|
|
1811
|
+
function help$4(out) {
|
|
1811
1812
|
out.out(DUNNING_USAGE);
|
|
1812
1813
|
return 0;
|
|
1813
1814
|
}
|
|
1815
|
+
// src/commands/email-smtp.ts
|
|
1816
|
+
const EMAIL_SMTP_USAGE = `Usage:
|
|
1817
|
+
steward email-smtp get [--json]
|
|
1818
|
+
steward email-smtp set --file <path> | --stdin
|
|
1819
|
+
steward email-smtp clear [--yes]
|
|
1820
|
+
steward email-smtp verify [--to <address>] [--json]
|
|
1821
|
+
|
|
1822
|
+
The product's own SMTP account for its billing emails (/v1/admin/email-smtp). Without one,
|
|
1823
|
+
the product's emails go through the installation's SMTP (STEWARD_SMTP_URL).
|
|
1824
|
+
|
|
1825
|
+
set reads the URL (smtp://user:pass@host:587 or smtps://user:pass@host:465; reserved
|
|
1826
|
+
characters in the password percent-encoded) from a file or from a pipe, never from an
|
|
1827
|
+
argument, so it stays out of shell history. Steward stores it encrypted and never returns
|
|
1828
|
+
it: get, doctor and the audit trail show only the host. clear goes back to the
|
|
1829
|
+
installation's SMTP.
|
|
1830
|
+
|
|
1831
|
+
verify logs in to the SMTP the product sends with and asks MAIL FROM (the product's sender,
|
|
1832
|
+
settings.emails.from.address) and RCPT TO (--to, default the sender), then stops before
|
|
1833
|
+
DATA: no email is sent. Exit code 1 when the account refuses.
|
|
1834
|
+
|
|
1835
|
+
Connection: STEWARD_ADMIN_URL + STEWARD_ADMIN_API_KEY (environment, otherwise ./.env.local).`;
|
|
1836
|
+
function schemaProblems(issues) {
|
|
1837
|
+
return issues.map((issue) => ` - ${issue.path.map(String).join(".") || "url"}: ${issue.message}`).join("\n");
|
|
1838
|
+
}
|
|
1839
|
+
const tlsText = (secure) => secure ? "TLS (smtps)" : "STARTTLS when offered";
|
|
1840
|
+
function describe(smtp) {
|
|
1841
|
+
if (!smtp.configured) return [`own account none`, `sends with ${smtp.transport === "installation" ? "the installation's SMTP (STEWARD_SMTP_URL)" : "nothing: no SMTP configured, emails are not sent"}`];
|
|
1842
|
+
return [`own account ${smtp.host}:${smtp.port} · ${tlsText(smtp.secure)} · set ${smtp.updatedAt}`, `sends with the product's own account`];
|
|
1843
|
+
}
|
|
1844
|
+
async function readUrl(ctx, values) {
|
|
1845
|
+
if (values.file === void 0 === (values.stdin !== true)) throw new UsageError("give exactly one of --file <path> or --stdin (details: steward email-smtp --help)");
|
|
1846
|
+
let text;
|
|
1847
|
+
if (values.file !== void 0) try {
|
|
1848
|
+
text = await readFile(resolve(ctx.cwd, values.file), "utf8");
|
|
1849
|
+
} catch (error) {
|
|
1850
|
+
throw new CliError(`could not read ${values.file} (${errnoCode(error) ?? "error"}); no request was sent`);
|
|
1851
|
+
}
|
|
1852
|
+
else {
|
|
1853
|
+
text = await ctx.readStdin();
|
|
1854
|
+
if (text === null) throw new UsageError("--stdin needs the URL piped in (e.g. steward email-smtp set --stdin < smtp-url.txt); it is not read from a terminal");
|
|
1855
|
+
}
|
|
1856
|
+
return text.trim();
|
|
1857
|
+
}
|
|
1858
|
+
async function emailSmtpCommand(ctx, out, args) {
|
|
1859
|
+
const [sub, ...rest] = args;
|
|
1860
|
+
if (sub === void 0 || sub === "--help" || sub === "-h" || sub === "help") {
|
|
1861
|
+
out.out(EMAIL_SMTP_USAGE);
|
|
1862
|
+
return sub === void 0 ? 2 : 0;
|
|
1863
|
+
}
|
|
1864
|
+
if (sub === "get") {
|
|
1865
|
+
const { values, positionals } = parse(rest, {
|
|
1866
|
+
...HELP_OPTION,
|
|
1867
|
+
json: { type: "boolean" }
|
|
1868
|
+
}, "email-smtp");
|
|
1869
|
+
if (values.help) return help$3(out);
|
|
1870
|
+
expectPositionals(positionals, 0, 0, "email-smtp");
|
|
1871
|
+
const target = requireAdminTarget(await resolveEnv(ctx));
|
|
1872
|
+
out.err(connectionLine(target));
|
|
1873
|
+
const smtp = await callSteward(target, () => clientFor(ctx, target).admin.emailSmtp.get());
|
|
1874
|
+
if (values.json) out.out(JSON.stringify(smtp, null, 2));
|
|
1875
|
+
else for (const line of describe(smtp)) out.out(line);
|
|
1876
|
+
return 0;
|
|
1877
|
+
}
|
|
1878
|
+
if (sub === "set") {
|
|
1879
|
+
const { values, positionals } = parse(rest, {
|
|
1880
|
+
...HELP_OPTION,
|
|
1881
|
+
file: { type: "string" },
|
|
1882
|
+
stdin: { type: "boolean" }
|
|
1883
|
+
}, "email-smtp");
|
|
1884
|
+
if (values.help) return help$3(out);
|
|
1885
|
+
expectPositionals(positionals, 0, 0, "email-smtp");
|
|
1886
|
+
const url = await readUrl(ctx, values);
|
|
1887
|
+
const parsed = SmtpUrlSchema.safeParse(url);
|
|
1888
|
+
if (!parsed.success) throw new UsageError(`invalid SMTP URL (no request was sent)\n${schemaProblems(parsed.error.issues)}`);
|
|
1889
|
+
const target = requireAdminTarget(await resolveEnv(ctx));
|
|
1890
|
+
out.err(connectionLine(target));
|
|
1891
|
+
const smtp = await callSteward(target, () => clientFor(ctx, target).admin.emailSmtp.set({ url: parsed.data }));
|
|
1892
|
+
out.out(`email SMTP account set → ${originOf(target.url)}`);
|
|
1893
|
+
for (const line of describe(smtp)) out.out(` ${line}`);
|
|
1894
|
+
out.err("Check it without sending an email: steward email-smtp verify");
|
|
1895
|
+
return 0;
|
|
1896
|
+
}
|
|
1897
|
+
if (sub === "clear") {
|
|
1898
|
+
const { values, positionals } = parse(rest, {
|
|
1899
|
+
...HELP_OPTION,
|
|
1900
|
+
yes: { type: "boolean" }
|
|
1901
|
+
}, "email-smtp");
|
|
1902
|
+
if (values.help) return help$3(out);
|
|
1903
|
+
expectPositionals(positionals, 0, 0, "email-smtp");
|
|
1904
|
+
const target = requireAdminTarget(await resolveEnv(ctx));
|
|
1905
|
+
out.err(connectionLine(target));
|
|
1906
|
+
if (!await confirm(ctx, `Remove the product's own SMTP account at ${originOf(target.url)}? Emails go back to the installation's SMTP.`, {
|
|
1907
|
+
yes: values.yes === true,
|
|
1908
|
+
notConfirmed: "the SMTP account was not removed"
|
|
1909
|
+
})) {
|
|
1910
|
+
out.err("not removed");
|
|
1911
|
+
return 1;
|
|
1912
|
+
}
|
|
1913
|
+
const smtp = await callSteward(target, () => clientFor(ctx, target).admin.emailSmtp.clear());
|
|
1914
|
+
out.out(`email SMTP account removed → ${originOf(target.url)}`);
|
|
1915
|
+
for (const line of describe(smtp)) out.out(` ${line}`);
|
|
1916
|
+
return 0;
|
|
1917
|
+
}
|
|
1918
|
+
if (sub === "verify") {
|
|
1919
|
+
const { values, positionals } = parse(rest, {
|
|
1920
|
+
...HELP_OPTION,
|
|
1921
|
+
to: { type: "string" },
|
|
1922
|
+
json: { type: "boolean" }
|
|
1923
|
+
}, "email-smtp");
|
|
1924
|
+
if (values.help) return help$3(out);
|
|
1925
|
+
expectPositionals(positionals, 0, 0, "email-smtp");
|
|
1926
|
+
const input = EmailSmtpVerifyInputSchema.safeParse(values.to !== void 0 ? { to: values.to } : {});
|
|
1927
|
+
if (!input.success) throw new UsageError("--to: must be an email address");
|
|
1928
|
+
const target = requireAdminTarget(await resolveEnv(ctx));
|
|
1929
|
+
out.err(connectionLine(target));
|
|
1930
|
+
const result = await callSteward(target, () => clientFor(ctx, target).admin.emailSmtp.verify(input.data));
|
|
1931
|
+
if (values.json) out.out(JSON.stringify(result, null, 2));
|
|
1932
|
+
else {
|
|
1933
|
+
const via = result.transport === "product" ? "product's own account" : "installation's SMTP";
|
|
1934
|
+
out.out(`${result.ok ? "ok ✓" : "refused ✗"} ${result.host} (${via}) MAIL FROM ${result.from} RCPT TO ${result.to}`);
|
|
1935
|
+
if (!result.ok) {
|
|
1936
|
+
out.out(` failed at ${result.stage} (${result.code ?? "unknown"})`);
|
|
1937
|
+
if (result.reply !== null) out.out(` server ${result.reply}`);
|
|
1938
|
+
}
|
|
1939
|
+
out.err("No email was sent (the session ended before DATA).");
|
|
1940
|
+
}
|
|
1941
|
+
return result.ok ? 0 : 1;
|
|
1942
|
+
}
|
|
1943
|
+
throw new UsageError(`unknown subcommand: email-smtp ${sub} (details: steward email-smtp --help)`);
|
|
1944
|
+
}
|
|
1945
|
+
function help$3(out) {
|
|
1946
|
+
out.out(EMAIL_SMTP_USAGE);
|
|
1947
|
+
return 0;
|
|
1948
|
+
}
|
|
1814
1949
|
// src/commands/events.ts
|
|
1815
1950
|
const EVENTS_USAGE = `Usage:
|
|
1816
1951
|
steward events send <ref> <name> [--meta key=value]… [--external-id <id>]
|
|
@@ -2960,7 +3095,7 @@ function help(out) {
|
|
|
2960
3095
|
return 0;
|
|
2961
3096
|
}
|
|
2962
3097
|
// src/main.ts
|
|
2963
|
-
const CLI_VERSION = "0.
|
|
3098
|
+
const CLI_VERSION = "0.12.0";
|
|
2964
3099
|
const USAGE = `steward — Steward CLI (@stewardhq/cli ${CLI_VERSION})
|
|
2965
3100
|
|
|
2966
3101
|
Usage: steward <command> [options]
|
|
@@ -2970,6 +3105,7 @@ Commands:
|
|
|
2970
3105
|
catalog push <file> [--yes] catalog sync (PUT /v1/admin/catalog)
|
|
2971
3106
|
settings get | set [flags] product settings (/v1/admin/settings)
|
|
2972
3107
|
endpoints list | add | rotate | deactivate webhook endpoints; the secret goes only to the --out file
|
|
3108
|
+
email-smtp get | set | clear | verify the product's own SMTP account; the URL only from a file or pipe
|
|
2973
3109
|
keys list | create | revoke API keys; the key goes only to the --out file
|
|
2974
3110
|
dunning get | set <policy.json> dunning policy (/v1/admin/dunning-policy)
|
|
2975
3111
|
reprice --plan <code> --notice-days <n> move a plan's subscribers to its current price
|
|
@@ -2996,6 +3132,7 @@ const COMMANDS = {
|
|
|
2996
3132
|
catalog: catalogCommand,
|
|
2997
3133
|
settings: settingsCommand,
|
|
2998
3134
|
endpoints: endpointsCommand,
|
|
3135
|
+
"email-smtp": emailSmtpCommand,
|
|
2999
3136
|
accounts: accountsCommand,
|
|
3000
3137
|
meters: metersCommand,
|
|
3001
3138
|
events: eventsCommand,
|
|
@@ -3071,6 +3208,12 @@ const ctx = {
|
|
|
3071
3208
|
} finally {
|
|
3072
3209
|
terminal.close();
|
|
3073
3210
|
}
|
|
3211
|
+
},
|
|
3212
|
+
readStdin: async () => {
|
|
3213
|
+
if (process.stdin.isTTY) return null;
|
|
3214
|
+
const chunks = [];
|
|
3215
|
+
for await (const chunk of process.stdin) chunks.push(chunk);
|
|
3216
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
3074
3217
|
}
|
|
3075
3218
|
};
|
|
3076
3219
|
process.exitCode = await main(process.argv.slice(2), ctx);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stewardhq/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.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.12.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/node": "^26.6.5",
|