@umituz/react-native-exception 1.2.6 → 1.2.8

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-exception",
3
- "version": "1.2.6",
3
+ "version": "1.2.8",
4
4
  "description": "Exception handling and error tracking for React Native apps",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -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,37 @@
1
+ /**
2
+ * Exception Store
3
+ * Zustand store for exception state management
4
+ */
5
+
6
+ import { create } from 'zustand';
7
+ import type { ExceptionEntity } from '../../domain/entities/ExceptionEntity';
8
+
9
+ interface ExceptionState {
10
+ exceptions: ExceptionEntity[];
11
+ addException: (exception: ExceptionEntity) => void;
12
+ clearExceptions: () => void;
13
+ markAsHandled: (id: string) => void;
14
+ }
15
+
16
+ export const useExceptionStore = create<ExceptionState>((set) => ({
17
+ exceptions: [],
18
+ addException: (exception: ExceptionEntity) =>
19
+ set((state: ExceptionState) => ({
20
+ exceptions: [...state.exceptions, exception],
21
+ })),
22
+ clearExceptions: () => set({ exceptions: [] }),
23
+ markAsHandled: (id: string) =>
24
+ set((state: ExceptionState) => ({
25
+ exceptions: state.exceptions.map((e) =>
26
+ e.id === id ? { ...e, isHandled: true } : e
27
+ ),
28
+ })),
29
+ }));
30
+
31
+ /**
32
+ * Hook to get exceptions from store
33
+ */
34
+ export const useExceptions = () => {
35
+ const exceptions = useExceptionStore((state: ExceptionState) => state.exceptions);
36
+ return exceptions;
37
+ };