export type GetApiV1FacilitiesOptions = {baseUrl: string, https?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; /** * Get all available facilities * * GET /v1/facilities */ export const getApiV1Facilities = async (options: GetApiV1FacilitiesOptions) => { const {baseUrl, fetch: fetchFn = fetch, https} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (https !== undefined) headers.set('authorization', `Basic ${btoa(`${https.username}:${https.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/facilities${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 };