import {z} from 'zod' export type GetApiUserNoticeEventsArgs = {IDs?: string | undefined, Name?: string | undefined, RequiresBookingRequest?: boolean | undefined, Enabled?: boolean | undefined, From?: string | undefined, To?: string | undefined, Lat?: number | undefined, Lng?: number | undefined, Country?: string | undefined, ExcludeBundleBookings?: boolean | undefined, Limit?: number | undefined, Offset?: number | undefined, OrderBy?: string | undefined}; export type GetApiUserNoticeEventsOptions = {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 getApiUserNoticeEventsResponse = z.array(noticeEvent); 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 }; /** * Lists user notice events * * GET /user-notice-events * * Also accepts auth: API-Key */ export const getApiUserNoticeEvents = async (args: GetApiUserNoticeEventsArgs, options: GetApiUserNoticeEventsOptions) => { const {baseUrl, fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.IDs != null) query.append("IDs", String(args.IDs)) if (args.Name != null) query.append("Name", String(args.Name)) if (args.RequiresBookingRequest != null) query.append("RequiresBookingRequest", String(args.RequiresBookingRequest)) if (args.Enabled != null) query.append("Enabled", String(args.Enabled)) if (args.From != null) query.append("From", String(args.From)) if (args.To != null) query.append("To", String(args.To)) if (args.Lat != null) query.append("Lat", String(args.Lat)) if (args.Lng != null) query.append("Lng", String(args.Lng)) if (args.Country != null) query.append("Country", String(args.Country)) if (args.ExcludeBundleBookings != null) query.append("ExcludeBundleBookings", String(args.ExcludeBundleBookings)) if (args.Limit != null) query.append("Limit", String(args.Limit)) if (args.Offset != null) query.append("Offset", String(args.Offset)) if (args.OrderBy != null) query.append("OrderBy", String(args.OrderBy)) if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/user-notice-events${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(getApiUserNoticeEventsResponse, await res.json()) };