@umituz/react-native-firebase 1.13.149 → 1.13.151
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/package.json +1 -1
- package/src/auth/infrastructure/services/apple-auth.service.ts +10 -2
- package/src/auth/infrastructure/services/google-auth.service.ts +10 -2
- package/src/auth/infrastructure/services/reauthentication.service.ts +5 -1
- package/src/auth/presentation/hooks/shared/auth-hooks.util.ts +60 -0
- package/src/auth/presentation/hooks/shared/hook-utils.util.ts +14 -216
- package/src/auth/presentation/hooks/shared/safe-state-hooks.util.ts +76 -0
- package/src/auth/presentation/hooks/shared/state-hooks.util.ts +97 -0
- package/src/domain/utils/async-executor.util.ts +16 -169
- package/src/domain/utils/error-handler.util.ts +18 -170
- package/src/domain/utils/error-handlers/error-checkers.ts +120 -0
- package/src/domain/utils/error-handlers/error-converters.ts +48 -0
- package/src/domain/utils/error-handlers/error-messages.ts +18 -0
- package/src/domain/utils/executors/advanced-executors.util.ts +59 -0
- package/src/domain/utils/executors/basic-executors.util.ts +56 -0
- package/src/domain/utils/executors/batch-executors.util.ts +42 -0
- package/src/domain/utils/executors/error-converters.util.ts +45 -0
- package/src/domain/utils/result/result-creators.ts +49 -0
- package/src/domain/utils/result/result-helpers.ts +60 -0
- package/src/domain/utils/result/result-types.ts +40 -0
- package/src/domain/utils/result.util.ts +28 -127
- package/src/domain/utils/validation.util.ts +38 -209
- package/src/domain/utils/validators/composite.validator.ts +24 -0
- package/src/domain/utils/validators/firebase.validator.ts +45 -0
- package/src/domain/utils/validators/generic.validator.ts +59 -0
- package/src/domain/utils/validators/string.validator.ts +25 -0
- package/src/domain/utils/validators/url.validator.ts +36 -0
- package/src/domain/utils/validators/user-input.validator.ts +54 -0
- package/src/firestore/infrastructure/middleware/QuotaTrackingMiddleware.ts +10 -3
- package/src/firestore/utils/deduplication/timer-manager.util.ts +2 -2
- package/src/firestore/utils/pagination.helper.ts +3 -1
- package/src/infrastructure/config/FirebaseClient.ts +29 -189
- package/src/infrastructure/config/clients/FirebaseClientSingleton.ts +82 -0
- package/src/infrastructure/config/services/FirebaseInitializationService.ts +115 -0
- package/src/init/createFirebaseInitModule.ts +9 -3
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Firebase Initialization Service
|
|
3
|
+
* Service layer for Firebase initialization with auth support
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { FirebaseConfig } from '../../../domain/value-objects/FirebaseConfig';
|
|
7
|
+
import type { FirebaseApp } from '../initializers/FirebaseAppInitializer';
|
|
8
|
+
import { FirebaseClientSingleton } from '../clients/FirebaseClientSingleton';
|
|
9
|
+
import { loadFirebaseConfig } from '../FirebaseConfigLoader';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Auth initializer callback type
|
|
13
|
+
* Returns a Promise that resolves when auth initialization is complete
|
|
14
|
+
*/
|
|
15
|
+
export type AuthInitializer = () => Promise<void>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Service initialization options
|
|
19
|
+
*/
|
|
20
|
+
export interface ServiceInitializationOptions {
|
|
21
|
+
authInitializer?: AuthInitializer;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Service initialization result interface
|
|
26
|
+
*/
|
|
27
|
+
export interface ServiceInitializationResult {
|
|
28
|
+
app: FirebaseApp | null;
|
|
29
|
+
auth: boolean | null;
|
|
30
|
+
authError?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Initialize Firebase client with configuration
|
|
35
|
+
*/
|
|
36
|
+
export function initializeFirebase(config: FirebaseConfig): FirebaseApp | null {
|
|
37
|
+
return FirebaseClientSingleton.getInstance().initialize(config);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Get Firebase app instance
|
|
42
|
+
* Auto-initializes from Constants/environment if not already initialized
|
|
43
|
+
*/
|
|
44
|
+
export function getFirebaseApp(): FirebaseApp | null {
|
|
45
|
+
return FirebaseClientSingleton.getInstance().getApp();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Auto-initialize Firebase from Constants/environment
|
|
50
|
+
*/
|
|
51
|
+
export function autoInitializeFirebase(): FirebaseApp | null {
|
|
52
|
+
const config = loadFirebaseConfig();
|
|
53
|
+
if (config) {
|
|
54
|
+
return initializeFirebase(config);
|
|
55
|
+
}
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Initialize all Firebase services (App and Auth)
|
|
61
|
+
* This is the main entry point for applications
|
|
62
|
+
*/
|
|
63
|
+
export async function initializeAllFirebaseServices(
|
|
64
|
+
config?: FirebaseConfig,
|
|
65
|
+
options?: ServiceInitializationOptions
|
|
66
|
+
): Promise<ServiceInitializationResult> {
|
|
67
|
+
const app = config ? initializeFirebase(config) : autoInitializeFirebase();
|
|
68
|
+
|
|
69
|
+
if (!app) {
|
|
70
|
+
return {
|
|
71
|
+
app: null,
|
|
72
|
+
auth: null,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Initialize Auth if provided
|
|
77
|
+
let authSuccess = null;
|
|
78
|
+
let authError: string | undefined;
|
|
79
|
+
|
|
80
|
+
if (options?.authInitializer) {
|
|
81
|
+
try {
|
|
82
|
+
await options.authInitializer();
|
|
83
|
+
authSuccess = true;
|
|
84
|
+
} catch (error) {
|
|
85
|
+
authError = error instanceof Error ? error.message : 'Auth initialization failed';
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return {
|
|
90
|
+
app,
|
|
91
|
+
auth: authSuccess,
|
|
92
|
+
authError,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Check if Firebase client is initialized
|
|
98
|
+
*/
|
|
99
|
+
export function isFirebaseInitialized(): boolean {
|
|
100
|
+
return FirebaseClientSingleton.getInstance().isInitialized();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Get initialization error if any
|
|
105
|
+
*/
|
|
106
|
+
export function getFirebaseInitializationError(): string | null {
|
|
107
|
+
return FirebaseClientSingleton.getInstance().getInitializationError();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Reset Firebase client instance
|
|
112
|
+
*/
|
|
113
|
+
export function resetFirebaseClient(): void {
|
|
114
|
+
FirebaseClientSingleton.getInstance().reset();
|
|
115
|
+
}
|
|
@@ -52,13 +52,17 @@ export function createFirebaseInitModule(
|
|
|
52
52
|
|
|
53
53
|
// Check if initialization was successful
|
|
54
54
|
if (!result.app) {
|
|
55
|
-
|
|
55
|
+
if (__DEV__) {
|
|
56
|
+
console.error('[Firebase] Initialization failed: Firebase app not initialized');
|
|
57
|
+
}
|
|
56
58
|
return false;
|
|
57
59
|
}
|
|
58
60
|
|
|
59
61
|
// Check if auth initialization failed
|
|
60
62
|
if (result.auth === false && result.authError) {
|
|
61
|
-
|
|
63
|
+
if (__DEV__) {
|
|
64
|
+
console.error(`[Firebase] Auth initialization failed: ${result.authError}`);
|
|
65
|
+
}
|
|
62
66
|
// Auth failure is not critical for the app to function
|
|
63
67
|
// Log the error but don't fail the entire initialization
|
|
64
68
|
}
|
|
@@ -66,7 +70,9 @@ export function createFirebaseInitModule(
|
|
|
66
70
|
return true;
|
|
67
71
|
} catch (error) {
|
|
68
72
|
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
69
|
-
|
|
73
|
+
if (__DEV__) {
|
|
74
|
+
console.error(`[Firebase] Initialization failed: ${errorMessage}`);
|
|
75
|
+
}
|
|
70
76
|
return false;
|
|
71
77
|
}
|
|
72
78
|
},
|