@heybox/hb-sdk 0.8.1-alpha.1 → 0.8.1-alpha.3
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 +12 -0
- package/README.md +32 -3
- package/dist/cli-chunks/{build-kMLIWqWY.cjs → build-B5Sbi8Sq.cjs} +13 -9
- package/dist/cli-chunks/{context-CzFFRcL4.cjs → context-DuxaBL3Y.cjs} +2 -2
- package/dist/cli-chunks/{create-0ow6gA9w.cjs → create-CIfZrg3F.cjs} +1 -1
- package/dist/cli-chunks/{dev-CPBPdpyu.cjs → dev-CFubP5kW.cjs} +10 -9
- package/dist/cli-chunks/{doctor-DQ8ctFKC.cjs → doctor-IPKn3PBn.cjs} +1 -1
- package/dist/cli-chunks/{index-Buner4kE.cjs → index-DCJN-V1y.cjs} +15 -15
- package/dist/cli-chunks/{index-RDcIrvwi.cjs → index-KHhdZ8eZ.cjs} +2 -2
- package/dist/cli-chunks/{index.esm-qwrdRuy-.cjs → index.esm-8hgZlNF8.cjs} +7 -7
- package/dist/cli-chunks/{login-DoduAO_f.cjs → login-CoB9jXxC.cjs} +2 -2
- package/dist/cli-chunks/{project-vite-B-sK-qup.cjs → project-vite-DMxdOWsU.cjs} +1 -1
- package/dist/cli-chunks/{remote-CF_SRmnj.cjs → remote-D4ZcngLn.cjs} +14 -10
- package/dist/cli-chunks/{runtime-gate-FseEYZze.cjs → runtime-gate-BWb8QIcX.cjs} +0 -107
- package/dist/cli-chunks/{runtime-permission-env-DdQtxdut.cjs → runtime-permission-env-XAZFauvZ.cjs} +125 -9
- package/dist/cli-chunks/{session-DHbw2Xgh.cjs → session-BnoHxzFq.cjs} +1 -1
- package/dist/cli-chunks/{skill-6IVv12JW.cjs → skill-CDEJtATn.cjs} +2 -2
- package/dist/cli-chunks/{version-TXwWxKvv.cjs → version-BGzCIQhE.cjs} +1 -1
- package/dist/cli.cjs +1 -1
- package/dist/devtools/browser-dev-host/assets/browser-dev-host-DzEst9n7.js +99 -0
- package/dist/devtools/browser-dev-host/assets/{index-C5MZZDa5.js → index-B-NHlLsr.js} +2 -2
- package/dist/devtools/browser-dev-host/index.html +1 -1
- package/dist/index.cjs.js +83 -2
- package/dist/index.esm.js +83 -3
- package/dist/templates/vanilla-vite-js/README.md.ejs +1 -1
- package/dist/templates/vanilla-vite-js/package.json.ejs +1 -0
- package/dist/templates/vanilla-vite-js/vite.config.js +1 -1
- package/dist/vite.cjs.js +19 -10
- package/dist/vite.esm.js +19 -10
- package/package.json +7 -7
- package/skill/SKILL.md +5 -2
- package/skill/references/api-protocol.md +8 -4
- package/skill/references/api-root.md +114 -12
- package/skill/references/cli.md +2 -2
- package/skill/references/examples.md +9 -1
- package/skill/references/recipes.md +1 -0
- package/skill/references/safety-boundaries.md +1 -1
- package/skill/skill.json +5 -5
- package/types/core/client.d.ts +7 -1
- package/types/core/sdk.d.ts +3 -0
- package/types/core/singleton.d.ts +3 -0
- package/types/index.d.ts +3 -1
- package/types/miniapp-manifest/node.d.ts +2 -0
- package/types/miniapp-manifest/schema.d.ts +1 -0
- package/types/modules/environment/index.d.ts +70 -0
- package/types/protocol.d.ts +1 -1
- package/types/vite/index.d.ts +1 -4
- package/dist/devtools/browser-dev-host/assets/browser-dev-host-TzYf9L6C.js +0 -99
package/dist/cli-chunks/{runtime-permission-env-DdQtxdut.cjs → runtime-permission-env-XAZFauvZ.cjs}
RENAMED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var fs = require('node:fs');
|
|
4
4
|
var path = require('node:path');
|
|
5
|
-
var version = require('./version-
|
|
5
|
+
var version = require('./version-BGzCIQhE.cjs');
|
|
6
6
|
var node_async_hooks = require('node:async_hooks');
|
|
7
7
|
|
|
8
8
|
var re = {exports: {}};
|
|
@@ -3069,6 +3069,111 @@ function isRecord$1(value) {
|
|
|
3069
3069
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
3070
3070
|
}
|
|
3071
3071
|
|
|
3072
|
+
const MINIAPP_PLATFORM_VALUES = ['android', 'ios', 'ohos', 'windows', 'macos', 'linux'];
|
|
3073
|
+
function isValidMiniappManifestVersion(version) {
|
|
3074
|
+
return getMiniappManifestVersionError(version) === undefined;
|
|
3075
|
+
}
|
|
3076
|
+
function validateMiniappManifestVersion(version, sourceLabel = 'manifest.version') {
|
|
3077
|
+
const error = getMiniappManifestVersionError(version);
|
|
3078
|
+
if (error) {
|
|
3079
|
+
throw new Error(`${sourceLabel} ${error}`);
|
|
3080
|
+
}
|
|
3081
|
+
return String(version).trim();
|
|
3082
|
+
}
|
|
3083
|
+
function parseMiniappManifestJson(raw, sourceLabel = 'manifest.json') {
|
|
3084
|
+
const hadBom = raw.charCodeAt(0) === 0xfeff;
|
|
3085
|
+
const text = hadBom ? raw.slice(1) : raw;
|
|
3086
|
+
let parsed;
|
|
3087
|
+
try {
|
|
3088
|
+
parsed = JSON.parse(text);
|
|
3089
|
+
}
|
|
3090
|
+
catch (error) {
|
|
3091
|
+
throw new Error(`${sourceLabel} 不是合法 JSON:${formatReason$1(error)}`);
|
|
3092
|
+
}
|
|
3093
|
+
if (!isManifestRecord(parsed)) {
|
|
3094
|
+
throw new Error(`${sourceLabel} 必须是 JSON 对象`);
|
|
3095
|
+
}
|
|
3096
|
+
return {
|
|
3097
|
+
manifest: parsed,
|
|
3098
|
+
hadBom,
|
|
3099
|
+
};
|
|
3100
|
+
}
|
|
3101
|
+
function validateMiniappManifestForDeploy(manifest) {
|
|
3102
|
+
const version = validateMiniappManifestVersion(manifest.version, 'manifest.version');
|
|
3103
|
+
const sdkVersion = validateSdkVersion(manifest.sdkVersion, 'manifest.sdkVersion');
|
|
3104
|
+
const permissions = parseMiniappPermissions(manifest.permissions, {
|
|
3105
|
+
present: Object.prototype.hasOwnProperty.call(manifest, 'permissions'),
|
|
3106
|
+
sdkVersion,
|
|
3107
|
+
sourceLabel: 'manifest.permissions',
|
|
3108
|
+
});
|
|
3109
|
+
return {
|
|
3110
|
+
version,
|
|
3111
|
+
sdkVersion,
|
|
3112
|
+
platforms: validateMiniappPlatforms(manifest.platforms, 'manifest.platforms'),
|
|
3113
|
+
...(permissions.permissions === undefined ? {} : { permissions: permissions.permissions }),
|
|
3114
|
+
};
|
|
3115
|
+
}
|
|
3116
|
+
function validateMiniappPlatforms(platforms, sourceLabel = 'platforms') {
|
|
3117
|
+
if (!Array.isArray(platforms) || platforms.length === 0) {
|
|
3118
|
+
throw new Error(`${sourceLabel} 必须是非空平台数组`);
|
|
3119
|
+
}
|
|
3120
|
+
const allowedPlatforms = new Set(MINIAPP_PLATFORM_VALUES);
|
|
3121
|
+
const seen = new Set();
|
|
3122
|
+
for (const platform of platforms) {
|
|
3123
|
+
if (typeof platform !== 'string' || !allowedPlatforms.has(platform)) {
|
|
3124
|
+
throw new Error(`${sourceLabel} 包含不支持的平台:${String(platform)}`);
|
|
3125
|
+
}
|
|
3126
|
+
if (seen.has(platform)) {
|
|
3127
|
+
throw new Error(`${sourceLabel} 包含重复平台:${platform}`);
|
|
3128
|
+
}
|
|
3129
|
+
seen.add(platform);
|
|
3130
|
+
}
|
|
3131
|
+
return Object.freeze(MINIAPP_PLATFORM_VALUES.filter((platform) => seen.has(platform)));
|
|
3132
|
+
}
|
|
3133
|
+
function areMiniappPlatformsEqual(left, right) {
|
|
3134
|
+
return left.length === right.length && left.every((platform, index) => platform === right[index]);
|
|
3135
|
+
}
|
|
3136
|
+
function validateSdkVersion(version, sourceLabel = 'sdkVersion') {
|
|
3137
|
+
if (typeof version !== 'string' || version.trim() === '') {
|
|
3138
|
+
throw new Error(`${sourceLabel} 必须是合法 SemVer:${String(version)}`);
|
|
3139
|
+
}
|
|
3140
|
+
const normalized = version.trim();
|
|
3141
|
+
const parsed = semverExports.parse(normalized);
|
|
3142
|
+
if (!parsed || parsed.version !== normalized || parsed.build.length > 0) {
|
|
3143
|
+
throw new Error(`${sourceLabel} 必须是合法 SemVer:${normalized}`);
|
|
3144
|
+
}
|
|
3145
|
+
return normalized;
|
|
3146
|
+
}
|
|
3147
|
+
function isManifestRecord(value) {
|
|
3148
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
3149
|
+
}
|
|
3150
|
+
function getMiniappManifestVersionError(version) {
|
|
3151
|
+
if (typeof version !== 'string' || version.trim() === '') {
|
|
3152
|
+
return `必须是合法 SemVer:${String(version)}`;
|
|
3153
|
+
}
|
|
3154
|
+
const normalized = version.trim();
|
|
3155
|
+
const parsed = semverExports.parse(normalized);
|
|
3156
|
+
if (!parsed) {
|
|
3157
|
+
return `必须是合法 SemVer:${normalized}`;
|
|
3158
|
+
}
|
|
3159
|
+
if (parsed.build.length > 0) {
|
|
3160
|
+
return `不能包含 build metadata:${normalized}`;
|
|
3161
|
+
}
|
|
3162
|
+
if (parsed.version !== normalized) {
|
|
3163
|
+
return `必须是合法 SemVer:${normalized}`;
|
|
3164
|
+
}
|
|
3165
|
+
if (parsed.major === 0 && parsed.minor === 0 && parsed.patch === 0) {
|
|
3166
|
+
return '不能是模板默认版本 0.0.0';
|
|
3167
|
+
}
|
|
3168
|
+
return undefined;
|
|
3169
|
+
}
|
|
3170
|
+
function formatReason$1(error) {
|
|
3171
|
+
if (error instanceof Error && error.message) {
|
|
3172
|
+
return error.message;
|
|
3173
|
+
}
|
|
3174
|
+
return String(error);
|
|
3175
|
+
}
|
|
3176
|
+
|
|
3072
3177
|
const MINIAPP_UPLOAD_SCOPE = 'activity';
|
|
3073
3178
|
const ACTIVITY_UPLOAD_KEY_MAX_LENGTH = 64;
|
|
3074
3179
|
const MINIAPP_UPLOAD_BATCH_SIZE = 50;
|
|
@@ -3359,14 +3464,16 @@ function findNearestPackageJsonPath(startDir) {
|
|
|
3359
3464
|
current = parent;
|
|
3360
3465
|
}
|
|
3361
3466
|
}
|
|
3467
|
+
function readMiniappPlatformsFromPackageJson(root) {
|
|
3468
|
+
const { packageJson } = readMiniappPackageJson(root);
|
|
3469
|
+
const heybox = readMiniappHeyboxConfig(packageJson);
|
|
3470
|
+
return validateMiniappPlatforms(heybox?.platforms, 'package.json#heybox.platforms');
|
|
3471
|
+
}
|
|
3362
3472
|
function readMiniappPermissionsFromPackageJson(root, sdkVersion) {
|
|
3363
3473
|
const { packageJson } = readMiniappPackageJson(root);
|
|
3364
|
-
const heybox = packageJson
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
}
|
|
3368
|
-
const present = isRecord(heybox) && Object.prototype.hasOwnProperty.call(heybox, 'permissions');
|
|
3369
|
-
return parseMiniappPermissions(isRecord(heybox) ? heybox.permissions : undefined, {
|
|
3474
|
+
const heybox = readMiniappHeyboxConfig(packageJson);
|
|
3475
|
+
const present = heybox !== undefined && Object.prototype.hasOwnProperty.call(heybox, 'permissions');
|
|
3476
|
+
return parseMiniappPermissions(heybox?.permissions, {
|
|
3370
3477
|
present,
|
|
3371
3478
|
sdkVersion,
|
|
3372
3479
|
});
|
|
@@ -3397,6 +3504,12 @@ function readMiniappPackageJson(root, requireVersion) {
|
|
|
3397
3504
|
}
|
|
3398
3505
|
return { packageJson, version: typeof packageJson.version === 'string' ? packageJson.version.trim() : '' };
|
|
3399
3506
|
}
|
|
3507
|
+
function readMiniappHeyboxConfig(packageJson) {
|
|
3508
|
+
if (packageJson.heybox !== undefined && !isRecord(packageJson.heybox)) {
|
|
3509
|
+
throw new Error('@heybox/hb-sdk 提示:package.json#heybox 必须是 JSON 对象');
|
|
3510
|
+
}
|
|
3511
|
+
return packageJson.heybox;
|
|
3512
|
+
}
|
|
3400
3513
|
function isRecord(value) {
|
|
3401
3514
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
3402
3515
|
}
|
|
@@ -3498,23 +3611,26 @@ exports.USER_MINIPROGRAM_ACCESS_STATUS_API_PATH = USER_MINIPROGRAM_ACCESS_STATUS
|
|
|
3498
3611
|
exports.USER_MINIPROGRAM_PREVIEW_ALLOWLIST_API_PATH = USER_MINIPROGRAM_PREVIEW_ALLOWLIST_API_PATH;
|
|
3499
3612
|
exports.USER_MINIPROGRAM_VERSION_PREVIEW_INFO_API_PATH = USER_MINIPROGRAM_VERSION_PREVIEW_INFO_API_PATH;
|
|
3500
3613
|
exports.WITHDRAW_USER_MINIPROGRAM_VERSION_API_PATH = WITHDRAW_USER_MINIPROGRAM_VERSION_API_PATH;
|
|
3614
|
+
exports.areMiniappPlatformsEqual = areMiniappPlatformsEqual;
|
|
3501
3615
|
exports.composeMiniappRuntimePermissions = composeMiniappRuntimePermissions;
|
|
3502
3616
|
exports.createMiniappArtifactFileHeader = createMiniappArtifactFileHeader;
|
|
3503
3617
|
exports.createMiniappArtifactSignatureHeader = createMiniappArtifactSignatureHeader;
|
|
3504
3618
|
exports.createMiniappPlatformCspEnv = createMiniappPlatformCspEnv;
|
|
3505
3619
|
exports.getMissingPermissionsWarning = getMissingPermissionsWarning;
|
|
3620
|
+
exports.isValidMiniappManifestVersion = isValidMiniappManifestVersion;
|
|
3506
3621
|
exports.normalizeRelativePath = normalizeRelativePath;
|
|
3507
3622
|
exports.parseMiniProgramRuntimePermissions = parseMiniProgramRuntimePermissions;
|
|
3508
|
-
exports.
|
|
3623
|
+
exports.parseMiniappManifestJson = parseMiniappManifestJson;
|
|
3509
3624
|
exports.prepareMiniappArtifactFiles = prepareMiniappArtifactFiles;
|
|
3510
3625
|
exports.readMiniappPermissionsFromPackageJson = readMiniappPermissionsFromPackageJson;
|
|
3626
|
+
exports.readMiniappPlatformsFromPackageJson = readMiniappPlatformsFromPackageJson;
|
|
3511
3627
|
exports.relativePathContainsNodeModulesSegment = relativePathContainsNodeModulesSegment;
|
|
3512
3628
|
exports.requireSemver = requireSemver;
|
|
3513
3629
|
exports.resolveMiniappSdkVersion = resolveMiniappSdkVersion;
|
|
3514
3630
|
exports.resolveMiniappUploadSessionFiles = resolveMiniappUploadSessionFiles;
|
|
3515
|
-
exports.semverExports = semverExports;
|
|
3516
3631
|
exports.shouldSkipMiniappPlatformCspFromEnv = shouldSkipMiniappPlatformCspFromEnv;
|
|
3517
3632
|
exports.shouldUploadDistFile = shouldUploadDistFile;
|
|
3633
|
+
exports.validateMiniappManifestForDeploy = validateMiniappManifestForDeploy;
|
|
3518
3634
|
exports.validateMiniappUploadPathLengths = validateMiniappUploadPathLengths;
|
|
3519
3635
|
exports.validateUploadTotalSize = validateUploadTotalSize;
|
|
3520
3636
|
exports.withMiniappPlatformCspEnv = withMiniappPlatformCspEnv;
|
|
@@ -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-BGzCIQhE.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-DCJN-V1y.cjs');
|
|
8
8
|
require('node:module');
|
|
9
9
|
require('node:fs');
|
|
10
10
|
require('path');
|