import {z} from 'zod' export type EventRecurrenceInfo = {schedule?: ('None' | 'Day' | 'Weekday' | 'Week' | 'Month' | 'Year') | undefined, endingCondition?: ('None' | 'Count' | 'Date') | undefined, endingAfter?: number | undefined, endingOn?: string | undefined}; export type TMCreateEventRequest = {id?: string | undefined, creatorId?: string | undefined, title: string, startTime: string, endTime: string, allDay?: boolean | undefined, recurrence?: EventRecurrenceInfo | undefined, color?: ('Black' | 'Red' | 'Orange' | 'Yellow' | 'Green' | 'Blue' | 'Purple' | 'Magenta') | undefined, location?: string | undefined, description?: string | undefined}; export type CreateApiTeamMessagingV1GroupsGroupIdEventsArgs = {groupId: string, body: TMCreateEventRequest}; export type CreateApiTeamMessagingV1GroupsGroupIdEventsOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const eventRecurrenceInfo = z.object({schedule: z.enum(["None", "Day", "Weekday", "Week", "Month", "Year"]).optional(), endingCondition: z.enum(["None", "Count", "Date"]).optional(), endingAfter: z.number().int().optional(), endingOn: z.string().optional()}); export const tMEventInfo = z.object({id: z.string().optional(), creatorId: z.string().optional(), title: z.string().optional(), startTime: z.string().optional(), endTime: z.string().optional(), allDay: z.boolean().optional(), recurrence: eventRecurrenceInfo.optional(), color: z.enum(["Black", "Red", "Orange", "Yellow", "Green", "Blue", "Purple", "Magenta"]).optional(), location: z.string().optional(), description: z.string().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 Event by Group ID * * POST /team-messaging/v1/groups/{groupId}/events */ export const createApiTeamMessagingV1GroupsGroupIdEvents = async (args: CreateApiTeamMessagingV1GroupsGroupIdEventsArgs, options?: CreateApiTeamMessagingV1GroupsGroupIdEventsOptions) => { const {baseUrl = "https://platform.ringcentral.com", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/team-messaging/v1/groups/${encodeURIComponent(String(args.groupId))}/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(tMEventInfo, await res.json()) };