import {z} from 'zod' export type GetApiPaymentsDepositAccountsArgs = {country?: string | undefined, currency?: string | undefined}; export type GetApiPaymentsDepositAccountsOptions = {baseUrl?: string | undefined, APIKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiPaymentsDepositAccountsResponse = z.object({data: z.array(z.object({id: z.string(), country_code: z.string(), account_name: z.string().min(1), account_number: z.string().min(1).optional(), account_type: z.enum(["checking", "current", "payment", "saving"]).optional(), alternate_account_identifiers: z.object({email: z.string()}).optional(), iban: z.string().min(1).optional(), institution: z.object({name: z.string().optional(), branch_name: z.string().optional(), address: z.string().optional(), city: z.string().optional(), zip_code: z.string().optional()}), supported_features: z.array(z.object({currency: z.string(), transfer_method: z.enum(["local", "swift"]), local_clearing_system: z.enum(["ach", "atm_prima", "bacs", "bank_transfer", "becs", "bi_fast", "chaps", "citad", "direct_entry_transfer", "duitnow", "eft", "elixir", "express_elixir", "fast", "faster_payments", "fednow", "fedwire", "fps", "giro", "hofinet", "instapay", "interac", "intradagclearing", "ipi", "kronos2", "masav", "napas", "npp", "osko", "payto", "pesonet", "pix", "rentas", "rtgs", "rtp", "sepa", "sepa_instant", "skn", "sorbnet", "spei", "straksclearing", "target2", "ted", "zahav", "zengin"]).optional(), routing_codes: z.array(z.object({type: z.enum(["ach", "bank_code", "branch_code", "bsb", "citad_bank_code", "cnpj", "fednow", "fedwire", "institution_number", "rtp", "sort_code", "swift", "transit_number"]), value: z.string().min(1)})).optional()})), swift_code: z.string().min(1).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 all deposit accounts * * GET /payments/deposit-accounts * * Also accepts auth: OAuth2 */ export const getApiPaymentsDepositAccounts = async (args: GetApiPaymentsDepositAccountsArgs, options?: GetApiPaymentsDepositAccountsOptions) => { const {baseUrl = "https://core.sivo.com", fetch: fetchFn = fetch, APIKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.country != null) query.append("country", String(args.country)) if (args.currency != null) query.append("currency", String(args.currency)) if (APIKeyAuth !== undefined) headers.set("Authorization", APIKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/payments/deposit-accounts${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(getApiPaymentsDepositAccountsResponse, await res.json()) };