@umituz/react-native-auth 3.4.28 → 3.4.30

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.28",
3
+ "version": "3.4.30",
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",
@@ -4,7 +4,7 @@
4
4
  */
5
5
 
6
6
  import type { DesignTokens } from "@umituz/react-native-design-system";
7
- import type { IUIProvider } from "../services/AuthPackage";
7
+ import type { IUIProvider } from "../types/UI.types";
8
8
 
9
9
  export class UIProviderAdapter implements IUIProvider {
10
10
  private theme: DesignTokens | null = null;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * UI Provider Interface
3
+ * Generic interface for theme and localization providers
4
+ */
5
+
6
+ import type { DesignTokens } from "@umituz/react-native-design-system";
7
+
8
+ export interface IUIProvider {
9
+ getTheme(): DesignTokens | null;
10
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
11
+ getLocalization(): any;
12
+ }
@@ -1,79 +0,0 @@
1
- import {
2
- AuthPackage,
3
- initializeAuthPackage,
4
- getAuthPackage,
5
- resetAuthPackage,
6
- DEFAULT_AUTH_PACKAGE_CONFIG
7
- } from '../../../src/infrastructure/services/AuthPackage';
8
- import type { IStorageProvider, IUIProvider, IValidationProvider } from '../../../src/infrastructure/services/AuthPackage';
9
-
10
- describe('AuthPackage', () => {
11
- let mockStorageProvider: jest.Mocked<IStorageProvider>;
12
- let mockUIProvider: jest.Mocked<IUIProvider>;
13
- let mockValidationProvider: jest.Mocked<IValidationProvider>;
14
-
15
- beforeEach(() => {
16
- mockStorageProvider = { get: jest.fn(), set: jest.fn(), remove: jest.fn() };
17
- mockUIProvider = { getTheme: jest.fn(), getLocalization: jest.fn() };
18
- mockValidationProvider = { validateEmail: jest.fn(), validatePassword: jest.fn() };
19
- resetAuthPackage();
20
- });
21
-
22
- describe('constructor', () => {
23
- it('should initialize with default config', () => {
24
- expect(new AuthPackage().getConfig()).toEqual(DEFAULT_AUTH_PACKAGE_CONFIG);
25
- });
26
-
27
- it('should merge custom config and deeply nested config', () => {
28
- const customConfig = { features: { anonymousMode: false }, validation: { passwordConfig: { minLength: 12 } } };
29
- const authPackage = new AuthPackage(customConfig);
30
- const config = authPackage.getConfig();
31
- expect(config.features.anonymousMode).toBe(false);
32
- expect(config.validation.passwordConfig.minLength).toBe(12);
33
- expect(config.validation.passwordConfig.requireLowercase).toBe(true);
34
- });
35
- });
36
-
37
- describe('provider management', () => {
38
- it('should set and get providers', () => {
39
- const authPackage = new AuthPackage();
40
- authPackage.setStorageProvider(mockStorageProvider);
41
- authPackage.setUIProvider(mockUIProvider);
42
- authPackage.setValidationProvider(mockValidationProvider);
43
- expect(authPackage.getStorageProvider()).toBe(mockStorageProvider);
44
- expect(authPackage.getUIProvider()).toBe(mockUIProvider);
45
- expect(authPackage.getValidationProvider()).toBe(mockValidationProvider);
46
- });
47
- });
48
-
49
- describe('feature flags', () => {
50
- it('should return feature status from config', () => {
51
- const authPackage = new AuthPackage({ features: { anonymousMode: false } });
52
- expect(authPackage.isFeatureEnabled('anonymousMode')).toBe(false);
53
- expect(authPackage.isFeatureEnabled('registration')).toBe(true);
54
- });
55
- });
56
-
57
- describe('global instance', () => {
58
- it('should manage global instances correctly', () => {
59
- const instance = initializeAuthPackage({ storageKeys: { anonymousMode: '@custom' } });
60
- expect(getAuthPackage()).toBe(instance);
61
- expect(getAuthPackage()?.getConfig().storageKeys.anonymousMode).toBe('@custom');
62
-
63
- resetAuthPackage();
64
- expect(getAuthPackage()).toBeNull();
65
- });
66
-
67
- it('should return null when not initialized', () => {
68
- resetAuthPackage();
69
- expect(getAuthPackage()).toBeNull();
70
- });
71
-
72
- it('should handle partial config', () => {
73
- const authPackage = new AuthPackage({ features: { anonymousMode: false } });
74
- const config = authPackage.getConfig();
75
- expect(config.features.anonymousMode).toBe(false);
76
- expect(config.features.registration).toBe(true);
77
- });
78
- });
79
- });
@@ -1,156 +0,0 @@
1
- /**
2
- * Auth Package Configuration
3
- * Centralized configuration for the auth package
4
- */
5
-
6
- import type { DesignTokens } from "@umituz/react-native-design-system";
7
- import type { PasswordConfig } from "../../domain/value-objects/AuthConfig";
8
-
9
- export interface AuthPackageConfig {
10
- storageKeys: {
11
- anonymousMode: string;
12
- showRegister: string;
13
- };
14
- validation: {
15
- emailRegex: RegExp;
16
- passwordConfig: PasswordConfig;
17
- };
18
- ui: {
19
- theme?: DesignTokens;
20
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
- localization?: any;
22
- };
23
- features: {
24
- anonymousMode: boolean;
25
- registration: boolean;
26
- passwordStrength: boolean;
27
- };
28
- }
29
-
30
- export const DEFAULT_AUTH_PACKAGE_CONFIG: AuthPackageConfig = {
31
- storageKeys: {
32
- anonymousMode: "@auth_anonymous_mode",
33
- showRegister: "auth_show_register",
34
- },
35
- validation: {
36
- emailRegex: /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
37
- passwordConfig: {
38
- minLength: 8,
39
- requireUppercase: true,
40
- requireLowercase: true,
41
- requireNumber: true,
42
- requireSpecialChar: false,
43
- },
44
- },
45
- ui: {
46
- theme: undefined,
47
- localization: undefined,
48
- },
49
- features: {
50
- anonymousMode: true,
51
- registration: true,
52
- passwordStrength: true,
53
- },
54
- };
55
-
56
- export interface IStorageProvider {
57
- get(key: string): Promise<string | null>;
58
- set(key: string, value: string): Promise<void>;
59
- remove(key: string): Promise<void>;
60
- }
61
-
62
- export interface IUIProvider {
63
- getTheme(): DesignTokens | null;
64
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
65
- getLocalization(): any;
66
- }
67
-
68
- export interface IValidationProvider {
69
- validateEmail(email: string): { isValid: boolean; error?: string };
70
- validatePassword(
71
- password: string,
72
- config: PasswordConfig
73
- ): { isValid: boolean; error?: string };
74
- }
75
-
76
- export class AuthPackage {
77
- private config: AuthPackageConfig;
78
- private storageProvider?: IStorageProvider;
79
- private uiProvider?: IUIProvider;
80
- private validationProvider?: IValidationProvider;
81
-
82
- constructor(config: Partial<AuthPackageConfig> = {}) {
83
- this.config = {
84
- ...DEFAULT_AUTH_PACKAGE_CONFIG,
85
- ...config,
86
- validation: {
87
- ...DEFAULT_AUTH_PACKAGE_CONFIG.validation,
88
- ...config.validation,
89
- passwordConfig: {
90
- ...DEFAULT_AUTH_PACKAGE_CONFIG.validation.passwordConfig,
91
- ...config.validation?.passwordConfig,
92
- },
93
- },
94
- ui: {
95
- ...DEFAULT_AUTH_PACKAGE_CONFIG.ui,
96
- ...config.ui,
97
- },
98
- features: {
99
- ...DEFAULT_AUTH_PACKAGE_CONFIG.features,
100
- ...config.features,
101
- },
102
- };
103
- }
104
-
105
- setStorageProvider(provider: IStorageProvider): void {
106
- this.storageProvider = provider;
107
- }
108
-
109
- setUIProvider(provider: IUIProvider): void {
110
- this.uiProvider = provider;
111
- }
112
-
113
- setValidationProvider(provider: IValidationProvider): void {
114
- this.validationProvider = provider;
115
- }
116
-
117
- getConfig(): AuthPackageConfig {
118
- return this.config;
119
- }
120
-
121
- getStorageProvider(): IStorageProvider | undefined {
122
- return this.storageProvider;
123
- }
124
-
125
- getUIProvider(): IUIProvider | undefined {
126
- return this.uiProvider;
127
- }
128
-
129
- getValidationProvider(): IValidationProvider | undefined {
130
- return this.validationProvider;
131
- }
132
-
133
- isFeatureEnabled(feature: keyof AuthPackageConfig["features"]): boolean {
134
- return this.config.features[feature];
135
- }
136
- }
137
-
138
- // Global package instance
139
- let packageInstance: AuthPackage | null = null;
140
-
141
- export function initializeAuthPackage(
142
- config: Partial<AuthPackageConfig> = {}
143
- ): AuthPackage {
144
- if (!packageInstance) {
145
- packageInstance = new AuthPackage(config);
146
- }
147
- return packageInstance;
148
- }
149
-
150
- export function getAuthPackage(): AuthPackage | null {
151
- return packageInstance;
152
- }
153
-
154
- export function resetAuthPackage(): void {
155
- packageInstance = null;
156
- }