@tolinax/ayoune-cli 2026.2.4 → 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.
- package/package.json +160 -158
- package/data/defaultActions.js +0 -9
- package/data/modelsAndRights.js +0 -3189
- package/data/modules.js +0 -111
- package/data/operations.js +0 -5
- package/data/services.js +0 -139
- package/index.js +0 -11
- package/lib/api/apiCallHandler.js +0 -68
- package/lib/api/apiClient.js +0 -100
- package/lib/api/auditCallHandler.js +0 -21
- package/lib/api/decodeToken.js +0 -4
- package/lib/api/handleAPIError.js +0 -59
- package/lib/api/login.js +0 -45
- package/lib/commands/createActionsCommand.js +0 -109
- package/lib/commands/createAiCommand.js +0 -188
- package/lib/commands/createAliasCommand.js +0 -106
- package/lib/commands/createAuditCommand.js +0 -49
- package/lib/commands/createBatchCommand.js +0 -304
- package/lib/commands/createCompletionsCommand.js +0 -169
- package/lib/commands/createConfigCommand.js +0 -208
- package/lib/commands/createCopyCommand.js +0 -39
- package/lib/commands/createCreateCommand.js +0 -50
- package/lib/commands/createDeleteCommand.js +0 -98
- package/lib/commands/createDeployCommand.js +0 -666
- package/lib/commands/createDescribeCommand.js +0 -42
- package/lib/commands/createEditCommand.js +0 -43
- package/lib/commands/createEventsCommand.js +0 -60
- package/lib/commands/createExecCommand.js +0 -182
- package/lib/commands/createExportCommand.js +0 -219
- package/lib/commands/createGetCommand.js +0 -47
- package/lib/commands/createJobsCommand.js +0 -168
- package/lib/commands/createListCommand.js +0 -49
- package/lib/commands/createLoginCommand.js +0 -18
- package/lib/commands/createLogoutCommand.js +0 -21
- package/lib/commands/createModulesCommand.js +0 -89
- package/lib/commands/createMonitorCommand.js +0 -283
- package/lib/commands/createPermissionsCommand.js +0 -241
- package/lib/commands/createProgram.js +0 -185
- package/lib/commands/createSearchCommand.js +0 -101
- package/lib/commands/createServicesCommand.js +0 -228
- package/lib/commands/createStorageCommand.js +0 -54
- package/lib/commands/createStreamCommand.js +0 -50
- package/lib/commands/createSyncCommand.js +0 -177
- package/lib/commands/createTemplateCommand.js +0 -238
- package/lib/commands/createUpdateCommand.js +0 -115
- package/lib/commands/createUsersCommand.js +0 -285
- package/lib/commands/createWebhooksCommand.js +0 -156
- package/lib/commands/createWhoAmICommand.js +0 -88
- package/lib/exitCodes.js +0 -6
- package/lib/helpers/addSpacesToCamelCase.js +0 -5
- package/lib/helpers/config.js +0 -6
- package/lib/helpers/configLoader.js +0 -60
- package/lib/helpers/formatDocument.js +0 -176
- package/lib/helpers/handleResponseFormatOptions.js +0 -85
- 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 -7
- package/lib/helpers/requireArg.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 -91
- package/lib/operations/handleCopySingleOperation.js +0 -22
- package/lib/operations/handleCreateSingleOperation.js +0 -35
- package/lib/operations/handleDeleteSingleOperation.js +0 -14
- package/lib/operations/handleDescribeSingleOperation.js +0 -22
- package/lib/operations/handleEditOperation.js +0 -51
- package/lib/operations/handleEditRawOperation.js +0 -35
- package/lib/operations/handleGetOperation.js +0 -29
- package/lib/operations/handleGetSingleOperation.js +0 -20
- package/lib/operations/handleListOperation.js +0 -63
- 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/promptConfirm.js +0 -12
- package/lib/prompts/promptDefaultAction.js +0 -13
- package/lib/prompts/promptEntry.js +0 -19
- 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 -13
- package/lib/socket/socketClient.js +0 -12
- package/lib/types.js +0 -1
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import { apiCallHandler } from "../api/apiCallHandler.js";
|
|
2
|
-
import { handleResponseFormatOptions } from "../helpers/handleResponseFormatOptions.js";
|
|
3
|
-
import { saveFile } from "../helpers/saveFile.js";
|
|
4
|
-
import { spinner } from "../../index.js";
|
|
5
|
-
import { EXIT_GENERAL_ERROR, EXIT_MISUSE } from "../exitCodes.js";
|
|
6
|
-
export function createWebhooksCommand(program) {
|
|
7
|
-
const hooks = program
|
|
8
|
-
.command("webhooks")
|
|
9
|
-
.alias("hooks")
|
|
10
|
-
.description("Manage webhooks and event subscriptions");
|
|
11
|
-
// ay webhooks list
|
|
12
|
-
hooks
|
|
13
|
-
.command("list")
|
|
14
|
-
.alias("ls")
|
|
15
|
-
.description("List registered webhooks")
|
|
16
|
-
.option("-l, --limit <number>", "Limit results", parseInt, 50)
|
|
17
|
-
.option("-p, --page <number>", "Page number", parseInt, 1)
|
|
18
|
-
.action(async (options) => {
|
|
19
|
-
var _a, _b, _c;
|
|
20
|
-
try {
|
|
21
|
-
const opts = { ...program.opts(), ...options };
|
|
22
|
-
spinner.start({ text: "Fetching webhooks...", color: "magenta" });
|
|
23
|
-
const res = await apiCallHandler("config", "hooks", "get", null, {
|
|
24
|
-
page: opts.page,
|
|
25
|
-
limit: opts.limit,
|
|
26
|
-
responseFormat: opts.responseFormat,
|
|
27
|
-
verbosity: opts.verbosity,
|
|
28
|
-
});
|
|
29
|
-
handleResponseFormatOptions(opts, res);
|
|
30
|
-
const total = (_c = (_b = (_a = res.meta) === null || _a === void 0 ? void 0 : _a.pageInfo) === null || _b === void 0 ? void 0 : _b.totalEntries) !== null && _c !== void 0 ? _c : 0;
|
|
31
|
-
spinner.success({ text: `Found ${total} webhooks` });
|
|
32
|
-
spinner.stop();
|
|
33
|
-
if (opts.save)
|
|
34
|
-
await saveFile("webhooks-list", opts, res);
|
|
35
|
-
}
|
|
36
|
-
catch (e) {
|
|
37
|
-
spinner.error({ text: e.message || "Failed to list webhooks" });
|
|
38
|
-
process.exit(EXIT_GENERAL_ERROR);
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
// ay webhooks get <id>
|
|
42
|
-
hooks
|
|
43
|
-
.command("get <id>")
|
|
44
|
-
.description("Get webhook details")
|
|
45
|
-
.action(async (id, options) => {
|
|
46
|
-
try {
|
|
47
|
-
const opts = { ...program.opts(), ...options };
|
|
48
|
-
spinner.start({ text: `Fetching webhook ${id}...`, color: "magenta" });
|
|
49
|
-
const res = await apiCallHandler("config", `hooks/${id}`, "get", null, {
|
|
50
|
-
responseFormat: opts.responseFormat,
|
|
51
|
-
verbosity: opts.verbosity,
|
|
52
|
-
});
|
|
53
|
-
handleResponseFormatOptions(opts, res);
|
|
54
|
-
spinner.success({ text: `Webhook ${id} loaded` });
|
|
55
|
-
spinner.stop();
|
|
56
|
-
}
|
|
57
|
-
catch (e) {
|
|
58
|
-
spinner.error({ text: e.message || "Failed to get webhook" });
|
|
59
|
-
process.exit(EXIT_GENERAL_ERROR);
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
// ay webhooks create --body '{...}'
|
|
63
|
-
hooks
|
|
64
|
-
.command("create")
|
|
65
|
-
.description("Create a new webhook")
|
|
66
|
-
.option("--body <json>", "Webhook definition as JSON")
|
|
67
|
-
.option("--body-file <path>", "Read webhook definition from file")
|
|
68
|
-
.action(async (options) => {
|
|
69
|
-
try {
|
|
70
|
-
const opts = { ...program.opts(), ...options };
|
|
71
|
-
let body = null;
|
|
72
|
-
if (opts.body) {
|
|
73
|
-
try {
|
|
74
|
-
body = JSON.parse(opts.body);
|
|
75
|
-
}
|
|
76
|
-
catch (_a) {
|
|
77
|
-
spinner.error({ text: "Invalid JSON in --body" });
|
|
78
|
-
process.exit(EXIT_MISUSE);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
else if (opts.bodyFile) {
|
|
82
|
-
const fs = await import("fs");
|
|
83
|
-
try {
|
|
84
|
-
body = JSON.parse(fs.readFileSync(opts.bodyFile, "utf-8"));
|
|
85
|
-
}
|
|
86
|
-
catch (_b) {
|
|
87
|
-
spinner.error({ text: `Invalid JSON in file: ${opts.bodyFile}` });
|
|
88
|
-
process.exit(EXIT_MISUSE);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
if (!body) {
|
|
92
|
-
spinner.error({ text: "Provide webhook definition via --body or --body-file" });
|
|
93
|
-
process.exit(EXIT_MISUSE);
|
|
94
|
-
}
|
|
95
|
-
spinner.start({ text: "Creating webhook...", color: "magenta" });
|
|
96
|
-
const res = await apiCallHandler("config", "hooks", "post", body, {
|
|
97
|
-
responseFormat: opts.responseFormat,
|
|
98
|
-
});
|
|
99
|
-
handleResponseFormatOptions(opts, res);
|
|
100
|
-
spinner.success({ text: `Webhook created` });
|
|
101
|
-
spinner.stop();
|
|
102
|
-
}
|
|
103
|
-
catch (e) {
|
|
104
|
-
spinner.error({ text: e.message || "Failed to create webhook" });
|
|
105
|
-
process.exit(EXIT_GENERAL_ERROR);
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
// ay webhooks delete <id>
|
|
109
|
-
hooks
|
|
110
|
-
.command("delete <id>")
|
|
111
|
-
.alias("rm")
|
|
112
|
-
.description("Delete a webhook")
|
|
113
|
-
.action(async (id, options) => {
|
|
114
|
-
try {
|
|
115
|
-
const opts = { ...program.opts(), ...options };
|
|
116
|
-
spinner.start({ text: `Deleting webhook ${id}...`, color: "magenta" });
|
|
117
|
-
const res = await apiCallHandler("config", `hooks/${id}`, "delete", null, {
|
|
118
|
-
responseFormat: opts.responseFormat,
|
|
119
|
-
});
|
|
120
|
-
handleResponseFormatOptions(opts, res);
|
|
121
|
-
spinner.success({ text: `Webhook ${id} deleted` });
|
|
122
|
-
spinner.stop();
|
|
123
|
-
}
|
|
124
|
-
catch (e) {
|
|
125
|
-
spinner.error({ text: e.message || "Failed to delete webhook" });
|
|
126
|
-
process.exit(EXIT_GENERAL_ERROR);
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
// ay webhooks templates
|
|
130
|
-
hooks
|
|
131
|
-
.command("templates")
|
|
132
|
-
.description("List available webhook templates")
|
|
133
|
-
.option("-l, --limit <number>", "Limit results", parseInt, 50)
|
|
134
|
-
.action(async (options) => {
|
|
135
|
-
var _a, _b, _c;
|
|
136
|
-
try {
|
|
137
|
-
const opts = { ...program.opts(), ...options };
|
|
138
|
-
spinner.start({ text: "Fetching webhook templates...", color: "magenta" });
|
|
139
|
-
const res = await apiCallHandler("config", "hooktemplates", "get", null, {
|
|
140
|
-
limit: opts.limit,
|
|
141
|
-
responseFormat: opts.responseFormat,
|
|
142
|
-
verbosity: opts.verbosity,
|
|
143
|
-
});
|
|
144
|
-
handleResponseFormatOptions(opts, res);
|
|
145
|
-
const total = (_c = (_b = (_a = res.meta) === null || _a === void 0 ? void 0 : _a.pageInfo) === null || _b === void 0 ? void 0 : _b.totalEntries) !== null && _c !== void 0 ? _c : 0;
|
|
146
|
-
spinner.success({ text: `Found ${total} webhook templates` });
|
|
147
|
-
spinner.stop();
|
|
148
|
-
if (opts.save)
|
|
149
|
-
await saveFile("webhook-templates", opts, res);
|
|
150
|
-
}
|
|
151
|
-
catch (e) {
|
|
152
|
-
spinner.error({ text: e.message || "Failed to list templates" });
|
|
153
|
-
process.exit(EXIT_GENERAL_ERROR);
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import chalk from "chalk";
|
|
2
|
-
import moment from "moment";
|
|
3
|
-
import { localStorage } from "../helpers/localStorage.js";
|
|
4
|
-
import { decodeToken } from "../api/decodeToken.js";
|
|
5
|
-
import { spinner } from "../../index.js";
|
|
6
|
-
import { login } from "../api/login.js";
|
|
7
|
-
import { EXIT_GENERAL_ERROR } from "../exitCodes.js";
|
|
8
|
-
const LABEL_MAP = {
|
|
9
|
-
_id: "User ID",
|
|
10
|
-
_customerID: "Customer",
|
|
11
|
-
_resellerID: "Reseller",
|
|
12
|
-
_agencyID: "Agency",
|
|
13
|
-
email: "Email",
|
|
14
|
-
name: "Name",
|
|
15
|
-
username: "Username",
|
|
16
|
-
role: "Role",
|
|
17
|
-
type: "Type",
|
|
18
|
-
language: "Language",
|
|
19
|
-
iat: "Issued",
|
|
20
|
-
exp: "Expires",
|
|
21
|
-
};
|
|
22
|
-
const SKIP_FIELDS = new Set(["password", "hash", "salt", "__v"]);
|
|
23
|
-
function formatValue(key, value) {
|
|
24
|
-
if ((key === "iat" || key === "exp") && typeof value === "number") {
|
|
25
|
-
const m = moment.unix(value);
|
|
26
|
-
const relative = m.fromNow();
|
|
27
|
-
const formatted = m.format("YYYY-MM-DD HH:mm:ss");
|
|
28
|
-
if (key === "exp" && m.isBefore(moment())) {
|
|
29
|
-
return chalk.red(`${formatted} (expired ${relative})`);
|
|
30
|
-
}
|
|
31
|
-
return `${formatted} ${chalk.dim(`(${relative})`)}`;
|
|
32
|
-
}
|
|
33
|
-
if (typeof value === "object" && value !== null) {
|
|
34
|
-
return JSON.stringify(value);
|
|
35
|
-
}
|
|
36
|
-
return String(value);
|
|
37
|
-
}
|
|
38
|
-
function displayUser(user) {
|
|
39
|
-
const name = user.name || user.username || user.email || "User";
|
|
40
|
-
const greeting = getGreeting();
|
|
41
|
-
console.log();
|
|
42
|
-
console.log(chalk.bold(` ${greeting}, ${chalk.cyan(name)}!`));
|
|
43
|
-
console.log(chalk.dim(` ${"─".repeat(44)}`));
|
|
44
|
-
const maxLabel = Math.max(...Object.keys(user)
|
|
45
|
-
.filter((k) => !SKIP_FIELDS.has(k))
|
|
46
|
-
.map((k) => (LABEL_MAP[k] || k).length));
|
|
47
|
-
for (const [key, value] of Object.entries(user)) {
|
|
48
|
-
if (SKIP_FIELDS.has(key) || value == null || value === "")
|
|
49
|
-
continue;
|
|
50
|
-
const label = LABEL_MAP[key] || key;
|
|
51
|
-
const formatted = formatValue(key, value);
|
|
52
|
-
console.log(` ${chalk.dim(label.padEnd(maxLabel + 2))} ${chalk.white(formatted)}`);
|
|
53
|
-
}
|
|
54
|
-
console.log();
|
|
55
|
-
}
|
|
56
|
-
function getGreeting() {
|
|
57
|
-
const hour = new Date().getHours();
|
|
58
|
-
if (hour < 12)
|
|
59
|
-
return "Good morning";
|
|
60
|
-
if (hour < 18)
|
|
61
|
-
return "Good afternoon";
|
|
62
|
-
return "Good evening";
|
|
63
|
-
}
|
|
64
|
-
export function createWhoAmICommand(program) {
|
|
65
|
-
program
|
|
66
|
-
.command("whoami")
|
|
67
|
-
.alias("who")
|
|
68
|
-
.description("Display the currently authenticated user")
|
|
69
|
-
.action(async (options) => {
|
|
70
|
-
try {
|
|
71
|
-
const tokenPayload = decodeToken(localStorage.getItem("token"));
|
|
72
|
-
if (tokenPayload) {
|
|
73
|
-
displayUser(tokenPayload.payload);
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
await login();
|
|
77
|
-
const newPayload = decodeToken(localStorage.getItem("token"));
|
|
78
|
-
if (newPayload) {
|
|
79
|
-
displayUser(newPayload.payload);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
catch (e) {
|
|
84
|
-
spinner.error({ text: e.message || "An unexpected error occurred" });
|
|
85
|
-
process.exit(EXIT_GENERAL_ERROR);
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
}
|
package/lib/exitCodes.js
DELETED
package/lib/helpers/config.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export const config = {
|
|
2
|
-
apiUrl: process.env.AYOUNE_API_URL || "https://api.ayoune.app",
|
|
3
|
-
auditUrl: process.env.AYOUNE_AUDIT_URL || "https://audit.ayoune.app",
|
|
4
|
-
notifierUrl: process.env.AYOUNE_NOTIFIER_URL || "https://notifier.ayoune.app",
|
|
5
|
-
loginUrl: process.env.AYOUNE_LOGIN_URL || "https://login.ayoune.app",
|
|
6
|
-
};
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { readFileSync, writeFileSync, existsSync, mkdirSync } from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import os from "os";
|
|
4
|
-
const CONFIG_PATHS = [
|
|
5
|
-
path.join(os.homedir(), ".config", "ayoune", "config.json"),
|
|
6
|
-
path.join(os.homedir(), ".ayounerc"),
|
|
7
|
-
];
|
|
8
|
-
function findConfigFile() {
|
|
9
|
-
for (const configPath of CONFIG_PATHS) {
|
|
10
|
-
if (existsSync(configPath)) {
|
|
11
|
-
return configPath;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
|
-
export function loadConfig() {
|
|
17
|
-
const configPath = findConfigFile();
|
|
18
|
-
if (!configPath) {
|
|
19
|
-
return {};
|
|
20
|
-
}
|
|
21
|
-
try {
|
|
22
|
-
const raw = readFileSync(configPath, "utf-8");
|
|
23
|
-
return JSON.parse(raw);
|
|
24
|
-
}
|
|
25
|
-
catch (_a) {
|
|
26
|
-
return {};
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
export function getConfigPath() {
|
|
30
|
-
return path.join(os.homedir(), ".config", "ayoune", "config.json");
|
|
31
|
-
}
|
|
32
|
-
export function saveConfig(config) {
|
|
33
|
-
const configPath = getConfigPath();
|
|
34
|
-
const dir = path.dirname(configPath);
|
|
35
|
-
if (!existsSync(dir)) {
|
|
36
|
-
mkdirSync(dir, { recursive: true });
|
|
37
|
-
}
|
|
38
|
-
writeFileSync(configPath, JSON.stringify(config, null, 2), "utf-8");
|
|
39
|
-
}
|
|
40
|
-
export function getActiveProfile(config) {
|
|
41
|
-
var _a, _b;
|
|
42
|
-
const profileName = process.env.AYOUNE_PROFILE || config.profile || "production";
|
|
43
|
-
return (_b = (_a = config.profiles) === null || _a === void 0 ? void 0 : _a[profileName]) !== null && _b !== void 0 ? _b : {};
|
|
44
|
-
}
|
|
45
|
-
export function getApiUrl(config) {
|
|
46
|
-
const profile = getActiveProfile(config);
|
|
47
|
-
return (process.env.AYOUNE_API_URL || profile.apiUrl || "https://api.ayoune.app");
|
|
48
|
-
}
|
|
49
|
-
export function getAuditUrl(config) {
|
|
50
|
-
const profile = getActiveProfile(config);
|
|
51
|
-
return (process.env.AYOUNE_AUDIT_URL ||
|
|
52
|
-
profile.auditUrl ||
|
|
53
|
-
"https://audit.ayoune.app");
|
|
54
|
-
}
|
|
55
|
-
export function getNotifierUrl(config) {
|
|
56
|
-
const profile = getActiveProfile(config);
|
|
57
|
-
return (process.env.AYOUNE_NOTIFIER_URL ||
|
|
58
|
-
profile.notifierUrl ||
|
|
59
|
-
"https://notifier.ayoune.app");
|
|
60
|
-
}
|
|
@@ -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,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
|
@@ -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
|
-
}
|