export type GetApiReportingInsightsDownloadArgs = {snapshotDate?: string | undefined, format?: string | undefined}; export type GetApiReportingInsightsDownloadOptions = {baseUrl: string, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; /** * Reporting insights download * * GET /reporting/insights/download * * Also accepts auth: jwtAuth, oauth2, oauth2 */ export const getApiReportingInsightsDownload = async (args: GetApiReportingInsightsDownloadArgs, options: GetApiReportingInsightsDownloadOptions) => { const {baseUrl, fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "*/*") if (args.snapshotDate != null) query.append("snapshotDate", String(args.snapshotDate)) if (args.format != null) query.append("format", String(args.format)) if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/reporting/insights/download${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.blob() };