@tolinax/ayoune-cli 2024.2.15 → 2024.2.17
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/data/modelsAndRights.js +3189 -0
- package/data/modules.js +26 -0
- package/index.js +11 -11
- package/lib/api/login.js +1 -1
- package/lib/commands/createAuditCommand.js +30 -30
- package/lib/commands/createCopyCommand.js +2 -2
- package/lib/commands/createCreateCommand.js +3 -1
- package/lib/commands/createDescribeCommand.js +4 -1
- package/lib/commands/createEditCommand.js +5 -2
- package/lib/commands/createListCommand.js +35 -35
- package/lib/commands/createModulesCommand.js +41 -41
- package/lib/helpers/handleResponseFormatOptions.js +43 -43
- package/lib/helpers/makeRandomToken.js +27 -0
- package/lib/models/getCollections.js +1 -1
- package/lib/models/getModelsInModules.js +1 -1
- package/lib/models/getModuleFromCollection.js +1 -1
- package/lib/operations/handleCollectionOperation.js +68 -68
- package/lib/operations/handleEditRawOperation.js +35 -35
- package/lib/operations/handleGetOperation.js +25 -25
- package/lib/prompts/promptAudits.js +15 -15
- package/lib/prompts/promptFileName.js +12 -12
- package/lib/prompts/promptFilePath.js +18 -18
- package/lib/prompts/promptModule.js +1 -1
- package/package.json +1 -2
- package/lib/prompts/prompFilePath.js +0 -11
package/data/modules.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
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 };
|
package/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
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
|
-
//Create new command instance
|
|
7
|
-
const program = new Command();
|
|
8
|
-
initializeSettings();
|
|
9
|
-
//Setup spinner
|
|
10
|
-
export const spinner = createSpinner("Getting data...");
|
|
11
|
-
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
|
+
//Create new command instance
|
|
7
|
+
const program = new Command();
|
|
8
|
+
initializeSettings();
|
|
9
|
+
//Setup spinner
|
|
10
|
+
export const spinner = createSpinner("Getting data...");
|
|
11
|
+
createProgram(program);
|
package/lib/api/login.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { socket } from "../socket/socketClient.js";
|
|
2
|
-
import { randomAsciiString } from "
|
|
2
|
+
import { randomAsciiString } from "../helpers/makeRandomToken.js";
|
|
3
3
|
import { spinner } from "../../index.js";
|
|
4
4
|
import { localStorage } from "../helpers/localStorage.js";
|
|
5
5
|
export const login = async () => {
|
|
@@ -1,30 +1,30 @@
|
|
|
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"),
|
|
11
|
-
.addArgument(new Argument("[id]", "The id to get the audit from").default(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
|
+
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
|
+
}
|
|
@@ -5,8 +5,8 @@ import { localStorage } from "../helpers/localStorage.js";
|
|
|
5
5
|
export function createCopyCommand(program) {
|
|
6
6
|
program
|
|
7
7
|
.command("copy")
|
|
8
|
-
.addArgument(new Argument("[collection]", "The collection to use").default(localStorage.getItem("lastCollection"),
|
|
9
|
-
.addArgument(new Argument("[id]", "The id to
|
|
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
10
|
.alias("cp")
|
|
11
11
|
.description("Copy entry with <id> in <collection>")
|
|
12
12
|
.action(async (collection, id, options) => {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Argument } from "commander";
|
|
1
2
|
import { getModuleFromCollection } from "../models/getModuleFromCollection.js";
|
|
2
3
|
import { promptCollectionWithModule } from "../prompts/promptCollectionWithModule.js";
|
|
3
4
|
import { handleCreateSingleOperation } from "../operations/handleCreateSingleOperation.js";
|
|
@@ -5,8 +6,9 @@ import { promptName } from "../prompts/promptName.js";
|
|
|
5
6
|
import { localStorage } from "../helpers/localStorage.js";
|
|
6
7
|
export function createCreateCommand(program) {
|
|
7
8
|
program
|
|
8
|
-
.command("create
|
|
9
|
+
.command("create")
|
|
9
10
|
.alias("c")
|
|
11
|
+
.addArgument(new Argument("[collection]", "The collection to use").default(localStorage.getItem("lastCollection"), `The last used collection (${localStorage.getItem("lastCollection")})`))
|
|
10
12
|
.description("Create entry in <collection>")
|
|
11
13
|
.action(async (collection, options) => {
|
|
12
14
|
try {
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
+
import { Argument } from "commander";
|
|
1
2
|
import { getModuleFromCollection } from "../models/getModuleFromCollection.js";
|
|
2
3
|
import { handleDescribeSingleOperation } from "../operations/handleDescribeSingleOperation.js";
|
|
3
4
|
import { localStorage } from "../helpers/localStorage.js";
|
|
4
5
|
export function createDescribeCommand(program) {
|
|
5
6
|
program
|
|
6
|
-
.command("describe
|
|
7
|
+
.command("describe")
|
|
7
8
|
.alias("d")
|
|
8
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")})`))
|
|
9
12
|
.action(async (collection, id, options) => {
|
|
10
13
|
try {
|
|
11
14
|
const opts = { ...program.opts(), ...options };
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
import { Argument } from "commander";
|
|
1
2
|
import { getModuleFromCollection } from "../models/getModuleFromCollection.js";
|
|
2
3
|
import { handleGetSingleOperation } from "../operations/handleGetSingleOperation.js";
|
|
3
4
|
import { handleEditOperation } from "../operations/handleEditOperation.js";
|
|
4
5
|
import { localStorage } from "../helpers/localStorage.js";
|
|
5
6
|
export function createEditCommand(program) {
|
|
6
7
|
program
|
|
7
|
-
.command("edit
|
|
8
|
+
.command("edit")
|
|
8
9
|
.alias("e")
|
|
9
|
-
.description("Edit entry with
|
|
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")})`))
|
|
10
13
|
.action(async (collection, id, options) => {
|
|
11
14
|
try {
|
|
12
15
|
const opts = { ...program.opts(), ...options };
|
|
@@ -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,41 +1,41 @@
|
|
|
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
|
+
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,43 +1,43 @@
|
|
|
1
|
-
import yaml from "js-yaml";
|
|
2
|
-
export function handleResponseFormatOptions(opts, res) {
|
|
3
|
-
let plainResult;
|
|
4
|
-
let result;
|
|
5
|
-
let meta = {};
|
|
6
|
-
let content;
|
|
7
|
-
if (opts.responseFormat && opts.responseFormat === "yaml") {
|
|
8
|
-
plainResult = yaml.load(res);
|
|
9
|
-
result = plainResult.payload;
|
|
10
|
-
meta = plainResult.meta;
|
|
11
|
-
content = yaml.dump(result);
|
|
12
|
-
console.log("\n");
|
|
13
|
-
console.log(content);
|
|
14
|
-
console.log("\n");
|
|
15
|
-
}
|
|
16
|
-
if (opts.responseFormat && opts.responseFormat === "csv") {
|
|
17
|
-
plainResult = res;
|
|
18
|
-
result = res.payload;
|
|
19
|
-
meta = res.meta;
|
|
20
|
-
content = result;
|
|
21
|
-
console.log("\n");
|
|
22
|
-
console.log(content);
|
|
23
|
-
console.log("\n");
|
|
24
|
-
}
|
|
25
|
-
if (opts.responseFormat && opts.responseFormat === "table") {
|
|
26
|
-
plainResult = res;
|
|
27
|
-
result = res.payload;
|
|
28
|
-
meta = res.meta;
|
|
29
|
-
content = result;
|
|
30
|
-
console.log("\n");
|
|
31
|
-
console.log(res);
|
|
32
|
-
console.log("\n");
|
|
33
|
-
}
|
|
34
|
-
if (opts.responseFormat && opts.responseFormat === "json") {
|
|
35
|
-
result = res.payload;
|
|
36
|
-
meta = res.meta;
|
|
37
|
-
content = JSON.stringify(result, null, 4);
|
|
38
|
-
console.log("\n");
|
|
39
|
-
console.table(result);
|
|
40
|
-
console.log("\n");
|
|
41
|
-
}
|
|
42
|
-
return { plainResult, result, meta, content };
|
|
43
|
-
}
|
|
1
|
+
import yaml from "js-yaml";
|
|
2
|
+
export function handleResponseFormatOptions(opts, res) {
|
|
3
|
+
let plainResult;
|
|
4
|
+
let result;
|
|
5
|
+
let meta = {};
|
|
6
|
+
let content;
|
|
7
|
+
if (opts.responseFormat && opts.responseFormat === "yaml") {
|
|
8
|
+
plainResult = yaml.load(res);
|
|
9
|
+
result = plainResult.payload;
|
|
10
|
+
meta = plainResult.meta;
|
|
11
|
+
content = yaml.dump(result);
|
|
12
|
+
console.log("\n");
|
|
13
|
+
console.log(content);
|
|
14
|
+
console.log("\n");
|
|
15
|
+
}
|
|
16
|
+
if (opts.responseFormat && opts.responseFormat === "csv") {
|
|
17
|
+
plainResult = res;
|
|
18
|
+
result = res.payload;
|
|
19
|
+
meta = res.meta;
|
|
20
|
+
content = result;
|
|
21
|
+
console.log("\n");
|
|
22
|
+
console.log(content);
|
|
23
|
+
console.log("\n");
|
|
24
|
+
}
|
|
25
|
+
if (opts.responseFormat && opts.responseFormat === "table") {
|
|
26
|
+
plainResult = res;
|
|
27
|
+
result = res.payload;
|
|
28
|
+
meta = res.meta;
|
|
29
|
+
content = result;
|
|
30
|
+
console.log("\n");
|
|
31
|
+
console.log(res);
|
|
32
|
+
console.log("\n");
|
|
33
|
+
}
|
|
34
|
+
if (opts.responseFormat && opts.responseFormat === "json") {
|
|
35
|
+
result = res.payload;
|
|
36
|
+
meta = res.meta;
|
|
37
|
+
content = JSON.stringify(result, null, 4);
|
|
38
|
+
console.log("\n");
|
|
39
|
+
console.table(result);
|
|
40
|
+
console.log("\n");
|
|
41
|
+
}
|
|
42
|
+
return { plainResult, result, meta, content };
|
|
43
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { randomBytes } from "crypto";
|
|
2
|
+
/** Sync */
|
|
3
|
+
const randomString = (length, chars) => {
|
|
4
|
+
if (!chars) {
|
|
5
|
+
throw new Error("Argument 'chars' is undefined");
|
|
6
|
+
}
|
|
7
|
+
const charsLength = chars.length;
|
|
8
|
+
if (charsLength > 256) {
|
|
9
|
+
throw new Error("Argument 'chars' should not have more than 256 characters" +
|
|
10
|
+
", otherwise unpredictability will be broken");
|
|
11
|
+
}
|
|
12
|
+
const _randomBytes = randomBytes(length);
|
|
13
|
+
let result = new Array(length);
|
|
14
|
+
let cursor = 0;
|
|
15
|
+
for (let i = 0; i < length; i++) {
|
|
16
|
+
cursor += _randomBytes[i];
|
|
17
|
+
result[i] = chars[cursor % charsLength];
|
|
18
|
+
}
|
|
19
|
+
return result.join("");
|
|
20
|
+
};
|
|
21
|
+
/** Sync */
|
|
22
|
+
export const randomAsciiString = (length = 32, alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") => {
|
|
23
|
+
if (typeof length === "undefined") {
|
|
24
|
+
length = 32;
|
|
25
|
+
}
|
|
26
|
+
return randomString(length, alphabet);
|
|
27
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { modelsAndRights } from "
|
|
1
|
+
import { modelsAndRights } from "../../data/modelsAndRights.js";
|
|
2
2
|
import { addSpacesToCamelCase } from "../helpers/addSpacesToCamelCase.js";
|
|
3
3
|
const getCollections = () => {
|
|
4
4
|
return modelsAndRights
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _ from "lodash";
|
|
2
2
|
import { addSpacesToCamelCase } from "../helpers/addSpacesToCamelCase.js";
|
|
3
|
-
import { modelsAndRights } from "
|
|
3
|
+
import { modelsAndRights } from "../../data/modelsAndRights.js";
|
|
4
4
|
const getModelsInModules = (module) => {
|
|
5
5
|
const m = _.filter(modelsAndRights, { module });
|
|
6
6
|
return m.map((el) => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _ from "lodash";
|
|
2
|
-
import { modelsAndRights } from "
|
|
2
|
+
import { modelsAndRights } from "../../data/modelsAndRights.js";
|
|
3
3
|
const getModuleFromCollection = (collection) => {
|
|
4
4
|
const m = _.find(modelsAndRights, (el) => el.plural.toLowerCase() === collection);
|
|
5
5
|
return m;
|
|
@@ -1,68 +1,68 @@
|
|
|
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
|
-
import yaml from "js-yaml";
|
|
8
|
-
import { promptFilePath } from "../prompts/promptFilePath.js";
|
|
9
|
-
import { promptFileName } from "../prompts/promptFileName.js";
|
|
10
|
-
import path from "path";
|
|
11
|
-
import { writeFile } from "fs/promises";
|
|
12
|
-
import { mkdirp } from "mkdirp";
|
|
13
|
-
export async function handleCollectionOperation(module, collection, entry, opts) {
|
|
14
|
-
spinner.start({ text: "", color: "magenta" });
|
|
15
|
-
let res;
|
|
16
|
-
let editContent;
|
|
17
|
-
const action = await promptDefaultAction();
|
|
18
|
-
switch (action) {
|
|
19
|
-
case "edit":
|
|
20
|
-
res = await apiCallHandler(`${module}/${collection.toLowerCase()}/${entry}?responseFormat=table`);
|
|
21
|
-
spinner.success({
|
|
22
|
-
text: `Got entry ${res.payload.name} - Took ${res.meta.responseTime} ms`,
|
|
23
|
-
});
|
|
24
|
-
spinner.stop();
|
|
25
|
-
editContent = res.payload;
|
|
26
|
-
await handleEditOperation(module, collection, editContent);
|
|
27
|
-
break;
|
|
28
|
-
case "edit raw":
|
|
29
|
-
res = await apiCallHandler(`${module}/${collection.toLowerCase()}/${entry}?responseFormat=${opts.responseFormat}`);
|
|
30
|
-
spinner.success({
|
|
31
|
-
text: `Got entry ${res.payload.name} - Took ${res.meta.responseTime} ms`,
|
|
32
|
-
});
|
|
33
|
-
spinner.stop();
|
|
34
|
-
editContent = res.payload;
|
|
35
|
-
await handleEditRawOperation(module, collection, editContent);
|
|
36
|
-
break;
|
|
37
|
-
case "describe":
|
|
38
|
-
res = await apiCallHandler(`${module}/${collection.toLowerCase()}/${entry}?responseFormat=yaml}`);
|
|
39
|
-
spinner.success({
|
|
40
|
-
text: `Got entry ${res.payload.name} - Took ${res.meta.responseTime} ms`,
|
|
41
|
-
});
|
|
42
|
-
spinner.stop();
|
|
43
|
-
editContent = res.payload;
|
|
44
|
-
console.log(yaml.dump(editContent));
|
|
45
|
-
break;
|
|
46
|
-
case "download":
|
|
47
|
-
res = await apiCallHandler(`${module}/${collection.toLowerCase()}/${entry}?responseFormat=${opts.responseFormat}}`);
|
|
48
|
-
spinner.success({
|
|
49
|
-
text: `Got entry ${res.payload.name} - Took ${res.meta.responseTime} ms`,
|
|
50
|
-
});
|
|
51
|
-
spinner.stop();
|
|
52
|
-
editContent = res.payload;
|
|
53
|
-
const folder = await promptFilePath(collection);
|
|
54
|
-
await mkdirp(folder);
|
|
55
|
-
const fileName = await promptFileName(`${collection}_${editContent._id}.${opts.responseFormat}`);
|
|
56
|
-
const contentToWrite = opts.responseFormat === "yaml"
|
|
57
|
-
? yaml.dump(editContent)
|
|
58
|
-
: opts.responseFormat === "csv"
|
|
59
|
-
? editContent
|
|
60
|
-
: JSON.stringify(editContent, null, 4);
|
|
61
|
-
await writeFile(path.join(folder, fileName), contentToWrite, {
|
|
62
|
-
encoding: "utf8",
|
|
63
|
-
});
|
|
64
|
-
break;
|
|
65
|
-
default:
|
|
66
|
-
break;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
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
|
+
import yaml from "js-yaml";
|
|
8
|
+
import { promptFilePath } from "../prompts/promptFilePath.js";
|
|
9
|
+
import { promptFileName } from "../prompts/promptFileName.js";
|
|
10
|
+
import path from "path";
|
|
11
|
+
import { writeFile } from "fs/promises";
|
|
12
|
+
import { mkdirp } from "mkdirp";
|
|
13
|
+
export async function handleCollectionOperation(module, collection, entry, opts) {
|
|
14
|
+
spinner.start({ text: "", color: "magenta" });
|
|
15
|
+
let res;
|
|
16
|
+
let editContent;
|
|
17
|
+
const action = await promptDefaultAction();
|
|
18
|
+
switch (action) {
|
|
19
|
+
case "edit":
|
|
20
|
+
res = await apiCallHandler(`${module}/${collection.toLowerCase()}/${entry}?responseFormat=table`);
|
|
21
|
+
spinner.success({
|
|
22
|
+
text: `Got entry ${res.payload.name} - Took ${res.meta.responseTime} ms`,
|
|
23
|
+
});
|
|
24
|
+
spinner.stop();
|
|
25
|
+
editContent = res.payload;
|
|
26
|
+
await handleEditOperation(module, collection, editContent);
|
|
27
|
+
break;
|
|
28
|
+
case "edit raw":
|
|
29
|
+
res = await apiCallHandler(`${module}/${collection.toLowerCase()}/${entry}?responseFormat=${opts.responseFormat}`);
|
|
30
|
+
spinner.success({
|
|
31
|
+
text: `Got entry ${res.payload.name} - Took ${res.meta.responseTime} ms`,
|
|
32
|
+
});
|
|
33
|
+
spinner.stop();
|
|
34
|
+
editContent = res.payload;
|
|
35
|
+
await handleEditRawOperation(module, collection, editContent);
|
|
36
|
+
break;
|
|
37
|
+
case "describe":
|
|
38
|
+
res = await apiCallHandler(`${module}/${collection.toLowerCase()}/${entry}?responseFormat=yaml}`);
|
|
39
|
+
spinner.success({
|
|
40
|
+
text: `Got entry ${res.payload.name} - Took ${res.meta.responseTime} ms`,
|
|
41
|
+
});
|
|
42
|
+
spinner.stop();
|
|
43
|
+
editContent = res.payload;
|
|
44
|
+
console.log(yaml.dump(editContent));
|
|
45
|
+
break;
|
|
46
|
+
case "download":
|
|
47
|
+
res = await apiCallHandler(`${module}/${collection.toLowerCase()}/${entry}?responseFormat=${opts.responseFormat}}`);
|
|
48
|
+
spinner.success({
|
|
49
|
+
text: `Got entry ${res.payload.name} - Took ${res.meta.responseTime} ms`,
|
|
50
|
+
});
|
|
51
|
+
spinner.stop();
|
|
52
|
+
editContent = res.payload;
|
|
53
|
+
const folder = await promptFilePath(collection);
|
|
54
|
+
await mkdirp(folder);
|
|
55
|
+
const fileName = await promptFileName(`${collection}_${editContent._id}.${opts.responseFormat}`);
|
|
56
|
+
const contentToWrite = opts.responseFormat === "yaml"
|
|
57
|
+
? yaml.dump(editContent)
|
|
58
|
+
: opts.responseFormat === "csv"
|
|
59
|
+
? editContent
|
|
60
|
+
: JSON.stringify(editContent, null, 4);
|
|
61
|
+
await writeFile(path.join(folder, fileName), contentToWrite, {
|
|
62
|
+
encoding: "utf8",
|
|
63
|
+
});
|
|
64
|
+
break;
|
|
65
|
+
default:
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
}
|