import {z} from 'zod' export type DBStringSlice = Array; export type NoticeEvent = {countries?: DBStringSlice | undefined, created?: string | undefined, enabled?: boolean | undefined, exclude_bundle_bookings?: boolean | undefined, from?: string | undefined, guest_acknowledgement_text?: string | undefined, guest_need_to_acknowledge?: boolean | undefined, guest_user_text?: string | undefined, host_acknowledgement_text?: string | undefined, host_help_url?: string | undefined, host_need_to_acknowledge?: boolean | undefined, host_user_text?: string | undefined, id?: number | undefined, lat?: number | undefined, lng?: number | undefined, name?: string | undefined, radius?: number | undefined, requires_booking_request?: boolean | undefined, to?: string | undefined, updated?: string | undefined}; export type CreateApiUserNoticeEventsArgs = {body: NoticeEvent}; export type CreateApiUserNoticeEventsOptions = {baseUrl: string, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const dBStringSlice = z.array(z.string()); export const noticeEvent = z.object({countries: dBStringSlice.optional(), created: z.string().optional(), enabled: z.boolean().optional(), exclude_bundle_bookings: z.boolean().optional(), from: z.string().optional(), guest_acknowledgement_text: z.string().optional(), guest_need_to_acknowledge: z.boolean().optional(), guest_user_text: z.string().optional(), host_acknowledgement_text: z.string().optional(), host_help_url: z.string().optional(), host_need_to_acknowledge: z.boolean().optional(), host_user_text: z.string().optional(), id: z.number().int().optional(), lat: z.number().optional(), lng: z.number().optional(), name: z.string().optional(), radius: z.number().optional(), requires_booking_request: z.boolean().optional(), to: z.string().optional(), updated: 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 }; /** * Creates a user notice event * * POST /user-notice-events * * Also accepts auth: API-Key */ export const createApiUserNoticeEvents = async (args: CreateApiUserNoticeEventsArgs, options: CreateApiUserNoticeEventsOptions) => { const {baseUrl, fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/user-notice-events${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(noticeEvent, await res.json()) };