@lark-apaas/miaoda-cli 0.1.2-alpha.4d0ff57 → 0.1.2-alpha.74c0e23

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 (55) hide show
  1. package/dist/api/app/api.js +25 -0
  2. package/dist/api/app/index.js +15 -0
  3. package/dist/api/app/schemas.js +79 -0
  4. package/dist/api/app/types.js +58 -0
  5. package/dist/api/db/api.js +6 -181
  6. package/dist/api/db/client.js +0 -36
  7. package/dist/api/db/index.js +1 -7
  8. package/dist/api/deploy/api.js +60 -0
  9. package/dist/api/deploy/index.js +16 -0
  10. package/dist/api/deploy/schemas.js +103 -0
  11. package/dist/api/deploy/types.js +22 -0
  12. package/dist/api/file/api.js +0 -15
  13. package/dist/api/file/index.js +1 -2
  14. package/dist/api/index.js +7 -1
  15. package/dist/api/observability/api.js +52 -0
  16. package/dist/api/observability/index.js +16 -0
  17. package/dist/api/observability/schemas.js +39 -0
  18. package/dist/api/observability/types.js +27 -0
  19. package/dist/cli/commands/app/index.js +62 -0
  20. package/dist/cli/commands/db/index.js +0 -137
  21. package/dist/cli/commands/deploy/index.js +139 -0
  22. package/dist/cli/commands/file/index.js +0 -7
  23. package/dist/cli/commands/index.js +6 -0
  24. package/dist/cli/commands/observability/index.js +227 -0
  25. package/dist/cli/commands/shared.js +37 -3
  26. package/dist/cli/handlers/{file/quota.js → app/get.js} +10 -20
  27. package/dist/cli/handlers/app/index.js +7 -0
  28. package/dist/cli/handlers/{db/quota.js → app/update.js} +20 -21
  29. package/dist/cli/handlers/db/data.js +1 -1
  30. package/dist/cli/handlers/db/index.js +1 -17
  31. package/dist/cli/handlers/deploy/deploy.js +83 -0
  32. package/dist/cli/handlers/deploy/error-log.js +61 -0
  33. package/dist/cli/handlers/deploy/get.js +70 -0
  34. package/dist/cli/handlers/deploy/helpers.js +41 -0
  35. package/dist/cli/handlers/deploy/history.js +70 -0
  36. package/dist/cli/handlers/deploy/index.js +14 -0
  37. package/dist/cli/handlers/deploy/polling.js +139 -0
  38. package/dist/cli/handlers/file/index.js +1 -3
  39. package/dist/cli/handlers/observability/analytics.js +189 -0
  40. package/dist/cli/handlers/observability/helpers.js +66 -0
  41. package/dist/cli/handlers/observability/index.js +12 -0
  42. package/dist/cli/handlers/observability/log.js +94 -0
  43. package/dist/cli/handlers/observability/metric.js +208 -0
  44. package/dist/cli/handlers/observability/trace.js +102 -0
  45. package/dist/utils/devops-error.js +28 -0
  46. package/dist/utils/git.js +29 -0
  47. package/dist/utils/http.js +32 -0
  48. package/dist/utils/index.js +13 -1
  49. package/dist/utils/output.js +338 -7
  50. package/dist/utils/time.js +132 -0
  51. package/package.json +7 -5
  52. package/dist/cli/handlers/db/audit.js +0 -250
  53. package/dist/cli/handlers/db/changelog.js +0 -104
  54. package/dist/cli/handlers/db/migration.js +0 -127
  55. package/dist/cli/handlers/db/recovery.js +0 -141
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAppInfo = getAppInfo;
4
+ exports.updateAppMeta = updateAppMeta;
5
+ const http_1 = require("../../utils/http");
6
+ const devops_error_1 = require("../../utils/devops-error");
7
+ const DEFAULT_ERR_CODE = "INTERNAL_DEVOPS_ERROR";
8
+ function envelopeOpts(errPrefix) {
9
+ return {
10
+ errPrefix,
11
+ defaultErrCode: DEFAULT_ERR_CODE,
12
+ mapErr: devops_error_1.mapDevopsError,
13
+ };
14
+ }
15
+ /** GET /v1/devops/app/:appID — 获取应用详情 */
16
+ async function getAppInfo(appID) {
17
+ const url = `/v1/devops/app/${encodeURIComponent(appID)}`;
18
+ return (0, http_1.getInnerApi)(url, envelopeOpts("Failed to get app info"));
19
+ }
20
+ /** POST /v1/devops/app/:appID/meta — 更新应用元数据 */
21
+ async function updateAppMeta(req) {
22
+ const url = `/v1/devops/app/${encodeURIComponent(req.appID)}/meta`;
23
+ // 路径已带 appID,body 里也保留以匹配 BAM IDL 的 sensitive:"no" 透传约定
24
+ return (0, http_1.postInnerApi)(url, req, envelopeOpts("Failed to update app"));
25
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ArchType = exports.Source = exports.BizType = exports.AppType = exports.AppMode = exports.AppStatus = exports.appMetaSchema = exports.updateAppMeta = exports.getAppInfo = void 0;
4
+ var api_1 = require("./api");
5
+ Object.defineProperty(exports, "getAppInfo", { enumerable: true, get: function () { return api_1.getAppInfo; } });
6
+ Object.defineProperty(exports, "updateAppMeta", { enumerable: true, get: function () { return api_1.updateAppMeta; } });
7
+ var schemas_1 = require("./schemas");
8
+ Object.defineProperty(exports, "appMetaSchema", { enumerable: true, get: function () { return schemas_1.appMetaSchema; } });
9
+ var types_1 = require("./types");
10
+ Object.defineProperty(exports, "AppStatus", { enumerable: true, get: function () { return types_1.AppStatus; } });
11
+ Object.defineProperty(exports, "AppMode", { enumerable: true, get: function () { return types_1.AppMode; } });
12
+ Object.defineProperty(exports, "AppType", { enumerable: true, get: function () { return types_1.AppType; } });
13
+ Object.defineProperty(exports, "BizType", { enumerable: true, get: function () { return types_1.BizType; } });
14
+ Object.defineProperty(exports, "Source", { enumerable: true, get: function () { return types_1.Source; } });
15
+ Object.defineProperty(exports, "ArchType", { enumerable: true, get: function () { return types_1.ArchType; } });
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.appMetaSchema = void 0;
4
+ const output_1 = require("../../utils/output");
5
+ const types_1 = require("./types");
6
+ // Partial<Record<...>>:未来 BAM 加新枚举值时这里没声明也不报错,运行期 lookup 自然得 undefined
7
+ const STATUS_TEXT = {
8
+ [types_1.AppStatus.UNSPECIFIED]: "unknown",
9
+ [types_1.AppStatus.PREPARING]: "preparing",
10
+ [types_1.AppStatus.UNRELEASED]: "unreleased",
11
+ [types_1.AppStatus.RELEASED]: "released",
12
+ [types_1.AppStatus.DELETED]: "deleted",
13
+ [types_1.AppStatus.UPGRADING]: "upgrading",
14
+ };
15
+ const MODE_TEXT = {
16
+ [types_1.AppMode.UNSPECIFIED]: "unknown",
17
+ [types_1.AppMode.STANDARD]: "standard",
18
+ [types_1.AppMode.EXPERT]: "expert",
19
+ };
20
+ const TYPE_TEXT = {
21
+ [types_1.AppType.UNSPECIFIED]: "unknown",
22
+ [types_1.AppType.STANDARD]: "standard",
23
+ [types_1.AppType.PROTOTYPE]: "prototype",
24
+ [types_1.AppType.APPLICATION]: "application",
25
+ [types_1.AppType.DESIGN]: "design",
26
+ [types_1.AppType.OPENCLAW]: "openclaw",
27
+ [types_1.AppType.CLAW_SUB]: "claw_sub",
28
+ };
29
+ const BIZ_TYPE_TEXT = {
30
+ [types_1.BizType.UNSPECIFIED]: "unknown",
31
+ [types_1.BizType.MIAODA]: "miaoda",
32
+ [types_1.BizType.FORCE]: "force",
33
+ };
34
+ const ARCH_TYPE_TEXT = {
35
+ [types_1.ArchType.UNSPECIFIED]: "unknown",
36
+ [types_1.ArchType.FULL_STACK]: "full_stack",
37
+ [types_1.ArchType.NOT_FULL_STACK]: "not_full_stack",
38
+ };
39
+ const SOURCE_TEXT = {
40
+ [types_1.Source.UNSPECIFIED]: "unknown",
41
+ [types_1.Source.CHAT]: "chat",
42
+ [types_1.Source.TEMPLATE]: "template",
43
+ [types_1.Source.IMPORT_ZIP]: "import_zip",
44
+ [types_1.Source.IMPORT_BASE]: "import_base",
45
+ };
46
+ function lookup(table) {
47
+ return (v) => {
48
+ if (typeof v !== "number")
49
+ return undefined;
50
+ return table[v];
51
+ };
52
+ }
53
+ /**
54
+ * AppMeta 的 pretty 渲染契约。
55
+ *
56
+ * 注:BAM 没给 createdAt / updatedAt 的单位注解;先按 ms(fmt.ms)渲染,
57
+ * 待 e2e 真值确认后调整。enum 字段通过 derive 翻译成可读字符串,JSON 模式
58
+ * 仍是 BAM 原值(数字枚举),与 BAM 接口契约保持一致。
59
+ */
60
+ exports.appMetaSchema = {
61
+ columns: [
62
+ { key: "appID", label: "app-id" },
63
+ { key: "name" },
64
+ { key: "description" },
65
+ { key: "status_text", label: "status", derive: (row) => lookup(STATUS_TEXT)(row.status) },
66
+ { key: "appType_text", label: "type", derive: (row) => lookup(TYPE_TEXT)(row.appType) },
67
+ { key: "appMode_text", label: "mode", derive: (row) => lookup(MODE_TEXT)(row.appMode) },
68
+ { key: "bizType_text", label: "biz-type", derive: (row) => lookup(BIZ_TYPE_TEXT)(row.bizType) },
69
+ { key: "archType_text", label: "arch", derive: (row) => lookup(ARCH_TYPE_TEXT)(row.archType) },
70
+ { key: "source_text", label: "source", derive: (row) => lookup(SOURCE_TEXT)(row.source) },
71
+ { key: "ownedBy", label: "owner" },
72
+ { key: "createdBy", label: "creator" },
73
+ { key: "dataBranchID", label: "branch" },
74
+ { key: "parentAppID", label: "parent-app" },
75
+ { key: "createdAt", label: "created-at", format: output_1.fmt.ms() },
76
+ { key: "updatedAt", label: "updated-at", format: output_1.fmt.ms() },
77
+ ],
78
+ strict: true,
79
+ };
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ // 与 BAM lark.apaas.devops v1.0.326 对齐:
3
+ // - CLIGetAppInfo (4070322) → AppInfo / AppMeta
4
+ // - CLIUpdateAppMeta (4070323) → 入参 name? / description?
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ArchType = exports.Source = exports.BizType = exports.AppType = exports.AppMode = exports.AppStatus = void 0;
7
+ /** 应用状态 */
8
+ var AppStatus;
9
+ (function (AppStatus) {
10
+ AppStatus[AppStatus["UNSPECIFIED"] = 0] = "UNSPECIFIED";
11
+ AppStatus[AppStatus["PREPARING"] = 1] = "PREPARING";
12
+ AppStatus[AppStatus["UNRELEASED"] = 2] = "UNRELEASED";
13
+ AppStatus[AppStatus["RELEASED"] = 3] = "RELEASED";
14
+ /** BAM 注释为 Deprecated;保留枚举以兼容历史响应数据 */
15
+ AppStatus[AppStatus["DELETED"] = 4] = "DELETED";
16
+ AppStatus[AppStatus["UPGRADING"] = 5] = "UPGRADING";
17
+ })(AppStatus || (exports.AppStatus = AppStatus = {}));
18
+ /** 应用模式 */
19
+ var AppMode;
20
+ (function (AppMode) {
21
+ AppMode[AppMode["UNSPECIFIED"] = 0] = "UNSPECIFIED";
22
+ AppMode[AppMode["STANDARD"] = 1] = "STANDARD";
23
+ AppMode[AppMode["EXPERT"] = 2] = "EXPERT";
24
+ })(AppMode || (exports.AppMode = AppMode = {}));
25
+ /** 应用类型 */
26
+ var AppType;
27
+ (function (AppType) {
28
+ AppType[AppType["UNSPECIFIED"] = 0] = "UNSPECIFIED";
29
+ AppType[AppType["STANDARD"] = 1] = "STANDARD";
30
+ AppType[AppType["PROTOTYPE"] = 2] = "PROTOTYPE";
31
+ AppType[AppType["APPLICATION"] = 3] = "APPLICATION";
32
+ AppType[AppType["DESIGN"] = 4] = "DESIGN";
33
+ AppType[AppType["OPENCLAW"] = 5] = "OPENCLAW";
34
+ AppType[AppType["CLAW_SUB"] = 6] = "CLAW_SUB";
35
+ })(AppType || (exports.AppType = AppType = {}));
36
+ /** 业务线 */
37
+ var BizType;
38
+ (function (BizType) {
39
+ BizType[BizType["UNSPECIFIED"] = 0] = "UNSPECIFIED";
40
+ BizType[BizType["MIAODA"] = 1] = "MIAODA";
41
+ BizType[BizType["FORCE"] = 2] = "FORCE";
42
+ })(BizType || (exports.BizType = BizType = {}));
43
+ /** 应用来源 */
44
+ var Source;
45
+ (function (Source) {
46
+ Source[Source["UNSPECIFIED"] = 0] = "UNSPECIFIED";
47
+ Source[Source["CHAT"] = 1] = "CHAT";
48
+ Source[Source["TEMPLATE"] = 2] = "TEMPLATE";
49
+ Source[Source["IMPORT_ZIP"] = 3] = "IMPORT_ZIP";
50
+ Source[Source["IMPORT_BASE"] = 4] = "IMPORT_BASE";
51
+ })(Source || (exports.Source = Source = {}));
52
+ /** 架构类型 */
53
+ var ArchType;
54
+ (function (ArchType) {
55
+ ArchType[ArchType["UNSPECIFIED"] = 0] = "UNSPECIFIED";
56
+ ArchType[ArchType["FULL_STACK"] = 1] = "FULL_STACK";
57
+ ArchType[ArchType["NOT_FULL_STACK"] = 2] = "NOT_FULL_STACK";
58
+ })(ArchType || (exports.ArchType = ArchType = {}));
@@ -4,12 +4,6 @@ exports.execSql = execSql;
4
4
  exports.getSchema = getSchema;
5
5
  exports.importData = importData;
6
6
  exports.exportData = exportData;
7
- exports.listDDLChangelog = listDDLChangelog;
8
- exports.setAuditConfig = setAuditConfig;
9
- exports.migrationInit = migrationInit;
10
- exports.migrate = migrate;
11
- exports.recover = recover;
12
- exports.getDbQuota = getDbQuota;
13
7
  const http_1 = require("../../utils/http");
14
8
  const error_1 = require("../../utils/error");
15
9
  const http_client_1 = require("@lark-apaas/http-client");
@@ -253,14 +247,10 @@ async function exportData(opts) {
253
247
  await mapDbHttpError(err, url, "Failed to export data");
254
248
  throw err; // 不可达
255
249
  }
256
- // 成功路径:响应 body 通常是原始 CSV/SQL/JSON 字节,但部分错误场景下网关会返
250
+ // 成功路径:响应 body 通常是原始 CSV/JSON 字节,但部分错误场景下网关会返
257
251
  // HTTP 200 + JSON envelope(status_code != "0"),需要在这里嗅探兜底。
258
- const defaultContentType = {
259
- csv: "text/csv",
260
- sql: "text/plain",
261
- json: "application/json",
262
- };
263
- const contentType = response.headers.get("Content-Type") ?? defaultContentType[opts.format];
252
+ const contentType = response.headers.get("Content-Type") ??
253
+ (opts.format === "csv" ? "text/csv" : "application/json");
264
254
  const ab = await response.arrayBuffer();
265
255
  const buf = Buffer.from(new Uint8Array(ab));
266
256
  if (buf.length === 0) {
@@ -268,9 +258,8 @@ async function exportData(opts) {
268
258
  }
269
259
  // Envelope sniff:HTTP 200 + Content-Type 为 application/json + body 解析得到
270
260
  // InnerEnvelope 且 status_code 非 "0" 时,按业务错误抛出。
271
- // CSV / SQL 都是非 JSON 输出,application/json 响应必是错误信封;JSON 格式
272
- // 成功响应自身就是 application/json,跳过 sniff 避免误判。
273
- if (opts.format !== "json" && /application\/json/i.test(contentType)) {
261
+ // CSV 格式做 sniff —— JSON 格式正常成功响应也是 application/json,会误判。
262
+ if (opts.format === "csv" && /application\/json/i.test(contentType)) {
274
263
  try {
275
264
  const parsed = JSON.parse(buf.toString("utf8"));
276
265
  if (parsed.status_code != null && parsed.status_code !== "0") {
@@ -280,7 +269,7 @@ async function exportData(opts) {
280
269
  }
281
270
  catch (err) {
282
271
  // 已经被 extractData 抛成 AppError → 透传;否则 JSON.parse 失败说明 body
283
- // 真的是 CSV / SQL 文本,继续按成功流程走
272
+ // 真的是 CSV 文本,继续按成功流程走
284
273
  if (err instanceof error_1.AppError)
285
274
  throw err;
286
275
  }
@@ -297,167 +286,3 @@ async function exportData(opts) {
297
286
  recordCount,
298
287
  };
299
288
  }
300
- // ── db changelog → InnerAdminListDDLChangelog ──
301
- /**
302
- * 后端:GET /v1/dataloom/app/{appId}/db/changelog?table=&since=&until=&limit=&cursor=&dbBranch=
303
- *
304
- * 时间字段 since/until 由 CLI 端归一化为 ISO 8601 UTC 后透传;后端按 created_at 比较。
305
- */
306
- async function listDDLChangelog(opts) {
307
- const client = (0, http_1.getHttpClient)();
308
- const url = (0, client_1.buildInnerUrl)(opts.appId, "/db/changelog", {
309
- table: opts.table,
310
- since: opts.since,
311
- until: opts.until,
312
- limit: opts.limit !== undefined ? String(opts.limit) : undefined,
313
- cursor: opts.cursor,
314
- dbBranch: opts.dbBranch,
315
- });
316
- const start = Date.now();
317
- let response;
318
- try {
319
- response = await client.get(url);
320
- (0, client_1.traceHttp)("GET", url, start, response);
321
- }
322
- catch (err) {
323
- (0, client_1.traceHttp)("GET", url, start, err instanceof http_client_1.HttpError ? err.response : undefined, err);
324
- await mapDbHttpError(err, url, "Failed to list DDL changelog");
325
- throw err; // 不可达
326
- }
327
- const body = (await response.json());
328
- const data = (0, client_1.extractData)(body);
329
- return {
330
- items: data.items ?? [],
331
- nextCursor: data.nextCursor && data.nextCursor !== "" ? data.nextCursor : null,
332
- hasMore: Boolean(data.hasMore),
333
- };
334
- }
335
- // ── db audit → InnerAdminSetAuditConfig ──
336
- /**
337
- * 后端:POST /v1/dataloom/app/{appId}/db/audit/config
338
- * 写:enabled=true 开启 / false 关闭。retention 仅 enabled=true 生效。
339
- *
340
- * 读路径(status / log)不在此模块——CLI handler 走 execSql 直接 SELECT
341
- * `_dl_audit_config` / `_dl_audit_log` 元数据表。
342
- */
343
- async function setAuditConfig(opts) {
344
- const client = (0, http_1.getHttpClient)();
345
- const url = (0, client_1.buildInnerUrl)(opts.appId, "/db/audit/config");
346
- const body = {
347
- table: opts.table,
348
- enabled: opts.enabled,
349
- };
350
- if (opts.retention !== undefined && opts.retention !== "")
351
- body.retention = opts.retention;
352
- if (opts.dbBranch !== undefined && opts.dbBranch !== "")
353
- body.dbBranch = opts.dbBranch;
354
- const start = Date.now();
355
- let response;
356
- try {
357
- response = await client.post(url, body);
358
- (0, client_1.traceHttp)("POST", url, start, response);
359
- }
360
- catch (err) {
361
- (0, client_1.traceHttp)("POST", url, start, err instanceof http_client_1.HttpError ? err.response : undefined, err);
362
- await mapDbHttpError(err, url, "Failed to set audit config");
363
- throw err; // 不可达
364
- }
365
- const respBody = (await response.json());
366
- const data = (0, client_1.extractData)(respBody);
367
- if (!data.status) {
368
- throw new error_1.AppError("INTERNAL_DB_ERROR", "audit config response missing status field");
369
- }
370
- return data.status;
371
- }
372
- // ── db migration → InnerAdminMigrationInit / InnerAdminMigrate ──
373
- /**
374
- * 后端:POST /v1/dataloom/app/{appId}/db/enableMultiEnv
375
- * 单库 → dev/online 双库初始化,不可逆。对应公开 API EnableMultiEnvDB 的 admin-inner 通道。
376
- */
377
- async function migrationInit(opts) {
378
- const client = (0, http_1.getHttpClient)();
379
- const url = (0, client_1.buildInnerUrl)(opts.appId, "/db/enableMultiEnv");
380
- const body = {};
381
- if (opts.syncData !== undefined)
382
- body.syncData = opts.syncData;
383
- const start = Date.now();
384
- let response;
385
- try {
386
- response = await client.post(url, body);
387
- (0, client_1.traceHttp)("POST", url, start, response);
388
- }
389
- catch (err) {
390
- (0, client_1.traceHttp)("POST", url, start, err instanceof http_client_1.HttpError ? err.response : undefined, err);
391
- await mapDbHttpError(err, url, "Failed to init migration");
392
- throw err; // 不可达
393
- }
394
- const respBody = (await response.json());
395
- return (0, client_1.extractData)(respBody);
396
- }
397
- /**
398
- * 后端:POST /v1/dataloom/app/{appId}/db/migration
399
- * 合并 diff + apply:dryRun=true 只返 changes 不下发;dryRun=false 才执行。
400
- */
401
- async function migrate(opts) {
402
- const client = (0, http_1.getHttpClient)();
403
- const url = (0, client_1.buildInnerUrl)(opts.appId, "/db/migration");
404
- const start = Date.now();
405
- let response;
406
- try {
407
- response = await client.post(url, { dryRun: opts.dryRun });
408
- (0, client_1.traceHttp)("POST", url, start, response);
409
- }
410
- catch (err) {
411
- (0, client_1.traceHttp)("POST", url, start, err instanceof http_client_1.HttpError ? err.response : undefined, err);
412
- await mapDbHttpError(err, url, "Failed to migrate");
413
- throw err; // 不可达
414
- }
415
- const respBody = (await response.json());
416
- return (0, client_1.extractData)(respBody);
417
- }
418
- // ── db recovery → InnerAdminRecover ──
419
- /**
420
- * 后端:POST /v1/dataloom/app/{appId}/db/recovery
421
- * 合并 PITR diff + apply:dryRun=true 预览影响;dryRun=false 触发恢复。
422
- */
423
- async function recover(opts) {
424
- const client = (0, http_1.getHttpClient)();
425
- const url = (0, client_1.buildInnerUrl)(opts.appId, "/db/recovery");
426
- const start = Date.now();
427
- let response;
428
- try {
429
- response = await client.post(url, {
430
- target: opts.target,
431
- dryRun: opts.dryRun,
432
- });
433
- (0, client_1.traceHttp)("POST", url, start, response);
434
- }
435
- catch (err) {
436
- (0, client_1.traceHttp)("POST", url, start, err instanceof http_client_1.HttpError ? err.response : undefined, err);
437
- await mapDbHttpError(err, url, "Failed to recover");
438
- throw err; // 不可达
439
- }
440
- const respBody = (await response.json());
441
- return (0, client_1.extractData)(respBody);
442
- }
443
- // ── db quota → InnerAdminGetDbQuota ──
444
- /**
445
- * 后端:GET /v1/dataloom/app/{appId}/db/quota?dbBranch=
446
- */
447
- async function getDbQuota(opts) {
448
- const client = (0, http_1.getHttpClient)();
449
- const url = (0, client_1.buildInnerUrl)(opts.appId, "/db/quota", { dbBranch: opts.dbBranch });
450
- const start = Date.now();
451
- let response;
452
- try {
453
- response = await client.get(url);
454
- (0, client_1.traceHttp)("GET", url, start, response);
455
- }
456
- catch (err) {
457
- (0, client_1.traceHttp)("GET", url, start, err instanceof http_client_1.HttpError ? err.response : undefined, err);
458
- await mapDbHttpError(err, url, "Failed to get db quota");
459
- throw err; // 不可达
460
- }
461
- const respBody = (await response.json());
462
- return (0, client_1.extractData)(respBody);
463
- }
@@ -129,42 +129,6 @@ const BIZ_ERR_MAP = new Map(Object.entries({
129
129
  // k_dl_1300015:SELECT 结果超过 1000 行硬拦;多行 hint 由 output.ts 的
130
130
  // SERVER_ERROR_HINTS 按语义 code 兜底,这里只做 code 改名
131
131
  k_dl_1300015: { code: "RESULT_SET_TOO_LARGE" },
132
- // audit
133
- k_dl_1310001: {
134
- code: "AUDIT_ALREADY_ENABLED",
135
- hint: "Use `miaoda db audit status <table>` to confirm current state.",
136
- },
137
- k_dl_1310002: {
138
- code: "AUDIT_NOT_ENABLED",
139
- hint: "Run `miaoda db audit enable <table>` first.",
140
- },
141
- k_dl_1310003: {
142
- code: "INVALID_RETENTION",
143
- hint: "Allowed values: 7d / 30d / 180d / 360d.",
144
- },
145
- // migration
146
- k_dl_1320001: {
147
- code: "MIGRATION_NOT_AVAILABLE",
148
- hint: "Migration commands require an expert-mode application.",
149
- },
150
- k_dl_1320002: { code: "MULTI_ENV_ALREADY_INITIALIZED" },
151
- k_dl_1320003: {
152
- code: "NO_PENDING_CHANGES",
153
- hint: "dev and online schemas are already in sync.",
154
- },
155
- // recovery
156
- k_dl_1330001: {
157
- code: "RECOVERY_WINDOW_EXCEEDED",
158
- hint: "Pick a timestamp inside the supported recovery window.",
159
- },
160
- k_dl_1330002: {
161
- code: "RECOVERY_IN_PROGRESS",
162
- hint: "Wait for the running recovery to finish, or check its status.",
163
- },
164
- k_dl_1330003: {
165
- code: "INVALID_TIMESTAMP",
166
- hint: "Use ISO 8601 / yyyy-mm-dd / yyyy-mm-dd HH:MM:SS.",
167
- },
168
132
  }));
169
133
  /** PG SQLSTATE → CLI code(当前 dataloom 不一定透传,预留未来使用) */
170
134
  exports.SQLSTATE_MAP = {
@@ -1,17 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.pickTableDetail = exports.flattenSchemaList = exports.parseSqlResult = exports.SQLSTATE_MAP = exports.ensureInnerSuccess = exports.buildInnerUrl = exports.getDbQuota = exports.recover = exports.migrate = exports.migrationInit = exports.setAuditConfig = exports.listDDLChangelog = exports.exportData = exports.importData = exports.getSchema = exports.execSql = void 0;
3
+ exports.pickTableDetail = exports.flattenSchemaList = exports.parseSqlResult = exports.SQLSTATE_MAP = exports.ensureInnerSuccess = exports.buildInnerUrl = exports.exportData = exports.importData = exports.getSchema = exports.execSql = void 0;
4
4
  var api_1 = require("./api");
5
5
  Object.defineProperty(exports, "execSql", { enumerable: true, get: function () { return api_1.execSql; } });
6
6
  Object.defineProperty(exports, "getSchema", { enumerable: true, get: function () { return api_1.getSchema; } });
7
7
  Object.defineProperty(exports, "importData", { enumerable: true, get: function () { return api_1.importData; } });
8
8
  Object.defineProperty(exports, "exportData", { enumerable: true, get: function () { return api_1.exportData; } });
9
- Object.defineProperty(exports, "listDDLChangelog", { enumerable: true, get: function () { return api_1.listDDLChangelog; } });
10
- Object.defineProperty(exports, "setAuditConfig", { enumerable: true, get: function () { return api_1.setAuditConfig; } });
11
- Object.defineProperty(exports, "migrationInit", { enumerable: true, get: function () { return api_1.migrationInit; } });
12
- Object.defineProperty(exports, "migrate", { enumerable: true, get: function () { return api_1.migrate; } });
13
- Object.defineProperty(exports, "recover", { enumerable: true, get: function () { return api_1.recover; } });
14
- Object.defineProperty(exports, "getDbQuota", { enumerable: true, get: function () { return api_1.getDbQuota; } });
15
9
  var client_1 = require("./client");
16
10
  Object.defineProperty(exports, "buildInnerUrl", { enumerable: true, get: function () { return client_1.buildInnerUrl; } });
17
11
  Object.defineProperty(exports, "ensureInnerSuccess", { enumerable: true, get: function () { return client_1.ensureInnerSuccess; } });
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createRelease = createRelease;
4
+ exports.listPipelineInstances = listPipelineInstances;
5
+ exports.getErrorLog = getErrorLog;
6
+ exports.queryPipelineInstance = queryPipelineInstance;
7
+ const http_1 = require("../../utils/http");
8
+ const devops_error_1 = require("../../utils/devops-error");
9
+ const DEFAULT_ERR_CODE = "INTERNAL_DEVOPS_ERROR";
10
+ function envelopeOpts(errPrefix) {
11
+ return {
12
+ errPrefix,
13
+ defaultErrCode: DEFAULT_ERR_CODE,
14
+ // deploy 与 app 走同一个 PSM;业务码映射复用
15
+ mapErr: devops_error_1.mapDevopsError,
16
+ };
17
+ }
18
+ /** POST /v1/devops/app/:appID/release — 触发发布 */
19
+ async function createRelease(req) {
20
+ const url = `/v1/devops/app/${encodeURIComponent(req.appID)}/release`;
21
+ return (0, http_1.postInnerApi)(url, req, envelopeOpts("Failed to create release"));
22
+ }
23
+ /**
24
+ * POST /v1/pipeline/app/:appID/instance/list — 分页查询发布历史
25
+ *
26
+ * 走 lark.apaas.devops_platform PSM(同 queryPipelineInstance)。
27
+ * 不复用 mapDevopsError——那是 lark.apaas.devops 的业务码映射。
28
+ */
29
+ async function listPipelineInstances(req) {
30
+ const url = `/v1/pipeline/app/${encodeURIComponent(req.appID)}/instance/list`;
31
+ return (0, http_1.postInnerApi)(url, req, {
32
+ errPrefix: "Failed to list deploys",
33
+ defaultErrCode: DEFAULT_ERR_CODE,
34
+ });
35
+ }
36
+ /**
37
+ * GET /v1/pipeline/app/:appID/instance/:instanceID/error_log — 获取发布错误日志
38
+ *
39
+ * 走 lark.apaas.devops_platform PSM;instanceID 即 pipelineTaskID == deploy-id。
40
+ * BAM CliGetToolInstanceErrorJobs(4073972),路径段无 body。
41
+ */
42
+ async function getErrorLog(req) {
43
+ const url = `/v1/pipeline/app/${encodeURIComponent(req.appID)}/instance/${encodeURIComponent(req.instanceID)}/error_log`;
44
+ return (0, http_1.getInnerApi)(url, {
45
+ errPrefix: "Failed to get error log",
46
+ defaultErrCode: DEFAULT_ERR_CODE,
47
+ });
48
+ }
49
+ /**
50
+ * GET /v1/pipeline/app/:appID/instance/:instanceID/detail — 轮询发布状态
51
+ *
52
+ * 走 lark.apaas.devops_platform PSM;URL 前缀不同但共用同一管理端 gateway。
53
+ */
54
+ async function queryPipelineInstance(req) {
55
+ const url = `/v1/pipeline/app/${encodeURIComponent(req.appID)}/instance/${encodeURIComponent(req.instanceID)}/detail`;
56
+ return (0, http_1.getInnerApi)(url, {
57
+ errPrefix: "Failed to query pipeline",
58
+ defaultErrCode: DEFAULT_ERR_CODE,
59
+ });
60
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NodeStatus = exports.nodeStatusFromText = exports.nodeStatusText = exports.errorJobSchema = exports.deployGetSchema = exports.deployHistorySchema = exports.queryPipelineInstance = exports.getErrorLog = exports.listPipelineInstances = exports.createRelease = void 0;
4
+ var api_1 = require("./api");
5
+ Object.defineProperty(exports, "createRelease", { enumerable: true, get: function () { return api_1.createRelease; } });
6
+ Object.defineProperty(exports, "listPipelineInstances", { enumerable: true, get: function () { return api_1.listPipelineInstances; } });
7
+ Object.defineProperty(exports, "getErrorLog", { enumerable: true, get: function () { return api_1.getErrorLog; } });
8
+ Object.defineProperty(exports, "queryPipelineInstance", { enumerable: true, get: function () { return api_1.queryPipelineInstance; } });
9
+ var schemas_1 = require("./schemas");
10
+ Object.defineProperty(exports, "deployHistorySchema", { enumerable: true, get: function () { return schemas_1.deployHistorySchema; } });
11
+ Object.defineProperty(exports, "deployGetSchema", { enumerable: true, get: function () { return schemas_1.deployGetSchema; } });
12
+ Object.defineProperty(exports, "errorJobSchema", { enumerable: true, get: function () { return schemas_1.errorJobSchema; } });
13
+ Object.defineProperty(exports, "nodeStatusText", { enumerable: true, get: function () { return schemas_1.nodeStatusText; } });
14
+ Object.defineProperty(exports, "nodeStatusFromText", { enumerable: true, get: function () { return schemas_1.nodeStatusFromText; } });
15
+ var types_1 = require("./types");
16
+ Object.defineProperty(exports, "NodeStatus", { enumerable: true, get: function () { return types_1.NodeStatus; } });
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.errorJobSchema = exports.deployGetSchema = exports.deployHistorySchema = void 0;
4
+ exports.nodeStatusText = nodeStatusText;
5
+ exports.nodeStatusFromText = nodeStatusFromText;
6
+ const output_1 = require("../../utils/output");
7
+ const types_1 = require("./types");
8
+ const NODE_STATUS_TEXT = {
9
+ [types_1.NodeStatus.UNSPECIFIED]: "unknown",
10
+ [types_1.NodeStatus.TODO]: "todo",
11
+ [types_1.NodeStatus.RUNNING]: "running",
12
+ [types_1.NodeStatus.SUCCESS]: "success",
13
+ [types_1.NodeStatus.FAILED]: "failed",
14
+ [types_1.NodeStatus.CANCELED]: "canceled",
15
+ [types_1.NodeStatus.HOLD_ON]: "hold_on",
16
+ };
17
+ function nodeStatusText(v) {
18
+ if (typeof v !== "number")
19
+ return undefined;
20
+ return NODE_STATUS_TEXT[v];
21
+ }
22
+ /** NodeStatus 文本(CLI flag 字符串)→ 枚举数值 */
23
+ function nodeStatusFromText(text) {
24
+ const lower = text.toLowerCase();
25
+ for (const [num, label] of Object.entries(NODE_STATUS_TEXT)) {
26
+ if (label === lower)
27
+ return Number(num);
28
+ }
29
+ return undefined;
30
+ }
31
+ function pipelineDurationMs(row) {
32
+ // SimpleInstance.createdAt / updatedAt:BAM IDL 未注单位,e2e 看是 ms。
33
+ const start = Number(row.createdAt);
34
+ const end = Number(row.updatedAt);
35
+ if (!Number.isFinite(start) || !Number.isFinite(end))
36
+ return undefined;
37
+ return end - start;
38
+ }
39
+ /**
40
+ * deploy history 列表的 pretty 渲染契约。
41
+ *
42
+ * BAM 返回 SimpleInstance(pipeline 实例),状态走 NodeStatus。
43
+ * 默认列:deploy-id(=ID)/ status / creator / created-at / duration(updatedAt-createdAt)。
44
+ */
45
+ exports.deployHistorySchema = {
46
+ columns: [
47
+ { key: "ID", label: "deploy-id" },
48
+ {
49
+ key: "status_text",
50
+ label: "status",
51
+ derive: (row) => nodeStatusText(row.status),
52
+ },
53
+ { key: "creator", label: "creator" },
54
+ { key: "createdAt", label: "created-at", format: output_1.fmt.ms() },
55
+ {
56
+ key: "duration",
57
+ label: "duration",
58
+ format: output_1.fmt.durationMs(),
59
+ derive: pipelineDurationMs,
60
+ },
61
+ ],
62
+ strict: true,
63
+ };
64
+ /**
65
+ * deploy get 单条详情的 key-value 渲染契约(基于 SimpleInstance)。
66
+ *
67
+ * 由于 BAM 没有 by-ID 的查询接口,handler 用 listPipelineInstances 在最近窗口
68
+ * 里筛一条 SimpleInstance 透传过来。
69
+ */
70
+ exports.deployGetSchema = {
71
+ columns: [
72
+ { key: "ID", label: "deploy-id" },
73
+ {
74
+ key: "status_text",
75
+ label: "status",
76
+ derive: (row) => nodeStatusText(row.status),
77
+ },
78
+ { key: "creator", label: "creator" },
79
+ { key: "updater", label: "updater" },
80
+ { key: "createdAt", label: "created-at", format: output_1.fmt.ms() },
81
+ { key: "updatedAt", label: "updated-at", format: output_1.fmt.ms() },
82
+ {
83
+ key: "duration",
84
+ label: "duration",
85
+ format: output_1.fmt.durationMs(),
86
+ derive: pipelineDurationMs,
87
+ },
88
+ { key: "templateID", label: "template" },
89
+ { key: "description" },
90
+ { key: "parameters" },
91
+ { key: "envVariables", label: "env-vars" },
92
+ ],
93
+ strict: true,
94
+ };
95
+ /** deploy error-log 表格渲染契约 */
96
+ exports.errorJobSchema = {
97
+ columns: [
98
+ { key: "jobID", label: "job-id" },
99
+ { key: "componentName", label: "component" },
100
+ { key: "errorMsg", label: "error", format: output_1.fmt.truncate(120) },
101
+ ],
102
+ strict: true,
103
+ };