@umituz/react-native-firebase 1.13.57 → 1.13.59
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/README.md +277 -0
- package/package.json +1 -1
- package/scripts/README.md +513 -0
- package/src/auth/README.md +339 -0
- package/src/auth/domain/README.md +264 -0
- package/src/auth/domain/errors/README.md +291 -0
- package/src/auth/infrastructure/config/README.md +239 -0
- package/src/auth/infrastructure/services/README.md +346 -0
- package/src/auth/infrastructure/stores/README.md +407 -0
- package/src/auth/presentation/hooks/README.md +442 -0
- package/src/domain/README.md +628 -0
- package/src/firestore/README.md +566 -0
- package/src/firestore/domain/README.md +325 -0
- package/src/firestore/domain/constants/README.md +332 -0
- package/src/firestore/domain/entities/README.md +286 -0
- package/src/firestore/domain/errors/README.md +389 -0
- package/src/firestore/infrastructure/config/README.md +239 -0
- package/src/firestore/infrastructure/middleware/README.md +316 -0
- package/src/firestore/infrastructure/repositories/README.md +425 -0
- package/src/firestore/infrastructure/services/README.md +332 -0
- package/src/firestore/types/pagination/README.md +332 -0
- package/src/firestore/utils/README.md +574 -0
- package/src/firestore/utils/dateUtils/README.md +171 -0
- package/src/firestore/utils/document-mapper.helper/README.md +309 -0
- package/src/firestore/utils/pagination.helper/README.md +298 -0
- package/src/firestore/utils/path-resolver/README.md +277 -0
- package/src/firestore/utils/query-builder/README.md +291 -0
- package/src/firestore/utils/quota-error-detector/README.md +355 -0
- package/src/infrastructure/README.md +408 -0
- package/src/infrastructure/config/README.md +262 -0
- package/src/presentation/README.md +556 -0
- package/src/storage/README.md +493 -0
- package/src/storage/deleter/README.md +370 -0
- package/src/storage/types/README.md +313 -0
- package/src/storage/uploader/README.md +409 -0
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
# Infrastructure Services
|
|
2
|
+
|
|
3
|
+
Core infrastructure services providing shared functionality across the application.
|
|
4
|
+
|
|
5
|
+
## Purpose
|
|
6
|
+
|
|
7
|
+
Provides infrastructure-level services for state management, error handling, logging, configuration, and utility functions used across all Firebase modules.
|
|
8
|
+
|
|
9
|
+
## For AI Agents
|
|
10
|
+
|
|
11
|
+
### Before Using Infrastructure Services
|
|
12
|
+
|
|
13
|
+
1. **USE** stores for global state management
|
|
14
|
+
2. **HANDLE** errors through centralized error handler
|
|
15
|
+
3. **LOG** events with appropriate log levels
|
|
16
|
+
4. **VALIDATE** configuration before use
|
|
17
|
+
5. **NEVER** create duplicate stores or services
|
|
18
|
+
|
|
19
|
+
### Required Practices
|
|
20
|
+
|
|
21
|
+
1. **Use Zustand stores** - Leverage provided stores for global state
|
|
22
|
+
2. **Centralize error handling** - Use errorHandler for all errors
|
|
23
|
+
3. **Log appropriately** - Use correct log levels (debug, info, warn, error)
|
|
24
|
+
4. **Validate configuration** - Check config before using services
|
|
25
|
+
5. **Use utilities** - Leverage provided utility functions
|
|
26
|
+
|
|
27
|
+
### Forbidden Practices
|
|
28
|
+
|
|
29
|
+
## ❌ NEVER
|
|
30
|
+
|
|
31
|
+
- Create duplicate state stores
|
|
32
|
+
- Handle errors inline without errorHandler
|
|
33
|
+
- Use console.log directly (use logger instead)
|
|
34
|
+
- Skip configuration validation
|
|
35
|
+
- Create duplicate utility functions
|
|
36
|
+
|
|
37
|
+
## ⚠️ Avoid
|
|
38
|
+
|
|
39
|
+
- Local state for global data
|
|
40
|
+
- Silent error swallowing
|
|
41
|
+
- Inconsistent log levels
|
|
42
|
+
- Hardcoded configuration
|
|
43
|
+
- Reinventing existing utilities
|
|
44
|
+
|
|
45
|
+
## State Management
|
|
46
|
+
|
|
47
|
+
### Auth Store
|
|
48
|
+
|
|
49
|
+
**Import From:** `@umituz/react-native-firebase/infrastructure` or `src/infrastructure`
|
|
50
|
+
|
|
51
|
+
**Hook:** `useAuthStore()`
|
|
52
|
+
|
|
53
|
+
**Purpose:** Manage authentication state globally
|
|
54
|
+
|
|
55
|
+
**State Properties:**
|
|
56
|
+
- `user: User | null` - Current authenticated user
|
|
57
|
+
- `isAuthenticated: boolean` - Authentication status
|
|
58
|
+
- `isLoading: boolean` - Loading state
|
|
59
|
+
- `error: Error | null` - Authentication error
|
|
60
|
+
|
|
61
|
+
**Actions:**
|
|
62
|
+
- `setUser(user)` - Set current user
|
|
63
|
+
- `setLoading(loading)` - Set loading state
|
|
64
|
+
- `setError(error)` - Set error
|
|
65
|
+
- `clearError()` - Clear error
|
|
66
|
+
- `logout()` - Logout user
|
|
67
|
+
|
|
68
|
+
**Usage Strategy:**
|
|
69
|
+
1. Import useAuthStore from infrastructure
|
|
70
|
+
2. Select only needed state (not entire store)
|
|
71
|
+
3. Use for authentication status checks
|
|
72
|
+
4. Update state through actions
|
|
73
|
+
5. Persist state automatically
|
|
74
|
+
|
|
75
|
+
**When to Use:**
|
|
76
|
+
- Authentication status checks
|
|
77
|
+
- User data access
|
|
78
|
+
- Global auth state management
|
|
79
|
+
- Protected route logic
|
|
80
|
+
|
|
81
|
+
### User Store
|
|
82
|
+
|
|
83
|
+
**Import From:** `@umituz/react-native-firebase/infrastructure` or `src/infrastructure`
|
|
84
|
+
|
|
85
|
+
**Hook:** `useUserStore()`
|
|
86
|
+
|
|
87
|
+
**Purpose:** Manage user data state globally
|
|
88
|
+
|
|
89
|
+
**State Properties:**
|
|
90
|
+
- `userData: UserData | null` - User profile data
|
|
91
|
+
- `loading: boolean` - Data loading state
|
|
92
|
+
- `error: Error | null` - Data fetch error
|
|
93
|
+
|
|
94
|
+
**Actions:**
|
|
95
|
+
- `fetchUserData(userId)` - Fetch user from Firestore
|
|
96
|
+
- `updateUserData(data)` - Update user data
|
|
97
|
+
- `clearUserData()` - Clear user data
|
|
98
|
+
|
|
99
|
+
**Usage Strategy:**
|
|
100
|
+
1. Import useUserStore from infrastructure
|
|
101
|
+
2. Select only needed properties
|
|
102
|
+
3. Fetch data on mount if needed
|
|
103
|
+
4. Handle loading and error states
|
|
104
|
+
5. Clear data on logout
|
|
105
|
+
|
|
106
|
+
**When to Use:**
|
|
107
|
+
- User profile management
|
|
108
|
+
- User data display
|
|
109
|
+
- User updates
|
|
110
|
+
- User state synchronization
|
|
111
|
+
|
|
112
|
+
## Error Handling
|
|
113
|
+
|
|
114
|
+
### Error Handler
|
|
115
|
+
|
|
116
|
+
**Import From:** `@umituz/react-native-firebase/infrastructure` or `src/infrastructure`
|
|
117
|
+
|
|
118
|
+
**Service:** `errorHandler`
|
|
119
|
+
|
|
120
|
+
**Purpose:** Centralized error handling and reporting
|
|
121
|
+
|
|
122
|
+
**Method:** `handle(error, options?)`
|
|
123
|
+
|
|
124
|
+
**Parameters:**
|
|
125
|
+
- `error: unknown` - Error to handle
|
|
126
|
+
- `options?: { context?, action?, showToast? }`
|
|
127
|
+
|
|
128
|
+
**Usage Strategy:**
|
|
129
|
+
1. Wrap operations in try-catch
|
|
130
|
+
2. Call errorHandler.handle() in catch
|
|
131
|
+
3. Provide context and action
|
|
132
|
+
4. Show toast if needed
|
|
133
|
+
5. Error logged and tracked automatically
|
|
134
|
+
|
|
135
|
+
**When to Use:**
|
|
136
|
+
- All error scenarios
|
|
137
|
+
- API failures
|
|
138
|
+
- Auth errors
|
|
139
|
+
- Firestore errors
|
|
140
|
+
- Validation errors
|
|
141
|
+
|
|
142
|
+
**Error Handling Flow:**
|
|
143
|
+
1. Normalize error to Error instance
|
|
144
|
+
2. Log error with context
|
|
145
|
+
3. Notify error listeners
|
|
146
|
+
4. Show toast if requested
|
|
147
|
+
5. Track error in analytics
|
|
148
|
+
|
|
149
|
+
## Logging
|
|
150
|
+
|
|
151
|
+
### Logger
|
|
152
|
+
|
|
153
|
+
**Import From:** `@umituz/react-native-firebase/infrastructure` or `src/infrastructure`
|
|
154
|
+
|
|
155
|
+
**Service:** `logger`
|
|
156
|
+
|
|
157
|
+
**Purpose:** Structured logging with levels
|
|
158
|
+
|
|
159
|
+
**Methods:**
|
|
160
|
+
- `debug(message, context?)` - Debug messages (DEV only)
|
|
161
|
+
- `info(message, context?)` - Informational messages
|
|
162
|
+
- `warn(message, context?)` - Warning messages
|
|
163
|
+
- `error(message, context?)` - Error messages
|
|
164
|
+
|
|
165
|
+
**Usage Strategy:**
|
|
166
|
+
1. Use appropriate log level
|
|
167
|
+
2. Include context object with relevant data
|
|
168
|
+
3. Debug only in development
|
|
169
|
+
4. Info for important events
|
|
170
|
+
5. Warn for concerning situations
|
|
171
|
+
6. Error for failures
|
|
172
|
+
|
|
173
|
+
**When to Use:**
|
|
174
|
+
- Debug: Development debugging
|
|
175
|
+
- Info: User actions, state changes
|
|
176
|
+
- Warn: Deprecated usage, unexpected but valid
|
|
177
|
+
- Error: Failures, exceptions
|
|
178
|
+
|
|
179
|
+
**Log Levels:**
|
|
180
|
+
- Debug: Detailed development info
|
|
181
|
+
- Info: General informational messages
|
|
182
|
+
- Warn: Warning conditions
|
|
183
|
+
- Error: Error conditions
|
|
184
|
+
|
|
185
|
+
## Configuration
|
|
186
|
+
|
|
187
|
+
### Config Manager
|
|
188
|
+
|
|
189
|
+
**Import From:** `@umituz/react-native-firebase/infrastructure` or `src/infrastructure`
|
|
190
|
+
|
|
191
|
+
**Service:** `configManager`
|
|
192
|
+
|
|
193
|
+
**Purpose:** Configuration management and validation
|
|
194
|
+
|
|
195
|
+
**Methods:**
|
|
196
|
+
- `set(key, value)` - Set config value
|
|
197
|
+
- `get<T>(key, defaultValue?)` - Get config value
|
|
198
|
+
- `getAll()` - Get all config
|
|
199
|
+
- `loadFromEnv()` - Load from environment
|
|
200
|
+
- `validate(requiredKeys)` - Validate config
|
|
201
|
+
|
|
202
|
+
**Usage Strategy:**
|
|
203
|
+
1. Load config from environment on startup
|
|
204
|
+
2. Validate required config keys
|
|
205
|
+
3. Access config with get() method
|
|
206
|
+
4. Provide default values when possible
|
|
207
|
+
5. Handle missing config errors
|
|
208
|
+
|
|
209
|
+
**When to Use:**
|
|
210
|
+
- App initialization
|
|
211
|
+
- Environment-specific settings
|
|
212
|
+
- Firebase configuration
|
|
213
|
+
- Feature flags
|
|
214
|
+
- API endpoints
|
|
215
|
+
|
|
216
|
+
## Utility Functions
|
|
217
|
+
|
|
218
|
+
### Async Utilities
|
|
219
|
+
|
|
220
|
+
**Import From:** `@umituz/react-native-firebase/infrastructure` or `src/infrastructure`
|
|
221
|
+
|
|
222
|
+
**Functions:**
|
|
223
|
+
- `retry(fn, maxRetries?, delay?)` - Retry with exponential backoff
|
|
224
|
+
- `debounce(fn, delay)` - Debounce function calls
|
|
225
|
+
- `throttle(fn, delay)` - Throttle function calls
|
|
226
|
+
|
|
227
|
+
**Usage Strategy:**
|
|
228
|
+
1. Use retry for unreliable operations
|
|
229
|
+
2. Use debounce for search/input
|
|
230
|
+
3. Use throttle for scroll/resize
|
|
231
|
+
4. Configure delay appropriately
|
|
232
|
+
5. Handle errors in retry
|
|
233
|
+
|
|
234
|
+
**When to Use:**
|
|
235
|
+
- Retry: API calls, network operations
|
|
236
|
+
- Debounce: Search boxes, input validation
|
|
237
|
+
- Throttle: Scroll events, resize handlers
|
|
238
|
+
|
|
239
|
+
### Validation Utilities
|
|
240
|
+
|
|
241
|
+
**Import From:** `@umituz/react-native-firebase/infrastructure` or `src/infrastructure`
|
|
242
|
+
|
|
243
|
+
**Functions:**
|
|
244
|
+
- `isValidEmail(email)` - Validate email format
|
|
245
|
+
- `isValidUrl(url)` - Validate URL format
|
|
246
|
+
- `validateRequired(data, requiredFields)` - Validate required fields
|
|
247
|
+
|
|
248
|
+
**Usage Strategy:**
|
|
249
|
+
1. Validate before API calls
|
|
250
|
+
2. Check email format on input
|
|
251
|
+
3. Validate URLs before navigation
|
|
252
|
+
4. Use validateRequired for forms
|
|
253
|
+
5. Show validation errors to users
|
|
254
|
+
|
|
255
|
+
**When to Use:**
|
|
256
|
+
- Form validation
|
|
257
|
+
- Input validation
|
|
258
|
+
- API request validation
|
|
259
|
+
- User signup/update
|
|
260
|
+
|
|
261
|
+
## Common Mistakes to Avoid
|
|
262
|
+
|
|
263
|
+
1. ❌ Creating duplicate state stores
|
|
264
|
+
- ✅ Use provided infrastructure stores
|
|
265
|
+
|
|
266
|
+
2. ❌ Handling errors inline
|
|
267
|
+
- ✅ Use centralized errorHandler
|
|
268
|
+
|
|
269
|
+
3. ❌ Using console.log directly
|
|
270
|
+
- ✅ Use logger with appropriate levels
|
|
271
|
+
|
|
272
|
+
4. ❌ Hardcoding configuration
|
|
273
|
+
- ✅ Use configManager with environment variables
|
|
274
|
+
|
|
275
|
+
5. ❌ Reinventing utilities
|
|
276
|
+
- ✅ Use provided utility functions
|
|
277
|
+
|
|
278
|
+
## AI Agent Instructions
|
|
279
|
+
|
|
280
|
+
### When Creating State
|
|
281
|
+
|
|
282
|
+
1. Check if store already exists
|
|
283
|
+
2. Use Zustand for global state
|
|
284
|
+
3. Provide actions for state updates
|
|
285
|
+
4. Select specific properties (not entire store)
|
|
286
|
+
5. Persist state if needed
|
|
287
|
+
|
|
288
|
+
### When Handling Errors
|
|
289
|
+
|
|
290
|
+
1. Wrap operations in try-catch
|
|
291
|
+
2. Use errorHandler.handle()
|
|
292
|
+
3. Provide context and action
|
|
293
|
+
4. Show user-friendly messages
|
|
294
|
+
5. Log errors appropriately
|
|
295
|
+
|
|
296
|
+
### When Logging
|
|
297
|
+
|
|
298
|
+
1. Use appropriate log level
|
|
299
|
+
2. Include context with relevant data
|
|
300
|
+
3. Debug only in development
|
|
301
|
+
4. Log important events
|
|
302
|
+
5. Don't log sensitive data
|
|
303
|
+
|
|
304
|
+
### When Validating
|
|
305
|
+
|
|
306
|
+
1. Validate before operations
|
|
307
|
+
2. Use validation utilities
|
|
308
|
+
3. Show clear error messages
|
|
309
|
+
4. Validate on client and server
|
|
310
|
+
5. Handle validation errors
|
|
311
|
+
|
|
312
|
+
## Code Quality Standards
|
|
313
|
+
|
|
314
|
+
### State Management
|
|
315
|
+
|
|
316
|
+
- Use Zustand stores
|
|
317
|
+
- Select specific properties
|
|
318
|
+
- Update through actions
|
|
319
|
+
- Persist when needed
|
|
320
|
+
- Handle loading states
|
|
321
|
+
|
|
322
|
+
### Error Handling
|
|
323
|
+
|
|
324
|
+
- Centralize error handling
|
|
325
|
+
- Provide context
|
|
326
|
+
- Show user-friendly messages
|
|
327
|
+
- Log all errors
|
|
328
|
+
- Track in analytics
|
|
329
|
+
|
|
330
|
+
### Logging
|
|
331
|
+
|
|
332
|
+
- Use appropriate levels
|
|
333
|
+
- Include context
|
|
334
|
+
- Don't log sensitive data
|
|
335
|
+
- Debug in development only
|
|
336
|
+
- Structure logs consistently
|
|
337
|
+
|
|
338
|
+
## Performance Considerations
|
|
339
|
+
|
|
340
|
+
### State Selectors
|
|
341
|
+
|
|
342
|
+
- Select specific properties (not entire store)
|
|
343
|
+
- Avoid unnecessary re-renders
|
|
344
|
+
- Use shallow equality when possible
|
|
345
|
+
- Batch state updates
|
|
346
|
+
- Persist state efficiently
|
|
347
|
+
|
|
348
|
+
### Error Handling
|
|
349
|
+
|
|
350
|
+
- Don't swallow errors
|
|
351
|
+
- Provide context for debugging
|
|
352
|
+
- Track errors asynchronously
|
|
353
|
+
- Show user feedback
|
|
354
|
+
- Don't block on error tracking
|
|
355
|
+
|
|
356
|
+
### Logging
|
|
357
|
+
|
|
358
|
+
- Minimize logging in production
|
|
359
|
+
- Use appropriate log levels
|
|
360
|
+
- Avoid expensive operations in logs
|
|
361
|
+
- Don't log in tight loops
|
|
362
|
+
- Structure logs for parsing
|
|
363
|
+
|
|
364
|
+
## Related Documentation
|
|
365
|
+
|
|
366
|
+
- [Auth Infrastructure README](../auth/infrastructure/README.md)
|
|
367
|
+
- [Firestore Infrastructure README](../firestore/infrastructure/README.md)
|
|
368
|
+
- [Storage Infrastructure README](../storage/README.md)
|
|
369
|
+
- [Firebase Config README](./config/README.md)
|
|
370
|
+
|
|
371
|
+
## API Reference
|
|
372
|
+
|
|
373
|
+
### Stores
|
|
374
|
+
|
|
375
|
+
**Import Path:** `@umituz/react-native-firebase/infrastructure` or `src/infrastructure`
|
|
376
|
+
|
|
377
|
+
| Hook | State | Actions |
|
|
378
|
+
|------|-------|---------|
|
|
379
|
+
| `useAuthStore` | `user, isAuthenticated, isLoading, error` | `setUser, setLoading, setError, clearError, logout` |
|
|
380
|
+
| `useUserStore` | `userData, loading, error` | `fetchUserData, updateUserData, clearUserData` |
|
|
381
|
+
|
|
382
|
+
### Services
|
|
383
|
+
|
|
384
|
+
**Import Path:** `@umituz/react-native-firebase/infrastructure` or `src/infrastructure`
|
|
385
|
+
|
|
386
|
+
| Service | Methods | Description |
|
|
387
|
+
|---------|---------|-------------|
|
|
388
|
+
| `errorHandler` | `handle(error, options?)` | Centralized error handling |
|
|
389
|
+
| `logger` | `debug, info, warn, error` | Structured logging |
|
|
390
|
+
| `configManager` | `set, get, getAll, loadFromEnv, validate` | Configuration management |
|
|
391
|
+
|
|
392
|
+
### Utilities
|
|
393
|
+
|
|
394
|
+
**Import Path:** `@umituz/react-native-firebase/infrastructure` or `src/infrastructure`
|
|
395
|
+
|
|
396
|
+
| Function | Parameters | Return Type | Description |
|
|
397
|
+
|----------|------------|-------------|-------------|
|
|
398
|
+
| `retry` | `fn, maxRetries?, delay?` | `Promise<T>` | Retry with backoff |
|
|
399
|
+
| `debounce` | `fn, delay` | Function | Debounce function |
|
|
400
|
+
| `throttle` | `fn, delay` | Function | Throttle function |
|
|
401
|
+
| `isValidEmail` | `email` | `boolean` | Validate email |
|
|
402
|
+
| `isValidUrl` | `url` | `boolean` | Validate URL |
|
|
403
|
+
| `validateRequired` | `data, fields` | Validation result | Validate required fields |
|
|
404
|
+
|
|
405
|
+
---
|
|
406
|
+
|
|
407
|
+
**Last Updated:** 2025-01-08
|
|
408
|
+
**Maintainer:** Infrastructure Team
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
# Firebase Infrastructure Configuration
|
|
2
|
+
|
|
3
|
+
Core Firebase client initialization, configuration management, and service orchestration for the entire package.
|
|
4
|
+
|
|
5
|
+
## Purpose
|
|
6
|
+
|
|
7
|
+
Provides foundational Firebase initialization and configuration system used by all modules (Auth, Firestore, Storage), handling app initialization, config loading/validation, service orchestration, state management, and error handling.
|
|
8
|
+
|
|
9
|
+
## For AI Agents
|
|
10
|
+
|
|
11
|
+
### Before Using Firebase Config
|
|
12
|
+
|
|
13
|
+
1. **INITIALIZE** Firebase once at app startup
|
|
14
|
+
2. **USE** environment variables for config
|
|
15
|
+
3. **VALIDATE** config before initialization
|
|
16
|
+
4. **HANDLE** initialization errors appropriately
|
|
17
|
+
5. **NEVER** initialize multiple times
|
|
18
|
+
|
|
19
|
+
### Required Practices
|
|
20
|
+
|
|
21
|
+
1. **Initialize once** - Call initializeFirebase() at app startup
|
|
22
|
+
2. **Use environment variables** - Load config from env, not hardcoded
|
|
23
|
+
3. **Validate config** - Check all required fields present
|
|
24
|
+
4. **Handle errors** - Show user-friendly error messages
|
|
25
|
+
5. **Check initialization** - Verify before using Firebase services
|
|
26
|
+
|
|
27
|
+
### Forbidden Practices
|
|
28
|
+
|
|
29
|
+
## ❌ NEVER
|
|
30
|
+
|
|
31
|
+
- Initialize Firebase multiple times
|
|
32
|
+
- Hardcode Firebase config
|
|
33
|
+
- Skip config validation
|
|
34
|
+
- Ignore initialization errors
|
|
35
|
+
- Use Firebase services before initialization
|
|
36
|
+
|
|
37
|
+
## ⚠️ Avoid
|
|
38
|
+
|
|
39
|
+
- Initializing Firebase in components
|
|
40
|
+
- Not checking initialization status
|
|
41
|
+
- Invalid config values
|
|
42
|
+
- Missing required config fields
|
|
43
|
+
- Initializing synchronously
|
|
44
|
+
|
|
45
|
+
## Initialization Strategy
|
|
46
|
+
|
|
47
|
+
### Basic Initialization
|
|
48
|
+
|
|
49
|
+
**Import From:** `@umituz/react-native-firebase` or `src/infrastructure/config`
|
|
50
|
+
|
|
51
|
+
**Function:** `initializeFirebase(config?)`
|
|
52
|
+
|
|
53
|
+
**Parameters:**
|
|
54
|
+
- `config?: FirebaseConfig` - Optional config object (uses env if not provided)
|
|
55
|
+
|
|
56
|
+
**Returns:** `Promise<void>`
|
|
57
|
+
|
|
58
|
+
**When to Use:**
|
|
59
|
+
- App startup (before any Firebase usage)
|
|
60
|
+
- Root component initialization
|
|
61
|
+
- Before using Auth, Firestore, or Storage
|
|
62
|
+
|
|
63
|
+
**Initialization Flow:**
|
|
64
|
+
1. Load config from env or parameter
|
|
65
|
+
2. Validate config fields
|
|
66
|
+
3. Initialize Firebase app
|
|
67
|
+
4. Initialize services (Auth, Firestore, Storage)
|
|
68
|
+
5. Set initialization state
|
|
69
|
+
|
|
70
|
+
### Configuration from Environment
|
|
71
|
+
|
|
72
|
+
**Import From:** `@umituz/react-native-firebase` or `src/infrastructure/config`
|
|
73
|
+
|
|
74
|
+
**Strategy:** Load config automatically from environment variables
|
|
75
|
+
|
|
76
|
+
**Required Environment Variables:**
|
|
77
|
+
- `EXPO_PUBLIC_FIREBASE_API_KEY` - Firebase API key
|
|
78
|
+
- `EXPO_PUBLIC_FIREBASE_AUTH_DOMAIN` - Auth domain
|
|
79
|
+
- `EXPO_PUBLIC_FIREBASE_PROJECT_ID` - Project ID
|
|
80
|
+
- `EXPO_PUBLIC_FIREBASE_STORAGE_BUCKET` - Storage bucket
|
|
81
|
+
- `EXPO_PUBLIC_FIREBASE_MESSAGING_SENDER_ID` - Sender ID
|
|
82
|
+
- `EXPO_PUBLIC_FIREBASE_APP_ID` - App ID
|
|
83
|
+
|
|
84
|
+
**Usage:**
|
|
85
|
+
1. Set environment variables in .env file
|
|
86
|
+
2. Call `initializeFirebase()` without parameters
|
|
87
|
+
3. Config auto-loaded from environment
|
|
88
|
+
4. Services initialized with config
|
|
89
|
+
|
|
90
|
+
**Benefits:**
|
|
91
|
+
- No hardcoded credentials
|
|
92
|
+
- Environment-specific configs
|
|
93
|
+
- Security (credentials not in code)
|
|
94
|
+
- Easy deployment management
|
|
95
|
+
|
|
96
|
+
### Manual Configuration
|
|
97
|
+
|
|
98
|
+
**Import From:** `@umituz/react-native-firebase` or `src/infrastructure/config`
|
|
99
|
+
|
|
100
|
+
**Strategy:** Provide config object directly to initializeFirebase()
|
|
101
|
+
|
|
102
|
+
**When to Use:**
|
|
103
|
+
- Testing without env vars
|
|
104
|
+
- Dynamic configuration
|
|
105
|
+
- Multi-tenant applications
|
|
106
|
+
- Config from external service
|
|
107
|
+
|
|
108
|
+
**Config Object Properties:**
|
|
109
|
+
- `apiKey: string` - Firebase API key
|
|
110
|
+
- `authDomain: string` - Auth domain
|
|
111
|
+
- `projectId: string` - Project ID
|
|
112
|
+
- `storageBucket: string` - Storage bucket
|
|
113
|
+
- `messagingSenderId: string` - Sender ID
|
|
114
|
+
- `appId: string` - App ID
|
|
115
|
+
|
|
116
|
+
## State Management
|
|
117
|
+
|
|
118
|
+
### Initialization State
|
|
119
|
+
|
|
120
|
+
**Import From:** `@umituz/react-native-firebase` or `src/infrastructure/config`
|
|
121
|
+
|
|
122
|
+
**Strategy:** Track Firebase initialization state
|
|
123
|
+
|
|
124
|
+
**State Properties:**
|
|
125
|
+
- `isInitialized: boolean` - Firebase initialized
|
|
126
|
+
- `isInitializing: boolean` - Initialization in progress
|
|
127
|
+
- `error: Error | null` - Initialization error
|
|
128
|
+
|
|
129
|
+
**Checking Status:**
|
|
130
|
+
- `isFirebaseInitialized()` - Check if ready
|
|
131
|
+
- `isFirebaseInitializing()` - Check if initializing
|
|
132
|
+
- `getFirebaseInitializationError()` - Get error if failed
|
|
133
|
+
|
|
134
|
+
**When to Check:**
|
|
135
|
+
- Before using Firebase services
|
|
136
|
+
- Before navigation
|
|
137
|
+
- Before app operations
|
|
138
|
+
- Error recovery
|
|
139
|
+
|
|
140
|
+
## Service Access
|
|
141
|
+
|
|
142
|
+
### Get Firebase App
|
|
143
|
+
|
|
144
|
+
**Import From:** `@umituz/react-native-firebase` or `src/infrastructure/config`
|
|
145
|
+
|
|
146
|
+
**Function:** `getFirebaseApp()`
|
|
147
|
+
|
|
148
|
+
**Returns:** `FirebaseApp` instance
|
|
149
|
+
|
|
150
|
+
**Usage Strategy:**
|
|
151
|
+
1. Check initialization status first
|
|
152
|
+
2. Call getFirebaseApp()
|
|
153
|
+
3. Use app for service initialization
|
|
154
|
+
4. Handle errors appropriately
|
|
155
|
+
|
|
156
|
+
**When to Use:**
|
|
157
|
+
- Custom service initialization
|
|
158
|
+
- Direct Firebase SDK usage
|
|
159
|
+
- Advanced Firebase features
|
|
160
|
+
|
|
161
|
+
## Common Mistakes to Avoid
|
|
162
|
+
|
|
163
|
+
1. ❌ Initializing Firebase multiple times
|
|
164
|
+
- ✅ Initialize once at app startup
|
|
165
|
+
|
|
166
|
+
2. ❌ Hardcoding config values
|
|
167
|
+
- ✅ Use environment variables
|
|
168
|
+
|
|
169
|
+
3. ❌ Not checking initialization status
|
|
170
|
+
- ✅ Always check isFirebaseInitialized()
|
|
171
|
+
|
|
172
|
+
4. ❌ Initializing in components
|
|
173
|
+
- ✅ Initialize in root/app startup
|
|
174
|
+
|
|
175
|
+
5. ❌ Ignoring initialization errors
|
|
176
|
+
- ✅ Handle and display errors
|
|
177
|
+
|
|
178
|
+
## AI Agent Instructions
|
|
179
|
+
|
|
180
|
+
### When Initializing Firebase
|
|
181
|
+
|
|
182
|
+
1. Call initializeFirebase() at app startup
|
|
183
|
+
2. Pass config or use environment variables
|
|
184
|
+
3. Await initialization completion
|
|
185
|
+
4. Check for errors
|
|
186
|
+
5. Show error message if failed
|
|
187
|
+
|
|
188
|
+
### When Checking Initialization
|
|
189
|
+
|
|
190
|
+
1. Use isFirebaseInitialized() before Firebase operations
|
|
191
|
+
2. Show loading state during initialization
|
|
192
|
+
3. Handle initialization errors
|
|
193
|
+
4. Provide retry option
|
|
194
|
+
5. Log errors for debugging
|
|
195
|
+
|
|
196
|
+
### When Getting Firebase App
|
|
197
|
+
|
|
198
|
+
1. Check initialization status first
|
|
199
|
+
2. Call getFirebaseApp()
|
|
200
|
+
3. Use app for services
|
|
201
|
+
4. Handle uninitialized state
|
|
202
|
+
5. Test thoroughly
|
|
203
|
+
|
|
204
|
+
## Code Quality Standards
|
|
205
|
+
|
|
206
|
+
### Configuration
|
|
207
|
+
|
|
208
|
+
- Validate all config fields
|
|
209
|
+
- Use environment variables
|
|
210
|
+
- Document required fields
|
|
211
|
+
- Handle missing config
|
|
212
|
+
- Provide clear error messages
|
|
213
|
+
|
|
214
|
+
### Error Handling
|
|
215
|
+
|
|
216
|
+
- Catch initialization errors
|
|
217
|
+
- Store error in state
|
|
218
|
+
- Provide error context
|
|
219
|
+
- Allow retry
|
|
220
|
+
- Log for debugging
|
|
221
|
+
|
|
222
|
+
## Performance Considerations
|
|
223
|
+
|
|
224
|
+
### Initialization Overhead
|
|
225
|
+
|
|
226
|
+
- One-time cost at app startup
|
|
227
|
+
- Async initialization (non-blocking)
|
|
228
|
+
- ~100-500ms typical
|
|
229
|
+
- Initialize once, reuse app instance
|
|
230
|
+
- Don't reinitialize unnecessarily
|
|
231
|
+
|
|
232
|
+
### Config Loading
|
|
233
|
+
|
|
234
|
+
- Environment variables load fast
|
|
235
|
+
- Validation adds minimal overhead
|
|
236
|
+
- Cache config after loading
|
|
237
|
+
- Don't reload config repeatedly
|
|
238
|
+
|
|
239
|
+
## Related Documentation
|
|
240
|
+
|
|
241
|
+
- [Auth Configuration README](../../auth/infrastructure/config/README.md)
|
|
242
|
+
- [Firestore Configuration README](../../firestore/infrastructure/config/README.md)
|
|
243
|
+
- [Storage Configuration README](../../storage/README.md)
|
|
244
|
+
|
|
245
|
+
## API Reference
|
|
246
|
+
|
|
247
|
+
### Main Functions
|
|
248
|
+
|
|
249
|
+
**Import Path:** `@umituz/react-native-firebase` or `src/infrastructure/config`
|
|
250
|
+
|
|
251
|
+
| Function | Parameters | Returns | Description |
|
|
252
|
+
|----------|-----------|---------|-------------|
|
|
253
|
+
| `initializeFirebase` | `config?: FirebaseConfig` | `Promise<void>` | Initialize Firebase |
|
|
254
|
+
| `getFirebaseApp` | - | `FirebaseApp` | Get Firebase app instance |
|
|
255
|
+
| `isFirebaseInitialized` | - | `boolean` | Check if initialized |
|
|
256
|
+
| `isFirebaseInitializing` | - | `boolean` | Check if initializing |
|
|
257
|
+
| `getFirebaseInitializationError` | - | `Error \| null` | Get initialization error |
|
|
258
|
+
|
|
259
|
+
---
|
|
260
|
+
|
|
261
|
+
**Last Updated:** 2025-01-08
|
|
262
|
+
**Maintainer:** Infrastructure Team
|