kinetex 1.3.0 → 1.5.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 (123) hide show
  1. package/README.md +413 -52
  2. package/dist/browser/kinetex.esm.js +38 -22
  3. package/dist/browser/kinetex.js +3134 -787
  4. package/dist/browser/kinetex.min.js +38 -22
  5. package/dist/cjs/aws-sigv4.js +140 -33
  6. package/dist/cjs/cache.js +58 -7
  7. package/dist/cjs/circuit-breaker.js +53 -4
  8. package/dist/cjs/client.js +726 -188
  9. package/dist/cjs/cookie-parser.js +131 -6
  10. package/dist/cjs/cookie-store.js +125 -28
  11. package/dist/cjs/core.js +691 -70
  12. package/dist/cjs/dedup.js +142 -21
  13. package/dist/cjs/digest.js +195 -38
  14. package/dist/cjs/graphql.js +166 -35
  15. package/dist/cjs/headers.js +327 -46
  16. package/dist/cjs/interceptors.js +227 -24
  17. package/dist/cjs/lifecycle.js +92 -59
  18. package/dist/cjs/logging.js +160 -24
  19. package/dist/cjs/mod.js +3 -2
  20. package/dist/cjs/pagination.js +247 -22
  21. package/dist/cjs/progress.js +178 -30
  22. package/dist/cjs/proxy.js +429 -0
  23. package/dist/cjs/response.js +506 -110
  24. package/dist/cjs/socks5.js +136 -15
  25. package/dist/cjs/sse.js +173 -43
  26. package/dist/cjs/url.js +191 -45
  27. package/dist/cjs/utils.js +335 -73
  28. package/dist/cjs/ws.js +62 -12
  29. package/dist/esm/aws-sigv4.js +140 -33
  30. package/dist/esm/aws-sigv4.js.map +1 -1
  31. package/dist/esm/cache.js +58 -7
  32. package/dist/esm/cache.js.map +1 -1
  33. package/dist/esm/circuit-breaker.js +53 -4
  34. package/dist/esm/circuit-breaker.js.map +1 -1
  35. package/dist/esm/client.js +726 -188
  36. package/dist/esm/client.js.map +1 -1
  37. package/dist/esm/cookie-parser.js +131 -6
  38. package/dist/esm/cookie-parser.js.map +1 -1
  39. package/dist/esm/cookie-store.js +125 -28
  40. package/dist/esm/cookie-store.js.map +1 -1
  41. package/dist/esm/core.js +691 -70
  42. package/dist/esm/core.js.map +1 -1
  43. package/dist/esm/dedup.js +142 -21
  44. package/dist/esm/dedup.js.map +1 -1
  45. package/dist/esm/digest.js +195 -38
  46. package/dist/esm/digest.js.map +1 -1
  47. package/dist/esm/graphql.js +166 -35
  48. package/dist/esm/graphql.js.map +1 -1
  49. package/dist/esm/headers.js +327 -46
  50. package/dist/esm/headers.js.map +1 -1
  51. package/dist/esm/interceptors.js +227 -24
  52. package/dist/esm/interceptors.js.map +1 -1
  53. package/dist/esm/lifecycle.js +92 -59
  54. package/dist/esm/lifecycle.js.map +1 -1
  55. package/dist/esm/logging.js +160 -24
  56. package/dist/esm/logging.js.map +1 -1
  57. package/dist/esm/mod.js +3 -2
  58. package/dist/esm/mod.js.map +1 -1
  59. package/dist/esm/pagination.js +247 -22
  60. package/dist/esm/pagination.js.map +1 -1
  61. package/dist/esm/progress.js +178 -30
  62. package/dist/esm/progress.js.map +1 -1
  63. package/dist/esm/proxy.js +430 -0
  64. package/dist/esm/proxy.js.map +1 -0
  65. package/dist/esm/response.js +506 -110
  66. package/dist/esm/response.js.map +1 -1
  67. package/dist/esm/socks5.js +136 -15
  68. package/dist/esm/socks5.js.map +1 -1
  69. package/dist/esm/sse.js +173 -43
  70. package/dist/esm/sse.js.map +1 -1
  71. package/dist/esm/types.js.map +1 -1
  72. package/dist/esm/url.js +191 -45
  73. package/dist/esm/url.js.map +1 -1
  74. package/dist/esm/utils.js +335 -73
  75. package/dist/esm/utils.js.map +1 -1
  76. package/dist/esm/ws.js +62 -12
  77. package/dist/esm/ws.js.map +1 -1
  78. package/dist/types/aws-sigv4.d.ts.map +1 -1
  79. package/dist/types/cache.d.ts +19 -1
  80. package/dist/types/cache.d.ts.map +1 -1
  81. package/dist/types/circuit-breaker.d.ts +15 -2
  82. package/dist/types/circuit-breaker.d.ts.map +1 -1
  83. package/dist/types/client.d.ts +69 -11
  84. package/dist/types/client.d.ts.map +1 -1
  85. package/dist/types/cookie-parser.d.ts +0 -17
  86. package/dist/types/cookie-parser.d.ts.map +1 -1
  87. package/dist/types/cookie-store.d.ts.map +1 -1
  88. package/dist/types/core.d.ts +216 -25
  89. package/dist/types/core.d.ts.map +1 -1
  90. package/dist/types/dedup.d.ts +38 -3
  91. package/dist/types/dedup.d.ts.map +1 -1
  92. package/dist/types/digest.d.ts +17 -37
  93. package/dist/types/digest.d.ts.map +1 -1
  94. package/dist/types/graphql.d.ts.map +1 -1
  95. package/dist/types/headers.d.ts +68 -31
  96. package/dist/types/headers.d.ts.map +1 -1
  97. package/dist/types/interceptors.d.ts +126 -38
  98. package/dist/types/interceptors.d.ts.map +1 -1
  99. package/dist/types/lifecycle.d.ts +19 -2
  100. package/dist/types/lifecycle.d.ts.map +1 -1
  101. package/dist/types/logging.d.ts +22 -3
  102. package/dist/types/logging.d.ts.map +1 -1
  103. package/dist/types/mod.d.ts +5 -3
  104. package/dist/types/mod.d.ts.map +1 -1
  105. package/dist/types/pagination.d.ts +0 -25
  106. package/dist/types/pagination.d.ts.map +1 -1
  107. package/dist/types/progress.d.ts +1 -1
  108. package/dist/types/progress.d.ts.map +1 -1
  109. package/dist/types/proxy.d.ts +50 -0
  110. package/dist/types/proxy.d.ts.map +1 -0
  111. package/dist/types/response.d.ts +49 -2
  112. package/dist/types/response.d.ts.map +1 -1
  113. package/dist/types/socks5.d.ts.map +1 -1
  114. package/dist/types/sse.d.ts.map +1 -1
  115. package/dist/types/types.d.ts +219 -26
  116. package/dist/types/types.d.ts.map +1 -1
  117. package/dist/types/url.d.ts +0 -25
  118. package/dist/types/url.d.ts.map +1 -1
  119. package/dist/types/utils.d.ts +69 -1
  120. package/dist/types/utils.d.ts.map +1 -1
  121. package/dist/types/ws.d.ts +0 -1
  122. package/dist/types/ws.d.ts.map +1 -1
  123. package/package.json +10 -4
