export type GetApiRestV1CreCsvOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Download CRE catalogue CSV * * GET /rest/v1/cre_csv */ export const getApiRestV1CreCsv = async (options: GetApiRestV1CreCsvOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "text/csv") const url = `${baseUrl.replace(/\/+$/, '')}/rest/v1/cre_csv${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() };