@npora/request 1.15.0 → 1.17.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 (122) hide show
  1. package/README.md +98 -36
  2. package/dist/{MockAdapter-H50LoFDu.d.ts → MockAdapter-BJ1a0ckc.d.ts} +2 -2
  3. package/dist/{MockAdapter-ChWzzSnH.d.cts → MockAdapter-CoHuXELk.d.cts} +2 -2
  4. package/dist/{Plugin-0Eh51_et.d.ts → Plugin-C6byiMAq.d.ts} +1 -1
  5. package/dist/{Plugin-YysllE6z.d.cts → Plugin-Cc_vfQSv.d.cts} +1 -1
  6. package/dist/RequestError-DMeCUJEa.cjs +1 -0
  7. package/dist/RequestError-qSMaUdmT.js +1 -0
  8. package/dist/SchemaValidationError-BTu7iCMY.d.cts +199 -0
  9. package/dist/SchemaValidationError-Bv77oija.d.ts +199 -0
  10. package/dist/{adapter-ODzpt_dM.d.ts → adapter-D6XE_YxP.d.ts} +1 -1
  11. package/dist/{adapter-BeVVCcNG.d.cts → adapter-DsqwOhaw.d.cts} +1 -1
  12. package/dist/{authPlugin-6E6_0dAO.d.ts → authPlugin-BagwFLqA.d.ts} +1 -1
  13. package/dist/{authPlugin-B_YpkyC8.d.cts → authPlugin-DqPbX2FY.d.cts} +1 -1
  14. package/dist/{cachePlugin-B9Hvsprg.d.cts → cachePlugin-BrJ6G6-V.d.cts} +2 -2
  15. package/dist/{cachePlugin-CvH26DBo.d.ts → cachePlugin-DInA4f25.d.ts} +2 -2
  16. package/dist/cachePlugin-DKViYySn.js +1 -0
  17. package/dist/cachePlugin-DzX2PikP.cjs +1 -0
  18. package/dist/{circuitBreakerPlugin-B45xghq9.d.cts → circuitBreakerPlugin-BXbAz8uE.d.cts} +2 -2
  19. package/dist/{circuitBreakerPlugin-DsH6YCNe.d.ts → circuitBreakerPlugin-CBuqvrMR.d.ts} +2 -2
  20. package/dist/{concurrencyPlugin-dwGNFYrM.d.ts → concurrencyPlugin-BcVI7cXt.d.ts} +2 -2
  21. package/dist/{concurrencyPlugin-CuJMua41.d.cts → concurrencyPlugin-DWmX3eYZ.d.cts} +2 -2
  22. package/dist/core.cjs +1 -1
  23. package/dist/core.d.cts +5 -5
  24. package/dist/core.d.ts +5 -5
  25. package/dist/core.js +1 -1
  26. package/dist/createAbortError-D8g0TXI5.js +1 -0
  27. package/dist/createAbortError-DGGLLZ8m.cjs +1 -0
  28. package/dist/createClient-C-gW6ddA.js +1 -0
  29. package/dist/createClient-CTWY1gHx.cjs +1 -0
  30. package/dist/{downloadPlugin-s8VS8t9r.d.ts → downloadPlugin-BQYXXzPU.d.ts} +1 -1
  31. package/dist/{downloadPlugin-CEXXJiDo.d.cts → downloadPlugin-CT8aRRZD.d.cts} +1 -1
  32. package/dist/errorResponseTimeout-BxdKy8Ii.js +1 -0
  33. package/dist/errorResponseTimeout-Cacuf_nD.cjs +1 -0
  34. package/dist/index.cjs +1 -1
  35. package/dist/index.d.cts +14 -14
  36. package/dist/index.d.ts +14 -14
  37. package/dist/index.js +1 -1
  38. package/dist/isBinaryBody-B0414zDU.cjs +1 -0
  39. package/dist/isBinaryBody-i4r46MoJ.js +1 -0
  40. package/dist/isReadableStream-0eF9O4Xl.cjs +1 -0
  41. package/dist/isReadableStream-O-PmslRY.js +1 -0
  42. package/dist/loggerPlugin-ByqINwKV.d.cts +6 -0
  43. package/dist/loggerPlugin-CBJgHRVR.d.ts +6 -0
  44. package/dist/plugins/auth.cjs +1 -1
  45. package/dist/plugins/auth.d.cts +1 -1
  46. package/dist/plugins/auth.d.ts +1 -1
  47. package/dist/plugins/auth.js +1 -1
  48. package/dist/plugins/cache.cjs +1 -1
  49. package/dist/plugins/cache.d.cts +1 -1
  50. package/dist/plugins/cache.d.ts +1 -1
  51. package/dist/plugins/cache.js +1 -1
  52. package/dist/plugins/circuit-breaker.cjs +1 -1
  53. package/dist/plugins/circuit-breaker.d.cts +1 -1
  54. package/dist/plugins/circuit-breaker.d.ts +1 -1
  55. package/dist/plugins/circuit-breaker.js +1 -1
  56. package/dist/plugins/concurrency.cjs +1 -1
  57. package/dist/plugins/concurrency.d.cts +1 -1
  58. package/dist/plugins/concurrency.d.ts +1 -1
  59. package/dist/plugins/concurrency.js +1 -1
  60. package/dist/plugins/download.cjs +1 -1
  61. package/dist/plugins/download.d.cts +1 -1
  62. package/dist/plugins/download.d.ts +1 -1
  63. package/dist/plugins/download.js +1 -1
  64. package/dist/plugins/logger.cjs +1 -1
  65. package/dist/plugins/logger.d.cts +1 -1
  66. package/dist/plugins/logger.d.ts +1 -1
  67. package/dist/plugins/logger.js +1 -1
  68. package/dist/plugins/retry.cjs +1 -1
  69. package/dist/plugins/retry.d.cts +1 -1
  70. package/dist/plugins/retry.d.ts +1 -1
  71. package/dist/plugins/retry.js +1 -1
  72. package/dist/plugins/upload.cjs +1 -1
  73. package/dist/plugins/upload.d.cts +1 -1
  74. package/dist/plugins/upload.d.ts +1 -1
  75. package/dist/plugins/upload.js +1 -1
  76. package/dist/plugins.cjs +1 -1
  77. package/dist/plugins.d.cts +9 -9
  78. package/dist/plugins.d.ts +9 -9
  79. package/dist/plugins.js +1 -1
  80. package/dist/resolveRequestOrigin-DzOB9oX9.cjs +1 -0
  81. package/dist/resolveRequestOrigin-jeuuD5SV.js +1 -0
  82. package/dist/{response-BhyS3PAL.d.cts → response-_OBxvs9O.d.cts} +87 -13
  83. package/dist/{response-BhyS3PAL.d.ts → response-_OBxvs9O.d.ts} +87 -13
  84. package/dist/retryPlugin-DPSIzQb2.d.cts +6 -0
  85. package/dist/retryPlugin-rz4-rw7Z.d.ts +6 -0
  86. package/dist/testing.cjs +1 -1
  87. package/dist/testing.d.cts +1 -1
  88. package/dist/testing.d.ts +1 -1
  89. package/dist/testing.js +1 -1
  90. package/dist/{uploadPlugin-Bb7EawRX.d.ts → uploadPlugin-BCWMMqzq.d.ts} +1 -1
  91. package/dist/{uploadPlugin-AfhFIsO7.d.cts → uploadPlugin-bdvue2IF.d.cts} +1 -1
  92. package/dist/validateResponseStatus-BpRZ-mwf.js +4 -0
  93. package/dist/validateResponseStatus-DPDVX0xy.cjs +4 -0
  94. package/dist/{waitForSignal-yR1BeU8f.cjs → waitForSignal-CwkTAWBO.cjs} +1 -1
  95. package/dist/{waitForSignal-DyyPvJd5.js → waitForSignal-D92W9SUV.js} +1 -1
  96. package/dist/xhrTransport-D6KlD1Xc.cjs +1 -0
  97. package/dist/xhrTransport-duU5wdMj.js +1 -0
  98. package/package.json +1 -1
  99. package/dist/RequestError-BH6V64XR.js +0 -1
  100. package/dist/RequestError-DPSv-HVF.cjs +0 -1
  101. package/dist/SchemaValidationError-CjvWT8YA.d.ts +0 -166
  102. package/dist/SchemaValidationError-WMTfqSBV.d.cts +0 -166
  103. package/dist/buildRequest-BRZwRLoN.cjs +0 -1
  104. package/dist/buildRequest-Cwt8XEWO.js +0 -1
  105. package/dist/cachePlugin-CSHwJYwI.js +0 -1
  106. package/dist/cachePlugin-ZPYdHbsM.cjs +0 -1
  107. package/dist/createAbortError-D4rRBq2B.js +0 -1
  108. package/dist/createAbortError-DJqbdYgk.cjs +0 -1
  109. package/dist/createClient-CibOTVAy.cjs +0 -1
  110. package/dist/createClient-I13D6XsD.js +0 -1
  111. package/dist/isURLSearchParams-B93cMCGj.js +0 -1
  112. package/dist/isURLSearchParams-o-c8Q42t.cjs +0 -1
  113. package/dist/loggerPlugin-C15EW7Sc.d.ts +0 -6
  114. package/dist/loggerPlugin-uOFiUtBi.d.cts +0 -6
  115. package/dist/resolveRequestOrigin-BndIJeZ7.js +0 -1
  116. package/dist/resolveRequestOrigin-CRATeWff.cjs +0 -1
  117. package/dist/retryPlugin-2mYKvWy3.d.ts +0 -6
  118. package/dist/retryPlugin-BqlUpmd0.d.cts +0 -6
  119. package/dist/validateResponseStatus-Dqzr342t.js +0 -4
  120. package/dist/validateResponseStatus-QAjcah2i.cjs +0 -4
  121. package/dist/xhrTransport-C0pg00i5.js +0 -1
  122. package/dist/xhrTransport-CeW2DDzo.cjs +0 -1
