mage-remote-run 0.4.0 ā 0.6.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/bin/mage-remote-run.js +52 -8
- package/lib/commands/adobe-io-events.js +61 -0
- package/lib/commands/company.js +115 -0
- package/lib/commands/connections.js +15 -0
- package/lib/commands/webhooks.js +48 -0
- package/lib/commands/websites.js +17 -2
- package/lib/config.js +2 -1
- package/package.json +1 -1
package/bin/mage-remote-run.js
CHANGED
|
@@ -24,21 +24,65 @@ import { registerCustomersCommands } from '../lib/commands/customers.js';
|
|
|
24
24
|
import { registerOrdersCommands } from '../lib/commands/orders.js';
|
|
25
25
|
import { registerEavCommands } from '../lib/commands/eav.js';
|
|
26
26
|
import { registerProductsCommands } from '../lib/commands/products.js';
|
|
27
|
+
import { registerCompanyCommands } from '../lib/commands/company.js';
|
|
27
28
|
import { registerTaxCommands } from '../lib/commands/tax.js';
|
|
28
29
|
import { registerInventoryCommands } from '../lib/commands/inventory.js';
|
|
30
|
+
import { registerAdobeIoEventsCommands } from '../lib/commands/adobe-io-events.js';
|
|
31
|
+
import { registerWebhooksCommands } from '../lib/commands/webhooks.js';
|
|
32
|
+
import { getActiveProfile } from '../lib/config.js';
|
|
29
33
|
|
|
30
34
|
registerConnectionCommands(program);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
|
|
36
|
+
const profile = await getActiveProfile();
|
|
37
|
+
|
|
38
|
+
if (profile) {
|
|
39
|
+
registerWebsitesCommands(program);
|
|
40
|
+
registerStoresCommands(program);
|
|
41
|
+
registerCustomersCommands(program);
|
|
42
|
+
registerOrdersCommands(program);
|
|
43
|
+
registerEavCommands(program);
|
|
44
|
+
registerProductsCommands(program);
|
|
45
|
+
registerTaxCommands(program);
|
|
46
|
+
registerInventoryCommands(program);
|
|
47
|
+
|
|
48
|
+
if (profile.type === 'ac-cloud-paas' || profile.type === 'ac-saas') {
|
|
49
|
+
registerAdobeIoEventsCommands(program);
|
|
50
|
+
registerCompanyCommands(program);
|
|
51
|
+
registerWebhooksCommands(program);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
program.hook('preAction', async (thisCommand, actionCommand) => {
|
|
56
|
+
// Check if we have an active profile and if format is not json/xml
|
|
57
|
+
// Note: 'options' are available on the command that has them defined.
|
|
58
|
+
// actionCommand is the command actually being executed.
|
|
59
|
+
if (profile) {
|
|
60
|
+
const config = await loadConfig();
|
|
61
|
+
if (config.showActiveConnectionHeader !== false) {
|
|
62
|
+
const opts = actionCommand.opts();
|
|
63
|
+
if (opts.format !== 'json' && opts.format !== 'xml') {
|
|
64
|
+
console.log(chalk.cyan(`Active Connection: ${chalk.bold(profile.name)} (${profile.type})`));
|
|
65
|
+
console.log(chalk.gray('ā'.repeat(60)) + '\n');
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
});
|
|
39
70
|
|
|
40
71
|
function resolveCommandMatch(parent, token) {
|
|
41
72
|
const tokenLower = token.toLowerCase();
|
|
73
|
+
|
|
74
|
+
// Check for exact match first
|
|
75
|
+
const exactMatch = parent.commands.find((cmd) => {
|
|
76
|
+
return cmd.name().toLowerCase() === tokenLower;
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
if (exactMatch) {
|
|
80
|
+
return {
|
|
81
|
+
match: exactMatch,
|
|
82
|
+
matches: [exactMatch]
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
42
86
|
const matches = parent.commands.filter((cmd) => {
|
|
43
87
|
const name = cmd.name().toLowerCase();
|
|
44
88
|
if (name.startsWith(tokenLower)) return true;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { createClient } from '../api/factory.js';
|
|
2
|
+
import { printTable, handleError } from '../utils.js';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
|
|
5
|
+
export function registerAdobeIoEventsCommands(program) {
|
|
6
|
+
const adobeIoEvents = program.command('adobe-io-event').description('Manage Adobe I/O Events');
|
|
7
|
+
|
|
8
|
+
adobeIoEvents.command('check-configuration')
|
|
9
|
+
.description('Check Adobe I/O Event configuration')
|
|
10
|
+
.option('-f, --format <type>', 'Output format (text, json, xml)', 'text')
|
|
11
|
+
.action(async (options) => {
|
|
12
|
+
try {
|
|
13
|
+
const client = await createClient();
|
|
14
|
+
const headers = {};
|
|
15
|
+
if (options.format === 'json') headers['Accept'] = 'application/json';
|
|
16
|
+
else if (options.format === 'xml') headers['Accept'] = 'application/xml';
|
|
17
|
+
|
|
18
|
+
// The endpoint is likely returning a simple boolean/string or a small object.
|
|
19
|
+
// Based on standard Magento APIs, let's assume it returns a boolean or object.
|
|
20
|
+
// We'll inspect the data structure.
|
|
21
|
+
const data = await client.get('V1/adobe_io_events/check_configuration', {}, { headers });
|
|
22
|
+
|
|
23
|
+
if (options.format === 'json') {
|
|
24
|
+
console.log(JSON.stringify(data, null, 2));
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (options.format === 'xml') {
|
|
28
|
+
console.log(data);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
console.log(chalk.bold.blue('\nš Configuration Check Result'));
|
|
33
|
+
console.log(chalk.gray('ā'.repeat(60)));
|
|
34
|
+
|
|
35
|
+
if (typeof data === 'object' && data !== null) {
|
|
36
|
+
if (Array.isArray(data)) {
|
|
37
|
+
console.log(JSON.stringify(data, null, 2));
|
|
38
|
+
} else {
|
|
39
|
+
Object.entries(data).forEach(([key, value]) => {
|
|
40
|
+
const label = key.replace(/_/g, ' ').replace(/\b\w/g, l => l.toUpperCase());
|
|
41
|
+
|
|
42
|
+
let displayValue = value;
|
|
43
|
+
if (typeof value === 'boolean') {
|
|
44
|
+
displayValue = value ? chalk.green('Yes') : chalk.red('No');
|
|
45
|
+
} else if (value === null) {
|
|
46
|
+
displayValue = chalk.gray('null');
|
|
47
|
+
} else if (typeof value === 'object') {
|
|
48
|
+
displayValue = JSON.stringify(value);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
console.log(` ${chalk.bold(label + ':').padEnd(35)} ${displayValue}`);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
} else {
|
|
55
|
+
console.log(` ${data}`);
|
|
56
|
+
}
|
|
57
|
+
console.log('');
|
|
58
|
+
|
|
59
|
+
} catch (e) { handleError(e); }
|
|
60
|
+
});
|
|
61
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { createClient } from '../api/factory.js';
|
|
2
|
+
import { printTable, handleError } from '../utils.js';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
|
|
5
|
+
export function registerCompanyCommands(program) {
|
|
6
|
+
const company = program.command('company').description('Manage companies');
|
|
7
|
+
|
|
8
|
+
company.command('list')
|
|
9
|
+
.description('List companies')
|
|
10
|
+
.option('-p, --page <number>', 'Page number', '1')
|
|
11
|
+
.option('-s, --size <number>', 'Page size', '20')
|
|
12
|
+
.option('--sort-by <field>', 'Field to sort by', 'entity_id')
|
|
13
|
+
.option('--sort-order <order>', 'Sort order (ASC, DESC)', 'ASC')
|
|
14
|
+
.option('-f, --format <type>', 'Output format (text, json, xml)', 'text')
|
|
15
|
+
.action(async (options) => {
|
|
16
|
+
try {
|
|
17
|
+
const client = await createClient();
|
|
18
|
+
const headers = {};
|
|
19
|
+
if (options.format === 'json') headers['Accept'] = 'application/json';
|
|
20
|
+
else if (options.format === 'xml') headers['Accept'] = 'application/xml';
|
|
21
|
+
|
|
22
|
+
const params = {
|
|
23
|
+
'searchCriteria[currentPage]': options.page,
|
|
24
|
+
'searchCriteria[pageSize]': options.size,
|
|
25
|
+
'searchCriteria[sortOrders][0][field]': options.sortBy,
|
|
26
|
+
'searchCriteria[sortOrders][0][direction]': options.sortOrder
|
|
27
|
+
};
|
|
28
|
+
const data = await client.get('V1/company', params, { headers });
|
|
29
|
+
|
|
30
|
+
if (options.format === 'json') {
|
|
31
|
+
console.log(JSON.stringify(data, null, 2));
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (options.format === 'xml') {
|
|
35
|
+
console.log(data);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// ID, Name, Email, Status, Rejected Reason
|
|
40
|
+
const rows = (data.items || []).map(c => [
|
|
41
|
+
c.id,
|
|
42
|
+
c.company_name,
|
|
43
|
+
c.company_email,
|
|
44
|
+
c.status,
|
|
45
|
+
c.sales_representative_id || '-'
|
|
46
|
+
]);
|
|
47
|
+
console.log(chalk.bold(`Total: ${data.total_count}, Page: ${options.page}, Size: ${options.size}`));
|
|
48
|
+
printTable(['ID', 'Name', 'Email', 'Status', 'Sales Rep ID'], rows);
|
|
49
|
+
} catch (e) { handleError(e); }
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
company.command('show <companyId>')
|
|
53
|
+
.description('Show company details')
|
|
54
|
+
.option('-f, --format <type>', 'Output format (text, json, xml)', 'text')
|
|
55
|
+
.action(async (companyId, options) => {
|
|
56
|
+
try {
|
|
57
|
+
const client = await createClient();
|
|
58
|
+
let headers = {};
|
|
59
|
+
if (options.format === 'json') headers['Accept'] = 'application/json';
|
|
60
|
+
else if (options.format === 'xml') headers['Accept'] = 'application/xml';
|
|
61
|
+
|
|
62
|
+
let data;
|
|
63
|
+
try {
|
|
64
|
+
data = await client.get(`V1/company/${encodeURIComponent(companyId)}`, {}, { headers });
|
|
65
|
+
} catch (e) {
|
|
66
|
+
throw new Error(`Company '${companyId}' not found.`);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (options.format === 'json') {
|
|
70
|
+
console.log(JSON.stringify(data, null, 2));
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (options.format === 'xml') {
|
|
74
|
+
console.log(data);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
console.log(chalk.bold.blue('\nš¢ Company Information'));
|
|
79
|
+
console.log(chalk.gray('ā'.repeat(60)));
|
|
80
|
+
|
|
81
|
+
// General
|
|
82
|
+
console.log(chalk.bold('\nā¹ļø General Information'));
|
|
83
|
+
console.log(` ${chalk.bold('ID:')} ${data.id}`);
|
|
84
|
+
console.log(` ${chalk.bold('Name:')} ${data.company_name}`);
|
|
85
|
+
console.log(` ${chalk.bold('Email:')} ${data.company_email}`);
|
|
86
|
+
console.log(` ${chalk.bold('Status:')} ${data.status}`);
|
|
87
|
+
console.log(` ${chalk.bold('Rejected Reason:')} ${data.reject_reason || '-'}`);
|
|
88
|
+
console.log(` ${chalk.bold('Sales Rep ID:')} ${data.sales_representative_id || '-'}`);
|
|
89
|
+
|
|
90
|
+
// Address
|
|
91
|
+
// Usually address info is nested or separate, but V1/company might return it directly
|
|
92
|
+
if (data.street) {
|
|
93
|
+
console.log(chalk.bold('\nš Address'));
|
|
94
|
+
console.log(` ${chalk.bold('Street:')} ${data.street}`);
|
|
95
|
+
console.log(` ${chalk.bold('City:')} ${data.city}`);
|
|
96
|
+
console.log(` ${chalk.bold('Region:')} ${data.region}`);
|
|
97
|
+
console.log(` ${chalk.bold('Postcode:')} ${data.postcode}`);
|
|
98
|
+
console.log(` ${chalk.bold('Country:')} ${data.country_id}`);
|
|
99
|
+
console.log(` ${chalk.bold('Phone:')} ${data.telephone}`);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Extension Attributes
|
|
103
|
+
if (data.extension_attributes && data.extension_attributes.applicable_payment_method) {
|
|
104
|
+
console.log(chalk.bold('\nš³ Payment Methods'));
|
|
105
|
+
const methods = data.extension_attributes.applicable_payment_method.length > 0
|
|
106
|
+
? data.extension_attributes.applicable_payment_method.join(', ')
|
|
107
|
+
: 'None';
|
|
108
|
+
console.log(` ${methods}`);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
console.log(chalk.gray('ā'.repeat(60)));
|
|
112
|
+
|
|
113
|
+
} catch (e) { handleError(e); }
|
|
114
|
+
});
|
|
115
|
+
}
|
|
@@ -220,4 +220,19 @@ export function registerConnectionCommands(program) {
|
|
|
220
220
|
console.log(chalk.green('Token cache cleared.'));
|
|
221
221
|
} catch (e) { handleError(e); }
|
|
222
222
|
});
|
|
223
|
+
|
|
224
|
+
connections.command('status-header <state>')
|
|
225
|
+
.description('Enable or disable the active connection header (on|off)')
|
|
226
|
+
.action(async (state) => {
|
|
227
|
+
try {
|
|
228
|
+
if (state !== 'on' && state !== 'off') {
|
|
229
|
+
console.error(chalk.red('Invalid state. Use "on" or "off".'));
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
const config = await loadConfig();
|
|
233
|
+
config.showActiveConnectionHeader = state === 'on';
|
|
234
|
+
await saveConfig(config);
|
|
235
|
+
console.log(chalk.green(`Active connection header is now ${state === 'on' ? 'enabled' : 'disabled'}.`));
|
|
236
|
+
} catch (e) { handleError(e); }
|
|
237
|
+
});
|
|
223
238
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { createClient } from '../api/factory.js';
|
|
2
|
+
import { printTable, handleError } from '../utils.js';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
|
|
5
|
+
export function registerWebhooksCommands(program) {
|
|
6
|
+
const webhooks = program.command('webhook').description('Manage webhooks');
|
|
7
|
+
|
|
8
|
+
webhooks.command('list')
|
|
9
|
+
.description('List available webhooks')
|
|
10
|
+
.option('-p, --page <number>', 'Page number', '1')
|
|
11
|
+
.option('-s, --size <number>', 'Page size', '20')
|
|
12
|
+
.option('-f, --format <type>', 'Output format (text, json, xml)', 'text')
|
|
13
|
+
.action(async (options) => {
|
|
14
|
+
try {
|
|
15
|
+
const client = await createClient();
|
|
16
|
+
const headers = {};
|
|
17
|
+
if (options.format === 'json') headers['Accept'] = 'application/json';
|
|
18
|
+
else if (options.format === 'xml') headers['Accept'] = 'application/xml';
|
|
19
|
+
|
|
20
|
+
const params = {
|
|
21
|
+
'searchCriteria[currentPage]': options.page,
|
|
22
|
+
'searchCriteria[pageSize]': options.size
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const data = await client.get('V1/webhooks/list', params, { headers });
|
|
26
|
+
|
|
27
|
+
if (options.format === 'json') {
|
|
28
|
+
console.log(JSON.stringify(data, null, 2));
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (options.format === 'xml') {
|
|
32
|
+
console.log(data);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const rows = (data.items || []).map(w => [
|
|
37
|
+
w.hook_id,
|
|
38
|
+
w.name,
|
|
39
|
+
w.status,
|
|
40
|
+
w.store_ids ? w.store_ids.join(',') : '-',
|
|
41
|
+
w.url
|
|
42
|
+
]);
|
|
43
|
+
|
|
44
|
+
console.log(chalk.bold(`Total: ${data.total_count}, Page: ${options.page}, Size: ${options.size}`));
|
|
45
|
+
printTable(['ID', 'Name', 'Status', 'Store IDs', 'URL'], rows);
|
|
46
|
+
} catch (e) { handleError(e); }
|
|
47
|
+
});
|
|
48
|
+
}
|
package/lib/commands/websites.js
CHANGED
|
@@ -8,10 +8,25 @@ export function registerWebsitesCommands(program) {
|
|
|
8
8
|
|
|
9
9
|
websites.command('list')
|
|
10
10
|
.description('List all websites')
|
|
11
|
-
.
|
|
11
|
+
.option('-f, --format <type>', 'Output format (text, json, xml)', 'text')
|
|
12
|
+
.action(async (options) => {
|
|
12
13
|
try {
|
|
13
14
|
const client = await createClient();
|
|
14
|
-
const
|
|
15
|
+
const headers = {};
|
|
16
|
+
if (options.format === 'json') headers['Accept'] = 'application/json';
|
|
17
|
+
else if (options.format === 'xml') headers['Accept'] = 'application/xml';
|
|
18
|
+
|
|
19
|
+
const data = await client.get('V1/store/websites', {}, { headers });
|
|
20
|
+
|
|
21
|
+
if (options.format === 'json') {
|
|
22
|
+
console.log(JSON.stringify(data, null, 2));
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (options.format === 'xml') {
|
|
26
|
+
console.log(data);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
15
30
|
const rows = data.map(w => [w.id, w.code, w.name, w.default_group_id]);
|
|
16
31
|
printTable(['ID', 'Code', 'Name', 'Def Group ID'], rows);
|
|
17
32
|
} catch (e) { handleError(e); }
|
package/lib/config.js
CHANGED
|
@@ -48,7 +48,8 @@ export async function getActiveProfile() {
|
|
|
48
48
|
if (!config.activeProfile || !config.profiles[config.activeProfile]) {
|
|
49
49
|
return null;
|
|
50
50
|
}
|
|
51
|
-
|
|
51
|
+
const profile = config.profiles[config.activeProfile];
|
|
52
|
+
return { ...profile, name: config.activeProfile };
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
export function getConfigPath() {
|