@umituz/react-native-firebase 1.7.0 → 1.7.3

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.
Files changed (31) hide show
  1. package/package.json +9 -4
  2. package/src/analytics/application/ports/IAnalyticsService.ts +92 -0
  3. package/src/analytics/index.ts +19 -0
  4. package/src/analytics/infrastructure/adapters/index.ts +10 -0
  5. package/src/analytics/infrastructure/adapters/native-analytics.adapter.ts +91 -0
  6. package/src/analytics/infrastructure/adapters/web-analytics.adapter.ts +63 -0
  7. package/src/analytics/infrastructure/services/FirebaseAnalyticsService.ts +187 -0
  8. package/src/analytics/infrastructure/services/PerformanceTracker.ts +49 -0
  9. package/src/analytics/infrastructure/services/analytics-event.service.ts +72 -0
  10. package/src/analytics/infrastructure/services/analytics-initializer.service.ts +162 -0
  11. package/src/analytics/infrastructure/services/analytics-user.service.ts +98 -0
  12. package/src/analytics/infrastructure/services/index.ts +12 -0
  13. package/src/analytics/presentation/decorators/PerformanceDecorator.ts +72 -0
  14. package/src/analytics/presentation/decorators/TrackingDecorator.ts +38 -0
  15. package/src/analytics/presentation/hooks/useNavigationTracking.ts +70 -0
  16. package/src/analytics/presentation/hooks/useScreenTime.ts +69 -0
  17. package/src/analytics/presentation/hooks/useScreenView.ts +70 -0
  18. package/src/analytics/presentation/utils/analyticsUtils.ts +78 -0
  19. package/src/crashlytics/index.ts +9 -0
  20. package/src/crashlytics/infrastructure/adapters/index.ts +8 -0
  21. package/src/crashlytics/infrastructure/adapters/native-crashlytics.adapter.ts +125 -0
  22. package/src/crashlytics/infrastructure/services/FirebaseCrashlyticsService.ts +99 -0
  23. package/src/crashlytics/infrastructure/services/crashlytics-error.service.ts +67 -0
  24. package/src/crashlytics/infrastructure/services/crashlytics-initializer.service.ts +31 -0
  25. package/src/crashlytics/infrastructure/services/crashlytics-user.service.ts +91 -0
  26. package/src/crashlytics/infrastructure/services/index.ts +11 -0
  27. package/src/domain/errors/FirebaseError.ts +20 -38
  28. package/src/domain/value-objects/FirebaseConfig.ts +10 -40
  29. package/src/index.ts +18 -22
  30. package/src/infrastructure/config/FirebaseClient.ts +11 -2
  31. package/README.md +0 -221
