[codex] Type malformed Clerk public config failures (#3422)
Co-authored-by: codex <[email protected]>
This commit is contained in:
1 parent
4d790f0064
commit
4d3fcacd84
2 files changed
+46
-10
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { assert, it } from "@effect/vitest";
|
||||
import * as ConfigProvider from "effect/ConfigProvider";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Result from "effect/Result";
|
||||
|
||||
import {
|
||||
makeCloudCliOAuthConfig,
|
||||
@@ -88,6 +89,27 @@ it.effect("requires Clerk OAuth config when the server bundle has no injected va
|
||||
}).pipe(provideEnv({}), Effect.flip),
|
||||
);
|
||||
|
||||
it.effect("reports malformed Clerk publishable keys as typed configuration failures", () =>
|
||||
Effect.gen(function* () {
|
||||
const result = yield* makeCloudCliOAuthConfig({
|
||||
clerkPublishableKeyFallback: "pk_test_not-base64!!",
|
||||
clerkCliOAuthClientIdFallback: "oauth_client_embedded",
|
||||
}).pipe(provideEnv({}), Effect.result);
|
||||
|
||||
assert.isTrue(Result.isFailure(result));
|
||||
if (Result.isFailure(result)) {
|
||||
assert.equal(result.failure.cause._tag, "SourceError");
|
||||
if (result.failure.cause._tag === "SourceError") {
|
||||
assert.equal(
|
||||
result.failure.cause.message,
|
||||
"Failed to derive Clerk Frontend API URL from the publishable key.",
|
||||
);
|
||||
assert.instanceOf(result.failure.cause.cause, Error);
|
||||
}
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
it("resolves relay client tracing from runtime config with build-time fallback", () => {
|
||||
const fallback = {
|
||||
tracesUrl: "https://embedded.example.test/v1/traces",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { clerkFrontendApiUrlFromPublishableKey } from "@t3tools/shared/relayAuth";
|
||||
import { normalizeSecureRelayUrl } from "@t3tools/shared/relayUrl";
|
||||
import * as Config from "effect/Config";
|
||||
import * as ConfigProvider from "effect/ConfigProvider";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Option from "effect/Option";
|
||||
import * as Schema from "effect/Schema";
|
||||
@@ -131,16 +132,29 @@ export function makeCloudCliOAuthConfig({
|
||||
clerkCliOAuthClientIdFallback,
|
||||
),
|
||||
}).pipe(
|
||||
Config.map(({ clerkPublishableKey, clientId }) => {
|
||||
const clerkFrontendApiUrl = clerkFrontendApiUrlFromPublishableKey(clerkPublishableKey);
|
||||
return {
|
||||
authorizationEndpoint: `${clerkFrontendApiUrl}/oauth/authorize`,
|
||||
tokenEndpoint: `${clerkFrontendApiUrl}/oauth/token`,
|
||||
clientId,
|
||||
redirectUri: CLOUD_CLI_OAUTH_REDIRECT_URI,
|
||||
scopes: CLOUD_CLI_OAUTH_SCOPES,
|
||||
} satisfies CloudCliOAuthConfig;
|
||||
}),
|
||||
Config.mapOrFail(({ clerkPublishableKey, clientId }) =>
|
||||
Effect.try({
|
||||
try: () => clerkFrontendApiUrlFromPublishableKey(clerkPublishableKey),
|
||||
catch: (cause) =>
|
||||
new Config.ConfigError(
|
||||
new ConfigProvider.SourceError({
|
||||
message: "Failed to derive Clerk Frontend API URL from the publishable key.",
|
||||
cause,
|
||||
}),
|
||||
),
|
||||
}).pipe(
|
||||
Effect.map(
|
||||
(clerkFrontendApiUrl) =>
|
||||
({
|
||||
authorizationEndpoint: `${clerkFrontendApiUrl}/oauth/authorize`,
|
||||
tokenEndpoint: `${clerkFrontendApiUrl}/oauth/token`,
|
||||
clientId,
|
||||
redirectUri: CLOUD_CLI_OAUTH_REDIRECT_URI,
|
||||
scopes: CLOUD_CLI_OAUTH_SCOPES,
|
||||
}) satisfies CloudCliOAuthConfig,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user