@heybox/hb-sdk 0.8.0 → 0.8.1-alpha.10

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 (69) hide show
  1. package/CHANGELOG.md +84 -0
  2. package/README.md +80 -7
  3. package/dist/cli-chunks/{build-PYCNacya.cjs → build-CtqIXxDL.cjs} +16 -10
  4. package/dist/cli-chunks/{context-m2W2XbL0.cjs → context-t57bMfbr.cjs} +17 -3
  5. package/dist/cli-chunks/{create-BdAg3WGA.cjs → create-BDOPSacf.cjs} +1 -1
  6. package/dist/cli-chunks/{dev-CyZuw7Yn.cjs → dev-VxjconYc.cjs} +628 -147
  7. package/dist/cli-chunks/{doctor-DU8rCfUF.cjs → doctor-BkfYdlnZ.cjs} +1 -1
  8. package/dist/cli-chunks/{index-MMW2ibQm.cjs → index-DDrytLTX.cjs} +87 -15
  9. package/dist/cli-chunks/{index-DATObqzK.cjs → index-lLaHzwfT.cjs} +2 -2
  10. package/dist/cli-chunks/{index.esm-BiAaAUFC.cjs → index.esm-Dy4qRhuo.cjs} +9 -8
  11. package/dist/cli-chunks/{login-B3TThMss.cjs → login-D2EX4R5_.cjs} +2 -2
  12. package/dist/cli-chunks/{project-vite-BQj8YLI4.cjs → project-vite-CFhz2THK.cjs} +1 -1
  13. package/dist/cli-chunks/{remote-DNvI7tHH.cjs → remote-CfESZxO2.cjs} +41 -28
  14. package/dist/cli-chunks/{runtime-gate-BEFp1w_s.cjs → runtime-gate-BWb8QIcX.cjs} +0 -107
  15. package/dist/cli-chunks/{runtime-permission-env-CtL8rsjB.cjs → runtime-permission-env-BtTDFqEL.cjs} +304 -23
  16. package/dist/cli-chunks/{session-DjBkjaF8.cjs → session-Dkhwjqhm.cjs} +1 -1
  17. package/dist/cli-chunks/{skill-cR_wnaw2.cjs → skill-DOveC5jt.cjs} +83 -27
  18. package/dist/cli-chunks/{version-yEn1E2Bg.cjs → version-C4nE66sX.cjs} +1 -1
  19. package/dist/cli.cjs +1 -1
  20. package/dist/devtools/browser-dev-host/assets/browser-dev-host-BM9Qo_Ta.js +101 -0
  21. package/dist/devtools/browser-dev-host/assets/desktop-app-launch-C2I333Yn.js +6 -0
  22. package/dist/devtools/browser-dev-host/assets/index-Bnb6MMTv.js +567 -0
  23. package/dist/devtools/browser-dev-host/assets/index-D-aNERAr.css +1 -0
  24. package/dist/devtools/browser-dev-host/index.html +3 -3
  25. package/dist/index.cjs.js +1970 -1567
  26. package/dist/index.esm.js +1969 -1568
  27. package/dist/miniapp-publish.cjs.js +61 -0
  28. package/dist/miniapp-publish.esm.js +59 -1
  29. package/dist/protocol.cjs.js +64 -13
  30. package/dist/protocol.esm.js +64 -13
  31. package/dist/templates/vanilla-vite-js/README.md.ejs +1 -1
  32. package/dist/templates/vanilla-vite-js/package.json.ejs +1 -0
  33. package/dist/templates/vanilla-vite-js/vite.config.js +1 -1
  34. package/dist/vite.cjs.js +1333 -18
  35. package/dist/vite.esm.js +1334 -20
  36. package/package.json +9 -11
  37. package/skill/SKILL.md +11 -3
  38. package/skill/references/api-protocol.md +8 -4
  39. package/skill/references/api-root.md +328 -210
  40. package/skill/references/cli.md +11 -3
  41. package/skill/references/examples.md +13 -1
  42. package/skill/references/recipes.md +162 -0
  43. package/skill/references/safety-boundaries.md +9 -3
  44. package/skill/skill.json +5 -5
  45. package/types/core/client.d.ts +9 -1
  46. package/types/core/sdk.d.ts +6 -0
  47. package/types/core/singleton.d.ts +6 -0
  48. package/types/devtools/device-logs.d.ts +48 -0
  49. package/types/index.d.ts +5 -1
  50. package/types/miniapp-manifest/companion-directory.d.ts +2 -0
  51. package/types/miniapp-manifest/companion-executable.d.ts +4 -0
  52. package/types/miniapp-manifest/companion-types.d.ts +38 -0
  53. package/types/miniapp-manifest/companions.d.ts +17 -0
  54. package/types/miniapp-manifest/index.d.ts +2 -0
  55. package/types/miniapp-manifest/node.d.ts +9 -0
  56. package/types/miniapp-manifest/permissions.d.ts +1 -1
  57. package/types/miniapp-manifest/schema.d.ts +5 -1
  58. package/types/miniapp-publish/index.d.ts +17 -2
  59. package/types/modules/companion/index.d.ts +57 -0
  60. package/types/modules/environment/index.d.ts +70 -0
  61. package/types/modules/network/index.d.ts +1 -4
  62. package/types/modules/network/observability.d.ts +0 -1
  63. package/types/protocol/dev-session.d.ts +8 -1
  64. package/types/protocol.d.ts +1 -1
  65. package/types/vite/index.d.ts +11 -4
  66. package/dist/devtools/browser-dev-host/assets/browser-dev-host-TzYf9L6C.js +0 -99
  67. package/dist/devtools/browser-dev-host/assets/index-C5MZZDa5.js +0 -567
  68. package/dist/devtools/browser-dev-host/assets/index-P-ra4m1y.css +0 -1
  69. package/dist/devtools/browser-dev-host/assets/workbench-state-BwV7bm4n.js +0 -5
