Skip to content

Change the format of the proxy url - #7

Merged
SiebeBaree merged 10 commits into
Enkryptify:mainfrom
axlistas:main
Jun 4, 2026
Merged

Change the format of the proxy url#7
SiebeBaree merged 10 commits into
Enkryptify:mainfrom
axlistas:main

Conversation

@axlistas

@axlistas axlistas commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Documentation

    • Simplified proxy API example by removing a commented option from the sample request.
  • Refactor

    • Proxy requests now encode routing context (workspace/project/environment/is-personal) in the request URL path and as top-level payload fields.
  • Bug Fixes

    • Upstream responses and error statuses are preserved and surfaced correctly; hop-by-hop headers are stripped and proxy errors are mapped to SDK errors.
  • Tests

    • Updated tests for routed proxy URLs, envelope-wrapped upstream responses, and new error/response behaviors.
  • Chores

    • Ensure build step runs in prepare script (updated npm prepare).

axlistas and others added 6 commits April 30, 2026 13:53
Align proxy requests with backend routing by putting
workspace/project/environment in the proxy URL path.

Remove config and is-personal from the wire payload
to match the proxy request schema.

Made-with: Cursor
Bring back usePersonal support for proxy requests and interceptor
rules by restoring is-personal on the proxy wire payload.

Set the default proxy base URL back to the root host path
instead of /v1/proxy and align tests accordingly.

Made-with: Cursor
@coderabbitai

coderabbitai Bot commented Jun 2, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e55aec45-b06b-4450-a306-ddb002241823

📥 Commits

Reviewing files that changed from the base of the PR and between 95dd979 and cc67e26.

📒 Files selected for processing (1)
  • package.json
✅ Files skipped from review due to trivial changes (1)
  • package.json

Walkthrough

The PR flattens proxy scope (workspace, project, environment-id, is-personal) from a nested config object into top-level wire fields, routes that scope as path segments appended to the proxy base URL (e.g., /ws-1/prj-1/env-1), and updates send/unwrap/error mapping logic to handle the proxy’s JSON envelope. HttpInterceptor, EnkryptifyProxy, sendProxyWire, and related tests/documentation are updated accordingly.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • Enkryptify/sdk#4: Both PRs reshape how the interceptor builds/sends the proxy wire payload and touch interceptor/proxy plumbing.
  • Enkryptify/sdk#3: The earlier proxy implementation that introduced the wire body/response handling this PR refactors and extends.
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 56.25% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Change the format of the proxy url' is vague and generic. It uses non-descriptive language that doesn't clearly convey the specific architectural change being made. Revise the title to be more specific about the change, such as 'Move workspace/project/environment from config object to proxy URL path' or 'Restructure proxy wire payload with top-level scope fields in URL'.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
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 unit tests (beta)
  • Create PR with unit tests

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

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/proxy.ts (1)

87-95: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Preserve the new top-level scope fields in the posted wire body.

sendProxyWire() currently drops workspace, project, and "environment-id" when rebuilding wireBody, so the JSON payload no longer matches ProxyWireBody. Routing them into the URL is additive here, not a replacement for the contract this PR just introduced.

