nlcurl 0.1.0 → 0.2.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 (197) hide show
  1. package/README.md +5 -13
  2. package/dist/cli/args.d.ts +37 -5
  3. package/dist/cli/args.d.ts.map +1 -1
  4. package/dist/cli/args.js +6 -17
  5. package/dist/cli/args.js.map +1 -1
  6. package/dist/cli/index.d.ts +3 -3
  7. package/dist/cli/index.js +25 -10
  8. package/dist/cli/index.js.map +1 -1
  9. package/dist/cli/output.d.ts +24 -7
  10. package/dist/cli/output.d.ts.map +1 -1
  11. package/dist/cli/output.js +24 -12
  12. package/dist/cli/output.js.map +1 -1
  13. package/dist/cookies/jar.d.ts +45 -13
  14. package/dist/cookies/jar.d.ts.map +1 -1
  15. package/dist/cookies/jar.js +88 -29
  16. package/dist/cookies/jar.js.map +1 -1
  17. package/dist/cookies/parser.d.ts +25 -3
  18. package/dist/cookies/parser.d.ts.map +1 -1
  19. package/dist/cookies/parser.js +12 -7
  20. package/dist/cookies/parser.js.map +1 -1
  21. package/dist/core/client.d.ts +49 -33
  22. package/dist/core/client.d.ts.map +1 -1
  23. package/dist/core/client.js +64 -38
  24. package/dist/core/client.js.map +1 -1
  25. package/dist/core/errors.d.ts +94 -6
  26. package/dist/core/errors.d.ts.map +1 -1
  27. package/dist/core/errors.js +95 -6
  28. package/dist/core/errors.js.map +1 -1
  29. package/dist/core/request.d.ts +96 -30
  30. package/dist/core/request.d.ts.map +1 -1
  31. package/dist/core/request.js +0 -3
  32. package/dist/core/request.js.map +1 -1
  33. package/dist/core/response.d.ts +92 -8
  34. package/dist/core/response.d.ts.map +1 -1
  35. package/dist/core/response.js +92 -7
  36. package/dist/core/response.js.map +1 -1
  37. package/dist/core/session.d.ts +109 -14
  38. package/dist/core/session.d.ts.map +1 -1
  39. package/dist/core/session.js +124 -46
  40. package/dist/core/session.js.map +1 -1
  41. package/dist/fingerprints/akamai.d.ts +11 -11
  42. package/dist/fingerprints/akamai.d.ts.map +1 -1
  43. package/dist/fingerprints/akamai.js +10 -14
  44. package/dist/fingerprints/akamai.js.map +1 -1
  45. package/dist/fingerprints/database.d.ts +14 -15
  46. package/dist/fingerprints/database.d.ts.map +1 -1
  47. package/dist/fingerprints/database.js +14 -19
  48. package/dist/fingerprints/database.js.map +1 -1
  49. package/dist/fingerprints/extensions.d.ts +121 -27
  50. package/dist/fingerprints/extensions.d.ts.map +1 -1
  51. package/dist/fingerprints/extensions.js +132 -49
  52. package/dist/fingerprints/extensions.js.map +1 -1
  53. package/dist/fingerprints/ja3.d.ts +34 -18
  54. package/dist/fingerprints/ja3.d.ts.map +1 -1
  55. package/dist/fingerprints/ja3.js +34 -18
  56. package/dist/fingerprints/ja3.js.map +1 -1
  57. package/dist/fingerprints/profiles/chrome.d.ts +21 -10
  58. package/dist/fingerprints/profiles/chrome.d.ts.map +1 -1
  59. package/dist/fingerprints/profiles/chrome.js +25 -22
  60. package/dist/fingerprints/profiles/chrome.js.map +1 -1
  61. package/dist/fingerprints/profiles/edge.d.ts +10 -7
  62. package/dist/fingerprints/profiles/edge.d.ts.map +1 -1
  63. package/dist/fingerprints/profiles/edge.js +10 -10
  64. package/dist/fingerprints/profiles/edge.js.map +1 -1
  65. package/dist/fingerprints/profiles/firefox.d.ts +11 -3
  66. package/dist/fingerprints/profiles/firefox.d.ts.map +1 -1
  67. package/dist/fingerprints/profiles/firefox.js +15 -14
  68. package/dist/fingerprints/profiles/firefox.js.map +1 -1
  69. package/dist/fingerprints/profiles/safari.d.ts +14 -3
  70. package/dist/fingerprints/profiles/safari.d.ts.map +1 -1
  71. package/dist/fingerprints/profiles/safari.js +16 -13
  72. package/dist/fingerprints/profiles/safari.js.map +1 -1
  73. package/dist/fingerprints/profiles/tor.d.ts +8 -7
  74. package/dist/fingerprints/profiles/tor.d.ts.map +1 -1
  75. package/dist/fingerprints/profiles/tor.js +8 -14
  76. package/dist/fingerprints/profiles/tor.js.map +1 -1
  77. package/dist/fingerprints/types.d.ts +70 -47
  78. package/dist/fingerprints/types.d.ts.map +1 -1
  79. package/dist/fingerprints/types.js +0 -7
  80. package/dist/fingerprints/types.js.map +1 -1
  81. package/dist/http/h1/client.d.ts +30 -9
  82. package/dist/http/h1/client.d.ts.map +1 -1
  83. package/dist/http/h1/client.js +152 -15
  84. package/dist/http/h1/client.js.map +1 -1
  85. package/dist/http/h1/encoder.d.ts +9 -6
  86. package/dist/http/h1/encoder.d.ts.map +1 -1
  87. package/dist/http/h1/encoder.js +8 -12
  88. package/dist/http/h1/encoder.js.map +1 -1
  89. package/dist/http/h1/parser.d.ts +68 -14
  90. package/dist/http/h1/parser.d.ts.map +1 -1
  91. package/dist/http/h1/parser.js +92 -37
  92. package/dist/http/h1/parser.js.map +1 -1
  93. package/dist/http/h2/client.d.ts +81 -14
  94. package/dist/http/h2/client.d.ts.map +1 -1
  95. package/dist/http/h2/client.js +465 -63
  96. package/dist/http/h2/client.js.map +1 -1
  97. package/dist/http/h2/frames.d.ts +103 -6
  98. package/dist/http/h2/frames.d.ts.map +1 -1
  99. package/dist/http/h2/frames.js +96 -17
  100. package/dist/http/h2/frames.js.map +1 -1
  101. package/dist/http/h2/hpack.d.ts +30 -5
  102. package/dist/http/h2/hpack.d.ts.map +1 -1
  103. package/dist/http/h2/hpack.js +39 -35
  104. package/dist/http/h2/hpack.js.map +1 -1
  105. package/dist/http/negotiator.d.ts +35 -12
  106. package/dist/http/negotiator.d.ts.map +1 -1
  107. package/dist/http/negotiator.js +89 -24
  108. package/dist/http/negotiator.js.map +1 -1
  109. package/dist/http/pool.d.ts +66 -17
  110. package/dist/http/pool.d.ts.map +1 -1
  111. package/dist/http/pool.js +47 -20
  112. package/dist/http/pool.js.map +1 -1
  113. package/dist/index.d.ts +2 -3
  114. package/dist/index.d.ts.map +1 -1
  115. package/dist/index.js +0 -13
  116. package/dist/index.js.map +1 -1
  117. package/dist/middleware/interceptor.d.ts +40 -8
  118. package/dist/middleware/interceptor.d.ts.map +1 -1
  119. package/dist/middleware/interceptor.js +28 -6
  120. package/dist/middleware/interceptor.js.map +1 -1
  121. package/dist/middleware/rate-limiter.d.ts +18 -5
  122. package/dist/middleware/rate-limiter.d.ts.map +1 -1
  123. package/dist/middleware/rate-limiter.js +12 -7
  124. package/dist/middleware/rate-limiter.js.map +1 -1
  125. package/dist/middleware/retry.d.ts +17 -5
  126. package/dist/middleware/retry.d.ts.map +1 -1
  127. package/dist/middleware/retry.js +13 -11
  128. package/dist/middleware/retry.js.map +1 -1
  129. package/dist/proxy/http-proxy.d.ts +17 -9
  130. package/dist/proxy/http-proxy.d.ts.map +1 -1
  131. package/dist/proxy/http-proxy.js +9 -13
  132. package/dist/proxy/http-proxy.js.map +1 -1
  133. package/dist/proxy/socks.d.ts +20 -9
  134. package/dist/proxy/socks.d.ts.map +1 -1
  135. package/dist/proxy/socks.js +20 -31
  136. package/dist/proxy/socks.js.map +1 -1
  137. package/dist/tls/constants.d.ts +74 -4
  138. package/dist/tls/constants.d.ts.map +1 -1
  139. package/dist/tls/constants.js +75 -21
  140. package/dist/tls/constants.js.map +1 -1
  141. package/dist/tls/node-engine.d.ts +17 -16
  142. package/dist/tls/node-engine.d.ts.map +1 -1
  143. package/dist/tls/node-engine.js +20 -27
  144. package/dist/tls/node-engine.js.map +1 -1
  145. package/dist/tls/stealth/client-hello.d.ts +32 -16
  146. package/dist/tls/stealth/client-hello.d.ts.map +1 -1
  147. package/dist/tls/stealth/client-hello.js +13 -37
  148. package/dist/tls/stealth/client-hello.js.map +1 -1
  149. package/dist/tls/stealth/engine.d.ts +18 -10
  150. package/dist/tls/stealth/engine.d.ts.map +1 -1
  151. package/dist/tls/stealth/engine.js +18 -24
  152. package/dist/tls/stealth/engine.js.map +1 -1
  153. package/dist/tls/stealth/handshake.d.ts +31 -17
  154. package/dist/tls/stealth/handshake.d.ts.map +1 -1
  155. package/dist/tls/stealth/handshake.js +173 -74
  156. package/dist/tls/stealth/handshake.js.map +1 -1
  157. package/dist/tls/stealth/key-schedule.d.ts +89 -32
  158. package/dist/tls/stealth/key-schedule.d.ts.map +1 -1
  159. package/dist/tls/stealth/key-schedule.js +62 -42
  160. package/dist/tls/stealth/key-schedule.js.map +1 -1
  161. package/dist/tls/stealth/record-layer.d.ts +76 -25
  162. package/dist/tls/stealth/record-layer.d.ts.map +1 -1
  163. package/dist/tls/stealth/record-layer.js +66 -36
  164. package/dist/tls/stealth/record-layer.js.map +1 -1
  165. package/dist/tls/types.d.ts +33 -25
  166. package/dist/tls/types.d.ts.map +1 -1
  167. package/dist/tls/types.js +0 -4
  168. package/dist/tls/types.js.map +1 -1
  169. package/dist/utils/buffer-reader.d.ts +99 -7
  170. package/dist/utils/buffer-reader.d.ts.map +1 -1
  171. package/dist/utils/buffer-reader.js +99 -7
  172. package/dist/utils/buffer-reader.js.map +1 -1
  173. package/dist/utils/buffer-writer.d.ts +99 -10
  174. package/dist/utils/buffer-writer.d.ts.map +1 -1
  175. package/dist/utils/buffer-writer.js +101 -12
  176. package/dist/utils/buffer-writer.js.map +1 -1
  177. package/dist/utils/encoding.d.ts +33 -8
  178. package/dist/utils/encoding.d.ts.map +1 -1
  179. package/dist/utils/encoding.js +58 -13
  180. package/dist/utils/encoding.js.map +1 -1
  181. package/dist/utils/logger.d.ts +61 -2
  182. package/dist/utils/logger.d.ts.map +1 -1
  183. package/dist/utils/logger.js +52 -4
  184. package/dist/utils/logger.js.map +1 -1
  185. package/dist/utils/url.d.ts +47 -7
  186. package/dist/utils/url.d.ts.map +1 -1
  187. package/dist/utils/url.js +47 -7
  188. package/dist/utils/url.js.map +1 -1
  189. package/dist/ws/client.d.ts +59 -15
  190. package/dist/ws/client.d.ts.map +1 -1
  191. package/dist/ws/client.js +34 -27
  192. package/dist/ws/client.js.map +1 -1
  193. package/dist/ws/frame.d.ts +43 -9
  194. package/dist/ws/frame.d.ts.map +1 -1
  195. package/dist/ws/frame.js +35 -19
  196. package/dist/ws/frame.js.map +1 -1
  197. package/package.json +2 -2
