@velaro/cli 1.4.132 → 1.4.134
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/lib/commands/magento.js +16 -3
- package/lib/commands/part-finder.js +23 -4
- package/lib/part-finder.test.js +32 -1
- package/package.json +1 -1
package/lib/commands/magento.js
CHANGED
|
@@ -73,6 +73,16 @@ ${RED}✗ Connection failed: ${e.message}${RST}
|
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
+
// The search endpoints need the Magento config id (configId) and the search text (query).
|
|
77
|
+
// Resolve the active store from /Magento/Configs; --config-id overrides it.
|
|
78
|
+
async function resolveConfigId(argv) {
|
|
79
|
+
if (argv.configId) return argv.configId;
|
|
80
|
+
const stores = await request('GET', '/Magento/Configs');
|
|
81
|
+
const active = (Array.isArray(stores) ? stores : []).find((s) => s.isActive);
|
|
82
|
+
if (!active) throw new Error('No active Magento store connected for this site.');
|
|
83
|
+
return active.id;
|
|
84
|
+
}
|
|
85
|
+
|
|
76
86
|
// ── customers ─────────────────────────────────────────────────────────────────
|
|
77
87
|
|
|
78
88
|
async function customersHandler(argv) {
|
|
@@ -81,7 +91,8 @@ async function customersHandler(argv) {
|
|
|
81
91
|
process.exitCode = 1;
|
|
82
92
|
return;
|
|
83
93
|
}
|
|
84
|
-
const
|
|
94
|
+
const configId = await resolveConfigId(argv);
|
|
95
|
+
const r = await request('GET', `/Magento/Customers/Search?configId=${configId}&query=${encodeURIComponent(argv.email)}`);
|
|
85
96
|
if (!r || !r.id) {
|
|
86
97
|
console.log(`\nNo customer found for ${argv.email}.\n`);
|
|
87
98
|
return;
|
|
@@ -104,7 +115,8 @@ async function ordersHandler(argv) {
|
|
|
104
115
|
}
|
|
105
116
|
const q = argv.id ?? argv.email;
|
|
106
117
|
const limit = Math.min(50, argv.limit ?? 10);
|
|
107
|
-
const
|
|
118
|
+
const configId = await resolveConfigId(argv);
|
|
119
|
+
const orders = await request('GET', `/Magento/Orders/Search?configId=${configId}&query=${encodeURIComponent(q)}&limit=${limit}`);
|
|
108
120
|
if (!Array.isArray(orders) || orders.length === 0) {
|
|
109
121
|
console.log(`\nNo orders found for "${q}".\n`);
|
|
110
122
|
return;
|
|
@@ -129,7 +141,8 @@ async function productsHandler(argv) {
|
|
|
129
141
|
return;
|
|
130
142
|
}
|
|
131
143
|
const limit = Math.min(50, argv.limit ?? 10);
|
|
132
|
-
const
|
|
144
|
+
const configId = await resolveConfigId(argv);
|
|
145
|
+
const products = await request('GET', `/Magento/Products/Search?configId=${configId}&query=${encodeURIComponent(argv.query)}&limit=${limit}`);
|
|
133
146
|
if (!Array.isArray(products) || products.length === 0) {
|
|
134
147
|
console.log(`\nNo products found for "${argv.query}".\n`);
|
|
135
148
|
return;
|
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
// velaro part-finder config get Show the order, time limits, confidence and no-result action
|
|
5
5
|
// velaro part-finder config set [--enabled true|false] [--order matrix,erp,catalog_exact,spec_search] [--disable erp,...]
|
|
6
6
|
// [--min-confidence 0.8] [--no-result handoff|categories|handoff_and_categories|capture_lead]
|
|
7
|
-
// velaro part-finder sources list|
|
|
7
|
+
// velaro part-finder sources list|sync|preview|remove [id] Matrix sources (SharePoint, OneDrive); preview shows the diff, nothing applied
|
|
8
|
+
// velaro part-finder sources add --url <share link> [--type sharepoint|onedrive] [--load-mode preload|live] [--sync-hours N] [--auto-approve]
|
|
8
9
|
// velaro part-finder misses [--dismiss <id>] What customers asked that found nothing
|
|
9
10
|
// velaro part-finder suggestions list|generate|approve <id>|reject <id>
|
|
10
11
|
//
|
|
@@ -58,6 +59,23 @@ export function buildConfigPatch(current, flags) {
|
|
|
58
59
|
return patch;
|
|
59
60
|
}
|
|
60
61
|
|
|
62
|
+
/** Body for POST /PartFinder/Sources from the add flags. Pure, so it is unit tested. The server resolves the link to the file. */
|
|
63
|
+
export function buildSourceBody(flags) {
|
|
64
|
+
const shareUrl = String(flags.url ?? '').trim();
|
|
65
|
+
if (!shareUrl) throw new Error('--url is required for add: the Share link to the .xlsx or .csv file in SharePoint or OneDrive.');
|
|
66
|
+
if (!/^https:\/\//i.test(shareUrl)) throw new Error('--url must be an https link to the file in SharePoint or OneDrive.');
|
|
67
|
+
const type = String(flags.type ?? 'sharepoint').toLowerCase();
|
|
68
|
+
if (type !== 'sharepoint' && type !== 'onedrive') throw new Error('--type must be sharepoint or onedrive.');
|
|
69
|
+
const body = { type, shareUrl, loadMode: flags['load-mode'] ?? 'preload', enabled: true };
|
|
70
|
+
if (flags['sync-hours'] !== undefined) {
|
|
71
|
+
const h = Number(flags['sync-hours']);
|
|
72
|
+
if (!Number.isFinite(h) || h <= 0) throw new Error('--sync-hours must be a positive number.');
|
|
73
|
+
body.syncIntervalHours = h;
|
|
74
|
+
}
|
|
75
|
+
if (flags['auto-approve'] === true) body.autoApproveRows = true;
|
|
76
|
+
return body;
|
|
77
|
+
}
|
|
78
|
+
|
|
61
79
|
export function listOf(r, ...keys) {
|
|
62
80
|
if (Array.isArray(r)) return r;
|
|
63
81
|
for (const k of keys) if (Array.isArray(r?.[k])) return r[k];
|
|
@@ -104,15 +122,16 @@ export const partFinderCommand = {
|
|
|
104
122
|
.positional('action', { choices: ['list', 'add', 'sync', 'preview', 'remove'] })
|
|
105
123
|
.positional('id', { type: 'number' })
|
|
106
124
|
.option('type', { type: 'string', default: 'sharepoint', describe: 'sharepoint or onedrive (add)' })
|
|
107
|
-
.option('
|
|
125
|
+
.option('url', { type: 'string', describe: 'Share link to the .xlsx or .csv file in SharePoint or OneDrive (add)' })
|
|
126
|
+
.option('sync-hours', { type: 'number', describe: 'how often to check the file, in hours (add)' })
|
|
127
|
+
.option('auto-approve', { type: 'boolean', describe: 'approve new rows automatically (add)' })
|
|
108
128
|
.option('load-mode', { type: 'string', default: 'preload', describe: 'preload or live (add)' })
|
|
109
129
|
.option('json', J),
|
|
110
130
|
runCommand(async (a) => {
|
|
111
131
|
let r;
|
|
112
132
|
if (a.action === 'list') r = await messagingGet('/PartFinder/Sources');
|
|
113
133
|
else if (a.action === 'add') {
|
|
114
|
-
|
|
115
|
-
r = await messagingPost('/PartFinder/Sources', { type: a.type, fileName: a.file, loadMode: a['load-mode'], enabled: true });
|
|
134
|
+
r = await messagingPost('/PartFinder/Sources', buildSourceBody(a));
|
|
116
135
|
} else {
|
|
117
136
|
if (!a.id) throw new Error(`An id is required for ${a.action}.`);
|
|
118
137
|
if (a.action === 'remove') { await messagingDel(`/PartFinder/Sources/${a.id}`); console.log(`Removed source ${a.id}`); return; }
|
package/lib/part-finder.test.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { test } from 'node:test';
|
|
2
2
|
import assert from 'node:assert/strict';
|
|
3
|
-
import { buildConfigPatch, describeFind, listOf, parseList } from './commands/part-finder.js';
|
|
3
|
+
import { buildConfigPatch, buildSourceBody, describeFind, listOf, parseList } from './commands/part-finder.js';
|
|
4
4
|
import { tools, handlers } from '../../mcp/parity/part-finder.customer.js';
|
|
5
5
|
|
|
6
6
|
const current = () => ({
|
|
@@ -52,6 +52,8 @@ test('reads bare or wrapped lists and describes a find result with its trace', (
|
|
|
52
52
|
assert.match(text, /trace: matrix -> miss \(3 ms\)/);
|
|
53
53
|
});
|
|
54
54
|
|
|
55
|
+
const LINK = 'https://contoso.sharepoint.com/:x:/s/parts/EabC123?e=1';
|
|
56
|
+
|
|
55
57
|
test('MCP parity: every tool has a handler, none takes a siteId, endpoints match the CLI', async () => {
|
|
56
58
|
for (const t of tools) {
|
|
57
59
|
assert.equal(typeof handlers[t.name], 'function');
|
|
@@ -69,6 +71,7 @@ test('MCP parity: every tool has a handler, none takes a siteId, endpoints match
|
|
|
69
71
|
await handlers.part_finder_config({}, ctx);
|
|
70
72
|
await handlers.part_finder_config({ minConfidence: 0.9 }, ctx);
|
|
71
73
|
await handlers.part_finder_sources({}, ctx);
|
|
74
|
+
await handlers.part_finder_source_add({ shareUrl: LINK }, ctx);
|
|
72
75
|
await handlers.part_finder_source_preview({ id: 4 }, ctx);
|
|
73
76
|
await handlers.part_finder_source_sync({ id: 4 }, ctx);
|
|
74
77
|
await handlers.part_finder_source_remove({ id: 4 }, ctx);
|
|
@@ -81,6 +84,7 @@ test('MCP parity: every tool has a handler, none takes a siteId, endpoints match
|
|
|
81
84
|
['GET', '/PartFinder/Config'],
|
|
82
85
|
['PUT', '/PartFinder/Config'],
|
|
83
86
|
['GET', '/PartFinder/Sources'],
|
|
87
|
+
['POST', '/PartFinder/Sources'],
|
|
84
88
|
['GET', '/PartFinder/Sources/4/Preview'],
|
|
85
89
|
['POST', '/PartFinder/Sources/4/SyncNow'],
|
|
86
90
|
['DEL', '/PartFinder/Sources/4'],
|
|
@@ -93,3 +97,30 @@ test('MCP parity: every tool has a handler, none takes a siteId, endpoints match
|
|
|
93
97
|
await assert.rejects(() => handlers.part_finder_source_sync({ id: 0 }, ctx), /positive integer/);
|
|
94
98
|
await assert.rejects(() => handlers.part_finder_config({ minConfidence: 3 }, ctx), /between 0 and 1/);
|
|
95
99
|
});
|
|
100
|
+
|
|
101
|
+
test('sources add (CLI): sends shareUrl, never fileName, and validates the link and type', () => {
|
|
102
|
+
const b = buildSourceBody({ url: ' ' + LINK + ' ' });
|
|
103
|
+
assert.deepEqual(b, { type: 'sharepoint', shareUrl: LINK, loadMode: 'preload', enabled: true });
|
|
104
|
+
assert.equal('fileName' in b, false);
|
|
105
|
+
const full = buildSourceBody({ url: LINK, type: 'OneDrive', 'load-mode': 'live', 'sync-hours': 6, 'auto-approve': true });
|
|
106
|
+
assert.equal(full.type, 'onedrive');
|
|
107
|
+
assert.equal(full.syncIntervalHours, 6);
|
|
108
|
+
assert.equal(full.autoApproveRows, true);
|
|
109
|
+
assert.throws(() => buildSourceBody({}), /--url is required/);
|
|
110
|
+
assert.throws(() => buildSourceBody({ url: 'Cross.xlsx' }), /https/);
|
|
111
|
+
assert.throws(() => buildSourceBody({ url: LINK, type: 'upload' }), /sharepoint or onedrive/);
|
|
112
|
+
assert.throws(() => buildSourceBody({ url: LINK, 'sync-hours': 0 }), /positive/);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test('sources add (MCP): body carries shareUrl, upload is refused, input schema requires shareUrl only', async () => {
|
|
116
|
+
const tool = tools.find((t) => t.name === 'part_finder_source_add');
|
|
117
|
+
assert.deepEqual(tool.inputSchema.required, ['shareUrl']);
|
|
118
|
+
assert.equal('fileName' in tool.inputSchema.properties, false);
|
|
119
|
+
const sent = [];
|
|
120
|
+
const ctx = { messagingPost: async (p, b) => { sent.push([p, b]); return {}; } };
|
|
121
|
+
await handlers.part_finder_source_add({ shareUrl: LINK, type: 'onedrive', autoApproveRows: true, syncIntervalHours: 12 }, ctx);
|
|
122
|
+
assert.deepEqual(sent[0], ['/PartFinder/Sources', { type: 'onedrive', shareUrl: LINK, loadMode: 'preload', enabled: true, syncIntervalHours: 12, autoApproveRows: true }]);
|
|
123
|
+
await assert.rejects(() => handlers.part_finder_source_add({}, ctx), /shareUrl is required/);
|
|
124
|
+
await assert.rejects(() => handlers.part_finder_source_add({ shareUrl: 'Cross.xlsx' }, ctx), /https/);
|
|
125
|
+
await assert.rejects(() => handlers.part_finder_source_add({ shareUrl: LINK, type: 'upload' }, ctx), /sharepoint or onedrive/);
|
|
126
|
+
});
|
package/package.json
CHANGED