@umituz/react-native-firebase 1.13.58 → 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.
Files changed (35) hide show
  1. package/README.md +277 -0
  2. package/package.json +1 -1
  3. package/scripts/README.md +513 -0
  4. package/src/auth/README.md +339 -0
  5. package/src/auth/domain/README.md +264 -0
  6. package/src/auth/domain/errors/README.md +291 -0
  7. package/src/auth/infrastructure/config/README.md +239 -0
  8. package/src/auth/infrastructure/services/README.md +346 -0
  9. package/src/auth/infrastructure/stores/README.md +407 -0
  10. package/src/auth/presentation/hooks/README.md +442 -0
  11. package/src/domain/README.md +628 -0
  12. package/src/firestore/README.md +566 -0
  13. package/src/firestore/domain/README.md +325 -0
  14. package/src/firestore/domain/constants/README.md +332 -0
  15. package/src/firestore/domain/entities/README.md +286 -0
  16. package/src/firestore/domain/errors/README.md +389 -0
  17. package/src/firestore/infrastructure/config/README.md +239 -0
  18. package/src/firestore/infrastructure/middleware/README.md +316 -0
  19. package/src/firestore/infrastructure/repositories/README.md +425 -0
  20. package/src/firestore/infrastructure/services/README.md +332 -0
  21. package/src/firestore/types/pagination/README.md +332 -0
  22. package/src/firestore/utils/README.md +574 -0
  23. package/src/firestore/utils/dateUtils/README.md +171 -0
  24. package/src/firestore/utils/document-mapper.helper/README.md +309 -0
  25. package/src/firestore/utils/pagination.helper/README.md +298 -0
  26. package/src/firestore/utils/path-resolver/README.md +277 -0
  27. package/src/firestore/utils/query-builder/README.md +291 -0
  28. package/src/firestore/utils/quota-error-detector/README.md +355 -0
  29. package/src/infrastructure/README.md +408 -0
  30. package/src/infrastructure/config/README.md +262 -0
  31. package/src/presentation/README.md +556 -0
  32. package/src/storage/README.md +493 -0
  33. package/src/storage/deleter/README.md +370 -0
  34. package/src/storage/types/README.md +313 -0
  35. package/src/storage/uploader/README.md +409 -0
