@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.
- 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 -150
- 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,283 +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 } from "../exitCodes.js";
|
|
6
|
-
export function createMonitorCommand(program) {
|
|
7
|
-
const monitor = program
|
|
8
|
-
.command("monitor")
|
|
9
|
-
.alias("mon")
|
|
10
|
-
.description("Monitor platform activity, logs, and alerts");
|
|
11
|
-
// ay monitor logs [type]
|
|
12
|
-
monitor
|
|
13
|
-
.command("logs [type]")
|
|
14
|
-
.description("List recent platform logs (api, error, mail, ai, trigger, ...)")
|
|
15
|
-
.addHelpText("after", `
|
|
16
|
-
Log types: api, error, mail, ai, trigger, doi, export, sms, whatsapp, production, setup, state, shop, score, sensor, stock, soi, reward, merge, download, post, webreceiver, work, computingentitieslogs, consumerapi, accessterminal, googleads
|
|
17
|
-
|
|
18
|
-
Examples:
|
|
19
|
-
ay monitor logs error List recent error logs
|
|
20
|
-
ay monitor logs api -l 10 List last 10 API logs
|
|
21
|
-
ay monitor logs ai -r table List AI logs in table format`)
|
|
22
|
-
.option("-l, --limit <number>", "Limit results", parseInt, 25)
|
|
23
|
-
.option("-p, --page <number>", "Page number", parseInt, 1)
|
|
24
|
-
.option("--sort <field>", "Sort by field", "-createdAt")
|
|
25
|
-
.action(async (type, options) => {
|
|
26
|
-
var _a, _b, _c;
|
|
27
|
-
try {
|
|
28
|
-
const opts = { ...program.opts(), ...options };
|
|
29
|
-
const logType = type || "api";
|
|
30
|
-
const collectionMap = {
|
|
31
|
-
api: "apilogs",
|
|
32
|
-
error: "errorlogs",
|
|
33
|
-
mail: "maillogs",
|
|
34
|
-
ai: "ailogs",
|
|
35
|
-
trigger: "triggerlogs",
|
|
36
|
-
doi: "doilogs",
|
|
37
|
-
export: "exportlogs",
|
|
38
|
-
sms: "smslogs",
|
|
39
|
-
whatsapp: "whatsapplogs",
|
|
40
|
-
production: "productionlogs",
|
|
41
|
-
setup: "setuplogs",
|
|
42
|
-
state: "statelogs",
|
|
43
|
-
shop: "shoplogs",
|
|
44
|
-
score: "scorelogs",
|
|
45
|
-
sensor: "sensorlogs",
|
|
46
|
-
stock: "stocklogs",
|
|
47
|
-
soi: "soilogs",
|
|
48
|
-
reward: "rewardlogs",
|
|
49
|
-
merge: "mergelogs",
|
|
50
|
-
download: "downloadlogs",
|
|
51
|
-
post: "postlogs",
|
|
52
|
-
webreceiver: "webreceiverlogs",
|
|
53
|
-
work: "worklogs",
|
|
54
|
-
consumerapi: "consumerapilogs",
|
|
55
|
-
accessterminal: "accessterminallogs",
|
|
56
|
-
googleads: "adwordslogs",
|
|
57
|
-
computing: "computingentitieslogs",
|
|
58
|
-
};
|
|
59
|
-
const collection = collectionMap[logType] || `${logType}logs`;
|
|
60
|
-
spinner.start({ text: `Fetching ${logType} logs...`, color: "magenta" });
|
|
61
|
-
const res = await apiCallHandler("logs", collection, "get", null, {
|
|
62
|
-
page: opts.page,
|
|
63
|
-
limit: opts.limit,
|
|
64
|
-
sort: opts.sort,
|
|
65
|
-
responseFormat: opts.responseFormat,
|
|
66
|
-
verbosity: opts.verbosity,
|
|
67
|
-
hideMeta: opts.hideMeta,
|
|
68
|
-
});
|
|
69
|
-
handleResponseFormatOptions(opts, res);
|
|
70
|
-
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;
|
|
71
|
-
spinner.success({ text: `Found ${total} ${logType} log entries` });
|
|
72
|
-
spinner.stop();
|
|
73
|
-
if (opts.save)
|
|
74
|
-
await saveFile(`monitor-logs-${logType}`, opts, res);
|
|
75
|
-
}
|
|
76
|
-
catch (e) {
|
|
77
|
-
spinner.error({ text: e.message || "Failed to fetch logs" });
|
|
78
|
-
process.exit(EXIT_GENERAL_ERROR);
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
// ay monitor alerts — command group
|
|
82
|
-
const alerts = monitor
|
|
83
|
-
.command("alerts")
|
|
84
|
-
.description("Manage platform alerts (list, acknowledge, resolve)");
|
|
85
|
-
// ay monitor alerts list
|
|
86
|
-
alerts
|
|
87
|
-
.command("list")
|
|
88
|
-
.alias("ls")
|
|
89
|
-
.description("List active alerts")
|
|
90
|
-
.addHelpText("after", `
|
|
91
|
-
Examples:
|
|
92
|
-
ay monitor alerts list List all active alerts
|
|
93
|
-
ay monitor alerts list --severity critical Show critical alerts only
|
|
94
|
-
ay monitor alerts list --type pod_crash Filter by alert type
|
|
95
|
-
ay monitor alerts list --status acknowledged Show acknowledged alerts`)
|
|
96
|
-
.option("-l, --limit <number>", "Limit results", parseInt, 50)
|
|
97
|
-
.option("-p, --page <number>", "Page number", parseInt, 1)
|
|
98
|
-
.option("--severity <level>", "Filter: info, warning, critical")
|
|
99
|
-
.option("--type <type>", "Filter: pod_crash, oom_killed, image_pull_error, deployment_failed, pipeline_failed, cluster_unreachable, high_restart_count, custom")
|
|
100
|
-
.option("--status <status>", "Filter: active, acknowledged, resolved", "active")
|
|
101
|
-
.action(async (options) => {
|
|
102
|
-
var _a, _b, _c;
|
|
103
|
-
try {
|
|
104
|
-
const opts = { ...program.opts(), ...options };
|
|
105
|
-
spinner.start({ text: "Fetching alerts...", color: "magenta" });
|
|
106
|
-
const params = {
|
|
107
|
-
page: opts.page,
|
|
108
|
-
limit: opts.limit,
|
|
109
|
-
responseFormat: opts.responseFormat,
|
|
110
|
-
verbosity: opts.verbosity,
|
|
111
|
-
hideMeta: opts.hideMeta,
|
|
112
|
-
};
|
|
113
|
-
if (opts.severity)
|
|
114
|
-
params.severity = opts.severity;
|
|
115
|
-
if (opts.type)
|
|
116
|
-
params.type = opts.type;
|
|
117
|
-
if (opts.status)
|
|
118
|
-
params.status = opts.status;
|
|
119
|
-
const res = await apiCallHandler("devops", "alerts", "get", null, params);
|
|
120
|
-
handleResponseFormatOptions(opts, res);
|
|
121
|
-
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;
|
|
122
|
-
spinner.success({ text: `Found ${total} alerts` });
|
|
123
|
-
spinner.stop();
|
|
124
|
-
if (opts.save)
|
|
125
|
-
await saveFile("monitor-alerts", opts, res);
|
|
126
|
-
}
|
|
127
|
-
catch (e) {
|
|
128
|
-
spinner.error({ text: e.message || "Failed to fetch alerts" });
|
|
129
|
-
process.exit(EXIT_GENERAL_ERROR);
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
// ay monitor alerts ack <id>
|
|
133
|
-
alerts
|
|
134
|
-
.command("ack <id>")
|
|
135
|
-
.alias("acknowledge")
|
|
136
|
-
.description("Acknowledge an alert")
|
|
137
|
-
.action(async (id, options) => {
|
|
138
|
-
try {
|
|
139
|
-
const opts = { ...program.opts(), ...options };
|
|
140
|
-
spinner.start({ text: `Acknowledging alert ${id}...`, color: "magenta" });
|
|
141
|
-
const res = await apiCallHandler("devops", `alerts/${id}/acknowledge`, "put", null, {
|
|
142
|
-
responseFormat: opts.responseFormat,
|
|
143
|
-
});
|
|
144
|
-
handleResponseFormatOptions(opts, res);
|
|
145
|
-
spinner.success({ text: `Alert ${id} acknowledged` });
|
|
146
|
-
spinner.stop();
|
|
147
|
-
}
|
|
148
|
-
catch (e) {
|
|
149
|
-
spinner.error({ text: e.message || "Failed to acknowledge alert" });
|
|
150
|
-
process.exit(EXIT_GENERAL_ERROR);
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
// ay monitor alerts resolve <id>
|
|
154
|
-
alerts
|
|
155
|
-
.command("resolve <id>")
|
|
156
|
-
.description("Resolve an alert")
|
|
157
|
-
.action(async (id, options) => {
|
|
158
|
-
try {
|
|
159
|
-
const opts = { ...program.opts(), ...options };
|
|
160
|
-
spinner.start({ text: `Resolving alert ${id}...`, color: "magenta" });
|
|
161
|
-
const res = await apiCallHandler("devops", `alerts/${id}/resolve`, "put", null, {
|
|
162
|
-
responseFormat: opts.responseFormat,
|
|
163
|
-
});
|
|
164
|
-
handleResponseFormatOptions(opts, res);
|
|
165
|
-
spinner.success({ text: `Alert ${id} resolved` });
|
|
166
|
-
spinner.stop();
|
|
167
|
-
}
|
|
168
|
-
catch (e) {
|
|
169
|
-
spinner.error({ text: e.message || "Failed to resolve alert" });
|
|
170
|
-
process.exit(EXIT_GENERAL_ERROR);
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
// ay monitor sessions
|
|
174
|
-
monitor
|
|
175
|
-
.command("sessions")
|
|
176
|
-
.description("List active user sessions")
|
|
177
|
-
.option("-l, --limit <number>", "Limit results", parseInt, 50)
|
|
178
|
-
.action(async (options) => {
|
|
179
|
-
var _a, _b, _c;
|
|
180
|
-
try {
|
|
181
|
-
const opts = { ...program.opts(), ...options };
|
|
182
|
-
spinner.start({ text: "Fetching active sessions...", color: "magenta" });
|
|
183
|
-
const res = await apiCallHandler("monitoring", "sessions", "get", null, {
|
|
184
|
-
limit: opts.limit,
|
|
185
|
-
responseFormat: opts.responseFormat,
|
|
186
|
-
verbosity: opts.verbosity,
|
|
187
|
-
});
|
|
188
|
-
handleResponseFormatOptions(opts, res);
|
|
189
|
-
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;
|
|
190
|
-
spinner.success({ text: `Found ${total} active sessions` });
|
|
191
|
-
spinner.stop();
|
|
192
|
-
if (opts.save)
|
|
193
|
-
await saveFile("monitor-sessions", opts, res);
|
|
194
|
-
}
|
|
195
|
-
catch (e) {
|
|
196
|
-
spinner.error({ text: e.message || "Failed to fetch sessions" });
|
|
197
|
-
process.exit(EXIT_GENERAL_ERROR);
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
// ay monitor checks
|
|
201
|
-
monitor
|
|
202
|
-
.command("checks")
|
|
203
|
-
.description("List monitoring checks and their results")
|
|
204
|
-
.option("-l, --limit <number>", "Limit results", parseInt, 50)
|
|
205
|
-
.action(async (options) => {
|
|
206
|
-
var _a, _b, _c;
|
|
207
|
-
try {
|
|
208
|
-
const opts = { ...program.opts(), ...options };
|
|
209
|
-
spinner.start({ text: "Fetching monitoring checks...", color: "magenta" });
|
|
210
|
-
const res = await apiCallHandler("monitoring", "checks", "get", null, {
|
|
211
|
-
limit: opts.limit,
|
|
212
|
-
responseFormat: opts.responseFormat,
|
|
213
|
-
verbosity: opts.verbosity,
|
|
214
|
-
});
|
|
215
|
-
handleResponseFormatOptions(opts, res);
|
|
216
|
-
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;
|
|
217
|
-
spinner.success({ text: `Found ${total} monitoring checks` });
|
|
218
|
-
spinner.stop();
|
|
219
|
-
if (opts.save)
|
|
220
|
-
await saveFile("monitor-checks", opts, res);
|
|
221
|
-
}
|
|
222
|
-
catch (e) {
|
|
223
|
-
spinner.error({ text: e.message || "Failed to fetch checks" });
|
|
224
|
-
process.exit(EXIT_GENERAL_ERROR);
|
|
225
|
-
}
|
|
226
|
-
});
|
|
227
|
-
// ay monitor activeusers
|
|
228
|
-
monitor
|
|
229
|
-
.command("activeusers")
|
|
230
|
-
.alias("users")
|
|
231
|
-
.description("Show currently active users on the platform")
|
|
232
|
-
.option("-l, --limit <number>", "Limit results", parseInt, 50)
|
|
233
|
-
.action(async (options) => {
|
|
234
|
-
var _a, _b, _c;
|
|
235
|
-
try {
|
|
236
|
-
const opts = { ...program.opts(), ...options };
|
|
237
|
-
spinner.start({ text: "Fetching active users...", color: "magenta" });
|
|
238
|
-
const res = await apiCallHandler("monitoring", "activeusers", "get", null, {
|
|
239
|
-
limit: opts.limit,
|
|
240
|
-
responseFormat: opts.responseFormat,
|
|
241
|
-
verbosity: opts.verbosity,
|
|
242
|
-
});
|
|
243
|
-
handleResponseFormatOptions(opts, res);
|
|
244
|
-
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;
|
|
245
|
-
spinner.success({ text: `${total} active users` });
|
|
246
|
-
spinner.stop();
|
|
247
|
-
if (opts.save)
|
|
248
|
-
await saveFile("monitor-activeusers", opts, res);
|
|
249
|
-
}
|
|
250
|
-
catch (e) {
|
|
251
|
-
spinner.error({ text: e.message || "Failed to fetch active users" });
|
|
252
|
-
process.exit(EXIT_GENERAL_ERROR);
|
|
253
|
-
}
|
|
254
|
-
});
|
|
255
|
-
// ay monitor pagestats
|
|
256
|
-
monitor
|
|
257
|
-
.command("pagestats")
|
|
258
|
-
.alias("pages")
|
|
259
|
-
.description("View page view statistics")
|
|
260
|
-
.option("-l, --limit <number>", "Limit results", parseInt, 50)
|
|
261
|
-
.action(async (options) => {
|
|
262
|
-
var _a, _b, _c;
|
|
263
|
-
try {
|
|
264
|
-
const opts = { ...program.opts(), ...options };
|
|
265
|
-
spinner.start({ text: "Fetching page statistics...", color: "magenta" });
|
|
266
|
-
const res = await apiCallHandler("monitoring", "pagestats", "get", null, {
|
|
267
|
-
limit: opts.limit,
|
|
268
|
-
responseFormat: opts.responseFormat,
|
|
269
|
-
verbosity: opts.verbosity,
|
|
270
|
-
});
|
|
271
|
-
handleResponseFormatOptions(opts, res);
|
|
272
|
-
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;
|
|
273
|
-
spinner.success({ text: `Found ${total} page stat entries` });
|
|
274
|
-
spinner.stop();
|
|
275
|
-
if (opts.save)
|
|
276
|
-
await saveFile("monitor-pagestats", opts, res);
|
|
277
|
-
}
|
|
278
|
-
catch (e) {
|
|
279
|
-
spinner.error({ text: e.message || "Failed to fetch page stats" });
|
|
280
|
-
process.exit(EXIT_GENERAL_ERROR);
|
|
281
|
-
}
|
|
282
|
-
});
|
|
283
|
-
}
|
|
@@ -1,241 +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 createPermissionsCommand(program) {
|
|
7
|
-
const perms = program
|
|
8
|
-
.command("permissions")
|
|
9
|
-
.alias("perms")
|
|
10
|
-
.description("Manage permissions, access requests, and user rights");
|
|
11
|
-
// ── PERMISSION REQUESTS ────────────────────────────────
|
|
12
|
-
const requests = perms
|
|
13
|
-
.command("requests")
|
|
14
|
-
.alias("req")
|
|
15
|
-
.description("Manage permission requests");
|
|
16
|
-
// ay permissions requests list
|
|
17
|
-
requests
|
|
18
|
-
.command("list")
|
|
19
|
-
.alias("ls")
|
|
20
|
-
.description("List permission requests")
|
|
21
|
-
.option("--status <status>", "Filter by status (pending, approved, rejected)")
|
|
22
|
-
.option("-l, --limit <number>", "Limit results", parseInt, 25)
|
|
23
|
-
.option("-p, --page <number>", "Page number", parseInt, 1)
|
|
24
|
-
.action(async (options) => {
|
|
25
|
-
var _a, _b, _c;
|
|
26
|
-
try {
|
|
27
|
-
const opts = { ...program.opts(), ...options };
|
|
28
|
-
spinner.start({ text: "Fetching permission requests...", color: "magenta" });
|
|
29
|
-
const params = {
|
|
30
|
-
page: opts.page,
|
|
31
|
-
limit: opts.limit,
|
|
32
|
-
responseFormat: opts.responseFormat,
|
|
33
|
-
verbosity: opts.verbosity,
|
|
34
|
-
};
|
|
35
|
-
if (opts.status)
|
|
36
|
-
params.status = opts.status;
|
|
37
|
-
const res = await apiCallHandler("config", "permissionrequests", "get", null, params);
|
|
38
|
-
handleResponseFormatOptions(opts, res);
|
|
39
|
-
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;
|
|
40
|
-
spinner.success({ text: `Found ${total} permission requests` });
|
|
41
|
-
spinner.stop();
|
|
42
|
-
if (opts.save)
|
|
43
|
-
await saveFile("permission-requests", opts, res);
|
|
44
|
-
}
|
|
45
|
-
catch (e) {
|
|
46
|
-
spinner.error({ text: e.message || "Failed to list permission requests" });
|
|
47
|
-
process.exit(EXIT_GENERAL_ERROR);
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
// ay permissions requests approve <id>
|
|
51
|
-
requests
|
|
52
|
-
.command("approve <id>")
|
|
53
|
-
.description("Approve a permission request")
|
|
54
|
-
.action(async (id, options) => {
|
|
55
|
-
try {
|
|
56
|
-
const opts = { ...program.opts(), ...options };
|
|
57
|
-
spinner.start({ text: `Approving request ${id}...`, color: "magenta" });
|
|
58
|
-
const res = await apiCallHandler("config", "permissionrequests", "put", { _id: id, status: "approved" }, { responseFormat: opts.responseFormat });
|
|
59
|
-
handleResponseFormatOptions(opts, res);
|
|
60
|
-
spinner.success({ text: `Permission request ${id} approved` });
|
|
61
|
-
spinner.stop();
|
|
62
|
-
}
|
|
63
|
-
catch (e) {
|
|
64
|
-
spinner.error({ text: e.message || "Failed to approve request" });
|
|
65
|
-
process.exit(EXIT_GENERAL_ERROR);
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
// ay permissions requests reject <id>
|
|
69
|
-
requests
|
|
70
|
-
.command("reject <id>")
|
|
71
|
-
.description("Reject a permission request")
|
|
72
|
-
.option("--reason <reason>", "Reason for rejection")
|
|
73
|
-
.action(async (id, options) => {
|
|
74
|
-
try {
|
|
75
|
-
const opts = { ...program.opts(), ...options };
|
|
76
|
-
spinner.start({ text: `Rejecting request ${id}...`, color: "magenta" });
|
|
77
|
-
const body = { _id: id, status: "rejected" };
|
|
78
|
-
if (opts.reason)
|
|
79
|
-
body.reason = opts.reason;
|
|
80
|
-
const res = await apiCallHandler("config", "permissionrequests", "put", body, { responseFormat: opts.responseFormat });
|
|
81
|
-
handleResponseFormatOptions(opts, res);
|
|
82
|
-
spinner.success({ text: `Permission request ${id} rejected` });
|
|
83
|
-
spinner.stop();
|
|
84
|
-
}
|
|
85
|
-
catch (e) {
|
|
86
|
-
spinner.error({ text: e.message || "Failed to reject request" });
|
|
87
|
-
process.exit(EXIT_GENERAL_ERROR);
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
// ay permissions requests create
|
|
91
|
-
requests
|
|
92
|
-
.command("create")
|
|
93
|
-
.description("Create a new permission request")
|
|
94
|
-
.option("--body <json>", "Request definition as JSON")
|
|
95
|
-
.option("--right <right>", "Right to request (e.g. crm.contacts.edit)")
|
|
96
|
-
.option("--reason <reason>", "Reason for the request")
|
|
97
|
-
.action(async (options) => {
|
|
98
|
-
try {
|
|
99
|
-
const opts = { ...program.opts(), ...options };
|
|
100
|
-
let body = null;
|
|
101
|
-
if (opts.body) {
|
|
102
|
-
try {
|
|
103
|
-
body = JSON.parse(opts.body);
|
|
104
|
-
}
|
|
105
|
-
catch (_a) {
|
|
106
|
-
spinner.error({ text: "Invalid JSON in --body" });
|
|
107
|
-
process.exit(EXIT_MISUSE);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
else if (opts.right) {
|
|
111
|
-
body = { right: opts.right };
|
|
112
|
-
if (opts.reason)
|
|
113
|
-
body.reason = opts.reason;
|
|
114
|
-
}
|
|
115
|
-
if (!body) {
|
|
116
|
-
spinner.error({ text: "Provide request via --body or --right" });
|
|
117
|
-
process.exit(EXIT_MISUSE);
|
|
118
|
-
}
|
|
119
|
-
spinner.start({ text: "Creating permission request...", color: "magenta" });
|
|
120
|
-
const res = await apiCallHandler("config", "permissionrequests", "post", body, {
|
|
121
|
-
responseFormat: opts.responseFormat,
|
|
122
|
-
});
|
|
123
|
-
handleResponseFormatOptions(opts, res);
|
|
124
|
-
spinner.success({ text: "Permission request created" });
|
|
125
|
-
spinner.stop();
|
|
126
|
-
}
|
|
127
|
-
catch (e) {
|
|
128
|
-
spinner.error({ text: e.message || "Failed to create permission request" });
|
|
129
|
-
process.exit(EXIT_GENERAL_ERROR);
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
// ── USER RIGHTS ────────────────────────────────────────
|
|
133
|
-
const rights = perms
|
|
134
|
-
.command("rights")
|
|
135
|
-
.description("View and manage user rights");
|
|
136
|
-
// ay permissions rights list
|
|
137
|
-
rights
|
|
138
|
-
.command("list")
|
|
139
|
-
.alias("ls")
|
|
140
|
-
.description("List user rights / permission assignments")
|
|
141
|
-
.option("--userId <id>", "Filter by user ID")
|
|
142
|
-
.option("-l, --limit <number>", "Limit results", parseInt, 50)
|
|
143
|
-
.option("-p, --page <number>", "Page number", parseInt, 1)
|
|
144
|
-
.action(async (options) => {
|
|
145
|
-
var _a, _b, _c;
|
|
146
|
-
try {
|
|
147
|
-
const opts = { ...program.opts(), ...options };
|
|
148
|
-
spinner.start({ text: "Fetching user rights...", color: "magenta" });
|
|
149
|
-
const params = {
|
|
150
|
-
page: opts.page,
|
|
151
|
-
limit: opts.limit,
|
|
152
|
-
responseFormat: opts.responseFormat,
|
|
153
|
-
verbosity: opts.verbosity,
|
|
154
|
-
};
|
|
155
|
-
if (opts.userId)
|
|
156
|
-
params.userId = opts.userId;
|
|
157
|
-
const res = await apiCallHandler("config", "userrights", "get", null, params);
|
|
158
|
-
handleResponseFormatOptions(opts, res);
|
|
159
|
-
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;
|
|
160
|
-
spinner.success({ text: `Found ${total} user right assignments` });
|
|
161
|
-
spinner.stop();
|
|
162
|
-
if (opts.save)
|
|
163
|
-
await saveFile("user-rights", opts, res);
|
|
164
|
-
}
|
|
165
|
-
catch (e) {
|
|
166
|
-
spinner.error({ text: e.message || "Failed to list user rights" });
|
|
167
|
-
process.exit(EXIT_GENERAL_ERROR);
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
// ay permissions rights get <id>
|
|
171
|
-
rights
|
|
172
|
-
.command("get <id>")
|
|
173
|
-
.description("Get user right details")
|
|
174
|
-
.action(async (id, options) => {
|
|
175
|
-
try {
|
|
176
|
-
const opts = { ...program.opts(), ...options };
|
|
177
|
-
spinner.start({ text: `Fetching right ${id}...`, color: "magenta" });
|
|
178
|
-
const res = await apiCallHandler("config", `userrights/${id}`, "get", null, {
|
|
179
|
-
responseFormat: opts.responseFormat,
|
|
180
|
-
verbosity: opts.verbosity,
|
|
181
|
-
});
|
|
182
|
-
handleResponseFormatOptions(opts, res);
|
|
183
|
-
spinner.success({ text: `Right ${id} loaded` });
|
|
184
|
-
spinner.stop();
|
|
185
|
-
}
|
|
186
|
-
catch (e) {
|
|
187
|
-
spinner.error({ text: e.message || "Failed to get user right" });
|
|
188
|
-
process.exit(EXIT_GENERAL_ERROR);
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
// ── AUDIT (ENHANCED) ──────────────────────────────────
|
|
192
|
-
perms
|
|
193
|
-
.command("audit")
|
|
194
|
-
.description("Audit permission changes and access logs")
|
|
195
|
-
.addHelpText("after", `
|
|
196
|
-
Examples:
|
|
197
|
-
ay permissions audit --action delete --days 30
|
|
198
|
-
ay permissions audit --userId abc123 --collection contacts
|
|
199
|
-
ay permissions audit --action create --days 7 --save`)
|
|
200
|
-
.option("--userId <id>", "Filter by user ID")
|
|
201
|
-
.option("--action <action>", "Filter by action (create, update, delete, login)")
|
|
202
|
-
.option("--collection <name>", "Filter by collection")
|
|
203
|
-
.option("--days <number>", "Show entries from last N days", parseInt, 7)
|
|
204
|
-
.option("-l, --limit <number>", "Limit results", parseInt, 50)
|
|
205
|
-
.option("-p, --page <number>", "Page number", parseInt, 1)
|
|
206
|
-
.action(async (options) => {
|
|
207
|
-
var _a, _b, _c;
|
|
208
|
-
try {
|
|
209
|
-
const opts = { ...program.opts(), ...options };
|
|
210
|
-
spinner.start({ text: "Fetching audit logs...", color: "magenta" });
|
|
211
|
-
const params = {
|
|
212
|
-
page: opts.page,
|
|
213
|
-
limit: opts.limit,
|
|
214
|
-
responseFormat: opts.responseFormat,
|
|
215
|
-
verbosity: opts.verbosity,
|
|
216
|
-
};
|
|
217
|
-
if (opts.userId)
|
|
218
|
-
params.userId = opts.userId;
|
|
219
|
-
if (opts.action)
|
|
220
|
-
params.action = opts.action;
|
|
221
|
-
if (opts.collection)
|
|
222
|
-
params.collection = opts.collection;
|
|
223
|
-
if (opts.days) {
|
|
224
|
-
const fromDate = new Date();
|
|
225
|
-
fromDate.setDate(fromDate.getDate() - opts.days);
|
|
226
|
-
params.from = fromDate.toISOString();
|
|
227
|
-
}
|
|
228
|
-
const res = await apiCallHandler("general", "auditlogs", "get", null, params);
|
|
229
|
-
handleResponseFormatOptions(opts, res);
|
|
230
|
-
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;
|
|
231
|
-
spinner.success({ text: `Found ${total} audit entries (last ${opts.days} days)` });
|
|
232
|
-
spinner.stop();
|
|
233
|
-
if (opts.save)
|
|
234
|
-
await saveFile("permissions-audit", opts, res);
|
|
235
|
-
}
|
|
236
|
-
catch (e) {
|
|
237
|
-
spinner.error({ text: e.message || "Failed to fetch audit logs" });
|
|
238
|
-
process.exit(EXIT_GENERAL_ERROR);
|
|
239
|
-
}
|
|
240
|
-
});
|
|
241
|
-
}
|