@umituz/react-native-firebase 1.2.1 → 1.3.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.
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-firebase",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.3.1",
|
|
4
|
+
"description": "Firebase core package for React Native apps - Centralized initialization for all Firebase services (App, Auth, Analytics, Crashlytics). Use dedicated packages for service-specific operations.",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./src/index.ts",
|
|
7
7
|
"scripts": {
|
package/src/index.ts
CHANGED
|
@@ -178,6 +178,95 @@ export function autoInitializeFirebase(): FirebaseApp | null {
|
|
|
178
178
|
return null;
|
|
179
179
|
}
|
|
180
180
|
|
|
181
|
+
/**
|
|
182
|
+
* Initialize all Firebase services (App, Auth, Analytics, Crashlytics)
|
|
183
|
+
* This is the main entry point for applications - call this once at app startup
|
|
184
|
+
* All services will be initialized automatically if Firebase App is available
|
|
185
|
+
*
|
|
186
|
+
* @param config - Optional Firebase configuration (if not provided, will auto-load from Constants/env)
|
|
187
|
+
* @returns Object with initialization results for each service
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```typescript
|
|
191
|
+
* import { initializeAllFirebaseServices } from '@umituz/react-native-firebase';
|
|
192
|
+
*
|
|
193
|
+
* // Auto-initialize from Constants/env
|
|
194
|
+
* const result = await initializeAllFirebaseServices();
|
|
195
|
+
*
|
|
196
|
+
* // Or provide config explicitly
|
|
197
|
+
* const result = await initializeAllFirebaseServices({
|
|
198
|
+
* apiKey: 'your-api-key',
|
|
199
|
+
* projectId: 'your-project-id',
|
|
200
|
+
* // ...
|
|
201
|
+
* });
|
|
202
|
+
* ```
|
|
203
|
+
*/
|
|
204
|
+
export async function initializeAllFirebaseServices(
|
|
205
|
+
config?: FirebaseConfig
|
|
206
|
+
): Promise<{
|
|
207
|
+
app: FirebaseApp | null;
|
|
208
|
+
auth: any | null;
|
|
209
|
+
analytics: any | null;
|
|
210
|
+
crashlytics: any | null;
|
|
211
|
+
}> {
|
|
212
|
+
// 1. Initialize Firebase App
|
|
213
|
+
let app: FirebaseApp | null = null;
|
|
214
|
+
if (config) {
|
|
215
|
+
app = initializeFirebase(config);
|
|
216
|
+
} else {
|
|
217
|
+
app = autoInitializeFirebase();
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (!app) {
|
|
221
|
+
// Firebase App not available - return null for all services
|
|
222
|
+
return {
|
|
223
|
+
app: null,
|
|
224
|
+
auth: null,
|
|
225
|
+
analytics: null,
|
|
226
|
+
crashlytics: null,
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// 2. Initialize Firebase Auth (if package is available)
|
|
231
|
+
let auth: any | null = null;
|
|
232
|
+
try {
|
|
233
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
234
|
+
const { initializeFirebaseAuth } = require('@umituz/react-native-firebase-auth');
|
|
235
|
+
auth = initializeFirebaseAuth();
|
|
236
|
+
} catch {
|
|
237
|
+
// @umituz/react-native-firebase-auth not available
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// 3. Initialize Firebase Analytics (if package is available)
|
|
241
|
+
let analytics: any | null = null;
|
|
242
|
+
try {
|
|
243
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
244
|
+
const { firebaseAnalyticsService } = require('@umituz/react-native-firebase-analytics');
|
|
245
|
+
await firebaseAnalyticsService.init();
|
|
246
|
+
analytics = firebaseAnalyticsService;
|
|
247
|
+
} catch {
|
|
248
|
+
// @umituz/react-native-firebase-analytics not available
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// 4. Initialize Firebase Crashlytics (if package is available)
|
|
252
|
+
let crashlytics: any | null = null;
|
|
253
|
+
try {
|
|
254
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
255
|
+
const { firebaseCrashlyticsService } = require('@umituz/react-native-firebase-crashlytics');
|
|
256
|
+
await firebaseCrashlyticsService.init();
|
|
257
|
+
crashlytics = firebaseCrashlyticsService;
|
|
258
|
+
} catch {
|
|
259
|
+
// @umituz/react-native-firebase-crashlytics not available
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
return {
|
|
263
|
+
app,
|
|
264
|
+
auth,
|
|
265
|
+
analytics,
|
|
266
|
+
crashlytics,
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
|
|
181
270
|
/**
|
|
182
271
|
* Check if Firebase client is initialized
|
|
183
272
|
*/
|
|
@@ -24,34 +24,38 @@ export function loadFirebaseConfig(): FirebaseConfig | null {
|
|
|
24
24
|
// expo-constants not available, skip
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
// Try both Constants.expoConfig and Constants.default.expoConfig
|
|
28
|
+
const expoConfig = Constants?.expoConfig || Constants?.default?.expoConfig;
|
|
29
|
+
const extra = expoConfig?.extra;
|
|
30
|
+
|
|
27
31
|
const config: Partial<FirebaseConfig> = {
|
|
28
32
|
apiKey:
|
|
29
|
-
|
|
33
|
+
extra?.firebaseApiKey ||
|
|
30
34
|
process.env.EXPO_PUBLIC_FIREBASE_API_KEY ||
|
|
31
35
|
process.env.FIREBASE_API_KEY ||
|
|
32
36
|
'',
|
|
33
37
|
authDomain:
|
|
34
|
-
|
|
38
|
+
extra?.firebaseAuthDomain ||
|
|
35
39
|
process.env.EXPO_PUBLIC_FIREBASE_AUTH_DOMAIN ||
|
|
36
40
|
process.env.FIREBASE_AUTH_DOMAIN ||
|
|
37
41
|
'',
|
|
38
42
|
projectId:
|
|
39
|
-
|
|
43
|
+
extra?.firebaseProjectId ||
|
|
40
44
|
process.env.EXPO_PUBLIC_FIREBASE_PROJECT_ID ||
|
|
41
45
|
process.env.FIREBASE_PROJECT_ID ||
|
|
42
46
|
'',
|
|
43
47
|
storageBucket:
|
|
44
|
-
|
|
48
|
+
extra?.firebaseStorageBucket ||
|
|
45
49
|
process.env.EXPO_PUBLIC_FIREBASE_STORAGE_BUCKET ||
|
|
46
50
|
process.env.FIREBASE_STORAGE_BUCKET ||
|
|
47
51
|
'',
|
|
48
52
|
messagingSenderId:
|
|
49
|
-
|
|
53
|
+
extra?.firebaseMessagingSenderId ||
|
|
50
54
|
process.env.EXPO_PUBLIC_FIREBASE_MESSAGING_SENDER_ID ||
|
|
51
55
|
process.env.FIREBASE_MESSAGING_SENDER_ID ||
|
|
52
56
|
'',
|
|
53
57
|
appId:
|
|
54
|
-
|
|
58
|
+
extra?.firebaseAppId ||
|
|
55
59
|
process.env.EXPO_PUBLIC_FIREBASE_APP_ID ||
|
|
56
60
|
process.env.FIREBASE_APP_ID ||
|
|
57
61
|
'',
|