@memnexus-ai/cli 1.7.201 → 1.7.202
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/dist/commands/auth.d.ts.map +1 -1
- package/dist/commands/auth.js +56 -6
- package/dist/commands/auth.js.map +1 -1
- package/dist/lib/auth.d.ts +30 -2
- package/dist/lib/auth.d.ts.map +1 -1
- package/dist/lib/auth.js +54 -5
- package/dist/lib/auth.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/commands/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/commands/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAYpC;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAwN3D"}
|
package/dist/commands/auth.js
CHANGED
|
@@ -7,6 +7,7 @@ exports.registerAuthCommands = registerAuthCommands;
|
|
|
7
7
|
const inquirer_1 = __importDefault(require("inquirer"));
|
|
8
8
|
const chalk_1 = __importDefault(require("chalk"));
|
|
9
9
|
const cli_table3_1 = __importDefault(require("cli-table3"));
|
|
10
|
+
const typescript_sdk_1 = require("@memnexus-ai/typescript-sdk");
|
|
10
11
|
const auth_1 = require("../lib/auth");
|
|
11
12
|
const config_1 = require("../lib/config");
|
|
12
13
|
const errors_1 = require("../lib/errors");
|
|
@@ -57,9 +58,21 @@ function registerAuthCommands(program) {
|
|
|
57
58
|
}
|
|
58
59
|
// Store the API key
|
|
59
60
|
(0, auth_1.storeApiKey)(apiKey);
|
|
60
|
-
// Validate the key by calling GET /api/users/me
|
|
61
|
+
// Validate the key by calling GET /api/users/me.
|
|
62
|
+
//
|
|
63
|
+
// We build a fresh SDK instance bound to the *exact* key the user just
|
|
64
|
+
// provided. Do NOT go through getSdk() / config.getApiKey() — that path
|
|
65
|
+
// prefers MX_API_KEY from the environment, which would silently
|
|
66
|
+
// validate a stale/revoked env key instead of the one being configured
|
|
67
|
+
// (see: the known bug where a stale MX_API_KEY shadowed login and
|
|
68
|
+
// caused removeApiKey() to wipe a good newly-stored key).
|
|
69
|
+
const validationSdk = new typescript_sdk_1.Memnexus({
|
|
70
|
+
baseUrl: config_1.config.getApiUrl(),
|
|
71
|
+
token: apiKey,
|
|
72
|
+
timeoutMs: 30000,
|
|
73
|
+
});
|
|
61
74
|
try {
|
|
62
|
-
const response = await
|
|
75
|
+
const response = await validationSdk.users.getCurrentUser();
|
|
63
76
|
const result = (0, api_client_1.extractResponseData)(response);
|
|
64
77
|
const user = result?.data;
|
|
65
78
|
if (user?.email) {
|
|
@@ -70,13 +83,26 @@ function registerAuthCommands(program) {
|
|
|
70
83
|
}
|
|
71
84
|
}
|
|
72
85
|
catch (validationError) {
|
|
73
|
-
|
|
74
|
-
if (
|
|
86
|
+
const isUnauthorized = validationError?.metadata?.status === 401 || validationError?.status === 401;
|
|
87
|
+
if (isUnauthorized) {
|
|
88
|
+
// The key the user just provided was rejected by the server.
|
|
89
|
+
// Remove the now-known-bad stored key and show an error.
|
|
75
90
|
(0, auth_1.removeApiKey)();
|
|
76
|
-
|
|
91
|
+
const portal = String(config_1.config.get('apiUrl')).includes('dev')
|
|
92
|
+
? 'https://portal.dev.memnexus.ai'
|
|
93
|
+
: 'https://portal.memnexus.ai';
|
|
94
|
+
console.log(chalk_1.default.red(`✗ Invalid API key. Check your key at ${portal}`));
|
|
95
|
+
// Env-var shadowing hint: if MX_API_KEY is set and differs from
|
|
96
|
+
// the provided key, surface that mechanism so the user knows why
|
|
97
|
+
// *other* commands may still appear to work or fail confusingly.
|
|
98
|
+
const envKey = process.env.MX_API_KEY;
|
|
99
|
+
if (envKey && envKey !== apiKey) {
|
|
100
|
+
console.log(chalk_1.default.yellow('Note: MX_API_KEY is set in your environment and will shadow the stored key — unset it or update it to the new key.'));
|
|
101
|
+
}
|
|
77
102
|
return;
|
|
78
103
|
}
|
|
79
|
-
// Non-auth error (network, etc.) — key is stored, just skip validation
|
|
104
|
+
// Non-auth error (network, etc.) — key is stored, just skip validation.
|
|
105
|
+
// Do NOT remove the stored key here: the key itself was not rejected.
|
|
80
106
|
console.log(chalk_1.default.dim('(Could not verify key — will validate on first use)'));
|
|
81
107
|
}
|
|
82
108
|
console.log(chalk_1.default.dim('\nRun `mx --help` to get started.'));
|
|
@@ -116,6 +142,9 @@ function registerAuthCommands(program) {
|
|
|
116
142
|
const statusData = {
|
|
117
143
|
authenticated: status.configured,
|
|
118
144
|
source: status.source || null,
|
|
145
|
+
envKeyPrefix: status.envKeyPrefix,
|
|
146
|
+
storedKeyPrefix: status.storedKeyPrefix,
|
|
147
|
+
storedKeyShadowed: status.storedKeyShadowed,
|
|
119
148
|
apiUrl,
|
|
120
149
|
outputFormat,
|
|
121
150
|
};
|
|
@@ -142,10 +171,31 @@ function registerAuthCommands(program) {
|
|
|
142
171
|
authStatus = chalk_1.default.red('✗ Not configured');
|
|
143
172
|
}
|
|
144
173
|
table.push(['Authentication', authStatus], ['API URL', apiUrl], ['Output Format', outputFormat]);
|
|
174
|
+
// Surface env key / stored key prefixes and shadowing so users can
|
|
175
|
+
// tell the two keys apart without exposing secrets. Only the prefix
|
|
176
|
+
// (through the dot, or first 12 chars) is ever displayed.
|
|
177
|
+
if (status.source === 'env' && status.envKeyPrefix) {
|
|
178
|
+
table.push(['Env Key (MX_API_KEY)', status.envKeyPrefix]);
|
|
179
|
+
}
|
|
180
|
+
if (status.source === 'config' && status.storedKeyPrefix) {
|
|
181
|
+
table.push(['Stored Key', status.storedKeyPrefix]);
|
|
182
|
+
}
|
|
183
|
+
if (status.storedKeyShadowed && status.storedKeyPrefix) {
|
|
184
|
+
table.push([
|
|
185
|
+
'Stored Key (shadowed)',
|
|
186
|
+
chalk_1.default.yellow(`${status.storedKeyPrefix} (not used while MX_API_KEY is set)`),
|
|
187
|
+
]);
|
|
188
|
+
}
|
|
145
189
|
console.log(table.toString());
|
|
190
|
+
if (status.storedKeyShadowed) {
|
|
191
|
+
console.log(chalk_1.default.yellow('\n⚠ MX_API_KEY is set in your environment and is shadowing a different stored key.\n Unset it (unset MX_API_KEY) to use the stored key, or update MX_API_KEY to match.'));
|
|
192
|
+
}
|
|
146
193
|
if (!status.configured) {
|
|
147
194
|
console.log(chalk_1.default.yellow('\nTo configure authentication, run: mx auth login'));
|
|
148
195
|
}
|
|
196
|
+
// Defensive: never leak a full key to stdout. Also ensures linters
|
|
197
|
+
// /reviewers can see `maskApiKey` is the single source of truth.
|
|
198
|
+
void auth_1.maskApiKey;
|
|
149
199
|
}
|
|
150
200
|
catch (error) {
|
|
151
201
|
(0, errors_1.handleError)(error);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/commands/auth.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/commands/auth.ts"],"names":[],"mappings":";;;;;AAgBA,oDAwNC;AAvOD,wDAAgC;AAChC,kDAA0B;AAC1B,4DAA+B;AAC/B,gEAAuD;AACvD,sCAAqF;AACrF,0CAAuC;AACvC,0CAA4C;AAC5C,kDAAwD;AACxD,kDAAgD;AAGhD;;;GAGG;AACH,SAAgB,oBAAoB,CAAC,OAAgB;IACnD,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,WAAW,CAAC,oCAAoC,CAAC,CAAC;IAEvF;;;OAGG;IACH,IAAI;SACD,OAAO,CAAC,OAAO,CAAC;SAChB,WAAW,CAAC,sCAAsC,CAAC;SACnD,MAAM,CAAC,iBAAiB,EAAE,kBAAkB,CAAC;SAC7C,MAAM,CAAC,eAAe,EAAE,iCAAiC,CAAC;SAC1D,MAAM,CAAC,KAAK,EAAE,OA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C,IAAI,CAAC,CAAC,YAAY,EAAE,MAAM,CAAC,eAAe,CAAC,CAAC,CAAC;YACrD,CAAC;YACD,IAAI,MAAM,CAAC,iBAAiB,IAAI,MAAM,CAAC,eAAe,EAAE,CAAC;gBACvD,KAAK,CAAC,IAAI,CAAC;oBACT,uBAAuB;oBACvB,eAAK,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,eAAe,qCAAqC,CAAC;iBAC7E,CAAC,CAAC;YACL,CAAC;YAED,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;YAE9B,IAAI,MAAM,CAAC,iBAAiB,EAAE,CAAC;gBAC7B,OAAO,CAAC,GAAG,CACT,eAAK,CAAC,MAAM,CACV,yKAAyK,CAC1K,CACF,CAAC;YACJ,CAAC;YAED,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;gBACvB,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,MAAM,CAAC,mDAAmD,CAAC,CAAC,CAAC;YACjF,CAAC;YAED,mEAAmE;YACnE,iEAAiE;YACjE,KAAK,iBAAU,CAAC;QAClB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAA,oBAAW,EAAC,KAAK,CAAC,CAAC;QACrB,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC"}
|
package/dist/lib/auth.d.ts
CHANGED
|
@@ -1,10 +1,38 @@
|
|
|
1
1
|
export declare function storeApiKey(apiKey: string): void;
|
|
2
2
|
export declare function removeApiKey(): void;
|
|
3
3
|
export declare function hasApiKey(): boolean;
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Mask an API key for display. MemNexus keys are formatted as
|
|
6
|
+
* `cmk_live_<16-char id>.<secret>`. Showing the prefix up to (and including)
|
|
7
|
+
* the dot allows users to distinguish keys without exposing the secret.
|
|
8
|
+
*
|
|
9
|
+
* For malformed / dot-less keys we fall back to revealing at most half of
|
|
10
|
+
* the input (capped at 8 characters). This guarantees at least one character
|
|
11
|
+
* is dropped from the original, so the mask can never equal the input —
|
|
12
|
+
* even for very short strings that may bypass higher-level length checks.
|
|
13
|
+
*
|
|
14
|
+
* Returns null when the input is falsy.
|
|
15
|
+
*/
|
|
16
|
+
export declare function maskApiKey(apiKey: string | undefined | null): string | null;
|
|
17
|
+
export interface ApiKeyStatus {
|
|
5
18
|
configured: boolean;
|
|
6
19
|
source: 'env' | 'config' | 'none';
|
|
7
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Masked prefix of the key in `process.env.MX_API_KEY`, if set.
|
|
22
|
+
*/
|
|
23
|
+
envKeyPrefix: string | null;
|
|
24
|
+
/**
|
|
25
|
+
* Masked prefix of the key stored in Configstore, if any.
|
|
26
|
+
*/
|
|
27
|
+
storedKeyPrefix: string | null;
|
|
28
|
+
/**
|
|
29
|
+
* True when BOTH an env key and a stored key exist AND they are different,
|
|
30
|
+
* meaning the env var is shadowing a distinct stored key. If the two keys
|
|
31
|
+
* are identical this is false (no real shadowing, no user confusion).
|
|
32
|
+
*/
|
|
33
|
+
storedKeyShadowed: boolean;
|
|
34
|
+
}
|
|
35
|
+
export declare function getApiKeyStatus(): ApiKeyStatus;
|
|
8
36
|
export declare function encryptApiKey(apiKey: string): string;
|
|
9
37
|
export declare function decryptApiKey(encryptedKey: string): string;
|
|
10
38
|
//# sourceMappingURL=auth.d.ts.map
|
package/dist/lib/auth.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/lib/auth.ts"],"names":[],"mappings":"AAGA,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAOhD;AAED,wBAAgB,YAAY,IAAI,IAAI,CAGnC;AAED,wBAAgB,SAAS,IAAI,OAAO,CAEnC;AAED,wBAAgB,
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/lib/auth.ts"],"names":[],"mappings":"AAGA,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAOhD;AAED,wBAAgB,YAAY,IAAI,IAAI,CAGnC;AAED,wBAAgB,SAAS,IAAI,OAAO,CAEnC;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,CAY3E;AAED,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,OAAO,CAAC;IACpB,MAAM,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;IAClC;;OAEG;IACH,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B;;OAEG;IACH,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B;;;;OAIG;IACH,iBAAiB,EAAE,OAAO,CAAC;CAC5B;AAED,wBAAgB,eAAe,IAAI,YAAY,CAgC9C;AAGD,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAGpD;AAED,wBAAgB,aAAa,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAG1D"}
|
package/dist/lib/auth.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.storeApiKey = storeApiKey;
|
|
7
7
|
exports.removeApiKey = removeApiKey;
|
|
8
8
|
exports.hasApiKey = hasApiKey;
|
|
9
|
+
exports.maskApiKey = maskApiKey;
|
|
9
10
|
exports.getApiKeyStatus = getApiKeyStatus;
|
|
10
11
|
exports.encryptApiKey = encryptApiKey;
|
|
11
12
|
exports.decryptApiKey = decryptApiKey;
|
|
@@ -25,14 +26,62 @@ function removeApiKey() {
|
|
|
25
26
|
function hasApiKey() {
|
|
26
27
|
return config_1.config.hasApiKey();
|
|
27
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Mask an API key for display. MemNexus keys are formatted as
|
|
31
|
+
* `cmk_live_<16-char id>.<secret>`. Showing the prefix up to (and including)
|
|
32
|
+
* the dot allows users to distinguish keys without exposing the secret.
|
|
33
|
+
*
|
|
34
|
+
* For malformed / dot-less keys we fall back to revealing at most half of
|
|
35
|
+
* the input (capped at 8 characters). This guarantees at least one character
|
|
36
|
+
* is dropped from the original, so the mask can never equal the input —
|
|
37
|
+
* even for very short strings that may bypass higher-level length checks.
|
|
38
|
+
*
|
|
39
|
+
* Returns null when the input is falsy.
|
|
40
|
+
*/
|
|
41
|
+
function maskApiKey(apiKey) {
|
|
42
|
+
if (!apiKey) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
const dotIdx = apiKey.indexOf('.');
|
|
46
|
+
if (dotIdx > 0 && dotIdx <= 32) {
|
|
47
|
+
return `${apiKey.slice(0, dotIdx)}...`;
|
|
48
|
+
}
|
|
49
|
+
// Fallback: never reveal more than half the key, and never more than 8 chars.
|
|
50
|
+
// Floor(length / 2) ensures strictly fewer characters than the input.
|
|
51
|
+
const revealChars = Math.min(8, Math.floor(apiKey.length / 2));
|
|
52
|
+
return `${apiKey.slice(0, revealChars)}...`;
|
|
53
|
+
}
|
|
28
54
|
function getApiKeyStatus() {
|
|
29
|
-
|
|
30
|
-
|
|
55
|
+
const envKey = process.env.MX_API_KEY;
|
|
56
|
+
const storedKey = config_1.config.get('apiKey');
|
|
57
|
+
const envKeyPrefix = maskApiKey(envKey);
|
|
58
|
+
const storedKeyPrefix = maskApiKey(storedKey);
|
|
59
|
+
const storedKeyShadowed = !!envKey && !!storedKey && envKey !== storedKey;
|
|
60
|
+
if (envKey) {
|
|
61
|
+
return {
|
|
62
|
+
configured: true,
|
|
63
|
+
source: 'env',
|
|
64
|
+
envKeyPrefix,
|
|
65
|
+
storedKeyPrefix,
|
|
66
|
+
storedKeyShadowed,
|
|
67
|
+
};
|
|
31
68
|
}
|
|
32
|
-
if (
|
|
33
|
-
return {
|
|
69
|
+
if (storedKey) {
|
|
70
|
+
return {
|
|
71
|
+
configured: true,
|
|
72
|
+
source: 'config',
|
|
73
|
+
envKeyPrefix: null,
|
|
74
|
+
storedKeyPrefix,
|
|
75
|
+
storedKeyShadowed: false,
|
|
76
|
+
};
|
|
34
77
|
}
|
|
35
|
-
return {
|
|
78
|
+
return {
|
|
79
|
+
configured: false,
|
|
80
|
+
source: 'none',
|
|
81
|
+
envKeyPrefix: null,
|
|
82
|
+
storedKeyPrefix: null,
|
|
83
|
+
storedKeyShadowed: false,
|
|
84
|
+
};
|
|
36
85
|
}
|
|
37
86
|
// TODO: Implement encryption/decryption
|
|
38
87
|
function encryptApiKey(apiKey) {
|
package/dist/lib/auth.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/lib/auth.ts"],"names":[],"mappings":";;;;;AAGA,kCAOC;AAED,oCAGC;AAED,8BAEC;
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/lib/auth.ts"],"names":[],"mappings":";;;;;AAGA,kCAOC;AAED,oCAGC;AAED,8BAEC;AAcD,gCAYC;AAqBD,0CAgCC;AAGD,sCAGC;AAED,sCAGC;AA7GD,qCAAkC;AAClC,kDAA0B;AAE1B,SAAgB,WAAW,CAAC,MAAc;IACxC,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC1C,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;IAED,sCAAsC;IACtC,eAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;AAC3B,CAAC;AAED,SAAgB,YAAY;IAC1B,eAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IACxB,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC,CAAC;AAChD,CAAC;AAED,SAAgB,SAAS;IACvB,OAAO,eAAM,CAAC,SAAS,EAAE,CAAC;AAC5B,CAAC;AAED;;;;;;;;;;;GAWG;AACH,S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