import {z} from 'zod' export type ExtensionStatusInfo = {comment?: string | undefined, reason?: ('SuspendedVoluntarily' | 'SuspendedInvoluntarily' | 'CancelledVoluntarily' | 'CancelledInvoluntarily') | undefined, till?: string | undefined}; 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 ContactInfoUpdateRequest = {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 ExtensionCountryInfoRequest = {id?: string | undefined}; export type ExtensionTimezoneInfoRequest = {id?: string | undefined}; export type ExtensionLanguageInfoRequest = {id?: string | undefined}; export type ExtensionGreetingLanguageInfoRequest = {id?: string | undefined}; export type ExtensionFormattingLocaleInfoRequest = {id?: string | undefined}; export type ExtensionCurrencyInfoRequest = {id?: string | undefined}; export type ExtensionRegionalSettingRequest = {homeCountry?: ExtensionCountryInfoRequest | undefined, timezone?: ExtensionTimezoneInfoRequest | undefined, language?: ExtensionLanguageInfoRequest | undefined, greetingLanguage?: ExtensionGreetingLanguageInfoRequest | undefined, formattingLocale?: ExtensionFormattingLocaleInfoRequest | undefined, currency?: ExtensionCurrencyInfoRequest | undefined, timeFormat?: ('12h' | '24h') | undefined}; export type SetupWizardStateForUpdateEnum = 'NotStarted' | 'Incomplete' | 'Completed'; export type CallQueueInfoRequest = {slaGoal?: number | undefined, slaThresholdSeconds?: number | undefined, includeAbandonedCalls?: boolean | undefined, abandonedThresholdSeconds?: number | undefined}; export type UserTransitionInfo = {sendWelcomeEmailsToUsers?: boolean | undefined, sendWelcomeEmail?: boolean | undefined}; export type CostCenterInfo = {id?: string | undefined, name?: string | undefined}; export type CustomFieldInfo = {id?: string | undefined, value?: string | undefined, displayName?: string | undefined}; export type ProvisioningSiteInfo = {id?: string | undefined, uri?: string | undefined, name?: string | undefined, code?: string | undefined}; export type ReferenceInfo = {ref?: string | undefined, type?: ('PartnerId' | 'CustomerDirectoryId') | undefined, refAccId?: string | undefined}; export type ExtensionBulkUpdateInfo = {id?: string | undefined, status?: ('Disabled' | 'Enabled' | 'NotActivated' | 'Frozen') | undefined, statusInfo?: ExtensionStatusInfo | undefined, reason?: string | undefined, comment?: string | undefined, extensionNumber?: string | undefined, contact?: ContactInfoUpdateRequest | undefined, regionalSettings?: ExtensionRegionalSettingRequest | undefined, setupWizardState?: SetupWizardStateForUpdateEnum | undefined, partnerId?: string | undefined, ivrPin?: string | undefined, password?: string | undefined, callQueueInfo?: CallQueueInfoRequest | undefined, transition?: UserTransitionInfo | undefined, costCenter?: CostCenterInfo | undefined, customFields?: Array | undefined, hidden?: boolean | undefined, site?: ProvisioningSiteInfo | undefined, type?: ('User' | 'FaxUser' | 'VirtualUser' | 'DigitalUser' | 'Department' | 'Announcement' | 'Voicemail' | 'SharedLinesGroup' | 'PagingOnly' | 'IvrMenu' | 'ApplicationExtension' | 'ParkLocation' | 'DelegatedLinesGroup') | undefined, references?: Array | undefined}; export type ExtensionBulkUpdateRequest = {records: Array}; export type CreateApiRestapiV10AccountAccountIdExtensionBulkUpdateArgs = {accountId: string, body: ExtensionBulkUpdateRequest}; export type CreateApiRestapiV10AccountAccountIdExtensionBulkUpdateOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const errorEntity = z.object({errorCode: z.string().optional(), message: z.string().optional(), parameterName: z.string().optional(), parameterValue: z.string().optional()}); export const extensionUpdateShortResult = z.object({extensionId: z.string().optional(), status: z.enum(["Fail", "Success"]).optional(), errors: z.array(errorEntity).optional()}); export const extensionBulkUpdateTaskResult = z.object({affectedItems: z.array(extensionUpdateShortResult).optional(), errors: z.array(errorEntity).optional()}); export const extensionBulkUpdateTaskResource = z.object({uri: z.string(), id: z.string(), status: z.enum(["Accepted", "InProgress", "Completed", "Failed"]), creationTime: z.string(), lastModifiedTime: z.string(), result: extensionBulkUpdateTaskResult.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 Multiple Extensions * * POST /restapi/v1.0/account/{accountId}/extension-bulk-update */ export const createApiRestapiV10AccountAccountIdExtensionBulkUpdate = async (args: CreateApiRestapiV10AccountAccountIdExtensionBulkUpdateArgs, options?: CreateApiRestapiV10AccountAccountIdExtensionBulkUpdateOptions) => { 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-bulk-update${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(extensionBulkUpdateTaskResource, await res.json()) };