@stewardhq/cli 0.13.0 → 0.15.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 +21 -6
- package/dist/bin.js +753 -391
- package/package.json +5 -5
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, DiscountCreateInputSchema, DiscountUpdateInputSchema, DunningPolicySchema, EmailSmtpVerifyInputSchema, EventsIngestInputSchema, FxRateSchema, GRANT_LIST_DEFAULT_LIMIT, GRANT_LIST_MAX_LIMIT, GrantListSubscriptionFilterSchema, INVOICE_LINE_TEXTS, IdSchema, InvoiceIssueInputSchema, InvoicePaymentStatusSchema, InvoiceStatusSchema, METER_CHARGE_MODES,
|
|
5
|
+
import { ACCOUNT_INCLUDES, ACCOUNT_LIST_QUERY_MAX, ADMIN_LIST_DEFAULT_LIMIT, ADMIN_LIST_MAX_LIMIT, AUDIT_LIST_FILTER_MAX, AccountListDeletedFilterSchema, AccountMetadataPatchInputSchema, ApiKeyCreateInputSchema, ApiKeyPrefixSchema, BankTransferRecordInputSchema, CatalogSyncInputSchema, CodeSchema, CreditAdjustmentInputSchema, DateTimeSchema, DiscountCreateInputSchema, DiscountUpdateInputSchema, DunningPolicySchema, EmailMessageStatusSchema, EmailSmtpVerifyInputSchema, EmailTemplateSchema, EventIdSchema, EventsIngestInputSchema, ExternalRefSchema, FxRateSchema, GRANT_LIST_DEFAULT_LIMIT, GRANT_LIST_MAX_LIMIT, GrantListSubscriptionFilterSchema, INVOICE_LINE_TEXTS, IdSchema, InvoiceIssueInputSchema, InvoicePaymentStatusSchema, InvoiceStatusSchema, METER_CHARGE_MODES, PaymentListDisputedFilterSchema, PaymentMethodSchema, ProductSettingsPatchSchema, RepriceInputSchema, SALES_REPORT_MAX_MONTHS, SmtpUrlSchema, StewardApiError, StewardConfigError, StewardError, StewardNetworkError, SubscriptionStatusSchema, TAX_PROVIDERS, TAX_THRESHOLD_PERIODS, TAX_THRESHOLD_SCOPES, TaxThresholdInputSchema, WebhookEndpointCreateInputSchema, WebhookEndpointRotateInputSchema, WebhookEventDeliveryFilterSchema, catalogPriceChangeCount as priceChangeCount, createSteward, diffCatalogSync, generateApiKeyToken, generateWebhookSecret, meteredRateText, 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";
|
|
@@ -117,11 +117,6 @@ function definesMeters(input) {
|
|
|
117
117
|
function definesUnlistedPlans(input) {
|
|
118
118
|
return input.plans.some((plan) => plan.listed === false);
|
|
119
119
|
}
|
|
120
|
-
const isPlainObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
121
|
-
/** JSON with sorted object keys: key order does not count as a change. */
|
|
122
|
-
const canonical = (value) => JSON.stringify(value ?? null, (_key, v) => isPlainObject(v) ? Object.fromEntries(Object.entries(v).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)) : v);
|
|
123
|
-
const priceKey = (p) => `${p.planCode}/${p.interval}/${p.intervalCount}/${p.currency}`;
|
|
124
|
-
const priceLabel = (p) => `${p.planCode} ${p.intervalCount > 1 ? `${p.intervalCount}×` : ""}${p.interval}`;
|
|
125
120
|
/** `TRY 1,250.00`; minor units with the currency's own fraction digits (unknown currency: minor units). */
|
|
126
121
|
function formatMinor(amountMinor, currency) {
|
|
127
122
|
try {
|
|
@@ -139,147 +134,12 @@ function formatMinor(amountMinor, currency) {
|
|
|
139
134
|
const percent$1 = (bps) => `${bps / 100}%`;
|
|
140
135
|
/** Units as exact text with grouping (`2,000,000`, `0.25`). */
|
|
141
136
|
const unitsText = (value) => new Intl.NumberFormat("en", { maximumFractionDigits: 6 }).format(plainDecimalOf(value));
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
const cap = p.capMinor === void 0 || p.capMinor === null ? "" : `, cap ${formatMinor(p.capMinor, p.currency)}`;
|
|
147
|
-
return `${formatMinor(p.amountMinor, p.currency)} per ${unitsText(p.perUnits)} unit${p.perUnits === 1 ? "" : "s"}${cap}`;
|
|
148
|
-
}
|
|
149
|
-
function creditTerms(properties) {
|
|
150
|
-
const parsed = MeterCreditPropertiesSchema.safeParse(properties);
|
|
151
|
-
return parsed.success ? {
|
|
152
|
-
meter: parsed.data.meter,
|
|
153
|
-
units: parsed.data.units,
|
|
154
|
-
rolloverCapUnits: parsed.data.rolloverCapUnits ?? null
|
|
155
|
-
} : null;
|
|
156
|
-
}
|
|
157
|
-
function diffMeters(current, input) {
|
|
158
|
-
const before = current?.meters ?? {};
|
|
159
|
-
const meters = {
|
|
160
|
-
added: [],
|
|
161
|
-
changed: [],
|
|
162
|
-
ruleChanged: [],
|
|
163
|
-
archived: []
|
|
164
|
-
};
|
|
165
|
-
for (const [code, next] of Object.entries(input.meters)) {
|
|
166
|
-
const old = Object.hasOwn(before, code) ? before[code] : void 0;
|
|
167
|
-
if (old === void 0) {
|
|
168
|
-
meters.added.push(code);
|
|
169
|
-
continue;
|
|
170
|
-
}
|
|
171
|
-
if (canonical(old.filter) !== canonical(next.filter) || canonical(old.aggregation) !== canonical(next.aggregation)) meters.ruleChanged.push(code);
|
|
172
|
-
if (canonical(old.label) !== canonical(next.label) || canonical(old.unitLabel) !== canonical(next.unitLabel) || (old.displayPer ?? null) !== (next.displayPer ?? null) || old.lowAt !== next.lowAt) meters.changed.push(code);
|
|
173
|
-
}
|
|
174
|
-
meters.archived = Object.keys(before).filter((code) => !Object.hasOwn(input.meters, code));
|
|
175
|
-
return meters;
|
|
176
|
-
}
|
|
177
|
-
function meteredTerms(p) {
|
|
178
|
-
return {
|
|
179
|
-
amountMinor: p.amountMinor,
|
|
180
|
-
perUnits: p.perUnits,
|
|
181
|
-
taxInclusive: p.taxInclusive,
|
|
182
|
-
taxRateBps: p.taxRateBps,
|
|
183
|
-
capMinor: p.capMinor ?? null
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
function diffMeteredPrices(current, input) {
|
|
187
|
-
const before = new Map((current?.meteredPrices ?? []).map((p) => [meteredKey(p), p]));
|
|
188
|
-
const inputKeys = new Set(input.meteredPrices.map(meteredKey));
|
|
189
|
-
const out = {
|
|
190
|
-
added: [],
|
|
191
|
-
deactivated: [],
|
|
192
|
-
changed: []
|
|
193
|
-
};
|
|
194
|
-
for (const price of input.meteredPrices) {
|
|
195
|
-
const old = before.get(meteredKey(price));
|
|
196
|
-
if (old === void 0) out.added.push(`${meteredLabel(price)} ${meteredRate(price)}`);
|
|
197
|
-
else if (canonical(meteredTerms(old)) !== canonical(meteredTerms(price))) out.changed.push({
|
|
198
|
-
label: meteredLabel(price),
|
|
199
|
-
id: old.id,
|
|
200
|
-
currency: price.currency,
|
|
201
|
-
from: meteredTerms(old),
|
|
202
|
-
to: meteredTerms(price)
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
for (const [key, price] of before) if (!inputKeys.has(key)) out.deactivated.push(`${meteredLabel(price)} ${meteredRate(price)}`);
|
|
206
|
-
return out;
|
|
207
|
-
}
|
|
137
|
+
const FORMAT = {
|
|
138
|
+
money: formatMinor,
|
|
139
|
+
units: unitsText
|
|
140
|
+
};
|
|
208
141
|
function diffCatalog(current, file) {
|
|
209
|
-
|
|
210
|
-
const currentBenefits = current?.benefits ?? {};
|
|
211
|
-
const benefits = {
|
|
212
|
-
added: Object.keys(input.benefits).filter((code) => !Object.hasOwn(currentBenefits, code)),
|
|
213
|
-
changed: Object.entries(input.benefits).filter(([code]) => Object.hasOwn(currentBenefits, code)).filter(([code, next]) => {
|
|
214
|
-
const before = currentBenefits[code];
|
|
215
|
-
return before.type !== next.type || canonical(before.properties) !== canonical(next.properties) || canonical(before.description) !== canonical(next.description);
|
|
216
|
-
}).map(([code]) => code),
|
|
217
|
-
archived: Object.keys(currentBenefits).filter((code) => !Object.hasOwn(input.benefits, code))
|
|
218
|
-
};
|
|
219
|
-
const currentPlans = new Map((current?.plans ?? []).map((plan) => [plan.code, plan.benefits ?? []]));
|
|
220
|
-
const planBenefits = [];
|
|
221
|
-
for (const plan of input.plans) {
|
|
222
|
-
const before = currentPlans.get(plan.code) ?? [];
|
|
223
|
-
const added = plan.benefits.filter((code) => !before.includes(code));
|
|
224
|
-
const removed = before.filter((code) => !plan.benefits.includes(code));
|
|
225
|
-
if (added.length > 0 || removed.length > 0) planBenefits.push({
|
|
226
|
-
plan: plan.code,
|
|
227
|
-
added,
|
|
228
|
-
removed
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
const currentListing = new Map((current?.plans ?? []).map((plan) => [plan.code, plan.listed ?? true]));
|
|
232
|
-
const planListing = input.plans.filter((plan) => (currentListing.get(plan.code) ?? true) !== plan.listed).map((plan) => ({
|
|
233
|
-
plan: plan.code,
|
|
234
|
-
listed: plan.listed
|
|
235
|
-
}));
|
|
236
|
-
const currentPrices = new Map((current?.prices ?? []).map((price) => [priceKey(price), price]));
|
|
237
|
-
const inputKeys = new Set(input.prices.map(priceKey));
|
|
238
|
-
const prices = {
|
|
239
|
-
added: [],
|
|
240
|
-
deactivated: [],
|
|
241
|
-
changed: []
|
|
242
|
-
};
|
|
243
|
-
for (const price of input.prices) {
|
|
244
|
-
const before = currentPrices.get(priceKey(price));
|
|
245
|
-
if (before === void 0) prices.added.push(`${priceLabel(price)} ${formatMinor(price.amountMinor, price.currency)}`);
|
|
246
|
-
else if (before.amountMinor !== price.amountMinor || before.taxInclusive !== price.taxInclusive || before.taxRateBps !== price.taxRateBps) {
|
|
247
|
-
const terms = ({ amountMinor, taxInclusive, taxRateBps }) => ({
|
|
248
|
-
amountMinor,
|
|
249
|
-
taxInclusive,
|
|
250
|
-
taxRateBps
|
|
251
|
-
});
|
|
252
|
-
prices.changed.push({
|
|
253
|
-
label: priceLabel(price),
|
|
254
|
-
id: before.id,
|
|
255
|
-
currency: price.currency,
|
|
256
|
-
from: terms(before),
|
|
257
|
-
to: terms(price)
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
for (const [key, price] of currentPrices) if (!inputKeys.has(key)) prices.deactivated.push(`${priceLabel(price)} ${formatMinor(price.amountMinor, price.currency)}`);
|
|
262
|
-
const credits = [];
|
|
263
|
-
for (const [code, next] of Object.entries(input.benefits)) {
|
|
264
|
-
const old = Object.hasOwn(currentBenefits, code) ? currentBenefits[code] : void 0;
|
|
265
|
-
if (old === void 0 || old.type !== "meter_credit" || next.type !== "meter_credit") continue;
|
|
266
|
-
const from = creditTerms(old.properties);
|
|
267
|
-
const to = creditTerms(next.properties);
|
|
268
|
-
if (from !== null && to !== null && canonical(from) !== canonical(to)) credits.push({
|
|
269
|
-
code,
|
|
270
|
-
from,
|
|
271
|
-
to
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
return {
|
|
275
|
-
benefits,
|
|
276
|
-
planBenefits,
|
|
277
|
-
planListing,
|
|
278
|
-
prices,
|
|
279
|
-
meters: diffMeters(current, input),
|
|
280
|
-
credits,
|
|
281
|
-
meteredPrices: diffMeteredPrices(current, input)
|
|
282
|
-
};
|
|
142
|
+
return diffCatalogSync(current, CatalogSyncInputSchema.parse(file), FORMAT);
|
|
283
143
|
}
|
|
284
144
|
function describePriceChange({ label, currency, from, to }) {
|
|
285
145
|
const parts = [];
|
|
@@ -290,15 +150,15 @@ function describePriceChange({ label, currency, from, to }) {
|
|
|
290
150
|
}
|
|
291
151
|
function describeMeteredPriceChange({ label, currency, from, to }) {
|
|
292
152
|
const parts = [];
|
|
293
|
-
if (from.amountMinor !== to.amountMinor || from.perUnits !== to.perUnits) parts.push(`${
|
|
153
|
+
if (from.amountMinor !== to.amountMinor || from.perUnits !== to.perUnits) parts.push(`${meteredRateText({
|
|
294
154
|
currency,
|
|
295
155
|
amountMinor: from.amountMinor,
|
|
296
156
|
perUnits: from.perUnits
|
|
297
|
-
})} → ${
|
|
157
|
+
}, FORMAT)} → ${meteredRateText({
|
|
298
158
|
currency,
|
|
299
159
|
amountMinor: to.amountMinor,
|
|
300
160
|
perUnits: to.perUnits
|
|
301
|
-
})}`);
|
|
161
|
+
}, FORMAT)}`);
|
|
302
162
|
if (from.capMinor !== to.capMinor) {
|
|
303
163
|
const cap = (minor) => minor === null ? "none" : formatMinor(minor, currency);
|
|
304
164
|
parts.push(`cap ${cap(from.capMinor)} → ${cap(to.capMinor)}`);
|
|
@@ -353,10 +213,6 @@ function describeDiff(diff) {
|
|
|
353
213
|
}
|
|
354
214
|
return lines.length > 0 ? ["changes against the current catalog:", ...lines] : [];
|
|
355
215
|
}
|
|
356
|
-
/** Price changes the operator confirms before the push: base prices and metered prices changed in place. */
|
|
357
|
-
function priceChangeCount(diff) {
|
|
358
|
-
return diff.prices.changed.length + diff.meteredPrices.changed.length;
|
|
359
|
-
}
|
|
360
216
|
// src/dotenv.ts
|
|
361
217
|
const LINE = /^(\s*)(export\s+)?([A-Za-z_][A-Za-z0-9_.-]*)\s*=(.*)$/;
|
|
362
218
|
function unquote(rest) {
|
|
@@ -522,9 +378,240 @@ function describeStewardError(error, target) {
|
|
|
522
378
|
}
|
|
523
379
|
return `steward response does not match the contract${where}: ${error.code} (HTTP ${error.httpStatus}) — the CLI and steward versions may be incompatible${request}`;
|
|
524
380
|
}
|
|
381
|
+
// src/secret-file.ts
|
|
382
|
+
async function withSecretFile(cwd, out, secret, options, action) {
|
|
383
|
+
const target = resolve(cwd, out);
|
|
384
|
+
try {
|
|
385
|
+
if ((await lstat(target)).isDirectory()) throw new CliError(`--out is a folder: ${out}`);
|
|
386
|
+
if (!options.force) throw new CliError(`${out} already exists; use --force to overwrite it (no request was sent)`);
|
|
387
|
+
} catch (error) {
|
|
388
|
+
if (error instanceof CliError) throw error;
|
|
389
|
+
if (errnoCode(error) !== "ENOENT") throw error;
|
|
390
|
+
}
|
|
391
|
+
const temp = join(dirname(target), `.${basename(target)}.${randomUUID().slice(0, 8)}.tmp`);
|
|
392
|
+
try {
|
|
393
|
+
await writeFile(temp, secret, {
|
|
394
|
+
mode: 384,
|
|
395
|
+
flag: "wx"
|
|
396
|
+
});
|
|
397
|
+
} catch (error) {
|
|
398
|
+
const code = errnoCode(error);
|
|
399
|
+
if (code === "ENOENT") throw new CliError(`--out folder does not exist: ${relative(cwd, dirname(target)) || "."}`);
|
|
400
|
+
throw new CliError(`could not write the secret file (${code ?? "error"}): ${out} (no request was sent)`);
|
|
401
|
+
}
|
|
402
|
+
let value;
|
|
403
|
+
try {
|
|
404
|
+
value = await action();
|
|
405
|
+
} catch (error) {
|
|
406
|
+
await unlink(temp).catch(() => {});
|
|
407
|
+
throw error;
|
|
408
|
+
}
|
|
409
|
+
try {
|
|
410
|
+
if (options.force) await rename(temp, target);
|
|
411
|
+
else {
|
|
412
|
+
await link(temp, target);
|
|
413
|
+
await unlink(temp).catch(() => {});
|
|
414
|
+
}
|
|
415
|
+
return {
|
|
416
|
+
value,
|
|
417
|
+
path: out,
|
|
418
|
+
fallback: false
|
|
419
|
+
};
|
|
420
|
+
} catch {
|
|
421
|
+
return {
|
|
422
|
+
value,
|
|
423
|
+
path: relative(cwd, temp),
|
|
424
|
+
fallback: true
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
// src/commands/endpoints.ts
|
|
429
|
+
const ENDPOINTS_USAGE = `Usage:
|
|
430
|
+
steward endpoints list [--json]
|
|
431
|
+
steward endpoints add --url <url> --out <file> [--event-types <a,b>] [--description <text>] [--force]
|
|
432
|
+
steward endpoints rotate <id> --out <file> [--force]
|
|
433
|
+
steward endpoints deactivate <id>
|
|
434
|
+
|
|
435
|
+
Webhook endpoints (/v1/admin/webhook-endpoints). The signing secret (whsec_…) is
|
|
436
|
+
generated on this machine and written ONLY to the --out file (0600, no trailing
|
|
437
|
+
newline); it is not written to the terminal and steward never returns it in any
|
|
438
|
+
response. If the file exists, no request is sent without --force. The operator moves
|
|
439
|
+
the secret into the product's Secret (the CLI does not call kubectl); on rotation the
|
|
440
|
+
product moves over with a "new,old" list. Delete the file after moving it. Without
|
|
441
|
+
--event-types only account.state_changed. deactivate cannot be undone (open a new
|
|
442
|
+
endpoint).
|
|
443
|
+
|
|
444
|
+
Connection: STEWARD_ADMIN_URL + STEWARD_ADMIN_API_KEY (environment, otherwise ./.env.local).`;
|
|
445
|
+
function schemaProblems$1(issues) {
|
|
446
|
+
return issues.map((issue) => ` - ${issue.path.map(String).join(".") || "(root)"}: ${issue.message}`).join("\n");
|
|
447
|
+
}
|
|
448
|
+
const lastDeliveryText = (endpoint) => {
|
|
449
|
+
const last = endpoint.lastDelivery;
|
|
450
|
+
if (last === null) return "-";
|
|
451
|
+
return `${last.status}${last.httpStatus !== null ? ` ${last.httpStatus}` : ""}${last.error !== null ? ` ${last.error}` : ""} (${last.at})`;
|
|
452
|
+
};
|
|
453
|
+
/** Left-aligned columns; the last column is not padded. */
|
|
454
|
+
function table(rows) {
|
|
455
|
+
const widths = rows[0].map((_, column) => Math.max(...rows.map((row) => row[column].length)));
|
|
456
|
+
return rows.map((row) => row.map((cell, column) => column === row.length - 1 ? cell : cell.padEnd(widths[column])).join(" "));
|
|
457
|
+
}
|
|
458
|
+
const typesText = (endpoint) => endpoint.eventTypes === null ? "(no filter: 0.1 types)" : endpoint.eventTypes.join(",");
|
|
459
|
+
async function endpointsCommand(ctx, out, args) {
|
|
460
|
+
const [sub, ...rest] = args;
|
|
461
|
+
if (sub === void 0 || sub === "--help" || sub === "-h" || sub === "help") {
|
|
462
|
+
out.out(ENDPOINTS_USAGE);
|
|
463
|
+
return sub === void 0 ? 2 : 0;
|
|
464
|
+
}
|
|
465
|
+
if (sub === "list") {
|
|
466
|
+
const { values, positionals } = parse(rest, {
|
|
467
|
+
...HELP_OPTION,
|
|
468
|
+
json: { type: "boolean" }
|
|
469
|
+
}, "endpoints");
|
|
470
|
+
if (values.help) return help$7(out);
|
|
471
|
+
expectPositionals(positionals, 0, 0, "endpoints");
|
|
472
|
+
const target = requireAdminTarget(await resolveEnv(ctx));
|
|
473
|
+
out.err(connectionLine(target));
|
|
474
|
+
const { items } = await callSteward(target, () => clientFor(ctx, target).admin.endpoints.list());
|
|
475
|
+
if (values.json) out.out(JSON.stringify(items, null, 2));
|
|
476
|
+
else if (items.length === 0) out.out("no endpoints — steward endpoints add --url <url> --out <file>");
|
|
477
|
+
else {
|
|
478
|
+
const rows = [[
|
|
479
|
+
"ID",
|
|
480
|
+
"STATUS",
|
|
481
|
+
"EVENTS",
|
|
482
|
+
"LAST DELIVERY",
|
|
483
|
+
"URL"
|
|
484
|
+
]];
|
|
485
|
+
for (const e of items) rows.push([
|
|
486
|
+
e.id,
|
|
487
|
+
e.status,
|
|
488
|
+
typesText(e),
|
|
489
|
+
lastDeliveryText(e),
|
|
490
|
+
e.description !== null ? `${e.url} (${e.description})` : e.url
|
|
491
|
+
]);
|
|
492
|
+
for (const line of table(rows)) out.out(line);
|
|
493
|
+
}
|
|
494
|
+
return 0;
|
|
495
|
+
}
|
|
496
|
+
if (sub === "add") {
|
|
497
|
+
const { values, positionals } = parse(rest, {
|
|
498
|
+
...HELP_OPTION,
|
|
499
|
+
url: { type: "string" },
|
|
500
|
+
out: { type: "string" },
|
|
501
|
+
"event-types": { type: "string" },
|
|
502
|
+
description: { type: "string" },
|
|
503
|
+
force: { type: "boolean" }
|
|
504
|
+
}, ENDPOINTS_USAGE);
|
|
505
|
+
if (values.help) return help$7(out);
|
|
506
|
+
expectPositionals(positionals, 0, 0, "endpoints");
|
|
507
|
+
const url = requireOption(values.url, "--url", "endpoints");
|
|
508
|
+
const file = requireOption(values.out, "--out", "endpoints");
|
|
509
|
+
const secret = generateWebhookSecret();
|
|
510
|
+
const input = {
|
|
511
|
+
url,
|
|
512
|
+
secret,
|
|
513
|
+
...values["event-types"] !== void 0 ? { eventTypes: parseList(values["event-types"]) } : {},
|
|
514
|
+
...values.description !== void 0 ? { description: values.description } : {}
|
|
515
|
+
};
|
|
516
|
+
const parsed = WebhookEndpointCreateInputSchema.safeParse(input);
|
|
517
|
+
if (!parsed.success) throw new UsageError(`invalid endpoint (no request was sent)\n${schemaProblems$1(parsed.error.issues)}`);
|
|
518
|
+
const target = requireAdminTarget(await resolveEnv(ctx));
|
|
519
|
+
out.err(connectionLine(target));
|
|
520
|
+
const steward = clientFor(ctx, target);
|
|
521
|
+
const result = await withSecretFile(ctx.cwd, file, secret, { force: values.force === true }, () => callSteward(target, () => steward.admin.endpoints.create(input)));
|
|
522
|
+
const endpoint = result.value;
|
|
523
|
+
out.out(`endpoint created → ${originOf(target.url)}`);
|
|
524
|
+
out.out(` id ${endpoint.id}`);
|
|
525
|
+
out.out(` url ${endpoint.url}`);
|
|
526
|
+
out.out(` events ${typesText(endpoint)}`);
|
|
527
|
+
secretNotice(out, result.path, result.fallback, "Move the secret into the product's Secret (STEWARD_WEBHOOK_SECRET), then delete the file.");
|
|
528
|
+
return 0;
|
|
529
|
+
}
|
|
530
|
+
if (sub === "rotate") {
|
|
531
|
+
const { values, positionals } = parse(rest, {
|
|
532
|
+
...HELP_OPTION,
|
|
533
|
+
out: { type: "string" },
|
|
534
|
+
force: { type: "boolean" }
|
|
535
|
+
}, "endpoints");
|
|
536
|
+
if (values.help) return help$7(out);
|
|
537
|
+
expectPositionals(positionals, 1, 1, "endpoints");
|
|
538
|
+
const id = positionals[0];
|
|
539
|
+
const file = requireOption(values.out, "--out", "endpoints");
|
|
540
|
+
const secret = generateWebhookSecret();
|
|
541
|
+
const parsed = WebhookEndpointRotateInputSchema.safeParse({ secret });
|
|
542
|
+
if (!parsed.success) throw new UsageError(`invalid secret\n${schemaProblems$1(parsed.error.issues)}`);
|
|
543
|
+
const target = requireAdminTarget(await resolveEnv(ctx));
|
|
544
|
+
out.err(connectionLine(target));
|
|
545
|
+
const steward = clientFor(ctx, target);
|
|
546
|
+
const result = await withSecretFile(ctx.cwd, file, secret, { force: values.force === true }, () => callSteward(target, () => steward.admin.endpoints.rotate(id, { secret })));
|
|
547
|
+
out.out(`secret rotated → ${originOf(target.url)}`);
|
|
548
|
+
out.out(` id ${result.value.id}`);
|
|
549
|
+
out.out(` url ${result.value.url}`);
|
|
550
|
+
secretNotice(out, result.path, result.fallback, "Set STEWARD_WEBHOOK_SECRET in the product's Secret to \"new,old\" and roll out; the old secret stays in steward as a second signature for the transition. Then delete the file.");
|
|
551
|
+
return 0;
|
|
552
|
+
}
|
|
553
|
+
if (sub === "deactivate") {
|
|
554
|
+
const { values, positionals } = parse(rest, { ...HELP_OPTION }, "endpoints");
|
|
555
|
+
if (values.help) return help$7(out);
|
|
556
|
+
expectPositionals(positionals, 1, 1, "endpoints");
|
|
557
|
+
const target = requireAdminTarget(await resolveEnv(ctx));
|
|
558
|
+
out.err(connectionLine(target));
|
|
559
|
+
const endpoint = await callSteward(target, () => clientFor(ctx, target).admin.endpoints.deactivate(positionals[0]));
|
|
560
|
+
out.out(`endpoint deactivated → ${originOf(target.url)}: ${endpoint.id} (${endpoint.url}, status ${endpoint.status})`);
|
|
561
|
+
return 0;
|
|
562
|
+
}
|
|
563
|
+
throw new UsageError(`unknown subcommand: endpoints ${sub} (details: steward endpoints --help)`);
|
|
564
|
+
}
|
|
565
|
+
function help$7(out) {
|
|
566
|
+
out.out(ENDPOINTS_USAGE);
|
|
567
|
+
return 0;
|
|
568
|
+
}
|
|
569
|
+
/** Where a generated secret went (`withSecretFile`); shared by `endpoints` and `keys`. */
|
|
570
|
+
function secretNotice(out, path, fallback, next) {
|
|
571
|
+
if (fallback) out.err(`! the secret could not be moved to the target file (it may have been created meanwhile); it is in ${path} (0600)`);
|
|
572
|
+
out.out(` secret ${path} (0600; not written to the terminal)`);
|
|
573
|
+
out.err(next);
|
|
574
|
+
}
|
|
575
|
+
// src/commands/list-options.ts
|
|
576
|
+
/** An optional flag's value checked against a contract schema; `message` (it names the flag) when it does not match. */
|
|
577
|
+
function checkedOption(value, schema, message) {
|
|
578
|
+
if (value === void 0) return void 0;
|
|
579
|
+
const parsed = schema.safeParse(value);
|
|
580
|
+
if (!parsed.success) throw new UsageError(message);
|
|
581
|
+
return parsed.data;
|
|
582
|
+
}
|
|
583
|
+
/** `--account <ref>`: the product's external ref of an account. */
|
|
584
|
+
const accountOption = (value) => checkedOption(value, ExternalRefSchema, "--account: an account ref (letters, digits and _ . : -)");
|
|
585
|
+
/**
|
|
586
|
+
* `--from` (inclusive) / `--to` (exclusive): ISO-8601 with an offset (a bare local time would depend on
|
|
587
|
+
* this machine's time zone). The flag names stay inside the messages: the package check
|
|
588
|
+
* (`scripts/check-pack.mjs`) reads a quoted flag name that ends with the word from as an import.
|
|
589
|
+
*/
|
|
590
|
+
function periodOptions(values) {
|
|
591
|
+
return {
|
|
592
|
+
from: checkedOption(values.from, DateTimeSchema, "--from: ISO-8601 with an offset, e.g. 2026-10-01T00:00:00Z"),
|
|
593
|
+
to: checkedOption(values.to, DateTimeSchema, "--to: ISO-8601 with an offset, e.g. 2026-10-01T00:00:00Z")
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
/** Free text of 1–`max` characters (`--search`, `--type`, `--action`, `--source`). */
|
|
597
|
+
function textOption(value, flag, max) {
|
|
598
|
+
if (value !== void 0 && (value.length === 0 || value.length > max)) throw new UsageError(`${flag}: 1–${max} characters`);
|
|
599
|
+
return value;
|
|
600
|
+
}
|
|
601
|
+
const limitOption = (value) => value === void 0 ? void 0 : parsePositiveInt(value, "--limit", { max: ADMIN_LIST_MAX_LIMIT });
|
|
602
|
+
/** The filter without its unset options: the contract's filter types take no explicit `undefined`. */
|
|
603
|
+
function definedOnly(filter) {
|
|
604
|
+
return Object.fromEntries(Object.entries(filter).filter(([, value]) => value !== void 0));
|
|
605
|
+
}
|
|
606
|
+
/** The stderr line of a cut list: how many were listed and the `--after` value of the next page. */
|
|
607
|
+
function nextPageLine(noun, limit, cursor) {
|
|
608
|
+
return `more ${noun} than the ${limit ?? ADMIN_LIST_DEFAULT_LIMIT} listed; next page: --after ${cursor}`;
|
|
609
|
+
}
|
|
525
610
|
// src/commands/accounts.ts
|
|
526
611
|
const ACCOUNTS_USAGE = `Usage:
|
|
527
612
|
steward accounts get <ref> [--include <a,b>] [--json]
|
|
613
|
+
steward accounts list [--search <text>] [--status <status>] [--plan <code>]
|
|
614
|
+
[--deleted exclude|include|only] [--limit <n>] [--after <ref>] [--json]
|
|
528
615
|
steward accounts metadata set <ref> <key>=<value>… [--reason <text>] [--json]
|
|
529
616
|
steward accounts metadata unset <ref> <key>… [--reason <text>] [--json]
|
|
530
617
|
|
|
@@ -536,6 +623,24 @@ metadata. Nothing is written.
|
|
|
536
623
|
prints the whole response.
|
|
537
624
|
--json print the response as JSON
|
|
538
625
|
|
|
626
|
+
list (admin) finds accounts without their exact ref: the product's accounts in ref order, one
|
|
627
|
+
line per account with its billing currency and live subscriptions (GET /v1/admin/accounts).
|
|
628
|
+
Nothing personal is listed (no billing profile, no notification address): get <ref> --include
|
|
629
|
+
profile reads one account's profile.
|
|
630
|
+
|
|
631
|
+
--search <text> the ref starts with it, or the display name contains it (case-insensitive,
|
|
632
|
+
1–${ACCOUNT_LIST_QUERY_MAX} characters)
|
|
633
|
+
--status <status> accounts with a subscription in that status: active, past_due, suspended,
|
|
634
|
+
canceled or expired
|
|
635
|
+
--plan <code> accounts with a live subscription (active, past_due, suspended) of that plan;
|
|
636
|
+
with --status, a subscription of that plan in that status. A code the product
|
|
637
|
+
never had is refused (plan_not_found).
|
|
638
|
+
--deleted exclude (default): accounts that are not deleted; only: deleted (anonymized)
|
|
639
|
+
ones, shown as "(deleted <time>)"; include: both
|
|
640
|
+
--limit <n> 1–${ADMIN_LIST_MAX_LIMIT}, default ${ADMIN_LIST_DEFAULT_LIMIT}; a cut list says so on stderr with the --after value
|
|
641
|
+
(the last REF) of the next page
|
|
642
|
+
--json print the items as JSON
|
|
643
|
+
|
|
539
644
|
metadata set / unset change single metadata keys (PATCH /v1/accounts/:ref/metadata) and leave
|
|
540
645
|
every other key as it is. Steward merges them in one atomic write, so the change cannot
|
|
541
646
|
overwrite a key another writer (the product, another operator) changes at the same time. The
|
|
@@ -552,16 +657,26 @@ The account must exist: these commands never create one (404 account_not_found).
|
|
|
552
657
|
must not carry personal data (names, e-mail addresses, phone numbers): use opaque ids and
|
|
553
658
|
flags. set and unset need a steward whose GET /v1/me lists the "account_metadata" capability.
|
|
554
659
|
|
|
555
|
-
Connection: STEWARD_URL + STEWARD_API_KEY (or, when neither is set,
|
|
556
|
-
STEWARD_ADMIN_API_KEY)
|
|
557
|
-
X-Actor-Ref operator:<user>.
|
|
558
|
-
Exit code 1: steward refused (unknown or deleted account, no capability); 2: wrong
|
|
559
|
-
nothing was sent.`;
|
|
660
|
+
Connection: get and metadata use STEWARD_URL + STEWARD_API_KEY (or, when neither is set,
|
|
661
|
+
STEWARD_ADMIN_URL + STEWARD_ADMIN_API_KEY); list uses STEWARD_ADMIN_URL + STEWARD_ADMIN_API_KEY.
|
|
662
|
+
Environment, otherwise ./.env.local. Changes are sent with X-Actor-Ref operator:<user>.
|
|
663
|
+
Exit code 1: steward refused (unknown or deleted account, unknown plan, no capability); 2: wrong
|
|
664
|
+
usage, nothing was sent.`;
|
|
560
665
|
const GET_OPTIONS$1 = {
|
|
561
666
|
...HELP_OPTION,
|
|
562
667
|
include: { type: "string" },
|
|
563
668
|
json: { type: "boolean" }
|
|
564
669
|
};
|
|
670
|
+
const LIST_OPTIONS$4 = {
|
|
671
|
+
...HELP_OPTION,
|
|
672
|
+
search: { type: "string" },
|
|
673
|
+
status: { type: "string" },
|
|
674
|
+
plan: { type: "string" },
|
|
675
|
+
deleted: { type: "string" },
|
|
676
|
+
limit: { type: "string" },
|
|
677
|
+
after: { type: "string" },
|
|
678
|
+
json: { type: "boolean" }
|
|
679
|
+
};
|
|
565
680
|
const METADATA_OPTIONS = {
|
|
566
681
|
...HELP_OPTION,
|
|
567
682
|
reason: { type: "string" },
|
|
@@ -626,6 +741,48 @@ async function getCommand(ctx, out, args) {
|
|
|
626
741
|
else for (const line of formatAccount(account)) out.out(line);
|
|
627
742
|
return 0;
|
|
628
743
|
}
|
|
744
|
+
async function listCommand$1(ctx, out, args) {
|
|
745
|
+
const { values, positionals } = parse(args, LIST_OPTIONS$4, "accounts");
|
|
746
|
+
if (values.help) {
|
|
747
|
+
out.out(ACCOUNTS_USAGE);
|
|
748
|
+
return 0;
|
|
749
|
+
}
|
|
750
|
+
expectPositionals(positionals, 0, 0, "accounts");
|
|
751
|
+
const limit = limitOption(values.limit);
|
|
752
|
+
const filter = definedOnly({
|
|
753
|
+
q: textOption(values.search, "--search", ACCOUNT_LIST_QUERY_MAX),
|
|
754
|
+
status: checkedOption(values.status, SubscriptionStatusSchema, `--status: one of ${SubscriptionStatusSchema.options.join(", ")}`),
|
|
755
|
+
plan: checkedOption(values.plan, CodeSchema, "--plan: a plan code"),
|
|
756
|
+
deleted: checkedOption(values.deleted, AccountListDeletedFilterSchema, "--deleted: exclude, include or only"),
|
|
757
|
+
limit,
|
|
758
|
+
after: checkedOption(values.after, ExternalRefSchema, "--after: an account ref (the last REF of the previous page)")
|
|
759
|
+
});
|
|
760
|
+
const target = requireAdminTarget(await resolveEnv(ctx));
|
|
761
|
+
out.err(connectionLine(target));
|
|
762
|
+
const { items, hasMore } = await callSteward(target, () => clientFor(ctx, target).admin.accounts.list(filter));
|
|
763
|
+
if (values.json) out.out(JSON.stringify(items, null, 2));
|
|
764
|
+
else if (items.length === 0) out.out("no accounts");
|
|
765
|
+
else {
|
|
766
|
+
const rows = [[
|
|
767
|
+
"REF",
|
|
768
|
+
"NAME",
|
|
769
|
+
"CREATED",
|
|
770
|
+
"CURRENCY",
|
|
771
|
+
"SUBSCRIPTIONS"
|
|
772
|
+
]];
|
|
773
|
+
for (const a of items) rows.push([
|
|
774
|
+
a.ref,
|
|
775
|
+
a.deletedAt !== null ? `(deleted ${a.deletedAt})` : a.displayName || "-",
|
|
776
|
+
a.createdAt,
|
|
777
|
+
a.billingCurrency ?? "-",
|
|
778
|
+
a.liveSubscriptions.map((s) => `${s.planCode}/${s.interval} ${s.status}`).join(", ") || "-"
|
|
779
|
+
]);
|
|
780
|
+
for (const line of table(rows)) out.out(line);
|
|
781
|
+
}
|
|
782
|
+
const last = items.at(-1);
|
|
783
|
+
if (hasMore && last !== void 0) out.err(nextPageLine("accounts", limit, last.ref));
|
|
784
|
+
return 0;
|
|
785
|
+
}
|
|
629
786
|
/** `key=value` arguments (split at the first `=`) or bare keys → the patch: a value sets, `null` removes. */
|
|
630
787
|
function parseMetadataChange(action, items) {
|
|
631
788
|
const change = /* @__PURE__ */ new Map();
|
|
@@ -672,236 +829,140 @@ async function metadataCommand(ctx, out, args) {
|
|
|
672
829
|
...values.reason !== void 0 ? { reason: values.reason } : {}
|
|
673
830
|
});
|
|
674
831
|
if (!input.success) throw new UsageError(`invalid metadata change (nothing was sent)\n${input.error.issues.map((issue) => ` - ${issue.path.map(String).join(".") || "(root)"}: ${issue.message}`).join("\n")}`);
|
|
675
|
-
const target = requireReadTarget(await resolveEnv(ctx));
|
|
676
|
-
out.err(connectionLine(target));
|
|
677
|
-
const steward = clientFor(ctx, target);
|
|
678
|
-
await requireMetadataCapability(steward, target);
|
|
679
|
-
const current = await callSteward(target, () => steward.accounts.get(ref));
|
|
680
|
-
const say = values.json ? out.err : out.out;
|
|
681
|
-
say(`metadata of ${ref}:`);
|
|
682
|
-
for (const line of changeLines(current.metadata, input.data.metadata)) say(line);
|
|
683
|
-
const updated = await callSteward(target, () => steward.accounts.updateMetadata(ref, input.data));
|
|
684
|
-
if (values.json) out.out(JSON.stringify(updated, null, 2));
|
|
685
|
-
else {
|
|
686
|
-
const count = Object.keys(updated.metadata).length;
|
|
687
|
-
out.out(`written → ${originOf(target.url)}: ${ref} now has ${count} metadata key${count === 1 ? "" : "s"}`);
|
|
688
|
-
}
|
|
689
|
-
return 0;
|
|
690
|
-
}
|
|
691
|
-
async function accountsCommand(ctx, out, args) {
|
|
692
|
-
const [sub, ...rest] = args;
|
|
693
|
-
if (sub === void 0 || sub === "--help" || sub === "-h" || sub === "help") {
|
|
694
|
-
out.out(ACCOUNTS_USAGE);
|
|
695
|
-
return sub === void 0 ? 2 : 0;
|
|
696
|
-
}
|
|
697
|
-
if (sub === "get") return getCommand(ctx, out, rest);
|
|
698
|
-
if (sub === "metadata") return metadataCommand(ctx, out, rest);
|
|
699
|
-
throw new UsageError(`unknown subcommand: accounts ${sub} (see: steward accounts --help)`);
|
|
700
|
-
}
|
|
701
|
-
// src/confirm.ts
|
|
702
|
-
/**
|
|
703
|
-
* Asks before a change that cannot be taken back; `yes` (`--yes`) skips the question. Without a
|
|
704
|
-
* terminal (CI, pipes) the command needs `--yes`: `notConfirmed` says what was not done.
|
|
705
|
-
*/
|
|
706
|
-
async function confirm(ctx, question, options) {
|
|
707
|
-
if (options.yes) return true;
|
|
708
|
-
const answer = await ctx.prompt(`${question} [y/N] `);
|
|
709
|
-
if (answer === null) throw new CliError(`confirmation needed: run again with --yes (${options.notConfirmed})`);
|
|
710
|
-
return /^y(es)?$/i.test(answer.trim());
|
|
711
|
-
}
|
|
712
|
-
// src/secret-file.ts
|
|
713
|
-
async function withSecretFile(cwd, out, secret, options, action) {
|
|
714
|
-
const target = resolve(cwd, out);
|
|
715
|
-
try {
|
|
716
|
-
if ((await lstat(target)).isDirectory()) throw new CliError(`--out is a folder: ${out}`);
|
|
717
|
-
if (!options.force) throw new CliError(`${out} already exists; use --force to overwrite it (no request was sent)`);
|
|
718
|
-
} catch (error) {
|
|
719
|
-
if (error instanceof CliError) throw error;
|
|
720
|
-
if (errnoCode(error) !== "ENOENT") throw error;
|
|
721
|
-
}
|
|
722
|
-
const temp = join(dirname(target), `.${basename(target)}.${randomUUID().slice(0, 8)}.tmp`);
|
|
723
|
-
try {
|
|
724
|
-
await writeFile(temp, secret, {
|
|
725
|
-
mode: 384,
|
|
726
|
-
flag: "wx"
|
|
727
|
-
});
|
|
728
|
-
} catch (error) {
|
|
729
|
-
const code = errnoCode(error);
|
|
730
|
-
if (code === "ENOENT") throw new CliError(`--out folder does not exist: ${relative(cwd, dirname(target)) || "."}`);
|
|
731
|
-
throw new CliError(`could not write the secret file (${code ?? "error"}): ${out} (no request was sent)`);
|
|
732
|
-
}
|
|
733
|
-
let value;
|
|
734
|
-
try {
|
|
735
|
-
value = await action();
|
|
736
|
-
} catch (error) {
|
|
737
|
-
await unlink(temp).catch(() => {});
|
|
738
|
-
throw error;
|
|
739
|
-
}
|
|
740
|
-
try {
|
|
741
|
-
if (options.force) await rename(temp, target);
|
|
742
|
-
else {
|
|
743
|
-
await link(temp, target);
|
|
744
|
-
await unlink(temp).catch(() => {});
|
|
745
|
-
}
|
|
746
|
-
return {
|
|
747
|
-
value,
|
|
748
|
-
path: out,
|
|
749
|
-
fallback: false
|
|
750
|
-
};
|
|
751
|
-
} catch {
|
|
752
|
-
return {
|
|
753
|
-
value,
|
|
754
|
-
path: relative(cwd, temp),
|
|
755
|
-
fallback: true
|
|
756
|
-
};
|
|
832
|
+
const target = requireReadTarget(await resolveEnv(ctx));
|
|
833
|
+
out.err(connectionLine(target));
|
|
834
|
+
const steward = clientFor(ctx, target);
|
|
835
|
+
await requireMetadataCapability(steward, target);
|
|
836
|
+
const current = await callSteward(target, () => steward.accounts.get(ref));
|
|
837
|
+
const say = values.json ? out.err : out.out;
|
|
838
|
+
say(`metadata of ${ref}:`);
|
|
839
|
+
for (const line of changeLines(current.metadata, input.data.metadata)) say(line);
|
|
840
|
+
const updated = await callSteward(target, () => steward.accounts.updateMetadata(ref, input.data));
|
|
841
|
+
if (values.json) out.out(JSON.stringify(updated, null, 2));
|
|
842
|
+
else {
|
|
843
|
+
const count = Object.keys(updated.metadata).length;
|
|
844
|
+
out.out(`written → ${originOf(target.url)}: ${ref} now has ${count} metadata key${count === 1 ? "" : "s"}`);
|
|
757
845
|
}
|
|
846
|
+
return 0;
|
|
758
847
|
}
|
|
759
|
-
|
|
760
|
-
const
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
848
|
+
async function accountsCommand(ctx, out, args) {
|
|
849
|
+
const [sub, ...rest] = args;
|
|
850
|
+
if (sub === void 0 || sub === "--help" || sub === "-h" || sub === "help") {
|
|
851
|
+
out.out(ACCOUNTS_USAGE);
|
|
852
|
+
return sub === void 0 ? 2 : 0;
|
|
853
|
+
}
|
|
854
|
+
if (sub === "get") return getCommand(ctx, out, rest);
|
|
855
|
+
if (sub === "list") return listCommand$1(ctx, out, rest);
|
|
856
|
+
if (sub === "metadata") return metadataCommand(ctx, out, rest);
|
|
857
|
+
throw new UsageError(`unknown subcommand: accounts ${sub} (see: steward accounts --help)`);
|
|
858
|
+
}
|
|
859
|
+
// src/commands/audit.ts
|
|
860
|
+
const AUDIT_USAGE = `Usage:
|
|
861
|
+
steward audit list [--account <ref>] [--action <action>] [--api-key <prefix>] [--console-user <id>]
|
|
862
|
+
[--source <source>] [--from <iso>] [--to <iso>] [--limit <n>] [--after <id>] [--json]
|
|
863
|
+
|
|
864
|
+
The product's audit trail, newest first, one line per row (GET /v1/admin/audit): when, the
|
|
865
|
+
action (e.g. subscription.canceled, api_key.created), the account, who wrote it and the actor.
|
|
866
|
+
WHO is the API key's prefix for a /v1 request (key a1b2c3d4e5f6), the console user's id for an
|
|
867
|
+
operator console request (console <id>), otherwise the source: job:<name>, cli (the pod CLI),
|
|
868
|
+
hosted or provider_webhook. ACTOR is what the caller reported about itself (X-Actor-Ref, e.g.
|
|
869
|
+
operator:ada), not proof of identity. Reads are not audited.
|
|
870
|
+
|
|
871
|
+
--account <ref> one account's rows (an unknown ref is account_not_found)
|
|
872
|
+
--action <action> one action, exact
|
|
873
|
+
--api-key <prefix> rows written with one API key: the 12 hex characters after stw_ (keys list)
|
|
874
|
+
--console-user <id> rows written by one console user, by id (as WHO shows it)
|
|
875
|
+
--source <source> rows of one source, exact (e.g. job:dunning, hosted)
|
|
876
|
+
--from <iso> written at or after (inclusive); ISO-8601 with an offset
|
|
877
|
+
--to <iso> written before (exclusive); ISO-8601 with an offset
|
|
878
|
+
--limit <n> 1–${ADMIN_LIST_MAX_LIMIT}, default ${ADMIN_LIST_DEFAULT_LIMIT}; a cut list says so on stderr with the --after value
|
|
879
|
+
(the last row's id) of the next page
|
|
880
|
+
--json print the items as JSON, with each row's writer, request id and detail (its
|
|
881
|
+
own record of what changed; an admin.request row carries the client IP)
|
|
774
882
|
|
|
775
883
|
Connection: STEWARD_ADMIN_URL + STEWARD_ADMIN_API_KEY (environment, otherwise ./.env.local).`;
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
}
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
884
|
+
const LIST_OPTIONS$3 = {
|
|
885
|
+
...HELP_OPTION,
|
|
886
|
+
account: { type: "string" },
|
|
887
|
+
action: { type: "string" },
|
|
888
|
+
"api-key": { type: "string" },
|
|
889
|
+
"console-user": { type: "string" },
|
|
890
|
+
source: { type: "string" },
|
|
891
|
+
from: { type: "string" },
|
|
892
|
+
to: { type: "string" },
|
|
893
|
+
limit: { type: "string" },
|
|
894
|
+
after: { type: "string" },
|
|
895
|
+
json: { type: "boolean" }
|
|
783
896
|
};
|
|
784
|
-
/**
|
|
785
|
-
function
|
|
786
|
-
|
|
787
|
-
|
|
897
|
+
/** Who wrote the row: the API key of a /v1 request, the console user of a console request, otherwise its source. */
|
|
898
|
+
function writerOf(writer) {
|
|
899
|
+
if (writer === null) return "-";
|
|
900
|
+
switch (writer.kind) {
|
|
901
|
+
case "api_key": return `key ${writer.prefix}`;
|
|
902
|
+
case "console_user": return `console ${writer.id}`;
|
|
903
|
+
case "source": return writer.source;
|
|
904
|
+
}
|
|
788
905
|
}
|
|
789
|
-
|
|
790
|
-
async function endpointsCommand(ctx, out, args) {
|
|
906
|
+
async function auditCommand(ctx, out, args) {
|
|
791
907
|
const [sub, ...rest] = args;
|
|
792
908
|
if (sub === void 0 || sub === "--help" || sub === "-h" || sub === "help") {
|
|
793
|
-
out.out(
|
|
909
|
+
out.out(AUDIT_USAGE);
|
|
794
910
|
return sub === void 0 ? 2 : 0;
|
|
795
911
|
}
|
|
796
|
-
if (sub
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
}, "endpoints");
|
|
801
|
-
if (values.help) return help$7(out);
|
|
802
|
-
expectPositionals(positionals, 0, 0, "endpoints");
|
|
803
|
-
const target = requireAdminTarget(await resolveEnv(ctx));
|
|
804
|
-
out.err(connectionLine(target));
|
|
805
|
-
const { items } = await callSteward(target, () => clientFor(ctx, target).admin.endpoints.list());
|
|
806
|
-
if (values.json) out.out(JSON.stringify(items, null, 2));
|
|
807
|
-
else if (items.length === 0) out.out("no endpoints — steward endpoints add --url <url> --out <file>");
|
|
808
|
-
else {
|
|
809
|
-
const rows = [[
|
|
810
|
-
"ID",
|
|
811
|
-
"STATUS",
|
|
812
|
-
"EVENTS",
|
|
813
|
-
"LAST DELIVERY",
|
|
814
|
-
"URL"
|
|
815
|
-
]];
|
|
816
|
-
for (const e of items) rows.push([
|
|
817
|
-
e.id,
|
|
818
|
-
e.status,
|
|
819
|
-
typesText(e),
|
|
820
|
-
lastDeliveryText(e),
|
|
821
|
-
e.description !== null ? `${e.url} (${e.description})` : e.url
|
|
822
|
-
]);
|
|
823
|
-
for (const line of table(rows)) out.out(line);
|
|
824
|
-
}
|
|
825
|
-
return 0;
|
|
826
|
-
}
|
|
827
|
-
if (sub === "add") {
|
|
828
|
-
const { values, positionals } = parse(rest, {
|
|
829
|
-
...HELP_OPTION,
|
|
830
|
-
url: { type: "string" },
|
|
831
|
-
out: { type: "string" },
|
|
832
|
-
"event-types": { type: "string" },
|
|
833
|
-
description: { type: "string" },
|
|
834
|
-
force: { type: "boolean" }
|
|
835
|
-
}, ENDPOINTS_USAGE);
|
|
836
|
-
if (values.help) return help$7(out);
|
|
837
|
-
expectPositionals(positionals, 0, 0, "endpoints");
|
|
838
|
-
const url = requireOption(values.url, "--url", "endpoints");
|
|
839
|
-
const file = requireOption(values.out, "--out", "endpoints");
|
|
840
|
-
const secret = generateWebhookSecret();
|
|
841
|
-
const input = {
|
|
842
|
-
url,
|
|
843
|
-
secret,
|
|
844
|
-
...values["event-types"] !== void 0 ? { eventTypes: parseList(values["event-types"]) } : {},
|
|
845
|
-
...values.description !== void 0 ? { description: values.description } : {}
|
|
846
|
-
};
|
|
847
|
-
const parsed = WebhookEndpointCreateInputSchema.safeParse(input);
|
|
848
|
-
if (!parsed.success) throw new UsageError(`invalid endpoint (no request was sent)\n${schemaProblems$1(parsed.error.issues)}`);
|
|
849
|
-
const target = requireAdminTarget(await resolveEnv(ctx));
|
|
850
|
-
out.err(connectionLine(target));
|
|
851
|
-
const steward = clientFor(ctx, target);
|
|
852
|
-
const result = await withSecretFile(ctx.cwd, file, secret, { force: values.force === true }, () => callSteward(target, () => steward.admin.endpoints.create(input)));
|
|
853
|
-
const endpoint = result.value;
|
|
854
|
-
out.out(`endpoint created → ${originOf(target.url)}`);
|
|
855
|
-
out.out(` id ${endpoint.id}`);
|
|
856
|
-
out.out(` url ${endpoint.url}`);
|
|
857
|
-
out.out(` events ${typesText(endpoint)}`);
|
|
858
|
-
secretNotice(out, result.path, result.fallback, "Move the secret into the product's Secret (STEWARD_WEBHOOK_SECRET), then delete the file.");
|
|
859
|
-
return 0;
|
|
860
|
-
}
|
|
861
|
-
if (sub === "rotate") {
|
|
862
|
-
const { values, positionals } = parse(rest, {
|
|
863
|
-
...HELP_OPTION,
|
|
864
|
-
out: { type: "string" },
|
|
865
|
-
force: { type: "boolean" }
|
|
866
|
-
}, "endpoints");
|
|
867
|
-
if (values.help) return help$7(out);
|
|
868
|
-
expectPositionals(positionals, 1, 1, "endpoints");
|
|
869
|
-
const id = positionals[0];
|
|
870
|
-
const file = requireOption(values.out, "--out", "endpoints");
|
|
871
|
-
const secret = generateWebhookSecret();
|
|
872
|
-
const parsed = WebhookEndpointRotateInputSchema.safeParse({ secret });
|
|
873
|
-
if (!parsed.success) throw new UsageError(`invalid secret\n${schemaProblems$1(parsed.error.issues)}`);
|
|
874
|
-
const target = requireAdminTarget(await resolveEnv(ctx));
|
|
875
|
-
out.err(connectionLine(target));
|
|
876
|
-
const steward = clientFor(ctx, target);
|
|
877
|
-
const result = await withSecretFile(ctx.cwd, file, secret, { force: values.force === true }, () => callSteward(target, () => steward.admin.endpoints.rotate(id, { secret })));
|
|
878
|
-
out.out(`secret rotated → ${originOf(target.url)}`);
|
|
879
|
-
out.out(` id ${result.value.id}`);
|
|
880
|
-
out.out(` url ${result.value.url}`);
|
|
881
|
-
secretNotice(out, result.path, result.fallback, "Set STEWARD_WEBHOOK_SECRET in the product's Secret to \"new,old\" and roll out; the old secret stays in steward as a second signature for the transition. Then delete the file.");
|
|
912
|
+
if (sub !== "list") throw new UsageError(`unknown subcommand: audit ${sub} (see: steward audit --help)`);
|
|
913
|
+
const { values, positionals } = parse(rest, LIST_OPTIONS$3, "audit");
|
|
914
|
+
if (values.help) {
|
|
915
|
+
out.out(AUDIT_USAGE);
|
|
882
916
|
return 0;
|
|
883
917
|
}
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
918
|
+
expectPositionals(positionals, 0, 0, "audit");
|
|
919
|
+
const limit = limitOption(values.limit);
|
|
920
|
+
const filter = definedOnly({
|
|
921
|
+
account: accountOption(values.account),
|
|
922
|
+
action: textOption(values.action, "--action", AUDIT_LIST_FILTER_MAX),
|
|
923
|
+
apiKey: checkedOption(values["api-key"], ApiKeyPrefixSchema, "--api-key: a key prefix, the 12 hex characters after stw_"),
|
|
924
|
+
consoleUser: checkedOption(values["console-user"], IdSchema, "--console-user: a console user id"),
|
|
925
|
+
source: textOption(values.source, "--source", AUDIT_LIST_FILTER_MAX),
|
|
926
|
+
...periodOptions(values),
|
|
927
|
+
limit,
|
|
928
|
+
after: checkedOption(values.after, IdSchema, "--after: an audit row id")
|
|
929
|
+
});
|
|
930
|
+
const target = requireAdminTarget(await resolveEnv(ctx));
|
|
931
|
+
out.err(connectionLine(target));
|
|
932
|
+
const { items, hasMore } = await callSteward(target, () => clientFor(ctx, target).admin.audit.list(filter));
|
|
933
|
+
if (values.json) out.out(JSON.stringify(items, null, 2));
|
|
934
|
+
else if (items.length === 0) out.out("no audit rows");
|
|
935
|
+
else {
|
|
936
|
+
const rows = [[
|
|
937
|
+
"TIME",
|
|
938
|
+
"ACTION",
|
|
939
|
+
"ACCOUNT",
|
|
940
|
+
"WHO",
|
|
941
|
+
"ACTOR"
|
|
942
|
+
]];
|
|
943
|
+
for (const row of items) rows.push([
|
|
944
|
+
row.createdAt,
|
|
945
|
+
row.action,
|
|
946
|
+
row.accountRef ?? "-",
|
|
947
|
+
writerOf(row.writer),
|
|
948
|
+
row.actorRef ?? "-"
|
|
949
|
+
]);
|
|
950
|
+
for (const line of table(rows)) out.out(line);
|
|
893
951
|
}
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
function help$7(out) {
|
|
897
|
-
out.out(ENDPOINTS_USAGE);
|
|
952
|
+
const last = items.at(-1);
|
|
953
|
+
if (hasMore && last !== void 0) out.err(nextPageLine("audit rows", limit, last.id));
|
|
898
954
|
return 0;
|
|
899
955
|
}
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
956
|
+
// src/confirm.ts
|
|
957
|
+
/**
|
|
958
|
+
* Asks before a change that cannot be taken back; `yes` (`--yes`) skips the question. Without a
|
|
959
|
+
* terminal (CI, pipes) the command needs `--yes`: `notConfirmed` says what was not done.
|
|
960
|
+
*/
|
|
961
|
+
async function confirm(ctx, question, options) {
|
|
962
|
+
if (options.yes) return true;
|
|
963
|
+
const answer = await ctx.prompt(`${question} [y/N] `);
|
|
964
|
+
if (answer === null) throw new CliError(`confirmation needed: run again with --yes (${options.notConfirmed})`);
|
|
965
|
+
return /^y(es)?$/i.test(answer.trim());
|
|
905
966
|
}
|
|
906
967
|
// src/commands/bank-transfers.ts
|
|
907
968
|
const BANK_TRANSFERS_USAGE = `Usage:
|
|
@@ -1817,10 +1878,11 @@ const DISCOUNTS_USAGE = `Usage:
|
|
|
1817
1878
|
steward discounts list [--archived] [--json]
|
|
1818
1879
|
steward discounts create --name <text> (--percent <n> | --amount <CUR:minor>...) --duration once|repeating|forever
|
|
1819
1880
|
[--months <n>] [--code <code>] [--plans <a,b>] [--starts <iso>] [--ends <iso>]
|
|
1820
|
-
[--max <n>] [--per-customer <n>|unlimited] [--json]
|
|
1881
|
+
[--max <n>] [--per-customer <n>|unlimited] [--benefit <code>]... [--json]
|
|
1821
1882
|
steward discounts update <id> [--name …] [--code <code>|none] [--plans <a,b>|none] [--starts <iso>|none]
|
|
1822
1883
|
[--ends <iso>|none] [--max <n>|none] [--per-customer <n>|unlimited]
|
|
1823
|
-
[--percent … | --amount …] [--duration … --months …]
|
|
1884
|
+
[--percent … | --amount …] [--duration … --months …]
|
|
1885
|
+
[--benefit <code>... | --benefit none] [--json]
|
|
1824
1886
|
steward discounts archive <id> [--yes]
|
|
1825
1887
|
|
|
1826
1888
|
The product's discounts (/v1/admin/discounts): a share (--percent 20, up to 99.99) or an amount per
|
|
@@ -1828,8 +1890,14 @@ currency in minor units (--amount USD:500 --amount EUR:450) off a plan's base pr
|
|
|
1828
1890
|
invoice (once), --months calendar months (repeating) or every invoice (forever). A discount with
|
|
1829
1891
|
--code is entered by the customer on the hosted checkout; one without is applied by the product
|
|
1830
1892
|
(checkout.create({ discountId })). Codes are case-insensitive. --plans restricts it (default:
|
|
1831
|
-
every listed plan). --per-customer defaults to 1.
|
|
1832
|
-
|
|
1893
|
+
every listed plan). --per-customer defaults to 1.
|
|
1894
|
+
|
|
1895
|
+
--benefit (repeatable) adds a catalog benefit the account is granted while its subscription runs
|
|
1896
|
+
with the discount: from the first period for a checkout, from the next renewal for a discount
|
|
1897
|
+
attached later, until the discount ends. A meter credit benefit with a rollover cap carries what
|
|
1898
|
+
is left of the last discounted period into the next one, once. On update the benefits given
|
|
1899
|
+
replace the list (--benefit none: no benefits). Once redeemed, its value, duration and benefits
|
|
1900
|
+
no longer change; archive it and create another instead.
|
|
1833
1901
|
|
|
1834
1902
|
create warns when the discount would bring a sellable price of the catalog to zero or under the
|
|
1835
1903
|
payment provider's minimum charge (such a price refuses the code at checkout).
|
|
@@ -1857,6 +1925,10 @@ const OPTIONS$1 = {
|
|
|
1857
1925
|
ends: { type: "string" },
|
|
1858
1926
|
max: { type: "string" },
|
|
1859
1927
|
"per-customer": { type: "string" },
|
|
1928
|
+
benefit: {
|
|
1929
|
+
type: "string",
|
|
1930
|
+
multiple: true
|
|
1931
|
+
},
|
|
1860
1932
|
json: { type: "boolean" }
|
|
1861
1933
|
};
|
|
1862
1934
|
const NONE = "none";
|
|
@@ -1878,6 +1950,16 @@ function parseAmounts(values) {
|
|
|
1878
1950
|
}
|
|
1879
1951
|
return out;
|
|
1880
1952
|
}
|
|
1953
|
+
/** `--benefit` values → benefit codes; `none` alone (update) → no benefits. */
|
|
1954
|
+
function benefitCodesOf(values, update) {
|
|
1955
|
+
const codes = values.map((v) => v.trim());
|
|
1956
|
+
if (codes.includes(NONE)) {
|
|
1957
|
+
if (!update) throw new UsageError("--benefit none: only on update (a new discount has no benefits without --benefit)");
|
|
1958
|
+
if (codes.length > 1) throw new UsageError("--benefit none: give it alone");
|
|
1959
|
+
return [];
|
|
1960
|
+
}
|
|
1961
|
+
return codes;
|
|
1962
|
+
}
|
|
1881
1963
|
/** The fields shared by create and update (update: `none` clears an optional one). */
|
|
1882
1964
|
function fieldsOf(values, update) {
|
|
1883
1965
|
const clearable = (value, read) => value === void 0 ? void 0 : update && value.trim() === NONE ? null : read(value);
|
|
@@ -1890,7 +1972,8 @@ function fieldsOf(values, update) {
|
|
|
1890
1972
|
startsAt: clearable(values.starts, (v) => v.trim()),
|
|
1891
1973
|
endsAt: clearable(values.ends, (v) => v.trim()),
|
|
1892
1974
|
maxRedemptions: clearable(values.max, (v) => parsePositiveInt(v, "--max")),
|
|
1893
|
-
maxRedemptionsPerCustomer: values["per-customer"] === void 0 ? void 0 : values["per-customer"].trim() === "unlimited" ? null : parsePositiveInt(values["per-customer"], "--per-customer")
|
|
1975
|
+
maxRedemptionsPerCustomer: values["per-customer"] === void 0 ? void 0 : values["per-customer"].trim() === "unlimited" ? null : parsePositiveInt(values["per-customer"], "--per-customer"),
|
|
1976
|
+
benefitCodes: values.benefit !== void 0 ? benefitCodesOf(values.benefit, update) : void 0
|
|
1894
1977
|
};
|
|
1895
1978
|
if (values.percent !== void 0 && values.amount !== void 0) throw new UsageError("give --percent or --amount, not both");
|
|
1896
1979
|
if (values.percent !== void 0) Object.assign(fields, {
|
|
@@ -1950,6 +2033,7 @@ function describe$1(d) {
|
|
|
1950
2033
|
d.maxRedemptions !== null ? `max ${d.maxRedemptions}` : null,
|
|
1951
2034
|
`per customer ${d.maxRedemptionsPerCustomer ?? "unlimited"}`,
|
|
1952
2035
|
d.planCodes.length > 0 ? `plans ${d.planCodes.join(",")}` : null,
|
|
2036
|
+
d.benefitCodes.length > 0 ? `benefits ${d.benefitCodes.join(",")}` : null,
|
|
1953
2037
|
d.startsAt ? `from ${d.startsAt}` : null,
|
|
1954
2038
|
d.endsAt ? `until ${d.endsAt}` : null
|
|
1955
2039
|
].filter(Boolean);
|
|
@@ -2172,10 +2256,99 @@ function help$3(out) {
|
|
|
2172
2256
|
out.out(EMAIL_SMTP_USAGE);
|
|
2173
2257
|
return 0;
|
|
2174
2258
|
}
|
|
2259
|
+
// src/commands/emails.ts
|
|
2260
|
+
/** Longest email id: an event id, or the source key of an email without one. */
|
|
2261
|
+
const EMAIL_ID_MAX = 200;
|
|
2262
|
+
const EMAILS_USAGE = `Usage:
|
|
2263
|
+
steward emails list [--account <ref>] [--status pending|sent|skipped|dead] [--template <name>]
|
|
2264
|
+
[--limit <n>] [--after <id>] [--json]
|
|
2265
|
+
|
|
2266
|
+
The billing emails steward queued for the product's accounts, newest first, one line per email
|
|
2267
|
+
(GET /v1/admin/emails): the template, the status, the account, the attempts and the last error.
|
|
2268
|
+
pending: waiting or being retried; sent; skipped: not sent, ERROR says why (e.g. no_recipient,
|
|
2269
|
+
template_disabled); dead: the retries ran out, ERROR is the last error code. The ID is the
|
|
2270
|
+
email's webhook event (evt_…) or, for an email without one (e.g. the invoice payment reminder),
|
|
2271
|
+
its source key. Recipient addresses are never stored, so they are not listed (--json has their
|
|
2272
|
+
count).
|
|
2273
|
+
|
|
2274
|
+
--account <ref> one account's emails (an unknown ref is account_not_found)
|
|
2275
|
+
--status <status> pending, sent, skipped or dead
|
|
2276
|
+
--template <name> one template, e.g. payment_receipt, payment_failed, invoice_payment_due (an
|
|
2277
|
+
unknown name is refused with the list)
|
|
2278
|
+
--limit <n> 1–${ADMIN_LIST_MAX_LIMIT}, default ${ADMIN_LIST_DEFAULT_LIMIT}; a cut list says so on stderr with the --after value
|
|
2279
|
+
(the last ID) of the next page
|
|
2280
|
+
--json print the items as JSON
|
|
2281
|
+
|
|
2282
|
+
Failing emails: steward doctor shows which SMTP account the emails go through and its recent
|
|
2283
|
+
failures; steward email-smtp verify checks the product's own account.
|
|
2284
|
+
|
|
2285
|
+
Connection: STEWARD_ADMIN_URL + STEWARD_ADMIN_API_KEY (environment, otherwise ./.env.local).`;
|
|
2286
|
+
const LIST_OPTIONS$2 = {
|
|
2287
|
+
...HELP_OPTION,
|
|
2288
|
+
account: { type: "string" },
|
|
2289
|
+
status: { type: "string" },
|
|
2290
|
+
template: { type: "string" },
|
|
2291
|
+
limit: { type: "string" },
|
|
2292
|
+
after: { type: "string" },
|
|
2293
|
+
json: { type: "boolean" }
|
|
2294
|
+
};
|
|
2295
|
+
async function emailsCommand(ctx, out, args) {
|
|
2296
|
+
const [sub, ...rest] = args;
|
|
2297
|
+
if (sub === void 0 || sub === "--help" || sub === "-h" || sub === "help") {
|
|
2298
|
+
out.out(EMAILS_USAGE);
|
|
2299
|
+
return sub === void 0 ? 2 : 0;
|
|
2300
|
+
}
|
|
2301
|
+
if (sub !== "list") throw new UsageError(`unknown subcommand: emails ${sub} (see: steward emails --help)`);
|
|
2302
|
+
const { values, positionals } = parse(rest, LIST_OPTIONS$2, "emails");
|
|
2303
|
+
if (values.help) {
|
|
2304
|
+
out.out(EMAILS_USAGE);
|
|
2305
|
+
return 0;
|
|
2306
|
+
}
|
|
2307
|
+
expectPositionals(positionals, 0, 0, "emails");
|
|
2308
|
+
const limit = limitOption(values.limit);
|
|
2309
|
+
const filter = definedOnly({
|
|
2310
|
+
account: accountOption(values.account),
|
|
2311
|
+
status: checkedOption(values.status, EmailMessageStatusSchema, "--status: pending, sent, skipped or dead"),
|
|
2312
|
+
template: checkedOption(values.template, EmailTemplateSchema, `--template: one of ${EmailTemplateSchema.options.join(", ")}`),
|
|
2313
|
+
limit,
|
|
2314
|
+
after: textOption(values.after, "--after", EMAIL_ID_MAX)
|
|
2315
|
+
});
|
|
2316
|
+
const target = requireAdminTarget(await resolveEnv(ctx));
|
|
2317
|
+
out.err(connectionLine(target));
|
|
2318
|
+
const { items, hasMore } = await callSteward(target, () => clientFor(ctx, target).admin.emails.list(filter));
|
|
2319
|
+
if (values.json) out.out(JSON.stringify(items, null, 2));
|
|
2320
|
+
else if (items.length === 0) out.out("no emails");
|
|
2321
|
+
else {
|
|
2322
|
+
const rows = [[
|
|
2323
|
+
"CREATED",
|
|
2324
|
+
"TEMPLATE",
|
|
2325
|
+
"STATUS",
|
|
2326
|
+
"ACCOUNT",
|
|
2327
|
+
"ATTEMPTS",
|
|
2328
|
+
"ERROR",
|
|
2329
|
+
"ID"
|
|
2330
|
+
]];
|
|
2331
|
+
for (const e of items) rows.push([
|
|
2332
|
+
e.createdAt,
|
|
2333
|
+
e.template,
|
|
2334
|
+
e.status,
|
|
2335
|
+
e.accountRef,
|
|
2336
|
+
String(e.attempts),
|
|
2337
|
+
e.lastError ?? "-",
|
|
2338
|
+
e.id
|
|
2339
|
+
]);
|
|
2340
|
+
for (const line of table(rows)) out.out(line);
|
|
2341
|
+
}
|
|
2342
|
+
const last = items.at(-1);
|
|
2343
|
+
if (hasMore && last !== void 0) out.err(nextPageLine("emails", limit, last.id));
|
|
2344
|
+
return 0;
|
|
2345
|
+
}
|
|
2175
2346
|
// src/commands/events.ts
|
|
2176
2347
|
const EVENTS_USAGE = `Usage:
|
|
2177
2348
|
steward events send <ref> <name> [--meta key=value]… [--external-id <id>]
|
|
2178
2349
|
[--timestamp <iso>] [--json]
|
|
2350
|
+
steward events list [--account <ref>] [--type <type>] [--delivery pending|delivered|dead|failed]
|
|
2351
|
+
[--limit <n>] [--after <event id>] [--json]
|
|
2179
2352
|
steward events redeliver <eventId> [<eventId>…]
|
|
2180
2353
|
|
|
2181
2354
|
Sends one event for account <ref> (POST /v1/events/ingest), e.g. to try a meter locally.
|
|
@@ -2201,7 +2374,35 @@ Exit code 1: the event was rejected (unknown or deleted account, timestamp out o
|
|
|
2201
2374
|
redeliver (admin; STEWARD_ADMIN_URL + STEWARD_ADMIN_API_KEY): requeues every delivery of a
|
|
2202
2375
|
webhook event (evt_…; dead ones included) with attempts reset, after the receiver's problem is
|
|
2203
2376
|
fixed. The dispatcher sends it on its next tick; an account's older events go first. When only
|
|
2204
|
-
the current state matters, the product calls POST /v1/accounts/:ref/resync instead
|
|
2377
|
+
the current state matters, the product calls POST /v1/accounts/:ref/resync instead.
|
|
2378
|
+
|
|
2379
|
+
list (admin; STEWARD_ADMIN_URL + STEWARD_ADMIN_API_KEY): the webhook events steward wrote for
|
|
2380
|
+
the product, newest first, one line per event (GET /v1/admin/events). DELIVERIES has one entry
|
|
2381
|
+
per endpoint, in endpoint order: the status, the attempts so far and the last error code
|
|
2382
|
+
(http_<status>, timeout, network_error, endpoint_inactive, url_not_allowed), e.g.
|
|
2383
|
+
"dead 8× http_500"; "-" when the product had no active endpoint. --json adds each endpoint's
|
|
2384
|
+
address, the last HTTP status and the next attempt time. The payload is not listed: read the
|
|
2385
|
+
account's state with steward accounts get <ref>.
|
|
2386
|
+
|
|
2387
|
+
--account <ref> one account's events (an unknown ref is account_not_found)
|
|
2388
|
+
--type <type> one event type, e.g. account.state_changed
|
|
2389
|
+
--delivery <d> events with a delivery that is pending, delivered or dead; failed: dead, or
|
|
2390
|
+
pending after a failed attempt (being retried)
|
|
2391
|
+
--limit <n> 1–${ADMIN_LIST_MAX_LIMIT}, default ${ADMIN_LIST_DEFAULT_LIMIT}; a cut list says so on stderr with the --after value
|
|
2392
|
+
(the last ID) of the next page
|
|
2393
|
+
--json print the items as JSON
|
|
2394
|
+
|
|
2395
|
+
A failed event (list --delivery failed) is sent again with steward events redeliver <id> once
|
|
2396
|
+
the receiver's problem is fixed.`;
|
|
2397
|
+
const LIST_OPTIONS$1 = {
|
|
2398
|
+
...HELP_OPTION,
|
|
2399
|
+
account: { type: "string" },
|
|
2400
|
+
type: { type: "string" },
|
|
2401
|
+
delivery: { type: "string" },
|
|
2402
|
+
limit: { type: "string" },
|
|
2403
|
+
after: { type: "string" },
|
|
2404
|
+
json: { type: "boolean" }
|
|
2405
|
+
};
|
|
2205
2406
|
const SEND_OPTIONS = {
|
|
2206
2407
|
...HELP_OPTION,
|
|
2207
2408
|
meta: {
|
|
@@ -2245,6 +2446,7 @@ async function eventsCommand(ctx, out, args) {
|
|
|
2245
2446
|
return sub === void 0 ? 2 : 0;
|
|
2246
2447
|
}
|
|
2247
2448
|
if (sub === "redeliver") return redeliverCommand(ctx, out, rest);
|
|
2449
|
+
if (sub === "list") return listCommand(ctx, out, rest);
|
|
2248
2450
|
if (sub !== "send") throw new UsageError(`unknown subcommand: events ${sub} (see: steward events --help)`);
|
|
2249
2451
|
const { values, positionals } = parse(rest, SEND_OPTIONS, "events");
|
|
2250
2452
|
if (values.help) {
|
|
@@ -2298,6 +2500,51 @@ async function redeliverCommand(ctx, out, args) {
|
|
|
2298
2500
|
}
|
|
2299
2501
|
return 0;
|
|
2300
2502
|
}
|
|
2503
|
+
/** One delivery in a table cell: `delivered 1×`, `dead 8× http_500`. */
|
|
2504
|
+
function deliveryText(delivery) {
|
|
2505
|
+
return `${delivery.status} ${delivery.attempts}×${delivery.lastError !== null ? ` ${delivery.lastError}` : ""}`;
|
|
2506
|
+
}
|
|
2507
|
+
async function listCommand(ctx, out, args) {
|
|
2508
|
+
const { values, positionals } = parse(args, LIST_OPTIONS$1, "events");
|
|
2509
|
+
if (values.help) {
|
|
2510
|
+
out.out(EVENTS_USAGE);
|
|
2511
|
+
return 0;
|
|
2512
|
+
}
|
|
2513
|
+
expectPositionals(positionals, 0, 0, "events");
|
|
2514
|
+
const limit = limitOption(values.limit);
|
|
2515
|
+
const filter = definedOnly({
|
|
2516
|
+
account: accountOption(values.account),
|
|
2517
|
+
type: textOption(values.type, "--type", AUDIT_LIST_FILTER_MAX),
|
|
2518
|
+
delivery: checkedOption(values.delivery, WebhookEventDeliveryFilterSchema, "--delivery: pending, delivered, dead or failed"),
|
|
2519
|
+
limit,
|
|
2520
|
+
after: checkedOption(values.after, EventIdSchema, "--after: an event id (evt_…)")
|
|
2521
|
+
});
|
|
2522
|
+
const target = requireAdminTarget(await resolveEnv(ctx));
|
|
2523
|
+
out.err(connectionLine(target));
|
|
2524
|
+
const { items, hasMore } = await callSteward(target, () => clientFor(ctx, target).admin.events.list(filter));
|
|
2525
|
+
if (values.json) out.out(JSON.stringify(items, null, 2));
|
|
2526
|
+
else if (items.length === 0) out.out("no events");
|
|
2527
|
+
else {
|
|
2528
|
+
const rows = [[
|
|
2529
|
+
"CREATED",
|
|
2530
|
+
"TYPE",
|
|
2531
|
+
"ACCOUNT",
|
|
2532
|
+
"DELIVERIES",
|
|
2533
|
+
"ID"
|
|
2534
|
+
]];
|
|
2535
|
+
for (const e of items) rows.push([
|
|
2536
|
+
e.createdAt,
|
|
2537
|
+
e.type,
|
|
2538
|
+
e.accountRef ?? "-",
|
|
2539
|
+
e.deliveries.map(deliveryText).join(", ") || "-",
|
|
2540
|
+
e.id
|
|
2541
|
+
]);
|
|
2542
|
+
for (const line of table(rows)) out.out(line);
|
|
2543
|
+
}
|
|
2544
|
+
const last = items.at(-1);
|
|
2545
|
+
if (hasMore && last !== void 0) out.err(nextPageLine("events", limit, last.id));
|
|
2546
|
+
return 0;
|
|
2547
|
+
}
|
|
2301
2548
|
// src/commands/grants.ts
|
|
2302
2549
|
const GRANTS_USAGE = `Usage:
|
|
2303
2550
|
steward grants list [--plan <code>] [--subscription none|live|any] [--limit <n>]
|
|
@@ -2380,7 +2627,8 @@ async function grantsCommand(ctx, out, args) {
|
|
|
2380
2627
|
// src/commands/invoices.ts
|
|
2381
2628
|
const INVOICES_USAGE = `Usage:
|
|
2382
2629
|
steward invoices list [--status draft|issued|void|all] [--payment-status <status>]
|
|
2383
|
-
[--from <iso>] [--to <iso>] [--limit <n>] [--
|
|
2630
|
+
[--from <iso>] [--to <iso>] [--limit <n>] [--after <invoice id>]
|
|
2631
|
+
[--json | --csv]
|
|
2384
2632
|
steward invoices issue <id> --number <number> [--external-ref <ref>] [--issued-at <iso>]
|
|
2385
2633
|
[--document <file.pdf>] [--yes] [--json]
|
|
2386
2634
|
|
|
@@ -2390,7 +2638,8 @@ list: the product's invoices, oldest first (GET /v1/admin/invoices). draft (defa
|
|
|
2390
2638
|
not issued yet, i.e. with no number of the external system; issued: the ones that have it; all:
|
|
2391
2639
|
every status. --payment-status narrows it (unpaid, paid, …). --from (inclusive) and --to
|
|
2392
2640
|
(exclusive), ISO-8601 with an offset, keep the invoices written in that window. --limit: 1–500,
|
|
2393
|
-
default 100; a cut list says so on stderr
|
|
2641
|
+
default 100; a cut list says so on stderr with the --after value (the last invoice id) of the
|
|
2642
|
+
next page.
|
|
2394
2643
|
|
|
2395
2644
|
--csv is the export for an accounting system that issues the invoices (one row per invoice, a
|
|
2396
2645
|
header row first): the invoice, its amounts in minor units, the tax decision (treatment, reason,
|
|
@@ -2422,6 +2671,7 @@ async function invoicesCommand(ctx, out, args) {
|
|
|
2422
2671
|
from: { type: "string" },
|
|
2423
2672
|
to: { type: "string" },
|
|
2424
2673
|
limit: { type: "string" },
|
|
2674
|
+
after: { type: "string" },
|
|
2425
2675
|
json: { type: "boolean" },
|
|
2426
2676
|
csv: { type: "boolean" }
|
|
2427
2677
|
}, "invoices");
|
|
@@ -2436,12 +2686,14 @@ async function invoicesCommand(ctx, out, args) {
|
|
|
2436
2686
|
const paymentStatus = InvoicePaymentStatusSchema.optional().safeParse(values["payment-status"]);
|
|
2437
2687
|
if (!paymentStatus.success) throw new UsageError(`--payment-status: one of ${InvoicePaymentStatusSchema.options.join(", ")}`);
|
|
2438
2688
|
const limit = values.limit !== void 0 ? parsePositiveInt(values.limit, "--limit", { max: 500 }) : void 0;
|
|
2689
|
+
if (values.after !== void 0 && !IdSchema.safeParse(values.after).success) throw new UsageError("--after: an invoice id");
|
|
2439
2690
|
const filter = {
|
|
2440
2691
|
...status !== void 0 ? { status } : {},
|
|
2441
2692
|
...paymentStatus.data !== void 0 ? { paymentStatus: paymentStatus.data } : {},
|
|
2442
2693
|
...values.from !== void 0 ? { from: values.from } : {},
|
|
2443
2694
|
...values.to !== void 0 ? { to: values.to } : {},
|
|
2444
|
-
...limit !== void 0 ? { limit } : {}
|
|
2695
|
+
...limit !== void 0 ? { limit } : {},
|
|
2696
|
+
...values.after !== void 0 ? { after: values.after } : {}
|
|
2445
2697
|
};
|
|
2446
2698
|
const target = requireAdminTarget(await resolveEnv(ctx));
|
|
2447
2699
|
out.err(connectionLine(target));
|
|
@@ -2472,7 +2724,8 @@ async function invoicesCommand(ctx, out, args) {
|
|
|
2472
2724
|
]);
|
|
2473
2725
|
for (const line of table(rows)) out.out(line);
|
|
2474
2726
|
}
|
|
2475
|
-
|
|
2727
|
+
const last = items.at(-1);
|
|
2728
|
+
if (hasMore && last !== void 0) out.err(`more invoices than the ${limit ?? 100} listed (--limit, at most 500); next page: --after ${last.id}`);
|
|
2476
2729
|
return 0;
|
|
2477
2730
|
}
|
|
2478
2731
|
if (sub === "issue") {
|
|
@@ -2746,6 +2999,103 @@ function help$1(out) {
|
|
|
2746
2999
|
out.out(KEYS_USAGE);
|
|
2747
3000
|
return 0;
|
|
2748
3001
|
}
|
|
3002
|
+
// src/commands/payments.ts
|
|
3003
|
+
const PAYMENTS_USAGE = `Usage:
|
|
3004
|
+
steward payments list [--account <ref>] [--method card|bank_transfer] [--disputed any|open|ever]
|
|
3005
|
+
[--from <iso>] [--to <iso>] [--limit <n>] [--after <id>] [--json]
|
|
3006
|
+
|
|
3007
|
+
The product's collected payments, newest collection first, one line per payment
|
|
3008
|
+
(GET /v1/admin/payments): when, the account, the method, the amount, what was refunded at the
|
|
3009
|
+
provider and the dispute (chargeback), if any. Only successful payments are recorded, so a
|
|
3010
|
+
failed charge is not listed (steward invoices list --status all --payment-status unpaid shows
|
|
3011
|
+
what is unpaid). A bank transfer received in another currency also shows what reached the bank;
|
|
3012
|
+
--json adds the rate entered.
|
|
3013
|
+
|
|
3014
|
+
--account <ref> one account's payments (an unknown ref is account_not_found)
|
|
3015
|
+
--method <method> card or bank_transfer
|
|
3016
|
+
--disputed <d> any (default); open: a dispute that is not closed yet; ever: disputed at some
|
|
3017
|
+
point. DISPUTE shows the provider's status and whether it is open or closed.
|
|
3018
|
+
--from <iso> collected at or after (inclusive); ISO-8601 with an offset
|
|
3019
|
+
--to <iso> collected before (exclusive); ISO-8601 with an offset
|
|
3020
|
+
--limit <n> 1–${ADMIN_LIST_MAX_LIMIT}, default ${ADMIN_LIST_DEFAULT_LIMIT}; a cut list says so on stderr with the --after value
|
|
3021
|
+
(the last ID) of the next page
|
|
3022
|
+
--json print the items as JSON
|
|
3023
|
+
|
|
3024
|
+
Connection: STEWARD_ADMIN_URL + STEWARD_ADMIN_API_KEY (environment, otherwise ./.env.local).`;
|
|
3025
|
+
const LIST_OPTIONS = {
|
|
3026
|
+
...HELP_OPTION,
|
|
3027
|
+
account: { type: "string" },
|
|
3028
|
+
method: { type: "string" },
|
|
3029
|
+
disputed: { type: "string" },
|
|
3030
|
+
from: { type: "string" },
|
|
3031
|
+
to: { type: "string" },
|
|
3032
|
+
limit: { type: "string" },
|
|
3033
|
+
after: { type: "string" },
|
|
3034
|
+
json: { type: "boolean" }
|
|
3035
|
+
};
|
|
3036
|
+
/** The amount, with what reached the bank when a transfer came in another currency. */
|
|
3037
|
+
function paymentAmountText(p) {
|
|
3038
|
+
const amount = formatMinor(p.amountMinor, p.currency);
|
|
3039
|
+
if (p.receivedAmountMinor === void 0 || p.receivedCurrency === void 0) return amount;
|
|
3040
|
+
return `${amount} (received ${formatMinor(p.receivedAmountMinor, p.receivedCurrency)})`;
|
|
3041
|
+
}
|
|
3042
|
+
/** `-` (never disputed), or the provider's dispute status and whether it is still open. */
|
|
3043
|
+
function disputeText(p) {
|
|
3044
|
+
if (p.dispute === null) return "-";
|
|
3045
|
+
return `${p.dispute.status ?? "disputed"} (${p.dispute.closedAt === null ? "open" : "closed"})`;
|
|
3046
|
+
}
|
|
3047
|
+
async function paymentsCommand(ctx, out, args) {
|
|
3048
|
+
const [sub, ...rest] = args;
|
|
3049
|
+
if (sub === void 0 || sub === "--help" || sub === "-h" || sub === "help") {
|
|
3050
|
+
out.out(PAYMENTS_USAGE);
|
|
3051
|
+
return sub === void 0 ? 2 : 0;
|
|
3052
|
+
}
|
|
3053
|
+
if (sub !== "list") throw new UsageError(`unknown subcommand: payments ${sub} (see: steward payments --help)`);
|
|
3054
|
+
const { values, positionals } = parse(rest, LIST_OPTIONS, "payments");
|
|
3055
|
+
if (values.help) {
|
|
3056
|
+
out.out(PAYMENTS_USAGE);
|
|
3057
|
+
return 0;
|
|
3058
|
+
}
|
|
3059
|
+
expectPositionals(positionals, 0, 0, "payments");
|
|
3060
|
+
const limit = limitOption(values.limit);
|
|
3061
|
+
const filter = definedOnly({
|
|
3062
|
+
account: accountOption(values.account),
|
|
3063
|
+
method: checkedOption(values.method, PaymentMethodSchema, "--method: card or bank_transfer"),
|
|
3064
|
+
disputed: checkedOption(values.disputed, PaymentListDisputedFilterSchema, "--disputed: any, open or ever"),
|
|
3065
|
+
...periodOptions(values),
|
|
3066
|
+
limit,
|
|
3067
|
+
after: checkedOption(values.after, IdSchema, "--after: a payment id")
|
|
3068
|
+
});
|
|
3069
|
+
const target = requireAdminTarget(await resolveEnv(ctx));
|
|
3070
|
+
out.err(connectionLine(target));
|
|
3071
|
+
const { items, hasMore } = await callSteward(target, () => clientFor(ctx, target).admin.payments.list(filter));
|
|
3072
|
+
if (values.json) out.out(JSON.stringify(items, null, 2));
|
|
3073
|
+
else if (items.length === 0) out.out("no payments");
|
|
3074
|
+
else {
|
|
3075
|
+
const rows = [[
|
|
3076
|
+
"COLLECTED",
|
|
3077
|
+
"ACCOUNT",
|
|
3078
|
+
"METHOD",
|
|
3079
|
+
"AMOUNT",
|
|
3080
|
+
"REFUNDED",
|
|
3081
|
+
"DISPUTE",
|
|
3082
|
+
"ID"
|
|
3083
|
+
]];
|
|
3084
|
+
for (const p of items) rows.push([
|
|
3085
|
+
p.occurredAt,
|
|
3086
|
+
p.accountRef,
|
|
3087
|
+
p.method,
|
|
3088
|
+
paymentAmountText(p),
|
|
3089
|
+
p.refundedMinor > 0 ? formatMinor(p.refundedMinor, p.currency) : "-",
|
|
3090
|
+
disputeText(p),
|
|
3091
|
+
p.id
|
|
3092
|
+
]);
|
|
3093
|
+
for (const line of table(rows)) out.out(line);
|
|
3094
|
+
}
|
|
3095
|
+
const last = items.at(-1);
|
|
3096
|
+
if (hasMore && last !== void 0) out.err(nextPageLine("payments", limit, last.id));
|
|
3097
|
+
return 0;
|
|
3098
|
+
}
|
|
2749
3099
|
// src/commands/reprice.ts
|
|
2750
3100
|
const REPRICE_USAGE = `Usage: steward reprice --plan <code> --notice-days <n> [--dry-run] [--yes] [--json]
|
|
2751
3101
|
|
|
@@ -2841,7 +3191,7 @@ const SETTINGS_USAGE = `Usage:
|
|
|
2841
3191
|
[--branding <json>] [--default-locale tr|en] [--display-time-zone <iana>]
|
|
2842
3192
|
[--default-country <XX>]
|
|
2843
3193
|
[--checkout-ttl <minutes>] [--portal-ttl <minutes>]
|
|
2844
|
-
[--extra-return-origins <a,b>] [--emails <json>]
|
|
3194
|
+
[--extra-return-origins <a,b>] [--public-url <url>] [--emails <json>]
|
|
2845
3195
|
[--billing-payment-due-days <1-60>] [--billing-min-invoice-minor <n>]
|
|
2846
3196
|
[--billing-allow-multiple-subscriptions true|false]
|
|
2847
3197
|
[--billing-renewal-notice-intervals <year,month>] [--billing-renewal-notice-days <1-90>]
|
|
@@ -2857,6 +3207,9 @@ Product settings (GET/PATCH /v1/admin/settings). A field not given is unchanged;
|
|
|
2857
3207
|
empty value (--privacy-url "") clears the field, --branding null clears the branding,
|
|
2858
3208
|
--branding '{"name":"Acme","supportEmail":"support@acme.com"}' merges shallowly (clear a
|
|
2859
3209
|
field with null). --extra-return-origins "" empties the list.
|
|
3210
|
+
--public-url puts the product's hosted links (checkout, portal, pay pages, e-mailed pay links)
|
|
3211
|
+
on another address of the same steward, e.g. a second brand's domain; steward accepts only an
|
|
3212
|
+
address its deployment serves (STEWARD_EXTRA_PUBLIC_URLS). "" restores the deployment's address.
|
|
2860
3213
|
--emails '{"billingPath":"/{LOCALE}/billing","templates":{"invoice_issued":{"enabled":false}}}'
|
|
2861
3214
|
sets billing emails (sender: from.name, from.address; templates merge per
|
|
2862
3215
|
template, null resets a field or template; --emails null resets all).
|
|
@@ -2914,6 +3267,7 @@ const SET_OPTIONS = {
|
|
|
2914
3267
|
"checkout-ttl": { type: "string" },
|
|
2915
3268
|
"portal-ttl": { type: "string" },
|
|
2916
3269
|
"extra-return-origins": { type: "string" },
|
|
3270
|
+
"public-url": { type: "string" },
|
|
2917
3271
|
emails: { type: "string" },
|
|
2918
3272
|
"billing-payment-due-days": { type: "string" },
|
|
2919
3273
|
"billing-min-invoice-minor": { type: "string" },
|
|
@@ -2988,6 +3342,7 @@ function buildSettingsPatch(values) {
|
|
|
2988
3342
|
if (values["checkout-ttl"] !== void 0) patch.checkoutTtlMinutes = parsePositiveInt(values["checkout-ttl"], "--checkout-ttl");
|
|
2989
3343
|
if (values["portal-ttl"] !== void 0) patch.portalTtlMinutes = parsePositiveInt(values["portal-ttl"], "--portal-ttl");
|
|
2990
3344
|
if (values["extra-return-origins"] !== void 0) patch.extraReturnOrigins = parseList(values["extra-return-origins"]);
|
|
3345
|
+
if (values["public-url"] !== void 0) patch.publicUrl = orNull(values["public-url"]);
|
|
2991
3346
|
const billing = {};
|
|
2992
3347
|
const dueDays = values["billing-payment-due-days"];
|
|
2993
3348
|
if (dueDays !== void 0) billing.paymentDueDays = dueDays.trim() === "" ? null : parsePositiveInt(dueDays, "--billing-payment-due-days", { max: 60 });
|
|
@@ -3321,7 +3676,7 @@ function help(out) {
|
|
|
3321
3676
|
return 0;
|
|
3322
3677
|
}
|
|
3323
3678
|
// src/main.ts
|
|
3324
|
-
const CLI_VERSION = "0.
|
|
3679
|
+
const CLI_VERSION = "0.15.0";
|
|
3325
3680
|
const USAGE = `steward — Steward CLI (@stewardhq/cli ${CLI_VERSION})
|
|
3326
3681
|
|
|
3327
3682
|
Usage: steward <command> [options]
|
|
@@ -3340,17 +3695,21 @@ Commands:
|
|
|
3340
3695
|
invoices list | issue invoices not issued yet; write the external invoice number
|
|
3341
3696
|
grants list active grants; --subscription none: paying for nothing
|
|
3342
3697
|
credits adjust <ref> <meter> --units=<n> credit entry, negative = adjustment
|
|
3343
|
-
accounts get | metadata set | unset
|
|
3698
|
+
accounts get | list | metadata set | unset read or list accounts; set or remove metadata keys
|
|
3344
3699
|
meters get | recompute | close-periods an account's meters; metering repairs (admin)
|
|
3345
|
-
events send | redeliver
|
|
3700
|
+
events send | list | redeliver send one event; list or redeliver webhook events (admin)
|
|
3701
|
+
audit list the product's audit trail: who changed what (admin)
|
|
3702
|
+
emails list billing emails steward queued; never the recipients (admin)
|
|
3703
|
+
payments list collected payments with refunds and disputes (admin)
|
|
3346
3704
|
tax thresholds list | set | delete tax registration thresholds and their counters
|
|
3347
3705
|
tax sales [--from] [--to] [--csv] paid sales per month and buyer country (admin)
|
|
3348
3706
|
|
|
3349
3707
|
Connection: admin commands use STEWARD_ADMIN_URL + STEWARD_ADMIN_API_KEY; doctor,
|
|
3350
|
-
accounts, meters and events use STEWARD_URL + STEWARD_API_KEY (or the
|
|
3351
|
-
one of these four variables is in the environment, all of them (and
|
|
3352
|
-
the environment and ./.env.local is not read at all; otherwise from
|
|
3353
|
-
in use is written to stderr (connection: …). Changes send
|
|
3708
|
+
accounts get|metadata, meters get and events send use STEWARD_URL + STEWARD_API_KEY (or the
|
|
3709
|
+
admin pair). If even one of these four variables is in the environment, all of them (and
|
|
3710
|
+
APP_URL) are read from the environment and ./.env.local is not read at all; otherwise from
|
|
3711
|
+
./.env.local. The source in use is written to stderr (connection: …). Changes send
|
|
3712
|
+
X-Actor-Ref operator:<user>.
|
|
3354
3713
|
The CLI never writes secrets to the terminal and never calls kubectl.
|
|
3355
3714
|
|
|
3356
3715
|
Details: steward <command> --help`;
|
|
@@ -3364,6 +3723,9 @@ const COMMANDS = {
|
|
|
3364
3723
|
accounts: accountsCommand,
|
|
3365
3724
|
meters: metersCommand,
|
|
3366
3725
|
events: eventsCommand,
|
|
3726
|
+
audit: auditCommand,
|
|
3727
|
+
emails: emailsCommand,
|
|
3728
|
+
payments: paymentsCommand,
|
|
3367
3729
|
keys: keysCommand,
|
|
3368
3730
|
dunning: dunningCommand,
|
|
3369
3731
|
reprice: repriceCommand,
|