import {z} from 'zod' export type AddAttendeeInput20240813 = {name: string, timeZone: string, phoneNumber?: string | undefined, language?: ('ar' | 'ca' | 'de' | 'es' | 'eu' | 'he' | 'id' | 'ja' | 'lv' | 'pl' | 'ro' | 'sr' | 'th' | 'vi' | 'az' | 'cs' | 'el' | 'es-419' | 'fi' | 'hr' | 'it' | 'km' | 'nl' | 'pt' | 'ru' | 'sv' | 'tr' | 'zh-CN' | 'bg' | 'da' | 'en' | 'et' | 'fr' | 'hu' | 'iw' | 'ko' | 'no' | 'pt-BR' | 'sk' | 'ta' | 'uk' | 'zh-TW' | 'bn') | undefined, email: string}; export type CreateApiV2BookingsBookingUidAttendeesArgs = {'cal-api-version': string, bookingUid: string, Authorization: string, body: AddAttendeeInput20240813}; export type CreateApiV2BookingsBookingUidAttendeesOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const bookingAttendeeOutput20240813 = z.object({name: z.string(), email: z.string(), displayEmail: z.string(), timeZone: z.string(), language: z.enum(["ar", "ca", "de", "es", "eu", "he", "id", "ja", "lv", "pl", "ro", "sr", "th", "vi", "az", "cs", "el", "es-419", "fi", "hr", "it", "km", "nl", "pt", "ru", "sv", "tr", "zh-CN", "bg", "da", "en", "et", "fr", "hu", "iw", "ko", "no", "pt-BR", "sk", "ta", "uk", "zh-TW", "bn"]).optional(), absent: z.boolean(), phoneNumber: z.string().optional(), id: z.number(), bookingId: z.number()}); export const addAttendeeOutput20240813 = z.object({status: z.enum(["success", "error"]), data: bookingAttendeeOutput20240813}); 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 }; /** * Add an attendee to a booking * * POST /v2/bookings/{bookingUid}/attendees */ export const createApiV2BookingsBookingUidAttendees = async (args: CreateApiV2BookingsBookingUidAttendeesArgs, options: CreateApiV2BookingsBookingUidAttendeesOptions) => { const {baseUrl, 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['cal-api-version'] != null) headers.set("cal-api-version", String(args['cal-api-version'])) if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) const url = `${baseUrl.replace(/\/+$/, '')}/v2/bookings/${encodeURIComponent(String(args.bookingUid))}/attendees${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(addAttendeeOutput20240813, await res.json()) };