@heybox/hb-sdk 0.8.3-alpha.2 → 0.8.3-alpha.4
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 +32 -0
- package/README.md +45 -7
- package/dist/cli-chunks/{build-lnIkF-rf.cjs → build-CkPA6jAR.cjs} +5 -5
- package/dist/cli-chunks/{context-DAdousk7.cjs → context-DoVGwJek.cjs} +35 -8
- package/dist/cli-chunks/{create-BrH3TKd9.cjs → create-vFF2Au_f.cjs} +1 -1
- package/dist/cli-chunks/{dev-Dazm6mjQ.cjs → dev-5lkHU1uv.cjs} +194 -73
- package/dist/cli-chunks/{doctor-Dqju9vZQ.cjs → doctor-DFt0LWou.cjs} +1 -1
- package/dist/cli-chunks/{index-ZxzVU017.cjs → index-CguXMrgP.cjs} +2 -2
- package/dist/cli-chunks/{index-Cscd6hCr.cjs → index-Ol4wxcob.cjs} +15 -15
- package/dist/cli-chunks/{index.esm-BPF3ML9J.cjs → index.esm-DUvvFi-Z.cjs} +7 -7
- package/dist/cli-chunks/{login-CR8vCqdL.cjs → login-CA5BhdXd.cjs} +2 -2
- package/dist/cli-chunks/{project-vite-C0fvgvWp.cjs → project-vite-P09pYZoU.cjs} +1 -1
- package/dist/cli-chunks/{remote-CZBw05sT.cjs → remote-DU0f2mlK.cjs} +36 -9
- package/dist/cli-chunks/{runtime-gate-CCyvzllG.cjs → runtime-gate-Ay8_t7m0.cjs} +1 -1
- package/dist/cli-chunks/{runtime-permission-env-v9THnMre.cjs → runtime-permission-env-C0clU7_f.cjs} +119 -6
- package/dist/cli-chunks/{session-UhAizNH0.cjs → session-2vOGqgeA.cjs} +1 -1
- package/dist/cli-chunks/{skill-BxL6KOYN.cjs → skill-D5Pf0dxT.cjs} +2 -2
- package/dist/cli-chunks/{version-B-iUWMkU.cjs → version-CF6ilsAH.cjs} +1 -1
- package/dist/cli.cjs +1 -1
- package/dist/devtools/browser-dev-host/assets/browser-dev-host-D6g0uewc.js +101 -0
- package/dist/devtools/browser-dev-host/assets/{desktop-app-launch-B1QBmFTk.js → desktop-app-launch-Cku9Fxud.js} +3 -3
- package/dist/devtools/browser-dev-host/assets/index-BrXEMo2-.css +1 -0
- package/dist/devtools/browser-dev-host/assets/{index-DWFHHorU.js → index-CVARuXxw.js} +4 -4
- package/dist/devtools/browser-dev-host/index.html +3 -3
- package/dist/index.cjs.js +32 -16
- package/dist/index.esm.js +32 -16
- package/dist/protocol.cjs.js +29 -20
- package/dist/protocol.esm.js +29 -21
- package/dist/vite.cjs.js +3 -3
- package/dist/vite.esm.js +3 -3
- package/docs/runtime-host-migration.md +5 -3
- package/package.json +6 -6
- package/skill/skill.json +4 -4
- package/types/index.d.ts +2 -2
- package/types/modules/viewport/index.d.ts +33 -2
- package/types/protocol/capabilities.d.ts +1 -1
- package/types/protocol/dev-session.d.ts +13 -2
- package/types/protocol.d.ts +2 -2
- package/dist/devtools/browser-dev-host/assets/browser-dev-host-BKVURp-m.js +0 -101
- package/dist/devtools/browser-dev-host/assets/index-D-cRoNV5.css +0 -1
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
6
|
<meta name="theme-color" content="#f4f5f7" />
|
|
7
7
|
<title>小程序工坊调试台</title>
|
|
8
|
-
<script type="module" crossorigin src="/assets/index-
|
|
9
|
-
<link rel="modulepreload" crossorigin href="/assets/desktop-app-launch-
|
|
10
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
8
|
+
<script type="module" crossorigin src="/assets/index-CVARuXxw.js"></script>
|
|
9
|
+
<link rel="modulepreload" crossorigin href="/assets/desktop-app-launch-Cku9Fxud.js">
|
|
10
|
+
<link rel="stylesheet" crossorigin href="/assets/index-BrXEMo2-.css">
|
|
11
11
|
</head>
|
|
12
12
|
<body>
|
|
13
13
|
<div id="app"></div>
|
package/dist/index.cjs.js
CHANGED
|
@@ -629,6 +629,7 @@ const USER_GET_STEAM_GAME_LIST_METHOD = 'user.getSteamGameList';
|
|
|
629
629
|
const SHARE_COPY_LINK_METHOD = 'share.copyLink';
|
|
630
630
|
const SHARE_SHOW_SHARE_MENU_METHOD = 'share.showShareMenu';
|
|
631
631
|
const SHARE_SCREENSHOT_METHOD = 'share.screenshot';
|
|
632
|
+
const VIEWPORT_SET_DISPLAY_METHOD = 'viewport.setDisplay';
|
|
632
633
|
const VIEWPORT_GET_WINDOW_INFO_METHOD = 'viewport.getWindowInfo';
|
|
633
634
|
const VIEWPORT_SET_NAVIGATION_BAR_STYLE_METHOD = 'viewport.setNavigationBarStyle';
|
|
634
635
|
const STORAGE_GET_STORAGE_METHOD = 'storage.getStorage';
|
|
@@ -747,7 +748,7 @@ const COMPANION_SHOW_NOTIFICATION_METHOD = 'companion.showNotification';
|
|
|
747
748
|
* @see [parseMiniProgramRuntimePermissions](/reference/symbols/protocol/functions/parseMiniProgramRuntimePermissions) Runtime 权限快照解析器。
|
|
748
749
|
*/
|
|
749
750
|
function isMiniProgramBridgeMessage(value) {
|
|
750
|
-
if (!isRecord$
|
|
751
|
+
if (!isRecord$3(value))
|
|
751
752
|
return false;
|
|
752
753
|
if (value.namespace !== MINI_PROGRAM_MESSAGE_NAMESPACE || (value.version !== 1 && value.version !== 2) || !isNonEmptyString$1(value.nonce)) {
|
|
753
754
|
return false;
|
|
@@ -897,7 +898,7 @@ function isMiniProgramRelativePath(value) {
|
|
|
897
898
|
* @see [DirectoryHandle](/reference/symbols/root/interfaces/DirectoryHandle) 可作为 derived path root 的目录代理。
|
|
898
899
|
*/
|
|
899
900
|
function isMiniProgramPathRootRef(value) {
|
|
900
|
-
if (!isRecord$
|
|
901
|
+
if (!isRecord$3(value))
|
|
901
902
|
return false;
|
|
902
903
|
if (value.kind === 'sandbox')
|
|
903
904
|
return hasOnlyKeys(value, ['kind']);
|
|
@@ -963,7 +964,7 @@ function isMiniProgramPathRootRef(value) {
|
|
|
963
964
|
* @see [FileHandle](/reference/symbols/root/interfaces/FileHandle) 使用文件引用的公开 I/O 代理。
|
|
964
965
|
*/
|
|
965
966
|
function isMiniProgramFileRef(value) {
|
|
966
|
-
if (!isRecord$
|
|
967
|
+
if (!isRecord$3(value) || value.kind !== 'file')
|
|
967
968
|
return false;
|
|
968
969
|
if (isNonEmptyString$1(value.handleId)) {
|
|
969
970
|
return hasOnlyKeys(value, ['kind', 'handleId']);
|
|
@@ -1030,7 +1031,7 @@ function isMiniProgramFileRef(value) {
|
|
|
1030
1031
|
* @see [DirectoryHandle](/reference/symbols/root/interfaces/DirectoryHandle) 使用目录引用的公开路径操作代理。
|
|
1031
1032
|
*/
|
|
1032
1033
|
function isMiniProgramDirectoryRef(value) {
|
|
1033
|
-
if (!isRecord$
|
|
1034
|
+
if (!isRecord$3(value) || value.kind !== 'directory')
|
|
1034
1035
|
return false;
|
|
1035
1036
|
if (isNonEmptyString$1(value.handleId)) {
|
|
1036
1037
|
return hasOnlyKeys(value, ['kind', 'handleId']);
|
|
@@ -1149,7 +1150,7 @@ function isMiniProgramByteArray(value) {
|
|
|
1149
1150
|
* @see [FileHandle](/reference/symbols/root/interfaces/FileHandle) 提供 `stat()` 的当前 session 文件代理。
|
|
1150
1151
|
*/
|
|
1151
1152
|
function isMiniProgramFileStat(value) {
|
|
1152
|
-
return (isRecord$
|
|
1153
|
+
return (isRecord$3(value) &&
|
|
1153
1154
|
value.kind === 'file' &&
|
|
1154
1155
|
isNonNegativeSafeInteger(value.size) &&
|
|
1155
1156
|
(value.modifiedAt === undefined || isNonNegativeFiniteNumber(value.modifiedAt)) &&
|
|
@@ -1209,7 +1210,7 @@ function isMiniProgramFileStat(value) {
|
|
|
1209
1210
|
* @see [isMiniProgramBridgeMessage](/reference/symbols/protocol/functions/isMiniProgramBridgeMessage) operation progress envelope 的最低校验。
|
|
1210
1211
|
*/
|
|
1211
1212
|
function isMiniProgramDownloadProgressPayload(value) {
|
|
1212
|
-
if (!isRecord$
|
|
1213
|
+
if (!isRecord$3(value) ||
|
|
1213
1214
|
!isNonNegativeSafeInteger(value.loaded) ||
|
|
1214
1215
|
typeof value.lengthComputable !== 'boolean' ||
|
|
1215
1216
|
!hasOnlyKeys(value, ['loaded', 'total', 'lengthComputable'])) {
|
|
@@ -1220,7 +1221,7 @@ function isMiniProgramDownloadProgressPayload(value) {
|
|
|
1220
1221
|
return isNonNegativeSafeInteger(value.total) && value.loaded <= value.total;
|
|
1221
1222
|
}
|
|
1222
1223
|
function isMiniProgramCompanionPrepareProgress(value) {
|
|
1223
|
-
if (!isRecord$
|
|
1224
|
+
if (!isRecord$3(value))
|
|
1224
1225
|
return false;
|
|
1225
1226
|
if (value.phase === 'downloading') {
|
|
1226
1227
|
return (isNonNegativeSafeInteger(value.loaded) &&
|
|
@@ -1238,10 +1239,10 @@ function isMiniProgramOperationProgressPayload(value) {
|
|
|
1238
1239
|
return isMiniProgramDownloadProgressPayload(value) || isMiniProgramCompanionPrepareProgress(value);
|
|
1239
1240
|
}
|
|
1240
1241
|
function isSDKHandshakePayload(value) {
|
|
1241
|
-
return isRecord$
|
|
1242
|
+
return isRecord$3(value) && isNonEmptyString$1(value.href) && typeof value.userAgent === 'string' && isNonEmptyString$1(value.sdkVersion);
|
|
1242
1243
|
}
|
|
1243
1244
|
function isBridgeError(value) {
|
|
1244
|
-
return isRecord$
|
|
1245
|
+
return isRecord$3(value) && isNonEmptyString$1(value.code) && typeof value.message === 'string';
|
|
1245
1246
|
}
|
|
1246
1247
|
function isNonNegativeSafeInteger(value) {
|
|
1247
1248
|
return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0;
|
|
@@ -1256,15 +1257,10 @@ function hasOnlyKeys(value, allowedKeys) {
|
|
|
1256
1257
|
const allowed = new Set(allowedKeys);
|
|
1257
1258
|
return Object.keys(value).every((key) => allowed.has(key));
|
|
1258
1259
|
}
|
|
1259
|
-
function isRecord$
|
|
1260
|
+
function isRecord$3(value) {
|
|
1260
1261
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
1261
1262
|
}
|
|
1262
1263
|
|
|
1263
|
-
/** 当前用户信息与登录能力支持的完整 scope 目录(canonical 顺序)。 */
|
|
1264
|
-
const USER_INFO_AUTHORIZATION_SCOPES = ['identity', 'profile', 'steam_account'];
|
|
1265
|
-
/** Companion alias 的跨构建、Runtime 与 Host 规范。 */
|
|
1266
|
-
const COMPANION_ALIAS_PATTERN = /^[a-z][a-z0-9-]{0,31}$/;
|
|
1267
|
-
|
|
1268
1264
|
const MINI_PROGRAM_PERMISSION_KEYS = [
|
|
1269
1265
|
'userInfo',
|
|
1270
1266
|
'steamLibrary',
|
|
@@ -1280,6 +1276,11 @@ new Set(MINI_PROGRAM_PERMISSION_KEYS);
|
|
|
1280
1276
|
|
|
1281
1277
|
new Set(MINI_PROGRAM_PERMISSION_KEYS);
|
|
1282
1278
|
|
|
1279
|
+
/** 当前用户信息与登录能力支持的完整 scope 目录(canonical 顺序)。 */
|
|
1280
|
+
const USER_INFO_AUTHORIZATION_SCOPES = ['identity', 'profile', 'steam_account'];
|
|
1281
|
+
/** Companion alias 的跨构建、Runtime 与 Host 规范。 */
|
|
1282
|
+
const COMPANION_ALIAS_PATTERN = /^[a-z][a-z0-9-]{0,31}$/;
|
|
1283
|
+
|
|
1283
1284
|
/** 获取浏览器全局 window。 */
|
|
1284
1285
|
function getGlobalWindow() {
|
|
1285
1286
|
return typeof window === 'undefined' ? undefined : window;
|
|
@@ -1341,7 +1342,7 @@ function createMessageId() {
|
|
|
1341
1342
|
/** 构建时替换为当前发布包的实际版本。 */
|
|
1342
1343
|
const HB_SDK_VERSION = typeof undefined === 'string'
|
|
1343
1344
|
? undefined
|
|
1344
|
-
: '0.8.3-alpha.
|
|
1345
|
+
: '0.8.3-alpha.4';
|
|
1345
1346
|
|
|
1346
1347
|
const RUNTIME_MODES = new Set(['production', 'preview', 'development', 'unknown']);
|
|
1347
1348
|
const OPERATING_SYSTEM_NAMES = new Set(['android', 'ios', 'ohos', 'windows', 'macos', 'linux', 'unknown']);
|
|
@@ -4402,6 +4403,20 @@ function setNavigationBarStyle(requester, options) {
|
|
|
4402
4403
|
*/
|
|
4403
4404
|
function createViewportModule(requester) {
|
|
4404
4405
|
return {
|
|
4406
|
+
// Runtime 持有唯一的操作截止时间;复用 cancel 链路,避免 SDK 普通请求 timer 提前失效。
|
|
4407
|
+
setDisplay: async (options) => {
|
|
4408
|
+
try {
|
|
4409
|
+
return await requester.requestOperation(VIEWPORT_SET_DISPLAY_METHOD, options);
|
|
4410
|
+
}
|
|
4411
|
+
catch (error) {
|
|
4412
|
+
// 旧 Runtime 或客户端缺少展示能力时统一降级,保留其它错误供业务处理。
|
|
4413
|
+
const code = error && typeof error === 'object' && 'code' in error ? error.code : undefined;
|
|
4414
|
+
if (code === 'METHOD_FORBIDDEN' || code === 'METHOD_NOT_FOUND' || code === 'REQUEST_UNSUPPORTED') {
|
|
4415
|
+
return { supported: false };
|
|
4416
|
+
}
|
|
4417
|
+
throw error;
|
|
4418
|
+
}
|
|
4419
|
+
},
|
|
4405
4420
|
getWindowInfo: () => getWindowInfo(requester),
|
|
4406
4421
|
setNavigationBarStyle: (options) => setNavigationBarStyle(requester, options),
|
|
4407
4422
|
};
|
|
@@ -5243,6 +5258,7 @@ const share = {
|
|
|
5243
5258
|
};
|
|
5244
5259
|
/** 默认 SDK 实例的 Viewport 模块。 */
|
|
5245
5260
|
const viewport = {
|
|
5261
|
+
setDisplay: (options) => getDefaultSDK().viewport.setDisplay(options),
|
|
5246
5262
|
getWindowInfo: () => getDefaultSDK().viewport.getWindowInfo(),
|
|
5247
5263
|
setNavigationBarStyle: (options) => getDefaultSDK().viewport.setNavigationBarStyle(options),
|
|
5248
5264
|
};
|
package/dist/index.esm.js
CHANGED
|
@@ -625,6 +625,7 @@ const USER_GET_STEAM_GAME_LIST_METHOD = 'user.getSteamGameList';
|
|
|
625
625
|
const SHARE_COPY_LINK_METHOD = 'share.copyLink';
|
|
626
626
|
const SHARE_SHOW_SHARE_MENU_METHOD = 'share.showShareMenu';
|
|
627
627
|
const SHARE_SCREENSHOT_METHOD = 'share.screenshot';
|
|
628
|
+
const VIEWPORT_SET_DISPLAY_METHOD = 'viewport.setDisplay';
|
|
628
629
|
const VIEWPORT_GET_WINDOW_INFO_METHOD = 'viewport.getWindowInfo';
|
|
629
630
|
const VIEWPORT_SET_NAVIGATION_BAR_STYLE_METHOD = 'viewport.setNavigationBarStyle';
|
|
630
631
|
const STORAGE_GET_STORAGE_METHOD = 'storage.getStorage';
|
|
@@ -743,7 +744,7 @@ const COMPANION_SHOW_NOTIFICATION_METHOD = 'companion.showNotification';
|
|
|
743
744
|
* @see [parseMiniProgramRuntimePermissions](/reference/symbols/protocol/functions/parseMiniProgramRuntimePermissions) Runtime 权限快照解析器。
|
|
744
745
|
*/
|
|
745
746
|
function isMiniProgramBridgeMessage(value) {
|
|
746
|
-
if (!isRecord$
|
|
747
|
+
if (!isRecord$3(value))
|
|
747
748
|
return false;
|
|
748
749
|
if (value.namespace !== MINI_PROGRAM_MESSAGE_NAMESPACE || (value.version !== 1 && value.version !== 2) || !isNonEmptyString$1(value.nonce)) {
|
|
749
750
|
return false;
|
|
@@ -893,7 +894,7 @@ function isMiniProgramRelativePath(value) {
|
|
|
893
894
|
* @see [DirectoryHandle](/reference/symbols/root/interfaces/DirectoryHandle) 可作为 derived path root 的目录代理。
|
|
894
895
|
*/
|
|
895
896
|
function isMiniProgramPathRootRef(value) {
|
|
896
|
-
if (!isRecord$
|
|
897
|
+
if (!isRecord$3(value))
|
|
897
898
|
return false;
|
|
898
899
|
if (value.kind === 'sandbox')
|
|
899
900
|
return hasOnlyKeys(value, ['kind']);
|
|
@@ -959,7 +960,7 @@ function isMiniProgramPathRootRef(value) {
|
|
|
959
960
|
* @see [FileHandle](/reference/symbols/root/interfaces/FileHandle) 使用文件引用的公开 I/O 代理。
|
|
960
961
|
*/
|
|
961
962
|
function isMiniProgramFileRef(value) {
|
|
962
|
-
if (!isRecord$
|
|
963
|
+
if (!isRecord$3(value) || value.kind !== 'file')
|
|
963
964
|
return false;
|
|
964
965
|
if (isNonEmptyString$1(value.handleId)) {
|
|
965
966
|
return hasOnlyKeys(value, ['kind', 'handleId']);
|
|
@@ -1026,7 +1027,7 @@ function isMiniProgramFileRef(value) {
|
|
|
1026
1027
|
* @see [DirectoryHandle](/reference/symbols/root/interfaces/DirectoryHandle) 使用目录引用的公开路径操作代理。
|
|
1027
1028
|
*/
|
|
1028
1029
|
function isMiniProgramDirectoryRef(value) {
|
|
1029
|
-
if (!isRecord$
|
|
1030
|
+
if (!isRecord$3(value) || value.kind !== 'directory')
|
|
1030
1031
|
return false;
|
|
1031
1032
|
if (isNonEmptyString$1(value.handleId)) {
|
|
1032
1033
|
return hasOnlyKeys(value, ['kind', 'handleId']);
|
|
@@ -1145,7 +1146,7 @@ function isMiniProgramByteArray(value) {
|
|
|
1145
1146
|
* @see [FileHandle](/reference/symbols/root/interfaces/FileHandle) 提供 `stat()` 的当前 session 文件代理。
|
|
1146
1147
|
*/
|
|
1147
1148
|
function isMiniProgramFileStat(value) {
|
|
1148
|
-
return (isRecord$
|
|
1149
|
+
return (isRecord$3(value) &&
|
|
1149
1150
|
value.kind === 'file' &&
|
|
1150
1151
|
isNonNegativeSafeInteger(value.size) &&
|
|
1151
1152
|
(value.modifiedAt === undefined || isNonNegativeFiniteNumber(value.modifiedAt)) &&
|
|
@@ -1205,7 +1206,7 @@ function isMiniProgramFileStat(value) {
|
|
|
1205
1206
|
* @see [isMiniProgramBridgeMessage](/reference/symbols/protocol/functions/isMiniProgramBridgeMessage) operation progress envelope 的最低校验。
|
|
1206
1207
|
*/
|
|
1207
1208
|
function isMiniProgramDownloadProgressPayload(value) {
|
|
1208
|
-
if (!isRecord$
|
|
1209
|
+
if (!isRecord$3(value) ||
|
|
1209
1210
|
!isNonNegativeSafeInteger(value.loaded) ||
|
|
1210
1211
|
typeof value.lengthComputable !== 'boolean' ||
|
|
1211
1212
|
!hasOnlyKeys(value, ['loaded', 'total', 'lengthComputable'])) {
|
|
@@ -1216,7 +1217,7 @@ function isMiniProgramDownloadProgressPayload(value) {
|
|
|
1216
1217
|
return isNonNegativeSafeInteger(value.total) && value.loaded <= value.total;
|
|
1217
1218
|
}
|
|
1218
1219
|
function isMiniProgramCompanionPrepareProgress(value) {
|
|
1219
|
-
if (!isRecord$
|
|
1220
|
+
if (!isRecord$3(value))
|
|
1220
1221
|
return false;
|
|
1221
1222
|
if (value.phase === 'downloading') {
|
|
1222
1223
|
return (isNonNegativeSafeInteger(value.loaded) &&
|
|
@@ -1234,10 +1235,10 @@ function isMiniProgramOperationProgressPayload(value) {
|
|
|
1234
1235
|
return isMiniProgramDownloadProgressPayload(value) || isMiniProgramCompanionPrepareProgress(value);
|
|
1235
1236
|
}
|
|
1236
1237
|
function isSDKHandshakePayload(value) {
|
|
1237
|
-
return isRecord$
|
|
1238
|
+
return isRecord$3(value) && isNonEmptyString$1(value.href) && typeof value.userAgent === 'string' && isNonEmptyString$1(value.sdkVersion);
|
|
1238
1239
|
}
|
|
1239
1240
|
function isBridgeError(value) {
|
|
1240
|
-
return isRecord$
|
|
1241
|
+
return isRecord$3(value) && isNonEmptyString$1(value.code) && typeof value.message === 'string';
|
|
1241
1242
|
}
|
|
1242
1243
|
function isNonNegativeSafeInteger(value) {
|
|
1243
1244
|
return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0;
|
|
@@ -1252,15 +1253,10 @@ function hasOnlyKeys(value, allowedKeys) {
|
|
|
1252
1253
|
const allowed = new Set(allowedKeys);
|
|
1253
1254
|
return Object.keys(value).every((key) => allowed.has(key));
|
|
1254
1255
|
}
|
|
1255
|
-
function isRecord$
|
|
1256
|
+
function isRecord$3(value) {
|
|
1256
1257
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
1257
1258
|
}
|
|
1258
1259
|
|
|
1259
|
-
/** 当前用户信息与登录能力支持的完整 scope 目录(canonical 顺序)。 */
|
|
1260
|
-
const USER_INFO_AUTHORIZATION_SCOPES = ['identity', 'profile', 'steam_account'];
|
|
1261
|
-
/** Companion alias 的跨构建、Runtime 与 Host 规范。 */
|
|
1262
|
-
const COMPANION_ALIAS_PATTERN = /^[a-z][a-z0-9-]{0,31}$/;
|
|
1263
|
-
|
|
1264
1260
|
const MINI_PROGRAM_PERMISSION_KEYS = [
|
|
1265
1261
|
'userInfo',
|
|
1266
1262
|
'steamLibrary',
|
|
@@ -1276,6 +1272,11 @@ new Set(MINI_PROGRAM_PERMISSION_KEYS);
|
|
|
1276
1272
|
|
|
1277
1273
|
new Set(MINI_PROGRAM_PERMISSION_KEYS);
|
|
1278
1274
|
|
|
1275
|
+
/** 当前用户信息与登录能力支持的完整 scope 目录(canonical 顺序)。 */
|
|
1276
|
+
const USER_INFO_AUTHORIZATION_SCOPES = ['identity', 'profile', 'steam_account'];
|
|
1277
|
+
/** Companion alias 的跨构建、Runtime 与 Host 规范。 */
|
|
1278
|
+
const COMPANION_ALIAS_PATTERN = /^[a-z][a-z0-9-]{0,31}$/;
|
|
1279
|
+
|
|
1279
1280
|
/** 获取浏览器全局 window。 */
|
|
1280
1281
|
function getGlobalWindow() {
|
|
1281
1282
|
return typeof window === 'undefined' ? undefined : window;
|
|
@@ -1337,7 +1338,7 @@ function createMessageId() {
|
|
|
1337
1338
|
/** 构建时替换为当前发布包的实际版本。 */
|
|
1338
1339
|
const HB_SDK_VERSION = typeof undefined === 'string'
|
|
1339
1340
|
? undefined
|
|
1340
|
-
: '0.8.3-alpha.
|
|
1341
|
+
: '0.8.3-alpha.4';
|
|
1341
1342
|
|
|
1342
1343
|
const RUNTIME_MODES = new Set(['production', 'preview', 'development', 'unknown']);
|
|
1343
1344
|
const OPERATING_SYSTEM_NAMES = new Set(['android', 'ios', 'ohos', 'windows', 'macos', 'linux', 'unknown']);
|
|
@@ -4398,6 +4399,20 @@ function setNavigationBarStyle(requester, options) {
|
|
|
4398
4399
|
*/
|
|
4399
4400
|
function createViewportModule(requester) {
|
|
4400
4401
|
return {
|
|
4402
|
+
// Runtime 持有唯一的操作截止时间;复用 cancel 链路,避免 SDK 普通请求 timer 提前失效。
|
|
4403
|
+
setDisplay: async (options) => {
|
|
4404
|
+
try {
|
|
4405
|
+
return await requester.requestOperation(VIEWPORT_SET_DISPLAY_METHOD, options);
|
|
4406
|
+
}
|
|
4407
|
+
catch (error) {
|
|
4408
|
+
// 旧 Runtime 或客户端缺少展示能力时统一降级,保留其它错误供业务处理。
|
|
4409
|
+
const code = error && typeof error === 'object' && 'code' in error ? error.code : undefined;
|
|
4410
|
+
if (code === 'METHOD_FORBIDDEN' || code === 'METHOD_NOT_FOUND' || code === 'REQUEST_UNSUPPORTED') {
|
|
4411
|
+
return { supported: false };
|
|
4412
|
+
}
|
|
4413
|
+
throw error;
|
|
4414
|
+
}
|
|
4415
|
+
},
|
|
4401
4416
|
getWindowInfo: () => getWindowInfo(requester),
|
|
4402
4417
|
setNavigationBarStyle: (options) => setNavigationBarStyle(requester, options),
|
|
4403
4418
|
};
|
|
@@ -5239,6 +5254,7 @@ const share = {
|
|
|
5239
5254
|
};
|
|
5240
5255
|
/** 默认 SDK 实例的 Viewport 模块。 */
|
|
5241
5256
|
const viewport = {
|
|
5257
|
+
setDisplay: (options) => getDefaultSDK().viewport.setDisplay(options),
|
|
5242
5258
|
getWindowInfo: () => getDefaultSDK().viewport.getWindowInfo(),
|
|
5243
5259
|
setNavigationBarStyle: (options) => getDefaultSDK().viewport.setNavigationBarStyle(options),
|
|
5244
5260
|
};
|
package/dist/protocol.cjs.js
CHANGED
|
@@ -38,6 +38,7 @@ const USER_GET_STEAM_GAME_LIST_METHOD = 'user.getSteamGameList';
|
|
|
38
38
|
const SHARE_COPY_LINK_METHOD = 'share.copyLink';
|
|
39
39
|
const SHARE_SHOW_SHARE_MENU_METHOD = 'share.showShareMenu';
|
|
40
40
|
const SHARE_SCREENSHOT_METHOD = 'share.screenshot';
|
|
41
|
+
const VIEWPORT_SET_DISPLAY_METHOD = 'viewport.setDisplay';
|
|
41
42
|
const VIEWPORT_GET_WINDOW_INFO_METHOD = 'viewport.getWindowInfo';
|
|
42
43
|
const VIEWPORT_SET_NAVIGATION_BAR_STYLE_METHOD = 'viewport.setNavigationBarStyle';
|
|
43
44
|
const STORAGE_GET_STORAGE_METHOD = 'storage.getStorage';
|
|
@@ -161,6 +162,13 @@ const MINI_PROGRAM_PROTOCOL_CAPABILITIES = [
|
|
|
161
162
|
requirement: { kind: 'none' },
|
|
162
163
|
risk: 'low',
|
|
163
164
|
},
|
|
165
|
+
{
|
|
166
|
+
method: VIEWPORT_SET_DISPLAY_METHOD,
|
|
167
|
+
module: 'viewport',
|
|
168
|
+
capability: VIEWPORT_SET_DISPLAY_METHOD,
|
|
169
|
+
requirement: { kind: 'none' },
|
|
170
|
+
risk: 'low',
|
|
171
|
+
},
|
|
164
172
|
{
|
|
165
173
|
method: STORAGE_GET_STORAGE_METHOD,
|
|
166
174
|
module: 'storage',
|
|
@@ -436,7 +444,7 @@ const MINI_PROGRAM_PROTOCOL_CAPABILITIES = [
|
|
|
436
444
|
* @see [parseMiniProgramRuntimePermissions](/reference/symbols/protocol/functions/parseMiniProgramRuntimePermissions) Runtime 权限快照解析器。
|
|
437
445
|
*/
|
|
438
446
|
function isMiniProgramBridgeMessage(value) {
|
|
439
|
-
if (!isRecord$
|
|
447
|
+
if (!isRecord$3(value))
|
|
440
448
|
return false;
|
|
441
449
|
if (value.namespace !== MINI_PROGRAM_MESSAGE_NAMESPACE || (value.version !== 1 && value.version !== 2) || !isNonEmptyString$1(value.nonce)) {
|
|
442
450
|
return false;
|
|
@@ -586,7 +594,7 @@ function isMiniProgramRelativePath(value) {
|
|
|
586
594
|
* @see [DirectoryHandle](/reference/symbols/root/interfaces/DirectoryHandle) 可作为 derived path root 的目录代理。
|
|
587
595
|
*/
|
|
588
596
|
function isMiniProgramPathRootRef(value) {
|
|
589
|
-
if (!isRecord$
|
|
597
|
+
if (!isRecord$3(value))
|
|
590
598
|
return false;
|
|
591
599
|
if (value.kind === 'sandbox')
|
|
592
600
|
return hasOnlyKeys(value, ['kind']);
|
|
@@ -652,7 +660,7 @@ function isMiniProgramPathRootRef(value) {
|
|
|
652
660
|
* @see [FileHandle](/reference/symbols/root/interfaces/FileHandle) 使用文件引用的公开 I/O 代理。
|
|
653
661
|
*/
|
|
654
662
|
function isMiniProgramFileRef(value) {
|
|
655
|
-
if (!isRecord$
|
|
663
|
+
if (!isRecord$3(value) || value.kind !== 'file')
|
|
656
664
|
return false;
|
|
657
665
|
if (isNonEmptyString$1(value.handleId)) {
|
|
658
666
|
return hasOnlyKeys(value, ['kind', 'handleId']);
|
|
@@ -719,7 +727,7 @@ function isMiniProgramFileRef(value) {
|
|
|
719
727
|
* @see [DirectoryHandle](/reference/symbols/root/interfaces/DirectoryHandle) 使用目录引用的公开路径操作代理。
|
|
720
728
|
*/
|
|
721
729
|
function isMiniProgramDirectoryRef(value) {
|
|
722
|
-
if (!isRecord$
|
|
730
|
+
if (!isRecord$3(value) || value.kind !== 'directory')
|
|
723
731
|
return false;
|
|
724
732
|
if (isNonEmptyString$1(value.handleId)) {
|
|
725
733
|
return hasOnlyKeys(value, ['kind', 'handleId']);
|
|
@@ -793,7 +801,7 @@ function isMiniProgramDirectoryRef(value) {
|
|
|
793
801
|
* @see [SaveFileResult](/reference/symbols/protocol/types/SaveFileResult) save picker 的 direct-ref 文件结果。
|
|
794
802
|
*/
|
|
795
803
|
function isMiniProgramFileDescriptor(value) {
|
|
796
|
-
return (isRecord$
|
|
804
|
+
return (isRecord$3(value) &&
|
|
797
805
|
value.kind === 'file' &&
|
|
798
806
|
isNonEmptyString$1(value.name) &&
|
|
799
807
|
isFileMode(value.mode) &&
|
|
@@ -863,7 +871,7 @@ function isMiniProgramFileDescriptor(value) {
|
|
|
863
871
|
* @see [PickDirectoryResult](/reference/symbols/protocol/types/PickDirectoryResult) picker 的 direct-ref 返回契约。
|
|
864
872
|
*/
|
|
865
873
|
function isMiniProgramDirectoryDescriptor(value) {
|
|
866
|
-
return (isRecord$
|
|
874
|
+
return (isRecord$3(value) &&
|
|
867
875
|
value.kind === 'directory' &&
|
|
868
876
|
isNonEmptyString$1(value.name) &&
|
|
869
877
|
isFileMode(value.mode) &&
|
|
@@ -1042,7 +1050,7 @@ function isMiniProgramByteArray(value) {
|
|
|
1042
1050
|
* @see [FileHandle](/reference/symbols/root/interfaces/FileHandle) 提供 `stat()` 的当前 session 文件代理。
|
|
1043
1051
|
*/
|
|
1044
1052
|
function isMiniProgramFileStat(value) {
|
|
1045
|
-
return (isRecord$
|
|
1053
|
+
return (isRecord$3(value) &&
|
|
1046
1054
|
value.kind === 'file' &&
|
|
1047
1055
|
isNonNegativeSafeInteger(value.size) &&
|
|
1048
1056
|
(value.modifiedAt === undefined || isNonNegativeFiniteNumber(value.modifiedAt)) &&
|
|
@@ -1102,7 +1110,7 @@ function isMiniProgramFileStat(value) {
|
|
|
1102
1110
|
* @see [isMiniProgramBridgeMessage](/reference/symbols/protocol/functions/isMiniProgramBridgeMessage) operation progress envelope 的最低校验。
|
|
1103
1111
|
*/
|
|
1104
1112
|
function isMiniProgramDownloadProgressPayload(value) {
|
|
1105
|
-
if (!isRecord$
|
|
1113
|
+
if (!isRecord$3(value) ||
|
|
1106
1114
|
!isNonNegativeSafeInteger(value.loaded) ||
|
|
1107
1115
|
typeof value.lengthComputable !== 'boolean' ||
|
|
1108
1116
|
!hasOnlyKeys(value, ['loaded', 'total', 'lengthComputable'])) {
|
|
@@ -1113,7 +1121,7 @@ function isMiniProgramDownloadProgressPayload(value) {
|
|
|
1113
1121
|
return isNonNegativeSafeInteger(value.total) && value.loaded <= value.total;
|
|
1114
1122
|
}
|
|
1115
1123
|
function isMiniProgramCompanionPrepareProgress(value) {
|
|
1116
|
-
if (!isRecord$
|
|
1124
|
+
if (!isRecord$3(value))
|
|
1117
1125
|
return false;
|
|
1118
1126
|
if (value.phase === 'downloading') {
|
|
1119
1127
|
return (isNonNegativeSafeInteger(value.loaded) &&
|
|
@@ -1131,10 +1139,10 @@ function isMiniProgramOperationProgressPayload(value) {
|
|
|
1131
1139
|
return isMiniProgramDownloadProgressPayload(value) || isMiniProgramCompanionPrepareProgress(value);
|
|
1132
1140
|
}
|
|
1133
1141
|
function isSDKHandshakePayload(value) {
|
|
1134
|
-
return isRecord$
|
|
1142
|
+
return isRecord$3(value) && isNonEmptyString$1(value.href) && typeof value.userAgent === 'string' && isNonEmptyString$1(value.sdkVersion);
|
|
1135
1143
|
}
|
|
1136
1144
|
function isBridgeError(value) {
|
|
1137
|
-
return isRecord$
|
|
1145
|
+
return isRecord$3(value) && isNonEmptyString$1(value.code) && typeof value.message === 'string';
|
|
1138
1146
|
}
|
|
1139
1147
|
function isFileMode(value) {
|
|
1140
1148
|
return value === 'read' || value === 'readwrite';
|
|
@@ -1152,13 +1160,10 @@ function hasOnlyKeys(value, allowedKeys) {
|
|
|
1152
1160
|
const allowed = new Set(allowedKeys);
|
|
1153
1161
|
return Object.keys(value).every((key) => allowed.has(key));
|
|
1154
1162
|
}
|
|
1155
|
-
function isRecord$
|
|
1163
|
+
function isRecord$3(value) {
|
|
1156
1164
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
1157
1165
|
}
|
|
1158
1166
|
|
|
1159
|
-
/** 当前用户信息与登录能力支持的完整 scope 目录(canonical 顺序)。 */
|
|
1160
|
-
const USER_INFO_AUTHORIZATION_SCOPES = ['identity', 'profile', 'steam_account'];
|
|
1161
|
-
|
|
1162
1167
|
const MINI_PROGRAM_PERMISSION_KEYS = [
|
|
1163
1168
|
'userInfo',
|
|
1164
1169
|
'steamLibrary',
|
|
@@ -1302,7 +1307,7 @@ function isManagedMiniProgramRuntimePermissionKey(key) {
|
|
|
1302
1307
|
* @see {@link https://docs.xiaoheihe.cn/hb_sdk/guide/permissions | 权限声明}
|
|
1303
1308
|
*/
|
|
1304
1309
|
function parseMiniProgramRuntimePermissions(snapshot) {
|
|
1305
|
-
if (!isRecord(snapshot) || snapshot.schema_version !== 1 || !Array.isArray(snapshot.entries)) {
|
|
1310
|
+
if (!isRecord$2(snapshot) || snapshot.schema_version !== 1 || !Array.isArray(snapshot.entries)) {
|
|
1306
1311
|
return { valid: false, permissions: {} };
|
|
1307
1312
|
}
|
|
1308
1313
|
if (snapshot.revision !== undefined && (typeof snapshot.revision !== 'number' || !Number.isInteger(snapshot.revision) || snapshot.revision < 0)) {
|
|
@@ -1311,7 +1316,7 @@ function parseMiniProgramRuntimePermissions(snapshot) {
|
|
|
1311
1316
|
const seenKeys = new Set();
|
|
1312
1317
|
const permissions = {};
|
|
1313
1318
|
for (const rawEntry of snapshot.entries) {
|
|
1314
|
-
if (!isRecord(rawEntry) || typeof rawEntry.key !== 'string' || !rawEntry.key.trim()) {
|
|
1319
|
+
if (!isRecord$2(rawEntry) || typeof rawEntry.key !== 'string' || !rawEntry.key.trim()) {
|
|
1315
1320
|
return { valid: false, permissions: {} };
|
|
1316
1321
|
}
|
|
1317
1322
|
const inputKey = rawEntry.key.trim();
|
|
@@ -1327,7 +1332,7 @@ function parseMiniProgramRuntimePermissions(snapshot) {
|
|
|
1327
1332
|
}
|
|
1328
1333
|
if (key === 'network') {
|
|
1329
1334
|
const config = rawEntry.config;
|
|
1330
|
-
if (!isRecord(config) || typeof config.useOfficialDomain !== 'boolean') {
|
|
1335
|
+
if (!isRecord$2(config) || typeof config.useOfficialDomain !== 'boolean') {
|
|
1331
1336
|
return { valid: false, permissions: {} };
|
|
1332
1337
|
}
|
|
1333
1338
|
permissions[key] = {
|
|
@@ -1337,7 +1342,7 @@ function parseMiniProgramRuntimePermissions(snapshot) {
|
|
|
1337
1342
|
};
|
|
1338
1343
|
continue;
|
|
1339
1344
|
}
|
|
1340
|
-
if (rawEntry.config !== null && rawEntry.config !== undefined && (!isRecord(rawEntry.config) || Object.keys(rawEntry.config).length > 0)) {
|
|
1345
|
+
if (rawEntry.config !== null && rawEntry.config !== undefined && (!isRecord$2(rawEntry.config) || Object.keys(rawEntry.config).length > 0)) {
|
|
1341
1346
|
return { valid: false, permissions: {} };
|
|
1342
1347
|
}
|
|
1343
1348
|
permissions[key] = {
|
|
@@ -1348,10 +1353,13 @@ function parseMiniProgramRuntimePermissions(snapshot) {
|
|
|
1348
1353
|
}
|
|
1349
1354
|
return { valid: true, permissions };
|
|
1350
1355
|
}
|
|
1351
|
-
function isRecord(value) {
|
|
1356
|
+
function isRecord$2(value) {
|
|
1352
1357
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
1353
1358
|
}
|
|
1354
1359
|
|
|
1360
|
+
/** 当前用户信息与登录能力支持的完整 scope 目录(canonical 顺序)。 */
|
|
1361
|
+
const USER_INFO_AUTHORIZATION_SCOPES = ['identity', 'profile', 'steam_account'];
|
|
1362
|
+
|
|
1355
1363
|
exports.AUTH_LOGIN_METHOD = AUTH_LOGIN_METHOD;
|
|
1356
1364
|
exports.CLOUD_LEADERBOARD_DELETE_CURRENT_USER_ENTRY_METHOD = CLOUD_LEADERBOARD_DELETE_CURRENT_USER_ENTRY_METHOD;
|
|
1357
1365
|
exports.CLOUD_LEADERBOARD_GET_CURRENT_USER_ENTRY_METHOD = CLOUD_LEADERBOARD_GET_CURRENT_USER_ENTRY_METHOD;
|
|
@@ -1402,6 +1410,7 @@ exports.USER_GET_STEAM_GAME_LIST_METHOD = USER_GET_STEAM_GAME_LIST_METHOD;
|
|
|
1402
1410
|
exports.USER_INFO_AUTHORIZATION_SCOPES = USER_INFO_AUTHORIZATION_SCOPES;
|
|
1403
1411
|
exports.USER_REVOKE_AUTHORIZATION_METHOD = USER_REVOKE_AUTHORIZATION_METHOD;
|
|
1404
1412
|
exports.VIEWPORT_GET_WINDOW_INFO_METHOD = VIEWPORT_GET_WINDOW_INFO_METHOD;
|
|
1413
|
+
exports.VIEWPORT_SET_DISPLAY_METHOD = VIEWPORT_SET_DISPLAY_METHOD;
|
|
1405
1414
|
exports.VIEWPORT_SET_NAVIGATION_BAR_STYLE_METHOD = VIEWPORT_SET_NAVIGATION_BAR_STYLE_METHOD;
|
|
1406
1415
|
exports.isManagedMiniProgramRuntimePermissionKey = isManagedMiniProgramRuntimePermissionKey;
|
|
1407
1416
|
exports.isMiniProgramBridgeMessage = isMiniProgramBridgeMessage;
|