import {z} from 'zod' export type GetApiApiTransactionV2ReportArgs = {walletId?: string | undefined, fromDate?: string | undefined, toDate?: string | undefined, format?: string | undefined, transactionType?: string | undefined}; export type GetApiApiTransactionV2ReportOptions = {baseUrl?: string | undefined, Hawk?: string | undefined, fetch?: typeof fetch | undefined}; export const simplifiedTransactionReportDto = z.object({id: z.number().int().optional(), uuid: z.string().optional(), dateCreated: z.number().int().optional(), lastUpdated: z.number().int().optional(), expiryDate: z.number().int().optional(), status: z.string().optional(), type: z.string().optional()}); export const getApiApiTransactionV2ReportResponse = z.array(simplifiedTransactionReportDto); 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 }; /** * Transactions report * * GET /api/transaction/v2/report */ export const getApiApiTransactionV2Report = async (args: GetApiApiTransactionV2ReportArgs, options?: GetApiApiTransactionV2ReportOptions) => { 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.walletId != null) query.append("walletId", String(args.walletId)) if (args.fromDate != null) query.append("fromDate", String(args.fromDate)) if (args.toDate != null) query.append("toDate", String(args.toDate)) if (args.format != null) query.append("format", String(args.format)) if (args.transactionType != null) query.append("transactionType", String(args.transactionType)) if (Hawk !== undefined) headers.set("Authorization", Hawk) const url = `${baseUrl.replace(/\/+$/, '')}/api/transaction/v2/report${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(getApiApiTransactionV2ReportResponse, await res.json()) };