Skip to content

feat: getOrgFullScanCached with 202 polling for cached full scans#660

Closed
John-David Dalton (jdalton) wants to merge 1 commit into
v1.4.xfrom
jdalton/surf-742-add-support-for-the-cached-flag-in-the-sdkcli-for-full-scans
Closed

feat: getOrgFullScanCached with 202 polling for cached full scans#660
John-David Dalton (jdalton) wants to merge 1 commit into
v1.4.xfrom
jdalton/surf-742-add-support-for-the-cached-flag-in-the-sdkcli-for-full-scans

Conversation

@jdalton

@jdalton John-David Dalton (jdalton) commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

Adds a buffered, cache-aware full-scan reader for the v1.4.x SDK line. Linear: SURF-742.

getOrgFullScanCached(orgSlug, fullScanId, options?)

  • Requests ?cached=true by default (immutable scan store).
  • 200 cache hit → parses the ndjson and returns { success, status: 200, data: SocketArtifact[] }.
  • 202 cache miss → the server is computing in the background; polls with exponential backoff (1s → 10s, 10min budget) until a 200, then returns. Never sees a pending result.
  • Budget exhausted → { success: false, status: 202, error: 'Cached full scan not ready', ... }.
  • cached: false → sends no cached param and returns the first 200 with no polling.

The streaming getOrgFullScan is untouched — it still pipes to a file/stdout, so it never has to "pipe a non-existent stream" on a 202. Buffered vs streamed are separate methods on purpose: widening getOrgFullScan's return type breaks handleApiCall<T> inference at the CLI's --stream call site, which SURF-742 requires to stay untouched.

Consumed by SocketDev/socket-cli#1425 (base v1.x), which pins the next SDK release (1.4.97) for socket scan view.

Verification
  • tsc --noEmit: clean
  • eslint + oxlint + biome: clean (sequential awaits in the poll loop carry the repo's eslint-disable no-await-in-loop, matching existing callsites)
  • vitest: 14/14 pass, incl. 5 new nock-driven cases in test/full-scan-cached.test.ts (200 hit, 202→200 poll, timeout, cached:false, 404)

getOrgFullScanCached reads a full scan's artifacts into memory, serving
pre-computed results from the immutable scan store via ?cached=true (the
default). A cache hit returns 200 with the ndjson artifacts; a cache miss
returns 202 Accepted while the server computes them, so the method polls
with exponential backoff until a 200 arrives or the poll budget is spent.

Unlike the streaming getOrgFullScan it buffers and returns the parsed
artifacts instead of piping to a stream, so it never pipes a non-existent
stream on a 202. The streaming getOrgFullScan is left untouched.
@jdalton

Copy link
Copy Markdown
Collaborator Author

Withdrawing: strategy changed — socket-cli v1.x will move to the latest @socketsecurity/sdk (4.x) and the SDK v1.4.x/v1.x release branches won't be maintained. SURF-742 for the shipping line is being done as a direct-API backport in socket-cli v1.x (no SDK dependency), so this v1.4.x SDK change isn't needed. The equivalent already exists on socket-sdk-js main.

@jdalton
John-David Dalton (jdalton) deleted the jdalton/surf-742-add-support-for-the-cached-flag-in-the-sdkcli-for-full-scans branch July 24, 2026 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant