@umituz/react-native-firebase 2.0.0 → 2.0.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.
Files changed (24) hide show
  1. package/package.json +1 -1
  2. package/src/domains/account-deletion/application/ports/reauthentication.types.ts +2 -0
  3. package/src/domains/auth/index.ts +0 -1
  4. package/src/domains/auth/domain/errors/README.md +0 -291
  5. package/src/domains/auth/infrastructure/config/README.md +0 -239
  6. package/src/domains/auth/infrastructure/services/README.md +0 -346
  7. package/src/domains/firestore/domain/README.md +0 -325
  8. package/src/domains/firestore/domain/constants/README.md +0 -332
  9. package/src/domains/firestore/domain/entities/README.md +0 -286
  10. package/src/domains/firestore/domain/errors/README.md +0 -389
  11. package/src/domains/firestore/infrastructure/config/README.md +0 -239
  12. package/src/domains/firestore/infrastructure/middleware/README.md +0 -316
  13. package/src/domains/firestore/infrastructure/repositories/README.md +0 -425
  14. package/src/domains/firestore/infrastructure/services/README.md +0 -332
  15. package/src/domains/firestore/types/pagination/README.md +0 -332
  16. package/src/domains/firestore/utils/README.md +0 -574
  17. package/src/domains/firestore/utils/dateUtils/README.md +0 -171
  18. package/src/domains/firestore/utils/document-mapper.helper/README.md +0 -309
  19. package/src/domains/firestore/utils/pagination.helper/README.md +0 -298
  20. package/src/domains/firestore/utils/query-builder/README.md +0 -291
  21. package/src/presentation/README.md +0 -556
  22. package/src/shared/domain/README.md +0 -628
  23. package/src/shared/infrastructure/README.md +0 -408
  24. package/src/shared/infrastructure/config/README.md +0 -262
