@plyaz/types 1.13.2 → 1.13.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.
Files changed (55) hide show
  1. package/dist/api/client/types.d.ts +3 -3
  2. package/dist/api/config/types.d.ts +62 -5
  3. package/dist/api/debugger/enums.d.ts +12 -0
  4. package/dist/api/debugger/types.d.ts +1 -1
  5. package/dist/api/errors/types.d.ts +46 -238
  6. package/dist/api/events/factories/errors/types.d.ts +26 -27
  7. package/dist/api/index.cjs +1437 -669
  8. package/dist/api/index.cjs.map +1 -1
  9. package/dist/api/index.d.ts +5 -2
  10. package/dist/api/index.js +1365 -603
  11. package/dist/api/index.js.map +1 -1
  12. package/dist/db/DatabaseAdapter.d.ts +2 -2
  13. package/dist/db/DatabaseService.d.ts +5 -5
  14. package/dist/db/config.types.d.ts +1 -1
  15. package/dist/db/database.types.d.ts +2 -2
  16. package/dist/db/index.cjs.map +1 -1
  17. package/dist/db/index.d.ts +1 -1
  18. package/dist/db/index.js.map +1 -1
  19. package/dist/errors/codes.d.ts +251 -0
  20. package/dist/errors/enums.d.ts +199 -0
  21. package/dist/errors/index.cjs +1287 -0
  22. package/dist/errors/index.cjs.map +1 -1
  23. package/dist/errors/index.d.ts +1 -0
  24. package/dist/errors/index.js +1264 -1
  25. package/dist/errors/index.js.map +1 -1
  26. package/dist/errors/types.d.ts +630 -14
  27. package/dist/index.cjs +2161 -1217
  28. package/dist/index.cjs.map +1 -1
  29. package/dist/index.d.ts +43 -1
  30. package/dist/index.js +1829 -911
  31. package/dist/index.js.map +1 -1
  32. package/dist/notifications/enums.d.ts +140 -0
  33. package/dist/notifications/index.cjs +4353 -0
  34. package/dist/notifications/index.cjs.map +1 -0
  35. package/dist/notifications/index.js +145 -0
  36. package/dist/notifications/index.js.map +1 -0
  37. package/dist/notifications/schemas.d.ts +73 -0
  38. package/dist/notifications/types.d.ts +1937 -0
  39. package/dist/payments/base-error/enum.d.ts +79 -0
  40. package/dist/payments/base-error/index.d.ts +2 -0
  41. package/dist/payments/base-error/types.d.ts +180 -0
  42. package/dist/payments/currency/enums.d.ts +37 -0
  43. package/dist/payments/currency/index.d.ts +1 -37
  44. package/dist/payments/index.cjs +40 -40
  45. package/dist/payments/index.cjs.map +1 -1
  46. package/dist/payments/index.d.ts +2 -1
  47. package/dist/payments/index.js +40 -40
  48. package/dist/payments/index.js.map +1 -1
  49. package/dist/payments/transaction/types.d.ts +3 -3
  50. package/dist/store/index.d.ts +1 -1
  51. package/dist/store/types.d.ts +2 -3
  52. package/package.json +6 -1
  53. package/dist/api/errors/enum.d.ts +0 -214
  54. package/dist/api/errors/index.d.ts +0 -6
  55. /package/dist/db/{enhanced-config.types.d.ts → features-config.types.d.ts} +0 -0
@@ -9,7 +9,7 @@ import type { EndpointTypes } from '../endpoints';
9
9
  import type { UnknownRecord } from 'type-fest';
10
10
  import type { NETWORK_QUALITY, NetworkInfo } from '../network';
11
11
  import type { ConfigConflict, DebugInfo } from '../debugger';
