@heybox/hb-sdk 0.7.2-alpha.0 → 0.7.3-alpha.0

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 (39) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +10 -10
  3. package/dist/cli-chunks/{build-DbQt0LIs.cjs → build-CIZIWLmV.cjs} +2 -2
  4. package/dist/cli-chunks/{context-Cmrhge3Y.cjs → context-DdKKaf1o.cjs} +1 -1
  5. package/dist/cli-chunks/{create-5ZLxb2p_.cjs → create-C5CW72BF.cjs} +1 -1
  6. package/dist/cli-chunks/{dev-CWSJ0YIw.cjs → dev-CH2yODBH.cjs} +5 -5
  7. package/dist/cli-chunks/{doctor-CpFYiqK9.cjs → doctor-SHwm6xSx.cjs} +1 -1
  8. package/dist/cli-chunks/{index-DomfJMuO.cjs → index-DIwi_FPa.cjs} +1 -1
  9. package/dist/cli-chunks/{index-BV8DdyEP.cjs → index-DiGjTruv.cjs} +14 -14
  10. package/dist/cli-chunks/{login-DhD2o29N.cjs → login-BrtCvOEN.cjs} +2 -2
  11. package/dist/cli-chunks/{project-vite-8IkVMyPu.cjs → project-vite-BoMy-fAP.cjs} +1 -1
  12. package/dist/cli-chunks/{remote-BZ6rfyuZ.cjs → remote-BDj3TcU7.cjs} +4 -4
  13. package/dist/cli-chunks/{session-DnqyIY87.cjs → session-DyEpQQ67.cjs} +1 -1
  14. package/dist/cli.cjs +1 -1
  15. package/dist/devtools/mock-host/main.js +78 -60
  16. package/dist/index.cjs.js +3 -11
  17. package/dist/index.esm.js +3 -11
  18. package/dist/protocol.cjs.js +0 -10
  19. package/dist/protocol.esm.js +1 -10
  20. package/dist/vite.cjs.js +1 -1
  21. package/dist/vite.esm.js +1 -1
  22. package/package.json +2 -2
  23. package/skill/SKILL.md +4 -4
  24. package/skill/references/api-protocol.md +2 -5
  25. package/skill/references/api-root.md +9 -18
  26. package/skill/references/cli.md +2 -2
  27. package/skill/references/examples.md +5 -11
  28. package/skill/references/recipes.md +16 -33
  29. package/skill/references/safety-boundaries.md +2 -2
  30. package/skill/scripts/sync-references.mjs +6 -12
  31. package/skill/scripts/validate-skill.mjs +7 -1
  32. package/skill/skill.json +4 -4
  33. package/types/index.d.ts +1 -1
  34. package/types/modules/user/get-info.d.ts +2 -2
  35. package/types/modules/user/index.d.ts +1 -5
  36. package/types/modules/user/types.d.ts +5 -3
  37. package/types/protocol/capabilities.d.ts +2 -12
  38. package/types/protocol.d.ts +2 -2
  39. package/types/modules/user/get-local-identity.d.ts +0 -9
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.7.2
4
+
5
+ ### SDK / Runtime
6
+
7
+ - 移除 `user.getLocalIdentity()`;未开通网络权限的小程序改用 `user.getInfo()` 静默获取 `userInfo.app_user_id`,不再展示身份授权弹窗。
8
+ - 未开通网络权限且用户已登录时,`user.getInfo()` 会静默建立或读取当前小程序隔离身份,并在每次成功调用后广播 `identity: granted`;撤销授权后再次调用会建立新的隔离身份。
9
+ - Runtime 不再兼容缺少 canonical `miniProgramId` 的无参 `getUserInfo()` adapter 路径;身份缺失时 `user.getInfo()` 返回 `INVALID_STATE`。
10
+
3
11
  ## 0.7.1
4
12
 
5
13
  ### Docs / Agent Skill
package/README.md CHANGED
@@ -23,20 +23,20 @@ npm run dev
23
23
  npm install @heybox/hb-sdk
24
24
  ```
25
25
 
26
- SDK 会在导入时启动握手,能力调用会自动等待 SDK 就绪。未开通网络权限的小程序可以读取当前小程序内的隔离身份:
26
+ SDK 会在导入时启动握手,能力调用会自动等待 SDK 就绪。未开通网络权限的小程序通过 `user.getInfo()` 静默读取当前小程序内的隔离身份:
27
27
 
28
28
  需要可信用户手势的按钮不能在点击回调里等待握手。页面加载时先用 `getHandshakeState()` 读取当前状态,再用 `onHandshakeStateChange()` 订阅并立即接收当前状态;仅在 `status === 'ready'` 时启用按钮,并在组件或页面销毁时调用订阅返回的取消函数。`ready` 生命周期事件只是握手成功瞬间派发、不会重放的边沿通知,不能用来判断当前状态。
29
29
 
30
30
  ```ts
31
31
  import hbSDK from '@heybox/hb-sdk';
