export type GetApiV1LeaderboardsArgs = {page: number, limit: number, type: 'following', duration: number, timeScope: 'all-time' | 'recent-interval'}; export type GetApiV1LeaderboardsOptions = {baseUrl: string, bearer?: string | undefined, fetch?: typeof fetch | undefined}; /** * GET /v1/leaderboards */ export const getApiV1Leaderboards = async (args: GetApiV1LeaderboardsArgs, options: GetApiV1LeaderboardsOptions) => { const {baseUrl, fetch: fetchFn = fetch, bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.page != null) query.append("page", String(args.page)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.type != null) query.append("type", String(args.type)) if (args.duration != null) query.append("duration", String(args.duration)) if (args.timeScope != null) query.append("timeScope", String(args.timeScope)) if (bearer !== undefined) headers.set('authorization', `Bearer ${bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/leaderboards${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 };