@plyaz/types 1.7.28 → 1.7.29

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.
@@ -180,3 +180,35 @@ export declare const PACKAGE_STATUS_CODES: {
180
180
  * Maps error codes to their HTTP status and metadata
181
181
  */
182
182
  export declare const ERROR_DEFINITIONS: ErrorDefinitions;
183
+ /**
184
+ * Mapping of error category values to camelCase emitter keys
185
+ * Used by the event system to route errors to appropriate handlers
186
+ *
187
+ * @example
188
+ * ```typescript
189
+ * import { ERROR_CATEGORY, ERROR_CATEGORY_TO_EMITTER_KEY } from '@plyaz/types/api';
190
+ *
191
+ * const category = ERROR_CATEGORY.RateLimit; // 'rate.limit'
192
+ * const emitterKey = ERROR_CATEGORY_TO_EMITTER_KEY[category]; // 'rateLimit'
193
+ * ```
194
+ */
195
+ export declare const ERROR_CATEGORY_TO_EMITTER_KEY: {
196
+ readonly network: "network";
197
+ readonly validation: "validation";
198
+ readonly authentication: "authentication";
199
+ readonly "rate.limit": "rateLimit";
200
+ readonly server: "server";
201
+ readonly timeout: "timeout";
202
+ readonly authorization: "authorization";
203
+ readonly "not.found": "notFound";
204
+ readonly conflict: "conflict";
205
+ readonly client: "client";
206
+ readonly "external.service": "externalService";
207
+ readonly cache: "cache";
208
+ readonly headers: "headers";
209
+ readonly retry: "retry";
210
+ readonly blockchain: "blockchain";
211
+ readonly strategy: "strategy";
212
+ readonly regional: "regional";
213
+ readonly unknown: "unknown";
214
+ };
@@ -8,6 +8,8 @@
8
8
  import type { ResponseError, RequestConfig } from 'fetchff';
9
9
  import type { ERROR_CATEGORY, ErrorDetail, ErrorResponse } from '../../errors';
10
10
  import type { API_ERROR_CODES, OPERATIONS, ERROR_FIELDS, STORAGE_TYPES, ApiClientInstance } from '..';
11
+ import type { PACKAGE_STATUS_CODES } from './enum';
12
+ import type { HTTP_STATUS } from '@plyaz/config';
11
13
  /**
12
14
  * Typed constants as types for convenience
13
15
  */
@@ -18,6 +20,58 @@ export type StorageType = (typeof STORAGE_TYPES)[keyof typeof STORAGE_TYPES];
18
20
  * Type for API error codes
19
21
  */
20
22
  export type ApiErrorCode = (typeof API_ERROR_CODES)[keyof typeof API_ERROR_CODES];
23
+ /**
24
+ * Type alias for error category values
25
+ * Represents a single category value from ERROR_CATEGORY
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * const category: ErrorCategoryValue = ERROR_CATEGORY.Network; // 'network'
30
+ * const isValid: ErrorCategoryValue = 'authentication'; // valid
31
+ * ```
32
+ */
33
+ export type ErrorCategoryValue = (typeof ERROR_CATEGORY)[keyof typeof ERROR_CATEGORY];
34
+ /**
35
+ * Type alias for API error code values
36
+ * Use this instead of repeating the verbose (typeof API_ERROR_CODES)[keyof typeof API_ERROR_CODES]
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * const code: ApiErrorCodeValue = API_ERROR_CODES.NETWORK_ERROR;
41
+ * ```
42
+ */
43
+ export type ApiErrorCodeValue = (typeof API_ERROR_CODES)[keyof typeof API_ERROR_CODES];
44
+ /**
45
+ * Type alias for package-specific status code values
46
+ * Custom status codes specific to @plyaz/api package (1xxx range)
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * const statusCode: PackageStatusCodeValue = PACKAGE_STATUS_CODES.CLIENT_CANCELLED; // 1001
51
+ * ```
52
+ */
53
+ export type PackageStatusCodeValue = (typeof PACKAGE_STATUS_CODES)[keyof typeof PACKAGE_STATUS_CODES];
54
+ /**
55
+ * Type alias for HTTP status code values
56
+ * Standard HTTP status codes from @plyaz/config
57
+ *
58
+ * @example
59
+ * ```typescript
60
+ * const statusCode: HttpStatusCodeValue = HTTP_STATUS.NOT_FOUND; // 404
61
+ * ```
62
+ */
63
+ export type HttpStatusCodeValue = (typeof HTTP_STATUS)[keyof typeof HTTP_STATUS];
64
+ /**
65
+ * Union type for all valid status codes
66
+ * Combines both HTTP status codes and package-specific status codes
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * const httpCode: StatusCodeValue = HTTP_STATUS.BAD_REQUEST; // 400
71
+ * const customCode: StatusCodeValue = PACKAGE_STATUS_CODES.CLIENT_CANCELLED; // 1001
72
+ * ```
73
+ */
74
+ export type StatusCodeValue = PackageStatusCodeValue | HttpStatusCodeValue;
21
75
  /**
22
76
  * Translation interpolation variables
23
77
  */
@@ -157,14 +211,14 @@ export interface ApiPackageErrorOptionsErrorDetail<ValueGiven, AllowedValues, Co
157
211
  * ```
158
212
  */
159
213
  export interface ApiPackageErrorLike extends Error {
160
- readonly statusCode: number;
161
- readonly errorCode: string;
214
+ readonly statusCode: StatusCodeValue;
215
+ readonly errorCode: ApiErrorCodeValue;
162
216
  readonly message: string;
163
217
  readonly errors?: ErrorDetail<unknown, unknown, unknown>[];
164
218
  readonly correlationId?: string;
165
219
  readonly timestamp: string;
166
220
  readonly responseError?: ResponseError;
167
- readonly category: typeof ERROR_CATEGORY;
221
+ readonly category: ErrorCategoryValue;
168
222
  readonly cause?: Error;
169
223
  readonly context?: ErrorContext;
170
224
  readonly requestConfig?: RequestConfig;
@@ -20,7 +20,7 @@ export interface GenericErrorEvent extends BaseEvent {
20
20
  type: typeof ERROR_EVENTS.GENERIC_ERROR;
21
21
  data: {
22
22
  error: ApiPackageErrorLike;
23
- category: typeof ERROR_CATEGORY | string;
23
+ category: (typeof ERROR_CATEGORY)[keyof typeof ERROR_CATEGORY] | string;
24
24
  code: string;
25
25
  message: string;
26
26
  context?: Record<string, unknown>;
@@ -177,6 +177,8 @@ var ERROR_CATEGORY = {
177
177
  Server: "server",
178
178
  /** Network-related error (e.g., unreachable endpoint). */
179
179
  Network: "network",
180
+ /** Blockchain-related error (e.g., transaction failure, gas limit). */
181
+ Blockchain: "blockchain",
180
182
  /** Validation-specific error (e.g., failed constraints or field errors). */
181
183
  Validation: "validation",
182
184
  /** Authentication-related error (e.g., invalid credentials, expired token). */
@@ -191,6 +193,8 @@ var ERROR_CATEGORY = {
191
193
  ExternalService: "external.service",
192
194
  /** Timeout error (request exceeded time limit). */
193
195
  Timeout: "timeout",
196
+ /** Conflict error (e.g., resource state conflict). */
197
+ Conflict: "conflict",
194
198
  /** Cache-related error. */
195
199
  Cache: "cache",
196
200
  /** Headers-related error (e.g., missing or invalid headers). */
@@ -673,6 +677,26 @@ var ERROR_DEFINITIONS = {
673
677
  category: ERROR_CATEGORY.Unknown
674
678
  }
675
679
  };
680
+ var ERROR_CATEGORY_TO_EMITTER_KEY = {
681
+ [ERROR_CATEGORY.Network]: "network",
682
+ [ERROR_CATEGORY.Validation]: "validation",
683
+ [ERROR_CATEGORY.Authentication]: "authentication",
684
+ [ERROR_CATEGORY.RateLimit]: "rateLimit",
685
+ [ERROR_CATEGORY.Server]: "server",
686
+ [ERROR_CATEGORY.Timeout]: "timeout",
687
+ [ERROR_CATEGORY.Authorization]: "authorization",
688
+ [ERROR_CATEGORY.NotFound]: "notFound",
689
+ [ERROR_CATEGORY.Conflict]: "conflict",
690
+ [ERROR_CATEGORY.Client]: "client",
691
+ [ERROR_CATEGORY.ExternalService]: "externalService",
692
+ [ERROR_CATEGORY.Cache]: "cache",
693
+ [ERROR_CATEGORY.Headers]: "headers",
694
+ [ERROR_CATEGORY.Retry]: "retry",
695
+ [ERROR_CATEGORY.Blockchain]: "blockchain",
696
+ [ERROR_CATEGORY.Strategy]: "strategy",
697
+ [ERROR_CATEGORY.Regional]: "regional",
698
+ [ERROR_CATEGORY.Unknown]: "unknown"
699
+ };
676
700
 
677
701
  // src/api/queue/enums.ts
678
702
  var PRIORITY_LEVEL = {
@@ -995,6 +1019,7 @@ exports.DATA_SAVER_PRESETS = DATA_SAVER_PRESETS;
995
1019
  exports.DEBUGGER_CONFIG_SOURCES = DEBUGGER_CONFIG_SOURCES;
996
1020
  exports.DEBUG_EVENTS = DEBUG_EVENTS;
997
1021
  exports.DEFAULT_THRESHOLDS = DEFAULT_THRESHOLDS;
1022
+ exports.ERROR_CATEGORY_TO_EMITTER_KEY = ERROR_CATEGORY_TO_EMITTER_KEY;
998
1023
  exports.ERROR_DEFINITIONS = ERROR_DEFINITIONS;
999
1024
  exports.ERROR_EVENTS = ERROR_EVENTS;
1000
1025
  exports.ERROR_FIELDS = ERROR_FIELDS;