package/README.md CHANGED
@@ -27,57 +27,54 @@ authentication, and upload/download progress.
27
27
  composable plugins over the standard Fetch API.
28
28
  - **Use one predictable contract everywhere.** Browsers, Web Workers, Node.js,
29
29
  ESM, and CommonJS share the same typed lifecycle and stable error codes.
30
+ - **Keep native platform values native.** `URL`, `Request`, `Headers`,
31
+ `FormData`, `Blob`, `ArrayBuffer`, and `ReadableStream` retain their Fetch
32
+ semantics, including supported cross-realm inputs.
33
+ - **Bound untrusted traffic.** Separate request, successful response, and error
34
+ response limits prevent accidental buffering while preserving meaningful
35
+ error codes and cancellation.
30
36
  - **Ship less supply-chain risk.** The package has no runtime dependencies and
31
37
  verifies public exports, browser behavior, security regressions, and size
32
38
  budgets before release.
33
39
 
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.
40
+ ## Design focus
41
+
42
+ Npora Request combines runtime validation, incremental streaming, persistent
43
+ cache correctness, resilience, observability, and cancellation under one
44
+ typed, deterministic lifecycle. It keeps the standard Fetch model, ships with
45
+ zero runtime dependencies, supports ESM and CommonJS, and exposes optional
46
+ capabilities through tree-shakeable subpath exports.
60
47
 
