import {z} from 'zod' export type NoteTextScheduleInstance = {content?: string | undefined}; export type CreateApiUserUserIDMonetaryAccountMonetaryAccountIDScheduleScheduleIDScheduleInstanceScheduleInstanceIDNoteTextArgs = {userID: number, 'monetary-accountID': number, scheduleID: number, 'schedule-instanceID': 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: NoteTextScheduleInstance}; export type CreateApiUserUserIDMonetaryAccountMonetaryAccountIDScheduleScheduleIDScheduleInstanceScheduleInstanceIDNoteTextOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const bunqId = z.object({id: z.number().int().optional()}); export const noteTextScheduleInstanceCreate = 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 }; /** * POST /user/{userID}/monetary-account/{monetary-accountID}/schedule/{scheduleID}/schedule-instance/{schedule-instanceID}/note-text */ export const createApiUserUserIDMonetaryAccountMonetaryAccountIDScheduleScheduleIDScheduleInstanceScheduleInstanceIDNoteText = async (args: CreateApiUserUserIDMonetaryAccountMonetaryAccountIDScheduleScheduleIDScheduleInstanceScheduleInstanceIDNoteTextArgs, options?: CreateApiUserUserIDMonetaryAccountMonetaryAccountIDScheduleScheduleIDScheduleInstanceScheduleInstanceIDNoteTextOptions) => { 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/${encodeURIComponent(String(args['monetary-accountID']))}/schedule/${encodeURIComponent(String(args.scheduleID))}/schedule-instance/${encodeURIComponent(String(args['schedule-instanceID']))}/note-text${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(noteTextScheduleInstanceCreate, await res.json()) };