@plyaz/types 1.7.18 → 1.7.20
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/client/enum.d.ts +12 -0
- package/dist/api/client/index.d.ts +1 -0
- package/dist/api/client/types.d.ts +114 -0
- package/dist/api/config/types.d.ts +56 -9
- package/dist/api/debugger/enums.d.ts +153 -0
- package/dist/api/debugger/factories/index.d.ts +1 -0
- package/dist/api/debugger/factories/types.d.ts +191 -0
- package/dist/api/debugger/index.d.ts +2 -0
- package/dist/api/debugger/types.d.ts +628 -0
- package/dist/api/endpoints/campaigns/index.d.ts +1 -0
- package/dist/api/endpoints/campaigns/types.d.ts +68 -0
- package/dist/api/endpoints/health/index.d.ts +1 -0
- package/dist/api/endpoints/health/types.d.ts +127 -0
- package/dist/api/endpoints/index.d.ts +3 -0
- package/dist/api/endpoints/types.d.ts +5 -0
- package/dist/api/errors/enum.d.ts +182 -0
- package/dist/api/errors/index.d.ts +1 -0
- package/dist/api/errors/types.d.ts +126 -27
- package/dist/api/events/enum.d.ts +262 -0
- package/dist/api/events/factories/cache/index.d.ts +1 -0
- package/dist/api/events/factories/cache/types.d.ts +60 -0
- package/dist/api/events/factories/client/index.d.ts +1 -0
- package/dist/api/events/factories/client/types.d.ts +120 -0
- package/dist/api/events/factories/config/index.d.ts +1 -0
- package/dist/api/events/factories/config/types.d.ts +77 -0
- package/dist/api/events/factories/debug/index.d.ts +1 -0
- package/dist/api/events/factories/debug/types.d.ts +131 -0
- package/dist/api/events/factories/errors/index.d.ts +1 -0
- package/dist/api/events/factories/errors/types.d.ts +293 -0
- package/dist/api/events/factories/headers/index.d.ts +1 -0
- package/dist/api/events/factories/headers/types.d.ts +256 -0
- package/dist/api/events/factories/index.d.ts +9 -0
- package/dist/api/events/factories/network/index.d.ts +1 -0
- package/dist/api/events/factories/network/types.d.ts +196 -0
- package/dist/api/events/factories/performance/index.d.ts +1 -0
- package/dist/api/events/factories/performance/types.d.ts +150 -0
- package/dist/api/events/factories/types.d.ts +84 -0
- package/dist/api/events/index.d.ts +2 -0
- package/dist/api/events/types.d.ts +1 -730
- package/dist/api/headers/enum.d.ts +34 -0
- package/dist/api/headers/index.d.ts +1 -0
- package/dist/api/headers/types.d.ts +456 -0
- package/dist/api/hooks/index.d.ts +1 -0
- package/dist/api/hooks/types.d.ts +131 -0
- package/dist/api/index.d.ts +7 -1
- package/dist/api/network/enums.d.ts +75 -5
- package/dist/api/network/frameworks/index.d.ts +2 -0
- package/dist/api/network/frameworks/nestjs/index.d.ts +1 -0
- package/dist/api/network/frameworks/nestjs/types.d.ts +47 -0
- package/dist/api/network/frameworks/types.d.ts +76 -0
- package/dist/api/network/index.d.ts +1 -0
- package/dist/api/network/types.d.ts +346 -39
- package/dist/api/performance/types.d.ts +17 -10
- package/dist/api/polling/types.d.ts +6 -4
- package/dist/api/pubsub/enum.d.ts +12 -0
- package/dist/api/pubsub/index.d.ts +2 -0
- package/dist/api/pubsub/types.d.ts +61 -0
- package/dist/api/queue/types.d.ts +69 -0
- package/dist/api/regional/enum.d.ts +75 -0
- package/dist/api/regional/index.d.ts +1 -0
- package/dist/api/regional/types.d.ts +2 -1
- package/dist/api/request/index.d.ts +1 -0
- package/dist/api/request/types.d.ts +44 -0
- package/dist/api/retry/types.d.ts +31 -0
- package/dist/api/strategies/types.d.ts +12 -8
- package/dist/errors/index.cjs +69 -0
- package/dist/errors/index.cjs.map +1 -1
- package/dist/errors/index.d.ts +1 -1
- package/dist/errors/index.js +66 -0
- package/dist/errors/index.js.map +1 -1
- package/dist/features/cache/types.d.ts +5 -0
- package/dist/testing/features/api/types.d.ts +355 -4
- package/package.json +5 -3
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { NetworkPresetConfig } from '..';
|
|
2
|
+
/**
|
|
3
|
+
* Data saver mode uses offline-optimized presets
|
|
4
|
+
*/
|
|
5
|
+
export declare const DATA_SAVER_PRESETS: NetworkPresetConfig;
|
|
6
|
+
/**
|
|
7
|
+
* Valid Client Hint header names
|
|
8
|
+
*/
|
|
9
|
+
export declare const CLIENT_HINT_HEADERS: {
|
|
10
|
+
readonly SAVE_DATA: "save-data";
|
|
11
|
+
readonly ECT: "ect";
|
|
12
|
+
readonly RTT: "rtt";
|
|
13
|
+
readonly DOWNLINK: "downlink";
|
|
14
|
+
readonly DEVICE_MEMORY: "device-memory";
|
|
15
|
+
readonly ACCEPT_CH: "Accept-CH";
|
|
16
|
+
readonly ACCEPT_CH_LIFETIME: "Accept-CH-Lifetime";
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Validation ranges for header values
|
|
20
|
+
*/
|
|
21
|
+
export declare const VALIDATION_RANGES: {
|
|
22
|
+
readonly RTT: {
|
|
23
|
+
readonly MIN: 0;
|
|
24
|
+
readonly MAX: 10000;
|
|
25
|
+
};
|
|
26
|
+
readonly DOWNLINK: {
|
|
27
|
+
readonly MIN: 0;
|
|
28
|
+
readonly MAX: 10000;
|
|
29
|
+
};
|
|
30
|
+
readonly DEVICE_MEMORY: {
|
|
31
|
+
readonly MIN: 0;
|
|
32
|
+
readonly MAX: 128;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Header Management Type Definitions
|
|
3
3
|
* Comprehensive types for HTTP headers, following TASK-016 specification
|
|
4
4
|
*/
|
|
5
|
+
import type { ApiClientInstance, DebuggerConfigSource, PerformancePresetName, RetryStrategyName, CacheStrategyName, RevalidationStrategyName } from '..';
|
|
5
6
|
/**
|
|
6
7
|
* Headers that affect cache key generation (based on fetchff behavior)
|
|
7
8
|
* These headers will be included in cache key computation
|
|
@@ -57,3 +58,458 @@ export type AuthType = 'Bearer' | 'Basic' | 'ApiKey' | 'Custom';
|
|
|
57
58
|
* Platform types for client identification
|
|
58
59
|
*/
|
|
59
60
|
export type PlatformType = 'ios' | 'android' | 'web' | 'desktop' | 'mobile' | string;
|
|
61
|
+
/**
|
|
62
|
+
* Configuration options for enriched context headers
|
|
63
|
+
* Controls what device, network, platform, and compliance headers are collected
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* const options: EnrichedHeadersOptions = {
|
|
68
|
+
* preset: 'standard',
|
|
69
|
+
* includeDevice: true,
|
|
70
|
+
* includeNetwork: true,
|
|
71
|
+
* autoDetectRegion: true,
|
|
72
|
+
* regionalPreset: 'gdpr',
|
|
73
|
+
* respectDoNotTrack: true
|
|
74
|
+
* };
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export interface EnrichedHeadersOptions {
|
|
78
|
+
/** Include device info from navigator */
|
|
79
|
+
includeDevice?: boolean;
|
|
80
|
+
/** Include network from Connection API */
|
|
81
|
+
includeNetwork?: boolean;
|
|
82
|
+
/** Include calculated recommendations */
|
|
83
|
+
includeAdaptive?: boolean;
|
|
84
|
+
/** Include browser/app detection */
|
|
85
|
+
includePlatform?: boolean;
|
|
86
|
+
/** Include performance metrics */
|
|
87
|
+
includePerformance?: boolean;
|
|
88
|
+
/** Include compliance-related headers */
|
|
89
|
+
includeCompliance?: boolean;
|
|
90
|
+
/** Preset configuration for common scenarios */
|
|
91
|
+
preset?: 'minimal' | 'standard' | 'full' | 'low-data' | 'high-performance' | 'compliance-strict';
|
|
92
|
+
/** Auto-detect region from timezone/locale/IP */
|
|
93
|
+
autoDetectRegion?: boolean;
|
|
94
|
+
/** Force specific compliance preset */
|
|
95
|
+
regionalPreset?: 'gdpr' | 'ccpa' | 'pipl' | 'appi' | 'global';
|
|
96
|
+
/** Force specific region code (e.g., 'eu', 'us-ca') */
|
|
97
|
+
region?: string;
|
|
98
|
+
/** Show consent UI if needed (placeholder, not implemented) */
|
|
99
|
+
requestConsent?: boolean;
|
|
100
|
+
/** Honor DNT (Do Not Track) header */
|
|
101
|
+
respectDoNotTrack?: boolean;
|
|
102
|
+
/** Use timezone for region detection */
|
|
103
|
+
useTimezone?: boolean;
|
|
104
|
+
/** Use browser locale for region detection */
|
|
105
|
+
useLocale?: boolean;
|
|
106
|
+
/** Use CDN headers (server-side only) */
|
|
107
|
+
useCDNHeaders?: boolean;
|
|
108
|
+
/** Use IP-based detection (requires server) */
|
|
109
|
+
useIPDetection?: boolean;
|
|
110
|
+
/** Use geolocation API (requires permission) */
|
|
111
|
+
useGeolocation?: boolean;
|
|
112
|
+
/** Default region if all detection methods fail */
|
|
113
|
+
fallbackRegion?: string;
|
|
114
|
+
/** Cache expiration in milliseconds */
|
|
115
|
+
cacheExpiry?: number;
|
|
116
|
+
/** Caching configuration for detection results */
|
|
117
|
+
cache?: {
|
|
118
|
+
/** Enable caching of detection results */
|
|
119
|
+
enabled?: boolean;
|
|
120
|
+
/** Time to live in milliseconds */
|
|
121
|
+
ttl?: number;
|
|
122
|
+
/** Storage type for cached data */
|
|
123
|
+
storage?: 'memory' | 'session' | 'local';
|
|
124
|
+
/** Custom storage key */
|
|
125
|
+
key?: string;
|
|
126
|
+
};
|
|
127
|
+
/** Master switch for enriched headers feature */
|
|
128
|
+
enabled?: boolean;
|
|
129
|
+
/** Store headers in AsyncLocalStorage context */
|
|
130
|
+
useContext?: boolean;
|
|
131
|
+
/** Headers to exclude from collection */
|
|
132
|
+
exclude?: string[];
|
|
133
|
+
/** Headers to always include even if preset excludes them */
|
|
134
|
+
include?: string[];
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Result of header validation
|
|
138
|
+
* Contains validation status with detailed error and warning messages
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```typescript
|
|
142
|
+
* const result: HeaderValidationResult = {
|
|
143
|
+
* isValid: false,
|
|
144
|
+
* errors: ['Missing authorization header', 'Invalid content-type'],
|
|
145
|
+
* warnings: ['Deprecated header format used']
|
|
146
|
+
* };
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
export interface HeaderValidationResult {
|
|
150
|
+
/** Whether the headers are valid */
|
|
151
|
+
isValid: boolean;
|
|
152
|
+
/** Array of validation error messages */
|
|
153
|
+
errors: string[];
|
|
154
|
+
/** Array of validation warning messages */
|
|
155
|
+
warnings: string[];
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Build enriched context headers from request context
|
|
159
|
+
*/
|
|
160
|
+
export interface RequestContext {
|
|
161
|
+
request?: {
|
|
162
|
+
headers?: Record<string, string | string[] | undefined>;
|
|
163
|
+
ip?: string;
|
|
164
|
+
method?: string;
|
|
165
|
+
url?: string;
|
|
166
|
+
[key: string]: unknown;
|
|
167
|
+
};
|
|
168
|
+
clientContext?: ApiClientInstance;
|
|
169
|
+
[key: string]: unknown;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Header merge strategy
|
|
173
|
+
*/
|
|
174
|
+
export type HeaderMergeStrategy = 'overwrite' | 'combine' | 'preserve';
|
|
175
|
+
/**
|
|
176
|
+
* Options for header merging
|
|
177
|
+
*/
|
|
178
|
+
export interface HeaderMergeOptions {
|
|
179
|
+
/** Strategy for handling conflicting headers */
|
|
180
|
+
strategy?: HeaderMergeStrategy;
|
|
181
|
+
/** Headers that should never be overwritten */
|
|
182
|
+
immutableHeaders?: string[];
|
|
183
|
+
/** Custom conflict resolver function */
|
|
184
|
+
conflictResolver?: (key: string, existingValue: string, newValue: string) => string;
|
|
185
|
+
/** Whether to emit events for conflicts and merges */
|
|
186
|
+
emitEvents?: boolean;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Header merge result with conflict tracking
|
|
190
|
+
*/
|
|
191
|
+
export interface HeaderMergeResult {
|
|
192
|
+
/** Merged headers */
|
|
193
|
+
headers: ApiHeaders;
|
|
194
|
+
/** Any conflicts that occurred during merging */
|
|
195
|
+
conflicts: Array<{
|
|
196
|
+
header: string;
|
|
197
|
+
sources: Array<{
|
|
198
|
+
source: DebuggerConfigSource;
|
|
199
|
+
value: string;
|
|
200
|
+
priority: number;
|
|
201
|
+
}>;
|
|
202
|
+
}>;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Extracted header categories from request processing
|
|
206
|
+
* Groups headers by their source type for organized middleware handling
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* ```typescript
|
|
210
|
+
* const extraction: RequestHeaderExtraction = {
|
|
211
|
+
* clientHints: { 'ECT': '4g', 'RTT': '50' },
|
|
212
|
+
* deviceInfo: { 'x-device-memory': '8' },
|
|
213
|
+
* networkInfo: { 'x-network-quality': 'good' }
|
|
214
|
+
* };
|
|
215
|
+
* ```
|
|
216
|
+
*/
|
|
217
|
+
export interface RequestHeaderExtraction {
|
|
218
|
+
/** Client hints headers from browser */
|
|
219
|
+
clientHints: ApiHeaders;
|
|
220
|
+
/** Device information headers */
|
|
221
|
+
deviceInfo: ApiHeaders;
|
|
222
|
+
/** Network information headers */
|
|
223
|
+
networkInfo: ApiHeaders;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Parameters for checking immutable header constraints
|
|
227
|
+
* Used internally during header merging to protect critical headers
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* ```typescript
|
|
231
|
+
* const params: ImmutableHeaderParams = {
|
|
232
|
+
* existingValue: 'Bearer token123',
|
|
233
|
+
* newValue: 'Bearer token456',
|
|
234
|
+
* key: 'authorization',
|
|
235
|
+
* normalizedKey: 'authorization',
|
|
236
|
+
* isImmutable: true,
|
|
237
|
+
* options: { immutableHeaders: ['authorization'] }
|
|
238
|
+
* };
|
|
239
|
+
* ```
|
|
240
|
+
*/
|
|
241
|
+
export interface ImmutableHeaderParams {
|
|
242
|
+
/** Existing header value (if any) */
|
|
243
|
+
existingValue: string | undefined;
|
|
244
|
+
/** New value attempting to be set */
|
|
245
|
+
newValue: string;
|
|
246
|
+
/** Original header key */
|
|
247
|
+
key: string;
|
|
248
|
+
/** Normalized lowercase header key */
|
|
249
|
+
normalizedKey: string;
|
|
250
|
+
/** Whether this header is marked as immutable */
|
|
251
|
+
isImmutable: boolean;
|
|
252
|
+
/** Header merge options including immutable list */
|
|
253
|
+
options: HeaderMergeOptions;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Parameters for resolving header conflicts during merging
|
|
257
|
+
* Provides all information needed to decide which value wins
|
|
258
|
+
*
|
|
259
|
+
* @example
|
|
260
|
+
* ```typescript
|
|
261
|
+
* const params: ConflictResolutionParams = {
|
|
262
|
+
* key: 'content-type',
|
|
263
|
+
* existingValue: 'application/json',
|
|
264
|
+
* newValue: 'application/xml',
|
|
265
|
+
* strategy: 'overwrite',
|
|
266
|
+
* conflictResolver: (key, existing, newVal) => newVal
|
|
267
|
+
* };
|
|
268
|
+
* ```
|
|
269
|
+
*/
|
|
270
|
+
export interface ConflictResolutionParams {
|
|
271
|
+
/** Header key with conflict */
|
|
272
|
+
key: string;
|
|
273
|
+
/** Current header value */
|
|
274
|
+
existingValue: string;
|
|
275
|
+
/** New value trying to be set */
|
|
276
|
+
newValue: string;
|
|
277
|
+
/** Merge strategy to apply */
|
|
278
|
+
strategy: HeaderMergeStrategy;
|
|
279
|
+
/** Optional custom resolver function */
|
|
280
|
+
conflictResolver?: HeaderMergeOptions['conflictResolver'];
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Parameters for processing a batch of new headers
|
|
284
|
+
* Used internally during header merge operations
|
|
285
|
+
*
|
|
286
|
+
* @example
|
|
287
|
+
* ```typescript
|
|
288
|
+
* const params: ProcessNewHeadersParams = {
|
|
289
|
+
* newHeaders: { 'content-type': 'application/json' },
|
|
290
|
+
* result: { 'authorization': 'Bearer token' },
|
|
291
|
+
* immutableSet: new Set(['authorization']),
|
|
292
|
+
* options: { strategy: 'overwrite' },
|
|
293
|
+
* strategy: 'overwrite',
|
|
294
|
+
* conflicts: []
|
|
295
|
+
* };
|
|
296
|
+
* ```
|
|
297
|
+
*/
|
|
298
|
+
export interface ProcessNewHeadersParams {
|
|
299
|
+
/** New headers to be merged */
|
|
300
|
+
newHeaders: ApiHeaders | undefined;
|
|
301
|
+
/** Result headers being built */
|
|
302
|
+
result: ApiHeaders;
|
|
303
|
+
/** Set of immutable header keys */
|
|
304
|
+
immutableSet: Set<string>;
|
|
305
|
+
/** Merge options */
|
|
306
|
+
options: HeaderMergeOptions;
|
|
307
|
+
/** Current merge strategy */
|
|
308
|
+
strategy: HeaderMergeStrategy;
|
|
309
|
+
/** Array collecting conflicts */
|
|
310
|
+
conflicts: HeaderMergeResult['conflicts'];
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Parameters for processing a single header entry
|
|
314
|
+
* Contains all context needed to handle one header during merge
|
|
315
|
+
*
|
|
316
|
+
* @example
|
|
317
|
+
* ```typescript
|
|
318
|
+
* const params: ProcessSingleHeaderParams = {
|
|
319
|
+
* key: 'Content-Type',
|
|
320
|
+
* value: 'application/json',
|
|
321
|
+
* normalizedKey: 'content-type',
|
|
322
|
+
* existingValue: 'text/plain',
|
|
323
|
+
* isImmutable: false,
|
|
324
|
+
* options: { strategy: 'overwrite' },
|
|
325
|
+
* strategy: 'overwrite'
|
|
326
|
+
* };
|
|
327
|
+
* ```
|
|
328
|
+
*/
|
|
329
|
+
export interface ProcessSingleHeaderParams {
|
|
330
|
+
/** Original header key */
|
|
331
|
+
key: string;
|
|
332
|
+
/** Header value to set */
|
|
333
|
+
value: string;
|
|
334
|
+
/** Normalized lowercase key */
|
|
335
|
+
normalizedKey: string;
|
|
336
|
+
/** Existing value (if any) */
|
|
337
|
+
existingValue: string | undefined;
|
|
338
|
+
/** Whether header is immutable */
|
|
339
|
+
isImmutable: boolean;
|
|
340
|
+
/** Merge options */
|
|
341
|
+
options: HeaderMergeOptions;
|
|
342
|
+
/** Merge strategy */
|
|
343
|
+
strategy: HeaderMergeStrategy;
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Result of processing a single header
|
|
347
|
+
* Indicates the final value and whether a conflict occurred
|
|
348
|
+
*
|
|
349
|
+
* @example
|
|
350
|
+
* ```typescript
|
|
351
|
+
* const result: ProcessSingleHeaderResult = {
|
|
352
|
+
* value: 'application/json',
|
|
353
|
+
* conflict: {
|
|
354
|
+
* header: 'content-type',
|
|
355
|
+
* sources: [
|
|
356
|
+
* { source: 'global', value: 'text/plain', priority: 1 },
|
|
357
|
+
* { source: 'request', value: 'application/json', priority: 3 }
|
|
358
|
+
* ]
|
|
359
|
+
* }
|
|
360
|
+
* };
|
|
361
|
+
* ```
|
|
362
|
+
*/
|
|
363
|
+
export interface ProcessSingleHeaderResult {
|
|
364
|
+
/** Final resolved header value */
|
|
365
|
+
value: string | undefined;
|
|
366
|
+
/** Conflict information if one occurred */
|
|
367
|
+
conflict?: {
|
|
368
|
+
header: string;
|
|
369
|
+
sources: Array<{
|
|
370
|
+
source: DebuggerConfigSource;
|
|
371
|
+
value: string;
|
|
372
|
+
priority: number;
|
|
373
|
+
}>;
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Parameters for tracking header conflicts
|
|
378
|
+
* Accumulates conflict information during merge process
|
|
379
|
+
*
|
|
380
|
+
* @example
|
|
381
|
+
* ```typescript
|
|
382
|
+
* const params: ConflictTrackingParams = {
|
|
383
|
+
* conflicts: {},
|
|
384
|
+
* normalizedKey: 'content-type',
|
|
385
|
+
* value: 'application/json',
|
|
386
|
+
* priority: 3,
|
|
387
|
+
* originalSource: { source: 'request', value: 'application/json', priority: 3 }
|
|
388
|
+
* };
|
|
389
|
+
* ```
|
|
390
|
+
*/
|
|
391
|
+
export interface ConflictTrackingParams {
|
|
392
|
+
/** Map of conflicts by header key */
|
|
393
|
+
conflicts: Record<string, {
|
|
394
|
+
header: string;
|
|
395
|
+
sources: Array<{
|
|
396
|
+
source: DebuggerConfigSource;
|
|
397
|
+
value: string;
|
|
398
|
+
priority: number;
|
|
399
|
+
}>;
|
|
400
|
+
}>;
|
|
401
|
+
/** Normalized header key */
|
|
402
|
+
normalizedKey: string;
|
|
403
|
+
/** Header value */
|
|
404
|
+
value: string;
|
|
405
|
+
/** Priority level of this source */
|
|
406
|
+
priority: number;
|
|
407
|
+
/** Original source information */
|
|
408
|
+
originalSource: {
|
|
409
|
+
source: DebuggerConfigSource;
|
|
410
|
+
value: string;
|
|
411
|
+
priority: number;
|
|
412
|
+
} | null;
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* Network preset configuration
|
|
416
|
+
*/
|
|
417
|
+
export interface NetworkPresetConfig {
|
|
418
|
+
performance: PerformancePresetName;
|
|
419
|
+
cache: CacheStrategyName;
|
|
420
|
+
retry: RetryStrategyName;
|
|
421
|
+
revalidation: RevalidationStrategyName;
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Header preset factory functions for common scenarios
|
|
425
|
+
* Each preset returns headers configured for specific use cases
|
|
426
|
+
*
|
|
427
|
+
* @example
|
|
428
|
+
* ```typescript
|
|
429
|
+
* const presets: HeaderPresetName = {
|
|
430
|
+
* json: () => ({ 'content-type': 'application/json' }),
|
|
431
|
+
* bearerToken: (token) => ({ 'authorization': `Bearer ${token}` }),
|
|
432
|
+
* cors: () => ({ 'origin': '*', 'access-control-allow-methods': 'GET,POST' })
|
|
433
|
+
* };
|
|
434
|
+
*
|
|
435
|
+
* // Usage
|
|
436
|
+
* const headers = presets.json();
|
|
437
|
+
* const authHeaders = presets.bearerToken('my-token-123');
|
|
438
|
+
* ```
|
|
439
|
+
*/
|
|
440
|
+
export type HeaderPresetName = {
|
|
441
|
+
/** JSON content type headers */
|
|
442
|
+
readonly json: () => ApiHeaders;
|
|
443
|
+
/** Form data content type headers */
|
|
444
|
+
readonly form: () => ApiHeaders;
|
|
445
|
+
/** File upload headers (multipart/form-data) */
|
|
446
|
+
readonly upload: () => ApiHeaders;
|
|
447
|
+
/** XML content type headers */
|
|
448
|
+
readonly xml: () => ApiHeaders;
|
|
449
|
+
/** GraphQL API headers */
|
|
450
|
+
readonly graphql: () => ApiHeaders;
|
|
451
|
+
/** Server-Sent Events headers */
|
|
452
|
+
readonly sse: () => ApiHeaders;
|
|
453
|
+
/** AJAX request headers */
|
|
454
|
+
readonly ajax: () => ApiHeaders;
|
|
455
|
+
/** WebSocket upgrade headers */
|
|
456
|
+
readonly websocket: () => ApiHeaders;
|
|
457
|
+
/** Plain text content type headers */
|
|
458
|
+
readonly text: () => ApiHeaders;
|
|
459
|
+
/** HTML content type headers */
|
|
460
|
+
readonly html: () => ApiHeaders;
|
|
461
|
+
/** CORS headers */
|
|
462
|
+
readonly cors: () => ApiHeaders;
|
|
463
|
+
/** Cache-Control: no-cache headers */
|
|
464
|
+
readonly noCache: () => ApiHeaders;
|
|
465
|
+
/** Basic authentication headers */
|
|
466
|
+
readonly basicAuth: (username: string, password: string) => ApiHeaders;
|
|
467
|
+
/** Bearer token authentication headers */
|
|
468
|
+
readonly bearerToken: (token: string) => ApiHeaders;
|
|
469
|
+
/** API key authentication headers */
|
|
470
|
+
readonly apiKey: (apiKey: string) => ApiHeaders;
|
|
471
|
+
};
|
|
472
|
+
/**
|
|
473
|
+
* Interface representing the public API of HeaderBuilder
|
|
474
|
+
* Useful for type-checking without requiring the actual class instance
|
|
475
|
+
*
|
|
476
|
+
* This interface allows for:
|
|
477
|
+
* - Duck typing compatibility
|
|
478
|
+
* - Easier mocking in tests
|
|
479
|
+
* - Type-safe function parameters without importing the class
|
|
480
|
+
* - Clearer documentation of the public API contract
|
|
481
|
+
*
|
|
482
|
+
* @example
|
|
483
|
+
* ```typescript
|
|
484
|
+
* function buildHeaders(builder: HeaderBuilderLike): ApiHeaders {
|
|
485
|
+
* return builder
|
|
486
|
+
* .auth('token123')
|
|
487
|
+
* .contentType('json')
|
|
488
|
+
* .build();
|
|
489
|
+
* }
|
|
490
|
+
* ```
|
|
491
|
+
*/
|
|
492
|
+
export interface HeaderBuilderLike {
|
|
493
|
+
auth(token: string, type?: AuthType): HeaderBuilderLike;
|
|
494
|
+
contentType(type: ContentType): HeaderBuilderLike;
|
|
495
|
+
accept(type: AcceptType): HeaderBuilderLike;
|
|
496
|
+
locale(locale: string): HeaderBuilderLike;
|
|
497
|
+
platform(platform: PlatformType): HeaderBuilderLike;
|
|
498
|
+
tenant(tenantId: string): HeaderBuilderLike;
|
|
499
|
+
user(userId: string): HeaderBuilderLike;
|
|
500
|
+
version(version: string): HeaderBuilderLike;
|
|
501
|
+
features(flags: string[] | string): HeaderBuilderLike;
|
|
502
|
+
device(deviceId: string): HeaderBuilderLike;
|
|
503
|
+
session(sessionId: string): HeaderBuilderLike;
|
|
504
|
+
client(clientId: string): HeaderBuilderLike;
|
|
505
|
+
correlationId(id?: string): HeaderBuilderLike;
|
|
506
|
+
requestId(id?: string): HeaderBuilderLike;
|
|
507
|
+
traceId(traceId?: string): HeaderBuilderLike;
|
|
508
|
+
spanId(spanId: string): HeaderBuilderLike;
|
|
509
|
+
ajax(): HeaderBuilderLike;
|
|
510
|
+
custom(key: string, value: string): HeaderBuilderLike;
|
|
511
|
+
merge(headers: Record<string, string>): HeaderBuilderLike;
|
|
512
|
+
build(): ApiHeaders;
|
|
513
|
+
clear(): HeaderBuilderLike;
|
|
514
|
+
remove(key: string): HeaderBuilderLike;
|
|
515
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type * from './types';
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import type { NETWORK_QUALITY, NetworkInfo } from '..';
|
|
2
|
+
import type { ConfigConflict, DebugInfo, MonitoringAlert } from '../debugger';
|
|
3
|
+
/**
|
|
4
|
+
* Hook options for conflict monitoring
|
|
5
|
+
*/
|
|
6
|
+
export interface UseApiConfigConflictsOptions {
|
|
7
|
+
/** Enable automatic conflict checking */
|
|
8
|
+
autoCheck?: boolean;
|
|
9
|
+
/** Interval for automatic checks (ms) */
|
|
10
|
+
interval?: number;
|
|
11
|
+
/** Handler for individual conflicts */
|
|
12
|
+
onConflict?: (conflict: ConfigConflict) => void;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Hook return value
|
|
16
|
+
*/
|
|
17
|
+
export interface UseApiConfigConflictsReturn {
|
|
18
|
+
/** Current conflicts */
|
|
19
|
+
conflicts: ConfigConflict[];
|
|
20
|
+
/** Whether currently checking */
|
|
21
|
+
isChecking: boolean;
|
|
22
|
+
/** Last check timestamp */
|
|
23
|
+
lastCheck: Date | null;
|
|
24
|
+
/** Manually trigger check */
|
|
25
|
+
checkNow: () => Promise<void>;
|
|
26
|
+
/** Clear all conflicts */
|
|
27
|
+
clearConflicts: () => void;
|
|
28
|
+
/** Number of conflicts */
|
|
29
|
+
conflictCount: number;
|
|
30
|
+
/** Whether there are any conflicts */
|
|
31
|
+
hasConflicts: boolean;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Hook options for debug info monitoring
|
|
35
|
+
*/
|
|
36
|
+
export interface UseApiDebugInfoOptions {
|
|
37
|
+
/** Enable automatic refresh */
|
|
38
|
+
autoRefresh?: boolean;
|
|
39
|
+
/** Refresh interval (ms) */
|
|
40
|
+
interval?: number;
|
|
41
|
+
/** Handler for debug info updates */
|
|
42
|
+
onUpdate?: (debugInfo: DebugInfo) => void;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Hook return value
|
|
46
|
+
*/
|
|
47
|
+
export interface UseApiDebugInfoReturn {
|
|
48
|
+
/** Current debug information */
|
|
49
|
+
debugInfo: DebugInfo | null;
|
|
50
|
+
/** Whether currently loading */
|
|
51
|
+
isLoading: boolean;
|
|
52
|
+
/** Last update timestamp */
|
|
53
|
+
lastUpdate: Date | null;
|
|
54
|
+
/** Manually refresh debug info */
|
|
55
|
+
refresh: () => Promise<void>;
|
|
56
|
+
/** Active configuration overrides */
|
|
57
|
+
activeOverrides: DebugInfo['activeOverrides'];
|
|
58
|
+
/** Performance score */
|
|
59
|
+
performanceScore: number | undefined;
|
|
60
|
+
/** Network quality */
|
|
61
|
+
networkQuality: DebugInfo['networkQuality'] | undefined;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Hook options for complete monitoring
|
|
65
|
+
*/
|
|
66
|
+
export interface UseApiMonitorOptions {
|
|
67
|
+
/** Enable conflict checking */
|
|
68
|
+
enableConflictCheck?: boolean;
|
|
69
|
+
/** Conflict check interval (ms) */
|
|
70
|
+
conflictCheckInterval?: number;
|
|
71
|
+
/** Enable debug info generation */
|
|
72
|
+
enableDebugInfo?: boolean;
|
|
73
|
+
/** Debug info interval (ms) */
|
|
74
|
+
debugInfoInterval?: number;
|
|
75
|
+
/** Handler for monitoring alerts */
|
|
76
|
+
onAlert?: (alert: MonitoringAlert) => void;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Hook return value
|
|
80
|
+
*/
|
|
81
|
+
export interface UseApiMonitorReturn {
|
|
82
|
+
/** Current conflicts */
|
|
83
|
+
conflicts: UseApiConfigConflictsReturn['conflicts'];
|
|
84
|
+
/** Whether there are conflicts */
|
|
85
|
+
hasConflicts: boolean;
|
|
86
|
+
/** Number of conflicts */
|
|
87
|
+
conflictCount: number;
|
|
88
|
+
/** Manually check conflicts */
|
|
89
|
+
checkConflicts: () => Promise<void>;
|
|
90
|
+
/** Debug information */
|
|
91
|
+
debugInfo: UseApiDebugInfoReturn['debugInfo'];
|
|
92
|
+
/** Active overrides */
|
|
93
|
+
activeOverrides: UseApiDebugInfoReturn['activeOverrides'];
|
|
94
|
+
/** Performance score */
|
|
95
|
+
performanceScore: number | undefined;
|
|
96
|
+
/** Network quality */
|
|
97
|
+
networkQuality: UseApiDebugInfoReturn['networkQuality'];
|
|
98
|
+
/** Refresh debug info */
|
|
99
|
+
refreshDebugInfo: () => Promise<void>;
|
|
100
|
+
/** Whether monitoring is active */
|
|
101
|
+
isMonitoring: boolean;
|
|
102
|
+
/** Start monitoring */
|
|
103
|
+
startMonitoring: () => void;
|
|
104
|
+
/** Stop monitoring */
|
|
105
|
+
stopMonitoring: () => void;
|
|
106
|
+
/** Last conflict check */
|
|
107
|
+
lastConflictCheck: Date | null;
|
|
108
|
+
/** Last debug update */
|
|
109
|
+
lastDebugUpdate: Date | null;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Hook return value
|
|
113
|
+
*/
|
|
114
|
+
export interface UseApiNetworkQualityReturn {
|
|
115
|
+
/** Current network quality */
|
|
116
|
+
quality: NETWORK_QUALITY;
|
|
117
|
+
/** Network information */
|
|
118
|
+
networkInfo: NetworkInfo;
|
|
119
|
+
/** Whether online */
|
|
120
|
+
isOnline: boolean;
|
|
121
|
+
/** Whether connection is slow */
|
|
122
|
+
isSlow: boolean;
|
|
123
|
+
/** Whether data saver is enabled */
|
|
124
|
+
isDataSaver: boolean;
|
|
125
|
+
/** Effective connection type */
|
|
126
|
+
effectiveType: NetworkInfo['effectiveType'];
|
|
127
|
+
/** Round-trip time */
|
|
128
|
+
rtt: NetworkInfo['rtt'];
|
|
129
|
+
/** Downlink speed */
|
|
130
|
+
downlink: NetworkInfo['downlink'];
|
|
131
|
+
}
|
package/dist/api/index.d.ts
CHANGED
|
@@ -7,7 +7,8 @@ export type * from './errors';
|
|
|
7
7
|
export type * from './queue';
|
|
8
8
|
export type * from './headers';
|
|
9
9
|
export type * from './network';
|
|
10
|
-
export type * from './
|
|
10
|
+
export type * from './endpoints';
|
|
11
|
+
export type * from './debugger';
|
|
11
12
|
export type * from './cache';
|
|
12
13
|
export type * from './retry';
|
|
13
14
|
export type * from './polling';
|
|
@@ -15,5 +16,10 @@ export type * from './revalidation';
|
|
|
15
16
|
export type * from './strategies';
|
|
16
17
|
export type * from './client';
|
|
17
18
|
export type * from './performance';
|
|
19
|
+
export type * from './request';
|
|
20
|
+
export type * from './regional';
|
|
21
|
+
export type * from './retry';
|
|
18
22
|
export type * from './config';
|
|
19
23
|
export type * from './utils';
|
|
24
|
+
export type * from './pubsub';
|
|
25
|
+
export type * from './hooks';
|