@tolinax/ayoune-cli 2024.2.4 → 2024.2.5
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/lib/api/decodeToken.js +4 -0
- package/lib/commands/createEventsCommand.js +54 -54
- package/lib/commands/createLogoutCommand.js +20 -0
- package/lib/commands/createProgram.js +60 -56
- package/lib/commands/createStreamCommand.js +45 -45
- package/lib/commands/createWhoAmICommand.js +27 -0
- package/package.json +3 -2
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
import { Option } from "commander";
|
|
2
|
-
import { localStorage } from "../helpers/localStorage.js";
|
|
3
|
-
import { decodeToken } from "
|
|
4
|
-
import { customerSocket } from "../socket/customerSocketClient.js";
|
|
5
|
-
import { spinner } from "../../index.js";
|
|
6
|
-
import yaml from "js-yaml";
|
|
7
|
-
export function createEventsCommand(program) {
|
|
8
|
-
program
|
|
9
|
-
.command("events")
|
|
10
|
-
.alias("sub")
|
|
11
|
-
.description("Attach to the live event bus")
|
|
12
|
-
.addOption(new Option("-f, --format <format>", "Set the output format")
|
|
13
|
-
.choices(["json", "yaml", "table"])
|
|
14
|
-
.default("json"))
|
|
15
|
-
.addOption(new Option("-c, --category <category>", "Set the category to listen").default("*"))
|
|
16
|
-
.addOption(new Option("-a, --action <action>", "Set the action to listen").default("*"))
|
|
17
|
-
.addOption(new Option("-l, --label <label>", "Set the label to listen").default("*"))
|
|
18
|
-
.addOption(new Option("-v, --value <value>", "Set the value to listen").default("*"))
|
|
19
|
-
.action(async (options) => {
|
|
20
|
-
try {
|
|
21
|
-
const tokenPayload = decodeToken(localStorage.getItem("token"));
|
|
22
|
-
const user = tokenPayload.payload;
|
|
23
|
-
spinner.start({ text: `Starting stream with [${user._customerID}]` });
|
|
24
|
-
const socket = customerSocket(user);
|
|
25
|
-
spinner.update({ text: "Stream active" });
|
|
26
|
-
socket.on("event", (data) => {
|
|
27
|
-
if (options.category !== "*" && options.category !== data.category)
|
|
28
|
-
return;
|
|
29
|
-
if (options.action !== "*" && options.action !== data.action)
|
|
30
|
-
return;
|
|
31
|
-
if (options.label !== "*" && options.label !== data.label)
|
|
32
|
-
return;
|
|
33
|
-
if (options.value !== "*" && options.value !== data.value)
|
|
34
|
-
return;
|
|
35
|
-
spinner.update({
|
|
36
|
-
text: `Received [${data.category}.${data.action}.${data.label}.${data.value}]`,
|
|
37
|
-
});
|
|
38
|
-
if (options.format === "table") {
|
|
39
|
-
console.table(data.evt_data);
|
|
40
|
-
}
|
|
41
|
-
if (options.format === "yaml") {
|
|
42
|
-
console.log(yaml.dump(data.evt_data));
|
|
43
|
-
}
|
|
44
|
-
if (options.format === "json") {
|
|
45
|
-
console.log(JSON.stringify(data.evt_data, null, 2));
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
catch (e) {
|
|
50
|
-
spinner.error({ text: e.message });
|
|
51
|
-
console.error(e);
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
}
|
|
1
|
+
import { Option } from "commander";
|
|
2
|
+
import { localStorage } from "../helpers/localStorage.js";
|
|
3
|
+
import { decodeToken } from "../api/decodeToken.js";
|
|
4
|
+
import { customerSocket } from "../socket/customerSocketClient.js";
|
|
5
|
+
import { spinner } from "../../index.js";
|
|
6
|
+
import yaml from "js-yaml";
|
|
7
|
+
export function createEventsCommand(program) {
|
|
8
|
+
program
|
|
9
|
+
.command("events")
|
|
10
|
+
.alias("sub")
|
|
11
|
+
.description("Attach to the live event bus")
|
|
12
|
+
.addOption(new Option("-f, --format <format>", "Set the output format")
|
|
13
|
+
.choices(["json", "yaml", "table"])
|
|
14
|
+
.default("json"))
|
|
15
|
+
.addOption(new Option("-c, --category <category>", "Set the category to listen").default("*"))
|
|
16
|
+
.addOption(new Option("-a, --action <action>", "Set the action to listen").default("*"))
|
|
17
|
+
.addOption(new Option("-l, --label <label>", "Set the label to listen").default("*"))
|
|
18
|
+
.addOption(new Option("-v, --value <value>", "Set the value to listen").default("*"))
|
|
19
|
+
.action(async (options) => {
|
|
20
|
+
try {
|
|
21
|
+
const tokenPayload = decodeToken(localStorage.getItem("token"));
|
|
22
|
+
const user = tokenPayload.payload;
|
|
23
|
+
spinner.start({ text: `Starting stream with [${user._customerID}]` });
|
|
24
|
+
const socket = customerSocket(user);
|
|
25
|
+
spinner.update({ text: "Stream active" });
|
|
26
|
+
socket.on("event", (data) => {
|
|
27
|
+
if (options.category !== "*" && options.category !== data.category)
|
|
28
|
+
return;
|
|
29
|
+
if (options.action !== "*" && options.action !== data.action)
|
|
30
|
+
return;
|
|
31
|
+
if (options.label !== "*" && options.label !== data.label)
|
|
32
|
+
return;
|
|
33
|
+
if (options.value !== "*" && options.value !== data.value)
|
|
34
|
+
return;
|
|
35
|
+
spinner.update({
|
|
36
|
+
text: `Received [${data.category}.${data.action}.${data.label}.${data.value}]`,
|
|
37
|
+
});
|
|
38
|
+
if (options.format === "table") {
|
|
39
|
+
console.table(data.evt_data);
|
|
40
|
+
}
|
|
41
|
+
if (options.format === "yaml") {
|
|
42
|
+
console.log(yaml.dump(data.evt_data));
|
|
43
|
+
}
|
|
44
|
+
if (options.format === "json") {
|
|
45
|
+
console.log(JSON.stringify(data.evt_data, null, 2));
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
spinner.error({ text: e.message });
|
|
51
|
+
console.error(e);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { localStorage } from "../helpers/localStorage.js";
|
|
2
|
+
import { spinner } from "../../index.js";
|
|
3
|
+
export function createLogoutCommand(program) {
|
|
4
|
+
program
|
|
5
|
+
.command("logout")
|
|
6
|
+
.alias("signout")
|
|
7
|
+
.description("Logout from your aYOUne account")
|
|
8
|
+
.action(async (options) => {
|
|
9
|
+
try {
|
|
10
|
+
spinner.start({ text: "Clearing credentials" });
|
|
11
|
+
localStorage.removeItem("token");
|
|
12
|
+
localStorage.removeItem("refreshToken");
|
|
13
|
+
spinner.success({ text: "Credentials cleared" });
|
|
14
|
+
}
|
|
15
|
+
catch (e) {
|
|
16
|
+
spinner.error({ text: e.message });
|
|
17
|
+
console.error(e);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
@@ -1,50 +1,54 @@
|
|
|
1
|
-
//Defines the main program structure for command line interface
|
|
2
|
-
import { Option } from "commander";
|
|
3
|
-
import path from "path";
|
|
4
|
-
import os from "os";
|
|
5
|
-
import { createModulesCommand } from "./createModulesCommand.js";
|
|
6
|
-
import { createListCommand } from "./createListCommand.js";
|
|
7
|
-
import { createGetCommand } from "./createGetCommand.js";
|
|
8
|
-
import { createEditCommand } from "./createEditCommand.js";
|
|
9
|
-
import { createLoginCommand } from "./createLoginCommand.js";
|
|
10
|
-
import { createDescribeCommand } from "./createDescribeCommand.js";
|
|
11
|
-
import { createCopyCommand } from "./createCopyCommand.js";
|
|
12
|
-
import { createCreateCommand } from "./createCreateCommand.js";
|
|
13
|
-
import { createStorageCommand } from "./createStorageCommand.js";
|
|
14
|
-
import { createAuditCommand } from "./createAuditCommand.js";
|
|
15
|
-
import { createStreamCommand } from "./createStreamCommand.js";
|
|
16
|
-
import { createEventsCommand } from "./createEventsCommand.js";
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
.
|
|
22
|
-
.
|
|
23
|
-
.
|
|
24
|
-
.
|
|
25
|
-
.
|
|
26
|
-
.
|
|
27
|
-
.
|
|
28
|
-
.
|
|
29
|
-
.
|
|
30
|
-
.
|
|
31
|
-
.
|
|
32
|
-
.addOption(new Option("-
|
|
33
|
-
.addOption(new Option("-
|
|
34
|
-
.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
1
|
+
//Defines the main program structure for command line interface
|
|
2
|
+
import { Option } from "commander";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import os from "os";
|
|
5
|
+
import { createModulesCommand } from "./createModulesCommand.js";
|
|
6
|
+
import { createListCommand } from "./createListCommand.js";
|
|
7
|
+
import { createGetCommand } from "./createGetCommand.js";
|
|
8
|
+
import { createEditCommand } from "./createEditCommand.js";
|
|
9
|
+
import { createLoginCommand } from "./createLoginCommand.js";
|
|
10
|
+
import { createDescribeCommand } from "./createDescribeCommand.js";
|
|
11
|
+
import { createCopyCommand } from "./createCopyCommand.js";
|
|
12
|
+
import { createCreateCommand } from "./createCreateCommand.js";
|
|
13
|
+
import { createStorageCommand } from "./createStorageCommand.js";
|
|
14
|
+
import { createAuditCommand } from "./createAuditCommand.js";
|
|
15
|
+
import { createStreamCommand } from "./createStreamCommand.js";
|
|
16
|
+
import { createEventsCommand } from "./createEventsCommand.js";
|
|
17
|
+
import { createWhoAmICommand } from "./createWhoAmICommand.js";
|
|
18
|
+
import { createLogoutCommand } from "./createLogoutCommand.js";
|
|
19
|
+
export function createProgram(program) {
|
|
20
|
+
program
|
|
21
|
+
.version("2024.2.0")
|
|
22
|
+
.addOption(new Option("-r, --responseFormat <format>", "Set the output format")
|
|
23
|
+
.choices(["json", "csv", "yaml", "table"])
|
|
24
|
+
.default("json"))
|
|
25
|
+
.addOption(new Option("-v, --verbosity <level>", "Set the verbosity level of the returned meta information")
|
|
26
|
+
.choices(["default", "extended", "minimal"])
|
|
27
|
+
.default("default")
|
|
28
|
+
.conflicts("hideMeta"))
|
|
29
|
+
.addOption(new Option("-m, --hideMeta", "Returns only the payload without meta information. ")
|
|
30
|
+
.default(false)
|
|
31
|
+
.conflicts("verbosity"))
|
|
32
|
+
.addOption(new Option("-s, --save", "Saves the response as file"))
|
|
33
|
+
.addOption(new Option("-d, --debug", "Saves the meta information as file"))
|
|
34
|
+
.addOption(new Option("-o, --outPath [filePath]", "Lets you set a path").default(path.join(os.homedir(), "aYOUne")))
|
|
35
|
+
.addOption(new Option("-n, --name [fileName]", "Lets you set a filename"))
|
|
36
|
+
.description("aYOUne - Business as a Service Command Line Interface");
|
|
37
|
+
program.showHelpAfterError();
|
|
38
|
+
createModulesCommand(program);
|
|
39
|
+
createListCommand(program);
|
|
40
|
+
createGetCommand(program);
|
|
41
|
+
createEditCommand(program);
|
|
42
|
+
createCopyCommand(program);
|
|
43
|
+
createDescribeCommand(program);
|
|
44
|
+
createCreateCommand(program);
|
|
45
|
+
createStorageCommand(program);
|
|
46
|
+
createAuditCommand(program);
|
|
47
|
+
createStreamCommand(program);
|
|
48
|
+
createEventsCommand(program);
|
|
49
|
+
createWhoAmICommand(program);
|
|
50
|
+
createLogoutCommand(program);
|
|
51
|
+
createLoginCommand(program);
|
|
48
52
|
program.addHelpText("beforeAll", `
|
|
49
53
|
__ ______ _ _
|
|
50
54
|
\\ \\ / / __ \\| | | |
|
|
@@ -52,12 +56,12 @@ export function createProgram(program) {
|
|
|
52
56
|
/ _\` \\ /| | | | | | | '_ \\ / _ \\
|
|
53
57
|
| (_| || | | |__| | |__| | | | | __/
|
|
54
58
|
\\__,_||_| \\____/ \\____/|_| |_|\\___|
|
|
55
|
-
`);
|
|
56
|
-
program.configureHelp({
|
|
57
|
-
sortOptions: true,
|
|
58
|
-
sortSubcommands: true,
|
|
59
|
-
showGlobalOptions: true,
|
|
60
|
-
});
|
|
61
|
-
//Parse command line arguments
|
|
62
|
-
program.parse(process.argv);
|
|
63
|
-
}
|
|
59
|
+
`);
|
|
60
|
+
program.configureHelp({
|
|
61
|
+
sortOptions: true,
|
|
62
|
+
sortSubcommands: true,
|
|
63
|
+
showGlobalOptions: true,
|
|
64
|
+
});
|
|
65
|
+
//Parse command line arguments
|
|
66
|
+
program.parse(process.argv);
|
|
67
|
+
}
|
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
import { Option } from "commander";
|
|
2
|
-
import { localStorage } from "../helpers/localStorage.js";
|
|
3
|
-
import { decodeToken } from "
|
|
4
|
-
import { customerSocket } from "../socket/customerSocketClient.js";
|
|
5
|
-
import { spinner } from "../../index.js";
|
|
6
|
-
import yaml from "js-yaml";
|
|
7
|
-
export function createStreamCommand(program) {
|
|
8
|
-
program
|
|
9
|
-
.command("stream")
|
|
10
|
-
.alias("listen")
|
|
11
|
-
.description("Attach to the live data stream")
|
|
12
|
-
.addOption(new Option("-f, --format <format>", "Set the output format")
|
|
13
|
-
.choices(["json", "yaml", "table"])
|
|
14
|
-
.default("json"))
|
|
15
|
-
.addOption(new Option("-l, --level <level>", "Set the detail level")
|
|
16
|
-
.choices(["default", "minimal", "extended"])
|
|
17
|
-
.default("default"))
|
|
18
|
-
.action(async (options) => {
|
|
19
|
-
try {
|
|
20
|
-
const tokenPayload = decodeToken(localStorage.getItem("token"));
|
|
21
|
-
const user = tokenPayload.payload;
|
|
22
|
-
console.log(user);
|
|
23
|
-
console.log(`Starting stream with [${user._customerID}]`);
|
|
24
|
-
spinner.start({ text: `Starting stream with [${user._customerID}]` });
|
|
25
|
-
const socket = customerSocket(user);
|
|
26
|
-
spinner.update({ text: "Stream active" });
|
|
27
|
-
socket.onAny((channel, data) => {
|
|
28
|
-
spinner.update({ text: `Received [${channel}]` });
|
|
29
|
-
if (options.format === "table") {
|
|
30
|
-
console.table(data);
|
|
31
|
-
}
|
|
32
|
-
if (options.format === "yaml") {
|
|
33
|
-
console.log(yaml.dump(data));
|
|
34
|
-
}
|
|
35
|
-
if (options.format === "json") {
|
|
36
|
-
console.log(JSON.stringify(data, null, 2));
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
catch (e) {
|
|
41
|
-
spinner.error({ text: e.message });
|
|
42
|
-
console.error(e);
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
}
|
|
1
|
+
import { Option } from "commander";
|
|
2
|
+
import { localStorage } from "../helpers/localStorage.js";
|
|
3
|
+
import { decodeToken } from "../api/decodeToken.js";
|
|
4
|
+
import { customerSocket } from "../socket/customerSocketClient.js";
|
|
5
|
+
import { spinner } from "../../index.js";
|
|
6
|
+
import yaml from "js-yaml";
|
|
7
|
+
export function createStreamCommand(program) {
|
|
8
|
+
program
|
|
9
|
+
.command("stream")
|
|
10
|
+
.alias("listen")
|
|
11
|
+
.description("Attach to the live data stream")
|
|
12
|
+
.addOption(new Option("-f, --format <format>", "Set the output format")
|
|
13
|
+
.choices(["json", "yaml", "table"])
|
|
14
|
+
.default("json"))
|
|
15
|
+
.addOption(new Option("-l, --level <level>", "Set the detail level")
|
|
16
|
+
.choices(["default", "minimal", "extended"])
|
|
17
|
+
.default("default"))
|
|
18
|
+
.action(async (options) => {
|
|
19
|
+
try {
|
|
20
|
+
const tokenPayload = decodeToken(localStorage.getItem("token"));
|
|
21
|
+
const user = tokenPayload.payload;
|
|
22
|
+
console.log(user);
|
|
23
|
+
console.log(`Starting stream with [${user._customerID}]`);
|
|
24
|
+
spinner.start({ text: `Starting stream with [${user._customerID}]` });
|
|
25
|
+
const socket = customerSocket(user);
|
|
26
|
+
spinner.update({ text: "Stream active" });
|
|
27
|
+
socket.onAny((channel, data) => {
|
|
28
|
+
spinner.update({ text: `Received [${channel}]` });
|
|
29
|
+
if (options.format === "table") {
|
|
30
|
+
console.table(data);
|
|
31
|
+
}
|
|
32
|
+
if (options.format === "yaml") {
|
|
33
|
+
console.log(yaml.dump(data));
|
|
34
|
+
}
|
|
35
|
+
if (options.format === "json") {
|
|
36
|
+
console.log(JSON.stringify(data, null, 2));
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
spinner.error({ text: e.message });
|
|
42
|
+
console.error(e);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Option } from "commander";
|
|
2
|
+
import { localStorage } from "../helpers/localStorage.js";
|
|
3
|
+
import { decodeToken } from "../api/decodeToken.js";
|
|
4
|
+
import { spinner } from "../../index.js";
|
|
5
|
+
export function createWhoAmICommand(program) {
|
|
6
|
+
program
|
|
7
|
+
.command("whoami")
|
|
8
|
+
.alias("who")
|
|
9
|
+
.description("Attach to the live data stream")
|
|
10
|
+
.addOption(new Option("-f, --format <format>", "Set the output format")
|
|
11
|
+
.choices(["json", "yaml", "table"])
|
|
12
|
+
.default("json"))
|
|
13
|
+
.addOption(new Option("-l, --level <level>", "Set the detail level")
|
|
14
|
+
.choices(["default", "minimal", "extended"])
|
|
15
|
+
.default("default"))
|
|
16
|
+
.action(async (options) => {
|
|
17
|
+
try {
|
|
18
|
+
const tokenPayload = decodeToken(localStorage.getItem("token"));
|
|
19
|
+
const user = tokenPayload.payload;
|
|
20
|
+
console.log(user);
|
|
21
|
+
}
|
|
22
|
+
catch (e) {
|
|
23
|
+
spinner.error({ text: e.message });
|
|
24
|
+
console.error(e);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tolinax/ayoune-cli",
|
|
3
|
-
"version": "2024.2.
|
|
3
|
+
"version": "2024.2.5",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.js",
|
|
@@ -102,7 +102,6 @@
|
|
|
102
102
|
}
|
|
103
103
|
},
|
|
104
104
|
"dependencies": {
|
|
105
|
-
"@tolinax/ayoune-core": "^2024.2.166",
|
|
106
105
|
"@tolinax/ayoune-models": "^2024.2.29",
|
|
107
106
|
"axios": "^1.6.7",
|
|
108
107
|
"axios-retry": "^4.0.0",
|
|
@@ -124,6 +123,7 @@
|
|
|
124
123
|
"mkdirp": "^3.0.1",
|
|
125
124
|
"moment": "^2.30.1",
|
|
126
125
|
"nanospinner": "^1.1.0",
|
|
126
|
+
"jsonwebtoken": "^9.0.2",
|
|
127
127
|
"node-localstorage": "^3.0.5",
|
|
128
128
|
"os": "^0.1.2",
|
|
129
129
|
"socket.io-client": "^4.7.4"
|
|
@@ -139,6 +139,7 @@
|
|
|
139
139
|
"@types/js-yaml": "^4.0.9",
|
|
140
140
|
"@types/lodash": "^4.14.202",
|
|
141
141
|
"@types/node": "^20.11.16",
|
|
142
|
+
"@types/jsonwebtoken": "^9.0.5",
|
|
142
143
|
"@types/node-localstorage": "^1.3.3",
|
|
143
144
|
"cpx": "^1.5.0",
|
|
144
145
|
"prettier": "^3.2.5",
|