@tolinax/ayoune-cli 2026.2.0 → 2026.2.2
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/modelsAndRights.js +3189 -0
- package/data/modules.js +111 -0
- package/data/operations.js +5 -0
- package/data/services.js +139 -0
- package/index.js +11 -0
- package/lib/api/apiCallHandler.js +68 -0
- package/lib/api/apiClient.js +100 -0
- package/lib/api/auditCallHandler.js +21 -0
- package/lib/api/decodeToken.js +4 -0
- package/lib/api/handleAPIError.js +59 -0
- package/lib/api/login.js +45 -0
- package/lib/commands/createActionsCommand.js +109 -0
- package/lib/commands/createAiCommand.js +188 -0
- package/lib/commands/createAliasCommand.js +106 -0
- package/lib/commands/createAuditCommand.js +49 -0
- package/lib/commands/createCompletionsCommand.js +136 -0
- package/lib/commands/createConfigCommand.js +208 -0
- package/lib/commands/createCopyCommand.js +39 -0
- package/lib/commands/createCreateCommand.js +50 -0
- package/lib/commands/createDeployCommand.js +666 -0
- package/lib/commands/createDescribeCommand.js +42 -0
- package/lib/commands/createEditCommand.js +43 -0
- package/lib/commands/createEventsCommand.js +60 -0
- package/lib/commands/createExecCommand.js +182 -0
- package/lib/commands/createGetCommand.js +47 -0
- package/lib/commands/createListCommand.js +49 -0
- package/lib/commands/createLoginCommand.js +18 -0
- package/lib/commands/createLogoutCommand.js +21 -0
- package/lib/commands/createModulesCommand.js +89 -0
- package/lib/commands/createMonitorCommand.js +283 -0
- package/lib/commands/createProgram.js +163 -0
- package/lib/commands/createServicesCommand.js +228 -0
- package/lib/commands/createStorageCommand.js +54 -0
- package/lib/commands/createStreamCommand.js +50 -0
- package/lib/commands/createWhoAmICommand.js +88 -0
- package/lib/exitCodes.js +6 -0
- package/lib/helpers/addSpacesToCamelCase.js +5 -0
- package/lib/helpers/config.js +6 -0
- package/lib/helpers/configLoader.js +60 -0
- package/lib/helpers/formatDocument.js +176 -0
- package/lib/helpers/handleResponseFormatOptions.js +85 -0
- package/lib/helpers/initializeSettings.js +14 -0
- package/lib/helpers/localStorage.js +4 -0
- package/lib/helpers/makeRandomToken.js +27 -0
- package/lib/helpers/parseInt.js +7 -0
- package/lib/helpers/requireArg.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 +91 -0
- package/lib/operations/handleCopySingleOperation.js +22 -0
- package/lib/operations/handleCreateSingleOperation.js +35 -0
- package/lib/operations/handleDeleteSingleOperation.js +14 -0
- package/lib/operations/handleDescribeSingleOperation.js +22 -0
- package/lib/operations/handleEditOperation.js +51 -0
- package/lib/operations/handleEditRawOperation.js +35 -0
- package/lib/operations/handleGetOperation.js +29 -0
- package/lib/operations/handleGetSingleOperation.js +20 -0
- package/lib/operations/handleListOperation.js +63 -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/promptConfirm.js +12 -0
- package/lib/prompts/promptDefaultAction.js +13 -0
- package/lib/prompts/promptEntry.js +19 -0
- package/lib/prompts/promptFileName.js +12 -0
- package/lib/prompts/promptFilePath.js +18 -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 +13 -0
- package/lib/socket/socketClient.js +12 -0
- package/lib/types.js +1 -0
- package/package.json +2 -2
- package/README.md +0 -505
|
@@ -0,0 +1,7 @@
|
|
|
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 };
|
|
@@ -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,91 @@
|
|
|
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 { handleDeleteSingleOperation } from "./handleDeleteSingleOperation.js";
|
|
6
|
+
import { spinner } from "../../index.js";
|
|
7
|
+
import { promptDefaultAction } from "../prompts/promptDefaultAction.js";
|
|
8
|
+
import { promptConfirm } from "../prompts/promptConfirm.js";
|
|
9
|
+
import yaml from "js-yaml";
|
|
10
|
+
import { formatDocument } from "../helpers/formatDocument.js";
|
|
11
|
+
import { promptFilePath } from "../prompts/promptFilePath.js";
|
|
12
|
+
import { promptFileName } from "../prompts/promptFileName.js";
|
|
13
|
+
import path from "path";
|
|
14
|
+
import { writeFile } from "fs/promises";
|
|
15
|
+
import { mkdirp } from "mkdirp";
|
|
16
|
+
function getEntryName(res) {
|
|
17
|
+
const p = res === null || res === void 0 ? void 0 : res.payload;
|
|
18
|
+
if (!p || typeof p === "string")
|
|
19
|
+
return "";
|
|
20
|
+
return p.name || p.title || p.subject || p.originalname || p._id || "";
|
|
21
|
+
}
|
|
22
|
+
function successText(action, res) {
|
|
23
|
+
var _a;
|
|
24
|
+
const name = getEntryName(res);
|
|
25
|
+
const time = (_a = res === null || res === void 0 ? void 0 : res.meta) === null || _a === void 0 ? void 0 : _a.responseTime;
|
|
26
|
+
const parts = [action];
|
|
27
|
+
if (name)
|
|
28
|
+
parts.push(`[${name}]`);
|
|
29
|
+
if (time)
|
|
30
|
+
parts.push(`- ${time}ms`);
|
|
31
|
+
return parts.join(" ");
|
|
32
|
+
}
|
|
33
|
+
export async function handleCollectionOperation(module, collection, entry, opts) {
|
|
34
|
+
const action = await promptDefaultAction();
|
|
35
|
+
const entryPath = `${collection.toLowerCase()}/${entry}`;
|
|
36
|
+
spinner.start({ text: `Processing ${action}...`, color: "magenta" });
|
|
37
|
+
let res;
|
|
38
|
+
let editContent;
|
|
39
|
+
switch (action) {
|
|
40
|
+
case "edit":
|
|
41
|
+
res = await apiCallHandler(module, entryPath, "get", null, { responseFormat: "table" });
|
|
42
|
+
spinner.success({ text: successText("Got entry", res) });
|
|
43
|
+
spinner.stop();
|
|
44
|
+
editContent = res.payload;
|
|
45
|
+
await handleEditOperation(module, collection, editContent);
|
|
46
|
+
break;
|
|
47
|
+
case "edit raw":
|
|
48
|
+
res = await apiCallHandler(module, entryPath, "get", null, { responseFormat: opts.responseFormat });
|
|
49
|
+
spinner.success({ text: successText("Got entry", res) });
|
|
50
|
+
spinner.stop();
|
|
51
|
+
editContent = res.payload;
|
|
52
|
+
await handleEditRawOperation(module, collection, editContent);
|
|
53
|
+
break;
|
|
54
|
+
case "describe":
|
|
55
|
+
res = await apiCallHandler(module, entryPath, "get", null, {});
|
|
56
|
+
spinner.success({ text: successText("Described", res) });
|
|
57
|
+
spinner.stop();
|
|
58
|
+
editContent = res.payload;
|
|
59
|
+
if (!opts.quiet) {
|
|
60
|
+
console.log(formatDocument(editContent, { module, collection, id: entry }));
|
|
61
|
+
}
|
|
62
|
+
break;
|
|
63
|
+
case "download":
|
|
64
|
+
res = await apiCallHandler(module, entryPath, "get", null, { responseFormat: opts.responseFormat });
|
|
65
|
+
spinner.success({ text: successText("Downloaded", res) });
|
|
66
|
+
spinner.stop();
|
|
67
|
+
editContent = res.payload;
|
|
68
|
+
const folder = await promptFilePath(collection);
|
|
69
|
+
await mkdirp(folder);
|
|
70
|
+
const fileName = await promptFileName(`${collection}_${editContent._id || entry}.${opts.responseFormat}`);
|
|
71
|
+
const contentToWrite = opts.responseFormat === "yaml"
|
|
72
|
+
? (typeof editContent === "string" ? editContent : yaml.dump(editContent))
|
|
73
|
+
: opts.responseFormat === "csv"
|
|
74
|
+
? editContent
|
|
75
|
+
: JSON.stringify(editContent, null, 4);
|
|
76
|
+
await writeFile(path.join(folder, fileName), contentToWrite, {
|
|
77
|
+
encoding: "utf8",
|
|
78
|
+
});
|
|
79
|
+
break;
|
|
80
|
+
case "delete":
|
|
81
|
+
spinner.stop();
|
|
82
|
+
const shouldDelete = opts.force || await promptConfirm(`Delete entry ${entry} in ${collection}?`);
|
|
83
|
+
if (shouldDelete) {
|
|
84
|
+
await handleDeleteSingleOperation(module, collection, entry, opts);
|
|
85
|
+
}
|
|
86
|
+
break;
|
|
87
|
+
default:
|
|
88
|
+
spinner.stop();
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -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,35 @@
|
|
|
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
|
+
var _a;
|
|
8
|
+
spinner.start({
|
|
9
|
+
text: `Creating entry in [${collection}]`,
|
|
10
|
+
color: "magenta",
|
|
11
|
+
});
|
|
12
|
+
let res = await apiCallHandler(module, collection.toLowerCase(), "post", {
|
|
13
|
+
name,
|
|
14
|
+
title: name,
|
|
15
|
+
subject: name,
|
|
16
|
+
summary: name,
|
|
17
|
+
}, {
|
|
18
|
+
responseFormat: opts.responseFormat,
|
|
19
|
+
verbosity: opts.verbosity,
|
|
20
|
+
});
|
|
21
|
+
// Dry-run returns { payload: null } — handle gracefully
|
|
22
|
+
if (!res || res.payload === null) {
|
|
23
|
+
spinner.stop();
|
|
24
|
+
return { data: null, content: null, result: null, meta: (_a = res === null || res === void 0 ? void 0 : res.meta) !== null && _a !== void 0 ? _a : {} };
|
|
25
|
+
}
|
|
26
|
+
let { plainResult, result, meta, content } = handleResponseFormatOptions({ ...opts }, res);
|
|
27
|
+
spinner.success({
|
|
28
|
+
text: `Created entry [${result === null || result === void 0 ? void 0 : result._id}] in ${collection}`,
|
|
29
|
+
});
|
|
30
|
+
spinner.stop();
|
|
31
|
+
if (result === null || result === void 0 ? void 0 : result._id) {
|
|
32
|
+
localStorage.setItem("lastId", result._id);
|
|
33
|
+
}
|
|
34
|
+
return { data: plainResult, content, result, meta };
|
|
35
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { apiCallHandler } from "../api/apiCallHandler.js";
|
|
2
|
+
import { spinner } from "../../index.js";
|
|
3
|
+
export async function handleDeleteSingleOperation(module, collection, id, opts) {
|
|
4
|
+
spinner.start({
|
|
5
|
+
text: `Deleting entry ${id} in [${collection}]`,
|
|
6
|
+
color: "magenta",
|
|
7
|
+
});
|
|
8
|
+
await apiCallHandler(module, `${collection.toLowerCase()}/${id}`, "delete", null, {
|
|
9
|
+
responseFormat: opts === null || opts === void 0 ? void 0 : opts.responseFormat,
|
|
10
|
+
verbosity: opts === null || opts === void 0 ? void 0 : opts.verbosity,
|
|
11
|
+
});
|
|
12
|
+
spinner.success({ text: `Deleted entry ${id} in ${collection}` });
|
|
13
|
+
spinner.stop();
|
|
14
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Operation handling functions
|
|
2
|
+
import { apiCallHandler } from "../api/apiCallHandler.js";
|
|
3
|
+
import { spinner } from "../../index.js";
|
|
4
|
+
import { formatDocument } from "../helpers/formatDocument.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
|
+
verbosity: opts.verbosity,
|
|
12
|
+
});
|
|
13
|
+
spinner.success({
|
|
14
|
+
text: `Got entry in ${collection}`,
|
|
15
|
+
});
|
|
16
|
+
spinner.stop();
|
|
17
|
+
const payload = res === null || res === void 0 ? void 0 : res.payload;
|
|
18
|
+
if (!opts.quiet) {
|
|
19
|
+
console.log(formatDocument(payload, { module, collection, id }));
|
|
20
|
+
}
|
|
21
|
+
return { data: res, content: payload, result: payload, meta: res === null || res === void 0 ? void 0 : res.meta };
|
|
22
|
+
}
|
|
@@ -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,29 @@
|
|
|
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
|
+
var _a, _b, _c, _d, _e, _f;
|
|
7
|
+
spinner.start({
|
|
8
|
+
text: `Getting entries in [${collection}]`,
|
|
9
|
+
color: "magenta",
|
|
10
|
+
});
|
|
11
|
+
let res = await apiCallHandler(module, collection.toLowerCase(), "get", null, {
|
|
12
|
+
page: opts.page,
|
|
13
|
+
responseFormat: opts.responseFormat,
|
|
14
|
+
limit: opts.limit,
|
|
15
|
+
from: opts.from,
|
|
16
|
+
fields: opts.fields,
|
|
17
|
+
hideMeta: opts.hideMeta,
|
|
18
|
+
verbosity: opts.verbosity,
|
|
19
|
+
});
|
|
20
|
+
let { plainResult, result, meta, content } = handleResponseFormatOptions(opts, res);
|
|
21
|
+
const totalEntries = (_b = (_a = meta === null || meta === void 0 ? void 0 : meta.pageInfo) === null || _a === void 0 ? void 0 : _a.totalEntries) !== null && _b !== void 0 ? _b : '?';
|
|
22
|
+
const page = (_d = (_c = meta === null || meta === void 0 ? void 0 : meta.pageInfo) === null || _c === void 0 ? void 0 : _c.page) !== null && _d !== void 0 ? _d : 1;
|
|
23
|
+
const totalPages = (_f = (_e = meta === null || meta === void 0 ? void 0 : meta.pageInfo) === null || _e === void 0 ? void 0 : _e.totalPages) !== null && _f !== void 0 ? _f : '?';
|
|
24
|
+
spinner.success({
|
|
25
|
+
text: `Got ${opts.limit} entries of ${totalEntries} : Page ${page} of ${totalPages}`,
|
|
26
|
+
});
|
|
27
|
+
spinner.stop();
|
|
28
|
+
return { data: plainResult, content, result, meta };
|
|
29
|
+
}
|
|
@@ -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,63 @@
|
|
|
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
|
+
async function fetchPage(module, collection, opts) {
|
|
6
|
+
return apiCallHandler(module, collection.toLowerCase(), "get", null, {
|
|
7
|
+
page: opts.page,
|
|
8
|
+
responseFormat: opts.responseFormat,
|
|
9
|
+
limit: opts.limit,
|
|
10
|
+
from: opts.from,
|
|
11
|
+
hideMeta: opts.hideMeta,
|
|
12
|
+
verbosity: opts.verbosity,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
export async function handleListOperation(module, collection, opts) {
|
|
16
|
+
var _a, _b, _c, _d;
|
|
17
|
+
spinner.start({
|
|
18
|
+
text: `Listing entries in [${collection}]`,
|
|
19
|
+
color: "magenta",
|
|
20
|
+
});
|
|
21
|
+
if (opts.all) {
|
|
22
|
+
// Auto-pagination: fetch all pages
|
|
23
|
+
let allPayload = [];
|
|
24
|
+
let page = 1;
|
|
25
|
+
let totalPages = 1;
|
|
26
|
+
let meta = {};
|
|
27
|
+
do {
|
|
28
|
+
const pageOpts = { ...opts, page };
|
|
29
|
+
const res = await fetchPage(module, collection, pageOpts);
|
|
30
|
+
const payload = res.payload;
|
|
31
|
+
meta = res.meta;
|
|
32
|
+
totalPages = (_b = (_a = meta.pageInfo) === null || _a === void 0 ? void 0 : _a.totalPages) !== null && _b !== void 0 ? _b : 1;
|
|
33
|
+
if (Array.isArray(payload)) {
|
|
34
|
+
allPayload = allPayload.concat(payload);
|
|
35
|
+
}
|
|
36
|
+
spinner.update({
|
|
37
|
+
text: `Fetching page ${page} of ${totalPages} (${allPayload.length} entries)`,
|
|
38
|
+
});
|
|
39
|
+
page++;
|
|
40
|
+
} while (page <= totalPages);
|
|
41
|
+
// Build a synthetic response with all data
|
|
42
|
+
const syntheticRes = {
|
|
43
|
+
payload: allPayload,
|
|
44
|
+
meta: { ...meta, pageInfo: { ...meta.pageInfo, page: 1, totalPages: 1, totalEntries: allPayload.length } },
|
|
45
|
+
};
|
|
46
|
+
const { plainResult, result, content } = handleResponseFormatOptions(opts, syntheticRes);
|
|
47
|
+
spinner.success({ text: `Got all ${allPayload.length} entries from ${totalPages} pages` });
|
|
48
|
+
spinner.stop();
|
|
49
|
+
return { data: plainResult, content, result, meta: syntheticRes.meta };
|
|
50
|
+
}
|
|
51
|
+
// Single page fetch
|
|
52
|
+
let res = await fetchPage(module, collection, opts);
|
|
53
|
+
let { plainResult, result, meta, content } = handleResponseFormatOptions(opts, res);
|
|
54
|
+
const total = (_d = (_c = meta.pageInfo) === null || _c === void 0 ? void 0 : _c.totalEntries) !== null && _d !== void 0 ? _d : 0;
|
|
55
|
+
const count = Array.isArray(result) ? result.length : total;
|
|
56
|
+
spinner.success({
|
|
57
|
+
text: total > 0
|
|
58
|
+
? `Got ${count} of ${total} entries : Page ${meta.pageInfo.page} of ${meta.pageInfo.totalPages}`
|
|
59
|
+
: `No entries found in [${collection}]`,
|
|
60
|
+
});
|
|
61
|
+
spinner.stop();
|
|
62
|
+
return { data: plainResult, content, result, meta };
|
|
63
|
+
}
|
|
@@ -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 an audit entry:",
|
|
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: "Select 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: "Select 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: "Select 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 an action:",
|
|
9
|
+
choices: defaultActions,
|
|
10
|
+
},
|
|
11
|
+
]);
|
|
12
|
+
return action;
|
|
13
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import inquirer from "inquirer";
|
|
2
|
+
function getEntryLabel(el) {
|
|
3
|
+
const name = el.name || el.title || el.subject || el.label || el.originalname || el.summary;
|
|
4
|
+
if (name) {
|
|
5
|
+
return `${name} (${el._id})`;
|
|
6
|
+
}
|
|
7
|
+
return el._id;
|
|
8
|
+
}
|
|
9
|
+
export async function promptEntry(result) {
|
|
10
|
+
const { entry } = await inquirer.prompt([
|
|
11
|
+
{
|
|
12
|
+
type: "search-list",
|
|
13
|
+
name: "entry",
|
|
14
|
+
message: "Choose an entry:",
|
|
15
|
+
choices: result.map((el) => ({ name: getEntryLabel(el), value: el._id })),
|
|
16
|
+
},
|
|
17
|
+
]);
|
|
18
|
+
return entry;
|
|
19
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import inquirer from "inquirer";
|
|
2
|
+
import os from "os";
|
|
3
|
+
import path from "path";
|
|
4
|
+
export async function promptFilePath(fp) {
|
|
5
|
+
const { filePath } = await inquirer.prompt([
|
|
6
|
+
{
|
|
7
|
+
type: "fuzzypath",
|
|
8
|
+
name: "filePath",
|
|
9
|
+
message: "Select a target directory:",
|
|
10
|
+
itemType: "directory",
|
|
11
|
+
default: fp,
|
|
12
|
+
rootPath: path.join(os.homedir(), "aYOUne"),
|
|
13
|
+
suggestOnly: false,
|
|
14
|
+
depthLimit: 8,
|
|
15
|
+
},
|
|
16
|
+
]);
|
|
17
|
+
return filePath;
|
|
18
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Prompt functions
|
|
2
|
+
import inquirer from "inquirer";
|
|
3
|
+
import { aYOUneModules } from "../../data/modules.js";
|
|
4
|
+
export async function promptModule() {
|
|
5
|
+
const { module } = await inquirer.prompt([
|
|
6
|
+
{
|
|
7
|
+
type: "list",
|
|
8
|
+
name: "module",
|
|
9
|
+
message: "Select a business 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 an operation:",
|
|
9
|
+
choices: operations,
|
|
10
|
+
},
|
|
11
|
+
]);
|
|
12
|
+
return operation;
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { io } from "socket.io-client";
|
|
2
|
+
import { config } from "../helpers/config.js";
|
|
3
|
+
export const customerSocket = (user) => {
|
|
4
|
+
return io(config.notifierUrl, {
|
|
5
|
+
autoConnect: true,
|
|
6
|
+
reconnection: true,
|
|
7
|
+
rejectUnauthorized: false,
|
|
8
|
+
query: {
|
|
9
|
+
customer: user._customerID,
|
|
10
|
+
username: user._id,
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
};
|