@velaro/cli 1.4.59 → 1.4.61

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/bin/velaro.js CHANGED
@@ -75,6 +75,7 @@ import { subscriptionCommand } from '../lib/commands/subscription.js';
75
75
  import { supportCommand } from '../lib/commands/support.js';
76
76
  import { routingCommand } from '../lib/commands/routing.js';
77
77
  import { diagnosticsCommand } from '../lib/commands/diagnostics.js';
78
+ import { aiSpendCommand } from '../lib/commands/ai-spend.js';
78
79
  import { emailInboxCommand } from '../lib/commands/email-inbox.js';
79
80
  import { callbackCommand } from '../lib/commands/callback.js';
80
81
  import { caseCommand } from '../lib/commands/case.js';
@@ -173,6 +174,7 @@ await yargs(hideBin(process.argv))
173
174
  .command({ command: 'support', desc: 'Staff SupportTools actions on a site (superadmin only)', builder: supportCommand, handler: () => {} })
174
175
  .command(routingCommand)
175
176
  .command(diagnosticsCommand)
177
+ .command(aiSpendCommand)
176
178
  .command(emailInboxCommand)
177
179
  .command(callbackCommand)
178
180
  .command(caseCommand)
@@ -0,0 +1,71 @@
1
+ import { get, post } from '../api.js';
2
+
3
+ const usd = (n) => `$${Number(n ?? 0).toFixed(2)}`;
4
+
5
+ function fmtPT(ts) {
6
+ if (!ts) return '-';
7
+ return new Date(ts).toLocaleString('en-US', { timeZone: 'America/Los_Angeles', dateStyle: 'short', timeStyle: 'short' }) + ' PT';
8
+ }
9
+
10
+ const reportCommand = {
11
+ command: 'report',
12
+ describe: 'AI spend by environment (prod/staging), site, model and key source (superadmin only)',
13
+ builder: (y) => y
14
+ .option('env', { type: 'string', default: 'both', choices: ['both', 'prod', 'staging'] })
15
+ .option('days', { type: 'number', default: 7 })
16
+ .option('json', { type: 'boolean', default: false }),
17
+ handler: async (argv) => {
18
+ const to = new Date();
19
+ const from = new Date(to.getTime() - argv.days * 86400000);
20
+ const r = await get(`SuperAdmin/AiSpend/Report?env=${argv.env}&from=${encodeURIComponent(from.toISOString())}&to=${encodeURIComponent(to.toISOString())}`);
21
+ if (argv.json) { console.log(JSON.stringify(r, null, 2)); return; }
22
+ console.log(`AI spend ${fmtPT(r.from)} to ${fmtPT(r.to)} (breaker trips: not available)`);
23
+ for (const e of r.environments ?? []) {
24
+ if (!e.available) { console.log(`\n[${e.environment}] unavailable: ${e.error}`); continue; }
25
+ const c = e.current;
26
+ console.log(`\n[${e.environment}] ${usd(c.totalEstimatedCostUsd)} / ${c.totalCalls} calls (prev ${usd(e.previous?.totalEstimatedCostUsd)}), cache read ${(e.cacheReadRatio * 100).toFixed(1)}%, QA ${e.qaSharePercent}%`);
27
+ (c.bySite ?? []).slice(0, 10).forEach(s => console.log(` site ${s.siteId}: ${usd(s.estimatedCostUsd)} (${s.calls} calls)`));
28
+ (e.anomalies ?? []).forEach(a => console.log(` ANOMALY site ${a.siteId}: ${a.kind} ${a.detail}`));
29
+ }
30
+ },
31
+ };
32
+
33
+ const reconcileCommand = {
34
+ command: 'reconcile',
35
+ describe: 'Record a provider console total and compare to logged spend',
36
+ builder: (y) => y
37
+ .option('env', { type: 'string', default: 'prod', choices: ['both', 'prod', 'staging'] })
38
+ .option('days', { type: 'number', default: 7 })
39
+ .option('provider', { type: 'string', default: 'Anthropic' })
40
+ .option('key', { type: 'string', describe: 'key bucket: platform, copilot, byok (omit for provider total)' })
41
+ .option('entered', { type: 'number', demandOption: true, describe: 'console total in USD' })
42
+ .option('threshold', { type: 'number', default: 25 })
43
+ .option('notes', { type: 'string' }),
44
+ handler: async (argv) => {
45
+ const to = new Date();
46
+ const from = new Date(to.getTime() - argv.days * 86400000);
47
+ const r = await post('SuperAdmin/AiSpend/Reconciliations', {
48
+ periodStartUtc: from.toISOString(), periodEndUtc: to.toISOString(), environment: argv.env,
49
+ provider: argv.provider, keyLabel: argv.key ?? null, enteredUsd: argv.entered, thresholdUsd: argv.threshold, notes: argv.notes ?? null,
50
+ });
51
+ console.log(`logged ${usd(r.loggedUsd)} vs console ${usd(r.enteredUsd)}: gap ${usd(r.gapUsd)} (${r.gapPercent ?? 'n/a'}%)${r.unloggedSpendFlagged ? ' FLAG: unlogged spend' : ''}`);
52
+ },
53
+ };
54
+
55
+ const historyCommand = {
56
+ command: 'history',
57
+ describe: 'List saved reconciliations',
58
+ builder: (y) => y,
59
+ handler: async () => {
60
+ const rows = await get('SuperAdmin/AiSpend/Reconciliations?take=50');
61
+ for (const r of rows) console.log(`${fmtPT(r.createdUtc)} ${r.environment} ${r.provider}${r.keyLabel ? '/' + r.keyLabel : ''} logged ${usd(r.loggedUsd)} console ${usd(r.enteredUsd)} gap ${usd(r.gapUsd)}${r.unloggedSpendFlagged ? ' FLAG' : ''}`);
62
+ },
63
+ };
64
+
65
+ export const aiSpendCommand = {
66
+ command: 'ai-spend <subcommand>',
67
+ describe: 'AI spend report and provider reconciliation (superadmin only)',
68
+ builder: (y) => y.command(reportCommand).command(reconcileCommand).command(historyCommand)
69
+ .demandCommand(1, 'Specify a subcommand: report, reconcile, history').strict(),
70
+ handler: () => {},
71
+ };
@@ -54,6 +54,36 @@ async function generateHandler(argv) {
54
54
  printUrls(urls);
55
55
  }
