@umituz/react-native-firebase 1.11.0 → 1.12.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-firebase",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.0",
|
|
4
4
|
"description": "Unified Firebase package for React Native apps - Centralized initialization and core services (Analytics, Crashlytics).",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./src/index.ts",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Native Analytics Adapter
|
|
3
3
|
* Single Responsibility: Handle Firebase Analytics native implementation
|
|
4
|
+
* Uses React Native Firebase v22+ modular API
|
|
4
5
|
*/
|
|
5
6
|
|
|
6
7
|
export interface NativeAnalyticsAdapter {
|
|
@@ -12,7 +13,15 @@ export interface NativeAnalyticsAdapter {
|
|
|
12
13
|
setAnalyticsCollectionEnabled(analytics: any, enabled: boolean): Promise<void>;
|
|
13
14
|
}
|
|
14
15
|
|
|
15
|
-
|
|
16
|
+
// Modular API functions from @react-native-firebase/analytics
|
|
17
|
+
let modularFunctions: {
|
|
18
|
+
getAnalytics: () => any;
|
|
19
|
+
logEvent: (analytics: any, name: string, params?: Record<string, any>) => Promise<void>;
|
|
20
|
+
setUserId: (analytics: any, id: string | null) => Promise<void>;
|
|
21
|
+
setUserProperties: (analytics: any, properties: Record<string, string | null>) => Promise<void>;
|
|
22
|
+
resetAnalyticsData: (analytics: any) => Promise<void>;
|
|
23
|
+
setAnalyticsCollectionEnabled: (analytics: any, enabled: boolean) => Promise<void>;
|
|
24
|
+
} | null = null;
|
|
16
25
|
|
|
17
26
|
try {
|
|
18
27
|
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
@@ -20,23 +29,17 @@ try {
|
|
|
20
29
|
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
21
30
|
const analyticsModule = require('@react-native-firebase/analytics');
|
|
22
31
|
|
|
23
|
-
//
|
|
24
|
-
//
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
// ES6 default export in CommonJS format
|
|
35
|
-
nativeAnalyticsModule = analyticsModule.default;
|
|
36
|
-
} else if (analyticsModule && typeof analyticsModule === 'object') {
|
|
37
|
-
// Try to use the module itself if it's callable
|
|
38
|
-
// Some bundlers wrap the function in an object
|
|
39
|
-
nativeAnalyticsModule = analyticsModule;
|
|
32
|
+
// Extract modular functions from the module
|
|
33
|
+
// React Native Firebase v22+ exports these as named exports
|
|
34
|
+
if (analyticsModule.getAnalytics && typeof analyticsModule.getAnalytics === 'function') {
|
|
35
|
+
modularFunctions = {
|
|
36
|
+
getAnalytics: analyticsModule.getAnalytics,
|
|
37
|
+
logEvent: analyticsModule.logEvent,
|
|
38
|
+
setUserId: analyticsModule.setUserId,
|
|
39
|
+
setUserProperties: analyticsModule.setUserProperties,
|
|
40
|
+
resetAnalyticsData: analyticsModule.resetAnalyticsData,
|
|
41
|
+
setAnalyticsCollectionEnabled: analyticsModule.setAnalyticsCollectionEnabled,
|
|
42
|
+
};
|
|
40
43
|
}
|
|
41
44
|
} catch (error) {
|
|
42
45
|
/* eslint-disable-next-line no-console */
|
|
@@ -45,47 +48,35 @@ try {
|
|
|
45
48
|
}
|
|
46
49
|
}
|
|
47
50
|
|
|
48
|
-
export const nativeAnalyticsAdapter: NativeAnalyticsAdapter | null =
|
|
49
|
-
|
|
50
|
-
? {
|
|
51
|
+
export const nativeAnalyticsAdapter: NativeAnalyticsAdapter | null = modularFunctions
|
|
52
|
+
? {
|
|
51
53
|
getAnalytics(): any {
|
|
52
|
-
|
|
53
|
-
if (typeof nativeAnalyticsModule === 'function') {
|
|
54
|
-
return nativeAnalyticsModule();
|
|
55
|
-
}
|
|
56
|
-
// If it's an object, try calling it directly (some modules are callable objects)
|
|
57
|
-
if (typeof nativeAnalyticsModule === 'object' && nativeAnalyticsModule.default) {
|
|
58
|
-
return typeof nativeAnalyticsModule.default === 'function'
|
|
59
|
-
? nativeAnalyticsModule.default()
|
|
60
|
-
: nativeAnalyticsModule.default;
|
|
61
|
-
}
|
|
62
|
-
return nativeAnalyticsModule;
|
|
54
|
+
return modularFunctions!.getAnalytics();
|
|
63
55
|
},
|
|
64
56
|
async logEvent(
|
|
65
57
|
analytics: any,
|
|
66
58
|
eventName: string,
|
|
67
59
|
params?: Record<string, any>,
|
|
68
60
|
): Promise<void> {
|
|
69
|
-
await
|
|
61
|
+
await modularFunctions!.logEvent(analytics, eventName, params);
|
|
70
62
|
},
|
|
71
63
|
async setUserId(analytics: any, userId: string): Promise<void> {
|
|
72
|
-
await
|
|
64
|
+
await modularFunctions!.setUserId(analytics, userId);
|
|
73
65
|
},
|
|
74
66
|
async setUserProperties(
|
|
75
67
|
analytics: any,
|
|
76
68
|
properties: Record<string, string>,
|
|
77
69
|
): Promise<void> {
|
|
78
|
-
await
|
|
70
|
+
await modularFunctions!.setUserProperties(analytics, properties);
|
|
79
71
|
},
|
|
80
72
|
async resetAnalyticsData(analytics: any): Promise<void> {
|
|
81
|
-
await
|
|
73
|
+
await modularFunctions!.resetAnalyticsData(analytics);
|
|
82
74
|
},
|
|
83
75
|
async setAnalyticsCollectionEnabled(
|
|
84
76
|
analytics: any,
|
|
85
77
|
enabled: boolean,
|
|
86
78
|
): Promise<void> {
|
|
87
|
-
await
|
|
79
|
+
await modularFunctions!.setAnalyticsCollectionEnabled(analytics, enabled);
|
|
88
80
|
},
|
|
89
81
|
}
|
|
90
|
-
|
|
91
|
-
|
|
82
|
+
: null;
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Native Crashlytics Adapter
|
|
3
3
|
* Single Responsibility: Handle Firebase Crashlytics native implementation
|
|
4
|
+
* Uses React Native Firebase v22+ modular API
|
|
4
5
|
*/
|
|
5
6
|
|
|
6
7
|
export interface CrashlyticsInstance {
|
|
7
|
-
|
|
8
|
-
setAttributes(attributes: Record<string, string>): Promise<void>;
|
|
9
|
-
recordError(error: Error): Promise<void>;
|
|
10
|
-
log(message: string): Promise<void>;
|
|
8
|
+
// Instance is now opaque - methods are called via modular functions
|
|
11
9
|
}
|
|
12
10
|
|
|
13
11
|
export interface NativeCrashlyticsAdapter {
|
|
@@ -18,28 +16,37 @@ export interface NativeCrashlyticsAdapter {
|
|
|
18
16
|
log(crashlytics: CrashlyticsInstance, message: string): Promise<void>;
|
|
19
17
|
}
|
|
20
18
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
19
|
+
// Modular API functions from @react-native-firebase/crashlytics
|
|
20
|
+
let modularFunctions: {
|
|
21
|
+
getCrashlytics: () => CrashlyticsInstance;
|
|
22
|
+
setUserId: (crashlytics: CrashlyticsInstance, userId: string) => Promise<void>;
|
|
23
|
+
setAttributes: (crashlytics: CrashlyticsInstance, attributes: Record<string, string>) => Promise<void>;
|
|
24
|
+
recordError: (crashlytics: CrashlyticsInstance, error: Error) => Promise<void>;
|
|
25
|
+
log: (crashlytics: CrashlyticsInstance, message: string) => Promise<void>;
|
|
26
|
+
} | null = null;
|
|
28
27
|
|
|
29
|
-
type NativeCrashlyticsModule = NativeCrashlyticsModuleFunction | NativeCrashlyticsModuleObject;
|
|
30
|
-
|
|
31
|
-
let nativeCrashlyticsModule: NativeCrashlyticsModule | null = null;
|
|
32
28
|
let isModuleLoaded = false;
|
|
33
29
|
|
|
34
30
|
function loadCrashlyticsModule(): void {
|
|
35
31
|
if (isModuleLoaded) return;
|
|
36
|
-
|
|
32
|
+
|
|
37
33
|
try {
|
|
38
34
|
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
39
35
|
require('@react-native-firebase/app');
|
|
40
36
|
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
41
|
-
const
|
|
42
|
-
|
|
37
|
+
const crashlyticsModule = require('@react-native-firebase/crashlytics');
|
|
38
|
+
|
|
39
|
+
// Extract modular functions from the module
|
|
40
|
+
// React Native Firebase v22+ exports these as named exports
|
|
41
|
+
if (crashlyticsModule.getCrashlytics && typeof crashlyticsModule.getCrashlytics === 'function') {
|
|
42
|
+
modularFunctions = {
|
|
43
|
+
getCrashlytics: crashlyticsModule.getCrashlytics,
|
|
44
|
+
setUserId: crashlyticsModule.setUserId,
|
|
45
|
+
setAttributes: crashlyticsModule.setAttributes,
|
|
46
|
+
recordError: crashlyticsModule.recordError,
|
|
47
|
+
log: crashlyticsModule.log,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
43
50
|
} catch {
|
|
44
51
|
// @react-native-firebase/crashlytics not available
|
|
45
52
|
} finally {
|
|
@@ -47,41 +54,22 @@ function loadCrashlyticsModule(): void {
|
|
|
47
54
|
}
|
|
48
55
|
}
|
|
49
56
|
|
|
50
|
-
function getCrashlyticsInstance(): CrashlyticsInstance | null {
|
|
51
|
-
if (!isModuleLoaded) {
|
|
52
|
-
loadCrashlyticsModule();
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (!nativeCrashlyticsModule) return null;
|
|
56
|
-
|
|
57
|
-
try {
|
|
58
|
-
if (typeof nativeCrashlyticsModule === 'function') {
|
|
59
|
-
return nativeCrashlyticsModule();
|
|
60
|
-
}
|
|
61
|
-
if ('default' in nativeCrashlyticsModule && typeof nativeCrashlyticsModule.default === 'function') {
|
|
62
|
-
return nativeCrashlyticsModule.default();
|
|
63
|
-
}
|
|
64
|
-
} catch (error) {
|
|
65
|
-
/* eslint-disable-next-line no-console */
|
|
66
|
-
if (__DEV__) {
|
|
67
|
-
console.warn('[Crashlytics] Failed to get instance:', error);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return null;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
57
|
export const nativeCrashlyticsAdapter: NativeCrashlyticsAdapter | null = {
|
|
75
58
|
getCrashlytics(): CrashlyticsInstance {
|
|
76
|
-
|
|
77
|
-
|
|
59
|
+
if (!isModuleLoaded) {
|
|
60
|
+
loadCrashlyticsModule();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (!modularFunctions) {
|
|
78
64
|
throw new Error('Crashlytics not initialized');
|
|
79
65
|
}
|
|
80
|
-
|
|
66
|
+
|
|
67
|
+
return modularFunctions.getCrashlytics();
|
|
81
68
|
},
|
|
82
69
|
async setUserId(crashlytics: CrashlyticsInstance, userId: string): Promise<void> {
|
|
70
|
+
if (!modularFunctions) return;
|
|
83
71
|
try {
|
|
84
|
-
await
|
|
72
|
+
await modularFunctions.setUserId(crashlytics, userId);
|
|
85
73
|
} catch (error) {
|
|
86
74
|
/* eslint-disable-next-line no-console */
|
|
87
75
|
if (__DEV__) {
|
|
@@ -93,8 +81,9 @@ export const nativeCrashlyticsAdapter: NativeCrashlyticsAdapter | null = {
|
|
|
93
81
|
crashlytics: CrashlyticsInstance,
|
|
94
82
|
attributes: Record<string, string>,
|
|
95
83
|
): Promise<void> {
|
|
84
|
+
if (!modularFunctions) return;
|
|
96
85
|
try {
|
|
97
|
-
await
|
|
86
|
+
await modularFunctions.setAttributes(crashlytics, attributes);
|
|
98
87
|
} catch (error) {
|
|
99
88
|
/* eslint-disable-next-line no-console */
|
|
100
89
|
if (__DEV__) {
|
|
@@ -103,8 +92,9 @@ export const nativeCrashlyticsAdapter: NativeCrashlyticsAdapter | null = {
|
|
|
103
92
|
}
|
|
104
93
|
},
|
|
105
94
|
async recordError(crashlytics: CrashlyticsInstance, error: Error): Promise<void> {
|
|
95
|
+
if (!modularFunctions) return;
|
|
106
96
|
try {
|
|
107
|
-
await
|
|
97
|
+
await modularFunctions.recordError(crashlytics, error);
|
|
108
98
|
} catch (err) {
|
|
109
99
|
/* eslint-disable-next-line no-console */
|
|
110
100
|
if (__DEV__) {
|
|
@@ -113,8 +103,9 @@ export const nativeCrashlyticsAdapter: NativeCrashlyticsAdapter | null = {
|
|
|
113
103
|
}
|
|
114
104
|
},
|
|
115
105
|
async log(crashlytics: CrashlyticsInstance, message: string): Promise<void> {
|
|
106
|
+
if (!modularFunctions) return;
|
|
116
107
|
try {
|
|
117
|
-
await
|
|
108
|
+
await modularFunctions.log(crashlytics, message);
|
|
118
109
|
} catch (error) {
|
|
119
110
|
/* eslint-disable-next-line no-console */
|
|
120
111
|
if (__DEV__) {
|