import {z} from 'zod' export type GetApiBillingTenantLocatorInstallmentLatticesInstallmentLatticeLocatorArgs = {tenantLocator: string, installmentLatticeLocator: unknown}; export type GetApiBillingTenantLocatorInstallmentLatticesInstallmentLatticeLocatorOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const installmentLatticeFrame = z.object({installmentStartTime: z.string(), installmentEndTime: z.string(), coverageStartTime: z.string(), coverageEndTime: z.string(), installmentDuration: z.number(), normalizedWeight: z.number(), coverageDuration: z.number(), generateTime: z.string(), dueTime: z.string(), autopayTime: z.string()}); export const installmentLatticeResponse = z.object({locator: z.string(), settingsLocator: z.string().optional(), createdAt: z.string(), createdBy: z.string(), accountLocator: z.string(), termStartTime: z.string(), termEndTime: z.string(), termLocator: z.string().optional(), quoteLocator: z.string().optional(), policyLocator: z.string().optional(), currency: z.string(), timezone: z.string(), basedOnLocator: z.string().optional(), effectiveTime: z.string(), frames: z.array(installmentLatticeFrame), reversalLattice: z.boolean()}); 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 }; /** * GET /billing/{tenantLocator}/installmentLattices/{installmentLatticeLocator} */ export const getApiBillingTenantLocatorInstallmentLatticesInstallmentLatticeLocator = async (args: GetApiBillingTenantLocatorInstallmentLatticesInstallmentLatticeLocatorArgs, options: GetApiBillingTenantLocatorInstallmentLatticesInstallmentLatticeLocatorOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/billing/${encodeURIComponent(String(args.tenantLocator))}/installmentLattices/${encodeURIComponent(String(args.installmentLatticeLocator))}${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(installmentLatticeResponse, await res.json()) };