@heybox/hb-sdk 0.2.0-alpha.2 → 0.3.1
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 +2 -2
- package/dist/cli.cjs +773 -473
- package/dist/devtools/mock-host/main.js +336 -203
- 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 +2 -0
- 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/references/api-root.md +14 -87
- package/skill/references/cli.md +2 -0
- package/skill/scripts/skill-metadata.mjs +4 -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.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
18
|
- `npm run dev`:启动本地 Vite 服务和 `hb-sdk` 内置 mock runtime host,适合本地调试 SDK 能力;调试页内可点击按钮在 Mac 版 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.1",
|
|
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",
|
|
@@ -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.1`
|
|
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 打包器未来通过其他子入口扩展。
|
package/skill/references/cli.md
CHANGED
|
@@ -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
351
|
- `npm run dev`:启动本地 Vite 服务和 `hb-sdk` 内置 mock runtime host,适合本地调试 SDK 能力;调试页内可点击按钮在 Mac 版 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');
|
package/skill/skill.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hb-sdk",
|
|
3
|
-
"skillVersion": "0.
|
|
3
|
+
"skillVersion": "0.3.1+skill.3af1f225a627",
|
|
4
4
|
"sdk": {
|
|
5
5
|
"package": "@heybox/hb-sdk",
|
|
6
|
-
"version": "0.
|
|
7
|
-
"compatibility": "0.
|
|
6
|
+
"version": "0.3.1",
|
|
7
|
+
"compatibility": "0.3.1"
|
|
8
8
|
},
|
|
9
9
|
"source": "https://open.xiaoheihe.cn/agent-skills/hb-sdk",
|
|
10
|
-
"integrity": "sha256-
|
|
10
|
+
"integrity": "sha256-3af1f225a627e3a1f6f4e01a98cc4e38bc571cb911a0e27cf0919784c6b9014f"
|
|
11
11
|
}
|
package/types/core/client.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { MiniProgramBridgeMethod, MiniProgramCapabilityPayload, MiniProgramCapabilityResult } from '../protocol/capabilities';
|
|
1
2
|
import type { MiniProgramEventHandler, MiniProgramEventName } from '../protocol/types';
|
|
2
3
|
/**
|
|
3
4
|
* 创建 SDK bridge client 的配置项。
|
|
@@ -17,22 +18,11 @@ export interface MiniProgramSDKOptions {
|
|
|
17
18
|
/** 精准 postMessage 目标 origin;未传时尝试推断,失败则回退为 `*`。 */
|
|
18
19
|
targetOrigin?: string;
|
|
19
20
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
*
|
|
23
|
-
* @remarks
|
|
24
|
-
* 各公开模块只依赖该最小接口发起 bridge 请求,以保持模块层与底层实现解耦。
|
|
25
|
-
*/
|
|
21
|
+
type MiniProgramRequesterArgs<Method extends MiniProgramBridgeMethod> = MiniProgramCapabilityPayload<Method> extends void ? [payload?: MiniProgramCapabilityPayload<Method>] : [payload: MiniProgramCapabilityPayload<Method>];
|
|
22
|
+
/** 模块 API 发起请求所需的最小能力。 */
|
|
26
23
|
export interface MiniProgramRequester {
|
|
27
|
-
/**
|
|
28
|
-
|
|
29
|
-
*
|
|
30
|
-
* @typeParam T 标准化后的返回值类型。
|
|
31
|
-
* @param method bridge method 名称。
|
|
32
|
-
* @param payload 可序列化请求载荷。
|
|
33
|
-
* @returns 由父容器返回的标准化结果。
|
|
34
|
-
*/
|
|
35
|
-
request<T>(method: string, payload?: unknown): Promise<T>;
|
|
24
|
+
/** 向父容器调用指定开放能力。 */
|
|
25
|
+
request<Method extends MiniProgramBridgeMethod>(method: Method, ...args: MiniProgramRequesterArgs<Method>): Promise<MiniProgramCapabilityResult<Method>>;
|
|
36
26
|
}
|
|
37
27
|
/** 底层 bridge client,负责握手、请求响应、事件分发与超时清理。 */
|
|
38
28
|
export declare class MiniProgramBridgeClient implements MiniProgramRequester {
|
|
@@ -60,7 +50,7 @@ export declare class MiniProgramBridgeClient implements MiniProgramRequester {
|
|
|
60
50
|
/** 移除小程序事件监听。 */
|
|
61
51
|
off<T extends MiniProgramEventName>(eventName: T, handler: MiniProgramEventHandler<T>): void;
|
|
62
52
|
/** 调用父容器开放能力。 */
|
|
63
|
-
request<
|
|
53
|
+
request<Method extends MiniProgramBridgeMethod>(method: Method, ...args: MiniProgramRequesterArgs<Method>): Promise<MiniProgramCapabilityResult<Method>>;
|
|
64
54
|
/** 销毁 SDK 实例,并拒绝尚未完成的请求。 */
|
|
65
55
|
destroy(): void;
|
|
66
56
|
private ensureStarted;
|
|
@@ -74,3 +64,4 @@ export declare class MiniProgramBridgeClient implements MiniProgramRequester {
|
|
|
74
64
|
private clearReadyTimers;
|
|
75
65
|
private rejectAllPending;
|
|
76
66
|
}
|
|
67
|
+
export {};
|
package/types/index.d.ts
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
export { createMiniProgramSDK, MiniProgramSDK } from './core/sdk';
|
|
2
2
|
export { HbMiniProgramSDKError, HbMiniProgramNetworkError } from './core/errors';
|
|
3
|
-
export type {
|
|
3
|
+
export type { MiniProgramSDKOptions } from './core/client';
|
|
4
4
|
export { ready, on, off, auth, user, share, viewport, storage, network } from './core/singleton';
|
|
5
|
-
export {
|
|
6
|
-
export { isMiniProgramBridgeMessage } from './protocol/guards';
|
|
7
|
-
export type { MiniProgramBridgeError, MiniProgramBridgeMessage, MiniProgramBridgeMessageType, MiniProgramEventHandler, MiniProgramEventName, MiniProgramEventPayloadMap, } from './protocol/types';
|
|
8
|
-
export { AUTH_LOGIN_METHOD, NETWORK_REQUEST_METHOD, SHARE_SCREENSHOT_METHOD, SHARE_SHOW_SHARE_MENU_METHOD, STORAGE_GET_STORAGE_METHOD, STORAGE_SET_STORAGE_METHOD, USER_GET_INFO_METHOD, VIEWPORT_GET_WINDOW_INFO_METHOD, } from './protocol/capabilities';
|
|
9
|
-
export type { MiniProgramAuthMethod, MiniProgramBridgeMethod, MiniProgramCapabilityDefinition, MiniProgramCapabilityModule, MiniProgramCapabilityPayload, MiniProgramCapabilityPayloadMap, MiniProgramCapabilityResult, MiniProgramCapabilityResultMap, MiniProgramCapabilityRisk, MiniProgramNetworkMethod, MiniProgramShareMethod, MiniProgramStorageMethod, MiniProgramUserMethod, MiniProgramViewportMethod, } from './protocol/capabilities';
|
|
5
|
+
export type { MiniProgramEventHandler, MiniProgramEventName, MiniProgramEventPayloadMap, } from './protocol/types';
|
|
10
6
|
export type { LoginPayload, LoginResult, MiniProgramAuthModule } from './modules/auth';
|
|
11
7
|
export type { GetUserInfoPayload, GetUserInfoResult, MiniProgramUserInfo, MiniProgramUserInfoResult, MiniProgramUserModule, } from './modules/user';
|
|
12
8
|
export type { MiniProgramScreenshotOptions, MiniProgramScreenshotRect, MiniProgramShareChannel, MiniProgramShareModule, MiniProgramShowShareMenuOptions, ScreenshotPayload, ScreenshotResult, ShowShareMenuPayload, ShowShareMenuResult, } from './modules/share';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function readMiniappVersionFromPackageJson(root: string): string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const MINIAPP_TEMPLATE_VERSION = "0.0.0";
|
|
2
|
+
export interface MiniappManifest {
|
|
3
|
+
[key: string]: unknown;
|
|
4
|
+
version: string;
|
|
5
|
+
}
|
|
6
|
+
export interface ParseMiniappManifestResult {
|
|
7
|
+
manifest: MiniappManifest;
|
|
8
|
+
hadBom: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function isValidMiniappManifestVersion(version: string): boolean;
|
|
11
|
+
export declare function getMiniappManifestBuildWarning(version: string): string | undefined;
|
|
12
|
+
export declare function renderMiniappManifest(manifest: MiniappManifest): string;
|
|
13
|
+
export declare function parseMiniappManifestJson(raw: string, sourceLabel?: string): ParseMiniappManifestResult;
|
|
14
|
+
export declare function validateMiniappManifestForDeploy(manifest: MiniappManifest): string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare const MINIAPP_UPLOAD_SCOPE = "activity";
|
|
2
2
|
export declare const ACTIVITY_UPLOAD_KEY_MAX_LENGTH = 64;
|
|
3
3
|
export declare const PUBLISH_USER_MINIPROGRAM_API_PATH = "/mall/developer/user_miniprogram/publish";
|
|
4
|
-
export
|
|
4
|
+
export { isValidMiniappManifestVersion as isValidVersion } from '../miniapp-manifest/schema';
|
|
5
5
|
export declare function normalizeRelativePath(relativePath: string): string;
|
|
6
6
|
export declare function relativePathContainsNodeModulesSegment(relativePath: string): boolean;
|
|
7
7
|
export declare function getMiniProgramUploadAlias(miniProgramId: string): string;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const HB_SDK_PACKAGE_NAME = "@heybox/hb-sdk";
|
|
2
|
+
export declare const HB_SDK_SKILL_NAME = "hb-sdk";
|
|
3
|
+
export declare const HB_SDK_AGENT_SKILLS_BASE_URL = "https://open.xiaoheihe.cn/agent-skills";
|
|
4
|
+
export declare const HB_SDK_SKILL_SOURCE = "https://open.xiaoheihe.cn/agent-skills/hb-sdk";
|
|
5
|
+
export declare const HB_SDK_SKILL_INDEX_URL = "https://open.xiaoheihe.cn/agent-skills/.well-known/agent-skills/index.json";
|
|
6
|
+
export declare const HB_SDK_SKILL_INSTALL_COMMAND = "npx skills add https://open.xiaoheihe.cn/agent-skills/hb-sdk";
|