@umituz/react-native-firebase 1.13.137 → 1.13.138

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.137",
3
+ "version": "1.13.138",
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",
@@ -8,7 +8,7 @@
8
8
 
9
9
  import type { FirestoreError } from 'firebase/firestore';
10
10
  import type { AuthError } from 'firebase/auth';
11
- import { hasCodeProperty } from '../utils/error-handler.util';
11
+ import { hasCodeProperty } from '../utils/type-guards.util';
12
12
 
13
13
  /**
14
14
  * Firebase error base interface
@@ -3,6 +3,8 @@
3
3
  * Centralized error handling utilities for Firebase operations
4
4
  */
5
5
 
6
+ import { hasCodeProperty, hasMessageProperty, hasCodeAndMessageProperties } from './type-guards.util';
7
+
6
8
  /**
7
9
  * Standard error structure with code and message
8
10
  */
@@ -36,32 +38,6 @@ const QUOTA_ERROR_MESSAGES = [
36
38
  */
37
39
  const RETRYABLE_ERROR_CODES = ['unavailable', 'deadline-exceeded', 'aborted'];
38
40
 
39
- /**
40
- * Type guard for error with code property
41
- * Uses proper type predicate instead of 'as' assertion
42
- */
43
- export function hasCodeProperty(error: unknown): error is { code: string } {
44
- return (
45
- typeof error === 'object' &&
46
- error !== null &&
47
- 'code' in error &&
48
- typeof (error as { code: unknown }).code === 'string'
49
- );
50
- }
51
-
52
- /**
53
- * Type guard for error with message property
54
- * Uses proper type predicate instead of 'as' assertion
55
- */
56
- export function hasMessageProperty(error: unknown): error is { message: string } {
57
- return (
58
- typeof error === 'object' &&
59
- error !== null &&
60
- 'message' in error &&
61
- typeof (error as { message: unknown }).message === 'string'
62
- );
63
- }
64
-
65
41
  /**
66
42
  * Convert unknown error to standard error info
67
43
  * Handles Error objects, strings, and unknown types
@@ -197,3 +173,6 @@ export function getQuotaErrorMessage(): string {
197
173
  export function getRetryableErrorMessage(): string {
198
174
  return 'Temporary error occurred. Please try again.';
199
175
  }
176
+
177
+ // Re-export type guards for convenience
178
+ export { hasCodeProperty, hasMessageProperty, hasCodeAndMessageProperties };
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Type Guard Utilities
3
+ *
4
+ * Common type guards for Firebase and JavaScript objects.
5
+ * Provides type-safe checking without using 'as' assertions.
6
+ */
7
+
8
+ /**
9
+ * Type guard for objects with a 'code' property of type string
10
+ * Commonly used for Firebase errors and other error objects
11
+ */
12
+ export function hasCodeProperty(error: unknown): error is { code: string } {
13
+ return (
14
+ typeof error === 'object' &&
15
+ error !== null &&
16
+ 'code' in error &&
17
+ typeof (error as { code: unknown }).code === 'string'
18
+ );
19
+ }
20
+
21
+ /**
22
+ * Type guard for objects with a 'message' property of type string
23
+ * Commonly used for Error objects
24
+ */
25
+ export function hasMessageProperty(error: unknown): error is { message: string } {
26
+ return (
27
+ typeof error === 'object' &&
28
+ error !== null &&
29
+ 'message' in error &&
30
+ typeof (error as { message: unknown }).message === 'string'
31
+ );
32
+ }
33
+
34
+ /**
35
+ * Type guard for objects with both 'code' and 'message' properties
36
+ * Commonly used for Firebase error objects
37
+ */
38
+ export function hasCodeAndMessageProperties(error: unknown): error is { code: string; message: string } {
39
+ return hasCodeProperty(error) && hasMessageProperty(error);
40
+ }
41
+
42
+ /**
43
+ * Type guard for objects with a 'name' property of type string
44
+ * Commonly used for Error objects
45
+ */
46
+ export function hasNameProperty(error: unknown): error is { name: string } {
47
+ return (
48
+ typeof error === 'object' &&
49
+ error !== null &&
50
+ 'name' in error &&
51
+ typeof (error as { name: unknown }).name === 'string'
52
+ );
53
+ }
54
+
55
+ /**
56
+ * Type guard for objects with a 'stack' property of type string
57
+ * Commonly used for Error objects
58
+ */
59
+ export function hasStackProperty(error: unknown): error is { stack: string } {
60
+ return (
61
+ typeof error === 'object' &&
62
+ error !== null &&
63
+ 'stack' in error &&
64
+ typeof (error as { stack: unknown }).stack === 'string'
65
+ );
66
+ }
@@ -9,7 +9,7 @@ import {
9
9
  type Transaction,
10
10
  } from "firebase/firestore";
11
11
  import { getFirestore } from "../../infrastructure/config/FirestoreClient";
12
- import type { Firestore } from "../../infrastructure/config/FirestoreClient";
12
+ import { hasCodeProperty } from "../../../domain/utils/type-guards.util";
13
13
 
14
14
  /**
15
15
  * Execute a transaction with automatic DB instance check.
@@ -23,10 +23,10 @@ export async function runTransaction<T>(
23
23
  throw new Error("[runTransaction] Firestore database is not initialized. Please ensure Firebase is properly initialized before running transactions.");
24
24
  }
25
25
  try {
26
- return await fbRunTransaction(db as Firestore, updateFunction);
26
+ return await fbRunTransaction(db, updateFunction);
27
27
  } catch (error) {
28
28
  const errorMessage = error instanceof Error ? error.message : 'Unknown error';
29
- const errorCode = error instanceof Error ? (error as { code?: string }).code : 'unknown';
29
+ const errorCode = hasCodeProperty(error) ? error.code : 'unknown';
30
30
 
31
31
  if (__DEV__) {
32
32
  console.error(`[runTransaction] Transaction failed (Code: ${errorCode}):`, errorMessage);