feat(resilience): add client RPC service wrapper

Add the browser-side resilience service wrapper using the existing lazy RPC-client pattern so premium auth continues to flow through the runtime fetch patch.

Validation:
- npm run typecheck (fails on existing Dodo/Clerk baseline issues in upstream/main)
- node --import tsx -e "import('./src/services/resilience.ts').then((m) => { console.log(Object.keys(m).sort().join(',')); })"
This commit is contained in:
lspassos1
2026-04-03 22:59:26 +01:00
parent 9b7eb248d8
commit 94e2f545c6

View File

@@ -0,0 +1,38 @@
import {
ResilienceServiceClient,
type GetResilienceRankingResponse,
type GetResilienceScoreResponse,
type ResilienceDomain,
type ResilienceDimension,
type ResilienceRankingItem,
} from '@/generated/client/worldmonitor/resilience/v1/service_client';
import { getRpcBaseUrl } from '@/services/rpc-client';
export type ResilienceScoreResponse = GetResilienceScoreResponse;
export type ResilienceRankingResponse = GetResilienceRankingResponse;
export type { ResilienceDomain, ResilienceDimension, ResilienceRankingItem };
let _client: ResilienceServiceClient | null = null;
function getClient(): ResilienceServiceClient {
if (!_client) {
_client = new ResilienceServiceClient(getRpcBaseUrl(), {
fetch: (...args: Parameters<typeof fetch>) => globalThis.fetch(...args),
});
}
return _client;
}
function normalizeCountryCode(countryCode: string): string {
return countryCode.trim().toUpperCase();
}
export async function getResilienceScore(countryCode: string): Promise<ResilienceScoreResponse> {
return getClient().getResilienceScore({
countryCode: normalizeCountryCode(countryCode),
});
}
export async function getResilienceRanking(): Promise<ResilienceRankingResponse> {
return getClient().getResilienceRanking({});
}