@newbeebox/newbeebox-app-engine-cli 1.4.0 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@newbeebox/newbeebox-app-engine-cli",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "description": "NewBee App Engine 命令行客户端(nae)——参数直达、默认人类可读(加 -o json 出 JSON),便于在终端使用与脚本/管道里解析。",
5
5
  "type": "module",
6
6
  "bin": {
package/src/http.js CHANGED
@@ -1,6 +1,7 @@
1
1
  // HTTP 客户端:包 fetch,统一注入 Bearer 密钥、解封 {code,msg,data} 信封、归一错误。
2
2
  // 业务命令只管调 request() 拿 data,错误分类(网络/鉴权/业务)交给这里。
3
3
  import { apiBase } from './config.js'
4
+ import { CLI_VERSION } from './version.js'
4
5
 
5
6
  // ApiError 后端返回的业务错误(HTTP>=400 且带 {code,msg} 信封)。
6
7
  export class ApiError extends Error {
@@ -48,7 +49,7 @@ export async function request(cfg, method, path, opts = {}) {
48
49
  }
49
50
  }
50
51
 
51
- const headers = {}
52
+ const headers = { 'X-NAE-CLI-Version': CLI_VERSION }
52
53
  if (token) headers['Authorization'] = `Bearer ${token}`
53
54
  let body
54
55
  if (opts.body !== undefined) {
package/src/index.js CHANGED
@@ -5,6 +5,7 @@
5
5
  import { readFileSync } from 'fs'
6
6
  import { Command } from 'commander'
7
7
  import { load, save, configPath } from './config.js'
8
+ import { CLI_VERSION } from './version.js'
8
9
  import { request, AuthError, NetworkError } from './http.js'
9
10
  import { runLogin } from './login.js'
10
11
  import { streamLogs } from './logs.js'
@@ -15,7 +16,7 @@ const program = new Command()
15
16
  program
16
17
  .name('nae')
17
18
  .description('NewBee App Engine CLI —— 默认人类可读,-o json 输出 JSON 供脚本解析')
18
- .version('1.4.0')
19
+ .version(CLI_VERSION)
19
20
  .option('--base-url <url>', '覆盖平台地址(也可用环境变量 NAE_BASE_URL)')
20
21
  .option('--token <token>', '覆盖访问密钥(也可用环境变量 NAE_TOKEN)')
21
22
  .option('-o, --output <format>', '输出格式:text(默认,人类可读)| json', 'text')
package/src/version.js ADDED
@@ -0,0 +1,16 @@
1
+ // CLI 版本单一真相:读包自身的 package.json。
2
+ // 之前 package.json 与 index.js 的 .version() 双写易漂移;此处归一,命令行 --version 与
3
+ // 请求头 X-NAE-CLI-Version 共用,永远与发布版本一致。
4
+ import { readFileSync } from 'node:fs'
5
+ import { fileURLToPath } from 'node:url'
6
+ import { dirname, join } from 'node:path'
7
+
8
+ let v = '0.0.0'
9
+ try {
10
+ const pkgPath = join(dirname(fileURLToPath(import.meta.url)), '..', 'package.json')
11
+ v = JSON.parse(readFileSync(pkgPath, 'utf8')).version || v
12
+ } catch {
13
+ // 读不到包元数据(极端打包场景)时回落,不影响功能。
14
+ }
15
+
16
+ export const CLI_VERSION = v