import {z} from 'zod' export type GetApiPosfinancingRestV2HomeMortgageDisclosuresArgs = {lifecycleStatus?: ('DRAFT' | 'ACTIVE' | 'DEPRECATED' | 'RETIRED') | undefined}; export type GetApiPosfinancingRestV2HomeMortgageDisclosuresOptions = {baseUrl?: string | undefined, jwt?: string | undefined, fetch?: typeof fetch | undefined}; export const sUBMISSIONLocalizationEntryDto = z.object({language: z.string(), locale: z.string(), text: z.string()}); export const sUBMISSIONLocalizedTextDto = z.object({default: z.string(), localizations: z.array(sUBMISSIONLocalizationEntryDto)}); export const sUBMISSIONHmdaApplicabilityDto = z.object({applicantRoles: z.array(z.enum(["APPLICANT", "COAPPLICANT"]))}); export const sUBMISSIONHmdaResponseSchemaDto = z.object({type: z.enum(["SINGLE_SELECT", "MULTI_SELECT", "NUMERIC", "TEXT", "DATE"]), allowedValues: z.array(z.string()).optional(), maxSelections: z.number().optional()}); export const sUBMISSIONHmdaOptionDto = z.object({key: z.string(), label: sUBMISSIONLocalizedTextDto, value: z.string()}); export const sUBMISSIONHmdaVisibilityConditionDto = z.object({field: z.string().optional(), operator: z.enum(["ALWAYS", "EQUALS", "CONTAINS"]), value: z.string().optional()}); export const sUBMISSIONHmdaVisibilityDto = z.object({conditions: z.array(sUBMISSIONHmdaVisibilityConditionDto), logic: z.enum(["ALL", "ANY"])}); export const sUBMISSIONHomeMortgageDisclosureDto = z.object({code: z.string(), section: z.string(), title: sUBMISSIONLocalizedTextDto, description: sUBMISSIONLocalizedTextDto.optional(), applicability: sUBMISSIONHmdaApplicabilityDto, responseSchema: sUBMISSIONHmdaResponseSchemaDto, options: z.array(sUBMISSIONHmdaOptionDto).optional(), visibility: sUBMISSIONHmdaVisibilityDto, lifecycleStatus: z.enum(["DRAFT", "ACTIVE", "DEPRECATED", "RETIRED"]), id: z.string()}); export const schemaObject1 = z.object({payload: z.object({items: z.array(sUBMISSIONHomeMortgageDisclosureDto), token: z.string(), tokenExpiresAt: 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 }; /** * Fetches the mortgage officer configuration for a state from application submission configuration. When categoryCode is omitted, the officer assigned to the state is returned. * * GET /posfinancing/rest/v2/home-mortgage-disclosures */ export const getApiPosfinancingRestV2HomeMortgageDisclosures = async (args: GetApiPosfinancingRestV2HomeMortgageDisclosuresArgs, options?: GetApiPosfinancingRestV2HomeMortgageDisclosuresOptions) => { const {baseUrl = "https://devint01-api.goodleap.com", fetch: fetchFn = fetch, jwt} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.lifecycleStatus != null) query.append("lifecycleStatus", String(args.lifecycleStatus)) if (jwt !== undefined) headers.set('authorization', `Bearer ${jwt}`) const url = `${baseUrl.replace(/\/+$/, '')}/posfinancing/rest/v2/home-mortgage-disclosures${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(schemaObject1, await res.json()) };