@heybox/hb-sdk 0.6.3 → 0.6.4-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.
- package/README.md +3 -1
- package/dist/cli-chunks/{context-Bu0Zusj_.cjs → context-BCwksd8H.cjs} +1 -1
- package/dist/cli-chunks/{create-CgAGcRtZ.cjs → create-BO8GHVi0.cjs} +1 -1
- package/dist/cli-chunks/{dev-g35-QcIa.cjs → dev-DmgKnEC2.cjs} +59 -41
- package/dist/cli-chunks/{doctor-klsQg82G.cjs → doctor-BlKB4f78.cjs} +1 -1
- package/dist/cli-chunks/{index-CbsbCgtf.cjs → index-PxkpQ5of.cjs} +2 -2
- package/dist/cli-chunks/{index--P321c8v.cjs → index-Q0G1SsEs.cjs} +13 -13
- package/dist/cli-chunks/{login-DEoReXOe.cjs → login-Cxdo4B6Z.cjs} +2 -2
- package/dist/cli-chunks/{remote-CZ-G3RSH.cjs → remote-C1Rsb1dx.cjs} +4 -4
- package/dist/cli-chunks/{session-vlPGi1Z8.cjs → session-CC3Oz3Xc.cjs} +1 -1
- package/dist/cli.cjs +1 -1
- package/dist/devtools/mock-host/index.html +54 -1
- package/dist/devtools/mock-host/main.js +196 -6
- package/dist/index.cjs.js +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/vite.cjs.js +1 -1
- package/dist/vite.esm.js +1 -1
- package/package.json +2 -2
- package/skill/SKILL.md +4 -2
- package/skill/references/api-root.md +4 -2
- package/skill/references/cli.md +5 -3
- package/skill/skill.json +4 -4
package/README.md
CHANGED
|
@@ -57,7 +57,9 @@ SDK 需要在黑盒小程序 iframe 容器内运行。父容器会为页面注
|
|
|
57
57
|
npm run dev
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
-
调试页会通过 iframe 加载本地页面并补齐小程序 bridge
|
|
60
|
+
调试页会通过 iframe 加载本地页面并补齐小程序 bridge 环境。`hb-sdk dev` 的基础启动只依赖本地页面地址:即使项目未绑定、CLI 未登录或远端暂时不可用,浏览器 Mock、Mac 启动协议和手机二维码也会继续生成,真机 dev shell 以匿名本地沙箱加载 `mini_url`,不会把公开 `detail` 查询作为启动门禁。项目已绑定时会限时 3 秒读取远端 dev context;成功后 Mock Host 用真实 Runtime 权限快照初始化本地模拟,失败或超时则显示脱敏警告,并默认拒绝 `network.request` 等受管能力。
|
|
61
|
+
|
|
62
|
+
Mock Host 可以在内存中调整 devtools-only 权限模拟,不会重建 iframe,因此不影响 Vite HMR;本地设置不会修改线上权限。调试页会对比已读取的线上快照,提示本地放开但上线后会返回 `PERMISSION_DENIED` 的差异。权限快照只通过 mock host 的同源只读 bootstrap 接口传递,URL query 不能提供或覆盖权限。真实容器加载开发 `mini_url` 前会提示“即将打开未经验证的开发网页。该页面可能由本机或局域网服务提供,请确认来源可信后继续。”,用户确认后才继续加载。Codex、VSCode 等内嵌浏览器可能无法唤起系统 APP;遇到这种情况时,请在系统浏览器中打开同一个调试页后重试。
|
|
61
63
|
|
|
62
64
|
在未使用脚手架的 Vite 项目中,可以把命令加到 `package.json`:
|
|
63
65
|
|
|
@@ -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
|
|
8
|
+
var index = require('./index-Q0G1SsEs.cjs');
|
|
9
9
|
require('node:module');
|
|
10
10
|
require('os');
|
|
11
11
|
require('readline');
|
|
@@ -9,8 +9,8 @@ var node_url = require('node:url');
|
|
|
9
9
|
var net = require('node:net');
|
|
10
10
|
var node_http = require('node:http');
|
|
11
11
|
var browser = require('./browser-RAy8e8cV.cjs');
|
|
12
|
-
var index = require('./index
|
|
13
|
-
var context = require('./context-
|
|
12
|
+
var index = require('./index-Q0G1SsEs.cjs');
|
|
13
|
+
var context = require('./context-BCwksd8H.cjs');
|
|
14
14
|
require('node:process');
|
|
15
15
|
require('node:buffer');
|
|
16
16
|
require('node:util');
|
|
@@ -24,7 +24,7 @@ require('events');
|
|
|
24
24
|
require('stream');
|
|
25
25
|
require('buffer');
|
|
26
26
|
require('util');
|
|
27
|
-
require('./session-
|
|
27
|
+
require('./session-CC3Oz3Xc.cjs');
|
|
28
28
|
require('node:crypto');
|
|
29
29
|
require('fs');
|
|
30
30
|
require('constants');
|
|
@@ -223,6 +223,7 @@ async function startMiniProgramMockHostServer(options) {
|
|
|
223
223
|
assertCompleteMiniProgramMockHostRoot(root);
|
|
224
224
|
const bootstrapJson = serializeMockHostBootstrap({
|
|
225
225
|
defaultLanAddressId: options.defaultLanAddressId,
|
|
226
|
+
devContext: options.devContext,
|
|
226
227
|
lanAddresses: options.lanAddresses ?? [],
|
|
227
228
|
macAppProtocol: options.macAppProtocol,
|
|
228
229
|
nativeAppLaunchUnavailableReason: options.nativeAppLaunchUnavailableReason,
|
|
@@ -669,12 +670,14 @@ function createHeyboxProtocol(payload) {
|
|
|
669
670
|
/** 构建时替换为当前发布包的实际版本。 */
|
|
670
671
|
const HB_SDK_VERSION = typeof undefined === 'string'
|
|
671
672
|
? undefined
|
|
672
|
-
: '0.6.
|
|
673
|
+
: '0.6.4-alpha.0';
|
|
673
674
|
|
|
674
675
|
const DEFAULT_APP_PORT = 5173;
|
|
675
676
|
const DEFAULT_MOCK_PORT = 5174;
|
|
677
|
+
const DEFAULT_DEV_CONTEXT_TIMEOUT_MS = 3000;
|
|
676
678
|
const DEV_LISTEN_HOST = '0.0.0.0';
|
|
677
679
|
const LOCAL_DEV_URL_HOST = '127.0.0.1';
|
|
680
|
+
const DEV_CONTEXT_UNAVAILABLE_WARNING = '远端 dev context 不可用,已继续匿名调试。';
|
|
678
681
|
// Shared with Heybox H5 Vite plugins so hb-sdk can own the launch output.
|
|
679
682
|
const MANAGED_DEV_OUTPUT_ENV = 'HEYBOX_DEV_SERVER_MANAGED_OUTPUT';
|
|
680
683
|
const VITE_LOG_LEVEL = 'warn';
|
|
@@ -701,6 +704,7 @@ async function runDevCommand(options, runtime = {}) {
|
|
|
701
704
|
fetchImpl,
|
|
702
705
|
logger,
|
|
703
706
|
projectRoot,
|
|
707
|
+
timeoutMs: runtime.devContextTimeoutMs ?? DEFAULT_DEV_CONTEXT_TIMEOUT_MS,
|
|
704
708
|
});
|
|
705
709
|
const vite = await logger.task('正在加载项目 Vite', () => loadProjectVite(projectRoot), { successText: '已加载项目 Vite' });
|
|
706
710
|
const appServer = await logger.task('正在创建 Vite dev server', () => withManagedDevOutputEnv(() => vite.createServer(createViteServerOptions(projectRoot, resolvedOptions)), runtime.env), { successText: '已创建 Vite dev server' });
|
|
@@ -724,18 +728,16 @@ async function runDevCommand(options, runtime = {}) {
|
|
|
724
728
|
try {
|
|
725
729
|
mockHost = await logger.task('正在启动 Mock runtime host', () => startMiniProgramMockHostServer({
|
|
726
730
|
appUrl,
|
|
731
|
+
devContext: devLaunchContext,
|
|
727
732
|
fetchImpl,
|
|
728
733
|
getPort: getPortImpl,
|
|
729
734
|
defaultLanAddressId: lanAddresses[0]?.id,
|
|
730
735
|
lanAddresses,
|
|
731
|
-
macAppProtocol:
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
})
|
|
737
|
-
: undefined,
|
|
738
|
-
nativeAppLaunchUnavailableReason: devLaunchContext.nativeAppLaunchUnavailableReason,
|
|
736
|
+
macAppProtocol: createMacAppProtocol(appUrl, {
|
|
737
|
+
miniProgramId: devLaunchContext.miniProgramId,
|
|
738
|
+
runtimeUrl: options.runtimeUrl,
|
|
739
|
+
sdkVersion: HB_SDK_VERSION,
|
|
740
|
+
}),
|
|
739
741
|
port: options.mockPort ?? DEFAULT_MOCK_PORT,
|
|
740
742
|
root: runtime.mockHostRoot,
|
|
741
743
|
rootCandidates: runtime.mockHostRootCandidates,
|
|
@@ -750,12 +752,10 @@ async function runDevCommand(options, runtime = {}) {
|
|
|
750
752
|
logger.success('Mock runtime host 已就绪');
|
|
751
753
|
logger.info(`Mock runtime host: ${mockHost.url}`);
|
|
752
754
|
logger.info(`Mini program URL: ${appUrl}`);
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
else {
|
|
758
|
-
logger.warn(`Mac/Mobile APP 真机调试不可用:${devLaunchContext.nativeAppLaunchUnavailableReason}`);
|
|
755
|
+
logger.info('Mac APP: use the button in Mock runtime host');
|
|
756
|
+
logger.info('Mobile APP: scan the QR code in Mock runtime host');
|
|
757
|
+
if (devLaunchContext.source === 'anonymous') {
|
|
758
|
+
logger.warn('当前使用匿名本地沙箱;真机调试可用,但不会携带远端小程序身份或权限。');
|
|
759
759
|
}
|
|
760
760
|
if (options.open !== false) {
|
|
761
761
|
logger.debug('正在打开浏览器调试页');
|
|
@@ -766,40 +766,61 @@ async function runDevCommand(options, runtime = {}) {
|
|
|
766
766
|
async function loadDevLaunchContext(options) {
|
|
767
767
|
const miniProgramId = await context.readBoundMiniProgramId(options.projectRoot);
|
|
768
768
|
if (!miniProgramId) {
|
|
769
|
-
const
|
|
770
|
-
options.logger.warn(`未读取到远端 Runtime 权限,Mock runtime 将默认拒绝受管能力:${
|
|
771
|
-
return {
|
|
769
|
+
const anonymousReason = '当前项目未绑定小程序。请先运行 hb-sdk remote create 或 hb-sdk remote bind <mini-program-id>。';
|
|
770
|
+
options.logger.warn(`未读取到远端 Runtime 权限,Mock runtime 将默认拒绝受管能力:${anonymousReason}`);
|
|
771
|
+
return {
|
|
772
|
+
source: 'anonymous',
|
|
773
|
+
warning: anonymousReason,
|
|
774
|
+
};
|
|
772
775
|
}
|
|
773
776
|
try {
|
|
774
|
-
const { detail, miniProgramId: verifiedMiniProgramId } = await options.logger.task('正在读取远端小程序权限', () =>
|
|
775
|
-
cwd: options.projectRoot,
|
|
776
|
-
env: options.env,
|
|
777
|
+
const { detail, miniProgramId: verifiedMiniProgramId } = await options.logger.task('正在读取远端小程序权限', () => loadRemoteDevContextWithTimeout({
|
|
777
778
|
fetchImpl: options.fetchImpl,
|
|
779
|
+
load: fetchImpl => context.getBoundMiniProgram({
|
|
780
|
+
cwd: options.projectRoot,
|
|
781
|
+
env: options.env,
|
|
782
|
+
fetchImpl,
|
|
783
|
+
}),
|
|
784
|
+
timeoutMs: options.timeoutMs,
|
|
778
785
|
}), { successText: '已读取远端小程序权限' });
|
|
779
|
-
return {
|
|
786
|
+
return {
|
|
787
|
+
source: 'remote',
|
|
788
|
+
miniProgramId: verifiedMiniProgramId,
|
|
789
|
+
runtimePermissions: detail.runtime_permissions,
|
|
790
|
+
};
|
|
780
791
|
}
|
|
781
792
|
catch (error) {
|
|
782
|
-
if (
|
|
793
|
+
if (error instanceof context.MiniProgramProjectBindingError &&
|
|
794
|
+
error.code !== 'MINI_PROGRAM_UNBOUND') {
|
|
783
795
|
throw error;
|
|
784
796
|
}
|
|
785
|
-
options.logger.warn(`未读取到远端 Runtime 权限,Mock runtime 将默认拒绝受管能力:${
|
|
797
|
+
options.logger.warn(`未读取到远端 Runtime 权限,Mock runtime 将默认拒绝受管能力:${DEV_CONTEXT_UNAVAILABLE_WARNING}`);
|
|
786
798
|
return {
|
|
787
|
-
|
|
799
|
+
source: 'anonymous',
|
|
800
|
+
warning: DEV_CONTEXT_UNAVAILABLE_WARNING,
|
|
788
801
|
};
|
|
789
802
|
}
|
|
790
803
|
}
|
|
791
|
-
function
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
return
|
|
804
|
+
async function loadRemoteDevContextWithTimeout(options) {
|
|
805
|
+
const controller = new AbortController();
|
|
806
|
+
const fetchImpl = ((input, init) => options.fetchImpl(input, { ...init, signal: controller.signal }));
|
|
807
|
+
let timeout;
|
|
808
|
+
try {
|
|
809
|
+
return await Promise.race([
|
|
810
|
+
options.load(fetchImpl),
|
|
811
|
+
new Promise((_resolve, reject) => {
|
|
812
|
+
timeout = setTimeout(() => {
|
|
813
|
+
controller.abort();
|
|
814
|
+
reject(new Error('dev context timeout'));
|
|
815
|
+
}, Math.max(1, options.timeoutMs));
|
|
816
|
+
}),
|
|
817
|
+
]);
|
|
797
818
|
}
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
(
|
|
819
|
+
finally {
|
|
820
|
+
if (timeout) {
|
|
821
|
+
clearTimeout(timeout);
|
|
822
|
+
}
|
|
801
823
|
}
|
|
802
|
-
return error instanceof Error && 'code' in error && error.code === 'AUTH_SESSION_MISSING';
|
|
803
824
|
}
|
|
804
825
|
function findProjectRoot(startDir) {
|
|
805
826
|
let current = path.resolve(startDir);
|
|
@@ -984,9 +1005,6 @@ async function closeAll(closers) {
|
|
|
984
1005
|
await Promise.allSettled(closers.map((close) => close()));
|
|
985
1006
|
}
|
|
986
1007
|
function createLanAddressCandidates(options) {
|
|
987
|
-
if (!options.miniProgramId) {
|
|
988
|
-
return [];
|
|
989
|
-
}
|
|
990
1008
|
const viteNetworkUrlByHost = new Map(options.viteNetworkUrls
|
|
991
1009
|
.map((url) => [readUrlHost(url), url])
|
|
992
1010
|
.filter((entry) => Boolean(entry[0])));
|
|
@@ -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
|
|
7
|
+
var index = require('./index-Q0G1SsEs.cjs');
|
|
8
8
|
require('node:module');
|
|
9
9
|
require('path');
|
|
10
10
|
require('os');
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var index$2 = require('./index
|
|
3
|
+
var index$2 = require('./index-Q0G1SsEs.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');
|
|
7
7
|
var require$$0$3 = require('assert');
|
|
8
8
|
var require$$4$2 = require('events');
|
|
9
9
|
var require$$1$1 = require('util');
|
|
10
|
-
var context$1 = require('./context-
|
|
10
|
+
var context$1 = require('./context-BCwksd8H.cjs');
|
|
11
11
|
var require$$0$5 = require('net');
|
|
12
12
|
var require$$0$4 = require('url');
|
|
13
13
|
var require$$2$2 = require('http');
|
|
@@ -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
|
|
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-Q0G1SsEs.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
|
|
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-Q0G1SsEs.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
|
|
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-Q0G1SsEs.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
|
|
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-Q0G1SsEs.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
|
|
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-Q0G1SsEs.cjs', document.baseURI).href)));
|
|
250
250
|
function __require() { return require$1("node:process"); }
|
|
251
251
|
|
|
252
252
|
var help = {};
|
|
@@ -13323,7 +13323,7 @@ function getPathname(pathWithQuery) {
|
|
|
13323
13323
|
}
|
|
13324
13324
|
|
|
13325
13325
|
const CLI_VERSION_PLACEHOLDER = ['__HB', 'SDK', 'CLI', 'VERSION__'].join('_');
|
|
13326
|
-
const BUILT_CLI_VERSION = '0.6.
|
|
13326
|
+
const BUILT_CLI_VERSION = '0.6.4-alpha.0';
|
|
13327
13327
|
const PACKAGE_JSON_CANDIDATES = [
|
|
13328
13328
|
path.resolve(__dirname, '..', '..', 'package.json'),
|
|
13329
13329
|
path.resolve(__dirname, '..', 'package.json'),
|
|
@@ -13644,31 +13644,31 @@ function createCommandLoggerResolver(options) {
|
|
|
13644
13644
|
};
|
|
13645
13645
|
}
|
|
13646
13646
|
const defaultClearLoginStatus = async (...args) => {
|
|
13647
|
-
const { clearLoginStatus } = await Promise.resolve().then(function () { return require('./login-
|
|
13647
|
+
const { clearLoginStatus } = await Promise.resolve().then(function () { return require('./login-Cxdo4B6Z.cjs'); });
|
|
13648
13648
|
return clearLoginStatus(...args);
|
|
13649
13649
|
};
|
|
13650
13650
|
const defaultLoginToHeybox = async (...args) => {
|
|
13651
|
-
const { loginToHeybox } = await Promise.resolve().then(function () { return require('./login-
|
|
13651
|
+
const { loginToHeybox } = await Promise.resolve().then(function () { return require('./login-Cxdo4B6Z.cjs'); });
|
|
13652
13652
|
return loginToHeybox(...args);
|
|
13653
13653
|
};
|
|
13654
13654
|
const defaultPrintLoginStatus = async (...args) => {
|
|
13655
|
-
const { printLoginStatus } = await Promise.resolve().then(function () { return require('./login-
|
|
13655
|
+
const { printLoginStatus } = await Promise.resolve().then(function () { return require('./login-Cxdo4B6Z.cjs'); });
|
|
13656
13656
|
return printLoginStatus(...args);
|
|
13657
13657
|
};
|
|
13658
13658
|
const defaultRunCreateCommand = async (...args) => {
|
|
13659
|
-
const { runCreateCommand } = await Promise.resolve().then(function () { return require('./create-
|
|
13659
|
+
const { runCreateCommand } = await Promise.resolve().then(function () { return require('./create-BO8GHVi0.cjs'); });
|
|
13660
13660
|
return runCreateCommand(...args);
|
|
13661
13661
|
};
|
|
13662
13662
|
const defaultRunDevCommand = async (...args) => {
|
|
13663
|
-
const { runDevCommand } = await Promise.resolve().then(function () { return require('./dev-
|
|
13663
|
+
const { runDevCommand } = await Promise.resolve().then(function () { return require('./dev-DmgKnEC2.cjs'); });
|
|
13664
13664
|
return runDevCommand(...args);
|
|
13665
13665
|
};
|
|
13666
13666
|
const defaultRunDoctorCommand = async (...args) => {
|
|
13667
|
-
const { runDoctorCommand } = await Promise.resolve().then(function () { return require('./doctor-
|
|
13667
|
+
const { runDoctorCommand } = await Promise.resolve().then(function () { return require('./doctor-BlKB4f78.cjs'); });
|
|
13668
13668
|
return runDoctorCommand(...args);
|
|
13669
13669
|
};
|
|
13670
13670
|
const defaultRunRemoteCommand = async (...args) => {
|
|
13671
|
-
const { runRemoteCommand } = await Promise.resolve().then(function () { return require('./remote-
|
|
13671
|
+
const { runRemoteCommand } = await Promise.resolve().then(function () { return require('./remote-C1Rsb1dx.cjs'); });
|
|
13672
13672
|
return runRemoteCommand(...args);
|
|
13673
13673
|
};
|
|
13674
13674
|
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-
|
|
6
|
+
var session = require('./session-CC3Oz3Xc.cjs');
|
|
7
7
|
var browser = require('./browser-RAy8e8cV.cjs');
|
|
8
|
-
var index = require('./index
|
|
8
|
+
var index = require('./index-Q0G1SsEs.cjs');
|
|
9
9
|
require('node:path');
|
|
10
10
|
require('fs');
|
|
11
11
|
require('constants');
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var promises = require('node:readline/promises');
|
|
4
|
-
var index = require('./index
|
|
5
|
-
var session = require('./session-
|
|
4
|
+
var index = require('./index-Q0G1SsEs.cjs');
|
|
5
|
+
var session = require('./session-CC3Oz3Xc.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 context = require('./context-
|
|
10
|
+
var context = require('./context-BCwksd8H.cjs');
|
|
11
11
|
require('node:module');
|
|
12
12
|
require('path');
|
|
13
13
|
require('os');
|
|
@@ -264,7 +264,7 @@ async function createDefaultCosClient(uploadToken) {
|
|
|
264
264
|
};
|
|
265
265
|
}
|
|
266
266
|
async function loadCosConstructor() {
|
|
267
|
-
const cosModule = await Promise.resolve().then(function () { return require('./index-
|
|
267
|
+
const cosModule = await Promise.resolve().then(function () { return require('./index-PxkpQ5of.cjs'); }).then(function (n) { return n.index; });
|
|
268
268
|
return cosModule.default;
|
|
269
269
|
}
|
|
270
270
|
function formatSize(bytes) {
|
package/dist/cli.cjs
CHANGED
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
button,
|
|
23
|
-
input
|
|
23
|
+
input,
|
|
24
|
+
select {
|
|
24
25
|
font: inherit;
|
|
25
26
|
}
|
|
26
27
|
|
|
@@ -190,6 +191,38 @@
|
|
|
190
191
|
background: #fff;
|
|
191
192
|
}
|
|
192
193
|
|
|
194
|
+
.inline-field {
|
|
195
|
+
display: flex;
|
|
196
|
+
align-items: center;
|
|
197
|
+
gap: 8px;
|
|
198
|
+
margin-top: 10px;
|
|
199
|
+
color: #475569;
|
|
200
|
+
font-size: 13px;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
.inline-field input {
|
|
204
|
+
width: 16px;
|
|
205
|
+
height: 16px;
|
|
206
|
+
margin: 0;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
.release-diagnostics {
|
|
210
|
+
display: grid;
|
|
211
|
+
gap: 6px;
|
|
212
|
+
margin: 10px 0 0;
|
|
213
|
+
padding: 0;
|
|
214
|
+
list-style: none;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
.release-diagnostics li {
|
|
218
|
+
border-left: 3px solid #d97706;
|
|
219
|
+
padding: 7px 8px;
|
|
220
|
+
color: #92400e;
|
|
221
|
+
background: #fffbeb;
|
|
222
|
+
font-size: 12px;
|
|
223
|
+
line-height: 1.5;
|
|
224
|
+
}
|
|
225
|
+
|
|
193
226
|
.mobile-qr {
|
|
194
227
|
display: grid;
|
|
195
228
|
justify-items: center;
|
|
@@ -353,6 +386,26 @@
|
|
|
353
386
|
<strong id="mini-url"></strong>
|
|
354
387
|
</section>
|
|
355
388
|
|
|
389
|
+
<section class="block">
|
|
390
|
+
<span>Dev Context</span>
|
|
391
|
+
<strong id="dev-context-status"></strong>
|
|
392
|
+
<label class="field" style="margin-top: 10px">
|
|
393
|
+
<span>network.request</span>
|
|
394
|
+
<select id="network-permission-select">
|
|
395
|
+
<option value="disabled">拒绝</option>
|
|
396
|
+
<option value="enabled">允许</option>
|
|
397
|
+
</select>
|
|
398
|
+
</label>
|
|
399
|
+
<label class="inline-field">
|
|
400
|
+
<input id="official-domain-checkbox" type="checkbox" />
|
|
401
|
+
<span>允许访问小黑盒官方域名</span>
|
|
402
|
+
</label>
|
|
403
|
+
<div class="actions" style="margin-top: 10px">
|
|
404
|
+
<button id="reset-permissions-button" type="button">恢复初始权限</button>
|
|
405
|
+
</div>
|
|
406
|
+
<ul class="release-diagnostics" id="release-diagnostics"></ul>
|
|
407
|
+
</section>
|
|
408
|
+
|
|
356
409
|
<section class="csp-violations" id="csp-violations" hidden>
|
|
357
410
|
<strong>网络或资源请求已被 CSP 阻止</strong>
|
|
358
411
|
</section>
|
|
@@ -3445,6 +3445,120 @@ function formatBlockedResource(payload) {
|
|
|
3445
3445
|
return '未知资源';
|
|
3446
3446
|
}
|
|
3447
3447
|
|
|
3448
|
+
const DEFAULT_PERMISSION_STATE = {
|
|
3449
|
+
networkRequest: {
|
|
3450
|
+
status: 'disabled',
|
|
3451
|
+
useOfficialDomain: false,
|
|
3452
|
+
},
|
|
3453
|
+
};
|
|
3454
|
+
function createMiniProgramMockPermissionState(context) {
|
|
3455
|
+
const parsed = parseRuntimePermissions(context.runtimePermissions);
|
|
3456
|
+
return parsed.valid && parsed.networkRequest
|
|
3457
|
+
? { networkRequest: { ...parsed.networkRequest } }
|
|
3458
|
+
: cloneDefaultPermissionState();
|
|
3459
|
+
}
|
|
3460
|
+
function createMiniProgramMockRuntimePermissions(state) {
|
|
3461
|
+
return {
|
|
3462
|
+
schema_version: 1,
|
|
3463
|
+
entries: [
|
|
3464
|
+
{
|
|
3465
|
+
key: 'network.request',
|
|
3466
|
+
status: state.networkRequest.status,
|
|
3467
|
+
config: {
|
|
3468
|
+
useOfficialDomain: state.networkRequest.useOfficialDomain,
|
|
3469
|
+
},
|
|
3470
|
+
},
|
|
3471
|
+
],
|
|
3472
|
+
};
|
|
3473
|
+
}
|
|
3474
|
+
function createMiniProgramDevReleaseDiagnostics(context, localState) {
|
|
3475
|
+
if (context.source === 'anonymous') {
|
|
3476
|
+
return [
|
|
3477
|
+
{
|
|
3478
|
+
code: 'REMOTE_CONTEXT_UNAVAILABLE',
|
|
3479
|
+
severity: 'warning',
|
|
3480
|
+
message: `未获取到线上权限配置,本地模拟不代表上线状态${context.warning ? `:${context.warning}` : ''}`,
|
|
3481
|
+
},
|
|
3482
|
+
];
|
|
3483
|
+
}
|
|
3484
|
+
const parsedRemote = parseRuntimePermissions(context.runtimePermissions);
|
|
3485
|
+
if (!parsedRemote.valid) {
|
|
3486
|
+
return [
|
|
3487
|
+
{
|
|
3488
|
+
code: 'REMOTE_PERMISSIONS_INVALID',
|
|
3489
|
+
severity: 'warning',
|
|
3490
|
+
message: '线上权限配置不可用,本地模拟不代表上线状态。',
|
|
3491
|
+
},
|
|
3492
|
+
];
|
|
3493
|
+
}
|
|
3494
|
+
const remoteState = parsedRemote.networkRequest ?? DEFAULT_PERMISSION_STATE.networkRequest;
|
|
3495
|
+
if (localState.networkRequest.status === 'enabled' &&
|
|
3496
|
+
remoteState.status !== 'enabled') {
|
|
3497
|
+
return [
|
|
3498
|
+
{
|
|
3499
|
+
code: 'NETWORK_REQUEST_DISABLED_ONLINE',
|
|
3500
|
+
severity: 'warning',
|
|
3501
|
+
message: '当前本地允许 network.request,但线上权限已关闭;上线后请求会返回 PERMISSION_DENIED。',
|
|
3502
|
+
},
|
|
3503
|
+
];
|
|
3504
|
+
}
|
|
3505
|
+
if (localState.networkRequest.status === 'enabled' &&
|
|
3506
|
+
localState.networkRequest.useOfficialDomain &&
|
|
3507
|
+
!remoteState.useOfficialDomain) {
|
|
3508
|
+
return [
|
|
3509
|
+
{
|
|
3510
|
+
code: 'OFFICIAL_DOMAIN_DISABLED_ONLINE',
|
|
3511
|
+
severity: 'warning',
|
|
3512
|
+
message: '当前本地允许访问小黑盒官方域名,但线上权限未开放;上线后相关请求会返回 PERMISSION_DENIED。',
|
|
3513
|
+
},
|
|
3514
|
+
];
|
|
3515
|
+
}
|
|
3516
|
+
return [];
|
|
3517
|
+
}
|
|
3518
|
+
function parseRuntimePermissions(snapshot) {
|
|
3519
|
+
if (!isRecord$2(snapshot) || snapshot.schema_version !== 1 || !Array.isArray(snapshot.entries)) {
|
|
3520
|
+
return { valid: false };
|
|
3521
|
+
}
|
|
3522
|
+
if (snapshot.revision !== undefined &&
|
|
3523
|
+
(typeof snapshot.revision !== 'number' ||
|
|
3524
|
+
!Number.isInteger(snapshot.revision) ||
|
|
3525
|
+
snapshot.revision < 0)) {
|
|
3526
|
+
return { valid: false };
|
|
3527
|
+
}
|
|
3528
|
+
const seenKeys = new Set();
|
|
3529
|
+
let networkRequest;
|
|
3530
|
+
for (const entry of snapshot.entries) {
|
|
3531
|
+
if (!isRecord$2(entry) || typeof entry.key !== 'string' || !entry.key.trim()) {
|
|
3532
|
+
return { valid: false };
|
|
3533
|
+
}
|
|
3534
|
+
const key = entry.key.trim();
|
|
3535
|
+
if (seenKeys.has(key) ||
|
|
3536
|
+
(entry.status !== 'enabled' && entry.status !== 'disabled') ||
|
|
3537
|
+
!isRecord$2(entry.config)) {
|
|
3538
|
+
return { valid: false };
|
|
3539
|
+
}
|
|
3540
|
+
seenKeys.add(key);
|
|
3541
|
+
if (key === 'network.request') {
|
|
3542
|
+
if (typeof entry.config.useOfficialDomain !== 'boolean') {
|
|
3543
|
+
return { valid: false };
|
|
3544
|
+
}
|
|
3545
|
+
networkRequest = {
|
|
3546
|
+
status: entry.status,
|
|
3547
|
+
useOfficialDomain: entry.config.useOfficialDomain,
|
|
3548
|
+
};
|
|
3549
|
+
}
|
|
3550
|
+
}
|
|
3551
|
+
return { valid: true, networkRequest };
|
|
3552
|
+
}
|
|
3553
|
+
function cloneDefaultPermissionState() {
|
|
3554
|
+
return {
|
|
3555
|
+
networkRequest: { ...DEFAULT_PERMISSION_STATE.networkRequest },
|
|
3556
|
+
};
|
|
3557
|
+
}
|
|
3558
|
+
function isRecord$2(value) {
|
|
3559
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
3560
|
+
}
|
|
3561
|
+
|
|
3448
3562
|
async function getMiniProgramRuntimeUserInfo(platformAdapter) {
|
|
3449
3563
|
const userId = await resolveCurrentUserId(platformAdapter);
|
|
3450
3564
|
if (!userId) {
|
|
@@ -6306,6 +6420,7 @@ const elements = {
|
|
|
6306
6420
|
cspViolations: queryElement('#csp-violations'),
|
|
6307
6421
|
debugPageCopyStatus: queryElement('#debug-page-copy-status'),
|
|
6308
6422
|
debugPageUrl: queryElement('#debug-page-url'),
|
|
6423
|
+
devContextStatus: queryElement('#dev-context-status'),
|
|
6309
6424
|
device: queryElement('#device'),
|
|
6310
6425
|
logs: queryElement('#logs'),
|
|
6311
6426
|
macAppButton: queryElement('#mac-app-button'),
|
|
@@ -6315,6 +6430,10 @@ const elements = {
|
|
|
6315
6430
|
mobileQrImage: queryElement('#mobile-qr-image'),
|
|
6316
6431
|
mobileQrStatus: queryElement('#mobile-qr-status'),
|
|
6317
6432
|
nicknameInput: queryElement('#nickname-input'),
|
|
6433
|
+
networkPermissionSelect: queryElement('#network-permission-select'),
|
|
6434
|
+
officialDomainCheckbox: queryElement('#official-domain-checkbox'),
|
|
6435
|
+
releaseDiagnostics: queryElement('#release-diagnostics'),
|
|
6436
|
+
resetPermissionsButton: queryElement('#reset-permissions-button'),
|
|
6318
6437
|
storageSnapshot: queryElement('#storage-snapshot'),
|
|
6319
6438
|
userStatus: queryElement('#user-status'),
|
|
6320
6439
|
};
|
|
@@ -6325,13 +6444,15 @@ if (!miniUrl) {
|
|
|
6325
6444
|
}
|
|
6326
6445
|
const miniProgramUrl = miniUrl;
|
|
6327
6446
|
const bootstrap = await loadMockHostBootstrap();
|
|
6328
|
-
const
|
|
6447
|
+
const devContext = bootstrap.devContext;
|
|
6448
|
+
const initialPermissionState = createMiniProgramMockPermissionState(devContext);
|
|
6449
|
+
let permissionState = clonePermissionState(initialPermissionState);
|
|
6329
6450
|
const iframe = document.createElement('iframe');
|
|
6330
6451
|
iframe.src = appendNonce(miniProgramUrl, nonce);
|
|
6331
6452
|
iframe.allow = 'clipboard-read; clipboard-write';
|
|
6332
6453
|
elements.device.appendChild(iframe);
|
|
6333
6454
|
elements.miniUrl.textContent = miniProgramUrl;
|
|
6334
|
-
const
|
|
6455
|
+
const platformAdapter = createBrowserMockRuntimePlatformAdapter({
|
|
6335
6456
|
iframe,
|
|
6336
6457
|
getCurrentHref: () => location.href,
|
|
6337
6458
|
getCurrentUser: () => currentUser,
|
|
@@ -6353,12 +6474,11 @@ const runtime = new MiniProgramMockRuntime(createBrowserMockRuntimePlatformAdapt
|
|
|
6353
6474
|
storage.set(key, value);
|
|
6354
6475
|
updateStorageSnapshot();
|
|
6355
6476
|
},
|
|
6356
|
-
}), {
|
|
6357
|
-
onAuthChange: (result) => postEvent('authChange', result),
|
|
6358
|
-
runtimePermissions,
|
|
6359
6477
|
});
|
|
6478
|
+
let runtime = createRuntime();
|
|
6360
6479
|
updateUserStatus();
|
|
6361
6480
|
updateStorageSnapshot();
|
|
6481
|
+
updatePermissionControls();
|
|
6362
6482
|
window.addEventListener('message', handleMessage);
|
|
6363
6483
|
window.addEventListener('beforeunload', () => {
|
|
6364
6484
|
postEvent('unload', { timestamp: Date.now() });
|
|
@@ -6386,7 +6506,48 @@ elements.copyDebugPageUrlButton.addEventListener('click', () => {
|
|
|
6386
6506
|
elements.mobileLanSelect.addEventListener('change', () => {
|
|
6387
6507
|
void updateMobileQrCode();
|
|
6388
6508
|
});
|
|
6509
|
+
elements.networkPermissionSelect.addEventListener('change', () => {
|
|
6510
|
+
permissionState.networkRequest.status =
|
|
6511
|
+
elements.networkPermissionSelect.value === 'enabled' ? 'enabled' : 'disabled';
|
|
6512
|
+
rebuildRuntimeWithPermissions();
|
|
6513
|
+
});
|
|
6514
|
+
elements.officialDomainCheckbox.addEventListener('change', () => {
|
|
6515
|
+
permissionState.networkRequest.useOfficialDomain = elements.officialDomainCheckbox.checked;
|
|
6516
|
+
rebuildRuntimeWithPermissions();
|
|
6517
|
+
});
|
|
6518
|
+
elements.resetPermissionsButton.addEventListener('click', () => {
|
|
6519
|
+
permissionState = clonePermissionState(initialPermissionState);
|
|
6520
|
+
rebuildRuntimeWithPermissions();
|
|
6521
|
+
});
|
|
6389
6522
|
const mobileAppQrReady = setupMobileAppQr();
|
|
6523
|
+
function createRuntime() {
|
|
6524
|
+
return new MiniProgramMockRuntime(platformAdapter, {
|
|
6525
|
+
onAuthChange: (result) => postEvent('authChange', result),
|
|
6526
|
+
runtimePermissions: createMiniProgramMockRuntimePermissions(permissionState),
|
|
6527
|
+
});
|
|
6528
|
+
}
|
|
6529
|
+
function rebuildRuntimeWithPermissions() {
|
|
6530
|
+
runtime = createRuntime();
|
|
6531
|
+
updatePermissionControls();
|
|
6532
|
+
}
|
|
6533
|
+
function updatePermissionControls() {
|
|
6534
|
+
elements.devContextStatus.textContent =
|
|
6535
|
+
devContext.source === 'remote'
|
|
6536
|
+
? `已连接线上配置${devContext.miniProgramId ? ` · ${devContext.miniProgramId}` : ''}`
|
|
6537
|
+
: '匿名本地沙箱';
|
|
6538
|
+
elements.networkPermissionSelect.value = permissionState.networkRequest.status;
|
|
6539
|
+
elements.officialDomainCheckbox.checked = permissionState.networkRequest.useOfficialDomain;
|
|
6540
|
+
elements.officialDomainCheckbox.disabled = permissionState.networkRequest.status !== 'enabled';
|
|
6541
|
+
const diagnostics = createMiniProgramDevReleaseDiagnostics(devContext, permissionState);
|
|
6542
|
+
elements.releaseDiagnostics.innerHTML = diagnostics
|
|
6543
|
+
.map((diagnostic) => `<li>${escapeHtml(diagnostic.message)}</li>`)
|
|
6544
|
+
.join('');
|
|
6545
|
+
}
|
|
6546
|
+
function clonePermissionState(state) {
|
|
6547
|
+
return {
|
|
6548
|
+
networkRequest: { ...state.networkRequest },
|
|
6549
|
+
};
|
|
6550
|
+
}
|
|
6390
6551
|
function handleMessage(event) {
|
|
6391
6552
|
if (event.source !== iframe.contentWindow || !isBridgeMessage(event.data)) {
|
|
6392
6553
|
return;
|
|
@@ -6599,10 +6760,17 @@ async function loadMockHostBootstrap() {
|
|
|
6599
6760
|
});
|
|
6600
6761
|
const payload = await response.json();
|
|
6601
6762
|
if (!isRecord(payload)) {
|
|
6602
|
-
return {
|
|
6763
|
+
return {
|
|
6764
|
+
devContext: {
|
|
6765
|
+
source: 'anonymous',
|
|
6766
|
+
warning: 'dev context 响应格式无效。',
|
|
6767
|
+
},
|
|
6768
|
+
lanAddresses: [],
|
|
6769
|
+
};
|
|
6603
6770
|
}
|
|
6604
6771
|
return {
|
|
6605
6772
|
defaultLanAddressId: typeof payload.defaultLanAddressId === 'string' ? payload.defaultLanAddressId : undefined,
|
|
6773
|
+
devContext: readDevContext(payload.devContext, payload.runtimePermissions),
|
|
6606
6774
|
lanAddresses: Array.isArray(payload.lanAddresses) ? payload.lanAddresses.filter(isLanAddress) : [],
|
|
6607
6775
|
macAppProtocol: typeof payload.macAppProtocol === 'string' ? payload.macAppProtocol : undefined,
|
|
6608
6776
|
nativeAppLaunchUnavailableReason: typeof payload.nativeAppLaunchUnavailableReason === 'string'
|
|
@@ -6613,11 +6781,33 @@ async function loadMockHostBootstrap() {
|
|
|
6613
6781
|
}
|
|
6614
6782
|
catch {
|
|
6615
6783
|
return {
|
|
6784
|
+
devContext: {
|
|
6785
|
+
source: 'anonymous',
|
|
6786
|
+
warning: '真机调试配置加载失败,请重启 hb-sdk dev 后重试。',
|
|
6787
|
+
},
|
|
6616
6788
|
lanAddresses: [],
|
|
6617
6789
|
nativeAppLaunchUnavailableReason: '真机调试配置加载失败,请重启 hb-sdk dev 后重试。',
|
|
6618
6790
|
};
|
|
6619
6791
|
}
|
|
6620
6792
|
}
|
|
6793
|
+
function readDevContext(value, legacyRuntimePermissions) {
|
|
6794
|
+
if (isRecord(value) && value.source === 'remote') {
|
|
6795
|
+
return {
|
|
6796
|
+
source: 'remote',
|
|
6797
|
+
miniProgramId: typeof value.miniProgramId === 'string' ? value.miniProgramId : undefined,
|
|
6798
|
+
runtimePermissions: value.runtimePermissions ?? legacyRuntimePermissions,
|
|
6799
|
+
};
|
|
6800
|
+
}
|
|
6801
|
+
if (isRecord(value) && value.source === 'anonymous') {
|
|
6802
|
+
return {
|
|
6803
|
+
source: 'anonymous',
|
|
6804
|
+
warning: typeof value.warning === 'string' ? value.warning : undefined,
|
|
6805
|
+
};
|
|
6806
|
+
}
|
|
6807
|
+
return legacyRuntimePermissions === undefined
|
|
6808
|
+
? { source: 'anonymous', warning: '未获取到 dev context。' }
|
|
6809
|
+
: { source: 'remote', runtimePermissions: legacyRuntimePermissions };
|
|
6810
|
+
}
|
|
6621
6811
|
function setupMobileLanSelect() {
|
|
6622
6812
|
elements.mobileLanSelect.innerHTML = '';
|
|
6623
6813
|
lanAddresses.forEach((address) => {
|
package/dist/index.cjs.js
CHANGED
package/dist/index.esm.js
CHANGED
package/dist/vite.cjs.js
CHANGED
package/dist/vite.esm.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@heybox/hb-sdk",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.4-alpha.0",
|
|
4
4
|
"sideEffects": [
|
|
5
5
|
"./src/index.ts",
|
|
6
6
|
"./src/core/singleton.ts",
|
|
@@ -92,7 +92,7 @@
|
|
|
92
92
|
"vue": "^2.7.16",
|
|
93
93
|
"vite": "^8.0.12",
|
|
94
94
|
"vitest": "^3.2.4",
|
|
95
|
-
"@heybox/hb-api": "~1.25.
|
|
95
|
+
"@heybox/hb-api": "~1.25.3"
|
|
96
96
|
},
|
|
97
97
|
"publishConfig": {
|
|
98
98
|
"registry": "https://registry.npmjs.org/",
|
package/skill/SKILL.md
CHANGED
|
@@ -49,7 +49,7 @@ Apply these instructions when writing, reviewing, or debugging code that consume
|
|
|
49
49
|
## Step 5: Use CLI workflows
|
|
50
50
|
|
|
51
51
|
1. Use `hb-sdk create <project-name>` to scaffold a standalone external mini-program template.
|
|
52
|
-
2. Use `hb-sdk dev` for local browser debugging through the built-in mock runtime host.
|
|
52
|
+
2. Use `hb-sdk dev` for local browser, Mac App, or mobile App debugging through the built-in mock runtime host. Vite and native dev-shell entrypoints only require the local `mini_url`: a missing project binding, CLI login, remote dev-context failure, or the 3-second context timeout must fall back to an anonymous local sandbox instead of blocking startup. Anonymous mode denies managed capabilities by default. When a verified remote dev context is available, the Mock Host uses its Runtime permission snapshot as the initial local simulation and reports local-versus-online permission differences.
|
|
53
53
|
3. Use `hb-sdk remote ...` for developer-owned remote mini-program management. Top-level `hb-sdk deploy` has been hard-cut and must not be recommended as a compatibility alias.
|
|
54
54
|
4. Use `hb-sdk remote entity list`, `hb-sdk remote entity current`, and `hb-sdk remote entity switch <entity-id>` to inspect or change the developer platform server-side current entity before remote management commands.
|
|
55
55
|
5. Use `hb-sdk remote create` to create a remote mini-program under the server-side current entity and bind the returned id into `package.json.heybox.miniProgramId`; use `hb-sdk remote bind <mini-program-id>` to bind an existing remote mini-program after current-entity manageability is verified. CLI project configuration contains only `package.json.heybox.miniProgramId`; mini-program name, icon, and cover images are maintained on the Open platform version-publish flow. On first submit without prior approved profile, the server injects a default name and default images.
|
|
@@ -64,7 +64,7 @@ Apply these instructions when writing, reviewing, or debugging code that consume
|
|
|
64
64
|
14. Add `--verbose` / `-v` only when diagnosing failures; default CLI errors are intentionally concise, while verbose output includes backend envelope, HTTP status, trace fields, raw body, or original submit-audit failure details.
|
|
65
65
|
15. Use `--json` for script consumption of `hb-sdk remote` commands. With `--json`, stdout must contain exactly one JSON object; progress, warnings, update reminders, and verbose diagnostics must not pollute stdout.
|
|
66
66
|
16. Do not expect custom base URLs to affect `hb-sdk doctor`, npm latest checks, or mock-host `network.request()`.
|
|
67
|
-
17. Use the Mock runtime host's "在 Mac 版 APP 中启动" button for Mac App debugging, or the "Mobile App" QR code after selecting a LAN interface for phone App debugging;
|
|
67
|
+
17. Use the Mock runtime host's "在 Mac 版 APP 中启动" button for Mac App debugging, or the "Mobile App" QR code after selecting a LAN interface for phone App debugging; these entrypoints remain available in anonymous mode. The phone must be on the same LAN and use a Heybox App version that supports the mini-program dev shell.
|
|
68
68
|
18. Use `--port`, `--mock-port`, and `--no-open` when the default Vite/mock ports or browser opening behavior need to be controlled.
|
|
69
69
|
19. Use `hb-sdk login`, `hb-sdk login status`, and `hb-sdk login clear` only for the CLI's own Heybox auth cache. Keep `hb-sdk login` top-level; it is not a remote mini-program command.
|
|
70
70
|
20. Treat `selectedEntity` in the CLI auth cache as a non-authoritative hint snapshot only. Every remote command must use the server-side current entity as the source of truth.
|
|
@@ -93,6 +93,8 @@ For CLI and local development:
|
|
|
93
93
|
2. Do not use `hb-sdk login` as a workaround for iframe SDK authentication.
|
|
94
94
|
3. Do not bypass `hb-sdk dev` by adding a second browser mock host.
|
|
95
95
|
4. Keep the Vite `miniappManifest()` plugin enabled so builds only start in a compatible APP Runtime. Normal deploy always runs the project build.
|
|
96
|
+
5. Keep Mock Host permission overrides in devtools-only memory. They must not rebuild the iframe, interrupt Vite HMR, mutate online permissions, or be passed through URL query parameters.
|
|
97
|
+
6. Treat remote dev context as optional diagnostics and initialization data. Do not use a public mini-program detail request as a dev startup gate.
|
|
96
98
|
|
|
97
99
|
For host/runtime/protocol-maintenance code:
|
|
98
100
|
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
## Package metadata
|
|
20
20
|
|
|
21
21
|
- Package: `@heybox/hb-sdk`
|
|
22
|
-
- Version at generation time: `0.6.
|
|
22
|
+
- Version at generation time: `0.6.4-alpha.0`
|
|
23
23
|
- Public root export: `@heybox/hb-sdk`
|
|
24
24
|
- Protocol export: `@heybox/hb-sdk/protocol`
|
|
25
25
|
- Vite plugin export: `@heybox/hb-sdk/vite`
|
|
@@ -450,7 +450,9 @@ SDK 需要在黑盒小程序 iframe 容器内运行。父容器会为页面注
|
|
|
450
450
|
npm run dev
|
|
451
451
|
```
|
|
452
452
|
|
|
453
|
-
调试页会通过 iframe 加载本地页面并补齐小程序 bridge
|
|
453
|
+
调试页会通过 iframe 加载本地页面并补齐小程序 bridge 环境。`hb-sdk dev` 的基础启动只依赖本地页面地址:即使项目未绑定、CLI 未登录或远端暂时不可用,浏览器 Mock、Mac 启动协议和手机二维码也会继续生成,真机 dev shell 以匿名本地沙箱加载 `mini_url`,不会把公开 `detail` 查询作为启动门禁。项目已绑定时会限时 3 秒读取远端 dev context;成功后 Mock Host 用真实 Runtime 权限快照初始化本地模拟,失败或超时则显示脱敏警告,并默认拒绝 `network.request` 等受管能力。
|
|
454
|
+
|
|
455
|
+
Mock Host 可以在内存中调整 devtools-only 权限模拟,不会重建 iframe,因此不影响 Vite HMR;本地设置不会修改线上权限。调试页会对比已读取的线上快照,提示本地放开但上线后会返回 `PERMISSION_DENIED` 的差异。权限快照只通过 mock host 的同源只读 bootstrap 接口传递,URL query 不能提供或覆盖权限。真实容器加载开发 `mini_url` 前会提示“即将打开未经验证的开发网页。该页面可能由本机或局域网服务提供,请确认来源可信后继续。”,用户确认后才继续加载。Codex、VSCode 等内嵌浏览器可能无法唤起系统 APP;遇到这种情况时,请在系统浏览器中打开同一个调试页后重试。
|
|
454
456
|
|
|
455
457
|
在未使用脚手架的 Vite 项目中,可以把命令加到 `package.json`:
|
|
456
458
|
|
package/skill/references/cli.md
CHANGED
|
@@ -103,7 +103,7 @@ Agent rules:
|
|
|
103
103
|
hb-sdk dev
|
|
104
104
|
```
|
|
105
105
|
|
|
106
|
-
`hb-sdk dev` 会从当前目录向上查找最近的 `package.json
|
|
106
|
+
`hb-sdk dev` 会从当前目录向上查找最近的 `package.json`。Vite、内置 mock runtime host、Mac 启动协议和手机二维码的基础启动只依赖本地页面地址,不要求项目先绑定或 CLI 先登录。项目已绑定时,CLI 会限时 3 秒读取远端 dev context;成功后用真实 Runtime 权限快照初始化 Mock Host,失败或超时则输出脱敏警告并继续匿名调试,`network.request` 等受管能力默认拒绝。公开 `detail` 查询不再是 dev 启动门禁。本地 `package.json` 无法解析等配置错误不会被降级,命令会直接报错。调试页默认自动打开;需要真实黑盒小程序容器加载同一页面时,点击调试页里的「在 Mac 版 APP 中启动」按钮,或在「Mobile App」区域选择局域网网卡后用手机小黑盒 APP 扫码。
|
|
107
107
|
|
|
108
108
|
常用参数:
|
|
109
109
|
|
|
@@ -116,11 +116,13 @@ hb-sdk dev
|
|
|
116
116
|
|
|
117
117
|
## Mock runtime 边界
|
|
118
118
|
|
|
119
|
-
`hb-sdk dev` 会把实际小程序页面地址编码到 mock host 的 `mini_url` query 中,由 mock host iframe 加载页面并补齐小程序 bridge
|
|
119
|
+
`hb-sdk dev` 会把实际小程序页面地址编码到 mock host 的 `mini_url` query 中,由 mock host iframe 加载页面并补齐小程序 bridge 环境。Mac 协议和手机二维码始终携带本地页面地址;远端 dev context 可用时还会携带已验证的小程序 ID,不可用时则进入匿名本地沙箱。真机 dev shell 不依赖公开 `detail` 查询完成启动。真实 Mac / Mobile App dev shell 加载开发 `mini_url` 前会提示“即将打开未经验证的开发网页。该页面可能由本机或局域网服务提供,请确认来源可信后继续。”,用户确认后才继续加载。Codex、VSCode 等内嵌浏览器可能无法唤起系统 APP;遇到这种情况时,请在系统浏览器中打开同一个调试页后重试。
|
|
120
120
|
|
|
121
121
|
不要为了本地调试再创建独立 mock runtime 包。CLI、模板和 mock host 都归属 `@heybox/hb-sdk`。
|
|
122
122
|
|
|
123
|
-
|
|
123
|
+
浏览器 Mock 的权限状态只存在于 Mock Host 内存中,URL query 不能提供或覆盖权限。远端 dev context 可用时,Mock Host 以线上快照作为初始值;不可用时匿名状态默认拒绝受管能力。开发者可以在调试页临时调整 `network.request` 和官方域名权限,变更只会重建 devtools-only mock runtime,不会重建 iframe 或中断 Vite HMR,也不会修改线上配置。调试页会对比线上快照并提示本地放开但上线后会返回 `PERMISSION_DENIED` 的差异。
|
|
124
|
+
|
|
125
|
+
本地 mock runtime 下已授权的 `network.request()` 会通过 `hb-sdk` 本地 mock network proxy 转发真实 HTTP(S) 请求,用于避免浏览器 CORS 影响本地调试。proxy 不会把黑盒客户端私有协议字段暴露给 iframe 业务代码。CLI 登录态和远端 dev context 也不会注入 iframe。
|
|
124
126
|
|
|
125
127
|
Use `hb-sdk dev` for local browser SDK debugging. Use the Mock runtime host's "在 Mac 版 APP 中启动" button for Mac App debugging, or the "Mobile App" QR code after selecting a LAN interface for phone App debugging. The phone must be on the same LAN and use a Heybox App version that supports the mini-program dev shell. If the mock host is open inside Codex, VSCode, or another embedded browser, ask the user to open the same debug page in the system browser before retrying because embedded browsers may block the `heybox://` protocol handoff.
|
|
126
128
|
|
package/skill/skill.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hb-sdk",
|
|
3
|
-
"skillVersion": "0.6.
|
|
3
|
+
"skillVersion": "0.6.4-alpha.0+skill.20921fb44039",
|
|
4
4
|
"sdk": {
|
|
5
5
|
"package": "@heybox/hb-sdk",
|
|
6
|
-
"version": "0.6.
|
|
7
|
-
"compatibility": "0.6.
|
|
6
|
+
"version": "0.6.4-alpha.0",
|
|
7
|
+
"compatibility": "0.6.4-alpha.0"
|
|
8
8
|
},
|
|
9
9
|
"source": "https://open.xiaoheihe.cn/agent-skills/hb-sdk",
|
|
10
|
-
"integrity": "sha256-
|
|
10
|
+
"integrity": "sha256-20921fb44039d21908fb692fc7d593c1dbc3b4f5dfa8f36f24aa0258ce150d13"
|
|
11
11
|
}
|