mirror of
https://github.com/koala73/worldmonitor.git
synced 2026-04-25 17:14:57 +02:00
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:
38
src/services/resilience.ts
Normal file
38
src/services/resilience.ts
Normal 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({});
|
||||
}
|
||||
Reference in New Issue
Block a user