@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
package/src/native-host.ts
DELETED
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
export {
|
|
2
|
-
MINI_PROGRAM_NATIVE_CHUNK_MAX_BYTES,
|
|
3
|
-
MINI_PROGRAM_NATIVE_HOST_CONTRACT_REVISION,
|
|
4
|
-
MINI_PROGRAM_NATIVE_HOST_DESCRIPTION,
|
|
5
|
-
MINI_PROGRAM_NATIVE_HOST_PROTOCOL_VERSION,
|
|
6
|
-
MINI_PROGRAM_NATIVE_OPERATIONS,
|
|
7
|
-
} from './native-host-contract.generated';
|
|
8
|
-
import { MINI_PROGRAM_NATIVE_CHUNK_MAX_BYTES } from './native-host-contract.generated';
|
|
9
|
-
/** Android WebMessageListener object 与 iOS WKScriptMessageHandler 共用名称。 */
|
|
10
|
-
export const MINI_PROGRAM_NATIVE_HOST_OBJECT = 'hbMiniProgramHost' as const;
|
|
11
|
-
/** Native 通过主文档 CustomEvent 回送 progress/result/error。 */
|
|
12
|
-
export const MINI_PROGRAM_NATIVE_HOST_MESSAGE_EVENT = 'heybox:miniprogram-native-host-message' as const;
|
|
13
|
-
|
|
14
|
-
export type MiniProgramNativeHostDomain = 'system' | 'network' | 'files';
|
|
15
|
-
|
|
16
|
-
/** H5 主文档发给 Native Host 的 operation 请求。 */
|
|
17
|
-
export interface MiniProgramNativeHostRequest {
|
|
18
|
-
requestId: string;
|
|
19
|
-
domain: MiniProgramNativeHostDomain;
|
|
20
|
-
operation: string;
|
|
21
|
-
payload?: unknown;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/** 取消独立引用原请求,重复取消必须是幂等操作。 */
|
|
25
|
-
export interface MiniProgramNativeHostCancel {
|
|
26
|
-
type: 'cancel';
|
|
27
|
-
requestId: string;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface MiniProgramNativeHostError {
|
|
31
|
-
code: string;
|
|
32
|
-
message: string;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export interface MiniProgramNativeHostDescription {
|
|
36
|
-
protocolVersion: number;
|
|
37
|
-
contractRevision: number;
|
|
38
|
-
operations: Readonly<Record<MiniProgramNativeHostDomain, readonly string[]>>;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export type MiniProgramNativeHostMessage =
|
|
42
|
-
| { requestId: string; type: 'progress'; payload: unknown }
|
|
43
|
-
| { requestId: string; type: 'result'; payload?: unknown }
|
|
44
|
-
| { requestId: string; type: 'error'; error: MiniProgramNativeHostError };
|
|
45
|
-
|
|
46
|
-
export interface MiniProgramNativeBinaryChunk {
|
|
47
|
-
resourceId: string;
|
|
48
|
-
data: string;
|
|
49
|
-
byteLength: number;
|
|
50
|
-
eof: boolean;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export type MiniProgramNativeFileRef =
|
|
54
|
-
| { scope: 'sandbox'; kind: 'file' | 'directory'; relativePath: string }
|
|
55
|
-
| { scope: 'grant'; id: string; kind: 'file' | 'directory'; relativePath: string };
|
|
56
|
-
|
|
57
|
-
export interface MiniProgramNativeFileDescriptor {
|
|
58
|
-
kind: 'file' | 'directory';
|
|
59
|
-
mode: 'read' | 'readwrite';
|
|
60
|
-
name: string;
|
|
61
|
-
ref: MiniProgramNativeFileRef;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export interface MiniProgramNativeNetworkOpenPayload {
|
|
65
|
-
purpose: 'request' | 'download';
|
|
66
|
-
url: string;
|
|
67
|
-
method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS';
|
|
68
|
-
params?: Record<string, unknown>;
|
|
69
|
-
data?: unknown;
|
|
70
|
-
headers?: Record<string, string>;
|
|
71
|
-
bodyEncoding?: 'json' | 'form';
|
|
72
|
-
timeoutMs: number;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export interface MiniProgramNativeNetworkOpenResult {
|
|
76
|
-
status: number;
|
|
77
|
-
statusText?: string;
|
|
78
|
-
headers: Record<string, string[]>;
|
|
79
|
-
resourceId: string;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export interface MiniProgramNativeNetworkReadPayload {
|
|
83
|
-
resourceId: string;
|
|
84
|
-
maxBytes: number;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export interface MiniProgramNativeNetworkReleasePayload {
|
|
88
|
-
resourceId: string;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export interface MiniProgramNativeNetworkTransferPayload {
|
|
92
|
-
resourceId: string;
|
|
93
|
-
target: MiniProgramNativeFileRef;
|
|
94
|
-
mode: 'replace-existing' | 'create-exclusive' | 'upsert';
|
|
95
|
-
maxBytes?: number;
|
|
96
|
-
expectedBytes?: number;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export interface MiniProgramNativeNetworkTransferResult {
|
|
100
|
-
committedBytes: number;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export interface MiniProgramNativeFilesCreatePayload {
|
|
104
|
-
ref: MiniProgramNativeFileRef;
|
|
105
|
-
recursive: boolean;
|
|
106
|
-
exclusive: boolean;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export interface MiniProgramNativeFilesRemovePayload {
|
|
110
|
-
ref: MiniProgramNativeFileRef;
|
|
111
|
-
recursive?: boolean;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export interface MiniProgramNativeFilesRefPayload {
|
|
115
|
-
ref: MiniProgramNativeFileRef;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export interface MiniProgramNativeFilesOpenPayload extends MiniProgramNativeFilesRefPayload {
|
|
119
|
-
maxBytes: number;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export interface MiniProgramNativeFilesOpenResult {
|
|
123
|
-
resourceId: string;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/** openWrite 后按序发送;eof=true 的最后一块触发 atomic commit。 */
|
|
127
|
-
export interface MiniProgramNativeFilesWritePayload extends MiniProgramNativeBinaryChunk {}
|
|
128
|
-
|
|
129
|
-
export type MiniProgramNativeFilesStatResult =
|
|
130
|
-
| { kind: 'file'; size: number; modifiedAt?: number; createdAt?: number }
|
|
131
|
-
| { kind: 'directory'; modifiedAt?: number; createdAt?: number };
|
|
132
|
-
|
|
133
|
-
export interface MiniProgramNativeFilesListPayload extends MiniProgramNativeFilesRefPayload {
|
|
134
|
-
limit: number;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
export interface MiniProgramNativeFilesPickFilesPayload {
|
|
138
|
-
mode: 'read' | 'readwrite';
|
|
139
|
-
accept?: string[];
|
|
140
|
-
multiple: boolean;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
export interface MiniProgramNativeFilesPickDirectoryPayload {
|
|
144
|
-
mode: 'read' | 'readwrite';
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
export interface MiniProgramNativeFilesSaveFilePayload {
|
|
148
|
-
suggestedName: string;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
export interface MiniProgramNativeTransferProgress {
|
|
152
|
-
resourceId: string;
|
|
153
|
-
loaded: number;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
export function isMiniProgramNativeHostMessage(value: unknown): value is MiniProgramNativeHostMessage {
|
|
157
|
-
if (!isRecord(value) || !isNonEmptyString(value.requestId)) return false;
|
|
158
|
-
if (value.type === 'progress') return Object.prototype.hasOwnProperty.call(value, 'payload');
|
|
159
|
-
if (value.type === 'result') return !Object.prototype.hasOwnProperty.call(value, 'error');
|
|
160
|
-
if (value.type !== 'error' || !isRecord(value.error)) return false;
|
|
161
|
-
return isNonEmptyString(value.error.code) && isNonEmptyString(value.error.message);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
export function isMiniProgramNativeHostDescription(value: unknown): value is MiniProgramNativeHostDescription {
|
|
165
|
-
if (
|
|
166
|
-
!isRecord(value) ||
|
|
167
|
-
!isPositiveSafeInteger(value.protocolVersion) ||
|
|
168
|
-
!isPositiveSafeInteger(value.contractRevision) ||
|
|
169
|
-
!isRecord(value.operations)
|
|
170
|
-
)
|
|
171
|
-
return false;
|
|
172
|
-
const operations = value.operations;
|
|
173
|
-
if (
|
|
174
|
-
!isOperationList(operations.system) ||
|
|
175
|
-
!isOperationList(operations.network) ||
|
|
176
|
-
!isOperationList(operations.files)
|
|
177
|
-
)
|
|
178
|
-
return false;
|
|
179
|
-
return operations.system.includes('describe');
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
export function isMiniProgramNativeBinaryChunk(value: unknown): value is MiniProgramNativeBinaryChunk {
|
|
183
|
-
return (
|
|
184
|
-
isRecord(value) &&
|
|
185
|
-
isNonEmptyString(value.resourceId) &&
|
|
186
|
-
typeof value.data === 'string' &&
|
|
187
|
-
Number.isSafeInteger(value.byteLength) &&
|
|
188
|
-
Number(value.byteLength) >= 0 &&
|
|
189
|
-
Number(value.byteLength) <= MINI_PROGRAM_NATIVE_CHUNK_MAX_BYTES &&
|
|
190
|
-
typeof value.eof === 'boolean' &&
|
|
191
|
-
(Number(value.byteLength) > 0 || value.eof)
|
|
192
|
-
);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
196
|
-
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
function isNonEmptyString(value: unknown): value is string {
|
|
200
|
-
return typeof value === 'string' && value.length > 0;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
function isPositiveSafeInteger(value: unknown): value is number {
|
|
204
|
-
return Number.isSafeInteger(value) && Number(value) > 0;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
function isOperationList(value: unknown): value is string[] {
|
|
208
|
-
return (
|
|
209
|
-
Array.isArray(value) &&
|
|
210
|
-
value.every(operation => isNonEmptyString(operation) && operation === operation.trim()) &&
|
|
211
|
-
new Set(value).size === value.length
|
|
212
|
-
);
|
|
213
|
-
}
|