export type GetApiAssetObjectHrefArgs = {'If-None-Match'?: string | undefined}; export type GetApiAssetObjectHrefOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Fetch an asset object * * GET /{assetObjectHref} */ export const getApiAssetObjectHref = async (args: GetApiAssetObjectHrefArgs, options?: GetApiAssetObjectHrefOptions) => { const {baseUrl = "http://data.geo.admin.ch/api/stac/v0.9", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args['If-None-Match'] != null) headers.set("If-None-Match", String(args['If-None-Match'])) const url = `${baseUrl.replace(/\/+$/, '')}/${encodeURIComponent(String(args.assetObjectHref))}${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 };