@umituz/react-native-design-system 2.6.107 → 2.6.111

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.
Files changed (35) hide show
  1. package/package.json +2 -2
  2. package/src/exception/domain/entities/ExceptionEntity.ts +115 -0
  3. package/src/exception/domain/repositories/IExceptionRepository.ts +37 -0
  4. package/src/exception/index.ts +65 -0
  5. package/src/exception/infrastructure/services/ExceptionHandler.ts +93 -0
  6. package/src/exception/infrastructure/services/ExceptionLogger.ts +142 -0
  7. package/src/exception/infrastructure/services/ExceptionReporter.ts +134 -0
  8. package/src/exception/infrastructure/services/ExceptionService.ts +154 -0
  9. package/src/exception/infrastructure/storage/ExceptionStore.ts +44 -0
  10. package/src/exception/presentation/components/ErrorBoundary.tsx +129 -0
  11. package/src/exception/presentation/components/ExceptionEmptyState.tsx +123 -0
  12. package/src/exception/presentation/components/ExceptionErrorState.tsx +118 -0
  13. package/src/exports/exception.ts +7 -0
  14. package/src/exports/infinite-scroll.ts +7 -0
  15. package/src/exports/uuid.ts +7 -0
  16. package/src/index.ts +15 -0
  17. package/src/infinite-scroll/domain/interfaces/infinite-scroll-list-props.ts +67 -0
  18. package/src/infinite-scroll/domain/types/infinite-scroll-config.ts +108 -0
  19. package/src/infinite-scroll/domain/types/infinite-scroll-return.ts +40 -0
  20. package/src/infinite-scroll/domain/types/infinite-scroll-state.ts +58 -0
  21. package/src/infinite-scroll/domain/utils/pagination-utils.ts +63 -0
  22. package/src/infinite-scroll/domain/utils/type-guards.ts +53 -0
  23. package/src/infinite-scroll/index.ts +62 -0
  24. package/src/infinite-scroll/presentation/components/empty.tsx +44 -0
  25. package/src/infinite-scroll/presentation/components/error.tsx +66 -0
  26. package/src/infinite-scroll/presentation/components/infinite-scroll-list.tsx +120 -0
  27. package/src/infinite-scroll/presentation/components/loading-more.tsx +38 -0
  28. package/src/infinite-scroll/presentation/components/loading.tsx +40 -0
  29. package/src/infinite-scroll/presentation/components/types.ts +124 -0
  30. package/src/infinite-scroll/presentation/hooks/pagination.helper.ts +83 -0
  31. package/src/infinite-scroll/presentation/hooks/useInfiniteScroll.ts +327 -0
  32. package/src/uuid/index.ts +15 -0
  33. package/src/uuid/infrastructure/utils/UUIDUtils.ts +75 -0
  34. package/src/uuid/package-lock.json +14255 -0
  35. package/src/uuid/types/UUID.ts +36 -0
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@umituz/react-native-design-system",
3
- "version": "2.6.107",
4
- "description": "Universal design system for React Native apps - Consolidated package with atoms, molecules, organisms, theme, typography, responsive and safe area utilities",
3
+ "version": "2.6.111",
4
+ "description": "Universal design system for React Native apps - Consolidated package with atoms, molecules, organisms, theme, typography, responsive, safe area, exception, infinite scroll and UUID utilities",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
7
7
  "exports": {
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Exception Entity - Domain Layer
3
+ * Pure business logic representation of errors and exceptions
4
+ */
5
+
6
+ import { generateUUID } from '@umituz/react-native-uuid';
7
+
8
+ export type ExceptionSeverity = 'fatal' | 'error' | 'warning' | 'info';
9
+ export type ExceptionCategory = 'network' | 'validation' | 'authentication' | 'authorization' | 'business-logic' | 'system' | 'storage' | 'unknown';
10
+
11
+ export interface ExceptionContext {
12
+ userId?: string;
13
+ screen?: string;
14
+ action?: string;
15
+ componentStack?: string;
16
+ metadata?: Record<string, unknown>;
17
+ }
18
+
19
+ export interface ExceptionEntity {
20
+ id: string;
21
+ message: string;
22
+ stackTrace?: string;
23
+ severity: ExceptionSeverity;
24
+ category: ExceptionCategory;
25
+ context: ExceptionContext;
26
+ timestamp: Date;
27
+ handled: boolean;
28
+ reported: boolean;
29
+ }
30
+
31
+ export interface ErrorLog {
32
+ id: string;
33
+ exceptionId: string;
34
+ userId?: string;
35
+ message: string;
36
+ stackTrace?: string;
37
+ severity: ExceptionSeverity;
38
+ category: ExceptionCategory;
39
+ context: ExceptionContext;
40
+ createdAt: Date;
41
+ }
42
+
43
+ /**
44
+ * Factory function to create an exception entity
45
+ */
46
+ export function createException(
47
+ error: Error,
48
+ severity: ExceptionSeverity = 'error',
49
+ category: ExceptionCategory = 'unknown',
50
+ context: ExceptionContext = {}
51
+ ): ExceptionEntity {
52
+ return {
53
+ id: generateUUID(),
54
+ message: error.message,
55
+ stackTrace: error.stack,
56
+ severity,
57
+ category,
58
+ context,
59
+ timestamp: new Date(),
60
+ handled: false,
61
+ reported: false,
62
+ };
63
+ }
64
+
65
+ /**
66
+ * Factory function to create an error log
67
+ */
68
+ export function createErrorLog(
69
+ exception: ExceptionEntity
70
+ ): ErrorLog {
71
+ return {
72
+ id: generateUUID(),
73
+ exceptionId: exception.id,
74
+ userId: exception.context.userId,
75
+ message: exception.message,
76
+ stackTrace: exception.stackTrace,
77
+ severity: exception.severity,
78
+ category: exception.category,
79
+ context: exception.context,
80
+ createdAt: new Date(),
81
+ };
82
+ }
83
+
84
+ /**
85
+ * Determine if exception should be reported
86
+ */
87
+ export function shouldReportException(exception: ExceptionEntity): boolean {
88
+ // Don't report warnings or info
89
+ if (exception.severity === 'warning' || exception.severity === 'info') {
90
+ return false;
91
+ }
92
+
93
+ // Don't report validation errors (user errors)
94
+ if (exception.category === 'validation') {
95
+ return false;
96
+ }
97
+
98
+ // Report everything else
99
+ return true;
100
+ }
101
+
102
+
103
+
104
+
105
+
106
+
107
+
108
+
109
+
110
+
111
+
112
+
113
+
114
+
115
+
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Exception Repository Interface
3
+ * Defines the contract for exception data persistence
4
+ */
5
+
6
+ import type { ExceptionEntity, ErrorLog } from '../entities/ExceptionEntity';
7
+
8
+ export interface ExceptionRepositoryError {
9
+ code: string;
10
+ message: string;
11
+ }
12
+
13
+ export type ExceptionResult<T> =
14
+ | { success: true; data: T }
15
+ | { success: false; error: ExceptionRepositoryError };
16
+
17
+ export interface IExceptionRepository {
18
+ /**
19
+ * Save an exception to storage
20
+ */
21
+ save(exception: ExceptionEntity): Promise<ExceptionResult<void>>;
22
+
23
+ /**
24
+ * Get all stored exceptions
25
+ */
26
+ getAll(): Promise<ExceptionResult<ExceptionEntity[]>>;
27
+
28
+ /**
29
+ * Clear all stored exceptions
30
+ */
31
+ clear(): Promise<ExceptionResult<void>>;
32
+
33
+ /**
34
+ * Log an error
35
+ */
36
+ log(errorLog: ErrorLog): Promise<ExceptionResult<void>>;
37
+ }
@@ -0,0 +1,65 @@
1
+ /**
2
+ * @umituz/react-native-exception - Public API
3
+ *
4
+ * Exception handling and error tracking for React Native apps
5
+ *
6
+ * Usage:
7
+ * import { ErrorBoundary, exceptionService, useExceptionStore } from '@umituz/react-native-exception';
8
+ */
9
+
10
+ // =============================================================================
11
+ // DOMAIN LAYER EXPORTS
12
+ // =============================================================================
13
+
14
+ // Entities
15
+ export type {
16
+ ExceptionEntity,
17
+ ErrorLog,
18
+ ExceptionContext,
19
+ ExceptionSeverity,
20
+ ExceptionCategory,
21
+ } from './domain/entities/ExceptionEntity';
22
+ export {
23
+ createException,
24
+ createErrorLog,
25
+ shouldReportException,
26
+ } from './domain/entities/ExceptionEntity';
27
+
28
+ // Repositories
29
+ export type {
30
+ IExceptionRepository,
31
+ ExceptionRepositoryError,
32
+ ExceptionResult,
33
+ } from './domain/repositories/IExceptionRepository';
34
+
35
+ // =============================================================================
36
+ // INFRASTRUCTURE LAYER EXPORTS
37
+ // =============================================================================
38
+
39
+ // State Store (Zustand)
40
+ export { useExceptionStore, useExceptions } from './infrastructure/storage/ExceptionStore';
41
+
42
+ // Services
43
+ // Infrastructure Services
44
+ export { ExceptionService } from './infrastructure/services/ExceptionService';
45
+ export { ExceptionHandler } from './infrastructure/services/ExceptionHandler';
46
+ export { ExceptionReporter } from './infrastructure/services/ExceptionReporter';
47
+ export { ExceptionLogger } from './infrastructure/services/ExceptionLogger';
48
+
49
+ // =============================================================================
50
+ // PRESENTATION LAYER EXPORTS
51
+ // =============================================================================
52
+
53
+ // Components
54
+ export { ErrorBoundary } from './presentation/components/ErrorBoundary';
55
+ export { ExceptionEmptyState } from './presentation/components/ExceptionEmptyState';
56
+ export type { ExceptionEmptyStateProps } from './presentation/components/ExceptionEmptyState';
57
+ export { ExceptionErrorState } from './presentation/components/ExceptionErrorState';
58
+ export type { ExceptionErrorStateProps } from './presentation/components/ExceptionErrorState';
59
+
60
+
61
+
62
+
63
+
64
+
65
+
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Exception Handler Service
3
+ *
4
+ * Handles exception creation, validation, and basic processing.
5
+ *
6
+ * SOLID: Single Responsibility - Only exception handling
7
+ * DRY: Centralized exception processing logic
8
+ * KISS: Simple exception handling interface
9
+ */
10
+
11
+ import type {
12
+ ExceptionEntity,
13
+ ExceptionContext,
14
+ ExceptionSeverity,
15
+ ExceptionCategory,
16
+ } from '../../domain/entities/ExceptionEntity';
17
+ import {
18
+ createException,
19
+ shouldReportException,
20
+ } from '../../domain/entities/ExceptionEntity';
21
+
22
+ export class ExceptionHandler {
23
+ /**
24
+ * Create and validate an exception
25
+ */
26
+ static createException(
27
+ error: Error,
28
+ severity: ExceptionSeverity = 'error',
29
+ category: ExceptionCategory = 'unknown',
30
+ context: ExceptionContext = {},
31
+ ): ExceptionEntity {
32
+ return createException(error, severity, category, context);
33
+ }
34
+
35
+ /**
36
+ * Check if exception should be reported
37
+ */
38
+ static shouldReportException(exception: ExceptionEntity): boolean {
39
+ return shouldReportException(exception);
40
+ }
41
+
42
+ /**
43
+ * Validate exception data
44
+ */
45
+ static validateException(exception: ExceptionEntity): boolean {
46
+ return !!(
47
+ exception.id &&
48
+ exception.message &&
49
+ exception.timestamp &&
50
+ exception.severity &&
51
+ exception.category
52
+ );
53
+ }
54
+
55
+ /**
56
+ * Sanitize exception for logging
57
+ */
58
+ static sanitizeException(exception: ExceptionEntity): ExceptionEntity {
59
+ return {
60
+ ...exception,
61
+ message: this.sanitizeMessage(exception.message),
62
+ context: this.sanitizeContext(exception.context),
63
+ };
64
+ }
65
+
66
+ /**
67
+ * Sanitize error message
68
+ */
69
+ private static sanitizeMessage(message: string): string {
70
+ // Remove sensitive information from error messages
71
+ return message
72
+ .replace(/password=[^&\s]*/gi, 'password=***')
73
+ .replace(/token=[^&\s]*/gi, 'token=***')
74
+ .replace(/key=[^&\s]*/gi, 'key=***');
75
+ }
76
+
77
+ /**
78
+ * Sanitize context object
79
+ */
80
+ private static sanitizeContext(context: ExceptionContext): ExceptionContext {
81
+ const sanitized: ExceptionContext = { ...context };
82
+
83
+ // Remove sensitive fields
84
+ const sensitiveFields = ['password', 'token', 'apiKey', 'secret'];
85
+ sensitiveFields.forEach(field => {
86
+ if (sanitized.metadata && sanitized.metadata[field]) {
87
+ sanitized.metadata = { ...sanitized.metadata, [field]: '***' };
88
+ }
89
+ });
90
+
91
+ return sanitized;
92
+ }
93
+ }
@@ -0,0 +1,142 @@
1
+ /**
2
+ * Exception Logger Service
3
+ *
4
+ * Handles local logging and persistence of exceptions.
5
+ *
6
+ * SOLID: Single Responsibility - Only exception logging/persistence
7
+ * DRY: Centralized logging logic
8
+ * KISS: Simple logging interface
9
+ */
10
+
11
+ import type { ExceptionEntity } from '../../domain/entities/ExceptionEntity';
12
+ import { ExceptionHandler } from './ExceptionHandler';
13
+ import { storageRepository } from '@umituz/react-native-storage';
14
+
15
+ export class ExceptionLogger {
16
+ private static readonly STORAGE_KEY = '@exceptions';
17
+ private maxStoredExceptions = 100;
18
+
19
+ /**
20
+ * Log exception locally
21
+ */
22
+ async logException(exception: ExceptionEntity): Promise<void> {
23
+ try {
24
+ const sanitizedException = ExceptionHandler.sanitizeException(exception);
25
+ const existingExceptions = await this.getStoredExceptions();
26
+
27
+ // Add new exception
28
+ existingExceptions.unshift(sanitizedException);
29
+
30
+ // Limit storage size
31
+ if (existingExceptions.length > this.maxStoredExceptions) {
32
+ existingExceptions.splice(this.maxStoredExceptions);
33
+ }
34
+
35
+ await storageRepository.setString(ExceptionLogger.STORAGE_KEY, JSON.stringify(existingExceptions));
36
+ } catch (error) {
37
+ // Fallback to console if storage fails
38
+ console.error('Failed to log exception:', error);
39
+ }
40
+ }
41
+
42
+ /**
43
+ * Get stored exceptions
44
+ */
45
+ async getStoredExceptions(): Promise<ExceptionEntity[]> {
46
+ try {
47
+ const result = await storageRepository.getString(ExceptionLogger.STORAGE_KEY, '[]');
48
+ if (result.success) {
49
+ return JSON.parse(result.data);
50
+ }
51
+ return [];
52
+ } catch (error) {
53
+ console.warn('Failed to get stored exceptions:', error);
54
+ return [];
55
+ }
56
+ }
57
+
58
+ /**
59
+ * Clear all stored exceptions
60
+ */
61
+ async clearStoredExceptions(): Promise<void> {
62
+ try {
63
+ await storageRepository.setString(ExceptionLogger.STORAGE_KEY, '[]');
64
+ } catch (error) {
65
+ console.warn('Failed to clear stored exceptions:', error);
66
+ }
67
+ }
68
+
69
+ /**
70
+ * Get exceptions by category
71
+ */
72
+ async getExceptionsByCategory(category: ExceptionEntity['category']): Promise<ExceptionEntity[]> {
73
+ const exceptions = await this.getStoredExceptions();
74
+ return exceptions.filter(ex => ex.category === category);
75
+ }
76
+
77
+ /**
78
+ * Get exceptions by severity
79
+ */
80
+ async getExceptionsBySeverity(severity: ExceptionEntity['severity']): Promise<ExceptionEntity[]> {
81
+ const exceptions = await this.getStoredExceptions();
82
+ return exceptions.filter(ex => ex.severity === severity);
83
+ }
84
+
85
+ /**
86
+ * Get recent exceptions (last N days)
87
+ */
88
+ async getRecentExceptions(days: number = 7): Promise<ExceptionEntity[]> {
89
+ const exceptions = await this.getStoredExceptions();
90
+ const cutoffDate = new Date();
91
+ cutoffDate.setDate(cutoffDate.getDate() - days);
92
+
93
+ return exceptions.filter(ex => new Date(ex.timestamp) >= cutoffDate);
94
+ }
95
+
96
+ /**
97
+ * Get exception statistics
98
+ */
99
+ async getExceptionStats(): Promise<{
100
+ total: number;
101
+ bySeverity: Record<ExceptionEntity['severity'], number>;
102
+ byCategory: Record<ExceptionEntity['category'], number>;
103
+ }> {
104
+ const exceptions = await this.getStoredExceptions();
105
+
106
+ const bySeverity: Record<ExceptionEntity['severity'], number> = {
107
+ fatal: 0,
108
+ error: 0,
109
+ warning: 0,
110
+ info: 0,
111
+ };
112
+
113
+ const byCategory: Record<ExceptionEntity['category'], number> = {
114
+ network: 0,
115
+ validation: 0,
116
+ authentication: 0,
117
+ authorization: 0,
118
+ 'business-logic': 0,
119
+ system: 0,
120
+ storage: 0,
121
+ unknown: 0,
122
+ };
123
+
124
+ exceptions.forEach(ex => {
125
+ bySeverity[ex.severity]++;
126
+ byCategory[ex.category]++;
127
+ });
128
+
129
+ return {
130
+ total: exceptions.length,
131
+ bySeverity,
132
+ byCategory,
133
+ };
134
+ }
135
+
136
+ /**
137
+ * Update max stored exceptions limit
138
+ */
139
+ setMaxStoredExceptions(limit: number): void {
140
+ this.maxStoredExceptions = Math.max(1, limit);
141
+ }
142
+ }
@@ -0,0 +1,134 @@
1
+ /**
2
+ * Exception Reporter Service
3
+ *
4
+ * Handles reporting exceptions to external services.
5
+ *
6
+ * SOLID: Single Responsibility - Only exception reporting
7
+ * DRY: Centralized reporting logic
8
+ * KISS: Simple reporting interface
9
+ */
10
+
11
+ import type { ExceptionEntity } from '../../domain/entities/ExceptionEntity';
12
+
13
+ export interface ExceptionReporterConfig {
14
+ enabled: boolean;
15
+ endpoint?: string;
16
+ apiKey?: string;
17
+ environment: 'development' | 'staging' | 'production';
18
+ }
19
+
20
+ export class ExceptionReporter {
21
+ private config: ExceptionReporterConfig;
22
+
23
+ constructor(config: ExceptionReporterConfig) {
24
+ this.config = config;
25
+ }
26
+
27
+ /**
28
+ * Report exception to external service
29
+ */
30
+ async reportException(exception: ExceptionEntity): Promise<boolean> {
31
+ if (!this.config.enabled) {
32
+ return false;
33
+ }
34
+
35
+ try {
36
+ // Default console reporting for development
37
+ if (this.config.environment === 'development') {
38
+ return this.reportToConsole(exception);
39
+ }
40
+
41
+ // External service reporting
42
+ if (this.config.endpoint) {
43
+ return await this.reportToExternalService(exception);
44
+ }
45
+
46
+ return false;
47
+ } catch (error) {
48
+ // Don't throw in reporter to avoid infinite loops
49
+ console.warn('Exception reporting failed:', error);
50
+ return false;
51
+ }
52
+ }
53
+
54
+ /**
55
+ * Report to console (development)
56
+ */
57
+ private reportToConsole(exception: ExceptionEntity): boolean {
58
+ const level = this.getConsoleLevel(exception.severity);
59
+
60
+ console[level](
61
+ `[${exception.severity.toUpperCase()}] ${exception.category}:`,
62
+ exception.message,
63
+ {
64
+ id: exception.id,
65
+ timestamp: exception.timestamp,
66
+ context: exception.context,
67
+ stack: exception.stackTrace,
68
+ }
69
+ );
70
+
71
+ return true;
72
+ }
73
+
74
+ /**
75
+ * Report to external service
76
+ */
77
+ private async reportToExternalService(exception: ExceptionEntity): Promise<boolean> {
78
+ if (!this.config.endpoint) {
79
+ return false;
80
+ }
81
+
82
+ const response = await fetch(this.config.endpoint, {
83
+ method: 'POST',
84
+ headers: {
85
+ 'Content-Type': 'application/json',
86
+ ...(this.config.apiKey && { 'Authorization': `Bearer ${this.config.apiKey}` }),
87
+ },
88
+ body: JSON.stringify({
89
+ id: exception.id,
90
+ message: exception.message,
91
+ severity: exception.severity,
92
+ category: exception.category,
93
+ timestamp: exception.timestamp,
94
+ context: exception.context,
95
+ stackTrace: exception.stackTrace,
96
+ environment: this.config.environment,
97
+ }),
98
+ });
99
+
100
+ return response.ok;
101
+ }
102
+
103
+ /**
104
+ * Get console level for severity
105
+ */
106
+ private getConsoleLevel(severity: ExceptionEntity['severity']): 'log' | 'warn' | 'error' {
107
+ switch (severity) {
108
+ case 'fatal':
109
+ case 'error':
110
+ return 'error';
111
+ case 'warning':
112
+ return 'warn';
113
+ default:
114
+ return 'log';
115
+ }
116
+ }
117
+
118
+ /**
119
+ * Update reporter configuration
120
+ */
121
+ updateConfig(config: Partial<ExceptionReporterConfig>): void {
122
+ this.config = { ...this.config, ...config };
123
+ }
124
+ }
125
+
126
+
127
+
128
+
129
+
130
+
131
+
132
+
133
+
134
+