56
56
 
57
+ // velaro netsuite m2m init|save|verify - OAuth 2.0 Client Credentials (machine-to-machine).
58
+ // Backend: NetSuiteAuthController POST NetSuite/M2M/Init | Save | Verify (velaro-messaging).
59
+ function printChecks(res) {
60
+ const checks = Array.isArray(res?.checks) ? res.checks : [];
61
+ console.log(`\n${BOLD}NetSuite M2M verification${RST}`);
62
+ for (const c of checks) {
63
+ console.log(` ${c.ok ? 'PASS' : 'FAIL'} ${c.name}${c.ok ? '' : ` - ${c.reason || c.reasonCode || 'failed'}`}`);
64
+ if (!c.ok && c.howToFix) console.log(` ${DIM}How to fix: ${c.howToFix}${RST}`);
65
+ }
66
+ console.log('');
67
+ }
68
+
69
+ async function m2mInitHandler(argv) {
70
+ const res = await messagingPost('/NetSuite/M2M/Init', { id: argv.config ?? null, company: argv.company, displayName: argv.name });
71
+ console.log(`\n${BOLD}Velaro public certificate${RST} (config ${res.id ?? argv.config ?? 'new'})`);
72
+ console.log('Upload in NetSuite: Setup > Integration > Manage Authentication > OAuth 2.0 Client Credentials (M2M) Setup');
73
+ console.log(res.certificatePem ?? '(no certificate returned)');
74
+ if (Array.isArray(res.steps)) res.steps.forEach((st, i) => console.log(` ${i + 1}. ${st}`));
75
+ console.log('');
76
+ }
77
+
78
+ async function m2mSaveHandler(argv) {
79
+ await messagingPost('/NetSuite/M2M/Save', { id: Number(argv.configId), clientId: argv.clientId, certificateId: argv.certificateId });
80
+ console.log(`\n ${GRN}Saved.${RST} Run "velaro netsuite m2m verify ${argv.configId}".\n`);
81
+ }
82
+
83
+ async function m2mVerifyHandler(argv) {
84
+ printChecks(await messagingPost('/NetSuite/M2M/Verify', { id: Number(argv.configId) }));
85
+ }
86
+
57
87
  export const netsuiteCommand = {
58
88
  command: 'netsuite <subcommand>',
59
89
  describe: 'NetSuite integration setup (click-to-dial / CTI)',
@@ -81,6 +111,31 @@ export const netsuiteCommand = {
81
111
  .strict(),
82
112
  handler: () => {},
83
113
  })
