import {z} from 'zod' export type GetApiRestapiV10AccountAccountIdExtensionExtensionIdConferencingArgs = {accountId: string, extensionId: string, countryId?: string | undefined}; export type GetApiRestapiV10AccountAccountIdExtensionExtensionIdConferencingOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const countryInfoShortModel = z.object({id: z.string().optional(), uri: z.string().optional(), name: z.string().optional(), isoCode: z.string().optional(), callingCode: z.string().optional()}); export const phoneNumberInfoConferencing = z.object({country: countryInfoShortModel.optional(), default: z.boolean().optional(), hasGreeting: z.boolean().optional(), location: z.string().optional(), phoneNumber: z.string().optional(), premium: z.boolean().optional()}); export const getConferencingInfoResponse = z.object({uri: z.string().optional(), allowJoinBeforeHost: z.boolean().optional(), hostCode: z.string().optional(), mode: z.string().optional(), participantCode: z.string().optional(), phoneNumber: z.string().optional(), supportUri: z.string().optional(), tapToJoinUri: z.string().optional(), phoneNumbers: z.array(phoneNumberInfoConferencing).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 }; /** * Get User Conferencing Settings * * GET /restapi/v1.0/account/{accountId}/extension/{extensionId}/conferencing */ export const getApiRestapiV10AccountAccountIdExtensionExtensionIdConferencing = async (args: GetApiRestapiV10AccountAccountIdExtensionExtensionIdConferencingArgs, options?: GetApiRestapiV10AccountAccountIdExtensionExtensionIdConferencingOptions) => { const {baseUrl = "https://platform.ringcentral.com", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.countryId != null) query.append("countryId", String(args.countryId)) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/restapi/v1.0/account/${encodeURIComponent(String(args.accountId))}/extension/${encodeURIComponent(String(args.extensionId))}/conferencing${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(getConferencingInfoResponse, await res.json()) };