@socketsecurity/lib 5.12.0 → 5.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,20 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [5.13.0](https://github.com/SocketDev/socket-lib/releases/tag/v5.13.0) - 2026-04-05
9
+
10
+ ### Added — http-request
11
+
12
+ - `readIncomingResponse()` — reads and buffers a Node.js `IncomingResponse` into an `HttpResponse` (#143)
13
+ - Useful for converting raw responses from code that bypasses `httpRequest()` (e.g. multipart form-data uploads) into the standard `HttpResponse` interface
14
+ - `IncomingResponse` type alias — disambiguates `IncomingMessage` as a client-side response
15
+ - `IncomingRequest` type alias — disambiguates `IncomingMessage` as a server-side request
16
+
17
+ ### Changed — http-request
18
+
19
+ - Internal `httpRequestAttempt` callbacks now use `IncomingResponse` type
20
+ - `HttpResponse.rawResponse` type narrowed from `IncomingMessage` to `IncomingResponse`
21
+
8
22
  ## [5.12.0](https://github.com/SocketDev/socket-lib/releases/tag/v5.12.0) - 2026-04-04
9
23
 
10
24
  ### Added — http-request
@@ -1,4 +1,8 @@
1
1
  import type { IncomingHttpHeaders, IncomingMessage } from 'http';
2
+ /** IncomingMessage received as a response to a client request (http.request callback). */
3
+ export type IncomingResponse = IncomingMessage;
4
+ /** IncomingMessage received as a request in a server handler (http.createServer callback). */
5
+ export type IncomingRequest = IncomingMessage;
2
6
  import type { Logger } from './logger.js';
3
7
  /**
4
8
  * Information passed to the onRequest hook before each request attempt.
@@ -314,12 +318,21 @@ export interface HttpResponse {
314
318
  */
315
319
  text(): string;
316
320
  /**
317
- * The underlying Node.js IncomingMessage for advanced use cases
321
+ * The underlying Node.js IncomingResponse for advanced use cases
318
322
  * (e.g., streaming, custom header inspection). Only available when
319
323
  * the response was not consumed by the convenience methods.
320
324
  */
321
- rawResponse?: IncomingMessage | undefined;
325
+ rawResponse?: IncomingResponse | undefined;
322
326
  }
327
+ /**
328
+ * Read and buffer a client-side IncomingResponse into an HttpResponse.
329
+ *
330
+ * Useful when you have a raw response from code that bypasses
331
+ * `httpRequest()` (e.g., multipart form-data uploads via `http.request()`,
332
+ * or responses from third-party HTTP libraries) and need to convert it
333
+ * into the standard HttpResponse interface.
334
+ */
335
+ export declare function readIncomingResponse(msg: IncomingResponse): Promise<HttpResponse>;
323
336
  /**
324
337
  * Configuration options for file downloads.
325
338
  */
@@ -25,7 +25,8 @@ __export(http_request_exports, {
25
25
  httpJson: () => httpJson,
26
26
  httpRequest: () => httpRequest,
27
27
  httpText: () => httpText,
28
- parseChecksums: () => parseChecksums
28
+ parseChecksums: () => parseChecksums,
29
+ readIncomingResponse: () => readIncomingResponse
29
30
  });
30
31
  module.exports = __toCommonJS(http_request_exports);
31
32
  var import_fs = require("./fs.js");
@@ -61,6 +62,29 @@ function getHttps() {
61
62
  }
62
63
  return _https;
63
64
  }
65
+ async function readIncomingResponse(msg) {
66
+ const chunks = [];
67
+ for await (const chunk of msg) {
68
+ chunks.push(chunk);
69
+ }
70
+ const body = Buffer.concat(chunks);
71
+ const status = msg.statusCode ?? 0;
72
+ const statusText = msg.statusMessage ?? "";
73
+ return {
74
+ arrayBuffer: () => body.buffer.slice(
75
+ body.byteOffset,
76
+ body.byteOffset + body.byteLength
77
+ ),
78
+ body,
79
+ headers: msg.headers,
80
+ json: () => JSON.parse(body.toString("utf8")),
81
+ ok: status >= 200 && status < 300,
82
+ rawResponse: msg,
83
+ status,
84
+ statusText,
85
+ text: () => body.toString("utf8")
86
+ };
87
+ }
64
88
  function parseChecksums(text) {
65
89
  const checksums = { __proto__: null };
66
90
  for (const line of text.split("\n")) {
@@ -613,5 +637,6 @@ async function httpText(url, options) {
613
637
  httpJson,
614
638
  httpRequest,
615
639
  httpText,
616
- parseChecksums
640
+ parseChecksums,
641
+ readIncomingResponse
617
642
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@socketsecurity/lib",
3
- "version": "5.12.0",
3
+ "version": "5.13.0",
4
4
  "packageManager": "pnpm@10.33.0",
5
5
  "license": "MIT",
6
6
  "description": "Core utilities and infrastructure for Socket.dev security tools",
@@ -735,7 +735,7 @@
735
735
  "@socketregistry/is-unicode-supported": "1.0.5",
736
736
  "@socketregistry/packageurl-js": "1.4.1",
737
737
  "@socketregistry/yocto-spinner": "1.0.25",
738
- "@socketsecurity/lib-stable": "npm:@socketsecurity/lib@5.11.4",
738
+ "@socketsecurity/lib-stable": "npm:@socketsecurity/lib@5.12.0",
739
739
  "@types/node": "24.9.2",
740
740
  "@typescript/native-preview": "7.0.0-dev.20250920.1",
741
741
  "@vitest/coverage-v8": "4.0.3",