@heybox/hb-sdk 0.8.0-alpha → 0.8.0-alpha.12
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 +106 -395
- package/README.md +107 -24
- package/THIRD_PARTY_NOTICES.md +1755 -0
- package/dist/cli-chunks/{build-DJWFSM1B.cjs → build-DNtjBmyy.cjs} +8 -5
- package/dist/cli-chunks/{context-DV2UK1Nz.cjs → context-CO_3KgM_.cjs} +39 -81
- package/dist/cli-chunks/{create-2HfoB48V.cjs → create-DG8JxrPU.cjs} +2 -2
- package/dist/cli-chunks/{dev-Dgt2zS9k.cjs → dev-C5U1Lo4e.cjs} +404 -577
- package/dist/cli-chunks/doctor-B50OXvrj.cjs +65 -0
- package/dist/cli-chunks/{index-D62ANeBv.cjs → index-B4nFqf-3.cjs} +50 -30
- package/dist/cli-chunks/{index-BjoSXl8C.cjs → index-B8FK1ojC.cjs} +2 -2
- package/dist/cli-chunks/{index.esm-CigcxJ2B.cjs → index.esm-DiX5WKSp.cjs} +8 -7
- package/dist/cli-chunks/{login-Cumknwdx.cjs → login-CBwmxsEK.cjs} +2 -2
- package/dist/cli-chunks/{project-vite-CcE-HMmd.cjs → project-vite-DWpmHOsV.cjs} +1 -1
- package/dist/cli-chunks/{remote-DDdP3xcE.cjs → remote-Dt-U4gDD.cjs} +57 -25
- package/dist/cli-chunks/{runtime-gate-DFjw66kF.cjs → runtime-gate-CMnGCdfq.cjs} +11 -3
- package/dist/cli-chunks/{runtime-permission-env-CjsCe5bp.cjs → runtime-permission-env-BcUsO3nG.cjs} +351 -0
- package/dist/cli-chunks/{session-BDi_AZSv.cjs → session-yy543BIB.cjs} +1 -1
- package/dist/cli-chunks/skill-B4SWt2o6.cjs +83 -0
- package/dist/cli-chunks/version-CmizPu7D.cjs +8 -0
- package/dist/cli.cjs +1 -1
- package/dist/devtools/browser-dev-host/assets/browser-dev-host-TzYf9L6C.js +99 -0
- package/dist/devtools/browser-dev-host/assets/heybox-logo-CogNENsk.svg +6 -0
- package/dist/devtools/browser-dev-host/assets/index-C5MZZDa5.js +567 -0
- package/dist/devtools/browser-dev-host/assets/index-P-ra4m1y.css +1 -0
- package/dist/devtools/browser-dev-host/assets/workbench-state-BwV7bm4n.js +5 -0
- package/dist/devtools/browser-dev-host/index.html +6 -435
- package/dist/index.cjs.js +1023 -29
- package/dist/index.esm.js +1023 -30
- 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 +281 -13
- package/dist/vite.esm.js +281 -13
- package/package.json +34 -11
- package/skill/SKILL.md +22 -20
- package/skill/references/api-protocol.md +100 -6
- package/skill/references/api-root.md +199 -28
- package/skill/references/cli.md +41 -24
- package/skill/references/examples.md +30 -1
- package/skill/references/llms-index.md +1 -1
- package/skill/references/recipes.md +139 -36
- package/skill/references/safety-boundaries.md +20 -5
- package/skill/skill.json +10 -5
- package/types/core/client.d.ts +17 -1
- package/types/core/mini-dev-console.d.ts +36 -0
- package/types/core/sdk.d.ts +3 -0
- package/types/core/singleton.d.ts +3 -0
- 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 +5 -0
- 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/network/index.d.ts +50 -3
- package/types/modules/share/index.d.ts +1 -1
- package/types/modules/share/show-share-menu.d.ts +1 -1
- package/types/modules/share/types.d.ts +2 -4
- package/types/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 +3 -1
- package/dist/cli-chunks/doctor-C95gIao_.cjs +0 -204
- package/dist/devtools/browser-dev-host/main.js +0 -12263
- package/dist/templates/vue3-vite-ts/README.md.ejs +0 -47
- package/dist/templates/vue3-vite-ts/index.html.ejs +0 -12
- package/dist/templates/vue3-vite-ts/package.json.ejs +0 -33
- package/dist/templates/vue3-vite-ts/src/App.vue +0 -78
- package/dist/templates/vue3-vite-ts/src/__tests__/App.spec.ts +0 -148
- package/dist/templates/vue3-vite-ts/src/auth-handoff.ts +0 -46
- package/dist/templates/vue3-vite-ts/src/main.ts +0 -5
- package/dist/templates/vue3-vite-ts/src/styles.css +0 -60
- package/dist/templates/vue3-vite-ts/src/vite-env.d.ts +0 -1
- package/dist/templates/vue3-vite-ts/tsconfig.app.json +0 -17
- package/dist/templates/vue3-vite-ts/tsconfig.json +0 -11
- package/dist/templates/vue3-vite-ts/tsconfig.node.json +0 -11
- package/dist/templates/vue3-vite-ts/vitest.config.ts +0 -10
- package/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 -794
- package/skill/scripts/validate-skill.mjs +0 -263
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
var fs$1 = require('node:fs');
|
|
4
4
|
var fs = require('node:fs/promises');
|
|
5
5
|
var path = require('node:path');
|
|
6
|
-
var runtimePermissionEnv = require('./runtime-permission-env-
|
|
7
|
-
var runtimeGate = require('./runtime-gate-
|
|
8
|
-
var index = require('./index-
|
|
9
|
-
var projectVite = require('./project-vite-
|
|
6
|
+
var runtimePermissionEnv = require('./runtime-permission-env-BcUsO3nG.cjs');
|
|
7
|
+
var runtimeGate = require('./runtime-gate-CMnGCdfq.cjs');
|
|
8
|
+
var index = require('./index-B4nFqf-3.cjs');
|
|
9
|
+
var projectVite = require('./project-vite-DWpmHOsV.cjs');
|
|
10
|
+
require('./version-CmizPu7D.cjs');
|
|
10
11
|
require('node:async_hooks');
|
|
11
12
|
require('node:module');
|
|
12
13
|
require('path');
|
|
@@ -27,6 +28,7 @@ async function runBuildCommand(_options = {}, runtime = {}) {
|
|
|
27
28
|
const env = runtime.env ?? process.env;
|
|
28
29
|
const mode = env.HB_SDK_ENV?.trim() || undefined;
|
|
29
30
|
const skipPlatformCsp = runtimePermissionEnv.shouldSkipMiniappPlatformCspFromEnv(env);
|
|
31
|
+
runtimePermissionEnv.readMiniappPermissionsFromPackageJson(projectRoot, runtimePermissionEnv.resolveMiniappSdkVersion());
|
|
30
32
|
await fs.rm(distDir, { force: true, recursive: true });
|
|
31
33
|
try {
|
|
32
34
|
return await runtimePermissionEnv.withMiniappPlatformCspEnv(skipPlatformCsp, async () => {
|
|
@@ -91,7 +93,7 @@ async function validateBuildOutput(projectRoot, logger) {
|
|
|
91
93
|
if (hadBom) {
|
|
92
94
|
logger.warn('dist/manifest.json 包含 BOM,已自动剥离');
|
|
93
95
|
}
|
|
94
|
-
const { platforms, sdkVersion, version } = runtimeGate.validateMiniappManifestForDeploy(manifest);
|
|
96
|
+
const { platforms, sdkVersion, version, permissions } = runtimeGate.validateMiniappManifestForDeploy(manifest);
|
|
95
97
|
const allFiles = await walkDistFiles(distDir);
|
|
96
98
|
const uploadFiles = allFiles.filter((file) => runtimePermissionEnv.shouldUploadDistFile(file.relativePath));
|
|
97
99
|
const sizeError = runtimePermissionEnv.validateUploadTotalSize(uploadFiles);
|
|
@@ -103,6 +105,7 @@ async function validateBuildOutput(projectRoot, logger) {
|
|
|
103
105
|
fileCount: uploadFiles.length,
|
|
104
106
|
sdkVersion,
|
|
105
107
|
platforms,
|
|
108
|
+
...(permissions === undefined ? {} : { permissions }),
|
|
106
109
|
totalBytes: uploadFiles.reduce((total, file) => total + file.size, 0),
|
|
107
110
|
version,
|
|
108
111
|
};
|
|
@@ -1,70 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var runtimePermissionEnv = require('./runtime-permission-env-BcUsO3nG.cjs');
|
|
4
|
+
var session = require('./session-yy543BIB.cjs');
|
|
5
5
|
var fs$1 = require('node:fs');
|
|
6
6
|
var fs = require('node:fs/promises');
|
|
7
7
|
var path = require('node:path');
|
|
8
8
|
|
|
9
|
-
const MANAGED_RUNTIME_PERMISSION_KEYS = new Set(['network.request']);
|
|
10
|
-
function isManagedMiniProgramRuntimePermissionKey(key) {
|
|
11
|
-
return MANAGED_RUNTIME_PERMISSION_KEYS.has(key);
|
|
12
|
-
}
|
|
13
|
-
function parseMiniProgramRuntimePermissions(snapshot) {
|
|
14
|
-
if (!isRecord(snapshot) || snapshot.schema_version !== 1 || !Array.isArray(snapshot.entries)) {
|
|
15
|
-
return { valid: false, permissions: {} };
|
|
16
|
-
}
|
|
17
|
-
if (snapshot.revision !== undefined && (typeof snapshot.revision !== 'number' || !Number.isInteger(snapshot.revision) || snapshot.revision < 0)) {
|
|
18
|
-
return { valid: false, permissions: {} };
|
|
19
|
-
}
|
|
20
|
-
const seenKeys = new Set();
|
|
21
|
-
const permissions = {};
|
|
22
|
-
for (const rawEntry of snapshot.entries) {
|
|
23
|
-
if (!isRecord(rawEntry) || typeof rawEntry.key !== 'string' || !rawEntry.key.trim()) {
|
|
24
|
-
return { valid: false, permissions: {} };
|
|
25
|
-
}
|
|
26
|
-
const key = rawEntry.key.trim();
|
|
27
|
-
if (seenKeys.has(key) || (rawEntry.status !== 'enabled' && rawEntry.status !== 'disabled') || !isRecord(rawEntry.config)) {
|
|
28
|
-
return { valid: false, permissions: {} };
|
|
29
|
-
}
|
|
30
|
-
seenKeys.add(key);
|
|
31
|
-
if (!isManagedMiniProgramRuntimePermissionKey(key))
|
|
32
|
-
continue;
|
|
33
|
-
if (key === 'network.request' && typeof rawEntry.config.useOfficialDomain !== 'boolean') {
|
|
34
|
-
return { valid: false, permissions: {} };
|
|
35
|
-
}
|
|
36
|
-
permissions[key] = {
|
|
37
|
-
key,
|
|
38
|
-
status: rawEntry.status,
|
|
39
|
-
config: { useOfficialDomain: rawEntry.config.useOfficialDomain },
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
return { valid: true, permissions };
|
|
43
|
-
}
|
|
44
|
-
function isRecord(value) {
|
|
45
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function parseBrowserDevPermissionState(value) {
|
|
49
|
-
if (!isPlainRecord(value) || !hasExactKeys(value, ['networkRequest']))
|
|
50
|
-
return undefined;
|
|
51
|
-
const networkRequest = value.networkRequest;
|
|
52
|
-
if (!isPlainRecord(networkRequest) || !hasExactKeys(networkRequest, ['status', 'useOfficialDomain']))
|
|
53
|
-
return undefined;
|
|
54
|
-
if (networkRequest.status !== 'enabled' && networkRequest.status !== 'disabled')
|
|
55
|
-
return undefined;
|
|
56
|
-
if (typeof networkRequest.useOfficialDomain !== 'boolean')
|
|
57
|
-
return undefined;
|
|
58
|
-
return {
|
|
59
|
-
networkRequest: {
|
|
60
|
-
status: networkRequest.status,
|
|
61
|
-
useOfficialDomain: networkRequest.useOfficialDomain,
|
|
62
|
-
},
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
9
|
function shouldSkipMiniappPlatformCsp(runtimePermissions) {
|
|
66
|
-
const parsed = parseMiniProgramRuntimePermissions(runtimePermissions);
|
|
67
|
-
const networkRequest = parsed.permissions
|
|
10
|
+
const parsed = runtimePermissionEnv.parseMiniProgramRuntimePermissions(runtimePermissions);
|
|
11
|
+
const networkRequest = parsed.permissions.network;
|
|
68
12
|
return parsed.valid && networkRequest?.status === 'enabled';
|
|
69
13
|
}
|
|
70
14
|
const DEFAULT_PERMISSION_STATE = {
|
|
@@ -74,8 +18,8 @@ const DEFAULT_PERMISSION_STATE = {
|
|
|
74
18
|
},
|
|
75
19
|
};
|
|
76
20
|
function createBrowserDevPermissionState(context) {
|
|
77
|
-
const parsed = parseMiniProgramRuntimePermissions(context.runtimePermissions);
|
|
78
|
-
const networkRequest = parsed.permissions
|
|
21
|
+
const parsed = runtimePermissionEnv.parseMiniProgramRuntimePermissions(context.runtimePermissions);
|
|
22
|
+
const networkRequest = parsed.permissions.network;
|
|
79
23
|
return parsed.valid && networkRequest
|
|
80
24
|
? {
|
|
81
25
|
networkRequest: {
|
|
@@ -85,32 +29,48 @@ function createBrowserDevPermissionState(context) {
|
|
|
85
29
|
}
|
|
86
30
|
: cloneDefaultPermissionState();
|
|
87
31
|
}
|
|
88
|
-
function createBrowserDevRuntimePermissions(state) {
|
|
89
|
-
return
|
|
90
|
-
schema_version: 1,
|
|
91
|
-
entries: [
|
|
92
|
-
{
|
|
93
|
-
key: 'network.request',
|
|
94
|
-
status: state.networkRequest.status,
|
|
95
|
-
config: {
|
|
96
|
-
useOfficialDomain: state.networkRequest.useOfficialDomain,
|
|
97
|
-
},
|
|
98
|
-
},
|
|
99
|
-
],
|
|
100
|
-
};
|
|
32
|
+
function createBrowserDevRuntimePermissions(snapshot, state) {
|
|
33
|
+
return createDevRuntimePermissions(snapshot, state, state.networkRequest.useOfficialDomain);
|
|
101
34
|
}
|
|
102
35
|
function cloneDefaultPermissionState() {
|
|
103
36
|
return {
|
|
104
37
|
networkRequest: { ...DEFAULT_PERMISSION_STATE.networkRequest },
|
|
105
38
|
};
|
|
106
39
|
}
|
|
40
|
+
function createDevRuntimePermissions(snapshot, state, useOfficialDomain) {
|
|
41
|
+
const parsed = runtimePermissionEnv.parseMiniProgramRuntimePermissions(snapshot);
|
|
42
|
+
if (!parsed.valid) {
|
|
43
|
+
return { schema_version: 1, entries: [] };
|
|
44
|
+
}
|
|
45
|
+
const entries = [];
|
|
46
|
+
for (const key of runtimePermissionEnv.MINI_PROGRAM_PERMISSION_KEYS) {
|
|
47
|
+
const entry = parsed.permissions[key];
|
|
48
|
+
if (!entry)
|
|
49
|
+
continue;
|
|
50
|
+
entries.push(key === 'network'
|
|
51
|
+
? {
|
|
52
|
+
key,
|
|
53
|
+
status: state.networkRequest.status,
|
|
54
|
+
config: { useOfficialDomain },
|
|
55
|
+
}
|
|
56
|
+
: {
|
|
57
|
+
key,
|
|
58
|
+
status: entry.status,
|
|
59
|
+
config: {},
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
const revision = isPlainRecord(snapshot) && typeof snapshot.revision === 'number' && Number.isInteger(snapshot.revision) && snapshot.revision >= 0
|
|
63
|
+
? snapshot.revision
|
|
64
|
+
: undefined;
|
|
65
|
+
return {
|
|
66
|
+
schema_version: 1,
|
|
67
|
+
...(revision === undefined ? {} : { revision }),
|
|
68
|
+
entries,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
107
71
|
function isPlainRecord(value) {
|
|
108
72
|
return typeof value === 'object' && value !== null && !Array.isArray(value) && Object.getPrototypeOf(value) === Object.prototype;
|
|
109
73
|
}
|
|
110
|
-
function hasExactKeys(value, keys) {
|
|
111
|
-
const actualKeys = Object.keys(value);
|
|
112
|
-
return actualKeys.length === keys.length && keys.every((key) => Object.hasOwn(value, key));
|
|
113
|
-
}
|
|
114
74
|
|
|
115
75
|
function createRemoteApiClient(options) {
|
|
116
76
|
return {
|
|
@@ -425,8 +385,6 @@ exports.createBrowserDevRuntimePermissions = createBrowserDevRuntimePermissions;
|
|
|
425
385
|
exports.createLocalDevLaunchToken = createLocalDevLaunchToken;
|
|
426
386
|
exports.createRemoteApiClientForEnvironment = createRemoteApiClientForEnvironment;
|
|
427
387
|
exports.getBoundMiniProgram = getBoundMiniProgram;
|
|
428
|
-
exports.parseBrowserDevPermissionState = parseBrowserDevPermissionState;
|
|
429
|
-
exports.parseMiniProgramRuntimePermissions = parseMiniProgramRuntimePermissions;
|
|
430
388
|
exports.readBoundMiniProgramId = readBoundMiniProgramId;
|
|
431
389
|
exports.readBoundMiniProgramIdFromPackageJson = readBoundMiniProgramIdFromPackageJson;
|
|
432
390
|
exports.readMiniProgramProjectPackage = readMiniProgramProjectPackage;
|
|
@@ -5,7 +5,7 @@ var fs = require('node:fs/promises');
|
|
|
5
5
|
var path = require('node:path');
|
|
6
6
|
var require$$0 = require('fs');
|
|
7
7
|
var require$$1 = require('path');
|
|
8
|
-
var index = require('./index-
|
|
8
|
+
var index = require('./index-B4nFqf-3.cjs');
|
|
9
9
|
require('node:module');
|
|
10
10
|
require('os');
|
|
11
11
|
require('readline');
|
|
@@ -1238,7 +1238,7 @@ function requireEjs () {
|
|
|
1238
1238
|
|
|
1239
1239
|
var ejsExports = requireEjs();
|
|
1240
1240
|
|
|
1241
|
-
const TEMPLATE_NAME = '
|
|
1241
|
+
const TEMPLATE_NAME = 'vanilla-vite-js';
|
|
1242
1242
|
const TEMPLATE_ROOT_CANDIDATES = [
|
|
1243
1243
|
path.resolve(__dirname, 'templates', TEMPLATE_NAME),
|
|
1244
1244
|
path.resolve(__dirname, '..', 'templates', TEMPLATE_NAME),
|