@zrhsh/wukong-cli 0.4.26 → 0.4.28
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/LICENSE +16 -0
- package/dist/cli.js +204 -159
- package/dist/cli.js.map +1 -1
- package/package.json +2 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Copyright (c) 2026 武汉壹品慧生活技术有限公司. All rights reserved.
|
|
2
|
+
|
|
3
|
+
本软件为武汉壹品慧生活技术有限公司(以下简称"公司")的专有资产,
|
|
4
|
+
仅限公司内部授权人员在公司业务范围内使用。
|
|
5
|
+
|
|
6
|
+
未经公司书面许可,任何单位和个人不得:
|
|
7
|
+
|
|
8
|
+
1. 复制、传播、分发本软件或其任何部分;
|
|
9
|
+
2. 修改、改编、翻译本软件;
|
|
10
|
+
3. 将本软件用于公司业务范围之外的任何用途;
|
|
11
|
+
4. 对本软件进行反向工程、反编译或反汇编。
|
|
12
|
+
|
|
13
|
+
本软件按"现状"提供,不附带任何明示或暗示的担保。
|
|
14
|
+
|
|
15
|
+
This software is proprietary and confidential.
|
|
16
|
+
Unauthorized copying, distribution, modification, or use is strictly prohibited.
|
package/dist/cli.js
CHANGED
|
@@ -256,8 +256,7 @@ function loadConfig() {
|
|
|
256
256
|
}
|
|
257
257
|
try {
|
|
258
258
|
const content = readFileSync2(configPath, "utf-8");
|
|
259
|
-
|
|
260
|
-
return config;
|
|
259
|
+
return JSON.parse(content);
|
|
261
260
|
} catch (error2) {
|
|
262
261
|
console.warn(`Warning: Failed to load config from ${configPath}: ${error2}`);
|
|
263
262
|
return {};
|
|
@@ -298,22 +297,6 @@ function getMergedEnvironmentConfig(env) {
|
|
|
298
297
|
}
|
|
299
298
|
return defaultEnvConfig;
|
|
300
299
|
}
|
|
301
|
-
function getAllEnvironments() {
|
|
302
|
-
const config = loadConfig();
|
|
303
|
-
const result = { ...ENVIRONMENTS };
|
|
304
|
-
if (config.customEnvironments) {
|
|
305
|
-
for (const [name, customEnv] of Object.entries(config.customEnvironments)) {
|
|
306
|
-
result[name] = {
|
|
307
|
-
name,
|
|
308
|
-
displayName: customEnv.displayName || name,
|
|
309
|
-
authBaseUrl: customEnv.authBaseUrl,
|
|
310
|
-
apiBaseUrl: customEnv.apiBaseUrl,
|
|
311
|
-
clientId: customEnv.clientId
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
return result;
|
|
316
|
-
}
|
|
317
300
|
function getDefaultEnvironment() {
|
|
318
301
|
const envFromVar = process.env.WUKONG_CLI_ENV;
|
|
319
302
|
if (envFromVar && isValidEnvironment(envFromVar)) {
|
|
@@ -568,7 +551,7 @@ var init_ora_ui_callbacks = __esm({
|
|
|
568
551
|
});
|
|
569
552
|
|
|
570
553
|
// src/core/auth/keytar-adapter.ts
|
|
571
|
-
import { createRequire } from "module";
|
|
554
|
+
import { createRequire as createRequire2 } from "module";
|
|
572
555
|
function isKeytarAvailable() {
|
|
573
556
|
return keytarModule !== null;
|
|
574
557
|
}
|
|
@@ -590,15 +573,15 @@ async function deletePassword(service, account) {
|
|
|
590
573
|
}
|
|
591
574
|
return await keytarModule.deletePassword(service, account);
|
|
592
575
|
}
|
|
593
|
-
var
|
|
576
|
+
var require3, keytarModule;
|
|
594
577
|
var init_keytar_adapter = __esm({
|
|
595
578
|
"src/core/auth/keytar-adapter.ts"() {
|
|
596
579
|
"use strict";
|
|
597
580
|
init_esm_shims();
|
|
598
|
-
|
|
581
|
+
require3 = createRequire2(import.meta.url);
|
|
599
582
|
keytarModule = null;
|
|
600
583
|
try {
|
|
601
|
-
keytarModule =
|
|
584
|
+
keytarModule = require3("keytar");
|
|
602
585
|
} catch (error2) {
|
|
603
586
|
keytarModule = null;
|
|
604
587
|
}
|
|
@@ -795,9 +778,18 @@ var init_token_cache = __esm({
|
|
|
795
778
|
|
|
796
779
|
// src/cli.ts
|
|
797
780
|
init_esm_shims();
|
|
798
|
-
init_debug();
|
|
799
781
|
import { Command as Command6 } from "commander";
|
|
800
782
|
|
|
783
|
+
// src/version.ts
|
|
784
|
+
init_esm_shims();
|
|
785
|
+
import { createRequire } from "module";
|
|
786
|
+
var require2 = createRequire(import.meta.url);
|
|
787
|
+
var pkg = require2("../package.json");
|
|
788
|
+
var CLI_VERSION = pkg.version;
|
|
789
|
+
|
|
790
|
+
// src/cli.ts
|
|
791
|
+
init_debug();
|
|
792
|
+
|
|
801
793
|
// src/utils/version/index.ts
|
|
802
794
|
init_esm_shims();
|
|
803
795
|
|
|
@@ -2098,16 +2090,18 @@ function getClient() {
|
|
|
2098
2090
|
}
|
|
2099
2091
|
|
|
2100
2092
|
// src/commands/auth.ts
|
|
2093
|
+
init_environments();
|
|
2101
2094
|
init_oceanet();
|
|
2102
|
-
|
|
2095
|
+
function resolveEnvContext() {
|
|
2096
|
+
const env = getCurrentEnvironment();
|
|
2097
|
+
setCurrentEnvironment(env);
|
|
2098
|
+
return { env, envConfig: ENVIRONMENTS[env] };
|
|
2099
|
+
}
|
|
2103
2100
|
var authCommands = new Command("auth").description("Authentication commands");
|
|
2104
2101
|
authCommands.command("login").description("Login using Device Authorization Flow").action(async () => {
|
|
2105
2102
|
try {
|
|
2106
|
-
const env =
|
|
2107
|
-
const allEnvs = getAllEnvironments();
|
|
2108
|
-
setCurrentEnvironment(env);
|
|
2103
|
+
const { env, envConfig } = resolveEnvContext();
|
|
2109
2104
|
const config = getOceanetConfig();
|
|
2110
|
-
const envConfig = allEnvs[env];
|
|
2111
2105
|
console.log("");
|
|
2112
2106
|
console.log(chalk5.bgBlue.white.bold(" Wukong CLI Login "));
|
|
2113
2107
|
console.log("");
|
|
@@ -2175,10 +2169,7 @@ authCommands.command("login").description("Login using Device Authorization Flow
|
|
|
2175
2169
|
}
|
|
2176
2170
|
});
|
|
2177
2171
|
authCommands.command("logout").description("Logout and clear saved tokens").action(async () => {
|
|
2178
|
-
const env =
|
|
2179
|
-
const allEnvs = getAllEnvironments();
|
|
2180
|
-
setCurrentEnvironment(env);
|
|
2181
|
-
const envConfig = allEnvs[env];
|
|
2172
|
+
const { env, envConfig } = resolveEnvContext();
|
|
2182
2173
|
try {
|
|
2183
2174
|
const accessToken = await getAccessToken();
|
|
2184
2175
|
const ystAccessToken = await getYstAccessToken();
|
|
@@ -2195,9 +2186,7 @@ authCommands.command("logout").description("Logout and clear saved tokens").acti
|
|
|
2195
2186
|
}
|
|
2196
2187
|
});
|
|
2197
2188
|
authCommands.command("refresh").description("Manually refresh access token").action(async () => {
|
|
2198
|
-
const env =
|
|
2199
|
-
const allEnvs = getAllEnvironments();
|
|
2200
|
-
const envConfig = allEnvs[env];
|
|
2189
|
+
const { env, envConfig } = resolveEnvContext();
|
|
2201
2190
|
try {
|
|
2202
2191
|
const config = getOceanetConfig();
|
|
2203
2192
|
const accessToken = await getAccessToken();
|
|
@@ -2243,10 +2232,7 @@ authCommands.command("refresh").description("Manually refresh access token").act
|
|
|
2243
2232
|
});
|
|
2244
2233
|
authCommands.command("status").description("Show authentication status").action(async () => {
|
|
2245
2234
|
console.log("");
|
|
2246
|
-
const env =
|
|
2247
|
-
const allEnvs = getAllEnvironments();
|
|
2248
|
-
setCurrentEnvironment(env);
|
|
2249
|
-
const envConfig = allEnvs[env];
|
|
2235
|
+
const { env, envConfig } = resolveEnvContext();
|
|
2250
2236
|
try {
|
|
2251
2237
|
const config = getOceanetConfig();
|
|
2252
2238
|
const accessToken = await getAccessToken();
|
|
@@ -2298,10 +2284,7 @@ authCommands.command("status").description("Show authentication status").action(
|
|
|
2298
2284
|
});
|
|
2299
2285
|
authCommands.command("token").description("Display current token structure and JWT payload claims").action(async () => {
|
|
2300
2286
|
console.log("");
|
|
2301
|
-
const env =
|
|
2302
|
-
const allEnvs = getAllEnvironments();
|
|
2303
|
-
setCurrentEnvironment(env);
|
|
2304
|
-
const envConfig = allEnvs[env];
|
|
2287
|
+
const { env, envConfig } = resolveEnvContext();
|
|
2305
2288
|
try {
|
|
2306
2289
|
let decodeJwt2 = function(token) {
|
|
2307
2290
|
try {
|
|
@@ -2463,6 +2446,48 @@ import ora4 from "ora";
|
|
|
2463
2446
|
import chalk6 from "chalk";
|
|
2464
2447
|
init_oceanet();
|
|
2465
2448
|
init_config_file_error();
|
|
2449
|
+
|
|
2450
|
+
// src/core/http/request-body.ts
|
|
2451
|
+
init_esm_shims();
|
|
2452
|
+
function parseRequestBody(raw) {
|
|
2453
|
+
if (!raw.trim()) {
|
|
2454
|
+
return {};
|
|
2455
|
+
}
|
|
2456
|
+
try {
|
|
2457
|
+
return { data: JSON.parse(raw) };
|
|
2458
|
+
} catch (error2) {
|
|
2459
|
+
return { error: error2 instanceof Error ? error2.message : String(error2) };
|
|
2460
|
+
}
|
|
2461
|
+
}
|
|
2462
|
+
function detectPageQueryEnvelope(body) {
|
|
2463
|
+
if (!isPlainObject(body)) {
|
|
2464
|
+
return null;
|
|
2465
|
+
}
|
|
2466
|
+
const hasPagingField = typeof body.current === "number" || typeof body.size === "number";
|
|
2467
|
+
if (!hasPagingField) {
|
|
2468
|
+
return null;
|
|
2469
|
+
}
|
|
2470
|
+
const envelope = body.param;
|
|
2471
|
+
if (isPlainObject(envelope) && isPlainObject(envelope.param)) {
|
|
2472
|
+
return null;
|
|
2473
|
+
}
|
|
2474
|
+
return {
|
|
2475
|
+
code: "PAGEQUERY_ENVELOPE",
|
|
2476
|
+
message: 'current/size \u51FA\u73B0\u5728\u8BF7\u6C42\u4F53\u9876\u5C42\uFF0C\u4F46 param \u5185\u6CA1\u6709\u5D4C\u5957\u7684\u4E1A\u52A1\u6761\u4EF6\u3002\u672C\u6846\u67B6\u7684\u5206\u9875\u67E5\u8BE2\u63A5\u53E3\u9700\u8981\u53CC\u5C42 param\uFF1A{"param":{"current":1,"size":20,"param":{...\u4E1A\u52A1\u6761\u4EF6}}}\u3002\u5199\u6210\u5355\u5C42\u65F6\u63A5\u53E3\u4ECD\u8FD4\u56DE 200\uFF0C\u4F46\u67E5\u8BE2\u6761\u4EF6\u4F1A\u88AB\u9759\u9ED8\u4E22\u5F03\u5E76\u8FD4\u56DE\u5168\u91CF\u6570\u636E\u3002'
|
|
2477
|
+
};
|
|
2478
|
+
}
|
|
2479
|
+
|
|
2480
|
+
// src/commands/http.ts
|
|
2481
|
+
function fail(message, jsonMode, errorCode = null) {
|
|
2482
|
+
if (jsonMode) {
|
|
2483
|
+
process.stderr.write(
|
|
2484
|
+
JSON.stringify({ error: { code: errorCode, message } }, null, 2) + "\n"
|
|
2485
|
+
);
|
|
2486
|
+
} else {
|
|
2487
|
+
console.error(chalk6.red(message));
|
|
2488
|
+
}
|
|
2489
|
+
process.exit(1);
|
|
2490
|
+
}
|
|
2466
2491
|
function fixGitBashPath(url) {
|
|
2467
2492
|
if (url.includes(":") && !url.startsWith("http")) {
|
|
2468
2493
|
const oceanetIndex = url.indexOf("/oceanet-");
|
|
@@ -2503,138 +2528,158 @@ function parseParams(params) {
|
|
|
2503
2528
|
}
|
|
2504
2529
|
return `?${searchParams.toString()}`;
|
|
2505
2530
|
}
|
|
2531
|
+
function warnOnPageQueryEnvelope(context) {
|
|
2532
|
+
if (!["POST", "PUT", "PATCH"].includes(context.method.toUpperCase())) {
|
|
2533
|
+
return;
|
|
2534
|
+
}
|
|
2535
|
+
const issue = detectPageQueryEnvelope(context.data);
|
|
2536
|
+
if (!issue) {
|
|
2537
|
+
return;
|
|
2538
|
+
}
|
|
2539
|
+
if (context.jsonMode) {
|
|
2540
|
+
process.stderr.write(JSON.stringify({ warning: issue }, null, 2) + "\n");
|
|
2541
|
+
return;
|
|
2542
|
+
}
|
|
2543
|
+
console.error("");
|
|
2544
|
+
console.error(chalk6.yellow(`[WARNING] ${issue.message}`));
|
|
2545
|
+
console.error("");
|
|
2546
|
+
}
|
|
2547
|
+
async function sendWithYstToken(context) {
|
|
2548
|
+
const ystAccessToken = await getYstAccessToken();
|
|
2549
|
+
if (!ystAccessToken) {
|
|
2550
|
+
fail("YST token not found. Please re-login: wukong-cli auth login", context.jsonMode);
|
|
2551
|
+
}
|
|
2552
|
+
context.spinner.text = `${context.method} ${chalk6.cyan(context.fullUrl)} (using YST token)`;
|
|
2553
|
+
const fetchOptions = {
|
|
2554
|
+
method: context.method.toUpperCase(),
|
|
2555
|
+
headers: {
|
|
2556
|
+
"Authorization": `Bearer ${ystAccessToken}`,
|
|
2557
|
+
"Content-Type": "application/json",
|
|
2558
|
+
...context.headers
|
|
2559
|
+
}
|
|
2560
|
+
};
|
|
2561
|
+
if (context.data !== void 0) {
|
|
2562
|
+
fetchOptions.body = JSON.stringify(context.data);
|
|
2563
|
+
}
|
|
2564
|
+
const finalUrl = context.fullUrl + parseParams(context.params);
|
|
2565
|
+
const startTime = Date.now();
|
|
2566
|
+
let response;
|
|
2567
|
+
try {
|
|
2568
|
+
response = await fetch(finalUrl, fetchOptions);
|
|
2569
|
+
} catch (fetchError) {
|
|
2570
|
+
const detail = JSON.stringify(fetchError.cause) || fetchError.message;
|
|
2571
|
+
throw new Error(`Request failed: ${finalUrl}
|
|
2572
|
+
${detail}`);
|
|
2573
|
+
}
|
|
2574
|
+
const duration = Date.now() - startTime;
|
|
2575
|
+
if (!response.ok) {
|
|
2576
|
+
const errText = await response.text().catch(() => "");
|
|
2577
|
+
throw new ApiError(
|
|
2578
|
+
response.status,
|
|
2579
|
+
`HTTP ${response.status}: ${errText.substring(0, 200)}`
|
|
2580
|
+
);
|
|
2581
|
+
}
|
|
2582
|
+
const body = await response.json();
|
|
2583
|
+
getApiErrorHandler().handle(body);
|
|
2584
|
+
return { data: unwrapResponse(body), duration, tokenKind: "yst" };
|
|
2585
|
+
}
|
|
2586
|
+
async function sendWithMainToken(context) {
|
|
2587
|
+
const client = getClient();
|
|
2588
|
+
context.spinner.text = `${context.method} ${chalk6.cyan(context.fullUrl)}`;
|
|
2589
|
+
const startTime = Date.now();
|
|
2590
|
+
let payload;
|
|
2591
|
+
switch (context.method.toUpperCase()) {
|
|
2592
|
+
case "GET":
|
|
2593
|
+
payload = await client.get(context.fullUrl + parseParams(context.params));
|
|
2594
|
+
break;
|
|
2595
|
+
case "POST":
|
|
2596
|
+
payload = await client.post(context.fullUrl, context.data, context.headers);
|
|
2597
|
+
break;
|
|
2598
|
+
case "PUT":
|
|
2599
|
+
payload = await client.put(context.fullUrl, context.data, context.headers);
|
|
2600
|
+
break;
|
|
2601
|
+
case "DELETE":
|
|
2602
|
+
payload = await client.delete(context.fullUrl);
|
|
2603
|
+
break;
|
|
2604
|
+
case "PATCH":
|
|
2605
|
+
payload = await client.patch(context.fullUrl, context.data, context.headers);
|
|
2606
|
+
break;
|
|
2607
|
+
default:
|
|
2608
|
+
throw new Error(`Unsupported method: ${context.method}`);
|
|
2609
|
+
}
|
|
2610
|
+
return { data: payload, duration: Date.now() - startTime, tokenKind: "main" };
|
|
2611
|
+
}
|
|
2612
|
+
function renderResult(result, jsonMode) {
|
|
2613
|
+
if (jsonMode) {
|
|
2614
|
+
process.stdout.write(JSON.stringify(result.data, null, 2) + "\n");
|
|
2615
|
+
return;
|
|
2616
|
+
}
|
|
2617
|
+
console.log("");
|
|
2618
|
+
console.log(chalk6.dim("Token:"), result.tokenKind === "yst" ? "YST" : "main");
|
|
2619
|
+
console.log(chalk6.dim("Duration:"), `${result.duration}ms`);
|
|
2620
|
+
console.log("");
|
|
2621
|
+
console.log(chalk6.dim("Response:"));
|
|
2622
|
+
console.log(JSON.stringify(result.data, null, 2));
|
|
2623
|
+
}
|
|
2624
|
+
function handleError(error2, jsonMode) {
|
|
2625
|
+
if (error2 instanceof ConfigFileError) {
|
|
2626
|
+
return fail(`Configuration Error
|
|
2627
|
+
${error2.toUserMessage()}`, jsonMode);
|
|
2628
|
+
}
|
|
2629
|
+
if (error2 instanceof ApiError) {
|
|
2630
|
+
return fail(`API Error (code: ${error2.code}): ${error2.message}`, jsonMode, error2.code);
|
|
2631
|
+
}
|
|
2632
|
+
return fail(error2 instanceof Error ? error2.message : String(error2), jsonMode);
|
|
2633
|
+
}
|
|
2506
2634
|
async function executeRequest(method, url, options) {
|
|
2507
|
-
const
|
|
2635
|
+
const jsonMode = options.json === true;
|
|
2636
|
+
const spinner = ora4({ text: "Sending request...", isSilent: jsonMode }).start();
|
|
2508
2637
|
try {
|
|
2509
2638
|
const accessToken = await getAccessToken();
|
|
2510
2639
|
if (!accessToken) {
|
|
2511
2640
|
spinner.fail("Not authenticated");
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
}
|
|
2535
|
-
};
|
|
2536
|
-
if (requestData) {
|
|
2537
|
-
fetchOptions.body = JSON.stringify(requestData);
|
|
2538
|
-
}
|
|
2539
|
-
const finalUrl = fullUrl + parseParams(options.params);
|
|
2540
|
-
let response;
|
|
2541
|
-
try {
|
|
2542
|
-
response = await fetch(finalUrl, fetchOptions);
|
|
2543
|
-
} catch (fetchError) {
|
|
2544
|
-
spinner.fail(`Request failed`);
|
|
2545
|
-
console.error(chalk6.red(`URL: ${finalUrl}`));
|
|
2546
|
-
console.error(chalk6.red(`Error: ${JSON.stringify(fetchError.cause) || fetchError.message}`));
|
|
2547
|
-
process.exit(1);
|
|
2548
|
-
}
|
|
2549
|
-
const duration2 = Date.now() - startTime2;
|
|
2550
|
-
if (!response.ok) {
|
|
2551
|
-
const errText = await response.text().catch(() => "");
|
|
2552
|
-
spinner.fail(`Request failed (${response.status})`);
|
|
2553
|
-
console.error(chalk6.red(`HTTP ${response.status}: ${errText.substring(0, 200)}`));
|
|
2554
|
-
process.exit(1);
|
|
2555
|
-
}
|
|
2556
|
-
const body = await response.json();
|
|
2557
|
-
getApiErrorHandler().handle(body);
|
|
2558
|
-
const data2 = unwrapResponse(body);
|
|
2559
|
-
spinner.succeed("Response received");
|
|
2560
|
-
console.log("");
|
|
2561
|
-
console.log(chalk6.dim("Status:"), `${response.status} ${response.statusText}`);
|
|
2562
|
-
console.log(chalk6.dim("Token:"), "YST");
|
|
2563
|
-
console.log(chalk6.dim("Duration:"), `${duration2}ms`);
|
|
2564
|
-
console.log("");
|
|
2565
|
-
console.log(chalk6.dim("Response:"));
|
|
2566
|
-
console.log(JSON.stringify(data2, null, 2));
|
|
2567
|
-
return;
|
|
2568
|
-
}
|
|
2569
|
-
const client = getClient();
|
|
2570
|
-
spinner.text = `${method} ${chalk6.cyan(fullUrl)}`;
|
|
2571
|
-
const startTime = Date.now();
|
|
2572
|
-
let data;
|
|
2573
|
-
switch (method.toUpperCase()) {
|
|
2574
|
-
case "GET":
|
|
2575
|
-
const getUrl = fullUrl + parseParams(options.params);
|
|
2576
|
-
data = await client.get(getUrl);
|
|
2577
|
-
break;
|
|
2578
|
-
case "POST":
|
|
2579
|
-
data = await client.post(fullUrl, requestData, customHeaders);
|
|
2580
|
-
break;
|
|
2581
|
-
case "PUT":
|
|
2582
|
-
data = await client.put(fullUrl, requestData, customHeaders);
|
|
2583
|
-
break;
|
|
2584
|
-
case "DELETE":
|
|
2585
|
-
data = await client.delete(fullUrl);
|
|
2586
|
-
break;
|
|
2587
|
-
case "PATCH":
|
|
2588
|
-
data = await client.patch(fullUrl, requestData, customHeaders);
|
|
2589
|
-
break;
|
|
2590
|
-
default:
|
|
2591
|
-
throw new Error(`Unsupported method: ${method}`);
|
|
2592
|
-
}
|
|
2593
|
-
const duration = Date.now() - startTime;
|
|
2594
|
-
spinner.succeed("Response received");
|
|
2595
|
-
console.log("");
|
|
2596
|
-
console.log(chalk6.dim("Status:"), "200 OK");
|
|
2597
|
-
console.log("");
|
|
2598
|
-
console.log(chalk6.dim("Response:"));
|
|
2599
|
-
console.log(JSON.stringify(data, null, 2));
|
|
2641
|
+
fail("Not authenticated. Please run: wukong-cli auth login", jsonMode);
|
|
2642
|
+
}
|
|
2643
|
+
const parsed = parseRequestBody(options.data ?? "");
|
|
2644
|
+
if (parsed.error) {
|
|
2645
|
+
spinner.fail("Invalid request body");
|
|
2646
|
+
const received = (options.data ?? "").replace(/\s+/g, " ").trim();
|
|
2647
|
+
fail(`Invalid JSON in -d: ${parsed.error}
|
|
2648
|
+
Received: ${received}`, jsonMode);
|
|
2649
|
+
}
|
|
2650
|
+
const context = {
|
|
2651
|
+
method,
|
|
2652
|
+
fullUrl: buildUrl2(url, options.baseUrl),
|
|
2653
|
+
data: parsed.data,
|
|
2654
|
+
headers: parseHeaders(options.headers),
|
|
2655
|
+
params: options.params,
|
|
2656
|
+
jsonMode,
|
|
2657
|
+
spinner
|
|
2658
|
+
};
|
|
2659
|
+
warnOnPageQueryEnvelope(context);
|
|
2660
|
+
const result = context.fullUrl.includes("/yst-") ? await sendWithYstToken(context) : await sendWithMainToken(context);
|
|
2661
|
+
spinner.succeed(`Response received (${result.duration}ms)`);
|
|
2662
|
+
renderResult(result, jsonMode);
|
|
2600
2663
|
} catch (error2) {
|
|
2601
2664
|
spinner.fail("Request failed");
|
|
2602
|
-
|
|
2603
|
-
console.log("");
|
|
2604
|
-
console.log(chalk6.red(`[ERROR] Configuration Error`));
|
|
2605
|
-
console.log("");
|
|
2606
|
-
console.log(chalk6.red(error2.toUserMessage()));
|
|
2607
|
-
console.log("");
|
|
2608
|
-
process.exit(1);
|
|
2609
|
-
}
|
|
2610
|
-
if (error2 instanceof ApiError) {
|
|
2611
|
-
console.log("");
|
|
2612
|
-
console.log(chalk6.red(`API Error (code: ${error2.code})`));
|
|
2613
|
-
console.log(chalk6.red(error2.message));
|
|
2614
|
-
console.log("");
|
|
2615
|
-
process.exit(1);
|
|
2616
|
-
}
|
|
2617
|
-
if (error2 instanceof Error) {
|
|
2618
|
-
console.error(chalk6.red(error2.message));
|
|
2619
|
-
}
|
|
2620
|
-
process.exit(1);
|
|
2665
|
+
handleError(error2, jsonMode);
|
|
2621
2666
|
}
|
|
2622
2667
|
}
|
|
2623
2668
|
var httpCommand = new Command2("http");
|
|
2624
2669
|
httpCommand.description("HTTP commands for making API requests");
|
|
2625
|
-
httpCommand.command("get <url>").description("Send GET request (uses configured base URL or override with -b)").option("-b, --base-url <url>", "Override base URL").option("-H, --header <key:value>", "Custom header (can be used multiple times)", []).action(async (url, options) => {
|
|
2670
|
+
httpCommand.command("get <url>").description("Send GET request (uses configured base URL or override with -b)").option("-b, --base-url <url>", "Override base URL").option("-H, --header <key:value>", "Custom header (can be used multiple times)", []).option("--json", "Print only the response body as JSON").action(async (url, options) => {
|
|
2626
2671
|
await executeRequest("GET", url, options);
|
|
2627
2672
|
});
|
|
2628
|
-
httpCommand.command("post <url>").description("Send POST request with JSON data").option("-b, --base-url <url>", "Override base URL").option("-H, --header <key:value>", "Custom header (can be used multiple times)", []).option("-d, --data <json>", "Request body as JSON string").action(async (url, options) => {
|
|
2673
|
+
httpCommand.command("post <url>").description("Send POST request with JSON data").option("-b, --base-url <url>", "Override base URL").option("-H, --header <key:value>", "Custom header (can be used multiple times)", []).option("-d, --data <json>", "Request body as JSON string").option("--json", "Print only the response body as JSON").action(async (url, options) => {
|
|
2629
2674
|
await executeRequest("POST", url, options);
|
|
2630
2675
|
});
|
|
2631
|
-
httpCommand.command("put <url>").description("Send PUT request with JSON data").option("-b, --base-url <url>", "Override base URL").option("-H, --header <key:value>", "Custom header (can be used multiple times)", []).option("-d, --data <json>", "Request body as JSON string").action(async (url, options) => {
|
|
2676
|
+
httpCommand.command("put <url>").description("Send PUT request with JSON data").option("-b, --base-url <url>", "Override base URL").option("-H, --header <key:value>", "Custom header (can be used multiple times)", []).option("-d, --data <json>", "Request body as JSON string").option("--json", "Print only the response body as JSON").action(async (url, options) => {
|
|
2632
2677
|
await executeRequest("PUT", url, options);
|
|
2633
2678
|
});
|
|
2634
|
-
httpCommand.command("patch <url>").description("Send PATCH request with JSON data").option("-b, --base-url <url>", "Override base URL").option("-H, --header <key:value>", "Custom header (can be used multiple times)", []).option("-d, --data <json>", "Request body as JSON string").action(async (url, options) => {
|
|
2679
|
+
httpCommand.command("patch <url>").description("Send PATCH request with JSON data").option("-b, --base-url <url>", "Override base URL").option("-H, --header <key:value>", "Custom header (can be used multiple times)", []).option("-d, --data <json>", "Request body as JSON string").option("--json", "Print only the response body as JSON").action(async (url, options) => {
|
|
2635
2680
|
await executeRequest("PATCH", url, options);
|
|
2636
2681
|
});
|
|
2637
|
-
httpCommand.command("delete <url>").description("Send DELETE request").option("-b, --base-url <url>", "Override base URL").option("-H, --header <key:value>", "Custom header (can be used multiple times)", []).action(async (url, options) => {
|
|
2682
|
+
httpCommand.command("delete <url>").description("Send DELETE request").option("-b, --base-url <url>", "Override base URL").option("-H, --header <key:value>", "Custom header (can be used multiple times)", []).option("--json", "Print only the response body as JSON").action(async (url, options) => {
|
|
2638
2683
|
await executeRequest("DELETE", url, options);
|
|
2639
2684
|
});
|
|
2640
2685
|
|
|
@@ -3120,7 +3165,7 @@ async function runUpdateCommand({
|
|
|
3120
3165
|
}
|
|
3121
3166
|
var updateCommand = new Command5("update").description("Update wukong-cli to the latest npm version").action(async () => {
|
|
3122
3167
|
const exitCode = await runUpdateCommand({
|
|
3123
|
-
currentVersion:
|
|
3168
|
+
currentVersion: CLI_VERSION,
|
|
3124
3169
|
versionProvider: new NpmVersionProvider(
|
|
3125
3170
|
"@zrhsh/wukong-cli",
|
|
3126
3171
|
"https://registry.npmjs.org"
|
|
@@ -3135,7 +3180,7 @@ var updateCommand = new Command5("update").description("Update wukong-cli to the
|
|
|
3135
3180
|
|
|
3136
3181
|
// src/cli.ts
|
|
3137
3182
|
var program = new Command6();
|
|
3138
|
-
program.name("wukong-cli").description("Wukong CLI - TypeScript implementation").version(
|
|
3183
|
+
program.name("wukong-cli").description("Wukong CLI - TypeScript implementation").version(CLI_VERSION).option("--debug", "Enable debug mode (show HTTP requests)").hook("preAction", (thisCommand) => {
|
|
3139
3184
|
const options = thisCommand.opts();
|
|
3140
3185
|
if (options.debug === true) {
|
|
3141
3186
|
setDebugMode(true, true);
|
|
@@ -3154,7 +3199,7 @@ if (process.argv.length === 2) {
|
|
|
3154
3199
|
program.parse();
|
|
3155
3200
|
setImmediate(() => {
|
|
3156
3201
|
try {
|
|
3157
|
-
const versionChecker = getVersionChecker(
|
|
3202
|
+
const versionChecker = getVersionChecker(CLI_VERSION);
|
|
3158
3203
|
const notifier = new ConsoleNotifier();
|
|
3159
3204
|
versionChecker.checkInBackground(notifier).catch(() => {
|
|
3160
3205
|
});
|