import {z} from 'zod' export type GetApiLienSearchesAdhocLiensSearchRequestIdArgs = {liens_search_request_id: string}; export type GetApiLienSearchesAdhocLiensSearchRequestIdOptions = {baseUrl?: string | undefined, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const v1TaskState = z.enum(["PENDING", "EXECUTING", "COMPLETED", "FAILED", "CANCELLED"]); 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 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 v1BusinessOrPersonType = z.enum(["Business", "Person"]); 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 v1AdhocLiensSearchResponse = z.object({id: z.string(), name: z.string(), state: v1TaskState, error: z.string().nullable().optional(), filings: z.array(v1LienFilingResponse), last_updated_at: z.string(), searched_states: z.array(v1StateAbbreviation)}); 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 Adhoc Liens * * GET /lien_searches/adhoc/{liens_search_request_id} */ export const getApiLienSearchesAdhocLiensSearchRequestId = async (args: GetApiLienSearchesAdhocLiensSearchRequestIdArgs, options?: GetApiLienSearchesAdhocLiensSearchRequestIdOptions) => { const {baseUrl = "https://api.baselayer.com", fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (APIKeyHeader !== undefined) headers.set("X-API-Key", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/lien_searches/adhoc/${encodeURIComponent(String(args.liens_search_request_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(v1AdhocLiensSearchResponse, await res.json()) };