@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,285 +0,0 @@
1
- import chalk from "chalk";
2
- import { apiCallHandler } from "../api/apiCallHandler.js";
3
- import { handleResponseFormatOptions } from "../helpers/handleResponseFormatOptions.js";
4
- import { saveFile } from "../helpers/saveFile.js";
5
- import { spinner } from "../../index.js";
6
- import { EXIT_GENERAL_ERROR, EXIT_MISUSE } from "../exitCodes.js";
7
- export function createUsersCommand(program) {
8
- const users = program
9
- .command("users")
10
- .description("Manage users, teams, and roles");
11
- // ── USERS ──────────────────────────────────────────────
12
- // ay users list
13
- users
14
- .command("list")
15
- .alias("ls")
16
- .description("List users")
17
- .option("--search <query>", "Search by name or email")
18
- .option("--role <roleId>", "Filter by role ID")
19
- .option("--active", "Show only active users")
20
- .option("-l, --limit <number>", "Limit results", parseInt, 50)
21
- .option("-p, --page <number>", "Page number", parseInt, 1)
22
- .action(async (options) => {
23
- var _a, _b, _c;
24
- try {
25
- const opts = { ...program.opts(), ...options };
26
- spinner.start({ text: "Fetching users...", color: "magenta" });
27
- const params = {
28
- page: opts.page,
29
- limit: opts.limit,
30
- responseFormat: opts.responseFormat,
31
- verbosity: opts.verbosity,
32
- };
33
- if (opts.search)
34
- params.q = opts.search;
35
- if (opts.role)
36
- params.role = opts.role;
37
- if (opts.active)
38
- params.active = "true";
39
- const res = await apiCallHandler("config", "users", "get", null, params);
40
- handleResponseFormatOptions(opts, res);
41
- 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;
42
- spinner.success({ text: `Found ${total} users` });
43
- spinner.stop();
44
- if (opts.save)
45
- await saveFile("users-list", opts, res);
46
- }
47
- catch (e) {
48
- spinner.error({ text: e.message || "Failed to list users" });
49
- process.exit(EXIT_GENERAL_ERROR);
50
- }
51
- });
52
- // ay users get <id>
53
- users
54
- .command("get <id>")
55
- .description("Get user details")
56
- .action(async (id, options) => {
57
- try {
58
- const opts = { ...program.opts(), ...options };
59
- spinner.start({ text: `Fetching user ${id}...`, color: "magenta" });
60
- const res = await apiCallHandler("config", `users/${id}`, "get", null, {
61
- responseFormat: opts.responseFormat,
62
- verbosity: opts.verbosity,
63
- });
64
- handleResponseFormatOptions(opts, res);
65
- spinner.success({ text: `User ${id} loaded` });
66
- spinner.stop();
67
- }
68
- catch (e) {
69
- spinner.error({ text: e.message || "Failed to get user" });
70
- process.exit(EXIT_GENERAL_ERROR);
71
- }
72
- });
73
- // ay users invite --email <email> --role <roleId>
74
- users
75
- .command("invite")
76
- .description("Invite a new user")
77
- .requiredOption("--email <email>", "Email address of the user to invite")
78
- .option("--role <roleId>", "Role ID to assign")
79
- .option("--firstName <name>", "First name")
80
- .option("--lastName <name>", "Last name")
81
- .action(async (options) => {
82
- try {
83
- const opts = { ...program.opts(), ...options };
84
- spinner.start({ text: `Inviting ${opts.email}...`, color: "magenta" });
85
- const body = { email: opts.email };
86
- if (opts.role)
87
- body.role = opts.role;
88
- if (opts.firstName)
89
- body.firstName = opts.firstName;
90
- if (opts.lastName)
91
- body.lastName = opts.lastName;
92
- const res = await apiCallHandler("config", "users", "post", body, {
93
- responseFormat: opts.responseFormat,
94
- });
95
- handleResponseFormatOptions(opts, res);
96
- spinner.success({ text: `Invitation sent to ${opts.email}` });
97
- spinner.stop();
98
- }
99
- catch (e) {
100
- spinner.error({ text: e.message || "Failed to invite user" });
101
- process.exit(EXIT_GENERAL_ERROR);
102
- }
103
- });
104
- // ay users deactivate <id>
105
- users
106
- .command("deactivate <id>")
107
- .description("Deactivate a user account")
108
- .action(async (id, options) => {
109
- try {
110
- const opts = { ...program.opts(), ...options };
111
- if (!opts.force && process.stdin.isTTY) {
112
- const inquirer = (await import("inquirer")).default;
113
- const { confirmed } = await inquirer.prompt([
114
- { type: "confirm", name: "confirmed", message: `Deactivate user ${id}?`, default: false },
115
- ]);
116
- if (!confirmed) {
117
- console.error(chalk.yellow(" Aborted."));
118
- return;
119
- }
120
- }
121
- spinner.start({ text: `Deactivating user ${id}...`, color: "magenta" });
122
- const res = await apiCallHandler("config", "users", "put", { _id: id, active: false }, {
123
- responseFormat: opts.responseFormat,
124
- });
125
- handleResponseFormatOptions(opts, res);
126
- spinner.success({ text: `User ${id} deactivated` });
127
- spinner.stop();
128
- }
129
- catch (e) {
130
- spinner.error({ text: e.message || "Failed to deactivate user" });
131
- process.exit(EXIT_GENERAL_ERROR);
132
- }
133
- });
134
- // ── TEAMS ──────────────────────────────────────────────
135
- const teams = users
136
- .command("teams")
137
- .description("Manage teams");
138
- // ay users teams list
139
- teams
140
- .command("list")
141
- .alias("ls")
142
- .description("List teams")
143
- .option("--search <query>", "Search teams by name")
144
- .option("-l, --limit <number>", "Limit results", parseInt, 50)
145
- .option("-p, --page <number>", "Page number", parseInt, 1)
146
- .action(async (options) => {
147
- var _a, _b, _c;
148
- try {
149
- const opts = { ...program.opts(), ...options };
150
- spinner.start({ text: "Fetching teams...", color: "magenta" });
151
- const params = {
152
- page: opts.page,
153
- limit: opts.limit,
154
- responseFormat: opts.responseFormat,
155
- verbosity: opts.verbosity,
156
- };
157
- if (opts.search)
158
- params.q = opts.search;
159
- const res = await apiCallHandler("config", "teams", "get", null, params);
160
- handleResponseFormatOptions(opts, res);
161
- 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;
162
- spinner.success({ text: `Found ${total} teams` });
163
- spinner.stop();
164
- if (opts.save)
165
- await saveFile("teams-list", opts, res);
166
- }
167
- catch (e) {
168
- spinner.error({ text: e.message || "Failed to list teams" });
169
- process.exit(EXIT_GENERAL_ERROR);
170
- }
171
- });
172
- // ay users teams get <id>
173
- teams
174
- .command("get <id>")
175
- .description("Get team details with members")
176
- .action(async (id, options) => {
177
- try {
178
- const opts = { ...program.opts(), ...options };
179
- spinner.start({ text: `Fetching team ${id}...`, color: "magenta" });
180
- const res = await apiCallHandler("config", `teams/${id}`, "get", null, {
181
- responseFormat: opts.responseFormat,
182
- verbosity: opts.verbosity,
183
- });
184
- handleResponseFormatOptions(opts, res);
185
- spinner.success({ text: `Team ${id} loaded` });
186
- spinner.stop();
187
- }
188
- catch (e) {
189
- spinner.error({ text: e.message || "Failed to get team" });
190
- process.exit(EXIT_GENERAL_ERROR);
191
- }
192
- });
193
- // ay users teams create --body '{...}'
194
- teams
195
- .command("create")
196
- .description("Create a new team")
197
- .option("--name <name>", "Team name")
198
- .option("--body <json>", "Full team definition as JSON")
199
- .action(async (options) => {
200
- try {
201
- const opts = { ...program.opts(), ...options };
202
- let body = null;
203
- if (opts.body) {
204
- try {
205
- body = JSON.parse(opts.body);
206
- }
207
- catch (_a) {
208
- spinner.error({ text: "Invalid JSON in --body" });
209
- process.exit(EXIT_MISUSE);
210
- }
211
- }
212
- else if (opts.name) {
213
- body = { name: opts.name };
214
- }
215
- if (!body) {
216
- spinner.error({ text: "Provide team definition via --name or --body" });
217
- process.exit(EXIT_MISUSE);
218
- }
219
- spinner.start({ text: "Creating team...", color: "magenta" });
220
- const res = await apiCallHandler("config", "teams", "post", body, {
221
- responseFormat: opts.responseFormat,
222
- });
223
- handleResponseFormatOptions(opts, res);
224
- spinner.success({ text: "Team created" });
225
- spinner.stop();
226
- }
227
- catch (e) {
228
- spinner.error({ text: e.message || "Failed to create team" });
229
- process.exit(EXIT_GENERAL_ERROR);
230
- }
231
- });
232
- // ── ROLES ──────────────────────────────────────────────
233
- const roles = users
234
- .command("roles")
235
- .description("Manage roles");
236
- // ay users roles list
237
- roles
238
- .command("list")
239
- .alias("ls")
240
- .description("List available roles")
241
- .option("-l, --limit <number>", "Limit results", parseInt, 50)
242
- .action(async (options) => {
243
- var _a, _b, _c;
244
- try {
245
- const opts = { ...program.opts(), ...options };
246
- spinner.start({ text: "Fetching roles...", color: "magenta" });
247
- const res = await apiCallHandler("config", "roles", "get", null, {
248
- limit: opts.limit,
249
- responseFormat: opts.responseFormat,
250
- verbosity: opts.verbosity,
251
- });
252
- handleResponseFormatOptions(opts, res);
253
- 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;
254
- spinner.success({ text: `Found ${total} roles` });
255
- spinner.stop();
256
- if (opts.save)
257
- await saveFile("roles-list", opts, res);
258
- }
259
- catch (e) {
260
- spinner.error({ text: e.message || "Failed to list roles" });
261
- process.exit(EXIT_GENERAL_ERROR);
262
- }
263
- });
264
- // ay users roles get <id>
265
- roles
266
- .command("get <id>")
267
- .description("Get role details with permissions")
268
- .action(async (id, options) => {
269
- try {
270
- const opts = { ...program.opts(), ...options };
271
- spinner.start({ text: `Fetching role ${id}...`, color: "magenta" });
272
- const res = await apiCallHandler("config", `roles/${id}`, "get", null, {
273
- responseFormat: opts.responseFormat,
274
- verbosity: opts.verbosity,
275
- });
276
- handleResponseFormatOptions(opts, res);
277
- spinner.success({ text: `Role ${id} loaded` });
278
- spinner.stop();
279
- }
280
- catch (e) {
281
- spinner.error({ text: e.message || "Failed to get role" });
282
- process.exit(EXIT_GENERAL_ERROR);
283
- }
284
- });
285
- }
@@ -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
@@ -1,6 +0,0 @@
1
- export const EXIT_SUCCESS = 0;
2
- export const EXIT_GENERAL_ERROR = 1;
3
- export const EXIT_MISUSE = 2;
4
- export const EXIT_AUTH_REQUIRED = 4;
5
- export const EXIT_PERMISSION_DENIED = 5;
6
- export const EXIT_CONFIG_ERROR = 6;
@@ -1,5 +0,0 @@
1
- export const addSpacesToCamelCase = (str) => {
2
- return str
3
- .replace(/([a-z])([A-Z])/g, "$1 $2") // add space between lower & upper case letters
4
- .replace(/^./, (str) => str.toUpperCase()); // capitalize the first letter
5
- };
@@ -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
- }