@umituz/react-native-firebase 2.6.0 → 2.6.1

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.
Files changed (39) hide show
  1. package/package.json +1 -1
  2. package/src/application/auth/index.ts +42 -0
  3. package/src/application/auth/ports/AuthPort.ts +164 -0
  4. package/src/application/auth/use-cases/SignInUseCase.ts +253 -0
  5. package/src/application/auth/use-cases/SignOutUseCase.ts +288 -0
  6. package/src/application/auth/use-cases/index.ts +26 -0
  7. package/src/domains/account-deletion/domain/index.ts +15 -0
  8. package/src/domains/account-deletion/domain/services/UserValidationService.ts +295 -0
  9. package/src/domains/account-deletion/index.ts +43 -6
  10. package/src/domains/account-deletion/infrastructure/services/AccountDeletionExecutor.ts +230 -0
  11. package/src/domains/account-deletion/infrastructure/services/AccountDeletionReauthHandler.ts +174 -0
  12. package/src/domains/account-deletion/infrastructure/services/AccountDeletionRepository.ts +266 -0
  13. package/src/domains/account-deletion/infrastructure/services/AccountDeletionTypes.ts +33 -0
  14. package/src/domains/account-deletion/infrastructure/services/account-deletion.service.ts +39 -227
  15. package/src/domains/auth/domain.ts +16 -0
  16. package/src/domains/auth/index.ts +7 -148
  17. package/src/domains/auth/infrastructure.ts +156 -0
  18. package/src/domains/auth/presentation/hooks/GoogleOAuthHookService.ts +247 -0
  19. package/src/domains/auth/presentation/hooks/useGoogleOAuth.ts +49 -103
  20. package/src/domains/auth/presentation.ts +25 -0
  21. package/src/domains/firestore/domain/entities/Collection.ts +288 -0
  22. package/src/domains/firestore/domain/entities/Document.ts +233 -0
  23. package/src/domains/firestore/domain/index.ts +30 -0
  24. package/src/domains/firestore/domain/services/QueryService.ts +182 -0
  25. package/src/domains/firestore/domain/services/QueryServiceAnalysis.ts +169 -0
  26. package/src/domains/firestore/domain/services/QueryServiceHelpers.ts +151 -0
  27. package/src/domains/firestore/domain/value-objects/QueryOptions.ts +191 -0
  28. package/src/domains/firestore/domain/value-objects/QueryOptions.ts.bak +320 -0
  29. package/src/domains/firestore/domain/value-objects/QueryOptionsSerialization.ts +207 -0
  30. package/src/domains/firestore/domain/value-objects/QueryOptionsValidation.ts +182 -0
  31. package/src/domains/firestore/domain/value-objects/WhereClause.ts +299 -0
  32. package/src/domains/firestore/domain/value-objects/WhereClauseFactory.ts +207 -0
  33. package/src/domains/firestore/index.ts +9 -6
  34. package/src/index.ts +25 -0
  35. package/src/shared/domain/utils/error-handlers/error-messages.ts +11 -0
  36. package/src/shared/infrastructure/base/ErrorHandler.ts +189 -0
  37. package/src/shared/infrastructure/base/ServiceBase.ts +220 -0
  38. package/src/shared/infrastructure/base/TypedGuard.ts +131 -0
  39. package/src/shared/infrastructure/base/index.ts +34 -0
@@ -1,241 +1,53 @@
1
1
  /**
2
- * Account Deletion Service
2
+ * Account Deletion Service (Refactored)
3
3
  * Handles Firebase account deletion with reauthentication support
4
+ *
5
+ * This file now delegates to the new DDD architecture:
6
+ * - AccountDeletionExecutor for deletion logic
7
+ * - UserValidationService for validation
8
+ * - AccountDeletionRepository for persistence
9
+ *
10
+ * Max lines: 150 (enforced for maintainability)
4
11
  */
5
12
 
