@umituz/react-native-firebase 1.11.0 → 1.12.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,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/react-native-firebase",
3
- "version": "1.11.0",
3
+ "version": "1.12.1",
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,8 +1,18 @@
1
1
  /**
2
2
  * Native Analytics Adapter
3
3
  * Single Responsibility: Handle Firebase Analytics native implementation
4
+ * Uses React Native Firebase v23+ modular API
4
5
  */
5
6
 
7
+ import {
8
+ getAnalytics,
9
+ logEvent,
10
+ setUserId,
11
+ setUserProperties,
12
+ resetAnalyticsData,
13
+ setAnalyticsCollectionEnabled,
14
+ } from '@react-native-firebase/analytics';
15
+
6
16
  export interface NativeAnalyticsAdapter {
7
17
  getAnalytics(): any;
8
18
  logEvent(analytics: any, eventName: string, params?: Record<string, any>): Promise<void>;
@@ -12,80 +22,33 @@ export interface NativeAnalyticsAdapter {
12
22
  setAnalyticsCollectionEnabled(analytics: any, enabled: boolean): Promise<void>;
13
23
  }
14
24
 
15
- let nativeAnalyticsModule: any = null;
16
-
17
- try {
18
- // eslint-disable-next-line @typescript-eslint/no-require-imports
19
- require('@react-native-firebase/app');
20
- // eslint-disable-next-line @typescript-eslint/no-require-imports
21
- const analyticsModule = require('@react-native-firebase/analytics');
22
-
23
- // @react-native-firebase/analytics returns a factory function via createModuleNamespace
24
- // Handle CommonJS (require) and ES6 (import) module formats
25
- // The module can be:
26
- // 1. Direct function: analyticsModule()
27
- // 2. Object with default: analyticsModule.default()
28
- // 3. Object with __esModule: analyticsModule.default() or analyticsModule()
29
-
30
- if (typeof analyticsModule === 'function') {
31
- // Direct function export
32
- nativeAnalyticsModule = analyticsModule;
33
- } else if (analyticsModule && typeof analyticsModule.default === 'function') {
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;
40
- }
41
- } catch (error) {
42
- /* eslint-disable-next-line no-console */
43
- if (__DEV__) {
44
- console.warn('⚠️ Firebase Analytics: Native module not available', error);
45
- }
46
- }
47
-
48
- export const nativeAnalyticsAdapter: NativeAnalyticsAdapter | null =
49
- nativeAnalyticsModule && (typeof nativeAnalyticsModule === 'function' || typeof nativeAnalyticsModule === 'object')
50
- ? {
51
- getAnalytics(): any {
52
- // Try calling as function first, then as object method
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;
63
- },
64
- async logEvent(
65
- analytics: any,
66
- eventName: string,
67
- params?: Record<string, any>,
68
- ): Promise<void> {
69
- await analytics.logEvent(eventName, params);
70
- },
71
- async setUserId(analytics: any, userId: string): Promise<void> {
72
- await analytics.setUserId(userId);
73
- },
74
- async setUserProperties(
75
- analytics: any,
76
- properties: Record<string, string>,
77
- ): Promise<void> {
78
- await analytics.setUserProperties(properties);
79
- },
80
- async resetAnalyticsData(analytics: any): Promise<void> {
81
- await analytics.resetAnalyticsData();
82
- },
83
- async setAnalyticsCollectionEnabled(
84
- analytics: any,
85
- enabled: boolean,
86
- ): Promise<void> {
87
- await analytics.setAnalyticsCollectionEnabled(enabled);
88
- },
89
- }
90
- : null;
91
-
25
+ export const nativeAnalyticsAdapter: NativeAnalyticsAdapter = {
26
+ getAnalytics(): any {
27
+ return getAnalytics();
28
+ },
29
+ async logEvent(
30
+ analytics: any,
31
+ eventName: string,
32
+ params?: Record<string, any>,
33
+ ): Promise<void> {
34
+ await logEvent(analytics, eventName, params);
35
+ },
36
+ async setUserId(analytics: any, userId: string): Promise<void> {
37
+ await setUserId(analytics, userId);
38
+ },
39
+ async setUserProperties(
40
+ analytics: any,
41
+ properties: Record<string, string>,
42
+ ): Promise<void> {
43
+ await setUserProperties(analytics, properties);
44
+ },
45
+ async resetAnalyticsData(analytics: any): Promise<void> {
46
+ await resetAnalyticsData(analytics);
47
+ },
48
+ async setAnalyticsCollectionEnabled(
49
+ analytics: any,
50
+ enabled: boolean,
51
+ ): Promise<void> {
52
+ await setAnalyticsCollectionEnabled(analytics, enabled);
53
+ },
54
+ };
@@ -1,13 +1,18 @@
1
1
  /**
2
2
  * Native Crashlytics Adapter
3
3
  * Single Responsibility: Handle Firebase Crashlytics native implementation
4
+ * Uses React Native Firebase v23+ modular API
4
5
  */
5
6
 
7
+ import {
8
+ getCrashlytics,
9
+ log,
10
+ recordError,
11
+ setAttribute,
12
+ } from '@react-native-firebase/crashlytics';
13
+
6
14
  export interface CrashlyticsInstance {
7
- setUserId(userId: string): Promise<void>;
8
- setAttributes(attributes: Record<string, string>): Promise<void>;
9
- recordError(error: Error): Promise<void>;
10
- log(message: string): Promise<void>;
15
+ // Instance is now opaque - methods are called via modular functions
11
16
  }
12
17
 
13
18
  export interface NativeCrashlyticsAdapter {
@@ -18,70 +23,14 @@ export interface NativeCrashlyticsAdapter {
18
23
  log(crashlytics: CrashlyticsInstance, message: string): Promise<void>;
19
24
  }
20
25
 
21
- interface NativeCrashlyticsModuleFunction {
22
- (): CrashlyticsInstance;
23
- }
24
-
25
- interface NativeCrashlyticsModuleObject {
26
- default: () => CrashlyticsInstance;
27
- }
28
-
29
- type NativeCrashlyticsModule = NativeCrashlyticsModuleFunction | NativeCrashlyticsModuleObject;
30
-
31
- let nativeCrashlyticsModule: NativeCrashlyticsModule | null = null;
32
- let isModuleLoaded = false;
33
-
34
- function loadCrashlyticsModule(): void {
35
- if (isModuleLoaded) return;
36
-
37
- try {
38
- // eslint-disable-next-line @typescript-eslint/no-require-imports
39
- require('@react-native-firebase/app');
40
- // eslint-disable-next-line @typescript-eslint/no-require-imports
41
- const crashlytics = require('@react-native-firebase/crashlytics');
42
- nativeCrashlyticsModule = crashlytics;
43
- } catch {
44
- // @react-native-firebase/crashlytics not available
45
- } finally {
46
- isModuleLoaded = true;
47
- }
48
- }
49
-
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
- export const nativeCrashlyticsAdapter: NativeCrashlyticsAdapter | null = {
26
+ export const nativeCrashlyticsAdapter: NativeCrashlyticsAdapter = {
75
27
  getCrashlytics(): CrashlyticsInstance {
76
- const instance = getCrashlyticsInstance();
77
- if (!instance) {
78
- throw new Error('Crashlytics not initialized');
79
- }
80
- return instance;
28
+ return getCrashlytics() as CrashlyticsInstance;
81
29
  },
82
30
  async setUserId(crashlytics: CrashlyticsInstance, userId: string): Promise<void> {
83
31
  try {
84
- await crashlytics.setUserId(userId);
32
+ // Note: setUserId is a method on the crashlytics instance, not a modular function
33
+ await (crashlytics as any).setUserId(userId);
85
34
  } catch (error) {
86
35
  /* eslint-disable-next-line no-console */
87
36
  if (__DEV__) {
@@ -94,7 +43,10 @@ export const nativeCrashlyticsAdapter: NativeCrashlyticsAdapter | null = {
94
43
  attributes: Record<string, string>,
95
44
  ): Promise<void> {
96
45
  try {
97
- await crashlytics.setAttributes(attributes);
46
+ // Set each attribute individually using the modular API
47
+ for (const [key, value] of Object.entries(attributes)) {
48
+ await setAttribute(crashlytics, key, value);
49
+ }
98
50
  } catch (error) {
99
51
  /* eslint-disable-next-line no-console */
100
52
  if (__DEV__) {
@@ -104,7 +56,7 @@ export const nativeCrashlyticsAdapter: NativeCrashlyticsAdapter | null = {
104
56
  },
105
57
  async recordError(crashlytics: CrashlyticsInstance, error: Error): Promise<void> {
106
58
  try {
107
- await crashlytics.recordError(error);
59
+ await recordError(crashlytics, error);
108
60
  } catch (err) {
109
61
  /* eslint-disable-next-line no-console */
110
62
  if (__DEV__) {
@@ -114,7 +66,7 @@ export const nativeCrashlyticsAdapter: NativeCrashlyticsAdapter | null = {
114
66
  },
115
67
  async log(crashlytics: CrashlyticsInstance, message: string): Promise<void> {
116
68
  try {
117
- await crashlytics.log(message);
69
+ await log(crashlytics, message);
118
70
  } catch (error) {
119
71
  /* eslint-disable-next-line no-console */
120
72
  if (__DEV__) {
package/LICENSE DELETED
@@ -1,33 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2024 Ümit UZ
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
22
-
23
-
24
-
25
-
26
-
27
-
28
-
29
-
30
-
31
-
32
-
33
-