export type GetApiAppReportingArgs = {projectId?: number | undefined, periodDays?: (7 | 30 | 60 | 90) | undefined, refresh?: boolean | undefined}; export type GetApiAppReportingOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Read the prepared global reporting snapshot from Postgres * * GET /app/reporting */ export const getApiAppReporting = async (args: GetApiAppReportingArgs, options: GetApiAppReportingOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.projectId != null) query.append("projectId", String(args.projectId)) if (args.periodDays != null) query.append("periodDays", String(args.periodDays)) if (args.refresh != null) query.append("refresh", String(args.refresh)) const url = `${baseUrl.replace(/\/+$/, '')}/app/reporting${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 };