export type GetApiIcsExportUrlArgs = {rental_id: number}; export type GetApiIcsExportUrlOptions = {baseUrl: string, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; /** * Returns URL to the .ics file download link. * * GET /ics/export-url * * Also accepts auth: API-Key */ export const getApiIcsExportUrl = async (args: GetApiIcsExportUrlArgs, options: GetApiIcsExportUrlOptions) => { const {baseUrl, fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.rental_id != null) query.append("rental_id", String(args.rental_id)) if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/ics/export-url${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 };