@umituz/react-native-firebase 2.6.7 → 3.0.1

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": "2.6.7",
3
+ "version": "3.0.1",
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",
@@ -1,6 +1,11 @@
1
1
  /**
2
2
  * React Native Firestore Module
3
3
  * Domain-Driven Design (DDD) Architecture
4
+ *
5
+ * IMPORTANT: This package does NOT import from 'firebase/firestore' or 'firebase/auth'.
6
+ * Import those directly in your app using the firebase SDK if you need types.
7
+ *
8
+ * This package provides utilities and repositories ONLY.
4
9
  */
5
10
 
6
11
  // =============================================================================
@@ -101,7 +106,3 @@ export { useFirestoreSnapshot } from './presentation/hooks/useFirestoreSnapshot'
101
106
  export type { UseFirestoreQueryOptions } from './presentation/hooks/useFirestoreQuery';
102
107
  export type { UseFirestoreMutationOptions } from './presentation/hooks/useFirestoreMutation';
103
108
  export type { UseFirestoreSnapshotOptions } from './presentation/hooks/useFirestoreSnapshot';
104
-
105
- // Export Firestore types directly from firebase package
106
- // Import them in your app: import { Timestamp } from 'firebase/firestore';
107
-
@@ -1,79 +1,76 @@
1
1
  /**
2
- * Firestore Client - Infrastructure Layer
2
+ * Firestore Configuration Client
3
3
  *
4
- * Domain-Driven Design: Infrastructure implementation of Firestore client
5
- * Singleton pattern for managing Firestore instance
6
- */
7
-
8
- import type { Firestore } from 'firebase/firestore';
9
- import { getFirestore as getFirestoreFromFirebase } from 'firebase/firestore';
10
- import { getFirebaseApp } from '../../../../shared/infrastructure/config/services/FirebaseInitializationService';
11
- import { ServiceClientSingleton } from '../../../../shared/infrastructure/config/base/ServiceClientSingleton';
12
-
13
- /**
14
- * Firestore Client Singleton
15
- * Manages Firestore initialization
4
+ * IMPORTANT: This package does NOT import from firebase/firestore to avoid
5
+ * IndexedDB dependencies that break React Native bundling.
6
+ *
7
+ * Instead, you should:
8
+ * 1. Install firebase SDK in your app: npm install firebase
9
+ * 2. Import and use getFirestore() from 'firebase/firestore' directly
10
+ * 3. Use the utilities from this package for repositories and helpers
16
11
  */
