import {z} from 'zod' export type StateAbbreviation = 'AL' | 'AK' | 'AZ' | 'AR' | 'CA' | 'CO' | 'CT' | 'DE' | 'DC' | 'FL' | 'GA' | 'HI' | 'ID' | 'IL' | 'IN' | 'IA' | 'KS' | 'KY' | 'LA' | 'ME' | 'MD' | 'MA' | 'MI' | 'MN' | 'MS' | 'MO' | 'MT' | 'NE' | 'NV' | 'NH' | 'NJ' | 'NM' | 'NY' | 'NC' | 'ND' | 'OH' | 'OK' | 'OR' | 'PA' | 'RI' | 'SC' | 'SD' | 'TN' | 'TX' | 'UT' | 'VT' | 'VA' | 'WA' | 'WV' | 'WI' | 'WY' | 'PR' | 'VI' | 'AE' | 'AA' | 'AP' | 'GU' | 'AS'; export type V1BusinessLiensSearchRequest = {type?: 'Business' | undefined, business_id: string, search_states?: (Array | null) | undefined}; export type V1PersonLiensSearchRequest = {type?: 'Person' | undefined, person_id: string, search_states: Array}; export type BusinessOrPersonType = 'Business' | 'Person'; export type V1AdditionalLiensSearchEntityRequest = {name: string, type: BusinessOrPersonType, search_states: Array}; export type V1BusinessSearchLiensSearchRequest = {type?: 'BusinessSearch' | undefined, business_search_id: string, search_states?: (Array | null) | undefined, additional_search_entities?: (Array | null) | undefined}; export type CreateApiLienSearchesArgs = {Prefer?: (string | null) | undefined, body: V1BusinessLiensSearchRequest | V1PersonLiensSearchRequest | V1BusinessSearchLiensSearchRequest}; export type CreateApiLienSearchesOptions = {baseUrl?: string | undefined, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const v1BusinessOrPersonType = z.enum(["Business", "Person"]); export const v1StateAbbreviation = z.enum(["AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE", "DC", "FL", "GA", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VA", "WA", "WV", "WI", "WY", "PR", "VI", "AE", "AA", "AP", "GU", "AS"]); export const v1AdditionalLiensSearchEntityResponse = z.object({name: z.string().min(1).max(256), type: v1BusinessOrPersonType, search_states: z.array(v1StateAbbreviation), normalized_name: z.string()}); export const v1TaskState = z.enum(["PENDING", "EXECUTING", "COMPLETED", "FAILED", "CANCELLED"]); export const v1LienPartyRole = z.enum(["Debtor", "Secured Party", "Record Owner"]); export const v1AddressRDI = z.enum(["Residential", "Commercial"]); export const v1USPSDeliveryType = z.enum(["FIRM", "GENERAL_DELIVERY", "HIGH_RISE", "POST_OFFICE", "RURAL_ROUTE", "STREET"]); export const v1AddressSummaryResponse = z.object({id: z.string(), street: z.string(), city: z.string(), state: v1StateAbbreviation, zip: z.string(), latitude: z.number(), longitude: z.number(), rdi: v1AddressRDI.nullable().optional(), deliverable: z.boolean().nullable().optional(), cmra: z.boolean().nullable().optional(), url: z.string().min(1).max(2083).nullable().optional(), delivery_type: v1USPSDeliveryType.nullable().optional()}); export const v1LienPartyResponse = z.object({id: z.string(), role: v1LienPartyRole, name: z.string(), address: v1AddressSummaryResponse.nullable(), type: z.string()}); export const v1LienAmendmentResponse = z.object({filing_number: z.string(), filing_type: z.string(), filing_date: z.string(), number_of_pages: z.number().int()}); export const v1LienCollateralStatementResponse = z.object({text: z.string(), sort_order: z.number().int()}); export const v1MatchType = z.enum(["NO_MATCH", "SIMILAR", "EXACT"]); export const v1LienFilingResponse = z.object({id: z.string(), state: v1StateAbbreviation, filing_number: z.string(), filing_type: z.string(), filing_date: z.string(), lapse_date: z.string(), status: z.string(), number_of_pages: z.number().int(), document_filename: z.string().nullable().optional(), parties: z.array(v1LienPartyResponse).optional(), amendments: z.array(v1LienAmendmentResponse).optional(), collateral_statements: z.array(v1LienCollateralStatementResponse).optional(), last_updated_at: z.string(), match_level: v1MatchType.nullable().optional(), search_entity_name: z.string().nullable().optional(), search_entity_type: v1BusinessOrPersonType.nullable().optional()}); export const v1LiensSearchResponse = z.object({id: z.string(), search_entities: z.array(v1AdditionalLiensSearchEntityResponse), state: v1TaskState, error: z.string().nullable().optional(), filings: z.array(v1LienFilingResponse), last_updated_at: z.string(), searched_states: z.array(v1StateAbbreviation).nullable().optional(), business_id: z.string().nullable().optional(), person_id: z.string().nullable().optional(), business_search_id: z.string().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 }; /** * Start Liens Search * * POST /lien_searches */ export const createApiLienSearches = async (args: CreateApiLienSearchesArgs, options?: CreateApiLienSearchesOptions) => { const {baseUrl = "https://api.baselayer.com", fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.Prefer != null) headers.set("Prefer", String(args.Prefer)) if (APIKeyHeader !== undefined) headers.set("X-API-Key", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/lien_searches${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(v1LiensSearchResponse, await res.json()) };