@plyaz/types 1.7.16 → 1.7.18
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.
- package/dist/api/cache/index.d.ts +5 -0
- package/dist/api/cache/types.d.ts +22 -0
- package/dist/api/client/index.d.ts +5 -0
- package/dist/api/client/types.d.ts +31 -0
- package/dist/api/config/index.d.ts +5 -0
- package/dist/api/config/types.d.ts +634 -0
- package/dist/api/errors/index.d.ts +5 -0
- package/dist/api/errors/types.d.ts +129 -0
- package/dist/api/events/index.d.ts +5 -0
- package/dist/api/events/types.d.ts +795 -0
- package/dist/api/headers/index.d.ts +5 -0
- package/dist/api/headers/types.d.ts +59 -0
- package/dist/api/index.d.ts +19 -1
- package/dist/api/network/enums.d.ts +14 -0
- package/dist/api/network/index.d.ts +6 -0
- package/dist/api/network/types.d.ts +121 -0
- package/dist/api/performance/index.d.ts +5 -0
- package/dist/api/performance/types.d.ts +137 -0
- package/dist/api/polling/index.d.ts +5 -0
- package/dist/api/polling/types.d.ts +74 -0
- package/dist/api/queue/enums.d.ts +31 -0
- package/dist/api/queue/index.d.ts +6 -0
- package/dist/api/queue/types.d.ts +65 -0
- package/dist/api/regional/index.d.ts +5 -0
- package/dist/api/regional/types.d.ts +50 -0
- package/dist/api/retry/index.d.ts +5 -0
- package/dist/api/retry/types.d.ts +26 -0
- package/dist/api/revalidation/index.d.ts +5 -0
- package/dist/api/revalidation/types.d.ts +33 -0
- package/dist/api/strategies/index.d.ts +5 -0
- package/dist/api/strategies/types.d.ts +27 -0
- package/dist/api/utils/enums.d.ts +23 -0
- package/dist/api/utils/index.d.ts +5 -0
- package/dist/auth/index.cjs +0 -41
- package/dist/auth/index.cjs.map +1 -1
- package/dist/auth/index.d.ts +1 -1
- package/dist/auth/index.js +0 -38
- package/dist/auth/index.js.map +1 -1
- package/dist/common/types.d.ts +1 -4
- package/dist/errors/enums.d.ts +27 -0
- package/dist/errors/index.cjs +0 -43
- package/dist/errors/index.cjs.map +1 -1
- package/dist/errors/index.d.ts +1 -1
- package/dist/errors/index.js +0 -40
- package/dist/errors/index.js.map +1 -1
- package/dist/events/index.cjs +0 -33
- package/dist/events/index.cjs.map +1 -1
- package/dist/events/index.d.ts +1 -1
- package/dist/events/index.js +0 -30
- package/dist/events/index.js.map +1 -1
- package/dist/events/types.d.ts +2 -2
- package/dist/index.cjs +0 -138
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +0 -128
- package/dist/index.js.map +1 -1
- package/dist/testing/common/utils/types.d.ts +2 -1
- package/dist/testing/features/api/types.d.ts +173 -21
- package/dist/web3/index.cjs +0 -27
- package/dist/web3/index.cjs.map +1 -1
- package/dist/web3/index.d.ts +1 -1
- package/dist/web3/index.js +0 -26
- package/dist/web3/index.js.map +1 -1
- package/package.json +3 -2
- package/dist/api/types.d.ts +0 -51
|
@@ -0,0 +1,634 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API Configuration Types
|
|
3
|
+
* Extends fetchff types while providing abstraction layer
|
|
4
|
+
*/
|
|
5
|
+
import type { RequestConfig as FetchffRequestConfig, FetchResponse, ResponseError, ErrorHandlingStrategy, CacheOptions, CacheKeyFunction, CacheSkipFunction, FetcherLogger, Method, DefaultParams, DefaultPayload, UrlPathParams, BodyPayload } from 'fetchff';
|
|
6
|
+
import type { PollingConfig, PollingStrategyName } from '../polling';
|
|
7
|
+
import type { UnifiedStrategyName } from '../strategies';
|
|
8
|
+
import type { CacheStrategyName } from '../cache';
|
|
9
|
+
import type { RetryConfig, RetryStrategyName } from '../retry';
|
|
10
|
+
import type { PerformancePresetName } from '../performance';
|
|
11
|
+
import type { RevalidationStrategyName } from '../revalidation';
|
|
12
|
+
import type { ApiHeaders } from '../headers';
|
|
13
|
+
import type { ErrorEventHandlers } from '../errors';
|
|
14
|
+
import type { ConfigUpdateStrategy, HandlerStrategy, EventScopeWithTemporary } from '../events';
|
|
15
|
+
import type { NETWORK_QUALITY } from '../network';
|
|
16
|
+
import type { HeaderEventHandlers, NetworkEventHandlers, ConfigEventHandlers, ClientEventHandlers, CacheEventHandlers, PerformanceEventHandlers } from '../events';
|
|
17
|
+
import type { ApiClientOptions } from '../client';
|
|
18
|
+
type HeaderBuilder = unknown;
|
|
19
|
+
type HeaderPresetName = string;
|
|
20
|
+
type DebugEventsConfig = Record<string, unknown>;
|
|
21
|
+
type EnrichedHeadersOptions = Record<string, unknown>;
|
|
22
|
+
export type { ConfigUpdateStrategy } from '../events';
|
|
23
|
+
/**
|
|
24
|
+
* HTTP Methods - extend from fetchff but uppercase
|
|
25
|
+
*/
|
|
26
|
+
export type HttpMethod = Uppercase<Method>;
|
|
27
|
+
/**
|
|
28
|
+
* Error handling strategies - re-export from fetchff
|
|
29
|
+
*/
|
|
30
|
+
export type ErrorStrategy = ErrorHandlingStrategy;
|
|
31
|
+
/**
|
|
32
|
+
* Cache configuration - extends fetchff's CacheOptions
|
|
33
|
+
*/
|
|
34
|
+
export interface ApiCacheConfig extends Partial<CacheOptions> {
|
|
35
|
+
/** Time to cache in seconds (maps to cacheTime) */
|
|
36
|
+
ttl?: number;
|
|
37
|
+
/** Time before considering cache stale (maps to staleTime) */
|
|
38
|
+
stale?: number;
|
|
39
|
+
/** Skip caching entirely (maps to skipCache) */
|
|
40
|
+
skip?: boolean | CacheSkipFunction;
|
|
41
|
+
/** Custom cache key generator */
|
|
42
|
+
keyGenerator?: CacheKeyFunction | string;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Interceptor type aliases for convenience
|
|
46
|
+
* These match fetchff's expected signatures
|
|
47
|
+
*/
|
|
48
|
+
export type RequestInterceptor = NonNullable<FetchffRequestConfig['onRequest']>;
|
|
49
|
+
export type ResponseInterceptor = NonNullable<FetchffRequestConfig['onResponse']>;
|
|
50
|
+
export type ErrorInterceptor = NonNullable<FetchffRequestConfig['onError']>;
|
|
51
|
+
export type RetryInterceptor = NonNullable<FetchffRequestConfig['onRetry']>;
|
|
52
|
+
/**
|
|
53
|
+
* Main API configuration interface
|
|
54
|
+
* Extends fetchff's RequestConfig with our abstraction layer
|
|
55
|
+
* Supports ALL fetchff configuration options
|
|
56
|
+
*/
|
|
57
|
+
export interface ApiConfig<TApiPackageError = unknown> extends Partial<Omit<FetchffRequestConfig, 'retry' | 'cache' | 'cacheTime' | 'staleTime' | 'skipCache' | 'cacheErrors' | 'cacheKey' | 'cacheBuster' | 'pollingInterval' | 'pollingDelay' | 'maxPollingAttempts' | 'shouldStopPolling' | 'data' | 'headers' | 'onRequest' | 'onResponse' | 'onError' | 'onRetry'>> {
|
|
58
|
+
/** Base URL for all requests */
|
|
59
|
+
baseURL?: string;
|
|
60
|
+
/** Default HTTP method */
|
|
61
|
+
method?: Method | string;
|
|
62
|
+
/** Default query parameters added to all requests */
|
|
63
|
+
params?: DefaultParams;
|
|
64
|
+
/** Default URL path parameters for dynamic routes */
|
|
65
|
+
urlPathParams?: UrlPathParams;
|
|
66
|
+
/** Default request body (alias for 'data' in fetchff) */
|
|
67
|
+
body?: BodyPayload;
|
|
68
|
+
/** Request timeout in milliseconds */
|
|
69
|
+
timeout?: number;
|
|
70
|
+
/** Include credentials (cookies) in requests */
|
|
71
|
+
withCredentials?: boolean;
|
|
72
|
+
/** Error handling strategy */
|
|
73
|
+
strategy?: ErrorHandlingStrategy;
|
|
74
|
+
/** Flatten nested response data */
|
|
75
|
+
flattenResponse?: boolean;
|
|
76
|
+
/** Default response when request fails */
|
|
77
|
+
defaultResponse?: unknown;
|
|
78
|
+
/** Cancel previous requests to same endpoint */
|
|
79
|
+
cancellable?: boolean;
|
|
80
|
+
/** Reject promise for cancelled requests */
|
|
81
|
+
rejectCancelled?: boolean;
|
|
82
|
+
/** Time window for request deduplication (ms) */
|
|
83
|
+
dedupeTime?: number;
|
|
84
|
+
/** Disable automatic request on init (React-specific) */
|
|
85
|
+
immediate?: boolean;
|
|
86
|
+
/** Retry configuration with better naming */
|
|
87
|
+
retry?: RetryConfig | false;
|
|
88
|
+
/** Cache configuration with better naming */
|
|
89
|
+
cache?: ApiCacheConfig;
|
|
90
|
+
/**
|
|
91
|
+
* Polling configuration
|
|
92
|
+
* Can be:
|
|
93
|
+
* - A strategy name: 'jobStatus' | 'healthCheck' | 'liveData' | etc.
|
|
94
|
+
* - A PollingConfig object for custom configuration
|
|
95
|
+
* - false to disable polling
|
|
96
|
+
*/
|
|
97
|
+
polling?: PollingStrategyName | PollingConfig | false;
|
|
98
|
+
/** Custom logger for debugging */
|
|
99
|
+
logger?: FetcherLogger;
|
|
100
|
+
/** Request interceptor(s) - can be single or array */
|
|
101
|
+
onRequest?: RequestInterceptor | RequestInterceptor[];
|
|
102
|
+
/** Response interceptor(s) - can be single or array */
|
|
103
|
+
onResponse?: ResponseInterceptor | ResponseInterceptor[];
|
|
104
|
+
/** Error interceptor(s) - can be single or array */
|
|
105
|
+
onError?: ErrorInterceptor | ErrorInterceptor[];
|
|
106
|
+
/** Retry interceptor(s) - can be single or array */
|
|
107
|
+
onRetry?: RetryInterceptor | RetryInterceptor[];
|
|
108
|
+
/**
|
|
109
|
+
* Unified strategy - Simple way to configure all domains at once
|
|
110
|
+
* Available: 'realtime', 'interactive', 'background', 'static', 'offline'
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```typescript
|
|
114
|
+
* const api = createApiClient({ unifiedStrategy: 'interactive' });
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
unifiedStrategy?: UnifiedStrategyName;
|
|
118
|
+
/**
|
|
119
|
+
* Individual strategy overrides
|
|
120
|
+
* These override the unified strategy if both are specified
|
|
121
|
+
*/
|
|
122
|
+
/** Cache strategy name or direct config */
|
|
123
|
+
cacheStrategy?: CacheStrategyName;
|
|
124
|
+
/** Retry strategy name or direct config */
|
|
125
|
+
retryStrategy?: RetryStrategyName;
|
|
126
|
+
/** Polling strategy name */
|
|
127
|
+
pollingStrategy?: PollingStrategyName;
|
|
128
|
+
/** Performance optimization preset name */
|
|
129
|
+
performanceStrategy?: PerformancePresetName;
|
|
130
|
+
/** Revalidation strategy name */
|
|
131
|
+
revalidationStrategy?: RevalidationStrategyName;
|
|
132
|
+
/**
|
|
133
|
+
* Advanced header configuration with multiple options
|
|
134
|
+
* Supports presets, static headers, dynamic headers, and builders
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* const api = createApiClient({
|
|
139
|
+
* headers: {
|
|
140
|
+
* presets: ['json', 'cors'],
|
|
141
|
+
* static: { 'x-api-key': 'secret' },
|
|
142
|
+
* dynamic: async () => ({ 'authorization': await getToken() }),
|
|
143
|
+
* autoDetectNetwork: true,
|
|
144
|
+
* requestClientHints: true
|
|
145
|
+
* }
|
|
146
|
+
* });
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
headers?: ApiHeaders | (() => ApiHeaders | Promise<ApiHeaders>) | {
|
|
150
|
+
/** Header presets to apply (e.g., 'json', 'cors', 'mobile') */
|
|
151
|
+
presets?: HeaderPresetName[];
|
|
152
|
+
/** Static headers that never change */
|
|
153
|
+
static?: ApiHeaders;
|
|
154
|
+
/** Dynamic headers computed at request time */
|
|
155
|
+
dynamic?: () => ApiHeaders | Promise<ApiHeaders>;
|
|
156
|
+
/** Header builder for complex logic */
|
|
157
|
+
builder?: (builder: HeaderBuilder) => HeaderBuilder;
|
|
158
|
+
/** Auto-detect network conditions and add Client Hints */
|
|
159
|
+
autoDetectNetwork?: boolean;
|
|
160
|
+
/** Request Client Hints from browser */
|
|
161
|
+
requestClientHints?: boolean;
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* Network-aware configuration for adaptive behavior
|
|
165
|
+
* Automatically adjusts client behavior based on network conditions
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```typescript
|
|
169
|
+
* const api = createApiClient({
|
|
170
|
+
* networkAware: {
|
|
171
|
+
* enabled: true,
|
|
172
|
+
* adaptConfig: true,
|
|
173
|
+
* qualityPresets: {
|
|
174
|
+
* [NETWORK_QUALITY.POOR]: {
|
|
175
|
+
* performance: 'minimal',
|
|
176
|
+
* cache: 'aggressive',
|
|
177
|
+
* retry: 'exponential'
|
|
178
|
+
* }
|
|
179
|
+
* },
|
|
180
|
+
* temporaryOverride: {
|
|
181
|
+
* enabled: true,
|
|
182
|
+
* triggers: { quality: [NETWORK_QUALITY.POOR] },
|
|
183
|
+
* overrideConfig: { timeout: 60000 }
|
|
184
|
+
* }
|
|
185
|
+
* }
|
|
186
|
+
* });
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
189
|
+
networkAware?: {
|
|
190
|
+
/** Enable network-aware features */
|
|
191
|
+
enabled?: boolean;
|
|
192
|
+
/** Automatically adapt configuration based on network */
|
|
193
|
+
adaptConfig?: boolean;
|
|
194
|
+
/** Request Client Hints for better detection */
|
|
195
|
+
requestClientHints?: boolean;
|
|
196
|
+
/** Custom quality thresholds */
|
|
197
|
+
thresholds?: {
|
|
198
|
+
good?: {
|
|
199
|
+
rtt?: number;
|
|
200
|
+
downlink?: number;
|
|
201
|
+
};
|
|
202
|
+
fair?: {
|
|
203
|
+
rtt?: number;
|
|
204
|
+
downlink?: number;
|
|
205
|
+
};
|
|
206
|
+
poor?: {
|
|
207
|
+
rtt?: number;
|
|
208
|
+
downlink?: number;
|
|
209
|
+
};
|
|
210
|
+
};
|
|
211
|
+
/** Custom quality-to-preset mappings */
|
|
212
|
+
qualityPresets?: Partial<Record<NETWORK_QUALITY, {
|
|
213
|
+
performance?: PerformancePresetName;
|
|
214
|
+
cache?: CacheStrategyName;
|
|
215
|
+
retry?: RetryStrategyName;
|
|
216
|
+
revalidation?: RevalidationStrategyName;
|
|
217
|
+
polling?: PollingStrategyName | null;
|
|
218
|
+
}>>;
|
|
219
|
+
/** Temporary override configuration */
|
|
220
|
+
temporaryOverride?: {
|
|
221
|
+
enabled?: boolean;
|
|
222
|
+
triggers?: {
|
|
223
|
+
quality?: NETWORK_QUALITY[];
|
|
224
|
+
rtt?: number;
|
|
225
|
+
downlink?: number;
|
|
226
|
+
saveData?: boolean;
|
|
227
|
+
};
|
|
228
|
+
overrideConfig?: Partial<ApiConfig>;
|
|
229
|
+
checkInterval?: number;
|
|
230
|
+
onOverrideChange?: ((active: boolean, reason: string) => void) | Array<(active: boolean, reason: string) => void>;
|
|
231
|
+
};
|
|
232
|
+
/** Event listeners for network changes */
|
|
233
|
+
events?: NetworkEventHandlers;
|
|
234
|
+
};
|
|
235
|
+
/**
|
|
236
|
+
* Enriched context headers configuration for microservices
|
|
237
|
+
* Automatically collects device, network, platform, and compliance headers
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* ```typescript
|
|
241
|
+
* const api = createApiClient({
|
|
242
|
+
* enrichedHeaders: {
|
|
243
|
+
* preset: 'standard',
|
|
244
|
+
* includeDevice: true,
|
|
245
|
+
* includeNetwork: true,
|
|
246
|
+
* includeCompliance: true,
|
|
247
|
+
* autoDetectRegion: true
|
|
248
|
+
* }
|
|
249
|
+
* });
|
|
250
|
+
* ```
|
|
251
|
+
*/
|
|
252
|
+
enrichedHeaders?: EnrichedHeadersOptions;
|
|
253
|
+
/**
|
|
254
|
+
* Event handlers for header changes, conflicts, and overrides
|
|
255
|
+
* Track all header modifications throughout the request lifecycle
|
|
256
|
+
*
|
|
257
|
+
* @example
|
|
258
|
+
* ```typescript
|
|
259
|
+
* const api = createApiClient({
|
|
260
|
+
* headerEvents: {
|
|
261
|
+
* onHeadersChanged: (event) => {
|
|
262
|
+
* console.log('Headers changed:', event.data.changes);
|
|
263
|
+
* },
|
|
264
|
+
* onHeadersEnriched: (event) => {
|
|
265
|
+
* console.log('Enriched headers:', event.data.headers);
|
|
266
|
+
* },
|
|
267
|
+
* onHeadersConflict: (event) => {
|
|
268
|
+
* console.warn('Header conflict:', event.data.header);
|
|
269
|
+
* },
|
|
270
|
+
* onHeadersOverride: (event) => {
|
|
271
|
+
* console.log('Headers overridden:', event.data.overridden);
|
|
272
|
+
* }
|
|
273
|
+
* }
|
|
274
|
+
* });
|
|
275
|
+
* ```
|
|
276
|
+
*/
|
|
277
|
+
headerEvents?: HeaderEventHandlers;
|
|
278
|
+
/** User's original configuration (preserved for restoration) */
|
|
279
|
+
preservedConfig?: Partial<ApiClientOptions>;
|
|
280
|
+
/**
|
|
281
|
+
* Debug event handlers for monitoring configuration conflicts and network changes
|
|
282
|
+
* These handlers are automatically connected when the client is created
|
|
283
|
+
*
|
|
284
|
+
* @example
|
|
285
|
+
* ```typescript
|
|
286
|
+
* const api = createApiClient({
|
|
287
|
+
* debugEvents: {
|
|
288
|
+
* onConflict: (conflict) => {
|
|
289
|
+
* console.warn('Config conflict:', conflict.property);
|
|
290
|
+
* },
|
|
291
|
+
* onDebugInfo: (info) => {
|
|
292
|
+
* metricsCollector.send('debug.info', info);
|
|
293
|
+
* },
|
|
294
|
+
* autoCheckInterval: 60000 // Check every minute
|
|
295
|
+
* }
|
|
296
|
+
* });
|
|
297
|
+
* ```
|
|
298
|
+
*/
|
|
299
|
+
debugEvents?: DebugEventsConfig;
|
|
300
|
+
/**
|
|
301
|
+
* Error event handlers for comprehensive error handling
|
|
302
|
+
* These handlers are automatically chained with global error handlers
|
|
303
|
+
*
|
|
304
|
+
* @example
|
|
305
|
+
* ```typescript
|
|
306
|
+
* const api = createApiClient({
|
|
307
|
+
* errorHandlers: {
|
|
308
|
+
* onNetworkError: (error) => {
|
|
309
|
+
* console.error('Network error:', error);
|
|
310
|
+
* showOfflineNotification();
|
|
311
|
+
* },
|
|
312
|
+
* onAuthenticationError: (error) => {
|
|
313
|
+
* console.error('Auth error:', error);
|
|
314
|
+
* redirectToLogin();
|
|
315
|
+
* },
|
|
316
|
+
* onRateLimitError: (error) => {
|
|
317
|
+
* console.warn('Rate limited:', error);
|
|
318
|
+
* scheduleRetry(error.retryAfter);
|
|
319
|
+
* },
|
|
320
|
+
* onAnyError: (error) => {
|
|
321
|
+
* // Catch-all for any errors
|
|
322
|
+
* logToSentry(error);
|
|
323
|
+
* }
|
|
324
|
+
* }
|
|
325
|
+
* });
|
|
326
|
+
* ```
|
|
327
|
+
*/
|
|
328
|
+
errorHandlers?: ErrorEventHandlers<TApiPackageError>;
|
|
329
|
+
/**
|
|
330
|
+
* Configuration event handlers for monitoring config changes and updates
|
|
331
|
+
* Track when global config is updated, reset, or when presets are applied
|
|
332
|
+
*
|
|
333
|
+
* @example
|
|
334
|
+
* ```typescript
|
|
335
|
+
* const api = createApiClient({
|
|
336
|
+
* configEvents: {
|
|
337
|
+
* onGlobalUpdated: (event) => {
|
|
338
|
+
* console.log('Config updated:', event.data.config);
|
|
339
|
+
* },
|
|
340
|
+
* onPresetApplied: (event) => {
|
|
341
|
+
* console.log('Preset applied:', event.data.preset);
|
|
342
|
+
* },
|
|
343
|
+
* onEnvironmentConfigured: (event) => {
|
|
344
|
+
* console.log('Environment detected:', event.data.environment);
|
|
345
|
+
* }
|
|
346
|
+
* }
|
|
347
|
+
* });
|
|
348
|
+
* ```
|
|
349
|
+
*/
|
|
350
|
+
configEvents?: ConfigEventHandlers;
|
|
351
|
+
/**
|
|
352
|
+
* Client lifecycle event handlers for monitoring client operations
|
|
353
|
+
* Track client creation, requests, responses, and retries
|
|
354
|
+
*
|
|
355
|
+
* @example
|
|
356
|
+
* ```typescript
|
|
357
|
+
* const api = createApiClient({
|
|
358
|
+
* clientEvents: {
|
|
359
|
+
* onClientCreated: (event) => {
|
|
360
|
+
* console.log('Client created:', event.data.clientId);
|
|
361
|
+
* },
|
|
362
|
+
* onRequestStart: (event) => {
|
|
363
|
+
* console.log('Request started:', event.data.url);
|
|
364
|
+
* },
|
|
365
|
+
* onResponseReceived: (event) => {
|
|
366
|
+
* console.log('Response received:', event.data.status);
|
|
367
|
+
* },
|
|
368
|
+
* onRetryAttempt: (event) => {
|
|
369
|
+
* console.warn('Retry attempt:', event.data.attempt);
|
|
370
|
+
* }
|
|
371
|
+
* }
|
|
372
|
+
* });
|
|
373
|
+
* ```
|
|
374
|
+
*/
|
|
375
|
+
clientEvents?: ClientEventHandlers;
|
|
376
|
+
/**
|
|
377
|
+
* Cache event handlers for monitoring cache operations
|
|
378
|
+
* Track cache hits, misses, invalidations, and stale data
|
|
379
|
+
*
|
|
380
|
+
* @example
|
|
381
|
+
* ```typescript
|
|
382
|
+
* const api = createApiClient({
|
|
383
|
+
* cacheEvents: {
|
|
384
|
+
* onCacheHit: (event) => {
|
|
385
|
+
* console.log('Cache hit:', event.data.key);
|
|
386
|
+
* },
|
|
387
|
+
* onCacheMiss: (event) => {
|
|
388
|
+
* console.log('Cache miss:', event.data.key);
|
|
389
|
+
* },
|
|
390
|
+
* onCacheInvalidate: (event) => {
|
|
391
|
+
* console.log('Cache invalidated:', event.data.pattern);
|
|
392
|
+
* }
|
|
393
|
+
* }
|
|
394
|
+
* });
|
|
395
|
+
* ```
|
|
396
|
+
*/
|
|
397
|
+
cacheEvents?: CacheEventHandlers;
|
|
398
|
+
/**
|
|
399
|
+
* Performance event handlers for monitoring API performance
|
|
400
|
+
* Track request timings, cache performance, and optimization events
|
|
401
|
+
*
|
|
402
|
+
* @example
|
|
403
|
+
* ```typescript
|
|
404
|
+
* const api = createApiClient({
|
|
405
|
+
* performanceEvents: {
|
|
406
|
+
* onRequestStart: (event) => {
|
|
407
|
+
* console.log('Request started:', event.data.requestId);
|
|
408
|
+
* },
|
|
409
|
+
* onRequestComplete: (event) => {
|
|
410
|
+
* console.log('Request completed in', event.data.duration, 'ms');
|
|
411
|
+
* },
|
|
412
|
+
* onThresholdExceeded: (event) => {
|
|
413
|
+
* console.warn('Performance threshold exceeded:', event.data.type);
|
|
414
|
+
* },
|
|
415
|
+
* onOptimizationApplied: (event) => {
|
|
416
|
+
* console.log('Optimization applied:', event.data.type);
|
|
417
|
+
* }
|
|
418
|
+
* }
|
|
419
|
+
* });
|
|
420
|
+
* ```
|
|
421
|
+
*/
|
|
422
|
+
performanceEvents?: PerformanceEventHandlers;
|
|
423
|
+
/**
|
|
424
|
+
* Configuration override strategy for controlling how configurations are applied
|
|
425
|
+
* Determines the scope and behavior when updating configurations
|
|
426
|
+
*
|
|
427
|
+
* Strategies:
|
|
428
|
+
* - 'merge': Merges with existing config at CLIENT scope
|
|
429
|
+
* - 'replace': Replaces existing config entirely at CLIENT scope
|
|
430
|
+
* - 'temporary': Applies at REQUEST/TEMPORARY scope (highest priority, default for updateConfig)
|
|
431
|
+
*
|
|
432
|
+
* Event scopes behavior:
|
|
433
|
+
* - Client creation: Default is ALL scopes (global + client handlers merged)
|
|
434
|
+
* - Global config: Only 'global' scope
|
|
435
|
+
* - updateConfig with 'temporary': Default is only 'request' scope
|
|
436
|
+
* - updateConfig with 'merge'/'replace': Uses client's eventScopes
|
|
437
|
+
* - Can be explicitly set via eventScopes to force specific scopes
|
|
438
|
+
*
|
|
439
|
+
* @example
|
|
440
|
+
* ```typescript
|
|
441
|
+
* // Use temporary strategy (default) for highest priority
|
|
442
|
+
* const api = createApiClient({
|
|
443
|
+
* timeout: 30000,
|
|
444
|
+
* configOverride: {
|
|
445
|
+
* strategy: 'temporary', // Apply future updates at REQUEST scope
|
|
446
|
+
* eventScopes: ['client', 'request'] // Only emit to these scopes
|
|
447
|
+
* }
|
|
448
|
+
* });
|
|
449
|
+
*
|
|
450
|
+
* // Use with updateConfig
|
|
451
|
+
* api.updateConfig({
|
|
452
|
+
* timeout: 60000,
|
|
453
|
+
* configOverride: {
|
|
454
|
+
* strategy: 'replace', // Replace CLIENT config entirely
|
|
455
|
+
* clearOnComplete: true // Auto-clear temporary overrides after request
|
|
456
|
+
* }
|
|
457
|
+
* });
|
|
458
|
+
*
|
|
459
|
+
* // Or pass strategy directly to updateConfig
|
|
460
|
+
* api.updateConfig(
|
|
461
|
+
* { timeout: 60000 },
|
|
462
|
+
* { strategy: 'temporary' } // Default behavior
|
|
463
|
+
* );
|
|
464
|
+
* ```
|
|
465
|
+
*/
|
|
466
|
+
configOverride?: {
|
|
467
|
+
/** Override strategy - controls WHERE config updates are applied (scope) */
|
|
468
|
+
strategy?: ConfigUpdateStrategy;
|
|
469
|
+
/**
|
|
470
|
+
* Handler strategy - controls how event handlers are registered and merged
|
|
471
|
+
* If not provided, falls back to 'strategy' value, then defaults to 'merge'
|
|
472
|
+
* Supports 'temporary' for handlers even when config strategy is different
|
|
473
|
+
*/
|
|
474
|
+
handlerStrategy?: HandlerStrategy;
|
|
475
|
+
/** Event scopes to emit to - defaults to all scopes if not specified */
|
|
476
|
+
eventScopes?: EventScopeWithTemporary[];
|
|
477
|
+
/** Auto-clear temporary overrides after request completes */
|
|
478
|
+
clearOnComplete?: boolean;
|
|
479
|
+
/**
|
|
480
|
+
* Use priority mode for handler merging - only use highest priority handler
|
|
481
|
+
* When true: Only the highest priority handler runs (request > client > global)
|
|
482
|
+
* When false: All handlers are merged and run in sequence (default behavior)
|
|
483
|
+
* Note: Works with 'merge', 'replace', 'prepend', 'append' HandlerStrategy
|
|
484
|
+
* @default false
|
|
485
|
+
*/
|
|
486
|
+
priority?: boolean;
|
|
487
|
+
};
|
|
488
|
+
/**
|
|
489
|
+
* Tracking and telemetry configuration
|
|
490
|
+
* Controls operation tracking, event processing, and debugging features
|
|
491
|
+
*
|
|
492
|
+
* @example
|
|
493
|
+
* ```typescript
|
|
494
|
+
* // Disable all tracking for GDPR compliance
|
|
495
|
+
* const api = createApiClient({
|
|
496
|
+
* tracking: {
|
|
497
|
+
* enabled: false,
|
|
498
|
+
* operations: false,
|
|
499
|
+
* events: false
|
|
500
|
+
* }
|
|
501
|
+
* });
|
|
502
|
+
*
|
|
503
|
+
* // Enable only events but not operation tracking
|
|
504
|
+
* const api = createApiClient({
|
|
505
|
+
* tracking: {
|
|
506
|
+
* operations: false,
|
|
507
|
+
* events: true,
|
|
508
|
+
* eventStrategy: 'immediate'
|
|
509
|
+
* }
|
|
510
|
+
* });
|
|
511
|
+
*
|
|
512
|
+
* // Custom tracking configuration
|
|
513
|
+
* const api = createApiClient({
|
|
514
|
+
* tracking: {
|
|
515
|
+
* enabled: true,
|
|
516
|
+
* operations: true,
|
|
517
|
+
* events: true,
|
|
518
|
+
* queueStrategy: 'batch',
|
|
519
|
+
* eventStrategy: 'immediate',
|
|
520
|
+
* performanceMode: 'minimal'
|
|
521
|
+
* }
|
|
522
|
+
* });
|
|
523
|
+
* ```
|
|
524
|
+
*/
|
|
525
|
+
tracking?: {
|
|
526
|
+
/**
|
|
527
|
+
* Master switch for all tracking features
|
|
528
|
+
* When false, disables operations, events, and debugging
|
|
529
|
+
* @default true
|
|
530
|
+
*/
|
|
531
|
+
enabled?: boolean;
|
|
532
|
+
/**
|
|
533
|
+
* Enable/disable operation tracking (debugger queue)
|
|
534
|
+
* Controls whether operations are tracked for debugging
|
|
535
|
+
* @default true
|
|
536
|
+
*/
|
|
537
|
+
operations?: boolean;
|
|
538
|
+
/**
|
|
539
|
+
* Enable/disable event emission and processing
|
|
540
|
+
* Controls whether events are emitted and processed
|
|
541
|
+
* @default true
|
|
542
|
+
*/
|
|
543
|
+
events?: boolean;
|
|
544
|
+
/**
|
|
545
|
+
* Queue processing strategy for operations
|
|
546
|
+
* - 'immediate': Process immediately (best for tests)
|
|
547
|
+
* - 'batch': Batch operations for processing
|
|
548
|
+
* - 'throttle': Throttle processing rate
|
|
549
|
+
* - 'debounce': Debounce processing
|
|
550
|
+
* @default 'batch' in production, 'immediate' in tests
|
|
551
|
+
*/
|
|
552
|
+
queueStrategy?: 'immediate' | 'batch' | 'throttle' | 'debounce';
|
|
553
|
+
/**
|
|
554
|
+
* Event processing strategy
|
|
555
|
+
* - 'immediate': Process events immediately
|
|
556
|
+
* - 'queued': Queue events for batch processing
|
|
557
|
+
* @default 'immediate'
|
|
558
|
+
*/
|
|
559
|
+
eventStrategy?: 'immediate' | 'queued';
|
|
560
|
+
/**
|
|
561
|
+
* Performance mode for tracking
|
|
562
|
+
* - 'full': Track everything with full detail
|
|
563
|
+
* - 'minimal': Track only essential operations
|
|
564
|
+
* - 'off': Disable tracking (same as enabled: false)
|
|
565
|
+
* @default 'full'
|
|
566
|
+
*/
|
|
567
|
+
performanceMode?: 'full' | 'minimal' | 'off';
|
|
568
|
+
/**
|
|
569
|
+
* Maximum number of operations to keep in history
|
|
570
|
+
* @default 1000
|
|
571
|
+
*/
|
|
572
|
+
historySize?: number;
|
|
573
|
+
/**
|
|
574
|
+
* Maximum number of conflicts to track
|
|
575
|
+
* @default 100
|
|
576
|
+
*/
|
|
577
|
+
maxConflicts?: number;
|
|
578
|
+
/**
|
|
579
|
+
* Skip adding entries to history for this request/operation
|
|
580
|
+
* Useful for batch operations to avoid duplicate history entries
|
|
581
|
+
* @default false
|
|
582
|
+
*/
|
|
583
|
+
skipHistory?: boolean;
|
|
584
|
+
/**
|
|
585
|
+
* Enable telemetry data collection (if configured)
|
|
586
|
+
* Separate from debugging - for analytics/monitoring
|
|
587
|
+
* @default false
|
|
588
|
+
*/
|
|
589
|
+
telemetry?: boolean;
|
|
590
|
+
};
|
|
591
|
+
}
|
|
592
|
+
/**
|
|
593
|
+
* Request-specific configuration
|
|
594
|
+
* Extends ApiConfig with request-specific fields
|
|
595
|
+
*/
|
|
596
|
+
export interface RequestConfig extends ApiConfig {
|
|
597
|
+
/** HTTP method - can be Method or string for flexibility */
|
|
598
|
+
method?: Method | string;
|
|
599
|
+
/** URL path (can be relative to baseURL) */
|
|
600
|
+
url?: string;
|
|
601
|
+
/** Query parameters */
|
|
602
|
+
params?: DefaultParams;
|
|
603
|
+
/** URL path parameters (for dynamic routes like /users/:id) */
|
|
604
|
+
urlPathParams?: UrlPathParams;
|
|
605
|
+
/** Request body */
|
|
606
|
+
body?: BodyPayload;
|
|
607
|
+
/** Abort signal for cancellation */
|
|
608
|
+
signal?: AbortSignal;
|
|
609
|
+
}
|
|
610
|
+
/**
|
|
611
|
+
* Endpoint configuration
|
|
612
|
+
* Used to define API endpoints with their specific settings
|
|
613
|
+
* Can override ALL global settings on per-endpoint basis
|
|
614
|
+
*/
|
|
615
|
+
export interface EndpointConfig extends Omit<RequestConfig, 'params' | 'urlPathParams' | 'body'> {
|
|
616
|
+
/** URL pattern (can include :param placeholders) */
|
|
617
|
+
url: string;
|
|
618
|
+
/** HTTP method - typically use Method constants */
|
|
619
|
+
method?: Method | string;
|
|
620
|
+
/** Description of the endpoint */
|
|
621
|
+
description?: string;
|
|
622
|
+
}
|
|
623
|
+
/**
|
|
624
|
+
* API Response wrapper
|
|
625
|
+
* Extends fetchff's FetchResponse
|
|
626
|
+
*/
|
|
627
|
+
export interface ApiResponse<TData = DefaultPayload, TBody = DefaultPayload, TParams = DefaultParams, TPathParams = UrlPathParams> extends FetchResponse<TData, TBody, TParams, TPathParams> {
|
|
628
|
+
}
|
|
629
|
+
/**
|
|
630
|
+
* API Error interface
|
|
631
|
+
* Extends fetchff's ResponseError
|
|
632
|
+
*/
|
|
633
|
+
export interface ApiError<TData = DefaultPayload, TBody = DefaultPayload, TParams = DefaultParams, TPathParams = UrlPathParams> extends ResponseError<TData, TBody, TParams, TPathParams> {
|
|
634
|
+
}
|