import {z} from 'zod' export type GetApiApiV1MerchantsIdBankAccountsActiveArgs = {id: string, currency?: string | undefined, roles?: (Array<'receiving' | 'settlement' | 'refund'>) | undefined, include_balance?: boolean | undefined}; export type GetApiApiV1MerchantsIdBankAccountsActiveOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const merchantBankAccountListResponse = z.object({success: z.boolean(), data: z.array(z.object({id: z.string().optional(), account_number: z.string().optional(), currency: z.string().min(3).max(3).optional(), country: z.string().min(2).max(2).optional(), status: z.union([z.literal("active"), z.literal("archived")]).optional(), account_information_session_id: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), iban: z.string().optional(), bic: z.string().optional(), sort_code: z.string().optional(), routing_number: z.string().optional(), bban: z.string().optional(), plusgiro_number: z.string().optional(), bsb: z.string().optional(), account_holder_name: z.string().optional(), supported_payment_schemes: z.array(z.object({id: z.string(), type: z.union([z.literal("SEPA_CREDIT_TRANSFER"), z.literal("MULTIBANCO"), z.literal("DANISH_DOMESTIC_CREDIT_TRANSFER"), z.literal("FASTER_PAYMENTS"), z.literal("BACS"), z.literal("BECS"), z.literal("ACH")]), name: z.string(), is_active: z.boolean(), additional_payment_method: z.boolean()})).optional(), roles: z.array(z.union([z.literal("receiving"), z.literal("settlement"), z.literal("refund")])).optional(), balance: z.string().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 }; /** * Get active bank account(s) for a merchant. Optionally filter by currency query param. * * GET /api/v1/merchants/{id}/bank-accounts/active */ export const getApiApiV1MerchantsIdBankAccountsActive = async (args: GetApiApiV1MerchantsIdBankAccountsActiveArgs, options?: GetApiApiV1MerchantsIdBankAccountsActiveOptions) => { 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 != null) query.append("currency", String(args.currency)) for (const item of args.roles ?? []) query.append("roles", String(item)) if (args.include_balance != null) query.append("include_balance", String(args.include_balance)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/merchants/${encodeURIComponent(String(args.id))}/bank-accounts/active${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(merchantBankAccountListResponse, await res.json()) };