import {z} from 'zod' export type GetApiApiV1DashboardDelinquentLoansArgs = {portfolioId: string, asOf?: string | undefined, productIds?: (Array | null) | undefined, productVersionIds?: (Array | null) | undefined, bucketCode?: ('current' | '1_30' | '31_60' | '61_90' | '91_plus' | 'par30' | 'par60' | 'par90') | undefined, assignedOfficerId?: string | undefined, limit?: number | undefined, offset?: number | undefined}; export type GetApiApiV1DashboardDelinquentLoansOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const dashboardFreshnessHuma = z.object({generatedAt: z.string(), isStale: z.boolean(), liveFallbackUsed: z.boolean(), policyCode: z.string(), policyPersistedAt: z.string(), snapshotAsOfDate: z.string(), snapshotId: z.string(), source: z.string(), stalenessReason: z.string().optional()}); export const delinquentLoanRowHuma = z.object({asOfDate: z.string(), assignedOfficerId: z.string(), assignedOfficerName: z.string(), borrowerId: z.string(), borrowerName: z.string(), bucketCode: z.string(), daysOverdue: z.number().int(), loanAccountId: z.string(), oldestDueDate: z.string(), outstandingAmount: z.string(), overdueAmount: z.string(), productId: z.string(), productVersionId: z.string()}); export const delinquentLoansHumaBody = z.object({asOfDate: z.string(), freshness: dashboardFreshnessHuma, limit: z.number().int(), loans: z.array(delinquentLoanRowHuma).nullable(), offset: z.number().int()}); 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 }; /** * List delinquent loans * * GET /api/v1/dashboard/delinquent-loans */ export const getApiApiV1DashboardDelinquentLoans = async (args: GetApiApiV1DashboardDelinquentLoansArgs, options?: GetApiApiV1DashboardDelinquentLoansOptions) => { const {baseUrl = "https://identity.sandbox.lerian.net", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.portfolioId != null) query.append("portfolioId", String(args.portfolioId)) if (args.asOf != null) query.append("asOf", String(args.asOf)) for (const item of args.productIds ?? []) query.append("productIds", String(item)) for (const item of args.productVersionIds ?? []) query.append("productVersionIds", String(item)) if (args.bucketCode != null) query.append("bucketCode", String(args.bucketCode)) if (args.assignedOfficerId != null) query.append("assignedOfficerId", String(args.assignedOfficerId)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/dashboard/delinquent-loans${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(delinquentLoansHumaBody, await res.json()) };