import {z} from 'zod' export type GetApiV1IpawsArchivedAlertsArgs = {$filter?: string | undefined, $top?: number | undefined, $skip?: number | undefined, $count?: boolean | undefined, $filename?: string | undefined, $metadata?: boolean | undefined, $gzip?: boolean | undefined, $orderby?: (Array<'id' | 'id desc' | 'identifier' | 'identifier desc' | 'sent' | 'sent desc' | 'sender' | 'sender desc' | 'status' | 'status desc' | 'msgType' | 'msgType desc' | 'source' | 'source desc' | 'scope' | 'scope desc' | 'restriction' | 'restriction desc' | 'addresses' | 'addresses desc' | 'code' | 'code desc' | 'note' | 'note desc' | 'incidents' | 'incidents desc' | 'searchGeometry' | 'searchGeometry desc' | 'infos' | 'infos desc' | 'cogId' | 'cogId desc' | 'xmlns' | 'xmlns desc' | 'originalMessage' | 'originalMessage desc'>) | undefined, $select?: (Array<'id' | 'identifier' | 'sent' | 'sender' | 'status' | 'msgType' | 'source' | 'scope' | 'restriction' | 'addresses' | 'code' | 'note' | 'incidents' | 'searchGeometry' | 'infos' | 'cogId' | 'xmlns' | 'originalMessage'>) | undefined, $format?: ('json' | 'jsonl' | 'jsona') | undefined}; export type GetApiV1IpawsArchivedAlertsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const metadata = z.object({skip: z.number().nullable().optional(), filter: z.string().nullable().optional(), orderBy: z.string().nullable().optional(), select: z.string().nullable().optional(), rundate: z.string().nullable().optional(), top: z.number().nullable().optional(), format: z.string().nullable().optional(), metadata: z.boolean().nullable().optional(), entityname: z.string().optional(), version: z.string().optional(), url: z.string().optional(), count: z.number().nullable().optional()}); export const v1IpawsArchivedAlerts = z.object({id: z.string().optional(), identifier: z.string().optional(), sent: z.string().optional(), sender: z.string().optional(), status: z.string().optional(), msgType: z.string().optional(), source: z.string().nullable().optional(), scope: z.string().optional(), restriction: z.string().nullable().optional(), addresses: z.string().nullable().optional(), code: z.array(z.object({})).nullable().optional(), note: z.string().nullable().optional(), incidents: z.string().nullable().optional(), searchGeometry: z.object({}).nullable().optional(), infos: z.array(z.object({})).nullable().optional(), cogId: z.number().optional(), xmlns: z.string().optional(), originalMessage: z.string().optional()}); export const getApiV1IpawsArchivedAlertsResponse = z.object({metadata: metadata.optional(), IpawsArchivedAlerts: z.array(v1IpawsArchivedAlerts).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 }; /** * IPAWS Archived Alerts * * GET /v1/IpawsArchivedAlerts */ export const getApiV1IpawsArchivedAlerts = async (args: GetApiV1IpawsArchivedAlertsArgs, options?: GetApiV1IpawsArchivedAlertsOptions) => { const {baseUrl = "https://www.fema.gov/api/open", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.$filter != null) query.append("$filter", String(args.$filter)) if (args.$top != null) query.append("$top", String(args.$top)) if (args.$skip != null) query.append("$skip", String(args.$skip)) if (args.$count != null) query.append("$count", String(args.$count)) if (args.$filename != null) query.append("$filename", String(args.$filename)) if (args.$metadata != null) query.append("$metadata", String(args.$metadata)) if (args.$gzip != null) query.append("$gzip", String(args.$gzip)) for (const item of args.$orderby ?? []) query.append("$orderby", String(item)) for (const item of args.$select ?? []) query.append("$select", String(item)) if (args.$format != null) query.append("$format", String(args.$format)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/IpawsArchivedAlerts${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(getApiV1IpawsArchivedAlertsResponse, await res.json()) };