@tolinax/ayoune-cli 2024.2.17 → 2024.3.0

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.
Files changed (61) hide show
  1. package/index.js +11 -11
  2. package/package.json +156 -147
  3. package/data/defaultActions.js +0 -9
  4. package/data/modelsAndRights.js +0 -3189
  5. package/data/modules.js +0 -26
  6. package/data/operations.js +0 -5
  7. package/lib/api/apiCallHandler.js +0 -42
  8. package/lib/api/apiClient.js +0 -16
  9. package/lib/api/auditCallHandler.js +0 -42
  10. package/lib/api/decodeToken.js +0 -4
  11. package/lib/api/handleAPIError.js +0 -0
  12. package/lib/api/login.js +0 -33
  13. package/lib/commands/createAuditCommand.js +0 -30
  14. package/lib/commands/createCopyCommand.js +0 -24
  15. package/lib/commands/createCreateCommand.js +0 -31
  16. package/lib/commands/createDescribeCommand.js +0 -27
  17. package/lib/commands/createEditCommand.js +0 -28
  18. package/lib/commands/createEventsCommand.js +0 -54
  19. package/lib/commands/createGetCommand.js +0 -36
  20. package/lib/commands/createListCommand.js +0 -35
  21. package/lib/commands/createLoginCommand.js +0 -17
  22. package/lib/commands/createLogoutCommand.js +0 -20
  23. package/lib/commands/createModulesCommand.js +0 -41
  24. package/lib/commands/createProgram.js +0 -67
  25. package/lib/commands/createStorageCommand.js +0 -16
  26. package/lib/commands/createStreamCommand.js +0 -45
  27. package/lib/commands/createWhoAmICommand.js +0 -26
  28. package/lib/helpers/addSpacesToCamelCase.js +0 -5
  29. package/lib/helpers/handleResponseFormatOptions.js +0 -43
  30. package/lib/helpers/initializeSettings.js +0 -14
  31. package/lib/helpers/localStorage.js +0 -4
  32. package/lib/helpers/makeRandomToken.js +0 -27
  33. package/lib/helpers/parseInt.js +0 -9
  34. package/lib/helpers/saveFile.js +0 -39
  35. package/lib/models/getCollections.js +0 -15
  36. package/lib/models/getModelsInModules.js +0 -13
  37. package/lib/models/getModuleFromCollection.js +0 -7
  38. package/lib/operations/handleAuditOperation.js +0 -22
  39. package/lib/operations/handleCollectionOperation.js +0 -68
  40. package/lib/operations/handleCopySingleOperation.js +0 -22
  41. package/lib/operations/handleCreateSingleOperation.js +0 -27
  42. package/lib/operations/handleDescribeSingleOperation.js +0 -20
  43. package/lib/operations/handleEditOperation.js +0 -51
  44. package/lib/operations/handleEditRawOperation.js +0 -35
  45. package/lib/operations/handleGetOperation.js +0 -25
  46. package/lib/operations/handleGetSingleOperation.js +0 -20
  47. package/lib/operations/handleListOperation.js +0 -24
  48. package/lib/operations/handleSingleAuditOperation.js +0 -27
  49. package/lib/prompts/promptAudits.js +0 -15
  50. package/lib/prompts/promptCollection.js +0 -13
  51. package/lib/prompts/promptCollectionInModule.js +0 -13
  52. package/lib/prompts/promptCollectionWithModule.js +0 -15
  53. package/lib/prompts/promptDefaultAction.js +0 -13
  54. package/lib/prompts/promptEntry.js +0 -12
  55. package/lib/prompts/promptFileName.js +0 -12
  56. package/lib/prompts/promptFilePath.js +0 -18
  57. package/lib/prompts/promptModule.js +0 -19
  58. package/lib/prompts/promptName.js +0 -11
  59. package/lib/prompts/promptOperation.js +0 -13
  60. package/lib/socket/customerSocketClient.js +0 -12
  61. package/lib/socket/socketClient.js +0 -11
