@plyaz/types 1.13.3 → 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 +3 -3
  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
@@ -1,18 +1,10 @@
1
1
  import type { ReactNode } from 'react';
2
- import type { WithStatusCode, WithErrorCode, WithMessage, WithCorrelationId, WithTimestamp, WithValidationError } from '../common/types';
2
+ import type { WithValidationError } from '../common/types';
3
3
  import type { ERRORS_CODES } from '@plyaz/config';
4
- import type { ERROR_CATEGORY } from './enums';
4
+ import type { ERROR_CATEGORY, ERROR_SEVERITY, COMMON_OPERATIONS, COMMON_FIELDS, COMMON_STORAGE_TYPES, INTERNAL_STATUS_CODES } from './enums';
5
5
  import type { NextFunction } from 'express';
6
- /**
7
- * Represents the structure of an error response returned by the application.
8
- * @template ErrorDetails - The type of the `errors` array, defaults to `ErrorDetailsList`.
9
- */
10
- export interface ErrorResponse<ErrorDetails = ErrorDetailsList> extends WithStatusCode, WithErrorCode, WithMessage, Partial<WithCorrelationId>, WithTimestamp {
11
- /**
12
- * Array of detailed errors, typically used for validation failures.
13
- */
14
- readonly errors: ErrorDetails;
15
- }
6
+ import type { ERROR_CODES } from './codes';
7
+ import type { ApiClientInstance } from '../api';
16
8
  /**
17
9
  * Additional context information about a validation error.
18
10
  * @template ValueGiven - Type of the value that caused the error.
@@ -50,9 +42,12 @@ export type ErrorDetail<ValueGiven, AllowedValues, Constraints> = WithValidation
50
42
  * Error Details Array.
51
43
  * @description A flexible list of error details that can contain string, number, or boolean values along with structured allowed values and constraints.
52
44
  */
53
- export type ErrorDetailsList = readonly ErrorDetail<string | number | boolean, Record<string, string>, Record<string, string>>[];
45
+ export type ErrorDetailsList<ValueGiven = string | number | boolean, AllowedValues = Record<string, string>, Constraints = Record<string, string>> = readonly ErrorDetail<ValueGiven, AllowedValues, Constraints>[];
46
+ /**
47
+ * Alias for error response structure, which serves for API responses.
48
+ */
49
+ export type ErrorResponse = ErrorDetailsList;
54
50
  export type ErrorCodeKey = keyof typeof ERRORS_CODES;
55
- export type ErrorCodeValue = (typeof ERRORS_CODES)[ErrorCodeKey];
56
51
  export type ErrorCodeMsg = (typeof ERRORS_CODES)[ErrorCodeKey];