6
- import { deleteUser, type User } from "firebase/auth";
7
- import { getFirebaseAuth } from "../../../auth/infrastructure/config/FirebaseAuthClient";
8
- import { markUserDeleted } from "../../../auth/infrastructure/services/user-document.service";
9
- import {
10
- getUserAuthProvider,
11
- reauthenticateWithApple,
12
- reauthenticateWithPassword,
13
- reauthenticateWithGoogle,
14
- } from "./reauthentication.service";
15
- import { successResult, type Result, toErrorInfo } from "../../../../shared/domain/utils";
13
+ import type { User } from "firebase/auth";
16
14
  import type { AccountDeletionOptions } from "../../application/ports/reauthentication.types";
17
- import { validateUserUnchanged } from "../../../auth/domain/utils/user-validation.util";
18
-
19
- export interface AccountDeletionResult extends Result<void> {
20
- requiresReauth?: boolean;
21
- }
22
-
23
- // Operation lock to prevent concurrent deletion attempts
24
- let deletionInProgress = false;
15
+ import { accountDeletionExecutor } from "./AccountDeletionExecutor";
16
+ import type { AccountDeletionResult } from "./AccountDeletionExecutor";
25
17
 
18
+ /**
19
+ * Delete current user account
20
+ * Handles reauthentication automatically if enabled
21
+ *
22
+ * @param options - Deletion options including reauthentication settings
23
+ * @returns Result of deletion operation
24
+ */
26
25
  export async function deleteCurrentUser(
27
26
  options: AccountDeletionOptions = { autoReauthenticate: true }
28
27
  ): Promise<AccountDeletionResult> {
29
- if (deletionInProgress) {
30
- return {
31
- success: false,
32
- error: { code: "auth/operation-in-progress", message: "Account deletion already in progress" },
33
- requiresReauth: false
34
- };
35
- }
36
-
37
- deletionInProgress = true;
38
-
39
- try {
40
- const auth = getFirebaseAuth();
41
- const user = auth?.currentUser;
42
-
43
- if (!auth || !user) {
44
- return {
45
- success: false,
46
- error: { code: "auth/not-ready", message: "Auth not ready" },
47
- requiresReauth: false
48
- };
49
- }
50
-
51
- const originalUserId = user.uid;
52
-
53
- if (user.isAnonymous) {
54
- return {
55
- success: false,
56
- error: { code: "auth/anonymous", message: "Cannot delete anonymous" },
57
- requiresReauth: false
58
- };
59
- }
60
-
61
- const provider = getUserAuthProvider(user);
62
-
63
- if (provider === "password" && options.autoReauthenticate && options.onPasswordRequired) {
64
- const reauth = await attemptReauth(user, options, originalUserId);
65
- if (reauth) {
66
- return reauth;
67
- }
68
- }
69
-
70
- try {
71
- const validation = validateUserUnchanged(auth, originalUserId);
72
- if (!('valid' in validation)) {
73
- return {
74
- success: false,
75
- error: validation.error,
76
- requiresReauth: false
77
- };
78
- }
79
-
80
- const marked = await markUserDeleted(user.uid);
81
- if (!marked && __DEV__) {
82
- console.warn('[AccountDeletion] Failed to mark user document as deleted before account removal');
83
- }
84
- await deleteUser(user);
85
- return successResult();
86
- } catch (error: unknown) {
87
- const errorInfo = toErrorInfo(error, 'auth/failed');
88
- const code = errorInfo.code;
89
- const message = errorInfo.message;
90
-
91
- const hasCredentials = !!(options.password || options.googleIdToken);
92
- const shouldReauth = options.autoReauthenticate === true || hasCredentials;
93
-
94
- if (code === "auth/requires-recent-login" && shouldReauth) {
95
- const reauth = await attemptReauth(user, options, originalUserId);
96
- if (reauth) return reauth;
97
- }
98
-
99
- return {
100
- success: false,
101
- error: { code, message },
102
- requiresReauth: code === "auth/requires-recent-login"
103
- };
104
- }
105
- } finally {
106
- deletionInProgress = false;
107
- }
108
- }
109
-
110
- async function attemptReauth(user: User, options: AccountDeletionOptions, originalUserId?: string): Promise<AccountDeletionResult | null> {
111
- if (originalUserId) {
112
- const authInstance = getFirebaseAuth();
113
- const validation = validateUserUnchanged(authInstance, originalUserId);
114
- if (!('valid' in validation)) {
115
- return {
116
- success: false,
117
- error: validation.error,
118
- requiresReauth: false
119
- };
120
- }
121
- }
122
-
123
- const provider = getUserAuthProvider(user);
124
-
125
- let res: { success: boolean; error?: { code?: string; message?: string } };
126
-
127
- if (provider === "apple.com") {
128
- res = await reauthenticateWithApple(user);
129
- } else if (provider === "google.com") {
130
- let googleToken = options.googleIdToken;
131
- if (!googleToken && options.onGoogleReauthRequired) {
132
- const token = await options.onGoogleReauthRequired();
133
- if (!token) {
134
- return {
135
- success: false,
136
- error: { code: "auth/google-reauth-cancelled", message: "Google reauth cancelled" },
137
- requiresReauth: true
138
- };
139
- }
140
- googleToken = token;
141
- }
142
- if (!googleToken) {
143
- return {
144
- success: false,
145
- error: { code: "auth/google-reauth", message: "Google reauth required" },
146
- requiresReauth: true
147
- };
148
- }
149
- res = await reauthenticateWithGoogle(user, googleToken);
150
- } else if (provider === "password") {
151
- let password = options.password;
152
- if (!password && options.onPasswordRequired) {
153
- const pwd = await options.onPasswordRequired();
154
- if (!pwd) {
155
- return {
156
- success: false,
157
- error: { code: "auth/password-reauth-cancelled", message: "Password reauth cancelled" },
158
- requiresReauth: true
159
- };
160
- }
161
- password = pwd;
162
- }
163
- if (!password) {
164
- return {
165
- success: false,
166
- error: { code: "auth/password-reauth", message: "Password required" },
167
- requiresReauth: true
168
- };
169
- }
170
- res = await reauthenticateWithPassword(user, password);
171
- } else {
172
- return null;
173
- }
174
-
175
- if (res.success) {
176
- try {
177
- const postReauthAuth = getFirebaseAuth();
178
- const currentUser = postReauthAuth?.currentUser || user;
179
-
180
- if (originalUserId) {
181
- const validationCheck = validateUserUnchanged(postReauthAuth, originalUserId);
182
- if (!('valid' in validationCheck)) {
183
- return {
184
- success: false,
185
- error: validationCheck.error,
186
- requiresReauth: false
187
- };
188
- }
189
- }
190
-
191
- const marked = await markUserDeleted(currentUser.uid);
192
- if (!marked && __DEV__) {
193
- console.warn('[AccountDeletion] Failed to mark user document as deleted before account removal (reauth path)');
194
- }
195
- await deleteUser(currentUser);
196
- return successResult();
197
- } catch (err: unknown) {
198
- const errorInfo = toErrorInfo(err, 'auth/failed');
199
- return {
200
- success: false,
201
- error: { code: errorInfo.code, message: errorInfo.message },
202
- requiresReauth: false
203
- };
204
- }
205
- }
206
-
207
- return {
208
- success: false,
209
- error: {
210
- code: res.error?.code || "auth/reauth-failed",
211
- message: res.error?.message || "Reauth failed",
212
- },
213
- requiresReauth: true
214
- };
28
+ return accountDeletionExecutor.deleteCurrentUser(options);
215
29
  }
