@umituz/react-native-firebase 1.13.14 → 1.13.16

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/react-native-firebase",
3
- "version": "1.13.14",
3
+ "version": "1.13.16",
4
4
  "description": "Unified Firebase package for React Native apps - Auth and Firestore services using Firebase JS SDK (no native modules).",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -19,7 +19,7 @@ export class QueryDeduplicationMiddleware {
19
19
  private pendingQueries = new Map<string, PendingQuery>();
20
20
  private readonly DEDUPLICATION_WINDOW_MS = 1000; // 1 second
21
21
  private readonly CLEANUP_INTERVAL_MS = 5000; // 5 seconds
22
- private cleanupTimer: NodeJS.Timeout | null = null;
22
+ private cleanupTimer: any = null;
23
23
 
24
24
  constructor() {
25
25
  this.startCleanupTimer();
@@ -32,7 +32,7 @@ export class QueryDeduplicationMiddleware {
32
32
  if (this.cleanupTimer) {
33
33
  clearInterval(this.cleanupTimer);
34
34
  }
35
-
35
+
36
36
  this.cleanupTimer = setInterval(() => {
37
37
  this.cleanupExpiredQueries();
38
38
  }, this.CLEANUP_INTERVAL_MS);
package/src/index.ts CHANGED
@@ -56,3 +56,10 @@ export * from './auth';
56
56
 
57
57
  export * from './firestore';
58
58
 
59
+ // =============================================================================
60
+ // STORAGE MODULE
61
+ // =============================================================================
62
+
63
+ export * from './storage';
64
+
65
+
@@ -0,0 +1 @@
1
+ export * from "./uploader";
@@ -0,0 +1,132 @@
1
+ /**
2
+ * Firebase Storage Uploader
3
+ * Uses fetch().blob() pattern for React Native compatibility
4
+ */
5
+
6
+ import {
7
+ getStorage,
8
+ ref,
9
+ uploadBytes,
10
+ getDownloadURL,
11
+ type UploadMetadata,
12
+ } from "firebase/storage";
13
+ import { getFirebaseApp } from "../infrastructure/config/FirebaseClient";
14
+
15
+ declare const __DEV__: boolean;
16
+
17
+ export interface UploadResult {
18
+ downloadUrl: string;
19
+ storagePath: string;
20
+ metadata?: any;
21
+ }
22
+
23
+ export interface UploadOptions {
24
+ mimeType?: string;
25
+ metadata?: any;
26
+ }
27
+
28
+ /**
29
+ * Extract MIME type from base64 data URL or return default
30
+ */
31
+ export function getMimeType(base64: string): string {
32
+ if (base64.startsWith("data:image/png")) return "image/png";
33
+ if (base64.startsWith("data:image/webp")) return "image/webp";
34
+ if (base64.startsWith("data:image/gif")) return "image/gif";
35
+ return "image/jpeg";
36
+ }
37
+
38
+ /**
39
+ * Ensure base64 has data URL prefix
40
+ */
41
+ function ensureDataUrl(base64: string, mimeType: string): string {
42
+ if (base64.startsWith("data:")) {
43
+ return base64;
44
+ }
45
+ return `data:${mimeType};base64,${base64}`;
46
+ }
47
+
48
+ function getStorageInstance() {
49
+ const app = getFirebaseApp();
50
+ return app ? getStorage(app) : null;
51
+ }
52
+
53
+ /**
54
+ * Upload base64 image to Firebase Storage
55
+ */
56
+ export async function uploadBase64Image(
57
+ base64: string,
58
+ storagePath: string,
59
+ options?: UploadOptions
60
+ ): Promise<UploadResult> {
61
+ const mimeType = options?.mimeType ?? getMimeType(base64);
62
+ const dataUrl = ensureDataUrl(base64, mimeType);
63
+
64
+ if (__DEV__) {
65
+ console.log("[StorageUploader] Starting base64 upload", {
66
+ storagePath,
67
+ mimeType,
68
+ });
69
+ }
70
+
71
+ const storage = getStorageInstance();
72
+ if (!storage) {
73
+ throw new Error("Firebase Storage not initialized");
74
+ }
75
+ const storageRef = ref(storage, storagePath);
76
+
77
+ const response = await fetch(dataUrl);
78
+ const blob = await response.blob();
79
+
80
+ const metadata: UploadMetadata = {
81
+ contentType: mimeType,
82
+ customMetadata: options?.metadata,
83
+ };
84
+
85
+ const snapshot = await uploadBytes(storageRef, blob, metadata);
86
+ const downloadUrl = await getDownloadURL(storageRef);
87
+
88
+ return {
89
+ downloadUrl,
90
+ storagePath,
91
+ metadata: snapshot.metadata,
92
+ };
93
+ }
94
+
95
+ /**
96
+ * Upload file from URI (file:// or content://)
97
+ */
98
+ export async function uploadFile(
99
+ uri: string,
100
+ storagePath: string,
101
+ options?: UploadOptions
102
+ ): Promise<UploadResult> {
103
+ if (__DEV__) {
104
+ console.log("[StorageUploader] Starting file upload", {
105
+ uri,
106
+ storagePath,
107
+ });
108
+ }
109
+
110
+ const storage = getStorageInstance();
111
+ if (!storage) {
112
+ throw new Error("Firebase Storage not initialized");
113
+ }
114
+ const storageRef = ref(storage, storagePath);
115
+
116
+ const response = await fetch(uri);
117
+ const blob = await response.blob();
118
+
119
+ const metadata: UploadMetadata = {
120
+ contentType: options?.mimeType ?? "image/jpeg",
121
+ customMetadata: options?.metadata,
122
+ };
123
+
124
+ const snapshot = await uploadBytes(storageRef, blob, metadata);
125
+ const downloadUrl = await getDownloadURL(storageRef);
126
+
127
+ return {
128
+ downloadUrl,
129
+ storagePath,
130
+ metadata: snapshot.metadata,
131
+ };
132
+ }