nlcurl 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +143 -140
- package/dist/cache/groups.d.ts +75 -0
- package/dist/cache/groups.d.ts.map +1 -0
- package/dist/cache/groups.js +118 -0
- package/dist/cache/groups.js.map +1 -0
- package/dist/cache/no-vary-search.d.ts +33 -0
- package/dist/cache/no-vary-search.d.ts.map +1 -0
- package/dist/cache/no-vary-search.js +148 -0
- package/dist/cache/no-vary-search.js.map +1 -0
- package/dist/cache/range.d.ts +120 -0
- package/dist/cache/range.d.ts.map +1 -0
- package/dist/cache/range.js +193 -0
- package/dist/cache/range.js.map +1 -0
- package/dist/cache/store.d.ts +58 -36
- package/dist/cache/store.d.ts.map +1 -1
- package/dist/cache/store.js +58 -46
- package/dist/cache/store.js.map +1 -1
- package/dist/cache/types.d.ts +7 -39
- package/dist/cache/types.d.ts.map +1 -1
- package/dist/cli/args.d.ts +4 -37
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +3 -4
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/index.d.ts +0 -5
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +1 -6
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/output.d.ts +14 -20
- package/dist/cli/output.d.ts.map +1 -1
- package/dist/cli/output.js +14 -20
- package/dist/cli/output.js.map +1 -1
- package/dist/cookies/jar.d.ts +30 -39
- package/dist/cookies/jar.d.ts.map +1 -1
- package/dist/cookies/jar.js +27 -37
- package/dist/cookies/jar.js.map +1 -1
- package/dist/cookies/parser.d.ts +13 -17
- package/dist/cookies/parser.d.ts.map +1 -1
- package/dist/cookies/parser.js +17 -14
- package/dist/cookies/parser.js.map +1 -1
- package/dist/cookies/psl-data.d.ts +1 -1
- package/dist/cookies/psl-data.js +1 -1
- package/dist/cookies/public-suffix.d.ts +5 -27
- package/dist/cookies/public-suffix.d.ts.map +1 -1
- package/dist/cookies/public-suffix.js +5 -37
- package/dist/cookies/public-suffix.js.map +1 -1
- package/dist/core/auth.d.ts +30 -0
- package/dist/core/auth.d.ts.map +1 -0
- package/dist/core/auth.js +34 -0
- package/dist/core/auth.js.map +1 -0
- package/dist/core/client.d.ts +28 -40
- package/dist/core/client.d.ts.map +1 -1
- package/dist/core/client.js +31 -41
- package/dist/core/client.js.map +1 -1
- package/dist/core/errors.d.ts +64 -88
- package/dist/core/errors.d.ts.map +1 -1
- package/dist/core/errors.js +64 -88
- package/dist/core/errors.js.map +1 -1
- package/dist/core/request.d.ts +23 -111
- package/dist/core/request.d.ts.map +1 -1
- package/dist/core/response.d.ts +49 -66
- package/dist/core/response.d.ts.map +1 -1
- package/dist/core/response.js +45 -59
- package/dist/core/response.js.map +1 -1
- package/dist/core/session.d.ts +66 -78
- package/dist/core/session.d.ts.map +1 -1
- package/dist/core/session.js +105 -76
- package/dist/core/session.js.map +1 -1
- package/dist/core/validation.d.ts +44 -43
- package/dist/core/validation.d.ts.map +1 -1
- package/dist/core/validation.js +44 -56
- package/dist/core/validation.js.map +1 -1
- package/dist/dns/cache.d.ts +59 -0
- package/dist/dns/cache.d.ts.map +1 -0
- package/dist/dns/cache.js +99 -0
- package/dist/dns/cache.js.map +1 -0
- package/dist/dns/codec.d.ts +20 -18
- package/dist/dns/codec.d.ts.map +1 -1
- package/dist/dns/codec.js +20 -36
- package/dist/dns/codec.js.map +1 -1
- package/dist/dns/doh-resolver.d.ts +17 -31
- package/dist/dns/doh-resolver.d.ts.map +1 -1
- package/dist/dns/doh-resolver.js +46 -47
- package/dist/dns/doh-resolver.js.map +1 -1
- package/dist/dns/dot-resolver.d.ts +89 -0
- package/dist/dns/dot-resolver.d.ts.map +1 -0
- package/dist/dns/dot-resolver.js +158 -0
- package/dist/dns/dot-resolver.js.map +1 -0
- package/dist/dns/https-rr.d.ts +19 -30
- package/dist/dns/https-rr.d.ts.map +1 -1
- package/dist/dns/https-rr.js +22 -40
- package/dist/dns/https-rr.js.map +1 -1
- package/dist/dns/types.d.ts +31 -59
- package/dist/dns/types.d.ts.map +1 -1
- package/dist/dns/types.js +3 -14
- package/dist/dns/types.js.map +1 -1
- package/dist/fingerprints/akamai.d.ts +3 -11
- package/dist/fingerprints/akamai.d.ts.map +1 -1
- package/dist/fingerprints/akamai.js +3 -11
- package/dist/fingerprints/akamai.js.map +1 -1
- package/dist/fingerprints/database.d.ts +6 -14
- package/dist/fingerprints/database.d.ts.map +1 -1
- package/dist/fingerprints/database.js +6 -14
- package/dist/fingerprints/database.js.map +1 -1
- package/dist/fingerprints/extensions.d.ts +56 -71
- package/dist/fingerprints/extensions.d.ts.map +1 -1
- package/dist/fingerprints/extensions.js +58 -71
- package/dist/fingerprints/extensions.js.map +1 -1
- package/dist/fingerprints/ja3.d.ts +12 -30
- package/dist/fingerprints/ja3.d.ts.map +1 -1
- package/dist/fingerprints/ja3.js +12 -30
- package/dist/fingerprints/ja3.js.map +1 -1
- package/dist/fingerprints/ja4.d.ts +18 -0
- package/dist/fingerprints/ja4.d.ts.map +1 -0
- package/dist/fingerprints/ja4.js +83 -0
- package/dist/fingerprints/ja4.js.map +1 -0
- package/dist/fingerprints/profiles/chrome.d.ts +18 -21
- package/dist/fingerprints/profiles/chrome.d.ts.map +1 -1
- package/dist/fingerprints/profiles/chrome.js +35 -31
- package/dist/fingerprints/profiles/chrome.js.map +1 -1
- package/dist/fingerprints/profiles/edge.d.ts +7 -10
- package/dist/fingerprints/profiles/edge.d.ts.map +1 -1
- package/dist/fingerprints/profiles/edge.js +7 -10
- package/dist/fingerprints/profiles/edge.js.map +1 -1
- package/dist/fingerprints/profiles/firefox.d.ts +8 -11
- package/dist/fingerprints/profiles/firefox.d.ts.map +1 -1
- package/dist/fingerprints/profiles/firefox.js +8 -11
- package/dist/fingerprints/profiles/firefox.js.map +1 -1
- package/dist/fingerprints/profiles/safari.d.ts +11 -14
- package/dist/fingerprints/profiles/safari.d.ts.map +1 -1
- package/dist/fingerprints/profiles/safari.js +11 -14
- package/dist/fingerprints/profiles/safari.js.map +1 -1
- package/dist/fingerprints/profiles/tor.d.ts +5 -8
- package/dist/fingerprints/profiles/tor.d.ts.map +1 -1
- package/dist/fingerprints/profiles/tor.js +5 -8
- package/dist/fingerprints/profiles/tor.js.map +1 -1
- package/dist/fingerprints/types.d.ts +42 -73
- package/dist/fingerprints/types.d.ts.map +1 -1
- package/dist/hsts/store.d.ts +19 -21
- package/dist/hsts/store.d.ts.map +1 -1
- package/dist/hsts/store.js +20 -28
- package/dist/hsts/store.js.map +1 -1
- package/dist/hsts/types.d.ts +10 -14
- package/dist/hsts/types.d.ts.map +1 -1
- package/dist/http/alt-svc.d.ts +31 -49
- package/dist/http/alt-svc.d.ts.map +1 -1
- package/dist/http/alt-svc.js +21 -55
- package/dist/http/alt-svc.js.map +1 -1
- package/dist/http/early-hints.d.ts +23 -0
- package/dist/http/early-hints.d.ts.map +1 -0
- package/dist/http/early-hints.js +33 -0
- package/dist/http/early-hints.js.map +1 -0
- package/dist/http/form-data.d.ts +17 -35
- package/dist/http/form-data.d.ts.map +1 -1
- package/dist/http/form-data.js +12 -34
- package/dist/http/form-data.js.map +1 -1
- package/dist/http/h1/client.d.ts +14 -26
- package/dist/http/h1/client.d.ts.map +1 -1
- package/dist/http/h1/client.js +14 -23
- package/dist/http/h1/client.js.map +1 -1
- package/dist/http/h1/encoder.d.ts +10 -17
- package/dist/http/h1/encoder.d.ts.map +1 -1
- package/dist/http/h1/encoder.js +10 -17
- package/dist/http/h1/encoder.js.map +1 -1
- package/dist/http/h1/parser.d.ts +22 -59
- package/dist/http/h1/parser.d.ts.map +1 -1
- package/dist/http/h1/parser.js +15 -47
- package/dist/http/h1/parser.js.map +1 -1
- package/dist/http/h2/client.d.ts +18 -59
- package/dist/http/h2/client.d.ts.map +1 -1
- package/dist/http/h2/client.js +29 -64
- package/dist/http/h2/client.js.map +1 -1
- package/dist/http/h2/frames.d.ts +53 -84
- package/dist/http/h2/frames.d.ts.map +1 -1
- package/dist/http/h2/frames.js +48 -76
- package/dist/http/h2/frames.js.map +1 -1
- package/dist/http/h2/hpack.d.ts +16 -35
- package/dist/http/h2/hpack.d.ts.map +1 -1
- package/dist/http/h2/hpack.js +16 -35
- package/dist/http/h2/hpack.js.map +1 -1
- package/dist/http/h3/detection.d.ts +5 -7
- package/dist/http/h3/detection.d.ts.map +1 -1
- package/dist/http/h3/detection.js +5 -23
- package/dist/http/h3/detection.js.map +1 -1
- package/dist/http/negotiator.d.ts +25 -38
- package/dist/http/negotiator.d.ts.map +1 -1
- package/dist/http/negotiator.js +16 -28
- package/dist/http/negotiator.js.map +1 -1
- package/dist/http/pool.d.ts +32 -62
- package/dist/http/pool.d.ts.map +1 -1
- package/dist/http/pool.js +22 -41
- package/dist/http/pool.js.map +1 -1
- package/dist/http/resumable-upload.d.ts +76 -0
- package/dist/http/resumable-upload.d.ts.map +1 -0
- package/dist/http/resumable-upload.js +104 -0
- package/dist/http/resumable-upload.js.map +1 -0
- package/dist/http/trailers.d.ts +29 -0
- package/dist/http/trailers.d.ts.map +1 -0
- package/dist/http/trailers.js +57 -0
- package/dist/http/trailers.js.map +1 -0
- package/dist/index.d.ts +21 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -2
- package/dist/index.js.map +1 -1
- package/dist/middleware/interceptor.d.ts +13 -32
- package/dist/middleware/interceptor.d.ts.map +1 -1
- package/dist/middleware/interceptor.js +11 -16
- package/dist/middleware/interceptor.js.map +1 -1
- package/dist/middleware/rate-limiter.d.ts +8 -17
- package/dist/middleware/rate-limiter.d.ts.map +1 -1
- package/dist/middleware/rate-limiter.js +11 -12
- package/dist/middleware/rate-limiter.js.map +1 -1
- package/dist/middleware/retry-after.d.ts +15 -0
- package/dist/middleware/retry-after.d.ts.map +1 -0
- package/dist/middleware/retry-after.js +36 -0
- package/dist/middleware/retry-after.js.map +1 -0
- package/dist/middleware/retry.d.ts +9 -18
- package/dist/middleware/retry.d.ts.map +1 -1
- package/dist/middleware/retry.js +12 -9
- package/dist/middleware/retry.js.map +1 -1
- package/dist/proxy/auth.d.ts +73 -0
- package/dist/proxy/auth.d.ts.map +1 -0
- package/dist/proxy/auth.js +128 -0
- package/dist/proxy/auth.js.map +1 -0
- package/dist/proxy/env-proxy.d.ts +5 -15
- package/dist/proxy/env-proxy.d.ts.map +1 -1
- package/dist/proxy/env-proxy.js +5 -23
- package/dist/proxy/env-proxy.js.map +1 -1
- package/dist/proxy/http-proxy.d.ts +12 -19
- package/dist/proxy/http-proxy.d.ts.map +1 -1
- package/dist/proxy/http-proxy.js +5 -8
- package/dist/proxy/http-proxy.js.map +1 -1
- package/dist/proxy/socks.d.ts +13 -20
- package/dist/proxy/socks.d.ts.map +1 -1
- package/dist/proxy/socks.js +5 -8
- package/dist/proxy/socks.js.map +1 -1
- package/dist/sse/parser.d.ts +14 -37
- package/dist/sse/parser.d.ts.map +1 -1
- package/dist/sse/parser.js +14 -28
- package/dist/sse/parser.js.map +1 -1
- package/dist/tls/constants.d.ts +15 -74
- package/dist/tls/constants.d.ts.map +1 -1
- package/dist/tls/constants.js +15 -74
- package/dist/tls/constants.js.map +1 -1
- package/dist/tls/ct.d.ts +78 -0
- package/dist/tls/ct.d.ts.map +1 -0
- package/dist/tls/ct.js +175 -0
- package/dist/tls/ct.js.map +1 -0
- package/dist/tls/early-data.d.ts +45 -0
- package/dist/tls/early-data.d.ts.map +1 -0
- package/dist/tls/early-data.js +46 -0
- package/dist/tls/early-data.js.map +1 -0
- package/dist/tls/ech.d.ts +68 -85
- package/dist/tls/ech.d.ts.map +1 -1
- package/dist/tls/ech.js +54 -102
- package/dist/tls/ech.js.map +1 -1
- package/dist/tls/keylog.d.ts +34 -0
- package/dist/tls/keylog.d.ts.map +1 -0
- package/dist/tls/keylog.js +64 -0
- package/dist/tls/keylog.js.map +1 -0
- package/dist/tls/node-engine.d.ts +10 -17
- package/dist/tls/node-engine.d.ts.map +1 -1
- package/dist/tls/node-engine.js +20 -18
- package/dist/tls/node-engine.js.map +1 -1
- package/dist/tls/ocsp.d.ts +55 -0
- package/dist/tls/ocsp.d.ts.map +1 -0
- package/dist/tls/ocsp.js +131 -0
- package/dist/tls/ocsp.js.map +1 -0
- package/dist/tls/pin-verification.d.ts +5 -4
- package/dist/tls/pin-verification.d.ts.map +1 -1
- package/dist/tls/pin-verification.js +5 -11
- package/dist/tls/pin-verification.js.map +1 -1
- package/dist/tls/session-cache.d.ts +27 -39
- package/dist/tls/session-cache.d.ts.map +1 -1
- package/dist/tls/session-cache.js +20 -24
- package/dist/tls/session-cache.js.map +1 -1
- package/dist/tls/stealth/client-hello.d.ts +25 -44
- package/dist/tls/stealth/client-hello.d.ts.map +1 -1
- package/dist/tls/stealth/client-hello.js +17 -28
- package/dist/tls/stealth/client-hello.js.map +1 -1
- package/dist/tls/stealth/engine.d.ts +5 -15
- package/dist/tls/stealth/engine.d.ts.map +1 -1
- package/dist/tls/stealth/engine.js +11 -17
- package/dist/tls/stealth/engine.js.map +1 -1
- package/dist/tls/stealth/handshake.d.ts +21 -31
- package/dist/tls/stealth/handshake.d.ts.map +1 -1
- package/dist/tls/stealth/handshake.js +15 -43
- package/dist/tls/stealth/handshake.js.map +1 -1
- package/dist/tls/stealth/key-schedule.d.ts +59 -86
- package/dist/tls/stealth/key-schedule.d.ts.map +1 -1
- package/dist/tls/stealth/key-schedule.js +46 -58
- package/dist/tls/stealth/key-schedule.js.map +1 -1
- package/dist/tls/stealth/record-layer.d.ts +52 -75
- package/dist/tls/stealth/record-layer.d.ts.map +1 -1
- package/dist/tls/stealth/record-layer.js +47 -63
- package/dist/tls/stealth/record-layer.js.map +1 -1
- package/dist/tls/stealth/tls12-handshake.d.ts +16 -0
- package/dist/tls/stealth/tls12-handshake.d.ts.map +1 -1
- package/dist/tls/stealth/tls12-handshake.js +8 -0
- package/dist/tls/stealth/tls12-handshake.js.map +1 -1
- package/dist/tls/types.d.ts +42 -60
- package/dist/tls/types.d.ts.map +1 -1
- package/dist/utils/buffer-reader.d.ts +26 -81
- package/dist/utils/buffer-reader.d.ts.map +1 -1
- package/dist/utils/buffer-reader.js +26 -81
- package/dist/utils/buffer-reader.js.map +1 -1
- package/dist/utils/buffer-writer.d.ts +30 -66
- package/dist/utils/buffer-writer.d.ts.map +1 -1
- package/dist/utils/buffer-writer.js +30 -66
- package/dist/utils/buffer-writer.js.map +1 -1
- package/dist/utils/compression.d.ts +18 -0
- package/dist/utils/compression.d.ts.map +1 -0
- package/dist/utils/compression.js +34 -0
- package/dist/utils/compression.js.map +1 -0
- package/dist/utils/dictionary-transport.d.ts +97 -0
- package/dist/utils/dictionary-transport.d.ts.map +1 -0
- package/dist/utils/dictionary-transport.js +171 -0
- package/dist/utils/dictionary-transport.js.map +1 -0
- package/dist/utils/encoding.d.ts +12 -30
- package/dist/utils/encoding.d.ts.map +1 -1
- package/dist/utils/encoding.js +15 -46
- package/dist/utils/encoding.js.map +1 -1
- package/dist/utils/happy-eyeballs.d.ts +18 -8
- package/dist/utils/happy-eyeballs.d.ts.map +1 -1
- package/dist/utils/happy-eyeballs.js +19 -27
- package/dist/utils/happy-eyeballs.js.map +1 -1
- package/dist/utils/logger.d.ts +54 -81
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +92 -64
- package/dist/utils/logger.js.map +1 -1
- package/dist/utils/tcp-fast-open.d.ts +30 -0
- package/dist/utils/tcp-fast-open.d.ts.map +1 -0
- package/dist/utils/tcp-fast-open.js +36 -0
- package/dist/utils/tcp-fast-open.js.map +1 -0
- package/dist/utils/url.d.ts +18 -25
- package/dist/utils/url.d.ts.map +1 -1
- package/dist/utils/url.js +18 -25
- package/dist/utils/url.js.map +1 -1
- package/dist/ws/client.d.ts +33 -53
- package/dist/ws/client.d.ts.map +1 -1
- package/dist/ws/client.js +29 -30
- package/dist/ws/client.js.map +1 -1
- package/dist/ws/frame.d.ts +24 -41
- package/dist/ws/frame.d.ts.map +1 -1
- package/dist/ws/frame.js +18 -33
- package/dist/ws/frame.js.map +1 -1
- package/dist/ws/permessage-deflate.d.ts +23 -28
- package/dist/ws/permessage-deflate.d.ts.map +1 -1
- package/dist/ws/permessage-deflate.js +18 -26
- package/dist/ws/permessage-deflate.js.map +1 -1
- package/package.json +62 -62
package/dist/core/request.d.ts
CHANGED
|
@@ -6,13 +6,11 @@ import type { CacheConfig, CacheMode } from "../cache/types.js";
|
|
|
6
6
|
import type { HSTSConfig } from "../hsts/types.js";
|
|
7
7
|
import type { DNSConfig } from "../dns/types.js";
|
|
8
8
|
import type { ECHOptions } from "../tls/ech.js";
|
|
9
|
+
import type { AuthConfig } from "./auth.js";
|
|
10
|
+
import type { EarlyHintsCallback } from "../http/early-hints.js";
|
|
11
|
+
import type { RequestEncoding } from "../utils/compression.js";
|
|
9
12
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* @typedef {Object} ProgressEvent
|
|
13
|
-
* @property {number} bytes - Bytes transferred so far.
|
|
14
|
-
* @property {number} totalBytes - Total bytes expected (`0` if unknown).
|
|
15
|
-
* @property {number} percent - Completion percentage (`0`–`100`), or `0` if total is unknown.
|
|
13
|
+
* Describes the progress of an upload or download operation.
|
|
16
14
|
*/
|
|
17
15
|
export interface ProgressEvent {
|
|
18
16
|
bytes: number;
|
|
@@ -20,28 +18,18 @@ export interface ProgressEvent {
|
|
|
20
18
|
percent: number;
|
|
21
19
|
}
|
|
22
20
|
/**
|
|
23
|
-
* Callback invoked during
|
|
21
|
+
* Callback invoked during upload or download progress.
|
|
24
22
|
*
|
|
25
23
|
* @callback ProgressCallback
|
|
26
|
-
* @param {ProgressEvent} event -
|
|
24
|
+
* @param {ProgressEvent} event - The current progress snapshot.
|
|
27
25
|
*/
|
|
28
26
|
export type ProgressCallback = (event: ProgressEvent) => void;
|
|
29
27
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* @typedef {'GET'|'POST'|'PUT'|'PATCH'|'DELETE'|'HEAD'|'OPTIONS'} HttpMethod
|
|
28
|
+
* Supported HTTP request methods.
|
|
33
29
|
*/
|
|
34
|
-
export type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS";
|
|
30
|
+
export type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS" | "QUERY";
|
|
35
31
|
/**
|
|
36
|
-
*
|
|
37
|
-
* milliseconds elapsed from request initiation.
|
|
38
|
-
*
|
|
39
|
-
* @typedef {Object} RequestTimings
|
|
40
|
-
* @property {number} dns - Time spent resolving the hostname via DNS.
|
|
41
|
-
* @property {number} connect - Time spent establishing the TCP connection.
|
|
42
|
-
* @property {number} tls - Time spent completing the TLS handshake.
|
|
43
|
-
* @property {number} firstByte - Time from connection open to the first response byte received.
|
|
44
|
-
* @property {number} total - Total wall-clock time for the entire request.
|
|
32
|
+
* Timing measurements for each phase of a request lifecycle, in milliseconds.
|
|
45
33
|
*/
|
|
46
34
|
export interface RequestTimings {
|
|
47
35
|
dns: number;
|
|
@@ -51,14 +39,7 @@ export interface RequestTimings {
|
|
|
51
39
|
total: number;
|
|
52
40
|
}
|
|
53
41
|
/**
|
|
54
|
-
* Per-phase timeout
|
|
55
|
-
* a field means no limit is applied for that phase.
|
|
56
|
-
*
|
|
57
|
-
* @typedef {Object} TimeoutConfig
|
|
58
|
-
* @property {number} [connect] - Maximum milliseconds to establish the TCP connection.
|
|
59
|
-
* @property {number} [tls] - Maximum milliseconds to complete the TLS handshake.
|
|
60
|
-
* @property {number} [response] - Maximum milliseconds to receive the first response byte.
|
|
61
|
-
* @property {number} [total] - Maximum total milliseconds for the whole request.
|
|
42
|
+
* Per-phase timeout thresholds for a request, in milliseconds.
|
|
62
43
|
*/
|
|
63
44
|
export interface TimeoutConfig {
|
|
64
45
|
connect?: number;
|
|
@@ -67,42 +48,12 @@ export interface TimeoutConfig {
|
|
|
67
48
|
total?: number;
|
|
68
49
|
}
|
|
69
50
|
/**
|
|
70
|
-
*
|
|
71
|
-
* plain strings are serialized automatically; raw `Buffer`s and
|
|
72
|
-
* `URLSearchParams` are used verbatim.
|
|
73
|
-
*
|
|
74
|
-
* @typedef {string|Buffer|URLSearchParams|Record<string,unknown>|ReadableStream<Uint8Array>|null} RequestBody
|
|
51
|
+
* Acceptable request body types for outgoing HTTP requests.
|
|
75
52
|
*/
|
|
76
53
|
export type RequestBody = string | Buffer | URLSearchParams | Record<string, unknown> | ReadableStream<Uint8Array> | FormData | null;
|
|
77
54
|
/**
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
* @typedef {Object} NLcURLRequest
|
|
82
|
-
* @property {string} url - Absolute or relative URL to request.
|
|
83
|
-
* @property {HttpMethod} [method='GET'] - HTTP method.
|
|
84
|
-
* @property {Record<string,string>} [headers] - Request headers to merge with session defaults.
|
|
85
|
-
* @property {RequestBody} [body] - Request body payload.
|
|
86
|
-
* @property {number|TimeoutConfig} [timeout] - Timeout in ms (flat) or per-phase config object.
|
|
87
|
-
* @property {AbortSignal} [signal] - Signal used to cancel the request early.
|
|
88
|
-
* @property {string} [impersonate] - Browser profile name (e.g. `"chrome136"`).
|
|
89
|
-
* @property {string} [ja3] - Custom JA3 fingerprint string override.
|
|
90
|
-
* @property {string} [akamai] - Custom Akamai HTTP/2 fingerprint override.
|
|
91
|
-
* @property {boolean} [stealth] - Use the custom stealth TLS engine.
|
|
92
|
-
* @property {boolean} [followRedirects=true] - Follow HTTP redirects automatically.
|
|
93
|
-
* @property {number} [maxRedirects=20] - Maximum number of redirects to follow.
|
|
94
|
-
* @property {boolean} [insecure] - Skip TLS certificate verification.
|
|
95
|
-
* @property {string} [proxy] - Proxy URL (`http://`, `socks4://`, `socks5://`).
|
|
96
|
-
* @property {[string,string]} [proxyAuth] - Proxy credentials as `[username, password]`.
|
|
97
|
-
* @property {'1.1'|'2'} [httpVersion] - Force a specific HTTP protocol version.
|
|
98
|
-
* @property {string} [baseURL] - Base URL prepended to relative `url` values.
|
|
99
|
-
* @property {Record<string,string|number|boolean>} [params] - Query parameters appended to the URL.
|
|
100
|
-
* @property {boolean|string} [cookieJar] - Enable a per-request cookie jar.
|
|
101
|
-
* @property {string} [acceptEncoding] - Override the `Accept-Encoding` header value.
|
|
102
|
-
* @property {string[]} [headerOrder] - Explicit header ordering for fingerprinting.
|
|
103
|
-
* @property {4|6} [dnsFamily] - Force IPv4 (`4`) or IPv6 (`6`) DNS resolution.
|
|
104
|
-
* @property {boolean} [stream] - Return a streaming response body.
|
|
105
|
-
* @property {Logger} [logger] - Logger instance for request-scoped diagnostics.
|
|
55
|
+
* Full request descriptor for a single HTTP request, including URL, method,
|
|
56
|
+
* headers, body, TLS fingerprinting, proxy, caching, and timeout options.
|
|
106
57
|
*/
|
|
107
58
|
export interface NLcURLRequest {
|
|
108
59
|
url: string;
|
|
@@ -130,29 +81,21 @@ export interface NLcURLRequest {
|
|
|
130
81
|
stream?: boolean;
|
|
131
82
|
logger?: Logger;
|
|
132
83
|
tls?: TLSOptions;
|
|
133
|
-
/** DNS-over-HTTPS configuration for this request. Overrides session-level DNS config. */
|
|
134
84
|
dns?: DNSConfig;
|
|
135
|
-
/** Encrypted Client Hello (ECH) options for this request. */
|
|
136
85
|
ech?: ECHOptions;
|
|
137
86
|
onUploadProgress?: ProgressCallback;
|
|
138
87
|
onDownloadProgress?: ProgressCallback;
|
|
139
88
|
throwOnError?: boolean;
|
|
140
|
-
/** HTTP cache mode for this request. Overrides session-level cache config. */
|
|
141
89
|
cache?: CacheMode;
|
|
142
|
-
/**
|
|
143
|
-
* Range header value for partial content requests (RFC 9110 §14).
|
|
144
|
-
* Example: `"bytes=0-499"` or `"bytes=500-999"` or `"bytes=-500"`.
|
|
145
|
-
*/
|
|
146
90
|
range?: string;
|
|
91
|
+
auth?: AuthConfig;
|
|
92
|
+
onEarlyHints?: EarlyHintsCallback;
|
|
93
|
+
expect100Continue?: boolean;
|
|
94
|
+
compressBody?: RequestEncoding;
|
|
95
|
+
methodOverride?: "QUERY";
|
|
147
96
|
}
|
|
148
97
|
/**
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
* @typedef {Object} ServerSentEvent
|
|
152
|
-
* @property {string} event - Event type (defaults to `"message"`).
|
|
153
|
-
* @property {string} data - Event data payload.
|
|
154
|
-
* @property {string} id - Last event ID.
|
|
155
|
-
* @property {number|undefined} retry - Reconnection time in ms suggested by the server.
|
|
98
|
+
* Represents a single server-sent event from an SSE stream.
|
|
156
99
|
*/
|
|
157
100
|
export interface ServerSentEvent {
|
|
158
101
|
event: string;
|
|
@@ -161,14 +104,7 @@ export interface ServerSentEvent {
|
|
|
161
104
|
retry?: number;
|
|
162
105
|
}
|
|
163
106
|
/**
|
|
164
|
-
* Configuration for automatic request retry
|
|
165
|
-
*
|
|
166
|
-
* @typedef {Object} RetryConfig
|
|
167
|
-
* @property {number} count - Maximum number of retry attempts after the initial request.
|
|
168
|
-
* @property {number} delay - Base delay in milliseconds between attempts.
|
|
169
|
-
* @property {'linear'|'exponential'} backoff - Strategy for increasing the delay on repeated failures.
|
|
170
|
-
* @property {number} jitter - Maximum random jitter in milliseconds added to each delay.
|
|
171
|
-
* @property {Function} [retryOn] - Optional predicate; return `true` to allow a retry.
|
|
107
|
+
* Configuration for automatic request retry behavior.
|
|
172
108
|
*/
|
|
173
109
|
export interface RetryConfig {
|
|
174
110
|
count: number;
|
|
@@ -178,28 +114,7 @@ export interface RetryConfig {
|
|
|
178
114
|
retryOn?: (error: Error | null, statusCode?: number) => boolean;
|
|
179
115
|
}
|
|
180
116
|
/**
|
|
181
|
-
* Session-level
|
|
182
|
-
* {@link NLcURLSession}. Individual request options always take precedence.
|
|
183
|
-
*
|
|
184
|
-
* @typedef {Object} NLcURLSessionConfig
|
|
185
|
-
* @property {string} [baseURL] - Base URL prepended to relative request URLs.
|
|
186
|
-
* @property {Record<string,string>} [headers] - Headers merged into every request.
|
|
187
|
-
* @property {number|TimeoutConfig} [timeout] - Default timeout applied to all requests.
|
|
188
|
-
* @property {string} [impersonate] - Default browser profile for fingerprinting.
|
|
189
|
-
* @property {string} [ja3] - Default JA3 fingerprint string.
|
|
190
|
-
* @property {string} [akamai] - Default Akamai HTTP/2 fingerprint.
|
|
191
|
-
* @property {boolean} [stealth] - Use the stealth TLS engine by default.
|
|
192
|
-
* @property {string} [proxy] - Default proxy URL.
|
|
193
|
-
* @property {[string,string]} [proxyAuth] - Default proxy credentials.
|
|
194
|
-
* @property {boolean} [followRedirects=true] - Follow redirects by default.
|
|
195
|
-
* @property {number} [maxRedirects=20] - Default maximum redirect count.
|
|
196
|
-
* @property {boolean} [insecure] - Skip TLS verification by default.
|
|
197
|
-
* @property {'1.1'|'2'} [httpVersion] - Force an HTTP protocol version for all requests.
|
|
198
|
-
* @property {boolean|string} [cookieJar] - Persistent cookie jar for the session.
|
|
199
|
-
* @property {Partial<RetryConfig>} [retry] - Automatic retry configuration.
|
|
200
|
-
* @property {string} [acceptEncoding] - Default `Accept-Encoding` header value.
|
|
201
|
-
* @property {4|6} [dnsFamily] - Force IPv4 or IPv6 for DNS resolution.
|
|
202
|
-
* @property {Logger} [logger] - Logger instance for session-scoped diagnostics.
|
|
117
|
+
* Session-level configuration shared across all requests in a session.
|
|
203
118
|
*/
|
|
204
119
|
export interface NLcURLSessionConfig {
|
|
205
120
|
baseURL?: string;
|
|
@@ -224,15 +139,12 @@ export interface NLcURLSessionConfig {
|
|
|
224
139
|
throwOnError?: boolean;
|
|
225
140
|
onUploadProgress?: ProgressCallback;
|
|
226
141
|
onDownloadProgress?: ProgressCallback;
|
|
227
|
-
/** HTTP cache configuration for the session (RFC 9111). */
|
|
228
142
|
cacheConfig?: CacheConfig;
|
|
229
|
-
/** HSTS configuration for the session (RFC 6797). */
|
|
230
143
|
hsts?: HSTSConfig;
|
|
231
|
-
/** DNS-over-HTTPS configuration for the session (RFC 8484). */
|
|
232
144
|
dns?: DNSConfig;
|
|
233
|
-
/** Encrypted Client Hello (ECH) configuration for the session (draft-ietf-tls-esni). */
|
|
234
145
|
ech?: ECHOptions;
|
|
235
|
-
/** Enable Alt-Svc (RFC 7838) for automatic HTTP/3 discovery. @default true */
|
|
236
146
|
altSvc?: boolean;
|
|
147
|
+
auth?: AuthConfig;
|
|
148
|
+
compressBody?: RequestEncoding;
|
|
237
149
|
}
|
|
238
150
|
//# sourceMappingURL=request.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/core/request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAChE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/core/request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAChE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CA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AQ,CAAC,EAAE,OAAO,CAAC;IACnB,WAAW,CAAC,EAAE,KAAK,GAAG,GAAG,GAAG,GAAG,CAAC;IAChC,SAAS,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAAC;IACzC,KAAK,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;IAC7B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,SAAS,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,UAAU,CAAC;IAEjB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC,kBAAkB,CAAC,EAAE,gBAAgB,CAAC;IAEtC,WAAW,CAAC,EAAE,WAAW,CAAC;IAE1B,IAAI,CAAC,EAAE,UAAU,CAAC;IAElB,GAAG,CAAC,EAAE,SAAS,CAAC;IAEhB,GAAG,CAAC,EAAE,UAAU,CAAC;IAEjB,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB,IAAI,CAAC,EAAE,UAAU,CAAC;IAElB,YAAY,CAAC,EAAE,eAAe,CAAC;CAChC"}
|
package/dist/core/response.d.ts
CHANGED
|
@@ -1,67 +1,53 @@
|
|
|
1
1
|
import type { RequestTimings, HttpMethod } from "./request.js";
|
|
2
2
|
import type { Readable } from "node:stream";
|
|
3
3
|
/**
|
|
4
|
-
* Metadata about the
|
|
5
|
-
*
|
|
6
|
-
* @typedef {Object} ResponseMeta
|
|
7
|
-
* @property {string} url - The final URL after all redirects.
|
|
8
|
-
* @property {HttpMethod} method - The HTTP method used for the request.
|
|
9
|
-
* @property {Record<string,string>} headers - The request headers that were sent.
|
|
10
|
-
* @property {string} [command] - An optional cURL-equivalent command string for debugging.
|
|
4
|
+
* Metadata about the request that produced a given response.
|
|
11
5
|
*/
|
|
12
6
|
export interface ResponseMeta {
|
|
13
7
|
url: string;
|
|
14
8
|
method: HttpMethod;
|
|
15
9
|
headers: Record<string, string>;
|
|
16
10
|
command?: string;
|
|
11
|
+
tlsVersion?: string;
|
|
12
|
+
tlsCipher?: string;
|
|
13
|
+
alpnProtocol?: string;
|
|
17
14
|
}
|
|
18
15
|
/**
|
|
19
|
-
*
|
|
20
|
-
* convenience accessors for common
|
|
21
|
-
* header inspection.
|
|
16
|
+
* Encapsulates an HTTP response with status, headers, body, timing data,
|
|
17
|
+
* and convenience accessors for common header values and body parsing.
|
|
22
18
|
*
|
|
23
|
-
* @
|
|
19
|
+
* @class
|
|
20
|
+
* @template T - The expected JSON body type.
|
|
24
21
|
*/
|
|
25
22
|
export declare class NLcURLResponse<T = unknown> {
|
|
26
|
-
/** HTTP status code
|
|
23
|
+
/** The HTTP status code. */
|
|
27
24
|
readonly status: number;
|
|
28
|
-
/** HTTP
|
|
25
|
+
/** The HTTP reason phrase. */
|
|
29
26
|
readonly statusText: string;
|
|
30
|
-
/**
|
|
27
|
+
/** Response headers as a case-insensitive key-value map. */
|
|
31
28
|
readonly headers: Record<string, string>;
|
|
32
|
-
/**
|
|
29
|
+
/** Raw header pairs preserving original casing and duplicates. */
|
|
33
30
|
readonly rawHeaders: Array<[string, string]>;
|
|
34
|
-
/**
|
|
31
|
+
/** The full response body as a Buffer. */
|
|
35
32
|
readonly rawBody: Buffer;
|
|
36
|
-
/**
|
|
33
|
+
/** A readable stream for streaming responses, or `null` for buffered responses. */
|
|
37
34
|
readonly body: Readable | null;
|
|
38
|
-
/** HTTP
|
|
35
|
+
/** The negotiated HTTP version (e.g. "1.1", "2"). */
|
|
39
36
|
readonly httpVersion: string;
|
|
40
|
-
/**
|
|
37
|
+
/** The final URL after any redirects. */
|
|
41
38
|
readonly url: string;
|
|
42
|
-
/**
|
|
39
|
+
/** The number of redirects followed to reach this response. */
|
|
43
40
|
readonly redirectCount: number;
|
|
44
|
-
/**
|
|
41
|
+
/** Timing measurements for each request phase. */
|
|
45
42
|
readonly timings: RequestTimings;
|
|
46
43
|
/** Metadata about the originating request. */
|
|
47
44
|
readonly request: ResponseMeta;
|
|
48
45
|
private _json;
|
|
49
46
|
private _text;
|
|
50
47
|
/**
|
|
51
|
-
* Creates a new NLcURLResponse
|
|
48
|
+
* Creates a new NLcURLResponse from the provided initialization fields.
|
|
52
49
|
*
|
|
53
|
-
* @param {Object}
|
|
54
|
-
* @param {number} init.status - HTTP status code.
|
|
55
|
-
* @param {string} init.statusText - HTTP status text.
|
|
56
|
-
* @param {Record<string,string>} init.headers - Normalized response headers.
|
|
57
|
-
* @param {Array<[string,string]>} [init.rawHeaders] - Raw header pairs; defaults to entries of `headers`.
|
|
58
|
-
* @param {Buffer} init.rawBody - Fully buffered response body.
|
|
59
|
-
* @param {Readable|null} [init.body] - Streaming body, or `null`.
|
|
60
|
-
* @param {string} init.httpVersion - Protocol version string.
|
|
61
|
-
* @param {string} init.url - Final URL after redirects.
|
|
62
|
-
* @param {number} init.redirectCount - Number of redirects followed.
|
|
63
|
-
* @param {RequestTimings} init.timings - Lifecycle timing measurements.
|
|
64
|
-
* @param {ResponseMeta} init.request - Originating request metadata.
|
|
50
|
+
* @param {Object} init - Response initialization fields.
|
|
65
51
|
*/
|
|
66
52
|
constructor(init: {
|
|
67
53
|
status: number;
|
|
@@ -77,77 +63,74 @@ export declare class NLcURLResponse<T = unknown> {
|
|
|
77
63
|
request: ResponseMeta;
|
|
78
64
|
});
|
|
79
65
|
/**
|
|
80
|
-
* Returns `true`
|
|
81
|
-
* range, `false` otherwise.
|
|
66
|
+
* Returns `true` if the response status is in the 2xx range.
|
|
82
67
|
*
|
|
83
68
|
* @returns {boolean} Whether the response indicates success.
|
|
84
69
|
*/
|
|
85
70
|
get ok(): boolean;
|
|
86
71
|
/**
|
|
87
|
-
* Decodes the raw body as a UTF-8 string
|
|
88
|
-
* memoized after the first call.
|
|
72
|
+
* Decodes the raw body as a UTF-8 string. Throws if the response is streaming.
|
|
89
73
|
*
|
|
90
|
-
* @returns {string} The response body
|
|
91
|
-
* @throws {Error} If the response
|
|
74
|
+
* @returns {string} The response body as text.
|
|
75
|
+
* @throws {Error} If the response is a streaming response.
|
|
92
76
|
*/
|
|
93
77
|
text(): string;
|
|
94
78
|
/**
|
|
95
|
-
* Parses the
|
|
96
|
-
* memoized after the first call.
|
|
79
|
+
* Parses the response body as JSON. Throws if the response is streaming.
|
|
97
80
|
*
|
|
98
|
-
* @template R -
|
|
99
|
-
* @returns {R} The JSON
|
|
100
|
-
* @throws {Error} If the response
|
|
81
|
+
* @template R - The expected parsed type.
|
|
82
|
+
* @returns {R} The parsed JSON value.
|
|
83
|
+
* @throws {Error} If the response is a streaming response.
|
|
101
84
|
* @throws {SyntaxError} If the body is not valid JSON.
|
|
102
|
-
*
|
|
103
|
-
* @example
|
|
104
|
-
* const data = response.json<{ id: number; name: string }>();
|
|
105
|
-
* console.log(data.id);
|
|
106
85
|
*/
|
|
107
86
|
json<R = T>(): R;
|
|
108
87
|
/**
|
|
109
|
-
* Returns the
|
|
110
|
-
* length when the header is absent or unparseable.
|
|
88
|
+
* Returns the Content-Length header value, or the raw body length as a fallback.
|
|
111
89
|
*
|
|
112
90
|
* @returns {number} The content length in bytes.
|
|
113
91
|
*/
|
|
114
92
|
get contentLength(): number;
|
|
115
93
|
/**
|
|
116
|
-
* Returns the
|
|
117
|
-
* string when the header is absent.
|
|
94
|
+
* Returns the Content-Type header value.
|
|
118
95
|
*
|
|
119
|
-
* @returns {string} The
|
|
96
|
+
* @returns {string} The content type, or an empty string if absent.
|
|
120
97
|
*/
|
|
121
98
|
get contentType(): string;
|
|
122
99
|
/**
|
|
123
|
-
* Returns the
|
|
100
|
+
* Returns the ETag header value, if present.
|
|
101
|
+
*
|
|
102
|
+
* @returns {string|undefined} The entity tag.
|
|
124
103
|
*/
|
|
125
104
|
get etag(): string | undefined;
|
|
126
105
|
/**
|
|
127
|
-
* Returns the
|
|
106
|
+
* Returns the Last-Modified header value, if present.
|
|
107
|
+
*
|
|
108
|
+
* @returns {string|undefined} The last modified date string.
|
|
128
109
|
*/
|
|
129
110
|
get lastModified(): string | undefined;
|
|
130
111
|
/**
|
|
131
|
-
* Returns the
|
|
112
|
+
* Returns the Cache-Control header value, if present.
|
|
113
|
+
*
|
|
114
|
+
* @returns {string|undefined} The cache control directive string.
|
|
132
115
|
*/
|
|
133
116
|
get cacheControl(): string | undefined;
|
|
134
117
|
/**
|
|
135
|
-
* Returns the
|
|
136
|
-
*
|
|
118
|
+
* Returns the Content-Range header value, if present.
|
|
119
|
+
*
|
|
120
|
+
* @returns {string|undefined} The content range descriptor.
|
|
137
121
|
*/
|
|
138
122
|
get contentRange(): string | undefined;
|
|
139
123
|
/**
|
|
140
|
-
* Returns the
|
|
141
|
-
*
|
|
124
|
+
* Returns the Accept-Ranges header value, if present.
|
|
125
|
+
*
|
|
126
|
+
* @returns {string|undefined} The accepted range unit.
|
|
142
127
|
*/
|
|
143
128
|
get acceptRanges(): string | undefined;
|
|
144
129
|
/**
|
|
145
|
-
*
|
|
146
|
-
* supporting multi-value headers such as `Set-Cookie` which are joined
|
|
147
|
-
* when accessed through `headers`.
|
|
130
|
+
* Retrieves all values for a given header name from the raw headers array.
|
|
148
131
|
*
|
|
149
|
-
* @param {string} name - The
|
|
150
|
-
* @returns {string[]} All
|
|
132
|
+
* @param {string} name - The header name (case-insensitive).
|
|
133
|
+
* @returns {string[]} All values for the specified header.
|
|
151
134
|
*/
|
|
152
135
|
getAll(name: string): string[];
|
|
153
136
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../../src/core/response.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C
|
|
1
|
+
{"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../../src/core/response.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAA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EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAAC,UAAU,CAAC,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAC;QAAC,WAAW,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,cAAc,CAAC;QAAC,OAAO,EAAE,YAAY,CAAA;KAAE;IAcjR;;;;OAIG;IACH,IAAI,EAAE,IAAI,OAAO,CAEhB;IAED;;;;;OAKG;IACH,IAAI,IAAI,MAAM;IAYd;;;;;;;OAOG;IACH,IAAI,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC;IAUhB;;;;OAIG;IACH,IAAI,aAAa,IAAI,MAAM,CAO1B;IAED;;;;OAIG;IACH,IAAI,WAAW,IAAI,MAAM,CAExB;IAED;;;;OAIG;IACH,IAAI,IAAI,IAAI,MAAM,GAAG,SAAS,CAE7B;IAED;;;;OAIG;IACH,IAAI,YAAY,IAAI,MAAM,GAAG,SAAS,CAErC;IAED;;;;OAIG;IACH,IAAI,YAAY,IAAI,MAAM,GAAG,SAAS,CAErC;IAED;;;;OAIG;IACH,IAAI,YAAY,IAAI,MAAM,GAAG,SAAS,CAErC;IAED;;;;OAIG;IACH,IAAI,YAAY,IAAI,MAAM,GAAG,SAAS,CAErC;IAED;;;;;OAKG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE;CAI/B"}
|
package/dist/core/response.js
CHANGED
|
@@ -1,50 +1,39 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* convenience accessors for common
|
|
4
|
-
* header inspection.
|
|
2
|
+
* Encapsulates an HTTP response with status, headers, body, timing data,
|
|
3
|
+
* and convenience accessors for common header values and body parsing.
|
|
5
4
|
*
|
|
6
|
-
* @
|
|
5
|
+
* @class
|
|
6
|
+
* @template T - The expected JSON body type.
|
|
7
7
|
*/
|
|
8
8
|
export class NLcURLResponse {
|
|
9
|
-
/** HTTP status code
|
|
9
|
+
/** The HTTP status code. */
|
|
10
10
|
status;
|
|
11
|
-
/** HTTP
|
|
11
|
+
/** The HTTP reason phrase. */
|
|
12
12
|
statusText;
|
|
13
|
-
/**
|
|
13
|
+
/** Response headers as a case-insensitive key-value map. */
|
|
14
14
|
headers;
|
|
15
|
-
/**
|
|
15
|
+
/** Raw header pairs preserving original casing and duplicates. */
|
|
16
16
|
rawHeaders;
|
|
17
|
-
/**
|
|
17
|
+
/** The full response body as a Buffer. */
|
|
18
18
|
rawBody;
|
|
19
|
-
/**
|
|
19
|
+
/** A readable stream for streaming responses, or `null` for buffered responses. */
|
|
20
20
|
body;
|
|
21
|
-
/** HTTP
|
|
21
|
+
/** The negotiated HTTP version (e.g. "1.1", "2"). */
|
|
22
22
|
httpVersion;
|
|
23
|
-
/**
|
|
23
|
+
/** The final URL after any redirects. */
|
|
24
24
|
url;
|
|
25
|
-
/**
|
|
25
|
+
/** The number of redirects followed to reach this response. */
|
|
26
26
|
redirectCount;
|
|
27
|
-
/**
|
|
27
|
+
/** Timing measurements for each request phase. */
|
|
28
28
|
timings;
|
|
29
29
|
/** Metadata about the originating request. */
|
|
30
30
|
request;
|
|
31
31
|
_json;
|
|
32
32
|
_text;
|
|
33
33
|
/**
|
|
34
|
-
* Creates a new NLcURLResponse
|
|
34
|
+
* Creates a new NLcURLResponse from the provided initialization fields.
|
|
35
35
|
*
|
|
36
|
-
* @param {Object}
|
|
37
|
-
* @param {number} init.status - HTTP status code.
|
|
38
|
-
* @param {string} init.statusText - HTTP status text.
|
|
39
|
-
* @param {Record<string,string>} init.headers - Normalized response headers.
|
|
40
|
-
* @param {Array<[string,string]>} [init.rawHeaders] - Raw header pairs; defaults to entries of `headers`.
|
|
41
|
-
* @param {Buffer} init.rawBody - Fully buffered response body.
|
|
42
|
-
* @param {Readable|null} [init.body] - Streaming body, or `null`.
|
|
43
|
-
* @param {string} init.httpVersion - Protocol version string.
|
|
44
|
-
* @param {string} init.url - Final URL after redirects.
|
|
45
|
-
* @param {number} init.redirectCount - Number of redirects followed.
|
|
46
|
-
* @param {RequestTimings} init.timings - Lifecycle timing measurements.
|
|
47
|
-
* @param {ResponseMeta} init.request - Originating request metadata.
|
|
36
|
+
* @param {Object} init - Response initialization fields.
|
|
48
37
|
*/
|
|
49
38
|
constructor(init) {
|
|
50
39
|
this.status = init.status;
|
|
@@ -60,8 +49,7 @@ export class NLcURLResponse {
|
|
|
60
49
|
this.request = init.request;
|
|
61
50
|
}
|
|
62
51
|
/**
|
|
63
|
-
* Returns `true`
|
|
64
|
-
* range, `false` otherwise.
|
|
52
|
+
* Returns `true` if the response status is in the 2xx range.
|
|
65
53
|
*
|
|
66
54
|
* @returns {boolean} Whether the response indicates success.
|
|
67
55
|
*/
|
|
@@ -69,11 +57,10 @@ export class NLcURLResponse {
|
|
|
69
57
|
return this.status >= 200 && this.status < 300;
|
|
70
58
|
}
|
|
71
59
|
/**
|
|
72
|
-
* Decodes the raw body as a UTF-8 string
|
|
73
|
-
* memoized after the first call.
|
|
60
|
+
* Decodes the raw body as a UTF-8 string. Throws if the response is streaming.
|
|
74
61
|
*
|
|
75
|
-
* @returns {string} The response body
|
|
76
|
-
* @throws {Error} If the response
|
|
62
|
+
* @returns {string} The response body as text.
|
|
63
|
+
* @throws {Error} If the response is a streaming response.
|
|
77
64
|
*/
|
|
78
65
|
text() {
|
|
79
66
|
if (this.body) {
|
|
@@ -87,17 +74,12 @@ export class NLcURLResponse {
|
|
|
87
74
|
return cached;
|
|
88
75
|
}
|
|
89
76
|
/**
|
|
90
|
-
* Parses the
|
|
91
|
-
* memoized after the first call.
|
|
77
|
+
* Parses the response body as JSON. Throws if the response is streaming.
|
|
92
78
|
*
|
|
93
|
-
* @template R -
|
|
94
|
-
* @returns {R} The JSON
|
|
95
|
-
* @throws {Error} If the response
|
|
79
|
+
* @template R - The expected parsed type.
|
|
80
|
+
* @returns {R} The parsed JSON value.
|
|
81
|
+
* @throws {Error} If the response is a streaming response.
|
|
96
82
|
* @throws {SyntaxError} If the body is not valid JSON.
|
|
97
|
-
*
|
|
98
|
-
* @example
|
|
99
|
-
* const data = response.json<{ id: number; name: string }>();
|
|
100
|
-
* console.log(data.id);
|
|
101
83
|
*/
|
|
102
84
|
json() {
|
|
103
85
|
if (this.body) {
|
|
@@ -109,8 +91,7 @@ export class NLcURLResponse {
|
|
|
109
91
|
return this._json;
|
|
110
92
|
}
|
|
111
93
|
/**
|
|
112
|
-
* Returns the
|
|
113
|
-
* length when the header is absent or unparseable.
|
|
94
|
+
* Returns the Content-Length header value, or the raw body length as a fallback.
|
|
114
95
|
*
|
|
115
96
|
* @returns {number} The content length in bytes.
|
|
116
97
|
*/
|
|
@@ -124,53 +105,58 @@ export class NLcURLResponse {
|
|
|
124
105
|
return this.rawBody.length;
|
|
125
106
|
}
|
|
126
107
|
/**
|
|
127
|
-
* Returns the
|
|
128
|
-
* string when the header is absent.
|
|
108
|
+
* Returns the Content-Type header value.
|
|
129
109
|
*
|
|
130
|
-
* @returns {string} The
|
|
110
|
+
* @returns {string} The content type, or an empty string if absent.
|
|
131
111
|
*/
|
|
132
112
|
get contentType() {
|
|
133
113
|
return this.headers["content-type"] ?? "";
|
|
134
114
|
}
|
|
135
115
|
/**
|
|
136
|
-
* Returns the
|
|
116
|
+
* Returns the ETag header value, if present.
|
|
117
|
+
*
|
|
118
|
+
* @returns {string|undefined} The entity tag.
|
|
137
119
|
*/
|
|
138
120
|
get etag() {
|
|
139
121
|
return this.headers["etag"];
|
|
140
122
|
}
|
|
141
123
|
/**
|
|
142
|
-
* Returns the
|
|
124
|
+
* Returns the Last-Modified header value, if present.
|
|
125
|
+
*
|
|
126
|
+
* @returns {string|undefined} The last modified date string.
|
|
143
127
|
*/
|
|
144
128
|
get lastModified() {
|
|
145
129
|
return this.headers["last-modified"];
|
|
146
130
|
}
|
|
147
131
|
/**
|
|
148
|
-
* Returns the
|
|
132
|
+
* Returns the Cache-Control header value, if present.
|
|
133
|
+
*
|
|
134
|
+
* @returns {string|undefined} The cache control directive string.
|
|
149
135
|
*/
|
|
150
136
|
get cacheControl() {
|
|
151
137
|
return this.headers["cache-control"];
|
|
152
138
|
}
|
|
153
139
|
/**
|
|
154
|
-
* Returns the
|
|
155
|
-
*
|
|
140
|
+
* Returns the Content-Range header value, if present.
|
|
141
|
+
*
|
|
142
|
+
* @returns {string|undefined} The content range descriptor.
|
|
156
143
|
*/
|
|
157
144
|
get contentRange() {
|
|
158
145
|
return this.headers["content-range"];
|
|
159
146
|
}
|
|
160
147
|
/**
|
|
161
|
-
* Returns the
|
|
162
|
-
*
|
|
148
|
+
* Returns the Accept-Ranges header value, if present.
|
|
149
|
+
*
|
|
150
|
+
* @returns {string|undefined} The accepted range unit.
|
|
163
151
|
*/
|
|
164
152
|
get acceptRanges() {
|
|
165
153
|
return this.headers["accept-ranges"];
|
|
166
154
|
}
|
|
167
155
|
/**
|
|
168
|
-
*
|
|
169
|
-
* supporting multi-value headers such as `Set-Cookie` which are joined
|
|
170
|
-
* when accessed through `headers`.
|
|
156
|
+
* Retrieves all values for a given header name from the raw headers array.
|
|
171
157
|
*
|
|
172
|
-
* @param {string} name - The
|
|
173
|
-
* @returns {string[]} All
|
|
158
|
+
* @param {string} name - The header name (case-insensitive).
|
|
159
|
+
* @returns {string[]} All values for the specified header.
|
|
174
160
|
*/
|
|
175
161
|
getAll(name) {
|
|
176
162
|
const lower = name.toLowerCase();
|