import {z} from 'zod' export type GetApiV2CalendarsCalendarEventEventUidArgs = {calendar: 'google', eventUid: string, Authorization: string}; export type GetApiV2CalendarsCalendarEventEventUidOptions = {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 }; /** * Get meeting details from calendar * * GET /v2/calendars/{calendar}/event/{eventUid} */ export const getApiV2CalendarsCalendarEventEventUid = async (args: GetApiV2CalendarsCalendarEventEventUidArgs, options: GetApiV2CalendarsCalendarEventEventUidOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) const url = `${baseUrl.replace(/\/+$/, '')}/v2/calendars/${encodeURIComponent(String(args.calendar))}/event/${encodeURIComponent(String(args.eventUid))}${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(getUnifiedCalendarEventOutput, await res.json()) };