@umituz/react-native-firebase 2.4.86 → 2.4.88

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.4.86",
3
+ "version": "2.4.88",
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",
@@ -96,6 +96,7 @@ export {
96
96
  export {
97
97
  QueryDeduplicationMiddleware,
98
98
  queryDeduplicationMiddleware,
99
+ syncDeduplicationWithQuota,
99
100
  useDeduplicationWithQuota,
100
101
  } from './infrastructure/middleware/QueryDeduplicationMiddleware';
101
102
  export type {
@@ -30,9 +30,9 @@ const DEFAULT_CLEANUP_INTERVAL_MS = 15000; // 15s (was 3s)
30
30
  * Quota-based window adjustment thresholds
31
31
  */
32
32
  const QUOTA_THRESHOLDS = {
33
- HIGH_USAGE: 0.80, // 80% - extend window to 30s
33
+ HIGH_USAGE: 0.80, // 80% - extend window to 60s (1 min)
34
34
  MEDIUM_USAGE: 0.60, // 60% - extend window to 20s
35
- NORMAL: 0.60, // < 60% - use default 10s
35
+ NORMAL: 0.50, // < 50% - use default 10s
36
36
  } as const;
37
37
 
38
38
  /**
@@ -280,15 +280,21 @@ export const queryDeduplicationMiddleware = new QueryDeduplicationMiddleware({
280
280
  });
281
281
 
282
282
  /**
283
- * Hook to integrate deduplication with quota tracking
283
+ * Helper function to integrate deduplication with quota tracking
284
284
  * Automatically adjusts window based on quota usage
285
285
  *
286
+ * Note: This is NOT a React hook, but a helper function.
287
+ * Call this from your own hook or effect as needed.
288
+ *
286
289
  * @example
287
290
  * ```typescript
288
- * useDeduplicationWithQuota(queryDeduplicationMiddleware, quotaMiddleware);
291
+ * // In your own hook or component:
292
+ * useEffect(() => {
293
+ * syncDeduplicationWithQuota(queryDeduplicationMiddleware, quotaMiddleware, quotaLimits);
294
+ * }, [quotaMiddleware.getCounts().reads]);
289
295
  * ```
290
296
  */
291
- export function useDeduplicationWithQuota(
297
+ export function syncDeduplicationWithQuota(
292
298
  deduplication: QueryDeduplicationMiddleware,
293
299
  quotaMiddleware: { getCounts: () => { reads: number; writes: number; deletes: number } },
294
300
  quotaLimits: { dailyReadLimit: number }
@@ -298,3 +304,9 @@ export function useDeduplicationWithQuota(
298
304
  const quotaPercentage = counts.reads / quotaLimits.dailyReadLimit;
299
305
  deduplication.adjustWindowForQuota(quotaPercentage);
300
306
  }
307
+
308
+ /**
309
+ * @deprecated Use syncDeduplicationWithQuota instead (not a hook)
310
+ * This will be removed in a future version
311
+ */
312
+ export const useDeduplicationWithQuota = syncDeduplicationWithQuota;
@@ -173,6 +173,8 @@ export function useSmartFirestoreSnapshot<TData>(
173
173
  * Handle app state changes (foreground/background)
174
174
  */
175
175
  useEffect(() => {
176
+ const timers: ReturnType<typeof setTimeout>[] = [];
177
+
176
178
  const handleAppStateChange = (nextAppState: AppStateStatus) => {
177
179
  const isBackgrounded = nextAppState.match(/inactive|background/);
178
180
 
@@ -190,12 +192,13 @@ export function useSmartFirestoreSnapshot<TData>(
190
192
 
191
193
  switch (backgroundStrategy) {
192
194
  case 'suspend':
193
- // Suspend immediately
194
- setTimeout(() => suspendListener(), 0);
195
+ // Suspend immediately - track timer for cleanup
196
+ const suspendTimer = setTimeout(() => suspendListener(), 0);
197
+ timers.push(suspendTimer);
195
198
  break;
196
199
 
197
200
  case 'timeout':
198
- // Suspend after timeout
201
+ // Suspend after timeout - timer stored in state for cleanup
199
202
  const timer = setTimeout(() => {
200
203
  suspendListener();
201
204
  }, backgroundTimeout);
@@ -215,10 +218,11 @@ export function useSmartFirestoreSnapshot<TData>(
215
218
  console.log(`[SmartSnapshot] App entering foreground for query:`, queryKey);
216
219
  }
217
220
 
218
- // Resume listener (with optional delay)
219
- setTimeout(() => {
221
+ // Resume listener (with optional delay) - track timer for cleanup
222
+ const resumeTimer = setTimeout(() => {
220
223
  resumeListener();
221
224
  }, resumeDelay);
225
+ timers.push(resumeTimer);
222
226
 
223
227
  return { ...prev, isBackgrounded: false, suspendTimer: null };
224
228
  }
@@ -231,6 +235,8 @@ export function useSmartFirestoreSnapshot<TData>(
231
235
 
232
236
  return () => {
233
237
  subscription.remove();
238
+ // Clean up any pending timers
239
+ timers.forEach(timer => clearTimeout(timer));
234
240
  };
235
241
  }, [queryKey, backgroundStrategy, backgroundTimeout, resumeDelay, suspendListener, resumeListener]);
236
242
 
@@ -343,9 +349,13 @@ export function useSmartListenerControl() {
343
349
  return () => subscription.remove();
344
350
  }, []);
345
351
 
352
+ // Compute background status once to avoid duplicate regex matching
353
+ const isBackgrounded = appState.match(/inactive|background/);
354
+ const isForegrounded = !isBackgrounded;
355
+
346
356
  return {
347
- isBackgrounded: appState.match(/inactive|background/),
348
- isForegrounded: !appState.match(/inactive|background/),
357
+ isBackgrounded,
358
+ isForegrounded,
349
359
  appState,
350
360
  };
351
361
  }
@@ -1,44 +0,0 @@
1
- ---
2
- description: Sets up or updates the @umituz/react-native-firebase package in a React Native app.
3
- ---
4
-
5
- # Firebase Infrastructure Setup Skill
6
-
7
- When this workflow/skill is invoked, follow these explicit instructions to configure `@umituz/react-native-firebase`.
8
-
9
- ## Step 1: Check and Update `package.json`
10
- - Analyze the project's `package.json`.
11
- - Check if `@umituz/react-native-firebase` exists.
12
- - If missing: Install with `npm install @umituz/react-native-firebase`.
13
- - If outdated: Update it to the latest version.
14
-
15
- ## Step 2: Install Peer Dependencies
16
- Check and install any missing peer dependencies (use `npx expo install` for Expo packages to ensure compatibility):
17
- - `firebase`
18
- - `@gorhom/portal`
19
- - `@tanstack/react-query`
20
- - `@umituz/react-native-design-system`
21
- - `expo-apple-authentication`, `expo-auth-session`, `expo-crypto`, `expo-web-browser`
22
-
23
- ## Step 3: Check Environment Variables
24
- - Ensure that Firebase credentials (like `FIREBASE_API_KEY`, `FIREBASE_PROJECT_ID`, etc.) are defined in the project's `.env.example` and `.env` files. If they are missing, prompt the user to add them or scaffold the keys.
25
-
26
- ## Step 4: Setup Initialization Logic
27
- - Locate the main entry point (e.g. `App.tsx`, `index.js`, or a dedicated config file).
28
- - Check if Firebase is initialized.
29
- - If not, import and implement the initialization boilerplate from `@umituz/react-native-firebase`:
30
- ```typescript
31
- import { autoInitializeFirebase } from '@umituz/react-native-firebase';
32
-
33
- // Call initialization logic early in the app lifecycle
34
- ```
35
-
36
- // turbo
37
- ## Step 5: Native Setup (If bare React Native)
38
- If the project structure indicates an iOS build folder is present, run:
39
- ```bash
40
- cd ios && pod install
41
- ```
42
-
43
- ## Step 6: Summary
44
- Output what was done: the packages that were updated, the environment keys that were checked/added, and the files modified to include initialization logic.