@heybox/hb-sdk 0.6.6-alpha.3 → 0.6.6-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/cli-chunks/{build-De-QADpA.cjs → build-C54stoRf.cjs} +31 -26
- package/dist/cli-chunks/{context-CvZs9ZBf.cjs → context-DvTynj3F.cjs} +122 -23
- package/dist/cli-chunks/{create-B5gGBaSV.cjs → create-uQS30kS_.cjs} +1 -1
- package/dist/cli-chunks/{dev-BcCWCeac.cjs → dev-1wE8dNiL.cjs} +24 -113
- package/dist/cli-chunks/{doctor-BhBM4cWH.cjs → doctor-B2aCUOQ7.cjs} +1 -1
- package/dist/cli-chunks/{index-QAkYgxPI.cjs → index-19i3Dr5H.cjs} +14 -14
- package/dist/cli-chunks/{index-DyUo67lf.cjs → index-DypVMqsr.cjs} +3 -3
- package/dist/cli-chunks/{login-BNLH13Zd.cjs → login-BIIUGwoq.cjs} +2 -2
- package/dist/cli-chunks/{project-vite-VcJMyz1l.cjs → project-vite-Dl3OoQjL.cjs} +1 -1
- package/dist/cli-chunks/{remote-BE53wntR.cjs → remote-47MjCKhu.cjs} +40 -22
- package/dist/cli-chunks/{runtime-gate-B2MQf1vc.cjs → runtime-gate--rPXjiG6.cjs} +3 -3
- package/dist/cli-chunks/{index-BQm5XmMC.cjs → runtime-permission-env-BSs4uCNa.cjs} +71 -0
- package/dist/cli-chunks/{session-YJ8xNESM.cjs → session-DJEuhrgq.cjs} +1 -1
- package/dist/cli.cjs +1 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/vite.cjs.js +20 -3
- package/dist/vite.esm.js +20 -3
- package/package.json +2 -2
- package/skill/references/api-root.md +11 -4
- package/skill/skill.json +4 -4
- package/types/vite/html-policy.d.ts +1 -0
- package/types/vite/runtime-permission-env.d.ts +9 -0
|
@@ -234,19 +234,19 @@ function requireArgument () {
|
|
|
234
234
|
|
|
235
235
|
var command = {};
|
|
236
236
|
|
|
237
|
-
const require$5 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/index-
|
|
237
|
+
const require$5 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/index-19i3Dr5H.cjs', document.baseURI).href)));
|
|
238
238
|
function __require$4() { return require$5("node:events"); }
|
|
239
239
|
|
|
240
|
-
const require$4 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/index-
|
|
240
|
+
const require$4 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/index-19i3Dr5H.cjs', document.baseURI).href)));
|
|
241
241
|
function __require$3() { return require$4("node:child_process"); }
|
|
242
242
|
|
|
243
|
-
const require$3 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/index-
|
|
243
|
+
const require$3 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/index-19i3Dr5H.cjs', document.baseURI).href)));
|
|
244
244
|
function __require$2() { return require$3("node:path"); }
|
|
245
245
|
|
|
246
|
-
const require$2 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/index-
|
|
246
|
+
const require$2 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/index-19i3Dr5H.cjs', document.baseURI).href)));
|
|
247
247
|
function __require$1() { return require$2("node:fs"); }
|
|
248
248
|
|
|
249
|
-
const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/index-
|
|
249
|
+
const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/index-19i3Dr5H.cjs', document.baseURI).href)));
|
|
250
250
|
function __require() { return require$1("node:process"); }
|
|
251
251
|
|
|
252
252
|
var help = {};
|
|
@@ -13347,7 +13347,7 @@ function getPathname(pathWithQuery) {
|
|
|
13347
13347
|
}
|
|
13348
13348
|
|
|
13349
13349
|
const CLI_VERSION_PLACEHOLDER = ['__HB', 'SDK', 'CLI', 'VERSION__'].join('_');
|
|
13350
|
-
const BUILT_CLI_VERSION = '0.6.6-alpha.
|
|
13350
|
+
const BUILT_CLI_VERSION = '0.6.6-alpha.4';
|
|
13351
13351
|
const PACKAGE_JSON_CANDIDATES = [
|
|
13352
13352
|
path.resolve(__dirname, '..', '..', 'package.json'),
|
|
13353
13353
|
path.resolve(__dirname, '..', 'package.json'),
|
|
@@ -13680,35 +13680,35 @@ function createCommandLoggerResolver(options) {
|
|
|
13680
13680
|
};
|
|
13681
13681
|
}
|
|
13682
13682
|
const defaultClearLoginStatus = async (...args) => {
|
|
13683
|
-
const { clearLoginStatus } = await Promise.resolve().then(function () { return require('./login-
|
|
13683
|
+
const { clearLoginStatus } = await Promise.resolve().then(function () { return require('./login-BIIUGwoq.cjs'); });
|
|
13684
13684
|
return clearLoginStatus(...args);
|
|
13685
13685
|
};
|
|
13686
13686
|
const defaultLoginToHeybox = async (...args) => {
|
|
13687
|
-
const { loginToHeybox } = await Promise.resolve().then(function () { return require('./login-
|
|
13687
|
+
const { loginToHeybox } = await Promise.resolve().then(function () { return require('./login-BIIUGwoq.cjs'); });
|
|
13688
13688
|
return loginToHeybox(...args);
|
|
13689
13689
|
};
|
|
13690
13690
|
const defaultPrintLoginStatus = async (...args) => {
|
|
13691
|
-
const { printLoginStatus } = await Promise.resolve().then(function () { return require('./login-
|
|
13691
|
+
const { printLoginStatus } = await Promise.resolve().then(function () { return require('./login-BIIUGwoq.cjs'); });
|
|
13692
13692
|
return printLoginStatus(...args);
|
|
13693
13693
|
};
|
|
13694
13694
|
const defaultRunBuildCommand = async (...args) => {
|
|
13695
|
-
const { runBuildCommand } = await Promise.resolve().then(function () { return require('./build-
|
|
13695
|
+
const { runBuildCommand } = await Promise.resolve().then(function () { return require('./build-C54stoRf.cjs'); });
|
|
13696
13696
|
return runBuildCommand(...args);
|
|
13697
13697
|
};
|
|
13698
13698
|
const defaultRunCreateCommand = async (...args) => {
|
|
13699
|
-
const { runCreateCommand } = await Promise.resolve().then(function () { return require('./create-
|
|
13699
|
+
const { runCreateCommand } = await Promise.resolve().then(function () { return require('./create-uQS30kS_.cjs'); });
|
|
13700
13700
|
return runCreateCommand(...args);
|
|
13701
13701
|
};
|
|
13702
13702
|
const defaultRunDevCommand = async (...args) => {
|
|
13703
|
-
const { runDevCommand } = await Promise.resolve().then(function () { return require('./dev-
|
|
13703
|
+
const { runDevCommand } = await Promise.resolve().then(function () { return require('./dev-1wE8dNiL.cjs'); });
|
|
13704
13704
|
return runDevCommand(...args);
|
|
13705
13705
|
};
|
|
13706
13706
|
const defaultRunDoctorCommand = async (...args) => {
|
|
13707
|
-
const { runDoctorCommand } = await Promise.resolve().then(function () { return require('./doctor-
|
|
13707
|
+
const { runDoctorCommand } = await Promise.resolve().then(function () { return require('./doctor-B2aCUOQ7.cjs'); });
|
|
13708
13708
|
return runDoctorCommand(...args);
|
|
13709
13709
|
};
|
|
13710
13710
|
const defaultRunRemoteCommand = async (...args) => {
|
|
13711
|
-
const { runRemoteCommand } = await Promise.resolve().then(function () { return require('./remote-
|
|
13711
|
+
const { runRemoteCommand } = await Promise.resolve().then(function () { return require('./remote-47MjCKhu.cjs'); });
|
|
13712
13712
|
return runRemoteCommand(...args);
|
|
13713
13713
|
};
|
|
13714
13714
|
function resolveStandaloneLogger(options, verbose) {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var index$2 = require('./index-
|
|
3
|
+
var index$2 = require('./index-19i3Dr5H.cjs');
|
|
4
4
|
var require$$0$2 = require('fs');
|
|
5
5
|
var require$$2$1 = require('crypto');
|
|
6
6
|
var require$$1$2 = require('path');
|
|
7
7
|
var require$$0$3 = require('assert');
|
|
8
8
|
var require$$4$2 = require('events');
|
|
9
9
|
var require$$1$1 = require('util');
|
|
10
|
-
var
|
|
10
|
+
var runtimePermissionEnv = require('./runtime-permission-env-BSs4uCNa.cjs');
|
|
11
11
|
var require$$0$5 = require('net');
|
|
12
12
|
var require$$0$4 = require('url');
|
|
13
13
|
var require$$2$2 = require('http');
|
|
@@ -13707,7 +13707,7 @@ function requireSource () {
|
|
|
13707
13707
|
const ajv_1 = requireAjv$1();
|
|
13708
13708
|
const ajv_formats_1 = requireDist();
|
|
13709
13709
|
const debounceFn = requireDebounceFn();
|
|
13710
|
-
const semver =
|
|
13710
|
+
const semver = runtimePermissionEnv.requireSemver();
|
|
13711
13711
|
const onetime = index$2.requireOnetime();
|
|
13712
13712
|
const encryptionAlgorithm = 'aes-256-cbc';
|
|
13713
13713
|
const createPlainObject = () => {
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
var promises = require('node:readline/promises');
|
|
4
4
|
var node_crypto = require('node:crypto');
|
|
5
5
|
var node_http = require('node:http');
|
|
6
|
-
var session = require('./session-
|
|
6
|
+
var session = require('./session-DJEuhrgq.cjs');
|
|
7
7
|
var browser = require('./browser-RAy8e8cV.cjs');
|
|
8
|
-
var index = require('./index-
|
|
8
|
+
var index = require('./index-19i3Dr5H.cjs');
|
|
9
9
|
require('node:path');
|
|
10
10
|
require('fs');
|
|
11
11
|
require('constants');
|
|
@@ -5,7 +5,7 @@ var fs$1 = require('node:fs/promises');
|
|
|
5
5
|
var node_module = require('node:module');
|
|
6
6
|
var path = require('node:path');
|
|
7
7
|
var node_url = require('node:url');
|
|
8
|
-
var index = require('./index-
|
|
8
|
+
var index = require('./index-19i3Dr5H.cjs');
|
|
9
9
|
|
|
10
10
|
function findProjectRoot(startDir) {
|
|
11
11
|
let current = path.resolve(startDir);
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var promises = require('node:readline/promises');
|
|
4
|
-
var index = require('./index-
|
|
5
|
-
var session = require('./session-
|
|
4
|
+
var index = require('./index-19i3Dr5H.cjs');
|
|
5
|
+
var session = require('./session-DJEuhrgq.cjs');
|
|
6
6
|
var childProcess = require('node:child_process');
|
|
7
7
|
var fs = require('node:fs');
|
|
8
8
|
var fs$1 = require('node:fs/promises');
|
|
9
9
|
var path = require('node:path');
|
|
10
|
-
var
|
|
11
|
-
var runtimeGate = require('./runtime-gate
|
|
12
|
-
var context = require('./context-
|
|
10
|
+
var runtimePermissionEnv = require('./runtime-permission-env-BSs4uCNa.cjs');
|
|
11
|
+
var runtimeGate = require('./runtime-gate--rPXjiG6.cjs');
|
|
12
|
+
var context = require('./context-DvTynj3F.cjs');
|
|
13
13
|
require('node:module');
|
|
14
14
|
require('path');
|
|
15
15
|
require('os');
|
|
@@ -23,6 +23,7 @@ require('util');
|
|
|
23
23
|
require('node:crypto');
|
|
24
24
|
require('fs');
|
|
25
25
|
require('constants');
|
|
26
|
+
require('node:async_hooks');
|
|
26
27
|
|
|
27
28
|
async function getCDNUploadInfo(options, runtime = {}) {
|
|
28
29
|
const body = new URLSearchParams();
|
|
@@ -69,7 +70,7 @@ async function runUpload(options, runtime = {}) {
|
|
|
69
70
|
const postCDNUploadCallback$1 = runtime.postCDNUploadCallback ?? postCDNUploadCallback;
|
|
70
71
|
const createReadStream = runtime.createReadStream ?? fs.createReadStream;
|
|
71
72
|
const orderedFiles = [...options.files].sort((a, b) => a.relativePath.localeCompare(b.relativePath));
|
|
72
|
-
const batches = chunkUploadFiles(orderedFiles,
|
|
73
|
+
const batches = chunkUploadFiles(orderedFiles, runtimePermissionEnv.MINIAPP_UPLOAD_BATCH_SIZE);
|
|
73
74
|
await logger.task(`正在上传 ${orderedFiles.length} 个文件`, async (taskContext) => {
|
|
74
75
|
logger.debug(`上传并发数: ${concurrency}`);
|
|
75
76
|
logger.debug(`上传批次数: ${batches.length}`);
|
|
@@ -79,7 +80,7 @@ async function runUpload(options, runtime = {}) {
|
|
|
79
80
|
logger.debug(`正在处理上传批次 ${batchIndex + 1}/${batches.length},文件数: ${batch.length}`);
|
|
80
81
|
logger.debug('正在获取 CDN 上传信息');
|
|
81
82
|
const fileInfos = createUploadFileInfos(batch, options);
|
|
82
|
-
const uploadInfo = await getCDNUploadInfo$1({ session: options.session, scope:
|
|
83
|
+
const uploadInfo = await getCDNUploadInfo$1({ session: options.session, scope: runtimePermissionEnv.MINIAPP_UPLOAD_SCOPE, fileInfos, needCache: false }, { baseUrl: runtime.baseUrl, fetchImpl });
|
|
83
84
|
logger.debug(`CDN bucket: ${uploadInfo.bucket}`);
|
|
84
85
|
logger.debug(`CDN region: ${uploadInfo.region}`);
|
|
85
86
|
validateUploadInfoKeys(batch, uploadInfo.keys, options);
|
|
@@ -140,7 +141,7 @@ function createUploadFileInfos(files, options) {
|
|
|
140
141
|
name: file.relativePath.split('/').pop() ?? file.relativePath,
|
|
141
142
|
mimetype: file.mimeType,
|
|
142
143
|
fsize: file.size,
|
|
143
|
-
path:
|
|
144
|
+
path: runtimePermissionEnv.getMiniappUploadKey({
|
|
144
145
|
miniProgramId: options.miniProgramId,
|
|
145
146
|
version: options.version,
|
|
146
147
|
relativePath: file.relativePath,
|
|
@@ -151,15 +152,15 @@ function validateUploadInfoKeys(files, keys, options) {
|
|
|
151
152
|
if (keys.length !== files.length) {
|
|
152
153
|
throw new index.CliError(`CDN 上传接口返回 key 数量异常:期望 ${files.length},实际 ${keys.length}`);
|
|
153
154
|
}
|
|
154
|
-
for (let index$
|
|
155
|
-
const expectedKey =
|
|
155
|
+
for (let index$1 = 0; index$1 < files.length; index$1 += 1) {
|
|
156
|
+
const expectedKey = runtimePermissionEnv.getMiniappUploadKey({
|
|
156
157
|
miniProgramId: options.miniProgramId,
|
|
157
158
|
version: options.version,
|
|
158
|
-
relativePath: files[index$
|
|
159
|
+
relativePath: files[index$1].relativePath,
|
|
159
160
|
});
|
|
160
|
-
const actualKey = keys[index$
|
|
161
|
+
const actualKey = keys[index$1];
|
|
161
162
|
if (actualKey !== expectedKey) {
|
|
162
|
-
throw new index.CliError(`CDN 上传接口返回 key 异常:${files[index$
|
|
163
|
+
throw new index.CliError(`CDN 上传接口返回 key 异常:${files[index$1].relativePath}`, [`CDN 上传接口返回 key 异常:${files[index$1].relativePath}`, `expected: ${expectedKey}`, `actual: ${actualKey}`].join('\n'));
|
|
163
164
|
}
|
|
164
165
|
}
|
|
165
166
|
}
|
|
@@ -191,7 +192,7 @@ async function createDefaultCosClient(uploadToken) {
|
|
|
191
192
|
};
|
|
192
193
|
}
|
|
193
194
|
async function loadCosConstructor() {
|
|
194
|
-
const cosModule = await Promise.resolve().then(function () { return require('./index-
|
|
195
|
+
const cosModule = await Promise.resolve().then(function () { return require('./index-DypVMqsr.cjs'); }).then(function (n) { return n.index; });
|
|
195
196
|
return cosModule.default;
|
|
196
197
|
}
|
|
197
198
|
function formatSize(bytes) {
|
|
@@ -235,7 +236,7 @@ function isRecord(value) {
|
|
|
235
236
|
}
|
|
236
237
|
|
|
237
238
|
async function precheckUserMiniprogramVersion(options, runtime = {}) {
|
|
238
|
-
return postUserMiniprogramVersionForm(
|
|
239
|
+
return postUserMiniprogramVersionForm(runtimePermissionEnv.PRECHECK_USER_MINIPROGRAM_VERSION_API_PATH, options, {
|
|
239
240
|
// 展示资料由服务端沿用 last approved 或注入默认名/默认图;CLI 不传 name/icon/cover。
|
|
240
241
|
...(options.version ? { version: options.version } : {}),
|
|
241
242
|
...(options.source_version ? { source_version: options.source_version } : {}),
|
|
@@ -244,7 +245,7 @@ async function precheckUserMiniprogramVersion(options, runtime = {}) {
|
|
|
244
245
|
}, runtime);
|
|
245
246
|
}
|
|
246
247
|
async function submitUserMiniprogramAudit(options, runtime = {}) {
|
|
247
|
-
return postUserMiniprogramVersionForm(
|
|
248
|
+
return postUserMiniprogramVersionForm(runtimePermissionEnv.SUBMIT_USER_MINIPROGRAM_AUDIT_API_PATH, options, {
|
|
248
249
|
// 展示资料由服务端沿用 last approved 或注入默认名/默认图;CLI 不传 name/icon/cover。
|
|
249
250
|
...(options.manifest ? { manifest: JSON.stringify(options.manifest) } : {}),
|
|
250
251
|
...(options.source_version ? { source_version: options.source_version } : {}),
|
|
@@ -341,11 +342,28 @@ async function runDeployCommand(options, runtime = {}) {
|
|
|
341
342
|
releaseNote,
|
|
342
343
|
autoPublish,
|
|
343
344
|
}, runtime, apiBaseUrl, projectRoot, logger);
|
|
345
|
+
let skipPlatformCsp = false;
|
|
346
|
+
try {
|
|
347
|
+
const { detail } = await logger.task('正在读取远端小程序权限', () => (runtime.getBoundMiniProgram ?? context.getBoundMiniProgram)({
|
|
348
|
+
allowUnsafeApiBaseUrl: options.allowUnsafeApiBaseUrl,
|
|
349
|
+
apiBaseUrl,
|
|
350
|
+
cwd: projectRoot,
|
|
351
|
+
env,
|
|
352
|
+
fetchImpl: runtime.fetchImpl,
|
|
353
|
+
loginBaseUrl,
|
|
354
|
+
session: session$1,
|
|
355
|
+
}), { successText: '已读取远端小程序权限' });
|
|
356
|
+
skipPlatformCsp = context.shouldSkipMiniappPlatformCsp(detail.runtime_permissions);
|
|
357
|
+
}
|
|
358
|
+
catch (error) {
|
|
359
|
+
logger.warn('未读取到远端 Runtime 权限,构建将继续注入平台 CSP。');
|
|
360
|
+
logger.debug(`远端 Runtime 权限读取失败详情:${index.readRedactedErrorMessage(error, { verbose: true })}`);
|
|
361
|
+
}
|
|
344
362
|
const pm = detectPackageManager(projectRoot);
|
|
345
363
|
const buildMode = env.HB_SDK_ENV?.trim();
|
|
346
364
|
logger.info(`开始构建: ${pm} ${createBuildArgs(pm, buildMode).join(' ')}`);
|
|
347
365
|
await runBuildScript(pm, projectRoot, runtime.spawn ?? childProcess.spawn, {
|
|
348
|
-
env,
|
|
366
|
+
env: runtimePermissionEnv.createMiniappPlatformCspEnv(env, skipPlatformCsp),
|
|
349
367
|
mode: buildMode,
|
|
350
368
|
outputMode: options.buildOutputMode ?? 'inherit',
|
|
351
369
|
stderr: runtime.stderr,
|
|
@@ -364,16 +382,16 @@ async function runDeployCommand(options, runtime = {}) {
|
|
|
364
382
|
}
|
|
365
383
|
const uploadFiles = await logger.task('正在校验 dist 上传文件', async () => {
|
|
366
384
|
const allFiles = await walkDistFiles(distDir);
|
|
367
|
-
const blocked = allFiles.find((entry) =>
|
|
385
|
+
const blocked = allFiles.find((entry) => runtimePermissionEnv.relativePathContainsNodeModulesSegment(entry.relativePath));
|
|
368
386
|
if (blocked) {
|
|
369
387
|
throw new Error(`dist 目录含 node_modules:${blocked.relativePath}`);
|
|
370
388
|
}
|
|
371
|
-
const files = allFiles.filter((entry) =>
|
|
372
|
-
const pathError =
|
|
389
|
+
const files = allFiles.filter((entry) => runtimePermissionEnv.shouldUploadDistFile(entry.relativePath));
|
|
390
|
+
const pathError = runtimePermissionEnv.validateUploadPaths(files, { miniProgramId, version, maxLength: runtimePermissionEnv.ACTIVITY_UPLOAD_KEY_MAX_LENGTH });
|
|
373
391
|
if (pathError) {
|
|
374
392
|
throw new Error(pathError);
|
|
375
393
|
}
|
|
376
|
-
const sizeError =
|
|
394
|
+
const sizeError = runtimePermissionEnv.validateUploadTotalSize(files);
|
|
377
395
|
if (sizeError) {
|
|
378
396
|
throw new Error(sizeError);
|
|
379
397
|
}
|
|
@@ -582,7 +600,7 @@ async function walkDistFiles(distDir) {
|
|
|
582
600
|
}
|
|
583
601
|
const fileStat = await fs$1.stat(absPath);
|
|
584
602
|
results.push({
|
|
585
|
-
relativePath:
|
|
603
|
+
relativePath: runtimePermissionEnv.normalizeRelativePath(relPath),
|
|
586
604
|
absolutePath: absPath,
|
|
587
605
|
size: fileStat.size,
|
|
588
606
|
mimeType: inferMimeType(entry.name),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var runtimePermissionEnv = require('./runtime-permission-env-BSs4uCNa.cjs');
|
|
4
4
|
|
|
5
5
|
function isValidMiniappManifestVersion(version) {
|
|
6
6
|
return getMiniappManifestVersionError(version) === undefined;
|
|
@@ -41,7 +41,7 @@ function validateSdkVersion(version, sourceLabel = 'sdkVersion') {
|
|
|
41
41
|
throw new Error(`${sourceLabel} 必须是合法 SemVer:${String(version)}`);
|
|
42
42
|
}
|
|
43
43
|
const normalized = version.trim();
|
|
44
|
-
const parsed =
|
|
44
|
+
const parsed = runtimePermissionEnv.semverExports.parse(normalized);
|
|
45
45
|
if (!parsed || parsed.version !== normalized || parsed.build.length > 0) {
|
|
46
46
|
throw new Error(`${sourceLabel} 必须是合法 SemVer:${normalized}`);
|
|
47
47
|
}
|
|
@@ -55,7 +55,7 @@ function getMiniappManifestVersionError(version) {
|
|
|
55
55
|
return `必须是合法 SemVer:${String(version)}`;
|
|
56
56
|
}
|
|
57
57
|
const normalized = version.trim();
|
|
58
|
-
const parsed =
|
|
58
|
+
const parsed = runtimePermissionEnv.semverExports.parse(normalized);
|
|
59
59
|
if (!parsed) {
|
|
60
60
|
return `必须是合法 SemVer:${normalized}`;
|
|
61
61
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var node_async_hooks = require('node:async_hooks');
|
|
4
|
+
|
|
3
5
|
var re = {exports: {}};
|
|
4
6
|
|
|
5
7
|
var constants;
|
|
@@ -2879,6 +2881,72 @@ function shouldUploadDistFile(relativePath) {
|
|
|
2879
2881
|
return true;
|
|
2880
2882
|
}
|
|
2881
2883
|
|
|
2884
|
+
const HB_SDK_RUNTIME_USE_OFFICIAL_DOMAIN_ENV = 'HB_SDK_RUNTIME_USE_OFFICIAL_DOMAIN';
|
|
2885
|
+
const HB_SDK_RUNTIME_PERMISSION_CONTEXT_ENV = 'HB_SDK_RUNTIME_PERMISSION_CONTEXT';
|
|
2886
|
+
const VERIFIED_RUNTIME_PERMISSION_CONTEXT = 'verified';
|
|
2887
|
+
const environmentScopeStorage = new node_async_hooks.AsyncLocalStorage();
|
|
2888
|
+
let environmentScopeTail = Promise.resolve();
|
|
2889
|
+
function shouldSkipMiniappPlatformCspFromEnv(env = process.env) {
|
|
2890
|
+
return env[HB_SDK_RUNTIME_PERMISSION_CONTEXT_ENV] === VERIFIED_RUNTIME_PERMISSION_CONTEXT && env[HB_SDK_RUNTIME_USE_OFFICIAL_DOMAIN_ENV] === '1';
|
|
2891
|
+
}
|
|
2892
|
+
function createMiniappPlatformCspEnv(env, skipPlatformCsp) {
|
|
2893
|
+
return {
|
|
2894
|
+
...env,
|
|
2895
|
+
[HB_SDK_RUNTIME_PERMISSION_CONTEXT_ENV]: VERIFIED_RUNTIME_PERMISSION_CONTEXT,
|
|
2896
|
+
[HB_SDK_RUNTIME_USE_OFFICIAL_DOMAIN_ENV]: skipPlatformCsp ? '1' : '0',
|
|
2897
|
+
};
|
|
2898
|
+
}
|
|
2899
|
+
async function withMiniappPlatformCspEnv(skipPlatformCsp, action, env = process.env) {
|
|
2900
|
+
if (environmentScopeStorage.getStore()?.active) {
|
|
2901
|
+
return runMiniappPlatformCspEnvScope(skipPlatformCsp, action, env);
|
|
2902
|
+
}
|
|
2903
|
+
let releaseScope = () => undefined;
|
|
2904
|
+
const previousScope = environmentScopeTail;
|
|
2905
|
+
environmentScopeTail = new Promise((resolve) => {
|
|
2906
|
+
releaseScope = resolve;
|
|
2907
|
+
});
|
|
2908
|
+
await previousScope;
|
|
2909
|
+
const scope = { active: true };
|
|
2910
|
+
try {
|
|
2911
|
+
return await environmentScopeStorage.run(scope, () => runMiniappPlatformCspEnvScope(skipPlatformCsp, action, env));
|
|
2912
|
+
}
|
|
2913
|
+
finally {
|
|
2914
|
+
scope.active = false;
|
|
2915
|
+
releaseScope();
|
|
2916
|
+
}
|
|
2917
|
+
}
|
|
2918
|
+
async function runMiniappPlatformCspEnvScope(skipPlatformCsp, action, env) {
|
|
2919
|
+
const targets = env === process.env ? [env] : [env, process.env];
|
|
2920
|
+
const previousValues = targets.map((target) => ({
|
|
2921
|
+
context: target[HB_SDK_RUNTIME_PERMISSION_CONTEXT_ENV],
|
|
2922
|
+
officialDomain: target[HB_SDK_RUNTIME_USE_OFFICIAL_DOMAIN_ENV],
|
|
2923
|
+
}));
|
|
2924
|
+
for (const target of targets) {
|
|
2925
|
+
target[HB_SDK_RUNTIME_PERMISSION_CONTEXT_ENV] = VERIFIED_RUNTIME_PERMISSION_CONTEXT;
|
|
2926
|
+
target[HB_SDK_RUNTIME_USE_OFFICIAL_DOMAIN_ENV] = skipPlatformCsp ? '1' : '0';
|
|
2927
|
+
}
|
|
2928
|
+
try {
|
|
2929
|
+
return await action();
|
|
2930
|
+
}
|
|
2931
|
+
finally {
|
|
2932
|
+
targets.forEach((target, index) => {
|
|
2933
|
+
const previousValue = previousValues[index];
|
|
2934
|
+
if (previousValue?.context === undefined) {
|
|
2935
|
+
delete target[HB_SDK_RUNTIME_PERMISSION_CONTEXT_ENV];
|
|
2936
|
+
}
|
|
2937
|
+
else {
|
|
2938
|
+
target[HB_SDK_RUNTIME_PERMISSION_CONTEXT_ENV] = previousValue.context;
|
|
2939
|
+
}
|
|
2940
|
+
if (previousValue?.officialDomain === undefined) {
|
|
2941
|
+
delete target[HB_SDK_RUNTIME_USE_OFFICIAL_DOMAIN_ENV];
|
|
2942
|
+
}
|
|
2943
|
+
else {
|
|
2944
|
+
target[HB_SDK_RUNTIME_USE_OFFICIAL_DOMAIN_ENV] = previousValue.officialDomain;
|
|
2945
|
+
}
|
|
2946
|
+
});
|
|
2947
|
+
}
|
|
2948
|
+
}
|
|
2949
|
+
|
|
2882
2950
|
exports.ACTIVITY_UPLOAD_KEY_MAX_LENGTH = ACTIVITY_UPLOAD_KEY_MAX_LENGTH;
|
|
2883
2951
|
exports.CREATE_USER_MINIPROGRAM_API_PATH = CREATE_USER_MINIPROGRAM_API_PATH;
|
|
2884
2952
|
exports.CREATE_USER_MINIPROGRAM_LEADERBOARD_API_PATH = CREATE_USER_MINIPROGRAM_LEADERBOARD_API_PATH;
|
|
@@ -2903,11 +2971,14 @@ exports.USER_MINIPROGRAM_ACCESS_STATUS_API_PATH = USER_MINIPROGRAM_ACCESS_STATUS
|
|
|
2903
2971
|
exports.USER_MINIPROGRAM_PREVIEW_ALLOWLIST_API_PATH = USER_MINIPROGRAM_PREVIEW_ALLOWLIST_API_PATH;
|
|
2904
2972
|
exports.USER_MINIPROGRAM_VERSION_PREVIEW_INFO_API_PATH = USER_MINIPROGRAM_VERSION_PREVIEW_INFO_API_PATH;
|
|
2905
2973
|
exports.WITHDRAW_USER_MINIPROGRAM_VERSION_API_PATH = WITHDRAW_USER_MINIPROGRAM_VERSION_API_PATH;
|
|
2974
|
+
exports.createMiniappPlatformCspEnv = createMiniappPlatformCspEnv;
|
|
2906
2975
|
exports.getMiniappUploadKey = getMiniappUploadKey;
|
|
2907
2976
|
exports.normalizeRelativePath = normalizeRelativePath;
|
|
2908
2977
|
exports.relativePathContainsNodeModulesSegment = relativePathContainsNodeModulesSegment;
|
|
2909
2978
|
exports.requireSemver = requireSemver;
|
|
2910
2979
|
exports.semverExports = semverExports;
|
|
2980
|
+
exports.shouldSkipMiniappPlatformCspFromEnv = shouldSkipMiniappPlatformCspFromEnv;
|
|
2911
2981
|
exports.shouldUploadDistFile = shouldUploadDistFile;
|
|
2912
2982
|
exports.validateUploadPaths = validateUploadPaths;
|
|
2913
2983
|
exports.validateUploadTotalSize = validateUploadTotalSize;
|
|
2984
|
+
exports.withMiniappPlatformCspEnv = withMiniappPlatformCspEnv;
|
package/dist/cli.cjs
CHANGED
package/dist/index.cjs.js
CHANGED
package/dist/index.esm.js
CHANGED
package/dist/vite.cjs.js
CHANGED
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
var node_fs = require('node:fs');
|
|
4
4
|
var path = require('node:path');
|
|
5
|
+
var node_async_hooks = require('node:async_hooks');
|
|
5
6
|
|
|
6
7
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
7
8
|
/** 构建时替换为当前发布包的实际版本。 */
|
|
8
9
|
const HB_SDK_VERSION = typeof undefined === 'string'
|
|
9
10
|
? undefined
|
|
10
|
-
: '0.6.6-alpha.
|
|
11
|
+
: '0.6.6-alpha.4';
|
|
11
12
|
|
|
12
13
|
var re = {exports: {}};
|
|
13
14
|
|
|
@@ -11471,6 +11472,9 @@ function enforceMiniappHtmlPolicy(html, options = {}) {
|
|
|
11471
11472
|
removePlatformCspMarkers(document);
|
|
11472
11473
|
walk(document, element => validateElement(element));
|
|
11473
11474
|
injectMiniappRuntimeGate(document);
|
|
11475
|
+
if (options.skipPlatformCsp) {
|
|
11476
|
+
return serialize(document);
|
|
11477
|
+
}
|
|
11474
11478
|
const content = options.hmrWebSocketUrl
|
|
11475
11479
|
? PRODUCTION_CSP.replace("connect-src 'none'", `connect-src ${options.hmrWebSocketUrl}`)
|
|
11476
11480
|
: PRODUCTION_CSP;
|
|
@@ -11580,9 +11584,19 @@ function walk(node, visit) {
|
|
|
11580
11584
|
walk(node.content, visit);
|
|
11581
11585
|
}
|
|
11582
11586
|
|
|
11587
|
+
const HB_SDK_RUNTIME_USE_OFFICIAL_DOMAIN_ENV = 'HB_SDK_RUNTIME_USE_OFFICIAL_DOMAIN';
|
|
11588
|
+
const HB_SDK_RUNTIME_PERMISSION_CONTEXT_ENV = 'HB_SDK_RUNTIME_PERMISSION_CONTEXT';
|
|
11589
|
+
const VERIFIED_RUNTIME_PERMISSION_CONTEXT = 'verified';
|
|
11590
|
+
new node_async_hooks.AsyncLocalStorage();
|
|
11591
|
+
Promise.resolve();
|
|
11592
|
+
function shouldSkipMiniappPlatformCspFromEnv(env = process.env) {
|
|
11593
|
+
return env[HB_SDK_RUNTIME_PERMISSION_CONTEXT_ENV] === VERIFIED_RUNTIME_PERMISSION_CONTEXT && env[HB_SDK_RUNTIME_USE_OFFICIAL_DOMAIN_ENV] === '1';
|
|
11594
|
+
}
|
|
11595
|
+
|
|
11583
11596
|
const sdkVersionPlaceholder = ['__HB_SDK', 'VERSION__'].join('_');
|
|
11584
11597
|
const sdkVersionBuildConstant = ['__HB_SDK_BUILD', 'VERSION__'].join('_');
|
|
11585
11598
|
function miniappManifest() {
|
|
11599
|
+
const skipPlatformCsp = shouldSkipMiniappPlatformCspFromEnv();
|
|
11586
11600
|
let root = process.cwd();
|
|
11587
11601
|
let outDir = 'dist';
|
|
11588
11602
|
let command = 'build';
|
|
@@ -11612,7 +11626,10 @@ function miniappManifest() {
|
|
|
11612
11626
|
}
|
|
11613
11627
|
},
|
|
11614
11628
|
transformIndexHtml(html) {
|
|
11615
|
-
return enforceMiniappHtmlPolicy(html,
|
|
11629
|
+
return enforceMiniappHtmlPolicy(html, {
|
|
11630
|
+
...(command === 'serve' ? { hmrWebSocketUrl } : {}),
|
|
11631
|
+
skipPlatformCsp,
|
|
11632
|
+
});
|
|
11616
11633
|
},
|
|
11617
11634
|
async closeBundle() {
|
|
11618
11635
|
// Rollup 在 buildStart/transform 失败后仍会调用 closeBundle。
|
|
@@ -11634,7 +11651,7 @@ function miniappManifest() {
|
|
|
11634
11651
|
if (!htmlFiles.includes(indexHtmlPath)) {
|
|
11635
11652
|
throw new Error('构建产物必须包含入口 dist/index.html');
|
|
11636
11653
|
}
|
|
11637
|
-
node_fs.writeFileSync(indexHtmlPath, enforceMiniappHtmlPolicy(node_fs.readFileSync(indexHtmlPath, 'utf8')));
|
|
11654
|
+
node_fs.writeFileSync(indexHtmlPath, enforceMiniappHtmlPolicy(node_fs.readFileSync(indexHtmlPath, 'utf8'), { skipPlatformCsp }));
|
|
11638
11655
|
const manifestPath = path.join(outputRoot, 'manifest.json');
|
|
11639
11656
|
node_fs.mkdirSync(path.dirname(manifestPath), { recursive: true });
|
|
11640
11657
|
node_fs.writeFileSync(manifestPath, renderMiniappManifest({ version, sdkVersion }));
|
package/dist/vite.esm.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { readFileSync, existsSync, writeFileSync, mkdirSync, readdirSync } from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
3
4
|
|
|
4
5
|
/** 构建时替换为当前发布包的实际版本。 */
|
|
5
6
|
const HB_SDK_VERSION = typeof undefined === 'string'
|
|
6
7
|
? undefined
|
|
7
|
-
: '0.6.6-alpha.
|
|
8
|
+
: '0.6.6-alpha.4';
|
|
8
9
|
|
|
9
10
|
var re = {exports: {}};
|
|
10
11
|
|
|
@@ -11468,6 +11469,9 @@ function enforceMiniappHtmlPolicy(html, options = {}) {
|
|
|
11468
11469
|
removePlatformCspMarkers(document);
|
|
11469
11470
|
walk(document, element => validateElement(element));
|
|
11470
11471
|
injectMiniappRuntimeGate(document);
|
|
11472
|
+
if (options.skipPlatformCsp) {
|
|
11473
|
+
return serialize(document);
|
|
11474
|
+
}
|
|
11471
11475
|
const content = options.hmrWebSocketUrl
|
|
11472
11476
|
? PRODUCTION_CSP.replace("connect-src 'none'", `connect-src ${options.hmrWebSocketUrl}`)
|
|
11473
11477
|
: PRODUCTION_CSP;
|
|
@@ -11577,9 +11581,19 @@ function walk(node, visit) {
|
|
|
11577
11581
|
walk(node.content, visit);
|
|
11578
11582
|
}
|
|
11579
11583
|
|
|
11584
|
+
const HB_SDK_RUNTIME_USE_OFFICIAL_DOMAIN_ENV = 'HB_SDK_RUNTIME_USE_OFFICIAL_DOMAIN';
|
|
11585
|
+
const HB_SDK_RUNTIME_PERMISSION_CONTEXT_ENV = 'HB_SDK_RUNTIME_PERMISSION_CONTEXT';
|
|
11586
|
+
const VERIFIED_RUNTIME_PERMISSION_CONTEXT = 'verified';
|
|
11587
|
+
new AsyncLocalStorage();
|
|
11588
|
+
Promise.resolve();
|
|
11589
|
+
function shouldSkipMiniappPlatformCspFromEnv(env = process.env) {
|
|
11590
|
+
return env[HB_SDK_RUNTIME_PERMISSION_CONTEXT_ENV] === VERIFIED_RUNTIME_PERMISSION_CONTEXT && env[HB_SDK_RUNTIME_USE_OFFICIAL_DOMAIN_ENV] === '1';
|
|
11591
|
+
}
|
|
11592
|
+
|
|
11580
11593
|
const sdkVersionPlaceholder = ['__HB_SDK', 'VERSION__'].join('_');
|
|
11581
11594
|
const sdkVersionBuildConstant = ['__HB_SDK_BUILD', 'VERSION__'].join('_');
|
|
11582
11595
|
function miniappManifest() {
|
|
11596
|
+
const skipPlatformCsp = shouldSkipMiniappPlatformCspFromEnv();
|
|
11583
11597
|
let root = process.cwd();
|
|
11584
11598
|
let outDir = 'dist';
|
|
11585
11599
|
let command = 'build';
|
|
@@ -11609,7 +11623,10 @@ function miniappManifest() {
|
|
|
11609
11623
|
}
|
|
11610
11624
|
},
|
|
11611
11625
|
transformIndexHtml(html) {
|
|
11612
|
-
return enforceMiniappHtmlPolicy(html,
|
|
11626
|
+
return enforceMiniappHtmlPolicy(html, {
|
|
11627
|
+
...(command === 'serve' ? { hmrWebSocketUrl } : {}),
|
|
11628
|
+
skipPlatformCsp,
|
|
11629
|
+
});
|
|
11613
11630
|
},
|
|
11614
11631
|
async closeBundle() {
|
|
11615
11632
|
// Rollup 在 buildStart/transform 失败后仍会调用 closeBundle。
|
|
@@ -11631,7 +11648,7 @@ function miniappManifest() {
|
|
|
11631
11648
|
if (!htmlFiles.includes(indexHtmlPath)) {
|
|
11632
11649
|
throw new Error('构建产物必须包含入口 dist/index.html');
|
|
11633
11650
|
}
|
|
11634
|
-
writeFileSync(indexHtmlPath, enforceMiniappHtmlPolicy(readFileSync(indexHtmlPath, 'utf8')));
|
|
11651
|
+
writeFileSync(indexHtmlPath, enforceMiniappHtmlPolicy(readFileSync(indexHtmlPath, 'utf8'), { skipPlatformCsp }));
|
|
11635
11652
|
const manifestPath = path.join(outputRoot, 'manifest.json');
|
|
11636
11653
|
mkdirSync(path.dirname(manifestPath), { recursive: true });
|
|
11637
11654
|
writeFileSync(manifestPath, renderMiniappManifest({ version, sdkVersion }));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@heybox/hb-sdk",
|
|
3
|
-
"version": "0.6.6-alpha.
|
|
3
|
+
"version": "0.6.6-alpha.4",
|
|
4
4
|
"sideEffects": [
|
|
5
5
|
"./src/index.ts",
|
|
6
6
|
"./src/core/singleton.ts",
|
|
@@ -93,7 +93,7 @@
|
|
|
93
93
|
"vue": "^2.7.16",
|
|
94
94
|
"vite": "^8.0.12",
|
|
95
95
|
"vitest": "^3.2.4",
|
|
96
|
-
"@heybox/hb-api": "~1.25.
|
|
96
|
+
"@heybox/hb-api": "~1.25.6"
|
|
97
97
|
},
|
|
98
98
|
"publishConfig": {
|
|
99
99
|
"registry": "https://registry.npmjs.org/",
|