@tolinax/ayoune-cli 2024.2.4 → 2024.2.6

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 CHANGED
@@ -1,16 +1,16 @@
1
- #! /usr/bin/env node
2
- import { Command } from "commander";
3
- import { createSpinner } from "nanospinner";
4
- import { initializeSettings } from "./lib/helpers/initializeSettings.js";
5
- import { createProgram } from "./lib/commands/createProgram.js";
6
- import path from "path";
7
- import { readFile } from "fs/promises";
8
- import * as process from "process";
9
- //Create new command instance
10
- //@ts-ignore
11
- const pkg = JSON.parse(await readFile(path.join(process.cwd(), "package.json"), "utf8"));
12
- const program = new Command();
13
- initializeSettings();
14
- //Setup spinner
15
- export const spinner = createSpinner("Getting data...");
16
- createProgram(program);
1
+ #! /usr/bin/env node
2
+ import { Command } from "commander";
3
+ import { createSpinner } from "nanospinner";
4
+ import { initializeSettings } from "./lib/helpers/initializeSettings.js";
5
+ import { createProgram } from "./lib/commands/createProgram.js";
6
+ import path from "path";
7
+ import { readFile } from "fs/promises";
8
+ import * as process from "process";
9
+ //Create new command instance
10
+ //@ts-ignore
11
+ const pkg = JSON.parse(await readFile(path.join(process.cwd(), "package.json"), "utf8"));
12
+ const program = new Command();
13
+ initializeSettings();
14
+ //Setup spinner
15
+ export const spinner = createSpinner("Getting data...");
16
+ createProgram(program);
@@ -0,0 +1,4 @@
1
+ import { decode } from "jsonwebtoken";
2
+ export const decodeToken = (token) => {
3
+ return decode(token, { json: true, complete: true });
4
+ };
@@ -1,6 +1,6 @@
1
1
  import { Option } from "commander";
2
2
  import { localStorage } from "../helpers/localStorage.js";
3
- import { decodeToken } from "@tolinax/ayoune-core/lib/auth/decodeToken.js";
3
+ import { decodeToken } from "../api/decodeToken.js";
4
4
  import { customerSocket } from "../socket/customerSocketClient.js";
5
5
  import { spinner } from "../../index.js";
6
6
  import yaml from "js-yaml";
@@ -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
+ }
@@ -14,6 +14,8 @@ import { createStorageCommand } from "./createStorageCommand.js";
14
14
  import { createAuditCommand } from "./createAuditCommand.js";
15
15
  import { createStreamCommand } from "./createStreamCommand.js";
16
16
  import { createEventsCommand } from "./createEventsCommand.js";
17
+ import { createWhoAmICommand } from "./createWhoAmICommand.js";
18
+ import { createLogoutCommand } from "./createLogoutCommand.js";
17
19
  export function createProgram(program) {
18
20
  program
19
21
  .version("2024.2.0")
@@ -44,6 +46,8 @@ export function createProgram(program) {
44
46
  createAuditCommand(program);
45
47
  createStreamCommand(program);
46
48
  createEventsCommand(program);
49
+ createWhoAmICommand(program);
50
+ createLogoutCommand(program);
47
51
  createLoginCommand(program);
48
52
  program.addHelpText("beforeAll", `
49
53
  __ ______ _ _
@@ -1,6 +1,6 @@
1
1
  import { Option } from "commander";
2
2
  import { localStorage } from "../helpers/localStorage.js";
3
- import { decodeToken } from "@tolinax/ayoune-core/lib/auth/decodeToken.js";
3
+ import { decodeToken } from "../api/decodeToken.js";
4
4
  import { customerSocket } from "../socket/customerSocketClient.js";
5
5
  import { spinner } from "../../index.js";
6
6
  import yaml from "js-yaml";
@@ -0,0 +1,26 @@
1
+ import { localStorage } from "../helpers/localStorage.js";
2
+ import { decodeToken } from "../api/decodeToken.js";
3
+ import { spinner } from "../../index.js";
4
+ import { login } from "../api/login.js";
5
+ export function createWhoAmICommand(program) {
6
+ program
7
+ .command("whoami")
8
+ .alias("who")
9
+ .description("Shows your user information")
10
+ .action(async (options) => {
11
+ try {
12
+ const tokenPayload = decodeToken(localStorage.getItem("token"));
13
+ if (tokenPayload) {
14
+ const user = tokenPayload.payload;
15
+ console.log(user);
16
+ }
17
+ else {
18
+ await login();
19
+ }
20
+ }
21
+ catch (e) {
22
+ spinner.error({ text: e.message });
23
+ console.error(e);
24
+ }
25
+ });
26
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tolinax/ayoune-cli",
3
- "version": "2024.2.4",
3
+ "version": "2024.2.6",
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",