import {z} from 'zod' export type WcsWebinarSettingsModel = {recordingEnabled?: boolean | undefined, autoRecord?: boolean | undefined, recordingSharingEnabled?: boolean | undefined, recordingDownloadEnabled?: boolean | undefined, recordingDeletionEnabled?: boolean | undefined, pastSessionDeletionEnabled?: boolean | undefined, panelistWaitingRoom?: boolean | undefined, panelistVideoEnabled?: boolean | undefined, panelistScreenSharingEnabled?: boolean | undefined, panelistMuteControlEnabled?: boolean | undefined, panelistAuthentication?: ('Guest' | 'AuthenticatedUser' | 'AuthenticatedCoworker') | undefined, attendeeAuthentication?: ('Guest' | 'AuthenticatedUser' | 'AuthenticatedCoworker') | undefined, artifactsAccessAuthentication?: ('Guest' | 'AuthenticatedUser' | 'AuthenticatedCoworker') | undefined, pstnEnabled?: boolean | undefined, password?: string | undefined, qnaEnabled?: boolean | undefined, qnaAnonymousEnabled?: boolean | undefined, pollsEnabled?: boolean | undefined, pollsAnonymousEnabled?: boolean | undefined, registrationEnabled?: boolean | undefined, postWebinarRedirectUri?: string | undefined, externalLivestreamEnabled?: boolean | undefined, moderatedQnaEnabled?: boolean | undefined}; export type RcwDomainUserModel = {userId: string, accountId: string, domain: 'pbx' | 'ilm'}; export type RcwLinkedUserModel = {linkedUser?: RcwDomainUserModel | undefined}; export type WebinarCreationRequest = {title: string, description?: string | undefined, settings?: WcsWebinarSettingsModel | undefined, host?: RcwLinkedUserModel | undefined}; export type CreateApiWebinarConfigurationV1WebinarsArgs = {body: WebinarCreationRequest}; export type CreateApiWebinarConfigurationV1WebinarsOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const wcsWebinarSettingsModel = z.object({recordingEnabled: z.boolean().optional(), autoRecord: z.boolean().optional(), recordingSharingEnabled: z.boolean().optional(), recordingDownloadEnabled: z.boolean().optional(), recordingDeletionEnabled: z.boolean().optional(), pastSessionDeletionEnabled: z.boolean().optional(), panelistWaitingRoom: z.boolean().optional(), panelistVideoEnabled: z.boolean().optional(), panelistScreenSharingEnabled: z.boolean().optional(), panelistMuteControlEnabled: z.boolean().optional(), panelistAuthentication: z.enum(["Guest", "AuthenticatedUser", "AuthenticatedCoworker"]).optional(), attendeeAuthentication: z.enum(["Guest", "AuthenticatedUser", "AuthenticatedCoworker"]).optional(), artifactsAccessAuthentication: z.enum(["Guest", "AuthenticatedUser", "AuthenticatedCoworker"]).optional(), pstnEnabled: z.boolean().optional(), password: z.string().max(64).optional(), qnaEnabled: z.boolean().optional(), qnaAnonymousEnabled: z.boolean().optional(), pollsEnabled: z.boolean().optional(), pollsAnonymousEnabled: z.boolean().optional(), registrationEnabled: z.boolean().optional(), postWebinarRedirectUri: z.string().optional(), externalLivestreamEnabled: z.boolean().optional(), moderatedQnaEnabled: z.boolean().optional()}); export const rcwDomainUserModel = z.object({userId: z.string().max(256), accountId: z.string().max(256), domain: z.enum(["pbx", "ilm"])}); export const wcsHostModel = z.object({entitled: z.boolean(), userId: z.string().max(256), accountId: z.string().max(256), linkedUser: rcwDomainUserModel.optional()}); export const wcsWebinarResource = z.object({id: z.string().min(1).max(20).optional(), creationTime: z.string(), lastModifiedTime: z.string(), title: z.string().min(1).max(512).optional(), description: z.string().max(4096).optional(), settings: wcsWebinarSettingsModel.optional(), host: wcsHostModel}); 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 * * POST /webinar/configuration/v1/webinars */ export const createApiWebinarConfigurationV1Webinars = async (args: CreateApiWebinarConfigurationV1WebinarsArgs, options?: CreateApiWebinarConfigurationV1WebinarsOptions) => { 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${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(wcsWebinarResource, await res.json()) };