@tolinax/ayoune-cli 2026.3.0 → 2026.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +160 -158
- package/data/defaultActions.js +0 -9
- package/data/modelsAndRights.js +0 -3189
- package/data/modules.js +0 -111
- package/data/operations.js +0 -5
- package/data/services.js +0 -139
- package/index.js +0 -11
- package/lib/api/apiCallHandler.js +0 -68
- package/lib/api/apiClient.js +0 -100
- package/lib/api/auditCallHandler.js +0 -21
- package/lib/api/decodeToken.js +0 -4
- package/lib/api/handleAPIError.js +0 -59
- package/lib/api/login.js +0 -45
- package/lib/commands/createActionsCommand.js +0 -109
- package/lib/commands/createAiCommand.js +0 -188
- package/lib/commands/createAliasCommand.js +0 -106
- package/lib/commands/createAuditCommand.js +0 -49
- package/lib/commands/createBatchCommand.js +0 -304
- package/lib/commands/createCompletionsCommand.js +0 -169
- package/lib/commands/createConfigCommand.js +0 -208
- package/lib/commands/createCopyCommand.js +0 -39
- package/lib/commands/createCreateCommand.js +0 -50
- package/lib/commands/createDeleteCommand.js +0 -98
- package/lib/commands/createDeployCommand.js +0 -666
- package/lib/commands/createDescribeCommand.js +0 -42
- package/lib/commands/createEditCommand.js +0 -43
- package/lib/commands/createEventsCommand.js +0 -60
- package/lib/commands/createExecCommand.js +0 -182
- package/lib/commands/createExportCommand.js +0 -219
- package/lib/commands/createGetCommand.js +0 -47
- package/lib/commands/createJobsCommand.js +0 -168
- package/lib/commands/createListCommand.js +0 -49
- package/lib/commands/createLoginCommand.js +0 -18
- package/lib/commands/createLogoutCommand.js +0 -21
- package/lib/commands/createModulesCommand.js +0 -150
- package/lib/commands/createMonitorCommand.js +0 -283
- package/lib/commands/createPermissionsCommand.js +0 -241
- package/lib/commands/createProgram.js +0 -185
- package/lib/commands/createSearchCommand.js +0 -101
- package/lib/commands/createServicesCommand.js +0 -228
- package/lib/commands/createStorageCommand.js +0 -54
- package/lib/commands/createStreamCommand.js +0 -50
- package/lib/commands/createSyncCommand.js +0 -177
- package/lib/commands/createTemplateCommand.js +0 -238
- package/lib/commands/createUpdateCommand.js +0 -115
- package/lib/commands/createUsersCommand.js +0 -285
- package/lib/commands/createWebhooksCommand.js +0 -156
- package/lib/commands/createWhoAmICommand.js +0 -88
- package/lib/exitCodes.js +0 -6
- package/lib/helpers/addSpacesToCamelCase.js +0 -5
- package/lib/helpers/config.js +0 -6
- package/lib/helpers/configLoader.js +0 -60
- package/lib/helpers/formatDocument.js +0 -176
- package/lib/helpers/handleResponseFormatOptions.js +0 -85
- package/lib/helpers/initializeSettings.js +0 -14
- package/lib/helpers/localStorage.js +0 -4
- package/lib/helpers/makeRandomToken.js +0 -27
- package/lib/helpers/parseInt.js +0 -7
- package/lib/helpers/requireArg.js +0 -9
- package/lib/helpers/saveFile.js +0 -39
- package/lib/models/getCollections.js +0 -15
- package/lib/models/getModelsInModules.js +0 -13
- package/lib/models/getModuleFromCollection.js +0 -7
- package/lib/operations/handleAuditOperation.js +0 -22
- package/lib/operations/handleCollectionOperation.js +0 -91
- package/lib/operations/handleCopySingleOperation.js +0 -22
- package/lib/operations/handleCreateSingleOperation.js +0 -35
- package/lib/operations/handleDeleteSingleOperation.js +0 -14
- package/lib/operations/handleDescribeSingleOperation.js +0 -22
- package/lib/operations/handleEditOperation.js +0 -51
- package/lib/operations/handleEditRawOperation.js +0 -35
- package/lib/operations/handleGetOperation.js +0 -29
- package/lib/operations/handleGetSingleOperation.js +0 -20
- package/lib/operations/handleListOperation.js +0 -63
- package/lib/operations/handleSingleAuditOperation.js +0 -27
- package/lib/prompts/promptAudits.js +0 -15
- package/lib/prompts/promptCollection.js +0 -13
- package/lib/prompts/promptCollectionInModule.js +0 -13
- package/lib/prompts/promptCollectionWithModule.js +0 -15
- package/lib/prompts/promptConfirm.js +0 -12
- package/lib/prompts/promptDefaultAction.js +0 -13
- package/lib/prompts/promptEntry.js +0 -19
- package/lib/prompts/promptFileName.js +0 -12
- package/lib/prompts/promptFilePath.js +0 -18
- package/lib/prompts/promptModule.js +0 -19
- package/lib/prompts/promptName.js +0 -11
- package/lib/prompts/promptOperation.js +0 -13
- package/lib/socket/customerSocketClient.js +0 -13
- package/lib/socket/socketClient.js +0 -12
- package/lib/types.js +0 -1
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
import { apiCallHandler } from "../api/apiCallHandler.js";
|
|
2
|
-
import { handleResponseFormatOptions } from "../helpers/handleResponseFormatOptions.js";
|
|
3
|
-
import { saveFile } from "../helpers/saveFile.js";
|
|
4
|
-
import { spinner } from "../../index.js";
|
|
5
|
-
import { EXIT_GENERAL_ERROR } from "../exitCodes.js";
|
|
6
|
-
export function createJobsCommand(program) {
|
|
7
|
-
const jobs = program
|
|
8
|
-
.command("jobs")
|
|
9
|
-
.alias("j")
|
|
10
|
-
.description("Manage background jobs, automations, and triggers");
|
|
11
|
-
// ay jobs list
|
|
12
|
-
jobs
|
|
13
|
-
.command("list")
|
|
14
|
-
.alias("ls")
|
|
15
|
-
.description("List scheduled/queued jobs")
|
|
16
|
-
.option("--status <status>", "Filter: active, waiting, completed, failed, delayed")
|
|
17
|
-
.option("-l, --limit <number>", "Limit results", parseInt, 50)
|
|
18
|
-
.option("-p, --page <number>", "Page number", parseInt, 1)
|
|
19
|
-
.action(async (options) => {
|
|
20
|
-
var _a, _b, _c;
|
|
21
|
-
try {
|
|
22
|
-
const opts = { ...program.opts(), ...options };
|
|
23
|
-
spinner.start({ text: "Fetching jobs...", color: "magenta" });
|
|
24
|
-
const params = {
|
|
25
|
-
page: opts.page,
|
|
26
|
-
limit: opts.limit,
|
|
27
|
-
responseFormat: opts.responseFormat,
|
|
28
|
-
verbosity: opts.verbosity,
|
|
29
|
-
};
|
|
30
|
-
if (opts.status)
|
|
31
|
-
params.status = opts.status;
|
|
32
|
-
const res = await apiCallHandler("general", "agendajobs", "get", null, params);
|
|
33
|
-
handleResponseFormatOptions(opts, res);
|
|
34
|
-
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;
|
|
35
|
-
spinner.success({ text: `Found ${total} jobs` });
|
|
36
|
-
spinner.stop();
|
|
37
|
-
if (opts.save)
|
|
38
|
-
await saveFile("jobs-list", opts, res);
|
|
39
|
-
}
|
|
40
|
-
catch (e) {
|
|
41
|
-
spinner.error({ text: e.message || "Failed to list jobs" });
|
|
42
|
-
process.exit(EXIT_GENERAL_ERROR);
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
// ay jobs triggers
|
|
46
|
-
jobs
|
|
47
|
-
.command("triggers")
|
|
48
|
-
.description("List automation triggers")
|
|
49
|
-
.option("-l, --limit <number>", "Limit results", parseInt, 50)
|
|
50
|
-
.option("-p, --page <number>", "Page number", parseInt, 1)
|
|
51
|
-
.action(async (options) => {
|
|
52
|
-
var _a, _b, _c;
|
|
53
|
-
try {
|
|
54
|
-
const opts = { ...program.opts(), ...options };
|
|
55
|
-
spinner.start({ text: "Fetching triggers...", color: "magenta" });
|
|
56
|
-
const res = await apiCallHandler("automation", "triggers", "get", null, {
|
|
57
|
-
page: opts.page,
|
|
58
|
-
limit: opts.limit,
|
|
59
|
-
responseFormat: opts.responseFormat,
|
|
60
|
-
verbosity: opts.verbosity,
|
|
61
|
-
});
|
|
62
|
-
handleResponseFormatOptions(opts, res);
|
|
63
|
-
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;
|
|
64
|
-
spinner.success({ text: `Found ${total} triggers` });
|
|
65
|
-
spinner.stop();
|
|
66
|
-
if (opts.save)
|
|
67
|
-
await saveFile("jobs-triggers", opts, res);
|
|
68
|
-
}
|
|
69
|
-
catch (e) {
|
|
70
|
-
spinner.error({ text: e.message || "Failed to list triggers" });
|
|
71
|
-
process.exit(EXIT_GENERAL_ERROR);
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
// ay jobs automations
|
|
75
|
-
jobs
|
|
76
|
-
.command("automations")
|
|
77
|
-
.alias("auto")
|
|
78
|
-
.description("List automations")
|
|
79
|
-
.option("--active", "Show only active automations")
|
|
80
|
-
.option("-l, --limit <number>", "Limit results", parseInt, 50)
|
|
81
|
-
.option("-p, --page <number>", "Page number", parseInt, 1)
|
|
82
|
-
.action(async (options) => {
|
|
83
|
-
var _a, _b, _c;
|
|
84
|
-
try {
|
|
85
|
-
const opts = { ...program.opts(), ...options };
|
|
86
|
-
spinner.start({ text: "Fetching automations...", color: "magenta" });
|
|
87
|
-
const params = {
|
|
88
|
-
page: opts.page,
|
|
89
|
-
limit: opts.limit,
|
|
90
|
-
responseFormat: opts.responseFormat,
|
|
91
|
-
verbosity: opts.verbosity,
|
|
92
|
-
};
|
|
93
|
-
if (opts.active)
|
|
94
|
-
params.active = "true";
|
|
95
|
-
const res = await apiCallHandler("automation", "automations", "get", null, params);
|
|
96
|
-
handleResponseFormatOptions(opts, res);
|
|
97
|
-
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;
|
|
98
|
-
spinner.success({ text: `Found ${total} automations` });
|
|
99
|
-
spinner.stop();
|
|
100
|
-
if (opts.save)
|
|
101
|
-
await saveFile("jobs-automations", opts, res);
|
|
102
|
-
}
|
|
103
|
-
catch (e) {
|
|
104
|
-
spinner.error({ text: e.message || "Failed to list automations" });
|
|
105
|
-
process.exit(EXIT_GENERAL_ERROR);
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
// ay jobs execute <automationId>
|
|
109
|
-
jobs
|
|
110
|
-
.command("execute <automationId>")
|
|
111
|
-
.alias("run")
|
|
112
|
-
.description("Execute an automation immediately")
|
|
113
|
-
.option("--body <json>", "Optional payload as JSON")
|
|
114
|
-
.action(async (automationId, options) => {
|
|
115
|
-
try {
|
|
116
|
-
const opts = { ...program.opts(), ...options };
|
|
117
|
-
spinner.start({ text: `Executing automation ${automationId}...`, color: "magenta" });
|
|
118
|
-
let body = null;
|
|
119
|
-
if (opts.body) {
|
|
120
|
-
try {
|
|
121
|
-
body = JSON.parse(opts.body);
|
|
122
|
-
}
|
|
123
|
-
catch (_a) {
|
|
124
|
-
spinner.error({ text: "Invalid JSON in --body" });
|
|
125
|
-
process.exit(EXIT_GENERAL_ERROR);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
const res = await apiCallHandler("automation", `automations/${automationId}/execute`, "post", body, { responseFormat: opts.responseFormat });
|
|
129
|
-
handleResponseFormatOptions(opts, res);
|
|
130
|
-
spinner.success({ text: `Automation ${automationId} executed` });
|
|
131
|
-
spinner.stop();
|
|
132
|
-
}
|
|
133
|
-
catch (e) {
|
|
134
|
-
spinner.error({ text: e.message || "Failed to execute automation" });
|
|
135
|
-
process.exit(EXIT_GENERAL_ERROR);
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
// ay jobs notifications
|
|
139
|
-
jobs
|
|
140
|
-
.command("notifications")
|
|
141
|
-
.alias("notify")
|
|
142
|
-
.description("List recent notifications")
|
|
143
|
-
.option("-l, --limit <number>", "Limit results", parseInt, 25)
|
|
144
|
-
.option("-p, --page <number>", "Page number", parseInt, 1)
|
|
145
|
-
.action(async (options) => {
|
|
146
|
-
var _a, _b, _c;
|
|
147
|
-
try {
|
|
148
|
-
const opts = { ...program.opts(), ...options };
|
|
149
|
-
spinner.start({ text: "Fetching notifications...", color: "magenta" });
|
|
150
|
-
const res = await apiCallHandler("general", "notifications", "get", null, {
|
|
151
|
-
page: opts.page,
|
|
152
|
-
limit: opts.limit,
|
|
153
|
-
responseFormat: opts.responseFormat,
|
|
154
|
-
verbosity: opts.verbosity,
|
|
155
|
-
});
|
|
156
|
-
handleResponseFormatOptions(opts, res);
|
|
157
|
-
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;
|
|
158
|
-
spinner.success({ text: `Found ${total} notifications` });
|
|
159
|
-
spinner.stop();
|
|
160
|
-
if (opts.save)
|
|
161
|
-
await saveFile("jobs-notifications", opts, res);
|
|
162
|
-
}
|
|
163
|
-
catch (e) {
|
|
164
|
-
spinner.error({ text: e.message || "Failed to list notifications" });
|
|
165
|
-
process.exit(EXIT_GENERAL_ERROR);
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
}
|
|
@@ -1,49 +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 { handleListOperation } from "../operations/handleListOperation.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
|
-
export function createListCommand(program) {
|
|
10
|
-
program
|
|
11
|
-
.command("list [collection]")
|
|
12
|
-
.alias("l")
|
|
13
|
-
.description("List entries in a collection with pagination support")
|
|
14
|
-
.addHelpText("after", `
|
|
15
|
-
Examples:
|
|
16
|
-
ay list contacts List contacts (page 1, limit 20)
|
|
17
|
-
ay list products -p 2 -l 50 List products page 2, 50 per page
|
|
18
|
-
ay list orders -r yaml -s List orders as YAML and save to file
|
|
19
|
-
ay list contacts --all Fetch all pages
|
|
20
|
-
ay list contacts --jq '[].name' Extract just names using JMESPath`)
|
|
21
|
-
.option("-p, --page <number>", "Page", parseInteger, 1)
|
|
22
|
-
.option("-l, --limit <number>", "Limit", parseInteger, 20)
|
|
23
|
-
.option("-f, --from <date>", "From date")
|
|
24
|
-
.option("-a, --all", "Fetch all pages automatically")
|
|
25
|
-
.action(async (collection, options) => {
|
|
26
|
-
try {
|
|
27
|
-
const opts = { ...program.opts(), ...options };
|
|
28
|
-
if (!collection) {
|
|
29
|
-
if (!process.stdin.isTTY) {
|
|
30
|
-
spinner.error({ text: "Missing required argument: collection" });
|
|
31
|
-
process.exit(EXIT_MISUSE);
|
|
32
|
-
}
|
|
33
|
-
collection = await promptCollectionWithModule();
|
|
34
|
-
}
|
|
35
|
-
const module = getModuleFromCollection(collection);
|
|
36
|
-
localStorage.setItem("lastModule", module.module);
|
|
37
|
-
localStorage.setItem("lastCollection", collection);
|
|
38
|
-
let result = {};
|
|
39
|
-
result = await handleListOperation(module.module, collection, opts);
|
|
40
|
-
if (opts.save) {
|
|
41
|
-
await saveFile("list", opts, result);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
catch (e) {
|
|
45
|
-
spinner.error({ text: e.message || "An unexpected error occurred" });
|
|
46
|
-
process.exit(EXIT_GENERAL_ERROR);
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { login } from "../api/login.js";
|
|
2
|
-
import { spinner } from "../../index.js";
|
|
3
|
-
import { EXIT_AUTH_REQUIRED } from "../exitCodes.js";
|
|
4
|
-
export function createLoginCommand(program) {
|
|
5
|
-
program
|
|
6
|
-
.command("login")
|
|
7
|
-
.alias("auth")
|
|
8
|
-
.description("Authenticate with your aYOUne account via browser")
|
|
9
|
-
.action(async () => {
|
|
10
|
-
try {
|
|
11
|
-
await login();
|
|
12
|
-
}
|
|
13
|
-
catch (e) {
|
|
14
|
-
spinner.error({ text: e.message || "An unexpected error occurred" });
|
|
15
|
-
process.exit(EXIT_AUTH_REQUIRED);
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { localStorage } from "../helpers/localStorage.js";
|
|
2
|
-
import { spinner } from "../../index.js";
|
|
3
|
-
import { EXIT_GENERAL_ERROR } from "../exitCodes.js";
|
|
4
|
-
export function createLogoutCommand(program) {
|
|
5
|
-
program
|
|
6
|
-
.command("logout")
|
|
7
|
-
.alias("signout")
|
|
8
|
-
.description("Clear stored credentials and log out")
|
|
9
|
-
.action(async (options) => {
|
|
10
|
-
try {
|
|
11
|
-
spinner.start({ text: "Clearing credentials" });
|
|
12
|
-
localStorage.removeItem("token");
|
|
13
|
-
localStorage.removeItem("refreshToken");
|
|
14
|
-
spinner.success({ text: "Credentials cleared" });
|
|
15
|
-
}
|
|
16
|
-
catch (e) {
|
|
17
|
-
spinner.error({ text: e.message || "An unexpected error occurred" });
|
|
18
|
-
process.exit(EXIT_GENERAL_ERROR);
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
}
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import { promptModule } from "../prompts/promptModule.js";
|
|
2
|
-
import { promptCollectionInModule } from "../prompts/promptCollectionInModule.js";
|
|
3
|
-
import { promptOperation } from "../prompts/promptOperation.js";
|
|
4
|
-
import { handleListOperation } from "../operations/handleListOperation.js";
|
|
5
|
-
import { promptEntry } from "../prompts/promptEntry.js";
|
|
6
|
-
import { handleCollectionOperation } from "../operations/handleCollectionOperation.js";
|
|
7
|
-
import { localStorage } from "../helpers/localStorage.js";
|
|
8
|
-
import { parseInteger } from "../helpers/parseInt.js";
|
|
9
|
-
import { handleGetOperation } from "../operations/handleGetOperation.js";
|
|
10
|
-
import { handleCreateSingleOperation } from "../operations/handleCreateSingleOperation.js";
|
|
11
|
-
import { handleDeleteSingleOperation } from "../operations/handleDeleteSingleOperation.js";
|
|
12
|
-
import { aYOUneModules } from "../../data/modules.js";
|
|
13
|
-
import { getModelsInModules } from "../models/getModelsInModules.js";
|
|
14
|
-
import { apiCallHandler } from "../api/apiCallHandler.js";
|
|
15
|
-
import { handleResponseFormatOptions } from "../helpers/handleResponseFormatOptions.js";
|
|
16
|
-
import { spinner } from "../../index.js";
|
|
17
|
-
import { EXIT_GENERAL_ERROR, EXIT_MISUSE } from "../exitCodes.js";
|
|
18
|
-
const DIRECT_OPERATIONS = ["list", "get", "create", "delete"];
|
|
19
|
-
function resolveModule(input) {
|
|
20
|
-
const lower = input.toLowerCase();
|
|
21
|
-
const match = aYOUneModules.find((m) => m.module === lower || m.label.toLowerCase() === lower);
|
|
22
|
-
return match ? match.module : null;
|
|
23
|
-
}
|
|
24
|
-
function resolveCollection(module, input) {
|
|
25
|
-
const lower = input.toLowerCase();
|
|
26
|
-
const collections = getModelsInModules(module);
|
|
27
|
-
const match = collections.find((c) => c.value === lower || c.name.toLowerCase() === lower);
|
|
28
|
-
return match ? match.value : null;
|
|
29
|
-
}
|
|
30
|
-
export function createModulesCommand(program) {
|
|
31
|
-
program
|
|
32
|
-
.command("modules [module] [collection] [operation] [subject]")
|
|
33
|
-
.alias("m")
|
|
34
|
-
.description("Browse modules, collections, and entries interactively")
|
|
35
|
-
.addHelpText("after", `
|
|
36
|
-
Examples:
|
|
37
|
-
ay modules Start interactive module browser
|
|
38
|
-
ay m Same using alias
|
|
39
|
-
ay m crm Jump straight to the CRM module
|
|
40
|
-
ay m crm consumers Jump to CRM consumers collection
|
|
41
|
-
ay m pm projects list List all projects
|
|
42
|
-
ay m pm projects create "Migration" Create a new project
|
|
43
|
-
ay m pm projects get <id> Get a project by ID
|
|
44
|
-
ay m pm projects delete <id> Delete a project by ID`)
|
|
45
|
-
.option("-p, --page <number>", "Page", parseInteger, 1)
|
|
46
|
-
.option("-l, --limit <number>", "Limit", parseInteger, 20)
|
|
47
|
-
.option("-f, --from <date>", "From date")
|
|
48
|
-
.option("-a, --all", "Fetch all pages (list only)")
|
|
49
|
-
.option("-q, --search <term>", "Search term")
|
|
50
|
-
.action(async (moduleArg, collectionArg, operationArg, subjectArg, options) => {
|
|
51
|
-
try {
|
|
52
|
-
const opts = { ...program.opts(), ...options };
|
|
53
|
-
// ─── Resolve module ──────────────────────────────────
|
|
54
|
-
let module;
|
|
55
|
-
if (moduleArg) {
|
|
56
|
-
const resolved = resolveModule(moduleArg);
|
|
57
|
-
if (!resolved) {
|
|
58
|
-
spinner.error({ text: `Unknown module: ${moduleArg}` });
|
|
59
|
-
process.exit(EXIT_MISUSE);
|
|
60
|
-
}
|
|
61
|
-
module = resolved;
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
if (!process.stdin.isTTY) {
|
|
65
|
-
spinner.error({ text: "The modules command requires an interactive terminal" });
|
|
66
|
-
process.exit(EXIT_MISUSE);
|
|
67
|
-
}
|
|
68
|
-
module = await promptModule();
|
|
69
|
-
}
|
|
70
|
-
// ─── Resolve collection ──────────────────────────────
|
|
71
|
-
let collection;
|
|
72
|
-
if (collectionArg) {
|
|
73
|
-
const resolved = resolveCollection(module, collectionArg);
|
|
74
|
-
if (!resolved) {
|
|
75
|
-
spinner.error({ text: `Unknown collection: ${collectionArg} in module ${module}` });
|
|
76
|
-
process.exit(EXIT_MISUSE);
|
|
77
|
-
}
|
|
78
|
-
collection = resolved;
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
if (!process.stdin.isTTY) {
|
|
82
|
-
spinner.error({ text: "Missing required argument: collection" });
|
|
83
|
-
process.exit(EXIT_MISUSE);
|
|
84
|
-
}
|
|
85
|
-
collection = await promptCollectionInModule(module);
|
|
86
|
-
}
|
|
87
|
-
localStorage.setItem("lastModule", module);
|
|
88
|
-
localStorage.setItem("lastCollection", collection);
|
|
89
|
-
// ─── Direct operation mode ───────────────────────────
|
|
90
|
-
if (operationArg && DIRECT_OPERATIONS.includes(operationArg.toLowerCase())) {
|
|
91
|
-
const op = operationArg.toLowerCase();
|
|
92
|
-
if (op === "list") {
|
|
93
|
-
const { result } = await handleListOperation(module, collection, opts);
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
if (op === "get") {
|
|
97
|
-
if (!subjectArg) {
|
|
98
|
-
spinner.error({ text: "Missing required argument: id" });
|
|
99
|
-
process.exit(EXIT_MISUSE);
|
|
100
|
-
}
|
|
101
|
-
spinner.start({ text: `Getting ${collection} ${subjectArg}...`, color: "magenta" });
|
|
102
|
-
const res = await apiCallHandler(module, `${collection.toLowerCase()}/${subjectArg}`, "get", null, {
|
|
103
|
-
responseFormat: opts.responseFormat,
|
|
104
|
-
verbosity: opts.verbosity,
|
|
105
|
-
});
|
|
106
|
-
handleResponseFormatOptions(opts, res);
|
|
107
|
-
spinner.success({ text: `Got ${collection} [${subjectArg}]` });
|
|
108
|
-
spinner.stop();
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
if (op === "create") {
|
|
112
|
-
if (!subjectArg) {
|
|
113
|
-
spinner.error({ text: "Missing required argument: name/subject" });
|
|
114
|
-
process.exit(EXIT_MISUSE);
|
|
115
|
-
}
|
|
116
|
-
await handleCreateSingleOperation(module, collection, subjectArg, opts);
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
if (op === "delete") {
|
|
120
|
-
if (!subjectArg) {
|
|
121
|
-
spinner.error({ text: "Missing required argument: id" });
|
|
122
|
-
process.exit(EXIT_MISUSE);
|
|
123
|
-
}
|
|
124
|
-
await handleDeleteSingleOperation(module, collection, subjectArg, opts);
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
// ─── Interactive mode (no operation provided) ────────
|
|
129
|
-
if (!process.stdin.isTTY) {
|
|
130
|
-
spinner.error({ text: "Interactive mode requires a terminal. Use: ay m <module> <collection> <operation> [subject]" });
|
|
131
|
-
process.exit(EXIT_MISUSE);
|
|
132
|
-
}
|
|
133
|
-
const operation = await promptOperation();
|
|
134
|
-
let entry = "";
|
|
135
|
-
if (operation === "list") {
|
|
136
|
-
const { result } = await handleListOperation(module, collection, opts);
|
|
137
|
-
entry = await promptEntry(result);
|
|
138
|
-
}
|
|
139
|
-
if (operation === "get") {
|
|
140
|
-
const { result } = await handleGetOperation(module, collection, opts);
|
|
141
|
-
entry = await promptEntry(result);
|
|
142
|
-
}
|
|
143
|
-
await handleCollectionOperation(module, collection, entry, opts);
|
|
144
|
-
}
|
|
145
|
-
catch (e) {
|
|
146
|
-
spinner.error({ text: e.message || "An unexpected error occurred" });
|
|
147
|
-
process.exit(EXIT_GENERAL_ERROR);
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
}
|