57
52
  export interface ReturnResponseType<T = unknown> {
58
53
  codeStatus: number;
@@ -77,5 +72,626 @@ export interface BaseErrorResponse {
77
72
  /** ISO timestamp when the error occurred. */
78
73
  timestamp: string;
79
74
  }
75
+ /**
76
+ * Error definition structure
77
+ * Single source of truth for all error definitions across @plyaz packages
78
+ * Combines properties from API, notifications, and future packages
79
+ */
80
+ export interface ErrorDefinition {
81
+ /** Error code (unique identifier) */
82
+ code: string;
83
+ /** HTTP or package-specific status code */
84
+ status: number;
85
+ /** Error category (from ERROR_CATEGORY) */
86
+ category: (typeof ERROR_CATEGORY)[keyof typeof ERROR_CATEGORY];
87
+ /** Error severity level (from ERROR_SEVERITY) - optional for backwards compat */
88
+ severity?: (typeof ERROR_SEVERITY)[keyof typeof ERROR_SEVERITY];
89
+ /** Whether this error is retryable - optional for backwards compat */
90
+ retryable?: boolean;
91
+ /** User-friendly error message - optional for backwards compat */
92
+ userMessage?: string;
93
+ /** Optional: Fields involved in the error (for validation errors) */
94
+ fieldsLeft?: string[];
95
+ }
96
+ /**
97
+ * Map of error codes to their definitions
98
+ * Indexed by error code values (e.g., 'CLIENT_INITIALIZATION_FAILED')
99
+ */
100
+ export type ErrorDefinitions = {
101
+ readonly [K in (typeof ERROR_CODES)[keyof typeof ERROR_CODES]]: ErrorDefinition;
102
+ };
103
+ /**
104
+ * Base error context
105
+ * Common fields used across all error contexts in @plyaz packages
106
+ * Combines context properties from API, notifications, and other packages
107
+ *
108
+ * Note: All string fields are freeform - you don't need to use specific const objects.
109
+ * For example, `operation` can be any string like 'storage', 'retrieval', 'validation', etc.
110
+ *
111
+ * Note: For validation errors with field-specific details, use the `errors` array with ErrorDetail objects.
112
+ */
113
+ export interface BaseErrorContext {
114
+ operation?: string;
115
+ originalError?: string;
116
+ url?: string;
117
+ method?: string;
118
+ timeoutMs?: number;
119
+ timeout?: number;
120
+ elapsed?: number;
121
+ channel?: string;
122
+ provider?: string;
123
+ recipientId?: string;
124
+ templateId?: string;
125
+ strategyName?: string;
126
+ fallback?: string;
127
+ eventType?: string;
128
+ reason?: string;
129
+ debuggerOperation?: string;
130
+ routerType?: string;
131
+ storageType?: string;
132
+ availableStrategies?: string;
133
+ requestedStrategy?: string;
134
+ fallbackUsed?: string;
135
+ requestedPreset?: string;
136
+ availablePresets?: string;
137
+ cacheKey?: string;
138
+ keyPrefix?: string;
139
+ exactKey?: string;
140
+ fallbackAvailable?: boolean;
141
+ warningCount?: number;
142
+ warnings?: string;
143
+ retryable?: boolean;
144
+ realm?: string;
145
+ scheme?: string;
146
+ limit?: number;
147
+ remaining?: number;
148
+ resetAt?: string;
149
+ retryAfter?: number;
150
+ serverMessage?: string;
151
+ traceId?: string;
152
+ correlationId?: string;
153
+ input?: unknown;
154
+ /**
155
+ * Validation error details
156
+ * Use ErrorDetail objects for field-specific validation errors
157
+ * Each ErrorDetail contains: field, message, code, and ErrorDetailContext (valueGiven, allowedValues, constraints)
158
+ */
159
+ errors?: ErrorDetail<unknown, unknown, unknown>[];
160
+ headers?: Record<string, string>;
161
+ i18n?: I18nContext;
162
+ [key: string]: unknown;
163
+ }
164
+ /**
165
+ * Cache-specific error context
166
+ * Extends BaseErrorContext with cache-related properties
167
+ */
168
+ export type CacheErrorContext = BaseErrorContext;
169
+ /**
170
+ * Headers-specific error context
171
+ * Extends BaseErrorContext with headers-related properties
172
+ */
173
+ export type HeadersErrorContext = BaseErrorContext;
174
+ /**
175
+ * Network-specific error context
176
+ * Extends BaseErrorContext with network-related properties
177
+ */
178
+ export type NetworkErrorContext = BaseErrorContext;
179
+ /**
180
+ * Regional-specific error context
181
+ * Extends BaseErrorContext with regional-related properties
182
+ */
183
+ export type RegionalErrorContext = BaseErrorContext;
184
+ /**
185
+ * Base options for creating package errors
186
+ * Common options across all @plyaz package errors
187
+ */
188
+ export interface BasePackageErrorOptions {
189
+ cause?: Error;
190
+ context?: BaseErrorContext;
191
+ metadata?: Record<string, string | number | boolean | null>;
192
+ correlationId?: string;
193
+ }
194
+ /**
195
+ * Extended package error options with additional properties
196
+ * Generic interface that works for API, notifications, and other packages
197
+ *
198
+ * @template TClientContext - Type of client context (e.g., ApiClientInstance<EndpointsList>)
199
+ * @template TResponseError - Type of response error (e.g., ResponseError from fetchff)
200
+ * @template TValueGiven - Type of validation error value
201
+ * @template TAllowedValues - Type of validation allowed values
202
+ * @template TConstraints - Type of validation constraints
203
+ *
204
+ * @example
205
+ * ```typescript
206
+ * // For API package:
207
+ * type ApiErrorOptions = PackageErrorOptions<
208
+ * ApiClientInstance<MyEndpoints>,
209
+ * ResponseError
210
+ * >;
211
+ *
212
+ * // For notifications package:
213
+ * type NotificationErrorOptions = PackageErrorOptions<never, never>;
214
+ * ```
215
+ */
216
+ export interface PackageErrorOptions<TClientContext = unknown, TResponseError = unknown, TValueGiven = unknown, TAllowedValues = unknown, TConstraints = unknown> extends BasePackageErrorOptions {
217
+ /** HTTP or package response error */
218
+ responseError?: TResponseError;
219
+ /** HTTP or package status code */
220
+ statusCode?: number;
221
+ /** Validation error details */
222
+ errors?: ErrorDetail<TValueGiven, TAllowedValues, TConstraints>[];
223
+ /** Client or service instance context */
224
+ clientContext?: TClientContext;
225
+ }
226
+ /**
227
+ * Unified interface for all @plyaz package errors
228
+ * THE single source of truth for error interfaces across all packages
229
+ *
230
+ * This interface should be implemented by:
231
+ * - BaseError in @plyaz/errors
232
+ * - ApiPackageError in @plyaz/api (extends BaseError)
233
+ * - NotificationPackageError in @plyaz/notifications (extends BaseError)
234
+ *
235
+ * Combines properties and methods from all error implementations
236
+ */
237
+ export interface PackageErrorLike extends Error {
238
+ /** Error code (unique identifier from ERROR_CODES) */
239
+ readonly errorCode: string;
240
+ /** Human-readable error message (for developers) */
241
+ readonly message: string;
242
+ /** ISO timestamp when error was created */
243
+ readonly timestamp: string;
244
+ /** Error category (from ERROR_CATEGORY) */
245
+ readonly category: (typeof ERROR_CATEGORY)[keyof typeof ERROR_CATEGORY];
246
+ /** Error severity level (from ERROR_SEVERITY) */
247
+ readonly severity?: (typeof ERROR_SEVERITY)[keyof typeof ERROR_SEVERITY];
248
+ /** Whether this error is retryable */
249
+ readonly retryable?: boolean;
250
+ /** Original error that caused this error */
251
+ readonly cause?: Error;
252
+ /** Alias for cause (for compatibility) */
253
+ readonly originalError?: Error;
254
+ /** Contextual information about the error */
255
+ readonly context?: BaseErrorContext;
256
+ /** Additional metadata (JSON-serializable) */
257
+ readonly metadata?: Record<string, string | number | boolean | null>;
258
+ /** Correlation ID for request tracking */
259
+ readonly correlationId?: string;
260
+ /** Trace ID for distributed tracing */
261
+ readonly traceId?: string;
262
+ /** HTTP status code (used by API and base errors) */
263
+ readonly statusCode?: number;
264
+ /** Validation error details (used by API errors) */
265
+ readonly errors?: ErrorDetail<unknown, unknown, unknown>[];
266
+ /** Alias for errors (for compatibility) */
267
+ readonly details?: ErrorDetail<unknown, unknown, unknown>[];
268
+ /** Error type (alternative name for errorCode in BaseError) */
269
+ readonly type?: string;
270
+ /** Getter for code property (alias for errorCode) */
271
+ readonly code: string;
272
+ /** Check if this is a validation error */
273
+ isValidationError(): boolean;
274
+ /** Check if this is a network error */
275
+ isNetworkError(): boolean;
276
+ /** Check if this error is retryable */
277
+ isRetryable(): boolean;
278
+ /** Check if this is an authentication error */
279
+ isAuthError?(): boolean;
280
+ /** Check if this is a server error */
281
+ isServerError?(): boolean;
282
+ /** Check if this is a client error */
283
+ isClientError?(): boolean;
284
+ /** Check if this is a provider error (notifications) */
285
+ isProviderError?(): boolean;
286
+ /** Check if this is a template error (notifications) */
287
+ isTemplateError?(): boolean;
288
+ /** Check if this is a rate limit error */
289
+ isRateLimitError?(): boolean;
290
+ /** Check if this is a queue error (notifications) */
291
+ isQueueError?(): boolean;
292
+ /** Check if this is a webhook error (notifications) */
293
+ isWebhookError?(): boolean;
294
+ /** Check if this is a configuration error */
295
+ isConfigurationError?(): boolean;
296
+ /** Check if this is a timeout error */
297
+ isTimeoutError?(): boolean;
298
+ /** Check if this is a not found error */
299
+ isNotFoundError?(): boolean;
300
+ /** Check if this is a conflict error */
301
+ isConflictError?(): boolean;
302
+ /** Convert error to ErrorResponse or JSON object for logging/API responses */
303
+ toJSON(): ErrorDetailsList | Record<string, unknown>;
304
+ /** Convert error to string representation */
305
+ toString(): string;
306
+ /** Get user-friendly message for display to end users */
307
+ getUserMessage(): string;
308
+ }
80
309
  export type AsyncMiddleware<TReturn = void> = (req: Request, res: Response, next: NextFunction) => Promise<TReturn>;
81
310
  export type MiddlewareWrapper = <TReturn>(fn: AsyncMiddleware<TReturn>) => (req: Request, res: Response, next: NextFunction) => Promise<void>;
311
+ /**
312
+ * ===== Error Event Handling =====
313
+ * Unified event handlers for all error categories across all packages
314
+ */
315
+ /**
316
+ * Event scope levels (uppercase format for @plyaz/errors)
317
+ * Each scope has different priority and lifecycle
318
+ *
319
+ * Scopes (in priority order):
320
+ * - GLOBAL: Application-wide handlers, persist across all requests
321
+ * - CONFIG: Configuration-level handlers, scoped to configuration instances
322
+ * - CLIENT: Client instance handlers, scoped to client lifecycle
323
+ * - REQUEST: Request-specific handlers, scoped to individual requests (highest priority)
324
+ * - TEMPORARY: Alias for REQUEST scope, automatically mapped to REQUEST for emission
325
+ *
326
+ * Note: TEMPORARY and REQUEST are functionally equivalent.
327
+ * TEMPORARY exists for semantic clarity when registering one-time handlers.
328
+ * When emitting events, TEMPORARY scope is automatically treated as REQUEST scope.
329
+ */
330
+ export type EventScope = 'GLOBAL' | 'CONFIG' | 'CLIENT' | 'REQUEST' | 'TEMPORARY';
331
+ /**
332
+ * Handler strategy for managing multiple handlers
333
+ * - merge: Add to existing handlers without duplicates (default)
334
+ * - replace: Replace all existing handlers with new ones
335
+ * - prepend: Add new handlers before existing ones
336
+ * - append: Add new handlers after existing ones
337
+ */
338
+ export type HandlerStrategy = 'merge' | 'replace' | 'prepend' | 'append';
339
+ /**
340
+ * Generic error event handler function
341
+ * Supports both synchronous and asynchronous handlers
342
+ * Can be a single function or an array of functions
343
+ */
344
+ export type ErrorEventHandler<TError = PackageErrorLike> = ((error: TError) => void | Promise<void>) | Array<(error: TError) => void | Promise<void>>;
345
+ /**
346
+ * Error event handlers interface
347
+ * Maps error categories to their handler functions (single or arrays)
348
+ * Used by event emitters in all @plyaz packages (api, notifications, errors, etc.)
349
+ *
350
+ * @template TError - The error type (defaults to PackageErrorLike)
351
+ *
352
+ * @example
353
+ * ```typescript
354
+ * const handlers: ErrorEventHandlers = {
355
+ * onValidationError: (error) => console.error('Validation failed:', error),
356
+ * onProviderError: [(error) => logger.error('Provider error:', error), (error) => metrics.track(error)],
357
+ * onAnyError: (error) => metrics.track('error', error)
358
+ * };
359
+ * ```
360
+ */
361
+ export interface ErrorEventHandlers<TError = PackageErrorLike> {
362
+ onError?: ErrorEventHandler<TError>;
363
+ onValidationError?: ErrorEventHandler<TError>;
364
+ onNetworkError?: ErrorEventHandler<TError>;
365
+ onAuthenticationError?: ErrorEventHandler<TError>;
366
+ onAuthorizationError?: ErrorEventHandler<TError>;
367
+ onRateLimitError?: ErrorEventHandler<TError>;
368
+ onTimeoutError?: ErrorEventHandler<TError>;
369
+ onNotFoundError?: ErrorEventHandler<TError>;
370
+ onConflictError?: ErrorEventHandler<TError>;
371
+ onServerError?: ErrorEventHandler<TError>;
372
+ onClientError?: ErrorEventHandler<TError>;
373
+ onExternalServiceError?: ErrorEventHandler<TError>;
374
+ onCacheError?: ErrorEventHandler<TError>;
375
+ onHeadersError?: ErrorEventHandler<TError>;
376
+ onRetryError?: ErrorEventHandler<TError>;
377
+ onStrategyError?: ErrorEventHandler<TError>;
378
+ onRegionalError?: ErrorEventHandler<TError>;
379
+ onProviderError?: ErrorEventHandler<TError>;
380
+ onQueueError?: ErrorEventHandler<TError>;
381
+ onWebhookError?: ErrorEventHandler<TError>;
382
+ onTemplateError?: ErrorEventHandler<TError>;
383
+ onConfigurationError?: ErrorEventHandler<TError>;
384
+ onBlockchainError?: ErrorEventHandler<TError>;
385
+ onUnknownError?: ErrorEventHandler<TError>;
386
+ onAnyError?: ErrorEventHandler<TError>;
387
+ }
388
+ /**
389
+ * Options for error handler registration
390
+ * Used when registering error handlers with different scopes and strategies
391
+ *
392
+ * @template TError - The error type (defaults to PackageErrorLike)
393
+ *
394
+ * @example
395
+ * ```typescript
396
+ * errorEmitter.on({
397
+ * onValidationError: handleValidation,
398
+ * }, {
399
+ * scope: 'REQUEST',
400
+ * strategy: 'prepend'
401
+ * });
402
+ * ```
403
+ */
404
+ export interface ErrorHandlerOptions<TError = PackageErrorLike> {
405
+ /**
406
+ * The scope level for the handler
407
+ * - GLOBAL: Applies to all errors across the application
408
+ * - CONFIG: Applies to errors in a specific configuration
409
+ * - CLIENT: Applies to errors in a specific client instance
410
+ * - REQUEST: Applies only to a specific request
411
+ * - TEMPORARY: Temporary handler that can be removed
412
+ *
413
+ * @default 'GLOBAL'
414
+ */
415
+ scope?: EventScope;
416
+ /**
417
+ * Strategy for handling multiple handlers
418
+ * - merge: Add to existing handlers (default)
419
+ * - replace: Replace existing handlers for this event type
420
+ * - prepend: Add new handlers before existing ones
421
+ * - append: Add new handlers after existing ones
422
+ *
423
+ * @default 'merge'
424
+ */
425
+ strategy?: HandlerStrategy;
426
+ /**
427
+ * Original unwrapped handler (before any transformations)
428
+ * Used internally to track the original handler for removal
429
+ */
430
+ originalHandler?: (data: TError) => void | Promise<void>;
431
+ }
432
+ /**
433
+ * Generic event factory interface
434
+ * Packages must provide an implementation that follows this interface
435
+ * Used by @plyaz/errors to abstract event handling across different packages
436
+ */
437
+ export interface ErrorEventFactory {
438
+ /**
439
+ * Add a scoped handler for an event
440
+ * @param scope - Event scope (GLOBAL, CONFIG, CLIENT, REQUEST, TEMPORARY)
441
+ * @param eventName - Event name (e.g., 'validation', 'network', '*')
442
+ * @param handler - Event handler function
443
+ * @param options - Handler options (strategy, originalHandler)
444
+ */
445
+ addScopedHandler<T = PackageErrorLike>(scope: EventScope, eventName: string, handler: (data: T) => void, options?: ErrorHandlerOptions<T>): void;
446
+ /**
447
+ * Remove a scoped handler
448
+ * @param scope - Event scope
449
+ * @param eventName - Event name
450
+ * @param handler - Optional specific handler to remove (if not provided, removes all handlers)
451
+ */
452
+ removeScopedHandler<T = PackageErrorLike>(scope: EventScope, eventName: string, handler?: (data: T) => void): void;
453
+ /**
454
+ * Get original handlers for a scope (before wrapping)
455
+ * @param scope - Event scope
456
+ * @returns Map of event names to handler arrays
457
+ */
458
+ getOriginalScopedHandlers<T = PackageErrorLike>(scope: EventScope): Map<string, Array<(data: T) => void>>;
459
+ /**
460
+ * Emit an error event with scoping
461
+ * @param eventName - Event name
462
+ * @param data - Event data
463
+ * @param options - Emission options (scopes to emit to)
464
+ */
465
+ emit<T = PackageErrorLike>(eventName: string, data: T, options?: {
466
+ scopes?: EventScope[];
467
+ }): void;
468
+ }
469
+ /**
470
+ * Scoped error emitter options
471
+ * Extends ErrorHandlerOptions with event factory override
472
+ */
473
+ export interface ScopedErrorEmitterOptions extends ErrorHandlerOptions {
474
+ /**
475
+ * Custom event factory to use
476
+ * If not provided, will use the global/default factory
477
+ */
478
+ eventFactory?: ErrorEventFactory;
479
+ }
480
+ /**
481
+ * Type for error event emitter function
482
+ * Packages can implement this to emit events when errors are created
483
+ */
484
+ export type ErrorEventEmitter = (error: PackageErrorLike) => void | Promise<void>;
485
+ /**
486
+ * ===== API Package Error Types =====
487
+ */
488
+ /**
489
+ * Generic API error detail
490
+ * Extends base ErrorDetail with required errorCode
491
+ * @template ValueGiven - Type of the value that caused the error
492
+ * @template AllowedValues - Type of acceptable values for the field
493
+ * @template Constraints - Type of validation constraints
494
+ * @template Context - Type of additional error context (key-value pairs)
495
+ */
496
+ export interface ApiErrorDetail<ValueGiven = unknown, AllowedValues = unknown, Constraints = unknown, Context extends Record<string, unknown> = Record<string, unknown>> {
497
+ /** Application-specific error code */
498
+ errorCode: string;
499
+ /** Human-readable error message */
500
+ message: string;
501
+ /** The field that caused the error (optional) */
502
+ field?: string;
503
+ /** The value that was provided (optional) */
504
+ value?: ValueGiven;
505
+ /** Allowed values for the field (optional) */
506
+ allowedValues?: AllowedValues;
507
+ /** Validation constraints (optional) */
508
+ constraints?: Constraints;
509
+ /** Additional error context (optional) */
510
+ context?: Context;
511
+ }
512
+ /**
513
+ * Generic API package error options
514
+ */
515
+ export interface ApiPackageErrorOptions<TEndpoints = unknown, TClient = ApiClientInstance<TEndpoints>> {
516
+ /** Error details (validation errors, etc.) */
517
+ errors?: ApiErrorDetail[];
518
+ /** Correlation ID for tracking */
519
+ correlationId?: string;
520
+ /** Original HTTP response error (from fetchff or similar) */
521
+ responseError?: unknown;
522
+ /** Cause error */
523
+ cause?: Error;
524
+ /** Error context */
525
+ context?: BaseErrorContext;
526
+ /** Client context (generic) */
527
+ clientContext?: TClient;
528
+ /** Additional metadata */
529
+ metadata?: Record<string, string | number | boolean | null>;
530
+ }
531
+ /**
532
+ * Configuration for ApiPackageError class
533
+ */
534
+ export interface ApiPackageErrorConfig {
535
+ /** Package namespace for event emission */
536
+ namespace?: string;
537
+ /** Event factory for scoped events */
538
+ eventFactory?: ErrorEventFactory;
539
+ /** Correlation ID generator */
540
+ correlationIdGenerator?: () => string;
541
+ }
542
+ /**
543
+ * ===== Error System Configuration =====
544
+ */
545
+ /**
546
+ * Translation message catalog
547
+ * Nested structure for i18n messages
548
+ */
549
+ export interface MessageCatalog {
550
+ [key: string]: string | MessageCatalog;
551
+ }
552
+ /**
553
+ * Message translator configuration
554
+ */
555
+ export interface TranslatorConfig {
556
+ /** Default locale to use */
557
+ defaultLocale: string;
558
+ /** Fallback locale if key not found */
559
+ fallbackLocale?: string;
560
+ /** Message catalogs by locale */
561
+ catalogs: Record<string, MessageCatalog>;
562
+ }
563
+ /**
564
+ * Error system initialization options
565
+ */
566
+ export interface ErrorSystemConfig {
567
+ /**
568
+ * Default locale to use for error messages
569
+ * @default 'en'
570
+ */
571
+ defaultLocale?: string;
572
+ /**
573
+ * Fallback locale if translation not found
574
+ * @default 'en'
575
+ */
576
+ fallbackLocale?: string;
577
+ /**
578
+ * Additional message catalogs to merge with built-in messages
579
+ * Useful for adding package-specific or custom error messages
580
+ */
581
+ additionalCatalogs?: Record<string, MessageCatalog>;
582
+ /**
583
+ * Replace built-in catalogs entirely (use with caution)
584
+ * If true, only additionalCatalogs will be used
585
+ * @default false
586
+ */
587
+ replaceBuiltIn?: boolean;
588
+ }
589
+ /**
590
+ * ===== Centralized Type Aliases =====
591
+ * Single source of truth for commonly used type aliases across all @plyaz packages
592
+ */
593
+ /**
594
+ * Type alias for error category values
595
+ * Represents a single category value from ERROR_CATEGORY
596
+ *
597
+ * @example
598
+ * ```typescript
599
+ * const category: ErrorCategoryValue = ERROR_CATEGORY.Network; // 'network'
600
+ * const isValid: ErrorCategoryValue = 'authentication'; // valid
601
+ * ```
602
+ */
603
+ export type ErrorCategoryValue = (typeof ERROR_CATEGORY)[keyof typeof ERROR_CATEGORY];
604
+ /**
605
+ * Type alias for error severity values
606
+ * Represents a single severity value from ERROR_SEVERITY
607
+ *
608
+ * @example
609
+ * ```typescript
610
+ * const severity: ErrorSeverityValue = ERROR_SEVERITY.High; // 'high'
611
+ * ```
612
+ */
613
+ export type ErrorSeverityValue = (typeof ERROR_SEVERITY)[keyof typeof ERROR_SEVERITY];
614
+ /**
615
+ * Type alias for common operation values
616
+ * Can be any string, but COMMON_OPERATIONS provides suggested values
617
+ *
618
+ * @example
619
+ * ```typescript
620
+ * import { COMMON_OPERATIONS } from '@plyaz/types';
621
+ *
622
+ * const op1: CommonOperation = COMMON_OPERATIONS.STORAGE;
623
+ * const op2: CommonOperation = 'custom-operation'; // Also valid
624
+ * ```
625
+ */
626
+ export type CommonOperation = (typeof COMMON_OPERATIONS)[keyof typeof COMMON_OPERATIONS] | string;
627
+ /**
628
+ * Type alias for common field values
629
+ * Can be any string, but COMMON_FIELDS provides suggested values
630
+ *
631
+ * @example
632
+ * ```typescript
633
+ * import { COMMON_FIELDS } from '@plyaz/types';
634
+ *
635
+ * const field1: CommonField = COMMON_FIELDS.EMAIL;
636
+ * const field2: CommonField = 'customField'; // Also valid
637
+ * ```
638
+ */
639
+ export type CommonField = (typeof COMMON_FIELDS)[keyof typeof COMMON_FIELDS] | string;
640
+ /**
641
+ * Type alias for common storage type values
642
+ * Can be any string, but COMMON_STORAGE_TYPES provides suggested values
643
+ *
644
+ * @example
645
+ * ```typescript
646
+ * import { COMMON_STORAGE_TYPES } from '@plyaz/types';
647
+ *
648
+ * const storage1: CommonStorageType = COMMON_STORAGE_TYPES.REDIS;
649
+ * const storage2: CommonStorageType = 'custom-storage'; // Also valid
650
+ * ```
651
+ */
652
+ export type CommonStorageType = (typeof COMMON_STORAGE_TYPES)[keyof typeof COMMON_STORAGE_TYPES] | string;
653
+ /**
654
+ * ===== Status Code Type Aliases =====
655
+ */
656
+ /**
657
+ * Type alias for internal package status codes (1xxx range)
658
+ * Custom internal status codes that don't map to HTTP status codes
659
+ *
660
+ * @example
661
+ * ```typescript
662
+ * import { INTERNAL_STATUS_CODES } from '@plyaz/types/errors';
663
+ *
664
+ * const statusCode: InternalStatusCodeValue = INTERNAL_STATUS_CODES.INVALID_CONFIGURATION; // 1001
665
+ * ```
666
+ */
667
+ export type InternalStatusCodeValue = (typeof INTERNAL_STATUS_CODES)[keyof typeof INTERNAL_STATUS_CODES];
668
+ /**
669
+ * Type alias for all status codes (HTTP + internal)
670
+ * Combines HTTP status codes (200-599) and internal package status codes (1xxx)
671
+ *
672
+ * @example
673
+ * ```typescript
674
+ * const httpStatus: StatusCodeValue = 404;
675
+ * const internalStatus: StatusCodeValue = 1001;
676
+ * ```
677
+ */
678
+ export type StatusCodeValue = number | InternalStatusCodeValue;
679
+ /**
680
+ * ===== I18n Support =====
681
+ */
682
+ /**
683
+ * Translation interpolation variables
684
+ * Used for i18n error message interpolation
685
+ *
686
+ * @example
687
+ * ```typescript
688
+ * const i18n: I18nContext = {
689
+ * count: 5,
690
+ * max: 10,
691
+ * fieldName: 'email'
692
+ * };
693
+ * ```
694
+ */
695
+ export interface I18nContext {
696
+ [key: string]: string | number | boolean | null | undefined;
697
+ }