import {z} from 'zod' export type UndefinedSubmitApplicationInput = {prequalificationId: string}; export type CreateApiPosfinancingRestV2ApplicationsApplicationIdFinanceAccountsArgs = {applicationId: string, body: UndefinedSubmitApplicationInput}; export type CreateApiPosfinancingRestV2ApplicationsApplicationIdFinanceAccountsOptions = {baseUrl?: string | undefined, jwt?: string | undefined, fetch?: typeof fetch | undefined}; export const undefinedApplicationPricingOutput = z.object({}); export const undefinedApplicationApplicantOutput = z.object({role: z.enum(["APPLICANT", "COAPPLICANT"]), firstName: z.string(), lastName: z.string(), email: z.string(), dropped: z.boolean()}); export const undefinedCaseAttachment = z.object({id: z.string(), extension: z.string(), type: z.string(), name: z.string(), label: z.string(), groupId: z.string(), status: z.string()}); export const undefinedDocumentToClear = z.object({type: z.string().optional(), name: z.string(), description: z.string()}); export const undefinedApplicationPendingCaseOutput = z.object({id: z.string(), name: z.string(), description: z.string(), reasonCodes: z.array(z.string()), status: z.string(), type: z.string(), attachments: z.array(undefinedCaseAttachment), domain: z.string(), deferred: z.boolean(), createdAt: z.string(), updatedAt: z.string(), updatedBy: z.string(), appliesTo: z.string(), documentsToClear: z.array(undefinedDocumentToClear)}); export const undefinedReapplyAction = z.object({description: z.string(), type: z.string()}); export const undefinedReapply = z.object({encouraged: z.boolean(), actions: z.array(undefinedReapplyAction).nullable()}); export const undefinedDecisionExplanationReason = z.object({reasonCode: z.string(), title: z.string(), description: z.string()}); export const undefinedDecisionExplanation = z.object({reapply: undefinedReapply.optional(), reasons: z.array(undefinedDecisionExplanationReason).optional()}); export const undefinedCreditLineDto = z.object({verified: z.number().optional(), adjusted: z.number().optional(), max: z.number(), effective: z.number()}); export const undefinedPrequalificationOfferRateDto = z.object({minimum: z.number(), maximum: z.number()}); export const undefinedMarginsDto = z.object({installment: z.number(), revolving: z.number()}); export const undefinedDealerFeeDto = z.object({percent: z.number()}); export const undefinedNumberRangeDto = z.object({minimum: z.number(), maximum: z.number()}); export const undefinedPrequalificationOfferOutputDto = z.object({id: z.string(), estimatedMonthlyPaymentWithAutopay: z.number().nullable(), estimatedMonthlyPaymentWithoutAutopay: z.number().nullable(), ratesWithAutopay: undefinedPrequalificationOfferRateDto, ratesWithoutAutopay: undefinedPrequalificationOfferRateDto, term: z.number(), maxAmount: z.number(), featured: z.boolean(), margins: undefinedMarginsDto.optional(), dealerFee: undefinedDealerFeeDto.optional(), projectCostLimits: undefinedNumberRangeDto}); export const undefinedApplicationChangeOutput = z.object({code: z.enum(["PROJECT_COST", "CREDIT_LINE"]), description: z.string()}); export const schemaObject12 = z.object({payload: z.object({pricing: undefinedApplicationPricingOutput.optional(), financeAccountId: z.string(), financeType: z.enum(["loan", "lease", "ppa", "ppav", "e-heloc"]), offerId: z.string(), categoryCode: z.enum(["Solar_TPO", "HVAC_LEASE", "BATTERY_LEASE", "HELOC"]), categoryId: z.string(), createdAt: z.string(), expiresAt: z.string(), tags: z.array(z.string()), status: z.enum(["APPROVED", "APPROVED_WITH_STIPS", "DECLINED", "PENDING", "CANCELED"]), reason: z.string(), type: z.enum(["SINGLE", "COMBINED", "PRIMARY", "SECONDARY"]), applicants: z.array(undefinedApplicationApplicantOutput), cases: z.array(undefinedApplicationPendingCaseOutput).optional(), borrowerActionableUrl: z.string().optional(), decisionExplanation: undefinedDecisionExplanation.optional(), creditLine: undefinedCreditLineDto.optional(), availableOffers: z.array(undefinedPrequalificationOfferOutputDto).optional(), projectReserveLimit: z.number().nullable().optional(), estimatedMonthlyPayment: z.number().nullable().optional(), autopayEnrolled: z.boolean().optional(), changes: z.array(undefinedApplicationChangeOutput).optional()})}); 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 }; /** * Submit a completed application for decisioning * * POST /posfinancing/rest/v2/applications/{applicationId}/finance-accounts */ export const createApiPosfinancingRestV2ApplicationsApplicationIdFinanceAccounts = async (args: CreateApiPosfinancingRestV2ApplicationsApplicationIdFinanceAccountsArgs, options?: CreateApiPosfinancingRestV2ApplicationsApplicationIdFinanceAccountsOptions) => { 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))}/finance-accounts${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(schemaObject12, await res.json()) };