Suggested fix
-    const wireBody: Record<string, unknown> = {
+    const wireBody: ProxyWireBody = {
         url: body.url,
         method: body.method,
+        workspace: body.workspace,
+        project: body.project,
+        "environment-id": body["environment-id"],
         "is-personal": body["is-personal"],
     };
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/proxy.ts` around lines 87 - 95, sendProxyWire is currently omitting the
top-level workspace, project and "environment-id" fields when constructing
wireBody; restore those fields so the posted JSON matches ProxyWireBody by
adding workspace: body.workspace, project: body.project and "environment-id":
body["environment-id"] to the wireBody object (in addition to still calling
buildProxyRequestUrl(ctx.proxyUrl, body.workspace, body.project,
body["environment-id"]) to create proxyRequestUrl). Update the construction of
wireBody (the variable named wireBody) so it includes those three fields
whenever present on body, while keeping the existing conditional headers/body
handling.
🧹 Nitpick comments (2)
tests/proxy.test.ts (1)

419-431: ⚡ Quick win

Assert content-length is stripped too.

This test injects both hop-by-hop headers, but it only verifies transfer-encoding. Please also assert that content-length is removed so the test fully covers the behavior described here.

Suggested assertion
         const res = await client.proxy.fetch("https://upstream/x");
+        expect(res.headers.get("content-length")).toBeNull();
         expect(res.headers.get("transfer-encoding")).toBeNull();
         expect(res.headers.get("x-custom")).toBe("keep");
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/proxy.test.ts` around lines 419 - 431, In the "strips hop-by-hop
headers (content-length, transfer-encoding) from the synthesized Response" test,
add an assertion that the synthesized Response also has the "content-length"
header removed: after calling client.proxy.fetch("https://upstream/x") and the
existing transfer-encoding assertion, assert that
res.headers.get("content-length") is null (reference: Enkryptify, proxy.fetch,
res.headers).
tests/interceptor.test.ts (1)

378-399: ⚡ Quick win

Assert the full flattened scope contract here.

These tests currently prove URL routing and is-personal, but they do not verify that workspace, project, and environment-id are still present at the top level of the wire body. A regression that keeps the routed URL correct while re-nesting or dropping those fields would still pass.

Suggested assertions
         const wire = await findProxyCall(fetchMock);
         expect(wire?.["is-personal"]).toBe(false);
+        expect(wire?.workspace).toBe("ws-x");
+        expect(wire?.project).toBe("prj-y");
+        expect(wire?.["environment-id"]).toBe("env-z");
+        expect(wire?.config).toBeUndefined();
         const proxyCall = await findCallByUrlPrefix(fetchMock, "https://proxy.test.com/");
         expect(proxyCall?.url).toBe("https://proxy.test.com/ws-x/prj-y/env-z");
         const wire = await findProxyCall(fetchMock);
         expect(wire?.["is-personal"]).toBe(false);
+        expect(wire?.workspace).toBe("override-ws");
+        expect(wire?.project).toBe("override-prj");
+        expect(wire?.["environment-id"]).toBe("override-env");
+        expect(wire?.config).toBeUndefined();
         const proxyCall = await findCallByUrlPrefix(fetchMock, "https://proxy.test.com/");
         expect(proxyCall?.url).toBe("https://proxy.test.com/override-ws/override-prj/override-env");

Also applies to: 402-428

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/interceptor.test.ts` around lines 378 - 399, Update the test that sets
up Enkryptify (activeClient via makeConfig with workspace/project/environment
and interceptor rules) to also assert the full flattened scope contract exists
on the proxied wire body: after getting wire from findProxyCall(fetchMock)
verify wire.workspace === "ws-x", wire.project === "prj-y" and
wire["environment-id"] === "env-z" (and keep the existing is-personal check);
apply the same additional assertions in the companion test that mirrors this one
(the test using the same makeConfig values and fetchMock flow) so we ensure
workspace, project and environment-id remain top-level fields and aren’t
re-nested or dropped.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/proxy.ts`:
- Around line 333-343: The hop-by-hop header set HOP_BY_HOP_RESPONSE_HEADERS
incorrectly lists "trailers" instead of the RFC-defined "trailer", so replace
the "trailers" entry with "trailer" in the HOP_BY_HOP_RESPONSE_HEADERS
ReadonlySet to ensure proxied Trailer headers are stripped from synthesized
responses; update the set initialization where HOP_BY_HOP_RESPONSE_HEADERS is
declared.

---

Outside diff comments:
In `@src/proxy.ts`:
- Around line 87-95: sendProxyWire is currently omitting the top-level
workspace, project and "environment-id" fields when constructing wireBody;
restore those fields so the posted JSON matches ProxyWireBody by adding
workspace: body.workspace, project: body.project and "environment-id":
body["environment-id"] to the wireBody object (in addition to still calling
buildProxyRequestUrl(ctx.proxyUrl, body.workspace, body.project,
body["environment-id"]) to create proxyRequestUrl). Update the construction of
wireBody (the variable named wireBody) so it includes those three fields
whenever present on body, while keeping the existing conditional headers/body
handling.

---

Nitpick comments:
In `@tests/interceptor.test.ts`:
- Around line 378-399: Update the test that sets up Enkryptify (activeClient via
makeConfig with workspace/project/environment and interceptor rules) to also
assert the full flattened scope contract exists on the proxied wire body: after
getting wire from findProxyCall(fetchMock) verify wire.workspace === "ws-x",
wire.project === "prj-y" and wire["environment-id"] === "env-z" (and keep the
existing is-personal check); apply the same additional assertions in the
companion test that mirrors this one (the test using the same makeConfig values
and fetchMock flow) so we ensure workspace, project and environment-id remain
top-level fields and aren’t re-nested or dropped.

In `@tests/proxy.test.ts`:
- Around line 419-431: In the "strips hop-by-hop headers (content-length,
transfer-encoding) from the synthesized Response" test, add an assertion that
the synthesized Response also has the "content-length" header removed: after
calling client.proxy.fetch("https://upstream/x") and the existing
transfer-encoding assertion, assert that res.headers.get("content-length") is
null (reference: Enkryptify, proxy.fetch, res.headers).
🪄 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: 7171ac6a-4bed-4585-a003-56254c500b25

📥 Commits

Reviewing files that changed from the base of the PR and between 6c71cbf and 5a6b7a2.

📒 Files selected for processing (3)
  • src/proxy.ts
  • tests/interceptor.test.ts
  • tests/proxy.test.ts

Comment thread src/proxy.ts
axlistas added 2 commits June 3, 2026 09:22
Consumers installing the SDK via a git URL (git+https://…#main) have no
published dist/, so pnpm must build it during the prepare lifecycle.
Append tsup to prepare; keep husky for local dev but guard it with
`|| true` so it never blocks the build when there is no .git (the
git-dep tarball case).
@SiebeBaree
SiebeBaree merged commit c37dbb2 into Enkryptify:main Jun 4, 2026
6 checks passed
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