import {z} from 'zod' export type UndefinedNameOnTitleInput = {first: string, last: string}; export type UndefinedPhoneInputDto = {phoneNumber: string, type: 'HOME' | 'MOBILE'}; export type UndefinedApplicationPersonaMaritalPartnerInput = {firstName: string, lastName: string, email: string, primaryPhoneNumber: UndefinedPhoneInputDto, secondaryPhoneNumber?: UndefinedPhoneInputDto | undefined, homeOccupancy?: ('PRIMARY' | 'SECONDARY' | 'INVESTMENT' | 'OTHER') | undefined}; export type UndefinedCreateApplicationPersonaInput = {nameOnTitle?: UndefinedNameOnTitleInput | undefined, primaryPhoneNumber: UndefinedPhoneInputDto, secondaryPhoneNumber?: UndefinedPhoneInputDto | undefined, maritalPartner?: UndefinedApplicationPersonaMaritalPartnerInput | undefined, firstName: string, lastName: string, email: string, maritalStatus: 'SINGLE' | 'MARRIED' | 'DIVORCED' | 'SEPARATED' | 'WIDOWED', homeOccupancy?: ('PRIMARY' | 'SECONDARY' | 'INVESTMENT' | 'OTHER') | undefined}; export type CreateApiPosfinancingRestV2ApplicationsApplicationIdPersonasArgs = {applicationId: unknown, body: UndefinedCreateApplicationPersonaInput}; export type CreateApiPosfinancingRestV2ApplicationsApplicationIdPersonasOptions = {baseUrl?: string | undefined, jwt?: string | undefined, fetch?: typeof fetch | undefined}; export const undefinedPhone = z.object({countryCode: z.string(), isoCountryCode: z.string().optional(), phoneNumber: z.string(), type: z.enum(["HOME", "MOBILE"])}); export const undefinedPersonaMaritalPartnerDto = z.object({firstName: z.string(), lastName: z.string(), email: z.string(), primaryPhoneNumber: undefinedPhone, secondaryPhoneNumber: undefinedPhone.optional(), homeOccupancy: z.enum(["PRIMARY", "SECONDARY", "INVESTMENT", "OTHER"]).optional()}); export const undefinedNameOnTitleDto = z.object({first: z.string(), last: z.string()}); export const schemaObject11 = z.object({payload: z.object({id: z.string(), type: z.literal("PROPERTY_OWNER"), firstName: z.string(), lastName: z.string(), email: z.string().optional(), primaryPhoneNumber: undefinedPhone.optional(), secondaryPhoneNumber: undefinedPhone.optional(), maritalStatus: z.enum(["SINGLE", "MARRIED", "DIVORCED", "SEPARATED", "WIDOWED"]).optional(), maritalPartner: undefinedPersonaMaritalPartnerDto.optional(), nameOnTitle: undefinedNameOnTitleDto.optional(), homeOccupancy: z.enum(["PRIMARY", "SECONDARY", "INVESTMENT", "OTHER"]).optional(), createdAt: 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 }; /** * Creates a property-owner persona on an application * * POST /posfinancing/rest/v2/applications/{applicationId}/personas */ export const createApiPosfinancingRestV2ApplicationsApplicationIdPersonas = async (args: CreateApiPosfinancingRestV2ApplicationsApplicationIdPersonasArgs, options?: CreateApiPosfinancingRestV2ApplicationsApplicationIdPersonasOptions) => { 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/applications/${encodeURIComponent(String(args.applicationId))}/personas${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(schemaObject11, await res.json()) };