bfi-cli 0.1.75 → 0.1.76

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 +195 -4
  2. package/package.json +1 -1
package/dist/cli.mjs CHANGED
@@ -8240,7 +8240,7 @@ async function runYmc(args, globalOpts) {
8240
8240
  const token = globalOpts.token;
8241
8241
  const api = new YmcApi(token ?? null, void 0, dryRun);
8242
8242
  if (!sub || sub === "--help" || sub === "-h") {
8243
- printHelp$1();
8243
+ printHelp$2();
8244
8244
  return;
8245
8245
  }
8246
8246
  if (sub === "help") {
@@ -8806,7 +8806,7 @@ async function runYmc(args, globalOpts) {
8806
8806
  }
8807
8807
  default:
8808
8808
  console.error(`未知子命令:${sub}`);
8809
- printHelp$1();
8809
+ printHelp$2();
8810
8810
  process.exit(1);
8811
8811
  }
8812
8812
  }
@@ -8937,11 +8937,11 @@ function printCommandHelp(cmd) {
8937
8937
  if (h) console.log(h);
8938
8938
  else {
8939
8939
  console.error(`未知子命令:${cmd}`);
8940
- printHelp$1();
8940
+ printHelp$2();
8941
8941
  process.exit(1);
8942
8942
  }
8943
8943
  }