61
48
  The current stress gate completed **10,000,000 logical operations at concurrency
62
49
  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).
50
+ requests at concurrency 256**. These are reproducible engineering checks, not
51
+ claims about every remote workload; commands and limitations are in the
52
+ [benchmark documentation](docs/benchmark.md).
69
53
 
70
54
  ## Features
71
55
 
72
56
  - Data-first and complete-response APIs with TypeScript inference.
57
+ - Native `URL` and `Request` inputs with explicit per-call overrides and stable
58
+ lifecycle snapshots.
59
+ - First-class RFC 10008 `QUERY` helpers with JSON bodies and safe retries for
60
+ replayable content.
61
+ - Query- and fragment-safe `baseURL` prefix composition.
73
62
  - Object query merging plus native ordered `URLSearchParams` through
74
63
  `searchParams`.
64
+ - Native multipart and URL-encoded response parsing through `formData`.
65
+ - Raw binary response parsing as a portable `Uint8Array` through `bytes`.
66
+ - Response-type-driven `Accept` negotiation with custom-header precedence.
67
+ - Standards-correct opaque and manual-redirect Fetch responses without false
68
+ HTTP or parser failures.
69
+ - Optional non-throwing HTTP status handling with parsed response data and
70
+ complete metadata.
75
71
  - Standard Schema v1 validation and transformation for untrusted responses.
76
72
  - Incremental SSE and NDJSON async iterables with cancellation and size limits.
77
73
  - Progress-aware file download streams that preserve backpressure and avoid
78
74
  buffering the complete response in memory.
79
75
  - Unified errors across Fetch, XHR, parsing, validation, timeouts, and aborts.
80
76
  - Request/response/error interceptors with deterministic priority ordering.
77
+ - Shallow-merged local request context for tracing and lifecycle policies.
81
78
  - Official retry, cache, circuit-breaker, concurrency, authentication, logger,
82
79
  upload, and download plugins.
83
80
  - Method-aware `MockAdapter` routing, matching, delays, failures, and history.
@@ -142,6 +139,44 @@ console.log(response.headers)
142
139
  console.log(response.raw)
