export type GetApiStatsArgs = {token: unknown}; export type GetApiStatsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Site stats * * GET /stats */ export const getApiStats = async (args: GetApiStatsArgs, options: GetApiStatsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.token != null) query.append("token", String(args.token)) const url = `${baseUrl.replace(/\/+$/, '')}/stats${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };