@umituz/react-native-firebase 1.13.120 → 1.13.122

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/package.json +3 -3
  2. package/src/auth/infrastructure/services/account-deletion.service.ts +4 -4
  3. package/src/auth/infrastructure/services/auth-utils.service.ts +2 -1
  4. package/src/auth/infrastructure/services/reauthentication.service.ts +15 -28
  5. package/src/domain/utils/error-handler.util.ts +90 -0
  6. package/src/domain/utils/id-generator.util.ts +50 -0
  7. package/src/domain/utils/validation.util.ts +133 -0
  8. package/src/firestore/infrastructure/middleware/QueryDeduplicationMiddleware.ts +26 -117
  9. package/src/firestore/infrastructure/services/RequestLoggerService.ts +2 -8
  10. package/src/firestore/utils/deduplication/index.ts +13 -0
  11. package/src/firestore/utils/deduplication/pending-query-manager.util.ts +93 -0
  12. package/src/firestore/utils/deduplication/query-key-generator.util.ts +41 -0
  13. package/src/firestore/utils/deduplication/timer-manager.util.ts +59 -0
  14. package/src/firestore/utils/document-mapper.helper.ts +45 -37
  15. package/src/firestore/utils/firestore-helper.ts +21 -85
  16. package/src/firestore/utils/mapper/base-mapper.util.ts +42 -0
  17. package/src/firestore/utils/mapper/enrichment-mapper.util.ts +82 -0
  18. package/src/firestore/utils/mapper/index.ts +8 -0
  19. package/src/firestore/utils/mapper/multi-enrichment-mapper.util.ts +39 -0
  20. package/src/firestore/utils/operation/operation-executor.util.ts +49 -0
  21. package/src/firestore/utils/query/filters.util.ts +75 -0
  22. package/src/firestore/utils/query/index.ts +10 -0
  23. package/src/firestore/utils/query/modifiers.util.ts +65 -0
  24. package/src/firestore/utils/query-builder.ts +7 -108
  25. package/src/firestore/utils/result/result.util.ts +45 -0
  26. package/src/firestore/utils/transaction/transaction.util.ts +45 -0
  27. package/src/index.ts +0 -1
  28. package/src/infrastructure/config/FirebaseConfigLoader.ts +9 -13
  29. package/src/storage/deleter/README.md +0 -370
  30. package/src/storage/deleter.ts +0 -109
  31. package/src/storage/index.ts +0 -8
  32. package/src/storage/storage-instance.ts +0 -11
  33. package/src/storage/types/README.md +0 -313
  34. package/src/storage/types.ts +0 -19
  35. package/src/storage/uploader.ts +0 -106
