@heybox/hb-sdk 0.3.3 → 0.4.0
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 +63 -28
- package/dist/cli-chunks/browser-RAy8e8cV.cjs +635 -0
- package/dist/cli-chunks/create-D1j9UnM7.cjs +1376 -0
- package/dist/cli-chunks/deploy-CknDDoS_.cjs +3730 -0
- package/dist/cli-chunks/dev-BS9h09yG.cjs +955 -0
- package/dist/cli-chunks/doctor-WTl1HCW0.cjs +186 -0
- package/dist/cli-chunks/index-io4h3kr-.cjs +13348 -0
- package/dist/cli-chunks/index-yjJgBEBF.cjs +64023 -0
- package/dist/cli-chunks/login-B-A53Sta.cjs +193 -0
- package/dist/cli-chunks/session-CMBN3o9z.cjs +3040 -0
- package/dist/cli.cjs +19 -77707
- package/dist/devtools/mock-host/index.html +62 -2
- package/dist/devtools/mock-host/main.js +3246 -20
- package/dist/index.cjs.js +20 -0
- package/dist/index.esm.js +20 -0
- package/dist/miniapp-publish.cjs.js +2810 -4
- package/dist/miniapp-publish.esm.js +2809 -4
- package/dist/protocol.cjs.js +15 -0
- package/dist/protocol.esm.js +15 -1
- package/dist/templates/vue3-vite-ts/README.md.ejs +2 -2
- package/dist/vite.cjs.js +2814 -14
- package/dist/vite.esm.js +2814 -14
- package/package.json +6 -1
- package/skill/SKILL.md +19 -13
- package/skill/references/api-protocol.md +7 -2
- package/skill/references/api-root.md +24 -13
- package/skill/references/cli.md +335 -104
- package/skill/scripts/sync-references.mjs +17 -1
- package/skill/skill.json +4 -4
- package/types/index.d.ts +1 -1
- package/types/miniapp-manifest/schema.d.ts +2 -1
- package/types/miniapp-publish/index.d.ts +2 -1
- package/types/modules/viewport/index.d.ts +33 -0
- package/types/protocol/capabilities.d.ts +17 -2
- package/types/protocol.d.ts +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@heybox/hb-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -63,6 +63,8 @@
|
|
|
63
63
|
"@types/ejs": "^3.1.5",
|
|
64
64
|
"@types/fs-extra": "^11.0.4",
|
|
65
65
|
"@types/node": "24.10.1",
|
|
66
|
+
"@types/qrcode": "^1.5.6",
|
|
67
|
+
"@types/semver": "^7.7.1",
|
|
66
68
|
"@vitest/coverage-v8": "^3.2.4",
|
|
67
69
|
"commander": "^12.1.0",
|
|
68
70
|
"cos-nodejs-sdk-v5": "2.15.4",
|
|
@@ -72,9 +74,12 @@
|
|
|
72
74
|
"get-port": "^7.1.0",
|
|
73
75
|
"happy-dom": "^19.0.2",
|
|
74
76
|
"open": "^10.2.0",
|
|
77
|
+
"ora": "^5.4.1",
|
|
75
78
|
"picocolors": "^1.1.1",
|
|
79
|
+
"qrcode": "^1.5.4",
|
|
76
80
|
"rimraf": "^5.0.5",
|
|
77
81
|
"rollup": "^4.52.4",
|
|
82
|
+
"semver": "^7.8.0",
|
|
78
83
|
"typescript": "^5.9.3",
|
|
79
84
|
"vue": "^2.7.16",
|
|
80
85
|
"vite": "^8.0.12",
|
package/skill/SKILL.md
CHANGED
|
@@ -48,18 +48,24 @@ Apply these instructions when writing, reviewing, or debugging code that consume
|
|
|
48
48
|
|
|
49
49
|
1. Use `hb-sdk create <project-name>` to scaffold a standalone external mini-program template.
|
|
50
50
|
2. Use `hb-sdk dev` for local browser debugging through the built-in mock runtime host.
|
|
51
|
-
3. Use `hb-sdk deploy
|
|
52
|
-
4. Use `hb-sdk deploy --skip-build
|
|
53
|
-
5.
|
|
54
|
-
6.
|
|
55
|
-
7.
|
|
56
|
-
8.
|
|
57
|
-
9.
|
|
58
|
-
10.
|
|
59
|
-
11.
|
|
60
|
-
12.
|
|
61
|
-
13.
|
|
62
|
-
14.
|
|
51
|
+
3. Use `hb-sdk deploy --release-note <text>` to build, upload, and submit the current project for audit. It reads `package.json.heybox.miniProgramId`, prechecks `package.json.version` before build, runs the project's `build` script via the package manager auto-detected by lockfile, uploads `dist/` to CDN (skipping `manifest.json`, `.DS_Store`, `.map`), then calls the submit-audit API.
|
|
52
|
+
4. Use `hb-sdk deploy --skip-build --release-note <text>` only when the `dist/` directory is already prepared by an upstream CI stage. In this mode the CLI reads `dist/manifest.json.version` before precheck. Missing `dist/manifest.json` or `dist/index.html` aborts the run.
|
|
53
|
+
5. Always provide a concise release note before deploy. Non-interactive environments must pass `--release-note`; interactive terminals may prompt for it. The default is manual release after approval; use `--auto-publish` when the audited version should automatically release after approval.
|
|
54
|
+
6. For internal test/staging backend operations, use origin-only custom URLs: `HB_SDK_API_BASE_URL` or `hb-sdk deploy --api-base-url <url>` for deploy APIs, and `HB_SDK_LOGIN_BASE_URL` or `hb-sdk login --login-base-url <url>` for browser login. CLI flags override env vars. API base URLs must be Heybox trusted HTTPS origins by default; use `--allow-unsafe-api-base-url` or `HB_SDK_ALLOW_UNSAFE_API_BASE_URL=1` only for local backend debugging. Do not include path, query, or hash in these URLs.
|
|
55
|
+
7. For development routing or gray validation, configure `packages/hb-sdk/src/cli/config.ts` with `@heybox/hb-types` `RylaiServiceTagConfig` (`default_tag` / path-specific `special_tag`) to attach `x-rylai-service-tag` and the matching `special_tag` query parameter to Heybox backend API requests.
|
|
56
|
+
8. If deploy targets a custom login environment, pass the same `--login-base-url` or `HB_SDK_LOGIN_BASE_URL` used for `hb-sdk login`; deploy rejects cached CLI login state from a different login origin.
|
|
57
|
+
9. Add `--verbose` / `-v` only when diagnosing failures; default CLI errors are intentionally concise, while verbose output includes backend envelope, HTTP status, trace fields, raw body, or original submit-audit failure details.
|
|
58
|
+
10. Do not expect custom base URLs to affect `hb-sdk doctor`, npm latest checks, or mock-host `network.request()`.
|
|
59
|
+
11. Use the Mock runtime host's "在 Mac 版 APP 中启动" button for Mac App debugging, or the "Mobile App" QR code after selecting a LAN interface for phone App debugging; the phone must be on the same LAN and use a Heybox App version that supports the mini-program dev shell.
|
|
60
|
+
12. Use `--port`, `--mock-port`, and `--no-open` when the default Vite/mock ports or browser opening behavior need to be controlled.
|
|
61
|
+
13. Use `hb-sdk login`, `hb-sdk login status`, and `hb-sdk login clear` only for the CLI's own Heybox auth cache.
|
|
62
|
+
14. Use `hb-sdk doctor` to diagnose whether the local `hb-sdk` skill matches the installed SDK and remote latest skill metadata.
|
|
63
|
+
15. Do not use `hb-sdk doctor` to auto-install skills; when installation or refresh is needed, tell the user to run `npx skills add https://open.xiaoheihe.cn/agent-skills/hb-sdk`.
|
|
64
|
+
16. If doctor reports `SDK_MISMATCH`, upgrade `@heybox/hb-sdk@latest` before reinstalling the skill.
|
|
65
|
+
17. Do not treat CLI login cache as iframe SDK login state; it does not change `auth.login()`, `user.getInfo()`, `network.request()`, or mock-user behavior.
|
|
66
|
+
18. Keep the CLI and mock runtime under `@heybox/hb-sdk`; do not create or revive a separate mock runtime package.
|
|
67
|
+
19. Do not pass `mini_program_id` as a CLI flag or environment variable; it must come from `package.json.heybox.miniProgramId`.
|
|
68
|
+
20. Do not import deploy / upload internals from outside the CLI; the only externally consumable subpath for publish-pipeline helpers is `@heybox/hb-sdk/miniapp-publish`.
|
|
63
69
|
|
|
64
70
|
## Step 6: Preserve capability boundaries
|
|
65
71
|
|
|
@@ -101,6 +107,6 @@ For host/runtime/protocol-maintenance code:
|
|
|
101
107
|
- `pnpm --filter @heybox/hb-sdk run check:boundary`
|
|
102
108
|
- `pnpm --filter @heybox/hb-sdk run test:unit`
|
|
103
109
|
- Verify `dist/cli.cjs` does not have any `require('cos-nodejs-sdk-v5')` left after `build:cli`; the boundary check enforces this automatically.
|
|
104
|
-
|
|
110
|
+
7. Verify public payload sync before publishing:
|
|
105
111
|
- `pnpm --filter @heybox-spa/open run sync:agent-skills`
|
|
106
112
|
- `pnpm --filter @heybox-spa/open run check:agent-skills`
|
|
@@ -46,6 +46,7 @@ export {
|
|
|
46
46
|
STORAGE_SET_STORAGE_METHOD,
|
|
47
47
|
USER_GET_INFO_METHOD,
|
|
48
48
|
VIEWPORT_GET_WINDOW_INFO_METHOD,
|
|
49
|
+
VIEWPORT_SET_NAVIGATION_BAR_STYLE_METHOD,
|
|
49
50
|
} from './protocol/capabilities';
|
|
50
51
|
export type {
|
|
51
52
|
MiniProgramAuthMethod,
|
|
@@ -86,8 +87,12 @@ export type {
|
|
|
86
87
|
export type {
|
|
87
88
|
GetWindowInfoPayload,
|
|
88
89
|
GetWindowInfoResult,
|
|
90
|
+
MiniProgramNavigationBarForegroundStyle,
|
|
89
91
|
MiniProgramSafeArea,
|
|
92
|
+
MiniProgramSetNavigationBarStyleOptions,
|
|
90
93
|
MiniProgramWindowInfoResult,
|
|
94
|
+
SetNavigationBarStylePayload,
|
|
95
|
+
SetNavigationBarStyleResult,
|
|
91
96
|
} from './modules/viewport';
|
|
92
97
|
export type {
|
|
93
98
|
MiniProgramNetworkHeaders,
|
|
@@ -131,5 +136,5 @@ Reference 由 `packages/hb-sdk` 的公开导出与源码注释自动生成,不
|
|
|
131
136
|
|
|
132
137
|
| 导出面 | Classes | Functions | Interfaces | Types | Constants |
|
|
133
138
|
| --- | ---: | ---: | ---: | ---: | ---: |
|
|
134
|
-
| Root API | 3 | 4 |
|
|
135
|
-
| Protocol API | 0 | 1 |
|
|
139
|
+
| Root API | 3 | 4 | 23 | 20 | 0 |
|
|
140
|
+
| Protocol API | 0 | 1 | 21 | 32 | 14 |
|
|
@@ -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.4.0`
|
|
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`
|
|
@@ -58,9 +58,13 @@ export type {
|
|
|
58
58
|
export type {
|
|
59
59
|
GetWindowInfoPayload,
|
|
60
60
|
GetWindowInfoResult,
|
|
61
|
+
MiniProgramNavigationBarForegroundStyle,
|
|
61
62
|
MiniProgramSafeArea,
|
|
63
|
+
MiniProgramSetNavigationBarStyleOptions,
|
|
62
64
|
MiniProgramViewportModule,
|
|
63
65
|
MiniProgramWindowInfoResult,
|
|
66
|
+
SetNavigationBarStylePayload,
|
|
67
|
+
SetNavigationBarStyleResult,
|
|
64
68
|
} from './modules/viewport';
|
|
65
69
|
export type {
|
|
66
70
|
GetStoragePayload,
|
|
@@ -105,8 +109,8 @@ Use `@heybox/hb-sdk/vite` only in `vite.config.ts`. Do not import it from iframe
|
|
|
105
109
|
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
106
110
|
import path from 'node:path';
|
|
107
111
|
import {
|
|
108
|
-
getMiniappManifestBuildWarning,
|
|
109
112
|
renderMiniappManifest,
|
|
113
|
+
validateMiniappPackageVersionForBuild,
|
|
110
114
|
} from '../miniapp-manifest/schema';
|
|
111
115
|
import { readMiniappVersionFromPackageJson } from '../miniapp-manifest/node';
|
|
112
116
|
|
|
@@ -140,12 +144,7 @@ export function miniappManifest(): MiniappManifestPlugin {
|
|
|
140
144
|
outDir = resolved.build.outDir;
|
|
141
145
|
},
|
|
142
146
|
writeBundle() {
|
|
143
|
-
const version = readMiniappVersionFromPackageJson(root);
|
|
144
|
-
const warning = getMiniappManifestBuildWarning(version);
|
|
145
|
-
|
|
146
|
-
if (warning) {
|
|
147
|
-
this.warn(warning);
|
|
148
|
-
}
|
|
147
|
+
const version = validateMiniappPackageVersionForBuild(readMiniappVersionFromPackageJson(root));
|
|
149
148
|
|
|
150
149
|
const manifestPath = path.resolve(root, outDir, 'manifest.json');
|
|
151
150
|
mkdirSync(path.dirname(manifestPath), { recursive: true });
|
|
@@ -198,7 +197,7 @@ npm install
|
|
|
198
197
|
npm run dev
|
|
199
198
|
```
|
|
200
199
|
|
|
201
|
-
模板默认使用 Vue 3、Vite、TypeScript 和 npm。`npm run dev` 会启动小程序页面服务,并打开 `hb-sdk` 内置的浏览器 mock 宿主环境,适合在普通浏览器里调试 SDK 能力;调试页内可点击按钮在 Mac 版 APP
|
|
200
|
+
模板默认使用 Vue 3、Vite、TypeScript 和 npm。`npm run dev` 会启动小程序页面服务,并打开 `hb-sdk` 内置的浏览器 mock 宿主环境,适合在普通浏览器里调试 SDK 能力;调试页内可点击按钮在 Mac 版 APP 中启动同一页面,也可以选择局域网网卡后用手机小黑盒 APP 扫码调试。手机需要与电脑处在同一局域网,并使用支持小程序调试壳的新版小黑盒 APP。Codex、VSCode 等内嵌浏览器可能无法转交 `heybox://` 协议;需要从调试页唤起 Mac 版 APP 时,请先在系统浏览器中打开调试页。
|
|
202
201
|
|
|
203
202
|
在已有项目中安装:
|
|
204
203
|
|
|
@@ -242,7 +241,7 @@ SDK 需要在黑盒小程序 iframe 容器内运行。父容器会为页面注
|
|
|
242
241
|
npm run dev
|
|
243
242
|
```
|
|
244
243
|
|
|
245
|
-
调试页会通过 iframe 加载本地页面并补齐小程序 bridge
|
|
244
|
+
调试页会通过 iframe 加载本地页面并补齐小程序 bridge 环境;如果需要真实黑盒小程序容器加载同一页面,可以点击调试页里的「在 Mac 版 APP 中启动」按钮,或在「Mobile App」区域选择局域网网卡后用手机小黑盒 APP 扫码。Codex、VSCode 等内嵌浏览器可能无法唤起系统 APP;遇到这种情况时,请在系统浏览器中打开同一个调试页后重试。
|
|
246
245
|
|
|
247
246
|
在未使用脚手架的 Vite 项目中,可以把命令加到 `package.json`:
|
|
248
247
|
|
|
@@ -325,6 +324,18 @@ const windowInfo = await viewport.getWindowInfo();
|
|
|
325
324
|
console.log(windowInfo.windowWidth, windowInfo.windowHeight, windowInfo.safeArea.top);
|
|
326
325
|
```
|
|
327
326
|
|
|
327
|
+
### 导航栏样式
|
|
328
|
+
|
|
329
|
+
```ts
|
|
330
|
+
import { viewport } from '@heybox/hb-sdk';
|
|
331
|
+
|
|
332
|
+
await viewport.setNavigationBarStyle({
|
|
333
|
+
foregroundStyle: 'light',
|
|
334
|
+
});
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
`foregroundStyle` 设置导航栏关闭按钮与状态栏图标/文字的明暗样式:`light` 表示白色前景,适合深色背景;`dark` 表示黑色前景,适合浅色背景。该能力不设置导航栏背景色,也不支持关闭按钮与状态栏分别配置。
|
|
338
|
+
|
|
328
339
|
### 隔离 Storage
|
|
329
340
|
|
|
330
341
|
```ts
|
|
@@ -373,7 +384,7 @@ try {
|
|
|
373
384
|
```ts
|
|
374
385
|
await network.request({
|
|
375
386
|
url: 'https://api.example.com/demo',
|
|
376
|
-
validateStatus: status => status < 500,
|
|
387
|
+
validateStatus: (status) => status < 500,
|
|
377
388
|
});
|
|
378
389
|
```
|
|
379
390
|
|
|
@@ -386,11 +397,11 @@ await network.request({
|
|
|
386
397
|
```ts
|
|
387
398
|
import { on } from '@heybox/hb-sdk';
|
|
388
399
|
|
|
389
|
-
const unsubscribeShow = on('show', payload => {
|
|
400
|
+
const unsubscribeShow = on('show', (payload) => {
|
|
390
401
|
console.log('页面展示', payload.timestamp, payload.source);
|
|
391
402
|
});
|
|
392
403
|
|
|
393
|
-
const unsubscribeAuth = on('authChange', payload => {
|
|
404
|
+
const unsubscribeAuth = on('authChange', (payload) => {
|
|
394
405
|
console.log('登录态变化', payload.isLogin, payload.userInfo);
|
|
395
406
|
});
|
|
396
407
|
|