@heybox/hb-sdk 0.9.9-alpha.0 → 0.9.9-alpha.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.
Files changed (37) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +2 -0
  3. package/dist/cli-chunks/{build-Vi5Zyplz.cjs → build-vZ5iT2JO.cjs} +5 -5
  4. package/dist/cli-chunks/{create-Cfz1IcYf.cjs → create-DJseFABS.cjs} +2 -2
  5. package/dist/cli-chunks/{dev-C2dtgF42.cjs → dev-CsuAVpLX.cjs} +15 -10
  6. package/dist/cli-chunks/{doctor-D-zMCLIA.cjs → doctor-BYzYg-oP.cjs} +1 -1
  7. package/dist/cli-chunks/{game-binding-guide-z3X6h8ck.cjs → game-binding-guide-BfKQ4e83.cjs} +3 -3
  8. package/dist/cli-chunks/{game-bindings-DiVP8PdD.cjs → game-bindings-DWOIBCax.cjs} +4 -4
  9. package/dist/cli-chunks/{games-THhcga6y.cjs → games-DmPaqaDd.cjs} +1 -1
  10. package/dist/cli-chunks/{index-H9U6-mLY.cjs → index-D5rcGk_z.cjs} +40 -25
  11. package/dist/cli-chunks/{index-BuYCoach.cjs → index-DPEhBPfc.cjs} +1 -1
  12. package/dist/cli-chunks/{index.esm-D8lqHXUQ.cjs → index.esm-CenYK5Bl.cjs} +72 -3
  13. package/dist/cli-chunks/{index.esm-XiyiK7eH.cjs → index.esm-DYWovNyE.cjs} +9 -9
  14. package/dist/cli-chunks/{login-Bw_1UJ8i.cjs → login-o1LQxi8P.cjs} +1 -1
  15. package/dist/cli-chunks/{project-vite-CFfq-fV7.cjs → project-vite-CGIy1XaL.cjs} +1 -1
  16. package/dist/cli-chunks/{remote-CU88U8t8.cjs → remote-BQ3O-aiB.cjs} +114 -26
  17. package/dist/cli-chunks/{runtime-permission-env-BtxzR-dv.cjs → runtime-permission-env-soFtqTxP.cjs} +24 -4
  18. package/dist/cli-chunks/{skill-7RZJxGDO.cjs → skill-BHighcnl.cjs} +2 -2
  19. package/dist/cli-chunks/{version-COTSItDf.cjs → version-CAh_EBAH.cjs} +1 -1
  20. package/dist/cli.cjs +1 -1
  21. package/dist/devtools/browser-dev-host/assets/browser-dev-host-D9CVFRHE.js +224 -0
  22. package/dist/devtools/browser-dev-host/assets/{desktop-app-launch-az2quV7I.js → desktop-app-launch-FZ3iQQs-.js} +1 -1
  23. package/dist/devtools/browser-dev-host/assets/{index-o5r5oqtq.js → index-CVzVitcL.js} +3 -3
  24. package/dist/devtools/browser-dev-host/index.html +2 -2
  25. package/dist/index.cjs.js +149 -4
  26. package/dist/index.esm.js +149 -5
  27. package/dist/miniapp-publish.cjs.js +64 -1
  28. package/dist/miniapp-publish.esm.js +63 -2
  29. package/dist/protocol.cjs.js +51 -5
  30. package/dist/protocol.esm.js +51 -5
  31. package/dist/vite.cjs.js +59 -2
  32. package/dist/vite.esm.js +59 -2
  33. package/package.json +5 -5
  34. package/skill/skill.json +4 -4
  35. package/types/index.d.ts +140 -4
  36. package/types/miniapp-publish/index.d.ts +14 -3
  37. package/dist/devtools/browser-dev-host/assets/browser-dev-host-CHdD15qt.js +0 -221
@@ -7,8 +7,8 @@
7
7
  <meta name="theme-color" content="#f4f5f7" media="(prefers-color-scheme: light)" />
8
8
  <meta name="theme-color" content="#14191e" media="(prefers-color-scheme: dark)" />
9
9
  <title>小程序工坊调试台</title>
10
- <script type="module" crossorigin src="/assets/index-o5r5oqtq.js"></script>
11
- <link rel="modulepreload" crossorigin href="/assets/desktop-app-launch-az2quV7I.js">
10
+ <script type="module" crossorigin src="/assets/index-CVzVitcL.js"></script>
11
+ <link rel="modulepreload" crossorigin href="/assets/desktop-app-launch-FZ3iQQs-.js">
12
12
  <link rel="stylesheet" crossorigin href="/assets/index-D0XGMYIr.css">
13
13
  </head>
14
14
  <body>
package/dist/index.cjs.js CHANGED
@@ -378,6 +378,105 @@ class HbMiniProgramNetworkError extends Error {
378
378
  }
379
379
  }
380
380
 
