import {z} from 'zod' export type GetApiV1HmaSubapplicationsProjectSiteInventoriesArgs = {$filter?: string | undefined, $top?: number | undefined, $skip?: number | undefined, $count?: boolean | undefined, $filename?: string | undefined, $metadata?: boolean | undefined, $gzip?: boolean | undefined, $orderby?: (Array<'subapplicationId' | 'subapplicationId desc' | 'projectSiteInventoryId' | 'projectSiteInventoryId desc' | 'projectSiteInventoryType' | 'projectSiteInventoryType desc' | 'primaryActivity' | 'primaryActivity desc' | 'secondaryActivity' | 'secondaryActivity desc' | 'primaryHazard' | 'primaryHazard desc' | 'secondaryHazard' | 'secondaryHazard desc' | 'city' | 'city desc' | 'countyCode' | 'countyCode desc' | 'county' | 'county desc' | 'stateCode' | 'stateCode desc' | 'stateAbbreviation' | 'stateAbbreviation desc' | 'zipcode' | 'zipcode desc' | 'structureType' | 'structureType desc' | 'structurePrimarySubtype' | 'structurePrimarySubtype desc' | 'structureSecondarySubtype' | 'structureSecondarySubtype desc' | 'foundationType' | 'foundationType desc' | 'buildingSize' | 'buildingSize desc' | 'lotSize' | 'lotSize desc' | 'yearBuilt' | 'yearBuilt desc' | 'firstFloorElevation' | 'firstFloorElevation desc' | 'feetAboveBaseFloodElevation' | 'feetAboveBaseFloodElevation desc' | 'baseFloodElevation' | 'baseFloodElevation desc' | 'floodZone' | 'floodZone desc' | 'estimatedPurchasePrice' | 'estimatedPurchasePrice desc' | 'proposedLandUse' | 'proposedLandUse desc' | 'currentlyRented' | 'currentlyRented desc' | 'criticalFacility' | 'criticalFacility desc' | 'alternateStructure' | 'alternateStructure desc' | 'substantiallyDamaged' | 'substantiallyDamaged desc' | 'publiclyOwned' | 'publiclyOwned desc' | 'insured' | 'insured desc' | 'insuranceType' | 'insuranceType desc' | 'repetitiveLossStructure' | 'repetitiveLossStructure desc' | 'severeRepetitiveLossStructure' | 'severeRepetitiveLossStructure desc' | 'costEffectivenessMethod' | 'costEffectivenessMethod desc' | 'preCalculatedBenefit' | 'preCalculatedBenefit desc' | 'benefitCostRatio' | 'benefitCostRatio desc' | 'ownerType' | 'ownerType desc' | 'coownerType' | 'coownerType desc' | 'id' | 'id desc'>) | undefined, $select?: (Array<'subapplicationId' | 'projectSiteInventoryId' | 'projectSiteInventoryType' | 'primaryActivity' | 'secondaryActivity' | 'primaryHazard' | 'secondaryHazard' | 'city' | 'countyCode' | 'county' | 'stateCode' | 'stateAbbreviation' | 'zipcode' | 'structureType' | 'structurePrimarySubtype' | 'structureSecondarySubtype' | 'foundationType' | 'buildingSize' | 'lotSize' | 'yearBuilt' | 'firstFloorElevation' | 'feetAboveBaseFloodElevation' | 'baseFloodElevation' | 'floodZone' | 'estimatedPurchasePrice' | 'proposedLandUse' | 'currentlyRented' | 'criticalFacility' | 'alternateStructure' | 'substantiallyDamaged' | 'publiclyOwned' | 'insured' | 'insuranceType' | 'repetitiveLossStructure' | 'severeRepetitiveLossStructure' | 'costEffectivenessMethod' | 'preCalculatedBenefit' | 'benefitCostRatio' | 'ownerType' | 'coownerType' | 'id'>) | undefined, $format?: ('json' | 'jsona' | 'csv' | 'jsonl' | 'parquet') | undefined}; export type GetApiV1HmaSubapplicationsProjectSiteInventoriesOptions = {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 v1HmaSubapplicationsProjectSiteInventories = z.object({subapplicationId: z.string().optional(), projectSiteInventoryId: z.number().optional(), projectSiteInventoryType: z.string().optional(), primaryActivity: z.string().nullable().optional(), secondaryActivity: z.string().nullable().optional(), primaryHazard: z.string().nullable().optional(), secondaryHazard: z.string().nullable().optional(), city: z.string().nullable().optional(), countyCode: z.string().nullable().optional(), county: z.string().nullable().optional(), stateCode: z.string().nullable().optional(), stateAbbreviation: z.string().nullable().optional(), zipcode: z.string().nullable().optional(), structureType: z.string().nullable().optional(), structurePrimarySubtype: z.string().nullable().optional(), structureSecondarySubtype: z.string().nullable().optional(), foundationType: z.string().nullable().optional(), buildingSize: z.number().nullable().optional(), lotSize: z.number().nullable().optional(), yearBuilt: z.number().nullable().optional(), firstFloorElevation: z.number().nullable().optional(), feetAboveBaseFloodElevation: z.number().nullable().optional(), baseFloodElevation: z.number().nullable().optional(), floodZone: z.string().nullable().optional(), estimatedPurchasePrice: z.number().nullable().optional(), proposedLandUse: z.string().nullable().optional(), currentlyRented: z.boolean().nullable().optional(), criticalFacility: z.boolean().nullable().optional(), alternateStructure: z.boolean().nullable().optional(), substantiallyDamaged: z.boolean().nullable().optional(), publiclyOwned: z.boolean().nullable().optional(), insured: z.boolean().nullable().optional(), insuranceType: z.string().nullable().optional(), repetitiveLossStructure: z.boolean().nullable().optional(), severeRepetitiveLossStructure: z.boolean().nullable().optional(), costEffectivenessMethod: z.string().nullable().optional(), preCalculatedBenefit: z.string().nullable().optional(), benefitCostRatio: z.number().nullable().optional(), ownerType: z.string().nullable().optional(), coownerType: z.string().nullable().optional(), id: z.string().optional()}); export const getApiV1HmaSubapplicationsProjectSiteInventoriesResponse = z.object({metadata: metadata.optional(), HmaSubapplicationsProjectSiteInventories: z.array(v1HmaSubapplicationsProjectSiteInventories).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 }; /** * HMA Subapplications Project Site Inventories * * GET /v1/HmaSubapplicationsProjectSiteInventories */ export const getApiV1HmaSubapplicationsProjectSiteInventories = async (args: GetApiV1HmaSubapplicationsProjectSiteInventoriesArgs, options?: GetApiV1HmaSubapplicationsProjectSiteInventoriesOptions) => { 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/HmaSubapplicationsProjectSiteInventories${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(getApiV1HmaSubapplicationsProjectSiteInventoriesResponse, await res.json()) };