@npora/request 1.6.0 → 1.8.0
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/README.md +21 -0
- package/dist/index.cjs +2653 -3236
- package/dist/index.d.cts +697 -597
- package/dist/index.d.ts +697 -597
- package/dist/index.js +2637 -3195
- package/package.json +7 -5
package/dist/index.d.cts
CHANGED
|
@@ -1,207 +1,228 @@
|
|
|
1
|
+
//#region src/types/method.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* HTTP request method.
|
|
3
4
|
*/
|
|
4
5
|
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS';
|
|
5
|
-
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region src/types/extensions.d.ts
|
|
6
8
|
type CircuitState = 'closed' | 'open' | 'half-open';
|
|
7
9
|
interface CircuitBreakerOptions {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Enable circuit-breaker protection for this request.
|
|
12
|
+
*
|
|
13
|
+
* @default true
|
|
14
|
+
*/
|
|
15
|
+
enabled?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Override the isolation key for this request.
|
|
18
|
+
*/
|
|
19
|
+
key?: string;
|
|
18
20
|
}
|
|
19
21
|
interface CircuitBreakerStateChange {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
key: string;
|
|
23
|
+
previousState: CircuitState;
|
|
24
|
+
state: CircuitState;
|
|
25
|
+
timestamp: number;
|
|
26
|
+
failures: number;
|
|
25
27
|
}
|
|
26
28
|
/**
|
|
27
29
|
* Per-request retry configuration used by the retry extension.
|
|
28
30
|
*/
|
|
29
31
|
interface RetryOptions {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
32
|
+
retries?: number;
|
|
33
|
+
/**
|
|
34
|
+
* HTTP methods that may be retried.
|
|
35
|
+
*
|
|
36
|
+
* @default GET, HEAD, OPTIONS, PUT and DELETE
|
|
37
|
+
*/
|
|
38
|
+
methods?: readonly HttpMethod[];
|
|
39
|
+
delay?: number | ((attempt: number, error: unknown) => number | Promise<number>);
|
|
40
|
+
/**
|
|
41
|
+
* Respect the server Retry-After response header.
|
|
42
|
+
*
|
|
43
|
+
* @default true
|
|
44
|
+
*/
|
|
45
|
+
respectRetryAfter?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Maximum retry delay in milliseconds.
|
|
48
|
+
*
|
|
49
|
+
* @default 60000
|
|
50
|
+
*/
|
|
51
|
+
maxDelay?: number;
|
|
52
|
+
/**
|
|
53
|
+
* Randomize the configured retry delay.
|
|
54
|
+
*
|
|
55
|
+
* `true` applies full jitter between zero and the configured delay.
|
|
56
|
+
* A function receives the pending retry event and returns the final delay.
|
|
57
|
+
* Server-provided Retry-After delays are not jittered.
|
|
58
|
+
*
|
|
59
|
+
* @default false
|
|
60
|
+
*/
|
|
61
|
+
jitter?: boolean | ((event: RetryEvent) => number | Promise<number>);
|
|
62
|
+
/**
|
|
63
|
+
* Maximum elapsed time across the initial request, retries and planned
|
|
64
|
+
* retry delays.
|
|
65
|
+
*
|
|
66
|
+
* @default unlimited
|
|
67
|
+
*/
|
|
68
|
+
maxElapsedTime?: number;
|
|
69
|
+
shouldRetry?: (error: unknown, attempt: number) => boolean | Promise<boolean>;
|
|
70
|
+
/**
|
|
71
|
+
* Observe a scheduled retry.
|
|
72
|
+
*
|
|
73
|
+
* Callback failures are isolated from the request lifecycle.
|
|
74
|
+
*/
|
|
75
|
+
onRetry?: (event: RetryEvent) => void | Promise<void>;
|
|
74
76
|
}
|
|
75
77
|
interface RetryEvent {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
78
|
+
/**
|
|
79
|
+
* One-based retry number.
|
|
80
|
+
*/
|
|
81
|
+
attempt: number;
|
|
82
|
+
/**
|
|
83
|
+
* Final delay before this retry in milliseconds.
|
|
84
|
+
*/
|
|
85
|
+
delay: number;
|
|
86
|
+
/**
|
|
87
|
+
* Time elapsed since the request started in milliseconds.
|
|
88
|
+
*/
|
|
89
|
+
elapsedTime: number;
|
|
90
|
+
error: unknown;
|
|
89
91
|
}
|
|
90
92
|
interface CacheOptions {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
93
|
+
enabled?: boolean;
|
|
94
|
+
ttl?: number;
|
|
95
|
+
key?: string;
|
|
96
|
+
/**
|
|
97
|
+
* Share one network operation between concurrent equivalent requests.
|
|
98
|
+
*
|
|
99
|
+
* @default true
|
|
100
|
+
*/
|
|
101
|
+
dedupe?: boolean;
|
|
102
|
+
}
|
|
103
|
+
interface ConcurrencyOptions {
|
|
104
|
+
/**
|
|
105
|
+
* Enable concurrency limiting for this request.
|
|
106
|
+
*
|
|
107
|
+
* @default true
|
|
108
|
+
*/
|
|
109
|
+
enabled?: boolean;
|
|
110
|
+
/**
|
|
111
|
+
* Override the isolation key for this request.
|
|
112
|
+
*/
|
|
113
|
+
key?: string;
|
|
114
|
+
/**
|
|
115
|
+
* Maximum time in milliseconds this request may wait for a permit.
|
|
116
|
+
*
|
|
117
|
+
* @default the plugin-level queueTimeout
|
|
118
|
+
*/
|
|
119
|
+
queueTimeout?: number;
|
|
100
120
|
}
|
|
101
121
|
interface AuthOptions {
|
|
102
|
-
|
|
103
|
-
|
|
122
|
+
token?: string | (() => string | Promise<string>);
|
|
123
|
+
scheme?: string;
|
|
104
124
|
}
|
|
105
125
|
interface LoggerOptions {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
126
|
+
enabled?: boolean;
|
|
127
|
+
/**
|
|
128
|
+
* Structured log destination.
|
|
129
|
+
*
|
|
130
|
+
* @default console
|
|
131
|
+
*/
|
|
132
|
+
logger?: RequestLogger;
|
|
133
|
+
/**
|
|
134
|
+
* Create the identifier shared by all lifecycle entries for a request.
|
|
135
|
+
*
|
|
136
|
+
* @default a plugin-local monotonic identifier
|
|
137
|
+
*/
|
|
138
|
+
createRequestId?: () => string;
|
|
119
139
|
}
|
|
120
140
|
interface RequestLogEntry {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
141
|
+
type: 'request';
|
|
142
|
+
requestId: string;
|
|
143
|
+
timestamp: number;
|
|
144
|
+
method: HttpMethod;
|
|
145
|
+
url: string;
|
|
126
146
|
}
|
|
127
147
|
interface ResponseLogEntry {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
148
|
+
type: 'response';
|
|
149
|
+
requestId: string;
|
|
150
|
+
timestamp: number;
|
|
151
|
+
duration: number;
|
|
152
|
+
attempts: number;
|
|
153
|
+
method: HttpMethod;
|
|
154
|
+
url: string;
|
|
155
|
+
status: number;
|
|
136
156
|
}
|
|
137
157
|
interface ErrorLogEntry {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
158
|
+
type: 'error';
|
|
159
|
+
requestId: string;
|
|
160
|
+
timestamp: number;
|
|
161
|
+
duration: number;
|
|
162
|
+
attempt: number;
|
|
163
|
+
method: HttpMethod;
|
|
164
|
+
url: string;
|
|
165
|
+
name: string;
|
|
166
|
+
message: string;
|
|
167
|
+
code?: string;
|
|
168
|
+
status?: number;
|
|
149
169
|
}
|
|
150
170
|
type LoggerEntry = RequestLogEntry | ResponseLogEntry | ErrorLogEntry;
|
|
151
171
|
interface RequestLogger {
|
|
152
|
-
|
|
153
|
-
|
|
172
|
+
info(message: string, entry: RequestLogEntry | ResponseLogEntry): void | Promise<void>;
|
|
173
|
+
error(message: string, entry: ErrorLogEntry): void | Promise<void>;
|
|
154
174
|
}
|
|
155
175
|
type UploadData = FormData | Record<string, unknown>;
|
|
156
176
|
/**
|
|
157
177
|
* Upload progress information.
|
|
158
178
|
*/
|
|
159
179
|
interface UploadProgress {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
180
|
+
/**
|
|
181
|
+
* Number of bytes sent.
|
|
182
|
+
*/
|
|
183
|
+
loaded: number;
|
|
184
|
+
/**
|
|
185
|
+
* Total request size when the browser provides it.
|
|
186
|
+
*/
|
|
187
|
+
total?: number;
|
|
188
|
+
/**
|
|
189
|
+
* Progress ratio between 0 and 1 when total is available.
|
|
190
|
+
*/
|
|
191
|
+
progress?: number;
|
|
172
192
|
}
|
|
173
193
|
interface UploadOptions {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
194
|
+
data: UploadData;
|
|
195
|
+
/**
|
|
196
|
+
* Called while XMLHttpRequest uploads the request body.
|
|
197
|
+
*/
|
|
198
|
+
onProgress?: (progress: UploadProgress) => void;
|
|
179
199
|
}
|
|
180
200
|
/**
|
|
181
201
|
* Download progress information.
|
|
182
202
|
*/
|
|
183
203
|
interface DownloadProgress {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
204
|
+
/**
|
|
205
|
+
* Number of bytes received.
|
|
206
|
+
*/
|
|
207
|
+
loaded: number;
|
|
208
|
+
/**
|
|
209
|
+
* Total response size when Content-Length is available.
|
|
210
|
+
*/
|
|
211
|
+
total?: number;
|
|
212
|
+
/**
|
|
213
|
+
* Progress ratio between 0 and 1 when total is available.
|
|
214
|
+
*/
|
|
215
|
+
progress?: number;
|
|
196
216
|
}
|
|
197
217
|
interface DownloadOptions {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
}
|
|
204
|
-
|
|
218
|
+
filename?: string;
|
|
219
|
+
/**
|
|
220
|
+
* Called while the response stream is being consumed.
|
|
221
|
+
*/
|
|
222
|
+
onProgress?: (progress: DownloadProgress) => void;
|
|
223
|
+
}
|
|
224
|
+
//#endregion
|
|
225
|
+
//#region src/types/config.d.ts
|
|
205
226
|
type QueryValue = string | number | boolean | null | undefined;
|
|
206
227
|
type QueryParams = Record<string, QueryValue | QueryValue[]>;
|
|
207
228
|
type ResponseType = 'json' | 'text' | 'blob' | 'arrayBuffer' | 'stream';
|
|
@@ -218,360 +239,387 @@ type FetchOptions = Omit<RequestInit, 'method' | 'headers' | 'body' | 'signal'>;
|
|
|
218
239
|
* Plugins extend this interface through TypeScript module augmentation.
|
|
219
240
|
*/
|
|
220
241
|
interface RequestExtensions {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
242
|
+
auth?: AuthOptions;
|
|
243
|
+
cache?: CacheOptions;
|
|
244
|
+
circuitBreaker?: CircuitBreakerOptions;
|
|
245
|
+
concurrency?: ConcurrencyOptions;
|
|
246
|
+
download?: DownloadOptions;
|
|
247
|
+
logger?: LoggerOptions;
|
|
248
|
+
retry?: number | RetryOptions;
|
|
249
|
+
upload?: UploadOptions;
|
|
228
250
|
}
|
|
229
251
|
interface RequestConfig {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
252
|
+
url: string;
|
|
253
|
+
method?: HttpMethod;
|
|
254
|
+
baseURL?: string;
|
|
255
|
+
fetchOptions?: FetchOptions;
|
|
256
|
+
headers?: HeadersInit;
|
|
257
|
+
query?: QueryParams;
|
|
258
|
+
body?: BodyInit | Record<string, unknown> | null;
|
|
259
|
+
json?: Record<string, unknown> | unknown[];
|
|
260
|
+
form?: URLSearchParams | Record<string, QueryValue | QueryValue[]>;
|
|
261
|
+
formData?: FormData | Record<string, unknown>;
|
|
262
|
+
timeout?: number;
|
|
263
|
+
signal?: AbortSignal;
|
|
264
|
+
/**
|
|
265
|
+
* Maximum parsed response body size in bytes.
|
|
266
|
+
*
|
|
267
|
+
* @default unlimited
|
|
268
|
+
*/
|
|
269
|
+
maxResponseSize?: number;
|
|
270
|
+
/**
|
|
271
|
+
* Maximum nested array depth accepted while building FormData.
|
|
272
|
+
*
|
|
273
|
+
* @default 32
|
|
274
|
+
*/
|
|
275
|
+
maxFormDataDepth?: number;
|
|
276
|
+
responseType?: ResponseType;
|
|
277
|
+
validateStatus?: (status: number) => boolean;
|
|
278
|
+
extensions?: RequestExtensions;
|
|
279
|
+
}
|
|
280
|
+
//#endregion
|
|
281
|
+
//#region src/types/response.d.ts
|
|
247
282
|
/**
|
|
248
283
|
* Npora response.
|
|
249
284
|
*/
|
|
250
285
|
interface NporaResponse<T = unknown> {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
}
|
|
276
|
-
|
|
286
|
+
/**
|
|
287
|
+
* Parsed response data.
|
|
288
|
+
*/
|
|
289
|
+
data: T;
|
|
290
|
+
/**
|
|
291
|
+
* HTTP status code.
|
|
292
|
+
*/
|
|
293
|
+
status: number;
|
|
294
|
+
/**
|
|
295
|
+
* HTTP status text.
|
|
296
|
+
*/
|
|
297
|
+
statusText: string;
|
|
298
|
+
/**
|
|
299
|
+
* Response headers.
|
|
300
|
+
*/
|
|
301
|
+
headers: Headers;
|
|
302
|
+
/**
|
|
303
|
+
* Request config.
|
|
304
|
+
*/
|
|
305
|
+
config: RequestConfig;
|
|
306
|
+
/**
|
|
307
|
+
* Raw Fetch Response.
|
|
308
|
+
*/
|
|
309
|
+
raw: Response;
|
|
310
|
+
}
|
|
311
|
+
//#endregion
|
|
312
|
+
//#region src/types/adapter.d.ts
|
|
277
313
|
/**
|
|
278
314
|
* Request adapter.
|
|
279
315
|
*/
|
|
280
316
|
interface Adapter {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
}
|
|
294
|
-
|
|
317
|
+
/**
|
|
318
|
+
* Send request.
|
|
319
|
+
*/
|
|
320
|
+
request<T = unknown>(config: RequestConfig): Promise<NporaResponse<T>>;
|
|
321
|
+
/**
|
|
322
|
+
* Optional first-attempt fast path for built-in adapters.
|
|
323
|
+
*
|
|
324
|
+
* Custom adapters do not need to implement this method.
|
|
325
|
+
*
|
|
326
|
+
* @internal
|
|
327
|
+
*/
|
|
328
|
+
requestValidated?<T = unknown>(config: RequestConfig, validatedHeaders: Headers, preserveRaw?: boolean): Promise<NporaResponse<T>>;
|
|
329
|
+
}
|
|
330
|
+
//#endregion
|
|
331
|
+
//#region src/types/client.d.ts
|
|
295
332
|
/**
|
|
296
333
|
* Client creation options.
|
|
297
334
|
*/
|
|
298
335
|
interface ClientOptions extends Partial<Omit<RequestConfig, 'url' | 'method'>> {
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
}
|
|
306
|
-
|
|
336
|
+
/**
|
|
337
|
+
* Request adapter.
|
|
338
|
+
*
|
|
339
|
+
* @default FetchAdapter
|
|
340
|
+
*/
|
|
341
|
+
adapter?: Adapter;
|
|
342
|
+
}
|
|
343
|
+
//#endregion
|
|
344
|
+
//#region src/adapters/FetchAdapter.d.ts
|
|
307
345
|
declare class FetchAdapter implements Adapter {
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
346
|
+
request<T = unknown>(config: RequestConfig): Promise<NporaResponse<T>>;
|
|
347
|
+
requestValidated<T = unknown>(config: RequestConfig, validatedHeaders: Headers, preserveRaw?: boolean): Promise<NporaResponse<T>>;
|
|
348
|
+
private execute;
|
|
311
349
|
}
|
|
312
|
-
|
|
350
|
+
//#endregion
|
|
351
|
+
//#region src/adapters/MockAdapter.d.ts
|
|
313
352
|
type MockHandler<T = unknown> = (config: RequestConfig) => T | Promise<T>;
|
|
314
353
|
type MockURLMatcher = string | RegExp;
|
|
315
354
|
interface MockRequestMatcher {
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
355
|
+
url: MockURLMatcher;
|
|
356
|
+
query?: QueryParams;
|
|
357
|
+
headers?: HeadersInit;
|
|
319
358
|
}
|
|
320
359
|
interface MockReply<T = unknown> {
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
360
|
+
status: number;
|
|
361
|
+
data?: T;
|
|
362
|
+
headers?: HeadersInit;
|
|
363
|
+
statusText?: string;
|
|
364
|
+
delay?: number;
|
|
326
365
|
}
|
|
327
366
|
type MockReplyHandler<T = unknown> = (config: RequestConfig) => MockReply<T> | Promise<MockReply<T>>;
|
|
328
367
|
interface MockResponseOptions {
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
368
|
+
headers?: HeadersInit;
|
|
369
|
+
statusText?: string;
|
|
370
|
+
delay?: number;
|
|
332
371
|
}
|
|
333
372
|
interface MockRoute {
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
373
|
+
reply<T = unknown>(handler: MockReplyHandler<T>): MockAdapter;
|
|
374
|
+
reply<T = unknown>(status: number, data?: T, options?: MockResponseOptions): MockAdapter;
|
|
375
|
+
replyOnce<T = unknown>(handler: MockReplyHandler<T>): MockAdapter;
|
|
376
|
+
replyOnce<T = unknown>(status: number, data?: T, options?: MockResponseOptions): MockAdapter;
|
|
377
|
+
networkError(message?: string): MockAdapter;
|
|
378
|
+
networkErrorOnce(message?: string): MockAdapter;
|
|
379
|
+
timeout(message?: string): MockAdapter;
|
|
380
|
+
timeoutOnce(message?: string): MockAdapter;
|
|
342
381
|
}
|
|
343
382
|
interface MockAdapterOptions {
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
383
|
+
handlers?: Record<string, MockHandler>;
|
|
384
|
+
/**
|
|
385
|
+
* Default delay for mock handlers and routes.
|
|
386
|
+
*
|
|
387
|
+
* @default 0
|
|
388
|
+
*/
|
|
389
|
+
delay?: number;
|
|
351
390
|
}
|
|
352
391
|
declare class MockAdapter implements Adapter {
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
}
|
|
378
|
-
|
|
392
|
+
private readonly handlers;
|
|
393
|
+
private readonly rules;
|
|
394
|
+
private readonly requests;
|
|
395
|
+
private readonly delay;
|
|
396
|
+
constructor(options?: MockAdapterOptions);
|
|
397
|
+
get history(): readonly RequestConfig[];
|
|
398
|
+
/**
|
|
399
|
+
* Register a legacy URL-only data handler.
|
|
400
|
+
*/
|
|
401
|
+
on<T = unknown>(url: string, handler: MockHandler<T>): this;
|
|
402
|
+
onMethod(method: HttpMethod, matcher: MockURLMatcher | MockRequestMatcher): MockRoute;
|
|
403
|
+
onGet(matcher: MockURLMatcher | MockRequestMatcher): MockRoute;
|
|
404
|
+
onPost(matcher: MockURLMatcher | MockRequestMatcher): MockRoute;
|
|
405
|
+
onPut(matcher: MockURLMatcher | MockRequestMatcher): MockRoute;
|
|
406
|
+
onPatch(matcher: MockURLMatcher | MockRequestMatcher): MockRoute;
|
|
407
|
+
onDelete(matcher: MockURLMatcher | MockRequestMatcher): MockRoute;
|
|
408
|
+
onHead(matcher: MockURLMatcher | MockRequestMatcher): MockRoute;
|
|
409
|
+
onOptions(matcher: MockURLMatcher | MockRequestMatcher): MockRoute;
|
|
410
|
+
resetHistory(): this;
|
|
411
|
+
resetHandlers(): this;
|
|
412
|
+
reset(): this;
|
|
413
|
+
request<T = unknown>(config: RequestConfig): Promise<NporaResponse<T>>;
|
|
414
|
+
private registerReply;
|
|
415
|
+
private registerError;
|
|
416
|
+
}
|
|
417
|
+
//#endregion
|
|
418
|
+
//#region src/interceptors/InterceptorManager.d.ts
|
|
379
419
|
type Interceptor<T> = (value: T) => T | Promise<T>;
|
|
380
420
|
interface InterceptorOptions {
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
421
|
+
/**
|
|
422
|
+
* Higher priority interceptors run first.
|
|
423
|
+
*
|
|
424
|
+
* @default 0
|
|
425
|
+
*/
|
|
426
|
+
priority?: number;
|
|
387
427
|
}
|
|
388
428
|
declare class InterceptorManager<T> {
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
}
|
|
399
|
-
|
|
429
|
+
private id;
|
|
430
|
+
private readonly interceptors;
|
|
431
|
+
private orderedInterceptors;
|
|
432
|
+
get active(): boolean;
|
|
433
|
+
use(interceptor: Interceptor<T>, options?: InterceptorOptions): number;
|
|
434
|
+
eject(id: number): void;
|
|
435
|
+
clear(): void;
|
|
436
|
+
run(value: T): Promise<T>;
|
|
437
|
+
private refreshOrder;
|
|
438
|
+
}
|
|
439
|
+
//#endregion
|
|
440
|
+
//#region src/core/RequestContext.d.ts
|
|
400
441
|
declare class RequestContext<T = unknown> {
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
}
|
|
409
|
-
|
|
442
|
+
config: RequestConfig;
|
|
443
|
+
response?: NporaResponse<T>;
|
|
444
|
+
error?: unknown;
|
|
445
|
+
readonly startTime: number;
|
|
446
|
+
endTime?: number;
|
|
447
|
+
attempt: number;
|
|
448
|
+
constructor(config: RequestConfig);
|
|
449
|
+
}
|
|
450
|
+
//#endregion
|
|
451
|
+
//#region src/interceptors/PluginHooks.d.ts
|
|
410
452
|
interface RetryDecision {
|
|
411
|
-
|
|
412
|
-
|
|
453
|
+
retry: boolean;
|
|
454
|
+
delay?: number;
|
|
413
455
|
}
|
|
414
456
|
interface HookOptions {
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
457
|
+
/**
|
|
458
|
+
* Higher priority hooks run first.
|
|
459
|
+
*
|
|
460
|
+
* @default 0
|
|
461
|
+
*/
|
|
462
|
+
priority?: number;
|
|
421
463
|
}
|
|
422
464
|
type HookDisposer = () => void;
|
|
423
465
|
type RequestHook = (context: RequestContext<unknown>) => void | Promise<void>;
|
|
424
466
|
type RetryHook = (context: RequestContext<unknown>, attempt: number) => RetryDecision | undefined | Promise<RetryDecision | undefined>;
|
|
425
|
-
|
|
467
|
+
//#endregion
|
|
468
|
+
//#region src/plugins/Plugin.d.ts
|
|
426
469
|
interface PluginInterceptorManager<T> {
|
|
427
|
-
|
|
428
|
-
|
|
470
|
+
use(interceptor: Interceptor<T>, options?: InterceptorOptions): number;
|
|
471
|
+
eject(id: number): void;
|
|
429
472
|
}
|
|
430
473
|
interface PluginHookManager {
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
474
|
+
onRequest(hook: RequestHook, options?: HookOptions): HookDisposer;
|
|
475
|
+
onResponse(hook: RequestHook, options?: HookOptions): HookDisposer;
|
|
476
|
+
onError(hook: RequestHook, options?: HookOptions): HookDisposer;
|
|
477
|
+
/**
|
|
478
|
+
* Observe the final request outcome after retries and interceptors finish.
|
|
479
|
+
*
|
|
480
|
+
* Settled hook failures are isolated from the request result.
|
|
481
|
+
*/
|
|
482
|
+
onSettled(hook: RequestHook, options?: HookOptions): HookDisposer;
|
|
483
|
+
onRetry(hook: RetryHook, options?: HookOptions): HookDisposer;
|
|
441
484
|
}
|
|
442
485
|
interface PluginContext {
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
486
|
+
interceptors: {
|
|
487
|
+
request: PluginInterceptorManager<RequestConfig>;
|
|
488
|
+
response: PluginInterceptorManager<NporaResponse>;
|
|
489
|
+
error: PluginInterceptorManager<unknown>;
|
|
490
|
+
};
|
|
491
|
+
hooks: PluginHookManager;
|
|
449
492
|
}
|
|
450
493
|
type PluginCleanup = () => void;
|
|
451
494
|
interface Plugin {
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
}
|
|
470
|
-
|
|
495
|
+
name: string;
|
|
496
|
+
/**
|
|
497
|
+
* Default priority for interceptors and hooks registered by this plugin.
|
|
498
|
+
* Higher priority registrations run first.
|
|
499
|
+
*
|
|
500
|
+
* @default 0
|
|
501
|
+
*/
|
|
502
|
+
priority?: number;
|
|
503
|
+
/**
|
|
504
|
+
* Plugins that must already be installed.
|
|
505
|
+
*/
|
|
506
|
+
requires?: readonly string[];
|
|
507
|
+
/**
|
|
508
|
+
* Plugins that cannot be installed on the same client.
|
|
509
|
+
*/
|
|
510
|
+
conflicts?: readonly string[];
|
|
511
|
+
install: (context: PluginContext) => void | PluginCleanup;
|
|
512
|
+
}
|
|
513
|
+
//#endregion
|
|
514
|
+
//#region src/client/Client.d.ts
|
|
471
515
|
declare class Client {
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
}
|
|
510
|
-
|
|
516
|
+
private readonly defaults;
|
|
517
|
+
private readonly adapter;
|
|
518
|
+
private readonly installedPlugins;
|
|
519
|
+
private readonly hooks;
|
|
520
|
+
readonly interceptors: {
|
|
521
|
+
request: InterceptorManager<RequestConfig>;
|
|
522
|
+
response: InterceptorManager<NporaResponse<unknown>>;
|
|
523
|
+
error: InterceptorManager<unknown>;
|
|
524
|
+
};
|
|
525
|
+
private readonly pipeline;
|
|
526
|
+
constructor(options?: ClientOptions);
|
|
527
|
+
/**
|
|
528
|
+
* Create an isolated client that inherits this client's defaults.
|
|
529
|
+
*/
|
|
530
|
+
extend(options?: ClientOptions): Client;
|
|
531
|
+
use(plugin: Plugin): this;
|
|
532
|
+
unuse(pluginName: string): this;
|
|
533
|
+
hasPlugin(pluginName: string): boolean;
|
|
534
|
+
request<T = unknown>(config: RequestConfig): Promise<T>;
|
|
535
|
+
requestResponse<T = unknown>(config: RequestConfig): Promise<NporaResponse<T>>;
|
|
536
|
+
get<T = unknown>(url: string, config?: Omit<RequestConfig, 'url' | 'method'>): Promise<T>;
|
|
537
|
+
getResponse<T = unknown>(url: string, config?: Omit<RequestConfig, 'url' | 'method'>): Promise<NporaResponse<T>>;
|
|
538
|
+
post<T = unknown>(url: string, config?: Omit<RequestConfig, 'url' | 'method'>): Promise<T>;
|
|
539
|
+
postResponse<T = unknown>(url: string, config?: Omit<RequestConfig, 'url' | 'method'>): Promise<NporaResponse<T>>;
|
|
540
|
+
put<T = unknown>(url: string, config?: Omit<RequestConfig, 'url' | 'method'>): Promise<T>;
|
|
541
|
+
putResponse<T = unknown>(url: string, config?: Omit<RequestConfig, 'url' | 'method'>): Promise<NporaResponse<T>>;
|
|
542
|
+
patch<T = unknown>(url: string, config?: Omit<RequestConfig, 'url' | 'method'>): Promise<T>;
|
|
543
|
+
patchResponse<T = unknown>(url: string, config?: Omit<RequestConfig, 'url' | 'method'>): Promise<NporaResponse<T>>;
|
|
544
|
+
delete<T = unknown>(url: string, config?: Omit<RequestConfig, 'url' | 'method'>): Promise<T>;
|
|
545
|
+
deleteResponse<T = unknown>(url: string, config?: Omit<RequestConfig, 'url' | 'method'>): Promise<NporaResponse<T>>;
|
|
546
|
+
head(url: string, config?: Omit<RequestConfig, 'url' | 'method'>): Promise<void>;
|
|
547
|
+
headResponse(url: string, config?: Omit<RequestConfig, 'url' | 'method'>): Promise<NporaResponse<void>>;
|
|
548
|
+
options<T = unknown>(url: string, config?: Omit<RequestConfig, 'url' | 'method'>): Promise<T>;
|
|
549
|
+
optionsResponse<T = unknown>(url: string, config?: Omit<RequestConfig, 'url' | 'method'>): Promise<NporaResponse<T>>;
|
|
550
|
+
private createPipeline;
|
|
551
|
+
private validatePlugin;
|
|
552
|
+
private findDependent;
|
|
553
|
+
}
|
|
554
|
+
//#endregion
|
|
555
|
+
//#region src/client/createClient.d.ts
|
|
511
556
|
/**
|
|
512
557
|
* Create an HTTP client instance.
|
|
513
558
|
*/
|
|
514
559
|
declare function createClient(options?: ClientOptions): Client;
|
|
515
|
-
|
|
560
|
+
//#endregion
|
|
561
|
+
//#region src/errors/RequestError.d.ts
|
|
516
562
|
/**
|
|
517
563
|
* Public request error codes.
|
|
518
564
|
*/
|
|
519
|
-
type RequestErrorCode = 'CONFIG_ERROR' | 'HTTP_ERROR' | 'NETWORK_ERROR' | 'TIMEOUT_ERROR' | 'ABORT_ERROR' | 'PARSER_ERROR' | 'CIRCUIT_OPEN';
|
|
565
|
+
type RequestErrorCode = 'CONFIG_ERROR' | 'HTTP_ERROR' | 'NETWORK_ERROR' | 'TIMEOUT_ERROR' | 'ABORT_ERROR' | 'PARSER_ERROR' | 'RESPONSE_TOO_LARGE' | 'CIRCUIT_OPEN' | 'CONCURRENCY_LIMIT';
|
|
520
566
|
interface RequestErrorOptions<T = unknown> {
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
567
|
+
/**
|
|
568
|
+
* Stable machine-readable error code.
|
|
569
|
+
*/
|
|
570
|
+
code: RequestErrorCode;
|
|
571
|
+
/**
|
|
572
|
+
* HTTP response status when available.
|
|
573
|
+
*/
|
|
574
|
+
status?: number;
|
|
575
|
+
/**
|
|
576
|
+
* Parsed response body when the server returned a response.
|
|
577
|
+
*/
|
|
578
|
+
data?: T;
|
|
579
|
+
/**
|
|
580
|
+
* Complete response metadata when the server returned a response.
|
|
581
|
+
*/
|
|
582
|
+
response?: NporaResponse<T>;
|
|
583
|
+
/**
|
|
584
|
+
* Effective request configuration.
|
|
585
|
+
*/
|
|
586
|
+
config?: RequestConfig;
|
|
587
|
+
/**
|
|
588
|
+
* Original error.
|
|
589
|
+
*/
|
|
590
|
+
cause?: unknown;
|
|
545
591
|
}
|
|
546
592
|
/**
|
|
547
593
|
* Unified public error for all request failures.
|
|
548
594
|
*/
|
|
549
595
|
declare class RequestError<T = unknown> extends Error {
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
}
|
|
558
|
-
|
|
596
|
+
readonly code: RequestErrorCode;
|
|
597
|
+
readonly status?: number;
|
|
598
|
+
readonly data?: T;
|
|
599
|
+
readonly response?: NporaResponse<T>;
|
|
600
|
+
readonly config?: RequestConfig;
|
|
601
|
+
readonly cause?: unknown;
|
|
602
|
+
constructor(message: string, options: RequestErrorOptions<T>);
|
|
603
|
+
}
|
|
604
|
+
//#endregion
|
|
605
|
+
//#region src/plugins/PluginError.d.ts
|
|
559
606
|
type PluginErrorCode = 'MISSING_DEPENDENCY' | 'PLUGIN_CONFLICT' | 'DEPENDENCY_IN_USE';
|
|
560
607
|
interface PluginErrorOptions {
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
608
|
+
code: PluginErrorCode;
|
|
609
|
+
plugin: string;
|
|
610
|
+
relatedPlugin: string;
|
|
564
611
|
}
|
|
565
612
|
/**
|
|
566
613
|
* Stable error thrown for invalid plugin lifecycle operations.
|
|
567
614
|
*/
|
|
568
615
|
declare class PluginError extends Error {
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
616
|
+
readonly code: PluginErrorCode;
|
|
617
|
+
readonly plugin: string;
|
|
618
|
+
readonly relatedPlugin: string;
|
|
619
|
+
constructor(message: string, options: PluginErrorOptions);
|
|
573
620
|
}
|
|
574
|
-
|
|
621
|
+
//#endregion
|
|
622
|
+
//#region src/plugins/authPlugin.d.ts
|
|
575
623
|
type MaybePromise$1<T> = T | Promise<T>;
|
|
576
624
|
/**
|
|
577
625
|
* Token storage used by the authentication extension.
|
|
@@ -580,192 +628,244 @@ type MaybePromise$1<T> = T | Promise<T>;
|
|
|
580
628
|
* The request library does not access localStorage or sessionStorage directly.
|
|
581
629
|
*/
|
|
582
630
|
interface AuthTokenStorage {
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
631
|
+
get(): MaybePromise$1<string | null | undefined>;
|
|
632
|
+
set(token: string): MaybePromise$1<void>;
|
|
633
|
+
remove(): MaybePromise$1<void>;
|
|
586
634
|
}
|
|
587
635
|
interface AuthPluginOptions {
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
636
|
+
/**
|
|
637
|
+
* Access token or access-token provider.
|
|
638
|
+
*
|
|
639
|
+
* When both token and storage are provided,
|
|
640
|
+
* the request-level token has the highest priority,
|
|
641
|
+
* followed by this token option, then storage.
|
|
642
|
+
*/
|
|
643
|
+
token?: string | (() => MaybePromise$1<string>);
|
|
644
|
+
/**
|
|
645
|
+
* Authorization scheme.
|
|
646
|
+
*
|
|
647
|
+
* @default 'Bearer'
|
|
648
|
+
*/
|
|
649
|
+
scheme?: string;
|
|
650
|
+
/**
|
|
651
|
+
* Optional access-token storage.
|
|
652
|
+
*/
|
|
653
|
+
storage?: AuthTokenStorage;
|
|
654
|
+
/**
|
|
655
|
+
* Refresh the access token.
|
|
656
|
+
*
|
|
657
|
+
* Returning a token stores it through storage when configured.
|
|
658
|
+
* Returning void allows the callback to update external state itself.
|
|
659
|
+
*/
|
|
660
|
+
refreshToken?: () => MaybePromise$1<string | void>;
|
|
661
|
+
/**
|
|
662
|
+
* Determine whether an error should trigger token refresh.
|
|
663
|
+
*
|
|
664
|
+
* @default HTTP status 401
|
|
665
|
+
*/
|
|
666
|
+
shouldRefresh?: (error: unknown) => MaybePromise$1<boolean>;
|
|
619
667
|
}
|
|
620
668
|
/**
|
|
621
669
|
* Authentication plugin.
|
|
622
670
|
*/
|
|
623
671
|
declare function authPlugin(options?: AuthPluginOptions): Plugin;
|
|
624
|
-
|
|
672
|
+
//#endregion
|
|
673
|
+
//#region src/plugins/cachePlugin.d.ts
|
|
625
674
|
type MaybePromise<T> = T | Promise<T>;
|
|
626
675
|
interface CacheEntry {
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
676
|
+
data: unknown;
|
|
677
|
+
expiresAt: number;
|
|
678
|
+
status: number;
|
|
679
|
+
statusText: string;
|
|
680
|
+
headers: Array<[string, string]>;
|
|
681
|
+
raw?: Response;
|
|
633
682
|
}
|
|
634
683
|
interface CacheStore {
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
684
|
+
get(key: string): MaybePromise<CacheEntry | undefined>;
|
|
685
|
+
set(key: string, entry: CacheEntry): MaybePromise<void>;
|
|
686
|
+
delete(key: string): MaybePromise<void>;
|
|
687
|
+
clear(): MaybePromise<void>;
|
|
639
688
|
}
|
|
640
689
|
interface MemoryCacheStoreOptions {
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
690
|
+
/**
|
|
691
|
+
* Maximum entries retained by the in-memory LRU store.
|
|
692
|
+
* Use `Infinity` for no practical limit.
|
|
693
|
+
*
|
|
694
|
+
* @default 1000
|
|
695
|
+
*/
|
|
696
|
+
maxEntries?: number;
|
|
648
697
|
}
|
|
649
698
|
declare class MemoryCacheStore implements CacheStore {
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
699
|
+
private readonly entries;
|
|
700
|
+
private readonly maxEntries;
|
|
701
|
+
constructor(options?: MemoryCacheStoreOptions);
|
|
702
|
+
get(key: string): CacheEntry | undefined;
|
|
703
|
+
set(key: string, entry: CacheEntry): void;
|
|
704
|
+
delete(key: string): void;
|
|
705
|
+
clear(): void;
|
|
657
706
|
}
|
|
658
707
|
interface CachePluginOptions {
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
708
|
+
/**
|
|
709
|
+
* HTTP methods that may be cached.
|
|
710
|
+
*
|
|
711
|
+
* @default GET and HEAD
|
|
712
|
+
*/
|
|
713
|
+
methods?: readonly HttpMethod[];
|
|
714
|
+
/**
|
|
715
|
+
* Additional request headers included in the default cache key.
|
|
716
|
+
* All explicitly configured request headers are included automatically.
|
|
717
|
+
*
|
|
718
|
+
* @default authorization, cookie, accept and accept-language
|
|
719
|
+
*/
|
|
720
|
+
varyHeaders?: readonly string[];
|
|
721
|
+
/**
|
|
722
|
+
* Cache storage shared by this plugin instance.
|
|
723
|
+
*
|
|
724
|
+
* @default an isolated MemoryCacheStore
|
|
725
|
+
*/
|
|
726
|
+
store?: CacheStore;
|
|
727
|
+
/**
|
|
728
|
+
* Maximum entries retained by the default MemoryCacheStore.
|
|
729
|
+
* Ignored when `store` is provided.
|
|
730
|
+
*
|
|
731
|
+
* @default 1000
|
|
732
|
+
*/
|
|
733
|
+
maxEntries?: number;
|
|
734
|
+
/**
|
|
735
|
+
* Share one network operation between concurrent equivalent requests.
|
|
736
|
+
*
|
|
737
|
+
* @default true
|
|
738
|
+
*/
|
|
739
|
+
dedupe?: boolean;
|
|
690
740
|
}
|
|
691
741
|
interface CachePlugin extends Plugin {
|
|
692
|
-
|
|
742
|
+
clear(): MaybePromise<void>;
|
|
693
743
|
}
|
|
694
744
|
declare function cachePlugin(options?: CachePluginOptions): CachePlugin;
|
|
695
|
-
|
|
745
|
+
//#endregion
|
|
746
|
+
//#region src/plugins/circuitBreakerPlugin.d.ts
|
|
696
747
|
interface CircuitBreakerPluginOptions {
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
748
|
+
/**
|
|
749
|
+
* Consecutive counted failures required to open a closed circuit.
|
|
750
|
+
*
|
|
751
|
+
* @default 5
|
|
752
|
+
*/
|
|
753
|
+
failureThreshold?: number;
|
|
754
|
+
/**
|
|
755
|
+
* Successful probes required to close a half-open circuit.
|
|
756
|
+
*
|
|
757
|
+
* @default 1
|
|
758
|
+
*/
|
|
759
|
+
successThreshold?: number;
|
|
760
|
+
/**
|
|
761
|
+
* Time in milliseconds before an open circuit permits probes.
|
|
762
|
+
*
|
|
763
|
+
* @default 30000
|
|
764
|
+
*/
|
|
765
|
+
resetTimeout?: number;
|
|
766
|
+
/**
|
|
767
|
+
* Maximum concurrent probes admitted while a circuit is half-open.
|
|
768
|
+
*
|
|
769
|
+
* @default 1
|
|
770
|
+
*/
|
|
771
|
+
halfOpenMaxRequests?: number;
|
|
772
|
+
/**
|
|
773
|
+
* Maximum inactive isolation states retained by this plugin instance.
|
|
774
|
+
* Active requests are never evicted and may temporarily exceed the limit.
|
|
775
|
+
*
|
|
776
|
+
* @default 1000
|
|
777
|
+
*/
|
|
778
|
+
maxCircuits?: number;
|
|
779
|
+
/**
|
|
780
|
+
* Create the default isolation key for a request.
|
|
781
|
+
*
|
|
782
|
+
* @default the resolved request origin or "default"
|
|
783
|
+
*/
|
|
784
|
+
createKey?: (config: RequestConfig) => string;
|
|
785
|
+
/**
|
|
786
|
+
* Decide whether a final request failure affects the circuit.
|
|
787
|
+
*
|
|
788
|
+
* @default network errors, timeouts, HTTP 429, and HTTP 5xx
|
|
789
|
+
*/
|
|
790
|
+
shouldCountFailure?: (error: unknown, config: RequestConfig) => boolean | Promise<boolean>;
|
|
791
|
+
/**
|
|
792
|
+
* Observe circuit state changes. Observer failures are isolated.
|
|
793
|
+
*/
|
|
794
|
+
onStateChange?: (event: Readonly<CircuitBreakerStateChange>) => void | Promise<void>;
|
|
744
795
|
}
|
|
745
796
|
interface CircuitBreakerPlugin extends Plugin {
|
|
746
|
-
|
|
747
|
-
|
|
797
|
+
getState(key: string): CircuitState;
|
|
798
|
+
reset(key?: string): void;
|
|
748
799
|
}
|
|
749
800
|
declare function circuitBreakerPlugin(options?: CircuitBreakerPluginOptions): CircuitBreakerPlugin;
|
|
750
|
-
|
|
801
|
+
//#endregion
|
|
802
|
+
//#region src/plugins/concurrencyPlugin.d.ts
|
|
803
|
+
interface ConcurrencyPluginOptions {
|
|
804
|
+
/**
|
|
805
|
+
* Maximum active logical requests for each isolation key.
|
|
806
|
+
*
|
|
807
|
+
* @default 10
|
|
808
|
+
*/
|
|
809
|
+
maxConcurrent?: number;
|
|
810
|
+
/**
|
|
811
|
+
* Maximum queued requests for each isolation key.
|
|
812
|
+
* Set to zero to reject instead of waiting.
|
|
813
|
+
*
|
|
814
|
+
* @default 1000
|
|
815
|
+
*/
|
|
816
|
+
maxQueue?: number;
|
|
817
|
+
/**
|
|
818
|
+
* Maximum time in milliseconds a request may wait for a permit.
|
|
819
|
+
*
|
|
820
|
+
* @default 30000
|
|
821
|
+
*/
|
|
822
|
+
queueTimeout?: number;
|
|
823
|
+
/**
|
|
824
|
+
* Maximum inactive isolation states retained by this plugin instance.
|
|
825
|
+
* Active and queued states are never evicted and may temporarily exceed
|
|
826
|
+
* the limit.
|
|
827
|
+
*
|
|
828
|
+
* @default 1000
|
|
829
|
+
*/
|
|
830
|
+
maxKeys?: number;
|
|
831
|
+
/**
|
|
832
|
+
* Create the default isolation key for a request.
|
|
833
|
+
*
|
|
834
|
+
* @default the resolved request origin or "default"
|
|
835
|
+
*/
|
|
836
|
+
createKey?: (config: RequestConfig) => string;
|
|
837
|
+
}
|
|
838
|
+
interface ConcurrencyState {
|
|
839
|
+
active: number;
|
|
840
|
+
queued: number;
|
|
841
|
+
}
|
|
842
|
+
interface ConcurrencyPlugin extends Plugin {
|
|
843
|
+
getState(key: string): Readonly<ConcurrencyState>;
|
|
844
|
+
}
|
|
845
|
+
declare function concurrencyPlugin(options?: ConcurrencyPluginOptions): ConcurrencyPlugin;
|
|
846
|
+
//#endregion
|
|
847
|
+
//#region src/plugins/downloadPlugin.d.ts
|
|
751
848
|
type DownloadTransport = 'auto' | 'fetch' | 'xhr';
|
|
752
849
|
interface DownloadPluginOptions {
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
850
|
+
/**
|
|
851
|
+
* Download progress transport.
|
|
852
|
+
*
|
|
853
|
+
* `auto` prefers Fetch response streams and falls back to XMLHttpRequest
|
|
854
|
+
* when streaming responses are unavailable.
|
|
855
|
+
*
|
|
856
|
+
* @default auto
|
|
857
|
+
*/
|
|
858
|
+
transport?: DownloadTransport;
|
|
762
859
|
}
|
|
763
860
|
declare function downloadPlugin(options?: DownloadPluginOptions): Plugin;
|
|
764
|
-
|
|
861
|
+
//#endregion
|
|
862
|
+
//#region src/plugins/loggerPlugin.d.ts
|
|
765
863
|
declare function loggerPlugin(defaultOptions?: LoggerOptions): Plugin;
|
|
766
|
-
|
|
864
|
+
//#endregion
|
|
865
|
+
//#region src/plugins/retryPlugin.d.ts
|
|
767
866
|
declare function retryPlugin(defaultOptions?: RetryOptions): Plugin;
|
|
768
|
-
|
|
867
|
+
//#endregion
|
|
868
|
+
//#region src/plugins/uploadPlugin.d.ts
|
|
769
869
|
declare function uploadPlugin(): Plugin;
|
|
770
|
-
|
|
771
|
-
export {
|
|
870
|
+
//#endregion
|
|
871
|
+
export { Adapter, AuthOptions, AuthPluginOptions, AuthTokenStorage, CacheEntry, CacheOptions, CachePlugin, CachePluginOptions, CacheStore, CircuitBreakerOptions, CircuitBreakerPlugin, CircuitBreakerPluginOptions, CircuitBreakerStateChange, CircuitState, Client, ClientOptions, ConcurrencyOptions, ConcurrencyPlugin, ConcurrencyPluginOptions, ConcurrencyState, DownloadOptions, DownloadPluginOptions, DownloadProgress, DownloadTransport, ErrorLogEntry, FetchAdapter, FetchOptions, HttpMethod, Interceptor, InterceptorManager, InterceptorOptions, LoggerEntry, LoggerOptions, MemoryCacheStore, MemoryCacheStoreOptions, MockAdapter, MockAdapterOptions, MockHandler, MockReply, MockReplyHandler, MockRequestMatcher, MockResponseOptions, MockRoute, MockURLMatcher, NporaResponse, Plugin, PluginCleanup, PluginContext, PluginError, PluginErrorCode, PluginErrorOptions, PluginHookManager, PluginInterceptorManager, QueryParams, QueryValue, RequestConfig, RequestError, RequestErrorCode, RequestErrorOptions, RequestExtensions, RequestLogEntry, RequestLogger, ResponseLogEntry, ResponseType, RetryEvent, RetryOptions, UploadData, UploadOptions, UploadProgress, authPlugin, cachePlugin, circuitBreakerPlugin, concurrencyPlugin, createClient, downloadPlugin, loggerPlugin, retryPlugin, uploadPlugin };
|