381
+ function createPostModule(client) {
382
+ const listeners = new Set();
383
+ let disposed = false;
384
+ let watching;
385
+ function startWatch() {
386
+ if (watching)
387
+ return watching;
388
+ const controller = new AbortController();
389
+ let resolveReady;
390
+ let rejectReady;
391
+ const ready = new Promise((resolve, reject) => {
392
+ resolveReady = resolve;
393
+ rejectReady = reject;
394
+ });
395
+ const state = { controller, ready };
396
+ watching = state;
397
+ // 使用可取消的长操作:SDK 销毁会立即发送 cancel,Runtime 按请求释放订阅。
398
+ void client
399
+ .requestOperation('post.watch', undefined, {
400
+ signal: controller.signal,
401
+ onProgress(progress) {
402
+ if (progress && typeof progress === 'object' && 'watching' in progress && progress.watching === true)
403
+ resolveReady();
404
+ },
405
+ })
406
+ .then(() => rejectReady(new Error('关联帖子订阅已结束')), rejectReady)
407
+ .finally(() => {
408
+ if (watching === state) {
409
+ watching = undefined;
410
+ listeners.clear();
411
+ }
412
+ });
413
+ return state;
414
+ }
415
+ const off = client.on('post_change', (event) => {
416
+ for (const listener of [...listeners]) {
417
+ try {
418
+ listener({ changed: [...event.changed] });
419
+ }
420
+ catch {
421
+ /* 单个监听者不影响其他订阅。 */
422
+ }
423
+ }
424
+ });
425
+ return {
426
+ get: () => client.request('post.get', undefined),
427
+ setLiked: (liked) => client.request('post.setLiked', { liked }),
428
+ setFavorited: (favorited) => client.request('post.setFavorited', { favorited }),
429
+ comments: {
430
+ list: (options = {}) => client.request('post.comments.list', options),
431
+ openEditor: (options = {}) => client.request('post.comments.openEditor', options),
432
+ delete: (commentId) => client.request('post.comments.delete', { commentId }),
433
+ setLiked: (options) => client.request('post.comments.setLiked', options),
434
+ },
435
+ async onChange(listener) {
436
+ if (disposed)
437
+ throw new Error('SDK 已释放');
438
+ // 每次注册独立计数,相同函数注册两次也可分别取消。
439
+ const subscription = (event) => listener(event);
440
+ listeners.add(subscription);
441
+ const state = startWatch();
442
+ try {
443
+ await state.ready;
444
+ }
445
+ catch (error) {
446
+ listeners.delete(subscription);
447
+ if (watching === state && !listeners.size) {
448
+ watching = undefined;
449
+ state.controller.abort();
450
+ }
451
+ throw error;
452
+ }
453
+ if (disposed)
454
+ throw new Error('SDK 已释放');
455
+ let cancelled = false;
456
+ return () => {
457
+ if (cancelled)
458
+ return;
459
+ cancelled = true;
460
+ listeners.delete(subscription);
461
+ if (!listeners.size && watching) {
462
+ const state = watching;
463
+ watching = undefined;
464
+ state.controller.abort();
465
+ }
466
+ };
467
+ },
468
+ dispose() {
469
+ if (disposed)
470
+ return;
471
+ disposed = true;
472
+ off();
473
+ listeners.clear();
474
+ watching?.controller.abort();
475
+ watching = undefined;
476
+ },
477
+ };
478
+ }
479
+
381
480
  /**
382
481
  * 所有小程序 iframe bridge envelope 共用的固定 namespace。
383
482
  *
@@ -515,8 +614,8 @@ const COMPANION_SHOW_NOTIFICATION_METHOD = 'companion.showNotification';
515
614
  * `code` 与字符串 `message`。该最低结构允许 `payload` 与合法 `error` 同时存在,终态语义由消费端决定。
516
615
  * - 普通 `event`(v1/v2):`method` 非空、`error` 必须为 `undefined`,`id` 可省略或为非空字符串;事件名和
517
616
  * `payload` 不在此处校验。
518
- * - `operation.progress` 与 `cancel` 只接受 v2。progress 还要求非空 `id` 和受支持的下载或 companion
519
- * prepare 进度 payload;cancel 要求非空 `id`,且 `method`、`payload`、`error` 都必须为 `undefined`。
617
+ * - `operation.progress` 与 `cancel` 只接受 v2。progress 还要求非空 `id` 和受支持的下载、companion
618
+ * prepare 或关联帖订阅就绪 payload;cancel 要求非空 `id`,且 `method`、`payload`、`error` 都必须为 `undefined`。
520
619
  *
521
620
  * 返回 `true` 只表示 wire envelope 可识别,不建立信任或授权边界。该函数不会校验
522
621
  * `MessageEvent.source` / `origin`,只检查 nonce 非空而不会与当前 iframe 的预期 nonce 比较,也不会确认
@@ -1244,7 +1343,9 @@ function isMiniProgramCompanionPrepareProgress(value) {
1244
1343
  hasOnlyKeys(value, ['phase', 'processed', 'total']));
1245
1344
  }
1246
1345
  function isMiniProgramOperationProgressPayload(value) {
1247
- return isMiniProgramDownloadProgressPayload(value) || isMiniProgramCompanionPrepareProgress(value);
1346
+ return (isMiniProgramDownloadProgressPayload(value) ||
1347
+ isMiniProgramCompanionPrepareProgress(value) ||
1348
+ (isRecord$5(value) && hasOnlyKeys(value, ['watching']) && value.watching === true));
1248
1349
  }
1249
1350
  function isSDKHandshakePayload(value) {
1250
1351
  return isRecord$5(value) && isNonEmptyString$1(value.href) && typeof value.userAgent === 'string' && isNonEmptyString$1(value.sdkVersion);
@@ -1498,6 +1599,7 @@ const MINI_PROGRAM_PERMISSION_KEYS = [
1498
1599
  'appProtocol',
1499
1600
  'workspaceCards',
1500
1601
  'user_game_data',
1602
+ 'post',
1501
1603
  ];
1502
1604
  new Set(MINI_PROGRAM_PERMISSION_KEYS);
1503
1605
 
@@ -8044,7 +8146,7 @@ function createMessageId() {
8044
8146
  /** 构建时替换为当前发布包的实际版本。 */
