@npora/request 1.14.3 → 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.
Files changed (106) hide show
  1. package/README.md +253 -4
  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 -1025
  40. package/dist/index.d.ts +15 -1025
  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 +66 -2
package/README.md CHANGED
@@ -31,6 +31,42 @@ authentication, and upload/download progress.
31
31
  verifies public exports, browser behavior, security regressions, and size
32
32
  budgets before release.
33
33
 
34
+ ## Where it stands out
35
+
36
+ Npora Request is aimed at applications that would otherwise assemble several
37
+ Axios interceptors, cache packages, queue utilities and stream parsers around
38
+ one HTTP client. The differentiation is the integrated lifecycle, not a claim
39
+ that one library is best for every transport.
40
+
41
+ | Area | Npora Request | Axios | Ky | Got |
42
+ | --- | --- | --- | --- | --- |
43
+ | Runtime dependencies | **0** | 4 | **0** | 12 |
44
+ | Standard Schema validation | **First-party** | Application code | First-party | Application code |
45
+ | Retry + circuit breaker + concurrency queue | **Composable plugins** | Retry/coordination added separately | Retry only | Retry; Node transport controls |
46
+ | Parsed SSE and NDJSON | **Incremental async iterables** | Raw response stream | Raw response stream | Raw response stream |
47
+ | Persistent response cache | **Web Storage, IndexedDB, tiered, cross-tab** | Application package | Application package | First-party cache |
48
+ | IndexedDB controls | **Schema, bytes, admission, metrics, compaction** | — | — | — |
49
+ | Node proxy/HTTP2/socket depth | Custom adapter | **Strong** | Fetch-dependent | **Strongest** |
50
+ | ESM and CommonJS exports | **Both** | Both | ESM | ESM |
51
+
52
+ Axios remains the safer choice when ecosystem adoption or mature Node adapter
53
+ compatibility dominates. Ky is excellent when a smaller Fetch convenience API
54
+ is enough. Got is the stronger Node-only transport specialist. Npora Request's
55
+ advantage is combining runtime validation, streaming, cache correctness,
56
+ resilience, observability and cancellation under one typed, deterministic,
57
+ zero-runtime-dependency lifecycle. See the dated, source-linked
58
+ [comparison](docs/comparison.md) for tradeoffs rather than marketing-only
59
+ claims.
60
+
61
+ The current stress gate completed **10,000,000 logical operations at concurrency
62
+ 256 with zero unexpected failures**, followed by **100,000 real localhost HTTP
63
+ requests at concurrency 256**. In a separate reproducible five-library
64
+ localhost JSON test, the pending release delivered **22,390 req/s median**,
65
+ within 1.2% of ofetch and ahead of Ky, Axios, and Got on that machine. These are
66
+ engineering checks, not claims about every remote workload; commands,
67
+ per-round results, and limitations are in the [benchmark
68
+ documentation](docs/benchmark.md).
69
+
34
70
  ## Features
35
71
 
36
72
  - Data-first and complete-response APIs with TypeScript inference.
@@ -232,6 +268,20 @@ api.ndjsonResponse(url, config)
232
268
 
233
269
  ## Plugins
234
270
 
271
+ Applications can keep using the backward-compatible root entry, or import
272
+ only the client and plugins they need:
273
+
274
+ ```ts
275
+ import { createClient } from '@npora/request/core'
276
+ import { retryPlugin } from '@npora/request/plugins/retry'
277
+
278
+ const request = createClient().use(retryPlugin({ retries: 2 }))
279
+ ```
280
+
281
+ `MockAdapter` is also available from `@npora/request/testing` and
282
+ `@npora/request/adapters/mock` so test-only utilities do not need to be
283
+ imported through the production entry point.
284
+
235
285
  ```ts
236
286
  import {
237
287
  authPlugin,
@@ -277,13 +327,211 @@ connect an external storage system:
277
327
  ```ts
