import {z} from 'zod' export type GetApiPipelinesIdArgs = {id: string}; export type GetApiPipelinesIdOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const supportedGeojsonGeometry2 = z.object({type: z.literal("Polygon"), coordinates: z.array(z.array(z.array(z.unknown())))}); export const pipelineResource = z.object({id: z.string().min(1), name: z.string().optional(), start_date: z.string(), end_date: z.string(), budget_per_km2: z.number().gte(0).optional(), max_cost: z.number().gte(0).optional(), resolution_low: z.number().gte(0.3).lte(30), resolution_high: z.number().gte(0.3).lte(30), cloud_cover_percentage: z.number().gte(0).lte(100), min_aoi_coverage_percentage: z.number().gte(0).lte(100).optional(), interval: z.string(), result_delivery: z.union([z.literal("first_available"), z.object({max_latency: z.string().optional(), priorities: z.array(z.enum(["lowest_cost", "highest_resolution", "latest", "midpoint", "earliest"])).optional()}), z.object({max_latency: z.string().optional(), priorities: z.array(z.literal("first_available")).optional()})]), aoi: supportedGeojsonGeometry2.optional(), area_km2: z.number().gt(0).optional(), output: z.object({id: z.string().min(1), format: z.literal("geotiff"), mosaic: z.union([z.enum(["stitched", "off"]), z.object({type: z.literal("stitched"), range: z.string().optional()})])}), tags: z.array(z.object({label: z.string().min(1), value: z.string().min(1)})).optional(), status: z.enum(["active", "inactive", "complete", "failed", "deactivating", "pending"]), status_reason: z.object({reason: z.enum(["results", "no_results", "some_results", "failed"]), description: z.string().min(1).optional()}).optional(), search_id: z.string().optional(), search_results: z.union([z.array(z.string()), z.string()]).optional(), sources: z.union([z.object({include: z.array(z.enum(["Kompsat-2", "Kompsat-3", "Kompsat-3A", "PlanetScope", "Sentinel-1", "Sentinel-2", "SkySat", "TripleSat", "Pleiades", "Spot", "PlanetScope-SuperDove", "Pleiades-Neo", "Pleiades-Neo-HD15", "USKY01", "NewSat-70cm", "Capella-SLC", "RCM", "Beijing-3N", "Beijing-3A"]))}), z.object({exclude: z.array(z.enum(["Kompsat-2", "Kompsat-3", "Kompsat-3A", "PlanetScope", "Sentinel-1", "Sentinel-2", "SkySat", "TripleSat", "Pleiades", "Spot", "PlanetScope-SuperDove", "Pleiades-Neo", "Pleiades-Neo-HD15", "USKY01", "NewSat-70cm", "Capella-SLC", "RCM", "Beijing-3N", "Beijing-3A"]))})]).optional(), created_at: z.string(), updated_at: z.string(), off_nadir_angle: z.array(z.number().gte(-90).lte(90)).optional()}); export const schema2xxResponse = z.object({data: pipelineResource, links: z.array(z.object({uri: z.string()})).optional(), errors: z.array(z.object({message: z.string().min(1).max(512)})).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 Order Details * * GET /pipelines/{id} */ export const getApiPipelinesId = async (args: GetApiPipelinesIdArgs, options?: GetApiPipelinesIdOptions) => { 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(/\/+$/, '')}/pipelines/${encodeURIComponent(String(args.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(schema2xxResponse, await res.json()) };