@tolinax/ayoune-cli 2024.2.1
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/defaultActions.js +9 -0
- package/data/operations.js +5 -0
- package/index.js +34 -0
- package/lib/api/apiCallHandler.js +42 -0
- package/lib/api/apiClient.js +16 -0
- package/lib/api/auditCallHandler.js +42 -0
- package/lib/api/handleAPIError.js +0 -0
- package/lib/api/login.js +33 -0
- package/lib/commands/createAuditCommand.js +28 -0
- package/lib/commands/createCopyCommand.js +24 -0
- package/lib/commands/createCreateCommand.js +29 -0
- package/lib/commands/createDescribeCommand.js +24 -0
- package/lib/commands/createEditCommand.js +25 -0
- package/lib/commands/createEventsCommand.js +54 -0
- package/lib/commands/createGetCommand.js +36 -0
- package/lib/commands/createListCommand.js +35 -0
- package/lib/commands/createLoginCommand.js +17 -0
- package/lib/commands/createModulesCommand.js +33 -0
- package/lib/commands/createProgram.js +63 -0
- package/lib/commands/createStorageCommand.js +16 -0
- package/lib/commands/createStreamCommand.js +45 -0
- package/lib/helpers/addSpacesToCamelCase.js +5 -0
- package/lib/helpers/handleResponseFormatOptions.js +43 -0
- package/lib/helpers/initializeSettings.js +14 -0
- package/lib/helpers/localStorage.js +4 -0
- package/lib/helpers/parseInt.js +9 -0
- package/lib/helpers/saveFile.js +39 -0
- package/lib/models/getCollections.js +15 -0
- package/lib/models/getModelsInModules.js +13 -0
- package/lib/models/getModuleFromCollection.js +7 -0
- package/lib/operations/handleAuditOperation.js +22 -0
- package/lib/operations/handleCollectionOperation.js +27 -0
- package/lib/operations/handleCopySingleOperation.js +22 -0
- package/lib/operations/handleCreateSingleOperation.js +27 -0
- package/lib/operations/handleDescribeSingleOperation.js +20 -0
- package/lib/operations/handleEditOperation.js +51 -0
- package/lib/operations/handleEditRawOperation.js +35 -0
- package/lib/operations/handleGetOperation.js +25 -0
- package/lib/operations/handleGetSingleOperation.js +20 -0
- package/lib/operations/handleListOperation.js +24 -0
- package/lib/operations/handleSingleAuditOperation.js +27 -0
- package/lib/prompts/promptAudits.js +15 -0
- package/lib/prompts/promptCollection.js +13 -0
- package/lib/prompts/promptCollectionInModule.js +13 -0
- package/lib/prompts/promptCollectionWithModule.js +15 -0
- package/lib/prompts/promptDefaultAction.js +13 -0
- package/lib/prompts/promptEntry.js +12 -0
- package/lib/prompts/promptModule.js +19 -0
- package/lib/prompts/promptName.js +11 -0
- package/lib/prompts/promptOperation.js +13 -0
- package/lib/socket/customerSocketClient.js +12 -0
- package/lib/socket/socketClient.js +11 -0
- package/package.json +147 -0
|
@@ -0,0 +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
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { modelsAndRights } from "@tolinax/ayoune-models/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 };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import _ from "lodash";
|
|
2
|
+
import { addSpacesToCamelCase } from "../helpers/addSpacesToCamelCase.js";
|
|
3
|
+
import { modelsAndRights } from "@tolinax/ayoune-models/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 };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import _ from "lodash";
|
|
2
|
+
import { modelsAndRights } from "@tolinax/ayoune-models/data/modelsAndRights.js";
|
|
3
|
+
const getModuleFromCollection = (collection) => {
|
|
4
|
+
const m = _.find(modelsAndRights, (el) => el.plural.toLowerCase() === collection);
|
|
5
|
+
return m;
|
|
6
|
+
};
|
|
7
|
+
export { getModuleFromCollection };
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +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
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import inquirer from "inquirer";
|
|
2
|
+
import { getModelsInModules } from "../models/getModelsInModules.js";
|
|
3
|
+
export async function promptCollectionInModule(module) {
|
|
4
|
+
const { collection } = await inquirer.prompt([
|
|
5
|
+
{
|
|
6
|
+
type: "list",
|
|
7
|
+
name: "collection",
|
|
8
|
+
message: "Choose a collection:",
|
|
9
|
+
choices: getModelsInModules(module),
|
|
10
|
+
},
|
|
11
|
+
]);
|
|
12
|
+
return collection;
|
|
13
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { promptModule } from "./promptModule.js";
|
|
2
|
+
import inquirer from "inquirer";
|
|
3
|
+
import { getModelsInModules } from "../models/getModelsInModules.js";
|
|
4
|
+
export async function promptCollectionWithModule() {
|
|
5
|
+
const module = await promptModule();
|
|
6
|
+
const { collection } = await inquirer.prompt([
|
|
7
|
+
{
|
|
8
|
+
type: "list",
|
|
9
|
+
name: "collection",
|
|
10
|
+
message: "Choose a collection:",
|
|
11
|
+
choices: getModelsInModules(module),
|
|
12
|
+
},
|
|
13
|
+
]);
|
|
14
|
+
return collection;
|
|
15
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import inquirer from "inquirer";
|
|
2
|
+
import { defaultActions } from "../../data/defaultActions.js";
|
|
3
|
+
export async function promptDefaultAction() {
|
|
4
|
+
const { action } = await inquirer.prompt([
|
|
5
|
+
{
|
|
6
|
+
type: "list",
|
|
7
|
+
name: "action",
|
|
8
|
+
message: "Choose a action:",
|
|
9
|
+
choices: defaultActions,
|
|
10
|
+
},
|
|
11
|
+
]);
|
|
12
|
+
return action;
|
|
13
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import inquirer from "inquirer";
|
|
2
|
+
export async function promptEntry(result) {
|
|
3
|
+
const { entry } = await inquirer.prompt([
|
|
4
|
+
{
|
|
5
|
+
type: "list",
|
|
6
|
+
name: "entry",
|
|
7
|
+
message: "Choose a entry:",
|
|
8
|
+
choices: result.map((el) => ({ name: el.label, value: el._id })),
|
|
9
|
+
},
|
|
10
|
+
]);
|
|
11
|
+
return entry;
|
|
12
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Prompt functions
|
|
2
|
+
import inquirer from "inquirer";
|
|
3
|
+
import { aYOUneModules } from "@tolinax/ayoune-models/data/modules.js";
|
|
4
|
+
export async function promptModule() {
|
|
5
|
+
const { module } = await inquirer.prompt([
|
|
6
|
+
{
|
|
7
|
+
type: "list",
|
|
8
|
+
name: "module",
|
|
9
|
+
message: "Choose a module:",
|
|
10
|
+
choices: aYOUneModules.map((el) => {
|
|
11
|
+
return {
|
|
12
|
+
name: el.label,
|
|
13
|
+
value: el.module,
|
|
14
|
+
};
|
|
15
|
+
}),
|
|
16
|
+
},
|
|
17
|
+
]);
|
|
18
|
+
return module;
|
|
19
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import inquirer from "inquirer";
|
|
2
|
+
import { operations } from "../../data/operations.js";
|
|
3
|
+
export async function promptOperation() {
|
|
4
|
+
const { operation } = await inquirer.prompt([
|
|
5
|
+
{
|
|
6
|
+
type: "list",
|
|
7
|
+
name: "operation",
|
|
8
|
+
message: "Choose a operation:",
|
|
9
|
+
choices: operations,
|
|
10
|
+
},
|
|
11
|
+
]);
|
|
12
|
+
return operation;
|
|
13
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { io } from "socket.io-client";
|
|
2
|
+
export const customerSocket = (user) => {
|
|
3
|
+
return io(`https://notifier.ayoune.app`, {
|
|
4
|
+
transports: ["websocket"],
|
|
5
|
+
autoConnect: true,
|
|
6
|
+
reconnection: true,
|
|
7
|
+
query: {
|
|
8
|
+
customer: user._customerID,
|
|
9
|
+
username: user._id,
|
|
10
|
+
},
|
|
11
|
+
});
|
|
12
|
+
};
|