@umituz/react-native-firebase 1.13.116 → 1.13.118
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 +1 -1
- package/src/auth/domain/errors/FirebaseAuthError.ts +0 -4
- package/src/auth/index.ts +0 -14
- package/src/auth/infrastructure/config/initializers/FirebaseAuthInitializer.ts +2 -23
- package/src/auth/infrastructure/services/apple-auth.types.ts +16 -4
- package/src/auth/infrastructure/services/auth-utils.service.ts +54 -46
- package/src/auth/infrastructure/services/google-auth.types.ts +18 -11
- package/src/auth/infrastructure/services/reauthentication.types.ts +16 -14
- package/src/auth/infrastructure/stores/auth.store.ts +1 -10
- package/src/auth/presentation/hooks/useAnonymousAuth.ts +1 -25
- package/src/domain/errors/FirebaseError.ts +0 -4
- package/src/firestore/domain/errors/FirebaseFirestoreError.ts +0 -8
- package/src/firestore/infrastructure/config/FirestoreClient.ts +0 -2
- package/src/firestore/infrastructure/middleware/QuotaTrackingMiddleware.ts +0 -13
- package/src/firestore/infrastructure/repositories/BaseRepository.ts +5 -5
- package/src/firestore/infrastructure/services/RequestLoggerService.ts +2 -24
- package/src/firestore/types/pagination.types.ts +0 -8
- package/src/firestore/utils/firestore-helper.ts +10 -14
- package/src/firestore/utils/quota-error-detector.util.ts +27 -16
- package/src/index.ts +0 -10
- package/src/infrastructure/config/FirebaseClient.ts +0 -9
- package/src/infrastructure/config/FirebaseConfigLoader.ts +33 -2
- package/src/infrastructure/config/orchestrators/FirebaseInitializationOrchestrator.ts +0 -21
- package/src/infrastructure/config/services/FirebaseServiceInitializer.ts +2 -18
- package/src/init/createFirebaseInitModule.ts +0 -1
- package/src/storage/deleter.ts +2 -35
- package/src/storage/uploader.ts +0 -34
- package/src/auth/README.md +0 -339
- package/src/auth/domain/README.md +0 -264
- package/src/auth/infrastructure/stores/README.md +0 -407
- package/src/auth/presentation/hooks/README.md +0 -442
- package/src/firestore/README.md +0 -566
- package/src/firestore/__tests__/BaseRepository.test.ts +0 -132
- package/src/firestore/__tests__/QueryDeduplicationMiddleware.test.ts +0 -147
- package/src/firestore/__tests__/mocks/react-native-firebase.ts +0 -23
- package/src/firestore/__tests__/setup.ts +0 -45
- package/src/firestore/utils/path-resolver/README.md +0 -277
- package/src/firestore/utils/quota-error-detector/README.md +0 -355
- package/src/storage/README.md +0 -493
- package/src/storage/uploader/README.md +0 -409
|
@@ -1,355 +0,0 @@
|
|
|
1
|
-
# Quota Error Detector
|
|
2
|
-
|
|
3
|
-
Utilities for detecting and handling Firestore quota errors and retryable errors.
|
|
4
|
-
|
|
5
|
-
## Purpose
|
|
6
|
-
|
|
7
|
-
Provides reliable detection of Firestore quota errors (resource-exhausted, quota-exceeded) and retryable transient errors (unavailable, deadline-exceeded) for proper error handling and user communication.
|
|
8
|
-
|
|
9
|
-
## For AI Agents
|
|
10
|
-
|
|
11
|
-
### Before Using Error Detection
|
|
12
|
-
|
|
13
|
-
1. **ALWAYS** wrap Firestore operations in try-catch
|
|
14
|
-
2. **CHECK** error type before handling
|
|
15
|
-
3. **PROVIDE** user-friendly messages for quota errors
|
|
16
|
-
4. **IMPLEMENT** retry logic for retryable errors
|
|
17
|
-
5. **LOG** errors appropriately
|
|
18
|
-
|
|
19
|
-
### Required Practices
|
|
20
|
-
|
|
21
|
-
1. **Use isQuotaError()** for quota detection
|
|
22
|
-
2. **Use getQuotaErrorMessage()** for user-facing messages
|
|
23
|
-
3. **Use isRetryableError()** for retry logic
|
|
24
|
-
4. **Handle quota errors gracefully** (stop operations, inform user)
|
|
25
|
-
5. **Implement exponential backoff** for retryable errors
|
|
26
|
-
|
|
27
|
-
### Forbidden Practices
|
|
28
|
-
|
|
29
|
-
## ❌ NEVER
|
|
30
|
-
|
|
31
|
-
- Ignore quota errors (continue operations)
|
|
32
|
-
- Show raw error messages to users
|
|
33
|
-
- Retry quota errors (won't succeed)
|
|
34
|
-
- Assume all errors are quota errors
|
|
35
|
-
- Log sensitive error data
|
|
36
|
-
|
|
37
|
-
## ⚠️ Avoid
|
|
38
|
-
|
|
39
|
-
- Too many retries (implement max retry limit)
|
|
40
|
-
- No delay between retries (use backoff)
|
|
41
|
-
- Confusing retryable with quota errors
|
|
42
|
-
- Not tracking quota usage
|
|
43
|
-
- Blocking UI for retryable errors
|
|
44
|
-
|
|
45
|
-
## Usage Strategies
|
|
46
|
-
|
|
47
|
-
### For Quota Error Handling
|
|
48
|
-
|
|
49
|
-
**Strategy:** Detect quota errors and stop operations immediately.
|
|
50
|
-
|
|
51
|
-
**When to Use:**
|
|
52
|
-
- After Firestore write operations
|
|
53
|
-
- After Firestore read operations (if quota-limited)
|
|
54
|
-
- In error boundaries
|
|
55
|
-
- In background sync operations
|
|
56
|
-
|
|
57
|
-
**Approach:**
|
|
58
|
-
1. Catch errors from Firestore operations
|
|
59
|
-
2. Check with isQuotaError()
|
|
60
|
-
3. Show user-friendly message
|
|
61
|
-
4. Disable operations that consume quota
|
|
62
|
-
5. Track quota exceeded state
|
|
63
|
-
|
|
64
|
-
**User Message Strategy:**
|
|
65
|
-
- Inform user clearly about quota limit
|
|
66
|
-
- Suggest upgrade plan or waiting
|
|
67
|
-
- Provide action buttons (upgrade, contact support)
|
|
68
|
-
- Don't show technical details
|
|
69
|
-
|
|
70
|
-
### For Retryable Error Handling
|
|
71
|
-
|
|
72
|
-
**Strategy:** Implement retry logic with exponential backoff.
|
|
73
|
-
|
|
74
|
-
**When to Use:**
|
|
75
|
-
- Network timeout errors
|
|
76
|
-
- Temporary service unavailability
|
|
77
|
-
- Deadline exceeded errors
|
|
78
|
-
- Automatic retry operations
|
|
79
|
-
|
|
80
|
-
**Approach:**
|
|
81
|
-
1. Check with isRetryableError()
|
|
82
|
-
2. Wait with exponential backoff (1s, 2s, 4s, 8s...)
|
|
83
|
-
3. Retry operation
|
|
84
|
-
4. Max retries: 3-5
|
|
85
|
-
5. Give up after max retries
|
|
86
|
-
|
|
87
|
-
**Exponential Backoff:**
|
|
88
|
-
- Retry 1: Wait 1 second
|
|
89
|
-
- Retry 2: Wait 2 seconds
|
|
90
|
-
- Retry 3: Wait 4 seconds
|
|
91
|
-
- Retry 4: Wait 8 seconds
|
|
92
|
-
- Max: 5 retries
|
|
93
|
-
|
|
94
|
-
### For Error Logging
|
|
95
|
-
|
|
96
|
-
**Strategy:** Log errors appropriately based on type.
|
|
97
|
-
|
|
98
|
-
**When to Use:**
|
|
99
|
-
- Monitoring error rates
|
|
100
|
-
- Debugging issues
|
|
101
|
-
- Analytics and alerting
|
|
102
|
-
|
|
103
|
-
**Approach:**
|
|
104
|
-
1. Log retryable errors as warnings
|
|
105
|
-
2. Log quota errors as errors
|
|
106
|
-
3. Include error context (operation, collection)
|
|
107
|
-
4. Don't log sensitive data (user data, tokens)
|
|
108
|
-
5. Aggregate error metrics
|
|
109
|
-
|
|
110
|
-
## Error Detection Logic
|
|
111
|
-
|
|
112
|
-
### Quota Error Detection
|
|
113
|
-
|
|
114
|
-
**isQuotaError(error)** checks for:
|
|
115
|
-
|
|
116
|
-
**Error Codes:**
|
|
117
|
-
- `resource-exhausted`
|
|
118
|
-
- `quota-exceeded`
|
|
119
|
-
- `RESOURCE_EXHAUSTED`
|
|
120
|
-
|
|
121
|
-
**Error Messages:**
|
|
122
|
-
- "quota"
|
|
123
|
-
- "exceeded"
|
|
124
|
-
- "limit"
|
|
125
|
-
- "too many requests"
|
|
126
|
-
|
|
127
|
-
**Detection Strategy:**
|
|
128
|
-
1. Check error.code for known quota codes
|
|
129
|
-
2. Check error.message for quota-related keywords
|
|
130
|
-
3. Case-insensitive message matching
|
|
131
|
-
|
|
132
|
-
### Retryable Error Detection
|
|
133
|
-
|
|
134
|
-
**isRetryableError(error)** checks for:
|
|
135
|
-
|
|
136
|
-
**Error Codes:**
|
|
137
|
-
- `unavailable` - Service temporarily unavailable
|
|
138
|
-
- `deadline-exceeded` - Request timeout
|
|
139
|
-
- `aborted` - Operation cancelled (can retry)
|
|
140
|
-
|
|
141
|
-
**Detection Strategy:**
|
|
142
|
-
1. Check error.code for retryable codes
|
|
143
|
-
2. Only code-based detection (more reliable)
|
|
144
|
-
3. Conservative (only retry if safe)
|
|
145
|
-
|
|
146
|
-
## API Reference
|
|
147
|
-
|
|
148
|
-
### `isQuotaError(error: unknown): boolean`
|
|
149
|
-
|
|
150
|
-
Check if error is a Firestore quota error.
|
|
151
|
-
|
|
152
|
-
**Parameters:**
|
|
153
|
-
- **error**: unknown - Error object from Firestore operation
|
|
154
|
-
|
|
155
|
-
**Returns:** boolean - True if quota error detected
|
|
156
|
-
|
|
157
|
-
**Use For:**
|
|
158
|
-
- Detecting quota exceeded
|
|
159
|
-
- Stopping operations
|
|
160
|
-
- Showing user messages
|
|
161
|
-
|
|
162
|
-
### `isRetryableError(error: unknown): boolean`
|
|
163
|
-
|
|
164
|
-
Check if error is retryable (transient).
|
|
165
|
-
|
|
166
|
-
**Parameters:**
|
|
167
|
-
- **error**: unknown - Error object from Firestore operation
|
|
168
|
-
|
|
169
|
-
**Returns:** boolean - True if error is retryable
|
|
170
|
-
|
|
171
|
-
**Use For:**
|
|
172
|
-
- Implementing retry logic
|
|
173
|
-
- Background sync operations
|
|
174
|
-
- Automatic recovery
|
|
175
|
-
|
|
176
|
-
### `getQuotaErrorMessage(): string`
|
|
177
|
-
|
|
178
|
-
Get user-friendly quota error message.
|
|
179
|
-
|
|
180
|
-
**Returns:** string - User-facing error message
|
|
181
|
-
|
|
182
|
-
**Use For:**
|
|
183
|
-
- Displaying to users
|
|
184
|
-
- Error notifications
|
|
185
|
-
- In-app messaging
|
|
186
|
-
|
|
187
|
-
**Message:** "Daily quota exceeded. Please try again tomorrow or upgrade your plan."
|
|
188
|
-
|
|
189
|
-
## Error Handling Patterns
|
|
190
|
-
|
|
191
|
-
### Pattern 1: Quota-Aware Operations
|
|
192
|
-
|
|
193
|
-
**Strategy:** Check for quota errors and handle gracefully
|
|
194
|
-
|
|
195
|
-
**Implementation Steps:**
|
|
196
|
-
1. Wrap Firestore operations in try-catch
|
|
197
|
-
2. Check if error is quota error with isQuotaError()
|
|
198
|
-
3. Show user-friendly message with getQuotaErrorMessage()
|
|
199
|
-
4. Disable further operations when quota exceeded
|
|
200
|
-
5. Log quota errors for monitoring
|
|
201
|
-
|
|
202
|
-
**Error Handling Flow:**
|
|
203
|
-
- Detect quota errors immediately
|
|
204
|
-
- Show clear user message
|
|
205
|
-
- Set quota exceeded flag in UI
|
|
206
|
-
- Prevent further quota-consuming operations
|
|
207
|
-
- Allow retry after quota reset
|
|
208
|
-
|
|
209
|
-
### Pattern 2: Retry with Backoff
|
|
210
|
-
|
|
211
|
-
**Strategy:** Retry only retryable errors with exponential backoff
|
|
212
|
-
|
|
213
|
-
**Implementation Steps:**
|
|
214
|
-
1. Define max retry attempts (typically 3)
|
|
215
|
-
2. Wrap operation in retry loop
|
|
216
|
-
3. Check if error is retryable with isRetryableError()
|
|
217
|
-
4. Calculate exponential delay: 2^attempt * 1000ms
|
|
218
|
-
5. Continue or throw based on retry count
|
|
219
|
-
|
|
220
|
-
**Retry Rules:**
|
|
221
|
-
- Retry retryable errors (resource exhaustion, rate limits)
|
|
222
|
-
- Never retry quota errors (will not succeed)
|
|
223
|
-
- Use exponential backoff between retries
|
|
224
|
-
- Set max retry limit to prevent infinite loops
|
|
225
|
-
- Return last error after max retries
|
|
226
|
-
|
|
227
|
-
### Pattern 3: Error Boundary
|
|
228
|
-
|
|
229
|
-
**Strategy:** Create React hook for error handling
|
|
230
|
-
|
|
231
|
-
**State Management:**
|
|
232
|
-
- Track quota exceeded status
|
|
233
|
-
- Track current error
|
|
234
|
-
- Provide execute function for operations
|
|
235
|
-
|
|
236
|
-
**Error Handling Logic:**
|
|
237
|
-
1. Check if error is quota error
|
|
238
|
-
2. Set quota exceeded flag if true
|
|
239
|
-
3. Check if error is retryable
|
|
240
|
-
4. Retry operation once if retryable
|
|
241
|
-
5. Set error state for other errors
|
|
242
|
-
|
|
243
|
-
**Hook Return Values:**
|
|
244
|
-
- execute function for operations
|
|
245
|
-
- quotaExceeded boolean flag
|
|
246
|
-
- error object with details
|
|
247
|
-
|
|
248
|
-
## Common Mistakes to Avoid
|
|
249
|
-
|
|
250
|
-
1. ❌ Retrying quota errors
|
|
251
|
-
- ✅ Quota errors will not succeed on retry
|
|
252
|
-
|
|
253
|
-
2. ❌ Showing raw error messages
|
|
254
|
-
- ✅ Use getQuotaErrorMessage() for user-friendly text
|
|
255
|
-
|
|
256
|
-
3. ❌ No retry limit for retryable errors
|
|
257
|
-
- ✅ Always implement max retry limit (3-5)
|
|
258
|
-
|
|
259
|
-
4. ❌ Ignoring error types
|
|
260
|
-
- ✅ Check error type before handling
|
|
261
|
-
|
|
262
|
-
5. ❌ Blocking UI for retryable errors
|
|
263
|
-
- ✅ Retry in background, show loading indicator
|
|
264
|
-
|
|
265
|
-
## AI Agent Instructions
|
|
266
|
-
|
|
267
|
-
### When Handling Firestore Errors
|
|
268
|
-
|
|
269
|
-
1. Always check error type before handling
|
|
270
|
-
2. Use isQuotaError() for quota detection
|
|
271
|
-
3. Use isRetryableError() for retry logic
|
|
272
|
-
4. Implement proper handling for each type
|
|
273
|
-
5. Provide user feedback for quota errors
|
|
274
|
-
|
|
275
|
-
### When Implementing Retry Logic
|
|
276
|
-
|
|
277
|
-
1. Only retry if isRetryableError() returns true
|
|
278
|
-
2. Implement exponential backoff (2^n * 1000ms)
|
|
279
|
-
3. Set max retry limit (3-5 retries)
|
|
280
|
-
4. Don't retry quota errors
|
|
281
|
-
5. Log retry attempts for monitoring
|
|
282
|
-
|
|
283
|
-
### For User Experience
|
|
284
|
-
|
|
285
|
-
1. Show clear messages for quota errors
|
|
286
|
-
2. Provide action buttons (upgrade, contact)
|
|
287
|
-
3. Use loading states for retryable errors
|
|
288
|
-
4. Don't block UI for transient errors
|
|
289
|
-
5. Track quota state globally
|
|
290
|
-
|
|
291
|
-
## Code Quality Standards
|
|
292
|
-
|
|
293
|
-
### TypeScript
|
|
294
|
-
|
|
295
|
-
- Use unknown type for error parameter
|
|
296
|
-
- Type guard functions properly
|
|
297
|
-
- Narrow error type before accessing properties
|
|
298
|
-
- Export for use across modules
|
|
299
|
-
|
|
300
|
-
### Error Handling
|
|
301
|
-
|
|
302
|
-
- Always handle quota errors explicitly
|
|
303
|
-
- Never swallow errors silently
|
|
304
|
-
- Log errors appropriately
|
|
305
|
-
- Provide context in logs
|
|
306
|
-
|
|
307
|
-
## Performance Considerations
|
|
308
|
-
|
|
309
|
-
### Retry Strategy
|
|
310
|
-
|
|
311
|
-
- Exponential backoff prevents hammering service
|
|
312
|
-
- Max retries prevent infinite loops
|
|
313
|
-
- Short delays for user-facing operations
|
|
314
|
-
- Longer delays for background operations
|
|
315
|
-
|
|
316
|
-
### Quota Monitoring
|
|
317
|
-
|
|
318
|
-
- Track quota usage proactively
|
|
319
|
-
- Show warnings before hitting limit
|
|
320
|
-
- Implement graceful degradation
|
|
321
|
-
- Cache data to reduce quota usage
|
|
322
|
-
|
|
323
|
-
## Related Documentation
|
|
324
|
-
|
|
325
|
-
- [Firestore Module README](../README.md)
|
|
326
|
-
- [Firestore Error Codes](https://firebase.google.com/docs/firestore/manage-rest/errors)
|
|
327
|
-
- [Quota Management](../../infrastructure/services/quota-tracker-service/README.md)
|
|
328
|
-
|
|
329
|
-
## Firebase Quota Best Practices
|
|
330
|
-
|
|
331
|
-
### Quota Types
|
|
332
|
-
|
|
333
|
-
**Daily Quota:**
|
|
334
|
-
- Reads: 50,000/day (free tier)
|
|
335
|
-
- Writes: 20,000/day (free tier)
|
|
336
|
-
- Deletes: 20,000/day (free tier)
|
|
337
|
-
|
|
338
|
-
**Strategies:**
|
|
339
|
-
- Monitor usage before hitting limits
|
|
340
|
-
- Implement caching to reduce reads
|
|
341
|
-
- Batch writes to reduce write count
|
|
342
|
-
- Use pagination to limit result size
|
|
343
|
-
|
|
344
|
-
### Quota Exceeded Handling
|
|
345
|
-
|
|
346
|
-
1. **Stop operations** - Don't waste quota on failed operations
|
|
347
|
-
2. **Inform user** - Clear message about what happened
|
|
348
|
-
3. **Provide options** - Upgrade plan, wait, contact support
|
|
349
|
-
4. **Track state** - Remember quota exceeded across app
|
|
350
|
-
5. **Retry later** - Allow retry when quota resets
|
|
351
|
-
|
|
352
|
-
---
|
|
353
|
-
|
|
354
|
-
**Last Updated:** 2025-01-08
|
|
355
|
-
**Maintainer:** Firestore Module Team
|