import {z} from 'zod' export type BatchAppointmentScheduleInput = {appointment_description?: string | undefined, appointment_duration?: number | undefined, appointment_location?: string | undefined, appointment_location_type?: (0 | 1 | 2) | undefined, appointment_owner_id?: string | undefined, appointment_subject?: string | undefined, appointment_subject_uses_schedule_name?: boolean | undefined, appointment_type_id?: string | undefined, availability_tzid?: string | undefined, buffer_time_after?: number | undefined, buffer_time_before?: number | undefined, confirmation_page_type?: (0 | 1) | undefined, confirmation_page_url?: string | undefined, is_enabled?: boolean | undefined, minimum_notice_time?: number | undefined, name?: string | undefined, owner_id?: string | undefined, planning_day_offset?: number | undefined, planning_period_from?: string | undefined, planning_period_to?: string | undefined, planning_type?: (0 | 1 | 2) | undefined, reminder_email_enabled?: boolean | undefined, reminder_email_offset?: number | undefined, reminder_email_offset_type?: (0 | 1 | 2 | 3) | undefined, reply_company_email_id?: string | undefined, schedule_name?: string | undefined, time_increment?: number | undefined, type?: (0 | 1) | undefined, url?: string | undefined, additional_fields_data?: Array<{field_id: string, label: string, is_required: boolean}> | undefined, availability_data?: Record | undefined, appointment_invitees_data?: (Array<{entity_id?: string | undefined, email: string, type: 1 | 2 | 3}>) | undefined, id?: string | undefined}; export type CreateApiEntitiesAppointmentSchedulesBatchModifyArgs = {'validation-level'?: number | undefined, 'rollback-method'?: (0 | 1) | undefined, body: Array}; export type CreateApiEntitiesAppointmentSchedulesBatchModifyOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const error = z.object({http_status: z.number().int(), code: z.number().int().optional(), name: z.string().optional(), message: z.string().optional(), success: z.boolean()}); export const createApiEntitiesAppointmentSchedulesBatchModifyResponse = z.object({success: z.boolean().optional(), data: z.array(z.union([z.string(), error])).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 }; /** * AppointmentSchedules.batch_create_or_update * * POST /entities/AppointmentSchedules/batch-modify */ export const createApiEntitiesAppointmentSchedulesBatchModify = async (args: CreateApiEntitiesAppointmentSchedulesBatchModifyArgs, options?: CreateApiEntitiesAppointmentSchedulesBatchModifyOptions) => { const {baseUrl = "https://us-east.api.coevera.com/api/v100/rest/spaces/your_space_id", fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['validation-level'] != null) query.append("validation-level", String(args['validation-level'])) if (args['rollback-method'] != null) query.append("rollback-method", String(args['rollback-method'])) if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/entities/AppointmentSchedules/batch-modify${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(createApiEntitiesAppointmentSchedulesBatchModifyResponse, await res.json()) };