@heybox/hb-sdk-protocol 0.9.1-alpha.1 → 0.9.1-alpha.11
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,63 +0,0 @@
|
|
|
1
|
-
import { type MiniProgramPermissionKey } from './permission-catalog';
|
|
2
|
-
import { type MiniProgramRuntimePermissionsSnapshot } from './permissions';
|
|
3
|
-
/** 仅供开发工具和 Host 使用;新增权限必须单独评估,不能从平台审批目录自动推导。 */
|
|
4
|
-
export declare const LOCAL_DEV_GRANT_PERMISSION_KEYS: readonly ["network", "companion"];
|
|
5
|
-
export type MiniProgramLocalDevPermissionKey = (typeof LOCAL_DEV_GRANT_PERMISSION_KEYS)[number];
|
|
6
|
-
export type MiniProgramLocalDevGrantEntry = {
|
|
7
|
-
key: 'network';
|
|
8
|
-
status: 'enabled';
|
|
9
|
-
config: {
|
|
10
|
-
useOfficialDomain: false;
|
|
11
|
-
};
|
|
12
|
-
} | {
|
|
13
|
-
key: 'companion';
|
|
14
|
-
status: 'enabled';
|
|
15
|
-
config: Record<string, never>;
|
|
16
|
-
};
|
|
17
|
-
/** CLI-owned Dev Context 合同,不属于小程序业务 API 或线上批准快照。 */
|
|
18
|
-
export interface MiniProgramLocalDevGrant {
|
|
19
|
-
schema_version: 1;
|
|
20
|
-
revision: number;
|
|
21
|
-
entries: MiniProgramLocalDevGrantEntry[];
|
|
22
|
-
}
|
|
23
|
-
/** 调用方已校验的本地声明;不存在的权限不会从 grant 获得授权。 */
|
|
24
|
-
export type MiniProgramLocalDevPermissionDeclarations = Partial<Record<MiniProgramPermissionKey, {
|
|
25
|
-
enabled: boolean;
|
|
26
|
-
useOfficialDomain?: boolean;
|
|
27
|
-
}>>;
|
|
28
|
-
export type ParsedMiniProgramLocalDevGrant = {
|
|
29
|
-
valid: true;
|
|
30
|
-
grant: MiniProgramLocalDevGrant;
|
|
31
|
-
} | {
|
|
32
|
-
valid: false;
|
|
33
|
-
grant?: undefined;
|
|
34
|
-
};
|
|
35
|
-
/**
|
|
36
|
-
* 严格解析本地 grant。任何未知字段、重复权限或非法配置都拒绝整份输入。
|
|
37
|
-
* 只校验数据合同;票据、身份、摘要、过期时间和 CLI lease 必须由 Host 另行验证。
|
|
38
|
-
*/
|
|
39
|
-
export declare function parseMiniProgramLocalDevGrant(value: unknown): ParsedMiniProgramLocalDevGrant;
|
|
40
|
-
/**
|
|
41
|
-
* 从已校验声明生成批准缺口。Companion 默认不符合资格,由 CLI 确认平台、产物与摘要后显式加入。
|
|
42
|
-
* 空 entries 可保留 revision,不能作为存在临时权限的判断依据。
|
|
43
|
-
*/
|
|
44
|
-
export declare function createMiniProgramLocalDevGrant(options: {
|
|
45
|
-
declaredPermissions: MiniProgramLocalDevPermissionDeclarations;
|
|
46
|
-
runtimePermissions: unknown;
|
|
47
|
-
revision: number;
|
|
48
|
-
eligiblePermissionKeys?: readonly MiniProgramLocalDevPermissionKey[];
|
|
49
|
-
}): MiniProgramLocalDevGrant;
|
|
50
|
-
/**
|
|
51
|
-
* 线上基线先与本地声明求交,再补齐临时权限,返回与输入脱离的普通 Runtime 快照。
|
|
52
|
-
* 调用方只可在当前 Dev Session 已验证且用户接受后传入 grant;本函数不证明其可信来源。
|
|
53
|
-
* 非法 grant 整体降权到基线,已批准配置不会被临时配置覆盖。
|
|
54
|
-
*/
|
|
55
|
-
export declare function composeLocalDevRuntimePermissions(options: {
|
|
56
|
-
declaredPermissions: MiniProgramLocalDevPermissionDeclarations;
|
|
57
|
-
runtimePermissions: unknown;
|
|
58
|
-
localDevGrant?: unknown;
|
|
59
|
-
}): {
|
|
60
|
-
runtimePermissions: MiniProgramRuntimePermissionsSnapshot;
|
|
61
|
-
temporaryPermissionKeys: MiniProgramLocalDevPermissionKey[];
|
|
62
|
-
grantValid: boolean;
|
|
63
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/** 由 scripts/generate-native-host-contract.mjs 生成,请勿手改。 */
|
|
2
|
-
export declare const MINI_PROGRAM_NATIVE_HOST_PROTOCOL_VERSION: 1;
|
|
3
|
-
export declare const MINI_PROGRAM_NATIVE_HOST_CONTRACT_REVISION: 1;
|
|
4
|
-
export declare const MINI_PROGRAM_NATIVE_CHUNK_MAX_BYTES: 65536;
|
|
5
|
-
export declare const MINI_PROGRAM_NATIVE_OPERATIONS: {
|
|
6
|
-
readonly system: readonly ["describe"];
|
|
7
|
-
readonly network: readonly ["open", "read", "release", "transfer"];
|
|
8
|
-
readonly files: readonly ["create", "remove", "exists", "openRead", "openWrite", "read", "release", "write", "stat", "list", "pickFiles", "pickDirectory", "saveFile"];
|
|
9
|
-
};
|
|
10
|
-
export declare const MINI_PROGRAM_NATIVE_HOST_DESCRIPTION: {
|
|
11
|
-
readonly protocolVersion: 1;
|
|
12
|
-
readonly contractRevision: 1;
|
|
13
|
-
readonly operations: {
|
|
14
|
-
readonly system: readonly ["describe"];
|
|
15
|
-
readonly network: readonly ["open", "read", "release", "transfer"];
|
|
16
|
-
readonly files: readonly ["create", "remove", "exists", "openRead", "openWrite", "read", "release", "write", "stat", "list", "pickFiles", "pickDirectory", "saveFile"];
|
|
17
|
-
};
|
|
18
|
-
};
|
package/types/native-host.d.ts
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
export { MINI_PROGRAM_NATIVE_CHUNK_MAX_BYTES, MINI_PROGRAM_NATIVE_HOST_CONTRACT_REVISION, MINI_PROGRAM_NATIVE_HOST_DESCRIPTION, MINI_PROGRAM_NATIVE_HOST_PROTOCOL_VERSION, MINI_PROGRAM_NATIVE_OPERATIONS, } from './native-host-contract.generated';
|
|
2
|
-
/** Android WebMessageListener object 与 iOS WKScriptMessageHandler 共用名称。 */
|
|
3
|
-
export declare const MINI_PROGRAM_NATIVE_HOST_OBJECT: "hbMiniProgramHost";
|
|
4
|
-
/** Native 通过主文档 CustomEvent 回送 progress/result/error。 */
|
|
5
|
-
export declare const MINI_PROGRAM_NATIVE_HOST_MESSAGE_EVENT: "heybox:miniprogram-native-host-message";
|
|
6
|
-
export type MiniProgramNativeHostDomain = 'system' | 'network' | 'files';
|
|
7
|
-
/** H5 主文档发给 Native Host 的 operation 请求。 */
|
|
8
|
-
export interface MiniProgramNativeHostRequest {
|
|
9
|
-
requestId: string;
|
|
10
|
-
domain: MiniProgramNativeHostDomain;
|
|
11
|
-
operation: string;
|
|
12
|
-
payload?: unknown;
|
|
13
|
-
}
|
|
14
|
-
/** 取消独立引用原请求,重复取消必须是幂等操作。 */
|
|
15
|
-
export interface MiniProgramNativeHostCancel {
|
|
16
|
-
type: 'cancel';
|
|
17
|
-
requestId: string;
|
|
18
|
-
}
|
|
19
|
-
export interface MiniProgramNativeHostError {
|
|
20
|
-
code: string;
|
|
21
|
-
message: string;
|
|
22
|
-
}
|
|
23
|
-
export interface MiniProgramNativeHostDescription {
|
|
24
|
-
protocolVersion: number;
|
|
25
|
-
contractRevision: number;
|
|
26
|
-
operations: Readonly<Record<MiniProgramNativeHostDomain, readonly string[]>>;
|
|
27
|
-
}
|
|
28
|
-
export type MiniProgramNativeHostMessage = {
|
|
29
|
-
requestId: string;
|
|
30
|
-
type: 'progress';
|
|
31
|
-
payload: unknown;
|
|
32
|
-
} | {
|
|
33
|
-
requestId: string;
|
|
34
|
-
type: 'result';
|
|
35
|
-
payload?: unknown;
|
|
36
|
-
} | {
|
|
37
|
-
requestId: string;
|
|
38
|
-
type: 'error';
|
|
39
|
-
error: MiniProgramNativeHostError;
|
|
40
|
-
};
|
|
41
|
-
export interface MiniProgramNativeBinaryChunk {
|
|
42
|
-
resourceId: string;
|
|
43
|
-
data: string;
|
|
44
|
-
byteLength: number;
|
|
45
|
-
eof: boolean;
|
|
46
|
-
}
|
|
47
|
-
export type MiniProgramNativeFileRef = {
|
|
48
|
-
scope: 'sandbox';
|
|
49
|
-
kind: 'file' | 'directory';
|
|
50
|
-
relativePath: string;
|
|
51
|
-
} | {
|
|
52
|
-
scope: 'grant';
|
|
53
|
-
id: string;
|
|
54
|
-
kind: 'file' | 'directory';
|
|
55
|
-
relativePath: string;
|
|
56
|
-
};
|
|
57
|
-
export interface MiniProgramNativeFileDescriptor {
|
|
58
|
-
kind: 'file' | 'directory';
|
|
59
|
-
mode: 'read' | 'readwrite';
|
|
60
|
-
name: string;
|
|
61
|
-
ref: MiniProgramNativeFileRef;
|
|
62
|
-
}
|
|
63
|
-
export interface MiniProgramNativeNetworkOpenPayload {
|
|
64
|
-
purpose: 'request' | 'download';
|
|
65
|
-
url: string;
|
|
66
|
-
method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS';
|
|
67
|
-
params?: Record<string, unknown>;
|
|
68
|
-
data?: unknown;
|
|
69
|
-
headers?: Record<string, string>;
|
|
70
|
-
bodyEncoding?: 'json' | 'form';
|
|
71
|
-
timeoutMs: number;
|
|
72
|
-
}
|
|
73
|
-
export interface MiniProgramNativeNetworkOpenResult {
|
|
74
|
-
status: number;
|
|
75
|
-
statusText?: string;
|
|
76
|
-
headers: Record<string, string[]>;
|
|
77
|
-
resourceId: string;
|
|
78
|
-
}
|
|
79
|
-
export interface MiniProgramNativeNetworkReadPayload {
|
|
80
|
-
resourceId: string;
|
|
81
|
-
maxBytes: number;
|
|
82
|
-
}
|
|
83
|
-
export interface MiniProgramNativeNetworkReleasePayload {
|
|
84
|
-
resourceId: string;
|
|
85
|
-
}
|
|
86
|
-
export interface MiniProgramNativeNetworkTransferPayload {
|
|
87
|
-
resourceId: string;
|
|
88
|
-
target: MiniProgramNativeFileRef;
|
|
89
|
-
mode: 'replace-existing' | 'create-exclusive' | 'upsert';
|
|
90
|
-
maxBytes?: number;
|
|
91
|
-
expectedBytes?: number;
|
|
92
|
-
}
|
|
93
|
-
export interface MiniProgramNativeNetworkTransferResult {
|
|
94
|
-
committedBytes: number;
|
|
95
|
-
}
|
|
96
|
-
export interface MiniProgramNativeFilesCreatePayload {
|
|
97
|
-
ref: MiniProgramNativeFileRef;
|
|
98
|
-
recursive: boolean;
|
|
99
|
-
exclusive: boolean;
|
|
100
|
-
}
|
|
101
|
-
export interface MiniProgramNativeFilesRemovePayload {
|
|
102
|
-
ref: MiniProgramNativeFileRef;
|
|
103
|
-
recursive?: boolean;
|
|
104
|
-
}
|
|
105
|
-
export interface MiniProgramNativeFilesRefPayload {
|
|
106
|
-
ref: MiniProgramNativeFileRef;
|
|
107
|
-
}
|
|
108
|
-
export interface MiniProgramNativeFilesOpenPayload extends MiniProgramNativeFilesRefPayload {
|
|
109
|
-
maxBytes: number;
|
|
110
|
-
}
|
|
111
|
-
export interface MiniProgramNativeFilesOpenResult {
|
|
112
|
-
resourceId: string;
|
|
113
|
-
}
|
|
114
|
-
/** openWrite 后按序发送;eof=true 的最后一块触发 atomic commit。 */
|
|
115
|
-
export interface MiniProgramNativeFilesWritePayload extends MiniProgramNativeBinaryChunk {
|
|
116
|
-
}
|
|
117
|
-
export type MiniProgramNativeFilesStatResult = {
|
|
118
|
-
kind: 'file';
|
|
119
|
-
size: number;
|
|
120
|
-
modifiedAt?: number;
|
|
121
|
-
createdAt?: number;
|
|
122
|
-
} | {
|
|
123
|
-
kind: 'directory';
|
|
124
|
-
modifiedAt?: number;
|
|
125
|
-
createdAt?: number;
|
|
126
|
-
};
|
|
127
|
-
export interface MiniProgramNativeFilesListPayload extends MiniProgramNativeFilesRefPayload {
|
|
128
|
-
limit: number;
|
|
129
|
-
}
|
|
130
|
-
export interface MiniProgramNativeFilesPickFilesPayload {
|
|
131
|
-
mode: 'read' | 'readwrite';
|
|
132
|
-
accept?: string[];
|
|
133
|
-
multiple: boolean;
|
|
134
|
-
}
|
|
135
|
-
export interface MiniProgramNativeFilesPickDirectoryPayload {
|
|
136
|
-
mode: 'read' | 'readwrite';
|
|
137
|
-
}
|
|
138
|
-
export interface MiniProgramNativeFilesSaveFilePayload {
|
|
139
|
-
suggestedName: string;
|
|
140
|
-
}
|
|
141
|
-
export interface MiniProgramNativeTransferProgress {
|
|
142
|
-
resourceId: string;
|
|
143
|
-
loaded: number;
|
|
144
|
-
}
|
|
145
|
-
export declare function isMiniProgramNativeHostMessage(value: unknown): value is MiniProgramNativeHostMessage;
|
|
146
|
-
export declare function isMiniProgramNativeHostDescription(value: unknown): value is MiniProgramNativeHostDescription;
|
|
147
|
-
export declare function isMiniProgramNativeBinaryChunk(value: unknown): value is MiniProgramNativeBinaryChunk;
|