import {z} from 'zod' export type UpdateApiApiV1BankAccountsBankAccountIdDeactivateArgs = {bankAccountId: string}; export type UpdateApiApiV1BankAccountsBankAccountIdDeactivateOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const merchantBankAccountResponse = z.object({success: z.boolean(), data: 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 }; /** * Deactivate a specific bank account * * PUT /api/v1/bank-accounts/{bankAccountId}/deactivate */ export const updateApiApiV1BankAccountsBankAccountIdDeactivate = async (args: UpdateApiApiV1BankAccountsBankAccountIdDeactivateArgs, options?: UpdateApiApiV1BankAccountsBankAccountIdDeactivateOptions) => { 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 (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/bank-accounts/${encodeURIComponent(String(args.bankAccountId))}/deactivate${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(merchantBankAccountResponse, await res.json()) };