@zrhsh/wukong-cli 0.4.20 → 0.4.23
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 +32 -5
- package/dist/cli.js +118 -30
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
- package/wukong-cli.json.template +1 -1
package/README.md
CHANGED
|
@@ -10,8 +10,9 @@
|
|
|
10
10
|
- 🐛 **调试模式** - 使用 `--debug` 标志显示 HTTP 请求和响应
|
|
11
11
|
- 💾 **安全存储** - 使用平台原生凭据管理器,支持文件回退
|
|
12
12
|
- 🛠️ **HTTP 客户端** - 内置 HTTP 客户端,自动处理认证
|
|
13
|
-
-
|
|
14
|
-
-
|
|
13
|
+
- 🔑 **YST Token 支持** - 自动获取、持久化、刷新 YST 子系统令牌
|
|
14
|
+
- 📋 **Token 信息查看** - 解码 JWT 查看令牌结构和有效期
|
|
15
|
+
- 🚀 **智能路由** - `/yst-` 路径自动使用 YST Token,其他路径使用主 Token
|
|
15
16
|
|
|
16
17
|
## 快速开始
|
|
17
18
|
|
|
@@ -82,6 +83,7 @@ wukong-cli auth login # OAuth Device PKCE Flow 登录
|
|
|
82
83
|
wukong-cli auth status # 显示认证状态
|
|
83
84
|
wukong-cli auth refresh # 刷新访问令牌
|
|
84
85
|
wukong-cli auth logout # 登出并清除令牌
|
|
86
|
+
wukong-cli auth token # 显示当前 Token 结构和 JWT 信息
|
|
85
87
|
```
|
|
86
88
|
|
|
87
89
|
### HTTP 命令
|
|
@@ -90,9 +92,20 @@ wukong-cli auth logout # 登出并清除令牌
|
|
|
90
92
|
wukong-cli http get "/endpoint" # GET 请求
|
|
91
93
|
wukong-cli http post "/endpoint" -d '{"key":"value"}' # POST 请求
|
|
92
94
|
wukong-cli http put "/endpoint" -d '{"key":"value"}' # PUT 请求
|
|
95
|
+
wukong-cli http patch "/endpoint" -d '{"key":"value"}' # PATCH 请求
|
|
93
96
|
wukong-cli http delete "/endpoint" # DELETE 请求
|
|
94
97
|
```
|
|
95
98
|
|
|
99
|
+
**自动 Token 路由**:接口路径包含 `/yst-` 时自动使用 YST Token,否则使用主 Token。
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
# 自动使用 YST Token(路径包含 /yst-)
|
|
103
|
+
wukong-cli http get /yst-system/sys/users/current
|
|
104
|
+
|
|
105
|
+
# 自动使用主 Token
|
|
106
|
+
wukong-cli http get /oceanet-auth/web/userInfo
|
|
107
|
+
```
|
|
108
|
+
|
|
96
109
|
### 全局选项
|
|
97
110
|
|
|
98
111
|
```bash
|
|
@@ -104,6 +117,10 @@ wukong-cli http delete "/endpoint" # DELETE 请求
|
|
|
104
117
|
## 环境切换
|
|
105
118
|
|
|
106
119
|
```bash
|
|
120
|
+
# 交互式切换默认环境
|
|
121
|
+
wukong-cli env
|
|
122
|
+
|
|
123
|
+
# 或通过环境变量临时切换
|
|
107
124
|
# PowerShell
|
|
108
125
|
$env:WUKONG_CLI_ENV="beta"
|
|
109
126
|
wukong-cli auth login
|
|
@@ -142,13 +159,23 @@ wukong-cli init # 创建或重置配置文件
|
|
|
142
159
|
|
|
143
160
|
```json
|
|
144
161
|
{
|
|
145
|
-
"defaultEnv": "
|
|
162
|
+
"defaultEnv": "beta",
|
|
146
163
|
"environments": {
|
|
147
164
|
"prod": {
|
|
148
165
|
"authBaseUrl": "https://portal.zrhsh.com",
|
|
149
166
|
"apiBaseUrl": "https://nrp.zrhsh.com",
|
|
150
167
|
"clientId": "wukong-cli-prod"
|
|
151
168
|
},
|
|
169
|
+
"uat": {
|
|
170
|
+
"authBaseUrl": "https://portal-uat.zrhsh.com",
|
|
171
|
+
"apiBaseUrl": "https://nrp-pd.zrhsh.com",
|
|
172
|
+
"clientId": "wukong-cli-uat"
|
|
173
|
+
},
|
|
174
|
+
"beta": {
|
|
175
|
+
"authBaseUrl": "https://portal-beta.zrhsh.com",
|
|
176
|
+
"apiBaseUrl": "https://nrp-recode.zrhsh.com",
|
|
177
|
+
"clientId": "wukong-cli-beta"
|
|
178
|
+
},
|
|
152
179
|
"dev": {
|
|
153
180
|
"authBaseUrl": "https://portal-dev.zrhsh.com",
|
|
154
181
|
"apiBaseUrl": "https://nrp-dev.zrhsh.com",
|
|
@@ -202,7 +229,7 @@ Edit your wukong-cli.json or run 'wukong-cli init' to reset
|
|
|
202
229
|
|
|
203
230
|
## 项目信息
|
|
204
231
|
|
|
205
|
-
- **版本**: 0.
|
|
232
|
+
- **版本**: 0.4.20
|
|
206
233
|
- **包名**: @zrhsh/wukong-cli
|
|
207
234
|
- **组织**: @zrhsh
|
|
208
235
|
- **许可证**: MIT
|
|
@@ -231,4 +258,4 @@ MIT License - 详见 [LICENSE](LICENSE) 文件
|
|
|
231
258
|
|
|
232
259
|
---
|
|
233
260
|
|
|
234
|
-
**当前版本**: 0.
|
|
261
|
+
**当前版本**: 0.4.20 | **包名**: @zrhsh/wukong-cli | **组织**: @zrhsh
|
package/dist/cli.js
CHANGED
|
@@ -778,7 +778,7 @@ var init_token_cache = __esm({
|
|
|
778
778
|
// src/cli.ts
|
|
779
779
|
init_esm_shims();
|
|
780
780
|
init_debug();
|
|
781
|
-
import { Command as
|
|
781
|
+
import { Command as Command6 } from "commander";
|
|
782
782
|
|
|
783
783
|
// src/utils/version/index.ts
|
|
784
784
|
init_esm_shims();
|
|
@@ -1370,6 +1370,23 @@ init_esm_shims();
|
|
|
1370
1370
|
init_esm_shims();
|
|
1371
1371
|
init_debug();
|
|
1372
1372
|
init_oceanet();
|
|
1373
|
+
import axios from "axios";
|
|
1374
|
+
function createHttpClient() {
|
|
1375
|
+
return axios.create({
|
|
1376
|
+
timeout: 3e4,
|
|
1377
|
+
validateStatus: () => true,
|
|
1378
|
+
headers: {
|
|
1379
|
+
"Accept": "application/json"
|
|
1380
|
+
}
|
|
1381
|
+
});
|
|
1382
|
+
}
|
|
1383
|
+
var httpClientInstance = null;
|
|
1384
|
+
function getHttpClient() {
|
|
1385
|
+
if (!httpClientInstance) {
|
|
1386
|
+
httpClientInstance = createHttpClient();
|
|
1387
|
+
}
|
|
1388
|
+
return httpClientInstance;
|
|
1389
|
+
}
|
|
1373
1390
|
function buildUrl(endpoint, options = {}) {
|
|
1374
1391
|
const { baseUrl, params } = options;
|
|
1375
1392
|
if (endpoint.startsWith("http://") || endpoint.startsWith("https://")) {
|
|
@@ -1391,10 +1408,6 @@ function buildUrl(endpoint, options = {}) {
|
|
|
1391
1408
|
return url;
|
|
1392
1409
|
}
|
|
1393
1410
|
var BaseHttpClient = class {
|
|
1394
|
-
/**
|
|
1395
|
-
* 发起 HTTP 请求
|
|
1396
|
-
* 支持运行时 baseUrl 覆盖(用于多域名支持)
|
|
1397
|
-
*/
|
|
1398
1411
|
async request(endpoint, options = {}) {
|
|
1399
1412
|
const {
|
|
1400
1413
|
method = "GET",
|
|
@@ -1410,25 +1423,21 @@ var BaseHttpClient = class {
|
|
|
1410
1423
|
};
|
|
1411
1424
|
debugRequest(method, url, requestHeaders, body);
|
|
1412
1425
|
const startTime = Date.now();
|
|
1413
|
-
const response = await
|
|
1414
|
-
|
|
1426
|
+
const response = await getHttpClient().request({
|
|
1427
|
+
url,
|
|
1428
|
+
method: method.toLowerCase(),
|
|
1415
1429
|
headers: requestHeaders,
|
|
1416
|
-
|
|
1430
|
+
data: body ?? void 0,
|
|
1431
|
+
timeout: 3e4
|
|
1417
1432
|
});
|
|
1418
1433
|
const duration = Date.now() - startTime;
|
|
1419
|
-
const data =
|
|
1434
|
+
const data = response.data;
|
|
1420
1435
|
debugResponse(response.status, response.statusText, data, duration);
|
|
1421
1436
|
return data;
|
|
1422
1437
|
}
|
|
1423
|
-
/**
|
|
1424
|
-
* GET 请求
|
|
1425
|
-
*/
|
|
1426
1438
|
async get(endpoint, params) {
|
|
1427
1439
|
return this.request(endpoint, { method: "GET", params });
|
|
1428
1440
|
}
|
|
1429
|
-
/**
|
|
1430
|
-
* POST 请求
|
|
1431
|
-
*/
|
|
1432
1441
|
async post(endpoint, data, headers) {
|
|
1433
1442
|
return this.request(endpoint, {
|
|
1434
1443
|
method: "POST",
|
|
@@ -1436,9 +1445,6 @@ var BaseHttpClient = class {
|
|
|
1436
1445
|
headers
|
|
1437
1446
|
});
|
|
1438
1447
|
}
|
|
1439
|
-
/**
|
|
1440
|
-
* PUT 请求
|
|
1441
|
-
*/
|
|
1442
1448
|
async put(endpoint, data, headers) {
|
|
1443
1449
|
return this.request(endpoint, {
|
|
1444
1450
|
method: "PUT",
|
|
@@ -1446,15 +1452,9 @@ var BaseHttpClient = class {
|
|
|
1446
1452
|
headers
|
|
1447
1453
|
});
|
|
1448
1454
|
}
|
|
1449
|
-
/**
|
|
1450
|
-
* DELETE 请求
|
|
1451
|
-
*/
|
|
1452
1455
|
async delete(endpoint) {
|
|
1453
1456
|
return this.request(endpoint, { method: "DELETE" });
|
|
1454
1457
|
}
|
|
1455
|
-
/**
|
|
1456
|
-
* PATCH 请求
|
|
1457
|
-
*/
|
|
1458
1458
|
async patch(endpoint, data, headers) {
|
|
1459
1459
|
return this.request(endpoint, {
|
|
1460
1460
|
method: "PATCH",
|
|
@@ -2620,9 +2620,96 @@ var initCommand = new Command3("init").description("Initialize configuration fil
|
|
|
2620
2620
|
await executeInit();
|
|
2621
2621
|
});
|
|
2622
2622
|
|
|
2623
|
-
// src/commands/
|
|
2623
|
+
// src/commands/env.ts
|
|
2624
2624
|
init_esm_shims();
|
|
2625
|
+
init_environments();
|
|
2625
2626
|
import { Command as Command4 } from "commander";
|
|
2627
|
+
import chalk8 from "chalk";
|
|
2628
|
+
import { readFileSync as readFileSync5, writeFileSync as writeFileSync5 } from "fs";
|
|
2629
|
+
import { join as join5 } from "path";
|
|
2630
|
+
import { homedir as homedir5 } from "os";
|
|
2631
|
+
import { createInterface } from "readline";
|
|
2632
|
+
var CONFIG_DIR3 = join5(homedir5(), ".wukong-cli");
|
|
2633
|
+
var CONFIG_FILE_PATH3 = join5(CONFIG_DIR3, "wukong-cli.json");
|
|
2634
|
+
function loadConfig2() {
|
|
2635
|
+
try {
|
|
2636
|
+
const content = readFileSync5(CONFIG_FILE_PATH3, "utf-8");
|
|
2637
|
+
if (!content) return null;
|
|
2638
|
+
return JSON.parse(content);
|
|
2639
|
+
} catch {
|
|
2640
|
+
return null;
|
|
2641
|
+
}
|
|
2642
|
+
}
|
|
2643
|
+
function saveConfig(config) {
|
|
2644
|
+
writeFileSync5(CONFIG_FILE_PATH3, JSON.stringify(config, null, 2), "utf-8");
|
|
2645
|
+
}
|
|
2646
|
+
function promptEnvironment(currentEnv2) {
|
|
2647
|
+
return new Promise((resolve) => {
|
|
2648
|
+
const rl = createInterface({
|
|
2649
|
+
input: process.stdin,
|
|
2650
|
+
output: process.stdout
|
|
2651
|
+
});
|
|
2652
|
+
rl.question(chalk8.dim("Enter environment name: "), (answer) => {
|
|
2653
|
+
rl.close();
|
|
2654
|
+
const trimmed = answer.trim();
|
|
2655
|
+
if (!trimmed) {
|
|
2656
|
+
resolve("");
|
|
2657
|
+
return;
|
|
2658
|
+
}
|
|
2659
|
+
const envEntries = Object.entries(ENVIRONMENTS);
|
|
2660
|
+
const matched = envEntries.find(([key]) => key === trimmed);
|
|
2661
|
+
if (!matched) {
|
|
2662
|
+
console.log(chalk8.yellow(` Unknown environment: "${trimmed}". Available: ${envEntries.map(([k]) => k).join(", ")}`));
|
|
2663
|
+
console.log("");
|
|
2664
|
+
resolve(trimmed);
|
|
2665
|
+
return;
|
|
2666
|
+
}
|
|
2667
|
+
resolve(trimmed);
|
|
2668
|
+
});
|
|
2669
|
+
});
|
|
2670
|
+
}
|
|
2671
|
+
var envCommand = new Command4("env").description("Switch default environment").action(async () => {
|
|
2672
|
+
console.log("");
|
|
2673
|
+
console.log(chalk8.bgBlue.white.bold(" Environment Switch "));
|
|
2674
|
+
console.log("");
|
|
2675
|
+
const config = loadConfig2();
|
|
2676
|
+
const currentEnv2 = config?.defaultEnv || "prod";
|
|
2677
|
+
const envEntries = Object.entries(ENVIRONMENTS);
|
|
2678
|
+
for (const [key, envConfig] of envEntries) {
|
|
2679
|
+
const isCurrent = key === currentEnv2;
|
|
2680
|
+
const marker = isCurrent ? chalk8.green(" * ") : " ";
|
|
2681
|
+
const name = isCurrent ? chalk8.bold(envConfig.displayName) : envConfig.displayName;
|
|
2682
|
+
console.log(`${marker}${chalk8.cyan(key.padEnd(8))} ${name}${chalk8.dim(` (${envConfig.apiBaseUrl})`)}`);
|
|
2683
|
+
}
|
|
2684
|
+
console.log("");
|
|
2685
|
+
console.log(chalk8.dim(`Current: ${chalk8.cyan(currentEnv2)} | Config: ${CONFIG_FILE_PATH3}`));
|
|
2686
|
+
console.log(chalk8.dim("Enter environment name to switch (or press Enter to cancel):"));
|
|
2687
|
+
const selected = await promptEnvironment(currentEnv2);
|
|
2688
|
+
if (!selected) {
|
|
2689
|
+
console.log("");
|
|
2690
|
+
console.log(chalk8.dim("Cancelled."));
|
|
2691
|
+
console.log("");
|
|
2692
|
+
return;
|
|
2693
|
+
}
|
|
2694
|
+
if (selected === currentEnv2) {
|
|
2695
|
+
console.log("");
|
|
2696
|
+
console.log(chalk8.dim(`Already on ${chalk8.cyan(selected)}`));
|
|
2697
|
+
console.log("");
|
|
2698
|
+
return;
|
|
2699
|
+
}
|
|
2700
|
+
const newConfig = { ...config, defaultEnv: selected };
|
|
2701
|
+
saveConfig(newConfig);
|
|
2702
|
+
console.log("");
|
|
2703
|
+
console.log(chalk8.bgGreen.black.bold(` Switched to ${selected} `));
|
|
2704
|
+
console.log(chalk8.dim(`Environment: ${ENVIRONMENTS[selected].displayName}`));
|
|
2705
|
+
console.log(chalk8.dim(`API Base: ${ENVIRONMENTS[selected].apiBaseUrl}`));
|
|
2706
|
+
console.log(chalk8.dim(`Auth Base: ${ENVIRONMENTS[selected].authBaseUrl}`));
|
|
2707
|
+
console.log("");
|
|
2708
|
+
});
|
|
2709
|
+
|
|
2710
|
+
// src/commands/update.ts
|
|
2711
|
+
init_esm_shims();
|
|
2712
|
+
import { Command as Command5 } from "commander";
|
|
2626
2713
|
|
|
2627
2714
|
// src/core/update/npm-updater.ts
|
|
2628
2715
|
init_esm_shims();
|
|
@@ -2733,9 +2820,9 @@ async function runUpdateCommand({
|
|
|
2733
2820
|
return 1;
|
|
2734
2821
|
}
|
|
2735
2822
|
}
|
|
2736
|
-
var updateCommand = new
|
|
2823
|
+
var updateCommand = new Command5("update").description("Update wukong-cli to the latest npm version").action(async () => {
|
|
2737
2824
|
const exitCode = await runUpdateCommand({
|
|
2738
|
-
currentVersion: "0.4.
|
|
2825
|
+
currentVersion: "0.4.23",
|
|
2739
2826
|
versionProvider: new NpmVersionProvider(
|
|
2740
2827
|
"@zrhsh/wukong-cli",
|
|
2741
2828
|
"https://registry.npmjs.org"
|
|
@@ -2749,8 +2836,8 @@ var updateCommand = new Command4("update").description("Update wukong-cli to the
|
|
|
2749
2836
|
});
|
|
2750
2837
|
|
|
2751
2838
|
// src/cli.ts
|
|
2752
|
-
var program = new
|
|
2753
|
-
program.name("wukong-cli").description("Wukong CLI - TypeScript implementation").version("0.4.
|
|
2839
|
+
var program = new Command6();
|
|
2840
|
+
program.name("wukong-cli").description("Wukong CLI - TypeScript implementation").version("0.4.23").option("--debug", "Enable debug mode (show HTTP requests)").hook("preAction", (thisCommand) => {
|
|
2754
2841
|
const options = thisCommand.opts();
|
|
2755
2842
|
if (options.debug === true) {
|
|
2756
2843
|
setDebugMode(true, true);
|
|
@@ -2761,6 +2848,7 @@ program.name("wukong-cli").description("Wukong CLI - TypeScript implementation")
|
|
|
2761
2848
|
program.addCommand(authCommands);
|
|
2762
2849
|
program.addCommand(httpCommand);
|
|
2763
2850
|
program.addCommand(initCommand);
|
|
2851
|
+
program.addCommand(envCommand);
|
|
2764
2852
|
program.addCommand(updateCommand);
|
|
2765
2853
|
if (process.argv.length === 2) {
|
|
2766
2854
|
program.help();
|
|
@@ -2768,7 +2856,7 @@ if (process.argv.length === 2) {
|
|
|
2768
2856
|
program.parse();
|
|
2769
2857
|
setImmediate(() => {
|
|
2770
2858
|
try {
|
|
2771
|
-
const versionChecker = getVersionChecker("0.4.
|
|
2859
|
+
const versionChecker = getVersionChecker("0.4.23");
|
|
2772
2860
|
const notifier = new ConsoleNotifier();
|
|
2773
2861
|
versionChecker.checkInBackground(notifier).catch(() => {
|
|
2774
2862
|
});
|