8045
8147
  const HB_SDK_VERSION = typeof undefined === 'string'
8046
8148
  ? undefined
8047
- : '0.9.9-alpha.0';
8149
+ : '0.9.9-alpha.1';
8048
8150
 
8049
8151
  const RUNTIME_MODES = new Set(['production', 'preview', 'development', 'unknown']);
8050
8152
  const OPERATING_SYSTEM_NAMES = new Set(['android', 'ios', 'ohos', 'windows', 'macos', 'linux', 'unknown']);
@@ -8328,6 +8430,8 @@ class MiniProgramBridgeClient {
8328
8430
  this.sendCancel(id);
8329
8431
  });
8330
8432
  this.destroyed = true;
8433
+ this.commentEditorRequestId = undefined;
8434
+ this.selfWindow?.removeEventListener('click', this.handleCommentEditorClick, true);
8331
8435
  this.selfWindow?.removeEventListener('message', this.handleMessage);
8332
8436
  this.selfWindow?.removeEventListener('popstate', this.handlePopState);
8333
8437
  this.selfWindow?.removeEventListener('hashchange', this.handleHashChange);
@@ -8495,6 +8599,22 @@ class MiniProgramBridgeClient {
8495
8599
  this.accountEventVersion += 1;
8496
8600
  this.eventBus.emit(eventName, message.payload);
8497
8601
  }
