nlcurl 0.6.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 +111 -0
- package/dist/cache/store.d.ts.map +1 -0
- package/dist/cache/store.js +414 -0
- package/dist/cache/store.js.map +1 -0
- package/dist/cache/types.d.ts +69 -0
- package/dist/cache/types.d.ts.map +1 -0
- package/dist/cache/types.js +2 -0
- package/dist/cache/types.js.map +1 -0
- 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 +33 -31
- package/dist/cookies/jar.d.ts.map +1 -1
- package/dist/cookies/jar.js +69 -33
- package/dist/cookies/jar.js.map +1 -1
- package/dist/cookies/parser.d.ts +14 -16
- package/dist/cookies/parser.d.ts.map +1 -1
- package/dist/cookies/parser.js +30 -13
- 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 +34 -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 +63 -85
- package/dist/core/request.d.ts.map +1 -1
- package/dist/core/response.d.ts +64 -59
- package/dist/core/response.d.ts.map +1 -1
- package/dist/core/response.js +70 -52
- package/dist/core/response.js.map +1 -1
- package/dist/core/session.d.ts +81 -70
- package/dist/core/session.d.ts.map +1 -1
- package/dist/core/session.js +198 -71
- package/dist/core/session.js.map +1 -1
- package/dist/core/validation.d.ts +44 -42
- package/dist/core/validation.d.ts.map +1 -1
- package/dist/core/validation.js +47 -58
- 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 +39 -0
- package/dist/dns/codec.d.ts.map +1 -0
- package/dist/dns/codec.js +238 -0
- package/dist/dns/codec.js.map +1 -0
- package/dist/dns/doh-resolver.d.ts +38 -0
- package/dist/dns/doh-resolver.d.ts.map +1 -0
- package/dist/dns/doh-resolver.js +191 -0
- package/dist/dns/doh-resolver.js.map +1 -0
- 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 +40 -0
- package/dist/dns/https-rr.d.ts.map +1 -0
- package/dist/dns/https-rr.js +109 -0
- package/dist/dns/https-rr.js.map +1 -0
- package/dist/dns/types.d.ts +82 -0
- package/dist/dns/types.d.ts.map +1 -0
- package/dist/dns/types.js +23 -0
- package/dist/dns/types.js.map +1 -0
- 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 +39 -0
- package/dist/hsts/store.d.ts.map +1 -0
- package/dist/hsts/store.js +163 -0
- package/dist/hsts/store.js.map +1 -0
- package/dist/hsts/types.d.ts +24 -0
- package/dist/hsts/types.d.ts.map +1 -0
- package/dist/hsts/types.js +2 -0
- package/dist/hsts/types.js.map +1 -0
- package/dist/http/alt-svc.d.ts +67 -0
- package/dist/http/alt-svc.d.ts.map +1 -0
- package/dist/http/alt-svc.js +186 -0
- package/dist/http/alt-svc.js.map +1 -0
- 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 +29 -22
- 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 +15 -0
- package/dist/http/h3/detection.d.ts.map +1 -0
- package/dist/http/h3/detection.js +41 -0
- package/dist/http/h3/detection.js.map +1 -0
- package/dist/http/negotiator.d.ts +43 -33
- package/dist/http/negotiator.d.ts.map +1 -1
- package/dist/http/negotiator.js +99 -41
- package/dist/http/negotiator.js.map +1 -1
- package/dist/http/pool.d.ts +34 -64
- 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 +36 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +32 -1
- 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 +15 -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 +11 -0
- package/dist/proxy/env-proxy.d.ts.map +1 -0
- package/dist/proxy/env-proxy.js +56 -0
- package/dist/proxy/env-proxy.js.map +1 -0
- package/dist/proxy/http-proxy.d.ts +13 -18
- package/dist/proxy/http-proxy.d.ts.map +1 -1
- package/dist/proxy/http-proxy.js +24 -14
- 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 +6 -9
- package/dist/proxy/socks.js.map +1 -1
- package/dist/sse/parser.d.ts +47 -0
- package/dist/sse/parser.d.ts.map +1 -0
- package/dist/sse/parser.js +139 -0
- package/dist/sse/parser.js.map +1 -0
- 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 +130 -0
- package/dist/tls/ech.d.ts.map +1 -0
- package/dist/tls/ech.js +353 -0
- package/dist/tls/ech.js.map +1 -0
- 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 +15 -14
- package/dist/tls/node-engine.d.ts.map +1 -1
- package/dist/tls/node-engine.js +54 -14
- 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 +10 -0
- package/dist/tls/pin-verification.d.ts.map +1 -0
- package/dist/tls/pin-verification.js +28 -0
- package/dist/tls/pin-verification.js.map +1 -0
- package/dist/tls/session-cache.d.ts +58 -0
- package/dist/tls/session-cache.d.ts.map +1 -0
- package/dist/tls/session-cache.js +76 -0
- package/dist/tls/session-cache.js.map +1 -0
- package/dist/tls/stealth/client-hello.d.ts +34 -32
- package/dist/tls/stealth/client-hello.d.ts.map +1 -1
- package/dist/tls/stealth/client-hello.js +116 -11
- 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 +163 -47
- package/dist/tls/stealth/engine.js.map +1 -1
- package/dist/tls/stealth/handshake.d.ts +23 -32
- package/dist/tls/stealth/handshake.d.ts.map +1 -1
- package/dist/tls/stealth/handshake.js +112 -27
- 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 +30 -0
- package/dist/tls/stealth/tls12-handshake.d.ts.map +1 -0
- package/dist/tls/stealth/tls12-handshake.js +470 -0
- package/dist/tls/stealth/tls12-handshake.js.map +1 -0
- package/dist/tls/types.d.ts +46 -48
- 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 -28
- package/dist/utils/encoding.d.ts.map +1 -1
- package/dist/utils/encoding.js +77 -40
- package/dist/utils/encoding.js.map +1 -1
- package/dist/utils/happy-eyeballs.d.ts +20 -7
- package/dist/utils/happy-eyeballs.d.ts.map +1 -1
- package/dist/utils/happy-eyeballs.js +57 -25
- 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 +35 -52
- package/dist/ws/client.d.ts.map +1 -1
- package/dist/ws/client.js +92 -37
- package/dist/ws/client.js.map +1 -1
- package/dist/ws/frame.d.ts +27 -42
- package/dist/ws/frame.d.ts.map +1 -1
- package/dist/ws/frame.js +25 -37
- package/dist/ws/frame.js.map +1 -1
- package/dist/ws/permessage-deflate.d.ts +53 -0
- package/dist/ws/permessage-deflate.d.ts.map +1 -0
- package/dist/ws/permessage-deflate.js +140 -0
- package/dist/ws/permessage-deflate.js.map +1 -0
- package/package.json +62 -62
package/dist/cookies/parser.js
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
import { isPublicSuffix } from "./public-suffix.js";
|
|
2
|
-
/**
|
|
3
|
-
* Parses a `Set-Cookie` header value into a {@link Cookie} object.
|
|
4
|
-
* Validates the cookie against the request URL to enforce domain and path
|
|
5
|
-
* scoping rules per RFC 6265.
|
|
6
|
-
*
|
|
7
|
-
* @param {string} header - Raw `Set-Cookie` header value.
|
|
8
|
-
* @param {URL} requestUrl - URL of the request that received the header.
|
|
9
|
-
* @returns {Cookie | null} Parsed cookie, or `null` if the header is invalid or
|
|
10
|
-
* the domain attribute fails validation against the request origin.
|
|
11
|
-
*/
|
|
12
2
|
const COOKIE_NAME_RE = /^[!#$%&'*+\-.^_`|~\w]+$/;
|
|
13
3
|
const COOKIE_VALUE_CTL_RE = /[\x00-\x1f\x7f]/;
|
|
14
4
|
const MAX_COOKIE_SIZE = 4096;
|
|
15
5
|
const VALID_SAMESITE = new Set(["strict", "lax", "none"]);
|
|
6
|
+
function looksLikeIP(host) {
|
|
7
|
+
if (host.includes(":"))
|
|
8
|
+
return true;
|
|
9
|
+
const parts = host.split(".");
|
|
10
|
+
return parts.length === 4 && parts.every((p) => /^\d{1,3}$/.test(p));
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Parses a Set-Cookie response header into a Cookie object, enforcing
|
|
14
|
+
* __Host- / __Secure- prefix rules, public suffix rejection, and SameSite defaults.
|
|
15
|
+
*
|
|
16
|
+
* @param {string} header - The raw Set-Cookie header value.
|
|
17
|
+
* @param {URL} requestUrl - The URL of the originating request.
|
|
18
|
+
* @returns {Cookie|null} The parsed cookie, or `null` if validation fails.
|
|
19
|
+
*/
|
|
16
20
|
export function parseSetCookie(header, requestUrl) {
|
|
17
21
|
const parts = header.split(";").map((s) => s.trim());
|
|
18
22
|
if (parts.length === 0)
|
|
@@ -39,6 +43,7 @@ export function parseSetCookie(header, requestUrl) {
|
|
|
39
43
|
secure: false,
|
|
40
44
|
httpOnly: false,
|
|
41
45
|
createdAt: Date.now(),
|
|
46
|
+
lastAccessedAt: Date.now(),
|
|
42
47
|
};
|
|
43
48
|
for (let i = 1; i < parts.length; i++) {
|
|
44
49
|
const attr = parts[i];
|
|
@@ -51,6 +56,12 @@ export function parseSetCookie(header, requestUrl) {
|
|
|
51
56
|
if (d.startsWith("."))
|
|
52
57
|
d = d.substring(1);
|
|
53
58
|
const host = requestUrl.hostname.toLowerCase();
|
|
59
|
+
if (looksLikeIP(d) || looksLikeIP(host)) {
|
|
60
|
+
if (d !== host)
|
|
61
|
+
return null;
|
|
62
|
+
cookie.domain = d;
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
54
65
|
if (d !== host && !host.endsWith("." + d)) {
|
|
55
66
|
return null;
|
|
56
67
|
}
|
|
@@ -90,6 +101,9 @@ export function parseSetCookie(header, requestUrl) {
|
|
|
90
101
|
}
|
|
91
102
|
break;
|
|
92
103
|
}
|
|
104
|
+
case "partitioned":
|
|
105
|
+
cookie.partitioned = true;
|
|
106
|
+
break;
|
|
93
107
|
}
|
|
94
108
|
}
|
|
95
109
|
if (cookie.sameSite === undefined) {
|
|
@@ -107,6 +121,9 @@ export function parseSetCookie(header, requestUrl) {
|
|
|
107
121
|
if (!cookie.secure)
|
|
108
122
|
return null;
|
|
109
123
|
}
|
|
124
|
+
if (cookie.partitioned && !cookie.secure) {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
110
127
|
return cookie;
|
|
111
128
|
}
|
|
112
129
|
function defaultPath(path) {
|
|
@@ -118,10 +135,10 @@ function defaultPath(path) {
|
|
|
118
135
|
return path.substring(0, lastSlash);
|
|
119
136
|
}
|
|
120
137
|
/**
|
|
121
|
-
* Serializes an array of cookies into
|
|
138
|
+
* Serializes an array of cookies into a Cookie header value string.
|
|
122
139
|
*
|
|
123
|
-
* @param {Cookie[]} cookies -
|
|
124
|
-
* @returns {string}
|
|
140
|
+
* @param {Cookie[]} cookies - The cookies to serialize.
|
|
141
|
+
* @returns {string} The serialized "name=value; name=value" string.
|
|
125
142
|
*/
|
|
126
143
|
export function serializeCookies(cookies) {
|
|
127
144
|
return cookies.map((c) => `${c.name}=${c.value}`).join("; ");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../../src/cookies/parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../../src/cookies/parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAoBpD,MAAM,cAAc,GAAG,yBAAyB,CAAC;AACjD,MAAM,mBAAmB,GAAG,iBAAiB,CAAC;AAC9C,MAAM,eAAe,GAAG,IAAI,CAAC;AAE7B,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;AAE1D,SAAS,WAAW,CAAC,IAAY;IAC/B,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IACpC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC9B,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AACvE,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,cAAc,C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
|
*
|
|
4
4
|
* Complete Mozilla Public Suffix List rules.
|
|
5
5
|
* Generated from: https://publicsuffix.org/list/public_suffix_list.dat
|
|
6
|
-
* Generated on: 2026-03-
|
|
6
|
+
* Generated on: 2026-03-08T17:47:36.443Z
|
|
7
7
|
* Total rules: 10153
|
|
8
8
|
*
|
|
9
9
|
* To regenerate: npx tsx scripts/update-psl.ts
|
package/dist/cookies/psl-data.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Complete Mozilla Public Suffix List rules.
|
|
5
5
|
* Generated from: https://publicsuffix.org/list/public_suffix_list.dat
|
|
6
|
-
* Generated on: 2026-03-
|
|
6
|
+
* Generated on: 2026-03-08T17:47:36.443Z
|
|
7
7
|
* Total rules: 10153
|
|
8
8
|
*
|
|
9
9
|
* To regenerate: npx tsx scripts/update-psl.ts
|
|
@@ -1,37 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* Uses the complete Mozilla Public Suffix List (10,000+ rules) to prevent
|
|
4
|
-
* supercookie attacks across all registered TLDs, ccSLDs, and hosting platforms.
|
|
2
|
+
* Determines whether a domain is a public suffix (eTLD) according to the Mozilla Public Suffix List.
|
|
5
3
|
*
|
|
6
|
-
*
|
|
7
|
-
* via `npx tsx scripts/update-psl.ts`. Regenerate periodically to stay current.
|
|
8
|
-
*
|
|
9
|
-
* Rules follow the PSL algorithm (https://wiki.mozilla.org/Public_Suffix_List/Algorithm):
|
|
10
|
-
* - A plain entry (e.g. `com`) means that label is a public suffix.
|
|
11
|
-
* - A wildcard entry (e.g. `*.uk`) means all two-label domains under `.uk` are suffixes.
|
|
12
|
-
* - An exception entry (e.g. `!www.ck`) overrides a wildcard and is NOT a suffix.
|
|
13
|
-
*/
|
|
14
|
-
/**
|
|
15
|
-
* Determines whether the given domain is a public suffix (effective TLD).
|
|
16
|
-
* A public suffix is a domain under which the general public can register
|
|
17
|
-
* names — e.g. `com`, `co.uk`, `github.io`.
|
|
18
|
-
*
|
|
19
|
-
* Cookies must never be set with a `domain` attribute equal to a public
|
|
20
|
-
* suffix, as that would create a supercookie affecting all sites under
|
|
21
|
-
* that suffix.
|
|
22
|
-
*
|
|
23
|
-
* @param {string} domain - The domain to check (lowercase, no trailing dot).
|
|
4
|
+
* @param {string} domain - The domain to check.
|
|
24
5
|
* @returns {boolean} `true` if the domain is a public suffix.
|
|
25
6
|
*/
|
|
26
7
|
export declare function isPublicSuffix(domain: string): boolean;
|
|
27
8
|
/**
|
|
28
|
-
*
|
|
29
|
-
* For example, `"www.example.co.uk"` → `"example.co.uk"`.
|
|
30
|
-
* Returns `null` if the domain is itself a public suffix or if
|
|
31
|
-
* the input is invalid.
|
|
9
|
+
* Extracts the registrable domain (eTLD+1) from a hostname using the Public Suffix List.
|
|
32
10
|
*
|
|
33
|
-
* @param {string} hostname -
|
|
34
|
-
* @returns {string
|
|
11
|
+
* @param {string} hostname - The full hostname.
|
|
12
|
+
* @returns {string|null} The registrable domain, or `null` if the hostname is itself a public suffix.
|
|
35
13
|
*/
|
|
36
14
|
export declare function getRegistrableDomain(hostname: string): string | null;
|
|
37
15
|
//# sourceMappingURL=public-suffix.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"public-suffix.d.ts","sourceRoot":"","sources":["../../src/cookies/public-suffix.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"public-suffix.d.ts","sourceRoot":"","sources":["../../src/cookies/public-suffix.ts"],"names":[],"mappings":"AAsGA;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAItD;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAapE"}
|
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Public Suffix List (PSL) implementation for cookie domain validation.
|
|
3
|
-
* Uses the complete Mozilla Public Suffix List (10,000+ rules) to prevent
|
|
4
|
-
* supercookie attacks across all registered TLDs, ccSLDs, and hosting platforms.
|
|
5
|
-
*
|
|
6
|
-
* The data is auto-generated from https://publicsuffix.org/list/public_suffix_list.dat
|
|
7
|
-
* via `npx tsx scripts/update-psl.ts`. Regenerate periodically to stay current.
|
|
8
|
-
*
|
|
9
|
-
* Rules follow the PSL algorithm (https://wiki.mozilla.org/Public_Suffix_List/Algorithm):
|
|
10
|
-
* - A plain entry (e.g. `com`) means that label is a public suffix.
|
|
11
|
-
* - A wildcard entry (e.g. `*.uk`) means all two-label domains under `.uk` are suffixes.
|
|
12
|
-
* - An exception entry (e.g. `!www.ck`) overrides a wildcard and is NOT a suffix.
|
|
13
|
-
*/
|
|
14
1
|
import { PSL_RULES } from "./psl-data.js";
|
|
15
2
|
function parseRule(raw) {
|
|
16
3
|
const isException = raw.startsWith("!");
|
|
@@ -57,16 +44,6 @@ for (const rule of RULES) {
|
|
|
57
44
|
node.isPublicSuffix = true;
|
|
58
45
|
}
|
|
59
46
|
}
|
|
60
|
-
/**
|
|
61
|
-
* Finds the number of labels in the effective TLD for a given domain,
|
|
62
|
-
* following the Mozilla PSL algorithm:
|
|
63
|
-
* 1. Walk the trie from right to left, tracking the longest matching rule.
|
|
64
|
-
* 2. Wildcards extend the eTLD by one label; exceptions retract it.
|
|
65
|
-
* 3. Default rule: if no rule matches, treat the rightmost label as the eTLD.
|
|
66
|
-
*
|
|
67
|
-
* @param {string} domain - Lowercase domain with labels separated by '.'.
|
|
68
|
-
* @returns {number} Number of labels (from the right) forming the eTLD.
|
|
69
|
-
*/
|
|
70
47
|
function findEffectiveTLDLength(domain) {
|
|
71
48
|
const labels = domain.split(".").reverse();
|
|
72
49
|
let node = ROOT;
|
|
@@ -101,15 +78,9 @@ function findEffectiveTLDLength(domain) {
|
|
|
101
78
|
return etldLabels;
|
|
102
79
|
}
|
|
103
80
|
/**
|
|
104
|
-
* Determines whether
|
|
105
|
-
* A public suffix is a domain under which the general public can register
|
|
106
|
-
* names — e.g. `com`, `co.uk`, `github.io`.
|
|
107
|
-
*
|
|
108
|
-
* Cookies must never be set with a `domain` attribute equal to a public
|
|
109
|
-
* suffix, as that would create a supercookie affecting all sites under
|
|
110
|
-
* that suffix.
|
|
81
|
+
* Determines whether a domain is a public suffix (eTLD) according to the Mozilla Public Suffix List.
|
|
111
82
|
*
|
|
112
|
-
* @param {string} domain - The domain to check
|
|
83
|
+
* @param {string} domain - The domain to check.
|
|
113
84
|
* @returns {boolean} `true` if the domain is a public suffix.
|
|
114
85
|
*/
|
|
115
86
|
export function isPublicSuffix(domain) {
|
|
@@ -118,13 +89,10 @@ export function isPublicSuffix(domain) {
|
|
|
118
89
|
return labels.length === findEffectiveTLDLength(d);
|
|
119
90
|
}
|
|
120
91
|
/**
|
|
121
|
-
*
|
|
122
|
-
* For example, `"www.example.co.uk"` → `"example.co.uk"`.
|
|
123
|
-
* Returns `null` if the domain is itself a public suffix or if
|
|
124
|
-
* the input is invalid.
|
|
92
|
+
* Extracts the registrable domain (eTLD+1) from a hostname using the Public Suffix List.
|
|
125
93
|
*
|
|
126
|
-
* @param {string} hostname -
|
|
127
|
-
* @returns {string
|
|
94
|
+
* @param {string} hostname - The full hostname.
|
|
95
|
+
* @returns {string|null} The registrable domain, or `null` if the hostname is itself a public suffix.
|
|
128
96
|
*/
|
|
129
97
|
export function getRegistrableDomain(hostname) {
|
|
130
98
|
const domain = hostname.toLowerCase();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"public-suffix.js","sourceRoot":"","sources":["../../src/cookies/public-suffix.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"public-suffix.js","sourceRoot":"","sources":["../../src/cookies/public-suffix.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAQ1C,SAAS,SAAS,CAAC,GAAW;IAC5B,MAAM,WAAW,GAAG,GAAG,CAAC,UAAU,CAAC,GAAG,CAA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AAC;QAAE,OAAO,IAAI,CAAC;IAEnC,MAAM,UAAU,GAAG,sBAAsB,CAAC,MAAM,CAAC,CAAC;IAElD,IAAI,MAAM,CAAC,MAAM,IAAI,UAAU,EAAE,CAAC;QAChC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,UAAU,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAChE,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration for HTTP authentication.
|
|
3
|
+
*
|
|
4
|
+
* @typedef {Object} AuthConfig
|
|
5
|
+
* @property {"basic"|"bearer"} type - The authentication scheme to use.
|
|
6
|
+
* @property {string} [username] - Username for Basic authentication.
|
|
7
|
+
* @property {string} [password] - Password for Basic authentication.
|
|
8
|
+
* @property {string} [token] - Bearer token for Bearer authentication.
|
|
9
|
+
*/
|
|
10
|
+
export interface AuthConfig {
|
|
11
|
+
type: "basic" | "bearer";
|
|
12
|
+
username?: string;
|
|
13
|
+
password?: string;
|
|
14
|
+
token?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Builds an HTTP Authorization header value from the given auth configuration.
|
|
18
|
+
*
|
|
19
|
+
* @param {AuthConfig} auth - The authentication configuration.
|
|
20
|
+
* @returns {string|undefined} The formatted Authorization header value, or `undefined` if credentials are incomplete.
|
|
21
|
+
*/
|
|
22
|
+
export declare function buildAuthHeader(auth: AuthConfig): string | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Extracts the authentication scheme name from a WWW-Authenticate or Proxy-Authenticate header.
|
|
25
|
+
*
|
|
26
|
+
* @param {string} header - The raw authenticate header value.
|
|
27
|
+
* @returns {string|undefined} The lowercase scheme name (e.g. "basic", "bearer"), or `undefined` if not parseable.
|
|
28
|
+
*/
|
|
29
|
+
export declare function parseAuthenticateScheme(header: string): string | undefined;
|
|
30
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/core/auth.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,OAAO,GAAG,QAAQ,CAAC;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,GAAG,SAAS,CAcpE;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAG1E"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds an HTTP Authorization header value from the given auth configuration.
|
|
3
|
+
*
|
|
4
|
+
* @param {AuthConfig} auth - The authentication configuration.
|
|
5
|
+
* @returns {string|undefined} The formatted Authorization header value, or `undefined` if credentials are incomplete.
|
|
6
|
+
*/
|
|
7
|
+
export function buildAuthHeader(auth) {
|
|
8
|
+
switch (auth.type) {
|
|
9
|
+
case "basic": {
|
|
10
|
+
if (!auth.username)
|
|
11
|
+
return undefined;
|
|
12
|
+
const credentials = `${auth.username}:${auth.password ?? ""}`;
|
|
13
|
+
return `Basic ${Buffer.from(credentials, "utf-8").toString("base64")}`;
|
|
14
|
+
}
|
|
15
|
+
case "bearer": {
|
|
16
|
+
if (!auth.token)
|
|
17
|
+
return undefined;
|
|
18
|
+
return `Bearer ${auth.token}`;
|
|
19
|
+
}
|
|
20
|
+
default:
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Extracts the authentication scheme name from a WWW-Authenticate or Proxy-Authenticate header.
|
|
26
|
+
*
|
|
27
|
+
* @param {string} header - The raw authenticate header value.
|
|
28
|
+
* @returns {string|undefined} The lowercase scheme name (e.g. "basic", "bearer"), or `undefined` if not parseable.
|
|
29
|
+
*/
|
|
30
|
+
export function parseAuthenticateScheme(header) {
|
|
31
|
+
const match = /^(\w+)\s/i.exec(header.trim());
|
|
32
|
+
return match ? match[1].toLowerCase() : undefined;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/core/auth.ts"],"names":[],"mappings":"AAgBA;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,IAAgB;IAC9C,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;QAClB,KAAK,OAAO,CAAC,CAAC,CAAC;YACb,IAAI,CAAC,IAAI,CAAC,QAAQ;gBAAE,OAAO,SAAS,CAAC;YACrC,MAAM,WAAW,GAAG,GAAG,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,QAAQ,IAAI,EAAE,EAAE,CAAC;YAC9D,OAAO,SAAS,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;QACzE,CAAC;QACD,KAAK,QAAQ,CAAC,CAAC,CAAC;YACd,IAAI,CAAC,IAAI,CAAC,KAAK;gBAAE,OAAO,SAAS,CAAC;YAClC,OAAO,UAAU,IAAI,CAAC,KAAK,EAAE,CAAC;QAChC,CAAC;QACD;YACE,OAAO,SAAS,CAAC;IACrB,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CAAC,MAAc;IACpD,MAAM,KAAK,GAAG,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;IAC9C,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAE,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AACrD,CAAC"}
|
package/dist/core/client.d.ts
CHANGED
|
@@ -2,92 +2,80 @@ import type { NLcURLRequest, NLcURLSessionConfig, RequestBody } from "./request.
|
|
|
2
2
|
import { NLcURLResponse } from "./response.js";
|
|
3
3
|
import { NLcURLSession, type RequestOptions } from "./session.js";
|
|
4
4
|
/**
|
|
5
|
-
* Creates a new
|
|
6
|
-
*
|
|
7
|
-
* across multiple requests. Call {@link NLcURLSession.close} when finished.
|
|
5
|
+
* Creates a new session with optional configuration for connection reuse,
|
|
6
|
+
* cookie persistence, caching, and other session-level features.
|
|
8
7
|
*
|
|
9
|
-
* @param {NLcURLSessionConfig} [config] - Session
|
|
8
|
+
* @param {NLcURLSessionConfig} [config] - Session configuration options.
|
|
10
9
|
* @returns {NLcURLSession} A new session instance.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* const session = createSession({ impersonate: 'chrome136' });
|
|
14
|
-
* const r = await session.get('https://example.com');
|
|
15
|
-
* session.close();
|
|
16
10
|
*/
|
|
17
11
|
export declare function createSession(config?: NLcURLSessionConfig): NLcURLSession;
|
|
18
12
|
/**
|
|
19
|
-
* Sends a one-shot HTTP request
|
|
20
|
-
*
|
|
21
|
-
* For repeated requests to the same origin, prefer {@link createSession}.
|
|
13
|
+
* Sends a one-shot HTTP request using a temporary session. Supports streaming
|
|
14
|
+
* responses when `input.stream` is `true`.
|
|
22
15
|
*
|
|
23
|
-
* @param {NLcURLRequest} input -
|
|
16
|
+
* @param {NLcURLRequest} input - The full request descriptor including URL, method, headers, and body.
|
|
24
17
|
* @returns {Promise<NLcURLResponse>} Resolves with the server response.
|
|
25
|
-
* @throws {AbortError} If the `signal` in `input` fires before completion.
|
|
26
|
-
* @throws {TimeoutError} If any configured timeout is exceeded.
|
|
27
|
-
* @throws {ConnectionError} If the TCP connection cannot be established.
|
|
28
|
-
* @throws {TLSError} If the TLS handshake fails.
|
|
29
|
-
* @throws {ProxyError} If the proxy tunnel cannot be established.
|
|
30
18
|
*/
|
|
31
19
|
export declare function request(input: NLcURLRequest): Promise<NLcURLResponse>;
|
|
32
20
|
/**
|
|
33
|
-
*
|
|
21
|
+
* Sends an HTTP GET request.
|
|
34
22
|
*
|
|
35
|
-
* @param {string}
|
|
36
|
-
* @param {RequestOptions & { impersonate?: string }}
|
|
23
|
+
* @param {string} url - The target URL.
|
|
24
|
+
* @param {RequestOptions & { impersonate?: string }} [options] - Optional request configuration.
|
|
37
25
|
* @returns {Promise<NLcURLResponse>} Resolves with the server response.
|
|
38
26
|
*/
|
|
39
27
|
export declare function get(url: string, options?: RequestOptions & {
|
|
40
28
|
impersonate?: string;
|
|
41
29
|
}): Promise<NLcURLResponse>;
|
|
42
30
|
/**
|
|
43
|
-
*
|
|
31
|
+
* Sends an HTTP POST request.
|
|
44
32
|
*
|
|
45
|
-
* @param {string}
|
|
46
|
-
* @param {RequestBody}
|
|
47
|
-
* @param {RequestOptions & { impersonate?: string }}
|
|
33
|
+
* @param {string} url - The target URL.
|
|
34
|
+
* @param {RequestBody} [body] - The request body.
|
|
35
|
+
* @param {RequestOptions & { impersonate?: string }} [options] - Optional request configuration.
|
|
48
36
|
* @returns {Promise<NLcURLResponse>} Resolves with the server response.
|
|
49
37
|
*/
|
|
50
38
|
export declare function post(url: string, body?: RequestBody, options?: RequestOptions & {
|
|
51
39
|
impersonate?: string;
|
|
52
40
|
}): Promise<NLcURLResponse>;
|
|
53
41
|
/**
|
|
54
|
-
*
|
|
42
|
+
* Sends an HTTP PUT request.
|
|
55
43
|
*
|
|
56
|
-
* @param {string}
|
|
57
|
-
* @param {RequestBody}
|
|
58
|
-
* @param {RequestOptions & { impersonate?: string }}
|
|
44
|
+
* @param {string} url - The target URL.
|
|
45
|
+
* @param {RequestBody} [body] - The request body.
|
|
46
|
+
* @param {RequestOptions & { impersonate?: string }} [options] - Optional request configuration.
|
|
59
47
|
* @returns {Promise<NLcURLResponse>} Resolves with the server response.
|
|
60
48
|
*/
|
|
61
49
|
export declare function put(url: string, body?: RequestBody, options?: RequestOptions & {
|
|
62
50
|
impersonate?: string;
|
|
63
51
|
}): Promise<NLcURLResponse>;
|
|
64
52
|
/**
|
|
65
|
-
*
|
|
53
|
+
* Sends an HTTP PATCH request.
|
|
66
54
|
*
|
|
67
|
-
* @param {string}
|
|
68
|
-
* @param {RequestBody}
|
|
69
|
-
* @param {RequestOptions & { impersonate?: string }}
|
|
55
|
+
* @param {string} url - The target URL.
|
|
56
|
+
* @param {RequestBody} [body] - The request body.
|
|
57
|
+
* @param {RequestOptions & { impersonate?: string }} [options] - Optional request configuration.
|
|
70
58
|
* @returns {Promise<NLcURLResponse>} Resolves with the server response.
|
|
71
59
|
*/
|
|
72
60
|
export declare function patch(url: string, body?: RequestBody, options?: RequestOptions & {
|
|
73
61
|
impersonate?: string;
|
|
74
62
|
}): Promise<NLcURLResponse>;
|
|
75
63
|
/**
|
|
76
|
-
*
|
|
64
|
+
* Sends an HTTP DELETE request.
|
|
77
65
|
*
|
|
78
|
-
* @param {string}
|
|
79
|
-
* @param {RequestOptions & { impersonate?: string }}
|
|
66
|
+
* @param {string} url - The target URL.
|
|
67
|
+
* @param {RequestOptions & { impersonate?: string }} [options] - Optional request configuration.
|
|
80
68
|
* @returns {Promise<NLcURLResponse>} Resolves with the server response.
|
|
81
69
|
*/
|
|
82
70
|
export declare function del(url: string, options?: RequestOptions & {
|
|
83
71
|
impersonate?: string;
|
|
84
72
|
}): Promise<NLcURLResponse>;
|
|
85
73
|
/**
|
|
86
|
-
*
|
|
74
|
+
* Sends an HTTP HEAD request.
|
|
87
75
|
*
|
|
88
|
-
* @param {string}
|
|
89
|
-
* @param {RequestOptions & { impersonate?: string }}
|
|
90
|
-
* @returns {Promise<NLcURLResponse>} Resolves with the response
|
|
76
|
+
* @param {string} url - The target URL.
|
|
77
|
+
* @param {RequestOptions & { impersonate?: string }} [options] - Optional request configuration.
|
|
78
|
+
* @returns {Promise<NLcURLResponse>} Resolves with the server response.
|
|
91
79
|
*/
|
|
92
80
|
export declare function head(url: string, options?: RequestOptions & {
|
|
93
81
|
impersonate?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/core/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACpF,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AAElE
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/core/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACpF,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AAElE;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,MAAM,CAAC,EAAE,mBAAmB,GAAG,aAAa,CAEzE;AAED;;;;;;GAMG;AACH,wBAAsB,OAAO,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC,CAsB3E;AAED;;;;;;GAMG;AACH,wBAAsB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG;IAAE,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,cAAc,CAAC,CAEnH;AAED;;;;;;;GAOG;AACH,wBAAsB,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG;IAAE,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,cAAc,CAAC,CAExI;AAED;;;;;;;GAOG;AACH,wBAAsB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG;IAAE,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,cAAc,CAAC,CAEvI;AAED;;;;;;;GAOG;AACH,wBAAsB,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG;IAAE,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,cAAc,CAAC,CAEzI;AAED;;;;;;GAMG;AACH,wBAAsB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG;IAAE,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,cAAc,CAAC,CAEnH;AAED;;;;;;GAMG;AACH,wBAAsB,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG;IAAE,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,cAAc,CAAC,CAEpH"}
|
package/dist/core/client.js
CHANGED
|
@@ -1,32 +1,20 @@
|
|
|
1
1
|
import { NLcURLSession } from "./session.js";
|
|
2
2
|
/**
|
|
3
|
-
* Creates a new
|
|
4
|
-
*
|
|
5
|
-
* across multiple requests. Call {@link NLcURLSession.close} when finished.
|
|
3
|
+
* Creates a new session with optional configuration for connection reuse,
|
|
4
|
+
* cookie persistence, caching, and other session-level features.
|
|
6
5
|
*
|
|
7
|
-
* @param {NLcURLSessionConfig} [config] - Session
|
|
6
|
+
* @param {NLcURLSessionConfig} [config] - Session configuration options.
|
|
8
7
|
* @returns {NLcURLSession} A new session instance.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* const session = createSession({ impersonate: 'chrome136' });
|
|
12
|
-
* const r = await session.get('https://example.com');
|
|
13
|
-
* session.close();
|
|
14
8
|
*/
|
|
15
9
|
export function createSession(config) {
|
|
16
10
|
return new NLcURLSession(config);
|
|
17
11
|
}
|
|
18
12
|
/**
|
|
19
|
-
* Sends a one-shot HTTP request
|
|
20
|
-
*
|
|
21
|
-
* For repeated requests to the same origin, prefer {@link createSession}.
|
|
13
|
+
* Sends a one-shot HTTP request using a temporary session. Supports streaming
|
|
14
|
+
* responses when `input.stream` is `true`.
|
|
22
15
|
*
|
|
23
|
-
* @param {NLcURLRequest} input -
|
|
16
|
+
* @param {NLcURLRequest} input - The full request descriptor including URL, method, headers, and body.
|
|
24
17
|
* @returns {Promise<NLcURLResponse>} Resolves with the server response.
|
|
25
|
-
* @throws {AbortError} If the `signal` in `input` fires before completion.
|
|
26
|
-
* @throws {TimeoutError} If any configured timeout is exceeded.
|
|
27
|
-
* @throws {ConnectionError} If the TCP connection cannot be established.
|
|
28
|
-
* @throws {TLSError} If the TLS handshake fails.
|
|
29
|
-
* @throws {ProxyError} If the proxy tunnel cannot be established.
|
|
30
18
|
*/
|
|
31
19
|
export async function request(input) {
|
|
32
20
|
const session = new NLcURLSession(extractSessionConfig(input));
|
|
@@ -39,7 +27,9 @@ export async function request(input) {
|
|
|
39
27
|
session.close();
|
|
40
28
|
throw err;
|
|
41
29
|
}
|
|
42
|
-
const cleanup = () =>
|
|
30
|
+
const cleanup = () => {
|
|
31
|
+
session.close();
|
|
32
|
+
};
|
|
43
33
|
response.body?.once("close", cleanup);
|
|
44
34
|
if (response.body === null)
|
|
45
35
|
session.close();
|
|
@@ -53,64 +43,64 @@ export async function request(input) {
|
|
|
53
43
|
}
|
|
54
44
|
}
|
|
55
45
|
/**
|
|
56
|
-
*
|
|
46
|
+
* Sends an HTTP GET request.
|
|
57
47
|
*
|
|
58
|
-
* @param {string}
|
|
59
|
-
* @param {RequestOptions & { impersonate?: string }}
|
|
48
|
+
* @param {string} url - The target URL.
|
|
49
|
+
* @param {RequestOptions & { impersonate?: string }} [options] - Optional request configuration.
|
|
60
50
|
* @returns {Promise<NLcURLResponse>} Resolves with the server response.
|
|
61
51
|
*/
|
|
62
52
|
export async function get(url, options) {
|
|
63
53
|
return request({ ...options, url, method: "GET" });
|
|
64
54
|
}
|
|
65
55
|
/**
|
|
66
|
-
*
|
|
56
|
+
* Sends an HTTP POST request.
|
|
67
57
|
*
|
|
68
|
-
* @param {string}
|
|
69
|
-
* @param {RequestBody}
|
|
70
|
-
* @param {RequestOptions & { impersonate?: string }}
|
|
58
|
+
* @param {string} url - The target URL.
|
|
59
|
+
* @param {RequestBody} [body] - The request body.
|
|
60
|
+
* @param {RequestOptions & { impersonate?: string }} [options] - Optional request configuration.
|
|
71
61
|
* @returns {Promise<NLcURLResponse>} Resolves with the server response.
|
|
72
62
|
*/
|
|
73
63
|
export async function post(url, body, options) {
|
|
74
64
|
return request({ ...options, url, method: "POST", body });
|
|
75
65
|
}
|
|
76
66
|
/**
|
|
77
|
-
*
|
|
67
|
+
* Sends an HTTP PUT request.
|
|
78
68
|
*
|
|
79
|
-
* @param {string}
|
|
80
|
-
* @param {RequestBody}
|
|
81
|
-
* @param {RequestOptions & { impersonate?: string }}
|
|
69
|
+
* @param {string} url - The target URL.
|
|
70
|
+
* @param {RequestBody} [body] - The request body.
|
|
71
|
+
* @param {RequestOptions & { impersonate?: string }} [options] - Optional request configuration.
|
|
82
72
|
* @returns {Promise<NLcURLResponse>} Resolves with the server response.
|
|
83
73
|
*/
|
|
84
74
|
export async function put(url, body, options) {
|
|
85
75
|
return request({ ...options, url, method: "PUT", body });
|
|
86
76
|
}
|
|
87
77
|
/**
|
|
88
|
-
*
|
|
78
|
+
* Sends an HTTP PATCH request.
|
|
89
79
|
*
|
|
90
|
-
* @param {string}
|
|
91
|
-
* @param {RequestBody}
|
|
92
|
-
* @param {RequestOptions & { impersonate?: string }}
|
|
80
|
+
* @param {string} url - The target URL.
|
|
81
|
+
* @param {RequestBody} [body] - The request body.
|
|
82
|
+
* @param {RequestOptions & { impersonate?: string }} [options] - Optional request configuration.
|
|
93
83
|
* @returns {Promise<NLcURLResponse>} Resolves with the server response.
|
|
94
84
|
*/
|
|
95
85
|
export async function patch(url, body, options) {
|
|
96
86
|
return request({ ...options, url, method: "PATCH", body });
|
|
97
87
|
}
|
|
98
88
|
/**
|
|
99
|
-
*
|
|
89
|
+
* Sends an HTTP DELETE request.
|
|
100
90
|
*
|
|
101
|
-
* @param {string}
|
|
102
|
-
* @param {RequestOptions & { impersonate?: string }}
|
|
91
|
+
* @param {string} url - The target URL.
|
|
92
|
+
* @param {RequestOptions & { impersonate?: string }} [options] - Optional request configuration.
|
|
103
93
|
* @returns {Promise<NLcURLResponse>} Resolves with the server response.
|
|
104
94
|
*/
|
|
105
95
|
export async function del(url, options) {
|
|
106
96
|
return request({ ...options, url, method: "DELETE" });
|
|
107
97
|
}
|
|
108
98
|
/**
|
|
109
|
-
*
|
|
99
|
+
* Sends an HTTP HEAD request.
|
|
110
100
|
*
|
|
111
|
-
* @param {string}
|
|
112
|
-
* @param {RequestOptions & { impersonate?: string }}
|
|
113
|
-
* @returns {Promise<NLcURLResponse>} Resolves with the response
|
|
101
|
+
* @param {string} url - The target URL.
|
|
102
|
+
* @param {RequestOptions & { impersonate?: string }} [options] - Optional request configuration.
|
|
103
|
+
* @returns {Promise<NLcURLResponse>} Resolves with the server response.
|
|
114
104
|
*/
|
|
115
105
|
export async function head(url, options) {
|
|
116
106
|
return request({ ...options, url, method: "HEAD" });
|
|
@@ -130,6 +120,9 @@ function extractSessionConfig(req) {
|
|
|
130
120
|
cookieJar: req.cookieJar,
|
|
131
121
|
logger: req.logger,
|
|
132
122
|
tls: req.tls,
|
|
123
|
+
throwOnError: req.throwOnError,
|
|
124
|
+
cacheConfig: req.cache ? { mode: req.cache } : undefined,
|
|
125
|
+
hsts: undefined,
|
|
133
126
|
};
|
|
134
127
|
}
|
|
135
128
|
//# sourceMappingURL=client.js.map
|