@npora/request 1.14.4 → 1.15.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 +253 -4
- package/dist/MockAdapter-ChWzzSnH.d.cts +71 -0
- package/dist/MockAdapter-H50LoFDu.d.ts +71 -0
- package/dist/Plugin-0Eh51_et.d.ts +124 -0
- package/dist/Plugin-YysllE6z.d.cts +124 -0
- package/dist/PluginError-CcuPSIRv.js +1 -0
- package/dist/PluginError-DT3VnlUB.cjs +1 -0
- package/dist/PluginError-DVP3pUt_.d.cts +18 -0
- package/dist/PluginError-DVP3pUt_.d.ts +18 -0
- package/dist/RequestError-BH6V64XR.js +1 -0
- package/dist/RequestError-DPSv-HVF.cjs +1 -0
- package/dist/SchemaValidationError-CjvWT8YA.d.ts +166 -0
- package/dist/SchemaValidationError-WMTfqSBV.d.cts +166 -0
- package/dist/adapter-BeVVCcNG.d.cts +21 -0
- package/dist/adapter-ODzpt_dM.d.ts +21 -0
- package/dist/authPlugin-6E6_0dAO.d.ts +53 -0
- package/dist/authPlugin-B_YpkyC8.d.cts +53 -0
- package/dist/buildRequest-BRZwRLoN.cjs +1 -0
- package/dist/buildRequest-Cwt8XEWO.js +1 -0
- package/dist/cachePlugin-B9Hvsprg.d.cts +297 -0
- package/dist/cachePlugin-CSHwJYwI.js +1 -0
- package/dist/cachePlugin-CvH26DBo.d.ts +297 -0
- package/dist/cachePlugin-ZPYdHbsM.cjs +1 -0
- package/dist/circuitBreakerPlugin-B45xghq9.d.cts +59 -0
- package/dist/circuitBreakerPlugin-DsH6YCNe.d.ts +59 -0
- package/dist/concurrencyPlugin-CuJMua41.d.cts +48 -0
- package/dist/concurrencyPlugin-dwGNFYrM.d.ts +48 -0
- package/dist/core.cjs +1 -0
- package/dist/core.d.cts +6 -0
- package/dist/core.d.ts +6 -0
- package/dist/core.js +1 -0
- package/dist/createAbortError-D4rRBq2B.js +1 -0
- package/dist/createAbortError-DJqbdYgk.cjs +1 -0
- package/dist/createClient-CibOTVAy.cjs +1 -0
- package/dist/createClient-I13D6XsD.js +1 -0
- package/dist/downloadPlugin-CEXXJiDo.d.cts +17 -0
- package/dist/downloadPlugin-s8VS8t9r.d.ts +17 -0
- package/dist/index.cjs +1 -4
- package/dist/index.d.cts +15 -1028
- package/dist/index.d.ts +15 -1028
- package/dist/index.js +1 -4
- package/dist/isPromiseLike-BuAv3bAe.js +1 -0
- package/dist/isPromiseLike-C8e95Or2.cjs +1 -0
- package/dist/isURLSearchParams-B93cMCGj.js +1 -0
- package/dist/isURLSearchParams-o-c8Q42t.cjs +1 -0
- package/dist/loggerPlugin-C15EW7Sc.d.ts +6 -0
- package/dist/loggerPlugin-uOFiUtBi.d.cts +6 -0
- package/dist/maxTimerDelay-Hn7X0Wuh.js +1 -0
- package/dist/maxTimerDelay-NH5XeTXb.cjs +1 -0
- package/dist/plugins/auth.cjs +1 -0
- package/dist/plugins/auth.d.cts +2 -0
- package/dist/plugins/auth.d.ts +2 -0
- package/dist/plugins/auth.js +1 -0
- package/dist/plugins/cache.cjs +1 -0
- package/dist/plugins/cache.d.cts +2 -0
- package/dist/plugins/cache.d.ts +2 -0
- package/dist/plugins/cache.js +1 -0
- package/dist/plugins/circuit-breaker.cjs +1 -0
- package/dist/plugins/circuit-breaker.d.cts +2 -0
- package/dist/plugins/circuit-breaker.d.ts +2 -0
- package/dist/plugins/circuit-breaker.js +1 -0
- package/dist/plugins/concurrency.cjs +1 -0
- package/dist/plugins/concurrency.d.cts +2 -0
- package/dist/plugins/concurrency.d.ts +2 -0
- package/dist/plugins/concurrency.js +1 -0
- package/dist/plugins/download.cjs +1 -0
- package/dist/plugins/download.d.cts +2 -0
- package/dist/plugins/download.d.ts +2 -0
- package/dist/plugins/download.js +1 -0
- package/dist/plugins/logger.cjs +1 -0
- package/dist/plugins/logger.d.cts +2 -0
- package/dist/plugins/logger.d.ts +2 -0
- package/dist/plugins/logger.js +1 -0
- package/dist/plugins/retry.cjs +1 -0
- package/dist/plugins/retry.d.cts +2 -0
- package/dist/plugins/retry.d.ts +2 -0
- package/dist/plugins/retry.js +1 -0
- package/dist/plugins/upload.cjs +1 -0
- package/dist/plugins/upload.d.cts +2 -0
- package/dist/plugins/upload.d.ts +2 -0
- package/dist/plugins/upload.js +1 -0
- package/dist/plugins.cjs +1 -0
- package/dist/plugins.d.cts +11 -0
- package/dist/plugins.d.ts +11 -0
- package/dist/plugins.js +1 -0
- package/dist/resolveExtensionConfig-BHHfQwjF.cjs +1 -0
- package/dist/resolveExtensionConfig-QAFHZVte.js +1 -0
- package/dist/resolveRequestOrigin-BndIJeZ7.js +1 -0
- package/dist/resolveRequestOrigin-CRATeWff.cjs +1 -0
- package/dist/response-BhyS3PAL.d.cts +441 -0
- package/dist/response-BhyS3PAL.d.ts +441 -0
- package/dist/retryPlugin-2mYKvWy3.d.ts +6 -0
- package/dist/retryPlugin-BqlUpmd0.d.cts +6 -0
- package/dist/testing.cjs +1 -0
- package/dist/testing.d.cts +2 -0
- package/dist/testing.d.ts +2 -0
- package/dist/testing.js +1 -0
- package/dist/uploadPlugin-AfhFIsO7.d.cts +5 -0
- package/dist/uploadPlugin-Bb7EawRX.d.ts +5 -0
- package/dist/validateResponseStatus-Dqzr342t.js +4 -0
- package/dist/validateResponseStatus-QAjcah2i.cjs +4 -0
- package/dist/waitForSignal-DyyPvJd5.js +1 -0
- package/dist/waitForSignal-yR1BeU8f.cjs +1 -0
- package/dist/xhrTransport-C0pg00i5.js +1 -0
- package/dist/xhrTransport-CeW2DDzo.cjs +1 -0
- package/package.json +65 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,1028 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
declare namespace StandardSchemaV1 {
|
|
18
|
-
interface Props<Input = unknown, Output = Input> {
|
|
19
|
-
readonly version: 1;
|
|
20
|
-
readonly vendor: string;
|
|
21
|
-
readonly validate: (value: unknown, options?: Options) => Result<Output> | Promise<Result<Output>>;
|
|
22
|
-
readonly types?: Types<Input, Output>;
|
|
23
|
-
}
|
|
24
|
-
interface Options {
|
|
25
|
-
readonly libraryOptions?: Record<string, unknown>;
|
|
26
|
-
}
|
|
27
|
-
type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
28
|
-
interface SuccessResult<Output> {
|
|
29
|
-
readonly value: Output;
|
|
30
|
-
readonly issues?: undefined;
|
|
31
|
-
}
|
|
32
|
-
interface FailureResult {
|
|
33
|
-
readonly issues: ReadonlyArray<Issue>;
|
|
34
|
-
}
|
|
35
|
-
interface Issue {
|
|
36
|
-
readonly message: string;
|
|
37
|
-
readonly path?: ReadonlyArray<PropertyKey | PathSegment>;
|
|
38
|
-
}
|
|
39
|
-
interface PathSegment {
|
|
40
|
-
readonly key: PropertyKey;
|
|
41
|
-
}
|
|
42
|
-
interface Types<Input = unknown, Output = Input> {
|
|
43
|
-
readonly input: Input;
|
|
44
|
-
readonly output: Output;
|
|
45
|
-
}
|
|
46
|
-
type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['input'];
|
|
47
|
-
type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['output'];
|
|
48
|
-
}
|
|
49
|
-
//#endregion
|
|
50
|
-
//#region src/types/extensions.d.ts
|
|
51
|
-
type CircuitState = 'closed' | 'open' | 'half-open';
|
|
52
|
-
interface CircuitBreakerOptions {
|
|
53
|
-
/**
|
|
54
|
-
* Enable circuit-breaker protection for this request.
|
|
55
|
-
*
|
|
56
|
-
* @default true
|
|
57
|
-
*/
|
|
58
|
-
enabled?: boolean;
|
|
59
|
-
/**
|
|
60
|
-
* Override the isolation key for this request.
|
|
61
|
-
*/
|
|
62
|
-
key?: string;
|
|
63
|
-
}
|
|
64
|
-
interface CircuitBreakerStateChange {
|
|
65
|
-
key: string;
|
|
66
|
-
previousState: CircuitState;
|
|
67
|
-
state: CircuitState;
|
|
68
|
-
timestamp: number;
|
|
69
|
-
failures: number;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Per-request retry configuration used by the retry extension.
|
|
73
|
-
*/
|
|
74
|
-
interface RetryOptions {
|
|
75
|
-
retries?: number;
|
|
76
|
-
/**
|
|
77
|
-
* HTTP methods that may be retried.
|
|
78
|
-
*
|
|
79
|
-
* @default GET, HEAD, OPTIONS, PUT and DELETE
|
|
80
|
-
*/
|
|
81
|
-
methods?: readonly HttpMethod[];
|
|
82
|
-
delay?: number | ((attempt: number, error: unknown) => number | Promise<number>);
|
|
83
|
-
/**
|
|
84
|
-
* Respect the server Retry-After response header.
|
|
85
|
-
*
|
|
86
|
-
* @default true
|
|
87
|
-
*/
|
|
88
|
-
respectRetryAfter?: boolean;
|
|
89
|
-
/**
|
|
90
|
-
* Maximum retry delay in milliseconds.
|
|
91
|
-
*
|
|
92
|
-
* @default 60000
|
|
93
|
-
*/
|
|
94
|
-
maxDelay?: number;
|
|
95
|
-
/**
|
|
96
|
-
* Randomize the configured retry delay.
|
|
97
|
-
*
|
|
98
|
-
* `true` applies full jitter between zero and the configured delay.
|
|
99
|
-
* A function receives the pending retry event and returns the final delay.
|
|
100
|
-
* Server-provided Retry-After delays are not jittered.
|
|
101
|
-
*
|
|
102
|
-
* @default false
|
|
103
|
-
*/
|
|
104
|
-
jitter?: boolean | ((event: RetryEvent) => number | Promise<number>);
|
|
105
|
-
/**
|
|
106
|
-
* Maximum elapsed time across the initial request, retries and planned
|
|
107
|
-
* retry delays.
|
|
108
|
-
*
|
|
109
|
-
* @default unlimited
|
|
110
|
-
*/
|
|
111
|
-
maxElapsedTime?: number;
|
|
112
|
-
shouldRetry?: (error: unknown, attempt: number) => boolean | Promise<boolean>;
|
|
113
|
-
/**
|
|
114
|
-
* Observe a scheduled retry.
|
|
115
|
-
*
|
|
116
|
-
* Callback failures are isolated from the request lifecycle.
|
|
117
|
-
*/
|
|
118
|
-
onRetry?: (event: RetryEvent) => void | Promise<void>;
|
|
119
|
-
}
|
|
120
|
-
interface RetryEvent {
|
|
121
|
-
/**
|
|
122
|
-
* One-based retry number.
|
|
123
|
-
*/
|
|
124
|
-
attempt: number;
|
|
125
|
-
/**
|
|
126
|
-
* Final delay before this retry in milliseconds.
|
|
127
|
-
*/
|
|
128
|
-
delay: number;
|
|
129
|
-
/**
|
|
130
|
-
* Time elapsed since the request started in milliseconds.
|
|
131
|
-
*/
|
|
132
|
-
elapsedTime: number;
|
|
133
|
-
error: unknown;
|
|
134
|
-
}
|
|
135
|
-
interface CacheOptions {
|
|
136
|
-
enabled?: boolean;
|
|
137
|
-
/**
|
|
138
|
-
* Time in milliseconds before a cached response expires.
|
|
139
|
-
* Use `0` to disable persistence or `Infinity` to retain it indefinitely.
|
|
140
|
-
*
|
|
141
|
-
* @default 30000
|
|
142
|
-
*/
|
|
143
|
-
ttl?: number;
|
|
144
|
-
key?: string;
|
|
145
|
-
/**
|
|
146
|
-
* Share one network operation between concurrent equivalent requests.
|
|
147
|
-
*
|
|
148
|
-
* @default true
|
|
149
|
-
*/
|
|
150
|
-
dedupe?: boolean;
|
|
151
|
-
}
|
|
152
|
-
interface ConcurrencyOptions {
|
|
153
|
-
/**
|
|
154
|
-
* Enable concurrency limiting for this request.
|
|
155
|
-
*
|
|
156
|
-
* @default true
|
|
157
|
-
*/
|
|
158
|
-
enabled?: boolean;
|
|
159
|
-
/**
|
|
160
|
-
* Override the isolation key for this request.
|
|
161
|
-
*/
|
|
162
|
-
key?: string;
|
|
163
|
-
/**
|
|
164
|
-
* Maximum time in milliseconds this request may wait for a permit.
|
|
165
|
-
*
|
|
166
|
-
* @default the plugin-level queueTimeout
|
|
167
|
-
*/
|
|
168
|
-
queueTimeout?: number;
|
|
169
|
-
}
|
|
170
|
-
interface AuthOptions {
|
|
171
|
-
token?: string | (() => string | Promise<string>);
|
|
172
|
-
scheme?: string;
|
|
173
|
-
}
|
|
174
|
-
interface LoggerOptions {
|
|
175
|
-
enabled?: boolean;
|
|
176
|
-
/**
|
|
177
|
-
* Structured log destination.
|
|
178
|
-
*
|
|
179
|
-
* @default console
|
|
180
|
-
*/
|
|
181
|
-
logger?: RequestLogger;
|
|
182
|
-
/**
|
|
183
|
-
* Create the identifier shared by all lifecycle entries for a request.
|
|
184
|
-
*
|
|
185
|
-
* @default a plugin-local monotonic identifier
|
|
186
|
-
*/
|
|
187
|
-
createRequestId?: () => string;
|
|
188
|
-
}
|
|
189
|
-
interface RequestLogEntry {
|
|
190
|
-
type: 'request';
|
|
191
|
-
requestId: string;
|
|
192
|
-
timestamp: number;
|
|
193
|
-
method: HttpMethod;
|
|
194
|
-
url: string;
|
|
195
|
-
}
|
|
196
|
-
interface ResponseLogEntry {
|
|
197
|
-
type: 'response';
|
|
198
|
-
requestId: string;
|
|
199
|
-
timestamp: number;
|
|
200
|
-
duration: number;
|
|
201
|
-
attempts: number;
|
|
202
|
-
method: HttpMethod;
|
|
203
|
-
url: string;
|
|
204
|
-
status: number;
|
|
205
|
-
}
|
|
206
|
-
interface ErrorLogEntry {
|
|
207
|
-
type: 'error';
|
|
208
|
-
requestId: string;
|
|
209
|
-
timestamp: number;
|
|
210
|
-
duration: number;
|
|
211
|
-
attempt: number;
|
|
212
|
-
method: HttpMethod;
|
|
213
|
-
url: string;
|
|
214
|
-
name: string;
|
|
215
|
-
message: string;
|
|
216
|
-
code?: string;
|
|
217
|
-
status?: number;
|
|
218
|
-
}
|
|
219
|
-
type LoggerEntry = RequestLogEntry | ResponseLogEntry | ErrorLogEntry;
|
|
220
|
-
interface RequestLogger {
|
|
221
|
-
info(message: string, entry: RequestLogEntry | ResponseLogEntry): void | Promise<void>;
|
|
222
|
-
error(message: string, entry: ErrorLogEntry): void | Promise<void>;
|
|
223
|
-
}
|
|
224
|
-
type UploadData = FormData | Record<string, unknown>;
|
|
225
|
-
interface TransferProgress {
|
|
226
|
-
/**
|
|
227
|
-
* Cumulative number of bytes transferred.
|
|
228
|
-
*/
|
|
229
|
-
loaded: number;
|
|
230
|
-
/**
|
|
231
|
-
* Total transfer size when the runtime provides it.
|
|
232
|
-
*/
|
|
233
|
-
total?: number;
|
|
234
|
-
/**
|
|
235
|
-
* Progress ratio between 0 and 1 when total is available.
|
|
236
|
-
*/
|
|
237
|
-
progress?: number;
|
|
238
|
-
/**
|
|
239
|
-
* Bytes transferred since the previous progress event.
|
|
240
|
-
*/
|
|
241
|
-
bytes?: number;
|
|
242
|
-
/**
|
|
243
|
-
* Average transfer rate in bytes per second when measurable.
|
|
244
|
-
*/
|
|
245
|
-
rate?: number;
|
|
246
|
-
/**
|
|
247
|
-
* Estimated remaining seconds when total and rate are available.
|
|
248
|
-
*/
|
|
249
|
-
estimated?: number;
|
|
250
|
-
}
|
|
251
|
-
/**
|
|
252
|
-
* Upload progress information.
|
|
253
|
-
*/
|
|
254
|
-
interface UploadProgress extends TransferProgress {}
|
|
255
|
-
interface UploadOptions {
|
|
256
|
-
data: UploadData;
|
|
257
|
-
/**
|
|
258
|
-
* Called while XMLHttpRequest uploads the request body.
|
|
259
|
-
*/
|
|
260
|
-
onProgress?: (progress: UploadProgress) => void;
|
|
261
|
-
}
|
|
262
|
-
/**
|
|
263
|
-
* Download progress information.
|
|
264
|
-
*/
|
|
265
|
-
interface DownloadProgress extends TransferProgress {}
|
|
266
|
-
type DownloadOutput = 'blob' | 'stream';
|
|
267
|
-
interface DownloadOptions {
|
|
268
|
-
/**
|
|
269
|
-
* Returned download representation.
|
|
270
|
-
*
|
|
271
|
-
* `stream` requires Fetch response-stream support and preserves backpressure
|
|
272
|
-
* without buffering the complete response in memory.
|
|
273
|
-
*
|
|
274
|
-
* @default 'blob'
|
|
275
|
-
*/
|
|
276
|
-
output?: DownloadOutput;
|
|
277
|
-
/**
|
|
278
|
-
* Reserved legacy field. It does not save or rename the returned Blob.
|
|
279
|
-
*
|
|
280
|
-
* @deprecated This field currently has no effect.
|
|
281
|
-
*/
|
|
282
|
-
filename?: string;
|
|
283
|
-
/**
|
|
284
|
-
* Called while the response stream is being consumed.
|
|
285
|
-
*/
|
|
286
|
-
onProgress?: (progress: DownloadProgress) => void;
|
|
287
|
-
}
|
|
288
|
-
//#endregion
|
|
289
|
-
//#region src/types/config.d.ts
|
|
290
|
-
type QueryValue = string | number | boolean | null | undefined;
|
|
291
|
-
type QueryParams = Record<string, QueryValue | QueryValue[]>;
|
|
292
|
-
type ResponseType = 'json' | 'text' | 'blob' | 'arrayBuffer' | 'stream' | 'sse' | 'ndjson';
|
|
293
|
-
/**
|
|
294
|
-
* Native Fetch options passed to the underlying adapter.
|
|
295
|
-
*
|
|
296
|
-
* Request fields managed by Npora Request are intentionally omitted so there
|
|
297
|
-
* is a single source of truth for method, headers, body and cancellation.
|
|
298
|
-
*/
|
|
299
|
-
type FetchOptions = Omit<RequestInit, 'method' | 'headers' | 'body' | 'signal'>;
|
|
300
|
-
/**
|
|
301
|
-
* Plugin-owned request configuration.
|
|
302
|
-
*
|
|
303
|
-
* Plugins extend this interface through TypeScript module augmentation.
|
|
304
|
-
*/
|
|
305
|
-
interface RequestExtensions {
|
|
306
|
-
auth?: AuthOptions;
|
|
307
|
-
cache?: CacheOptions;
|
|
308
|
-
circuitBreaker?: CircuitBreakerOptions;
|
|
309
|
-
concurrency?: ConcurrencyOptions;
|
|
310
|
-
download?: DownloadOptions;
|
|
311
|
-
logger?: LoggerOptions;
|
|
312
|
-
retry?: number | RetryOptions;
|
|
313
|
-
upload?: UploadOptions;
|
|
314
|
-
}
|
|
315
|
-
interface RequestConfig {
|
|
316
|
-
url: string;
|
|
317
|
-
method?: HttpMethod;
|
|
318
|
-
baseURL?: string;
|
|
319
|
-
fetchOptions?: FetchOptions;
|
|
320
|
-
headers?: HeadersInit;
|
|
321
|
-
query?: QueryParams;
|
|
322
|
-
searchParams?: URLSearchParams;
|
|
323
|
-
body?: BodyInit | Record<string, unknown> | null;
|
|
324
|
-
json?: Record<string, unknown> | unknown[];
|
|
325
|
-
form?: URLSearchParams | Record<string, QueryValue | QueryValue[]>;
|
|
326
|
-
formData?: FormData | Record<string, unknown>;
|
|
327
|
-
timeout?: number;
|
|
328
|
-
signal?: AbortSignal;
|
|
329
|
-
/**
|
|
330
|
-
* Maximum parsed response body size in bytes.
|
|
331
|
-
*
|
|
332
|
-
* @default unlimited
|
|
333
|
-
*/
|
|
334
|
-
maxResponseSize?: number;
|
|
335
|
-
/**
|
|
336
|
-
* Maximum nested array depth accepted while building FormData.
|
|
337
|
-
*
|
|
338
|
-
* @default 32
|
|
339
|
-
*/
|
|
340
|
-
maxFormDataDepth?: number;
|
|
341
|
-
responseType?: ResponseType;
|
|
342
|
-
/**
|
|
343
|
-
* Validate and optionally transform the parsed response value.
|
|
344
|
-
*
|
|
345
|
-
* Accepts any Standard Schema v1 compatible validator.
|
|
346
|
-
*/
|
|
347
|
-
schema?: StandardSchemaV1;
|
|
348
|
-
validateStatus?: (status: number) => boolean;
|
|
349
|
-
extensions?: RequestExtensions;
|
|
350
|
-
}
|
|
351
|
-
//#endregion
|
|
352
|
-
//#region src/types/response.d.ts
|
|
353
|
-
/**
|
|
354
|
-
* A message decoded from a `text/event-stream` response.
|
|
355
|
-
*/
|
|
356
|
-
interface ServerSentEvent {
|
|
357
|
-
/**
|
|
358
|
-
* Event payload with multiple `data` fields joined by newlines.
|
|
359
|
-
*/
|
|
360
|
-
data: string;
|
|
361
|
-
/**
|
|
362
|
-
* Event type, defaulting to `message`.
|
|
363
|
-
*/
|
|
364
|
-
event: string;
|
|
365
|
-
/**
|
|
366
|
-
* Most recently observed event identifier.
|
|
367
|
-
*/
|
|
368
|
-
id: string;
|
|
369
|
-
/**
|
|
370
|
-
* Most recently observed server reconnection delay in milliseconds.
|
|
371
|
-
*/
|
|
372
|
-
retry?: number;
|
|
373
|
-
}
|
|
374
|
-
/**
|
|
375
|
-
* Npora response.
|
|
376
|
-
*/
|
|
377
|
-
interface NporaResponse<T = unknown> {
|
|
378
|
-
/**
|
|
379
|
-
* Parsed response data.
|
|
380
|
-
*/
|
|
381
|
-
data: T;
|
|
382
|
-
/**
|
|
383
|
-
* HTTP status code.
|
|
384
|
-
*/
|
|
385
|
-
status: number;
|
|
386
|
-
/**
|
|
387
|
-
* HTTP status text.
|
|
388
|
-
*/
|
|
389
|
-
statusText: string;
|
|
390
|
-
/**
|
|
391
|
-
* Response headers.
|
|
392
|
-
*/
|
|
393
|
-
headers: Headers;
|
|
394
|
-
/**
|
|
395
|
-
* Request config.
|
|
396
|
-
*/
|
|
397
|
-
config: RequestConfig;
|
|
398
|
-
/**
|
|
399
|
-
* Raw Fetch Response.
|
|
400
|
-
*/
|
|
401
|
-
raw: Response;
|
|
402
|
-
}
|
|
403
|
-
//#endregion
|
|
404
|
-
//#region src/types/adapter.d.ts
|
|
405
|
-
/**
|
|
406
|
-
* Request adapter.
|
|
407
|
-
*/
|
|
408
|
-
interface Adapter {
|
|
409
|
-
/**
|
|
410
|
-
* Send request.
|
|
411
|
-
*/
|
|
412
|
-
request<T = unknown>(config: RequestConfig): Promise<NporaResponse<T>>;
|
|
413
|
-
/**
|
|
414
|
-
* Optional first-attempt fast path for built-in adapters.
|
|
415
|
-
*
|
|
416
|
-
* Custom adapters do not need to implement this method.
|
|
417
|
-
*
|
|
418
|
-
* @internal
|
|
419
|
-
*/
|
|
420
|
-
requestValidated?<T = unknown>(config: RequestConfig, validatedHeaders: Headers, preserveRaw?: boolean): Promise<NporaResponse<T>>;
|
|
421
|
-
}
|
|
422
|
-
//#endregion
|
|
423
|
-
//#region src/types/client.d.ts
|
|
424
|
-
/**
|
|
425
|
-
* Client creation options.
|
|
426
|
-
*/
|
|
427
|
-
interface ClientOptions extends Partial<Omit<RequestConfig, 'url' | 'method' | 'schema'>> {
|
|
428
|
-
/**
|
|
429
|
-
* Request adapter.
|
|
430
|
-
*
|
|
431
|
-
* @default FetchAdapter
|
|
432
|
-
*/
|
|
433
|
-
adapter?: Adapter;
|
|
434
|
-
}
|
|
435
|
-
//#endregion
|
|
436
|
-
//#region src/adapters/FetchAdapter.d.ts
|
|
437
|
-
declare class FetchAdapter implements Adapter {
|
|
438
|
-
request<T = unknown>(config: RequestConfig): Promise<NporaResponse<T>>;
|
|
439
|
-
requestValidated<T = unknown>(config: RequestConfig, validatedHeaders: Headers, preserveRaw?: boolean): Promise<NporaResponse<T>>;
|
|
440
|
-
private execute;
|
|
441
|
-
}
|
|
442
|
-
//#endregion
|
|
443
|
-
//#region src/adapters/MockAdapter.d.ts
|
|
444
|
-
type MockHandler<T = unknown> = (config: RequestConfig) => T | Promise<T>;
|
|
445
|
-
type MockURLMatcher = string | RegExp;
|
|
446
|
-
interface MockRequestMatcher {
|
|
447
|
-
url: MockURLMatcher;
|
|
448
|
-
query?: QueryParams;
|
|
449
|
-
searchParams?: URLSearchParams;
|
|
450
|
-
headers?: HeadersInit;
|
|
451
|
-
}
|
|
452
|
-
interface MockReply<T = unknown> {
|
|
453
|
-
status: number;
|
|
454
|
-
data?: T;
|
|
455
|
-
headers?: HeadersInit;
|
|
456
|
-
statusText?: string;
|
|
457
|
-
delay?: number;
|
|
458
|
-
}
|
|
459
|
-
type MockReplyHandler<T = unknown> = (config: RequestConfig) => MockReply<T> | Promise<MockReply<T>>;
|
|
460
|
-
interface MockResponseOptions {
|
|
461
|
-
headers?: HeadersInit;
|
|
462
|
-
statusText?: string;
|
|
463
|
-
delay?: number;
|
|
464
|
-
}
|
|
465
|
-
interface MockRoute {
|
|
466
|
-
reply<T = unknown>(handler: MockReplyHandler<T>): MockAdapter;
|
|
467
|
-
reply<T = unknown>(status: number, data?: T, options?: MockResponseOptions): MockAdapter;
|
|
468
|
-
replyOnce<T = unknown>(handler: MockReplyHandler<T>): MockAdapter;
|
|
469
|
-
replyOnce<T = unknown>(status: number, data?: T, options?: MockResponseOptions): MockAdapter;
|
|
470
|
-
networkError(message?: string): MockAdapter;
|
|
471
|
-
networkErrorOnce(message?: string): MockAdapter;
|
|
472
|
-
timeout(message?: string): MockAdapter;
|
|
473
|
-
timeoutOnce(message?: string): MockAdapter;
|
|
474
|
-
}
|
|
475
|
-
interface MockAdapterOptions {
|
|
476
|
-
handlers?: Record<string, MockHandler>;
|
|
477
|
-
/**
|
|
478
|
-
* Default delay for mock handlers and routes.
|
|
479
|
-
*
|
|
480
|
-
* @default 0
|
|
481
|
-
*/
|
|
482
|
-
delay?: number;
|
|
483
|
-
}
|
|
484
|
-
declare class MockAdapter implements Adapter {
|
|
485
|
-
private readonly handlers;
|
|
486
|
-
private readonly rules;
|
|
487
|
-
private readonly requests;
|
|
488
|
-
private readonly delay;
|
|
489
|
-
constructor(options?: MockAdapterOptions);
|
|
490
|
-
get history(): readonly RequestConfig[];
|
|
491
|
-
/**
|
|
492
|
-
* Register a legacy URL-only data handler.
|
|
493
|
-
*/
|
|
494
|
-
on<T = unknown>(url: string, handler: MockHandler<T>): this;
|
|
495
|
-
onMethod(method: HttpMethod, matcher: MockURLMatcher | MockRequestMatcher): MockRoute;
|
|
496
|
-
onGet(matcher: MockURLMatcher | MockRequestMatcher): MockRoute;
|
|
497
|
-
onPost(matcher: MockURLMatcher | MockRequestMatcher): MockRoute;
|
|
498
|
-
onPut(matcher: MockURLMatcher | MockRequestMatcher): MockRoute;
|
|
499
|
-
onPatch(matcher: MockURLMatcher | MockRequestMatcher): MockRoute;
|
|
500
|
-
onDelete(matcher: MockURLMatcher | MockRequestMatcher): MockRoute;
|
|
501
|
-
onHead(matcher: MockURLMatcher | MockRequestMatcher): MockRoute;
|
|
502
|
-
onOptions(matcher: MockURLMatcher | MockRequestMatcher): MockRoute;
|
|
503
|
-
resetHistory(): this;
|
|
504
|
-
resetHandlers(): this;
|
|
505
|
-
reset(): this;
|
|
506
|
-
request<T = unknown>(config: RequestConfig): Promise<NporaResponse<T>>;
|
|
507
|
-
private registerReply;
|
|
508
|
-
private registerError;
|
|
509
|
-
}
|
|
510
|
-
//#endregion
|
|
511
|
-
//#region src/interceptors/InterceptorManager.d.ts
|
|
512
|
-
type Interceptor<T> = (value: T) => T | Promise<T>;
|
|
513
|
-
interface InterceptorOptions {
|
|
514
|
-
/**
|
|
515
|
-
* Higher priority interceptors run first.
|
|
516
|
-
*
|
|
517
|
-
* @default 0
|
|
518
|
-
*/
|
|
519
|
-
priority?: number;
|
|
520
|
-
}
|
|
521
|
-
declare class InterceptorManager<T> {
|
|
522
|
-
private id;
|
|
523
|
-
private readonly interceptors;
|
|
524
|
-
private orderedInterceptors;
|
|
525
|
-
get active(): boolean;
|
|
526
|
-
use(interceptor: Interceptor<T>, options?: InterceptorOptions): number;
|
|
527
|
-
eject(id: number): void;
|
|
528
|
-
clear(): void;
|
|
529
|
-
run(value: T): Promise<T>;
|
|
530
|
-
private runMaybeAsync;
|
|
531
|
-
private refreshOrder;
|
|
532
|
-
}
|
|
533
|
-
//#endregion
|
|
534
|
-
//#region src/core/RequestContext.d.ts
|
|
535
|
-
declare class RequestContext<T = unknown> {
|
|
536
|
-
readonly preserveRaw: boolean;
|
|
537
|
-
config: RequestConfig;
|
|
538
|
-
response?: NporaResponse<T>;
|
|
539
|
-
error?: unknown;
|
|
540
|
-
readonly startTime: number;
|
|
541
|
-
endTime?: number;
|
|
542
|
-
attempt: number;
|
|
543
|
-
constructor(config: RequestConfig, preserveRaw?: boolean);
|
|
544
|
-
}
|
|
545
|
-
//#endregion
|
|
546
|
-
//#region src/interceptors/PluginHooks.d.ts
|
|
547
|
-
interface RetryDecision {
|
|
548
|
-
retry: boolean;
|
|
549
|
-
delay?: number;
|
|
550
|
-
}
|
|
551
|
-
interface HookOptions {
|
|
552
|
-
/**
|
|
553
|
-
* Higher priority hooks run first.
|
|
554
|
-
*
|
|
555
|
-
* @default 0
|
|
556
|
-
*/
|
|
557
|
-
priority?: number;
|
|
558
|
-
/** @internal Response hooks may opt out when they never inspect raw. */
|
|
559
|
-
requiresRawResponse?: boolean;
|
|
560
|
-
}
|
|
561
|
-
type HookDisposer = () => void;
|
|
562
|
-
type RequestHook = (context: RequestContext<unknown>) => void | Promise<void>;
|
|
563
|
-
type RetryHook = (context: RequestContext<unknown>, attempt: number) => RetryDecision | undefined | Promise<RetryDecision | undefined>;
|
|
564
|
-
//#endregion
|
|
565
|
-
//#region src/plugins/Plugin.d.ts
|
|
566
|
-
interface PluginInterceptorManager<T> {
|
|
567
|
-
use(interceptor: Interceptor<T>, options?: InterceptorOptions): number;
|
|
568
|
-
eject(id: number): void;
|
|
569
|
-
}
|
|
570
|
-
interface PluginHookManager {
|
|
571
|
-
onRequest(hook: RequestHook, options?: HookOptions): HookDisposer;
|
|
572
|
-
/**
|
|
573
|
-
* Provide an alternative transport for the current attempt.
|
|
574
|
-
*
|
|
575
|
-
* Transport hooks run inside the retry loop. A hook that handles the
|
|
576
|
-
* request assigns `context.response`; later transport hooks and the client
|
|
577
|
-
* adapter are then skipped for that attempt.
|
|
578
|
-
*/
|
|
579
|
-
onTransport(hook: RequestHook, options?: HookOptions): HookDisposer;
|
|
580
|
-
onResponse(hook: RequestHook, options?: HookOptions): HookDisposer;
|
|
581
|
-
onError(hook: RequestHook, options?: HookOptions): HookDisposer;
|
|
582
|
-
/**
|
|
583
|
-
* Observe the final request outcome after retries and interceptors finish.
|
|
584
|
-
*
|
|
585
|
-
* Settled hook failures are isolated from the request result.
|
|
586
|
-
*/
|
|
587
|
-
onSettled(hook: RequestHook, options?: HookOptions): HookDisposer;
|
|
588
|
-
onRetry(hook: RetryHook, options?: HookOptions): HookDisposer;
|
|
589
|
-
}
|
|
590
|
-
interface PluginContext {
|
|
591
|
-
interceptors: {
|
|
592
|
-
request: PluginInterceptorManager<RequestConfig>;
|
|
593
|
-
response: PluginInterceptorManager<NporaResponse>;
|
|
594
|
-
error: PluginInterceptorManager<unknown>;
|
|
595
|
-
};
|
|
596
|
-
hooks: PluginHookManager;
|
|
597
|
-
}
|
|
598
|
-
type PluginCleanup = () => void;
|
|
599
|
-
interface Plugin {
|
|
600
|
-
name: string;
|
|
601
|
-
/**
|
|
602
|
-
* Default priority for interceptors and hooks registered by this plugin.
|
|
603
|
-
* Higher priority registrations run first.
|
|
604
|
-
*
|
|
605
|
-
* @default 0
|
|
606
|
-
*/
|
|
607
|
-
priority?: number;
|
|
608
|
-
/**
|
|
609
|
-
* Plugins that must already be installed.
|
|
610
|
-
*/
|
|
611
|
-
requires?: readonly string[];
|
|
612
|
-
/**
|
|
613
|
-
* Plugins that cannot be installed on the same client.
|
|
614
|
-
*/
|
|
615
|
-
conflicts?: readonly string[];
|
|
616
|
-
install: (context: PluginContext) => void | PluginCleanup;
|
|
617
|
-
}
|
|
618
|
-
//#endregion
|
|
619
|
-
//#region src/client/Client.d.ts
|
|
620
|
-
type MethodConfig = Omit<RequestConfig, 'url' | 'method'>;
|
|
621
|
-
type SchemaMethodConfig<Schema extends StandardSchemaV1> = Omit<MethodConfig, 'schema'> & {
|
|
622
|
-
schema: Schema;
|
|
623
|
-
};
|
|
624
|
-
declare class Client {
|
|
625
|
-
private readonly defaults;
|
|
626
|
-
private readonly adapter;
|
|
627
|
-
private readonly installedPlugins;
|
|
628
|
-
private readonly hooks;
|
|
629
|
-
readonly interceptors: {
|
|
630
|
-
request: InterceptorManager<RequestConfig>;
|
|
631
|
-
response: InterceptorManager<NporaResponse<unknown>>;
|
|
632
|
-
error: InterceptorManager<unknown>;
|
|
633
|
-
};
|
|
634
|
-
private readonly pipeline;
|
|
635
|
-
constructor(options?: ClientOptions);
|
|
636
|
-
/**
|
|
637
|
-
* Create an isolated client that inherits this client's defaults.
|
|
638
|
-
*/
|
|
639
|
-
extend(options?: ClientOptions): Client;
|
|
640
|
-
use(plugin: Plugin): this;
|
|
641
|
-
unuse(pluginName: string): this;
|
|
642
|
-
hasPlugin(pluginName: string): boolean;
|
|
643
|
-
request<Schema extends StandardSchemaV1>(config: RequestConfig & {
|
|
644
|
-
schema: Schema;
|
|
645
|
-
}): Promise<StandardSchemaV1.InferOutput<Schema>>;
|
|
646
|
-
request<T = unknown>(config: RequestConfig): Promise<T>;
|
|
647
|
-
requestResponse<Schema extends StandardSchemaV1>(config: RequestConfig & {
|
|
648
|
-
schema: Schema;
|
|
649
|
-
}): Promise<NporaResponse<StandardSchemaV1.InferOutput<Schema>>>;
|
|
650
|
-
requestResponse<T = unknown>(config: RequestConfig): Promise<NporaResponse<T>>;
|
|
651
|
-
get<Schema extends StandardSchemaV1>(url: string, config: SchemaMethodConfig<Schema>): Promise<StandardSchemaV1.InferOutput<Schema>>;
|
|
652
|
-
get<T = unknown>(url: string, config?: MethodConfig): Promise<T>;
|
|
653
|
-
getResponse<Schema extends StandardSchemaV1>(url: string, config: SchemaMethodConfig<Schema>): Promise<NporaResponse<StandardSchemaV1.InferOutput<Schema>>>;
|
|
654
|
-
getResponse<T = unknown>(url: string, config?: MethodConfig): Promise<NporaResponse<T>>;
|
|
655
|
-
post<Schema extends StandardSchemaV1>(url: string, config: SchemaMethodConfig<Schema>): Promise<StandardSchemaV1.InferOutput<Schema>>;
|
|
656
|
-
post<T = unknown>(url: string, config?: MethodConfig): Promise<T>;
|
|
657
|
-
postResponse<Schema extends StandardSchemaV1>(url: string, config: SchemaMethodConfig<Schema>): Promise<NporaResponse<StandardSchemaV1.InferOutput<Schema>>>;
|
|
658
|
-
postResponse<T = unknown>(url: string, config?: MethodConfig): Promise<NporaResponse<T>>;
|
|
659
|
-
put<Schema extends StandardSchemaV1>(url: string, config: SchemaMethodConfig<Schema>): Promise<StandardSchemaV1.InferOutput<Schema>>;
|
|
660
|
-
put<T = unknown>(url: string, config?: MethodConfig): Promise<T>;
|
|
661
|
-
putResponse<Schema extends StandardSchemaV1>(url: string, config: SchemaMethodConfig<Schema>): Promise<NporaResponse<StandardSchemaV1.InferOutput<Schema>>>;
|
|
662
|
-
putResponse<T = unknown>(url: string, config?: MethodConfig): Promise<NporaResponse<T>>;
|
|
663
|
-
patch<Schema extends StandardSchemaV1>(url: string, config: SchemaMethodConfig<Schema>): Promise<StandardSchemaV1.InferOutput<Schema>>;
|
|
664
|
-
patch<T = unknown>(url: string, config?: MethodConfig): Promise<T>;
|
|
665
|
-
patchResponse<Schema extends StandardSchemaV1>(url: string, config: SchemaMethodConfig<Schema>): Promise<NporaResponse<StandardSchemaV1.InferOutput<Schema>>>;
|
|
666
|
-
patchResponse<T = unknown>(url: string, config?: MethodConfig): Promise<NporaResponse<T>>;
|
|
667
|
-
delete<Schema extends StandardSchemaV1>(url: string, config: SchemaMethodConfig<Schema>): Promise<StandardSchemaV1.InferOutput<Schema>>;
|
|
668
|
-
delete<T = unknown>(url: string, config?: MethodConfig): Promise<T>;
|
|
669
|
-
deleteResponse<Schema extends StandardSchemaV1>(url: string, config: SchemaMethodConfig<Schema>): Promise<NporaResponse<StandardSchemaV1.InferOutput<Schema>>>;
|
|
670
|
-
deleteResponse<T = unknown>(url: string, config?: MethodConfig): Promise<NporaResponse<T>>;
|
|
671
|
-
head(url: string, config?: Omit<MethodConfig, 'schema'>): Promise<void>;
|
|
672
|
-
headResponse(url: string, config?: Omit<MethodConfig, 'schema'>): Promise<NporaResponse<void>>;
|
|
673
|
-
options<Schema extends StandardSchemaV1>(url: string, config: SchemaMethodConfig<Schema>): Promise<StandardSchemaV1.InferOutput<Schema>>;
|
|
674
|
-
options<T = unknown>(url: string, config?: MethodConfig): Promise<T>;
|
|
675
|
-
optionsResponse<Schema extends StandardSchemaV1>(url: string, config: SchemaMethodConfig<Schema>): Promise<NporaResponse<StandardSchemaV1.InferOutput<Schema>>>;
|
|
676
|
-
optionsResponse<T = unknown>(url: string, config?: MethodConfig): Promise<NporaResponse<T>>;
|
|
677
|
-
/**
|
|
678
|
-
* Consume a server-sent event response as a lazy async iterable.
|
|
679
|
-
*/
|
|
680
|
-
sse(url: string, config?: Omit<RequestConfig, 'url' | 'method' | 'responseType' | 'schema'>): Promise<AsyncIterable<ServerSentEvent>>;
|
|
681
|
-
/**
|
|
682
|
-
* Consume a server-sent event response with complete response metadata.
|
|
683
|
-
*/
|
|
684
|
-
sseResponse(url: string, config?: Omit<RequestConfig, 'url' | 'method' | 'responseType' | 'schema'>): Promise<NporaResponse<AsyncIterable<ServerSentEvent>>>;
|
|
685
|
-
/**
|
|
686
|
-
* Consume newline-delimited JSON records as a lazy async iterable.
|
|
687
|
-
*/
|
|
688
|
-
ndjson<T = unknown>(url: string, config?: Omit<RequestConfig, 'url' | 'method' | 'responseType' | 'schema'>): Promise<AsyncIterable<T>>;
|
|
689
|
-
/**
|
|
690
|
-
* Consume newline-delimited JSON with complete response metadata.
|
|
691
|
-
*/
|
|
692
|
-
ndjsonResponse<T = unknown>(url: string, config?: Omit<RequestConfig, 'url' | 'method' | 'responseType' | 'schema'>): Promise<NporaResponse<AsyncIterable<T>>>;
|
|
693
|
-
private requestMethod;
|
|
694
|
-
private requestMethodResponse;
|
|
695
|
-
private mergeMethodConfig;
|
|
696
|
-
private createPipeline;
|
|
697
|
-
private validatePlugin;
|
|
698
|
-
private findDependent;
|
|
699
|
-
}
|
|
700
|
-
//#endregion
|
|
701
|
-
//#region src/client/createClient.d.ts
|
|
702
|
-
/**
|
|
703
|
-
* Create an HTTP client instance.
|
|
704
|
-
*/
|
|
705
|
-
declare function createClient(options?: ClientOptions): Client;
|
|
706
|
-
//#endregion
|
|
707
|
-
//#region src/errors/RequestError.d.ts
|
|
708
|
-
/**
|
|
709
|
-
* Public request error codes.
|
|
710
|
-
*/
|
|
711
|
-
type RequestErrorCode = 'CONFIG_ERROR' | 'HTTP_ERROR' | 'NETWORK_ERROR' | 'TIMEOUT_ERROR' | 'ABORT_ERROR' | 'PARSER_ERROR' | 'SCHEMA_ERROR' | 'RESPONSE_TOO_LARGE' | 'CIRCUIT_OPEN' | 'CONCURRENCY_LIMIT';
|
|
712
|
-
interface RequestErrorOptions<T = unknown> {
|
|
713
|
-
/**
|
|
714
|
-
* Stable machine-readable error code.
|
|
715
|
-
*/
|
|
716
|
-
code: RequestErrorCode;
|
|
717
|
-
/**
|
|
718
|
-
* HTTP response status when available.
|
|
719
|
-
*/
|
|
720
|
-
status?: number;
|
|
721
|
-
/**
|
|
722
|
-
* Parsed response body when the server returned a response.
|
|
723
|
-
*/
|
|
724
|
-
data?: T;
|
|
725
|
-
/**
|
|
726
|
-
* Complete response metadata when the server returned a response.
|
|
727
|
-
*/
|
|
728
|
-
response?: NporaResponse<T>;
|
|
729
|
-
/**
|
|
730
|
-
* Effective request configuration.
|
|
731
|
-
*/
|
|
732
|
-
config?: RequestConfig;
|
|
733
|
-
/**
|
|
734
|
-
* Original error.
|
|
735
|
-
*/
|
|
736
|
-
cause?: unknown;
|
|
737
|
-
}
|
|
738
|
-
/**
|
|
739
|
-
* Unified public error for all request failures.
|
|
740
|
-
*/
|
|
741
|
-
declare class RequestError<T = unknown> extends Error {
|
|
742
|
-
readonly code: RequestErrorCode;
|
|
743
|
-
readonly status?: number;
|
|
744
|
-
readonly data?: T;
|
|
745
|
-
readonly response?: NporaResponse<T>;
|
|
746
|
-
readonly config?: RequestConfig;
|
|
747
|
-
readonly cause?: unknown;
|
|
748
|
-
constructor(message: string, options: RequestErrorOptions<T>);
|
|
749
|
-
}
|
|
750
|
-
//#endregion
|
|
751
|
-
//#region src/errors/SchemaValidationError.d.ts
|
|
752
|
-
/**
|
|
753
|
-
* Response failure reported by a Standard Schema compatible validator.
|
|
754
|
-
*/
|
|
755
|
-
declare class SchemaValidationError<T = unknown> extends RequestError<T> {
|
|
756
|
-
readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
|
|
757
|
-
readonly schemaVendor: string;
|
|
758
|
-
constructor(message: string, response: NporaResponse<T>, schemaVendor: string, issues?: ReadonlyArray<StandardSchemaV1.Issue>, cause?: unknown);
|
|
759
|
-
}
|
|
760
|
-
//#endregion
|
|
761
|
-
//#region src/plugins/PluginError.d.ts
|
|
762
|
-
type PluginErrorCode = 'MISSING_DEPENDENCY' | 'PLUGIN_CONFLICT' | 'DEPENDENCY_IN_USE';
|
|
763
|
-
interface PluginErrorOptions {
|
|
764
|
-
code: PluginErrorCode;
|
|
765
|
-
plugin: string;
|
|
766
|
-
relatedPlugin: string;
|
|
767
|
-
}
|
|
768
|
-
/**
|
|
769
|
-
* Stable error thrown for invalid plugin lifecycle operations.
|
|
770
|
-
*/
|
|
771
|
-
declare class PluginError extends Error {
|
|
772
|
-
readonly code: PluginErrorCode;
|
|
773
|
-
readonly plugin: string;
|
|
774
|
-
readonly relatedPlugin: string;
|
|
775
|
-
constructor(message: string, options: PluginErrorOptions);
|
|
776
|
-
}
|
|
777
|
-
//#endregion
|
|
778
|
-
//#region src/plugins/authPlugin.d.ts
|
|
779
|
-
type MaybePromise$1<T> = T | Promise<T>;
|
|
780
|
-
/**
|
|
781
|
-
* Token storage used by the authentication extension.
|
|
782
|
-
*
|
|
783
|
-
* Storage implementation is supplied by the application.
|
|
784
|
-
* The request library does not access localStorage or sessionStorage directly.
|
|
785
|
-
*/
|
|
786
|
-
interface AuthTokenStorage {
|
|
787
|
-
get(): MaybePromise$1<string | null | undefined>;
|
|
788
|
-
set(token: string): MaybePromise$1<void>;
|
|
789
|
-
remove(): MaybePromise$1<void>;
|
|
790
|
-
}
|
|
791
|
-
interface AuthPluginOptions {
|
|
792
|
-
/**
|
|
793
|
-
* Access token or access-token provider.
|
|
794
|
-
*
|
|
795
|
-
* When both token and storage are provided,
|
|
796
|
-
* the request-level token has the highest priority,
|
|
797
|
-
* followed by this token option, then storage.
|
|
798
|
-
*/
|
|
799
|
-
token?: string | (() => MaybePromise$1<string>);
|
|
800
|
-
/**
|
|
801
|
-
* Authorization scheme.
|
|
802
|
-
*
|
|
803
|
-
* @default 'Bearer'
|
|
804
|
-
*/
|
|
805
|
-
scheme?: string;
|
|
806
|
-
/**
|
|
807
|
-
* Optional access-token storage.
|
|
808
|
-
*/
|
|
809
|
-
storage?: AuthTokenStorage;
|
|
810
|
-
/**
|
|
811
|
-
* Refresh the access token.
|
|
812
|
-
*
|
|
813
|
-
* Returning a token stores it through storage when configured.
|
|
814
|
-
* Returning void allows the callback to update external state itself.
|
|
815
|
-
*/
|
|
816
|
-
refreshToken?: () => MaybePromise$1<string | void>;
|
|
817
|
-
/**
|
|
818
|
-
* Determine whether an error should trigger token refresh.
|
|
819
|
-
*
|
|
820
|
-
* @default HTTP status 401
|
|
821
|
-
*/
|
|
822
|
-
shouldRefresh?: (error: unknown) => MaybePromise$1<boolean>;
|
|
823
|
-
}
|
|
824
|
-
/**
|
|
825
|
-
* Authentication plugin.
|
|
826
|
-
*/
|
|
827
|
-
declare function authPlugin(options?: AuthPluginOptions): Plugin;
|
|
828
|
-
//#endregion
|
|
829
|
-
//#region src/plugins/cachePlugin.d.ts
|
|
830
|
-
type MaybePromise<T> = T | Promise<T>;
|
|
831
|
-
interface CacheEntry {
|
|
832
|
-
data: unknown;
|
|
833
|
-
expiresAt: number;
|
|
834
|
-
status: number;
|
|
835
|
-
statusText: string;
|
|
836
|
-
headers: Array<[string, string]>;
|
|
837
|
-
raw?: Response;
|
|
838
|
-
}
|
|
839
|
-
interface CacheStore {
|
|
840
|
-
get(key: string): MaybePromise<CacheEntry | undefined>;
|
|
841
|
-
set(key: string, entry: CacheEntry): MaybePromise<void>;
|
|
842
|
-
delete(key: string): MaybePromise<void>;
|
|
843
|
-
clear(): MaybePromise<void>;
|
|
844
|
-
}
|
|
845
|
-
interface MemoryCacheStoreOptions {
|
|
846
|
-
/**
|
|
847
|
-
* Maximum entries retained by the in-memory LRU store.
|
|
848
|
-
* Use `Infinity` for no practical limit.
|
|
849
|
-
*
|
|
850
|
-
* @default 1000
|
|
851
|
-
*/
|
|
852
|
-
maxEntries?: number;
|
|
853
|
-
}
|
|
854
|
-
declare class MemoryCacheStore implements CacheStore {
|
|
855
|
-
private readonly entries;
|
|
856
|
-
private readonly maxEntries;
|
|
857
|
-
private newestKey;
|
|
858
|
-
constructor(options?: MemoryCacheStoreOptions);
|
|
859
|
-
get(key: string): CacheEntry | undefined;
|
|
860
|
-
set(key: string, entry: CacheEntry): void;
|
|
861
|
-
delete(key: string): void;
|
|
862
|
-
clear(): void;
|
|
863
|
-
}
|
|
864
|
-
interface CachePluginOptions {
|
|
865
|
-
/**
|
|
866
|
-
* HTTP methods that may be cached.
|
|
867
|
-
*
|
|
868
|
-
* @default GET and HEAD
|
|
869
|
-
*/
|
|
870
|
-
methods?: readonly HttpMethod[];
|
|
871
|
-
/**
|
|
872
|
-
* Additional request headers included in the default cache key.
|
|
873
|
-
* All explicitly configured request headers are included automatically.
|
|
874
|
-
*
|
|
875
|
-
* @default authorization, cookie, accept and accept-language
|
|
876
|
-
*/
|
|
877
|
-
varyHeaders?: readonly string[];
|
|
878
|
-
/**
|
|
879
|
-
* Cache storage shared by this plugin instance.
|
|
880
|
-
*
|
|
881
|
-
* @default an isolated MemoryCacheStore
|
|
882
|
-
*/
|
|
883
|
-
store?: CacheStore;
|
|
884
|
-
/**
|
|
885
|
-
* Maximum entries retained by the default MemoryCacheStore.
|
|
886
|
-
* Ignored when `store` is provided.
|
|
887
|
-
*
|
|
888
|
-
* @default 1000
|
|
889
|
-
*/
|
|
890
|
-
maxEntries?: number;
|
|
891
|
-
/**
|
|
892
|
-
* Share one network operation between concurrent equivalent requests.
|
|
893
|
-
*
|
|
894
|
-
* @default true
|
|
895
|
-
*/
|
|
896
|
-
dedupe?: boolean;
|
|
897
|
-
}
|
|
898
|
-
interface CachePlugin extends Plugin {
|
|
899
|
-
clear(): MaybePromise<void>;
|
|
900
|
-
}
|
|
901
|
-
declare function cachePlugin(options?: CachePluginOptions): CachePlugin;
|
|
902
|
-
//#endregion
|
|
903
|
-
//#region src/plugins/circuitBreakerPlugin.d.ts
|
|
904
|
-
interface CircuitBreakerPluginOptions {
|
|
905
|
-
/**
|
|
906
|
-
* Consecutive counted failures required to open a closed circuit.
|
|
907
|
-
*
|
|
908
|
-
* @default 5
|
|
909
|
-
*/
|
|
910
|
-
failureThreshold?: number;
|
|
911
|
-
/**
|
|
912
|
-
* Successful probes required to close a half-open circuit.
|
|
913
|
-
*
|
|
914
|
-
* @default 1
|
|
915
|
-
*/
|
|
916
|
-
successThreshold?: number;
|
|
917
|
-
/**
|
|
918
|
-
* Time in milliseconds before an open circuit permits probes.
|
|
919
|
-
*
|
|
920
|
-
* @default 30000
|
|
921
|
-
*/
|
|
922
|
-
resetTimeout?: number;
|
|
923
|
-
/**
|
|
924
|
-
* Maximum concurrent probes admitted while a circuit is half-open.
|
|
925
|
-
*
|
|
926
|
-
* @default 1
|
|
927
|
-
*/
|
|
928
|
-
halfOpenMaxRequests?: number;
|
|
929
|
-
/**
|
|
930
|
-
* Maximum inactive isolation states retained by this plugin instance.
|
|
931
|
-
* Active requests are never evicted and may temporarily exceed the limit.
|
|
932
|
-
*
|
|
933
|
-
* @default 1000
|
|
934
|
-
*/
|
|
935
|
-
maxCircuits?: number;
|
|
936
|
-
/**
|
|
937
|
-
* Create the default isolation key for a request.
|
|
938
|
-
*
|
|
939
|
-
* @default the resolved request origin or "default"
|
|
940
|
-
*/
|
|
941
|
-
createKey?: (config: RequestConfig) => string;
|
|
942
|
-
/**
|
|
943
|
-
* Decide whether a final request failure affects the circuit.
|
|
944
|
-
*
|
|
945
|
-
* @default network errors, timeouts, HTTP 429, and HTTP 5xx
|
|
946
|
-
*/
|
|
947
|
-
shouldCountFailure?: (error: unknown, config: RequestConfig) => boolean | Promise<boolean>;
|
|
948
|
-
/**
|
|
949
|
-
* Observe circuit state changes. Observer failures are isolated.
|
|
950
|
-
*/
|
|
951
|
-
onStateChange?: (event: Readonly<CircuitBreakerStateChange>) => void | Promise<void>;
|
|
952
|
-
}
|
|
953
|
-
interface CircuitBreakerPlugin extends Plugin {
|
|
954
|
-
getState(key: string): CircuitState;
|
|
955
|
-
reset(key?: string): void;
|
|
956
|
-
}
|
|
957
|
-
declare function circuitBreakerPlugin(options?: CircuitBreakerPluginOptions): CircuitBreakerPlugin;
|
|
958
|
-
//#endregion
|
|
959
|
-
//#region src/plugins/concurrencyPlugin.d.ts
|
|
960
|
-
interface ConcurrencyPluginOptions {
|
|
961
|
-
/**
|
|
962
|
-
* Maximum active logical requests for each isolation key.
|
|
963
|
-
*
|
|
964
|
-
* @default 10
|
|
965
|
-
*/
|
|
966
|
-
maxConcurrent?: number;
|
|
967
|
-
/**
|
|
968
|
-
* Maximum queued requests for each isolation key.
|
|
969
|
-
* Set to zero to reject instead of waiting.
|
|
970
|
-
*
|
|
971
|
-
* @default 1000
|
|
972
|
-
*/
|
|
973
|
-
maxQueue?: number;
|
|
974
|
-
/**
|
|
975
|
-
* Maximum time in milliseconds a request may wait for a permit.
|
|
976
|
-
*
|
|
977
|
-
* @default 30000
|
|
978
|
-
*/
|
|
979
|
-
queueTimeout?: number;
|
|
980
|
-
/**
|
|
981
|
-
* Maximum inactive isolation states retained by this plugin instance.
|
|
982
|
-
* Active and queued states are never evicted and may temporarily exceed
|
|
983
|
-
* the limit.
|
|
984
|
-
*
|
|
985
|
-
* @default 1000
|
|
986
|
-
*/
|
|
987
|
-
maxKeys?: number;
|
|
988
|
-
/**
|
|
989
|
-
* Create the default isolation key for a request.
|
|
990
|
-
*
|
|
991
|
-
* @default the resolved request origin or "default"
|
|
992
|
-
*/
|
|
993
|
-
createKey?: (config: RequestConfig) => string;
|
|
994
|
-
}
|
|
995
|
-
interface ConcurrencyState {
|
|
996
|
-
active: number;
|
|
997
|
-
queued: number;
|
|
998
|
-
}
|
|
999
|
-
interface ConcurrencyPlugin extends Plugin {
|
|
1000
|
-
getState(key: string): Readonly<ConcurrencyState>;
|
|
1001
|
-
}
|
|
1002
|
-
declare function concurrencyPlugin(options?: ConcurrencyPluginOptions): ConcurrencyPlugin;
|
|
1003
|
-
//#endregion
|
|
1004
|
-
//#region src/plugins/downloadPlugin.d.ts
|
|
1005
|
-
type DownloadTransport = 'auto' | 'fetch' | 'xhr';
|
|
1006
|
-
interface DownloadPluginOptions {
|
|
1007
|
-
/**
|
|
1008
|
-
* Download progress transport.
|
|
1009
|
-
*
|
|
1010
|
-
* `auto` prefers Fetch response streams and falls back to XMLHttpRequest
|
|
1011
|
-
* when streaming responses are unavailable.
|
|
1012
|
-
*
|
|
1013
|
-
* @default auto
|
|
1014
|
-
*/
|
|
1015
|
-
transport?: DownloadTransport;
|
|
1016
|
-
}
|
|
1017
|
-
declare function downloadPlugin(options?: DownloadPluginOptions): Plugin;
|
|
1018
|
-
//#endregion
|
|
1019
|
-
//#region src/plugins/loggerPlugin.d.ts
|
|
1020
|
-
declare function loggerPlugin(defaultOptions?: LoggerOptions): Plugin;
|
|
1021
|
-
//#endregion
|
|
1022
|
-
//#region src/plugins/retryPlugin.d.ts
|
|
1023
|
-
declare function retryPlugin(defaultOptions?: RetryOptions): Plugin;
|
|
1024
|
-
//#endregion
|
|
1025
|
-
//#region src/plugins/uploadPlugin.d.ts
|
|
1026
|
-
declare function uploadPlugin(): Plugin;
|
|
1027
|
-
//#endregion
|
|
1028
|
-
export { Adapter, AuthOptions, AuthPluginOptions, AuthTokenStorage, CacheEntry, CacheOptions, CachePlugin, CachePluginOptions, CacheStore, CircuitBreakerOptions, CircuitBreakerPlugin, CircuitBreakerPluginOptions, CircuitBreakerStateChange, CircuitState, Client, ClientOptions, ConcurrencyOptions, ConcurrencyPlugin, ConcurrencyPluginOptions, ConcurrencyState, DownloadOptions, DownloadOutput, 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, SchemaValidationError, ServerSentEvent, StandardSchemaV1, TransferProgress, UploadData, UploadOptions, UploadProgress, authPlugin, cachePlugin, circuitBreakerPlugin, concurrencyPlugin, createClient, downloadPlugin, loggerPlugin, retryPlugin, uploadPlugin };
|
|
1
|
+
import { A as StandardSchemaV1, C as ResponseLogEntry, D as UploadData, E as TransferProgress, O as UploadOptions, S as RequestLogger, T as RetryOptions, _ as DownloadProgress, a as QueryValue, b as LoggerOptions, c as ResponseType, d as CircuitBreakerOptions, f as CircuitBreakerStateChange, g as DownloadOutput, h as DownloadOptions, i as QueryParams, j as HttpMethod, k as UploadProgress, l as AuthOptions, m as ConcurrencyOptions, n as ServerSentEvent, o as RequestConfig, p as CircuitState, r as FetchOptions, s as RequestExtensions, t as NporaResponse, u as CacheOptions, v as ErrorLogEntry, w as RetryEvent, x as RequestLogEntry, y as LoggerEntry } from "./response-BhyS3PAL.cjs";
|
|
2
|
+
import { t as Adapter } from "./adapter-BeVVCcNG.cjs";
|
|
3
|
+
import { a as FetchAdapter, c as ClientOptions, i as RequestErrorOptions, n as RequestError, o as createClient, r as RequestErrorCode, s as Client, t as SchemaValidationError } from "./SchemaValidationError-WMTfqSBV.cjs";
|
|
4
|
+
import { a as MockReplyHandler, c as MockRoute, i as MockReply, l as MockURLMatcher, n as MockAdapterOptions, o as MockRequestMatcher, r as MockHandler, s as MockResponseOptions, t as MockAdapter } from "./MockAdapter-ChWzzSnH.cjs";
|
|
5
|
+
import { a as PluginInterceptorManager, c as InterceptorOptions, i as PluginHookManager, n as PluginCleanup, o as Interceptor, r as PluginContext, s as InterceptorManager, t as Plugin } from "./Plugin-YysllE6z.cjs";
|
|
6
|
+
import { n as PluginErrorCode, r as PluginErrorOptions, t as PluginError } from "./PluginError-DVP3pUt_.cjs";
|
|
7
|
+
import { n as AuthTokenStorage, r as authPlugin, t as AuthPluginOptions } from "./authPlugin-B_YpkyC8.cjs";
|
|
8
|
+
import { C as IndexedDBCacheStoreOptions, S as IndexedDBCacheStoreEvent, _ as TieredCacheStore, a as CachePluginOptions, b as IndexedDBCacheCompactionResult, c as CacheStats, d as MemoryCacheStoreOptions, f as WebStorageCacheStore, g as TieredCacheCoordinationOptions, h as TieredCacheBroadcastOptions, i as CachePlugin, l as CacheStore, m as cachePlugin, n as CacheEvent, o as CacheRefreshLease, p as WebStorageCacheStoreOptions, r as CacheEventType, s as CacheSetOptions, t as CacheEntry, u as MemoryCacheStore, v as TieredCacheStoreOptions, w as IndexedDBCacheUsage, x as IndexedDBCacheStore, y as IndexedDBCacheCompactionOptions } from "./cachePlugin-B9Hvsprg.cjs";
|
|
9
|
+
import { n as CircuitBreakerPluginOptions, r as circuitBreakerPlugin, t as CircuitBreakerPlugin } from "./circuitBreakerPlugin-B45xghq9.cjs";
|
|
10
|
+
import { i as concurrencyPlugin, n as ConcurrencyPluginOptions, r as ConcurrencyState, t as ConcurrencyPlugin } from "./concurrencyPlugin-CuJMua41.cjs";
|
|
11
|
+
import { n as DownloadTransport, r as downloadPlugin, t as DownloadPluginOptions } from "./downloadPlugin-CEXXJiDo.cjs";
|
|
12
|
+
import { t as loggerPlugin } from "./loggerPlugin-uOFiUtBi.cjs";
|
|
13
|
+
import { t as retryPlugin } from "./retryPlugin-BqlUpmd0.cjs";
|
|
14
|
+
import { t as uploadPlugin } from "./uploadPlugin-AfhFIsO7.cjs";
|
|
15
|
+
export { Adapter, AuthOptions, AuthPluginOptions, AuthTokenStorage, CacheEntry, CacheEvent, CacheEventType, CacheOptions, CachePlugin, CachePluginOptions, CacheRefreshLease, CacheSetOptions, CacheStats, CacheStore, CircuitBreakerOptions, CircuitBreakerPlugin, CircuitBreakerPluginOptions, CircuitBreakerStateChange, CircuitState, Client, ClientOptions, ConcurrencyOptions, ConcurrencyPlugin, ConcurrencyPluginOptions, ConcurrencyState, DownloadOptions, DownloadOutput, DownloadPluginOptions, DownloadProgress, DownloadTransport, ErrorLogEntry, FetchAdapter, FetchOptions, HttpMethod, type IndexedDBCacheCompactionOptions, type IndexedDBCacheCompactionResult, IndexedDBCacheStore, type IndexedDBCacheStoreEvent, type IndexedDBCacheStoreOptions, type IndexedDBCacheUsage, 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, SchemaValidationError, ServerSentEvent, StandardSchemaV1, type TieredCacheBroadcastOptions, type TieredCacheCoordinationOptions, TieredCacheStore, type TieredCacheStoreOptions, TransferProgress, UploadData, UploadOptions, UploadProgress, WebStorageCacheStore, WebStorageCacheStoreOptions, authPlugin, cachePlugin, circuitBreakerPlugin, concurrencyPlugin, createClient, downloadPlugin, loggerPlugin, retryPlugin, uploadPlugin };
|