@heybox/hb-sdk 0.7.4 → 0.8.0-alpha
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 +61 -0
- package/README.md +14 -14
- package/dist/cli-chunks/{build-CVPqGQY3.cjs → build-DJWFSM1B.cjs} +6 -5
- package/dist/cli-chunks/{context-C1nTGr-R.cjs → context-DV2UK1Nz.cjs} +2 -2
- package/dist/cli-chunks/{create-C5qrLLvv.cjs → create-2HfoB48V.cjs} +1 -1
- package/dist/cli-chunks/{dev-U5BlN4ei.cjs → dev-Dgt2zS9k.cjs} +8 -8
- package/dist/cli-chunks/{doctor-DxqHMTbm.cjs → doctor-C95gIao_.cjs} +1 -1
- package/dist/cli-chunks/{index-BfR6OZeU.cjs → index-BjoSXl8C.cjs} +2 -2
- package/dist/cli-chunks/{index-DLrcC_ij.cjs → index-D62ANeBv.cjs} +14 -14
- package/dist/cli-chunks/{index.esm-DbbyeU1z.cjs → index.esm-CigcxJ2B.cjs} +6 -6
- package/dist/cli-chunks/{login-DQkArK14.cjs → login-Cumknwdx.cjs} +2 -2
- package/dist/cli-chunks/{project-vite-c13CKUUl.cjs → project-vite-CcE-HMmd.cjs} +1 -1
- package/dist/cli-chunks/{remote-816SyJyA.cjs → remote-DDdP3xcE.cjs} +10 -8
- package/dist/cli-chunks/{runtime-gate-CtV7rWyX.cjs → runtime-gate-DFjw66kF.cjs} +20 -1
- package/dist/cli-chunks/{runtime-permission-env-D-8_jPG3.cjs → runtime-permission-env-CjsCe5bp.cjs} +13 -13
- package/dist/cli-chunks/{session-ySUU0fVq.cjs → session-BDi_AZSv.cjs} +1 -1
- package/dist/cli.cjs +1 -1
- package/dist/devtools/browser-dev-host/main.js +654 -472
- package/dist/index.cjs.js +714 -639
- package/dist/index.esm.js +714 -639
- package/dist/miniapp-publish.cjs.js +13 -13
- package/dist/miniapp-publish.esm.js +13 -13
- package/dist/templates/vue3-vite-ts/README.md.ejs +2 -0
- package/dist/templates/vue3-vite-ts/vite.config.ts +1 -1
- package/dist/vite.cjs.js +31 -4
- package/dist/vite.esm.js +31 -5
- package/package.json +11 -8
- package/skill/references/api-protocol.md +14 -2
- package/skill/references/api-root.md +42 -21
- package/skill/references/examples.md +1 -1
- package/skill/references/safety-boundaries.md +1 -1
- package/skill/scripts/sync-references.mjs +3 -1
- package/skill/skill.json +4 -4
- package/types/core/errors.d.ts +5 -5
- package/types/core/sdk.d.ts +5 -5
- package/types/core/singleton.d.ts +56 -6
- package/types/miniapp-manifest/schema.d.ts +5 -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/navigation/index.d.ts +46 -4
- package/types/modules/network/index.d.ts +22 -11
- 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 +3 -3
- 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/vite/index.d.ts +15 -7
|
@@ -2937,7 +2937,7 @@ function shouldUploadDistFile(relativePath) {
|
|
|
2937
2937
|
/**
|
|
2938
2938
|
* 校验构建产物路径和大小,并按路径 UTF-8 字节序排序。
|
|
2939
2939
|
*
|
|
2940
|
-
* @param files 待处理的构建产物文件。
|
|
2940
|
+
* @param files - 待处理的构建产物文件。
|
|
2941
2941
|
* @returns 保留输入附加字段的有序文件列表。
|
|
2942
2942
|
* @throws 路径不规范、路径重复或文件大小非法时抛出错误。
|
|
2943
2943
|
*/
|
|
@@ -2946,7 +2946,7 @@ function prepareMiniappArtifactFiles(files) {
|
|
|
2946
2946
|
throw new Error('构建产物文件数量超出签名协议上限');
|
|
2947
2947
|
}
|
|
2948
2948
|
const usedPaths = new Set();
|
|
2949
|
-
const prepared = files.map(file => {
|
|
2949
|
+
const prepared = files.map((file) => {
|
|
2950
2950
|
const relativePath = normalizeMiniappArtifactRelativePath(file.relativePath);
|
|
2951
2951
|
if (usedPaths.has(relativePath)) {
|
|
2952
2952
|
throw new Error(`构建产物包含重复文件路径:${relativePath}`);
|
|
@@ -2960,15 +2960,15 @@ function prepareMiniappArtifactFiles(files) {
|
|
|
2960
2960
|
/**
|
|
2961
2961
|
* 按服务端 session key 前缀校验最终上传路径的 UTF-8 字节长度。
|
|
2962
2962
|
*
|
|
2963
|
-
* @param files 待上传的构建产物文件。
|
|
2964
|
-
* @param options 小程序和长度限制配置。
|
|
2963
|
+
* @param files - 待上传的构建产物文件。
|
|
2964
|
+
* @param options - 小程序和长度限制配置。
|
|
2965
2965
|
* @returns 第一个超长路径的错误提示;全部合法时返回 `undefined`。
|
|
2966
2966
|
*/
|
|
2967
2967
|
function validateMiniappUploadPathLengths(files, options) {
|
|
2968
2968
|
const maxLength = options.maxLength ?? ACTIVITY_UPLOAD_KEY_MAX_LENGTH;
|
|
2969
2969
|
const prefix = `/u/${getMiniProgramUploadAlias(options.miniProgramId)}/${'x'.repeat(MINIAPP_UPLOAD_SESSION_REF_LENGTH)}/`;
|
|
2970
2970
|
const prefixLength = textEncoder.encode(prefix).length;
|
|
2971
|
-
const tooLongFile = files.find(file => {
|
|
2971
|
+
const tooLongFile = files.find((file) => {
|
|
2972
2972
|
const relativePath = normalizeMiniappArtifactRelativePath(file.relativePath);
|
|
2973
2973
|
return prefixLength + textEncoder.encode(relativePath).length > maxLength;
|
|
2974
2974
|
});
|
|
@@ -2977,7 +2977,7 @@ function validateMiniappUploadPathLengths(files, options) {
|
|
|
2977
2977
|
/**
|
|
2978
2978
|
* 创建 v1 整包签名头。
|
|
2979
2979
|
*
|
|
2980
|
-
* @param fileCount 参与签名的文件数量。
|
|
2980
|
+
* @param fileCount - 参与签名的文件数量。
|
|
2981
2981
|
* @returns 包含协议标识和文件数量的字节数组。
|
|
2982
2982
|
* @throws 文件数量超出协议范围时抛出错误。
|
|
2983
2983
|
*/
|
|
@@ -2990,7 +2990,7 @@ function createMiniappArtifactSignatureHeader(fileCount) {
|
|
|
2990
2990
|
/**
|
|
2991
2991
|
* 创建单个文件的 v1 framing header。
|
|
2992
2992
|
*
|
|
2993
|
-
* @param file 已规范化或待校验的构建产物文件。
|
|
2993
|
+
* @param file - 已规范化或待校验的构建产物文件。
|
|
2994
2994
|
* @returns 包含路径长度、路径和文件大小的字节数组。
|
|
2995
2995
|
* @throws 文件路径或大小非法时抛出错误。
|
|
2996
2996
|
*/
|
|
@@ -3003,9 +3003,9 @@ function createMiniappArtifactFileHeader(file) {
|
|
|
3003
3003
|
/**
|
|
3004
3004
|
* 校验服务端 session 文件映射,并计算仍需上传的文件。
|
|
3005
3005
|
*
|
|
3006
|
-
* @param localFiles 本地构建产物文件。
|
|
3007
|
-
* @param serverFiles 服务端签发的文件映射。
|
|
3008
|
-
* @param uploadedKeys 服务端已确认上传成功的 key。
|
|
3006
|
+
* @param localFiles - 本地构建产物文件。
|
|
3007
|
+
* @param serverFiles - 服务端签发的文件映射。
|
|
3008
|
+
* @param uploadedKeys - 服务端已确认上传成功的 key。
|
|
3009
3009
|
* @returns 完整映射、待上传文件和已确认 key。
|
|
3010
3010
|
* @throws 服务端映射与本地产物不一致时抛出错误。
|
|
3011
3011
|
*/
|
|
@@ -3037,7 +3037,7 @@ function resolveMiniappUploadSessionFiles(localFiles, serverFiles, uploadedKeys)
|
|
|
3037
3037
|
serverSizes.set(relativePath, size);
|
|
3038
3038
|
knownKeys.add(key);
|
|
3039
3039
|
}
|
|
3040
|
-
const files = preparedFiles.map(file => {
|
|
3040
|
+
const files = preparedFiles.map((file) => {
|
|
3041
3041
|
const key = mappings.get(file.relativePath);
|
|
3042
3042
|
if (!key) {
|
|
3043
3043
|
throw new Error(`上传会话缺少文件映射:${file.relativePath}`);
|
|
@@ -3057,7 +3057,7 @@ function resolveMiniappUploadSessionFiles(localFiles, serverFiles, uploadedKeys)
|
|
|
3057
3057
|
}
|
|
3058
3058
|
return {
|
|
3059
3059
|
files,
|
|
3060
|
-
missingFiles: files.filter(file => !completed.has(file.key)),
|
|
3060
|
+
missingFiles: files.filter((file) => !completed.has(file.key)),
|
|
3061
3061
|
uploadedKeys: [...completed],
|
|
3062
3062
|
};
|
|
3063
3063
|
}
|
|
@@ -3075,7 +3075,7 @@ function normalizeMiniappArtifactRelativePath(relativePath) {
|
|
|
3075
3075
|
if (containsControlCharacter(value) || UNPAIRED_SURROGATE_PATTERN.test(value)) {
|
|
3076
3076
|
throw new Error(`构建产物路径包含非法字符:${value}`);
|
|
3077
3077
|
}
|
|
3078
|
-
if (value.split('/').some(segment => !segment || segment === '.' || segment === '..')) {
|
|
3078
|
+
if (value.split('/').some((segment) => !segment || segment === '.' || segment === '..')) {
|
|
3079
3079
|
throw new Error(`构建产物路径包含非法目录段:${value}`);
|
|
3080
3080
|
}
|
|
3081
3081
|
if (value.includes(',')) {
|
|
@@ -2935,7 +2935,7 @@ function shouldUploadDistFile(relativePath) {
|
|
|
2935
2935
|
/**
|
|
2936
2936
|
* 校验构建产物路径和大小,并按路径 UTF-8 字节序排序。
|
|
2937
2937
|
*
|
|
2938
|
-
* @param files 待处理的构建产物文件。
|
|
2938
|
+
* @param files - 待处理的构建产物文件。
|
|
2939
2939
|
* @returns 保留输入附加字段的有序文件列表。
|
|
2940
2940
|
* @throws 路径不规范、路径重复或文件大小非法时抛出错误。
|
|
2941
2941
|
*/
|
|
@@ -2944,7 +2944,7 @@ function prepareMiniappArtifactFiles(files) {
|
|
|
2944
2944
|
throw new Error('构建产物文件数量超出签名协议上限');
|
|
2945
2945
|
}
|
|
2946
2946
|
const usedPaths = new Set();
|
|
2947
|
-
const prepared = files.map(file => {
|
|
2947
|
+
const prepared = files.map((file) => {
|
|
2948
2948
|
const relativePath = normalizeMiniappArtifactRelativePath(file.relativePath);
|
|
2949
2949
|
if (usedPaths.has(relativePath)) {
|
|
2950
2950
|
throw new Error(`构建产物包含重复文件路径:${relativePath}`);
|
|
@@ -2958,15 +2958,15 @@ function prepareMiniappArtifactFiles(files) {
|
|
|
2958
2958
|
/**
|
|
2959
2959
|
* 按服务端 session key 前缀校验最终上传路径的 UTF-8 字节长度。
|
|
2960
2960
|
*
|
|
2961
|
-
* @param files 待上传的构建产物文件。
|
|
2962
|
-
* @param options 小程序和长度限制配置。
|
|
2961
|
+
* @param files - 待上传的构建产物文件。
|
|
2962
|
+
* @param options - 小程序和长度限制配置。
|
|
2963
2963
|
* @returns 第一个超长路径的错误提示;全部合法时返回 `undefined`。
|
|
2964
2964
|
*/
|
|
2965
2965
|
function validateMiniappUploadPathLengths(files, options) {
|
|
2966
2966
|
const maxLength = options.maxLength ?? ACTIVITY_UPLOAD_KEY_MAX_LENGTH;
|
|
2967
2967
|
const prefix = `/u/${getMiniProgramUploadAlias(options.miniProgramId)}/${'x'.repeat(MINIAPP_UPLOAD_SESSION_REF_LENGTH)}/`;
|
|
2968
2968
|
const prefixLength = textEncoder.encode(prefix).length;
|
|
2969
|
-
const tooLongFile = files.find(file => {
|
|
2969
|
+
const tooLongFile = files.find((file) => {
|
|
2970
2970
|
const relativePath = normalizeMiniappArtifactRelativePath(file.relativePath);
|
|
2971
2971
|
return prefixLength + textEncoder.encode(relativePath).length > maxLength;
|
|
2972
2972
|
});
|
|
@@ -2975,7 +2975,7 @@ function validateMiniappUploadPathLengths(files, options) {
|
|
|
2975
2975
|
/**
|
|
2976
2976
|
* 创建 v1 整包签名头。
|
|
2977
2977
|
*
|
|
2978
|
-
* @param fileCount 参与签名的文件数量。
|
|
2978
|
+
* @param fileCount - 参与签名的文件数量。
|
|
2979
2979
|
* @returns 包含协议标识和文件数量的字节数组。
|
|
2980
2980
|
* @throws 文件数量超出协议范围时抛出错误。
|
|
2981
2981
|
*/
|
|
@@ -2988,7 +2988,7 @@ function createMiniappArtifactSignatureHeader(fileCount) {
|
|
|
2988
2988
|
/**
|
|
2989
2989
|
* 创建单个文件的 v1 framing header。
|
|
2990
2990
|
*
|
|
2991
|
-
* @param file 已规范化或待校验的构建产物文件。
|
|
2991
|
+
* @param file - 已规范化或待校验的构建产物文件。
|
|
2992
2992
|
* @returns 包含路径长度、路径和文件大小的字节数组。
|
|
2993
2993
|
* @throws 文件路径或大小非法时抛出错误。
|
|
2994
2994
|
*/
|
|
@@ -3001,9 +3001,9 @@ function createMiniappArtifactFileHeader(file) {
|
|
|
3001
3001
|
/**
|
|
3002
3002
|
* 校验服务端 session 文件映射,并计算仍需上传的文件。
|
|
3003
3003
|
*
|
|
3004
|
-
* @param localFiles 本地构建产物文件。
|
|
3005
|
-
* @param serverFiles 服务端签发的文件映射。
|
|
3006
|
-
* @param uploadedKeys 服务端已确认上传成功的 key。
|
|
3004
|
+
* @param localFiles - 本地构建产物文件。
|
|
3005
|
+
* @param serverFiles - 服务端签发的文件映射。
|
|
3006
|
+
* @param uploadedKeys - 服务端已确认上传成功的 key。
|
|
3007
3007
|
* @returns 完整映射、待上传文件和已确认 key。
|
|
3008
3008
|
* @throws 服务端映射与本地产物不一致时抛出错误。
|
|
3009
3009
|
*/
|
|
@@ -3035,7 +3035,7 @@ function resolveMiniappUploadSessionFiles(localFiles, serverFiles, uploadedKeys)
|
|
|
3035
3035
|
serverSizes.set(relativePath, size);
|
|
3036
3036
|
knownKeys.add(key);
|
|
3037
3037
|
}
|
|
3038
|
-
const files = preparedFiles.map(file => {
|
|
3038
|
+
const files = preparedFiles.map((file) => {
|
|
3039
3039
|
const key = mappings.get(file.relativePath);
|
|
3040
3040
|
if (!key) {
|
|
3041
3041
|
throw new Error(`上传会话缺少文件映射:${file.relativePath}`);
|
|
@@ -3055,7 +3055,7 @@ function resolveMiniappUploadSessionFiles(localFiles, serverFiles, uploadedKeys)
|
|
|
3055
3055
|
}
|
|
3056
3056
|
return {
|
|
3057
3057
|
files,
|
|
3058
|
-
missingFiles: files.filter(file => !completed.has(file.key)),
|
|
3058
|
+
missingFiles: files.filter((file) => !completed.has(file.key)),
|
|
3059
3059
|
uploadedKeys: [...completed],
|
|
3060
3060
|
};
|
|
3061
3061
|
}
|
|
@@ -3073,7 +3073,7 @@ function normalizeMiniappArtifactRelativePath(relativePath) {
|
|
|
3073
3073
|
if (containsControlCharacter(value) || UNPAIRED_SURROGATE_PATTERN.test(value)) {
|
|
3074
3074
|
throw new Error(`构建产物路径包含非法字符:${value}`);
|
|
3075
3075
|
}
|
|
3076
|
-
if (value.split('/').some(segment => !segment || segment === '.' || segment === '..')) {
|
|
3076
|
+
if (value.split('/').some((segment) => !segment || segment === '.' || segment === '..')) {
|
|
3077
3077
|
throw new Error(`构建产物路径包含非法目录段:${value}`);
|
|
3078
3078
|
}
|
|
3079
3079
|
if (value.includes(',')) {
|
package/dist/vite.cjs.js
CHANGED
|
@@ -8,7 +8,7 @@ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentS
|
|
|
8
8
|
/** 构建时替换为当前发布包的实际版本。 */
|
|
9
9
|
const HB_SDK_VERSION = typeof undefined === 'string'
|
|
10
10
|
? undefined
|
|
11
|
-
: '0.
|
|
11
|
+
: '0.8.0-alpha';
|
|
12
12
|
|
|
13
13
|
var re = {exports: {}};
|
|
14
14
|
|
|
@@ -2795,6 +2795,7 @@ function requireSemver () {
|
|
|
2795
2795
|
|
|
2796
2796
|
var semverExports = requireSemver();
|
|
2797
2797
|
|
|
2798
|
+
const MINIAPP_PLATFORM_VALUES = ['android', 'ios', 'ohos', 'windows', 'macos', 'linux'];
|
|
2798
2799
|
function validateMiniappPackageVersionForBuild(version) {
|
|
2799
2800
|
return validateMiniappManifestVersion(version, 'package.json.version');
|
|
2800
2801
|
}
|
|
@@ -2806,7 +2807,25 @@ function validateMiniappManifestVersion(version, sourceLabel = 'manifest.version
|
|
|
2806
2807
|
return String(version).trim();
|
|
2807
2808
|
}
|
|
2808
2809
|
function renderMiniappManifest(manifest) {
|
|
2809
|
-
|
|
2810
|
+
const platforms = validateMiniappPlatforms(manifest.platforms, 'manifest.platforms');
|
|
2811
|
+
return `${JSON.stringify({ version: manifest.version, sdkVersion: manifest.sdkVersion, platforms }, null, 2)}\n`;
|
|
2812
|
+
}
|
|
2813
|
+
function validateMiniappPlatforms(platforms, sourceLabel = 'platforms') {
|
|
2814
|
+
if (!Array.isArray(platforms) || platforms.length === 0) {
|
|
2815
|
+
throw new Error(`${sourceLabel} 必须是非空平台数组`);
|
|
2816
|
+
}
|
|
2817
|
+
const allowedPlatforms = new Set(MINIAPP_PLATFORM_VALUES);
|
|
2818
|
+
const seen = new Set();
|
|
2819
|
+
for (const platform of platforms) {
|
|
2820
|
+
if (typeof platform !== 'string' || !allowedPlatforms.has(platform)) {
|
|
2821
|
+
throw new Error(`${sourceLabel} 包含不支持的平台:${String(platform)}`);
|
|
2822
|
+
}
|
|
2823
|
+
if (seen.has(platform)) {
|
|
2824
|
+
throw new Error(`${sourceLabel} 包含重复平台:${platform}`);
|
|
2825
|
+
}
|
|
2826
|
+
seen.add(platform);
|
|
2827
|
+
}
|
|
2828
|
+
return Object.freeze(MINIAPP_PLATFORM_VALUES.filter((platform) => seen.has(platform)));
|
|
2810
2829
|
}
|
|
2811
2830
|
function getMiniappManifestVersionError(version) {
|
|
2812
2831
|
if (typeof version !== 'string' || version.trim() === '') {
|
|
@@ -11629,7 +11648,8 @@ function shouldSkipMiniappPlatformCspFromEnv(env = process.env) {
|
|
|
11629
11648
|
|
|
11630
11649
|
const sdkVersionPlaceholder = ['__HB_SDK', 'VERSION__'].join('_');
|
|
11631
11650
|
const sdkVersionBuildConstant = ['__HB_SDK_BUILD', 'VERSION__'].join('_');
|
|
11632
|
-
function miniappManifest() {
|
|
11651
|
+
function miniappManifest(options) {
|
|
11652
|
+
const platforms = validateMiniappPlatforms(options?.platforms, 'miniappManifest().platforms');
|
|
11633
11653
|
const skipPlatformCsp = shouldSkipMiniappPlatformCspFromEnv();
|
|
11634
11654
|
let root = process.cwd();
|
|
11635
11655
|
let outDir = 'dist';
|
|
@@ -11649,6 +11669,12 @@ function miniappManifest() {
|
|
|
11649
11669
|
};
|
|
11650
11670
|
},
|
|
11651
11671
|
configResolved(resolved) {
|
|
11672
|
+
if (resolved.plugins) {
|
|
11673
|
+
const manifestPluginCount = resolved.plugins.filter((plugin) => plugin.name === 'heybox-miniapp-manifest').length;
|
|
11674
|
+
if (manifestPluginCount !== 1) {
|
|
11675
|
+
throw new Error(`Vite 配置必须且只能包含一个 miniappManifest() 插件,当前数量:${manifestPluginCount}`);
|
|
11676
|
+
}
|
|
11677
|
+
}
|
|
11652
11678
|
root = resolved.root;
|
|
11653
11679
|
outDir = resolved.build.outDir;
|
|
11654
11680
|
command = resolved.command;
|
|
@@ -11688,7 +11714,7 @@ function miniappManifest() {
|
|
|
11688
11714
|
node_fs.writeFileSync(indexHtmlPath, enforceMiniappHtmlPolicy(node_fs.readFileSync(indexHtmlPath, 'utf8'), { skipPlatformCsp }));
|
|
11689
11715
|
const manifestPath = path.join(outputRoot, 'manifest.json');
|
|
11690
11716
|
node_fs.mkdirSync(path.dirname(manifestPath), { recursive: true });
|
|
11691
|
-
node_fs.writeFileSync(manifestPath, renderMiniappManifest({ version, sdkVersion }));
|
|
11717
|
+
node_fs.writeFileSync(manifestPath, renderMiniappManifest({ version, sdkVersion, platforms }));
|
|
11692
11718
|
},
|
|
11693
11719
|
};
|
|
11694
11720
|
}
|
|
@@ -11734,4 +11760,5 @@ function resolveHmrWebSocketUrl(resolved) {
|
|
|
11734
11760
|
return `${protocol}://${host}${port ? `:${port}` : ''}`;
|
|
11735
11761
|
}
|
|
11736
11762
|
|
|
11763
|
+
exports.MINIAPP_PLATFORM_VALUES = MINIAPP_PLATFORM_VALUES;
|
|
11737
11764
|
exports.miniappManifest = miniappManifest;
|
package/dist/vite.esm.js
CHANGED
|
@@ -5,7 +5,7 @@ import { AsyncLocalStorage } from 'node:async_hooks';
|
|
|
5
5
|
/** 构建时替换为当前发布包的实际版本。 */
|
|
6
6
|
const HB_SDK_VERSION = typeof undefined === 'string'
|
|
7
7
|
? undefined
|
|
8
|
-
: '0.
|
|
8
|
+
: '0.8.0-alpha';
|
|
9
9
|
|
|
10
10
|
var re = {exports: {}};
|
|
11
11
|
|
|
@@ -2792,6 +2792,7 @@ function requireSemver () {
|
|
|
2792
2792
|
|
|
2793
2793
|
var semverExports = requireSemver();
|
|
2794
2794
|
|
|
2795
|
+
const MINIAPP_PLATFORM_VALUES = ['android', 'ios', 'ohos', 'windows', 'macos', 'linux'];
|
|
2795
2796
|
function validateMiniappPackageVersionForBuild(version) {
|
|
2796
2797
|
return validateMiniappManifestVersion(version, 'package.json.version');
|
|
2797
2798
|
}
|
|
@@ -2803,7 +2804,25 @@ function validateMiniappManifestVersion(version, sourceLabel = 'manifest.version
|
|
|
2803
2804
|
return String(version).trim();
|
|
2804
2805
|
}
|
|
2805
2806
|
function renderMiniappManifest(manifest) {
|
|
2806
|
-
|
|
2807
|
+
const platforms = validateMiniappPlatforms(manifest.platforms, 'manifest.platforms');
|
|
2808
|
+
return `${JSON.stringify({ version: manifest.version, sdkVersion: manifest.sdkVersion, platforms }, null, 2)}\n`;
|
|
2809
|
+
}
|
|
2810
|
+
function validateMiniappPlatforms(platforms, sourceLabel = 'platforms') {
|
|
2811
|
+
if (!Array.isArray(platforms) || platforms.length === 0) {
|
|
2812
|
+
throw new Error(`${sourceLabel} 必须是非空平台数组`);
|
|
2813
|
+
}
|
|
2814
|
+
const allowedPlatforms = new Set(MINIAPP_PLATFORM_VALUES);
|
|
2815
|
+
const seen = new Set();
|
|
2816
|
+
for (const platform of platforms) {
|
|
2817
|
+
if (typeof platform !== 'string' || !allowedPlatforms.has(platform)) {
|
|
2818
|
+
throw new Error(`${sourceLabel} 包含不支持的平台:${String(platform)}`);
|
|
2819
|
+
}
|
|
2820
|
+
if (seen.has(platform)) {
|
|
2821
|
+
throw new Error(`${sourceLabel} 包含重复平台:${platform}`);
|
|
2822
|
+
}
|
|
2823
|
+
seen.add(platform);
|
|
2824
|
+
}
|
|
2825
|
+
return Object.freeze(MINIAPP_PLATFORM_VALUES.filter((platform) => seen.has(platform)));
|
|
2807
2826
|
}
|
|
2808
2827
|
function getMiniappManifestVersionError(version) {
|
|
2809
2828
|
if (typeof version !== 'string' || version.trim() === '') {
|
|
@@ -11626,7 +11645,8 @@ function shouldSkipMiniappPlatformCspFromEnv(env = process.env) {
|
|
|
11626
11645
|
|
|
11627
11646
|
const sdkVersionPlaceholder = ['__HB_SDK', 'VERSION__'].join('_');
|
|
11628
11647
|
const sdkVersionBuildConstant = ['__HB_SDK_BUILD', 'VERSION__'].join('_');
|
|
11629
|
-
function miniappManifest() {
|
|
11648
|
+
function miniappManifest(options) {
|
|
11649
|
+
const platforms = validateMiniappPlatforms(options?.platforms, 'miniappManifest().platforms');
|
|
11630
11650
|
const skipPlatformCsp = shouldSkipMiniappPlatformCspFromEnv();
|
|
11631
11651
|
let root = process.cwd();
|
|
11632
11652
|
let outDir = 'dist';
|
|
@@ -11646,6 +11666,12 @@ function miniappManifest() {
|
|
|
11646
11666
|
};
|
|
11647
11667
|
},
|
|
11648
11668
|
configResolved(resolved) {
|
|
11669
|
+
if (resolved.plugins) {
|
|
11670
|
+
const manifestPluginCount = resolved.plugins.filter((plugin) => plugin.name === 'heybox-miniapp-manifest').length;
|
|
11671
|
+
if (manifestPluginCount !== 1) {
|
|
11672
|
+
throw new Error(`Vite 配置必须且只能包含一个 miniappManifest() 插件,当前数量:${manifestPluginCount}`);
|
|
11673
|
+
}
|
|
11674
|
+
}
|
|
11649
11675
|
root = resolved.root;
|
|
11650
11676
|
outDir = resolved.build.outDir;
|
|
11651
11677
|
command = resolved.command;
|
|
@@ -11685,7 +11711,7 @@ function miniappManifest() {
|
|
|
11685
11711
|
writeFileSync(indexHtmlPath, enforceMiniappHtmlPolicy(readFileSync(indexHtmlPath, 'utf8'), { skipPlatformCsp }));
|
|
11686
11712
|
const manifestPath = path.join(outputRoot, 'manifest.json');
|
|
11687
11713
|
mkdirSync(path.dirname(manifestPath), { recursive: true });
|
|
11688
|
-
writeFileSync(manifestPath, renderMiniappManifest({ version, sdkVersion }));
|
|
11714
|
+
writeFileSync(manifestPath, renderMiniappManifest({ version, sdkVersion, platforms }));
|
|
11689
11715
|
},
|
|
11690
11716
|
};
|
|
11691
11717
|
}
|
|
@@ -11731,4 +11757,4 @@ function resolveHmrWebSocketUrl(resolved) {
|
|
|
11731
11757
|
return `${protocol}://${host}${port ? `:${port}` : ''}`;
|
|
11732
11758
|
}
|
|
11733
11759
|
|
|
11734
|
-
export { miniappManifest };
|
|
11760
|
+
export { MINIAPP_PLATFORM_VALUES, miniappManifest };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@heybox/hb-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0-alpha",
|
|
4
4
|
"sideEffects": [
|
|
5
5
|
"./src/index.ts",
|
|
6
6
|
"./src/core/singleton.ts",
|
|
@@ -53,11 +53,11 @@
|
|
|
53
53
|
"author": "",
|
|
54
54
|
"license": "ISC",
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@msgpack/msgpack": "
|
|
56
|
+
"@msgpack/msgpack": "2.8.0",
|
|
57
57
|
"parse5": "^7.3.0",
|
|
58
58
|
"undici": "^7.28.0",
|
|
59
59
|
"ws": "^8.18.0",
|
|
60
|
-
"@heybox/hb-sdk-protocol": "0.
|
|
60
|
+
"@heybox/hb-sdk-protocol": "0.8.0-alpha"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
63
|
"vite": ">=5"
|
|
@@ -100,11 +100,11 @@
|
|
|
100
100
|
"vue": "^2.7.16",
|
|
101
101
|
"vite": "^8.0.12",
|
|
102
102
|
"vitest": "^3.2.4",
|
|
103
|
-
"@heybox/hb-api": "~1.25.
|
|
104
|
-
"@heybox/hb-sdk-runtime": "~0.
|
|
105
|
-
"@heybox/runtime
|
|
103
|
+
"@heybox/hb-api": "~1.25.23",
|
|
104
|
+
"@heybox/hb-sdk-runtime": "~0.8.0-alpha",
|
|
105
|
+
"@heybox/runtime": "~0.2.0",
|
|
106
106
|
"@heybox/runtime-policy": "~0.2.0",
|
|
107
|
-
"@heybox/runtime": "~0.2.0"
|
|
107
|
+
"@heybox/runtime-transport-fetch": "~0.2.0"
|
|
108
108
|
},
|
|
109
109
|
"publishConfig": {
|
|
110
110
|
"registry": "https://registry.npmjs.org/",
|
|
@@ -149,6 +149,8 @@
|
|
|
149
149
|
"build:types": "tsc -p tsconfig.dts.json",
|
|
150
150
|
"check:boundary": "node scripts/check-boundary.cjs",
|
|
151
151
|
"check:docs-sync": "pnpm -w exec hbexec hb-sdk check",
|
|
152
|
+
"check:compatibility-evidence": "node scripts/validate-compatibility-evidence.mjs",
|
|
153
|
+
"check:api-semver": "node ../../ops/jobs/hb-sdk-docs-contract/semantic-diff.cjs",
|
|
152
154
|
"clean": "rimraf ./dist && rimraf ./types",
|
|
153
155
|
"test:unit": "NODE_OPTIONS='--conditions=heybox' vitest run",
|
|
154
156
|
"test:types:characterization": "tsc -p tsconfig.characterization.json --noEmit --pretty false",
|
|
@@ -160,7 +162,8 @@
|
|
|
160
162
|
"test:watch": "NODE_OPTIONS='--conditions=heybox' vitest",
|
|
161
163
|
"changelog:draft": "node scripts/changelog-draft.cjs",
|
|
162
164
|
"check:changelog": "node scripts/check-changelog.cjs",
|
|
163
|
-
"test:release": "node --test scripts/release-family.test.cjs ../../ops/jobs/publish-changed-packages/publish.test.cjs",
|
|
165
|
+
"test:release": "node --test scripts/release-family.test.cjs ../../ops/jobs/publish-changed-packages/publish.test.cjs ../../ops/jobs/release-hb-sdk/docs-release-contract.test.cjs",
|
|
166
|
+
"test:compatibility-evidence": "node --test scripts/validate-compatibility-evidence.test.mjs",
|
|
164
167
|
"release:prepare": "node scripts/release-prepare.cjs",
|
|
165
168
|
"release:tag": "node scripts/release-tag.cjs",
|
|
166
169
|
"release:family:dry-run": "node ../../ops/jobs/publish-changed-packages/publish.cjs --dry-run",
|
|
@@ -202,6 +202,18 @@ Reference 由 `@heybox/hb-sdk` 的公开导出与源码注释自动生成,不
|
|
|
202
202
|
| 导出面 | Classes | Functions | Interfaces | Types | Constants |
|
|
203
203
|
| --- | ---: | ---: | ---: | ---: | ---: |
|
|
204
204
|
| Root API | 2 | 4 | 51 | 57 | 1 |
|
|
205
|
-
| Protocol API | 0 | 3 |
|
|
205
|
+
| Protocol API | 0 | 3 | 34 | 62 | 30 |
|
|
206
206
|
| Miniapp Publish API | 0 | 5 | 2 | 0 | 0 |
|
|
207
|
-
| Vite API | 0 | 1 |
|
|
207
|
+
| Vite API | 0 | 1 | 5 | 1 | 1 |
|
|
208
|
+
|
|
209
|
+
<!-- Generated by apps/docs/hb-sdk/scripts/generate-api-docs.ts; schemaVersion=2; fingerprint=d54639a086217e53edf8a85d2e11e0f0263aa0fd3dc88183fe2b3f3f07b4f4a1 -->
|
|
210
|
+
|
|
211
|
+
## SDK API
|
|
212
|
+
|
|
213
|
+
- [兼容性总览](https://docs.xiaoheihe.cn/hb_sdk/reference/compatibility)
|
|
214
|
+
|
|
215
|
+
## 常用 API
|
|
216
|
+
|
|
217
|
+
- [`user.getInfo`](https://docs.xiaoheihe.cn/hb_sdk/reference/sdk/user/getInfo)
|
|
218
|
+
- [`auth.login`](https://docs.xiaoheihe.cn/hb_sdk/reference/sdk/auth/login)
|
|
219
|
+
- [`cloud.leaderboard.submit`](https://docs.xiaoheihe.cn/hb_sdk/reference/sdk/cloud/leaderboard/submit)
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
## Package metadata
|
|
25
25
|
|
|
26
26
|
- Package: `@heybox/hb-sdk`
|
|
27
|
-
- Version at generation time: `0.
|
|
27
|
+
- Version at generation time: `0.8.0-alpha`
|
|
28
28
|
- Public root export: `@heybox/hb-sdk`
|
|
29
29
|
- Protocol export: `@heybox/hb-sdk/protocol`
|
|
30
30
|
- Vite plugin export: `@heybox/hb-sdk/vite`
|
|
@@ -210,12 +210,18 @@ Use `@heybox/hb-sdk/vite` only in `vite.config.ts`. Do not import it from iframe
|
|
|
210
210
|
import { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from 'node:fs';
|
|
211
211
|
import path from 'node:path';
|
|
212
212
|
import { HB_SDK_VERSION } from '../core/version';
|
|
213
|
-
import {
|
|
213
|
+
import {
|
|
214
|
+
MINIAPP_PLATFORM_VALUES,
|
|
215
|
+
renderMiniappManifest,
|
|
216
|
+
validateMiniappPackageVersionForBuild,
|
|
217
|
+
validateMiniappPlatforms,
|
|
218
|
+
type MiniappPlatform,
|
|
219
|
+
} from '../miniapp-manifest/schema';
|
|
214
220
|
import { readMiniappVersionFromPackageJson } from '../miniapp-manifest/node';
|
|
215
221
|
import { enforceMiniappHtmlPolicy } from './html-policy';
|
|
216
222
|
import { shouldSkipMiniappPlatformCspFromEnv } from './runtime-permission-env';
|
|
217
223
|
|
|
218
|
-
|
|
224
|
+
export interface MiniappManifestPlugin {
|
|
219
225
|
name: string;
|
|
220
226
|
config: (config: MiniappManifestUserConfig) => MiniappManifestUserConfig | void;
|
|
221
227
|
configResolved: (resolved: MiniappManifestResolvedConfig) => void;
|
|
@@ -223,18 +229,18 @@ type MiniappManifestPlugin = {
|
|
|
223
229
|
buildEnd: (error?: Error) => void;
|
|
224
230
|
transformIndexHtml: (html: string) => string;
|
|
225
231
|
closeBundle: (this: MiniappManifestPluginContext) => Promise<void>;
|
|
226
|
-
}
|
|
232
|
+
}
|
|
227
233
|
|
|
228
|
-
interface MiniappManifestUserConfig {
|
|
234
|
+
export interface MiniappManifestUserConfig {
|
|
229
235
|
base?: string;
|
|
230
236
|
define?: Record<string, string>;
|
|
231
237
|
}
|
|
232
238
|
|
|
233
|
-
interface MiniappManifestPluginContext {
|
|
239
|
+
export interface MiniappManifestPluginContext {
|
|
234
240
|
warn: (message: string) => void;
|
|
235
241
|
}
|
|
236
242
|
|
|
237
|
-
interface MiniappManifestResolvedConfig {
|
|
243
|
+
export interface MiniappManifestResolvedConfig {
|
|
238
244
|
root: string;
|
|
239
245
|
command: 'build' | 'serve';
|
|
240
246
|
build: {
|
|
@@ -253,12 +259,21 @@ interface MiniappManifestResolvedConfig {
|
|
|
253
259
|
protocol?: 'ws' | 'wss';
|
|
254
260
|
};
|
|
255
261
|
};
|
|
262
|
+
plugins?: readonly { name?: string }[];
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
export { MINIAPP_PLATFORM_VALUES };
|
|
266
|
+
export type { MiniappPlatform };
|
|
267
|
+
|
|
268
|
+
export interface MiniappManifestOptions {
|
|
269
|
+
platforms: readonly MiniappPlatform[];
|
|
256
270
|
}
|
|
257
271
|
|
|
258
272
|
const sdkVersionPlaceholder = ['__HB_SDK', 'VERSION__'].join('_');
|
|
259
273
|
const sdkVersionBuildConstant = ['__HB_SDK_BUILD', 'VERSION__'].join('_');
|
|
260
274
|
|
|
261
|
-
export function miniappManifest(): MiniappManifestPlugin {
|
|
275
|
+
export function miniappManifest(options: MiniappManifestOptions): MiniappManifestPlugin {
|
|
276
|
+
const platforms = validateMiniappPlatforms(options?.platforms, 'miniappManifest().platforms');
|
|
262
277
|
const skipPlatformCsp = shouldSkipMiniappPlatformCspFromEnv();
|
|
263
278
|
let root = process.cwd();
|
|
264
279
|
let outDir = 'dist';
|
|
@@ -279,6 +294,12 @@ export function miniappManifest(): MiniappManifestPlugin {
|
|
|
279
294
|
};
|
|
280
295
|
},
|
|
281
296
|
configResolved(resolved) {
|
|
297
|
+
if (resolved.plugins) {
|
|
298
|
+
const manifestPluginCount = resolved.plugins.filter((plugin) => plugin.name === 'heybox-miniapp-manifest').length;
|
|
299
|
+
if (manifestPluginCount !== 1) {
|
|
300
|
+
throw new Error(`Vite 配置必须且只能包含一个 miniappManifest() 插件,当前数量:${manifestPluginCount}`);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
282
303
|
root = resolved.root;
|
|
283
304
|
outDir = resolved.build.outDir;
|
|
284
305
|
command = resolved.command;
|
|
@@ -322,7 +343,7 @@ export function miniappManifest(): MiniappManifestPlugin {
|
|
|
322
343
|
|
|
323
344
|
const manifestPath = path.join(outputRoot, 'manifest.json');
|
|
324
345
|
mkdirSync(path.dirname(manifestPath), { recursive: true });
|
|
325
|
-
writeFileSync(manifestPath, renderMiniappManifest({ version, sdkVersion }));
|
|
346
|
+
writeFileSync(manifestPath, renderMiniappManifest({ version, sdkVersion, platforms }));
|
|
326
347
|
},
|
|
327
348
|
};
|
|
328
349
|
}
|
|
@@ -556,18 +577,18 @@ function reportSDKError(errorCode: string, message: string, data?: unknown) {
|
|
|
556
577
|
|
|
557
578
|
SDK 还提供 `getHandshakeState()` / `onHandshakeStateChange()` 管理持久握手状态,并通过 `on()` / `off()` 处理前后台、登录态等生命周期事件。
|
|
558
579
|
|
|
559
|
-
| 模块 | 用途
|
|
560
|
-
| ------------ |
|
|
561
|
-
| `auth` | 获取交给开发者服务端交换的短期授权码
|
|
562
|
-
| `user` | 读取 Host 当前用户资料、隔离身份或撤销授权
|
|
563
|
-
| `share` | 打开分享、复制链接或截图分享流程
|
|
564
|
-
| `ui` | 展示 Toast 和 Loading
|
|
565
|
-
| `device` | 调用振动和剪贴板能力
|
|
566
|
-
| `navigation` | 关闭、刷新页面或打开小黑盒页面
|
|
567
|
-
| `viewport` | 读取窗口信息和设置导航栏样式
|
|
568
|
-
| `storage` | 读写当前小程序的隔离存储
|
|
569
|
-
| `cloud` | 使用小程序云端排行榜
|
|
570
|
-
| `network` | 发起经过平台授权的网络请求
|
|
580
|
+
| 模块 | 用途 |
|
|
581
|
+
| ------------ | ------------------------------------------ |
|
|
582
|
+
| `auth` | 获取交给开发者服务端交换的短期授权码 |
|
|
583
|
+
| `user` | 读取 Host 当前用户资料、隔离身份或撤销授权 |
|
|
584
|
+
| `share` | 打开分享、复制链接或截图分享流程 |
|
|
585
|
+
| `ui` | 展示 Toast 和 Loading |
|
|
586
|
+
| `device` | 调用振动和剪贴板能力 |
|
|
587
|
+
| `navigation` | 关闭、刷新页面或打开小黑盒页面 |
|
|
588
|
+
| `viewport` | 读取窗口信息和设置导航栏样式 |
|
|
589
|
+
| `storage` | 读写当前小程序的隔离存储 |
|
|
590
|
+
| `cloud` | 使用小程序云端排行榜 |
|
|
591
|
+
| `network` | 发起经过平台授权的网络请求 |
|
|
571
592
|
|
|
572
593
|
具体方法、参数和返回值以 [API Reference](https://docs.xiaoheihe.cn/hb_sdk/reference/) 为准,常见组合写法见 [Recipes](https://docs.xiaoheihe.cn/hb_sdk/recipes/)。
|
|
573
594
|
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
- `network.request()` 不能访问平台保留的 runtime auth 与 OpenAPI 内部路径;页面不得持有或交换服务端应用凭据。
|
|
25
25
|
- `network.request` 不支持 `multipart/form-data`;App Host 仅支持 form(`application/x-www-form-urlencoded`)与 JSON。表单请用 `URLSearchParams#toString()` 作为 `data`,文件上传请走专用上传能力。
|
|
26
26
|
- 仅当远端已启用 `network.request` 时,`hb-sdk dev` 与 `hb-sdk remote deploy` 构建才会跳过平台 CSP;其他构建继续注入平台 CSP。`useOfficialDomain` 不参与 CSP 跳过判定。
|
|
27
|
-
- 构建必须启用 `miniappManifest()
|
|
27
|
+
- 构建必须启用 `miniappManifest({ platforms })` 并显式声明实际承诺适配的平台,推荐统一使用 `hb-sdk build`。新项目模板中的 `['android', 'ios', 'ohos']` 只是初始配置,不代表已经完成真机验收。
|
|
28
28
|
|
|
29
29
|
## Agent rules
|
|
30
30
|
|
|
@@ -78,6 +78,8 @@ function rewriteBundledProtocolIndexLinks(markdown) {
|
|
|
78
78
|
return markdown
|
|
79
79
|
.replaceAll('(./root/)', '(api-root.md)')
|
|
80
80
|
.replaceAll('(./protocol/)', '(#public-protocol-entrypoint)')
|
|
81
|
+
.replaceAll('(./compatibility)', '(https://docs.xiaoheihe.cn/hb_sdk/reference/compatibility)')
|
|
82
|
+
.replaceAll('](/reference/', '](https://docs.xiaoheihe.cn/hb_sdk/reference/')
|
|
81
83
|
.replaceAll('(./miniapp-publish/)', '(https://open.xiaoheihe.cn/docs/hb_sdk/reference/miniapp-publish/)')
|
|
82
84
|
.replaceAll('(./vite/)', '(https://open.xiaoheihe.cn/docs/hb_sdk/reference/vite/)')
|
|
83
85
|
.replaceAll('(./runtime/)', '(https://docs.xiaoheihe.cn/hb_sdk/reference/runtime/)')
|
|
@@ -735,7 +737,7 @@ import { defineConfig } from 'vite';
|
|
|
735
737
|
|
|
736
738
|
export default defineConfig({
|
|
737
739
|
base: './',
|
|
738
|
-
plugins: [miniappManifest()],
|
|
740
|
+
plugins: [miniappManifest({ platforms: ['android', 'ios', 'ohos'] })],
|
|
739
741
|
});`,
|
|
740
742
|
)}
|
|
741
743
|
|
package/skill/skill.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hb-sdk",
|
|
3
|
-
"skillVersion": "0.
|
|
3
|
+
"skillVersion": "0.8.0-alpha+skill.e73cb0ba5184",
|
|
4
4
|
"sdk": {
|
|
5
5
|
"package": "@heybox/hb-sdk",
|
|
6
|
-
"version": "0.
|
|
7
|
-
"compatibility": "0.
|
|
6
|
+
"version": "0.8.0-alpha",
|
|
7
|
+
"compatibility": "0.8.0-alpha"
|
|
8
8
|
},
|
|
9
9
|
"source": "https://open.xiaoheihe.cn/agent-skills/hb-sdk",
|
|
10
|
-
"integrity": "sha256-
|
|
10
|
+
"integrity": "sha256-e73cb0ba518459e1b262d09fb0ead87a7163c8e5358430184a9dd4f085049357"
|
|
11
11
|
}
|