8602
+ commentEditorRequestId;
8603
+ handleCommentEditorClick = () => {
8604
+ const requestId = this.commentEditorRequestId;
8605
+ if (!requestId || this.destroyed || this.runtimeUnavailable)
8606
+ return;
8607
+ this.commentEditorRequestId = undefined;
8608
+ this.selfWindow?.removeEventListener('click', this.handleCommentEditorClick, true);
8609
+ this.postMessage({
8610
+ namespace: MINI_PROGRAM_MESSAGE_NAMESPACE,
8611
+ version: MINI_PROGRAM_MESSAGE_VERSION,
8612
+ nonce: this.nonce,
8613
+ type: 'event',
8614
+ method: 'sdk.post.editor.dismiss',
8615
+ payload: { requestId },
8616
+ });
8617
+ };
8498
8618
  handleResponse(message) {
8499
8619
  if (message.method === SDK_HANDSHAKE_METHOD && message.error === undefined) {
8500
8620
  this.eventBus.emit('workspace_cards_launch_context_change', readRecord(message.payload)?.workspaceCardLaunchContext ?? null);
@@ -8516,6 +8636,10 @@ class MiniProgramBridgeClient {
8516
8636
  pending.reject(new HbMiniProgramSDKError(message.error));
8517
8637
  return;
8518
8638
  }
8639
+ if (message.method === 'post.comments.openEditor') {
8640
+ this.commentEditorRequestId = message.id;
8641
+ this.selfWindow?.addEventListener('click', this.handleCommentEditorClick, true);
8642
+ }
8519
8643
  pending.resolve(message.payload);
8520
8644
  }
8521
8645
  handleOperationProgress(message) {
@@ -12766,6 +12890,8 @@ function createNavigationModule(requester) {
12766
12890
  * 能力调用会自动等待与父容器完成握手。
12767
12891
  */
12768
12892
  class MiniProgramSDK {
12893
+ post;
12894
+ disposePost;
12769
12895
  client;
12770
12896
  /** 工作区卡片启动上下文与显式刷新。 */
12771
12897
  workspaceCards;
@@ -12806,6 +12932,9 @@ class MiniProgramSDK {
12806
12932
  constructor(options) {
12807
12933
  const launchHref = (options?.selfWindow ?? getGlobalWindow())?.location.href;
12808
12934
  this.client = new MiniProgramBridgeClient(options);
12935
+ const post = createPostModule(this.client);
12936
+ this.post = post;
12937
+ this.disposePost = () => post.dispose();
12809
12938
  const cards = createWorkspaceCardsModule(this.client);
12810
12939
  this.workspaceCards = cards;
12811
12940
  this.disposeWorkspaceCards = cards.dispose;
@@ -12860,6 +12989,7 @@ class MiniProgramSDK {
12860
12989
  * 已销毁实例不应继续复用。
12861
12990
  */
12862
12991
  destroy() {
12992
+ this.disposePost();
12863
12993
  this.disposeWorkspaceCards();
12864
12994
  this.client.destroy();
12865
12995
  }
@@ -13355,6 +13485,19 @@ const workspaceCards = {
13355
13485
  getLaunchContext: () => getDefaultSDK().workspaceCards.getLaunchContext(),
13356
13486
  onLaunchContextChange: (listener) => getDefaultSDK().workspaceCards.onLaunchContextChange(listener),
13357
13487
  };
13488
+ /** 默认 SDK 实例的关联帖子能力。 */
13489
+ const post = {
13490
+ get: () => getDefaultSDK().post.get(),
13491
+ setLiked: (options) => getDefaultSDK().post.setLiked(options),
13492
+ setFavorited: (options) => getDefaultSDK().post.setFavorited(options),
13493
+ onChange: (listener) => getDefaultSDK().post.onChange(listener),
13494
+ comments: {
13495
+ list: options => getDefaultSDK().post.comments.list(options),
13496
+ openEditor: options => getDefaultSDK().post.comments.openEditor(options),
13497
+ delete: commentId => getDefaultSDK().post.comments.delete(commentId),
13498
+ setLiked: options => getDefaultSDK().post.comments.setLiked(options),
13499
+ },
13500
+ };
13358
13501
 
13359
13502
  const hbSDK = {
13360
13503
  getHandshakeState,
@@ -13374,6 +13517,7 @@ const hbSDK = {
13374
13517
  environment,
13375
13518
  navigation,
13376
13519
  cloud,
13520
+ post,
13377
13521
  gameSaves,
13378
13522
  companion,
13379
13523
  workspaceCards,
@@ -13398,6 +13542,7 @@ exports.network = network;
13398
13542
  exports.off = off;
13399
13543
  exports.on = on;
13400
13544
  exports.onHandshakeStateChange = onHandshakeStateChange;
13545
+ exports.post = post;
13401
13546
  exports.share = share;
13402
13547
  exports.storage = storage;
13403
13548
  exports.ui = ui;
package/dist/index.esm.js CHANGED
@@ -374,6 +374,105 @@ class HbMiniProgramNetworkError extends Error {
374
374
  }
375
375
  }
376
376
 
377
+ function createPostModule(client) {
378
+ const listeners = new Set();
379
+ let disposed = false;
380
+ let watching;
381
+ function startWatch() {
382
+ if (watching)
383
+ return watching;
384
+ const controller = new AbortController();
385
+ let resolveReady;
386
+ let rejectReady;
387
+ const ready = new Promise((resolve, reject) => {
388
+ resolveReady = resolve;
389
+ rejectReady = reject;
390
+ });
391
+ const state = { controller, ready };
392
+ watching = state;
393
+ // 使用可取消的长操作:SDK 销毁会立即发送 cancel,Runtime 按请求释放订阅。
394
+ void client
395
+ .requestOperation('post.watch', undefined, {
396
+ signal: controller.signal,
397
+ onProgress(progress) {
398
+ if (progress && typeof progress === 'object' && 'watching' in progress && progress.watching === true)
399
+ resolveReady();
400
+ },
401
+ })
402
+ .then(() => rejectReady(new Error('关联帖子订阅已结束')), rejectReady)
403
+ .finally(() => {
404
+ if (watching === state) {
405
+ watching = undefined;
406
+ listeners.clear();
407
+ }
408
+ });
409
+ return state;
410
+ }
411
+ const off = client.on('post_change', (event) => {
412
+ for (const listener of [...listeners]) {
413
+ try {
414
+ listener({ changed: [...event.changed] });
415
+ }
416
+ catch {
417
+ /* 单个监听者不影响其他订阅。 */
418
+ }
419
+ }
420
+ });
421
+ return {
422
+ get: () => client.request('post.get', undefined),
423
+ setLiked: (liked) => client.request('post.setLiked', { liked }),
424
+ setFavorited: (favorited) => client.request('post.setFavorited', { favorited }),
425
+ comments: {
426
+ list: (options = {}) => client.request('post.comments.list', options),
427
+ openEditor: (options = {}) => client.request('post.comments.openEditor', options),
428
+ delete: (commentId) => client.request('post.comments.delete', { commentId }),
429
+ setLiked: (options) => client.request('post.comments.setLiked', options),
430
+ },
431
+ async onChange(listener) {
432
+ if (disposed)
433
+ throw new Error('SDK 已释放');
434
+ // 每次注册独立计数,相同函数注册两次也可分别取消。
435
+ const subscription = (event) => listener(event);
436
+ listeners.add(subscription);
437
+ const state = startWatch();
438
+ try {
439
+ await state.ready;
440
+ }
441
+ catch (error) {
442
+ listeners.delete(subscription);
443
+ if (watching === state && !listeners.size) {
444
+ watching = undefined;
445
+ state.controller.abort();
446
+ }
447
+ throw error;
448
+ }
449
+ if (disposed)
450
+ throw new Error('SDK 已释放');
451
+ let cancelled = false;
452
+ return () => {
453
+ if (cancelled)
454
+ return;
455
+ cancelled = true;
456
+ listeners.delete(subscription);
457
+ if (!listeners.size && watching) {
458
+ const state = watching;
459
+ watching = undefined;
460
+ state.controller.abort();
461
+ }
462
+ };
463
+ },
464
+ dispose() {
465
+ if (disposed)
466
+ return;
467
+ disposed = true;
468
+ off();
469
+ listeners.clear();
470
+ watching?.controller.abort();
471
+ watching = undefined;
472
+ },
473
+ };
474
+ }
475
+
377
476
  /**
378
477
  * 所有小程序 iframe bridge envelope 共用的固定 namespace。
379
478
  *
@@ -511,8 +610,8 @@ const COMPANION_SHOW_NOTIFICATION_METHOD = 'companion.showNotification';
511
610
  * `code` 与字符串 `message`。该最低结构允许 `payload` 与合法 `error` 同时存在,终态语义由消费端决定。
512
611
  * - 普通 `event`(v1/v2):`method` 非空、`error` 必须为 `undefined`,`id` 可省略或为非空字符串;事件名和
513
612
  * `payload` 不在此处校验。
514
- * - `operation.progress` 与 `cancel` 只接受 v2。progress 还要求非空 `id` 和受支持的下载或 companion
515
- * prepare 进度 payload;cancel 要求非空 `id`,且 `method`、`payload`、`error` 都必须为 `undefined`。
613
+ * - `operation.progress` 与 `cancel` 只接受 v2。progress 还要求非空 `id` 和受支持的下载、companion
614
+ * prepare 或关联帖订阅就绪 payload;cancel 要求非空 `id`,且 `method`、`payload`、`error` 都必须为 `undefined`。
516
615
  *
517
616
  * 返回 `true` 只表示 wire envelope 可识别,不建立信任或授权边界。该函数不会校验
518
617
  * `MessageEvent.source` / `origin`,只检查 nonce 非空而不会与当前 iframe 的预期 nonce 比较,也不会确认
@@ -1240,7 +1339,9 @@ function isMiniProgramCompanionPrepareProgress(value) {
1240
1339
  hasOnlyKeys(value, ['phase', 'processed', 'total']));
1241
1340
  }
1242
1341
  function isMiniProgramOperationProgressPayload(value) {
1243
- return isMiniProgramDownloadProgressPayload(value) || isMiniProgramCompanionPrepareProgress(value);
1342
+ return (isMiniProgramDownloadProgressPayload(value) ||
1343
+ isMiniProgramCompanionPrepareProgress(value) ||
1344
+ (isRecord$5(value) && hasOnlyKeys(value, ['watching']) && value.watching === true));
1244
1345
  }
1245
1346
  function isSDKHandshakePayload(value) {
1246
1347
  return isRecord$5(value) && isNonEmptyString$1(value.href) && typeof value.userAgent === 'string' && isNonEmptyString$1(value.sdkVersion);
@@ -1494,6 +1595,7 @@ const MINI_PROGRAM_PERMISSION_KEYS = [
1494
1595
  'appProtocol',
1495
1596
  'workspaceCards',
1496
1597
  'user_game_data',
1598
+ 'post',
1497
1599
  ];
1498
1600
  new Set(MINI_PROGRAM_PERMISSION_KEYS);
1499
1601
 
@@ -8040,7 +8142,7 @@ function createMessageId() {
8040
8142
  /** 构建时替换为当前发布包的实际版本。 */
8041
8143
  const HB_SDK_VERSION = typeof undefined === 'string'
8042
8144
  ? undefined
8043
- : '0.9.9-alpha.0';
8145
+ : '0.9.9-alpha.1';
8044
8146
 
8045
8147
  const RUNTIME_MODES = new Set(['production', 'preview', 'development', 'unknown']);
8046
8148
  const OPERATING_SYSTEM_NAMES = new Set(['android', 'ios', 'ohos', 'windows', 'macos', 'linux', 'unknown']);
@@ -8324,6 +8426,8 @@ class MiniProgramBridgeClient {
8324
8426
  this.sendCancel(id);
8325
8427
  });
8326
8428
  this.destroyed = true;
8429
+ this.commentEditorRequestId = undefined;
8430
+ this.selfWindow?.removeEventListener('click', this.handleCommentEditorClick, true);
8327
8431
  this.selfWindow?.removeEventListener('message', this.handleMessage);
8328
8432
  this.selfWindow?.removeEventListener('popstate', this.handlePopState);
8329
8433
  this.selfWindow?.removeEventListener('hashchange', this.handleHashChange);
@@ -8491,6 +8595,22 @@ class MiniProgramBridgeClient {
8491
8595
  this.accountEventVersion += 1;
8492
8596
  this.eventBus.emit(eventName, message.payload);
8493
8597
  }
8598
+ commentEditorRequestId;
8599
+ handleCommentEditorClick = () => {
8600
+ const requestId = this.commentEditorRequestId;
8601
+ if (!requestId || this.destroyed || this.runtimeUnavailable)
8602
+ return;
8603
+ this.commentEditorRequestId = undefined;
8604
+ this.selfWindow?.removeEventListener('click', this.handleCommentEditorClick, true);
8605
+ this.postMessage({
8606
+ namespace: MINI_PROGRAM_MESSAGE_NAMESPACE,
8607
+ version: MINI_PROGRAM_MESSAGE_VERSION,
8608
+ nonce: this.nonce,
8609
+ type: 'event',
8610
+ method: 'sdk.post.editor.dismiss',
8611
+ payload: { requestId },
8612
+ });
8613
+ };
8494
8614
  handleResponse(message) {
8495
8615
  if (message.method === SDK_HANDSHAKE_METHOD && message.error === undefined) {
8496
8616
  this.eventBus.emit('workspace_cards_launch_context_change', readRecord(message.payload)?.workspaceCardLaunchContext ?? null);
@@ -8512,6 +8632,10 @@ class MiniProgramBridgeClient {
8512
8632
  pending.reject(new HbMiniProgramSDKError(message.error));
8513
8633
  return;
8514
8634
  }
8635
+ if (message.method === 'post.comments.openEditor') {
8636
+ this.commentEditorRequestId = message.id;
8637
+ this.selfWindow?.addEventListener('click', this.handleCommentEditorClick, true);
8638
+ }
8515
8639
  pending.resolve(message.payload);
8516
8640
  }
8517
8641
  handleOperationProgress(message) {
@@ -12762,6 +12886,8 @@ function createNavigationModule(requester) {
12762
12886
  * 能力调用会自动等待与父容器完成握手。
12763
12887
  */
12764
12888
  class MiniProgramSDK {
12889
+ post;
12890
+ disposePost;
12765
12891
  client;
12766
12892
  /** 工作区卡片启动上下文与显式刷新。 */
12767
12893
  workspaceCards;
@@ -12802,6 +12928,9 @@ class MiniProgramSDK {
12802
12928
  constructor(options) {
12803
12929
  const launchHref = (options?.selfWindow ?? getGlobalWindow())?.location.href;
12804
12930
  this.client = new MiniProgramBridgeClient(options);
12931
+ const post = createPostModule(this.client);
12932
+ this.post = post;
12933
+ this.disposePost = () => post.dispose();
12805
12934
  const cards = createWorkspaceCardsModule(this.client);
12806
12935
  this.workspaceCards = cards;
12807
12936
  this.disposeWorkspaceCards = cards.dispose;
@@ -12856,6 +12985,7 @@ class MiniProgramSDK {
12856
12985
  * 已销毁实例不应继续复用。
12857
12986
  */
12858
12987
  destroy() {
12988
+ this.disposePost();
12859
12989
  this.disposeWorkspaceCards();
12860
12990
  this.client.destroy();
12861
12991
  }
@@ -13351,6 +13481,19 @@ const workspaceCards = {
13351
13481
  getLaunchContext: () => getDefaultSDK().workspaceCards.getLaunchContext(),
13352
13482
  onLaunchContextChange: (listener) => getDefaultSDK().workspaceCards.onLaunchContextChange(listener),
13353
13483
  };
13484
+ /** 默认 SDK 实例的关联帖子能力。 */
13485
+ const post = {
13486
+ get: () => getDefaultSDK().post.get(),
13487
+ setLiked: (options) => getDefaultSDK().post.setLiked(options),
13488
+ setFavorited: (options) => getDefaultSDK().post.setFavorited(options),
13489
+ onChange: (listener) => getDefaultSDK().post.onChange(listener),
13490
+ comments: {
13491
+ list: options => getDefaultSDK().post.comments.list(options),
13492
+ openEditor: options => getDefaultSDK().post.comments.openEditor(options),
13493
+ delete: commentId => getDefaultSDK().post.comments.delete(commentId),
13494
+ setLiked: options => getDefaultSDK().post.comments.setLiked(options),
13495
+ },
13496
+ };
13354
13497
 
13355
13498
  const hbSDK = {
13356
13499
  getHandshakeState,
@@ -13370,9 +13513,10 @@ const hbSDK = {
13370
13513
  environment,
13371
13514
  navigation,
13372
13515
  cloud,
13516
+ post,
13373
13517
  gameSaves,
13374
13518
  companion,
13375
13519
  workspaceCards,
13376
13520
  };
13377
13521
 
13378
- export { AuthorFollowStatus, HbMiniProgramNetworkError, HbMiniProgramSDKError, USER_INFO_AUTHORIZATION_SCOPES, auth, cloud, companion, hbSDK as default, device, environment, files, gameSaves, getHandshakeState, media, navigation, network, off, on, onHandshakeStateChange, share, storage, ui, user, viewport, workspaceCards };
13522
+ export { AuthorFollowStatus, HbMiniProgramNetworkError, HbMiniProgramSDKError, USER_INFO_AUTHORIZATION_SCOPES, auth, cloud, companion, hbSDK as default, device, environment, files, gameSaves, getHandshakeState, media, navigation, network, off, on, onHandshakeStateChange, post, share, storage, ui, user, viewport, workspaceCards };
@@ -7,6 +7,19 @@
7
7
  * 并在 origin 可以固定且协议模式要求时校验 origin。
8
8
  */
9
9
 
10
+ const POST_READ_METHODS = [
11
+ 'post.get',
12
+ 'post.comments.list',
13
+ 'post.watch',
14
+ ];
15
+ const POST_WRITE_METHODS = [
16
+ 'post.setLiked',
17
+ 'post.setFavorited',
18
+ 'post.comments.openEditor',
19
+ 'post.comments.delete',
20
+ 'post.comments.setLiked',
21
+ ];
22
+
10
23
  /** 游戏资料内部 wire:业务方法由 SDK 映射为精确资源请求。 */
11
24
  const USER_GAMES_GET_OVERVIEW_METHOD = 'user.games.getOverview';
12
25
  const USER_DATA_QUERY_METHOD = 'user.data.query';
@@ -117,6 +130,20 @@ const COMPANION_SHOW_NOTIFICATION_METHOD = 'companion.showNotification';
117
130
  * 仅表示无需 Manifest 权限声明,不表示绕过参数校验、Host 能力、可信手势或业务策略。
118
131
  */
119
132
  [
133
+ ...POST_READ_METHODS.map((method) => ({
134
+ method,
135
+ module: 'post',
136
+ capability: method,
137
+ requirement: { kind: 'all', permissions: ['post'] },
138
+ risk: 'medium',
139
+ })),
140
+ ...POST_WRITE_METHODS.map((method) => ({
141
+ method,
142
+ module: 'post',
143
+ capability: method,
144
+ requirement: { kind: 'all', permissions: ['post'] },
145
+ risk: 'high',
146
+ })),
120
147
  ...[GAME_SAVES_LIST_METHOD, GAME_SAVES_SYNC_METHOD, GAME_SAVES_GET_FILE_METHOD, GAME_SAVES_READ_PARSED_DATA_METHOD].map((method) => ({
121
148
  method,
122
149
  module: 'gameSaves',
@@ -209,7 +236,13 @@ const COMPANION_SHOW_NOTIFICATION_METHOD = 'companion.showNotification';
209
236
  requirement: { kind: 'all', permissions: ['share'] },
210
237
  risk: 'medium',
211
238
  },
212
- { method: SHARE_SCREENSHOT_LONG_METHOD, module: 'share', capability: SHARE_SCREENSHOT_LONG_METHOD, requirement: { kind: 'all', permissions: ['share'] }, risk: 'medium' },
239
+ {
240
+ method: SHARE_SCREENSHOT_LONG_METHOD,
241
+ module: 'share',
242
+ capability: SHARE_SCREENSHOT_LONG_METHOD,
243
+ requirement: { kind: 'all', permissions: ['share'] },
244
+ risk: 'medium',
245
+ },
213
246
  {
214
247
  method: VIEWPORT_GET_WINDOW_INFO_METHOD,
215
248
  module: 'viewport',
@@ -678,6 +711,7 @@ const MINI_PROGRAM_PERMISSION_KEYS = [
678
711
  'appProtocol',
679
712
  'workspaceCards',
680
713
  'user_game_data',
714
+ 'post',
681
715
  ];
682
716
  const MINI_PROGRAM_PERMISSION_CATALOG = [
683
717
  {
@@ -886,6 +920,19 @@ const MINI_PROGRAM_PERMISSION_CATALOG = [
886
920
  '平台取数不授予小程序 `network` 权限;已交付的数据副本无法撤回。',
887
921
  ],
888
922
  },
923
+ {
924
+ key: 'post',
925
+ name: '关联帖子',
926
+ description: '读取关联帖子与评论,或以当前用户身份互动并打开社区原生编辑器。',
927
+ access: 'declaration',
928
+ risk: 'high',
929
+ config: {
930
+ read: { type: 'boolean', required: false, default: false, description: '读取帖子、评论和订阅变化。' },
931
+ write: { type: 'boolean', required: false, default: false, description: '点赞、收藏、删除评论及打开社区原生编辑器。' },
932
+ },
933
+ methods: [...POST_READ_METHODS, ...POST_WRITE_METHODS],
934
+ conditions: ['显式声明 read / write,省略时为 false;写操作须由用户明确触发,继续执行社区审核和权限校验。'],
935
+ },
889
936
  ];
890
937
  new Set(MINI_PROGRAM_PERMISSION_KEYS);
891
938
 
@@ -10543,6 +10590,16 @@ function parseMiniappPermissions(value, options) {
10543
10590
  }
10544
10591
  useOfficialDomain = declaration.useOfficialDomain === true;
10545
10592
  }
10593
+ if (key === 'post') {
10594
+ for (const field of ['read', 'write']) {
10595
+ if (declaration[field] !== undefined && typeof declaration[field] !== 'boolean') {
10596
+ throw new Error(`${itemLabel}.${field} 必须是 boolean`);
10597
+ }
10598
+ }
10599
+ if (declaration.enabled)
10600
+ permissions.post = { enabled: true, read: declaration.read === true, write: declaration.write === true };
10601
+ continue;
10602
+ }
10546
10603
  if (key === 'user_game_data') {
10547
10604
  // 即使声明关闭也校验资源清单:enabled:false 不能隐藏非法字段。
10548
10605
  const resources = parseUserGameDataResources(declaration.resources, itemLabel);
@@ -19428,6 +19485,10 @@ const LIST_USER_MINIPROGRAM_API_PATH = '/mall/developer/user_miniprogram/list';
19428
19485
  const CREATE_USER_MINIPROGRAM_API_PATH = '/mall/developer/user_miniprogram/create';
19429
19486
  /** 查询单个小程序详情的开放平台 API 路径。 */
19430
19487
  const DETAIL_USER_MINIPROGRAM_API_PATH = '/mall/developer/user_miniprogram/detail';
19488
+ /** 查询和更新小程序关联帖子的开放平台 API 路径。 */
19489
+ const USER_MINIPROGRAM_POST_BINDING_API_PATH = '/mall/developer/user_miniprogram/post/binding';
19490
+ /** 校验并预览待关联的帖子。 */
19491
+ const USER_MINIPROGRAM_POST_PREVIEW_API_PATH = '/mall/developer/user_miniprogram/post/preview';
19431
19492
  /** 创建本地开发启动凭据的开放平台 API 路径。 */
19432
19493
  const CREATE_USER_MINIPROGRAM_LOCAL_DEV_LAUNCH_TOKEN_API_PATH = '/mall/developer/user_miniprogram/local_dev_launch_token';
19433
19494
  /** 查询小程序预览白名单的开放平台 API 路径。 */
@@ -20113,6 +20174,8 @@ exports.TAKE_DOWN_USER_MINIPROGRAM_API_PATH = TAKE_DOWN_USER_MINIPROGRAM_API_PAT
20113
20174
  exports.UPDATE_SQUARE_DISPLAY_API_PATH = UPDATE_SQUARE_DISPLAY_API_PATH;
20114
20175
  exports.UPDATE_USER_MINIPROGRAM_PREVIEW_ALLOWLIST_API_PATH = UPDATE_USER_MINIPROGRAM_PREVIEW_ALLOWLIST_API_PATH;
20115
20176
  exports.USER_MINIPROGRAM_ACCESS_STATUS_API_PATH = USER_MINIPROGRAM_ACCESS_STATUS_API_PATH;
20177
+ exports.USER_MINIPROGRAM_POST_BINDING_API_PATH = USER_MINIPROGRAM_POST_BINDING_API_PATH;
20178
+ exports.USER_MINIPROGRAM_POST_PREVIEW_API_PATH = USER_MINIPROGRAM_POST_PREVIEW_API_PATH;
20116
20179
  exports.USER_MINIPROGRAM_PREVIEW_ALLOWLIST_API_PATH = USER_MINIPROGRAM_PREVIEW_ALLOWLIST_API_PATH;
20117
20180
  exports.USER_MINIPROGRAM_VERSION_PREVIEW_INFO_API_PATH = USER_MINIPROGRAM_VERSION_PREVIEW_INFO_API_PATH;
20118
20181
  exports.WITHDRAW_USER_MINIPROGRAM_VERSION_API_PATH = WITHDRAW_USER_MINIPROGRAM_VERSION_API_PATH;