@heybox/hb-sdk 0.6.6-alpha.1 → 0.6.6-alpha.3

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.
Files changed (34) hide show
  1. package/README.md +41 -6
  2. package/dist/cli-chunks/build-De-QADpA.cjs +137 -0
  3. package/dist/cli-chunks/context-CvZs9ZBf.cjs +311 -0
  4. package/dist/cli-chunks/{create-DlU4nWz_.cjs → create-B5gGBaSV.cjs} +1 -1
  5. package/dist/cli-chunks/{dev-Bb4U965a.cjs → dev-BcCWCeac.cjs} +11 -42
  6. package/dist/cli-chunks/{doctor-DwDqOLdV.cjs → doctor-BhBM4cWH.cjs} +1 -1
  7. package/dist/cli-chunks/{context-D-cb_pNY.cjs → index-BQm5XmMC.cjs} +19 -308
  8. package/dist/cli-chunks/{index-B6gnwx39.cjs → index-DyUo67lf.cjs} +3 -3
  9. package/dist/cli-chunks/{index-gP0K2xx1.cjs → index-QAkYgxPI.cjs} +32 -16
  10. package/dist/cli-chunks/{login-BFIcNgmi.cjs → login-BNLH13Zd.cjs} +2 -2
  11. package/dist/cli-chunks/project-vite-VcJMyz1l.cjs +45 -0
  12. package/dist/cli-chunks/remote-BE53wntR.cjs +1504 -0
  13. package/dist/cli-chunks/{remote-YESvKni6.cjs → runtime-gate-B2MQf1vc.cjs} +7 -1501
  14. package/dist/cli-chunks/{session-BRwveiW8.cjs → session-YJ8xNESM.cjs} +1 -1
  15. package/dist/cli.cjs +1 -1
  16. package/dist/devtools/mock-host/main.js +149 -3
  17. package/dist/index.cjs.js +1 -1
  18. package/dist/index.esm.js +1 -1
  19. package/dist/templates/vue3-vite-ts/README.md.ejs +2 -2
  20. package/dist/templates/vue3-vite-ts/package.json.ejs +1 -1
  21. package/dist/vite.cjs.js +1 -1
  22. package/dist/vite.esm.js +1 -1
  23. package/package.json +1 -1
  24. package/skill/SKILL.md +19 -14
  25. package/skill/references/api-protocol.md +3 -2
  26. package/skill/references/api-root.md +20 -7
  27. package/skill/references/cli.md +33 -1
  28. package/skill/references/recipes.md +53 -0
  29. package/skill/references/safety-boundaries.md +1 -1
  30. package/skill/scripts/sync-references.mjs +23 -1
  31. package/skill/skill.json +4 -4
  32. package/types/index.d.ts +1 -1
  33. package/types/modules/share/types.d.ts +11 -0
  34. package/types/protocol.d.ts +1 -1
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var index = require('./index-gP0K2xx1.cjs');
3
+ var index = require('./index-QAkYgxPI.cjs');
4
4
  var node_crypto = require('node:crypto');
5
5
  var path = require('node:path');
6
6
  var require$$0$2 = require('fs');
package/dist/cli.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var index = require('./cli-chunks/index-gP0K2xx1.cjs');
3
+ var index = require('./cli-chunks/index-QAkYgxPI.cjs');
4
4
  require('node:module');
5
5
  require('node:fs');
6
6
  require('node:fs/promises');
@@ -4245,15 +4245,150 @@ function getPositiveNumber(value, fallback) {
4245
4245
  return numberValue;
4246
4246
  }
4247
4247
 