278
328
  const cache = cachePlugin({
279
329
  store: sharedStore,
280
- dedupe: true
330
+ dedupe: true,
331
+ onEvent(event) {
332
+ metrics.increment(`cache.${event.type}`)
333
+ }
334
+ })
335
+ ```
336
+
337
+ Use `cache.getStats()` for a snapshot of hits, misses, bypasses,
338
+ invalidations, deduplication, revalidation, stale recovery, and background
339
+ refresh outcomes.
340
+ `cache.resetStats()` resets only these counters; it does not clear entries.
341
+ Events contain only a decision type and timestamp, never URLs, cache keys, or
342
+ headers. Observer failures do not affect requests.
343
+ Failed manual or automatic invalidations are counted in
344
+ `invalidationErrors` and emit `invalidation-error` without exposing the error.
345
+
346
+ Seed or optimistically update parsed cache data without a network request:
347
+
348
+ ```ts
349
+ await cache.set({ url: '/users/1' }, user, {
350
+ ttl: 30000,
351
+ tags: ['user:1']
352
+ })
353
+
354
+ await cache.update<User>({ url: '/users/1' }, current => ({
355
+ ...current,
356
+ name: 'Updated locally'
357
+ }))
358
+ ```
359
+
360
+ Return `undefined` from `update` to delete the entry. It returns `false` when
361
+ no entry exists. These operations use the same effective cache key as requests,
362
+ wait for overlapping asynchronous store operations, and prevent older
363
+ same-key responses from overwriting the new value.
364
+
365
+ Delete one entry without flushing unrelated cached responses:
366
+
367
+ ```ts
368
+ await cache.delete({
369
+ url: '/users/1',
370
+ baseURL: '/api',
371
+ extensions: {
372
+ cache: { enabled: true }
373
+ }
374
+ })
375
+ ```
376
+
377
+ Pass the effective request configuration used to create the entry, including
378
+ merged `baseURL`, query, response type, and representation headers. A custom
379
+ `extensions.cache.key` can be deleted without reproducing those dimensions.
380
+
381
+ Group related entries with bounded cache tags and invalidate them together:
382
+
383
+ ```ts
384
+ await request.get('/users/1', {
385
+ extensions: {
386
+ cache: {
387
+ enabled: true,
388
+ tags: ['user:1', 'users']
389
+ }
390
+ }
391
+ })
392
+
393
+ await cache.invalidateTags('user:1')
394
+ ```
395
+
396
+ The default memory store supports tags directly. Custom stores must implement
397
+ the optional `CacheStore.invalidateTags()` capability.
398
+
399
+ Persist JSON-compatible cached data across client instances with isolated
400
+ browser storage:
401
+
402
+ ```ts
403
+ import { WebStorageCacheStore } from '@npora/request/plugins/cache'
404
+
405
+ const cache = cachePlugin({
406
+ store: new WebStorageCacheStore(sessionStorage, {
407
+ namespace: 'dashboard-v1',
408
+ maxEntries: 250
409
+ })
410
+ })
411
+ ```
412
+
413
+ Use `localStorage` only when responses may safely survive browser restarts and
414
+ sign-out boundaries. The adapter never persists native `Response` objects;
415
+ `getResponse()` refetches when raw bytes are required.
416
+
417
+ For larger values and non-blocking storage, use IndexedDB instead:
418
+
419
+ ```ts
420
+ import { IndexedDBCacheStore } from '@npora/request/plugins/cache'
421
+
422
+ const store = new IndexedDBCacheStore(indexedDB, {
423
+ databaseName: 'dashboard-cache',
424
+ namespace: 'account:1',
425
+ schemaVersion: 2,
426
+ maxEntries: 500,
427
+ maxBytes: 20 * 1024 * 1024,
428
+ shouldPersist: (entry, bytes) => (
429
+ entry.status === 200 && bytes < 2 * 1024 * 1024
430
+ ),
431
+ onEvent: event => metrics.record('persistent-cache', event)
432
+ })
433
+ const cache = cachePlugin({ store })
434
+ ```
435
+
436
+ IndexedDB uses structured cloning, preserving values such as `Blob`, `Date`,
437
+ `Map`, typed arrays, and `BigInt` while still omitting native `Response` bodies.
438
+ Increment the positive integer `schemaVersion` whenever the cached data shape
439
+ becomes incompatible. Older records are isolated and pruned automatically;
440
+ the default version `1` continues to read records created before this option
441
+ existed. Older clients preserve every higher-version record without validating
442
+ its envelope, including during writes, clearing, compaction, and quota
443
+ recovery, so rolling deployments remain safe when the persisted structure
444
+ changes completely.
445
+ `maxBytes` adds an approximate structured-clone byte budget alongside
446
+ `maxEntries`. Oversized entries are skipped and older entries are evicted by
447
+ LRU. Quota-exceeded writes remove the oldest half of the current schema cache
448
+ and retry once by default; set `quotaRecovery: false` to report the first quota
449
+ failure without recovery.
450
+ Use `await store.getUsage()` to inspect the current schema's aggregate entry
451
+ count and estimated bytes. The optional `onEvent` observer reports aggregated
452
+ eviction, recovery, cleanup, and oversized-entry rejection events without
453
+ exposing keys, namespaces, URLs, or response data. Observer failures never
454
+ affect cache operations.
455
+ Use `shouldPersist(entry, estimatedBytes)` for application-specific admission,
456
+ such as excluding sensitive payloads, one-hit responses, or large low-value
457
+ objects. It may return a boolean or promise. Returning `false` removes an older
458
+ same-key value and emits an aggregate `admission-policy` rejection; thrown
459
+ errors are reported to the caller and leave the old value unchanged.
460
+ Run bounded maintenance without loading the namespace into memory:
461
+
462
+ ```ts
463
+ const result = await store.compact({
464
+ // Preserve seven days for stale-if-error recovery.
465
+ expiredBefore: Date.now() - 7 * 24 * 60 * 60 * 1000,
466
+ maxRemovals: 500
467
+ })
468
+ ```
469
+
470
+ `compact()` removes current-schema entries beyond the chosen stale boundary,
471
+ reports aggregate scan/removal/byte counts, and emits privacy-safe `expired`
472
+ events. Repeat while `hasMore` is true when using `maxRemovals`. Usage
473
+ inspection now streams records through an IndexedDB cursor, avoiding a
474
+ namespace-sized result array.
475
+
476
+ Combine memory speed with persistence through a read-through, write-through
477
+ store:
478
+
479
+ ```ts
480
+ const persistent = new IndexedDBCacheStore(indexedDB, {
481
+ namespace: 'account:1',
482
+ schemaVersion: 2
483
+ })
484
+ const channel = new BroadcastChannel('dashboard-cache:account:1:v1')
485
+ const store = new TieredCacheStore({
486
+ primary: new MemoryCacheStore({ maxEntries: 100 }),
487
+ secondary: persistent,
488
+ broadcast: { channel },
489
+ coordination: {
490
+ locks: navigator.locks,
491
+ namespace: 'dashboard-cache:account:1:v1'
492
+ }
493
+ })
494
+ const cache = cachePlugin({
495
+ store
281
496
  })
