export type GetApiV1VersionsArgs = {facility?: Array | undefined}; export type GetApiV1VersionsOptions = {baseUrl: string, https?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; /** * Get the last run version from the settings table * * GET /v1/versions */ export const getApiV1Versions = async (args: GetApiV1VersionsArgs, options: GetApiV1VersionsOptions) => { 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 (https !== undefined) headers.set('authorization', `Basic ${btoa(`${https.username}:${https.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/versions${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 };