export type GetApiApiGridsArgs = {north?: number | undefined, south?: number | undefined, east?: number | undefined, west?: number | undefined}; export type GetApiApiGridsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Returns the grid squares that a specified area overlaps * * GET /api/grids */ export const getApiApiGrids = async (args: GetApiApiGridsArgs, options: GetApiApiGridsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.north != null) query.append("north", String(args.north)) if (args.south != null) query.append("south", String(args.south)) if (args.east != null) query.append("east", String(args.east)) if (args.west != null) query.append("west", String(args.west)) const url = `${baseUrl.replace(/\/+$/, '')}/api/grids${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 };