@heybox/hb-sdk 0.8.0-alpha.3 → 0.8.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/CHANGELOG.md +136 -422
- package/README.md +28 -18
- package/dist/cli-chunks/{build-qWzAbpS7.cjs → build-PYCNacya.cjs} +8 -5
- package/dist/cli-chunks/{context-CtS2Thp0.cjs → context-m2W2XbL0.cjs} +42 -59
- package/dist/cli-chunks/{create-PV5ua977.cjs → create-BdAg3WGA.cjs} +2 -2
- package/dist/cli-chunks/{dev-CwKbAm_H.cjs → dev-CyZuw7Yn.cjs} +76 -64
- package/dist/cli-chunks/{doctor-tJUGOYrm.cjs → doctor-DU8rCfUF.cjs} +1 -1
- package/dist/cli-chunks/{index-DVuD75Hr.cjs → index-DATObqzK.cjs} +2 -2
- package/dist/cli-chunks/{index-De687C6-.cjs → index-MMW2ibQm.cjs} +32 -21
- package/dist/cli-chunks/{index.esm-B-4yrLNm.cjs → index.esm-BiAaAUFC.cjs} +8 -8
- package/dist/cli-chunks/{login-DolpqD8K.cjs → login-B3TThMss.cjs} +2 -2
- package/dist/cli-chunks/{project-vite-1rvkK-M8.cjs → project-vite-BQj8YLI4.cjs} +1 -1
- package/dist/cli-chunks/{remote-rIAQE_G2.cjs → remote-DNvI7tHH.cjs} +57 -25
- package/dist/cli-chunks/{runtime-gate-DFjw66kF.cjs → runtime-gate-BEFp1w_s.cjs} +11 -3
- package/dist/cli-chunks/{runtime-permission-env-CjsCe5bp.cjs → runtime-permission-env-CtL8rsjB.cjs} +351 -0
- package/dist/cli-chunks/{session-CzaM2Cq3.cjs → session-DjBkjaF8.cjs} +1 -1
- package/dist/cli-chunks/{skill-CM40_9WH.cjs → skill-cR_wnaw2.cjs} +2 -2
- package/dist/cli-chunks/{version-Bz-AfXQU.cjs → version-yEn1E2Bg.cjs} +1 -1
- package/dist/cli.cjs +1 -1
- package/dist/devtools/browser-dev-host/assets/browser-dev-host-TzYf9L6C.js +99 -0
- package/dist/devtools/browser-dev-host/assets/{index-CeP6SLB3.js → index-C5MZZDa5.js} +4 -4
- package/dist/devtools/browser-dev-host/assets/index-P-ra4m1y.css +1 -0
- package/dist/devtools/browser-dev-host/assets/workbench-state-BwV7bm4n.js +5 -0
- package/dist/devtools/browser-dev-host/index.html +3 -3
- package/dist/index.cjs.js +100 -2
- package/dist/index.esm.js +100 -2
- package/dist/protocol.cjs.js +189 -47
- package/dist/protocol.esm.js +189 -47
- package/dist/templates/{vue3-vite-ts → vanilla-vite-js}/.gitignore.ejs +0 -1
- package/dist/templates/vanilla-vite-js/README.md.ejs +14 -0
- package/dist/templates/vanilla-vite-js/index.html.ejs +20 -0
- package/dist/templates/vanilla-vite-js/package.json.ejs +22 -0
- package/dist/templates/vanilla-vite-js/src/assets/heybox-logo.svg +8 -0
- package/dist/templates/vanilla-vite-js/src/main.js +39 -0
- package/dist/templates/vanilla-vite-js/src/styles.css +155 -0
- package/dist/templates/{vue3-vite-ts/vite.config.ts → vanilla-vite-js/vite.config.js} +1 -2
- package/dist/vite.cjs.js +281 -13
- package/dist/vite.esm.js +281 -13
- package/package.json +13 -9
- package/skill/SKILL.md +8 -9
- package/skill/references/api-protocol.md +1 -3
- package/skill/references/api-root.md +65 -21
- package/skill/references/cli.md +17 -5
- package/skill/references/examples.md +3 -3
- package/skill/references/recipes.md +40 -41
- package/skill/references/safety-boundaries.md +9 -5
- package/skill/skill.json +5 -5
- package/types/core/mini-dev-console.d.ts +36 -0
- package/types/miniapp-manifest/index.d.ts +1 -0
- package/types/miniapp-manifest/node.d.ts +3 -0
- package/types/miniapp-manifest/permissions.d.ts +37 -0
- package/types/miniapp-manifest/schema.d.ts +5 -0
- package/types/modules/share/index.d.ts +1 -1
- package/types/modules/share/show-share-menu.d.ts +1 -1
- package/types/modules/share/types.d.ts +2 -4
- package/types/vite/index.d.ts +3 -1
- package/dist/devtools/browser-dev-host/assets/browser-dev-host-uq-Wac6k.js +0 -97
- package/dist/devtools/browser-dev-host/assets/index-KD2f3Jdz.css +0 -1
- package/dist/devtools/browser-dev-host/assets/workbench-state-D-1U0JRq.js +0 -5
- package/dist/templates/vue3-vite-ts/README.md.ejs +0 -47
- package/dist/templates/vue3-vite-ts/index.html.ejs +0 -12
- package/dist/templates/vue3-vite-ts/package.json.ejs +0 -33
- package/dist/templates/vue3-vite-ts/src/App.vue +0 -78
- package/dist/templates/vue3-vite-ts/src/__tests__/App.spec.ts +0 -148
- package/dist/templates/vue3-vite-ts/src/auth-handoff.ts +0 -46
- package/dist/templates/vue3-vite-ts/src/main.ts +0 -5
- package/dist/templates/vue3-vite-ts/src/styles.css +0 -60
- package/dist/templates/vue3-vite-ts/src/vite-env.d.ts +0 -1
- package/dist/templates/vue3-vite-ts/tsconfig.app.json +0 -17
- package/dist/templates/vue3-vite-ts/tsconfig.json +0 -11
- package/dist/templates/vue3-vite-ts/tsconfig.node.json +0 -11
- package/dist/templates/vue3-vite-ts/vitest.config.ts +0 -10
package/dist/cli-chunks/{runtime-permission-env-CjsCe5bp.cjs → runtime-permission-env-CtL8rsjB.cjs}
RENAMED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var fs = require('node:fs');
|
|
4
|
+
var path = require('node:path');
|
|
5
|
+
var version = require('./version-yEn1E2Bg.cjs');
|
|
3
6
|
var node_async_hooks = require('node:async_hooks');
|
|
4
7
|
|
|
5
8
|
var re = {exports: {}};
|
|
@@ -2787,6 +2790,285 @@ function requireSemver () {
|
|
|
2787
2790
|
|
|
2788
2791
|
var semverExports = requireSemver();
|
|
2789
2792
|
|
|
2793
|
+
const MINI_PROGRAM_PERMISSION_KEYS = [
|
|
2794
|
+
'userInfo',
|
|
2795
|
+
'steamLibrary',
|
|
2796
|
+
'share',
|
|
2797
|
+
'storage',
|
|
2798
|
+
'filesystem',
|
|
2799
|
+
'clipboard',
|
|
2800
|
+
'leaderboard',
|
|
2801
|
+
'network',
|
|
2802
|
+
];
|
|
2803
|
+
const MINI_PROGRAM_PERMISSION_CATALOG = [
|
|
2804
|
+
{
|
|
2805
|
+
key: 'userInfo',
|
|
2806
|
+
name: '用户信息',
|
|
2807
|
+
description: '登录小程序并读取当前用户的授权信息。',
|
|
2808
|
+
access: 'declaration',
|
|
2809
|
+
risk: 'medium',
|
|
2810
|
+
config: {},
|
|
2811
|
+
methods: ['auth.login', 'user.getInfo'],
|
|
2812
|
+
conditions: ['继续执行黑盒登录、用户授权和可信手势规则。'],
|
|
2813
|
+
},
|
|
2814
|
+
{
|
|
2815
|
+
key: 'steamLibrary',
|
|
2816
|
+
name: 'Steam 游戏库',
|
|
2817
|
+
description: '读取当前用户授权的 Steam 游戏库。',
|
|
2818
|
+
access: 'declaration',
|
|
2819
|
+
risk: 'high',
|
|
2820
|
+
config: {},
|
|
2821
|
+
methods: ['user.getSteamGameList'],
|
|
2822
|
+
conditions: ['继续执行账号绑定和数据可用性规则。'],
|
|
2823
|
+
},
|
|
2824
|
+
{
|
|
2825
|
+
key: 'share',
|
|
2826
|
+
name: '分享',
|
|
2827
|
+
description: '使用小程序分享、分享菜单和截图能力。',
|
|
2828
|
+
access: 'declaration',
|
|
2829
|
+
risk: 'medium',
|
|
2830
|
+
config: {},
|
|
2831
|
+
methods: ['share.copyLink', 'share.showShareMenu', 'share.screenshot'],
|
|
2832
|
+
conditions: ['继续执行分享参数校验和 Host 支持检查。'],
|
|
2833
|
+
},
|
|
2834
|
+
{
|
|
2835
|
+
key: 'storage',
|
|
2836
|
+
name: '键值存储',
|
|
2837
|
+
description: '读写按小程序隔离的简单键值数据。',
|
|
2838
|
+
access: 'declaration',
|
|
2839
|
+
risk: 'medium',
|
|
2840
|
+
config: {},
|
|
2841
|
+
methods: ['storage.getStorage', 'storage.setStorage'],
|
|
2842
|
+
conditions: ['仅用于简单键值存储,不包含文件系统。'],
|
|
2843
|
+
},
|
|
2844
|
+
{
|
|
2845
|
+
key: 'filesystem',
|
|
2846
|
+
name: '文件系统',
|
|
2847
|
+
description: '访问小程序沙盒文件和用户选择的外部文件。',
|
|
2848
|
+
access: 'declaration',
|
|
2849
|
+
risk: 'high',
|
|
2850
|
+
config: {},
|
|
2851
|
+
methods: [
|
|
2852
|
+
'network.download',
|
|
2853
|
+
'files.pickFiles',
|
|
2854
|
+
'files.pickDirectory',
|
|
2855
|
+
'files.saveFile',
|
|
2856
|
+
'file.create',
|
|
2857
|
+
'file.remove',
|
|
2858
|
+
'file.exists',
|
|
2859
|
+
'file.readText',
|
|
2860
|
+
'file.writeText',
|
|
2861
|
+
'file.readBytes',
|
|
2862
|
+
'file.writeBytes',
|
|
2863
|
+
'file.stat',
|
|
2864
|
+
'directory.create',
|
|
2865
|
+
'directory.remove',
|
|
2866
|
+
'directory.exists',
|
|
2867
|
+
'directory.list',
|
|
2868
|
+
],
|
|
2869
|
+
conditions: ['外部文件继续要求有效的用户选择、会话句柄和匹配的读写模式。'],
|
|
2870
|
+
},
|
|
2871
|
+
{
|
|
2872
|
+
key: 'clipboard',
|
|
2873
|
+
name: '剪贴板',
|
|
2874
|
+
description: '向系统剪贴板写入文本。',
|
|
2875
|
+
access: 'declaration',
|
|
2876
|
+
risk: 'medium',
|
|
2877
|
+
config: {},
|
|
2878
|
+
methods: ['device.setClipboard'],
|
|
2879
|
+
conditions: ['继续执行文本长度和 Host 支持限制。'],
|
|
2880
|
+
},
|
|
2881
|
+
{
|
|
2882
|
+
key: 'leaderboard',
|
|
2883
|
+
name: '排行榜',
|
|
2884
|
+
description: '读写小程序云排行榜。',
|
|
2885
|
+
access: 'declaration',
|
|
2886
|
+
risk: 'medium',
|
|
2887
|
+
config: {},
|
|
2888
|
+
methods: [
|
|
2889
|
+
'cloud.leaderboard.submit',
|
|
2890
|
+
'cloud.leaderboard.getList',
|
|
2891
|
+
'cloud.leaderboard.getCurrentUserEntry',
|
|
2892
|
+
'cloud.leaderboard.deleteCurrentUserEntry',
|
|
2893
|
+
'cloud.leaderboard.getInfo',
|
|
2894
|
+
],
|
|
2895
|
+
conditions: ['排行榜必须已创建,用户和资源规则保持不变。'],
|
|
2896
|
+
},
|
|
2897
|
+
{
|
|
2898
|
+
key: 'network',
|
|
2899
|
+
name: '网络',
|
|
2900
|
+
description: '通过 network 模块请求或下载外部资源。',
|
|
2901
|
+
access: 'platform-approval',
|
|
2902
|
+
risk: 'high',
|
|
2903
|
+
config: {
|
|
2904
|
+
useOfficialDomain: {
|
|
2905
|
+
type: 'boolean',
|
|
2906
|
+
required: false,
|
|
2907
|
+
default: false,
|
|
2908
|
+
description: '是否申请访问小黑盒官方域名。',
|
|
2909
|
+
},
|
|
2910
|
+
},
|
|
2911
|
+
methods: ['network.request', 'network.download'],
|
|
2912
|
+
conditions: ['声明后仍需平台批准,并继续执行网络安全策略。'],
|
|
2913
|
+
},
|
|
2914
|
+
];
|
|
2915
|
+
new Set(MINI_PROGRAM_PERMISSION_KEYS);
|
|
2916
|
+
|
|
2917
|
+
const MANAGED_RUNTIME_PERMISSION_KEYS = new Set(MINI_PROGRAM_PERMISSION_KEYS);
|
|
2918
|
+
function isManagedMiniProgramRuntimePermissionKey(key) {
|
|
2919
|
+
return MANAGED_RUNTIME_PERMISSION_KEYS.has(key);
|
|
2920
|
+
}
|
|
2921
|
+
function parseMiniProgramRuntimePermissions(snapshot) {
|
|
2922
|
+
if (!isRecord$2(snapshot) || snapshot.schema_version !== 1 || !Array.isArray(snapshot.entries)) {
|
|
2923
|
+
return { valid: false, permissions: {} };
|
|
2924
|
+
}
|
|
2925
|
+
if (snapshot.revision !== undefined && (typeof snapshot.revision !== 'number' || !Number.isInteger(snapshot.revision) || snapshot.revision < 0)) {
|
|
2926
|
+
return { valid: false, permissions: {} };
|
|
2927
|
+
}
|
|
2928
|
+
const seenKeys = new Set();
|
|
2929
|
+
const permissions = {};
|
|
2930
|
+
for (const rawEntry of snapshot.entries) {
|
|
2931
|
+
if (!isRecord$2(rawEntry) || typeof rawEntry.key !== 'string' || !rawEntry.key.trim()) {
|
|
2932
|
+
return { valid: false, permissions: {} };
|
|
2933
|
+
}
|
|
2934
|
+
const inputKey = rawEntry.key.trim();
|
|
2935
|
+
const key = inputKey === 'network.request' ? 'network' : inputKey;
|
|
2936
|
+
if (seenKeys.has(key) || (rawEntry.status !== 'enabled' && rawEntry.status !== 'disabled')) {
|
|
2937
|
+
return { valid: false, permissions: {} };
|
|
2938
|
+
}
|
|
2939
|
+
seenKeys.add(key);
|
|
2940
|
+
if (!isManagedMiniProgramRuntimePermissionKey(key)) {
|
|
2941
|
+
if (!isRecord$2(rawEntry.config))
|
|
2942
|
+
return { valid: false, permissions: {} };
|
|
2943
|
+
continue;
|
|
2944
|
+
}
|
|
2945
|
+
if (key === 'network') {
|
|
2946
|
+
const config = rawEntry.config;
|
|
2947
|
+
if (!isRecord$2(config) || typeof config.useOfficialDomain !== 'boolean') {
|
|
2948
|
+
return { valid: false, permissions: {} };
|
|
2949
|
+
}
|
|
2950
|
+
permissions[key] = {
|
|
2951
|
+
key,
|
|
2952
|
+
status: rawEntry.status,
|
|
2953
|
+
config: { useOfficialDomain: config.useOfficialDomain },
|
|
2954
|
+
};
|
|
2955
|
+
continue;
|
|
2956
|
+
}
|
|
2957
|
+
if (rawEntry.config !== null && rawEntry.config !== undefined && (!isRecord$2(rawEntry.config) || Object.keys(rawEntry.config).length > 0)) {
|
|
2958
|
+
return { valid: false, permissions: {} };
|
|
2959
|
+
}
|
|
2960
|
+
permissions[key] = {
|
|
2961
|
+
key,
|
|
2962
|
+
status: rawEntry.status,
|
|
2963
|
+
config: {},
|
|
2964
|
+
};
|
|
2965
|
+
}
|
|
2966
|
+
return { valid: true, permissions };
|
|
2967
|
+
}
|
|
2968
|
+
function isRecord$2(value) {
|
|
2969
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
2970
|
+
}
|
|
2971
|
+
|
|
2972
|
+
const MINIAPP_PERMISSION_KEYS = MINI_PROGRAM_PERMISSION_KEYS;
|
|
2973
|
+
function parseMiniappPermissions(value, options) {
|
|
2974
|
+
const sourceLabel = options.sourceLabel ?? 'package.json#heybox.permissions';
|
|
2975
|
+
if (!options.present) {
|
|
2976
|
+
if (requiresExplicitPermissions(options.sdkVersion)) {
|
|
2977
|
+
throw new Error(`${sourceLabel} 在 @heybox/hb-sdk ${options.sdkVersion} 中必须声明;无权限需求时请配置空对象 {}`);
|
|
2978
|
+
}
|
|
2979
|
+
return { declared: false };
|
|
2980
|
+
}
|
|
2981
|
+
if (!isRecord$1(value)) {
|
|
2982
|
+
throw new Error(`${sourceLabel} 必须是 JSON 对象`);
|
|
2983
|
+
}
|
|
2984
|
+
const knownKeys = new Set(MINIAPP_PERMISSION_KEYS);
|
|
2985
|
+
for (const key of Object.keys(value)) {
|
|
2986
|
+
if (!knownKeys.has(key))
|
|
2987
|
+
throw new Error(`${sourceLabel} 包含未知权限:${key}`);
|
|
2988
|
+
}
|
|
2989
|
+
const permissions = {};
|
|
2990
|
+
for (const key of MINIAPP_PERMISSION_KEYS) {
|
|
2991
|
+
if (!Object.prototype.hasOwnProperty.call(value, key))
|
|
2992
|
+
continue;
|
|
2993
|
+
const declaration = value[key];
|
|
2994
|
+
const itemLabel = `${sourceLabel}.${key}`;
|
|
2995
|
+
if (!isRecord$1(declaration))
|
|
2996
|
+
throw new Error(`${itemLabel} 必须是 JSON 对象`);
|
|
2997
|
+
const definition = MINI_PROGRAM_PERMISSION_CATALOG.find((item) => item.key === key);
|
|
2998
|
+
if (!definition)
|
|
2999
|
+
throw new Error(`权限目录缺少定义:${key}`);
|
|
3000
|
+
const allowedFields = new Set(['enabled', ...Object.keys(definition.config)]);
|
|
3001
|
+
for (const field of Object.keys(declaration)) {
|
|
3002
|
+
if (!allowedFields.has(field))
|
|
3003
|
+
throw new Error(`${itemLabel} 包含未知字段:${field}`);
|
|
3004
|
+
}
|
|
3005
|
+
if (typeof declaration.enabled !== 'boolean')
|
|
3006
|
+
throw new Error(`${itemLabel}.enabled 必须是 boolean`);
|
|
3007
|
+
let useOfficialDomain = false;
|
|
3008
|
+
if (key === 'network') {
|
|
3009
|
+
if (declaration.useOfficialDomain !== undefined && typeof declaration.useOfficialDomain !== 'boolean') {
|
|
3010
|
+
throw new Error(`${itemLabel}.useOfficialDomain 必须是 boolean`);
|
|
3011
|
+
}
|
|
3012
|
+
useOfficialDomain = declaration.useOfficialDomain === true;
|
|
3013
|
+
}
|
|
3014
|
+
if (!declaration.enabled)
|
|
3015
|
+
continue;
|
|
3016
|
+
permissions[key] = key === 'network' ? { enabled: true, useOfficialDomain } : { enabled: true };
|
|
3017
|
+
}
|
|
3018
|
+
return { declared: true, permissions: permissions };
|
|
3019
|
+
}
|
|
3020
|
+
function requiresExplicitPermissions(sdkVersion) {
|
|
3021
|
+
const parsed = semverExports.parse(sdkVersion);
|
|
3022
|
+
if (!parsed)
|
|
3023
|
+
throw new Error(`sdkVersion 必须是合法 SemVer:${sdkVersion}`);
|
|
3024
|
+
return parsed.major > 0 || parsed.minor >= 9;
|
|
3025
|
+
}
|
|
3026
|
+
function getMissingPermissionsWarning(sourceLabel = 'package.json#heybox.permissions') {
|
|
3027
|
+
return `${sourceLabel} 尚未声明。当前按 0.8 兼容行为构建;0.9.0 起将拒绝构建,请尽快补充权限声明(无权限需求时配置 {})。`;
|
|
3028
|
+
}
|
|
3029
|
+
function composeMiniappRuntimePermissions(local, approvals) {
|
|
3030
|
+
const parsedApprovals = parseMiniProgramRuntimePermissions(approvals);
|
|
3031
|
+
const approvalRevision = isRecord$1(approvals) && Number.isInteger(approvals.revision) ? approvals.revision : undefined;
|
|
3032
|
+
const views = [];
|
|
3033
|
+
const entries = [];
|
|
3034
|
+
for (const definition of MINI_PROGRAM_PERMISSION_CATALOG) {
|
|
3035
|
+
const declaration = local.permissions?.[definition.key];
|
|
3036
|
+
const declared = !local.declared || declaration?.enabled === true;
|
|
3037
|
+
if (definition.access === 'declaration') {
|
|
3038
|
+
views.push({ key: definition.key, access: definition.access, declared, approved: null, effective: declared });
|
|
3039
|
+
if (declared)
|
|
3040
|
+
entries.push({ key: definition.key, status: 'enabled', config: {} });
|
|
3041
|
+
continue;
|
|
3042
|
+
}
|
|
3043
|
+
const approval = parsedApprovals.valid ? parsedApprovals.permissions[definition.key] : undefined;
|
|
3044
|
+
const approved = approval?.status === 'enabled';
|
|
3045
|
+
const requestedOfficialDomain = declaration?.enabled === true && 'useOfficialDomain' in declaration && declaration.useOfficialDomain;
|
|
3046
|
+
const approvedOfficialDomain = approval?.config.useOfficialDomain === true;
|
|
3047
|
+
const effective = declared && approved;
|
|
3048
|
+
const effectiveOfficialDomain = effective && (local.declared ? requestedOfficialDomain : true) && approvedOfficialDomain;
|
|
3049
|
+
views.push({
|
|
3050
|
+
key: definition.key,
|
|
3051
|
+
access: definition.access,
|
|
3052
|
+
declared,
|
|
3053
|
+
approved,
|
|
3054
|
+
requestedConfig: { useOfficialDomain: requestedOfficialDomain },
|
|
3055
|
+
approvedConfig: { useOfficialDomain: approvedOfficialDomain },
|
|
3056
|
+
effective,
|
|
3057
|
+
effectiveConfig: { useOfficialDomain: effectiveOfficialDomain },
|
|
3058
|
+
});
|
|
3059
|
+
if (declared) {
|
|
3060
|
+
entries.push({ key: definition.key, status: effective ? 'enabled' : 'disabled', config: { useOfficialDomain: effectiveOfficialDomain } });
|
|
3061
|
+
}
|
|
3062
|
+
}
|
|
3063
|
+
return {
|
|
3064
|
+
runtimePermissions: { schema_version: 1, ...(approvalRevision === undefined ? {} : { revision: approvalRevision }), entries },
|
|
3065
|
+
views,
|
|
3066
|
+
};
|
|
3067
|
+
}
|
|
3068
|
+
function isRecord$1(value) {
|
|
3069
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
3070
|
+
}
|
|
3071
|
+
|
|
2790
3072
|
const MINIAPP_UPLOAD_SCOPE = 'activity';
|
|
2791
3073
|
const ACTIVITY_UPLOAD_KEY_MAX_LENGTH = 64;
|
|
2792
3074
|
const MINIAPP_UPLOAD_BATCH_SIZE = 50;
|
|
@@ -3063,6 +3345,68 @@ function compareBytes(left, right) {
|
|
|
3063
3345
|
return left.length - right.length;
|
|
3064
3346
|
}
|
|
3065
3347
|
|
|
3348
|
+
function findNearestPackageJsonPath(startDir) {
|
|
3349
|
+
let current = path.resolve(startDir);
|
|
3350
|
+
while (true) {
|
|
3351
|
+
const packageJsonPath = path.join(current, 'package.json');
|
|
3352
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
3353
|
+
return packageJsonPath;
|
|
3354
|
+
}
|
|
3355
|
+
const parent = path.dirname(current);
|
|
3356
|
+
if (parent === current) {
|
|
3357
|
+
return path.join(path.resolve(startDir), 'package.json');
|
|
3358
|
+
}
|
|
3359
|
+
current = parent;
|
|
3360
|
+
}
|
|
3361
|
+
}
|
|
3362
|
+
function readMiniappPermissionsFromPackageJson(root, sdkVersion) {
|
|
3363
|
+
const { packageJson } = readMiniappPackageJson(root);
|
|
3364
|
+
const heybox = packageJson.heybox;
|
|
3365
|
+
if (heybox !== undefined && !isRecord(heybox)) {
|
|
3366
|
+
throw new Error('@heybox/hb-sdk 提示:package.json#heybox 必须是 JSON 对象');
|
|
3367
|
+
}
|
|
3368
|
+
const present = isRecord(heybox) && Object.prototype.hasOwnProperty.call(heybox, 'permissions');
|
|
3369
|
+
return parseMiniappPermissions(isRecord(heybox) ? heybox.permissions : undefined, {
|
|
3370
|
+
present,
|
|
3371
|
+
sdkVersion,
|
|
3372
|
+
});
|
|
3373
|
+
}
|
|
3374
|
+
function resolveMiniappSdkVersion() {
|
|
3375
|
+
if (!version.HB_SDK_VERSION.startsWith('__HB_SDK_'))
|
|
3376
|
+
return version.HB_SDK_VERSION;
|
|
3377
|
+
const packageJson = JSON.parse(fs.readFileSync(path.resolve(__dirname, '..', '..', 'package.json'), 'utf8'));
|
|
3378
|
+
if (typeof packageJson.version !== 'string' || !packageJson.version)
|
|
3379
|
+
throw new Error('未能读取 @heybox/hb-sdk 当前版本号');
|
|
3380
|
+
return packageJson.version;
|
|
3381
|
+
}
|
|
3382
|
+
function readMiniappPackageJson(root, requireVersion) {
|
|
3383
|
+
const packageJsonPath = findNearestPackageJsonPath(root);
|
|
3384
|
+
let content;
|
|
3385
|
+
try {
|
|
3386
|
+
content = fs.readFileSync(packageJsonPath, 'utf8');
|
|
3387
|
+
}
|
|
3388
|
+
catch (error) {
|
|
3389
|
+
throw new Error(`@heybox/hb-sdk 读取 package.json 失败:${formatReason(error)}`);
|
|
3390
|
+
}
|
|
3391
|
+
let packageJson;
|
|
3392
|
+
try {
|
|
3393
|
+
packageJson = JSON.parse(content);
|
|
3394
|
+
}
|
|
3395
|
+
catch (error) {
|
|
3396
|
+
throw new Error(`@heybox/hb-sdk 解析 package.json 失败:${formatReason(error)}`);
|
|
3397
|
+
}
|
|
3398
|
+
return { packageJson, version: typeof packageJson.version === 'string' ? packageJson.version.trim() : '' };
|
|
3399
|
+
}
|
|
3400
|
+
function isRecord(value) {
|
|
3401
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
3402
|
+
}
|
|
3403
|
+
function formatReason(error) {
|
|
3404
|
+
if (error instanceof Error && error.message) {
|
|
3405
|
+
return error.message;
|
|
3406
|
+
}
|
|
3407
|
+
return String(error);
|
|
3408
|
+
}
|
|
3409
|
+
|
|
3066
3410
|
const HB_SDK_RUNTIME_USE_OFFICIAL_DOMAIN_ENV = 'HB_SDK_RUNTIME_USE_OFFICIAL_DOMAIN';
|
|
3067
3411
|
const HB_SDK_RUNTIME_PERMISSION_CONTEXT_ENV = 'HB_SDK_RUNTIME_PERMISSION_CONTEXT';
|
|
3068
3412
|
const VERIFIED_RUNTIME_PERMISSION_CONTEXT = 'verified';
|
|
@@ -3142,6 +3486,7 @@ exports.LIST_USER_MINIPROGRAM_LEADERBOARD_API_PATH = LIST_USER_MINIPROGRAM_LEADE
|
|
|
3142
3486
|
exports.LIST_USER_MINIPROGRAM_VERSION_API_PATH = LIST_USER_MINIPROGRAM_VERSION_API_PATH;
|
|
3143
3487
|
exports.MINIAPP_UPLOAD_BATCH_SIZE = MINIAPP_UPLOAD_BATCH_SIZE;
|
|
3144
3488
|
exports.MINIAPP_UPLOAD_SCOPE = MINIAPP_UPLOAD_SCOPE;
|
|
3489
|
+
exports.MINI_PROGRAM_PERMISSION_KEYS = MINI_PROGRAM_PERMISSION_KEYS;
|
|
3145
3490
|
exports.PRECHECK_USER_MINIPROGRAM_VERSION_API_PATH = PRECHECK_USER_MINIPROGRAM_VERSION_API_PATH;
|
|
3146
3491
|
exports.RELEASE_USER_MINIPROGRAM_VERSION_API_PATH = RELEASE_USER_MINIPROGRAM_VERSION_API_PATH;
|
|
3147
3492
|
exports.REOPEN_USER_MINIPROGRAM_API_PATH = REOPEN_USER_MINIPROGRAM_API_PATH;
|
|
@@ -3153,13 +3498,19 @@ exports.USER_MINIPROGRAM_ACCESS_STATUS_API_PATH = USER_MINIPROGRAM_ACCESS_STATUS
|
|
|
3153
3498
|
exports.USER_MINIPROGRAM_PREVIEW_ALLOWLIST_API_PATH = USER_MINIPROGRAM_PREVIEW_ALLOWLIST_API_PATH;
|
|
3154
3499
|
exports.USER_MINIPROGRAM_VERSION_PREVIEW_INFO_API_PATH = USER_MINIPROGRAM_VERSION_PREVIEW_INFO_API_PATH;
|
|
3155
3500
|
exports.WITHDRAW_USER_MINIPROGRAM_VERSION_API_PATH = WITHDRAW_USER_MINIPROGRAM_VERSION_API_PATH;
|
|
3501
|
+
exports.composeMiniappRuntimePermissions = composeMiniappRuntimePermissions;
|
|
3156
3502
|
exports.createMiniappArtifactFileHeader = createMiniappArtifactFileHeader;
|
|
3157
3503
|
exports.createMiniappArtifactSignatureHeader = createMiniappArtifactSignatureHeader;
|
|
3158
3504
|
exports.createMiniappPlatformCspEnv = createMiniappPlatformCspEnv;
|
|
3505
|
+
exports.getMissingPermissionsWarning = getMissingPermissionsWarning;
|
|
3159
3506
|
exports.normalizeRelativePath = normalizeRelativePath;
|
|
3507
|
+
exports.parseMiniProgramRuntimePermissions = parseMiniProgramRuntimePermissions;
|
|
3508
|
+
exports.parseMiniappPermissions = parseMiniappPermissions;
|
|
3160
3509
|
exports.prepareMiniappArtifactFiles = prepareMiniappArtifactFiles;
|
|
3510
|
+
exports.readMiniappPermissionsFromPackageJson = readMiniappPermissionsFromPackageJson;
|
|
3161
3511
|
exports.relativePathContainsNodeModulesSegment = relativePathContainsNodeModulesSegment;
|
|
3162
3512
|
exports.requireSemver = requireSemver;
|
|
3513
|
+
exports.resolveMiniappSdkVersion = resolveMiniappSdkVersion;
|
|
3163
3514
|
exports.resolveMiniappUploadSessionFiles = resolveMiniappUploadSessionFiles;
|
|
3164
3515
|
exports.semverExports = semverExports;
|
|
3165
3516
|
exports.shouldSkipMiniappPlatformCspFromEnv = shouldSkipMiniappPlatformCspFromEnv;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var path = require('node:path');
|
|
4
|
-
var version = require('./version-
|
|
4
|
+
var version = require('./version-yEn1E2Bg.cjs');
|
|
5
5
|
var childProcess = require('node:child_process');
|
|
6
6
|
var fs = require('node:fs/promises');
|
|
7
|
-
var index = require('./index-
|
|
7
|
+
var index = require('./index-MMW2ibQm.cjs');
|
|
8
8
|
require('node:module');
|
|
9
9
|
require('node:fs');
|
|
10
10
|
require('path');
|