@tolinax/ayoune-cli 2026.3.0 → 2026.3.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.
Files changed (90) hide show
  1. package/package.json +160 -158
  2. package/data/defaultActions.js +0 -9
  3. package/data/modelsAndRights.js +0 -3189
  4. package/data/modules.js +0 -111
  5. package/data/operations.js +0 -5
  6. package/data/services.js +0 -139
  7. package/index.js +0 -11
  8. package/lib/api/apiCallHandler.js +0 -68
  9. package/lib/api/apiClient.js +0 -100
  10. package/lib/api/auditCallHandler.js +0 -21
  11. package/lib/api/decodeToken.js +0 -4
  12. package/lib/api/handleAPIError.js +0 -59
  13. package/lib/api/login.js +0 -45
  14. package/lib/commands/createActionsCommand.js +0 -109
  15. package/lib/commands/createAiCommand.js +0 -188
  16. package/lib/commands/createAliasCommand.js +0 -106
  17. package/lib/commands/createAuditCommand.js +0 -49
  18. package/lib/commands/createBatchCommand.js +0 -304
  19. package/lib/commands/createCompletionsCommand.js +0 -169
  20. package/lib/commands/createConfigCommand.js +0 -208
  21. package/lib/commands/createCopyCommand.js +0 -39
  22. package/lib/commands/createCreateCommand.js +0 -50
  23. package/lib/commands/createDeleteCommand.js +0 -98
  24. package/lib/commands/createDeployCommand.js +0 -666
  25. package/lib/commands/createDescribeCommand.js +0 -42
  26. package/lib/commands/createEditCommand.js +0 -43
  27. package/lib/commands/createEventsCommand.js +0 -60
  28. package/lib/commands/createExecCommand.js +0 -182
  29. package/lib/commands/createExportCommand.js +0 -219
  30. package/lib/commands/createGetCommand.js +0 -47
  31. package/lib/commands/createJobsCommand.js +0 -168
  32. package/lib/commands/createListCommand.js +0 -49
  33. package/lib/commands/createLoginCommand.js +0 -18
  34. package/lib/commands/createLogoutCommand.js +0 -21
  35. package/lib/commands/createModulesCommand.js +0 -150
  36. package/lib/commands/createMonitorCommand.js +0 -283
  37. package/lib/commands/createPermissionsCommand.js +0 -241
  38. package/lib/commands/createProgram.js +0 -185
  39. package/lib/commands/createSearchCommand.js +0 -101
  40. package/lib/commands/createServicesCommand.js +0 -228
  41. package/lib/commands/createStorageCommand.js +0 -54
  42. package/lib/commands/createStreamCommand.js +0 -50
  43. package/lib/commands/createSyncCommand.js +0 -177
  44. package/lib/commands/createTemplateCommand.js +0 -238
  45. package/lib/commands/createUpdateCommand.js +0 -115
  46. package/lib/commands/createUsersCommand.js +0 -285
  47. package/lib/commands/createWebhooksCommand.js +0 -156
  48. package/lib/commands/createWhoAmICommand.js +0 -88
  49. package/lib/exitCodes.js +0 -6
  50. package/lib/helpers/addSpacesToCamelCase.js +0 -5
  51. package/lib/helpers/config.js +0 -6
  52. package/lib/helpers/configLoader.js +0 -60
  53. package/lib/helpers/formatDocument.js +0 -176
  54. package/lib/helpers/handleResponseFormatOptions.js +0 -85
  55. package/lib/helpers/initializeSettings.js +0 -14
  56. package/lib/helpers/localStorage.js +0 -4
  57. package/lib/helpers/makeRandomToken.js +0 -27
  58. package/lib/helpers/parseInt.js +0 -7
  59. package/lib/helpers/requireArg.js +0 -9
  60. package/lib/helpers/saveFile.js +0 -39
  61. package/lib/models/getCollections.js +0 -15
  62. package/lib/models/getModelsInModules.js +0 -13
  63. package/lib/models/getModuleFromCollection.js +0 -7
  64. package/lib/operations/handleAuditOperation.js +0 -22
  65. package/lib/operations/handleCollectionOperation.js +0 -91
  66. package/lib/operations/handleCopySingleOperation.js +0 -22
  67. package/lib/operations/handleCreateSingleOperation.js +0 -35
  68. package/lib/operations/handleDeleteSingleOperation.js +0 -14
  69. package/lib/operations/handleDescribeSingleOperation.js +0 -22
  70. package/lib/operations/handleEditOperation.js +0 -51
  71. package/lib/operations/handleEditRawOperation.js +0 -35
  72. package/lib/operations/handleGetOperation.js +0 -29
  73. package/lib/operations/handleGetSingleOperation.js +0 -20
  74. package/lib/operations/handleListOperation.js +0 -63
  75. package/lib/operations/handleSingleAuditOperation.js +0 -27
  76. package/lib/prompts/promptAudits.js +0 -15
  77. package/lib/prompts/promptCollection.js +0 -13
  78. package/lib/prompts/promptCollectionInModule.js +0 -13
  79. package/lib/prompts/promptCollectionWithModule.js +0 -15
  80. package/lib/prompts/promptConfirm.js +0 -12
  81. package/lib/prompts/promptDefaultAction.js +0 -13
  82. package/lib/prompts/promptEntry.js +0 -19
  83. package/lib/prompts/promptFileName.js +0 -12
  84. package/lib/prompts/promptFilePath.js +0 -18
  85. package/lib/prompts/promptModule.js +0 -19
  86. package/lib/prompts/promptName.js +0 -11
  87. package/lib/prompts/promptOperation.js +0 -13
  88. package/lib/socket/customerSocketClient.js +0 -13
  89. package/lib/socket/socketClient.js +0 -12
  90. package/lib/types.js +0 -1
