@heybox/hb-sdk 0.9.6-alpha.1 → 0.9.6-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.
- package/CHANGELOG.md +79 -5
- package/README.md +35 -559
- package/dist/cli-chunks/{artifact-C5n7xjnz.cjs → artifact-BaZzEQjq.cjs} +3 -3
- package/dist/cli-chunks/{build-BgBt5SkX.cjs → build-Ykhw1sz9.cjs} +8 -6
- package/dist/cli-chunks/{create-BL6uwtkQ.cjs → create-BEjKsD1y.cjs} +3 -1
- package/dist/cli-chunks/{dev-NgklQb6b.cjs → dev-DpkBN4ir.cjs} +9613 -616
- package/dist/cli-chunks/{dev-context-Tf8MgSsu.cjs → dev-context-B3Y_EcXC.cjs} +4 -6
- package/dist/cli-chunks/{doctor-CGlEf1yi.cjs → doctor-DPELjB83.cjs} +3 -1
- package/dist/cli-chunks/{games-Cc-DclmK.cjs → games-D2hnnWKY.cjs} +3 -1
- package/dist/cli-chunks/{index-D9XLBbNV.cjs → index-DCj9vtVv.cjs} +1 -1
- package/dist/cli-chunks/{index-CmxsiTTn.cjs → index-DIgSsTuu.cjs} +1754 -120
- package/dist/cli-chunks/index.esm-t29GC7yg.cjs +154 -0
- package/dist/cli-chunks/{login-ZMBDHBuA.cjs → login-C5XmcbRa.cjs} +3 -3
- package/dist/cli-chunks/{project-vite-eM87vX9L.cjs → project-vite-B12EMgRq.cjs} +3 -18
- package/dist/cli-chunks/{remote-DVhxpWDg.cjs → remote-lFAA88Zl.cjs} +12 -21
- package/dist/cli-chunks/{runtime-permission-env-q1FWWwbV.cjs → runtime-permission-env-CYbLBtWo.cjs} +61 -12
- package/dist/cli-chunks/{skill-mRXM87hY.cjs → skill-AilHsggi.cjs} +3 -2
- package/dist/cli-chunks/{version-BqHRI4Lz.cjs → version-KZTUyIiC.cjs} +1 -1
- package/dist/cli.cjs +3 -1
- package/dist/dev.cjs +1358 -0
- package/dist/dev.mjs +1356 -0
- package/dist/devtools/browser-dev-host/assets/browser-dev-host-C0_lx52X.js +100 -0
- package/dist/devtools/browser-dev-host/assets/desktop-app-launch-CPk4dD63.js +6 -0
- package/dist/devtools/browser-dev-host/assets/index-BzOC7Q8l.js +586 -0
- package/dist/devtools/browser-dev-host/assets/index-CHYEXFEg.css +1 -0
- package/dist/devtools/browser-dev-host/index.html +3 -3
- package/dist/index.cjs.js +60 -112
- package/dist/index.esm.js +60 -112
- package/dist/miniapp-publish.cjs.js +1 -1
- package/dist/miniapp-publish.esm.js +1 -1
- package/dist/vite.cjs.js +1059 -202
- package/dist/vite.esm.js +1060 -203
- package/docs/device-logs.md +39 -22
- package/package.json +23 -10
- package/skill/skill.json +4 -4
- package/types/dev/index.d.cts +386 -0
- package/types/dev/index.d.mts +386 -0
- package/types/dev/vendor/playwright-core/LICENSE +202 -0
- package/types/dev/vendor/playwright-core/NOTICE +5 -0
- package/types/dev/vendor/playwright-core/UPSTREAM.json +5 -0
- package/types/dev/vendor/playwright-core/types/protocol.d.ts +24776 -0
- package/types/dev/vendor/playwright-core/types/structs.d.ts +52 -0
- package/types/dev/vendor/playwright-core/types/types.d.ts +27167 -0
- package/types/index.d.ts +12 -4
- package/types/protocol.d.ts +3 -2
- package/types/vite/index.d.ts +5 -4
- package/dist/cli-chunks/index.esm-DnyLP_Zc.cjs +0 -5216
- package/dist/devtools/browser-dev-host/assets/browser-dev-host-DtWOjzCe.js +0 -103
- package/dist/devtools/browser-dev-host/assets/desktop-app-launch-C2Vw0-AC.js +0 -6
- package/dist/devtools/browser-dev-host/assets/index-B-rjfibN.js +0 -567
- package/dist/devtools/browser-dev-host/assets/index-DSTlrpnQ.css +0 -1
- package/docs/runtime-host-migration.md +0 -128
package/dist/index.esm.js
CHANGED
|
@@ -252,7 +252,7 @@ function redactUrlSearchParams(params) {
|
|
|
252
252
|
return changed;
|
|
253
253
|
}
|
|
254
254
|
function redactSensitivePairsInRawText(text) {
|
|
255
|
-
return text.replace(/([?&#]|^|[?&])([^=&#\s]+)=([^&#\s]*)/g, (full, prefix, key
|
|
255
|
+
return text.replace(/([?&#]|^|[?&])([^=&#\s]+)=([^&#\s]*)/g, (full, prefix, key) => {
|
|
256
256
|
if (!isSensitiveNetworkKey(key)) {
|
|
257
257
|
return full;
|
|
258
258
|
}
|
|
@@ -7505,7 +7505,7 @@ function createMessageId() {
|
|
|
7505
7505
|
/** 构建时替换为当前发布包的实际版本。 */
|
|
7506
7506
|
const HB_SDK_VERSION = typeof undefined === 'string'
|
|
7507
7507
|
? undefined
|
|
7508
|
-
: '0.9.6-alpha.
|
|
7508
|
+
: '0.9.6-alpha.10';
|
|
7509
7509
|
|
|
7510
7510
|
const RUNTIME_MODES = new Set(['production', 'preview', 'development', 'unknown']);
|
|
7511
7511
|
const OPERATING_SYSTEM_NAMES = new Set(['android', 'ios', 'ohos', 'windows', 'macos', 'linux', 'unknown']);
|
|
@@ -7635,18 +7635,52 @@ class MiniProgramBridgeClient {
|
|
|
7635
7635
|
}
|
|
7636
7636
|
/** 调用父容器开放能力。 */
|
|
7637
7637
|
async request(method, ...args) {
|
|
7638
|
-
|
|
7639
|
-
const result = await this.performRequest(method, args[0], !HOST_MANAGED_TIMEOUT_METHODS.has(method));
|
|
7640
|
-
if (method === 'auth.getAccountState' && accountVersion !== this.accountEventVersion) {
|
|
7641
|
-
throw createSDKError('AUTHORIZATION_CONTEXT_CHANGED', '读取期间账号状态发生变化,请保留较新的事件状态');
|
|
7642
|
-
}
|
|
7643
|
-
return result;
|
|
7638
|
+
return this.performRequest(method, args[0], !HOST_MANAGED_TIMEOUT_METHODS.has(method), undefined, true);
|
|
7644
7639
|
}
|
|
7645
7640
|
/** 发起不使用固定总时长 timer 的长操作。 */
|
|
7646
7641
|
async requestOperation(method, payload, options = {}) {
|
|
7647
7642
|
return this.performRequest(method, payload, false, options);
|
|
7648
7643
|
}
|
|
7649
|
-
async performRequest(method, payload, useTimeout, options = {}) {
|
|
7644
|
+
async performRequest(method, payload, useTimeout, options = {}, validateAccountState = false) {
|
|
7645
|
+
const id = createMessageId();
|
|
7646
|
+
// 接收端仅由开发 HTML 安装;读取和回调均隔离,不改变业务结果。
|
|
7647
|
+
let observer;
|
|
7648
|
+
try {
|
|
7649
|
+
const candidate = this.selfWindow?.__hbSdkDevObserver;
|
|
7650
|
+
if (typeof candidate === 'function')
|
|
7651
|
+
observer = candidate;
|
|
7652
|
+
}
|
|
7653
|
+
catch { /* 自定义 Window 的访问器也不能阻断请求。 */ }
|
|
7654
|
+
if (!observer)
|
|
7655
|
+
return this.executeRequest(id, method, payload, useTimeout, options, validateAccountState);
|
|
7656
|
+
const startedAt = Date.now();
|
|
7657
|
+
const startedMonotonic = diagnosticNow();
|
|
7658
|
+
const report = (outcome, error) => {
|
|
7659
|
+
try {
|
|
7660
|
+
const errorCode = error instanceof HbMiniProgramSDKError ? error.code : undefined;
|
|
7661
|
+
observer({ phase: 'client', method, callId: id, outcome, timestamp: Date.now(), startedAt,
|
|
7662
|
+
durationMs: Math.max(0, diagnosticNow() - startedMonotonic), ...(errorCode ? { errorCode } : {}) });
|
|
7663
|
+
}
|
|
7664
|
+
catch { /* 调试观察不得影响 SDK 调用。 */ }
|
|
7665
|
+
};
|
|
7666
|
+
report('started');
|
|
7667
|
+
try {
|
|
7668
|
+
const value = await this.executeRequest(id, method, payload, useTimeout, options, validateAccountState);
|
|
7669
|
+
report('success');
|
|
7670
|
+
return value;
|
|
7671
|
+
}
|
|
7672
|
+
catch (error) {
|
|
7673
|
+
let cancelled = false;
|
|
7674
|
+
try {
|
|
7675
|
+
cancelled = error instanceof HbMiniProgramSDKError && (error.code === 'REQUEST_CANCELLED' || error.code === 'OPERATION_CANCELLED');
|
|
7676
|
+
}
|
|
7677
|
+
catch { /* 自定义拒绝值可包含抛错的 Proxy,仍须保留原拒绝值。 */ }
|
|
7678
|
+
report(cancelled || options.signal?.aborted ? 'cancelled' : 'error', error);
|
|
7679
|
+
throw error;
|
|
7680
|
+
}
|
|
7681
|
+
}
|
|
7682
|
+
async executeRequest(id, method, payload, useTimeout, options, validateAccountState) {
|
|
7683
|
+
const accountVersion = this.accountEventVersion;
|
|
7650
7684
|
if (this.destroyed) {
|
|
7651
7685
|
throw createSDKError('SDK_DESTROYED', '小程序 SDK 已销毁');
|
|
7652
7686
|
}
|
|
@@ -7676,7 +7710,6 @@ class MiniProgramBridgeClient {
|
|
|
7676
7710
|
if (options.signal?.aborted) {
|
|
7677
7711
|
throw options.createAbortError?.() ?? createSDKError('REQUEST_CANCELLED', `${method} 已取消`);
|
|
7678
7712
|
}
|
|
7679
|
-
const id = createMessageId();
|
|
7680
7713
|
const message = {
|
|
7681
7714
|
namespace: MINI_PROGRAM_MESSAGE_NAMESPACE,
|
|
7682
7715
|
version: MINI_PROGRAM_MESSAGE_VERSION,
|
|
@@ -7686,18 +7719,7 @@ class MiniProgramBridgeClient {
|
|
|
7686
7719
|
method,
|
|
7687
7720
|
payload,
|
|
7688
7721
|
};
|
|
7689
|
-
const
|
|
7690
|
-
const report = (outcome, error) => {
|
|
7691
|
-
if (typeof false === 'undefined' || !false)
|
|
7692
|
-
return;
|
|
7693
|
-
try {
|
|
7694
|
-
const target = this.selfWindow;
|
|
7695
|
-
const errorCode = error instanceof HbMiniProgramSDKError ? error.code : undefined;
|
|
7696
|
-
target?.__hbSdkDeviceLog?.({ method, callId: id, outcome, durationMs: Date.now() - startedAt, errorCode });
|
|
7697
|
-
}
|
|
7698
|
-
catch { /* 调试输出不能改变 SDK 调用结果。 */ }
|
|
7699
|
-
};
|
|
7700
|
-
return new Promise((resolve, reject) => {
|
|
7722
|
+
const result = await new Promise((resolve, reject) => {
|
|
7701
7723
|
const pending = {
|
|
7702
7724
|
resolve: resolve,
|
|
7703
7725
|
reject,
|
|
@@ -7745,7 +7767,11 @@ class MiniProgramBridgeClient {
|
|
|
7745
7767
|
pending.abortHandler();
|
|
7746
7768
|
}
|
|
7747
7769
|
}
|
|
7748
|
-
})
|
|
7770
|
+
});
|
|
7771
|
+
if (validateAccountState && method === 'auth.getAccountState' && accountVersion !== this.accountEventVersion) {
|
|
7772
|
+
throw createSDKError('AUTHORIZATION_CONTEXT_CHANGED', '读取期间账号状态发生变化,请保留较新的事件状态');
|
|
7773
|
+
}
|
|
7774
|
+
return result;
|
|
7749
7775
|
}
|
|
7750
7776
|
/** 销毁 SDK 实例,并拒绝尚未完成的请求。 */
|
|
7751
7777
|
destroy() {
|
|
@@ -8072,6 +8098,10 @@ function waitForHandshakeOrAbort(handshake, signal, createAbortError, getTermina
|
|
|
8072
8098
|
onAbort();
|
|
8073
8099
|
});
|
|
8074
8100
|
}
|
|
8101
|
+
/** 诊断耗时独立于墙钟校时。 */
|
|
8102
|
+
function diagnosticNow() {
|
|
8103
|
+
return typeof performance === 'undefined' ? Date.now() : performance.now();
|
|
8104
|
+
}
|
|
8075
8105
|
|
|
8076
8106
|
/**
|
|
8077
8107
|
* 获取短期授权码。
|
|
@@ -11385,13 +11415,18 @@ function getFollowStatus(requester) {
|
|
|
11385
11415
|
*
|
|
11386
11416
|
* @throws {@link HbMiniProgramSDKError} `userInfo` 未声明或不可用、握手失败、Host 不支持该能力、
|
|
11387
11417
|
* 当前小程序身份缺失、账号/隔离身份读取失败、返回结构不合法、Runtime 终止,或请求期间
|
|
11388
|
-
*
|
|
11418
|
+
* 账号与授权上下文变化时抛出。第三方联网小程序的身份读取返回 `SERVER_API_REQUIRED`。
|
|
11389
11419
|
*
|
|
11390
11420
|
* @remarks
|
|
11421
|
+
* **网络权限决定用户信息的读取入口:`local` 模式使用本方法;联网的 `server` 模式
|
|
11422
|
+
* 使用 `auth.login()` 与服务端换票,调用本方法读取身份会返回 `SERVER_API_REQUIRED`。**
|
|
11423
|
+
*
|
|
11391
11424
|
* 当前账号未登录属于正常返回分支,不抛错。账号已登录时,该能力不展示授权 UI,也不要求
|
|
11392
11425
|
* 可信用户手势;Runtime 会静默建立或读取当前小程序的隔离 `app_user_id`,并授予
|
|
11393
11426
|
* `identity` 与 `profile`。它只要求 Manifest 中声明 `userInfo`,不要求公开 `network`
|
|
11394
|
-
*
|
|
11427
|
+
* 权限,也不返回可供服务端换票的授权码。第三方小程序在启用网络权限的 `server` 模式下
|
|
11428
|
+
* 会以 `SERVER_API_REQUIRED` 拒绝身份读取,应改用 `auth.login()` 并由开发者服务端换票;
|
|
11429
|
+
* `local` 与兼容 `legacy` 模式保留直接读取能力。
|
|
11395
11430
|
*
|
|
11396
11431
|
* @example
|
|
11397
11432
|
* ```ts
|
|
@@ -11816,94 +11851,7 @@ function createMiniProgramSDK(options) {
|
|
|
11816
11851
|
return new MiniProgramSDK(options);
|
|
11817
11852
|
}
|
|
11818
11853
|
|
|
11819
|
-
/**
|
|
11820
|
-
* iframe 与调试台页面的开发期 console 捕获转发。
|
|
11821
|
-
*
|
|
11822
|
-
* 双条件门控(iframe 转发):
|
|
11823
|
-
* 1. 构建期:`hb-sdk dev`(vite serve)注入 `false`;`hb-sdk build` /
|
|
11824
|
-
* `vite build`(生产)永不注入或替换为 `false`,本模块被死代码消除。
|
|
11825
|
-
* 2. 运行期:仅在 `window.name` 为 `__hb_sdk_mini_dev__` 的调试 iframe 中激活,
|
|
11826
|
-
* 用户设备上的正式运行环境没有该标记。
|
|
11827
|
-
*
|
|
11828
|
-
* 无侵入 patch `console.log/debug/info/warn/error`:原样放行(DevTools 不受影响)+
|
|
11829
|
-
* 通过 `window.parent.postMessage` 转发给调试台(CSP 的 connect-src 不约束 postMessage,
|
|
11830
|
-
* 网络上报由调试台页面代理)。发送全程静默:失败不得回打 console,避免自触发死循环。
|
|
11831
|
-
*
|
|
11832
|
-
* 激活时机:由 SDK 默认单例初始化时调用(业务 `import '@heybox/hb-sdk'` 即生效);
|
|
11833
|
-
* iframe 标记由调试台 `iframe.name` 与 vite dev 注入的无依赖 bootstrap 共同设置。
|
|
11834
|
-
* 调试台页面自身(runtime 跑在这里,`[hb-sdk-runtime]` 日志不经过 iframe)另用
|
|
11835
|
-
* `installMiniDevConsoleSelfCapture` 接入「日志」页签(source: 'host')。
|
|
11836
|
-
*/
|
|
11837
|
-
const MINI_DEV_IFRAME_WINDOW_NAME = '__hb_sdk_mini_dev__';
|
|
11838
|
-
const MINI_DEV_CONSOLE_EVENT_TYPE = 'hb-sdk:mini-dev-console';
|
|
11839
|
-
/** 调试台页面与 iframe bootstrap 共用的已安装标记(window/console 上的属性名)。 */
|
|
11840
|
-
const MINI_DEV_CONSOLE_INSTALL_FLAG = '__hb_sdk_mini_dev_console_installed__';
|
|
11841
|
-
/** 调试台页面自捕获(source: 'host')与 iframe 转发共用的已安装标记。 */
|
|
11842
|
-
const INSTALL_FLAG = MINI_DEV_CONSOLE_INSTALL_FLAG;
|
|
11843
|
-
function isDevLoggingEnabled() {
|
|
11844
|
-
if (typeof false !== 'undefined' && false !== true) {
|
|
11845
|
-
return false;
|
|
11846
|
-
}
|
|
11847
|
-
return typeof window !== 'undefined' && window.name === MINI_DEV_IFRAME_WINDOW_NAME;
|
|
11848
|
-
}
|
|
11849
|
-
const levels = ['log', 'debug', 'info', 'warn', 'error'];
|
|
11850
|
-
function patchConsoleLevels(consoleRef, deliver, owner) {
|
|
11851
|
-
if (!owner || owner[INSTALL_FLAG] === true) {
|
|
11852
|
-
return false;
|
|
11853
|
-
}
|
|
11854
|
-
let patched = false;
|
|
11855
|
-
for (const level of levels) {
|
|
11856
|
-
const original = consoleRef[level];
|
|
11857
|
-
if (typeof original !== 'function') {
|
|
11858
|
-
continue;
|
|
11859
|
-
}
|
|
11860
|
-
const forward = function (...args) {
|
|
11861
|
-
try {
|
|
11862
|
-
deliver(level, args);
|
|
11863
|
-
}
|
|
11864
|
-
catch {
|
|
11865
|
-
/* 转发失败必须静默,禁止回打 console 造成自触发循环。 */
|
|
11866
|
-
}
|
|
11867
|
-
return original.apply(this, args);
|
|
11868
|
-
};
|
|
11869
|
-
try {
|
|
11870
|
-
consoleRef[level] = forward;
|
|
11871
|
-
patched = true;
|
|
11872
|
-
}
|
|
11873
|
-
catch {
|
|
11874
|
-
return patched;
|
|
11875
|
-
}
|
|
11876
|
-
}
|
|
11877
|
-
if (patched) {
|
|
11878
|
-
owner[INSTALL_FLAG] = true;
|
|
11879
|
-
}
|
|
11880
|
-
return patched;
|
|
11881
|
-
}
|
|
11882
|
-
function installMiniDevConsoleForwarding(consoleRef = console) {
|
|
11883
|
-
if (!isDevLoggingEnabled()) {
|
|
11884
|
-
return;
|
|
11885
|
-
}
|
|
11886
|
-
patchConsoleLevels(consoleRef, (level, args) => {
|
|
11887
|
-
const message = {
|
|
11888
|
-
type: MINI_DEV_CONSOLE_EVENT_TYPE,
|
|
11889
|
-
detail: { level, args, timestamp: Date.now() },
|
|
11890
|
-
};
|
|
11891
|
-
window.parent?.postMessage(message, '*');
|
|
11892
|
-
}, typeof window === 'undefined' ? undefined : window);
|
|
11893
|
-
}
|
|
11894
|
-
|
|
11895
11854
|
let defaultSDK = createMiniProgramSDK();
|
|
11896
|
-
if (typeof false !== 'undefined' && false && typeof window !== 'undefined') {
|
|
11897
|
-
window.__hbSdkSandboxList = async (path) => (await getDefaultSDK().files.sandbox.directory(path).list({ limit: 200 })).map((entry) => ({ name: entry.name, kind: entry.kind }));
|
|
11898
|
-
}
|
|
11899
|
-
// 开发期调试台 console 捕获:双条件门控(vite serve 注入 define + 调试 iframe 标记),
|
|
11900
|
-
// 生产构建被死代码消除,正式环境无副作用。失败静默,绝不影响 SDK 初始化。
|
|
11901
|
-
try {
|
|
11902
|
-
installMiniDevConsoleForwarding();
|
|
11903
|
-
}
|
|
11904
|
-
catch {
|
|
11905
|
-
/* 捕获层异常不得阻断 SDK 单例创建。 */
|
|
11906
|
-
}
|
|
11907
11855
|
function getDefaultSDK() {
|
|
11908
11856
|
if (!defaultSDK) {
|
|
11909
11857
|
defaultSDK = createMiniProgramSDK();
|
|
@@ -32,7 +32,7 @@ const MINI_PROGRAM_PERMISSION_CATALOG = [
|
|
|
32
32
|
risk: 'high',
|
|
33
33
|
config: {},
|
|
34
34
|
methods: ['gameSaves.list', 'gameSaves.sync', 'gameSaves.getFile', 'gameSaves.readParsedData'],
|
|
35
|
-
conditions: ['
|
|
35
|
+
conditions: ['需声明权限并校验当前 Steam 账号,无需额外授权弹窗;可读取受支持游戏已有的完整结构化数据,不触发解析。同步需有效 Steam 登录,文件下载另需宿主支持文件读取。'],
|
|
36
36
|
},
|
|
37
37
|
{
|
|
38
38
|
key: 'userInfo',
|
|
@@ -30,7 +30,7 @@ const MINI_PROGRAM_PERMISSION_CATALOG = [
|
|
|
30
30
|
risk: 'high',
|
|
31
31
|
config: {},
|
|
32
32
|
methods: ['gameSaves.list', 'gameSaves.sync', 'gameSaves.getFile', 'gameSaves.readParsedData'],
|
|
33
|
-
conditions: ['
|
|
33
|
+
conditions: ['需声明权限并校验当前 Steam 账号,无需额外授权弹窗;可读取受支持游戏已有的完整结构化数据,不触发解析。同步需有效 Steam 登录,文件下载另需宿主支持文件读取。'],
|
|
34
34
|
},
|
|
35
35
|
{
|
|
36
36
|
key: 'userInfo',
|