Skip to content

Replace @knocklabs/client axios transport with fetch#1010

Open
cjbell wants to merge 9 commits into
mainfrom
cjbell-replace-axios-fetch-3b83
Open

Replace @knocklabs/client axios transport with fetch#1010
cjbell wants to merge 9 commits into
mainfrom
cjbell-replace-axios-fetch-3b83

Conversation

@cjbell

@cjbell cjbell commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Description

Replace the internal @knocklabs/client HTTP transport from axios/axios-retry with native fetch, preserving the makeRequest({ method, url, params, data }) call shape and removing the axios dependencies.

Transport rewrite:

  • Reimplements query-param serialization, header handling, JSON body encoding, response parsing, and retry/backoff on fetch.
  • Holds behavior parity with axios: array and nested-object param serialization, omission of null-valued headers, retry count (1 initial attempt + 3 retries) and conditions (5xx, 429, network errors), Retry-After handling, and the error.response.status / error.response.data shape that consumers read.
  • Returns an actionable error when no global fetch exists.

Consumer regressions the migration would have introduced, caught in review and fixed here:

  • Slack and MS Teams connection status showed "error" instead of "disconnected" for an unconnected tenant, because the @knocklabs/react-core hooks keyed off the axios-only error.code. They now read response.status, and AuthCheckResult no longer exposes code, exposing response.status instead.
  • Retry-After on 429 and 503 responses was no longer honored (axios-retry respected it). Restored, along with retry-delay jitter.

Also in this PR:

  • Read the retry response body without cloning it, so the underlying connection is released.
  • A characterization test suite pins the wire format, response mapping, and retry behavior, with regression tests for the two fixes above.
  • Changesets for @knocklabs/client and @knocklabs/react-core, both patch.

Checklist

  • Tests have been added for new features or major refactors to existing features.

Screenshots or videos

N/A. Non-UI SDK change.

Validation

  • @knocklabs/client api.test.ts and api.characterization.test.ts, plus the @knocklabs/react-core Slack and MS Teams connection-status hook tests, pass.
  • Type-check, lint, and Prettier pass on the changed files.
  • Rebased onto main; yarn.lock validated with yarn install --mode=update-lockfile (no drift).

Linear Issue: KNO-12329

Open in Web Open in Cursor 

@changeset-bot

changeset-bot Bot commented Jun 5, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: eb1b42b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@knocklabs/react-core Patch
@knocklabs/client Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel

vercel Bot commented Jun 5, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
javascript-ms-teams-connect-example Ready Ready Preview, Comment Jun 18, 2026 4:35pm
javascript-nextjs-example Ready Ready Preview, Comment Jun 18, 2026 4:35pm
javascript-slack-connect-example Ready Ready Preview, Comment Jun 18, 2026 4:35pm
javascript-slack-kit-example Ready Ready Preview, Comment Jun 18, 2026 4:35pm

Request Review

Comment thread packages/client/src/api.ts Outdated
@kylemcd kylemcd force-pushed the cjbell-replace-axios-fetch-3b83 branch from 394b56a to 0916d4c Compare June 18, 2026 14:51
@kylemcd kylemcd force-pushed the cjbell-replace-axios-fetch-3b83 branch from 0916d4c to 3d31bc4 Compare June 18, 2026 14:55

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 3d31bc4. Configure here.

Comment thread packages/client/src/api.ts
cursoragent and others added 8 commits June 18, 2026 11:27
Co-authored-by: Chris Bell <chris@cjbell.co>
Co-authored-by: Chris Bell <chris@cjbell.co>
Co-authored-by: Chris Bell <chris@cjbell.co>
…ias, drop dead eslint directive, document retry loop)
Addresses Cursor BugBot "Unread bodies on HTTP retries". On retryable
5xx/429 responses the retry loop read a clone and left the original
Response body undrained. The response is discarded before the next
attempt, so read it directly (no clone), which drains the body and
releases the connection. Also updates the retry-exhaustion test to
return a fresh Response per call, matching real fetch semantics where a
body can only be consumed once.
…s, not axios code

The connection-status hooks classified a not-yet-connected tenant by
reading the axios error code ("ERR_BAD_REQUEST"). The new fetch
transport returns an ApiRequestError with no code field, so that branch
died and unconnected tenants rendered as a connection "error" instead
of "disconnected". Key off response.status (4xx) instead, which both
the old and new transports provide. Adds regression tests for the
not-set path (previously uncovered) and updates AuthCheckResult to drop
the axios-only code field and expose response.status.
axios-retry's exponentialDelay used Math.max(backoff, retryAfter(error))
and added up to 20% jitter. The fetch port used a fixed exponential
backoff and dropped both, so a 429/503 carrying Retry-After was retried
on the short backoff (exhausting retries in ~1.4s) instead of waiting
the server-specified window. Parse Retry-After (seconds or HTTP date)
and take the max with the jittered backoff, restoring the old behavior.
@codecov

codecov Bot commented Jun 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.12150% with 19 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.46%. Comparing base (3dd0aa8) to head (eb1b42b).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
packages/client/src/api.ts 90.77% 19 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1010      +/-   ##
==========================================
+ Coverage   63.95%   64.46%   +0.51%     
==========================================
  Files         212      212              
  Lines       10028    10211     +183     
  Branches     1321     1389      +68     
==========================================
+ Hits         6413     6583     +170     
- Misses       3590     3603      +13     
  Partials       25       25              
Files with missing lines Coverage Δ
packages/react-core/src/modules/core/types.ts 100.00% <ø> (ø)
...dules/ms-teams/hooks/useMsTeamsConnectionStatus.ts 98.07% <100.00%> (+10.32%) ⬆️
...rc/modules/slack/hooks/useSlackConnectionStatus.ts 93.65% <100.00%> (+3.65%) ⬆️
packages/client/src/api.ts 92.17% <90.77%> (-5.91%) ⬇️

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.

3 participants