@@ -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-MMW2ibQm.cjs');
6
+ var index = require('./index-DDrytLTX.cjs');
7
7
  require('node:module');
8
8
  require('node:fs');
9
9
  require('path');
@@ -234,19 +234,19 @@ function requireArgument () {
234
234
 
235
235
  var command = {};
236
236
 
237
- const require$5 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/index-MMW2ibQm.cjs', document.baseURI).href)));
237
+ const require$5 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/index-DDrytLTX.cjs', document.baseURI).href)));
238
238
  function __require$4() { return require$5("node:events"); }
239
239
 
240
- const require$4 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/index-MMW2ibQm.cjs', document.baseURI).href)));
240
+ const require$4 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/index-DDrytLTX.cjs', document.baseURI).href)));
241
241
  function __require$3() { return require$4("node:child_process"); }
242
242
 
243
- const require$3 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/index-MMW2ibQm.cjs', document.baseURI).href)));
243
+ const require$3 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/index-DDrytLTX.cjs', document.baseURI).href)));
244
244
  function __require$2() { return require$3("node:path"); }
245
245
 
246
- const require$2 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/index-MMW2ibQm.cjs', document.baseURI).href)));
246
+ const require$2 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/index-DDrytLTX.cjs', document.baseURI).href)));
247
247
  function __require$1() { return require$2("node:fs"); }
248
248
 
249
- const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/index-MMW2ibQm.cjs', document.baseURI).href)));
249
+ const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/index-DDrytLTX.cjs', document.baseURI).href)));
250
250
  function __require() { return require$1("node:process"); }
251
251
 
252
252
  var help = {};
@@ -3795,6 +3795,77 @@ const {
3795
3795
  Help,
3796
3796
  } = commander;
3797
3797
 
3798
+ /** Agent 输出只使用 stdout JSON/NDJSON,不混入交互提示。 */
3799
+ function installDevLogCommands(dev) {
3800
+ dev.command('sandbox').description('查看设备沙箱').command('list')
3801
+ .requiredOption('--device <id>', '设备会话 ID').option('--path <path>', '逻辑目录', '.')
3802
+ .option('--port <port>', '调试台端口', '5174').option('--json', 'JSON 输出')
3803
+ .action(async (options, command) => {
3804
+ const port = Number(command.parent?.parent?.opts().port ?? options.port);
3805
+ if (!Number.isInteger(port) || port < 1 || port > 65535)
3806
+ throw new Error('端口无效');
3807
+ const origin = `http://127.0.0.1:${port}`;
3808
+ const bootstrap = await (await fetch(origin + '/__hb_sdk_bootstrap__', { signal: AbortSignal.timeout(5000), redirect: 'error' })).json();
3809
+ const response = await fetch(origin + '/__hb_sdk__/sandbox', { method: 'POST', redirect: 'error', headers: { origin, 'content-type': 'application/json', 'x-hb-sdk-csrf': bootstrap.csrfToken }, body: JSON.stringify({ device: options.device, path: options.path }), signal: AbortSignal.timeout(12000) });
3810
+ if (!response.ok)
3811
+ throw new Error(`目录查询失败:HTTP ${response.status}`);
3812
+ process.stdout.write(JSON.stringify(await response.json()) + '\n');
3813
+ });
3814
+ for (const kind of ['logs', 'devices']) {
3815
+ dev
3816
+ .command(kind)
3817
+ .description(kind === 'logs' ? '读取多设备调试日志' : '列出调试设备会话')
3818
+ .option('--port <port>', '调试台端口', '5174')
3819
+ .option('--json', '输出机器可读 JSON')
3820
+ .option('--device <id>', '设备会话 ID')
3821
+ .option('--level <level>', '日志级别')
3822
+ .option('--source <source>', '日志来源')
3823
+ .option('--query <text>', '搜索输出')
3824
+ .option('--callId <id>', '关联 SDK 调用 ID')
3825
+ .option('--id <id>', '读取服务端日志 ID')
3826
+ .option('--since <timestamp>', '设备时间下界,毫秒')
3827
+ .option('--after <cursor>', '从游标后继续读取', '0')
3828
+ .option('--limit <count>', '每页条数', '100')
3829
+ .option('--follow', '持续输出 NDJSON')
3830
+ .option('--duration <seconds>', '持续读取时长,默认 60 秒', '60')
3831
+ .action(async (options, command) => {
3832
+ const port = Number(command.parent?.opts().port ?? options.port);
3833
+ const duration = Number(options.duration);
3834
+ if (!Number.isInteger(port) || port < 1 || port > 65535 || !Number.isFinite(duration) || duration <= 0)
3835
+ throw new Error('端口或持续时间无效');
3836
+ const params = new URLSearchParams();
3837
+ for (const key of ['device', 'level', 'source', 'query', 'after', 'limit', 'callId', 'id', 'since'])
3838
+ if (options[key])
3839
+ params.set(key, options[key]);
3840
+ let epoch = '';
3841
+ const deadline = Date.now() + duration * 1000;
3842
+ do {
3843
+ const response = await fetch(`http://127.0.0.1:${port}/__hb_sdk__/device-logs?${params}`, {
3844
+ signal: AbortSignal.timeout(5000),
3845
+ redirect: 'error',
3846
+ });
3847
+ if (!response.ok)
3848
+ throw new Error(`日志读取失败:HTTP ${response.status}`);
3849
+ const page = await response.json();
3850
+ if (!page.epoch)
3851
+ throw new Error('当前调试台没有设备日志服务,请确认项目使用 miniappManifest 并通过 hb-sdk dev 启动');
3852
+ if (epoch && epoch !== page.epoch) {
3853
+ params.set('after', '0');
3854
+ epoch = page.epoch;
3855
+ continue;
3856
+ }
3857
+ epoch = page.epoch;
3858
+ process.stdout.write(JSON.stringify(kind === 'devices' ? { epoch, devices: page.devices } : page) + '\n');
3859
+ params.set('after', String(page.nextCursor));
3860
+ if (!options.follow)
3861
+ break;
3862
+ if (!page.hasMore)
3863
+ await new Promise((resolve) => setTimeout(resolve, 1000));
3864
+ } while (Date.now() < deadline);
3865
+ });
3866
+ }
3867
+ }
3868
+
3798
3869
  var envPaths$1 = {exports: {}};
3799
3870
 
3800
3871
  var hasRequiredEnvPaths;
@@ -13353,7 +13424,7 @@ function getPathname(pathWithQuery) {
13353
13424
  }
13354
13425
 
13355
13426
  const CLI_VERSION_PLACEHOLDER = ['__HB', 'SDK', 'CLI', 'VERSION__'].join('_');
13356
- const BUILT_CLI_VERSION = '0.8.0';
13427
+ const BUILT_CLI_VERSION = '0.8.1-alpha.10';
13357
13428
  const PACKAGE_JSON_CANDIDATES = [
13358
13429
  path.resolve(__dirname, '..', '..', 'package.json'),
13359
13430
  path.resolve(__dirname, '..', 'package.json'),
@@ -13447,6 +13518,7 @@ function createCliProgram(overrides = {}) {
13447
13518
  const logger = resolveLogger(command);
13448
13519
  await handlers.runDevCommand(options, { logger });
13449
13520
  }, handlers.printUpdateReminder, resolveLogger));
