@heybox/hb-sdk-protocol 0.9.1-alpha.1 → 0.9.1-alpha.10
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 +17 -1
- package/dist/card-actions.cjs.js +9 -0
- package/dist/card-actions.esm.js +7 -0
- package/dist/index.cjs.js +6579 -5
- package/dist/index.esm.js +6558 -6
- package/generated/native-host-contract.json +46 -2
- package/generated/permission-catalog.json +49 -2
- package/package.json +17 -6
- package/types/index.d.ts +6390 -9
- package/types/workspace-card-actions.d.ts +7 -0
- package/src/bridge.ts +0 -196
- package/src/capabilities.ts +0 -670
- package/src/constants.ts +0 -36
- package/src/guards.ts +0 -835
- package/src/index.ts +0 -9
- package/src/local-dev-grant.ts +0 -141
- package/src/native-host-contract.generated.ts +0 -60
- package/src/native-host-contract.source.json +0 -479
- package/src/native-host.ts +0 -213
- package/src/payloads.ts +0 -1080
- package/src/permission-catalog.ts +0 -193
- package/src/permissions.ts +0 -216
- package/types/bridge.d.ts +0 -163
- package/types/capabilities.d.ts +0 -596
- package/types/constants.d.ts +0 -33
- package/types/guards.d.ts +0 -660
- package/types/local-dev-grant.d.ts +0 -63
- package/types/native-host-contract.generated.d.ts +0 -18
- package/types/native-host.d.ts +0 -147
- package/types/payloads.d.ts +0 -992
- package/types/permission-catalog.d.ts +0 -117
- package/types/permissions.d.ts +0 -159
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import type { MiniProgramBridgeMethod, MiniProgramCapabilityRisk } from './capabilities';
|
|
2
|
-
export declare const MINI_PROGRAM_PERMISSION_KEYS: readonly ["userInfo", "steamLibrary", "share", "storage", "filesystem", "clipboard", "leaderboard", "network", "companion"];
|
|
3
|
-
export type MiniProgramPermissionKey = (typeof MINI_PROGRAM_PERMISSION_KEYS)[number];
|
|
4
|
-
export type MiniProgramPermissionRequirement = {
|
|
5
|
-
readonly kind: 'none';
|
|
6
|
-
} | {
|
|
7
|
-
readonly kind: 'all';
|
|
8
|
-
readonly permissions: readonly MiniProgramPermissionKey[];
|
|
9
|
-
};
|
|
10
|
-
export type MiniProgramPermissionAccess = 'declaration' | 'platform-approval';
|
|
11
|
-
export interface MiniProgramPermissionConfigFieldDefinition {
|
|
12
|
-
readonly type: 'boolean';
|
|
13
|
-
readonly required: boolean;
|
|
14
|
-
readonly default: boolean;
|
|
15
|
-
readonly description: string;
|
|
16
|
-
}
|
|
17
|
-
export interface MiniProgramPermissionDefinition {
|
|
18
|
-
readonly key: MiniProgramPermissionKey;
|
|
19
|
-
readonly name: string;
|
|
20
|
-
readonly description: string;
|
|
21
|
-
readonly access: MiniProgramPermissionAccess;
|
|
22
|
-
readonly risk: MiniProgramCapabilityRisk;
|
|
23
|
-
readonly config: Readonly<Record<string, MiniProgramPermissionConfigFieldDefinition>>;
|
|
24
|
-
readonly methods: readonly MiniProgramBridgeMethod[];
|
|
25
|
-
readonly conditions: readonly string[];
|
|
26
|
-
}
|
|
27
|
-
export declare const MINI_PROGRAM_PERMISSION_CATALOG: readonly [{
|
|
28
|
-
readonly key: "userInfo";
|
|
29
|
-
readonly name: "用户信息";
|
|
30
|
-
readonly description: "登录小程序并读取当前用户的授权信息。";
|
|
31
|
-
readonly access: "declaration";
|
|
32
|
-
readonly risk: "medium";
|
|
33
|
-
readonly config: {};
|
|
34
|
-
readonly methods: readonly ["auth.login", "user.getInfo"];
|
|
35
|
-
readonly conditions: readonly ["继续执行黑盒登录、用户授权和可信手势规则。"];
|
|
36
|
-
}, {
|
|
37
|
-
readonly key: "steamLibrary";
|
|
38
|
-
readonly name: "Steam 游戏库";
|
|
39
|
-
readonly description: "读取当前用户授权的 Steam 游戏库。";
|
|
40
|
-
readonly access: "declaration";
|
|
41
|
-
readonly risk: "high";
|
|
42
|
-
readonly config: {};
|
|
43
|
-
readonly methods: readonly ["user.getSteamGameList"];
|
|
44
|
-
readonly conditions: readonly ["继续执行账号绑定和数据可用性规则。"];
|
|
45
|
-
}, {
|
|
46
|
-
readonly key: "share";
|
|
47
|
-
readonly name: "分享";
|
|
48
|
-
readonly description: "使用小程序分享、分享菜单和截图能力。";
|
|
49
|
-
readonly access: "declaration";
|
|
50
|
-
readonly risk: "medium";
|
|
51
|
-
readonly config: {};
|
|
52
|
-
readonly methods: readonly ["share.copyLink", "share.showShareMenu", "share.screenshot"];
|
|
53
|
-
readonly conditions: readonly ["继续执行分享参数校验和 Host 支持检查。"];
|
|
54
|
-
}, {
|
|
55
|
-
readonly key: "storage";
|
|
56
|
-
readonly name: "键值存储";
|
|
57
|
-
readonly description: "读写按小程序隔离的简单键值数据。";
|
|
58
|
-
readonly access: "declaration";
|
|
59
|
-
readonly risk: "medium";
|
|
60
|
-
readonly config: {};
|
|
61
|
-
readonly methods: readonly ["storage.getStorage", "storage.setStorage"];
|
|
62
|
-
readonly conditions: readonly ["仅用于简单键值存储,不包含文件系统。"];
|
|
63
|
-
}, {
|
|
64
|
-
readonly key: "filesystem";
|
|
65
|
-
readonly name: "文件系统";
|
|
66
|
-
readonly description: "访问小程序沙盒文件和用户选择的外部文件。";
|
|
67
|
-
readonly access: "declaration";
|
|
68
|
-
readonly risk: "high";
|
|
69
|
-
readonly config: {};
|
|
70
|
-
readonly methods: readonly ["network.download", "files.pickFiles", "files.pickDirectory", "files.saveFile", "file.create", "file.remove", "file.exists", "file.readText", "file.writeText", "file.readBytes", "file.writeBytes", "file.stat", "directory.create", "directory.remove", "directory.exists", "directory.list"];
|
|
71
|
-
readonly conditions: readonly ["外部文件继续要求有效的用户选择、会话句柄和匹配的读写模式。"];
|
|
72
|
-
}, {
|
|
73
|
-
readonly key: "clipboard";
|
|
74
|
-
readonly name: "剪贴板";
|
|
75
|
-
readonly description: "向系统剪贴板写入文本。";
|
|
76
|
-
readonly access: "declaration";
|
|
77
|
-
readonly risk: "medium";
|
|
78
|
-
readonly config: {};
|
|
79
|
-
readonly methods: readonly ["device.setClipboard"];
|
|
80
|
-
readonly conditions: readonly ["继续执行文本长度和 Host 支持限制。"];
|
|
81
|
-
}, {
|
|
82
|
-
readonly key: "leaderboard";
|
|
83
|
-
readonly name: "排行榜";
|
|
84
|
-
readonly description: "读写小程序云排行榜。";
|
|
85
|
-
readonly access: "declaration";
|
|
86
|
-
readonly risk: "medium";
|
|
87
|
-
readonly config: {};
|
|
88
|
-
readonly methods: readonly ["cloud.leaderboard.submit", "cloud.leaderboard.getList", "cloud.leaderboard.getCurrentUserEntry", "cloud.leaderboard.deleteCurrentUserEntry", "cloud.leaderboard.getInfo"];
|
|
89
|
-
readonly conditions: readonly ["排行榜必须已创建,用户和资源规则保持不变。"];
|
|
90
|
-
}, {
|
|
91
|
-
readonly key: "network";
|
|
92
|
-
readonly name: "网络";
|
|
93
|
-
readonly description: "通过 network 模块请求或下载外部资源。";
|
|
94
|
-
readonly access: "platform-approval";
|
|
95
|
-
readonly risk: "high";
|
|
96
|
-
readonly config: {
|
|
97
|
-
readonly useOfficialDomain: {
|
|
98
|
-
readonly type: "boolean";
|
|
99
|
-
readonly required: false;
|
|
100
|
-
readonly default: false;
|
|
101
|
-
readonly description: "是否申请访问小黑盒官方域名。";
|
|
102
|
-
};
|
|
103
|
-
};
|
|
104
|
-
readonly methods: readonly ["network.request", "network.download"];
|
|
105
|
-
readonly conditions: readonly ["声明后仍需平台批准,并继续执行网络安全策略。"];
|
|
106
|
-
}, {
|
|
107
|
-
readonly key: "companion";
|
|
108
|
-
readonly name: "桌面辅助应用";
|
|
109
|
-
readonly description: "下载、准备并运行随当前小程序版本发布的受管桌面程序。";
|
|
110
|
-
readonly access: "platform-approval";
|
|
111
|
-
readonly risk: "high";
|
|
112
|
-
readonly config: {};
|
|
113
|
-
readonly methods: readonly ["companion.getInfo", "companion.getPreparationStatus", "companion.prepare", "companion.cancelPreparation", "companion.getActiveSession", "companion.launch", "companion.session.write", "companion.session.closeStdin", "companion.session.terminate", "companion.session.ackOutput", "companion.openAttachment", "companion.showNotification"];
|
|
114
|
-
readonly conditions: readonly ["声明后仍需平台批准,并继续执行可信用户手势、Host 能力和当前版本 Manifest 校验。"];
|
|
115
|
-
}];
|
|
116
|
-
export declare const MINI_PROGRAM_NO_DECLARATION_METHODS: readonly ["user.revokeAuthorization", "ui.showToast", "ui.showLoading", "ui.hideLoading", "viewport.getWindowInfo", "viewport.setNavigationBarStyle", "viewport.setDisplay", "device.vibrate", "navigation.close", "navigation.reload", "navigation.openAppPage"];
|
|
117
|
-
export declare function isMiniProgramPermissionKey(key: string): key is MiniProgramPermissionKey;
|
package/types/permissions.d.ts
DELETED
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
import { type MiniProgramPermissionKey } from './permission-catalog';
|
|
2
|
-
/**
|
|
3
|
-
* 判断字符串是否是当前协议目录管理的 canonical runtime permission key。
|
|
4
|
-
*
|
|
5
|
-
* @param key - 已确认类型为 `string` 的候选权限 key;若输入来自 `unknown` 边界,调用方须先完成字符串检查。
|
|
6
|
-
* @returns 与 `MINI_PROGRAM_PERMISSION_KEYS` 中某项精确相等时返回 `true`,并将 TypeScript 类型收窄为
|
|
7
|
-
* `MiniProgramPermissionKey`;未知、历史或格式不同的字符串返回 `false`。
|
|
8
|
-
*
|
|
9
|
-
* @remarks
|
|
10
|
-
* 当前 canonical key 集合固定为:
|
|
11
|
-
*
|
|
12
|
-
* - `userInfo`
|
|
13
|
-
* - `steamLibrary`
|
|
14
|
-
* - `share`
|
|
15
|
-
* - `storage`
|
|
16
|
-
* - `filesystem`
|
|
17
|
-
* - `clipboard`
|
|
18
|
-
* - `leaderboard`
|
|
19
|
-
* - `network`
|
|
20
|
-
* - `companion`
|
|
21
|
-
*
|
|
22
|
-
* 匹配大小写敏感且按原字符串执行。该 guard 不 trim,因此 `' network '` 返回 `false`;历史权限 key
|
|
23
|
-
* `network.request` 也返回 `false`,即使同名 capability method 仍是公开 method。消费完整 schema v1 权限快照时
|
|
24
|
-
* 应使用 {@link parseMiniProgramRuntimePermissions},由解析边界统一 trim,并把历史 `network.request` 归一为
|
|
25
|
-
* canonical `network`。未知的 future key 同样返回 `false`;本 guard 不负责 parser 的前向兼容忽略策略。
|
|
26
|
-
*
|
|
27
|
-
* 类型谓词只把字符串收窄为 `MiniProgramPermissionKey` union,不读取权限 entry、status 或 config,也不检查
|
|
28
|
-
* Manifest。返回 `true` 不表示权限已声明、平台已批准、Runtime snapshot 中存在、status 为 `enabled`、Host 支持,
|
|
29
|
-
* 或当前 capability 已获准执行。尤其 `network` 与 `companion` 还需要平台批准;其他 declaration 权限也继续受
|
|
30
|
-
* 各自适用的 Host、用户授权、可信手势、参数与业务策略约束。
|
|
31
|
-
*
|
|
32
|
-
* `MINI_PROGRAM_PERMISSION_CATALOG` 提供每个 key 的展示信息、access、风险、配置字段和 method 集合;具体 bridge
|
|
33
|
-
* method 是否要求某项权限应以 {@link MINI_PROGRAM_PROTOCOL_CAPABILITIES} 的 `requirement` 为准。`kind: 'none'`
|
|
34
|
-
* 的 method 不会因为某个 key 被本 guard 识别而新增权限要求。
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* ```ts
|
|
38
|
-
* import { isManagedMiniProgramRuntimePermissionKey } from '@heybox/hb-sdk/protocol';
|
|
39
|
-
*
|
|
40
|
-
* function acceptPermissionKey(candidate: unknown) {
|
|
41
|
-
* if (typeof candidate !== 'string') return undefined;
|
|
42
|
-
* return isManagedMiniProgramRuntimePermissionKey(candidate) ? candidate : undefined;
|
|
43
|
-
* }
|
|
44
|
-
*
|
|
45
|
-
* acceptPermissionKey('filesystem'); // 'filesystem'
|
|
46
|
-
* acceptPermissionKey('network'); // 'network'
|
|
47
|
-
* acceptPermissionKey(' network '); // undefined:guard 不 trim
|
|
48
|
-
* acceptPermissionKey('network.request'); // undefined:legacy key 只由 snapshot parser 归一化
|
|
49
|
-
* ```
|
|
50
|
-
*
|
|
51
|
-
* @see [parseMiniProgramRuntimePermissions](/reference/symbols/protocol/functions/parseMiniProgramRuntimePermissions) 完整 snapshot 的 trim、legacy 归一化与 config 校验。
|
|
52
|
-
* @see [MINI_PROGRAM_PROTOCOL_CAPABILITIES](/reference/symbols/protocol/constants/MINI_PROGRAM_PROTOCOL_CAPABILITIES) method 到 permission requirement 的权威映射。
|
|
53
|
-
* @see [权限声明](/guide/permissions) Manifest 声明、平台批准与 Runtime 状态的完整流程。
|
|
54
|
-
*/
|
|
55
|
-
export declare function isManagedMiniProgramRuntimePermissionKey(key: string): key is MiniProgramPermissionKey;
|
|
56
|
-
export type MiniProgramRuntimePermissionStatus = 'enabled' | 'disabled';
|
|
57
|
-
export interface MiniProgramRuntimePermissionEntry {
|
|
58
|
-
key: MiniProgramPermissionKey;
|
|
59
|
-
status: MiniProgramRuntimePermissionStatus;
|
|
60
|
-
config: Record<string, unknown>;
|
|
61
|
-
}
|
|
62
|
-
export interface MiniProgramRuntimePermissionsSnapshot {
|
|
63
|
-
schema_version: 1;
|
|
64
|
-
revision?: number;
|
|
65
|
-
entries: MiniProgramRuntimePermissionEntry[];
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* `parseMiniProgramRuntimePermissions()` 返回的独立 canonical 视图。
|
|
69
|
-
*
|
|
70
|
-
* @remarks
|
|
71
|
-
* 结果不保留输入 snapshot、entries 或 config 的对象引用,也不包含 `schema_version`、`revision`
|
|
72
|
-
* 和未知权限。该对象不是授权决定;Runtime 还必须按 capability requirement、entry status、Host
|
|
73
|
-
* 能力和后续 policy 判断是否允许调用。
|
|
74
|
-
*/
|
|
75
|
-
export interface ParsedMiniProgramRuntimePermissions {
|
|
76
|
-
/**
|
|
77
|
-
* 整个 schema v1 snapshot 是否通过结构、重复 key 与已知 config 校验。`true` 不表示存在任何
|
|
78
|
-
* permission、任何 entry 为 `enabled`,也不表示 capability 已获授权。
|
|
79
|
-
*/
|
|
80
|
-
valid: boolean;
|
|
81
|
-
/**
|
|
82
|
-
* 仅包含当前协议认识的 canonical key。缺失 key 表示 snapshot 未声明该权限;`disabled` entry
|
|
83
|
-
* 仍会保留。`valid: false` 时该映射必为空,解析器不会暴露部分成功结果。
|
|
84
|
-
*/
|
|
85
|
-
permissions: Partial<Record<MiniProgramPermissionKey, MiniProgramRuntimePermissionEntry>>;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* 将不可信的 schema v1 runtime permission snapshot 解析为独立的 canonical 权限映射。
|
|
89
|
-
*
|
|
90
|
-
* @param snapshot - Host、服务端、dev context 或持久化边界提供的普通反序列化数据;调用方不需要先做
|
|
91
|
-
* 类型断言。Proxy trap 或 getter 自身抛出的异常会原样传播。
|
|
92
|
-
* @returns {@link ParsedMiniProgramRuntimePermissions}。完整 snapshot 合法时返回
|
|
93
|
-
* `{ valid: true, permissions }`;顶层、entry、状态、重复 key 或已知 config 任一校验失败时统一
|
|
94
|
-
* 返回 `{ valid: false, permissions: {} }`,不会保留部分权限。
|
|
95
|
-
*
|
|
96
|
-
* @remarks
|
|
97
|
-
* 顶层必须是对象,`schema_version` 必须严格等于数字 `1`,`entries` 必须是数组。`revision`
|
|
98
|
-
* 可省略;存在时必须是大于或等于 `0` 的整数。revision 只参与输入校验,不会复制到返回值。
|
|
99
|
-
* 顶层与 entry 的其他字段会被忽略,以便 schema v1 内前向扩展。
|
|
100
|
-
*
|
|
101
|
-
* 每个 entry 必须是对象,`key` 必须是 trim 后非空的字符串,`status` 必须严格为
|
|
102
|
-
* `'enabled'` 或 `'disabled'`。解析器先 trim key,再把唯一的历史别名 `network.request`
|
|
103
|
-
* 归一为 canonical `network`;大小写不会转换。重复检查基于归一化后的所有 key,因此
|
|
104
|
-
* `network` 与 ` network.request ` 冲突,两个相同未知 future key 也会让整个 snapshot fail
|
|
105
|
-
* closed。
|
|
106
|
-
*
|
|
107
|
-
* 是否属于当前受管 key 由 {@link isManagedMiniProgramRuntimePermissionKey} 与权限目录决定。
|
|
108
|
-
* 为兼容较新服务端,非空、状态合法且不重复的未知 key 会被忽略;其 `config` 可以缺失、为
|
|
109
|
-
* `null`、数组或任意未来结构,均不会使已认识的权限失效。未知 entry 不会出现在返回映射中。
|
|
110
|
-
*
|
|
111
|
-
* 已知权限严格执行当前 schema:`network` 必须提供对象 config,且
|
|
112
|
-
* `useOfficialDomain` 必须是 boolean;其他额外 network config 字段会丢弃,返回值只复制该
|
|
113
|
-
* boolean。其余当前权限是无配置项权限,输入 config 可以缺失、为 `null` 或 `{}`,并统一输出
|
|
114
|
-
* `{}`;非空对象、数组或其他值会使整个 snapshot 无效。Runtime snapshot 必须显式包含
|
|
115
|
-
* network 的有效 boolean,即使 Manifest 目录把省略 `useOfficialDomain` 的开发者默认值定义为
|
|
116
|
-
* `false`。
|
|
117
|
-
*
|
|
118
|
-
* 返回的 canonical entry/config 都是新对象;修改原 snapshot、entry 或嵌套 network config
|
|
119
|
-
* 不会改变解析结果。`permissions` 是 Partial map:合法空 entries、只包含未知权限,或没有某个
|
|
120
|
-
* canonical key 时,解析仍可 `valid: true`,对应属性保持缺失。
|
|
121
|
-
*
|
|
122
|
-
* `valid: true` 只表示 snapshot 可安全消费,不代表 entry 已启用,更不代表某个 capability 已获
|
|
123
|
-
* 授权。Runtime consumer 应先查 {@link MINI_PROGRAM_PROTOCOL_CAPABILITIES} 中目标 method 的
|
|
124
|
-
* `requirement`:`kind: 'none'` 不读取权限;`kind: 'all'` 要求列出的每个 canonical entry 都存在
|
|
125
|
-
* 且 `status === 'enabled'`。之后仍需通过 Host capability、可信手势、用户授权、参数和业务
|
|
126
|
-
* policy。当前 Runtime 对 `valid: false` 按空权限表 fail closed,受保护 method 会得到
|
|
127
|
-
* `PERMISSION_NOT_DECLARED`,而不是沿用输入中的部分 enabled entry。
|
|
128
|
-
*
|
|
129
|
-
* @example
|
|
130
|
-
* ```ts
|
|
131
|
-
* import { parseMiniProgramRuntimePermissions } from '@heybox/hb-sdk/protocol';
|
|
132
|
-
*
|
|
133
|
-
* const parsed = parseMiniProgramRuntimePermissions({
|
|
134
|
-
* schema_version: 1,
|
|
135
|
-
* revision: 4,
|
|
136
|
-
* entries: [
|
|
137
|
-
* {
|
|
138
|
-
* key: ' network.request ',
|
|
139
|
-
* status: 'enabled',
|
|
140
|
-
* config: { useOfficialDomain: false, futureField: 'discarded' },
|
|
141
|
-
* },
|
|
142
|
-
* { key: 'future.permission', status: 'disabled', config: null },
|
|
143
|
-
* ],
|
|
144
|
-
* });
|
|
145
|
-
*
|
|
146
|
-
* // legacy key 已归一化;未知 future key 被忽略。
|
|
147
|
-
* if (parsed.valid && parsed.permissions.network?.status === 'enabled') {
|
|
148
|
-
* console.log(parsed.permissions.network.config.useOfficialDomain); // false
|
|
149
|
-
* // 继续执行 capability requirement、Host 与业务 policy 校验。
|
|
150
|
-
* }
|
|
151
|
-
* ```
|
|
152
|
-
*
|
|
153
|
-
* @see {@link ParsedMiniProgramRuntimePermissions}
|
|
154
|
-
* @see {@link MiniProgramRuntimePermissionsSnapshot}
|
|
155
|
-
* @see {@link isManagedMiniProgramRuntimePermissionKey}
|
|
156
|
-
* @see {@link MINI_PROGRAM_PROTOCOL_CAPABILITIES}
|
|
157
|
-
* @see {@link https://docs.xiaoheihe.cn/hb_sdk/guide/permissions | 权限声明}
|
|
158
|
-
*/
|
|
159
|
-
export declare function parseMiniProgramRuntimePermissions(snapshot: unknown): ParsedMiniProgramRuntimePermissions;
|