import {z} from 'zod' export type GetApiPosfinancingRestV2PrequalificationsPrequalificationIdArgs = {prequalificationId: unknown}; export type GetApiPosfinancingRestV2PrequalificationsPrequalificationIdOptions = {baseUrl?: string | undefined, jwt?: string | undefined, fetch?: typeof fetch | undefined}; export const undefinedPrequalificationCategoryDto = z.object({id: z.string(), code: z.enum(["Solar_TPO", "HVAC_LEASE", "BATTERY_LEASE", "HELOC"]), name: z.string()}); 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 undefinedAddress = z.object({line1: z.string(), line2: z.string().optional(), city: z.string(), state: z.string(), zip: z.string(), country: z.string().optional()}); export const undefinedLegalEntityDto = z.object({name: z.string(), address: undefinedAddress}); export const undefinedMortgageOfficerOutputDto = z.object({fullName: z.string(), licenseNumber: z.string(), legalEntity: undefinedLegalEntityDto, id: z.string()}); export const schemaObject4 = z.object({payload: z.object({projectCost: z.number().nullable(), requestedCreditLine: z.number().nullable(), selectedOfferId: z.string().optional(), category: undefinedPrequalificationCategoryDto, availableOffers: z.array(undefinedPrequalificationOfferOutputDto), autopayEnrolled: z.boolean(), projectReserveLimit: z.number().nullable(), createdAt: z.string(), expiresAt: z.string(), status: z.enum(["APPROVED", "APPROVED_WITH_STIPS", "DECLINED", "PENDING", "CANCELED"]), mortgageOfficer: undefinedMortgageOfficerOutputDto.optional(), id: 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 a prequalification by its unique identifier. * * GET /posfinancing/rest/v2/prequalifications/{prequalificationId} */ export const getApiPosfinancingRestV2PrequalificationsPrequalificationId = async (args: GetApiPosfinancingRestV2PrequalificationsPrequalificationIdArgs, options?: GetApiPosfinancingRestV2PrequalificationsPrequalificationIdOptions) => { 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 (jwt !== undefined) headers.set('authorization', `Bearer ${jwt}`) const url = `${baseUrl.replace(/\/+$/, '')}/posfinancing/rest/v2/prequalifications/${encodeURIComponent(String(args.prequalificationId))}${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(schemaObject4, await res.json()) };