282
497
  ```
283
498
 
284
- The default memory store keeps up to 1,000 entries using LRU eviction and
285
- removes expired entries when read. Set `maxEntries` to tune the bound, use `0`
286
- to disable storage, or use `Infinity` for an explicitly unbounded store.
499
+ Hot reads remain synchronous. Cold secondary hits are promoted to memory, and
500
+ writes reach the persistent tier before becoming visible in memory. The
501
+ optional channel evicts stale primary entries in other tabs without sending
502
+ URLs, headers, response data, or complete cache keys. Call `store.dispose()`
503
+ and `channel.close()` when the context is torn down. Optional Web Locks
504
+ coordination serializes same-key refreshes across tabs; waiters reread the
505
+ shared secondary cache instead of issuing a duplicate request. Omit
506
+ `coordination` where `navigator.locks` is unavailable.
507
+ Mutation requests can invalidate tags automatically after their final success:
508
+
509
+ ```ts
510
+ await request.patch('/users/1', {
511
+ json: update,
512
+ extensions: {
513
+ cache: {
514
+ invalidateTags: ['user:1', 'users']
515
+ }
516
+ }
517
+ })
518
+ ```
519
+
520
+ Final HTTP, Schema, interceptor, cancellation, and exhausted-retry failures do
521
+ not invalidate entries.
522
+
523
+ The default memory store keeps up to 1,000 entries using LRU eviction. Expired
524
+ entries with `ETag` or `Last-Modified` validators are conditionally revalidated;
525
+ set `maxEntries` to tune the bound, use `0` to disable storage, or use `Infinity`
526
+ for an explicitly unbounded store.
527
+
528
+ Request `Cache-Control: no-cache` or `max-age=0` to force validation, and use
529
+ `Cache-Control: no-store` to bypass cache reads, writes, and request sharing.
530
+ Response `stale-if-error` can serve an expired entry after network, timeout, or
531
+ 5xx failure; `extensions.cache.staleIfError` sets an application limit in
532
+ milliseconds.
533
+ Response `stale-while-revalidate` can return stale data immediately while one
534
+ deduplicated refresh runs through the same client pipeline in the background.
287
535
 
288
536
  Built-in plugins:
289
537
 
@@ -409,6 +657,7 @@ Stable request error codes:
409
657
  - `ABORT_ERROR`
410
658
  - `PARSER_ERROR`
411
659
  - `SCHEMA_ERROR`
660
+ - `REQUEST_TOO_LARGE`
412
661
  - `RESPONSE_TOO_LARGE`
413
662
  - `CIRCUIT_OPEN`
414
663
  - `CONCURRENCY_LIMIT`
@@ -0,0 +1,71 @@
1
+ import { i as QueryParams, j as HttpMethod, o as RequestConfig, t as NporaResponse } from "./response-BhyS3PAL.cjs";
2
+ import { t as Adapter } from "./adapter-BeVVCcNG.cjs";
3
+ //#region src/adapters/MockAdapter.d.ts
4
+ type MockHandler<T = unknown> = (config: RequestConfig) => T | Promise<T>;
5
+ type MockURLMatcher = string | RegExp;
6
+ interface MockRequestMatcher {
7
+ url: MockURLMatcher;
8
+ query?: QueryParams;
9
+ searchParams?: URLSearchParams;
10
+ headers?: HeadersInit;
11
+ }
12
+ interface MockReply<T = unknown> {
13
+ status: number;
14
+ data?: T;
15
+ headers?: HeadersInit;
16
+ statusText?: string;
17
+ delay?: number;
18
+ }
19
+ type MockReplyHandler<T = unknown> = (config: RequestConfig) => MockReply<T> | Promise<MockReply<T>>;
20
+ interface MockResponseOptions {
21
+ headers?: HeadersInit;
22
+ statusText?: string;
23
+ delay?: number;
24
+ }
25
+ interface MockRoute {
26
+ reply<T = unknown>(handler: MockReplyHandler<T>): MockAdapter;
27
+ reply<T = unknown>(status: number, data?: T, options?: MockResponseOptions): MockAdapter;
28
+ replyOnce<T = unknown>(handler: MockReplyHandler<T>): MockAdapter;
29
+ replyOnce<T = unknown>(status: number, data?: T, options?: MockResponseOptions): MockAdapter;
30
+ networkError(message?: string): MockAdapter;
31
+ networkErrorOnce(message?: string): MockAdapter;
32
+ timeout(message?: string): MockAdapter;
33
+ timeoutOnce(message?: string): MockAdapter;
34
+ }
35
+ interface MockAdapterOptions {
36
+ handlers?: Record<string, MockHandler>;
37
+ /**
38
+ * Default delay for mock handlers and routes.
39
+ *
40
+ * @default 0
41
+ */
42
+ delay?: number;
43
+ }
44
+ declare class MockAdapter implements Adapter {
45
+ private readonly handlers;
46
+ private readonly rules;
47
+ private readonly requests;
48
+ private readonly delay;
49
+ constructor(options?: MockAdapterOptions);
50
+ get history(): readonly RequestConfig[];
51
+ /**
52
+ * Register a legacy URL-only data handler.
53
+ */
54
+ on<T = unknown>(url: string, handler: MockHandler<T>): this;
55
+ onMethod(method: HttpMethod, matcher: MockURLMatcher | MockRequestMatcher): MockRoute;
56
+ onGet(matcher: MockURLMatcher | MockRequestMatcher): MockRoute;
57
+ onPost(matcher: MockURLMatcher | MockRequestMatcher): MockRoute;
58
+ onPut(matcher: MockURLMatcher | MockRequestMatcher): MockRoute;
59
+ onPatch(matcher: MockURLMatcher | MockRequestMatcher): MockRoute;
60
+ onDelete(matcher: MockURLMatcher | MockRequestMatcher): MockRoute;
61
+ onHead(matcher: MockURLMatcher | MockRequestMatcher): MockRoute;
62
+ onOptions(matcher: MockURLMatcher | MockRequestMatcher): MockRoute;
63
+ resetHistory(): this;
64
+ resetHandlers(): this;
65
+ reset(): this;
66
+ request<T = unknown>(config: RequestConfig): Promise<NporaResponse<T>>;
67
+ private registerReply;
68
+ private registerError;
69
+ }
70
+ //#endregion
71
+ export { MockReplyHandler as a, MockRoute as c, MockReply as i, MockURLMatcher as l, MockAdapterOptions as n, MockRequestMatcher as o, MockHandler as r, MockResponseOptions as s, MockAdapter as t };
@@ -0,0 +1,71 @@
1
+ import { i as QueryParams, j as HttpMethod, o as RequestConfig, t as NporaResponse } from "./response-BhyS3PAL.js";
2
+ import { t as Adapter } from "./adapter-ODzpt_dM.js";
3
+ //#region src/adapters/MockAdapter.d.ts
4
+ type MockHandler<T = unknown> = (config: RequestConfig) => T | Promise<T>;
5
+ type MockURLMatcher = string | RegExp;
6
+ interface MockRequestMatcher {
7
+ url: MockURLMatcher;
8
+ query?: QueryParams;
9
+ searchParams?: URLSearchParams;
10
+ headers?: HeadersInit;
11
+ }
12
+ interface MockReply<T = unknown> {
13
+ status: number;
14
+ data?: T;
15
+ headers?: HeadersInit;
16
+ statusText?: string;
17
+ delay?: number;
18
+ }
19
+ type MockReplyHandler<T = unknown> = (config: RequestConfig) => MockReply<T> | Promise<MockReply<T>>;
20
+ interface MockResponseOptions {
21
+ headers?: HeadersInit;
22
+ statusText?: string;
23
+ delay?: number;
24
+ }
25
+ interface MockRoute {
26
+ reply<T = unknown>(handler: MockReplyHandler<T>): MockAdapter;
27
+ reply<T = unknown>(status: number, data?: T, options?: MockResponseOptions): MockAdapter;
28
+ replyOnce<T = unknown>(handler: MockReplyHandler<T>): MockAdapter;
29
+ replyOnce<T = unknown>(status: number, data?: T, options?: MockResponseOptions): MockAdapter;
30
+ networkError(message?: string): MockAdapter;
31
+ networkErrorOnce(message?: string): MockAdapter;
32
+ timeout(message?: string): MockAdapter;
33
+ timeoutOnce(message?: string): MockAdapter;
34
+ }
35
+ interface MockAdapterOptions {
36
+ handlers?: Record<string, MockHandler>;
37
+ /**
38
+ * Default delay for mock handlers and routes.
39
+ *
40
+ * @default 0
41
+ */
42
+ delay?: number;
43
+ }
44
+ declare class MockAdapter implements Adapter {
45
+ private readonly handlers;
46
+ private readonly rules;
47
+ private readonly requests;
48
+ private readonly delay;
49
+ constructor(options?: MockAdapterOptions);
50
+ get history(): readonly RequestConfig[];
51
+ /**
52
+ * Register a legacy URL-only data handler.
53
+ */
54
+ on<T = unknown>(url: string, handler: MockHandler<T>): this;
55
+ onMethod(method: HttpMethod, matcher: MockURLMatcher | MockRequestMatcher): MockRoute;
56
+ onGet(matcher: MockURLMatcher | MockRequestMatcher): MockRoute;
57
+ onPost(matcher: MockURLMatcher | MockRequestMatcher): MockRoute;
58
+ onPut(matcher: MockURLMatcher | MockRequestMatcher): MockRoute;
59
+ onPatch(matcher: MockURLMatcher | MockRequestMatcher): MockRoute;
60
+ onDelete(matcher: MockURLMatcher | MockRequestMatcher): MockRoute;
61
+ onHead(matcher: MockURLMatcher | MockRequestMatcher): MockRoute;
62
+ onOptions(matcher: MockURLMatcher | MockRequestMatcher): MockRoute;
63
+ resetHistory(): this;
64
+ resetHandlers(): this;
65
+ reset(): this;
66
+ request<T = unknown>(config: RequestConfig): Promise<NporaResponse<T>>;
67
+ private registerReply;
68
+ private registerError;
69
+ }
70
+ //#endregion
71
+ export { MockReplyHandler as a, MockRoute as c, MockReply as i, MockURLMatcher as l, MockAdapterOptions as n, MockRequestMatcher as o, MockHandler as r, MockResponseOptions as s, MockAdapter as t };
@@ -0,0 +1,124 @@
1
+ import { o as RequestConfig, t as NporaResponse } from "./response-BhyS3PAL.js";
2
+ //#region src/interceptors/InterceptorManager.d.ts
3
+ type Interceptor<T> = (value: T) => T | Promise<T>;
4
+ interface InterceptorOptions {
5
+ /**
6
+ * Higher priority interceptors run first.
7
+ *
8
+ * @default 0
9
+ */
10
+ priority?: number;
11
+ }
12
+ declare class InterceptorManager<T> {
13
+ private id;
14
+ private readonly interceptors;
15
+ private orderedInterceptors;
16
+ get active(): boolean;
17
+ use(interceptor: Interceptor<T>, options?: InterceptorOptions): number;
18
+ eject(id: number): void;
19
+ clear(): void;
20
+ run(value: T): Promise<T>;
21
+ private runMaybeAsync;
22
+ private refreshOrder;
23
+ }
24
+ //#endregion
25
+ //#region src/core/RequestContext.d.ts
26
+ declare class RequestContext<T = unknown> {
27
+ readonly preserveRaw: boolean;
28
+ /** @internal */
29
+ readonly background: boolean;
30
+ config: RequestConfig;
31
+ /** @internal Request input before interceptors and hooks mutate it. */
32
+ readonly initialConfig: RequestConfig;
33
+ response?: NporaResponse<T>;
34
+ /** @internal Candidate used only after retry handling declines another attempt. */
35
+ fallbackResponse?: NporaResponse<T>;
36
+ error?: unknown;
37
+ readonly startTime: number;
38
+ endTime?: number;
39
+ attempt: number;
40
+ constructor(config: RequestConfig, preserveRaw?: boolean,
41
+ /** @internal */
42
+ background?: boolean);
43
+ }
44
+ //#endregion
45
+ //#region src/interceptors/PluginHooks.d.ts
46
+ interface RetryDecision {
47
+ retry: boolean;
48
+ delay?: number;
49
+ }
50
+ interface HookOptions {
51
+ /**
52
+ * Higher priority hooks run first.
53
+ *
54
+ * @default 0
55
+ */
56
+ priority?: number;
57
+ /** @internal Response hooks may opt out when they never inspect raw. */
58
+ requiresRawResponse?: boolean;
59
+ }
60
+ type HookDisposer = () => void;
61
+ type RequestHook = (context: RequestContext<unknown>) => void | Promise<void>;
62
+ type RetryHook = (context: RequestContext<unknown>, attempt: number) => RetryDecision | undefined | Promise<RetryDecision | undefined>;
63
+ //#endregion
64
+ //#region src/plugins/Plugin.d.ts
65
+ interface PluginInterceptorManager<T> {
66
+ use(interceptor: Interceptor<T>, options?: InterceptorOptions): number;
67
+ eject(id: number): void;
68
+ }
69
+ interface PluginHookManager {
70
+ onRequest(hook: RequestHook, options?: HookOptions): HookDisposer;
71
+ /**
72
+ * Provide an alternative transport for the current attempt.
73
+ *
74
+ * Transport hooks run inside the retry loop. A hook that handles the
75
+ * request assigns `context.response`; later transport hooks and the client
76
+ * adapter are then skipped for that attempt.
77
+ */
78
+ onTransport(hook: RequestHook, options?: HookOptions): HookDisposer;
79
+ onResponse(hook: RequestHook, options?: HookOptions): HookDisposer;
80
+ onError(hook: RequestHook, options?: HookOptions): HookDisposer;
81
+ /**
82
+ * Observe the final request outcome after retries and interceptors finish.
83
+ *
84
+ * Settled hook failures are isolated from the request result.
85
+ */
86
+ onSettled(hook: RequestHook, options?: HookOptions): HookDisposer;
87
+ onRetry(hook: RetryHook, options?: HookOptions): HookDisposer;
88
+ }
89
+ interface PluginContext {
90
+ interceptors: {
91
+ request: PluginInterceptorManager<RequestConfig>;
92
+ response: PluginInterceptorManager<NporaResponse>;
93
+ error: PluginInterceptorManager<unknown>;
94
+ };
95
+ hooks: PluginHookManager;
96
+ /** @internal Dispatch a request through the owning client pipeline. */
97
+ dispatch<T = unknown>(config: RequestConfig, options?: PluginDispatchOptions): Promise<NporaResponse<T>>;
98
+ }
99
+ interface PluginDispatchOptions {
100
+ background?: boolean;
101
+ preserveRaw?: boolean;
102
+ }
103
+ type PluginCleanup = () => void;
104
+ interface Plugin {
105
+ name: string;
106
+ /**
107
+ * Default priority for interceptors and hooks registered by this plugin.
108
+ * Higher priority registrations run first.
109
+ *
110
+ * @default 0
111
+ */
112
+ priority?: number;
113
+ /**
114
+ * Plugins that must already be installed.
115
+ */
116
+ requires?: readonly string[];
117
+ /**
118
+ * Plugins that cannot be installed on the same client.
119
+ */
120
+ conflicts?: readonly string[];
121
+ install: (context: PluginContext) => void | PluginCleanup;
122
+ }
123
+ //#endregion
124
+ export { PluginInterceptorManager as a, InterceptorOptions as c, PluginHookManager as i, PluginCleanup as n, Interceptor as o, PluginContext as r, InterceptorManager as s, Plugin as t };
@@ -0,0 +1,124 @@
1
+ import { o as RequestConfig, t as NporaResponse } from "./response-BhyS3PAL.cjs";
2
+ //#region src/interceptors/InterceptorManager.d.ts
3
+ type Interceptor<T> = (value: T) => T | Promise<T>;
4
+ interface InterceptorOptions {
5
+ /**
6
+ * Higher priority interceptors run first.
7
+ *
8
+ * @default 0
9
+ */
10
+ priority?: number;
11
+ }
12
+ declare class InterceptorManager<T> {
13
+ private id;
14
+ private readonly interceptors;
15
+ private orderedInterceptors;
16
+ get active(): boolean;
17
+ use(interceptor: Interceptor<T>, options?: InterceptorOptions): number;
18
+ eject(id: number): void;
19
+ clear(): void;
20
+ run(value: T): Promise<T>;
21
+ private runMaybeAsync;
22
+ private refreshOrder;
23
+ }
24
+ //#endregion
25
+ //#region src/core/RequestContext.d.ts
26
+ declare class RequestContext<T = unknown> {
27
+ readonly preserveRaw: boolean;
28
+ /** @internal */
29
+ readonly background: boolean;
30
+ config: RequestConfig;
31
+ /** @internal Request input before interceptors and hooks mutate it. */
32
+ readonly initialConfig: RequestConfig;
33
+ response?: NporaResponse<T>;
34
+ /** @internal Candidate used only after retry handling declines another attempt. */
35
+ fallbackResponse?: NporaResponse<T>;
36
+ error?: unknown;
37
+ readonly startTime: number;
38
+ endTime?: number;
39
+ attempt: number;
40
+ constructor(config: RequestConfig, preserveRaw?: boolean,
41
+ /** @internal */
42
+ background?: boolean);
43
+ }
44
+ //#endregion
45
+ //#region src/interceptors/PluginHooks.d.ts
46
+ interface RetryDecision {
47
+ retry: boolean;
48
+ delay?: number;
49
+ }
50
+ interface HookOptions {
51
+ /**
52
+ * Higher priority hooks run first.
53
+ *
54
+ * @default 0
55
+ */
56
+ priority?: number;
57
+ /** @internal Response hooks may opt out when they never inspect raw. */
58
+ requiresRawResponse?: boolean;
59
+ }
60
+ type HookDisposer = () => void;
61
+ type RequestHook = (context: RequestContext<unknown>) => void | Promise<void>;
62
+ type RetryHook = (context: RequestContext<unknown>, attempt: number) => RetryDecision | undefined | Promise<RetryDecision | undefined>;
63
+ //#endregion
64
+ //#region src/plugins/Plugin.d.ts
65
+ interface PluginInterceptorManager<T> {
66
+ use(interceptor: Interceptor<T>, options?: InterceptorOptions): number;
67
+ eject(id: number): void;
68
+ }
69
+ interface PluginHookManager {
70
+ onRequest(hook: RequestHook, options?: HookOptions): HookDisposer;
71
+ /**
72
+ * Provide an alternative transport for the current attempt.
73
+ *
74
+ * Transport hooks run inside the retry loop. A hook that handles the
75
+ * request assigns `context.response`; later transport hooks and the client
76
+ * adapter are then skipped for that attempt.
77
+ */
78
+ onTransport(hook: RequestHook, options?: HookOptions): HookDisposer;
79
+ onResponse(hook: RequestHook, options?: HookOptions): HookDisposer;
80
+ onError(hook: RequestHook, options?: HookOptions): HookDisposer;
81
+ /**
82
+ * Observe the final request outcome after retries and interceptors finish.
83
+ *
84
+ * Settled hook failures are isolated from the request result.
85
+ */
86
+ onSettled(hook: RequestHook, options?: HookOptions): HookDisposer;
87
+ onRetry(hook: RetryHook, options?: HookOptions): HookDisposer;
88
+ }
89
+ interface PluginContext {
90
+ interceptors: {
91
+ request: PluginInterceptorManager<RequestConfig>;
92
+ response: PluginInterceptorManager<NporaResponse>;
93
+ error: PluginInterceptorManager<unknown>;
94
+ };
95
+ hooks: PluginHookManager;
96
+ /** @internal Dispatch a request through the owning client pipeline. */
97
+ dispatch<T = unknown>(config: RequestConfig, options?: PluginDispatchOptions): Promise<NporaResponse<T>>;
98
+ }
99
+ interface PluginDispatchOptions {
100
+ background?: boolean;
101
+ preserveRaw?: boolean;
102
+ }
103
+ type PluginCleanup = () => void;
104
+ interface Plugin {
105
+ name: string;
106
+ /**
107
+ * Default priority for interceptors and hooks registered by this plugin.
108
+ * Higher priority registrations run first.
109
+ *
110
+ * @default 0
111
+ */
112
+ priority?: number;
113
+ /**
114
+ * Plugins that must already be installed.
115
+ */
116
+ requires?: readonly string[];
117
+ /**
118
+ * Plugins that cannot be installed on the same client.
119
+ */
120
+ conflicts?: readonly string[];
121
+ install: (context: PluginContext) => void | PluginCleanup;
122
+ }
123
+ //#endregion
124
+ export { PluginInterceptorManager as a, InterceptorOptions as c, PluginHookManager as i, PluginCleanup as n, Interceptor as o, PluginContext as r, InterceptorManager as s, Plugin as t };
@@ -0,0 +1 @@
1
+ var PluginError=class extends Error{constructor(e,t){super(e),this.name=`PluginError`,this.code=t.code,this.plugin=t.plugin,this.relatedPlugin=t.relatedPlugin,Object.setPrototypeOf(this,new.target.prototype)}};export{PluginError as t};
@@ -0,0 +1 @@
1
+ var PluginError=class extends Error{constructor(e,t){super(e),this.name=`PluginError`,this.code=t.code,this.plugin=t.plugin,this.relatedPlugin=t.relatedPlugin,Object.setPrototypeOf(this,new.target.prototype)}};Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return PluginError}});