@velaro/cli 1.4.117 → 1.4.119

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
@@ -12,6 +12,7 @@ import { ingestCommand } from '../lib/commands/ingest.js';
12
12
  import { indexMoveCommand } from '../lib/commands/index-move.js';
13
13
  import { safetyCommand } from '../lib/commands/safety.js';
14
14
  import { knowledgeAdvisorCommand } from '../lib/commands/knowledge-advisor.js';
15
+ import { productMatchCommand } from '../lib/commands/product-match.js';
15
16
  import { knowledgeCommand } from '../lib/commands/knowledge.js';
16
17
  import { productCommand } from '../lib/commands/product.js';
17
18
  import { mcpKeyCommand } from '../lib/commands/mcp-key.js';
@@ -180,6 +181,7 @@ await yargs(hideBin(process.argv))
180
181
  .command(indexMoveCommand)
181
182
  .command(safetyCommand)
182
183
  .command(knowledgeAdvisorCommand)
184
+ .command(productMatchCommand)
183
185
  .command(knowledgeCommand)
184
186
  .command(productCommand)
185
187
  .command(mcpKeyCommand)
@@ -41,6 +41,18 @@ async function call(s, a) {
41
41
  return fn(s.method || 'GET', s.path(a), s.body ? s.body(a) : undefined);
42
42
  }
43
43
 
