@zuzjs/flare 0.2.12 → 0.2.14
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/dist/index-DQHYN410.d.cts +1322 -0
- package/dist/index-DQHYN410.d.ts +1322 -0
- package/dist/index.cjs +3 -3
- package/dist/index.d.cts +3 -1366
- package/dist/index.d.ts +3 -1366
- package/dist/index.js +2 -2
- package/dist/react.cjs +2 -0
- package/dist/react.d.cts +21 -0
- package/dist/react.d.ts +21 -0
- package/dist/react.js +1 -0
- package/package.json +14 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,1370 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { F as FlareConfig, a as FlareClient } from './index-DQHYN410.cjs';
|
|
2
|
+
export { A as AggregateFunction, b as AggregateSpec, c as AndFilter, d as AnyFilter, e as AuthConfigListener, f as AuthResult, g as AuthStateListener, h as AuthWithPendingVerificationResult, i as AuthWithTokenResult, B as BaseMessage, j as BrowserPushRegistrationOptions, k as BrowserPushTokenOptions, C as ChangeEvent, l as ChangeOperation, m as CollectionExternalStore, n as CollectionPresetMethods, o as CollectionQuery, p as CollectionReference, q as CollectionStream, r as CollectionStreamListener, s as CollectionStreamMeta, t as CollectionStreamOptions, u as ConnectionState, v as CursorValue, D as DataMapperFn, w as DataMapperRegistry, x as DocAddedCallback, y as DocChangedCallback, z as DocDeletedCallback, E as DocUpdatedCallback, G as DocumentQueryBuilder, H as DocumentReference, I as DocumentSnapshot, J as EmailLinkVerifyResult, K as EmailSendResult, L as FlareAction, M as FlareAuthConfig, N as FlareAuthHydrationInput, O as FlareAuthHydrationOptions, P as FlareAuthProviderId, Q as FlareAuthProviderPublicConfig, R as FlareAuthSession, S as FlareAuthUser, T as FlareEvent, U as FlareRule, V as GroupByClause, W as HavingClause, X as JoinClause, Y as JoinQueryPattern, Z as NestedJoinClause, _ as OfflineOperation, $ as OrFilter, a0 as OrderByClause, a1 as PresenceCallback, a2 as PresenceJoinCallback, a3 as PresenceLeaveCallback, a4 as PresenceMember, a5 as PushSendResult, a6 as QueryConfig, a7 as QueryOperator, a8 as QueryPresetMap, a9 as QueryPresetParams, aa as QueryPresetRow, ab as QueryPresetSpec, ac as QuerySnapshot, ad as RegisterPushTokenInput, ae as RulePermission, af as SecurityRuleEntry, ag as SecurityRulesMap, ah as SendEmailInput, ai as SendPushNotificationInput, aj as SnapshotEvent, ak as StreamFlushReason, al as StructuredJoinClause, am as StructuredQuery, an as SubscribeMessage, ao as SubscribeOptions, ap as SubscriptionCallback, aq as SubscriptionData, ar as SubscriptionError, as as SubscriptionErrorCallback, at as SubscriptionHandle, au as VectorFieldConfig, av as VectorSearchClause, aw as VerifyEmailLinkInput, ax as WhereCondition, ay as flareRulesToSecurityMap, az as parseValue, aA as parseWhereCondition, aB as securityMapToFlareRules } from './index-DQHYN410.cjs';
|
|
2
3
|
export { Anonymous, Apple, AuthGuard, AuthToken, CreateUserWithEmailAndPasswordInput, Credentials, Dropbox, Facebook, GitHub, Google, NormalizedProfile, OAuthProvider, ProviderId, Providers, SignInAnonymouslyInput, SignInWithEmailAndPasswordInput, Twitter, setupProvider } from '@zuzjs/auth';
|
|
3
4
|
|
|
4
|
-
/**
|
|
5
|
-
* Client Configuration
|
|
6
|
-
*/
|
|
7
|
-
interface FlareConfig {
|
|
8
|
-
/** Base URL for the Flare API. */
|
|
9
|
-
endpoint: string;
|
|
10
|
-
/**
|
|
11
|
-
* Optional HTTP base URL for auth API calls.
|
|
12
|
-
* When set, all auth HTTP calls go through this base instead of calling
|
|
13
|
-
* Flare directly. Use this to route calls through a Next.js proxy so CSRF
|
|
14
|
-
* is handled entirely server-side.
|
|
15
|
-
* Example: '/api/flare' (relative, browser resolves against current origin)
|
|
16
|
-
*/
|
|
17
|
-
httpBase?: string;
|
|
18
|
-
/**
|
|
19
|
-
* WebSocket path used for realtime transport.
|
|
20
|
-
* Defaults to '/' for backward compatibility.
|
|
21
|
-
*/
|
|
22
|
-
wsPath?: string;
|
|
23
|
-
/** Unique identifier for the application. */
|
|
24
|
-
appId: string;
|
|
25
|
-
/** API key for the application. */
|
|
26
|
-
apiKey?: string;
|
|
27
|
-
/**
|
|
28
|
-
* Request content type for credential auth endpoints (/auth/token, /auth/register).
|
|
29
|
-
* Defaults to OAuth-compatible form encoding.
|
|
30
|
-
*/
|
|
31
|
-
authRequestContentType?: "application/x-www-form-urlencoded" | "application/json";
|
|
32
|
-
/** Public key for the application. */
|
|
33
|
-
publicKey?: string;
|
|
34
|
-
/** Whether to automatically reconnect on connection loss. */
|
|
35
|
-
autoReconnect?: boolean;
|
|
36
|
-
/** Delay between reconnection attempts in milliseconds. */
|
|
37
|
-
reconnectDelay?: number;
|
|
38
|
-
/** Maximum delay between reconnection attempts in milliseconds. */
|
|
39
|
-
maxReconnectDelay?: number;
|
|
40
|
-
/** Enable or disable debug mode. */
|
|
41
|
-
debug?: boolean;
|
|
42
|
-
/** Enable or disable request timing. */
|
|
43
|
-
requestTiming?: boolean;
|
|
44
|
-
/** Connection timeout in milliseconds. */
|
|
45
|
-
connectionTimeout?: number;
|
|
46
|
-
/** Enable automatic push notification registration on supported platforms. */
|
|
47
|
-
pushNotifications?: boolean;
|
|
48
|
-
/**
|
|
49
|
-
* Optional per-collection mapper registry for shaping inbound data.
|
|
50
|
-
*
|
|
51
|
-
* Keys can be:
|
|
52
|
-
* - base collection names (e.g. "boards")
|
|
53
|
-
* - join aliases (`join(..., { as: "team" })` => "team")
|
|
54
|
-
*/
|
|
55
|
-
dataMapper?: DataMapperRegistry;
|
|
56
|
-
}
|
|
57
|
-
type DataMapperFn<TRow = any, TMapped = any> = (row: TRow) => TMapped;
|
|
58
|
-
type DataMapperRegistry = Record<string, DataMapperFn<any, any>>;
|
|
59
|
-
type FlareAuthProviderId = "credentials" | "anonymous" | "google" | "facebook" | "github" | "dropbox" | "apple" | "twitter";
|
|
60
|
-
interface FlareAuthProviderPublicConfig {
|
|
61
|
-
enabled: boolean;
|
|
62
|
-
clientId?: string;
|
|
63
|
-
scopes?: string[];
|
|
64
|
-
}
|
|
65
|
-
interface FlareAuthConfig {
|
|
66
|
-
appId: string;
|
|
67
|
-
enabled: boolean;
|
|
68
|
-
needsEmailVerification?: boolean;
|
|
69
|
-
autoSendVerificationEmail?: boolean;
|
|
70
|
-
redirectUri?: string;
|
|
71
|
-
csrfToken?: string;
|
|
72
|
-
cookie?: {
|
|
73
|
-
accessTokenName?: string;
|
|
74
|
-
refreshTokenName?: string;
|
|
75
|
-
csrfTokenName?: string;
|
|
76
|
-
domain?: string;
|
|
77
|
-
path?: string;
|
|
78
|
-
secure?: boolean;
|
|
79
|
-
sameSite?: "Lax" | "Strict" | "None";
|
|
80
|
-
accessTokenMaxAge?: number;
|
|
81
|
-
refreshTokenMaxAge?: number;
|
|
82
|
-
csrfTokenMaxAge?: number;
|
|
83
|
-
};
|
|
84
|
-
providers: Record<FlareAuthProviderId, FlareAuthProviderPublicConfig>;
|
|
85
|
-
}
|
|
86
|
-
interface FlareAuthSession {
|
|
87
|
-
uid: string;
|
|
88
|
-
accessToken: string;
|
|
89
|
-
refreshToken: string | null;
|
|
90
|
-
provider?: string;
|
|
91
|
-
email?: string | null;
|
|
92
|
-
emailVerified?: boolean;
|
|
93
|
-
}
|
|
94
|
-
interface FlareAuthUser {
|
|
95
|
-
uid: string;
|
|
96
|
-
email: string;
|
|
97
|
-
email_verified: string;
|
|
98
|
-
[x: string]: any;
|
|
99
|
-
}
|
|
100
|
-
interface RegisterPushTokenInput {
|
|
101
|
-
token: string;
|
|
102
|
-
platform?: string;
|
|
103
|
-
deviceId?: string;
|
|
104
|
-
topics?: string[];
|
|
105
|
-
authAppId?: string;
|
|
106
|
-
}
|
|
107
|
-
interface BrowserPushTokenOptions {
|
|
108
|
-
/** Service worker registration used for PushManager subscription. */
|
|
109
|
-
serviceWorkerRegistration?: ServiceWorkerRegistration;
|
|
110
|
-
/** Existing PushSubscription to reuse instead of subscribing again. */
|
|
111
|
-
subscription?: PushSubscription;
|
|
112
|
-
/** Public VAPID key used when creating a new PushSubscription. */
|
|
113
|
-
applicationServerKey?: string;
|
|
114
|
-
/** When true, unsubscribe old subscriptions before creating a new one. */
|
|
115
|
-
forceResubscribe?: boolean;
|
|
116
|
-
}
|
|
117
|
-
interface BrowserPushRegistrationOptions extends BrowserPushTokenOptions {
|
|
118
|
-
/** Optional explicit platform label. Defaults to "web". */
|
|
119
|
-
platform?: string;
|
|
120
|
-
deviceId?: string;
|
|
121
|
-
topics?: string[];
|
|
122
|
-
authAppId?: string;
|
|
123
|
-
}
|
|
124
|
-
interface SendPushNotificationInput {
|
|
125
|
-
title?: string;
|
|
126
|
-
body?: string;
|
|
127
|
-
image?: string;
|
|
128
|
-
data?: Record<string, unknown>;
|
|
129
|
-
tokens?: string[];
|
|
130
|
-
uid?: string;
|
|
131
|
-
topic?: string;
|
|
132
|
-
priority?: "normal" | "high";
|
|
133
|
-
ttlSeconds?: number;
|
|
134
|
-
dryRun?: boolean;
|
|
135
|
-
authAppId?: string;
|
|
136
|
-
}
|
|
137
|
-
interface PushSendResult {
|
|
138
|
-
sent: boolean;
|
|
139
|
-
appId: string;
|
|
140
|
-
targetCount: number;
|
|
141
|
-
successCount: number;
|
|
142
|
-
failureCount: number;
|
|
143
|
-
invalidatedTokenCount: number;
|
|
144
|
-
dryRun: boolean;
|
|
145
|
-
}
|
|
146
|
-
interface SendEmailInput {
|
|
147
|
-
to: string | string[];
|
|
148
|
-
tag: string;
|
|
149
|
-
values?: Record<string, unknown>;
|
|
150
|
-
authAppId?: string;
|
|
151
|
-
}
|
|
152
|
-
interface EmailSendResult {
|
|
153
|
-
sent: boolean;
|
|
154
|
-
appId: string;
|
|
155
|
-
tag: string;
|
|
156
|
-
recipientCount: number;
|
|
157
|
-
acceptedCount: number;
|
|
158
|
-
rejectedCount: number;
|
|
159
|
-
includeVerificationLink?: boolean;
|
|
160
|
-
linkId?: string;
|
|
161
|
-
verifyUrl?: string;
|
|
162
|
-
messageId?: string;
|
|
163
|
-
}
|
|
164
|
-
interface VerifyEmailLinkInput {
|
|
165
|
-
token: string;
|
|
166
|
-
tag?: string;
|
|
167
|
-
email?: string;
|
|
168
|
-
authAppId?: string;
|
|
169
|
-
}
|
|
170
|
-
interface EmailLinkVerifyResult {
|
|
171
|
-
verified: boolean;
|
|
172
|
-
alreadyVerified: boolean;
|
|
173
|
-
appId: string;
|
|
174
|
-
linkId: string;
|
|
175
|
-
email: string;
|
|
176
|
-
tag: string;
|
|
177
|
-
verifiedAt?: string;
|
|
178
|
-
acceptedByUid?: string;
|
|
179
|
-
}
|
|
180
|
-
type AuthStateListener = (session: FlareAuthSession & FlareAuthUser | null) => void;
|
|
181
|
-
type AuthConfigListener = (conf: FlareAuthConfig) => void;
|
|
182
|
-
interface SubscribeOptions {
|
|
183
|
-
skipSnapshot?: boolean;
|
|
184
|
-
}
|
|
185
|
-
type QueryOperator = "==" | "!=" | "<" | "<=" | ">" | ">=" | "in" | "not-in" | "array-contains" | "array-contains-any" | "elem-match" | "like" | "not-like" | "contains" | "exists" | "not-exists";
|
|
186
|
-
interface QueryConfig {
|
|
187
|
-
field: string;
|
|
188
|
-
op: QueryOperator;
|
|
189
|
-
value: unknown;
|
|
190
|
-
}
|
|
191
|
-
/** OR group */
|
|
192
|
-
interface OrFilter {
|
|
193
|
-
or: AnyFilter[];
|
|
194
|
-
}
|
|
195
|
-
/** AND group */
|
|
196
|
-
interface AndFilter {
|
|
197
|
-
and: AnyFilter[];
|
|
198
|
-
}
|
|
199
|
-
type AnyFilter = QueryConfig | OrFilter | AndFilter;
|
|
200
|
-
type WhereCondition = Record<string, string | number | boolean | any[]>;
|
|
201
|
-
interface OrderByClause {
|
|
202
|
-
field: string;
|
|
203
|
-
dir?: "asc" | "desc";
|
|
204
|
-
}
|
|
205
|
-
interface GroupByClause {
|
|
206
|
-
fields: string[];
|
|
207
|
-
}
|
|
208
|
-
interface HavingClause {
|
|
209
|
-
field: string;
|
|
210
|
-
op: "==" | "!=" | "<" | "<=" | ">" | ">=";
|
|
211
|
-
value: number;
|
|
212
|
-
}
|
|
213
|
-
interface CursorValue {
|
|
214
|
-
values: unknown[];
|
|
215
|
-
}
|
|
216
|
-
type AggregateFunction = "count" | "sum" | "avg" | "min" | "max" | "distinct";
|
|
217
|
-
interface AggregateSpec {
|
|
218
|
-
fn: AggregateFunction;
|
|
219
|
-
field?: string;
|
|
220
|
-
alias?: string;
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* Join definition used by CollectionReference.Join().
|
|
224
|
-
*
|
|
225
|
-
* Example:
|
|
226
|
-
* Join("tasks", { source: "id", target: "boardId", as: "tasks" })
|
|
227
|
-
*/
|
|
228
|
-
interface JoinQueryPattern {
|
|
229
|
-
where?: AnyFilter[];
|
|
230
|
-
orderBy?: OrderByClause[];
|
|
231
|
-
limit?: number;
|
|
232
|
-
offset?: number;
|
|
233
|
-
startAt?: CursorValue;
|
|
234
|
-
startAfter?: CursorValue;
|
|
235
|
-
endAt?: CursorValue;
|
|
236
|
-
endBefore?: CursorValue;
|
|
237
|
-
aggregate?: AggregateSpec[];
|
|
238
|
-
groupBy?: GroupByClause;
|
|
239
|
-
having?: HavingClause[];
|
|
240
|
-
vectorSearch?: VectorSearchClause;
|
|
241
|
-
select?: string[];
|
|
242
|
-
distinctField?: string;
|
|
243
|
-
}
|
|
244
|
-
interface NestedJoinClause extends JoinQueryPattern {
|
|
245
|
-
/** Joined collection name for this nested join. */
|
|
246
|
-
collection: string;
|
|
247
|
-
/** Field from the parent join result. */
|
|
248
|
-
source: string;
|
|
249
|
-
/** Field from this nested collection to match source. */
|
|
250
|
-
target: string;
|
|
251
|
-
/** Alias where nested rows are attached in each parent join row. */
|
|
252
|
-
as: string;
|
|
253
|
-
/** If true, expect at most one joined row. */
|
|
254
|
-
single?: boolean;
|
|
255
|
-
/** Recursive nested joins. */
|
|
256
|
-
joins?: NestedJoinClause[];
|
|
257
|
-
}
|
|
258
|
-
interface JoinClause extends JoinQueryPattern {
|
|
259
|
-
/** Field from the base collection (the collection you started the query on). */
|
|
260
|
-
source: string;
|
|
261
|
-
/** Field from the joined collection that should match source. */
|
|
262
|
-
target: string;
|
|
263
|
-
/** Alias where joined rows will be attached in each result object. */
|
|
264
|
-
as: string;
|
|
265
|
-
/** If true, expect at most one joined row (object instead of array on server side). */
|
|
266
|
-
single?: boolean;
|
|
267
|
-
/** Optional nested joins under this join. */
|
|
268
|
-
joins?: NestedJoinClause[];
|
|
269
|
-
}
|
|
270
|
-
/** Internal wire-ready join shape sent to server query engine. */
|
|
271
|
-
interface StructuredJoinClause extends JoinQueryPattern {
|
|
272
|
-
from: string;
|
|
273
|
-
localField: string;
|
|
274
|
-
foreignField: string;
|
|
275
|
-
as: string;
|
|
276
|
-
single?: boolean;
|
|
277
|
-
joins?: StructuredJoinClause[];
|
|
278
|
-
}
|
|
279
|
-
interface VectorSearchClause {
|
|
280
|
-
field: string;
|
|
281
|
-
vector: number[];
|
|
282
|
-
k: number;
|
|
283
|
-
metric?: "cosine" | "euclidean" | "dotProduct";
|
|
284
|
-
minScore?: number;
|
|
285
|
-
}
|
|
286
|
-
/** Full structured query (document query + SQL-style feature set) */
|
|
287
|
-
interface StructuredQuery {
|
|
288
|
-
where?: AnyFilter[];
|
|
289
|
-
orderBy?: OrderByClause[];
|
|
290
|
-
limit?: number;
|
|
291
|
-
offset?: number;
|
|
292
|
-
startAt?: CursorValue;
|
|
293
|
-
startAfter?: CursorValue;
|
|
294
|
-
endAt?: CursorValue;
|
|
295
|
-
endBefore?: CursorValue;
|
|
296
|
-
aggregate?: AggregateSpec[];
|
|
297
|
-
groupBy?: GroupByClause;
|
|
298
|
-
having?: HavingClause[];
|
|
299
|
-
joins?: StructuredJoinClause[];
|
|
300
|
-
vectorSearch?: VectorSearchClause;
|
|
301
|
-
select?: string[];
|
|
302
|
-
distinctField?: string;
|
|
303
|
-
}
|
|
304
|
-
type QueryPresetSpec<Params extends Record<string, unknown> = Record<string, unknown>, Row = any> = {
|
|
305
|
-
params: Params;
|
|
306
|
-
row: Row;
|
|
307
|
-
};
|
|
308
|
-
type QueryPresetMap = Record<string, QueryPresetSpec<any, any>>;
|
|
309
|
-
type QueryPresetParams<TSpec> = TSpec extends QueryPresetSpec<infer Params, any> ? Params : Record<string, unknown>;
|
|
310
|
-
type QueryPresetRow<TSpec> = TSpec extends QueryPresetSpec<any, infer Row> ? Row : any;
|
|
311
|
-
type ChangeOperation = 'insert' | 'update' | 'replace' | 'delete';
|
|
312
|
-
/**
|
|
313
|
-
* Fired once when the subscription is first established.
|
|
314
|
-
* `data` is always an array — the full matching collection snapshot.
|
|
315
|
-
*/
|
|
316
|
-
interface SnapshotEvent<T = any> {
|
|
317
|
-
type: 'snapshot';
|
|
318
|
-
subscriptionId: string;
|
|
319
|
-
collection: string;
|
|
320
|
-
data: T[];
|
|
321
|
-
}
|
|
322
|
-
/**
|
|
323
|
-
* Fired on every subsequent document mutation that matches the subscription query.
|
|
324
|
-
* `data` is the single affected document (null on delete).
|
|
325
|
-
*/
|
|
326
|
-
interface ChangeEvent<T = any> {
|
|
327
|
-
type: 'change';
|
|
328
|
-
subscriptionId: string;
|
|
329
|
-
collection: string;
|
|
330
|
-
docId: string;
|
|
331
|
-
operation: ChangeOperation;
|
|
332
|
-
data: T | null;
|
|
333
|
-
}
|
|
334
|
-
/** Discriminated union — narrow on `event.type` to get the right shape. */
|
|
335
|
-
type SubscriptionData<T = any> = SnapshotEvent<T> | ChangeEvent<T>;
|
|
336
|
-
type SubscriptionCallback<T = any> = (data: SubscriptionData<T>) => void;
|
|
337
|
-
interface SubscriptionError {
|
|
338
|
-
code?: string;
|
|
339
|
-
message: string;
|
|
340
|
-
permissionDenied: boolean;
|
|
341
|
-
raw?: unknown;
|
|
342
|
-
}
|
|
343
|
-
type SubscriptionErrorCallback = (error: SubscriptionError) => void;
|
|
344
|
-
interface SubscriptionHandle {
|
|
345
|
-
(): void;
|
|
346
|
-
unsubscribe: () => void;
|
|
347
|
-
onError: (callback: SubscriptionErrorCallback) => SubscriptionHandle;
|
|
348
|
-
onPermissionDenied: (callback: SubscriptionErrorCallback) => SubscriptionHandle;
|
|
349
|
-
catch: (callback: SubscriptionErrorCallback) => SubscriptionHandle;
|
|
350
|
-
}
|
|
351
|
-
type DocAddedCallback<T = any> = (data: T, docId: string) => void;
|
|
352
|
-
type DocUpdatedCallback<T = any> = (data: T, docId: string) => void;
|
|
353
|
-
type DocDeletedCallback<T = any> = (docId: string) => void;
|
|
354
|
-
type DocChangedCallback<T = any> = (data: T | null, docId: string, operation: ChangeOperation) => void;
|
|
355
|
-
type StreamFlushReason = 'snapshot' | 'change-batch';
|
|
356
|
-
interface CollectionStreamOptions<T = any> {
|
|
357
|
-
/** Delay before a queued burst is flushed to listeners. */
|
|
358
|
-
flushMs?: number;
|
|
359
|
-
/** Flush immediately when queued changes reach this count. */
|
|
360
|
-
maxBatchSize?: number;
|
|
361
|
-
/** Field used to identify docs inside snapshots when getId is not provided. */
|
|
362
|
-
idField?: keyof T & string;
|
|
363
|
-
/** Custom identifier extractor for snapshot rows. */
|
|
364
|
-
getId?: (doc: T) => string | undefined;
|
|
365
|
-
/** Where newly inserted docs should be placed when they were not in snapshot. */
|
|
366
|
-
insertAt?: 'start' | 'end';
|
|
367
|
-
/** Optional cap to keep only the newest N docs in local stream state. */
|
|
368
|
-
maxDocs?: number;
|
|
369
|
-
/** Optional local sort run after flush. */
|
|
370
|
-
sort?: (a: T, b: T) => number;
|
|
371
|
-
}
|
|
372
|
-
interface CollectionStreamMeta {
|
|
373
|
-
reason: StreamFlushReason;
|
|
374
|
-
batchSize: number;
|
|
375
|
-
version: number;
|
|
376
|
-
ready: boolean;
|
|
377
|
-
}
|
|
378
|
-
type CollectionStreamListener<T = any> = (rows: readonly T[], meta: CollectionStreamMeta) => void;
|
|
379
|
-
interface CollectionStream<T = any> {
|
|
380
|
-
/** Subscribe to stream updates (call unsubscribe to stop). */
|
|
381
|
-
subscribe: (listener: CollectionStreamListener<T>, emitCurrent?: boolean) => () => void;
|
|
382
|
-
/** Returns the latest immutable snapshot of rows. */
|
|
383
|
-
getSnapshot: () => readonly T[];
|
|
384
|
-
/** Returns true after the initial snapshot has been received. */
|
|
385
|
-
isReady: () => boolean;
|
|
386
|
-
/** Monotonic version incremented on each flush. */
|
|
387
|
-
getVersion: () => number;
|
|
388
|
-
/** Stop the underlying realtime subscription and cleanup timers/listeners. */
|
|
389
|
-
close: () => void;
|
|
390
|
-
/** Attach subscription-level error handler. */
|
|
391
|
-
onError: (callback: SubscriptionErrorCallback) => CollectionStream<T>;
|
|
392
|
-
/** Attach permission-denied handler. */
|
|
393
|
-
onPermissionDenied: (callback: SubscriptionErrorCallback) => CollectionStream<T>;
|
|
394
|
-
}
|
|
395
|
-
interface CollectionExternalStore<T = any> {
|
|
396
|
-
/** Standard external-store subscribe signature used by UI store hooks. */
|
|
397
|
-
subscribe: (onStoreChange: () => void) => () => void;
|
|
398
|
-
/** Returns current immutable rows snapshot. */
|
|
399
|
-
getSnapshot: () => readonly T[];
|
|
400
|
-
/** Server snapshot fallback for SSR-safe store hooks. */
|
|
401
|
-
getServerSnapshot: () => readonly T[];
|
|
402
|
-
/** Access to underlying realtime stream for advanced handlers. */
|
|
403
|
-
stream: CollectionStream<T>;
|
|
404
|
-
/** Stops realtime stream and detaches listeners. */
|
|
405
|
-
destroy: () => void;
|
|
406
|
-
}
|
|
407
|
-
interface DocumentSnapshot<T = any> {
|
|
408
|
-
id: string;
|
|
409
|
-
data: T | null;
|
|
410
|
-
exists: boolean;
|
|
411
|
-
}
|
|
412
|
-
interface QuerySnapshot<T = any> {
|
|
413
|
-
docs: DocumentSnapshot<T>[];
|
|
414
|
-
size: number;
|
|
415
|
-
empty: boolean;
|
|
416
|
-
}
|
|
417
|
-
interface OfflineOperation {
|
|
418
|
-
id: string;
|
|
419
|
-
type: 'write' | 'delete';
|
|
420
|
-
collection: string;
|
|
421
|
-
docId: string;
|
|
422
|
-
data?: Record<string, unknown>;
|
|
423
|
-
merge?: boolean;
|
|
424
|
-
clientTs: number;
|
|
425
|
-
}
|
|
426
|
-
interface AuthResult {
|
|
427
|
-
uid: string;
|
|
428
|
-
token?: string;
|
|
429
|
-
}
|
|
430
|
-
type ConnectionState = 'connecting' | 'connected' | 'disconnected' | 'reconnecting' | 'error';
|
|
431
|
-
interface AuthWithPendingVerificationResult {
|
|
432
|
-
verificationRequired: true;
|
|
433
|
-
created: true;
|
|
434
|
-
emailSent: boolean;
|
|
435
|
-
preview?: {
|
|
436
|
-
code: string;
|
|
437
|
-
link: string;
|
|
438
|
-
};
|
|
439
|
-
}
|
|
440
|
-
interface AuthWithTokenResult extends AuthResult {
|
|
441
|
-
accessToken: string;
|
|
442
|
-
refreshToken: string | null;
|
|
443
|
-
authToken: AuthToken;
|
|
444
|
-
created: boolean;
|
|
445
|
-
}
|
|
446
|
-
interface PresenceMember {
|
|
447
|
-
uid: string;
|
|
448
|
-
socketId: string;
|
|
449
|
-
room: string;
|
|
450
|
-
meta?: Record<string, unknown>;
|
|
451
|
-
joinedAt: number;
|
|
452
|
-
lastSeen: number;
|
|
453
|
-
}
|
|
454
|
-
type PresenceCallback = (members: PresenceMember[]) => void;
|
|
455
|
-
type PresenceJoinCallback = (member: PresenceMember) => void;
|
|
456
|
-
type PresenceLeaveCallback = (uid: string) => void;
|
|
457
|
-
/** Fields marked as vector will be auto-embedded before write */
|
|
458
|
-
type VectorFieldConfig = {
|
|
459
|
-
/** Dimensions of the vector (e.g. 1536 for OpenAI ada-002) */
|
|
460
|
-
dimensions: number;
|
|
461
|
-
/** Optional custom embedding function; defaults to client-configured embedder */
|
|
462
|
-
embed?: (text: string) => Promise<number[]>;
|
|
463
|
-
};
|
|
464
|
-
type RulePermission = "create" | "read" | "update" | "delete";
|
|
465
|
-
interface FlareRule {
|
|
466
|
-
id: string;
|
|
467
|
-
name: string;
|
|
468
|
-
auth: "any" | "guest" | "auth";
|
|
469
|
-
collection: string;
|
|
470
|
-
document?: string;
|
|
471
|
-
condition?: string;
|
|
472
|
-
permissions: RulePermission[];
|
|
473
|
-
}
|
|
474
|
-
interface SecurityRuleEntry {
|
|
475
|
-
".read"?: string;
|
|
476
|
-
".write"?: string;
|
|
477
|
-
".create"?: string;
|
|
478
|
-
".update"?: string;
|
|
479
|
-
".delete"?: string;
|
|
480
|
-
}
|
|
481
|
-
type SecurityRulesMap = Record<string, SecurityRuleEntry>;
|
|
482
|
-
declare const flareRulesToSecurityMap: (rules: FlareRule[]) => SecurityRulesMap;
|
|
483
|
-
declare const securityMapToFlareRules: (rules: SecurityRulesMap) => FlareRule[];
|
|
484
|
-
|
|
485
|
-
/**
|
|
486
|
-
* Parse ORM-style where condition: { age: ">= 25", role: "admin" }
|
|
487
|
-
* Returns array of QueryConfig objects
|
|
488
|
-
*/
|
|
489
|
-
declare function parseWhereCondition(condition: WhereCondition): QueryConfig[];
|
|
490
|
-
/**
|
|
491
|
-
* Parse string value to appropriate type
|
|
492
|
-
*/
|
|
493
|
-
declare function parseValue(val: string): any;
|
|
494
|
-
/**
|
|
495
|
-
* Query builder for document operations (ORM-style)
|
|
496
|
-
* Supports: doc('users').update({...}).where({ id: 'alice' })
|
|
497
|
-
*
|
|
498
|
-
* This class is thenable - you can await it directly without .execute() or .get()
|
|
499
|
-
* @example
|
|
500
|
-
* await doc('users').where({ id: 'alice' })
|
|
501
|
-
* await doc('users').update({ name: 'Alice' }).where({ id: 'alice' })
|
|
502
|
-
*/
|
|
503
|
-
declare class DocumentQueryBuilder<T = any> implements PromiseLike<T | null | void> {
|
|
504
|
-
private client;
|
|
505
|
-
private collection;
|
|
506
|
-
private docIdFromRef?;
|
|
507
|
-
private whereCondition?;
|
|
508
|
-
private updateData?;
|
|
509
|
-
private setData?;
|
|
510
|
-
private deleteOp;
|
|
511
|
-
private promise?;
|
|
512
|
-
constructor(client: FlareClient<any>, collection: string, docIdFromRef?: string | undefined);
|
|
513
|
-
/**
|
|
514
|
-
* Set where condition
|
|
515
|
-
*/
|
|
516
|
-
where(condition: WhereCondition): this;
|
|
517
|
-
/**
|
|
518
|
-
* Set update data (for update operations)
|
|
519
|
-
*/
|
|
520
|
-
update(data: Partial<T>): this;
|
|
521
|
-
/**
|
|
522
|
-
* Set data (for set operations)
|
|
523
|
-
*/
|
|
524
|
-
set(data: Partial<T>): this;
|
|
525
|
-
/**
|
|
526
|
-
* Mark for deletion
|
|
527
|
-
*/
|
|
528
|
-
delete(): this;
|
|
529
|
-
/**
|
|
530
|
-
* Get the document ID from doc() reference or where condition.
|
|
531
|
-
*/
|
|
532
|
-
private getDocId;
|
|
533
|
-
/**
|
|
534
|
-
* Execute the query
|
|
535
|
-
* @deprecated Use await directly instead of .execute()
|
|
536
|
-
*/
|
|
537
|
-
execute(): Promise<T | null | void>;
|
|
538
|
-
/**
|
|
539
|
-
* Internal execute method
|
|
540
|
-
*/
|
|
541
|
-
private _execute;
|
|
542
|
-
/**
|
|
543
|
-
* Make this class thenable so it can be awaited directly
|
|
544
|
-
*/
|
|
545
|
-
then<TResult1 = T | null | void, TResult2 = never>(onfulfilled?: ((value: T | null | void) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null): PromiseLike<TResult1 | TResult2>;
|
|
546
|
-
/**
|
|
547
|
-
* Get the document data once
|
|
548
|
-
*/
|
|
549
|
-
get(): Promise<T | null>;
|
|
550
|
-
/**
|
|
551
|
-
* Subscribe to real-time updates
|
|
552
|
-
*/
|
|
553
|
-
onSnapshot(callback: SubscriptionCallback<T>): () => void;
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
/** Document reference */
|
|
557
|
-
declare class DocumentReference<T = any> {
|
|
558
|
-
private client;
|
|
559
|
-
readonly collection: string;
|
|
560
|
-
readonly id: string;
|
|
561
|
-
constructor(client: FlareClient<any>, collection: string, id: string);
|
|
562
|
-
get(): Promise<T | null>;
|
|
563
|
-
set(data: Partial<T>): Promise<void>;
|
|
564
|
-
update(data: Partial<T>): Promise<void>;
|
|
565
|
-
delete(): Promise<void>;
|
|
566
|
-
onSnapshot(callback: SubscriptionCallback<T>): () => void;
|
|
567
|
-
/**
|
|
568
|
-
* Fires when this document is updated / replaced.
|
|
569
|
-
*/
|
|
570
|
-
onDocUpdated(callback: DocUpdatedCallback<T>): () => void;
|
|
571
|
-
/**
|
|
572
|
-
* Fires when this document is deleted.
|
|
573
|
-
*/
|
|
574
|
-
onDocDeleted(callback: DocDeletedCallback<T>): () => void;
|
|
575
|
-
/**
|
|
576
|
-
* Fires on any change to this document (update / delete).
|
|
577
|
-
* `data` is null on deletes.
|
|
578
|
-
*/
|
|
579
|
-
onDocChanged(callback: DocChangedCallback<T>): () => void;
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
type CollectionPresetMethods<TPresetMap extends QueryPresetMap> = {
|
|
583
|
-
[K in keyof TPresetMap & string]: (params: QueryPresetParams<TPresetMap[K]>) => CollectionQuery<QueryPresetRow<TPresetMap[K]>, TPresetMap>;
|
|
584
|
-
};
|
|
585
|
-
type CollectionQuery<T = any, TPresetMap extends QueryPresetMap = {}> = CollectionReference<T, TPresetMap> & CollectionPresetMethods<TPresetMap>;
|
|
586
|
-
declare class CollectionReference<T = any, TPresetMap extends QueryPresetMap = {}> implements PromiseLike<T[]> {
|
|
587
|
-
private client;
|
|
588
|
-
readonly collection: string;
|
|
589
|
-
private sq;
|
|
590
|
-
private promise?;
|
|
591
|
-
constructor(client: FlareClient<TPresetMap>, collection: string);
|
|
592
|
-
doc(id: string): DocumentReference<T>;
|
|
593
|
-
private clone;
|
|
594
|
-
private normalizeFilterValue;
|
|
595
|
-
private normalizeFilter;
|
|
596
|
-
private toQueryFilters;
|
|
597
|
-
private appendOperatorFilter;
|
|
598
|
-
private appendAndFilters;
|
|
599
|
-
private toOrNode;
|
|
600
|
-
private toAndNode;
|
|
601
|
-
private isLeafFilter;
|
|
602
|
-
private isIdentityGuard;
|
|
603
|
-
private splitIdentityGuards;
|
|
604
|
-
private appendOrFilters;
|
|
605
|
-
private appendFilters;
|
|
606
|
-
with<Name extends keyof TPresetMap & string>(name: Name, params: QueryPresetParams<TPresetMap[Name]>): CollectionQuery<QueryPresetRow<TPresetMap[Name]>, TPresetMap>;
|
|
607
|
-
with(name: string, params?: Record<string, unknown>): CollectionQuery<T, TPresetMap>;
|
|
608
|
-
/** ORM shorthand: .where({ age: ">= 25", role: "admin" }) */
|
|
609
|
-
where(condition: WhereCondition): CollectionQuery<T, TPresetMap>;
|
|
610
|
-
and(condition: WhereCondition): CollectionQuery<T, TPresetMap>;
|
|
611
|
-
or(condition: WhereCondition): CollectionQuery<T, TPresetMap>;
|
|
612
|
-
in(field: string, values: unknown[] | unknown): CollectionQuery<T, TPresetMap>;
|
|
613
|
-
andIn(field: string, values: unknown[] | unknown): CollectionQuery<T, TPresetMap>;
|
|
614
|
-
orIn(field: string, values: unknown[] | unknown): CollectionQuery<T, TPresetMap>;
|
|
615
|
-
notIn(field: string, values: unknown[] | unknown): CollectionQuery<T, TPresetMap>;
|
|
616
|
-
andNotIn(field: string, values: unknown[] | unknown): CollectionQuery<T, TPresetMap>;
|
|
617
|
-
orNotIn(field: string, values: unknown[] | unknown): CollectionQuery<T, TPresetMap>;
|
|
618
|
-
arrayContains(field: string, value: unknown): CollectionQuery<T, TPresetMap>;
|
|
619
|
-
andArrayContains(field: string, value: unknown): CollectionQuery<T, TPresetMap>;
|
|
620
|
-
orArrayContains(field: string, value: unknown): CollectionQuery<T, TPresetMap>;
|
|
621
|
-
arrayContainsAny(field: string, values: unknown[] | unknown): CollectionQuery<T, TPresetMap>;
|
|
622
|
-
andArrayContainsAny(field: string, values: unknown[] | unknown): CollectionQuery<T, TPresetMap>;
|
|
623
|
-
orArrayContainsAny(field: string, values: unknown[] | unknown): CollectionQuery<T, TPresetMap>;
|
|
624
|
-
some(field: string, condition: Record<string, unknown>): CollectionQuery<T, TPresetMap>;
|
|
625
|
-
andSome(field: string, condition: Record<string, unknown>): CollectionQuery<T, TPresetMap>;
|
|
626
|
-
orSome(field: string, condition: Record<string, unknown>): CollectionQuery<T, TPresetMap>;
|
|
627
|
-
like(field: string, value: string): CollectionQuery<T, TPresetMap>;
|
|
628
|
-
andLike(field: string, value: string): CollectionQuery<T, TPresetMap>;
|
|
629
|
-
orLike(field: string, value: string): CollectionQuery<T, TPresetMap>;
|
|
630
|
-
notLike(field: string, value: string): CollectionQuery<T, TPresetMap>;
|
|
631
|
-
andNotLike(field: string, value: string): CollectionQuery<T, TPresetMap>;
|
|
632
|
-
orNotLike(field: string, value: string): CollectionQuery<T, TPresetMap>;
|
|
633
|
-
exists(field: string): CollectionQuery<T, TPresetMap>;
|
|
634
|
-
andExists(field: string): CollectionQuery<T, TPresetMap>;
|
|
635
|
-
orExists(field: string): CollectionQuery<T, TPresetMap>;
|
|
636
|
-
notExists(field: string): CollectionQuery<T, TPresetMap>;
|
|
637
|
-
andNotExists(field: string): CollectionQuery<T, TPresetMap>;
|
|
638
|
-
orNotExists(field: string): CollectionQuery<T, TPresetMap>;
|
|
639
|
-
/** Get items starting from the most recently created (descending sequence) */
|
|
640
|
-
latest(): CollectionQuery<T, TPresetMap>;
|
|
641
|
-
/** Get items starting from the most recently created (descending sequence) */
|
|
642
|
-
newest(): CollectionQuery<T, TPresetMap>;
|
|
643
|
-
/** Get items starting from the first ever created (ascending sequence) */
|
|
644
|
-
oldest(): CollectionQuery<T, TPresetMap>;
|
|
645
|
-
orderBy(field: string, dir?: "asc" | "desc"): CollectionQuery<T, TPresetMap>;
|
|
646
|
-
limit(n: number): CollectionQuery<T, TPresetMap>;
|
|
647
|
-
offset(n: number): CollectionQuery<T, TPresetMap>;
|
|
648
|
-
startAt(...values: unknown[]): CollectionQuery<T, TPresetMap>;
|
|
649
|
-
startAfter(...values: unknown[]): CollectionQuery<T, TPresetMap>;
|
|
650
|
-
endAt(...values: unknown[]): CollectionQuery<T, TPresetMap>;
|
|
651
|
-
endBefore(...values: unknown[]): CollectionQuery<T, TPresetMap>;
|
|
652
|
-
aggregate(...specs: AggregateSpec[]): CollectionQuery<T, TPresetMap>;
|
|
653
|
-
count(alias?: string): CollectionQuery<T, TPresetMap>;
|
|
654
|
-
sum(field: string, alias?: string): CollectionQuery<T, TPresetMap>;
|
|
655
|
-
avg(field: string, alias?: string): CollectionQuery<T, TPresetMap>;
|
|
656
|
-
min(field: string, alias?: string): CollectionQuery<T, TPresetMap>;
|
|
657
|
-
max(field: string, alias?: string): CollectionQuery<T, TPresetMap>;
|
|
658
|
-
distinct(field: string, alias?: string): CollectionQuery<T, TPresetMap>;
|
|
659
|
-
groupBy(...fields: string[]): CollectionQuery<T, TPresetMap>;
|
|
660
|
-
having(field: string, op: HavingClause['op'], value: number): CollectionQuery<T, TPresetMap>;
|
|
661
|
-
private buildStructuredJoin;
|
|
662
|
-
private cloneStructuredJoin;
|
|
663
|
-
private appendNestedJoinByAlias;
|
|
664
|
-
private parseRelationRef;
|
|
665
|
-
/**
|
|
666
|
-
* Join another collection into this query.
|
|
667
|
-
*
|
|
668
|
-
* @param collectionName Joined collection name.
|
|
669
|
-
* @param j Join mapping clause.
|
|
670
|
-
* @example
|
|
671
|
-
* flare.collection("boards")
|
|
672
|
-
* .join("tasks", { source: "id", target: "boardId", as: "tasks" })
|
|
673
|
-
* .get();
|
|
674
|
-
*/
|
|
675
|
-
join(collectionName: string, j: JoinClause): CollectionQuery<T, TPresetMap>;
|
|
676
|
-
/**
|
|
677
|
-
* Append a nested join under an existing join alias.
|
|
678
|
-
* Example:
|
|
679
|
-
* .join("lists", { source: "id", target: "boardId", as: "lists" })
|
|
680
|
-
* .joinNested("lists", "cards", { source: "id", target: "listId", as: "cards" })
|
|
681
|
-
*/
|
|
682
|
-
joinNested(parentAlias: string, collectionName: string, j: JoinClause): CollectionQuery<T, TPresetMap>;
|
|
683
|
-
Join(collectionName: string, j: JoinClause): CollectionQuery<T, TPresetMap>;
|
|
684
|
-
JoinNested(parentAlias: string, collectionName: string, j: JoinClause): CollectionQuery<T, TPresetMap>;
|
|
685
|
-
/**
|
|
686
|
-
* SQL-like relation shorthand.
|
|
687
|
-
* Example: .withRelation("team.uid->users.id", { as: "teamMembers" })
|
|
688
|
-
*/
|
|
689
|
-
withRelation(relation: string, options?: (Omit<JoinClause, 'source' | 'target' | 'as'> & {
|
|
690
|
-
as?: string;
|
|
691
|
-
})): CollectionQuery<T, TPresetMap>;
|
|
692
|
-
select(...fields: string[]): CollectionQuery<T, TPresetMap>;
|
|
693
|
-
/** Returns unique values for a single field */
|
|
694
|
-
distinctField(field: string): CollectionQuery<T, TPresetMap>;
|
|
695
|
-
/**
|
|
696
|
-
* KNN nearest-neighbour search (requires Atlas vector index).
|
|
697
|
-
* @example
|
|
698
|
-
* col.vectorSearch({ field: "embedding", vector: [...1536 numbers...], k: 10 })
|
|
699
|
-
*/
|
|
700
|
-
vectorSearch(opts: VectorSearchClause): CollectionQuery<T, TPresetMap>;
|
|
701
|
-
getRawQuery(): {
|
|
702
|
-
collection: string;
|
|
703
|
-
query: StructuredQuery;
|
|
704
|
-
};
|
|
705
|
-
get(): Promise<T[]>;
|
|
706
|
-
first(): Promise<T | null>;
|
|
707
|
-
last(): Promise<T | null>;
|
|
708
|
-
private _isStructured;
|
|
709
|
-
private _execute;
|
|
710
|
-
private _executeQuery;
|
|
711
|
-
private _executeSubscribe;
|
|
712
|
-
then<TResult1 = T[], TResult2 = never>(onfulfilled?: ((value: T[]) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null): PromiseLike<TResult1 | TResult2>;
|
|
713
|
-
/**
|
|
714
|
-
* Subscribe to real-time updates.
|
|
715
|
-
* The full StructuredQuery (including orderBy, where, limit, offset) is sent
|
|
716
|
-
* to the server so the initial snapshot respects all constraints.
|
|
717
|
-
* Individual change events are then sorted / filtered client-side to keep
|
|
718
|
-
* the live result consistent.
|
|
719
|
-
*/
|
|
720
|
-
onSnapshot(callback: SubscriptionCallback<T[]>): SubscriptionHandle;
|
|
721
|
-
/**
|
|
722
|
-
* High-throughput stream wrapper for bursty collections (chat, feeds, logs).
|
|
723
|
-
* It keeps local state and flushes change bursts in batches to reduce UI churn.
|
|
724
|
-
*/
|
|
725
|
-
stream(options?: CollectionStreamOptions<T>): CollectionStream<T>;
|
|
726
|
-
/**
|
|
727
|
-
* Framework-agnostic external-store bridge.
|
|
728
|
-
* Compatible with UI hooks expecting subscribe/getSnapshot signatures.
|
|
729
|
-
*/
|
|
730
|
-
asStore(options?: CollectionStreamOptions<T>): CollectionExternalStore<T>;
|
|
731
|
-
onDocAdded(callback: DocAddedCallback<T>): () => void;
|
|
732
|
-
onDocUpdated(callback: DocUpdatedCallback<T>): () => void;
|
|
733
|
-
onDocDeleted(callback: DocDeletedCallback<T>): () => void;
|
|
734
|
-
onDocChanged(callback: DocChangedCallback<T>): () => void;
|
|
735
|
-
add(data: Partial<T>): Promise<DocumentReference<T>>;
|
|
736
|
-
update(data: Partial<T>): DocumentQueryBuilder<T>;
|
|
737
|
-
delete(): DocumentQueryBuilder<T>;
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
/** Client Request */
|
|
741
|
-
declare enum FlareAction {
|
|
742
|
-
SUBSCRIBE = "subscribe",
|
|
743
|
-
UNSUBSCRIBE = "unsubscribe",
|
|
744
|
-
WRITE = "write",
|
|
745
|
-
DELETE = "delete",
|
|
746
|
-
AUTH = "auth",
|
|
747
|
-
PING = "ping",
|
|
748
|
-
OFFLINE_SYNC = "offline_sync",
|
|
749
|
-
CALL = "call",
|
|
750
|
-
/** One-shot rich query (no real-time subscription) */
|
|
751
|
-
QUERY = "query",
|
|
752
|
-
/** Presence */
|
|
753
|
-
PRESENCE_JOIN = "presence_join",
|
|
754
|
-
PRESENCE_LEAVE = "presence_leave",
|
|
755
|
-
PRESENCE_HEARTBEAT = "presence_heartbeat"
|
|
756
|
-
}
|
|
757
|
-
/** Server Response */
|
|
758
|
-
declare enum FlareEvent {
|
|
759
|
-
SNAPSHOT = "snapshot",
|
|
760
|
-
CHANGE = "change",
|
|
761
|
-
ERROR = "error",
|
|
762
|
-
ACK = "ack",
|
|
763
|
-
PONG = "pong",
|
|
764
|
-
AUTH_OK = "auth_ok",
|
|
765
|
-
OFFLINE_ACK = "offline_ack",
|
|
766
|
-
CALL_RESPONSE = "call_response",
|
|
767
|
-
QUERY_RESULT = "query_result",
|
|
768
|
-
PRESENCE_STATE = "presence_state",
|
|
769
|
-
PRESENCE_JOIN = "presence_join",
|
|
770
|
-
PRESENCE_LEAVE = "presence_leave"
|
|
771
|
-
}
|
|
772
|
-
interface BaseMessage {
|
|
773
|
-
id: string;
|
|
774
|
-
type: FlareAction | FlareEvent;
|
|
775
|
-
ts: number;
|
|
776
|
-
}
|
|
777
|
-
interface SubscribeMessage extends BaseMessage {
|
|
778
|
-
type: FlareAction.SUBSCRIBE;
|
|
779
|
-
collection: string;
|
|
780
|
-
docId?: string;
|
|
781
|
-
query?: Record<string, unknown>;
|
|
782
|
-
skipSnapshot?: boolean;
|
|
783
|
-
resumeToken?: string;
|
|
784
|
-
}
|
|
785
|
-
|
|
786
|
-
type TransportOptions = {
|
|
787
|
-
url: string;
|
|
788
|
-
onMessage: (data: any) => void;
|
|
789
|
-
onOpen?: () => void;
|
|
790
|
-
onClose?: () => void;
|
|
791
|
-
onError?: (error: Error) => void;
|
|
792
|
-
autoReconnect?: boolean;
|
|
793
|
-
reconnectDelay?: number;
|
|
794
|
-
maxReconnectDelay?: number;
|
|
795
|
-
debug?: boolean;
|
|
796
|
-
/** RSA public key (PEM). When set, all outgoing messages are RSA-OAEP encrypted. */
|
|
797
|
-
publicKey?: string;
|
|
798
|
-
};
|
|
799
|
-
|
|
800
|
-
declare class FlareTransport {
|
|
801
|
-
private socket;
|
|
802
|
-
private reconnectInterval;
|
|
803
|
-
private maxReconnectDelay;
|
|
804
|
-
private isConnected;
|
|
805
|
-
private shouldReconnect;
|
|
806
|
-
private options;
|
|
807
|
-
private messageQueue;
|
|
808
|
-
private heartbeatInterval;
|
|
809
|
-
private connectionTimeout;
|
|
810
|
-
constructor(options: TransportOptions);
|
|
811
|
-
connect(): void;
|
|
812
|
-
private handleReconnect;
|
|
813
|
-
private startHeartbeat;
|
|
814
|
-
private stopHeartbeat;
|
|
815
|
-
private flushQueue;
|
|
816
|
-
send(message: object): void;
|
|
817
|
-
disconnect(): void;
|
|
818
|
-
get connected(): boolean;
|
|
819
|
-
private log;
|
|
820
|
-
}
|
|
821
|
-
|
|
822
|
-
type ConnectionListener = (state: ConnectionState) => void;
|
|
823
|
-
type ErrorListener = (error: Error) => void;
|
|
824
|
-
type HttpResponseSnapshot = {
|
|
825
|
-
status: number;
|
|
826
|
-
headers: Record<string, string>;
|
|
827
|
-
data: any;
|
|
828
|
-
};
|
|
829
|
-
type ActiveSubscription = {
|
|
830
|
-
baseId: string;
|
|
831
|
-
liveId: string;
|
|
832
|
-
collection: string;
|
|
833
|
-
docId?: string;
|
|
834
|
-
query?: StructuredQuery;
|
|
835
|
-
callback: SubscriptionCallback;
|
|
836
|
-
options: SubscribeOptions;
|
|
837
|
-
};
|
|
838
|
-
type QueryPresetHandler<Params extends Record<string, unknown> = Record<string, unknown>, Row = any> = (ref: CollectionQuery<any, any>, params: Params) => CollectionQuery<Row, any>;
|
|
839
|
-
/** Embedder function registered by the user */
|
|
840
|
-
type EmbedFn = (text: string) => Promise<number[]>;
|
|
841
|
-
declare class FlareBase<TPresetMap extends QueryPresetMap = {}> {
|
|
842
|
-
protected transport: FlareTransport;
|
|
843
|
-
protected readonly config: FlareConfig;
|
|
844
|
-
protected readonly pendingAcks: Map<string, (value: any) => void>;
|
|
845
|
-
protected readonly subscriptions: Map<string, SubscriptionCallback>;
|
|
846
|
-
protected readonly activeSubscriptions: Map<string, ActiveSubscription>;
|
|
847
|
-
protected readonly queryPresets: Map<string, QueryPresetHandler<any, any>>;
|
|
848
|
-
protected readonly subscriptionErrorHandlers: Map<string, Set<SubscriptionErrorCallback>>;
|
|
849
|
-
protected readonly subscriptionPermissionHandlers: Map<string, Set<SubscriptionErrorCallback>>;
|
|
850
|
-
protected readonly subscriptionLastErrors: Map<string, SubscriptionError>;
|
|
851
|
-
protected readonly offlineQueue: any[];
|
|
852
|
-
protected currentState: ConnectionState;
|
|
853
|
-
protected connectionListeners: ConnectionListener[];
|
|
854
|
-
protected errorListeners: ErrorListener[];
|
|
855
|
-
protected isDebug: boolean;
|
|
856
|
-
protected socketAuthUid: string;
|
|
857
|
-
protected pendingSubscriptionReplay: boolean;
|
|
858
|
-
protected subscriptionReplayPromise: Promise<void>;
|
|
859
|
-
protected requestTraceSeq: number;
|
|
860
|
-
protected requestTimingEnabled: boolean;
|
|
861
|
-
protected httpInFlight: Map<string, Promise<HttpResponseSnapshot>>;
|
|
862
|
-
protected httpResponseCache: Map<string, HttpResponseSnapshot>;
|
|
863
|
-
protected readonly maxHttpCacheEntries = 200;
|
|
864
|
-
protected presenceCallbacks: Map<string, PresenceCallback[]>;
|
|
865
|
-
protected presenceJoinCbs: Map<string, PresenceJoinCallback[]>;
|
|
866
|
-
protected presenceLeaveCbs: Map<string, PresenceLeaveCallback[]>;
|
|
867
|
-
protected presenceHeartbeatTimer?: ReturnType<typeof setInterval>;
|
|
868
|
-
protected embedder?: EmbedFn;
|
|
869
|
-
protected vectorSchema: Map<string, Map<string, VectorFieldConfig>>;
|
|
870
|
-
protected throwFetchFlareError(payload: unknown, fallbackMessage: string, fallbackCode: string): never;
|
|
871
|
-
protected nowMs(): number;
|
|
872
|
-
protected normalizeHeaders(headers?: HeadersInit): Record<string, string>;
|
|
873
|
-
protected redactHeaders(headers: Record<string, string>): Record<string, string>;
|
|
874
|
-
protected stableStringify(value: unknown): string;
|
|
875
|
-
protected buildHttpCacheKey(method: string, url: string, headers: Record<string, string>, body: unknown, credentials?: RequestCredentials): string;
|
|
876
|
-
protected shouldCacheResponse(method: string, url: string): boolean;
|
|
877
|
-
protected rememberHttpResponse(key: string, value: HttpResponseSnapshot): void;
|
|
878
|
-
protected createTimedFetchTrace(snapshot: HttpResponseSnapshot, requestId: number, startedAtMs: number, method: string, url: string, networkMs: number): {
|
|
879
|
-
response: {
|
|
880
|
-
status: number;
|
|
881
|
-
ok: boolean;
|
|
882
|
-
headers: {
|
|
883
|
-
get: (name: string) => string | null;
|
|
884
|
-
};
|
|
885
|
-
json: () => Promise<any>;
|
|
886
|
-
};
|
|
887
|
-
requestId: number;
|
|
888
|
-
startedAtMs: number;
|
|
889
|
-
networkMs: number;
|
|
890
|
-
method: string;
|
|
891
|
-
url: string;
|
|
892
|
-
};
|
|
893
|
-
protected logHttpTiming(...args: any[]): void;
|
|
894
|
-
protected mergeHeaders(base: HeadersInit | undefined, extra: Record<string, string>): HeadersInit;
|
|
895
|
-
protected toWireField(field: string): string;
|
|
896
|
-
protected fromWireField(field: string): string;
|
|
897
|
-
protected normalizeOutboundData(value: unknown): unknown;
|
|
898
|
-
protected normalizeInboundData(value: unknown): unknown;
|
|
899
|
-
private getDataMapper;
|
|
900
|
-
private runMapper;
|
|
901
|
-
private applyJoinAliasMappers;
|
|
902
|
-
mapInboundResult(collection: string, payload: unknown, query?: StructuredQuery): unknown;
|
|
903
|
-
protected normalizeOutboundAnyFilter(filter: Record<string, unknown>): Record<string, unknown>;
|
|
904
|
-
protected normalizeOutboundQuery(query: unknown): unknown;
|
|
905
|
-
protected timedFetch(label: string, input: string, init?: RequestInit): Promise<{
|
|
906
|
-
response: {
|
|
907
|
-
status: number;
|
|
908
|
-
ok: boolean;
|
|
909
|
-
headers: {
|
|
910
|
-
get: (name: string) => string | null;
|
|
911
|
-
};
|
|
912
|
-
json: () => Promise<any>;
|
|
913
|
-
};
|
|
914
|
-
requestId: number;
|
|
915
|
-
startedAtMs: number;
|
|
916
|
-
networkMs: number;
|
|
917
|
-
method: string;
|
|
918
|
-
url: string;
|
|
919
|
-
}>;
|
|
920
|
-
protected parseJsonWithTiming(label: string, trace: {
|
|
921
|
-
requestId: number;
|
|
922
|
-
startedAtMs: number;
|
|
923
|
-
response: {
|
|
924
|
-
status: number;
|
|
925
|
-
ok: boolean;
|
|
926
|
-
headers: {
|
|
927
|
-
get: (name: string) => string | null;
|
|
928
|
-
};
|
|
929
|
-
json: () => Promise<any>;
|
|
930
|
-
};
|
|
931
|
-
networkMs: number;
|
|
932
|
-
method: string;
|
|
933
|
-
url: string;
|
|
934
|
-
}): Promise<any>;
|
|
935
|
-
protected getHttpBase(): string;
|
|
936
|
-
protected log(...args: any[]): void;
|
|
937
|
-
constructor(config: FlareConfig);
|
|
938
|
-
connect(): void;
|
|
939
|
-
disconnect(): void;
|
|
940
|
-
get connectionState(): ConnectionState;
|
|
941
|
-
get isConnected(): boolean;
|
|
942
|
-
onConnectionStateChange(listener: ConnectionListener): () => void;
|
|
943
|
-
onError(callback: ErrorListener): () => void;
|
|
944
|
-
collection<T = any>(name: string): CollectionQuery<T, TPresetMap>;
|
|
945
|
-
registerQueryPreset<Name extends string, Params extends Record<string, unknown>, Row = any>(name: Name, handler: QueryPresetHandler<Params, Row>): this & FlareBase<TPresetMap & Record<Name, QueryPresetSpec<Params, Row>>>;
|
|
946
|
-
registerQueryPresets<TRegistry extends Record<string, QueryPresetHandler<any, any>>>(presets: TRegistry): this & FlareBase<TPresetMap & {
|
|
947
|
-
[K in keyof TRegistry]: TRegistry[K] extends QueryPresetHandler<infer Params, infer Row> ? QueryPresetSpec<Params, Row> : QueryPresetSpec<Record<string, unknown>, any>;
|
|
948
|
-
}>;
|
|
949
|
-
hasQueryPreset(name: string): boolean;
|
|
950
|
-
applyQueryPreset<Name extends keyof TPresetMap & string>(ref: CollectionReference<any, TPresetMap>, name: Name, params: QueryPresetParams<TPresetMap[Name]>): CollectionQuery<QueryPresetRow<TPresetMap[Name]>, TPresetMap>;
|
|
951
|
-
applyQueryPreset<T = any>(ref: CollectionQuery<T, TPresetMap>, name: string, params?: Record<string, unknown>): CollectionQuery<T, TPresetMap>;
|
|
952
|
-
doc<T = any>(collection: string): DocumentQueryBuilder<T>;
|
|
953
|
-
doc<T = any>(collection: string, id: string): DocumentReference<T>;
|
|
954
|
-
ping(): Promise<number>;
|
|
955
|
-
call<T = Record<string, unknown>>(topic: string, payload?: Record<string, unknown>): Promise<T>;
|
|
956
|
-
query<T = Record<string, unknown>>(collection: string, q?: StructuredQuery): Promise<T[]>;
|
|
957
|
-
setEmbedder(fn: EmbedFn): void;
|
|
958
|
-
markVectorField(collection: string, field: string, config?: VectorFieldConfig): void;
|
|
959
|
-
embedVectorFields(collection: string, data: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
960
|
-
joinPresence(room: string, meta?: Record<string, unknown>): Promise<() => void>;
|
|
961
|
-
leavePresence(room: string): Promise<void>;
|
|
962
|
-
onPresenceState(room: string, cb: PresenceCallback): () => void;
|
|
963
|
-
onPresenceJoin(room: string, cb: PresenceJoinCallback): () => void;
|
|
964
|
-
onPresenceLeave(room: string, cb: PresenceLeaveCallback): () => void;
|
|
965
|
-
private _startPresenceHeartbeat;
|
|
966
|
-
private _stopPresenceHeartbeat;
|
|
967
|
-
syncOffline(): Promise<void>;
|
|
968
|
-
protected beforeActivateSubscription(_entry: ActiveSubscription): Promise<void>;
|
|
969
|
-
protected activateSubscription(entry: ActiveSubscription): Promise<void>;
|
|
970
|
-
protected toSubscriptionError(err: unknown): SubscriptionError;
|
|
971
|
-
protected emitSubscriptionError(baseId: string, error: SubscriptionError): void;
|
|
972
|
-
protected replayActiveSubscriptions(): Promise<void>;
|
|
973
|
-
subscribe(subId: string, collection: string, docId: string | undefined, query: StructuredQuery | undefined, callback: SubscriptionCallback, options?: SubscribeOptions): SubscriptionHandle;
|
|
974
|
-
send(type: FlareAction, payload: any): Promise<any>;
|
|
975
|
-
private handleTransportError;
|
|
976
|
-
protected onConnected(): void;
|
|
977
|
-
protected onDisconnected(): void;
|
|
978
|
-
protected setState(state: ConnectionState): void;
|
|
979
|
-
protected handleIncoming(msg: any): void;
|
|
980
|
-
}
|
|
981
|
-
|
|
982
|
-
/**
|
|
983
|
-
* FlareAuth extends FlareBase with all authentication and CSRF logic.
|
|
984
|
-
*
|
|
985
|
-
* CSRF strategy
|
|
986
|
-
* ─────────────
|
|
987
|
-
* The server sets an HttpOnly cookie on /auth/config responses. The raw
|
|
988
|
-
* cookie value is NOT readable by JS (HttpOnly), but the server also echoes
|
|
989
|
-
* the token in the `x-flare-csrf` response header so the client can send
|
|
990
|
-
* it back as `x-flare-csrf` on every mutating request.
|
|
991
|
-
*
|
|
992
|
-
* Two environments are supported:
|
|
993
|
-
* 1. Browser – header is read from the /auth/config fetch; stored in
|
|
994
|
-
* `this.csrfToken` (in-memory only, never written to a
|
|
995
|
-
* readable cookie by the client).
|
|
996
|
-
* 2. Next.js SSR – use the standalone `createCsrfProxy()` handler
|
|
997
|
-
* (see Client/proxy.ts) which captures the Set-Cookie header
|
|
998
|
-
* from Flare server and sets it on the client domain too, so
|
|
999
|
-
* the browser owns two HttpOnly cookies: one from the Flare
|
|
1000
|
-
* domain and one from the Next.js domain.
|
|
1001
|
-
*/
|
|
1002
|
-
declare class FlareAuth<TPresetMap extends QueryPresetMap = {}> extends FlareBase<TPresetMap> {
|
|
1003
|
-
static AUTH_TRACE_STORAGE_KEY: string;
|
|
1004
|
-
protected authToken?: string;
|
|
1005
|
-
protected userId?: string;
|
|
1006
|
-
protected authGuard?: AuthGuard;
|
|
1007
|
-
protected authConfig?: FlareAuthConfig;
|
|
1008
|
-
/** In-memory CSRF token extracted from the `x-flare-csrf` response header */
|
|
1009
|
-
protected csrfToken?: string;
|
|
1010
|
-
protected csrfInitPromise?: Promise<void>;
|
|
1011
|
-
protected csrfBootstrapAttempted: boolean;
|
|
1012
|
-
protected socketAuthSyncPromise?: Promise<void>;
|
|
1013
|
-
protected pushServiceWorkerInitPromise?: Promise<ServiceWorkerRegistration | null>;
|
|
1014
|
-
protected authSession: FlareAuthSession | null;
|
|
1015
|
-
protected authBootstrapPromise?: Promise<void>;
|
|
1016
|
-
protected authBootstrapAttempted: boolean;
|
|
1017
|
-
protected authStateListeners: AuthStateListener[];
|
|
1018
|
-
protected authConfigListeners: AuthConfigListener[];
|
|
1019
|
-
protected currentProfile: FlareAuthUser | undefined;
|
|
1020
|
-
protected isAuthTraceEnabled(): boolean;
|
|
1021
|
-
setAuthTrace(enabled: boolean, persist?: boolean): void;
|
|
1022
|
-
protected traceAuth(event: string, details?: Record<string, unknown>): void;
|
|
1023
|
-
private getAuthRequestContentType;
|
|
1024
|
-
private buildAuthRequestBody;
|
|
1025
|
-
private getDefaultCsrfCookieName;
|
|
1026
|
-
getCsrfCookieName(): string;
|
|
1027
|
-
/**
|
|
1028
|
-
* Read the CSRF token from a browser-readable cookie (set by the server as
|
|
1029
|
-
* a non-HttpOnly fallback) or fall back to the in-memory value captured
|
|
1030
|
-
* from the response header.
|
|
1031
|
-
*
|
|
1032
|
-
* Priority:
|
|
1033
|
-
* 1. Non-HttpOnly cookie on the current domain (browser only)
|
|
1034
|
-
* 2. In-memory value from `x-flare-csrf` response header
|
|
1035
|
-
*/
|
|
1036
|
-
getCsrfToken(): string | null;
|
|
1037
|
-
private getCookieValue;
|
|
1038
|
-
/**
|
|
1039
|
-
* Extract CSRF token from a server response.
|
|
1040
|
-
* The server now sends it ONLY as the `x-flare-csrf` response header
|
|
1041
|
-
* (not in the JSON body). We still support the body field as a fallback
|
|
1042
|
-
* for older server versions.
|
|
1043
|
-
*/
|
|
1044
|
-
protected extractCsrfToken(json: unknown, response?: {
|
|
1045
|
-
headers: {
|
|
1046
|
-
get: (name: string) => string | null;
|
|
1047
|
-
};
|
|
1048
|
-
}): string | undefined;
|
|
1049
|
-
getCsrfHeaders(): Record<string, string>;
|
|
1050
|
-
/**
|
|
1051
|
-
* Inject CSRF token directly (used by SSR middleware).
|
|
1052
|
-
* This allows the server to bootstrap CSRF once and inject it into the client,
|
|
1053
|
-
* preventing redundant /auth/config calls.
|
|
1054
|
-
*
|
|
1055
|
-
* @example
|
|
1056
|
-
* // In Next.js middleware
|
|
1057
|
-
* const csrf = extractCsrfFromRequest(request, appId);
|
|
1058
|
-
* if (csrf) {
|
|
1059
|
-
* flareClient.setCsrfToken(csrf);
|
|
1060
|
-
* }
|
|
1061
|
-
*/
|
|
1062
|
-
setCsrfToken(token: string): void;
|
|
1063
|
-
ensureCsrfProtection(): Promise<void>;
|
|
1064
|
-
loadAuthConfig(): Promise<FlareAuthConfig>;
|
|
1065
|
-
protected fetchAuthConfig(): Promise<FlareAuthConfig>;
|
|
1066
|
-
onAuthConfigLoaded(listener: AuthConfigListener): () => void;
|
|
1067
|
-
protected setProfile(profile: FlareAuthUser): void;
|
|
1068
|
-
protected setAuthSession(session: FlareAuthSession | null, source?: string): void;
|
|
1069
|
-
onAuthStateChanged(listener: AuthStateListener): () => void;
|
|
1070
|
-
onAuthStateChange(listener: AuthStateListener): () => void;
|
|
1071
|
-
get currentUser(): FlareAuthUser | undefined;
|
|
1072
|
-
getCurrentUser(): FlareAuthUser | undefined;
|
|
1073
|
-
protected syncSocketAuth(accessToken?: string | null): Promise<void>;
|
|
1074
|
-
protected updateSocketIdentity(uid?: string, forceReplay?: boolean): Promise<void>;
|
|
1075
|
-
protected beforeActivateSubscription(_entry: any): Promise<void>;
|
|
1076
|
-
protected onConnected(): void;
|
|
1077
|
-
protected handleIncoming(msg: any): void;
|
|
1078
|
-
auth(token: string): Promise<AuthResult>;
|
|
1079
|
-
signInWithEmailAndPassword(email: string, password: string, options?: {
|
|
1080
|
-
scope?: string[];
|
|
1081
|
-
createIfMissing?: boolean;
|
|
1082
|
-
}): Promise<AuthResult & {
|
|
1083
|
-
kind?: string;
|
|
1084
|
-
accessToken: string;
|
|
1085
|
-
refreshToken: string | null;
|
|
1086
|
-
authToken: AuthToken;
|
|
1087
|
-
created?: boolean;
|
|
1088
|
-
}>;
|
|
1089
|
-
signInWithEmail(email: string, password: string, options?: {
|
|
1090
|
-
scope?: string[];
|
|
1091
|
-
createIfMissing?: boolean;
|
|
1092
|
-
}): Promise<AuthResult & {
|
|
1093
|
-
kind?: string;
|
|
1094
|
-
accessToken: string;
|
|
1095
|
-
refreshToken: string | null;
|
|
1096
|
-
authToken: AuthToken;
|
|
1097
|
-
created?: boolean;
|
|
1098
|
-
}>;
|
|
1099
|
-
createUserWithEmail(email: string, password: string, options?: {
|
|
1100
|
-
scope?: string[];
|
|
1101
|
-
additionalParams?: Record<string, string>;
|
|
1102
|
-
signInIfAllowed?: boolean;
|
|
1103
|
-
}): Promise<{
|
|
1104
|
-
kind?: string;
|
|
1105
|
-
verificationRequired: true;
|
|
1106
|
-
verification_required: true;
|
|
1107
|
-
emailSent: boolean;
|
|
1108
|
-
email_sent: boolean;
|
|
1109
|
-
message?: string;
|
|
1110
|
-
preview?: {
|
|
1111
|
-
code: string;
|
|
1112
|
-
link: string;
|
|
1113
|
-
};
|
|
1114
|
-
} | (AuthResult & {
|
|
1115
|
-
kind?: string;
|
|
1116
|
-
accessToken: string;
|
|
1117
|
-
access_token: string;
|
|
1118
|
-
token_type: string;
|
|
1119
|
-
expires_in: number;
|
|
1120
|
-
refreshToken: string | null;
|
|
1121
|
-
refresh_token: string | null;
|
|
1122
|
-
scope: string;
|
|
1123
|
-
expires_at: string | number;
|
|
1124
|
-
sid: string;
|
|
1125
|
-
authToken: AuthToken;
|
|
1126
|
-
auth_token: AuthToken;
|
|
1127
|
-
verificationRequired: false;
|
|
1128
|
-
verification_required: false;
|
|
1129
|
-
emailSent: boolean;
|
|
1130
|
-
email_sent: boolean;
|
|
1131
|
-
preview?: {
|
|
1132
|
-
code: string;
|
|
1133
|
-
link: string;
|
|
1134
|
-
};
|
|
1135
|
-
})>;
|
|
1136
|
-
createUserWithEmailAndPassword(email: string, password: string, options?: {
|
|
1137
|
-
scope?: string[];
|
|
1138
|
-
additionalParams?: Record<string, string>;
|
|
1139
|
-
signInIfAllowed?: boolean;
|
|
1140
|
-
}): Promise<{
|
|
1141
|
-
kind?: string;
|
|
1142
|
-
verificationRequired: true;
|
|
1143
|
-
verification_required: true;
|
|
1144
|
-
emailSent: boolean;
|
|
1145
|
-
email_sent: boolean;
|
|
1146
|
-
message?: string;
|
|
1147
|
-
preview?: {
|
|
1148
|
-
code: string;
|
|
1149
|
-
link: string;
|
|
1150
|
-
};
|
|
1151
|
-
} | (AuthResult & {
|
|
1152
|
-
kind?: string;
|
|
1153
|
-
accessToken: string;
|
|
1154
|
-
access_token: string;
|
|
1155
|
-
token_type: string;
|
|
1156
|
-
expires_in: number;
|
|
1157
|
-
refreshToken: string | null;
|
|
1158
|
-
refresh_token: string | null;
|
|
1159
|
-
scope: string;
|
|
1160
|
-
expires_at: string | number;
|
|
1161
|
-
sid: string;
|
|
1162
|
-
authToken: AuthToken;
|
|
1163
|
-
auth_token: AuthToken;
|
|
1164
|
-
verificationRequired: false;
|
|
1165
|
-
verification_required: false;
|
|
1166
|
-
emailSent: boolean;
|
|
1167
|
-
email_sent: boolean;
|
|
1168
|
-
preview?: {
|
|
1169
|
-
code: string;
|
|
1170
|
-
link: string;
|
|
1171
|
-
};
|
|
1172
|
-
})>;
|
|
1173
|
-
signInOrCreateWithEmail(email: string, password: string, options?: {
|
|
1174
|
-
scope?: string[];
|
|
1175
|
-
additionalParams?: Record<string, string>;
|
|
1176
|
-
}): Promise<{
|
|
1177
|
-
kind?: string;
|
|
1178
|
-
verificationRequired: true;
|
|
1179
|
-
created: true;
|
|
1180
|
-
emailSent: boolean;
|
|
1181
|
-
preview?: {
|
|
1182
|
-
code: string;
|
|
1183
|
-
link: string;
|
|
1184
|
-
};
|
|
1185
|
-
} | (AuthResult & {
|
|
1186
|
-
accessToken: string;
|
|
1187
|
-
refreshToken: string | null;
|
|
1188
|
-
authToken: AuthToken;
|
|
1189
|
-
created: boolean;
|
|
1190
|
-
})>;
|
|
1191
|
-
signInOrCreateWithEmailAndPassword(email: string, password: string, options?: {
|
|
1192
|
-
scope?: string[];
|
|
1193
|
-
additionalParams?: Record<string, string>;
|
|
1194
|
-
}): Promise<{
|
|
1195
|
-
kind?: string;
|
|
1196
|
-
verificationRequired: true;
|
|
1197
|
-
created: true;
|
|
1198
|
-
emailSent: boolean;
|
|
1199
|
-
preview?: {
|
|
1200
|
-
code: string;
|
|
1201
|
-
link: string;
|
|
1202
|
-
};
|
|
1203
|
-
} | (AuthResult & {
|
|
1204
|
-
accessToken: string;
|
|
1205
|
-
refreshToken: string | null;
|
|
1206
|
-
authToken: AuthToken;
|
|
1207
|
-
created: boolean;
|
|
1208
|
-
})>;
|
|
1209
|
-
sendEmailVerification(email: string): Promise<{
|
|
1210
|
-
sent: boolean;
|
|
1211
|
-
emailSent: boolean;
|
|
1212
|
-
preview?: {
|
|
1213
|
-
code: string;
|
|
1214
|
-
link: string;
|
|
1215
|
-
};
|
|
1216
|
-
}>;
|
|
1217
|
-
verifyEmailWithCode(email: string, code: string): Promise<{
|
|
1218
|
-
verified: boolean;
|
|
1219
|
-
email: string;
|
|
1220
|
-
}>;
|
|
1221
|
-
confirmEmailLink(token: string, email: string): Promise<{
|
|
1222
|
-
verified: boolean;
|
|
1223
|
-
email: string;
|
|
1224
|
-
}>;
|
|
1225
|
-
sendAccountRecovery(email: string): Promise<{
|
|
1226
|
-
kind?: string;
|
|
1227
|
-
sent: boolean;
|
|
1228
|
-
emailSent?: boolean;
|
|
1229
|
-
preview?: {
|
|
1230
|
-
code: string;
|
|
1231
|
-
token: string;
|
|
1232
|
-
};
|
|
1233
|
-
}>;
|
|
1234
|
-
recoverAccountWithCode(email: string, code: string, newPassword: string): Promise<{
|
|
1235
|
-
recovered: boolean;
|
|
1236
|
-
email: string;
|
|
1237
|
-
sessionsRevoked?: number;
|
|
1238
|
-
}>;
|
|
1239
|
-
recoverAccountWithToken(token: string, newPassword: string): Promise<{
|
|
1240
|
-
recovered: boolean;
|
|
1241
|
-
email: string;
|
|
1242
|
-
sessionsRevoked?: number;
|
|
1243
|
-
}>;
|
|
1244
|
-
private toUint8ArrayFromBase64Url;
|
|
1245
|
-
private encodePushTokenFromSubscription;
|
|
1246
|
-
private fetchPushSetupConfig;
|
|
1247
|
-
setupPushServiceWorker(): Promise<ServiceWorkerRegistration | null>;
|
|
1248
|
-
requestPushPermission(): Promise<NotificationPermission>;
|
|
1249
|
-
acquireBrowserPushToken(options?: BrowserPushTokenOptions): Promise<{
|
|
1250
|
-
token: string;
|
|
1251
|
-
subscription: PushSubscription;
|
|
1252
|
-
}>;
|
|
1253
|
-
enableBrowserPush(options?: BrowserPushRegistrationOptions): Promise<{
|
|
1254
|
-
registered: boolean;
|
|
1255
|
-
appId: string;
|
|
1256
|
-
uid: string;
|
|
1257
|
-
token: string;
|
|
1258
|
-
platform?: string;
|
|
1259
|
-
subscription: PushSubscription;
|
|
1260
|
-
}>;
|
|
1261
|
-
registerPushToken(input: RegisterPushTokenInput): Promise<{
|
|
1262
|
-
registered: boolean;
|
|
1263
|
-
appId: string;
|
|
1264
|
-
uid: string;
|
|
1265
|
-
token: string;
|
|
1266
|
-
platform?: string;
|
|
1267
|
-
}>;
|
|
1268
|
-
unregisterPushToken(token: string, authAppId?: string): Promise<{
|
|
1269
|
-
unregistered: boolean;
|
|
1270
|
-
appId: string;
|
|
1271
|
-
token: string;
|
|
1272
|
-
removed: boolean;
|
|
1273
|
-
}>;
|
|
1274
|
-
sendPushNotification(input: SendPushNotificationInput): Promise<PushSendResult>;
|
|
1275
|
-
sendEmail(input: SendEmailInput): Promise<EmailSendResult>;
|
|
1276
|
-
verifyEmailLink(input: VerifyEmailLinkInput): Promise<EmailLinkVerifyResult>;
|
|
1277
|
-
signIn(providerId: ProviderId, options?: {
|
|
1278
|
-
returnTo?: string;
|
|
1279
|
-
metaTag?: string;
|
|
1280
|
-
}): Promise<any>;
|
|
1281
|
-
signIn(authGuard: Pick<AuthGuard, 'signIn'>, providerId: ProviderId, options?: {
|
|
1282
|
-
returnTo?: string;
|
|
1283
|
-
metaTag?: string;
|
|
1284
|
-
}): Promise<any>;
|
|
1285
|
-
signInWithGoogle(options?: {
|
|
1286
|
-
returnTo?: string;
|
|
1287
|
-
metaTag?: string;
|
|
1288
|
-
}): Promise<any>;
|
|
1289
|
-
signInWithGitHub(options?: {
|
|
1290
|
-
returnTo?: string;
|
|
1291
|
-
metaTag?: string;
|
|
1292
|
-
}): Promise<any>;
|
|
1293
|
-
signInWithFacebook(options?: {
|
|
1294
|
-
returnTo?: string;
|
|
1295
|
-
metaTag?: string;
|
|
1296
|
-
}): Promise<any>;
|
|
1297
|
-
signInWithDropbox(options?: {
|
|
1298
|
-
returnTo?: string;
|
|
1299
|
-
metaTag?: string;
|
|
1300
|
-
}): Promise<any>;
|
|
1301
|
-
handleSignInRedirect(autoRedirect?: boolean): Promise<(AuthResult & {
|
|
1302
|
-
authToken: AuthToken;
|
|
1303
|
-
provider?: ProviderId;
|
|
1304
|
-
}) | null>;
|
|
1305
|
-
handleSignInRedirect(authGuard: Pick<AuthGuard, 'handleRedirect'>, autoRedirect?: boolean): Promise<(AuthResult & {
|
|
1306
|
-
authToken: AuthToken;
|
|
1307
|
-
provider?: ProviderId;
|
|
1308
|
-
}) | null>;
|
|
1309
|
-
private exchangeProviderToken;
|
|
1310
|
-
protected getAuthGuard(): Promise<AuthGuard>;
|
|
1311
|
-
refreshAuthSession(refresh_token?: string): Promise<FlareAuthSession | null>;
|
|
1312
|
-
issueSsrToken(ttlSeconds?: number): Promise<{
|
|
1313
|
-
token: string;
|
|
1314
|
-
token_type: string;
|
|
1315
|
-
expires_in: number;
|
|
1316
|
-
uid: string;
|
|
1317
|
-
role: string;
|
|
1318
|
-
email?: string;
|
|
1319
|
-
}>;
|
|
1320
|
-
signOut(): Promise<void>;
|
|
1321
|
-
protected registerWithEmail(email: string, password: string, options?: {
|
|
1322
|
-
scope?: string[];
|
|
1323
|
-
additionalParams?: Record<string, string>;
|
|
1324
|
-
signInIfAllowed?: boolean;
|
|
1325
|
-
}): Promise<Record<string, any>>;
|
|
1326
|
-
protected requestEmailPasswordToken(email: string, password: string, scope?: string[]): Promise<AuthToken & {
|
|
1327
|
-
kind: string;
|
|
1328
|
-
}>;
|
|
1329
|
-
protected fetchAuthMe(token?: string): Promise<{
|
|
1330
|
-
id?: string;
|
|
1331
|
-
email?: string | null;
|
|
1332
|
-
email_verified?: boolean;
|
|
1333
|
-
}>;
|
|
1334
|
-
}
|
|
1335
|
-
|
|
1336
|
-
/**
|
|
1337
|
-
* Client/index.ts ─ entry point
|
|
1338
|
-
*
|
|
1339
|
-
* FlareClient is the public-facing class. All logic lives in:
|
|
1340
|
-
* - Client/base.ts → transport, subscriptions, presence, vector, offline
|
|
1341
|
-
* - Client/auth.ts → CSRF capture, all auth & session methods
|
|
1342
|
-
*
|
|
1343
|
-
* CSRF Protection (SSR-Only by Default)
|
|
1344
|
-
* ────────────────────────────────────
|
|
1345
|
-
* FlareClient does NOT automatically fetch CSRF on construction. Instead:
|
|
1346
|
-
*
|
|
1347
|
-
* 1. SSR (Next.js): Middleware fetches /auth/config once, sets CSRF as HttpOnly
|
|
1348
|
-
* cookie on response. Methods automatically use this cookie (no extra calls).
|
|
1349
|
-
*
|
|
1350
|
-
* 2. Browser-only (SPA): Explicitly call client.ensureCsrfProtection() before
|
|
1351
|
-
* mutations to fetch /auth/config and cache CSRF token in memory.
|
|
1352
|
-
*
|
|
1353
|
-
* Why? Eliminates redundant /auth/config calls in SSR, where every method used
|
|
1354
|
-
* to fetch it again internally. Now CSRF bootstrapping happens once (in middleware),
|
|
1355
|
-
* and auth methods just use getCsrfHeaders() which returns the cached token
|
|
1356
|
-
* (if available) or empty object (relying on HttpOnly cookie validation).
|
|
1357
|
-
*
|
|
1358
|
-
* This file wires FlareAuth together and leaves CSRF bootstrapping to the user.
|
|
1359
|
-
*/
|
|
1360
|
-
|
|
1361
|
-
declare class FlareClient<TPresetMap extends QueryPresetMap = {}> extends FlareAuth<TPresetMap> {
|
|
1362
|
-
private autoPushRegisteredIdentity?;
|
|
1363
|
-
constructor(config: FlareConfig);
|
|
1364
|
-
private enableAutoPushNotificationsAfterAuth;
|
|
1365
|
-
autoEnablePushNotifications(): Promise<void>;
|
|
1366
|
-
}
|
|
1367
|
-
|
|
1368
5
|
/**
|
|
1369
6
|
* Client/proxy.ts ─ Next.js SSR CSRF proxy helper
|
|
1370
7
|
*
|
|
@@ -1553,4 +190,4 @@ declare const getFlare: () => FlareClient | null;
|
|
|
1553
190
|
*/
|
|
1554
191
|
declare const disconnectFlare: () => void;
|
|
1555
192
|
|
|
1556
|
-
export { type
|
|
193
|
+
export { type AuthConfigResponse, type CsrfProxyConfig, FlareClient, FlareConfig, FlareError, FlareErrors, FlareResponseCodes, buildFlareHeaders, connectApp, createCsrfProxy, createCsrfProxyHandler, disconnectFlare, extractCsrfFromRequest, getFlare };
|