@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.
- 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 -89
- 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,228 +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
|
-
import { aYOUneModules } from "../../data/modules.js";
|
|
7
|
-
import { aYOUneServices } from "../../data/services.js";
|
|
8
|
-
function buildServiceRegistry() {
|
|
9
|
-
const services = [];
|
|
10
|
-
// APIs from modules
|
|
11
|
-
for (const m of aYOUneModules) {
|
|
12
|
-
services.push({
|
|
13
|
-
name: m.label,
|
|
14
|
-
type: "api",
|
|
15
|
-
module: m.module,
|
|
16
|
-
host: m.host,
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
// Services
|
|
20
|
-
for (const s of aYOUneServices) {
|
|
21
|
-
services.push({
|
|
22
|
-
name: s.label,
|
|
23
|
-
type: "service",
|
|
24
|
-
module: s.module,
|
|
25
|
-
host: s.host,
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
return services;
|
|
29
|
-
}
|
|
30
|
-
export function createServicesCommand(program) {
|
|
31
|
-
const svc = program
|
|
32
|
-
.command("services")
|
|
33
|
-
.alias("svc")
|
|
34
|
-
.description("Discover and manage aYOUne platform services");
|
|
35
|
-
// ay services list
|
|
36
|
-
svc
|
|
37
|
-
.command("list")
|
|
38
|
-
.alias("ls")
|
|
39
|
-
.description("List all registered services, APIs, and gateways")
|
|
40
|
-
.option("--type <type>", "Filter by type: api, service, gateway, worker")
|
|
41
|
-
.option("--module <module>", "Filter by module name")
|
|
42
|
-
.action(async (options) => {
|
|
43
|
-
try {
|
|
44
|
-
const opts = { ...program.opts(), ...options };
|
|
45
|
-
spinner.start({ text: "Loading service registry...", color: "magenta" });
|
|
46
|
-
let services = buildServiceRegistry();
|
|
47
|
-
if (opts.type) {
|
|
48
|
-
services = services.filter((s) => s.type === opts.type);
|
|
49
|
-
}
|
|
50
|
-
if (opts.module) {
|
|
51
|
-
services = services.filter((s) => s.module === opts.module);
|
|
52
|
-
}
|
|
53
|
-
const res = {
|
|
54
|
-
payload: services,
|
|
55
|
-
meta: { responseTime: 0, pageInfo: { totalEntries: services.length, page: 1, totalPages: 1 } },
|
|
56
|
-
};
|
|
57
|
-
handleResponseFormatOptions(opts, res);
|
|
58
|
-
spinner.success({ text: `Found ${services.length} services` });
|
|
59
|
-
spinner.stop();
|
|
60
|
-
if (opts.save)
|
|
61
|
-
await saveFile("services-list", opts, res);
|
|
62
|
-
}
|
|
63
|
-
catch (e) {
|
|
64
|
-
spinner.error({ text: e.message || "Failed to list services" });
|
|
65
|
-
process.exit(EXIT_GENERAL_ERROR);
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
// ay services endpoints <host>
|
|
69
|
-
svc
|
|
70
|
-
.command("endpoints <host>")
|
|
71
|
-
.alias("ep")
|
|
72
|
-
.description("List API endpoints for a service host")
|
|
73
|
-
.addHelpText("after", `
|
|
74
|
-
Examples:
|
|
75
|
-
ay services endpoints ai.ayoune.app
|
|
76
|
-
ay services endpoints crm-api.ayoune.app -r table`)
|
|
77
|
-
.action(async (host, options) => {
|
|
78
|
-
try {
|
|
79
|
-
const opts = { ...program.opts(), ...options };
|
|
80
|
-
spinner.start({ text: `Fetching endpoints for ${host}...`, color: "magenta" });
|
|
81
|
-
const res = await apiCallHandler("config", "ayouneapiactions", "get", null, {
|
|
82
|
-
limit: 500,
|
|
83
|
-
responseFormat: "json",
|
|
84
|
-
});
|
|
85
|
-
if (!(res === null || res === void 0 ? void 0 : res.payload)) {
|
|
86
|
-
spinner.error({ text: "No API actions found" });
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
const endpoints = (Array.isArray(res.payload) ? res.payload : [])
|
|
90
|
-
.filter((a) => {
|
|
91
|
-
const h = a.host || "";
|
|
92
|
-
return h.includes(host) && !a.deprecated;
|
|
93
|
-
})
|
|
94
|
-
.map((a) => ({
|
|
95
|
-
method: (a.method || "GET").toUpperCase(),
|
|
96
|
-
endpoint: a.endpoint || "",
|
|
97
|
-
operationId: a.operationId || "",
|
|
98
|
-
action: a.action || "",
|
|
99
|
-
description: a.shortDescription || a.description || "",
|
|
100
|
-
}))
|
|
101
|
-
.sort((a, b) => a.endpoint.localeCompare(b.endpoint));
|
|
102
|
-
const formattedRes = {
|
|
103
|
-
payload: endpoints,
|
|
104
|
-
meta: { responseTime: 0, pageInfo: { totalEntries: endpoints.length, page: 1, totalPages: 1 } },
|
|
105
|
-
};
|
|
106
|
-
handleResponseFormatOptions(opts, formattedRes);
|
|
107
|
-
spinner.success({ text: `Found ${endpoints.length} endpoints on ${host}` });
|
|
108
|
-
spinner.stop();
|
|
109
|
-
if (opts.save)
|
|
110
|
-
await saveFile("service-endpoints", opts, formattedRes);
|
|
111
|
-
}
|
|
112
|
-
catch (e) {
|
|
113
|
-
spinner.error({ text: e.message || "Failed to fetch endpoints" });
|
|
114
|
-
process.exit(EXIT_GENERAL_ERROR);
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
// ay services health [host]
|
|
118
|
-
svc
|
|
119
|
-
.command("health [host]")
|
|
120
|
-
.description("Check health of a service or all services")
|
|
121
|
-
.option("--timeout <ms>", "Request timeout in ms", parseInt, 5000)
|
|
122
|
-
.action(async (host, options) => {
|
|
123
|
-
try {
|
|
124
|
-
const opts = { ...program.opts(), ...options };
|
|
125
|
-
const targets = host
|
|
126
|
-
? [{ name: host, host }]
|
|
127
|
-
: buildServiceRegistry().map((s) => ({ name: s.name, host: s.host }));
|
|
128
|
-
// Deduplicate by host
|
|
129
|
-
const uniqueTargets = [...new Map(targets.map((t) => [t.host, t])).values()];
|
|
130
|
-
spinner.start({ text: `Checking ${uniqueTargets.length} service(s)...`, color: "magenta" });
|
|
131
|
-
const { default: axios } = await import("axios");
|
|
132
|
-
const https = await import("https");
|
|
133
|
-
const agent = new https.Agent({ rejectUnauthorized: false });
|
|
134
|
-
const results = await Promise.allSettled(uniqueTargets.map(async (t) => {
|
|
135
|
-
const start = Date.now();
|
|
136
|
-
try {
|
|
137
|
-
const resp = await axios.get(`https://${t.host}/`, {
|
|
138
|
-
timeout: opts.timeout,
|
|
139
|
-
httpsAgent: agent,
|
|
140
|
-
validateStatus: () => true,
|
|
141
|
-
});
|
|
142
|
-
return {
|
|
143
|
-
host: t.host,
|
|
144
|
-
name: t.name,
|
|
145
|
-
status: resp.status < 500 ? "healthy" : "unhealthy",
|
|
146
|
-
statusCode: resp.status,
|
|
147
|
-
responseTime: Date.now() - start,
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
catch (e) {
|
|
151
|
-
return {
|
|
152
|
-
host: t.host,
|
|
153
|
-
name: t.name,
|
|
154
|
-
status: "unreachable",
|
|
155
|
-
statusCode: 0,
|
|
156
|
-
responseTime: Date.now() - start,
|
|
157
|
-
error: e.code || e.message,
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
}));
|
|
161
|
-
const payload = results.map((r) => (r.status === "fulfilled" ? r.value : { status: "error" }));
|
|
162
|
-
const healthy = payload.filter((p) => p.status === "healthy").length;
|
|
163
|
-
const res = {
|
|
164
|
-
payload,
|
|
165
|
-
meta: {
|
|
166
|
-
responseTime: 0,
|
|
167
|
-
pageInfo: { totalEntries: payload.length, page: 1, totalPages: 1 },
|
|
168
|
-
},
|
|
169
|
-
};
|
|
170
|
-
handleResponseFormatOptions(opts, res);
|
|
171
|
-
spinner.success({ text: `${healthy}/${uniqueTargets.length} services healthy` });
|
|
172
|
-
spinner.stop();
|
|
173
|
-
if (opts.save)
|
|
174
|
-
await saveFile("services-health", opts, res);
|
|
175
|
-
}
|
|
176
|
-
catch (e) {
|
|
177
|
-
spinner.error({ text: e.message || "Health check failed" });
|
|
178
|
-
process.exit(EXIT_GENERAL_ERROR);
|
|
179
|
-
}
|
|
180
|
-
});
|
|
181
|
-
// ay services describe <module>
|
|
182
|
-
svc
|
|
183
|
-
.command("describe <module>")
|
|
184
|
-
.alias("desc")
|
|
185
|
-
.description("Show detailed info about a module/service")
|
|
186
|
-
.action(async (moduleName, options) => {
|
|
187
|
-
try {
|
|
188
|
-
const opts = { ...program.opts(), ...options };
|
|
189
|
-
spinner.start({ text: `Describing ${moduleName}...`, color: "magenta" });
|
|
190
|
-
// Find matching entries
|
|
191
|
-
const apis = aYOUneModules.filter((m) => m.module === moduleName);
|
|
192
|
-
const svcs = aYOUneServices.filter((s) => s.module === moduleName);
|
|
193
|
-
// Fetch endpoint count from apiactions
|
|
194
|
-
const res = await apiCallHandler("config", "ayouneapiactions", "get", null, {
|
|
195
|
-
limit: 500,
|
|
196
|
-
responseFormat: "json",
|
|
197
|
-
});
|
|
198
|
-
const allActions = Array.isArray(res === null || res === void 0 ? void 0 : res.payload) ? res.payload : [];
|
|
199
|
-
const moduleActions = allActions.filter((a) => a.nameSpace === moduleName && !a.deprecated);
|
|
200
|
-
const methods = {};
|
|
201
|
-
for (const a of moduleActions) {
|
|
202
|
-
const m = (a.method || "GET").toUpperCase();
|
|
203
|
-
methods[m] = (methods[m] || 0) + 1;
|
|
204
|
-
}
|
|
205
|
-
const description = {
|
|
206
|
-
module: moduleName,
|
|
207
|
-
apis: apis.map((a) => ({ label: a.label, host: a.host })),
|
|
208
|
-
services: svcs.map((s) => ({ label: s.label, host: s.host })),
|
|
209
|
-
endpoints: {
|
|
210
|
-
total: moduleActions.length,
|
|
211
|
-
byMethod: methods,
|
|
212
|
-
},
|
|
213
|
-
capabilities: [...new Set(moduleActions.map((a) => a.capability).filter(Boolean))].sort(),
|
|
214
|
-
};
|
|
215
|
-
const formattedRes = {
|
|
216
|
-
payload: description,
|
|
217
|
-
meta: { responseTime: 0 },
|
|
218
|
-
};
|
|
219
|
-
handleResponseFormatOptions(opts, formattedRes);
|
|
220
|
-
spinner.success({ text: `Module: ${moduleName} — ${moduleActions.length} endpoints` });
|
|
221
|
-
spinner.stop();
|
|
222
|
-
}
|
|
223
|
-
catch (e) {
|
|
224
|
-
spinner.error({ text: e.message || "Failed to describe service" });
|
|
225
|
-
process.exit(EXIT_GENERAL_ERROR);
|
|
226
|
-
}
|
|
227
|
-
});
|
|
228
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import chalk from "chalk";
|
|
2
|
-
import { localStorage } from "../helpers/localStorage.js";
|
|
3
|
-
import { loadConfig } from "../helpers/configLoader.js";
|
|
4
|
-
import { spinner } from "../../index.js";
|
|
5
|
-
import { EXIT_GENERAL_ERROR } from "../exitCodes.js";
|
|
6
|
-
const REDACT_KEYS = new Set(["token", "refreshToken"]);
|
|
7
|
-
function redact(value) {
|
|
8
|
-
if (value.length <= 8)
|
|
9
|
-
return "••••";
|
|
10
|
-
return value.slice(0, 4) + "••••" + value.slice(-4);
|
|
11
|
-
}
|
|
12
|
-
export function createStorageCommand(program) {
|
|
13
|
-
program
|
|
14
|
-
.command("storage")
|
|
15
|
-
.alias("s")
|
|
16
|
-
.description("Display stored session data and preferences")
|
|
17
|
-
.action(async () => {
|
|
18
|
-
var _a, _b;
|
|
19
|
-
try {
|
|
20
|
-
const storage = {};
|
|
21
|
-
for (let i = 0; i < localStorage.length; i++) {
|
|
22
|
-
const key = localStorage.key(i);
|
|
23
|
-
if (key) {
|
|
24
|
-
const value = (_a = localStorage.getItem(key)) !== null && _a !== void 0 ? _a : "";
|
|
25
|
-
storage[key] = REDACT_KEYS.has(key) ? redact(value) : value;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
console.log();
|
|
29
|
-
console.log(chalk.bold(" Session Storage"));
|
|
30
|
-
console.log(chalk.dim(` ${"─".repeat(44)}`));
|
|
31
|
-
const maxKey = Math.max(...Object.keys(storage).map((k) => k.length), 0);
|
|
32
|
-
for (const [key, value] of Object.entries(storage)) {
|
|
33
|
-
console.log(` ${chalk.dim(key.padEnd(maxKey + 2))} ${chalk.white(value)}`);
|
|
34
|
-
}
|
|
35
|
-
const config = loadConfig();
|
|
36
|
-
const defaults = (_b = config.defaults) !== null && _b !== void 0 ? _b : {};
|
|
37
|
-
const defaultEntries = Object.entries(defaults).filter(([, v]) => v !== undefined && v !== null);
|
|
38
|
-
if (defaultEntries.length > 0) {
|
|
39
|
-
console.log();
|
|
40
|
-
console.log(chalk.bold(" Config Defaults"));
|
|
41
|
-
console.log(chalk.dim(` ${"─".repeat(44)}`));
|
|
42
|
-
const maxDefault = Math.max(...defaultEntries.map(([k]) => k.length));
|
|
43
|
-
for (const [key, value] of defaultEntries) {
|
|
44
|
-
console.log(` ${chalk.dim(key.padEnd(maxDefault + 2))} ${chalk.white(String(value))}`);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
console.log();
|
|
48
|
-
}
|
|
49
|
-
catch (e) {
|
|
50
|
-
spinner.error({ text: e.message || "An unexpected error occurred" });
|
|
51
|
-
process.exit(EXIT_GENERAL_ERROR);
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
}
|
|
@@ -1,50 +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 createStreamCommand(program) {
|
|
9
|
-
program
|
|
10
|
-
.command("stream")
|
|
11
|
-
.alias("listen")
|
|
12
|
-
.description("Subscribe to real-time data changes via WebSocket")
|
|
13
|
-
.addHelpText("after", `
|
|
14
|
-
Examples:
|
|
15
|
-
ay stream Stream all data changes as JSON
|
|
16
|
-
ay stream -f yaml Stream changes in YAML format
|
|
17
|
-
ay listen -l minimal Stream with minimal detail`)
|
|
18
|
-
.addOption(new Option("-f, --format <format>", "Set the output format")
|
|
19
|
-
.choices(["json", "yaml", "table"])
|
|
20
|
-
.default("json"))
|
|
21
|
-
.addOption(new Option("-l, --level <level>", "Set the detail level")
|
|
22
|
-
.choices(["default", "minimal", "extended"])
|
|
23
|
-
.default("default"))
|
|
24
|
-
.action(async (options) => {
|
|
25
|
-
try {
|
|
26
|
-
const tokenPayload = decodeToken(localStorage.getItem("token"));
|
|
27
|
-
const user = tokenPayload.payload;
|
|
28
|
-
console.log(`Starting stream with [${user._customerID}]`);
|
|
29
|
-
spinner.start({ text: `Starting stream with [${user._customerID}]` });
|
|
30
|
-
const socket = customerSocket(user);
|
|
31
|
-
spinner.update({ text: "Stream active" });
|
|
32
|
-
socket.onAny((channel, data) => {
|
|
33
|
-
spinner.update({ text: `Received [${channel}]` });
|
|
34
|
-
if (options.format === "table") {
|
|
35
|
-
console.table(data);
|
|
36
|
-
}
|
|
37
|
-
if (options.format === "yaml") {
|
|
38
|
-
console.log(yaml.dump(data));
|
|
39
|
-
}
|
|
40
|
-
if (options.format === "json") {
|
|
41
|
-
console.log(JSON.stringify(data, null, 2));
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
catch (e) {
|
|
46
|
-
spinner.error({ text: e.message || "An unexpected error occurred" });
|
|
47
|
-
process.exit(EXIT_GENERAL_ERROR);
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
}
|
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
import { apiCallHandler } from "../api/apiCallHandler.js";
|
|
2
|
-
import { handleResponseFormatOptions } from "../helpers/handleResponseFormatOptions.js";
|
|
3
|
-
import { spinner } from "../../index.js";
|
|
4
|
-
import { EXIT_GENERAL_ERROR } from "../exitCodes.js";
|
|
5
|
-
export function createSyncCommand(program) {
|
|
6
|
-
const sync = program
|
|
7
|
-
.command("sync")
|
|
8
|
-
.description("Synchronize platform data across systems");
|
|
9
|
-
// ay sync repos
|
|
10
|
-
sync
|
|
11
|
-
.command("repos")
|
|
12
|
-
.description("Sync repositories from connected providers")
|
|
13
|
-
.addHelpText("after", `
|
|
14
|
-
Examples:
|
|
15
|
-
ay sync repos Sync all repositories
|
|
16
|
-
ay sync repos --provider bitbucket Sync only Bitbucket repos
|
|
17
|
-
ay sync repos --id <repoId> Sync a specific repository`)
|
|
18
|
-
.option("--provider <provider>", "Filter by provider (bitbucket, github)")
|
|
19
|
-
.option("--id <repoId>", "Sync a specific repository by ID")
|
|
20
|
-
.action(async (options) => {
|
|
21
|
-
try {
|
|
22
|
-
const opts = { ...program.opts(), ...options };
|
|
23
|
-
if (opts.id) {
|
|
24
|
-
spinner.start({ text: `Syncing repository ${opts.id}...`, color: "magenta" });
|
|
25
|
-
const res = await apiCallHandler("devops", `repositories/${opts.id}/sync`, "post", null, { responseFormat: opts.responseFormat });
|
|
26
|
-
handleResponseFormatOptions(opts, res);
|
|
27
|
-
spinner.success({ text: `Repository ${opts.id} sync initiated` });
|
|
28
|
-
spinner.stop();
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
spinner.start({ text: "Syncing repositories...", color: "magenta" });
|
|
32
|
-
const params = {
|
|
33
|
-
responseFormat: opts.responseFormat,
|
|
34
|
-
verbosity: opts.verbosity,
|
|
35
|
-
};
|
|
36
|
-
if (opts.provider)
|
|
37
|
-
params.provider = opts.provider;
|
|
38
|
-
// List repos first, then trigger sync
|
|
39
|
-
const listRes = await apiCallHandler("devops", "repositories", "get", null, {
|
|
40
|
-
...params,
|
|
41
|
-
limit: 200,
|
|
42
|
-
});
|
|
43
|
-
const repos = Array.isArray(listRes === null || listRes === void 0 ? void 0 : listRes.payload) ? listRes.payload : [];
|
|
44
|
-
let syncCount = 0;
|
|
45
|
-
let errorCount = 0;
|
|
46
|
-
for (const repo of repos) {
|
|
47
|
-
if (opts.provider && repo.provider !== opts.provider)
|
|
48
|
-
continue;
|
|
49
|
-
try {
|
|
50
|
-
await apiCallHandler("devops", `repositories/${repo._id}/sync`, "post", null, { responseFormat: "json" });
|
|
51
|
-
syncCount++;
|
|
52
|
-
spinner.update({ text: `Syncing repositories... ${syncCount}/${repos.length}` });
|
|
53
|
-
}
|
|
54
|
-
catch (_a) {
|
|
55
|
-
errorCount++;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
spinner.success({ text: `Synced ${syncCount}/${repos.length} repositories` });
|
|
59
|
-
spinner.stop();
|
|
60
|
-
if (errorCount > 0) {
|
|
61
|
-
console.error(` ${errorCount} repositories failed to sync`);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
catch (e) {
|
|
66
|
-
spinner.error({ text: e.message || "Repository sync failed" });
|
|
67
|
-
process.exit(EXIT_GENERAL_ERROR);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
// ay sync clusters
|
|
71
|
-
sync
|
|
72
|
-
.command("clusters")
|
|
73
|
-
.description("Sync Kubernetes cluster state")
|
|
74
|
-
.option("--id <clusterId>", "Sync a specific cluster by ID")
|
|
75
|
-
.action(async (options) => {
|
|
76
|
-
try {
|
|
77
|
-
const opts = { ...program.opts(), ...options };
|
|
78
|
-
if (opts.id) {
|
|
79
|
-
spinner.start({ text: `Syncing cluster ${opts.id}...`, color: "magenta" });
|
|
80
|
-
const res = await apiCallHandler("devops", `clusters/${opts.id}/sync`, "post", null, { responseFormat: opts.responseFormat });
|
|
81
|
-
handleResponseFormatOptions(opts, res);
|
|
82
|
-
spinner.success({ text: `Cluster ${opts.id} sync initiated` });
|
|
83
|
-
spinner.stop();
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
spinner.start({ text: "Syncing all clusters...", color: "magenta" });
|
|
87
|
-
const listRes = await apiCallHandler("devops", "clusters", "get", null, {
|
|
88
|
-
limit: 100,
|
|
89
|
-
responseFormat: "json",
|
|
90
|
-
});
|
|
91
|
-
const clusters = Array.isArray(listRes === null || listRes === void 0 ? void 0 : listRes.payload) ? listRes.payload : [];
|
|
92
|
-
let syncCount = 0;
|
|
93
|
-
for (const cluster of clusters) {
|
|
94
|
-
try {
|
|
95
|
-
await apiCallHandler("devops", `clusters/${cluster._id}/sync`, "post", null, { responseFormat: "json" });
|
|
96
|
-
syncCount++;
|
|
97
|
-
}
|
|
98
|
-
catch (_a) {
|
|
99
|
-
// ignore individual failures
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
spinner.success({ text: `Synced ${syncCount}/${clusters.length} clusters` });
|
|
103
|
-
spinner.stop();
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
catch (e) {
|
|
107
|
-
spinner.error({ text: e.message || "Cluster sync failed" });
|
|
108
|
-
process.exit(EXIT_GENERAL_ERROR);
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
// ay sync pipelines
|
|
112
|
-
sync
|
|
113
|
-
.command("pipelines")
|
|
114
|
-
.description("Sync pipeline status from CI/CD providers")
|
|
115
|
-
.option("--provider <provider>", "Filter by provider (bitbucket, github)")
|
|
116
|
-
.option("-l, --limit <number>", "Limit results", parseInt, 50)
|
|
117
|
-
.action(async (options) => {
|
|
118
|
-
try {
|
|
119
|
-
const opts = { ...program.opts(), ...options };
|
|
120
|
-
spinner.start({ text: "Syncing pipeline status...", color: "magenta" });
|
|
121
|
-
const params = {
|
|
122
|
-
limit: opts.limit,
|
|
123
|
-
responseFormat: opts.responseFormat,
|
|
124
|
-
verbosity: opts.verbosity,
|
|
125
|
-
};
|
|
126
|
-
if (opts.provider)
|
|
127
|
-
params.provider = opts.provider;
|
|
128
|
-
const res = await apiCallHandler("devops", "pipelines/sync", "post", null, params);
|
|
129
|
-
handleResponseFormatOptions(opts, res);
|
|
130
|
-
spinner.success({ text: "Pipeline sync initiated" });
|
|
131
|
-
spinner.stop();
|
|
132
|
-
}
|
|
133
|
-
catch (e) {
|
|
134
|
-
spinner.error({ text: e.message || "Pipeline sync failed" });
|
|
135
|
-
process.exit(EXIT_GENERAL_ERROR);
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
// ay sync status
|
|
139
|
-
sync
|
|
140
|
-
.command("status")
|
|
141
|
-
.description("Show sync status across all systems")
|
|
142
|
-
.action(async (options) => {
|
|
143
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
144
|
-
try {
|
|
145
|
-
const opts = { ...program.opts(), ...options };
|
|
146
|
-
spinner.start({ text: "Fetching sync status...", color: "magenta" });
|
|
147
|
-
// Gather status from multiple endpoints
|
|
148
|
-
const [reposRes, clustersRes, pipelinesRes] = await Promise.allSettled([
|
|
149
|
-
apiCallHandler("devops", "repositories", "get", null, { limit: 1, responseFormat: "json" }),
|
|
150
|
-
apiCallHandler("devops", "clusters", "get", null, { limit: 1, responseFormat: "json" }),
|
|
151
|
-
apiCallHandler("devops", "pipelines", "get", null, { limit: 1, responseFormat: "json" }),
|
|
152
|
-
]);
|
|
153
|
-
const status = {
|
|
154
|
-
repositories: {
|
|
155
|
-
total: reposRes.status === "fulfilled" ? (_d = (_c = (_b = (_a = reposRes.value) === null || _a === void 0 ? void 0 : _a.meta) === null || _b === void 0 ? void 0 : _b.pageInfo) === null || _c === void 0 ? void 0 : _c.totalEntries) !== null && _d !== void 0 ? _d : 0 : "error",
|
|
156
|
-
},
|
|
157
|
-
clusters: {
|
|
158
|
-
total: clustersRes.status === "fulfilled" ? (_h = (_g = (_f = (_e = clustersRes.value) === null || _e === void 0 ? void 0 : _e.meta) === null || _f === void 0 ? void 0 : _f.pageInfo) === null || _g === void 0 ? void 0 : _g.totalEntries) !== null && _h !== void 0 ? _h : 0 : "error",
|
|
159
|
-
},
|
|
160
|
-
pipelines: {
|
|
161
|
-
total: pipelinesRes.status === "fulfilled" ? (_m = (_l = (_k = (_j = pipelinesRes.value) === null || _j === void 0 ? void 0 : _j.meta) === null || _k === void 0 ? void 0 : _k.pageInfo) === null || _l === void 0 ? void 0 : _l.totalEntries) !== null && _m !== void 0 ? _m : 0 : "error",
|
|
162
|
-
},
|
|
163
|
-
};
|
|
164
|
-
const res = {
|
|
165
|
-
payload: status,
|
|
166
|
-
meta: { pageInfo: { totalEntries: 1, page: 1, totalPages: 1 } },
|
|
167
|
-
};
|
|
168
|
-
handleResponseFormatOptions(opts, res);
|
|
169
|
-
spinner.success({ text: "Sync status retrieved" });
|
|
170
|
-
spinner.stop();
|
|
171
|
-
}
|
|
172
|
-
catch (e) {
|
|
173
|
-
spinner.error({ text: e.message || "Failed to get sync status" });
|
|
174
|
-
process.exit(EXIT_GENERAL_ERROR);
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
}
|