@lark-apaas/miaoda-cli 0.1.2-alpha.746290f → 0.1.2-alpha.8bc93eb

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.
@@ -5,6 +5,7 @@ exports.getSchema = getSchema;
5
5
  exports.importData = importData;
6
6
  exports.exportData = exportData;
7
7
  exports.listDDLChangelog = listDDLChangelog;
8
+ exports.getAuditStatus = getAuditStatus;
8
9
  exports.setAuditConfig = setAuditConfig;
9
10
  exports.migrationInit = migrationInit;
10
11
  exports.migrate = migrate;
@@ -332,13 +333,35 @@ async function listDDLChangelog(opts) {
332
333
  hasMore: Boolean(data.hasMore),
333
334
  };
334
335
  }
335
- // ── db audit → InnerAdminSetAuditConfig ──
336
+ // ── db audit → InnerAdminGetAuditStatus / InnerAdminSetAuditConfig ──
337
+ /**
338
+ * 后端:GET /v1/dataloom/app/{appId}/db/audit/status?table=&dbBranch=
339
+ * 查表审计开关状态。table 非空 → 单表过滤;空 → 返当前 workspace 全部已配置表。
340
+ */
341
+ async function getAuditStatus(opts) {
342
+ const client = (0, http_1.getHttpClient)();
343
+ const url = (0, client_1.buildInnerUrl)(opts.appId, "/db/audit/status", {
344
+ table: opts.table,
345
+ dbBranch: opts.dbBranch,
346
+ });
347
+ const start = Date.now();
348
+ let response;
349
+ try {
350
+ response = await client.get(url);
351
+ (0, client_1.traceHttp)("GET", url, start, response);
352
+ }
353
+ catch (err) {
354
+ (0, client_1.traceHttp)("GET", url, start, err instanceof http_client_1.HttpError ? err.response : undefined, err);
355
+ await mapDbHttpError(err, url, "Failed to get audit status");
356
+ throw err; // 不可达
357
+ }
358
+ const respBody = (await response.json());
359
+ const data = (0, client_1.extractData)(respBody);
360
+ return data.items ?? [];
361
+ }
336
362
  /**
337
363
  * 后端:POST /v1/dataloom/app/{appId}/db/audit/config
338
364
  * 写:enabled=true 开启 / false 关闭。retention 仅 enabled=true 生效。
339
- *
340
- * 读路径(status / log)不在此模块——CLI handler 走 execSql 直接 SELECT
341
- * `_dl_audit_config` / `_dl_audit_log` 元数据表。
342
365
  */