216
30
 
31
+ /**
32
+ * Delete specific user account
33
+ * Direct deletion without reauthentication
34
+ *
35
+ * @param user - User to delete
36
+ * @returns Result of deletion operation
37
+ */
217
38
  export async function deleteUserAccount(user: User | null): Promise<AccountDeletionResult> {
218
- if (!user || user.isAnonymous) {
219
- return {
220
- success: false,
221
- error: { code: "auth/invalid", message: "Invalid user" },
222
- requiresReauth: false
223
- };
224
- }
39
+ return accountDeletionExecutor.deleteUserAccount(user);
40
+ }
225
41
 
226
- try {
227
- const marked = await markUserDeleted(user.uid);
228
- if (!marked && __DEV__) {
229
- console.warn('[AccountDeletion] Failed to mark user document as deleted (deleteUserAccount)');
230
- }
231
- await deleteUser(user);
232
- return successResult();
233
- } catch (error: unknown) {
234
- const errorInfo = toErrorInfo(error, 'auth/failed');
235
- return {
236
- success: false,
237
- error: { code: errorInfo.code, message: errorInfo.message },
238
- requiresReauth: errorInfo.code === "auth/requires-recent-login"
239
- };
240
- }
42
+ /**
43
+ * Check if deletion is in progress
44
+ * Useful for preventing concurrent deletion attempts
45
+ *
46
+ * @returns True if deletion is currently in progress
47
+ */
48
+ export function isDeletionInProgress(): boolean {
49
+ return accountDeletionExecutor.isDeletionInProgress();
241
50
  }
