@heybox/hb-sdk 0.2.0-alpha.2 → 0.3.2
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 +7 -6
- package/dist/cli.cjs +1119 -722
- package/dist/devtools/mock-host/index.html +78 -1
- package/dist/devtools/mock-host/main.js +378 -204
- package/dist/index.cjs.js +2 -14
- package/dist/index.esm.js +3 -2
- package/dist/miniapp-publish.cjs.js +6 -5
- package/dist/miniapp-publish.esm.js +6 -5
- package/dist/templates/vue3-vite-ts/README.md.ejs +3 -1
- package/dist/templates/vue3-vite-ts/package.json.ejs +5 -0
- package/dist/vite.cjs.js +54 -30
- package/dist/vite.esm.js +55 -31
- package/package.json +3 -4
- package/skill/SKILL.md +1 -1
- package/skill/references/api-root.md +16 -89
- package/skill/references/cli.md +6 -4
- package/skill/scripts/skill-metadata.mjs +4 -1
- package/skill/scripts/sync-references.mjs +1 -1
- package/skill/skill.json +4 -4
- package/types/core/client.d.ts +7 -16
- package/types/index.d.ts +2 -6
- package/types/miniapp-manifest/index.d.ts +2 -0
- package/types/miniapp-manifest/node.d.ts +1 -0
- package/types/miniapp-manifest/schema.d.ts +14 -0
- package/types/miniapp-publish/index.d.ts +1 -1
- package/types/skill-metadata.d.ts +6 -0
package/dist/index.cjs.js
CHANGED
|
@@ -240,8 +240,9 @@ class MiniProgramBridgeClient {
|
|
|
240
240
|
this.eventBus.off(eventName, handler);
|
|
241
241
|
}
|
|
242
242
|
/** 调用父容器开放能力。 */
|
|
243
|
-
async request(method,
|
|
243
|
+
async request(method, ...args) {
|
|
244
244
|
await this.ready();
|
|
245
|
+
const payload = args[0];
|
|
245
246
|
const id = createMessageId();
|
|
246
247
|
const message = {
|
|
247
248
|
namespace: MINI_PROGRAM_MESSAGE_NAMESPACE,
|
|
@@ -888,25 +889,12 @@ const hbSDK = {
|
|
|
888
889
|
network,
|
|
889
890
|
};
|
|
890
891
|
|
|
891
|
-
exports.AUTH_LOGIN_METHOD = AUTH_LOGIN_METHOD;
|
|
892
892
|
exports.HbMiniProgramNetworkError = HbMiniProgramNetworkError;
|
|
893
893
|
exports.HbMiniProgramSDKError = HbMiniProgramSDKError;
|
|
894
|
-
exports.MINI_PROGRAM_BRIDGE_NONCE_PARAM = MINI_PROGRAM_BRIDGE_NONCE_PARAM;
|
|
895
|
-
exports.MINI_PROGRAM_MESSAGE_NAMESPACE = MINI_PROGRAM_MESSAGE_NAMESPACE;
|
|
896
|
-
exports.MINI_PROGRAM_MESSAGE_VERSION = MINI_PROGRAM_MESSAGE_VERSION;
|
|
897
894
|
exports.MiniProgramSDK = MiniProgramSDK;
|
|
898
|
-
exports.NETWORK_REQUEST_METHOD = NETWORK_REQUEST_METHOD;
|
|
899
|
-
exports.SDK_HANDSHAKE_METHOD = SDK_HANDSHAKE_METHOD;
|
|
900
|
-
exports.SHARE_SCREENSHOT_METHOD = SHARE_SCREENSHOT_METHOD;
|
|
901
|
-
exports.SHARE_SHOW_SHARE_MENU_METHOD = SHARE_SHOW_SHARE_MENU_METHOD;
|
|
902
|
-
exports.STORAGE_GET_STORAGE_METHOD = STORAGE_GET_STORAGE_METHOD;
|
|
903
|
-
exports.STORAGE_SET_STORAGE_METHOD = STORAGE_SET_STORAGE_METHOD;
|
|
904
|
-
exports.USER_GET_INFO_METHOD = USER_GET_INFO_METHOD;
|
|
905
|
-
exports.VIEWPORT_GET_WINDOW_INFO_METHOD = VIEWPORT_GET_WINDOW_INFO_METHOD;
|
|
906
895
|
exports.auth = auth;
|
|
907
896
|
exports.createMiniProgramSDK = createMiniProgramSDK;
|
|
908
897
|
exports.default = hbSDK;
|
|
909
|
-
exports.isMiniProgramBridgeMessage = isMiniProgramBridgeMessage;
|
|
910
898
|
exports.network = network;
|
|
911
899
|
exports.off = off;
|
|
912
900
|
exports.on = on;
|
package/dist/index.esm.js
CHANGED
|
@@ -236,8 +236,9 @@ class MiniProgramBridgeClient {
|
|
|
236
236
|
this.eventBus.off(eventName, handler);
|
|
237
237
|
}
|
|
238
238
|
/** 调用父容器开放能力。 */
|
|
239
|
-
async request(method,
|
|
239
|
+
async request(method, ...args) {
|
|
240
240
|
await this.ready();
|
|
241
|
+
const payload = args[0];
|
|
241
242
|
const id = createMessageId();
|
|
242
243
|
const message = {
|
|
243
244
|
namespace: MINI_PROGRAM_MESSAGE_NAMESPACE,
|
|
@@ -884,4 +885,4 @@ const hbSDK = {
|
|
|
884
885
|
network,
|
|
885
886
|
};
|
|
886
887
|
|
|
887
|
-
export {
|
|
888
|
+
export { HbMiniProgramNetworkError, HbMiniProgramSDKError, MiniProgramSDK, auth, createMiniProgramSDK, hbSDK as default, network, off, on, ready, share, storage, user, viewport };
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const PUBLISH_VERSION_RE = /^\d+\.\d+\.\d+$/;
|
|
4
|
+
function isValidMiniappManifestVersion(version) {
|
|
5
|
+
return PUBLISH_VERSION_RE.test(String(version || '').trim());
|
|
6
|
+
}
|
|
7
|
+
|
|
3
8
|
const MINIAPP_UPLOAD_SCOPE = 'activity';
|
|
4
9
|
const ACTIVITY_UPLOAD_KEY_MAX_LENGTH = 64;
|
|
5
10
|
const PUBLISH_USER_MINIPROGRAM_API_PATH = '/mall/developer/user_miniprogram/publish';
|
|
6
|
-
const VERSION_PATTERN = /^\d+\.\d+\.\d+$/;
|
|
7
11
|
const FNV_OFFSET = 0x811c9dc5;
|
|
8
12
|
const FNV_PRIME = 0x01000193;
|
|
9
|
-
function isValidVersion(version) {
|
|
10
|
-
return VERSION_PATTERN.test(String(version || '').trim());
|
|
11
|
-
}
|
|
12
13
|
function normalizeRelativePath(relativePath) {
|
|
13
14
|
return String(relativePath || '')
|
|
14
15
|
.replace(/\\/g, '/')
|
|
@@ -70,7 +71,7 @@ exports.MINIAPP_UPLOAD_SCOPE = MINIAPP_UPLOAD_SCOPE;
|
|
|
70
71
|
exports.PUBLISH_USER_MINIPROGRAM_API_PATH = PUBLISH_USER_MINIPROGRAM_API_PATH;
|
|
71
72
|
exports.getMiniProgramUploadAlias = getMiniProgramUploadAlias;
|
|
72
73
|
exports.getMiniappUploadKey = getMiniappUploadKey;
|
|
73
|
-
exports.isValidVersion =
|
|
74
|
+
exports.isValidVersion = isValidMiniappManifestVersion;
|
|
74
75
|
exports.normalizeRelativePath = normalizeRelativePath;
|
|
75
76
|
exports.relativePathContainsNodeModulesSegment = relativePathContainsNodeModulesSegment;
|
|
76
77
|
exports.shouldUploadDistFile = shouldUploadDistFile;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
const PUBLISH_VERSION_RE = /^\d+\.\d+\.\d+$/;
|
|
2
|
+
function isValidMiniappManifestVersion(version) {
|
|
3
|
+
return PUBLISH_VERSION_RE.test(String(version || '').trim());
|
|
4
|
+
}
|
|
5
|
+
|
|
1
6
|
const MINIAPP_UPLOAD_SCOPE = 'activity';
|
|
2
7
|
const ACTIVITY_UPLOAD_KEY_MAX_LENGTH = 64;
|
|
3
8
|
const PUBLISH_USER_MINIPROGRAM_API_PATH = '/mall/developer/user_miniprogram/publish';
|
|
4
|
-
const VERSION_PATTERN = /^\d+\.\d+\.\d+$/;
|
|
5
9
|
const FNV_OFFSET = 0x811c9dc5;
|
|
6
10
|
const FNV_PRIME = 0x01000193;
|
|
7
|
-
function isValidVersion(version) {
|
|
8
|
-
return VERSION_PATTERN.test(String(version || '').trim());
|
|
9
|
-
}
|
|
10
11
|
function normalizeRelativePath(relativePath) {
|
|
11
12
|
return String(relativePath || '')
|
|
12
13
|
.replace(/\\/g, '/')
|
|
@@ -63,4 +64,4 @@ function shouldUploadDistFile(relativePath) {
|
|
|
63
64
|
return true;
|
|
64
65
|
}
|
|
65
66
|
|
|
66
|
-
export { ACTIVITY_UPLOAD_KEY_MAX_LENGTH, MINIAPP_UPLOAD_SCOPE, PUBLISH_USER_MINIPROGRAM_API_PATH, getMiniProgramUploadAlias, getMiniappUploadKey, isValidVersion, normalizeRelativePath, relativePathContainsNodeModulesSegment, shouldUploadDistFile, validateUploadPaths };
|
|
67
|
+
export { ACTIVITY_UPLOAD_KEY_MAX_LENGTH, MINIAPP_UPLOAD_SCOPE, PUBLISH_USER_MINIPROGRAM_API_PATH, getMiniProgramUploadAlias, getMiniappUploadKey, isValidMiniappManifestVersion as isValidVersion, normalizeRelativePath, relativePathContainsNodeModulesSegment, shouldUploadDistFile, validateUploadPaths };
|
|
@@ -10,12 +10,14 @@ npm run dev
|
|
|
10
10
|
npm run typecheck
|
|
11
11
|
npm run test:unit
|
|
12
12
|
npm run build
|
|
13
|
+
npm run deploy
|
|
13
14
|
```
|
|
14
15
|
|
|
15
16
|
## 开发模式
|
|
16
17
|
|
|
17
|
-
- `npm run dev`:启动本地 Vite 服务和 `hb-sdk` 内置 mock runtime host,适合本地调试 SDK 能力;调试页内可点击按钮在 Mac 版 APP 中启动同一页面。
|
|
18
|
+
- `npm run dev`:启动本地 Vite 服务和 `hb-sdk` 内置 mock runtime host,适合本地调试 SDK 能力;调试页内可点击按钮在 Mac 版 APP 中启动同一页面。Codex、VSCode 等内嵌浏览器可能无法唤起系统 APP,需要时请在系统浏览器中打开同一个调试页后重试。
|
|
18
19
|
- `npm run build`:先执行 TypeScript 检查,再构建生产产物。
|
|
20
|
+
- `npm run deploy`:构建并发布当前小程序。发布前需要先把 `package.json` 中的 `heybox.miniProgramId` 改成后台分配的真实小程序 id,并执行过 `npx hb-sdk login`。
|
|
19
21
|
|
|
20
22
|
## 更多能力
|
|
21
23
|
|
|
@@ -3,8 +3,13 @@
|
|
|
3
3
|
"version": "0.0.0",
|
|
4
4
|
"private": true,
|
|
5
5
|
"type": "module",
|
|
6
|
+
"heybox": {
|
|
7
|
+
"miniProgramId": ""
|
|
8
|
+
},
|
|
6
9
|
"scripts": {
|
|
10
|
+
"hb-sdk": "hb-sdk",
|
|
7
11
|
"dev": "hb-sdk dev",
|
|
12
|
+
"deploy": "hb-sdk deploy",
|
|
8
13
|
"build": "vue-tsc --noEmit && vite build",
|
|
9
14
|
"preview": "vite preview",
|
|
10
15
|
"typecheck": "vue-tsc --noEmit",
|
package/dist/vite.cjs.js
CHANGED
|
@@ -3,32 +3,37 @@
|
|
|
3
3
|
var node_fs = require('node:fs');
|
|
4
4
|
var path = require('node:path');
|
|
5
5
|
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
writeBundle() {
|
|
20
|
-
const version = readMiniappVersion(root);
|
|
21
|
-
if (!SEMVER_LIKE_RE.test(version)) {
|
|
22
|
-
this.warn(`package.json.version "${version}" 不是标准 semver,仍会写入 manifest.json`);
|
|
23
|
-
}
|
|
24
|
-
const manifestPath = path.resolve(root, outDir, 'manifest.json');
|
|
25
|
-
node_fs.mkdirSync(path.dirname(manifestPath), { recursive: true });
|
|
26
|
-
node_fs.writeFileSync(manifestPath, `${JSON.stringify({ version }, null, 2)}\n`);
|
|
27
|
-
},
|
|
28
|
-
};
|
|
6
|
+
const MINIAPP_TEMPLATE_VERSION = '0.0.0';
|
|
7
|
+
const BUILD_VERSION_RE = /^\d+\.\d+\.\d+(?:[-+].*)?$/;
|
|
8
|
+
function getMiniappManifestBuildWarning(version) {
|
|
9
|
+
if (version === MINIAPP_TEMPLATE_VERSION) {
|
|
10
|
+
return '@heybox/hb-sdk 提示:package.json.version 仍是模板默认的 0.0.0;manifest 会写入,但发布前必须改成实际 x.y.z 版本';
|
|
11
|
+
}
|
|
12
|
+
if (!BUILD_VERSION_RE.test(version)) {
|
|
13
|
+
return `package.json.version "${version}" 不是标准 semver,仍会写入 manifest.json`;
|
|
14
|
+
}
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
function renderMiniappManifest(manifest) {
|
|
18
|
+
return `${JSON.stringify({ version: manifest.version }, null, 2)}\n`;
|
|
29
19
|
}
|
|
30
|
-
|
|
31
|
-
|
|
20
|
+
|
|
21
|
+
function findNearestPackageJsonPath(startDir) {
|
|
22
|
+
let current = path.resolve(startDir);
|
|
23
|
+
while (true) {
|
|
24
|
+
const packageJsonPath = path.join(current, 'package.json');
|
|
25
|
+
if (node_fs.existsSync(packageJsonPath)) {
|
|
26
|
+
return packageJsonPath;
|
|
27
|
+
}
|
|
28
|
+
const parent = path.dirname(current);
|
|
29
|
+
if (parent === current) {
|
|
30
|
+
return path.join(path.resolve(startDir), 'package.json');
|
|
31
|
+
}
|
|
32
|
+
current = parent;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function readMiniappVersionFromPackageJson(root) {
|
|
36
|
+
const packageJsonPath = findNearestPackageJsonPath(root);
|
|
32
37
|
let content;
|
|
33
38
|
try {
|
|
34
39
|
content = node_fs.readFileSync(packageJsonPath, 'utf8');
|
|
@@ -46,11 +51,7 @@ function readMiniappVersion(root) {
|
|
|
46
51
|
if (typeof packageJson.version !== 'string' || packageJson.version.trim() === '') {
|
|
47
52
|
throw new Error('@heybox/hb-sdk 提示:package.json.version 必须是非空字符串');
|
|
48
53
|
}
|
|
49
|
-
|
|
50
|
-
if (version === TEMPLATE_VERSION) {
|
|
51
|
-
throw new Error(TEMPLATE_VERSION_ERROR);
|
|
52
|
-
}
|
|
53
|
-
return version;
|
|
54
|
+
return packageJson.version.trim();
|
|
54
55
|
}
|
|
55
56
|
function formatReason(error) {
|
|
56
57
|
if (error instanceof Error && error.message) {
|
|
@@ -59,4 +60,27 @@ function formatReason(error) {
|
|
|
59
60
|
return String(error);
|
|
60
61
|
}
|
|
61
62
|
|
|
63
|
+
function miniappManifest() {
|
|
64
|
+
let root = process.cwd();
|
|
65
|
+
let outDir = 'dist';
|
|
66
|
+
return {
|
|
67
|
+
name: 'heybox-miniapp-manifest',
|
|
68
|
+
apply: 'build',
|
|
69
|
+
configResolved(resolved) {
|
|
70
|
+
root = resolved.root;
|
|
71
|
+
outDir = resolved.build.outDir;
|
|
72
|
+
},
|
|
73
|
+
writeBundle() {
|
|
74
|
+
const version = readMiniappVersionFromPackageJson(root);
|
|
75
|
+
const warning = getMiniappManifestBuildWarning(version);
|
|
76
|
+
if (warning) {
|
|
77
|
+
this.warn(warning);
|
|
78
|
+
}
|
|
79
|
+
const manifestPath = path.resolve(root, outDir, 'manifest.json');
|
|
80
|
+
node_fs.mkdirSync(path.dirname(manifestPath), { recursive: true });
|
|
81
|
+
node_fs.writeFileSync(manifestPath, renderMiniappManifest({ version }));
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
62
86
|
exports.miniappManifest = miniappManifest;
|
package/dist/vite.esm.js
CHANGED
|
@@ -1,32 +1,37 @@
|
|
|
1
|
-
import { mkdirSync, writeFileSync
|
|
1
|
+
import { readFileSync, existsSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
writeBundle() {
|
|
18
|
-
const version = readMiniappVersion(root);
|
|
19
|
-
if (!SEMVER_LIKE_RE.test(version)) {
|
|
20
|
-
this.warn(`package.json.version "${version}" 不是标准 semver,仍会写入 manifest.json`);
|
|
21
|
-
}
|
|
22
|
-
const manifestPath = path.resolve(root, outDir, 'manifest.json');
|
|
23
|
-
mkdirSync(path.dirname(manifestPath), { recursive: true });
|
|
24
|
-
writeFileSync(manifestPath, `${JSON.stringify({ version }, null, 2)}\n`);
|
|
25
|
-
},
|
|
26
|
-
};
|
|
4
|
+
const MINIAPP_TEMPLATE_VERSION = '0.0.0';
|
|
5
|
+
const BUILD_VERSION_RE = /^\d+\.\d+\.\d+(?:[-+].*)?$/;
|
|
6
|
+
function getMiniappManifestBuildWarning(version) {
|
|
7
|
+
if (version === MINIAPP_TEMPLATE_VERSION) {
|
|
8
|
+
return '@heybox/hb-sdk 提示:package.json.version 仍是模板默认的 0.0.0;manifest 会写入,但发布前必须改成实际 x.y.z 版本';
|
|
9
|
+
}
|
|
10
|
+
if (!BUILD_VERSION_RE.test(version)) {
|
|
11
|
+
return `package.json.version "${version}" 不是标准 semver,仍会写入 manifest.json`;
|
|
12
|
+
}
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
function renderMiniappManifest(manifest) {
|
|
16
|
+
return `${JSON.stringify({ version: manifest.version }, null, 2)}\n`;
|
|
27
17
|
}
|
|
28
|
-
|
|
29
|
-
|
|
18
|
+
|
|
19
|
+
function findNearestPackageJsonPath(startDir) {
|
|
20
|
+
let current = path.resolve(startDir);
|
|
21
|
+
while (true) {
|
|
22
|
+
const packageJsonPath = path.join(current, 'package.json');
|
|
23
|
+
if (existsSync(packageJsonPath)) {
|
|
24
|
+
return packageJsonPath;
|
|
25
|
+
}
|
|
26
|
+
const parent = path.dirname(current);
|
|
27
|
+
if (parent === current) {
|
|
28
|
+
return path.join(path.resolve(startDir), 'package.json');
|
|
29
|
+
}
|
|
30
|
+
current = parent;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function readMiniappVersionFromPackageJson(root) {
|
|
34
|
+
const packageJsonPath = findNearestPackageJsonPath(root);
|
|
30
35
|
let content;
|
|
31
36
|
try {
|
|
32
37
|
content = readFileSync(packageJsonPath, 'utf8');
|
|
@@ -44,11 +49,7 @@ function readMiniappVersion(root) {
|
|
|
44
49
|
if (typeof packageJson.version !== 'string' || packageJson.version.trim() === '') {
|
|
45
50
|
throw new Error('@heybox/hb-sdk 提示:package.json.version 必须是非空字符串');
|
|
46
51
|
}
|
|
47
|
-
|
|
48
|
-
if (version === TEMPLATE_VERSION) {
|
|
49
|
-
throw new Error(TEMPLATE_VERSION_ERROR);
|
|
50
|
-
}
|
|
51
|
-
return version;
|
|
52
|
+
return packageJson.version.trim();
|
|
52
53
|
}
|
|
53
54
|
function formatReason(error) {
|
|
54
55
|
if (error instanceof Error && error.message) {
|
|
@@ -57,4 +58,27 @@ function formatReason(error) {
|
|
|
57
58
|
return String(error);
|
|
58
59
|
}
|
|
59
60
|
|
|
61
|
+
function miniappManifest() {
|
|
62
|
+
let root = process.cwd();
|
|
63
|
+
let outDir = 'dist';
|
|
64
|
+
return {
|
|
65
|
+
name: 'heybox-miniapp-manifest',
|
|
66
|
+
apply: 'build',
|
|
67
|
+
configResolved(resolved) {
|
|
68
|
+
root = resolved.root;
|
|
69
|
+
outDir = resolved.build.outDir;
|
|
70
|
+
},
|
|
71
|
+
writeBundle() {
|
|
72
|
+
const version = readMiniappVersionFromPackageJson(root);
|
|
73
|
+
const warning = getMiniappManifestBuildWarning(version);
|
|
74
|
+
if (warning) {
|
|
75
|
+
this.warn(warning);
|
|
76
|
+
}
|
|
77
|
+
const manifestPath = path.resolve(root, outDir, 'manifest.json');
|
|
78
|
+
mkdirSync(path.dirname(manifestPath), { recursive: true });
|
|
79
|
+
writeFileSync(manifestPath, renderMiniappManifest({ version }));
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
60
84
|
export { miniappManifest };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@heybox/hb-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -43,9 +43,7 @@
|
|
|
43
43
|
"keywords": [],
|
|
44
44
|
"author": "",
|
|
45
45
|
"license": "ISC",
|
|
46
|
-
"dependencies": {
|
|
47
|
-
"cos-nodejs-sdk-v5": "2.15.4"
|
|
48
|
-
},
|
|
46
|
+
"dependencies": {},
|
|
49
47
|
"peerDependencies": {
|
|
50
48
|
"vite": ">=5"
|
|
51
49
|
},
|
|
@@ -66,6 +64,7 @@
|
|
|
66
64
|
"@types/node": "24.10.1",
|
|
67
65
|
"@vitest/coverage-v8": "^3.2.4",
|
|
68
66
|
"commander": "^12.1.0",
|
|
67
|
+
"cos-nodejs-sdk-v5": "2.15.4",
|
|
69
68
|
"ejs": "^3.1.10",
|
|
70
69
|
"env-paths": "^2.2.1",
|
|
71
70
|
"fs-extra": "^11.3.0",
|
package/skill/SKILL.md
CHANGED
|
@@ -50,7 +50,7 @@ Apply these instructions when writing, reviewing, or debugging code that consume
|
|
|
50
50
|
2. Use `hb-sdk dev` for local browser debugging through the built-in mock runtime host.
|
|
51
51
|
3. Use `hb-sdk deploy` to build and publish the current project. It reads `package.json.heybox.miniProgramId`, runs the project's `build` script via the package manager auto-detected by lockfile, then uploads `dist/` to CDN (skipping `manifest.json`, `.DS_Store`, `.map`) and calls the publish API.
|
|
52
52
|
4. Use `hb-sdk deploy --skip-build` only when the `dist/` directory is already prepared by an upstream CI stage. Missing `dist/manifest.json` or `dist/index.html` aborts the run.
|
|
53
|
-
5. Use the Mock runtime host's "在 Mac 版 APP 中启动" button when the page needs to be loaded by the real Heybox mini-program container.
|
|
53
|
+
5. Use the Mock runtime host's "在 Mac 版 APP 中启动" button when the page needs to be loaded by the real Heybox mini-program container; if the mock host is open inside Codex, VSCode, or another embedded browser, ask the user to open the same debug page in the system browser before retrying because embedded browsers may block the `heybox://` protocol handoff.
|
|
54
54
|
6. Use `--port`, `--mock-port`, `--host`, and `--no-open` when the default Vite/mock ports, host, or browser opening behavior need to be controlled.
|
|
55
55
|
7. Use `hb-sdk login`, `hb-sdk login status`, and `hb-sdk login clear` only for the CLI's own Heybox auth cache.
|
|
56
56
|
8. Use `hb-sdk doctor` to diagnose whether the local `hb-sdk` skill matches the installed SDK and remote latest skill metadata.
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
## Package metadata
|
|
20
20
|
|
|
21
21
|
- Package: `@heybox/hb-sdk`
|
|
22
|
-
- Version at generation time: `0.
|
|
22
|
+
- Version at generation time: `0.3.2`
|
|
23
23
|
- Public root export: `@heybox/hb-sdk`
|
|
24
24
|
- Protocol export: `@heybox/hb-sdk/protocol`
|
|
25
25
|
- Vite plugin export: `@heybox/hb-sdk/vite`
|
|
@@ -29,49 +29,13 @@
|
|
|
29
29
|
```ts
|
|
30
30
|
export { createMiniProgramSDK, MiniProgramSDK } from './core/sdk';
|
|
31
31
|
export { HbMiniProgramSDKError, HbMiniProgramNetworkError } from './core/errors';
|
|
32
|
-
export type {
|
|
32
|
+
export type { MiniProgramSDKOptions } from './core/client';
|
|
33
33
|
export { ready, on, off, auth, user, share, viewport, storage, network } from './core/singleton';
|
|
34
|
-
export {
|
|
35
|
-
MINI_PROGRAM_BRIDGE_NONCE_PARAM,
|
|
36
|
-
MINI_PROGRAM_MESSAGE_NAMESPACE,
|
|
37
|
-
MINI_PROGRAM_MESSAGE_VERSION,
|
|
38
|
-
SDK_HANDSHAKE_METHOD,
|
|
39
|
-
} from './protocol/constants';
|
|
40
|
-
export { isMiniProgramBridgeMessage } from './protocol/guards';
|
|
41
34
|
export type {
|
|
42
|
-
MiniProgramBridgeError,
|
|
43
|
-
MiniProgramBridgeMessage,
|
|
44
|
-
MiniProgramBridgeMessageType,
|
|
45
35
|
MiniProgramEventHandler,
|
|
46
36
|
MiniProgramEventName,
|
|
47
37
|
MiniProgramEventPayloadMap,
|
|
48
38
|
} from './protocol/types';
|
|
49
|
-
export {
|
|
50
|
-
AUTH_LOGIN_METHOD,
|
|
51
|
-
NETWORK_REQUEST_METHOD,
|
|
52
|
-
SHARE_SCREENSHOT_METHOD,
|
|
53
|
-
SHARE_SHOW_SHARE_MENU_METHOD,
|
|
54
|
-
STORAGE_GET_STORAGE_METHOD,
|
|
55
|
-
STORAGE_SET_STORAGE_METHOD,
|
|
56
|
-
USER_GET_INFO_METHOD,
|
|
57
|
-
VIEWPORT_GET_WINDOW_INFO_METHOD,
|
|
58
|
-
} from './protocol/capabilities';
|
|
59
|
-
export type {
|
|
60
|
-
MiniProgramAuthMethod,
|
|
61
|
-
MiniProgramBridgeMethod,
|
|
62
|
-
MiniProgramCapabilityDefinition,
|
|
63
|
-
MiniProgramCapabilityModule,
|
|
64
|
-
MiniProgramCapabilityPayload,
|
|
65
|
-
MiniProgramCapabilityPayloadMap,
|
|
66
|
-
MiniProgramCapabilityResult,
|
|
67
|
-
MiniProgramCapabilityResultMap,
|
|
68
|
-
MiniProgramCapabilityRisk,
|
|
69
|
-
MiniProgramNetworkMethod,
|
|
70
|
-
MiniProgramShareMethod,
|
|
71
|
-
MiniProgramStorageMethod,
|
|
72
|
-
MiniProgramUserMethod,
|
|
73
|
-
MiniProgramViewportMethod,
|
|
74
|
-
} from './protocol/capabilities';
|
|
75
39
|
export type { LoginPayload, LoginResult, MiniProgramAuthModule } from './modules/auth';
|
|
76
40
|
export type {
|
|
77
41
|
GetUserInfoPayload,
|
|
@@ -138,12 +102,13 @@ export default hbSDK;
|
|
|
138
102
|
Use `@heybox/hb-sdk/vite` only in `vite.config.ts`. Do not import it from iframe mini-program business code.
|
|
139
103
|
|
|
140
104
|
```ts
|
|
141
|
-
import { mkdirSync,
|
|
105
|
+
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
142
106
|
import path from 'node:path';
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
107
|
+
import {
|
|
108
|
+
getMiniappManifestBuildWarning,
|
|
109
|
+
renderMiniappManifest,
|
|
110
|
+
} from '../miniapp-manifest/schema';
|
|
111
|
+
import { readMiniappVersionFromPackageJson } from '../miniapp-manifest/node';
|
|
147
112
|
|
|
148
113
|
type MiniappManifestPlugin = {
|
|
149
114
|
name: string;
|
|
@@ -175,57 +140,19 @@ export function miniappManifest(): MiniappManifestPlugin {
|
|
|
175
140
|
outDir = resolved.build.outDir;
|
|
176
141
|
},
|
|
177
142
|
writeBundle() {
|
|
178
|
-
const version =
|
|
143
|
+
const version = readMiniappVersionFromPackageJson(root);
|
|
144
|
+
const warning = getMiniappManifestBuildWarning(version);
|
|
179
145
|
|
|
180
|
-
if (
|
|
181
|
-
this.warn(
|
|
146
|
+
if (warning) {
|
|
147
|
+
this.warn(warning);
|
|
182
148
|
}
|
|
183
149
|
|
|
184
150
|
const manifestPath = path.resolve(root, outDir, 'manifest.json');
|
|
185
151
|
mkdirSync(path.dirname(manifestPath), { recursive: true });
|
|
186
|
-
writeFileSync(manifestPath,
|
|
152
|
+
writeFileSync(manifestPath, renderMiniappManifest({ version }));
|
|
187
153
|
},
|
|
188
154
|
};
|
|
189
155
|
}
|
|
190
|
-
|
|
191
|
-
function readMiniappVersion(root: string): string {
|
|
192
|
-
const packageJsonPath = path.join(root, 'package.json');
|
|
193
|
-
let content: string;
|
|
194
|
-
|
|
195
|
-
try {
|
|
196
|
-
content = readFileSync(packageJsonPath, 'utf8');
|
|
197
|
-
} catch (error) {
|
|
198
|
-
throw new Error(`@heybox/hb-sdk 读取 package.json 失败:${formatReason(error)}`);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
let packageJson: { version?: unknown };
|
|
202
|
-
|
|
203
|
-
try {
|
|
204
|
-
packageJson = JSON.parse(content) as { version?: unknown };
|
|
205
|
-
} catch (error) {
|
|
206
|
-
throw new Error(`@heybox/hb-sdk 解析 package.json 失败:${formatReason(error)}`);
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
if (typeof packageJson.version !== 'string' || packageJson.version.trim() === '') {
|
|
210
|
-
throw new Error('@heybox/hb-sdk 提示:package.json.version 必须是非空字符串');
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
const version = packageJson.version.trim();
|
|
214
|
-
|
|
215
|
-
if (version === TEMPLATE_VERSION) {
|
|
216
|
-
throw new Error(TEMPLATE_VERSION_ERROR);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
return version;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
function formatReason(error: unknown): string {
|
|
223
|
-
if (error instanceof Error && error.message) {
|
|
224
|
-
return error.message;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
return String(error);
|
|
228
|
-
}
|
|
229
156
|
```
|
|
230
157
|
|
|
231
158
|
## Manifest
|
|
@@ -253,7 +180,7 @@ export default defineConfig({
|
|
|
253
180
|
|
|
254
181
|
- 读取 `package.json` 失败或 JSON 解析失败:`vite build` 直接失败,并输出具体原因。
|
|
255
182
|
- `package.json.version` 不是非空字符串:`vite build` 直接失败。
|
|
256
|
-
- `package.json.version` 仍是模板默认值 `0.0.0`:`vite build`
|
|
183
|
+
- `package.json.version` 仍是模板默认值 `0.0.0`:`vite build` 输出 warning 并写入 manifest;`hb-sdk deploy` 会拒绝发布,必须改成实际 `x.y.z` 版本。
|
|
257
184
|
- 版本号不满足极简 semver 形态 `x.y.z`:只输出 Rollup/Vite warning,仍会写入 manifest。
|
|
258
185
|
|
|
259
186
|
`manifest.json` 不部署到 CDN,只交给发布流水线读取后上送后台;Host 通过后台 API 间接读取版本信息。第一阶段只支持 Vite 项目,非 Vite 打包器未来通过其他子入口扩展。
|
|
@@ -271,7 +198,7 @@ npm install
|
|
|
271
198
|
npm run dev
|
|
272
199
|
```
|
|
273
200
|
|
|
274
|
-
模板默认使用 Vue 3、Vite、TypeScript 和 npm。`npm run dev` 会启动小程序页面服务,并打开 `hb-sdk` 内置的浏览器 mock 宿主环境,适合在普通浏览器里调试 SDK 能力;调试页内可点击按钮在 Mac 版 APP 中启动同一页面。
|
|
201
|
+
模板默认使用 Vue 3、Vite、TypeScript 和 npm。`npm run dev` 会启动小程序页面服务,并打开 `hb-sdk` 内置的浏览器 mock 宿主环境,适合在普通浏览器里调试 SDK 能力;调试页内可点击按钮在 Mac 版 APP 中启动同一页面。Codex、VSCode 等内嵌浏览器可能无法转交 `heybox://` 协议;需要从调试页唤起 Mac 版 APP 时,请先在系统浏览器中打开调试页。
|
|
275
202
|
|
|
276
203
|
在已有项目中安装:
|
|
277
204
|
|
|
@@ -315,7 +242,7 @@ SDK 需要在黑盒小程序 iframe 容器内运行。父容器会为页面注
|
|
|
315
242
|
npm run dev
|
|
316
243
|
```
|
|
317
244
|
|
|
318
|
-
调试页会通过 iframe 加载本地页面并补齐小程序 bridge 环境;如果需要真实黑盒小程序容器加载同一页面,点击调试页里的「在 Mac 版 APP 中启动」按钮。
|
|
245
|
+
调试页会通过 iframe 加载本地页面并补齐小程序 bridge 环境;如果需要真实黑盒小程序容器加载同一页面,点击调试页里的「在 Mac 版 APP 中启动」按钮。Codex、VSCode 等内嵌浏览器可能无法唤起系统 APP;遇到这种情况时,请在系统浏览器中打开同一个调试页后重试。
|
|
319
246
|
|
|
320
247
|
在未使用脚手架的 Vite 项目中,可以把命令加到 `package.json`:
|
|
321
248
|
|
package/skill/references/cli.md
CHANGED
|
@@ -228,7 +228,7 @@ Agent rules:
|
|
|
228
228
|
hb-sdk dev
|
|
229
229
|
```
|
|
230
230
|
|
|
231
|
-
`hb-sdk dev` 会从当前目录向上查找最近的 `package.json` 作为项目根目录,加载该项目安装的 `vite`,并优先使用项目内的 Vite 配置文件。命令会同时启动内置 mock runtime host 并默认打开调试页;如果需要真实黑盒小程序容器加载同一页面,点击调试页里的「在 Mac 版 APP
|
|
231
|
+
`hb-sdk dev` 会从当前目录向上查找最近的 `package.json` 作为项目根目录,加载该项目安装的 `vite`,并优先使用项目内的 Vite 配置文件。命令会同时启动内置 mock runtime host 并默认打开调试页;如果需要真实黑盒小程序容器加载同一页面,点击调试页里的「在 Mac 版 APP 中启动」按钮。Codex、VSCode 等内嵌浏览器可能无法转交 `heybox://` 协议;需要从调试页唤起 Mac 版 APP 时,请先在系统浏览器中打开调试页。项目没有安装 Vite 时,命令会提示安装依赖或把 Vite 放到 `devDependencies`。
|
|
232
232
|
|
|
233
233
|
常用参数:
|
|
234
234
|
|
|
@@ -241,13 +241,13 @@ hb-sdk dev
|
|
|
241
241
|
|
|
242
242
|
## Mock runtime 边界
|
|
243
243
|
|
|
244
|
-
`hb-sdk dev` 会把实际小程序页面地址编码到 mock host 的 `mini_url` query 中,由 mock host iframe 加载页面并补齐小程序 bridge 环境。mock host 内置登录/登出、`show`、`hide`、在 Mac 版 APP 中启动等调试按钮,并通过同一份 devtools-only runtime adapter 处理 SDK 能力调用。
|
|
244
|
+
`hb-sdk dev` 会把实际小程序页面地址编码到 mock host 的 `mini_url` query 中,由 mock host iframe 加载页面并补齐小程序 bridge 环境。mock host 内置登录/登出、`show`、`hide`、在 Mac 版 APP 中启动等调试按钮,并通过同一份 devtools-only runtime adapter 处理 SDK 能力调用。Codex、VSCode 等内嵌浏览器可能无法唤起系统 APP;遇到这种情况时,请在系统浏览器中打开同一个调试页后重试。
|
|
245
245
|
|
|
246
246
|
不要为了本地调试再创建独立 mock runtime 包。CLI、模板和 mock host 都归属 `@heybox/hb-sdk`。
|
|
247
247
|
|
|
248
248
|
本地 mock runtime 下的 `network.request()` 会通过 `hb-sdk` 本地 mock network proxy 转发真实 HTTP(S) 请求,用于避免浏览器 CORS 影响本地调试。proxy 不会把黑盒客户端私有协议字段暴露给 iframe 业务代码。
|
|
249
249
|
|
|
250
|
-
Use `hb-sdk dev` for local browser SDK debugging. Use the Mock runtime host's "在 Mac 版 APP 中启动" button when the page needs to be loaded by the real Heybox mini-program container.
|
|
250
|
+
Use `hb-sdk dev` for local browser SDK debugging. Use the Mock runtime host's "在 Mac 版 APP 中启动" button when the page needs to be loaded by the real Heybox mini-program container. If the mock host is open inside Codex, VSCode, or another embedded browser, ask the user to open the same debug page in the system browser before retrying because embedded browsers may block the `heybox://` protocol handoff.
|
|
251
251
|
|
|
252
252
|
## CLI login cache
|
|
253
253
|
|
|
@@ -343,12 +343,14 @@ npm run dev
|
|
|
343
343
|
npm run typecheck
|
|
344
344
|
npm run test:unit
|
|
345
345
|
npm run build
|
|
346
|
+
npm run deploy
|
|
346
347
|
```
|
|
347
348
|
|
|
348
349
|
## 开发模式
|
|
349
350
|
|
|
350
|
-
- `npm run dev`:启动本地 Vite 服务和 `hb-sdk` 内置 mock runtime host,适合本地调试 SDK 能力;调试页内可点击按钮在 Mac 版 APP 中启动同一页面。
|
|
351
|
+
- `npm run dev`:启动本地 Vite 服务和 `hb-sdk` 内置 mock runtime host,适合本地调试 SDK 能力;调试页内可点击按钮在 Mac 版 APP 中启动同一页面。Codex、VSCode 等内嵌浏览器可能无法唤起系统 APP,需要时请在系统浏览器中打开同一个调试页后重试。
|
|
351
352
|
- `npm run build`:先执行 TypeScript 检查,再构建生产产物。
|
|
353
|
+
- `npm run deploy`:构建并发布当前小程序。发布前需要先把 `package.json` 中的 `heybox.miniProgramId` 改成后台分配的真实小程序 id,并执行过 `npx hb-sdk login`。
|
|
352
354
|
|
|
353
355
|
## 更多能力
|
|
354
356
|
|
|
@@ -2,7 +2,10 @@ import { createHash } from 'node:crypto';
|
|
|
2
2
|
|
|
3
3
|
export const HB_SDK_SKILL_NAME = 'hb-sdk';
|
|
4
4
|
export const HB_SDK_PACKAGE_NAME = '@heybox/hb-sdk';
|
|
5
|
-
export const
|
|
5
|
+
export const HB_SDK_AGENT_SKILLS_BASE_URL = 'https://open.xiaoheihe.cn/agent-skills';
|
|
6
|
+
export const HB_SDK_SKILL_SOURCE = `${HB_SDK_AGENT_SKILLS_BASE_URL}/${HB_SDK_SKILL_NAME}`;
|
|
7
|
+
export const HB_SDK_SKILL_INDEX_URL = `${HB_SDK_AGENT_SKILLS_BASE_URL}/.well-known/agent-skills/index.json`;
|
|
8
|
+
export const HB_SDK_SKILL_INSTALL_COMMAND = `npx skills add ${HB_SDK_SKILL_SOURCE}`;
|
|
6
9
|
|
|
7
10
|
export function createSkillContentHash(fileEntries) {
|
|
8
11
|
const hash = createHash('sha256');
|
|
@@ -326,7 +326,7 @@ Agent rules:
|
|
|
326
326
|
|
|
327
327
|
${cliDevSection}
|
|
328
328
|
|
|
329
|
-
Use \`hb-sdk dev\` for local browser SDK debugging. Use the Mock runtime host's "在 Mac 版 APP 中启动" button when the page needs to be loaded by the real Heybox mini-program container.
|
|
329
|
+
Use \`hb-sdk dev\` for local browser SDK debugging. Use the Mock runtime host's "在 Mac 版 APP 中启动" button when the page needs to be loaded by the real Heybox mini-program container. If the mock host is open inside Codex, VSCode, or another embedded browser, ask the user to open the same debug page in the system browser before retrying because embedded browsers may block the \`heybox://\` protocol handoff.
|
|
330
330
|
|
|
331
331
|
## CLI login cache
|
|
332
332
|
|
package/skill/skill.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hb-sdk",
|
|
3
|
-
"skillVersion": "0.
|
|
3
|
+
"skillVersion": "0.3.2+skill.f845392336aa",
|
|
4
4
|
"sdk": {
|
|
5
5
|
"package": "@heybox/hb-sdk",
|
|
6
|
-
"version": "0.
|
|
7
|
-
"compatibility": "0.
|
|
6
|
+
"version": "0.3.2",
|
|
7
|
+
"compatibility": "0.3.2"
|
|
8
8
|
},
|
|
9
9
|
"source": "https://open.xiaoheihe.cn/agent-skills/hb-sdk",
|
|
10
|
-
"integrity": "sha256-
|
|
10
|
+
"integrity": "sha256-f845392336aabd50713f07fe9570e9208e1801f1e20eecb7ccd58941ab83ab64"
|
|
11
11
|
}
|