mage-remote-run 0.22.0 → 0.23.1
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/mage-remote-run.js +11 -3
- package/lib/command-registry.js +11 -5
- package/lib/commands/connections.js +104 -13
- package/lib/commands/modules.js +62 -0
- package/lib/commands/shipments.js +327 -0
- package/lib/config.js +4 -1
- package/lib/mcp.js +8 -8
- package/package.json +1 -1
package/bin/mage-remote-run.js
CHANGED
|
@@ -10,6 +10,7 @@ const pkg = require('../package.json');
|
|
|
10
10
|
|
|
11
11
|
const program = new Command();
|
|
12
12
|
|
|
13
|
+
|
|
13
14
|
program
|
|
14
15
|
.name('mage-remote-run')
|
|
15
16
|
.description('The remote swiss army knife for Magento Open Source, Mage-OS, Adobe Commerce')
|
|
@@ -48,12 +49,18 @@ import { startMcpServer } from '../lib/mcp.js';
|
|
|
48
49
|
// But we need them registered early if we want them to show up in help even if config fails?
|
|
49
50
|
// Actually registerCommands handles null profile by registering connection commands only.
|
|
50
51
|
|
|
51
|
-
program.command('mcp')
|
|
52
|
+
program.command('mcp [args...]')
|
|
52
53
|
.description('Run as MCP server')
|
|
53
54
|
.option('--transport <type>', 'Transport type (stdio, http)', 'stdio')
|
|
54
55
|
.option('--host <host>', 'HTTP Host', '127.0.0.1')
|
|
55
56
|
.option('--port <port>', 'HTTP Port', '18098')
|
|
56
|
-
.
|
|
57
|
+
.allowExcessArguments(true)
|
|
58
|
+
.allowUnknownOption(true)
|
|
59
|
+
.action(async (args, options) => {
|
|
60
|
+
// We ignore extra arguments but log them for debugging purposes
|
|
61
|
+
if (args && args.length > 0) {
|
|
62
|
+
// console.error(chalk.yellow(`[mage-remote-run] Warning: Received extra arguments for mcp command: ${args.join(' ')}`));
|
|
63
|
+
}
|
|
57
64
|
await startMcpServer(options);
|
|
58
65
|
});
|
|
59
66
|
|
|
@@ -68,7 +75,8 @@ program.hook('preAction', async (thisCommand, actionCommand) => {
|
|
|
68
75
|
const config = await loadConfig();
|
|
69
76
|
if (config.showActiveConnectionHeader !== false) {
|
|
70
77
|
const opts = actionCommand.opts();
|
|
71
|
-
if
|
|
78
|
+
// Standard output corruption check: Don't print header if output is json/xml OR if running mcp command (which uses stdio)
|
|
79
|
+
if (opts.format !== 'json' && opts.format !== 'xml' && actionCommand.name() !== 'mcp') {
|
|
72
80
|
console.log(chalk.cyan(`Active Connection: ${chalk.bold(profile.name)} (${profile.type})`));
|
|
73
81
|
console.log(chalk.gray('━'.repeat(60)) + '\n');
|
|
74
82
|
}
|
package/lib/command-registry.js
CHANGED
|
@@ -13,9 +13,11 @@ import { registerEventsCommands } from './commands/events.js';
|
|
|
13
13
|
import { registerWebhooksCommands } from './commands/webhooks.js';
|
|
14
14
|
import { registerPurchaseOrderCartCommands } from './commands/purchase-order-cart.js';
|
|
15
15
|
import { registerImportCommands } from './commands/import.js';
|
|
16
|
+
import { registerModulesCommands } from './commands/modules.js';
|
|
16
17
|
import { registerConsoleCommand } from './commands/console.js';
|
|
18
|
+
import { registerShipmentCommands } from './commands/shipments.js';
|
|
17
19
|
|
|
18
|
-
export { registerConnectionCommands, registerConsoleCommand };
|
|
20
|
+
export { registerConnectionCommands, registerConsoleCommand, registerShipmentCommands };
|
|
19
21
|
|
|
20
22
|
const GROUPS = {
|
|
21
23
|
CORE: [
|
|
@@ -28,6 +30,7 @@ const GROUPS = {
|
|
|
28
30
|
registerCartCommands,
|
|
29
31
|
registerTaxCommands,
|
|
30
32
|
registerInventoryCommands,
|
|
33
|
+
registerShipmentCommands,
|
|
31
34
|
registerConsoleCommand
|
|
32
35
|
],
|
|
33
36
|
COMMERCE: [
|
|
@@ -40,14 +43,17 @@ const GROUPS = {
|
|
|
40
43
|
],
|
|
41
44
|
IMPORT: [
|
|
42
45
|
registerImportCommands
|
|
46
|
+
],
|
|
47
|
+
MODULES: [
|
|
48
|
+
registerModulesCommands
|
|
43
49
|
]
|
|
44
50
|
};
|
|
45
51
|
|
|
46
52
|
const TYPE_MAPPINGS = {
|
|
47
|
-
'magento-os': [...GROUPS.CORE],
|
|
48
|
-
'mage-os': [...GROUPS.CORE],
|
|
49
|
-
'ac-on-prem': [...GROUPS.CORE, ...GROUPS.COMMERCE, ...GROUPS.IMPORT],
|
|
50
|
-
'ac-cloud-paas': [...GROUPS.CORE, ...GROUPS.COMMERCE, ...GROUPS.CLOUD, ...GROUPS.IMPORT],
|
|
53
|
+
'magento-os': [...GROUPS.CORE, ...GROUPS.MODULES],
|
|
54
|
+
'mage-os': [...GROUPS.CORE, ...GROUPS.MODULES],
|
|
55
|
+
'ac-on-prem': [...GROUPS.CORE, ...GROUPS.COMMERCE, ...GROUPS.IMPORT, ...GROUPS.MODULES],
|
|
56
|
+
'ac-cloud-paas': [...GROUPS.CORE, ...GROUPS.COMMERCE, ...GROUPS.CLOUD, ...GROUPS.IMPORT, ...GROUPS.MODULES],
|
|
51
57
|
'ac-saas': [...GROUPS.CORE, ...GROUPS.COMMERCE, ...GROUPS.CLOUD, ...GROUPS.IMPORT] // Assuming SaaS has same feature set as PaaS for CLI
|
|
52
58
|
};
|
|
53
59
|
|
|
@@ -57,6 +57,107 @@ async function configureAndTestConnection(name, initialSettings = {}) {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
|
|
60
|
+
// Helper to print connection status
|
|
61
|
+
async function printConnectionStatus(config) {
|
|
62
|
+
if (!config.activeProfile) {
|
|
63
|
+
console.log(chalk.yellow('No active profile configured. Run "connection add" or "connection select".'));
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const profile = config.profiles[config.activeProfile];
|
|
68
|
+
|
|
69
|
+
if (profile) {
|
|
70
|
+
// ASCII Logos
|
|
71
|
+
const logos = {
|
|
72
|
+
adobe: chalk.red(`
|
|
73
|
+
@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@
|
|
74
|
+
@@@@@@@@@@@@@@ @@@@@@@@@@@@@@
|
|
75
|
+
@@@@@@@@@@@@@ @@@@@@@@@@@@@
|
|
76
|
+
@@@@@@@@@@@@@ @@@@@@@@@@@@
|
|
77
|
+
@@@@@@@@@@@@ @@@@@@@@@@@@
|
|
78
|
+
@@@@@@@@@@@ @@@@@@@@@@@
|
|
79
|
+
@@@@@@@@@@ @@@@@@@@@@
|
|
80
|
+
@@@@@@@@@ @@@ @@@@@@@@@
|
|
81
|
+
@@@@@@@@@ @@@ @@@@@@@@@
|
|
82
|
+
@@@@@@@@ @@@@@ @@@@@@@@
|
|
83
|
+
@@@@@@@ @@@@@@@ @@@@@@@
|
|
84
|
+
@@@@@@ @@@@@@@@@ @@@@@@
|
|
85
|
+
@@@@@@ @@@@@@@@@@@ @@@@@@
|
|
86
|
+
@@@@@ @@@@@@@@@@@@ @@@@@
|
|
87
|
+
@@@@ @@@@@@@@@@@@@ @@@@
|
|
88
|
+
@@@ @@@@@@@ @@@
|
|
89
|
+
@@ @@@@@@@ @@
|
|
90
|
+
@@ @@@@@@ @@
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
`),
|
|
94
|
+
magento: chalk.hex('#FFA500')(`
|
|
95
|
+
@@
|
|
96
|
+
@@@@@@@@
|
|
97
|
+
@@@@@@@@@@@@@@
|
|
98
|
+
@@@@@@@@@@@@@@@@@@@@
|
|
99
|
+
@@@@@@@@@@@@@@@@@@@@@@@@@@
|
|
100
|
+
@@@@@@@@@@@@@@ @@@@@@@@@@@@@@
|
|
101
|
+
@@@@@@@@@@@@@@ @@@@@@@@@@@@@@
|
|
102
|
+
@@@@@@@@@@@@@ @@@@@@@@@@@@@
|
|
103
|
+
@@@@@@@@@@ @@@@@@@@@@
|
|
104
|
+
@@@@@@@ @@@@ @@@@ @@@@@@@
|
|
105
|
+
@@@@@@@ @@@@@@@ @@@@@@@ @@@@@@@
|
|
106
|
+
@@@@@@@ @@@@@@@ @@@@@@@ @@@@@@@
|
|
107
|
+
@@@@@@@ @@@@@@@ @@@@@@@ @@@@@@@
|
|
108
|
+
@@@@@@@ @@@@@@@ @@@@@@@ @@@@@@@
|
|
109
|
+
@@@@@@@ @@@@@@@ @@@@@@@ @@@@@@@
|
|
110
|
+
@@@@@@@ @@@@@@@ @@@@@@@ @@@@@@@
|
|
111
|
+
@@@@@@@ @@@@@@@ @@@@@@@ @@@@@@@
|
|
112
|
+
@@@@@@@ @@@@@@@ @@@@@@@ @@@@@@@
|
|
113
|
+
@@@@@@@ @@@@@@@ @@@@@@@ @@@@@@@
|
|
114
|
+
@@@@@@@ @@@@@@@ @@@@@@@ @@@@@@@
|
|
115
|
+
@@@@@ @@@@@@@ @@@@@@@ @@@@@
|
|
116
|
+
@@@ @@@@@@@ @@@@@@@ @@@
|
|
117
|
+
@@@@@@@@@@@@@@@@@@
|
|
118
|
+
@@@@@@@@@@@@@@@@@@
|
|
119
|
+
@@@@@@@@@@@@@@
|
|
120
|
+
@@@@@@@@
|
|
121
|
+
@@ `),
|
|
122
|
+
mageos: chalk.hex('#FFA500')(`
|
|
123
|
+
====== ======
|
|
124
|
+
============ ============
|
|
125
|
+
====================================
|
|
126
|
+
==========================================
|
|
127
|
+
================================================
|
|
128
|
+
================================-===============--
|
|
129
|
+
=============----============----============-----
|
|
130
|
+
=========--------=========-------=========--------
|
|
131
|
+
========---------========--------========---------
|
|
132
|
+
========---------========--------========---------
|
|
133
|
+
========---------========--------========---------
|
|
134
|
+
=====------ ======------ =====------
|
|
135
|
+
==--- ===--- ==---
|
|
136
|
+
`)
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
let logo = '';
|
|
140
|
+
if (profile.type && profile.type.startsWith('ac-')) {
|
|
141
|
+
logo = logos.adobe;
|
|
142
|
+
} else if (profile.type === 'mage-os') {
|
|
143
|
+
logo = logos.mageos;
|
|
144
|
+
} else if (profile.type === 'magento-os') {
|
|
145
|
+
logo = logos.magento;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (logo) {
|
|
149
|
+
console.log(logo);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
console.log(chalk.bold('Active Profile:'), chalk.green(config.activeProfile));
|
|
153
|
+
console.log(`Type: ${profile.type}`);
|
|
154
|
+
console.log(`URL: ${profile.url}`);
|
|
155
|
+
} else {
|
|
156
|
+
console.log(chalk.red('Profile not found in configuration!'));
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
|
|
60
161
|
export function registerConnectionCommands(program) {
|
|
61
162
|
const connections = program.command('connection').description('Manage mage-remote-run connection profiles');
|
|
62
163
|
|
|
@@ -307,18 +408,7 @@ Examples:
|
|
|
307
408
|
.action(async () => {
|
|
308
409
|
try {
|
|
309
410
|
const config = await loadConfig();
|
|
310
|
-
|
|
311
|
-
console.log(chalk.yellow('No active profile configured. Run "connection add" or "connection select".'));
|
|
312
|
-
return;
|
|
313
|
-
}
|
|
314
|
-
console.log(chalk.bold('Active Profile:'), chalk.green(config.activeProfile));
|
|
315
|
-
const profile = config.profiles[config.activeProfile];
|
|
316
|
-
if (profile) {
|
|
317
|
-
console.log(`Type: ${profile.type}`);
|
|
318
|
-
console.log(`URL: ${profile.url}`);
|
|
319
|
-
} else {
|
|
320
|
-
console.log(chalk.red('Profile not found in configuration!'));
|
|
321
|
-
}
|
|
411
|
+
await printConnectionStatus(config);
|
|
322
412
|
} catch (e) { handleError(e); }
|
|
323
413
|
});
|
|
324
414
|
|
|
@@ -355,7 +445,8 @@ Examples:
|
|
|
355
445
|
|
|
356
446
|
config.activeProfile = selected;
|
|
357
447
|
await saveConfig(config);
|
|
358
|
-
|
|
448
|
+
|
|
449
|
+
await printConnectionStatus(config);
|
|
359
450
|
} catch (e) { handleError(e); }
|
|
360
451
|
});
|
|
361
452
|
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
|
|
2
|
+
import { createClient } from '../api/factory.js';
|
|
3
|
+
import { printTable, handleError } from '../utils.js';
|
|
4
|
+
|
|
5
|
+
export function registerModulesCommands(program) {
|
|
6
|
+
const modules = program.command('module').description('Manage modules');
|
|
7
|
+
|
|
8
|
+
//-------------------------------------------------------
|
|
9
|
+
// "module list" Command
|
|
10
|
+
//-------------------------------------------------------
|
|
11
|
+
modules.command('list')
|
|
12
|
+
.description('List all modules')
|
|
13
|
+
.option('-f, --format <type>', 'Output format (text, json, xml)', 'text')
|
|
14
|
+
.addHelpText('after', `
|
|
15
|
+
Examples:
|
|
16
|
+
$ mage-remote-run module list
|
|
17
|
+
$ mage-remote-run module list --format json
|
|
18
|
+
`)
|
|
19
|
+
.action(async (options) => {
|
|
20
|
+
try {
|
|
21
|
+
const client = await createClient();
|
|
22
|
+
const headers = {};
|
|
23
|
+
// The API endpoint seems to be just a list of strings usually for /V1/modules?
|
|
24
|
+
// Actually standard Magento API GET /V1/modules returns string[].
|
|
25
|
+
|
|
26
|
+
if (options.format === 'json') headers['Accept'] = 'application/json';
|
|
27
|
+
else if (options.format === 'xml') headers['Accept'] = 'application/xml';
|
|
28
|
+
|
|
29
|
+
let data;
|
|
30
|
+
try {
|
|
31
|
+
data = await client.get('V1/modules', {}, { headers });
|
|
32
|
+
} catch (apiError) {
|
|
33
|
+
// Sometimes client.get throws if non-200, which is good.
|
|
34
|
+
throw apiError;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (options.format === 'json') {
|
|
38
|
+
console.log(JSON.stringify(data, null, 2));
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (options.format === 'xml') {
|
|
42
|
+
// If the response was already XML string because of Accept header, data might be the string.
|
|
43
|
+
// But client.get usually parses JSON by default. If Accept is XML, axios might return string.
|
|
44
|
+
// Let's assume data is what we got.
|
|
45
|
+
console.log(data);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Default text format
|
|
50
|
+
// data is expected to be an array of module names strings ["Magento_Store", ...]
|
|
51
|
+
// Map to rows for table
|
|
52
|
+
if (Array.isArray(data)) {
|
|
53
|
+
const rows = data.map(m => [m]);
|
|
54
|
+
printTable(['Module'], rows);
|
|
55
|
+
} else {
|
|
56
|
+
// Fallback if structure is different
|
|
57
|
+
console.log(data);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
} catch (e) { handleError(e); }
|
|
61
|
+
});
|
|
62
|
+
}
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
import { createClient } from '../api/factory.js';
|
|
2
|
+
import { printTable, handleError } from '../utils.js';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import inquirer from 'inquirer';
|
|
5
|
+
|
|
6
|
+
export function registerShipmentCommands(program) {
|
|
7
|
+
const shipments = program.command('shipment').description('Manage shipments');
|
|
8
|
+
|
|
9
|
+
//-------------------------------------------------------
|
|
10
|
+
// "shipment list" Command
|
|
11
|
+
//-------------------------------------------------------
|
|
12
|
+
shipments.command('list')
|
|
13
|
+
.description('List shipments')
|
|
14
|
+
.option('-p, --page <number>', 'Page number', '1')
|
|
15
|
+
.option('-s, --size <number>', 'Page size', '20')
|
|
16
|
+
.option('-f, --format <type>', 'Output format (text, json, xml)', 'text')
|
|
17
|
+
.option('--order-id <id>', 'Filter by Order ID')
|
|
18
|
+
.addHelpText('after', `
|
|
19
|
+
Examples:
|
|
20
|
+
$ mage-remote-run shipment list
|
|
21
|
+
$ mage-remote-run shipment list --page 1 --size 10
|
|
22
|
+
$ mage-remote-run shipment list --format json
|
|
23
|
+
$ mage-remote-run shipment list --order-id 123
|
|
24
|
+
`)
|
|
25
|
+
.action(async (options) => {
|
|
26
|
+
try {
|
|
27
|
+
const client = await createClient();
|
|
28
|
+
const headers = {};
|
|
29
|
+
if (options.format === 'json') headers['Accept'] = 'application/json';
|
|
30
|
+
else if (options.format === 'xml') headers['Accept'] = 'application/xml';
|
|
31
|
+
|
|
32
|
+
const params = {
|
|
33
|
+
'searchCriteria[currentPage]': options.page,
|
|
34
|
+
'searchCriteria[pageSize]': options.size
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
if (options.orderId) {
|
|
38
|
+
params['searchCriteria[filter_groups][0][filters][0][field]'] = 'order_id';
|
|
39
|
+
params['searchCriteria[filter_groups][0][filters][0][value]'] = options.orderId;
|
|
40
|
+
params['searchCriteria[filter_groups][0][filters][0][condition_type]'] = 'eq';
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const data = await client.get('V1/shipments', params, { headers });
|
|
44
|
+
|
|
45
|
+
if (options.format === 'json') {
|
|
46
|
+
console.log(JSON.stringify(data, null, 2));
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (options.format === 'xml') {
|
|
50
|
+
console.log(data);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const rows = (data.items || []).map(s => [
|
|
55
|
+
s.entity_id,
|
|
56
|
+
s.increment_id,
|
|
57
|
+
s.order_id,
|
|
58
|
+
s.total_qty,
|
|
59
|
+
s.created_at
|
|
60
|
+
]);
|
|
61
|
+
console.log(chalk.bold(`Total: ${data.total_count}, Page: ${options.page}, Size: ${options.size}`));
|
|
62
|
+
printTable(['ID', 'Increment ID', 'Order ID', 'Total Qty', 'Created At'], rows);
|
|
63
|
+
} catch (e) { handleError(e); }
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
//-------------------------------------------------------
|
|
67
|
+
// "shipment show" Command
|
|
68
|
+
//-------------------------------------------------------
|
|
69
|
+
shipments.command('show <id>')
|
|
70
|
+
.description('Show shipment details')
|
|
71
|
+
.option('-f, --format <type>', 'Output format (text, json, xml)', 'text')
|
|
72
|
+
.addHelpText('after', `
|
|
73
|
+
Examples:
|
|
74
|
+
$ mage-remote-run shipment show 123
|
|
75
|
+
`)
|
|
76
|
+
.action(async (id, options) => {
|
|
77
|
+
try {
|
|
78
|
+
const client = await createClient();
|
|
79
|
+
const headers = {};
|
|
80
|
+
if (options.format === 'json') headers['Accept'] = 'application/json';
|
|
81
|
+
else if (options.format === 'xml') headers['Accept'] = 'application/xml';
|
|
82
|
+
|
|
83
|
+
let shipment;
|
|
84
|
+
try {
|
|
85
|
+
shipment = await client.get(`V1/shipment/${id}`, {}, { headers });
|
|
86
|
+
} catch (e) {
|
|
87
|
+
// Try to search by increment_id
|
|
88
|
+
const params = {
|
|
89
|
+
'searchCriteria[filter_groups][0][filters][0][field]': 'increment_id',
|
|
90
|
+
'searchCriteria[filter_groups][0][filters][0][value]': id,
|
|
91
|
+
'searchCriteria[filter_groups][0][filters][0][condition_type]': 'eq'
|
|
92
|
+
};
|
|
93
|
+
const searchData = await client.get('V1/shipments', params);
|
|
94
|
+
|
|
95
|
+
if (searchData.items && searchData.items.length > 0) {
|
|
96
|
+
shipment = searchData.items[0];
|
|
97
|
+
// If format is XML, we need to fetch by ID to get XML response
|
|
98
|
+
if (options.format === 'xml') {
|
|
99
|
+
shipment = await client.get(`V1/shipment/${shipment.entity_id}`, {}, { headers });
|
|
100
|
+
}
|
|
101
|
+
} else {
|
|
102
|
+
// If original error was 404, report as not found
|
|
103
|
+
if (e.response && e.response.status === 404) {
|
|
104
|
+
throw new Error(`Shipment ${id} not found.`);
|
|
105
|
+
}
|
|
106
|
+
// Otherwise rethrow original error (e.g. 401, 500)
|
|
107
|
+
throw e;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (options.format === 'json') {
|
|
112
|
+
console.log(JSON.stringify(shipment, null, 2));
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if (options.format === 'xml') {
|
|
116
|
+
console.log(shipment);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
console.log(chalk.bold.blue('\n📦 Shipment Information'));
|
|
121
|
+
console.log(chalk.gray('━'.repeat(50)));
|
|
122
|
+
console.log(`${chalk.bold('ID:')} ${shipment.entity_id}`);
|
|
123
|
+
console.log(`${chalk.bold('Increment ID:')} ${shipment.increment_id}`);
|
|
124
|
+
console.log(`${chalk.bold('Order ID:')} ${shipment.order_id}`);
|
|
125
|
+
console.log(`${chalk.bold('Total Qty:')} ${shipment.total_qty}`);
|
|
126
|
+
console.log(`${chalk.bold('Created At:')} ${shipment.created_at}`);
|
|
127
|
+
|
|
128
|
+
if (shipment.items && shipment.items.length > 0) {
|
|
129
|
+
console.log(chalk.bold('\n🛒 Items'));
|
|
130
|
+
const itemRows = shipment.items.map(item => [
|
|
131
|
+
item.sku,
|
|
132
|
+
item.name,
|
|
133
|
+
Math.floor(item.qty),
|
|
134
|
+
item.price
|
|
135
|
+
]);
|
|
136
|
+
printTable(['SKU', 'Name', 'Qty', 'Price'], itemRows);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (shipment.tracks && shipment.tracks.length > 0) {
|
|
140
|
+
console.log(chalk.bold('\n🚚 Tracking'));
|
|
141
|
+
const trackRows = shipment.tracks.map(track => [
|
|
142
|
+
track.title,
|
|
143
|
+
track.carrier_code,
|
|
144
|
+
track.track_number
|
|
145
|
+
]);
|
|
146
|
+
printTable(['Title', 'Carrier', 'Number'], trackRows);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (shipment.comments && shipment.comments.length > 0) {
|
|
150
|
+
console.log(chalk.bold('\n💬 Comments'));
|
|
151
|
+
const commentRows = shipment.comments.map(c => [
|
|
152
|
+
c.created_at,
|
|
153
|
+
c.comment
|
|
154
|
+
]);
|
|
155
|
+
printTable(['Date', 'Comment'], commentRows);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
} catch (e) { handleError(e); }
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
//-------------------------------------------------------
|
|
162
|
+
// "shipment create" Command
|
|
163
|
+
//-------------------------------------------------------
|
|
164
|
+
shipments.command('create <orderId>')
|
|
165
|
+
.description('Create shipment for an order')
|
|
166
|
+
.option('--notify', 'Notify customer via email')
|
|
167
|
+
.option('--append-comment', 'Append comment')
|
|
168
|
+
.option('--comment <text>', 'Comment text')
|
|
169
|
+
.option('--visible', 'Comment visible on frontend')
|
|
170
|
+
.option('--tracks <json>', 'Tracks array JSON string')
|
|
171
|
+
.option('--items <json>', 'Items array JSON string (if partial shipment)')
|
|
172
|
+
.addHelpText('after', `
|
|
173
|
+
Examples:
|
|
174
|
+
$ mage-remote-run shipment create 123 --notify
|
|
175
|
+
$ mage-remote-run shipment create 123 --tracks '[{"carrier_code":"fedex","title":"FedEx","track_number":"123456"}]'
|
|
176
|
+
`)
|
|
177
|
+
.action(async (orderId, options) => {
|
|
178
|
+
try {
|
|
179
|
+
const client = await createClient();
|
|
180
|
+
const payload = {
|
|
181
|
+
notify: !!options.notify,
|
|
182
|
+
appendComment: !!options.appendComment,
|
|
183
|
+
comment: {
|
|
184
|
+
extension_attributes: {},
|
|
185
|
+
comment: options.comment || '',
|
|
186
|
+
is_visible_on_front: options.visible ? 1 : 0
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
if (options.tracks) {
|
|
191
|
+
payload.tracks = JSON.parse(options.tracks);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (options.items) {
|
|
195
|
+
payload.items = JSON.parse(options.items);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const result = await client.post(`V1/order/${orderId}/ship`, payload);
|
|
199
|
+
console.log(chalk.green(`Shipment created. ID: ${result}`));
|
|
200
|
+
} catch (e) { handleError(e); }
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
//-------------------------------------------------------
|
|
204
|
+
// "shipment label" Command
|
|
205
|
+
//-------------------------------------------------------
|
|
206
|
+
shipments.command('label <id>')
|
|
207
|
+
.description('Retrieve shipping label')
|
|
208
|
+
.addHelpText('after', `
|
|
209
|
+
Examples:
|
|
210
|
+
$ mage-remote-run shipment label 123
|
|
211
|
+
`)
|
|
212
|
+
.action(async (id) => {
|
|
213
|
+
try {
|
|
214
|
+
const client = await createClient();
|
|
215
|
+
const label = await client.get(`V1/shipment/${id}/label`);
|
|
216
|
+
if (label) {
|
|
217
|
+
console.log(label);
|
|
218
|
+
} else {
|
|
219
|
+
console.log(chalk.yellow('No label found.'));
|
|
220
|
+
}
|
|
221
|
+
} catch (e) { handleError(e); }
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
//-------------------------------------------------------
|
|
225
|
+
// "shipment track" Command
|
|
226
|
+
//-------------------------------------------------------
|
|
227
|
+
shipments.command('track <id>')
|
|
228
|
+
.description('Add tracking number to shipment')
|
|
229
|
+
.requiredOption('--carrier <code>', 'Carrier code')
|
|
230
|
+
.requiredOption('--title <title>', 'Carrier title')
|
|
231
|
+
.requiredOption('--number <number>', 'Tracking number')
|
|
232
|
+
.addHelpText('after', `
|
|
233
|
+
Examples:
|
|
234
|
+
$ mage-remote-run shipment track 123 --carrier fedex --title FedEx --number 987654321
|
|
235
|
+
`)
|
|
236
|
+
.action(async (id, options) => {
|
|
237
|
+
try {
|
|
238
|
+
const client = await createClient();
|
|
239
|
+
const payload = {
|
|
240
|
+
entity: {
|
|
241
|
+
order_id: null, // Will be filled by backend logic usually, or we might need order_id?
|
|
242
|
+
// Actually V1/shipment/:id/track requires 'entity' which is SalesDataShipmentTrackInterface
|
|
243
|
+
// Parent ID is the shipment ID.
|
|
244
|
+
parent_id: id,
|
|
245
|
+
carrier_code: options.carrier,
|
|
246
|
+
title: options.title,
|
|
247
|
+
track_number: options.number
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
// Note: The endpoint is POST /V1/shipment/track (Wait, is it /V1/shipments/{id}/...? No, documentation says POST /V1/shipment/track usually, checking...)
|
|
252
|
+
// Standard Magento API: POST /V1/shipment/track
|
|
253
|
+
// Body: { "entity": { "parent_id": ... } }
|
|
254
|
+
|
|
255
|
+
const result = await client.post(`V1/shipment/track`, payload);
|
|
256
|
+
console.log(chalk.green(`Tracking added. ID: ${result}`));
|
|
257
|
+
} catch (e) { handleError(e); }
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
//-------------------------------------------------------
|
|
261
|
+
// "shipment email" Command
|
|
262
|
+
//-------------------------------------------------------
|
|
263
|
+
shipments.command('email <id>')
|
|
264
|
+
.description('Send shipment email')
|
|
265
|
+
.addHelpText('after', `
|
|
266
|
+
Examples:
|
|
267
|
+
$ mage-remote-run shipment email 123
|
|
268
|
+
`)
|
|
269
|
+
.action(async (id) => {
|
|
270
|
+
try {
|
|
271
|
+
const client = await createClient();
|
|
272
|
+
// POST /V1/shipment/{id}/emails
|
|
273
|
+
const result = await client.post(`V1/shipment/${id}/emails`);
|
|
274
|
+
if (result) {
|
|
275
|
+
console.log(chalk.green('Email sent.'));
|
|
276
|
+
} else {
|
|
277
|
+
// Sometimes it returns boolean true/false
|
|
278
|
+
console.log(chalk.green('Email sent signal processed.'));
|
|
279
|
+
}
|
|
280
|
+
} catch (e) { handleError(e); }
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
//-------------------------------------------------------
|
|
284
|
+
// "shipment comments" Command
|
|
285
|
+
//-------------------------------------------------------
|
|
286
|
+
shipments.command('comments <id>')
|
|
287
|
+
.description('Add comment to shipment')
|
|
288
|
+
.requiredOption('--comment <text>', 'Comment text')
|
|
289
|
+
.option('--visible', 'Visible on frontend')
|
|
290
|
+
.option('--notify', 'Notify customer')
|
|
291
|
+
.addHelpText('after', `
|
|
292
|
+
Examples:
|
|
293
|
+
$ mage-remote-run shipment comments 123 --comment "Package is on the way" --notify
|
|
294
|
+
`)
|
|
295
|
+
.action(async (id, options) => {
|
|
296
|
+
try {
|
|
297
|
+
const client = await createClient();
|
|
298
|
+
const payload = {
|
|
299
|
+
entity: {
|
|
300
|
+
parent_id: id,
|
|
301
|
+
comment: options.comment,
|
|
302
|
+
is_visible_on_front: options.visible ? 1 : 0,
|
|
303
|
+
is_customer_notified: options.notify ? 1 : 0
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
// Endpoint: POST /V1/shipment/comments
|
|
307
|
+
// Wait, standard magento is POST /V1/shipment/{id}/comments mostly?
|
|
308
|
+
// Checking standard swagger... POST /V1/shipment/{id}/comments maps to ShipmentCommentRepositoryInterface.save
|
|
309
|
+
// Actually, there is POST /V1/shipment/comments as well?
|
|
310
|
+
// Let's use POST /V1/shipment/{id}/comments
|
|
311
|
+
|
|
312
|
+
// Update: Actually standard Magento might be POST /V1/shipment/comments to create a comment with parent_id in body?
|
|
313
|
+
// Let's check a reliable source or trust the pattern. Order comments are /V1/orders/{id}/comments.
|
|
314
|
+
// Shipment comments... Magento 2.4 REST API docs:
|
|
315
|
+
// POST /V1/shipment/{id}/comments -> salesShipmentCommentRepositoryV1
|
|
316
|
+
// Body: { entity: { ... } }
|
|
317
|
+
|
|
318
|
+
// Also common is POST /V1/shipment/comments (no ID in URL) -> same repo?
|
|
319
|
+
// Let's use the ID in URL one if possible, but let's stick to /V1/shipment/{id}/comments if we can confirm it exists.
|
|
320
|
+
// If not sure, standard practice.
|
|
321
|
+
|
|
322
|
+
// Let's try /V1/shipment/:id/comments
|
|
323
|
+
const result = await client.post(`V1/shipment/${id}/comments`, payload);
|
|
324
|
+
console.log(chalk.green(`Comment added. ID: ${result.entity_id || result}`));
|
|
325
|
+
} catch (e) { handleError(e); }
|
|
326
|
+
});
|
|
327
|
+
}
|
package/lib/config.js
CHANGED
|
@@ -18,6 +18,7 @@ const OLD_CONFIG_DIR = paths.config;
|
|
|
18
18
|
const OLD_CONFIG_FILE = path.join(OLD_CONFIG_DIR, 'config.json');
|
|
19
19
|
|
|
20
20
|
async function migrateOldConfig() {
|
|
21
|
+
// print platform
|
|
21
22
|
if (process.platform !== 'darwin') {
|
|
22
23
|
return;
|
|
23
24
|
}
|
|
@@ -55,7 +56,9 @@ export async function saveConfig(config) {
|
|
|
55
56
|
try {
|
|
56
57
|
await mkdirp(CONFIG_DIR);
|
|
57
58
|
fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2));
|
|
58
|
-
|
|
59
|
+
if (process.env.DEBUG) {
|
|
60
|
+
console.log(`Configuration saved to ${CONFIG_FILE}`);
|
|
61
|
+
}
|
|
59
62
|
} catch (e) {
|
|
60
63
|
console.error("Error saving config:", e.message);
|
|
61
64
|
throw e;
|
package/lib/mcp.js
CHANGED
|
@@ -62,8 +62,8 @@ export async function startMcpServer(options) {
|
|
|
62
62
|
|
|
63
63
|
} else {
|
|
64
64
|
// STDIO
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
console.error(`Protocol: stdio`);
|
|
66
|
+
console.error(`Registered Tools: ${toolsCount}`);
|
|
67
67
|
const transport = new StdioServerTransport();
|
|
68
68
|
await server.connect(transport);
|
|
69
69
|
}
|
|
@@ -82,7 +82,7 @@ function registerTools(server, program) {
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
// It's a leaf command, register as tool
|
|
85
|
-
// Tool name: Replace spaces/colons with underscores.
|
|
85
|
+
// Tool name: Replace spaces/colons with underscores.
|
|
86
86
|
// Example: website list -> website_list
|
|
87
87
|
const toolName = cmdName.replace(/[^a-zA-Z0-9_]/g, '_');
|
|
88
88
|
|
|
@@ -105,7 +105,7 @@ function registerTools(server, program) {
|
|
|
105
105
|
|
|
106
106
|
cmd.options.forEach(opt => {
|
|
107
107
|
const name = opt.name(); // e.g. "format" for --format
|
|
108
|
-
// Check flags to guess type.
|
|
108
|
+
// Check flags to guess type.
|
|
109
109
|
// -f, --format <type> -> string
|
|
110
110
|
// -v, --verbose -> boolean
|
|
111
111
|
|
|
@@ -186,9 +186,9 @@ async function executeCommand(cmdDefinition, args, parentName) {
|
|
|
186
186
|
// Wait, registerTools calls: `executeCommand(cmd, args, parentName)`
|
|
187
187
|
// If parentName is "website", and cmd is "list", we need "website list"
|
|
188
188
|
|
|
189
|
-
// NOTE: parentName in processCommand is built recursively with underscores?
|
|
190
|
-
// In processCommand(subCmd, cmdName), cmdName is "parent_sub".
|
|
191
|
-
// So if we have website -> list.
|
|
189
|
+
// NOTE: parentName in processCommand is built recursively with underscores?
|
|
190
|
+
// In processCommand(subCmd, cmdName), cmdName is "parent_sub".
|
|
191
|
+
// So if we have website -> list.
|
|
192
192
|
// processCommand(website) -> processCommand(list, "website")
|
|
193
193
|
// parentName in executeCommand is "website".
|
|
194
194
|
// cmd.name() is "list".
|
|
@@ -212,7 +212,7 @@ async function executeCommand(cmdDefinition, args, parentName) {
|
|
|
212
212
|
// `cmdName` = `parentName_cmd.name()`.
|
|
213
213
|
// So for `website list`:
|
|
214
214
|
// `processCommand(website, '')` -> `cmdName="website"`.
|
|
215
|
-
// -> `processCommand(list, "website")`.
|
|
215
|
+
// -> `processCommand(list, "website")`.
|
|
216
216
|
// -> register tool "website_list". `parentName` passed to execute is "website".
|
|
217
217
|
|
|
218
218
|
// So `parentName` is the accumulated prefix with underscores.
|