import {z} from 'zod' export type RcwEmailModel = string; export type FixedAnswerModel = {questionId: string, answerIds: Array}; export type VariableAnswerModel = {questionId: string, answerText: string}; export type RegAnswerModel = FixedAnswerModel | VariableAnswerModel; export type RegistrantBaseModelWithQuestionnaire = {firstName: string, lastName: string, email: RcwEmailModel, joinUri?: string | undefined, cancellationUri?: string | undefined, registeredPostWebinar?: (boolean | null) | undefined, visitorId?: string | undefined, externalId?: string | undefined, registrationTime?: string | undefined, ipAddress?: string | undefined, source?: string | undefined, participantId?: string | undefined, questionnaire?: Array | undefined}; export type CreateApiWebinarRegistrationV1SessionsSessionIdRegistrantsArgs = {sessionId: string, body: RegistrantBaseModelWithQuestionnaire}; export type CreateApiWebinarRegistrationV1SessionsSessionIdRegistrantsOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const rcwEmailModel = z.string().min(1).max(256); export const fixedAnswerModel = z.object({questionId: z.string(), answerIds: z.array(z.string())}); export const variableAnswerModel = z.object({questionId: z.string(), answerText: z.string()}); export const regAnswerModel = z.union([fixedAnswerModel, variableAnswerModel]); export const registrantModelResponsePostWithQuestionnaire = z.object({id: z.string().min(1).max(20).optional(), creationTime: z.string(), lastModifiedTime: z.string(), firstName: z.string().max(64), lastName: z.string().max(64), email: rcwEmailModel, joinUri: z.string().min(5).max(256).optional(), cancellationUri: z.string().min(5).max(256).optional(), registeredPostWebinar: z.boolean().nullable().optional(), visitorId: z.string().optional(), externalId: z.string().optional(), registrationTime: z.string().optional(), ipAddress: z.string().optional(), source: z.string().optional(), participantId: z.string().optional(), questionnaire: z.array(regAnswerModel).optional(), icalendarSequence: z.number().int().gte(0).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 Registrant * * POST /webinar/registration/v1/sessions/{sessionId}/registrants */ export const createApiWebinarRegistrationV1SessionsSessionIdRegistrants = async (args: CreateApiWebinarRegistrationV1SessionsSessionIdRegistrantsArgs, options?: CreateApiWebinarRegistrationV1SessionsSessionIdRegistrantsOptions) => { 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/registration/v1/sessions/${encodeURIComponent(String(args.sessionId))}/registrants${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(registrantModelResponsePostWithQuestionnaire, await res.json()) };