import {z} from 'zod' export type ContactBusinessAddressInfo = {country?: string | undefined, state?: string | undefined, city?: string | undefined, street?: string | undefined, zip?: string | undefined}; export type PronouncedNamePromptInfo = {id?: string | undefined, contentUri?: string | undefined, contentType?: ('audio/mpeg' | 'audio/wav') | undefined}; export type PronouncedNameInfo = {type?: ('Default' | 'TextToSpeech' | 'Recorded') | undefined, text?: string | undefined, prompt?: PronouncedNamePromptInfo | undefined}; export type ContactInfoCreationRequest = {firstName?: string | undefined, lastName?: string | undefined, company?: string | undefined, jobTitle?: string | undefined, email?: string | undefined, businessPhone?: string | undefined, mobilePhone?: string | undefined, businessAddress?: ContactBusinessAddressInfo | undefined, emailAsLoginName?: boolean | undefined, pronouncedName?: PronouncedNameInfo | undefined, department?: string | undefined}; export type CostCenterInfo = {id?: string | undefined, name?: string | undefined}; export type CustomFieldInfo = {id?: string | undefined, value?: string | undefined, displayName?: string | undefined}; export type ReferenceInfo = {ref?: string | undefined, type?: ('PartnerId' | 'CustomerDirectoryId') | undefined, refAccId?: string | undefined}; export type CountryInfoShortModel = {id?: string | undefined, uri?: string | undefined, name?: string | undefined, isoCode?: string | undefined, callingCode?: string | undefined}; export type TimezoneInfo = {id?: string | undefined, uri?: string | undefined, name?: string | undefined, description?: string | undefined, bias?: string | undefined}; export type RegionalLanguageInfo = {id?: string | undefined, localeCode?: string | undefined, name?: string | undefined}; export type GreetingLanguageInfo = {id?: string | undefined, localeCode?: string | undefined, name?: string | undefined}; export type FormattingLocaleInfo = {id?: string | undefined, localeCode?: string | undefined, name?: string | undefined}; export type RegionalSettings = {homeCountry?: CountryInfoShortModel | undefined, timezone?: TimezoneInfo | undefined, language?: RegionalLanguageInfo | undefined, greetingLanguage?: GreetingLanguageInfo | undefined, formattingLocale?: FormattingLocaleInfo | undefined, timeFormat?: ('12h' | '24h') | undefined}; export type SetupWizardStateForUpdateEnum = 'NotStarted' | 'Incomplete' | 'Completed'; export type OperatorInfo = {id?: string | undefined, uri?: string | undefined, extensionNumber?: string | undefined, name?: string | undefined}; export type SiteInfo = {id?: string | undefined, uri?: string | undefined, name?: string | undefined, extensionNumber?: string | undefined, callerIdName?: string | undefined, email?: string | undefined, businessAddress?: ContactBusinessAddressInfo | undefined, regionalSettings?: RegionalSettings | undefined, operator?: OperatorInfo | undefined, code?: string | undefined}; export type ExtensionStatusInfo = {comment?: string | undefined, reason?: ('SuspendedVoluntarily' | 'SuspendedInvoluntarily' | 'CancelledVoluntarily' | 'CancelledInvoluntarily') | undefined, till?: string | undefined}; export type ExtensionCreationRequest = {contact?: ContactInfoCreationRequest | undefined, extensionNumber?: string | undefined, costCenter?: CostCenterInfo | undefined, customFields?: Array | undefined, password?: string | undefined, references?: Array | undefined, regionalSettings?: RegionalSettings | undefined, partnerId?: string | undefined, ivrPin?: string | undefined, setupWizardState?: SetupWizardStateForUpdateEnum | undefined, site?: SiteInfo | undefined, status?: ('Enabled' | 'Disabled' | 'NotActivated' | 'Unassigned' | 'Frozen') | undefined, statusInfo?: ExtensionStatusInfo | undefined, type?: ('User' | 'VirtualUser' | 'DigitalUser' | 'FlexibleUser' | 'Department' | 'Announcement' | 'Voicemail' | 'SharedLinesGroup' | 'PagingOnly' | 'ParkLocation' | 'Limited') | undefined, hidden?: boolean | undefined}; export type CreateApiRestapiV10AccountAccountIdExtensionArgs = {accountId: string, body: ExtensionCreationRequest}; export type CreateApiRestapiV10AccountAccountIdExtensionOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const contactBusinessAddressInfo = z.object({country: z.string().optional(), state: z.string().optional(), city: z.string().optional(), street: z.string().optional(), zip: z.string().optional()}); export const pronouncedNamePromptInfo = z.object({id: z.string().optional(), contentUri: z.string().optional(), contentType: z.enum(["audio/mpeg", "audio/wav"]).optional()}); export const pronouncedNameInfo = z.object({type: z.enum(["Default", "TextToSpeech", "Recorded"]).optional(), text: z.string().optional(), prompt: pronouncedNamePromptInfo.optional()}); export const contactInfo = z.object({firstName: z.string().optional(), lastName: z.string().optional(), name: z.string().optional(), company: z.string().optional(), jobTitle: z.string().optional(), email: z.string().optional(), businessPhone: z.string().optional(), mobilePhone: z.string().optional(), businessAddress: contactBusinessAddressInfo.optional(), emailAsLoginName: z.boolean().optional(), pronouncedName: pronouncedNameInfo.optional(), department: z.string().optional()}); export const costCenterInfo = z.object({id: z.string().optional(), name: z.string().optional()}); export const customFieldInfo = z.object({id: z.string().optional(), value: z.string().optional(), displayName: z.string().optional()}); export const permissionInfoAdmin = z.object({enabled: z.boolean().optional()}); export const permissionInfoInt = z.object({enabled: z.boolean().optional()}); export const extensionPermissions = z.object({admin: permissionInfoAdmin.optional(), internationalCalling: permissionInfoInt.optional()}); export const profileImageInfoURI = z.object({uri: z.string().optional()}); export const profileImageInfo = z.object({uri: z.string(), etag: z.string().optional(), lastModified: z.string().optional(), contentType: z.string().optional(), scales: z.array(profileImageInfoURI).optional()}); export const referenceInfo = z.object({ref: z.string().optional(), type: z.enum(["PartnerId", "CustomerDirectoryId"]).optional(), refAccId: z.string().optional()}); 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 timezoneInfo = z.object({id: z.string().optional(), uri: z.string().optional(), name: z.string().optional(), description: z.string().optional(), bias: z.string().optional()}); export const regionalLanguageInfo = z.object({id: z.string().optional(), localeCode: z.string().optional(), name: z.string().optional()}); export const greetingLanguageInfo = z.object({id: z.string().optional(), localeCode: z.string().optional(), name: z.string().optional()}); export const formattingLocaleInfo = z.object({id: z.string().optional(), localeCode: z.string().optional(), name: z.string().optional()}); export const regionalSettings = z.object({homeCountry: countryInfoShortModel.optional(), timezone: timezoneInfo.optional(), language: regionalLanguageInfo.optional(), greetingLanguage: greetingLanguageInfo.optional(), formattingLocale: formattingLocaleInfo.optional(), timeFormat: z.enum(["12h", "24h"]).optional()}); export const extensionServiceFeatureInfo = z.object({enabled: z.boolean().optional(), featureName: z.enum(["AccountFederation", "Archiver", "AutomaticCallRecordingMute", "AutomaticInboundCallRecording", "AutomaticOutboundCallRecording", "BlockedMessageForwarding", "Calendar", "CallerIdControl", "CallForwarding", "CallPark", "CallParkLocations", "CallSupervision", "CallSwitch", "CallQualitySurvey", "Conferencing", "ConferencingNumber", "ConfigureDelegates", "DeveloperPortal", "DND", "DynamicConference", "EmergencyAddressAutoUpdate", "EmergencyCalling", "EncryptionAtRest", "ExternalDirectoryIntegration", "Fax", "FaxReceiving", "FreeSoftPhoneLines", "HDVoice", "HipaaCompliance", "Intercom", "InternationalCalling", "InternationalSMS", "LinkedSoftphoneLines", "MMS", "MobileVoipEmergencyCalling", "OnDemandCallRecording", "Pager", "PagerReceiving", "Paging", "PasswordAuth", "PromoMessage", "Reports", "Presence", "RCTeams", "RingOut", "SalesForce", "SharedLines", "SingleExtensionUI", "SiteCodes", "SMS", "SMSReceiving", "SoftPhoneUpdate", "TelephonySessions", "UserManagement", "VideoConferencing", "VoipCalling", "VoipCallingOnMobile", "Voicemail", "VoicemailToText", "WebPhone"]).optional(), reason: z.string().optional()}); export const setupWizardStateForUpdateEnum = z.enum(["NotStarted", "Incomplete", "Completed"]); export const provisioningSiteInfo = z.object({id: z.string().optional(), uri: z.string().optional(), name: z.string().optional(), code: z.string().optional()}); export const extensionStatusInfo = z.object({comment: z.string().optional(), reason: z.enum(["SuspendedVoluntarily", "SuspendedInvoluntarily", "CancelledVoluntarily", "CancelledInvoluntarily"]).optional(), till: z.string().optional()}); export const assignedCountryInfo = z.object({id: z.string().optional(), uri: z.string().optional(), isoCode: z.string().optional(), name: z.string().optional()}); export const extensionCreationResponse = z.object({id: z.number().int().optional(), uri: z.string().optional(), contact: contactInfo.optional(), costCenter: costCenterInfo.optional(), customFields: z.array(customFieldInfo).optional(), extensionNumber: z.string().optional(), name: z.string().optional(), partnerId: z.string().optional(), permissions: extensionPermissions.optional(), profileImage: profileImageInfo.optional(), references: z.array(referenceInfo).optional(), regionalSettings: regionalSettings.optional(), serviceFeatures: z.array(extensionServiceFeatureInfo).optional(), setupWizardState: setupWizardStateForUpdateEnum.optional(), site: provisioningSiteInfo.optional(), status: z.enum(["Enabled", "Disabled", "Frozen", "NotActivated", "Unassigned"]).optional(), statusInfo: extensionStatusInfo.optional(), type: z.enum(["User", "VirtualUser", "DigitalUser", "FlexibleUser", "Department", "Announcement", "Voicemail", "SharedLinesGroup", "PagingOnly", "ParkLocation", "Limited"]).optional(), hidden: z.boolean().optional(), assignedCountry: assignedCountryInfo.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 Extension * * POST /restapi/v1.0/account/{accountId}/extension */ export const createApiRestapiV10AccountAccountIdExtension = async (args: CreateApiRestapiV10AccountAccountIdExtensionArgs, options?: CreateApiRestapiV10AccountAccountIdExtensionOptions) => { 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(/\/+$/, '')}/restapi/v1.0/account/${encodeURIComponent(String(args.accountId))}/extension${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(extensionCreationResponse, await res.json()) };