bfi-cli 0.1.73 → 0.1.74

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 (2) hide show
  1. package/dist/cli.mjs +71 -6
  2. package/package.json +1 -1
package/dist/cli.mjs CHANGED
@@ -8058,6 +8058,7 @@ var YmcApi = class {
8058
8058
  if (Object.keys(body).length > 0) console.log(JSON.stringify(body, null, 2));
8059
8059
  process.exit(0);
8060
8060
  }
8061
+ if (!this.token) throw new Error("未配置 API token:请 `bfi auth login --token <token>` 或 export BFI_TOKEN");
8061
8062
  const url = `${this.baseUrl}/${path.replace(/^\//, "")}`;
8062
8063
  const payload = JSON.stringify(body);
8063
8064
  const mod = url.startsWith("https://") ? https : http;
@@ -8159,27 +8160,58 @@ function emit(result, jsonMode, summarize) {
8159
8160
  function raw0(text) {
8160
8161
  return text || "{}";
8161
8162
  }
8162
- const ENV_DOC = "环境: test/daily/pre/core1-4/commldev";
8163
+ const ENV_DOC = "环境: test/daily/pre/core1/core2/core3/core4/commldev";
8164
+ const VALID_ENVS = [
8165
+ "test",
8166
+ "daily",
8167
+ "pre",
8168
+ "core1",
8169
+ "core2",
8170
+ "core3",
8171
+ "core4",
8172
+ "commldev"
8173
+ ];
8174
+ const TIME_RE = /^\d+(m|h|d|w)$/;
8175
+ function envError(env) {
8176
+ if (!env || !env.trim()) return `缺少环境参数:-e <${ENV_DOC}>`;
8177
+ if (!VALID_ENVS.includes(env.toLowerCase())) return `环境参数无效:收到 '${env}'\n合法值:${VALID_ENVS.join(" | ")}(若为新环境请升级 bfi CLI)\n例:bfi ymc slowsql -t 1d --app yonbip-scm-scmmp -e core3`;
8178
+ return null;
8179
+ }
8180
+ function timeError(t) {
8181
+ if (!t || !t.trim()) return `缺少时间参数:-t <简写>(如 1h/3d/10m/4w,表示过去 N 单位到现在)\n精确窗口:--start-time "yyyy-MM-dd HH:mm:ss" --end-time 同格式(北京时间)`;
8182
+ if (!TIME_RE.test(t)) return `时间简写无效:收到 '${t}'\n合法格式:<N><单位>,单位 m(分)/h(时)/d(天)/w(周),如 10m/2h/3d/4w\n精确窗口:--start-time "yyyy-MM-dd HH:mm:ss" --end-time 同格式(北京时间)`;
8183
+ return null;
8184
+ }
8163
8185
  function requireEnv(args) {
8164
8186
  const env = opt(args, "-e", "--env", "--env-name");
8165
- if (!env) {
8166
- console.error(`缺少环境参数:-e <${ENV_DOC}>`);
8187
+ const err = envError(env);
8188
+ if (err) {
8189
+ console.error(err);
8167
8190
  process.exit(1);
8168
8191
  }
8169
8192
  return { env_name: env };
8170
8193
  }
8171
8194
  function timeOf(args, required = true) {
8172
8195
  const t = opt(args, "-t", "--time");
8173
- if (!t && required) {
8174
- console.error("缺少时间参数:-t <简写>(如 1h/3d/10m/4w,表示过去 N 单位到现在)");
8196
+ const err = timeError(t);
8197
+ if (err && required) {
8198
+ console.error(err);
8175
8199
  process.exit(1);
8176
8200
  }
8201
+ if (t && !err) validateTime(t);
8177
8202
  return t ? { time: t } : {};
8178
8203
  }
8179
8204
  function timeOpts(args) {
8180
8205
  const out = {};
8181
8206
  const t = opt(args, "-t", "--time");
8182
- if (t) out.time = t;
8207
+ if (t) {
8208
+ const err = timeError(t);
8209
+ if (err) {
8210
+ console.error(err);
8211
+ process.exit(1);
8212
+ }
8213
+ out.time = t;
8214
+ }
8183
8215
  const st = opt(args, "--start-time");
8184
8216
  if (st) out.start_time = st;
8185
8217
  const et = opt(args, "--end-time");
@@ -8725,6 +8757,27 @@ async function runYmc(args, globalOpts) {
8725
8757
  }
8726
8758
  break;
8727
8759
  }
8760
+ case "tool-download": {
8761
+ const uploadFileName = positionals(rest)[0];
8762
+ if (!uploadFileName) {
8763
+ console.error("用法:bfi ymc tool-download <uploadFileName> -e <env> [-o 输出文件]");
8764
+ console.error("例:bfi ymc tool-download monitor/17ff7937-xxx.html -e pre -o ~/flame.html");
8765
+ console.error("uploadFileName 来源:bfi ymc call tool/list(uploadPath 字段)或 bfi ymc dump-list(uploadPath)");
8766
+ process.exit(1);
8767
+ }
8768
+ const out = opt(rest, "-o", "--out") || uploadFileName.split("/").pop() || "download.bin";
8769
+ try {
8770
+ const n = await api.download("ymc/tool/download", {
8771
+ ...requireEnv(rest),
8772
+ uploadFileName
8773
+ }, out);
8774
+ console.log(`✓ 已下载 ${n} 字节 → ${out}`);
8775
+ } catch (e) {
8776
+ console.error(`✗ ${e.message}`);
8777
+ process.exit(1);
8778
+ }
8779
+ break;
8780
+ }
8728
8781
  case "call": {
8729
8782
  const route = positionals(rest)[0];
8730
8783
  const dataStr = opt(rest, "--data") || "{}";
@@ -8866,6 +8919,10 @@ const HELP = {
8866
8919
  "bpr-download": `bfi ymc bpr-download <pk> -e <env> [-o <输出文件>]
8867
8920
  BPR 报告 HTML 下载(文件流写盘)。pk 来源:bfi ymc call bpr/list --data '{"page":1,"pageSize":10}' -e <env>。
8868
8921
  输出默认 bpr_<pk前16>.html。`,
8922
+ "tool-download": `bfi ymc tool-download <uploadFileName> -e <env> [-o <输出文件>]
8923
+ 诊断文件内容下载(CPU 火焰图/堆 dump/BPR HTML 等文件流写盘)。
8924
+ uploadFileName 来源:bfi ymc call tool/list(uploadPath)或 bfi ymc dump-list(uploadPath)。
8925
+ 输出默认取文件名部分(monitor/xx.html → xx.html)。`,
8869
8926
  call: `bfi ymc call <route> -e <env> [--data '<json>'] [-t <time> | --start-time <s> --end-time <e>] [--timeout <秒>] [--json]
8870
8927
  通用透传:覆盖全部注册表端点(warningCall/warningSql/exceptionHistory/bpr/list/alert/detail/tool/list/app/history/environment/uba/query ...)。
8871
8928
  完整清单与参数声明:curl http://172.20.35.178:8901/openapi.json 或 /docs(Swagger UI)。
@@ -8887,6 +8944,8 @@ function printHelp() {
8887
8944
  console.log(`
8888
8945
  bfi ymc — 观测查询(v2 API:YMC/Kibana/SLS/trace)
8889
8946
 
8947
+ 详细帮助/示例:bfi ymc help <命令>(首次使用必看——含参数默认值与易错点)
8948
+
8890
8949
  命令:
8891
8950
  status 登录会话状态(dev/prod)
8892
8951
  trace <trace_id> -e <env> 三源合一(SLS+链路+ingress)
@@ -8902,6 +8961,12 @@ bfi ymc — 观测查询(v2 API:YMC/Kibana/SLS/trace)
8902
8961
  url-stats </uri> -t <time> -e <env> [--app <service_name>]
8903
8962
  ingress --trace-id <id> | --uri </path> [-t <time>] -e <env> [--exact] [--app <service_name>]
8904
8963
  dump-list [-t <time>] -e <env> [--app] [--type profiler]
8964
+ tool-download <uploadPath> -e <env> [-o <文件>] 诊断文件内容下载
8965
+ log-url <...> SLS 直链(日志中心页面直达)
8966
+ events / sample-list 集群事件 / 采样数据列表
8967
+ callstat / sqlstat 慢调用/慢SQL 统计版聚合
8968
+ rca <...> 官方智能诊断 RCA(长耗时)
8969
+ bpr-download <pk> BPR 报告下载
8905
8970
  cases <search|show|upload|index> 案例库(KEDB)
8906
8971
  wiki search "<kw>" [--source] [--titles] 知识库统一检索(wiki/jira/文库)
8907
8972
  wiki show <id> [--source] 知识条目全文
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bfi-cli",
3
- "version": "0.1.73",
3
+ "version": "0.1.74",
4
4
  "description": "用友大业财BFI统一命令行工具,支持技能,技能包,元数据,UI元数据等",
5
5
  "type": "module",
6
6
  "bin": {