import {z} from 'zod' export type Amount = {value?: string | undefined, currency?: string | undefined}; export type MonetaryAccountSetting = {color?: string | undefined, icon?: string | undefined, default_avatar_status?: string | undefined, restriction_chat?: string | undefined, sdd_expiration_action?: string | undefined}; export type Image = {attachment_public_uuid?: string | undefined, content_type?: string | undefined, height?: number | undefined, width?: number | undefined}; export type Avatar = {uuid?: string | undefined, anchor_uuid?: string | undefined, image?: Array | undefined, style?: string | undefined}; export type Pointer = {type?: string | undefined, value?: string | undefined, name?: string | undefined, service?: string | undefined}; export type Issuer = {bic?: string | undefined, name?: string | undefined}; export type MonetaryAccountProfileFill = {status?: string | undefined, balance_preferred?: Amount | undefined, balance_threshold_low?: Amount | undefined, issuer?: Issuer | undefined}; export type LabelUser = {uuid?: string | undefined, display_name?: string | undefined, country?: string | undefined, avatar?: Avatar | undefined, public_nick_name?: string | undefined}; export type LabelMonetaryAccount = {iban?: string | undefined, display_name?: string | undefined, avatar?: Avatar | undefined, label_user?: LabelUser | undefined, country?: string | undefined, bunq_me?: Pointer | undefined, is_light?: boolean | undefined, swift_bic?: string | undefined, swift_account_number?: string | undefined, transferwise_account_number?: string | undefined, transferwise_bank_code?: string | undefined, merchant_category_code?: string | undefined}; export type MonetaryAccountProfileDrain = {status?: string | undefined, balance_preferred?: Amount | undefined, balance_threshold_high?: Amount | undefined, savings_account_alias?: LabelMonetaryAccount | undefined}; export type MonetaryAccountProfile = {profile_fill?: MonetaryAccountProfileFill | undefined, profile_drain?: MonetaryAccountProfileDrain | undefined}; export type BunqId = {id?: number | undefined}; export type MonetaryAccountBank = {currency?: string | undefined, description?: string | undefined, daily_limit?: Amount | undefined, avatar_uuid?: string | undefined, status?: string | undefined, sub_status?: string | undefined, reason?: string | undefined, reason_description?: string | undefined, display_name?: string | undefined, setting?: MonetaryAccountSetting | undefined, country_iban?: string | undefined, id?: number | undefined, created?: string | undefined, updated?: string | undefined, avatar?: Avatar | undefined, overdraft_limit?: Amount | undefined, balance?: Amount | undefined, alias?: Array | undefined, public_uuid?: string | undefined, user_id?: number | undefined, monetary_account_profile?: MonetaryAccountProfile | undefined, all_auto_save_id?: Array | undefined}; export type UpdateApiUserUserIDMonetaryAccountBankItemIdArgs = {userID: number, itemId: number, 'Cache-Control'?: string | undefined, 'User-Agent': string, 'X-Bunq-Language'?: string | undefined, 'X-Bunq-Region'?: string | undefined, 'X-Bunq-Client-Request-Id'?: string | undefined, 'X-Bunq-Geolocation'?: string | undefined, 'X-Bunq-Client-Authentication': string, body: MonetaryAccountBank}; export type UpdateApiUserUserIDMonetaryAccountBankItemIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const bunqId = z.object({id: z.number().int().optional()}); export const monetaryAccountBankUpdate = z.object({Id: bunqId.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 }; /** * PUT /user/{userID}/monetary-account-bank/{itemId} */ export const updateApiUserUserIDMonetaryAccountBankItemId = async (args: UpdateApiUserUserIDMonetaryAccountBankItemIdArgs, options?: UpdateApiUserUserIDMonetaryAccountBankItemIdOptions) => { const {baseUrl = "https://public-api.sandbox.bunq.com/v1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['Cache-Control'] != null) headers.set("Cache-Control", String(args['Cache-Control'])) if (args['User-Agent'] != null) headers.set("User-Agent", String(args['User-Agent'])) if (args['X-Bunq-Language'] != null) headers.set("X-Bunq-Language", String(args['X-Bunq-Language'])) if (args['X-Bunq-Region'] != null) headers.set("X-Bunq-Region", String(args['X-Bunq-Region'])) if (args['X-Bunq-Client-Request-Id'] != null) headers.set("X-Bunq-Client-Request-Id", String(args['X-Bunq-Client-Request-Id'])) if (args['X-Bunq-Geolocation'] != null) headers.set("X-Bunq-Geolocation", String(args['X-Bunq-Geolocation'])) if (args['X-Bunq-Client-Authentication'] != null) headers.set("X-Bunq-Client-Authentication", String(args['X-Bunq-Client-Authentication'])) const url = `${baseUrl.replace(/\/+$/, '')}/user/${encodeURIComponent(String(args.userID))}/monetary-account-bank/${encodeURIComponent(String(args.itemId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(monetaryAccountBankUpdate, await res.json()) };