import {z} from 'zod' export type V1MiddleNameParse = 'None' | 'Share' | 'ShareMerge' | 'AppendMiddleInitial' | 'AppendMiddleInitialAll'; export type V1IncludeSuffix = 'None' | 'OriginalOnly' | 'All'; export type V1SuppressHyphenParse = 'Never' | 'MultipleOnly' | 'Always'; export type V1ParseModel = 'NameSegmentParse' | 'None'; export type V1ParsePermutateOptions = {keep_original?: (boolean | null) | undefined, first_name_remove_list?: (string | null) | undefined, last_name_remove_list?: (string | null) | undefined, middle_name_parse?: (V1MiddleNameParse | null) | undefined, force_hyphen?: (boolean | null) | undefined, include_suffix?: (V1IncludeSuffix | null) | undefined, parse_prefix?: (boolean | null) | undefined, parse_suffix?: (boolean | null) | undefined, max_permutation_count?: (number | null) | undefined, merge_name_parts?: (boolean | null) | undefined, mixed_case_split?: (boolean | null) | undefined, suppress_hyphen_parse?: (V1SuppressHyphenParse | null) | undefined, toggle_middle_name?: (boolean | null) | undefined, toggle_primary_name?: (boolean | null) | undefined, transpose?: (boolean | null) | undefined, validate_permutation_count?: (boolean | null) | undefined, remove_nobiliary_participle?: (boolean | null) | undefined, parse_model?: (V1ParseModel | null) | undefined}; export type V1MLASearchRequest = {parse_permutate_options?: (V1ParsePermutateOptions | null) | undefined, certificate?: boolean | undefined, reference_id?: (string | null) | undefined, first_name: string, last_name: string, middle_name?: (string | null) | undefined, birth_date: string, ssn: string, itin?: (string | null) | undefined}; export type CreateApiMlaSearchesArgs = {body: V1MLASearchRequest}; export type CreateApiMlaSearchesOptions = {baseUrl?: string | undefined, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const v1PnIdTypeCode = z.enum(["S", "I"]); export const v1MLAResponsePerson = z.object({pn_id: z.string().nullable().optional(), pn_id_confirmation: z.string().nullable().optional(), first_name: z.string().nullable().optional(), last_name: z.string().nullable().optional(), middle_name: z.string().nullable().optional(), date_of_birth: z.string().nullable().optional(), pn_id_type_code: v1PnIdTypeCode.nullable().optional()}); export const v1MLAResponseEligibility = z.object({covered: z.boolean(), transaction_id: z.string().nullable().optional(), content: z.string().nullable().optional(), certificate_type: z.string().nullable().optional()}); export const v1MLAResponseResult = z.object({id: z.string().nullable().optional(), person_request: v1MLAResponsePerson, eligibility: v1MLAResponseEligibility}); export const v1MLAResponse = z.object({reference_id: z.string().nullable().optional(), covered: z.boolean(), results: z.array(v1MLAResponseResult).nullable().optional(), created_at: z.string()}); 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 }; /** * Mla Search * * POST /mla/searches */ export const createApiMlaSearches = async (args: CreateApiMlaSearchesArgs, options?: CreateApiMlaSearchesOptions) => { 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 (APIKeyHeader !== undefined) headers.set("X-API-Key", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/mla/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(v1MLAResponse, await res.json()) };