143
140
  ```
144
141
 
142
+ ## Native Fetch inputs
143
+
144
+ Use a native `Request` directly when another platform layer already owns the
145
+ request construction. Client defaults and explicit overrides still participate
146
+ in the normal lifecycle, while an unchanged body is not cloned or buffered:
147
+
148
+ ```ts
149
+ const input = new Request('https://api.example.com/users/1', {
150
+ headers: {
151
+ authorization: `Bearer ${accessToken}`
152
+ }
153
+ })
154
+
155
+ const user = await api.request<User>(input, {
156
+ timeout: 3000
157
+ })
158
+ ```
159
+
160
+ Native `URL`, `Headers`, body values, cancellation signals, and Fetch options
161
+ remain available throughout interceptors, plugins, responses, and errors.
162
+
163
+ ## Content-bearing queries
164
+
165
+ Use the standardized `QUERY` method for safe, idempotent queries whose input
166
+ belongs in a typed request body instead of a long URL:
167
+
168
+ ```ts
169
+ const users = await api.query<User[]>('/users/search', {
170
+ json: {
171
+ status: 'active',
172
+ teams: ['platform', 'web']
173
+ }
174
+ })
175
+ ```
176
+
177
+ JSON supplies the required media type automatically. Replayable QUERY bodies
178
+ participate in safe retries when the retry plugin is installed.
179
+
145
180
  ## Response validation
146
181
 
147
182
  Validate untrusted response data with any Standard Schema v1 compatible
@@ -196,6 +231,26 @@ the loop cancels the response reader. `maxResponseSize` remains enforced while
196
231
  the stream is consumed. A response schema validates the parsed response value
197
232
  once; it does not validate individual SSE events or NDJSON records.
198
233
 
234
+ Native `FormData`, `Blob`, `ArrayBuffer`, and `ReadableStream` request bodies
235
+ also work when created by another same-origin window or iframe. Detection does
236
+ not lock streams, and retry safety and request-size limits remain active.
237
+ With Fetch, `maxRequestSize` counts stream chunks without buffering and
238
+ cancels the source once the limit is exceeded.
239
+
240
+ Buffered bodies attached to thrown HTTP errors are capped at 10 MiB by
241
+ default. Override `maxErrorResponseSize`, or set it to `Infinity` for trusted
242
+ services that require complete error payloads. This guard preserves
243
+ `HTTP_ERROR`; a stricter `maxResponseSize` remains a hard
244
+ `RESPONSE_TOO_LARGE` limit.
245
+
246
+ Error-body reads and asynchronous JSON parsing are also bounded by `timeout`,
247
+ or by a 10-second error-only fallback when timeout is disabled. The fallback
248
+ keeps `HTTP_ERROR` and omits stalled data; explicit and total timeouts retain
249
+ `TIMEOUT_ERROR`. Malformed or rejected error payloads likewise keep
250
+ `HTTP_ERROR` with unavailable data, so parser failures cannot hide the server
251
+ status. Successful and explicitly non-throwing responses retain strict parser
252
+ errors. Fetch consumes error bodies once; use `error.data` for their payload.
253
+
199
254
  ## Request configuration
200
255
 
201
256
  ```ts
@@ -218,6 +273,7 @@ Query objects merge with client defaults. Native `searchParams` replace
218
273
  inherited query defaults while preserving repeated keys and order.
219
274
 
220
275
  The body options `body`, `json`, `form`, and `formData` are mutually exclusive.
276
+ `json` accepts complete JSON root values, including primitives and `null`.
221
277
  `GET` and `HEAD` requests cannot contain a body. Invalid configuration throws a
222
278
  `RequestError` before the adapter sends a request.
223
279
 
@@ -244,11 +300,14 @@ isolated to each client.
244
300
  ```ts
245
301
  api.request(config)
246
302
  api.requestResponse(config)
303
+ api.request(nativeRequest, config)
304
+ api.requestResponse(nativeRequest, config)
247
305
 
248
306
  api.get(url, config)
249
307
  api.post(url, config)
250
308
  api.put(url, config)
251
309
  api.patch(url, config)
310
+ api.query(url, config)
252
311
  api.delete(url, config)
253
312
  api.head(url, config)
254
313
  api.options(url, config)
@@ -259,6 +318,7 @@ api.getResponse(url, config)
259
318
  api.postResponse(url, config)
260
319
  api.putResponse(url, config)
261
320
  api.patchResponse(url, config)
321
+ api.queryResponse(url, config)
262
322
  api.deleteResponse(url, config)
263
323
  api.headResponse(url, config)
264
324
  api.optionsResponse(url, config)
@@ -635,12 +695,12 @@ const api = createClient({ adapter })
635
695
  ## Errors
636
696
 
637
697
  ```ts
638
- import { RequestError } from '@npora/request'
698
+ import { isRequestError } from '@npora/request'
639
699
 
