@velaro/cli 1.4.243 → 1.4.245

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.
@@ -1,184 +0,0 @@
1
- // velaro billing-automation — review-hold and dry-run switches for invoice emails and charges
2
- // (BillingAutomationController, /api/BillingAutomation). Staff only.
3
- import { request } from '../api.js';
4
-
5
- const MODES = ['auto', 'review', 'dry_run'];
6
- const GATES = ['send', 'charge', 'both'];
7
-
8
- function money(cents) {
9
- if (cents == null) return '';
10
- return `$${(cents / 100).toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`;
11
- }
12
-
13
- function fail(message) {
14
- console.error(message);
15
- process.exit(1);
16
- }
17
-
18
- async function listRules() {
19
- const rules = await request('GET', '/api/BillingAutomation/rules');
20
- if (!rules.length) {
21
- console.log('No rules. With no rules, every invoice runs automatically.');
22
- return;
23
- }
24
- for (const r of rules) {
25
- const scope = [
26
- r.accountType ? `account=${r.accountType}` : null,
27
- r.paymentMethod ? `method=${r.paymentMethod}` : null,
28
- r.minAmountCents != null ? `from=${money(r.minAmountCents)}` : null,
29
- r.maxAmountCents != null ? `to=${money(r.maxAmountCents)}` : null,
30
- ].filter(Boolean).join(' ') || 'global default';
31
- console.log(`#${r.id} ${r.enabled ? 'on ' : 'off'} ${r.appliesTo.padEnd(6)} ${r.mode.padEnd(8)} ${scope} ${r.name}`);
32
- }
33
- }
34
-
35
- async function setGlobal(appliesTo, mode) {
36
- if (!GATES.includes(appliesTo)) fail(`appliesTo must be one of: ${GATES.join(', ')}`);
37
- if (!MODES.includes(mode)) fail(`mode must be one of: ${MODES.join(', ')}`);
38
- await request('PUT', `/api/BillingAutomation/global/${appliesTo}`, { mode }); // controller action: SaveGlobal
39
- console.log(`Global ${appliesTo} set to ${mode}.`);
40
- }
41
-
42
- async function addRule(args) {
43
- if (!args.name) fail('Usage: velaro billing-automation rule-add --name "Review big ACH" --applies-to charge --mode review [--account-type enterprise] [--min-cents 100000] [--max-cents 500000] [--payment-method ach]');
44
- const body = {
45
- name: args.name,
46
- appliesTo: args.appliesTo ?? 'both',
47
- mode: args.mode,
48
- accountType: args.accountType ?? null,
49
- minAmountCents: args.minCents ?? null,
50
- maxAmountCents: args.maxCents ?? null,
51
- paymentMethod: args.paymentMethod ?? null,
52
- enabled: true,
53
- };
54
- const r = await request('POST', '/api/BillingAutomation/rules', body);
55
- console.log(`Rule #${r.id} added: ${r.name} (${r.appliesTo} -> ${r.mode}).`);
56
- }
57
-
58
- async function setRuleEnabled(id, enabled) {
59
- const rules = await request('GET', '/api/BillingAutomation/rules');
60
- const rule = rules.find((r) => r.id === Number(id));
61
- if (!rule) fail(`No rule #${id}.`);
62
- await request('PUT', `/api/BillingAutomation/rules/${rule.id}`, {
63
- name: rule.name,
64
- appliesTo: rule.appliesTo,
65
- mode: rule.mode,
66
- accountType: rule.accountType,
67
- minAmountCents: rule.minAmountCents,
68
- maxAmountCents: rule.maxAmountCents,
69
- paymentMethod: rule.paymentMethod,
70
- enabled,
71
- });
72
- console.log(`Rule #${rule.id} ${enabled ? 'turned on' : 'turned off'}.`);
73
- }
74
-
75
- async function deleteRule(id) {
76
- await request('DELETE', `/api/BillingAutomation/rules/${id}`);
77
- console.log(`Rule #${id} deleted.`);
78
- }
79
-
80
- function printDecisions(rows, emptyText) {
81
- if (!rows.length) {
82
- console.log(emptyText);
83
- return;
84
- }
85
- for (const d of rows) {
86
- const label = d.outcome === 'dry_run' ? 'WOULD' : 'HELD ';
87
- const state = d.resolution ? ` [${d.resolution}]` : '';
88
- console.log(`#${d.id} ${label} ${d.action.padEnd(6)} invoice ${d.invoiceId} ${money(d.amountCents)} ${d.paymentMethod ?? '-'} ${d.createdAt}${state}`);
89
- console.log(` ${d.reason}`);
90
- }
91
- }
92
-
93
- async function queue() {
94
- printDecisions(await request('GET', '/api/BillingAutomation/decisions?status=open&take=200'), 'Nothing is waiting for review.');
95
- }
96
-
97
- async function dryRuns() {
98
- printDecisions(await request('GET', '/api/BillingAutomation/decisions?status=dry_run&take=100'), 'No dry-run entries.');
99
- }
100
-
101
- async function approve(id) {
102
- const res = await request('POST', `/api/BillingAutomation/decisions/${id}/approve`, {});
103
- console.log(`Approved #${id}. Released: ${res.released}.`);
104
- }
105
-
106
- async function dismiss(id) {
107
- await request('POST', `/api/BillingAutomation/decisions/${id}/dismiss`, {});
108
- console.log(`Dismissed #${id}. It stays on hold until approved.`);
109
- }
110
-
111
- async function setAccountType(subscriptionId, value) {
112
- const res = await request('PUT', `/api/BillingAutomation/subscription/${subscriptionId}/account-type`, { accountType: value ?? null });
113
- console.log(`Subscription ${res.id} account type: ${res.accountType ?? '(unset)'}.`);
114
- }
115
-
116
- async function notifySettings() {
117
- const all = await request('GET', '/api/BillingNotifications/settings');
118
- for (const [key, value] of Object.entries(all)) {
119
- console.log(`${key.padEnd(20)} ${value ?? '(not set: code default)'}`);
120
- }
121
- }
122
-
123
- async function notifySet(key, value) {
124
- await request('PUT', `/api/BillingNotifications/settings/${key}`, { value });
125
- console.log(`${key} set to ${value}.`);
126
- }
127
-
128
- // Only the channels you pass change. The others keep their current override (the API replaces all three).
129
- async function setReceipts(subscriptionId, args) {
130
- const sub = await request('GET', `/api/BillingSubscription/${subscriptionId}`);
131
- const res = await request('PUT', `/api/BillingNotifications/subscriptions/${subscriptionId}/receipts`, {
132
- card: args.card ?? sub.receiptCardOverride ?? null,
133
- ach: args.ach ?? sub.receiptAchOverride ?? null,
134
- other: args.other ?? sub.receiptOtherOverride ?? null,
135
- });
136
- console.log(`Subscription ${res.id} receipts: card=${res.card ?? 'inherit'} ach=${res.ach ?? 'inherit'} other=${res.other ?? 'inherit'}.`);
137
- }
138
-
139
- async function digestSendNow() {
140
- const res = await request('POST', '/api/BillingNotifications/digest/send-now', {});
141
- console.log(`Digest sent to ${res.recipients.join(', ')}: ${res.subject}`);
142
- }
143
-
144
- async function receiptsRunNow() {
145
- const res = await request('POST', '/api/BillingNotifications/receipts/run-now', {});
146
- console.log(`Receipts run: ${res.summary}`);
147
- }
148
-
149
- export const billingAutomationCommand = {
150
- command: 'billing-automation <subcommand>',
151
- describe: 'Review-hold and dry-run switches for invoice emails and charges, the review queue, and account types',
152
- builder: (yargs) =>
153
- yargs
154
- .command('rules', 'List every automation rule and global switch', {}, () => listRules())
155
- .command('global <appliesTo> <mode>', 'Set the global default: appliesTo = send | charge | both; mode = auto | review | dry_run', {}, (args) => setGlobal(args.appliesTo, args.mode))
156
- .command('rule-add', 'Add a scoped rule (--name required; filters are optional)', {
157
- name: { type: 'string' },
158
- appliesTo: { type: 'string', choices: GATES, default: 'both' },
159
- mode: { type: 'string', choices: MODES, demandOption: true },
160
- accountType: { type: 'string' },
161
- minCents: { type: 'number' },
162
- maxCents: { type: 'number' },
163
- paymentMethod: { type: 'string', choices: ['cash', 'check', 'ach', 'wire', 'card'] },
164
- }, (args) => addRule(args))
165
- .command('rule-on <id>', 'Turn a rule on', {}, (args) => setRuleEnabled(args.id, true))
166
- .command('rule-off <id>', 'Turn a rule off', {}, (args) => setRuleEnabled(args.id, false))
167
- .command('rule-delete <id>', 'Delete a rule (queue entries keep their rule name)', {}, (args) => deleteRule(args.id))
168
- .command('queue', 'Show held sends and charges waiting for review', {}, () => queue())
169
- .command('dry-runs', 'Show what the dry-run switches would have sent or charged', {}, () => dryRuns())
170
- .command('approve <id>', 'Approve a held entry and release its send or charge now', {}, (args) => approve(args.id))
171
- .command('dismiss <id>', 'Dismiss a held entry (it stays on hold, alerts stop)', {}, (args) => dismiss(args.id))
172
- .command('account-type <subscriptionId> [value]', 'Set a subscription account type that rules match on (omit value to clear)', {}, (args) => setAccountType(args.subscriptionId, args.value))
173
- .command('notify-settings', 'Show the global notification settings (receipts, invoice BCC, digest recipients)', {}, () => notifySettings())
174
- .command('digest-send-now', 'Send the billing digest now to digest.recipients (same email as the 7am run)', {}, () => digestSendNow())
175
- .command('receipts-run-now', 'Decide pending payment receipts now instead of at :05 and print the counts', {}, () => receiptsRunNow())
176
- .command('notify-set <key> <value>', 'Set a global notification setting: receipts.card|receipts.ach|receipts.other = never|send; invoices.bcc = emails (blank = none); digest.recipients = emails', {}, (args) => notifySet(args.key, args.value))
177
- .command('receipts <subscriptionId>', 'Set receipt overrides on one subscription (--card/--ach/--other = never|send). Channels you omit keep their current override.', {
178
- card: { type: 'string', choices: ['never', 'send'] },
179
- ach: { type: 'string', choices: ['never', 'send'] },
180
- other: { type: 'string', choices: ['never', 'send'] },
181
- }, (args) => setReceipts(args.subscriptionId, args))
182
- .demandCommand(1, 'Specify a subcommand: rules | global | rule-add | rule-on | rule-off | rule-delete | queue | dry-runs | approve | dismiss | account-type'),
183
- handler: () => {},
184
- };
@@ -1,64 +0,0 @@
1
- // velaro billing-email-preference — governed billing-notification email-type preferences
2
- // (BillingEmailPreferenceController). Data model + UX only — no command here sends, or can send,
3
- // a real customer email. Every type defaults OFF; see the "New feature requested by Alex"
4
- // section of project_unified_billing_system_2026_08_30.md.
5
- import { request } from '../api.js';
6
-
7
- async function listPreferences(args) {
8
- const url = args.siteId ? `/BillingEmailPreference?siteId=${args.siteId}` : '/BillingEmailPreference';
9
- const result = await request('GET', url);
10
-
11
- console.log(`\nLive today (informational — not governed here)\n${'-'.repeat(70)}`);
12
- for (const s of result.liveToday) {
13
- console.log(` ${s.displayName}`);
14
- console.log(` ${s.description}`);
15
- console.log(` source: ${s.sourceLocation}`);
16
- }
17
-
18
- console.log(`\nGoverned types${args.siteId ? ` (site ${args.siteId})` : ' (system defaults)'}\n${'-'.repeat(70)}`);
19
- for (const t of result.governed) {
20
- const reach = t.isCurrentlyReachable ? '' : ' [not built yet — no event exists to trigger this]';
21
- const setBy = args.siteId ? ` effective=${t.effective} (set by ${t.setBy})` : ` systemDefault=${t.systemDefault}`;
22
- console.log(` [${t.notificationType}] ${t.displayName}${reach}${setBy}`);
23
- }
24
- console.log('');
25
- }
26
-
27
- async function setPreference(notificationType, args) {
28
- if (!args.siteId || args.enabled == null) {
29
- console.error('Usage: velaro billing-email-preference set <notificationType> --site-id 100150 --enabled true|false');
30
- process.exit(1);
31
- }
32
- const result = await request('PUT', `/BillingEmailPreference/${notificationType}?siteId=${args.siteId}`, {
33
- isEnabled: args.enabled === 'true' || args.enabled === true,
34
- });
35
- console.log(`Site ${args.siteId} override for ${result.notificationType}: ${result.siteOverride}`);
36
- }
37
-
38
- async function resetPreference(notificationType, args) {
39
- if (!args.siteId) {
40
- console.error('Usage: velaro billing-email-preference reset <notificationType> --site-id 100150');
41
- process.exit(1);
42
- }
43
- const result = await request('DELETE', `/BillingEmailPreference/${notificationType}?siteId=${args.siteId}`);
44
- console.log(result.reset ? `Site ${args.siteId} override for ${notificationType} reset to system default.` : `No override existed for ${notificationType}.`);
45
- }
46
-
47
- export const billingEmailPreferenceCommand = {
48
- command: 'billing-email-preference <subcommand>',
49
- describe: 'View and set billing email-notification-type preferences (data model + UX only — no real email is ever sent by this command)',
50
- builder: (yargs) =>
51
- yargs
52
- .command('list', 'List live-today senders + governed types (with effective value if --site-id given)', {
53
- 'site-id': { type: 'number', desc: 'View effective value + override state for this site instead of system defaults only' },
54
- }, (args) => listPreferences(args))
55
- .command('set <notificationType>', 'Set a site-level override for one governed type', {
56
- 'site-id': { type: 'number' },
57
- enabled: { type: 'string', desc: 'true or false' },
58
- }, (args) => setPreference(args.notificationType, args))
59
- .command('reset <notificationType>', "Reset a site's override back to the system default", {
60
- 'site-id': { type: 'number' },
61
- }, (args) => resetPreference(args.notificationType, args))
62
- .demandCommand(1, 'Specify a subcommand: list | set | reset'),
63
- handler: () => {},
64
- };