114
+ .command({
115
+ command: 'm2m <action>',
116
+ describe: 'NetSuite machine-to-machine (OAuth 2.0 Client Credentials) setup',
117
+ builder: yy => yy
118
+ .command({
119
+ command: 'init',
120
+ describe: 'Generate the Velaro public certificate to upload into NetSuite',
121
+ builder: a => a.option('config', { type: 'number' }).option('company', { type: 'string' }).option('name', { type: 'string' }),
122
+ handler: m2mInitHandler,
123
+ })
124
+ .command({
125
+ command: 'save <configId>',
126
+ describe: 'Store the Client ID and Certificate ID from NetSuite',
127
+ builder: a => a.option('client-id', { type: 'string', demandOption: true }).option('certificate-id', { type: 'string', demandOption: true }),
128
+ handler: argv => m2mSaveHandler({ configId: argv.configId, clientId: argv['client-id'], certificateId: argv['certificate-id'] }),
129
+ })
130
+ .command({
131
+ command: 'verify <configId>',
132
+ describe: 'Run the per-check verification (token, REST, customer read)',
133
+ handler: m2mVerifyHandler,
134
+ })
135
+ .demandCommand(1, 'Specify an m2m action: init, save, or verify.')
136
+ .strict(),
137
+ handler: () => {},
138
+ })
84
139
  .demandCommand(1, 'Specify a netsuite subcommand.')
85
140
  .strict(),
86
141
  handler: () => {},
@@ -18,10 +18,21 @@ async function usage(argv) {
18
18
  for (const note of u.notes ?? []) console.log(` Note: ${note}`);
19
19
  }
20
20
 
21
+ async function verifyToken(argv) {
22
+ const t = await request('GET', 'ScraperJobs/VerifyToken');
23
+ if (argv.json) { console.log(JSON.stringify(t, null, 2)); return; }
24
+ console.log('\nScraper verification (give this to your web host to allowlist our crawler)');
25
+ console.log(` Header: ${t.header_name}: ${t.header_value}`);
26
+ console.log(` Scraper IP: ${t.scraper_ip}`);
27
+ if (t.instructions) console.log(`\n${t.instructions}`);
28
+ }
29
+
21
30
  export function scraperCommand(yargs) {
22
31
  return yargs
23
32
  .command('usage', 'Show scraper/upload/chunk usage for a site (staff only)', (y) => y
24
33
  .option('site', { type: 'number', demandOption: true, describe: 'Target site id' })
25
34
  .option('json', { type: 'boolean', describe: 'Print raw JSON' }), (a) => usage(a))
26
- .demandCommand(1, 'Specify a subcommand: usage');
35
+ .command('verify-token', 'Show your scraper verification header + IP for web-host allowlisting', (y) => y
36
+ .option('json', { type: 'boolean', describe: 'Print raw JSON' }), (a) => verifyToken(a))
37
+ .demandCommand(1, 'Specify a subcommand: usage, verify-token');
27
38
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@velaro/cli",
3
- "version": "1.4.59",
3
+ "version": "1.4.61",
4
4
  "description": "Velaro Workspace v20 — command-line interface for managing bots, knowledge base ingestion, MCP API keys, search indexes, and ops health.",
5
5
  "type": "module",
6
6
  "bin": {