import {z} from 'zod' export type RcwRoleEnum = 'Panelist' | 'CoHost' | 'Host' | 'Attendee'; export type GetApiWebinarHistoryV1WebinarsWebinarIdSessionsSessionIdParticipantsArgs = {webinarId: string, sessionId: string, role?: Array | undefined, originalRole?: Array | undefined, perPage?: number | undefined, pageToken?: string | undefined}; export type GetApiWebinarHistoryV1WebinarsWebinarIdSessionsSessionIdParticipantsOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const rcwRoleEnum = z.enum(["Panelist", "CoHost", "Host", "Attendee"]); export const rcwDomainUserModel = z.object({userId: z.string().max(256), accountId: z.string().max(256), domain: z.enum(["pbx", "ilm"])}); export const rcwEmailModel = z.string().min(1).max(256); export const participantExtendedModel = z.object({id: z.string().min(1).max(20).optional(), firstName: z.string().max(64).optional(), lastName: z.string().max(64).optional(), role: rcwRoleEnum, originalRole: rcwRoleEnum, linkedUser: rcwDomainUserModel.optional(), avatarToken: z.string().optional(), type: z.enum(["User", "Room"]), email: rcwEmailModel.optional(), qnaBlocked: z.boolean().optional(), joinTime: z.string().optional(), leaveTime: z.string().optional(), wasEjected: z.boolean().optional(), inviteeId: z.string().optional(), registrantId: z.string().optional(), uniqueUserHash: z.string().optional()}); export const rcwPagingModel = z.object({perPage: z.number().int().gte(1).lte(1000), pageToken: z.string(), nextPageToken: z.string().optional(), previousPageToken: z.string().optional()}); export const participantListResource = z.object({records: z.array(participantExtendedModel), paging: rcwPagingModel}); 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 }; /** * List Session Participants * * GET /webinar/history/v1/webinars/{webinarId}/sessions/{sessionId}/participants */ export const getApiWebinarHistoryV1WebinarsWebinarIdSessionsSessionIdParticipants = async (args: GetApiWebinarHistoryV1WebinarsWebinarIdSessionsSessionIdParticipantsArgs, options?: GetApiWebinarHistoryV1WebinarsWebinarIdSessionsSessionIdParticipantsOptions) => { const {baseUrl = "https://platform.ringcentral.com", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") for (const item of args.role ?? []) query.append("role", String(item)) for (const item of args.originalRole ?? []) query.append("originalRole", String(item)) if (args.perPage != null) query.append("perPage", String(args.perPage)) if (args.pageToken != null) query.append("pageToken", String(args.pageToken)) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/webinar/history/v1/webinars/${encodeURIComponent(String(args.webinarId))}/sessions/${encodeURIComponent(String(args.sessionId))}/participants${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(participantListResource, await res.json()) };