@autocodeflow/cli 1.5.0
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/dist/client.d.ts +14 -0
- package/dist/client.js +202 -0
- package/dist/commands/apps.d.ts +2 -0
- package/dist/commands/apps.js +322 -0
- package/dist/commands/audit.d.ts +2 -0
- package/dist/commands/audit.js +77 -0
- package/dist/commands/deploy.d.ts +2 -0
- package/dist/commands/deploy.js +49 -0
- package/dist/commands/exec.d.ts +32 -0
- package/dist/commands/exec.js +156 -0
- package/dist/commands/executors.d.ts +2 -0
- package/dist/commands/executors.js +183 -0
- package/dist/commands/login.d.ts +2 -0
- package/dist/commands/login.js +116 -0
- package/dist/commands/projects.d.ts +6 -0
- package/dist/commands/projects.js +97 -0
- package/dist/commands/tasks.d.ts +2 -0
- package/dist/commands/tasks.js +625 -0
- package/dist/config.d.ts +27 -0
- package/dist/config.js +160 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +93 -0
- package/package.json +47 -0
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Reset client (needed after config changes in same process). */
|
|
2
|
+
export declare function resetClient(): void;
|
|
3
|
+
export declare function unwrap<T>(raw: unknown): T;
|
|
4
|
+
export declare function get<T>(path: string, params?: Record<string, string | number | undefined>): Promise<T>;
|
|
5
|
+
export declare function post<T>(path: string, body?: unknown): Promise<T>;
|
|
6
|
+
export declare function put<T>(path: string, body?: unknown): Promise<T>;
|
|
7
|
+
export declare function patch<T>(path: string, body?: unknown): Promise<T>;
|
|
8
|
+
export declare function del<T>(path: string): Promise<T>;
|
|
9
|
+
/**
|
|
10
|
+
* Render any thrown error as a single readable line, distinguishing
|
|
11
|
+
* 401 (not authenticated) from 403 (authenticated but not allowed) and
|
|
12
|
+
* surfacing the backend message instead of axios' generic text.
|
|
13
|
+
*/
|
|
14
|
+
export declare function formatApiError(e: unknown): string;
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.formatApiError = exports.del = exports.patch = exports.put = exports.post = exports.get = exports.unwrap = exports.resetClient = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Thin HTTP client wrapper for the AutoCodeFlow Admin API.
|
|
9
|
+
*/
|
|
10
|
+
const axios_1 = __importDefault(require("axios"));
|
|
11
|
+
const config_1 = require("./config");
|
|
12
|
+
let _client = null;
|
|
13
|
+
/** base URL without trailing slashes(/auth/refresh 直连拼接用) */
|
|
14
|
+
function baseUrl() {
|
|
15
|
+
return (0, config_1.getApiUrl)().replace(/\/+$/, "");
|
|
16
|
+
}
|
|
17
|
+
/** Reset client (needed after config changes in same process). */
|
|
18
|
+
function resetClient() {
|
|
19
|
+
_client = null;
|
|
20
|
+
}
|
|
21
|
+
exports.resetClient = resetClient;
|
|
22
|
+
// The admin-api applies a global ResponseInterceptor that wraps every
|
|
23
|
+
// successful response in `{ code, message, data }`. Mirror admin-web's
|
|
24
|
+
// client and strip that envelope so callers can keep using `data.list`,
|
|
25
|
+
// `data.total`, etc. without unwrapping manually.
|
|
26
|
+
//
|
|
27
|
+
// 判据(WIKI-OPT-4 收紧,对齐 mcp-server):raw 是对象 且 含 `data` 键
|
|
28
|
+
// 且 `code` 为数值。理由:ResponseInterceptor 的信封 `code` 恒为数值
|
|
29
|
+
// (`response.statusCode ?? 200`)、`message` 恒为字符串 "success",因此
|
|
30
|
+
// 「数值 code」即可精确识别信封,`message` 的存在不再作为判据——旧的
|
|
31
|
+
// data+(code|message) 宽松启发式会把自带 data+message 字段(无 code)的
|
|
32
|
+
// 业务实体误解包,整个实体被截断成它的 data 值;收紧后这类实体原样透传。
|
|
33
|
+
function unwrap(raw) {
|
|
34
|
+
if (raw &&
|
|
35
|
+
typeof raw === "object" &&
|
|
36
|
+
"data" in raw) {
|
|
37
|
+
const envelope = raw;
|
|
38
|
+
if (typeof envelope.code === "number") {
|
|
39
|
+
return (envelope.data ?? null);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return raw;
|
|
43
|
+
}
|
|
44
|
+
exports.unwrap = unwrap;
|
|
45
|
+
// ---------------------------------------------------------------------------
|
|
46
|
+
// BUG-13 (SEC-01 CLI 复审): 401 单飞自愈
|
|
47
|
+
// ---------------------------------------------------------------------------
|
|
48
|
+
// login 现在同时保存 refreshToken,但 access token 默认 15 分钟过期——此前
|
|
49
|
+
// CLI 一过期就全命令 401,只能重新 acf login。此处的自愈语义:
|
|
50
|
+
// - 401 且本地存有 refresh token → 单飞(并发 401 共享同一次刷新)调
|
|
51
|
+
// POST /auth/refresh,成功则换发双 token 并重放原请求一次;
|
|
52
|
+
// - 刷新失败 → clearAuth()(本地凭据已不可信),错误照常抛给
|
|
53
|
+
// formatApiError 提示重新登录;
|
|
54
|
+
// - /auth/* 路径自身的 401 不触发刷新(登录失败不是 token 过期);
|
|
55
|
+
// - 非幂等请求重放与 DR-06 的区分:重放只发生在「401=请求从未到达业务层
|
|
56
|
+
// 被拒」的认证态,不是业务副作用重试,单次重放安全。
|
|
57
|
+
let refreshInFlight = null;
|
|
58
|
+
async function refreshAccessToken() {
|
|
59
|
+
const refreshToken = (0, config_1.getRefreshToken)();
|
|
60
|
+
if (!refreshToken)
|
|
61
|
+
return null;
|
|
62
|
+
try {
|
|
63
|
+
const r = await axios_1.default.post(`${baseUrl()}/auth/refresh`, { refreshToken }, { timeout: 10000 });
|
|
64
|
+
const data = unwrap(r.data);
|
|
65
|
+
if (typeof data?.accessToken === "string" && data.accessToken.length > 0) {
|
|
66
|
+
(0, config_1.setToken)(data.accessToken);
|
|
67
|
+
// DR-07 修复后的 refresh 是原子轮换:响应携带新 refreshToken 必须跟进
|
|
68
|
+
if (typeof data.refreshToken === "string" &&
|
|
69
|
+
data.refreshToken.length > 0) {
|
|
70
|
+
(0, config_1.setRefreshToken)(data.refreshToken);
|
|
71
|
+
}
|
|
72
|
+
return data.accessToken;
|
|
73
|
+
}
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function isAuthPath(url) {
|
|
81
|
+
return !!url && url.includes("/auth/");
|
|
82
|
+
}
|
|
83
|
+
function getClient() {
|
|
84
|
+
if (!_client) {
|
|
85
|
+
_client = axios_1.default.create({
|
|
86
|
+
baseURL: (0, config_1.getApiUrl)(),
|
|
87
|
+
timeout: 30000,
|
|
88
|
+
});
|
|
89
|
+
// Token 逐请求读取(不再在实例创建时烘焙):同进程内 login / 刷新轮换
|
|
90
|
+
// 后无需 resetClient 也能带上最新凭据(resetClient 保留仅为兼容)。
|
|
91
|
+
_client.interceptors.request.use((cfg) => {
|
|
92
|
+
const token = (0, config_1.getToken)();
|
|
93
|
+
if (token) {
|
|
94
|
+
cfg.headers = Object.assign({}, cfg.headers, {
|
|
95
|
+
Authorization: `Bearer ${token}`,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
return cfg;
|
|
99
|
+
});
|
|
100
|
+
_client.interceptors.response.use(undefined, async (err) => {
|
|
101
|
+
const status = err.response?.status;
|
|
102
|
+
const cfg = err.config;
|
|
103
|
+
if (status !== 401 ||
|
|
104
|
+
!cfg ||
|
|
105
|
+
cfg._acfAuthRetried ||
|
|
106
|
+
isAuthPath(cfg.url)) {
|
|
107
|
+
throw err;
|
|
108
|
+
}
|
|
109
|
+
cfg._acfAuthRetried = true;
|
|
110
|
+
refreshInFlight ?? (refreshInFlight = refreshAccessToken().finally(() => {
|
|
111
|
+
refreshInFlight = null;
|
|
112
|
+
}));
|
|
113
|
+
const token = await refreshInFlight;
|
|
114
|
+
if (token) {
|
|
115
|
+
// 重放走 getClient():request 拦截器会用刚换发的新 token 重写
|
|
116
|
+
// Authorization 头,无需手工改 cfg.headers。
|
|
117
|
+
return getClient().request(cfg);
|
|
118
|
+
}
|
|
119
|
+
(0, config_1.clearAuth)();
|
|
120
|
+
throw err;
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
return _client;
|
|
124
|
+
}
|
|
125
|
+
async function get(path, params) {
|
|
126
|
+
const r = await getClient().get(path, { params });
|
|
127
|
+
return unwrap(r.data);
|
|
128
|
+
}
|
|
129
|
+
exports.get = get;
|
|
130
|
+
async function post(path, body) {
|
|
131
|
+
const r = await getClient().post(path, body);
|
|
132
|
+
return unwrap(r.data);
|
|
133
|
+
}
|
|
134
|
+
exports.post = post;
|
|
135
|
+
async function put(path, body) {
|
|
136
|
+
const r = await getClient().put(path, body);
|
|
137
|
+
return unwrap(r.data);
|
|
138
|
+
}
|
|
139
|
+
exports.put = put;
|
|
140
|
+
async function patch(path, body) {
|
|
141
|
+
const r = await getClient().patch(path, body);
|
|
142
|
+
return unwrap(r.data);
|
|
143
|
+
}
|
|
144
|
+
exports.patch = patch;
|
|
145
|
+
async function del(path) {
|
|
146
|
+
const r = await getClient().delete(path);
|
|
147
|
+
return unwrap(r.data);
|
|
148
|
+
}
|
|
149
|
+
exports.del = del;
|
|
150
|
+
// ---------------------------------------------------------------------------
|
|
151
|
+
// Error formatting
|
|
152
|
+
// ---------------------------------------------------------------------------
|
|
153
|
+
// The API returns errors as `{ statusCode, message, error }` (NestJS) or the
|
|
154
|
+
// `{ code, message, data }` envelope. class-validator may send `message` as a
|
|
155
|
+
// string[]. Axios itself only surfaces "Request failed with status code 400",
|
|
156
|
+
// so without this helper the actual cause never reaches the terminal.
|
|
157
|
+
function detailFromData(data) {
|
|
158
|
+
if (!data || typeof data !== "object")
|
|
159
|
+
return "";
|
|
160
|
+
const d = data;
|
|
161
|
+
const m = d.message;
|
|
162
|
+
// QA-07 契约:空串 message 视为「未提供」,继续走 message[]/error 兜底
|
|
163
|
+
//(与 mcp-server extractDetail 对齐;此前空串 message 会遮蔽 error 字段)。
|
|
164
|
+
if (typeof m === "string" && m)
|
|
165
|
+
return m;
|
|
166
|
+
if (Array.isArray(m) && m.length)
|
|
167
|
+
return m.map(String).join("; ");
|
|
168
|
+
if (typeof d.error === "string" && d.error)
|
|
169
|
+
return d.error;
|
|
170
|
+
return "";
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Render any thrown error as a single readable line, distinguishing
|
|
174
|
+
* 401 (not authenticated) from 403 (authenticated but not allowed) and
|
|
175
|
+
* surfacing the backend message instead of axios' generic text.
|
|
176
|
+
*/
|
|
177
|
+
function formatApiError(e) {
|
|
178
|
+
if (axios_1.default.isAxiosError(e)) {
|
|
179
|
+
const err = e;
|
|
180
|
+
const status = err.response?.status;
|
|
181
|
+
const detail = detailFromData(err.response?.data);
|
|
182
|
+
switch (status) {
|
|
183
|
+
case 400:
|
|
184
|
+
return `Bad request (400): ${detail || "invalid parameters — the API rejects fields not declared in its DTO whitelist"}`;
|
|
185
|
+
case 401:
|
|
186
|
+
return `Unauthorized (401): ${detail || "token missing, expired or invalid"} — run "acf login" or pass --token / set ACF_TOKEN`;
|
|
187
|
+
case 403:
|
|
188
|
+
return `Forbidden (403): ${detail || "your account is not allowed to perform this operation (some endpoints require the ADMIN role)"}`;
|
|
189
|
+
case 404:
|
|
190
|
+
return `Not found (404): ${detail || "resource does not exist"}`;
|
|
191
|
+
case 409:
|
|
192
|
+
return `Conflict (409): ${detail || "resource already exists"}`;
|
|
193
|
+
default:
|
|
194
|
+
if (status) {
|
|
195
|
+
return `API error (${status}): ${detail || err.message}`;
|
|
196
|
+
}
|
|
197
|
+
return `Network error: ${err.message} (is the API reachable at ${(0, config_1.getApiUrl)()}?)`;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return e instanceof Error ? e.message : String(e);
|
|
201
|
+
}
|
|
202
|
+
exports.formatApiError = formatApiError;
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.appsCommand = void 0;
|
|
30
|
+
const commander_1 = require("commander");
|
|
31
|
+
const cli_table3_1 = __importDefault(require("cli-table3"));
|
|
32
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
33
|
+
const ora_1 = __importDefault(require("ora"));
|
|
34
|
+
const client_1 = require("../client");
|
|
35
|
+
function statusColor(s) {
|
|
36
|
+
if (s === 'running')
|
|
37
|
+
return chalk_1.default.green(s);
|
|
38
|
+
if (s === 'stopped')
|
|
39
|
+
return chalk_1.default.gray(s);
|
|
40
|
+
if (s === 'error' || s === 'failed')
|
|
41
|
+
return chalk_1.default.red(s);
|
|
42
|
+
if (s === 'deploying')
|
|
43
|
+
return chalk_1.default.cyan(s);
|
|
44
|
+
return chalk_1.default.yellow(s);
|
|
45
|
+
}
|
|
46
|
+
/** Load a JSON payload from --file (preferred) or --json. */
|
|
47
|
+
async function loadJsonBody(json, file) {
|
|
48
|
+
const fs = await Promise.resolve().then(() => __importStar(require('fs/promises')));
|
|
49
|
+
const raw = file ? await fs.readFile(file, 'utf-8') : json;
|
|
50
|
+
if (raw === undefined) {
|
|
51
|
+
throw new Error('Missing JSON payload (provide --json or --file)');
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
return JSON.parse(raw);
|
|
55
|
+
}
|
|
56
|
+
catch (e) {
|
|
57
|
+
throw new Error(`Invalid JSON payload: ${e instanceof Error ? e.message : String(e)}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function appsCommand() {
|
|
61
|
+
const cmd = new commander_1.Command('app').description('Manage applications');
|
|
62
|
+
// acf app list
|
|
63
|
+
cmd.command('list')
|
|
64
|
+
.description('List all applications')
|
|
65
|
+
.option('--json', 'Emit raw JSON (CI-consumable, no table)')
|
|
66
|
+
.action(async (opts) => {
|
|
67
|
+
const spinner = (0, ora_1.default)('Fetching applications…').start();
|
|
68
|
+
try {
|
|
69
|
+
const data = await (0, client_1.get)('/applications');
|
|
70
|
+
spinner.stop();
|
|
71
|
+
const apps = Array.isArray(data) ? data : (data.list ?? []);
|
|
72
|
+
if (opts.json) {
|
|
73
|
+
// ECO-02: --json —— CI/脚本消费面
|
|
74
|
+
console.log(JSON.stringify(apps));
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const table = new cli_table3_1.default({
|
|
78
|
+
head: ['ID', 'Name', 'Status', 'Version', 'Git Repo', 'Branch'],
|
|
79
|
+
colWidths: [14, 26, 12, 10, 28, 14],
|
|
80
|
+
style: { head: ['cyan'] },
|
|
81
|
+
});
|
|
82
|
+
for (const a of apps) {
|
|
83
|
+
table.push([
|
|
84
|
+
a.id.slice(0, 12),
|
|
85
|
+
a.name,
|
|
86
|
+
statusColor(a.status),
|
|
87
|
+
a.version ?? '-',
|
|
88
|
+
a.gitRepo ?? '-',
|
|
89
|
+
a.gitBranch ?? '-',
|
|
90
|
+
]);
|
|
91
|
+
}
|
|
92
|
+
console.log(table.toString());
|
|
93
|
+
}
|
|
94
|
+
catch (e) {
|
|
95
|
+
spinner.fail('Failed to list applications');
|
|
96
|
+
console.error(chalk_1.default.red((0, client_1.formatApiError)(e)));
|
|
97
|
+
process.exit(1);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
// acf app get <id>
|
|
101
|
+
cmd.command('get <id>')
|
|
102
|
+
.description('Show application details')
|
|
103
|
+
.action(async (id) => {
|
|
104
|
+
const spinner = (0, ora_1.default)('Fetching application…').start();
|
|
105
|
+
try {
|
|
106
|
+
const a = await (0, client_1.get)(`/applications/${id}`);
|
|
107
|
+
spinner.stop();
|
|
108
|
+
console.log(chalk_1.default.bold('Application Details'));
|
|
109
|
+
console.log(' ID :', a.id);
|
|
110
|
+
console.log(' Name :', a.name);
|
|
111
|
+
console.log(' Status :', statusColor(a.status));
|
|
112
|
+
console.log(' Version :', a.version ?? '-');
|
|
113
|
+
console.log(' Runtime :', a.runtime ?? '-');
|
|
114
|
+
console.log(' Git Repo :', a.gitRepo ?? '-');
|
|
115
|
+
console.log(' Git Branch :', a.gitBranch ?? '-');
|
|
116
|
+
console.log(' Git Commit :', a.gitCommit ?? '-');
|
|
117
|
+
console.log(' Entrypoint :', a.entrypoint ?? '-');
|
|
118
|
+
console.log(' Package URL :', a.packageUrl ?? '-');
|
|
119
|
+
console.log(' Description :', a.description ?? '-');
|
|
120
|
+
}
|
|
121
|
+
catch (e) {
|
|
122
|
+
spinner.fail('Failed');
|
|
123
|
+
console.error(chalk_1.default.red((0, client_1.formatApiError)(e)));
|
|
124
|
+
process.exit(1);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
// acf app create
|
|
128
|
+
cmd.command('create')
|
|
129
|
+
.description('Create an application (JSON payload via --json or --file; required: name, version, runtime)')
|
|
130
|
+
.requiredOption('--json <body>', 'Application body as JSON string')
|
|
131
|
+
.option('--file <path>', 'Read application body from a JSON file (overrides --json)')
|
|
132
|
+
.action(async (opts) => {
|
|
133
|
+
const spinner = (0, ora_1.default)('Creating application…').start();
|
|
134
|
+
try {
|
|
135
|
+
const body = await loadJsonBody(opts.json, opts.file);
|
|
136
|
+
const a = await (0, client_1.post)('/applications', body);
|
|
137
|
+
spinner.succeed(`Application created: ${a.id}`);
|
|
138
|
+
console.log(chalk_1.default.gray(` name: ${a.name} version: ${a.version ?? '-'} status: ${statusColor(a.status)}`));
|
|
139
|
+
}
|
|
140
|
+
catch (e) {
|
|
141
|
+
spinner.fail('Failed to create application');
|
|
142
|
+
console.error(chalk_1.default.red((0, client_1.formatApiError)(e)));
|
|
143
|
+
process.exit(1);
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
// acf app update <id>
|
|
147
|
+
cmd.command('update <id>')
|
|
148
|
+
.description('Update an application (JSON payload via --json or --file). ' +
|
|
149
|
+
'Accepted fields: description, version, runtime, status, gitRepo, gitBranch, gitCommit, manifest, env, entrypoint, packageUrl, webhookSecret. ' +
|
|
150
|
+
'NOTE: the backend UpdateApplicationDto has no `name` field — renaming is not supported.')
|
|
151
|
+
.requiredOption('--json <body>', 'Application patch body as JSON string')
|
|
152
|
+
.option('--file <path>', 'Read application patch body from a JSON file (overrides --json)')
|
|
153
|
+
.action(async (id, opts) => {
|
|
154
|
+
const spinner = (0, ora_1.default)('Updating application…').start();
|
|
155
|
+
try {
|
|
156
|
+
const body = (await loadJsonBody(opts.json, opts.file));
|
|
157
|
+
// UpdateApplicationDto has no `name` — with forbidNonWhitelisted the
|
|
158
|
+
// API would answer 400 "property name should not exist". Fail early
|
|
159
|
+
// with an actionable message instead.
|
|
160
|
+
if (body && typeof body === 'object' && 'name' in body) {
|
|
161
|
+
throw new Error('Application update does not support renaming: the backend UpdateApplicationDto has no `name` field. ' +
|
|
162
|
+
'Remove "name" from the payload.');
|
|
163
|
+
}
|
|
164
|
+
const a = await (0, client_1.put)(`/applications/${id}`, body);
|
|
165
|
+
spinner.succeed(`Application updated: ${a.id}`);
|
|
166
|
+
console.log(chalk_1.default.gray(` name: ${a.name} version: ${a.version ?? '-'} status: ${statusColor(a.status)}`));
|
|
167
|
+
}
|
|
168
|
+
catch (e) {
|
|
169
|
+
spinner.fail('Failed to update application');
|
|
170
|
+
console.error(chalk_1.default.red((0, client_1.formatApiError)(e)));
|
|
171
|
+
process.exit(1);
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
// acf app delete <id>
|
|
175
|
+
cmd.command('delete <id>')
|
|
176
|
+
.description('Delete an application')
|
|
177
|
+
.option('-y, --yes', 'Skip confirmation prompt', false)
|
|
178
|
+
.action(async (id, opts) => {
|
|
179
|
+
if (!opts.yes) {
|
|
180
|
+
const readline = await Promise.resolve().then(() => __importStar(require('readline/promises')));
|
|
181
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
182
|
+
const answer = await rl.question(`Delete application ${id}? [y/N] `);
|
|
183
|
+
rl.close();
|
|
184
|
+
if (!/^y(es)?$/i.test(answer)) {
|
|
185
|
+
console.log(chalk_1.default.yellow('Aborted.'));
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
const spinner = (0, ora_1.default)('Deleting application…').start();
|
|
190
|
+
try {
|
|
191
|
+
await (0, client_1.del)(`/applications/${id}`);
|
|
192
|
+
spinner.succeed(`Application ${id} deleted`);
|
|
193
|
+
}
|
|
194
|
+
catch (e) {
|
|
195
|
+
spinner.fail('Failed to delete application');
|
|
196
|
+
console.error(chalk_1.default.red((0, client_1.formatApiError)(e)));
|
|
197
|
+
process.exit(1);
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
// acf app analyze <id>
|
|
201
|
+
cmd.command('analyze <id>')
|
|
202
|
+
.description('Run AI health analysis on an application')
|
|
203
|
+
.action(async (id) => {
|
|
204
|
+
const spinner = (0, ora_1.default)('Running AI health analysis…').start();
|
|
205
|
+
try {
|
|
206
|
+
const result = await (0, client_1.post)(`/applications/${id}/analyze`);
|
|
207
|
+
spinner.stop();
|
|
208
|
+
console.log(chalk_1.default.bold(`\nAI Health Analysis — ${result.appName}`));
|
|
209
|
+
console.log(chalk_1.default.gray('─'.repeat(60)));
|
|
210
|
+
console.log(` Total tasks : ${result.stats.totalTasks}`);
|
|
211
|
+
console.log(` Avg success rate: ${chalk_1.default.green(result.stats.avgSuccessRate + '%')}`);
|
|
212
|
+
console.log(` Avg duration : ${result.stats.avgDuration}ms`);
|
|
213
|
+
if (result.stats.criticalTasks.length > 0) {
|
|
214
|
+
console.log(` Critical tasks : ${chalk_1.default.red(result.stats.criticalTasks.join(', '))}`);
|
|
215
|
+
}
|
|
216
|
+
console.log();
|
|
217
|
+
console.log(result.analysis);
|
|
218
|
+
}
|
|
219
|
+
catch (e) {
|
|
220
|
+
spinner.fail('Analysis failed');
|
|
221
|
+
console.error(chalk_1.default.red((0, client_1.formatApiError)(e)));
|
|
222
|
+
process.exit(1);
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
// acf app deploy <id>
|
|
226
|
+
cmd.command('deploy <id>')
|
|
227
|
+
.description('Deploy an application to an executor (auto-selects the lowest-load online executor when --executor is omitted)')
|
|
228
|
+
.option('-e, --executor <executorId>', 'Pin to a specific executor')
|
|
229
|
+
.option('-m, --run-mode <mode>', 'Run mode: once | daemon | scheduled', 'daemon')
|
|
230
|
+
.option('--env <json>', 'Env var overrides as JSON, e.g. \'{"KEY":"value"}\'')
|
|
231
|
+
.option('--start-command <cmd>', 'Startup command override (defaults to manifest entrypoint)')
|
|
232
|
+
.action(async (id, opts) => {
|
|
233
|
+
const spinner = (0, ora_1.default)('Triggering deployment…').start();
|
|
234
|
+
try {
|
|
235
|
+
const body = { runMode: opts.runMode };
|
|
236
|
+
if (opts.executor)
|
|
237
|
+
body.executorId = opts.executor;
|
|
238
|
+
if (opts.env)
|
|
239
|
+
body.env = JSON.parse(opts.env);
|
|
240
|
+
if (opts.startCommand)
|
|
241
|
+
body.startCommand = opts.startCommand;
|
|
242
|
+
const dep = await (0, client_1.post)(`/app-deployments/applications/${id}/deploy`, body);
|
|
243
|
+
spinner.succeed('Deployment triggered');
|
|
244
|
+
console.log(chalk_1.default.gray(` deployment: ${dep?.id ?? '-'} status: ${dep?.status ?? '-'} executor: ${dep?.executorId ?? 'auto'}`));
|
|
245
|
+
}
|
|
246
|
+
catch (e) {
|
|
247
|
+
spinner.fail('Deployment failed');
|
|
248
|
+
console.error(chalk_1.default.red((0, client_1.formatApiError)(e)));
|
|
249
|
+
process.exit(1);
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
// acf app deployments [appId]
|
|
253
|
+
cmd.command('deployments [appId]')
|
|
254
|
+
.description('List deployments (optionally filtered by application)')
|
|
255
|
+
.option('-p, --page <n>', 'Page number', '1')
|
|
256
|
+
.option('-n, --page-size <n>', 'Page size', '20')
|
|
257
|
+
.action(async (appId, opts) => {
|
|
258
|
+
const spinner = (0, ora_1.default)('Fetching deployments…').start();
|
|
259
|
+
try {
|
|
260
|
+
// app-deployment.service.findAll returns `{ data, total }`
|
|
261
|
+
const data = await (0, client_1.get)('/app-deployments', {
|
|
262
|
+
...(appId ? { applicationId: appId } : {}),
|
|
263
|
+
page: opts.page,
|
|
264
|
+
pageSize: opts.pageSize,
|
|
265
|
+
});
|
|
266
|
+
spinner.stop();
|
|
267
|
+
const list = Array.isArray(data) ? data : (data.data ?? data.list ?? []);
|
|
268
|
+
const table = new cli_table3_1.default({
|
|
269
|
+
head: ['Deployment', 'App', 'Executor', 'Status', 'RunMode'],
|
|
270
|
+
colWidths: [14, 14, 14, 12, 11],
|
|
271
|
+
style: { head: ['cyan'] },
|
|
272
|
+
});
|
|
273
|
+
for (const d of list) {
|
|
274
|
+
table.push([
|
|
275
|
+
d.id.slice(0, 12),
|
|
276
|
+
d.applicationId?.slice(0, 12) ?? '-',
|
|
277
|
+
d.executorId?.slice(0, 12) ?? '-',
|
|
278
|
+
statusColor(d.status),
|
|
279
|
+
d.runMode ?? '-',
|
|
280
|
+
]);
|
|
281
|
+
}
|
|
282
|
+
console.log(table.toString());
|
|
283
|
+
}
|
|
284
|
+
catch (e) {
|
|
285
|
+
spinner.fail('Failed to list deployments');
|
|
286
|
+
console.error(chalk_1.default.red((0, client_1.formatApiError)(e)));
|
|
287
|
+
process.exit(1);
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
// acf app versions <id>
|
|
291
|
+
cmd.command('versions <id>')
|
|
292
|
+
.description('Show application version history')
|
|
293
|
+
.action(async (id) => {
|
|
294
|
+
const spinner = (0, ora_1.default)('Fetching version history…').start();
|
|
295
|
+
try {
|
|
296
|
+
// getVersionHistory returns `commit` / `deployedAt` (no gitCommit / changeNote)
|
|
297
|
+
const versions = await (0, client_1.get)(`/applications/${id}/versions`);
|
|
298
|
+
spinner.stop();
|
|
299
|
+
const table = new cli_table3_1.default({
|
|
300
|
+
head: ['Version', 'Commit', 'Deployed', 'Status'],
|
|
301
|
+
colWidths: [12, 14, 25, 12],
|
|
302
|
+
style: { head: ['cyan'] },
|
|
303
|
+
});
|
|
304
|
+
for (const v of versions) {
|
|
305
|
+
table.push([
|
|
306
|
+
v.version,
|
|
307
|
+
v.commit?.slice(0, 12) ?? '-',
|
|
308
|
+
new Date(v.deployedAt ?? v.createdAt ?? '').toLocaleString(),
|
|
309
|
+
v.status ?? '-',
|
|
310
|
+
]);
|
|
311
|
+
}
|
|
312
|
+
console.log(table.toString());
|
|
313
|
+
}
|
|
314
|
+
catch (e) {
|
|
315
|
+
spinner.fail('Failed to list versions');
|
|
316
|
+
console.error(chalk_1.default.red((0, client_1.formatApiError)(e)));
|
|
317
|
+
process.exit(1);
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
return cmd;
|
|
321
|
+
}
|
|
322
|
+
exports.appsCommand = appsCommand;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.auditCommand = void 0;
|
|
7
|
+
const commander_1 = require("commander");
|
|
8
|
+
const cli_table3_1 = __importDefault(require("cli-table3"));
|
|
9
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
10
|
+
const ora_1 = __importDefault(require("ora"));
|
|
11
|
+
const client_1 = require("../client");
|
|
12
|
+
function resultColor(r) {
|
|
13
|
+
if (r === 'success')
|
|
14
|
+
return chalk_1.default.green(r);
|
|
15
|
+
if (r === 'failure')
|
|
16
|
+
return chalk_1.default.red(r);
|
|
17
|
+
return r ?? '-';
|
|
18
|
+
}
|
|
19
|
+
function auditCommand() {
|
|
20
|
+
const cmd = new commander_1.Command('audit').description('Query the audit log');
|
|
21
|
+
// acf audit list
|
|
22
|
+
cmd.command('list')
|
|
23
|
+
.description('List audit log entries (newest first)')
|
|
24
|
+
.option('--action <action>', 'Filter by action, fuzzy match (e.g. task.trigger)')
|
|
25
|
+
.option('--resource <resource>', 'Filter by exact resource type (e.g. task)')
|
|
26
|
+
.option('--user-id <n>', 'Filter by operator user id')
|
|
27
|
+
.option('--username <username>', 'Filter by operator username (fuzzy match)')
|
|
28
|
+
.option('--start-time <iso>', 'Only entries created at/after this time (ISO 8601, e.g. 2026-01-01T00:00:00Z)')
|
|
29
|
+
.option('--end-time <iso>', 'Only entries created at/before this time (ISO 8601)')
|
|
30
|
+
.option('-p, --page <n>', 'Page number', '1')
|
|
31
|
+
.option('-n, --page-size <n>', 'Page size (max 100)', '20')
|
|
32
|
+
.action(async (opts) => {
|
|
33
|
+
const spinner = (0, ora_1.default)('Fetching audit logs…').start();
|
|
34
|
+
try {
|
|
35
|
+
// AuditQueryDto whitelist: action / resource / userId / username /
|
|
36
|
+
// startTime / endTime (+ page / pageSize from PaginationDto). Any
|
|
37
|
+
// other query field is rejected with 400 by forbidNonWhitelisted.
|
|
38
|
+
const data = await (0, client_1.get)('/audit', {
|
|
39
|
+
page: opts.page,
|
|
40
|
+
pageSize: opts.pageSize,
|
|
41
|
+
action: opts.action,
|
|
42
|
+
resource: opts.resource,
|
|
43
|
+
userId: opts.userId,
|
|
44
|
+
username: opts.username,
|
|
45
|
+
startTime: opts.startTime,
|
|
46
|
+
endTime: opts.endTime,
|
|
47
|
+
});
|
|
48
|
+
spinner.stop();
|
|
49
|
+
const rows = Array.isArray(data) ? data : (data.data ?? []);
|
|
50
|
+
const total = Array.isArray(data) ? rows.length : (data.total ?? rows.length);
|
|
51
|
+
const table = new cli_table3_1.default({
|
|
52
|
+
head: ['Time', 'User', 'Action', 'Resource', 'Resource ID', 'Result'],
|
|
53
|
+
colWidths: [25, 16, 24, 14, 18, 10],
|
|
54
|
+
style: { head: ['cyan'] },
|
|
55
|
+
});
|
|
56
|
+
for (const log of rows) {
|
|
57
|
+
table.push([
|
|
58
|
+
new Date(log.createdAt).toLocaleString(),
|
|
59
|
+
log.username ?? (log.userId !== undefined ? `#${log.userId}` : '-'),
|
|
60
|
+
log.action,
|
|
61
|
+
log.resource ?? '-',
|
|
62
|
+
log.resourceId?.slice(0, 16) ?? '-',
|
|
63
|
+
resultColor(log.result),
|
|
64
|
+
]);
|
|
65
|
+
}
|
|
66
|
+
console.log(table.toString());
|
|
67
|
+
console.log(chalk_1.default.gray(`Total: ${total} page ${opts.page}`));
|
|
68
|
+
}
|
|
69
|
+
catch (e) {
|
|
70
|
+
spinner.fail('Failed to list audit logs');
|
|
71
|
+
console.error(chalk_1.default.red((0, client_1.formatApiError)(e)));
|
|
72
|
+
process.exit(1);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
return cmd;
|
|
76
|
+
}
|
|
77
|
+
exports.auditCommand = auditCommand;
|