@zuzjs/flare-admin 0.1.1

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.
@@ -0,0 +1,793 @@
1
+ interface FlareAdminConfig {
2
+ /**
3
+ * Base URL of your FlareServer instance.
4
+ * Self-hosted: "http://localhost:5050"
5
+ * SaaS: "https://www.zedgon.io"
6
+ */
7
+ serverUrl: string;
8
+ /** The app ID created with `flare app create` */
9
+ appId: string;
10
+ /**
11
+ * Admin key printed when you run `flare app create`.
12
+ * Keep in an environment variable — NEVER expose to the browser.
13
+ */
14
+ adminKey: string;
15
+ /** Default token TTL, e.g. "24h" */
16
+ defaultTtl?: string;
17
+ }
18
+ interface CreateCustomTokenOptions {
19
+ role?: "user" | "admin" | "anon";
20
+ claims?: Record<string, unknown>;
21
+ ttl?: string;
22
+ }
23
+ interface FlareAdminAuth {
24
+ createCustomToken(uid: string | number, opts?: CreateCustomTokenOptions): Promise<string>;
25
+ }
26
+ interface AdminPushSendInput {
27
+ title?: string;
28
+ body?: string;
29
+ image?: string;
30
+ data?: Record<string, unknown>;
31
+ tokens?: string[];
32
+ uid?: string;
33
+ topic?: string;
34
+ priority?: "normal" | "high";
35
+ ttlSeconds?: number;
36
+ dryRun?: boolean;
37
+ }
38
+ interface AdminPushSendResult {
39
+ sent: boolean;
40
+ appId: string;
41
+ targetCount: number;
42
+ successCount: number;
43
+ failureCount: number;
44
+ invalidatedTokenCount: number;
45
+ dryRun: boolean;
46
+ }
47
+ interface AdminPushToken {
48
+ token: string;
49
+ uid: string;
50
+ platform?: string;
51
+ deviceId?: string;
52
+ topics?: string[];
53
+ createdAt?: string;
54
+ updatedAt?: string;
55
+ lastSeenAt?: string;
56
+ }
57
+ interface FlareAdminNotifications {
58
+ send(input: AdminPushSendInput): Promise<AdminPushSendResult>;
59
+ tokens(): Promise<{
60
+ appId: string;
61
+ hasPushGateway: boolean;
62
+ total: number;
63
+ tokens: AdminPushToken[];
64
+ }>;
65
+ }
66
+ type QueryOperator = "==" | "!=" | "<" | "<=" | ">" | ">=" | "in" | "not-in" | "array-contains" | "array-contains-any" | "elem-match" | "like" | "not-like" | "contains" | "exists" | "not-exists";
67
+ interface WhereFilter {
68
+ field: string;
69
+ op: QueryOperator;
70
+ value: unknown;
71
+ }
72
+ /** OR group — matches if ANY inner filter matches */
73
+ interface OrFilter {
74
+ or: AnyFilter[];
75
+ }
76
+ /** AND group — matches only if ALL inner filters match */
77
+ interface AndFilter {
78
+ and: AnyFilter[];
79
+ }
80
+ type AnyFilter = WhereFilter | OrFilter | AndFilter;
81
+ /**
82
+ * ORM-style shorthand: `{ age: ">= 25", role: "admin" }`
83
+ */
84
+ type WhereCondition = Record<string, string | number | boolean | unknown[]>;
85
+ interface OrderByClause {
86
+ field: string;
87
+ dir?: "asc" | "desc";
88
+ }
89
+ interface GroupByClause {
90
+ fields: string[];
91
+ }
92
+ interface HavingClause {
93
+ field: string;
94
+ op: "==" | "!=" | "<" | "<=" | ">" | ">=";
95
+ value: number;
96
+ }
97
+ interface CursorValue {
98
+ values: unknown[];
99
+ }
100
+ type AggregateFunction = "count" | "sum" | "avg" | "min" | "max" | "distinct";
101
+ interface AggregateSpec {
102
+ fn: AggregateFunction;
103
+ field?: string;
104
+ alias?: string;
105
+ }
106
+ interface JoinClause {
107
+ source: string;
108
+ target: string;
109
+ as: string;
110
+ single?: boolean;
111
+ where?: AnyFilter[];
112
+ orderBy?: OrderByClause[];
113
+ limit?: number;
114
+ offset?: number;
115
+ select?: string[];
116
+ joins?: NestedJoinClause[];
117
+ }
118
+ interface NestedJoinClause extends JoinClause {
119
+ collection: string;
120
+ }
121
+ interface StructuredJoinClause {
122
+ from: string;
123
+ localField: string;
124
+ foreignField: string;
125
+ as: string;
126
+ single?: boolean;
127
+ where?: AnyFilter[];
128
+ orderBy?: OrderByClause[];
129
+ limit?: number;
130
+ offset?: number;
131
+ select?: string[];
132
+ joins?: StructuredJoinClause[];
133
+ }
134
+ interface VectorSearchClause {
135
+ field: string;
136
+ vector: number[];
137
+ k: number;
138
+ metric?: "cosine" | "euclidean" | "dotProduct";
139
+ minScore?: number;
140
+ }
141
+ /** Full structured query (mirrors client StructuredQuery / server StructuredQuery) */
142
+ interface StructuredQuery {
143
+ where?: AnyFilter[];
144
+ orderBy?: OrderByClause[];
145
+ limit?: number;
146
+ offset?: number;
147
+ startAt?: CursorValue;
148
+ startAfter?: CursorValue;
149
+ endAt?: CursorValue;
150
+ endBefore?: CursorValue;
151
+ aggregate?: AggregateSpec[];
152
+ groupBy?: GroupByClause;
153
+ having?: HavingClause[];
154
+ joins?: StructuredJoinClause[];
155
+ vectorSearch?: VectorSearchClause;
156
+ select?: string[];
157
+ distinctField?: string;
158
+ }
159
+ /** Minimal structural interface satisfied by AdminCollectionReference<T>. */
160
+ interface FlareAdminDb {
161
+ collection<T = Record<string, unknown>>(name: string): AdminCollectionShape<T>;
162
+ }
163
+ interface AdminDocumentShape<T> {
164
+ get(): Promise<T | null>;
165
+ set(data: Partial<T>): Promise<void>;
166
+ update(data: Partial<T>): Promise<void>;
167
+ delete(): Promise<void>;
168
+ }
169
+ interface AdminCollectionShape<T> {
170
+ allowSensitiveAuthUserFields(enabled?: boolean): AdminCollectionShape<T>;
171
+ where(condition: WhereCondition): AdminCollectionShape<T>;
172
+ and(condition: WhereCondition): AdminCollectionShape<T>;
173
+ or(condition: WhereCondition): AdminCollectionShape<T>;
174
+ in(field: string, values: unknown[] | unknown): AdminCollectionShape<T>;
175
+ andIn(field: string, values: unknown[] | unknown): AdminCollectionShape<T>;
176
+ orIn(field: string, values: unknown[] | unknown): AdminCollectionShape<T>;
177
+ notIn(field: string, values: unknown[] | unknown): AdminCollectionShape<T>;
178
+ andNotIn(field: string, values: unknown[] | unknown): AdminCollectionShape<T>;
179
+ orNotIn(field: string, values: unknown[] | unknown): AdminCollectionShape<T>;
180
+ arrayContains(field: string, value: unknown): AdminCollectionShape<T>;
181
+ andArrayContains(field: string, value: unknown): AdminCollectionShape<T>;
182
+ orArrayContains(field: string, value: unknown): AdminCollectionShape<T>;
183
+ arrayContainsAny(field: string, values: unknown[] | unknown): AdminCollectionShape<T>;
184
+ andArrayContainsAny(field: string, values: unknown[] | unknown): AdminCollectionShape<T>;
185
+ orArrayContainsAny(field: string, values: unknown[] | unknown): AdminCollectionShape<T>;
186
+ some(field: string, condition: Record<string, unknown>): AdminCollectionShape<T>;
187
+ andSome(field: string, condition: Record<string, unknown>): AdminCollectionShape<T>;
188
+ orSome(field: string, condition: Record<string, unknown>): AdminCollectionShape<T>;
189
+ like(field: string, value: string): AdminCollectionShape<T>;
190
+ andLike(field: string, value: string): AdminCollectionShape<T>;
191
+ orLike(field: string, value: string): AdminCollectionShape<T>;
192
+ notLike(field: string, value: string): AdminCollectionShape<T>;
193
+ andNotLike(field: string, value: string): AdminCollectionShape<T>;
194
+ orNotLike(field: string, value: string): AdminCollectionShape<T>;
195
+ exists(field: string): AdminCollectionShape<T>;
196
+ andExists(field: string): AdminCollectionShape<T>;
197
+ orExists(field: string): AdminCollectionShape<T>;
198
+ notExists(field: string): AdminCollectionShape<T>;
199
+ andNotExists(field: string): AdminCollectionShape<T>;
200
+ orNotExists(field: string): AdminCollectionShape<T>;
201
+ latest(): AdminCollectionShape<T>;
202
+ newest(): AdminCollectionShape<T>;
203
+ oldest(): AdminCollectionShape<T>;
204
+ orderBy(field: string, dir?: "asc" | "desc"): AdminCollectionShape<T>;
205
+ limit(n: number): AdminCollectionShape<T>;
206
+ offset(n: number): AdminCollectionShape<T>;
207
+ startAt(...values: unknown[]): AdminCollectionShape<T>;
208
+ startAfter(...values: unknown[]): AdminCollectionShape<T>;
209
+ endAt(...values: unknown[]): AdminCollectionShape<T>;
210
+ endBefore(...values: unknown[]): AdminCollectionShape<T>;
211
+ aggregate(...specs: AggregateSpec[]): AdminCollectionShape<T>;
212
+ count(alias?: string): AdminCollectionShape<T>;
213
+ sum(field: string, alias?: string): AdminCollectionShape<T>;
214
+ avg(field: string, alias?: string): AdminCollectionShape<T>;
215
+ min(field: string, alias?: string): AdminCollectionShape<T>;
216
+ max(field: string, alias?: string): AdminCollectionShape<T>;
217
+ distinct(field: string, alias?: string): AdminCollectionShape<T>;
218
+ groupBy(...fields: string[]): AdminCollectionShape<T>;
219
+ having(field: string, op: HavingClause["op"], value: number): AdminCollectionShape<T>;
220
+ join(collection: string, j: JoinClause): AdminCollectionShape<T>;
221
+ joinNested(parentAlias: string, collection: string, j: JoinClause): AdminCollectionShape<T>;
222
+ Join(collection: string, j: JoinClause): AdminCollectionShape<T>;
223
+ JoinNested(parentAlias: string, collection: string, j: JoinClause): AdminCollectionShape<T>;
224
+ withRelation(relation: string, options?: Omit<JoinClause, "source" | "target" | "as"> & {
225
+ as?: string;
226
+ }): AdminCollectionShape<T>;
227
+ select(...fields: string[]): AdminCollectionShape<T>;
228
+ distinctField(field: string): AdminCollectionShape<T>;
229
+ vectorSearch(opts: VectorSearchClause): AdminCollectionShape<T>;
230
+ getRawQuery(): {
231
+ collection: string;
232
+ query: StructuredQuery;
233
+ };
234
+ get(): Promise<T[]>;
235
+ first(): Promise<T | null>;
236
+ last(): Promise<T | null>;
237
+ add(data: Partial<T>): Promise<AdminDocumentShape<T>>;
238
+ deleteMany(): Promise<number>;
239
+ doc(id: string): AdminDocumentShape<T>;
240
+ }
241
+ interface AdminSnapshotData<T = unknown> {
242
+ subscriptionId: string;
243
+ collection: string;
244
+ docId?: string;
245
+ data: T;
246
+ type: "snapshot" | "change";
247
+ operation?: "insert" | "update" | "delete" | "replace";
248
+ }
249
+ type AdminSnapshotCallback<T = unknown> = (data: AdminSnapshotData<T>) => void;
250
+ type AdminDocAddedCallback<T = unknown> = (data: T, docId: string) => void;
251
+ type AdminDocUpdatedCallback<T = unknown> = (data: T, docId: string) => void;
252
+ type AdminDocDeletedCallback = (docId: string) => void;
253
+ type AdminDocChangedCallback<T = unknown> = (data: T | null, docId: string, operation: "insert" | "update" | "delete" | "replace") => void;
254
+ interface AdminSubscribeOptions {
255
+ skipSnapshot?: boolean;
256
+ }
257
+ interface AdminSubscriptionError {
258
+ code?: string;
259
+ message: string;
260
+ permissionDenied: boolean;
261
+ raw?: unknown;
262
+ }
263
+ type AdminSubscriptionErrorCallback = (error: AdminSubscriptionError) => void;
264
+ interface AdminSubscriptionHandle {
265
+ (): void;
266
+ unsubscribe: () => void;
267
+ onError: (callback: AdminSubscriptionErrorCallback) => AdminSubscriptionHandle;
268
+ onPermissionDenied: (callback: AdminSubscriptionErrorCallback) => AdminSubscriptionHandle;
269
+ catch: (callback: AdminSubscriptionErrorCallback) => AdminSubscriptionHandle;
270
+ }
271
+
272
+ declare class AdminDocumentReference<T = Record<string, unknown>> {
273
+ private readonly cfg;
274
+ readonly collection: string;
275
+ readonly id: string;
276
+ constructor(cfg: Required<FlareAdminConfig>, collection: string, id: string);
277
+ private get baseUrl();
278
+ private get headers();
279
+ private request;
280
+ /** Fetch this document. Returns `null` if it does not exist. */
281
+ get(): Promise<T | null>;
282
+ /**
283
+ * Replace (or create) this document entirely.
284
+ * All fields not in `data` are removed.
285
+ */
286
+ set(data: Partial<T>): Promise<void>;
287
+ /**
288
+ * Merge `data` into the existing document (upsert).
289
+ * Only the provided fields are changed.
290
+ */
291
+ update(data: Partial<T>): Promise<void>;
292
+ /** Delete this document. */
293
+ delete(): Promise<void>;
294
+ /** Return the parent collection reference. */
295
+ parent(): AdminCollectionReference<T>;
296
+ }
297
+
298
+ declare class AdminCollectionReference<T = Record<string, unknown>> {
299
+ private readonly cfg;
300
+ readonly name: string;
301
+ private sq;
302
+ private opts;
303
+ constructor(cfg: Required<FlareAdminConfig>, name: string);
304
+ private get baseUrl();
305
+ private get headers();
306
+ private clone;
307
+ allowSensitiveAuthUserFields(enabled?: boolean): AdminCollectionReference<T>;
308
+ private normalizeFilterValue;
309
+ private toQueryFilters;
310
+ private appendAndFilters;
311
+ private appendOrFilters;
312
+ private appendFilters;
313
+ private appendOperatorFilter;
314
+ where(condition: WhereCondition): AdminCollectionReference<T>;
315
+ and(condition: WhereCondition): AdminCollectionReference<T>;
316
+ or(condition: WhereCondition): AdminCollectionReference<T>;
317
+ in(field: string, values: unknown[] | unknown): AdminCollectionReference<T>;
318
+ andIn(field: string, values: unknown[] | unknown): AdminCollectionReference<T>;
319
+ orIn(field: string, values: unknown[] | unknown): AdminCollectionReference<T>;
320
+ notIn(field: string, values: unknown[] | unknown): AdminCollectionReference<T>;
321
+ andNotIn(field: string, values: unknown[] | unknown): AdminCollectionReference<T>;
322
+ orNotIn(field: string, values: unknown[] | unknown): AdminCollectionReference<T>;
323
+ arrayContains(field: string, value: unknown): AdminCollectionReference<T>;
324
+ andArrayContains(field: string, value: unknown): AdminCollectionReference<T>;
325
+ orArrayContains(field: string, value: unknown): AdminCollectionReference<T>;
326
+ arrayContainsAny(field: string, values: unknown[] | unknown): AdminCollectionReference<T>;
327
+ andArrayContainsAny(field: string, values: unknown[] | unknown): AdminCollectionReference<T>;
328
+ orArrayContainsAny(field: string, values: unknown[] | unknown): AdminCollectionReference<T>;
329
+ some(field: string, condition: Record<string, unknown>): AdminCollectionReference<T>;
330
+ andSome(field: string, condition: Record<string, unknown>): AdminCollectionReference<T>;
331
+ orSome(field: string, condition: Record<string, unknown>): AdminCollectionReference<T>;
332
+ like(field: string, value: string): AdminCollectionReference<T>;
333
+ andLike(field: string, value: string): AdminCollectionReference<T>;
334
+ orLike(field: string, value: string): AdminCollectionReference<T>;
335
+ notLike(field: string, value: string): AdminCollectionReference<T>;
336
+ andNotLike(field: string, value: string): AdminCollectionReference<T>;
337
+ orNotLike(field: string, value: string): AdminCollectionReference<T>;
338
+ exists(field: string): AdminCollectionReference<T>;
339
+ andExists(field: string): AdminCollectionReference<T>;
340
+ orExists(field: string): AdminCollectionReference<T>;
341
+ notExists(field: string): AdminCollectionReference<T>;
342
+ andNotExists(field: string): AdminCollectionReference<T>;
343
+ orNotExists(field: string): AdminCollectionReference<T>;
344
+ latest(): AdminCollectionReference<T>;
345
+ newest(): AdminCollectionReference<T>;
346
+ oldest(): AdminCollectionReference<T>;
347
+ orderBy(field: string, dir?: "asc" | "desc"): AdminCollectionReference<T>;
348
+ limit(n: number): AdminCollectionReference<T>;
349
+ offset(n: number): AdminCollectionReference<T>;
350
+ startAt(...values: unknown[]): AdminCollectionReference<T>;
351
+ startAfter(...values: unknown[]): AdminCollectionReference<T>;
352
+ endAt(...values: unknown[]): AdminCollectionReference<T>;
353
+ endBefore(...values: unknown[]): AdminCollectionReference<T>;
354
+ aggregate(...specs: AggregateSpec[]): AdminCollectionReference<T>;
355
+ count(alias?: string): AdminCollectionReference<T>;
356
+ sum(field: string, alias?: string): AdminCollectionReference<T>;
357
+ avg(field: string, alias?: string): AdminCollectionReference<T>;
358
+ min(field: string, alias?: string): AdminCollectionReference<T>;
359
+ max(field: string, alias?: string): AdminCollectionReference<T>;
360
+ distinct(field: string, alias?: string): AdminCollectionReference<T>;
361
+ groupBy(...fields: string[]): AdminCollectionReference<T>;
362
+ having(field: string, op: HavingClause["op"], value: number): AdminCollectionReference<T>;
363
+ private buildStructuredJoin;
364
+ private cloneStructuredJoin;
365
+ private appendNestedJoinByAlias;
366
+ private parseRelationRef;
367
+ join(collectionName: string, j: JoinClause): AdminCollectionReference<T>;
368
+ joinNested(parentAlias: string, collectionName: string, j: JoinClause): AdminCollectionReference<T>;
369
+ Join(collectionName: string, j: JoinClause): AdminCollectionReference<T>;
370
+ JoinNested(parentAlias: string, collectionName: string, j: JoinClause): AdminCollectionReference<T>;
371
+ withRelation(relation: string, options?: (Omit<JoinClause, "source" | "target" | "as"> & {
372
+ as?: string;
373
+ })): AdminCollectionReference<T>;
374
+ select(...fields: string[]): AdminCollectionReference<T>;
375
+ distinctField(field: string): AdminCollectionReference<T>;
376
+ vectorSearch(opts: VectorSearchClause): AdminCollectionReference<T>;
377
+ getRawQuery(): {
378
+ collection: string;
379
+ query: StructuredQuery;
380
+ };
381
+ get(): Promise<T[]>;
382
+ first(): Promise<T | null>;
383
+ last(): Promise<T | null>;
384
+ add(data: Partial<T>): Promise<AdminDocumentReference<T>>;
385
+ deleteMany(): Promise<number>;
386
+ doc(id: string): AdminDocumentReference<T>;
387
+ }
388
+
389
+ declare class FlareAdminDbService implements FlareAdminDb {
390
+ private readonly cfg;
391
+ constructor(cfg: Required<FlareAdminConfig>);
392
+ /**
393
+ * Reference a collection for one-shot queries and mutations.
394
+ *
395
+ * Supports the full StructuredQuery builder API:
396
+ * `where`, `and`, `or`, `orderBy`, `limit`, `offset`,
397
+ * `startAt/After`, `endAt/Before`, `count/sum/avg/min/max/distinct`,
398
+ * `groupBy`, `having`, `Join`, `select`, `distinctField`, `vectorSearch`.
399
+ *
400
+ * @example
401
+ * const users = await admin.db().collection<User>("users").get();
402
+ * const admins = await admin.db().collection("users")
403
+ * .where({ role: "admin" }).orderBy("name").get();
404
+ * const ref = await admin.db().collection("users").add({ name: "Alice" });
405
+ * await admin.db().collection("users").doc("alice").update({ plan: "pro" });
406
+ */
407
+ collection<T = Record<string, unknown>>(name: string): AdminCollectionReference<T>;
408
+ }
409
+
410
+ declare class FlareAdminAuthService implements FlareAdminAuth {
411
+ private readonly cfg;
412
+ constructor(cfg: Required<FlareAdminConfig>);
413
+ createCustomToken(uid: string | number, opts?: CreateCustomTokenOptions): Promise<string>;
414
+ }
415
+
416
+ declare class FlareAdminNotificationsService implements FlareAdminNotifications {
417
+ private readonly cfg;
418
+ constructor(cfg: Required<FlareAdminConfig>);
419
+ private get baseUrl();
420
+ private get headers();
421
+ send(input: AdminPushSendInput): Promise<AdminPushSendResult>;
422
+ tokens(): Promise<{
423
+ appId: string;
424
+ hasPushGateway: boolean;
425
+ total: number;
426
+ tokens: AdminPushToken[];
427
+ }>;
428
+ }
429
+
430
+ type AdminRealtimeSubscriber$1 = {
431
+ subscribe: (collection: string, docId: string | undefined, structuredQuery: StructuredQuery | undefined, callback: AdminSnapshotCallback, options?: AdminSubscribeOptions) => AdminSubscriptionHandle;
432
+ };
433
+ /**
434
+ * Real-time reference to a single document.
435
+ *
436
+ * @example
437
+ * const unsub = admin.connection()
438
+ * .collection("users").doc("alice")
439
+ * .onSnapshot((snap) => console.log(snap.data));
440
+ */
441
+ declare class AdminLiveDocumentReference<T = Record<string, unknown>> {
442
+ private readonly conn;
443
+ /** Collection name */
444
+ readonly collection: string;
445
+ /** Document ID */
446
+ readonly id: string;
447
+ constructor(conn: AdminRealtimeSubscriber$1,
448
+ /** Collection name */
449
+ collection: string,
450
+ /** Document ID */
451
+ id: string);
452
+ /**
453
+ * Subscribe to real-time changes for this document.
454
+ * The callback fires once with the initial snapshot, then on every update.
455
+ *
456
+ * @returns An unsubscribe function — call it to stop listening.
457
+ */
458
+ onSnapshot(callback: AdminSnapshotCallback<T>): () => void;
459
+ }
460
+
461
+ type AdminRealtimeSubscriber = {
462
+ subscribe: (collection: string, docId: string | undefined, structuredQuery: StructuredQuery | undefined, callback: AdminSnapshotCallback, options?: AdminSubscribeOptions) => AdminSubscriptionHandle;
463
+ };
464
+ declare class AdminLiveCollectionReference<T = Record<string, unknown>> {
465
+ private readonly conn;
466
+ readonly name: string;
467
+ private sq;
468
+ constructor(conn: AdminRealtimeSubscriber, name: string);
469
+ private clone;
470
+ private normalizeFilterValue;
471
+ private toQueryFilters;
472
+ private appendAndFilters;
473
+ private appendOrFilters;
474
+ private appendFilters;
475
+ private appendOperatorFilter;
476
+ where(condition: WhereCondition): AdminLiveCollectionReference<T>;
477
+ and(condition: WhereCondition): AdminLiveCollectionReference<T>;
478
+ or(condition: WhereCondition): AdminLiveCollectionReference<T>;
479
+ in(field: string, values: unknown[] | unknown): AdminLiveCollectionReference<T>;
480
+ andIn(field: string, values: unknown[] | unknown): AdminLiveCollectionReference<T>;
481
+ orIn(field: string, values: unknown[] | unknown): AdminLiveCollectionReference<T>;
482
+ notIn(field: string, values: unknown[] | unknown): AdminLiveCollectionReference<T>;
483
+ andNotIn(field: string, values: unknown[] | unknown): AdminLiveCollectionReference<T>;
484
+ orNotIn(field: string, values: unknown[] | unknown): AdminLiveCollectionReference<T>;
485
+ arrayContains(field: string, value: unknown): AdminLiveCollectionReference<T>;
486
+ andArrayContains(field: string, value: unknown): AdminLiveCollectionReference<T>;
487
+ orArrayContains(field: string, value: unknown): AdminLiveCollectionReference<T>;
488
+ arrayContainsAny(field: string, values: unknown[] | unknown): AdminLiveCollectionReference<T>;
489
+ andArrayContainsAny(field: string, values: unknown[] | unknown): AdminLiveCollectionReference<T>;
490
+ orArrayContainsAny(field: string, values: unknown[] | unknown): AdminLiveCollectionReference<T>;
491
+ some(field: string, condition: Record<string, unknown>): AdminLiveCollectionReference<T>;
492
+ andSome(field: string, condition: Record<string, unknown>): AdminLiveCollectionReference<T>;
493
+ orSome(field: string, condition: Record<string, unknown>): AdminLiveCollectionReference<T>;
494
+ like(field: string, value: string): AdminLiveCollectionReference<T>;
495
+ andLike(field: string, value: string): AdminLiveCollectionReference<T>;
496
+ orLike(field: string, value: string): AdminLiveCollectionReference<T>;
497
+ notLike(field: string, value: string): AdminLiveCollectionReference<T>;
498
+ andNotLike(field: string, value: string): AdminLiveCollectionReference<T>;
499
+ orNotLike(field: string, value: string): AdminLiveCollectionReference<T>;
500
+ exists(field: string): AdminLiveCollectionReference<T>;
501
+ andExists(field: string): AdminLiveCollectionReference<T>;
502
+ orExists(field: string): AdminLiveCollectionReference<T>;
503
+ notExists(field: string): AdminLiveCollectionReference<T>;
504
+ andNotExists(field: string): AdminLiveCollectionReference<T>;
505
+ orNotExists(field: string): AdminLiveCollectionReference<T>;
506
+ latest(): AdminLiveCollectionReference<T>;
507
+ newest(): AdminLiveCollectionReference<T>;
508
+ oldest(): AdminLiveCollectionReference<T>;
509
+ orderBy(field: string, dir?: "asc" | "desc"): AdminLiveCollectionReference<T>;
510
+ limit(n: number): AdminLiveCollectionReference<T>;
511
+ offset(n: number): AdminLiveCollectionReference<T>;
512
+ startAt(...values: unknown[]): AdminLiveCollectionReference<T>;
513
+ startAfter(...values: unknown[]): AdminLiveCollectionReference<T>;
514
+ endAt(...values: unknown[]): AdminLiveCollectionReference<T>;
515
+ endBefore(...values: unknown[]): AdminLiveCollectionReference<T>;
516
+ aggregate(...specs: AggregateSpec[]): AdminLiveCollectionReference<T>;
517
+ count(alias?: string): AdminLiveCollectionReference<T>;
518
+ sum(field: string, alias?: string): AdminLiveCollectionReference<T>;
519
+ avg(field: string, alias?: string): AdminLiveCollectionReference<T>;
520
+ min(field: string, alias?: string): AdminLiveCollectionReference<T>;
521
+ max(field: string, alias?: string): AdminLiveCollectionReference<T>;
522
+ distinct(field: string, alias?: string): AdminLiveCollectionReference<T>;
523
+ groupBy(...fields: string[]): AdminLiveCollectionReference<T>;
524
+ having(field: string, op: HavingClause["op"], value: number): AdminLiveCollectionReference<T>;
525
+ private buildStructuredJoin;
526
+ private cloneStructuredJoin;
527
+ private appendNestedJoinByAlias;
528
+ private parseRelationRef;
529
+ join(collectionName: string, j: JoinClause): AdminLiveCollectionReference<T>;
530
+ joinNested(parentAlias: string, collectionName: string, j: JoinClause): AdminLiveCollectionReference<T>;
531
+ Join(collectionName: string, j: JoinClause): AdminLiveCollectionReference<T>;
532
+ JoinNested(parentAlias: string, collectionName: string, j: JoinClause): AdminLiveCollectionReference<T>;
533
+ withRelation(relation: string, options?: (Omit<JoinClause, "source" | "target" | "as"> & {
534
+ as?: string;
535
+ })): AdminLiveCollectionReference<T>;
536
+ select(...fields: string[]): AdminLiveCollectionReference<T>;
537
+ distinctField(field: string): AdminLiveCollectionReference<T>;
538
+ vectorSearch(opts: VectorSearchClause): AdminLiveCollectionReference<T>;
539
+ doc(id: string): AdminLiveDocumentReference<T>;
540
+ getRawQuery(): {
541
+ collection: string;
542
+ query: StructuredQuery;
543
+ };
544
+ onSnapshot(callback: AdminSnapshotCallback<T[]>): () => void;
545
+ onDocAdded(callback: AdminDocAddedCallback<T>): () => void;
546
+ onDocUpdated(callback: AdminDocUpdatedCallback<T>): () => void;
547
+ onDocDeleted(callback: AdminDocDeletedCallback): () => void;
548
+ onDocChanged(callback: AdminDocChangedCallback<T>): () => void;
549
+ private _buildSq;
550
+ }
551
+
552
+ /**
553
+ * The real-time connection service returned by `admin.connection()`.
554
+ *
555
+ * One `FlareAdminConnection` (and its underlying WebSocket) is shared per
556
+ * `FlareAdminApp` instance. Call `.disconnect()` when you no longer need it.
557
+ *
558
+ * @example
559
+ * const unsub = admin.connection()
560
+ * .collection("orders")
561
+ * .where({ status: "pending" })
562
+ * .or({ priority: "high" })
563
+ * .orderBy("createdAt", "desc")
564
+ * .onSnapshot((snap) => console.log(snap));
565
+ *
566
+ * const unsub2 = admin.connection()
567
+ * .collection("users").doc("alice")
568
+ * .onSnapshot((snap) => console.log(snap.data));
569
+ *
570
+ * unsub(); unsub2();
571
+ * admin.connection().disconnect();
572
+ */
573
+ declare class FlareAdminConnection {
574
+ /**
575
+ * Reference a collection for real-time subscriptions.
576
+ * Returns an `AdminLiveCollectionReference` with the full query-builder API.
577
+ */
578
+ collection<T = Record<string, unknown>>(name: string): AdminLiveCollectionReference<T>;
579
+ /** Wait until the WebSocket is open and authenticated. */
580
+ ready(): Promise<void>;
581
+ /** Close the WebSocket connection permanently (no reconnect). */
582
+ disconnect(): void;
583
+ }
584
+
585
+ /**
586
+ * Manages a persistent admin WebSocket connection to FlareServer.
587
+ * Passes `adminKey` as a query param — the server immediately elevates the
588
+ * socket to role "admin", bypassing all security rules.
589
+ */
590
+ declare class FlareAdminWsConnection {
591
+ private readonly cfg;
592
+ private ws;
593
+ private readonly pendingAcks;
594
+ private readonly subscriptions;
595
+ private readonly activeSubscriptions;
596
+ private readonly subscriptionErrorHandlers;
597
+ private readonly subscriptionPermissionHandlers;
598
+ private readonly subscriptionLastErrors;
599
+ private connected;
600
+ private shouldReconnect;
601
+ private reconnectDelay;
602
+ private readonly wsUrl;
603
+ private _readyResolve;
604
+ private _readyPromise;
605
+ constructor(cfg: Required<FlareAdminConfig>);
606
+ /** Resolves once the WS is open and AUTH_OK is received from the server. */
607
+ ready(): Promise<void>;
608
+ /** Close the connection permanently (no reconnect). */
609
+ disconnect(): void;
610
+ /**
611
+ * Send a typed message and await its ACK / response.
612
+ */
613
+ send(type: string, payload: Record<string, unknown>): Promise<Record<string, unknown>>;
614
+ /**
615
+ * Subscribe to a collection / document in real-time.
616
+ * Passes a full `StructuredQuery` (or docId) to the server.
617
+ * Returns an unsubscribe function.
618
+ */
619
+ subscribe(collection: string, docId: string | undefined, structuredQuery: StructuredQuery | undefined, callback: AdminSnapshotCallback, options?: AdminSubscribeOptions): AdminSubscriptionHandle;
620
+ private activateSubscription;
621
+ private replayActiveSubscriptions;
622
+ private toSubscriptionError;
623
+ private emitSubscriptionError;
624
+ private _connect;
625
+ private _handle;
626
+ }
627
+
628
+ /**
629
+ * @zuzjs/flare-admin
630
+ *
631
+ * Server-side admin SDK for FlareServer.
632
+ * Runs only on your backend, never in a browser.
633
+ *
634
+ * ─── Quick start ──────────────────────────────────────────────────────────────
635
+ *
636
+ * import { connectApp } from "@zuzjs/flare-admin";
637
+ *
638
+ * const admin = connectApp({
639
+ * serverUrl: process.env.FLARE_URL!,
640
+ * appId: process.env.FLARE_APP_ID!,
641
+ * adminKey: process.env.FLARE_ADMIN_KEY!,
642
+ * });
643
+ *
644
+ * // Mint a custom auth token (for use by the browser client)
645
+ * const token = await admin.auth().createCustomToken(String(user.id), {
646
+ * role: user.isAdmin ? "admin" : "user",
647
+ * claims: { email: user.email, plan: user.plan },
648
+ * });
649
+ *
650
+ * // One-shot DB queries (bypasses security rules)
651
+ * const users = await admin.db().collection("users").get();
652
+ * await admin.db().collection("users").doc("alice").set({ name: "Alice" });
653
+ *
654
+ * // Rich queries
655
+ * const seniors = await admin.db()
656
+ * .collection("users")
657
+ * .where({ age: ">= 60" })
658
+ * .orderBy("name")
659
+ * .limit(10)
660
+ * .get();
661
+ *
662
+ * // Real-time subscriptions over WebSocket
663
+ * const unsub = admin.connection()
664
+ * .collection("orders")
665
+ * .where({ status: "pending" })
666
+ * .orderBy("createdAt", "desc")
667
+ * .onSnapshot((snap) => console.log(snap));
668
+ */
669
+
670
+ /**
671
+ * A FlareAdmin application instance.
672
+ * Create one with `connectApp()` and keep it as a module-level singleton.
673
+ */
674
+ declare class FlareAdminApp {
675
+ private readonly cfg;
676
+ private _auth?;
677
+ private _db?;
678
+ private _conn?;
679
+ private _notifications?;
680
+ /**
681
+ * Access the auth service.
682
+ *
683
+ * @example
684
+ * const token = await admin.auth().createCustomToken(uid, { role: "user" });
685
+ */
686
+ auth(): FlareAdminAuth;
687
+ /**
688
+ * Access the database service.
689
+ * All operations bypass security rules — admin has full read/write access.
690
+ *
691
+ * Supports the full StructuredQuery builder API:
692
+ * `where`, `and`, `or`, `orderBy`, `limit`, `offset`,
693
+ * `startAt/After`, `endAt/Before`, `count/sum/avg/min/max/distinct`,
694
+ * `groupBy`, `having`, `Join`, `select`, `distinctField`, `vectorSearch`.
695
+ *
696
+ * @example
697
+ * const users = await admin.db().collection("users").get();
698
+ * const admins = await admin.db().collection("users")
699
+ * .where({ role: "admin" }).orderBy("name").get();
700
+ * const [{ count }] = await admin.db().collection("users").count().get();
701
+ * await admin.db().collection("users").doc("alice").update({ plan: "pro" });
702
+ */
703
+ db(): FlareAdminDb;
704
+ /**
705
+ * Open (or reuse) a persistent admin WebSocket connection.
706
+ * One socket is shared per app instance — call `.disconnect()` when done.
707
+ *
708
+ * Supports the full query-builder API on live subscriptions:
709
+ * `where`, `and`, `or`, `orderBy`, `limit`, `offset`,
710
+ * `startAt/After`, `endAt/Before`, `count/sum/avg/min/max/distinct`,
711
+ * `groupBy`, `having`, `Join`, `select`, `distinctField`, `vectorSearch`.
712
+ *
713
+ * @example
714
+ * const unsub = admin.connection()
715
+ * .collection("orders")
716
+ * .where({ status: "pending" })
717
+ * .orderBy("createdAt", "desc")
718
+ * .limit(50)
719
+ * .onSnapshot((snap) => {
720
+ * if (snap.type === "snapshot") console.log("initial:", snap.data);
721
+ * else console.log(snap.operation, snap.data);
722
+ * });
723
+ *
724
+ * const unsub2 = admin.connection()
725
+ * .collection("users").doc("alice")
726
+ * .onSnapshot((snap) => console.log(snap.data));
727
+ *
728
+ * unsub();
729
+ * unsub2();
730
+ * admin.connection().disconnect();
731
+ */
732
+ connection(): FlareAdminConnection;
733
+ /**
734
+ * Access push notification management APIs.
735
+ */
736
+ notifications(): FlareAdminNotifications;
737
+ }
738
+ /**
739
+ * Initialize a FlareAdmin app instance.
740
+ * Call once at server boot. Calling again with the same name is idempotent.
741
+ *
742
+ * @param config Server coordinates + admin key.
743
+ * @param name App name for multi-tenant setups (default: `"[DEFAULT]"`).
744
+ *
745
+ * @example
746
+ * const admin = connectApp({
747
+ * serverUrl: process.env.FLARE_URL!,
748
+ * appId: process.env.FLARE_APP_ID!,
749
+ * adminKey: process.env.FLARE_ADMIN_KEY!,
750
+ * });
751
+ */
752
+ declare function connectApp(config: FlareAdminConfig, name?: string): FlareAdminApp;
753
+ /**
754
+ * Retrieve an already-initialized app by name.
755
+ * @throws If the app has not been initialized yet.
756
+ */
757
+ declare function getApp(name?: string): FlareAdminApp;
758
+ /**
759
+ * Get the auth service from the default app.
760
+ * Equivalent to `getApp().auth()`.
761
+ *
762
+ * @example
763
+ * import { auth } from "@zuzjs/flare-admin";
764
+ * const token = await auth().createCustomToken(uid);
765
+ */
766
+ declare function auth(name?: string): FlareAdminAuth;
767
+ /**
768
+ * Get the db service from the default app.
769
+ * Equivalent to `getApp().db()`.
770
+ *
771
+ * @example
772
+ * import { db } from "@zuzjs/flare-admin";
773
+ * const users = await db().collection("users").get();
774
+ */
775
+ declare function db(name?: string): FlareAdminDb;
776
+ /**
777
+ * Get the real-time WebSocket connection from the default app.
778
+ * Equivalent to `getApp().connection()`.
779
+ *
780
+ * @example
781
+ * import { connection } from "@zuzjs/flare-admin";
782
+ * const unsub = connection().collection("users")
783
+ * .where({ role: "admin" })
784
+ * .onSnapshot((snap) => console.log(snap));
785
+ */
786
+ declare function connection(name?: string): FlareAdminConnection;
787
+ /**
788
+ * Get the notifications service from the default app.
789
+ * Equivalent to `getApp().notifications()`.
790
+ */
791
+ declare function notifications(name?: string): FlareAdminNotifications;
792
+
793
+ 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, connection, db, getApp, notifications };