51
+
52
+ // Re-export types for backward compatibility
53
+ export type { AccountDeletionResult };
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Firebase Auth Domain Layer
3
+ * Domain-Driven Design (DDD) - Domain Exports
4
+ *
5
+ * Pure domain logic without infrastructure concerns.
6
+ * Exports domain entities, value objects, and domain services.
7
+ */
8
+
9
+ // Domain Value Objects
10
+ export type { FirebaseAuthConfig } from './domain/value-objects/FirebaseAuthConfig';
11
+
12
+ // Domain Entities
13
+ export {
14
+ isAnonymousUser,
15
+ } from './domain/entities/AnonymousUser';
16
+ export type { AnonymousUser } from './domain/entities/AnonymousUser';
@@ -1,165 +1,24 @@
1
1
  /**
2
2
  * Firebase Auth Module
3
3
  * Domain-Driven Design (DDD) Architecture
4
+ *
5
+ * Exports organized by DDD layers for better maintainability.
6
+ * Main re-exports everything for backward compatibility.
4
7
  */
5
8
 
6
9
  // =============================================================================
7
10
  // DOMAIN LAYER - Business Logic
8
11
  // =============================================================================
9
-
10
- export type { FirebaseAuthConfig } from './domain/value-objects/FirebaseAuthConfig';
11
-
12
- // Anonymous User Entity
13
- export {
14
- isAnonymousUser,
15
- } from './domain/entities/AnonymousUser';
16
- export type { AnonymousUser } from './domain/entities/AnonymousUser';
12
+ export * from './domain';
17
13
 
18
14
  // =============================================================================
19
15
  // INFRASTRUCTURE LAYER - Implementation
20
16
  // =============================================================================
21
-
22
- export {
23
- getFirebaseAuth,
24
- isFirebaseAuthInitialized,
25
- getFirebaseAuthInitializationError,
26
- resetFirebaseAuthClient,
27
- firebaseAuthClient,
28
- initializeFirebaseAuth,
29
- } from './infrastructure/config/FirebaseAuthClient';
30
-
31
- export type {
32
- Auth,
33
- } from './infrastructure/config/FirebaseAuthClient';
34
-
35
- // Auth Utilities
36
- export {
37
- checkAuthState,
38
- isAuthenticated,
39
- isAnonymous,
40
- getCurrentUserId,
41
- getCurrentUser,
42
- getCurrentUserIdFromGlobal,
43
- getCurrentUserFromGlobal,
44
- isCurrentUserAuthenticated,
45
- isCurrentUserAnonymous,
46
- verifyUserId,
47
- isValidUser,
48
- } from './infrastructure/services/auth-utils.service';
49
-
50
- export type {
51
- AuthCheckResult,
52
- } from './infrastructure/services/auth-utils.service';
53
-
54
- // Anonymous Auth Service
55
- export {
56
- AnonymousAuthService,
57
- anonymousAuthService,
58
- } from './infrastructure/services/anonymous-auth.service';
59
-
60
- export type {
61
- AnonymousAuthResult,
62
- AnonymousAuthServiceInterface,
63
- } from './infrastructure/services/anonymous-auth.service';
64
-
65
- // Firestore Utilities
66
- export {
67
- shouldSkipFirestoreQuery,
68
- createFirestoreQueryOptions,
69
- } from './infrastructure/services/firestore-utils.service';
70
-
71
- export type {
72
- FirestoreQueryOptions,
73
- FirestoreQueryResult,
74
- FirestoreQuerySkipReason,
75
- } from './infrastructure/services/firestore-utils.service';
76
-
17
+ export * from './infrastructure';
77
18
 
78
19
  // =============================================================================