4248
+ const MINI_PROGRAM_DEV_SHELL_PROTOCOL = 'heybox-mini-dev:';
4249
+ function isMiniProgramDevShellHref(href) {
4250
+ try {
4251
+ return isMiniProgramDevShellUrl(new URL(href));
4252
+ }
4253
+ catch {
4254
+ return false;
4255
+ }
4256
+ }
4257
+ function isMiniProgramDevShellUrl(url) {
4258
+ return url.protocol === MINI_PROGRAM_DEV_SHELL_PROTOCOL;
4259
+ }
4260
+
4261
+ function readMiniProgramRuntimeSharePostOptions(value, options) {
4262
+ if (value === undefined || value === null) {
4263
+ return {};
4264
+ }
4265
+ if (!isMiniProgramRuntimeRecord(value)) {
4266
+ return invalidSharePostResult(`${options.method} post 必须是对象或 null`);
4267
+ }
4268
+ const topicIds = readTopicIds(value.topicIds);
4269
+ const topics = readTopics(value.topics);
4270
+ const invalidMessages = [...topicIds.invalidMessages, ...topics.invalidMessages];
4271
+ let normalizedTopicIds = topicIds.values;
4272
+ if (options.maxTopicIds !== undefined && normalizedTopicIds.length > options.maxTopicIds) {
4273
+ invalidMessages.push(`${options.method} post.topicIds 最多允许 ${options.maxTopicIds} 项`);
4274
+ normalizedTopicIds = normalizedTopicIds.slice(0, options.maxTopicIds);
4275
+ }
4276
+ const post = createNormalizedPostOptions(normalizedTopicIds, topics.values);
4277
+ if (!post) {
4278
+ invalidMessages.push(`${options.method} post 至少需要一个有效的 topicIds 或 topics`);
4279
+ }
4280
+ return {
4281
+ post,
4282
+ invalidMessage: invalidMessages[0],
4283
+ };
4284
+ }
4285
+ function handleMiniProgramRuntimeSharePostValidation(result, platformAdapter, invoke) {
4286
+ if (!result.invalidMessage) {
4287
+ return invoke(result.post);
4288
+ }
4289
+ const invalidMessage = result.invalidMessage;
4290
+ return isMiniProgramShareDevelopmentRuntime(platformAdapter).then((isDevelopment) => {
4291
+ if (isDevelopment) {
4292
+ throw createMiniProgramRuntimeBridgeError('INVALID_PARAMS', invalidMessage);
4293
+ }
4294
+ return invoke(result.post);
4295
+ });
4296
+ }
4297
+ function readTopicIds(value) {
4298
+ if (value === undefined) {
4299
+ return { values: [], invalidMessages: [] };
4300
+ }
4301
+ if (!Array.isArray(value)) {
4302
+ return { values: [], invalidMessages: ['post.topicIds 必须是数组'] };
4303
+ }
4304
+ const values = [];
4305
+ const seen = new Set();
4306
+ const invalidMessages = [];
4307
+ for (const item of value) {
4308
+ const normalized = normalizeTopicId(item);
4309
+ if (!normalized) {
4310
+ invalidMessages.push('post.topicIds 每项必须是正整数或非空字符串');
4311
+ continue;
4312
+ }
4313
+ if (!seen.has(normalized)) {
4314
+ seen.add(normalized);
4315
+ values.push(normalized);
4316
+ }
4317
+ }
4318
+ return { values, invalidMessages };
4319
+ }
4320
+ function readTopics(value) {
4321
+ if (value === undefined) {
4322
+ return { values: [], invalidMessages: [] };
4323
+ }
4324
+ if (!Array.isArray(value)) {
4325
+ return { values: [], invalidMessages: ['post.topics 必须是数组'] };
4326
+ }
4327
+ const values = [];
4328
+ const seen = new Set();
4329
+ const invalidMessages = [];
4330
+ for (const item of value) {
4331
+ const normalized = typeof item === 'string' ? item.trim() : '';
4332
+ if (!normalized || normalized.startsWith('#') || normalized.endsWith('#')) {
4333
+ invalidMessages.push('post.topics 每项必须是不含首尾 # 的非空字符串');
4334
+ continue;
4335
+ }
4336
+ if (!seen.has(normalized)) {
4337
+ seen.add(normalized);
4338
+ values.push(normalized);
4339
+ }
4340
+ }
4341
+ return { values, invalidMessages };
4342
+ }
4343
+ function normalizeTopicId(value) {
4344
+ if (typeof value === 'number') {
4345
+ return Number.isSafeInteger(value) && value > 0 ? String(value) : undefined;
4346
+ }
4347
+ if (typeof value === 'string') {
4348
+ return value.trim() || undefined;
4349
+ }
4350
+ return undefined;
4351
+ }
4352
+ function createNormalizedPostOptions(topicIds, topics) {
4353
+ if (topicIds.length === 0 && topics.length === 0) {
4354
+ return undefined;
4355
+ }
4356
+ return {
4357
+ ...(topicIds.length > 0 ? { topicIds } : {}),
4358
+ ...(topics.length > 0 ? { topics } : {}),
4359
+ };
4360
+ }
4361
+ function invalidSharePostResult(message) {
4362
+ return { invalidMessage: message };
4363
+ }
4364
+ async function isMiniProgramShareDevelopmentRuntime(platformAdapter) {
4365
+ try {
4366
+ if (isMiniProgramDevShellHref(platformAdapter.app.getCurrentHref())) {
4367
+ return true;
4368
+ }
4369
+ }
4370
+ catch {
4371
+ // 环境读取失败时继续使用宿主的显式开发态判断。
4372
+ }
4373
+ try {
4374
+ return Boolean(await platformAdapter.app.isDevRuntime?.());
4375
+ }
4376
+ catch {
4377
+ return false;
4378
+ }
4379
+ }
4380
+
4248
4381
  /** 截图并唤起分享。 */
4249
4382
  function shareMiniProgramRuntimeScreenshot(payload, platformAdapter) {
4250
4383
  const options = readMiniProgramScreenshotOptions(payload);
4251
4384
  const rect = options.rect || getMiniProgramRuntimeViewportRect(platformAdapter);
4252
- return platformAdapter.share.shareScreenshot({
4385
+ const postResult = readMiniProgramRuntimeSharePostOptions(payload && typeof payload === 'object' ? payload.post : undefined, { method: 'share.screenshot' });
4386
+ return handleMiniProgramRuntimeSharePostValidation(postResult, platformAdapter, (post) => platformAdapter.share.shareScreenshot({
4253
4387
  rect,
4254
4388
  delay: options.delay,
4255
4389
  saveToAlbum: options.saveToAlbum,
4256
- });
4390
+ post,
4391
+ }));
4257
4392
  }