343
366
  async function setAuditConfig(opts) {
344
367
  const client = (0, http_1.getHttpClient)();
@@ -1,12 +1,13 @@
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.getDbQuota = exports.recover = exports.migrate = exports.migrationInit = exports.setAuditConfig = exports.getAuditStatus = exports.listDDLChangelog = 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
9
  Object.defineProperty(exports, "listDDLChangelog", { enumerable: true, get: function () { return api_1.listDDLChangelog; } });
10
+ Object.defineProperty(exports, "getAuditStatus", { enumerable: true, get: function () { return api_1.getAuditStatus; } });
10
11
  Object.defineProperty(exports, "setAuditConfig", { enumerable: true, get: function () { return api_1.setAuditConfig; } });
11
12
  Object.defineProperty(exports, "migrationInit", { enumerable: true, get: function () { return api_1.migrationInit; } });
12
13
  Object.defineProperty(exports, "migrate", { enumerable: true, get: function () { return api_1.migrate; } });
@@ -40,6 +40,7 @@ exports.handleDbAuditList = handleDbAuditList;
40
40
  const api = __importStar(require("../../../api/index"));
41
41
  const index_1 = require("../../../api/file/index");
42
42
  const shared_1 = require("../../../cli/commands/shared");
43
+ const colors_1 = require("../../../utils/colors");
43
44
  const error_1 = require("../../../utils/error");
44
45
  const output_1 = require("../../../utils/output");
45
46
  const render_1 = require("../../../utils/render");
@@ -47,34 +48,30 @@ const index_2 = require("../../../api/db/index");
47
48
  const VALID_RETENTION = new Set(["7d", "30d", "180d", "360d", "forever"]);
48
49
  async function handleDbAuditStatus(table, opts) {
49
50
  const appId = (0, shared_1.resolveAppId)(opts);
50
- const sql = table !== undefined && table !== ""
51
- ? `SELECT "table", enabled, enabled_at, retention FROM _dl_audit_config WHERE "table" = '${escapeSqlLiteral(table)}'`
52
- : `SELECT "table", enabled, enabled_at, retention FROM _dl_audit_config ORDER BY "table"`;
53
- const results = await api.db.execSql({ appId, sql, dbBranch: opts.env });
54
- const rows = collectSelectRows(results);
55
- // 单表查询且 _dl_audit_config 没记录 → enabled=false 占位
51
+ const items = await api.db.getAuditStatus({ appId, table, dbBranch: opts.env });
52
+ const rows = items.map(toAuditStatus);
53
+ // 单表查询但后端没记录 占位 enabled=false
56
54
  if (table !== undefined && table !== "" && rows.length === 0) {
57
- rows.push({ table, enabled: false });
55
+ rows.push({ table, enabled: false, enabled_at: null, retention: null });
58
56
  }
59
- const items = rows.map(toAuditStatus);
60
57
  // PRD JSON:单表返 object,多表返 array
61
58
  if ((0, output_1.isJsonMode)()) {
62
- if (table !== undefined && items.length === 1) {
63
- (0, output_1.emitOk)((0, output_1.snakeCaseKeys)(items[0]));
59
+ if (table !== undefined && rows.length === 1) {
60
+ (0, output_1.emitOk)((0, output_1.snakeCaseKeys)(rows[0]));
64
61
  }
65
62
  else {
66
- (0, output_1.emitOk)((0, output_1.snakeCaseKeys)(items));
63
+ (0, output_1.emitOk)((0, output_1.snakeCaseKeys)(rows));
67
64
  }
68
65
  return;
69
66
  }
70
- if (items.length === 0) {
67
+ if (rows.length === 0) {
71
68
  (0, output_1.emit)("No audit configuration found.");
72
69
  return;
73
70
  }
74
71
  const tty = (0, render_1.isStdoutTty)();
75
- // 单表 → key:value 形态(PRD 示例)
76
- if (table !== undefined && items.length === 1) {
77
- const it = items[0];
72
+ // 单表 → key:value 形态
73
+ if (table !== undefined && rows.length === 1) {
74
+ const it = rows[0];
78
75
  (0, output_1.emit)((0, render_1.renderKeyValue)([
79
76
  ["Table", it.table],
80
77
  ["Enabled", boolToYesNo(it.enabled)],
@@ -85,7 +82,7 @@ async function handleDbAuditStatus(table, opts) {
85
82
  }
86
83
  // 列表 → table 形态
87
84
  const headers = ["table", "enabled", "enabled_at", "retention"];
88
- const out = items.map((it) => [
85
+ const out = rows.map((it) => [
89
86
  it.table,
90
87
  boolToYesNo(it.enabled),
91
88
  it.enabled_at ? (0, render_1.formatTime)(it.enabled_at, tty) : "—",
@@ -93,24 +90,12 @@ async function handleDbAuditStatus(table, opts) {
93
90
  ]);
94
91
  (0, output_1.emit)(tty ? (0, render_1.renderAlignedTable)(headers, out) : (0, render_1.renderTsv)(headers, out));
95
92
  }
96
- function toAuditStatus(row) {
97
- // retention 列存的是后端 ValidDay (int64 天数),按 sentinel 反向映射成 PRD 字符串
98
- const rawRetention = row.retention;
99
- let retention = null;
100
- if (rawRetention != null) {
101
- if (typeof rawRetention === "number") {
102
- retention = retentionDaysToString(rawRetention);
103
- }
104
- else if (typeof rawRetention === "string") {
105
- // 兼容存的就是字符串形态("7d" / "forever")
106
- retention = rawRetention;
107
- }
108
- }
93
+ function toAuditStatus(s) {
109
94
  return {
110
- table: asString(row.table),
111
- enabled: Boolean(row.enabled),
112
- enabled_at: row.enabled_at == null ? null : asString(row.enabled_at),
113
- retention,
95
+ table: s.table,
96
+ enabled: s.enabled,
97
+ enabled_at: s.enabledAt ?? null,
98
+ retention: s.retention ?? null,
114
99
  };
115
100
  }
116
101
  async function handleDbAuditEnable(table, opts) {
@@ -146,7 +131,9 @@ async function handleDbAuditEnable(table, opts) {
146
131
  }
147
132
  const tty = (0, render_1.isStdoutTty)();
148
133
  const prefix = tty ? "✓" : "OK";
149
- (0, output_1.emit)(`${prefix} Audit enabled for table '${status.table}' (retention: ${status.retention ?? retention})`);
134
+ // c.highlight 内部按 TTY/NO_COLOR/FORCE_COLOR 自动决定是否染色,无需再判 tty
135
+ const tableLabel = colors_1.c.highlight(`'${status.table}'`);
136
+ (0, output_1.emit)(`${prefix} Audit enabled for table ${tableLabel} (retention: ${status.retention ?? retention})`);
150
137
  }
151
138
  async function handleDbAuditDisable(table, opts) {
152
139
  if (!table) {
@@ -170,7 +157,7 @@ async function handleDbAuditDisable(table, opts) {
170
157
  }
171
158
  const tty = (0, render_1.isStdoutTty)();
172
159
  const prefix = tty ? "✓" : "OK";
173
- (0, output_1.emit)(`${prefix} Audit disabled for table '${status.table}'`);
160
+ (0, output_1.emit)(`${prefix} Audit disabled for table ${colors_1.c.highlight(`'${status.table}'`)}`);
174
161
  }
175
162
  async function handleDbAuditList(tables, opts) {
176
163
  if (tables.length === 0) {
@@ -285,20 +272,6 @@ function escapeSqlLiteral(s) {
285
272
  function boolToYesNo(b) {
286
273
  return b ? "yes" : "no";
287
274
  }
288
- // 后端 ValidDay (int64 天数) → PRD retention 字符串。-1 = 永久(前端 / 后端约定)
289
- function retentionDaysToString(days) {
290
- if (days === -1)
291
- return "forever";
292
- if (days === 7)
293
- return "7d";
294
- if (days === 30)
295
- return "30d";
296
- if (days === 180)
297
- return "180d";
298
- if (days === 360)
299
- return "360d";
300
- return `${String(days)}d`;
301
- }
302
275
  function asString(v, fallback = "") {
303
276
  if (v == null)
304
277
  return fallback;
@@ -42,7 +42,17 @@ async function handleDbQuota(opts) {
42
42
  const appId = (0, shared_1.resolveAppId)(opts);
43
43
  const data = await api.db.getDbQuota({ appId, dbBranch: opts.env });
44
44
  if ((0, output_1.isJsonMode)()) {
45
- (0, output_1.emitOk)((0, output_1.snakeCaseKeys)(data));
45
+ // 配额未对接(storageQuotaBytes=0)时,quota / usage_percent 字段都不输出
46
+ const out = {
47
+ storageUsedBytes: data.storageUsedBytes,
48
+ tables: data.tables,
49
+ views: data.views,
50
+ };
51
+ if (data.storageQuotaBytes > 0) {
52
+ out.storageQuotaBytes = data.storageQuotaBytes;
53
+ out.usagePercent = data.usagePercent;
54
+ }
55
+ (0, output_1.emitOk)((0, output_1.snakeCaseKeys)(out));
46
56
  return;
47
57
  }
48
58
  // PRD:单行 "Storage: 14.9 MB / 1 GB (1.5%)";配额未对接时只显示 used
@@ -42,7 +42,16 @@ async function handleFileQuota(opts) {
42
42
  const appId = (0, shared_1.resolveAppId)(opts);
43
43
  const data = await api.file.getStorageQuota({ appId });
44
44
  if ((0, output_1.isJsonMode)()) {
45
- (0, output_1.emitOk)((0, output_1.snakeCaseKeys)(data));
45
+ // 配额未对接(storageQuotaBytes=0)时,quota / usage_percent 字段都不输出
46
+ const out = {
47
+ storageUsedBytes: data.storageUsedBytes,
48
+ files: data.files,
49
+ };
50
+ if (data.storageQuotaBytes > 0) {
51
+ out.storageQuotaBytes = data.storageQuotaBytes;
52
+ out.usagePercent = data.usagePercent;
53
+ }
54
+ (0, output_1.emitOk)((0, output_1.snakeCaseKeys)(out));
46
55
  return;
47
56
  }
48
57
  // PRD:单行 "Storage: 150 MB / 1 GB (15%)";配额未对接时只显示 used
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/miaoda-cli",
3
- "version": "0.1.2-alpha.746290f",
3
+ "version": "0.1.2-alpha.8bc93eb",
4
4
  "description": "Miaoda 平台命令行工具,面向 Agent 调用",
5
5
  "type": "commonjs",
6
6
  "bin": {