import {z} from 'zod' export type GetApiLedgerV1ReportSchedulesArgs = {page?: number | undefined, size?: number | undefined}; export type GetApiLedgerV1ReportSchedulesOptions = {baseUrl?: string | undefined, Hawk?: string | undefined, fetch?: typeof fetch | undefined}; export const pageable = z.object({pageNumber: z.number().int().optional(), pageSize: z.number().int().optional(), sort: z.array(z.string()).optional(), offset: z.number().int().optional(), paged: z.boolean().optional(), unpaged: z.boolean().optional()}); export const getApiLedgerV1ReportSchedulesResponse = z.object({content: z.array(z.object({id: z.string().optional(), createdBy: z.string().optional(), accountReference: z.string().optional(), time: z.string().optional(), timezone: z.string().optional(), frequencyType: z.enum(["DAILY", "WEEKLY", "MONTHLY"]).optional(), frequencyDay: z.number().int().optional(), format: z.enum(["CSV", "PDF", "JSON"]).optional(), channel: z.enum(["WEBHOOK", "EMAIL"]).optional(), email: z.string().optional(), reportType: z.enum(["TRANSACTION", "BALANCE", "SUMMARY"]).optional()})).optional(), pageable: pageable.optional(), last: z.boolean().optional(), totalPages: z.number().int().optional(), totalElements: z.number().int().optional(), first: z.boolean().optional(), size: z.number().int().optional(), number: z.number().int().optional(), sort: z.array(z.string()).optional(), numberOfElements: z.number().int().optional(), empty: z.boolean().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 }; /** * List report schedules * * GET /ledger/v1/report-schedules */ export const getApiLedgerV1ReportSchedules = async (args: GetApiLedgerV1ReportSchedulesArgs, options?: GetApiLedgerV1ReportSchedulesOptions) => { const {baseUrl = "https://api.sandbox.bvnk.com", fetch: fetchFn = fetch, Hawk} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.size != null) query.append("size", String(args.size)) if (Hawk !== undefined) headers.set("Authorization", Hawk) const url = `${baseUrl.replace(/\/+$/, '')}/ledger/v1/report-schedules${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(getApiLedgerV1ReportSchedulesResponse, await res.json()) };