640
700
  try {
641
701
  await api.get('/users/missing')
642
702
  } catch (error) {
643
- if (error instanceof RequestError) {
703
+ if (isRequestError(error)) {
644
704
  console.error(error.code)
645
705
  console.error(error.status)
646
706
  console.error(error.data)
@@ -666,6 +726,10 @@ Stable request error codes:
666
726
  request failures through the unified base class while still inspecting schema
667
727
  issues when `error.code === 'SCHEMA_ERROR'`.
668
728
 
729
+ Prefer `isRequestError()` and `isSchemaValidationError()` when narrowing an
730
+ unknown caught value. Their non-enumerable shared brands work across iframes
731
+ and duplicated package instances, where `instanceof` can fail.
732
+
669
733
  ## Supply-chain verification
670
734
 
671
735
  The published package contains only the built `dist` artifacts, has no runtime
@@ -680,8 +744,6 @@ allowlist, and size budgets.
680
744
  - [API reference](https://github.com/npora/request/blob/main/docs/api.md)
681
745
  - [Architecture](https://github.com/npora/request/blob/main/docs/architecture.md)
682
746
  - [Migration from 0.x](https://github.com/npora/request/blob/main/docs/migration.md)
683
- - [Migration from Axios or Ky](https://github.com/npora/request/blob/main/docs/migration-from-axios-and-ky.md)
684
- - [HTTP client comparison](https://github.com/npora/request/blob/main/docs/comparison.md)
685
747
  - [Security model](https://github.com/npora/request/blob/main/docs/security.md)
686
748
  - [Testing and release gates](https://github.com/npora/request/blob/main/docs/testing.md)
687
749
  - [Performance benchmarks](https://github.com/npora/request/blob/main/docs/benchmark.md)
@@ -1,5 +1,5 @@
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";
1
+ import { R as HttpMethod, c as QueryParams, d as RequestConfig, t as NporaResponse } from "./response-_OBxvs9O.js";
2
+ import { t as Adapter } from "./adapter-D6XE_YxP.js";
3
3
  //#region src/adapters/MockAdapter.d.ts
4
4
  type MockHandler<T = unknown> = (config: RequestConfig) => T | Promise<T>;
5
5
  type MockURLMatcher = string | RegExp;
@@ -1,5 +1,5 @@
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";
1
+ import { R as HttpMethod, c as QueryParams, d as RequestConfig, t as NporaResponse } from "./response-_OBxvs9O.cjs";
2
+ import { t as Adapter } from "./adapter-DsqwOhaw.cjs";
3
3
  //#region src/adapters/MockAdapter.d.ts
4
4
  type MockHandler<T = unknown> = (config: RequestConfig) => T | Promise<T>;
5
5
  type MockURLMatcher = string | RegExp;
@@ -1,4 +1,4 @@
1
- import { o as RequestConfig, t as NporaResponse } from "./response-BhyS3PAL.js";
1
+ import { d as RequestConfig, t as NporaResponse } from "./response-_OBxvs9O.js";
2
2
  //#region src/interceptors/InterceptorManager.d.ts
3
3
  type Interceptor<T> = (value: T) => T | Promise<T>;
4
4
  interface InterceptorOptions {
@@ -1,4 +1,4 @@
1
- import { o as RequestConfig, t as NporaResponse } from "./response-BhyS3PAL.cjs";
1
+ import { d as RequestConfig, t as NporaResponse } from "./response-_OBxvs9O.cjs";
2
2
  //#region src/interceptors/InterceptorManager.d.ts
3
3
  type Interceptor<T> = (value: T) => T | Promise<T>;
4
4
  interface InterceptorOptions {
@@ -0,0 +1 @@
1
+ const e=Symbol.for(`@npora/request/RequestError`);var RequestError=class extends Error{constructor(t,n){super(t),Object.defineProperty(this,e,{value:!0}),this.name=`RequestError`,this.code=n.code,this.status=n.status??n.response?.status,this.data=n.data??n.response?.data,this.response=n.response,this.config=n.config??n.response?.config,this.cause=n.cause}toJSON(){return{name:this.name,message:this.message,code:this.code,status:this.status}}};function isRequestError(t){if(typeof t!=`object`&&typeof t!=`function`||t===null)return!1;try{return Reflect.get(t,e)===!0}catch{return!1}}Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return isRequestError}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return RequestError}});
@@ -0,0 +1 @@
1
+ const e=Symbol.for(`@npora/request/RequestError`);var RequestError=class extends Error{constructor(t,n){super(t),Object.defineProperty(this,e,{value:!0}),this.name=`RequestError`,this.code=n.code,this.status=n.status??n.response?.status,this.data=n.data??n.response?.data,this.response=n.response,this.config=n.config??n.response?.config,this.cause=n.cause}toJSON(){return{name:this.name,message:this.message,code:this.code,status:this.status}}};function isRequestError(t){if(typeof t!=`object`&&typeof t!=`function`||t===null)return!1;try{return Reflect.get(t,e)===!0}catch{return!1}}export{isRequestError as n,RequestError as t};
@@ -0,0 +1,199 @@
1
+ import { L as StandardSchemaV1, d as RequestConfig, m as RequestURL, n as ServerSentEvent, p as RequestInputConfig, t as NporaResponse } from "./response-_OBxvs9O.cjs";
2
+ import { t as Adapter } from "./adapter-DsqwOhaw.cjs";
3
+ import { s as InterceptorManager, t as Plugin } from "./Plugin-Cc_vfQSv.cjs";
4
+ //#region src/types/client.d.ts
5
+ /**
6
+ * Client creation options.
7
+ */
8
+ interface ClientOptions extends Partial<Omit<RequestConfig, 'url' | 'method' | 'schema'>> {
9
+ /**
10
+ * Request adapter.
11
+ *
12
+ * @default FetchAdapter
13
+ */
14
+ adapter?: Adapter;
15
+ }
16
+ //#endregion
17
+ //#region src/client/Client.d.ts
18
+ type MethodConfig = Omit<RequestConfig, 'url' | 'method'>;
19
+ type SchemaMethodConfig<Schema extends StandardSchemaV1> = Omit<MethodConfig, 'schema'> & {
20
+ schema: Schema;
21
+ };
22
+ declare class Client {
23
+ private readonly defaults;
24
+ private readonly adapter;
25
+ private readonly installedPlugins;
26
+ private readonly hooks;
27
+ readonly interceptors: {
28
+ request: InterceptorManager<RequestConfig>;
29
+ response: InterceptorManager<NporaResponse<unknown>>;
30
+ error: InterceptorManager<unknown>;
31
+ };
32
+ private readonly pipeline;
33
+ constructor(options?: ClientOptions);
34
+ /**
35
+ * Create an isolated client that inherits this client's defaults.
36
+ */
37
+ extend(options?: ClientOptions): Client;
38
+ use(plugin: Plugin): this;
39
+ unuse(pluginName: string): this;
40
+ hasPlugin(pluginName: string): boolean;
41
+ request<Schema extends StandardSchemaV1>(config: RequestConfig & {
42
+ schema: Schema;
43
+ }): Promise<StandardSchemaV1.InferOutput<Schema>>;
44
+ request<Schema extends StandardSchemaV1>(input: Request, config: RequestInputConfig & {
45
+ schema: Schema;
46
+ }): Promise<StandardSchemaV1.InferOutput<Schema>>;
47
+ request<T = unknown>(config: RequestConfig): Promise<T>;
48
+ request<T = unknown>(input: Request, config?: RequestInputConfig): Promise<T>;
49
+ requestResponse<Schema extends StandardSchemaV1>(config: RequestConfig & {
50
+ schema: Schema;
51
+ }): Promise<NporaResponse<StandardSchemaV1.InferOutput<Schema>>>;
52
+ requestResponse<Schema extends StandardSchemaV1>(input: Request, config: RequestInputConfig & {
53
+ schema: Schema;
54
+ }): Promise<NporaResponse<StandardSchemaV1.InferOutput<Schema>>>;
55
+ requestResponse<T = unknown>(config: RequestConfig): Promise<NporaResponse<T>>;
56
+ requestResponse<T = unknown>(input: Request, config?: RequestInputConfig): Promise<NporaResponse<T>>;
57
+ get<Schema extends StandardSchemaV1>(url: RequestURL, config: SchemaMethodConfig<Schema>): Promise<StandardSchemaV1.InferOutput<Schema>>;
58
+ get<T = unknown>(url: RequestURL, config?: MethodConfig): Promise<T>;
59
+ getResponse<Schema extends StandardSchemaV1>(url: RequestURL, config: SchemaMethodConfig<Schema>): Promise<NporaResponse<StandardSchemaV1.InferOutput<Schema>>>;
60
+ getResponse<T = unknown>(url: RequestURL, config?: MethodConfig): Promise<NporaResponse<T>>;
61
+ post<Schema extends StandardSchemaV1>(url: RequestURL, config: SchemaMethodConfig<Schema>): Promise<StandardSchemaV1.InferOutput<Schema>>;
62
+ post<T = unknown>(url: RequestURL, config?: MethodConfig): Promise<T>;
63
+ postResponse<Schema extends StandardSchemaV1>(url: RequestURL, config: SchemaMethodConfig<Schema>): Promise<NporaResponse<StandardSchemaV1.InferOutput<Schema>>>;
64
+ postResponse<T = unknown>(url: RequestURL, config?: MethodConfig): Promise<NporaResponse<T>>;
65
+ put<Schema extends StandardSchemaV1>(url: RequestURL, config: SchemaMethodConfig<Schema>): Promise<StandardSchemaV1.InferOutput<Schema>>;
66
+ put<T = unknown>(url: RequestURL, config?: MethodConfig): Promise<T>;
67
+ putResponse<Schema extends StandardSchemaV1>(url: RequestURL, config: SchemaMethodConfig<Schema>): Promise<NporaResponse<StandardSchemaV1.InferOutput<Schema>>>;
68
+ putResponse<T = unknown>(url: RequestURL, config?: MethodConfig): Promise<NporaResponse<T>>;
69
+ patch<Schema extends StandardSchemaV1>(url: RequestURL, config: SchemaMethodConfig<Schema>): Promise<StandardSchemaV1.InferOutput<Schema>>;
70
+ patch<T = unknown>(url: RequestURL, config?: MethodConfig): Promise<T>;
71
+ patchResponse<Schema extends StandardSchemaV1>(url: RequestURL, config: SchemaMethodConfig<Schema>): Promise<NporaResponse<StandardSchemaV1.InferOutput<Schema>>>;
72
+ patchResponse<T = unknown>(url: RequestURL, config?: MethodConfig): Promise<NporaResponse<T>>;
73
+ query<Schema extends StandardSchemaV1>(url: RequestURL, config: SchemaMethodConfig<Schema>): Promise<StandardSchemaV1.InferOutput<Schema>>;
74
+ query<T = unknown>(url: RequestURL, config?: MethodConfig): Promise<T>;
75
+ queryResponse<Schema extends StandardSchemaV1>(url: RequestURL, config: SchemaMethodConfig<Schema>): Promise<NporaResponse<StandardSchemaV1.InferOutput<Schema>>>;
76
+ queryResponse<T = unknown>(url: RequestURL, config?: MethodConfig): Promise<NporaResponse<T>>;
77
+ delete<Schema extends StandardSchemaV1>(url: RequestURL, config: SchemaMethodConfig<Schema>): Promise<StandardSchemaV1.InferOutput<Schema>>;
78
+ delete<T = unknown>(url: RequestURL, config?: MethodConfig): Promise<T>;
79
+ deleteResponse<Schema extends StandardSchemaV1>(url: RequestURL, config: SchemaMethodConfig<Schema>): Promise<NporaResponse<StandardSchemaV1.InferOutput<Schema>>>;
80
+ deleteResponse<T = unknown>(url: RequestURL, config?: MethodConfig): Promise<NporaResponse<T>>;
81
+ head(url: RequestURL, config?: Omit<MethodConfig, 'schema'>): Promise<void>;
82
+ headResponse(url: RequestURL, config?: Omit<MethodConfig, 'schema'>): Promise<NporaResponse<void>>;
83
+ options<Schema extends StandardSchemaV1>(url: RequestURL, config: SchemaMethodConfig<Schema>): Promise<StandardSchemaV1.InferOutput<Schema>>;
84
+ options<T = unknown>(url: RequestURL, config?: MethodConfig): Promise<T>;
85
+ optionsResponse<Schema extends StandardSchemaV1>(url: RequestURL, config: SchemaMethodConfig<Schema>): Promise<NporaResponse<StandardSchemaV1.InferOutput<Schema>>>;
86
+ optionsResponse<T = unknown>(url: RequestURL, config?: MethodConfig): Promise<NporaResponse<T>>;
87
+ /**
88
+ * Consume a server-sent event response as a lazy async iterable.
89
+ */
90
+ sse(url: RequestURL, config?: Omit<RequestConfig, 'url' | 'method' | 'responseType' | 'schema'>): Promise<AsyncIterable<ServerSentEvent>>;
91
+ /**
92
+ * Consume a server-sent event response with complete response metadata.
93
+ */
94
+ sseResponse(url: RequestURL, config?: Omit<RequestConfig, 'url' | 'method' | 'responseType' | 'schema'>): Promise<NporaResponse<AsyncIterable<ServerSentEvent>>>;
95
+ /**
96
+ * Consume newline-delimited JSON records as a lazy async iterable.
97
+ */
98
+ ndjson<T = unknown>(url: RequestURL, config?: Omit<RequestConfig, 'url' | 'method' | 'responseType' | 'schema'>): Promise<AsyncIterable<T>>;
99
+ /**
100
+ * Consume newline-delimited JSON with complete response metadata.
101
+ */
102
+ ndjsonResponse<T = unknown>(url: RequestURL, config?: Omit<RequestConfig, 'url' | 'method' | 'responseType' | 'schema'>): Promise<NporaResponse<AsyncIterable<T>>>;
103
+ private requestMethod;
104
+ private requestMethodResponse;
105
+ private mergeMethodConfig;
106
+ private mergeRequestInput;
107
+ private createPipeline;
108
+ private validatePlugin;
109
+ private findDependent;
110
+ }
111
+ //#endregion
112
+ //#region src/client/createClient.d.ts
113
+ /**
114
+ * Create an HTTP client instance.
115
+ */
116
+ declare function createClient(options?: ClientOptions): Client;
117
+ //#endregion
118
+ //#region src/adapters/FetchAdapter.d.ts
119
+ declare class FetchAdapter implements Adapter {
120
+ request<T = unknown>(config: RequestConfig): Promise<NporaResponse<T>>;
121
+ requestValidated<T = unknown>(config: RequestConfig, validatedHeaders: Headers, preserveRaw?: boolean): Promise<NporaResponse<T>>;
122
+ private execute;
123
+ }
124
+ //#endregion
125
+ //#region src/errors/RequestError.d.ts
126
+ /**
127
+ * Public request error codes.
128
+ */
129
+ type RequestErrorCode = 'CONFIG_ERROR' | 'HTTP_ERROR' | 'NETWORK_ERROR' | 'TIMEOUT_ERROR' | 'ABORT_ERROR' | 'PARSER_ERROR' | 'SCHEMA_ERROR' | 'REQUEST_TOO_LARGE' | 'RESPONSE_TOO_LARGE' | 'CIRCUIT_OPEN' | 'CONCURRENCY_LIMIT';
130
+ interface RequestErrorOptions<T = unknown> {
131
+ /**
132
+ * Stable machine-readable error code.
133
+ */
134
+ code: RequestErrorCode;
135
+ /**
136
+ * HTTP response status when available.
137
+ */
138
+ status?: number;
139
+ /**
140
+ * Parsed response body when the server returned a response.
141
+ */
142
+ data?: T;
143
+ /**
144
+ * Complete response metadata when the server returned a response.
145
+ */
146
+ response?: NporaResponse<T>;
147
+ /**
148
+ * Effective request configuration.
149
+ */
150
+ config?: RequestConfig;
151
+ /**
152
+ * Original error.
153
+ */
154
+ cause?: unknown;
155
+ }
156
+ /**
157
+ * Unified public error for all request failures.
158
+ */
159
+ declare class RequestError<T = unknown> extends Error {
160
+ readonly code: RequestErrorCode;
161
+ readonly status?: number;
162
+ readonly data?: T;
163
+ readonly response?: NporaResponse<T>;
164
+ readonly config?: RequestConfig;
165
+ readonly cause?: unknown;
166
+ constructor(message: string, options: RequestErrorOptions<T>);
167
+ /**
168
+ * Return a privacy-reduced representation for logs and telemetry.
169
+ *
170
+ * Request configuration, response bodies and causes are deliberately
171
+ * excluded because they can contain credentials or application data.
172
+ */
173
+ toJSON(): {
174
+ name: string;
175
+ message: string;
176
+ code: RequestErrorCode;
177
+ status?: number;
178
+ };
179
+ }
180
+ /**
181
+ * Identify request errors across realms and duplicated package instances.
182
+ */
183
+ declare function isRequestError<T = unknown>(value: unknown): value is RequestError<T>;
184
+ //#endregion
185
+ //#region src/errors/SchemaValidationError.d.ts
186
+ /**
187
+ * Response failure reported by a Standard Schema compatible validator.
188
+ */
189
+ declare class SchemaValidationError<T = unknown> extends RequestError<T> {
190
+ readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
191
+ readonly schemaVendor: string;
192
+ constructor(message: string, response: NporaResponse<T>, schemaVendor: string, issues?: ReadonlyArray<StandardSchemaV1.Issue>, cause?: unknown);
193
+ }
194
+ /**
195
+ * Identify schema validation errors across realms and package instances.
196
+ */
197
+ declare function isSchemaValidationError<T = unknown>(value: unknown): value is SchemaValidationError<T>;
198
+ //#endregion
199
+ export { RequestErrorOptions as a, createClient as c, RequestErrorCode as i, Client as l, isSchemaValidationError as n, isRequestError as o, RequestError as r, FetchAdapter as s, SchemaValidationError as t, ClientOptions as u };