@authsome/ui-core 0.1.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/dist/index.mjs ADDED
@@ -0,0 +1,1415 @@
1
+ // src/types/auth.ts
2
+ var AuthState = /* @__PURE__ */ ((AuthState2) => {
3
+ AuthState2["AUTHENTICATED"] = "authenticated";
4
+ AuthState2["UNAUTHENTICATED"] = "unauthenticated";
5
+ AuthState2["LOADING"] = "loading";
6
+ AuthState2["ERROR"] = "error";
7
+ return AuthState2;
8
+ })(AuthState || {});
9
+ var AuthErrorType = /* @__PURE__ */ ((AuthErrorType2) => {
10
+ AuthErrorType2["INVALID_CREDENTIALS"] = "invalid_credentials";
11
+ AuthErrorType2["USER_NOT_FOUND"] = "user_not_found";
12
+ AuthErrorType2["USER_ALREADY_EXISTS"] = "user_already_exists";
13
+ AuthErrorType2["INVALID_TOKEN"] = "invalid_token";
14
+ AuthErrorType2["TOKEN_EXPIRED"] = "token_expired";
15
+ AuthErrorType2["NETWORK_ERROR"] = "network_error";
16
+ AuthErrorType2["VALIDATION_ERROR"] = "validation_error";
17
+ AuthErrorType2["MFA_REQUIRED"] = "mfa_required";
18
+ AuthErrorType2["EMAIL_NOT_VERIFIED"] = "email_not_verified";
19
+ AuthErrorType2["PHONE_NOT_VERIFIED"] = "phone_not_verified";
20
+ AuthErrorType2["RATE_LIMIT_EXCEEDED"] = "rate_limit_exceeded";
21
+ AuthErrorType2["UNKNOWN_ERROR"] = "unknown_error";
22
+ return AuthErrorType2;
23
+ })(AuthErrorType || {});
24
+ var AuthError = class _AuthError extends Error {
25
+ constructor(message, type = "unknown_error" /* UNKNOWN_ERROR */, options) {
26
+ super(message);
27
+ this.name = "AuthError";
28
+ this.type = type;
29
+ this.details = options?.details;
30
+ this.code = options?.code;
31
+ this.originalError = options?.originalError;
32
+ if (Error.captureStackTrace) {
33
+ Error.captureStackTrace(this, _AuthError);
34
+ }
35
+ }
36
+ };
37
+ var OAuthProvider = /* @__PURE__ */ ((OAuthProvider2) => {
38
+ OAuthProvider2["GOOGLE"] = "google";
39
+ OAuthProvider2["GITHUB"] = "github";
40
+ OAuthProvider2["FACEBOOK"] = "facebook";
41
+ OAuthProvider2["TWITTER"] = "twitter";
42
+ OAuthProvider2["MICROSOFT"] = "microsoft";
43
+ OAuthProvider2["APPLE"] = "apple";
44
+ OAuthProvider2["LINKEDIN"] = "linkedin";
45
+ OAuthProvider2["DISCORD"] = "discord";
46
+ return OAuthProvider2;
47
+ })(OAuthProvider || {});
48
+ var TwoFactorMethod = /* @__PURE__ */ ((TwoFactorMethod2) => {
49
+ TwoFactorMethod2["TOTP"] = "totp";
50
+ TwoFactorMethod2["SMS"] = "sms";
51
+ TwoFactorMethod2["EMAIL"] = "email";
52
+ TwoFactorMethod2["BACKUP_CODE"] = "backup_code";
53
+ return TwoFactorMethod2;
54
+ })(TwoFactorMethod || {});
55
+
56
+ // src/types/storage.ts
57
+ var LocalStorageAdapter = class {
58
+ getItem(key) {
59
+ if (typeof window === "undefined") return null;
60
+ return window.localStorage.getItem(key);
61
+ }
62
+ setItem(key, value) {
63
+ if (typeof window === "undefined") return;
64
+ window.localStorage.setItem(key, value);
65
+ }
66
+ removeItem(key) {
67
+ if (typeof window === "undefined") return;
68
+ window.localStorage.removeItem(key);
69
+ }
70
+ clear() {
71
+ if (typeof window === "undefined") return;
72
+ window.localStorage.clear();
73
+ }
74
+ };
75
+ var SessionStorageAdapter = class {
76
+ getItem(key) {
77
+ if (typeof window === "undefined") return null;
78
+ return window.sessionStorage.getItem(key);
79
+ }
80
+ setItem(key, value) {
81
+ if (typeof window === "undefined") return;
82
+ window.sessionStorage.setItem(key, value);
83
+ }
84
+ removeItem(key) {
85
+ if (typeof window === "undefined") return;
86
+ window.sessionStorage.removeItem(key);
87
+ }
88
+ clear() {
89
+ if (typeof window === "undefined") return;
90
+ window.sessionStorage.clear();
91
+ }
92
+ };
93
+ var MemoryStorageAdapter = class {
94
+ constructor() {
95
+ this.store = /* @__PURE__ */ new Map();
96
+ }
97
+ getItem(key) {
98
+ return this.store.get(key) ?? null;
99
+ }
100
+ setItem(key, value) {
101
+ this.store.set(key, value);
102
+ }
103
+ removeItem(key) {
104
+ this.store.delete(key);
105
+ }
106
+ clear() {
107
+ this.store.clear();
108
+ }
109
+ };
110
+
111
+ // src/types/observable.ts
112
+ var Observable = class {
113
+ constructor(initialValue) {
114
+ this.listeners = /* @__PURE__ */ new Set();
115
+ this.value = initialValue;
116
+ }
117
+ /**
118
+ * Get current value
119
+ */
120
+ getValue() {
121
+ return this.value;
122
+ }
123
+ /**
124
+ * Set new value and notify listeners
125
+ */
126
+ setValue(newValue) {
127
+ if (this.value !== newValue) {
128
+ this.value = newValue;
129
+ this.notify();
130
+ }
131
+ }
132
+ /**
133
+ * Update value with a function
134
+ */
135
+ update(updater) {
136
+ this.setValue(updater(this.value));
137
+ }
138
+ /**
139
+ * Subscribe to value changes
140
+ */
141
+ subscribe(listener) {
142
+ this.listeners.add(listener);
143
+ listener(this.value);
144
+ return () => {
145
+ this.listeners.delete(listener);
146
+ };
147
+ }
148
+ /**
149
+ * Notify all listeners
150
+ */
151
+ notify() {
152
+ this.listeners.forEach((listener) => listener(this.value));
153
+ }
154
+ /**
155
+ * Clear all listeners
156
+ */
157
+ clearListeners() {
158
+ this.listeners.clear();
159
+ }
160
+ /**
161
+ * Get number of listeners
162
+ */
163
+ getListenerCount() {
164
+ return this.listeners.size;
165
+ }
166
+ };
167
+
168
+ // src/utils/errors.ts
169
+ function createAuthError(type, message, details, code) {
170
+ return new AuthError(message, type, { details, code });
171
+ }
172
+ function isAuthError(error) {
173
+ return error instanceof AuthError;
174
+ }
175
+ function toAuthError(error) {
176
+ if (isAuthError(error)) {
177
+ return error;
178
+ }
179
+ if (error instanceof Error) {
180
+ return new AuthError(error.message, "unknown_error" /* UNKNOWN_ERROR */, {
181
+ details: {
182
+ originalError: error.name,
183
+ stack: error.stack
184
+ }
185
+ });
186
+ }
187
+ if (typeof error === "string") {
188
+ return new AuthError(error, "unknown_error" /* UNKNOWN_ERROR */);
189
+ }
190
+ return new AuthError(
191
+ "An unknown error occurred",
192
+ "unknown_error" /* UNKNOWN_ERROR */,
193
+ { details: { error } }
194
+ );
195
+ }
196
+ function isNetworkError(error) {
197
+ if (error instanceof Error) {
198
+ return error.name === "NetworkError" || error.message.includes("network") || error.message.includes("fetch");
199
+ }
200
+ return false;
201
+ }
202
+ function isUnauthenticatedError(error) {
203
+ if (isAuthError(error)) {
204
+ return error.type === "invalid_token" /* INVALID_TOKEN */ || error.type === "token_expired" /* TOKEN_EXPIRED */;
205
+ }
206
+ return false;
207
+ }
208
+ function isMFARequiredError(error) {
209
+ if (isAuthError(error)) {
210
+ return error.type === "mfa_required" /* MFA_REQUIRED */;
211
+ }
212
+ return false;
213
+ }
214
+
215
+ // src/utils/validation.ts
216
+ var EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
217
+ var PHONE_REGEX = /^\+?[1-9]\d{1,14}$/;
218
+ var USERNAME_REGEX = /^[a-zA-Z0-9_-]{3,30}$/;
219
+ function validateEmail(email) {
220
+ if (!email) {
221
+ return { field: "email", message: "Email is required" };
222
+ }
223
+ if (!EMAIL_REGEX.test(email)) {
224
+ return { field: "email", message: "Invalid email address" };
225
+ }
226
+ return null;
227
+ }
228
+ function validatePassword(password, options = {}) {
229
+ const {
230
+ minLength = 8,
231
+ requireUppercase = true,
232
+ requireLowercase = true,
233
+ requireNumber = true,
234
+ requireSpecial = false
235
+ } = options;
236
+ if (!password) {
237
+ return { field: "password", message: "Password is required" };
238
+ }
239
+ if (password.length < minLength) {
240
+ return {
241
+ field: "password",
242
+ message: `Password must be at least ${minLength} characters`
243
+ };
244
+ }
245
+ if (requireUppercase && !/[A-Z]/.test(password)) {
246
+ return {
247
+ field: "password",
248
+ message: "Password must contain at least one uppercase letter"
249
+ };
250
+ }
251
+ if (requireLowercase && !/[a-z]/.test(password)) {
252
+ return {
253
+ field: "password",
254
+ message: "Password must contain at least one lowercase letter"
255
+ };
256
+ }
257
+ if (requireNumber && !/\d/.test(password)) {
258
+ return { field: "password", message: "Password must contain at least one number" };
259
+ }
260
+ if (requireSpecial && !/[!@#$%^&*(),.?":{}|<>]/.test(password)) {
261
+ return {
262
+ field: "password",
263
+ message: "Password must contain at least one special character"
264
+ };
265
+ }
266
+ return null;
267
+ }
268
+ function validatePhone(phone) {
269
+ if (!phone) {
270
+ return { field: "phone", message: "Phone number is required" };
271
+ }
272
+ if (!PHONE_REGEX.test(phone)) {
273
+ return {
274
+ field: "phone",
275
+ message: "Invalid phone number. Use international format (+1234567890)"
276
+ };
277
+ }
278
+ return null;
279
+ }
280
+ function validateUsername(username) {
281
+ if (!username) {
282
+ return { field: "username", message: "Username is required" };
283
+ }
284
+ if (!USERNAME_REGEX.test(username)) {
285
+ return {
286
+ field: "username",
287
+ message: "Username must be 3-30 characters and contain only letters, numbers, underscores, and hyphens"
288
+ };
289
+ }
290
+ return null;
291
+ }
292
+ function validate2FACode(code) {
293
+ if (!code) {
294
+ return { field: "code", message: "Verification code is required" };
295
+ }
296
+ if (!/^\d{6}$/.test(code)) {
297
+ return { field: "code", message: "Code must be 6 digits" };
298
+ }
299
+ return null;
300
+ }
301
+ function validateRequired(value, fieldName) {
302
+ if (!value || typeof value === "string" && !value.trim()) {
303
+ return { field: fieldName, message: `${fieldName} is required` };
304
+ }
305
+ return null;
306
+ }
307
+
308
+ // src/utils/tokens.ts
309
+ var TOKEN_KEY = "authsome_token";
310
+ var REFRESH_TOKEN_KEY = "authsome_refresh_token";
311
+ var TokenManager = class {
312
+ constructor(storage = new LocalStorageAdapter()) {
313
+ this.storage = storage;
314
+ }
315
+ /**
316
+ * Get access token
317
+ */
318
+ async getToken() {
319
+ return await Promise.resolve(this.storage.getItem(TOKEN_KEY));
320
+ }
321
+ /**
322
+ * Set access token
323
+ */
324
+ async setToken(token) {
325
+ await Promise.resolve(this.storage.setItem(TOKEN_KEY, token));
326
+ }
327
+ /**
328
+ * Remove access token
329
+ */
330
+ async removeToken() {
331
+ await Promise.resolve(this.storage.removeItem(TOKEN_KEY));
332
+ }
333
+ /**
334
+ * Get refresh token
335
+ */
336
+ async getRefreshToken() {
337
+ return await Promise.resolve(this.storage.getItem(REFRESH_TOKEN_KEY));
338
+ }
339
+ /**
340
+ * Set refresh token
341
+ */
342
+ async setRefreshToken(token) {
343
+ await Promise.resolve(this.storage.setItem(REFRESH_TOKEN_KEY, token));
344
+ }
345
+ /**
346
+ * Remove refresh token
347
+ */
348
+ async removeRefreshToken() {
349
+ await Promise.resolve(this.storage.removeItem(REFRESH_TOKEN_KEY));
350
+ }
351
+ /**
352
+ * Clear all tokens
353
+ */
354
+ async clearTokens() {
355
+ await this.removeToken();
356
+ await this.removeRefreshToken();
357
+ }
358
+ /**
359
+ * Check if token is expired
360
+ */
361
+ isTokenExpired(token) {
362
+ try {
363
+ const payload = this.decodeToken(token);
364
+ if (!payload.exp) return false;
365
+ const expiresAt = payload.exp * 1e3;
366
+ const now = Date.now();
367
+ return expiresAt - now < 6e4;
368
+ } catch {
369
+ return true;
370
+ }
371
+ }
372
+ /**
373
+ * Decode JWT token (without verification)
374
+ */
375
+ decodeToken(token) {
376
+ const parts = token.split(".");
377
+ if (parts.length !== 3) {
378
+ throw new Error("Invalid token format");
379
+ }
380
+ const payload = parts[1];
381
+ const decoded = atob(payload);
382
+ return JSON.parse(decoded);
383
+ }
384
+ };
385
+
386
+ // src/adapters/base-provider.ts
387
+ var BaseAuthProvider = class {
388
+ constructor() {
389
+ this.config = {};
390
+ this.initialized = false;
391
+ }
392
+ /**
393
+ * Initialize the provider
394
+ */
395
+ async initialize(config) {
396
+ this.config = config;
397
+ this.initialized = true;
398
+ }
399
+ /**
400
+ * Ensure provider is initialized
401
+ */
402
+ ensureInitialized() {
403
+ if (!this.initialized) {
404
+ throw new Error(`Provider ${this.name} is not initialized`);
405
+ }
406
+ }
407
+ /**
408
+ * Make HTTP request
409
+ */
410
+ async request(url, options = {}) {
411
+ const response = await fetch(url, {
412
+ ...options,
413
+ headers: {
414
+ "Content-Type": "application/json",
415
+ ...options.headers
416
+ }
417
+ });
418
+ if (!response.ok) {
419
+ const error = await response.json().catch(() => ({
420
+ message: response.statusText
421
+ }));
422
+ throw error;
423
+ }
424
+ return response.json();
425
+ }
426
+ /**
427
+ * Normalize error to AuthError
428
+ */
429
+ normalizeError(error) {
430
+ return toAuthError(error);
431
+ }
432
+ };
433
+
434
+ // src/client.ts
435
+ var AuthClient = class {
436
+ constructor(config) {
437
+ this.provider = config.provider;
438
+ this.autoRefresh = config.autoRefresh ?? true;
439
+ this.refreshInterval = config.refreshInterval ?? 5 * 60 * 1e3;
440
+ this.state = new Observable({
441
+ state: "loading" /* LOADING */,
442
+ user: null,
443
+ session: null,
444
+ error: null,
445
+ isAuthenticated: false,
446
+ isLoading: true
447
+ });
448
+ }
449
+ /**
450
+ * Initialize the auth client
451
+ */
452
+ async initialize() {
453
+ try {
454
+ const user = await this.provider.getCurrentUser();
455
+ const session = await this.provider.getCurrentSession();
456
+ if (user && session) {
457
+ this.updateState({
458
+ state: "authenticated" /* AUTHENTICATED */,
459
+ user,
460
+ session,
461
+ error: null,
462
+ isAuthenticated: true,
463
+ isLoading: false
464
+ });
465
+ if (this.autoRefresh) {
466
+ this.startAutoRefresh();
467
+ }
468
+ } else {
469
+ this.updateState({
470
+ state: "unauthenticated" /* UNAUTHENTICATED */,
471
+ user: null,
472
+ session: null,
473
+ error: null,
474
+ isAuthenticated: false,
475
+ isLoading: false
476
+ });
477
+ }
478
+ } catch (error) {
479
+ this.handleError(error);
480
+ }
481
+ }
482
+ /**
483
+ * Sign in with credentials
484
+ */
485
+ async signIn(request) {
486
+ try {
487
+ this.setLoading();
488
+ const response = await this.provider.signIn(request);
489
+ if (response.requiresTwoFactor) {
490
+ this.updateState({
491
+ state: "unauthenticated" /* UNAUTHENTICATED */,
492
+ user: response.user,
493
+ session: null,
494
+ error: null,
495
+ isAuthenticated: false,
496
+ isLoading: false
497
+ });
498
+ return;
499
+ }
500
+ this.updateState({
501
+ state: "authenticated" /* AUTHENTICATED */,
502
+ user: response.user,
503
+ session: response.session,
504
+ error: null,
505
+ isAuthenticated: true,
506
+ isLoading: false
507
+ });
508
+ if (this.autoRefresh) {
509
+ this.startAutoRefresh();
510
+ }
511
+ } catch (error) {
512
+ this.handleError(error);
513
+ }
514
+ }
515
+ /**
516
+ * Sign up with credentials
517
+ */
518
+ async signUp(request) {
519
+ try {
520
+ this.setLoading();
521
+ const response = await this.provider.signUp(request);
522
+ this.updateState({
523
+ state: "authenticated" /* AUTHENTICATED */,
524
+ user: response.user,
525
+ session: response.session,
526
+ error: null,
527
+ isAuthenticated: true,
528
+ isLoading: false
529
+ });
530
+ if (this.autoRefresh) {
531
+ this.startAutoRefresh();
532
+ }
533
+ } catch (error) {
534
+ this.handleError(error);
535
+ }
536
+ }
537
+ /**
538
+ * Sign out
539
+ */
540
+ async signOut() {
541
+ try {
542
+ this.stopAutoRefresh();
543
+ await this.provider.signOut();
544
+ this.updateState({
545
+ state: "unauthenticated" /* UNAUTHENTICATED */,
546
+ user: null,
547
+ session: null,
548
+ error: null,
549
+ isAuthenticated: false,
550
+ isLoading: false
551
+ });
552
+ } catch (error) {
553
+ this.handleError(error);
554
+ }
555
+ }
556
+ /**
557
+ * Update user profile
558
+ */
559
+ async updateUser(request) {
560
+ try {
561
+ const user = await this.provider.updateUser(request);
562
+ const currentState = this.state.getValue();
563
+ this.updateState({
564
+ ...currentState,
565
+ user
566
+ });
567
+ } catch (error) {
568
+ this.handleError(error);
569
+ }
570
+ }
571
+ /**
572
+ * Change password
573
+ */
574
+ async changePassword(request) {
575
+ try {
576
+ await this.provider.changePassword(request);
577
+ } catch (error) {
578
+ throw this.provider.normalizeError(error);
579
+ }
580
+ }
581
+ /**
582
+ * Request password reset
583
+ */
584
+ async requestPasswordReset(request) {
585
+ try {
586
+ await this.provider.requestPasswordReset(request);
587
+ } catch (error) {
588
+ throw this.provider.normalizeError(error);
589
+ }
590
+ }
591
+ /**
592
+ * Confirm password reset
593
+ */
594
+ async confirmPasswordReset(request) {
595
+ try {
596
+ await this.provider.confirmPasswordReset(request);
597
+ } catch (error) {
598
+ throw this.provider.normalizeError(error);
599
+ }
600
+ }
601
+ /**
602
+ * Get OAuth sign in URL
603
+ */
604
+ async getOAuthUrl(request) {
605
+ return this.provider.oauthSignIn(request);
606
+ }
607
+ /**
608
+ * Handle OAuth callback
609
+ */
610
+ async handleOAuthCallback(request) {
611
+ try {
612
+ this.setLoading();
613
+ const response = await this.provider.oauthCallback(request);
614
+ this.updateState({
615
+ state: "authenticated" /* AUTHENTICATED */,
616
+ user: response.user,
617
+ session: response.session,
618
+ error: null,
619
+ isAuthenticated: true,
620
+ isLoading: false
621
+ });
622
+ if (this.autoRefresh) {
623
+ this.startAutoRefresh();
624
+ }
625
+ } catch (error) {
626
+ this.handleError(error);
627
+ }
628
+ }
629
+ /**
630
+ * Get available OAuth providers
631
+ */
632
+ async getOAuthProviders() {
633
+ return this.provider.getOAuthProviders();
634
+ }
635
+ /**
636
+ * Send magic link
637
+ */
638
+ async sendMagicLink(request) {
639
+ try {
640
+ await this.provider.sendMagicLink(request);
641
+ } catch (error) {
642
+ throw this.provider.normalizeError(error);
643
+ }
644
+ }
645
+ /**
646
+ * Verify magic link
647
+ */
648
+ async verifyMagicLink(request) {
649
+ try {
650
+ this.setLoading();
651
+ const response = await this.provider.verifyMagicLink(request);
652
+ this.updateState({
653
+ state: "authenticated" /* AUTHENTICATED */,
654
+ user: response.user,
655
+ session: response.session,
656
+ error: null,
657
+ isAuthenticated: true,
658
+ isLoading: false
659
+ });
660
+ if (this.autoRefresh) {
661
+ this.startAutoRefresh();
662
+ }
663
+ } catch (error) {
664
+ this.handleError(error);
665
+ }
666
+ }
667
+ /**
668
+ * Send phone verification code
669
+ */
670
+ async sendPhoneCode(request) {
671
+ try {
672
+ await this.provider.sendPhoneCode(request);
673
+ } catch (error) {
674
+ throw this.provider.normalizeError(error);
675
+ }
676
+ }
677
+ /**
678
+ * Verify phone code
679
+ */
680
+ async verifyPhoneCode(request) {
681
+ try {
682
+ this.setLoading();
683
+ const response = await this.provider.verifyPhoneCode(request);
684
+ this.updateState({
685
+ state: "authenticated" /* AUTHENTICATED */,
686
+ user: response.user,
687
+ session: response.session,
688
+ error: null,
689
+ isAuthenticated: true,
690
+ isLoading: false
691
+ });
692
+ if (this.autoRefresh) {
693
+ this.startAutoRefresh();
694
+ }
695
+ } catch (error) {
696
+ this.handleError(error);
697
+ }
698
+ }
699
+ /**
700
+ * Setup 2FA
701
+ */
702
+ async setupTwoFactor(request) {
703
+ return this.provider.setupTwoFactor(request);
704
+ }
705
+ /**
706
+ * Verify 2FA code
707
+ */
708
+ async verifyTwoFactor(request) {
709
+ try {
710
+ this.setLoading();
711
+ const response = await this.provider.verifyTwoFactor(request);
712
+ this.updateState({
713
+ state: "authenticated" /* AUTHENTICATED */,
714
+ user: response.user,
715
+ session: response.session,
716
+ error: null,
717
+ isAuthenticated: true,
718
+ isLoading: false
719
+ });
720
+ if (this.autoRefresh) {
721
+ this.startAutoRefresh();
722
+ }
723
+ } catch (error) {
724
+ this.handleError(error);
725
+ }
726
+ }
727
+ /**
728
+ * Disable 2FA
729
+ */
730
+ async disableTwoFactor() {
731
+ return this.provider.disableTwoFactor();
732
+ }
733
+ /**
734
+ * Get 2FA status
735
+ */
736
+ async getTwoFactorStatus() {
737
+ return this.provider.getTwoFactorStatus();
738
+ }
739
+ /**
740
+ * Register passkey
741
+ */
742
+ async registerPasskey(request) {
743
+ return this.provider.registerPasskey(request);
744
+ }
745
+ /**
746
+ * Authenticate with passkey
747
+ */
748
+ async authenticatePasskey(request) {
749
+ try {
750
+ this.setLoading();
751
+ const response = await this.provider.authenticatePasskey(request);
752
+ this.updateState({
753
+ state: "authenticated" /* AUTHENTICATED */,
754
+ user: response.user,
755
+ session: response.session,
756
+ error: null,
757
+ isAuthenticated: true,
758
+ isLoading: false
759
+ });
760
+ if (this.autoRefresh) {
761
+ this.startAutoRefresh();
762
+ }
763
+ } catch (error) {
764
+ this.handleError(error);
765
+ }
766
+ }
767
+ /**
768
+ * List passkeys
769
+ */
770
+ async listPasskeys() {
771
+ return this.provider.listPasskeys();
772
+ }
773
+ /**
774
+ * Delete passkey
775
+ */
776
+ async deletePasskey(credentialId) {
777
+ return this.provider.deletePasskey(credentialId);
778
+ }
779
+ /**
780
+ * Get all organizations the user belongs to
781
+ * Only available if the provider supports organizations
782
+ */
783
+ async getOrganizations() {
784
+ if (!this.provider.getOrganizations) {
785
+ throw this.createUnsupportedError("Organization support");
786
+ }
787
+ return this.provider.getOrganizations();
788
+ }
789
+ /**
790
+ * Get the currently active organization
791
+ * Only available if the provider supports organizations
792
+ */
793
+ async getActiveOrganization() {
794
+ if (!this.provider.getActiveOrganization) {
795
+ throw this.createUnsupportedError("Organization support");
796
+ }
797
+ return this.provider.getActiveOrganization();
798
+ }
799
+ /**
800
+ * Set the active organization and refresh user state
801
+ * Only available if the provider supports organizations
802
+ */
803
+ async setActiveOrganization(organizationId) {
804
+ if (!this.provider.setActiveOrganization) {
805
+ throw this.createUnsupportedError("Organization support");
806
+ }
807
+ await this.provider.setActiveOrganization(organizationId);
808
+ await this.refreshSession();
809
+ }
810
+ /**
811
+ * Get organization memberships with roles and permissions
812
+ * Only available if the provider supports organizations
813
+ */
814
+ async getOrganizationMemberships() {
815
+ if (!this.provider.getOrganizationMemberships) {
816
+ throw this.createUnsupportedError("Organization memberships");
817
+ }
818
+ return this.provider.getOrganizationMemberships();
819
+ }
820
+ /**
821
+ * Check if the provider supports organizations
822
+ */
823
+ supportsOrganizations() {
824
+ return !!(this.provider.getOrganizations && this.provider.getActiveOrganization && this.provider.setActiveOrganization);
825
+ }
826
+ /**
827
+ * Refresh session
828
+ */
829
+ async refreshSession() {
830
+ try {
831
+ const session = await this.provider.refreshSession();
832
+ const currentState = this.state.getValue();
833
+ this.updateState({
834
+ ...currentState,
835
+ session
836
+ });
837
+ } catch (error) {
838
+ await this.signOut();
839
+ }
840
+ }
841
+ /**
842
+ * Get current user
843
+ */
844
+ getUser() {
845
+ return this.state.getValue().user;
846
+ }
847
+ /**
848
+ * Get current session
849
+ */
850
+ getSession() {
851
+ return this.state.getValue().session;
852
+ }
853
+ /**
854
+ * Check if authenticated
855
+ */
856
+ isAuthenticated() {
857
+ return this.state.getValue().isAuthenticated;
858
+ }
859
+ /**
860
+ * Get current error
861
+ */
862
+ getError() {
863
+ return this.state.getValue().error;
864
+ }
865
+ /**
866
+ * Clear error
867
+ */
868
+ clearError() {
869
+ const currentState = this.state.getValue();
870
+ this.updateState({
871
+ ...currentState,
872
+ error: null
873
+ });
874
+ }
875
+ /**
876
+ * Subscribe to auth state changes
877
+ */
878
+ subscribe(listener) {
879
+ return this.state.subscribe(listener);
880
+ }
881
+ /**
882
+ * Cleanup resources
883
+ */
884
+ destroy() {
885
+ this.stopAutoRefresh();
886
+ this.state.clearListeners();
887
+ }
888
+ // Private methods
889
+ updateState(newState) {
890
+ this.state.setValue(newState);
891
+ }
892
+ setLoading() {
893
+ const currentState = this.state.getValue();
894
+ this.updateState({
895
+ ...currentState,
896
+ state: "loading" /* LOADING */,
897
+ isLoading: true,
898
+ error: null
899
+ });
900
+ }
901
+ handleError(error) {
902
+ const authError = this.provider.normalizeError(error);
903
+ const currentState = this.state.getValue();
904
+ this.updateState({
905
+ ...currentState,
906
+ state: "error" /* ERROR */,
907
+ error: authError,
908
+ isLoading: false
909
+ });
910
+ }
911
+ startAutoRefresh() {
912
+ this.stopAutoRefresh();
913
+ this.refreshTimer = setInterval(() => {
914
+ this.refreshSession();
915
+ }, this.refreshInterval);
916
+ }
917
+ stopAutoRefresh() {
918
+ if (this.refreshTimer) {
919
+ clearInterval(this.refreshTimer);
920
+ this.refreshTimer = void 0;
921
+ }
922
+ }
923
+ createUnsupportedError(feature) {
924
+ return {
925
+ name: "AuthError",
926
+ message: `${feature} is not available with this auth provider`,
927
+ type: "unknown_error" /* UNKNOWN_ERROR */
928
+ };
929
+ }
930
+ };
931
+
932
+ // src/flows/types.ts
933
+ var FlowStep = /* @__PURE__ */ ((FlowStep2) => {
934
+ FlowStep2["SIGN_IN"] = "sign_in";
935
+ FlowStep2["SIGN_UP"] = "sign_up";
936
+ FlowStep2["EMAIL_PASSWORD_SIGN_IN"] = "email_password_sign_in";
937
+ FlowStep2["EMAIL_PASSWORD_SIGN_UP"] = "email_password_sign_up";
938
+ FlowStep2["OAUTH_SELECT"] = "oauth_select";
939
+ FlowStep2["OAUTH_CALLBACK"] = "oauth_callback";
940
+ FlowStep2["MAGIC_LINK_REQUEST"] = "magic_link_request";
941
+ FlowStep2["MAGIC_LINK_VERIFY"] = "magic_link_verify";
942
+ FlowStep2["MAGIC_LINK_SENT"] = "magic_link_sent";
943
+ FlowStep2["PHONE_REQUEST"] = "phone_request";
944
+ FlowStep2["PHONE_VERIFY"] = "phone_verify";
945
+ FlowStep2["USERNAME_SIGN_IN"] = "username_sign_in";
946
+ FlowStep2["USERNAME_SIGN_UP"] = "username_sign_up";
947
+ FlowStep2["PASSKEY_REGISTER"] = "passkey_register";
948
+ FlowStep2["PASSKEY_AUTHENTICATE"] = "passkey_authenticate";
949
+ FlowStep2["MFA_REQUIRED"] = "mfa_required";
950
+ FlowStep2["MFA_SETUP"] = "mfa_setup";
951
+ FlowStep2["MFA_VERIFY"] = "mfa_verify";
952
+ FlowStep2["MFA_SELECT_METHOD"] = "mfa_select_method";
953
+ FlowStep2["EMAIL_VERIFICATION_REQUIRED"] = "email_verification_required";
954
+ FlowStep2["EMAIL_VERIFICATION_SENT"] = "email_verification_sent";
955
+ FlowStep2["PHONE_VERIFICATION_REQUIRED"] = "phone_verification_required";
956
+ FlowStep2["PASSWORD_RESET_REQUEST"] = "password_reset_request";
957
+ FlowStep2["PASSWORD_RESET_SENT"] = "password_reset_sent";
958
+ FlowStep2["PASSWORD_RESET_CONFIRM"] = "password_reset_confirm";
959
+ FlowStep2["PASSWORD_CHANGE"] = "password_change";
960
+ FlowStep2["PROFILE_UPDATE"] = "profile_update";
961
+ FlowStep2["PROFILE_COMPLETE"] = "profile_complete";
962
+ FlowStep2["SUCCESS"] = "success";
963
+ FlowStep2["ERROR"] = "error";
964
+ FlowStep2["CANCELLED"] = "cancelled";
965
+ return FlowStep2;
966
+ })(FlowStep || {});
967
+ var FlowConfigType = /* @__PURE__ */ ((FlowConfigType2) => {
968
+ FlowConfigType2["SIMPLE_SIGN_IN"] = "simple_sign_in";
969
+ FlowConfigType2["SIMPLE_SIGN_UP"] = "simple_sign_up";
970
+ FlowConfigType2["SIGN_UP_WITH_EMAIL_VERIFICATION"] = "sign_up_with_email_verification";
971
+ FlowConfigType2["SIGN_IN_WITH_MFA"] = "sign_in_with_mfa";
972
+ FlowConfigType2["OAUTH_SIGN_IN"] = "oauth_sign_in";
973
+ FlowConfigType2["MAGIC_LINK_FLOW"] = "magic_link_flow";
974
+ FlowConfigType2["PHONE_AUTH_FLOW"] = "phone_auth_flow";
975
+ FlowConfigType2["COMPLETE_SIGN_UP_FLOW"] = "complete_sign_up_flow";
976
+ FlowConfigType2["SECURE_SIGN_IN_FLOW"] = "secure_sign_in_flow";
977
+ FlowConfigType2["PASSWORD_RESET_FLOW"] = "password_reset_flow";
978
+ FlowConfigType2["CUSTOM"] = "custom";
979
+ return FlowConfigType2;
980
+ })(FlowConfigType || {});
981
+ var FlowAction = /* @__PURE__ */ ((FlowAction2) => {
982
+ FlowAction2["START"] = "start";
983
+ FlowAction2["NEXT"] = "next";
984
+ FlowAction2["BACK"] = "back";
985
+ FlowAction2["CANCEL"] = "cancel";
986
+ FlowAction2["ERROR"] = "error";
987
+ FlowAction2["RESET"] = "reset";
988
+ return FlowAction2;
989
+ })(FlowAction || {});
990
+
991
+ // src/flows/engine.ts
992
+ var FlowEngine = class {
993
+ constructor(config, initialState) {
994
+ this.history = [];
995
+ this.config = config;
996
+ this.state = {
997
+ currentStep: config.initialStep,
998
+ ...initialState
999
+ };
1000
+ this.history.push(this.state.currentStep);
1001
+ }
1002
+ /**
1003
+ * Get current flow state
1004
+ */
1005
+ getState() {
1006
+ return { ...this.state };
1007
+ }
1008
+ /**
1009
+ * Get current step
1010
+ */
1011
+ getCurrentStep() {
1012
+ return this.state.currentStep;
1013
+ }
1014
+ /**
1015
+ * Check if step is allowed in this flow
1016
+ */
1017
+ isStepAllowed(step) {
1018
+ return this.config.allowedSteps.includes(step);
1019
+ }
1020
+ /**
1021
+ * Transition to next step based on action
1022
+ */
1023
+ async transition(event) {
1024
+ const { action, data, error } = event;
1025
+ switch (action) {
1026
+ case "start":
1027
+ return this.handleStart(data);
1028
+ case "next":
1029
+ return this.handleNext(data);
1030
+ case "back":
1031
+ return this.handleBack();
1032
+ case "cancel":
1033
+ return this.handleCancel();
1034
+ case "error":
1035
+ return this.handleError(error);
1036
+ case "reset":
1037
+ return this.handleReset();
1038
+ default:
1039
+ throw new AuthError(
1040
+ `Unknown flow action: ${action}`,
1041
+ "validation_error" /* VALIDATION_ERROR */
1042
+ );
1043
+ }
1044
+ }
1045
+ /**
1046
+ * Start or restart the flow
1047
+ */
1048
+ handleStart(data) {
1049
+ this.state = {
1050
+ currentStep: this.config.initialStep,
1051
+ ...data
1052
+ };
1053
+ this.history = [this.state.currentStep];
1054
+ if (this.config.onStepChange) {
1055
+ this.config.onStepChange(this.state.currentStep, this.state);
1056
+ }
1057
+ return this.getState();
1058
+ }
1059
+ /**
1060
+ * Move to next step
1061
+ */
1062
+ handleNext(data) {
1063
+ this.state = {
1064
+ ...this.state,
1065
+ ...data,
1066
+ previousStep: this.state.currentStep
1067
+ };
1068
+ const transitionConfig = this.config.transitions[this.state.currentStep];
1069
+ if (!transitionConfig) {
1070
+ throw new AuthError(
1071
+ `No transition configured for step: ${this.state.currentStep}`,
1072
+ "validation_error" /* VALIDATION_ERROR */
1073
+ );
1074
+ }
1075
+ if (transitionConfig.conditions) {
1076
+ for (const condition of transitionConfig.conditions) {
1077
+ if (condition.when(this.state)) {
1078
+ return this.moveToStep(condition.then);
1079
+ }
1080
+ }
1081
+ }
1082
+ if (transitionConfig.onSuccess) {
1083
+ return this.moveToStep(transitionConfig.onSuccess);
1084
+ }
1085
+ throw new AuthError(
1086
+ `No valid transition found for step: ${this.state.currentStep}`,
1087
+ "validation_error" /* VALIDATION_ERROR */
1088
+ );
1089
+ }
1090
+ /**
1091
+ * Go back to previous step
1092
+ */
1093
+ handleBack() {
1094
+ if (this.history.length < 2) {
1095
+ throw new AuthError(
1096
+ "Cannot go back - already at first step",
1097
+ "validation_error" /* VALIDATION_ERROR */
1098
+ );
1099
+ }
1100
+ this.history.pop();
1101
+ const previousStep = this.history[this.history.length - 1];
1102
+ const transitionConfig = this.config.transitions[this.state.currentStep];
1103
+ const targetStep = transitionConfig?.onBack || previousStep;
1104
+ return this.moveToStep(targetStep, false);
1105
+ }
1106
+ /**
1107
+ * Cancel the flow
1108
+ */
1109
+ handleCancel() {
1110
+ const transitionConfig = this.config.transitions[this.state.currentStep];
1111
+ const targetStep = transitionConfig?.onCancel;
1112
+ if (this.config.onCancel) {
1113
+ this.config.onCancel(this.state);
1114
+ }
1115
+ if (targetStep) {
1116
+ return this.moveToStep(targetStep);
1117
+ }
1118
+ this.state.currentStep = "cancelled";
1119
+ return this.getState();
1120
+ }
1121
+ /**
1122
+ * Handle error in flow
1123
+ */
1124
+ handleError(error) {
1125
+ this.state.error = error;
1126
+ const transitionConfig = this.config.transitions[this.state.currentStep];
1127
+ const targetStep = transitionConfig?.onError;
1128
+ if (this.config.onError) {
1129
+ this.config.onError(error, this.state);
1130
+ }
1131
+ if (targetStep) {
1132
+ return this.moveToStep(targetStep);
1133
+ }
1134
+ return this.getState();
1135
+ }
1136
+ /**
1137
+ * Reset flow to initial state
1138
+ */
1139
+ handleReset() {
1140
+ return this.handleStart();
1141
+ }
1142
+ /**
1143
+ * Move to a specific step
1144
+ */
1145
+ moveToStep(step, addToHistory = true) {
1146
+ if (!this.isStepAllowed(step)) {
1147
+ throw new AuthError(
1148
+ `Step ${step} is not allowed in this flow`,
1149
+ "validation_error" /* VALIDATION_ERROR */
1150
+ );
1151
+ }
1152
+ this.state.currentStep = step;
1153
+ if (addToHistory) {
1154
+ this.history.push(step);
1155
+ }
1156
+ if (this.config.onStepChange) {
1157
+ this.config.onStepChange(step, this.state);
1158
+ }
1159
+ if (step === "success" && this.state.user && this.state.session) {
1160
+ if (this.config.onComplete) {
1161
+ this.config.onComplete(this.state.user, this.state.session);
1162
+ }
1163
+ }
1164
+ return this.getState();
1165
+ }
1166
+ /**
1167
+ * Get flow history
1168
+ */
1169
+ getHistory() {
1170
+ return [...this.history];
1171
+ }
1172
+ /**
1173
+ * Check if can go back
1174
+ */
1175
+ canGoBack() {
1176
+ return this.history.length > 1;
1177
+ }
1178
+ };
1179
+
1180
+ // src/flows/configs.ts
1181
+ var simpleSignInFlow = {
1182
+ name: "Simple Sign In",
1183
+ description: "Basic email/password sign-in",
1184
+ initialStep: "email_password_sign_in" /* EMAIL_PASSWORD_SIGN_IN */,
1185
+ allowedSteps: [
1186
+ "email_password_sign_in" /* EMAIL_PASSWORD_SIGN_IN */,
1187
+ "password_reset_request" /* PASSWORD_RESET_REQUEST */,
1188
+ "password_reset_sent" /* PASSWORD_RESET_SENT */,
1189
+ "success" /* SUCCESS */,
1190
+ "error" /* ERROR */
1191
+ ],
1192
+ transitions: {
1193
+ ["email_password_sign_in" /* EMAIL_PASSWORD_SIGN_IN */]: {
1194
+ onSuccess: "success" /* SUCCESS */,
1195
+ onError: "email_password_sign_in" /* EMAIL_PASSWORD_SIGN_IN */
1196
+ },
1197
+ ["password_reset_request" /* PASSWORD_RESET_REQUEST */]: {
1198
+ onSuccess: "password_reset_sent" /* PASSWORD_RESET_SENT */,
1199
+ onBack: "email_password_sign_in" /* EMAIL_PASSWORD_SIGN_IN */
1200
+ },
1201
+ ["password_reset_sent" /* PASSWORD_RESET_SENT */]: {
1202
+ onSuccess: "email_password_sign_in" /* EMAIL_PASSWORD_SIGN_IN */
1203
+ }
1204
+ }
1205
+ };
1206
+ var signInWithMFAFlow = {
1207
+ name: "Sign In with MFA",
1208
+ description: "Sign-in that handles MFA if enabled",
1209
+ initialStep: "email_password_sign_in" /* EMAIL_PASSWORD_SIGN_IN */,
1210
+ allowedSteps: [
1211
+ "email_password_sign_in" /* EMAIL_PASSWORD_SIGN_IN */,
1212
+ "mfa_required" /* MFA_REQUIRED */,
1213
+ "mfa_select_method" /* MFA_SELECT_METHOD */,
1214
+ "mfa_verify" /* MFA_VERIFY */,
1215
+ "password_reset_request" /* PASSWORD_RESET_REQUEST */,
1216
+ "password_reset_sent" /* PASSWORD_RESET_SENT */,
1217
+ "success" /* SUCCESS */,
1218
+ "error" /* ERROR */
1219
+ ],
1220
+ transitions: {
1221
+ ["email_password_sign_in" /* EMAIL_PASSWORD_SIGN_IN */]: {
1222
+ onSuccess: "success" /* SUCCESS */,
1223
+ onError: "email_password_sign_in" /* EMAIL_PASSWORD_SIGN_IN */,
1224
+ conditions: [
1225
+ {
1226
+ when: (state) => state.mfaRequired === true,
1227
+ then: "mfa_required" /* MFA_REQUIRED */
1228
+ }
1229
+ ]
1230
+ },
1231
+ ["mfa_required" /* MFA_REQUIRED */]: {
1232
+ onSuccess: "mfa_verify" /* MFA_VERIFY */,
1233
+ conditions: [
1234
+ {
1235
+ when: (state) => (state.mfaMethods?.length || 0) > 1,
1236
+ then: "mfa_select_method" /* MFA_SELECT_METHOD */
1237
+ }
1238
+ ]
1239
+ },
1240
+ ["mfa_select_method" /* MFA_SELECT_METHOD */]: {
1241
+ onSuccess: "mfa_verify" /* MFA_VERIFY */,
1242
+ onBack: "email_password_sign_in" /* EMAIL_PASSWORD_SIGN_IN */
1243
+ },
1244
+ ["mfa_verify" /* MFA_VERIFY */]: {
1245
+ onSuccess: "success" /* SUCCESS */,
1246
+ onError: "mfa_verify" /* MFA_VERIFY */,
1247
+ onBack: "mfa_select_method" /* MFA_SELECT_METHOD */
1248
+ },
1249
+ ["password_reset_request" /* PASSWORD_RESET_REQUEST */]: {
1250
+ onSuccess: "password_reset_sent" /* PASSWORD_RESET_SENT */,
1251
+ onBack: "email_password_sign_in" /* EMAIL_PASSWORD_SIGN_IN */
1252
+ }
1253
+ }
1254
+ };
1255
+ var completeSignUpFlow = {
1256
+ name: "Complete Sign Up",
1257
+ description: "Sign-up with email verification and profile completion",
1258
+ initialStep: "email_password_sign_up" /* EMAIL_PASSWORD_SIGN_UP */,
1259
+ allowedSteps: [
1260
+ "email_password_sign_up" /* EMAIL_PASSWORD_SIGN_UP */,
1261
+ "email_verification_required" /* EMAIL_VERIFICATION_REQUIRED */,
1262
+ "email_verification_sent" /* EMAIL_VERIFICATION_SENT */,
1263
+ "profile_complete" /* PROFILE_COMPLETE */,
1264
+ "success" /* SUCCESS */,
1265
+ "error" /* ERROR */
1266
+ ],
1267
+ transitions: {
1268
+ ["email_password_sign_up" /* EMAIL_PASSWORD_SIGN_UP */]: {
1269
+ onSuccess: "email_verification_required" /* EMAIL_VERIFICATION_REQUIRED */,
1270
+ onError: "email_password_sign_up" /* EMAIL_PASSWORD_SIGN_UP */,
1271
+ conditions: [
1272
+ {
1273
+ when: (state) => state.verificationRequired === false,
1274
+ then: "profile_complete" /* PROFILE_COMPLETE */
1275
+ }
1276
+ ]
1277
+ },
1278
+ ["email_verification_required" /* EMAIL_VERIFICATION_REQUIRED */]: {
1279
+ onSuccess: "email_verification_sent" /* EMAIL_VERIFICATION_SENT */
1280
+ },
1281
+ ["email_verification_sent" /* EMAIL_VERIFICATION_SENT */]: {
1282
+ onSuccess: "profile_complete" /* PROFILE_COMPLETE */
1283
+ },
1284
+ ["profile_complete" /* PROFILE_COMPLETE */]: {
1285
+ onSuccess: "success" /* SUCCESS */,
1286
+ onError: "profile_complete" /* PROFILE_COMPLETE */
1287
+ }
1288
+ }
1289
+ };
1290
+ var magicLinkFlow = {
1291
+ name: "Magic Link",
1292
+ description: "Passwordless authentication via email",
1293
+ initialStep: "magic_link_request" /* MAGIC_LINK_REQUEST */,
1294
+ allowedSteps: [
1295
+ "magic_link_request" /* MAGIC_LINK_REQUEST */,
1296
+ "magic_link_sent" /* MAGIC_LINK_SENT */,
1297
+ "magic_link_verify" /* MAGIC_LINK_VERIFY */,
1298
+ "success" /* SUCCESS */,
1299
+ "error" /* ERROR */
1300
+ ],
1301
+ transitions: {
1302
+ ["magic_link_request" /* MAGIC_LINK_REQUEST */]: {
1303
+ onSuccess: "magic_link_sent" /* MAGIC_LINK_SENT */,
1304
+ onError: "magic_link_request" /* MAGIC_LINK_REQUEST */
1305
+ },
1306
+ ["magic_link_sent" /* MAGIC_LINK_SENT */]: {
1307
+ onSuccess: "magic_link_verify" /* MAGIC_LINK_VERIFY */
1308
+ },
1309
+ ["magic_link_verify" /* MAGIC_LINK_VERIFY */]: {
1310
+ onSuccess: "success" /* SUCCESS */,
1311
+ onError: "magic_link_request" /* MAGIC_LINK_REQUEST */
1312
+ }
1313
+ }
1314
+ };
1315
+ var phoneAuthFlow = {
1316
+ name: "Phone Authentication",
1317
+ description: "SMS-based authentication",
1318
+ initialStep: "phone_request" /* PHONE_REQUEST */,
1319
+ allowedSteps: [
1320
+ "phone_request" /* PHONE_REQUEST */,
1321
+ "phone_verify" /* PHONE_VERIFY */,
1322
+ "success" /* SUCCESS */,
1323
+ "error" /* ERROR */
1324
+ ],
1325
+ transitions: {
1326
+ ["phone_request" /* PHONE_REQUEST */]: {
1327
+ onSuccess: "phone_verify" /* PHONE_VERIFY */,
1328
+ onError: "phone_request" /* PHONE_REQUEST */
1329
+ },
1330
+ ["phone_verify" /* PHONE_VERIFY */]: {
1331
+ onSuccess: "success" /* SUCCESS */,
1332
+ onError: "phone_verify" /* PHONE_VERIFY */,
1333
+ onBack: "phone_request" /* PHONE_REQUEST */
1334
+ }
1335
+ }
1336
+ };
1337
+ var oauthSignInFlow = {
1338
+ name: "OAuth Sign In",
1339
+ description: "Third-party OAuth authentication",
1340
+ initialStep: "oauth_select" /* OAUTH_SELECT */,
1341
+ allowedSteps: [
1342
+ "oauth_select" /* OAUTH_SELECT */,
1343
+ "oauth_callback" /* OAUTH_CALLBACK */,
1344
+ "success" /* SUCCESS */,
1345
+ "error" /* ERROR */
1346
+ ],
1347
+ transitions: {
1348
+ ["oauth_select" /* OAUTH_SELECT */]: {
1349
+ onSuccess: "oauth_callback" /* OAUTH_CALLBACK */,
1350
+ onError: "oauth_select" /* OAUTH_SELECT */
1351
+ },
1352
+ ["oauth_callback" /* OAUTH_CALLBACK */]: {
1353
+ onSuccess: "success" /* SUCCESS */,
1354
+ onError: "oauth_select" /* OAUTH_SELECT */
1355
+ }
1356
+ }
1357
+ };
1358
+ var passwordResetFlow = {
1359
+ name: "Password Reset",
1360
+ description: "Reset forgotten password",
1361
+ initialStep: "password_reset_request" /* PASSWORD_RESET_REQUEST */,
1362
+ allowedSteps: [
1363
+ "password_reset_request" /* PASSWORD_RESET_REQUEST */,
1364
+ "password_reset_sent" /* PASSWORD_RESET_SENT */,
1365
+ "password_reset_confirm" /* PASSWORD_RESET_CONFIRM */,
1366
+ "success" /* SUCCESS */,
1367
+ "error" /* ERROR */
1368
+ ],
1369
+ transitions: {
1370
+ ["password_reset_request" /* PASSWORD_RESET_REQUEST */]: {
1371
+ onSuccess: "password_reset_sent" /* PASSWORD_RESET_SENT */,
1372
+ onError: "password_reset_request" /* PASSWORD_RESET_REQUEST */
1373
+ },
1374
+ ["password_reset_sent" /* PASSWORD_RESET_SENT */]: {
1375
+ onSuccess: "password_reset_confirm" /* PASSWORD_RESET_CONFIRM */
1376
+ },
1377
+ ["password_reset_confirm" /* PASSWORD_RESET_CONFIRM */]: {
1378
+ onSuccess: "success" /* SUCCESS */,
1379
+ onError: "password_reset_confirm" /* PASSWORD_RESET_CONFIRM */
1380
+ }
1381
+ }
1382
+ };
1383
+ function getFlowConfig(type) {
1384
+ switch (type) {
1385
+ case "simple_sign_in" /* SIMPLE_SIGN_IN */:
1386
+ return simpleSignInFlow;
1387
+ case "sign_in_with_mfa" /* SIGN_IN_WITH_MFA */:
1388
+ return signInWithMFAFlow;
1389
+ case "complete_sign_up_flow" /* COMPLETE_SIGN_UP_FLOW */:
1390
+ return completeSignUpFlow;
1391
+ case "magic_link_flow" /* MAGIC_LINK_FLOW */:
1392
+ return magicLinkFlow;
1393
+ case "phone_auth_flow" /* PHONE_AUTH_FLOW */:
1394
+ return phoneAuthFlow;
1395
+ case "oauth_sign_in" /* OAUTH_SIGN_IN */:
1396
+ return oauthSignInFlow;
1397
+ case "password_reset_flow" /* PASSWORD_RESET_FLOW */:
1398
+ return passwordResetFlow;
1399
+ default:
1400
+ throw new Error(`Unknown flow type: ${type}`);
1401
+ }
1402
+ }
1403
+ var predefinedFlows = {
1404
+ ["simple_sign_in" /* SIMPLE_SIGN_IN */]: simpleSignInFlow,
1405
+ ["sign_in_with_mfa" /* SIGN_IN_WITH_MFA */]: signInWithMFAFlow,
1406
+ ["complete_sign_up_flow" /* COMPLETE_SIGN_UP_FLOW */]: completeSignUpFlow,
1407
+ ["magic_link_flow" /* MAGIC_LINK_FLOW */]: magicLinkFlow,
1408
+ ["phone_auth_flow" /* PHONE_AUTH_FLOW */]: phoneAuthFlow,
1409
+ ["oauth_sign_in" /* OAUTH_SIGN_IN */]: oauthSignInFlow,
1410
+ ["password_reset_flow" /* PASSWORD_RESET_FLOW */]: passwordResetFlow
1411
+ };
1412
+
1413
+ export { AuthClient, AuthError, AuthErrorType, AuthState, BaseAuthProvider, FlowAction, FlowConfigType, FlowEngine, FlowStep, LocalStorageAdapter, MemoryStorageAdapter, OAuthProvider, Observable, SessionStorageAdapter, TokenManager, TwoFactorMethod, completeSignUpFlow, createAuthError, getFlowConfig, isAuthError, isMFARequiredError, isNetworkError, isUnauthenticatedError, magicLinkFlow, oauthSignInFlow, passwordResetFlow, phoneAuthFlow, predefinedFlows, signInWithMFAFlow, simpleSignInFlow, toAuthError, validate2FACode, validateEmail, validatePassword, validatePhone, validateRequired, validateUsername };
1414
+ //# sourceMappingURL=index.mjs.map
1415
+ //# sourceMappingURL=index.mjs.map