-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat(webapp): let the deployment S2 client endpoints be overridden #4867
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
d-cs
wants to merge
1
commit into
main
Choose a base branch
from
feat/s2-local-endpoint
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+79
−4
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import { S2 } from "@s2-dev/streamstore"; | ||
| import { env } from "~/env.server"; | ||
|
|
||
| export type DeploymentS2Config = { | ||
| accessToken: string; | ||
| endpoint?: string; | ||
| }; | ||
|
|
||
| // One endpoint drives both the account and basin hosts. The SDK honours only endpoints passed | ||
| // here (`S2Environment.parse()` is opt-in and we never call it), and overriding just one of the | ||
| // two would send the access token to the hosted service while the other half went elsewhere. | ||
| export function buildDeploymentS2Client({ accessToken, endpoint }: DeploymentS2Config): S2 { | ||
| return new S2({ | ||
| accessToken, | ||
| endpoints: { account: endpoint, basin: endpoint }, | ||
| }); | ||
| } | ||
|
|
||
| export function createDeploymentS2Client(): S2 | undefined { | ||
| if (env.S2_ENABLED !== "1") { | ||
| return undefined; | ||
| } | ||
|
|
||
| return buildDeploymentS2Client({ | ||
| accessToken: env.S2_ACCESS_TOKEN, | ||
| endpoint: env.S2_DEPLOYMENT_ENDPOINT, | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { buildDeploymentS2Client } from "~/v3/s2Client.server"; | ||
|
|
||
| const BASIN = "trigger-local"; | ||
|
|
||
| describe("buildDeploymentS2Client", () => { | ||
| it("uses the SDK's hosted defaults when no endpoint is configured", () => { | ||
| const client = buildDeploymentS2Client({ accessToken: "token" }); | ||
|
|
||
| expect(client.endpoints.accountBaseUrl()).toBe("https://a.s2.dev/v1"); | ||
| expect(client.endpoints.basinBaseUrl(BASIN)).toBe(`https://${BASIN}.b.s2.dev/v1`); | ||
| expect(client.endpoints.includeBasinHeader).toBe(false); | ||
| }); | ||
|
|
||
| it("points both the account and basin hosts at a configured endpoint", () => { | ||
| const client = buildDeploymentS2Client({ | ||
| accessToken: "token", | ||
| endpoint: "http://localhost:4566", | ||
| }); | ||
|
|
||
| expect(client.endpoints.accountBaseUrl()).toBe("http://localhost:4566/v1"); | ||
| expect(client.endpoints.basinBaseUrl(BASIN)).toBe("http://localhost:4566/v1"); | ||
| expect(client.endpoints.includeBasinHeader).toBe(true); | ||
| }); | ||
|
|
||
| // A split configuration would send the access token to the hosted service while the operator | ||
| // believed the client was entirely local, so one value has to drive both hosts. | ||
| it("never leaves one host hosted while the other is overridden", () => { | ||
| const client = buildDeploymentS2Client({ | ||
| accessToken: "token", | ||
| endpoint: "http://localhost:4566", | ||
| }); | ||
|
|
||
| expect(client.endpoints.accountBaseUrl()).not.toContain("s2.dev"); | ||
| expect(client.endpoints.basinBaseUrl(BASIN)).not.toContain("s2.dev"); | ||
| }); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
Add crumbs for the endpoint-override path.
Add a crumb marker or
#region@crumbs`` block while implementing this configuration path. Use an approved namespace, or ask before selecting one.apps/webapp/app/env.server.ts#L82-L90: mark the endpoint parsing and normalization path.apps/webapp/app/v3/s2Client.server.ts#L12-L16: mark the endpoint client-construction path.As per coding guidelines: “Add crumbs as you write code” and “Do not invent new namespaces.”
📍 Affects 2 files
apps/webapp/app/env.server.ts#L82-L90(this comment)apps/webapp/app/v3/s2Client.server.ts#L12-L16Source: Coding guidelines