import {z} from 'zod' export type GetApiTilesCogPointLonLatArgs = {lon: number, lat: number, data_path?: (string | null) | undefined, carbon_pool?: (string | null) | undefined, product_type?: (string | null) | undefined, product_variant?: (string | null) | undefined, resolution?: (number | null) | undefined, year?: (number | null) | undefined, analysis_completed_at?: (string | null) | undefined, url?: (string | null) | undefined, coord_crs?: (string | null) | undefined, bidx?: (Array | null) | undefined, expression?: (string | null) | undefined, nodata?: (number | number | string | null) | undefined, unscale?: (boolean | null) | undefined, resampling?: ('nearest' | 'bilinear' | 'cubic' | 'cubic_spline' | 'lanczos' | 'average' | 'mode' | 'gauss' | 'rms' | null) | undefined, reproject?: ('nearest' | 'bilinear' | 'cubic' | 'cubic_spline' | 'lanczos' | 'average' | 'mode' | 'sum' | 'rms' | null) | undefined}; export type GetApiTilesCogPointLonLatOptions = {baseUrl: string, APIKeyQuery?: string | undefined, fetch?: typeof fetch | undefined}; export const titilerCoreModelsResponsesPoint = z.object({coordinates: z.array(z.number()), values: z.array(z.number().nullable()), band_names: z.array(z.string())}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Point * * GET /tiles/cog/point/{lon},{lat} */ export const getApiTilesCogPointLonLat = async (args: GetApiTilesCogPointLonLatArgs, options: GetApiTilesCogPointLonLatOptions) => { const {baseUrl, fetch: fetchFn = fetch, APIKeyQuery} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.data_path != null) query.append("data_path", String(args.data_path)) if (args.carbon_pool != null) query.append("carbon_pool", String(args.carbon_pool)) if (args.product_type != null) query.append("product_type", String(args.product_type)) if (args.product_variant != null) query.append("product_variant", String(args.product_variant)) if (args.resolution != null) query.append("resolution", String(args.resolution)) if (args.year != null) query.append("year", String(args.year)) if (args.analysis_completed_at != null) query.append("analysis_completed_at", String(args.analysis_completed_at)) if (args.url != null) query.append("url", String(args.url)) if (args.coord_crs != null) query.append("coord_crs", String(args.coord_crs)) for (const item of args.bidx ?? []) query.append("bidx", String(item)) if (args.expression != null) query.append("expression", String(args.expression)) if (args.nodata != null) query.append("nodata", String(args.nodata)) if (args.unscale != null) query.append("unscale", String(args.unscale)) if (args.resampling != null) query.append("resampling", String(args.resampling)) if (args.reproject != null) query.append("reproject", String(args.reproject)) if (APIKeyQuery !== undefined) query.set("access_token", APIKeyQuery) const url = `${baseUrl.replace(/\/+$/, '')}/tiles/cog/point/${encodeURIComponent(String(args.lon))},${encodeURIComponent(String(args.lat))}${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 validateResponse(titilerCoreModelsResponsesPoint, await res.json()) };