package/data/modules.js DELETED
@@ -1,26 +0,0 @@
1
- const aYOUneModules = [
2
- { label: "Artificial Intelligence", module: "ai" },
3
- { label: "Asset store", module: "assetstore" },
4
- { label: "Customer Relationship Management", module: "crm" },
5
- { label: "Project management", module: "pm" },
6
- { label: "Content management system", module: "cms" },
7
- { label: "Marketing", module: "marketing" },
8
- { label: "Automation", module: "automation" },
9
- { label: "Sale", module: "sale" },
10
- { label: "Product information management", module: "pim" },
11
- { label: "Hub", module: "hub" },
12
- { label: "Human Resources", module: "hr" },
13
- { label: "Service Desk", module: "service" },
14
- { label: "Purchase", module: "purchase" },
15
- { label: "Accounting", module: "accounting" },
16
- { label: "E Commerce", module: "ecommerce" },
17
- { label: "Monitoring", module: "monitoring" },
18
- { label: "Production", module: "production" },
19
- { label: "Affiliate", module: "affiliate" },
20
- { label: "Reporting", module: "reporting" },
21
- { label: "Export", module: "export" },
22
- { label: "Configuration", module: "config" },
23
- { label: "Terminal", module: "terminal" },
24
- ];
25
- export default aYOUneModules;
26
- export { aYOUneModules };
@@ -1,5 +0,0 @@
1
- const operations = [
2
- 'list',
3
- 'get',
4
- ];
5
- export { operations };
@@ -1,42 +0,0 @@
1
- import { api } from "./apiClient.js";
2
- import { spinner } from "../../index.js";
3
- import * as process from "process";
4
- import { login } from "./login.js";
5
- import { localStorage } from "../helpers/localStorage.js";
6
- export const apiCallHandler = async (url, method = "get", data = null, params = {}) => {
7
- var _a, _b, _c;
8
- try {
9
- const response = await api({
10
- method,
11
- url,
12
- data,
13
- params: { ...params, ref: `ayoune-cli@${process.env.AYOUNE_VERSION}` },
14
- headers: {
15
- Authorization: `Bearer ${localStorage.getItem("token")}`,
16
- },
17
- });
18
- return response.data;
19
- }
20
- catch (error) {
21
- const apiError = error.response;
22
- if (apiError.status === 400) {
23
- spinner.error({
24
- text: `Bad Request: ${apiError.data.meta.message}`,
25
- });
26
- }
27
- if (apiError.status === 401) {
28
- await login();
29
- }
30
- if (apiError.status === 403) {
31
- spinner.error({
32
- text: `You are not allowed to access this ressource... Required rights are [${(_c = (_b = (_a = apiError.data) === null || _a === void 0 ? void 0 : _a.meta) === null || _b === void 0 ? void 0 : _b.requiredRights) === null || _c === void 0 ? void 0 : _c.join(",")}]`,
33
- });
34
- }
35
- else {
36
- spinner.error({
37
- text: `Status ${apiError.status}: ${apiError.statusText} | ${apiError.data.meta.message}`,
38
- });
39
- }
40
- return apiError.data;
41
- }
42
- };
@@ -1,16 +0,0 @@
1
- import axios from "axios";
2
- import axiosRetry from "axios-retry";
3
- const hosts = {
4
- api: "https://api.ayoune.app",
5
- api_dev: "http://localhost:3000",
6
- audit: "https://audit.ayoune.app",
7
- };
8
- const api = axios.create({
9
- baseURL: hosts.api_dev,
10
- });
11
- const audit = axios.create({
12
- baseURL: hosts.audit,
13
- });
14
- axiosRetry(api, { retries: 3 });
15
- axiosRetry(audit, { retries: 3 });
16
- export { api, audit };
@@ -1,42 +0,0 @@
1
- import { audit } from "./apiClient.js";
2
- import { spinner } from "../../index.js";
3
- import * as process from "process";
4
- import { login } from "./login.js";
5
- import { localStorage } from "../helpers/localStorage.js";
6
- export const auditCallHandler = async (url, method = "get", data = null, params = {}) => {
7
- var _a, _b, _c;
8
- try {
9
- const response = await audit({
10
- method,
11
- url,
12
- data,
13
- params: { ...params, ref: `ayoune-cli@${process.env.AYOUNE_VERSION}` },
14
- headers: {
15
- Authorization: `Bearer ${localStorage.getItem("token")}`,
16
- },
17
- });
18
- return response.data;
19
- }
20
- catch (error) {
21
- const apiError = error.response;
22
- if (apiError.status === 400) {
23
- spinner.error({
24
- text: `Bad Request: ${apiError.data.meta.message}`,
25
- });
26
- }
27
- if (apiError.status === 401) {
28
- await login();
29
- }
30
- if (apiError.status === 403) {
31
- spinner.error({
32
- text: `You are not allowed to access this ressource... Required rights are [${(_c = (_b = (_a = apiError.data) === null || _a === void 0 ? void 0 : _a.meta) === null || _b === void 0 ? void 0 : _b.requiredRights) === null || _c === void 0 ? void 0 : _c.join(",")}]`,
33
- });
34
- }
35
- else {
36
- spinner.error({
37
- text: `Status ${apiError.status}: ${apiError.statusText} | ${apiError.data.meta.message}`,
38
- });
39
- }
40
- return apiError.data;
41
- }
42
- };
@@ -1,4 +0,0 @@
1
- import { decode } from "jsonwebtoken";
2
- export const decodeToken = (token) => {
3
- return decode(token, { json: true, complete: true });
4
- };
File without changes
package/lib/api/login.js DELETED
@@ -1,33 +0,0 @@
1
- import { socket } from "../socket/socketClient.js";
2
- import { randomAsciiString } from "../helpers/makeRandomToken.js";
3
- import { spinner } from "../../index.js";
4
- import { localStorage } from "../helpers/localStorage.js";
5
- export const login = async () => {
6
- spinner.start({ text: "Waiting for login\n" });
7
- const token = randomAsciiString();
8
- console.log(`___________________________________________________`);
9
- console.log(`Visit: https://login.ayoune.app/ayoune?cli=${token}`);
10
- console.log(`___________________________________________________`);
11
- const credentials = await waitForCredentials(token);
12
- return credentials;
13
- };
14
- const waitForCredentials = async (token) => {
15
- return new Promise(function (resolve, reject) {
16
- const _socket = socket(token);
17
- _socket.on("join:cli:confirmed", async (data) => {
18
- spinner.update({ text: `Session active` });
19
- });
20
- _socket.on("cli-token", async (data) => {
21
- spinner.success({ text: `Received auth credentials` });
22
- localStorage.setItem("token", data.token);
23
- localStorage.setItem("refreshToken", data.refreshToken);
24
- resolve(data);
25
- });
26
- _socket.on("connect_error", async (err) => {
27
- spinner.error({ text: err.message });
28
- });
29
- _socket.on("connect", async () => {
30
- spinner.update({ text: "Tunnel established. Waiting for credentials" });
31
- });
32
- });
33
- };
@@ -1,30 +0,0 @@
1
- import { Argument } from "commander";
2
- import { localStorage } from "../helpers/localStorage.js";
3
- import { handleAuditOperation } from "../operations/handleAuditOperation.js";
4
- import { promptAudits } from "../prompts/promptAudits.js";
5
- import { handleSingleAuditOperation } from "../operations/handleSingleAuditOperation.js";
6
- import yaml from "js-yaml";
7
- export function createAuditCommand(program) {
8
- program
9
- .command("audit")
10
- .addArgument(new Argument("[collection]", "The collection to use").default(localStorage.getItem("lastCollection"), `The last used collection (${localStorage.getItem("lastCollection")})`))
11
- .addArgument(new Argument("[id]", "The id to get the audit from").default(localStorage.getItem("lastId"), `The last used id (${localStorage.getItem("lastId")})`))
12
- .alias("history")
13
- .description("Get the history of <id> in <collection>")
14
- .action(async (collection, id, options) => {
15
- try {
16
- const opts = { ...program.opts(), ...options };
17
- const { data, content, result, meta } = await handleAuditOperation(collection, id, {
18
- ...opts,
19
- });
20
- const selectedAudit = await promptAudits(result);
21
- const { singleData, singleContent, singleResult, singleMeta } = await handleSingleAuditOperation(collection, id, selectedAudit, {
22
- ...opts,
23
- });
24
- console.log(yaml.dump(singleContent));
25
- }
26
- catch (e) {
27
- console.error(e);
28
- }
29
- });
30
- }
@@ -1,24 +0,0 @@
1
- import { Argument } from "commander";
2
- import { getModuleFromCollection } from "../models/getModuleFromCollection.js";
3
- import { handleCopySingleOperation } from "../operations/handleCopySingleOperation.js";
4
- import { localStorage } from "../helpers/localStorage.js";
5
- export function createCopyCommand(program) {
6
- program
7
- .command("copy")
8
- .addArgument(new Argument("[collection]", "The collection to use").default(localStorage.getItem("lastCollection"), `The last used collection (${localStorage.getItem("lastCollection")})`))
9
- .addArgument(new Argument("[id]", "The id to get the audit from").default(localStorage.getItem("lastId"), `The last used id (${localStorage.getItem("lastId")})`))
10
- .alias("cp")
11
- .description("Copy entry with <id> in <collection>")
12
- .action(async (collection, id, options) => {
13
- try {
14
- const opts = { ...program.opts(), ...options };
15
- const module = getModuleFromCollection(collection);
16
- await handleCopySingleOperation(module.module, collection, id, {
17
- ...opts,
18
- });
19
- }
20
- catch (e) {
21
- console.error(e);
22
- }
23
- });
24
- }
@@ -1,31 +0,0 @@
1
- import { Argument } from "commander";
2
- import { getModuleFromCollection } from "../models/getModuleFromCollection.js";
3
- import { promptCollectionWithModule } from "../prompts/promptCollectionWithModule.js";
4
- import { handleCreateSingleOperation } from "../operations/handleCreateSingleOperation.js";
5
- import { promptName } from "../prompts/promptName.js";
6
- import { localStorage } from "../helpers/localStorage.js";
7
- export function createCreateCommand(program) {
8
- program
9
- .command("create")
10
- .alias("c")
11
- .addArgument(new Argument("[collection]", "The collection to use").default(localStorage.getItem("lastCollection"), `The last used collection (${localStorage.getItem("lastCollection")})`))
12
- .description("Create entry in <collection>")
13
- .action(async (collection, options) => {
14
- try {
15
- const opts = { ...program.opts(), ...options };
16
- if (!collection) {
17
- collection = await promptCollectionWithModule();
18
- }
19
- const module = getModuleFromCollection(collection);
20
- const name = await promptName();
21
- await handleCreateSingleOperation(module.module, collection, name, {
22
- ...opts,
23
- });
24
- localStorage.setItem("lastModule", module.module);
25
- localStorage.setItem("lastCollection", collection);
26
- }
27
- catch (e) {
28
- console.error(e);
29
- }
30
- });
31
- }
@@ -1,27 +0,0 @@
1
- import { Argument } from "commander";
2
- import { getModuleFromCollection } from "../models/getModuleFromCollection.js";
3
- import { handleDescribeSingleOperation } from "../operations/handleDescribeSingleOperation.js";
4
- import { localStorage } from "../helpers/localStorage.js";
5
- export function createDescribeCommand(program) {
6
- program
7
- .command("describe")
8
- .alias("d")
9
- .description("Describe entry with <id> in <collection>")
10
- .addArgument(new Argument("[collection]", "The collection to use").default(localStorage.getItem("lastCollection"), `The last used collection (${localStorage.getItem("lastCollection")})`))
11
- .addArgument(new Argument("[id]", "The id to get the audit from").default(localStorage.getItem("lastId"), `The last used id (${localStorage.getItem("lastId")})`))
12
- .action(async (collection, id, options) => {
13
- try {
14
- const opts = { ...program.opts(), ...options };
15
- const module = getModuleFromCollection(collection);
16
- localStorage.setItem("lastModule", module.module);
17
- localStorage.setItem("lastCollection", collection);
18
- localStorage.setItem("lastId", id);
19
- await handleDescribeSingleOperation(module.module, collection, id, {
20
- ...opts,
21
- });
22
- }
23
- catch (e) {
24
- console.error(e);
25
- }
26
- });
27
- }
@@ -1,28 +0,0 @@
1
- import { Argument } from "commander";
2
- import { getModuleFromCollection } from "../models/getModuleFromCollection.js";
3
- import { handleGetSingleOperation } from "../operations/handleGetSingleOperation.js";
4
- import { handleEditOperation } from "../operations/handleEditOperation.js";
5
- import { localStorage } from "../helpers/localStorage.js";
6
- export function createEditCommand(program) {
7
- program
8
- .command("edit")
9
- .alias("e")
10
- .description("Edit entry with [id] in [collection]")
11
- .addArgument(new Argument("[collection]", "The collection to use").default(localStorage.getItem("lastCollection"), `The last used collection (${localStorage.getItem("lastCollection")})`))
12
- .addArgument(new Argument("[id]", "The id to get the audit from").default(localStorage.getItem("lastId"), `The last used id (${localStorage.getItem("lastId")})`))
13
- .action(async (collection, id, options) => {
14
- try {
15
- const opts = { ...program.opts(), ...options };
16
- const module = getModuleFromCollection(collection);
17
- localStorage.setItem("lastModule", module.module);
18
- localStorage.setItem("lastCollection", collection);
19
- localStorage.setItem("lastId", id);
20
- let result = {};
21
- result = await handleGetSingleOperation(module.module, collection, id, opts);
22
- await handleEditOperation(module.module, collection, result.content);
23
- }
24
- catch (e) {
25
- console.error(e);
26
- }
27
- });
28
- }
@@ -1,54 +0,0 @@
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,36 +0,0 @@
1
- import { parseInteger } from "../helpers/parseInt.js";
2
- import { promptCollectionWithModule } from "../prompts/promptCollectionWithModule.js";
3
- import { getModuleFromCollection } from "../models/getModuleFromCollection.js";
4
- import { saveFile } from "../helpers/saveFile.js";
5
- import { handleGetOperation } from "../operations/handleGetOperation.js";
6
- import { localStorage } from "../helpers/localStorage.js";
7
- export function createGetCommand(program) {
8
- program
9
- .command("get [collection]")
10
- .alias("g")
11
- .description("Get Data 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
- .option("-i, --fields <fields...>", "Fields to get")
16
- .action(async (collection, options) => {
17
- try {
18
- const opts = { ...program.opts(), ...options };
19
- if (!collection) {
20
- collection = await promptCollectionWithModule();
21
- }
22
- const module = getModuleFromCollection(collection);
23
- localStorage.setItem("lastModule", module.module);
24
- localStorage.setItem("lastCollection", collection);
25
- let result = {};
26
- let entry = "";
27
- result = await handleGetOperation(module.module, collection, opts);
28
- if (opts.save) {
29
- await saveFile("get", opts, result);
30
- }
31
- }
32
- catch (e) {
33
- console.error(e);
34
- }
35
- });
36
- }
@@ -1,35 +0,0 @@
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,17 +0,0 @@
1
- import { login } from "../api/login.js";
2
- import * as process from "process";
3
- export function createLoginCommand(program) {
4
- program
5
- .command("login")
6
- .alias("auth")
7
- .description("Login to your aYOUne account")
8
- .action(async () => {
9
- try {
10
- await login();
11
- process.exit();
12
- }
13
- catch (e) {
14
- console.error(e);
15
- }
16
- });
17
- }
@@ -1,20 +0,0 @@
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,41 +0,0 @@
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
- import { handleGetOperation } from "../operations/handleGetOperation.js";
10
- export function createModulesCommand(program) {
11
- program
12
- .command("modules")
13
- .alias("m")
14
- .description("List modules")
15
- .option("-p, --page <number>", "Page", parseInteger, 1)
16
- .option("-l, --limit <number>", "Limit", parseInteger, 20)
17
- .option("-f, --from <date>", "From date")
18
- .action(async (options) => {
19
- try {
20
- const opts = { ...program.opts(), ...options };
21
- const module = await promptModule();
22
- const collection = await promptCollectionInModule(module);
23
- const operation = await promptOperation();
24
- localStorage.setItem("lastModule", module);
25
- localStorage.setItem("lastCollection", collection);
26
- let entry = "";
27
- if (operation === "list") {
28
- const { result } = await handleListOperation(module, collection, opts);
29
- entry = await promptEntry(result);
30
- }
31
- if (operation === "get") {
32
- const { result } = await handleGetOperation(module, collection, opts);
33
- entry = await promptEntry(result);
34
- }
35
- await handleCollectionOperation(module, collection, entry, opts);
36
- }
37
- catch (e) {
38
- console.error(e);
39
- }
40
- });
41
- }
@@ -1,67 +0,0 @@
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
- program.addHelpText("beforeAll", `
53
- __ ______ _ _
54
- \\ \\ / / __ \\| | | |
55
- __ \\ \\_/ / | | | | | |_ __ ___
56
- / _\` \\ /| | | | | | | '_ \\ / _ \\
57
- | (_| || | | |__| | |__| | | | | __/
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
- }
@@ -1,16 +0,0 @@
1
- import { localStorage } from "../helpers/localStorage.js";
2
- export function createStorageCommand(program) {
3
- program
4
- .command("storage")
5
- .alias("s")
6
- .description("Show current local storage")
7
- .action(async () => {
8
- try {
9
- const storage = { ...localStorage };
10
- console.table(storage);
11
- }
12
- catch (e) {
13
- console.error(e);
14
- }
15
- });
16
- }