@umituz/react-native-firebase 2.6.6 → 3.0.0

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.6",
3
+ "version": "3.0.0",
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,17 +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
- // Re-export commonly used Firebase Firestore types
106
- export type {
107
- Timestamp,
108
- DocumentSnapshot,
109
- QuerySnapshot,
110
- DocumentReference,
111
- CollectionReference,
112
- Query,
113
- Transaction,
114
- } from 'firebase/firestore';
115
-
116
- // Firebase types are available from the 'firebase' package directly
117
- // Import them in your app: import { Timestamp } from 'firebase/firestore';
@@ -1,79 +1,80 @@
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
4
+ * IMPORTANT: Does NOT import from firebase/firestore.
5
+ * Import firebase SDK in your app and initialize it there.
6
+ *
7
+ * This client only provides type definitions and initialization helpers.
6
8
  */
7
9
 
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
16
- */
17
- class FirestoreClientSingleton extends ServiceClientSingleton<Firestore> {
18
- private constructor() {
19
- super();
20
- }
10
+ import { FirebaseInitializationError } from "../../../../shared/domain/errors/FirebaseError";
21
11
 
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
- }
12
+ export interface Firestore {
13
+ app: unknown; // FirebaseApp from firebase/app
14
+ }
29
15
 
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
- }
16
+ let firestoreInstance: Firestore | null = null;
17
+ let initializationError: Error | null = null;
39
18
 
