@heybox/hb-sdk 0.9.6-alpha.3 → 0.9.6-alpha.5

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.
Files changed (33) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +4 -0
  3. package/dist/cli-chunks/{artifact-DpdQXyMk.cjs → artifact-DVC4uf_d.cjs} +3 -3
  4. package/dist/cli-chunks/{build-6jaa_DWs.cjs → build-Cnbra2Uh.cjs} +5 -5
  5. package/dist/cli-chunks/{create-BxtJr_Qo.cjs → create-BA6LJaSN.cjs} +1 -1
  6. package/dist/cli-chunks/{dev-CXreyoOz.cjs → dev-DhunXM74.cjs} +340 -230
  7. package/dist/cli-chunks/{dev-context-C_d5kGJ0.cjs → dev-context-ChFPpG-d.cjs} +2 -2
  8. package/dist/cli-chunks/{doctor-RzGG7eTJ.cjs → doctor-of3bxqi4.cjs} +1 -1
  9. package/dist/cli-chunks/{games--86wl41n.cjs → games-Cal1suXc.cjs} +1 -1
  10. package/dist/cli-chunks/{index-D154ye55.cjs → index-D-tz0KHY.cjs} +19 -17
  11. package/dist/cli-chunks/{index-DQYKTVsj.cjs → index-HKZRLLPE.cjs} +1 -1
  12. package/dist/cli-chunks/{index.esm-Ciz9FXSG.cjs → index.esm-BEoQF0yq.cjs} +7 -6
  13. package/dist/cli-chunks/{login-DNLvgfHj.cjs → login-Zl2mfKS3.cjs} +1 -1
  14. package/dist/cli-chunks/{project-vite-CLYg4ukC.cjs → project-vite-DEBchdPu.cjs} +1 -1
  15. package/dist/cli-chunks/{remote-CDetYvVT.cjs → remote-CRhsafjv.cjs} +6 -6
  16. package/dist/cli-chunks/{runtime-permission-env-DtiCQ0vK.cjs → runtime-permission-env-B2j6D1ts.cjs} +2 -2
  17. package/dist/cli-chunks/{skill-k_TvHgJp.cjs → skill-O1q_ccfW.cjs} +2 -2
  18. package/dist/cli-chunks/{version-Ch_qF-6N.cjs → version-BOBr2N1h.cjs} +1 -1
  19. package/dist/cli.cjs +1 -1
  20. package/dist/devtools/browser-dev-host/assets/browser-dev-host-CTLTrYRi.js +103 -0
  21. package/dist/devtools/browser-dev-host/assets/{desktop-app-launch-BQyQdYEd.js → desktop-app-launch-B8Nuahot.js} +3 -3
  22. package/dist/devtools/browser-dev-host/assets/{index-Cd6MCK70.js → index-DkQhQiKD.js} +4 -4
  23. package/dist/devtools/browser-dev-host/assets/index-QPl84u9f.css +1 -0
  24. package/dist/devtools/browser-dev-host/index.html +3 -3
  25. package/dist/index.cjs.js +1 -1
  26. package/dist/index.esm.js +1 -1
  27. package/dist/vite.cjs.js +46 -15
  28. package/dist/vite.esm.js +46 -15
  29. package/package.json +6 -6
  30. package/skill/skill.json +4 -4
  31. package/types/vite/index.d.ts +4 -3
  32. package/dist/devtools/browser-dev-host/assets/browser-dev-host-Dx8r12md.js +0 -103
  33. package/dist/devtools/browser-dev-host/assets/index-DSTlrpnQ.css +0 -1
@@ -1,24 +1,25 @@
1
1
  'use strict';
2
2
 
3
- var index = require('./index-D154ye55.cjs');
3
+ var index = require('./index-D-tz0KHY.cjs');
4
4
  var node_crypto = require('node:crypto');
5
5
  var fs = require('node:fs');
6
6
  var path = require('node:path');
7
- var runtimePermissionEnv = require('./runtime-permission-env-DtiCQ0vK.cjs');
8
- var version = require('./version-Ch_qF-6N.cjs');
7
+ var runtimePermissionEnv = require('./runtime-permission-env-B2j6D1ts.cjs');
8
+ var version = require('./version-BOBr2N1h.cjs');
9
9
  require('node:zlib');
10
- var devContext = require('./dev-context-C_d5kGJ0.cjs');
10
+ var devContext = require('./dev-context-ChFPpG-d.cjs');
11
11
  var os = require('node:os');
12
12
  var net = require('node:net');
13
13
  var promises = require('node:dns/promises');
14
14
  var node_http = require('node:http');
15
15
  var node_module = require('node:module');
16
+ var node_events = require('node:events');
16
17
  var undici = require('undici');
