@npora/request 1.17.4 → 1.17.5
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 +57 -86
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,78 +7,21 @@
|
|
|
7
7
|
[](LICENSE)
|
|
8
8
|
|
|
9
9
|
A production-focused, TypeScript-first HTTP client built on the standard Fetch
|
|
10
|
-
API
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
- **Add resilience without hiding the transport.** Retry, cache, circuit
|
|
26
|
-
breaker, concurrency, authentication, logging, and progress are isolated,
|
|
27
|
-
composable plugins over the standard Fetch API.
|
|
28
|
-
- **Use one predictable contract everywhere.** Browsers, Web Workers, Node.js,
|
|
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.
|
|
36
|
-
- **Ship less supply-chain risk.** The package has no runtime dependencies and
|
|
37
|
-
verifies public exports, browser behavior, security regressions, and size
|
|
38
|
-
budgets before release.
|
|
39
|
-
|
|
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.
|
|
47
|
-
|
|
48
|
-
The current stress gate completed **10,000,000 logical operations at concurrency
|
|
49
|
-
256 with zero unexpected failures**, followed by **100,000 real localhost HTTP
|
|
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).
|
|
53
|
-
|
|
54
|
-
## Features
|
|
55
|
-
|
|
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.
|
|
62
|
-
- Object query merging plus native ordered `URLSearchParams` through
|
|
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.
|
|
71
|
-
- Standard Schema v1 validation and transformation for untrusted responses.
|
|
72
|
-
- Incremental SSE and NDJSON async iterables with cancellation and size limits.
|
|
73
|
-
- Progress-aware file download streams that preserve backpressure and avoid
|
|
74
|
-
buffering the complete response in memory.
|
|
75
|
-
- Unified errors across Fetch, XHR, parsing, validation, timeouts, and aborts.
|
|
76
|
-
- Request/response/error interceptors with deterministic priority ordering.
|
|
77
|
-
- Shallow-merged local request context for tracing and lifecycle policies.
|
|
78
|
-
- Official retry, cache, circuit-breaker, concurrency, authentication, logger,
|
|
79
|
-
upload, and download plugins.
|
|
80
|
-
- Method-aware `MockAdapter` routing, matching, delays, failures, and history.
|
|
81
|
-
- Browser, Web Worker, ESM, and CommonJS support with zero runtime dependencies.
|
|
10
|
+
API. It adds typed responses, runtime validation, streaming, stable errors, and
|
|
11
|
+
composable resilience while keeping native platform values visible. The package
|
|
12
|
+
has zero runtime dependencies.
|
|
13
|
+
|
|
14
|
+
## Start here
|
|
15
|
+
|
|
16
|
+
| Goal | Documentation |
|
|
17
|
+
| --- | --- |
|
|
18
|
+
| Send the first request | [Quick start](#quick-start) |
|
|
19
|
+
| Find a client or response API | [API reference](docs/api.md) |
|
|
20
|
+
| Configure URLs, bodies, timeouts, or parsing | [Configuration reference](docs/configuration.md) |
|
|
21
|
+
| Add retry, cache, authentication, or observability | [Plugins](#plugins) |
|
|
22
|
+
| Handle stable error codes | [Errors](#errors) |
|
|
23
|
+
| Configure Node.js proxying, pooling, mTLS, or DNS | [Undici integration](docs/undici.md) |
|
|
24
|
+
| Review runtime boundaries and release checks | [Testing](docs/testing.md) and [security](docs/security.md) |
|
|
82
25
|
|
|
83
26
|
## Install
|
|
84
27
|
|
|
@@ -94,18 +37,6 @@ Node.js 22 or newer is required. Modern Chromium-based browsers, Firefox,
|
|
|
94
37
|
Safari/WebKit, and Web Workers are supported through their native Fetch
|
|
95
38
|
implementations.
|
|
96
39
|
|
|
97
|
-
## Version support
|
|
98
|
-
|
|
99
|
-
| Version | Status | Guidance |
|
|
100
|
-
| --- | --- | --- |
|
|
101
|
-
| `latest` | Current | Recommended for all new and existing applications. |
|
|
102
|
-
| Earlier releases `>=1.0.0` | Historical stable | Upgrade to `latest` for current fixes and security hardening. |
|
|
103
|
-
| `<1.0.0` | Deprecated and unsupported | Upgrade immediately; 0.x receives no fixes or security updates. |
|
|
104
|
-
|
|
105
|
-
All published releases before `1.0.0` are deprecated by project policy. Do not
|
|
106
|
-
use a 0.x release in production, documentation examples, dependency templates,
|
|
107
|
-
or new lockfiles.
|
|
108
|
-
|
|
109
40
|
## Quick start
|
|
110
41
|
|
|
111
42
|
```ts
|
|
@@ -127,8 +58,18 @@ const api = createClient({
|
|
|
127
58
|
const user = await api.get<User>('/users/1')
|
|
128
59
|
```
|
|
129
60
|
|
|
130
|
-
Data-first methods return the parsed response body.
|
|
131
|
-
|
|
61
|
+
Data-first methods return the parsed response body. Request JSON with the
|
|
62
|
+
dedicated `json` option:
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
const created = await api.post<User>('/users', {
|
|
66
|
+
json: {
|
|
67
|
+
name: 'Ada'
|
|
68
|
+
}
|
|
69
|
+
})
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Use a response method when status, headers, or the native `Response` is needed:
|
|
132
73
|
|
|
133
74
|
```ts
|
|
134
75
|
const response = await api.getResponse<User>('/users/1')
|
|
@@ -139,6 +80,36 @@ console.log(response.headers)
|
|
|
139
80
|
console.log(response.raw)
|
|
140
81
|
```
|
|
141
82
|
|
|
83
|
+
## Why Npora Request
|
|
84
|
+
|
|
85
|
+
- **Runtime-safe responses.** Standard Schema v1 validates and transforms
|
|
86
|
+
untrusted data while preserving response and error metadata.
|
|
87
|
+
- **Incremental streaming.** File downloads, SSE, and NDJSON preserve
|
|
88
|
+
backpressure, cancellation, timeouts, progress, and response-size limits.
|
|
89
|
+
- **Composable resilience.** Retry, cache, circuit breaker, concurrency,
|
|
90
|
+
rate limiting, authentication, logging, and observability are isolated
|
|
91
|
+
plugins over the standard Fetch lifecycle.
|
|
92
|
+
- **Native platform contracts.** `URL`, `Request`, `Headers`, `FormData`,
|
|
93
|
+
`Blob`, `ArrayBuffer`, and `ReadableStream` retain their Fetch semantics.
|
|
94
|
+
- **Bounded traffic and stable failures.** Separate request, successful
|
|
95
|
+
response, and error response limits use typed errors with documented codes.
|
|
96
|
+
- **Portable, verifiable delivery.** Browser, Web Worker, Node.js, ESM, and
|
|
97
|
+
CommonJS behavior is checked alongside public exports, security regressions,
|
|
98
|
+
and package-size budgets.
|
|
99
|
+
|
|
100
|
+
## Version support
|
|
101
|
+
|
|
102
|
+
| Version | Status | Guidance |
|
|
103
|
+
| --- | --- | --- |
|
|
104
|
+
| `latest` | Current stable 1.x | Recommended for new and existing applications. |
|
|
105
|
+
| Earlier releases `>=1.0.0` | Historical | Upgrade to `latest` for current fixes and security hardening. |
|
|
106
|
+
| `<1.0.0` | Unsupported | Upgrade immediately; 0.x receives no fixes or security updates. |
|
|
107
|
+
|
|
108
|
+
The current 1.x line is in active maintenance. Backward-compatible fixes ship
|
|
109
|
+
as patch releases; new public capabilities require a minor release, and
|
|
110
|
+
breaking public API changes require a new major version. All published releases
|
|
111
|
+
before `1.0.0` are deprecated.
|
|
112
|
+
|
|
142
113
|
## Native Fetch inputs
|
|
143
114
|
|
|
144
115
|
Use a native `Request` directly when another platform layer already owns the
|