import {z} from 'zod' export type GetApiV1VehiclesEligibilityIdResultsArgs = {id: string, maxPageSize?: (number | null) | undefined, currentPage?: (number | null) | undefined}; export type GetApiV1VehiclesEligibilityIdResultsOptions = {baseUrl?: string | undefined, OAuth2ClientCredentialsBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const eligibilityVinEntryStatusEnum = z.enum(["NOT_SUPPORTED", "VALIDATION_ERROR", "PENDING", "SUBMITTED", "INELIGIBLE_PENDING_FAILURE_REASON", "ELIGIBLE", "INELIGIBLE", "FAILED"]); export const singleEligibilityResult = z.object({rowId: z.number().int(), vin: z.string().min(17).max(17), make: z.enum(["ABARTH", "ALFA ROMEO", "AUDI", "BMW", "CHERY", "CHRYSLER", "CITROEN", "CUPRA", "DODGE", "DS AUTOMOBILES", "FIAT", "FORD", "HYUNDAI", "JAECOO", "JEEP", "KIA", "LANCIA", "LEXUS", "MASERATI", "MERCEDES BENZ", "MINI", "NISSAN", "OMODA", "OPEL", "PEUGEOT", "POLESTAR", "RAM", "RENAULT", "SEAT", "SKODA", "TESLA", "TOYOTA", "VAUXHALL", "VOLKSWAGEN", "VOLVO"]).nullable().optional(), status: eligibilityVinEntryStatusEnum, errorMessage: z.string().nullable().optional()}); export const pageResultsSingleEligibilityResult = z.object({results: z.array(singleEligibilityResult).optional(), totalResults: z.number().int().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 }; /** * Bulk Vehicle Eligibility Check Results * * GET /v1/vehicles/eligibility/{id}/results */ export const getApiV1VehiclesEligibilityIdResults = async (args: GetApiV1VehiclesEligibilityIdResultsArgs, options?: GetApiV1VehiclesEligibilityIdResultsOptions) => { const {baseUrl = "https://api.volteras.com", fetch: fetchFn = fetch, OAuth2ClientCredentialsBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.maxPageSize != null) query.append("maxPageSize", String(args.maxPageSize)) if (args.currentPage != null) query.append("currentPage", String(args.currentPage)) if (OAuth2ClientCredentialsBearer !== undefined) headers.set('authorization', `Bearer ${OAuth2ClientCredentialsBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/vehicles/eligibility/${encodeURIComponent(String(args.id))}/results${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(pageResultsSingleEligibilityResult, await res.json()) };