import {z} from 'zod' export type GetApiApiV1BankAccountsBankAccountIdTransactionsArgs = {bankAccountId: string, date_from?: string | undefined, date_to?: string | undefined, page?: number | undefined, limit?: (number | number | number | number) | undefined, direction?: ('in' | 'out') | undefined}; export type GetApiApiV1BankAccountsBankAccountIdTransactionsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const bankAccountTransactionsListResponse = z.object({success: z.boolean(), data: z.array(z.object({date: z.string(), direction: z.union([z.literal("in"), z.literal("out")]), amount: z.string(), currency: z.string(), beneficiary: z.string(), running_balance: z.string(), transaction_type: z.string(), status: z.string(), web_transaction_id: z.string(), related_transaction_id: z.string().optional(), related_transaction_number: z.string().optional()})), pagination: z.object({total: z.number().int(), page: z.number().int(), limit: z.number().int(), totalPages: z.number().int(), hasNextPage: z.boolean(), hasPreviousPage: 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 }; /** * List transactions for a bank account (money in / money out). Currently supported only for refund accounts; other roles return 404. Supports JSON (paginated) and xlsx/csv exports via Accept header. * * GET /api/v1/bank-accounts/{bankAccountId}/transactions */ export const getApiApiV1BankAccountsBankAccountIdTransactions = async (args: GetApiApiV1BankAccountsBankAccountIdTransactionsArgs, options?: GetApiApiV1BankAccountsBankAccountIdTransactionsOptions) => { const {baseUrl = "https://core.quidkey.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.date_from != null) query.append("date_from", String(args.date_from)) if (args.date_to != null) query.append("date_to", String(args.date_to)) if (args.page != null) query.append("page", String(args.page)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.direction != null) query.append("direction", String(args.direction)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/bank-accounts/${encodeURIComponent(String(args.bankAccountId))}/transactions${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(bankAccountTransactionsListResponse, await res.json()) };