error-ux-cli 1.0.0 → 1.1.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/index.js +48 -8
- package/lib/commands.js +1284 -730
- package/lib/dashboard.mjs +4 -4
- package/lib/dbExplorer.mjs +284 -0
- package/lib/git.js +92 -4
- package/lib/pgClient.js +102 -0
- package/lib/plugins.js +94 -0
- package/lib/storage.js +71 -3
- package/lib/utils.js +22 -10
- package/package.json +13 -6
package/index.js
CHANGED
|
@@ -5,6 +5,7 @@ const commands = require('./lib/commands');
|
|
|
5
5
|
const utils = require('./lib/utils');
|
|
6
6
|
const storage = require('./lib/storage');
|
|
7
7
|
const auth = require('./lib/auth');
|
|
8
|
+
const plugins = require('./lib/plugins');
|
|
8
9
|
|
|
9
10
|
async function main() {
|
|
10
11
|
utils.loadEnv();
|
|
@@ -40,14 +41,22 @@ async function main() {
|
|
|
40
41
|
|
|
41
42
|
let authenticated = false;
|
|
42
43
|
let attempts = 0;
|
|
44
|
+
let masterKey = null;
|
|
45
|
+
let activePlugins = {};
|
|
43
46
|
const storedHash = config.users[targetUser].password_hash;
|
|
44
|
-
|
|
47
|
+
|
|
45
48
|
while (!authenticated && attempts < 3) {
|
|
46
49
|
const pwd = await auth.askPassword(rl, `Password (${targetUser}): `);
|
|
47
50
|
if (auth.verifyPassword(pwd, storedHash)) {
|
|
48
51
|
authenticated = true;
|
|
49
52
|
config.activeUser = targetUser;
|
|
50
|
-
|
|
53
|
+
// If the password is a 128-char Master Key, store it for the session
|
|
54
|
+
if (pwd.length === 128) {
|
|
55
|
+
masterKey = pwd;
|
|
56
|
+
activePlugins = plugins.loadPlugins();
|
|
57
|
+
console.log('\n--- \uD83D\uDD12 Admin Session Unlocked ---');
|
|
58
|
+
}
|
|
59
|
+
await commands.ensureUserNewsApiKey(rl, config, config.users[targetUser], { forcePrompt: true });
|
|
51
60
|
await storage.saveConfig(config);
|
|
52
61
|
} else {
|
|
53
62
|
attempts++;
|
|
@@ -62,14 +71,14 @@ async function main() {
|
|
|
62
71
|
// 3. Execution
|
|
63
72
|
if (args.length > 0) {
|
|
64
73
|
try {
|
|
65
|
-
await processInput(rl, args.join(' '), true);
|
|
74
|
+
await processInput(rl, args.join(' '), true, masterKey, activePlugins);
|
|
66
75
|
} catch (err) {
|
|
67
76
|
console.error('error');
|
|
68
77
|
}
|
|
69
78
|
rl.close();
|
|
70
79
|
} else {
|
|
71
80
|
try {
|
|
72
|
-
await commands.handleDashboard(rl);
|
|
81
|
+
await commands.handleDashboard(rl, masterKey);
|
|
73
82
|
} catch (err) {
|
|
74
83
|
console.error('error');
|
|
75
84
|
}
|
|
@@ -77,7 +86,7 @@ async function main() {
|
|
|
77
86
|
|
|
78
87
|
rl.on('line', async (line) => {
|
|
79
88
|
try {
|
|
80
|
-
await processInput(rl, line.trim(), false);
|
|
89
|
+
await processInput(rl, line.trim(), false, masterKey, activePlugins);
|
|
81
90
|
} catch (err) {
|
|
82
91
|
console.error('error');
|
|
83
92
|
}
|
|
@@ -93,18 +102,23 @@ async function main() {
|
|
|
93
102
|
}
|
|
94
103
|
}
|
|
95
104
|
|
|
96
|
-
async function processInput(rl, input, isDirect) {
|
|
105
|
+
async function processInput(rl, input, isDirect, masterKey, activePlugins = {}) {
|
|
97
106
|
const trimmedInput = input.trim();
|
|
98
107
|
if (trimmedInput === '' || trimmedInput === 'help') {
|
|
99
|
-
await commands.handleMenu();
|
|
108
|
+
await commands.handleMenu(masterKey, activePlugins);
|
|
100
109
|
return;
|
|
101
110
|
}
|
|
102
111
|
|
|
103
112
|
const firstWord = trimmedInput.split(' ')[0].toLowerCase();
|
|
104
113
|
const restOfInput = trimmedInput.slice(firstWord.length).trim();
|
|
114
|
+
const args = restOfInput ? restOfInput.split(' ') : [];
|
|
105
115
|
|
|
106
116
|
switch (firstWord) {
|
|
107
117
|
case 'user':
|
|
118
|
+
if (masterKey) {
|
|
119
|
+
console.error('Action Restricted: The "user" command is disabled while in a secure Admin session. Exit the session to manage profiles.');
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
108
122
|
await commands.handleUser(rl, restOfInput);
|
|
109
123
|
break;
|
|
110
124
|
case 'export':
|
|
@@ -136,14 +150,40 @@ async function processInput(rl, input, isDirect) {
|
|
|
136
150
|
case 'repo':
|
|
137
151
|
await commands.handleRepo(rl, restOfInput);
|
|
138
152
|
break;
|
|
153
|
+
case 'sync':
|
|
154
|
+
if (!masterKey) break; // FALLTHROUGH to default (Unknown)
|
|
155
|
+
await commands.handleAdminSync(rl, masterKey);
|
|
156
|
+
break;
|
|
157
|
+
case 'plugin':
|
|
158
|
+
if (!masterKey) break; // FALLTHROUGH to default (Unknown)
|
|
159
|
+
await commands.handlePlugin(rl, masterKey);
|
|
160
|
+
break;
|
|
161
|
+
case 'settings':
|
|
162
|
+
if (!masterKey) break; // FALLTHROUGH to default (Unknown)
|
|
163
|
+
masterKey = await commands.handleSettings(rl, masterKey);
|
|
164
|
+
break;
|
|
165
|
+
case 'pg':
|
|
166
|
+
if (!masterKey) break; // FALLTHROUGH to default (Unknown)
|
|
167
|
+
await commands.handleDB(rl, masterKey);
|
|
168
|
+
break;
|
|
139
169
|
case 'uninstall':
|
|
140
170
|
await commands.handleUninstall(rl);
|
|
141
171
|
break;
|
|
172
|
+
case 'mission':
|
|
173
|
+
if (!masterKey) break; // FALLTHROUGH to default (Unknown)
|
|
174
|
+
await commands.handleMission(rl, args, masterKey);
|
|
175
|
+
break;
|
|
142
176
|
case 'exit':
|
|
143
177
|
rl.close();
|
|
144
178
|
break;
|
|
145
179
|
default:
|
|
146
|
-
|
|
180
|
+
// High priority: Dynamic Admin Plugins
|
|
181
|
+
if (masterKey && activePlugins[firstWord]) {
|
|
182
|
+
await activePlugins[firstWord].run(rl, restOfInput, masterKey);
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const found = await commands.handleShortcut(firstWord, masterKey);
|
|
147
187
|
if (!found && trimmedInput !== '') {
|
|
148
188
|
console.error('error');
|
|
149
189
|
}
|