@umituz/react-native-auth 3.4.26 → 3.4.27

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-auth",
3
- "version": "3.4.26",
3
+ "version": "3.4.27",
4
4
  "description": "Authentication service for React Native apps - Secure, type-safe, and production-ready. Provider-agnostic design with dependency injection, configurable validation, and comprehensive error handling.",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
package/src/index.ts CHANGED
@@ -54,7 +54,7 @@ export {
54
54
  createStorageProvider,
55
55
  StorageProviderAdapter,
56
56
  } from './infrastructure/adapters/StorageProviderAdapter';
57
- export type { IStorageProvider } from './infrastructure/services/AuthPackage';
57
+ export type { IStorageProvider } from './infrastructure/types/Storage.types';
58
58
  export {
59
59
  ensureUserDocument,
60
60
  markUserDeleted,
@@ -84,6 +84,10 @@ export type {
84
84
  ValidationResult,
85
85
  PasswordStrengthResult,
86
86
  PasswordRequirements,
87
+ ValidationConfig,
88
+ } from './infrastructure/utils/AuthValidation';
89
+ export {
90
+ DEFAULT_VAL_CONFIG,
87
91
  } from './infrastructure/utils/AuthValidation';
88
92
 
89
93
  // PRESENTATION LAYER
@@ -3,7 +3,7 @@
3
3
  * Adapts external storage implementations to our IStorageProvider interface
4
4
  */
5
5
 
6
- import type { IStorageProvider } from "../services/AuthPackage";
6
+ import type { IStorageProvider } from "../types/Storage.types";
7
7
 
8
8
  /**
9
9
  * Interface that describes the shape of common storage implementations
@@ -5,8 +5,8 @@
5
5
 
6
6
  import type { IAuthProvider } from "../../application/ports/IAuthProvider";
7
7
  import type { AuthUser } from "../../domain/entities/AuthUser";
8
- import { emitAnonymousModeEnabled } from "../utils/AuthEventEmitter";
9
- import type { IStorageProvider } from "./AuthPackage";
8
+ import { emitAnonymousModeEnabled } from "./AuthEventService";
9
+ import type { IStorageProvider } from "../types/Storage.types";
10
10
 
11
11
  export class AnonymousModeService {
12
12
  private isAnonymousMode: boolean = false;
@@ -26,7 +26,7 @@ export class AnonymousModeService {
26
26
  }
27
27
  }
28
28
 
29
- async save(storageProvider: IStorageProvider): Promise<void> {
29
+ private async save(storageProvider: IStorageProvider): Promise<void> {
30
30
  try {
31
31
  await storageProvider.set(this.storageKey, this.isAnonymousMode.toString());
32
32
  } catch {
@@ -14,7 +14,7 @@ import { AuthRepository } from "../repositories/AuthRepository";
14
14
  import { AnonymousModeService } from "./AnonymousModeService";
15
15
  import { authEventService } from "./AuthEventService";
16
16
  import { authTracker } from "../utils/auth-tracker.util";
17
- import type { IStorageProvider } from "./AuthPackage";
17
+ import type { IStorageProvider } from "../types/Storage.types";
18
18
 
19
19
  export class AuthService implements IAuthService {
20
20
  private repository!: AuthRepository;
@@ -18,7 +18,7 @@ import { collectDeviceExtras } from "@umituz/react-native-design-system";
18
18
  import { initializeAuthListener } from "../../presentation/stores/initializeAuthListener";
19
19
  import type { AuthConfig } from "../../domain/value-objects/AuthConfig";
20
20
 
21
- import type { IStorageProvider } from "./AuthPackage";
21
+ import type { IStorageProvider } from "../types/Storage.types";
22
22
 
23
23
  /**
24
24
  * Unified auth initialization options
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Storage Provider Interface
3
+ * Generic storage interface for auth operations
4
+ */
5
+
6
+ export interface IStorageProvider {
7
+ get(key: string): Promise<string | null>;
8
+ set(key: string, value: string): Promise<void>;
9
+ remove(key: string): Promise<void>;
10
+ }
@@ -1,17 +1,21 @@
1
1
  import type { PasswordConfig } from "../../domain/value-objects/AuthConfig";
2
- import { getAuthPackage } from "../services/AuthPackage";
3
2
 
4
3
  export interface ValidationResult { isValid: boolean; error?: string; }
5
4
  export interface PasswordStrengthResult extends ValidationResult { requirements: PasswordRequirements; }
6
5
  export interface PasswordRequirements {
7
6
  hasMinLength: boolean; hasUppercase: boolean; hasLowercase: boolean; hasNumber: boolean; hasSpecialChar: boolean;
8
7
  }
8
+
9
9
  export interface ValidationConfig {
10
- emailRegex: RegExp; uppercaseRegex: RegExp; lowercaseRegex: RegExp;
11
- numberRegex: RegExp; specialCharRegex: RegExp; displayNameMinLength: number;
10
+ emailRegex: RegExp;
11
+ uppercaseRegex: RegExp;
12
+ lowercaseRegex: RegExp;
13
+ numberRegex: RegExp;
14
+ specialCharRegex: RegExp;
15
+ displayNameMinLength: number;
12
16
  }
13
17
 
14
- const DEFAULT_VAL_CONFIG: ValidationConfig = {
18
+ export const DEFAULT_VAL_CONFIG: ValidationConfig = {
15
19
  emailRegex: /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
16
20
  uppercaseRegex: /[A-Z]/,
17
21
  lowercaseRegex: /[a-z]/,
@@ -20,21 +24,12 @@ const DEFAULT_VAL_CONFIG: ValidationConfig = {
20
24
  displayNameMinLength: 2,
21
25
  };
22
26
 
23
- function getValConfig(): ValidationConfig {
24
- const p = getAuthPackage()?.getConfig();
25
- return {
26
- emailRegex: p?.validation.emailRegex || DEFAULT_VAL_CONFIG.emailRegex,
27
- uppercaseRegex: DEFAULT_VAL_CONFIG.uppercaseRegex,
28
- lowercaseRegex: DEFAULT_VAL_CONFIG.lowercaseRegex,
29
- numberRegex: DEFAULT_VAL_CONFIG.numberRegex,
30
- specialCharRegex: DEFAULT_VAL_CONFIG.specialCharRegex,
31
- displayNameMinLength: DEFAULT_VAL_CONFIG.displayNameMinLength,
32
- };
33
- }
34
-
35
- export function validateEmail(email: string): ValidationResult {
27
+ export function validateEmail(
28
+ email: string,
29
+ config: ValidationConfig = DEFAULT_VAL_CONFIG
30
+ ): ValidationResult {
36
31
  if (!email || email.trim() === "") return { isValid: false, error: "auth.validation.emailRequired" };
37
- if (!getValConfig().emailRegex.test(email.trim())) return { isValid: false, error: "auth.validation.invalidEmail" };
32
+ if (!config.emailRegex.test(email.trim())) return { isValid: false, error: "auth.validation.invalidEmail" };
38
33
  return { isValid: true };
39
34
  }
40
35
 
@@ -43,14 +38,17 @@ export function validatePasswordForLogin(password: string): ValidationResult {
43
38
  return { isValid: true };
44
39
  }
45
40
 
46
- export function validatePasswordForRegister(password: string, config: PasswordConfig): PasswordStrengthResult {
47
- const v = getValConfig();
41
+ export function validatePasswordForRegister(
42
+ password: string,
43
+ config: PasswordConfig,
44
+ validationConfig: ValidationConfig = DEFAULT_VAL_CONFIG
45
+ ): PasswordStrengthResult {
48
46
  const req: PasswordRequirements = {
49
47
  hasMinLength: password.length >= config.minLength,
50
- hasUppercase: !config.requireUppercase || v.uppercaseRegex.test(password),
51
- hasLowercase: !config.requireLowercase || v.lowercaseRegex.test(password),
52
- hasNumber: !config.requireNumber || v.numberRegex.test(password),
53
- hasSpecialChar: !config.requireSpecialChar || v.specialCharRegex.test(password),
48
+ hasUppercase: !config.requireUppercase || validationConfig.uppercaseRegex.test(password),
49
+ hasLowercase: !config.requireLowercase || validationConfig.lowercaseRegex.test(password),
50
+ hasNumber: !config.requireNumber || validationConfig.numberRegex.test(password),
51
+ hasSpecialChar: !config.requireSpecialChar || validationConfig.specialCharRegex.test(password),
54
52
  };
55
53
 
56
54
  if (!password) return { isValid: false, error: "auth.validation.passwordRequired", requirements: req };
@@ -69,8 +67,11 @@ export function validatePasswordConfirmation(password: string, confirm: string):
69
67
  return { isValid: true };
70
68
  }
71
69
 
72
- export function validateDisplayName(name: string, minLength?: number): ValidationResult {
70
+ export function validateDisplayName(
71
+ name: string,
72
+ minLength: number = DEFAULT_VAL_CONFIG.displayNameMinLength
73
+ ): ValidationResult {
73
74
  if (!name || name.trim() === "") return { isValid: false, error: "auth.validation.nameRequired" };
74
- if (name.trim().length < (minLength ?? getValConfig().displayNameMinLength)) return { isValid: false, error: "auth.validation.nameTooShort" };
75
+ if (name.trim().length < minLength) return { isValid: false, error: "auth.validation.nameTooShort" };
75
76
  return { isValid: true };
76
77
  }
@@ -1,53 +0,0 @@
1
- /**
2
- * Anonymous Mode Storage
3
- * Single Responsibility: Manage anonymous mode persistence
4
- */
5
-
6
- import { getAuthPackage } from "../services/AuthPackage";
7
-
8
- export async function loadAnonymousMode(storageKey?: string): Promise<boolean> {
9
- try {
10
- const packageConfig = getAuthPackage()?.getConfig();
11
- const key = storageKey ?? packageConfig?.storageKeys.anonymousMode ?? "@auth_anonymous_mode";
12
-
13
- const storageProvider = getAuthPackage()?.getStorageProvider();
14
- if (!storageProvider) return false;
15
-
16
- const value = await storageProvider.get(key);
17
- return value === "true";
18
- } catch {
19
- return false;
20
- }
21
- }
22
-
23
- export async function saveAnonymousMode(isAnonymous: boolean, storageKey?: string): Promise<void> {
24
- try {
25
- const packageConfig = getAuthPackage()?.getConfig();
26
- const key = storageKey ?? packageConfig?.storageKeys.anonymousMode ?? "@auth_anonymous_mode";
27
-
28
- const storageProvider = getAuthPackage()?.getStorageProvider();
29
- if (!storageProvider) return;
30
-
31
- if (isAnonymous) {
32
- await storageProvider.set(key, "true");
33
- } else {
34
- await storageProvider.remove(key);
35
- }
36
- } catch {
37
- // Ignore storage errors
38
- }
39
- }
40
-
41
- export async function clearAnonymousMode(storageKey?: string): Promise<void> {
42
- try {
43
- const packageConfig = getAuthPackage()?.getConfig();
44
- const key = storageKey ?? packageConfig?.storageKeys.anonymousMode ?? "@auth_anonymous_mode";
45
-
46
- const storageProvider = getAuthPackage()?.getStorageProvider();
47
- if (!storageProvider) return;
48
-
49
- await storageProvider.remove(key);
50
- } catch {
51
- // Ignore storage errors
52
- }
53
- }
@@ -1,14 +0,0 @@
1
- /**
2
- * Auth Event Emitter
3
- * Single Responsibility: Emit auth-related events
4
- */
5
-
6
- import { DeviceEventEmitter } from "react-native";
7
-
8
- export function emitUserAuthenticated(userId: string): void {
9
- DeviceEventEmitter.emit("user-authenticated", { userId });
10
- }
11
-
12
- export function emitAnonymousModeEnabled(): void {
13
- DeviceEventEmitter.emit("anonymous-mode-enabled");
14
- }