8944
- function printHelp$1() {
8944
+ function printHelp$2() {
8945
8945
  console.log(`
8946
8946
  bfi ymc — 观测查询(v2 API:YMC/Kibana/SLS/trace)
8947
8947
 
@@ -8985,6 +8985,194 @@ bfi ymc — 观测查询(v2 API:YMC/Kibana/SLS/trace)
8985
8985
  详细帮助:bfi ymc help <命令>(或 bfi ymc <命令> -h)——含参数说明/默认值/示例。
8986
8986
  `);
8987
8987
  }
8988
+ const METRICS = [
8989
+ "entry",
8990
+ "fail",
8991
+ "costtime",
8992
+ "content"
8993
+ ];
8994
+ const RESOURCES = [
8995
+ "type-doc",
8996
+ "type-info",
8997
+ "listener-doc"
8998
+ ];
8999
+ function printHelp$1() {
9000
+ console.log(`bfi event — YonBIP 事件中心取数(诊断编排见 bfi-diagnose-event 技能)
9001
+
9002
+ 用法:
9003
+ bfi event monitor <metric> [过滤参数]
9004
+ metric: entry|fail|costtime|content
9005
+ 过滤: --log-date D --source-id S --event-type-code ET --node-code N --datacenter DC --size N
9006
+ bfi event master <resource> [action[:target]]
9007
+ resource: type-doc|type-info|listener-doc
9008
+ action[:target]:
9009
+ list | code:<编码> | id:<ID> | latest:<源ID,类型编码> | source-type:<源ID,类型编码>
9010
+ source-node:<源ID,节点编码> | event-type:<类型编码> | micro-service:<微服务编码>
9011
+ bfi event stat <dc> <date> [metric_type] [--page N] [--size N]
9012
+ date: yyyy-MM-dd 单日;metric_type: enter|fail|response_time_4s_|response_time_2s_4s|body_size_512k_1m|body_size_1m_
9013
+ bfi event record <dc> <date> --source-id S --event-type ET --node-code N --ds-code DS [--record-status fail] [--record-id ID] [--tenant-code T] [--size ≤20]
9014
+ bfi event content <dc> <date> --event-id E --ds-code DS --tenant-code T
9015
+ bfi event dclist <dc>
9016
+ 全局: --json / --dry-run / --token <tok>
9017
+
9018
+ 示例:
9019
+ bfi event master type-doc code:PC_PRODUCT_STOP
9020
+ bfi event dclist core1
9021
+ bfi event stat core1 2026-09-14 fail
9022
+ bfi event record core1 2026-09-14 --source-id MULILANG --event-type MULILANGCHANGE --node-code N --ds-code YonBip_core1_2_service`);
9023
+ }
9024
+ function missing(name) {
9025
+ console.error(`缺少参数 ${name}。运行 bfi event --help 查看用法。`);
9026
+ process.exit(1);
9027
+ }
9028
+ async function runEvent(args, globalOpts) {
9029
+ const sub = args[0];
9030
+ const rest = args.slice(1);
9031
+ if (!sub || sub === "--help" || sub === "-h" || flag(rest, "--help") || flag(rest, "-h")) {
9032
+ printHelp$1();
9033
+ return;
9034
+ }
9035
+ const jsonMode = flag(rest, "--json");
9036
+ const dryRun = flag(rest, "--dry-run");
9037
+ const api = new YmcApi(globalOpts.token ?? null, void 0, dryRun);
9038
+ if (!dryRun && !api.token) {
9039
+ console.error("未认证。先运行:bfi auth login --token <sk-token>(或传 --token)");
9040
+ process.exit(1);
9041
+ }
9042
+ const reqs = positionals(rest);
9043
+ const call = async (path, body) => emit(await api.call(path, body), jsonMode);
9044
+ const num = (name, dflt) => Number(opt(rest, name) ?? dflt);
9045
+ const str = (name) => opt(rest, name);
9046
+ if (sub === "monitor") {
9047
+ const metric = reqs[0];
9048
+ if (!metric || !METRICS.includes(metric)) {
9049
+ console.error("缺少/无效 metric(entry|fail|costtime|content)。例:bfi event monitor fail");
9050
+ process.exit(1);
9051
+ }
9052
+ const body = {
9053
+ metric,
9054
+ size: num("--size", 200)
9055
+ };
9056
+ for (const [cliName, key] of Object.entries({
9057
+ "--log-date": "log_date",
9058
+ "--source-id": "source_id",
9059
+ "--event-type-code": "event_type_code",
9060
+ "--node-code": "node_code",
9061
+ "--datacenter": "datacenter"
9062
+ })) {
9063
+ const v = str(cliName);
9064
+ if (v) body[key] = v;
9065
+ }
9066
+ await call("event/monitor", body);
9067
+ return;
9068
+ }
9069
+ if (sub === "master") {
9070
+ const resource = reqs[0];
9071
+ if (!resource || !RESOURCES.includes(resource)) {
9072
+ console.error("缺少/无效 resource(type-doc|type-info|listener-doc)。例:bfi event master type-doc code:PC_PRODUCT_STOP");
9073
+ process.exit(1);
9074
+ }
9075
+ let action = "list";
9076
+ let target;
9077
+ const second = reqs[1];
9078
+ if (second && second.includes(":")) {
9079
+ const i = second.indexOf(":");
9080
+ action = second.slice(0, i);
9081
+ target = second.slice(i + 1);
9082
+ } else if (second) {
9083
+ action = "code";
9084
+ target = second;
9085
+ }
9086
+ await call("event/master", {
9087
+ resource,
9088
+ action,
9089
+ target,
9090
+ query: {
9091
+ page: num("--page", 0),
9092
+ size: num("--size", 200)
9093
+ }
9094
+ });
9095
+ return;
9096
+ }
9097
+ if (sub === "stat") {
9098
+ const dc = reqs[0];
9099
+ const date = reqs[1];
9100
+ if (!dc || !date) {
9101
+ console.error("用法: bfi event stat <dc> <date> [metric_type]");
9102
+ process.exit(1);
9103
+ }
9104
+ await call("event/stat", {
9105
+ dc,
9106
+ date,
9107
+ metric_type: reqs[2] ?? "fail",
9108
+ page: num("--page", 0),
9109
+ size: num("--size", 1e3)
9110
+ });
9111
+ return;
9112
+ }
9113
+ if (sub === "record") {
9114
+ const dc = reqs[0];
9115
+ const date = reqs[1];
9116
+ if (!dc || !date) {
9117
+ console.error("用法: bfi event record <dc> <date> --source-id S --event-type ET --node-code N --ds-code DS");
9118
+ process.exit(1);
9119
+ }
9120
+ const sourceId = str("--source-id");
9121
+ const eventType = str("--event-type");
9122
+ const nodeCode = str("--node-code");
9123
+ const dsCode = str("--ds-code");
9124
+ if (!sourceId) missing("--source-id");
9125
+ if (!eventType) missing("--event-type");
9126
+ if (!nodeCode) missing("--node-code");
9127
+ if (!dsCode) missing("--ds-code");
9128
+ const body = {
9129
+ dc,
9130
+ date,
9131
+ source_id: sourceId,
9132
+ event_type: eventType,
9133
+ node_code: nodeCode,
9134
+ ds_code: dsCode,
9135
+ record_status: str("--record-status") ?? "fail",
9136
+ size: num("--size", 20)
9137
+ };
9138
+ const rid = str("--record-id");
9139
+ if (rid) body.record_id = rid;
9140
+ const tc = str("--tenant-code");
9141
+ if (tc) body.tenant_code = tc;
9142
+ await call("event/record", body);
9143
+ return;
9144
+ }
9145
+ if (sub === "content") {
9146
+ const dc = reqs[0];
9147
+ const date = reqs[1];
9148
+ const eventId = str("--event-id");
9149
+ const dsCode = str("--ds-code");
9150
+ const tenantCode = str("--tenant-code");
9151
+ if (!dc || !date || !eventId || !dsCode || !tenantCode) {
9152
+ console.error("用法: bfi event content <dc> <date> --event-id E --ds-code DS --tenant-code T");
9153
+ process.exit(1);
9154
+ }
9155
+ await call("event/content", {
9156
+ dc,
9157
+ date,
9158
+ event_id: eventId,
9159
+ ds_code: dsCode,
9160
+ tenant_code: tenantCode
9161
+ });
9162
+ return;
9163
+ }
9164
+ if (sub === "dclist") {
9165
+ const dc = reqs[0];
9166
+ if (!dc) {
9167
+ console.error("用法: bfi event dclist <dc>");
9168
+ process.exit(1);
9169
+ }
9170
+ await call("event/dclist", { dc });
9171
+ return;
9172
+ }
9173
+ console.error(`未知子命令: ${sub}。运行 bfi event --help`);
9174
+ process.exit(1);
9175
+ }
8988
9176
  function loadSourceMapConsumer() {
8989
9177
  return createRequire(import.meta.url)("source-map").SourceMapConsumer;
8990
9178
  }
@@ -9670,6 +9858,9 @@ async function main() {
9670
9858
  case "fe-locate":
9671
9859
  await runFeLocate(restArgs, globalOpts);
9672
9860
  break;
9861
+ case "event":
9862
+ await runEvent(restArgs, globalOpts);
9863
+ break;
9673
9864
  case "auth":
9674
9865
  if (restArgs[0] === "logout") await runLogout();
9675
9866
  else if (restArgs[0] === "whoami") await runWhoami(globalOpts);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bfi-cli",
3
- "version": "0.1.75",
3
+ "version": "0.1.76",
4
4
  "description": "用友大业财BFI统一命令行工具,支持技能,技能包,元数据,UI元数据等",
5
5
  "type": "module",
6
6
  "bin": {