export type GetApiOgcCollectionsArgs = {bbox?: (Array) | undefined, datetime?: string | undefined, f?: string | undefined}; export type GetApiOgcCollectionsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * List the available collections from the service * * GET /ogc/collections */ export const getApiOgcCollections = async (args: GetApiOgcCollectionsArgs, options: GetApiOgcCollectionsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() for (const item of args.bbox ?? []) query.append("bbox", String(item)) if (args.datetime != null) query.append("datetime", String(args.datetime)) if (args.f != null) query.append("f", String(args.f)) const url = `${baseUrl.replace(/\/+$/, '')}/ogc/collections${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 };