@tolinax/ayoune-cli 2024.2.5 → 2024.2.7

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);
@@ -1,4 +1,4 @@
1
- import { decode } from "jsonwebtoken";
2
- export const decodeToken = (token) => {
3
- return decode(token, { json: true, complete: true });
4
- };
1
+ import { decode } from "jsonwebtoken";
2
+ export const decodeToken = (token) => {
3
+ return decode(token, { json: true, complete: true });
4
+ };
@@ -1,54 +1,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
- }
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
+ }
@@ -1,35 +1,35 @@
1
- import { parseInteger } from "../helpers/parseInt.js";
2
- import { promptCollectionWithModule } from "../prompts/promptCollectionWithModule.js";
3
- import { getModuleFromCollection } from "../models/getModuleFromCollection.js";
4
- import { handleListOperation } from "../operations/handleListOperation.js";
5
- import { saveFile } from "../helpers/saveFile.js";
6
- import { localStorage } from "../helpers/localStorage.js";
7
- export function createListCommand(program) {
8
- program
9
- .command("list [collection]")
10
- .alias("l")
11
- .description("List entries in collection")
12
- .option("-p, --page <number>", "Page", parseInteger, 1)
13
- .option("-l, --limit <number>", "Limit", parseInteger, 20)
14
- .option("-f, --from <date>", "From date")
15
- .action(async (collection, options) => {
16
- try {
17
- const opts = { ...program.opts(), ...options };
18
- if (!collection) {
19
- collection = await promptCollectionWithModule();
20
- }
21
- const module = getModuleFromCollection(collection);
22
- localStorage.setItem("lastModule", module.module);
23
- localStorage.setItem("lastCollection", collection);
24
- let result = {};
25
- let entry = "";
26
- result = await handleListOperation(module.module, collection, opts);
27
- if (opts.save) {
28
- await saveFile("list", opts, result);
29
- }
30
- }
31
- catch (e) {
32
- console.error(e);
33
- }
34
- });
35
- }
1
+ import { parseInteger } from "../helpers/parseInt.js";
2
+ import { promptCollectionWithModule } from "../prompts/promptCollectionWithModule.js";
3
+ import { getModuleFromCollection } from "../models/getModuleFromCollection.js";
4
+ import { handleListOperation } from "../operations/handleListOperation.js";
5
+ import { saveFile } from "../helpers/saveFile.js";
6
+ import { localStorage } from "../helpers/localStorage.js";
7
+ export function createListCommand(program) {
8
+ program
9
+ .command("list [collection]")
10
+ .alias("l")
11
+ .description("List entries in collection")
12
+ .option("-p, --page <number>", "Page", parseInteger, 1)
13
+ .option("-l, --limit <number>", "Limit", parseInteger, 20)
14
+ .option("-f, --from <date>", "From date")
15
+ .action(async (collection, options) => {
16
+ try {
17
+ const opts = { ...program.opts(), ...options };
18
+ if (!collection) {
19
+ collection = await promptCollectionWithModule();
20
+ }
21
+ const module = getModuleFromCollection(collection);
22
+ localStorage.setItem("lastModule", module.module);
23
+ localStorage.setItem("lastCollection", collection);
24
+ let result = {};
25
+ let entry = "";
26
+ result = await handleListOperation(module.module, collection, opts);
27
+ if (opts.save) {
28
+ await saveFile("list", opts, result);
29
+ }
30
+ }
31
+ catch (e) {
32
+ console.error(e);
33
+ }
34
+ });
35
+ }
@@ -1,20 +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
+ 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,33 +1,36 @@
1
- import { promptModule } from "../prompts/promptModule.js";
2
- import { promptCollectionInModule } from "../prompts/promptCollectionInModule.js";
3
- import { promptOperation } from "../prompts/promptOperation.js";
4
- import { handleListOperation } from "../operations/handleListOperation.js";
5
- import { promptEntry } from "../prompts/promptEntry.js";
6
- import { handleCollectionOperation } from "../operations/handleCollectionOperation.js";
7
- import { localStorage } from "../helpers/localStorage.js";
8
- export function createModulesCommand(program) {
9
- program
10
- .command("modules")
11
- .alias("m")
12
- .description("List modules")
13
- .action(async (message) => {
14
- try {
15
- console.log(message);
16
- const module = await promptModule();
17
- const collection = await promptCollectionInModule(module);
18
- const operation = await promptOperation();
19
- localStorage.setItem("lastModule", module);
20
- localStorage.setItem("lastCollection", collection);
21
- let result = {};
22
- let entry = "";
23
- if (operation === "list") {
24
- result = await handleListOperation(module, collection);
25
- entry = await promptEntry(result);
26
- }
27
- await handleCollectionOperation(module, collection, entry, operation);
28
- }
29
- catch (e) {
30
- console.error(e);
31
- }
32
- });
33
- }
1
+ import { promptModule } from "../prompts/promptModule.js";
2
+ import { promptCollectionInModule } from "../prompts/promptCollectionInModule.js";
3
+ import { promptOperation } from "../prompts/promptOperation.js";
4
+ import { handleListOperation } from "../operations/handleListOperation.js";
5
+ import { promptEntry } from "../prompts/promptEntry.js";
6
+ import { handleCollectionOperation } from "../operations/handleCollectionOperation.js";
7
+ import { localStorage } from "../helpers/localStorage.js";
8
+ import { parseInteger } from "../helpers/parseInt.js";
9
+ export function createModulesCommand(program) {
10
+ program
11
+ .command("modules")
12
+ .alias("m")
13
+ .description("List modules")
14
+ .option("-p, --page <number>", "Page", parseInteger, 1)
15
+ .option("-l, --limit <number>", "Limit", parseInteger, 20)
16
+ .option("-f, --from <date>", "From date")
17
+ .action(async (options) => {
18
+ try {
19
+ const opts = { ...program.opts(), ...options };
20
+ const module = await promptModule();
21
+ const collection = await promptCollectionInModule(module);
22
+ const operation = await promptOperation();
23
+ localStorage.setItem("lastModule", module);
24
+ localStorage.setItem("lastCollection", collection);
25
+ let entry = "";
26
+ if (operation === "list") {
27
+ const { result } = await handleListOperation(module, collection, opts);
28
+ entry = await promptEntry(result);
29
+ }
30
+ await handleCollectionOperation(module, collection, entry, operation);
31
+ }
32
+ catch (e) {
33
+ console.error(e);
34
+ }
35
+ });
36
+ }
@@ -1,54 +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
- 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);
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);
52
52
  program.addHelpText("beforeAll", `
53
53
  __ ______ _ _
54
54
  \\ \\ / / __ \\| | | |
@@ -56,12 +56,12 @@ export function createProgram(program) {
56
56
  / _\` \\ /| | | | | | | '_ \\ / _ \\
57
57
  | (_| || | | |__| | |__| | | | | __/
58
58
  \\__,_||_| \\____/ \\____/|_| |_|\\___|
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
- }
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 "../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
- }
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
+ }
@@ -1,27 +1,26 @@
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
- }
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
+ }
@@ -1,27 +1,27 @@
1
- // All the remaining operations are classified here
2
- import { apiCallHandler } from "../api/apiCallHandler.js";
3
- import { handleEditOperation } from "./handleEditOperation.js";
4
- import { handleEditRawOperation } from "./handleEditRawOperation.js";
5
- import { spinner } from "../../index.js";
6
- import { promptDefaultAction } from "../prompts/promptDefaultAction.js";
7
- export async function handleCollectionOperation(module, collection, entry, operation) {
8
- spinner.start({ text: "", color: "magenta" });
9
- const res = await apiCallHandler(`${module}/${collection.toLowerCase()}/${entry}?responseFormat=table`);
10
- const editContent = res.payload;
11
- console.log(editContent);
12
- spinner.success({
13
- text: `Got entry ${res.payload.name} - Took ${res.meta.responseTime} ms`,
14
- });
15
- spinner.stop();
16
- const action = await promptDefaultAction();
17
- switch (action) {
18
- case "edit":
19
- await handleEditOperation(module, collection, editContent);
20
- break;
21
- case "edit raw":
22
- await handleEditRawOperation(module, collection, editContent);
23
- break;
24
- default:
25
- break;
26
- }
27
- }
1
+ // All the remaining operations are classified here
2
+ import { apiCallHandler } from "../api/apiCallHandler.js";
3
+ import { handleEditOperation } from "./handleEditOperation.js";
4
+ import { handleEditRawOperation } from "./handleEditRawOperation.js";
5
+ import { spinner } from "../../index.js";
6
+ import { promptDefaultAction } from "../prompts/promptDefaultAction.js";
7
+ export async function handleCollectionOperation(module, collection, entry, operation) {
8
+ spinner.start({ text: "", color: "magenta" });
9
+ const res = await apiCallHandler(`${module}/${collection.toLowerCase()}/${entry}?responseFormat=table`);
10
+ const editContent = res.payload;
11
+ console.log(editContent);
12
+ spinner.success({
13
+ text: `Got entry ${res.payload.name} - Took ${res.meta.responseTime} ms`,
14
+ });
15
+ spinner.stop();
16
+ const action = await promptDefaultAction();
17
+ switch (action) {
18
+ case "edit":
19
+ await handleEditOperation(module, collection, editContent);
20
+ break;
21
+ case "edit raw":
22
+ await handleEditRawOperation(module, collection, editContent);
23
+ break;
24
+ default:
25
+ break;
26
+ }
27
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tolinax/ayoune-cli",
3
- "version": "2024.2.5",
3
+ "version": "2024.2.7",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./index.js",