4258
4393
  function readMiniProgramScreenshotOptions(payload) {
4259
4394
  if (payload === undefined || payload === null) {
@@ -4288,7 +4423,17 @@ function readScreenshotRect(value) {
4288
4423
 
4289
4424
  /** 展示基础分享面板。 */
4290
4425
  function showMiniProgramRuntimeShareMenu(payload, platformAdapter, context = {}) {
4291
- return platformAdapter.share.showShareMenu(readMiniProgramShareMenuOptions(payload, platformAdapter, context));
4426
+ const options = readMiniProgramShareMenuOptions(payload, platformAdapter, context);
4427
+ let postResult = readMiniProgramRuntimeSharePostOptions(payload.post, {
4428
+ maxTopicIds: 1,
4429
+ method: 'share.showShareMenu',
4430
+ });
4431
+ if (options.channel && postResult.post) {
4432
+ postResult = {
4433
+ invalidMessage: postResult.invalidMessage || 'share.showShareMenu channel 与 post 不能同时使用',
4434
+ };
4435
+ }
4436
+ return handleMiniProgramRuntimeSharePostValidation(postResult, platformAdapter, (post) => platformAdapter.share.showShareMenu({ ...options, post }));
4292
4437
  }
4293
4438
  function readMiniProgramShareMenuOptions(payload, platformAdapter, context) {
4294
4439
  assertMiniProgramRuntimeRecord(payload, 'share.showShareMenu 参数必须是对象');
@@ -5201,6 +5346,7 @@ function createBrowserMockRuntimePlatformAdapter(options) {
5201
5346
  return {
5202
5347
  app: {
5203
5348
  getCurrentHref: options.getCurrentHref,
5349
+ isDevRuntime: () => true,
5204
5350
  },
5205
5351
  launch: {
5206
5352
  async getMiniProgramInfo() {
package/dist/index.cjs.js CHANGED
@@ -325,7 +325,7 @@ function createMessageId() {
325
325
  /** 构建时替换为当前发布包的实际版本。 */
326
326
  const HB_SDK_VERSION = typeof undefined === 'string'
327
327
  ? undefined
328
- : '0.6.6-alpha.1';
328
+ : '0.6.6-alpha.3';
329
329
 
330
330
  /**
331
331
  * 判断未知数据是否符合小程序 bridge 消息信封。
package/dist/index.esm.js CHANGED
@@ -321,7 +321,7 @@ function createMessageId() {
321
321
  /** 构建时替换为当前发布包的实际版本。 */
322
322
  const HB_SDK_VERSION = typeof undefined === 'string'
323
323
  ? undefined
324
- : '0.6.6-alpha.1';
324
+ : '0.6.6-alpha.3';
325
325
 
326
326
  /**
327
327
  * 判断未知数据是否符合小程序 bridge 消息信封。
@@ -20,8 +20,8 @@ npm run deploy
20
20
  ## 开发模式
21
21
 
22
22
  - `npm run dev`:打开本地调试页,可以使用浏览器 Mock,也可以在 Mac 版 APP 或手机小黑盒 APP 中验收。手机和电脑需要处于同一局域网。
23
- - `npm run build`:先执行 TypeScript 检查,再构建生产产物。
24
- - `npm run deploy -- --release-note "..."`:检查、构建、上传并提交审核。首次提交前先运行 `npx hb-sdk login`,再用 `npx hb-sdk remote create` 创建小程序,或用 `npx hb-sdk remote bind <mini-program-id>` 绑定已有小程序。审核通过后,用 `hb-sdk remote release <version>` 发布。
23
+ - `npm run build`:先执行 TypeScript 检查,再通过 `hb-sdk build` 构建生产产物。
24
+ - `npm run deploy -- --release-note "..."`:检查、执行项目的 `scripts.build`、上传并提交审核。首次提交前先运行 `npx hb-sdk login`,再用 `npx hb-sdk remote create` 创建小程序,或用 `npx hb-sdk remote bind <mini-program-id>` 绑定已有小程序。审核通过后,用 `hb-sdk remote release <version>` 发布。
25
25
 
26
26
  ## 更多能力
27
27
 
@@ -10,7 +10,7 @@
10
10
  "hb-sdk": "hb-sdk",
11
11
  "dev": "hb-sdk dev",
12
12
  "deploy": "hb-sdk remote deploy",
13
- "build": "vue-tsc --noEmit && vite build",
13
+ "build": "vue-tsc --noEmit && hb-sdk build",
14
14
  "preview": "vite preview",
15
15
  "typecheck": "vue-tsc --noEmit",
16
16
  "test:unit": "vitest run",
package/dist/vite.cjs.js CHANGED
@@ -7,7 +7,7 @@ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentS
7
7
  /** 构建时替换为当前发布包的实际版本。 */
8
8
  const HB_SDK_VERSION = typeof undefined === 'string'
9
9
  ? undefined
10
- : '0.6.6-alpha.1';
10
+ : '0.6.6-alpha.3';
11
11
 
12
12
  var re = {exports: {}};
13
13
 
package/dist/vite.esm.js CHANGED
@@ -4,7 +4,7 @@ import path from 'node:path';
4
4
  /** 构建时替换为当前发布包的实际版本。 */
5
5
  const HB_SDK_VERSION = typeof undefined === 'string'
6
6
  ? undefined
7
- : '0.6.6-alpha.1';
7
+ : '0.6.6-alpha.3';
8
8
 
9
9
  var re = {exports: {}};
10
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heybox/hb-sdk",
3
- "version": "0.6.6-alpha.1",
3
+ "version": "0.6.6-alpha.3",
4
4
  "sideEffects": [
5
5
  "./src/index.ts",
6
6
  "./src/core/singleton.ts",
package/skill/SKILL.md CHANGED
@@ -11,7 +11,7 @@ Apply these instructions when writing, reviewing, or debugging code that consume
11
11
 
12
12
  1. If the task is workshop mini-program business code, use the root package import path `@heybox/hb-sdk`.
13
13
  2. If the task is parent-container runtime, bridge-server, protocol contract, or `@heybox/hb-sdk-runtime` work, use `@heybox/hb-sdk/protocol` only for shared constants and types.
14
- 3. If the task is project scaffolding, local startup, browser Mock, device debugging, CLI login, Agent Skill diagnosis, or CLI troubleshooting, use the `hb-sdk` CLI workflow.
14
+ 3. If the task is project scaffolding, local startup, production build, browser Mock, device debugging, CLI login, Agent Skill diagnosis, or CLI troubleshooting, use the `hb-sdk` CLI workflow.
15
15
  4. If the task is reviewing a mini-program for submission, listing, audit, publishing, content compliance, data/privacy compliance, runtime quality, or icon/cover design requirements, use the online publishing rules workflow.
16
16
  5. If the task asks for direct login-state extraction, cookies, tokens, raw Heybox client protocols, or internal hb-sdk package paths, refuse that approach and use the public SDK or CLI boundary instead.
17
17
  6. If the task is not about Heybox workshop mini-program SDK usage, CLI usage, protocol contracts, or listing/audit/compliance review, do not apply this skill.
@@ -21,7 +21,7 @@ Apply these instructions when writing, reviewing, or debugging code that consume
21
21
  1. For root SDK imports, singleton usage, modules, and errors, read `references/api-root.md`.
22
22
  2. For host/runtime protocol contracts only, read `references/api-protocol.md`. Do not use this reference for mini-program business code.
23
23
  3. For common business flows, read `references/recipes.md`.
24
- 4. For CLI commands, local debugging, device debugging, CLI login, Agent Skill doctor, and update reminders, read `references/cli.md`.
24
+ 4. For CLI commands, production builds, local debugging, device debugging, CLI login, Agent Skill doctor, and update reminders, read `references/cli.md`.
25
25
  5. For allowed/forbidden capabilities and security boundaries, read `references/safety-boundaries.md`.
26
26
  6. For Vite build manifest behavior, read `references/api-root.md` and `references/safety-boundaries.md`.
27
27
  7. For generated documentation provenance and deeper API lookup paths, read `references/llms-index.md`.
@@ -45,30 +45,35 @@ Apply these instructions when writing, reviewing, or debugging code that consume
45
45
  5. Handle `HbMiniProgramNetworkError` separately when HTTP completed but `validateStatus` rejected the status.
46
46
  6. Cancel lifecycle/event subscriptions returned by `on()` when the page or component unmounts.
47
47
  7. Use the default SDK instance exposed by the root package.
48
+ 8. Use `share.showShareMenu({ post })` or `share.screenshot({ post })` to preset editable community destinations and topics. Pass partition IDs through `topicIds` and topic text without surrounding `#` through `topics`; do not construct the underlying client post protocol.
48
49
 
49
50
  ## Step 5: Use CLI workflows
50
51
 
51
52
  1. Use `hb-sdk create <project-name>` to scaffold a workshop mini-program.
52
53
  2. Use `hb-sdk dev` for browser, Mac App, or mobile App debugging. These entries remain available without CLI login or project binding, but managed capabilities are denied by default.
53
54
  3. Use `--port`, `--mock-port`, and `--no-open` when the default local ports or browser opening behavior need to be controlled.
54
- 4. Use `hb-sdk login`, `hb-sdk login status`, and `hb-sdk login clear` only for development and publishing commands. This login does not change the mini-program user's login state.
55
- 5. Use `hb-sdk remote entity current` to confirm the current developer account and `hb-sdk remote entity switch <entity-id>` to change it before remote operations.
56
- 6. Use `hb-sdk remote create` to create and bind a mini-program; use `hb-sdk remote bind <mini-program-id>` to bind an existing manageable mini-program.
57
- 7. Use `hb-sdk remote info`, `hb-sdk remote list`, `hb-sdk remote access`, `hb-sdk remote versions`, `hb-sdk remote preview <version>`, and `hb-sdk remote allowlist ...` for remote inspection and preview management.
58
- 8. Use `hb-sdk remote deploy --release-note <text>` to check, build, upload, and submit the current project for audit. Do not recommend the removed top-level `hb-sdk deploy` alias.
59
- 9. After approval, use `hb-sdk remote release <version>` for manual release or `--auto-publish` when an eligible low-risk version should release automatically.
60
- 10. Treat approval, release, and public display as separate states. Do not promise square, search, or recommendation visibility after release.
61
- 11. Use `hb-sdk remote withdraw`, `hb-sdk remote take-down`, `hb-sdk remote reopen`, and square visibility commands only after showing the target and obtaining required confirmation.
62
- 12. Use `--json` for script consumption and `--verbose` only when concise output is insufficient for diagnosis.
63
- 13. Use `hb-sdk doctor` to diagnose whether the local Skill matches the installed SDK; follow its output to install or refresh the Skill.
64
- 14. Do not print or expose cookies, tokens, private headers, or other credentials.
55
+ 4. Use `hb-sdk build [--env <name>] [--verbose]` as the recommended production build entry. It directly owns the Vite build, always cleans and writes `dist/`, and works without CLI login, project binding, or network access.
56
+ 5. Keep `miniappManifest()` explicitly enabled in `vite.config.ts`; `hb-sdk build` must fail when the required Manifest or Runtime gate output is missing.
57
+ 6. Keep project typechecking in `scripts.build`, for example `vue-tsc --noEmit && hb-sdk build`; `hb-sdk build` does not run typechecking or invoke `scripts.build` itself.
58
+ 7. Existing projects may continue to use `vite build`; do not auto-migrate them. Do not invent `--mode`, `--json`, config, or output-directory flags for `hb-sdk build`.
59
+ 8. Use `hb-sdk login`, `hb-sdk login status`, and `hb-sdk login clear` only for development and publishing commands. This login does not change the mini-program user's login state.
60
+ 9. Use `hb-sdk remote entity current` to confirm the current developer account and `hb-sdk remote entity switch <entity-id>` to change it before remote operations.
61
+ 10. Use `hb-sdk remote create` to create and bind a mini-program; use `hb-sdk remote bind <mini-program-id>` to bind an existing manageable mini-program.
62
+ 11. Use `hb-sdk remote info`, `hb-sdk remote list`, `hb-sdk remote access`, `hb-sdk remote versions`, `hb-sdk remote preview <version>`, and `hb-sdk remote allowlist ...` for remote inspection and preview management.
63
+ 12. Use `hb-sdk remote deploy --release-note <text>` to run the project's `scripts.build`, upload, and submit the current project for audit. Do not recommend the removed top-level `hb-sdk deploy` alias.
64
+ 13. After approval, use `hb-sdk remote release <version>` for manual release or `--auto-publish` when an eligible low-risk version should release automatically.
65
+ 14. Treat approval, release, and public display as separate states. Do not promise square, search, or recommendation visibility after release.
66
+ 15. Use `hb-sdk remote withdraw`, `hb-sdk remote take-down`, `hb-sdk remote reopen`, and square visibility commands only after showing the target and obtaining required confirmation.
67
+ 16. Use `--json` for remote script consumption and `--verbose` only when concise output is insufficient for diagnosis.
68
+ 17. Use `hb-sdk doctor` to diagnose whether the local Skill matches the installed SDK; follow its output to install or refresh the Skill.
69
+ 18. Do not print or expose cookies, tokens, private headers, or other credentials.
65
70
 
66
71
  ## Step 6: Preserve capability boundaries
67
72
 
68
73
  For workshop mini-program business code:
69
74
 
70
75
  1. Do not read or request tokens, cookies, phone numbers, or private credentials from the SDK.
71
- 2. Do not expose raw share protocol fields, JS callbacks, activity reporting, custom buttons, post publishing, or upload-only flows.
76
+ 2. Do not expose raw share protocol fields, JS callbacks, activity reporting, custom buttons, direct post publishing, or upload-only flows. Public `share.*({ post })` options only preset an editable client post flow and never publish automatically.
72
77
  3. Do not use unsupported storage operations such as delete, clear, info listing, or global client storage access.
73
78
  4. Use only the public `network.request` configuration.
74
79
  5. Do not use private package paths or client protocols.
@@ -144,6 +144,7 @@ export type {
144
144
  MiniProgramScreenshotOptions,
145
145
  MiniProgramScreenshotRect,
146
146
  MiniProgramShareChannel,
147
+ MiniProgramSharePostOptions,
147
148
  MiniProgramShowShareMenuOptions,
148
149
  } from './modules/share';
149
150
  export type { GetStoragePayload, GetStorageResult, SetStoragePayload } from './modules/storage';
@@ -222,7 +223,7 @@ Reference 由 `@heybox/hb-sdk` 的公开导出与源码注释自动生成,不
222
223
 
223
224
  | 导出面 | Classes | Functions | Interfaces | Types | Constants |
224
225
  | --- | ---: | ---: | ---: | ---: | ---: |
225
- | Root API | 2 | 3 | 66 | 57 | 0 |
226
- | Protocol API | 0 | 3 | 43 | 67 | 32 |
226
+ | Root API | 2 | 3 | 67 | 57 | 0 |
227
+ | Protocol API | 0 | 3 | 44 | 67 | 32 |
227
228
  | Miniapp Publish API | 0 | 5 | 2 | 0 | 0 |
228
229
  | Vite API | 0 | 1 | 0 | 0 | 0 |
@@ -19,7 +19,7 @@
19
19
  ## Package metadata
20
20
 
21
21
  - Package: `@heybox/hb-sdk`
22
- - Version at generation time: `0.6.6-alpha.1`
22
+ - Version at generation time: `0.6.6-alpha.3`
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`
@@ -99,6 +99,7 @@ export type {
99
99
  MiniProgramScreenshotRect,
100
100
  MiniProgramShareChannel,
101
101
  MiniProgramShareModule,
102
+ MiniProgramSharePostOptions,
102
103
  MiniProgramShowShareMenuOptions,
103
104
  ScreenshotPayload,
104
105
  ScreenshotResult,
@@ -355,7 +356,7 @@ function resolveHmrWebSocketUrl(resolved: MiniappManifestResolvedConfig) {
355
356
 
356
357
  ## Manifest
357
358
 
358
- `@heybox/hb-sdk/vite` 提供构建时插件 `miniappManifest()`。Vite 项目完成 `vite build` 后,会在输出目录写入 `manifest.json`:
359
+ `@heybox/hb-sdk/vite` 提供构建时插件 `miniappManifest()`。项目通过 `hb-sdk build` 完成生产构建后,会在固定的 `dist/` 中写入 `manifest.json`:
359
360
 
360
361
  ```json
361
362
  {
@@ -364,7 +365,7 @@ function resolveHmrWebSocketUrl(resolved: MiniappManifestResolvedConfig) {
364
365
  }
365
366
  ```
366
367
 
367
- `version` 来自小程序项目自身的 `package.json.version`,`sdkVersion` 来自当前安装 SDK 的构建版本且不能由业务覆盖。`hb-sdk create` 生成的模板默认已注册插件;现有 Vite 项目可以在 `vite.config.ts` 中手动接入:
368
+ `version` 来自小程序项目自身的 `package.json.version`,`sdkVersion` 来自当前安装 SDK 的构建版本且不能由业务覆盖。`hb-sdk build` 要求项目显式注册这个插件;`hb-sdk create` 生成的模板默认已注册,现有 Vite 项目可以在 `vite.config.ts` 中手动接入:
368
369
 
369
370
  ```ts
370
371
  import { miniappManifest } from '@heybox/hb-sdk/vite';
@@ -382,13 +383,13 @@ export default defineConfig({
382
383
 
383
384
  插件只接受单页应用:输出目录只能存在入口 `index.html`。build 会用结构化 HTML parser 校验入口,并把平台 CSP 插入 `<head>` 首位;已有 CSP 会原样保留,两份策略按浏览器交集生效。正式策略禁止 `fetch`、XHR、WebSocket、EventSource、Beacon、Worker、iframe、表单和对象加载等浏览器原生出口;业务网络请求应使用 `network.request()`。dev 使用相同策略,只额外放行当前 Vite 的精确 HMR WebSocket 地址。
384
385
 
385
- meta refresh、外部 anchor、`dns-prefetch`、`preconnect`、`prerender`、外部资源 URL 和额外 HTML 会使 build 失败。内联 script/style 允许,但 `unsafe-eval` 不允许。`dev` 和手动 Vite build 不再请求远端最低 SDK 版本;构建仍会把当前 `sdkVersion` 写入 Manifest,`hb-sdk remote deploy` 仍校验 Manifest 结构并经过服务端 precheck / submit-audit 策略。
386
+ meta refresh、外部 anchor、`dns-prefetch`、`preconnect`、`prerender`、外部资源 URL 和额外 HTML 会使 build 失败。内联 script/style 允许,但 `unsafe-eval` 不允许。`dev`、`hb-sdk build` 和手动 Vite build 都不请求远端最低 SDK 版本;构建仍会把当前 `sdkVersion` 写入 Manifest,`hb-sdk remote deploy` 仍校验 Manifest 结构并经过服务端 precheck / submit-audit 策略。
386
387
 
387
388
  失败与警告语义:
388
389
 
389
- - 读取 `package.json` 失败或 JSON 解析失败:`vite build` 直接失败,并输出具体原因。
390
- - `package.json.version` 不是非空字符串:`vite build` 直接失败。
391
- - `package.json.version` 仍是模板默认值 `0.0.0`:`vite build` 直接失败,必须改成实际 SemVer。
390
+ - 读取 `package.json` 失败或 JSON 解析失败:build 直接失败,并输出具体原因。
391
+ - `package.json.version` 不是非空字符串:build 直接失败。
392
+ - `package.json.version` 仍是模板默认值 `0.0.0`:build 直接失败,必须改成实际 SemVer。
392
393
  - 版本号不是严格 SemVer、包含 build metadata 或缺少 `sdkVersion`:build/deploy 直接失败。
393
394
 
394
395
  `manifest.json` 不部署到 CDN,只交给发布流水线读取后上送后台;Host 通过后台 API 间接读取版本信息。第一阶段只支持 Vite 项目,非 Vite 打包器未来通过其他子入口扩展。
@@ -545,6 +546,10 @@ await share.showShareMenu({
545
546
  title: '我的小程序页面',
546
547
  desc: '来自黑盒小程序的分享',
547
548
  imageUrl: 'https://imgheybox.max-c.com/demo.png',
549
+ post: {
550
+ topicIds: [235709],
551
+ topics: ['无畏契约战绩'],
552
+ },
548
553
  });
549
554
  ```
550
555
 
@@ -552,15 +557,23 @@ await share.showShareMenu({
552
557
  `/tools/common_share?user_miniprogram_id=...` 分享落地页。只有确实要分享外部
553
558
  HTTP(S) 页面时才显式传 `url`。
554
559
 
560
+ `post` 用于给“转发到社区”预置可编辑的分区与话题。`topicIds` 接受正整数或非空字符串并按首次出现顺序去重;`topics` 只传话题内容,不要包含首尾 `#`。`showShareMenu()` 只支持一个默认分区,并且不能与 `channel` 同时使用;本地 Mock、App Dev Shell 和开发 Runtime 会直接拒绝这类错误,生产 Runtime 会过滤非法项、只取第一个分区并继续普通分享。`post: null` 等同于不配置。
561
+
555
562
  截图分享:
556
563
 
557
564
  ```ts
558
565
  await share.screenshot({
559
566
  delay: 100,
560
567
  saveToAlbum: true,
568
+ post: {
569
+ topicIds: [235709, 66739],
570
+ topics: ['无畏契约战绩'],
571
+ },
561
572
  });
562
573
  ```
563
574
 
575
+ 截图分享支持多个预置分区;分区与话题仍由用户在客户端发帖页中确认和修改,SDK 不会直接发布内容。
576
+
564
577
  ### 基础 UI
565
578
 
566
579
  ```ts
@@ -8,6 +8,7 @@
8
8
  - packages/hb-sdk/src/cli/index.ts
9
9
  - packages/hb-sdk/src/cli/commands/create.ts
10
10
  - packages/hb-sdk/src/cli/commands/dev.ts
11
+ - packages/hb-sdk/src/cli/commands/build.ts
11
12
  - packages/hb-sdk/src/cli/commands/login.ts
12
13
  - apps/docs/hb-sdk/guide/cli.md
13
14
 
@@ -17,6 +18,7 @@
17
18
  - [Command surface](#command-surface)
18
19
  - [Create a mini-program template](#create-a-mini-program-template)
19
20
  - [Local debugging](#local-debugging)
21
+ - [Production build](#production-build)
20
22
  - [Deploy and publish](#deploy-and-publish)
21
23
  - [Developer account scope](#developer-account-scope)
22
24
  - [Remote management commands](#remote-management-commands)
@@ -34,6 +36,7 @@ Use the bundled `hb-sdk` CLI to create a workshop mini-program, open the local d
34
36
  ```text
35
37
  hb-sdk create <project-name>
36
38
  hb-sdk dev [--port <port>] [--mock-port <port>] [--no-open]
39
+ hb-sdk build [--env <name>] [--verbose]
37
40
  hb-sdk login
38
41
  hb-sdk login status
39
42
  hb-sdk login clear
@@ -139,6 +142,35 @@ Dev Context 中调整的 `network.request` 权限不会修改线上配置,但
139
142
 
140
143
  Use `hb-sdk dev` to open the local debugging page. The "在 Mac 版 APP 中启动" button opens the page in the Mac App; the "Mobile App" QR code opens it in the phone App after a LAN interface is selected. These entries remain available without CLI login or project binding, but managed capabilities are denied by default. The phone and computer must be on the same LAN. If an embedded browser cannot open the App, use the system browser.
141
144
 
145
+ ## Production build
146
+
147
+ ## 生产构建
148
+
149
+ ```bash
150
+ hb-sdk build [--env <name>] [--verbose]
151
+ ```
152
+
153
+ `hb-sdk build` 直接使用项目安装的 Vite,先清理再生成固定的 `dist/`,并校验小程序入口、Manifest 和可上传产物。它不执行类型检查,不要求 CLI 登录或绑定小程序,也不访问远端服务。项目必须在 `vite.config.ts` 中显式注册 `miniappManifest()`。
154
+
155
+ 推荐由项目的 `scripts.build` 保留类型检查:
156
+
157
+ ```json
158
+ {
159
+ "scripts": {
160
+ "build": "vue-tsc --noEmit && hb-sdk build"
161
+ }
162
+ }
163
+ ```
164
+
165
+ 构建命令只支持 `--env` 和 `--verbose`。已有项目继续使用 `vite build` 仍然兼容,不会自动迁移。
166
+
167
+ Agent rules:
168
+
169
+ - Use `hb-sdk build [--env <name>] [--verbose]` as the recommended production build entry.
170
+ - Require explicit `miniappManifest()` configuration and keep typechecking in the project's `scripts.build`.
171
+ - Do not claim `hb-sdk build` needs login, binding, or network access, and do not invent unsupported build flags.
172
+ - Existing `vite build` projects remain compatible and must not be auto-migrated.
173
+
142
174
  ## Deploy and publish
143
175
 
144
176
  ## 部署发布
@@ -158,7 +190,7 @@ hb-sdk remote bind mp_xxxxxxxx
158
190
  hb-sdk remote deploy --release-note "修复登录状态展示"
159
191
  ```
160
192
 
161
- 这条命令会完成检查、构建、上传和提交审核。默认在审核通过后等待手动发布;普通低风险版本可以追加 `--auto-publish`。完整命令见 `hb-sdk remote --help`,提交要求见[小程序工坊上架规则](https://docs.xiaoheihe.cn/hb_sdk/guide/mini-program-publishing-rules)。
193
+ 这条命令会完成检查、执行项目的 `scripts.build`、上传和提交审核,因此项目定义的类型检查仍会执行。默认在审核通过后等待手动发布;普通低风险版本可以追加 `--auto-publish`。完整命令见 `hb-sdk remote --help`,提交要求见[小程序工坊上架规则](https://docs.xiaoheihe.cn/hb_sdk/guide/mini-program-publishing-rules)。
162
194
 
163
195
  Before publishing, `hb-sdk remote deploy` verifies that the bound mini-program belongs to the current developer account. If it does not, the command stops and asks the user to switch accounts.
164
196
 
@@ -9,6 +9,7 @@
9
9
  - apps/docs/hb-sdk/guide/lifecycle.md
10
10
  - apps/docs/hb-sdk/guide/error-handling.md
11
11
  - apps/docs/hb-sdk/recipes/login-gate.md
12
+ - apps/docs/hb-sdk/recipes/community-share.md
12
13
  - apps/docs/hb-sdk/recipes/custom-instance.md
13
14
 
14
15
  ## Contents
@@ -18,6 +19,7 @@
18
19
  - [Lifecycle events](#lifecycle-events)
19
20
  - [Error handling](#error-handling)
20
21
  - [Login gate recipe](#login-gate-recipe)
22
+ - [Community share recipe](#community-share-recipe)
21
23
  - [Custom instance recipe](#custom-instance-recipe)
22
24
  ## Quick start
23
25
 
@@ -355,6 +357,57 @@ async function handleSubmit() {
355
357
  - 用户主动点击登录、提交、收藏等动作时,再调用 `login`。
356
358
  - 登录态变化后,父容器应派发 `authChange`,页面可据此刷新用户相关 UI。
357
359
 
360
+ ## Community share recipe
361
+
362
+
363
+ # 社区分享预置
364
+
365
+ `share.showShareMenu()` 和 `share.screenshot()` 可以给客户端的“转发到社区”流程预置分区与话题。预置内容进入发帖页后仍可由用户修改,SDK 不会直接发布内容。
366
+
367
+ ## 普通分享
368
+
369
+ 普通分享只支持一个默认分区,并且配置 `post` 时不要同时指定站外 `channel`。
370
+
371
+ ```ts
372
+ import { ready, share } from '@heybox/hb-sdk'
373
+
374
+ await ready()
375
+
376
+ await share.showShareMenu({
377
+ title: '本局战绩',
378
+ desc: '查看我的完整战绩',
379
+ post: {
380
+ topicIds: [235709],
381
+ topics: ['无畏契约战绩'],
382
+ },
383
+ })
384
+ ```
385
+
386
+ ## 截图分享
387
+
388
+ 截图分享可以预置多个分区,客户端发帖页负责最终选择与确认。
389
+
390
+ ```ts
391
+ await share.screenshot({
392
+ delay: 100,
393
+ saveToAlbum: true,
394
+ post: {
395
+ topicIds: [235709, 66739],
396
+ topics: ['无畏契约战绩'],
397
+ },
398
+ })
399
+ ```
400
+
401
+ ## 参数边界
402
+
403
+ - `topicIds` 接受正整数或非空字符串,按首次出现顺序去重。
404
+ - `topics` 只传话题内容,不要添加首尾 `#`;字符串会先 trim 再去重。
405
+ - `post: null` 等同于不配置社区发帖预置,`post: {}` 是无效配置。
406
+ - 本地 Mock、App Dev Shell 和开发 Runtime 会对无效配置返回 `INVALID_PARAMS`。
407
+ - 生产 Runtime 会过滤无效项;普通分享只使用第一个有效分区,配置冲突时保留站外 `channel`,不会阻断原分享流程。
408
+
409
+ 调用方不能通过该 API 传客户端协议、回调、自定义按钮或发布指令。
410
+
358
411
  ## Custom instance recipe
359
412
 
360
413
 
@@ -23,7 +23,7 @@
23
23
 
24
24
  - Do not instruct mini-program code to read, extract, forward, store, or depend on token, cookie, phone number, or private credentials.
25
25
  - Negative safety statements that explain the SDK does not expose token/cookie/private credentials are correct and should be preserved.
26
- - Do not use raw share protocol fields, JS callbacks, activity reporting, post publishing, custom buttons, or upload-only flows.
26
+ - Do not use raw share protocol fields, JS callbacks, activity reporting, direct post publishing, custom buttons, or upload-only flows. Public `share.*({ post })` options only preset an editable client post flow.
27
27
  - Do not use storage delete, clear, info listing, V2, or global Heybox client storage access.
28
28
  - Do not pass host-only protocol fields through `network.request`.
29
29
  - Do not build raw `postMessage` bridge flows in iframe business code.