17
18
  var fs$1 = require('node:fs/promises');
18
19
  var require$$0$1 = require('crypto');
19
20
  var require$$0 = require('buffer');
20
21
  var browser = require('./browser-RAy8e8cV.cjs');
21
- var projectVite = require('./project-vite-CLYg4ukC.cjs');
22
+ var projectVite = require('./project-vite-DEBchdPu.cjs');
22
23
 
23
24
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
24
25
  const DEFAULT_DEV_CONTEXT_TIMEOUT_MS = 3000;
@@ -1320,6 +1321,309 @@ function getDeviceLogs(appUrl) {
1320
1321
  return stores.get(Number(new URL(appUrl).port));
1321
1322
  }
1322
1323
 
1324
+ /** 只允许服务端签发的新版存档对象,固定 GET、无会话凭证、禁止重定向。 */
1325
+ function isGameSaveDownloadRequest(request) {
1326
+ if (request.source !== 'runtime-private' ||
1327
+ request.credentials !== 'omit' ||
1328
+ request.route !== 'game-save' ||
1329
+ request.target.kind !== 'absolute-url' ||
1330
+ request.method !== 'GET' ||
1331
+ request.redirectPolicy !== 'error' ||
1332
+ request.data !== undefined ||
1333
+ request.params !== undefined ||
1334
+ request.headers !== undefined)
1335
+ return false;
1336
+ try {
1337
+ const url = new URL(request.target.url);
1338
+ return (url.protocol === 'https:' &&
1339
+ url.hostname === 'heybox-beijing-1251007209.cos.ap-beijing.myqcloud.com' &&
1340
+ !url.port &&
1341
+ !url.username &&
1342
+ !url.password &&
1343
+ !url.hash &&
1344
+ /^\/cloud_archive\/[0-9]{1,20}\.zip$/.test(url.pathname) &&
1345
+ url.searchParams.has('q-signature'));
1346
+ }
1347
+ catch {
1348
+ return false;
1349
+ }
1350
+ }
1351
+
1352
+ const PATHNAME_MAX_DECODE_ROUNDS = 4;
1353
+ const OFFICIAL_ROOT_DOMAINS = ['xiaoheihe.cn', 'max-c.com', 'debugmode.cn', 'maxjia.com'];
1354
+ const DENIED_REQUEST_HEADERS = new Set([
1355
+ 'connection',
1356
+ 'content-length',
1357
+ 'host',
1358
+ 'keep-alive',
1359
+ 'proxy-connection',
1360
+ 'te',
1361
+ 'trailer',
1362
+ 'transfer-encoding',
1363
+ 'upgrade',
1364
+ 'x-heybox-runtime-auth-context-token',
1365
+ ]);
1366
+ /** 任意 origin 都不得通过公开 network.request 访问的 Runtime 私有路径。 */
1367
+ const PUBLIC_NETWORK_PROTECTED_PATH_PREFIXES = ['/user_miniprogram/runtime/auth', '/user_miniprogram/openapi/v1'];
1368
+ /** 官方 origin 上会签发、恢复或校验账号 credential 的私有路径。 */
1369
+ const PUBLIC_NETWORK_OFFICIAL_ACCOUNT_SENSITIVE_PATH_PREFIXES = [
1370
+ '/account/restore_login',
1371
+ '/account/check_login',
1372
+ '/account/login',
1373
+ '/account/get_login_code',
1374
+ '/account/login_code',
1375
+ '/account/get_qrcode_url',
1376
+ '/account/qr_state',
1377
+ '/account/google_2fa_verify',
1378
+ '/account/open/login',
1379
+ '/account/captcha',
1380
+ '/account/get_verify_code',
1381
+ '/account/send_verify_code',
1382
+ '/account/verify_code',
1383
+ ];
1384
+ /** 判断公开网络能力是否命中 Runtime 或官方账号敏感路径。 */
1385
+ function isProtectedMiniProgramNetworkPath(pathname, official) {
1386
+ const normalized = normalizePublicNetworkPathname(pathname);
1387
+ if (normalized === null)
1388
+ return true;
1389
+ if (matchesPathPrefix(normalized, PUBLIC_NETWORK_PROTECTED_PATH_PREFIXES))
1390
+ return true;
1391
+ return official && matchesPathPrefix(normalized, PUBLIC_NETWORK_OFFICIAL_ACCOUNT_SENSITIVE_PATH_PREFIXES);
1392
+ }
1393
+ /** 使用 Runtime 唯一的官方域名分类规则判断请求目标。 */
1394
+ function isOfficialMiniProgramNetworkUrl(url) {
1395
+ const hostname = url.hostname.toLowerCase().replace(/\.$/, '');
1396
+ return OFFICIAL_ROOT_DOMAINS.some((rootDomain) => hostname === rootDomain || hostname.endsWith(`.${rootDomain}`));
1397
+ }
1398
+ /** 判断公开网络能力是否禁止调用方设置该请求头。 */
1399
+ function isForbiddenMiniProgramNetworkRequestHeader(name) {
1400
+ const normalized = name.trim().toLowerCase();
1401
+ return DENIED_REQUEST_HEADERS.has(normalized) || /^(?:x-heybox|x-xhh)-(?:access-token|auth|authorization|pkey|session|token)$/.test(normalized);
1402
+ }
1403
+ function normalizePublicNetworkPathname(pathname) {
1404
+ let decoded = pathname;
1405
+ for (let round = 0; round < PATHNAME_MAX_DECODE_ROUNDS; round += 1) {
1406
+ let next;
1407
+ try {
1408
+ next = decodeURIComponent(decoded);
1409
+ }
1410
+ catch {
1411
+ return null;
1412
+ }
1413
+ if (next === decoded)
1414
+ return normalizeDecodedPathname(decoded);
1415
+ decoded = next;
1416
+ }
1417
+ try {
1418
+ if (decodeURIComponent(decoded) !== decoded)
1419
+ return null;
1420
+ }
1421
+ catch {
1422
+ return null;
1423
+ }
1424
+ return normalizeDecodedPathname(decoded);
1425
+ }
1426
+ function matchesPathPrefix(pathname, prefixes) {
1427
+ return prefixes.some((prefix) => pathname === prefix || pathname.startsWith(`${prefix}/`));
1428
+ }
1429
+ function normalizeDecodedPathname(pathname) {
1430
+ const segments = [];
1431
+ for (const segment of pathname.replace(/\\/g, '/').split('/')) {
1432
+ if (!segment || segment === '.')
1433
+ continue;
1434
+ if (segment === '..')
1435
+ segments.pop();
1436
+ else
1437
+ segments.push(segment);
1438
+ }
1439
+ return `/${segments.join('/')}`;
1440
+ }
1441
+
1442
+ const BROWSER_DEV_HOST_JSON_BODY_LIMIT = 1024 * 1024;
1443
+ class BrowserDevHostHttpError extends Error {
1444
+ status;
1445
+ code;
1446
+ constructor(status, code, message) {
1447
+ super(message);
1448
+ this.status = status;
1449
+ this.code = code;
1450
+ this.name = 'BrowserDevHostHttpError';
1451
+ }
1452
+ }
1453
+ function createBrowserDevHostRequestAbortScope(request, response) {
1454
+ const controller = new AbortController();
1455
+ const abort = () => controller.abort();
1456
+ const onResponseClose = () => {
1457
+ if (!response.writableEnded)
1458
+ abort();
1459
+ };
1460
+ request.once('aborted', abort);
1461
+ response.once('close', onResponseClose);
1462
+ if (request.aborted || (response.destroyed && !response.writableEnded))
1463
+ abort();
1464
+ return {
1465
+ dispose() {
1466
+ request.removeListener('aborted', abort);
1467
+ response.removeListener('close', onResponseClose);
1468
+ },
1469
+ signal: controller.signal,
1470
+ };
1471
+ }
1472
+ function readJsonRequestBody(request, options = {}) {
1473
+ return new Promise((resolve, reject) => {
1474
+ const chunks = [];
1475
+ const maxBytes = options.maxBytes ?? BROWSER_DEV_HOST_JSON_BODY_LIMIT;
1476
+ let size = 0;
1477
+ let tooLarge = false;
1478
+ request.on('data', (chunk) => {
1479
+ if (tooLarge)
1480
+ return;
1481
+ const buffer = Buffer.from(chunk);
1482
+ size += buffer.byteLength;
1483
+ if (size > maxBytes) {
1484
+ tooLarge = true;
1485
+ chunks.length = 0;
1486
+ reject(createBrowserDevHostError(413, 'REQUEST_ENTITY_TOO_LARGE', 'Browser Dev Host network proxy request body too large'));
1487
+ if (options.destroyOnLimit !== false)
1488
+ request.destroy();
1489
+ else
1490
+ request.resume();
1491
+ return;
1492
+ }
1493
+ chunks.push(buffer);
1494
+ });
1495
+ request.on('error', reject);
1496
+ request.on('aborted', () => {
1497
+ reject('Browser Dev Host network proxy request aborted');
1498
+ });
1499
+ request.on('end', () => {
1500
+ if (tooLarge)
1501
+ return;
1502
+ const rawBody = Buffer.concat(chunks).toString('utf8');
1503
+ if (!rawBody.trim()) {
1504
+ resolve({});
1505
+ return;
1506
+ }
1507
+ try {
1508
+ resolve(JSON.parse(rawBody));
1509
+ }
1510
+ catch {
1511
+ reject(createBrowserDevHostError(400, 'INVALID_JSON', 'Browser Dev Host network proxy received invalid JSON'));
1512
+ }
1513
+ });
1514
+ });
1515
+ }
1516
+ function writeJsonResponse(response, status, body) {
1517
+ response.writeHead(status, {
1518
+ 'content-type': 'application/json; charset=utf-8',
1519
+ 'cache-control': 'no-store',
1520
+ });
1521
+ response.end(body === undefined ? '' : JSON.stringify(body));
1522
+ }
1523
+ function writeTokenNetworkJsonResponse(response, status, body) {
1524
+ response.writeHead(status, {
1525
+ 'access-control-allow-headers': 'content-type',
1526
+ 'access-control-allow-methods': 'POST, OPTIONS',
1527
+ 'access-control-allow-origin': '*',
1528
+ 'access-control-allow-private-network': 'true',
1529
+ 'cache-control': 'no-store',
1530
+ 'content-type': 'application/json; charset=utf-8',
1531
+ });
1532
+ response.end(body === undefined ? '' : JSON.stringify(body));
1533
+ }
1534
+ function writeSerializedJsonResponse(response, status, body) {
1535
+ response.writeHead(status, {
1536
+ 'content-type': 'application/json; charset=utf-8',
1537
+ 'cache-control': 'no-store',
1538
+ });
1539
+ response.end(body);
1540
+ }
1541
+ function isRecord$2(value) {
1542
+ return Object.prototype.toString.call(value) === '[object Object]';
1543
+ }
1544
+ function isObjectLike(value) {
1545
+ return (typeof value === 'object' || typeof value === 'function') && value !== null;
1546
+ }
1547
+ function createBrowserDevHostError(status, code, message) {
1548
+ return new BrowserDevHostHttpError(status, code, message);
1549
+ }
1550
+ function readBrowserDevHostErrorStatus(error) {
1551
+ return isObjectLike(error) && typeof error.status === 'number' ? error.status : 500;
1552
+ }
1553
+ function toBrowserDevHostErrorPayload(error) {
1554
+ if (isObjectLike(error) && typeof error.code === 'string' && typeof error.message === 'string') {
1555
+ return {
1556
+ code: error.code,
1557
+ message: error.message,
1558
+ };
1559
+ }
1560
+ return {
1561
+ code: 'BROWSER_DEV_HOST_NETWORK_ERROR',
1562
+ message: readErrorMessage(error),
1563
+ };
1564
+ }
1565
+ function readErrorMessage(error) {
1566
+ return error instanceof Error ? error.message : String(error);
1567
+ }
1568
+
1569
+ const MAX_BYTES = 8 * 1024 * 1024;
1570
+ /** 固定存档桶的无凭证流式中转。调用方必须先通过 loopback、Origin 与 CSRF 校验。 */
1571
+ async function handleBrowserDevGameSaveDownload(request, response, fetchImpl) {
1572
+ const scope = createBrowserDevHostRequestAbortScope(request, response);
1573
+ let reader;
1574
+ try {
1575
+ const input = await readJsonRequestBody(request);
1576
+ if (!isRecord$2(input) || !isRecord$2(input.target) || !isGameSaveDownloadRequest(input)) {
1577
+ writeJsonResponse(response, 400, { code: 'INVALID_PARAMS', message: '无效存档下载请求' });
1578
+ return;
1579
+ }
1580
+ const signal = AbortSignal.any([scope.signal, AbortSignal.timeout(60_000)]);
1581
+ const upstream = await fetchImpl(String(input.target.url), { method: 'GET', credentials: 'omit', redirect: 'error', signal });
1582
+ reader = upstream.body?.getReader();
1583
+ if (upstream.status !== 200 || !reader || upstream.headers.has('content-range')) {
1584
+ writeJsonResponse(response, 502, { code: 'DOWNLOAD_HTTP_STATUS', message: '存档下载响应异常' });
1585
+ return;
1586
+ }
1587
+ const encoded = upstream.headers.get('content-encoding');
1588
+ const length = !encoded || encoded === 'identity' ? upstream.headers.get('content-length') : null;
1589
+ if (length && (!/^(0|[1-9]\d*)$/.test(length) || Number(length) > MAX_BYTES)) {
1590
+ writeJsonResponse(response, 413, { code: 'FILE_TOO_LARGE', message: '存档文件超过 8 MiB' });
1591
+ return;
1592
+ }
1593
+ response.writeHead(200, {
1594
+ 'content-type': 'application/zip',
1595
+ 'cache-control': 'no-store',
1596
+ 'x-content-type-options': 'nosniff',
1597
+ ...(length ? { 'content-length': length } : {}),
1598
+ });
1599
+ let received = 0;
1600
+ while (true) {
1601
+ signal.throwIfAborted();
1602
+ const chunk = await reader.read();
1603
+ if (chunk.done)
1604
+ break;
1605
+ // 最多多转发一个字节,使接收端能稳定判断 FILE_TOO_LARGE;不缓冲完整 ZIP。
1606
+ const bytes = chunk.value.subarray(0, Math.max(0, MAX_BYTES + 1 - received));
1607
+ received += bytes.byteLength;
1608
+ if (!response.write(bytes))
1609
+ await node_events.once(response, 'drain', { signal });
1610
+ if (received > MAX_BYTES)
1611
+ break;
1612
+ }
1613
+ response.end();
1614
+ }
1615
+ catch {
1616
+ if (!response.headersSent)
1617
+ writeJsonResponse(response, 502, { code: 'DOWNLOAD_NETWORK_FAILED', message: '存档下载失败或已取消' });
1618
+ else
1619
+ response.destroy();
1620
+ }
1621
+ finally {
1622
+ await reader?.cancel().catch(() => { });
1623
+ scope.dispose();
1624
+ }
1625
+ }
1626
+
1323
1627
  /** Dev Shell 读取局域网 Dev Session endpoint 的 query 参数。 */
