export type GetApiV1SettingsArgs = {facility?: Array | undefined, name: string}; export type GetApiV1SettingsOptions = {baseUrl: string, https?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; /** * Get one key / value pair from the settings table * * GET /v1/settings */ export const getApiV1Settings = async (args: GetApiV1SettingsArgs, options: GetApiV1SettingsOptions) => { const {baseUrl, fetch: fetchFn = fetch, https} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.facility != null) query.append("facility", args.facility.join(',')) if (args.name != null) query.append("name", String(args.name)) if (https !== undefined) headers.set('authorization', `Basic ${btoa(`${https.username}:${https.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/settings${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 };