@plyaz/types 1.7.17 → 1.7.19

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 (73) hide show
  1. package/dist/api/client/enum.d.ts +12 -0
  2. package/dist/api/client/index.d.ts +1 -0
  3. package/dist/api/client/types.d.ts +114 -0
  4. package/dist/api/config/types.d.ts +56 -8
  5. package/dist/api/debugger/enums.d.ts +152 -0
  6. package/dist/api/debugger/factories/index.d.ts +1 -0
  7. package/dist/api/debugger/factories/types.d.ts +191 -0
  8. package/dist/api/debugger/index.d.ts +2 -0
  9. package/dist/api/debugger/types.d.ts +664 -0
  10. package/dist/api/endpoints/campaigns/index.d.ts +1 -0
  11. package/dist/api/endpoints/campaigns/types.d.ts +68 -0
  12. package/dist/api/endpoints/health/index.d.ts +1 -0
  13. package/dist/api/endpoints/health/types.d.ts +127 -0
  14. package/dist/api/endpoints/index.d.ts +3 -0
  15. package/dist/api/endpoints/types.d.ts +5 -0
  16. package/dist/api/errors/enum.d.ts +182 -0
  17. package/dist/api/errors/index.d.ts +1 -0
  18. package/dist/api/errors/types.d.ts +125 -26
  19. package/dist/api/events/enum.d.ts +261 -0
  20. package/dist/api/events/factories/cache/index.d.ts +1 -0
  21. package/dist/api/events/factories/cache/types.d.ts +60 -0
  22. package/dist/api/events/factories/client/index.d.ts +1 -0
  23. package/dist/api/events/factories/client/types.d.ts +120 -0
  24. package/dist/api/events/factories/config/index.d.ts +1 -0
  25. package/dist/api/events/factories/config/types.d.ts +79 -0
  26. package/dist/api/events/factories/debug/index.d.ts +1 -0
  27. package/dist/api/events/factories/debug/types.d.ts +130 -0
  28. package/dist/api/events/factories/errors/index.d.ts +1 -0
  29. package/dist/api/events/factories/errors/types.d.ts +293 -0
  30. package/dist/api/events/factories/headers/index.d.ts +1 -0
  31. package/dist/api/events/factories/headers/types.d.ts +256 -0
  32. package/dist/api/events/factories/index.d.ts +9 -0
  33. package/dist/api/events/factories/network/index.d.ts +1 -0
  34. package/dist/api/events/factories/network/types.d.ts +196 -0
  35. package/dist/api/events/factories/performance/index.d.ts +1 -0
  36. package/dist/api/events/factories/performance/types.d.ts +150 -0
  37. package/dist/api/events/factories/types.d.ts +84 -0
  38. package/dist/api/events/index.d.ts +2 -0
  39. package/dist/api/events/types.d.ts +4 -657
  40. package/dist/api/headers/enum.d.ts +34 -0
  41. package/dist/api/headers/index.d.ts +1 -0
  42. package/dist/api/headers/types.d.ts +456 -0
  43. package/dist/api/hooks/index.d.ts +1 -0
  44. package/dist/api/hooks/types.d.ts +131 -0
  45. package/dist/api/index.d.ts +6 -1
  46. package/dist/api/network/enums.d.ts +75 -5
  47. package/dist/api/network/frameworks/index.d.ts +2 -0
  48. package/dist/api/network/frameworks/nestjs/index.d.ts +1 -0
  49. package/dist/api/network/frameworks/nestjs/types.d.ts +47 -0
  50. package/dist/api/network/frameworks/types.d.ts +76 -0
  51. package/dist/api/network/index.d.ts +1 -0
  52. package/dist/api/network/types.d.ts +347 -39
  53. package/dist/api/performance/types.d.ts +17 -10
  54. package/dist/api/polling/types.d.ts +1 -1
  55. package/dist/api/pubsub/enum.d.ts +12 -0
  56. package/dist/api/pubsub/index.d.ts +2 -0
  57. package/dist/api/pubsub/types.d.ts +61 -0
  58. package/dist/api/queue/types.d.ts +69 -0
  59. package/dist/api/regional/enum.d.ts +75 -0
  60. package/dist/api/regional/index.d.ts +1 -0
  61. package/dist/api/regional/types.d.ts +2 -1
  62. package/dist/api/request/index.d.ts +1 -0
  63. package/dist/api/request/types.d.ts +44 -0
  64. package/dist/api/retry/types.d.ts +31 -0
  65. package/dist/api/strategies/types.d.ts +12 -8
  66. package/dist/errors/index.cjs +69 -0
  67. package/dist/errors/index.cjs.map +1 -1
  68. package/dist/errors/index.d.ts +1 -1
  69. package/dist/errors/index.js +66 -0
  70. package/dist/errors/index.js.map +1 -1
  71. package/dist/features/cache/types.d.ts +5 -0
  72. package/dist/testing/features/api/types.d.ts +355 -4
  73. package/package.json +5 -3
