mage-remote-run 0.17.0 → 0.18.0
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/company.js +6 -4
- package/lib/commands/console.js +8 -6
- package/lib/utils.js +27 -1
- package/package.json +1 -1
package/lib/commands/company.js
CHANGED
|
@@ -226,14 +226,16 @@ Examples:
|
|
|
226
226
|
const answers = await inquirer.prompt([
|
|
227
227
|
{ name: 'company_name', message: 'Company Name:', default: current.company_name },
|
|
228
228
|
{ name: 'company_email', message: 'Company Email:', default: current.company_email },
|
|
229
|
-
{ name: 'sales_representative_id', message: 'Sales Rep ID:', default: current.sales_representative_id },
|
|
230
|
-
{ name: 'customer_group_id', message: 'Customer Group ID:', default: current.customer_group_id }
|
|
229
|
+
{ name: 'sales_representative_id', message: 'Sales Rep ID:', default: String(current.sales_representative_id) },
|
|
230
|
+
{ name: 'customer_group_id', message: 'Customer Group ID:', default: String(current.customer_group_id) }
|
|
231
231
|
]);
|
|
232
232
|
|
|
233
233
|
// Merge
|
|
234
234
|
const payload = {
|
|
235
|
-
|
|
236
|
-
|
|
235
|
+
company: {
|
|
236
|
+
...current,
|
|
237
|
+
...answers
|
|
238
|
+
}
|
|
237
239
|
};
|
|
238
240
|
|
|
239
241
|
await client.put(`V1/company/${companyId}`, payload);
|
package/lib/commands/console.js
CHANGED
|
@@ -18,12 +18,14 @@ export function registerConsoleCommand(program) {
|
|
|
18
18
|
console.log(chalk.gray('Debug mode enabled'));
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
if (process.env.NODE_ENV !== 'test') {
|
|
22
|
+
console.log(chalk.bold.blue('Mage Remote Run Interactive Console'));
|
|
23
|
+
console.log(chalk.gray('Type your commands directly or write JS code.'));
|
|
24
|
+
console.log(chalk.gray('Global variables available: client (async factory), config, chalk'));
|
|
25
|
+
console.log(chalk.gray('Example JS: await (await client()).get("V1/store/websites")'));
|
|
26
|
+
console.log(chalk.gray('Type "list" to see available commands.'));
|
|
27
|
+
console.log(chalk.gray('Type .exit to quit.\n'));
|
|
28
|
+
}
|
|
27
29
|
|
|
28
30
|
// State for the REPL
|
|
29
31
|
let localProgram;
|
package/lib/utils.js
CHANGED
|
@@ -11,7 +11,33 @@ export function printTable(headers, data) {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export function handleError(error) {
|
|
14
|
-
|
|
14
|
+
let message = error.message;
|
|
15
|
+
|
|
16
|
+
// specific handling for Magento API Errors which are often JSON stringified
|
|
17
|
+
// Format: "API Error 404: {...}"
|
|
18
|
+
const apiErrorMatch = message.match(/^API Error (\d+): (.+)$/);
|
|
19
|
+
if (apiErrorMatch) {
|
|
20
|
+
const statusCode = apiErrorMatch[1];
|
|
21
|
+
const jsonPart = apiErrorMatch[2];
|
|
22
|
+
try {
|
|
23
|
+
const parsed = JSON.parse(jsonPart);
|
|
24
|
+
if (parsed.message) {
|
|
25
|
+
let prettyMessage = parsed.message;
|
|
26
|
+
if (parsed.parameters) {
|
|
27
|
+
// Substitute %fieldName with values
|
|
28
|
+
Object.keys(parsed.parameters).forEach(key => {
|
|
29
|
+
prettyMessage = prettyMessage.replace(new RegExp(`%${key}`, 'g'), parsed.parameters[key]);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
message = `${prettyMessage}`;
|
|
33
|
+
// Optional: append status code if not 200? The user request just showed the clean message.
|
|
34
|
+
}
|
|
35
|
+
} catch (e) {
|
|
36
|
+
// If parsing fails, keep original message
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
console.error(chalk.red('Error:'), message);
|
|
15
41
|
if (process.env.DEBUG) {
|
|
16
42
|
console.error(error);
|
|
17
43
|
}
|