1324
1628
  const MINI_PROGRAM_DEV_CONTEXT_QUERY_PARAM = 'dev_context_url';
1325
1629
  /** Browser Dev Host 创建和读取 Dev Session 的固定路径。 */
@@ -1556,223 +1860,6 @@ class StrictJsonKeyScanner {
1556
1860
  }
1557
1861
  }
1558
1862
 
1559
- const BROWSER_DEV_HOST_JSON_BODY_LIMIT = 1024 * 1024;
1560
- class BrowserDevHostHttpError extends Error {
1561
- status;
1562
- code;
1563
- constructor(status, code, message) {
1564
- super(message);
1565
- this.status = status;
1566
- this.code = code;
1567
- this.name = 'BrowserDevHostHttpError';
1568
- }
1569
- }
1570
- function createBrowserDevHostRequestAbortScope(request, response) {
1571
- const controller = new AbortController();
1572
- const abort = () => controller.abort();
1573
- const onResponseClose = () => {
1574
- if (!response.writableEnded)
1575
- abort();
1576
- };
1577
- request.once('aborted', abort);
1578
- response.once('close', onResponseClose);
1579
- if (request.aborted || (response.destroyed && !response.writableEnded))
1580
- abort();
1581
- return {
1582
- dispose() {
1583
- request.removeListener('aborted', abort);
1584
- response.removeListener('close', onResponseClose);
1585
- },
1586
- signal: controller.signal,
1587
- };
1588
- }
1589
- function readJsonRequestBody(request, options = {}) {
1590
- return new Promise((resolve, reject) => {
1591
- const chunks = [];
1592
- const maxBytes = options.maxBytes ?? BROWSER_DEV_HOST_JSON_BODY_LIMIT;
1593
- let size = 0;
1594
- let tooLarge = false;
1595
- request.on('data', (chunk) => {
1596
- if (tooLarge)
1597
- return;
1598
- const buffer = Buffer.from(chunk);
1599
- size += buffer.byteLength;
1600
- if (size > maxBytes) {
1601
- tooLarge = true;
1602
- chunks.length = 0;
1603
- reject(createBrowserDevHostError(413, 'REQUEST_ENTITY_TOO_LARGE', 'Browser Dev Host network proxy request body too large'));
1604
- if (options.destroyOnLimit !== false)
1605
- request.destroy();
1606
- else
1607
- request.resume();
1608
- return;
1609
- }
1610
- chunks.push(buffer);
1611
- });
1612
- request.on('error', reject);
1613
- request.on('aborted', () => {
1614
- reject('Browser Dev Host network proxy request aborted');
1615
- });
1616
- request.on('end', () => {
1617
- if (tooLarge)
1618
- return;
1619
- const rawBody = Buffer.concat(chunks).toString('utf8');
1620
- if (!rawBody.trim()) {
1621
- resolve({});
1622
- return;
1623
- }
1624
- try {
1625
- resolve(JSON.parse(rawBody));
1626
- }
1627
- catch {
1628
- reject(createBrowserDevHostError(400, 'INVALID_JSON', 'Browser Dev Host network proxy received invalid JSON'));
1629
- }
1630
- });
1631
- });
1632
- }
1633
- function writeJsonResponse(response, status, body) {
1634
- response.writeHead(status, {
1635
- 'content-type': 'application/json; charset=utf-8',
1636
- 'cache-control': 'no-store',
1637
- });
1638
- response.end(body === undefined ? '' : JSON.stringify(body));
1639
- }
1640
- function writeTokenNetworkJsonResponse(response, status, body) {
1641
- response.writeHead(status, {
1642
- 'access-control-allow-headers': 'content-type',
1643
- 'access-control-allow-methods': 'POST, OPTIONS',
1644
- 'access-control-allow-origin': '*',
1645
- 'access-control-allow-private-network': 'true',
1646
- 'cache-control': 'no-store',
1647
- 'content-type': 'application/json; charset=utf-8',
1648
- });
1649
- response.end(body === undefined ? '' : JSON.stringify(body));
1650
- }
1651
- function writeSerializedJsonResponse(response, status, body) {
1652
- response.writeHead(status, {
1653
- 'content-type': 'application/json; charset=utf-8',
1654
- 'cache-control': 'no-store',
1655
- });
1656
- response.end(body);
1657
- }
1658
- function isRecord$2(value) {
1659
- return Object.prototype.toString.call(value) === '[object Object]';
1660
- }
1661
- function isObjectLike(value) {
1662
- return (typeof value === 'object' || typeof value === 'function') && value !== null;
1663
- }
1664
- function createBrowserDevHostError(status, code, message) {
1665
- return new BrowserDevHostHttpError(status, code, message);
1666
- }
1667
- function readBrowserDevHostErrorStatus(error) {
1668
- return isObjectLike(error) && typeof error.status === 'number' ? error.status : 500;
1669
- }
1670
- function toBrowserDevHostErrorPayload(error) {
1671
- if (isObjectLike(error) && typeof error.code === 'string' && typeof error.message === 'string') {
1672
- return {
1673
- code: error.code,
1674
- message: error.message,
1675
- };
1676
- }
1677
- return {
1678
- code: 'BROWSER_DEV_HOST_NETWORK_ERROR',
1679
- message: readErrorMessage(error),
1680
- };
1681
- }
1682
- function readErrorMessage(error) {
1683
- return error instanceof Error ? error.message : String(error);
1684
- }
1685
-
1686
- const PATHNAME_MAX_DECODE_ROUNDS = 4;
1687
- const OFFICIAL_ROOT_DOMAINS = ['xiaoheihe.cn', 'max-c.com', 'debugmode.cn', 'maxjia.com'];
1688
- const DENIED_REQUEST_HEADERS = new Set([
1689
- 'connection',
1690
- 'content-length',
1691
- 'host',
1692
- 'keep-alive',
1693
- 'proxy-connection',
1694
- 'te',
1695
- 'trailer',
1696
- 'transfer-encoding',
1697
- 'upgrade',
1698
- 'x-heybox-runtime-auth-context-token',
1699
- ]);
1700
- /** 任意 origin 都不得通过公开 network.request 访问的 Runtime 私有路径。 */
1701
- const PUBLIC_NETWORK_PROTECTED_PATH_PREFIXES = ['/user_miniprogram/runtime/auth', '/user_miniprogram/openapi/v1'];
1702
- /** 官方 origin 上会签发、恢复或校验账号 credential 的私有路径。 */
1703
- const PUBLIC_NETWORK_OFFICIAL_ACCOUNT_SENSITIVE_PATH_PREFIXES = [
1704
- '/account/restore_login',
1705
- '/account/check_login',
1706
- '/account/login',
1707
- '/account/get_login_code',
1708
- '/account/login_code',
1709
- '/account/get_qrcode_url',
1710
- '/account/qr_state',
1711
- '/account/google_2fa_verify',
1712
- '/account/open/login',
1713
- '/account/captcha',
1714
- '/account/get_verify_code',
1715
- '/account/send_verify_code',
1716
- '/account/verify_code',
1717
- ];
1718
- /** 判断公开网络能力是否命中 Runtime 或官方账号敏感路径。 */
1719
- function isProtectedMiniProgramNetworkPath(pathname, official) {
1720
- const normalized = normalizePublicNetworkPathname(pathname);
1721
- if (normalized === null)
1722
- return true;
1723
- if (matchesPathPrefix(normalized, PUBLIC_NETWORK_PROTECTED_PATH_PREFIXES))
1724
- return true;
1725
- return official && matchesPathPrefix(normalized, PUBLIC_NETWORK_OFFICIAL_ACCOUNT_SENSITIVE_PATH_PREFIXES);
1726
- }
1727
- /** 使用 Runtime 唯一的官方域名分类规则判断请求目标。 */
1728
- function isOfficialMiniProgramNetworkUrl(url) {
1729
- const hostname = url.hostname.toLowerCase().replace(/\.$/, '');
1730
- return OFFICIAL_ROOT_DOMAINS.some((rootDomain) => hostname === rootDomain || hostname.endsWith(`.${rootDomain}`));
1731
- }
1732
- /** 判断公开网络能力是否禁止调用方设置该请求头。 */
1733
- function isForbiddenMiniProgramNetworkRequestHeader(name) {
1734
- const normalized = name.trim().toLowerCase();
1735
- return DENIED_REQUEST_HEADERS.has(normalized) || /^(?:x-heybox|x-xhh)-(?:access-token|auth|authorization|pkey|session|token)$/.test(normalized);
1736
- }
1737
- function normalizePublicNetworkPathname(pathname) {
1738
- let decoded = pathname;
1739
- for (let round = 0; round < PATHNAME_MAX_DECODE_ROUNDS; round += 1) {
1740
- let next;
1741
- try {
1742
- next = decodeURIComponent(decoded);
1743
- }
1744
- catch {
1745
- return null;
1746
- }
1747
- if (next === decoded)
1748
- return normalizeDecodedPathname(decoded);
1749
- decoded = next;
1750
- }
1751
- try {
1752
- if (decodeURIComponent(decoded) !== decoded)
1753
- return null;
1754
- }
1755
- catch {
1756
- return null;
1757
- }
1758
- return normalizeDecodedPathname(decoded);
1759
- }
1760
- function matchesPathPrefix(pathname, prefixes) {
1761
- return prefixes.some((prefix) => pathname === prefix || pathname.startsWith(`${prefix}/`));
1762
- }
1763
- function normalizeDecodedPathname(pathname) {
1764
- const segments = [];
1765
- for (const segment of pathname.replace(/\\/g, '/').split('/')) {
1766
- if (!segment || segment === '.')
1767
- continue;
1768
- if (segment === '..')
1769
- segments.pop();
1770
- else
1771
- segments.push(segment);
1772
- }
1773
- return `/${segments.join('/')}`;
1774
- }
1775
-
1776
1863
  const MAX_BROWSER_DEV_HOST_NETWORK_REQUEST_BODY = 2 * 1024 * 1024;
