Skip to content

feat: add interceptor#4

Merged
SiebeBaree merged 1 commit into
mainfrom
04-21-feat_add_interceptor
Apr 21, 2026
Merged

feat: add interceptor#4
SiebeBaree merged 1 commit into
mainfrom
04-21-feat_add_interceptor

Conversation

@SiebeBaree
Copy link
Copy Markdown
Member

@SiebeBaree SiebeBaree commented Apr 21, 2026

Summary by CodeRabbit

Release Notes

  • New Features

    • Added HTTP request interception with configurable matching rules
    • Support for URL rewriting, header manipulation, and body overrides per rule
    • Per-rule workspace, project, and environment configuration overrides
  • Chores

    • Node.js minimum version requirement updated to >=18
    • Added new runtime dependency
  • Tests

    • Comprehensive test coverage added for interceptor functionality

Copy link
Copy Markdown
Member Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 21, 2026

Walkthrough

This pull request introduces HTTP request interception capabilities to the Enkryptify SDK. It adds a new @mswjs/interceptors runtime dependency (v0.41.4) and Node.js >=18 engine requirement, implements an HttpInterceptor class that intercepts outbound fetch/Node HTTP requests and routes them through the Enkryptify proxy based on configured rules. The PR refactors proxy internals to expose sendProxyWire and ProxySendContext for reuse, introduces interceptor configuration types with rule matching via string prefix/RegExp/function, optional URL/header/body rewrites, and per-rule proxy overrides. It adds utility functions for URL templating, header merging with hop-by-hop filtering, and body resolution supporting JSON/function transformations. The Enkryptify class integrates optional interceptor lifecycle management, exposing an _interceptorReady() method for test coordination. Comprehensive test coverage validates matching logic, body handling, error paths, and interceptor lifecycle behavior.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~90 minutes

Possibly related PRs

  • feat: added support for proxy #3: Modifies proxy-related code (src/proxy.ts) and exported types to refactor sendProxyWire and ProxySendContext, which serve as the foundation for the HTTP interceptor integration in this PR.
  • SDK v0.1 #1: Extends core SDK files (src/enkryptify.ts, src/errors.ts, src/index.ts, src/types.ts) that this PR builds upon and directly integrates with for interceptor feature implementation.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: add interceptor' directly and clearly summarizes the main change—adding HTTP interceptor functionality to the SDK.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 04-21-feat_add_interceptor

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/enkryptify.ts`:
- Around line 134-135: The code reads interceptorConfig.rules.length without
validating rules' shape; update the guard so you only access .length when rules
is an array (e.g., use Array.isArray(interceptorConfig.rules) or coerce to an
array) and handle bad shapes by either treating rules as empty or throwing a
controlled SDK error; change the condition around interceptorConfig (the block
that checks interceptorConfig.enabled and currently reads
interceptorConfig.rules.length) to validate interceptorConfig.rules before using
.length and keep the rest of the block (including usage of this.#proxy._ctx)
unchanged.

In `@src/internal/template.ts`:
- Around line 59-67: mergeHeaders currently strips hop-by-hop headers from input
but then applies overrides which can reintroduce them; update the overrides loop
in mergeHeaders to ignore any override whose lower-cased key is in the
hop-by-hop set (e.g. HOP_BY_HOP_HEADERS) so that overrides cannot add those
headers back, and still allow deletes (value === undefined) to remove headers
but never re-add a hop-by-hop header to out.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9c8c514c-1f63-494f-9fb8-19004e7d62da

📥 Commits

Reviewing files that changed from the base of the PR and between e05bb47 and 4bb17b5.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (9)
  • package.json
  • src/enkryptify.ts
  • src/errors.ts
  • src/index.ts
  • src/interceptor.ts
  • src/internal/template.ts
  • src/proxy.ts
  • src/types.ts
  • tests/interceptor.test.ts

Comment thread src/enkryptify.ts
Comment thread src/internal/template.ts
@SiebeBaree SiebeBaree marked this pull request as ready for review April 21, 2026 12:10
@SiebeBaree SiebeBaree merged commit f215302 into main Apr 21, 2026
6 checks passed
@SiebeBaree SiebeBaree deleted the 04-21-feat_add_interceptor branch April 29, 2026 05:49
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.

1 participant