@zleap-ai/app-sdk 0.0.0-stage → 0.10.0
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/LICENSE +24 -0
- package/README.md +39 -2
- package/dist/build-info.json +20 -0
- package/dist/host.js +2 -0
- package/dist/index.js +2 -0
- package/dist/types/api.d.ts +11 -0
- package/dist/types/app.d.ts +77 -0
- package/dist/types/execution.d.ts +73 -0
- package/dist/types/files.d.ts +60 -0
- package/dist/types/index.d.ts +369 -0
- package/dist/types/protocol.d.ts +84 -0
- package/dist/types/transport.d.ts +2 -0
- package/dist/types/values.d.ts +51 -0
- package/dist/types/workspace.d.ts +51 -0
- package/dist/types/zleap-sdk-types.d.ts +138 -0
- package/dist/types/zleap-sdk.d.ts +232 -0
- package/dist/workspace.js +2 -0
- package/package.json +42 -4
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
import { authorize, checkUpdate, getIdentity, getUpdateManager } from './app.js';
|
|
2
|
+
import { type FunctionInput, type JobResult } from './execution.js';
|
|
3
|
+
import { type UploadInput, type UploadResult, type DownloadResult, type DeleteInput, type DeleteResult } from './files.js';
|
|
4
|
+
import { CloudError, type Capabilities, type CloudMethod, type CloudPushEvent, type CloudTransport } from './protocol.js';
|
|
5
|
+
export type { CapabilityInput, JobInput, JobResult, FunctionInput } from './execution.js';
|
|
6
|
+
import { FieldOperation, type Condition } from './values.js';
|
|
7
|
+
export { CloudError } from './protocol.js';
|
|
8
|
+
export { AppError } from './app.js';
|
|
9
|
+
export type { AuthResult, AuthScope, UpdateCheckResult, UpdateManager } from './app.js';
|
|
10
|
+
export type { Capabilities, CloudTransport } from './protocol.js';
|
|
11
|
+
export { boundedBinary, writesCloud } from './protocol.js';
|
|
12
|
+
export interface Callbacks<T> {
|
|
13
|
+
success?: (result: T) => void;
|
|
14
|
+
fail?: (error: CloudError) => void;
|
|
15
|
+
complete?: (result: T | CloudError) => void;
|
|
16
|
+
}
|
|
17
|
+
export interface Meta {
|
|
18
|
+
requestId: string;
|
|
19
|
+
operationId?: string;
|
|
20
|
+
version?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface ReadResult<T> {
|
|
23
|
+
data: T;
|
|
24
|
+
errMsg: string;
|
|
25
|
+
_meta: Meta;
|
|
26
|
+
}
|
|
27
|
+
export interface CountResult {
|
|
28
|
+
total: number;
|
|
29
|
+
errMsg: string;
|
|
30
|
+
_meta: Meta;
|
|
31
|
+
}
|
|
32
|
+
export interface WatchResult {
|
|
33
|
+
data: Document[];
|
|
34
|
+
cursor: string;
|
|
35
|
+
changed: boolean;
|
|
36
|
+
hasMore: boolean;
|
|
37
|
+
errMsg: string;
|
|
38
|
+
_meta: Meta;
|
|
39
|
+
}
|
|
40
|
+
export interface WriteResult {
|
|
41
|
+
_id?: string;
|
|
42
|
+
stats: {
|
|
43
|
+
created: number;
|
|
44
|
+
updated: number;
|
|
45
|
+
removed: number;
|
|
46
|
+
};
|
|
47
|
+
errMsg: string;
|
|
48
|
+
_meta: Meta;
|
|
49
|
+
}
|
|
50
|
+
export interface OperationResult {
|
|
51
|
+
operationId: string;
|
|
52
|
+
state: 'succeeded';
|
|
53
|
+
result: WriteResult;
|
|
54
|
+
}
|
|
55
|
+
export interface AgentOptions {
|
|
56
|
+
operationId?: string;
|
|
57
|
+
expectedVersion?: string;
|
|
58
|
+
}
|
|
59
|
+
export interface WriteOptions {
|
|
60
|
+
data: Record<string, unknown>;
|
|
61
|
+
agentos?: AgentOptions;
|
|
62
|
+
}
|
|
63
|
+
export interface RemoveOptions {
|
|
64
|
+
agentos?: AgentOptions;
|
|
65
|
+
}
|
|
66
|
+
export type Document = Record<string, unknown> & {
|
|
67
|
+
_id: string;
|
|
68
|
+
_openid: string;
|
|
69
|
+
_version: string;
|
|
70
|
+
};
|
|
71
|
+
type CallbackMode<T> = Callbacks<T> & ({
|
|
72
|
+
success: (result: T) => void;
|
|
73
|
+
} | {
|
|
74
|
+
fail: (error: CloudError) => void;
|
|
75
|
+
} | {
|
|
76
|
+
complete: (result: T | CloudError) => void;
|
|
77
|
+
});
|
|
78
|
+
/**
|
|
79
|
+
* 「用宿主决定的环境」哨兵。
|
|
80
|
+
*
|
|
81
|
+
* 环境(dev/prod)是「部署 + 用户」的关系,不是应用能判断的事实:应用既不知道这台机器
|
|
82
|
+
* 开放了哪个数据域,也不知道当前用户是不是本应用的发布者。所以不要写死 `'dev'`,
|
|
83
|
+
* 传这个哨兵,由宿主在建立会话时解析(与服务端 SDK 的 `DYNAMIC_CURRENT_ENV` 同义)。
|
|
84
|
+
*
|
|
85
|
+
* 宿主未识别哨兵时握手会被拒(`ENV_MISMATCH`)—— 宁可失败也不默默落到 dev,
|
|
86
|
+
* 否则应用会以爲在用真实数据域而其实在沙箱里。
|
|
87
|
+
*/
|
|
88
|
+
export declare const DYNAMIC_CURRENT_ENV = "DYNAMIC_CURRENT_ENV";
|
|
89
|
+
interface Session {
|
|
90
|
+
ready(): Promise<Capabilities>;
|
|
91
|
+
request(method: CloudMethod, args: Record<string, unknown>): Promise<{
|
|
92
|
+
value: Record<string, unknown>;
|
|
93
|
+
requestId: string;
|
|
94
|
+
}>;
|
|
95
|
+
createId(): string;
|
|
96
|
+
/**
|
|
97
|
+
* Host-pushed change events for this session. Present only when the host
|
|
98
|
+
* negotiated a transport that supports push; `watch` still works without it.
|
|
99
|
+
*/
|
|
100
|
+
onEvent?(handler: (event: CloudPushEvent) => void): () => void;
|
|
101
|
+
}
|
|
102
|
+
declare class Query {
|
|
103
|
+
protected readonly session: Session;
|
|
104
|
+
protected readonly key: string;
|
|
105
|
+
private readonly query;
|
|
106
|
+
constructor(session: Session, key: string, query?: Record<string, unknown>);
|
|
107
|
+
private with;
|
|
108
|
+
where(value: Record<string, unknown> | Condition): Query;
|
|
109
|
+
orderBy(path: string, direction: 'asc' | 'desc'): Query;
|
|
110
|
+
limit(value: number): Query;
|
|
111
|
+
skip(value: number): Query;
|
|
112
|
+
field(projection: Record<string, boolean>): Query;
|
|
113
|
+
get(options: CallbackMode<ReadResult<Document[]>>): void;
|
|
114
|
+
get(options?: undefined): Promise<ReadResult<Document[]>>;
|
|
115
|
+
count(options: CallbackMode<CountResult>): void;
|
|
116
|
+
count(options?: undefined): Promise<CountResult>;
|
|
117
|
+
watch(options?: {
|
|
118
|
+
cursor?: string;
|
|
119
|
+
query?: Record<string, unknown>;
|
|
120
|
+
maxDocs?: number;
|
|
121
|
+
}): Promise<WatchResult>;
|
|
122
|
+
after(): never;
|
|
123
|
+
/**
|
|
124
|
+
* Subscribe to changes in this collection, pushed by the host.
|
|
125
|
+
*
|
|
126
|
+
* Apps cannot hold their own connection (the sandboxed iframe pins
|
|
127
|
+
* `connect-src` to `'none'`), so the host subscribes to the platform channel
|
|
128
|
+
* on their behalf and forwards each change here. Prefer this over calling
|
|
129
|
+
* `watch()` on a timer: it is the difference between reacting in milliseconds
|
|
130
|
+
* and re-reading the collection every N seconds.
|
|
131
|
+
*
|
|
132
|
+
* The callback carries only the change coordinates — re-read what you need via
|
|
133
|
+
* `get`/`watch`, treating the event as a signal rather than the payload.
|
|
134
|
+
* Returns an unsubscribe function. When the host did not negotiate push the
|
|
135
|
+
* handler is never called, so callers that also poll stay correct.
|
|
136
|
+
*/
|
|
137
|
+
onChange(handler: (change: CloudPushEvent) => void): () => void;
|
|
138
|
+
update(): never;
|
|
139
|
+
remove(): never;
|
|
140
|
+
}
|
|
141
|
+
declare class DocumentReference {
|
|
142
|
+
private readonly session;
|
|
143
|
+
private readonly collection;
|
|
144
|
+
private readonly id;
|
|
145
|
+
private readonly throwOnNotFound;
|
|
146
|
+
constructor(session: Session, collection: string, id: string, throwOnNotFound: boolean);
|
|
147
|
+
get(options: CallbackMode<ReadResult<Document | null>>): void;
|
|
148
|
+
get(options?: undefined): Promise<ReadResult<Document | null>>;
|
|
149
|
+
private mutate;
|
|
150
|
+
set(options: WriteOptions & CallbackMode<WriteResult>): void;
|
|
151
|
+
set(options: WriteOptions): Promise<WriteResult>;
|
|
152
|
+
update(options: WriteOptions & CallbackMode<WriteResult>): void;
|
|
153
|
+
update(options: WriteOptions): Promise<WriteResult>;
|
|
154
|
+
remove(options: RemoveOptions & CallbackMode<WriteResult>): void;
|
|
155
|
+
remove(options?: RemoveOptions): Promise<WriteResult>;
|
|
156
|
+
}
|
|
157
|
+
declare class Collection extends Query {
|
|
158
|
+
private readonly throwOnNotFound;
|
|
159
|
+
constructor(session: Session, key: string, throwOnNotFound: boolean);
|
|
160
|
+
doc(id: string): DocumentReference;
|
|
161
|
+
add(options: WriteOptions & CallbackMode<WriteResult>): void;
|
|
162
|
+
add(options: WriteOptions): Promise<WriteResult>;
|
|
163
|
+
}
|
|
164
|
+
export declare function createCloudClient(factory?: (environmentKey: string) => CloudTransport): {
|
|
165
|
+
/** 应用运行期能力:版本更新(与云资源无关) */
|
|
166
|
+
app: {
|
|
167
|
+
getUpdateManager: typeof getUpdateManager;
|
|
168
|
+
checkUpdate: typeof checkUpdate;
|
|
169
|
+
};
|
|
170
|
+
/** 授权登录:系统授权框 + openid(与云资源无关) */
|
|
171
|
+
auth: {
|
|
172
|
+
authorize: typeof authorize;
|
|
173
|
+
getIdentity: typeof getIdentity;
|
|
174
|
+
};
|
|
175
|
+
cloud: {
|
|
176
|
+
DYNAMIC_CURRENT_ENV: string;
|
|
177
|
+
init(options: {
|
|
178
|
+
env: string | {
|
|
179
|
+
database: string;
|
|
180
|
+
functions: string;
|
|
181
|
+
storage: string;
|
|
182
|
+
};
|
|
183
|
+
traceUser?: boolean;
|
|
184
|
+
}): void;
|
|
185
|
+
database(options?: {
|
|
186
|
+
throwOnNotFound?: boolean;
|
|
187
|
+
}): {
|
|
188
|
+
command: Readonly<{
|
|
189
|
+
eq: (value: unknown) => Condition;
|
|
190
|
+
neq: (value: unknown) => Condition;
|
|
191
|
+
gt: (value: unknown) => Condition;
|
|
192
|
+
gte: (value: unknown) => Condition;
|
|
193
|
+
lt: (value: unknown) => Condition;
|
|
194
|
+
lte: (value: unknown) => Condition;
|
|
195
|
+
in: (value: unknown[]) => Condition;
|
|
196
|
+
nin: (value: unknown[]) => Condition;
|
|
197
|
+
exists: (value: boolean) => Condition;
|
|
198
|
+
and: (...values: (Condition | Record<string, unknown>)[]) => Condition;
|
|
199
|
+
or: (...values: (Condition | Record<string, unknown>)[]) => Condition;
|
|
200
|
+
inc: (value: number) => FieldOperation;
|
|
201
|
+
set: (value: unknown) => FieldOperation;
|
|
202
|
+
remove: () => FieldOperation;
|
|
203
|
+
}>;
|
|
204
|
+
collection: (key: string) => Collection;
|
|
205
|
+
serverDate: (options?: {
|
|
206
|
+
offset?: number;
|
|
207
|
+
}) => FieldOperation;
|
|
208
|
+
runTransaction: (options?: Callbacks<never>) => void | Promise<never>;
|
|
209
|
+
};
|
|
210
|
+
callFunction(options: FunctionInput & Callbacks<JobResult>): Promise<JobResult> | void;
|
|
211
|
+
uploadFile(options: UploadInput & Callbacks<UploadResult>): Promise<UploadResult> | void;
|
|
212
|
+
downloadFile(options: {
|
|
213
|
+
fileID: string;
|
|
214
|
+
} & Callbacks<DownloadResult>): Promise<DownloadResult> | void;
|
|
215
|
+
deleteFile(options: DeleteInput & Callbacks<DeleteResult>): Promise<DeleteResult> | void;
|
|
216
|
+
getTempFileURL: (options?: Callbacks<never>) => void | Promise<never>;
|
|
217
|
+
os: {
|
|
218
|
+
files: {
|
|
219
|
+
getOperation: (operationValue: string) => Promise<{
|
|
220
|
+
operation_id: string;
|
|
221
|
+
state: "pending" | "succeeded" | "cancelled";
|
|
222
|
+
chunk_size?: number;
|
|
223
|
+
received?: number[];
|
|
224
|
+
file?: Record<string, unknown> | null;
|
|
225
|
+
}>;
|
|
226
|
+
cancel: (operationValue: string) => Promise<{
|
|
227
|
+
operation_id: string;
|
|
228
|
+
state: "pending" | "succeeded" | "cancelled";
|
|
229
|
+
chunk_size?: number;
|
|
230
|
+
received?: number[];
|
|
231
|
+
file?: Record<string, unknown> | null;
|
|
232
|
+
}>;
|
|
233
|
+
stat: (fileID: string) => Promise<UploadResult>;
|
|
234
|
+
};
|
|
235
|
+
capabilities: {
|
|
236
|
+
invoke: (args: import("./execution.js").CapabilityInput) => Promise<JobResult>;
|
|
237
|
+
};
|
|
238
|
+
jobs: {
|
|
239
|
+
submit: (args: import("./execution.js").JobInput) => Promise<JobResult>;
|
|
240
|
+
get: (args: {
|
|
241
|
+
jobId: string;
|
|
242
|
+
}) => Promise<JobResult>;
|
|
243
|
+
result: (args: {
|
|
244
|
+
jobId: string;
|
|
245
|
+
}) => Promise<JobResult>;
|
|
246
|
+
wait: (args: import("./execution.js").JobWaitInput) => Promise<JobResult>;
|
|
247
|
+
cancel: (args: {
|
|
248
|
+
jobId: string;
|
|
249
|
+
}) => Promise<{
|
|
250
|
+
cancelRequested: boolean;
|
|
251
|
+
}>;
|
|
252
|
+
};
|
|
253
|
+
api: {
|
|
254
|
+
token: () => Promise<import("./api.js").ApiToken>;
|
|
255
|
+
fetch: (path: string, init?: RequestInit) => Promise<Response>;
|
|
256
|
+
};
|
|
257
|
+
ready: () => Promise<Capabilities>;
|
|
258
|
+
getCapabilities: () => Promise<Capabilities>;
|
|
259
|
+
close: () => void | undefined;
|
|
260
|
+
operations: {
|
|
261
|
+
createId: () => string;
|
|
262
|
+
get: (operationId: string) => Promise<OperationResult>;
|
|
263
|
+
};
|
|
264
|
+
};
|
|
265
|
+
};
|
|
266
|
+
};
|
|
267
|
+
export declare const zl: {
|
|
268
|
+
/** 应用运行期能力:版本更新(与云资源无关) */
|
|
269
|
+
app: {
|
|
270
|
+
getUpdateManager: typeof getUpdateManager;
|
|
271
|
+
checkUpdate: typeof checkUpdate;
|
|
272
|
+
};
|
|
273
|
+
/** 授权登录:系统授权框 + openid(与云资源无关) */
|
|
274
|
+
auth: {
|
|
275
|
+
authorize: typeof authorize;
|
|
276
|
+
getIdentity: typeof getIdentity;
|
|
277
|
+
};
|
|
278
|
+
cloud: {
|
|
279
|
+
DYNAMIC_CURRENT_ENV: string;
|
|
280
|
+
init(options: {
|
|
281
|
+
env: string | {
|
|
282
|
+
database: string;
|
|
283
|
+
functions: string;
|
|
284
|
+
storage: string;
|
|
285
|
+
};
|
|
286
|
+
traceUser?: boolean;
|
|
287
|
+
}): void;
|
|
288
|
+
database(options?: {
|
|
289
|
+
throwOnNotFound?: boolean;
|
|
290
|
+
}): {
|
|
291
|
+
command: Readonly<{
|
|
292
|
+
eq: (value: unknown) => Condition;
|
|
293
|
+
neq: (value: unknown) => Condition;
|
|
294
|
+
gt: (value: unknown) => Condition;
|
|
295
|
+
gte: (value: unknown) => Condition;
|
|
296
|
+
lt: (value: unknown) => Condition;
|
|
297
|
+
lte: (value: unknown) => Condition;
|
|
298
|
+
in: (value: unknown[]) => Condition;
|
|
299
|
+
nin: (value: unknown[]) => Condition;
|
|
300
|
+
exists: (value: boolean) => Condition;
|
|
301
|
+
and: (...values: (Condition | Record<string, unknown>)[]) => Condition;
|
|
302
|
+
or: (...values: (Condition | Record<string, unknown>)[]) => Condition;
|
|
303
|
+
inc: (value: number) => FieldOperation;
|
|
304
|
+
set: (value: unknown) => FieldOperation;
|
|
305
|
+
remove: () => FieldOperation;
|
|
306
|
+
}>;
|
|
307
|
+
collection: (key: string) => Collection;
|
|
308
|
+
serverDate: (options?: {
|
|
309
|
+
offset?: number;
|
|
310
|
+
}) => FieldOperation;
|
|
311
|
+
runTransaction: (options?: Callbacks<never>) => void | Promise<never>;
|
|
312
|
+
};
|
|
313
|
+
callFunction(options: FunctionInput & Callbacks<JobResult>): Promise<JobResult> | void;
|
|
314
|
+
uploadFile(options: UploadInput & Callbacks<UploadResult>): Promise<UploadResult> | void;
|
|
315
|
+
downloadFile(options: {
|
|
316
|
+
fileID: string;
|
|
317
|
+
} & Callbacks<DownloadResult>): Promise<DownloadResult> | void;
|
|
318
|
+
deleteFile(options: DeleteInput & Callbacks<DeleteResult>): Promise<DeleteResult> | void;
|
|
319
|
+
getTempFileURL: (options?: Callbacks<never>) => void | Promise<never>;
|
|
320
|
+
os: {
|
|
321
|
+
files: {
|
|
322
|
+
getOperation: (operationValue: string) => Promise<{
|
|
323
|
+
operation_id: string;
|
|
324
|
+
state: "pending" | "succeeded" | "cancelled";
|
|
325
|
+
chunk_size?: number;
|
|
326
|
+
received?: number[];
|
|
327
|
+
file?: Record<string, unknown> | null;
|
|
328
|
+
}>;
|
|
329
|
+
cancel: (operationValue: string) => Promise<{
|
|
330
|
+
operation_id: string;
|
|
331
|
+
state: "pending" | "succeeded" | "cancelled";
|
|
332
|
+
chunk_size?: number;
|
|
333
|
+
received?: number[];
|
|
334
|
+
file?: Record<string, unknown> | null;
|
|
335
|
+
}>;
|
|
336
|
+
stat: (fileID: string) => Promise<UploadResult>;
|
|
337
|
+
};
|
|
338
|
+
capabilities: {
|
|
339
|
+
invoke: (args: import("./execution.js").CapabilityInput) => Promise<JobResult>;
|
|
340
|
+
};
|
|
341
|
+
jobs: {
|
|
342
|
+
submit: (args: import("./execution.js").JobInput) => Promise<JobResult>;
|
|
343
|
+
get: (args: {
|
|
344
|
+
jobId: string;
|
|
345
|
+
}) => Promise<JobResult>;
|
|
346
|
+
result: (args: {
|
|
347
|
+
jobId: string;
|
|
348
|
+
}) => Promise<JobResult>;
|
|
349
|
+
wait: (args: import("./execution.js").JobWaitInput) => Promise<JobResult>;
|
|
350
|
+
cancel: (args: {
|
|
351
|
+
jobId: string;
|
|
352
|
+
}) => Promise<{
|
|
353
|
+
cancelRequested: boolean;
|
|
354
|
+
}>;
|
|
355
|
+
};
|
|
356
|
+
api: {
|
|
357
|
+
token: () => Promise<import("./api.js").ApiToken>;
|
|
358
|
+
fetch: (path: string, init?: RequestInit) => Promise<Response>;
|
|
359
|
+
};
|
|
360
|
+
ready: () => Promise<Capabilities>;
|
|
361
|
+
getCapabilities: () => Promise<Capabilities>;
|
|
362
|
+
close: () => void | undefined;
|
|
363
|
+
operations: {
|
|
364
|
+
createId: () => string;
|
|
365
|
+
get: (operationId: string) => Promise<OperationResult>;
|
|
366
|
+
};
|
|
367
|
+
};
|
|
368
|
+
};
|
|
369
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
export declare const CLOUD_PROTOCOL = 2;
|
|
2
|
+
export declare const CLOUD_CONNECT = "__zleap_cloud_connect";
|
|
3
|
+
export declare const CLOUD_READY = "__zleap_cloud_ready";
|
|
4
|
+
export declare const CLOUD_CLOSE = "__zleap_cloud_close";
|
|
5
|
+
export declare const CLOUD_CLOSED = "__zleap_cloud_closed";
|
|
6
|
+
/**
|
|
7
|
+
* Host → app **push** frame. Every other frame is a handshake or a reply keyed
|
|
8
|
+
* by a requestId the app sent, so this is a genuinely new direction.
|
|
9
|
+
*
|
|
10
|
+
* The app iframe is pinned to `connect-src 'none'`, so it cannot open its own
|
|
11
|
+
* long-lived connection. The host (apps/main) subscribes to the platform
|
|
12
|
+
* realtime channel on the app's behalf and forwards changes over this frame.
|
|
13
|
+
* The payload goes through the same whitelist projection as replies, so future
|
|
14
|
+
* control-plane fields can never become iframe credentials.
|
|
15
|
+
*/
|
|
16
|
+
export declare const CLOUD_EVENT = "__zleap_cloud_event";
|
|
17
|
+
/** 页面接口令牌走独立消息:只调 OS 接口的应用不声明 Cloud 能力,也没有 Cloud 会话。 */
|
|
18
|
+
export declare const APP_API_TOKEN = "__zleap_api_token";
|
|
19
|
+
export declare const REQUEST_ID: RegExp;
|
|
20
|
+
export declare const OPERATION_ID: RegExp;
|
|
21
|
+
export type CloudMethod = 'documents.query' | 'documents.snapshot' | 'documents.mutate' | 'operations.get' | 'execution.invoke' | 'execution.get' | 'execution.cancel' | FileMethod;
|
|
22
|
+
export type FileMethod = 'files.begin' | 'files.chunk' | 'files.commit' | 'files.cancel' | 'files.operation' | 'files.stat' | 'files.read' | 'files.delete';
|
|
23
|
+
export interface Capabilities {
|
|
24
|
+
protocol: {
|
|
25
|
+
major: 2;
|
|
26
|
+
minor: 0;
|
|
27
|
+
};
|
|
28
|
+
profiles: string[];
|
|
29
|
+
operators: string[];
|
|
30
|
+
limits: Record<string, number>;
|
|
31
|
+
serverTime: number;
|
|
32
|
+
}
|
|
33
|
+
export interface CloudRequest {
|
|
34
|
+
requestId: string;
|
|
35
|
+
method: CloudMethod;
|
|
36
|
+
args: Record<string, unknown>;
|
|
37
|
+
}
|
|
38
|
+
export interface CloudTransport {
|
|
39
|
+
ready(): Promise<Capabilities>;
|
|
40
|
+
request(method: CloudMethod, args: Record<string, unknown>, requestId: string): Promise<unknown>;
|
|
41
|
+
/**
|
|
42
|
+
* Register a handler for host-pushed change events.
|
|
43
|
+
*
|
|
44
|
+
* Returns an unsubscribe function. Apps cannot hold their own connection (the
|
|
45
|
+
* iframe is pinned to `connect-src 'none'`), so the host subscribes on their
|
|
46
|
+
* behalf and forwards changes here — this replaces polling for callers that
|
|
47
|
+
* would otherwise re-read on a timer.
|
|
48
|
+
*/
|
|
49
|
+
onEvent(handler: (event: CloudPushEvent) => void): () => void;
|
|
50
|
+
close(): void;
|
|
51
|
+
}
|
|
52
|
+
/** One host-pushed change. Mirrors what `cloudPushProjection` allows through. */
|
|
53
|
+
export interface CloudPushEvent {
|
|
54
|
+
event: string;
|
|
55
|
+
app_id?: string;
|
|
56
|
+
/** The app-facing collection name, as declared in the manifest. */
|
|
57
|
+
collection_key?: string;
|
|
58
|
+
/** Data-service internal id; kept for correlation, not for filtering. */
|
|
59
|
+
collection_id?: string;
|
|
60
|
+
document_key?: string;
|
|
61
|
+
change_seq?: string;
|
|
62
|
+
operation_id?: string;
|
|
63
|
+
}
|
|
64
|
+
export declare class CloudError extends Error {
|
|
65
|
+
readonly errCode: string;
|
|
66
|
+
readonly errMsg: string;
|
|
67
|
+
readonly requestId?: string;
|
|
68
|
+
readonly operationId?: string;
|
|
69
|
+
readonly retryable: boolean;
|
|
70
|
+
readonly jobId?: string;
|
|
71
|
+
readonly invocationId?: string;
|
|
72
|
+
constructor(code: string, requestId?: string, operationId?: string, job?: {
|
|
73
|
+
jobId: string;
|
|
74
|
+
invocationId: string;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
export declare function plain(value: unknown): value is Record<string, unknown>;
|
|
78
|
+
export declare function keysOnly(value: Record<string, unknown>, keys: readonly string[]): boolean;
|
|
79
|
+
export declare function boundedJson(value: unknown, max?: number): boolean;
|
|
80
|
+
export declare function parseCloudRequest(value: unknown): CloudRequest | null;
|
|
81
|
+
export declare function boundedBinary(value: unknown): value is Record<string, unknown> & {
|
|
82
|
+
data: ArrayBuffer;
|
|
83
|
+
};
|
|
84
|
+
export declare function writesCloud(method: CloudMethod): boolean;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export type ValueTypes = Record<string, 'date'>;
|
|
2
|
+
export type Filter = {
|
|
3
|
+
op: string;
|
|
4
|
+
field?: string;
|
|
5
|
+
value?: unknown;
|
|
6
|
+
value_type?: 'date';
|
|
7
|
+
filters?: Filter[];
|
|
8
|
+
};
|
|
9
|
+
export declare class Condition {
|
|
10
|
+
readonly filters: Filter[];
|
|
11
|
+
constructor(filters: Filter[]);
|
|
12
|
+
and(other: Condition): Condition;
|
|
13
|
+
or(other: Condition): Condition;
|
|
14
|
+
}
|
|
15
|
+
export declare class FieldOperation {
|
|
16
|
+
readonly op: 'inc' | 'set' | 'remove' | 'serverDate';
|
|
17
|
+
readonly value?: unknown;
|
|
18
|
+
readonly offset: number;
|
|
19
|
+
constructor(op: 'inc' | 'set' | 'remove' | 'serverDate', value?: unknown, offset?: number);
|
|
20
|
+
}
|
|
21
|
+
export declare const command: Readonly<{
|
|
22
|
+
eq: (value: unknown) => Condition;
|
|
23
|
+
neq: (value: unknown) => Condition;
|
|
24
|
+
gt: (value: unknown) => Condition;
|
|
25
|
+
gte: (value: unknown) => Condition;
|
|
26
|
+
lt: (value: unknown) => Condition;
|
|
27
|
+
lte: (value: unknown) => Condition;
|
|
28
|
+
in: (value: unknown[]) => Condition;
|
|
29
|
+
nin: (value: unknown[]) => Condition;
|
|
30
|
+
exists: (value: boolean) => Condition;
|
|
31
|
+
and: (...values: (Condition | Record<string, unknown>)[]) => Condition;
|
|
32
|
+
or: (...values: (Condition | Record<string, unknown>)[]) => Condition;
|
|
33
|
+
inc: (value: number) => FieldOperation;
|
|
34
|
+
set: (value: unknown) => FieldOperation;
|
|
35
|
+
remove: () => FieldOperation;
|
|
36
|
+
}>;
|
|
37
|
+
export declare function fieldPath(path: string, system?: boolean): void;
|
|
38
|
+
export declare function filterOf(value: Condition | Record<string, unknown>, field?: string): Filter;
|
|
39
|
+
export interface FieldCommand {
|
|
40
|
+
op: string;
|
|
41
|
+
path: string;
|
|
42
|
+
value?: unknown;
|
|
43
|
+
value_types?: ValueTypes;
|
|
44
|
+
offset?: number;
|
|
45
|
+
}
|
|
46
|
+
export declare function encodeMutation(input: Record<string, unknown>, mode: string): {
|
|
47
|
+
data: Record<string, unknown>;
|
|
48
|
+
value_types: ValueTypes;
|
|
49
|
+
field_operations: FieldCommand[];
|
|
50
|
+
};
|
|
51
|
+
export declare function decodeDates(input: unknown, types: Record<string, unknown>): unknown;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/** @generated from packages/shared/src/apps/workspaceSdk.ts; source SHA256: 47ceb13ac6415f7b347fb2d8932f3613d0a515aa71748e46e08056aa5c9764f2 */
|
|
2
|
+
/** Standalone SDK for explicitly selected OS directories. No JWT, URL or raw API bridge. */
|
|
3
|
+
export interface WorkspaceFolder {
|
|
4
|
+
handle: string;
|
|
5
|
+
name: string;
|
|
6
|
+
}
|
|
7
|
+
export interface WorkspaceFile {
|
|
8
|
+
id: string;
|
|
9
|
+
name: string;
|
|
10
|
+
mime_type: string | null;
|
|
11
|
+
size: number;
|
|
12
|
+
version: number;
|
|
13
|
+
created_at: number;
|
|
14
|
+
}
|
|
15
|
+
export interface WorkspaceListing {
|
|
16
|
+
files: WorkspaceFile[];
|
|
17
|
+
folders: WorkspaceFolder[];
|
|
18
|
+
}
|
|
19
|
+
export interface WorkspaceImage {
|
|
20
|
+
fileId: string;
|
|
21
|
+
name: string;
|
|
22
|
+
mimeType: string;
|
|
23
|
+
size: number;
|
|
24
|
+
version: number;
|
|
25
|
+
blob: Blob;
|
|
26
|
+
}
|
|
27
|
+
export interface WorkspaceOperation {
|
|
28
|
+
operationId: string;
|
|
29
|
+
status: 'pending' | 'succeeded' | 'failed' | 'unknown';
|
|
30
|
+
result?: unknown;
|
|
31
|
+
code?: string | null;
|
|
32
|
+
}
|
|
33
|
+
export declare class WorkspaceError extends Error {
|
|
34
|
+
readonly code: string;
|
|
35
|
+
readonly operationId?: string;
|
|
36
|
+
constructor(code: string, operationId?: string);
|
|
37
|
+
}
|
|
38
|
+
export declare function connectWorkspace(): Promise<{
|
|
39
|
+
selectFolder: () => Promise<WorkspaceFolder>;
|
|
40
|
+
restoreFolder: () => Promise<WorkspaceFolder | null>;
|
|
41
|
+
list: (handle: string) => Promise<WorkspaceListing>;
|
|
42
|
+
readImage: (handle: string, fileId: string, expectedVersion: number) => Promise<WorkspaceImage>;
|
|
43
|
+
createFolder: (parent: string, name: string, operationId?: string) => Promise<WorkspaceFolder>;
|
|
44
|
+
move: (source: string, destination: string, fileIds: string[], operationId?: string) => Promise<{
|
|
45
|
+
moved: number;
|
|
46
|
+
fileIds: string[];
|
|
47
|
+
}>;
|
|
48
|
+
operation: (operationId: string) => Promise<WorkspaceOperation>;
|
|
49
|
+
createOperationId: () => `${string}-${string}-${string}-${string}-${string}`;
|
|
50
|
+
close: () => void;
|
|
51
|
+
}>;
|