@@ -0,0 +1,68 @@
1
+ import type { Endpoint, Req } from 'fetchff';
2
+ interface Campaign {
3
+ id: string;
4
+ name: string;
5
+ description: string;
6
+ status: 'draft' | 'active' | 'paused' | 'completed';
7
+ startDate: string;
8
+ endDate: string;
9
+ athleteIds: string[];
10
+ createdAt: string;
11
+ updatedAt: string;
12
+ }
13
+ interface CampaignStats {
14
+ totalParticipants: number;
15
+ totalViews: number;
16
+ engagement: number;
17
+ performance: Record<string, unknown>;
18
+ }
19
+ interface CampaignListParams {
20
+ limit?: number;
21
+ offset?: number;
22
+ status?: Campaign['status'];
23
+ athleteId?: string;
24
+ }
25
+ interface CampaignCreateBody {
26
+ name: string;
27
+ description: string;
28
+ startDate: string;
29
+ endDate: string;
30
+ athleteIds?: string[];
31
+ }
32
+ interface CampaignUpdateBody {
33
+ name?: string;
34
+ description?: string;
35
+ status?: Campaign['status'];
36
+ startDate?: string;
37
+ endDate?: string;
38
+ }
39
+ interface CampaignPathParams {
40
+ id: string;
41
+ }
42
+ interface JoinCampaignBody {
43
+ athleteId: string;
44
+ }
45
+ /**
46
+ * Campaign endpoint types for TypeScript
47
+ * Using fetchff's Req type to properly define endpoints
48
+ */
49
+ export interface CampaignEndpointTypes {
50
+ getCampaign: Endpoint<Req<Campaign, never, never, CampaignPathParams>>;
51
+ listCampaigns: Endpoint<Req<Campaign[], never, CampaignListParams>>;
52
+ createCampaign: Endpoint<Req<Campaign, CampaignCreateBody>>;
53
+ updateCampaign: Endpoint<Req<Campaign, CampaignUpdateBody, never, CampaignPathParams>>;
54
+ deleteCampaign: Endpoint<Req<{
55
+ success: boolean;
56
+ }, never, never, CampaignPathParams>>;
57
+ getCampaignStats: Endpoint<Req<CampaignStats, never, never, CampaignPathParams>>;
58
+ getCampaignParticipants: Endpoint<Req<{
59
+ athleteIds: string[];
60
+ }, never, never, CampaignPathParams>>;
61
+ joinCampaign: Endpoint<Req<{
62
+ success: boolean;
63
+ }, JoinCampaignBody, never, CampaignPathParams>>;
64
+ leaveCampaign: Endpoint<Req<{
65
+ success: boolean;
66
+ }, JoinCampaignBody, never, CampaignPathParams>>;
67
+ }
68
+ export {};
@@ -0,0 +1 @@
1
+ export type * from './types';
@@ -0,0 +1,127 @@
1
+ import type { Endpoint, Req } from 'fetchff';
2
+ /**
3
+ * Job Status Response
4
+ * Used by endpoints that monitor job/task progress
5
+ */
6
+ interface JobStatusResponse {
7
+ jobId: string;
8
+ status: 'pending' | 'running' | 'completed' | 'failed' | 'cancelled';
9
+ progress?: number;
10
+ message?: string;
11
+ result?: unknown;
12
+ error?: string;
13
+ startedAt?: string;
14
+ completedAt?: string;
15
+ }
16
+ /**
17
+ * Health Check Response
18
+ * Used by health monitoring endpoints
19
+ */
20
+ interface HealthCheckResponse {
21
+ status: 'up' | 'down' | 'degraded';
22
+ healthy: boolean;
23
+ version: string;
24
+ uptime: number;
25
+ services: {
26
+ database: boolean;
27
+ cache: boolean;
28
+ queue: boolean;
29
+ };
30
+ }
31
+ /**
32
+ * Live Data Response
33
+ * Used by real-time data endpoints
34
+ */
35
+ interface LiveDataResponse<T = unknown> {
36
+ data: T;
37
+ timestamp: string;
38
+ noUpdates?: boolean;
39
+ lastUpdateId?: string;
40
+ }
41
+ /**
42
+ * Data Sync Response
43
+ * Used by data synchronization endpoints
44
+ */
45
+ interface DataSyncResponse {
46
+ syncId: string;
47
+ status: 'pending' | 'syncing' | 'completed' | 'failed';
48
+ syncComplete?: boolean;
49
+ hasConflicts?: boolean;
50
+ conflictCount?: number;
51
+ itemsSynced?: number;
52
+ totalItems?: number;
53
+ }
54
+ /**
55
+ * Resource Status Response
56
+ * Used by resource availability endpoints
57
+ */
58
+ interface ResourceStatusResponse {
59
+ resourceId: string;
60
+ available: boolean;
61
+ status: 'preparing' | 'ready' | 'busy' | 'unavailable';
62
+ estimatedAvailableAt?: string;
63
+ }
64
+ /**
65
+ * Path parameters for job endpoints
66
+ */
67
+ interface JobPathParams {
68
+ jobId: string;
69
+ }
70
+ /**
71
+ * Path parameters for resource endpoints
72
+ */
73
+ interface ResourcePathParams {
74
+ resourceId: string;
75
+ }
76
+ /**
77
+ * Query parameters for live data
78
+ */
79
+ interface LiveDataParams {
80
+ since?: string;
81
+ limit?: number;
82
+ }
83
+ /**
84
+ * Body for starting a job
85
+ */
86
+ interface StartJobBody {
87
+ type: string;
88
+ parameters?: Record<string, unknown>;
89
+ }
90
+ /**
91
+ * Body for sync operations
92
+ */
93
+ interface StartSyncBody {
94
+ source: string;
95
+ target: string;
96
+ options?: {
97
+ resolveConflicts?: 'source' | 'target' | 'manual';
98
+ dryRun?: boolean;
99
+ };
100
+ }
101
+ /**
102
+ * Polling example endpoint types with full TypeScript support
103
+ * These demonstrate how endpoints should be typed for polling scenarios
104
+ */
105
+ export interface PollingEndpointTypes {
106
+ getJobStatus: Endpoint<Req<JobStatusResponse, never, never, JobPathParams>>;
107
+ startJob: Endpoint<Req<JobStatusResponse, StartJobBody>>;
108
+ cancelJob: Endpoint<Req<{
109
+ success: boolean;
110
+ }, never, never, JobPathParams>>;
111
+ healthCheck: Endpoint<Req<HealthCheckResponse>>;
112
+ getLiveData: Endpoint<Req<LiveDataResponse, never, LiveDataParams>>;
113
+ getDashboardMetrics: Endpoint<Req<LiveDataResponse<{
114
+ activeUsers: number;
115
+ requests: number;
116
+ responseTime: number;
117
+ }>, never, LiveDataParams>>;
118
+ startSync: Endpoint<Req<DataSyncResponse, StartSyncBody>>;
119
+ getSyncStatus: Endpoint<Req<DataSyncResponse, never, never, {
120
+ syncId: string;
121
+ }>>;
122
+ getResourceStatus: Endpoint<Req<ResourceStatusResponse, never, never, ResourcePathParams>>;
123
+ reserveResource: Endpoint<Req<ResourceStatusResponse, {
124
+ duration: number;
125
+ }, never, ResourcePathParams>>;
126
+ }
127
+ export {};
@@ -0,0 +1,3 @@
1
+ export type * from './campaigns';
2
+ export type * from './health';
3
+ export type * from './types';
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Query parameters type - matches fetchff's flexible param handling
3
+ * Supports objects, URLSearchParams, and arrays of name-value pairs
4
+ */
5
+ export type QueryParams = Record<string, string | number | boolean | string[] | number[]> | URLSearchParams | Array<[string, string]>;
@@ -0,0 +1,182 @@
1
+ /**
2
+ * Typed constants for API error handling
3
+ */
4
+ import type { ErrorDefinitions } from '..';
5
+ /**
6
+ * Operation types for error context
7
+ */
8
+ export declare const OPERATIONS: {
9
+ readonly STORAGE: "storage";
10
+ readonly RETRIEVAL: "retrieval";
11
+ readonly INVALIDATION: "invalidation";
12
+ readonly ENRICHMENT: "enrichment";
13
+ readonly VALIDATION: "validation";
14
+ readonly PRESET_LOOKUP: "preset-lookup";
15
+ readonly INITIALIZATION: "initialization";
16
+ readonly CONFIGURATION: "configuration";
17
+ readonly REQUEST: "request";
18
+ readonly RESPONSE: "response";
19
+ readonly RETRY: "retry";
20
+ readonly REVALIDATION: "revalidation";
21
+ readonly STRATEGY_EXECUTION: "strategy-execution";
22
+ readonly POLLING: "polling";
23
+ readonly SUBSCRIPTION: "subscription";
24
+ readonly PUBLICATION: "publication";
25
+ readonly DEBUG: "debug";
26
+ readonly DEBUG_TRACKING: "debug-tracking";
27
+ readonly ENDPOINT_BUILD: "endpoint-build";
28
+ readonly TRACKING: "tracking";
29
+ readonly NETWORK_CHECK: "network-check";
30
+ readonly EVENT_HANDLING: "event-handling";
31
+ readonly SERIALIZATION: "serialization";
32
+ readonly DESERIALIZATION: "deserialization";
33
+ readonly REGIONAL_DETECTION: "regional-detection";
34
+ readonly MONITORING: "monitoring";
35
+ readonly CONTEXT_SETUP: "context-setup";
36
+ readonly FALLBACK: "fallback";
37
+ };
38
+ /**
39
+ * Field types for error context
40
+ */
41
+ export declare const ERROR_FIELDS: {
42
+ readonly STORAGE: "storage";
43
+ readonly CACHE: "cache";
44
+ readonly HEADERS: "headers";
45
+ readonly PRESET_NAME: "presetName";
46
+ readonly PRESET_ID: "presetId";
47
+ readonly CONFIG: "config";
48
+ readonly URL: "url";
49
+ readonly METHOD: "method";
50
+ readonly STRATEGY: "strategy";
51
+ readonly RETRY_COUNT: "retryCount";
52
+ readonly MAX_RETRIES: "maxRetries";
53
+ readonly POLLING_INTERVAL: "pollingInterval";
54
+ readonly TOPIC: "topic";
55
+ readonly CHANNEL: "channel";
56
+ readonly ENDPOINT: "endpoint";
57
+ readonly CLIENT: "client";
58
+ readonly NETWORK_TYPE: "networkType";
59
+ readonly TIME_INTERVAL: "timeInterval";
60
+ };
61
+ /**
62
+ * Storage types for API errors
63
+ */
64
+ export declare const STORAGE_TYPES: {
65
+ readonly PRIMARY: "primary";
66
+ readonly FALLBACK: "fallback";
67
+ readonly MEMORY: "memory";
68
+ readonly SESSION: "session";
69
+ readonly LOCAL: "local";
70
+ };
71
+ /**
72
+ * API Error Codes - domain-specific and grouped by category
73
+ */
74
+ export declare const API_ERROR_CODES: {
75
+ readonly CLIENT_INITIALIZATION_FAILED: "CLIENT_INITIALIZATION_FAILED";
76
+ readonly CLIENT_INVALID_CONFIG: "CLIENT_INVALID_CONFIG";
77
+ readonly CLIENT_MISSING_BASE_URL: "CLIENT_MISSING_BASE_URL";
78
+ readonly CLIENT_CANCELLED: "CLIENT_CANCELLED";
79
+ readonly CONFIG_VALIDATION_FAILED: "CONFIG_VALIDATION_FAILED";
80
+ readonly HEADER_PROCESSING_FAILED: "HEADER_PROCESSING_FAILED";
81
+ readonly NETWORK_OVERRIDE_FAILED: "NETWORK_OVERRIDE_FAILED";
82
+ readonly REQUEST_TIMEOUT: "REQUEST_TIMEOUT";
83
+ readonly REQUEST_ABORTED: "REQUEST_ABORTED";
84
+ readonly REQUEST_INVALID_PARAMS: "REQUEST_INVALID_PARAMS";
85
+ readonly REQUEST_PREPARATION_FAILED: "REQUEST_PREPARATION_FAILED";
86
+ readonly RESPONSE_INVALID_FORMAT: "RESPONSE_INVALID_FORMAT";
87
+ readonly RESPONSE_PARSING_FAILED: "RESPONSE_PARSING_FAILED";
88
+ readonly NETWORK_CONNECTION_FAILED: "NETWORK_CONNECTION_FAILED";
89
+ readonly NETWORK_OFFLINE: "NETWORK_OFFLINE";
90
+ readonly NETWORK_DNS_FAILED: "NETWORK_DNS_FAILED";
91
+ readonly NETWORK_TIMEOUT: "NETWORK_TIMEOUT";
92
+ readonly NETWORK_ERROR: "NETWORK_ERROR";
93
+ readonly NETWORK_PRESET_NOT_FOUND: "NETWORK_PRESET_NOT_FOUND";
94
+ readonly NETWORK_CONFIGURATION_INVALID: "NETWORK_CONFIGURATION_INVALID";
95
+ readonly REGIONAL_PRESET_NOT_FOUND: "REGIONAL_PRESET_NOT_FOUND";
96
+ readonly REGION_DETECTION_FAILED: "REGION_DETECTION_FAILED";
97
+ readonly HEADERS_ENRICHMENT_FAILED: "HEADERS_ENRICHMENT_FAILED";
98
+ readonly HEADERS_VALIDATION_FAILED: "HEADERS_VALIDATION_FAILED";
99
+ readonly HEADERS_MERGE_CONFLICT: "HEADERS_MERGE_CONFLICT";
100
+ readonly CACHE_STORAGE_FAILED: "CACHE_STORAGE_FAILED";
101
+ readonly CACHE_RETRIEVAL_FAILED: "CACHE_RETRIEVAL_FAILED";
102
+ readonly CACHE_INVALIDATION_FAILED: "CACHE_INVALIDATION_FAILED";
103
+ readonly RETRY_EXHAUSTED: "RETRY_EXHAUSTED";
104
+ readonly RETRY_STRATEGY_INVALID: "RETRY_STRATEGY_INVALID";
105
+ readonly STRATEGY_INVALID: "STRATEGY_INVALID";
106
+ readonly STRATEGY_CONFLICT: "STRATEGY_CONFLICT";
107
+ readonly STRATEGY_EXECUTION_FAILED: "STRATEGY_EXECUTION_FAILED";
108
+ readonly POLLING_TIMEOUT: "POLLING_TIMEOUT";
109
+ readonly POLLING_CANCELLED: "POLLING_CANCELLED";
110
+ readonly POLLING_INVALID_CONFIG: "POLLING_INVALID_CONFIG";
111
+ readonly PUBSUB_SUBSCRIPTION_FAILED: "PUBSUB_SUBSCRIPTION_FAILED";
112
+ readonly PUBSUB_PUBLICATION_FAILED: "PUBSUB_PUBLICATION_FAILED";
113
+ readonly PUBSUB_INVALID_TOPIC: "PUBSUB_INVALID_TOPIC";
114
+ readonly PUBSUB_CHANNEL_ERROR: "PUBSUB_CHANNEL_ERROR";
115
+ readonly REVALIDATION_FAILED: "REVALIDATION_FAILED";
116
+ readonly REVALIDATION_IN_PROGRESS: "REVALIDATION_IN_PROGRESS";
117
+ readonly DEBUG_TRACKING_FAILED: "DEBUG_TRACKING_FAILED";
118
+ readonly DEBUG_OVERRIDE_FAILED: "DEBUG_OVERRIDE_FAILED";
119
+ readonly DEBUG_CONFLICT_DETECTED: "DEBUG_CONFLICT_DETECTED";
120
+ readonly ENDPOINT_BUILD_FAILED: "ENDPOINT_BUILD_FAILED";
121
+ readonly ENDPOINT_NOT_FOUND: "ENDPOINT_NOT_FOUND";
122
+ readonly ENDPOINT_INVALID_CONFIG: "ENDPOINT_INVALID_CONFIG";
123
+ readonly EVENT_HANDLER_FAILED: "EVENT_HANDLER_FAILED";
124
+ readonly EVENT_EMISSION_FAILED: "EVENT_EMISSION_FAILED";
125
+ readonly MONITORING_FAILED: "MONITORING_FAILED";
126
+ readonly CONTEXT_OPERATION_FAILED: "CONTEXT_OPERATION_FAILED";
127
+ readonly AUTH_TOKEN_EXPIRED: "AUTH_TOKEN_EXPIRED";
128
+ readonly AUTH_UNAUTHORIZED: "AUTH_UNAUTHORIZED";
129
+ readonly AUTH_FORBIDDEN: "AUTH_FORBIDDEN";
130
+ readonly AUTH_INVALID_CREDENTIALS: "AUTH_INVALID_CREDENTIALS";
131
+ readonly RATE_LIMIT_EXCEEDED: "RATE_LIMIT_EXCEEDED";
132
+ readonly RESOURCE_NOT_FOUND: "RESOURCE_NOT_FOUND";
133
+ readonly INTERNAL_SERVER_ERROR: "INTERNAL_SERVER_ERROR";
134
+ readonly SERVICE_UNAVAILABLE: "SERVICE_UNAVAILABLE";
135
+ readonly EXTERNAL_SERVICE_ERROR: "EXTERNAL_SERVICE_ERROR";
136
+ readonly UNKNOWN_ERROR: "UNKNOWN_ERROR";
137
+ readonly VALIDATION_ERROR: "VALIDATION_ERROR";
138
+ readonly VALIDATION_FAILED: "VALIDATION_FAILED";
139
+ readonly REQUIRED_FIELD_MISSING: "REQUIRED_FIELD_MISSING";
140
+ readonly INVALID_FORMAT: "INVALID_FORMAT";
141
+ readonly VALIDATION_INVALID_FORMAT: "INVALID_FORMAT";
142
+ readonly STRING_TOO_SHORT: "STRING_TOO_SHORT";
143
+ readonly STRING_TOO_LONG: "STRING_TOO_LONG";
144
+ readonly CLIENT_ERROR: "CLIENT_ERROR";
145
+ readonly SERVER_ERROR: "SERVER_ERROR";
146
+ readonly TIMEOUT: "TIMEOUT";
147
+ };
148
+ /**
149
+ * Internal package status codes (non-HTTP)
150
+ * Used for internal configuration and validation errors that aren't HTTP-related
151
+ */
152
+ export declare const PACKAGE_STATUS_CODES: {
153
+ readonly INVALID_CONFIGURATION: 1001;
154
+ readonly MISSING_CONFIGURATION: 1002;
155
+ readonly CONFIGURATION_CONFLICT: 1003;
156
+ readonly CONFIGURATION_TRACKING_FAILED: 1004;
157
+ readonly DEBUG_TRACKING_FAILED: 1005;
158
+ readonly RESOURCE_NOT_FOUND: 1010;
159
+ readonly RESOURCE_ALREADY_EXISTS: 1011;
160
+ readonly RESOURCE_UNAVAILABLE: 1012;
161
+ readonly INVALID_PARAMETER: 1020;
162
+ readonly MISSING_PARAMETER: 1021;
163
+ readonly PARAMETER_OUT_OF_RANGE: 1022;
164
+ readonly STRATEGY_NOT_FOUND: 1030;
165
+ readonly PRESET_NOT_FOUND: 1031;
166
+ readonly INVALID_STRATEGY: 1032;
167
+ readonly REQUEST_FAILED: 1035;
168
+ readonly INITIALIZATION_FAILED: 1040;
169
+ readonly OPERATION_FAILED: 1041;
170
+ readonly STATE_CORRUPTION: 1042;
171
+ readonly SERIALIZATION_FAILED: 1043;
172
+ readonly DESERIALIZATION_FAILED: 1044;
173
+ readonly CONFIGURATION_INVALID: 1045;
174
+ readonly HEADER_PROCESSING_ERROR: 1046;
175
+ readonly REGION_DETECTION_ERROR: 1047;
176
+ readonly NETWORK_OVERRIDE_ERROR: 1048;
177
+ };
178
+ /**
179
+ * Centralized error definitions mapping
180
+ * Maps error codes to their HTTP status and metadata
181
+ */
182
+ export declare const ERROR_DEFINITIONS: ErrorDefinitions;
@@ -3,3 +3,4 @@
3
3
  * Re-exports all error-related types for the API package
