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 V1SCRASearchRequest = {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 | null) | undefined, ssn: string, date_of_interest?: string | undefined}; export type CreateApiScraSearchesArgs = {body: V1SCRASearchRequest}; export type CreateApiScraSearchesOptions = {baseUrl?: string | undefined, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const v1SCRAResponsePerson = 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(), active_duty_date: z.string().nullable().optional(), cadency_name: z.string().nullable().optional(), batch_id: z.string().nullable().optional()}); export const v1DepartmentOfDefensePositionCode = z.enum(["AG", "AJ", "AR", "AV", "AZ", "CJ", "CR", "CV", "CZ", "FG", "FJ", "FR", "FV", "HR", "MR", "MV", "MZ", "NJ", "NR", "NV", "OR", "SR", "SV", "ZZ"]); export const v1SCRAResponseEligibility = z.object({covered: z.boolean(), transaction_id: z.string().nullable().optional(), content: z.string().nullable().optional(), date_of_interest: z.string().nullable().optional(), active_duty_covered: z.boolean(), active_duty_start_date: z.string().nullable().optional(), active_duty_end_date: z.string().nullable().optional(), active_duty_service_component_code: v1DepartmentOfDefensePositionCode.nullable().optional(), active_duty_service_component_string: z.string().nullable().optional(), early_indication_covered: z.boolean(), early_indication_start_date: z.string().nullable().optional(), early_indication_end_date: z.string().nullable().optional(), early_indication_service_component_code: v1DepartmentOfDefensePositionCode.nullable().optional(), early_indication_service_component_string: z.string().nullable().optional(), hera_covered: z.boolean(), hera_start_date: z.string().nullable().optional(), hera_end_date: z.string().nullable().optional(), hera_service_component_code: z.string().nullable().optional(), hera_service_component_string: z.string().nullable().optional(), active_duty_indicator_code: z.string().nullable().optional(), match_reason_code: z.string().nullable().optional(), scra_eligibility_type: z.string().nullable().optional()}); export const v1SCRAResponseResult = z.object({id: z.string().nullable().optional(), person_request: v1SCRAResponsePerson, eligibility: v1SCRAResponseEligibility}); export const v1SCRAResponse = z.object({reference_id: z.string().nullable().optional(), covered: z.boolean(), results: z.array(v1SCRAResponseResult).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 }; /** * Scra Search * * POST /scra/searches */ export const createApiScraSearches = async (args: CreateApiScraSearchesArgs, options?: CreateApiScraSearchesOptions) => { 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(/\/+$/, '')}/scra/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(v1SCRAResponse, await res.json()) };