@npora/request 1.14.4 → 1.15.1

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.
Files changed (106) hide show
  1. package/README.md +231 -5
  2. package/dist/MockAdapter-ChWzzSnH.d.cts +71 -0
  3. package/dist/MockAdapter-H50LoFDu.d.ts +71 -0
  4. package/dist/Plugin-0Eh51_et.d.ts +124 -0
  5. package/dist/Plugin-YysllE6z.d.cts +124 -0
  6. package/dist/PluginError-CcuPSIRv.js +1 -0
  7. package/dist/PluginError-DT3VnlUB.cjs +1 -0
  8. package/dist/PluginError-DVP3pUt_.d.cts +18 -0
  9. package/dist/PluginError-DVP3pUt_.d.ts +18 -0
  10. package/dist/RequestError-BH6V64XR.js +1 -0
  11. package/dist/RequestError-DPSv-HVF.cjs +1 -0
  12. package/dist/SchemaValidationError-CjvWT8YA.d.ts +166 -0
  13. package/dist/SchemaValidationError-WMTfqSBV.d.cts +166 -0
  14. package/dist/adapter-BeVVCcNG.d.cts +21 -0
  15. package/dist/adapter-ODzpt_dM.d.ts +21 -0
  16. package/dist/authPlugin-6E6_0dAO.d.ts +53 -0
  17. package/dist/authPlugin-B_YpkyC8.d.cts +53 -0
  18. package/dist/buildRequest-BRZwRLoN.cjs +1 -0
  19. package/dist/buildRequest-Cwt8XEWO.js +1 -0
  20. package/dist/cachePlugin-B9Hvsprg.d.cts +297 -0
  21. package/dist/cachePlugin-CSHwJYwI.js +1 -0
  22. package/dist/cachePlugin-CvH26DBo.d.ts +297 -0
  23. package/dist/cachePlugin-ZPYdHbsM.cjs +1 -0
  24. package/dist/circuitBreakerPlugin-B45xghq9.d.cts +59 -0
  25. package/dist/circuitBreakerPlugin-DsH6YCNe.d.ts +59 -0
  26. package/dist/concurrencyPlugin-CuJMua41.d.cts +48 -0
  27. package/dist/concurrencyPlugin-dwGNFYrM.d.ts +48 -0
  28. package/dist/core.cjs +1 -0
  29. package/dist/core.d.cts +6 -0
  30. package/dist/core.d.ts +6 -0
  31. package/dist/core.js +1 -0
  32. package/dist/createAbortError-D4rRBq2B.js +1 -0
  33. package/dist/createAbortError-DJqbdYgk.cjs +1 -0
  34. package/dist/createClient-CibOTVAy.cjs +1 -0
  35. package/dist/createClient-I13D6XsD.js +1 -0
  36. package/dist/downloadPlugin-CEXXJiDo.d.cts +17 -0
  37. package/dist/downloadPlugin-s8VS8t9r.d.ts +17 -0
  38. package/dist/index.cjs +1 -4
  39. package/dist/index.d.cts +15 -1028
  40. package/dist/index.d.ts +15 -1028
  41. package/dist/index.js +1 -4
  42. package/dist/isPromiseLike-BuAv3bAe.js +1 -0
  43. package/dist/isPromiseLike-C8e95Or2.cjs +1 -0
  44. package/dist/isURLSearchParams-B93cMCGj.js +1 -0
  45. package/dist/isURLSearchParams-o-c8Q42t.cjs +1 -0
  46. package/dist/loggerPlugin-C15EW7Sc.d.ts +6 -0
  47. package/dist/loggerPlugin-uOFiUtBi.d.cts +6 -0
  48. package/dist/maxTimerDelay-Hn7X0Wuh.js +1 -0
  49. package/dist/maxTimerDelay-NH5XeTXb.cjs +1 -0
  50. package/dist/plugins/auth.cjs +1 -0
  51. package/dist/plugins/auth.d.cts +2 -0
  52. package/dist/plugins/auth.d.ts +2 -0
  53. package/dist/plugins/auth.js +1 -0
  54. package/dist/plugins/cache.cjs +1 -0
  55. package/dist/plugins/cache.d.cts +2 -0
  56. package/dist/plugins/cache.d.ts +2 -0
  57. package/dist/plugins/cache.js +1 -0
  58. package/dist/plugins/circuit-breaker.cjs +1 -0
  59. package/dist/plugins/circuit-breaker.d.cts +2 -0
  60. package/dist/plugins/circuit-breaker.d.ts +2 -0
  61. package/dist/plugins/circuit-breaker.js +1 -0
  62. package/dist/plugins/concurrency.cjs +1 -0
  63. package/dist/plugins/concurrency.d.cts +2 -0
  64. package/dist/plugins/concurrency.d.ts +2 -0
  65. package/dist/plugins/concurrency.js +1 -0
  66. package/dist/plugins/download.cjs +1 -0
  67. package/dist/plugins/download.d.cts +2 -0
  68. package/dist/plugins/download.d.ts +2 -0
  69. package/dist/plugins/download.js +1 -0
  70. package/dist/plugins/logger.cjs +1 -0
  71. package/dist/plugins/logger.d.cts +2 -0
  72. package/dist/plugins/logger.d.ts +2 -0
  73. package/dist/plugins/logger.js +1 -0
  74. package/dist/plugins/retry.cjs +1 -0
  75. package/dist/plugins/retry.d.cts +2 -0
  76. package/dist/plugins/retry.d.ts +2 -0
  77. package/dist/plugins/retry.js +1 -0
  78. package/dist/plugins/upload.cjs +1 -0
  79. package/dist/plugins/upload.d.cts +2 -0
  80. package/dist/plugins/upload.d.ts +2 -0
  81. package/dist/plugins/upload.js +1 -0
  82. package/dist/plugins.cjs +1 -0
  83. package/dist/plugins.d.cts +11 -0
  84. package/dist/plugins.d.ts +11 -0
  85. package/dist/plugins.js +1 -0
  86. package/dist/resolveExtensionConfig-BHHfQwjF.cjs +1 -0
  87. package/dist/resolveExtensionConfig-QAFHZVte.js +1 -0
  88. package/dist/resolveRequestOrigin-BndIJeZ7.js +1 -0
  89. package/dist/resolveRequestOrigin-CRATeWff.cjs +1 -0
  90. package/dist/response-BhyS3PAL.d.cts +441 -0
  91. package/dist/response-BhyS3PAL.d.ts +441 -0
  92. package/dist/retryPlugin-2mYKvWy3.d.ts +6 -0
  93. package/dist/retryPlugin-BqlUpmd0.d.cts +6 -0
  94. package/dist/testing.cjs +1 -0
  95. package/dist/testing.d.cts +2 -0
  96. package/dist/testing.d.ts +2 -0
  97. package/dist/testing.js +1 -0
  98. package/dist/uploadPlugin-AfhFIsO7.d.cts +5 -0
  99. package/dist/uploadPlugin-Bb7EawRX.d.ts +5 -0
  100. package/dist/validateResponseStatus-Dqzr342t.js +4 -0
  101. package/dist/validateResponseStatus-QAjcah2i.cjs +4 -0
  102. package/dist/waitForSignal-DyyPvJd5.js +1 -0
  103. package/dist/waitForSignal-yR1BeU8f.cjs +1 -0
  104. package/dist/xhrTransport-C0pg00i5.js +1 -0
  105. package/dist/xhrTransport-CeW2DDzo.cjs +1 -0
  106. package/package.json +65 -2
