SPB Git forge

spb/countryatlas

Public
20commits 1branches 0releases
268.3 MBsize
maindefault branch
12 days agolast push
TypeScript 57% Python 38.6% JavaScript 3.6% CSS 0.6%
2.2 KB · 48 lines typescript
Raw Blame History
1import 'server-only';2import { request } from './api';3import type { MultiSeriesResponse } from './types';4import type {5  ChangesFeedResponse,6  IndicatorResponse,7  IndicatorsResponse,8  MethodologyResponse,9  RegionResponse,10  RegionsResponse,11  SourceResponse,12  SourcesResponse,13  TrendResponse,14} from './types-explore';1516/**17 * Server-side endpoints for the indicators / regions / explore / changes / sources / methodology pages.18 * Same conventions as `lib/api.ts` (`request<T>` → ApiError, ISR 900 s). Kept in its own file because two19 * agents extend the API surface concurrently.20 */21export const apiExplore = {22  indicators: (q: { topic?: string; q?: string; featured?: boolean; source?: string; with_data?: boolean } = {}) => request<IndicatorsResponse>('/indicators', q),2324  indicator: (slug: string) => request<IndicatorResponse>(`/indicators/${encodeURIComponent(slug)}`),2526  indicatorTrend: (slug: string, group = 'world', q: { from?: number; to?: number; min_n?: number } = {}) =>27    request<TrendResponse>(`/indicators/${encodeURIComponent(slug)}/trend`, { group, ...q }),2829  /** `/series?country=A,B&indicator=x,y` bundle (max 20 countries × 12 indicators). */30  seriesBundle: (countries: string[], indicators: string[], q: { from?: number; to?: number; include_forecast?: boolean } = {}) =>31    request<MultiSeriesResponse>('/series', { country: countries.join(','), indicator: indicators.join(','), ...q }),3233  regions: (kind?: string) => request<RegionsResponse>('/regions', { kind }),3435  region: (slug: string, q: { indicator?: string; sort?: 'asc' | 'desc' } = {}) => request<RegionResponse>(`/regions/${encodeURIComponent(slug)}`, q),3637  changes: (q: { limit?: number; offset?: number; kind?: string; indicator?: string; country?: string; topic?: string; min_severity?: number } = {}) =>38    request<ChangesFeedResponse>('/changes', q),3940  sources: () => request<SourcesResponse>('/sources'),4142  source: (id: string, runsLimit = 30) => request<SourceResponse>(`/sources/${encodeURIComponent(id)}`, { runs_limit: runsLimit }),4344  methodology: () => request<MethodologyResponse>('/methodology', undefined, { revalidate: 3600 }),45};4647export type ApiExplore = typeof apiExplore;48