@stewardhq/cli 0.10.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 +25 -36
- package/dist/bin.js +736 -86
- package/package.json +5 -5
package/dist/bin.js
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
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, InvoiceIssueInputSchema, InvoicePaymentStatusSchema, InvoiceStatusSchema, 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, 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";
|
|
9
9
|
import { randomUUID } from "node:crypto";
|
|
10
10
|
import { pathToFileURL } from "node:url";
|
|
11
|
-
|
|
11
|
+
// src/io.ts
|
|
12
12
|
const SECRET_PATTERN = /\b(whsec_|stw_)[A-Za-z0-9_\-+/=]+/g;
|
|
13
13
|
/** Masks secret-shaped values (`whsec_***`). */
|
|
14
14
|
function redactSecrets(text) {
|
|
@@ -41,8 +41,7 @@ function errnoCode(error) {
|
|
|
41
41
|
const code = typeof error === "object" && error !== null ? error.code : void 0;
|
|
42
42
|
return typeof code === "string" ? code : void 0;
|
|
43
43
|
}
|
|
44
|
-
|
|
45
|
-
//#region src/args.ts
|
|
44
|
+
// src/args.ts
|
|
46
45
|
const HELP_OPTION = { help: {
|
|
47
46
|
type: "boolean",
|
|
48
47
|
short: "h"
|
|
@@ -105,8 +104,7 @@ function parseBoolean(value, flag) {
|
|
|
105
104
|
].includes(text)) return false;
|
|
106
105
|
throw new UsageError(`${flag}: must be true or false`);
|
|
107
106
|
}
|
|
108
|
-
|
|
109
|
-
//#region src/catalog-diff.ts
|
|
107
|
+
// src/catalog-diff.ts
|
|
110
108
|
/** A catalog that defines benefits needs a steward with the `benefits` capability (M27). */
|
|
111
109
|
function definesBenefits(input) {
|
|
112
110
|
return Object.keys(input.benefits ?? {}).length > 0;
|
|
@@ -138,7 +136,7 @@ function formatMinor(amountMinor, currency) {
|
|
|
138
136
|
return `${amountMinor} ${currency} (minor units)`;
|
|
139
137
|
}
|
|
140
138
|
}
|
|
141
|
-
const percent = (bps) => `${bps / 100}%`;
|
|
139
|
+
const percent$1 = (bps) => `${bps / 100}%`;
|
|
142
140
|
/** Units as exact text with grouping (`2,000,000`, `0.25`). */
|
|
143
141
|
const unitsText = (value) => new Intl.NumberFormat("en", { maximumFractionDigits: 6 }).format(plainDecimalOf(value));
|
|
144
142
|
const meteredKey = (p) => `${p.planCode}/${p.meter}/${p.currency}`;
|
|
@@ -286,7 +284,7 @@ function diffCatalog(current, file) {
|
|
|
286
284
|
function describePriceChange({ label, currency, from, to }) {
|
|
287
285
|
const parts = [];
|
|
288
286
|
if (from.amountMinor !== to.amountMinor) parts.push(`${formatMinor(from.amountMinor, currency)} → ${formatMinor(to.amountMinor, currency)}`);
|
|
289
|
-
if (from.taxRateBps !== to.taxRateBps) parts.push(`tax rate ${percent(from.taxRateBps)} → ${percent(to.taxRateBps)}`);
|
|
287
|
+
if (from.taxRateBps !== to.taxRateBps) parts.push(`tax rate ${percent$1(from.taxRateBps)} → ${percent$1(to.taxRateBps)}`);
|
|
290
288
|
if (from.taxInclusive !== to.taxInclusive) parts.push(`tax ${from.taxInclusive ? "inclusive" : "exclusive"} → ${to.taxInclusive ? "inclusive" : "exclusive"}`);
|
|
291
289
|
return `${from.amountMinor === to.amountMinor ? `${label} ${formatMinor(to.amountMinor, currency)}` : label}: ${parts.join(", ")}`;
|
|
292
290
|
}
|
|
@@ -305,7 +303,7 @@ function describeMeteredPriceChange({ label, currency, from, to }) {
|
|
|
305
303
|
const cap = (minor) => minor === null ? "none" : formatMinor(minor, currency);
|
|
306
304
|
parts.push(`cap ${cap(from.capMinor)} → ${cap(to.capMinor)}`);
|
|
307
305
|
}
|
|
308
|
-
if (from.taxRateBps !== to.taxRateBps) parts.push(`tax rate ${percent(from.taxRateBps)} → ${percent(to.taxRateBps)}`);
|
|
306
|
+
if (from.taxRateBps !== to.taxRateBps) parts.push(`tax rate ${percent$1(from.taxRateBps)} → ${percent$1(to.taxRateBps)}`);
|
|
309
307
|
if (from.taxInclusive !== to.taxInclusive) parts.push(`tax ${from.taxInclusive ? "inclusive" : "exclusive"} → ${to.taxInclusive ? "inclusive" : "exclusive"}`);
|
|
310
308
|
return `${label}: ${parts.join(", ")}`;
|
|
311
309
|
}
|
|
@@ -359,8 +357,7 @@ function describeDiff(diff) {
|
|
|
359
357
|
function priceChangeCount(diff) {
|
|
360
358
|
return diff.prices.changed.length + diff.meteredPrices.changed.length;
|
|
361
359
|
}
|
|
362
|
-
|
|
363
|
-
//#region src/dotenv.ts
|
|
360
|
+
// src/dotenv.ts
|
|
364
361
|
const LINE = /^(\s*)(export\s+)?([A-Za-z_][A-Za-z0-9_.-]*)\s*=(.*)$/;
|
|
365
362
|
function unquote(rest) {
|
|
366
363
|
const value = rest.trim();
|
|
@@ -391,8 +388,7 @@ async function readDotenvFile(path) {
|
|
|
391
388
|
throw error;
|
|
392
389
|
}
|
|
393
390
|
}
|
|
394
|
-
|
|
395
|
-
//#region src/env.ts
|
|
391
|
+
// src/env.ts
|
|
396
392
|
const ENV_LOCAL = ".env.local";
|
|
397
393
|
/** If even one of these is in the process environment, `.env.local` is not read. */
|
|
398
394
|
const CONNECTION_VARIABLES = [
|
|
@@ -526,8 +522,7 @@ function describeStewardError(error, target) {
|
|
|
526
522
|
}
|
|
527
523
|
return `steward response does not match the contract${where}: ${error.code} (HTTP ${error.httpStatus}) — the CLI and steward versions may be incompatible${request}`;
|
|
528
524
|
}
|
|
529
|
-
|
|
530
|
-
//#region src/commands/accounts.ts
|
|
525
|
+
// src/commands/accounts.ts
|
|
531
526
|
const ACCOUNTS_USAGE = `Usage:
|
|
532
527
|
steward accounts get <ref> [--include <a,b>] [--json]
|
|
533
528
|
steward accounts metadata set <ref> <key>=<value>… [--reason <text>] [--json]
|
|
@@ -703,8 +698,7 @@ async function accountsCommand(ctx, out, args) {
|
|
|
703
698
|
if (sub === "metadata") return metadataCommand(ctx, out, rest);
|
|
704
699
|
throw new UsageError(`unknown subcommand: accounts ${sub} (see: steward accounts --help)`);
|
|
705
700
|
}
|
|
706
|
-
|
|
707
|
-
//#region src/confirm.ts
|
|
701
|
+
// src/confirm.ts
|
|
708
702
|
/**
|
|
709
703
|
* Asks before a change that cannot be taken back; `yes` (`--yes`) skips the question. Without a
|
|
710
704
|
* terminal (CI, pipes) the command needs `--yes`: `notConfirmed` says what was not done.
|
|
@@ -715,8 +709,7 @@ async function confirm(ctx, question, options) {
|
|
|
715
709
|
if (answer === null) throw new CliError(`confirmation needed: run again with --yes (${options.notConfirmed})`);
|
|
716
710
|
return /^y(es)?$/i.test(answer.trim());
|
|
717
711
|
}
|
|
718
|
-
|
|
719
|
-
//#region src/secret-file.ts
|
|
712
|
+
// src/secret-file.ts
|
|
720
713
|
async function withSecretFile(cwd, out, secret, options, action) {
|
|
721
714
|
const target = resolve(cwd, out);
|
|
722
715
|
try {
|
|
@@ -763,8 +756,7 @@ async function withSecretFile(cwd, out, secret, options, action) {
|
|
|
763
756
|
};
|
|
764
757
|
}
|
|
765
758
|
}
|
|
766
|
-
|
|
767
|
-
//#region src/commands/endpoints.ts
|
|
759
|
+
// src/commands/endpoints.ts
|
|
768
760
|
const ENDPOINTS_USAGE = `Usage:
|
|
769
761
|
steward endpoints list [--json]
|
|
770
762
|
steward endpoints add --url <url> --out <file> [--event-types <a,b>] [--description <text>] [--force]
|
|
@@ -781,7 +773,7 @@ product moves over with a "new,old" list. Delete the file after moving it. Witho
|
|
|
781
773
|
endpoint).
|
|
782
774
|
|
|
783
775
|
Connection: STEWARD_ADMIN_URL + STEWARD_ADMIN_API_KEY (environment, otherwise ./.env.local).`;
|
|
784
|
-
function schemaProblems(issues) {
|
|
776
|
+
function schemaProblems$1(issues) {
|
|
785
777
|
return issues.map((issue) => ` - ${issue.path.map(String).join(".") || "(root)"}: ${issue.message}`).join("\n");
|
|
786
778
|
}
|
|
787
779
|
const lastDeliveryText = (endpoint) => {
|
|
@@ -806,7 +798,7 @@ async function endpointsCommand(ctx, out, args) {
|
|
|
806
798
|
...HELP_OPTION,
|
|
807
799
|
json: { type: "boolean" }
|
|
808
800
|
}, "endpoints");
|
|
809
|
-
if (values.help) return help$
|
|
801
|
+
if (values.help) return help$6(out);
|
|
810
802
|
expectPositionals(positionals, 0, 0, "endpoints");
|
|
811
803
|
const target = requireAdminTarget(await resolveEnv(ctx));
|
|
812
804
|
out.err(connectionLine(target));
|
|
@@ -841,7 +833,7 @@ async function endpointsCommand(ctx, out, args) {
|
|
|
841
833
|
description: { type: "string" },
|
|
842
834
|
force: { type: "boolean" }
|
|
843
835
|
}, ENDPOINTS_USAGE);
|
|
844
|
-
if (values.help) return help$
|
|
836
|
+
if (values.help) return help$6(out);
|
|
845
837
|
expectPositionals(positionals, 0, 0, "endpoints");
|
|
846
838
|
const url = requireOption(values.url, "--url", "endpoints");
|
|
847
839
|
const file = requireOption(values.out, "--out", "endpoints");
|
|
@@ -853,7 +845,7 @@ async function endpointsCommand(ctx, out, args) {
|
|
|
853
845
|
...values.description !== void 0 ? { description: values.description } : {}
|
|
854
846
|
};
|
|
855
847
|
const parsed = WebhookEndpointCreateInputSchema.safeParse(input);
|
|
856
|
-
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)}`);
|
|
857
849
|
const target = requireAdminTarget(await resolveEnv(ctx));
|
|
858
850
|
out.err(connectionLine(target));
|
|
859
851
|
const steward = clientFor(ctx, target);
|
|
@@ -872,13 +864,13 @@ async function endpointsCommand(ctx, out, args) {
|
|
|
872
864
|
out: { type: "string" },
|
|
873
865
|
force: { type: "boolean" }
|
|
874
866
|
}, "endpoints");
|
|
875
|
-
if (values.help) return help$
|
|
867
|
+
if (values.help) return help$6(out);
|
|
876
868
|
expectPositionals(positionals, 1, 1, "endpoints");
|
|
877
869
|
const id = positionals[0];
|
|
878
870
|
const file = requireOption(values.out, "--out", "endpoints");
|
|
879
871
|
const secret = generateWebhookSecret();
|
|
880
872
|
const parsed = WebhookEndpointRotateInputSchema.safeParse({ secret });
|
|
881
|
-
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)}`);
|
|
882
874
|
const target = requireAdminTarget(await resolveEnv(ctx));
|
|
883
875
|
out.err(connectionLine(target));
|
|
884
876
|
const steward = clientFor(ctx, target);
|
|
@@ -891,7 +883,7 @@ async function endpointsCommand(ctx, out, args) {
|
|
|
891
883
|
}
|
|
892
884
|
if (sub === "deactivate") {
|
|
893
885
|
const { values, positionals } = parse(rest, { ...HELP_OPTION }, "endpoints");
|
|
894
|
-
if (values.help) return help$
|
|
886
|
+
if (values.help) return help$6(out);
|
|
895
887
|
expectPositionals(positionals, 1, 1, "endpoints");
|
|
896
888
|
const target = requireAdminTarget(await resolveEnv(ctx));
|
|
897
889
|
out.err(connectionLine(target));
|
|
@@ -901,7 +893,7 @@ async function endpointsCommand(ctx, out, args) {
|
|
|
901
893
|
}
|
|
902
894
|
throw new UsageError(`unknown subcommand: endpoints ${sub} (details: steward endpoints --help)`);
|
|
903
895
|
}
|
|
904
|
-
function help$
|
|
896
|
+
function help$6(out) {
|
|
905
897
|
out.out(ENDPOINTS_USAGE);
|
|
906
898
|
return 0;
|
|
907
899
|
}
|
|
@@ -911,15 +903,14 @@ function secretNotice(out, path, fallback, next) {
|
|
|
911
903
|
out.out(` secret ${path} (0600; not written to the terminal)`);
|
|
912
904
|
out.err(next);
|
|
913
905
|
}
|
|
914
|
-
|
|
915
|
-
//#region src/commands/bank-transfers.ts
|
|
906
|
+
// src/commands/bank-transfers.ts
|
|
916
907
|
const BANK_TRANSFERS_USAGE = `Usage:
|
|
917
908
|
steward bank-transfers list [--status pending|expired] [--rate <rate> [--currency <CUR>]]
|
|
918
909
|
[--json]
|
|
919
910
|
steward bank-transfers record <code> --amount <minor> --currency <CUR> --received-at <iso>
|
|
920
911
|
--bank-ref <ref> [--rate <rate>]
|
|
921
912
|
[--checkout <id> [--accept-expired] | --invoice <id>]
|
|
922
|
-
[--yes] [--json]
|
|
913
|
+
[--override-billing-currency] [--yes] [--json]
|
|
923
914
|
steward bank-transfers fx-report [--from <iso>] [--to <iso>] [--json | --csv]
|
|
924
915
|
|
|
925
916
|
Bank transfer (havale/EFT) reconciliation (/v1/admin/bank-transfers).
|
|
@@ -949,6 +940,10 @@ within the product's tolerance (fxToleranceBps, default 0.5%) of its amount at t
|
|
|
949
940
|
is settled in its own currency. --rate is required for such a transfer and refused for one in
|
|
950
941
|
the item's currency. Steward never looks a rate up.
|
|
951
942
|
|
|
943
|
+
record --override-billing-currency: settle a checkout that is not in the account's billing
|
|
944
|
+
currency (another payment fixed it after the checkout opened; refused with currency_mismatch
|
|
945
|
+
otherwise). Not needed for an invoice, nor for a checkout the product opened with the override.
|
|
946
|
+
|
|
952
947
|
fx-report: the payments received in another currency (invoice number and date, amount settled,
|
|
953
948
|
amount received, the rate entered, received date), latest first; --from (inclusive) and --to
|
|
954
949
|
(exclusive) are ISO-8601 with an offset, by received date. The accountant's input for
|
|
@@ -970,7 +965,7 @@ async function bankTransfersCommand(ctx, out, args) {
|
|
|
970
965
|
currency: { type: "string" },
|
|
971
966
|
json: { type: "boolean" }
|
|
972
967
|
}, "bank-transfers");
|
|
973
|
-
if (values.help) return help$
|
|
968
|
+
if (values.help) return help$5(out);
|
|
974
969
|
expectPositionals(positionals, 0, 0, "bank-transfers");
|
|
975
970
|
const status = values.status ?? "pending";
|
|
976
971
|
if (status !== "pending" && status !== "expired") throw new UsageError("--status: pending or expired");
|
|
@@ -1025,13 +1020,14 @@ async function bankTransfersCommand(ctx, out, args) {
|
|
|
1025
1020
|
checkout: { type: "string" },
|
|
1026
1021
|
invoice: { type: "string" },
|
|
1027
1022
|
"accept-expired": { type: "boolean" },
|
|
1023
|
+
"override-billing-currency": { type: "boolean" },
|
|
1028
1024
|
yes: {
|
|
1029
1025
|
type: "boolean",
|
|
1030
1026
|
short: "y"
|
|
1031
1027
|
},
|
|
1032
1028
|
json: { type: "boolean" }
|
|
1033
1029
|
}, "bank-transfers");
|
|
1034
|
-
if (values.help) return help$
|
|
1030
|
+
if (values.help) return help$5(out);
|
|
1035
1031
|
expectPositionals(positionals, 1, 1, "bank-transfers");
|
|
1036
1032
|
const receivedAt = requireOption(values["received-at"], "--received-at", "bank-transfers");
|
|
1037
1033
|
if (!WITH_OFFSET$1.test(receivedAt)) throw new UsageError("--received-at: ISO-8601 with an offset (2026-09-28T10:15:00+03:00)");
|
|
@@ -1044,7 +1040,8 @@ async function bankTransfersCommand(ctx, out, args) {
|
|
|
1044
1040
|
...values.rate !== void 0 ? { rate: parseRate(values.rate) } : {},
|
|
1045
1041
|
...values.checkout !== void 0 ? { checkoutSessionId: values.checkout } : {},
|
|
1046
1042
|
...values.invoice !== void 0 ? { invoiceId: values.invoice } : {},
|
|
1047
|
-
...values["accept-expired"] ? { acceptExpired: true } : {}
|
|
1043
|
+
...values["accept-expired"] ? { acceptExpired: true } : {},
|
|
1044
|
+
...values["override-billing-currency"] ? { overrideBillingCurrency: true } : {}
|
|
1048
1045
|
};
|
|
1049
1046
|
const parsed = BankTransferRecordInputSchema.safeParse(input);
|
|
1050
1047
|
if (!parsed.success) throw new UsageError(`invalid transfer (nothing was sent)\n${parsed.error.issues.map((issue) => ` - ${issue.path.map(String).join(".") || "(root)"}: ${issue.message}`).join("\n")}`);
|
|
@@ -1074,7 +1071,7 @@ async function bankTransfersCommand(ctx, out, args) {
|
|
|
1074
1071
|
json: { type: "boolean" },
|
|
1075
1072
|
csv: { type: "boolean" }
|
|
1076
1073
|
}, "bank-transfers");
|
|
1077
|
-
if (values.help) return help$
|
|
1074
|
+
if (values.help) return help$5(out);
|
|
1078
1075
|
expectPositionals(positionals, 0, 0, "bank-transfers");
|
|
1079
1076
|
if (values.json && values.csv) throw new UsageError("--json or --csv, not both");
|
|
1080
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)");
|
|
@@ -1139,12 +1136,11 @@ function csvField(value) {
|
|
|
1139
1136
|
const text = typeof value === "string" && /^[=+\-@]/.test(value) ? `'${value}` : String(value);
|
|
1140
1137
|
return /[",\n\r]/.test(text) ? `"${text.replace(/"/g, "\"\"")}"` : text;
|
|
1141
1138
|
}
|
|
1142
|
-
function help$
|
|
1139
|
+
function help$5(out) {
|
|
1143
1140
|
out.out(BANK_TRANSFERS_USAGE);
|
|
1144
1141
|
return 0;
|
|
1145
1142
|
}
|
|
1146
|
-
|
|
1147
|
-
//#region src/catalog-file.ts
|
|
1143
|
+
// src/catalog-file.ts
|
|
1148
1144
|
const MODULE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
1149
1145
|
".js",
|
|
1150
1146
|
".mjs",
|
|
@@ -1204,8 +1200,7 @@ async function loadCatalogFile(ctx, file) {
|
|
|
1204
1200
|
if (!parsed.success) throw new CliError(`${file}: invalid catalog (no request was sent)\n${parsed.error.issues.map((issue) => ` - ${issue.path.map(String).join(".") || "(root)"}: ${issue.message}`).join("\n")}`);
|
|
1205
1201
|
return input;
|
|
1206
1202
|
}
|
|
1207
|
-
|
|
1208
|
-
//#region src/commands/catalog.ts
|
|
1203
|
+
// src/commands/catalog.ts
|
|
1209
1204
|
const CATALOG_USAGE = `Usage: steward catalog push <file> [--yes]
|
|
1210
1205
|
|
|
1211
1206
|
Syncs the catalog definition to steward (PUT /v1/admin/catalog), then prints the version
|
|
@@ -1340,8 +1335,7 @@ async function catalogCommand(ctx, out, args) {
|
|
|
1340
1335
|
for (const line of lines) out.out(line);
|
|
1341
1336
|
return providerErrors > 0 ? 1 : 0;
|
|
1342
1337
|
}
|
|
1343
|
-
|
|
1344
|
-
//#region src/commands/meters.ts
|
|
1338
|
+
// src/commands/meters.ts
|
|
1345
1339
|
const METERS_USAGE = `Usage:
|
|
1346
1340
|
steward meters get <ref> [--periods <n>] [--json]
|
|
1347
1341
|
steward meters recompute <ref> [--meter <code>] [--json]
|
|
@@ -1464,8 +1458,7 @@ async function metersCommand(ctx, out, args) {
|
|
|
1464
1458
|
else for (const line of formatMeters(meters, periods)) out.out(line);
|
|
1465
1459
|
return 0;
|
|
1466
1460
|
}
|
|
1467
|
-
|
|
1468
|
-
//#region src/commands/credits.ts
|
|
1461
|
+
// src/commands/credits.ts
|
|
1469
1462
|
const CREDITS_USAGE = `Usage: steward credits adjust <ref> <meter> --units=<n> --reason <text> [--json]
|
|
1470
1463
|
|
|
1471
1464
|
One credit ledger entry for the meter's current usage period of account <ref>
|
|
@@ -1518,8 +1511,7 @@ async function creditsCommand(ctx, out, args) {
|
|
|
1518
1511
|
if (read !== void 0) out.out(` balance ${formatUnitsText(read.balance)} · standing ${read.standing}`);
|
|
1519
1512
|
return 0;
|
|
1520
1513
|
}
|
|
1521
|
-
|
|
1522
|
-
//#region src/commands/doctor.ts
|
|
1514
|
+
// src/commands/doctor.ts
|
|
1523
1515
|
const DOCTOR_USAGE = `Usage: steward doctor [--json]
|
|
1524
1516
|
|
|
1525
1517
|
The GET /v1/doctor report. Sections in order: status, catalog, provider, settings,
|
|
@@ -1663,11 +1655,18 @@ function formatDoctorReport(report, cliWarnings, metering = null) {
|
|
|
1663
1655
|
lines.push(`catalog synced ${yesNo(catalog.synced)}${catalog.version !== null ? ` · version ${catalog.version}` : ""} · ${plural(catalog.plans, "plan")} · ${plural(catalog.sellablePrices, "sellable price")} · ${catalog.unsellablePrices.length} unsellable`);
|
|
1664
1656
|
for (const price of catalog.unsellablePrices) lines.push(` ✗ ${price.planCode} ${price.interval}×${price.intervalCount} ${price.currency}: ${price.reason}`);
|
|
1665
1657
|
const providerState = !provider.configured ? "not configured ✗" : provider.healthy === false ? "unreachable !" : "configured ✓";
|
|
1658
|
+
const webhook = provider.webhook ? ` · webhook ${provider.webhook.configured ? `configured ✓ (last event ${provider.webhook.lastEventAt ?? "never"})` : "not configured ✗"}${provider.webhook.openDisputes > 0 ? ` · ${provider.webhook.openDisputes} open dispute(s) !` : ""}` : "";
|
|
1659
|
+
const renewal = provider.automaticRenewal ? ` · automatic renewal active ✓ (${provider.automaticRenewal.subscriptionsWithCard} with a saved card, ${provider.automaticRenewal.subscriptionsWithoutCard} without; renewal notice ${provider.automaticRenewal.renewalNotice ? `${provider.automaticRenewal.renewalNotice.daysBefore} days before, ${provider.automaticRenewal.renewalNotice.intervals.join("/")}` : "off"})` : provider.configured ? " · automatic renewal off (invoice e-mail and pay page)" : "";
|
|
1666
1660
|
const providerError = provider.lastError ? ` · last error ${provider.lastError.code} (${provider.lastError.operation}, ${provider.lastError.at})` : "";
|
|
1667
|
-
lines.push(`provider ${provider.id}${provider.environment !== null ? ` · ${provider.environment}` : ""} · ${providerState}${providerError}`);
|
|
1661
|
+
lines.push(`provider ${provider.id}${provider.environment !== null ? ` · ${provider.environment}` : ""} · ${providerState}${webhook}${renewal}${providerError}`);
|
|
1668
1662
|
lines.push(`settings appUrl ${settings.appUrl ?? "none"} · return origins: ${settings.returnOrigins.length > 0 ? settings.returnOrigins.join(", ") : "none"}`);
|
|
1669
1663
|
const missing = [...hosted.branding.missing.map((field) => `branding.${field}`), ...hosted.legalLinks.missing];
|
|
1670
1664
|
lines.push(`hosted ${hosted.ready ? "ready ✓" : `not ready ✗${missing.length > 0 ? ` (missing: ${missing.join(", ")})` : ""}`}`);
|
|
1665
|
+
if (report.legal) {
|
|
1666
|
+
const legal = report.legal;
|
|
1667
|
+
const mark = (set) => set ? "✓" : "✗";
|
|
1668
|
+
lines.push(`legal seller ${mark(legal.seller)} · withdrawal waiver ${legal.withdrawalWaiver ? `${legal.withdrawalWaiver.version} ✓` : "✗"}` + (legal.cardSaved ? ` · card-on-file consent ${legal.cardOnFile ? `${legal.cardOnFile.version} ✓` : "✗"}` : "") + (legal.pendingErasures > 0 ? ` · ${legal.pendingErasures} provider erasure(s) pending !` : ""));
|
|
1669
|
+
}
|
|
1671
1670
|
if (report.endpoints.length === 0) lines.push("endpoints none");
|
|
1672
1671
|
else {
|
|
1673
1672
|
lines.push("endpoints");
|
|
@@ -1682,7 +1681,8 @@ function formatDoctorReport(report, cliWarnings, metering = null) {
|
|
|
1682
1681
|
const { emails } = report;
|
|
1683
1682
|
const problems = [...emails.transportConfigured ? [] : ["no transport"], ...emails.senderConfigured ? [] : ["no sender"]];
|
|
1684
1683
|
const disabled = emails.disabledTemplates.length > 0 ? ` · disabled: ${emails.disabledTemplates.join(", ")}` : "";
|
|
1685
|
-
|
|
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}`);
|
|
1686
1686
|
}
|
|
1687
1687
|
if (report.apiKeys) {
|
|
1688
1688
|
lines.push(report.apiKeys.length === 0 ? "api keys none active" : "api keys");
|
|
@@ -1732,8 +1732,7 @@ async function doctorCommand(ctx, out, args) {
|
|
|
1732
1732
|
else for (const line of formatDoctorReport(report, cliWarnings, metering)) out.out(line);
|
|
1733
1733
|
return failed ? 1 : 0;
|
|
1734
1734
|
}
|
|
1735
|
-
|
|
1736
|
-
//#region src/commands/dunning.ts
|
|
1735
|
+
// src/commands/dunning.ts
|
|
1737
1736
|
const DUNNING_USAGE = `Usage:
|
|
1738
1737
|
steward dunning get [--json]
|
|
1739
1738
|
steward dunning set <policy.json> [--yes]
|
|
@@ -1759,7 +1758,7 @@ async function dunningCommand(ctx, out, args) {
|
|
|
1759
1758
|
...HELP_OPTION,
|
|
1760
1759
|
json: { type: "boolean" }
|
|
1761
1760
|
}, "dunning");
|
|
1762
|
-
if (values.help) return help$
|
|
1761
|
+
if (values.help) return help$4(out);
|
|
1763
1762
|
expectPositionals(positionals, 0, 0, "dunning");
|
|
1764
1763
|
const target = requireAdminTarget(await resolveEnv(ctx));
|
|
1765
1764
|
out.err(connectionLine(target));
|
|
@@ -1776,7 +1775,7 @@ async function dunningCommand(ctx, out, args) {
|
|
|
1776
1775
|
short: "y"
|
|
1777
1776
|
}
|
|
1778
1777
|
}, "dunning");
|
|
1779
|
-
if (values.help) return help$
|
|
1778
|
+
if (values.help) return help$4(out);
|
|
1780
1779
|
expectPositionals(positionals, 1, 1, "dunning");
|
|
1781
1780
|
const file = positionals[0];
|
|
1782
1781
|
let json;
|
|
@@ -1809,12 +1808,145 @@ async function dunningCommand(ctx, out, args) {
|
|
|
1809
1808
|
}
|
|
1810
1809
|
throw new UsageError(`unknown subcommand: dunning ${sub} (see: steward dunning --help)`);
|
|
1811
1810
|
}
|
|
1812
|
-
function help$
|
|
1811
|
+
function help$4(out) {
|
|
1813
1812
|
out.out(DUNNING_USAGE);
|
|
1814
1813
|
return 0;
|
|
1815
1814
|
}
|
|
1816
|
-
|
|
1817
|
-
|
|
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
|
+
}
|
|
1949
|
+
// src/commands/events.ts
|
|
1818
1950
|
const EVENTS_USAGE = `Usage:
|
|
1819
1951
|
steward events send <ref> <name> [--meta key=value]… [--external-id <id>]
|
|
1820
1952
|
[--timestamp <iso>] [--json]
|
|
@@ -1940,11 +2072,89 @@ async function redeliverCommand(ctx, out, args) {
|
|
|
1940
2072
|
}
|
|
1941
2073
|
return 0;
|
|
1942
2074
|
}
|
|
1943
|
-
|
|
1944
|
-
|
|
2075
|
+
// src/commands/grants.ts
|
|
2076
|
+
const GRANTS_USAGE = `Usage:
|
|
2077
|
+
steward grants list [--plan <code>] [--subscription none|live|any] [--limit <n>]
|
|
2078
|
+
[--after <grant id>] [--json]
|
|
2079
|
+
|
|
2080
|
+
The product's active grants (not revoked, started, not ended), one line per grant, with the
|
|
2081
|
+
account and its live subscriptions (GET /v1/admin/grants).
|
|
2082
|
+
|
|
2083
|
+
--plan: only the grants of that plan (a code the product never had is refused). Without it,
|
|
2084
|
+
grants of named benefits or overrides only are listed too (plan -).
|
|
2085
|
+
--subscription: none = accounts with no live subscription (active, past_due, suspended), e.g.
|
|
2086
|
+
granted a plan but paying for nothing; live = accounts with one; any (default) = both.
|
|
2087
|
+
--limit: 1–${GRANT_LIST_MAX_LIMIT}, default ${GRANT_LIST_DEFAULT_LIMIT}; a cut list says so on stderr with the --after
|
|
2088
|
+
value of the next page.
|
|
2089
|
+
|
|
2090
|
+
Connection: STEWARD_ADMIN_URL + STEWARD_ADMIN_API_KEY (environment, otherwise ./.env.local).`;
|
|
2091
|
+
async function grantsCommand(ctx, out, args) {
|
|
2092
|
+
const [sub, ...rest] = args;
|
|
2093
|
+
if (sub === void 0 || sub === "--help" || sub === "-h" || sub === "help") {
|
|
2094
|
+
out.out(GRANTS_USAGE);
|
|
2095
|
+
return sub === void 0 ? 2 : 0;
|
|
2096
|
+
}
|
|
2097
|
+
if (sub === "list") {
|
|
2098
|
+
const { values, positionals } = parse(rest, {
|
|
2099
|
+
...HELP_OPTION,
|
|
2100
|
+
plan: { type: "string" },
|
|
2101
|
+
subscription: { type: "string" },
|
|
2102
|
+
limit: { type: "string" },
|
|
2103
|
+
after: { type: "string" },
|
|
2104
|
+
json: { type: "boolean" }
|
|
2105
|
+
}, "grants");
|
|
2106
|
+
if (values.help) {
|
|
2107
|
+
out.out(GRANTS_USAGE);
|
|
2108
|
+
return 0;
|
|
2109
|
+
}
|
|
2110
|
+
expectPositionals(positionals, 0, 0, "grants");
|
|
2111
|
+
if (values.plan !== void 0 && !CodeSchema.safeParse(values.plan).success) throw new UsageError("--plan: a plan code");
|
|
2112
|
+
const subscription = GrantListSubscriptionFilterSchema.optional().safeParse(values.subscription);
|
|
2113
|
+
if (!subscription.success) throw new UsageError("--subscription: none, live or any");
|
|
2114
|
+
if (values.after !== void 0 && !IdSchema.safeParse(values.after).success) throw new UsageError("--after: a grant id");
|
|
2115
|
+
const limit = values.limit !== void 0 ? parsePositiveInt(values.limit, "--limit", { max: GRANT_LIST_MAX_LIMIT }) : void 0;
|
|
2116
|
+
const filter = {
|
|
2117
|
+
...values.plan !== void 0 ? { plan: values.plan } : {},
|
|
2118
|
+
...subscription.data !== void 0 ? { subscription: subscription.data } : {},
|
|
2119
|
+
...limit !== void 0 ? { limit } : {},
|
|
2120
|
+
...values.after !== void 0 ? { after: values.after } : {}
|
|
2121
|
+
};
|
|
2122
|
+
const target = requireAdminTarget(await resolveEnv(ctx));
|
|
2123
|
+
out.err(connectionLine(target));
|
|
2124
|
+
const { items, hasMore } = await callSteward(target, () => clientFor(ctx, target).admin.grants.list(filter));
|
|
2125
|
+
if (values.json) out.out(JSON.stringify(items, null, 2));
|
|
2126
|
+
else if (items.length === 0) out.out("no active grants");
|
|
2127
|
+
else {
|
|
2128
|
+
const rows = [[
|
|
2129
|
+
"ACCOUNT",
|
|
2130
|
+
"NAME",
|
|
2131
|
+
"PLAN",
|
|
2132
|
+
"ENDS",
|
|
2133
|
+
"SUBSCRIPTIONS",
|
|
2134
|
+
"GRANT",
|
|
2135
|
+
"REASON"
|
|
2136
|
+
]];
|
|
2137
|
+
for (const g of items) rows.push([
|
|
2138
|
+
g.accountRef,
|
|
2139
|
+
g.accountDisplayName || "-",
|
|
2140
|
+
g.planCode ?? "-",
|
|
2141
|
+
g.endsAt ?? "-",
|
|
2142
|
+
g.liveSubscriptions.map((s) => `${s.planCode}/${s.interval} ${s.status}`).join(", ") || "-",
|
|
2143
|
+
g.grantId,
|
|
2144
|
+
g.reason
|
|
2145
|
+
]);
|
|
2146
|
+
for (const line of table(rows)) out.out(line);
|
|
2147
|
+
}
|
|
2148
|
+
const last = items.at(-1);
|
|
2149
|
+
if (hasMore && last !== void 0) out.err(`more grants than the ${limit ?? GRANT_LIST_DEFAULT_LIMIT} listed; next page: --after ${last.grantId}`);
|
|
2150
|
+
return 0;
|
|
2151
|
+
}
|
|
2152
|
+
throw new UsageError(`unknown subcommand: grants ${sub} (see: steward grants --help)`);
|
|
2153
|
+
}
|
|
2154
|
+
// src/commands/invoices.ts
|
|
1945
2155
|
const INVOICES_USAGE = `Usage:
|
|
1946
2156
|
steward invoices list [--status draft|issued|void|all] [--payment-status <status>]
|
|
1947
|
-
[--limit <n>] [--json]
|
|
2157
|
+
[--from <iso>] [--to <iso>] [--limit <n>] [--json | --csv]
|
|
1948
2158
|
steward invoices issue <id> --number <number> [--external-ref <ref>] [--issued-at <iso>]
|
|
1949
2159
|
[--document <file.pdf>] [--yes] [--json]
|
|
1950
2160
|
|
|
@@ -1952,8 +2162,15 @@ Tracking which invoices have been cut in the external system (e-Arşiv, the acco
|
|
|
1952
2162
|
|
|
1953
2163
|
list: the product's invoices, oldest first (GET /v1/admin/invoices). draft (default): the ones
|
|
1954
2164
|
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, …). --
|
|
1956
|
-
|
|
2165
|
+
every status. --payment-status narrows it (unpaid, paid, …). --from (inclusive) and --to
|
|
2166
|
+
(exclusive), ISO-8601 with an offset, keep the invoices written in that window. --limit: 1–500,
|
|
2167
|
+
default 100; a cut list says so on stderr.
|
|
2168
|
+
|
|
2169
|
+
--csv is the export for an accounting system that issues the invoices (one row per invoice, a
|
|
2170
|
+
header row first): the invoice, its amounts in minor units, the tax decision (treatment, reason,
|
|
2171
|
+
tax country), the period, the payment (date, method, reference), the buyer copy (kind, names,
|
|
2172
|
+
contact, address with postal code, region and country, tax ID with its type) and the lines as a
|
|
2173
|
+
JSON array. Columns are only ever added at the end. --json prints the items as the API returns them.
|
|
1957
2174
|
|
|
1958
2175
|
issue: writes the number the invoice got in the external system and marks it issued
|
|
1959
2176
|
(POST /v1/invoices/:id/issue). --number is unique within the product. --external-ref is any
|
|
@@ -1976,11 +2193,17 @@ async function invoicesCommand(ctx, out, args) {
|
|
|
1976
2193
|
...HELP_OPTION,
|
|
1977
2194
|
status: { type: "string" },
|
|
1978
2195
|
"payment-status": { type: "string" },
|
|
2196
|
+
from: { type: "string" },
|
|
2197
|
+
to: { type: "string" },
|
|
1979
2198
|
limit: { type: "string" },
|
|
1980
|
-
json: { type: "boolean" }
|
|
2199
|
+
json: { type: "boolean" },
|
|
2200
|
+
csv: { type: "boolean" }
|
|
1981
2201
|
}, "invoices");
|
|
1982
|
-
if (values.help) return help$
|
|
2202
|
+
if (values.help) return help$2(out);
|
|
1983
2203
|
expectPositionals(positionals, 0, 0, "invoices");
|
|
2204
|
+
if (values.json && values.csv) throw new UsageError("--json and --csv: choose one");
|
|
2205
|
+
if (values.from !== void 0 && !DateTimeSchema.safeParse(values.from).success) throw new UsageError("--from: ISO-8601 with an offset, e.g. 2026-10-01T00:00:00Z");
|
|
2206
|
+
if (values.to !== void 0 && !DateTimeSchema.safeParse(values.to).success) throw new UsageError("--to: ISO-8601 with an offset, e.g. 2026-10-01T00:00:00Z");
|
|
1984
2207
|
const statusText = values.status ?? "draft";
|
|
1985
2208
|
const status = statusText === "all" ? void 0 : InvoiceStatusSchema.safeParse(statusText).data;
|
|
1986
2209
|
if (statusText !== "all" && status === void 0) throw new UsageError("--status: draft, issued, void or all");
|
|
@@ -1990,13 +2213,18 @@ async function invoicesCommand(ctx, out, args) {
|
|
|
1990
2213
|
const filter = {
|
|
1991
2214
|
...status !== void 0 ? { status } : {},
|
|
1992
2215
|
...paymentStatus.data !== void 0 ? { paymentStatus: paymentStatus.data } : {},
|
|
2216
|
+
...values.from !== void 0 ? { from: values.from } : {},
|
|
2217
|
+
...values.to !== void 0 ? { to: values.to } : {},
|
|
1993
2218
|
...limit !== void 0 ? { limit } : {}
|
|
1994
2219
|
};
|
|
1995
2220
|
const target = requireAdminTarget(await resolveEnv(ctx));
|
|
1996
2221
|
out.err(connectionLine(target));
|
|
1997
2222
|
const { items, hasMore } = await callSteward(target, () => clientFor(ctx, target).admin.invoices.list(filter));
|
|
1998
2223
|
if (values.json) out.out(JSON.stringify(items, null, 2));
|
|
1999
|
-
else if (
|
|
2224
|
+
else if (values.csv) {
|
|
2225
|
+
out.out(INVOICE_EXPORT_COLUMNS.join(","));
|
|
2226
|
+
for (const invoice of items) out.out(invoiceExportRow(invoice).map(csvCell$1).join(","));
|
|
2227
|
+
} else if (items.length === 0) out.out(`no ${status ?? ""} invoices`.replace(" ", " "));
|
|
2000
2228
|
else {
|
|
2001
2229
|
const rows = [[
|
|
2002
2230
|
"CREATED",
|
|
@@ -2034,7 +2262,7 @@ async function invoicesCommand(ctx, out, args) {
|
|
|
2034
2262
|
},
|
|
2035
2263
|
json: { type: "boolean" }
|
|
2036
2264
|
}, "invoices");
|
|
2037
|
-
if (values.help) return help$
|
|
2265
|
+
if (values.help) return help$2(out);
|
|
2038
2266
|
expectPositionals(positionals, 1, 1, "invoices");
|
|
2039
2267
|
const id = positionals[0];
|
|
2040
2268
|
const number = requireOption(values.number, "--number", "invoices").trim();
|
|
@@ -2068,6 +2296,93 @@ async function invoicesCommand(ctx, out, args) {
|
|
|
2068
2296
|
}
|
|
2069
2297
|
throw new UsageError(`unknown subcommand: invoices ${sub} (see: steward invoices --help)`);
|
|
2070
2298
|
}
|
|
2299
|
+
const INVOICE_EXPORT_COLUMNS = [
|
|
2300
|
+
"id",
|
|
2301
|
+
"number",
|
|
2302
|
+
"status",
|
|
2303
|
+
"createdAt",
|
|
2304
|
+
"issuedAt",
|
|
2305
|
+
"accountRef",
|
|
2306
|
+
"billingReason",
|
|
2307
|
+
"currency",
|
|
2308
|
+
"subtotalMinor",
|
|
2309
|
+
"taxMinor",
|
|
2310
|
+
"totalMinor",
|
|
2311
|
+
"taxRateBps",
|
|
2312
|
+
"taxTreatment",
|
|
2313
|
+
"taxReason",
|
|
2314
|
+
"taxCountry",
|
|
2315
|
+
"periodStart",
|
|
2316
|
+
"periodEnd",
|
|
2317
|
+
"paymentStatus",
|
|
2318
|
+
"paidAt",
|
|
2319
|
+
"paymentMethod",
|
|
2320
|
+
"paymentRef",
|
|
2321
|
+
"buyerKind",
|
|
2322
|
+
"buyerContactName",
|
|
2323
|
+
"buyerCompanyName",
|
|
2324
|
+
"buyerEmail",
|
|
2325
|
+
"buyerPhone",
|
|
2326
|
+
"buyerAddress",
|
|
2327
|
+
"buyerCity",
|
|
2328
|
+
"buyerPostalCode",
|
|
2329
|
+
"buyerRegion",
|
|
2330
|
+
"buyerCountry",
|
|
2331
|
+
"buyerTaxIdType",
|
|
2332
|
+
"buyerTaxId",
|
|
2333
|
+
"buyerTaxOffice",
|
|
2334
|
+
"lines"
|
|
2335
|
+
];
|
|
2336
|
+
function invoiceExportRow(invoice) {
|
|
2337
|
+
const buyer = invoice.buyer;
|
|
2338
|
+
const values = {
|
|
2339
|
+
id: invoice.id,
|
|
2340
|
+
number: invoice.number,
|
|
2341
|
+
status: invoice.status,
|
|
2342
|
+
createdAt: invoice.createdAt,
|
|
2343
|
+
issuedAt: invoice.issuedAt,
|
|
2344
|
+
accountRef: invoice.accountRef,
|
|
2345
|
+
billingReason: invoice.billingReason ?? null,
|
|
2346
|
+
currency: invoice.currency,
|
|
2347
|
+
subtotalMinor: invoice.subtotalMinor,
|
|
2348
|
+
taxMinor: invoice.taxMinor,
|
|
2349
|
+
totalMinor: invoice.totalMinor,
|
|
2350
|
+
taxRateBps: invoice.taxRateBps,
|
|
2351
|
+
taxTreatment: invoice.taxTreatment ?? null,
|
|
2352
|
+
taxReason: invoice.taxReason ?? null,
|
|
2353
|
+
taxCountry: invoice.taxCountry ?? null,
|
|
2354
|
+
periodStart: invoice.periodStart ?? null,
|
|
2355
|
+
periodEnd: invoice.periodEnd ?? null,
|
|
2356
|
+
paymentStatus: invoice.paymentStatus ?? null,
|
|
2357
|
+
paidAt: invoice.paidAt ?? null,
|
|
2358
|
+
paymentMethod: invoice.paymentMethod ?? null,
|
|
2359
|
+
paymentRef: invoice.paymentRef ?? null,
|
|
2360
|
+
buyerKind: buyer.kind,
|
|
2361
|
+
buyerContactName: buyer.contactName,
|
|
2362
|
+
buyerCompanyName: buyer.companyName ?? null,
|
|
2363
|
+
buyerEmail: buyer.email,
|
|
2364
|
+
buyerPhone: buyer.phone,
|
|
2365
|
+
buyerAddress: buyer.address,
|
|
2366
|
+
buyerCity: buyer.city,
|
|
2367
|
+
buyerPostalCode: buyer.postalCode ?? null,
|
|
2368
|
+
buyerRegion: buyer.region ?? null,
|
|
2369
|
+
buyerCountry: buyer.country,
|
|
2370
|
+
buyerTaxIdType: buyer.taxId !== void 0 ? taxIdTypeOf(buyer.country, buyer.taxIdType) : null,
|
|
2371
|
+
buyerTaxId: buyer.taxId ?? null,
|
|
2372
|
+
buyerTaxOffice: buyer.taxOffice ?? null,
|
|
2373
|
+
lines: JSON.stringify(invoice.lines.map((line) => ({
|
|
2374
|
+
description: line.description,
|
|
2375
|
+
quantity: line.quantity,
|
|
2376
|
+
unitAmountMinor: line.unitAmountMinor,
|
|
2377
|
+
amountMinor: line.amountMinor
|
|
2378
|
+
})))
|
|
2379
|
+
};
|
|
2380
|
+
return INVOICE_EXPORT_COLUMNS.map((column) => values[column]);
|
|
2381
|
+
}
|
|
2382
|
+
const csvCell$1 = (value) => {
|
|
2383
|
+
const cell = value === null ? "" : String(value);
|
|
2384
|
+
return /[",\n\r]/.test(cell) ? `"${cell.replace(/"/g, "\"\"")}"` : cell;
|
|
2385
|
+
};
|
|
2071
2386
|
/** Reads the PDF to attach; the same checks as steward's (PDF signature, at most 5 MB) before anything is sent. */
|
|
2072
2387
|
async function readDocument(ctx, file) {
|
|
2073
2388
|
let bytes;
|
|
@@ -2080,12 +2395,11 @@ async function readDocument(ctx, file) {
|
|
|
2080
2395
|
if (bytes.length > MAX_DOCUMENT_BYTES) throw new UsageError(`--document: ${file} is larger than 5 MB`);
|
|
2081
2396
|
return bytes;
|
|
2082
2397
|
}
|
|
2083
|
-
function help$
|
|
2398
|
+
function help$2(out) {
|
|
2084
2399
|
out.out(INVOICES_USAGE);
|
|
2085
2400
|
return 0;
|
|
2086
2401
|
}
|
|
2087
|
-
|
|
2088
|
-
//#region src/commands/keys.ts
|
|
2402
|
+
// src/commands/keys.ts
|
|
2089
2403
|
const KEYS_USAGE = `Usage:
|
|
2090
2404
|
steward keys list [--json]
|
|
2091
2405
|
steward keys create --name <name> --scope product|checkout|admin --out <file>
|
|
@@ -2123,7 +2437,7 @@ async function keysCommand(ctx, out, args) {
|
|
|
2123
2437
|
...HELP_OPTION,
|
|
2124
2438
|
json: { type: "boolean" }
|
|
2125
2439
|
}, "keys");
|
|
2126
|
-
if (values.help) return help(out);
|
|
2440
|
+
if (values.help) return help$1(out);
|
|
2127
2441
|
expectPositionals(positionals, 0, 0, "keys");
|
|
2128
2442
|
const target = requireAdminTarget(await resolveEnv(ctx));
|
|
2129
2443
|
out.err(connectionLine(target));
|
|
@@ -2161,7 +2475,7 @@ async function keysCommand(ctx, out, args) {
|
|
|
2161
2475
|
"no-expiry": { type: "boolean" },
|
|
2162
2476
|
force: { type: "boolean" }
|
|
2163
2477
|
}, "keys");
|
|
2164
|
-
if (values.help) return help(out);
|
|
2478
|
+
if (values.help) return help$1(out);
|
|
2165
2479
|
expectPositionals(positionals, 0, 0, "keys");
|
|
2166
2480
|
const name = requireOption(values.name, "--name", "keys");
|
|
2167
2481
|
const scope = requireOption(values.scope, "--scope", "keys");
|
|
@@ -2192,7 +2506,7 @@ async function keysCommand(ctx, out, args) {
|
|
|
2192
2506
|
}
|
|
2193
2507
|
if (sub === "revoke") {
|
|
2194
2508
|
const { values, positionals } = parse(rest, { ...HELP_OPTION }, "keys");
|
|
2195
|
-
if (values.help) return help(out);
|
|
2509
|
+
if (values.help) return help$1(out);
|
|
2196
2510
|
expectPositionals(positionals, 1, 1, "keys");
|
|
2197
2511
|
const target = requireAdminTarget(await resolveEnv(ctx));
|
|
2198
2512
|
out.err(connectionLine(target));
|
|
@@ -2202,12 +2516,11 @@ async function keysCommand(ctx, out, args) {
|
|
|
2202
2516
|
}
|
|
2203
2517
|
throw new UsageError(`unknown subcommand: keys ${sub} (see: steward keys --help)`);
|
|
2204
2518
|
}
|
|
2205
|
-
function help(out) {
|
|
2519
|
+
function help$1(out) {
|
|
2206
2520
|
out.out(KEYS_USAGE);
|
|
2207
2521
|
return 0;
|
|
2208
2522
|
}
|
|
2209
|
-
|
|
2210
|
-
//#region src/commands/reprice.ts
|
|
2523
|
+
// src/commands/reprice.ts
|
|
2211
2524
|
const REPRICE_USAGE = `Usage: steward reprice --plan <code> --notice-days <n> [--dry-run] [--yes] [--json]
|
|
2212
2525
|
|
|
2213
2526
|
Moves the live subscriptions of a plan to the plan's current price and metered rates
|
|
@@ -2295,19 +2608,24 @@ async function repriceCommand(ctx, out, args) {
|
|
|
2295
2608
|
else out.out(`scheduled → ${originOf(target.url)}: ${result.scheduled} subscription${result.scheduled === 1 ? "" : "s"} (one notice e-mail each)`);
|
|
2296
2609
|
return 0;
|
|
2297
2610
|
}
|
|
2298
|
-
|
|
2299
|
-
//#region src/commands/settings.ts
|
|
2611
|
+
// src/commands/settings.ts
|
|
2300
2612
|
const SETTINGS_USAGE = `Usage:
|
|
2301
2613
|
steward settings get
|
|
2302
2614
|
steward settings set [--app-url <url>] [--privacy-url <url>] [--terms-url <url>]
|
|
2303
|
-
[--branding <json>] [--default-locale tr|en]
|
|
2615
|
+
[--branding <json>] [--default-locale tr|en] [--display-time-zone <iana>]
|
|
2616
|
+
[--default-country <XX>]
|
|
2304
2617
|
[--checkout-ttl <minutes>] [--portal-ttl <minutes>]
|
|
2305
2618
|
[--extra-return-origins <a,b>] [--emails <json>]
|
|
2306
2619
|
[--billing-payment-due-days <1-60>] [--billing-min-invoice-minor <n>]
|
|
2307
2620
|
[--billing-allow-multiple-subscriptions true|false]
|
|
2621
|
+
[--billing-renewal-notice-intervals <year,month>] [--billing-renewal-notice-days <1-90>]
|
|
2622
|
+
[--billing-invoice-line-text iso|localized]
|
|
2308
2623
|
[--metering-charge-mode off|dry_run|live]
|
|
2309
2624
|
[--metering-late-grace-minutes <0-1440>] [--events-retention-days <45-400>]
|
|
2310
2625
|
[--provider <id>]
|
|
2626
|
+
[--tax-provider price|none] [--tax-exemption-reason-en <text>]
|
|
2627
|
+
[--tax-exemption-reason-tr <text>] [--consumer-markets <XX,YY>]
|
|
2628
|
+
[--seller <json>] [--withdrawal-waiver <json>] [--card-on-file <json>]
|
|
2311
2629
|
|
|
2312
2630
|
Product settings (GET/PATCH /v1/admin/settings). A field not given is unchanged; an
|
|
2313
2631
|
empty value (--privacy-url "") clears the field, --branding null clears the branding,
|
|
@@ -2321,15 +2639,41 @@ invoice to its due date (default 7), --billing-min-invoice-minor smallest amount
|
|
|
2321
2639
|
steward invoices on its own, in minor units (default 1000), and
|
|
2322
2640
|
--billing-allow-multiple-subscriptions (default false: a checkout for an account with
|
|
2323
2641
|
a live subscription is 409 already_subscribed; true: only a second subscription to the
|
|
2324
|
-
same plan is).
|
|
2642
|
+
same plan is). --billing-renewal-notice-intervals lists the plan intervals that get the
|
|
2643
|
+
renewal notice e-mail (e.g. year; default none: no notice) and --billing-renewal-notice-days
|
|
2644
|
+
how many days before the renewal it is sent (default 30). --billing-invoice-line-text decides
|
|
2645
|
+
how new invoice lines are written: iso (default) ISO dates and the product's default language,
|
|
2646
|
+
localized the buyer's language with dates written in it. An empty value ("") restores the
|
|
2647
|
+
field's default.
|
|
2325
2648
|
Metering (settings.metering, settings.events): --metering-charge-mode prices overage
|
|
2326
2649
|
at the end of a usage period: dry_run (default) records the charge without invoicing
|
|
2327
2650
|
it, live adds it to the renewal invoice, off prices nothing — run one full cycle in
|
|
2328
2651
|
dry_run before live. --metering-late-grace-minutes how long a period waits for late
|
|
2329
2652
|
events before it closes (default 60). --events-retention-days how long raw events are
|
|
2330
2653
|
kept after receipt, once their period is closed (default 120). "" restores the default.
|
|
2654
|
+
--default-locale is the language of hosted pages and emails when the call, the session and
|
|
2655
|
+
the account name none steward supports. --display-time-zone is the IANA zone customer-facing
|
|
2656
|
+
dates are shown in (default Europe/Istanbul; a time of day names the zone); "" restores it.
|
|
2657
|
+
--default-country is the ISO country code (e.g. TR, DE, US) the hosted checkout and portal
|
|
2658
|
+
forms start on when the buyer has no stored profile (default TR); "" restores the default.
|
|
2331
2659
|
--provider sets the payment provider for NEW checkouts and payment sessions (open ones keep
|
|
2332
2660
|
theirs); steward accepts only a provider configured in its deployment (iyzico, fake…).
|
|
2661
|
+
Tax (settings.tax): --tax-provider decides the tax of invoices written from now on: price
|
|
2662
|
+
(default) the price's own rate; none no tax charged, every invoice exempt with the exemption
|
|
2663
|
+
wording (while the seller is under its thresholds; see steward tax --help).
|
|
2664
|
+
--tax-exemption-reason-en / -tr is that wording per language (the seller's legal wording; doctor
|
|
2665
|
+
warns while the provider is none and it is unset). --consumer-markets lists the countries open
|
|
2666
|
+
to individual buyers (e.g. AT,BE,…,US): a consumer elsewhere is refused at checkout, a business
|
|
2667
|
+
buyer never; "" opens every country (the default). "" restores a field's default.
|
|
2668
|
+
Legal (settings.legal; the texts are the seller's own, steward ships none; each is replaced as a
|
|
2669
|
+
whole, "" or null removes it): --seller is the seller's identity shown in the footer of hosted
|
|
2670
|
+
pages and e-mails, '{"legalName":"Acme Ltd","address":"1 Example Street, Example City",
|
|
2671
|
+
"taxId":"XX123456789","registrationNumber":"12345678"}'.
|
|
2672
|
+
--withdrawal-waiver is the checkbox consumers tick at checkout to waive the right of withdrawal,
|
|
2673
|
+
'{"version":"2026-10","text":{"en":"…"},"url":"https://…","countries":["DE","FR"]}' (countries
|
|
2674
|
+
empty or left out: every consumer). --card-on-file is the checkbox a card payer ticks when the
|
|
2675
|
+
card is saved for renewals (Stripe), '{"version":"2026-10","text":{"en":"…"}}'. Each acceptance
|
|
2676
|
+
is recorded with the version.
|
|
2333
2677
|
|
|
2334
2678
|
Connection: STEWARD_ADMIN_URL + STEWARD_ADMIN_API_KEY (environment, otherwise ./.env.local).`;
|
|
2335
2679
|
const SET_OPTIONS = {
|
|
@@ -2339,6 +2683,8 @@ const SET_OPTIONS = {
|
|
|
2339
2683
|
"terms-url": { type: "string" },
|
|
2340
2684
|
branding: { type: "string" },
|
|
2341
2685
|
"default-locale": { type: "string" },
|
|
2686
|
+
"display-time-zone": { type: "string" },
|
|
2687
|
+
"default-country": { type: "string" },
|
|
2342
2688
|
"checkout-ttl": { type: "string" },
|
|
2343
2689
|
"portal-ttl": { type: "string" },
|
|
2344
2690
|
"extra-return-origins": { type: "string" },
|
|
@@ -2346,12 +2692,35 @@ const SET_OPTIONS = {
|
|
|
2346
2692
|
"billing-payment-due-days": { type: "string" },
|
|
2347
2693
|
"billing-min-invoice-minor": { type: "string" },
|
|
2348
2694
|
"billing-allow-multiple-subscriptions": { type: "string" },
|
|
2695
|
+
"billing-renewal-notice-intervals": { type: "string" },
|
|
2696
|
+
"billing-renewal-notice-days": { type: "string" },
|
|
2697
|
+
"billing-invoice-line-text": { type: "string" },
|
|
2349
2698
|
"metering-charge-mode": { type: "string" },
|
|
2350
2699
|
"metering-late-grace-minutes": { type: "string" },
|
|
2351
2700
|
"events-retention-days": { type: "string" },
|
|
2352
|
-
provider: { type: "string" }
|
|
2701
|
+
provider: { type: "string" },
|
|
2702
|
+
"tax-provider": { type: "string" },
|
|
2703
|
+
"tax-exemption-reason-en": { type: "string" },
|
|
2704
|
+
"tax-exemption-reason-tr": { type: "string" },
|
|
2705
|
+
"consumer-markets": { type: "string" },
|
|
2706
|
+
seller: { type: "string" },
|
|
2707
|
+
"withdrawal-waiver": { type: "string" },
|
|
2708
|
+
"card-on-file": { type: "string" }
|
|
2353
2709
|
};
|
|
2354
2710
|
const orNull = (value) => value.trim() === "" ? null : value.trim();
|
|
2711
|
+
/** A JSON object flag; "" or null → null (clear). */
|
|
2712
|
+
function jsonObjectOrNull(value, flag) {
|
|
2713
|
+
const text = value.trim();
|
|
2714
|
+
if (text === "" || text === "null") return null;
|
|
2715
|
+
let parsed;
|
|
2716
|
+
try {
|
|
2717
|
+
parsed = JSON.parse(text);
|
|
2718
|
+
} catch {
|
|
2719
|
+
throw new UsageError(`--${flag}: must be a JSON object (see steward settings --help)`);
|
|
2720
|
+
}
|
|
2721
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) throw new UsageError(`--${flag}: must be a JSON object`);
|
|
2722
|
+
return parsed;
|
|
2723
|
+
}
|
|
2355
2724
|
/** A patch from the flags; validated with the contract schema (if invalid no request is sent). */
|
|
2356
2725
|
function buildSettingsPatch(values) {
|
|
2357
2726
|
const patch = {};
|
|
@@ -2387,6 +2756,8 @@ function buildSettingsPatch(values) {
|
|
|
2387
2756
|
}
|
|
2388
2757
|
}
|
|
2389
2758
|
if (values["default-locale"] !== void 0) patch.defaultLocale = values["default-locale"].trim();
|
|
2759
|
+
if (values["display-time-zone"] !== void 0) patch.displayTimeZone = orNull(values["display-time-zone"]);
|
|
2760
|
+
if (values["default-country"] !== void 0) patch.defaultCountry = orNull(values["default-country"])?.toUpperCase() ?? null;
|
|
2390
2761
|
if (values.provider !== void 0) patch.provider = values.provider.trim();
|
|
2391
2762
|
if (values["checkout-ttl"] !== void 0) patch.checkoutTtlMinutes = parsePositiveInt(values["checkout-ttl"], "--checkout-ttl");
|
|
2392
2763
|
if (values["portal-ttl"] !== void 0) patch.portalTtlMinutes = parsePositiveInt(values["portal-ttl"], "--portal-ttl");
|
|
@@ -2398,6 +2769,18 @@ function buildSettingsPatch(values) {
|
|
|
2398
2769
|
if (minInvoice !== void 0) billing.minInvoiceMinor = minInvoice.trim() === "" ? null : parseNonNegativeInt(minInvoice, "--billing-min-invoice-minor");
|
|
2399
2770
|
const multiple = values["billing-allow-multiple-subscriptions"];
|
|
2400
2771
|
if (multiple !== void 0) billing.allowMultipleSubscriptions = multiple.trim() === "" ? null : parseBoolean(multiple, "--billing-allow-multiple-subscriptions");
|
|
2772
|
+
const renewalNotice = {};
|
|
2773
|
+
const noticeIntervals = values["billing-renewal-notice-intervals"];
|
|
2774
|
+
if (noticeIntervals !== void 0) renewalNotice.intervals = noticeIntervals.trim() === "" ? null : parseList(noticeIntervals);
|
|
2775
|
+
const noticeDays = values["billing-renewal-notice-days"];
|
|
2776
|
+
if (noticeDays !== void 0) renewalNotice.daysBefore = noticeDays.trim() === "" ? null : parsePositiveInt(noticeDays, "--billing-renewal-notice-days", { max: 90 });
|
|
2777
|
+
if (Object.keys(renewalNotice).length > 0) billing.renewalNotice = renewalNotice;
|
|
2778
|
+
const lineText = values["billing-invoice-line-text"];
|
|
2779
|
+
if (lineText !== void 0) {
|
|
2780
|
+
const style = lineText.trim();
|
|
2781
|
+
if (style !== "" && !INVOICE_LINE_TEXTS.includes(style)) throw new UsageError(`--billing-invoice-line-text: one of ${INVOICE_LINE_TEXTS.join(", ")}`);
|
|
2782
|
+
billing.invoiceLineText = style === "" ? null : style;
|
|
2783
|
+
}
|
|
2401
2784
|
if (Object.keys(billing).length > 0) patch.billing = billing;
|
|
2402
2785
|
const metering = {};
|
|
2403
2786
|
const chargeMode = values["metering-charge-mode"];
|
|
@@ -2411,6 +2794,27 @@ function buildSettingsPatch(values) {
|
|
|
2411
2794
|
if (Object.keys(metering).length > 0) patch.metering = metering;
|
|
2412
2795
|
const retention = values["events-retention-days"];
|
|
2413
2796
|
if (retention !== void 0) patch.events = { retentionDays: retention.trim() === "" ? null : parsePositiveInt(retention, "--events-retention-days", { max: 400 }) };
|
|
2797
|
+
const tax = {};
|
|
2798
|
+
const taxProvider = values["tax-provider"];
|
|
2799
|
+
if (taxProvider !== void 0) {
|
|
2800
|
+
const id = taxProvider.trim();
|
|
2801
|
+
if (id !== "" && !TAX_PROVIDERS.includes(id)) throw new UsageError(`--tax-provider: one of ${TAX_PROVIDERS.join(", ")}`);
|
|
2802
|
+
tax.provider = id === "" ? null : id;
|
|
2803
|
+
}
|
|
2804
|
+
const reasons = {};
|
|
2805
|
+
for (const locale of ["en", "tr"]) {
|
|
2806
|
+
const reason = values[`tax-exemption-reason-${locale}`];
|
|
2807
|
+
if (reason !== void 0) reasons[locale] = orNull(reason);
|
|
2808
|
+
}
|
|
2809
|
+
if (Object.keys(reasons).length > 0) tax.exemptionReason = reasons;
|
|
2810
|
+
const markets = values["consumer-markets"];
|
|
2811
|
+
if (markets !== void 0) tax.consumerMarkets = markets.trim() === "" ? null : parseList(markets).map((country) => country.toUpperCase());
|
|
2812
|
+
if (Object.keys(tax).length > 0) patch.tax = tax;
|
|
2813
|
+
const legal = {};
|
|
2814
|
+
if (values.seller !== void 0) legal.seller = jsonObjectOrNull(values.seller, "seller");
|
|
2815
|
+
if (values["withdrawal-waiver"] !== void 0) legal.withdrawalWaiver = jsonObjectOrNull(values["withdrawal-waiver"], "withdrawal-waiver");
|
|
2816
|
+
if (values["card-on-file"] !== void 0) legal.cardOnFile = jsonObjectOrNull(values["card-on-file"], "card-on-file");
|
|
2817
|
+
if (Object.keys(legal).length > 0) patch.legal = legal;
|
|
2414
2818
|
if (Object.keys(patch).length === 0) throw new UsageError(`at least one settings flag is required (details: steward settings --help)`);
|
|
2415
2819
|
const parsed = ProductSettingsPatchSchema.safeParse(patch);
|
|
2416
2820
|
if (!parsed.success) throw new UsageError(`invalid settings (no request was sent)\n${parsed.error.issues.map((issue) => ` - ${issue.path.map(String).join(".") || "(root)"}: ${issue.message}`).join("\n")}`);
|
|
@@ -2454,9 +2858,244 @@ async function settingsCommand(ctx, out, args) {
|
|
|
2454
2858
|
}
|
|
2455
2859
|
throw new UsageError(`unknown subcommand: settings ${sub} (details: steward settings --help)`);
|
|
2456
2860
|
}
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2861
|
+
// src/commands/tax.ts
|
|
2862
|
+
const TAX_USAGE = `Usage:
|
|
2863
|
+
steward tax thresholds list [--json]
|
|
2864
|
+
steward tax thresholds set <code> --scope <scope> --currency <XXX>
|
|
2865
|
+
[--amount-minor <n>] [--transactions <n>]
|
|
2866
|
+
[--country <XX>] [--region <XX>] [--home-country <XX>]
|
|
2867
|
+
[--period calendar_year|rolling_12_months] [--warn-at-bps <1-10000>]
|
|
2868
|
+
[--fx-rate <XXX>=<rate> ...] [--note <text>]
|
|
2869
|
+
steward tax thresholds delete <code>
|
|
2870
|
+
steward tax sales [--from <iso>] [--to <iso>] [--json | --csv]
|
|
2871
|
+
|
|
2872
|
+
Tax registration thresholds and the sales they count (/v1/admin/tax/thresholds,
|
|
2873
|
+
/v1/admin/sales). Steward ships with no threshold: the seller's tax adviser decides which apply,
|
|
2874
|
+
how much and how they are counted; enter each with "set".
|
|
2875
|
+
|
|
2876
|
+
Scopes (--scope): company_turnover (every paid sale), eu_cross_border_consumer (individual
|
|
2877
|
+
buyers in an EU member state other than --home-country, the seller's), country (buyers in
|
|
2878
|
+
--country), us_state (buyers in the US state --region, e.g. CA). A threshold has an amount
|
|
2879
|
+
(--amount-minor, minor units of --currency), a number of sales (--transactions) or both; it
|
|
2880
|
+
counts its --period (default calendar_year, UTC) and warns at --warn-at-bps of its limit
|
|
2881
|
+
(default 8000 = 80%). Sales in another currency count at --fx-rate (units of --currency per 1
|
|
2882
|
+
unit of the sale's, e.g. --fx-rate USD=0.92 --fx-rate GBP=1.17); without a rate they are not
|
|
2883
|
+
counted and doctor warns. "set" replaces the whole threshold; every change is audited.
|
|
2884
|
+
|
|
2885
|
+
A sale is a payment steward collected, by its date, attributed to the buyer's declared country
|
|
2886
|
+
and region on the invoice it paid, net of refunds.
|
|
2887
|
+
|
|
2888
|
+
sales: paid sales per UTC month, buyer country, region, buyer kind, currency and tax treatment,
|
|
2889
|
+
with counts and totals (the threshold evidence). --from inclusive, --to exclusive (ISO-8601 with
|
|
2890
|
+
an offset); default: this calendar year up to now; at most ${SALES_REPORT_MAX_MONTHS} months.
|
|
2891
|
+
|
|
2892
|
+
Connection: STEWARD_ADMIN_URL + STEWARD_ADMIN_API_KEY (environment, otherwise ./.env.local).`;
|
|
2893
|
+
const percent = (bps) => bps === null ? "-" : `${(bps / 100).toFixed(2)}%`;
|
|
2894
|
+
function scopeText(t) {
|
|
2895
|
+
switch (t.scope) {
|
|
2896
|
+
case "country": return `country ${t.country}`;
|
|
2897
|
+
case "us_state": return `us_state ${t.region}`;
|
|
2898
|
+
case "eu_cross_border_consumer": return `eu_cross_border_consumer (home ${t.homeCountry})`;
|
|
2899
|
+
default: return t.scope;
|
|
2900
|
+
}
|
|
2901
|
+
}
|
|
2902
|
+
function limitText(t) {
|
|
2903
|
+
return [t.amountMinor !== null ? `${t.amountMinor} ${t.currency}` : null, t.transactions !== null ? `${t.transactions} sales` : null].filter((part) => part !== null).join(" / ");
|
|
2904
|
+
}
|
|
2905
|
+
/** `USD=0.92` flags → the rates map (the contract checks each rate). */
|
|
2906
|
+
function parseFxRates(values) {
|
|
2907
|
+
const rates = {};
|
|
2908
|
+
for (const value of values ?? []) {
|
|
2909
|
+
const match = /^([A-Za-z]{3})=(.+)$/.exec(value.trim());
|
|
2910
|
+
if (!match) throw new UsageError("--fx-rate: <currency>=<rate>, e.g. USD=0.92");
|
|
2911
|
+
rates[match[1].toUpperCase()] = match[2].trim();
|
|
2912
|
+
}
|
|
2913
|
+
return rates;
|
|
2914
|
+
}
|
|
2915
|
+
/** The threshold from the flags; validated with the contract schema (if invalid no request is sent). */
|
|
2916
|
+
function buildThresholdInput(values) {
|
|
2917
|
+
const text = (name) => typeof values[name] === "string" ? values[name].trim() : void 0;
|
|
2918
|
+
const input = {
|
|
2919
|
+
scope: text("scope"),
|
|
2920
|
+
currency: text("currency")?.toUpperCase(),
|
|
2921
|
+
fxRates: parseFxRates(values["fx-rate"])
|
|
2922
|
+
};
|
|
2923
|
+
const amount = text("amount-minor");
|
|
2924
|
+
if (amount !== void 0) input.amountMinor = parsePositiveInt(amount, "--amount-minor");
|
|
2925
|
+
const transactions = text("transactions");
|
|
2926
|
+
if (transactions !== void 0) input.transactions = parsePositiveInt(transactions, "--transactions");
|
|
2927
|
+
if (text("country") !== void 0) input.country = text("country").toUpperCase();
|
|
2928
|
+
if (text("region") !== void 0) input.region = text("region").toUpperCase();
|
|
2929
|
+
if (text("home-country") !== void 0) input.homeCountry = text("home-country").toUpperCase();
|
|
2930
|
+
if (text("period") !== void 0) input.period = text("period");
|
|
2931
|
+
const warnAt = text("warn-at-bps");
|
|
2932
|
+
if (warnAt !== void 0) input.warnAtBps = parsePositiveInt(warnAt, "--warn-at-bps", { max: 1e4 });
|
|
2933
|
+
if (text("note") !== void 0) input.note = text("note");
|
|
2934
|
+
const parsed = TaxThresholdInputSchema.safeParse(input);
|
|
2935
|
+
if (!parsed.success) throw new UsageError(`invalid threshold (no request was sent)\n${parsed.error.issues.map((issue) => ` - ${issue.path.map(String).join(".") || "(root)"}: ${issue.message}`).join("\n")}\nscopes: ${TAX_THRESHOLD_SCOPES.join(", ")}; periods: ${TAX_THRESHOLD_PERIODS.join(", ")}`);
|
|
2936
|
+
return input;
|
|
2937
|
+
}
|
|
2938
|
+
const csvCell = (value) => {
|
|
2939
|
+
const cell = value === null ? "" : String(value);
|
|
2940
|
+
return /[",\n]/.test(cell) ? `"${cell.replace(/"/g, "\"\"")}"` : cell;
|
|
2941
|
+
};
|
|
2942
|
+
const SALES_COLUMNS = [
|
|
2943
|
+
"month",
|
|
2944
|
+
"country",
|
|
2945
|
+
"region",
|
|
2946
|
+
"buyerKind",
|
|
2947
|
+
"currency",
|
|
2948
|
+
"taxTreatment",
|
|
2949
|
+
"sales",
|
|
2950
|
+
"amountMinor",
|
|
2951
|
+
"taxMinor",
|
|
2952
|
+
"refundedMinor"
|
|
2953
|
+
];
|
|
2954
|
+
function salesRow(item) {
|
|
2955
|
+
return SALES_COLUMNS.map((column) => item[column]);
|
|
2956
|
+
}
|
|
2957
|
+
async function taxCommand(ctx, out, args) {
|
|
2958
|
+
const [sub, ...rest] = args;
|
|
2959
|
+
if (sub === void 0 || sub === "--help" || sub === "-h" || sub === "help") {
|
|
2960
|
+
out.out(TAX_USAGE);
|
|
2961
|
+
return sub === void 0 ? 2 : 0;
|
|
2962
|
+
}
|
|
2963
|
+
if (sub === "thresholds") {
|
|
2964
|
+
const [action, ...more] = rest;
|
|
2965
|
+
if (action === "list") {
|
|
2966
|
+
const { values, positionals } = parse(more, {
|
|
2967
|
+
...HELP_OPTION,
|
|
2968
|
+
json: { type: "boolean" }
|
|
2969
|
+
}, "tax");
|
|
2970
|
+
if (values.help) return help(out);
|
|
2971
|
+
expectPositionals(positionals, 0, 0, "tax");
|
|
2972
|
+
const target = requireAdminTarget(await resolveEnv(ctx));
|
|
2973
|
+
out.err(connectionLine(target));
|
|
2974
|
+
const { items } = await callSteward(target, () => clientFor(ctx, target).admin.tax.thresholds.list());
|
|
2975
|
+
if (values.json) out.out(JSON.stringify(items, null, 2));
|
|
2976
|
+
else if (items.length === 0) out.out("no tax thresholds (enter the ones that apply: steward tax thresholds set --help)");
|
|
2977
|
+
else {
|
|
2978
|
+
const rows = [[
|
|
2979
|
+
"CODE",
|
|
2980
|
+
"SCOPE",
|
|
2981
|
+
"LIMIT",
|
|
2982
|
+
"PERIOD",
|
|
2983
|
+
"COUNTED",
|
|
2984
|
+
"AMOUNT",
|
|
2985
|
+
"SALES",
|
|
2986
|
+
"STATUS"
|
|
2987
|
+
]];
|
|
2988
|
+
for (const t of items) rows.push([
|
|
2989
|
+
t.code,
|
|
2990
|
+
scopeText(t),
|
|
2991
|
+
limitText(t),
|
|
2992
|
+
`${t.usage.from.slice(0, 10)} – ${t.usage.to.slice(0, 10)}`,
|
|
2993
|
+
`${t.usage.amountMinor} ${t.currency} / ${t.usage.transactions} sales`,
|
|
2994
|
+
percent(t.usage.amountShareBps),
|
|
2995
|
+
percent(t.usage.transactionShareBps),
|
|
2996
|
+
t.usage.status
|
|
2997
|
+
]);
|
|
2998
|
+
for (const line of table(rows)) out.out(line);
|
|
2999
|
+
for (const t of items) for (const u of t.usage.unconverted) out.err(`${t.code}: ${u.transactions} sale(s) in ${u.currency} (${u.amountMinor}) not counted: no --fx-rate ${u.currency}=…`);
|
|
3000
|
+
}
|
|
3001
|
+
return 0;
|
|
3002
|
+
}
|
|
3003
|
+
if (action === "set") {
|
|
3004
|
+
const { values, positionals } = parse(more, {
|
|
3005
|
+
...HELP_OPTION,
|
|
3006
|
+
scope: { type: "string" },
|
|
3007
|
+
currency: { type: "string" },
|
|
3008
|
+
"amount-minor": { type: "string" },
|
|
3009
|
+
transactions: { type: "string" },
|
|
3010
|
+
country: { type: "string" },
|
|
3011
|
+
region: { type: "string" },
|
|
3012
|
+
"home-country": { type: "string" },
|
|
3013
|
+
period: { type: "string" },
|
|
3014
|
+
"warn-at-bps": { type: "string" },
|
|
3015
|
+
"fx-rate": {
|
|
3016
|
+
type: "string",
|
|
3017
|
+
multiple: true
|
|
3018
|
+
},
|
|
3019
|
+
note: { type: "string" }
|
|
3020
|
+
}, "tax");
|
|
3021
|
+
if (values.help) return help(out);
|
|
3022
|
+
expectPositionals(positionals, 1, 1, "tax");
|
|
3023
|
+
const code = positionals[0];
|
|
3024
|
+
if (!CodeSchema.safeParse(code).success) throw new UsageError("<code>: lowercase letters, digits and _ (e.g. small_business)");
|
|
3025
|
+
const input = buildThresholdInput(values);
|
|
3026
|
+
const target = requireAdminTarget(await resolveEnv(ctx));
|
|
3027
|
+
out.err(connectionLine(target));
|
|
3028
|
+
const stored = await callSteward(target, () => clientFor(ctx, target).admin.tax.thresholds.set(code, input));
|
|
3029
|
+
out.err(`threshold ${code} stored → ${originOf(target.url)}`);
|
|
3030
|
+
out.out(JSON.stringify(stored, null, 2));
|
|
3031
|
+
return 0;
|
|
3032
|
+
}
|
|
3033
|
+
if (action === "delete") {
|
|
3034
|
+
const { values, positionals } = parse(more, { ...HELP_OPTION }, "tax");
|
|
3035
|
+
if (values.help) return help(out);
|
|
3036
|
+
expectPositionals(positionals, 1, 1, "tax");
|
|
3037
|
+
const code = positionals[0];
|
|
3038
|
+
if (!CodeSchema.safeParse(code).success) throw new UsageError("<code>: lowercase letters, digits and _");
|
|
3039
|
+
const target = requireAdminTarget(await resolveEnv(ctx));
|
|
3040
|
+
out.err(connectionLine(target));
|
|
3041
|
+
await callSteward(target, () => clientFor(ctx, target).admin.tax.thresholds.delete(code));
|
|
3042
|
+
out.out(`threshold ${code} deleted → ${originOf(target.url)}`);
|
|
3043
|
+
return 0;
|
|
3044
|
+
}
|
|
3045
|
+
throw new UsageError(`unknown subcommand: tax thresholds${action !== void 0 ? ` ${action}` : ""} (see: steward tax --help)`);
|
|
3046
|
+
}
|
|
3047
|
+
if (sub === "sales") {
|
|
3048
|
+
const { values, positionals } = parse(rest, {
|
|
3049
|
+
...HELP_OPTION,
|
|
3050
|
+
from: { type: "string" },
|
|
3051
|
+
to: { type: "string" },
|
|
3052
|
+
json: { type: "boolean" },
|
|
3053
|
+
csv: { type: "boolean" }
|
|
3054
|
+
}, "tax");
|
|
3055
|
+
if (values.help) return help(out);
|
|
3056
|
+
expectPositionals(positionals, 0, 0, "tax");
|
|
3057
|
+
if (values.json && values.csv) throw new UsageError("--json and --csv: choose one");
|
|
3058
|
+
if (values.from !== void 0 && !DateTimeSchema.safeParse(values.from).success) throw new UsageError("--from: ISO-8601 with an offset, e.g. 2026-01-01T00:00:00Z");
|
|
3059
|
+
if (values.to !== void 0 && !DateTimeSchema.safeParse(values.to).success) throw new UsageError("--to: ISO-8601 with an offset, e.g. 2026-01-01T00:00:00Z");
|
|
3060
|
+
const range = {
|
|
3061
|
+
...values.from !== void 0 ? { from: values.from } : {},
|
|
3062
|
+
...values.to !== void 0 ? { to: values.to } : {}
|
|
3063
|
+
};
|
|
3064
|
+
const target = requireAdminTarget(await resolveEnv(ctx));
|
|
3065
|
+
out.err(connectionLine(target));
|
|
3066
|
+
const report = await callSteward(target, () => clientFor(ctx, target).admin.tax.sales(range));
|
|
3067
|
+
out.err(`sales ${report.from} – ${report.to}`);
|
|
3068
|
+
if (values.json) out.out(JSON.stringify(report, null, 2));
|
|
3069
|
+
else if (values.csv) {
|
|
3070
|
+
out.out(SALES_COLUMNS.join(","));
|
|
3071
|
+
for (const item of report.items) out.out(salesRow(item).map(csvCell).join(","));
|
|
3072
|
+
} else if (report.items.length === 0) out.out("no paid sales in the period");
|
|
3073
|
+
else {
|
|
3074
|
+
const rows = [[
|
|
3075
|
+
"MONTH",
|
|
3076
|
+
"COUNTRY",
|
|
3077
|
+
"REGION",
|
|
3078
|
+
"KIND",
|
|
3079
|
+
"CURRENCY",
|
|
3080
|
+
"TREATMENT",
|
|
3081
|
+
"SALES",
|
|
3082
|
+
"AMOUNT",
|
|
3083
|
+
"TAX",
|
|
3084
|
+
"REFUNDED"
|
|
3085
|
+
]];
|
|
3086
|
+
for (const item of report.items) rows.push(salesRow(item).map((cell) => cell === null ? "-" : String(cell)));
|
|
3087
|
+
for (const line of table(rows)) out.out(line);
|
|
3088
|
+
}
|
|
3089
|
+
return 0;
|
|
3090
|
+
}
|
|
3091
|
+
throw new UsageError(`unknown subcommand: tax ${sub} (see: steward tax --help)`);
|
|
3092
|
+
}
|
|
3093
|
+
function help(out) {
|
|
3094
|
+
out.out(TAX_USAGE);
|
|
3095
|
+
return 0;
|
|
3096
|
+
}
|
|
3097
|
+
// src/main.ts
|
|
3098
|
+
const CLI_VERSION = "0.12.0";
|
|
2460
3099
|
const USAGE = `steward — Steward CLI (@stewardhq/cli ${CLI_VERSION})
|
|
2461
3100
|
|
|
2462
3101
|
Usage: steward <command> [options]
|
|
@@ -2466,15 +3105,19 @@ Commands:
|
|
|
2466
3105
|
catalog push <file> [--yes] catalog sync (PUT /v1/admin/catalog)
|
|
2467
3106
|
settings get | set [flags] product settings (/v1/admin/settings)
|
|
2468
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
|
|
2469
3109
|
keys list | create | revoke API keys; the key goes only to the --out file
|
|
2470
3110
|
dunning get | set <policy.json> dunning policy (/v1/admin/dunning-policy)
|
|
2471
3111
|
reprice --plan <code> --notice-days <n> move a plan's subscribers to its current price
|
|
2472
3112
|
bank-transfers list | record | fx-report bank transfer reconciliation (/v1/admin/bank-transfers)
|
|
2473
3113
|
invoices list | issue invoices not issued yet; write the external invoice number
|
|
3114
|
+
grants list active grants; --subscription none: paying for nothing
|
|
2474
3115
|
credits adjust <ref> <meter> --units=<n> credit entry, negative = adjustment
|
|
2475
3116
|
accounts get | metadata set | unset read an account; set or remove metadata keys
|
|
2476
3117
|
meters get | recompute | close-periods an account's meters; metering repairs (admin)
|
|
2477
3118
|
events send | redeliver send one event; redeliver webhook events (admin)
|
|
3119
|
+
tax thresholds list | set | delete tax registration thresholds and their counters
|
|
3120
|
+
tax sales [--from] [--to] [--csv] paid sales per month and buyer country (admin)
|
|
2478
3121
|
|
|
2479
3122
|
Connection: admin commands use STEWARD_ADMIN_URL + STEWARD_ADMIN_API_KEY; doctor,
|
|
2480
3123
|
accounts, meters and events use STEWARD_URL + STEWARD_API_KEY (or the admin pair). If even
|
|
@@ -2489,6 +3132,7 @@ const COMMANDS = {
|
|
|
2489
3132
|
catalog: catalogCommand,
|
|
2490
3133
|
settings: settingsCommand,
|
|
2491
3134
|
endpoints: endpointsCommand,
|
|
3135
|
+
"email-smtp": emailSmtpCommand,
|
|
2492
3136
|
accounts: accountsCommand,
|
|
2493
3137
|
meters: metersCommand,
|
|
2494
3138
|
events: eventsCommand,
|
|
@@ -2497,7 +3141,9 @@ const COMMANDS = {
|
|
|
2497
3141
|
reprice: repriceCommand,
|
|
2498
3142
|
"bank-transfers": bankTransfersCommand,
|
|
2499
3143
|
invoices: invoicesCommand,
|
|
2500
|
-
|
|
3144
|
+
grants: grantsCommand,
|
|
3145
|
+
credits: creditsCommand,
|
|
3146
|
+
tax: taxCommand
|
|
2501
3147
|
};
|
|
2502
3148
|
async function main(argv, ctx) {
|
|
2503
3149
|
const out = createOutput(ctx.stdout, ctx.stderr);
|
|
@@ -2534,8 +3180,7 @@ async function main(argv, ctx) {
|
|
|
2534
3180
|
return 1;
|
|
2535
3181
|
}
|
|
2536
3182
|
}
|
|
2537
|
-
|
|
2538
|
-
//#region src/bin.ts
|
|
3183
|
+
// src/bin.ts
|
|
2539
3184
|
const ctx = {
|
|
2540
3185
|
cwd: process.cwd(),
|
|
2541
3186
|
env: process.env,
|
|
@@ -2563,8 +3208,13 @@ const ctx = {
|
|
|
2563
3208
|
} finally {
|
|
2564
3209
|
terminal.close();
|
|
2565
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");
|
|
2566
3217
|
}
|
|
2567
3218
|
};
|
|
2568
3219
|
process.exitCode = await main(process.argv.slice(2), ctx);
|
|
2569
|
-
//#endregion
|
|
2570
3220
|
export {};
|