@tolinax/ayoune-cli 2024.2.18 → 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.
- package/index.js +11 -11
- package/package.json +156 -147
- package/data/defaultActions.js +0 -9
- package/data/modelsAndRights.js +0 -3189
- package/data/modules.js +0 -26
- package/data/operations.js +0 -5
- package/lib/api/apiCallHandler.js +0 -42
- package/lib/api/apiClient.js +0 -16
- package/lib/api/auditCallHandler.js +0 -42
- package/lib/api/decodeToken.js +0 -4
- package/lib/api/handleAPIError.js +0 -0
- package/lib/api/login.js +0 -33
- package/lib/commands/createAuditCommand.js +0 -30
- package/lib/commands/createCopyCommand.js +0 -24
- package/lib/commands/createCreateCommand.js +0 -31
- package/lib/commands/createDescribeCommand.js +0 -27
- package/lib/commands/createEditCommand.js +0 -28
- package/lib/commands/createEventsCommand.js +0 -54
- package/lib/commands/createGetCommand.js +0 -36
- package/lib/commands/createListCommand.js +0 -35
- package/lib/commands/createLoginCommand.js +0 -17
- package/lib/commands/createLogoutCommand.js +0 -20
- package/lib/commands/createModulesCommand.js +0 -41
- package/lib/commands/createProgram.js +0 -67
- package/lib/commands/createStorageCommand.js +0 -16
- package/lib/commands/createStreamCommand.js +0 -45
- package/lib/commands/createWhoAmICommand.js +0 -26
- package/lib/helpers/addSpacesToCamelCase.js +0 -5
- package/lib/helpers/handleResponseFormatOptions.js +0 -43
- package/lib/helpers/initializeSettings.js +0 -14
- package/lib/helpers/localStorage.js +0 -4
- package/lib/helpers/makeRandomToken.js +0 -27
- package/lib/helpers/parseInt.js +0 -9
- package/lib/helpers/saveFile.js +0 -39
- package/lib/models/getCollections.js +0 -15
- package/lib/models/getModelsInModules.js +0 -13
- package/lib/models/getModuleFromCollection.js +0 -7
- package/lib/operations/handleAuditOperation.js +0 -22
- package/lib/operations/handleCollectionOperation.js +0 -68
- package/lib/operations/handleCopySingleOperation.js +0 -22
- package/lib/operations/handleCreateSingleOperation.js +0 -27
- package/lib/operations/handleDescribeSingleOperation.js +0 -20
- package/lib/operations/handleEditOperation.js +0 -51
- package/lib/operations/handleEditRawOperation.js +0 -35
- package/lib/operations/handleGetOperation.js +0 -25
- package/lib/operations/handleGetSingleOperation.js +0 -20
- package/lib/operations/handleListOperation.js +0 -24
- package/lib/operations/handleSingleAuditOperation.js +0 -27
- package/lib/prompts/promptAudits.js +0 -15
- package/lib/prompts/promptCollection.js +0 -13
- package/lib/prompts/promptCollectionInModule.js +0 -13
- package/lib/prompts/promptCollectionWithModule.js +0 -15
- package/lib/prompts/promptDefaultAction.js +0 -13
- package/lib/prompts/promptEntry.js +0 -12
- package/lib/prompts/promptFileName.js +0 -12
- package/lib/prompts/promptFilePath.js +0 -18
- package/lib/prompts/promptModule.js +0 -19
- package/lib/prompts/promptName.js +0 -11
- package/lib/prompts/promptOperation.js +0 -13
- package/lib/socket/customerSocketClient.js +0 -12
- package/lib/socket/socketClient.js +0 -11
|
@@ -1,45 +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 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,26 +0,0 @@
|
|
|
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,43 +0,0 @@
|
|
|
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,14 +0,0 @@
|
|
|
1
|
-
//Initializes settings for system environment and inquirer
|
|
2
|
-
import inquirer from "inquirer";
|
|
3
|
-
import inquirerFuzzyPath from "inquirer-fuzzy-path";
|
|
4
|
-
import inquirerSearchList from "inquirer-search-list";
|
|
5
|
-
import inquirerFileTreeSelection from "inquirer-file-tree-selection-prompt";
|
|
6
|
-
import inquirerTableInput from "inquirer-table-input";
|
|
7
|
-
import InterruptedPrompt from "inquirer-interrupted-prompt";
|
|
8
|
-
export function initializeSettings() {
|
|
9
|
-
inquirer.registerPrompt("fuzzypath", inquirerFuzzyPath);
|
|
10
|
-
inquirer.registerPrompt("search-list", inquirerSearchList);
|
|
11
|
-
inquirer.registerPrompt("file-tree-selection", inquirerFileTreeSelection);
|
|
12
|
-
inquirer.registerPrompt("table-input", inquirerTableInput);
|
|
13
|
-
InterruptedPrompt.fromAll(inquirer);
|
|
14
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
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
|
-
};
|
package/lib/helpers/parseInt.js
DELETED
package/lib/helpers/saveFile.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { mkdirp } from "mkdirp";
|
|
2
|
-
import moment from "moment";
|
|
3
|
-
import path from "path";
|
|
4
|
-
import { writeFile } from "fs/promises";
|
|
5
|
-
import { spinner } from "../../index.js";
|
|
6
|
-
export async function saveFile(type, opts, result) {
|
|
7
|
-
if (opts.save) {
|
|
8
|
-
await mkdirp(opts.outPath);
|
|
9
|
-
const fileName = opts.name
|
|
10
|
-
? opts.name
|
|
11
|
-
: type +
|
|
12
|
-
"_page_" +
|
|
13
|
-
result.meta.pageInfo.page +
|
|
14
|
-
"_" +
|
|
15
|
-
moment().format("YYYY_DD_MM_HH_mm_ss");
|
|
16
|
-
const pathToWrite = path.join(opts.outPath, `${fileName}`).toString();
|
|
17
|
-
console.log(pathToWrite);
|
|
18
|
-
spinner.start({
|
|
19
|
-
text: `Saving operation as ${pathToWrite}.${opts.responseFormat}`,
|
|
20
|
-
color: "yellow",
|
|
21
|
-
});
|
|
22
|
-
await writeFile(`${pathToWrite}.${opts.responseFormat}`, result.content, {
|
|
23
|
-
encoding: "utf8",
|
|
24
|
-
});
|
|
25
|
-
spinner.success({
|
|
26
|
-
text: `File written: ${pathToWrite}.${opts.responseFormat}`,
|
|
27
|
-
});
|
|
28
|
-
if (opts.debug) {
|
|
29
|
-
spinner.start({
|
|
30
|
-
text: `Saving operation as ${pathToWrite}.meta.json`,
|
|
31
|
-
color: "yellow",
|
|
32
|
-
});
|
|
33
|
-
await writeFile(`${pathToWrite}.meta.json`, JSON.stringify(result.meta, null, 4), {
|
|
34
|
-
encoding: "utf8",
|
|
35
|
-
});
|
|
36
|
-
spinner.success({ text: `File written: ${pathToWrite}.meta.json` });
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { modelsAndRights } from "../../data/modelsAndRights.js";
|
|
2
|
-
import { addSpacesToCamelCase } from "../helpers/addSpacesToCamelCase.js";
|
|
3
|
-
const getCollections = () => {
|
|
4
|
-
return modelsAndRights
|
|
5
|
-
.filter((el) => {
|
|
6
|
-
return el.module !== "su";
|
|
7
|
-
})
|
|
8
|
-
.map((el) => {
|
|
9
|
-
return {
|
|
10
|
-
name: addSpacesToCamelCase(el.plural),
|
|
11
|
-
value: el.plural.toLowerCase(),
|
|
12
|
-
};
|
|
13
|
-
});
|
|
14
|
-
};
|
|
15
|
-
export { getCollections };
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import _ from "lodash";
|
|
2
|
-
import { addSpacesToCamelCase } from "../helpers/addSpacesToCamelCase.js";
|
|
3
|
-
import { modelsAndRights } from "../../data/modelsAndRights.js";
|
|
4
|
-
const getModelsInModules = (module) => {
|
|
5
|
-
const m = _.filter(modelsAndRights, { module });
|
|
6
|
-
return m.map((el) => {
|
|
7
|
-
return {
|
|
8
|
-
name: addSpacesToCamelCase(el.plural),
|
|
9
|
-
value: el.plural.toLowerCase(),
|
|
10
|
-
};
|
|
11
|
-
});
|
|
12
|
-
};
|
|
13
|
-
export { getModelsInModules };
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import _ from "lodash";
|
|
2
|
-
import { modelsAndRights } from "../../data/modelsAndRights.js";
|
|
3
|
-
const getModuleFromCollection = (collection) => {
|
|
4
|
-
const m = _.find(modelsAndRights, (el) => el.plural.toLowerCase() === collection);
|
|
5
|
-
return m;
|
|
6
|
-
};
|
|
7
|
-
export { getModuleFromCollection };
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
// Operation handling functions
|
|
2
|
-
import { spinner } from "../../index.js";
|
|
3
|
-
import { handleResponseFormatOptions } from "../helpers/handleResponseFormatOptions.js";
|
|
4
|
-
import { localStorage } from "../helpers/localStorage.js";
|
|
5
|
-
import { auditCallHandler } from "../api/auditCallHandler.js";
|
|
6
|
-
export async function handleAuditOperation(collection, id, opts) {
|
|
7
|
-
spinner.start({
|
|
8
|
-
text: `Getting audit for ${id} in [${collection}]`,
|
|
9
|
-
color: "magenta",
|
|
10
|
-
});
|
|
11
|
-
let res = await auditCallHandler(`${collection.toLowerCase()}/${id}`, "get", null, {
|
|
12
|
-
responseFormat: opts.responseFormat,
|
|
13
|
-
verbosity: opts.verbosity,
|
|
14
|
-
});
|
|
15
|
-
let { plainResult, result, meta, content } = handleResponseFormatOptions({ ...opts }, res);
|
|
16
|
-
spinner.success({
|
|
17
|
-
text: `Got Audit ${id} in ${collection}`,
|
|
18
|
-
});
|
|
19
|
-
spinner.stop();
|
|
20
|
-
localStorage.setItem("lastId", result._id);
|
|
21
|
-
return { data: plainResult, content, result, meta };
|
|
22
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
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,22 +0,0 @@
|
|
|
1
|
-
// Operation handling functions
|
|
2
|
-
import { apiCallHandler } from "../api/apiCallHandler.js";
|
|
3
|
-
import { spinner } from "../../index.js";
|
|
4
|
-
import { handleResponseFormatOptions } from "../helpers/handleResponseFormatOptions.js";
|
|
5
|
-
import { localStorage } from "../helpers/localStorage.js";
|
|
6
|
-
export async function handleCopySingleOperation(module, collection, id, opts) {
|
|
7
|
-
spinner.start({
|
|
8
|
-
text: `Copying entry ${id} in [${collection}]`,
|
|
9
|
-
color: "magenta",
|
|
10
|
-
});
|
|
11
|
-
let res = await apiCallHandler(`${module}/${collection.toLowerCase()}/${id}/copy`, "post", null, {
|
|
12
|
-
responseFormat: opts.responseFormat,
|
|
13
|
-
verbosity: opts.verbosity,
|
|
14
|
-
});
|
|
15
|
-
let { plainResult, result, meta, content } = handleResponseFormatOptions({ ...opts }, res);
|
|
16
|
-
spinner.success({
|
|
17
|
-
text: `Copied entry ${id} in ${collection}: New ID [${result._id}]`,
|
|
18
|
-
});
|
|
19
|
-
spinner.stop();
|
|
20
|
-
localStorage.setItem("lastId", result._id);
|
|
21
|
-
return { data: plainResult, content, result, meta };
|
|
22
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
// Operation handling functions
|
|
2
|
-
import { apiCallHandler } from "../api/apiCallHandler.js";
|
|
3
|
-
import { spinner } from "../../index.js";
|
|
4
|
-
import { handleResponseFormatOptions } from "../helpers/handleResponseFormatOptions.js";
|
|
5
|
-
import { localStorage } from "../helpers/localStorage.js";
|
|
6
|
-
export async function handleCreateSingleOperation(module, collection, name, opts) {
|
|
7
|
-
spinner.start({
|
|
8
|
-
text: `Creating entry in [${collection}]`,
|
|
9
|
-
color: "magenta",
|
|
10
|
-
});
|
|
11
|
-
let res = await apiCallHandler(`${module}/${collection.toLowerCase()}`, "post", {
|
|
12
|
-
name,
|
|
13
|
-
title: name,
|
|
14
|
-
subject: name,
|
|
15
|
-
summary: name,
|
|
16
|
-
}, {
|
|
17
|
-
responseFormat: opts.responseFormat,
|
|
18
|
-
verbosity: opts.verbosity,
|
|
19
|
-
});
|
|
20
|
-
let { plainResult, result, meta, content } = handleResponseFormatOptions({ ...opts }, res);
|
|
21
|
-
spinner.success({
|
|
22
|
-
text: `Created entry [${result._id}] in ${collection}`,
|
|
23
|
-
});
|
|
24
|
-
spinner.stop();
|
|
25
|
-
localStorage.setItem("lastId", result._id);
|
|
26
|
-
return { data: plainResult, content, result, meta };
|
|
27
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
// Operation handling functions
|
|
2
|
-
import { apiCallHandler } from "../api/apiCallHandler.js";
|
|
3
|
-
import { spinner } from "../../index.js";
|
|
4
|
-
import { handleResponseFormatOptions } from "../helpers/handleResponseFormatOptions.js";
|
|
5
|
-
export async function handleDescribeSingleOperation(module, collection, id, opts) {
|
|
6
|
-
spinner.start({
|
|
7
|
-
text: `Getting entry in [${collection}]`,
|
|
8
|
-
color: "magenta",
|
|
9
|
-
});
|
|
10
|
-
let res = await apiCallHandler(`${module}/${collection.toLowerCase()}/${id}`, "get", null, {
|
|
11
|
-
responseFormat: "yaml",
|
|
12
|
-
verbosity: opts.verbosity,
|
|
13
|
-
});
|
|
14
|
-
let { plainResult, result, meta, content } = handleResponseFormatOptions({ ...opts, responseFormat: "yaml" }, res);
|
|
15
|
-
spinner.success({
|
|
16
|
-
text: `Got entry in ${collection}`,
|
|
17
|
-
});
|
|
18
|
-
spinner.stop();
|
|
19
|
-
return { data: plainResult, content, result, meta };
|
|
20
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import inquirer from "inquirer";
|
|
2
|
-
import chalk from "chalk";
|
|
3
|
-
import { apiCallHandler } from "../api/apiCallHandler.js";
|
|
4
|
-
import { spinner } from "../../index.js";
|
|
5
|
-
export async function handleEditOperation(module, collection, editContent) {
|
|
6
|
-
console.log(editContent);
|
|
7
|
-
const { edits } = await inquirer.prompt([
|
|
8
|
-
{
|
|
9
|
-
type: "table-input",
|
|
10
|
-
name: "edits",
|
|
11
|
-
message: "EDIT MODE",
|
|
12
|
-
infoMessage: `Navigate and Edit`,
|
|
13
|
-
hideInfoWhenKeyPressed: true,
|
|
14
|
-
freezeColumns: 1,
|
|
15
|
-
decimalPoint: ".",
|
|
16
|
-
decimalPlaces: 2,
|
|
17
|
-
selectedColor: chalk.yellow,
|
|
18
|
-
editableColor: chalk.bgYellow.bold,
|
|
19
|
-
editingColor: chalk.bgGreen.bold,
|
|
20
|
-
columns: editContent.columns.map((column) => ({
|
|
21
|
-
...column,
|
|
22
|
-
name: column.editable
|
|
23
|
-
? chalk.cyan.bold(column.name)
|
|
24
|
-
: chalk.red.bold(column.name),
|
|
25
|
-
})),
|
|
26
|
-
rows: editContent.rows,
|
|
27
|
-
validate: () => false,
|
|
28
|
-
},
|
|
29
|
-
]);
|
|
30
|
-
console.log(edits);
|
|
31
|
-
const { save } = await inquirer.prompt([
|
|
32
|
-
{
|
|
33
|
-
type: "confirm",
|
|
34
|
-
name: "save",
|
|
35
|
-
message: "Save changes",
|
|
36
|
-
},
|
|
37
|
-
]);
|
|
38
|
-
if (save) {
|
|
39
|
-
spinner.start({
|
|
40
|
-
text: `Attempting to save`,
|
|
41
|
-
color: "magenta",
|
|
42
|
-
});
|
|
43
|
-
const res = await apiCallHandler(`${module}/${collection.toLowerCase()}`, "put", edits.result);
|
|
44
|
-
const result = res.payload;
|
|
45
|
-
console.log(result);
|
|
46
|
-
spinner.success({
|
|
47
|
-
text: `Saved - Took ${res.meta.responseTime} ms`,
|
|
48
|
-
});
|
|
49
|
-
spinner.stop();
|
|
50
|
-
}
|
|
51
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import inquirer from "inquirer";
|
|
2
|
-
import { apiCallHandler } from "../api/apiCallHandler.js";
|
|
3
|
-
import { spinner } from "../../index.js";
|
|
4
|
-
export async function handleEditRawOperation(module, collection, result) {
|
|
5
|
-
const { content } = await inquirer.prompt([
|
|
6
|
-
{
|
|
7
|
-
type: "editor",
|
|
8
|
-
name: "content",
|
|
9
|
-
postfix: ".json",
|
|
10
|
-
message: "Edit",
|
|
11
|
-
default: JSON.stringify(result, null, 4),
|
|
12
|
-
},
|
|
13
|
-
]);
|
|
14
|
-
const contentToSave = JSON.parse(content);
|
|
15
|
-
const { save } = await inquirer.prompt([
|
|
16
|
-
{
|
|
17
|
-
type: "confirm",
|
|
18
|
-
name: "save",
|
|
19
|
-
message: "Save changes",
|
|
20
|
-
},
|
|
21
|
-
]);
|
|
22
|
-
if (save) {
|
|
23
|
-
spinner.start({
|
|
24
|
-
text: `Attempting to save [${contentToSave.name}]`,
|
|
25
|
-
color: "magenta",
|
|
26
|
-
});
|
|
27
|
-
const res = await apiCallHandler(`${module}/${collection.toLowerCase()}`, "put", JSON.parse(content));
|
|
28
|
-
result = res.payload;
|
|
29
|
-
console.log(result);
|
|
30
|
-
spinner.success({
|
|
31
|
-
text: `Saved [${contentToSave.name}] - Took ${res.meta.responseTime} ms`,
|
|
32
|
-
});
|
|
33
|
-
spinner.stop();
|
|
34
|
-
}
|
|
35
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
// Operation handling functions
|
|
2
|
-
import { apiCallHandler } from "../api/apiCallHandler.js";
|
|
3
|
-
import { spinner } from "../../index.js";
|
|
4
|
-
import { handleResponseFormatOptions } from "../helpers/handleResponseFormatOptions.js";
|
|
5
|
-
export async function handleGetOperation(module, collection, opts) {
|
|
6
|
-
spinner.start({
|
|
7
|
-
text: `Getting entries in [${collection}]`,
|
|
8
|
-
color: "magenta",
|
|
9
|
-
});
|
|
10
|
-
let res = await apiCallHandler(`${module}/${collection.toLowerCase()}`, "get", null, {
|
|
11
|
-
page: opts.page,
|
|
12
|
-
responseFormat: opts.responseFormat,
|
|
13
|
-
limit: opts.limit,
|
|
14
|
-
from: opts.from,
|
|
15
|
-
fields: opts.fields,
|
|
16
|
-
hideMeta: opts.hideMeta,
|
|
17
|
-
verbosity: opts.verbosity,
|
|
18
|
-
});
|
|
19
|
-
let { plainResult, result, meta, content } = handleResponseFormatOptions(opts, res);
|
|
20
|
-
spinner.success({
|
|
21
|
-
text: `Got ${opts.limit} entries of ${meta.pageInfo.totalEntries} : Page ${meta.pageInfo.page} of ${meta.pageInfo.totalPages}`,
|
|
22
|
-
});
|
|
23
|
-
spinner.stop();
|
|
24
|
-
return { data: plainResult, content, result, meta };
|
|
25
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
// Operation handling functions
|
|
2
|
-
import { apiCallHandler } from "../api/apiCallHandler.js";
|
|
3
|
-
import { spinner } from "../../index.js";
|
|
4
|
-
import { handleResponseFormatOptions } from "../helpers/handleResponseFormatOptions.js";
|
|
5
|
-
export async function handleGetSingleOperation(module, collection, id, opts) {
|
|
6
|
-
spinner.start({
|
|
7
|
-
text: `Getting entry in [${collection}]`,
|
|
8
|
-
color: "magenta",
|
|
9
|
-
});
|
|
10
|
-
let res = await apiCallHandler(`${module}/${collection.toLowerCase()}/${id}`, "get", null, {
|
|
11
|
-
responseFormat: "table",
|
|
12
|
-
verbosity: opts.verbosity,
|
|
13
|
-
});
|
|
14
|
-
let { plainResult, result, meta, content } = handleResponseFormatOptions({ ...opts, responseFormat: "table" }, res);
|
|
15
|
-
spinner.success({
|
|
16
|
-
text: `Got entry in ${collection}`,
|
|
17
|
-
});
|
|
18
|
-
spinner.stop();
|
|
19
|
-
return { data: plainResult, content, result, meta };
|
|
20
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
// Operation handling functions
|
|
2
|
-
import { apiCallHandler } from "../api/apiCallHandler.js";
|
|
3
|
-
import { spinner } from "../../index.js";
|
|
4
|
-
import { handleResponseFormatOptions } from "../helpers/handleResponseFormatOptions.js";
|
|
5
|
-
export async function handleListOperation(module, collection, opts) {
|
|
6
|
-
spinner.start({
|
|
7
|
-
text: `Listing entries in [${collection}]`,
|
|
8
|
-
color: "magenta",
|
|
9
|
-
});
|
|
10
|
-
let res = await apiCallHandler(`${module}/${collection.toLowerCase()}/list`, "get", null, {
|
|
11
|
-
page: opts.page,
|
|
12
|
-
responseFormat: opts.responseFormat,
|
|
13
|
-
limit: opts.limit,
|
|
14
|
-
from: opts.from,
|
|
15
|
-
hideMeta: opts.hideMeta,
|
|
16
|
-
verbosity: opts.verbosity,
|
|
17
|
-
});
|
|
18
|
-
let { plainResult, result, meta, content } = handleResponseFormatOptions(opts, res);
|
|
19
|
-
spinner.success({
|
|
20
|
-
text: `Got ${opts.limit} entries of ${meta.pageInfo.totalEntries} : Page ${meta.pageInfo.page} of ${meta.pageInfo.totalPages}`,
|
|
21
|
-
});
|
|
22
|
-
spinner.stop();
|
|
23
|
-
return { data: plainResult, content, result, meta };
|
|
24
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
// Operation handling functions
|
|
2
|
-
import { spinner } from "../../index.js";
|
|
3
|
-
import { handleResponseFormatOptions } from "../helpers/handleResponseFormatOptions.js";
|
|
4
|
-
import { localStorage } from "../helpers/localStorage.js";
|
|
5
|
-
import { auditCallHandler } from "../api/auditCallHandler.js";
|
|
6
|
-
export async function handleSingleAuditOperation(collection, id, auditId, opts) {
|
|
7
|
-
spinner.start({
|
|
8
|
-
text: `Getting audit [${auditId}] for [${id}] in [${collection}]`,
|
|
9
|
-
color: "magenta",
|
|
10
|
-
});
|
|
11
|
-
let res = await auditCallHandler(`${collection.toLowerCase()}/${id}/${auditId}`, "get", null, {
|
|
12
|
-
responseFormat: opts.responseFormat,
|
|
13
|
-
verbosity: opts.verbosity,
|
|
14
|
-
});
|
|
15
|
-
let { plainResult, result, meta, content } = handleResponseFormatOptions({ ...opts }, res);
|
|
16
|
-
spinner.success({
|
|
17
|
-
text: `Got audit [${auditId}] for [${id}] in [${collection}]`,
|
|
18
|
-
});
|
|
19
|
-
spinner.stop();
|
|
20
|
-
localStorage.setItem("lastId", result._id);
|
|
21
|
-
return {
|
|
22
|
-
singleData: plainResult,
|
|
23
|
-
singleContent: content,
|
|
24
|
-
singleResult: result,
|
|
25
|
-
singleMeta: meta,
|
|
26
|
-
};
|
|
27
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import inquirer from "inquirer";
|
|
2
|
-
export async function promptAudits(result) {
|
|
3
|
-
const { audit } = await inquirer.prompt([
|
|
4
|
-
{
|
|
5
|
-
type: "list",
|
|
6
|
-
name: "audit",
|
|
7
|
-
message: "Choose a audit:",
|
|
8
|
-
choices: result.map((el) => ({
|
|
9
|
-
name: `${el.action} at ${el.ts} by ${el._userID.first_name} ${el._userID.last_name}`,
|
|
10
|
-
value: el._id,
|
|
11
|
-
})),
|
|
12
|
-
},
|
|
13
|
-
]);
|
|
14
|
-
return audit;
|
|
15
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import inquirer from "inquirer";
|
|
2
|
-
import { getCollections } from "../models/getCollections.js";
|
|
3
|
-
async function promptCollection() {
|
|
4
|
-
const { collection } = await inquirer.prompt([
|
|
5
|
-
{
|
|
6
|
-
type: "list",
|
|
7
|
-
name: "collection",
|
|
8
|
-
message: "Choose a collection:",
|
|
9
|
-
choices: getCollections(),
|
|
10
|
-
},
|
|
11
|
-
]);
|
|
12
|
-
return collection;
|
|
13
|
-
}
|