4
4
  */
5
5
  export type * from './types';
6
+ export * from './enum';
@@ -2,24 +2,76 @@
2
2
  * Error handling types for @plyaz/api package
3
3
  * Following the Confluence architecture specifications
4
4
  */
5
- import type { OPERATIONS, ERROR_FIELDS, STORAGE_TYPES } from '@plyaz/config';
6
- import type { ERROR_CATEGORY, BaseErrorResponse, ErrorDetail } from '../../errors';
5
+ /**
6
+ * Import ResponseError and RequestConfig types from fetchff
7
+ */
8
+ import type { ResponseError, RequestConfig } from 'fetchff';
9
+ import type { ERROR_CATEGORY, ErrorDetail, ErrorResponse } from '../../errors';
10
+ import type { API_ERROR_CODES, OPERATIONS, ERROR_FIELDS, STORAGE_TYPES } from '..';
7
11
  /**
8
12
  * Typed constants as types for convenience
9
13
  */
10
14
  export type ErrorOperation = (typeof OPERATIONS)[keyof typeof OPERATIONS];
11
15
  export type ErrorField = (typeof ERROR_FIELDS)[keyof typeof ERROR_FIELDS];
12
16
  export type StorageType = (typeof STORAGE_TYPES)[keyof typeof STORAGE_TYPES];
