@vaiftech/auth 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.
- package/LICENSE +21 -0
- package/README.md +177 -0
- package/dist/chunk-JF55RF72.mjs +1 -0
- package/dist/client-28ISGmu6.d.mts +611 -0
- package/dist/client-28ISGmu6.d.ts +611 -0
- package/dist/index.d.mts +83 -0
- package/dist/index.d.ts +83 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -0
- package/dist/react.d.mts +158 -0
- package/dist/react.d.ts +158 -0
- package/dist/react.js +1 -0
- package/dist/react.mjs +1 -0
- package/package.json +71 -0
|
@@ -0,0 +1,611 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vaiftech/auth - Type definitions
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* User object returned from authentication endpoints
|
|
6
|
+
*/
|
|
7
|
+
interface User {
|
|
8
|
+
id: string;
|
|
9
|
+
email: string;
|
|
10
|
+
name?: string;
|
|
11
|
+
avatarUrl?: string;
|
|
12
|
+
phone?: string;
|
|
13
|
+
timezone?: string;
|
|
14
|
+
emailVerified: boolean;
|
|
15
|
+
phoneVerified: boolean;
|
|
16
|
+
mfaEnabled: boolean;
|
|
17
|
+
providers: OAuthProviderType[];
|
|
18
|
+
metadata?: Record<string, unknown>;
|
|
19
|
+
lastSignInAt?: string;
|
|
20
|
+
createdAt: string;
|
|
21
|
+
updatedAt?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Minimal user info for session
|
|
25
|
+
*/
|
|
26
|
+
interface UserInfo {
|
|
27
|
+
id: string;
|
|
28
|
+
email: string;
|
|
29
|
+
name?: string;
|
|
30
|
+
avatarUrl?: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Authentication session
|
|
34
|
+
*/
|
|
35
|
+
interface Session {
|
|
36
|
+
accessToken: string;
|
|
37
|
+
refreshToken?: string;
|
|
38
|
+
expiresAt: number;
|
|
39
|
+
expiresIn: number;
|
|
40
|
+
tokenType: 'bearer';
|
|
41
|
+
user: User;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Session info (for listing active sessions)
|
|
45
|
+
*/
|
|
46
|
+
interface SessionInfo {
|
|
47
|
+
id: string;
|
|
48
|
+
userId: string;
|
|
49
|
+
userAgent?: string;
|
|
50
|
+
ipAddress?: string;
|
|
51
|
+
location?: string;
|
|
52
|
+
lastActiveAt: string;
|
|
53
|
+
createdAt: string;
|
|
54
|
+
current: boolean;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Standard auth response
|
|
58
|
+
*/
|
|
59
|
+
interface AuthResponse {
|
|
60
|
+
session: Session;
|
|
61
|
+
user: User;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Token refresh response
|
|
65
|
+
*/
|
|
66
|
+
interface TokenRefreshResponse {
|
|
67
|
+
accessToken: string;
|
|
68
|
+
refreshToken?: string;
|
|
69
|
+
expiresAt: number;
|
|
70
|
+
expiresIn: number;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* MFA challenge response when MFA is required
|
|
74
|
+
*/
|
|
75
|
+
interface MFAChallenge {
|
|
76
|
+
mfaRequired: true;
|
|
77
|
+
mfaToken: string;
|
|
78
|
+
mfaMethods: MFAMethod[];
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Type guard for MFA challenge
|
|
82
|
+
*/
|
|
83
|
+
declare function isMFAChallenge(response: AuthResponse | MFAChallenge): response is MFAChallenge;
|
|
84
|
+
/**
|
|
85
|
+
* Sign up options
|
|
86
|
+
*/
|
|
87
|
+
interface SignUpOptions {
|
|
88
|
+
email: string;
|
|
89
|
+
password: string;
|
|
90
|
+
name?: string;
|
|
91
|
+
phone?: string;
|
|
92
|
+
metadata?: Record<string, unknown>;
|
|
93
|
+
redirectUrl?: string;
|
|
94
|
+
emailRedirectTo?: string;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Sign in options (email/password)
|
|
98
|
+
*/
|
|
99
|
+
interface SignInWithPasswordOptions {
|
|
100
|
+
email: string;
|
|
101
|
+
password: string;
|
|
102
|
+
mfaCode?: string;
|
|
103
|
+
rememberMe?: boolean;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Sign in with OAuth options
|
|
107
|
+
*/
|
|
108
|
+
interface SignInWithOAuthOptions {
|
|
109
|
+
provider: OAuthProviderType;
|
|
110
|
+
redirectTo?: string;
|
|
111
|
+
scopes?: string[];
|
|
112
|
+
queryParams?: Record<string, string>;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Sign in with magic link options
|
|
116
|
+
*/
|
|
117
|
+
interface SignInWithMagicLinkOptions {
|
|
118
|
+
email: string;
|
|
119
|
+
redirectTo?: string;
|
|
120
|
+
shouldCreateUser?: boolean;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Sign in with OTP (one-time password) options
|
|
124
|
+
*/
|
|
125
|
+
interface SignInWithOTPOptions {
|
|
126
|
+
email?: string;
|
|
127
|
+
phone?: string;
|
|
128
|
+
channel?: 'sms' | 'whatsapp' | 'email';
|
|
129
|
+
shouldCreateUser?: boolean;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Verify OTP options
|
|
133
|
+
*/
|
|
134
|
+
interface VerifyOTPOptions {
|
|
135
|
+
email?: string;
|
|
136
|
+
phone?: string;
|
|
137
|
+
token: string;
|
|
138
|
+
type: 'signup' | 'recovery' | 'email_change' | 'phone_change' | 'magiclink';
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Sign in with SSO options
|
|
142
|
+
*/
|
|
143
|
+
interface SignInWithSSOOptions {
|
|
144
|
+
domain?: string;
|
|
145
|
+
providerId?: string;
|
|
146
|
+
redirectTo?: string;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Anonymous sign in options
|
|
150
|
+
*/
|
|
151
|
+
interface SignInAnonymouslyOptions {
|
|
152
|
+
metadata?: Record<string, unknown>;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Password reset request options
|
|
156
|
+
*/
|
|
157
|
+
interface ResetPasswordOptions {
|
|
158
|
+
email: string;
|
|
159
|
+
redirectTo?: string;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Update password options
|
|
163
|
+
*/
|
|
164
|
+
interface UpdatePasswordOptions {
|
|
165
|
+
currentPassword?: string;
|
|
166
|
+
newPassword: string;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Set password options (for password recovery)
|
|
170
|
+
*/
|
|
171
|
+
interface SetPasswordOptions {
|
|
172
|
+
token: string;
|
|
173
|
+
password: string;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Update user options
|
|
177
|
+
*/
|
|
178
|
+
interface UpdateUserOptions {
|
|
179
|
+
email?: string;
|
|
180
|
+
phone?: string;
|
|
181
|
+
password?: string;
|
|
182
|
+
name?: string;
|
|
183
|
+
avatarUrl?: string;
|
|
184
|
+
metadata?: Record<string, unknown>;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Email change confirmation
|
|
188
|
+
*/
|
|
189
|
+
interface ConfirmEmailChangeOptions {
|
|
190
|
+
token: string;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Supported OAuth providers
|
|
194
|
+
*/
|
|
195
|
+
type OAuthProviderType = 'google' | 'github' | 'microsoft' | 'apple' | 'discord' | 'slack' | 'twitter' | 'facebook' | 'linkedin' | 'spotify' | 'twitch' | 'notion' | 'figma' | 'zoom';
|
|
196
|
+
/**
|
|
197
|
+
* OAuth response with redirect URL
|
|
198
|
+
*/
|
|
199
|
+
interface OAuthResponse {
|
|
200
|
+
url: string;
|
|
201
|
+
provider: OAuthProviderType;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* OAuth identity linked to user
|
|
205
|
+
*/
|
|
206
|
+
interface OAuthIdentity {
|
|
207
|
+
id: string;
|
|
208
|
+
provider: OAuthProviderType;
|
|
209
|
+
providerId: string;
|
|
210
|
+
email?: string;
|
|
211
|
+
name?: string;
|
|
212
|
+
avatarUrl?: string;
|
|
213
|
+
createdAt: string;
|
|
214
|
+
lastSignInAt?: string;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* MFA method types
|
|
218
|
+
*/
|
|
219
|
+
type MFAMethod = 'totp' | 'sms' | 'email';
|
|
220
|
+
/**
|
|
221
|
+
* MFA factor
|
|
222
|
+
*/
|
|
223
|
+
interface MFAFactor {
|
|
224
|
+
id: string;
|
|
225
|
+
type: MFAMethod;
|
|
226
|
+
friendlyName?: string;
|
|
227
|
+
status: 'unverified' | 'verified';
|
|
228
|
+
createdAt: string;
|
|
229
|
+
updatedAt: string;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* MFA setup response (TOTP)
|
|
233
|
+
*/
|
|
234
|
+
interface MFASetupResponse {
|
|
235
|
+
id: string;
|
|
236
|
+
type: MFAMethod;
|
|
237
|
+
totpUri?: string;
|
|
238
|
+
qrCode?: string;
|
|
239
|
+
secret?: string;
|
|
240
|
+
backupCodes?: string[];
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* MFA verify options
|
|
244
|
+
*/
|
|
245
|
+
interface MFAVerifyOptions {
|
|
246
|
+
factorId: string;
|
|
247
|
+
code: string;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* MFA challenge options
|
|
251
|
+
*/
|
|
252
|
+
interface MFAChallengeOptions {
|
|
253
|
+
factorId: string;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* MFA challenge response
|
|
257
|
+
*/
|
|
258
|
+
interface MFAChallengeResponse {
|
|
259
|
+
id: string;
|
|
260
|
+
expiresAt: number;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Auth event types
|
|
264
|
+
*/
|
|
265
|
+
type AuthEventType = 'SIGNED_IN' | 'SIGNED_OUT' | 'TOKEN_REFRESHED' | 'USER_UPDATED' | 'PASSWORD_RECOVERY' | 'MFA_CHALLENGE_VERIFIED' | 'INITIAL_SESSION';
|
|
266
|
+
/**
|
|
267
|
+
* Auth state change event
|
|
268
|
+
*/
|
|
269
|
+
interface AuthChangeEvent {
|
|
270
|
+
event: AuthEventType;
|
|
271
|
+
session: Session | null;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Auth state change callback
|
|
275
|
+
*/
|
|
276
|
+
type AuthStateChangeCallback = (event: AuthChangeEvent) => void;
|
|
277
|
+
/**
|
|
278
|
+
* Subscription to auth state changes
|
|
279
|
+
*/
|
|
280
|
+
interface AuthSubscription {
|
|
281
|
+
unsubscribe: () => void;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Storage adapter interface
|
|
285
|
+
*/
|
|
286
|
+
interface StorageAdapter {
|
|
287
|
+
getItem(key: string): string | null | Promise<string | null>;
|
|
288
|
+
setItem(key: string, value: string): void | Promise<void>;
|
|
289
|
+
removeItem(key: string): void | Promise<void>;
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Async storage adapter interface
|
|
293
|
+
*/
|
|
294
|
+
interface AsyncStorageAdapter {
|
|
295
|
+
getItem(key: string): Promise<string | null>;
|
|
296
|
+
setItem(key: string, value: string): Promise<void>;
|
|
297
|
+
removeItem(key: string): Promise<void>;
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Auth client configuration
|
|
301
|
+
*/
|
|
302
|
+
interface AuthClientConfig {
|
|
303
|
+
/**
|
|
304
|
+
* VAIF API URL
|
|
305
|
+
*/
|
|
306
|
+
url: string;
|
|
307
|
+
/**
|
|
308
|
+
* Project API key (publishable key)
|
|
309
|
+
*/
|
|
310
|
+
apiKey?: string;
|
|
311
|
+
/**
|
|
312
|
+
* Custom headers to include with every request
|
|
313
|
+
*/
|
|
314
|
+
headers?: Record<string, string>;
|
|
315
|
+
/**
|
|
316
|
+
* Storage adapter for session persistence
|
|
317
|
+
* @default localStorage (browser) or in-memory (Node.js)
|
|
318
|
+
*/
|
|
319
|
+
storage?: StorageAdapter | AsyncStorageAdapter;
|
|
320
|
+
/**
|
|
321
|
+
* Storage key prefix
|
|
322
|
+
* @default 'vaif.auth.'
|
|
323
|
+
*/
|
|
324
|
+
storageKey?: string;
|
|
325
|
+
/**
|
|
326
|
+
* Enable automatic token refresh
|
|
327
|
+
* @default true
|
|
328
|
+
*/
|
|
329
|
+
autoRefreshToken?: boolean;
|
|
330
|
+
/**
|
|
331
|
+
* Persist session to storage
|
|
332
|
+
* @default true
|
|
333
|
+
*/
|
|
334
|
+
persistSession?: boolean;
|
|
335
|
+
/**
|
|
336
|
+
* Detect session from URL (for OAuth callbacks)
|
|
337
|
+
* @default true
|
|
338
|
+
*/
|
|
339
|
+
detectSessionInUrl?: boolean;
|
|
340
|
+
/**
|
|
341
|
+
* Flow type for OAuth
|
|
342
|
+
* @default 'implicit'
|
|
343
|
+
*/
|
|
344
|
+
flowType?: 'implicit' | 'pkce';
|
|
345
|
+
/**
|
|
346
|
+
* Debug mode - logs auth events
|
|
347
|
+
* @default false
|
|
348
|
+
*/
|
|
349
|
+
debug?: boolean;
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Auth error codes
|
|
353
|
+
*/
|
|
354
|
+
type AuthErrorCode = 'invalid_credentials' | 'user_not_found' | 'user_already_exists' | 'email_not_verified' | 'phone_not_verified' | 'invalid_token' | 'token_expired' | 'session_expired' | 'mfa_required' | 'mfa_invalid' | 'oauth_error' | 'rate_limited' | 'weak_password' | 'invalid_email' | 'invalid_phone' | 'network_error' | 'unknown_error';
|
|
355
|
+
/**
|
|
356
|
+
* Auth error
|
|
357
|
+
*/
|
|
358
|
+
declare class AuthError extends Error {
|
|
359
|
+
code: AuthErrorCode;
|
|
360
|
+
status?: number;
|
|
361
|
+
details?: Record<string, unknown>;
|
|
362
|
+
constructor(message: string, code: AuthErrorCode, status?: number, details?: Record<string, unknown>);
|
|
363
|
+
static isAuthError(error: unknown): error is AuthError;
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Session expired error
|
|
367
|
+
*/
|
|
368
|
+
declare class SessionExpiredError extends AuthError {
|
|
369
|
+
constructor(message?: string);
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Invalid credentials error
|
|
373
|
+
*/
|
|
374
|
+
declare class InvalidCredentialsError extends AuthError {
|
|
375
|
+
constructor(message?: string);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* @vaiftech/auth - Main Auth Client
|
|
380
|
+
*
|
|
381
|
+
* Comprehensive authentication client with session management,
|
|
382
|
+
* automatic token refresh, and event-driven state updates.
|
|
383
|
+
*/
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* VAIF Auth Client
|
|
387
|
+
*
|
|
388
|
+
* @example
|
|
389
|
+
* ```typescript
|
|
390
|
+
* import { createAuthClient } from '@vaiftech/auth';
|
|
391
|
+
*
|
|
392
|
+
* const auth = createAuthClient({
|
|
393
|
+
* url: 'https://api.vaif.studio',
|
|
394
|
+
* apiKey: 'your-project-key',
|
|
395
|
+
* });
|
|
396
|
+
*
|
|
397
|
+
* // Sign up
|
|
398
|
+
* const { session, user } = await auth.signUp({
|
|
399
|
+
* email: 'user@example.com',
|
|
400
|
+
* password: 'secure-password',
|
|
401
|
+
* });
|
|
402
|
+
*
|
|
403
|
+
* // Sign in
|
|
404
|
+
* const { session, user } = await auth.signInWithPassword({
|
|
405
|
+
* email: 'user@example.com',
|
|
406
|
+
* password: 'secure-password',
|
|
407
|
+
* });
|
|
408
|
+
*
|
|
409
|
+
* // Listen to auth state changes
|
|
410
|
+
* auth.onAuthStateChange((event) => {
|
|
411
|
+
* console.log('Auth state changed:', event.event);
|
|
412
|
+
* if (event.session) {
|
|
413
|
+
* console.log('User:', event.session.user);
|
|
414
|
+
* }
|
|
415
|
+
* });
|
|
416
|
+
* ```
|
|
417
|
+
*/
|
|
418
|
+
declare class VaifAuthClient {
|
|
419
|
+
private config;
|
|
420
|
+
private storage;
|
|
421
|
+
private refreshTimer;
|
|
422
|
+
private listeners;
|
|
423
|
+
private initialized;
|
|
424
|
+
private initPromise;
|
|
425
|
+
private currentSession;
|
|
426
|
+
constructor(config: AuthClientConfig);
|
|
427
|
+
/**
|
|
428
|
+
* Initialize the auth client
|
|
429
|
+
* Loads session from storage and sets up auto-refresh
|
|
430
|
+
*/
|
|
431
|
+
initialize(): Promise<Session | null>;
|
|
432
|
+
private _initialize;
|
|
433
|
+
/**
|
|
434
|
+
* Get the current session
|
|
435
|
+
*/
|
|
436
|
+
getSession(): Promise<Session | null>;
|
|
437
|
+
/**
|
|
438
|
+
* Get the current user
|
|
439
|
+
*/
|
|
440
|
+
getUser(): Promise<User | null>;
|
|
441
|
+
/**
|
|
442
|
+
* Set session manually (useful for SSR)
|
|
443
|
+
*/
|
|
444
|
+
setSession(accessToken: string, refreshToken?: string): Promise<AuthResponse>;
|
|
445
|
+
/**
|
|
446
|
+
* Refresh the current session
|
|
447
|
+
*/
|
|
448
|
+
refreshSession(): Promise<Session | null>;
|
|
449
|
+
/**
|
|
450
|
+
* Sign up a new user with email and password
|
|
451
|
+
*/
|
|
452
|
+
signUp(options: SignUpOptions): Promise<AuthResponse | MFAChallenge>;
|
|
453
|
+
/**
|
|
454
|
+
* Sign in with email and password
|
|
455
|
+
*/
|
|
456
|
+
signInWithPassword(options: SignInWithPasswordOptions): Promise<AuthResponse | MFAChallenge>;
|
|
457
|
+
/**
|
|
458
|
+
* Sign in with OAuth provider
|
|
459
|
+
*/
|
|
460
|
+
signInWithOAuth(options: SignInWithOAuthOptions): Promise<OAuthResponse>;
|
|
461
|
+
/**
|
|
462
|
+
* Sign in with magic link (passwordless email)
|
|
463
|
+
*/
|
|
464
|
+
signInWithMagicLink(options: SignInWithMagicLinkOptions): Promise<{
|
|
465
|
+
ok: boolean;
|
|
466
|
+
}>;
|
|
467
|
+
/**
|
|
468
|
+
* Sign in with OTP (one-time password)
|
|
469
|
+
*/
|
|
470
|
+
signInWithOTP(options: SignInWithOTPOptions): Promise<{
|
|
471
|
+
ok: boolean;
|
|
472
|
+
}>;
|
|
473
|
+
/**
|
|
474
|
+
* Verify OTP code
|
|
475
|
+
*/
|
|
476
|
+
verifyOTP(options: VerifyOTPOptions): Promise<AuthResponse>;
|
|
477
|
+
/**
|
|
478
|
+
* Sign in anonymously
|
|
479
|
+
*/
|
|
480
|
+
signInAnonymously(options?: SignInAnonymouslyOptions): Promise<AuthResponse>;
|
|
481
|
+
/**
|
|
482
|
+
* Sign out the current user
|
|
483
|
+
*/
|
|
484
|
+
signOut(): Promise<void>;
|
|
485
|
+
/**
|
|
486
|
+
* Sign out from all devices
|
|
487
|
+
*/
|
|
488
|
+
signOutAll(): Promise<void>;
|
|
489
|
+
/**
|
|
490
|
+
* Request password reset email
|
|
491
|
+
*/
|
|
492
|
+
resetPasswordForEmail(options: ResetPasswordOptions): Promise<{
|
|
493
|
+
ok: boolean;
|
|
494
|
+
}>;
|
|
495
|
+
/**
|
|
496
|
+
* Update password (requires current session)
|
|
497
|
+
*/
|
|
498
|
+
updatePassword(options: UpdatePasswordOptions): Promise<{
|
|
499
|
+
ok: boolean;
|
|
500
|
+
}>;
|
|
501
|
+
/**
|
|
502
|
+
* Set new password with recovery token
|
|
503
|
+
*/
|
|
504
|
+
setPassword(options: SetPasswordOptions): Promise<AuthResponse>;
|
|
505
|
+
/**
|
|
506
|
+
* Update current user
|
|
507
|
+
*/
|
|
508
|
+
updateUser(options: UpdateUserOptions): Promise<User>;
|
|
509
|
+
/**
|
|
510
|
+
* Get user identities (linked OAuth providers)
|
|
511
|
+
*/
|
|
512
|
+
getUserIdentities(): Promise<OAuthIdentity[]>;
|
|
513
|
+
/**
|
|
514
|
+
* Link OAuth provider to current user
|
|
515
|
+
*/
|
|
516
|
+
linkIdentity(provider: OAuthProviderType, options?: {
|
|
517
|
+
redirectTo?: string;
|
|
518
|
+
}): Promise<OAuthResponse>;
|
|
519
|
+
/**
|
|
520
|
+
* Unlink OAuth provider from current user
|
|
521
|
+
*/
|
|
522
|
+
unlinkIdentity(provider: OAuthProviderType): Promise<{
|
|
523
|
+
ok: boolean;
|
|
524
|
+
}>;
|
|
525
|
+
/**
|
|
526
|
+
* List enrolled MFA factors
|
|
527
|
+
*/
|
|
528
|
+
listMFAFactors(): Promise<MFAFactor[]>;
|
|
529
|
+
/**
|
|
530
|
+
* Enroll a new MFA factor
|
|
531
|
+
*/
|
|
532
|
+
enrollMFA(options: {
|
|
533
|
+
type: 'totp' | 'sms' | 'email';
|
|
534
|
+
friendlyName?: string;
|
|
535
|
+
}): Promise<MFASetupResponse>;
|
|
536
|
+
/**
|
|
537
|
+
* Verify and enable MFA factor
|
|
538
|
+
*/
|
|
539
|
+
verifyMFA(options: MFAVerifyOptions): Promise<{
|
|
540
|
+
ok: boolean;
|
|
541
|
+
backupCodes?: string[];
|
|
542
|
+
}>;
|
|
543
|
+
/**
|
|
544
|
+
* Create MFA challenge for verification
|
|
545
|
+
*/
|
|
546
|
+
challengeMFA(options: MFAChallengeOptions): Promise<MFAChallengeResponse>;
|
|
547
|
+
/**
|
|
548
|
+
* Verify MFA during login
|
|
549
|
+
*/
|
|
550
|
+
verifyMFAChallenge(mfaToken: string, code: string): Promise<AuthResponse>;
|
|
551
|
+
/**
|
|
552
|
+
* Unenroll MFA factor
|
|
553
|
+
*/
|
|
554
|
+
unenrollMFA(factorId: string, code: string): Promise<{
|
|
555
|
+
ok: boolean;
|
|
556
|
+
}>;
|
|
557
|
+
/**
|
|
558
|
+
* Regenerate MFA backup codes
|
|
559
|
+
*/
|
|
560
|
+
regenerateBackupCodes(): Promise<{
|
|
561
|
+
backupCodes: string[];
|
|
562
|
+
}>;
|
|
563
|
+
/**
|
|
564
|
+
* List all active sessions
|
|
565
|
+
*/
|
|
566
|
+
listSessions(): Promise<SessionInfo[]>;
|
|
567
|
+
/**
|
|
568
|
+
* Revoke a specific session
|
|
569
|
+
*/
|
|
570
|
+
revokeSession(sessionId: string): Promise<{
|
|
571
|
+
ok: boolean;
|
|
572
|
+
}>;
|
|
573
|
+
/**
|
|
574
|
+
* Revoke all sessions except current
|
|
575
|
+
*/
|
|
576
|
+
revokeOtherSessions(): Promise<{
|
|
577
|
+
ok: boolean;
|
|
578
|
+
}>;
|
|
579
|
+
/**
|
|
580
|
+
* Resend email verification
|
|
581
|
+
*/
|
|
582
|
+
resendEmailVerification(options?: {
|
|
583
|
+
redirectTo?: string;
|
|
584
|
+
}): Promise<{
|
|
585
|
+
ok: boolean;
|
|
586
|
+
}>;
|
|
587
|
+
/**
|
|
588
|
+
* Verify email with token
|
|
589
|
+
*/
|
|
590
|
+
verifyEmail(token: string): Promise<AuthResponse>;
|
|
591
|
+
/**
|
|
592
|
+
* Subscribe to auth state changes
|
|
593
|
+
*/
|
|
594
|
+
onAuthStateChange(callback: AuthStateChangeCallback): AuthSubscription;
|
|
595
|
+
private _fetch;
|
|
596
|
+
private _fetchUser;
|
|
597
|
+
private _refreshToken;
|
|
598
|
+
private _handleUrlSession;
|
|
599
|
+
private _persistSession;
|
|
600
|
+
private _setupAutoRefresh;
|
|
601
|
+
private _clearRefreshTimer;
|
|
602
|
+
private _notifyListeners;
|
|
603
|
+
private _mapErrorCode;
|
|
604
|
+
private _log;
|
|
605
|
+
}
|
|
606
|
+
/**
|
|
607
|
+
* Create a new VAIF Auth client
|
|
608
|
+
*/
|
|
609
|
+
declare function createAuthClient(config: AuthClientConfig): VaifAuthClient;
|
|
610
|
+
|
|
611
|
+
export { type AsyncStorageAdapter as A, type AuthStateChangeCallback as B, type ConfirmEmailChangeOptions as C, type AuthSubscription as D, type AuthClientConfig as E, type AuthErrorCode as F, AuthError as G, SessionExpiredError as H, InvalidCredentialsError as I, isMFAChallenge as J, type MFAChallenge as M, type OAuthProviderType as O, type ResetPasswordOptions as R, type StorageAdapter as S, type TokenRefreshResponse as T, type User as U, VaifAuthClient as V, type Session as a, type UserInfo as b, createAuthClient as c, type SessionInfo as d, type AuthResponse as e, type SignUpOptions as f, type SignInWithPasswordOptions as g, type SignInWithOAuthOptions as h, type SignInWithMagicLinkOptions as i, type SignInWithOTPOptions as j, type VerifyOTPOptions as k, type SignInWithSSOOptions as l, type SignInAnonymouslyOptions as m, type UpdatePasswordOptions as n, type SetPasswordOptions as o, type UpdateUserOptions as p, type OAuthResponse as q, type OAuthIdentity as r, type MFAMethod as s, type MFAFactor as t, type MFASetupResponse as u, type MFAVerifyOptions as v, type MFAChallengeOptions as w, type MFAChallengeResponse as x, type AuthEventType as y, type AuthChangeEvent as z };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { S as StorageAdapter, A as AsyncStorageAdapter, a as Session } from './client-28ISGmu6.mjs';
|
|
2
|
+
export { z as AuthChangeEvent, E as AuthClientConfig, G as AuthError, F as AuthErrorCode, y as AuthEventType, e as AuthResponse, B as AuthStateChangeCallback, D as AuthSubscription, C as ConfirmEmailChangeOptions, I as InvalidCredentialsError, M as MFAChallenge, w as MFAChallengeOptions, x as MFAChallengeResponse, t as MFAFactor, s as MFAMethod, u as MFASetupResponse, v as MFAVerifyOptions, r as OAuthIdentity, O as OAuthProviderType, q as OAuthResponse, R as ResetPasswordOptions, H as SessionExpiredError, d as SessionInfo, o as SetPasswordOptions, m as SignInAnonymouslyOptions, i as SignInWithMagicLinkOptions, h as SignInWithOAuthOptions, j as SignInWithOTPOptions, g as SignInWithPasswordOptions, l as SignInWithSSOOptions, f as SignUpOptions, T as TokenRefreshResponse, n as UpdatePasswordOptions, p as UpdateUserOptions, U as User, b as UserInfo, V as VaifAuthClient, k as VerifyOTPOptions, c as createAuthClient, J as isMFAChallenge } from './client-28ISGmu6.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @vaiftech/auth - Storage utilities
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Check if running in browser environment
|
|
10
|
+
*/
|
|
11
|
+
declare function isBrowser(): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* In-memory storage fallback
|
|
14
|
+
*/
|
|
15
|
+
declare class MemoryStorage implements StorageAdapter {
|
|
16
|
+
private storage;
|
|
17
|
+
getItem(key: string): string | null;
|
|
18
|
+
setItem(key: string, value: string): void;
|
|
19
|
+
removeItem(key: string): void;
|
|
20
|
+
clear(): void;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Local storage adapter
|
|
24
|
+
*/
|
|
25
|
+
declare class LocalStorageAdapter implements StorageAdapter {
|
|
26
|
+
getItem(key: string): string | null;
|
|
27
|
+
setItem(key: string, value: string): void;
|
|
28
|
+
removeItem(key: string): void;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Session storage adapter
|
|
32
|
+
*/
|
|
33
|
+
declare class SessionStorageAdapter implements StorageAdapter {
|
|
34
|
+
getItem(key: string): string | null;
|
|
35
|
+
setItem(key: string, value: string): void;
|
|
36
|
+
removeItem(key: string): void;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Cookie storage options
|
|
40
|
+
*/
|
|
41
|
+
interface CookieStorageOptions {
|
|
42
|
+
secure?: boolean;
|
|
43
|
+
sameSite?: 'strict' | 'lax' | 'none';
|
|
44
|
+
path?: string;
|
|
45
|
+
domain?: string;
|
|
46
|
+
maxAge?: number;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Cookie storage adapter with secure defaults
|
|
50
|
+
*/
|
|
51
|
+
declare class CookieStorageAdapter implements StorageAdapter {
|
|
52
|
+
private options;
|
|
53
|
+
constructor(options?: CookieStorageOptions);
|
|
54
|
+
getItem(key: string): string | null;
|
|
55
|
+
setItem(key: string, value: string): void;
|
|
56
|
+
removeItem(key: string): void;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Get default storage adapter
|
|
60
|
+
*/
|
|
61
|
+
declare function getDefaultStorage(): StorageAdapter;
|
|
62
|
+
/**
|
|
63
|
+
* Storage helper with session serialization
|
|
64
|
+
*/
|
|
65
|
+
declare class SessionStorage {
|
|
66
|
+
private adapter;
|
|
67
|
+
private keyPrefix;
|
|
68
|
+
constructor(adapter: StorageAdapter | AsyncStorageAdapter, keyPrefix?: string);
|
|
69
|
+
private key;
|
|
70
|
+
getSession(): Promise<Session | null>;
|
|
71
|
+
setSession(session: Session): Promise<void>;
|
|
72
|
+
removeSession(): Promise<void>;
|
|
73
|
+
getRefreshToken(): Promise<string | null>;
|
|
74
|
+
setRefreshToken(token: string): Promise<void>;
|
|
75
|
+
removeRefreshToken(): Promise<void>;
|
|
76
|
+
clear(): Promise<void>;
|
|
77
|
+
}
|
|
78
|
+
declare const memoryStorage: MemoryStorage;
|
|
79
|
+
declare const localStorage: MemoryStorage | LocalStorageAdapter;
|
|
80
|
+
declare const sessionStorage: MemoryStorage | SessionStorageAdapter;
|
|
81
|
+
declare const cookieStorage: (options?: CookieStorageOptions) => CookieStorageAdapter;
|
|
82
|
+
|
|
83
|
+
export { AsyncStorageAdapter, type CookieStorageOptions, Session, SessionStorage, StorageAdapter, cookieStorage, getDefaultStorage, isBrowser, localStorage, memoryStorage, sessionStorage };
|