export type GetApiReportsScreeningsArgs = {from?: string | undefined, to?: string | undefined, timeZone?: string | undefined, format?: 'csv' | undefined}; export type GetApiReportsScreeningsOptions = {baseUrl: string, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Download a bounded screening CSV with explicit expired outcomes * * GET /reports/screenings */ export const getApiReportsScreenings = async (args: GetApiReportsScreeningsArgs, options: GetApiReportsScreeningsOptions) => { const {baseUrl, fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "text/csv") if (args.from != null) query.append("from", String(args.from)) if (args.to != null) query.append("to", String(args.to)) if (args.timeZone != null) query.append("timeZone", String(args.timeZone)) if (args.format != null) query.append("format", String(args.format)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/reports/screenings${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 res.text() };