@@ -0,0 +1,493 @@
1
+ # Storage Module
2
+
3
+ Firebase Storage module providing file upload and deletion operations with automatic MIME type detection and metadata support.
4
+
5
+ ## Purpose
6
+
7
+ Provides clean, maintainable file upload and deletion operations for Firebase Storage with proper error handling, metadata management, and path organization.
8
+
9
+ ## For AI Agents
10
+
11
+ ### Before Using This Module
12
+
13
+ 1. **READ** this entire README
14
+ 2. **UNDERSTAND** path organization strategies
15
+ 3. **ALWAYS** clean up old files before uploading new ones
16
+ 4. **USE** organized path structures
17
+ 5. **HANDLE** errors appropriately
18
+
19
+ ### Required Practices
20
+
21
+ 1. **Clean up old files** before uploading replacements
22
+ 2. **Use organized path structures** (e.g., `users/{userId}/avatar.jpg`)
23
+ 3. **Add metadata** to files for tracking
24
+ 4. **Handle upload/delete errors** appropriately
25
+ 5. **Use batch deletion** for multiple files
26
+
27
+ ### Forbidden Practices
28
+
29
+ ## ❌ NEVER
30
+
31
+ - Upload new files without deleting old ones (wastes storage)
32
+ - Use disorganized path structures
33
+ - Ignore upload/delete errors
34
+ - Store files at root level
35
+ - Hardcode storage paths
36
+ - Forget to add metadata for tracking
37
+
38
+ ## ⚠️ Avoid
39
+
40
+ - Large file uploads without compression
41
+ - Uploading temporary files without cleanup
42
+ - Inconsistent path naming
43
+ - Missing error handling
44
+ - Not setting Firebase Storage security rules
45
+
46
+ ## 🏗️ Architecture
47
+
48
+ **Directory Structure:**
49
+
50
+ - **uploader/** - Upload operations (Base64 and file uploads)
51
+ - **deleter/** - Delete operations (Single and batch deletions)
52
+ - **types/** - Type definitions (Storage interfaces and types)
53
+
54
+ ## ✅ Required Practices
55
+
56
+ ### Path Organization
57
+
58
+ **Strategy:** Use hierarchical, organized paths for all files.
59
+
60
+ **Path Pattern:**
61
+ - User files: `users/{userId}/{category}/{filename}`
62
+ - Post files: `posts/{postId}/{category}/{filename}`
63
+ - Product files: `products/{productId}/{category}/{filename}`
64
+
65
+ **Why Organized Paths:**
66
+ - Easy to manage and delete
67
+ - Clear file ownership
68
+ - Simple security rules
69
+ - Efficient cleanup
70
+
71
+ **Examples:**
72
+ - users/user123/avatar.jpg
73
+ - users/user123/photos/photo_2024-01-15.jpg
74
+ - posts/post456/images/image1.jpg
75
+ - products/prod789/thumbnails/thumb.jpg
76
+
77
+ ### File Cleanup
78
+
79
+ **Strategy:** Always delete old files before uploading replacements.
80
+
81
+ **When to Clean Up:**
82
+ - Uploading new avatar (delete old avatar)
83
+ - Replacing product images
84
+ - Updating post attachments
85
+ - User deletes their content
86
+
87
+ **Approach:**
88
+ 1. Store storage path in database (not download URL)
89
+ 2. Before uploading new file, delete old one
90
+ 3. Handle deletion errors appropriately
91
+ 4. Verify deletion success
92
+
93
+ ### Metadata Strategy
94
+
95
+ **Strategy:** Attach useful metadata to all uploads.
96
+
97
+ **Required Metadata:**
98
+ - `uploadedBy` - User ID who uploaded
99
+ - `uploadedAt` - ISO timestamp
100
+ - `originalName` - Original filename
101
+ - `contentType` - MIME type
102
+
103
+ **Optional Metadata:**
104
+ - Category or tags
105
+ - Related document IDs
106
+ - File dimensions (for images)
107
+ - Custom application fields
108
+
109
+ ### Error Handling
110
+
111
+ **Required Error Handling:**
112
+ 1. Handle network failures
113
+ 2. Handle quota exceeded
114
+ 3. Handle unauthorized access
115
+ 4. Handle invalid files
116
+ 5. Log errors appropriately
117
+
118
+ ## 🎯 Usage Strategies
119
+
120
+ ### For Avatar Upload
121
+
122
+ **Strategy:** Replace old avatar with new one.
123
+
124
+ **When to Use:**
125
+ - User updates profile picture
126
+ - Initial avatar upload
127
+
128
+ **Approach:**
129
+ 1. Pick image from gallery/camera
130
+ 2. Convert to base64
131
+ 3. Delete old avatar if exists
132
+ 4. Upload new avatar
133
+ 5. Save storage path to database
134
+ 6. Handle errors
135
+
136
+ **Path Pattern:** `users/{userId}/avatar.jpg`
137
+
138
+ ### For Multiple Photos
139
+
140
+ **Strategy:** Upload multiple photos with organized paths.
141
+
142
+ **When to Use:**
143
+ - Photo gallery uploads
144
+ - Batch image uploads
145
+ - Album creation
146
+
147
+ **Approach:**
148
+ 1. Generate unique storage path for each photo
149
+ 2. Upload in parallel or sequence
150
+ 3. Collect all results
151
+ 4. Save paths to database
152
+ 5. Handle partial failures
153
+
154
+ **Path Pattern:** `users/{userId}/photos/{timestamp}_{index}.jpg`
155
+
156
+ ### For Product Images
157
+
158
+ **Strategy:** Organize by product with thumbnails.
159
+
160
+ **When to Use:**
161
+ - E-commerce applications
162
+ - Product catalog management
163
+ - Image gallery per product
164
+
165
+ **Approach:**
166
+ 1. Main images: `products/{productId}/images/{filename}`
167
+ 2. Thumbnails: `products/{productId}/thumbnails/{filename}`
168
+ 3. Upload main image first
169
+ 4. Generate and upload thumbnail
170
+ 5. Save both paths to database
171
+
172
+ ### For Document Upload
173
+
174
+ **Strategy:** Upload documents with proper metadata.
175
+
176
+ **When to Use:**
177
+ - PDF reports
178
+ - Document storage
179
+ - File attachments
180
+
181
+ **Approach:**
182
+ 1. Use uploadFile for URI-based uploads
183
+ 2. Provide explicit MIME type
184
+ 3. Add descriptive metadata
185
+ 4. Organize by category/date
186
+ 5. Implement access control
187
+
188
+ **Path Pattern:** `documents/{userId}/{category}/{filename}.pdf`
189
+
190
+ ## 🔧 Upload Operations
191
+
192
+ ### Base64 Image Upload
193
+
194
+ **Function:** `uploadBase64Image(base64, storagePath, options?)`
195
+
196
+ **When to Use:**
197
+ - Images from camera/gallery (with base64)
198
+ - Profile pictures
199
+ - Small to medium images
200
+
201
+ **Features:**
202
+ - Automatic MIME type detection
203
+ - Data URL prefix support
204
+ - Custom metadata attachment
205
+ - Error handling
206
+
207
+ **Supported Types:**
208
+ - JPEG (image/jpeg)
209
+ - PNG (image/png)
210
+ - WebP (image/webp)
211
+ - GIF (image/gif)
212
+
213
+ ### File Upload
214
+
215
+ **Function:** `uploadFile(uri, storagePath, options?)`
216
+
217
+ **When to Use:**
218
+ - Files from file pickers
219
+ - Document uploads
220
+ - Large files
221
+ - Video uploads
222
+
223
+ **Supported URI Schemes:**
224
+ - `file://` - File system URIs
225
+ - `content://` - Android content URIs
226
+ - `http://` - Remote files
227
+
228
+ **Upload Options:**
229
+ - `mimeType` - Explicit MIME type (recommended for non-images)
230
+ - `customMetadata` - Custom key-value pairs
231
+
232
+ ## 🗑️ Deletion Operations
233
+
234
+ ### Single File Deletion
235
+
236
+ **Function:** `deleteStorageFile(downloadUrlOrPath)`
237
+
238
+ **When to Use:**
239
+ - Deleting user profile picture
240
+ - Removing post attachments
241
+ - Cleaning up old files
242
+
243
+ **Accepts:**
244
+ - Full download URL
245
+ - Storage path only
246
+
247
+ **Returns:**
248
+ - `success` - Deletion status
249
+ - `storagePath` - Deleted file path
250
+
251
+ **Strategy:**
252
+ - Always store storage path in database
253
+ - Use path for deletion (not URL)
254
+ - Handle deletion errors
255
+
256
+ ### Batch Deletion
257
+
258
+ **Function:** `deleteStorageFiles(urlsOrPaths[])`
259
+
260
+ **When to Use:**
261
+ - Deleting album/photos
262
+ - Cleaning up multiple files
263
+ - Batch operations
264
+
265
+ **Returns:**
266
+ - `successful` - Array of deleted paths
267
+ - `failed` - Array of failed deletions with errors
268
+
269
+ **Strategy:**
270
+ - More efficient than individual deletions
271
+ - Handle partial failures
272
+ - Log failed deletions
273
+ - Verify all critical files deleted
274
+
275
+ ## 🤖 AI Agent Instructions
276
+
277
+ ### When Implementing Upload
278
+
279
+ 1. Organize paths by category (users, posts, products)
280
+ 2. Delete old file before uploading replacement
281
+ 3. Add metadata for tracking
282
+ 4. Handle network errors
283
+ 5. Show loading state to user
284
+ 6. Verify upload success
285
+
286
+ ### When Implementing Deletion
287
+
288
+ 1. Store storage path in database (not URL)
289
+ 2. Delete before uploading replacement
290
+ 3. Use batch deletion for multiple files
291
+ 4. Handle errors gracefully
292
+ 5. Inform user of failures
293
+ 6. Log deletion errors
294
+
295
+ ### When Organizing Paths
296
+
297
+ 1. Use hierarchical structure
298
+ 2. Include user/resource ID in path
299
+ 3. Use descriptive category names
300
+ 4. Include timestamp or unique identifier
301
+ 5. Keep paths consistent
302
+ 6. Document path patterns
303
+
304
+ ## 📏 Code Quality Standards
305
+
306
+ ### File Size
307
+
308
+ - **Maximum:** 200 lines per file
309
+ - **Strategy:** Split upload/delete logic into separate files
310
+ - **Current:** uploader/index.ts, deleter/index.ts
311
+
312
+ ### TypeScript
313
+
314
+ - Use strict mode
315
+ - Define proper types for all functions
316
+ - Export types used by other modules
317
+ - Never use `any` type
318
+
319
+ ### Naming Conventions
320
+
321
+ - Files: `kebab-case.ts`
322
+ - Functions: `camelCase`
323
+ - Interfaces/Types: `PascalCase`
324
+ - Storage paths: `kebab-case` with underscores
325
+
326
+ ### Error Handling
327
+
328
+ 1. Always try-catch upload operations
329
+ 2. Handle Firebase Storage errors
330
+ 3. Provide user-friendly error messages
331
+ 4. Log errors for debugging
332
+ 5. Never ignore errors
333
+
334
+ ## 🚨 Common Mistakes to Avoid
335
+
336
+ 1. ❌ Not deleting old files before uploading new ones
337
+ - ✅ Always delete old file first
338
+
339
+ 2. ❌ Storing download URLs in database
340
+ - ✅ Store storage paths instead
341
+
342
+ 3. ❌ Disorganized path structure
343
+ - ✅ Use hierarchical organized paths
344
+
345
+ 4. ❌ Missing metadata on uploads
346
+ - ✅ Always add tracking metadata
347
+
348
+ 5. ❌ Not handling upload errors
349
+ - ✅ Wrap in try-catch and show error to user
350
+
351
+ 6. ❌ Using root-level storage paths
352
+ - ✅ Organize by user/resource/category
353
+
354
+ ## 🔐 Security Rules Guidance
355
+
356
+ ### Basic User Path Security
357
+
358
+ **Path Pattern:** `users/{userId}/{allPaths=**}`
359
+
360
+ **Rules:**
361
+ - Allow read: Public (all users can read)
362
+ - Allow write: Only authenticated user matching userId in path
363
+
364
+ **Implementation Location:** Firebase Console → Storage → Rules
365
+
366
+ ### Product Path Security
367
+
368
+ **Path Pattern:** `products/{productId}/{allPaths=**}`
369
+
370
+ **Rules:**
371
+ - Allow read: Public (all users can read)
372
+ - Allow write: Authenticated users only
373
+
374
+ **Implementation Location:** Firebase Console → Storage → Rules
375
+
376
+ ### Key Security Principles
377
+
378
+ 1. **Validate user ID** - Match request.auth.uid to path
379
+ 2. **Validate file types** - Check MIME type in metadata
380
+ 3. **Validate file size** - Limit upload size
381
+ 4. **Public reads** - Allow public read for images
382
+ 5. **Authenticated writes** - Require authentication for writes
383
+
384
+ ## 📊 Performance Considerations
385
+
386
+ ### Upload Optimization
387
+
388
+ - **Compress images** before uploading
389
+ - **Limit file sizes** (recommend <5MB for mobile)
390
+ - **Use progressive encoding** for large images
391
+ - **Show upload progress** to users
392
+ - **Implement retry logic** for failed uploads
393
+
394
+ ### Storage Cost Management
395
+
396
+ - **Delete old files** to reduce storage costs
397
+ - **Use lifecycle policies** for automatic cleanup
398
+ - **Compress images** before upload
399
+ - **Monitor storage usage** regularly
400
+ - **Set appropriate file size limits**
401
+
402
+ ## 📚 Related Documentation
403
+
404
+ - [Development Guidelines](../../CONTRIBUTING.md)
405
+ - [Firebase Storage Documentation](https://firebase.google.com/docs/storage)
406
+ - [Storage Security Rules](https://firebase.google.com/docs/storage/security/start)
407
+
408
+ ## 🔗 API Reference
409
+
410
+ ### Upload Functions
411
+
412
+ | Function | Description | Return Type |
413
+ |----------|-------------|-------------|
414
+ | `uploadBase64Image(base64, path, options?)` | Upload base64 image | `Promise<UploadResult>` |
415
+ | `uploadFile(uri, path, options?)` | Upload file from URI | `Promise<UploadResult>` |
416
+ | `getMimeType(base64)` | Detect MIME type | `string` |
417
+
418
+ ### Delete Functions
419
+
420
+ | Function | Description | Return Type |
421
+ |----------|-------------|-------------|
422
+ | `deleteStorageFile(urlOrPath)` | Delete single file | `Promise<DeleteResult>` |
423
+ | `deleteStorageFiles(urlsOrPaths[])` | Delete multiple files | `Promise<BatchDeleteResult>` |
424
+
425
+ ### Types
426
+
427
+ **UploadResult**
428
+ - `downloadUrl` - Public download URL
429
+ - `storagePath` - Internal storage path
430
+
431
+ **UploadOptions**
432
+ - `mimeType` - Content type (auto-detected for base64 images)
433
+ - `customMetadata` - Key-value pairs for tracking
434
+
435
+ **DeleteResult**
436
+ - `success` - Deletion status
437
+ - `storagePath` - Deleted file path
438
+
439
+ **BatchDeleteResult**
440
+ - `successful` - Array of deleted paths
441
+ - `failed` - Array of failed deletions with path and error
442
+
443
+ ## 🎓 Key Concepts
444
+
445
+ ### Why Clean Up Old Files?
446
+
447
+ **Storage Costs:**
448
+ - Firebase Storage charges by GB stored
449
+ - Old files waste money
450
+ - Accumulated files increase costs over time
451
+
452
+ **Performance:**
453
+ - Fewer files = faster listings
454
+ - Reduced clutter
455
+ - Easier management
456
+
457
+ **User Experience:**
458
+ - Avoid broken references
459
+ - Prevent stale content
460
+ - Keep data fresh
461
+
462
+ ### Why Use Storage Paths Not URLs?
463
+
464
+ **Paths:**
465
+ - Stable and permanent
466
+ - Work across environments
467
+ - Can generate URL when needed
468
+ - Smaller database storage
469
+
470
+ **URLs:**
471
+ - May contain tokens
472
+ - Environment-specific
473
+ - Larger storage requirement
474
+ - Can change
475
+
476
+ ### Why Add Metadata?
477
+
478
+ **Tracking:**
479
+ - Who uploaded the file
480
+ - When it was uploaded
481
+ - What the original filename was
482
+ - File type and category
483
+
484
+ **Management:**
485
+ - Easy to identify files
486
+ - Can filter by metadata
487
+ - Audit trail
488
+ - Debugging support
489
+
490
+ ---
491
+
492
+ **Last Updated:** 2025-01-08
493
+ **Maintainer:** Storage Module Team