17
+ /**
18
+ * Type for API error codes
19
+ */
20
+ export type ApiErrorCode = (typeof API_ERROR_CODES)[keyof typeof API_ERROR_CODES];
13
21
  /**
14
22
  * Translation interpolation variables
15
23
  */
16
24
  export interface I18nContext {
17
25
  [key: string]: string | number | boolean | null | undefined;
18
26
  }
27
+ /**
28
+ * Base error context with common fields
29
+ */
30
+ export interface BaseErrorContext {
31
+ operation?: ErrorOperation;
32
+ originalError?: string;
33
+ i18n?: I18nContext;
34
+ url?: string;
35
+ method?: string;
36
+ strategyName?: string;
37
+ fallback?: string;
38
+ eventType?: string;
39
+ reason?: string;
40
+ debuggerOperation?: string;
41
+ timeoutMs?: number;
42
+ timeout?: number;
43
+ elapsed?: number;
44
+ routerType?: string;
45
+ storageType?: string;
46
+ availableStrategies?: string;
47
+ requestedStrategy?: string;
48
+ fallbackUsed?: string;
49
+ requestedPreset?: string;
50
+ availablePresets?: string;
51
+ retryable?: boolean;
52
+ field?: string;
53
+ value?: unknown;
54
+ constraints?: Record<string, string>;
55
+ realm?: string;
56
+ scheme?: string;
57
+ limit?: number;
58
+ remaining?: number;
59
+ resetAt?: string;
60
+ retryAfter?: number;
61
+ serverMessage?: string;
62
+ traceId?: string;
63
+ input?: unknown;
64
+ errors?: Array<{
65
+ field: string;
66
+ message: string;
67
+ code?: string;
68
+ }>;
69
+ headers?: Record<string, string>;
70
+ }
19
71
  /**
20
72
  * Cache error context
21
73
  */