@@ -1,370 +0,0 @@
1
- # Storage Deleter
2
-
3
- Firebase Storage deletion functionality supporting single file and batch deletion operations.
4
-
5
- ## Purpose
6
-
7
- Provides file deletion capabilities for Firebase Storage with single file deletion, batch deletion operations, URL/path parsing, and comprehensive error handling/reporting.
8
-
9
- ## For AI Agents
10
-
11
- ### Before Using Storage Deleter
12
-
13
- 1. **ALWAYS** use deleter functions (never Firebase Storage SDK directly)
14
- 2. **TRACK** file paths in database for cleanup
15
- 3. **USE** batch deletion for multiple files
16
- 4. **HANDLE** deletion errors appropriately
17
- 5. **VERIFY** file paths before deletion
18
-
19
- ### Required Practices
20
-
21
- 1. **Use deleter functions** - Import from storage module
22
- 2. **Track file paths** - Store paths in Firestore database
23
- 3. **Use batch deletion** - Delete multiple files efficiently
24
- 4. **Handle partial failures** - Some files may fail to delete
25
- 5. **Check deletion results** - Verify success/failure
26
- 6. **Clean up old files** - Remove unused files regularly
27
-
28
- ### Forbidden Practices
29
-
30
- ## ❌ NEVER
31
-
32
- - Use Firebase Storage SDK directly in application code
33
- - Delete files without tracking paths
34
- - Ignore deletion failures
35
- - Delete files based on URL patterns (unreliable)
36
- - Assume deletion always succeeds
37
- - Delete without user confirmation (for user-initiated actions)
38
-
39
- ## ⚠️ Avoid
40
-
41
- - Sequential single deletes (use batch instead)
42
- - Not tracking deleted files
43
- - Deleting without verification
44
- - Not cleaning up temporary files
45
- - Ignoring partial batch failures
46
-
47
- ## Usage Strategies
48
-
49
- ### For Single File Deletion
50
-
51
- **Strategy:** Use deleteStorageFile for individual file deletion.
52
-
53
- **Import From:** `@umituz/react-native-firebase/storage` or `src/storage/deleter`
54
-
55
- **When to Use:**
56
- - Deleting single file (avatar, document)
57
- - Replacing old file with new
58
- - User-initiated deletion
59
- - Temporary file cleanup
60
-
61
- **Function:** `deleteStorageFile(downloadUrlOrPath)`
62
-
63
- **Parameters:**
64
- - `downloadUrlOrPath: string` - Download URL or storage path
65
-
66
- **Returns:** `Promise<DeleteResult>`
67
- - `success: boolean` - Deletion succeeded
68
- - `storagePath: string` - Storage path
69
-
70
- **Strategy:**
71
- 1. Use stored file path (from database)
72
- 2. Call deleteStorageFile
73
- 3. Check result.success
74
- 4. Handle failures appropriately
75
- 5. Update database to remove path reference
76
-
77
- ### For Batch Deletion
78
-
79
- **Strategy:** Use deleteStorageFiles for multiple file deletion.
80
-
81
- **Import From:** `@umituz/react-native-firebase/storage` or `src/storage/deleter`
82
-
83
- **When to Use:**
84
- - Deleting all user files
85
- - Cleaning up multiple documents
86
- - Gallery deletion
87
- - Bulk file cleanup
88
-
89
- **Function:** `deleteStorageFiles(urlsOrPaths)`
90
-
91
- **Parameters:**
92
- - `urlsOrPaths: string[]` - Array of download URLs or storage paths
93
-
94
- **Returns:** `Promise<BatchDeleteResult>`
95
- - `successful: string[]` - Array of deleted storage paths
96
- - `failed: Array<{path, error}>` - Failed deletions with errors
97
-
98
- **Strategy:**
99
- 1. Collect file paths from database
100
- 2. Call deleteStorageFiles with paths array
101
- 3. Check result.successful and result.failed
102
- 4. Log or retry failed deletions
103
- 5. Update database to remove deleted paths
104
-
105
- ### For User Account Deletion
106
-
107
- **Strategy:** Delete all user files when account is deleted.
108
-
109
- **Import From:** `@umituz/react-native-firebase/storage` and firestore
110
-
111
- **When to Use:**
112
- - User deletes account
113
- - GDPR compliance
114
- - User data cleanup
115
- - Admin-initiated deletion
116
-
117
- **Implementation Strategy:**
118
- 1. Fetch all user file paths from Firestore
119
- 2. Call deleteStorageFiles with paths
120
- 3. Check for partial failures
121
- 4. Log failed deletions for manual cleanup
122
- 5. Delete Firestore user document
123
- 6. Delete Auth account
124
-
125
- ### For Old Avatar Replacement
126
-
127
- **Strategy:** Delete old avatar when uploading new one.
128
-
129
- **Import From:** `@umituz/react-native-firebase/storage` and firestore
130
-
131
- **When to Use:**
132
- - User updates profile picture
133
- - Avatar replacement
134
- - Image updates
135
-
136
- **Implementation Strategy:**
137
- 1. Upload new avatar
138
- 2. Get new download URL
139
- 3. Delete old avatar if path exists
140
- 4. Update user document with new path
141
- 5. Handle deletion failure gracefully (old file not critical)
142
-
143
- ### For Temporary File Cleanup
144
-
145
- **Strategy:** Delete temporary files after use.
146
-
147
- **Import From:** `@umituz/react-native-firebase/storage` and firestore
148
-
149
- **When to Use:**
150
- - Clean up temp files after processing
151
- - Remove upload drafts
152
- - Delete expired files
153
-
154
- **Implementation Strategy:**
155
- 1. Track temporary files in database
156
- 2. Schedule cleanup after time period
157
- 3. Use batch deletion
158
- 4. Log failures for manual review
159
- 5. Update database to remove references
160
-
161
- ### For File Path Tracking
162
-
163
- **Strategy:** Store file paths in Firestore for later deletion.
164
-
165
- **Import From:** Firestore repository
166
-
167
- **When to Use:**
168
- - Need to delete files later
169
- - User account management
170
- - File ownership tracking
171
-
172
- **Tracking Strategy:**
173
- 1. Store storagePath in document when uploading
174
- 2. Add to array field for multiple files
175
- 3. Use arrayUnion for adding paths
176
- 4. Use arrayRemove for removing paths
177
- 5. Query all paths when deleting
178
-
179
- **Example Fields:**
180
- - `avatarPath: string` - Single avatar path
181
- - `photoPaths: string[]` - Multiple photo paths
182
- - `temporaryPaths: string[]` - Temporary file paths
183
- - `documentPaths: string[]` - Document file paths
184
-
185
- ### For Conditional Deletion
186
-
187
- **Strategy:** Delete file only if not referenced elsewhere.
188
-
189
- **Import From:** `@umituz/react-native-firebase/storage` and firestore
190
-
191
- **When to Use:**
192
- - File may be referenced by multiple documents
193
- - Need to verify file not in use
194
- - Prevent accidental deletion
195
-
196
- **Implementation Strategy:**
197
- 1. Check if file path referenced in database
198
- 2. Only delete if not referenced
199
- 3. Use transactions for verification
200
- 4. Handle race conditions
201
- 5. Log skipped deletions
202
-
203
- ## Error Handling
204
-
205
- ### Batch Deletion Failures
206
-
207
- **Strategy:** Handle partial failures in batch operations.
208
-
209
- **Import From:** Handle BatchDeleteResult from deleteStorageFiles
210
-
211
- **Failure Types:**
212
- - File not found (non-critical)
213
- - Network errors (retry recommended)
214
- - Unauthorized access (critical)
215
- - Storage quota exceeded (rare for deletion)
216
-
217
- **Handling Strategy:**
218
- 1. Check result.failed array
219
- 2. Log failed deletions with errors
220
- 3. Retry network failures
221
- 4. Alert on unauthorized errors
222
- 5. Continue on file-not-found errors
223
-
224
- ### Retry Strategy
225
-
226
- **Strategy:** Retry failed deletions with exponential backoff.
227
-
228
- **Implementation:**
229
- 1. First attempt: deleteStorageFiles
230
- 2. Collect failed paths from result
231
- 3. Wait with exponential backoff (1s, 2s, 4s)
232
- 4. Retry only failed paths
233
- 5. Limit retries to 3 attempts
234
- 6. Log permanently failed paths
235
-
236
- ## Common Mistakes to Avoid
237
-
238
- 1. ❌ Not tracking file paths
239
- - ✅ Store paths in Firestore database
240
-
241
- 2. ❌ Ignoring deletion failures
242
- - ✅ Check result.success and handle failures
243
-
244
- 3. ❌ Deleting without user confirmation
245
- - ✅ Confirm before destructive operations
246
-
247
- 4. ❌ Using sequential single deletes
248
- - ✅ Use batch deletion for multiple files
249
-
250
- 5. ❌ Not cleaning up temporary files
251
- - ✅ Schedule regular cleanup tasks
252
-
253
- 6. ❌ Assuming deletion always succeeds
254
- - ✅ Verify and handle partial failures
255
-
256
- ## AI Agent Instructions
257
-
258
- ### When Deleting Single File
259
-
260
- 1. Retrieve file path from database
261
- 2. Call deleteStorageFile with path
262
- 3. Check result.success
263
- 4. Update database to remove path
264
- 5. Handle errors appropriately
265
-
266
- ### When Deleting Multiple Files
267
-
268
- 1. Collect all file paths from database
269
- 2. Call deleteStorageFiles with paths array
270
- 3. Check result.failed for partial failures
271
- 4. Retry failed deletions if appropriate
272
- 5. Update database to remove deleted paths
273
- 6. Log permanently failed deletions
274
-
275
- ### When Replacing File
276
-
277
- 1. Upload new file first
278
- 2. Get new download URL and path
279
- 3. Delete old file if path exists
280
- 4. Handle deletion failure gracefully
281
- 5. Update database with new path
282
-
283
- ### When Cleaning User Files
284
-
285
- 1. Query all user file paths from database
286
- 2. Use batch deletion
287
- 3. Check for partial failures
288
- 4. Log failures for manual cleanup
289
- 5. Delete user document
290
- 6. Delete Auth account
291
-
292
- ## Code Quality Standards
293
-
294
- ### TypeScript
295
-
296
- - Use DeleteResult type for single deletion
297
- - Use BatchDeleteResult for batch deletion
298
- - Type all file path parameters
299
- - Handle errors properly
300
-
301
- ### Error Handling
302
-
303
- - Always check result.success
304
- - Handle result.failed in batch operations
305
- - Log technical errors for debugging
306
- - Return user-friendly error messages
307
- - Retry when appropriate
308
-
309
- ### File Path Management
310
-
311
- - Store paths in Firestore database
312
- - Use descriptive field names (avatarPath, photoPaths)
313
- - Update paths on file operations
314
- - Clean up path references on deletion
315
-
316
- ## Performance Considerations
317
-
318
- ### Batch vs Sequential
319
-
320
- **Batch Deletion:**
321
- - Deletes files in parallel
322
- - Faster for multiple files
323
- - Single API call
324
- - Recommended for > 1 file
325
-
326
- **Sequential Deletion:**
327
- - Only use for single file
328
- - Slower for multiple files
329
- - Multiple API calls
330
- - Not recommended
331
-
332
- ### Path Tracking Overhead
333
-
334
- - Minimal overhead to store paths
335
- - Faster deletion with known paths
336
- - No need to list Storage files
337
- - Better than URL parsing
338
-
339
- ## Related Documentation
340
-
341
- - [Storage Module README](../README.md)
342
- - [Storage Uploader README](../uploader/README.md)
343
- - [Storage Types README](../types/README.md)
344
- - [Auth README](../../auth/README.md)
345
-
346
- ## API Reference
347
-
348
- ### Main Functions
349
-
350
- **Import Path:** `@umituz/react-native-firebase/storage` or `src/storage/deleter`
351
-
352
- | Function | Parameters | Returns | Description |
353
- |----------|-----------|---------|-------------|
354
- | `deleteStorageFile` | downloadUrlOrPath | `Promise<DeleteResult>` | Delete single file |
355
- | `deleteStorageFiles` | urlsOrPaths[] | `Promise<BatchDeleteResult>` | Delete multiple files |
356
-
357
- ### Type Definitions
358
-
359
- **DeleteResult:**
360
- - `success: boolean` - Deletion succeeded
361
- - `storagePath: string` - Storage path
362
-
363
- **BatchDeleteResult:**
364
- - `successful: string[]` - Array of deleted storage paths
365
- - `failed: Array<{path, error}>` - Failed deletions with error messages
366
-
367
- ---
368
-
369
- **Last Updated:** 2025-01-08
370
- **Maintainer:** Storage Module Team
@@ -1,109 +0,0 @@
1
- /**
2
- * Firebase Storage Deleter
3
- * Handles single and batch deletion from Firebase Storage
4
- */
5
-
6
- import { ref, deleteObject } from "firebase/storage";
7
- import { getStorageInstance } from "./storage-instance";
8
- import type { DeleteResult } from "./types";
9
-
10
- /**
11
- * Batch delete result interface
12
- */
13
- export interface BatchDeleteResult {
14
- successful: string[];
15
- failed: Array<{ path: string; error: string }>;
16
- }
17
-
18
- /**
19
- * Extract storage path from Firebase download URL
20
- */
21
- function extractStoragePath(downloadUrl: string): string | null {
22
- if (!downloadUrl.startsWith("https://")) {
23
- return downloadUrl;
24
- }
25
-
26
- try {
27
- const urlObj = new URL(downloadUrl);
28
- const pathMatch = urlObj.pathname.match(/\/o\/(.+)/);
29
-
30
- if (!pathMatch || !pathMatch[1]) {
31
- return null;
32
- }
33
-
34
- return decodeURIComponent(pathMatch[1]);
35
- } catch {
36
- return null;
37
- }
38
- }
39
-
40
- /**
41
- * Delete image from Firebase Storage
42
- * Accepts either a download URL or storage path
43
- */
44
- export async function deleteStorageFile(
45
- downloadUrlOrPath: string
46
- ): Promise<DeleteResult> {
47
- const storagePath = extractStoragePath(downloadUrlOrPath);
48
-
49
- if (!storagePath) {
50
- return { success: false, storagePath: downloadUrlOrPath };
51
- }
52
-
53
- try {
54
- const storage = getStorageInstance();
55
- if (!storage) {
56
- throw new Error("Firebase Storage not initialized");
57
- }
58
-
59
- const storageRef = ref(storage, storagePath);
60
- await deleteObject(storageRef);
61
-
62
- return { success: true, storagePath };
63
- } catch {
64
- return { success: false, storagePath };
65
- }
66
- }
67
-
68
- /**
69
- * Delete multiple files from Firebase Storage
70
- * Processes deletions in parallel for better performance
71
- *
72
- * @param urlsOrPaths - Array of download URLs or storage paths
73
- * @returns Batch delete result with successful and failed deletions
74
- */
75
- export async function deleteStorageFiles(
76
- urlsOrPaths: string[]
77
- ): Promise<BatchDeleteResult> {
78
- const storage = getStorageInstance();
79
- if (!storage) {
80
- return {
81
- successful: [],
82
- failed: urlsOrPaths.map((path) => ({
83
- path,
84
- error: "Firebase Storage not initialized",
85
- })),
86
- };
87
- }
88
-
89
- const results = await Promise.allSettled(
90
- urlsOrPaths.map((urlOrPath) => deleteStorageFile(urlOrPath))
91
- );
92
-
93
- const successful: string[] = [];
94
- const failed: Array<{ path: string; error: string }> = [];
95
-
96
- results.forEach((result, index) => {
97
- if (result.status === "fulfilled" && result.value.success) {
98
- successful.push(result.value.storagePath);
99
- } else {
100
- const errorMessage = result.status === "rejected"
101
- ? String(result.reason instanceof Error ? result.reason.message : "Unknown error")
102
- : "Delete operation failed";
103
- const path = urlsOrPaths[index] ?? "unknown";
104
- failed.push({ path, error: errorMessage });
105
- }
106
- });
107
-
108
- return { successful, failed };
109
- }
@@ -1,8 +0,0 @@
1
- /**
2
- * Firebase Storage Module
3
- */
4
-
5
- export type { UploadResult, UploadOptions, DeleteResult } from "./types";
6
- export type { BatchDeleteResult } from "./deleter";
7
- export { uploadBase64Image, uploadFile, getMimeType } from "./uploader";
8
- export { deleteStorageFile, deleteStorageFiles } from "./deleter";
@@ -1,11 +0,0 @@
1
- /**
2
- * Shared Firebase Storage instance getter
3
- */
4
-
5
- import { getStorage } from "firebase/storage";
6
- import { getFirebaseApp } from "../infrastructure/config/FirebaseClient";
7
-
8
- export function getStorageInstance() {
9
- const app = getFirebaseApp();
10
- return app ? getStorage(app) : null;
11
- }