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.
Files changed (354) hide show
  1. package/README.md +143 -140
  2. package/dist/cache/groups.d.ts +75 -0
  3. package/dist/cache/groups.d.ts.map +1 -0
  4. package/dist/cache/groups.js +118 -0
  5. package/dist/cache/groups.js.map +1 -0
  6. package/dist/cache/no-vary-search.d.ts +33 -0
  7. package/dist/cache/no-vary-search.d.ts.map +1 -0
  8. package/dist/cache/no-vary-search.js +148 -0
  9. package/dist/cache/no-vary-search.js.map +1 -0
  10. package/dist/cache/range.d.ts +120 -0
  11. package/dist/cache/range.d.ts.map +1 -0
  12. package/dist/cache/range.js +193 -0
  13. package/dist/cache/range.js.map +1 -0
  14. package/dist/cache/store.d.ts +111 -0
  15. package/dist/cache/store.d.ts.map +1 -0
  16. package/dist/cache/store.js +414 -0
  17. package/dist/cache/store.js.map +1 -0
  18. package/dist/cache/types.d.ts +69 -0
  19. package/dist/cache/types.d.ts.map +1 -0
  20. package/dist/cache/types.js +2 -0
  21. package/dist/cache/types.js.map +1 -0
  22. package/dist/cli/args.d.ts +4 -37
  23. package/dist/cli/args.d.ts.map +1 -1
  24. package/dist/cli/args.js +3 -4
  25. package/dist/cli/args.js.map +1 -1
  26. package/dist/cli/index.d.ts +0 -5
  27. package/dist/cli/index.d.ts.map +1 -1
  28. package/dist/cli/index.js +1 -6
  29. package/dist/cli/index.js.map +1 -1
  30. package/dist/cli/output.d.ts +14 -20
  31. package/dist/cli/output.d.ts.map +1 -1
  32. package/dist/cli/output.js +14 -20
  33. package/dist/cli/output.js.map +1 -1
  34. package/dist/cookies/jar.d.ts +33 -31
  35. package/dist/cookies/jar.d.ts.map +1 -1
  36. package/dist/cookies/jar.js +69 -33
  37. package/dist/cookies/jar.js.map +1 -1
  38. package/dist/cookies/parser.d.ts +14 -16
  39. package/dist/cookies/parser.d.ts.map +1 -1
  40. package/dist/cookies/parser.js +30 -13
  41. package/dist/cookies/parser.js.map +1 -1
  42. package/dist/cookies/psl-data.d.ts +1 -1
  43. package/dist/cookies/psl-data.js +1 -1
  44. package/dist/cookies/public-suffix.d.ts +5 -27
  45. package/dist/cookies/public-suffix.d.ts.map +1 -1
  46. package/dist/cookies/public-suffix.js +5 -37
  47. package/dist/cookies/public-suffix.js.map +1 -1
  48. package/dist/core/auth.d.ts +30 -0
  49. package/dist/core/auth.d.ts.map +1 -0
  50. package/dist/core/auth.js +34 -0
  51. package/dist/core/auth.js.map +1 -0
  52. package/dist/core/client.d.ts +28 -40
  53. package/dist/core/client.d.ts.map +1 -1
  54. package/dist/core/client.js +34 -41
  55. package/dist/core/client.js.map +1 -1
  56. package/dist/core/errors.d.ts +64 -88
  57. package/dist/core/errors.d.ts.map +1 -1
  58. package/dist/core/errors.js +64 -88
  59. package/dist/core/errors.js.map +1 -1
  60. package/dist/core/request.d.ts +63 -85
  61. package/dist/core/request.d.ts.map +1 -1
  62. package/dist/core/response.d.ts +64 -59
  63. package/dist/core/response.d.ts.map +1 -1
  64. package/dist/core/response.js +70 -52
  65. package/dist/core/response.js.map +1 -1
  66. package/dist/core/session.d.ts +81 -70
  67. package/dist/core/session.d.ts.map +1 -1
  68. package/dist/core/session.js +198 -71
  69. package/dist/core/session.js.map +1 -1
  70. package/dist/core/validation.d.ts +44 -42
  71. package/dist/core/validation.d.ts.map +1 -1
  72. package/dist/core/validation.js +47 -58
  73. package/dist/core/validation.js.map +1 -1
  74. package/dist/dns/cache.d.ts +59 -0
  75. package/dist/dns/cache.d.ts.map +1 -0
  76. package/dist/dns/cache.js +99 -0
  77. package/dist/dns/cache.js.map +1 -0
  78. package/dist/dns/codec.d.ts +39 -0
  79. package/dist/dns/codec.d.ts.map +1 -0
  80. package/dist/dns/codec.js +238 -0
  81. package/dist/dns/codec.js.map +1 -0
  82. package/dist/dns/doh-resolver.d.ts +38 -0
  83. package/dist/dns/doh-resolver.d.ts.map +1 -0
  84. package/dist/dns/doh-resolver.js +191 -0
  85. package/dist/dns/doh-resolver.js.map +1 -0
  86. package/dist/dns/dot-resolver.d.ts +89 -0
  87. package/dist/dns/dot-resolver.d.ts.map +1 -0
  88. package/dist/dns/dot-resolver.js +158 -0
  89. package/dist/dns/dot-resolver.js.map +1 -0
  90. package/dist/dns/https-rr.d.ts +40 -0
  91. package/dist/dns/https-rr.d.ts.map +1 -0
  92. package/dist/dns/https-rr.js +109 -0
  93. package/dist/dns/https-rr.js.map +1 -0
  94. package/dist/dns/types.d.ts +82 -0
  95. package/dist/dns/types.d.ts.map +1 -0
  96. package/dist/dns/types.js +23 -0
  97. package/dist/dns/types.js.map +1 -0
  98. package/dist/fingerprints/akamai.d.ts +3 -11
  99. package/dist/fingerprints/akamai.d.ts.map +1 -1
  100. package/dist/fingerprints/akamai.js +3 -11
  101. package/dist/fingerprints/akamai.js.map +1 -1
  102. package/dist/fingerprints/database.d.ts +6 -14
  103. package/dist/fingerprints/database.d.ts.map +1 -1
  104. package/dist/fingerprints/database.js +6 -14
  105. package/dist/fingerprints/database.js.map +1 -1
  106. package/dist/fingerprints/extensions.d.ts +56 -71
  107. package/dist/fingerprints/extensions.d.ts.map +1 -1
  108. package/dist/fingerprints/extensions.js +58 -71
  109. package/dist/fingerprints/extensions.js.map +1 -1
  110. package/dist/fingerprints/ja3.d.ts +12 -30
  111. package/dist/fingerprints/ja3.d.ts.map +1 -1
  112. package/dist/fingerprints/ja3.js +12 -30
  113. package/dist/fingerprints/ja3.js.map +1 -1
  114. package/dist/fingerprints/ja4.d.ts +18 -0
  115. package/dist/fingerprints/ja4.d.ts.map +1 -0
  116. package/dist/fingerprints/ja4.js +83 -0
  117. package/dist/fingerprints/ja4.js.map +1 -0
  118. package/dist/fingerprints/profiles/chrome.d.ts +18 -21
  119. package/dist/fingerprints/profiles/chrome.d.ts.map +1 -1
  120. package/dist/fingerprints/profiles/chrome.js +35 -31
  121. package/dist/fingerprints/profiles/chrome.js.map +1 -1
  122. package/dist/fingerprints/profiles/edge.d.ts +7 -10
  123. package/dist/fingerprints/profiles/edge.d.ts.map +1 -1
  124. package/dist/fingerprints/profiles/edge.js +7 -10
  125. package/dist/fingerprints/profiles/edge.js.map +1 -1
  126. package/dist/fingerprints/profiles/firefox.d.ts +8 -11
  127. package/dist/fingerprints/profiles/firefox.d.ts.map +1 -1
  128. package/dist/fingerprints/profiles/firefox.js +8 -11
  129. package/dist/fingerprints/profiles/firefox.js.map +1 -1
  130. package/dist/fingerprints/profiles/safari.d.ts +11 -14
  131. package/dist/fingerprints/profiles/safari.d.ts.map +1 -1
  132. package/dist/fingerprints/profiles/safari.js +11 -14
  133. package/dist/fingerprints/profiles/safari.js.map +1 -1
  134. package/dist/fingerprints/profiles/tor.d.ts +5 -8
  135. package/dist/fingerprints/profiles/tor.d.ts.map +1 -1
  136. package/dist/fingerprints/profiles/tor.js +5 -8
  137. package/dist/fingerprints/profiles/tor.js.map +1 -1
  138. package/dist/fingerprints/types.d.ts +42 -73
  139. package/dist/fingerprints/types.d.ts.map +1 -1
  140. package/dist/hsts/store.d.ts +39 -0
  141. package/dist/hsts/store.d.ts.map +1 -0
  142. package/dist/hsts/store.js +163 -0
  143. package/dist/hsts/store.js.map +1 -0
  144. package/dist/hsts/types.d.ts +24 -0
  145. package/dist/hsts/types.d.ts.map +1 -0
  146. package/dist/hsts/types.js +2 -0
  147. package/dist/hsts/types.js.map +1 -0
  148. package/dist/http/alt-svc.d.ts +67 -0
  149. package/dist/http/alt-svc.d.ts.map +1 -0
  150. package/dist/http/alt-svc.js +186 -0
  151. package/dist/http/alt-svc.js.map +1 -0
  152. package/dist/http/early-hints.d.ts +23 -0
  153. package/dist/http/early-hints.d.ts.map +1 -0
  154. package/dist/http/early-hints.js +33 -0
  155. package/dist/http/early-hints.js.map +1 -0
  156. package/dist/http/form-data.d.ts +17 -35
  157. package/dist/http/form-data.d.ts.map +1 -1
  158. package/dist/http/form-data.js +12 -34
  159. package/dist/http/form-data.js.map +1 -1
  160. package/dist/http/h1/client.d.ts +14 -26
  161. package/dist/http/h1/client.d.ts.map +1 -1
  162. package/dist/http/h1/client.js +29 -22
  163. package/dist/http/h1/client.js.map +1 -1
  164. package/dist/http/h1/encoder.d.ts +10 -17
  165. package/dist/http/h1/encoder.d.ts.map +1 -1
  166. package/dist/http/h1/encoder.js +10 -17
  167. package/dist/http/h1/encoder.js.map +1 -1
  168. package/dist/http/h1/parser.d.ts +22 -59
  169. package/dist/http/h1/parser.d.ts.map +1 -1
  170. package/dist/http/h1/parser.js +15 -47
  171. package/dist/http/h1/parser.js.map +1 -1
  172. package/dist/http/h2/client.d.ts +18 -59
  173. package/dist/http/h2/client.d.ts.map +1 -1
  174. package/dist/http/h2/client.js +29 -64
  175. package/dist/http/h2/client.js.map +1 -1
  176. package/dist/http/h2/frames.d.ts +53 -84
  177. package/dist/http/h2/frames.d.ts.map +1 -1
  178. package/dist/http/h2/frames.js +48 -76
  179. package/dist/http/h2/frames.js.map +1 -1
  180. package/dist/http/h2/hpack.d.ts +16 -35
  181. package/dist/http/h2/hpack.d.ts.map +1 -1
  182. package/dist/http/h2/hpack.js +16 -35
  183. package/dist/http/h2/hpack.js.map +1 -1
  184. package/dist/http/h3/detection.d.ts +15 -0
  185. package/dist/http/h3/detection.d.ts.map +1 -0
  186. package/dist/http/h3/detection.js +41 -0
  187. package/dist/http/h3/detection.js.map +1 -0
  188. package/dist/http/negotiator.d.ts +43 -33
  189. package/dist/http/negotiator.d.ts.map +1 -1
  190. package/dist/http/negotiator.js +99 -41
  191. package/dist/http/negotiator.js.map +1 -1
  192. package/dist/http/pool.d.ts +34 -64
  193. package/dist/http/pool.d.ts.map +1 -1
  194. package/dist/http/pool.js +22 -41
  195. package/dist/http/pool.js.map +1 -1
  196. package/dist/http/resumable-upload.d.ts +76 -0
  197. package/dist/http/resumable-upload.d.ts.map +1 -0
  198. package/dist/http/resumable-upload.js +104 -0
  199. package/dist/http/resumable-upload.js.map +1 -0
  200. package/dist/http/trailers.d.ts +29 -0
  201. package/dist/http/trailers.d.ts.map +1 -0
  202. package/dist/http/trailers.js +57 -0
  203. package/dist/http/trailers.js.map +1 -0
  204. package/dist/index.d.ts +36 -8
  205. package/dist/index.d.ts.map +1 -1
  206. package/dist/index.js +32 -1
  207. package/dist/index.js.map +1 -1
  208. package/dist/middleware/interceptor.d.ts +13 -32
  209. package/dist/middleware/interceptor.d.ts.map +1 -1
  210. package/dist/middleware/interceptor.js +11 -16
  211. package/dist/middleware/interceptor.js.map +1 -1
  212. package/dist/middleware/rate-limiter.d.ts +8 -17
  213. package/dist/middleware/rate-limiter.d.ts.map +1 -1
  214. package/dist/middleware/rate-limiter.js +15 -12
  215. package/dist/middleware/rate-limiter.js.map +1 -1
  216. package/dist/middleware/retry-after.d.ts +15 -0
  217. package/dist/middleware/retry-after.d.ts.map +1 -0
  218. package/dist/middleware/retry-after.js +36 -0
  219. package/dist/middleware/retry-after.js.map +1 -0
  220. package/dist/middleware/retry.d.ts +9 -18
  221. package/dist/middleware/retry.d.ts.map +1 -1
  222. package/dist/middleware/retry.js +12 -9
  223. package/dist/middleware/retry.js.map +1 -1
  224. package/dist/proxy/auth.d.ts +73 -0
  225. package/dist/proxy/auth.d.ts.map +1 -0
  226. package/dist/proxy/auth.js +128 -0
  227. package/dist/proxy/auth.js.map +1 -0
  228. package/dist/proxy/env-proxy.d.ts +11 -0
  229. package/dist/proxy/env-proxy.d.ts.map +1 -0
  230. package/dist/proxy/env-proxy.js +56 -0
  231. package/dist/proxy/env-proxy.js.map +1 -0
  232. package/dist/proxy/http-proxy.d.ts +13 -18
  233. package/dist/proxy/http-proxy.d.ts.map +1 -1
  234. package/dist/proxy/http-proxy.js +24 -14
  235. package/dist/proxy/http-proxy.js.map +1 -1
  236. package/dist/proxy/socks.d.ts +13 -20
  237. package/dist/proxy/socks.d.ts.map +1 -1
  238. package/dist/proxy/socks.js +6 -9
  239. package/dist/proxy/socks.js.map +1 -1
  240. package/dist/sse/parser.d.ts +47 -0
  241. package/dist/sse/parser.d.ts.map +1 -0
  242. package/dist/sse/parser.js +139 -0
  243. package/dist/sse/parser.js.map +1 -0
  244. package/dist/tls/constants.d.ts +15 -74
  245. package/dist/tls/constants.d.ts.map +1 -1
  246. package/dist/tls/constants.js +15 -74
  247. package/dist/tls/constants.js.map +1 -1
  248. package/dist/tls/ct.d.ts +78 -0
  249. package/dist/tls/ct.d.ts.map +1 -0
  250. package/dist/tls/ct.js +175 -0
  251. package/dist/tls/ct.js.map +1 -0
  252. package/dist/tls/early-data.d.ts +45 -0
  253. package/dist/tls/early-data.d.ts.map +1 -0
  254. package/dist/tls/early-data.js +46 -0
  255. package/dist/tls/early-data.js.map +1 -0
  256. package/dist/tls/ech.d.ts +130 -0
  257. package/dist/tls/ech.d.ts.map +1 -0
  258. package/dist/tls/ech.js +353 -0
  259. package/dist/tls/ech.js.map +1 -0
  260. package/dist/tls/keylog.d.ts +34 -0
  261. package/dist/tls/keylog.d.ts.map +1 -0
  262. package/dist/tls/keylog.js +64 -0
  263. package/dist/tls/keylog.js.map +1 -0
  264. package/dist/tls/node-engine.d.ts +15 -14
  265. package/dist/tls/node-engine.d.ts.map +1 -1
  266. package/dist/tls/node-engine.js +54 -14
  267. package/dist/tls/node-engine.js.map +1 -1
  268. package/dist/tls/ocsp.d.ts +55 -0
  269. package/dist/tls/ocsp.d.ts.map +1 -0
  270. package/dist/tls/ocsp.js +131 -0
  271. package/dist/tls/ocsp.js.map +1 -0
  272. package/dist/tls/pin-verification.d.ts +10 -0
  273. package/dist/tls/pin-verification.d.ts.map +1 -0
  274. package/dist/tls/pin-verification.js +28 -0
  275. package/dist/tls/pin-verification.js.map +1 -0
  276. package/dist/tls/session-cache.d.ts +58 -0
  277. package/dist/tls/session-cache.d.ts.map +1 -0
  278. package/dist/tls/session-cache.js +76 -0
  279. package/dist/tls/session-cache.js.map +1 -0
  280. package/dist/tls/stealth/client-hello.d.ts +34 -32
  281. package/dist/tls/stealth/client-hello.d.ts.map +1 -1
  282. package/dist/tls/stealth/client-hello.js +116 -11
  283. package/dist/tls/stealth/client-hello.js.map +1 -1
  284. package/dist/tls/stealth/engine.d.ts +5 -15
  285. package/dist/tls/stealth/engine.d.ts.map +1 -1
  286. package/dist/tls/stealth/engine.js +163 -47
  287. package/dist/tls/stealth/engine.js.map +1 -1
  288. package/dist/tls/stealth/handshake.d.ts +23 -32
  289. package/dist/tls/stealth/handshake.d.ts.map +1 -1
  290. package/dist/tls/stealth/handshake.js +112 -27
  291. package/dist/tls/stealth/handshake.js.map +1 -1
  292. package/dist/tls/stealth/key-schedule.d.ts +59 -86
  293. package/dist/tls/stealth/key-schedule.d.ts.map +1 -1
  294. package/dist/tls/stealth/key-schedule.js +46 -58
  295. package/dist/tls/stealth/key-schedule.js.map +1 -1
  296. package/dist/tls/stealth/record-layer.d.ts +52 -75
  297. package/dist/tls/stealth/record-layer.d.ts.map +1 -1
  298. package/dist/tls/stealth/record-layer.js +47 -63
  299. package/dist/tls/stealth/record-layer.js.map +1 -1
  300. package/dist/tls/stealth/tls12-handshake.d.ts +30 -0
  301. package/dist/tls/stealth/tls12-handshake.d.ts.map +1 -0
  302. package/dist/tls/stealth/tls12-handshake.js +470 -0
  303. package/dist/tls/stealth/tls12-handshake.js.map +1 -0
  304. package/dist/tls/types.d.ts +46 -48
  305. package/dist/tls/types.d.ts.map +1 -1
  306. package/dist/utils/buffer-reader.d.ts +26 -81
  307. package/dist/utils/buffer-reader.d.ts.map +1 -1
  308. package/dist/utils/buffer-reader.js +26 -81
  309. package/dist/utils/buffer-reader.js.map +1 -1
  310. package/dist/utils/buffer-writer.d.ts +30 -66
  311. package/dist/utils/buffer-writer.d.ts.map +1 -1
  312. package/dist/utils/buffer-writer.js +30 -66
  313. package/dist/utils/buffer-writer.js.map +1 -1
  314. package/dist/utils/compression.d.ts +18 -0
  315. package/dist/utils/compression.d.ts.map +1 -0
  316. package/dist/utils/compression.js +34 -0
  317. package/dist/utils/compression.js.map +1 -0
  318. package/dist/utils/dictionary-transport.d.ts +97 -0
  319. package/dist/utils/dictionary-transport.d.ts.map +1 -0
  320. package/dist/utils/dictionary-transport.js +171 -0
  321. package/dist/utils/dictionary-transport.js.map +1 -0
  322. package/dist/utils/encoding.d.ts +12 -28
  323. package/dist/utils/encoding.d.ts.map +1 -1
  324. package/dist/utils/encoding.js +77 -40
  325. package/dist/utils/encoding.js.map +1 -1
  326. package/dist/utils/happy-eyeballs.d.ts +20 -7
  327. package/dist/utils/happy-eyeballs.d.ts.map +1 -1
  328. package/dist/utils/happy-eyeballs.js +57 -25
  329. package/dist/utils/happy-eyeballs.js.map +1 -1
  330. package/dist/utils/logger.d.ts +54 -81
  331. package/dist/utils/logger.d.ts.map +1 -1
  332. package/dist/utils/logger.js +92 -64
  333. package/dist/utils/logger.js.map +1 -1
  334. package/dist/utils/tcp-fast-open.d.ts +30 -0
  335. package/dist/utils/tcp-fast-open.d.ts.map +1 -0
  336. package/dist/utils/tcp-fast-open.js +36 -0
  337. package/dist/utils/tcp-fast-open.js.map +1 -0
  338. package/dist/utils/url.d.ts +18 -25
  339. package/dist/utils/url.d.ts.map +1 -1
  340. package/dist/utils/url.js +18 -25
  341. package/dist/utils/url.js.map +1 -1
  342. package/dist/ws/client.d.ts +35 -52
  343. package/dist/ws/client.d.ts.map +1 -1
  344. package/dist/ws/client.js +92 -37
  345. package/dist/ws/client.js.map +1 -1
  346. package/dist/ws/frame.d.ts +27 -42
  347. package/dist/ws/frame.d.ts.map +1 -1
  348. package/dist/ws/frame.js +25 -37
  349. package/dist/ws/frame.js.map +1 -1
  350. package/dist/ws/permessage-deflate.d.ts +53 -0
  351. package/dist/ws/permessage-deflate.d.ts.map +1 -0
  352. package/dist/ws/permessage-deflate.js +140 -0
  353. package/dist/ws/permessage-deflate.js.map +1 -0
  354. package/package.json +62 -62