22
- export interface CacheErrorContext extends BaseErrorResponse {
74
+ export interface CacheErrorContext extends BaseErrorContext {
23
75
  operation: ErrorOperation;
24
76
  cacheKey?: string;
25
77
  keyPrefix?: string;
@@ -30,7 +82,7 @@ export interface CacheErrorContext extends BaseErrorResponse {
30
82
  /**
31
83
  * Headers error context
32
84
  */
33
- export interface HeadersErrorContext extends BaseErrorResponse {
85
+ export interface HeadersErrorContext extends BaseErrorContext {
34
86
  operation: ErrorOperation;
35
87
  warningCount?: number;
36
88
  warnings?: string;
@@ -38,7 +90,7 @@ export interface HeadersErrorContext extends BaseErrorResponse {
38
90
  /**
39
91
  * Regional error context
40
92
  */
41
- export interface RegionalErrorContext extends BaseErrorResponse {
93
+ export interface RegionalErrorContext extends BaseErrorContext {
42
94
  operation: ErrorOperation;
43
95
  requestedPreset?: string;
44
96
  availablePresets?: string;
@@ -47,7 +99,7 @@ export interface RegionalErrorContext extends BaseErrorResponse {
47
99
  /**
48
100
  * Network error context
49
101
  */
50
- export interface NetworkErrorContext extends BaseErrorResponse {
102
+ export interface NetworkErrorContext extends BaseErrorContext {
51
103
  operation: ErrorOperation;
52
104
  requestedPreset?: string;
53
105
  availablePresets?: string;
@@ -58,7 +110,7 @@ export interface NetworkErrorContext extends BaseErrorResponse {
58
110
  export interface ErrorDefinition {
59
111
  code: string;
60
112
  status: number;
61
- category: typeof ERROR_CATEGORY;
113
+ category: (typeof ERROR_CATEGORY)[keyof typeof ERROR_CATEGORY];
62
114
  fieldsLeft?: string[];
63
115
  }
64
116
  /**
@@ -70,7 +122,7 @@ export type ErrorDefinitions = {
70
122
  /**
71
123
  * Union type for all error contexts
72
124
  */
73
- export type ErrorContext = BaseErrorResponse | CacheErrorContext | HeadersErrorContext | RegionalErrorContext | NetworkErrorContext;
125
+ export type ErrorContext = BaseErrorContext | CacheErrorContext | HeadersErrorContext | RegionalErrorContext | NetworkErrorContext;
74
126
  /**
75
127
  * Options for creating an ApiPackageError
76
128
  * Note: ApiPackageError class itself is not migrated as it contains implementation
@@ -84,29 +136,76 @@ export interface ApiPackageErrorOptionsErrorDetail<ValueGiven, AllowedValues, Co
84
136
  context?: ErrorContext;
85
137
  clientContext?: unknown;
86
138
  }
139
+ /**
140
+ * Interface representing the public API of ApiPackageError
141
+ * Useful for type-checking without requiring the actual class instance
142
+ *
143
+ * This interface allows for:
144
+ * - Duck typing compatibility
145
+ * - Easier mocking in tests
146
+ * - Type-safe function parameters without importing the class
147
+ * - Clearer documentation of the public API contract
148
+ *
149
+ * @example
150
+ * ```typescript
151
+ * function handleError(error: ApiPackageErrorLike): void {
152
+ * if (error.isRetryable()) {
153
+ * // Retry logic
154
+ * }
155
+ * console.error(error.getUserMessage());
156
+ * }
157
+ * ```
158
+ */
159
+ export interface ApiPackageErrorLike extends Error {
160
+ readonly statusCode: number;
161
+ readonly errorCode: string;
162
+ readonly message: string;
163
+ readonly errors?: ErrorDetail<unknown, unknown, unknown>[];
164
+ readonly correlationId?: string;
165
+ readonly timestamp: string;
166
+ readonly responseError?: ResponseError;
167
+ readonly category: typeof ERROR_CATEGORY;
168
+ readonly cause?: Error;
169
+ readonly context?: ErrorContext;
170
+ readonly requestConfig?: RequestConfig;
171
+ readonly responseData?: ResponseError['response'];
172
+ readonly details?: ErrorDetail<unknown, unknown, unknown>[];
173
+ readonly originalError?: Error;
174
+ readonly metadata?: Record<string, string | number | boolean | null>;
175
+ readonly code: string;
176
+ isAuthError(): boolean;
177
+ isValidationError(): boolean;
178
+ isNetworkError(): boolean;
179
+ isServerError(): boolean;
180
+ isClientError(): boolean;
181
+ isRetryable(): boolean;
182
+ toJSON(): ErrorResponse;
183
+ toString(): string;
184
+ getUserMessage(): string;
185
+ }
87
186
  /**
88
187
  * Event handler types for API package errors
89
188
  * Note: ApiPackageError is not imported here to avoid implementation dependencies
90
189
  */
91
190
  export interface ErrorEventHandlers {
92
- onValidationError?: ((error: unknown) => void) | Array<(error: unknown) => void>;
93
- onNetworkError?: ((error: unknown) => void) | Array<(error: unknown) => void>;
94
- onAuthenticationError?: ((error: unknown) => void) | Array<(error: unknown) => void>;
95
- onAuthorizationError?: ((error: unknown) => void) | Array<(error: unknown) => void>;
96
- onRateLimitError?: ((error: unknown) => void) | Array<(error: unknown) => void>;
97
- onTimeoutError?: ((error: unknown) => void) | Array<(error: unknown) => void>;
98
- onConflictError?: ((error: unknown) => void) | Array<(error: unknown) => void>;
99
- onNotFoundError?: ((error: unknown) => void) | Array<(error: unknown) => void>;
100
- onServerError?: ((error: unknown) => void) | Array<(error: unknown) => void>;
101
- onClientError?: ((error: unknown) => void) | Array<(error: unknown) => void>;
102
- onExternalServiceError?: ((error: unknown) => void) | Array<(error: unknown) => void>;
103
- onCacheError?: ((error: unknown) => void) | Array<(error: unknown) => void>;
104
- onHeadersError?: ((error: unknown) => void) | Array<(error: unknown) => void>;
105
- onRetryError?: ((error: unknown) => void) | Array<(error: unknown) => void>;
106
- onStrategyError?: ((error: unknown) => void) | Array<(error: unknown) => void>;
107
- onRegionalError?: ((error: unknown) => void) | Array<(error: unknown) => void>;
108
- onUnknownError?: ((error: unknown) => void) | Array<(error: unknown) => void>;
109
- onAnyError?: ((error: unknown) => void) | Array<(error: unknown) => void>;
191
+ onValidationError?: ((error: ApiPackageErrorLike) => void) | Array<(error: ApiPackageErrorLike) => void>;
192
+ onNetworkError?: ((error: ApiPackageErrorLike) => void) | Array<(error: ApiPackageErrorLike) => void>;
193
+ onAuthenticationError?: ((error: ApiPackageErrorLike) => void) | Array<(error: ApiPackageErrorLike) => void>;
194
+ onAuthorizationError?: ((error: ApiPackageErrorLike) => void) | Array<(error: ApiPackageErrorLike) => void>;
195
+ onRateLimitError?: ((error: ApiPackageErrorLike) => void) | Array<(error: ApiPackageErrorLike) => void>;
196
+ onTimeoutError?: ((error: ApiPackageErrorLike) => void) | Array<(error: ApiPackageErrorLike) => void>;
197
+ onConflictError?: ((error: ApiPackageErrorLike) => void) | Array<(error: ApiPackageErrorLike) => void>;
198
+ onNotFoundError?: ((error: ApiPackageErrorLike) => void) | Array<(error: ApiPackageErrorLike) => void>;
199
+ onServerError?: ((error: ApiPackageErrorLike) => void) | Array<(error: ApiPackageErrorLike) => void>;
200
+ onClientError?: ((error: ApiPackageErrorLike) => void) | Array<(error: ApiPackageErrorLike) => void>;
201
+ onExternalServiceError?: ((error: ApiPackageErrorLike) => void) | Array<(error: ApiPackageErrorLike) => void>;
202
+ onCacheError?: ((error: ApiPackageErrorLike) => void) | Array<(error: ApiPackageErrorLike) => void>;
203
+ onHeadersError?: ((error: ApiPackageErrorLike) => void) | Array<(error: ApiPackageErrorLike) => void>;
204
+ onRetryError?: ((error: ApiPackageErrorLike) => void) | Array<(error: ApiPackageErrorLike) => void>;
205
+ onStrategyError?: ((error: ApiPackageErrorLike) => void) | Array<(error: ApiPackageErrorLike) => void>;
206
+ onRegionalError?: ((error: ApiPackageErrorLike) => void) | Array<(error: ApiPackageErrorLike) => void>;
207
+ onUnknownError?: ((error: ApiPackageErrorLike) => void) | Array<(error: ApiPackageErrorLike) => void>;
208
+ onAnyError?: ((error: ApiPackageErrorLike) => void) | Array<(error: ApiPackageErrorLike) => void>;
110
209
  }
111
210
  /**
112
211
  * Options for error handler registration