import {z} from 'zod' export type GetApiUserUserIDMonetaryAccountMonetaryAccountIDScheduleScheduleIDScheduleInstanceArgs = {userID: number, 'monetary-accountID': number, scheduleID: 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}; export type GetApiUserUserIDMonetaryAccountMonetaryAccountIDScheduleScheduleIDScheduleInstanceOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const error = z.array(z.object({error_description: z.string().optional(), error_description_translated: z.string().optional()})); export const amount = z.object({value: z.string().optional(), currency: z.string().optional()}); export const image = z.object({attachment_public_uuid: z.string().optional(), content_type: z.string().optional(), height: z.number().int().optional(), width: z.number().int().optional()}); export const avatar = z.object({uuid: z.string().optional(), anchor_uuid: z.string().optional(), image: z.array(image).optional(), style: z.string().optional()}); export const labelUser = z.object({uuid: z.string().optional(), display_name: z.string().optional(), country: z.string().optional(), avatar: avatar.optional(), public_nick_name: z.string().optional()}); export const pointer = z.object({type: z.string().optional(), value: z.string().optional(), name: z.string().optional(), service: z.string().optional()}); export const labelMonetaryAccount = z.object({iban: z.string().optional(), display_name: z.string().optional(), avatar: avatar.optional(), label_user: labelUser.optional(), country: z.string().optional(), bunq_me: pointer.optional(), is_light: z.boolean().optional(), swift_bic: z.string().optional(), swift_account_number: z.string().optional(), transferwise_account_number: z.string().optional(), transferwise_bank_code: z.string().optional(), merchant_category_code: z.string().optional()}); export const attachmentMonetaryAccountPayment = z.object({id: z.number().int().optional(), monetary_account_id: z.number().int().optional()}); export const paymentArrivalExpected = z.object({status: z.string().optional(), time: z.string().optional()}); export const address = z.object({street: z.string().optional(), house_number: z.string().optional(), po_box: z.string().optional(), postal_code: z.string().optional(), city: z.string().optional(), country: z.string().optional(), extra: z.string().optional(), mailbox_name: z.string().optional(), province: z.string().optional(), is_user_address_updated: z.boolean().optional()}); export const geolocation = z.object({latitude: z.number().int().optional(), longitude: z.number().int().optional(), altitude: z.number().int().optional(), radius: z.number().int().optional()}); export const requestInquiryReference = z.object({type: z.string().optional(), id: z.number().int().optional()}); export const paymentBatchAnchoredPayment = z.object({Payment: z.array(z.lazy(() => payment)).optional()}); export const paymentBatch = z.object({payments: paymentBatchAnchoredPayment.optional()}); export const ginmonTransaction = z.object({status: z.string().optional(), status_description: z.string().optional(), status_description_translated: z.string().optional(), amount_billing: amount.optional(), amount_billing_original: amount.optional(), isin: z.string().optional(), external_identifier: z.string().optional(), label_user: labelUser.optional(), label_monetary_account: labelMonetaryAccount.optional(), counter_label_monetary_account: labelMonetaryAccount.optional(), event_id: z.number().int().optional()}); export const paymentAutoAllocateInstance = z.object({id: z.number().int().optional(), created: z.string().optional(), updated: z.string().optional(), payment_auto_allocate_id: z.number().int().optional(), status: z.string().optional(), error_message: z.array(error).optional(), payment_batch: paymentBatch.optional(), payment_id: z.number().int().optional(), all_ginmon_transaction_order: z.array(ginmonTransaction).optional()}); export const paymentSuspendedOutgoing = z.object({status: z.string().optional(), monetary_account_id: z.string().optional(), time_execution: z.string().optional()}); export const paymentFee = z.object({value: z.string().optional(), currency: z.string().optional(), invoice_id: z.number().int().optional()}); export const payment: z.ZodType = z.object({amount: amount.optional(), counterparty_alias: labelMonetaryAccount.optional(), description: z.string().optional(), attachment: z.array(attachmentMonetaryAccountPayment).optional(), merchant_reference: z.string().optional(), allow_bunqto: z.boolean().optional(), id: z.number().int().optional(), created: z.string().optional(), updated: z.string().optional(), monetary_account_id: z.number().int().optional(), alias: labelMonetaryAccount.optional(), type: z.string().optional(), sub_type: z.string().optional(), payment_arrival_expected: paymentArrivalExpected.optional(), bunqto_status: z.string().optional(), bunqto_sub_status: z.string().optional(), bunqto_share_url: z.string().optional(), bunqto_expiry: z.string().optional(), bunqto_time_responded: z.string().optional(), batch_id: z.number().int().optional(), scheduled_id: z.number().int().optional(), address_shipping: address.optional(), address_billing: address.optional(), geolocation: geolocation.optional(), request_reference_split_the_bill: z.array(requestInquiryReference).optional(), balance_after_mutation: amount.optional(), payment_auto_allocate_instance: paymentAutoAllocateInstance.optional(), payment_suspended_outgoing: paymentSuspendedOutgoing.optional(), payment_fee: paymentFee.optional()}); export const scheduleAnchorObject = z.object({Payment: payment.optional(), PaymentBatch: paymentBatch.optional()}); export const scheduleInstanceAnchorObject = z.object({Payment: payment.optional(), PaymentBatch: paymentBatch.optional()}); export const scheduleInstanceListing = z.object({state: z.string().optional(), time_start: z.string().optional(), time_end: z.string().optional(), error_message: z.array(error).optional(), scheduled_object: scheduleAnchorObject.optional(), result_object: scheduleInstanceAnchorObject.optional(), request_reference_split_the_bill: z.array(requestInquiryReference).optional()}); export const getApiUserUserIDMonetaryAccountMonetaryAccountIDScheduleScheduleIDScheduleInstanceResponse = z.array(scheduleInstanceListing); 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 /user/{userID}/monetary-account/{monetary-accountID}/schedule/{scheduleID}/schedule-instance */ export const getApiUserUserIDMonetaryAccountMonetaryAccountIDScheduleScheduleIDScheduleInstance = async (args: GetApiUserUserIDMonetaryAccountMonetaryAccountIDScheduleScheduleIDScheduleInstanceArgs, options?: GetApiUserUserIDMonetaryAccountMonetaryAccountIDScheduleScheduleIDScheduleInstanceOptions) => { const {baseUrl = "https://public-api.sandbox.bunq.com/v1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() 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/${encodeURIComponent(String(args['monetary-accountID']))}/schedule/${encodeURIComponent(String(args.scheduleID))}/schedule-instance${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(getApiUserUserIDMonetaryAccountMonetaryAccountIDScheduleScheduleIDScheduleInstanceResponse, await res.json()) };