import {z} from 'zod' export type CalendarEventResponseStatus = 'accepted' | 'pending' | 'declined' | 'needsAction'; export type UpdateCalendarEventAttendee = {email?: string | undefined, name?: string | undefined, responseStatus?: CalendarEventResponseStatus | undefined, self?: (boolean | null) | undefined, optional?: (boolean | null) | undefined, host?: (boolean | null) | undefined}; export type CalendarEventStatus = 'accepted' | 'pending' | 'declined' | 'cancelled'; export type UpdateUnifiedCalendarEventInput = {start?: ({time?: string | undefined, timeZone?: string | undefined}) | undefined, end?: ({time?: string | undefined, timeZone?: string | undefined}) | undefined, title?: string | undefined, description?: (string | null) | undefined, attendees?: (Array | null) | undefined, status?: CalendarEventStatus | undefined}; export type PatchApiV2CalendarsConnectionsConnectionIdEventsEventIdArgs = {connectionId: string, eventId: string, calendarId?: string | undefined, Authorization: string, body: UpdateUnifiedCalendarEventInput}; export type PatchApiV2CalendarsConnectionsConnectionIdEventsEventIdOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const calendarEventVideoLocation = z.object({type: z.literal("video"), url: z.string(), label: z.string().nullable().optional(), password: z.string().nullable().optional(), meetingCode: z.string().nullable().optional(), accessCode: z.string().nullable().optional()}); export const calendarEventPhoneLocation = z.object({type: z.literal("phone"), url: z.string(), label: z.string().nullable().optional(), pin: z.string().nullable().optional(), password: z.string().nullable().optional(), accessCode: z.string().nullable().optional(), regionCode: z.string().nullable().optional()}); export const calendarEventSipLocation = z.object({type: z.literal("sip"), url: z.string(), label: z.string().nullable().optional(), pin: z.string().nullable().optional(), password: z.string().nullable().optional()}); export const calendarEventMoreLocation = z.object({type: z.literal("more"), url: z.string(), label: z.string().nullable().optional()}); export const calendarEventResponseStatus = z.enum(["accepted", "pending", "declined", "needsAction"]); export const calendarEventAttendee = z.object({email: z.string(), name: z.string().optional(), responseStatus: calendarEventResponseStatus.optional(), self: z.boolean().nullable().optional(), optional: z.boolean().nullable().optional(), host: z.boolean().nullable().optional()}); export const calendarEventStatus = z.enum(["accepted", "pending", "declined", "cancelled"]); export const calendarEventHost = z.object({email: z.string(), name: z.string().nullable().optional(), responseStatus: calendarEventResponseStatus.optional()}); export const calendarEventOwner = z.object({email: z.string(), name: z.string().nullable().optional()}); export const calendarSource = z.enum(["google", "office365", "apple"]); export const unifiedCalendarEventOutput = z.object({start: z.object({time: z.string().optional(), timeZone: z.string().optional()}), end: z.object({time: z.string().optional(), timeZone: z.string().optional()}), id: z.string(), title: z.string(), description: z.string().nullable().optional(), locations: z.array(z.discriminatedUnion("type", [calendarEventVideoLocation, calendarEventPhoneLocation, calendarEventSipLocation, calendarEventMoreLocation])).nullable().optional(), attendees: z.array(calendarEventAttendee).nullable().optional(), status: calendarEventStatus.optional(), hosts: z.array(calendarEventHost).nullable().optional(), calendarEventOwner: calendarEventOwner.nullable().optional(), source: calendarSource}); export const getUnifiedCalendarEventOutput = z.object({status: z.enum(["success", "error"]), data: unifiedCalendarEventOutput}); 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 }; /** * Update event for a connection * * PATCH /v2/calendars/connections/{connectionId}/events/{eventId} */ export const patchApiV2CalendarsConnectionsConnectionIdEventsEventId = async (args: PatchApiV2CalendarsConnectionsConnectionIdEventsEventIdArgs, options: PatchApiV2CalendarsConnectionsConnectionIdEventsEventIdOptions) => { 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.calendarId != null) query.append("calendarId", String(args.calendarId)) if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) const url = `${baseUrl.replace(/\/+$/, '')}/v2/calendars/connections/${encodeURIComponent(String(args.connectionId))}/events/${encodeURIComponent(String(args.eventId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(getUnifiedCalendarEventOutput, await res.json()) };