40
- getFirestore(): Firestore {
41
- if (!this.isInitialized()) {
42
- return this.initialize();
43
- }
44
- return this.getInstance();
19
+ /**
20
+ * Initialize Firestore
21
+ * Note: This is a placeholder. You should initialize Firestore in your app using:
22
+ * import { initializeFirestore } from 'firebase/firestore';
23
+ * import { getReactNativePersistence } from 'firebase/firestore/react-native';
24
+ */
25
+ export async function initializeFirestore(
26
+ firebaseApp: unknown // FirebaseApp from firebase/app
27
+ ): Promise<Firestore> {
28
+ if (firestoreInstance) {
29
+ return firestoreInstance;
45
30
  }
46
31
 
47
- private static instance: FirestoreClientSingleton | null = null;
32
+ try {
33
+ // In a real app, you would do:
34
+ // const { getFirestore, initializeFirestore } = await import('firebase/firestore');
35
+ // const { getReactNativePersistence } = await import('firebase/firestore/react-native');
36
+ // const persistence = getReactNativePersistence();
37
+ // firestoreInstance = initializeFirestore(firebaseApp, {
38
+ // localCache: persistence
39
+ // });
48
40
 
49
- static getInstance(): FirestoreClientSingleton {
50
- if (!this.instance) {
51
- this.instance = new FirestoreClientSingleton();
52
- }
53
- return this.instance;
41
+ // For now, this is a placeholder that assumes firestore is initialized elsewhere
42
+ throw new FirebaseInitializationError(
43
+ "Firestore must be initialized in your app using firebase/firestore SDK. " +
44
+ "Use initializeFirestore() from 'firebase/firestore' with React Native persistence."
45
+ );
46
+ } catch (error) {
47
+ initializationError = error as Error;
48
+ throw error;
54
49
  }
55
50
  }
56
51
 
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
- };
52
+ /**
53
+ * Get Firestore instance
54
+ * Returns null if not initialized
55
+ */
56
+ export function getFirestore(): Firestore | null {
57
+ return firestoreInstance;
58
+ }
70
59
 
71
- export const getFirestoreInitializationError = (): Error | null => {
72
- return firestoreClientSingleton.getInitializationError();
73
- };
60
+ /**
61
+ * Check if Firestore is initialized
62
+ */
63
+ export function isFirestoreInitialized(): boolean {
64
+ return firestoreInstance !== null;
65
+ }
74
66
 
75
- export const resetFirestoreClient = (): void => {
76
- firestoreClientSingleton.reset();
77
- };
67
+ /**
68
+ * Get Firestore initialization error
69
+ */
70
+ export function getFirestoreInitializationError(): Error | null {
71
+ return initializationError;
72
+ }
78
73
 
79
- export type { Firestore } from 'firebase/firestore';
74
+ /**
75
+ * Reset Firestore client state
76
+ */
77
+ export function resetFirestoreClient(): void {
78
+ firestoreInstance = null;
79
+ initializationError = null;
80
+ }
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
@@ -32,8 +37,6 @@ export type {
32
37
  ServiceInitializationResult,
33
38
  } from "./shared/infrastructure/config/services/FirebaseInitializationService";
34
39
 
35
- export type { FirebaseApp } from 'firebase/app';
36
-
37
40
  // Type Guards
38
41
  export {
39
42
  isFirestoreError,
@@ -0,0 +1,274 @@
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
+ export interface Firestore {
33
+ app: FirebaseApp;
34
+ }
35
+
36
+ export interface DocumentSnapshot<T = unknown> {
37
+ id: string;
38
+ ref: DocumentReference<T>;
39
+ data: T | null;
40
+ metadata: SnapshotMetadata;
41
+ exists(): boolean;
42
+ }
43
+
44
+ export interface SnapshotMetadata {
45
+ hasPendingWrites: boolean;
46
+ fromCache: boolean;
47
+ }
48
+
49
+ export interface QuerySnapshot<T = unknown> {
50
+ docs: QueryDocumentSnapshot<T>[];
51
+ metadata: SnapshotMetadata;
52
+ size: number;
53
+ empty: boolean;
54
+ docChanges: DocumentChange<T>[];
55
+ }
56
+
57
+ export interface QueryDocumentSnapshot<T = unknown> extends DocumentSnapshot<T> {}
58
+
59
+ export interface DocumentReference<T = unknown> {
60
+ id: string;
61
+ firestore: Firestore;
62
+ path: string;
63
+ parent: CollectionReference<T> | null;
64
+ get(): Promise<DocumentSnapshot<T>>;
65
+ }
66
+
67
+ export interface CollectionReference<T = unknown> {
68
+ id: string;
69
+ firestore: Firestore;
70
+ path: string;
71
+ parent: CollectionReference<unknown> | DocumentReference<unknown> | null;
72
+ doc(documentPath?: string): DocumentReference<T>;
73
+ }
74
+
75
+ export interface Query<T = unknown> {
76
+ firestore: Firestore;
77
+ }
78
+
79
+ // =============================================================================
80
+ // Firestore Types - Field Values
81
+ // =============================================================================
82
+
83
+ export type FieldPath = string | readonly string[];
84
+
85
+ export interface FieldValue {
86
+ isEqual(other: unknown): boolean;
87
+ }
88
+
89
+ export interface Bytes {
90
+ toUint8Array(): Uint8Array;
91
+ toBase64(): string;
92
+ toString(format?: 'base64' | 'base64url'): string;
93
+ }
94
+
95
+ // =============================================================================
96
+ // Firestore Types - Timestamp
97
+ // =============================================================================
98
+
99
+ export class Timestamp {
100
+ readonly seconds: number;
101
+ readonly nanoseconds: number;
102
+
103
+ constructor(seconds: number, nanoseconds: number);
104
+
105
+ static now(): Timestamp;
106
+ static fromDate(date: Date): Timestamp;
107
+ static fromMillis(milliseconds: number): Timestamp;
108
+
109
+ toDate(): Date;
110
+ toMillis(): number;
111
+ toString(): string;
112
+ isEqual(other: Timestamp): boolean;
113
+
114
+ valueOf(): number {
115
+ return this.toMillis();
116
+ }
117
+ }
118
+
119
+ // =============================================================================
120
+ // Firestore Types - GeoPoint
121
+ // =============================================================================
122
+
123
+ export class GeoPoint {
124
+ readonly latitude: number;
125
+ readonly longitude: number;
126
+
127
+ constructor(latitude: number, longitude: number);
128
+
129
+ toString(): string;
130
+ isEqual(other: GeoPoint): boolean;
131
+ }
132
+
133
+ // =============================================================================
134
+ // Firestore Types - Transaction
135
+ // =============================================================================
136
+
137
+ export interface Transaction {
138
+ get(documentRef: DocumentReference): Promise<DocumentSnapshot>;
139
+ set(documentRef: DocumentReference, data: unknown): Promise<void>;
140
+ update(documentRef: DocumentReference, data: Partial<unknown>): Promise<void>;
141
+ delete(documentRef: DocumentReference): Promise<void>;
142
+ }
143
+
144
+ // =============================================================================
145
+ // Firestore Types - Query
146
+ // =============================================================================
147
+
148
+ export type WhereFilterOp =
149
+ | '<'
150
+ | '<='
151
+ | '=='
152
+ | '!='
153
+ | '>='
154
+ | '>'
155
+ | 'array-contains'
156
+ | 'in'
157
+ | 'array-contains-any'
158
+ | 'not-in';
159
+
160
+ export type OrderByDirection = 'asc' | 'desc';
161
+
162
+ export type QueryConstraint = QueryFilterConstraint | QueryOrderByConstraint | QueryLimitConstraint | QueryStartAtConstraint | QueryEndAtConstraint;
163
+
164
+ export interface QueryFilterConstraint {
165
+ type: 'where';
166
+ fieldPath: FieldPath;
167
+ op: WhereFilterOp;
168
+ value: unknown;
169
+ }
170
+
171
+ export interface QueryOrderByConstraint {
172
+ type: 'orderBy';
173
+ fieldPath: FieldPath;
174
+ direction?: OrderByDirection;
175
+ }
176
+
177
+ export interface QueryLimitConstraint {
178
+ type: 'limit';
179
+ limit: number;
180
+ }
181
+
182
+ export interface QueryStartAtConstraint {
183
+ type: 'startAt';
184
+ cursor: unknown;
185
+ }
186
+
187
+ export interface QueryEndAtConstraint {
188
+ type: 'endAt';
189
+ cursor: unknown;
190
+ }
191
+
192
+ // =============================================================================
193
+ // Auth Types
194
+ // =============================================================================
195
+
196
+ export interface Auth {
197
+ app: FirebaseApp;
198
+ currentUser: User | null;
199
+ }
200
+
201
+ export interface User {
202
+ uid: string;
203
+ email: string | null;
204
+ emailVerified: boolean;
205
+ displayName: string | null;
206
+ photoURL: string | null;
207
+ phoneNumber: string | null;
208
+ tenantId: string | null;
209
+ providerId: string;
210
+ metadata: UserMetadata;
211
+ isAnonymous: boolean;
212
+ }
213
+
214
+ export interface UserMetadata {
215
+ creationTime?: string;
216
+ lastSignInTime?: string | null;
217
+ }
218
+
219
+ export interface UserCredential {
220
+ user: User;
221
+ providerId: string | null;
222
+ operationType?: string;
223
+ }
224
+
225
+ export interface AuthCredential {
226
+ providerId: string;
227
+ signInMethod: string;
228
+ }
229
+
230
+ // =============================================================================
231
+ // Error Types
232
+ // =============================================================================
233
+
234
+ export interface FirestoreError {
235
+ code: string;
236
+ message: string;
237
+ name: string;
238
+ }
239
+
240
+ export interface AuthError {
241
+ code: string;
242
+ message: string;
243
+ name: string;
244
+ }
245
+
246
+ export interface FirebaseError extends Error {
247
+ code: string;
248
+ name: string;
249
+ }
250
+
251
+ // =============================================================================
252
+ // Change Type
253
+ // =============================================================================
254
+
255
+ export type DocumentChangeType = 'added' | 'removed' | 'modified';
256
+
257
+ export interface DocumentChange<T = unknown> {
258
+ type: DocumentChangeType;
259
+ doc: QueryDocumentSnapshot<T>;
260
+ oldIndex?: number;
261
+ newIndex?: number;
262
+ }
263
+
264
+ // =============================================================================
265
+ // Blob Types
266
+ // =============================================================================
267
+
268
+ export interface Blob {
269
+ bytes: Uint8Array;
270
+ }
271
+
272
+ export function blob(bytes: Uint8Array): Blob {
273
+ return { bytes };
274
+ }