@velaro/cli 1.4.120 → 1.4.121
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 +0 -19
- package/bin/velaro.js +21 -92
- package/lib/avatar-motion.test.js +1 -1
- package/lib/avatar-switch.test.js +1 -1
- package/lib/commands/agent.js +7 -58
- package/lib/commands/ai-config.js +8 -34
- package/lib/commands/index.js +18 -14
- package/lib/commands/kb.js +4 -94
- package/lib/commands/knowledge.js +2 -2
- package/lib/commands/ops-groups.js +0 -13
- package/lib/commands/safety.js +1 -1
- package/lib/commands/salesforce.js +1 -1
- package/lib/commands/sap.js +1 -1
- package/lib/commands/schedule-adherence.js +1 -1
- package/lib/commands/teams.js +1 -1
- package/lib/commands/woocommerce.js +1 -1
- package/lib/commands/workflow.js +4 -31
- package/lib/staff-optional.js +10 -0
- package/package.json +2 -2
- package/lib/cobrowse-settings.js +0 -90
- package/lib/cobrowse-settings.test.js +0 -45
- package/lib/commands/activity.js +0 -147
- package/lib/commands/acuity.js +0 -66
- package/lib/commands/ai-federation.js +0 -55
- package/lib/commands/ai-models.js +0 -203
- package/lib/commands/ai-spend.js +0 -71
- package/lib/commands/avatar.js +0 -253
- package/lib/commands/bigcommerce.js +0 -50
- package/lib/commands/calendly.js +0 -62
- package/lib/commands/cobrowse.js +0 -99
- package/lib/commands/coupon-grant.js +0 -192
- package/lib/commands/diag-groups.js +0 -108
- package/lib/commands/diagnostics.js +0 -298
- package/lib/commands/email-inbox.js +0 -110
- package/lib/commands/entitlement.js +0 -375
- package/lib/commands/image-analysis.js +0 -27
- package/lib/commands/logs-insights.js +0 -342
- package/lib/commands/logs.js +0 -1248
- package/lib/commands/migrate.js +0 -379
- package/lib/commands/migration-status.js +0 -66
- package/lib/commands/ops.js +0 -266
- package/lib/commands/parity-staff-tools.js +0 -205
- package/lib/commands/pricing.js +0 -132
- package/lib/commands/report-speed.js +0 -112
- package/lib/commands/scraper.js +0 -38
- package/lib/commands/site-provision.js +0 -68
- package/lib/commands/sitesync.js +0 -158
- package/lib/commands/skill-usage.js +0 -39
- package/lib/commands/staff.js +0 -31
- package/lib/commands/status-page.js +0 -95
- package/lib/commands/status-sla.js +0 -47
- package/lib/commands/subscription.js +0 -102
- package/lib/commands/support.js +0 -309
- package/lib/commands/tour-policy.js +0 -61
- package/lib/commands/triage.js +0 -66
- package/lib/entitlement-report-packages.test.js +0 -47
- package/lib/log-search.js +0 -252
- package/lib/log-search.test.js +0 -374
- package/lib/logs-insights.test.js +0 -146
- package/lib/messaging-routes.test.js +0 -37
- package/lib/report-speed.test.js +0 -26
- package/lib/siteUser.js +0 -35
- package/lib/siteUser.test.js +0 -45
- package/lib/skill-usage.test.js +0 -36
- package/lib/status-sla.test.js +0 -23
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
// CLI surface for per-account Stripe discount grants (velaro-admin
|
|
2
|
-
// BillingCouponGrantController). Velaro-billing-staff only, same as the REST endpoints — the API
|
|
3
|
-
// enforces the role gate, this is just a convenient front end for it.
|
|
4
|
-
//
|
|
5
|
-
// NOTE ON SCOPE: this manages Velaro's STRIPE-side discount grants. The reusable coupon-CODE
|
|
6
|
-
// catalog is a separate, pre-existing system in velaro-messaging
|
|
7
|
-
// (superadmin/billing/coupons + BillingCoupons table); use `--coupon-code` here to record which
|
|
8
|
-
// catalog code a grant corresponds to. These are deliberately not the same thing — see the
|
|
9
|
-
// StripeCouponGrant entity doc comment for the ownership boundary.
|
|
10
|
-
|
|
11
|
-
import { request } from '../api.js';
|
|
12
|
-
|
|
13
|
-
const BASE = '/BillingCouponGrant';
|
|
14
|
-
|
|
15
|
-
function money(cents) {
|
|
16
|
-
return `$${(Number(cents) / 100).toFixed(2)}`;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function amount(g) {
|
|
20
|
-
return g.amountType === 'percent' ? `${g.amountValue}%` : `${money(g.amountValue)} ${String(g.currency).toUpperCase()}`;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function duration(g) {
|
|
24
|
-
switch (g.durationKind) {
|
|
25
|
-
case 'forever': return 'forever';
|
|
26
|
-
case 'periods': return `${g.durationMonths} billing period(s)`;
|
|
27
|
-
case 'once': return 'one-time';
|
|
28
|
-
case 'trial_only': return 'trial-only (expires unused if not applied during the trial)';
|
|
29
|
-
case 'until_date': return `until ${g.expiresAtUtc}`;
|
|
30
|
-
default: return g.durationKind;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function scope(g) {
|
|
35
|
-
return g.scope === 'account' ? 'whole account' : `${g.scope}: ${g.scopeTargetPriceId}`;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// How the discount is actually enforced. Not every Velaro account is charged via Stripe —
|
|
39
|
-
// manually-invoiced and comped accounts get the discount recorded here for whoever bills them,
|
|
40
|
-
// with no Stripe call made at all.
|
|
41
|
-
function appliedVia(g) {
|
|
42
|
-
if (!g.appliedVia) return '(not applied yet)';
|
|
43
|
-
return g.appliedVia === 'manual_invoice'
|
|
44
|
-
? 'manual invoice (account is not Stripe-billed; no Stripe coupon created)'
|
|
45
|
-
: 'Stripe coupon';
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function line(g) {
|
|
49
|
-
const flag = g.isActive ? '*' : ' ';
|
|
50
|
-
return `${flag} [${g.id}] site ${g.siteId} ${amount(g).padEnd(14)} ${String(g.status).padEnd(15)} ${scope(g).padEnd(28)} ${duration(g)}`;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
async function list(args) {
|
|
54
|
-
const params = new URLSearchParams();
|
|
55
|
-
if (args.site) params.set('siteId', String(args.site));
|
|
56
|
-
if (args.all) params.set('includeTerminal', 'true');
|
|
57
|
-
const qs = params.toString();
|
|
58
|
-
|
|
59
|
-
const rows = await request('GET', qs ? `${BASE}?${qs}` : BASE);
|
|
60
|
-
if (!Array.isArray(rows) || rows.length === 0) {
|
|
61
|
-
console.log(args.all ? 'No discount grants found.' : 'No active discount grants. Use --all to include revoked/failed/expired.');
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
console.log(' ID SITE AMOUNT STATUS SCOPE DURATION');
|
|
65
|
-
rows.forEach((g) => console.log(line(g)));
|
|
66
|
-
console.log(`\n${rows.length} grant(s). "*" = active (holds the account's one-discount slot).`);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
async function get(id) {
|
|
70
|
-
const g = await request('GET', `${BASE}/${id}`);
|
|
71
|
-
console.log(`Grant #${g.id} — site ${g.siteId}`);
|
|
72
|
-
console.log(` Name: ${g.name}`);
|
|
73
|
-
console.log(` Coupon code: ${g.couponCode ?? '(none — ad-hoc grant)'}`);
|
|
74
|
-
console.log(` Amount: ${amount(g)}`);
|
|
75
|
-
console.log(` Scope: ${scope(g)}`);
|
|
76
|
-
console.log(` Duration: ${duration(g)}`);
|
|
77
|
-
console.log(` Status: ${g.status}${g.isActive ? ' (active)' : ''}`);
|
|
78
|
-
console.log(` Applied via: ${appliedVia(g)}`);
|
|
79
|
-
console.log(` Stripe coupon: ${g.stripeCouponId ?? '(not created yet)'}`);
|
|
80
|
-
console.log(` Stripe sub: ${g.stripeSubscriptionId ?? '(not resolved yet)'}`);
|
|
81
|
-
console.log(` Stripe discount: ${g.stripeDiscountId ?? '(not attached yet)'}`);
|
|
82
|
-
console.log(` Applied at: ${g.appliedAtUtc ?? '(not applied)'}`);
|
|
83
|
-
console.log(` Attempts: ${g.attemptCount}`);
|
|
84
|
-
if (g.failureReason) console.log(` Last failure: ${g.failureReason}`);
|
|
85
|
-
if (g.notes) console.log(` Notes: ${g.notes}`);
|
|
86
|
-
console.log(` Created: ${g.createdAtUtc} by ${g.createdBy}`);
|
|
87
|
-
if (g.revokedAtUtc) console.log(` Revoked: ${g.revokedAtUtc} by ${g.revokedBy}`);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function buildBody(args) {
|
|
91
|
-
const body = {};
|
|
92
|
-
if (args.site !== undefined) body.siteId = Number(args.site);
|
|
93
|
-
if (args.name !== undefined) body.name = args.name;
|
|
94
|
-
if (args['coupon-code']) body.couponCode = args['coupon-code'];
|
|
95
|
-
if (args.type !== undefined) body.amountType = args.type;
|
|
96
|
-
if (args.value !== undefined) body.amountValue = Number(args.value);
|
|
97
|
-
if (args.currency !== undefined) body.currency = args.currency;
|
|
98
|
-
if (args.scope !== undefined) body.scope = args.scope;
|
|
99
|
-
if (args['scope-price']) body.scopeTargetPriceId = args['scope-price'];
|
|
100
|
-
if (args.duration !== undefined) body.durationKind = args.duration;
|
|
101
|
-
if (args.months !== undefined) body.durationMonths = Number(args.months);
|
|
102
|
-
if (args.expires !== undefined) body.expiresAtUtc = args.expires;
|
|
103
|
-
if (args.notes !== undefined) body.notes = args.notes;
|
|
104
|
-
return body;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
async function create(args) {
|
|
108
|
-
if (!args.site || args.value === undefined) {
|
|
109
|
-
console.error('Usage: velaro coupon-grant create --site <siteId> --type percent|fixed --value <n> --duration forever|periods|once|trial_only|until_date [--months N] [--expires ISO] [--scope account|package|feature --scope-price <stripePriceId>] [--name "..."] [--coupon-code CODE] [--notes "..."]');
|
|
110
|
-
console.error(' --value is a percentage for --type percent, or WHOLE CENTS for --type fixed (5000 = $50.00).');
|
|
111
|
-
process.exit(1);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const g = await request('POST', BASE, buildBody(args));
|
|
115
|
-
console.log(`Created grant #${g.id} for site ${g.siteId}: ${amount(g)}, ${duration(g)}, ${scope(g)}.`);
|
|
116
|
-
console.log(`Status: ${g.status}. The Stripe side is attached by a background job — re-run "velaro coupon-grant get ${g.id}" in a moment to confirm it reached "applied".`);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
async function update(args) {
|
|
120
|
-
if (!args.id) {
|
|
121
|
-
console.error('Usage: velaro coupon-grant update --id <grantId> [--name ...] [--type ...] [--value ...] [--duration ...] [--months N] [--expires ISO] [--scope ...] [--scope-price ...] [--notes ...]');
|
|
122
|
-
console.error(' Only a still-pending grant can be edited. Every field is optional — omitted fields are left untouched.');
|
|
123
|
-
process.exit(1);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const body = buildBody(args);
|
|
127
|
-
delete body.siteId; // a grant never moves between accounts
|
|
128
|
-
const g = await request('PUT', `${BASE}/${args.id}`, body);
|
|
129
|
-
console.log(`Updated grant #${g.id}: ${amount(g)}, ${duration(g)}, ${scope(g)}.`);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
async function revoke(id) {
|
|
133
|
-
if (!id) {
|
|
134
|
-
console.error('Usage: velaro coupon-grant revoke <grantId>');
|
|
135
|
-
process.exit(1);
|
|
136
|
-
}
|
|
137
|
-
const g = await request('DELETE', `${BASE}/${id}`);
|
|
138
|
-
console.log(`Revoked grant #${g.id} for site ${g.siteId}. The Stripe discount has been removed and the account's discount slot is free again.`);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
async function retry(id) {
|
|
142
|
-
if (!id) {
|
|
143
|
-
console.error('Usage: velaro coupon-grant retry <grantId>');
|
|
144
|
-
process.exit(1);
|
|
145
|
-
}
|
|
146
|
-
const g = await request('POST', `${BASE}/${id}/retry`);
|
|
147
|
-
console.log(`Re-created failed grant as #${g.id} (status ${g.status}). Check back with "velaro coupon-grant get ${g.id}".`);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
export const couponGrantCommand = {
|
|
151
|
-
command: 'coupon-grant <subcommand>',
|
|
152
|
-
describe: "Manage per-account Stripe discount grants (Velaro billing staff only). One active discount per account.",
|
|
153
|
-
builder: (yargs) =>
|
|
154
|
-
yargs
|
|
155
|
-
.command('list', 'List discount grants', {
|
|
156
|
-
site: { type: 'number', describe: 'Filter to one site' },
|
|
157
|
-
all: { type: 'boolean', default: false, describe: 'Include revoked/failed/expired grants' },
|
|
158
|
-
}, (args) => list(args))
|
|
159
|
-
.command('get <id>', 'Show one grant in full', {}, (args) => get(args.id))
|
|
160
|
-
.command('create', 'Grant a discount to one account', {
|
|
161
|
-
site: { type: 'number', describe: 'Target site ID (required)' },
|
|
162
|
-
name: { type: 'string', describe: 'Staff-facing label for why this was granted' },
|
|
163
|
-
'coupon-code': { type: 'string', describe: 'Audit link to a reusable code in the messaging coupon catalog' },
|
|
164
|
-
type: { type: 'string', default: 'percent', describe: 'percent | fixed' },
|
|
165
|
-
value: { type: 'number', describe: 'Percentage, or whole CENTS when --type fixed (required)' },
|
|
166
|
-
currency: { type: 'string', default: 'usd', describe: 'Currency for a fixed amount' },
|
|
167
|
-
scope: { type: 'string', default: 'account', describe: 'account | package | feature' },
|
|
168
|
-
'scope-price': { type: 'string', describe: 'Stripe Price ID the discount is limited to (required unless scope=account)' },
|
|
169
|
-
duration: { type: 'string', default: 'once', describe: 'forever | periods | once | trial_only | until_date' },
|
|
170
|
-
months: { type: 'number', describe: 'Billing periods, when --duration periods' },
|
|
171
|
-
expires: { type: 'string', describe: 'ISO UTC cutoff, required when --duration until_date' },
|
|
172
|
-
notes: { type: 'string', describe: 'Internal note' },
|
|
173
|
-
}, (args) => create(args))
|
|
174
|
-
.command('update', 'Edit a still-pending grant (partial update)', {
|
|
175
|
-
id: { type: 'number', describe: 'Grant ID (required)' },
|
|
176
|
-
name: { type: 'string' },
|
|
177
|
-
'coupon-code': { type: 'string' },
|
|
178
|
-
type: { type: 'string' },
|
|
179
|
-
value: { type: 'number' },
|
|
180
|
-
currency: { type: 'string' },
|
|
181
|
-
scope: { type: 'string' },
|
|
182
|
-
'scope-price': { type: 'string' },
|
|
183
|
-
duration: { type: 'string' },
|
|
184
|
-
months: { type: 'number' },
|
|
185
|
-
expires: { type: 'string' },
|
|
186
|
-
notes: { type: 'string' },
|
|
187
|
-
}, (args) => update(args))
|
|
188
|
-
.command('revoke <id>', "Remove a grant's discount from Stripe and free the account's slot", {}, (args) => revoke(args.id))
|
|
189
|
-
.command('retry <id>', 'Re-attempt a failed grant', {}, (args) => retry(args.id))
|
|
190
|
-
.demandCommand(1, 'Specify a subcommand: list | get | create | update | revoke | retry'),
|
|
191
|
-
handler: () => {},
|
|
192
|
-
};
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
// MCP parity command groups: admin, apple, force-expire-site, backfill, kpi, audit-trail, code, crm, hangfire.
|
|
2
|
-
// Each subcommand calls the same REST route as the MCP tool of the same name (mcp/server.js, mcp/staff-server.js).
|
|
3
|
-
// Staff-only routes are enforced by the backend.
|
|
4
|
-
import { get, post, del, messagingGet, messagingPost } from '../api.js';
|
|
5
|
-
import { show, qs, needYes, group } from '../parity-util.js';
|
|
6
|
-
|
|
7
|
-
export const adminCommand = { command: 'admin', ...group('Velaro staff: admin API diagnostics', [
|
|
8
|
-
['startup-diagnostics', 'Recent AdminStartupDiagnostics rows (migrations, startup exceptions)',
|
|
9
|
-
(y) => y.option('context-label', { type: 'string' }).option('count', { type: 'number' }),
|
|
10
|
-
async (a) => show(await get(`/SuperAdmin/StartupDiagnostics${qs({ contextLabel: a['context-label'], count: a.count })}`))],
|
|
11
|
-
]) };
|
|
12
|
-
|
|
13
|
-
export const appleCommand = { command: 'apple', ...group('Velaro staff: Apple Messages for Business diagnostics', [
|
|
14
|
-
['health <siteId>', 'Apple Messages health for a site',
|
|
15
|
-
(y) => y.positional('siteId', { type: 'number' }),
|
|
16
|
-
async (a) => show(await messagingGet(`/SupportTools/sites/${a.siteId}/apple/health`))],
|
|
17
|
-
['test-control <siteId>', 'Send an Apple test-control action to a conversation',
|
|
18
|
-
(y) => y.positional('siteId', { type: 'number' })
|
|
19
|
-
.option('control', { type: 'string', demandOption: true, describe: 'Control name' })
|
|
20
|
-
.option('conversation-id', { type: 'number' }),
|
|
21
|
-
async (a) => show(await messagingPost(`/SupportTools/sites/${a.siteId}/apple/test-control`, { control: a.control, conversationId: a['conversation-id'] }))],
|
|
22
|
-
]) };
|
|
23
|
-
|
|
24
|
-
export const forceExpireSiteCommand = {
|
|
25
|
-
command: 'force-expire-site <siteId>',
|
|
26
|
-
describe: 'Velaro staff: force-expire a site subscription (destructive, needs --yes)',
|
|
27
|
-
builder: (y) => y.positional('siteId', { type: 'number' }).option('yes', { type: 'boolean', describe: 'Confirm' }),
|
|
28
|
-
handler: async (a) => {
|
|
29
|
-
needYes(a, `force-expire site ${a.siteId}`);
|
|
30
|
-
show(await messagingPost(`/SuperAdmin/subscription/${a.siteId}/force-expire`));
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export const backfillCommand = { command: 'backfill', ...group('Velaro staff: per-site data backfills (preview unless --apply --yes)', [
|
|
35
|
-
['types', 'List backfill types', null, async () => show(await messagingGet('/SuperAdmin/backfill-types'))],
|
|
36
|
-
['run <siteId>', 'Preview or apply a backfill for a site',
|
|
37
|
-
(y) => y.positional('siteId', { type: 'number' })
|
|
38
|
-
.option('type', { type: 'string', demandOption: true })
|
|
39
|
-
.option('from', { type: 'string', demandOption: true, describe: 'yyyy-MM-dd' })
|
|
40
|
-
.option('to', { type: 'string', demandOption: true, describe: 'yyyy-MM-dd' })
|
|
41
|
-
.option('apply', { type: 'boolean', describe: 'Write the backfill (default is a preview)' })
|
|
42
|
-
.option('yes', { type: 'boolean', describe: 'Confirm --apply' }),
|
|
43
|
-
async (a) => {
|
|
44
|
-
if (a.apply) needYes(a, 'apply a backfill');
|
|
45
|
-
show(await messagingPost(`/SuperAdmin/sites/${encodeURIComponent(a.siteId)}/backfill`, { type: a.type, from: a.from, to: a.to, apply: a.apply === true }));
|
|
46
|
-
}],
|
|
47
|
-
]) };
|
|
48
|
-
|
|
49
|
-
export const kpiCommand = { command: 'kpi', ...group('Live operations KPIs', [
|
|
50
|
-
['snapshot', 'Real-time ops snapshot: agents, queues, waits, channels, teams', null, async () => show(await get('/LiveDashboard/snapshot'))],
|
|
51
|
-
]) };
|
|
52
|
-
|
|
53
|
-
export const auditTrailCommand = { command: 'audit-trail', ...group('Audit trail of configuration changes', [
|
|
54
|
-
['list', 'List audit entries',
|
|
55
|
-
(y) => y.option('entity-type', { type: 'string' }).option('entity-id', { type: 'string' }).option('take', { type: 'number', default: 200 }),
|
|
56
|
-
async (a) => show(await get(`/AuditTrail${qs({ entityType: a['entity-type'], entityId: a['entity-id'], take: Math.min(500, a.take ?? 200) })}`))],
|
|
57
|
-
]) };
|
|
58
|
-
|
|
59
|
-
export const codeCommand = { command: 'code', ...group('Push files to a Velaro repo branch (needs GITHUB_TOKEN)', [
|
|
60
|
-
['push-files', 'Create one commit with files on dev/main/master (destructive, needs --yes)',
|
|
61
|
-
(y) => y.option('message', { type: 'string', demandOption: true })
|
|
62
|
-
.option('file', { type: 'array', demandOption: true, describe: 'repoPath=localPath, repeatable' })
|
|
63
|
-
.option('repo', { type: 'string', default: 'velaro-admin' })
|
|
64
|
-
.option('branch', { type: 'string', default: 'dev' })
|
|
65
|
-
.option('yes', { type: 'boolean' }),
|
|
66
|
-
async (a) => {
|
|
67
|
-
needYes(a, 'push a commit');
|
|
68
|
-
const token = process.env.GITHUB_TOKEN;
|
|
69
|
-
if (!token) throw new Error('GITHUB_TOKEN env var is not set.');
|
|
70
|
-
const { readFileSync } = await import('node:fs');
|
|
71
|
-
const files = a.file.map((f) => { const [p, l] = String(f).split('='); return { path: p, content: readFileSync(l || p, 'utf8') }; });
|
|
72
|
-
const REPOS = ['velaro-admin', 'velaro-messaging', 'velaro-shared', 'velaro-shared-frontend'];
|
|
73
|
-
if (!REPOS.includes(a.repo)) throw new Error(`Repo not allowed. Allowed: ${REPOS.join(', ')}`);
|
|
74
|
-
if (!['dev', 'master', 'main'].includes(a.branch)) throw new Error('Branch must be dev, master or main.');
|
|
75
|
-
const norm = (p) => p.replace(/\\/g, '/').replace(/^\.\//, '').replace(/^\//, '');
|
|
76
|
-
if (files.some((f) => norm(f.path) === '.github' || norm(f.path).startsWith('.github/'))) throw new Error('Cannot push to .github/ paths.');
|
|
77
|
-
const base = `https://api.github.com/repos/velaro/${a.repo}`;
|
|
78
|
-
const headers = { Authorization: `Bearer ${token}`, Accept: 'application/vnd.github+json', 'X-GitHub-Api-Version': '2022-11-28', 'Content-Type': 'application/json' };
|
|
79
|
-
const gh = async (path, opts = {}) => {
|
|
80
|
-
const r = await fetch(base + path, { headers, ...opts });
|
|
81
|
-
if (!r.ok) throw new Error(`GitHub API ${path} -> ${r.status}: ${await r.text()}`);
|
|
82
|
-
return r.json();
|
|
83
|
-
};
|
|
84
|
-
const head = (await gh(`/git/refs/heads/${a.branch}`)).object.sha;
|
|
85
|
-
const baseTree = (await gh(`/git/commits/${head}`)).tree.sha;
|
|
86
|
-
const tree = await Promise.all(files.map(async (f) => {
|
|
87
|
-
const b = await gh('/git/blobs', { method: 'POST', body: JSON.stringify({ content: f.content, encoding: 'utf-8' }) });
|
|
88
|
-
return { path: f.path, mode: '100644', type: 'blob', sha: b.sha };
|
|
89
|
-
}));
|
|
90
|
-
const nt = await gh('/git/trees', { method: 'POST', body: JSON.stringify({ base_tree: baseTree, tree }) });
|
|
91
|
-
const c = await gh('/git/commits', { method: 'POST', body: JSON.stringify({ message: a.message, tree: nt.sha, parents: [head] }) });
|
|
92
|
-
await gh(`/git/refs/heads/${a.branch}`, { method: 'PATCH', body: JSON.stringify({ sha: c.sha }) });
|
|
93
|
-
console.log(`Pushed to velaro/${a.repo}@${a.branch} commit ${c.sha.slice(0, 8)}\n${files.map((f) => ' ' + f.path).join('\n')}`);
|
|
94
|
-
}],
|
|
95
|
-
]) };
|
|
96
|
-
|
|
97
|
-
export const crmCommand = { command: 'crm', ...group('Velaro staff: CRM email-campaign engine audit', [
|
|
98
|
-
['email-campaign-audit', 'Row counts for the legacy CRM email-campaign tables (safe-to-retire check)', null,
|
|
99
|
-
async () => show(await messagingGet('/SuperAdmin/crm-email-campaign-audit'))],
|
|
100
|
-
]) };
|
|
101
|
-
|
|
102
|
-
export const hangfireCommand = { command: 'hangfire', ...group('Velaro staff: failed Hangfire jobs', [
|
|
103
|
-
['list-failed', 'List failed jobs', null, async () => show(await get('/DatabaseTool/FailedJobs'))],
|
|
104
|
-
['retry <id>', 'Requeue one failed job', (y) => y.positional('id', { type: 'string' }),
|
|
105
|
-
async (a) => show(await post(`/DatabaseTool/FailedJobs/${a.id}/retry`))],
|
|
106
|
-
['delete-failed <id>', 'Delete one failed job (needs --yes)', (y) => y.positional('id', { type: 'string' }).option('yes', { type: 'boolean' }),
|
|
107
|
-
async (a) => { needYes(a, `delete failed job ${a.id}`); show(await del(`/DatabaseTool/FailedJobs/${a.id}`)); }],
|
|
108
|
-
]) };
|
|
@@ -1,298 +0,0 @@
|
|
|
1
|
-
import { get as adminGet, getCredentials } from '../api.js';
|
|
2
|
-
import { readConfig, ENVS } from '../config.js';
|
|
3
|
-
|
|
4
|
-
// ── helpers ───────────────────────────────────────────────────────────────────
|
|
5
|
-
|
|
6
|
-
const RESET = '\x1b[0m';
|
|
7
|
-
const BOLD = '\x1b[1m';
|
|
8
|
-
const DIM = '\x1b[2m';
|
|
9
|
-
const CYN = '\x1b[36m';
|
|
10
|
-
const YEL = '\x1b[33m';
|
|
11
|
-
const GRN = '\x1b[32m';
|
|
12
|
-
const RED = '\x1b[31m';
|
|
13
|
-
|
|
14
|
-
function fmtDate(ts) {
|
|
15
|
-
if (!ts) return '—';
|
|
16
|
-
return new Date(ts).toLocaleString('en-US', {
|
|
17
|
-
timeZone: 'America/Los_Angeles',
|
|
18
|
-
dateStyle: 'short',
|
|
19
|
-
timeStyle: 'short',
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function trunc(str, len = 100) {
|
|
24
|
-
if (!str) return '';
|
|
25
|
-
return str.length > len ? str.slice(0, len - 1) + '…' : str;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function requireSite(argv) {
|
|
29
|
-
if (!argv.site) {
|
|
30
|
-
console.error(`\n${RED}Error:${RESET} Use --site <siteId> to specify which customer site to query.\n`);
|
|
31
|
-
process.exit(1);
|
|
32
|
-
}
|
|
33
|
-
return argv.site;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
async function getMsgBase(argv) {
|
|
37
|
-
const cfg = readConfig();
|
|
38
|
-
const env = argv.env || cfg.env || 'staging';
|
|
39
|
-
return cfg.envs?.[env]?.messagingApiBase ?? ENVS[env]?.messagingApiBase
|
|
40
|
-
?? 'https://velaro-messaging-api-staging.azurewebsites.net';
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function requireAdmin(creds) {
|
|
44
|
-
if (creds.siteId !== 1032) {
|
|
45
|
-
console.error('velaro diagnostics crm-email-campaign-audit is only available to Velaro staff (site 1032).');
|
|
46
|
-
process.exit(1);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// ── velaro diagnostics skill-logs ─────────────────────────────────────────────
|
|
51
|
-
|
|
52
|
-
const skillLogsCommand = {
|
|
53
|
-
command: 'skill-logs',
|
|
54
|
-
describe: 'Show recent AI skill invocation logs for a site',
|
|
55
|
-
builder: (y) => y
|
|
56
|
-
.option('site', {
|
|
57
|
-
alias: 's',
|
|
58
|
-
type: 'number',
|
|
59
|
-
describe: 'Site ID to query (required)',
|
|
60
|
-
})
|
|
61
|
-
.option('errors-only', {
|
|
62
|
-
type: 'boolean',
|
|
63
|
-
default: false,
|
|
64
|
-
describe: 'Show only failed skill calls',
|
|
65
|
-
})
|
|
66
|
-
.option('take', {
|
|
67
|
-
alias: 'n',
|
|
68
|
-
type: 'number',
|
|
69
|
-
default: 25,
|
|
70
|
-
describe: 'Number of entries to return (default 25)',
|
|
71
|
-
}),
|
|
72
|
-
handler: async (argv) => {
|
|
73
|
-
const siteId = requireSite(argv);
|
|
74
|
-
const qs = new URLSearchParams({
|
|
75
|
-
siteId: String(siteId),
|
|
76
|
-
errorsOnly: String(argv['errors-only']),
|
|
77
|
-
take: String(argv.take),
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
let items;
|
|
81
|
-
try {
|
|
82
|
-
items = await adminGet(`SuperAdmin/Diagnostics/skill-logs?${qs}`);
|
|
83
|
-
} catch (err) {
|
|
84
|
-
console.error(`\n${RED}Error:${RESET} ${err.message}\n`);
|
|
85
|
-
process.exit(1);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
items = Array.isArray(items?.logs) ? items.logs : [];
|
|
89
|
-
|
|
90
|
-
console.log(`\n${BOLD}── Skill Logs — Site ${siteId} ──────────────────────────────────────────${RESET}`);
|
|
91
|
-
|
|
92
|
-
if (!items.length) {
|
|
93
|
-
console.log(` ${DIM}No skill log entries found.${RESET}\n`);
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
for (const entry of items) {
|
|
98
|
-
const ts = fmtDate(entry.calledAt);
|
|
99
|
-
const tool = (entry.toolName ?? '—').padEnd(32);
|
|
100
|
-
const success = entry.success ? `${GRN}✓${RESET}` : `${RED}✗${RESET}`;
|
|
101
|
-
const duration = entry.durationMs != null ? `${entry.durationMs}ms`.padStart(7) : ' —';
|
|
102
|
-
const category = entry.category ? `${DIM}[${entry.category}]${RESET}` : '';
|
|
103
|
-
|
|
104
|
-
console.log(` ${CYN}${ts}${RESET} ${success} ${BOLD}${tool}${RESET} ${duration} ${category}`);
|
|
105
|
-
|
|
106
|
-
if (!entry.success && entry.resultPreview) {
|
|
107
|
-
console.log(` ${RED}${trunc(entry.resultPreview, 120)}${RESET}`);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
console.log();
|
|
111
|
-
},
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
// ── velaro diagnostics integration-logs ──────────────────────────────────────
|
|
115
|
-
|
|
116
|
-
const integrationLogsCommand = {
|
|
117
|
-
command: 'integration-logs',
|
|
118
|
-
describe: 'Show recent integration activity log entries for a site',
|
|
119
|
-
builder: (y) => y
|
|
120
|
-
.option('site', {
|
|
121
|
-
alias: 's',
|
|
122
|
-
type: 'number',
|
|
123
|
-
describe: 'Site ID to query (required)',
|
|
124
|
-
})
|
|
125
|
-
.option('severity', {
|
|
126
|
-
type: 'string',
|
|
127
|
-
describe: 'Filter by severity: error | warning | info',
|
|
128
|
-
choices: ['Error', 'Warning', 'Info'],
|
|
129
|
-
})
|
|
130
|
-
.option('integration', {
|
|
131
|
-
alias: 'i',
|
|
132
|
-
type: 'string',
|
|
133
|
-
describe: 'Integration slug to filter (e.g. HubSpot, Salesforce)',
|
|
134
|
-
})
|
|
135
|
-
.option('take', {
|
|
136
|
-
alias: 'n',
|
|
137
|
-
type: 'number',
|
|
138
|
-
default: 25,
|
|
139
|
-
describe: 'Number of entries to return (default 25)',
|
|
140
|
-
}),
|
|
141
|
-
handler: async (argv) => {
|
|
142
|
-
const siteId = requireSite(argv);
|
|
143
|
-
const params = { siteId: String(siteId), take: String(argv.take) };
|
|
144
|
-
if (argv.severity) params.severity = argv.severity;
|
|
145
|
-
if (argv.integration) params.integration = argv.integration;
|
|
146
|
-
const qs = new URLSearchParams(params);
|
|
147
|
-
|
|
148
|
-
let items;
|
|
149
|
-
try {
|
|
150
|
-
items = await adminGet(`SuperAdmin/Diagnostics/integration-logs?${qs}`);
|
|
151
|
-
} catch (err) {
|
|
152
|
-
console.error(`\n${RED}Error:${RESET} ${err.message}\n`);
|
|
153
|
-
process.exit(1);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
items = Array.isArray(items?.logs) ? items.logs : [];
|
|
157
|
-
|
|
158
|
-
console.log(`\n${BOLD}── Integration Logs — Site ${siteId} ────────────────────────────────────${RESET}`);
|
|
159
|
-
|
|
160
|
-
if (!items.length) {
|
|
161
|
-
console.log(` ${DIM}No integration log entries found.${RESET}\n`);
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
for (const entry of items) {
|
|
166
|
-
const ts = fmtDate(entry.createdAt);
|
|
167
|
-
const integration = (entry.integration ?? '—').padEnd(18);
|
|
168
|
-
const sevColor = entry.severity === 'Error' ? RED
|
|
169
|
-
: entry.severity === 'Warning' ? YEL
|
|
170
|
-
: DIM;
|
|
171
|
-
const sev = `${sevColor}${(entry.severity ?? 'Info').padEnd(7)}${RESET}`;
|
|
172
|
-
const msg = trunc(entry.message ?? '', 100);
|
|
173
|
-
|
|
174
|
-
console.log(` ${CYN}${ts}${RESET} ${sev} ${BOLD}${integration}${RESET} ${msg}`);
|
|
175
|
-
}
|
|
176
|
-
console.log();
|
|
177
|
-
},
|
|
178
|
-
};
|
|
179
|
-
|
|
180
|
-
// ── velaro diagnostics routing-decisions ─────────────────────────────────────
|
|
181
|
-
|
|
182
|
-
const routingDecisionsCommand = {
|
|
183
|
-
command: 'routing-decisions',
|
|
184
|
-
describe: 'Show recent smart routing decision events for a site',
|
|
185
|
-
builder: (y) => y
|
|
186
|
-
.option('site', {
|
|
187
|
-
alias: 's',
|
|
188
|
-
type: 'number',
|
|
189
|
-
describe: 'Site ID to query (required)',
|
|
190
|
-
})
|
|
191
|
-
.option('take', {
|
|
192
|
-
alias: 'n',
|
|
193
|
-
type: 'number',
|
|
194
|
-
default: 25,
|
|
195
|
-
describe: 'Number of entries to return (default 25)',
|
|
196
|
-
}),
|
|
197
|
-
handler: async (argv) => {
|
|
198
|
-
const siteId = requireSite(argv);
|
|
199
|
-
const qs = new URLSearchParams({ siteId: String(siteId), take: String(argv.take) });
|
|
200
|
-
|
|
201
|
-
let items;
|
|
202
|
-
try {
|
|
203
|
-
items = await adminGet(`SuperAdmin/Diagnostics/routing-decisions?${qs}`);
|
|
204
|
-
} catch (err) {
|
|
205
|
-
console.error(`\n${RED}Error:${RESET} ${err.message}\n`);
|
|
206
|
-
process.exit(1);
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
items = Array.isArray(items?.decisions) ? items.decisions : [];
|
|
210
|
-
|
|
211
|
-
console.log(`\n${BOLD}── Routing Decisions — Site ${siteId} ───────────────────────────────────${RESET}`);
|
|
212
|
-
|
|
213
|
-
if (!items.length) {
|
|
214
|
-
console.log(` ${DIM}No routing decision events found.${RESET}\n`);
|
|
215
|
-
return;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
for (const entry of items) {
|
|
219
|
-
const ts = fmtDate(entry.occurredAt);
|
|
220
|
-
const trigger = (entry.trigger ?? '—').padEnd(20);
|
|
221
|
-
const rule = entry.ruleName ? `${DIM}${entry.ruleName}${RESET} → ` : '';
|
|
222
|
-
const outcome = (entry.outcomeType ?? '—').padEnd(18);
|
|
223
|
-
const label = entry.outcomeLabel ? `${GRN}${entry.outcomeLabel}${RESET}` : '';
|
|
224
|
-
const agentCount = entry.agentsAvailable ?? entry.agentsOnline;
|
|
225
|
-
const agents = agentCount != null ? ` ${DIM}agents avail: ${agentCount}${RESET}` : '';
|
|
226
|
-
|
|
227
|
-
console.log(` ${CYN}${ts}${RESET} ${BOLD}${trigger}${RESET} ${rule}${outcome}${label}${agents}`);
|
|
228
|
-
}
|
|
229
|
-
console.log();
|
|
230
|
-
},
|
|
231
|
-
};
|
|
232
|
-
|
|
233
|
-
// ── velaro diagnostics crm-email-campaign-audit ──────────────────────────────
|
|
234
|
-
// Retirement-decision diagnostic for the dead/duplicate CrmEmailCampaign system
|
|
235
|
-
// (velaro-messaging's server/Velaro.Messaging.Data/Data/Crm/CrmEmailCampaign*.cs) --
|
|
236
|
-
// the question of "does it have real data or is it safe to delete" was blocked all
|
|
237
|
-
// session on not wanting to run raw SQL against staging/prod. This calls the aggregate,
|
|
238
|
-
// non-PII SuperAdmin/crm-email-campaign-audit endpoint instead. Mirrors the ai-models.js
|
|
239
|
-
// --env/requireAdmin pattern exactly.
|
|
240
|
-
|
|
241
|
-
const crmEmailCampaignAuditCommand = {
|
|
242
|
-
command: 'crm-email-campaign-audit',
|
|
243
|
-
describe: 'Aggregate, non-PII row counts for the dead CrmEmailCampaign system (Velaro staff only) -- answers the delete-vs-migrate retirement question without raw SQL',
|
|
244
|
-
builder: (y) => y
|
|
245
|
-
.option('env', { describe: 'staging or prod', type: 'string' }),
|
|
246
|
-
handler: async (argv) => {
|
|
247
|
-
const creds = await getCredentials();
|
|
248
|
-
requireAdmin(creds);
|
|
249
|
-
const msgBase = await getMsgBase(argv);
|
|
250
|
-
|
|
251
|
-
const res = await fetch(`${msgBase}/SuperAdmin/crm-email-campaign-audit`, {
|
|
252
|
-
headers: {
|
|
253
|
-
Authorization: `Bearer ${creds.velaroToken}`,
|
|
254
|
-
'X-Internal-SiteId': String(creds.siteId),
|
|
255
|
-
},
|
|
256
|
-
signal: AbortSignal.timeout(20000),
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
if (!res.ok) {
|
|
260
|
-
console.error(`HTTP ${res.status}: ${await res.text().catch(() => '')}`);
|
|
261
|
-
process.exit(1);
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
const data = await res.json();
|
|
265
|
-
const env = argv.env || readConfig().env || 'staging';
|
|
266
|
-
|
|
267
|
-
console.log(`\n${BOLD}── CrmEmailCampaign Retirement Audit (${env}) ──────────────────────${RESET}`);
|
|
268
|
-
console.log(` Total campaigns: ${data.totalCampaigns}`);
|
|
269
|
-
console.log(` Total enrollments: ${data.totalEnrollments}`);
|
|
270
|
-
console.log(` Distinct sites w/ campaigns: ${data.distinctSitesWithCampaigns}`);
|
|
271
|
-
console.log(` Oldest campaign created: ${data.oldestCampaignCreatedAt ?? '—'}`);
|
|
272
|
-
console.log(` Newest campaign created: ${data.newestCampaignCreatedAt ?? '—'}`);
|
|
273
|
-
console.log(` Oldest enrollment date: ${data.oldestEnrollmentDate ?? '—'}`);
|
|
274
|
-
console.log(` Newest enrollment date: ${data.newestEnrollmentDate ?? '—'}`);
|
|
275
|
-
console.log(` Generated at (UTC): ${data.generatedAtUtc}`);
|
|
276
|
-
|
|
277
|
-
if (data.totalCampaigns === 0 && data.totalEnrollments === 0) {
|
|
278
|
-
console.log(`\n ${GRN}Both tables are empty -- safe to delete without a data migration.${RESET}\n`);
|
|
279
|
-
} else {
|
|
280
|
-
console.log(`\n ${YEL}Real rows exist -- retirement needs a data migration into admin's EmailCampaign engine, not a plain delete.${RESET}\n`);
|
|
281
|
-
}
|
|
282
|
-
},
|
|
283
|
-
};
|
|
284
|
-
|
|
285
|
-
// ── top-level diagnostics command ─────────────────────────────────────────────
|
|
286
|
-
|
|
287
|
-
export const diagnosticsCommand = {
|
|
288
|
-
command: 'diagnostics <subcommand>',
|
|
289
|
-
describe: 'Query skill logs, integration logs, routing decisions, and staff-only audits (superadmin only)',
|
|
290
|
-
builder: (y) => y
|
|
291
|
-
.command(skillLogsCommand)
|
|
292
|
-
.command(integrationLogsCommand)
|
|
293
|
-
.command(routingDecisionsCommand)
|
|
294
|
-
.command(crmEmailCampaignAuditCommand)
|
|
295
|
-
.demandCommand(1, 'Specify a subcommand: skill-logs, integration-logs, routing-decisions, crm-email-campaign-audit')
|
|
296
|
-
.strict(),
|
|
297
|
-
handler: () => {},
|
|
298
|
-
};
|