@umituz/react-native-firebase 2.4.30 → 2.4.33
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 +1 -1
- package/src/domains/account-deletion/application/ports/reauthentication.types.ts +0 -14
- package/src/domains/account-deletion/infrastructure/services/account-deletion.service.ts +0 -2
- package/src/domains/account-deletion/infrastructure/services/reauthentication.service.ts +0 -6
- package/src/domains/auth/domain/entities/AnonymousUser.ts +0 -13
- package/src/domains/auth/domain/utils/user-validation.util.ts +0 -19
- package/src/domains/auth/infrastructure/config/FirebaseAuthClient.ts +0 -1
- package/src/domains/auth/infrastructure/services/apple-auth.types.ts +0 -19
- package/src/domains/auth/infrastructure/services/base/base-auth.service.ts +0 -49
- package/src/domains/auth/infrastructure/services/google-auth.types.ts +0 -12
- package/src/domains/auth/infrastructure/services/user-document.service.ts +0 -6
- package/src/domains/auth/infrastructure/services/utils/auth-result-converter.util.ts +3 -3
- package/src/domains/auth/infrastructure/utils/auth-guard.util.ts +2 -48
- package/src/domains/auth/presentation/hooks/useGoogleOAuth.ts +1 -1
- package/src/domains/auth/presentation/hooks/utils/auth-state-change.handler.ts +2 -2
- package/src/domains/firestore/infrastructure/middleware/QueryDeduplicationMiddleware.ts +0 -1
- package/src/domains/firestore/infrastructure/repositories/BaseRepository.ts +1 -1
- package/src/domains/firestore/utils/deduplication/pending-query-manager.util.ts +1 -1
- package/src/domains/firestore/utils/deduplication/query-key-generator.util.ts +0 -16
- package/src/domains/firestore/utils/deduplication/timer-manager.util.ts +1 -1
- package/src/domains/firestore/utils/firestore-helper.ts +0 -3
- package/src/domains/firestore/utils/query/filters.util.ts +0 -10
- package/src/domains/firestore/utils/query-builder.ts +3 -3
- package/src/domains/firestore/utils/result/result.util.ts +2 -5
- package/src/init/index.ts +0 -2
- package/src/shared/domain/guards/firebase-error.guard.ts +3 -3
- package/src/shared/domain/utils/async-executor.util.ts +1 -10
- package/src/shared/domain/utils/error-handlers/error-checkers.ts +1 -37
- package/src/shared/domain/utils/error-handlers/error-messages.ts +0 -3
- package/src/shared/domain/utils/executors/basic-executors.util.ts +1 -22
- package/src/shared/domain/utils/id-generator.util.ts +0 -37
- package/src/shared/domain/utils/index.ts +0 -90
- package/src/shared/domain/utils/result/result-creators.ts +1 -1
- package/src/shared/domain/utils/result/result-helpers.ts +1 -48
- package/src/shared/domain/utils/service-config.util.ts +2 -21
- package/src/shared/domain/utils/type-guards.util.ts +1 -55
- package/src/shared/domain/utils/validators/firebase.validator.ts +0 -11
- package/src/shared/domain/utils/validators/string.validator.ts +0 -14
- package/src/shared/infrastructure/config/base/ClientStateManager.ts +1 -1
- package/src/shared/infrastructure/config/base/ServiceClientSingleton.ts +2 -2
- package/src/shared/infrastructure/config/initializers/FirebaseAppInitializer.ts +2 -92
- package/src/domains/auth/domain/errors/FirebaseAuthError.ts +0 -18
- package/src/domains/auth/infrastructure/services/auth-guard.service.ts +0 -101
- package/src/domains/auth/presentation/hooks/shared/auth-hooks.util.ts +0 -60
- package/src/domains/auth/presentation/hooks/shared/safe-state-hooks.util.ts +0 -76
- package/src/domains/auth/presentation/hooks/shared/state-hooks.util.ts +0 -97
- package/src/shared/domain/utils/credential.util.ts +0 -102
- package/src/shared/domain/utils/executors/advanced-executors.util.ts +0 -59
- package/src/shared/domain/utils/executors/batch-executors.util.ts +0 -42
- package/src/shared/domain/utils/validators/composite.validator.ts +0 -24
- package/src/shared/domain/utils/validators/generic.validator.ts +0 -59
- package/src/shared/domain/utils/validators/url.validator.ts +0 -36
- package/src/shared/domain/utils/validators/user-input.validator.ts +0 -54
- package/src/shared/domain/utils/validators/validation.util.ts +0 -63
- package/src/shared/infrastructure/config/validators/FirebaseConfigValidator.ts +0 -89
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-firebase",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.33",
|
|
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",
|
|
@@ -5,11 +5,6 @@
|
|
|
5
5
|
|
|
6
6
|
import type { AuthCredential } from 'firebase/auth';
|
|
7
7
|
|
|
8
|
-
export interface ReauthenticationCredential {
|
|
9
|
-
provider: 'password' | 'google.com' | 'apple.com';
|
|
10
|
-
credential: AuthCredential;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
8
|
export interface ReauthenticationResult {
|
|
14
9
|
success: boolean;
|
|
15
10
|
error?: {
|
|
@@ -29,15 +24,6 @@ export interface ReauthCredentialResult {
|
|
|
29
24
|
};
|
|
30
25
|
}
|
|
31
26
|
|
|
32
|
-
export interface AccountDeletionResult {
|
|
33
|
-
success: boolean;
|
|
34
|
-
error?: {
|
|
35
|
-
code?: string;
|
|
36
|
-
message?: string;
|
|
37
|
-
requiresReauth?: boolean;
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
27
|
export interface AccountDeletionOptions {
|
|
42
28
|
reauthenticate?: boolean;
|
|
43
29
|
autoReauthenticate?: boolean;
|
|
@@ -22,8 +22,6 @@ export interface AccountDeletionResult extends Result<void> {
|
|
|
22
22
|
requiresReauth?: boolean;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
export type { AccountDeletionOptions } from "../../application/ports/reauthentication.types";
|
|
26
|
-
|
|
27
25
|
// Operation lock to prevent concurrent deletion attempts
|
|
28
26
|
let deletionInProgress = false;
|
|
29
27
|
|
|
@@ -21,12 +21,6 @@ import type {
|
|
|
21
21
|
ReauthCredentialResult
|
|
22
22
|
} from "../../application/ports/reauthentication.types";
|
|
23
23
|
|
|
24
|
-
export type {
|
|
25
|
-
ReauthenticationResult,
|
|
26
|
-
AuthProviderType,
|
|
27
|
-
ReauthCredentialResult
|
|
28
|
-
} from "../../application/ports/reauthentication.types";
|
|
29
|
-
|
|
30
24
|
/**
|
|
31
25
|
* Validates email format
|
|
32
26
|
*/
|
|
@@ -31,16 +31,3 @@ export function toAnonymousUser(user: User): AnonymousUser {
|
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
/**
|
|
35
|
-
* Validate AnonymousUser entity
|
|
36
|
-
*/
|
|
37
|
-
export function isValidAnonymousUser(user: unknown): user is AnonymousUser {
|
|
38
|
-
return (
|
|
39
|
-
typeof user === 'object' &&
|
|
40
|
-
user !== null &&
|
|
41
|
-
'uid' in user &&
|
|
42
|
-
typeof user.uid === 'string' &&
|
|
43
|
-
'isAnonymous' in user &&
|
|
44
|
-
user.isAnonymous === true
|
|
45
|
-
);
|
|
46
|
-
}
|
|
@@ -56,22 +56,3 @@ export function validateUserUnchanged(
|
|
|
56
56
|
return { valid: true };
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
/**
|
|
60
|
-
* Capture current user ID for later validation
|
|
61
|
-
* Returns null if no user is signed in
|
|
62
|
-
*
|
|
63
|
-
* @param auth - Firebase Auth instance
|
|
64
|
-
* @returns Current user ID or null
|
|
65
|
-
*
|
|
66
|
-
* @example
|
|
67
|
-
* ```typescript
|
|
68
|
-
* const auth = getFirebaseAuth();
|
|
69
|
-
* const originalUserId = captureUserId(auth);
|
|
70
|
-
* if (!originalUserId) {
|
|
71
|
-
* return failureResultFrom('auth/no-user', 'No user signed in');
|
|
72
|
-
* }
|
|
73
|
-
* ```
|
|
74
|
-
*/
|
|
75
|
-
export function captureUserId(auth: Auth | null): string | null {
|
|
76
|
-
return auth?.currentUser?.uid ?? null;
|
|
77
|
-
}
|
|
@@ -88,4 +88,3 @@ export const getFirebaseAuthInitializationError = () => firebaseAuthClient?.getI
|
|
|
88
88
|
export const resetFirebaseAuthClient = () => firebaseAuthClient?.reset();
|
|
89
89
|
|
|
90
90
|
export type { Auth } from 'firebase/auth';
|
|
91
|
-
export type { FirebaseAuthConfig } from '../../domain/value-objects/FirebaseAuthConfig';
|
|
@@ -5,13 +5,6 @@
|
|
|
5
5
|
|
|
6
6
|
import type { UserCredential } from 'firebase/auth';
|
|
7
7
|
|
|
8
|
-
export interface AppleAuthConfig {
|
|
9
|
-
clientId?: string;
|
|
10
|
-
scope?: string;
|
|
11
|
-
redirectURI?: string;
|
|
12
|
-
state?: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
8
|
export interface AppleAuthSuccessResult {
|
|
16
9
|
success: true;
|
|
17
10
|
userCredential: UserCredential;
|
|
@@ -25,15 +18,3 @@ export interface AppleAuthErrorResult {
|
|
|
25
18
|
}
|
|
26
19
|
|
|
27
20
|
export type AppleAuthResult = AppleAuthSuccessResult | AppleAuthErrorResult;
|
|
28
|
-
|
|
29
|
-
export interface AppleAuthCredential {
|
|
30
|
-
idToken: string;
|
|
31
|
-
rawNonce: string;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export type User = {
|
|
35
|
-
uid: string;
|
|
36
|
-
email?: string | null;
|
|
37
|
-
displayName?: string | null;
|
|
38
|
-
isAnonymous: boolean;
|
|
39
|
-
};
|
|
@@ -2,35 +2,8 @@
|
|
|
2
2
|
* Base Auth Service
|
|
3
3
|
*
|
|
4
4
|
* Provides common authentication service functionality
|
|
5
|
-
* Handles error processing, result formatting, and credential management
|
|
6
5
|
*/
|
|
7
6
|
|
|
8
|
-
import type { UserCredential } from 'firebase/auth';
|
|
9
|
-
import { toErrorInfo, type Result } from '../../../../../shared/domain/utils';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Authentication result with user credential
|
|
13
|
-
*/
|
|
14
|
-
export interface AuthSuccessData {
|
|
15
|
-
readonly userCredential: UserCredential;
|
|
16
|
-
readonly isNewUser: boolean;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Auth result type that extends the base Result
|
|
21
|
-
*/
|
|
22
|
-
export type AuthResult = Result<AuthSuccessData>;
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Check if user is new based on metadata
|
|
26
|
-
*/
|
|
27
|
-
export function checkIsNewUser(userCredential: UserCredential): boolean {
|
|
28
|
-
return (
|
|
29
|
-
userCredential.user.metadata.creationTime ===
|
|
30
|
-
userCredential.user.metadata.lastSignInTime
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
7
|
/**
|
|
35
8
|
* Check if error is a cancellation error
|
|
36
9
|
*/
|
|
@@ -40,25 +13,3 @@ export function isCancellationError(error: unknown): boolean {
|
|
|
40
13
|
}
|
|
41
14
|
return false;
|
|
42
15
|
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Create failure result from error
|
|
46
|
-
*/
|
|
47
|
-
export function createFailureResult(error: unknown): { success: false; error: { code: string; message: string } } {
|
|
48
|
-
const errorInfo = toErrorInfo(error, 'auth/failed');
|
|
49
|
-
return {
|
|
50
|
-
success: false,
|
|
51
|
-
error: errorInfo,
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Create success result from user credential
|
|
57
|
-
*/
|
|
58
|
-
export function createSuccessResult(userCredential: UserCredential): { success: true; userCredential: UserCredential; isNewUser: boolean } {
|
|
59
|
-
return {
|
|
60
|
-
success: true,
|
|
61
|
-
userCredential,
|
|
62
|
-
isNewUser: checkIsNewUser(userCredential),
|
|
63
|
-
};
|
|
64
|
-
}
|
|
@@ -26,15 +26,3 @@ export interface GoogleAuthErrorResult {
|
|
|
26
26
|
|
|
27
27
|
export type GoogleAuthResult = GoogleAuthSuccessResult | GoogleAuthErrorResult;
|
|
28
28
|
|
|
29
|
-
export interface GoogleAuthCredential {
|
|
30
|
-
idToken: string;
|
|
31
|
-
accessToken?: string;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export type User = {
|
|
35
|
-
uid: string;
|
|
36
|
-
email?: string | null;
|
|
37
|
-
displayName?: string | null;
|
|
38
|
-
isAnonymous: boolean;
|
|
39
|
-
photoURL?: string | null;
|
|
40
|
-
};
|
|
@@ -18,12 +18,6 @@ import {
|
|
|
18
18
|
buildUpdateData,
|
|
19
19
|
} from "./user-document-builder.util";
|
|
20
20
|
|
|
21
|
-
export type {
|
|
22
|
-
UserDocumentUser,
|
|
23
|
-
UserDocumentConfig,
|
|
24
|
-
UserDocumentExtras,
|
|
25
|
-
} from "./user-document.types";
|
|
26
|
-
|
|
27
21
|
declare const __DEV__: boolean;
|
|
28
22
|
|
|
29
23
|
let userDocumentConfig: UserDocumentConfig = {};
|
|
@@ -11,7 +11,7 @@ import type { Result } from '../../../../../shared/domain/utils/result/result-ty
|
|
|
11
11
|
* Generic OAuth authentication success result
|
|
12
12
|
* Used by Apple, Google, and other OAuth providers
|
|
13
13
|
*/
|
|
14
|
-
|
|
14
|
+
interface OAuthAuthSuccessResult {
|
|
15
15
|
success: true;
|
|
16
16
|
userCredential: any;
|
|
17
17
|
isNewUser: boolean;
|
|
@@ -20,7 +20,7 @@ export interface OAuthAuthSuccessResult {
|
|
|
20
20
|
/**
|
|
21
21
|
* Generic OAuth authentication error result
|
|
22
22
|
*/
|
|
23
|
-
|
|
23
|
+
interface OAuthAuthErrorResult {
|
|
24
24
|
success: false;
|
|
25
25
|
error: string;
|
|
26
26
|
code?: string;
|
|
@@ -29,7 +29,7 @@ export interface OAuthAuthErrorResult {
|
|
|
29
29
|
/**
|
|
30
30
|
* Generic OAuth authentication result (discriminated union)
|
|
31
31
|
*/
|
|
32
|
-
|
|
32
|
+
type OAuthAuthResult = OAuthAuthSuccessResult | OAuthAuthErrorResult;
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
35
|
* Convert standard Result to OAuth-specific result format
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Auth Guard Utilities
|
|
3
3
|
* Reusable helpers for auth initialization checks and error handling
|
|
4
|
-
* Eliminates duplicate auth guard patterns across services and hooks
|
|
5
4
|
*/
|
|
6
5
|
|
|
7
6
|
import type { Auth } from 'firebase/auth';
|
|
@@ -17,24 +16,15 @@ import { ERROR_MESSAGES } from '../../../../shared/domain/utils/error-handlers/e
|
|
|
17
16
|
/**
|
|
18
17
|
* Result of auth guard check
|
|
19
18
|
*/
|
|
20
|
-
|
|
19
|
+
type AuthGuardResult =
|
|
21
20
|
| { success: true; auth: Auth }
|
|
22
21
|
| FailureResult;
|
|
23
22
|
|
|
24
23
|
/**
|
|
25
24
|
* Guard that ensures auth is initialized before proceeding
|
|
26
25
|
* Returns auth instance or failure result
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```typescript
|
|
30
|
-
* const guardResult = requireAuth();
|
|
31
|
-
* if (!guardResult.success) {
|
|
32
|
-
* return guardResult;
|
|
33
|
-
* }
|
|
34
|
-
* const auth = guardResult.auth;
|
|
35
|
-
* ```
|
|
36
26
|
*/
|
|
37
|
-
|
|
27
|
+
function requireAuth(): AuthGuardResult {
|
|
38
28
|
const auth = getFirebaseAuth();
|
|
39
29
|
if (!auth) {
|
|
40
30
|
return failureResultFrom('auth/not-ready', ERROR_MESSAGES.AUTH.NOT_INITIALIZED);
|
|
@@ -44,20 +34,6 @@ export function requireAuth(): AuthGuardResult {
|
|
|
44
34
|
|
|
45
35
|
/**
|
|
46
36
|
* Execute auth operation with automatic auth initialization check and error handling
|
|
47
|
-
* Eliminates need for manual auth guards and try-catch blocks
|
|
48
|
-
*
|
|
49
|
-
* @param operation - Operation that requires auth instance
|
|
50
|
-
* @returns Result with operation data or error
|
|
51
|
-
*
|
|
52
|
-
* @example
|
|
53
|
-
* ```typescript
|
|
54
|
-
* export async function signInWithEmail(email: string, password: string): Promise<Result<User>> {
|
|
55
|
-
* return withAuth(async (auth) => {
|
|
56
|
-
* const userCredential = await signInWithEmailAndPassword(auth, email, password);
|
|
57
|
-
* return userCredential.user;
|
|
58
|
-
* });
|
|
59
|
-
* }
|
|
60
|
-
* ```
|
|
61
37
|
*/
|
|
62
38
|
export async function withAuth<T>(
|
|
63
39
|
operation: (auth: Auth) => Promise<T>
|
|
@@ -74,25 +50,3 @@ export async function withAuth<T>(
|
|
|
74
50
|
return failureResultFromError(error, 'auth/operation-failed');
|
|
75
51
|
}
|
|
76
52
|
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Synchronous version of withAuth for non-async operations
|
|
80
|
-
*
|
|
81
|
-
* @param operation - Synchronous operation that requires auth instance
|
|
82
|
-
* @returns Result with operation data or error
|
|
83
|
-
*/
|
|
84
|
-
export function withAuthSync<T>(
|
|
85
|
-
operation: (auth: Auth) => T
|
|
86
|
-
): Result<T> {
|
|
87
|
-
const guardResult = requireAuth();
|
|
88
|
-
if (!guardResult.success) {
|
|
89
|
-
return guardResult;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
try {
|
|
93
|
-
const data = operation(guardResult.auth);
|
|
94
|
-
return successResult(data);
|
|
95
|
-
} catch (error) {
|
|
96
|
-
return failureResultFromError(error, 'auth/operation-failed');
|
|
97
|
-
}
|
|
98
|
-
}
|
|
@@ -16,9 +16,9 @@ import { createAuthCheckResult } from '../../../infrastructure/services/auth-uti
|
|
|
16
16
|
* @param setError - State setter for errors
|
|
17
17
|
* @returns Callback function for auth state changes
|
|
18
18
|
*/
|
|
19
|
-
|
|
19
|
+
type AuthStateChangeHandler = (user: User | null) => void;
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
interface CreateAuthStateChangeHandlerParams {
|
|
22
22
|
setAuthState: (state: AuthCheckResult) => void;
|
|
23
23
|
setLoading: (loading: boolean) => void;
|
|
24
24
|
setError: (error: Error | null) => void;
|
|
@@ -14,7 +14,7 @@ import { isQuotaError as checkQuotaError } from '../../../../shared/domain/utils
|
|
|
14
14
|
import { ERROR_MESSAGES } from '../../../../shared/domain/utils/error-handlers/error-messages';
|
|
15
15
|
import { quotaTrackingMiddleware } from '../middleware/QuotaTrackingMiddleware';
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
enum RepositoryState {
|
|
18
18
|
ACTIVE = 'active',
|
|
19
19
|
DESTROYED = 'destroyed',
|
|
20
20
|
}
|
|
@@ -32,19 +32,3 @@ export function generateQueryKey(key: QueryKey): string {
|
|
|
32
32
|
return parts.join('|');
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
/**
|
|
36
|
-
* Create a query key object
|
|
37
|
-
*/
|
|
38
|
-
export function createQueryKey(
|
|
39
|
-
collection: string,
|
|
40
|
-
filters: string,
|
|
41
|
-
limit?: number,
|
|
42
|
-
orderBy?: string
|
|
43
|
-
): QueryKey {
|
|
44
|
-
return {
|
|
45
|
-
collection,
|
|
46
|
-
filters,
|
|
47
|
-
limit,
|
|
48
|
-
orderBy,
|
|
49
|
-
};
|
|
50
|
-
}
|
|
@@ -3,13 +3,10 @@
|
|
|
3
3
|
* Provides common patterns for Firestore operations with error handling
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
export type { Firestore } from "../infrastructure/config/FirestoreClient";
|
|
7
|
-
|
|
8
6
|
export {
|
|
9
7
|
createErrorResult,
|
|
10
8
|
createSuccessResult,
|
|
11
9
|
type NoDbResult,
|
|
12
|
-
NO_DB_ERROR,
|
|
13
10
|
} from "./result/result.util";
|
|
14
11
|
|
|
15
12
|
export {
|
|
@@ -63,13 +63,3 @@ export function createEqualFilter(
|
|
|
63
63
|
return { field, operator: "==", value };
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
/**
|
|
67
|
-
* Create a field filter for custom operator
|
|
68
|
-
*/
|
|
69
|
-
export function createFieldFilter(
|
|
70
|
-
field: string,
|
|
71
|
-
operator: WhereFilterOp,
|
|
72
|
-
value: string | number | boolean | string[] | number[],
|
|
73
|
-
): FieldFilter {
|
|
74
|
-
return { field, operator, value };
|
|
75
|
-
}
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
type Firestore,
|
|
9
9
|
type Query,
|
|
10
10
|
} from "firebase/firestore";
|
|
11
|
-
import { applyFieldFilter, createInFilter, createEqualFilter,
|
|
11
|
+
import { applyFieldFilter, createInFilter, createEqualFilter, type FieldFilter } from "./query/filters.util";
|
|
12
12
|
import { applyDateRange, applySort, applyCursor, applyLimit, type SortOptions, type DateRangeOptions } from "./query/modifiers.util";
|
|
13
13
|
|
|
14
14
|
export interface QueryBuilderOptions {
|
|
@@ -48,5 +48,5 @@ export function buildQuery(
|
|
|
48
48
|
return q;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
export { createInFilter, createEqualFilter
|
|
52
|
-
export type { FieldFilter
|
|
51
|
+
export { createInFilter, createEqualFilter };
|
|
52
|
+
export type { FieldFilter };
|
|
@@ -7,7 +7,7 @@ import type { Result, FailureResult } from '../../../../shared/domain/utils/resu
|
|
|
7
7
|
|
|
8
8
|
export type NoDbResult = FailureResult;
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
const NO_DB_ERROR: NoDbResult = {
|
|
11
11
|
success: false,
|
|
12
12
|
error: { message: "No DB", code: "DB_ERR" },
|
|
13
13
|
};
|
|
@@ -22,7 +22,7 @@ export function createErrorResult<T>(message: string, code: string): Result<T> {
|
|
|
22
22
|
/**
|
|
23
23
|
* Create a standard success result
|
|
24
24
|
*/
|
|
25
|
-
export function
|
|
25
|
+
export function createSuccessResult<T>(data?: T): Result<T> {
|
|
26
26
|
return { success: true, data: data as T };
|
|
27
27
|
}
|
|
28
28
|
|
|
@@ -32,6 +32,3 @@ export function createFirestoreSuccessResult<T>(data?: T): Result<T> {
|
|
|
32
32
|
export function createNoDbErrorResult<T>(): Result<T> {
|
|
33
33
|
return { success: false, error: NO_DB_ERROR.error };
|
|
34
34
|
}
|
|
35
|
-
|
|
36
|
-
// Alias for backward compatibility
|
|
37
|
-
export const createSuccessResult = createFirestoreSuccessResult;
|
package/src/init/index.ts
CHANGED
|
@@ -51,21 +51,21 @@ export function isAuthError(error: unknown): error is AuthError {
|
|
|
51
51
|
/**
|
|
52
52
|
* Check if error is a Firebase error (either Firestore or Auth)
|
|
53
53
|
*/
|
|
54
|
-
|
|
54
|
+
function isFirebaseError(error: unknown): error is FirebaseErrorBase {
|
|
55
55
|
return isFirestoreError(error) || isAuthError(error);
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
59
|
* Check if error has a specific code
|
|
60
60
|
*/
|
|
61
|
-
|
|
61
|
+
function hasErrorCode(error: unknown, code: string): boolean {
|
|
62
62
|
return hasCodeProperty(error) && error.code === code;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
/**
|
|
66
66
|
* Check if error code matches any of the provided codes
|
|
67
67
|
*/
|
|
68
|
-
|
|
68
|
+
function hasAnyErrorCode(error: unknown, codes: string[]): boolean {
|
|
69
69
|
if (!hasCodeProperty(error)) return false;
|
|
70
70
|
return codes.includes(error.code);
|
|
71
71
|
}
|
|
@@ -1,18 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Async Operation Executor Utility
|
|
3
|
-
* Re-exports
|
|
3
|
+
* Re-exports async executors
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
// Basic Executors
|
|
7
6
|
export {
|
|
8
7
|
executeOperation,
|
|
9
|
-
executeOperationWithCode,
|
|
10
|
-
executeVoidOperation,
|
|
11
8
|
executeAuthOperation,
|
|
12
9
|
} from './executors/basic-executors.util';
|
|
13
|
-
|
|
14
|
-
// Batch Executors
|
|
15
|
-
export { executeAll, executeSequence } from './executors/batch-executors.util';
|
|
16
|
-
|
|
17
|
-
// Advanced Executors
|
|
18
|
-
export { executeWithRetry, executeWithTimeout } from './executors/advanced-executors.util';
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
* Check error types and categories
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import type { ErrorInfo } from '../result/result-types';
|
|
7
6
|
import { hasCodeProperty, hasMessageProperty } from '../type-guards.util';
|
|
8
7
|
|
|
9
8
|
/**
|
|
@@ -31,51 +30,16 @@ const QUOTA_ERROR_MESSAGES = [
|
|
|
31
30
|
*/
|
|
32
31
|
const RETRYABLE_ERROR_CODES = ['unavailable', 'deadline-exceeded', 'aborted'];
|
|
33
32
|
|
|
34
|
-
/**
|
|
35
|
-
* Check if error info has a specific error code
|
|
36
|
-
*/
|
|
37
|
-
export function hasErrorCode(error: ErrorInfo, code: string): boolean {
|
|
38
|
-
return error.code === code;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
33
|
/**
|
|
42
34
|
* Check if error is a cancelled/auth cancelled error
|
|
43
35
|
*/
|
|
44
|
-
export function isCancelledError(error:
|
|
36
|
+
export function isCancelledError(error: { code: string; message: string }): boolean {
|
|
45
37
|
return (
|
|
46
38
|
error.code === 'auth/cancelled' ||
|
|
47
39
|
error.message.includes('ERR_CANCELED')
|
|
48
40
|
);
|
|
49
41
|
}
|
|
50
42
|
|
|
51
|
-
/**
|
|
52
|
-
* Check if error info is a quota error
|
|
53
|
-
*/
|
|
54
|
-
export function isQuotaErrorInfo(error: ErrorInfo): boolean {
|
|
55
|
-
return (
|
|
56
|
-
error.code === 'quota-exceeded' ||
|
|
57
|
-
error.code.includes('quota') ||
|
|
58
|
-
error.message.toLowerCase().includes('quota')
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Check if error info is a network error
|
|
64
|
-
*/
|
|
65
|
-
export function isNetworkError(error: ErrorInfo): boolean {
|
|
66
|
-
return (
|
|
67
|
-
error.code.includes('network') ||
|
|
68
|
-
error.message.toLowerCase().includes('network')
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Check if error info is an authentication error
|
|
74
|
-
*/
|
|
75
|
-
export function isAuthError(error: ErrorInfo): boolean {
|
|
76
|
-
return error.code.startsWith('auth/');
|
|
77
|
-
}
|
|
78
|
-
|
|
79
43
|
/**
|
|
80
44
|
* Check if unknown error is a Firestore quota error
|
|
81
45
|
* Enhanced type guard with proper error checking
|
|
@@ -10,7 +10,7 @@ import { toErrorInfo } from '../error-handlers/error-converters';
|
|
|
10
10
|
/**
|
|
11
11
|
* Error converter function type
|
|
12
12
|
*/
|
|
13
|
-
|
|
13
|
+
type ErrorConverter = (error: unknown) => { code: string; message: string };
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Execute async operation with error handling
|
|
@@ -29,27 +29,6 @@ export async function executeOperation<T>(
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
/**
|
|
33
|
-
* Execute async operation with error handling and default code
|
|
34
|
-
*/
|
|
35
|
-
export async function executeOperationWithCode<T>(
|
|
36
|
-
operation: () => Promise<T>,
|
|
37
|
-
defaultErrorCode = 'operation/failed'
|
|
38
|
-
): Promise<Result<T>> {
|
|
39
|
-
return executeOperation(operation, (error: unknown) => toErrorInfo(error, defaultErrorCode));
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Execute async void operation
|
|
44
|
-
* Useful for operations that don't return data
|
|
45
|
-
*/
|
|
46
|
-
export async function executeVoidOperation(
|
|
47
|
-
operation: () => Promise<void>,
|
|
48
|
-
errorConverter?: ErrorConverter
|
|
49
|
-
): Promise<Result<void>> {
|
|
50
|
-
return executeOperation(operation, errorConverter) as Promise<Result<void>>;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
32
|
/**
|
|
54
33
|
* Execute async operation with auth error handling
|
|
55
34
|
*/
|