@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.
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 -89
  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,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
- }
@@ -1,185 +0,0 @@
1
- //Defines the main program structure for command line interface
2
- import { Option } from "commander";
3
- import chalk from "chalk";
4
- import path from "path";
5
- import os from "os";
6
- import { spinner } from "../../index.js";
7
- import { createModulesCommand } from "./createModulesCommand.js";
8
- import { createListCommand } from "./createListCommand.js";
9
- import { createGetCommand } from "./createGetCommand.js";
10
- import { createEditCommand } from "./createEditCommand.js";
11
- import { createLoginCommand } from "./createLoginCommand.js";
12
- import { createDescribeCommand } from "./createDescribeCommand.js";
13
- import { createCopyCommand } from "./createCopyCommand.js";
14
- import { createCreateCommand } from "./createCreateCommand.js";
15
- import { createStorageCommand } from "./createStorageCommand.js";
16
- import { createAuditCommand } from "./createAuditCommand.js";
17
- import { createStreamCommand } from "./createStreamCommand.js";
18
- import { createEventsCommand } from "./createEventsCommand.js";
19
- import { createWhoAmICommand } from "./createWhoAmICommand.js";
20
- import { createLogoutCommand } from "./createLogoutCommand.js";
21
- import { createCompletionsCommand } from "./createCompletionsCommand.js";
22
- import { createAliasCommand, registerUserAliases } from "./createAliasCommand.js";
23
- import { createConfigCommand } from "./createConfigCommand.js";
24
- import { createActionsCommand } from "./createActionsCommand.js";
25
- import { createExecCommand } from "./createExecCommand.js";
26
- import { createAiCommand } from "./createAiCommand.js";
27
- import { enableDebug } from "../api/apiClient.js";
28
- import { enableDryRun } from "../api/apiCallHandler.js";
29
- import { enableJsonErrors } from "../api/handleAPIError.js";
30
- import { createServicesCommand } from "./createServicesCommand.js";
31
- import { createDeployCommand } from "./createDeployCommand.js";
32
- import { createMonitorCommand } from "./createMonitorCommand.js";
33
- import { createDeleteCommand } from "./createDeleteCommand.js";
34
- import { createUpdateCommand } from "./createUpdateCommand.js";
35
- import { createBatchCommand } from "./createBatchCommand.js";
36
- import { createSearchCommand } from "./createSearchCommand.js";
37
- import { createWebhooksCommand } from "./createWebhooksCommand.js";
38
- import { createJobsCommand } from "./createJobsCommand.js";
39
- import { createExportCommand } from "./createExportCommand.js";
40
- import { createUsersCommand } from "./createUsersCommand.js";
41
- import { createSyncCommand } from "./createSyncCommand.js";
42
- import { createPermissionsCommand } from "./createPermissionsCommand.js";
43
- import { createTemplateCommand } from "./createTemplateCommand.js";
44
- import { localStorage } from "../helpers/localStorage.js";
45
- import { login } from "../api/login.js";
46
- import { loadConfig } from "../helpers/configLoader.js";
47
- export function createProgram(program) {
48
- program
49
- .version("2024.8.0")
50
- .addOption(new Option("-r, --responseFormat <format>", "Set the output format")
51
- .choices(["json", "csv", "yaml", "table"])
52
- .default("json"))
53
- .addOption(new Option("-v, --verbosity <level>", "Set the verbosity level of the returned meta information")
54
- .choices(["default", "extended", "minimal"])
55
- .default("default")
56
- .conflicts("hideMeta"))
57
- .addOption(new Option("-m, --hideMeta", "Returns only the payload without meta information. ")
58
- .default(false)
59
- .conflicts("verbosity"))
60
- .addOption(new Option("-s, --save", "Saves the response as file"))
61
- .addOption(new Option("-d, --debug", "Show detailed request/response information"))
62
- .addOption(new Option("-o, --outPath [filePath]", "Lets you set a path").default(path.join(os.homedir(), "aYOUne")))
63
- .addOption(new Option("-n, --name [fileName]", "Lets you set a filename"))
64
- .addOption(new Option("-q, --quiet", "Suppress all output except errors and results"))
65
- .addOption(new Option("--force", "Skip confirmation prompts for destructive actions"))
66
- .addOption(new Option("--dry-run", "Preview what a command would do without executing"))
67
- .addOption(new Option("--jq <expression>", "Filter JSON output using JMESPath expression"))
68
- .addOption(new Option("--columns <fields>", "Comma-separated list of columns to display"))
69
- .addOption(new Option("--no-color", "Disable colored output"))
70
- .addOption(new Option("--json-errors", "Output errors as JSON to stderr (for AI agents/scripts)"))
71
- .description("aYOUne - Business as a Service Command Line Interface");
72
- program.showHelpAfterError();
73
- program.showSuggestionAfterError(true);
74
- createModulesCommand(program);
75
- createListCommand(program);
76
- createGetCommand(program);
77
- createEditCommand(program);
78
- createCopyCommand(program);
79
- createDescribeCommand(program);
80
- createCreateCommand(program);
81
- createStorageCommand(program);
82
- createAuditCommand(program);
83
- createStreamCommand(program);
84
- createEventsCommand(program);
85
- createWhoAmICommand(program);
86
- createLogoutCommand(program);
87
- createActionsCommand(program);
88
- createExecCommand(program);
89
- createAiCommand(program);
90
- createServicesCommand(program);
91
- createDeployCommand(program);
92
- createMonitorCommand(program);
93
- createDeleteCommand(program);
94
- createUpdateCommand(program);
95
- createBatchCommand(program);
96
- createSearchCommand(program);
97
- createWebhooksCommand(program);
98
- createJobsCommand(program);
99
- createExportCommand(program);
100
- createUsersCommand(program);
101
- createSyncCommand(program);
102
- createPermissionsCommand(program);
103
- createTemplateCommand(program);
104
- createCompletionsCommand(program);
105
- createAliasCommand(program);
106
- createConfigCommand(program);
107
- registerUserAliases(program);
108
- createLoginCommand(program);
109
- program.addHelpText("beforeAll", `
110
- __ ______ _ _
111
- \\ \\ / / __ \\| | | |
112
- __ \\ \\_/ / | | | | | |_ __ ___
113
- / _\` \\ /| | | | | | | '_ \\ / _ \\
114
- | (_| || | | |__| | |__| | | | | __/
115
- \\__,_||_| \\____/ \\____/|_| |_|\\___|
116
- `);
117
- program.configureHelp({
118
- sortOptions: true,
119
- sortSubcommands: true,
120
- showGlobalOptions: true,
121
- });
122
- // Respect NO_COLOR env var (no-color.org standard)
123
- if (process.env.NO_COLOR !== undefined) {
124
- chalk.level = 0;
125
- }
126
- program.hook("preAction", async (thisCommand) => {
127
- var _a;
128
- // Apply saved defaults — only when the user didn't pass the flag explicitly
129
- const config = loadConfig();
130
- const defaults = (_a = config.defaults) !== null && _a !== void 0 ? _a : {};
131
- const rawArgs = process.argv.slice(2);
132
- if (defaults.responseFormat && !rawArgs.some(a => ["-r", "--responseFormat"].includes(a)))
133
- program.setOptionValue("responseFormat", defaults.responseFormat);
134
- if (defaults.verbosity && !rawArgs.some(a => ["-v", "--verbosity"].includes(a)))
135
- program.setOptionValue("verbosity", defaults.verbosity);
136
- if (defaults.outPath && !rawArgs.some(a => ["-o", "--outPath"].includes(a)))
137
- program.setOptionValue("outPath", defaults.outPath);
138
- if (defaults.hideMeta && !rawArgs.some(a => ["-m", "--hideMeta"].includes(a)))
139
- program.setOptionValue("hideMeta", defaults.hideMeta);
140
- if (defaults.quiet && !rawArgs.some(a => ["-q", "--quiet"].includes(a)))
141
- program.setOptionValue("quiet", defaults.quiet);
142
- if (defaults.force && !rawArgs.some(a => ["--force"].includes(a)))
143
- program.setOptionValue("force", defaults.force);
144
- if (defaults.dryRun && !rawArgs.some(a => ["--dry-run"].includes(a)))
145
- program.setOptionValue("dryRun", defaults.dryRun);
146
- const opts = program.opts();
147
- if (opts.color === false) {
148
- chalk.level = 0;
149
- }
150
- if (opts.debug) {
151
- enableDebug();
152
- }
153
- if (opts.dryRun) {
154
- enableDryRun();
155
- }
156
- if (opts.jsonErrors) {
157
- enableJsonErrors();
158
- }
159
- if (opts.quiet) {
160
- spinner.start = () => spinner;
161
- spinner.update = () => spinner;
162
- spinner.success = () => spinner;
163
- spinner.stop = () => spinner;
164
- // spinner.error left intact
165
- }
166
- // Token from env var (headless/AI agent mode) — takes precedence over stored token
167
- const envToken = process.env.AYOUNE_TOKEN;
168
- if (envToken && !localStorage.getItem("token")) {
169
- localStorage.setItem("token", envToken);
170
- }
171
- // First-run onboarding: auto-login if no token stored
172
- const cmdName = thisCommand.name();
173
- const skipAuth = ["login", "logout", "whoami", "completions", "alias", "config", "help"];
174
- if (!skipAuth.includes(cmdName) && process.stdin.isTTY) {
175
- const token = localStorage.getItem("token");
176
- if (!token) {
177
- console.error(chalk.cyan.bold("\n Welcome to aYOUne CLI!\n"));
178
- console.error(chalk.dim(" You need to authenticate before using this command.\n"));
179
- await login();
180
- }
181
- }
182
- });
183
- //Parse command line arguments
184
- program.parse(process.argv);
185
- }
@@ -1,101 +0,0 @@
1
- import { getModuleFromCollection } from "../models/getModuleFromCollection.js";
2
- import { apiCallHandler } from "../api/apiCallHandler.js";
3
- import { handleResponseFormatOptions } from "../helpers/handleResponseFormatOptions.js";
4
- import { saveFile } from "../helpers/saveFile.js";
5
- import { localStorage } from "../helpers/localStorage.js";
6
- import { spinner } from "../../index.js";
7
- import { EXIT_GENERAL_ERROR } from "../exitCodes.js";
8
- export function createSearchCommand(program) {
9
- program
10
- .command("search <collection> [query]")
11
- .alias("find")
12
- .description("Search entries in a collection with advanced filtering")
13
- .addHelpText("after", `
14
- Examples:
15
- ay search contacts "John" Full-text search
16
- ay search contacts --filter "status=active" Filter by field
17
- ay search products --filter "price>100" Comparison filter
18
- ay search orders --filter "status=paid" --sort "-createdAt"
19
- ay search leads --filter "source=website,stage=qualified" --fields "name,email,stage"
20
- ay find invoices --filter "total>500" --count Just count matches`)
21
- .option("--filter <filters>", "Comma-separated key=value filters (supports =, !=, >, <, >=, <=)")
22
- .option("--fields <fields>", "Comma-separated fields to return (projection)")
23
- .option("--sort <field>", "Sort by field (prefix with - for descending)", "-createdAt")
24
- .option("--count", "Only return count of matching entries", false)
25
- .option("-l, --limit <number>", "Limit results", parseInt, 25)
26
- .option("-p, --page <number>", "Page number", parseInt, 1)
27
- .action(async (collection, query, options) => {
28
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
29
- try {
30
- const opts = { ...program.opts(), ...options };
31
- const module = getModuleFromCollection(collection);
32
- spinner.start({ text: `Searching ${collection}...`, color: "magenta" });
33
- const params = {
34
- page: opts.page,
35
- limit: opts.limit,
36
- sort: opts.sort,
37
- responseFormat: opts.responseFormat,
38
- verbosity: opts.verbosity,
39
- hideMeta: opts.hideMeta,
40
- };
41
- if (query) {
42
- params.q = query;
43
- }
44
- if (opts.fields) {
45
- params.fields = opts.fields;
46
- }
47
- // Parse filters into query params
48
- if (opts.filter) {
49
- const filters = opts.filter.split(",");
50
- for (const f of filters) {
51
- const match = f.match(/^(\w+)(!=|>=|<=|>|<|=)(.+)$/);
52
- if (match) {
53
- const [, key, op, value] = match;
54
- if (op === "=") {
55
- params[key] = value;
56
- }
57
- else if (op === "!=") {
58
- params[`${key}[ne]`] = value;
59
- }
60
- else if (op === ">") {
61
- params[`${key}[gt]`] = value;
62
- }
63
- else if (op === "<") {
64
- params[`${key}[lt]`] = value;
65
- }
66
- else if (op === ">=") {
67
- params[`${key}[gte]`] = value;
68
- }
69
- else if (op === "<=") {
70
- params[`${key}[lte]`] = value;
71
- }
72
- }
73
- }
74
- }
75
- const res = await apiCallHandler(module.module, collection.toLowerCase(), "get", null, params);
76
- if (opts.count) {
77
- 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;
78
- spinner.success({ text: `${total} matching entries in ${collection}` });
79
- spinner.stop();
80
- console.log(total);
81
- return;
82
- }
83
- handleResponseFormatOptions(opts, res);
84
- const total = (_f = (_e = (_d = res.meta) === null || _d === void 0 ? void 0 : _d.pageInfo) === null || _e === void 0 ? void 0 : _e.totalEntries) !== null && _f !== void 0 ? _f : 0;
85
- const page = (_j = (_h = (_g = res.meta) === null || _g === void 0 ? void 0 : _g.pageInfo) === null || _h === void 0 ? void 0 : _h.page) !== null && _j !== void 0 ? _j : 1;
86
- const totalPages = (_m = (_l = (_k = res.meta) === null || _k === void 0 ? void 0 : _k.pageInfo) === null || _l === void 0 ? void 0 : _l.totalPages) !== null && _m !== void 0 ? _m : 1;
87
- spinner.success({
88
- text: `Found ${total} entries in ${collection} (page ${page}/${totalPages})`,
89
- });
90
- spinner.stop();
91
- localStorage.setItem("lastModule", module.module);
92
- localStorage.setItem("lastCollection", collection);
93
- if (opts.save)
94
- await saveFile("search", opts, res);
95
- }
96
- catch (e) {
97
- spinner.error({ text: e.message || "Search failed" });
98
- process.exit(EXIT_GENERAL_ERROR);
99
- }
100
- });
101
- }