import {z} from 'zod' export type GetApiApiV1AdminBankAccountsBankAccountIdTransfermateTransactionSummaryArgs = {bankAccountId: string, currency_from?: string | undefined, ref_number?: string | undefined, reconciliation_id?: string | undefined, date_from?: string | undefined, date_to?: string | undefined, transactions_statuses?: string | undefined, client_transaction_id?: string | undefined, p_number?: string | undefined}; export type GetApiApiV1AdminBankAccountsBankAccountIdTransfermateTransactionSummaryOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const adminTransfermateTransactionSummaryResponse = z.object({success: z.boolean(), data: z.object({is_successful: z.boolean(), messages: z.object({}), page: z.number().optional(), pages_count: z.number().optional(), records_per_page: z.number().optional(), total_records: z.number().optional(), transactions: z.array(z.object({})), metadata: z.array(z.object({}))})}); 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 raw TransferMate transaction summary for a bank account (admin only) * * GET /api/v1/admin/bank-accounts/{bankAccountId}/transfermate/transaction-summary */ export const getApiApiV1AdminBankAccountsBankAccountIdTransfermateTransactionSummary = async (args: GetApiApiV1AdminBankAccountsBankAccountIdTransfermateTransactionSummaryArgs, options?: GetApiApiV1AdminBankAccountsBankAccountIdTransfermateTransactionSummaryOptions) => { 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.currency_from != null) query.append("currency_from", String(args.currency_from)) if (args.ref_number != null) query.append("ref_number", String(args.ref_number)) if (args.reconciliation_id != null) query.append("reconciliation_id", String(args.reconciliation_id)) 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.transactions_statuses != null) query.append("transactions_statuses", String(args.transactions_statuses)) if (args.client_transaction_id != null) query.append("client_transaction_id", String(args.client_transaction_id)) if (args.p_number != null) query.append("p_number", String(args.p_number)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/admin/bank-accounts/${encodeURIComponent(String(args.bankAccountId))}/transfermate/transaction-summary${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(adminTransfermateTransactionSummaryResponse, await res.json()) };