79
- // INFRASTRUCTURE LAYER - Social Auth Services
20
+ // PRESENTATION LAYER - React Hooks
80
21
  // =============================================================================
81
-
82
- export {
83
- GoogleAuthService,
84
- googleAuthService,
85
- } from './infrastructure/services/google-auth.service';
86
- export type {
87
- GoogleAuthConfig,
88
- GoogleAuthResult,
89
- } from './infrastructure/services/google-auth.types';
90
-
91
- export {
92
- GoogleOAuthService,
93
- googleOAuthService,
94
- } from './infrastructure/services/google-oauth.service';
95
- export type {
96
- GoogleOAuthConfig,
97
- } from './infrastructure/services/google-oauth.service';
98
-
99
- export {
100
- AppleAuthService,
101
- appleAuthService,
102
- } from './infrastructure/services/apple-auth.service';
103
- export type { AppleAuthResult } from './infrastructure/services/apple-auth.types';
104
-
105
- // =============================================================================
106
- // PRESENTATION LAYER - Hooks
107
- // =============================================================================
108
-
109
- export { useFirebaseAuth } from './presentation/hooks/useFirebaseAuth';
110
- export type { UseFirebaseAuthResult } from './presentation/hooks/useFirebaseAuth';
111
-
112
- export { useAnonymousAuth } from './presentation/hooks/useAnonymousAuth';
113
- export type { UseAnonymousAuthResult } from './presentation/hooks/useAnonymousAuth';
114
-
115
- export { useSocialAuth } from './presentation/hooks/useSocialAuth';
116
- export type {
117
- SocialAuthConfig,
118
- SocialAuthResult,
119
- UseSocialAuthResult,
120
- } from './presentation/hooks/useSocialAuth';
121
-
122
- export { useGoogleOAuth } from './presentation/hooks/useGoogleOAuth';
123
- export type {
124
- UseGoogleOAuthResult,
125
- } from './presentation/hooks/useGoogleOAuth';
126
-
127
- // Password Management
128
- export {
129
- updateUserPassword,
130
- } from './infrastructure/services/password.service';
131
-
132
- // Email/Password Authentication
133
- export {
134
- signInWithEmail,
135
- signUpWithEmail,
136
- signOut,
137
- linkAnonymousWithEmail,
138
- } from './infrastructure/services/email-auth.service';
139
- export type {
140
- EmailCredentials,
141
- EmailAuthResult,
142
- } from './infrastructure/services/email-auth.service';
143
-
144
- // Auth Listener
145
- export {
146
- setupAuthListener,
147
- } from './infrastructure/services/auth-listener.service';
148
- export type {
149
- AuthListenerConfig,
150
- AuthListenerResult,
151
- } from './infrastructure/services/auth-listener.service';
152
-
153
- // User Document Service
154
- export {
155
- ensureUserDocument,
156
- markUserDeleted,
157
- configureUserDocumentService,
158
- } from './infrastructure/services/user-document.service';
159
- export type {
160
- UserDocumentUser,
161
- UserDocumentConfig,
162
- UserDocumentExtras,
163
- } from './infrastructure/services/user-document.types';
22
+ export * from './presentation';
164
23
 
165
24
 
