@zrhsh/wukong-cli 0.4.29 → 0.4.30

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/dist/cli.js CHANGED
@@ -172,6 +172,8 @@ var init_environments = __esm({
172
172
  displayName: "Development",
173
173
  authBaseUrl: "https://portal-dev.zrhsh.com",
174
174
  apiBaseUrl: "https://nrp-dev.zrhsh.com",
175
+ yosBaseUrl: "https://yos-dev.zrhsh.com",
176
+ srmBaseUrl: "https://srm-dev.zrhsh.com",
175
177
  clientId: "wukong-cli-dev"
176
178
  },
177
179
  beta: {
@@ -179,6 +181,8 @@ var init_environments = __esm({
179
181
  displayName: "Testing",
180
182
  authBaseUrl: "https://portal-beta.zrhsh.com",
181
183
  apiBaseUrl: "https://nrp-recode.zrhsh.com",
184
+ yosBaseUrl: "https://yos-beta.zrhsh.com",
185
+ srmBaseUrl: "https://srm-recode.zrhsh.com",
182
186
  clientId: "wukong-cli-beta"
183
187
  },
184
188
  uat: {
@@ -186,6 +190,8 @@ var init_environments = __esm({
186
190
  displayName: "UAT (User Acceptance Testing)",
187
191
  authBaseUrl: "https://portal-uat.zrhsh.com",
188
192
  apiBaseUrl: "https://nrp-pd.zrhsh.com",
193
+ yosBaseUrl: "https://yos-uat.zrhsh.com",
194
+ srmBaseUrl: "https://srm-pd.zrhsh.com",
189
195
  clientId: "wukong-cli-uat"
190
196
  },
191
197
  prod: {
@@ -193,6 +199,8 @@ var init_environments = __esm({
193
199
  displayName: "Production",
194
200
  authBaseUrl: "https://portal.zrhsh.com",
195
201
  apiBaseUrl: "https://nrp.zrhsh.com",
202
+ yosBaseUrl: "https://yos.zrhsh.com",
203
+ srmBaseUrl: "https://srm.zrhsh.com",
196
204
  clientId: "wukong-cli-prod"
197
205
  }
198
206
  };
@@ -262,6 +270,9 @@ function loadConfig() {
262
270
  return {};
263
271
  }
264
272
  }
273
+ function normalizeBaseUrl(url) {
274
+ return url.replace(/\/+$/, "");
275
+ }
265
276
  function getMergedEnvironmentConfig(env) {
266
277
  const config = loadConfig();
267
278
  const defaultEnvConfig = ENVIRONMENTS[env];
@@ -290,12 +301,21 @@ function getMergedEnvironmentConfig(env) {
290
301
  return {
291
302
  name: env,
292
303
  displayName: defaultEnvConfig.displayName,
293
- authBaseUrl: envConfig.authBaseUrl,
294
- apiBaseUrl: envConfig.apiBaseUrl,
304
+ authBaseUrl: normalizeBaseUrl(envConfig.authBaseUrl),
305
+ apiBaseUrl: normalizeBaseUrl(envConfig.apiBaseUrl),
306
+ // 跨域地址允许不写,缺省沿用内置默认值
307
+ yosBaseUrl: normalizeBaseUrl(envConfig.yosBaseUrl ?? defaultEnvConfig.yosBaseUrl),
308
+ srmBaseUrl: normalizeBaseUrl(envConfig.srmBaseUrl ?? defaultEnvConfig.srmBaseUrl),
295
309
  clientId: envConfig.clientId
296
310
  };
297
311
  }
298
- return defaultEnvConfig;
312
+ return {
313
+ ...defaultEnvConfig,
314
+ authBaseUrl: normalizeBaseUrl(defaultEnvConfig.authBaseUrl),
315
+ apiBaseUrl: normalizeBaseUrl(defaultEnvConfig.apiBaseUrl),
316
+ yosBaseUrl: normalizeBaseUrl(defaultEnvConfig.yosBaseUrl),
317
+ srmBaseUrl: normalizeBaseUrl(defaultEnvConfig.srmBaseUrl)
318
+ };
299
319
  }
300
320
  function getDefaultEnvironment() {
301
321
  const envFromVar = process.env.WUKONG_CLI_ENV;
@@ -2551,10 +2571,65 @@ function detectPageQueryEnvelope(body) {
2551
2571
  }
2552
2572
  return {
2553
2573
  code: "PAGEQUERY_ENVELOPE",
2554
- 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'
2574
+ message: 'current/size \u51FA\u73B0\u5728\u8BF7\u6C42\u4F53\u9876\u5C42\uFF0C\u4E14 param \u5185\u6CA1\u6709\u5D4C\u5957\u7684\u4E1A\u52A1\u6761\u4EF6\u3002\n \u82E5\u5165\u53C2\u6765\u81EA\u7528\u6237 / \u63A5\u53E3\u6587\u6863 / \u4EE3\u7801 / \u6293\u5305 \u2192 \u4EE5\u539F\u59CB\u5165\u53C2\u4E3A\u51C6\uFF0C\u5FFD\u7565\u672C\u63D0\u793A\u3001\u539F\u6837\u4F20\u9012\u5373\u53EF\u3002\n \u53EA\u6709\u5728\u6CA1\u6709\u4EFB\u4F55\u539F\u59CB\u5165\u53C2\u3001\u4E14\u786E\u8BA4\u662F\u4E3B\u7AD9\u5206\u9875\u63A5\u53E3\u65F6\uFF0C\u624D\u5C1D\u8BD5\u53CC\u5C42 param\uFF1A\n {"param":{"current":1,"size":20,"param":{...\u4E1A\u52A1\u6761\u4EF6}}}\n \u8BD5\u5B8C\u8BF7\u6BD4\u5BF9\u7ED3\u679C\uFF08\u6539\u4E00\u4E2A\u7B5B\u9009\u6761\u4EF6\uFF0C\u770B\u603B\u6570\u662F\u5426\u53D8\u5316\uFF09\uFF0C\u5426\u5219\u53EF\u80FD 200 \u4F46\u6761\u4EF6\u88AB\u4E22\u5F03\u3002'
2555
2575
  };
2556
2576
  }
2557
2577
 
2578
+ // src/core/http/target-url.ts
2579
+ init_esm_shims();
2580
+ var MSYS_ROOT_TAIL = /^[A-Za-z]:.*\/(?:PortableGit|Git|mingw64|usr)(?=\/)/i;
2581
+ var SERVICE_SEGMENT = /^(?:oceanet|wukong|yst|yos|srm)(?:-|$)/i;
2582
+ function fixGitBashPath(input) {
2583
+ if (!input || input.startsWith("http")) {
2584
+ return input;
2585
+ }
2586
+ if (!/^[A-Za-z]:[\\/]/.test(input)) {
2587
+ return input;
2588
+ }
2589
+ const normalized = input.replace(/\\/g, "/");
2590
+ const rootMatch = normalized.match(MSYS_ROOT_TAIL);
2591
+ if (rootMatch) {
2592
+ return normalized.slice(rootMatch[0].length);
2593
+ }
2594
+ const segments = normalized.split("/");
2595
+ const serviceIndex = segments.findIndex((segment) => SERVICE_SEGMENT.test(segment));
2596
+ if (serviceIndex > 0) {
2597
+ return `/${segments.slice(serviceIndex).join("/")}`;
2598
+ }
2599
+ return input;
2600
+ }
2601
+ function joinUrl(baseUrl, path2) {
2602
+ const base = baseUrl.replace(/\/+$/, "");
2603
+ if (!path2) {
2604
+ return base;
2605
+ }
2606
+ return `${base}${path2.startsWith("/") ? path2 : `/${path2}`}`;
2607
+ }
2608
+ function isOceanetApiHost(targetUrl, apiBaseUrl) {
2609
+ try {
2610
+ return new URL(targetUrl).host.toLowerCase() === new URL(apiBaseUrl).host.toLowerCase();
2611
+ } catch {
2612
+ return false;
2613
+ }
2614
+ }
2615
+ function getHost(targetUrl) {
2616
+ try {
2617
+ return new URL(targetUrl).host.toLowerCase();
2618
+ } catch {
2619
+ return "";
2620
+ }
2621
+ }
2622
+ function resolveTokenKind(targetUrl) {
2623
+ const host = getHost(targetUrl);
2624
+ if (/^srm[.-]/i.test(host)) {
2625
+ return "yst";
2626
+ }
2627
+ if (/^yos[.-]/i.test(host)) {
2628
+ return "main";
2629
+ }
2630
+ return targetUrl.includes("/yst-") ? "yst" : "main";
2631
+ }
2632
+
2558
2633
  // src/core/http/response-guard.ts
2559
2634
  init_esm_shims();
2560
2635
  var AUTH_ERROR_CODES = [401, 403, 9913, 9914];
@@ -2595,15 +2670,6 @@ function fail(message, jsonMode, errorCode = null, exitCode = 1) {
2595
2670
  }
2596
2671
  process.exit(exitCode);
2597
2672
  }
2598
- function fixGitBashPath(url) {
2599
- if (url.includes(":") && !url.startsWith("http")) {
2600
- const oceanetIndex = url.indexOf("/oceanet-");
2601
- if (oceanetIndex >= 0) {
2602
- return url.substring(oceanetIndex);
2603
- }
2604
- }
2605
- return url;
2606
- }
2607
2673
  function parseHeaders(headers) {
2608
2674
  const result = {};
2609
2675
  if (Array.isArray(headers)) {
@@ -2623,7 +2689,7 @@ function buildUrl2(url, baseUrl) {
2623
2689
  }
2624
2690
  const config = OCEANET_CONFIG();
2625
2691
  const base = baseUrl || config.API_BASE_URL;
2626
- return `${base}${cleanUrl}`;
2692
+ return joinUrl(base, cleanUrl);
2627
2693
  }
2628
2694
  function parseParams(params) {
2629
2695
  if (!params || Object.keys(params).length === 0) {
@@ -2639,6 +2705,9 @@ function warnOnPageQueryEnvelope(context) {
2639
2705
  if (!["POST", "PUT", "PATCH"].includes(context.method.toUpperCase())) {
2640
2706
  return;
2641
2707
  }
2708
+ if (!isOceanetApiHost(context.fullUrl, OCEANET_CONFIG().API_BASE_URL)) {
2709
+ return;
2710
+ }
2642
2711
  const issue = detectPageQueryEnvelope(context.data);
2643
2712
  if (!issue) {
2644
2713
  return;
@@ -2747,11 +2816,6 @@ async function executeRequest(method, url, options) {
2747
2816
  const jsonMode = options.json === true;
2748
2817
  const spinner = ora4({ text: "Sending request...", isSilent: jsonMode }).start();
2749
2818
  try {
2750
- const accessToken = await getAccessToken();
2751
- if (!accessToken) {
2752
- spinner.fail("Not authenticated");
2753
- fail("Not authenticated. Please run: wukong-cli auth login", jsonMode);
2754
- }
2755
2819
  const parsed = parseRequestBody(options.data ?? "");
2756
2820
  if (parsed.error) {
2757
2821
  spinner.fail("Invalid request body");
@@ -2759,9 +2823,18 @@ async function executeRequest(method, url, options) {
2759
2823
  fail(`Invalid JSON in -d: ${parsed.error}
2760
2824
  Received: ${received}`, jsonMode);
2761
2825
  }
2826
+ const fullUrl = buildUrl2(url, options.baseUrl);
2827
+ const tokenKind = resolveTokenKind(fullUrl);
2828
+ if (tokenKind === "main") {
2829
+ const accessToken = await getAccessToken();
2830
+ if (!accessToken) {
2831
+ spinner.fail("Not authenticated");
2832
+ fail("Not authenticated. Please run: wukong-cli auth login", jsonMode);
2833
+ }
2834
+ }
2762
2835
  const context = {
2763
2836
  method,
2764
- fullUrl: buildUrl2(url, options.baseUrl),
2837
+ fullUrl,
2765
2838
  data: parsed.data,
2766
2839
  headers: parseHeaders(options.headers),
2767
2840
  params: options.params,
@@ -2769,7 +2842,7 @@ async function executeRequest(method, url, options) {
2769
2842
  spinner
2770
2843
  };
2771
2844
  warnOnPageQueryEnvelope(context);
2772
- const result = context.fullUrl.includes("/yst-") ? await sendWithYstToken(context) : await sendWithMainToken(context);
2845
+ const result = tokenKind === "yst" ? await sendWithYstToken(context) : await sendWithMainToken(context);
2773
2846
  if (looksLikeHtml(result.data)) {
2774
2847
  spinner.fail("Unexpected HTML response");
2775
2848
  fail(describeHtmlResponse(), jsonMode, null, 2);
@@ -3041,6 +3114,8 @@ function reportSwitch(name, previous) {
3041
3114
  console.log(chalk9.dim(` Environment: ${config.displayName}`));
3042
3115
  console.log(chalk9.dim(` API Base: ${config.apiBaseUrl}`));
3043
3116
  console.log(chalk9.dim(` Auth Base: ${config.authBaseUrl}`));
3117
+ console.log(chalk9.dim(` YOS Base: ${config.yosBaseUrl} ${chalk9.dim("(main token)")}`));
3118
+ console.log(chalk9.dim(` SRM Base: ${config.srmBaseUrl} ${chalk9.dim("(YST token)")}`));
3044
3119
  console.log(chalk9.dim(` Config: ${getUserConfigPath()}`));
3045
3120
  if (previous !== name) {
3046
3121
  console.log(chalk9.dim(` Previous: ${previous}`));
@@ -3122,6 +3197,8 @@ function runCurrent(json) {
3122
3197
  displayName: config.displayName,
3123
3198
  authBaseUrl: config.authBaseUrl,
3124
3199
  apiBaseUrl: config.apiBaseUrl,
3200
+ yosBaseUrl: config.yosBaseUrl,
3201
+ srmBaseUrl: config.srmBaseUrl,
3125
3202
  clientId: config.clientId
3126
3203
  },
3127
3204
  null,
@@ -3134,6 +3211,8 @@ function runCurrent(json) {
3134
3211
  console.log(`${chalk9.bold(env)} - ${chalk9.dim(config.displayName)}`);
3135
3212
  console.log(chalk9.dim(` API Base: ${config.apiBaseUrl}`));
3136
3213
  console.log(chalk9.dim(` Auth Base: ${config.authBaseUrl}`));
3214
+ console.log(chalk9.dim(` YOS Base: ${config.yosBaseUrl} (main token)`));
3215
+ console.log(chalk9.dim(` SRM Base: ${config.srmBaseUrl} (YST token)`));
3137
3216
  console.log(chalk9.dim(` Client ID: ${config.clientId}`));
3138
3217
  console.log(chalk9.dim(` Source: ${SOURCE_LABEL[source]}`));
3139
3218
  console.log("");