@@ -1,346 +0,0 @@
1
- # Auth Services
2
-
3
- Firebase Authentication service layer providing authentication operations, utilities, and guards.
4
-
5
- ## Purpose
6
-
7
- Provides service layer for Firebase Authentication including anonymous auth, Google OAuth, Apple Auth, reauthentication, account deletion, auth guards, and auth-related Firestore utilities.
8
-
9
- ## For AI Agents
10
-
11
- ### Before Using Auth Services
12
-
13
- 1. **USE** services (never Firebase Auth SDK directly in UI)
14
- 2. **HANDLE** service results properly
15
- 3. **CHECK** success property before using data
16
- 4. **HANDLE** errors appropriately
17
- 5. **USE** auth guards for protected routes
18
-
19
- ### Required Practices
20
-
21
- 1. **Use services** - Import from auth infrastructure/services
22
- 2. **Check results** - Always check success property
23
- 3. **Handle errors** - Display user-friendly messages
24
- 4. **Use guards** - Protect routes with authGuardService
25
- 5. **Clean up** - Delete Firestore data on account deletion
26
-
27
- ### Forbidden Practices
28
-
29
- ## ❌ NEVER
30
-
31
- - Use Firebase Auth SDK directly in UI components
32
- - Ignore success property in results
33
- - Skip error handling
34
- - Mix service concerns
35
- - Delete Auth without Firestore cleanup
36
-
37
- ## ⚠️ Avoid
38
-
39
- - Not checking success before using user data
40
- - Showing technical error messages
41
- - Not using auth guards for protected routes
42
- - Forgetting to delete Firestore data
43
- - Hardcoding auth configuration
44
-
45
- ## Service Overview
46
-
47
- ### AnonymousAuthService
48
-
49
- **Import From:** `@umituz/react-native-firebase/auth` or `src/auth/infrastructure/services`
50
-
51
- **Purpose:** Handle anonymous (guest) user authentication
52
-
53
- **Methods:**
54
- - `signIn()` - Sign in as anonymous user
55
-
56
- **Returns:** `Promise<AnonymousAuthResult>`
57
- - `success: boolean` - Operation succeeded
58
- - `user?: User` - Authenticated user
59
- - `error?: Error` - Error if failed
60
-
61
- **Usage Strategy:**
62
- 1. Call signIn() for guest access
63
- 2. Check success property
64
- 3. Access user data if successful
65
- 4. Handle errors appropriately
66
- 5. Prompt to upgrade to permanent account
67
-
68
- **When to Use:**
69
- - Quick app tryout without registration
70
- - Temporary user sessions
71
- - Testing without credentials
72
- - Guest access with limited functionality
73
-
74
- ### GoogleAuthService
75
-
76
- **Import From:** `@umituz/react-native-firebase/auth` or `src/auth/infrastructure/services`
77
-
78
- **Purpose:** Handle Google OAuth authentication
79
-
80
- **Methods:**
81
- - `signIn(config)` - Sign in with Google
82
-
83
- **Parameters:**
84
- - `config: GoogleAuthConfig`
85
- - `clientId: string` - Google OAuth Client ID
86
-
87
- **Returns:** `Promise<GoogleAuthResult>`
88
- - `success: boolean` - Operation succeeded
89
- - `user?: User` - Authenticated user
90
- - `idToken?: string` - Google ID token
91
- - `error?: Error` - Error if failed
92
-
93
- **Usage Strategy:**
94
- 1. Configure with Google Client ID
95
- 2. Call signIn() on user action
96
- 3. Check success property
97
- 4. Access user and idToken if successful
98
- 5. Handle errors gracefully
99
-
100
- **When to Use:**
101
- - Primary authentication method
102
- - Google account sign-in
103
- - Account linking
104
- - Reauthentication
105
-
106
- ### AppleAuthService
107
-
108
- **Import From:** `@umituz/react-native-firebase/auth` or `src/auth/infrastructure/services`
109
-
110
- **Purpose:** Handle Apple ID authentication (iOS only)
111
-
112
- **Methods:**
113
- - `signIn()` - Sign in with Apple ID
114
-
115
- **Returns:** `Promise<AppleAuthResult>`
116
- - `success: boolean` - Operation succeeded
117
- - `user?: User` - Authenticated user
118
- - `authorizationCode?: string` - Apple authorization code
119
- - `error?: Error` - Error if failed
120
-
121
- **Usage Strategy:**
122
- 1. Call signIn() on user action (iOS only)
123
- 2. Automatically skipped on Android
124
- 3. Check success property
125
- 4. Access user data if successful
126
- 5. Handle errors appropriately
127
-
128
- **When to Use:**
129
- - iOS applications
130
- - Alternative to Google sign-in
131
- - Privacy-focused authentication
132
- - Account linking
133
-
134
- ## Account Operations
135
-
136
- ### ReauthenticationService
137
-
138
- **Import From:** `@umituz/react-native-firebase/auth` or `src/auth/infrastructure/services`
139
-
140
- **Purpose:** Handle user reauthentication for sensitive operations
141
-
142
- **Methods:**
143
- - `reauthenticate(user)` - Reauthenticate current user
144
-
145
- **When to Use:**
146
- - Before account deletion
147
- - Before password change
148
- - Before sensitive operations
149
- - Email verification
150
-
151
- **Strategy:**
152
- 1. Verify user identity
153
- 2. Call reauthenticate method
154
- 3. Handle reauthentication
155
- 4. Proceed with sensitive operation
156
- 5. Handle errors appropriately
157
-
158
- ### Account Deletion Service
159
-
160
- **Import From:** `@umituz/react-native-firebase/auth` or `src/auth/infrastructure/services`
161
-
162
- **Purpose:** Handle complete account deletion including Auth and Firestore data
163
-
164
- **Methods:**
165
- - `deleteCurrentUser()` - Delete current user account
166
-
167
- **Cleanup Process:**
168
- 1. Delete Firebase Auth account
169
- 2. Automatically delete Firestore user data
170
- 3. Clean up Storage files (manual if needed)
171
- 4. Sign out user
172
- 5. Navigate to login screen
173
-
174
- **When to Use:**
175
- - User requests account deletion
176
- - GDPR compliance
177
- - User data cleanup
178
- - Account testing
179
-
180
- **Strategy:**
181
- 1. Confirm deletion with user
182
- 2. Call deleteCurrentUser()
183
- 3. Auth deletion automatic
184
- 4. Firestore cleanup automatic
185
- 5. Manual Storage cleanup if needed
186
-
187
- ## Route Protection
188
-
189
- ### AuthGuardService
190
-
191
- **Import From:** `@umituz/react-native-firebase/auth` or `src/auth/infrastructure/services`
192
-
193
- **Purpose:** Protect routes that require authentication
194
-
195
- **Methods:**
196
- - `canActivate()` - Check if route can be activated
197
- - `canActivateAnonymous()` - Check if anonymous users allowed
198
-
199
- **Returns:** `boolean` - Whether route can be accessed
200
-
201
- **Usage Strategy:**
202
- 1. Use in protected route components
203
- 2. Check canActivate() before rendering
204
- 3. Redirect to login if not authenticated
205
- 4. Handle anonymous users appropriately
206
- 5. Show loading state during check
207
-
208
- **When to Use:**
209
- - Pages requiring authentication
210
- - User profile pages
211
- - Dashboard and settings
212
- - Protected features
213
-
214
- ## Firestore Utilities
215
-
216
- ### AuthFirestoreUtils
217
-
218
- **Import From:** `@umituz/react-native-firebase/auth` or `src/auth/infrastructure/services`
219
-
220
- **Purpose:** Helper functions for auth-related Firestore operations
221
-
222
- **Utilities:**
223
- - User document path resolution
224
- - User data creation/update
225
- - User data cleanup on deletion
226
- - Auth state synchronization
227
-
228
- **When to Use:**
229
- - Creating user documents in Firestore
230
- - Updating user profile data
231
- - Cleaning up user data
232
- - Syncing auth state with database
233
-
234
- ## Service Result Types
235
-
236
- ### AuthResult Pattern
237
-
238
- **Import From:** All auth services return similar result types
239
-
240
- **Common Properties:**
241
- - `success: boolean` - Operation succeeded
242
- - `user?: User` - Authenticated user (when applicable)
243
- - `error?: Error` - Error if operation failed
244
-
245
- **Usage:**
246
- 1. Call service method
247
- 2. Check result.success
248
- 3. Use result.user if success
249
- 4. Handle result.error if failed
250
- 5. Never assume success
251
-
252
- ## Common Mistakes to Avoid
253
-
254
- 1. ❌ Not checking success property
255
- - ✅ Always check result.success first
256
-
257
- 2. ❌ Using Firebase Auth SDK directly
258
- - ✅ Use auth services
259
-
260
- 3. ❌ Not handling errors
261
- - ✅ Check result.error and display message
262
-
263
- 4. ❌ Deleting Auth without Firestore cleanup
264
- - ✅ Use deleteCurrentUser() for complete cleanup
265
-
266
- 5. ❌ Not protecting routes
267
- - ✅ Use authGuardService
268
-
269
- ## AI Agent Instructions
270
-
271
- ### When Using Auth Services
272
-
273
- 1. Import service from auth infrastructure/services
274
- 2. Call service method with appropriate parameters
275
- 3. Check result.success property
276
- 4. Use result.user data if successful
277
- 5. Handle result.error appropriately
278
-
279
- ### When Protecting Route
280
-
281
- 1. Use authGuardService.canActivate()
282
- 2. Check result before showing protected content
283
- 3. Redirect to login if not authenticated
284
- 4. Handle anonymous users appropriately
285
- 5. Show loading state during check
286
-
287
- ### When Deleting Account
288
-
289
- 1. Confirm deletion with user
290
- 2. Call deleteCurrentUser() service
291
- 3. Firestore cleanup automatic
292
- 4. Clean up Storage files if needed
293
- 5. Sign out and navigate to login
294
-
295
- ## Code Quality Standards
296
-
297
- ### TypeScript
298
-
299
- - Type all service methods
300
- - Use proper result types
301
- - Handle errors with types
302
- - Export service instances
303
- - Document service behavior
304
-
305
- ### Error Handling
306
-
307
- - Always return success property
308
- - Include error details
309
- - Provide context in errors
310
- - Handle edge cases
311
- - Test error flows
312
-
313
- ## Related Documentation
314
-
315
- - [Auth Module README](../../README.md)
316
- - [Auth Stores README](../stores/README.md)
317
- - [Auth Hooks README](../../presentation/hooks/README.md)
318
- - [Auth Errors README](../../domain/errors/README.md)
319
-
320
- ## API Reference
321
-
322
- ### Main Services
323
-
324
- **Import Path:** `@umituz/react-native-firebase/auth` or `src/auth/infrastructure/services`
325
-
326
- | Service | Purpose | Methods |
327
- |---------|---------|---------|
328
- | `anonymousAuthService` | Anonymous authentication | `signIn()` |
329
- | `googleAuthService` | Google OAuth | `signIn(config)` |
330
- | `appleAuthService` | Apple ID authentication | `signIn()` |
331
- | `authGuardService` | Route protection | `canActivate()`, `canActivateAnonymous()` |
332
- | `reauthenticationService` | User reauthentication | `reauthenticate(user)` |
333
- | `accountDeletionService` | Account deletion | `deleteCurrentUser()` |
334
-
335
- ### Result Types
336
-
337
- | Type | Properties |
338
- |------|------------|
339
- | `AnonymousAuthResult` | success, user?, error? |
340
- | `GoogleAuthResult` | success, user?, idToken?, error? |
341
- | `AppleAuthResult` | success, user?, authorizationCode?, error? |
342
-
343
- ---
344
-
345
- **Last Updated:** 2025-01-08
346
- **Maintainer:** Auth Module Team
@@ -1,325 +0,0 @@
1
- # Firestore Domain
2
-
3
- Domain layer for Firestore module containing business logic, entities, value objects, errors, and domain services.
4
-
5
- ## Purpose
6
-
7
- Implements Domain-Driven Design (DDD) principles for Firestore, separating business logic from infrastructure concerns and providing a clean architecture.
8
-
9
- ## For AI Agents
10
-
11
- ### Before Using Firestore Domain
12
-
13
- 1. **UNDERSTAND** DDD architecture (domain → infrastructure → presentation)
14
- 2. **USE** domain entities (not infrastructure)
15
- 3. **NEVER** import Firebase SDK in domain layer
16
- 4. **DEFINE** business logic in domain
17
- 5. **KEEP** domain layer Firebase-free
18
-
19
- ### Required Practices
20
-
21
- 1. **Keep domain Firebase-free** - No Firebase imports in domain
22
- 2. **Define entities** - Business entities with behavior
23
- 3. **Create value objects** - Immutable value types
24
- 4. **Define domain errors** - Custom error classes
25
- 5. **Write domain services** - Business logic services
26
-
27
- ### Forbidden Practices
28
-
29
- ## ❌ NEVER
30
-
31
- - Import Firebase SDK in domain layer
32
- - Mix infrastructure concerns in domain
33
- - Create anemic domain models (data without behavior)
34
- - Skip domain validation
35
- - Put business logic in infrastructure
36
-
37
- ## ⚠️ Avoid
38
-
39
- - Leaking domain logic to infrastructure
40
- - Not validating business rules
41
- - Missing domain entities
42
- - Complex domain services
43
- - Unclear domain boundaries
44
-
45
- ## Domain Layer Structure
46
-
47
- ### Organization
48
-
49
- **Import From:** `src/firestore/domain`
50
-
51
- **Structure:**
52
- - `entities/` - Business entities (QuotaMetrics, RequestLog)
53
- - `services/` - Domain services (QuotaCalculator)
54
- - `constants/` - Domain constants (QuotaLimits)
55
- - `errors/` - Domain errors (FirebaseFirestoreError)
56
-
57
- **Principles:**
58
- - No external dependencies (Firebase-free)
59
- - Pure business logic
60
- - Type-safe entities
61
- - Clear boundaries
62
- - Testable in isolation
63
-
64
- ## Entities
65
-
66
- ### QuotaMetrics
67
-
68
- **Import From:** `@umituz/react-native-firebase/firestore` or `src/firestore/domain`
69
-
70
- **Purpose:** Represents Firestore quota usage metrics
71
-
72
- **Properties:**
73
- - `totalReads: number` - Total read operations
74
- - `totalWrites: number` - Total write operations
75
- - `totalDeletes: number` - Total delete operations
76
- - `reads: QuotaStatus` - Read quota details
77
- - `writes: QuotaStatus` - Write quota details
78
- - `deletes: QuotaStatus` - Delete quota details
79
-
80
- **QuotaStatus Properties:**
81
- - `used: number` - Amount used
82
- - `limit: number` - Total limit
83
- - `percentage: number` - Usage percentage (0-100)
84
-
85
- **Usage:**
86
- - Track quota usage
87
- - Display usage to users
88
- - Check thresholds
89
- - Calculate remaining quota
90
- - Monitor trends
91
-
92
- **When to Use:**
93
- - After quota calculations
94
- - Displaying quota status
95
- - Checking thresholds
96
- - Monitoring usage
97
- - Cost analysis
98
-
99
- ### RequestLog
100
-
101
- **Import From:** `@umituz/react-native-firebase/firestore` or `src/firestore/domain`
102
-
103
- **Purpose:** Log entry for a Firestore request
104
-
105
- **Properties:**
106
- - `type: RequestType` - Operation type ('read', 'write', 'delete')
107
- - `collectionName: string` - Collection being accessed
108
- - `documentCount: number` - Number of documents affected
109
- - `timestamp: number` - Unix timestamp of request
110
- - `queryHash?: string` - Hash of query for duplicate detection
111
-
112
- **Usage:**
113
- - Create log entry before operation
114
- - Populate with operation details
115
- - Store for analytics and monitoring
116
- - Use queryHash for deduplication
117
-
118
- **When to Use:**
119
- - Repository operations (read, write, delete)
120
- - Quota tracking middleware
121
- - Performance monitoring
122
- - Analytics and reporting
123
-
124
- ## Value Objects
125
-
126
- ### QuotaStatus
127
-
128
- **Import From:** `@umituz/react-native-firebase/firestore` or `src/firestore/domain`
129
-
130
- **Purpose:** Represents quota usage status for a single operation type
131
-
132
- **Properties:**
133
- - `used: number` - Amount used
134
- - `limit: number` - Total limit
135
- - `percentage: number` - Usage percentage
136
-
137
- **Characteristics:**
138
- - Immutable value object
139
- - Used in QuotaMetrics
140
- - Calculated from raw counts
141
- - Used for threshold checking
142
-
143
- **When to Use:**
144
- - Calculating quota usage
145
- - Checking thresholds
146
- - Displaying quota status
147
- - Monitoring limits
148
-
149
- ## Domain Services
150
-
151
- ### QuotaCalculator
152
-
153
- **Import From:** `@umituz/react-native-firebase/firestore` or `src/firestore/domain/services`
154
-
155
- **Purpose:** Business logic for quota calculations
156
-
157
- **Responsibilities:**
158
- - Calculate quota usage percentages
159
- - Check quota thresholds
160
- - Calculate remaining quota
161
- - Validate quota limits
162
-
163
- **Methods:**
164
- - Calculate usage from operation counts
165
- - Compare against thresholds
166
- - Return QuotaMetrics object
167
-
168
- **When to Use:**
169
- - After batch operations
170
- - Displaying quota status
171
- - Checking before large operations
172
- - Monitoring usage trends
173
-
174
- ## Domain Constants
175
-
176
- ### QuotaLimits
177
-
178
- **Import From:** `@umituz/react-native-firebase/firestore` or `src/firestore/domain/constants`
179
-
180
- **Purpose:** Firebase free tier quota limits
181
-
182
- **Constants:**
183
- - Daily read limit (50,000)
184
- - Daily write limit (20,000)
185
- - Monthly delete limit (20,000)
186
-
187
- **Usage:**
188
- - Quota calculations
189
- - Display limits to users
190
- - Calculate remaining quota
191
- - Set up monitoring
192
-
193
- **When to Use:**
194
- - Calculating quota usage
195
- - Displaying quota information
196
- - Setting up alerts
197
- - Checking remaining quota
198
-
199
- ## Domain Errors
200
-
201
- ### FirebaseFirestoreError
202
-
203
- **Import From:** `@umituz/react-native-firebase/firestore` or `src/firestore/domain/errors`
204
-
205
- **Purpose:** Base error class for all Firestore errors
206
-
207
- **Properties:**
208
- - `code: string` - Error code
209
- - `message: string` - Error message
210
-
211
- **Hierarchy:**
212
- - FirebaseFirestoreError (base)
213
- - FirebaseFirestoreInitializationError
214
- - FirebaseFirestoreQuotaError
215
-
216
- **When to Use:**
217
- - Throwing custom Firestore errors
218
- - Type-safe error handling
219
- - Error code for conditional logic
220
- - Structured error information
221
-
222
- ## Common Mistakes to Avoid
223
-
224
- 1. ❌ Importing Firebase in domain layer
225
- - ✅ Keep domain Firebase-free
226
-
227
- 2. ❌ Anemic domain models
228
- - ✅ Add behavior to entities
229
-
230
- 3. ❌ Business logic in infrastructure
231
- - ✅ Put business logic in domain
232
-
233
- 4. ❌ Not validating business rules
234
- - ✅ Validate in domain layer
235
-
236
- 5. ❌ Leaking domain logic
237
- - ✅ Keep domain logic contained
238
-
239
- ## AI Agent Instructions
240
-
241
- ### When Creating Domain Entity
242
-
243
- 1. Define entity interface
244
- 2. Add business logic methods
245
- 3. Validate invariants
246
- 4. Keep Firebase-free
247
- 5. Export for infrastructure use
248
-
249
- ### When Creating Domain Service
250
-
251
- 1. Identify business logic
252
- 2. Create service class
253
- 3. Implement business rules
254
- 4. Keep pure functions
255
- 5. Test in isolation
256
-
257
- ### When Creating Domain Error
258
-
259
- 1. Extend base error class
260
- 2. Add error code
261
- 3. Provide clear message
262
- 4. Include context
263
- 5. Export for use
264
-
265
- ## Code Quality Standards
266
-
267
- ### Domain Layer
268
-
269
- - No Firebase imports
270
- - Pure TypeScript
271
- - Business logic only
272
- - Type-safe entities
273
- - Clear interfaces
274
-
275
- ### Testing
276
-
277
- - Test domain in isolation
278
- - Mock infrastructure
279
- - Test business rules
280
- - Validate invariants
281
- - Unit test coverage
282
-
283
- ## Related Documentation
284
-
285
- - [Firestore Module README](../../README.md)
286
- - [Firestore Infrastructure README](../../infrastructure/README.md)
287
- - [Firestore Errors README](../errors/README.md)
288
- - [Quota Constants README](../constants/README.md)
289
-
290
- ## Architecture
291
-
292
- ### Domain Layer Responsibilities
293
-
294
- **What Domain Does:**
295
- - Defines business entities
296
- - Contains business logic
297
- - Validates business rules
298
- - Provides domain services
299
- - Defines domain errors
300
-
301
- **What Domain Doesn't Do:**
302
- - No Firebase SDK usage
303
- - No database operations
304
- - No HTTP requests
305
- - No external integrations
306
- - No UI concerns
307
-
308
- ### DDD Principles
309
-
310
- **Strategic Patterns:**
311
- - Entities (identity-based objects)
312
- - Value Objects (immutable values)
313
- - Domain Services (stateless operations)
314
- - Aggregates (consistency boundaries)
315
- - Repositories (infrastructure concern)
316
-
317
- **Tactical Patterns:**
318
- - Factory (creation)
319
- - Strategy (algorithms)
320
- - Specification (business rules)
321
-
322
- ---
323
-
324
- **Last Updated:** 2025-01-08
325
- **Maintainer:** Firestore Module Team