@heybox/hb-sdk-protocol 0.8.1-alpha.1 → 0.8.1-alpha.2

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 CHANGED
@@ -43,6 +43,12 @@ import { MINI_PROGRAM_PROTOCOL_CAPABILITIES, type MiniProgramBridgeMessage } fro
43
43
 
44
44
  协议包不决定业务授权。`auth.login()` 的 UI、账号会话、授权码签发和 OpenAPI 都由 Host/服务端负责;协议层只传递经过约束的 request/response 数据。
45
45
 
46
+ ## 握手环境快照
47
+
48
+ Runtime 可以在握手 response 中附带 `MiniProgramRuntimeEnvironmentInfo`。该快照只包含运行模式、Host App 版本、canonical 小程序 ID/版本和标准化操作系统信息,不包含账号、设备唯一标识、UA 或凭据。字段缺失和旧 Host 通过固定的 `null` / `'unknown'` 语义兼容;客户端 SDK 会在对外派发 `ready` 事件前缓存快照,业务代码通过根包的 `environment` 模块读取。
49
+
50
+ 该 response 是 v2 envelope 上的向后兼容扩展,不新增 capability method 或权限,也不提升 `MINI_PROGRAM_MESSAGE_VERSION`。旧 SDK 没有对应 pending request,会忽略该 response;新 SDK 遇到旧 Host 时生成未知值快照。
51
+
46
52
  ## 公开入口
47
53
 
48
54
  - `@heybox/hb-sdk-protocol`:本包唯一入口,适合 Host、Runtime 和协议维护代码。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heybox/hb-sdk-protocol",
3
- "version": "0.8.1-alpha.1",
3
+ "version": "0.8.1-alpha.2",
4
4
  "description": "Heybox mini-program iframe bridge wire contracts.",
5
5
  "sideEffects": false,
6
6
  "exports": {
package/src/bridge.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { MINI_PROGRAM_MESSAGE_NAMESPACE, MINI_PROGRAM_OPERATION_PROGRESS_METHOD } from './constants';
2
- import type { DownloadProgressPayload, UserInfoAuthorization } from './payloads';
2
+ import type { DownloadProgressPayload, MiniProgramRuntimeEnvironmentInfo, UserInfoAuthorization } from './payloads';
3
3
 
4
4
  export type MiniProgramBridgeMessageType = 'handshake' | 'request' | 'response' | 'event' | 'cancel';
5
5
  export type MiniProgramEventName =
@@ -22,6 +22,11 @@ export interface SDKHandshakePayload {
22
22
  userAgent: string;
23
23
  sdkVersion: string;
24
24
  }
25
+ /** Runtime 对 SDK 握手的可选扩展响应。 */
26
+ export interface SDKHandshakeResult {
27
+ /** Host 与 Runtime 归一化后的环境快照。 */
28
+ environment: MiniProgramRuntimeEnvironmentInfo;
29
+ }
25
30
  export interface RuntimeLocationProbePayload {
26
31
  probeId: string;
27
32
  timestamp: number;
package/src/payloads.ts CHANGED
@@ -134,6 +134,36 @@ export type ScreenshotPayload =
134
134
  | undefined;
135
135
  export type ScreenshotResult = unknown;
136
136
 
137
+ /** 当前小程序实例的运行模式。 */
138
+ export type MiniProgramRuntimeMode = 'production' | 'preview' | 'development' | 'unknown';
139
+
140
+ /** Host 明确提供的操作系统名称。 */
141
+ export type MiniProgramOperatingSystemName = 'android' | 'ios' | 'ohos' | 'windows' | 'macos' | 'linux' | 'unknown';
142
+
143
+ /**
144
+ * Runtime 在握手期间下发的环境快照。
145
+ *
146
+ * @remarks
147
+ * 所有字段只用于界面适配、兼容降级和诊断,不能作为鉴权、权限控制或风控依据。
148
+ * 版本字段均为不透明字符串,除缺失判断外不承诺格式或大小比较语义。
149
+ */
150
+ export interface MiniProgramRuntimeEnvironmentInfo {
151
+ readonly runtime: {
152
+ readonly mode: MiniProgramRuntimeMode;
153
+ };
154
+ readonly host: {
155
+ readonly appVersion: string | null;
156
+ };
157
+ readonly miniProgram: {
158
+ readonly id: string | null;
159
+ readonly version: string | null;
160
+ };
161
+ readonly operatingSystem: {
162
+ readonly name: MiniProgramOperatingSystemName;
163
+ readonly version: string | null;
164
+ };
165
+ }
166
+
137
167
  export interface GetStoragePayload {
138
168
  key: string;
139
169
  }
package/types/bridge.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { MINI_PROGRAM_MESSAGE_NAMESPACE, MINI_PROGRAM_OPERATION_PROGRESS_METHOD } from './constants';
2
- import type { DownloadProgressPayload, UserInfoAuthorization } from './payloads';
2
+ import type { DownloadProgressPayload, MiniProgramRuntimeEnvironmentInfo, UserInfoAuthorization } from './payloads';
3
3
  export type MiniProgramBridgeMessageType = 'handshake' | 'request' | 'response' | 'event' | 'cancel';
4
4
  export type MiniProgramEventName = 'launch' | 'ready' | 'show' | 'hide' | 'unload' | 'error' | 'heybox_app_login_change' | 'user_info_authorization_change';
5
5
  export interface MiniProgramBridgeError {
@@ -12,6 +12,11 @@ export interface SDKHandshakePayload {
12
12
  userAgent: string;
13
13
  sdkVersion: string;
14
14
  }
15
+ /** Runtime 对 SDK 握手的可选扩展响应。 */
16
+ export interface SDKHandshakeResult {
17
+ /** Host 与 Runtime 归一化后的环境快照。 */
18
+ environment: MiniProgramRuntimeEnvironmentInfo;
19
+ }
15
20
  export interface RuntimeLocationProbePayload {
16
21
  probeId: string;
17
22
  timestamp: number;
@@ -146,6 +146,33 @@ export type ScreenshotPayload = {
146
146
  post?: MiniProgramSharePostOptions | null;
147
147
  } | undefined;
148
148
  export type ScreenshotResult = unknown;
149
+ /** 当前小程序实例的运行模式。 */
150
+ export type MiniProgramRuntimeMode = 'production' | 'preview' | 'development' | 'unknown';
151
+ /** Host 明确提供的操作系统名称。 */
152
+ export type MiniProgramOperatingSystemName = 'android' | 'ios' | 'ohos' | 'windows' | 'macos' | 'linux' | 'unknown';
153
+ /**
154
+ * Runtime 在握手期间下发的环境快照。
155
+ *
156
+ * @remarks
157
+ * 所有字段只用于界面适配、兼容降级和诊断,不能作为鉴权、权限控制或风控依据。
158
+ * 版本字段均为不透明字符串,除缺失判断外不承诺格式或大小比较语义。
159
+ */
160
+ export interface MiniProgramRuntimeEnvironmentInfo {
161
+ readonly runtime: {
162
+ readonly mode: MiniProgramRuntimeMode;
163
+ };
164
+ readonly host: {
165
+ readonly appVersion: string | null;
166
+ };
167
+ readonly miniProgram: {
168
+ readonly id: string | null;
169
+ readonly version: string | null;
170
+ };
171
+ readonly operatingSystem: {
172
+ readonly name: MiniProgramOperatingSystemName;
173
+ readonly version: string | null;
174
+ };
175
+ }
149
176
  export interface GetStoragePayload {
150
177
  key: string;
151
178
  }