@tern-secure/types 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,717 @@
1
+ /**
2
+ * TernSecure User
3
+ */
4
+ interface IdTokenResult {
5
+ authTime: string;
6
+ expirationTime: string;
7
+ issuedAtTime: string;
8
+ signInProvider: string | null;
9
+ signInSecondFactor: string | null;
10
+ token: string;
11
+ claims: Record<string, any>;
12
+ }
13
+ interface UserInfo {
14
+ displayName: string | null;
15
+ email: string | null;
16
+ phoneNumber: string | null;
17
+ photoURL: string | null;
18
+ providerId: string;
19
+ uid: string;
20
+ }
21
+ interface TernSecureUser extends UserInfo {
22
+ emailVerified: boolean;
23
+ isAnonymous: boolean;
24
+ metadata: {
25
+ creationTime?: string;
26
+ lastSignInTime?: string;
27
+ };
28
+ providerData: UserInfo[];
29
+ refreshToken: string;
30
+ tenantId: string | null;
31
+ delete(): Promise<void>;
32
+ getIdToken(forceRefresh?: boolean): Promise<string>;
33
+ getIdTokenResult(forceRefresh?: boolean): Promise<IdTokenResult>;
34
+ reload(): Promise<void>;
35
+ toJSON(): object;
36
+ }
37
+ type TernSecureUserData = {
38
+ uid: string;
39
+ email: string | null;
40
+ emailVerified?: boolean;
41
+ displayName?: string | null;
42
+ };
43
+ /**
44
+ * TernSecure Firebase configuration interface
45
+ * Extends Firebase's base configuration options
46
+ */
47
+ interface TernSecureConfig {
48
+ apiKey: string;
49
+ authDomain: string;
50
+ projectId: string;
51
+ storageBucket: string;
52
+ messagingSenderId: string;
53
+ appId: string;
54
+ measurementId?: string;
55
+ appName?: string;
56
+ }
57
+ /**
58
+ * Configuration validation result
59
+ */
60
+ interface ConfigValidationResult {
61
+ isValid: boolean;
62
+ errors: string[];
63
+ config: TernSecureConfig;
64
+ }
65
+ /**
66
+ * TernSecure initialization options
67
+ */
68
+ interface TernSecureOptions {
69
+ /** Environment setting for different configurations */
70
+ environment?: 'development' | 'production';
71
+ /** Geographic region for data storage */
72
+ region?: string;
73
+ /** Custom error handler */
74
+ onError?: (error: Error) => void;
75
+ /** Debug mode flag */
76
+ debug?: boolean;
77
+ }
78
+ /**
79
+ * Firebase initialization state
80
+ */
81
+ interface FirebaseState {
82
+ /** Whether Firebase has been initialized */
83
+ initialized: boolean;
84
+ /** Any initialization errors */
85
+ error: Error | null;
86
+ /** Timestamp of last initialization attempt */
87
+ lastInitAttempt?: number;
88
+ }
89
+ /**
90
+ * Firebase Admin configuration interface
91
+ */
92
+ interface TernSecureAdminConfig {
93
+ projectId: string;
94
+ clientEmail: string;
95
+ privateKey: string;
96
+ }
97
+ /**
98
+ * Firebase Admin configuration validation result
99
+ */
100
+ interface AdminConfigValidationResult {
101
+ isValid: boolean;
102
+ errors: string[];
103
+ config: TernSecureAdminConfig;
104
+ }
105
+
106
+ type ErrorCode = keyof typeof ERRORS;
107
+ interface AuthErrorResponse {
108
+ success: false;
109
+ message: string;
110
+ code: ErrorCode;
111
+ }
112
+ interface AuthErrorTree extends Error {
113
+ code?: any | string;
114
+ message: string;
115
+ response?: any | string;
116
+ }
117
+ interface SignInResponseTree {
118
+ success: boolean;
119
+ message?: string;
120
+ error?: any | undefined;
121
+ user?: any;
122
+ }
123
+ declare const ERRORS: {
124
+ readonly SERVER_SIDE_INITIALIZATION: "TernSecure must be initialized on the client side";
125
+ readonly REQUIRES_VERIFICATION: "AUTH_REQUIRES_VERIFICATION";
126
+ readonly AUTHENTICATED: "AUTHENTICATED";
127
+ readonly UNAUTHENTICATED: "UNAUTHENTICATED";
128
+ readonly UNVERIFIED: "UNVERIFIED";
129
+ readonly NOT_INITIALIZED: "TernSecure services are not initialized. Call initializeTernSecure() first";
130
+ readonly HOOK_CONTEXT: "Hook must be used within TernSecureProvider";
131
+ readonly EMAIL_NOT_VERIFIED: "EMAIL_NOT_VERIFIED";
132
+ readonly INVALID_CREDENTIALS: "INVALID_CREDENTIALS";
133
+ readonly USER_DISABLED: "USER_DISABLED";
134
+ readonly TOO_MANY_ATTEMPTS: "TOO_MANY_ATTEMPTS";
135
+ readonly NETWORK_ERROR: "NETWORK_ERROR";
136
+ readonly INVALID_EMAIL: "INVALID_EMAIL";
137
+ readonly WEAK_PASSWORD: "WEAK_PASSWORD";
138
+ readonly EMAIL_EXISTS: "EMAIL_EXISTS";
139
+ readonly POPUP_BLOCKED: "POPUP_BLOCKED";
140
+ readonly OPERATION_NOT_ALLOWED: "OPERATION_NOT_ALLOWED";
141
+ readonly EXPIRED_TOKEN: "EXPIRED_TOKEN";
142
+ readonly INVALID_TOKEN: "INVALID_TOKEN";
143
+ readonly SESSION_EXPIRED: "SESSION_EXPIRED";
144
+ readonly INTERNAL_ERROR: "INTERNAL_ERROR";
145
+ readonly UNKNOWN_ERROR: "An unknown error occurred.";
146
+ readonly INVALID_ARGUMENT: "Invalid argument provided.";
147
+ readonly USER_NOT_FOUND: "auth/user-not-found";
148
+ readonly WRONG_PASSWORD: "auth/wrong-password";
149
+ readonly EMAIL_ALREADY_IN_USE: "auth/email-already-in-use";
150
+ readonly REQUIRES_RECENT_LOGIN: "auth/requires-recent-login";
151
+ readonly NO_SESSION_COOKIE: "No session cookie found.";
152
+ readonly INVALID_SESSION_COOKIE: "Invalid session cookie.";
153
+ readonly NO_ID_TOKEN: "No ID token found.";
154
+ readonly INVALID_ID_TOKEN: "Invalid ID token.";
155
+ readonly REDIRECT_LOOP: "Redirect loop detected.";
156
+ };
157
+ type AuthErrorCode = keyof typeof ERRORS;
158
+ declare class TernSecureError extends Error {
159
+ code: ErrorCode;
160
+ constructor(code: ErrorCode, message?: string);
161
+ }
162
+ /**
163
+ * Handles Firebase authentication errors with multiple fallback mechanisms
164
+ */
165
+ declare function handleFirebaseAuthError(error: unknown): AuthErrorResponse;
166
+ /**
167
+ * Type guard to check if a response is an AuthErrorResponse
168
+ */
169
+ declare function isAuthErrorResponse(response: unknown): response is AuthErrorResponse;
170
+ declare function getErrorAlertVariant(error: any | undefined): "destructive" | "default";
171
+
172
+ /**
173
+ * Defines the basic structure for color theming.
174
+ */
175
+ interface ThemeColors {
176
+ primary?: string;
177
+ secondary?: string;
178
+ accent?: string;
179
+ background?: string;
180
+ text?: string;
181
+ error?: string;
182
+ success?: string;
183
+ }
184
+ /**
185
+ * Defines the basic structure for font theming.
186
+ */
187
+ interface ThemeFonts {
188
+ primary?: string;
189
+ secondary?: string;
190
+ }
191
+ /**
192
+ * Defines the basic structure for spacing and layout theming.
193
+ */
194
+ interface ThemeSpacing {
195
+ small?: string | number;
196
+ medium?: string | number;
197
+ large?: string | number;
198
+ }
199
+ /**
200
+ * Defines the basic structure for border radius theming.
201
+ */
202
+ interface ThemeBorderRadius {
203
+ small?: string | number;
204
+ medium?: string | number;
205
+ large?: string | number;
206
+ }
207
+ /**
208
+ * Allows for overriding styles of specific UI components.
209
+ * Properties can be CSS-in-JS objects or class names, depending on implementation.
210
+ */
211
+ interface ThemeComponentStyles {
212
+ button?: Record<string, any> | string;
213
+ input?: Record<string, any> | string;
214
+ card?: Record<string, any> | string;
215
+ label?: Record<string, any> | string;
216
+ }
217
+ /**
218
+ * Defines the overall appearance/theme configuration.
219
+ * This allows for broad customization of the UI components.
220
+ */
221
+ interface Appearance {
222
+ colors?: ThemeColors;
223
+ fonts?: ThemeFonts;
224
+ spacing?: ThemeSpacing;
225
+ borderRadius?: ThemeBorderRadius;
226
+ componentStyles?: ThemeComponentStyles;
227
+ variables?: Record<string, string | number>;
228
+ }
229
+ /**
230
+ * Base UI configuration shared between SignIn and SignUp
231
+ */
232
+ interface BaseAuthUIConfig {
233
+ /** Visual appearance configuration */
234
+ appearance?: Appearance;
235
+ /** Application logo URL or SVG string */
236
+ logo?: string;
237
+ /** Application name for display */
238
+ appName?: string;
239
+ /** Render mode for cross-platform support */
240
+ renderMode?: 'modal' | 'page' | 'embedded';
241
+ /** Layout direction */
242
+ layout?: 'vertical' | 'horizontal';
243
+ /** Custom loading message */
244
+ loadingMessage?: string;
245
+ /** Loading spinner variant */
246
+ loadingSpinnerVariant?: 'circular' | 'linear' | 'dots';
247
+ /** Accessibility configuration */
248
+ a11y?: {
249
+ /** ARIA labels and descriptions */
250
+ labels?: Record<string, string>;
251
+ /** Element to receive initial focus */
252
+ initialFocus?: string;
253
+ /** Whether to trap focus within the auth UI */
254
+ trapFocus?: boolean;
255
+ };
256
+ }
257
+ /**
258
+ * Sign-in specific UI configuration
259
+ */
260
+ interface SignInUIConfig extends BaseAuthUIConfig {
261
+ /** Social sign-in buttons configuration */
262
+ socialButtons?: {
263
+ google?: boolean;
264
+ microsoft?: boolean;
265
+ github?: boolean;
266
+ facebook?: boolean;
267
+ twitter?: boolean;
268
+ apple?: boolean;
269
+ linkedin?: boolean;
270
+ layout?: 'vertical' | 'horizontal';
271
+ size?: 'small' | 'medium' | 'large';
272
+ };
273
+ /** "Remember me" checkbox configuration */
274
+ rememberMe?: {
275
+ enabled?: boolean;
276
+ defaultChecked?: boolean;
277
+ };
278
+ /** Sign-up link configuration */
279
+ signUpLink?: {
280
+ enabled?: boolean;
281
+ text?: string;
282
+ href?: string;
283
+ };
284
+ }
285
+ /**
286
+ * Sign-up specific UI configuration
287
+ */
288
+ interface SignUpUIConfig extends BaseAuthUIConfig {
289
+ /** Password requirements display configuration */
290
+ passwordRequirements?: {
291
+ show?: boolean;
292
+ rules?: Array<{
293
+ rule: string;
294
+ description: string;
295
+ }>;
296
+ };
297
+ /** Terms and conditions configuration */
298
+ terms?: {
299
+ enabled?: boolean;
300
+ text?: string;
301
+ link?: string;
302
+ };
303
+ }
304
+
305
+ interface TernSecureSession {
306
+ token: string | null;
307
+ expiresAt?: number;
308
+ }
309
+ type SignInFormValues = {
310
+ email: string;
311
+ password: string;
312
+ phoneNumber?: string;
313
+ };
314
+ type SignInInitialValue = Partial<SignInFormValues>;
315
+ type SignUpFormValues = {
316
+ email: string;
317
+ password: string;
318
+ confirmPassword?: string;
319
+ displayName?: string;
320
+ };
321
+ type SignUpInitialValue = Partial<SignUpFormValues>;
322
+ interface SignInResponse {
323
+ success: boolean;
324
+ message?: string;
325
+ error?: any | undefined;
326
+ user?: any;
327
+ }
328
+ interface AuthError extends Error {
329
+ code?: any | string;
330
+ message: string;
331
+ response?: SignInResponse;
332
+ }
333
+ declare function isSignInResponse(value: any): value is SignInResponse;
334
+ interface AuthActions {
335
+ signInWithEmail: (email: string, password: string) => Promise<SignInResponse>;
336
+ signInWithGoogle: () => Promise<void>;
337
+ signInWithMicrosoft: () => Promise<void>;
338
+ signOut: () => Promise<void>;
339
+ getRedirectResult: () => Promise<any>;
340
+ getIdToken: () => Promise<string | null>;
341
+ createUserWithEmailAndPassword?: (email: string, password: string) => Promise<SignInResponse>;
342
+ sendEmailVerification?: (user: TernSecureUser) => Promise<void>;
343
+ }
344
+ interface RedirectConfig {
345
+ redirectUrl?: string;
346
+ isReturn?: boolean;
347
+ priority?: number;
348
+ }
349
+ interface SignInProps extends RedirectConfig {
350
+ initialValue?: SignInInitialValue;
351
+ logo?: string;
352
+ appName?: string;
353
+ appearance?: Appearance;
354
+ onError?: (error: AuthError) => void;
355
+ onSuccess?: (user: TernSecureUser | null) => void;
356
+ }
357
+ /**
358
+ * SignUpProps interface defines the properties for the sign-up component.
359
+ * It extends RedirectConfig to include redirect-related properties.
360
+ */
361
+ interface SignUpProps extends RedirectConfig {
362
+ initialValue?: SignUpInitialValue;
363
+ logo?: string;
364
+ appName?: string;
365
+ appearance?: Appearance;
366
+ onError?: (error: AuthError) => void;
367
+ onSuccess?: (user: TernSecureUser | null) => void;
368
+ }
369
+ /**
370
+ * Defines the contract for a TernSecure instance.
371
+ * This instance provides authentication state, user information, and methods
372
+ * for managing the authentication lifecycle. It is designed to be used by
373
+ * UI packages like tern-ui, which act as "dumb" renderers.
374
+ */
375
+ interface TernSecureInstance {
376
+ /** Indicates if the user is currently signed in. */
377
+ isSignedIn: () => boolean;
378
+ /** The current authenticated user object, or null if not signed in. */
379
+ user: TernSecureUser | null;
380
+ /** The current user session information, or null if not signed in. */
381
+ session: TernSecureSession | null;
382
+ /** Initiates the sign-out process for the current user. */
383
+ signOut: () => Promise<void>;
384
+ /**
385
+ * Prepares or signals to mount the sign-in interface.
386
+ * @param options Optional configuration or initial state for the sign-in UI, conforming to SignInProps.
387
+ */
388
+ mountSignIn: (options?: SignInProps) => void;
389
+ /** Cleans up or signals to unmount the sign-in interface. */
390
+ unmountSignIn: () => void;
391
+ /**
392
+ * Prepares or signals to mount the sign-up interface.
393
+ * @param options Optional configuration or initial state for the sign-up UI, conforming to SignUpProps.
394
+ */
395
+ mountSignUp: (options?: SignUpProps) => void;
396
+ /** Cleans up or signals to unmount the sign-up interface. */
397
+ unmountSignUp: () => void;
398
+ /**
399
+ * Determines if a redirect is necessary based on the current authentication
400
+ * state and the given path.
401
+ * @param currentPath The current URL path.
402
+ * @returns True if a redirect is needed, false otherwise, or a string path to redirect to.
403
+ */
404
+ shouldRedirect: (currentPath: string) => boolean | string;
405
+ /**
406
+ * Constructs a URL, appending necessary redirect parameters.
407
+ * Useful for redirecting back to the original page after authentication.
408
+ * @param baseUrl The base URL to which redirect parameters should be added.
409
+ * @returns The new URL string with redirect parameters.
410
+ */
411
+ constructUrlWithRedirect: (baseUrl: string) => string;
412
+ /**
413
+ * Redirects the user to the configured login page.
414
+ * @param redirectUrl Optional URL to redirect to after successful login.
415
+ */
416
+ redirectToLogin: (redirectUrl?: string) => void;
417
+ /** Indicates if an authentication operation is currently in progress. */
418
+ isLoading: boolean;
419
+ /** Holds any error that occurred during an authentication operation, or null otherwise. */
420
+ error: Error | null;
421
+ /** Indicates if the user has verified their email address. */
422
+ sendVerificationEmail: () => Promise<void>;
423
+ }
424
+
425
+ type SessionStatus = 'active' | 'expired' | 'revoked' | 'pending';
426
+ /**
427
+ * parsed can be replaced with
428
+ */
429
+ declare interface ParsedToken {
430
+ /** Expiration time of the token. */
431
+ 'exp'?: string;
432
+ /** UID of the user. */
433
+ 'sub'?: string;
434
+ /** Time at which authentication was performed. */
435
+ 'auth_time'?: string;
436
+ /** Issuance time of the token. */
437
+ 'iat'?: string;
438
+ /** Firebase specific claims, containing the provider(s) used to authenticate the user. */
439
+ 'firebase'?: {
440
+ 'sign_in_provider'?: string;
441
+ 'sign_in_second_factor'?: string;
442
+ 'identities'?: Record<string, string>;
443
+ };
444
+ /** Map of any additional custom claims. */
445
+ [key: string]: unknown;
446
+ }
447
+ /**
448
+ * Core properties for any session that is or was authenticated.
449
+ * These properties are guaranteed to exist for active, expired, or revoked sessions.
450
+ */
451
+ interface AuthenticatedSessionBase {
452
+ /** The Firebase Auth ID token JWT string. */
453
+ token: string;
454
+ /** The ID token expiration time (e.g., UTC string or Unix timestamp). */
455
+ expirationTime: string;
456
+ /** The ID token issuance time. */
457
+ issuedAtTime: string;
458
+ /** Time at which authentication was performed (from token claims). */
459
+ authTime: string;
460
+ /**
461
+ * The entire payload claims of the ID token including the standard reserved claims
462
+ * as well as custom claims.
463
+ */
464
+ claims: ParsedToken;
465
+ /**
466
+ * Time the user last signed in.
467
+ * This could be from Firebase User metadata or persisted by TernSecure.
468
+ */
469
+ lastSignedAt?: number;
470
+ /** signInProvider */
471
+ signInProvider: string;
472
+ }
473
+ /**
474
+ * Represents a session when the user is authenticated and the token is considered active.
475
+ */
476
+ interface ActiveSession extends AuthenticatedSessionBase {
477
+ status: 'active';
478
+ }
479
+ /**
480
+ * Represents a session when the user was authenticated, but the token has expired.
481
+ */
482
+ interface ExpiredSession extends AuthenticatedSessionBase {
483
+ status: 'expired';
484
+ }
485
+ /**
486
+ * Represents a session that is awaiting some action.
487
+ */
488
+ interface PendingSession extends AuthenticatedSessionBase {
489
+ status: 'pending';
490
+ }
491
+ /**
492
+ * Defines the possible states of a user's session within TernSecure.
493
+ * This is a discriminated union based on the `status` property.
494
+ * The actual `TernSecureUser` (Firebase User object) is typically stored separately,
495
+ * for example, in `TernSecureInstanceTree.auth.user`.
496
+ */
497
+ type TernSecureSessionTree = ActiveSession | ExpiredSession;
498
+ type SignedInSession = ActiveSession | PendingSession | ExpiredSession;
499
+
500
+ type SignInStatus = 'idle' | 'pending_email_password' | 'pending_social' | 'pending_mfa' | 'redirecting' | 'success' | 'error';
501
+ type SignInFormValuesTree = {
502
+ email: string;
503
+ password: string;
504
+ phoneNumber?: string;
505
+ };
506
+ type SignInInitialValueTree = Partial<SignInFormValuesTree>;
507
+ interface ResendEmailVerification extends SignInResponseTree {
508
+ isVerified?: boolean;
509
+ }
510
+ declare function isSignInResponseTree(value: any): value is SignInResponseTree;
511
+ interface SignInResource {
512
+ /**
513
+ * The current status of the sign-in process.
514
+ */
515
+ status?: SignInStatus;
516
+ /**
517
+ * Signs in a user with their email and password.
518
+ * @param params - The sign-in form values.
519
+ * @returns A promise that resolves with the sign-in response.
520
+ */
521
+ withEmailAndPassword: (params: SignInFormValuesTree) => Promise<SignInResponseTree>;
522
+ /**
523
+ * @param provider - The identifier of the social provider (e.g., 'google', 'microsoft', 'github').
524
+ * @param options - Optional configuration for the social sign-in flow.
525
+ * @returns A promise that resolves with the sign-in response or void if redirecting.
526
+ */
527
+ withSocialProvider: (provider: string, options?: {
528
+ mode?: 'popup' | 'redirect';
529
+ }) => Promise<SignInResponseTree | void>;
530
+ /**
531
+ * Completes an MFA (Multi-Factor Authentication) step after a primary authentication attempt.
532
+ * @param mfaToken - The MFA token or code submitted by the user.
533
+ * @param mfaContext - Optional context or session data from the MFA initiation step.
534
+ * @returns A promise that resolves with the sign-in response upon successful MFA verification.
535
+ */
536
+ completeMfaSignIn: (mfaToken: string, mfaContext?: any) => Promise<SignInResponseTree>;
537
+ /**
538
+ * Sends a password reset email to the given email address.
539
+ * @param email - The user's email address.
540
+ * @returns A promise that resolves when the email is sent.
541
+ */
542
+ sendPasswordResetEmail: (email: string) => Promise<void>;
543
+ /**
544
+ * Resends the email verification link to the user's email address.
545
+ * @returns A promise that resolves with the sign-in response.
546
+ */
547
+ resendEmailVerification: () => Promise<ResendEmailVerification>;
548
+ }
549
+
550
+ interface SignUpResource {
551
+ status?: SignUpStatus | null;
552
+ username?: string | null;
553
+ firstName?: string | null;
554
+ lastName?: string | null;
555
+ displayName?: string | null;
556
+ email: string | null;
557
+ phoneNumber?: string | null;
558
+ /**
559
+ * @param provider - The identifier of the social provider (e.g., 'google', 'microsoft', 'github').
560
+ * @param options - Optional configuration for the social sign-in flow.
561
+ * @returns A promise that resolves with the sign-in response or void if redirecting.
562
+ */
563
+ withSocialProvider: (provider: string, options?: {
564
+ mode?: 'popup' | 'redirect';
565
+ }) => Promise<SignInResponseTree | void>;
566
+ }
567
+ type SignUpStatus = 'missing_requirements' | 'complete' | 'abandoned';
568
+
569
+ interface TernSecureState {
570
+ userId: string | null;
571
+ isLoaded: boolean;
572
+ error: Error | null;
573
+ isValid: boolean;
574
+ isVerified: boolean;
575
+ isAuthenticated: boolean;
576
+ token: any | null;
577
+ email: string | null;
578
+ status: "loading" | "authenticated" | "unauthenticated" | "unverified";
579
+ requiresVerification?: boolean;
580
+ user?: TernSecureUser | null;
581
+ }
582
+ type AuthProviderStatus = 'idle' | 'pending' | 'error' | 'success';
583
+ declare const DEFAULT_TERN_SECURE_STATE: TernSecureState;
584
+ interface TernSecureAuthProvider {
585
+ /** Current auth state */
586
+ internalAuthState: TernSecureState;
587
+ /** Current user*/
588
+ ternSecureUser(): TernSecureUser | null;
589
+ /** Current session */
590
+ currentSession: SignedInSession | null;
591
+ /** Sign in resource for authentication operations */
592
+ signIn: SignInResource;
593
+ /** SignUp resource for authentication operations */
594
+ signUp: SignUpResource;
595
+ /** The Firebase configuration used by this TernAuth instance. */
596
+ ternSecureConfig?: TernSecureConfig;
597
+ /** Sign out the current user */
598
+ signOut(): Promise<void>;
599
+ }
600
+
601
+ type SignInRedirectUrl = {
602
+ signInForceRedirectUrl?: string | null;
603
+ };
604
+ type SignUpRedirectUrl = {
605
+ signUpForceRedirectUrl?: string | null;
606
+ };
607
+ type RedirectOptions = SignInRedirectUrl | SignUpRedirectUrl;
608
+
609
+ type Mode = 'browser' | 'server';
610
+ type TernSecureInstanceTreeOptions = {
611
+ initialSession?: TernSecureSessionTree | null;
612
+ defaultAppearance?: Appearance;
613
+ signInUrl?: string;
614
+ signUpUrl?: string;
615
+ mode?: Mode;
616
+ onAuthStateChanged?: (user: TernSecureUser | null) => void;
617
+ onError?: (error: AuthErrorTree) => void;
618
+ environment?: string | undefined;
619
+ requireverification?: boolean;
620
+ ternSecureConfig?: TernSecureConfig;
621
+ } & SignInRedirectUrl & SignUpRedirectUrl;
622
+ type TernSecureInstanceTreeStatus = 'error' | 'loading' | 'ready';
623
+ /**
624
+ * Instance interface for managing auth UI state
625
+ */
626
+ interface TernSecureInstanceTree {
627
+ customDomain?: string;
628
+ proxyUrl?: string;
629
+ apiKey?: string;
630
+ projectId?: string;
631
+ environment?: string | undefined;
632
+ mode?: Mode;
633
+ isReady: boolean;
634
+ status: TernSecureInstanceTreeStatus;
635
+ isVisible: boolean;
636
+ currentView: 'signIn' | 'signUp' | 'verify' | null;
637
+ isLoading: boolean;
638
+ error: Error | null;
639
+ /** Authentication State */
640
+ auth: {
641
+ /** Current authenticated user */
642
+ user: TernSecureUser | null;
643
+ /** Current session information */
644
+ session: SignedInSession | null;
645
+ };
646
+ /** Core Authentication Methods */
647
+ ternAuth: TernSecureAuthProvider | undefined;
648
+ showSignIn: (targetNode: HTMLDivElement, config?: SignInPropsTree) => void;
649
+ hideSignIn: (targetNode: HTMLDivElement) => void;
650
+ showSignUp: (targetNode: HTMLDivElement, config?: SignUpPropsTree) => void;
651
+ hideSignUp: (targetNode: HTMLDivElement) => void;
652
+ showUserButton: (targetNode: HTMLDivElement) => void;
653
+ hideUserButton: (targetNode: HTMLDivElement) => void;
654
+ clearError: () => void;
655
+ setLoading: (isLoading: boolean) => void;
656
+ /** Get redirect result from OAuth flows */
657
+ getRedirectResult: () => Promise<any>;
658
+ /** Check if redirect is needed */
659
+ shouldRedirect: (currentPath: string) => boolean | string;
660
+ /** Construct URL with redirect parameters */
661
+ constructUrlWithRedirect: (to: string) => string;
662
+ /** Navigate to SignIn page */
663
+ redirectToSignIn(options?: SignInRedirectOptions): Promise<unknown>;
664
+ /** Navigate to SignUp page */
665
+ redirectToSignUp(options?: SignUpRedirectOptions): Promise<unknown>;
666
+ redirectAfterSignIn: () => void;
667
+ redirectAfterSignUp: () => void;
668
+ /** Error and Event Handling */
669
+ events: {
670
+ /** Subscribe to auth state changes */
671
+ onAuthStateChanged: (callback: (authState: TernSecureState) => void) => () => void;
672
+ /** Subscribe to error events */
673
+ onError: (callback: (error: AuthErrorTree) => void) => () => void;
674
+ /** Status */
675
+ onStatusChanged: (callback: (status: TernSecureInstanceTreeStatus) => void) => () => void;
676
+ };
677
+ }
678
+ type SignUpFormValuesTree = {
679
+ email: string;
680
+ password: string;
681
+ confirmPassword?: string;
682
+ displayName?: string;
683
+ };
684
+ type SignUpInitialValueTree = Partial<SignUpFormValuesTree>;
685
+ /**
686
+ * Props for SignIn component focusing on UI concerns
687
+ */
688
+ type SignInPropsTree = {
689
+ /** URL to navigate to after successfully sign-in */
690
+ forceRedirectUrl?: string | null;
691
+ /** Initial form values */
692
+ initialValue?: SignInInitialValueTree;
693
+ /** UI configuration */
694
+ ui?: SignInUIConfig;
695
+ /** Callbacks */
696
+ onError?: (error: AuthErrorTree) => void;
697
+ onSuccess?: (user: TernSecureUser | null) => void;
698
+ } & SignUpRedirectUrl;
699
+ /**
700
+ * Props for SignUp component focusing on UI concerns
701
+ */
702
+ type SignUpPropsTree = {
703
+ /** URL to navigate to after successfully sign-up */
704
+ forceRedirectUrl?: string | null;
705
+ /** Initial form values */
706
+ initialValue?: SignUpInitialValueTree;
707
+ /** UI configuration */
708
+ ui?: SignUpUIConfig;
709
+ /** Callbacks */
710
+ onSubmit?: (values: SignUpFormValuesTree) => Promise<void>;
711
+ onError?: (error: AuthErrorTree) => void;
712
+ onSuccess?: (user: TernSecureUser | null) => void;
713
+ } & SignInRedirectUrl;
714
+ type SignInRedirectOptions = RedirectOptions;
715
+ type SignUpRedirectOptions = RedirectOptions;
716
+
717
+ export { type ActiveSession, type AdminConfigValidationResult, type Appearance, type AuthActions, type AuthError, type AuthErrorCode, type AuthErrorResponse, type AuthErrorTree, type AuthProviderStatus, type BaseAuthUIConfig, type ConfigValidationResult, DEFAULT_TERN_SECURE_STATE, ERRORS, type ErrorCode, type ExpiredSession, type FirebaseState, type IdTokenResult, type ParsedToken, type PendingSession, type RedirectConfig, type RedirectOptions, type ResendEmailVerification, type SessionStatus, type SignInFormValuesTree, type SignInInitialValue, type SignInInitialValueTree, type SignInProps, type SignInPropsTree, type SignInRedirectOptions, type SignInRedirectUrl, type SignInResource, type SignInResponse, type SignInResponseTree, type SignInStatus, type SignInUIConfig, type SignUpFormValuesTree, type SignUpInitialValue, type SignUpInitialValueTree, type SignUpProps, type SignUpPropsTree, type SignUpRedirectOptions, type SignUpRedirectUrl, type SignUpResource, type SignUpStatus, type SignUpUIConfig, type SignedInSession, type TernSecureAdminConfig, type TernSecureAuthProvider, type TernSecureConfig, TernSecureError, type TernSecureInstance, type TernSecureInstanceTree, type TernSecureInstanceTreeOptions, type TernSecureInstanceTreeStatus, type TernSecureOptions, type TernSecureSession, type TernSecureSessionTree, type TernSecureState, type TernSecureUser, type TernSecureUserData, type ThemeBorderRadius, type ThemeColors, type ThemeComponentStyles, type ThemeFonts, type ThemeSpacing, type UserInfo, getErrorAlertVariant, handleFirebaseAuthError, isAuthErrorResponse, isSignInResponse, isSignInResponseTree };