@n42/cli 0.1.89 → 0.1.91
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/docs/DB_USAGE.md +0 -1
- package/jest.config.js +6 -0
- package/package.json +1 -1
- package/src/auth.js +8 -7
- package/src/cli.js +25 -20
- package/src/colors.js +42 -0
- package/src/utils.js +2 -1
package/docs/DB_USAGE.md
CHANGED
package/jest.config.js
ADDED
package/package.json
CHANGED
package/src/auth.js
CHANGED
|
@@ -3,7 +3,9 @@ const { NODE42_DIR, TOKENS_FILE, API_URL, EP_SIGNIN, EP_REFRESH, EP_ME } = requi
|
|
|
3
3
|
const { handleError } = require("./errors");
|
|
4
4
|
const { getUserWithIndex } = require("./user");
|
|
5
5
|
const { clearScreen, ask, startSpinner } = require("./utils");
|
|
6
|
+
|
|
6
7
|
const db = require("./db");
|
|
8
|
+
const C = require("./colors");
|
|
7
9
|
|
|
8
10
|
|
|
9
11
|
async function login() {
|
|
@@ -25,7 +27,7 @@ async function login() {
|
|
|
25
27
|
if (!res.ok) {
|
|
26
28
|
stopSpinner();
|
|
27
29
|
|
|
28
|
-
console.error(`Login failed
|
|
30
|
+
console.error(`[${res.status}] ${C.RED}Login failed${C.RESET} - Invalid credentials`);
|
|
29
31
|
process.exit(1);
|
|
30
32
|
}
|
|
31
33
|
|
|
@@ -34,7 +36,7 @@ async function login() {
|
|
|
34
36
|
|
|
35
37
|
const { accessToken, refreshToken, idToken } = tokens;
|
|
36
38
|
if (!accessToken || !refreshToken || !idToken) {
|
|
37
|
-
console.error(
|
|
39
|
+
console.error(`${C.RED}Invalid auth response`);
|
|
38
40
|
process.exit(1);
|
|
39
41
|
}
|
|
40
42
|
|
|
@@ -50,14 +52,12 @@ async function login() {
|
|
|
50
52
|
stopSpinner();
|
|
51
53
|
|
|
52
54
|
if (!authenticated) {
|
|
53
|
-
console.error(
|
|
55
|
+
console.error(`${C.RED}Not authenticated${C.RESET}`);
|
|
54
56
|
process.exit(1);
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
user = getUserWithIndex(0);
|
|
58
|
-
console.log(
|
|
59
|
-
`Authenticated as ${user.userName} <${user.userMail}> (${user.role})`
|
|
60
|
-
);
|
|
60
|
+
console.log(`Authenticated as ${user.userName} <${C.BLUE}${user.userMail}${C.RESET}> ${C.DIM}(${user.role})${C.RESET}\n`);
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
function logout() {
|
|
@@ -69,7 +69,8 @@ function logout() {
|
|
|
69
69
|
|
|
70
70
|
function loadTokens() {
|
|
71
71
|
if (!fs.existsSync(TOKENS_FILE)) {
|
|
72
|
-
console.error(
|
|
72
|
+
console.error(`Tokens missing...`);
|
|
73
|
+
console.log(`Run: ${C.BLUE}n42 login${C.RESET}\n`);
|
|
73
74
|
process.exit(1);
|
|
74
75
|
}
|
|
75
76
|
return JSON.parse(fs.readFileSync(TOKENS_FILE, "utf8"));
|
package/src/cli.js
CHANGED
|
@@ -12,6 +12,7 @@ createAppDirs();
|
|
|
12
12
|
const program = new Command();
|
|
13
13
|
const pkg = require("../package.json");
|
|
14
14
|
const db = require("./db");
|
|
15
|
+
const C = require("./colors");
|
|
15
16
|
|
|
16
17
|
const fs = require("fs");
|
|
17
18
|
const path = require("path");
|
|
@@ -27,7 +28,7 @@ program
|
|
|
27
28
|
.action((shell) => {
|
|
28
29
|
|
|
29
30
|
if (shell !== "bash") {
|
|
30
|
-
console.error(
|
|
31
|
+
console.error(`${C.RED}Only bash supported${C.RESET}`);
|
|
31
32
|
return;
|
|
32
33
|
}
|
|
33
34
|
|
|
@@ -35,9 +36,9 @@ program
|
|
|
35
36
|
const dest = path.join(NODE42_DIR, "completion.bash");
|
|
36
37
|
fs.copyFileSync(src, dest);
|
|
37
38
|
|
|
38
|
-
console.log(
|
|
39
|
+
console.log(`${C.DIM}Completion script saved to ${dest}${C.RESET}\n`);
|
|
39
40
|
console.log(`Run this once:`);
|
|
40
|
-
console.log(
|
|
41
|
+
console.log(`${C.BLUE}source ${dest}${C.RESET}\n`);
|
|
41
42
|
});
|
|
42
43
|
|
|
43
44
|
program
|
|
@@ -80,21 +81,21 @@ program
|
|
|
80
81
|
const user = getUserWithIndex(0);
|
|
81
82
|
const currentMonth = new Date().toISOString().slice(0, 7);
|
|
82
83
|
console.log(`Node42 CLI v${pkg.version}
|
|
83
|
-
User
|
|
84
|
-
ID : ${user.id}
|
|
84
|
+
${C.BOLD}User${C.RESET}
|
|
85
|
+
ID : ${C.CYAN}${user.id}${C.RESET}
|
|
85
86
|
Name : ${user.userName}
|
|
86
87
|
Email : ${user.userMail}
|
|
87
88
|
Role : ${user.role}
|
|
88
89
|
|
|
89
|
-
Rate Limits
|
|
90
|
-
Discovery : ${user.rateLimits.discovery}
|
|
91
|
-
Transactions : ${user.rateLimits.transactions}
|
|
92
|
-
Validation : ${user.rateLimits.validation}
|
|
90
|
+
${C.BOLD}Rate Limits${C.RESET}
|
|
91
|
+
Discovery : ${C.RED}${user.rateLimits.discovery}${C.RESET}
|
|
92
|
+
Transactions : ${C.RED}${user.rateLimits.transactions}${C.RESET}
|
|
93
|
+
Validation : ${C.RED}${user.rateLimits.validation}${C.RESET}
|
|
93
94
|
|
|
94
|
-
Usage (Current Month)
|
|
95
|
-
Discovery : ${user.serviceUsage.discovery[currentMonth] ?? 0}
|
|
96
|
-
Transactions : ${user.serviceUsage.transactions[currentMonth] ?? 0}
|
|
97
|
-
Validation : ${user.serviceUsage.validation[currentMonth] ?? 0}
|
|
95
|
+
${C.BOLD}Usage${C.RESET} ${C.DIM}(Current Month)${C.RESET}
|
|
96
|
+
Discovery : ${C.RED}${user.serviceUsage.discovery[currentMonth] ?? 0}${C.RESET}
|
|
97
|
+
Transactions : ${C.RED}${user.serviceUsage.transactions[currentMonth] ?? 0}${C.RESET}
|
|
98
|
+
Validation : ${C.RED}${user.serviceUsage.validation[currentMonth] ?? 0}${C.RESET}
|
|
98
99
|
`);
|
|
99
100
|
});
|
|
100
101
|
|
|
@@ -110,8 +111,9 @@ program
|
|
|
110
111
|
usage = 0;
|
|
111
112
|
}
|
|
112
113
|
|
|
113
|
-
clearScreen(`Node42 CLI v${pkg.version}`);
|
|
114
|
-
console.log(`Usage
|
|
114
|
+
clearScreen(`Node42 CLI v${pkg.version}\n`);
|
|
115
|
+
console.log(`Usage ${C.BOLD}${service}${C.RESET}`);
|
|
116
|
+
console.log(`${C.DIM}${currentMonth}:${C.RESET} ${C.RED}${usage}${C.RESET}\n`);
|
|
115
117
|
});
|
|
116
118
|
|
|
117
119
|
program
|
|
@@ -163,24 +165,27 @@ program
|
|
|
163
165
|
|
|
164
166
|
// ---- OUTPUT ----
|
|
165
167
|
clearScreen(`Node42 CLI v${pkg.version}`);
|
|
166
|
-
console.log(`Found ${artefacts.length} artefact(s)${filterInfo}\n`);
|
|
168
|
+
console.log(`Found ${C.RED}${artefacts.length}${C.RESET} artefact(s)${filterInfo}\n`);
|
|
167
169
|
|
|
168
170
|
const DATE = "DATE".padEnd(19);
|
|
169
171
|
const PID = "PID".padEnd(15);
|
|
170
172
|
const FILE = "FILE";
|
|
171
|
-
console.log(`${DATE} ${PID} ${FILE}`);
|
|
173
|
+
console.log(`${DATE} ${C.CYAN}${PID}${C.RESET} ${FILE}`);
|
|
172
174
|
|
|
173
175
|
for (const item of artefacts) {
|
|
174
176
|
const d = new Date(item.createdAt);
|
|
175
|
-
const
|
|
177
|
+
const iso = d.toISOString(); // 2026-01-30T16:53:28.123Z
|
|
178
|
+
const date = iso.slice(0, 10); // 2026-01-30
|
|
179
|
+
const time = iso.slice(11, 19); // 16:53:28
|
|
176
180
|
const file = path.join(ARTEFACTS_DIR, `${item.file}`);
|
|
181
|
+
const link = `\u001B]8;;file://${file}\u0007Open\u001B]8;;\u0007`
|
|
177
182
|
|
|
178
183
|
let pid = item.participantId;
|
|
179
184
|
if (!participantId) {
|
|
180
185
|
pid = pid.length > 15 ? pid.substring(0, 12) + "..." : pid
|
|
181
|
-
console.log(`${
|
|
186
|
+
console.log(`${date} ${C.DIM}${time}${C.RESET} ${C.CYAN}${pid.padEnd(15)}${C.RESET} ${item.file} ${C.BLUE}[${link}]${C.RESET}`);
|
|
182
187
|
} else {
|
|
183
|
-
console.log(`${
|
|
188
|
+
console.log(`${date} ${C.DIM}${time}${C.RESET} ${item.file} ${C.BLUE}[${link}]${C.RESET}`);
|
|
184
189
|
}
|
|
185
190
|
}
|
|
186
191
|
|
package/src/colors.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const RESET = "\x1b[0m";
|
|
2
|
+
|
|
3
|
+
const BLACK = "\x1b[30m";
|
|
4
|
+
const RED = "\x1b[31m";
|
|
5
|
+
const GREEN = "\x1b[32m";
|
|
6
|
+
const YELLOW = "\x1b[33m";
|
|
7
|
+
const BLUE = "\x1b[34m";
|
|
8
|
+
const MAGENTA = "\x1b[35m";
|
|
9
|
+
const CYAN = "\x1b[36m";
|
|
10
|
+
const WHITE = "\x1b[37m";
|
|
11
|
+
|
|
12
|
+
const BOLD = "\x1b[1m";
|
|
13
|
+
const DIM = "\x1b[2m";
|
|
14
|
+
const UNDERLINE = "\x1b[4m";
|
|
15
|
+
|
|
16
|
+
const RED_BOLD = "\x1b[1;31m";
|
|
17
|
+
const GREEN_BOLD = "\x1b[1;32m";
|
|
18
|
+
const YELLOW_BOLD = "\x1b[1;33m";
|
|
19
|
+
const BLUE_BOLD = "\x1b[1;34m";
|
|
20
|
+
const MAGENTA_BOLD = "\x1b[1;35m";
|
|
21
|
+
const CYAN_BOLD = "\x1b[1;36m";
|
|
22
|
+
|
|
23
|
+
module.exports = {
|
|
24
|
+
RESET,
|
|
25
|
+
BLACK,
|
|
26
|
+
RED,
|
|
27
|
+
GREEN,
|
|
28
|
+
YELLOW,
|
|
29
|
+
BLUE,
|
|
30
|
+
MAGENTA,
|
|
31
|
+
CYAN,
|
|
32
|
+
WHITE,
|
|
33
|
+
BOLD,
|
|
34
|
+
DIM,
|
|
35
|
+
UNDERLINE,
|
|
36
|
+
RED_BOLD,
|
|
37
|
+
GREEN_BOLD,
|
|
38
|
+
YELLOW_BOLD,
|
|
39
|
+
BLUE_BOLD,
|
|
40
|
+
MAGENTA_BOLD,
|
|
41
|
+
CYAN_BOLD
|
|
42
|
+
};
|
package/src/utils.js
CHANGED
|
@@ -3,6 +3,7 @@ const inquirer = require("inquirer");
|
|
|
3
3
|
const readline = require("readline");
|
|
4
4
|
const config = require("./config");
|
|
5
5
|
const db = require("./db");
|
|
6
|
+
const C = require("./colors");
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
function clearScreen(text) {
|
|
@@ -20,7 +21,7 @@ function ask(question, def, hidden=false) {
|
|
|
20
21
|
terminal: true
|
|
21
22
|
});
|
|
22
23
|
|
|
23
|
-
const q = def ? `${question} (${def}): ` : `${question}: `;
|
|
24
|
+
const q = def ? `${question} ${C.DIM}(${def})${C.RESET}: ` : `${question}: `;
|
|
24
25
|
|
|
25
26
|
process.stdin.on("data", char => {
|
|
26
27
|
char = char + "";
|