@@ -0,0 +1,156 @@
1
+ /**
2
+ * Firebase Auth Infrastructure Layer
3
+ * Domain-Driven Design (DDD) - Infrastructure Exports
4
+ *
5
+ * Infrastructure implementation including:
6
+ * - Firebase Auth client configuration
7
+ * - Auth utilities and services
8
+ * - Social auth providers
9
+ * - Email/password authentication
10
+ * - User document management
11
+ */
12
+
13
+ // =============================================================================
14
+ // Firebase Auth Client
15
+ // =============================================================================
16
+
17
+ export {
18
+ getFirebaseAuth,
19
+ isFirebaseAuthInitialized,
20
+ getFirebaseAuthInitializationError,
21
+ resetFirebaseAuthClient,
22
+ firebaseAuthClient,
23
+ initializeFirebaseAuth,
24
+ } from './infrastructure/config/FirebaseAuthClient';
25
+
26
+ export type {
27
+ Auth,
28
+ } from './infrastructure/config/FirebaseAuthClient';
29
+
30
+ // =============================================================================
31
+ // Auth Utilities
32
+ // =============================================================================
33
+
34
+ export {
35
+ checkAuthState,
36
+ isAuthenticated,
37
+ isAnonymous,
38
+ getCurrentUserId,
39
+ getCurrentUser,
40
+ getCurrentUserIdFromGlobal,
41
+ getCurrentUserFromGlobal,
42
+ isCurrentUserAuthenticated,
43
+ isCurrentUserAnonymous,
44
+ verifyUserId,
45
+ isValidUser,
46
+ } from './infrastructure/services/auth-utils.service';
47
+
48
+ export type {
49
+ AuthCheckResult,
50
+ } from './infrastructure/services/auth-utils.service';
51
+
52
+ // =============================================================================
53
+ // Anonymous Auth Service
54
+ // =============================================================================
55
+
56
+ export {
57
+ AnonymousAuthService,
58
+ anonymousAuthService,
59
+ } from './infrastructure/services/anonymous-auth.service';
60
+
61
+ export type {
62
+ AnonymousAuthResult,
63
+ AnonymousAuthServiceInterface,
64
+ } from './infrastructure/services/anonymous-auth.service';
65
+
66
+ // =============================================================================
67
+ // Firestore Utilities
68
+ // =============================================================================
69
+
70
+ export {
71
+ shouldSkipFirestoreQuery,
72
+ createFirestoreQueryOptions,
73
+ } from './infrastructure/services/firestore-utils.service';
74
+
75
+ export type {
76
+ FirestoreQueryOptions,
77
+ FirestoreQueryResult,
78
+ FirestoreQuerySkipReason,
79
+ } from './infrastructure/services/firestore-utils.service';
80
+
81
+ // =============================================================================
82
+ // Social Auth Services
83
+ // =============================================================================
84
+
85
+ export {
86
+ GoogleAuthService,
87
+ googleAuthService,
88
+ } from './infrastructure/services/google-auth.service';
89
+ export type {
90
+ GoogleAuthConfig,
91
+ GoogleAuthResult,
92
+ } from './infrastructure/services/google-auth.types';
93
+
94
+ export {
95
+ GoogleOAuthService,
96
+ googleOAuthService,
97
+ } from './infrastructure/services/google-oauth.service';
98
+ export type {
99
+ GoogleOAuthConfig,
100
+ } from './infrastructure/services/google-oauth.service';
101
+
102
+ export {
103
+ AppleAuthService,
104
+ appleAuthService,
105
+ } from './infrastructure/services/apple-auth.service';
106
+ export type { AppleAuthResult } from './infrastructure/services/apple-auth.types';
107
+
108
+ // =============================================================================
109
+ // Email/Password Authentication
110
+ // =============================================================================
111
+
112
+ export {
113
+ signInWithEmail,
114
+ signUpWithEmail,
115
+ signOut,
116
+ linkAnonymousWithEmail,
117
+ } from './infrastructure/services/email-auth.service';
118
+ export type {
119
+ EmailCredentials,
120
+ EmailAuthResult,
121
+ } from './infrastructure/services/email-auth.service';
122
+
123
+ // =============================================================================
124
+ // Password Management
125
+ // =============================================================================
126
+
127
+ export {
128
+ updateUserPassword,
129
+ } from './infrastructure/services/password.service';
130
+
131
+ // =============================================================================
132
+ // Auth Listener
133
+ // =============================================================================
134
+
135
+ export {
136
+ setupAuthListener,
137
+ } from './infrastructure/services/auth-listener.service';
138
+ export type {
139
+ AuthListenerConfig,
140
+ AuthListenerResult,
141
+ } from './infrastructure/services/auth-listener.service';
142
+
143
+ // =============================================================================
144
+ // User Document Service
145
+ // =============================================================================
146
+
147
+ export {
148
+ ensureUserDocument,
149
+ markUserDeleted,
150
+ configureUserDocumentService,
151
+ } from './infrastructure/services/user-document.service';
152
+ export type {
153
+ UserDocumentUser,
154
+ UserDocumentConfig,
155
+ UserDocumentExtras,
156
+ } from './infrastructure/services/user-document.types';