export type GetApiBagSubstitutionRulesDateCsvArgs = {date: string}; export type GetApiBagSubstitutionRulesDateCsvOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * GET /bag-substitution-rules/{date}.csv */ export const getApiBagSubstitutionRulesDateCsv = async (args: GetApiBagSubstitutionRulesDateCsvArgs, options: GetApiBagSubstitutionRulesDateCsvOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "text/csv") const url = `${baseUrl.replace(/\/+$/, '')}/bag-substitution-rules/${encodeURIComponent(String(args.date))}.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() };