@plyaz/types 1.12.3 → 1.12.4

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.
@@ -1 +1 @@
1
- export {};
1
+ export type * from "./types";
@@ -0,0 +1,83 @@
1
+ import type { StateCreator } from 'zustand';
2
+ import type { BaseErrorContext } from '../api';
3
+ /**
4
+ * Represents the error state and actions available for managing global errors.
5
+ *
6
+ * @typedef {Object} ErrorSliceType
7
+ * @property {ReturnResponseType | null} error - The current error state, or `null` if no error exists.
8
+ * @property {(error: ReturnResponseType) => void} addError - Adds or updates the global error state.
9
+ * @property {() => void} clearError - Clears the current error from the store.
10
+ */
11
+ type ErrorSeverity = 'critical' | 'error' | 'warning' | 'info';
12
+ interface BaseError {
13
+ statusCode: number;
14
+ message: string;
15
+ timestamp: string;
16
+ type: string;
17
+ context?: BaseErrorContext;
18
+ }
19
+ export interface ErrorLogEntry {
20
+ id: string;
21
+ error: BaseError;
22
+ timestamp: string;
23
+ severity?: ErrorSeverity;
24
+ source?: string;
25
+ correlationId?: string;
26
+ dismissed?: boolean;
27
+ context?: Record<string, object>;
28
+ }
29
+ export interface ErrorOptions {
30
+ source?: string;
31
+ context?: Record<string, object>;
32
+ severity?: ErrorSeverity;
33
+ correlationId?: string;
34
+ }
35
+ export interface ErrorSliceType {
36
+ errors: ErrorLogEntry[];
37
+ maxErrors: number;
38
+ addError: (error: BaseError, options?: ErrorOptions) => void;
39
+ addErrors: (errors: BaseError[], options?: ErrorOptions) => void;
40
+ clearError: (errorId: string) => void;
41
+ clearErrors: (errorIds: string[]) => void;
42
+ clearErrorsByType: (type: string) => void;
43
+ clearErrorsBySeverity: (severity: ErrorSeverity) => void;
44
+ clearAll: () => void;
45
+ dismissError: (errorId: string) => void;
46
+ dismissErrors: (errorIds: string[]) => void;
47
+ dismissAll: () => void;
48
+ getLatestError: () => ErrorLogEntry | null;
49
+ getErrorsByType: (type: string) => ErrorLogEntry[];
50
+ getErrorsBySeverity: (severity: ErrorSeverity) => ErrorLogEntry[];
51
+ getErrorsBySource: (source: string) => ErrorLogEntry[];
52
+ getUndismissedErrors: () => ErrorLogEntry[];
53
+ getActiveErrors: () => ErrorLogEntry[];
54
+ hasActiveErrors: () => boolean;
55
+ getErrorCount: () => number;
56
+ getActiveErrorCount: () => number;
57
+ }
58
+ /**
59
+ * Base Zustand slice creator type.
60
+ *
61
+ * Used for slices **without** middleware such as `persist` or `immer`.
62
+ */
63
+ export type BaseSliceCreator<T> = StateCreator<T>;
64
+ type MiddlewareMutators = [never, unknown][];
65
+ /**
66
+ * Zustand slice creator type for slices that use middleware
67
+ * like `persist` and `immer`.
68
+ *
69
+ * Note: You don't need to manually specify middleware type tuples
70
+ * (like `["zustand/persist", T]`) since Zustand automatically infers them.
71
+ */
72
+ export type PersistentSliceCreator<T> = StateCreator<T, [
73
+ ], MiddlewareMutators, T>;
74
+ /**
75
+ * Root store type that combines multiple Zustand slices.
76
+ *
77
+ * Currently includes only `ErrorSliceType`, but can later be extended
78
+ * to include other slices such as `AuthSliceType`, `UserSliceType`, etc.
79
+ *
80
+ * @typedef {ErrorSliceType} RootStore
81
+ */
82
+ export type RootStore = ErrorSliceType;
83
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plyaz/types",
3
- "version": "1.12.3",
3
+ "version": "1.12.4",
4
4
  "author": "Redeemer Pace",
5
5
  "license": "ISC",
6
6
  "description": "Provides shared TypeScript types and schema utilities for validation and parsing in the @playz ecosystem.",
@@ -183,7 +183,8 @@
183
183
  "packageManager": "pnpm@10.11.0",
184
184
  "dependencies": {
185
185
  "pino": "^10.0.0",
186
- "type-fest": "^4.41.0"
186
+ "type-fest": "^4.41.0",
187
+ "zustand": "^5.0.0"
187
188
  },
188
189
  "devDependencies": {
189
190
  "@changesets/cli": "^2.29.5",