@velaro/cli 1.4.118 → 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)
@@ -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.118",
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": {