package/README.md DELETED
@@ -1,221 +0,0 @@
1
- # @umituz/react-native-firebase
2
-
3
- Domain-Driven Design Firebase client for React Native apps with type-safe operations and singleton pattern.
4
-
5
- Built with **SOLID**, **DRY**, and **KISS** principles.
6
-
7
- ## Installation
8
-
9
- ```bash
10
- npm install @umituz/react-native-firebase
11
- ```
12
-
13
- ## Peer Dependencies
14
-
15
- - `firebase` >= 11.0.0
16
- - `react` >= 18.2.0
17
- - `react-native` >= 0.74.0
18
- - `@react-native-async-storage/async-storage` >= 1.21.0
19
-
20
- ## Features
21
-
22
- - ✅ Domain-Driven Design (DDD) architecture
23
- - ✅ SOLID principles (Single Responsibility, Open/Closed, etc.)
24
- - ✅ DRY (Don't Repeat Yourself)
25
- - ✅ KISS (Keep It Simple, Stupid)
26
- - ✅ Singleton pattern for single client instance
27
- - ✅ Type-safe Firebase operations
28
- - ✅ Platform-specific initialization (Web vs Native)
29
- - ✅ **Security**: No .env reading - configuration must be provided by app
30
- - ✅ Works with Expo and React Native CLI
31
-
32
- ## Important: Configuration
33
-
34
- **This package does NOT read from .env files for security reasons.** You must provide configuration from your application code.
35
-
36
- ### Why?
37
-
38
- - **Security**: Prevents accidental exposure of credentials
39
- - **Flexibility**: Works with any configuration source (Constants, config files, etc.)
40
- - **Multi-app support**: Same package can be used across hundreds of apps with different configs
41
-
42
- ## Usage
43
-
44
- ### 1. Initialize Firebase Client
45
-
46
- Initialize the client early in your app (e.g., in `App.tsx` or `index.js`):
47
-
48
- ```typescript
49
- import { initializeFirebase } from '@umituz/react-native-firebase';
50
- import Constants from 'expo-constants';
51
-
52
- // Get configuration from your app's config source
53
- const config = {
54
- apiKey: Constants.expoConfig?.extra?.firebaseApiKey || process.env.EXPO_PUBLIC_FIREBASE_API_KEY!,
55
- authDomain: Constants.expoConfig?.extra?.firebaseAuthDomain || process.env.EXPO_PUBLIC_FIREBASE_AUTH_DOMAIN!,
56
- projectId: Constants.expoConfig?.extra?.firebaseProjectId || process.env.EXPO_PUBLIC_FIREBASE_PROJECT_ID!,
57
- storageBucket: Constants.expoConfig?.extra?.firebaseStorageBucket,
58
- messagingSenderId: Constants.expoConfig?.extra?.firebaseMessagingSenderId,
59
- appId: Constants.expoConfig?.extra?.firebaseAppId,
60
- };
61
-
62
- // Initialize
63
- const app = initializeFirebase(config);
64
-
65
- if (!app) {
66
- console.error('Failed to initialize Firebase');
67
- }
68
- ```
69
-
70
- ### 2. Use Firebase Services
71
-
72
- #### Direct Access
73
-
74
- ```typescript
75
- import { getFirebaseApp } from '@umituz/react-native-firebase';
76
- import { getFirebaseAuth } from '@umituz/react-native-firebase-auth';
77
- import { getFirestore } from '@umituz/react-native-firestore';
78
-
79
- // Get instances
80
- const app = getFirebaseApp();
81
- const auth = getFirebaseAuth();
82
- const db = getFirestore();
83
-
84
- // Use Firebase features
85
- import { signInWithEmailAndPassword } from 'firebase/auth';
86
- import { collection, getDocs } from 'firebase/firestore';
87
-
88
- // Sign in
89
- await signInWithEmailAndPassword(auth, email, password);
90
-
91
- // Query Firestore
92
- const querySnapshot = await getDocs(collection(db, 'users'));
93
- ```
94
-
95
- ### 3. Error Handling
96
-
97
- ```typescript
98
- import {
99
- getFirebaseApp,
100
- FirebaseInitializationError,
101
- FirebaseConfigurationError,
102
- } from '@umituz/react-native-firebase';
103
-
104
- try {
105
- const app = getFirebaseApp();
106
- // Use app
107
- } catch (error) {
108
- if (error instanceof FirebaseInitializationError) {
109
- console.error('Firebase not initialized:', error.message);
110
- } else if (error instanceof FirebaseConfigurationError) {
111
- console.error('Invalid configuration:', error.message);
112
- }
113
- }
114
- ```
115
-
116
- ### 4. Check Initialization Status
117
-
118
- ```typescript
119
- import {
120
- isFirebaseInitialized,
121
- getFirebaseInitializationError,
122
- } from '@umituz/react-native-firebase';
123
-
124
- if (isFirebaseInitialized()) {
125
- console.log('Firebase is ready');
126
- } else {
127
- const error = getFirebaseInitializationError();
128
- console.error('Initialization error:', error);
129
- }
130
- ```
131
-
132
- ## Architecture
133
-
134
- ### SOLID Principles
135
-
136
- - **Single Responsibility**: Each class has one clear purpose
137
- - `FirebaseConfigValidator`: Only validates configuration
138
- - `FirebaseAppInitializer`: Only initializes Firebase App
139
- - `FirebaseClient`: Only orchestrates Firebase App initialization
140
-
141
- - **Open/Closed**: Extensible through configuration, closed for modification
142
-
143
- - **Dependency Inversion**: Depends on abstractions (interfaces), not concrete implementations
144
-
145
- ### DRY (Don't Repeat Yourself)
146
-
147
- - Shared initialization logic extracted to specialized classes
148
- - No code duplication across platforms
149
-
150
- ### KISS (Keep It Simple, Stupid)
151
-
152
- - Simple, focused classes
153
- - Clear responsibilities
154
- - Easy to understand and maintain
155
-
156
- ## API
157
-
158
- ### Functions
159
-
160
- - `initializeFirebase(config)`: Initialize Firebase App with configuration
161
- - `getFirebaseApp()`: Get Firebase App instance (throws if not initialized)
162
- - `isFirebaseInitialized()`: Check if Firebase App is initialized
163
- - `getFirebaseInitializationError()`: Get initialization error if any
164
- - `resetFirebaseClient()`: Reset client instance (useful for testing)
165
-
166
- ### Types
167
-
168
- - `FirebaseConfig`: Configuration interface
169
- - `FirebaseApp`: Firebase App type
170
-
171
- ### Errors
172
-
173
- - `FirebaseError`: Base error class
174
- - `FirebaseInitializationError`: Initialization errors
175
- - `FirebaseConfigurationError`: Configuration errors
176
-
177
- ### Related Packages
178
-
179
- For other Firebase services, use dedicated packages:
180
- - `@umituz/react-native-firebase-auth` - Firebase Authentication
181
- - `@umituz/react-native-firebase-analytics` - Firebase Analytics
182
- - `@umituz/react-native-firebase-crashlytics` - Firebase Crashlytics
183
- - `@umituz/react-native-firestore` - Firestore initialization and utilities
184
-
185
- ## Integration with Expo
186
-
187
- For Expo apps, configure in `app.config.js`:
188
-
189
- ```javascript
190
- module.exports = () => {
191
- return {
192
- expo: {
193
- // ... other config
194
- extra: {
195
- firebaseApiKey: process.env.EXPO_PUBLIC_FIREBASE_API_KEY,
196
- firebaseAuthDomain: process.env.EXPO_PUBLIC_FIREBASE_AUTH_DOMAIN,
197
- firebaseProjectId: process.env.EXPO_PUBLIC_FIREBASE_PROJECT_ID,
198
- firebaseStorageBucket: process.env.EXPO_PUBLIC_FIREBASE_STORAGE_BUCKET,
199
- firebaseMessagingSenderId: process.env.EXPO_PUBLIC_FIREBASE_MESSAGING_SENDER_ID,
200
- firebaseAppId: process.env.EXPO_PUBLIC_FIREBASE_APP_ID,
201
- },
202
- },
203
- };
204
- };
205
- ```
206
-
207
- ## Security Best Practices
208
-
209
- 1. **Never commit credentials**: Use environment variables or secure config files
210
- 2. **Use proper Firebase security rules**: Configure Firestore and Storage rules
211
- 3. **Implement RLS**: Use Firebase security rules for data protection
212
- 4. **Clear user data on logout**: Always clear user data on logout (GDPR compliance)
213
-
214
- ## License
215
-
216
- MIT
217
-
218
-
219
-
220
-
221
-