12
- import type { ApiPackageErrorLike } from '../errors';
12
+ import type { PackageErrorLike } from '../../errors';
13
13
  /**
14
14
  * Options for creating an API client
15
15
  * Endpoints are automatically included from src/api/endpoints
@@ -66,7 +66,7 @@ export interface EventManagerLike<TEventManager = unknown> {
66
66
  eventCountsByType: Record<string, number>;
67
67
  };
68
68
  getActiveScopes(): EventScopeWithTemporary[];
69
- emitError(error: ApiPackageErrorLike): void;
69
+ emitError(error: PackageErrorLike): void;
70
70
  emitRequestStart(config: RequestConfig): void;
71
71
  emitResponseReceived<TData = unknown>(response: FetchResponse<TData>): void;
72
72
  emitRetryAttempt<TResponse = unknown>(error: ResponseError<TResponse>, attemptNumber: number, config?: RequestConfig): void;
@@ -239,7 +239,7 @@ export interface ClientEventManagerLike<TEventManager> {
239
239
  eventCountsByType: Record<string, number>;
240
240
  };
241
241
  getActiveScopes(): EventScopeWithTemporary[];
242
- emitError(error: ApiPackageErrorLike): void;
242
+ emitError(error: PackageErrorLike): void;
243
243
  emitRequestStart(config: RequestConfig): void;
244
244
  emitResponseReceived<TData = unknown>(response: FetchResponse<TData>): void;
245
245
  emitRetryAttempt<TResponse = unknown>(error: ResponseError<TResponse>, attemptNumber: number, config?: RequestConfig): void;
@@ -10,13 +10,13 @@ import type { RetryConfig, RetryStrategyName } from '../retry';
10
10
  import type { PerformancePresetName } from '../performance';
11
11
  import type { RevalidationStrategyName } from '../revalidation';
12
12
  import type { ApiHeaders, EnrichedHeadersOptions, HeaderBuilderLike, HeaderPresetName } from '../headers';
13
- import type { ErrorEventHandlers } from '../errors';
14
13
  import type { ConfigUpdateStrategy, HandlerStrategy, EventScopeWithTemporary } from '../events';
15
14
  import type { NETWORK_QUALITY } from '../network';
16
15
  import type { HeaderEventHandlers, NetworkEventHandlers, ConfigEventHandlers, ClientEventHandlers, CacheEventHandlers, PerformanceEventHandlers } from '../events';
17
16
  import type { ApiClientOptions } from '../client';
18
17
  import type { DebugEventsConfig } from '../debugger';
19
18
  import type { EncryptionConfig } from '../encryption';
19
+ import type { ErrorEventHandlers, ErrorDetailsList, MessageCatalog } from '../../errors';
20
20
  /**
21
21
  * HTTP Methods - extend from fetchff but uppercase
22
22
  */
@@ -640,6 +640,38 @@ export interface ApiConfig extends Partial<Omit<FetchffRequestConfig, 'retry' |
640
640
  */
641
641
  telemetry?: boolean;
642
642
  };
643
+ /**
644
+ * Error system configuration
645
+ * Controls error message localization and custom error catalogs
646
+ *
647
+ * @example
648
+ * ```typescript
649
+ * const api = createApiClient({
650
+ * errors: {
651
+ * locale: 'es',
652
+ * additionalCatalogs: {
653
+ * en: {
654
+ * errors: {
655
+ * custom_error: 'Custom error message'
656
+ * }
657
+ * }
658
+ * }
659
+ * }
660
+ * });
661
+ * ```
662
+ */
663
+ errors?: {
664
+ /**
665
+ * Default locale for error messages
666
+ * @default 'en'
667
+ */
668
+ locale?: string;
669
+ /**
670
+ * Additional message catalogs for custom errors
671
+ * Merged with built-in error messages
672
+ */
673
+ additionalCatalogs?: Record<string, MessageCatalog>;
674
+ };
643
675
  }
644
676
  /**
645
677
  * Request-specific configuration
@@ -676,13 +708,38 @@ export interface EndpointConfig extends Omit<RequestConfig, 'params' | 'urlPathP
676
708
  * API Response wrapper
677
709
  * Extends fetchff's FetchResponse
678
710
  */