@@ -1,20 +1,21 @@
1
- /**
2
- * Cookie jar (RFC 6265).
3
- *
4
- * Thread-safe, in-memory cookie storage with domain/path matching
5
- * and expiration handling.
6
- */
7
1
  import { parseSetCookie, serializeCookies } from './parser.js';
8
- /** Maximum number of cookies stored (per RFC 6265 §6.1 guidance). */
9
2
  const MAX_COOKIES = 3000;
10
3
  const MAX_COOKIES_PER_DOMAIN = 50;
4
+ /**
5
+ * In-memory cookie store implementing RFC 6265 semantics. Manages cookie
6
+ * scoping by domain and path, enforces per-domain and global cookie limits,
7
+ * and supports Netscape cookie file import/export for persistence.
8
+ */
11
9
  export class CookieJar {
12
10
  cookies = [];
13
11
  /**
14
- * Store cookies from Set-Cookie response headers.
12
+ * Parses all `Set-Cookie` values from `headers` (or from `rawHeaders` when
13
+ * available to handle multiple `Set-Cookie` entries) and stores any valid
14
+ * cookies scoped to the request URL.
15
15
  *
16
- * Accepts either a flat Record (with optional rawHeaders for proper
17
- * multi-value handling) or processes the merged header value.
16
+ * @param {Record<string, string>} headers - Normalized response headers.
17
+ * @param {URL} requestUrl - URL of the originating request (used for domain scoping).
18
+ * @param {Array<[string, string]>} [rawHeaders] - Original header pairs, allowing multiple `set-cookie` entries.
18
19
  */
19
20
  setCookies(headers, requestUrl, rawHeaders) {
20
21
  const setCookieValues = this.extractSetCookieValues(headers, rawHeaders);
@@ -26,15 +27,19 @@ export class CookieJar {
26
27
  }
27
28
  }
28
29
  /**
29
- * Get the Cookie header value for a request URL.
30
- * Returns empty string if no cookies match.
30
+ * Builds the `Cookie` request header value for cookies that match `url`.
31
+ * Cookies are sorted by longest path prefix first, then by creation time.
32
+ * Expired cookies are excluded automatically.
33
+ *
34
+ * @param {URL} url - The URL of the outgoing request.
35
+ * @returns {string} Serialized cookie string suitable for the `Cookie` header,
36
+ * or an empty string if no cookies match.
31
37
  */
32
38
  getCookieHeader(url) {
33
39
  const now = Date.now();
34
40
  const matching = this.cookies.filter((c) => this.matches(c, url, now));
35
41
  if (matching.length === 0)
36
42
  return '';
37
- // Sort by path length (longest first), then creation time (earliest first)
38
43
  matching.sort((a, b) => {
39
44
  if (a.path.length !== b.path.length)
40
45
  return b.path.length - a.path.length;
@@ -43,48 +48,109 @@ export class CookieJar {
43
48
  return serializeCookies(matching);
44
49
  }
45
50
  /**
46
- * Clear all cookies.
51
+ * Removes all cookies from the jar.
47
52
  */
48
53
  clear() {
49
54
  this.cookies = [];
50
55
  }
51
56
  /**
52
- * Clear cookies for a specific domain.
57
+ * Removes all cookies whose domain matches `domain` (case-insensitive).
58
+ *
59
+ * @param {string} domain - Domain string to clear (e.g. `"example.com"`).
53
60
  */
54
61
  clearDomain(domain) {
55
62
  this.cookies = this.cookies.filter((c) => c.domain !== domain.toLowerCase());
56
63
  }
57
64
  /**
58
- * Get all stored cookies (for inspection/debugging).
65
+ * Returns a read-only snapshot of all cookies currently in the jar,
66
+ * including any that may already be expired.
67
+ *
68
+ * @returns {ReadonlyArray<Cookie>} All stored cookies.
59
69
  */
60
70
  all() {
61
71
  return this.cookies;
62
72
  }
73
+ /**
74
+ * Returns the total number of cookies currently in the jar.
75
+ *
76
+ * @returns {number} Cookie count.
77
+ */
63
78
  get size() {
64
79
  return this.cookies.length;
65
80
  }
66
- // ---- Internal ----
81
+ /**
82
+ * Serializes all cookies to Netscape cookie file format. The output can be
83
+ * saved to disk and reloaded via {@link CookieJar.loadNetscapeString}.
84
+ *
85
+ * @returns {string} Netscape-format cookie file content (newline-terminated).
86
+ */
87
+ toNetscapeString() {
88
+ const lines = ['# Netscape HTTP Cookie File'];
89
+ for (const c of this.cookies) {
90
+ const domain = c.domain.startsWith('.') ? c.domain : '.' + c.domain;
91
+ const includeSubdomains = domain.startsWith('.') ? 'TRUE' : 'FALSE';
92
+ const path = c.path || '/';
93
+ const secure = c.secure ? 'TRUE' : 'FALSE';
94
+ let expires = '0';
95
+ if (c.maxAge !== undefined) {
96
+ expires = String(Math.floor((c.createdAt + c.maxAge * 1000) / 1000));
97
+ }
98
+ else if (c.expires) {
99
+ expires = String(Math.floor(c.expires.getTime() / 1000));
100
+ }
101
+ lines.push(`${domain}\t${includeSubdomains}\t${path}\t${secure}\t${expires}\t${c.name}\t${c.value}`);
102
+ }
103
+ return lines.join('\n') + '\n';
104
+ }
105
+ /**
106
+ * Imports cookies from a Netscape cookie file string. Lines beginning with
107
+ * `#` or blank lines are ignored. Cookies with invalid formats are skipped.
108
+ * Imported cookies are merged with any existing cookies in the jar.
109
+ *
110
+ * @param {string} content - Netscape cookie file content.
111
+ */
112
+ loadNetscapeString(content) {
113
+ for (const line of content.split('\n')) {
114
+ const trimmed = line.trim();
115
+ if (!trimmed || trimmed.startsWith('#'))
116
+ continue;
117
+ const parts = trimmed.split('\t');
118
+ if (parts.length < 7)
119
+ continue;
120
+ const [domain, , path, secure, expires, name, value] = parts;
121
+ const cookie = {
122
+ name: name,
123
+ value: value,
124
+ domain: domain.startsWith('.') ? domain.slice(1) : domain,
125
+ path: path,
126
+ secure: secure === 'TRUE',
127
+ httpOnly: false,
128
+ sameSite: undefined,
129
+ createdAt: Date.now(),
130
+ };
131
+ const expiresNum = parseInt(expires, 10);
132
+ if (expiresNum > 0) {
133
+ cookie.expires = new Date(expiresNum * 1000);
134
+ }
135
+ this.store(cookie);
136
+ }
137
+ }
67
138
  store(cookie) {
68
- // Max-Age = 0 means delete
69
139
  if (cookie.maxAge !== undefined && cookie.maxAge <= 0) {
70
140
  this.cookies = this.cookies.filter((c) => !(c.name === cookie.name && c.domain === cookie.domain && c.path === cookie.path));
71
141
  return;
72
142
  }
73
- // Replace existing cookie with same name/domain/path
74
143
  const idx = this.cookies.findIndex((c) => c.name === cookie.name && c.domain === cookie.domain && c.path === cookie.path);
75
144
  if (idx >= 0) {
76
145
  this.cookies[idx] = cookie;
77
146
  }
78
147
  else {
79
- // Enforce per-domain limit
80
148
  const domainCount = this.cookies.filter((c) => c.domain === cookie.domain).length;
81
149
  if (domainCount >= MAX_COOKIES_PER_DOMAIN) {
82
- // Evict oldest cookie for this domain
83
150
  const oldest = this.cookies.findIndex((c) => c.domain === cookie.domain);
84
151
  if (oldest >= 0)
85
152
  this.cookies.splice(oldest, 1);
86
153
  }
87
- // Enforce global limit
88
154
  if (this.cookies.length >= MAX_COOKIES) {
89
155
  this.cookies.shift();
90
156
  }
@@ -92,21 +158,17 @@ export class CookieJar {
92
158
  }
93
159
  }
94
160
  matches(cookie, url, now) {
95
- // Check expiration
96
161
  if (cookie.maxAge !== undefined) {
97
162
  if (now > cookie.createdAt + cookie.maxAge * 1000)
98
163
  return false;
99
164
  }
100
165
  if (cookie.expires && now > cookie.expires.getTime())
101
166
  return false;
102
- // Domain matching
103
167
  const host = url.hostname.toLowerCase();
104
168
  if (!this.domainMatches(host, cookie.domain))
105
169
  return false;
106
- // Path matching
107
170
  if (!this.pathMatches(url.pathname, cookie.path))
108
171
  return false;
109
- // Secure flag
110
172
  if (cookie.secure && url.protocol !== 'https:')
111
173
  return false;
112
174
  return true;
@@ -114,7 +176,6 @@ export class CookieJar {
114
176
  domainMatches(host, domain) {
115
177
  if (host === domain)
116
178
  return true;
117
- // Host must end with .domain
118
179
  return host.endsWith('.' + domain);
119
180
  }
120
181
  pathMatches(requestPath, cookiePath) {
@@ -129,13 +190,11 @@ export class CookieJar {
129
190
  return false;
130
191
  }
131
192
  extractSetCookieValues(headers, rawHeaders) {
132
- // Prefer raw headers to preserve individual Set-Cookie values
133
193
  if (rawHeaders) {
134
194
  return rawHeaders
135
195
  .filter(([k]) => k.toLowerCase() === 'set-cookie')
136
196
  .map(([, v]) => v);
137
197
  }
138
- // Fallback: extract from merged Record
139
198
  const values = [];
140
199
  for (const [key, value] of Object.entries(headers)) {
141
200
  if (key.toLowerCase() === 'set-cookie') {
@@ -1 +1 @@
1
- {"version":3,"file":"jar.js","sourceRoot":"","sources":["../../src/cookies/jar.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAe,MAAM,aAAa,CAAC;AAE5E,qEAAqE;AACr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,EAAE,CAAC,CAAC,CAAC,CAAC;QACvB,CAAC;QACD,MAAM,MAAM,GAAa,EAAE,CAAC;QAC5B,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;YACnD,IAAI,GAAG,CAAC,WAAW,EAAE,KAAK,YAAY,EAAE,CAAC;gBACvC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACrB,CAAC;QACH,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
@@ -1,5 +1,17 @@
1
1
  /**
2
- * Cookie parser and serializer (RFC 6265).
2
+ * Represents a parsed HTTP cookie as stored in the `CookieJar`.
3
+ *
4
+ * @typedef {Object} Cookie
5
+ * @property {string} name - Cookie name.
6
+ * @property {string} value - Cookie value.
7
+ * @property {string} domain - Effective domain (without leading dot).
8
+ * @property {string} path - Cookie path scope.
9
+ * @property {Date} [expires] - Absolute expiry date (from the `Expires` attribute).
10
+ * @property {number} [maxAge] - Relative lifetime in seconds (from the `Max-Age` attribute).
11
+ * @property {boolean} secure - Whether the cookie is restricted to HTTPS.
12
+ * @property {boolean} httpOnly - Whether the cookie is inaccessible to client-side scripts.
13
+ * @property {'strict' | 'lax' | 'none'} [sameSite] - SameSite policy.
14
+ * @property {number} createdAt - Unix timestamp (ms) when the cookie was created.
3
15
  */
4
16
  export interface Cookie {
5
17
  name: string;
@@ -14,11 +26,21 @@ export interface Cookie {
14
26
  createdAt: number;
15
27
  }
16
28
  /**
17
- * Parse a Set-Cookie header value into a Cookie object.
29
+ * Parses a `Set-Cookie` header value into a {@link Cookie} object.
30
+ * Validates the cookie against the request URL to enforce domain and path
31
+ * scoping rules per RFC 6265.
32
+ *
33
+ * @param {string} header - Raw `Set-Cookie` header value.
34
+ * @param {URL} requestUrl - URL of the request that received the header.
35
+ * @returns {Cookie | null} Parsed cookie, or `null` if the header is invalid or
36
+ * the domain attribute fails validation against the request origin.
18
37
  */
19
38
  export declare function parseSetCookie(header: string, requestUrl: URL): Cookie | null;
20
39
  /**
21
- * Serialize cookies for the Cookie header.
40
+ * Serializes an array of cookies into the `Cookie` request header value.
41
+ *
42
+ * @param {Cookie[]} cookies - Cookies to serialize (in desired send order).
43
+ * @returns {string} Semicolon-separated `name=value` string suitable for the `Cookie` header.
22
44
  */
23
45
  export declare function serializeCookies(cookies: Cookie[]): string;
24
46
  //# sourceMappingURL=parser.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/cookies/parser.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,MAAM;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,IAAI,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,QAAQ,GAAG,KAAK,GAAG,MAAM,CAAC;IACrC,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,GAAG,MAAM,GAAG,IAAI,CA0E7E;AASD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,CAE1D"}
1
+ {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/cookies/parser.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,MAAM;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,IAAI,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,QAAQ,GAAG,KAAK,GAAG,MAAM,CAAC;IACrC,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,GAAG,MAAM,GAAG,IAAI,CAwE7E;AASD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,CAE1D"}
@@ -1,8 +1,12 @@
1
1
  /**
2
- * Cookie parser and serializer (RFC 6265).
3
- */
4
- /**
5
- * Parse a Set-Cookie header value into a Cookie object.
2
+ * Parses a `Set-Cookie` header value into a {@link Cookie} object.
3
+ * Validates the cookie against the request URL to enforce domain and path
4
+ * scoping rules per RFC 6265.
5
+ *
6
+ * @param {string} header - Raw `Set-Cookie` header value.
7
+ * @param {URL} requestUrl - URL of the request that received the header.
8
+ * @returns {Cookie | null} Parsed cookie, or `null` if the header is invalid or
9
+ * the domain attribute fails validation against the request origin.
6
10
  */
7
11
  export function parseSetCookie(header, requestUrl) {
8
12
  const parts = header.split(';').map((s) => s.trim());
@@ -37,10 +41,8 @@ export function parseSetCookie(header, requestUrl) {
37
41
  let d = attrValue.toLowerCase();
38
42
  if (d.startsWith('.'))
39
43
  d = d.substring(1);
40
- // Validate domain matches request host (RFC 6265 §5.3.6)
41
44
  const host = requestUrl.hostname.toLowerCase();
42
45
  if (d !== host && !host.endsWith('.' + d)) {
43
- // Reject cookie — domain doesn't match request
44
46
  return null;
45
47
  }
46
48
  cookie.domain = d;
@@ -85,7 +87,10 @@ function defaultPath(path) {
85
87
  return path.substring(0, lastSlash);
86
88
  }
87
89
  /**
88
- * Serialize cookies for the Cookie header.
90
+ * Serializes an array of cookies into the `Cookie` request header value.
91
+ *
92
+ * @param {Cookie[]} cookies - Cookies to serialize (in desired send order).
93
+ * @returns {string} Semicolon-separated `name=value` string suitable for the `Cookie` header.
89
94
  */
90
95
  export function serializeCookies(cookies) {
91
96
  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;;GAEG;AAeH;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,MAAc,EAAE,UAAe;IAC5D,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IACrD,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAEpC,MAAM,SAAS,GAAG,KAAK,CAAC,CAAC,CAAE,CAAC;IAC5B,MAAM,KAAK,GAAG,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACrC,IAAI,KAAK,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IAE3B,MAAM,IAAI,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC;IAClD,MAAM,KAAK,GAAG,SAAS,CAAC,SAAS,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAEpD,IAAI,CAAC,IAAI;QAAE,OAAO,IAAI,CAAC;IAEvB,MAAM,MAAM,GAAW;QACrB,IAAI;QACJ,KAAK;QACL,MAAM,EAAE,UAAU,CAAC,QAAQ;QAC3B,IAAI,EAAE,WAAW,CAAC,UAAU,CAAC,QAAQ,CAAC;QACtC,MAAM,EAAE,KAAK;QACb,QAAQ,EAAE,KAAK;QACf,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;KACtB,CAAC;IAEF,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAA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AAC;gBACD,MAAM;YACR,CAAC;YACD,KAAK,SAAS,CAAC,CAAC,CAAC;gBACf,MAAM,IAAI,GAAG,QAAQ,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;gBACrC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;oBACxB,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC;gBACvB,CAAC;gBACD,MAAM;YACR,CAAC;YACD,KAAK,QAAQ;gBACX,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC;gBACrB,MAAM;YACR,KAAK,UAAU;gBACb,MAAM,CAAC,QAAQ,GAAG,IAAI,CAAC;gBACvB,MAAM;YACR,KAAK,UAAU;gBACb,MAAM,CAAC,QAAQ,GAAG,SAAS,CAAC,WAAW,EAAwB,CAAC;gBAChE,MAAM;QACV,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,WAAW,CAAC,IAAY;IAC/B,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,OAAO,GAAG,CAAC;IAC/C,MAAM,SAAS,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IACxC,IAAI,SAAS,KAAK,CAAC;QAAE,OAAO,GAAG,CAAC;IAChC,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;AACtC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAiB;IAChD,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC/D,CAAC"}
@@ -1,77 +1,93 @@
1
- /**
2
- * NLcURL client.
3
- *
4
- * The primary public interface for making HTTP requests with browser
5
- * fingerprint impersonation. Provides both a session-based API for
6
- * persistent connections and cookie handling, and standalone convenience
7
- * functions for one-off requests.
8
- */
9
1
  import type { NLcURLRequest, NLcURLSessionConfig, RequestBody } from './request.js';
10
2
  import { NLcURLResponse } from './response.js';
11
3
  import { NLcURLSession, type RequestOptions } from './session.js';
12
4
  /**
13
- * Create a new persistent session.
5
+ * Creates a new {@link NLcURLSession} with the given configuration. Use a
6
+ * session when you need to share cookies, connection pools, or interceptors
7
+ * across multiple requests. Call {@link NLcURLSession.close} when finished.
14
8
  *
15
- * Sessions maintain a connection pool, cookie jar, and default
16
- * configuration across multiple requests.
9
+ * @param {NLcURLSessionConfig} [config] - Session-level defaults.
10
+ * @returns {NLcURLSession} A new session instance.
17
11
  *
18
12
  * @example
19
- * ```ts
20
13
  * const session = createSession({ impersonate: 'chrome136' });
21
- * const response = await session.get('https://httpbin.org/get');
22
- * console.log(response.json());
14
+ * const r = await session.get('https://example.com');
23
15
  * session.close();
24
- * ```
25
16
  */
26
17
  export declare function createSession(config?: NLcURLSessionConfig): NLcURLSession;
27
18
  /**
28
- * Send an HTTP request.
19
+ * Sends a one-shot HTTP request by creating a temporary session internally.
20
+ * The session is closed automatically after the response is received.
21
+ * For repeated requests to the same origin, prefer {@link createSession}.
29
22
  *
30
- * Creates a temporary session, sends the request, and closes the session.
31
- * For multiple requests, use `createSession()` instead for better
32
- * performance via connection reuse.
33
- *
34
- * @example
35
- * ```ts
36
- * const resp = await request({
37
- * url: 'https://httpbin.org/get',
38
- * impersonate: 'chrome136',
39
- * });
40
- * ```
23
+ * @param {NLcURLRequest} input - Complete request descriptor.
24
+ * @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.
41
30
  */
42
31
  export declare function request(input: NLcURLRequest): Promise<NLcURLResponse>;
43
32
  /**
44
- * Send a GET request.
33
+ * Issues a one-shot `GET` request.
34
+ *
35
+ * @param {string} url - Absolute URL to request.
36
+ * @param {RequestOptions & { impersonate?: string }} [options] - Optional per-request settings.
37
+ * @returns {Promise<NLcURLResponse>} Resolves with the server response.
45
38
  */
46
39
  export declare function get(url: string, options?: RequestOptions & {
47
40
  impersonate?: string;
48
41
  }): Promise<NLcURLResponse>;
49
42
  /**
50
- * Send a POST request.
43
+ * Issues a one-shot `POST` request.
44
+ *
45
+ * @param {string} url - Absolute URL to request.
46
+ * @param {RequestBody} [body] - Request body payload.
47
+ * @param {RequestOptions & { impersonate?: string }} [options] - Optional per-request settings.
48
+ * @returns {Promise<NLcURLResponse>} Resolves with the server response.
51
49
  */
52
50
  export declare function post(url: string, body?: RequestBody, options?: RequestOptions & {
53
51
  impersonate?: string;
54
52
  }): Promise<NLcURLResponse>;
55
53
  /**
56
- * Send a PUT request.
54
+ * Issues a one-shot `PUT` request.
55
+ *
56
+ * @param {string} url - Absolute URL to request.
57
+ * @param {RequestBody} [body] - Request body payload.
58
+ * @param {RequestOptions & { impersonate?: string }} [options] - Optional per-request settings.
59
+ * @returns {Promise<NLcURLResponse>} Resolves with the server response.
57
60
  */
58
61
  export declare function put(url: string, body?: RequestBody, options?: RequestOptions & {
59
62
  impersonate?: string;
60
63
  }): Promise<NLcURLResponse>;
61
64
  /**
62
- * Send a PATCH request.
65
+ * Issues a one-shot `PATCH` request.
66
+ *
67
+ * @param {string} url - Absolute URL to request.
68
+ * @param {RequestBody} [body] - Request body payload.
69
+ * @param {RequestOptions & { impersonate?: string }} [options] - Optional per-request settings.
70
+ * @returns {Promise<NLcURLResponse>} Resolves with the server response.
63
71
  */
64
72
  export declare function patch(url: string, body?: RequestBody, options?: RequestOptions & {
65
73
  impersonate?: string;
66
74
  }): Promise<NLcURLResponse>;
67
75
  /**
68
- * Send a DELETE request.
76
+ * Issues a one-shot `DELETE` request.
77
+ *
78
+ * @param {string} url - Absolute URL to request.
79
+ * @param {RequestOptions & { impersonate?: string }} [options] - Optional per-request settings.
80
+ * @returns {Promise<NLcURLResponse>} Resolves with the server response.
69
81
  */
70
82
  export declare function del(url: string, options?: RequestOptions & {
71
83
  impersonate?: string;
72
84
  }): Promise<NLcURLResponse>;
73
85
  /**
74
- * Send a HEAD request.
86
+ * Issues a one-shot `HEAD` request. The response body will be empty.
87
+ *
88
+ * @param {string} url - Absolute URL to request.
89
+ * @param {RequestOptions & { impersonate?: string }} [options] - Optional per-request settings.
90
+ * @returns {Promise<NLcURLResponse>} Resolves with the response (headers only, no body).
75
91
  */
76
92
  export declare function head(url: string, options?: RequestOptions & {
77
93
  impersonate?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/core/client.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,aAAa,EACb,mBAAmB,EACnB,WAAW,EACZ,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AAElE;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAAC,MAAM,CAAC,EAAE,mBAAmB,GAAG,aAAa,CAEzE;AAID;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,OAAO,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC,CAO3E;AAED;;GAEG;AACH,wBAAsB,GAAG,CACvB,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,cAAc,GAAG;IAAE,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,GAClD,OAAO,CAAC,cAAc,CAAC,CAEzB;AAED;;GAEG;AACH,wBAAsB,IAAI,CACxB,GAAG,EAAE,MAAM,EACX,IAAI,CAAC,EAAE,WAAW,EAClB,OAAO,CAAC,EAAE,cAAc,GAAG;IAAE,WAAW,C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* The primary public interface for making HTTP requests with browser
5
- * fingerprint impersonation. Provides both a session-based API for
6
- * persistent connections and cookie handling, and standalone convenience
7
- * functions for one-off requests.
8
- */
9
1
  import { NLcURLSession } from './session.js';
10
2
  /**
11
- * Create a new persistent session.
3
+ * Creates a new {@link NLcURLSession} with the given configuration. Use a
4
+ * session when you need to share cookies, connection pools, or interceptors
5
+ * across multiple requests. Call {@link NLcURLSession.close} when finished.
12
6
  *
13
- * Sessions maintain a connection pool, cookie jar, and default
14
- * configuration across multiple requests.
7
+ * @param {NLcURLSessionConfig} [config] - Session-level defaults.
8
+ * @returns {NLcURLSession} A new session instance.
15
9
  *
16
10
  * @example
17
- * ```ts
18
11
  * const session = createSession({ impersonate: 'chrome136' });
19
- * const response = await session.get('https://httpbin.org/get');
20
- * console.log(response.json());
12
+ * const r = await session.get('https://example.com');
21
13
  * session.close();
22
- * ```
23
14
  */
24
15
  export function createSession(config) {
25
16
  return new NLcURLSession(config);
26
17
  }
27
- // ---- One-shot request functions ----
28
18
  /**
29
- * Send an HTTP request.
30
- *
31
- * Creates a temporary session, sends the request, and closes the session.
32
- * For multiple requests, use `createSession()` instead for better
33
- * performance via connection reuse.
19
+ * Sends a one-shot HTTP request by creating a temporary session internally.
20
+ * The session is closed automatically after the response is received.
21
+ * For repeated requests to the same origin, prefer {@link createSession}.
34
22
  *
35
- * @example
36
- * ```ts
37
- * const resp = await request({
38
- * url: 'https://httpbin.org/get',
39
- * impersonate: 'chrome136',
40
- * });
41
- * ```
23
+ * @param {NLcURLRequest} input - Complete request descriptor.
24
+ * @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.
42
30
  */
43
31
  export async function request(input) {
44
32
  const session = new NLcURLSession(extractSessionConfig(input));
33
+ if (input.stream) {
34
+ let response;
35
+ try {
36
+ response = await session.request(input);
37
+ }
38
+ catch (err) {
39
+ session.close();
40
+ throw err;
41
+ }
42
+ const cleanup = () => session.close();
43
+ response.body?.once('close', cleanup);
44
+ if (response.body === null)
45
+ session.close();
46
+ return response;
47
+ }
45
48
  try {
46
49
  return await session.request(input);
47
50
  }
@@ -50,45 +53,68 @@ export async function request(input) {
50
53
  }
51
54
  }
52
55
  /**
53
- * Send a GET request.
56
+ * Issues a one-shot `GET` request.
57
+ *
58
+ * @param {string} url - Absolute URL to request.
59
+ * @param {RequestOptions & { impersonate?: string }} [options] - Optional per-request settings.
60
+ * @returns {Promise<NLcURLResponse>} Resolves with the server response.
54
61
  */
55
62
  export async function get(url, options) {
56
63
  return request({ ...options, url, method: 'GET' });
57
64
  }
58
65
  /**
59
- * Send a POST request.
66
+ * Issues a one-shot `POST` request.
67
+ *
68
+ * @param {string} url - Absolute URL to request.
69
+ * @param {RequestBody} [body] - Request body payload.
70
+ * @param {RequestOptions & { impersonate?: string }} [options] - Optional per-request settings.
71
+ * @returns {Promise<NLcURLResponse>} Resolves with the server response.
60
72
  */
61
73
  export async function post(url, body, options) {
62
74
  return request({ ...options, url, method: 'POST', body });
63
75
  }
64
76
  /**
65
- * Send a PUT request.
77
+ * Issues a one-shot `PUT` request.
78
+ *
79
+ * @param {string} url - Absolute URL to request.
80
+ * @param {RequestBody} [body] - Request body payload.
81
+ * @param {RequestOptions & { impersonate?: string }} [options] - Optional per-request settings.
82
+ * @returns {Promise<NLcURLResponse>} Resolves with the server response.
66
83
  */
67
84
  export async function put(url, body, options) {
68
85
  return request({ ...options, url, method: 'PUT', body });
69
86
  }
70
87
  /**
71
- * Send a PATCH request.
88
+ * Issues a one-shot `PATCH` request.
89
+ *
90
+ * @param {string} url - Absolute URL to request.
91
+ * @param {RequestBody} [body] - Request body payload.
92
+ * @param {RequestOptions & { impersonate?: string }} [options] - Optional per-request settings.
93
+ * @returns {Promise<NLcURLResponse>} Resolves with the server response.
72
94
  */
73
95
  export async function patch(url, body, options) {
74
96
  return request({ ...options, url, method: 'PATCH', body });
75
97
  }
76
98
  /**
77
- * Send a DELETE request.
99
+ * Issues a one-shot `DELETE` request.
100
+ *
101
+ * @param {string} url - Absolute URL to request.
102
+ * @param {RequestOptions & { impersonate?: string }} [options] - Optional per-request settings.
103
+ * @returns {Promise<NLcURLResponse>} Resolves with the server response.
78
104
  */
79
105
  export async function del(url, options) {
80
106
  return request({ ...options, url, method: 'DELETE' });
81
107
  }
82
108
  /**
83
- * Send a HEAD request.
109
+ * Issues a one-shot `HEAD` request. The response body will be empty.
110
+ *
111
+ * @param {string} url - Absolute URL to request.
112
+ * @param {RequestOptions & { impersonate?: string }} [options] - Optional per-request settings.
113
+ * @returns {Promise<NLcURLResponse>} Resolves with the response (headers only, no body).
84
114
  */
85
115
  export async function head(url, options) {
86
116
  return request({ ...options, url, method: 'HEAD' });
87
117
  }
88
- // ---- Internal ----
89
- /**
90
- * Extract session-level configuration from a request object.
91
- */
92
118
  function extractSessionConfig(req) {
93
119
  return {
94
120
  impersonate: req.impersonate,