import {z} from 'zod' export type SUBMISSIONOwnershipMatchesAddressDto = {street: string, street2?: (string | null) | undefined, city: string, state: string, zip: string}; export type SUBMISSIONCandidateNameDto = {first: string, middle?: string | undefined, last: string}; export type SUBMISSIONOwnershipMatchesInput = {address: SUBMISSIONOwnershipMatchesAddressDto, names: Array}; export type CreateApiPosfinancingRestV2OwnershipMatchesArgs = {body: SUBMISSIONOwnershipMatchesInput}; export type CreateApiPosfinancingRestV2OwnershipMatchesOptions = {baseUrl?: string | undefined, jwt?: string | undefined, fetch?: typeof fetch | undefined}; export const sUBMISSIONPropertyOwnerDto = z.object({firstName: z.string().nullable(), middleName: z.string().nullable(), lastName: z.string().nullable(), fullName: z.string().nullable(), isCorporate: z.boolean(), matched: z.boolean()}); export const sUBMISSIONCandidateNameMatchDto = z.object({first: z.string(), middle: z.string().nullable(), last: z.string(), isPropertyOwner: z.boolean()}); export const schemaObject9 = z.object({payload: z.object({allOwnersMatched: z.boolean(), similarityThreshold: z.number(), owners: z.array(sUBMISSIONPropertyOwnerDto), names: z.array(sUBMISSIONCandidateNameMatchDto)})}); 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 }; /** * Find ownership matches * * POST /posfinancing/rest/v2/ownership-matches */ export const createApiPosfinancingRestV2OwnershipMatches = async (args: CreateApiPosfinancingRestV2OwnershipMatchesArgs, options?: CreateApiPosfinancingRestV2OwnershipMatchesOptions) => { const {baseUrl = "https://devint01-api.goodleap.com", fetch: fetchFn = fetch, jwt} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (jwt !== undefined) headers.set('authorization', `Bearer ${jwt}`) const url = `${baseUrl.replace(/\/+$/, '')}/posfinancing/rest/v2/ownership-matches${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(schemaObject9, await res.json()) };