nlcurl 0.1.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/LICENSE +21 -0
- package/README.md +162 -0
- package/dist/cli/args.d.ts +42 -0
- package/dist/cli/args.d.ts.map +1 -0
- package/dist/cli/args.js +262 -0
- package/dist/cli/args.js.map +1 -0
- package/dist/cli/index.d.ts +8 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +114 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/output.d.ts +22 -0
- package/dist/cli/output.d.ts.map +1 -0
- package/dist/cli/output.js +105 -0
- package/dist/cli/output.js.map +1 -0
- package/dist/cookies/jar.d.ts +41 -0
- package/dist/cookies/jar.d.ts.map +1 -0
- package/dist/cookies/jar.js +148 -0
- package/dist/cookies/jar.js.map +1 -0
- package/dist/cookies/parser.d.ts +24 -0
- package/dist/cookies/parser.d.ts.map +1 -0
- package/dist/cookies/parser.js +93 -0
- package/dist/cookies/parser.js.map +1 -0
- package/dist/core/client.d.ts +79 -0
- package/dist/core/client.d.ts.map +1 -0
- package/dist/core/client.js +106 -0
- package/dist/core/client.js.map +1 -0
- package/dist/core/errors.d.ts +36 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +65 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/request.d.ts +96 -0
- package/dist/core/request.d.ts.map +1 -0
- package/dist/core/request.js +5 -0
- package/dist/core/request.js.map +1 -0
- package/dist/core/response.d.ts +48 -0
- package/dist/core/response.d.ts.map +1 -0
- package/dist/core/response.js +65 -0
- package/dist/core/response.js.map +1 -0
- package/dist/core/session.d.ts +60 -0
- package/dist/core/session.d.ts.map +1 -0
- package/dist/core/session.js +305 -0
- package/dist/core/session.js.map +1 -0
- package/dist/fingerprints/akamai.d.ts +17 -0
- package/dist/fingerprints/akamai.d.ts.map +1 -0
- package/dist/fingerprints/akamai.js +30 -0
- package/dist/fingerprints/akamai.js.map +1 -0
- package/dist/fingerprints/database.d.ts +33 -0
- package/dist/fingerprints/database.d.ts.map +1 -0
- package/dist/fingerprints/database.js +68 -0
- package/dist/fingerprints/database.js.map +1 -0
- package/dist/fingerprints/extensions.d.ts +49 -0
- package/dist/fingerprints/extensions.d.ts.map +1 -0
- package/dist/fingerprints/extensions.js +178 -0
- package/dist/fingerprints/extensions.js.map +1 -0
- package/dist/fingerprints/ja3.d.ts +32 -0
- package/dist/fingerprints/ja3.d.ts.map +1 -0
- package/dist/fingerprints/ja3.js +64 -0
- package/dist/fingerprints/ja3.js.map +1 -0
- package/dist/fingerprints/profiles/chrome.d.ts +30 -0
- package/dist/fingerprints/profiles/chrome.d.ts.map +1 -0
- package/dist/fingerprints/profiles/chrome.js +202 -0
- package/dist/fingerprints/profiles/chrome.js.map +1 -0
- package/dist/fingerprints/profiles/edge.d.ts +16 -0
- package/dist/fingerprints/profiles/edge.d.ts.map +1 -0
- package/dist/fingerprints/profiles/edge.js +61 -0
- package/dist/fingerprints/profiles/edge.js.map +1 -0
- package/dist/fingerprints/profiles/firefox.d.ts +13 -0
- package/dist/fingerprints/profiles/firefox.d.ts.map +1 -0
- package/dist/fingerprints/profiles/firefox.js +160 -0
- package/dist/fingerprints/profiles/firefox.js.map +1 -0
- package/dist/fingerprints/profiles/safari.d.ts +16 -0
- package/dist/fingerprints/profiles/safari.d.ts.map +1 -0
- package/dist/fingerprints/profiles/safari.js +140 -0
- package/dist/fingerprints/profiles/safari.js.map +1 -0
- package/dist/fingerprints/profiles/tor.d.ts +14 -0
- package/dist/fingerprints/profiles/tor.d.ts.map +1 -0
- package/dist/fingerprints/profiles/tor.js +136 -0
- package/dist/fingerprints/profiles/tor.js.map +1 -0
- package/dist/fingerprints/types.d.ts +104 -0
- package/dist/fingerprints/types.d.ts.map +1 -0
- package/dist/fingerprints/types.js +9 -0
- package/dist/fingerprints/types.js.map +1 -0
- package/dist/http/h1/client.d.ts +21 -0
- package/dist/http/h1/client.d.ts.map +1 -0
- package/dist/http/h1/client.js +136 -0
- package/dist/http/h1/client.js.map +1 -0
- package/dist/http/h1/encoder.d.ts +11 -0
- package/dist/http/h1/encoder.d.ts.map +1 -0
- package/dist/http/h1/encoder.js +75 -0
- package/dist/http/h1/encoder.js.map +1 -0
- package/dist/http/h1/parser.d.ts +61 -0
- package/dist/http/h1/parser.d.ts.map +1 -0
- package/dist/http/h1/parser.js +258 -0
- package/dist/http/h1/parser.js.map +1 -0
- package/dist/http/h2/client.d.ts +48 -0
- package/dist/http/h2/client.d.ts.map +1 -0
- package/dist/http/h2/client.js +376 -0
- package/dist/http/h2/client.js.map +1 -0
- package/dist/http/h2/frames.d.ts +65 -0
- package/dist/http/h2/frames.d.ts.map +1 -0
- package/dist/http/h2/frames.js +184 -0
- package/dist/http/h2/frames.js.map +1 -0
- package/dist/http/h2/hpack.d.ts +27 -0
- package/dist/http/h2/hpack.d.ts.map +1 -0
- package/dist/http/h2/hpack.js +423 -0
- package/dist/http/h2/hpack.js.map +1 -0
- package/dist/http/negotiator.d.ts +36 -0
- package/dist/http/negotiator.d.ts.map +1 -0
- package/dist/http/negotiator.js +101 -0
- package/dist/http/negotiator.js.map +1 -0
- package/dist/http/pool.d.ts +63 -0
- package/dist/http/pool.d.ts.map +1 -0
- package/dist/http/pool.js +177 -0
- package/dist/http/pool.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/middleware/interceptor.d.ts +27 -0
- package/dist/middleware/interceptor.d.ts.map +1 -0
- package/dist/middleware/interceptor.js +35 -0
- package/dist/middleware/interceptor.js.map +1 -0
- package/dist/middleware/rate-limiter.d.ts +26 -0
- package/dist/middleware/rate-limiter.d.ts.map +1 -0
- package/dist/middleware/rate-limiter.js +59 -0
- package/dist/middleware/rate-limiter.js.map +1 -0
- package/dist/middleware/retry.d.ts +17 -0
- package/dist/middleware/retry.d.ts.map +1 -0
- package/dist/middleware/retry.js +64 -0
- package/dist/middleware/retry.js.map +1 -0
- package/dist/proxy/http-proxy.d.ts +23 -0
- package/dist/proxy/http-proxy.d.ts.map +1 -0
- package/dist/proxy/http-proxy.js +93 -0
- package/dist/proxy/http-proxy.js.map +1 -0
- package/dist/proxy/socks.d.ts +24 -0
- package/dist/proxy/socks.d.ts.map +1 -0
- package/dist/proxy/socks.js +196 -0
- package/dist/proxy/socks.js.map +1 -0
- package/dist/tls/constants.d.ts +142 -0
- package/dist/tls/constants.d.ts.map +1 -0
- package/dist/tls/constants.js +163 -0
- package/dist/tls/constants.js.map +1 -0
- package/dist/tls/node-engine.d.ts +22 -0
- package/dist/tls/node-engine.d.ts.map +1 -0
- package/dist/tls/node-engine.js +190 -0
- package/dist/tls/node-engine.js.map +1 -0
- package/dist/tls/stealth/client-hello.d.ts +38 -0
- package/dist/tls/stealth/client-hello.d.ts.map +1 -0
- package/dist/tls/stealth/client-hello.js +197 -0
- package/dist/tls/stealth/client-hello.js.map +1 -0
- package/dist/tls/stealth/engine.d.ts +16 -0
- package/dist/tls/stealth/engine.d.ts.map +1 -0
- package/dist/tls/stealth/engine.js +196 -0
- package/dist/tls/stealth/engine.js.map +1 -0
- package/dist/tls/stealth/handshake.d.ts +45 -0
- package/dist/tls/stealth/handshake.d.ts.map +1 -0
- package/dist/tls/stealth/handshake.js +403 -0
- package/dist/tls/stealth/handshake.js.map +1 -0
- package/dist/tls/stealth/key-schedule.d.ts +85 -0
- package/dist/tls/stealth/key-schedule.d.ts.map +1 -0
- package/dist/tls/stealth/key-schedule.js +141 -0
- package/dist/tls/stealth/key-schedule.js.map +1 -0
- package/dist/tls/stealth/record-layer.d.ts +74 -0
- package/dist/tls/stealth/record-layer.d.ts.map +1 -0
- package/dist/tls/stealth/record-layer.js +167 -0
- package/dist/tls/stealth/record-layer.js.map +1 -0
- package/dist/tls/types.d.ts +58 -0
- package/dist/tls/types.d.ts.map +1 -0
- package/dist/tls/types.js +6 -0
- package/dist/tls/types.js.map +1 -0
- package/dist/utils/buffer-reader.d.ts +32 -0
- package/dist/utils/buffer-reader.d.ts.map +1 -0
- package/dist/utils/buffer-reader.js +99 -0
- package/dist/utils/buffer-reader.js.map +1 -0
- package/dist/utils/buffer-writer.d.ts +35 -0
- package/dist/utils/buffer-writer.d.ts.map +1 -0
- package/dist/utils/buffer-writer.js +121 -0
- package/dist/utils/buffer-writer.js.map +1 -0
- package/dist/utils/encoding.d.ts +19 -0
- package/dist/utils/encoding.d.ts.map +1 -0
- package/dist/utils/encoding.js +63 -0
- package/dist/utils/encoding.js.map +1 -0
- package/dist/utils/logger.d.ts +24 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +56 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/url.d.ts +22 -0
- package/dist/utils/url.d.ts.map +1 -0
- package/dist/utils/url.js +56 -0
- package/dist/utils/url.js.map +1 -0
- package/dist/ws/client.d.ts +63 -0
- package/dist/ws/client.d.ts.map +1 -0
- package/dist/ws/client.js +273 -0
- package/dist/ws/client.js.map +1 -0
- package/dist/ws/frame.d.ts +44 -0
- package/dist/ws/frame.d.ts.map +1 -0
- package/dist/ws/frame.js +146 -0
- package/dist/ws/frame.js.map +1 -0
- package/package.json +57 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Binary reader for parsing TLS records, HTTP/2 frames, and other
|
|
3
|
+
* network protocol structures. All multi-byte integers are read in
|
|
4
|
+
* network byte order (big-endian) unless stated otherwise.
|
|
5
|
+
*/
|
|
6
|
+
export class BufferReader {
|
|
7
|
+
_buf;
|
|
8
|
+
_pos;
|
|
9
|
+
constructor(buf, offset = 0) {
|
|
10
|
+
this._buf = buf;
|
|
11
|
+
this._pos = offset;
|
|
12
|
+
}
|
|
13
|
+
get position() {
|
|
14
|
+
return this._pos;
|
|
15
|
+
}
|
|
16
|
+
get remaining() {
|
|
17
|
+
return this._buf.length - this._pos;
|
|
18
|
+
}
|
|
19
|
+
get length() {
|
|
20
|
+
return this._buf.length;
|
|
21
|
+
}
|
|
22
|
+
get buffer() {
|
|
23
|
+
return this._buf;
|
|
24
|
+
}
|
|
25
|
+
peek(length) {
|
|
26
|
+
this.assertAvailable(length);
|
|
27
|
+
return this._buf.subarray(this._pos, this._pos + length);
|
|
28
|
+
}
|
|
29
|
+
readUInt8() {
|
|
30
|
+
this.assertAvailable(1);
|
|
31
|
+
const v = this._buf[this._pos];
|
|
32
|
+
this._pos += 1;
|
|
33
|
+
return v;
|
|
34
|
+
}
|
|
35
|
+
readUInt16() {
|
|
36
|
+
this.assertAvailable(2);
|
|
37
|
+
const v = this._buf.readUInt16BE(this._pos);
|
|
38
|
+
this._pos += 2;
|
|
39
|
+
return v;
|
|
40
|
+
}
|
|
41
|
+
readUInt24() {
|
|
42
|
+
this.assertAvailable(3);
|
|
43
|
+
const b0 = this._buf[this._pos];
|
|
44
|
+
const b1 = this._buf[this._pos + 1];
|
|
45
|
+
const b2 = this._buf[this._pos + 2];
|
|
46
|
+
this._pos += 3;
|
|
47
|
+
return (b0 << 16) | (b1 << 8) | b2;
|
|
48
|
+
}
|
|
49
|
+
readUInt32() {
|
|
50
|
+
this.assertAvailable(4);
|
|
51
|
+
const v = this._buf.readUInt32BE(this._pos);
|
|
52
|
+
this._pos += 4;
|
|
53
|
+
return v;
|
|
54
|
+
}
|
|
55
|
+
readBytes(length) {
|
|
56
|
+
this.assertAvailable(length);
|
|
57
|
+
const slice = Buffer.from(this._buf.subarray(this._pos, this._pos + length));
|
|
58
|
+
this._pos += length;
|
|
59
|
+
return slice;
|
|
60
|
+
}
|
|
61
|
+
/** Read a length-prefixed vector with 1-byte length field. */
|
|
62
|
+
readVector8() {
|
|
63
|
+
const len = this.readUInt8();
|
|
64
|
+
return this.readBytes(len);
|
|
65
|
+
}
|
|
66
|
+
/** Read a length-prefixed vector with 2-byte length field. */
|
|
67
|
+
readVector16() {
|
|
68
|
+
const len = this.readUInt16();
|
|
69
|
+
return this.readBytes(len);
|
|
70
|
+
}
|
|
71
|
+
/** Read a length-prefixed vector with 3-byte length field. */
|
|
72
|
+
readVector24() {
|
|
73
|
+
const len = this.readUInt24();
|
|
74
|
+
return this.readBytes(len);
|
|
75
|
+
}
|
|
76
|
+
skip(length) {
|
|
77
|
+
this.assertAvailable(length);
|
|
78
|
+
this._pos += length;
|
|
79
|
+
}
|
|
80
|
+
seek(position) {
|
|
81
|
+
if (position < 0 || position > this._buf.length) {
|
|
82
|
+
throw new RangeError(`Seek position ${position} out of bounds [0, ${this._buf.length}]`);
|
|
83
|
+
}
|
|
84
|
+
this._pos = position;
|
|
85
|
+
}
|
|
86
|
+
/** Create a sub-reader over the next `length` bytes without copying. */
|
|
87
|
+
subReader(length) {
|
|
88
|
+
this.assertAvailable(length);
|
|
89
|
+
const sub = new BufferReader(this._buf.subarray(this._pos, this._pos + length));
|
|
90
|
+
this._pos += length;
|
|
91
|
+
return sub;
|
|
92
|
+
}
|
|
93
|
+
assertAvailable(n) {
|
|
94
|
+
if (this._pos + n > this._buf.length) {
|
|
95
|
+
throw new RangeError(`Buffer underflow: need ${n} bytes at offset ${this._pos}, only ${this._buf.length - this._pos} available`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=buffer-reader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buffer-reader.js","sourceRoot":"","sources":["../../src/utils/buffer-reader.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,OAAO,YAAY;IACf,IAAI,CAAS;IACb,IAAI,CAAS;IAErB,YAAY,GAAW,EAAE,SAAiB,CAAC;QACzC,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;QAChB,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC;IACrB,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,IAAI,CAAC,M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AAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YAChD,MAAM,IAAI,UAAU,CAAC,iBAAiB,QAAQ,sBAAsB,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;QAC3F,CAAC;QACD,IAAI,CAAC,IAAI,GAAG,QAAQ,CAAC;IACvB,CAAC;IAED,wEAAwE;IACxE,SAAS,CAAC,MAAc;QACtB,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;QAC7B,MAAM,GAAG,GAAG,IAAI,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC;QAChF,IAAI,CAAC,IAAI,IAAI,MAAM,CAAC;QACpB,OAAO,GAAG,CAAC;IACb,CAAC;IAEO,eAAe,CAAC,CAAS;QAC/B,IAAI,IAAI,CAAC,IAAI,GAAG,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACrC,MAAM,IAAI,UAAU,CAClB,0BAA0B,CAAC,oBAAoB,IAAI,CAAC,IAAI,UAAU,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,IAAI,YAAY,CAC3G,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Binary writer for constructing TLS records, HTTP/2 frames, and other
|
|
3
|
+
* network protocol structures. All multi-byte integers are written in
|
|
4
|
+
* network byte order (big-endian) unless stated otherwise.
|
|
5
|
+
*/
|
|
6
|
+
export declare class BufferWriter {
|
|
7
|
+
private _buf;
|
|
8
|
+
private _pos;
|
|
9
|
+
constructor(capacity?: number);
|
|
10
|
+
get position(): number;
|
|
11
|
+
get length(): number;
|
|
12
|
+
/** Return a copy of the written portion. */
|
|
13
|
+
toBuffer(): Buffer;
|
|
14
|
+
writeUInt8(value: number): this;
|
|
15
|
+
writeUInt16(value: number): this;
|
|
16
|
+
writeUInt24(value: number): this;
|
|
17
|
+
writeUInt32(value: number): this;
|
|
18
|
+
writeBytes(data: Buffer | Uint8Array): this;
|
|
19
|
+
/** Write a length-prefixed vector with 1-byte length field. */
|
|
20
|
+
writeVector8(data: Buffer | Uint8Array): this;
|
|
21
|
+
/** Write a length-prefixed vector with 2-byte length field. */
|
|
22
|
+
writeVector16(data: Buffer | Uint8Array): this;
|
|
23
|
+
/** Write a length-prefixed vector with 3-byte length field. */
|
|
24
|
+
writeVector24(data: Buffer | Uint8Array): this;
|
|
25
|
+
/**
|
|
26
|
+
* Reserve space and return the offset. The caller must fill the
|
|
27
|
+
* reserved bytes before calling toBuffer().
|
|
28
|
+
*/
|
|
29
|
+
reserve(size: number): number;
|
|
30
|
+
/** Overwrite bytes at a specific offset (for back-patching lengths). */
|
|
31
|
+
patchUInt16(offset: number, value: number): void;
|
|
32
|
+
patchUInt24(offset: number, value: number): void;
|
|
33
|
+
private ensureCapacity;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=buffer-writer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buffer-writer.d.ts","sourceRoot":"","sources":["../../src/utils/buffer-writer.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,qBAAa,YAAY;IACvB,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,IAAI,CAAS;gBAET,QAAQ,GAAE,MAAyB;IAK/C,IAAI,QAAQ,IAAI,MAAM,CAErB;IAED,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,4CAA4C;IAC5C,QAAQ,IAAI,MAAM;IAIlB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAO/B,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAOhC,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAShC,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAOhC,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI;IAW3C,+DAA+D;IAC/D,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI;IAS7C,+DAA+D;IAC/D,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI;IAS9C,+DAA+D;IAC/D,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI;IAS9C;;;OAGG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAO7B,wEAAwE;IACxE,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAIhD,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAMhD,OAAO,CAAC,cAAc;CAWvB"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Binary writer for constructing TLS records, HTTP/2 frames, and other
|
|
3
|
+
* network protocol structures. All multi-byte integers are written in
|
|
4
|
+
* network byte order (big-endian) unless stated otherwise.
|
|
5
|
+
*/
|
|
6
|
+
const INITIAL_CAPACITY = 1024;
|
|
7
|
+
const GROWTH_FACTOR = 2;
|
|
8
|
+
export class BufferWriter {
|
|
9
|
+
_buf;
|
|
10
|
+
_pos;
|
|
11
|
+
constructor(capacity = INITIAL_CAPACITY) {
|
|
12
|
+
this._buf = Buffer.allocUnsafe(capacity);
|
|
13
|
+
this._pos = 0;
|
|
14
|
+
}
|
|
15
|
+
get position() {
|
|
16
|
+
return this._pos;
|
|
17
|
+
}
|
|
18
|
+
get length() {
|
|
19
|
+
return this._pos;
|
|
20
|
+
}
|
|
21
|
+
/** Return a copy of the written portion. */
|
|
22
|
+
toBuffer() {
|
|
23
|
+
return Buffer.from(this._buf.subarray(0, this._pos));
|
|
24
|
+
}
|
|
25
|
+
writeUInt8(value) {
|
|
26
|
+
this.ensureCapacity(1);
|
|
27
|
+
this._buf[this._pos] = value & 0xff;
|
|
28
|
+
this._pos += 1;
|
|
29
|
+
return this;
|
|
30
|
+
}
|
|
31
|
+
writeUInt16(value) {
|
|
32
|
+
this.ensureCapacity(2);
|
|
33
|
+
this._buf.writeUInt16BE(value, this._pos);
|
|
34
|
+
this._pos += 2;
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
writeUInt24(value) {
|
|
38
|
+
this.ensureCapacity(3);
|
|
39
|
+
this._buf[this._pos] = (value >>> 16) & 0xff;
|
|
40
|
+
this._buf[this._pos + 1] = (value >>> 8) & 0xff;
|
|
41
|
+
this._buf[this._pos + 2] = value & 0xff;
|
|
42
|
+
this._pos += 3;
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
writeUInt32(value) {
|
|
46
|
+
this.ensureCapacity(4);
|
|
47
|
+
this._buf.writeUInt32BE(value, this._pos);
|
|
48
|
+
this._pos += 4;
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
writeBytes(data) {
|
|
52
|
+
this.ensureCapacity(data.length);
|
|
53
|
+
if (data instanceof Buffer) {
|
|
54
|
+
data.copy(this._buf, this._pos);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
this._buf.set(data, this._pos);
|
|
58
|
+
}
|
|
59
|
+
this._pos += data.length;
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
/** Write a length-prefixed vector with 1-byte length field. */
|
|
63
|
+
writeVector8(data) {
|
|
64
|
+
if (data.length > 0xff) {
|
|
65
|
+
throw new RangeError(`Vector8 overflow: ${data.length} > 255`);
|
|
66
|
+
}
|
|
67
|
+
this.writeUInt8(data.length);
|
|
68
|
+
this.writeBytes(data);
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
71
|
+
/** Write a length-prefixed vector with 2-byte length field. */
|
|
72
|
+
writeVector16(data) {
|
|
73
|
+
if (data.length > 0xffff) {
|
|
74
|
+
throw new RangeError(`Vector16 overflow: ${data.length} > 65535`);
|
|
75
|
+
}
|
|
76
|
+
this.writeUInt16(data.length);
|
|
77
|
+
this.writeBytes(data);
|
|
78
|
+
return this;
|
|
79
|
+
}
|
|
80
|
+
/** Write a length-prefixed vector with 3-byte length field. */
|
|
81
|
+
writeVector24(data) {
|
|
82
|
+
if (data.length > 0xffffff) {
|
|
83
|
+
throw new RangeError(`Vector24 overflow: ${data.length} > 16777215`);
|
|
84
|
+
}
|
|
85
|
+
this.writeUInt24(data.length);
|
|
86
|
+
this.writeBytes(data);
|
|
87
|
+
return this;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Reserve space and return the offset. The caller must fill the
|
|
91
|
+
* reserved bytes before calling toBuffer().
|
|
92
|
+
*/
|
|
93
|
+
reserve(size) {
|
|
94
|
+
this.ensureCapacity(size);
|
|
95
|
+
const offset = this._pos;
|
|
96
|
+
this._pos += size;
|
|
97
|
+
return offset;
|
|
98
|
+
}
|
|
99
|
+
/** Overwrite bytes at a specific offset (for back-patching lengths). */
|
|
100
|
+
patchUInt16(offset, value) {
|
|
101
|
+
this._buf.writeUInt16BE(value, offset);
|
|
102
|
+
}
|
|
103
|
+
patchUInt24(offset, value) {
|
|
104
|
+
this._buf[offset] = (value >>> 16) & 0xff;
|
|
105
|
+
this._buf[offset + 1] = (value >>> 8) & 0xff;
|
|
106
|
+
this._buf[offset + 2] = value & 0xff;
|
|
107
|
+
}
|
|
108
|
+
ensureCapacity(needed) {
|
|
109
|
+
const required = this._pos + needed;
|
|
110
|
+
if (required <= this._buf.length)
|
|
111
|
+
return;
|
|
112
|
+
let newCap = this._buf.length;
|
|
113
|
+
while (newCap < required) {
|
|
114
|
+
newCap *= GROWTH_FACTOR;
|
|
115
|
+
}
|
|
116
|
+
const newBuf = Buffer.allocUnsafe(newCap);
|
|
117
|
+
this._buf.copy(newBuf, 0, 0, this._pos);
|
|
118
|
+
this._buf = newBuf;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
//# sourceMapping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M,CAAC,GAAG,CAAC,KAAK,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;QAC1C,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC;QAC7C,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,KAAK,GAAG,IAAI,CAAC;IACvC,CAAC;IAEO,cAAc,CAAC,MAAc;QACnC,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC;QACpC,IAAI,QAAQ,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM;YAAE,OAAO;QACzC,IAAI,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC;QAC9B,OAAO,MAAM,GAAG,QAAQ,EAAE,CAAC;YACzB,MAAM,IAAI,aAAa,CAAC;QAC1B,CAAC;QACD,MAAM,MAAM,GAAG,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAC1C,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QACxC,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC;IACrB,CAAC;CACF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content-Encoding decompression using only node:zlib.
|
|
3
|
+
* Supports gzip, deflate, brotli, and zstd (Node 22+).
|
|
4
|
+
*/
|
|
5
|
+
/** Whether this Node.js runtime can decompress zstd content. */
|
|
6
|
+
export declare const supportsZstd: boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Decompress a response body according to the Content-Encoding header.
|
|
9
|
+
* Returns the original buffer if the encoding is not recognised or empty.
|
|
10
|
+
*/
|
|
11
|
+
export declare function decompressBody(body: Buffer, contentEncoding: string | undefined): Promise<Buffer>;
|
|
12
|
+
/** Return the canonical Accept-Encoding value for browser impersonation. */
|
|
13
|
+
export declare function defaultAcceptEncoding(): string;
|
|
14
|
+
/**
|
|
15
|
+
* Strip unsupported encodings (e.g. zstd on Node < 22) from an
|
|
16
|
+
* accept-encoding header value so servers never send what we can't decode.
|
|
17
|
+
*/
|
|
18
|
+
export declare function sanitizeAcceptEncoding(value: string): string;
|
|
19
|
+
//# sourceMappingURL=encoding.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encoding.d.ts","sourceRoot":"","sources":["../../src/utils/encoding.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAgBH,gEAAgE;AAChE,eAAO,MAAM,YAAY,EAAE,OAAsC,CAAC;AAElE;;;GAGG;AACH,wBAAsB,cAAc,CAClC,IAAI,EAAE,MAAM,EACZ,eAAe,EAAE,MAAM,GAAG,SAAS,GAClC,OAAO,CAAC,MAAM,CAAC,CA8BjB;AAED,4EAA4E;AAC5E,wBAAgB,qBAAqB,IAAI,MAAM,CAE9C;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAO5D"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content-Encoding decompression using only node:zlib.
|
|
3
|
+
* Supports gzip, deflate, brotli, and zstd (Node 22+).
|
|
4
|
+
*/
|
|
5
|
+
import * as zlib from 'node:zlib';
|
|
6
|
+
import { promisify } from 'node:util';
|
|
7
|
+
const gunzipAsync = promisify(zlib.gunzip);
|
|
8
|
+
const inflateAsync = promisify(zlib.inflate);
|
|
9
|
+
const brotliDecompressAsync = promisify(zlib.brotliDecompress);
|
|
10
|
+
// zstd is natively supported in Node 22+ via node:zlib
|
|
11
|
+
const _zstdFn = zlib['zstdDecompress'];
|
|
12
|
+
const zstdDecompressAsync = typeof _zstdFn === 'function'
|
|
13
|
+
? promisify(_zstdFn)
|
|
14
|
+
: null;
|
|
15
|
+
/** Whether this Node.js runtime can decompress zstd content. */
|
|
16
|
+
export const supportsZstd = zstdDecompressAsync !== null;
|
|
17
|
+
/**
|
|
18
|
+
* Decompress a response body according to the Content-Encoding header.
|
|
19
|
+
* Returns the original buffer if the encoding is not recognised or empty.
|
|
20
|
+
*/
|
|
21
|
+
export async function decompressBody(body, contentEncoding) {
|
|
22
|
+
if (!contentEncoding || body.length === 0)
|
|
23
|
+
return body;
|
|
24
|
+
const encoding = contentEncoding.trim().toLowerCase();
|
|
25
|
+
switch (encoding) {
|
|
26
|
+
case 'gzip':
|
|
27
|
+
case 'x-gzip':
|
|
28
|
+
return gunzipAsync(body);
|
|
29
|
+
case 'deflate':
|
|
30
|
+
return inflateAsync(body);
|
|
31
|
+
case 'br':
|
|
32
|
+
return brotliDecompressAsync(body);
|
|
33
|
+
case 'zstd':
|
|
34
|
+
if (zstdDecompressAsync) {
|
|
35
|
+
return zstdDecompressAsync(body);
|
|
36
|
+
}
|
|
37
|
+
// Node < 22: zstd not available natively, return raw bytes.
|
|
38
|
+
return body;
|
|
39
|
+
case 'identity':
|
|
40
|
+
return body;
|
|
41
|
+
default:
|
|
42
|
+
// Unknown encoding -- return as-is rather than throwing.
|
|
43
|
+
return body;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/** Return the canonical Accept-Encoding value for browser impersonation. */
|
|
47
|
+
export function defaultAcceptEncoding() {
|
|
48
|
+
return supportsZstd ? 'gzip, deflate, br, zstd' : 'gzip, deflate, br';
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Strip unsupported encodings (e.g. zstd on Node < 22) from an
|
|
52
|
+
* accept-encoding header value so servers never send what we can't decode.
|
|
53
|
+
*/
|
|
54
|
+
export function sanitizeAcceptEncoding(value) {
|
|
55
|
+
if (supportsZstd)
|
|
56
|
+
return value;
|
|
57
|
+
return value
|
|
58
|
+
.split(',')
|
|
59
|
+
.map(s => s.trim())
|
|
60
|
+
.filter(s => !s.startsWith('zstd'))
|
|
61
|
+
.join(', ');
|
|
62
|
+
}
|
|
63
|
+
//# sour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CAAC;gBACxB,OAAO,mBAAmB,CAAC,IAAI,CAAC,CAAC;YACnC,CAAC;YACD,4DAA4D;YAC5D,OAAO,IAAI,CAAC;QAEd,KAAK,UAAU;YACb,OAAO,IAAI,CAAC;QAEd;YACE,yDAAyD;YACzD,OAAO,IAAI,CAAC;IAChB,CAAC;AACH,CAAC;AAED,4EAA4E;AAC5E,MAAM,UAAU,qBAAqB;IACnC,OAAO,YAAY,CAAC,CAAC,CAAC,yBAAyB,CAAC,CAAC,CAAC,mBAAmB,CAAC;AACxE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CAAC,KAAa;IAClD,IAAI,YAAY;QAAE,OAAO,KAAK,CAAC;IAC/B,OAAO,KAAK;SACT,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;SAClB,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;SAClC,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured logger with configurable verbosity.
|
|
3
|
+
*/
|
|
4
|
+
export type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'silent';
|
|
5
|
+
export interface Logger {
|
|
6
|
+
debug(message: string, ...args: unknown[]): void;
|
|
7
|
+
info(message: string, ...args: unknown[]): void;
|
|
8
|
+
warn(message: string, ...args: unknown[]): void;
|
|
9
|
+
error(message: string, ...args: unknown[]): void;
|
|
10
|
+
}
|
|
11
|
+
export declare class ConsoleLogger implements Logger {
|
|
12
|
+
private level;
|
|
13
|
+
constructor(level?: LogLevel);
|
|
14
|
+
debug(message: string, ...args: unknown[]): void;
|
|
15
|
+
info(message: string, ...args: unknown[]): void;
|
|
16
|
+
warn(message: string, ...args: unknown[]): void;
|
|
17
|
+
error(message: string, ...args: unknown[]): void;
|
|
18
|
+
private formatArgs;
|
|
19
|
+
}
|
|
20
|
+
/** Silent logger that discards all output. */
|
|
21
|
+
export declare const SILENT_LOGGER: Logger;
|
|
22
|
+
export declare function setDefaultLogger(logger: Logger): void;
|
|
23
|
+
export declare function getDefaultLogger(): Logger;
|
|
24
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAC;AAUtE,MAAM,WAAW,MAAM;IACrB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IACjD,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAChD,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAChD,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;CAClD;AAED,qBAAa,aAAc,YAAW,MAAM;IAC1C,OAAO,CAAC,KAAK,CAAS;gBAEV,KAAK,GAAE,QAAiB;IAIpC,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAMhD,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAM/C,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAM/C,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAMhD,OAAO,CAAC,UAAU;CAInB;AAED,8CAA8C;AAC9C,eAAO,MAAM,aAAa,EAAE,MAK3B,CAAC;AAIF,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAErD;AAED,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured logger with configurable verbosity.
|
|
3
|
+
*/
|
|
4
|
+
const LEVEL_ORDER = {
|
|
5
|
+
debug: 0,
|
|
6
|
+
info: 1,
|
|
7
|
+
warn: 2,
|
|
8
|
+
error: 3,
|
|
9
|
+
silent: 4,
|
|
10
|
+
};
|
|
11
|
+
export class ConsoleLogger {
|
|
12
|
+
level;
|
|
13
|
+
constructor(level = 'warn') {
|
|
14
|
+
this.level = LEVEL_ORDER[level];
|
|
15
|
+
}
|
|
16
|
+
debug(message, ...args) {
|
|
17
|
+
if (this.level <= LEVEL_ORDER.debug) {
|
|
18
|
+
process.stderr.write(`[nlcurl:debug] ${message}${this.formatArgs(args)}\n`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
info(message, ...args) {
|
|
22
|
+
if (this.level <= LEVEL_ORDER.info) {
|
|
23
|
+
process.stderr.write(`[nlcurl:info] ${message}${this.formatArgs(args)}\n`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
warn(message, ...args) {
|
|
27
|
+
if (this.level <= LEVEL_ORDER.warn) {
|
|
28
|
+
process.stderr.write(`[nlcurl:warn] ${message}${this.formatArgs(args)}\n`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
error(message, ...args) {
|
|
32
|
+
if (this.level <= LEVEL_ORDER.error) {
|
|
33
|
+
process.stderr.write(`[nlcurl:error] ${message}${this.formatArgs(args)}\n`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
formatArgs(args) {
|
|
37
|
+
if (args.length === 0)
|
|
38
|
+
return '';
|
|
39
|
+
return ' ' + args.map((a) => (typeof a === 'string' ? a : JSON.stringify(a))).join(' ');
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/** Silent logger that discards all output. */
|
|
43
|
+
export const SILENT_LOGGER = {
|
|
44
|
+
debug() { },
|
|
45
|
+
info() { },
|
|
46
|
+
warn() { },
|
|
47
|
+
error() { },
|
|
48
|
+
};
|
|
49
|
+
let _default = new ConsoleLogger('warn');
|
|
50
|
+
export function setDefaultLogger(logger) {
|
|
51
|
+
_default = logger;
|
|
52
|
+
}
|
|
53
|
+
export function getDefaultLogger() {
|
|
54
|
+
return _default;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,MAAM,WAAW,GAA6B;IAC5C,KAAK,EAAE,CAAC;IACR,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;IACP,KAAK,EAAE,CAAC;IACR,MAAM,EAAE,CAAC;CACV,CAAC;AASF,MAAM,OAAO,aAAa;IAChB,KAAK,CAAS;IAEtB,YAAY,QAAkB,MAAM;QAClC,IAAI,CAAC,KAAK,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC;IAED,KAAK,CAAC,OAAe,EAAE,GAAG,IAAe;QACvC,IAAI,IAAI,CAAC,KAAK,IAAI,WAAW,CAAC,KAAK,EAAE,CAAC;YACpC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,kBAAkB,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC9E,CAAC;IACH,CAAC;IAED,IAAI,CAAC,OAAe,EAAE,GAAG,IAAe;QACtC,IAAI,IAAI,CAAC,KAAK,IAAI,WAAW,CAAC,IAAI,EAAE,CAAC;YACnC,OAAO,CAAC,MAAM,CAA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M,CAAC;AACpB,CAAC;AAED,MAAM,UAAU,gBAAgB;IAC9B,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* URL utilities -- parsing, query string encoding, base URL joining.
|
|
3
|
+
* Zero dependencies; uses the built-in WHATWG URL API.
|
|
4
|
+
*/
|
|
5
|
+
export declare function resolveURL(base: string | undefined, relative: string): string;
|
|
6
|
+
export declare function appendParams(url: string, params?: Record<string, string | number | boolean>): string;
|
|
7
|
+
export declare function parseURL(raw: string): URL;
|
|
8
|
+
/**
|
|
9
|
+
* Extract the origin key used for connection pooling:
|
|
10
|
+
* `protocol://host:port`
|
|
11
|
+
*/
|
|
12
|
+
export declare function originOf(url: string): string;
|
|
13
|
+
/** Return the hostname suitable for the TLS SNI extension. */
|
|
14
|
+
export declare function sniHost(url: string): string;
|
|
15
|
+
/** Return the host:port string for TCP connection. */
|
|
16
|
+
export declare function hostPort(url: string): {
|
|
17
|
+
host: string;
|
|
18
|
+
port: number;
|
|
19
|
+
};
|
|
20
|
+
/** Return the request path including query string. */
|
|
21
|
+
export declare function requestPath(url: string): string;
|
|
22
|
+
//# sourceMappingURL=url.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../../src/utils/url.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAO7E;AAED,wBAAgB,YAAY,CAC1B,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,GACjD,MAAM,CASR;AAED,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAEzC;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAI5C;AAED,8DAA8D;AAC9D,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED,sDAAsD;AACtD,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAOpE;AAED,sDAAsD;AACtD,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAG/C"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* URL utilities -- parsing, query string encoding, base URL joining.
|
|
3
|
+
* Zero dependencies; uses the built-in WHATWG URL API.
|
|
4
|
+
*/
|
|
5
|
+
export function resolveURL(base, relative) {
|
|
6
|
+
if (!base)
|
|
7
|
+
return relative;
|
|
8
|
+
try {
|
|
9
|
+
return new URL(relative, base).toString();
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return relative;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export function appendParams(url, params) {
|
|
16
|
+
if (!params || Object.keys(params).length === 0)
|
|
17
|
+
return url;
|
|
18
|
+
const parsed = new URL(url);
|
|
19
|
+
for (const [key, value] of Object.entries(params)) {
|
|
20
|
+
if (value === undefined || value === null)
|
|
21
|
+
continue;
|
|
22
|
+
parsed.searchParams.append(key, String(value));
|
|
23
|
+
}
|
|
24
|
+
return parsed.toString();
|
|
25
|
+
}
|
|
26
|
+
export function parseURL(raw) {
|
|
27
|
+
return new URL(raw);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Extract the origin key used for connection pooling:
|
|
31
|
+
* `protocol://host:port`
|
|
32
|
+
*/
|
|
33
|
+
export function originOf(url) {
|
|
34
|
+
const u = new URL(url);
|
|
35
|
+
const port = u.port || (u.protocol === 'https:' ? '443' : '80');
|
|
36
|
+
return `${u.protocol}//${u.hostname}:${port}`;
|
|
37
|
+
}
|
|
38
|
+
/** Return the hostname suitable for the TLS SNI extension. */
|
|
39
|
+
export function sniHost(url) {
|
|
40
|
+
return new URL(url).hostname;
|
|
41
|
+
}
|
|
42
|
+
/** Return the host:port string for TCP connection. */
|
|
43
|
+
export function hostPort(url) {
|
|
44
|
+
const u = new URL(url);
|
|
45
|
+
const defaultPort = u.protocol === 'https:' ? 443 : 80;
|
|
46
|
+
return {
|
|
47
|
+
host: u.hostname,
|
|
48
|
+
port: u.port ? parseInt(u.port, 10) : defaultPort,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/** Return the request path including query string. */
|
|
52
|
+
export function requestPath(url) {
|
|
53
|
+
const u = new URL(url);
|
|
54
|
+
return u.pathname + u.search;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=url.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url.js","sourceRoot":"","sources":["../../src/utils/url.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,UAAU,UAAU,CAAC,IAAwB,EAAE,QAAgB;IACnE,IAAI,CAAC,IAAI;QAAE,OAAO,QAAQ,CAAC;IAC3B,IAAI,CAAC;QACH,OAAO,IAAI,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAC;IAC5C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,QAAQ,CAAC;IAClB,CAAC;AACH,CAAC;AAED,MAAM,UAAU,YAAY,CAC1B,GAAW,EACX,MAAkD;IAElD,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,GAAG,CAAC;IAE5D,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IAC5B,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAClD,IAAI,KAAK,K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,WAAW,CAAC,GAAW;IACrC,MAAM,CAAC,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IACvB,OAAO,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,MAAM,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WebSocket client with TLS fingerprint impersonation.
|
|
3
|
+
*
|
|
4
|
+
* Implements the WebSocket protocol (RFC 6455) over impersonated
|
|
5
|
+
* TLS connections. Supports text and binary messages, ping/pong,
|
|
6
|
+
* and graceful close.
|
|
7
|
+
*/
|
|
8
|
+
import { EventEmitter } from 'node:events';
|
|
9
|
+
export interface WebSocketOptions {
|
|
10
|
+
/** Browser profile name to impersonate. */
|
|
11
|
+
impersonate?: string;
|
|
12
|
+
/** Use the stealth TLS engine. */
|
|
13
|
+
stealth?: boolean;
|
|
14
|
+
/** Extra headers for the upgrade request. */
|
|
15
|
+
headers?: Record<string, string>;
|
|
16
|
+
/** WebSocket sub-protocols. */
|
|
17
|
+
protocols?: string[];
|
|
18
|
+
/** Skip TLS certificate verification. */
|
|
19
|
+
insecure?: boolean;
|
|
20
|
+
/** Connection timeout in milliseconds. */
|
|
21
|
+
timeout?: number;
|
|
22
|
+
}
|
|
23
|
+
export type WebSocketState = 'connecting' | 'open' | 'closing' | 'closed';
|
|
24
|
+
export interface WebSocketEvents {
|
|
25
|
+
open: [];
|
|
26
|
+
message: [data: string | Buffer, isBinary: boolean];
|
|
27
|
+
close: [code: number, reason: string];
|
|
28
|
+
error: [error: Error];
|
|
29
|
+
ping: [data: Buffer];
|
|
30
|
+
pong: [data: Buffer];
|
|
31
|
+
}
|
|
32
|
+
export declare class WebSocketClient extends EventEmitter {
|
|
33
|
+
state: WebSocketState;
|
|
34
|
+
protocol: string;
|
|
35
|
+
readonly url: string;
|
|
36
|
+
private socket;
|
|
37
|
+
private parser;
|
|
38
|
+
private fragments;
|
|
39
|
+
private fragmentOpcode;
|
|
40
|
+
constructor(url: string, options?: WebSocketOptions);
|
|
41
|
+
/**
|
|
42
|
+
* Send a text message.
|
|
43
|
+
*/
|
|
44
|
+
sendText(data: string): void;
|
|
45
|
+
/**
|
|
46
|
+
* Send a binary message.
|
|
47
|
+
*/
|
|
48
|
+
sendBinary(data: Buffer): void;
|
|
49
|
+
/**
|
|
50
|
+
* Send a ping frame.
|
|
51
|
+
*/
|
|
52
|
+
ping(data?: Buffer): void;
|
|
53
|
+
/**
|
|
54
|
+
* Initiate a graceful close handshake.
|
|
55
|
+
*/
|
|
56
|
+
close(code?: number, reason?: string): void;
|
|
57
|
+
private assertOpen;
|
|
58
|
+
private connect;
|
|
59
|
+
private performUpgrade;
|
|
60
|
+
private onData;
|
|
61
|
+
private handleFrame;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/ws/client.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAiB3C,MAAM,WAAW,gBAAgB;IAC/B,2CAA2C;IAC3C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kCAAkC;IAClC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,6CAA6C;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,+BAA+B;IAC/B,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,yCAAyC;IACzC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,0CAA0C;IAC1C,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,MAAM,cAAc,GAAG,YAAY,GAAG,MAAM,GAAG,SAAS,GAAG,QAAQ,CAAC;AAE1E,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,EAAE,CAAC;IACT,OAAO,EAAE,CAAC,IAAI,E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