import {z} from 'zod' export type WcsSessionStatusModel = 'Scheduled' | 'Active' | 'Finished'; export type WcsSessionWithLocaleCodeModel = {scheduledStartTime: string, scheduledDuration: number, timeZone: string, localizedTimeZoneDescription?: string | undefined, panelJoinTimeOffset?: number | undefined, title?: string | undefined, description?: string | undefined, status?: WcsSessionStatusModel | undefined, hostJoinUri?: string | undefined, localeCode?: string | undefined}; export type CreateApiWebinarConfigurationV1WebinarsWebinarIdSessionsArgs = {body: WcsSessionWithLocaleCodeModel}; export type CreateApiWebinarConfigurationV1WebinarsWebinarIdSessionsOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const wcsSessionStatusModel = z.enum(["Scheduled", "Active", "Finished"]); export const wcsSessionResource = z.object({id: z.string().min(1).max(20).optional(), creationTime: z.string(), lastModifiedTime: z.string(), scheduledStartTime: z.string(), scheduledDuration: z.number().int().gte(30).lte(43200), timeZone: z.string().min(3).max(64), localizedTimeZoneDescription: z.string().optional(), panelJoinTimeOffset: z.number().int().gte(0).optional(), title: z.string().max(512).optional(), description: z.string().max(4096).optional(), status: wcsSessionStatusModel.optional(), hostJoinUri: z.string().min(5).max(256).optional(), localeCode: z.string().min(2).max(8).optional(), videoBridgeId: z.string().optional(), videoBridgePassword: z.string().optional(), videoBridgePstnPassword: z.string().optional(), attendeeJoinUri: z.string().min(5).max(256).optional(), hasUnsentInvites: 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 }; /** * Create Webinar Session * * POST /webinar/configuration/v1/webinars/{webinarId}/sessions */ export const createApiWebinarConfigurationV1WebinarsWebinarIdSessions = async (args: CreateApiWebinarConfigurationV1WebinarsWebinarIdSessionsArgs, options?: CreateApiWebinarConfigurationV1WebinarsWebinarIdSessionsOptions) => { 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(/\/+$/, '')}/webinar/configuration/v1/webinars/${encodeURIComponent(String(args.webinarId))}/sessions${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(wcsSessionResource, await res.json()) };