@umituz/react-native-firebase 1.3.1 → 1.5.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 +0 -0
- package/README.md +0 -0
- package/lib/application/ports/IFirebaseClient.d.ts +37 -0
- package/lib/application/ports/IFirebaseClient.d.ts.map +1 -0
- package/lib/application/ports/IFirebaseClient.js +8 -0
- package/lib/application/ports/IFirebaseClient.js.map +1 -0
- package/lib/domain/errors/FirebaseError.d.ts +28 -0
- package/lib/domain/errors/FirebaseError.d.ts.map +1 -0
- package/lib/domain/errors/FirebaseError.js +46 -0
- package/lib/domain/errors/FirebaseError.js.map +1 -0
- package/lib/domain/value-objects/FirebaseConfig.d.ts +36 -0
- package/lib/domain/value-objects/FirebaseConfig.d.ts.map +1 -0
- package/lib/domain/value-objects/FirebaseConfig.js +8 -0
- package/lib/domain/value-objects/FirebaseConfig.js.map +1 -0
- package/lib/index.d.ts +26 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +29 -0
- package/lib/index.js.map +1 -0
- package/lib/infrastructure/config/FirebaseClient.d.ts +145 -0
- package/lib/infrastructure/config/FirebaseClient.d.ts.map +1 -0
- package/lib/infrastructure/config/FirebaseClient.js +335 -0
- package/lib/infrastructure/config/FirebaseClient.js.map +1 -0
- package/lib/infrastructure/config/FirebaseConfigLoader.d.ts +16 -0
- package/lib/infrastructure/config/FirebaseConfigLoader.d.ts.map +1 -0
- package/lib/infrastructure/config/FirebaseConfigLoader.js +131 -0
- package/lib/infrastructure/config/FirebaseConfigLoader.js.map +1 -0
- package/lib/infrastructure/config/initializers/FirebaseAppInitializer.d.ts +17 -0
- package/lib/infrastructure/config/initializers/FirebaseAppInitializer.d.ts.map +1 -0
- package/lib/infrastructure/config/initializers/FirebaseAppInitializer.js +83 -0
- package/lib/infrastructure/config/initializers/FirebaseAppInitializer.js.map +1 -0
- package/lib/infrastructure/config/validators/FirebaseConfigValidator.d.ts +18 -0
- package/lib/infrastructure/config/validators/FirebaseConfigValidator.d.ts.map +1 -0
- package/lib/infrastructure/config/validators/FirebaseConfigValidator.js +62 -0
- package/lib/infrastructure/config/validators/FirebaseConfigValidator.js.map +1 -0
- package/package.json +19 -4
- package/src/application/ports/IFirebaseClient.ts +4 -3
- package/src/domain/errors/FirebaseError.ts +0 -0
- package/src/domain/value-objects/FirebaseConfig.ts +0 -0
- package/src/index.ts +0 -0
- package/src/infrastructure/config/FirebaseClient.ts +222 -92
- package/src/infrastructure/config/FirebaseConfigLoader.ts +140 -45
- package/src/infrastructure/config/initializers/FirebaseAppInitializer.ts +67 -27
- package/src/infrastructure/config/validators/FirebaseConfigValidator.ts +58 -25
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Firebase Client - Infrastructure Layer
|
|
3
|
+
*
|
|
4
|
+
* Domain-Driven Design: Infrastructure implementation of Firebase client
|
|
5
|
+
* Singleton pattern for managing Firebase client instance
|
|
6
|
+
*
|
|
7
|
+
* IMPORTANT: This package does NOT read from .env files.
|
|
8
|
+
* Configuration must be provided by the application.
|
|
9
|
+
*
|
|
10
|
+
* SOLID Principles:
|
|
11
|
+
* - Single Responsibility: Only orchestrates initialization, delegates to specialized classes
|
|
12
|
+
* - Open/Closed: Extensible through configuration, closed for modification
|
|
13
|
+
* - Dependency Inversion: Depends on abstractions (interfaces), not concrete implementations
|
|
14
|
+
*/
|
|
15
|
+
import { FirebaseConfigValidator } from './validators/FirebaseConfigValidator';
|
|
16
|
+
import { FirebaseAppInitializer } from './initializers/FirebaseAppInitializer';
|
|
17
|
+
import { loadFirebaseConfig } from './FirebaseConfigLoader';
|
|
18
|
+
/**
|
|
19
|
+
* Firebase Client State Manager
|
|
20
|
+
* Manages the state of Firebase initialization
|
|
21
|
+
*/
|
|
22
|
+
class FirebaseClientState {
|
|
23
|
+
constructor() {
|
|
24
|
+
this.app = null;
|
|
25
|
+
this.initializationError = null;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Get the current Firebase app instance
|
|
29
|
+
*/
|
|
30
|
+
getApp() {
|
|
31
|
+
return this.app;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Set the Firebase app instance
|
|
35
|
+
*/
|
|
36
|
+
setApp(app) {
|
|
37
|
+
this.app = app;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Check if client is initialized
|
|
41
|
+
*/
|
|
42
|
+
isInitialized() {
|
|
43
|
+
return this.app !== null;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Get initialization error if any
|
|
47
|
+
*/
|
|
48
|
+
getInitializationError() {
|
|
49
|
+
return this.initializationError;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Set initialization error
|
|
53
|
+
*/
|
|
54
|
+
setInitializationError(error) {
|
|
55
|
+
this.initializationError = error;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Reset the client state
|
|
59
|
+
*/
|
|
60
|
+
reset() {
|
|
61
|
+
this.app = null;
|
|
62
|
+
this.initializationError = null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Firebase Initialization Orchestrator
|
|
67
|
+
* Handles the initialization logic
|
|
68
|
+
*/
|
|
69
|
+
class FirebaseInitializationOrchestrator {
|
|
70
|
+
/**
|
|
71
|
+
* Initialize Firebase with configuration
|
|
72
|
+
*/
|
|
73
|
+
static initialize(config, state) {
|
|
74
|
+
// Return existing instance if already initialized
|
|
75
|
+
if (state.isInitialized()) {
|
|
76
|
+
if (__DEV__) {
|
|
77
|
+
console.log('[Firebase] Already initialized, returning existing instance');
|
|
78
|
+
}
|
|
79
|
+
return state.getApp();
|
|
80
|
+
}
|
|
81
|
+
// Don't retry if initialization already failed
|
|
82
|
+
if (state.getInitializationError()) {
|
|
83
|
+
if (__DEV__) {
|
|
84
|
+
console.log('[Firebase] Previous initialization failed, skipping retry');
|
|
85
|
+
}
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
try {
|
|
89
|
+
if (__DEV__) {
|
|
90
|
+
console.log('[Firebase] Initializing with projectId:', config.projectId);
|
|
91
|
+
}
|
|
92
|
+
// Validate configuration
|
|
93
|
+
FirebaseConfigValidator.validate(config);
|
|
94
|
+
// Initialize Firebase App
|
|
95
|
+
const app = FirebaseAppInitializer.initialize(config);
|
|
96
|
+
state.setApp(app);
|
|
97
|
+
if (__DEV__) {
|
|
98
|
+
console.log('[Firebase] Successfully initialized');
|
|
99
|
+
}
|
|
100
|
+
return app;
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
const errorMessage = error instanceof Error
|
|
104
|
+
? error.message
|
|
105
|
+
: 'Failed to initialize Firebase client';
|
|
106
|
+
state.setInitializationError(errorMessage);
|
|
107
|
+
if (__DEV__) {
|
|
108
|
+
console.error('[Firebase] Initialization failed:', errorMessage);
|
|
109
|
+
}
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Auto-initialize Firebase from environment
|
|
115
|
+
*/
|
|
116
|
+
static autoInitialize(state) {
|
|
117
|
+
if (state.isInitialized() || state.getInitializationError()) {
|
|
118
|
+
return state.getApp();
|
|
119
|
+
}
|
|
120
|
+
const autoConfig = loadFirebaseConfig();
|
|
121
|
+
if (autoConfig) {
|
|
122
|
+
if (__DEV__) {
|
|
123
|
+
console.log('[Firebase] Auto-initializing with environment config');
|
|
124
|
+
}
|
|
125
|
+
return this.initialize(autoConfig, state);
|
|
126
|
+
}
|
|
127
|
+
if (__DEV__) {
|
|
128
|
+
console.log('[Firebase] No configuration found for auto-initialization');
|
|
129
|
+
}
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Firebase Client Singleton
|
|
135
|
+
* Orchestrates Firebase initialization using specialized initializers
|
|
136
|
+
*/
|
|
137
|
+
class FirebaseClientSingleton {
|
|
138
|
+
constructor() {
|
|
139
|
+
this.state = new FirebaseClientState();
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Get singleton instance
|
|
143
|
+
*/
|
|
144
|
+
static getInstance() {
|
|
145
|
+
if (!FirebaseClientSingleton.instance) {
|
|
146
|
+
FirebaseClientSingleton.instance = new FirebaseClientSingleton();
|
|
147
|
+
}
|
|
148
|
+
return FirebaseClientSingleton.instance;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Initialize Firebase client with configuration
|
|
152
|
+
* Configuration must be provided by the application (not from .env)
|
|
153
|
+
*
|
|
154
|
+
* @param config - Firebase configuration
|
|
155
|
+
* @returns Firebase app instance or null if initialization fails
|
|
156
|
+
*/
|
|
157
|
+
initialize(config) {
|
|
158
|
+
return FirebaseInitializationOrchestrator.initialize(config, this.state);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Get the Firebase app instance
|
|
162
|
+
* Auto-initializes from Constants/environment if not already initialized
|
|
163
|
+
* Returns null if config is not available (offline mode - no error)
|
|
164
|
+
* @returns Firebase app instance or null if not initialized
|
|
165
|
+
*/
|
|
166
|
+
getApp() {
|
|
167
|
+
return FirebaseInitializationOrchestrator.autoInitialize(this.state);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Check if client is initialized
|
|
171
|
+
*/
|
|
172
|
+
isInitialized() {
|
|
173
|
+
return this.state.isInitialized();
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Get initialization error if any
|
|
177
|
+
*/
|
|
178
|
+
getInitializationError() {
|
|
179
|
+
return this.state.getInitializationError();
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Reset the client instance
|
|
183
|
+
* Useful for testing
|
|
184
|
+
*/
|
|
185
|
+
reset() {
|
|
186
|
+
this.state.reset();
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
FirebaseClientSingleton.instance = null;
|
|
190
|
+
/**
|
|
191
|
+
* Singleton instance
|
|
192
|
+
*/
|
|
193
|
+
export const firebaseClient = FirebaseClientSingleton.getInstance();
|
|
194
|
+
/**
|
|
195
|
+
* Initialize Firebase client
|
|
196
|
+
* This is the main entry point for applications
|
|
197
|
+
*
|
|
198
|
+
* @param config - Firebase configuration (must be provided by app, not from .env)
|
|
199
|
+
* @returns Firebase app instance or null if initialization fails
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* ```typescript
|
|
203
|
+
* import { initializeFirebase } from '@umituz/react-native-firebase';
|
|
204
|
+
*
|
|
205
|
+
* const config = {
|
|
206
|
+
* apiKey: 'your-api-key',
|
|
207
|
+
* authDomain: 'your-project.firebaseapp.com',
|
|
208
|
+
* projectId: 'your-project-id',
|
|
209
|
+
* };
|
|
210
|
+
*
|
|
211
|
+
* const app = initializeFirebase(config);
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
214
|
+
export function initializeFirebase(config) {
|
|
215
|
+
return firebaseClient.initialize(config);
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Get Firebase app instance
|
|
219
|
+
* Auto-initializes from Constants/environment if not already initialized
|
|
220
|
+
* Returns null if config is not available (offline mode - no error)
|
|
221
|
+
* @returns Firebase app instance or null if not initialized
|
|
222
|
+
*/
|
|
223
|
+
export function getFirebaseApp() {
|
|
224
|
+
return firebaseClient.getApp();
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Auto-initialize Firebase from Constants/environment
|
|
228
|
+
* Called automatically when getFirebaseApp() is first accessed
|
|
229
|
+
* Can be called manually to initialize early
|
|
230
|
+
* @returns Firebase app instance or null if initialization fails
|
|
231
|
+
*/
|
|
232
|
+
export function autoInitializeFirebase() {
|
|
233
|
+
const config = loadFirebaseConfig();
|
|
234
|
+
if (config) {
|
|
235
|
+
return initializeFirebase(config);
|
|
236
|
+
}
|
|
237
|
+
return null;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Service initializer class for better separation of concerns
|
|
241
|
+
*/
|
|
242
|
+
class ServiceInitializer {
|
|
243
|
+
/**
|
|
244
|
+
* Initialize optional Firebase service with error handling
|
|
245
|
+
*/
|
|
246
|
+
static initializeService(packageName, initializerName, isAsync = false) {
|
|
247
|
+
try {
|
|
248
|
+
const serviceModule = require(packageName);
|
|
249
|
+
const service = serviceModule[initializerName];
|
|
250
|
+
if (isAsync && typeof service.init === 'function') {
|
|
251
|
+
return service;
|
|
252
|
+
}
|
|
253
|
+
return typeof service === 'function' ? service() : service;
|
|
254
|
+
}
|
|
255
|
+
catch {
|
|
256
|
+
return null;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Initialize all optional Firebase services
|
|
261
|
+
*/
|
|
262
|
+
static async initializeServices() {
|
|
263
|
+
if (__DEV__) {
|
|
264
|
+
console.log('[Firebase] Initializing optional services...');
|
|
265
|
+
}
|
|
266
|
+
const auth = this.initializeService('@umituz/react-native-firebase-auth', 'initializeFirebaseAuth');
|
|
267
|
+
const analytics = this.initializeService('@umituz/react-native-firebase-analytics', 'firebaseAnalyticsService', true);
|
|
268
|
+
const crashlytics = this.initializeService('@umituz/react-native-firebase-crashlytics', 'firebaseCrashlyticsService', true);
|
|
269
|
+
if (__DEV__) {
|
|
270
|
+
console.log('[Firebase] Services initialized - Auth:', !!auth, 'Analytics:', !!analytics, 'Crashlytics:', !!crashlytics);
|
|
271
|
+
}
|
|
272
|
+
return { auth, analytics, crashlytics };
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Initialize all Firebase services (App, Auth, Analytics, Crashlytics)
|
|
277
|
+
* This is the main entry point for applications - call this once at app startup
|
|
278
|
+
* All services will be initialized automatically if Firebase App is available
|
|
279
|
+
*
|
|
280
|
+
* @param config - Optional Firebase configuration (if not provided, will auto-load from Constants/env)
|
|
281
|
+
* @returns Object with initialization results for each service
|
|
282
|
+
*
|
|
283
|
+
* @example
|
|
284
|
+
* ```typescript
|
|
285
|
+
* import { initializeAllFirebaseServices } from '@umituz/react-native-firebase';
|
|
286
|
+
*
|
|
287
|
+
* // Auto-initialize from Constants/env
|
|
288
|
+
* const result = await initializeAllFirebaseServices();
|
|
289
|
+
*
|
|
290
|
+
* // Or provide config explicitly
|
|
291
|
+
* const result = await initializeAllFirebaseServices({
|
|
292
|
+
* apiKey: 'your-api-key',
|
|
293
|
+
* projectId: 'your-project-id',
|
|
294
|
+
* // ...
|
|
295
|
+
* });
|
|
296
|
+
* ```
|
|
297
|
+
*/
|
|
298
|
+
export async function initializeAllFirebaseServices(config) {
|
|
299
|
+
const app = config ? initializeFirebase(config) : autoInitializeFirebase();
|
|
300
|
+
if (!app) {
|
|
301
|
+
return {
|
|
302
|
+
app: null,
|
|
303
|
+
auth: null,
|
|
304
|
+
analytics: null,
|
|
305
|
+
crashlytics: null,
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
const { auth, analytics, crashlytics } = await ServiceInitializer.initializeServices();
|
|
309
|
+
return {
|
|
310
|
+
app,
|
|
311
|
+
auth,
|
|
312
|
+
analytics,
|
|
313
|
+
crashlytics,
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Check if Firebase client is initialized
|
|
318
|
+
*/
|
|
319
|
+
export function isFirebaseInitialized() {
|
|
320
|
+
return firebaseClient.isInitialized();
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Get initialization error if any
|
|
324
|
+
*/
|
|
325
|
+
export function getFirebaseInitializationError() {
|
|
326
|
+
return firebaseClient.getInitializationError();
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Reset Firebase client instance
|
|
330
|
+
* Useful for testing
|
|
331
|
+
*/
|
|
332
|
+
export function resetFirebaseClient() {
|
|
333
|
+
firebaseClient.reset();
|
|
334
|
+
}
|
|
335
|
+
//# sourceMappingURL=FirebaseClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FirebaseClient.js","sourceRoot":"","sources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CAAC,KAAK,EAAE,CAAC;AACzB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Firebase Config Loader
|
|
3
|
+
*
|
|
4
|
+
* Automatically loads Firebase configuration from:
|
|
5
|
+
* 1. expo-constants (Constants.expoConfig?.extra)
|
|
6
|
+
* 2. Environment variables (process.env)
|
|
7
|
+
*
|
|
8
|
+
* This allows zero-configuration Firebase initialization.
|
|
9
|
+
*/
|
|
10
|
+
import type { FirebaseConfig } from '../../domain/value-objects/FirebaseConfig';
|
|
11
|
+
/**
|
|
12
|
+
* Load Firebase configuration from Constants and environment variables
|
|
13
|
+
* Returns null if no valid configuration is found
|
|
14
|
+
*/
|
|
15
|
+
export declare function loadFirebaseConfig(): FirebaseConfig | null;
|
|
16
|
+
//# sourceMappingURL=FirebaseConfigLoader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FirebaseConfigLoader.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/config/FirebaseConfigLoader.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2CAA2C,CAAC;AA4IhF;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI,cAAc,GAAG,IAAI,CAe1D"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Firebase Config Loader
|
|
3
|
+
*
|
|
4
|
+
* Automatically loads Firebase configuration from:
|
|
5
|
+
* 1. expo-constants (Constants.expoConfig?.extra)
|
|
6
|
+
* 2. Environment variables (process.env)
|
|
7
|
+
*
|
|
8
|
+
* This allows zero-configuration Firebase initialization.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Expo Constants configuration source
|
|
12
|
+
*/
|
|
13
|
+
class ExpoConfigSource {
|
|
14
|
+
constructor() {
|
|
15
|
+
let Constants;
|
|
16
|
+
try {
|
|
17
|
+
Constants = require('expo-constants');
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
// expo-constants not available
|
|
21
|
+
}
|
|
22
|
+
const expoConfig = Constants?.expoConfig || Constants?.default?.expoConfig;
|
|
23
|
+
this.extra = expoConfig?.extra || {};
|
|
24
|
+
}
|
|
25
|
+
getApiKey() {
|
|
26
|
+
return this.extra?.firebaseApiKey || '';
|
|
27
|
+
}
|
|
28
|
+
getAuthDomain() {
|
|
29
|
+
return this.extra?.firebaseAuthDomain || '';
|
|
30
|
+
}
|
|
31
|
+
getProjectId() {
|
|
32
|
+
return this.extra?.firebaseProjectId || '';
|
|
33
|
+
}
|
|
34
|
+
getStorageBucket() {
|
|
35
|
+
return this.extra?.firebaseStorageBucket || '';
|
|
36
|
+
}
|
|
37
|
+
getMessagingSenderId() {
|
|
38
|
+
return this.extra?.firebaseMessagingSenderId || '';
|
|
39
|
+
}
|
|
40
|
+
getAppId() {
|
|
41
|
+
return this.extra?.firebaseAppId || '';
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Environment variables configuration source
|
|
46
|
+
*/
|
|
47
|
+
class EnvironmentConfigSource {
|
|
48
|
+
getApiKey() {
|
|
49
|
+
return process.env.EXPO_PUBLIC_FIREBASE_API_KEY ||
|
|
50
|
+
process.env.FIREBASE_API_KEY ||
|
|
51
|
+
'';
|
|
52
|
+
}
|
|
53
|
+
getAuthDomain() {
|
|
54
|
+
return process.env.EXPO_PUBLIC_FIREBASE_AUTH_DOMAIN ||
|
|
55
|
+
process.env.FIREBASE_AUTH_DOMAIN ||
|
|
56
|
+
'';
|
|
57
|
+
}
|
|
58
|
+
getProjectId() {
|
|
59
|
+
return process.env.EXPO_PUBLIC_FIREBASE_PROJECT_ID ||
|
|
60
|
+
process.env.FIREBASE_PROJECT_ID ||
|
|
61
|
+
'';
|
|
62
|
+
}
|
|
63
|
+
getStorageBucket() {
|
|
64
|
+
return process.env.EXPO_PUBLIC_FIREBASE_STORAGE_BUCKET ||
|
|
65
|
+
process.env.FIREBASE_STORAGE_BUCKET ||
|
|
66
|
+
'';
|
|
67
|
+
}
|
|
68
|
+
getMessagingSenderId() {
|
|
69
|
+
return process.env.EXPO_PUBLIC_FIREBASE_MESSAGING_SENDER_ID ||
|
|
70
|
+
process.env.FIREBASE_MESSAGING_SENDER_ID ||
|
|
71
|
+
'';
|
|
72
|
+
}
|
|
73
|
+
getAppId() {
|
|
74
|
+
return process.env.EXPO_PUBLIC_FIREBASE_APP_ID ||
|
|
75
|
+
process.env.FIREBASE_APP_ID ||
|
|
76
|
+
'';
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Configuration aggregator
|
|
81
|
+
*/
|
|
82
|
+
class ConfigAggregator {
|
|
83
|
+
constructor() {
|
|
84
|
+
this.sources = [
|
|
85
|
+
new ExpoConfigSource(),
|
|
86
|
+
new EnvironmentConfigSource(),
|
|
87
|
+
];
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Get configuration value from first available source
|
|
91
|
+
*/
|
|
92
|
+
getValue(getter) {
|
|
93
|
+
for (const source of this.sources) {
|
|
94
|
+
const value = getter(source);
|
|
95
|
+
if (value && value.trim() !== '') {
|
|
96
|
+
return value;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return '';
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Build Firebase configuration from all sources
|
|
103
|
+
*/
|
|
104
|
+
buildConfig() {
|
|
105
|
+
return {
|
|
106
|
+
apiKey: this.getValue(source => source.getApiKey()),
|
|
107
|
+
authDomain: this.getValue(source => source.getAuthDomain()),
|
|
108
|
+
projectId: this.getValue(source => source.getProjectId()),
|
|
109
|
+
storageBucket: this.getValue(source => source.getStorageBucket()),
|
|
110
|
+
messagingSenderId: this.getValue(source => source.getMessagingSenderId()),
|
|
111
|
+
appId: this.getValue(source => source.getAppId()),
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Load Firebase configuration from Constants and environment variables
|
|
117
|
+
* Returns null if no valid configuration is found
|
|
118
|
+
*/
|
|
119
|
+
export function loadFirebaseConfig() {
|
|
120
|
+
const aggregator = new ConfigAggregator();
|
|
121
|
+
const config = aggregator.buildConfig();
|
|
122
|
+
// Only return config if required fields are present and not empty
|
|
123
|
+
if (config.apiKey &&
|
|
124
|
+
config.projectId &&
|
|
125
|
+
config.apiKey.trim() !== '' &&
|
|
126
|
+
config.projectId.trim() !== '') {
|
|
127
|
+
return config;
|
|
128
|
+
}
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=FirebaseConfigLoader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FirebaseConfigLoader.js","sourceRoot":"","sources":["../../../src/infrastructure/config/FirebaseConfigLoader.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAgBH;;GAEG;AACH,MAAM,gBAAgB;IAGpB;QACE,IAAI,SAAc,CAAC;QAEnB,IAAI,CAAC;YACH,SAAS,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;QACxC,CAAC;QAAC,MAAM,CAAC;YACP,+BAA+B;QACjC,CAAC;QAED,MAAM,UAAU,GAAG,SAAS,EAAE,UAAU,IAAI,SAAS,EAAE,OAAO,EAAE,UAAU,CAAC;QAC3E,IAAI,CAAC,KAAK,GAAG,UAAU,EAAE,KAAK,IAAI,EAAE,CAAC;IACvC,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,KAAK,EAAE,cAAc,IAAI,EAAE,CAAC;IAC1C,CAAC;IAED,aAAa;QACX,OAAO,IAAI,CAAC,KAAK,EAAE,kBAAkB,IAAI,EAAE,CAAC;IAC9C,CAAC;IAED,YAAY;QACV,OAAO,IAAI,CAAC,KAAK,EAAE,iBAAiB,IAAI,EAAE,CAAC;IAC7C,CAAC;IAED,gBAAgB;QACd,OAAO,IAAI,CAAC,KAAK,EAAE,qBAAqB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CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Firebase App Initializer
|
|
3
|
+
*
|
|
4
|
+
* Single Responsibility: Initialize Firebase App instance
|
|
5
|
+
*/
|
|
6
|
+
import type { FirebaseConfig } from '../../../domain/value-objects/FirebaseConfig';
|
|
7
|
+
export type FirebaseApp = any;
|
|
8
|
+
/**
|
|
9
|
+
* Initializes Firebase App
|
|
10
|
+
*/
|
|
11
|
+
export declare class FirebaseAppInitializer {
|
|
12
|
+
/**
|
|
13
|
+
* Initialize or get existing Firebase App
|
|
14
|
+
*/
|
|
15
|
+
static initialize(config: FirebaseConfig): FirebaseApp;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=FirebaseAppInitializer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FirebaseAppInitializer.d.ts","sourceRoot":"","sources":["../../../../src/infrastructure/config/initializers/FirebaseAppInitializer.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8CAA8C,CAAC;AAGnF,MAAM,MAAM,WAAW,GAAG,GAAG,CAAC;AAsE9B;;GAEG;AACH,qBAAa,sBAAsB;IACjC;;OAEG;IACH,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,cAAc,GAAG,WAAW;CAUvD"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Firebase App Initializer
|
|
3
|
+
*
|
|
4
|
+
* Single Responsibility: Initialize Firebase App instance
|
|
5
|
+
*/
|
|
6
|
+
import { FirebaseInitializationError } from '../../../domain/errors/FirebaseError';
|
|
7
|
+
/**
|
|
8
|
+
* Firebase configuration mapper
|
|
9
|
+
*/
|
|
10
|
+
class FirebaseConfigMapper {
|
|
11
|
+
/**
|
|
12
|
+
* Map domain config to Firebase SDK config
|
|
13
|
+
*/
|
|
14
|
+
static toFirebaseConfig(config) {
|
|
15
|
+
return {
|
|
16
|
+
apiKey: config.apiKey,
|
|
17
|
+
authDomain: config.authDomain,
|
|
18
|
+
projectId: config.projectId,
|
|
19
|
+
storageBucket: config.storageBucket,
|
|
20
|
+
messagingSenderId: config.messagingSenderId,
|
|
21
|
+
appId: config.appId,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Firebase App manager
|
|
27
|
+
*/
|
|
28
|
+
class FirebaseAppManager {
|
|
29
|
+
/**
|
|
30
|
+
* Check if Firebase App is already initialized
|
|
31
|
+
*/
|
|
32
|
+
static isInitialized() {
|
|
33
|
+
try {
|
|
34
|
+
const existingApps = getApps();
|
|
35
|
+
return existingApps.length > 0;
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Get existing Firebase App instance
|
|
43
|
+
*/
|
|
44
|
+
static getExistingApp() {
|
|
45
|
+
try {
|
|
46
|
+
const existingApps = getApps();
|
|
47
|
+
return existingApps.length > 0 ? existingApps[0] : null;
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Create new Firebase App instance
|
|
55
|
+
*/
|
|
56
|
+
static createApp(config) {
|
|
57
|
+
try {
|
|
58
|
+
const firebaseConfig = FirebaseConfigMapper.toFirebaseConfig(config);
|
|
59
|
+
return initializeApp(firebaseConfig);
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
throw new FirebaseInitializationError(`Failed to initialize Firebase App: ${error instanceof Error ? error.message : 'Unknown error'}`, error);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Initializes Firebase App
|
|
68
|
+
*/
|
|
69
|
+
export class FirebaseAppInitializer {
|
|
70
|
+
/**
|
|
71
|
+
* Initialize or get existing Firebase App
|
|
72
|
+
*/
|
|
73
|
+
static initialize(config) {
|
|
74
|
+
// Return existing app if already initialized
|
|
75
|
+
const existingApp = FirebaseAppManager.getExistingApp();
|
|
76
|
+
if (existingApp) {
|
|
77
|
+
return existingApp;
|
|
78
|
+
}
|
|
79
|
+
// Create new app
|
|
80
|
+
return FirebaseAppManager.createApp(config);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=FirebaseAppInitializer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FirebaseAppInitializer.js","sourceRoot":"","sources":["../../../../src/infrastructure/config/initializers/FirebaseAppInitializer.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,2BAA2B,EAAE,MAAM,sCAAsC,CAAC;AAOnF;;GAEG;AACH,MAAM,oBAAoB;IACxB;;OAEG;IACH,MAAM,CAAC,gBAAgB,CAAC,MAAsB;QAC5C,OAAO;YACL,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,UAAU,EAAE,MAAM,CAAC,UAAU;YAC7B,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,aAAa,EAAE,MAAM,CAAC,aAAa;YACnC,iBAAiB,EAAE,MAAM,CAAC,iBAAiB;YAC3C,KAAK,EAAE,MAAM,CAAC,KAAK;SACpB,CAAC;IACJ,CAAC;CACF;AAED;;GAEG;AACH,MAAM,kBAAkB;IACtB;;OAEG;IACH,MAAM,CAAC,aAAa;QAClB,IAAI,CAAC;YACH,MAAM,YAAY,GAAG,OAAO,EAAE,CAAC;YAC/B,OAAO,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC;QACjC,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,cAAc;QACnB,IAAI,CAAC;YACH,MAAM,YAAY,GAAG,OAAO,EAAE,CAAC;YAC/B,OAAO,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAC1D,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,SAAS,CAAC,MAAsB;QACrC,IAAI,CAAC;YACH,MAAM,cAAc,GAAG,oBAAoB,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC;YACrE,OAAO,aAAa,CAAC,cAAc,CAAC,CAAC;QACvC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,2BAA2B,CACnC,sCACE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAC3C,EAAE,EACF,KAAK,CACN,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,sBAAsB;IACjC;;OAEG;IACH,MAAM,CAAC,UAAU,CAAC,MAAsB;QACtC,6CAA6C;QAC7C,MAAM,WAAW,GAAG,kBAAkB,CAAC,cAAc,EAAE,CAAC;QACxD,IAAI,WAAW,EAAE,CAAC;YAChB,OAAO,WAAW,CAAC;QACrB,CAAC;QAED,iBAAiB;QACjB,OAAO,kBAAkB,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAC9C,CAAC;CACF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Firebase Configuration Validator
|
|
3
|
+
*
|
|
4
|
+
* Single Responsibility: Validates Firebase configuration
|
|
5
|
+
*/
|
|
6
|
+
import type { FirebaseConfig } from '../../../domain/value-objects/FirebaseConfig';
|
|
7
|
+
/**
|
|
8
|
+
* Firebase Configuration Validator
|
|
9
|
+
*/
|
|
10
|
+
export declare class FirebaseConfigValidator {
|
|
11
|
+
private static rules;
|
|
12
|
+
/**
|
|
13
|
+
* Validate Firebase configuration
|
|
14
|
+
* @throws {FirebaseConfigurationError} If configuration is invalid
|
|
15
|
+
*/
|
|
16
|
+
static validate(config: FirebaseConfig): void;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=FirebaseConfigValidator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FirebaseConfigValidator.d.ts","sourceRoot":"","sources":["../../../../src/infrastructure/config/validators/FirebaseConfigValidator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8CAA8C,CAAC;AAuDnF;;GAEG;AACH,qBAAa,uBAAuB;IAClC,OAAO,CAAC,MAAM,CAAC,KAAK,CAMlB;IAEF;;;OAGG;IACH,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,cAAc,GAAG,IAAI;CAK9C"}
|