@heybox/hb-sdk 0.7.5-alpha.0 → 0.8.0-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 +99 -352
- package/README.md +103 -26
- package/THIRD_PARTY_NOTICES.md +1755 -0
- package/dist/cli-chunks/{build-V1YBdpzY.cjs → build-aDJbiFqF.cjs} +9 -5
- package/dist/cli-chunks/{context-Ba1Je-wT.cjs → context-Dp36pZ9a.cjs} +39 -81
- package/dist/cli-chunks/{create-CKGjqo9E.cjs → create-P3g0ricz.cjs} +2 -2
- package/dist/cli-chunks/{dev-XopYKLYZ.cjs → dev-CisJkXuQ.cjs} +396 -576
- package/dist/cli-chunks/doctor-B-LF5-uj.cjs +65 -0
- package/dist/cli-chunks/{index-C9mpajVG.cjs → index-BDaeBI_B.cjs} +50 -30
- package/dist/cli-chunks/{index-DKWfX6Ut.cjs → index-CZGkk7fQ.cjs} +2 -2
- package/dist/cli-chunks/{index.esm-SXAQ3WVR.cjs → index.esm-NNLG29Tt.cjs} +8 -7
- package/dist/cli-chunks/{login-BVWicWqe.cjs → login-DTY5GolC.cjs} +2 -2
- package/dist/cli-chunks/{project-vite-CBb38HJ3.cjs → project-vite-DlCjHlu_.cjs} +1 -1
- package/dist/cli-chunks/{remote-BG1u0NKT.cjs → remote-BBMr7j8W.cjs} +61 -27
- package/dist/cli-chunks/{runtime-gate-CtV7rWyX.cjs → runtime-gate-BppCl1r3.cjs} +30 -3
- package/dist/cli-chunks/{runtime-permission-env-D-8_jPG3.cjs → runtime-permission-env-CqsTHeas.cjs} +364 -13
- package/dist/cli-chunks/{session-CJS_SEp9.cjs → session-CnGeZCRZ.cjs} +1 -1
- package/dist/cli-chunks/skill-B0yAnPOJ.cjs +83 -0
- package/dist/cli-chunks/version-DN5jrixS.cjs +8 -0
- package/dist/cli.cjs +1 -1
- package/dist/devtools/browser-dev-host/assets/browser-dev-host-BhZGUyYw.js +97 -0
- package/dist/devtools/browser-dev-host/assets/heybox-logo-CogNENsk.svg +6 -0
- package/dist/devtools/browser-dev-host/assets/index-DJFB5ySU.css +1 -0
- package/dist/devtools/browser-dev-host/assets/index-Dh9H1JOm.js +567 -0
- package/dist/devtools/browser-dev-host/assets/workbench-state-wHgWRb7I.js +5 -0
- package/dist/devtools/browser-dev-host/index.html +6 -435
- package/dist/index.cjs.js +1051 -91
- package/dist/index.esm.js +1051 -92
- package/dist/miniapp-publish.cjs.js +13 -13
- package/dist/miniapp-publish.esm.js +13 -13
- package/dist/protocol.cjs.js +381 -37
- package/dist/protocol.esm.js +355 -38
- 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 +256 -10
- package/dist/vite.esm.js +256 -11
- package/package.json +37 -11
- package/skill/SKILL.md +22 -20
- package/skill/references/api-protocol.md +112 -6
- package/skill/references/api-root.md +194 -30
- package/skill/references/cli.md +41 -24
- package/skill/references/examples.md +31 -2
- package/skill/references/llms-index.md +1 -1
- package/skill/references/recipes.md +139 -36
- package/skill/references/safety-boundaries.md +15 -6
- package/skill/skill.json +10 -5
- package/types/core/client.d.ts +17 -1
- package/types/core/errors.d.ts +5 -5
- package/types/core/sdk.d.ts +8 -5
- package/types/core/singleton.d.ts +59 -6
- package/types/index.d.ts +4 -2
- 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 +10 -0
- package/types/miniapp-publish/index.d.ts +8 -8
- package/types/modules/auth/index.d.ts +15 -1
- package/types/modules/cloud/index.d.ts +75 -5
- package/types/modules/device/index.d.ts +31 -3
- package/types/modules/files/index.d.ts +5 -0
- package/types/modules/files/registry.d.ts +35 -0
- package/types/modules/files/types.d.ts +159 -0
- package/types/modules/navigation/index.d.ts +46 -4
- package/types/modules/network/index.d.ts +72 -14
- package/types/modules/share/copy-link.d.ts +3 -3
- package/types/modules/share/index.d.ts +61 -5
- package/types/modules/share/screenshot.d.ts +3 -3
- package/types/modules/share/show-share-menu.d.ts +4 -4
- package/types/modules/share/types.d.ts +2 -4
- package/types/modules/storage/index.d.ts +38 -10
- package/types/modules/ui/index.d.ts +46 -4
- package/types/modules/user/get-info.d.ts +1 -1
- package/types/modules/user/index.d.ts +46 -4
- package/types/modules/user/steam-game-list.d.ts +2 -2
- package/types/modules/viewport/index.d.ts +36 -8
- package/types/protocol/capabilities.d.ts +2 -2
- package/types/protocol/constants.d.ts +1 -1
- package/types/protocol/guards.d.ts +1 -1
- package/types/protocol/types.d.ts +1 -1
- package/types/protocol.d.ts +4 -3
- package/types/skill-metadata.d.ts +0 -4
- package/types/vite/index.d.ts +15 -7
- package/dist/cli-chunks/doctor-BHbrYQqT.cjs +0 -204
- package/dist/devtools/browser-dev-host/main.js +0 -12158
- package/dist/templates/vue3-vite-ts/README.md.ejs +0 -45
- 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/skill/scripts/check-references.mjs +0 -14
- package/skill/scripts/markdown-sections.mjs +0 -36
- package/skill/scripts/package-skill.mjs +0 -60
- package/skill/scripts/package-skill.sh +0 -6
- package/skill/scripts/skill-metadata.mjs +0 -77
- package/skill/scripts/sync-agent-skills-payload.mjs +0 -359
- package/skill/scripts/sync-references.mjs +0 -792
- package/skill/scripts/validate-skill.mjs +0 -263
package/dist/cli-chunks/{runtime-permission-env-D-8_jPG3.cjs → runtime-permission-env-CqsTHeas.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-DN5jrixS.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;
|
|
@@ -2869,7 +3151,7 @@ function shouldUploadDistFile(relativePath) {
|
|
|
2869
3151
|
/**
|
|
2870
3152
|
* 校验构建产物路径和大小,并按路径 UTF-8 字节序排序。
|
|
2871
3153
|
*
|
|
2872
|
-
* @param files 待处理的构建产物文件。
|
|
3154
|
+
* @param files - 待处理的构建产物文件。
|
|
2873
3155
|
* @returns 保留输入附加字段的有序文件列表。
|
|
2874
3156
|
* @throws 路径不规范、路径重复或文件大小非法时抛出错误。
|
|
2875
3157
|
*/
|
|
@@ -2878,7 +3160,7 @@ function prepareMiniappArtifactFiles(files) {
|
|
|
2878
3160
|
throw new Error('构建产物文件数量超出签名协议上限');
|
|
2879
3161
|
}
|
|
2880
3162
|
const usedPaths = new Set();
|
|
2881
|
-
const prepared = files.map(file => {
|
|
3163
|
+
const prepared = files.map((file) => {
|
|
2882
3164
|
const relativePath = normalizeMiniappArtifactRelativePath(file.relativePath);
|
|
2883
3165
|
if (usedPaths.has(relativePath)) {
|
|
2884
3166
|
throw new Error(`构建产物包含重复文件路径:${relativePath}`);
|
|
@@ -2892,15 +3174,15 @@ function prepareMiniappArtifactFiles(files) {
|
|
|
2892
3174
|
/**
|
|
2893
3175
|
* 按服务端 session key 前缀校验最终上传路径的 UTF-8 字节长度。
|
|
2894
3176
|
*
|
|
2895
|
-
* @param files 待上传的构建产物文件。
|
|
2896
|
-
* @param options 小程序和长度限制配置。
|
|
3177
|
+
* @param files - 待上传的构建产物文件。
|
|
3178
|
+
* @param options - 小程序和长度限制配置。
|
|
2897
3179
|
* @returns 第一个超长路径的错误提示;全部合法时返回 `undefined`。
|
|
2898
3180
|
*/
|
|
2899
3181
|
function validateMiniappUploadPathLengths(files, options) {
|
|
2900
3182
|
const maxLength = options.maxLength ?? ACTIVITY_UPLOAD_KEY_MAX_LENGTH;
|
|
2901
3183
|
const prefix = `/u/${getMiniProgramUploadAlias(options.miniProgramId)}/${'x'.repeat(MINIAPP_UPLOAD_SESSION_REF_LENGTH)}/`;
|
|
2902
3184
|
const prefixLength = textEncoder.encode(prefix).length;
|
|
2903
|
-
const tooLongFile = files.find(file => {
|
|
3185
|
+
const tooLongFile = files.find((file) => {
|
|
2904
3186
|
const relativePath = normalizeMiniappArtifactRelativePath(file.relativePath);
|
|
2905
3187
|
return prefixLength + textEncoder.encode(relativePath).length > maxLength;
|
|
2906
3188
|
});
|
|
@@ -2909,7 +3191,7 @@ function validateMiniappUploadPathLengths(files, options) {
|
|
|
2909
3191
|
/**
|
|
2910
3192
|
* 创建 v1 整包签名头。
|
|
2911
3193
|
*
|
|
2912
|
-
* @param fileCount 参与签名的文件数量。
|
|
3194
|
+
* @param fileCount - 参与签名的文件数量。
|
|
2913
3195
|
* @returns 包含协议标识和文件数量的字节数组。
|
|
2914
3196
|
* @throws 文件数量超出协议范围时抛出错误。
|
|
2915
3197
|
*/
|
|
@@ -2922,7 +3204,7 @@ function createMiniappArtifactSignatureHeader(fileCount) {
|
|
|
2922
3204
|
/**
|
|
2923
3205
|
* 创建单个文件的 v1 framing header。
|
|
2924
3206
|
*
|
|
2925
|
-
* @param file 已规范化或待校验的构建产物文件。
|
|
3207
|
+
* @param file - 已规范化或待校验的构建产物文件。
|
|
2926
3208
|
* @returns 包含路径长度、路径和文件大小的字节数组。
|
|
2927
3209
|
* @throws 文件路径或大小非法时抛出错误。
|
|
2928
3210
|
*/
|
|
@@ -2935,9 +3217,9 @@ function createMiniappArtifactFileHeader(file) {
|
|
|
2935
3217
|
/**
|
|
2936
3218
|
* 校验服务端 session 文件映射,并计算仍需上传的文件。
|
|
2937
3219
|
*
|
|
2938
|
-
* @param localFiles 本地构建产物文件。
|
|
2939
|
-
* @param serverFiles 服务端签发的文件映射。
|
|
2940
|
-
* @param uploadedKeys 服务端已确认上传成功的 key。
|
|
3220
|
+
* @param localFiles - 本地构建产物文件。
|
|
3221
|
+
* @param serverFiles - 服务端签发的文件映射。
|
|
3222
|
+
* @param uploadedKeys - 服务端已确认上传成功的 key。
|
|
2941
3223
|
* @returns 完整映射、待上传文件和已确认 key。
|
|
2942
3224
|
* @throws 服务端映射与本地产物不一致时抛出错误。
|
|
2943
3225
|
*/
|
|
@@ -2969,7 +3251,7 @@ function resolveMiniappUploadSessionFiles(localFiles, serverFiles, uploadedKeys)
|
|
|
2969
3251
|
serverSizes.set(relativePath, size);
|
|
2970
3252
|
knownKeys.add(key);
|
|
2971
3253
|
}
|
|
2972
|
-
const files = preparedFiles.map(file => {
|
|
3254
|
+
const files = preparedFiles.map((file) => {
|
|
2973
3255
|
const key = mappings.get(file.relativePath);
|
|
2974
3256
|
if (!key) {
|
|
2975
3257
|
throw new Error(`上传会话缺少文件映射:${file.relativePath}`);
|
|
@@ -2989,7 +3271,7 @@ function resolveMiniappUploadSessionFiles(localFiles, serverFiles, uploadedKeys)
|
|
|
2989
3271
|
}
|
|
2990
3272
|
return {
|
|
2991
3273
|
files,
|
|
2992
|
-
missingFiles: files.filter(file => !completed.has(file.key)),
|
|
3274
|
+
missingFiles: files.filter((file) => !completed.has(file.key)),
|
|
2993
3275
|
uploadedKeys: [...completed],
|
|
2994
3276
|
};
|
|
2995
3277
|
}
|
|
@@ -3007,7 +3289,7 @@ function normalizeMiniappArtifactRelativePath(relativePath) {
|
|
|
3007
3289
|
if (containsControlCharacter(value) || UNPAIRED_SURROGATE_PATTERN.test(value)) {
|
|
3008
3290
|
throw new Error(`构建产物路径包含非法字符:${value}`);
|
|
3009
3291
|
}
|
|
3010
|
-
if (value.split('/').some(segment => !segment || segment === '.' || segment === '..')) {
|
|
3292
|
+
if (value.split('/').some((segment) => !segment || segment === '.' || segment === '..')) {
|
|
3011
3293
|
throw new Error(`构建产物路径包含非法目录段:${value}`);
|
|
3012
3294
|
}
|
|
3013
3295
|
if (value.includes(',')) {
|
|
@@ -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;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var path = require('node:path');
|
|
4
|
+
var version = require('./version-DN5jrixS.cjs');
|
|
5
|
+
var childProcess = require('node:child_process');
|
|
6
|
+
var fs = require('node:fs/promises');
|
|
7
|
+
var index = require('./index-BDaeBI_B.cjs');
|
|
8
|
+
require('node:module');
|
|
9
|
+
require('node:fs');
|
|
10
|
+
require('path');
|
|
11
|
+
require('os');
|
|
12
|
+
require('readline');
|
|
13
|
+
require('tty');
|
|
14
|
+
require('assert');
|
|
15
|
+
require('events');
|
|
16
|
+
require('stream');
|
|
17
|
+
require('buffer');
|
|
18
|
+
require('util');
|
|
19
|
+
|
|
20
|
+
function installSkill(options) {
|
|
21
|
+
const binary = require.resolve('skills/bin/cli.mjs');
|
|
22
|
+
const args = ['add', path.join(options.packageRoot, 'skill'), '--copy'];
|
|
23
|
+
if (options.global)
|
|
24
|
+
args.push('--global');
|
|
25
|
+
if (options.allAgents)
|
|
26
|
+
args.push('--agent', '*');
|
|
27
|
+
else if (options.agents?.length)
|
|
28
|
+
args.push('--agent', ...options.agents);
|
|
29
|
+
if (options.force)
|
|
30
|
+
args.push('--force');
|
|
31
|
+
const env = { ...process.env, ...options.env, DISABLE_TELEMETRY: '1', DO_NOT_TRACK: '1' };
|
|
32
|
+
const run = options.spawnImpl ?? childProcess.spawn;
|
|
33
|
+
return new Promise((resolve, reject) => {
|
|
34
|
+
const child = run(process.execPath, [binary, ...args], { cwd: options.cwd, env, stdio: 'inherit' });
|
|
35
|
+
child.on('error', reject);
|
|
36
|
+
child.on('close', (code) => resolve({ code: code ?? 1 }));
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function findProjectPackageJson(cwd = process.cwd()) {
|
|
41
|
+
let current = path.resolve(cwd);
|
|
42
|
+
while (true) {
|
|
43
|
+
const candidate = path.join(current, 'package.json');
|
|
44
|
+
try {
|
|
45
|
+
await fs.access(candidate);
|
|
46
|
+
return candidate;
|
|
47
|
+
}
|
|
48
|
+
catch { /* continue */ }
|
|
49
|
+
const parent = path.dirname(current);
|
|
50
|
+
if (parent === current)
|
|
51
|
+
return undefined;
|
|
52
|
+
current = parent;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
async function verifyProjectSdk(cwd, version) {
|
|
56
|
+
const file = await findProjectPackageJson(cwd);
|
|
57
|
+
if (!file)
|
|
58
|
+
throw new Error('未找到项目 package.json,请在项目目录执行');
|
|
59
|
+
const pkg = JSON.parse(await fs.readFile(file, 'utf8'));
|
|
60
|
+
const declared = pkg.dependencies?.['@heybox/hb-sdk'] ?? pkg.devDependencies?.['@heybox/hb-sdk'];
|
|
61
|
+
if (!declared)
|
|
62
|
+
throw new Error('项目缺少 @heybox/hb-sdk 依赖');
|
|
63
|
+
if (declared !== version && !String(declared).includes(version)) {
|
|
64
|
+
throw new Error(`项目 @heybox/hb-sdk 版本 ${declared} 与 CLI ${version} 不一致`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async function runSkillInstallCommand(options = {}) {
|
|
69
|
+
if (options.agent?.length && options.allAgents)
|
|
70
|
+
throw new Error('--agent 与 --all-agents 互斥');
|
|
71
|
+
const logger = options.logger ?? index.createCliLogger();
|
|
72
|
+
const packageRoot = options.packageRoot ?? path.resolve(__dirname, '../../..');
|
|
73
|
+
const cwd = options.cwd ?? process.cwd();
|
|
74
|
+
if (!options.global)
|
|
75
|
+
await verifyProjectSdk(cwd, version.HB_SDK_VERSION);
|
|
76
|
+
const result = await installSkill({ packageRoot, cwd, global: options.global, agents: options.agent, allAgents: options.allAgents, force: options.force });
|
|
77
|
+
if (result.code !== 0)
|
|
78
|
+
throw new Error(`Skill 安装失败(退出码 ${result.code})`);
|
|
79
|
+
logger.success('hb-sdk Skill 安装完成');
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
exports.runSkillInstallCommand = runSkillInstallCommand;
|