@umituz/react-native-firebase 2.4.14 → 2.4.16
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/infrastructure/services/account-deletion.service.ts +29 -21
- package/src/domains/account-deletion/infrastructure/services/reauthentication.service.ts +2 -2
- package/src/domains/auth/domain/utils/user-metadata.util.ts +72 -0
- package/src/domains/auth/domain/utils/user-validation.util.ts +77 -0
- package/src/domains/auth/infrastructure/services/apple-auth.service.ts +6 -27
- package/src/domains/auth/infrastructure/services/auth-guard.service.ts +39 -33
- package/src/domains/auth/infrastructure/services/base/base-auth.service.ts +2 -2
- package/src/domains/auth/infrastructure/services/email-auth.service.ts +18 -38
- package/src/domains/auth/infrastructure/services/google-auth.service.ts +6 -27
- package/src/domains/auth/infrastructure/services/utils/auth-result-converter.util.ts +71 -0
- package/src/domains/auth/infrastructure/utils/auth-guard.util.ts +98 -0
- package/src/domains/firestore/index.ts +1 -1
- package/src/domains/firestore/infrastructure/config/FirestoreClient.ts +3 -16
- package/src/domains/firestore/infrastructure/repositories/BaseRepository.ts +1 -4
- package/src/domains/firestore/utils/firestore-helper.ts +0 -3
- package/src/domains/firestore/utils/operation/operation-executor.util.ts +3 -3
- package/src/domains/firestore/utils/result/result.util.ts +7 -25
- package/src/index.ts +1 -1
- package/src/shared/domain/utils/async-executor.util.ts +1 -6
- package/src/shared/domain/utils/error-handler.util.ts +4 -2
- package/src/shared/domain/utils/error-handlers/error-checkers.ts +1 -1
- package/src/shared/domain/utils/error-handlers/error-converters.ts +6 -28
- package/src/shared/domain/utils/executors/basic-executors.util.ts +10 -6
- package/src/shared/domain/utils/index.ts +0 -4
- package/src/shared/domain/utils/result/result-creators.ts +3 -16
- package/src/shared/domain/utils/type-guards.util.ts +33 -8
- package/src/shared/domain/utils/validators/firebase.validator.ts +4 -5
- package/src/shared/domain/utils/validators/url.validator.ts +2 -2
- package/src/shared/domain/utils/validators/user-input.validator.ts +1 -1
- package/src/shared/domain/utils/validators/validation.util.ts +63 -0
- package/src/shared/domain/utils/executors/error-converters.util.ts +0 -45
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic Validation Utilities
|
|
3
|
+
* Provides reusable validation patterns to eliminate duplication
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Generic validation utility that throws error if validation fails
|
|
8
|
+
* Eliminates duplicate validate-or-throw patterns across the codebase
|
|
9
|
+
*
|
|
10
|
+
* @param value - Value to validate
|
|
11
|
+
* @param validator - Validation function that returns true if valid
|
|
12
|
+
* @param errorMessage - Error message to throw if validation fails
|
|
13
|
+
* @param ErrorClass - Error class to instantiate (defaults to Error)
|
|
14
|
+
* @throws {ErrorClass} When validation fails
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* validateOrThrow(
|
|
19
|
+
* cursor,
|
|
20
|
+
* isValidCursor,
|
|
21
|
+
* ERROR_MESSAGES.FIRESTORE.INVALID_CURSOR,
|
|
22
|
+
* CursorValidationError
|
|
23
|
+
* );
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export function validateOrThrow<T>(
|
|
27
|
+
value: T,
|
|
28
|
+
validator: (value: T) => boolean,
|
|
29
|
+
errorMessage: string,
|
|
30
|
+
ErrorClass: new (message: string) => Error = Error
|
|
31
|
+
): void {
|
|
32
|
+
if (!validator(value)) {
|
|
33
|
+
throw new ErrorClass(errorMessage);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Validate multiple values, throw on first failure
|
|
39
|
+
* Useful for validating multiple preconditions before an operation
|
|
40
|
+
*
|
|
41
|
+
* @param validations - Array of validation configurations
|
|
42
|
+
* @throws {Error} When any validation fails
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* validateAllOrThrow([
|
|
47
|
+
* { value: email, validator: isValidEmail, errorMessage: 'Invalid email' },
|
|
48
|
+
* { value: password, validator: isValidPassword, errorMessage: 'Invalid password' },
|
|
49
|
+
* ]);
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export function validateAllOrThrow<T = unknown>(
|
|
53
|
+
validations: Array<{
|
|
54
|
+
value: T;
|
|
55
|
+
validator: (value: T) => boolean;
|
|
56
|
+
errorMessage: string;
|
|
57
|
+
ErrorClass?: new (message: string) => Error;
|
|
58
|
+
}>
|
|
59
|
+
): void {
|
|
60
|
+
for (const { value, validator, errorMessage, ErrorClass = Error } of validations) {
|
|
61
|
+
validateOrThrow(value, validator, errorMessage, ErrorClass);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Error Converters
|
|
3
|
-
* Convert unknown errors to structured ErrorInfo
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Error converter function type
|
|
8
|
-
* Converts unknown errors to ErrorInfo
|
|
9
|
-
*/
|
|
10
|
-
export type ErrorConverter = (error: unknown) => { code: string; message: string };
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Default error converter for auth operations
|
|
14
|
-
*/
|
|
15
|
-
export function authErrorConverter(error: unknown): { code: string; message: string } {
|
|
16
|
-
if (error instanceof Error) {
|
|
17
|
-
return {
|
|
18
|
-
code: (error as { code?: string }).code ?? 'auth/failed',
|
|
19
|
-
message: error.message,
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
return {
|
|
23
|
-
code: 'auth/failed',
|
|
24
|
-
message: typeof error === 'string' ? error : 'Authentication failed',
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Default error converter for operations
|
|
30
|
-
*/
|
|
31
|
-
export function defaultErrorConverter(
|
|
32
|
-
error: unknown,
|
|
33
|
-
defaultCode = 'operation/failed'
|
|
34
|
-
): { code: string; message: string } {
|
|
35
|
-
if (error instanceof Error) {
|
|
36
|
-
return {
|
|
37
|
-
code: (error as { code?: string }).code ?? defaultCode,
|
|
38
|
-
message: error.message,
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
return {
|
|
42
|
-
code: defaultCode,
|
|
43
|
-
message: typeof error === 'string' ? error : 'Operation failed',
|
|
44
|
-
};
|
|
45
|
-
}
|