@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,42 +0,0 @@
1
- import { Argument } from "commander";
2
- import { getModuleFromCollection } from "../models/getModuleFromCollection.js";
3
- import { handleDescribeSingleOperation } from "../operations/handleDescribeSingleOperation.js";
4
- import { localStorage } from "../helpers/localStorage.js";
5
- import { spinner } from "../../index.js";
6
- import { EXIT_GENERAL_ERROR, EXIT_MISUSE } from "../exitCodes.js";
7
- export function createDescribeCommand(program) {
8
- program
9
- .command("describe")
10
- .alias("d")
11
- .description("Show detailed YAML description of an entry")
12
- .addHelpText("after", `
13
- Examples:
14
- ay describe contacts 64a1b2c3d4e5 Describe a contact entry
15
- ay d Describe last used entry`)
16
- .addArgument(new Argument("[collection]", "The collection to use").default(localStorage.getItem("lastCollection"), `The last used collection (${localStorage.getItem("lastCollection")})`))
17
- .addArgument(new Argument("[id]", "The ID of the entry to describe").default(localStorage.getItem("lastId"), `The last used id (${localStorage.getItem("lastId")})`))
18
- .action(async (collection, id, options) => {
19
- try {
20
- if (!collection) {
21
- spinner.error({ text: "Missing required argument: collection. Run a list or get command first, or provide it explicitly." });
22
- process.exit(EXIT_MISUSE);
23
- }
24
- if (!id) {
25
- spinner.error({ text: "Missing required argument: id. Provide an entry ID explicitly." });
26
- process.exit(EXIT_MISUSE);
27
- }
28
- const opts = { ...program.opts(), ...options };
29
- const module = getModuleFromCollection(collection);
30
- localStorage.setItem("lastModule", module.module);
31
- localStorage.setItem("lastCollection", collection);
32
- localStorage.setItem("lastId", id);
33
- await handleDescribeSingleOperation(module.module, collection, id, {
34
- ...opts,
35
- });
36
- }
37
- catch (e) {
38
- spinner.error({ text: e.message || "An unexpected error occurred" });
39
- process.exit(EXIT_GENERAL_ERROR);
40
- }
41
- });
42
- }
@@ -1,43 +0,0 @@
1
- import { Argument } from "commander";
2
- import { getModuleFromCollection } from "../models/getModuleFromCollection.js";
3
- import { handleGetSingleOperation } from "../operations/handleGetSingleOperation.js";
4
- import { handleEditOperation } from "../operations/handleEditOperation.js";
5
- import { localStorage } from "../helpers/localStorage.js";
6
- import { spinner } from "../../index.js";
7
- import { EXIT_GENERAL_ERROR, EXIT_MISUSE } from "../exitCodes.js";
8
- export function createEditCommand(program) {
9
- program
10
- .command("edit")
11
- .alias("e")
12
- .description("Edit an entry by ID in a collection")
13
- .addHelpText("after", `
14
- Examples:
15
- ay edit contacts 64a1b2c3d4e5 Edit contact by ID
16
- ay edit Edit last used entry`)
17
- .addArgument(new Argument("[collection]", "The collection to use").default(localStorage.getItem("lastCollection"), `The last used collection (${localStorage.getItem("lastCollection")})`))
18
- .addArgument(new Argument("[id]", "The ID of the entry to edit").default(localStorage.getItem("lastId"), `The last used id (${localStorage.getItem("lastId")})`))
19
- .action(async (collection, id, options) => {
20
- try {
21
- if (!collection) {
22
- spinner.error({ text: "Missing required argument: collection. Run a list or get command first, or provide it explicitly." });
23
- process.exit(EXIT_MISUSE);
24
- }
25
- if (!id) {
26
- spinner.error({ text: "Missing required argument: id. Provide an entry ID explicitly." });
27
- process.exit(EXIT_MISUSE);
28
- }
29
- const opts = { ...program.opts(), ...options };
30
- const module = getModuleFromCollection(collection);
31
- localStorage.setItem("lastModule", module.module);
32
- localStorage.setItem("lastCollection", collection);
33
- localStorage.setItem("lastId", id);
34
- let result = {};
35
- result = await handleGetSingleOperation(module.module, collection, id, opts);
36
- await handleEditOperation(module.module, collection, result.content);
37
- }
38
- catch (e) {
39
- spinner.error({ text: e.message || "An unexpected error occurred" });
40
- process.exit(EXIT_GENERAL_ERROR);
41
- }
42
- });
43
- }
@@ -1,60 +0,0 @@
1
- import { Option } from "commander";
2
- import { localStorage } from "../helpers/localStorage.js";
3
- import { decodeToken } from "../api/decodeToken.js";
4
- import { customerSocket } from "../socket/customerSocketClient.js";
5
- import { spinner } from "../../index.js";
6
- import yaml from "js-yaml";
7
- import { EXIT_GENERAL_ERROR } from "../exitCodes.js";
8
- export function createEventsCommand(program) {
9
- program
10
- .command("events")
11
- .alias("sub")
12
- .description("Subscribe to filtered events via WebSocket")
13
- .addHelpText("after", `
14
- Examples:
15
- ay events Listen to all events
16
- ay events -c sales -a create Filter by category and action
17
- ay sub -f yaml -c crm Subscribe to CRM events as YAML`)
18
- .addOption(new Option("-f, --format <format>", "Set the output format")
19
- .choices(["json", "yaml", "table"])
20
- .default("json"))
21
- .addOption(new Option("-c, --category <category>", "Set the category to listen").default("*"))
22
- .addOption(new Option("-a, --action <action>", "Set the action to listen").default("*"))
23
- .addOption(new Option("-l, --label <label>", "Set the label to listen").default("*"))
24
- .addOption(new Option("-V, --value <value>", "Set the value to listen").default("*"))
25
- .action(async (options) => {
26
- try {
27
- const tokenPayload = decodeToken(localStorage.getItem("token"));
28
- const user = tokenPayload.payload;
29
- spinner.start({ text: `Starting stream with [${user._customerID}]` });
30
- const socket = customerSocket(user);
31
- spinner.update({ text: "Stream active" });
32
- socket.on("event", (data) => {
33
- if (options.category !== "*" && options.category !== data.category)
34
- return;
35
- if (options.action !== "*" && options.action !== data.action)
36
- return;
37
- if (options.label !== "*" && options.label !== data.label)
38
- return;
39
- if (options.value !== "*" && options.value !== data.value)
40
- return;
41
- spinner.update({
42
- text: `Received [${data.category}.${data.action}.${data.label}.${data.value}]`,
43
- });
44
- if (options.format === "table") {
45
- console.table(data.evt_data);
46
- }
47
- if (options.format === "yaml") {
48
- console.log(yaml.dump(data.evt_data));
49
- }
50
- if (options.format === "json") {
51
- console.log(JSON.stringify(data.evt_data, null, 2));
52
- }
53
- });
54
- }
55
- catch (e) {
56
- spinner.error({ text: e.message || "An unexpected error occurred" });
57
- process.exit(EXIT_GENERAL_ERROR);
58
- }
59
- });
60
- }
@@ -1,182 +0,0 @@
1
- import chalk from "chalk";
2
- import { api } from "../api/apiClient.js";
3
- import { apiCallHandler } from "../api/apiCallHandler.js";
4
- import { handleResponseFormatOptions } from "../helpers/handleResponseFormatOptions.js";
5
- import { saveFile } from "../helpers/saveFile.js";
6
- import { localStorage } from "../helpers/localStorage.js";
7
- import { spinner } from "../../index.js";
8
- import { EXIT_GENERAL_ERROR, EXIT_MISUSE } from "../exitCodes.js";
9
- async function resolveAction(searchTerm) {
10
- // Try exact operationId match first
11
- const res = await apiCallHandler("config", "ayouneapiactions", "get", null, {
12
- q: searchTerm,
13
- limit: 50,
14
- responseFormat: "json",
15
- });
16
- if (!(res === null || res === void 0 ? void 0 : res.payload) || !Array.isArray(res.payload) || res.payload.length === 0) {
17
- return null;
18
- }
19
- const actions = res.payload.filter((a) => !a.deprecated);
20
- // Exact operationId match
21
- const exact = actions.find((a) => a.operationId === searchTerm);
22
- if (exact)
23
- return mapAction(exact);
24
- // Partial operationId match
25
- const partial = actions.find((a) => { var _a; return (_a = a.operationId) === null || _a === void 0 ? void 0 : _a.includes(searchTerm); });
26
- if (partial)
27
- return mapAction(partial);
28
- // If multiple results, return first match
29
- if (actions.length > 0)
30
- return mapAction(actions[0]);
31
- return null;
32
- }
33
- function mapAction(a) {
34
- return {
35
- host: a.host || "",
36
- endpoint: a.endpoint || "",
37
- method: (a.method || "GET").toUpperCase(),
38
- operationId: a.operationId || "",
39
- nameSpace: a.nameSpace || "",
40
- capability: a.capability || "",
41
- params: a.params || [],
42
- query: a.query || [],
43
- description: a.shortDescription || a.description || "",
44
- };
45
- }
46
- function buildUrl(endpoint, paramValues) {
47
- let url = endpoint;
48
- for (const [key, value] of Object.entries(paramValues)) {
49
- url = url.replace(`:${key}`, encodeURIComponent(value));
50
- }
51
- return url;
52
- }
53
- export function createExecCommand(program) {
54
- program
55
- .command("exec <operationId>")
56
- .alias("x")
57
- .description("Execute any registered API action by operationId")
58
- .addHelpText("after", `
59
- Examples:
60
- ay exec ayoune.ai.conversations.create.one --body '{"prompt":"Hello"}'
61
- ay exec ayoune.crm.contacts.list
62
- ay exec ayoune.pm.projects.create.one --body '{"subject":"Migration"}'
63
- ay exec ayoune.ai.prompts.list -r table
64
- ay exec ayoune.sale.orders.get.one --param id=507f1f77bcf86cd799439011`)
65
- .option("--body <json>", "Request body as JSON string")
66
- .option("--body-file <path>", "Read request body from file")
67
- .option("--body-stdin", "Read request body from stdin (for piping)")
68
- .option("--param <kv...>", "Path parameters as key=value pairs")
69
- .option("--query <kv...>", "Query parameters as key=value pairs")
70
- .action(async (operationId, options) => {
71
- try {
72
- const opts = { ...program.opts(), ...options };
73
- spinner.start({ text: `Resolving action: ${operationId}`, color: "magenta" });
74
- const action = await resolveAction(operationId);
75
- if (!action) {
76
- spinner.error({ text: `No API action found for: ${operationId}` });
77
- process.exit(EXIT_MISUSE);
78
- }
79
- spinner.update({ text: `Executing: ${action.method} https://${action.host}${action.endpoint}` });
80
- // Parse path params
81
- const paramValues = {};
82
- if (opts.param) {
83
- for (const p of opts.param) {
84
- const [key, ...rest] = p.split("=");
85
- paramValues[key] = rest.join("=");
86
- }
87
- }
88
- // Parse query params
89
- const queryParams = {
90
- responseFormat: opts.responseFormat,
91
- verbosity: opts.verbosity,
92
- };
93
- if (opts.hideMeta)
94
- queryParams.hideMeta = "true";
95
- if (opts.query) {
96
- for (const q of opts.query) {
97
- const [key, ...rest] = q.split("=");
98
- queryParams[key] = rest.join("=");
99
- }
100
- }
101
- // Parse body
102
- let body = null;
103
- if (opts.body) {
104
- try {
105
- body = JSON.parse(opts.body);
106
- }
107
- catch (_a) {
108
- spinner.error({ text: "Invalid JSON in --body" });
109
- process.exit(EXIT_MISUSE);
110
- }
111
- }
112
- if (opts.bodyFile) {
113
- const fs = await import("fs");
114
- const content = fs.readFileSync(opts.bodyFile, "utf-8");
115
- try {
116
- body = JSON.parse(content);
117
- }
118
- catch (_b) {
119
- spinner.error({ text: `Invalid JSON in file: ${opts.bodyFile}` });
120
- process.exit(EXIT_MISUSE);
121
- }
122
- }
123
- if (opts.bodyStdin && !process.stdin.isTTY) {
124
- const chunks = [];
125
- for await (const chunk of process.stdin) {
126
- chunks.push(chunk);
127
- }
128
- const stdinContent = Buffer.concat(chunks).toString("utf-8").trim();
129
- if (stdinContent) {
130
- try {
131
- body = JSON.parse(stdinContent);
132
- }
133
- catch (_c) {
134
- spinner.error({ text: "Invalid JSON from stdin" });
135
- process.exit(EXIT_MISUSE);
136
- }
137
- }
138
- }
139
- // Build final URL
140
- const url = buildUrl(action.endpoint, paramValues);
141
- const fullUrl = `https://${action.host}${url}`;
142
- // Dry-run support
143
- if (opts.dryRun && action.method !== "GET") {
144
- spinner.stop();
145
- console.error(chalk.yellow.bold("\n [DRY RUN] Request not sent:\n"));
146
- console.error(` ${chalk.dim("Operation:")} ${chalk.cyan(action.operationId)}`);
147
- console.error(` ${chalk.dim("Method:")} ${chalk.cyan(action.method)}`);
148
- console.error(` ${chalk.dim("URL:")} ${chalk.cyan(fullUrl)}`);
149
- if (body) {
150
- console.error(` ${chalk.dim("Body:")} ${JSON.stringify(body, null, 2).split("\n").join("\n ")}`);
151
- }
152
- console.error();
153
- return;
154
- }
155
- // Execute the request directly against the service host
156
- const response = await api({
157
- baseURL: `https://${action.host}`,
158
- method: action.method.toLowerCase(),
159
- url,
160
- data: body,
161
- params: queryParams,
162
- headers: {
163
- Authorization: `Bearer ${localStorage.getItem("token")}`,
164
- },
165
- });
166
- const res = response.data;
167
- const { plainResult, result, content } = handleResponseFormatOptions(opts, res);
168
- const payloadCount = Array.isArray(res === null || res === void 0 ? void 0 : res.payload) ? res.payload.length : 1;
169
- spinner.success({
170
- text: `${action.method} ${action.operationId} — ${payloadCount} result(s)`,
171
- });
172
- spinner.stop();
173
- if (opts.save) {
174
- await saveFile("exec", opts, res);
175
- }
176
- }
177
- catch (e) {
178
- spinner.error({ text: e.message || "Failed to execute API action" });
179
- process.exit(EXIT_GENERAL_ERROR);
180
- }
181
- });
182
- }
@@ -1,219 +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 { spinner } from "../../index.js";
6
- import { EXIT_GENERAL_ERROR } from "../exitCodes.js";
7
- export function createExportCommand(program) {
8
- const exp = program
9
- .command("export")
10
- .alias("exp")
11
- .description("Export data from collections in various formats");
12
- // ay export run <collection>
13
- exp
14
- .command("run <collection>")
15
- .description("Export entries from a collection")
16
- .addHelpText("after", `
17
- Examples:
18
- ay export run contacts --format csv --fields "firstName,lastName,email"
19
- ay export run products --format json --filter "status=active"
20
- ay export run invoices --format csv --filter "createdAt>2025-01-01" --save`)
21
- .option("--format <format>", "Export format (json, csv, yaml)", "csv")
22
- .option("--fields <fields>", "Comma-separated fields to include in export")
23
- .option("--filter <filters>", "Comma-separated key=value filters")
24
- .option("--sort <field>", "Sort by field (prefix with - for descending)", "-createdAt")
25
- .option("-l, --limit <number>", "Limit results (0 = all)", parseInt, 0)
26
- .option("-p, --page <number>", "Page number", parseInt, 1)
27
- .action(async (collection, options) => {
28
- var _a, _b, _c, _d, _e, _f;
29
- try {
30
- const opts = { ...program.opts(), ...options };
31
- const module = getModuleFromCollection(collection);
32
- spinner.start({ text: `Exporting ${collection}...`, color: "magenta" });
33
- const params = {
34
- page: opts.page,
35
- sort: opts.sort,
36
- responseFormat: opts.format,
37
- verbosity: opts.verbosity,
38
- };
39
- if (opts.limit > 0)
40
- params.limit = opts.limit;
41
- if (opts.fields)
42
- params.fields = opts.fields;
43
- // Parse filters
44
- if (opts.filter) {
45
- const filters = opts.filter.split(",");
46
- for (const f of filters) {
47
- const match = f.match(/^(\w+)(!=|>=|<=|>|<|=)(.+)$/);
48
- if (match) {
49
- const [, key, op, value] = match;
50
- if (op === "=")
51
- params[key] = value;
52
- else if (op === "!=")
53
- params[`${key}[ne]`] = value;
54
- else if (op === ">")
55
- params[`${key}[gt]`] = value;
56
- else if (op === "<")
57
- params[`${key}[lt]`] = value;
58
- else if (op === ">=")
59
- params[`${key}[gte]`] = value;
60
- else if (op === "<=")
61
- params[`${key}[lte]`] = value;
62
- }
63
- }
64
- }
65
- // If limit=0, fetch all pages
66
- if (opts.limit === 0) {
67
- params.limit = 500;
68
- const allPayload = [];
69
- let currentPage = 1;
70
- let totalPages = 1;
71
- do {
72
- params.page = currentPage;
73
- const res = await apiCallHandler(module.module, collection.toLowerCase(), "get", null, params);
74
- if (res === null || res === void 0 ? void 0 : res.payload) {
75
- if (Array.isArray(res.payload))
76
- allPayload.push(...res.payload);
77
- else
78
- allPayload.push(res.payload);
79
- }
80
- totalPages = (_c = (_b = (_a = res === null || res === void 0 ? void 0 : res.meta) === null || _a === void 0 ? void 0 : _a.pageInfo) === null || _b === void 0 ? void 0 : _b.totalPages) !== null && _c !== void 0 ? _c : 1;
81
- spinner.update({ text: `Exporting ${collection}... page ${currentPage}/${totalPages}` });
82
- currentPage++;
83
- } while (currentPage <= totalPages);
84
- const fullRes = {
85
- payload: allPayload,
86
- meta: { pageInfo: { totalEntries: allPayload.length, page: 1, totalPages: 1 } },
87
- };
88
- // Force response format to match export format
89
- opts.responseFormat = opts.format;
90
- handleResponseFormatOptions(opts, fullRes);
91
- spinner.success({ text: `Exported ${allPayload.length} entries from ${collection}` });
92
- spinner.stop();
93
- if (opts.save)
94
- await saveFile(`export-${collection}`, opts, fullRes);
95
- }
96
- else {
97
- const res = await apiCallHandler(module.module, collection.toLowerCase(), "get", null, params);
98
- opts.responseFormat = opts.format;
99
- handleResponseFormatOptions(opts, res);
100
- 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;
101
- spinner.success({ text: `Exported ${total} entries from ${collection}` });
102
- spinner.stop();
103
- if (opts.save)
104
- await saveFile(`export-${collection}`, opts, res);
105
- }
106
- }
107
- catch (e) {
108
- spinner.error({ text: e.message || "Export failed" });
109
- process.exit(EXIT_GENERAL_ERROR);
110
- }
111
- });
112
- // ay export list
113
- exp
114
- .command("list")
115
- .alias("ls")
116
- .description("List previous exports")
117
- .option("-l, --limit <number>", "Limit results", parseInt, 25)
118
- .option("-p, --page <number>", "Page number", parseInt, 1)
119
- .action(async (options) => {
120
- var _a, _b, _c;
121
- try {
122
- const opts = { ...program.opts(), ...options };
123
- spinner.start({ text: "Fetching exports...", color: "magenta" });
124
- const res = await apiCallHandler("export", "exports", "get", null, {
125
- page: opts.page,
126
- limit: opts.limit,
127
- responseFormat: opts.responseFormat,
128
- verbosity: opts.verbosity,
129
- });
130
- handleResponseFormatOptions(opts, res);
131
- 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;
132
- spinner.success({ text: `Found ${total} exports` });
133
- spinner.stop();
134
- if (opts.save)
135
- await saveFile("exports-list", opts, res);
136
- }
137
- catch (e) {
138
- spinner.error({ text: e.message || "Failed to list exports" });
139
- process.exit(EXIT_GENERAL_ERROR);
140
- }
141
- });
142
- // ay export get <id>
143
- exp
144
- .command("get <id>")
145
- .description("Get export details and download URL")
146
- .action(async (id, options) => {
147
- try {
148
- const opts = { ...program.opts(), ...options };
149
- spinner.start({ text: `Fetching export ${id}...`, color: "magenta" });
150
- const res = await apiCallHandler("export", `exports/${id}`, "get", null, {
151
- responseFormat: opts.responseFormat,
152
- verbosity: opts.verbosity,
153
- });
154
- handleResponseFormatOptions(opts, res);
155
- spinner.success({ text: `Export ${id} loaded` });
156
- spinner.stop();
157
- }
158
- catch (e) {
159
- spinner.error({ text: e.message || "Failed to get export" });
160
- process.exit(EXIT_GENERAL_ERROR);
161
- }
162
- });
163
- // ay export configs
164
- exp
165
- .command("configs")
166
- .description("List export configurations")
167
- .option("-l, --limit <number>", "Limit results", parseInt, 50)
168
- .action(async (options) => {
169
- var _a, _b, _c;
170
- try {
171
- const opts = { ...program.opts(), ...options };
172
- spinner.start({ text: "Fetching export configs...", color: "magenta" });
173
- const res = await apiCallHandler("export", "exportconfigs", "get", null, {
174
- limit: opts.limit,
175
- responseFormat: opts.responseFormat,
176
- verbosity: opts.verbosity,
177
- });
178
- handleResponseFormatOptions(opts, res);
179
- 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;
180
- spinner.success({ text: `Found ${total} export configurations` });
181
- spinner.stop();
182
- if (opts.save)
183
- await saveFile("export-configs", opts, res);
184
- }
185
- catch (e) {
186
- spinner.error({ text: e.message || "Failed to list export configs" });
187
- process.exit(EXIT_GENERAL_ERROR);
188
- }
189
- });
190
- // ay export logs
191
- exp
192
- .command("logs")
193
- .description("List export logs")
194
- .option("-l, --limit <number>", "Limit results", parseInt, 25)
195
- .option("-p, --page <number>", "Page number", parseInt, 1)
196
- .action(async (options) => {
197
- var _a, _b, _c;
198
- try {
199
- const opts = { ...program.opts(), ...options };
200
- spinner.start({ text: "Fetching export logs...", color: "magenta" });
201
- const res = await apiCallHandler("logs", "export", "get", null, {
202
- page: opts.page,
203
- limit: opts.limit,
204
- responseFormat: opts.responseFormat,
205
- verbosity: opts.verbosity,
206
- });
207
- handleResponseFormatOptions(opts, res);
208
- 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;
209
- spinner.success({ text: `Found ${total} export log entries` });
210
- spinner.stop();
211
- if (opts.save)
212
- await saveFile("export-logs", opts, res);
213
- }
214
- catch (e) {
215
- spinner.error({ text: e.message || "Failed to list export logs" });
216
- process.exit(EXIT_GENERAL_ERROR);
217
- }
218
- });
219
- }
@@ -1,47 +0,0 @@
1
- import { parseInteger } from "../helpers/parseInt.js";
2
- import { promptCollectionWithModule } from "../prompts/promptCollectionWithModule.js";
3
- import { getModuleFromCollection } from "../models/getModuleFromCollection.js";
4
- import { saveFile } from "../helpers/saveFile.js";
5
- import { handleGetOperation } from "../operations/handleGetOperation.js";
6
- import { localStorage } from "../helpers/localStorage.js";
7
- import { spinner } from "../../index.js";
8
- import { EXIT_GENERAL_ERROR, EXIT_MISUSE } from "../exitCodes.js";
9
- export function createGetCommand(program) {
10
- program
11
- .command("get [collection]")
12
- .alias("g")
13
- .description("Retrieve entries from a collection with field selection")
14
- .addHelpText("after", `
15
- Examples:
16
- ay get contacts Get contacts with default fields
17
- ay get products -i name price Get only name and price fields
18
- ay get orders -p 3 -l 10 -r csv Get orders page 3, 10 per page, as CSV`)
19
- .option("-p, --page <number>", "Page", parseInteger, 1)
20
- .option("-l, --limit <number>", "Limit", parseInteger, 20)
21
- .option("-f, --from <date>", "From date")
22
- .option("-i, --fields <fields...>", "Fields to get")
23
- .action(async (collection, options) => {
24
- try {
25
- const opts = { ...program.opts(), ...options };
26
- if (!collection) {
27
- if (!process.stdin.isTTY) {
28
- spinner.error({ text: "Missing required argument: collection" });
29
- process.exit(EXIT_MISUSE);
30
- }
31
- collection = await promptCollectionWithModule();
32
- }
33
- const module = getModuleFromCollection(collection);
34
- localStorage.setItem("lastModule", module.module);
35
- localStorage.setItem("lastCollection", collection);
36
- let result = {};
37
- result = await handleGetOperation(module.module, collection, opts);
38
- if (opts.save) {
39
- await saveFile("get", opts, result);
40
- }
41
- }
42
- catch (e) {
43
- spinner.error({ text: e.message || "An unexpected error occurred" });
44
- process.exit(EXIT_GENERAL_ERROR);
45
- }
46
- });
47
- }