@heybox/hb-sdk 0.6.6-alpha.2 → 0.6.6-alpha.4

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 (37) hide show
  1. package/README.md +44 -7
  2. package/dist/cli-chunks/build-C54stoRf.cjs +142 -0
  3. package/dist/cli-chunks/context-DvTynj3F.cjs +410 -0
  4. package/dist/cli-chunks/{create-CxjB3oSo.cjs → create-uQS30kS_.cjs} +1 -1
  5. package/dist/cli-chunks/{dev-Km0or0yY.cjs → dev-1wE8dNiL.cjs} +29 -149
  6. package/dist/cli-chunks/{doctor-baVOqNSh.cjs → doctor-B2aCUOQ7.cjs} +1 -1
  7. package/dist/cli-chunks/{index-ByDy5HXi.cjs → index-19i3Dr5H.cjs} +32 -16
  8. package/dist/cli-chunks/{index-DCsEAuca.cjs → index-DypVMqsr.cjs} +3 -3
  9. package/dist/cli-chunks/{login-fNe0eDs_.cjs → login-BIIUGwoq.cjs} +2 -2
  10. package/dist/cli-chunks/project-vite-Dl3OoQjL.cjs +45 -0
  11. package/dist/cli-chunks/remote-47MjCKhu.cjs +1522 -0
  12. package/dist/cli-chunks/{remote-BRIlRrCG.cjs → runtime-gate--rPXjiG6.cjs} +7 -1501
  13. package/dist/cli-chunks/{context-CM46YbPT.cjs → runtime-permission-env-BSs4uCNa.cjs} +75 -293
  14. package/dist/cli-chunks/{session-CTcelATz.cjs → session-DJEuhrgq.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 +68 -4
  22. package/dist/vite.esm.js +68 -4
  23. package/package.json +2 -2
  24. package/skill/SKILL.md +19 -14
  25. package/skill/references/api-protocol.md +3 -2
  26. package/skill/references/api-root.md +57 -11
  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
  35. package/types/vite/html-policy.d.ts +5 -1
  36. package/types/vite/index.d.ts +10 -1
  37. package/types/vite/runtime-permission-env.d.ts +9 -0
@@ -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.
@@ -207,6 +207,7 @@ const authGuide = frontmatterless(read('apps/docs/hb-sdk/guide/auth.md'));
207
207
  const lifecycleGuide = frontmatterless(read('apps/docs/hb-sdk/guide/lifecycle.md'));
208
208
  const errorGuide = frontmatterless(read('apps/docs/hb-sdk/guide/error-handling.md'));
209
209
  const loginGate = frontmatterless(read('apps/docs/hb-sdk/recipes/login-gate.md'));
210
+ const communityShare = frontmatterless(read('apps/docs/hb-sdk/recipes/community-share.md'));
210
211
  const customInstance = frontmatterless(read('apps/docs/hb-sdk/recipes/custom-instance.md'));
211
212
  const referenceHome = frontmatterless(read('apps/docs/hb-sdk/reference/index.md'));
212
213
  const quickStartSection = extractSection(readme, '## 快速开始');
@@ -220,6 +221,7 @@ const manifestSection = extractSection(readme, '## Manifest');
220
221
  const cliSummarySection = extractSection(readme, '## CLI');
221
222
  const cliCreateSection = extractSection(cliGuide, '## 创建工坊小程序');
222
223
  const cliDevSection = extractSection(cliGuide, '## 推荐调试流程');
224
+ const cliBuildSection = extractSection(cliGuide, '## 生产构建');
223
225
  const cliDeploySection = extractSection(cliGuide, '## 部署发布');
224
226
  const cliRemoteSection = extractSection(cliGuide, '## 远端管理命令');
225
227
  const cliLoginSection = extractSection(cliGuide, '## CLI 登录态');
@@ -227,6 +229,7 @@ const cliDoctorSection = extractSection(cliGuide, '## Agent Skill doctor');
227
229
  const cliUpdateSection = extractSection(cliGuide, '## 版本提醒');
228
230
  const cliCommandSurface = `hb-sdk create <project-name>
229
231
  hb-sdk dev [--port <port>] [--mock-port <port>] [--no-open]
232
+ hb-sdk build [--env <name>] [--verbose]
230
233
  hb-sdk login
231
234
  hb-sdk login status
232
235
  hb-sdk login clear
@@ -344,6 +347,7 @@ files.set('cli.md', `${header('CLI reference', [
344
347
  'packages/hb-sdk/src/cli/index.ts',
345
348
  'packages/hb-sdk/src/cli/commands/create.ts',
346
349
  'packages/hb-sdk/src/cli/commands/dev.ts',
350
+ 'packages/hb-sdk/src/cli/commands/build.ts',
347
351
  'packages/hb-sdk/src/cli/commands/login.ts',
348
352
  'apps/docs/hb-sdk/guide/cli.md',
349
353
  ])}${contents([
@@ -351,6 +355,7 @@ files.set('cli.md', `${header('CLI reference', [
351
355
  ['Command surface', 'command-surface'],
352
356
  ['Create a mini-program template', 'create-a-mini-program-template'],
353
357
  ['Local debugging', 'local-debugging'],
358
+ ['Production build', 'production-build'],
354
359
  ['Deploy and publish', 'deploy-and-publish'],
355
360
  ['Developer account scope', 'developer-account-scope'],
356
361
  ['Remote management commands', 'remote-management-commands'],
@@ -386,6 +391,17 @@ ${cliDevSection}
386
391
 
387
392
  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.
388
393
 
394
+ ## Production build
395
+
396
+ ${cliBuildSection}
397
+
398
+ Agent rules:
399
+
400
+ - Use \`hb-sdk build [--env <name>] [--verbose]\` as the recommended production build entry.
401
+ - Require explicit \`miniappManifest()\` configuration and keep typechecking in the project's \`scripts.build\`.
402
+ - Do not claim \`hb-sdk build\` needs login, binding, or network access, and do not invent unsupported build flags.
403
+ - Existing \`vite build\` projects remain compatible and must not be auto-migrated.
404
+
389
405
  ## Deploy and publish
390
406
 
391
407
  ${rewriteBundledCliLinks(cliDeploySection)}
@@ -462,6 +478,7 @@ files.set('recipes.md', `${header('Recipes', [
462
478
  'apps/docs/hb-sdk/guide/lifecycle.md',
463
479
  'apps/docs/hb-sdk/guide/error-handling.md',
464
480
  'apps/docs/hb-sdk/recipes/login-gate.md',
481
+ 'apps/docs/hb-sdk/recipes/community-share.md',
465
482
  'apps/docs/hb-sdk/recipes/custom-instance.md',
466
483
  ])}${contents([
467
484
  ['Quick start', 'quick-start'],
@@ -469,6 +486,7 @@ files.set('recipes.md', `${header('Recipes', [
469
486
  ['Lifecycle events', 'lifecycle-events'],
470
487
  ['Error handling', 'error-handling'],
471
488
  ['Login gate recipe', 'login-gate-recipe'],
489
+ ['Community share recipe', 'community-share-recipe'],
472
490
  ['Custom instance recipe', 'custom-instance-recipe'],
473
491
  ])}## Quick start
474
492
 
@@ -490,6 +508,10 @@ ${rewriteBundledRecipeLinks(errorGuide)}
490
508
 
491
509
  ${rewriteBundledRecipeLinks(loginGate)}
492
510
 
511
+ ## Community share recipe
512
+
513
+ ${rewriteBundledRecipeLinks(communityShare)}
514
+
493
515
  ## Custom instance recipe
494
516
 
495
517
  ${rewriteBundledRecipeLinks(customInstance)}
@@ -506,7 +528,7 @@ ${capabilityBoundaries}
506
528
 
507
529
  - Do not instruct mini-program code to read, extract, forward, store, or depend on token, cookie, phone number, or private credentials.
508
530
  - Negative safety statements that explain the SDK does not expose token/cookie/private credentials are correct and should be preserved.
509
- - Do not use raw share protocol fields, JS callbacks, activity reporting, post publishing, custom buttons, or upload-only flows.
531
+ - 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.
510
532
  - Do not use storage delete, clear, info listing, V2, or global Heybox client storage access.
511
533
  - Do not pass host-only protocol fields through \`network.request\`.
512
534
  - Do not build raw \`postMessage\` bridge flows in iframe business code.
package/skill/skill.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "hb-sdk",
3
- "skillVersion": "0.6.6-alpha.2+skill.1b5ff79af27f",
3
+ "skillVersion": "0.6.6-alpha.4+skill.849ac4dd68e1",
4
4
  "sdk": {
5
5
  "package": "@heybox/hb-sdk",
6
- "version": "0.6.6-alpha.2",
7
- "compatibility": "0.6.6-alpha.2"
6
+ "version": "0.6.6-alpha.4",
7
+ "compatibility": "0.6.6-alpha.4"
8
8
  },
9
9
  "source": "https://open.xiaoheihe.cn/agent-skills/hb-sdk",
10
- "integrity": "sha256-1b5ff79af27f9af02b914553b6e7324f66543861cce638c526c9158586ed5fb5"
10
+ "integrity": "sha256-849ac4dd68e1d39c13e686809d6a4e9c1bcfd90fbac899b45f43bd364db1fc68"
11
11
  }
package/types/index.d.ts CHANGED
@@ -4,7 +4,7 @@ export type { MiniProgramEventHandler, MiniProgramEventName, MiniProgramEventPay
4
4
  export type { LoginPayload, LoginResult, MiniProgramAuthModule } from './modules/auth';
5
5
  export type { DeleteCurrentUserLeaderboardEntryPayload, DeleteCurrentUserLeaderboardEntryResult, GetCurrentUserLeaderboardEntryPayload, GetCurrentUserLeaderboardEntryResult, GetLeaderboardInfoPayload, GetLeaderboardInfoResult, GetLeaderboardListPayload, GetLeaderboardListResult, LeaderboardEntry, LeaderboardOrder, MiniProgramCloudLeaderboardModule, MiniProgramCloudModule, SubmitLeaderboardEntryPayload, SubmitLeaderboardEntryResult, } from './modules/cloud';
6
6
  export type { BasePlatformAccountInfo, CurrentUserAvatarConfig, CurrentUserAvatarDecoration, CurrentUserBbsInfo, CurrentUserDetail, CurrentUserLevelInfo, CurrentUserMedal, CurrentUserProfile, EpicPlatformAccountInfo, GetCurrentUserDetailPayload, GetCurrentUserDetailResult, GetCurrentUserProfilePayload, GetCurrentUserProfileResult, GetPlatformAccountInfoPayload, GetPlatformAccountInfoResult, GetPlatformAccountOverviewPayload, GetPlatformAccountOverviewResult, GetSteamGameListOptions, GetSteamGameListPayload, GetSteamGameListResult, GetUserInfoPayload, GetUserInfoResult, MiniProgramUserInfo, MiniProgramUserInfoResult, MiniProgramUserModule, MobilePlatformAccountInfo, PcHardwareAccountInfo, PlatformAccountInfoMap, PlatformAccountOverview, PlatformAccountResult, PlatformAccountType, PlatformStatItem, PsnPlatformAccountInfo, SteamGameListData, SteamGameListItem, SteamGameListSort, SteamGamePrice, SteamPlatformAccountInfo, SwitchPlatformAccountInfo, UserScopedResult, XboxPlatformAccountInfo, } from './modules/user';
7
- export type { MiniProgramScreenshotOptions, MiniProgramScreenshotRect, MiniProgramShareChannel, MiniProgramShareModule, MiniProgramShowShareMenuOptions, ScreenshotPayload, ScreenshotResult, ShowShareMenuPayload, ShowShareMenuResult, } from './modules/share';
7
+ export type { MiniProgramScreenshotOptions, MiniProgramScreenshotRect, MiniProgramShareChannel, MiniProgramShareModule, MiniProgramSharePostOptions, MiniProgramShowShareMenuOptions, ScreenshotPayload, ScreenshotResult, ShowShareMenuPayload, ShowShareMenuResult, } from './modules/share';
8
8
  export type { GetWindowInfoPayload, GetWindowInfoResult, MiniProgramNavigationBarForegroundStyle, MiniProgramSafeArea, MiniProgramSetNavigationBarStyleOptions, MiniProgramViewportModule, MiniProgramWindowInfoResult, SetNavigationBarStylePayload, SetNavigationBarStyleResult, } from './modules/viewport';
9
9
  export type { GetStoragePayload, GetStorageResult, MiniProgramStorageModule, SetStoragePayload, } from './modules/storage';
10
10
  export type { MiniProgramNetworkHeaders, MiniProgramNetworkModule, MiniProgramNetworkParams, MiniProgramNetworkRequestConfig, MiniProgramNetworkRequestMethod, MiniProgramNetworkResponse, MiniProgramNetworkValidateStatus, NetworkRequestPayload, NetworkResponsePayload, } from './modules/network';
@@ -5,6 +5,13 @@
5
5
  * 不同宿主环境可支持的渠道集合可能不同;未传 `channel` 时由客户端自行展示默认分享面板。
6
6
  */
7
7
  export type MiniProgramShareChannel = 'wechatSession' | 'wechatTimeline' | 'qqFriend' | 'qzone' | 'weibo';
8
+ /** 社区发帖预置配置。 */
9
+ export interface MiniProgramSharePostOptions {
10
+ /** 默认发布分区 ID;普通分享只使用第一项,截图分享支持多项。 */
11
+ topicIds?: (string | number)[];
12
+ /** 预置话题内容,不包含首尾 `#`。 */
13
+ topics?: string[];
14
+ }
8
15
  /**
9
16
  * 展示基础分享面板的配置。
10
17
  *
@@ -22,6 +29,8 @@ export interface MiniProgramShowShareMenuOptions {
22
29
  imageUrl?: string;
23
30
  /** 指定分享渠道;不传则由客户端展示默认分享面板。 */
24
31
  channel?: MiniProgramShareChannel;
32
+ /** 转发到社区时使用的分区与话题预置;`null` 等同于不配置。 */
33
+ post?: MiniProgramSharePostOptions | null;
25
34
  }
26
35
  /**
27
36
  * 截图区域。
@@ -52,4 +61,6 @@ export interface MiniProgramScreenshotOptions {
52
61
  delay?: number;
53
62
  /** 是否展示保存到相册能力。 */
54
63
  saveToAlbum?: boolean;
64
+ /** 转发到社区时使用的分区与话题预置;`null` 等同于不配置。 */
65
+ post?: MiniProgramSharePostOptions | null;
55
66
  }
@@ -10,7 +10,7 @@ export type { DeleteCurrentUserLeaderboardEntryPayload, DeleteCurrentUserLeaderb
10
10
  export type { GetCurrentUserDetailPayload, GetCurrentUserDetailResult, GetCurrentUserProfilePayload, GetCurrentUserProfileResult, GetPlatformAccountInfoPayload, GetPlatformAccountInfoResult, GetPlatformAccountOverviewPayload, GetPlatformAccountOverviewResult, GetSteamGameListOptions, GetSteamGameListPayload, GetSteamGameListResult, GetUserInfoPayload, GetUserInfoResult, MiniProgramUserInfo, MiniProgramUserInfoResult, SteamGameListData, SteamGameListItem, SteamGameListSort, SteamGamePrice, } from './modules/user';
11
11
  export type { ScreenshotPayload, ScreenshotResult } from './modules/share/screenshot';
12
12
  export type { ShowShareMenuPayload, ShowShareMenuResult } from './modules/share/show-share-menu';
13
- export type { MiniProgramScreenshotOptions, MiniProgramScreenshotRect, MiniProgramShareChannel, MiniProgramShowShareMenuOptions, } from './modules/share';
13
+ export type { MiniProgramScreenshotOptions, MiniProgramScreenshotRect, MiniProgramShareChannel, MiniProgramSharePostOptions, MiniProgramShowShareMenuOptions, } from './modules/share';
14
14
  export type { GetStoragePayload, GetStorageResult, SetStoragePayload } from './modules/storage';
15
15
  export type { GetWindowInfoPayload, GetWindowInfoResult, MiniProgramNavigationBarForegroundStyle, MiniProgramSafeArea, MiniProgramSetNavigationBarStyleOptions, MiniProgramWindowInfoResult, SetNavigationBarStylePayload, SetNavigationBarStyleResult, } from './modules/viewport';
16
16
  export type { MiniProgramNetworkHeaders, MiniProgramNetworkParams, MiniProgramNetworkRequestConfig, MiniProgramNetworkRequestMethod, MiniProgramNetworkResponse, MiniProgramNetworkValidateStatus, NetworkRequestPayload, NetworkResponsePayload, } from './modules/network';
@@ -1 +1,5 @@
1
- export declare function enforceMiniappHtmlPolicy(html: string): string;
1
+ export declare const PRODUCTION_CSP: string;
2
+ export declare function enforceMiniappHtmlPolicy(html: string, options?: {
3
+ hmrWebSocketUrl?: string;
4
+ skipPlatformCsp?: boolean;
5
+ }): string;
@@ -20,7 +20,16 @@ interface MiniappManifestResolvedConfig {
20
20
  build: {
21
21
  outDir: string;
22
22
  };
23
- server: Record<string, unknown>;
23
+ server: {
24
+ host?: string | boolean;
25
+ port?: number;
26
+ hmr?: boolean | {
27
+ clientPort?: number;
28
+ host?: string;
29
+ port?: number;
30
+ protocol?: 'ws' | 'wss';
31
+ };
32
+ };
24
33
  }
25
34
  export declare function miniappManifest(): MiniappManifestPlugin;
26
35
  export {};
@@ -0,0 +1,9 @@
1
+ export declare const HB_SDK_RUNTIME_USE_OFFICIAL_DOMAIN_ENV = "HB_SDK_RUNTIME_USE_OFFICIAL_DOMAIN";
2
+ export declare const HB_SDK_RUNTIME_PERMISSION_CONTEXT_ENV = "HB_SDK_RUNTIME_PERMISSION_CONTEXT";
3
+ export declare function shouldSkipMiniappPlatformCspFromEnv(env?: NodeJS.ProcessEnv): boolean;
4
+ export declare function createMiniappPlatformCspEnv(env: NodeJS.ProcessEnv, skipPlatformCsp: boolean): {
5
+ HB_SDK_RUNTIME_PERMISSION_CONTEXT: string;
6
+ HB_SDK_RUNTIME_USE_OFFICIAL_DOMAIN: string;
7
+ TZ?: string | undefined;
8
+ };
9
+ export declare function withMiniappPlatformCspEnv<T>(skipPlatformCsp: boolean, action: () => Promise<T>, env?: NodeJS.ProcessEnv): Promise<T>;