44
+ // Safety guard for subscription/expiry writes. Default is DENY: these commands refuse to run
45
+ // unless VELARO_ALLOW_SUBSCRIPTION_WRITE=1 is set, and a protected site can never be written from
46
+ // the CLI. Site 20678 (Northern New England Poison Control) is protected: it stays on its own
47
+ // account and expiry controls, and must not be extended, flagged, or changed from this CLI.
48
+ const PROTECTED_SITE_IDS = new Set([20678]);
49
+ function subscriptionWriteGuard(a) {
50
+ if (process.env.VELARO_ALLOW_SUBSCRIPTION_WRITE !== '1') return 'Subscription writes are disabled in the CLI. Set VELARO_ALLOW_SUBSCRIPTION_WRITE=1 for one deliberate run.';
51
+ const id = Number(a.site);
52
+ if (PROTECTED_SITE_IDS.has(id)) return `Site ${id} is protected. Subscription and expiry changes for it are not allowed from the CLI.`;
53
+ return null;
54
+ }
55
+
44
56
  export function addRoutes(y, specs) {
45
57
  for (const s of specs) {
46
58
  y.command(s.name, s.desc, (yy) => {
@@ -50,6 +62,7 @@ export function addRoutes(y, specs) {
50
62
  }, async (a) => {
51
63
  try {
52
64
  if ((s.yes || (s.needsYes && s.needsYes(a))) && !a.yes) { console.error(`Refusing without --yes: ${s.desc}`); process.exit(1); }
65
+ if (s.guard) { const why = s.guard(a); if (why) { console.error(`Refused: ${why}`); process.exit(1); } }
53
66
  out(s.run ? await s.run(a) : await call(s, a));
54
67
  } catch (e) { console.error(e.message); process.exit(1); }
55
68
  });
@@ -75,9 +88,9 @@ export const SUPPORT_EXTRA = [
75
88
  { name: 'site-health', desc: 'Site health: subscription, agents, last login, 7-day errors', opts: site, path: (a) => `${SP(a)}/health` },
76
89
  { name: 'site-agents', desc: 'Agents on a site', opts: site, path: (a) => `${SP(a)}/agents` },
77
90
  { name: 'site-activity', desc: 'Activity log for a site', opts: { ...site, page: N('Page'), 'page-size': N('Page size (max 200)'), category: S('Category') }, path: (a) => `${SP(a)}/activity${qs({ page: a.page ?? 1, pageSize: Math.min(200, a.pageSize ?? 50), category: a.category })}` },
78
- { name: 'extend-subscription', desc: 'Extend a site subscription by N days', yes: true, method: 'POST', opts: { ...site, days: N('Days', true) }, path: (a) => `${SP(a)}/extend-subscription`, body: (a) => ({ days: a.days }) },
91
+ { name: 'extend-subscription', desc: 'Extend a site subscription by N days', guard: subscriptionWriteGuard, yes: true, method: 'POST', opts: { ...site, days: N('Days', true) }, path: (a) => `${SP(a)}/extend-subscription`, body: (a) => ({ days: a.days }) },
79
92
  { name: 'set-user-active', desc: 'Activate/deactivate a user on a site', yes: true, method: 'POST', opts: { ...site, 'user-id': N('User id', true), active: { type: 'boolean', demandOption: true, describe: 'true or false' } }, path: (a) => `SupportTools/users/${a.userId}/sites/${a.site}/set-active`, body: (a) => ({ isActive: a.active }) },
80
- { name: 'bulk-set-flags', desc: 'Set several subscription flags at once (JSON object)', yes: true, method: 'POST', opts: { ...site, flags: S('JSON object or @file.json', true) }, path: (a) => `${SP(a)}/subscription/bulk-flags`, body: (a) => ({ flags: json(a.flags) }) },
93
+ { name: 'bulk-set-flags', desc: 'Set several subscription flags at once (JSON object)', guard: subscriptionWriteGuard, yes: true, method: 'POST', opts: { ...site, flags: S('JSON object or @file.json', true) }, path: (a) => `${SP(a)}/subscription/bulk-flags`, body: (a) => ({ flags: json(a.flags) }) },
81
94
  { name: 'create-agent', desc: 'Create an agent on any site (staff)', api: 'msg', method: 'POST', opts: { ...site, email: S('Email', true), 'first-name': S('First name'), 'last-name': S('Last name'), roles: S('Comma list of roles'), 'team-ids': S('Comma list of team ids'), 'max-chats': N('Max chats (0 = default)') }, path: (a) => `/SupportTools/sites/${a.site}/agents`, body: (a) => ({ email: a.email, firstName: a.firstName, lastName: a.lastName, roles: csv(a.roles), teamIds: csvN(a.teamIds), maxChats: a.maxChats ?? 0 }) },
82
95
  { name: 'schedule-adherence', desc: 'Schedule adherence diagnostics for a site', api: 'msg', opts: { ...site, role: S('role'), 'agent-id': N('Agent id (required when role=agent)'), start: S('Start'), end: S('End'), tz: S('Timezone') }, path: (a) => `/Reports/sites/${a.site}/schedule-adherence-diagnostics${qs({ detail: 'true', role: a.role, agentId: a.agentId, start: a.start, end: a.end, tz: a.tz })}` },
83
96
  { name: 'appointments-list-sites', desc: 'Sites with Velaro Appointments enabled', api: 'msg', path: () => '/Appointments/admin/sites-with-appointments' },
@@ -0,0 +1,81 @@
1
+ // velaro product-match - the per-site Product Match matrix (competitor, old or discontinued part -> your OWN catalog SKU).
2
+ //
3
+ // velaro product-match match "<part or model>" Look a part up (same deterministic action the bot uses)
4
+ // velaro product-match import <file.csv|file.xlsx> Upload the cross-reference matrix (approval column defaults to NO)
5
+ // velaro product-match list [--q text] [--page n] Show matrix rows
6
+ // velaro product-match approve <id> [--revoke] Approve (or revoke) one row; only approved rows are ever recommended
7
+ // velaro product-match remove <id> Delete one row
8
+ // velaro product-match deny list|set "Brand A,Brand B" Brands / competitors the bot must never name
9
+ //
10
+ // Calls messaging POST /BusinessActions/match_product/Execute and the /ProductMatch endpoints. Site scope comes from the signed-in
11
+ // identity. Needs the Product Match package (EnableProductMatch); without it the server answers 403 / not enabled.
12
+ import fs from 'node:fs';
13
+ import path from 'node:path';
14
+ import { messagingGet, messagingPost, messagingPut, messagingDel } from '../api.js';
15
+ import { runCommand } from '../run.js';
16
+
17
+ export function buildImportBody(filePath) {
18
+ const ext = path.extname(filePath).toLowerCase();
19
+ if (ext !== '.csv' && ext !== '.xlsx') throw new Error('Only .csv and .xlsx files are supported.');
20
+ const bytes = fs.readFileSync(filePath);
21
+ if (bytes.length === 0) throw new Error('The file is empty.');
22
+ if (bytes.length > 5 * 1024 * 1024) throw new Error('The file is over the 5 MB limit.');
23
+ return { fileName: path.basename(filePath), contentBase64: bytes.toString('base64') };
24
+ }
25
+
26
+ export function parseTerms(text) {
27
+ return String(text ?? '').split(/[,\n;]/).map((t) => t.trim()).filter(Boolean);
28
+ }
29
+
30
+ export const productMatchCommand = {
31
+ command: 'product-match',
32
+ describe: 'Product Match matrix: map competitor, old or discontinued parts to your own catalog SKUs',
33
+ builder: (yargs) => yargs
34
+ .command('match <query>', 'Look up the match for a part number, SKU or model', (y) => y
35
+ .positional('query', { type: 'string' }).option('json', { type: 'boolean' }),
36
+ runCommand(async (a) => {
37
+ const r = await messagingPost('/BusinessActions/match_product/Execute', { query: a.query });
38
+ if (a.json) { console.log(JSON.stringify(r, null, 2)); return; }
39
+ if (!r.success) { console.log(`Not available: ${r.error ?? r.errorKind}`); process.exitCode = 1; return; }
40
+ const d = r.data;
41
+ console.log(`Status: ${d.status}${d.handoff ? ' (hand off to a person, no recommendation)' : ''}`);
42
+ for (const m of d.recommendations ?? []) console.log(` ${m.sku} ${m.name} [${m.matchType}]`);
43
+ }))
44
+ .command('import <file>', 'Upload a .csv or .xlsx cross-reference matrix', (y) => y
45
+ .positional('file', { type: 'string' }).option('json', { type: 'boolean' }),
46
+ runCommand(async (a) => {
47
+ const r = await messagingPost('/ProductMatch/ImportFile', buildImportBody(a.file));
48
+ if (a.json) { console.log(JSON.stringify(r, null, 2)); return; }
49
+ console.log(`Added ${r.added}, updated ${r.updated}, skipped ${r.skipped}. Targets not in your catalog (never recommended): ${r.targetsNotInCatalog}.`);
50
+ for (const e of r.errors ?? []) console.log(` ${e}`);
51
+ console.log('Rows are NOT approved unless the file had an Approved column set to yes. Approve with: velaro product-match approve <id>');
52
+ }))
53
+ .command('list', 'List matrix rows', (y) => y
54
+ .option('q', { type: 'string' }).option('page', { type: 'number', default: 1 }).option('json', { type: 'boolean' }),
55
+ runCommand(async (a) => {
56
+ const qs = new URLSearchParams({ page: String(a.page) });
57
+ if (a.q) qs.set('q', a.q);
58
+ const r = await messagingGet(`/ProductMatch/Entries?${qs}`);
59
+ if (a.json) { console.log(JSON.stringify(r, null, 2)); return; }
60
+ console.log(`${r.total} row(s)`);
61
+ for (const e of r.entries ?? []) console.log(` #${e.id} ${e.source} -> ${e.target} [${e.matchType}] ${e.approved ? 'approved' : 'NOT approved'}`);
62
+ }))
63
+ .command('approve <id>', 'Approve (or --revoke) one row', (y) => y
64
+ .positional('id', { type: 'number' }).option('revoke', { type: 'boolean', default: false }),
65
+ runCommand(async (a) => {
66
+ const r = await messagingPut(`/ProductMatch/Entries/${a.id}/Approve`, { approved: !a.revoke });
67
+ console.log(`Row ${r.id}: ${r.approved ? 'approved' : 'not approved'}`);
68
+ }))
69
+ .command('remove <id>', 'Delete one row', (y) => y.positional('id', { type: 'number' }),
70
+ runCommand(async (a) => { await messagingDel(`/ProductMatch/Entries/${a.id}`); console.log(`Removed row ${a.id}`); }))
71
+ .command('deny <action> [terms]', 'list or set the brands / competitors the bot must never name', (y) => y
72
+ .positional('action', { choices: ['list', 'set'] }).positional('terms', { type: 'string', describe: 'comma separated (set replaces the whole list)' }),
73
+ runCommand(async (a) => {
74
+ const r = a.action === 'set'
75
+ ? await messagingPut('/ProductMatch/DenyTerms', { terms: parseTerms(a.terms) })
76
+ : await messagingGet('/ProductMatch/DenyTerms');
77
+ console.log((r.terms ?? []).length ? r.terms.join(', ') : '(none)');
78
+ }))
79
+ .demandCommand(1),
80
+ handler: () => {},
81
+ };
@@ -0,0 +1,48 @@
1
+ import { test } from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import fs from 'node:fs';
4
+ import os from 'node:os';
5
+ import path from 'node:path';
6
+ import { buildImportBody, parseTerms } from './commands/product-match.js';
7
+ import { tools, handlers } from '../../mcp/parity/product-match.customer.js';
8
+
9
+ test('builds a base64 import body for csv and rejects other types and empty files', () => {
10
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'pm-'));
11
+ const csv = path.join(dir, 'm.csv');
12
+ fs.writeFileSync(csv, 'Competitor SKU,Our SKU\nA-1,B-1\n');
13
+ const body = buildImportBody(csv);
14
+ assert.equal(body.fileName, 'm.csv');
15
+ assert.match(Buffer.from(body.contentBase64, 'base64').toString(), /A-1,B-1/);
16
+ const pdf = path.join(dir, 'm.pdf');
17
+ fs.writeFileSync(pdf, 'x');
18
+ assert.throws(() => buildImportBody(pdf), /csv and .xlsx/);
19
+ const empty = path.join(dir, 'e.csv');
20
+ fs.writeFileSync(empty, '');
21
+ assert.throws(() => buildImportBody(empty), /empty/);
22
+ });
23
+
24
+ test('parses deny terms from commas, semicolons and newlines', () => {
25
+ assert.deepEqual(parseTerms('Philips, ResMed;Inogen\n Drive '), ['Philips', 'ResMed', 'Inogen', 'Drive']);
26
+ assert.deepEqual(parseTerms(undefined), []);
27
+ });
28
+
29
+ test('MCP parity: every tool has a handler, none takes a siteId, endpoints match the CLI', async () => {
30
+ for (const t of tools) {
31
+ assert.equal(typeof handlers[t.name], 'function');
32
+ assert.ok(!Object.keys(t.inputSchema.properties ?? {}).includes('siteId'));
33
+ }
34
+ const calls = [];
35
+ const ctx = {
36
+ messagingGet: async (p) => { calls.push(['GET', p]); return {}; },
37
+ messagingPost: async (p, b) => { calls.push(['POST', p, b]); return {}; },
38
+ messagingPut: async (p, b) => { calls.push(['PUT', p, b]); return {}; },
39
+ messagingDel: async (p) => { calls.push(['DEL', p]); return {}; },
40
+ };
41
+ await handlers.product_match_lookup({ query: 'ACME-100' }, ctx);
42
+ await handlers.product_match_approve({ id: 5 }, ctx);
43
+ await handlers.product_match_deny_terms({ terms: ['Philips'] }, ctx);
44
+ assert.deepEqual(calls[0], ['POST', '/BusinessActions/match_product/Execute', { query: 'ACME-100' }]);
45
+ assert.deepEqual(calls[1], ['PUT', '/ProductMatch/Entries/5/Approve', { approved: true }]);
46
+ assert.deepEqual(calls[2], ['PUT', '/ProductMatch/DenyTerms', { terms: ['Philips'] }]);
47
+ await assert.rejects(() => handlers.product_match_approve({ id: 'x' }, ctx), /positive integer/);
48
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@velaro/cli",
3
- "version": "1.4.117",
3
+ "version": "1.4.119",
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": {