1777
1864
  const MAX_BROWSER_DEV_HOST_NETWORK_RESPONSE_BODY = 5 * 1024 * 1024;
1778
1865
  const DENIED_NETWORK_TARGETS = createDeniedNetworkTargets();
@@ -3056,8 +3143,8 @@ const DEFAULT_CHANNEL_TRANSPORT = {
3056
3143
  };
3057
3144
  const IPV4_LOOPBACK_ADDRESSES = new net.BlockList();
3058
3145
  IPV4_LOOPBACK_ADDRESSES.addSubnet('127.0.0.0', 8, 'ipv4');
3059
- const { WebSocket, WebSocketServer } = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/dev-CXreyoOz.cjs', document.baseURI).href)))('ws');
3060
- const { parse: parseHtml } = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/dev-CXreyoOz.cjs', document.baseURI).href)))('parse5');
3146
+ const { WebSocket, WebSocketServer } = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/dev-DhunXM74.cjs', document.baseURI).href)))('ws');
3147
+ const { parse: parseHtml } = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/dev-DhunXM74.cjs', document.baseURI).href)))('parse5');
3061
3148
  const BROWSER_DEV_HOST_ROOT_CANDIDATES = [
3062
3149
  path.resolve(__dirname, 'devtools/browser-dev-host'),
3063
3150
  path.resolve(__dirname, '../devtools/browser-dev-host'),
@@ -3399,6 +3486,18 @@ function createBrowserDevHostServer(root, runtime) {
3399
3486
  writeSerializedJsonResponse(response, 200, runtime.readBootstrapJson());
3400
3487
  return;
3401
3488
  }
3489
+ if (pathname === '/__hb_sdk__/game-save-download') {
3490
+ if (!isValidSensitiveRequest(request, loopbackPeer, runtime.sessionController.csrfToken)) {
3491
+ writeForbidden(response);
3492
+ return;
3493
+ }
3494
+ if (request.method !== 'POST') {
3495
+ writeMethodNotAllowed(response, 'POST');
3496
+ return;
3497
+ }
3498
+ await handleBrowserDevGameSaveDownload(request, response, runtime.fetchImpl);
3499
+ return;
3500
+ }
3402
3501
  if (pathname === '/__hb_sdk__/sandbox') {
3403
3502
  if (!isValidSensitiveRequest(request, loopbackPeer, runtime.sessionController.csrfToken)) {
3404
3503
  writeForbidden(response);
@@ -12224,7 +12323,7 @@ function assertNodeRuntimeCapabilities(ctx, settings) {
12224
12323
  function createNodeRealtimeDriverRegistry() {
12225
12324
  const registry = createRuntimeRealtimeDriverRegistry();
12226
12325
  registry.registerLazy('node-websocket', async () => {
12227
- const mod = await Promise.resolve().then(function () { return require('./index.esm-Ciz9FXSG.cjs'); });
12326
+ const mod = await Promise.resolve().then(function () { return require('./index.esm-BEoQF0yq.cjs'); });
12228
12327
  return mod.createNodeWebSocketRuntimeDriver();
12229
12328
  });
12230
12329
  return registry;
@@ -16059,7 +16158,16 @@ function createBrowserDevHostCliAuth(options = {}) {
16059
16158
  {
16060
16159
  id: 'hb-sdk-dev-host',
16061
16160
  match: () => 1,
16062
- request: applyRuntimeRequestTargetPolicy(websitePolicy.request, { serviceEnvironment: 'production' }),
16161
+ request: applyRuntimeRequestTargetPolicy(websitePolicy.request, {
16162
+ serviceEnvironment: 'production',
16163
+ targets: {
16164
+ ...runtimeRequestTargets,
16165
+ 'heybox-api': {
16166
+ ...runtimeRequestTargets['heybox-api'],
16167
+ prod: index.resolveHeyboxApiBaseUrl({ env: options.env ?? process.env }),
16168
+ },
16169
+ },
16170
+ }),
16063
16171
  },
16064
16172
  ],
16065
16173
  });
@@ -16140,7 +16248,10 @@ async function executeCliHeyboxAuthenticatedRequest(runtime, session, request, s
16140
16248
  }
16141
16249
  const credentials = request.credentials ?? 'heybox-session';
16142
16250
  const method = (request.method ?? 'GET').toUpperCase();
16143
- const headers = {};
16251
+ const serviceTag = index.resolveHeyboxRylaiServiceTag(path);
16252
+ const headers = {
16253
+ ...(serviceTag ? { 'x-rylai-service-tag': serviceTag } : {}),
16254
+ };
16144
16255
  if (credentials !== 'omit')
16145
16256
  headers.cookie = session.cookieHeader;
16146
16257
  if (request.headers) {
@@ -16159,6 +16270,7 @@ async function executeCliHeyboxAuthenticatedRequest(runtime, session, request, s
16159
16270
  method: method,
16160
16271
  query: {
16161
16272
  heybox_id: session.heyboxId,
16273
+ ...(serviceTag ? { special_tag: serviceTag } : {}),
16162
16274
  ...readQueryParams(request.params),
16163
16275
  },
16164
16276
  signal,
@@ -16841,9 +16953,7 @@ function createViteServerOptions(projectRoot, options, launchPlugin) {
16841
16953
  // launch.json 由 mini-program-dev-launch plugin 自己处理 PNA/CORS 预检;
16842
16954
  // Vite 通用 CORS 会抢先返回 `*`,缺少 Access-Control-Allow-Private-Network。
16843
16955
  cors: false,
16844
- hmr: {
16845
- clientPort: options.port ?? DEFAULT_APP_PORT,
16846
- },
16956
+ ...(options.hmr === false ? { hmr: false } : {}),
16847
16957
  host: DEV_LISTEN_HOST,
16848
16958
  port: options.port ?? DEFAULT_APP_PORT,
16849
16959
  strictPort: true,
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var index = require('./index-D154ye55.cjs');
4
- var runtimePermissionEnv = require('./runtime-permission-env-DtiCQ0vK.cjs');
3
+ var index = require('./index-D-tz0KHY.cjs');
4
+ var runtimePermissionEnv = require('./runtime-permission-env-B2j6D1ts.cjs');
5
5
  var node_crypto = require('node:crypto');
6
6
  var fs = require('node:fs/promises');
7
7
  var path = require('node:path');
@@ -3,7 +3,7 @@
3
3
  var fs = require('node:fs/promises');
4
4
  var os = require('node:os');
5
5
  var path = require('node:path');
6
- var index = require('./index-D154ye55.cjs');
6
+ var index = require('./index-D-tz0KHY.cjs');
7
7
  require('node:module');
8
8
  require('readline');
9
9
  require('os');
@@ -3,7 +3,7 @@
3
3
  var node_crypto = require('node:crypto');
4
4
  var fs = require('node:fs/promises');
5
5
  var path = require('node:path');
6
- var index = require('./index-D154ye55.cjs');
6
+ var index = require('./index-D-tz0KHY.cjs');
7
7
  require('node:module');
8
8
  require('readline');
9
9
  require('os');