@tern-secure/types 1.0.4 → 1.0.5
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/esm/index.js +0 -106
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +336 -40
- package/dist/index.d.ts +1054 -11
- package/dist/index.js +0 -110
- package/dist/index.js.map +1 -1
- package/package.json +4 -2
- package/dist/all.d.ts +0 -105
- package/dist/all.d.ts.map +0 -1
- package/dist/auth.d.ts +0 -37
- package/dist/auth.d.ts.map +0 -1
- package/dist/errors.d.ts +0 -66
- package/dist/errors.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/instanceTree.d.ts +0 -140
- package/dist/instanceTree.d.ts.map +0 -1
- package/dist/redirect.d.ts +0 -8
- package/dist/redirect.d.ts.map +0 -1
- package/dist/session.d.ts +0 -87
- package/dist/session.d.ts.map +0 -1
- package/dist/signIn.d.ts +0 -56
- package/dist/signIn.d.ts.map +0 -1
- package/dist/signUp.d.ts +0 -20
- package/dist/signUp.d.ts.map +0 -1
- package/dist/ternsecure.d.ts +0 -123
- package/dist/ternsecure.d.ts.map +0 -1
- package/dist/theme.d.ts +0 -133
- package/dist/theme.d.ts.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,1054 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
+
tenantId?: string;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Configuration validation result
|
|
60
|
+
*/
|
|
61
|
+
interface ConfigValidationResult {
|
|
62
|
+
isValid: boolean;
|
|
63
|
+
errors: string[];
|
|
64
|
+
config: TernSecureConfig;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* TernSecure initialization options
|
|
68
|
+
*/
|
|
69
|
+
interface TernSecureOptions {
|
|
70
|
+
/** Environment setting for different configurations */
|
|
71
|
+
environment?: 'development' | 'production';
|
|
72
|
+
/** Geographic region for data storage */
|
|
73
|
+
region?: string;
|
|
74
|
+
/** Custom error handler */
|
|
75
|
+
onError?: (error: Error) => void;
|
|
76
|
+
/** Debug mode flag */
|
|
77
|
+
debug?: boolean;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Firebase initialization state
|
|
81
|
+
*/
|
|
82
|
+
interface FirebaseState {
|
|
83
|
+
/** Whether Firebase has been initialized */
|
|
84
|
+
initialized: boolean;
|
|
85
|
+
/** Any initialization errors */
|
|
86
|
+
error: Error | null;
|
|
87
|
+
/** Timestamp of last initialization attempt */
|
|
88
|
+
lastInitAttempt?: number;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Firebase Admin configuration interface
|
|
92
|
+
*/
|
|
93
|
+
interface TernSecureAdminConfig {
|
|
94
|
+
projectId: string;
|
|
95
|
+
clientEmail: string;
|
|
96
|
+
privateKey: string;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Firebase Server configuration interface
|
|
100
|
+
*/
|
|
101
|
+
interface TernSecureServerConfig {
|
|
102
|
+
apiKey: string;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Firebase Admin configuration validation result
|
|
106
|
+
*/
|
|
107
|
+
interface AdminConfigValidationResult {
|
|
108
|
+
isValid: boolean;
|
|
109
|
+
errors: string[];
|
|
110
|
+
config: TernSecureAdminConfig;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Firebase Server configuration validation result
|
|
114
|
+
*/
|
|
115
|
+
interface ServerConfigValidationResult {
|
|
116
|
+
isValid: boolean;
|
|
117
|
+
errors: string[];
|
|
118
|
+
config: TernSecureServerConfig;
|
|
119
|
+
}
|
|
120
|
+
type InstanceType = 'production' | 'development';
|
|
121
|
+
|
|
122
|
+
interface TernSecureAPIError {
|
|
123
|
+
code: string;
|
|
124
|
+
message: string;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
interface CookieStore {
|
|
128
|
+
get(name: string): Promise<{
|
|
129
|
+
value: string | undefined;
|
|
130
|
+
}>;
|
|
131
|
+
set(name: string, value: string, options: CookieOptions): Promise<void>;
|
|
132
|
+
delete(name: string): Promise<void>;
|
|
133
|
+
}
|
|
134
|
+
interface CookieOptions {
|
|
135
|
+
maxAge?: number;
|
|
136
|
+
httpOnly?: boolean;
|
|
137
|
+
secure?: boolean;
|
|
138
|
+
sameSite?: 'strict' | 'lax' | 'none';
|
|
139
|
+
path?: string;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
type AuthErrorCode = keyof typeof ERRORS;
|
|
143
|
+
type ErrorCode = keyof typeof ERRORS;
|
|
144
|
+
declare const ERRORS: {
|
|
145
|
+
readonly SERVER_SIDE_INITIALIZATION: "TernSecure must be initialized on the client side";
|
|
146
|
+
readonly REQUIRES_VERIFICATION: "AUTH_REQUIRES_VERIFICATION";
|
|
147
|
+
readonly AUTHENTICATED: "AUTHENTICATED";
|
|
148
|
+
readonly UNAUTHENTICATED: "UNAUTHENTICATED";
|
|
149
|
+
readonly UNVERIFIED: "UNVERIFIED";
|
|
150
|
+
readonly NOT_INITIALIZED: "TernSecure services are not initialized. Call initializeTernSecure() first";
|
|
151
|
+
readonly HOOK_CONTEXT: "Hook must be used within TernSecureProvider";
|
|
152
|
+
readonly EMAIL_NOT_VERIFIED: "EMAIL_NOT_VERIFIED";
|
|
153
|
+
readonly INVALID_CREDENTIALS: "INVALID_CREDENTIALS";
|
|
154
|
+
readonly USER_DISABLED: "USER_DISABLED";
|
|
155
|
+
readonly TOO_MANY_ATTEMPTS: "TOO_MANY_ATTEMPTS";
|
|
156
|
+
readonly NETWORK_ERROR: "NETWORK_ERROR";
|
|
157
|
+
readonly INVALID_EMAIL: "INVALID_EMAIL";
|
|
158
|
+
readonly WEAK_PASSWORD: "WEAK_PASSWORD";
|
|
159
|
+
readonly EMAIL_EXISTS: "EMAIL_EXISTS";
|
|
160
|
+
readonly POPUP_BLOCKED: "POPUP_BLOCKED";
|
|
161
|
+
readonly OPERATION_NOT_ALLOWED: "OPERATION_NOT_ALLOWED";
|
|
162
|
+
readonly EXPIRED_TOKEN: "EXPIRED_TOKEN";
|
|
163
|
+
readonly INVALID_TOKEN: "INVALID_TOKEN";
|
|
164
|
+
readonly SESSION_EXPIRED: "SESSION_EXPIRED";
|
|
165
|
+
readonly INTERNAL_ERROR: "INTERNAL_ERROR";
|
|
166
|
+
readonly UNKNOWN_ERROR: "An unknown error occurred.";
|
|
167
|
+
readonly INVALID_ARGUMENT: "Invalid argument provided.";
|
|
168
|
+
readonly USER_NOT_FOUND: "auth/user-not-found";
|
|
169
|
+
readonly WRONG_PASSWORD: "auth/wrong-password";
|
|
170
|
+
readonly EMAIL_ALREADY_IN_USE: "auth/email-already-in-use";
|
|
171
|
+
readonly REQUIRES_RECENT_LOGIN: "auth/requires-recent-login";
|
|
172
|
+
readonly NO_SESSION_COOKIE: "No session cookie found.";
|
|
173
|
+
readonly INVALID_SESSION_COOKIE: "Invalid session cookie.";
|
|
174
|
+
readonly NO_ID_TOKEN: "No ID token found.";
|
|
175
|
+
readonly INVALID_ID_TOKEN: "Invalid ID token.";
|
|
176
|
+
readonly REDIRECT_LOOP: "Redirect loop detected.";
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Defines the basic structure for color theming.
|
|
181
|
+
*/
|
|
182
|
+
interface ThemeColors {
|
|
183
|
+
primary?: string;
|
|
184
|
+
secondary?: string;
|
|
185
|
+
accent?: string;
|
|
186
|
+
background?: string;
|
|
187
|
+
text?: string;
|
|
188
|
+
error?: string;
|
|
189
|
+
success?: string;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Defines the basic structure for font theming.
|
|
193
|
+
*/
|
|
194
|
+
interface ThemeFonts {
|
|
195
|
+
primary?: string;
|
|
196
|
+
secondary?: string;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Defines the basic structure for spacing and layout theming.
|
|
200
|
+
*/
|
|
201
|
+
interface ThemeSpacing {
|
|
202
|
+
small?: string | number;
|
|
203
|
+
medium?: string | number;
|
|
204
|
+
large?: string | number;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Defines the basic structure for border radius theming.
|
|
208
|
+
*/
|
|
209
|
+
interface ThemeBorderRadius {
|
|
210
|
+
small?: string | number;
|
|
211
|
+
medium?: string | number;
|
|
212
|
+
large?: string | number;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Allows for overriding styles of specific UI components.
|
|
216
|
+
* Properties can be CSS-in-JS objects or class names, depending on implementation.
|
|
217
|
+
*/
|
|
218
|
+
interface ThemeComponentStyles {
|
|
219
|
+
button?: Record<string, any> | string;
|
|
220
|
+
input?: Record<string, any> | string;
|
|
221
|
+
card?: Record<string, any> | string;
|
|
222
|
+
label?: Record<string, any> | string;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Defines the overall appearance/theme configuration.
|
|
226
|
+
* This allows for broad customization of the UI components.
|
|
227
|
+
*/
|
|
228
|
+
interface Appearance {
|
|
229
|
+
colors?: ThemeColors;
|
|
230
|
+
fonts?: ThemeFonts;
|
|
231
|
+
spacing?: ThemeSpacing;
|
|
232
|
+
borderRadius?: ThemeBorderRadius;
|
|
233
|
+
componentStyles?: ThemeComponentStyles;
|
|
234
|
+
variables?: Record<string, string | number>;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Base UI configuration shared between SignIn and SignUp
|
|
238
|
+
*/
|
|
239
|
+
interface BaseAuthUIConfig {
|
|
240
|
+
/** Visual appearance configuration */
|
|
241
|
+
appearance?: Appearance;
|
|
242
|
+
/** Application logo URL or SVG string */
|
|
243
|
+
logo?: string;
|
|
244
|
+
/** Application name for display */
|
|
245
|
+
appName?: string;
|
|
246
|
+
/** Render mode for cross-platform support */
|
|
247
|
+
renderMode?: 'modal' | 'page' | 'embedded';
|
|
248
|
+
/** Layout direction */
|
|
249
|
+
layout?: 'vertical' | 'horizontal';
|
|
250
|
+
/** Custom loading message */
|
|
251
|
+
loadingMessage?: string;
|
|
252
|
+
/** Loading spinner variant */
|
|
253
|
+
loadingSpinnerVariant?: 'circular' | 'linear' | 'dots';
|
|
254
|
+
/** Accessibility configuration */
|
|
255
|
+
a11y?: {
|
|
256
|
+
/** ARIA labels and descriptions */
|
|
257
|
+
labels?: Record<string, string>;
|
|
258
|
+
/** Element to receive initial focus */
|
|
259
|
+
initialFocus?: string;
|
|
260
|
+
/** Whether to trap focus within the auth UI */
|
|
261
|
+
trapFocus?: boolean;
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Sign-in specific UI configuration
|
|
266
|
+
*/
|
|
267
|
+
interface SignInUIConfig extends BaseAuthUIConfig {
|
|
268
|
+
/** Social sign-in buttons configuration */
|
|
269
|
+
socialButtons?: {
|
|
270
|
+
google?: boolean;
|
|
271
|
+
microsoft?: boolean;
|
|
272
|
+
github?: boolean;
|
|
273
|
+
facebook?: boolean;
|
|
274
|
+
twitter?: boolean;
|
|
275
|
+
apple?: boolean;
|
|
276
|
+
linkedin?: boolean;
|
|
277
|
+
layout?: 'vertical' | 'horizontal';
|
|
278
|
+
size?: 'small' | 'medium' | 'large';
|
|
279
|
+
};
|
|
280
|
+
/** "Remember me" checkbox configuration */
|
|
281
|
+
rememberMe?: {
|
|
282
|
+
enabled?: boolean;
|
|
283
|
+
defaultChecked?: boolean;
|
|
284
|
+
};
|
|
285
|
+
/** Sign-up link configuration */
|
|
286
|
+
signUpLink?: {
|
|
287
|
+
enabled?: boolean;
|
|
288
|
+
text?: string;
|
|
289
|
+
href?: string;
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Sign-up specific UI configuration
|
|
294
|
+
*/
|
|
295
|
+
interface SignUpUIConfig extends BaseAuthUIConfig {
|
|
296
|
+
/** Password requirements display configuration */
|
|
297
|
+
passwordRequirements?: {
|
|
298
|
+
show?: boolean;
|
|
299
|
+
rules?: Array<{
|
|
300
|
+
rule: string;
|
|
301
|
+
description: string;
|
|
302
|
+
}>;
|
|
303
|
+
};
|
|
304
|
+
/** Terms and conditions configuration */
|
|
305
|
+
terms?: {
|
|
306
|
+
enabled?: boolean;
|
|
307
|
+
text?: string;
|
|
308
|
+
link?: string;
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
interface TernSecureSession {
|
|
313
|
+
token: string | null;
|
|
314
|
+
expiresAt?: number;
|
|
315
|
+
}
|
|
316
|
+
type SignInFormValues = {
|
|
317
|
+
email: string;
|
|
318
|
+
password: string;
|
|
319
|
+
phoneNumber?: string;
|
|
320
|
+
};
|
|
321
|
+
type SignInInitialValue = Partial<SignInFormValues>;
|
|
322
|
+
type SignUpFormValues = {
|
|
323
|
+
email: string;
|
|
324
|
+
password: string;
|
|
325
|
+
confirmPassword?: string;
|
|
326
|
+
displayName?: string;
|
|
327
|
+
};
|
|
328
|
+
type SignUpInitialValue = Partial<SignUpFormValues>;
|
|
329
|
+
interface SignInResponse {
|
|
330
|
+
success: boolean;
|
|
331
|
+
message?: string;
|
|
332
|
+
error?: any | undefined;
|
|
333
|
+
user?: any;
|
|
334
|
+
}
|
|
335
|
+
interface AuthError extends Error {
|
|
336
|
+
code?: any | string;
|
|
337
|
+
message: string;
|
|
338
|
+
response?: SignInResponse;
|
|
339
|
+
}
|
|
340
|
+
declare function isSignInResponse(value: any): value is SignInResponse;
|
|
341
|
+
interface AuthActions {
|
|
342
|
+
signInWithEmail: (email: string, password: string) => Promise<SignInResponse>;
|
|
343
|
+
signInWithGoogle: () => Promise<void>;
|
|
344
|
+
signInWithMicrosoft: () => Promise<void>;
|
|
345
|
+
signOut: () => Promise<void>;
|
|
346
|
+
getRedirectResult: () => Promise<any>;
|
|
347
|
+
getIdToken: () => Promise<string | null>;
|
|
348
|
+
createUserWithEmailAndPassword?: (email: string, password: string) => Promise<SignInResponse>;
|
|
349
|
+
sendEmailVerification?: (user: TernSecureUser) => Promise<void>;
|
|
350
|
+
}
|
|
351
|
+
interface RedirectConfig {
|
|
352
|
+
redirectUrl?: string;
|
|
353
|
+
isReturn?: boolean;
|
|
354
|
+
priority?: number;
|
|
355
|
+
}
|
|
356
|
+
interface SignInProps extends RedirectConfig {
|
|
357
|
+
initialValue?: SignInInitialValue;
|
|
358
|
+
logo?: string;
|
|
359
|
+
appName?: string;
|
|
360
|
+
appearance?: Appearance;
|
|
361
|
+
onError?: (error: AuthError) => void;
|
|
362
|
+
onSuccess?: (user: TernSecureUser | null) => void;
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* SignUpProps interface defines the properties for the sign-up component.
|
|
366
|
+
* It extends RedirectConfig to include redirect-related properties.
|
|
367
|
+
*/
|
|
368
|
+
interface SignUpProps extends RedirectConfig {
|
|
369
|
+
initialValue?: SignUpInitialValue;
|
|
370
|
+
logo?: string;
|
|
371
|
+
appName?: string;
|
|
372
|
+
appearance?: Appearance;
|
|
373
|
+
onError?: (error: AuthError) => void;
|
|
374
|
+
onSuccess?: (user: TernSecureUser | null) => void;
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Defines the contract for a TernSecure instance.
|
|
378
|
+
* This instance provides authentication state, user information, and methods
|
|
379
|
+
* for managing the authentication lifecycle. It is designed to be used by
|
|
380
|
+
* UI packages like tern-ui, which act as "dumb" renderers.
|
|
381
|
+
*/
|
|
382
|
+
interface TernSecureInstanceOld {
|
|
383
|
+
/** Indicates if the user is currently signed in. */
|
|
384
|
+
isSignedIn: () => boolean;
|
|
385
|
+
/** The current authenticated user object, or null if not signed in. */
|
|
386
|
+
user: TernSecureUser | null;
|
|
387
|
+
/** The current user session information, or null if not signed in. */
|
|
388
|
+
session: TernSecureSession | null;
|
|
389
|
+
/** Initiates the sign-out process for the current user. */
|
|
390
|
+
signOut: () => Promise<void>;
|
|
391
|
+
/**
|
|
392
|
+
* Prepares or signals to mount the sign-in interface.
|
|
393
|
+
* @param options Optional configuration or initial state for the sign-in UI, conforming to SignInProps.
|
|
394
|
+
*/
|
|
395
|
+
mountSignIn: (options?: SignInProps) => void;
|
|
396
|
+
/** Cleans up or signals to unmount the sign-in interface. */
|
|
397
|
+
unmountSignIn: () => void;
|
|
398
|
+
/**
|
|
399
|
+
* Prepares or signals to mount the sign-up interface.
|
|
400
|
+
* @param options Optional configuration or initial state for the sign-up UI, conforming to SignUpProps.
|
|
401
|
+
*/
|
|
402
|
+
mountSignUp: (options?: SignUpProps) => void;
|
|
403
|
+
/** Cleans up or signals to unmount the sign-up interface. */
|
|
404
|
+
unmountSignUp: () => void;
|
|
405
|
+
/**
|
|
406
|
+
* Determines if a redirect is necessary based on the current authentication
|
|
407
|
+
* state and the given path.
|
|
408
|
+
* @param currentPath The current URL path.
|
|
409
|
+
* @returns True if a redirect is needed, false otherwise, or a string path to redirect to.
|
|
410
|
+
*/
|
|
411
|
+
shouldRedirect: (currentPath: string) => boolean | string;
|
|
412
|
+
/**
|
|
413
|
+
* Constructs a URL, appending necessary redirect parameters.
|
|
414
|
+
* Useful for redirecting back to the original page after authentication.
|
|
415
|
+
* @param baseUrl The base URL to which redirect parameters should be added.
|
|
416
|
+
* @returns The new URL string with redirect parameters.
|
|
417
|
+
*/
|
|
418
|
+
constructUrlWithRedirect: (baseUrl: string) => string;
|
|
419
|
+
/**
|
|
420
|
+
* Redirects the user to the configured login page.
|
|
421
|
+
* @param redirectUrl Optional URL to redirect to after successful login.
|
|
422
|
+
*/
|
|
423
|
+
redirectToLogin: (redirectUrl?: string) => void;
|
|
424
|
+
/** Indicates if an authentication operation is currently in progress. */
|
|
425
|
+
isLoading: boolean;
|
|
426
|
+
/** Holds any error that occurred during an authentication operation, or null otherwise. */
|
|
427
|
+
error: Error | null;
|
|
428
|
+
/** Indicates if the user has verified their email address. */
|
|
429
|
+
sendVerificationEmail: () => Promise<void>;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
type SessionStatus = 'active' | 'expired' | 'revoked' | 'pending';
|
|
433
|
+
/**
|
|
434
|
+
* parsed can be replaced with
|
|
435
|
+
*/
|
|
436
|
+
interface ParsedToken {
|
|
437
|
+
/** Expiration time of the token. */
|
|
438
|
+
'exp'?: string;
|
|
439
|
+
/** UID of the user. */
|
|
440
|
+
'sub'?: string;
|
|
441
|
+
/** Time at which authentication was performed. */
|
|
442
|
+
'auth_time'?: string;
|
|
443
|
+
/** Issuance time of the token. */
|
|
444
|
+
'iat'?: string;
|
|
445
|
+
/** Firebase specific claims, containing the provider(s) used to authenticate the user. */
|
|
446
|
+
'firebase'?: {
|
|
447
|
+
'sign_in_provider'?: string;
|
|
448
|
+
'sign_in_second_factor'?: string;
|
|
449
|
+
'identities'?: Record<string, string>;
|
|
450
|
+
};
|
|
451
|
+
/** Map of any additional custom claims. */
|
|
452
|
+
[key: string]: unknown;
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Core properties for any session that is or was authenticated.
|
|
456
|
+
* These properties are guaranteed to exist for active, expired, or revoked sessions.
|
|
457
|
+
*/
|
|
458
|
+
interface AuthenticatedSessionBase {
|
|
459
|
+
/** The Firebase Auth ID token JWT string. */
|
|
460
|
+
token: string;
|
|
461
|
+
/** The ID token expiration time (e.g., UTC string or Unix timestamp). */
|
|
462
|
+
expirationTime: string;
|
|
463
|
+
/** The ID token issuance time. */
|
|
464
|
+
issuedAtTime: string;
|
|
465
|
+
/** Time at which authentication was performed (from token claims). */
|
|
466
|
+
authTime: string;
|
|
467
|
+
/**
|
|
468
|
+
* The entire payload claims of the ID token including the standard reserved claims
|
|
469
|
+
* as well as custom claims.
|
|
470
|
+
*/
|
|
471
|
+
claims: ParsedToken;
|
|
472
|
+
/**
|
|
473
|
+
* Time the user last signed in.
|
|
474
|
+
* This could be from Firebase User metadata or persisted by TernSecure.
|
|
475
|
+
*/
|
|
476
|
+
lastSignedAt?: number;
|
|
477
|
+
/** signInProvider */
|
|
478
|
+
signInProvider: string;
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* Represents a session when the user is authenticated and the token is considered active.
|
|
482
|
+
*/
|
|
483
|
+
interface ActiveSession extends AuthenticatedSessionBase {
|
|
484
|
+
status: 'active';
|
|
485
|
+
user?: TernSecureUser;
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* Represents a session when the user was authenticated, but the token has expired.
|
|
489
|
+
*/
|
|
490
|
+
interface ExpiredSession extends AuthenticatedSessionBase {
|
|
491
|
+
status: 'expired';
|
|
492
|
+
user?: TernSecureUser;
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* Represents a session that is awaiting some action.
|
|
496
|
+
*/
|
|
497
|
+
interface PendingSession extends AuthenticatedSessionBase {
|
|
498
|
+
status: 'pending';
|
|
499
|
+
user?: TernSecureUser;
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* Defines the possible states of a user's session within TernSecure.
|
|
503
|
+
* This is a discriminated union based on the `status` property.
|
|
504
|
+
* The actual `TernSecureUser` (Firebase User object) is typically stored separately,
|
|
505
|
+
* for example, in `TernSecureInstanceTree.auth.user`.
|
|
506
|
+
*/
|
|
507
|
+
type TernSecureSessionTree = ActiveSession | ExpiredSession;
|
|
508
|
+
type SignedInSession = ActiveSession | PendingSession | ExpiredSession;
|
|
509
|
+
interface SessionParams {
|
|
510
|
+
idToken: string;
|
|
511
|
+
csrfToken?: string;
|
|
512
|
+
}
|
|
513
|
+
interface SessionResult {
|
|
514
|
+
success: boolean;
|
|
515
|
+
message: string;
|
|
516
|
+
expiresIn?: number;
|
|
517
|
+
error?: string;
|
|
518
|
+
cookieSet?: boolean;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
type SignInStatus = 'idle' | 'pending_email_password' | 'pending_social' | 'pending_mfa' | 'redirecting' | 'success' | 'error';
|
|
522
|
+
type SignInFormValuesTree = {
|
|
523
|
+
email: string;
|
|
524
|
+
password: string;
|
|
525
|
+
phoneNumber?: string;
|
|
526
|
+
};
|
|
527
|
+
interface AuthErrorResponse {
|
|
528
|
+
success: false;
|
|
529
|
+
message: string;
|
|
530
|
+
code: ErrorCode;
|
|
531
|
+
}
|
|
532
|
+
interface AuthErrorTree extends Error {
|
|
533
|
+
code?: any | string;
|
|
534
|
+
message: string;
|
|
535
|
+
response?: any | string;
|
|
536
|
+
}
|
|
537
|
+
interface SignInResponseTree {
|
|
538
|
+
success: boolean;
|
|
539
|
+
message?: string;
|
|
540
|
+
error?: any | undefined;
|
|
541
|
+
user?: any;
|
|
542
|
+
}
|
|
543
|
+
type SignInInitialValueTree = Partial<SignInFormValuesTree>;
|
|
544
|
+
interface ResendEmailVerification extends SignInResponseTree {
|
|
545
|
+
isVerified?: boolean;
|
|
546
|
+
}
|
|
547
|
+
declare function isSignInResponseTree(value: any): value is SignInResponseTree;
|
|
548
|
+
interface SignInResource {
|
|
549
|
+
/**
|
|
550
|
+
* The current status of the sign-in process.
|
|
551
|
+
*/
|
|
552
|
+
status?: SignInStatus;
|
|
553
|
+
/**
|
|
554
|
+
* Signs in a user with their email and password.
|
|
555
|
+
* @param params - The sign-in form values.
|
|
556
|
+
* @returns A promise that resolves with the sign-in response.
|
|
557
|
+
*/
|
|
558
|
+
withEmailAndPassword: (params: SignInFormValuesTree) => Promise<SignInResponseTree>;
|
|
559
|
+
/**
|
|
560
|
+
* @param provider - The identifier of the social provider (e.g., 'google', 'microsoft', 'github').
|
|
561
|
+
* @param options - Optional configuration for the social sign-in flow.
|
|
562
|
+
* @returns A promise that resolves with the sign-in response or void if redirecting.
|
|
563
|
+
*/
|
|
564
|
+
withSocialProvider: (provider: string, options?: {
|
|
565
|
+
mode?: 'popup' | 'redirect';
|
|
566
|
+
}) => Promise<SignInResponseTree | void>;
|
|
567
|
+
/**
|
|
568
|
+
* Completes an MFA (Multi-Factor Authentication) step after a primary authentication attempt.
|
|
569
|
+
* @param mfaToken - The MFA token or code submitted by the user.
|
|
570
|
+
* @param mfaContext - Optional context or session data from the MFA initiation step.
|
|
571
|
+
* @returns A promise that resolves with the sign-in response upon successful MFA verification.
|
|
572
|
+
*/
|
|
573
|
+
completeMfaSignIn: (mfaToken: string, mfaContext?: any) => Promise<SignInResponseTree>;
|
|
574
|
+
/**
|
|
575
|
+
* Sends a password reset email to the given email address.
|
|
576
|
+
* @param email - The user's email address.
|
|
577
|
+
* @returns A promise that resolves when the email is sent.
|
|
578
|
+
*/
|
|
579
|
+
sendPasswordResetEmail: (email: string) => Promise<void>;
|
|
580
|
+
/**
|
|
581
|
+
* Resends the email verification link to the user's email address.
|
|
582
|
+
* @returns A promise that resolves with the sign-in response.
|
|
583
|
+
*/
|
|
584
|
+
resendEmailVerification: () => Promise<ResendEmailVerification>;
|
|
585
|
+
/**
|
|
586
|
+
* Checks the result of a redirect-based sign-in flow, typically used in OAuth or SSO scenarios.
|
|
587
|
+
* @returns A promise that resolves with the sign-in response or null if no result is available.
|
|
588
|
+
*/
|
|
589
|
+
checkRedirectResult: () => Promise<SignInResponseTree | null>;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
interface SignUpResource {
|
|
593
|
+
status?: SignUpStatus | null;
|
|
594
|
+
username?: string | null;
|
|
595
|
+
firstName?: string | null;
|
|
596
|
+
lastName?: string | null;
|
|
597
|
+
displayName?: string | null;
|
|
598
|
+
email: string | null;
|
|
599
|
+
phoneNumber?: string | null;
|
|
600
|
+
/**
|
|
601
|
+
* @param provider - The identifier of the social provider (e.g., 'google', 'microsoft', 'github').
|
|
602
|
+
* @param options - Optional configuration for the social sign-in flow.
|
|
603
|
+
* @returns A promise that resolves with the sign-in response or void if redirecting.
|
|
604
|
+
*/
|
|
605
|
+
withSocialProvider: (provider: string, options?: {
|
|
606
|
+
mode?: 'popup' | 'redirect';
|
|
607
|
+
}) => Promise<SignInResponseTree | void>;
|
|
608
|
+
}
|
|
609
|
+
type SignUpStatus = 'missing_requirements' | 'complete' | 'abandoned';
|
|
610
|
+
|
|
611
|
+
interface FirebaseClaims {
|
|
612
|
+
identities: {
|
|
613
|
+
[key: string]: unknown;
|
|
614
|
+
};
|
|
615
|
+
sign_in_provider: string;
|
|
616
|
+
sign_in_second_factor?: string;
|
|
617
|
+
second_factor_identifier?: string;
|
|
618
|
+
tenant?: string;
|
|
619
|
+
[key: string]: unknown;
|
|
620
|
+
}
|
|
621
|
+
interface DecodedIdToken {
|
|
622
|
+
aud: string;
|
|
623
|
+
auth_time: number;
|
|
624
|
+
email?: string;
|
|
625
|
+
email_verified?: boolean;
|
|
626
|
+
exp: number;
|
|
627
|
+
firebase: FirebaseClaims;
|
|
628
|
+
iat: number;
|
|
629
|
+
iss: string;
|
|
630
|
+
phone_number?: string;
|
|
631
|
+
picture?: string;
|
|
632
|
+
sub: string;
|
|
633
|
+
uid: string;
|
|
634
|
+
[key: string]: any;
|
|
635
|
+
}
|
|
636
|
+
interface VerifiedTokens {
|
|
637
|
+
IdToken: string;
|
|
638
|
+
DecodedIdToken: DecodedIdToken;
|
|
639
|
+
}
|
|
640
|
+
interface JWTProtectedHeader {
|
|
641
|
+
alg?: string;
|
|
642
|
+
kid?: string;
|
|
643
|
+
x5t?: string;
|
|
644
|
+
x5c?: string[];
|
|
645
|
+
x5u?: string;
|
|
646
|
+
jku?: string;
|
|
647
|
+
typ?: string;
|
|
648
|
+
cty?: string;
|
|
649
|
+
crit?: string[];
|
|
650
|
+
b64?: boolean;
|
|
651
|
+
enc?: string;
|
|
652
|
+
[propName: string]: unknown;
|
|
653
|
+
}
|
|
654
|
+
interface JWTPayload {
|
|
655
|
+
iss?: string;
|
|
656
|
+
sub?: string;
|
|
657
|
+
aud?: string | string[];
|
|
658
|
+
jti?: string;
|
|
659
|
+
nbf?: number;
|
|
660
|
+
exp?: number;
|
|
661
|
+
iat?: number;
|
|
662
|
+
[propName: string]: unknown;
|
|
663
|
+
}
|
|
664
|
+
type Jwt = {
|
|
665
|
+
header: JWTProtectedHeader;
|
|
666
|
+
payload: JWTPayload;
|
|
667
|
+
signature: Uint8Array;
|
|
668
|
+
raw: {
|
|
669
|
+
header: string;
|
|
670
|
+
payload: string;
|
|
671
|
+
signature: string;
|
|
672
|
+
text: string;
|
|
673
|
+
};
|
|
674
|
+
};
|
|
675
|
+
|
|
676
|
+
type SignInRedirectUrl = {
|
|
677
|
+
signInForceRedirectUrl?: string | null;
|
|
678
|
+
};
|
|
679
|
+
type SignUpRedirectUrl = {
|
|
680
|
+
signUpForceRedirectUrl?: string | null;
|
|
681
|
+
};
|
|
682
|
+
type AfterSignOutUrl = {
|
|
683
|
+
afterSignOutUrl?: string | null;
|
|
684
|
+
};
|
|
685
|
+
type RedirectOptions = SignInRedirectUrl | SignUpRedirectUrl;
|
|
686
|
+
|
|
687
|
+
interface InitialState {
|
|
688
|
+
userId: string | null;
|
|
689
|
+
token: any | null;
|
|
690
|
+
email: string | null;
|
|
691
|
+
user?: TernSecureUser | null;
|
|
692
|
+
}
|
|
693
|
+
interface TernSecureState {
|
|
694
|
+
userId: string | null;
|
|
695
|
+
isLoaded: boolean;
|
|
696
|
+
error: Error | null;
|
|
697
|
+
isValid: boolean;
|
|
698
|
+
isVerified: boolean;
|
|
699
|
+
isAuthenticated: boolean;
|
|
700
|
+
token: any | null;
|
|
701
|
+
email: string | null;
|
|
702
|
+
status: "loading" | "authenticated" | "unauthenticated" | "unverified";
|
|
703
|
+
user?: TernSecureUser | null;
|
|
704
|
+
}
|
|
705
|
+
type AuthProviderStatus = "idle" | "pending" | "error" | "success";
|
|
706
|
+
declare const DEFAULT_TERN_SECURE_STATE: TernSecureState;
|
|
707
|
+
interface TernSecureAuthProvider {
|
|
708
|
+
/** Current auth state */
|
|
709
|
+
internalAuthState: TernSecureState;
|
|
710
|
+
/** Current user*/
|
|
711
|
+
ternSecureUser(): TernSecureUser | null;
|
|
712
|
+
/** AuthCookie Manager */
|
|
713
|
+
authCookieManager(): void;
|
|
714
|
+
/** Current session */
|
|
715
|
+
currentSession: SignedInSession | null;
|
|
716
|
+
/** Sign in resource for authentication operations */
|
|
717
|
+
signIn: SignInResource | undefined;
|
|
718
|
+
/** SignUp resource for authentication operations */
|
|
719
|
+
signUp: SignUpResource | undefined;
|
|
720
|
+
/** The Firebase configuration used by this TernAuth instance. */
|
|
721
|
+
ternSecureConfig?: TernSecureConfig;
|
|
722
|
+
/** Sign out the current user */
|
|
723
|
+
signOut(): Promise<void>;
|
|
724
|
+
}
|
|
725
|
+
type Persistence = "local" | "session" | "browserCookie" | "none";
|
|
726
|
+
type Mode$1 = "browser" | "server";
|
|
727
|
+
type TernAuthSDK = {
|
|
728
|
+
/** SDK package name (e.g., @tern-secure/auth) */
|
|
729
|
+
name: string;
|
|
730
|
+
/** SDK version (e.g., 1.2.3) */
|
|
731
|
+
version: string;
|
|
732
|
+
/** Build environment (development, production, test) */
|
|
733
|
+
environment?: string;
|
|
734
|
+
/** Build date as ISO string */
|
|
735
|
+
buildDate?: string;
|
|
736
|
+
/** Additional build metadata */
|
|
737
|
+
buildInfo?: {
|
|
738
|
+
name: string;
|
|
739
|
+
version: string;
|
|
740
|
+
buildDate: string;
|
|
741
|
+
buildEnv: string;
|
|
742
|
+
};
|
|
743
|
+
};
|
|
744
|
+
interface TernSecureResources {
|
|
745
|
+
user?: TernSecureUser | null;
|
|
746
|
+
session?: SignedInSession | null;
|
|
747
|
+
}
|
|
748
|
+
type TernSecureAuthOptions = {
|
|
749
|
+
apiUrl?: string;
|
|
750
|
+
sdkMetadata?: TernAuthSDK;
|
|
751
|
+
signInUrl?: string;
|
|
752
|
+
signUpUrl?: string;
|
|
753
|
+
mode?: Mode$1;
|
|
754
|
+
requiresVerification?: boolean;
|
|
755
|
+
isTernSecureDev?: boolean;
|
|
756
|
+
ternSecureConfig?: TernSecureConfig;
|
|
757
|
+
persistence?: Persistence;
|
|
758
|
+
enableServiceWorker?: boolean;
|
|
759
|
+
} & SignInRedirectUrl & SignUpRedirectUrl & AfterSignOutUrl;
|
|
760
|
+
type TernAuthListenerEventPayload = {
|
|
761
|
+
authStateChanged: TernSecureState;
|
|
762
|
+
userChanged: TernSecureUser;
|
|
763
|
+
sessionChanged: SignedInSession | null;
|
|
764
|
+
tokenRefreshed: string | null;
|
|
765
|
+
};
|
|
766
|
+
type TernAuthListenerEvent = keyof TernAuthListenerEventPayload;
|
|
767
|
+
type ListenerCallback = (emission: TernSecureResources) => void;
|
|
768
|
+
type UnsubscribeCallback = () => void;
|
|
769
|
+
type TernSecureEvent = keyof TernAuthEventPayload;
|
|
770
|
+
type EventHandler<Events extends TernSecureEvent> = (payload: TernAuthEventPayload[Events]) => void;
|
|
771
|
+
type TernAuthEventPayload = {
|
|
772
|
+
status: TernSecureAuthStatus;
|
|
773
|
+
};
|
|
774
|
+
type TernSecureAuthStatus = "error" | "loading" | "ready";
|
|
775
|
+
type onEventListener = <E extends TernSecureEvent>(event: E, handler: EventHandler<E>, opt?: {
|
|
776
|
+
notify?: boolean;
|
|
777
|
+
}) => void;
|
|
778
|
+
type OffEventListener = <E extends TernSecureEvent>(event: E, handler: EventHandler<E>) => void;
|
|
779
|
+
type SignOutOptions = {
|
|
780
|
+
/** URL to redirect to after sign out */
|
|
781
|
+
redirectUrl?: string;
|
|
782
|
+
/** Callback to perform consumer-specific cleanup (e.g., delete session cookies) */
|
|
783
|
+
onBeforeSignOut?: () => Promise<void> | void;
|
|
784
|
+
/** Callback executed after successful sign out */
|
|
785
|
+
onAfterSignOut?: () => Promise<void> | void;
|
|
786
|
+
};
|
|
787
|
+
interface SignOut {
|
|
788
|
+
(options?: SignOutOptions): Promise<void>;
|
|
789
|
+
}
|
|
790
|
+
interface TernSecureAuth {
|
|
791
|
+
/** TernSecureAuth SDK version number */
|
|
792
|
+
version: string | undefined;
|
|
793
|
+
/** Metadata about the SDK instance */
|
|
794
|
+
sdkMetadata: TernAuthSDK | undefined;
|
|
795
|
+
/** Indicates if the TernSecureAuth instance is currently loading */
|
|
796
|
+
isLoading: boolean;
|
|
797
|
+
/** The current status of the TernSecureAuth instance */
|
|
798
|
+
status: TernSecureAuthStatus;
|
|
799
|
+
/** TernSecure API URL */
|
|
800
|
+
apiUrl: string;
|
|
801
|
+
/** TernSecure domain for API string */
|
|
802
|
+
domain: string;
|
|
803
|
+
/** TernSecure Proxy url */
|
|
804
|
+
proxyUrl?: string;
|
|
805
|
+
/** TernSecure Instance type */
|
|
806
|
+
instanceType: InstanceType | undefined;
|
|
807
|
+
/** Indicates if the TernSecureAuth instance is ready for use */
|
|
808
|
+
isReady: boolean;
|
|
809
|
+
/** Requires Verification */
|
|
810
|
+
requiresVerification: boolean;
|
|
811
|
+
/** Initialize TernSecureAuth */
|
|
812
|
+
initialize(options?: TernSecureAuthOptions): Promise<void>;
|
|
813
|
+
/** Current user*/
|
|
814
|
+
user: TernSecureUser | null | undefined;
|
|
815
|
+
/** Current session */
|
|
816
|
+
currentSession: SignedInSession | null;
|
|
817
|
+
/** Sign in resource for authentication operations */
|
|
818
|
+
signIn: SignInResource | undefined | null;
|
|
819
|
+
/** SignUp resource for authentication operations */
|
|
820
|
+
signUp: SignUpResource | undefined | null;
|
|
821
|
+
/** The Firebase configuration used by this TernAuth instance. */
|
|
822
|
+
ternSecureConfig?: TernSecureConfig;
|
|
823
|
+
/** Subscribe to auth state changes */
|
|
824
|
+
onAuthStateChanged(callback: (cb: any) => void): () => void;
|
|
825
|
+
/** Sign out the current user */
|
|
826
|
+
signOut: SignOut;
|
|
827
|
+
/** Subscribe to a single event */
|
|
828
|
+
on: onEventListener;
|
|
829
|
+
/** Remove event listener */
|
|
830
|
+
off: OffEventListener;
|
|
831
|
+
addListener: (callback: ListenerCallback) => UnsubscribeCallback;
|
|
832
|
+
}
|
|
833
|
+
interface TernSecureAuthFactory {
|
|
834
|
+
create(options?: TernSecureAuthOptions): TernSecureAuth;
|
|
835
|
+
}
|
|
836
|
+
type SharedSignInAuthObjectProperties = {
|
|
837
|
+
session: DecodedIdToken;
|
|
838
|
+
userId: string;
|
|
839
|
+
};
|
|
840
|
+
type CheckCustomClaims = {
|
|
841
|
+
role?: string | string[];
|
|
842
|
+
permissions?: string | string[];
|
|
843
|
+
[key: string]: any;
|
|
844
|
+
};
|
|
845
|
+
type CheckAuthorizationFromSessionClaims = (isAuthorizedParams: CheckCustomClaims) => boolean;
|
|
846
|
+
type TernVerificationResult = (DecodedIdToken & {
|
|
847
|
+
valid: true;
|
|
848
|
+
token?: string;
|
|
849
|
+
error?: never;
|
|
850
|
+
}) | {
|
|
851
|
+
valid: false;
|
|
852
|
+
error: AuthErrorResponse;
|
|
853
|
+
};
|
|
854
|
+
|
|
855
|
+
type Mode = 'browser' | 'server';
|
|
856
|
+
type TernSecureSDK = {
|
|
857
|
+
/** SDK package name (e.g., @tern-secure/ui) */
|
|
858
|
+
name: string;
|
|
859
|
+
/** SDK version (e.g., 1.2.3) */
|
|
860
|
+
version: string;
|
|
861
|
+
/** Build environment (development, production, test) */
|
|
862
|
+
environment?: string;
|
|
863
|
+
/** Build date as ISO string */
|
|
864
|
+
buildDate?: string;
|
|
865
|
+
/** Additional build metadata */
|
|
866
|
+
buildInfo?: {
|
|
867
|
+
name: string;
|
|
868
|
+
version: string;
|
|
869
|
+
buildDate: string;
|
|
870
|
+
buildEnv: string;
|
|
871
|
+
};
|
|
872
|
+
};
|
|
873
|
+
type SignOutOptionsTree = {
|
|
874
|
+
/** URL to redirect to after sign out */
|
|
875
|
+
redirectUrl?: string;
|
|
876
|
+
/** Callback to perform consumer-specific cleanup (e.g., delete session cookies) */
|
|
877
|
+
onBeforeSignOut?: () => Promise<void> | void;
|
|
878
|
+
/** Callback executed after successful sign out */
|
|
879
|
+
onAfterSignOut?: () => Promise<void> | void;
|
|
880
|
+
};
|
|
881
|
+
type TernSecureInstanceTreeOptions = {
|
|
882
|
+
sdkMetadata?: TernSecureSDK;
|
|
883
|
+
initialSession?: TernSecureSessionTree | null;
|
|
884
|
+
defaultAppearance?: Appearance;
|
|
885
|
+
signInUrl?: string;
|
|
886
|
+
signUpUrl?: string;
|
|
887
|
+
mode?: Mode;
|
|
888
|
+
onAuthStateChanged?: (user: TernSecureUser | null) => void;
|
|
889
|
+
onError?: (error: AuthErrorTree) => void;
|
|
890
|
+
requiresVerification?: boolean;
|
|
891
|
+
isTernSecureDev?: boolean;
|
|
892
|
+
ternSecureConfig?: TernSecureConfig;
|
|
893
|
+
enableServiceWorker?: boolean;
|
|
894
|
+
} & SignInRedirectUrl & SignUpRedirectUrl & AfterSignOutUrl;
|
|
895
|
+
type TernSecureInstanceTreeStatus = 'error' | 'loading' | 'ready';
|
|
896
|
+
/**
|
|
897
|
+
* Instance interface for managing auth UI state
|
|
898
|
+
*/
|
|
899
|
+
interface TernSecureInstanceTree {
|
|
900
|
+
version: string | undefined;
|
|
901
|
+
sdkMetadata: TernSecureSDK | undefined;
|
|
902
|
+
customDomain?: string;
|
|
903
|
+
proxyUrl?: string;
|
|
904
|
+
apiKey?: string;
|
|
905
|
+
projectId?: string;
|
|
906
|
+
environment?: string | undefined;
|
|
907
|
+
mode?: Mode;
|
|
908
|
+
isReady: boolean;
|
|
909
|
+
status: TernSecureInstanceTreeStatus;
|
|
910
|
+
isVisible: boolean;
|
|
911
|
+
currentView: 'signIn' | 'signUp' | 'verify' | null;
|
|
912
|
+
isLoading: boolean;
|
|
913
|
+
error: Error | null;
|
|
914
|
+
requiresVerification: boolean;
|
|
915
|
+
/** Authentication State */
|
|
916
|
+
auth: {
|
|
917
|
+
/** Current authenticated user */
|
|
918
|
+
user: TernSecureUser | null;
|
|
919
|
+
/** Current session information */
|
|
920
|
+
session: SignedInSession | null;
|
|
921
|
+
};
|
|
922
|
+
/** Core Authentication Methods */
|
|
923
|
+
ternAuth: TernSecureAuthProvider | undefined;
|
|
924
|
+
/** Sign out current user with optional cleanup */
|
|
925
|
+
signOut: (options?: SignOutOptionsTree) => Promise<void>;
|
|
926
|
+
showSignIn: (targetNode: HTMLDivElement, config?: SignInPropsTree) => void;
|
|
927
|
+
hideSignIn: (targetNode: HTMLDivElement) => void;
|
|
928
|
+
showSignUp: (targetNode: HTMLDivElement, config?: SignUpPropsTree) => void;
|
|
929
|
+
hideSignUp: (targetNode: HTMLDivElement) => void;
|
|
930
|
+
showUserButton: (targetNode: HTMLDivElement) => void;
|
|
931
|
+
hideUserButton: (targetNode: HTMLDivElement) => void;
|
|
932
|
+
clearError: () => void;
|
|
933
|
+
setLoading: (isLoading: boolean) => void;
|
|
934
|
+
/** Get redirect result from OAuth flows */
|
|
935
|
+
getRedirectResult: () => Promise<any>;
|
|
936
|
+
/** Check if redirect is needed */
|
|
937
|
+
shouldRedirect: (currentPath: string) => boolean | string;
|
|
938
|
+
/** Construct URL with redirect parameters */
|
|
939
|
+
constructUrlWithAuthRedirect: (to: string) => string;
|
|
940
|
+
/** Navigate to SignIn page */
|
|
941
|
+
redirectToSignIn(options?: SignInRedirectOptions): Promise<unknown>;
|
|
942
|
+
/** Navigate to SignUp page */
|
|
943
|
+
redirectToSignUp(options?: SignUpRedirectOptions): Promise<unknown>;
|
|
944
|
+
redirectAfterSignIn: () => void;
|
|
945
|
+
redirectAfterSignUp: () => void;
|
|
946
|
+
/** Error and Event Handling */
|
|
947
|
+
events: {
|
|
948
|
+
/** Subscribe to auth state changes */
|
|
949
|
+
onAuthStateChanged: (callback: (authState: TernSecureState) => void) => () => void;
|
|
950
|
+
/** Subscribe to error events */
|
|
951
|
+
onError: (callback: (error: AuthErrorTree) => void) => () => void;
|
|
952
|
+
/** Status */
|
|
953
|
+
onStatusChanged: (callback: (status: TernSecureInstanceTreeStatus) => void) => () => void;
|
|
954
|
+
};
|
|
955
|
+
}
|
|
956
|
+
/**
|
|
957
|
+
* Instance interface for managing auth UI state
|
|
958
|
+
*/
|
|
959
|
+
interface TernSecureInstance {
|
|
960
|
+
customDomain?: string;
|
|
961
|
+
proxyUrl?: string;
|
|
962
|
+
apiKey?: string;
|
|
963
|
+
projectId?: string;
|
|
964
|
+
environment?: string | undefined;
|
|
965
|
+
mode?: Mode;
|
|
966
|
+
isReady: boolean;
|
|
967
|
+
isLoading: boolean;
|
|
968
|
+
error: Error | null;
|
|
969
|
+
requiresVerification: boolean;
|
|
970
|
+
/** Sign out current user with optional cleanup */
|
|
971
|
+
signOut: (options?: SignOutOptionsTree) => Promise<void>;
|
|
972
|
+
}
|
|
973
|
+
type SignUpFormValuesTree = {
|
|
974
|
+
email: string;
|
|
975
|
+
password: string;
|
|
976
|
+
confirmPassword?: string;
|
|
977
|
+
displayName?: string;
|
|
978
|
+
};
|
|
979
|
+
type SignUpInitialValueTree = Partial<SignUpFormValuesTree>;
|
|
980
|
+
/**
|
|
981
|
+
* Props for SignIn component focusing on UI concerns
|
|
982
|
+
*/
|
|
983
|
+
type SignInPropsTree = {
|
|
984
|
+
/** Routing Path */
|
|
985
|
+
path?: string;
|
|
986
|
+
/** URL to navigate to after successfully sign-in */
|
|
987
|
+
forceRedirectUrl?: string | null;
|
|
988
|
+
/** Initial form values */
|
|
989
|
+
initialValue?: SignInInitialValueTree;
|
|
990
|
+
/** UI configuration */
|
|
991
|
+
ui?: SignInUIConfig;
|
|
992
|
+
/** Callbacks */
|
|
993
|
+
onError?: (error: AuthErrorTree) => void;
|
|
994
|
+
onSuccess?: (user: TernSecureUser | null) => void;
|
|
995
|
+
} & SignUpRedirectUrl;
|
|
996
|
+
/**
|
|
997
|
+
* Props for SignUp component focusing on UI concerns
|
|
998
|
+
*/
|
|
999
|
+
type SignUpPropsTree = {
|
|
1000
|
+
/** URL to navigate to after successfully sign-up */
|
|
1001
|
+
forceRedirectUrl?: string | null;
|
|
1002
|
+
/** Initial form values */
|
|
1003
|
+
initialValue?: SignUpInitialValueTree;
|
|
1004
|
+
/** UI configuration */
|
|
1005
|
+
ui?: SignUpUIConfig;
|
|
1006
|
+
/** Callbacks */
|
|
1007
|
+
onSubmit?: (values: SignUpFormValuesTree) => Promise<void>;
|
|
1008
|
+
onError?: (error: AuthErrorTree) => void;
|
|
1009
|
+
onSuccess?: (user: TernSecureUser | null) => void;
|
|
1010
|
+
} & SignInRedirectUrl;
|
|
1011
|
+
type SignInRedirectOptions = RedirectOptions;
|
|
1012
|
+
type SignUpRedirectOptions = RedirectOptions;
|
|
1013
|
+
|
|
1014
|
+
interface TernSecureApiErrorJSON {
|
|
1015
|
+
code: string;
|
|
1016
|
+
message: string;
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
type UseAuthReturn = {
|
|
1020
|
+
userId: string | null | undefined;
|
|
1021
|
+
isLoaded: boolean;
|
|
1022
|
+
isValid: boolean;
|
|
1023
|
+
isVerified: boolean;
|
|
1024
|
+
isAuthenticated: boolean;
|
|
1025
|
+
token: any | null;
|
|
1026
|
+
email: string | null;
|
|
1027
|
+
status: "loading" | "authenticated" | "unauthenticated" | "unverified";
|
|
1028
|
+
user?: TernSecureUser | null;
|
|
1029
|
+
signOut: SignOut;
|
|
1030
|
+
};
|
|
1031
|
+
type UseSignInReturn = {
|
|
1032
|
+
isLoaded: false;
|
|
1033
|
+
signIn: undefined;
|
|
1034
|
+
} | {
|
|
1035
|
+
isLoaded: true;
|
|
1036
|
+
signIn: SignInResource;
|
|
1037
|
+
};
|
|
1038
|
+
|
|
1039
|
+
type DomainOrProxyUrl = {
|
|
1040
|
+
proxyUrl?: never;
|
|
1041
|
+
domain?: string | ((url: URL) => string);
|
|
1042
|
+
} | {
|
|
1043
|
+
proxyUrl?: string | ((url: URL) => string);
|
|
1044
|
+
domain?: never;
|
|
1045
|
+
};
|
|
1046
|
+
|
|
1047
|
+
/**
|
|
1048
|
+
* Enables autocompletion for a union type, while keeping the ability to use any string
|
|
1049
|
+
* or type of `T`
|
|
1050
|
+
* @internal
|
|
1051
|
+
*/
|
|
1052
|
+
type Autocomplete<U extends T, T = string> = U | (T & Record<never, never>);
|
|
1053
|
+
|
|
1054
|
+
export { type ActiveSession, type AdminConfigValidationResult, type AfterSignOutUrl, type Appearance, type AuthActions, type AuthError, type AuthErrorCode, type AuthErrorResponse, type AuthErrorTree, type AuthProviderStatus, type Autocomplete, type BaseAuthUIConfig, type CheckAuthorizationFromSessionClaims, type CheckCustomClaims, type ConfigValidationResult, type CookieOptions, type CookieStore, DEFAULT_TERN_SECURE_STATE, type DecodedIdToken, type DomainOrProxyUrl, ERRORS, type ErrorCode, type ExpiredSession, type FirebaseClaims, type FirebaseState, type IdTokenResult, type InitialState, type InstanceType, type JWTPayload, type JWTProtectedHeader, type Jwt, type ListenerCallback, type ParsedToken, type PendingSession, type Persistence, type RedirectConfig, type RedirectOptions, type ResendEmailVerification, type ServerConfigValidationResult, type SessionParams, type SessionResult, type SessionStatus, type SharedSignInAuthObjectProperties, 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 SignOut, type SignOutOptions, type SignOutOptionsTree, type SignUpFormValuesTree, type SignUpInitialValue, type SignUpInitialValueTree, type SignUpProps, type SignUpPropsTree, type SignUpRedirectOptions, type SignUpRedirectUrl, type SignUpResource, type SignUpStatus, type SignUpUIConfig, type SignedInSession, type TernAuthEventPayload, type TernAuthListenerEvent, type TernAuthListenerEventPayload, type TernAuthSDK, type TernSecureAPIError, type TernSecureAdminConfig, type TernSecureApiErrorJSON, type TernSecureAuth, type TernSecureAuthFactory, type TernSecureAuthOptions, type TernSecureAuthProvider, type TernSecureAuthStatus, type TernSecureConfig, type TernSecureInstance, type TernSecureInstanceOld, type TernSecureInstanceTree, type TernSecureInstanceTreeOptions, type TernSecureInstanceTreeStatus, type TernSecureOptions, type TernSecureResources, type TernSecureSDK, type TernSecureServerConfig, type TernSecureSession, type TernSecureSessionTree, type TernSecureState, type TernSecureUser, type TernSecureUserData, type TernVerificationResult, type ThemeBorderRadius, type ThemeColors, type ThemeComponentStyles, type ThemeFonts, type ThemeSpacing, type UnsubscribeCallback, type UseAuthReturn, type UseSignInReturn, type UserInfo, type VerifiedTokens, isSignInResponse, isSignInResponseTree };
|