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