import {z} from 'zod' export type BridgePstnPins = {host?: string | undefined, participant?: string | undefined}; export type WebPin = string; export type BridgePins = {pstn?: BridgePstnPins | undefined, web?: WebPin | undefined}; export type BridgeRequestSecurity = {passwordProtected?: boolean | undefined, password?: string | undefined, noGuests?: boolean | undefined, sameAccount?: boolean | undefined, e2ee?: boolean | undefined}; export type BridgeJoinPstnPreferences = {promptAnnouncement?: boolean | undefined, promptParticipants?: boolean | undefined}; export type BridgeJoinPreferences = {audioMuted?: boolean | undefined, videoMuted?: boolean | undefined, waitingRoomRequired?: ('Nobody' | 'Everybody' | 'GuestsOnly' | 'OtherAccount') | undefined, pstn?: BridgeJoinPstnPreferences | undefined}; export type EveryoneCanControl = {enabled?: boolean | undefined, locked?: boolean | undefined}; export type AutoShared = {enabled?: boolean | undefined, locked?: boolean | undefined}; export type RecordingsPreferences = {everyoneCanControl?: EveryoneCanControl | undefined, autoShared?: AutoShared | undefined}; export type BridgePreferences = {join?: BridgeJoinPreferences | undefined, playTones?: ('On' | 'Off' | 'ExitOnly' | 'EnterOnly') | undefined, musicOnHold?: boolean | undefined, joinBeforeHost?: boolean | undefined, screenSharing?: boolean | undefined, recordingsMode?: ('Auto' | 'ForceAuto' | 'User') | undefined, transcriptionsMode?: ('Auto' | 'ForceAuto' | 'User') | undefined, recordings?: RecordingsPreferences | undefined, allowEveryoneTranscribeMeetings?: boolean | undefined}; export type CreateBridgeRequest = {name?: string | undefined, type?: ('Instant' | 'Scheduled' | 'PMI') | undefined, pins?: BridgePins | undefined, security?: BridgeRequestSecurity | undefined, preferences?: BridgePreferences | undefined}; export type CreateApiRcvideoV2AccountAccountIdExtensionExtensionIdBridgesArgs = {accountId: string, extensionId: string, body: CreateBridgeRequest}; export type CreateApiRcvideoV2AccountAccountIdExtensionExtensionIdBridgesOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const user = z.object({accountId: z.string(), extensionId: z.string()}); export const bridgePstnPins = z.object({host: z.string().optional(), participant: z.string().optional()}); export const webPin = z.string(); export const bridgePinsWithAliases = z.object({pstn: bridgePstnPins.optional(), web: webPin.optional(), aliases: z.array(z.string()).optional()}); export const bridgeResponseSecurityPassword = z.object({plainText: z.string().optional(), pstn: z.string().optional(), joinQuery: z.string().optional()}); export const bridgeResponseSecurity = z.object({passwordProtected: z.boolean().optional(), password: bridgeResponseSecurityPassword.optional(), noGuests: z.boolean().optional(), sameAccount: z.boolean().optional(), e2ee: z.boolean().optional()}); export const bridgeJoinPstnPreferences = z.object({promptAnnouncement: z.boolean().optional(), promptParticipants: z.boolean().optional()}); export const bridgeJoinPreferences = z.object({audioMuted: z.boolean().optional(), videoMuted: z.boolean().optional(), waitingRoomRequired: z.enum(["Nobody", "Everybody", "GuestsOnly", "OtherAccount"]).optional(), pstn: bridgeJoinPstnPreferences.optional()}); export const everyoneCanControl = z.object({enabled: z.boolean().optional(), locked: z.boolean().optional()}); export const autoShared = z.object({enabled: z.boolean().optional(), locked: z.boolean().optional()}); export const recordingsPreferences = z.object({everyoneCanControl: everyoneCanControl.optional(), autoShared: autoShared.optional()}); export const bridgePreferences = z.object({join: bridgeJoinPreferences.optional(), playTones: z.enum(["On", "Off", "ExitOnly", "EnterOnly"]).optional(), musicOnHold: z.boolean().optional(), joinBeforeHost: z.boolean().optional(), screenSharing: z.boolean().optional(), recordingsMode: z.enum(["Auto", "ForceAuto", "User"]).optional(), transcriptionsMode: z.enum(["Auto", "ForceAuto", "User"]).optional(), recordings: recordingsPreferences.optional(), allowEveryoneTranscribeMeetings: z.boolean().optional()}); export const bridgeDiscovery = z.object({web: z.string().optional()}); export const bridgeResponse = z.object({id: z.string().optional(), name: z.string().optional(), type: z.enum(["Instant", "Scheduled", "PMI"]).optional(), host: user.optional(), pins: bridgePinsWithAliases.optional(), security: bridgeResponseSecurity.optional(), preferences: bridgePreferences.optional(), discovery: bridgeDiscovery.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 Bridge * * POST /rcvideo/v2/account/{accountId}/extension/{extensionId}/bridges */ export const createApiRcvideoV2AccountAccountIdExtensionExtensionIdBridges = async (args: CreateApiRcvideoV2AccountAccountIdExtensionExtensionIdBridgesArgs, options?: CreateApiRcvideoV2AccountAccountIdExtensionExtensionIdBridgesOptions) => { 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(/\/+$/, '')}/rcvideo/v2/account/${encodeURIComponent(String(args.accountId))}/extension/${encodeURIComponent(String(args.extensionId))}/bridges${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(bridgeResponse, await res.json()) };