export type GetApiRegionsArgs = {Authorization: string}; export type GetApiRegionsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Get all regions of all countries * * GET /regions */ export const getApiRegions = async (args: GetApiRegionsArgs, options?: GetApiRegionsOptions) => { const {baseUrl = "http://127.0.0.1:8443", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) const url = `${baseUrl.replace(/\/+$/, '')}/regions${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 };