@magentrix-corp/magentrix-cli 1.3.14 → 1.3.15
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/actions/setup.js
CHANGED
|
@@ -6,6 +6,7 @@ import { ensureVSCodeFileAssociation } from "../utils/preferences.js";
|
|
|
6
6
|
import { CWD, EXPORT_ROOT, HASHED_CWD } from "../vars/global.js";
|
|
7
7
|
import { select } from "@inquirer/prompts";
|
|
8
8
|
import { registerWorkspace } from "../utils/workspaces.js";
|
|
9
|
+
import debug from '../utils/debug.js';
|
|
9
10
|
|
|
10
11
|
const config = new Config();
|
|
11
12
|
|
|
@@ -52,6 +53,9 @@ export const setup = async (cliOptions = {}) => {
|
|
|
52
53
|
let authSuccess = false;
|
|
53
54
|
let apiKey, instanceUrl, tokenData;
|
|
54
55
|
|
|
56
|
+
debug.log('SETUP', `Starting setup (pathHash: ${HASHED_CWD}, CWD: ${CWD})`);
|
|
57
|
+
debug.log('SETUP', `CLI options provided: apiKey=${cliOptions.apiKey ? 'yes' : 'no'}, instanceUrl=${cliOptions.instanceUrl || 'no'}`);
|
|
58
|
+
|
|
55
59
|
while (!authSuccess) {
|
|
56
60
|
// Get API key (from CLI or prompt)
|
|
57
61
|
apiKey = cliOptions.apiKey
|
|
@@ -63,11 +67,15 @@ export const setup = async (cliOptions = {}) => {
|
|
|
63
67
|
? cliOptions.instanceUrl.trim()
|
|
64
68
|
: await ensureInstanceUrl(true);
|
|
65
69
|
|
|
70
|
+
debug.log('SETUP', `Attempting authentication with instance: ${instanceUrl}`);
|
|
71
|
+
|
|
66
72
|
// Validate credentials by attempting to fetch an access token
|
|
67
73
|
try {
|
|
68
74
|
tokenData = await tryAuthenticate(apiKey, instanceUrl);
|
|
75
|
+
debug.log('SETUP', 'Authentication successful');
|
|
69
76
|
authSuccess = true;
|
|
70
77
|
} catch (error) {
|
|
78
|
+
debug.log('SETUP', `Authentication failed: ${error.message}`);
|
|
71
79
|
console.log(error.message);
|
|
72
80
|
console.log();
|
|
73
81
|
|
|
@@ -105,6 +113,7 @@ export const setup = async (cliOptions = {}) => {
|
|
|
105
113
|
console.log(); // Blank line for spacing
|
|
106
114
|
|
|
107
115
|
// Save values since authentication succeeded
|
|
116
|
+
debug.log('SETUP', `Saving credentials for pathHash: ${HASHED_CWD}`);
|
|
108
117
|
config.save('instanceUrl', instanceUrl, { global: true, pathHash: HASHED_CWD });
|
|
109
118
|
console.log('✅ Instance URL saved securely!');
|
|
110
119
|
|
package/package.json
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import debug from '../debug.js';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Checks if the provided Magentrix instance URL is reachable by making a GET request.
|
|
3
5
|
* Throws an error if the response status is not 200 (OK), or if there is a network error.
|
|
@@ -8,6 +10,7 @@
|
|
|
8
10
|
* @returns {Promise<void>} Resolves if the instance is reachable (status 200); otherwise throws.
|
|
9
11
|
*/
|
|
10
12
|
export const checkInstanceUrl = async (instanceUrl) => {
|
|
13
|
+
debug.log('URL-CHECK', `Checking reachability: GET ${instanceUrl}`);
|
|
11
14
|
try {
|
|
12
15
|
// Native fetch is available in Node 18+; for older versions, use node-fetch.
|
|
13
16
|
const response = await fetch(instanceUrl, {
|
|
@@ -15,15 +18,28 @@ export const checkInstanceUrl = async (instanceUrl) => {
|
|
|
15
18
|
// You can add a small timeout here using AbortController if needed.
|
|
16
19
|
});
|
|
17
20
|
|
|
21
|
+
debug.log('URL-CHECK', `Response: ${response.status} ${response.statusText}`);
|
|
22
|
+
|
|
18
23
|
if (response.status !== 200) {
|
|
19
24
|
throw new Error(
|
|
20
25
|
`Instance URL responded with status ${response.status} (${response.statusText}). Expected 200 OK.`
|
|
21
26
|
);
|
|
22
27
|
}
|
|
23
28
|
} catch (err) {
|
|
29
|
+
// Node's fetch wraps the real error in err.cause (e.g. ENOTFOUND, ECONNREFUSED, ETIMEDOUT)
|
|
30
|
+
const cause = err.cause || {};
|
|
31
|
+
const rootCode = cause.code || '';
|
|
32
|
+
const rootMsg = cause.message || '';
|
|
33
|
+
const detail = rootCode ? `${rootCode}: ${rootMsg}` : (err.message || String(err));
|
|
34
|
+
|
|
35
|
+
debug.log('URL-CHECK', `Failed: ${detail}`);
|
|
36
|
+
if (cause.code) debug.log('URL-CHECK', `Error code: ${cause.code}`);
|
|
37
|
+
if (cause.hostname) debug.log('URL-CHECK', `Hostname: ${cause.hostname}`);
|
|
38
|
+
if (err.stack) debug.log('URL-CHECK', `Stack: ${err.stack}`);
|
|
39
|
+
|
|
24
40
|
// Wrap and re-throw to provide a clear error message.
|
|
25
41
|
throw new Error(
|
|
26
|
-
`Failed to reach instance URL "${instanceUrl}": ${
|
|
42
|
+
`Failed to reach instance URL "${instanceUrl}": ${detail}`
|
|
27
43
|
);
|
|
28
44
|
}
|
|
29
45
|
};
|
|
@@ -36,7 +36,7 @@ export async function ensureValidCredentials() {
|
|
|
36
36
|
|
|
37
37
|
// If missing API key or URL, prompt/setup immediately
|
|
38
38
|
if (!apiKey || !instanceUrl) {
|
|
39
|
-
debug.auth(
|
|
39
|
+
debug.auth(`Missing credentials for this directory (pathHash: ${HASHED_CWD}). No API key or instance URL found in global config for this workspace. This usually means 'magentrix setup' was never run from this directory, or was run from a different path. Falling back to setup wizard.`);
|
|
40
40
|
return setup();
|
|
41
41
|
}
|
|
42
42
|
|
|
@@ -3,6 +3,7 @@ import Config from "../../config.js";
|
|
|
3
3
|
import { checkInstanceUrl } from "../checkInstanceUrl.js";
|
|
4
4
|
import { withSpinner } from "../../spinner.js";
|
|
5
5
|
import { HASHED_CWD } from "../../../vars/global.js";
|
|
6
|
+
import debug from '../../debug.js';
|
|
6
7
|
|
|
7
8
|
const config = new Config();
|
|
8
9
|
const urlRegex = /^https:\/\/[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
|
|
@@ -45,13 +46,16 @@ export const ensureInstanceUrl = async (forcePrompt = false) => {
|
|
|
45
46
|
const trimmed = inputUrl.trim().replace(/\/+$/, '');
|
|
46
47
|
|
|
47
48
|
// Now check reachability WITH a spinner
|
|
49
|
+
debug.log('SETUP', `User entered instance URL: ${trimmed}`);
|
|
48
50
|
try {
|
|
49
51
|
await withSpinner('Checking instance URL...', () =>
|
|
50
52
|
checkInstanceUrl(trimmed)
|
|
51
53
|
);
|
|
52
54
|
|
|
55
|
+
debug.log('SETUP', `Instance URL reachable: ${trimmed}`);
|
|
53
56
|
return trimmed;
|
|
54
57
|
} catch (error) {
|
|
58
|
+
debug.log('SETUP', `Instance URL not reachable: ${trimmed} — ${error.message}`);
|
|
55
59
|
// Print error AFTER spinner, then re-prompt
|
|
56
60
|
console.error('❌ Instance URL not reachable. Try again.');
|
|
57
61
|
}
|
package/utils/magentrix/fetch.js
CHANGED
|
@@ -84,7 +84,11 @@ export const fetchMagentrix = async ({
|
|
|
84
84
|
body: requestBody
|
|
85
85
|
});
|
|
86
86
|
} catch (err) {
|
|
87
|
-
|
|
87
|
+
const cause = err.cause || {};
|
|
88
|
+
const rootDetail = cause.code ? `${cause.code}: ${cause.message || ''}` : '';
|
|
89
|
+
debug.log('HTTP-ERR', `Network error: ${err.message}${rootDetail ? ` (${rootDetail})` : ''}`);
|
|
90
|
+
if (cause.code) debug.log('HTTP-ERR', `Error code: ${cause.code}, hostname: ${cause.hostname || 'N/A'}`);
|
|
91
|
+
if (err.stack) debug.log('HTTP-ERR', `Stack: ${err.stack}`);
|
|
88
92
|
const errorObj = {
|
|
89
93
|
type: 'network',
|
|
90
94
|
message: `Network error contacting Magentrix API: ${err.message}`,
|