@tolinax/ayoune-cli 2026.2.2 → 2026.2.4

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.
@@ -0,0 +1,285 @@
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
+ }
@@ -0,0 +1,156 @@
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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tolinax/ayoune-cli",
3
- "version": "2026.2.2",
3
+ "version": "2026.2.4",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./index.js",