import {z} from 'zod' export type EventBusy = boolean | null; export type EventCapacity = number; export type EventConferencingRequest = {provider: 'Google Meet' | 'Zoom Meeting' | 'Microsoft Teams' | 'Teams for Business', autocreate: {conf_grant_id?: string | undefined, conf_settings?: {[key: string]: unknown} | undefined}} | {provider?: 'Google Meet' | undefined, details: {url: string, phone?: Array | undefined, pin?: string | undefined}} | {provider?: 'Zoom Meeting' | undefined, details: {url: string, meeting_code?: (string | null) | undefined, password?: (string | null) | undefined}} | {provider?: 'Microsoft Teams' | undefined, details: {url: string}} | {provider?: 'Teams for Business' | undefined, details: {url: string}} | {provider?: 'Skype for Consumer' | undefined, details: {url: string}} | {provider?: 'Skype for Business' | undefined, details: {url: string}} | {provider?: 'WebEx' | undefined, details: {url: string, password?: string | undefined, pin?: string | undefined, phone?: Array | undefined}} | {provider?: 'GoToMeeting' | undefined, details: {url: string, meeting_code?: string | undefined, password?: string | undefined, phone?: Array | undefined}} | Record; export type EventDescription = string; export type EventHideParticipants = boolean; export type EventLocation = string; export type Metadata = {[key: string]: string}; export type OnJoinMessage = {type: 'text', content: string, send_after_ms: number}; export type OnParticipantJoinMessage = {type: 'text', content: string, debounce_ms: number}; export type Messages = {on_join?: Array | undefined, on_participant_join?: Array | undefined}; export type MeetingSettings = {action_items?: boolean | undefined, action_items_settings?: ({custom_instructions?: string | undefined}) | undefined, audio_recording?: boolean | undefined, leave_after_silence_seconds?: number | undefined, summary?: boolean | undefined, summary_settings?: ({custom_instructions?: string | undefined}) | undefined, transcription?: boolean | undefined, video_recording?: boolean | undefined, transcription_settings?: ({expected_languages?: Array | undefined, fallback_language?: string | undefined, keywords?: Array | undefined, use_speaker_names_as_keywords?: boolean | undefined} | null) | undefined, messages?: Messages | undefined}; export type EventSync = {id?: string | undefined, meeting_settings?: MeetingSettings | undefined, name?: string | undefined}; export type EventParticipantsCreateUpdate = {comment?: string | undefined, email: string, name?: string | undefined, phone_number?: string | undefined}; export type EventResources = {email: string, name?: string | undefined}; export type EventRecurrence = Array; export type EventRemindersCreate = {use_default?: boolean | undefined, overrides?: (Array<{reminder_minutes?: number | undefined, reminder_method?: ('popup' | 'email' | 'display' | 'sound') | undefined}>) | undefined}; export type EventTitle = string; export type EventVisibility = 'default' | 'private' | 'public' | null; export type EventWhen = {time?: number | undefined, timezone?: string | undefined} | {start_time?: number | undefined, end_time?: number | undefined, start_timezone?: (string | null) | undefined, end_timezone?: (string | null) | undefined} | {date?: string | undefined} | {start_date?: string | undefined, end_date?: string | undefined}; export type EventCreate = {busy?: EventBusy | undefined, capacity?: EventCapacity | undefined, conferencing?: EventConferencingRequest | undefined, description?: EventDescription | undefined, hide_participants?: EventHideParticipants | undefined, location?: EventLocation | undefined, metadata?: Metadata | undefined, notetaker?: EventSync | undefined, participants?: Array | undefined, resources?: Array | undefined, recurrence?: EventRecurrence | undefined, reminders?: EventRemindersCreate | undefined, title?: EventTitle | undefined, visibility?: EventVisibility | undefined, when: EventWhen}; export type CreateApiV3GrantsGrantIdEventsArgs = {calendar_id: string, select?: string | undefined, notify_participants?: boolean | undefined, tentative_as_busy?: boolean | undefined, body: EventCreate}; export type CreateApiV3GrantsGrantIdEventsOptions = {baseUrl?: string | undefined, NYLASAPIKEY?: string | undefined, fetch?: typeof fetch | undefined}; export const eventCalendarId = z.string().nullable(); export const eventConferencingResponse = z.object({provider: z.enum(["Google Meet", "GoToMeeting", "Microsoft Teams", "Teams for Business", "Skype for Business", "Skype for Consumer", "WebEx", "Zoom Meeting", "unknown"]).optional(), details: z.object({url: z.string().optional(), meeting_code: z.string().optional(), password: z.string().optional(), pin: z.string().optional(), phone: z.array(z.string()).optional()}).optional(), autocreate: z.object({}).optional()}); export const eventCreatedAt = z.number().int().nullable(); export const grantId = z.string(); export const eventHtmlLink = z.string(); export const eventIcalUid = z.string().nullable(); export const eventId = z.string().min(1); export const eventIsOwner = z.boolean(); export const metadata = z.record(z.string(), z.string().max(500)); export const object = z.string(); export const organizer = z.object({name: z.string().optional(), email: z.string().optional()}); export const eventParticipants = z.array(z.object({comment: z.string().optional(), email: z.string().optional(), name: z.string().optional(), phone_number: z.string().optional(), status: z.enum(["yes", "no", "maybe", "noreply"]).optional()})); export const eventResources = z.object({email: z.string(), name: z.string().optional()}); export const eventReadOnly = z.boolean(); export const eventReminders = z.object({use_default: z.boolean().nullable().optional(), overrides: z.array(z.object({reminder_minutes: z.number().int().optional(), reminder_method: z.enum(["popup", "email", "display", "sound"]).optional()})).nullable().optional()}); export const eventRecurrence = z.array(z.string()); export const eventStatus = z.enum(["confirmed", "cancelled", "maybe"]); export const eventUpdatedAt = z.number().int().nullable(); export const eventVisibility = z.enum(["default", "private", "public"]).nullable(); export const eventWhenResponse = z.union([z.object({start_time: z.number().int().optional(), end_time: z.number().int().optional(), start_timezone: z.string().min(1).nullable().optional(), end_timezone: z.string().min(1).nullable().optional()}), z.object({date: z.string().optional()}), z.object({start_date: z.string().min(1).optional(), end_date: z.string().optional()})]).nullable(); export const onJoinMessage = z.object({type: z.literal("text"), content: z.string().min(1).max(1000), send_after_ms: z.number().int().gte(1).lte(600000)}); export const onParticipantJoinMessage = z.object({type: z.literal("text"), content: z.string().min(1).max(1000), debounce_ms: z.number().int().gte(1).lte(600000)}); export const messages = z.object({on_join: z.array(onJoinMessage).optional(), on_participant_join: z.array(onParticipantJoinMessage).optional()}); export const meetingSettings = z.object({action_items: z.boolean().optional(), action_items_settings: z.object({custom_instructions: z.string().optional()}).optional(), audio_recording: z.boolean().optional(), leave_after_silence_seconds: z.number().int().gte(10).lte(3600).optional(), summary: z.boolean().optional(), summary_settings: z.object({custom_instructions: z.string().optional()}).optional(), transcription: z.boolean().optional(), video_recording: z.boolean().optional(), transcription_settings: z.object({expected_languages: z.array(z.string()).optional(), fallback_language: z.string().optional(), keywords: z.array(z.string().max(200)).optional(), use_speaker_names_as_keywords: z.boolean().optional()}).nullable().optional(), messages: messages.optional()}); export const eventSync = z.object({id: z.string().optional(), meeting_settings: meetingSettings.optional(), name: z.string().optional()}); export const createApiV3GrantsGrantIdEventsResponse = z.object({request_id: z.string().optional(), data: z.object({busy: z.boolean().optional(), calendar_id: eventCalendarId.optional(), conferencing: eventConferencingResponse.optional(), created_at: eventCreatedAt.optional(), description: z.string().nullable().optional(), text_description: z.string().nullable().optional(), hide_participants: z.boolean().optional(), grant_id: grantId.optional(), html_link: eventHtmlLink.optional(), ical_uid: eventIcalUid.optional(), id: eventId.optional(), is_owner: eventIsOwner.optional(), location: z.string().nullable().optional(), master_event_id: z.string().nullable().optional(), metadata: metadata.optional(), object: object.optional(), organizer: organizer.optional(), participants: eventParticipants.optional(), resources: z.array(eventResources).optional(), read_only: eventReadOnly.optional(), reminders: eventReminders.optional(), recurrence: eventRecurrence.optional(), status: eventStatus.optional(), title: z.string().min(1).max(1024).optional(), updated_at: eventUpdatedAt.optional(), visibility: eventVisibility.optional(), when: eventWhenResponse.optional(), original_start_time: z.number().int().optional(), notetaker: eventSync.optional()}).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 }; /** * Create an event * * POST /v3/grants/{grant_id}/events * * Also accepts auth: ACCESS_TOKEN */ export const createApiV3GrantsGrantIdEvents = async (args: CreateApiV3GrantsGrantIdEventsArgs, options?: CreateApiV3GrantsGrantIdEventsOptions) => { const {baseUrl = "https://api.us.nylas.com", fetch: fetchFn = fetch, NYLASAPIKEY} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.calendar_id != null) query.append("calendar_id", String(args.calendar_id)) if (args.select != null) query.append("select", String(args.select)) if (args.notify_participants != null) query.append("notify_participants", String(args.notify_participants)) if (args.tentative_as_busy != null) query.append("tentative_as_busy", String(args.tentative_as_busy)) if (NYLASAPIKEY !== undefined) headers.set('authorization', `Bearer ${NYLASAPIKEY}`) const url = `${baseUrl.replace(/\/+$/, '')}/v3/grants/${encodeURIComponent(String(args.grant_id))}/events${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(createApiV3GrantsGrantIdEventsResponse, await res.json()) };