import {z} from 'zod' export type UpdateConferenceParticipantRequest = {end_conference_on_exit?: boolean | undefined, soft_end_conference_on_exit?: boolean | undefined, beep_enabled?: ('always' | 'never' | 'on_enter' | 'on_exit') | undefined}; export type PatchApiConferencesIdParticipantsParticipantIdArgs = {id: string, participant_id: string, body: UpdateConferenceParticipantRequest}; export type PatchApiConferencesIdParticipantsParticipantIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const conferenceParticipant = z.object({id: z.string().optional(), call_control_id: z.string().optional(), call_leg_id: z.string().optional(), conference_id: z.string().optional(), label: z.string().optional(), status: z.enum(["joining", "joined", "left"]).optional(), muted: z.boolean().optional(), on_hold: z.boolean().optional(), whisper_call_control_ids: z.array(z.string()).optional(), created_at: z.string().optional(), updated_at: z.string().optional(), end_conference_on_exit: z.boolean().optional(), soft_end_conference_on_exit: z.boolean().optional()}); export const conferenceParticipantResource = z.object({data: conferenceParticipant.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 }; /** * Update a conference participant * * PATCH /conferences/{id}/participants/{participant_id} */ export const patchApiConferencesIdParticipantsParticipantId = async (args: PatchApiConferencesIdParticipantsParticipantIdArgs, options?: PatchApiConferencesIdParticipantsParticipantIdOptions) => { const {baseUrl = "https://api.telnyx.com/v2", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/conferences/${encodeURIComponent(String(args.id))}/participants/${encodeURIComponent(String(args.participant_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(conferenceParticipantResource, await res.json()) };