13521
+ installDevLogCommands(program.commands.find(command => command.name() === 'dev'));
13450
13522
  addVerboseOption(program.command('build').description('构建当前小程序项目').option('--env <name>', '加载项目根下 .env.<name> 预设并作为 Vite mode')).action(async (...args) => {
13451
13523
  const command = readCommandFromActionArgs(args);
13452
13524
  if (!command) {
@@ -13701,39 +13773,39 @@ function createCommandLoggerResolver(options) {
13701
13773
  };
13702
13774
  }
13703
13775
  const defaultClearLoginStatus = async (...args) => {
13704
- const { clearLoginStatus } = await Promise.resolve().then(function () { return require('./login-B3TThMss.cjs'); });
13776
+ const { clearLoginStatus } = await Promise.resolve().then(function () { return require('./login-D2EX4R5_.cjs'); });
13705
13777
  return clearLoginStatus(...args);
13706
13778
  };
13707
13779
  const defaultLoginToHeybox = async (...args) => {
13708
- const { loginToHeybox } = await Promise.resolve().then(function () { return require('./login-B3TThMss.cjs'); });
13780
+ const { loginToHeybox } = await Promise.resolve().then(function () { return require('./login-D2EX4R5_.cjs'); });
13709
13781
  return loginToHeybox(...args);
13710
13782
  };
13711
13783
  const defaultPrintLoginStatus = async (...args) => {
13712
- const { printLoginStatus } = await Promise.resolve().then(function () { return require('./login-B3TThMss.cjs'); });
13784
+ const { printLoginStatus } = await Promise.resolve().then(function () { return require('./login-D2EX4R5_.cjs'); });
13713
13785
  return printLoginStatus(...args);
13714
13786
  };
13715
13787
  const defaultRunBuildCommand = async (...args) => {
13716
- const { runBuildCommand } = await Promise.resolve().then(function () { return require('./build-PYCNacya.cjs'); });
13788
+ const { runBuildCommand } = await Promise.resolve().then(function () { return require('./build-CtqIXxDL.cjs'); });
13717
13789
  return runBuildCommand(...args);
13718
13790
  };
13719
13791
  const defaultRunCreateCommand = async (...args) => {
13720
- const { runCreateCommand } = await Promise.resolve().then(function () { return require('./create-BdAg3WGA.cjs'); });
13792
+ const { runCreateCommand } = await Promise.resolve().then(function () { return require('./create-BDOPSacf.cjs'); });
13721
13793
  return runCreateCommand(...args);
13722
13794
  };
13723
13795
  const defaultRunDevCommand = async (...args) => {
13724
- const { runDevCommand } = await Promise.resolve().then(function () { return require('./dev-CyZuw7Yn.cjs'); }).then(function (n) { return n.dev; });
13796
+ const { runDevCommand } = await Promise.resolve().then(function () { return require('./dev-VxjconYc.cjs'); }).then(function (n) { return n.dev; });
13725
13797
  return runDevCommand(...args);
13726
13798
  };
13727
13799
  const defaultRunDoctorCommand = async (...args) => {
13728
- const { runDoctorCommand } = await Promise.resolve().then(function () { return require('./doctor-DU8rCfUF.cjs'); });
13800
+ const { runDoctorCommand } = await Promise.resolve().then(function () { return require('./doctor-BkfYdlnZ.cjs'); });
13729
13801
  return runDoctorCommand(...args);
13730
13802
  };
13731
13803
  const defaultRunSkillInstallCommand = async (...args) => {
13732
- const { runSkillInstallCommand } = await Promise.resolve().then(function () { return require('./skill-cR_wnaw2.cjs'); });
13804
+ const { runSkillInstallCommand } = await Promise.resolve().then(function () { return require('./skill-DOveC5jt.cjs'); });
13733
13805
  return runSkillInstallCommand(...args);
13734
13806
  };
13735
13807
  const defaultRunRemoteCommand = async (...args) => {
13736
- const { runRemoteCommand } = await Promise.resolve().then(function () { return require('./remote-DNvI7tHH.cjs'); });
13808
+ const { runRemoteCommand } = await Promise.resolve().then(function () { return require('./remote-CfESZxO2.cjs'); });
13737
13809
  return runRemoteCommand(...args);
13738
13810
  };
13739
13811
  function resolveStandaloneLogger(options, verbose) {
@@ -1,13 +1,13 @@
1
1
  'use strict';
2
2
 
3
- var index$2 = require('./index-MMW2ibQm.cjs');
3
+ var index$2 = require('./index-DDrytLTX.cjs');
4
4
  var require$$0$3 = require('fs');
5
5
  var require$$0$2 = require('crypto');
6
6
  var require$$1$2 = require('path');
7
7
  var require$$0$5 = require('assert');
8
8
  var require$$0$4 = require('events');
9
9
  var require$$1$1 = require('util');
10
- var runtimePermissionEnv = require('./runtime-permission-env-CtL8rsjB.cjs');
10
+ var runtimePermissionEnv = require('./runtime-permission-env-BtTDFqEL.cjs');
11
11
  var require$$0$7 = require('net');
12
12
  var require$$0$6 = require('url');
13
13
  var require$$2$1 = require('http');
@@ -11,8 +11,8 @@ var require$$0$4 = require('url');
11
11
  var require$$0 = require('zlib');
12
12
  var require$$0$1 = require('buffer');
13
13
  var require$$1 = require('util');
14
- var index = require('./index-MMW2ibQm.cjs');
15
- var dev = require('./dev-CyZuw7Yn.cjs');
14
+ var index = require('./index-DDrytLTX.cjs');
15
+ var dev = require('./dev-VxjconYc.cjs');
16
16
  require('node:module');
17
17
  require('node:fs');
18
18
  require('node:fs/promises');
@@ -22,16 +22,16 @@ require('os');
22
22
  require('readline');
23
23
  require('tty');
24
24
  require('assert');
25
+ require('node:crypto');
25
26
  require('node:os');
26
27
  require('node:net');
27
- require('node:crypto');
28
28
  require('node:dns/promises');
29
29
  require('node:http');
30
- require('./context-m2W2XbL0.cjs');
31
- require('./runtime-permission-env-CtL8rsjB.cjs');
32
- require('./version-yEn1E2Bg.cjs');
30
+ require('./context-t57bMfbr.cjs');
31
+ require('./runtime-permission-env-BtTDFqEL.cjs');
32
+ require('./version-C4nE66sX.cjs');
33
33
  require('node:async_hooks');
34
- require('./session-DjBkjaF8.cjs');
34
+ require('./session-Dkhwjqhm.cjs');
35
35
  require('fs');
36
36
  require('constants');
37
37
  require('undici');
@@ -41,7 +41,8 @@ require('node:buffer');
41
41
  require('node:url');
42
42
  require('node:util');
43
43
  require('node:child_process');
44
- require('./project-vite-BQj8YLI4.cjs');
44
+ require('./project-vite-CFhz2THK.cjs');
45
+ require('node:zlib');
45
46
 
46
47
  var bufferUtil = {exports: {}};
47
48
 
@@ -3,9 +3,9 @@
3
3
  var promises = require('node:readline/promises');
4
4
  var node_crypto = require('node:crypto');
5
5
  var node_http = require('node:http');
6
- var session = require('./session-DjBkjaF8.cjs');
6
+ var session = require('./session-Dkhwjqhm.cjs');
7
7
  var browser = require('./browser-RAy8e8cV.cjs');
8
- var index = require('./index-MMW2ibQm.cjs');
8
+ var index = require('./index-DDrytLTX.cjs');
9
9
  require('node:path');
10
10
  require('fs');
11
11
  require('constants');
@@ -5,7 +5,7 @@ var fs$1 = require('node:fs/promises');
5
5
  var node_module = require('node:module');
6
6
  var path = require('node:path');
7
7
  var node_url = require('node:url');
8
- var index = require('./index-MMW2ibQm.cjs');
8
+ var index = require('./index-DDrytLTX.cjs');
9
9
 
10
10
  function findProjectRoot(startDir) {
11
11
  let current = path.resolve(startDir);
@@ -1,16 +1,17 @@
1
1
  'use strict';
2
2
 
3
3
  var promises = require('node:readline/promises');
4
- var index = require('./index-MMW2ibQm.cjs');
5
- var session = require('./session-DjBkjaF8.cjs');
4
+ var index = require('./index-DDrytLTX.cjs');
5
+ var session = require('./session-Dkhwjqhm.cjs');
6
6
  var childProcess = require('node:child_process');
7
7
  var fs = require('node:fs');
8
8
  var fs$1 = require('node:fs/promises');
9
9
  var path = require('node:path');
10
- var runtimePermissionEnv = require('./runtime-permission-env-CtL8rsjB.cjs');
11
- var runtimeGate = require('./runtime-gate-BEFp1w_s.cjs');
10
+ var runtimePermissionEnv = require('./runtime-permission-env-BtTDFqEL.cjs');
12
11
  var node_crypto = require('node:crypto');
13
- var context = require('./context-m2W2XbL0.cjs');
12
+ require('node:zlib');
13
+ var runtimeGate = require('./runtime-gate-BWb8QIcX.cjs');
14
+ var context = require('./context-t57bMfbr.cjs');
14
15
  require('node:module');
15
16
  require('path');
16
17
  require('os');
@@ -23,7 +24,7 @@ require('buffer');
23
24
  require('util');
24
25
  require('fs');
25
26
  require('constants');
26
- require('./version-yEn1E2Bg.cjs');
27
+ require('./version-C4nE66sX.cjs');
27
28
  require('node:async_hooks');
28
29
 
29
30
  async function getCDNUploadInfo(options, runtime = {}) {
@@ -86,15 +87,14 @@ async function createUserMiniprogramUploadSession(options, runtime = {}) {
86
87
  return postUserMiniprogramVersionForm(CREATE_USER_MINIPROGRAM_UPLOAD_SESSION_API_PATH, options, {
87
88
  version: options.version,
88
89
  artifact_signature: options.artifactSignature,
89
- relative_paths: options.relativePaths.join(','),
90
- file_sizes: options.fileSizes.map(size => String(size)).join(','),
90
+ files: JSON.stringify(options.files),
91
91
  }, runtime);
92
92
  }
93
93
  async function recordUserMiniprogramUploadResult(options, runtime = {}) {
94
94
  await postUserMiniprogramVersionForm(RECORD_USER_MINIPROGRAM_UPLOAD_RESULT_API_PATH, options, {
95
95
  version: options.version,
96
96
  session_id: options.sessionId,
97
- keys: options.keys.join(','),
97
+ files: JSON.stringify(options.files),
98
98
  }, runtime);
99
99
  }
100
100
  async function postUserMiniprogramVersionForm(path, options, fields, runtime) {
@@ -209,7 +209,9 @@ async function runUpload(options, runtime = {}) {
209
209
  miniProgramId: options.miniProgramId,
210
210
  version: options.version,
211
211
  sessionId: options.uploadSessionId,
212
- keys: successfulKeys,
212
+ files: indexedFiles
213
+ .filter((item) => successfulKeys.includes(item.key))
214
+ .map((item) => ({ path: item.file.relativePath, size: item.file.size, sha256: item.file.sha256 })),
213
215
  }, { baseUrl: runtime.baseUrl, fetchImpl });
214
216
  }
215
217
  if (firstUploadError) {
@@ -272,7 +274,7 @@ function createDefaultCosClient(uploadToken, COS) {
272
274
  };
273
275
  }
274
276
  async function loadCosConstructor() {
275
- const cosModule = await Promise.resolve().then(function () { return require('./index-DATObqzK.cjs'); }).then(function (n) { return n.index; });
277
+ const cosModule = await Promise.resolve().then(function () { return require('./index-lLaHzwfT.cjs'); }).then(function (n) { return n.index; });
276
278
  return cosModule.default;
277
279
  }
278
280
  function formatSize(bytes) {
@@ -315,24 +317,28 @@ function isRecord(value) {
315
317
  return Object.prototype.toString.call(value) === '[object Object]';
316
318
  }
317
319
 
318
- async function computeMiniappArtifactSignature(files, runtime = {}) {
320
+ /** 单次流式读取同时生成整包签名和逐文件 SHA-256 receipt。 */
321
+ async function computeMiniappArtifactReceipt(files, runtime = {}) {
319
322
  const preparedFiles = runtimePermissionEnv.prepareMiniappArtifactFiles(files);
320
323
  const hash = node_crypto.createHash('sha256');
321
324
  const createReadStream = runtime.createReadStream ?? fs.createReadStream;
322
325
  hash.update(runtimePermissionEnv.createMiniappArtifactSignatureHeader(preparedFiles.length));
323
326
  for (const file of preparedFiles) {
324
327
  hash.update(runtimePermissionEnv.createMiniappArtifactFileHeader(file));
328
+ const fileHash = node_crypto.createHash('sha256');
325
329
  let bytesRead = 0;
326
330
  for await (const chunk of createReadStream(file.absolutePath)) {
327
331
  const bytes = typeof chunk === 'string' ? Buffer.from(chunk) : chunk;
328
332
  bytesRead += bytes.byteLength;
329
333
  hash.update(bytes);
334
+ fileHash.update(bytes);
330
335
  }
331
336
  if (bytesRead !== file.size) {
332
337
  throw new Error(`构建产物在签名期间发生变化:${file.relativePath}`);
333
338
  }
339
+ Object.assign(file, { sha256: fileHash.digest('hex') });
334
340
  }
335
- return hash.digest('hex');
341
+ return { artifactSignature: hash.digest('hex'), files: preparedFiles };
336
342
  }
337
343
 
338
344
  const DEPLOY_LOCKED_MESSAGE = '当前设备已有同版本产物正在上传,请等待完成后重试';
@@ -509,6 +515,7 @@ async function runDeployCommand(options, runtime = {}) {
509
515
  throw new Error('未在 package.json 中找到 heybox.miniProgramId,请先配置 mini program id');
510
516
  }
511
517
  const fromVersion = options.fromVersion?.trim();
518
+ const declaredPlatforms = fromVersion ? undefined : runtimePermissionEnv.readMiniappPlatformsFromPackageJson(projectRoot);
512
519
  const releaseNote = await resolveDeployReleaseNote(options, runtime);
513
520
  const session$1 = await logger.task('正在校验 Heybox 登录态', () => (runtime.requireAuthSession ?? session.requireHeyboxAuthSession)({ loginBaseUrl }), { successText: 'Heybox 登录态有效' });
514
521
  logger.debug(`Heybox API: ${apiBaseUrl}`);
@@ -583,6 +590,9 @@ async function runDeployCommand(options, runtime = {}) {
583
590
  const distDir = path.join(projectRoot, 'dist');
584
591
  const parsedManifest = await readDeployManifest(projectRoot, logger);
585
592
  ({ manifest, version } = parsedManifest);
593
+ if (!declaredPlatforms || !runtimePermissionEnv.areMiniappPlatformsEqual(parsedManifest.platforms, declaredPlatforms)) {
594
+ throw new Error('dist/manifest.json.platforms 与 package.json#heybox.platforms 不一致,请重新 build 后再 deploy');
595
+ }
586
596
  if (version !== precheckVersion) {
587
597
  throw new Error(`dist/manifest.json.version (${version}) 与预检版本 (${precheckVersion}) 不一致,请重新 build 后再 deploy`);
588
598
  }
@@ -597,7 +607,7 @@ async function runDeployCommand(options, runtime = {}) {
597
607
  if (pathError) {
598
608
  throw new Error(pathError);
599
609
  }
600
- const sizeError = runtimePermissionEnv.validateUploadTotalSize(files);
610
+ const sizeError = runtimePermissionEnv.validateMiniappUploadSizeBudgets(files);
601
611
  if (sizeError) {
602
612
  throw new Error(sizeError);
603
613
  }
@@ -605,20 +615,23 @@ async function runDeployCommand(options, runtime = {}) {
605
615
  return files;
606
616
  }, { successText: 'dist 上传文件校验完成' });
607
617
  // deploy 期间 dist 视为稳定构建输出;为避免持有大量文件描述符,签名和上传不会共享打开的文件句柄。
608
- const artifactSignature = await logger.task('正在计算构建产物签名', () => (runtime.computeMiniappArtifactSignature ?? computeMiniappArtifactSignature)(uploadFiles), { successText: '构建产物签名计算完成' });
618
+ const artifactReceipt = await logger.task('正在计算构建产物签名', () => (runtime.computeMiniappArtifactReceipt ?? computeMiniappArtifactReceipt)(uploadFiles), { successText: '构建产物签名计算完成' });
619
+ runtimePermissionEnv.validateMiniappCompanionFileReceipts(manifest?.companions, artifactReceipt.files);
609
620
  const createdUploadSession = await logger.task('正在创建或恢复上传会话', async () => {
610
621
  const result = await (runtime.createUserMiniprogramUploadSession ?? createUserMiniprogramUploadSession)({
611
622
  session: session$1,
612
623
  miniProgramId,
613
624
  version,
614
- artifactSignature,
615
- relativePaths: uploadFiles.map((file) => file.relativePath),
616
- fileSizes: uploadFiles.map((file) => file.size),
625
+ artifactSignature: artifactReceipt.artifactSignature,
626
+ files: artifactReceipt.files.map((file) => ({ path: file.relativePath, size: file.size, sha256: file.sha256 })),
617
627
  }, { baseUrl: apiBaseUrl, fetchImpl: runtime.fetchImpl });
618
628
  if (typeof result.session_id !== 'string' || !result.session_id.trim()) {
619
629
  throw new Error('创建上传会话失败:服务端未返回 session_id');
620
630
  }
621
- const resolved = runtimePermissionEnv.resolveMiniappUploadSessionFiles(uploadFiles, Array.isArray(result.files) ? result.files : [], Array.isArray(result.uploaded_keys) ? result.uploaded_keys : []);
631
+ if (result.file_receipt_version !== 1) {
632
+ throw new Error('创建上传会话失败:服务端不支持文件完整性 receipt v1,请升级服务端后重试');
633
+ }
634
+ const resolved = runtimePermissionEnv.resolveMiniappUploadSessionFiles(artifactReceipt.files, Array.isArray(result.files) ? result.files : [], Array.isArray(result.uploaded_keys) ? result.uploaded_keys : []);
622
635
  return {
623
636
  sessionId: result.session_id.trim(),
624
637
  files: resolved.files,
@@ -633,10 +646,10 @@ async function runDeployCommand(options, runtime = {}) {
633
646
  try {
634
647
  if (createdUploadSession.missingFiles.length > 0) {
635
648
  await assertDeployUploadFilesStillMatchSignature({
636
- computeMiniappArtifactSignature: runtime.computeMiniappArtifactSignature ?? computeMiniappArtifactSignature,
649
+ computeMiniappArtifactReceipt: runtime.computeMiniappArtifactReceipt ?? computeMiniappArtifactReceipt,
637
650
  distDir,
638
- expectedFiles: uploadFiles,
639
- expectedSignature: artifactSignature,
651
+ expectedFiles: artifactReceipt.files,
652
+ expectedSignature: artifactReceipt.artifactSignature,
640
653
  miniProgramId,
641
654
  });
642
655
  await (runtime.runUpload ?? runUpload)({
@@ -734,11 +747,11 @@ async function readDeployManifest(projectRoot, logger) {
734
747
  if (!runtimeGate.hasMiniappRuntimeGate(entryHtml)) {
735
748
  throw new Error('dist/index.html 缺少平台 Runtime 启动门禁,请在 Vite 配置中启用 miniappManifest() 后重新 build');
736
749
  }
737
- const { manifest, hadBom } = runtimeGate.parseMiniappManifestJson(await fs$1.readFile(manifestPath, 'utf8'), 'dist/manifest.json');
750
+ const { manifest, hadBom } = runtimePermissionEnv.parseMiniappManifestJson(await fs$1.readFile(manifestPath, 'utf8'), 'dist/manifest.json');
738
751
  if (hadBom) {
739
752
  logger.warn('dist/manifest.json 包含 BOM,已自动剥离');
740
753
  }
741
- const validated = runtimeGate.validateMiniappManifestForDeploy(manifest);
754
+ const validated = runtimePermissionEnv.validateMiniappManifestForDeploy(manifest);
742
755
  return {
743
756
  manifest: { ...manifest, platforms: validated.platforms },
744
757
  sdkVersion: validated.sdkVersion,
@@ -747,7 +760,7 @@ async function readDeployManifest(projectRoot, logger) {
747
760
  };
748
761
  }
749
762
  function validateVersionForDeploy(version, sourceLabel) {
750
- if (typeof version !== 'string' || !runtimeGate.isValidMiniappManifestVersion(version)) {
763
+ if (typeof version !== 'string' || !runtimePermissionEnv.isValidMiniappManifestVersion(version)) {
751
764
  throw new Error(`${sourceLabel} 必须是合法 SemVer,允许 prerelease,不允许 build metadata 和 0.0.0:${String(version)}`);
752
765
  }
753
766
  return version.trim();
@@ -908,12 +921,12 @@ async function assertDeployUploadFilesStillMatchSignature(options) {
908
921
  if (pathError) {
909
922
  throw new Error(pathError);
910
923
  }
911
- const sizeError = runtimePermissionEnv.validateUploadTotalSize(currentFiles);
924
+ const sizeError = runtimePermissionEnv.validateMiniappUploadSizeBudgets(currentFiles);
912
925
  if (sizeError) {
913
926
  throw new Error(sizeError);
914
927
  }
915
- const currentSignature = await options.computeMiniappArtifactSignature(currentFiles);
916
- if (currentSignature !== options.expectedSignature) {
928
+ const currentReceipt = await options.computeMiniappArtifactReceipt(currentFiles);
929
+ if (currentReceipt.artifactSignature !== options.expectedSignature) {
917
930
  throw new Error('dist 构建产物在签名后发生变化,请重新 build 后再 deploy');
918
931
  }
919
932
  }
@@ -1,109 +1,5 @@
1
1
  'use strict';
2
2
 
3
- var runtimePermissionEnv = require('./runtime-permission-env-CtL8rsjB.cjs');
4
-
5
- const MINIAPP_PLATFORM_VALUES = ['android', 'ios', 'ohos', 'windows', 'macos', 'linux'];
6
- function isValidMiniappManifestVersion(version) {
7
- return getMiniappManifestVersionError(version) === undefined;
8
- }
9
- function validateMiniappManifestVersion(version, sourceLabel = 'manifest.version') {
10
- const error = getMiniappManifestVersionError(version);
11
- if (error) {
12
- throw new Error(`${sourceLabel} ${error}`);
13
- }
14
- return String(version).trim();
15
- }
16
- function parseMiniappManifestJson(raw, sourceLabel = 'manifest.json') {
17
- const hadBom = raw.charCodeAt(0) === 0xfeff;
18
- const text = hadBom ? raw.slice(1) : raw;
19
- let parsed;
20
- try {
21
- parsed = JSON.parse(text);
22
- }
23
- catch (error) {
24
- throw new Error(`${sourceLabel} 不是合法 JSON:${formatReason(error)}`);
25
- }
26
- if (!isManifestRecord(parsed)) {
27
- throw new Error(`${sourceLabel} 必须是 JSON 对象`);
28
- }
29
- return {
30
- manifest: parsed,
31
- hadBom,
32
- };
33
- }
34
- function validateMiniappManifestForDeploy(manifest) {
35
- const version = validateMiniappManifestVersion(manifest.version, 'manifest.version');
36
- const sdkVersion = validateSdkVersion(manifest.sdkVersion, 'manifest.sdkVersion');
37
- const permissions = runtimePermissionEnv.parseMiniappPermissions(manifest.permissions, {
38
- present: Object.prototype.hasOwnProperty.call(manifest, 'permissions'),
39
- sdkVersion,
40
- sourceLabel: 'manifest.permissions',
41
- });
42
- return {
43
- version,
44
- sdkVersion,
45
- platforms: validateMiniappPlatforms(manifest.platforms, 'manifest.platforms'),
46
- ...(permissions.permissions === undefined ? {} : { permissions: permissions.permissions }),
47
- };
48
- }
49
- function validateMiniappPlatforms(platforms, sourceLabel = 'platforms') {
50
- if (!Array.isArray(platforms) || platforms.length === 0) {
51
- throw new Error(`${sourceLabel} 必须是非空平台数组`);
52
- }
53
- const allowedPlatforms = new Set(MINIAPP_PLATFORM_VALUES);
54
- const seen = new Set();
55
- for (const platform of platforms) {
56
- if (typeof platform !== 'string' || !allowedPlatforms.has(platform)) {
57
- throw new Error(`${sourceLabel} 包含不支持的平台:${String(platform)}`);
58
- }
59
- if (seen.has(platform)) {
60
- throw new Error(`${sourceLabel} 包含重复平台:${platform}`);
61
- }
62
- seen.add(platform);
63
- }
64
- return Object.freeze(MINIAPP_PLATFORM_VALUES.filter((platform) => seen.has(platform)));
65
- }
66
- function validateSdkVersion(version, sourceLabel = 'sdkVersion') {
67
- if (typeof version !== 'string' || version.trim() === '') {
68
- throw new Error(`${sourceLabel} 必须是合法 SemVer:${String(version)}`);
69
- }
70
- const normalized = version.trim();
71
- const parsed = runtimePermissionEnv.semverExports.parse(normalized);
72
- if (!parsed || parsed.version !== normalized || parsed.build.length > 0) {
73
- throw new Error(`${sourceLabel} 必须是合法 SemVer:${normalized}`);
74
- }
75
- return normalized;
76
- }
77
- function isManifestRecord(value) {
78
- return typeof value === 'object' && value !== null && !Array.isArray(value);
79
- }
80
- function getMiniappManifestVersionError(version) {
81
- if (typeof version !== 'string' || version.trim() === '') {
82
- return `必须是合法 SemVer:${String(version)}`;
83
- }
84
- const normalized = version.trim();
85
- const parsed = runtimePermissionEnv.semverExports.parse(normalized);
86
- if (!parsed) {
87
- return `必须是合法 SemVer:${normalized}`;
88
- }
89
- if (parsed.build.length > 0) {
90
- return `不能包含 build metadata:${normalized}`;
91
- }
92
- if (parsed.version !== normalized) {
93
- return `必须是合法 SemVer:${normalized}`;
94
- }
95
- if (parsed.major === 0 && parsed.minor === 0 && parsed.patch === 0) {
96
- return '不能是模板默认版本 0.0.0';
97
- }
98
- return undefined;
99
- }
100
- function formatReason(error) {
101
- if (error instanceof Error && error.message) {
102
- return error.message;
103
- }
104
- return String(error);
105
- }
106
-
107
3
  const UNDEFINED_CODE_POINTS = new Set([
108
4
  65534, 65535, 131070, 131071, 196606, 196607, 262142, 262143, 327678, 327679, 393214,
109
5
  393215, 458750, 458751, 524286, 524287, 589822, 589823, 655358, 655359, 720894,
@@ -8390,6 +8286,3 @@ function walk(node, visit) {
8390
8286
  }
8391
8287
 
8392
8288
  exports.hasMiniappRuntimeGate = hasMiniappRuntimeGate;
8393
- exports.isValidMiniappManifestVersion = isValidMiniappManifestVersion;
8394
- exports.parseMiniappManifestJson = parseMiniappManifestJson;
8395
- exports.validateMiniappManifestForDeploy = validateMiniappManifestForDeploy;