@@ -1,176 +0,0 @@
1
- import chalk from 'chalk';
2
- import moment from 'moment';
3
- import { addSpacesToCamelCase } from './addSpacesToCamelCase.js';
4
- const SKIP_FIELDS = new Set(['__v', 'password', 'hash', 'salt']);
5
- function isDateField(key, value) {
6
- if (typeof value === 'string' && /^\d{4}-\d{2}-\d{2}T/.test(value))
7
- return true;
8
- if (key.endsWith('At') || key.endsWith('Date'))
9
- return true;
10
- return false;
11
- }
12
- function formatDate(value) {
13
- const m = moment(value);
14
- if (!m.isValid())
15
- return String(value);
16
- const formatted = m.format('YYYY-MM-DD HH:mm:ss');
17
- const relative = m.fromNow();
18
- return `${formatted} ${chalk.dim(`(${relative})`)}`;
19
- }
20
- function formatValue(key, value) {
21
- if (value == null || value === '')
22
- return '';
23
- if (typeof value === 'boolean') {
24
- return value ? chalk.green('yes') : chalk.red('no');
25
- }
26
- if (isDateField(key, value)) {
27
- return formatDate(value);
28
- }
29
- if (typeof value === 'number') {
30
- return String(value);
31
- }
32
- if (Array.isArray(value)) {
33
- if (value.length === 0)
34
- return '';
35
- if (value.every((v) => typeof v !== 'object' || v === null)) {
36
- return value.join(', ');
37
- }
38
- return '';
39
- }
40
- if (typeof value === 'object')
41
- return '';
42
- const str = String(value);
43
- if ((key.endsWith('ID') || key.endsWith('Id') || key === '_id') && str.length > 10) {
44
- return chalk.dim(str);
45
- }
46
- return str;
47
- }
48
- function getEntryName(obj) {
49
- return (obj === null || obj === void 0 ? void 0 : obj.name) || (obj === null || obj === void 0 ? void 0 : obj.title) || (obj === null || obj === void 0 ? void 0 : obj.subject) || (obj === null || obj === void 0 ? void 0 : obj.originalname) || '';
50
- }
51
- function renderHeader(obj, ctx) {
52
- const name = getEntryName(obj);
53
- const contextParts = [];
54
- if (ctx.module)
55
- contextParts.push(ctx.module);
56
- if (ctx.collection)
57
- contextParts.push(ctx.collection);
58
- if (ctx.id)
59
- contextParts.push(ctx.id);
60
- const contextLine = contextParts.join(chalk.dim(' · '));
61
- const contentWidth = Math.max(name ? name.length : 0, contextLine ? contextParts.join(' · ').length : 0, 30);
62
- const boxWidth = contentWidth + 4;
63
- const lines = [];
64
- lines.push(chalk.dim(`╭${'─'.repeat(boxWidth)}╮`));
65
- if (name) {
66
- lines.push(chalk.dim('│') + ` ${chalk.bold.white(name)}${' '.repeat(boxWidth - name.length - 2)}` + chalk.dim('│'));
67
- }
68
- if (contextLine) {
69
- const plainLen = contextParts.join(' · ').length;
70
- lines.push(chalk.dim('│') + ` ${chalk.dim(contextLine)}${' '.repeat(boxWidth - plainLen - 2)}` + chalk.dim('│'));
71
- }
72
- lines.push(chalk.dim(`╰${'─'.repeat(boxWidth)}╯`));
73
- return lines.join('\n');
74
- }
75
- function collectFields(obj) {
76
- const flat = [];
77
- const nested = [];
78
- const arrayOfObjects = [];
79
- for (const [key, value] of Object.entries(obj)) {
80
- if (SKIP_FIELDS.has(key) || value == null || value === '')
81
- continue;
82
- if (Array.isArray(value)) {
83
- if (value.length === 0)
84
- continue;
85
- if (value.some((v) => typeof v === 'object' && v !== null)) {
86
- arrayOfObjects.push([key, value]);
87
- }
88
- else {
89
- flat.push([key, value]);
90
- }
91
- }
92
- else if (typeof value === 'object' && !isDateField(key, value)) {
93
- nested.push([key, value]);
94
- }
95
- else {
96
- flat.push([key, value]);
97
- }
98
- }
99
- return { flat, nested, arrayOfObjects };
100
- }
101
- function renderFields(fields, indent, labelWidth) {
102
- const pad = ' '.repeat(indent);
103
- const lines = [];
104
- for (const [key, value] of fields) {
105
- const formatted = formatValue(key, value);
106
- if (!formatted)
107
- continue;
108
- const label = addSpacesToCamelCase(key);
109
- lines.push(`${pad}${chalk.dim(label.padEnd(labelWidth))} ${chalk.white(formatted)}`);
110
- }
111
- return lines;
112
- }
113
- function getLabelWidth(fields) {
114
- if (fields.length === 0)
115
- return 16;
116
- return Math.max(...fields.map(([k]) => addSpacesToCamelCase(k).length)) + 2;
117
- }
118
- function renderSection(title, obj, indent) {
119
- const pad = ' '.repeat(indent);
120
- const lines = [];
121
- const { flat, nested, arrayOfObjects } = collectFields(obj);
122
- lines.push('');
123
- lines.push(`${pad}${chalk.dim('── ' + addSpacesToCamelCase(title) + ' ' + '─'.repeat(Math.max(0, 36 - title.length)))}`);
124
- const labelWidth = getLabelWidth(flat);
125
- lines.push(...renderFields(flat, indent + 2, labelWidth));
126
- for (const [key, value] of nested) {
127
- lines.push(...renderSection(key, value, indent + 2));
128
- }
129
- for (const [key, items] of arrayOfObjects) {
130
- lines.push('');
131
- lines.push(`${pad} ${chalk.dim('── ' + addSpacesToCamelCase(key) + ' ' + '─'.repeat(Math.max(0, 34 - key.length)))}`);
132
- items.forEach((item, i) => {
133
- if (typeof item === 'object' && item !== null) {
134
- lines.push(`${pad} ${chalk.dim(`[${i + 1}]`)}`);
135
- const itemFields = collectFields(item);
136
- const itemLabelWidth = getLabelWidth(itemFields.flat);
137
- lines.push(...renderFields(itemFields.flat, indent + 6, itemLabelWidth));
138
- }
139
- else {
140
- lines.push(`${pad} ${chalk.dim(`[${i + 1}]`)} ${String(item)}`);
141
- }
142
- });
143
- }
144
- return lines;
145
- }
146
- export function formatDocument(obj, ctx = {}) {
147
- if (!obj || typeof obj !== 'object')
148
- return String(obj !== null && obj !== void 0 ? obj : '');
149
- const lines = [];
150
- lines.push('');
151
- lines.push(renderHeader(obj, ctx));
152
- const { flat, nested, arrayOfObjects } = collectFields(obj);
153
- const labelWidth = getLabelWidth(flat);
154
- lines.push('');
155
- lines.push(...renderFields(flat, 2, labelWidth));
156
- for (const [key, value] of nested) {
157
- lines.push(...renderSection(key, value, 2));
158
- }
159
- for (const [key, items] of arrayOfObjects) {
160
- lines.push('');
161
- lines.push(` ${chalk.dim('── ' + addSpacesToCamelCase(key) + ' ' + '─'.repeat(Math.max(0, 36 - key.length)))}`);
162
- items.forEach((item, i) => {
163
- if (typeof item === 'object' && item !== null) {
164
- lines.push(` ${chalk.dim(`[${i + 1}]`)}`);
165
- const itemFields = collectFields(item);
166
- const itemLabelWidth = getLabelWidth(itemFields.flat);
167
- lines.push(...renderFields(itemFields.flat, 6, itemLabelWidth));
168
- }
169
- else {
170
- lines.push(` ${chalk.dim(`[${i + 1}]`)} ${String(item)}`);
171
- }
172
- });
173
- }
174
- lines.push('');
175
- return lines.join('\n');
176
- }
@@ -1,85 +0,0 @@
1
- import yaml from "js-yaml";
2
- import jmespath from "jmespath";
3
- function filterColumns(data, columns) {
4
- const fields = columns.split(",").map((c) => c.trim());
5
- if (Array.isArray(data)) {
6
- return data.map((item) => {
7
- const filtered = {};
8
- for (const f of fields) {
9
- if (item[f] !== undefined)
10
- filtered[f] = item[f];
11
- }
12
- return filtered;
13
- });
14
- }
15
- if (typeof data === "object" && data !== null) {
16
- const filtered = {};
17
- for (const f of fields) {
18
- if (data[f] !== undefined)
19
- filtered[f] = data[f];
20
- }
21
- return filtered;
22
- }
23
- return data;
24
- }
25
- export function handleResponseFormatOptions(opts, res) {
26
- let plainResult;
27
- let result;
28
- let meta = {};
29
- let content;
30
- if (opts.responseFormat && opts.responseFormat === "yaml") {
31
- plainResult = yaml.load(res);
32
- result = plainResult.payload;
33
- meta = plainResult.meta;
34
- }
35
- if (opts.responseFormat && opts.responseFormat === "csv") {
36
- plainResult = res;
37
- result = res.payload;
38
- meta = res.meta;
39
- }
40
- if (opts.responseFormat && opts.responseFormat === "table") {
41
- plainResult = res;
42
- result = res.payload;
43
- meta = res.meta;
44
- }
45
- if (opts.responseFormat && opts.responseFormat === "json") {
46
- plainResult = res;
47
- result = res.payload;
48
- meta = res.meta;
49
- }
50
- // Apply --columns filter
51
- if (opts.columns && result) {
52
- result = filterColumns(result, opts.columns);
53
- }
54
- // Apply --jq (JMESPath) filter
55
- if (opts.jq && result) {
56
- try {
57
- result = jmespath.search(result, opts.jq);
58
- }
59
- catch (e) {
60
- console.error(`JMESPath error: ${e.message}`);
61
- }
62
- }
63
- // Generate content string after filtering
64
- if (opts.responseFormat === "yaml") {
65
- content = yaml.dump(result);
66
- }
67
- else if (opts.responseFormat === "csv") {
68
- content = result;
69
- }
70
- else if (opts.responseFormat === "table") {
71
- content = result;
72
- }
73
- else {
74
- content = JSON.stringify(result, null, 4);
75
- }
76
- if (!opts.quiet) {
77
- if (opts.responseFormat === "table") {
78
- console.table(result);
79
- }
80
- else if (content !== undefined) {
81
- console.log(content);
82
- }
83
- }
84
- return { plainResult, result, meta, content };
85
- }
@@ -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,4 +0,0 @@
1
- import { LocalStorage } from "node-localstorage";
2
- import path from "path";
3
- import os from "os";
4
- export const localStorage = new LocalStorage(path.join(os.homedir(), "aYOUne", "storage"));
@@ -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
- };
@@ -1,7 +0,0 @@
1
- export function parseInteger(value, dummyPrevious) {
2
- const parsedValue = parseInt(value, 10);
3
- if (isNaN(parsedValue)) {
4
- throw new Error("Not a number.");
5
- }
6
- return parsedValue;
7
- }
@@ -1,9 +0,0 @@
1
- import { spinner } from "../../index.js";
2
- export function requireArg(value, name) {
3
- if (value)
4
- return true;
5
- if (process.stdin.isTTY)
6
- return false; // allow prompt to run
7
- spinner.error({ text: `Missing required argument: ${name}` });
8
- process.exit(1);
9
- }
@@ -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,91 +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 { 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
- }
@@ -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,35 +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
- 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
- }
@@ -1,14 +0,0 @@
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
- }
@@ -1,22 +0,0 @@
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
- }
@@ -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
- }