@@ -0,0 +1,430 @@
1
+ /**
2
+ * §14 HTTP(S) CONNECT PROXY TUNNELING
3
+ *
4
+ * Establishes a TCP tunnel to a target host through an HTTP/HTTPS proxy using
5
+ * the `CONNECT` method (RFC 9110 §9.3.6), then optionally wraps that socket in
6
+ * TLS to the target.
7
+ *
8
+ * The tunnel is how an HTTP proxy must be used for HTTPS: the client sends
9
+ * only the CONNECT request line to the proxy, and from there the proxy is a
10
+ * blind byte relay. The target's certificate is therefore validated end to
11
+ * end against the target's own name — the proxy never terminates TLS, so it
12
+ * cannot impersonate the target without the CA store rejecting it.
13
+ *
14
+ * This module is Node-only by construction: it imports `node:net` and
15
+ * `node:tls`. Other runtimes route through their own `fetch` and must use a
16
+ * proxy-capable dispatcher instead.
17
+ *
18
+ * @module
19
+ */
20
+ import { KinetexError } from "./types.js";
21
+ /**
22
+ * True when `host` is an IPv4/IPv6 literal rather than a DNS name.
23
+ *
24
+ * A textual shape check rather than `node:net.isIP`, because this is a
25
+ * synchronous guard and the module only reaches for `node:net` through a
26
+ * dynamic import. Being imprecise here is harmless: the worst case is that a
27
+ * name the resolver dislikes is sent as SNI, and the TLS stack rejects it.
28
+ */
29
+ function isIpLiteral(host) {
30
+ const h = host.startsWith("[") && host.endsWith("]") ? host.slice(1, -1) : host;
31
+ return h.includes(":") || /^\d+(\.\d+)*$/.test(h);
32
+ }
33
+ const DEFAULT_CONNECT_TIMEOUT_MS = 30_000;
34
+ /** Maximum CONNECT response head we will buffer before giving up. */
35
+ const MAX_HEAD_BYTES = 64 * 1024;
36
+ /**
37
+ * True when the proxy URL names a SOCKS proxy, which needs a different
38
+ * mechanism entirely (`createSocks5Tunnel` in `kinetex/socks5`).
39
+ */
40
+ function isSocksProxy(url) {
41
+ return /^socks5h?:/i.test(url);
42
+ }
43
+ /**
44
+ * Build the `Proxy-Authorization` header value for Basic proxy auth.
45
+ *
46
+ * Uses the same encoding as the client's HTTP Basic auth. Returns `undefined`
47
+ * when no username was supplied — an empty username is still a deliberate
48
+ * (if unusual) credential, so it is encoded rather than skipped.
49
+ */
50
+ function proxyAuthHeader(proxy) {
51
+ if (proxy.username === undefined)
52
+ return undefined;
53
+ const raw = `${proxy.username}:${proxy.password ?? ""}`;
54
+ const bytes = new TextEncoder().encode(raw);
55
+ let binary = "";
56
+ for (const b of bytes)
57
+ binary += String.fromCharCode(b);
58
+ const b64 = typeof globalThis.btoa === "function"
59
+ ? globalThis.btoa(binary)
60
+ : // Node without btoa (or a non-Latin1 username) — encode explicitly.
61
+ Buffer.from(bytes).toString("base64");
62
+ return `Basic ${b64}`;
63
+ }
64
+ /**
65
+ * Parse a `CONNECT` response head.
66
+ *
67
+ * @returns The numeric status code, or `null` when the head is incomplete.
68
+ */
69
+ function parseConnectStatus(head) {
70
+ const statusLine = head.split("\r\n", 1)[0] ?? "";
71
+ const match = /^HTTP\/1\.[01] (\d{3})(?: (.*))?$/.exec(statusLine);
72
+ if (!match)
73
+ return null;
74
+ return { status: Number(match[1]), reason: match[2] ?? "" };
75
+ }
76
+ /**
77
+ * Open a socket to a target host through an HTTP(S) proxy via `CONNECT`.
78
+ *
79
+ * Returns a socket connected to the **target** — already TLS-wrapped when the
80
+ * target is `https:`. The caller owns it and decides whether to pool it.
81
+ *
82
+ * @param proxy - Proxy URL and optional Basic credentials.
83
+ * @param target - Fully-resolved target URL.
84
+ * @param options - CA, timeout, and abort configuration.
85
+ * @returns A socket tunneled to the target.
86
+ * @throws {KinetexError} `EVALIDATION` for a SOCKS proxy or a malformed proxy
87
+ * URL, `EPROXYAUTH` when the proxy demands credentials, `EPROXY` for any
88
+ * other non-2xx CONNECT response, `ETIMEOUT` if the proxy never answers,
89
+ * `EABORT` if `signal` fires, and `ENETWORK` for socket/TLS failures.
90
+ */
91
+ export async function connectThroughProxy(proxy, target, options = {}) {
92
+ // Built conditionally: `exactOptionalPropertyTypes` forbids passing an
93
+ // explicit `undefined` for an optional property.
94
+ const errMeta = options.request !== undefined ? { request: options.request } : {};
95
+ if (isSocksProxy(proxy.url)) {
96
+ throw new KinetexError(`proxy url "${proxy.url}" is a SOCKS proxy, which needs a different mechanism. ` +
97
+ "Use createSocks5Tunnel() from kinetex/socks5 and supply your own fetch over the tunnel.", "EVALIDATION", errMeta);
98
+ }
99
+ let proxyUrl;
100
+ try {
101
+ proxyUrl = new URL(proxy.url);
102
+ }
103
+ catch (err) {
104
+ throw new KinetexError(`proxy url "${proxy.url}" is not a valid URL`, "EVALIDATION", {
105
+ ...errMeta,
106
+ cause: err,
107
+ });
108
+ }
109
+ if (proxyUrl.protocol !== "http:" && proxyUrl.protocol !== "https:") {
110
+ throw new KinetexError(`proxy url scheme "${proxyUrl.protocol}" is not supported; use http:, https:, socks5: or socks5h:`, "EVALIDATION", errMeta);
111
+ }
112
+ const net = await import("node:net");
113
+ const tls = await import("node:tls");
114
+ const proxyPort = proxyUrl.port
115
+ ? Number(proxyUrl.port)
116
+ : proxyUrl.protocol === "https:"
117
+ ? 443
118
+ : 80;
119
+ const targetPort = target.port ? Number(target.port) : target.protocol === "https:" ? 443 : 80;
120
+ const authority = `${target.hostname}:${targetPort}`;
121
+ const timeoutMs = options.connectTimeoutMs ?? DEFAULT_CONNECT_TIMEOUT_MS;
122
+ // ── 1. TCP (or TLS-to-proxy) connection to the proxy itself ───────────────
123
+ const baseSocket = proxyUrl.protocol === "https:"
124
+ ? await openTlsSocket(tls, {
125
+ host: proxyUrl.hostname,
126
+ port: proxyPort,
127
+ servername: proxyUrl.hostname,
128
+ ...(options.ca !== undefined ? { ca: options.ca } : {}),
129
+ }, timeoutMs, options.signal, errMeta, `proxy ${proxyUrl.host}`)
130
+ : await openTcpSocket(net, { host: proxyUrl.hostname, port: proxyPort }, timeoutMs, options.signal, errMeta, `proxy ${proxyUrl.host}`);
131
+ // ── 2. CONNECT handshake ─────────────────────────────────────────────────
132
+ const auth = proxyAuthHeader(proxy);
133
+ const connectLines = [
134
+ `CONNECT ${authority} HTTP/1.1`,
135
+ `Host: ${authority}`,
136
+ // RFC 9110 §9.3.6: proxies that support persistent tunnels are expected to
137
+ // treat a tunnel as still-open even without this, but sending it is what
138
+ // every real client does and some proxies misbehave without it.
139
+ "Proxy-Connection: Keep-Alive",
140
+ ...(auth !== undefined ? [`Proxy-Authorization: ${auth}`] : []),
141
+ "",
142
+ "",
143
+ ];
144
+ baseSocket.write(connectLines.join("\r\n"));
145
+ let head = "";
146
+ // TCP does not preserve write boundaries. A proxy that splits the 200 head
147
+ // across two writes and puts the target's first bytes in the second
148
+ // delivers the head terminator and the start of the tunnelled stream in a
149
+ // single read, so the tail is kept and put back rather than discarded --
150
+ // dropping it silently truncates the message the caller is about to read.
151
+ //
152
+ // The head is therefore read in PAUSED mode -- `on("readable")` plus
153
+ // `read()` -- and never with `on("data")`. `on("data")` switches the stream
154
+ // to flowing mode, and removing the last `data` listener does NOT switch it
155
+ // back, so a flowing socket with nothing attached silently DISCARDS the
156
+ // bytes after the head terminator. `unshift()` alone does not recover them
157
+ // either: a later `on("data")` sets `state.flowing = true` before calling
158
+ // `resume()`, and `resume()` only restarts the flow when flowing was
159
+ // previously false, so the socket stalls with the tail still buffered and
160
+ // the caller waits forever. Reading paused leaves the flow state unset, so
161
+ // whichever consumer comes next -- `on("data")`, `pipe()`, or
162
+ // `tls.connect({ socket })` -- starts the flow and sees the tail.
163
+ const headResult = await new Promise((resolve) => {
164
+ // Pull every buffered chunk into `head`; a null read means the buffer is
165
+ // drained and `readable` will fire again when more arrives.
166
+ const drain = () => {
167
+ for (;;) {
168
+ const chunk = baseSocket.read();
169
+ if (chunk === null)
170
+ return;
171
+ head += chunk.toString("latin1");
172
+ }
173
+ };
174
+ const onReadable = () => {
175
+ drain();
176
+ const end = head.indexOf("\r\n\r\n");
177
+ if (end === -1) {
178
+ if (head.length > MAX_HEAD_BYTES) {
179
+ cleanup();
180
+ resolve({
181
+ ok: false,
182
+ err: new KinetexError("Proxy sent an oversized CONNECT response", "EPROXY", errMeta),
183
+ });
184
+ }
185
+ return;
186
+ }
187
+ cleanup();
188
+ const parsed = parseConnectStatus(head.slice(0, end));
189
+ if (!parsed) {
190
+ resolve({
191
+ ok: false,
192
+ err: new KinetexError(`Proxy returned a malformed CONNECT response: ${JSON.stringify(head.slice(0, end).split("\r\n", 1)[0] ?? "")}`, "EPROXY", errMeta),
193
+ });
194
+ return;
195
+ }
196
+ // RFC 9110 section 9.3.6: any 2xx switches the proxy to tunnel mode.
197
+ // Only 200 was accepted, so a proxy answering 201 or 204 was reported
198
+ // as a refusal.
199
+ if (parsed.status >= 200 && parsed.status < 300) {
200
+ // Put the tunnel bytes back in front of the buffered stream before
201
+ // handing the socket on. latin1 round-trips the bytes exactly, which
202
+ // is how `head` was built.
203
+ const tail = head.slice(end + 4);
204
+ if (tail.length > 0)
205
+ baseSocket.unshift(Buffer.from(tail, "latin1"));
206
+ resolve({ ok: true });
207
+ return;
208
+ }
209
+ if (parsed.status === 407) {
210
+ // Deliberately does not echo credentials back to the caller.
211
+ resolve({
212
+ ok: false,
213
+ err: new KinetexError("Proxy requires authentication (407). Set `username`/`password` on the proxy config, " +
214
+ "or embed them in the proxy URL.", "EPROXY", errMeta),
215
+ });
216
+ return;
217
+ }
218
+ resolve({
219
+ ok: false,
220
+ err: new KinetexError(`Proxy refused CONNECT to ${authority}: ${parsed.status} ${parsed.reason}`.trim(), "EPROXY", errMeta),
221
+ });
222
+ };
223
+ const onError = (e) => {
224
+ cleanup();
225
+ resolve({
226
+ ok: false,
227
+ err: new KinetexError(`Proxy connection failed: ${e.message}`, "ENETWORK", {
228
+ ...errMeta,
229
+ cause: e,
230
+ }),
231
+ });
232
+ };
233
+ // A proxy that closes the connection mid-handshake delivers a clean FIN,
234
+ // not a reset — so no `error` event fires and the socket simply ends.
235
+ // Without this the request would sit here until the connect timeout
236
+ // expired: 30s by default, for a proxy that is already gone.
237
+ const onClosedEarly = () => {
238
+ cleanup();
239
+ resolve({
240
+ ok: false,
241
+ err: new KinetexError(`Proxy closed the connection before answering CONNECT for ${authority}`, "EPROXY", errMeta),
242
+ });
243
+ };
244
+ const onTimeout = () => {
245
+ cleanup();
246
+ baseSocket.destroy();
247
+ resolve({
248
+ ok: false,
249
+ err: new KinetexError(`Proxy did not respond to CONNECT for ${authority} within ${timeoutMs}ms`, "ETIMEOUT", errMeta),
250
+ });
251
+ };
252
+ const onAbort = () => {
253
+ cleanup();
254
+ baseSocket.destroy();
255
+ resolve({
256
+ ok: false,
257
+ err: new KinetexError("Proxy connection aborted", "EABORT", errMeta),
258
+ });
259
+ };
260
+ const timer = setTimeout(onTimeout, timeoutMs);
261
+ if (typeof timer.unref === "function") {
262
+ timer.unref();
263
+ }
264
+ function cleanup() {
265
+ clearTimeout(timer);
266
+ baseSocket.off("readable", onReadable);
267
+ baseSocket.off("error", onError);
268
+ baseSocket.off("end", onClosedEarly);
269
+ baseSocket.off("close", onClosedEarly);
270
+ baseSocket.off("timeout", onTimeout);
271
+ options.signal?.removeEventListener("abort", onAbort);
272
+ }
273
+ baseSocket.on("readable", onReadable);
274
+ baseSocket.once("error", onError);
275
+ baseSocket.once("end", onClosedEarly);
276
+ baseSocket.once("close", onClosedEarly);
277
+ baseSocket.setTimeout(timeoutMs, onTimeout);
278
+ options.signal?.addEventListener("abort", onAbort, { once: true });
279
+ // Data may already be buffered (the request write above and the reply
280
+ // can cross), and `readable` does not fire for bytes that arrived before
281
+ // the listener was attached.
282
+ drain();
283
+ });
284
+ if (!headResult.ok) {
285
+ baseSocket.destroy();
286
+ throw headResult.err;
287
+ }
288
+ // ── 3. TLS to the target through the tunnel ───────────────────────────────
289
+ if (target.protocol !== "https:") {
290
+ // Clear the handshake listeners' timeout; the socket now belongs to the
291
+ // caller and its own timeout policy.
292
+ baseSocket.setTimeout(0);
293
+ return baseSocket;
294
+ }
295
+ return await new Promise((resolve, reject) => {
296
+ // The CONNECT handshake is over and its timeout/abort listeners are torn
297
+ // down, but the TLS handshake to the target has not happened yet. A peer
298
+ // that accepts the tunnel and then says nothing -- a black-holed target,
299
+ // or a proxy that relays to nothing -- would otherwise wait forever, so
300
+ // the same timeout and abort cover this step too.
301
+ const onTunnelTimeout = () => {
302
+ done();
303
+ baseSocket.destroy();
304
+ reject(new KinetexError(`TLS handshake through proxy to ${target.hostname} did not complete within ${timeoutMs}ms`, "ETIMEOUT", errMeta));
305
+ };
306
+ const onTunnelAbort = () => {
307
+ done();
308
+ baseSocket.destroy();
309
+ reject(new KinetexError("Proxy connection aborted", "EABORT", errMeta));
310
+ };
311
+ const tunnelTimer = setTimeout(onTunnelTimeout, timeoutMs);
312
+ if (typeof tunnelTimer.unref === "function") {
313
+ tunnelTimer.unref();
314
+ }
315
+ options.signal?.addEventListener("abort", onTunnelAbort, { once: true });
316
+ function done() {
317
+ clearTimeout(tunnelTimer);
318
+ options.signal?.removeEventListener("abort", onTunnelAbort);
319
+ }
320
+ // RFC 6066 §3 forbids IP literals in SNI, and Node 26 rejects the
321
+ // handshake outright when one is sent; Node 22 and 24 ignored it. Omit
322
+ // `servername` for IP targets so certificate verification falls back to
323
+ // the `host`/`authorized` check, which still covers the certificate.
324
+ const sni = options.servername ?? target.hostname;
325
+ const secure = tls.connect({
326
+ socket: baseSocket,
327
+ ...(sni !== undefined && !isIpLiteral(sni) ? { servername: sni } : {}),
328
+ ...(options.ca !== undefined ? { ca: options.ca } : {}),
329
+ },
330
+ // `rejectUnauthorized` is left at its default (true), so a peer that
331
+ // fails verification emits `error` rather than reaching this callback.
332
+ // Verification therefore cannot be bypassed here, and the callback
333
+ // only ever runs for a verified handshake.
334
+ () => {
335
+ done();
336
+ baseSocket.setTimeout(0);
337
+ resolve(secure);
338
+ });
339
+ secure.once("error", (e) => {
340
+ done();
341
+ baseSocket.destroy();
342
+ reject(new KinetexError(`TLS handshake through proxy failed for ${target.hostname}: ${e.message}`, "ENETWORK", { ...errMeta, cause: e }));
343
+ });
344
+ });
345
+ }
346
+ /** Open a plain TCP socket, rejecting on error/timeout/abort. */
347
+ async function openTcpSocket(net, opts, timeoutMs, signal, errMeta, what) {
348
+ return await new Promise((resolve, reject) => {
349
+ const socket = net.connect({ host: opts.host, port: opts.port });
350
+ const onError = (e) => {
351
+ cleanup();
352
+ reject(new KinetexError(`Cannot reach ${what}: ${e.message}`, "ENETWORK", {
353
+ ...errMeta,
354
+ cause: e,
355
+ }));
356
+ };
357
+ const timer = setTimeout(() => {
358
+ cleanup();
359
+ socket.destroy();
360
+ reject(new KinetexError(`Connecting to ${what} timed out`, "ETIMEOUT", errMeta));
361
+ }, timeoutMs);
362
+ if (typeof timer.unref === "function") {
363
+ timer.unref();
364
+ }
365
+ const onAbort = () => {
366
+ cleanup();
367
+ socket.destroy();
368
+ reject(new KinetexError("Proxy connection aborted", "EABORT", errMeta));
369
+ };
370
+ function cleanup() {
371
+ clearTimeout(timer);
372
+ socket.off("error", onError);
373
+ signal?.removeEventListener("abort", onAbort);
374
+ }
375
+ socket.once("error", onError);
376
+ socket.once("connect", () => {
377
+ cleanup();
378
+ resolve(socket);
379
+ });
380
+ if (signal?.aborted)
381
+ onAbort();
382
+ else
383
+ signal?.addEventListener("abort", onAbort, { once: true });
384
+ });
385
+ }
386
+ /** Open a TLS socket to an HTTPS proxy itself. */
387
+ async function openTlsSocket(tls, opts, timeoutMs, signal, errMeta, what) {
388
+ return await new Promise((resolve, reject) => {
389
+ const socket = tls.connect({
390
+ host: opts.host,
391
+ port: opts.port,
392
+ ...(isIpLiteral(opts.servername) ? {} : { servername: opts.servername }),
393
+ ...(opts.ca !== undefined ? { ca: opts.ca } : {}),
394
+ }, () => {
395
+ cleanup();
396
+ resolve(socket);
397
+ });
398
+ const onError = (e) => {
399
+ cleanup();
400
+ reject(new KinetexError(`Cannot reach ${what}: ${e.message}`, "ENETWORK", {
401
+ ...errMeta,
402
+ cause: e,
403
+ }));
404
+ };
405
+ const timer = setTimeout(() => {
406
+ cleanup();
407
+ socket.destroy();
408
+ reject(new KinetexError(`Connecting to ${what} timed out`, "ETIMEOUT", errMeta));
409
+ }, timeoutMs);
410
+ if (typeof timer.unref === "function") {
411
+ timer.unref();
412
+ }
413
+ const onAbort = () => {
414
+ cleanup();
415
+ socket.destroy();
416
+ reject(new KinetexError("Proxy connection aborted", "EABORT", errMeta));
417
+ };
418
+ function cleanup() {
419
+ clearTimeout(timer);
420
+ socket.off("error", onError);
421
+ signal?.removeEventListener("abort", onAbort);
422
+ }
423
+ socket.once("error", onError);
424
+ if (signal?.aborted)
425
+ onAbort();
426
+ else
427
+ signal?.addEventListener("abort", onAbort, { once: true });
428
+ });
429
+ }
430
+ //# sourceMappingURL=proxy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proxy.js","sourceRoot":"","sources":["../../src/proxy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAG1C;;;;;;;GAOG;AACH,SAAS,WAAW,CAAC,IAAY;IAC/B,MAAM,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAChF,OAAO,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpD,CAAC;AAgBD,MAAM,0BAA0B,GAAG,MAAM,CAAC;AAE1C,qEAAqE;AACrE,MAAM,cAAc,GAAG,EAAE,GAAG,IAAI,CAAC;AAEjC;;;GAGG;AACH,SAAS,YAAY,CAAC,GAAW;IAC/B,OAAO,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACjC,CAAC;AAED;;;;;;GAMG;AACH,SAAS,eAAe,CAAC,KAAkB;IACzC,IAAI,KAAK,CAAC,QAAQ,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IACnD,MAAM,GAAG,GAAG,GAAG,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,QAAQ,IAAI,EAAE,EAAE,CAAC;IACxD,MAAM,KAAK,GAAG,IAAI,WAAW,EAA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