@zuzjs/flare-admin 0.1.4 → 0.1.6
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 +312 -138
- package/dist/index.cjs +4 -4
- package/dist/index.d.cts +578 -47
- package/dist/index.d.ts +94 -11
- package/dist/index.js +3 -3
- package/dist/lib/grpc.d.ts +11 -0
- package/dist/lib/http.d.ts +3 -0
- package/dist/lib/notifications.d.ts +1 -1
- package/dist/lib/storage.d.ts +98 -0
- package/dist/realtime/Connection.d.ts +14 -0
- package/dist/realtime/LiveCollection.d.ts +3 -1
- package/dist/realtime/WsConnection.d.ts +11 -1
- package/dist/serverTimestamp.d.ts +13 -0
- package/dist/types/index.d.ts +357 -0
- package/package.json +4 -1
- package/proto/admin.proto +129 -0
- package/proto/app.proto +69 -0
- package/proto/auth.proto +70 -0
- package/proto/flare.proto +11 -0
- package/proto/query.proto +109 -0
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
type AdminConnectionState = 'connecting' | 'connected' | 'disconnected' | 'reconnecting' | 'error';
|
|
2
|
+
type AdminConnectionStateListener = (state: AdminConnectionState) => void;
|
|
1
3
|
interface FlareAdminConfig {
|
|
2
4
|
/**
|
|
3
5
|
* Base URL of your FlareServer instance.
|
|
@@ -12,6 +14,12 @@ interface FlareAdminConfig {
|
|
|
12
14
|
* Keep in an environment variable — NEVER expose to the browser.
|
|
13
15
|
*/
|
|
14
16
|
adminKey: string;
|
|
17
|
+
/** Optional gRPC endpoint, e.g. "127.0.0.1:5051". */
|
|
18
|
+
grpcUrl?: string;
|
|
19
|
+
/** Transport preference for supported operations. */
|
|
20
|
+
transport?: "auto" | "http" | "grpc";
|
|
21
|
+
/** Optional HTTP base URL override for admin HTTP APIs. */
|
|
22
|
+
httpBase?: string;
|
|
15
23
|
/** Default token TTL, e.g. "24h" */
|
|
16
24
|
defaultTtl?: string;
|
|
17
25
|
/**
|
|
@@ -89,6 +97,322 @@ interface FlareAdminNotifications {
|
|
|
89
97
|
tokens: AdminPushToken[];
|
|
90
98
|
}>;
|
|
91
99
|
}
|
|
100
|
+
interface AdminStorageServer {
|
|
101
|
+
id: string;
|
|
102
|
+
name: string;
|
|
103
|
+
kind: string;
|
|
104
|
+
endpoint: string;
|
|
105
|
+
bucket: string;
|
|
106
|
+
region: string;
|
|
107
|
+
prefix?: string;
|
|
108
|
+
dataDir?: string;
|
|
109
|
+
forcePathStyle?: boolean;
|
|
110
|
+
frozen?: boolean;
|
|
111
|
+
readOnly?: boolean;
|
|
112
|
+
createdAt?: unknown;
|
|
113
|
+
updatedAt?: unknown;
|
|
114
|
+
}
|
|
115
|
+
interface AdminStorageServerInput {
|
|
116
|
+
name: string;
|
|
117
|
+
kind?: string;
|
|
118
|
+
endpoint?: string;
|
|
119
|
+
bucket: string;
|
|
120
|
+
region?: string;
|
|
121
|
+
accessKey?: string;
|
|
122
|
+
secretKey?: string;
|
|
123
|
+
prefix?: string;
|
|
124
|
+
dataDir?: string;
|
|
125
|
+
forcePathStyle?: boolean;
|
|
126
|
+
frozen?: boolean;
|
|
127
|
+
readOnly?: boolean;
|
|
128
|
+
}
|
|
129
|
+
interface AdminStorageServerPatchInput {
|
|
130
|
+
name?: string;
|
|
131
|
+
endpoint?: string;
|
|
132
|
+
bucket?: string;
|
|
133
|
+
region?: string;
|
|
134
|
+
accessKey?: string;
|
|
135
|
+
secretKey?: string;
|
|
136
|
+
prefix?: string;
|
|
137
|
+
dataDir?: string;
|
|
138
|
+
forcePathStyle?: boolean;
|
|
139
|
+
frozen?: boolean;
|
|
140
|
+
readOnly?: boolean;
|
|
141
|
+
}
|
|
142
|
+
interface AdminStorageUploadInput {
|
|
143
|
+
serverId: string;
|
|
144
|
+
path: string;
|
|
145
|
+
contentBase64: string;
|
|
146
|
+
contentType?: string;
|
|
147
|
+
encrypt?: boolean;
|
|
148
|
+
}
|
|
149
|
+
interface AdminStorageDownloadInput {
|
|
150
|
+
serverId: string;
|
|
151
|
+
path: string;
|
|
152
|
+
decrypt?: boolean;
|
|
153
|
+
}
|
|
154
|
+
interface AdminStorageDeleteInput {
|
|
155
|
+
serverId: string;
|
|
156
|
+
path: string;
|
|
157
|
+
}
|
|
158
|
+
interface AdminStorageObjectResult {
|
|
159
|
+
ok: boolean;
|
|
160
|
+
path: string;
|
|
161
|
+
key: string;
|
|
162
|
+
encrypted?: boolean;
|
|
163
|
+
size?: number;
|
|
164
|
+
contentBase64?: string;
|
|
165
|
+
contentType?: string;
|
|
166
|
+
}
|
|
167
|
+
declare enum AdminStorageSignedAction {
|
|
168
|
+
Upload = "upload",
|
|
169
|
+
Download = "download",
|
|
170
|
+
Delete = "delete",
|
|
171
|
+
Edit = "edit"
|
|
172
|
+
}
|
|
173
|
+
interface AdminStorageSignedUrlInput {
|
|
174
|
+
bucket: string;
|
|
175
|
+
key: string;
|
|
176
|
+
action: AdminStorageSignedAction;
|
|
177
|
+
expiresInSeconds?: number;
|
|
178
|
+
sizeBytes?: number;
|
|
179
|
+
contentType?: string;
|
|
180
|
+
encrypt?: boolean;
|
|
181
|
+
decrypt?: boolean;
|
|
182
|
+
forceDownload?: boolean;
|
|
183
|
+
allowedOrigins?: string[];
|
|
184
|
+
embedOnly?: boolean;
|
|
185
|
+
}
|
|
186
|
+
interface AdminStorageSignedUrlResult {
|
|
187
|
+
ok: boolean;
|
|
188
|
+
action: AdminStorageSignedAction;
|
|
189
|
+
method: "PUT" | "PATCH" | "GET" | "DELETE";
|
|
190
|
+
token: string;
|
|
191
|
+
urlPath: string;
|
|
192
|
+
url: string;
|
|
193
|
+
expiresInSeconds?: number;
|
|
194
|
+
expiresAt: number;
|
|
195
|
+
forceDownload?: boolean;
|
|
196
|
+
allowedOrigins?: string[];
|
|
197
|
+
embedOnly?: boolean;
|
|
198
|
+
}
|
|
199
|
+
interface AdminGetObjectUrlInput {
|
|
200
|
+
bucket: string;
|
|
201
|
+
key: string;
|
|
202
|
+
decrypt?: boolean;
|
|
203
|
+
expiresInSeconds?: number;
|
|
204
|
+
forceDownload?: boolean;
|
|
205
|
+
allowedOrigins?: string[];
|
|
206
|
+
embedOnly?: boolean;
|
|
207
|
+
}
|
|
208
|
+
interface AdminDownloadObjectInput extends AdminGetObjectUrlInput {
|
|
209
|
+
filename?: string;
|
|
210
|
+
openInNewTab?: boolean;
|
|
211
|
+
}
|
|
212
|
+
interface AdminDownloadObjectResult {
|
|
213
|
+
ok: boolean;
|
|
214
|
+
url: string;
|
|
215
|
+
filename: string;
|
|
216
|
+
triggered: boolean;
|
|
217
|
+
}
|
|
218
|
+
interface AdminStorageAwsConfig {
|
|
219
|
+
kind: string;
|
|
220
|
+
endpoint: string;
|
|
221
|
+
region: string;
|
|
222
|
+
bucket: string;
|
|
223
|
+
prefix?: string;
|
|
224
|
+
dataDir?: string;
|
|
225
|
+
forcePathStyle?: boolean;
|
|
226
|
+
accessKeyId: string;
|
|
227
|
+
secretAccessKey: string;
|
|
228
|
+
}
|
|
229
|
+
interface AdminStorageRulesPolicy {
|
|
230
|
+
maxEntries?: number;
|
|
231
|
+
maxAgeDays?: number;
|
|
232
|
+
}
|
|
233
|
+
interface AdminStorageRulesHistoryResult {
|
|
234
|
+
history: unknown[];
|
|
235
|
+
policy: AdminStorageRulesPolicy;
|
|
236
|
+
restoreEvents: unknown[];
|
|
237
|
+
}
|
|
238
|
+
interface FlareAdminStorage {
|
|
239
|
+
servers(): Promise<AdminStorageServer[]>;
|
|
240
|
+
createServer(input: AdminStorageServerInput): Promise<{
|
|
241
|
+
ok: boolean;
|
|
242
|
+
serverId: string;
|
|
243
|
+
}>;
|
|
244
|
+
patchServer(serverId: string, input: AdminStorageServerPatchInput): Promise<{
|
|
245
|
+
ok: boolean;
|
|
246
|
+
serverId: string;
|
|
247
|
+
}>;
|
|
248
|
+
deleteServer(serverId: string): Promise<{
|
|
249
|
+
ok: boolean;
|
|
250
|
+
serverId: string;
|
|
251
|
+
removedObjects: number;
|
|
252
|
+
}>;
|
|
253
|
+
awsConfig(serverId: string): Promise<AdminStorageAwsConfig>;
|
|
254
|
+
uploadObject(input: AdminStorageUploadInput): Promise<AdminStorageObjectResult>;
|
|
255
|
+
downloadObject(input: AdminStorageDownloadInput): Promise<AdminStorageObjectResult>;
|
|
256
|
+
deleteObject(input: AdminStorageDeleteInput | AdminDeleteObjectsInput): Promise<AdminStorageObjectResult | {
|
|
257
|
+
ok: boolean;
|
|
258
|
+
deleted: string[];
|
|
259
|
+
errors: Record<string, string>;
|
|
260
|
+
}>;
|
|
261
|
+
createSignedUrl(input: AdminStorageSignedUrlInput): Promise<AdminStorageSignedUrlResult>;
|
|
262
|
+
setRules(input: {
|
|
263
|
+
rules?: Record<string, unknown>;
|
|
264
|
+
rulesDsl?: string;
|
|
265
|
+
rulesHistoryPolicy?: AdminStorageRulesPolicy;
|
|
266
|
+
}): Promise<{
|
|
267
|
+
id: string;
|
|
268
|
+
}>;
|
|
269
|
+
validateRules(rulesDsl: string): Promise<{
|
|
270
|
+
valid: boolean;
|
|
271
|
+
diagnostics: unknown[];
|
|
272
|
+
rulesCount: number;
|
|
273
|
+
}>;
|
|
274
|
+
rulesHistory(): Promise<AdminStorageRulesHistoryResult>;
|
|
275
|
+
restoreRules(historyId: string): Promise<{
|
|
276
|
+
id: string;
|
|
277
|
+
rulesText: string;
|
|
278
|
+
}>;
|
|
279
|
+
createBucket(name: string, options?: AdminStorageBucketInput): Promise<AdminStorageBucket>;
|
|
280
|
+
listBuckets(): Promise<AdminStorageBucket[]>;
|
|
281
|
+
deleteBucket(name: string): Promise<{
|
|
282
|
+
ok: boolean;
|
|
283
|
+
removedObjects: number;
|
|
284
|
+
}>;
|
|
285
|
+
deleteBuckets(names: string[]): Promise<{
|
|
286
|
+
ok: boolean;
|
|
287
|
+
deleted: string[];
|
|
288
|
+
errors: Record<string, string>;
|
|
289
|
+
}>;
|
|
290
|
+
getBucketLocation(name: string): Promise<{
|
|
291
|
+
bucket: string;
|
|
292
|
+
kind: string;
|
|
293
|
+
region?: string;
|
|
294
|
+
endpoint?: string;
|
|
295
|
+
}>;
|
|
296
|
+
putObject(input: AdminPutObjectInput): Promise<AdminPutObjectResult>;
|
|
297
|
+
getObject(input: AdminGetObjectInput): Promise<AdminGetObjectResult>;
|
|
298
|
+
getObjectUrl(input: AdminGetObjectUrlInput): Promise<string>;
|
|
299
|
+
downloadObject(input: AdminDownloadObjectInput): Promise<AdminDownloadObjectResult>;
|
|
300
|
+
headObject(input: AdminHeadObjectInput): Promise<AdminStorageObjectMeta>;
|
|
301
|
+
headObjects(input: AdminHeadObjectsInput): Promise<AdminStorageObjectMeta[]>;
|
|
302
|
+
listObjects(input: AdminListObjectsInput): Promise<AdminListObjectsResult>;
|
|
303
|
+
copyObject(input: AdminCopyObjectInput): Promise<{
|
|
304
|
+
ok: boolean;
|
|
305
|
+
}>;
|
|
306
|
+
copyObjects(inputs: AdminCopyObjectInput[]): Promise<{
|
|
307
|
+
ok: boolean;
|
|
308
|
+
errors: Record<string, string>;
|
|
309
|
+
}>;
|
|
310
|
+
deleteObjects(input: AdminDeleteObjectsInput): Promise<{
|
|
311
|
+
ok: boolean;
|
|
312
|
+
deleted: string[];
|
|
313
|
+
errors: Record<string, string>;
|
|
314
|
+
}>;
|
|
315
|
+
}
|
|
316
|
+
interface AdminStorageBucket {
|
|
317
|
+
id: string;
|
|
318
|
+
name: string;
|
|
319
|
+
bucket: string;
|
|
320
|
+
kind: string;
|
|
321
|
+
region?: string;
|
|
322
|
+
endpoint?: string;
|
|
323
|
+
prefix?: string;
|
|
324
|
+
frozen?: boolean;
|
|
325
|
+
readOnly?: boolean;
|
|
326
|
+
createdAt?: unknown;
|
|
327
|
+
updatedAt?: unknown;
|
|
328
|
+
}
|
|
329
|
+
interface AdminStorageBucketInput {
|
|
330
|
+
kind?: string;
|
|
331
|
+
prefix?: string;
|
|
332
|
+
region?: string;
|
|
333
|
+
endpoint?: string;
|
|
334
|
+
accessKey?: string;
|
|
335
|
+
secretKey?: string;
|
|
336
|
+
dataDir?: string;
|
|
337
|
+
forcePathStyle?: boolean;
|
|
338
|
+
}
|
|
339
|
+
interface AdminStorageObjectMeta {
|
|
340
|
+
key: string;
|
|
341
|
+
bucket: string;
|
|
342
|
+
size: number;
|
|
343
|
+
contentType: string;
|
|
344
|
+
encrypted: boolean;
|
|
345
|
+
createdAt?: unknown;
|
|
346
|
+
updatedAt?: unknown;
|
|
347
|
+
}
|
|
348
|
+
interface AdminPutObjectInput {
|
|
349
|
+
bucket: string;
|
|
350
|
+
key: string;
|
|
351
|
+
body?: string | Uint8Array | ArrayBuffer | Buffer;
|
|
352
|
+
/** Pre-encoded base64 body. Mutually exclusive with `body`. Always uses base64 path. */
|
|
353
|
+
contentBase64?: string;
|
|
354
|
+
contentType?: string;
|
|
355
|
+
/** Encrypt at rest with AES-256-GCM. Defaults to true. */
|
|
356
|
+
encrypt?: boolean;
|
|
357
|
+
/**
|
|
358
|
+
* Max payload bytes for the base64-over-JSON upload path.
|
|
359
|
+
* Payloads larger than this are uploaded via a signed URL (raw binary PUT).
|
|
360
|
+
* Default: 4 MiB.
|
|
361
|
+
*/
|
|
362
|
+
base64MaxBytes?: number;
|
|
363
|
+
}
|
|
364
|
+
interface AdminPutObjectResult {
|
|
365
|
+
ok: boolean;
|
|
366
|
+
bucket: string;
|
|
367
|
+
key: string;
|
|
368
|
+
size: number;
|
|
369
|
+
encrypted: boolean;
|
|
370
|
+
}
|
|
371
|
+
interface AdminGetObjectInput {
|
|
372
|
+
bucket: string;
|
|
373
|
+
key: string;
|
|
374
|
+
decrypt?: boolean;
|
|
375
|
+
}
|
|
376
|
+
interface AdminGetObjectResult {
|
|
377
|
+
ok: boolean;
|
|
378
|
+
bucket: string;
|
|
379
|
+
key: string;
|
|
380
|
+
contentBase64: string;
|
|
381
|
+
contentType: string;
|
|
382
|
+
size: number;
|
|
383
|
+
encrypted: boolean;
|
|
384
|
+
}
|
|
385
|
+
interface AdminHeadObjectInput {
|
|
386
|
+
bucket: string;
|
|
387
|
+
key: string;
|
|
388
|
+
}
|
|
389
|
+
interface AdminHeadObjectsInput {
|
|
390
|
+
bucket: string;
|
|
391
|
+
keys: string[];
|
|
392
|
+
}
|
|
393
|
+
interface AdminListObjectsInput {
|
|
394
|
+
bucket: string;
|
|
395
|
+
prefix?: string;
|
|
396
|
+
limit?: number;
|
|
397
|
+
cursor?: string;
|
|
398
|
+
}
|
|
399
|
+
interface AdminListObjectsResult {
|
|
400
|
+
bucket: string;
|
|
401
|
+
objects: AdminStorageObjectMeta[];
|
|
402
|
+
count: number;
|
|
403
|
+
hasMore: boolean;
|
|
404
|
+
cursor?: string;
|
|
405
|
+
}
|
|
406
|
+
interface AdminCopyObjectInput {
|
|
407
|
+
sourceBucket: string;
|
|
408
|
+
sourceKey: string;
|
|
409
|
+
destBucket: string;
|
|
410
|
+
destKey: string;
|
|
411
|
+
}
|
|
412
|
+
interface AdminDeleteObjectsInput {
|
|
413
|
+
bucket: string;
|
|
414
|
+
keys: string[];
|
|
415
|
+
}
|
|
92
416
|
type QueryOperator = "==" | "!=" | "<" | "<=" | ">" | ">=" | "in" | "not-in" | "array-contains" | "array-contains-any" | "elem-match" | "like" | "not-like" | "contains" | "exists" | "not-exists";
|
|
93
417
|
interface WhereFilter {
|
|
94
418
|
field: string;
|
|
@@ -277,6 +601,39 @@ type AdminDocAddedCallback<T = unknown> = (data: T, docId: string) => void;
|
|
|
277
601
|
type AdminDocUpdatedCallback<T = unknown> = (data: T, docId: string) => void;
|
|
278
602
|
type AdminDocDeletedCallback = (docId: string) => void;
|
|
279
603
|
type AdminDocChangedCallback<T = unknown> = (data: T | null, docId: string, operation: "insert" | "update" | "delete" | "replace") => void;
|
|
604
|
+
type AdminStreamFlushReason = "snapshot" | "change-batch";
|
|
605
|
+
interface AdminCollectionStreamOptions<T = unknown> {
|
|
606
|
+
flushMs?: number;
|
|
607
|
+
maxBatchSize?: number;
|
|
608
|
+
idField?: keyof T & string;
|
|
609
|
+
getId?: (doc: T) => string | undefined;
|
|
610
|
+
insertAt?: "start" | "end";
|
|
611
|
+
maxDocs?: number;
|
|
612
|
+
sort?: (a: T, b: T) => number;
|
|
613
|
+
}
|
|
614
|
+
interface AdminCollectionStreamMeta {
|
|
615
|
+
reason: AdminStreamFlushReason;
|
|
616
|
+
batchSize: number;
|
|
617
|
+
version: number;
|
|
618
|
+
ready: boolean;
|
|
619
|
+
}
|
|
620
|
+
type AdminCollectionStreamListener<T = unknown> = (rows: readonly T[], meta: AdminCollectionStreamMeta) => void;
|
|
621
|
+
interface AdminCollectionStream<T = unknown> {
|
|
622
|
+
subscribe: (listener: AdminCollectionStreamListener<T>, emitCurrent?: boolean) => () => void;
|
|
623
|
+
getSnapshot: () => readonly T[];
|
|
624
|
+
isReady: () => boolean;
|
|
625
|
+
getVersion: () => number;
|
|
626
|
+
close: () => void;
|
|
627
|
+
onError: (callback: AdminSubscriptionErrorCallback) => AdminCollectionStream<T>;
|
|
628
|
+
onPermissionDenied: (callback: AdminSubscriptionErrorCallback) => AdminCollectionStream<T>;
|
|
629
|
+
}
|
|
630
|
+
interface AdminCollectionExternalStore<T = unknown> {
|
|
631
|
+
subscribe: (onStoreChange: () => void) => () => void;
|
|
632
|
+
getSnapshot: () => readonly T[];
|
|
633
|
+
getServerSnapshot: () => readonly T[];
|
|
634
|
+
stream: AdminCollectionStream<T>;
|
|
635
|
+
destroy: () => void;
|
|
636
|
+
}
|
|
280
637
|
interface AdminSubscribeOptions {
|
|
281
638
|
skipSnapshot?: boolean;
|
|
282
639
|
}
|
|
@@ -454,6 +811,104 @@ declare class FlareAdminNotificationsService implements FlareAdminNotifications
|
|
|
454
811
|
}>;
|
|
455
812
|
}
|
|
456
813
|
|
|
814
|
+
declare class FlareAdminStorageService {
|
|
815
|
+
private readonly cfg;
|
|
816
|
+
constructor(cfg: Required<FlareAdminConfig>);
|
|
817
|
+
private base;
|
|
818
|
+
private get headers();
|
|
819
|
+
protected jsonRequest<T>(method: string, path: string, body?: unknown): Promise<T>;
|
|
820
|
+
request<T>(method: string, path: string, body?: unknown): Promise<T>;
|
|
821
|
+
servers(): Promise<AdminStorageServer[]>;
|
|
822
|
+
createServer(input: AdminStorageServerInput): Promise<{
|
|
823
|
+
ok: boolean;
|
|
824
|
+
serverId: string;
|
|
825
|
+
}>;
|
|
826
|
+
patchServer(serverId: string, input: AdminStorageServerPatchInput): Promise<{
|
|
827
|
+
ok: boolean;
|
|
828
|
+
serverId: string;
|
|
829
|
+
}>;
|
|
830
|
+
deleteServer(serverId: string): Promise<{
|
|
831
|
+
ok: boolean;
|
|
832
|
+
serverId: string;
|
|
833
|
+
removedObjects: number;
|
|
834
|
+
}>;
|
|
835
|
+
awsConfig(serverId: string): Promise<AdminStorageAwsConfig>;
|
|
836
|
+
uploadObject(input: AdminStorageUploadInput): Promise<AdminStorageObjectResult>;
|
|
837
|
+
downloadObject(input: AdminStorageDownloadInput): Promise<AdminStorageObjectResult>;
|
|
838
|
+
deleteObject(input: AdminStorageDeleteInput): Promise<AdminStorageObjectResult>;
|
|
839
|
+
createSignedUrl(input: AdminStorageSignedUrlInput): Promise<AdminStorageSignedUrlResult>;
|
|
840
|
+
setRules(input: {
|
|
841
|
+
rules?: Record<string, unknown>;
|
|
842
|
+
rulesDsl?: string;
|
|
843
|
+
rulesHistoryPolicy?: AdminStorageRulesPolicy;
|
|
844
|
+
}): Promise<{
|
|
845
|
+
id: string;
|
|
846
|
+
}>;
|
|
847
|
+
validateRules(rulesDsl: string): Promise<{
|
|
848
|
+
valid: boolean;
|
|
849
|
+
diagnostics: unknown[];
|
|
850
|
+
rulesCount: number;
|
|
851
|
+
}>;
|
|
852
|
+
rulesHistory(): Promise<AdminStorageRulesHistoryResult>;
|
|
853
|
+
restoreRules(historyId: string): Promise<{
|
|
854
|
+
id: string;
|
|
855
|
+
rulesText: string;
|
|
856
|
+
}>;
|
|
857
|
+
}
|
|
858
|
+
/**
|
|
859
|
+
* S3-compatible admin storage service.
|
|
860
|
+
* Works with bucket names; resolves server IDs internally.
|
|
861
|
+
*/
|
|
862
|
+
declare class FlareAdminStorageS3 {
|
|
863
|
+
private readonly _svc;
|
|
864
|
+
private readonly _bucketCache;
|
|
865
|
+
private _bucketListLoaded;
|
|
866
|
+
private _bucketListPromise;
|
|
867
|
+
constructor(svc: FlareAdminStorageService);
|
|
868
|
+
private _ensureBuckets;
|
|
869
|
+
private _loadBuckets;
|
|
870
|
+
private _invalidateCache;
|
|
871
|
+
private _resolveBucketId;
|
|
872
|
+
createBucket(name: string, options?: AdminStorageBucketInput): Promise<AdminStorageBucket>;
|
|
873
|
+
listBuckets(): Promise<AdminStorageBucket[]>;
|
|
874
|
+
deleteBucket(name: string): Promise<{
|
|
875
|
+
ok: boolean;
|
|
876
|
+
removedObjects: number;
|
|
877
|
+
}>;
|
|
878
|
+
deleteBuckets(names: string[]): Promise<{
|
|
879
|
+
ok: boolean;
|
|
880
|
+
deleted: string[];
|
|
881
|
+
errors: Record<string, string>;
|
|
882
|
+
}>;
|
|
883
|
+
getBucketLocation(name: string): Promise<{
|
|
884
|
+
bucket: string;
|
|
885
|
+
kind: string;
|
|
886
|
+
region?: string;
|
|
887
|
+
endpoint?: string;
|
|
888
|
+
}>;
|
|
889
|
+
putObject(input: AdminPutObjectInput): Promise<AdminPutObjectResult>;
|
|
890
|
+
getObject(input: AdminGetObjectInput): Promise<AdminGetObjectResult>;
|
|
891
|
+
getObjectUrl(input: AdminGetObjectUrlInput): Promise<string>;
|
|
892
|
+
downloadObject(input: AdminDownloadObjectInput): Promise<AdminDownloadObjectResult>;
|
|
893
|
+
headObject(input: AdminHeadObjectInput): Promise<AdminStorageObjectMeta>;
|
|
894
|
+
headObjects(input: AdminHeadObjectsInput): Promise<AdminStorageObjectMeta[]>;
|
|
895
|
+
listObjects(input: AdminListObjectsInput): Promise<AdminListObjectsResult>;
|
|
896
|
+
copyObject(input: AdminCopyObjectInput): Promise<{
|
|
897
|
+
ok: boolean;
|
|
898
|
+
}>;
|
|
899
|
+
copyObjects(inputs: AdminCopyObjectInput[]): Promise<{
|
|
900
|
+
ok: boolean;
|
|
901
|
+
errors: Record<string, string>;
|
|
902
|
+
}>;
|
|
903
|
+
deleteObject(input: AdminStorageDeleteInput): Promise<AdminStorageObjectResult>;
|
|
904
|
+
deleteObjects(input: AdminDeleteObjectsInput): Promise<{
|
|
905
|
+
ok: boolean;
|
|
906
|
+
deleted: string[];
|
|
907
|
+
errors: Record<string, string>;
|
|
908
|
+
}>;
|
|
909
|
+
createSignedUrl(input: AdminStorageSignedUrlInput): Promise<AdminStorageSignedUrlResult>;
|
|
910
|
+
}
|
|
911
|
+
|
|
457
912
|
type AdminRealtimeSubscriber$1 = {
|
|
458
913
|
subscribe: (collection: string, docId: string | undefined, structuredQuery: StructuredQuery | undefined, callback: AdminSnapshotCallback, options?: AdminSubscribeOptions) => AdminSubscriptionHandle;
|
|
459
914
|
};
|
|
@@ -569,6 +1024,8 @@ declare class AdminLiveCollectionReference<T = Record<string, unknown>> {
|
|
|
569
1024
|
query: StructuredQuery;
|
|
570
1025
|
};
|
|
571
1026
|
onSnapshot(callback: AdminSnapshotCallback<T[]>): () => void;
|
|
1027
|
+
stream(options?: AdminCollectionStreamOptions<T>): AdminCollectionStream<T>;
|
|
1028
|
+
asStore(options?: AdminCollectionStreamOptions<T>): AdminCollectionExternalStore<T>;
|
|
572
1029
|
onDocAdded(callback: AdminDocAddedCallback<T>): () => void;
|
|
573
1030
|
onDocUpdated(callback: AdminDocUpdatedCallback<T>): () => void;
|
|
574
1031
|
onDocDeleted(callback: AdminDocDeletedCallback): () => void;
|
|
@@ -605,6 +1062,19 @@ declare class FlareAdminConnection {
|
|
|
605
1062
|
collection<T = Record<string, unknown>>(name: string): AdminLiveCollectionReference<T>;
|
|
606
1063
|
/** Wait until the WebSocket is open and authenticated. */
|
|
607
1064
|
ready(): Promise<void>;
|
|
1065
|
+
/** Current connection state. */
|
|
1066
|
+
get connectionState(): AdminConnectionState;
|
|
1067
|
+
/**
|
|
1068
|
+
* Subscribe to connection state changes.
|
|
1069
|
+
* Returns an unsubscribe function.
|
|
1070
|
+
*
|
|
1071
|
+
* @example
|
|
1072
|
+
* const unsub = admin.live().onConnectionStateChange((state) => {
|
|
1073
|
+
* console.log("connection:", state);
|
|
1074
|
+
* });
|
|
1075
|
+
* // state: 'connecting' | 'connected' | 'disconnected' | 'reconnecting' | 'error'
|
|
1076
|
+
*/
|
|
1077
|
+
onConnectionStateChange(listener: AdminConnectionStateListener): () => void;
|
|
608
1078
|
/** Close the WebSocket connection permanently (no reconnect). */
|
|
609
1079
|
disconnect(): void;
|
|
610
1080
|
}
|
|
@@ -626,12 +1096,21 @@ declare class FlareAdminWsConnection {
|
|
|
626
1096
|
private connected;
|
|
627
1097
|
private shouldReconnect;
|
|
628
1098
|
private reconnectDelay;
|
|
1099
|
+
private _state;
|
|
1100
|
+
private _stateListeners;
|
|
629
1101
|
private readonly wsUrl;
|
|
630
1102
|
private _readyResolve;
|
|
631
1103
|
private _readyPromise;
|
|
632
1104
|
constructor(cfg: Required<FlareAdminConfig>);
|
|
633
1105
|
/** Resolves once the WS is open and AUTH_OK is received from the server. */
|
|
634
1106
|
ready(): Promise<void>;
|
|
1107
|
+
/** Current connection state. */
|
|
1108
|
+
get connectionState(): AdminConnectionState;
|
|
1109
|
+
/**
|
|
1110
|
+
* Subscribe to connection state changes.
|
|
1111
|
+
* Returns an unsubscribe function.
|
|
1112
|
+
*/
|
|
1113
|
+
onConnectionStateChange(listener: AdminConnectionStateListener): () => void;
|
|
635
1114
|
/** Close the connection permanently (no reconnect). */
|
|
636
1115
|
disconnect(): void;
|
|
637
1116
|
/**
|
|
@@ -648,51 +1127,24 @@ declare class FlareAdminWsConnection {
|
|
|
648
1127
|
private replayActiveSubscriptions;
|
|
649
1128
|
private toSubscriptionError;
|
|
650
1129
|
private emitSubscriptionError;
|
|
1130
|
+
private _setState;
|
|
651
1131
|
private _connect;
|
|
652
1132
|
private _handle;
|
|
653
1133
|
}
|
|
654
1134
|
|
|
655
1135
|
/**
|
|
656
|
-
*
|
|
657
|
-
*
|
|
658
|
-
* Server-side admin SDK for FlareServer.
|
|
659
|
-
* Runs only on your backend, never in a browser.
|
|
660
|
-
*
|
|
661
|
-
* ─── Quick start ──────────────────────────────────────────────────────────────
|
|
662
|
-
*
|
|
663
|
-
* import { connectApp } from "@zuzjs/flare-admin";
|
|
1136
|
+
* Sentinel value that asks flare-node to write the current server timestamp.
|
|
664
1137
|
*
|
|
665
|
-
*
|
|
666
|
-
*
|
|
667
|
-
* appId: process.env.FLARE_APP_ID!,
|
|
668
|
-
* adminKey: process.env.FLARE_ADMIN_KEY!,
|
|
669
|
-
* });
|
|
670
|
-
*
|
|
671
|
-
* // Mint a custom auth token (for use by the browser client)
|
|
672
|
-
* const token = await admin.auth().createCustomToken(String(user.id), {
|
|
673
|
-
* role: user.isAdmin ? "admin" : "user",
|
|
674
|
-
* claims: { email: user.email, plan: user.plan },
|
|
675
|
-
* });
|
|
676
|
-
*
|
|
677
|
-
* // One-shot DB queries (bypasses security rules)
|
|
678
|
-
* const users = await admin.db().collection("users").get();
|
|
679
|
-
* await admin.db().collection("users").doc("alice").set({ name: "Alice" });
|
|
680
|
-
*
|
|
681
|
-
* // Rich queries
|
|
682
|
-
* const seniors = await admin.db()
|
|
683
|
-
* .collection("users")
|
|
684
|
-
* .where({ age: ">= 60" })
|
|
685
|
-
* .orderBy("name")
|
|
686
|
-
* .limit(10)
|
|
687
|
-
* .get();
|
|
688
|
-
*
|
|
689
|
-
* // Real-time subscriptions over WebSocket
|
|
690
|
-
* const unsub = admin.connection()
|
|
691
|
-
* .collection("orders")
|
|
692
|
-
* .where({ status: "pending" })
|
|
693
|
-
* .orderBy("createdAt", "desc")
|
|
694
|
-
* .onSnapshot((snap) => console.log(snap));
|
|
1138
|
+
* Usage:
|
|
1139
|
+
* await admin.db().collection("posts").doc(id).update({ updatedAt: ServerTimeStamp })
|
|
695
1140
|
*/
|
|
1141
|
+
declare const ServerTimeStamp: "ServerTimeStamp";
|
|
1142
|
+
/**
|
|
1143
|
+
* Object form of the same sentinel for payloads that prefer structured values.
|
|
1144
|
+
*/
|
|
1145
|
+
declare const ServerTimeStampField: {
|
|
1146
|
+
readonly $serverTimestamp: true;
|
|
1147
|
+
};
|
|
696
1148
|
|
|
697
1149
|
/**
|
|
698
1150
|
* A FlareAdmin application instance.
|
|
@@ -704,6 +1156,8 @@ declare class FlareAdminApp {
|
|
|
704
1156
|
private _db?;
|
|
705
1157
|
private _conn?;
|
|
706
1158
|
private _notifications?;
|
|
1159
|
+
private _storage?;
|
|
1160
|
+
private _storageS3?;
|
|
707
1161
|
/**
|
|
708
1162
|
* Access the auth service.
|
|
709
1163
|
*
|
|
@@ -738,7 +1192,7 @@ declare class FlareAdminApp {
|
|
|
738
1192
|
* `groupBy`, `having`, `Join`, `select`, `distinctField`, `vectorSearch`.
|
|
739
1193
|
*
|
|
740
1194
|
* @example
|
|
741
|
-
* const unsub = admin.
|
|
1195
|
+
* const unsub = admin.live()
|
|
742
1196
|
* .collection("orders")
|
|
743
1197
|
* .where({ status: "pending" })
|
|
744
1198
|
* .orderBy("createdAt", "desc")
|
|
@@ -748,19 +1202,86 @@ declare class FlareAdminApp {
|
|
|
748
1202
|
* else console.log(snap.operation, snap.data);
|
|
749
1203
|
* });
|
|
750
1204
|
*
|
|
751
|
-
* const unsub2 = admin.
|
|
1205
|
+
* const unsub2 = admin.live()
|
|
752
1206
|
* .collection("users").doc("alice")
|
|
753
1207
|
* .onSnapshot((snap) => console.log(snap.data));
|
|
754
1208
|
*
|
|
755
1209
|
* unsub();
|
|
756
1210
|
* unsub2();
|
|
757
|
-
* admin.
|
|
1211
|
+
* admin.live().disconnect();
|
|
758
1212
|
*/
|
|
759
|
-
|
|
1213
|
+
live(): FlareAdminConnection;
|
|
760
1214
|
/**
|
|
761
1215
|
* Access push notification management APIs.
|
|
762
1216
|
*/
|
|
763
1217
|
notifications(): FlareAdminNotifications;
|
|
1218
|
+
private storageService;
|
|
1219
|
+
storage(): FlareAdminStorageS3;
|
|
1220
|
+
/**
|
|
1221
|
+
* S3-compatible storage service. Works with bucket names; no server IDs needed.
|
|
1222
|
+
* Bucket is auto-created on putObject() if it doesn't exist.
|
|
1223
|
+
*
|
|
1224
|
+
* @example
|
|
1225
|
+
* await admin.s3().putObject({ bucket: 'avatars', key: 'alice.png', body: buffer });
|
|
1226
|
+
* const { contentBase64 } = await admin.s3().getObject({ bucket: 'avatars', key: 'alice.png' });
|
|
1227
|
+
*/
|
|
1228
|
+
s3(): FlareAdminStorageS3;
|
|
1229
|
+
createSignedUrl(input: AdminStorageSignedUrlInput): Promise<AdminStorageSignedUrlResult>;
|
|
1230
|
+
createBucket(name: string, options?: AdminStorageBucketInput): Promise<AdminStorageBucket>;
|
|
1231
|
+
listBuckets(): Promise<AdminStorageBucket[]>;
|
|
1232
|
+
deleteBucket(name: string): Promise<{
|
|
1233
|
+
ok: boolean;
|
|
1234
|
+
removedObjects: number;
|
|
1235
|
+
}>;
|
|
1236
|
+
deleteBuckets(names: string[]): Promise<{
|
|
1237
|
+
ok: boolean;
|
|
1238
|
+
deleted: string[];
|
|
1239
|
+
errors: Record<string, string>;
|
|
1240
|
+
}>;
|
|
1241
|
+
getBucketLocation(name: string): Promise<{
|
|
1242
|
+
bucket: string;
|
|
1243
|
+
kind: string;
|
|
1244
|
+
region?: string;
|
|
1245
|
+
endpoint?: string;
|
|
1246
|
+
}>;
|
|
1247
|
+
putObject(input: AdminPutObjectInput): Promise<AdminPutObjectResult>;
|
|
1248
|
+
getObject(input: AdminGetObjectInput): Promise<AdminGetObjectResult>;
|
|
1249
|
+
getObjectUrl(input: AdminGetObjectUrlInput): Promise<string>;
|
|
1250
|
+
downloadObject(input: AdminDownloadObjectInput): Promise<AdminDownloadObjectResult>;
|
|
1251
|
+
headObject(input: AdminHeadObjectInput): Promise<AdminStorageObjectMeta>;
|
|
1252
|
+
headObjects(input: AdminHeadObjectsInput): Promise<AdminStorageObjectMeta[]>;
|
|
1253
|
+
listObjects(input: AdminListObjectsInput): Promise<AdminListObjectsResult>;
|
|
1254
|
+
copyObject(input: AdminCopyObjectInput): Promise<{
|
|
1255
|
+
ok: boolean;
|
|
1256
|
+
}>;
|
|
1257
|
+
copyObjects(inputs: AdminCopyObjectInput[]): Promise<{
|
|
1258
|
+
ok: boolean;
|
|
1259
|
+
errors: Record<string, string>;
|
|
1260
|
+
}>;
|
|
1261
|
+
deleteObjects(input: AdminDeleteObjectsInput): Promise<{
|
|
1262
|
+
ok: boolean;
|
|
1263
|
+
deleted: string[];
|
|
1264
|
+
errors: Record<string, string>;
|
|
1265
|
+
}>;
|
|
1266
|
+
/**
|
|
1267
|
+
* Subscribe to WebSocket connection state changes.
|
|
1268
|
+
* Initializes the live connection if not already open.
|
|
1269
|
+
* Returns an unsubscribe function.
|
|
1270
|
+
*
|
|
1271
|
+
* @example
|
|
1272
|
+
* const unsub = admin.onConnectionStateChange((state) => {
|
|
1273
|
+
* console.log("connection:", state);
|
|
1274
|
+
* // state: 'connecting' | 'connected' | 'disconnected' | 'reconnecting' | 'error'
|
|
1275
|
+
* });
|
|
1276
|
+
* // Later:
|
|
1277
|
+
* unsub();
|
|
1278
|
+
*/
|
|
1279
|
+
onConnectionStateChange(listener: (state: AdminConnectionState) => void): () => void;
|
|
1280
|
+
/**
|
|
1281
|
+
* Disconnect realtime resources tied to this app instance.
|
|
1282
|
+
* Safe to call multiple times.
|
|
1283
|
+
*/
|
|
1284
|
+
disconnect(): void;
|
|
764
1285
|
}
|
|
765
1286
|
/**
|
|
766
1287
|
* Initialize a FlareAdmin app instance.
|
|
@@ -782,6 +1303,15 @@ declare function connectApp(config: FlareAdminConfig, name?: string): FlareAdmin
|
|
|
782
1303
|
* @throws If the app has not been initialized yet.
|
|
783
1304
|
*/
|
|
784
1305
|
declare function getApp(name?: string): FlareAdminApp;
|
|
1306
|
+
/**
|
|
1307
|
+
* Disconnect and remove an initialized app by name.
|
|
1308
|
+
* Returns true when an app existed and was removed.
|
|
1309
|
+
*/
|
|
1310
|
+
declare function disconnectApp(name?: string): boolean;
|
|
1311
|
+
/**
|
|
1312
|
+
* Disconnect and clear all initialized apps.
|
|
1313
|
+
*/
|
|
1314
|
+
declare function disconnectAllApps(): void;
|
|
785
1315
|
/**
|
|
786
1316
|
* Get the auth service from the default app.
|
|
787
1317
|
* Equivalent to `getApp().auth()`.
|
|
@@ -802,19 +1332,20 @@ declare function auth(name?: string): FlareAdminAuth;
|
|
|
802
1332
|
declare function db(name?: string): FlareAdminDb;
|
|
803
1333
|
/**
|
|
804
1334
|
* Get the real-time WebSocket connection from the default app.
|
|
805
|
-
* Equivalent to `getApp().
|
|
1335
|
+
* Equivalent to `getApp().live()`.
|
|
806
1336
|
*
|
|
807
1337
|
* @example
|
|
808
|
-
* import {
|
|
809
|
-
* const unsub =
|
|
1338
|
+
* import { live } from "@zuzjs/flare-admin";
|
|
1339
|
+
* const unsub = live().collection("users")
|
|
810
1340
|
* .where({ role: "admin" })
|
|
811
1341
|
* .onSnapshot((snap) => console.log(snap));
|
|
812
1342
|
*/
|
|
813
|
-
declare function
|
|
1343
|
+
declare function live(name?: string): FlareAdminConnection;
|
|
814
1344
|
/**
|
|
815
1345
|
* Get the notifications service from the default app.
|
|
816
1346
|
* Equivalent to `getApp().notifications()`.
|
|
817
1347
|
*/
|
|
818
1348
|
declare function notifications(name?: string): FlareAdminNotifications;
|
|
1349
|
+
declare function storage(name?: string): FlareAdminStorageS3;
|
|
819
1350
|
|
|
820
|
-
export { AdminCollectionReference, type AdminDocAddedCallback, type AdminDocChangedCallback, type AdminDocDeletedCallback, type AdminDocUpdatedCallback, AdminDocumentReference, AdminLiveCollectionReference, AdminLiveDocumentReference, type AdminPushSendInput, type AdminPushSendResult, type AdminPushToken, type AdminSnapshotCallback, type AdminSnapshotData, type AdminSubscriptionError, type AdminSubscriptionErrorCallback, type AdminSubscriptionHandle, type AggregateFunction, type AggregateSpec, type AnyFilter, type CreateCustomTokenOptions, type CursorValue, FlareAdminApp, type FlareAdminAuth, FlareAdminAuthService, type FlareAdminConfig, FlareAdminConnection, type FlareAdminDb, FlareAdminDbService, type FlareAdminNotifications, FlareAdminNotificationsService, FlareAdminWsConnection, type GroupByClause, type HavingClause, type JoinClause, type OrFilter, type OrderByClause, type QueryOperator, type StructuredQuery, type VectorSearchClause, type WhereCondition, type WhereFilter, auth, connectApp,
|
|
1351
|
+
export { AdminCollectionReference, type AdminConnectionState, type AdminConnectionStateListener, type AdminCopyObjectInput, type AdminDeleteObjectsInput, type AdminDocAddedCallback, type AdminDocChangedCallback, type AdminDocDeletedCallback, type AdminDocUpdatedCallback, AdminDocumentReference, type AdminDownloadObjectInput, type AdminDownloadObjectResult, type AdminGetObjectInput, type AdminGetObjectResult, type AdminGetObjectUrlInput, type AdminHeadObjectInput, type AdminHeadObjectsInput, type AdminListObjectsInput, type AdminListObjectsResult, AdminLiveCollectionReference, AdminLiveDocumentReference, type AdminPushSendInput, type AdminPushSendResult, type AdminPushToken, type AdminPutObjectInput, type AdminPutObjectResult, type AdminSnapshotCallback, type AdminSnapshotData, type AdminStorageAwsConfig, type AdminStorageBucket, type AdminStorageBucketInput, type AdminStorageDeleteInput, type AdminStorageDownloadInput, type AdminStorageObjectMeta, type AdminStorageObjectResult, type AdminStorageRulesHistoryResult, type AdminStorageRulesPolicy, type AdminStorageServer, type AdminStorageServerInput, type AdminStorageServerPatchInput, AdminStorageSignedAction, type AdminStorageSignedUrlInput, type AdminStorageSignedUrlResult, type AdminStorageUploadInput, type AdminSubscriptionError, type AdminSubscriptionErrorCallback, type AdminSubscriptionHandle, type AggregateFunction, type AggregateSpec, type AnyFilter, type CreateCustomTokenOptions, type CursorValue, FlareAdminApp, type FlareAdminAuth, FlareAdminAuthService, type FlareAdminConfig, FlareAdminConnection, type FlareAdminDb, FlareAdminDbService, type FlareAdminNotifications, FlareAdminNotificationsService, type FlareAdminStorage, FlareAdminStorageS3, FlareAdminWsConnection, type GroupByClause, type HavingClause, type JoinClause, type OrFilter, type OrderByClause, type QueryOperator, ServerTimeStamp, ServerTimeStampField, type StructuredQuery, type VectorSearchClause, type WhereCondition, type WhereFilter, auth, connectApp, db, disconnectAllApps, disconnectApp, getApp, live, notifications, storage };
|