import {z} from 'zod' export type GetApiPeopleIdArgs = {id: string}; export type GetApiPeopleIdOptions = {baseUrl?: string | undefined, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const v1Gender = z.enum(["M", "F"]); export const v1MaritalStatus = z.enum(["married", "single", "divorced", "widowed", "separated", "domestic_partner", "civil_union", "other"]); export const v1CourtStateAbbreviation = z.enum(["US", "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", "CN", "VI", "AE", "AA", "AP", "MX"]); export const v1BankruptcyType = z.enum(["Chapter 7", "Chapter 11", "Chapter 12", "Chapter 13", "Chapter 15"]); export const v1DocketParty = z.object({id: z.string(), name: z.string(), party_type: z.string().nullable().optional(), counsel: z.array(z.string()).optional()}); export const v1DocketExhibit = z.object({id: z.string(), title: z.string(), is_available: z.boolean().optional(), document_url: z.string().nullable()}); export const v1DocketUpdate = z.object({id: z.string(), title: z.string().nullable().optional(), contents: z.string().nullable().optional(), date: z.string().nullable().optional(), exhibits: z.array(v1DocketExhibit).optional()}); export const v1MatchType = z.enum(["NO_MATCH", "SIMILAR", "EXACT"]); export const v1BusinessOrPersonType = z.enum(["Business", "Person"]); export const v1RiskLevel = z.enum(["high", "medium", "low", "no_risk"]); export const v1NormalizedDocketStatus = z.enum(["open", "closed"]); export const v1DocketResponse = z.object({id: z.string(), docket_number: z.string(), court: z.string(), state: v1CourtStateAbbreviation.nullable().optional(), division: z.string().nullable().optional(), judges: z.array(z.string()).optional(), title: z.string(), case_type: z.string().nullable().optional(), status: z.string().nullable().optional(), is_bankruptcy: z.boolean(), bankruptcy_type: v1BankruptcyType.nullable().optional(), date_filed: z.string().optional(), last_synced_at: z.string().nullable().optional(), parties: z.array(v1DocketParty).optional(), updates: z.array(v1DocketUpdate).optional(), match_level: v1MatchType.nullable().optional(), search_entity_name: z.string().nullable().optional(), search_entity_type: v1BusinessOrPersonType.nullable().optional(), risk_level: v1RiskLevel.nullable().optional(), normalized_status: v1NormalizedDocketStatus.nullable().optional()}); 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 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 v1WatchlistDataSource = z.enum(["Death Master File", "Department of Treasury, Office of Foreign Assets Control", "Politically Exposed Persons", "IRS Exempt Organizations List", "FBI Wanted List", "Department of Commerce, Consolidated Screening List", "Consolidated Canadian Autonomous Sanctions List", "HHS OIG List of Excluded Individuals/Entities", "Baselayer Fraud Consortium"]); export const v1WatchlistHitResponse = z.object({code: z.string(), name: v1WatchlistDataSource, count: z.number().int(), details: z.array(z.record(z.string(), z.unknown())).nullable().optional()}); export const v1PersonResponse = z.object({id: z.string(), first_name: z.string(), last_name: z.string(), ssn: z.string(), middle_name: z.string().nullable().optional(), phone_number: z.string().nullable().optional(), email: z.string().nullable().optional(), date_of_birth: z.string().nullable().optional(), gender: v1Gender.nullable().optional(), marital_status: v1MaritalStatus.nullable().optional(), suffix: z.string().nullable().optional(), title: z.string().nullable().optional(), created_at: z.string(), updated_at: z.string().nullable().optional(), dockets: z.array(v1DocketResponse).optional(), liens: z.array(v1LienFilingResponse).optional(), watchlist_hits: z.array(v1WatchlistHitResponse).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 Person * * GET /people/{id} */ export const getApiPeopleId = async (args: GetApiPeopleIdArgs, options?: GetApiPeopleIdOptions) => { 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(/\/+$/, '')}/people/${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(v1PersonResponse, await res.json()) };