@@ -5,24 +5,17 @@ const LEVEL_ORDER = {
5
5
  error: 3,
6
6
  silent: 4,
7
7
  };
8
- /**
9
- * Default {@link Logger} implementation that writes to `process.stderr`.
10
- * Messages are prefixed with `[nlcurl:<level>]` and only emitted when the
11
- * message severity meets or exceeds the configured `level`.
12
- *
13
- * Supports scoped child loggers via {@link ConsoleLogger.child}, which
14
- * prepend a component tag to every message for easy filtering.
15
- */
8
+ /** Logger implementation that writes to `stderr` with level filtering. */
16
9
  export class ConsoleLogger {
17
10
  level;
18
11
  prefix;
19
12
  bindings;
20
13
  /**
21
- * Creates a new ConsoleLogger.
14
+ * Create a console logger.
22
15
  *
23
- * @param {LogLevel} [level='warn'] - Minimum severity level to emit.
24
- * @param {string} [prefix=''] - Component prefix prepended to every message.
25
- * @param {LogBindings} [bindings={}] - Key-value metadata appended to every message.
16
+ * @param {LogLevel} level - Minimum severity to output.
17
+ * @param {string} prefix - Namespace prefix for log lines.
18
+ * @param {LogBindings} bindings - Structured context fields.
26
19
  */
27
20
  constructor(level = "warn", prefix = "", bindings = {}) {
28
21
  this.level = LEVEL_ORDER[level];
@@ -30,17 +23,10 @@ export class ConsoleLogger {
30
23
  this.bindings = bindings;
31
24
  }
32
25
  /**
33
- * Creates a child logger that inherits this logger's level and prepends
34
- * an additional component tag to every message. Bindings from the parent
35
- * are merged with the child's bindings (child values win on conflict).
36
- *
37
- * @param {LogBindings} bindings - Additional metadata for the child scope.
38
- * @returns {ConsoleLogger} A new scoped logger instance.
26
+ * Create a child logger with additional bindings.
39
27
  *
40
- * @example
41
- * const logger = new ConsoleLogger('debug');
42
- * const child = logger.child({ component: 'h2' });
43
- * child.debug('stream opened', { streamId: 1 });
28
+ * @param {LogBindings} bindings - Extra structured context fields.
29
+ * @returns {ConsoleLogger} New child `ConsoleLogger`.
44
30
  */
45
31
  child(bindings) {
46
32
  const component = typeof bindings["component"] === "string" ? bindings["component"] : "";
@@ -49,57 +35,32 @@ export class ConsoleLogger {
49
35
  return new ConsoleLogger(this.resolveLevel(), childPrefix, merged);
50
36
  }
51
37
  /**
52
- * Updates the minimum severity level at runtime without creating a new
53
- * logger instance.
38
+ * Change the minimum log level at runtime.
54
39
  *
55
- * @param {LogLevel} level - New minimum severity level.
40
+ * @param {LogLevel} level - New severity threshold.
56
41
  */
57
42
  setLevel(level) {
58
43
  this.level = LEVEL_ORDER[level];
59
44
  }
60
- /**
61
- * Emits a debug-level message to `stderr` -- only written when the
62
- * configured minimum level is `'debug'`.
63
- *
64
- * @param {string} message - Primary log message.
65
- * @param {...unknown} args - Additional values appended after the message.
66
- */
45
+ /** Log a debug-level message. */
67
46
  debug(message, ...args) {
68
47
  if (this.level <= LEVEL_ORDER.debug) {
69
48
  this.write("debug", message, args);
70
49
  }
71
50
  }
72
- /**
73
- * Emits an info-level message to `stderr` -- only written when the
74
- * configured minimum level is `'debug'` or `'info'`.
75
- *
76
- * @param {string} message - Primary log message.
77
- * @param {...unknown} args - Additional values appended after the message.
78
- */
51
+ /** Log an info-level message. */
79
52
  info(message, ...args) {
80
53
  if (this.level <= LEVEL_ORDER.info) {
81
54
  this.write("info", message, args);
82
55
  }
83
56
  }
84
- /**
85
- * Emits a warn-level message to `stderr` -- only written when the
86
- * configured minimum level is `'debug'`, `'info'`, or `'warn'`.
87
- *
88
- * @param {string} message - Primary log message.
89
- * @param {...unknown} args - Additional values appended after the message.
90
- */
57
+ /** Log a warning-level message. */
91
58
  warn(message, ...args) {
92
59
  if (this.level <= LEVEL_ORDER.warn) {
93
60
  this.write("warn", message, args);
94
61
  }
95
62
  }
96
- /**
97
- * Emits an error-level message to `stderr` -- only written when the
98
- * configured minimum level is not `'silent'`.
99
- *
100
- * @param {string} message - Primary log message.
101
- * @param {...unknown} args - Additional values appended after the message.
102
- */
63
+ /** Log an error-level message. */
103
64
  error(message, ...args) {
104
65
  if (this.level <= LEVEL_ORDER.error) {
105
66
  this.write("error", message, args);
@@ -122,30 +83,97 @@ export class ConsoleLogger {
122
83
  return "warn";
123
84
  }
124
85
  }
125
- /**
126
- * A no-op {@link Logger} that discards all messages. Assign this via
127
- * {@link setDefaultLogger} to silence the library entirely.
128
- */
86
+ /** Singleton no-op logger that discards all messages. */
129
87
  export const SILENT_LOGGER = {
130
88
  debug() { },
131
89
  info() { },
132
90
  warn() { },
133
91
  error() { },
134
92
  };
93
+ /** Logger implementation that writes structured JSON to `stderr` with level filtering. */
94
+ export class JsonLogger {
95
+ level;
96
+ service;
97
+ bindings;
98
+ /**
99
+ * Create a JSON logger.
100
+ *
101
+ * @param {LogLevel} level - Minimum severity to output.
102
+ * @param {string} service - Service name included in every log entry.
103
+ * @param {LogBindings} bindings - Structured context fields.
104
+ */
105
+ constructor(level = "warn", service = "nlcurl", bindings = {}) {
106
+ this.level = LEVEL_ORDER[level];
107
+ this.service = service;
108
+ this.bindings = bindings;
109
+ }
110
+ /**
111
+ * Create a child JSON logger with additional bindings.
112
+ *
113
+ * @param {LogBindings} bindings - Extra structured context fields.
114
+ * @returns {JsonLogger} New child `JsonLogger`.
115
+ */
116
+ child(bindings) {
117
+ const merged = { ...this.bindings, ...bindings };
118
+ return new JsonLogger(this.resolveLevel(), this.service, merged);
119
+ }
120
+ /**
121
+ * Change the minimum log level at runtime.
122
+ *
123
+ * @param {LogLevel} level - New severity threshold.
124
+ */
125
+ setLevel(level) {
126
+ this.level = LEVEL_ORDER[level];
127
+ }
128
+ debug(message, ...args) {
129
+ if (this.level <= LEVEL_ORDER.debug)
130
+ this.emit("debug", message, args);
131
+ }
132
+ info(message, ...args) {
133
+ if (this.level <= LEVEL_ORDER.info)
134
+ this.emit("info", message, args);
135
+ }
136
+ warn(message, ...args) {
137
+ if (this.level <= LEVEL_ORDER.warn)
138
+ this.emit("warn", message, args);
139
+ }
140
+ error(message, ...args) {
141
+ if (this.level <= LEVEL_ORDER.error)
142
+ this.emit("error", message, args);
143
+ }
144
+ emit(level, message, args) {
145
+ const entry = {
146
+ timestamp: new Date().toISOString(),
147
+ level,
148
+ message,
149
+ service: this.service,
150
+ };
151
+ for (const [k, v] of Object.entries(this.bindings)) {
152
+ entry[k] = v;
153
+ }
154
+ if (args.length > 0) {
155
+ entry["metadata"] = args;
156
+ }
157
+ process.stderr.write(JSON.stringify(entry) + "\n");
158
+ }
159
+ resolveLevel() {
160
+ for (const [name, order] of Object.entries(LEVEL_ORDER)) {
161
+ if (order === this.level)
162
+ return name;
163
+ }
164
+ return "warn";
165
+ }
166
+ }
135
167
  let _default = new ConsoleLogger("warn");
136
168
  /**
137
- * Replaces the process-wide default logger used by all NLcURL internals.
169
+ * Set the process-wide default logger.
138
170
  *
139
- * @param {Logger} logger - New logger instance to install.
171
+ * @param {Logger} logger - Logger instance to use as the default.
140
172
  */
141
173
  export function setDefaultLogger(logger) {
142
174
  _default = logger;
143
175
  }
144
- /**
145
- * Returns the currently active process-wide logger.
146
- *
147
- * @returns {Logger} The active logger instance.
148
- */
176
+ /** Return the current process-wide default logger. */
149
177
  export function getDefaultLogger() {
150
178
  return _default;
151
179
  }
@@ -1 +1 @@
1
- {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAgBA,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;AAkBF;;;;;;;GAOG;AACH,MAAM,OAAO,aAAa;IAChB,KAAK,CAAS;IACL,MAAM,CAAS;IACf,QAAQ,CAAc;IAEvC;;;;;;OAMG;IACH,YAAY,QAAkB,MAAM,EAAE,SAAiB,EAAE,EAAE,WAAwB,EAAE;QACnF,IAAI,CAAC,KAAK,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC;QAChC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,KAAK,CAAC,QAAqB;QACzB,MAAM,SAAS,GAAG,OAAO,QAAQ,CAAC,WAAW,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,CAA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AAE;YACnC,KAAK;YACL,OAAO;YACP,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC;QACF,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;YACnD,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QACf,CAAC;QACD,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACpB,KAAK,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC;QAC3B,CAAC;QACD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;IACrD,CAAC;IAEO,YAAY;QAClB,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC;YACxD,IAAI,KAAK,KAAK,IAAI,CAAC,KAAK;gBAAE,OAAO,IAAgB,CAAC;QACpD,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAED,IAAI,QAAQ,GAAW,IAAI,aAAa,CAAC,MAAM,CAAC,CAAC;AAEjD;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAc;IAC7C,QAAQ,GAAG,MAAM,CAAC;AACpB,CAAC;AAED,sDAAsD;AACtD,MAAM,UAAU,gBAAgB;IAC9B,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Check whether TCP Fast Open is supported on the current platform.
3
+ *
4
+ * @returns {boolean} `true` on Linux and macOS.
5
+ */
6
+ export declare function isTFOSupported(): boolean;
7
+ /** Configuration for TCP Fast Open (TFO). */
8
+ export interface TFOOptions {
9
+ /** Enable TCP Fast Open for the connection. */
10
+ enabled?: boolean;
11
+ /** Data to send during the TCP handshake. */
12
+ connectData?: Buffer;
13
+ }
14
+ /**
15
+ * Build socket creation options for TCP Fast Open.
16
+ *
17
+ * @param {TFOOptions} [tfo] - TFO configuration.
18
+ * @returns {Record<string, unknown>} Options object to merge into socket creation.
19
+ */
20
+ export declare function buildTFOSocketOptions(tfo?: TFOOptions): Record<string, unknown>;
21
+ /**
22
+ * Return the current TFO support status and platform name.
23
+ *
24
+ * @returns {{ supported: boolean; platform: string }} Object with `supported` flag and `platform` string.
25
+ */
26
+ export declare function getTFOStatus(): {
27
+ supported: boolean;
28
+ platform: string;
29
+ };
30
+ //# sourceMappingURL=tcp-fast-open.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tcp-fast-open.d.ts","sourceRoot":"","sources":["../../src/utils/tcp-fast-open.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,cAAc,IAAI,OAAO,CAGxC;AAED,6CAA6C;AAC7C,MAAM,WAAW,UAAU;IACzB,+CAA+C;IAC/C,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,6CAA6C;IAC7C,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,CAAC,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAQ/E;AAED;;;;GAIG;AACH,wBAAgB,YAAY,IAAI;IAAE,SAAS,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAKvE"}
@@ -0,0 +1,36 @@
1
+ import { platform } from "node:os";
2
+ /**
3
+ * Check whether TCP Fast Open is supported on the current platform.
4
+ *
5
+ * @returns {boolean} `true` on Linux and macOS.
6
+ */
7
+ export function isTFOSupported() {
8
+ const os = platform();
9
+ return os === "linux" || os === "darwin";
10
+ }
11
+ /**
12
+ * Build socket creation options for TCP Fast Open.
13
+ *
14
+ * @param {TFOOptions} [tfo] - TFO configuration.
15
+ * @returns {Record<string, unknown>} Options object to merge into socket creation.
16
+ */
17
+ export function buildTFOSocketOptions(tfo) {
18
+ if (!tfo?.enabled || !isTFOSupported()) {
19
+ return {};
20
+ }
21
+ return {
22
+ fastOpen: true,
23
+ };
24
+ }
25
+ /**
26
+ * Return the current TFO support status and platform name.
27
+ *
28
+ * @returns {{ supported: boolean; platform: string }} Object with `supported` flag and `platform` string.
29
+ */
30
+ export function getTFOStatus() {
31
+ return {
32
+ supported: isTFOSupported(),
33
+ platform: platform(),
34
+ };
35
+ }
36
+ //# sourceMappingURL=tcp-fast-open.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tcp-fast-open.js","sourceRoot":"","sources":["../../src/utils/tcp-fast-open.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC;;;;GAIG;AACH,MAAM,UAAU,cAAc;IAC5B,MAAM,EAAE,GAAG,QAAQ,EAAE,CAAC;IACtB,OAAO,EAAE,KAAK,OAAO,IAAI,EAAE,KAAK,QAAQ,CAAC;AAC3C,CAAC;AAUD;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAC,GAAgB;IACpD,IAAI,CAAC,GAAG,EAAE,OAAO,IAAI,CAAC,cAAc,EAAE,EAAE,CAAC;QACvC,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,OAAO;QACL,QAAQ,EAAE,IAAI;KACf,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,YAAY;IAC1B,OAAO;QACL,SAAS,EAAE,cAAc,EAAE;QAC3B,QAAQ,EAAE,QAAQ,EAAE;KACrB,CAAC;AACJ,CAAC"}
@@ -1,62 +1,55 @@
1
1
  /**
2
- * Resolves `relative` against `base`. When `base` is `undefined` or the
3
- * resolution fails, `relative` is returned as-is.
2
+ * Resolve a relative URL against an optional base.
4
3
  *
5
- * @param {string | undefined} base - Base URL string.
6
- * @param {string} relative - Relative or absolute URL to resolve.
7
- * @returns {string} The resolved absolute URL, or `relative` if resolution fails.
4
+ * @param {string | undefined} base - Base URL string.
5
+ * @param {string} relative - Relative or absolute URL string.
6
+ * @returns {string} Resolved absolute URL string.
8
7
  */
9
8
  export declare function resolveURL(base: string | undefined, relative: string): string;
10
9
  /**
11
- * Appends `params` as query-string parameters to `url`. Existing parameters in
12
- * the URL are preserved. `undefined` and `null` values are omitted.
10
+ * Append query parameters to a URL string.
13
11
  *
14
- * @param {string} url - Base URL.
15
- * @param {Record<string, string | number | boolean>} [params] - Key-value pairs to append.
16
- * @returns {string} URL with appended query parameters.
12
+ * @param {string} url - Base URL string.
13
+ * @param {Record<string, string | number | boolean>} [params] - Key-value pairs to append.
14
+ * @returns {string} URL string with appended query parameters.
17
15
  */
18
16
  export declare function appendParams(url: string, params?: Record<string, string | number | boolean>): string;
19
17
  /**
20
- * Parses `raw` into a `URL` object.
18
+ * Parse a URL string into a `URL` object.
21
19
  *
22
- * @param {string} raw - Absolute URL string to parse.
23
- * @returns {URL} Parsed URL.
24
- * @throws {TypeError} If `raw` is not a valid absolute URL.
20
+ * @param {string} raw - Raw URL string.
21
+ * @returns {URL} Parsed `URL` instance.
25
22
  */
26
23
  export declare function parseURL(raw: string): URL;
27
24
  /**
28
- * Returns the origin of `url` in `scheme://hostname:port` form. The port is
29
- * always included explicitly, defaulting to `443` for `https:` and `80` for
30
- * `http:`.
25
+ * Extract the origin (scheme + hostname + port) from a URL.
31
26
  *
32
27
  * @param {string} url - Absolute URL string.
33
28
  * @returns {string} Origin string (e.g. `"https://example.com:443"`).
34
29
  */
35
30
  export declare function originOf(url: string): string;
36
31
  /**
37
- * Extracts the hostname from `url` for use as the TLS SNI server-name value.
32
+ * Extract the hostname for TLS SNI from a URL.
38
33
  *
39
34
  * @param {string} url - Absolute URL string.
40
- * @returns {string} Hostname without port (e.g. `"example.com"`).
35
+ * @returns {string} Hostname string.
41
36
  */
42
37
  export declare function sniHost(url: string): string;
43
38
  /**
44
- * Extracts the host and port from `url`. The port defaults to `443` for
45
- * `https:` and `80` for `http:` when not explicitly specified in the URL.
39
+ * Extract the hostname and port from a URL.
46
40
  *
47
41
  * @param {string} url - Absolute URL string.
48
- * @returns {{ host: string; port: number }} Hostname and numeric port.
42
+ * @returns {{ host: string; port: number }} Object with `host` and numeric `port`.
49
43
  */
50
44
  export declare function hostPort(url: string): {
51
45
  host: string;
52
46
  port: number;
53
47
  };
54
48
  /**
55
- * Returns the path and query string of `url` suitable for use as the
56
- * request-target in an HTTP/1.1 request line.
49
+ * Extract the request path (pathname + search) from a URL.
57
50
  *
58
51
  * @param {string} url - Absolute URL string.
59
- * @returns {string} Path + query string (e.g. `"/search?q=hello"`).
52
+ * @returns {string} Path string suitable for an HTTP request line.
60
53
  */
61
54
  export declare function requestPath(url: string): string;
62
55
  //# sourceMappingURL=url.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../../src/utils/url.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAO7E;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,GAAG,MAAM,CASpG;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAEzC;AAED;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAI5C;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAOpE;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAG/C"}
1
+ {"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../../src/utils/url.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAO7E;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,GAAG,MAAM,CASpG;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAEzC;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAI5C;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAOpE;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAG/C"}
package/dist/utils/url.js CHANGED
@@ -1,10 +1,9 @@
1
1
  /**
2
- * Resolves `relative` against `base`. When `base` is `undefined` or the
3
- * resolution fails, `relative` is returned as-is.
2
+ * Resolve a relative URL against an optional base.
4
3
  *
5
- * @param {string | undefined} base - Base URL string.
6
- * @param {string} relative - Relative or absolute URL to resolve.
7
- * @returns {string} The resolved absolute URL, or `relative` if resolution fails.
4
+ * @param {string | undefined} base - Base URL string.
5
+ * @param {string} relative - Relative or absolute URL string.
6
+ * @returns {string} Resolved absolute URL string.
8
7
  */
9
8
  export function resolveURL(base, relative) {
10
9
  if (!base)
@@ -17,12 +16,11 @@ export function resolveURL(base, relative) {
17
16
  }
18
17
  }
19
18
  /**
20
- * Appends `params` as query-string parameters to `url`. Existing parameters in
21
- * the URL are preserved. `undefined` and `null` values are omitted.
19
+ * Append query parameters to a URL string.
22
20
  *
23
- * @param {string} url - Base URL.
24
- * @param {Record<string, string | number | boolean>} [params] - Key-value pairs to append.
25
- * @returns {string} URL with appended query parameters.
21
+ * @param {string} url - Base URL string.
22
+ * @param {Record<string, string | number | boolean>} [params] - Key-value pairs to append.
23
+ * @returns {string} URL string with appended query parameters.
26
24
  */
27
25
  export function appendParams(url, params) {
28
26
  if (!params || Object.keys(params).length === 0)
@@ -36,19 +34,16 @@ export function appendParams(url, params) {
36
34
  return parsed.toString();
37
35
  }
38
36
  /**
39
- * Parses `raw` into a `URL` object.
37
+ * Parse a URL string into a `URL` object.
40
38
  *
41
- * @param {string} raw - Absolute URL string to parse.
42
- * @returns {URL} Parsed URL.
43
- * @throws {TypeError} If `raw` is not a valid absolute URL.
39
+ * @param {string} raw - Raw URL string.
40
+ * @returns {URL} Parsed `URL` instance.
44
41
  */
45
42
  export function parseURL(raw) {
46
43
  return new URL(raw);
47
44
  }
48
45
  /**
49
- * Returns the origin of `url` in `scheme://hostname:port` form. The port is
50
- * always included explicitly, defaulting to `443` for `https:` and `80` for
51
- * `http:`.
46
+ * Extract the origin (scheme + hostname + port) from a URL.
52
47
  *
53
48
  * @param {string} url - Absolute URL string.
54
49
  * @returns {string} Origin string (e.g. `"https://example.com:443"`).
@@ -59,20 +54,19 @@ export function originOf(url) {
59
54
  return `${u.protocol}//${u.hostname}:${port}`;
60
55
  }
61
56
  /**
62
- * Extracts the hostname from `url` for use as the TLS SNI server-name value.
57
+ * Extract the hostname for TLS SNI from a URL.
63
58
  *
64
59
  * @param {string} url - Absolute URL string.
65
- * @returns {string} Hostname without port (e.g. `"example.com"`).
60
+ * @returns {string} Hostname string.
66
61
  */
67
62
  export function sniHost(url) {
68
63
  return new URL(url).hostname;
69
64
  }
70
65
  /**
71
- * Extracts the host and port from `url`. The port defaults to `443` for
72
- * `https:` and `80` for `http:` when not explicitly specified in the URL.
66
+ * Extract the hostname and port from a URL.
73
67
  *
74
68
  * @param {string} url - Absolute URL string.
75
- * @returns {{ host: string; port: number }} Hostname and numeric port.
69
+ * @returns {{ host: string; port: number }} Object with `host` and numeric `port`.
76
70
  */
77
71
  export function hostPort(url) {
78
72
  const u = new URL(url);
@@ -83,11 +77,10 @@ export function hostPort(url) {
83
77
  };
84
78
  }
85
79
  /**
86
- * Returns the path and query string of `url` suitable for use as the
87
- * request-target in an HTTP/1.1 request line.
80
+ * Extract the request path (pathname + search) from a URL.
88
81
  *
89
82
  * @param {string} url - Absolute URL string.
90
- * @returns {string} Path + query string (e.g. `"/search?q=hello"`).
83
+ * @returns {string} Path string suitable for an HTTP request line.
91
84
  */
92
85
  export function requestPath(url) {
93
86
  const u = new URL(url);
@@ -1 +1 @@
1
- {"version":3,"file":"url.js","sourceRoot":"","sources":["../../src/utils/url.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,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;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAAC,GAAW,EAAE,MAAkD;IAC1F,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,IA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connection.
4
- *
5
- * @typedef {Object} WebSocketOptions
6
- * @property {string} [impersonate] - Browser profile name for fingerprint impersonation.
7
- * @property {boolean} [stealth] - Use the stealth TLS engine for byte-level fingerprinting.
8
- * @property {Record<string, string>} [headers] - Additional HTTP upgrade request headers.
9
- * @property {string[]} [protocols] - Sub-protocol names to negotiate.
10
- * @property {boolean} [insecure] - Skip TLS certificate validation for `wss:` connections.
11
- * @property {number} [timeout] - Connection timeout in milliseconds.
12
- */
2
+ /** Configuration options for a WebSocket connection. */
13
3
  export interface WebSocketOptions {
4
+ /** Browser profile name to impersonate for TLS fingerprinting. */
14
5
  impersonate?: string;
6
+ /** Use the stealth TLS engine for fingerprint impersonation. */
15
7
  stealth?: boolean;
8
+ /** Additional HTTP headers to include in the upgrade request. */
16
9
  headers?: Record<string, string>;
10
+ /** Subprotocols to offer during the upgrade handshake. */
17
11
  protocols?: string[];
12
+ /** Skip TLS certificate verification. */
18
13
  insecure?: boolean;
14
+ /** Connection timeout in milliseconds. */
19
15
  timeout?: number;
16
+ /** Enable per-message deflate compression. */
17
+ compress?: boolean;
20
18
  }
21
- /**
22
- * WebSocket connection state.
23
- *
24
- * @typedef {'connecting' | 'open' | 'closing' | 'closed'} WebSocketState
25
- */
19
+ /** Current lifecycle state of the WebSocket connection. */
26
20
  export type WebSocketState = "connecting" | "open" | "closing" | "closed";
27
- /**
28
- * Typed event map for {@link WebSocketClient}.
29
- *
30
- * @typedef {Object} WebSocketEvents
31
- * @property {[]} open - Emitted when the connection is established.
32
- * @property {[data: string | Buffer, isBinary: boolean]} message - Emitted for each incoming message.
33
- * @property {[code: number, reason: string]} close - Emitted when the connection closes.
34
- * @property {[error: Error]} error - Emitted on connection or protocol errors.
35
- * @property {[data: Buffer]} ping - Emitted when a PING frame is received.
36
- * @property {[data: Buffer]} pong - Emitted when a PONG frame is received.
37
- */
21
+ /** Event map for {@link WebSocketClient} emitter. */
38
22
  export interface WebSocketEvents {
23
+ /** Fired when the connection has been established. */
39
24
  open: [];
25
+ /** Fired when a text or binary message is received. */
40
26
  message: [data: string | Buffer, isBinary: boolean];
27
+ /** Fired when the connection has been cleanly closed. */
41
28
  close: [code: number, reason: string];
29
+ /** Fired on transport or protocol errors. */
42
30
  error: [error: Error];
31
+ /** Fired when a ping frame is received. */
43
32
  ping: [data: Buffer];
33
+ /** Fired when a pong frame is received. */
44
34
  pong: [data: Buffer];
45
35
  }
46
36
  /**
47
- * WebSocket client with optional browser fingerprint impersonation. Emits
48
- * typed lifecycle events (`open`, `message`, `close`, `error`, `ping`, `pong`).
49
- * The connection is initiated asynchronously in the constructor; listen for
50
- * the `'open'` event before sending frames.
51
- *
52
- * @example
53
- * const ws = new WebSocketClient('wss://echo.example.com', { impersonate: 'chrome136' });
54
- * ws.on('open', () => ws.sendText('hello'));
55
- * ws.on('message', (data) => console.log(data));
37
+ * RFC 6455 WebSocket client with optional TLS fingerprinting
38
+ * and per-message deflate compression.
56
39
  */
57
40
  export declare class WebSocketClient extends EventEmitter {
41
+ /** Current connection lifecycle state. */
58
42
  state: WebSocketState;
43
+ /** Negotiated subprotocol, or empty string if none. */
59
44
  protocol: string;
45
+ /** Original WebSocket URL. */
60
46
  readonly url: string;
61
47
  private socket;
62
48
  private parser;
63
49
  private fragments;
64
50
  private fragmentOpcode;
51
+ private deflate;
65
52
  /**
66
- * Creates a new WebSocketClient and begins connecting to `url`.
53
+ * Create a new WebSocket connection.
67
54
  *
68
- * @param {string} url - WebSocket URL (`ws:` or `wss:`).
69
- * @param {WebSocketOptions} [options={}] - Connection and impersonation options.
55
+ * @param {string} url - `ws://` or `wss://` URL to connect to.
56
+ * @param {WebSocketOptions} [options] - Connection and TLS options.
70
57
  */
71
58
  constructor(url: string, options?: WebSocketOptions);
72
59
  /**
73
- * Sends a UTF-8 text message.
60
+ * Send a UTF-8 text message.
74
61
  *
75
- * @param {string} data - Text to send.
76
- * @throws {NLcURLError} If the WebSocket is not in the `'open'` state.
62
+ * @param {string} data - Text payload to send.
77
63
  */
78
64
  sendText(data: string): void;
79
65
  /**
80
- * Sends a binary message.
66
+ * Send a binary message.
81
67
  *
82
- * @param {Buffer} data - Binary data to send.
83
- * @throws {NLcURLError} If the WebSocket is not in the `'open'` state.
68
+ * @param {Buffer} data - Binary payload to send.
84
69
  */
85
70
  sendBinary(data: Buffer): void;
86
71
  /**
87
- * Sends a PING control frame.
72
+ * Send a WebSocket ping frame.
88
73
  *
89
- * @param {Buffer} [data=Buffer.alloc(0)] - Optional ping payload (up to 125 bytes).
90
- * @throws {NLcURLError} If the WebSocket is not in the `'open'` state.
74
+ * @param {Buffer} [data] - Optional payload (up to 125 bytes).
91
75
  */
92
76
  ping(data?: Buffer): void;
93
77
  /**
94
- * Initiates a graceful close handshake by sending a CLOSE frame with the
95
- * given status code and reason. Does nothing if the connection is not open.
78
+ * Initiate a graceful close handshake.
96
79
  *
97
- * @param {number} [code=1000] - WebSocket close status code.
98
- * @param {string} [reason=''] - Human-readable close reason (UTF-8, max 123 bytes).
80
+ * @param {number} [code] - Close status code (default `1000`).
81
+ * @param {string} [reason] - Human-readable close reason.
99
82
  */
100
83
  close(code?: number, reason?: string): void;
101
84
  private assertOpen;