@@ -0,0 +1,441 @@
1
+ //#region src/types/method.d.ts
2
+ /**
3
+ * HTTP request method.
4
+ */
5
+ type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS';
6
+ //#endregion
7
+ //#region src/types/standardSchema.d.ts
8
+ /**
9
+ * Standard Schema v1 interface.
10
+ *
11
+ * Compatible schema libraries can be consumed without a runtime dependency on
12
+ * `@standard-schema/spec`.
13
+ */
14
+ interface StandardSchemaV1<Input = unknown, Output = Input> {
15
+ readonly '~standard': StandardSchemaV1.Props<Input, Output>;
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
+ /**
145
+ * Maximum time in milliseconds that an expired entry may be used after an
146
+ * eligible network or 5xx failure. Response `stale-if-error` may shorten it.
147
+ *
148
+ * @default response stale-if-error, otherwise disabled
149
+ */
150
+ staleIfError?: number;
151
+ /**
152
+ * Maximum time in milliseconds that an expired entry may be returned while
153
+ * one deduplicated background refresh runs. The response directive may
154
+ * shorten this window.
155
+ *
156
+ * @default response stale-while-revalidate, otherwise disabled
157
+ */
158
+ staleWhileRevalidate?: number;
159
+ key?: string;
160
+ /** Tags used for grouped cache invalidation. */
161
+ tags?: readonly string[];
162
+ /** Tags invalidated after this request settles successfully. */
163
+ invalidateTags?: readonly string[];
164
+ /**
165
+ * Share one network operation between concurrent equivalent requests.
166
+ *
167
+ * @default true
168
+ */
169
+ dedupe?: boolean;
170
+ }
171
+ interface ConcurrencyOptions {
172
+ /**
173
+ * Enable concurrency limiting for this request.
174
+ *
175
+ * @default true
176
+ */
177
+ enabled?: boolean;
178
+ /**
179
+ * Override the isolation key for this request.
180
+ */
181
+ key?: string;
182
+ /**
183
+ * Maximum time in milliseconds this request may wait for a permit.
184
+ *
185
+ * @default the plugin-level queueTimeout
186
+ */
187
+ queueTimeout?: number;
188
+ }
189
+ interface AuthOptions {
190
+ token?: string | (() => string | Promise<string>);
191
+ scheme?: string;
192
+ }
193
+ interface LoggerOptions {
194
+ enabled?: boolean;
195
+ /**
196
+ * Structured log destination.
197
+ *
198
+ * @default console
199
+ */
200
+ logger?: RequestLogger;
201
+ /**
202
+ * Create the identifier shared by all lifecycle entries for a request.
203
+ *
204
+ * @default a plugin-local monotonic identifier
205
+ */
206
+ createRequestId?: () => string;
207
+ }
208
+ interface RequestLogEntry {
209
+ type: 'request';
210
+ requestId: string;
211
+ timestamp: number;
212
+ method: HttpMethod;
213
+ url: string;
214
+ }
215
+ interface ResponseLogEntry {
216
+ type: 'response';
217
+ requestId: string;
218
+ timestamp: number;
219
+ duration: number;
220
+ attempts: number;
221
+ method: HttpMethod;
222
+ url: string;
223
+ status: number;
224
+ }
225
+ interface ErrorLogEntry {
226
+ type: 'error';
227
+ requestId: string;
228
+ timestamp: number;
229
+ duration: number;
230
+ attempt: number;
231
+ method: HttpMethod;
232
+ url: string;
233
+ name: string;
234
+ message: string;
235
+ code?: string;
236
+ status?: number;
237
+ }
238
+ type LoggerEntry = RequestLogEntry | ResponseLogEntry | ErrorLogEntry;
239
+ interface RequestLogger {
240
+ info(message: string, entry: RequestLogEntry | ResponseLogEntry): void | Promise<void>;
241
+ error(message: string, entry: ErrorLogEntry): void | Promise<void>;
242
+ }
243
+ type UploadData = FormData | Record<string, unknown>;
244
+ interface TransferProgress {
245
+ /**
246
+ * Cumulative number of bytes transferred.
247
+ */
248
+ loaded: number;
249
+ /**
250
+ * Total transfer size when the runtime provides it.
251
+ */
252
+ total?: number;
253
+ /**
254
+ * Progress ratio between 0 and 1 when total is available.
255
+ */
256
+ progress?: number;
257
+ /**
258
+ * Bytes transferred since the previous progress event.
259
+ */
260
+ bytes?: number;
261
+ /**
262
+ * Average transfer rate in bytes per second when measurable.
263
+ */
264
+ rate?: number;
265
+ /**
266
+ * Estimated remaining seconds when total and rate are available.
267
+ */
268
+ estimated?: number;
269
+ }
270
+ /**
271
+ * Upload progress information.
272
+ */
273
+ interface UploadProgress extends TransferProgress {}
274
+ interface UploadOptions {
275
+ data: UploadData;
276
+ /**
277
+ * Called while XMLHttpRequest uploads the request body.
278
+ */
279
+ onProgress?: (progress: UploadProgress) => void;
280
+ }
281
+ /**
282
+ * Download progress information.
283
+ */
284
+ interface DownloadProgress extends TransferProgress {}
285
+ type DownloadOutput = 'blob' | 'stream';
286
+ interface DownloadOptions {
287
+ /**
288
+ * Returned download representation.
289
+ *
290
+ * `stream` requires Fetch response-stream support and preserves backpressure
291
+ * without buffering the complete response in memory.
292
+ *
293
+ * @default 'blob'
294
+ */
295
+ output?: DownloadOutput;
296
+ /**
297
+ * Reserved legacy field. It does not save or rename the returned Blob.
298
+ *
299
+ * @deprecated This field currently has no effect.
300
+ */
301
+ filename?: string;
302
+ /**
303
+ * Called while the response stream is being consumed.
304
+ */
305
+ onProgress?: (progress: DownloadProgress) => void;
306
+ }
307
+ //#endregion
308
+ //#region src/types/config.d.ts
309
+ type QueryValue = string | number | boolean | null | undefined;
310
+ type QueryParams = Record<string, QueryValue | QueryValue[]>;
311
+ type ResponseType = 'json' | 'text' | 'blob' | 'arrayBuffer' | 'stream' | 'sse' | 'ndjson';
312
+ /**
313
+ * Native Fetch options passed to the underlying adapter.
314
+ *
315
+ * Request fields managed by Npora Request are intentionally omitted so there
316
+ * is a single source of truth for method, headers, body and cancellation.
317
+ */
318
+ type FetchOptions = Omit<RequestInit, 'method' | 'headers' | 'body' | 'signal'>;
319
+ /**
320
+ * Plugin-owned request configuration.
321
+ *
322
+ * Plugins extend this interface through TypeScript module augmentation.
323
+ */
324
+ interface RequestExtensions {
325
+ auth?: AuthOptions;
326
+ cache?: CacheOptions;
327
+ circuitBreaker?: CircuitBreakerOptions;
328
+ concurrency?: ConcurrencyOptions;
329
+ download?: DownloadOptions;
330
+ logger?: LoggerOptions;
331
+ retry?: number | RetryOptions;
332
+ upload?: UploadOptions;
333
+ }
334
+ interface RequestConfig {
335
+ url: string;
336
+ method?: HttpMethod;
337
+ baseURL?: string;
338
+ /**
339
+ * Allow an absolute request URL to bypass `baseURL`.
340
+ *
341
+ * Disable this when `baseURL` defines the trusted request boundary.
342
+ *
343
+ * @default true
344
+ */
345
+ allowAbsoluteUrls?: boolean;
346
+ fetchOptions?: FetchOptions;
347
+ headers?: HeadersInit;
348
+ query?: QueryParams;
349
+ searchParams?: URLSearchParams;
350
+ body?: BodyInit | Record<string, unknown> | null;
351
+ json?: Record<string, unknown> | unknown[];
352
+ form?: URLSearchParams | Record<string, QueryValue | QueryValue[]>;
353
+ formData?: FormData | Record<string, unknown>;
354
+ timeout?: number;
355
+ signal?: AbortSignal;
356
+ /**
357
+ * Maximum request body size in bytes when the serialized size can be
358
+ * determined before dispatch.
359
+ *
360
+ * FormData and ReadableStream bodies cannot be preflighted without
361
+ * buffering and are therefore not covered.
362
+ *
363
+ * @default unlimited
364
+ */
365
+ maxRequestSize?: number;
366
+ /**
367
+ * Maximum parsed response body size in bytes.
368
+ *
369
+ * @default unlimited
370
+ */
371
+ maxResponseSize?: number;
372
+ /**
373
+ * Maximum nested array depth accepted while building FormData.
374
+ *
375
+ * @default 32
376
+ */
377
+ maxFormDataDepth?: number;
378
+ responseType?: ResponseType;
379
+ /**
380
+ * Validate and optionally transform the parsed response value.
381
+ *
382
+ * Accepts any Standard Schema v1 compatible validator.
383
+ */
384
+ schema?: StandardSchemaV1;
385
+ validateStatus?: (status: number) => boolean;
386
+ extensions?: RequestExtensions;
387
+ }
388
+ //#endregion
389
+ //#region src/types/response.d.ts
390
+ /**
391
+ * A message decoded from a `text/event-stream` response.
392
+ */
393
+ interface ServerSentEvent {
394
+ /**
395
+ * Event payload with multiple `data` fields joined by newlines.
396
+ */
397
+ data: string;
398
+ /**
399
+ * Event type, defaulting to `message`.
400
+ */
401
+ event: string;
402
+ /**
403
+ * Most recently observed event identifier.
404
+ */
405
+ id: string;
406
+ /**
407
+ * Most recently observed server reconnection delay in milliseconds.
408
+ */
409
+ retry?: number;
410
+ }
411
+ /**
412
+ * Npora response.
413
+ */
414
+ interface NporaResponse<T = unknown> {
415
+ /**
416
+ * Parsed response data.
417
+ */
418
+ data: T;
419
+ /**
420
+ * HTTP status code.
421
+ */
422
+ status: number;
423
+ /**
424
+ * HTTP status text.
425
+ */
426
+ statusText: string;
427
+ /**
428
+ * Response headers.
429
+ */
430
+ headers: Headers;
431
+ /**
432
+ * Request config.
433
+ */
434
+ config: RequestConfig;
435
+ /**
436
+ * Raw Fetch Response.
437
+ */
438
+ raw: Response;
439
+ }
440
+ //#endregion
441
+ export { StandardSchemaV1 as A, ResponseLogEntry as C, UploadData as D, TransferProgress as E, UploadOptions as O, RequestLogger as S, RetryOptions as T, DownloadProgress as _, QueryValue as a, LoggerOptions as b, ResponseType as c, CircuitBreakerOptions as d, CircuitBreakerStateChange as f, DownloadOutput as g, DownloadOptions as h, QueryParams as i, HttpMethod as j, UploadProgress as k, AuthOptions as l, ConcurrencyOptions as m, ServerSentEvent as n, RequestConfig as o, CircuitState as p, FetchOptions as r, RequestExtensions as s, NporaResponse as t, CacheOptions as u, ErrorLogEntry as v, RetryEvent as w, RequestLogEntry as x, LoggerEntry as y };