Skip to content

refactor: deduplicate with @socketsecurity/lib#556

Open
jdalton wants to merge 3 commits intomainfrom
chore/deduplicate-with-lib
Open

refactor: deduplicate with @socketsecurity/lib#556
jdalton wants to merge 3 commits intomainfrom
chore/deduplicate-with-lib

Conversation

@jdalton
Copy link
Copy Markdown
Contributor

@jdalton jdalton commented Apr 5, 2026

Summary

  • Delete duplicated src/promise-queue.ts and import PromiseQueue from @socketsecurity/lib/promise-queue
  • Refactor src/http-client.ts to use @socketsecurity/lib/http-request internally (-472 net lines)
    • createGetRequest, createDeleteRequest, createRequestWithJson now use lib's httpRequest()
    • ResponseError.response changed from IncomingMessage to HttpResponse
    • isResponseOk uses response.ok, getErrorResponseBody uses response.text()
    • Removed raw node:http/node:https usage from request functions
    • getHttpModule/getResponse retained for file-upload.ts backward compat
  • Fix retry logic: don't retry 4xx client errors (400, 404), always retry 429 with backoff
  • Update socket-sdk-class.ts: IncomingMessageHttpResponse, .statusCode.status, streaming → buffered reads

Test plan

  • All 763 tests pass
  • TypeScript type checks pass
  • Lint passes

jdalton added 3 commits April 5, 2026 00:00
…-queue

Remove duplicated PromiseQueue implementation and import from the shared
library instead. The lib version has an identical API with a more
efficient idle notification mechanism.
Replace raw node:http/node:https usage with lib's httpRequest() in
http-client.ts and socket-sdk-class.ts. This deduplicates HTTP handling
logic and aligns the SDK with the shared library's request infrastructure.

Key changes:
- createGetRequest, createDeleteRequest, createRequestWithJson now use
  httpRequest() and return HttpResponse instead of IncomingMessage
- ResponseError.response is now HttpResponse (status/statusText vs
  statusCode/statusMessage)
- isResponseOk uses response.ok instead of manual statusCode range check
- getErrorResponseBody/getResponseJson work with buffered HttpResponse
- NDJSON streaming replaced with response.text().split('\n') parsing
- downloadOrgFullScanFilesAsTar and streamFullScan use buffered writes
- downloadPatch simplified from raw http.get to httpRequest()
- file-upload.ts wraps IncomingMessage via wrapIncomingMessage() adapter
- getHttpModule and getResponse retained for file-upload.ts compatibility
The retry logic was retrying all HTTP errors including 4xx client errors
(400, 404, etc.) which are permanent failures that won't succeed on
retry. After migrating to @socketsecurity/lib/http-request, this caused
ERR_NOCK_NO_MATCH in tests because nock interceptors were consumed on
the first attempt but pRetry would retry.

Changes:
- Throw immediately on 4xx errors (except 429) in #executeWithRetry to
  prevent wasteful retries of permanent failures
- Always retry 429 (rate limiting) with default backoff when Retry-After
  header is missing/invalid/past, since rate limits are temporary
- Use nock callback-style replies for 400/404 tests (nock v14 with
  @mswjs/interceptors requires this for httpRequest compatibility)
- Update stream-limits test to expect thrown error since lib enforces
  maxResponseSize at network level (non-ResponseError)
@jdalton jdalton changed the title refactor: replace local PromiseQueue with @socketsecurity/lib refactor: deduplicate with @socketsecurity/lib Apr 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants