Open History to see the last commit
1import { assert, it } from "@effect/vitest";
2import * as ConfigProvider from "effect/ConfigProvider";
3import * as Effect from "effect/Effect";
4
5import { makeCloudCliOAuthConfig, makeRelayUrlConfig } from "./publicConfig.ts";
6
7const provideEnv = (env: Readonly<Record<string, string>>) =>
8 Effect.provide(ConfigProvider.layer(ConfigProvider.fromEnv({ env })));
9
10it.effect("uses the statically injected relay URL when no runtime override exists", () =>
11 Effect.gen(function* () {
12 const relayUrl = yield* makeRelayUrlConfig("https://embedded.example.test///").pipe(
13 provideEnv({}),
14 );
15
16 assert.equal(relayUrl, "https://embedded.example.test");
17 }),
18);
19
20it.effect("prefers a runtime relay URL override over the statically injected value", () =>
21 Effect.gen(function* () {
22 const relayUrl = yield* makeRelayUrlConfig("https://embedded.example.test").pipe(
23 provideEnv({ T3CODE_RELAY_URL: "https://runtime.example.test///" }),
24 );
25
26 assert.equal(relayUrl, "https://runtime.example.test");
27 }),
28);
29
30it.effect("requires a relay URL when the server bundle has no injected value", () =>
31 makeRelayUrlConfig("").pipe(provideEnv({}), Effect.flip),
32);
33
34it.effect("rejects an insecure runtime relay URL override", () =>
35 makeRelayUrlConfig("https://embedded.example.test").pipe(
36 provideEnv({ T3CODE_RELAY_URL: "http://runtime.example.test" }),
37 Effect.flip,
38 ),
39);
40
41it.effect("rejects an injected relay URL with a non-origin path", () =>
42 makeRelayUrlConfig("https://embedded.example.test/path").pipe(provideEnv({}), Effect.flip),
43);
44
45it.effect("derives direct Clerk OAuth endpoints from statically injected public config", () =>
46 Effect.gen(function* () {
47 const config = yield* makeCloudCliOAuthConfig({
48 clerkPublishableKeyFallback: "pk_test_Y2xlcmsuZXhhbXBsZS50ZXN0JA==",
49 clerkCliOAuthClientIdFallback: "oauth_client_embedded",
50 }).pipe(provideEnv({}));
51
52 assert.deepEqual(config, {
53 authorizationEndpoint: "https://clerk.example.test/oauth/authorize",
54 tokenEndpoint: "https://clerk.example.test/oauth/token",
55 clientId: "oauth_client_embedded",
56 redirectUri: "http://127.0.0.1:34338/callback",
57 scopes: ["openid", "profile", "email"],
58 });
59 }),
60);
61
62it.effect("prefers runtime Clerk OAuth config overrides over statically injected values", () =>
63 Effect.gen(function* () {
64 const config = yield* makeCloudCliOAuthConfig({
65 clerkPublishableKeyFallback: "pk_test_ZW1iZWRkZWQuZXhhbXBsZS50ZXN0JA==",
66 clerkCliOAuthClientIdFallback: "oauth_client_embedded",
67 }).pipe(
68 provideEnv({
69 T3CODE_CLERK_PUBLISHABLE_KEY: "pk_test_cnVudGltZS5leGFtcGxlLnRlc3Qk",
70 T3CODE_CLERK_CLI_OAUTH_CLIENT_ID: "oauth_client_runtime",
71 }),
72 );
73
74 assert.equal(config.authorizationEndpoint, "https://runtime.example.test/oauth/authorize");
75 assert.equal(config.tokenEndpoint, "https://runtime.example.test/oauth/token");
76 assert.equal(config.clientId, "oauth_client_runtime");
77 }),
78);
79
80it.effect("requires Clerk OAuth config when the server bundle has no injected values", () =>
81 makeCloudCliOAuthConfig({
82 clerkPublishableKeyFallback: "",
83 clerkCliOAuthClientIdFallback: "",
84 }).pipe(provideEnv({}), Effect.flip),
85);