@j0hanz/superfetch 2.5.2 → 2.6.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 +356 -223
- package/dist/assets/logo.svg +24837 -24835
- package/dist/cache.d.ts +28 -20
- package/dist/cache.js +292 -514
- package/dist/config.d.ts +41 -7
- package/dist/config.js +298 -148
- package/dist/crypto.js +25 -12
- package/dist/dom-noise-removal.js +379 -421
- package/dist/errors.d.ts +2 -2
- package/dist/errors.js +25 -8
- package/dist/fetch.d.ts +18 -16
- package/dist/fetch.js +1132 -526
- package/dist/host-normalization.js +40 -10
- package/dist/http-native.js +628 -287
- package/dist/index.js +67 -7
- package/dist/instructions.md +44 -30
- package/dist/ip-blocklist.d.ts +8 -0
- package/dist/ip-blocklist.js +65 -0
- package/dist/json.js +14 -9
- package/dist/language-detection.d.ts +2 -11
- package/dist/language-detection.js +289 -280
- package/dist/markdown-cleanup.d.ts +0 -1
- package/dist/markdown-cleanup.js +391 -429
- package/dist/mcp-validator.js +4 -2
- package/dist/mcp.js +184 -135
- package/dist/observability.js +89 -21
- package/dist/resources.js +16 -6
- package/dist/server-tuning.d.ts +2 -0
- package/dist/server-tuning.js +25 -23
- package/dist/session.d.ts +1 -0
- package/dist/session.js +41 -33
- package/dist/tasks.d.ts +2 -0
- package/dist/tasks.js +91 -9
- package/dist/timer-utils.d.ts +5 -0
- package/dist/timer-utils.js +20 -0
- package/dist/tools.d.ts +28 -5
- package/dist/tools.js +317 -183
- package/dist/transform-types.d.ts +5 -1
- package/dist/transform.d.ts +3 -2
- package/dist/transform.js +1138 -421
- package/dist/type-guards.d.ts +1 -0
- package/dist/type-guards.js +7 -0
- package/dist/workers/transform-child.d.ts +1 -0
- package/dist/workers/transform-child.js +118 -0
- package/dist/workers/transform-worker.js +87 -78
- package/package.json +21 -13
|
@@ -1,21 +1,30 @@
|
|
|
1
|
-
import { isIP } from 'node:net';
|
|
1
|
+
import { isIP, SocketAddress } from 'node:net';
|
|
2
|
+
import { domainToASCII } from 'node:url';
|
|
2
3
|
export function normalizeHost(value) {
|
|
3
|
-
const
|
|
4
|
-
if (!
|
|
4
|
+
const trimmedLower = value.trim().toLowerCase();
|
|
5
|
+
if (!trimmedLower)
|
|
5
6
|
return null;
|
|
6
|
-
const first = takeFirstHostValue(
|
|
7
|
+
const first = takeFirstHostValue(trimmedLower);
|
|
7
8
|
if (!first)
|
|
8
9
|
return null;
|
|
10
|
+
const socketAddress = SocketAddress.parse(first);
|
|
11
|
+
if (socketAddress)
|
|
12
|
+
return normalizeHostname(socketAddress.address);
|
|
13
|
+
const parsed = parseHostWithUrl(first);
|
|
14
|
+
if (parsed)
|
|
15
|
+
return parsed;
|
|
9
16
|
const ipv6 = stripIpv6Brackets(first);
|
|
10
17
|
if (ipv6)
|
|
11
|
-
return
|
|
18
|
+
return normalizeHostname(ipv6);
|
|
12
19
|
if (isIpV6Literal(first)) {
|
|
13
|
-
return
|
|
20
|
+
return normalizeHostname(first);
|
|
14
21
|
}
|
|
15
|
-
return
|
|
22
|
+
return normalizeHostname(stripPortIfPresent(first));
|
|
16
23
|
}
|
|
17
24
|
function takeFirstHostValue(value) {
|
|
18
|
-
|
|
25
|
+
// Faster than split(',') for large forwarded headers; preserves behavior.
|
|
26
|
+
const commaIndex = value.indexOf(',');
|
|
27
|
+
const first = commaIndex === -1 ? value : value.slice(0, commaIndex);
|
|
19
28
|
if (!first)
|
|
20
29
|
return null;
|
|
21
30
|
const trimmed = first.trim();
|
|
@@ -38,10 +47,31 @@ function stripPortIfPresent(value) {
|
|
|
38
47
|
function isIpV6Literal(value) {
|
|
39
48
|
return isIP(value) === 6;
|
|
40
49
|
}
|
|
50
|
+
function normalizeHostname(value) {
|
|
51
|
+
const trimmed = value.trim().toLowerCase();
|
|
52
|
+
if (!trimmed)
|
|
53
|
+
return null;
|
|
54
|
+
if (isIP(trimmed))
|
|
55
|
+
return stripTrailingDots(trimmed);
|
|
56
|
+
const ascii = domainToASCII(trimmed);
|
|
57
|
+
return ascii ? stripTrailingDots(ascii) : null;
|
|
58
|
+
}
|
|
59
|
+
function parseHostWithUrl(value) {
|
|
60
|
+
const candidateUrl = `http://${value}`;
|
|
61
|
+
if (!URL.canParse(candidateUrl))
|
|
62
|
+
return null;
|
|
63
|
+
try {
|
|
64
|
+
const parsed = new URL(candidateUrl);
|
|
65
|
+
return normalizeHostname(parsed.hostname);
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
41
71
|
function stripTrailingDots(value) {
|
|
72
|
+
// Keep loop (rather than regex) to preserve exact behavior and avoid hidden allocations.
|
|
42
73
|
let result = value;
|
|
43
|
-
while (result.endsWith('.'))
|
|
74
|
+
while (result.endsWith('.'))
|
|
44
75
|
result = result.slice(0, -1);
|
|
45
|
-
}
|
|
46
76
|
return result;
|
|
47
77
|
}
|