@umituz/react-native-firebase 1.12.0 → 1.12.2

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.12.0",
3
+ "version": "1.12.2",
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",
@@ -52,4 +52,4 @@
52
52
  "README.md",
53
53
  "LICENSE"
54
54
  ]
55
- }
55
+ }
@@ -1,9 +1,18 @@
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
+ * Uses React Native Firebase v23+ modular API
5
5
  */
6
6
 
7
+ import {
8
+ getAnalytics,
9
+ logEvent,
10
+ setUserId,
11
+ setUserProperties,
12
+ resetAnalyticsData,
13
+ setAnalyticsCollectionEnabled,
14
+ } from '@react-native-firebase/analytics';
15
+
7
16
  export interface NativeAnalyticsAdapter {
8
17
  getAnalytics(): any;
9
18
  logEvent(analytics: any, eventName: string, params?: Record<string, any>): Promise<void>;
@@ -13,70 +22,33 @@ export interface NativeAnalyticsAdapter {
13
22
  setAnalyticsCollectionEnabled(analytics: any, enabled: boolean): Promise<void>;
14
23
  }
15
24
 
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;
25
-
26
- try {
27
- // eslint-disable-next-line @typescript-eslint/no-require-imports
28
- require('@react-native-firebase/app');
29
- // eslint-disable-next-line @typescript-eslint/no-require-imports
30
- const analyticsModule = require('@react-native-firebase/analytics');
31
-
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
- };
43
- }
44
- } catch (error) {
45
- /* eslint-disable-next-line no-console */
46
- if (__DEV__) {
47
- console.warn('⚠️ Firebase Analytics: Native module not available', error);
48
- }
49
- }
50
-
51
- export const nativeAnalyticsAdapter: NativeAnalyticsAdapter | null = modularFunctions
52
- ? {
53
- getAnalytics(): any {
54
- return modularFunctions!.getAnalytics();
55
- },
56
- async logEvent(
57
- analytics: any,
58
- eventName: string,
59
- params?: Record<string, any>,
60
- ): Promise<void> {
61
- await modularFunctions!.logEvent(analytics, eventName, params);
62
- },
63
- async setUserId(analytics: any, userId: string): Promise<void> {
64
- await modularFunctions!.setUserId(analytics, userId);
65
- },
66
- async setUserProperties(
67
- analytics: any,
68
- properties: Record<string, string>,
69
- ): Promise<void> {
70
- await modularFunctions!.setUserProperties(analytics, properties);
71
- },
72
- async resetAnalyticsData(analytics: any): Promise<void> {
73
- await modularFunctions!.resetAnalyticsData(analytics);
74
- },
75
- async setAnalyticsCollectionEnabled(
76
- analytics: any,
77
- enabled: boolean,
78
- ): Promise<void> {
79
- await modularFunctions!.setAnalyticsCollectionEnabled(analytics, enabled);
80
- },
81
- }
82
- : null;
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,12 +1,19 @@
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
+ * Uses React Native Firebase v23+ modular API
5
5
  */
6
6
 
7
- export interface CrashlyticsInstance {
8
- // Instance is now opaque - methods are called via modular functions
9
- }
7
+ import {
8
+ getCrashlytics,
9
+ log,
10
+ recordError,
11
+ setAttribute,
12
+ setUserId,
13
+ } from '@react-native-firebase/crashlytics';
14
+ import type { FirebaseCrashlyticsTypes } from '@react-native-firebase/crashlytics';
15
+
16
+ export type CrashlyticsInstance = FirebaseCrashlyticsTypes.Module;
10
17
 
11
18
  export interface NativeCrashlyticsAdapter {
12
19
  getCrashlytics(): CrashlyticsInstance;
@@ -16,60 +23,13 @@ export interface NativeCrashlyticsAdapter {
16
23
  log(crashlytics: CrashlyticsInstance, message: string): Promise<void>;
17
24
  }
18
25
 
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;
27
-
28
- let isModuleLoaded = false;
29
-
30
- function loadCrashlyticsModule(): void {
31
- if (isModuleLoaded) return;
32
-
33
- try {
34
- // eslint-disable-next-line @typescript-eslint/no-require-imports
35
- require('@react-native-firebase/app');
36
- // eslint-disable-next-line @typescript-eslint/no-require-imports
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
- }
50
- } catch {
51
- // @react-native-firebase/crashlytics not available
52
- } finally {
53
- isModuleLoaded = true;
54
- }
55
- }
56
-
57
- export const nativeCrashlyticsAdapter: NativeCrashlyticsAdapter | null = {
26
+ export const nativeCrashlyticsAdapter: NativeCrashlyticsAdapter = {
58
27
  getCrashlytics(): CrashlyticsInstance {
59
- if (!isModuleLoaded) {
60
- loadCrashlyticsModule();
61
- }
62
-
63
- if (!modularFunctions) {
64
- throw new Error('Crashlytics not initialized');
65
- }
66
-
67
- return modularFunctions.getCrashlytics();
28
+ return getCrashlytics();
68
29
  },
69
30
  async setUserId(crashlytics: CrashlyticsInstance, userId: string): Promise<void> {
70
- if (!modularFunctions) return;
71
31
  try {
72
- await modularFunctions.setUserId(crashlytics, userId);
32
+ await setUserId(crashlytics, userId);
73
33
  } catch (error) {
74
34
  /* eslint-disable-next-line no-console */
75
35
  if (__DEV__) {
@@ -81,9 +41,11 @@ export const nativeCrashlyticsAdapter: NativeCrashlyticsAdapter | null = {
81
41
  crashlytics: CrashlyticsInstance,
82
42
  attributes: Record<string, string>,
83
43
  ): Promise<void> {
84
- if (!modularFunctions) return;
85
44
  try {
86
- await modularFunctions.setAttributes(crashlytics, attributes);
45
+ // Set each attribute individually using the modular API
46
+ for (const [key, value] of Object.entries(attributes)) {
47
+ await setAttribute(crashlytics, key, value);
48
+ }
87
49
  } catch (error) {
88
50
  /* eslint-disable-next-line no-console */
89
51
  if (__DEV__) {
@@ -92,9 +54,8 @@ export const nativeCrashlyticsAdapter: NativeCrashlyticsAdapter | null = {
92
54
  }
93
55
  },
94
56
  async recordError(crashlytics: CrashlyticsInstance, error: Error): Promise<void> {
95
- if (!modularFunctions) return;
96
57
  try {
97
- await modularFunctions.recordError(crashlytics, error);
58
+ await recordError(crashlytics, error);
98
59
  } catch (err) {
99
60
  /* eslint-disable-next-line no-console */
100
61
  if (__DEV__) {
@@ -103,9 +64,8 @@ export const nativeCrashlyticsAdapter: NativeCrashlyticsAdapter | null = {
103
64
  }
104
65
  },
105
66
  async log(crashlytics: CrashlyticsInstance, message: string): Promise<void> {
106
- if (!modularFunctions) return;
107
67
  try {
108
- await modularFunctions.log(crashlytics, message);
68
+ await log(crashlytics, message);
109
69
  } catch (error) {
110
70
  /* eslint-disable-next-line no-console */
111
71
  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
-