@heybox/hb-sdk 0.10.0-alpha.2 → 0.10.0-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 +7 -0
- package/README.md +13 -0
- package/dist/cli-chunks/{build-Be8QI9ma.cjs → build-wguxGJim.cjs} +8 -6
- package/dist/cli-chunks/{create-CaAGgJXF.cjs → create-mJhWyXDG.cjs} +2 -2
- package/dist/cli-chunks/{dev-BS8uwRH2.cjs → dev-CyfaFkKn.cjs} +19 -11
- package/dist/cli-chunks/{doctor-CgdrOrS5.cjs → doctor-De8pnp13.cjs} +1 -1
- package/dist/cli-chunks/{game-binding-guide-DX8uXx0V.cjs → game-binding-guide-C9ICs9zj.cjs} +3 -3
- package/dist/cli-chunks/{game-bindings-CjI0oA1t.cjs → game-bindings-Bg2xoKZY.cjs} +4 -4
- package/dist/cli-chunks/{games-C8A0PCo-.cjs → games-CAhkA4nh.cjs} +1 -1
- package/dist/cli-chunks/{index-BTOX41Vr.cjs → index-B8rzkV1n.cjs} +1 -1
- package/dist/cli-chunks/{index-CMbVUUpA.cjs → index-pGP_FOkj.cjs} +24 -22
- package/dist/cli-chunks/{index.esm-D7A_j5MA.cjs → index.esm-B8H9EwB1.cjs} +67 -0
- package/dist/cli-chunks/{index.esm-CIBT3Na1.cjs → index.esm-BqyU_JCg.cjs} +9 -9
- package/dist/cli-chunks/{login-BWuLgJWT.cjs → login-BYLNpsQ1.cjs} +1 -1
- package/dist/cli-chunks/{project-vite-FWtHl3XL.cjs → project-vite-BRUA9Vng.cjs} +1 -1
- package/dist/cli-chunks/{remote-R1jgvh-Z.cjs → remote-BAf86E8n.cjs} +13 -9
- package/dist/cli-chunks/{runtime-permission-env-BuXOApO4.cjs → runtime-permission-env-XMA-YAuB.cjs} +392 -113
- package/dist/cli-chunks/{skill-EM-Uv3Rj.cjs → skill-D6kR1-g0.cjs} +2 -2
- package/dist/cli-chunks/{version-BXh-cltM.cjs → version-SUKtha-_.cjs} +1 -1
- package/dist/cli.cjs +1 -1
- package/dist/devtools/browser-dev-host/assets/browser-dev-host-C2-qtvqp.js +224 -0
- package/dist/devtools/browser-dev-host/assets/{desktop-app-launch-BXVw6d6N.js → desktop-app-launch-DVnZ7dFB.js} +1 -1
- package/dist/devtools/browser-dev-host/assets/{index-CABlopeJ.js → index-DCPdAyuJ.js} +3 -3
- package/dist/devtools/browser-dev-host/index.html +2 -2
- package/dist/index.cjs.js +284 -1
- package/dist/index.esm.js +284 -1
- package/dist/miniapp-publish.cjs.js +215 -116
- package/dist/miniapp-publish.esm.js +214 -117
- package/dist/protocol.cjs.js +57 -0
- package/dist/protocol.esm.js +57 -0
- package/dist/vite.cjs.js +238 -96
- package/dist/vite.esm.js +238 -96
- package/package.json +6 -6
- package/skill/skill.json +4 -4
- package/types/index.d.ts +81 -6
- package/types/miniapp-publish/index.d.ts +30 -15
- package/types/vite/index.d.ts +7 -0
- package/dist/devtools/browser-dev-host/assets/browser-dev-host-CpphzCg4.js +0 -224
package/dist/vite.cjs.js
CHANGED
|
@@ -69,6 +69,13 @@ const POST_WRITE_METHODS = [
|
|
|
69
69
|
'post.comments.delete',
|
|
70
70
|
'post.comments.setLiked',
|
|
71
71
|
];
|
|
72
|
+
const CLOUD_ROOMS_LIST_METHOD = 'cloud.rooms.list';
|
|
73
|
+
const CLOUD_ROOMS_CREATE_METHOD = 'cloud.rooms.create';
|
|
74
|
+
const CLOUD_ROOMS_JOIN_METHOD = 'cloud.rooms.join';
|
|
75
|
+
const CLOUD_ROOMS_SEND_METHOD = 'cloud.rooms.send';
|
|
76
|
+
const CLOUD_ROOMS_LEAVE_METHOD = 'cloud.rooms.leave';
|
|
77
|
+
const CLOUD_ROOMS_DISPOSE_METHOD = 'cloud.rooms.dispose';
|
|
78
|
+
const CLOUD_ROOMS_LIFECYCLE_METHOD = 'cloud.rooms.lifecycle';
|
|
72
79
|
|
|
73
80
|
/** 游戏资料内部 wire:业务方法由 SDK 映射为精确资源请求。 */
|
|
74
81
|
const USER_GAMES_GET_OVERVIEW_METHOD = 'user.games.getOverview';
|
|
@@ -482,6 +489,55 @@ const COMPANION_SHOW_NOTIFICATION_METHOD = 'companion.showNotification';
|
|
|
482
489
|
requirement: { kind: 'none' },
|
|
483
490
|
risk: 'medium',
|
|
484
491
|
},
|
|
492
|
+
{
|
|
493
|
+
method: CLOUD_ROOMS_LIST_METHOD,
|
|
494
|
+
module: 'cloud',
|
|
495
|
+
capability: CLOUD_ROOMS_LIST_METHOD,
|
|
496
|
+
requirement: { kind: 'all', permissions: ['cloud_rooms'] },
|
|
497
|
+
risk: 'medium',
|
|
498
|
+
},
|
|
499
|
+
{
|
|
500
|
+
method: CLOUD_ROOMS_CREATE_METHOD,
|
|
501
|
+
module: 'cloud',
|
|
502
|
+
capability: CLOUD_ROOMS_CREATE_METHOD,
|
|
503
|
+
requirement: { kind: 'all', permissions: ['cloud_rooms'] },
|
|
504
|
+
risk: 'medium',
|
|
505
|
+
},
|
|
506
|
+
{
|
|
507
|
+
method: CLOUD_ROOMS_JOIN_METHOD,
|
|
508
|
+
module: 'cloud',
|
|
509
|
+
capability: CLOUD_ROOMS_JOIN_METHOD,
|
|
510
|
+
requirement: { kind: 'all', permissions: ['cloud_rooms'] },
|
|
511
|
+
risk: 'medium',
|
|
512
|
+
},
|
|
513
|
+
{
|
|
514
|
+
method: CLOUD_ROOMS_SEND_METHOD,
|
|
515
|
+
module: 'cloud',
|
|
516
|
+
capability: CLOUD_ROOMS_SEND_METHOD,
|
|
517
|
+
requirement: { kind: 'all', permissions: ['cloud_rooms'] },
|
|
518
|
+
risk: 'medium',
|
|
519
|
+
},
|
|
520
|
+
{
|
|
521
|
+
method: CLOUD_ROOMS_LEAVE_METHOD,
|
|
522
|
+
module: 'cloud',
|
|
523
|
+
capability: CLOUD_ROOMS_LEAVE_METHOD,
|
|
524
|
+
requirement: { kind: 'all', permissions: ['cloud_rooms'] },
|
|
525
|
+
risk: 'medium',
|
|
526
|
+
},
|
|
527
|
+
{
|
|
528
|
+
method: CLOUD_ROOMS_DISPOSE_METHOD,
|
|
529
|
+
module: 'cloud',
|
|
530
|
+
capability: CLOUD_ROOMS_DISPOSE_METHOD,
|
|
531
|
+
requirement: { kind: 'all', permissions: ['cloud_rooms'] },
|
|
532
|
+
risk: 'medium',
|
|
533
|
+
},
|
|
534
|
+
{
|
|
535
|
+
method: CLOUD_ROOMS_LIFECYCLE_METHOD,
|
|
536
|
+
module: 'cloud',
|
|
537
|
+
capability: CLOUD_ROOMS_LIFECYCLE_METHOD,
|
|
538
|
+
requirement: { kind: 'all', permissions: ['cloud_rooms'] },
|
|
539
|
+
risk: 'medium',
|
|
540
|
+
},
|
|
485
541
|
{
|
|
486
542
|
method: CLOUD_LEADERBOARD_SUBMIT_METHOD,
|
|
487
543
|
module: 'cloud',
|
|
@@ -804,6 +860,7 @@ const MINI_PROGRAM_PERMISSION_KEYS = [
|
|
|
804
860
|
'share',
|
|
805
861
|
'storage',
|
|
806
862
|
'cloud_storage',
|
|
863
|
+
'cloud_rooms',
|
|
807
864
|
'gameSaves',
|
|
808
865
|
'filesystem',
|
|
809
866
|
'media',
|
|
@@ -1001,6 +1058,16 @@ const MINI_PROGRAM_PERMISSION_CATALOG = [
|
|
|
1001
1058
|
methods: ['workspaceCards.requestRefresh'],
|
|
1002
1059
|
conditions: ['需平台批准、Host 支持与有效执行租约;不隐式授予网络或存储权限。'],
|
|
1003
1060
|
},
|
|
1061
|
+
{
|
|
1062
|
+
key: 'cloud_rooms',
|
|
1063
|
+
name: '实时动作房间',
|
|
1064
|
+
description: '在少人数房间内交换随包声明的结构化动作。',
|
|
1065
|
+
access: 'platform-approval',
|
|
1066
|
+
risk: 'medium',
|
|
1067
|
+
config: {},
|
|
1068
|
+
methods: ['cloud.rooms.list', 'cloud.rooms.create', 'cloud.rooms.join', 'cloud.rooms.send', 'cloud.rooms.leave', 'cloud.rooms.dispose', 'cloud.rooms.lifecycle'],
|
|
1069
|
+
conditions: ['仅允许当前版本房间协议中的动作和受限参数,不提供自由文字、文件或媒体传输。'],
|
|
1070
|
+
},
|
|
1004
1071
|
{
|
|
1005
1072
|
key: 'user_game_data',
|
|
1006
1073
|
name: '游戏资料',
|
|
@@ -1065,12 +1132,12 @@ function parseUserGameDataResourceDeclarations(value) {
|
|
|
1065
1132
|
return parseDeclarations(value);
|
|
1066
1133
|
}
|
|
1067
1134
|
function parseDeclarations(value, runtimeSnapshot) {
|
|
1068
|
-
if (!isRecord$4(value))
|
|
1135
|
+
if (!isRecord$4$1(value))
|
|
1069
1136
|
throw new Error('resources 必须是资源声明对象;每项资源必须填写 purpose');
|
|
1070
1137
|
const known = {};
|
|
1071
1138
|
for (const key of Object.keys(value).sort()) {
|
|
1072
1139
|
const entry = value[key];
|
|
1073
|
-
if (!isRecord$4(entry) || Object.keys(entry).length !== 1 || !Object.prototype.hasOwnProperty.call(entry, 'purpose'))
|
|
1140
|
+
if (!isRecord$4$1(entry) || Object.keys(entry).length !== 1 || !Object.prototype.hasOwnProperty.call(entry, 'purpose'))
|
|
1074
1141
|
throw new Error(`resources.${key} 必须且只能包含 purpose`);
|
|
1075
1142
|
let purpose;
|
|
1076
1143
|
try {
|
|
@@ -1086,7 +1153,7 @@ function parseDeclarations(value, runtimeSnapshot) {
|
|
|
1086
1153
|
}
|
|
1087
1154
|
return known;
|
|
1088
1155
|
}
|
|
1089
|
-
function isRecord$4(value) {
|
|
1156
|
+
function isRecord$4$1(value) {
|
|
1090
1157
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
1091
1158
|
}
|
|
1092
1159
|
|
|
@@ -11346,7 +11413,7 @@ async function ensureBasicInfoDirectory(rootPath, relative) {
|
|
|
11346
11413
|
/** 构建时替换为当前发布包的实际版本。 */
|
|
11347
11414
|
const HB_SDK_VERSION = typeof undefined === 'string'
|
|
11348
11415
|
? undefined
|
|
11349
|
-
: '0.10.0-alpha.
|
|
11416
|
+
: '0.10.0-alpha.4';
|
|
11350
11417
|
|
|
11351
11418
|
/**
|
|
11352
11419
|
* network.request 诊断日志的纯脱敏工具。
|
|
@@ -12432,6 +12499,122 @@ flush()})();
|
|
|
12432
12499
|
</script>`;
|
|
12433
12500
|
}
|
|
12434
12501
|
|
|
12502
|
+
const MINIAPP_PERMISSION_KEYS = MINI_PROGRAM_PERMISSION_KEYS;
|
|
12503
|
+
function parseMiniappPermissions(value, options) {
|
|
12504
|
+
const sourceLabel = options.sourceLabel ?? 'package.json#heybox.permissions';
|
|
12505
|
+
if (!options.present) {
|
|
12506
|
+
if (requiresExplicitPermissions(options.sdkVersion)) {
|
|
12507
|
+
throw new Error(`${sourceLabel} 在 @heybox/hb-sdk ${options.sdkVersion} 中必须声明;无权限需求时请配置空对象 {}`);
|
|
12508
|
+
}
|
|
12509
|
+
return { declared: false };
|
|
12510
|
+
}
|
|
12511
|
+
if (!isRecord$4(value)) {
|
|
12512
|
+
throw new Error(`${sourceLabel} 必须是 JSON 对象`);
|
|
12513
|
+
}
|
|
12514
|
+
const knownKeys = new Set(MINIAPP_PERMISSION_KEYS);
|
|
12515
|
+
for (const key of Object.keys(value)) {
|
|
12516
|
+
if (!knownKeys.has(key))
|
|
12517
|
+
throw new Error(`${sourceLabel} 包含未知权限:${key}`);
|
|
12518
|
+
}
|
|
12519
|
+
const permissions = {};
|
|
12520
|
+
for (const key of MINIAPP_PERMISSION_KEYS) {
|
|
12521
|
+
if (!Object.prototype.hasOwnProperty.call(value, key))
|
|
12522
|
+
continue;
|
|
12523
|
+
const declaration = value[key];
|
|
12524
|
+
const itemLabel = `${sourceLabel}.${key}`;
|
|
12525
|
+
if (!isRecord$4(declaration))
|
|
12526
|
+
throw new Error(`${itemLabel} 必须是 JSON 对象`);
|
|
12527
|
+
const definition = MINI_PROGRAM_PERMISSION_CATALOG.find((item) => item.key === key);
|
|
12528
|
+
if (!definition)
|
|
12529
|
+
throw new Error(`权限目录缺少定义:${key}`);
|
|
12530
|
+
const allowedFields = new Set(['enabled', ...Object.keys(definition.config)]);
|
|
12531
|
+
for (const field of Object.keys(declaration)) {
|
|
12532
|
+
if (!allowedFields.has(field))
|
|
12533
|
+
throw new Error(`${itemLabel} 包含未知字段:${field}`);
|
|
12534
|
+
}
|
|
12535
|
+
if (typeof declaration.enabled !== 'boolean')
|
|
12536
|
+
throw new Error(`${itemLabel}.enabled 必须是 boolean`);
|
|
12537
|
+
let useOfficialDomain = false;
|
|
12538
|
+
if (key === 'network') {
|
|
12539
|
+
if (declaration.useOfficialDomain !== undefined && typeof declaration.useOfficialDomain !== 'boolean') {
|
|
12540
|
+
throw new Error(`${itemLabel}.useOfficialDomain 必须是 boolean`);
|
|
12541
|
+
}
|
|
12542
|
+
useOfficialDomain = declaration.useOfficialDomain === true;
|
|
12543
|
+
}
|
|
12544
|
+
if (key === 'post') {
|
|
12545
|
+
for (const field of ['read', 'write']) {
|
|
12546
|
+
if (declaration[field] !== undefined && typeof declaration[field] !== 'boolean') {
|
|
12547
|
+
throw new Error(`${itemLabel}.${field} 必须是 boolean`);
|
|
12548
|
+
}
|
|
12549
|
+
}
|
|
12550
|
+
if (declaration.enabled)
|
|
12551
|
+
permissions.post = { enabled: true, read: declaration.read === true, write: declaration.write === true };
|
|
12552
|
+
continue;
|
|
12553
|
+
}
|
|
12554
|
+
if (key === 'user_game_data') {
|
|
12555
|
+
// 即使声明关闭也校验资源清单:enabled:false 不能隐藏非法字段。
|
|
12556
|
+
const resources = parseUserGameDataResources(declaration.resources, itemLabel);
|
|
12557
|
+
if (!declaration.enabled)
|
|
12558
|
+
continue;
|
|
12559
|
+
permissions.user_game_data = { enabled: true, resources };
|
|
12560
|
+
continue;
|
|
12561
|
+
}
|
|
12562
|
+
if (!declaration.enabled)
|
|
12563
|
+
continue;
|
|
12564
|
+
permissions[key] = key === 'network' ? { enabled: true, useOfficialDomain } : { enabled: true };
|
|
12565
|
+
}
|
|
12566
|
+
return { declared: true, permissions: permissions };
|
|
12567
|
+
}
|
|
12568
|
+
/**
|
|
12569
|
+
* 校验 Manifest 中的精确资源清单。
|
|
12570
|
+
*
|
|
12571
|
+
* @param value - `user_game_data.resources`;必须显式提供对象,空对象表示不请求任何资源。
|
|
12572
|
+
* @param itemLabel - 报错时使用的字段路径。
|
|
12573
|
+
* @returns 按固定顺序输出的已发布资源与规范化用途。
|
|
12574
|
+
* @throws 非对象、未开放 key 或非法用途直接报错。
|
|
12575
|
+
*/
|
|
12576
|
+
function parseUserGameDataResources(value, itemLabel) {
|
|
12577
|
+
try {
|
|
12578
|
+
return parseUserGameDataResourceDeclarations(value);
|
|
12579
|
+
}
|
|
12580
|
+
catch (error) {
|
|
12581
|
+
throw new Error(`${itemLabel}.${error.message}`);
|
|
12582
|
+
}
|
|
12583
|
+
}
|
|
12584
|
+
function requiresExplicitPermissions(sdkVersion) {
|
|
12585
|
+
const parsed = semverExports.parse(sdkVersion);
|
|
12586
|
+
if (!parsed)
|
|
12587
|
+
throw new Error(`sdkVersion 必须是合法 SemVer:${sdkVersion}`);
|
|
12588
|
+
return parsed.major > 0 || parsed.minor >= 9;
|
|
12589
|
+
}
|
|
12590
|
+
function isRecord$4(value) {
|
|
12591
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
12592
|
+
}
|
|
12593
|
+
/** Whether this manifest opts into the reviewed cloud room capability. */
|
|
12594
|
+
function declaresCloudRooms(manifest) {
|
|
12595
|
+
const permissions = manifest.permissions;
|
|
12596
|
+
return permissions?.cloud_rooms?.enabled === true;
|
|
12597
|
+
}
|
|
12598
|
+
|
|
12599
|
+
function isRecord$3(value) {
|
|
12600
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
12601
|
+
}
|
|
12602
|
+
function assertRoomReferences(refs) {
|
|
12603
|
+
if (!isRecord$3(refs) || Object.keys(refs).length > 4)
|
|
12604
|
+
throw new Error('roomDefinitions 无效');
|
|
12605
|
+
for (const [name, ref] of Object.entries(refs)) {
|
|
12606
|
+
if (!/^[A-Za-z][A-Za-z0-9_]{0,47}$/.test(name) ||
|
|
12607
|
+
['constructor', 'prototype', '__proto__'].includes(name) ||
|
|
12608
|
+
!isRecord$3(ref) ||
|
|
12609
|
+
Object.keys(ref).some((key) => key !== 'name' && key !== 'hash') ||
|
|
12610
|
+
ref.name !== name ||
|
|
12611
|
+
typeof ref.hash !== 'string' ||
|
|
12612
|
+
!/^[a-f0-9]{64}$/.test(ref.hash)) {
|
|
12613
|
+
throw new Error('Room 公开引用无效');
|
|
12614
|
+
}
|
|
12615
|
+
}
|
|
12616
|
+
}
|
|
12617
|
+
|
|
12435
12618
|
/** 单个小程序版本最多声明的关联游戏数量。 */
|
|
12436
12619
|
const MINIAPP_BIND_APP_IDS_MAX_COUNT = 20;
|
|
12437
12620
|
/**
|
|
@@ -12555,98 +12738,6 @@ function parseMiniappDesc(value, sourceLabel = 'package.json#heybox.desc') {
|
|
|
12555
12738
|
return desc;
|
|
12556
12739
|
}
|
|
12557
12740
|
|
|
12558
|
-
const MINIAPP_PERMISSION_KEYS = MINI_PROGRAM_PERMISSION_KEYS;
|
|
12559
|
-
function parseMiniappPermissions(value, options) {
|
|
12560
|
-
const sourceLabel = options.sourceLabel ?? 'package.json#heybox.permissions';
|
|
12561
|
-
if (!options.present) {
|
|
12562
|
-
if (requiresExplicitPermissions(options.sdkVersion)) {
|
|
12563
|
-
throw new Error(`${sourceLabel} 在 @heybox/hb-sdk ${options.sdkVersion} 中必须声明;无权限需求时请配置空对象 {}`);
|
|
12564
|
-
}
|
|
12565
|
-
return { declared: false };
|
|
12566
|
-
}
|
|
12567
|
-
if (!isRecord$3(value)) {
|
|
12568
|
-
throw new Error(`${sourceLabel} 必须是 JSON 对象`);
|
|
12569
|
-
}
|
|
12570
|
-
const knownKeys = new Set(MINIAPP_PERMISSION_KEYS);
|
|
12571
|
-
for (const key of Object.keys(value)) {
|
|
12572
|
-
if (!knownKeys.has(key))
|
|
12573
|
-
throw new Error(`${sourceLabel} 包含未知权限:${key}`);
|
|
12574
|
-
}
|
|
12575
|
-
const permissions = {};
|
|
12576
|
-
for (const key of MINIAPP_PERMISSION_KEYS) {
|
|
12577
|
-
if (!Object.prototype.hasOwnProperty.call(value, key))
|
|
12578
|
-
continue;
|
|
12579
|
-
const declaration = value[key];
|
|
12580
|
-
const itemLabel = `${sourceLabel}.${key}`;
|
|
12581
|
-
if (!isRecord$3(declaration))
|
|
12582
|
-
throw new Error(`${itemLabel} 必须是 JSON 对象`);
|
|
12583
|
-
const definition = MINI_PROGRAM_PERMISSION_CATALOG.find((item) => item.key === key);
|
|
12584
|
-
if (!definition)
|
|
12585
|
-
throw new Error(`权限目录缺少定义:${key}`);
|
|
12586
|
-
const allowedFields = new Set(['enabled', ...Object.keys(definition.config)]);
|
|
12587
|
-
for (const field of Object.keys(declaration)) {
|
|
12588
|
-
if (!allowedFields.has(field))
|
|
12589
|
-
throw new Error(`${itemLabel} 包含未知字段:${field}`);
|
|
12590
|
-
}
|
|
12591
|
-
if (typeof declaration.enabled !== 'boolean')
|
|
12592
|
-
throw new Error(`${itemLabel}.enabled 必须是 boolean`);
|
|
12593
|
-
let useOfficialDomain = false;
|
|
12594
|
-
if (key === 'network') {
|
|
12595
|
-
if (declaration.useOfficialDomain !== undefined && typeof declaration.useOfficialDomain !== 'boolean') {
|
|
12596
|
-
throw new Error(`${itemLabel}.useOfficialDomain 必须是 boolean`);
|
|
12597
|
-
}
|
|
12598
|
-
useOfficialDomain = declaration.useOfficialDomain === true;
|
|
12599
|
-
}
|
|
12600
|
-
if (key === 'post') {
|
|
12601
|
-
for (const field of ['read', 'write']) {
|
|
12602
|
-
if (declaration[field] !== undefined && typeof declaration[field] !== 'boolean') {
|
|
12603
|
-
throw new Error(`${itemLabel}.${field} 必须是 boolean`);
|
|
12604
|
-
}
|
|
12605
|
-
}
|
|
12606
|
-
if (declaration.enabled)
|
|
12607
|
-
permissions.post = { enabled: true, read: declaration.read === true, write: declaration.write === true };
|
|
12608
|
-
continue;
|
|
12609
|
-
}
|
|
12610
|
-
if (key === 'user_game_data') {
|
|
12611
|
-
// 即使声明关闭也校验资源清单:enabled:false 不能隐藏非法字段。
|
|
12612
|
-
const resources = parseUserGameDataResources(declaration.resources, itemLabel);
|
|
12613
|
-
if (!declaration.enabled)
|
|
12614
|
-
continue;
|
|
12615
|
-
permissions.user_game_data = { enabled: true, resources };
|
|
12616
|
-
continue;
|
|
12617
|
-
}
|
|
12618
|
-
if (!declaration.enabled)
|
|
12619
|
-
continue;
|
|
12620
|
-
permissions[key] = key === 'network' ? { enabled: true, useOfficialDomain } : { enabled: true };
|
|
12621
|
-
}
|
|
12622
|
-
return { declared: true, permissions: permissions };
|
|
12623
|
-
}
|
|
12624
|
-
/**
|
|
12625
|
-
* 校验 Manifest 中的精确资源清单。
|
|
12626
|
-
*
|
|
12627
|
-
* @param value - `user_game_data.resources`;必须显式提供对象,空对象表示不请求任何资源。
|
|
12628
|
-
* @param itemLabel - 报错时使用的字段路径。
|
|
12629
|
-
* @returns 按固定顺序输出的已发布资源与规范化用途。
|
|
12630
|
-
* @throws 非对象、未开放 key 或非法用途直接报错。
|
|
12631
|
-
*/
|
|
12632
|
-
function parseUserGameDataResources(value, itemLabel) {
|
|
12633
|
-
try {
|
|
12634
|
-
return parseUserGameDataResourceDeclarations(value);
|
|
12635
|
-
}
|
|
12636
|
-
catch (error) {
|
|
12637
|
-
throw new Error(`${itemLabel}.${error.message}`);
|
|
12638
|
-
}
|
|
12639
|
-
}
|
|
12640
|
-
function requiresExplicitPermissions(sdkVersion) {
|
|
12641
|
-
const parsed = semverExports.parse(sdkVersion);
|
|
12642
|
-
if (!parsed)
|
|
12643
|
-
throw new Error(`sdkVersion 必须是合法 SemVer:${sdkVersion}`);
|
|
12644
|
-
return parsed.major > 0 || parsed.minor >= 9;
|
|
12645
|
-
}
|
|
12646
|
-
function isRecord$3(value) {
|
|
12647
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
12648
|
-
}
|
|
12649
|
-
|
|
12650
12741
|
/**
|
|
12651
12742
|
* `package.json#heybox.platforms` 接受的平台值,顺序同时是 Manifest 的规范化输出顺序。
|
|
12652
12743
|
*
|
|
@@ -12701,6 +12792,7 @@ function renderMiniappManifest(manifest) {
|
|
|
12701
12792
|
const category = parseMiniappCategory(manifest.category, 'manifest.category');
|
|
12702
12793
|
const bindAppIds = parseMiniappBindAppIds(manifest.bindAppIds, { sourceLabel: 'manifest.bindAppIds' });
|
|
12703
12794
|
const desc = parseMiniappDesc(manifest.desc, 'manifest.desc');
|
|
12795
|
+
validateManifestRooms(manifest);
|
|
12704
12796
|
const output = {
|
|
12705
12797
|
version: manifest.version,
|
|
12706
12798
|
sdkVersion: manifest.sdkVersion,
|
|
@@ -12708,6 +12800,7 @@ function renderMiniappManifest(manifest) {
|
|
|
12708
12800
|
platforms,
|
|
12709
12801
|
...(manifest.permissions === undefined ? {} : { permissions: manifest.permissions }),
|
|
12710
12802
|
...(manifest.companions === undefined ? {} : { companions: manifest.companions }),
|
|
12803
|
+
...(manifest.roomDefinitions === undefined ? {} : { roomDefinitions: manifest.roomDefinitions }),
|
|
12711
12804
|
...(manifest.workspaceCards === undefined ? {} : { workspaceCards: manifest.workspaceCards }),
|
|
12712
12805
|
...(window === undefined ? {} : { window }),
|
|
12713
12806
|
...(bindAppIds.length === 0 ? {} : { bindAppIds }),
|
|
@@ -12817,6 +12910,14 @@ function getMiniappManifestVersionError(version) {
|
|
|
12817
12910
|
}
|
|
12818
12911
|
return undefined;
|
|
12819
12912
|
}
|
|
12913
|
+
function validateManifestRooms(manifest) {
|
|
12914
|
+
const refs = manifest.roomDefinitions;
|
|
12915
|
+
if (refs === undefined)
|
|
12916
|
+
return;
|
|
12917
|
+
assertRoomReferences(refs);
|
|
12918
|
+
if (Object.keys(refs).length && !manifest.permissions?.cloud_rooms?.enabled)
|
|
12919
|
+
throw new Error('Room 需要声明 cloud_rooms 权限');
|
|
12920
|
+
}
|
|
12820
12921
|
|
|
12821
12922
|
function findNearestPackageJsonPath(startDir) {
|
|
12822
12923
|
let current = path.resolve(startDir);
|
|
@@ -12931,6 +13032,22 @@ function readMiniappWorkspaceCardsFromPackageJson(root) {
|
|
|
12931
13032
|
const { packageJson, packageJsonPath } = readMiniappPackageJson(root, false);
|
|
12932
13033
|
return { declaration: readMiniappHeyboxConfig(packageJson)?.workspaceCards, projectRoot: path.dirname(packageJsonPath) };
|
|
12933
13034
|
}
|
|
13035
|
+
function readMiniappRoomDefinitionsFromBuild(root) {
|
|
13036
|
+
const filename = path.join(root, '.hb-sdk/rooms/references.json');
|
|
13037
|
+
if (!node_fs.existsSync(filename))
|
|
13038
|
+
return undefined;
|
|
13039
|
+
try {
|
|
13040
|
+
const raw = node_fs.readFileSync(filename);
|
|
13041
|
+
if (raw.length > 4096)
|
|
13042
|
+
throw new Error('Room 引用文件过大');
|
|
13043
|
+
const refs = JSON.parse(raw.toString('utf8'));
|
|
13044
|
+
assertRoomReferences(refs);
|
|
13045
|
+
return refs;
|
|
13046
|
+
}
|
|
13047
|
+
catch (cause) {
|
|
13048
|
+
throw new Error(`无法读取 Room 引用文件 ${filename},请重新运行 hb-sdk build:${formatReason(cause)}`, { cause });
|
|
13049
|
+
}
|
|
13050
|
+
}
|
|
12934
13051
|
|
|
12935
13052
|
/** 检查原生入口的文件格式与目标架构;文件后缀和执行位不能代替此门禁。 */
|
|
12936
13053
|
function assertCompanionExecutable(bytes, target) {
|
|
@@ -22658,6 +22775,11 @@ function miniappManifest() {
|
|
|
22658
22775
|
let companionArtifactAccessToken = parseDevAccessToken(process.env[HB_SDK_COMPANION_ARTIFACT_ACCESS_TOKEN_ENV]);
|
|
22659
22776
|
let miniProgramManifestAccessToken = parseDevAccessToken(process.env[HB_SDK_MINI_PROGRAM_MANIFEST_ACCESS_TOKEN_ENV]);
|
|
22660
22777
|
let root = process.cwd();
|
|
22778
|
+
let cloudRooms;
|
|
22779
|
+
function hasCloudRooms() {
|
|
22780
|
+
return cloudRooms ??= declaresCloudRooms(readMiniappPermissionsFromPackageJson(root, resolveSdkVersion()));
|
|
22781
|
+
}
|
|
22782
|
+
const privateRoomsDirectory = /(?:^|[\\/])\.hb-sdk[\\/]rooms[\\/]/;
|
|
22661
22783
|
let outDir = 'dist';
|
|
22662
22784
|
let command = 'build';
|
|
22663
22785
|
let resolvedConfig;
|
|
@@ -22668,6 +22790,21 @@ function miniappManifest() {
|
|
|
22668
22790
|
let priorBuildError;
|
|
22669
22791
|
return {
|
|
22670
22792
|
name: 'heybox-miniapp-manifest',
|
|
22793
|
+
resolveId(source) {
|
|
22794
|
+
if (privateRoomsDirectory.test(source) || (/\.room\.json(?:\?|$)/i.test(source) && hasCloudRooms()))
|
|
22795
|
+
throw new Error('私有 Room 规则不能导入客户端,请导入 generated/rooms/*.contract');
|
|
22796
|
+
return null;
|
|
22797
|
+
},
|
|
22798
|
+
generateBundle(_options, bundle) {
|
|
22799
|
+
for (const [name, file] of Object.entries(bundle)) {
|
|
22800
|
+
const source = file.code ?? (typeof file.source === 'string' ? file.source : file.source ? new TextDecoder().decode(file.source) : '');
|
|
22801
|
+
if (privateRoomsDirectory.test(name) || ((/\.room\.json$/i.test(name) || source.includes('hb-room-relay/1')) && hasCloudRooms())) {
|
|
22802
|
+
// generateBundle 发生在 buildEnd 之后,需保存此错误,防止 closeBundle 用缺文件覆盖它。
|
|
22803
|
+
priorBuildError = new Error('构建产物包含私有 Room 规则');
|
|
22804
|
+
throw priorBuildError;
|
|
22805
|
+
}
|
|
22806
|
+
}
|
|
22807
|
+
},
|
|
22671
22808
|
config(config, env) {
|
|
22672
22809
|
assertMiniappViteBase(config.base);
|
|
22673
22810
|
// command 在本钩子时序早于 configResolved,必须取自 env 命令而非闭包;
|
|
@@ -22700,6 +22837,7 @@ function miniappManifest() {
|
|
|
22700
22837
|
}
|
|
22701
22838
|
}
|
|
22702
22839
|
root = resolved.root;
|
|
22840
|
+
cloudRooms = undefined;
|
|
22703
22841
|
outDir = resolved.build.outDir;
|
|
22704
22842
|
command = resolved.command;
|
|
22705
22843
|
if (command === 'serve') {
|
|
@@ -23097,6 +23235,7 @@ function miniappManifest() {
|
|
|
23097
23235
|
const manifestPath = path.join(outputRoot, 'manifest.json');
|
|
23098
23236
|
const companions = prepareMiniappCompanions(companionDeclarations, { root: companionConfig.projectRoot, outputRoot, platforms });
|
|
23099
23237
|
node_fs.mkdirSync(path.dirname(manifestPath), { recursive: true });
|
|
23238
|
+
const roomDefinitions = declaresCloudRooms(parsedPermissions) ? readMiniappRoomDefinitionsFromBuild(root) : undefined;
|
|
23100
23239
|
const manifestText = renderMiniappManifest({
|
|
23101
23240
|
...(desc === undefined ? {} : { desc }),
|
|
23102
23241
|
version,
|
|
@@ -23105,6 +23244,7 @@ function miniappManifest() {
|
|
|
23105
23244
|
...(category === undefined ? {} : { category }),
|
|
23106
23245
|
...(basicInfo === undefined ? {} : basicInfo),
|
|
23107
23246
|
...(parsedPermissions.permissions === undefined ? {} : { permissions: parsedPermissions.permissions }),
|
|
23247
|
+
...(roomDefinitions === undefined ? {} : { roomDefinitions }),
|
|
23108
23248
|
...(companions === undefined ? {} : { companions }),
|
|
23109
23249
|
...(workspaceCards === undefined ? {} : { workspaceCards }),
|
|
23110
23250
|
...(windowDeclaration === undefined ? {} : { window: windowDeclaration }),
|
|
@@ -23175,11 +23315,13 @@ async function prepareDevSnapshot(root, outDir, platforms, declarations, workspa
|
|
|
23175
23315
|
const sourcePath = path.join(snapshotRoot, ...artifactPath.split('/'));
|
|
23176
23316
|
artifacts.set(artifactPath, { path: artifactPath, size: node_fs.lstatSync(sourcePath).size, sourcePath });
|
|
23177
23317
|
}
|
|
23318
|
+
const roomDefinitions = declaresCloudRooms({ permissions }) ? readMiniappRoomDefinitionsFromBuild(root) : undefined;
|
|
23178
23319
|
const manifest = {
|
|
23179
23320
|
version,
|
|
23180
23321
|
sdkVersion,
|
|
23181
23322
|
platforms,
|
|
23182
23323
|
...(permissions === undefined ? {} : { permissions }),
|
|
23324
|
+
...(roomDefinitions === undefined ? {} : { roomDefinitions }),
|
|
23183
23325
|
...(companions === undefined ? {} : { companions }),
|
|
23184
23326
|
...(workspaceCardsManifest === undefined ? {} : { workspaceCards: workspaceCardsManifest }),
|
|
23185
23327
|
...(windowDeclaration === undefined ? {} : { window: windowDeclaration }),
|