import {z} from 'zod' export type GetApiEarthcacheAoiMonitorsMonitorIdResultsResultIdArgs = {monitor_id: string, result_id: string}; export type GetApiEarthcacheAoiMonitorsMonitorIdResultsResultIdOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const aOIMonitorLocation = z.object({type: z.literal("Polygon"), coordinates: z.array(z.array(z.array(z.number()))), bbox: z.array(z.number()).optional()}); export const aOIMonitorResult = z.object({id: z.string(), monitor_id: z.string(), location: aOIMonitorLocation, intersection: aOIMonitorLocation, source: z.string(), product_name: z.string(), resolution: z.number(), start_time: z.string(), end_time: z.string(), preview_uri: z.string(), thumbnail_uri: z.string(), location_coverage_percentage: z.number().gte(0).lte(100), area_sq_km: z.number(), price_per_sq_km: z.number().nullable().optional(), minimum_area_sq_km: z.number().nullable().optional(), cost: z.number().nullable().optional(), result_cloud_cover_percentage: z.number().gte(0).lte(100), sensor_type: z.string(), off_nadir_angle: z.number().nullable().optional(), product: z.object({}).nullable().optional(), properties: z.object({}).nullable().optional()}); 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 }; /** * Get AOI Monitor Result * * GET /earthcache/aoi-monitors/{monitor_id}/results/{result_id} */ export const getApiEarthcacheAoiMonitorsMonitorIdResultsResultId = async (args: GetApiEarthcacheAoiMonitorsMonitorIdResultsResultIdArgs, options?: GetApiEarthcacheAoiMonitorsMonitorIdResultsResultIdOptions) => { const {baseUrl = "https://api.skywatch.co/earthcache", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (ApiKey !== undefined) headers.set("x-api-key", ApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/earthcache/aoi-monitors/${encodeURIComponent(String(args.monitor_id))}/results/${encodeURIComponent(String(args.result_id))}${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(aOIMonitorResult, await res.json()) };