Skip to content

Commit f3b43a1

Browse files
[codex] Structure missing client cloud config errors (#3346)
Co-authored-by: codex <codex@users.noreply.github.com>
1 parent 8331511 commit f3b43a1

4 files changed

Lines changed: 51 additions & 4 deletions

File tree

apps/mobile/src/features/cloud/publicConfig.test.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import { describe, expect, it, vi } from "vite-plus/test";
22

3-
import { hasTracingPublicConfig, resolveCloudPublicConfig } from "./publicConfig";
3+
import {
4+
CloudPublicConfigMissingError,
5+
hasTracingPublicConfig,
6+
resolveCloudPublicConfig,
7+
resolveRelayClerkTokenOptions,
8+
} from "./publicConfig";
49

510
vi.mock("expo-constants", () => ({
611
default: {
@@ -11,6 +16,12 @@ vi.mock("expo-constants", () => ({
1116
}));
1217

1318
describe("resolveCloudPublicConfig", () => {
19+
it("reports the missing Clerk JWT template as structured configuration", () => {
20+
expect(() => resolveRelayClerkTokenOptions()).toThrowError(
21+
new CloudPublicConfigMissingError({ key: "T3CODE_CLERK_JWT_TEMPLATE" }),
22+
);
23+
});
24+
1425
it("returns no cloud configuration for an unconfigured build", () => {
1526
expect(resolveCloudPublicConfig({})).toEqual({
1627
clerk: {

apps/mobile/src/features/cloud/publicConfig.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
import Constants from "expo-constants";
22
import { relayClerkTokenOptions } from "@t3tools/shared/relayAuth";
33
import { normalizeSecureRelayUrl } from "@t3tools/shared/relayUrl";
4+
import * as Schema from "effect/Schema";
5+
6+
export class CloudPublicConfigMissingError extends Schema.TaggedErrorClass<CloudPublicConfigMissingError>()(
7+
"CloudPublicConfigMissingError",
8+
{
9+
key: Schema.Literal("T3CODE_CLERK_JWT_TEMPLATE"),
10+
},
11+
) {
12+
override get message(): string {
13+
return `${this.key} is not configured.`;
14+
}
15+
}
416

517
export interface CloudPublicConfig {
618
readonly clerk: {
@@ -87,7 +99,7 @@ export function hasTracingPublicConfig(
8799
export function resolveRelayClerkTokenOptions() {
88100
const { jwtTemplate } = resolveCloudPublicConfig().clerk;
89101
if (!jwtTemplate) {
90-
throw new Error("T3CODE_CLERK_JWT_TEMPLATE is not configured.");
102+
throw new CloudPublicConfigMissingError({ key: "T3CODE_CLERK_JWT_TEMPLATE" });
91103
}
92104
return relayClerkTokenOptions(jwtTemplate);
93105
}

apps/web/src/cloud/publicConfig.test.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { afterEach, describe, expect, it, vi } from "vite-plus/test";
22

3-
import { hasCloudPublicConfig } from "./publicConfig.ts";
3+
import {
4+
CloudPublicConfigMissingError,
5+
hasCloudPublicConfig,
6+
resolveRelayClerkTokenOptions,
7+
} from "./publicConfig.ts";
48

59
afterEach(() => {
610
vi.unstubAllEnvs();
@@ -30,4 +34,12 @@ describe("hasCloudPublicConfig", () => {
3034

3135
expect(hasCloudPublicConfig()).toBe(false);
3236
});
37+
38+
it("reports the missing Clerk JWT template as structured configuration", () => {
39+
vi.stubEnv("VITE_CLERK_JWT_TEMPLATE", "");
40+
41+
expect(() => resolveRelayClerkTokenOptions()).toThrowError(
42+
new CloudPublicConfigMissingError({ key: "T3CODE_CLERK_JWT_TEMPLATE" }),
43+
);
44+
});
3345
});

apps/web/src/cloud/publicConfig.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
import { relayClerkTokenOptions } from "@t3tools/shared/relayAuth";
22
import { normalizeSecureRelayUrl } from "@t3tools/shared/relayUrl";
3+
import * as Schema from "effect/Schema";
4+
5+
export class CloudPublicConfigMissingError extends Schema.TaggedErrorClass<CloudPublicConfigMissingError>()(
6+
"CloudPublicConfigMissingError",
7+
{
8+
key: Schema.Literal("T3CODE_CLERK_JWT_TEMPLATE"),
9+
},
10+
) {
11+
override get message(): string {
12+
return `${this.key} is not configured.`;
13+
}
14+
}
315

416
export interface CloudPublicConfig {
517
readonly clerkPublishableKey: string | null;
@@ -65,7 +77,7 @@ export function hasCloudPublicConfig(): boolean {
6577
export function resolveRelayClerkTokenOptions() {
6678
const { clerkJwtTemplate } = resolveCloudPublicConfig();
6779
if (!clerkJwtTemplate) {
68-
throw new Error("T3CODE_CLERK_JWT_TEMPLATE is not configured.");
80+
throw new CloudPublicConfigMissingError({ key: "T3CODE_CLERK_JWT_TEMPLATE" });
6981
}
7082
return relayClerkTokenOptions(clerkJwtTemplate);
7183
}

0 commit comments

Comments
 (0)