679
- export interface ApiResponse<TData = DefaultPayload, TBody = DefaultPayload, TParams = DefaultParams, TPathParams = UrlPathParams> extends FetchResponse<TData, TBody, TParams, TPathParams> {
680
- }
711
+ export type ApiResponse<TData = DefaultPayload, TBody = DefaultPayload, TParams = DefaultParams, TPathParams = UrlPathParams> = FetchResponse<TData, TBody, TParams, TPathParams>;
681
712
  /**
682
713
  * API Error interface
683
- * Extends fetchff's ResponseError
714
+ * Extends fetchff's ResponseError with error response data typed as ErrorDetailsList
715
+ *
716
+ * The response data (accessible via response.data or response) contains
717
+ * the error details array from the API.
718
+ *
719
+ * @template TData - Type of response data, defaults to ErrorDetailsList (array of error details)
720
+ * @template TBody - Type of request body
721
+ * @template TParams - Type of query parameters
722
+ * @template TPathParams - Type of URL path parameters
723
+ *
724
+ * @example
725
+ * ```typescript
726
+ * // Default: response.data will be ErrorDetailsList
727
+ * const error: ApiError = {
728
+ * message: 'Validation failed',
729
+ * status: 400,
730
+ * response: {
731
+ * data: [
732
+ * { field: 'email', message: 'Invalid email format', code: 'INVALID_EMAIL' }
733
+ * ]
734
+ * }
735
+ * };
736
+ *
737
+ * // Custom error response type
738
+ * interface CustomError { code: string; details: string }
739
+ * const error: ApiError<CustomError[]> = { ... };
740
+ * ```
684
741
  */
685
- export interface ApiError<TData = DefaultPayload, TBody = DefaultPayload, TParams = DefaultParams, TPathParams = UrlPathParams> extends ResponseError<TData, TBody, TParams, TPathParams> {
742
+ export interface ApiError<ValueGiven = string | number | boolean, AllowedValues = Record<string, string>, Constraints = Record<string, string>, TData = ErrorDetailsList<ValueGiven, AllowedValues, Constraints>, TBody = DefaultPayload, TParams = DefaultParams, TPathParams = UrlPathParams> extends ResponseError<TData, TBody, TParams, TPathParams> {
686
743
  }
687
744
  /**
688
745
  * Configuration state that tracks base config and temporary overrides separately
@@ -15,6 +15,12 @@ export declare const FACTORY_OPERATIONS: {
15
15
  readonly FACTORY_REGISTER: "factory_register";
16
16
  readonly HANDLER_REGISTERED: "handler_registered";
17
17
  readonly HANDLER_UNREGISTERED: "handler_unregistered";
18
+ /**
19
+ * Indicates that a specific handler instance has been removed from a factory or scope.
20
+ * Use this when removing a particular handler by reference or ID, as opposed to
21
+ * HANDLER_UNREGISTERED, which refers to unregistering a handler type or all handlers.
22
+ */
23
+ readonly SPECIFIC_HANDLER_REMOVED: "specific_handler_removed";
18
24
  readonly SCOPE_LISTENERS_CLEARED: "scope_listeners_cleared";
19
25
  };
20
26
  /**
@@ -200,6 +206,12 @@ export declare const UNIFIED_OPERATIONS: {
200
206
  readonly FACTORY_REGISTER: "factory_register";
201
207
  readonly HANDLER_REGISTERED: "handler_registered";
202
208
  readonly HANDLER_UNREGISTERED: "handler_unregistered";
209
+ /**
210
+ * Indicates that a specific handler instance has been removed from a factory or scope.
211
+ * Use this when removing a particular handler by reference or ID, as opposed to
212
+ * HANDLER_UNREGISTERED, which refers to unregistering a handler type or all handlers.
213
+ */
214
+ readonly SPECIFIC_HANDLER_REMOVED: "specific_handler_removed";
203
215
  readonly SCOPE_LISTENERS_CLEARED: "scope_listeners_cleared";
204
216
  };
205
217
  export type QueueOperationType = (typeof QUEUE_OPERATIONS)[keyof typeof QUEUE_OPERATIONS];
