import {z} from 'zod' export type GetApiApiV1CalendarsCalendarIdEventsEventIdArgs = {account_id: string, event_id: string, calendar_id: string}; export type GetApiApiV1CalendarsCalendarIdEventsEventIdOptions = {baseUrl?: string | undefined, AccessToken?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiV1CalendarsCalendarIdEventsEventIdResponse = z.object({object: z.literal("CalendarEvent"), id: z.string(), ical_uid: z.string().optional(), master_event_id: z.string().optional(), calendar_id: z.string(), created_at: z.string(), updated_at: z.string(), title: z.string(), body: z.string().optional(), location: z.string().optional(), is_cancelled: z.boolean(), is_all_day: z.boolean(), is_attendees_list_hidden: z.boolean(), attendees: z.array(z.object({email: z.string(), display_name: z.string().optional(), comment: z.string().optional(), is_organizer: z.boolean(), is_optional: z.boolean(), is_resource: z.boolean(), type: z.union([z.literal("required"), z.literal("optional"), z.literal("resource")]), response_status: z.union([z.literal("yes"), z.literal("no"), z.literal("maybe"), z.literal("noreply")])})).optional(), start: z.union([z.object({date_time: z.string(), time_zone: z.string()}), z.object({date: z.string()})]), end: z.union([z.object({date_time: z.string(), time_zone: z.string()}), z.object({date: z.string()})]), recurrence: z.array(z.string()).optional(), organizer: z.object({email: z.string(), display_name: z.string().optional()}), conference: z.object({provider: z.enum(["google_meet", "zoom", "teams", "unknown"]), conference_id: z.string().optional(), url: z.string().optional()}).optional(), visibility: z.union([z.literal("public"), z.literal("private")]), transparency: z.union([z.literal("opaque"), z.literal("transparent")]), event_type: z.string(), guests_can_modify: z.boolean().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 }; /** * Retrieve an event * * GET /api/v1/calendars/{calendar_id}/events/{event_id} */ export const getApiApiV1CalendarsCalendarIdEventsEventId = async (args: GetApiApiV1CalendarsCalendarIdEventsEventIdArgs, options?: GetApiApiV1CalendarsCalendarIdEventsEventIdOptions) => { const {baseUrl = "https://api1.unipile.com:13111", fetch: fetchFn = fetch, AccessToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.account_id != null) query.append("account_id", String(args.account_id)) if (AccessToken !== undefined) headers.set("X-API-KEY", AccessToken) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/calendars/${encodeURIComponent(String(args.calendar_id))}/events/${encodeURIComponent(String(args.event_id))}${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(getApiApiV1CalendarsCalendarIdEventsEventIdResponse, await res.json()) };