import {z} from 'zod' export type GetApiRoomsRoomIdSessionsArgs = {room_id: string, include_participants?: boolean | undefined, filter?: ({date_created_at?: ({eq?: string | undefined, gte?: string | undefined, lte?: string | undefined}) | undefined, date_updated_at?: ({eq?: string | undefined, gte?: string | undefined, lte?: string | undefined}) | undefined, date_ended_at?: ({eq?: string | undefined, gte?: string | undefined, lte?: string | undefined}) | undefined, active?: boolean | undefined}) | undefined, page?: ({size?: number | undefined, number?: number | undefined}) | undefined}; export type GetApiRoomsRoomIdSessionsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const roomParticipant = z.object({id: z.string().optional(), session_id: z.string().optional(), context: z.string().optional(), joined_at: z.string().optional(), updated_at: z.string().optional(), left_at: z.string().optional(), record_type: z.string().optional()}); export const roomSession = z.object({id: z.string().optional(), room_id: z.string().optional(), active: z.boolean().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), ended_at: z.string().optional(), participants: z.array(roomParticipant).optional(), record_type: z.string().optional()}); export const paginationMeta = z.object({total_pages: z.number().int().optional(), total_results: z.number().int().optional(), page_number: z.number().int().optional(), page_size: z.number().int().optional()}); export const getApiRoomsRoomIdSessionsResponse = z.object({data: z.array(roomSession).optional(), meta: paginationMeta.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 }; /** * View a list of room sessions. * * GET /rooms/{room_id}/sessions */ export const getApiRoomsRoomIdSessions = async (args: GetApiRoomsRoomIdSessionsArgs, options?: GetApiRoomsRoomIdSessionsOptions) => { const {baseUrl = "https://api.telnyx.com/v2", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.include_participants != null) query.append("include_participants", String(args.include_participants)) if (args.filter != null) query.append("filter", JSON.stringify(args.filter)) if (args.page != null) query.append("page", JSON.stringify(args.page)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/rooms/${encodeURIComponent(String(args.room_id))}/sessions${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(getApiRoomsRoomIdSessionsResponse, await res.json()) };