17
- class FirestoreClientSingleton extends ServiceClientSingleton<Firestore> {
18
- private constructor() {
19
- super();
20
- }
21
-
22
- initialize(): Firestore {
23
- try {
24
- const app = getFirebaseApp();
25
- if (!app) {
26
- this.setError('Firebase App is not initialized');
27
- throw new Error('Firebase App is not initialized');
28
- }
29
12
 
30
- const firestore = getFirestoreFromFirebase(app);
31
- this.instance = firestore;
32
- return firestore;
33
- } catch (error) {
34
- const errorMessage = error instanceof Error ? error.message : 'Firestore initialization failed';
35
- this.setError(errorMessage);
36
- throw error;
37
- }
38
- }
13
+ import { FirebaseInitializationError } from "../../../../shared/domain/errors/FirebaseError";
39
14
 
40
- getFirestore(): Firestore {
41
- if (!this.isInitialized()) {
42
- return this.initialize();
43
- }
44
- return this.getInstance();
45
- }
15
+ // Firestore type from firebase/firestore SDK
16
+ // Import in your app: import type { Firestore } from 'firebase/firestore'
17
+ export type Firestore = unknown;
46
18
 
47
- private static instance: FirestoreClientSingleton | null = null;
19
+ let firestoreInstance: Firestore | null = null;
20
+ let initializationError: Error | null = null;
48
21
 
49
- static getInstance(): FirestoreClientSingleton {
50
- if (!this.instance) {
51
- this.instance = new FirestoreClientSingleton();
52
- }
53
- return this.instance;
54
- }
22
+ /**
23
+ * Initialize Firestore
24
+ *
25
+ * DEPRECATED: This function is deprecated and will be removed in future versions.
26
+ *
27
+ * Instead, initialize Firestore directly in your app:
28
+ * ```typescript
29
+ * import { initializeFirestore } from 'firebase/firestore';
30
+ * import { getReactNativePersistence } from 'firebase/firestore/react-native';
31
+ * import AsyncStorage from '@react-native-async-storage/async-storage';
32
+ *
33
+ * const firestore = initializeFirestore(firebaseApp, {
34
+ * localCache: getReactNativePersistence(AsyncStorage)
35
+ * });
36
+ * ```
37
+ */
38
+ export async function initializeFirestore(
39
+ firebaseApp: unknown // FirebaseApp from firebase/app
40
+ ): Promise<Firestore> {
41
+ throw new FirebaseInitializationError(
42
+ "Firestore initialization has moved. " +
43
+ "Please use initializeFirestore() from 'firebase/firestore' directly in your app. " +
44
+ "See package README for migration guide."
45
+ );
55
46
  }
56
47
 
57
- const firestoreClientSingleton = FirestoreClientSingleton.getInstance();
58
-
59
- export const initializeFirestore = (): Firestore => {
60
- return firestoreClientSingleton.initialize();
61
- };
62
-
63
- export const getFirestore = (): Firestore => {
64
- return firestoreClientSingleton.getFirestore();
65
- };
66
-
67
- export const isFirestoreInitialized = (): boolean => {
68
- return firestoreClientSingleton.isInitialized();
69
- };
48
+ /**
49
+ * Get Firestore instance
50
+ * Returns null if not initialized
51
+ */
52
+ export function getFirestore(): Firestore | null {
53
+ return firestoreInstance;
54
+ }
70
55
 
71
- export const getFirestoreInitializationError = (): Error | null => {
72
- return firestoreClientSingleton.getInitializationError();
73
- };
56
+ /**
57
+ * Check if Firestore is initialized
58
+ */
59
+ export function isFirestoreInitialized(): boolean {
60
+ return firestoreInstance !== null;
61
+ }
74
62
 
75
- export const resetFirestoreClient = (): void => {
76
- firestoreClientSingleton.reset();
77
- };
63
+ /**
64
+ * Get Firestore initialization error
65
+ */
66
+ export function getFirestoreInitializationError(): Error | null {
67
+ return initializationError;
68
+ }
78
69
 
79
- export type { Firestore } from 'firebase/firestore';
70
+ /**
71
+ * Reset Firestore client state
72
+ */
73
+ export function resetFirestoreClient(): void {
74
+ firestoreInstance = null;
75
+ initializationError = null;
76
+ }
package/src/index.ts CHANGED
@@ -2,6 +2,11 @@
2
2
  * React Native Firebase - Unified Package
3
3
  *
4
4
  * Domain-Driven Design (DDD) Architecture
5
+ *
6
+ * IMPORTANT: This package does NOT import from 'firebase/app' or other firebase packages.
7
+ * Import firebase SDK directly in your app if you need those types.
8
+ *
9
+ * This package provides utilities and abstractions ONLY for React Native.
5
10
  */
6
11
 
7
12
  // Core Errors
@@ -0,0 +1,276 @@
1
+ /**
2
+ * Firebase Type Definitions
3
+ *
4
+ * These types mirror Firebase SDK types but don't import from the firebase package.
5
+ * This prevents the 'idb' dependency that causes bundling errors in React Native.
6
+ */
7
+
8
+ // =============================================================================
9
+ // Firebase App Types
10
+ // =============================================================================
11
+
12
+ export interface FirebaseApp {
13
+ name: string;
14
+ options?: FirebaseAppOptions;
15
+ }
16
+
17
+ export interface FirebaseAppOptions {
18
+ apiKey?: string;
19
+ authDomain?: string;
20
+ databaseURL?: string;
21
+ projectId?: string;
22
+ storageBucket?: string;
23
+ messagingSenderId?: string;
24
+ appId?: string;
25
+ measurementId?: string;
26
+ }
27
+
28
+ // =============================================================================
29
+ // Firestore Types
30
+ // =============================================================================
31
+
32
+ // IMPORTANT: Import Firestore from 'firebase/firestore' in your app
33
+ // Do NOT use this type - it's only for internal package compatibility
34
+ export interface Firestore {
35
+ readonly __brand: 'Firestore';
36
+ }
37
+
38
+ export interface DocumentSnapshot<T = unknown> {
39
+ id: string;
40
+ ref: DocumentReference<T>;
41
+ data: T | null;
42
+ metadata: SnapshotMetadata;
43
+ exists(): boolean;
44
+ }
45
+
46
+ export interface SnapshotMetadata {
47
+ hasPendingWrites: boolean;
48
+ fromCache: boolean;
49
+ }
50
+
51
+ export interface QuerySnapshot<T = unknown> {
52
+ docs: QueryDocumentSnapshot<T>[];
53
+ metadata: SnapshotMetadata;
54
+ size: number;
55
+ empty: boolean;
56
+ docChanges: DocumentChange<T>[];
57
+ }
58
+
59
+ export interface QueryDocumentSnapshot<T = unknown> extends DocumentSnapshot<T> {}
60
+
61
+ export interface DocumentReference<T = unknown> {
62
+ id: string;
63
+ firestore: Firestore;
64
+ path: string;
65
+ parent: CollectionReference<T> | null;
66
+ get(): Promise<DocumentSnapshot<T>>;
67
+ }
68
+
69
+ export interface CollectionReference<T = unknown> {
70
+ id: string;
71
+ firestore: Firestore;
72
+ path: string;
73
+ parent: CollectionReference<unknown> | DocumentReference<unknown> | null;
74
+ doc(documentPath?: string): DocumentReference<T>;
75
+ }
76
+
77
+ export interface Query<T = unknown> {
78
+ firestore: Firestore;
79
+ }
80
+
81
+ // =============================================================================
82
+ // Firestore Types - Field Values
83
+ // =============================================================================
84
+
85
+ export type FieldPath = string | readonly string[];
86
+
87
+ export interface FieldValue {
88
+ isEqual(other: unknown): boolean;
89
+ }
90
+
91
+ export interface Bytes {
92
+ toUint8Array(): Uint8Array;
93
+ toBase64(): string;
94
+ toString(format?: 'base64' | 'base64url'): string;
95
+ }
96
+
97
+ // =============================================================================
98
+ // Firestore Types - Timestamp
99
+ // =============================================================================
100
+
101
+ export class Timestamp {
102
+ readonly seconds: number;
103
+ readonly nanoseconds: number;
104
+
105
+ constructor(seconds: number, nanoseconds: number);
106
+
107
+ static now(): Timestamp;
108
+ static fromDate(date: Date): Timestamp;
109
+ static fromMillis(milliseconds: number): Timestamp;
110
+
111
+ toDate(): Date;
112
+ toMillis(): number;
113
+ toString(): string;
114
+ isEqual(other: Timestamp): boolean;
115
+
116
+ valueOf(): number {
117
+ return this.toMillis();
118
+ }
119
+ }
120
+
121
+ // =============================================================================
122
+ // Firestore Types - GeoPoint
123
+ // =============================================================================
124
+
125
+ export class GeoPoint {
126
+ readonly latitude: number;
127
+ readonly longitude: number;
128
+
129
+ constructor(latitude: number, longitude: number);
130
+
131
+ toString(): string;
132
+ isEqual(other: GeoPoint): boolean;
133
+ }
134
+
135
+ // =============================================================================
136
+ // Firestore Types - Transaction
137
+ // =============================================================================
138
+
139
+ export interface Transaction {
140
+ get(documentRef: DocumentReference): Promise<DocumentSnapshot>;
141
+ set(documentRef: DocumentReference, data: unknown): Promise<void>;
142
+ update(documentRef: DocumentReference, data: Partial<unknown>): Promise<void>;
143
+ delete(documentRef: DocumentReference): Promise<void>;
144
+ }
145
+
146
+ // =============================================================================
147
+ // Firestore Types - Query
148
+ // =============================================================================
149
+
150
+ export type WhereFilterOp =
151
+ | '<'
152
+ | '<='
153
+ | '=='
154
+ | '!='
155
+ | '>='
156
+ | '>'
157
+ | 'array-contains'
158
+ | 'in'
159
+ | 'array-contains-any'
160
+ | 'not-in';
161
+
162
+ export type OrderByDirection = 'asc' | 'desc';
163
+
164
+ export type QueryConstraint = QueryFilterConstraint | QueryOrderByConstraint | QueryLimitConstraint | QueryStartAtConstraint | QueryEndAtConstraint;
165
+
166
+ export interface QueryFilterConstraint {
167
+ type: 'where';
168
+ fieldPath: FieldPath;
169
+ op: WhereFilterOp;
170
+ value: unknown;
171
+ }
172
+
173
+ export interface QueryOrderByConstraint {
174
+ type: 'orderBy';
175
+ fieldPath: FieldPath;
176
+ direction?: OrderByDirection;
177
+ }
178
+
179
+ export interface QueryLimitConstraint {
180
+ type: 'limit';
181
+ limit: number;
182
+ }
183
+
184
+ export interface QueryStartAtConstraint {
185
+ type: 'startAt';
186
+ cursor: unknown;
187
+ }
188
+
189
+ export interface QueryEndAtConstraint {
190
+ type: 'endAt';
191
+ cursor: unknown;
192
+ }
193
+
194
+ // =============================================================================
195
+ // Auth Types
196
+ // =============================================================================
197
+
198
+ export interface Auth {
199
+ app: FirebaseApp;
200
+ currentUser: User | null;
201
+ }
202
+
203
+ export interface User {
204
+ uid: string;
205
+ email: string | null;
206
+ emailVerified: boolean;
207
+ displayName: string | null;
208
+ photoURL: string | null;
209
+ phoneNumber: string | null;
210
+ tenantId: string | null;
211
+ providerId: string;
212
+ metadata: UserMetadata;
213
+ isAnonymous: boolean;
214
+ }
215
+
216
+ export interface UserMetadata {
217
+ creationTime?: string;
218
+ lastSignInTime?: string | null;
219
+ }
220
+
221
+ export interface UserCredential {
222
+ user: User;
223
+ providerId: string | null;
224
+ operationType?: string;
225
+ }
226
+
227
+ export interface AuthCredential {
228
+ providerId: string;
229
+ signInMethod: string;
230
+ }
231
+
232
+ // =============================================================================
233
+ // Error Types
234
+ // =============================================================================
235
+
236
+ export interface FirestoreError {
237
+ code: string;
238
+ message: string;
239
+ name: string;
240
+ }
241
+
242
+ export interface AuthError {
243
+ code: string;
244
+ message: string;
245
+ name: string;
246
+ }
247
+
248
+ export interface FirebaseError extends Error {
249
+ code: string;
250
+ name: string;
251
+ }
252
+
253
+ // =============================================================================
254
+ // Change Type
255
+ // =============================================================================
256
+
257
+ export type DocumentChangeType = 'added' | 'removed' | 'modified';
258
+
259
+ export interface DocumentChange<T = unknown> {
260
+ type: DocumentChangeType;
261
+ doc: QueryDocumentSnapshot<T>;
262
+ oldIndex?: number;
263
+ newIndex?: number;
264
+ }
265
+
266
+ // =============================================================================
267
+ // Blob Types
268
+ // =============================================================================
269
+
270
+ export interface Blob {
271
+ bytes: Uint8Array;
272
+ }
273
+
274
+ export function blob(bytes: Uint8Array): Blob {
275
+ return { bytes };
276
+ }