32
32
 
33
- async function getLocalIdentityFromUserAction() {
34
- const { appUserId } = await hbSDK.user.getLocalIdentity();
35
- return appUserId;
33
+ async function getCurrentUser() {
34
+ const result = await hbSDK.user.getInfo();
35
+ return result.userInfo?.app_user_id;
36
36
  }
37
37
  ```
38
38
 
39
- `getLocalIdentityFromUserAction` 绑定到按钮点击等可信用户操作。首次登录或 identity consent 需要 UI 而缺少可信手势时返回 `USER_GESTURE_REQUIRED`;用户取消或关闭时返回 `AUTHORIZATION_CANCELLED`,不会确认或改变授权状态。
39
+ `user.getInfo()` 不展示授权弹窗,也不要求可信用户手势。未登录时返回 `isHeyboxAppLoggedIn: false`;已登录时默认返回当前小程序隔离的 `app_user_id`。
40
40
 
41
41
  已开通网络权限的小程序在按钮点击等明确的用户操作中调用 `auth.login()`:
42
42
 
@@ -52,7 +52,7 @@ async function loginFromUserAction() {
52
52
  }
53
53
  ```
54
54
 
55
- `auth.login()` 返回 `{ code, expiresIn: 300, scopes }`,其中 `identity` 隐式强制包含;它不返回 user、profile、`appUserId` 或 token。页面只能把 code 交给开发者服务端,再由服务端按后端 OpenAPI 文档换取 token。未开通网络权限的小程序使用 `user.getLocalIdentity()`,无法获取 code 或调用 OpenAPI。完整边界见[用户身份与登录](https://docs.xiaoheihe.cn/hb_sdk/guide/auth)。
55
+ `auth.login()` 返回 `{ code, expiresIn: 300, scopes }`,其中 `identity` 隐式强制包含;它不返回 user、profile、`app_user_id` 或 token。页面只能把 code 交给开发者服务端,再由服务端按后端 OpenAPI 文档换取 token。未开通网络权限的小程序使用 `user.getInfo()`,无法获取 code 或调用 OpenAPI。完整边界见[用户身份与登录](https://docs.xiaoheihe.cn/hb_sdk/guide/auth)。
56
56
 
57
57
  用户可以在明确的按钮点击和二次确认后撤销当前小程序的授权:
58
58
 
@@ -62,7 +62,7 @@ async function revokeAuthorizationFromUserAction() {
62
62
  if (!confirmed) return;
63
63
 
64
64
  await hbSDK.user.revokeAuthorization();
65
- // 同步清理业务保存的 appUserId、用户资料和服务端会话。
65
+ // 同步清理业务保存的 app_user_id、用户资料和服务端会话。
66
66
  }
67
67
  ```
68
68
 
@@ -107,7 +107,7 @@ SDK 还提供 `getHandshakeState()` / `onHandshakeStateChange()` 管理持久握
107
107
  | 模块 | 用途 |
108
108
  | ------------ | ------------------------------------------------------------ |
109
109
  | `auth` | 获取交给开发者服务端交换的短期授权码 |
110
- | `user` | 使用 Host current-user APIs 或读取无网络小程序的本地隔离身份 |
110
+ | `user` | 读取 Host 当前用户资料、隔离身份或撤销授权 |
111
111
  | `share` | 打开分享或截图分享流程 |
112
112
  | `ui` | 展示 Toast 和 Loading |
113
113
  | `device` | 调用振动和剪贴板能力 |
@@ -127,8 +127,8 @@ SDK 还提供 `getHandshakeState()` / `onHandshakeStateChange()` 管理持久握
127
127
  - `auth.login({ scopes? })` 只返回 `{ code, expiresIn: 300, scopes }`;identity 隐式强制包含,code 只能提交给开发者服务端。
128
128
  - 需要授权 UI 时,`auth.login()` 必须来自可信用户手势,否则返回 `USER_GESTURE_REQUIRED`;用户取消或关闭时返回 `AUTHORIZATION_CANCELLED`。已授权时可以静默返回新 code。
129
129
  - `user.getSteamGameList()` 仅供未开通网络权限的小程序通过 Host 读取;已开通网络权限时返回 `SERVER_API_REQUIRED`,且授权码与 OpenAPI 不提供 Steam 游戏库 scope 或资源接口。
130
- - 已开通网络权限时,公开的 `user.getInfo()` 和 `user.getLocalIdentity()` 返回 `SERVER_API_REQUIRED`;对应身份和资料数据应由开发者服务端通过 OpenAPI 获取。
131
- - 未开通网络权限时,只用 `user.getLocalIdentity()` 获取 `{ appUserId }`,不能获取 code 或调用 OpenAPI。
130
+ - 已开通网络权限时,公开的 `user.getInfo()` 返回 `SERVER_API_REQUIRED`;对应身份和资料数据应由开发者服务端通过 OpenAPI 获取。
131
+ - 未开通网络权限时,使用 `user.getInfo()` 静默读取 `userInfo.app_user_id`,不能获取 code 或调用 OpenAPI。
132
132
  - `user.revokeAuthorization()` 在两种网络模式下都要求可信用户手势;成功后必须停止使用并清理业务缓存的旧身份、资料和服务端会话。
133
133
  - `on()` 返回取消监听函数,组件卸载或页面销毁时需要调用。
134
134
  - 业务网络请求使用 `network.request()`,不要依赖浏览器原生网络出口。
@@ -5,8 +5,8 @@ var fs = require('node:fs/promises');
5
5
  var path = require('node:path');
6
6
  var runtimePermissionEnv = require('./runtime-permission-env-D-8_jPG3.cjs');
7
7
  var runtimeGate = require('./runtime-gate-CtV7rWyX.cjs');
8
- var index = require('./index-BV8DdyEP.cjs');
9
- var projectVite = require('./project-vite-8IkVMyPu.cjs');
8
+ var index = require('./index-DiGjTruv.cjs');
9
+ var projectVite = require('./project-vite-BoMy-fAP.cjs');
10
10
  require('node:async_hooks');
11
11
  require('node:module');
12
12
  require('path');
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var session = require('./session-DnqyIY87.cjs');
3
+ var session = require('./session-DyEpQQ67.cjs');
4
4
  var runtimePermissionEnv = require('./runtime-permission-env-D-8_jPG3.cjs');
5
5
  var fs$1 = require('node:fs');
6
6
  var fs = require('node:fs/promises');
@@ -5,7 +5,7 @@ var fs = require('node:fs/promises');
5
5
  var path = require('node:path');
6
6
  var require$$0 = require('fs');
7
7
  var require$$1 = require('path');
8
- var index = require('./index-BV8DdyEP.cjs');
8
+ var index = require('./index-DiGjTruv.cjs');
9
9
  require('node:module');
10
10
  require('os');
11
11
  require('readline');
@@ -6,15 +6,15 @@ var path = require('node:path');
6
6
  var net = require('node:net');
7
7
  var promises = require('node:dns/promises');
8
8
  var node_http = require('node:http');
9
- var context = require('./context-Cmrhge3Y.cjs');
9
+ var context = require('./context-DdKKaf1o.cjs');
10
10
  var node_crypto = require('node:crypto');
11
11
  var undici = require('undici');
12
12
  var browser = require('./browser-RAy8e8cV.cjs');
13
- var index = require('./index-BV8DdyEP.cjs');
14
- var projectVite = require('./project-vite-8IkVMyPu.cjs');
13
+ var index = require('./index-DiGjTruv.cjs');
14
+ var projectVite = require('./project-vite-BoMy-fAP.cjs');
15
15
  var fs$1 = require('node:fs/promises');
16
16
  var runtimePermissionEnv = require('./runtime-permission-env-D-8_jPG3.cjs');
17
- require('./session-DnqyIY87.cjs');
17
+ require('./session-DyEpQQ67.cjs');
18
18
  require('fs');
19
19
  require('constants');
20
20
  require('stream');
@@ -1347,7 +1347,7 @@ function createHeyboxProtocol(payload) {
1347
1347
  /** 构建时替换为当前发布包的实际版本。 */
1348
1348
  const HB_SDK_VERSION = typeof undefined === 'string'
1349
1349
  ? undefined
1350
- : '0.7.2-alpha.0';
1350
+ : '0.7.3-alpha.0';
1351
1351
 
1352
1352
  class DevPermissionOverrideStoreError extends Error {
1353
1353
  code;
@@ -4,7 +4,7 @@ var fs$1 = require('node:fs');
4
4
  var fs = require('node:fs/promises');
5
5
  var os = require('node:os');
6
6
  var path = require('node:path');
7
- var index = require('./index-BV8DdyEP.cjs');
7
+ var index = require('./index-DiGjTruv.cjs');
8
8
  require('node:module');
9
9
  require('path');
10
10
  require('os');
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var index$2 = require('./index-BV8DdyEP.cjs');
3
+ var index$2 = require('./index-DiGjTruv.cjs');
4
4
  var require$$0$2 = require('fs');
5
5
  var require$$2$1 = require('crypto');
6
6
  var require$$1$2 = 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-BV8DdyEP.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-DiGjTruv.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-BV8DdyEP.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-DiGjTruv.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-BV8DdyEP.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-DiGjTruv.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-BV8DdyEP.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-DiGjTruv.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-BV8DdyEP.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-DiGjTruv.cjs', document.baseURI).href)));
250
250
  function __require() { return require$1("node:process"); }
251
251
 
252
252
  var help = {};
@@ -13347,7 +13347,7 @@ function getPathname(pathWithQuery) {
13347
13347
  }
13348
13348
 
13349
13349
  const CLI_VERSION_PLACEHOLDER = ['__HB', 'SDK', 'CLI', 'VERSION__'].join('_');
13350
- const BUILT_CLI_VERSION = '0.7.2-alpha.0';
13350
+ const BUILT_CLI_VERSION = '0.7.3-alpha.0';
13351
13351
  const PACKAGE_JSON_CANDIDATES = [
13352
13352
  path.resolve(__dirname, '..', '..', 'package.json'),
13353
13353
  path.resolve(__dirname, '..', 'package.json'),
@@ -13681,35 +13681,35 @@ function createCommandLoggerResolver(options) {
13681
13681
  };
13682
13682
  }
13683
13683
  const defaultClearLoginStatus = async (...args) => {
13684
- const { clearLoginStatus } = await Promise.resolve().then(function () { return require('./login-DhD2o29N.cjs'); });
13684
+ const { clearLoginStatus } = await Promise.resolve().then(function () { return require('./login-BrtCvOEN.cjs'); });
13685
13685
  return clearLoginStatus(...args);
13686
13686
  };
13687
13687
  const defaultLoginToHeybox = async (...args) => {
13688
- const { loginToHeybox } = await Promise.resolve().then(function () { return require('./login-DhD2o29N.cjs'); });
13688
+ const { loginToHeybox } = await Promise.resolve().then(function () { return require('./login-BrtCvOEN.cjs'); });
13689
13689
  return loginToHeybox(...args);
13690
13690
  };
13691
13691
  const defaultPrintLoginStatus = async (...args) => {
13692
- const { printLoginStatus } = await Promise.resolve().then(function () { return require('./login-DhD2o29N.cjs'); });
13692
+ const { printLoginStatus } = await Promise.resolve().then(function () { return require('./login-BrtCvOEN.cjs'); });
13693
13693
  return printLoginStatus(...args);
13694
13694
  };
13695
13695
  const defaultRunBuildCommand = async (...args) => {
13696
- const { runBuildCommand } = await Promise.resolve().then(function () { return require('./build-DbQt0LIs.cjs'); });
13696
+ const { runBuildCommand } = await Promise.resolve().then(function () { return require('./build-CIZIWLmV.cjs'); });
13697
13697
  return runBuildCommand(...args);
13698
13698
  };
13699
13699
  const defaultRunCreateCommand = async (...args) => {
13700
- const { runCreateCommand } = await Promise.resolve().then(function () { return require('./create-5ZLxb2p_.cjs'); });
13700
+ const { runCreateCommand } = await Promise.resolve().then(function () { return require('./create-C5CW72BF.cjs'); });
13701
13701
  return runCreateCommand(...args);
13702
13702
  };
13703
13703
  const defaultRunDevCommand = async (...args) => {
13704
- const { runDevCommand } = await Promise.resolve().then(function () { return require('./dev-CWSJ0YIw.cjs'); });
13704
+ const { runDevCommand } = await Promise.resolve().then(function () { return require('./dev-CH2yODBH.cjs'); });
13705
13705
  return runDevCommand(...args);
13706
13706
  };
13707
13707
  const defaultRunDoctorCommand = async (...args) => {
13708
- const { runDoctorCommand } = await Promise.resolve().then(function () { return require('./doctor-CpFYiqK9.cjs'); });
13708
+ const { runDoctorCommand } = await Promise.resolve().then(function () { return require('./doctor-SHwm6xSx.cjs'); });
13709
13709
  return runDoctorCommand(...args);
13710
13710
  };
13711
13711
  const defaultRunRemoteCommand = async (...args) => {
13712
- const { runRemoteCommand } = await Promise.resolve().then(function () { return require('./remote-BZ6rfyuZ.cjs'); });
13712
+ const { runRemoteCommand } = await Promise.resolve().then(function () { return require('./remote-BDj3TcU7.cjs'); });
13713
13713
  return runRemoteCommand(...args);
13714
13714
  };
13715
13715
  function resolveStandaloneLogger(options, verbose) {
@@ -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-DnqyIY87.cjs');
6
+ var session = require('./session-DyEpQQ67.cjs');
7
7
  var browser = require('./browser-RAy8e8cV.cjs');
8
- var index = require('./index-BV8DdyEP.cjs');
8
+ var index = require('./index-DiGjTruv.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-BV8DdyEP.cjs');
8
+ var index = require('./index-DiGjTruv.cjs');
9
9
 
10
10
  function findProjectRoot(startDir) {
11
11
  let current = path.resolve(startDir);
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  var promises = require('node:readline/promises');
4
- var index = require('./index-BV8DdyEP.cjs');
5
- var session = require('./session-DnqyIY87.cjs');
4
+ var index = require('./index-DiGjTruv.cjs');
5
+ var session = require('./session-DyEpQQ67.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');
@@ -10,7 +10,7 @@ var path = require('node:path');
10
10
  var runtimePermissionEnv = require('./runtime-permission-env-D-8_jPG3.cjs');
11
11
  var runtimeGate = require('./runtime-gate-CtV7rWyX.cjs');
12
12
  var node_crypto = require('node:crypto');
13
- var context = require('./context-Cmrhge3Y.cjs');
13
+ var context = require('./context-DdKKaf1o.cjs');
14
14
  require('node:module');
15
15
  require('path');
16
16
  require('os');
@@ -271,7 +271,7 @@ function createDefaultCosClient(uploadToken, COS) {
271
271
  };
272
272
  }
273
273
  async function loadCosConstructor() {
274
- const cosModule = await Promise.resolve().then(function () { return require('./index-DomfJMuO.cjs'); }).then(function (n) { return n.index; });
274
+ const cosModule = await Promise.resolve().then(function () { return require('./index-DIwi_FPa.cjs'); }).then(function (n) { return n.index; });
275
275
  return cosModule.default;
276
276
  }
277
277
  function formatSize(bytes) {
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var index = require('./index-BV8DdyEP.cjs');
3
+ var index = require('./index-DiGjTruv.cjs');
4
4
  var node_crypto = require('node:crypto');
5
5
  var path = require('node:path');
6
6
  var require$$0$2 = require('fs');
package/dist/cli.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var index = require('./cli-chunks/index-BV8DdyEP.cjs');
3
+ var index = require('./cli-chunks/index-DiGjTruv.cjs');
4
4
  require('node:module');
5
5
  require('node:fs');
6
6
  require('node:fs/promises');
@@ -163,8 +163,6 @@ function normalizeDecodedNetworkPathname(decoded) {
163
163
  const AUTH_LOGIN_METHOD = 'auth.login';
164
164
  /** 读取当前登录态、授权状态和已获准披露资料的 bridge method 标识。 */
165
165
  const USER_GET_INFO_METHOD = 'user.getInfo';
166
- /** 读取当前用户小程序隔离身份的 bridge method 标识。 */
167
- const USER_GET_LOCAL_IDENTITY_METHOD = 'user.getLocalIdentity';
168
166
  /** 撤销当前用户授予本小程序授权的 bridge method 标识。 */
169
167
  const USER_REVOKE_AUTHORIZATION_METHOD = 'user.revokeAuthorization';
170
168
  /** 读取当前已登录用户 Steam 游戏库的 bridge method 标识。 */
@@ -265,13 +263,6 @@ const MINI_PROGRAM_PROTOCOL_CAPABILITIES = [
265
263
  permission: 'user.getInfo',
266
264
  risk: 'medium',
267
265
  },
268
- {
269
- method: USER_GET_LOCAL_IDENTITY_METHOD,
270
- module: 'user',
271
- capability: USER_GET_LOCAL_IDENTITY_METHOD,
272
- permission: 'user.getLocalIdentity',
273
- risk: 'medium',
274
- },
275
266
  {
276
267
  method: USER_REVOKE_AUTHORIZATION_METHOD,
277
268
  module: 'user',
@@ -5189,34 +5180,15 @@ function hashString(value) {
5189
5180
  }
5190
5181
 
5191
5182
  async function getMiniProgramRuntimeUserInfo(platformAdapter, identity) {
5192
- const miniProgramId = identity?.miniProgramId?.trim();
5193
- return miniProgramId
5194
- ? platformAdapter.user.getUserInfo({ miniProgramId })
5195
- : platformAdapter.user.getUserInfo();
5196
- }
5197
-
5198
- async function getMiniProgramRuntimeLocalIdentity(payload, platformAdapter, identity, trustedUserGesture) {
5199
- if (payload !== undefined) {
5200
- throw createMiniProgramRuntimeBridgeError('INVALID_PARAMS', 'user.getLocalIdentity 不接收入参');
5201
- }
5202
5183
  const miniProgramId = identity?.miniProgramId?.trim();
5203
5184
  if (!miniProgramId) {
5204
- throw createMiniProgramRuntimeBridgeError('INVALID_STATE', 'user.getLocalIdentity 缺少可信小程序身份');
5185
+ throw createMiniProgramRuntimeBridgeError('INVALID_STATE', 'user.getInfo 缺少可信小程序身份');
5205
5186
  }
5206
- const result = await platformAdapter.user.getLocalIdentity({
5207
- miniProgramId,
5208
- trustedUserGesture,
5209
- });
5210
- if (!isMiniProgramRuntimeRecord(result)
5211
- || typeof result.appUserId !== 'string'
5212
- || !result.appUserId.trim()) {
5213
- throw createMiniProgramRuntimeBridgeError('INVALID_RESPONSE', 'Host user.getLocalIdentity 返回无效');
5187
+ const result = await platformAdapter.user.getUserInfo({ miniProgramId });
5188
+ if (result.isHeyboxAppLoggedIn) {
5189
+ platformAdapter.auth.emitAuthEvent?.('user_info_authorization_change', result.authorization);
5214
5190
  }
5215
- platformAdapter.auth.emitAuthEvent?.('user_info_authorization_change', {
5216
- identity: 'granted',
5217
- profile: 'not_requested',
5218
- });
5219
- return { appUserId: result.appUserId };
5191
+ return result;
5220
5192
  }
5221
5193
 
5222
5194
  async function revokeMiniProgramRuntimeAuthorization(payload, platformAdapter, identity, trustedUserGesture) {
@@ -5568,7 +5540,6 @@ const MINI_PROGRAM_MOCK_RUNTIME_METHODS = MINI_PROGRAM_PROTOCOL_CAPABILITIES.map
5568
5540
  const MINI_PROGRAM_MOCK_RUNTIME_METHOD_HANDLER_MAP = {
5569
5541
  [AUTH_LOGIN_METHOD]: (runtime, payload, context) => runtime.login(payload, context),
5570
5542
  [USER_GET_INFO_METHOD]: (runtime) => runtime.getUserInfo(),
5571
- [USER_GET_LOCAL_IDENTITY_METHOD]: (runtime, payload, context) => runtime.getLocalIdentity(payload, context),
5572
5543
  [USER_REVOKE_AUTHORIZATION_METHOD]: (runtime, payload, context) => runtime.revokeAuthorization(payload, context),
5573
5544
  [USER_GET_STEAM_GAME_LIST_METHOD]: (runtime, payload) => runtime.getSteamGameList(payload),
5574
5545
  [SHARE_SHOW_SHARE_MENU_METHOD]: (runtime, payload) => runtime.showShareMenu(payload),
@@ -5610,6 +5581,9 @@ function createBrowserMockRuntimePlatformAdapter(options) {
5610
5581
  },
5611
5582
  },
5612
5583
  auth: {
5584
+ emitAuthEvent(name, payload) {
5585
+ options.onAuthEvent?.(name, payload);
5586
+ },
5613
5587
  async getCurrentUserId() {
5614
5588
  const user = options.getCurrentUser();
5615
5589
  return user?.app_user_id;
@@ -5629,27 +5603,21 @@ function createBrowserMockRuntimePlatformAdapter(options) {
5629
5603
  },
5630
5604
  },
5631
5605
  user: {
5632
- async getUserInfo() {
5606
+ async getUserInfo(identity) {
5633
5607
  const currentUser = options.getCurrentUser();
5634
5608
  const appUserId = currentUser?.app_user_id;
5635
- return appUserId
5609
+ const miniProgramId = identity?.miniProgramId;
5610
+ return appUserId && miniProgramId
5636
5611
  ? {
5637
5612
  isHeyboxAppLoggedIn: true,
5638
5613
  authorization: { identity: 'granted', profile: 'not_requested' },
5639
5614
  userInfo: {
5640
- app_user_id: appUserId,
5615
+ app_user_id: `${appUserId}:${miniProgramId}`,
5641
5616
  profile: { nickname: currentUser?.nickname || '', avatar: currentUser?.avatar || '' },
5642
5617
  },
5643
5618
  }
5644
5619
  : { isHeyboxAppLoggedIn: false, authorization: null, userInfo: null };
5645
5620
  },
5646
- async getLocalIdentity() {
5647
- const appUserId = options.getCurrentUser()?.app_user_id;
5648
- if (!appUserId) {
5649
- throw createMockBridgeError('NOT_LOGGED_IN', '当前 Mock 用户未登录');
5650
- }
5651
- return { appUserId };
5652
- },
5653
5621
  async revokeAuthorization(request) {
5654
5622
  if (!request.trustedUserGesture) {
5655
5623
  throw createMockBridgeError('USER_GESTURE_REQUIRED', 'Mock 撤销授权需要可信用户手势');
@@ -5838,10 +5806,6 @@ class MiniProgramMockRuntime {
5838
5806
  this.assertMockHostUserApiEnabled();
5839
5807
  return getMiniProgramRuntimeUserInfo(this.adapter, this.options.identity);
5840
5808
  }
5841
- getLocalIdentity(payload, context) {
5842
- this.assertMockHostUserApiEnabled();
5843
- return getMiniProgramRuntimeLocalIdentity(payload, this.adapter, this.options.identity, context.trustedUserGesture);
5844
- }
5845
5809
  revokeAuthorization(payload, context) {
5846
5810
  if (!this.authorizationMutationEnabled) {
5847
5811
  throw createMockBridgeError('SERVER_API_REQUIRED', '当前模式缺少有效的小程序权限快照');
@@ -6852,9 +6816,13 @@ const storage = new Map();
6852
6816
  const logs = [];
6853
6817
  let handshaken = false;
6854
6818
  let navigationBarStyle = 'dark';
6819
+ let mockHostDisposed = false;
6855
6820
  let mobileQrGeneration = 0;
6856
6821
  let mobileQrRefreshTimer;
6822
+ let nativeLaunchConfigRefreshTimer;
6857
6823
  let mobileDevSessionCreation = Promise.resolve();
6824
+ let mobileQrSessionInFlight = false;
6825
+ let mobileQrSessionPending = false;
6858
6826
  let currentUser = {
6859
6827
  app_user_id: 'au_debug_user',
6860
6828
  nickname: 'PC Debug User',
@@ -6913,6 +6881,7 @@ const platformAdapter = createBrowserMockRuntimePlatformAdapter({
6913
6881
  currentUser = createUserFromForm();
6914
6882
  updateUserStatus();
6915
6883
  },
6884
+ onAuthEvent: (name, payload) => postEvent(name, payload),
6916
6885
  requestNetwork,
6917
6886
  setDocumentTitle(title) {
6918
6887
  document.title = title;
@@ -6931,10 +6900,7 @@ updateUserStatus();
6931
6900
  updateStorageSnapshot();
6932
6901
  updatePermissionControls();
6933
6902
  window.addEventListener('message', handleMessage);
6934
- window.addEventListener('beforeunload', () => {
6935
- clearMobileQrRefreshTimer();
6936
- postEvent('unload', { timestamp: Date.now() });
6937
- });
6903
+ window.addEventListener('beforeunload', disposeMockHost);
6938
6904
  queryElement('#login-button').addEventListener('click', () => {
6939
6905
  void runtime.login();
6940
6906
  });
@@ -6967,13 +6933,14 @@ elements.resetPermissionsButton.addEventListener('click', () => {
6967
6933
  const mobileAppQrReady = setupMobileAppQr();
6968
6934
  if (bootstrap.devContext.source === 'remote') {
6969
6935
  void mobileAppQrReady.then(() => {
6970
- window.setInterval(() => void refreshNativeLaunchConfig(), NATIVE_LAUNCH_CONFIG_REFRESH_MS);
6936
+ if (mockHostDisposed) {
6937
+ return;
6938
+ }
6939
+ nativeLaunchConfigRefreshTimer = window.setInterval(() => void refreshNativeLaunchConfig(), NATIVE_LAUNCH_CONFIG_REFRESH_MS);
6971
6940
  });
6972
6941
  }
6973
6942
  function createRuntime() {
6974
6943
  return new MiniProgramMockRuntime(platformAdapter, {
6975
- onHeyboxAppLoginChange: payload => postEvent('heybox_app_login_change', payload),
6976
- onUserInfoAuthorizationChange: authorization => postEvent('user_info_authorization_change', authorization),
6977
6944
  runtimePermissions: createMiniProgramMockRuntimePermissions(permissionState),
6978
6945
  });
6979
6946
  }
@@ -7358,6 +7325,9 @@ async function copyDebugPageUrl() {
7358
7325
  }
7359
7326
  }
7360
7327
  async function setupMobileAppQr() {
7328
+ if (mockHostDisposed) {
7329
+ return;
7330
+ }
7361
7331
  lanAddresses = bootstrap.lanAddresses;
7362
7332
  defaultLanAddressId = bootstrap.defaultLanAddressId;
7363
7333
  macAppProtocol = bootstrap.macAppProtocol;
@@ -7367,11 +7337,13 @@ async function setupMobileAppQr() {
7367
7337
  await updateMobileQrCode();
7368
7338
  }
7369
7339
  async function refreshNativeLaunchConfig() {
7370
- if (nativeLaunchConfigRefreshInFlight)
7340
+ if (mockHostDisposed || nativeLaunchConfigRefreshInFlight)
7371
7341
  return;
7372
7342
  nativeLaunchConfigRefreshInFlight = true;
7373
7343
  try {
7374
7344
  const latest = await loadMockHostBootstrap();
7345
+ if (mockHostDisposed)
7346
+ return;
7375
7347
  const signature = readNativeLaunchConfigSignature(latest);
7376
7348
  if (signature === nativeLaunchConfigSignature)
7377
7349
  return;
@@ -7475,9 +7447,35 @@ function setupMobileLanSelect() {
7475
7447
  elements.mobileLanSelect.disabled = !hasLanAddress;
7476
7448
  }
7477
7449
  async function updateMobileQrCode() {
7450
+ if (mockHostDisposed) {
7451
+ return;
7452
+ }
7478
7453
  const generation = ++mobileQrGeneration;
7479
7454
  clearMobileQrRefreshTimer();
7455
+ if (mobileQrSessionInFlight) {
7456
+ mobileQrSessionPending = true;
7457
+ return;
7458
+ }
7459
+ mobileQrSessionInFlight = true;
7460
+ await generateMobileQrCode(generation);
7461
+ }
7462
+ function releaseMobileQrSession() {
7463
+ if (!mobileQrSessionInFlight) {
7464
+ return;
7465
+ }
7466
+ mobileQrSessionInFlight = false;
7467
+ if (mockHostDisposed) {
7468
+ mobileQrSessionPending = false;
7469
+ return;
7470
+ }
7471
+ if (mobileQrSessionPending) {
7472
+ mobileQrSessionPending = false;
7473
+ void updateMobileQrCode();
7474
+ }
7475
+ }
7476
+ async function generateMobileQrCode(generation) {
7480
7477
  if (nativeAppLaunchUnavailableReason) {
7478
+ releaseMobileQrSession();
7481
7479
  elements.mobileQrImage.removeAttribute('src');
7482
7480
  elements.mobileQrImage.hidden = true;
7483
7481
  elements.mobileQrStatus.textContent = nativeAppLaunchUnavailableReason;
@@ -7485,6 +7483,7 @@ async function updateMobileQrCode() {
7485
7483
  }
7486
7484
  const selected = readSelectedLanAddress();
7487
7485
  if (!selected) {
7486
+ releaseMobileQrSession();
7488
7487
  elements.mobileQrImage.removeAttribute('src');
7489
7488
  elements.mobileQrImage.hidden = true;
7490
7489
  elements.mobileQrStatus.textContent = '';
@@ -7492,6 +7491,7 @@ async function updateMobileQrCode() {
7492
7491
  }
7493
7492
  const basePayload = selected.mobileAppQrPayload;
7494
7493
  if (!basePayload) {
7494
+ releaseMobileQrSession();
7495
7495
  elements.mobileQrImage.removeAttribute('src');
7496
7496
  elements.mobileQrImage.hidden = true;
7497
7497
  elements.mobileQrStatus.textContent = '真机调试配置不可用,请重启 hb-sdk dev 后重试。';
@@ -7500,7 +7500,9 @@ async function updateMobileQrCode() {
7500
7500
  elements.mobileQrStatus.textContent = '正在生成二维码...';
7501
7501
  try {
7502
7502
  const devSession = await createMobileDevSession(selected);
7503
- if (generation !== mobileQrGeneration) {
7503
+ // 会话请求完成后立即放行下一轮刷新;旧二维码编码可能仍在异步进行,不能阻塞新会话。
7504
+ releaseMobileQrSession();
7505
+ if (mockHostDisposed || generation !== mobileQrGeneration) {
7504
7506
  return;
7505
7507
  }
7506
7508
  // 测试端扫一扫暂不支持打开网页,二维码必须直接编码 heybox:// 协议(不能走 HTTP 短链)。
@@ -7511,7 +7513,7 @@ async function updateMobileQrCode() {
7511
7513
  margin: 2,
7512
7514
  width: MOBILE_QR_IMAGE_SIZE,
7513
7515
  });
7514
- if (generation !== mobileQrGeneration) {
7516
+ if (mockHostDisposed || generation !== mobileQrGeneration) {
7515
7517
  return;
7516
7518
  }
7517
7519
  elements.mobileQrImage.src = imageUrl;
@@ -7520,7 +7522,8 @@ async function updateMobileQrCode() {
7520
7522
  scheduleMobileQrRefresh(devSession.expiresAt, generation);
7521
7523
  }
7522
7524
  catch (error) {
7523
- if (generation !== mobileQrGeneration) {
7525
+ releaseMobileQrSession();
7526
+ if (mockHostDisposed || generation !== mobileQrGeneration) {
7524
7527
  return;
7525
7528
  }
7526
7529
  elements.mobileQrImage.removeAttribute('src');
@@ -7570,7 +7573,7 @@ async function requestMobileDevSession(selected) {
7570
7573
  }
7571
7574
  function scheduleMobileQrRefresh(expiresAt, generation) {
7572
7575
  mobileQrRefreshTimer = window.setTimeout(() => {
7573
- if (generation !== mobileQrGeneration) {
7576
+ if (mockHostDisposed || generation !== mobileQrGeneration) {
7574
7577
  return;
7575
7578
  }
7576
7579
  elements.mobileQrImage.removeAttribute('src');
@@ -7586,6 +7589,21 @@ function clearMobileQrRefreshTimer() {
7586
7589
  window.clearTimeout(mobileQrRefreshTimer);
7587
7590
  mobileQrRefreshTimer = undefined;
7588
7591
  }
7592
+ function disposeMockHost() {
7593
+ if (mockHostDisposed) {
7594
+ return;
7595
+ }
7596
+ mockHostDisposed = true;
7597
+ mobileQrGeneration += 1;
7598
+ mobileQrSessionPending = false;
7599
+ clearMobileQrRefreshTimer();
7600
+ if (nativeLaunchConfigRefreshTimer !== undefined) {
7601
+ window.clearInterval(nativeLaunchConfigRefreshTimer);
7602
+ nativeLaunchConfigRefreshTimer = undefined;
7603
+ }
7604
+ window.removeEventListener('message', handleMessage);
7605
+ postEvent('unload', { timestamp: Date.now() });
7606
+ }
7589
7607
  function applyDevContextToMobileQrPayload(payload, devContextUrl) {
7590
7608
  const protocolMarker = payload.includes('#heybox://') ? '#heybox://' : 'heybox://';
7591
7609
  const protocolIndex = payload.indexOf(protocolMarker);