@newbeebox/newbeebox-app-engine-cli 1.3.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/README.md CHANGED
@@ -80,6 +80,7 @@ nae apps
80
80
  nae create --app-id myweb --tag latest --port 8080 \
81
81
  --cpu 500m --mem 512Mi --env '{"FOO":"bar"}'
82
82
  # 自带 basePath 的框架(如 Next.js)加 --keep-path-prefix
83
+ # 仅内部访问(不导出外链,只在集群内经 DNS+端口调用)加 --internal-only(创建后不可改)
83
84
  ```
84
85
 
85
86
  创建模板应用:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@newbeebox/newbeebox-app-engine-cli",
3
- "version": "1.3.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.3.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')
@@ -199,6 +200,7 @@ program
199
200
  .option('--mem <limit>', '内存上限,如 512Mi / 1Gi')
200
201
  .option('--max-restarts <n>', '失败重启上限,0=不封顶', (v) => parseInt(v, 10))
201
202
  .option('--keep-path-prefix', '不剥离 /apps/<appid> 前缀(自带 basePath 的框架用)')
203
+ .option('--internal-only', '普通应用:不导出外部链接,只在集群内经 DNS+端口访问(创建后不可改)')
202
204
  .option('--template <key>', '模板应用:模板 key')
203
205
  .option('--storage <size>', '模板应用:持久卷大小,如 10Gi')
204
206
  .option('--replicas <n>', '副本数', (v) => parseInt(v, 10))
@@ -219,6 +221,9 @@ program
219
221
  # 自带 basePath 的框架(Next.js Node server 等):保留 /apps/<appid> 前缀
220
222
  nae create --app-id mynext --tag latest --port 3000 --keep-path-prefix
221
223
 
224
+ # 仅内部访问:不导出外部链接,只在集群内经 DNS+端口被其它应用调用(如后端 API)
225
+ nae create --app-id myapi --tag latest --port 8080 --internal-only
226
+
222
227
  # 模板应用 Redis:--config 取该模板的服务特性参数(见 nae templates)
223
228
  nae create --kind template --app-id myredis --template redis --storage 2Gi \\
224
229
  --config '{"password":"s3cret","persistence":"rdb"}'
@@ -244,6 +249,7 @@ program
244
249
  mem_limit: opts.mem,
245
250
  max_restarts: opts.maxRestarts,
246
251
  keep_path_prefix: opts.keepPathPrefix || undefined,
252
+ internal_only: opts.internalOnly || undefined,
247
253
  template_key: opts.template,
248
254
  storage_size: opts.storage,
249
255
  replicas: opts.replicas,
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