@@ -208,7 +208,7 @@ export interface MonitoringAlert {
208
208
  /**
209
209
  * Factory operation types for type safety
210
210
  */
211
- export type FactoryOperationType = 'factory_created' | 'factory_accessed' | 'factory_initialized' | 'factories_reset' | 'factory_register' | 'handler_registered' | 'handler_unregistered' | 'scope_listeners_cleared';
211
+ export type FactoryOperationType = 'factory_created' | 'factory_accessed' | 'factory_initialized' | 'factories_reset' | 'factory_register' | 'handler_registered' | 'handler_unregistered' | 'specific_handler_removed' | 'scope_listeners_cleared';
212
212
  /**
213
213
  * Event operation types for pubsub and event system
214
214
  */
@@ -6,54 +6,32 @@
6
6
  * Import and re-export ResponseError and RequestConfig types from fetchff
7
7
  * These are 3rd party types that @plyaz/api wraps
8
8
  */
9
- import type { ResponseError, RequestConfig } from 'fetchff';
10
- import type { ERROR_CATEGORY, ErrorDetail, ErrorResponse } from '../../errors';
11
- import type { API_ERROR_CODES, OPERATIONS, ERROR_FIELDS, STORAGE_TYPES, ApiClientInstance } from '..';
12
- import type { PACKAGE_STATUS_CODES } from './enum';
9
+ import type { ResponseError } from 'fetchff';
10
+ import type { ErrorDetail, BasePackageErrorOptions, INTERNAL_STATUS_CODES, PackageErrorLike } from '../../errors';
11
+ import type { ApiClientInstance } from '..';
13
12
  import type { HTTP_STATUS } from '@plyaz/config';
14
13
  /**
15
- * Typed constants as types for convenience
14
+ * ===== Type Aliases =====
15
+ * Re-exported from centralized location for backwards compatibility
16
+ * NEW CODE should import from @plyaz/types/errors instead
16
17
  */
17
- export type ErrorOperation = (typeof OPERATIONS)[keyof typeof OPERATIONS];
18
- export type ErrorField = (typeof ERROR_FIELDS)[keyof typeof ERROR_FIELDS];
19
- export type StorageType = (typeof STORAGE_TYPES)[keyof typeof STORAGE_TYPES];
18
+ export type { CommonOperation as ErrorOperation } from '../../errors';
19
+ export type { CommonField as ErrorField } from '../../errors';
20
+ export type { CommonStorageType as StorageType } from '../../errors';
20
21
  /**
21
- * Type for API error codes
22
+ * ===== Status Code Type Aliases =====
23
+ * API-specific status code types
22
24
  */
23
- export type ApiErrorCode = (typeof API_ERROR_CODES)[keyof typeof API_ERROR_CODES];
24
25
  /**
25
- * Type alias for error category values
26
- * Represents a single category value from ERROR_CATEGORY
26
+ * Type alias for internal package status codes (1xxx range)
27
+ * Custom internal status codes that don't map to HTTP status codes
27
28
  *
28
29
  * @example
29
30
  * ```typescript
30
- * const category: ErrorCategoryValue = ERROR_CATEGORY.Network; // 'network'
31
- * const isValid: ErrorCategoryValue = 'authentication'; // valid
31
+ * const statusCode: InternalStatusCodeValue = INTERNAL_STATUS_CODES.INVALID_CONFIGURATION; // 1001
32
32
  * ```
33
33
  */
34
- export type ErrorCategoryValue = (typeof ERROR_CATEGORY)[keyof typeof ERROR_CATEGORY];
35
- /**
36
- * Type alias for API error code values
37
- * Use this instead of repeating the verbose (typeof API_ERROR_CODES)[keyof typeof API_ERROR_CODES]
38
- * Also allows dynamic HTTP error codes in the form HTTP_${number}
39
- *
40
- * @example
41
- * ```typescript
42
- * const code: ApiErrorCodeValue = API_ERROR_CODES.NETWORK_ERROR;
43
- * const dynamicCode: ApiErrorCodeValue = `HTTP_${404}`; // Also valid
44
- * ```
45
- */
46
- export type ApiErrorCodeValue = (typeof API_ERROR_CODES)[keyof typeof API_ERROR_CODES] | `HTTP_${number}`;
47
- /**
48
- * Type alias for package-specific status code values
49
- * Custom status codes specific to @plyaz/api package (1xxx range)
50
- *
51
- * @example
52
- * ```typescript
53
- * const statusCode: PackageStatusCodeValue = PACKAGE_STATUS_CODES.CLIENT_CANCELLED; // 1001
54
- * ```
55
- */
56
- export type PackageStatusCodeValue = (typeof PACKAGE_STATUS_CODES)[keyof typeof PACKAGE_STATUS_CODES];
34
+ export type InternalStatusCodeValue = (typeof INTERNAL_STATUS_CODES)[keyof typeof INTERNAL_STATUS_CODES];
57
35
  /**
58
36
  * Type alias for HTTP status code values
59
37
  * Standard HTTP status codes from @plyaz/config
@@ -65,233 +43,63 @@ export type PackageStatusCodeValue = (typeof PACKAGE_STATUS_CODES)[keyof typeof
65
43
  */
66
44
  export type HttpStatusCodeValue = (typeof HTTP_STATUS)[keyof typeof HTTP_STATUS];
67
45
  /**
68
- * Union type for all valid status codes
69
- * Combines both HTTP status codes and package-specific status codes
46
+ * Union type for all valid API status codes
47
+ * Combines both HTTP status codes and internal package status codes
70
48
  *
71
49
  * @example
72
50
  * ```typescript
73
- * const httpCode: StatusCodeValue = HTTP_STATUS.BAD_REQUEST; // 400
74
- * const customCode: StatusCodeValue = PACKAGE_STATUS_CODES.CLIENT_CANCELLED; // 1001
51
+ * const httpCode: ApiStatusCodeValue = HTTP_STATUS.BAD_REQUEST; // 400
52
+ * const internalCode: ApiStatusCodeValue = INTERNAL_STATUS_CODES.INVALID_CONFIGURATION; // 1001
75
53
  * ```
76
54
  */
77
- export type StatusCodeValue = PackageStatusCodeValue | HttpStatusCodeValue;
55
+ export type ApiStatusCodeValue = InternalStatusCodeValue | HttpStatusCodeValue;
78
56
  /**
79
57
  * Translation interpolation variables
58
+ * Used for i18n error message interpolation
80
59
  */
81
60
  export interface I18nContext {
82
61
  [key: string]: string | number | boolean | null | undefined;
83
62
  }
84
- /**
85
- * Base error context with common fields
86
- */
87
- export interface BaseErrorContext {
88
- operation?: ErrorOperation;
89
- originalError?: string;
90
- i18n?: I18nContext;
91
- url?: string;
92
- method?: string;
93
- strategyName?: string;
94
- fallback?: string;
95
- eventType?: string;
96
- reason?: string;
97
- debuggerOperation?: string;
98
- timeoutMs?: number;
99
- timeout?: number;
100
- elapsed?: number;
101
- routerType?: string;
102
- storageType?: string;
103
- availableStrategies?: string;
104
- requestedStrategy?: string;
105
- fallbackUsed?: string;
106
- requestedPreset?: string;
107
- availablePresets?: string;
108
- retryable?: boolean;
109
- field?: string;
110
- value?: unknown;
111
- constraints?: Record<string, string>;
112
- realm?: string;
113
- scheme?: string;
114
- limit?: number;
115
- remaining?: number;
116
- resetAt?: string;
117
- retryAfter?: number;
118
- serverMessage?: string;
119
- traceId?: string;
120
- input?: unknown;
121
- errors?: Array<{
122
- field: string;
123
- message: string;
124
- code?: string;
125
- }>;
126
- headers?: Record<string, string>;
127
- }
128
- /**
129
- * Cache error context
130
- */
131
- export interface CacheErrorContext extends BaseErrorContext {
132
- operation: ErrorOperation;
133
- cacheKey?: string;
134
- keyPrefix?: string;
135
- exactKey?: string;
136
- storageType?: StorageType | string;
137
- fallbackAvailable?: boolean;
138
- }
139
- /**
140
- * Headers error context
141
- */
142
- export interface HeadersErrorContext extends BaseErrorContext {
143
- operation: ErrorOperation;
144
- warningCount?: number;
145
- warnings?: string;
146
- }
147
- /**
148
- * Regional error context
149
- */
150
- export interface RegionalErrorContext extends BaseErrorContext {
151
- operation: ErrorOperation;
152
- requestedPreset?: string;
153
- availablePresets?: string;
154
- fallbackUsed?: string;
155
- }
156
- /**
157
- * Network error context
158
- */
159
- export interface NetworkErrorContext extends BaseErrorContext {
160
- operation: ErrorOperation;
161
- requestedPreset?: string;
162
- availablePresets?: string;
163
- }
164
- /**
165
- * Error definition structure
166
- */
167
- export interface ErrorDefinition {
168
- code: string;
169
- status: number;
170
- category: (typeof ERROR_CATEGORY)[keyof typeof ERROR_CATEGORY];
171
- fieldsLeft?: string[];
172
- }
173
- /**
174
- * Map of error codes to their definitions
175
- */
176
- export type ErrorDefinitions = {
177
- [key: string]: ErrorDefinition;
178
- };
179
- /**
180
- * Union type for all error contexts
181
- */
182
- export type ErrorContext = BaseErrorContext | CacheErrorContext | HeadersErrorContext | RegionalErrorContext | NetworkErrorContext;
183
63
  /**
184
64
  * Options for creating an ApiPackageError
185
- * Note: ApiPackageError class itself is not migrated as it contains implementation
65
+ * Extends BasePackageErrorOptions with API-specific properties
186
66
  */
187
- export interface ApiPackageErrorOptionsErrorDetail<ValueGiven, AllowedValues, Constraints> {
67
+ export interface ApiPackageErrorOptionsErrorDetail<ValueGiven, AllowedValues, Constraints> extends BasePackageErrorOptions {
68
+ /** HTTP response error from fetchff */
188
69
  responseError?: unknown;
70
+ /** HTTP status code */
189
71
  statusCode?: number;
72
+ /** Validation error details */
190
73
  errors?: ErrorDetail<ValueGiven, AllowedValues, Constraints>[];
191
- correlationId?: string;
192
- cause?: Error;
193
- context?: ErrorContext;
74
+ /** API client instance context (avoid circular dependency) */
194
75
  clientContext?: unknown;
195
76
  }
196
77
  /**
197
- * Interface representing the public API of ApiPackageError
198
- * Useful for type-checking without requiring the actual class instance
78
+ * ErrorEventHandlers and ErrorHandlerOptions moved to centralized location
79
+ * Import from: import { ErrorEventHandlers, ErrorHandlerOptions } from '@plyaz/types/errors';
199
80
  *
200
- * This interface allows for:
201
- * - Duck typing compatibility
202
- * - Easier mocking in tests
203
- * - Type-safe function parameters without importing the class
204
- * - Clearer documentation of the public API contract
205
- *
206
- * @example
207
- * ```typescript
208
- * function handleError(error: ApiPackageErrorLike): void {
209
- * if (error.isRetryable()) {
210
- * // Retry logic
211
- * }
212
- * console.error(error.getUserMessage());
213
- * }
214
- * ```
215
- */
216
- export interface ApiPackageErrorLike extends Error {
217
- readonly statusCode: StatusCodeValue;
218
- readonly errorCode: ApiErrorCodeValue;
219
- readonly message: string;
220
- readonly errors?: ErrorDetail<unknown, unknown, unknown>[];
221
- readonly correlationId?: string;
222
- readonly timestamp: string;
223
- readonly responseError?: ResponseError;
224
- readonly category: ErrorCategoryValue;
225
- readonly cause?: Error;
226
- readonly context?: ErrorContext;
227
- readonly requestConfig?: RequestConfig;
228
- readonly responseData?: ResponseError['response'];
229
- readonly details?: ErrorDetail<unknown, unknown, unknown>[];
230
- readonly originalError?: Error;
231
- readonly metadata?: Record<string, string | number | boolean | null>;
232
- readonly code: string;
233
- isAuthError(): boolean;
234
- isValidationError(): boolean;
235
- isNetworkError(): boolean;
236
- isServerError(): boolean;
237
- isClientError(): boolean;
238
- isRetryable(): boolean;
239
- toJSON(): ErrorResponse;
240
- toString(): string;
241
- getUserMessage(): string;
242
- }
243
- /**
244
- * Event handler types for API package errors
245
- * Note: ApiPackageError is not imported here to avoid implementation dependencies
246
- */
247
- export interface ErrorEventHandlers {
248
- onValidationError?: ((error: ApiPackageErrorLike) => void) | Array<(error: ApiPackageErrorLike) => void>;
249
- onNetworkError?: ((error: ApiPackageErrorLike) => void) | Array<(error: ApiPackageErrorLike) => void>;
250
- onAuthenticationError?: ((error: ApiPackageErrorLike) => void) | Array<(error: ApiPackageErrorLike) => void>;
251
- onAuthorizationError?: ((error: ApiPackageErrorLike) => void) | Array<(error: ApiPackageErrorLike) => void>;
252
- onRateLimitError?: ((error: ApiPackageErrorLike) => void) | Array<(error: ApiPackageErrorLike) => void>;
253
- onTimeoutError?: ((error: ApiPackageErrorLike) => void) | Array<(error: ApiPackageErrorLike) => void>;
254
- onConflictError?: ((error: ApiPackageErrorLike) => void) | Array<(error: ApiPackageErrorLike) => void>;
255
- onNotFoundError?: ((error: ApiPackageErrorLike) => void) | Array<(error: ApiPackageErrorLike) => void>;
256
- onServerError?: ((error: ApiPackageErrorLike) => void) | Array<(error: ApiPackageErrorLike) => void>;
257
- onClientError?: ((error: ApiPackageErrorLike) => void) | Array<(error: ApiPackageErrorLike) => void>;
258
- onExternalServiceError?: ((error: ApiPackageErrorLike) => void) | Array<(error: ApiPackageErrorLike) => void>;
259
- onCacheError?: ((error: ApiPackageErrorLike) => void) | Array<(error: ApiPackageErrorLike) => void>;
260
- onHeadersError?: ((error: ApiPackageErrorLike) => void) | Array<(error: ApiPackageErrorLike) => void>;
261
- onRetryError?: ((error: ApiPackageErrorLike) => void) | Array<(error: ApiPackageErrorLike) => void>;
262
- onStrategyError?: ((error: ApiPackageErrorLike) => void) | Array<(error: ApiPackageErrorLike) => void>;
263
- onRegionalError?: ((error: ApiPackageErrorLike) => void) | Array<(error: ApiPackageErrorLike) => void>;
264
- onUnknownError?: ((error: ApiPackageErrorLike) => void) | Array<(error: ApiPackageErrorLike) => void>;
265
- onAnyError?: ((error: ApiPackageErrorLike) => void) | Array<(error: ApiPackageErrorLike) => void>;
266
- }
267
- /**
268
- * Options for error handler registration
81
+ * Re-exported here for backwards compatibility
269
82
  */
270
- export interface ErrorHandlerOptions {
271
- /**
272
- * The scope level for the handler
273
- * @default 'GLOBAL'
274
- */
275
- scope?: 'GLOBAL' | 'CONFIG' | 'CLIENT' | 'REQUEST' | 'TEMPORARY';
276
- /**
277
- * Strategy for handling multiple handlers
278
- * - 'merge': Add to existing handlers (default)
279
- * - 'replace': Replace existing handlers for this event type
280
- * - 'prepend': Add new handlers before existing ones
281
- * - 'append': Add new handlers after existing ones
282
- * @default 'merge'
283
- */
284
- strategy?: 'merge' | 'replace' | 'prepend' | 'append';
285
- }
83
+ export type { ErrorEventHandlers, ErrorHandlerOptions } from '../../errors';
286
84
  /**
287
- * Options for creating an ApiPackageError
85
+ * Options for creating an ApiPackageError with typed client instance
86
+ * Extends BasePackageErrorOptions with API-specific properties
288
87
  */
289
- export interface ApiPackageErrorOptions<EndpointsList> {
88
+ export interface ApiPackageErrorOptions<EndpointsList> extends BasePackageErrorOptions {
89
+ /** HTTP response error from fetchff */
290
90
  responseError?: ResponseError;
91
+ /** HTTP status code */
291
92
  statusCode?: number;
93
+ /** Validation error details */
292
94
  errors?: ErrorDetail<unknown, unknown, unknown>[];
293
- correlationId?: string;
294
- cause?: Error;
295
- context?: ErrorContext;
95
+ /** API client instance (typed with endpoints list) */
296
96
  clientContext?: ApiClientInstance<EndpointsList>;
297
97
  }
98
+ /**
99
+ * Handler function type for category-based error event emission
100
+ * Used to map error categories to their corresponding event emission handlers
101
+ *
102
+ * @param error - The package error to emit
103
+ * @param context - Optional context from the error containing additional metadata
104
+ */
105
+ export type CategoryErrorHandler = (error: PackageErrorLike, context: Record<string, unknown> | undefined) => void;