import {z} from 'zod' export type CallingPlanX = {id?: string | undefined, referenceId?: string | undefined, referenceType?: ('SIP_TRUNK' | 'END_USER' | 'IVR' | 'ACCOUNT' | 'SPECIALTY_LINE' | 'CONTACT_CENTER') | undefined, callingPlanProductId?: string | undefined, endDate?: string | undefined, startDate?: string | undefined, planMinutes?: number | undefined, secondsRemaining?: number | undefined}; export type ProvisioningRequestX = {id?: string | undefined, requestDate?: string | undefined, httpStatus?: number | undefined, deviceId?: string | undefined, ipAddress?: string | undefined, userAgent?: string | undefined}; export type DeviceX = {id: string, deviceTypeId: string, accountId: string, partitionId: string, macAddress?: string | undefined, deviceName: string, emergencyNumber?: string | undefined, emergencyNumberReservationId?: string | undefined, faxEnabled: boolean, lineNumber: number, userId: string, sipPassword?: string | undefined, sipUsername?: string | undefined, zipcode?: string | undefined, state?: string | undefined, lineType?: ('Line' | 'AdvancedSharedLine' | 'ReferencedUser' | 'IntercomLine' | 'PresenceBlfUser' | 'SpeedDialUser' | 'SpeedDialTn' | 'CallParkingSpot' | 'SipPaging' | 'Custom') | undefined, referenceId?: string | undefined, provisioningRequest?: ProvisioningRequestX | undefined}; export type CallerIdConfigX = {callerIdNumber?: string | undefined, externalCallerIdVisible: boolean, extensionCallerIdVisible: boolean, callerIdNumberReservationId?: string | undefined, callerIdName?: string | undefined}; export type CallHandlingX = {type?: ('Forward' | 'Voicemail' | 'Busy') | undefined, forwardToNumber?: string | undefined, description?: string | undefined}; export type CallHandlingWithTimeoutX = {type?: ('Forward' | 'Voicemail' | 'Busy' | 'RingForever') | undefined, timeout?: number | undefined, forwardToNumber?: string | undefined, description?: string | undefined}; export type RingPhoneCallHandlingX = {busyCallHandling?: CallHandlingX | undefined, noAnswerCallHandling?: CallHandlingWithTimeoutX | undefined, unregisteredCallHandling?: CallHandlingX | undefined}; export type SimultaneousRingEndpointX = {toNumber?: string | undefined, ringDelay?: number | undefined, ringDuration?: number | undefined, continueOnBusy?: boolean | undefined}; export type SimultaneousRingCallHandlingX = {forwardToNumberList?: Array | undefined, forwardToTimedNumberList?: Array | undefined, noAnswerCallHandling?: CallHandlingWithTimeoutX | undefined, continueOnBusy?: boolean | undefined}; export type FindMeEndpointX = {ringUserDevice?: boolean | undefined, toNumber?: string | undefined, description?: string | undefined, timeout?: number | undefined, toUserId?: string | undefined, continueOnBusy?: boolean | undefined}; export type FindMeFollowMeCallHandlingX = {findMeEndpoints?: Array | undefined, busyCallHandling?: CallHandlingX | undefined, timeoutType?: ('Forward' | 'Voicemail' | 'Busy' | 'RingForever') | undefined}; export type ForwardAlwaysNumberTypeX = 'Extension' | 'PhoneNumber' | 'ShortCode'; export type CallHandlingSettingsX = {callWaitingEnabled?: boolean | undefined, doNotDisturbEnabled?: boolean | undefined, callHandlingOptionType?: ('RingPhone' | 'ForwardAlways' | 'SimultaneousRing' | 'FindMeFollowMe') | undefined, forwardAlwaysToNumber?: string | undefined, forwardAlwaysToNumberDescription?: string | undefined, ringPhoneCallHandling?: RingPhoneCallHandlingX | undefined, simultaneousRingCallHandling?: SimultaneousRingCallHandlingX | undefined, findMeFollowMeCallHandling?: FindMeFollowMeCallHandlingX | undefined, forwardAlwaysToNumberType?: ForwardAlwaysNumberTypeX | undefined}; export type CustomCallScreenX = {telephoneNumber?: string | undefined, blockType?: ('Allow' | 'Block' | 'Voicemail' | 'Forward' | 'VipRing' | 'BlockWithPrompt') | undefined, ringType?: ('StandardRing' | 'Ring1' | 'Ring2' | 'Ring3' | 'Ring4' | 'Ring5' | 'Ring6' | 'Ring7') | undefined}; export type CallScreeningSettingsX = {anonymousCallScreen?: ('Allow' | 'Block' | 'Voicemail' | 'Forward' | 'VipRing' | 'BlockWithPrompt') | undefined, anonymousRingType?: ('StandardRing' | 'Ring1' | 'Ring2' | 'Ring3' | 'Ring4' | 'Ring5' | 'Ring6' | 'Ring7') | undefined, tollFreeCallScreen?: ('Allow' | 'Block' | 'Voicemail' | 'Forward' | 'VipRing' | 'BlockWithPrompt') | undefined, tollFreeRingType?: ('StandardRing' | 'Ring1' | 'Ring2' | 'Ring3' | 'Ring4' | 'Ring5' | 'Ring6' | 'Ring7') | undefined, defaultCallScreen?: ('Allow' | 'Block' | 'Voicemail' | 'Forward' | 'VipRing' | 'BlockWithPrompt') | undefined, defaultRingType?: ('StandardRing' | 'Ring1' | 'Ring2' | 'Ring3' | 'Ring4' | 'Ring5' | 'Ring6' | 'Ring7') | undefined, customCallScreenList?: Array | undefined, forwardTn?: string | undefined}; export type MediaFriendsX = {enabled?: boolean | undefined, host?: string | undefined, toNumber?: string | undefined}; export type WeeklyScheduleTimeX = {startTime: string, endTime: string}; export type WeeklyScheduleX = {SUN?: WeeklyScheduleTimeX | undefined, MON?: WeeklyScheduleTimeX | undefined, TUE?: WeeklyScheduleTimeX | undefined, WED?: WeeklyScheduleTimeX | undefined, THU?: WeeklyScheduleTimeX | undefined, FRI?: WeeklyScheduleTimeX | undefined, SAT?: WeeklyScheduleTimeX | undefined}; export type CustomScheduleX = {date: string, startTime: string, endTime: string}; export type ScheduleX = {name?: string | undefined, type?: ('CUSTOM' | 'WEEKLY') | undefined, weekly?: {[key: string]: WeeklyScheduleX} | undefined, custom?: Array | undefined}; export type CallHandlingScheduleX = {schedule?: ScheduleX | undefined, callHandling?: CallHandlingSettingsX | undefined}; export type EndUserPrivacySettingsX = {directoryPrivacyEnabled?: boolean | undefined, autoAttendantDialByExtensionPrivacyEnabled?: boolean | undefined, autoAttendantDialByNamePrivacyEnabled?: boolean | undefined, autoAnswerPrivacyEnabled?: boolean | undefined}; export type UserGroupX = {id?: string | undefined, name?: string | undefined, description?: string | undefined}; export type EndUserV2X = {id?: string | undefined, username?: string | undefined, firstName?: string | undefined, lastName?: string | undefined, emailAddress?: string | undefined, mustChangePassword?: boolean | undefined, languageTag?: string | undefined, partitionId?: string | undefined, accountId?: string | undefined, callingPlans?: Array | undefined, devices?: Array | undefined, timeZone: 'US/Samoa' | 'US/Hawaii' | 'US/Alaska' | 'US/Pacific' | 'US/Arizona' | 'US/Mountain' | 'US/Central' | 'US/Eastern' | 'America/St_Thomas' | 'Canada/Pacific' | 'Canada/Mountain' | 'Canada/Central' | 'Canada/Eastern' | 'Canada/Atlantic' | 'Canada/Newfoundland', extension?: string | undefined, callerIdConfig?: CallerIdConfigX | undefined, callHandlingSettings?: CallHandlingSettingsX | undefined, callScreeningSettings?: CallScreeningSettingsX | undefined, newCppId?: string | undefined, mediaFriends?: MediaFriendsX | undefined, callHandlingSchedules?: Array | undefined, voicemailBoxId?: string | undefined, endUserType?: ('ADMIN' | 'ADVANCED_ADMIN' | 'BASIC_ADMIN' | 'STANDARD' | 'STANDARD_ADMIN' | 'SUPER_ADMIN') | undefined, userProductPlan?: ('STANDARD' | 'ADVANCED' | 'PROFESSIONAL') | undefined, softphoneClientType?: ('STRETTO' | 'CYMBUS') | undefined, pinLockedOut?: boolean | undefined, privacySettings?: EndUserPrivacySettingsX | undefined, welcomeEmailSent?: string | undefined, blockEmail?: boolean | undefined, allowPortalAccess?: boolean | undefined, tags?: string | undefined, group?: UserGroupX | undefined}; export type UpdateApiV2PartitionPartitionIdAccountAccountIdUserUserIdArgs = {accountId: string, partitionId: string, userId: string, body: EndUserV2X}; export type UpdateApiV2PartitionPartitionIdAccountAccountIdUserUserIdOptions = {baseUrl?: string | undefined, XAuthToken?: string | undefined, fetch?: typeof fetch | undefined}; export const callingPlanX = z.object({id: z.string().optional(), referenceId: z.string().optional(), referenceType: z.enum(["SIP_TRUNK", "END_USER", "IVR", "ACCOUNT", "SPECIALTY_LINE", "CONTACT_CENTER"]).optional(), callingPlanProductId: z.string().optional(), endDate: z.string().optional(), startDate: z.string().optional(), planMinutes: z.number().int().optional(), secondsRemaining: z.number().int().optional()}); export const provisioningRequestX = z.object({id: z.string().optional(), requestDate: z.string().optional(), httpStatus: z.number().int().optional(), deviceId: z.string().optional(), ipAddress: z.string().optional(), userAgent: z.string().optional()}); export const deviceX = z.object({id: z.string(), deviceTypeId: z.string(), accountId: z.string(), partitionId: z.string(), macAddress: z.string().optional(), deviceName: z.string(), emergencyNumber: z.string().optional(), emergencyNumberReservationId: z.string().optional(), faxEnabled: z.boolean(), lineNumber: z.number().int(), userId: z.string(), sipPassword: z.string().optional(), sipUsername: z.string().optional(), zipcode: z.string().optional(), state: z.string().optional(), lineType: z.enum(["Line", "AdvancedSharedLine", "ReferencedUser", "IntercomLine", "PresenceBlfUser", "SpeedDialUser", "SpeedDialTn", "CallParkingSpot", "SipPaging", "Custom"]).optional(), referenceId: z.string().optional(), provisioningRequest: provisioningRequestX.optional()}); export const callerIdConfigX = z.object({callerIdNumber: z.string().optional(), externalCallerIdVisible: z.boolean(), extensionCallerIdVisible: z.boolean(), callerIdNumberReservationId: z.string().optional(), callerIdName: z.string().optional()}); export const callHandlingX = z.object({type: z.enum(["Forward", "Voicemail", "Busy"]).optional(), forwardToNumber: z.string().optional(), description: z.string().optional()}); export const callHandlingWithTimeoutX = z.object({type: z.enum(["Forward", "Voicemail", "Busy", "RingForever"]).optional(), timeout: z.number().int().gte(1).optional(), forwardToNumber: z.string().optional(), description: z.string().optional()}); export const ringPhoneCallHandlingX = z.object({busyCallHandling: callHandlingX.optional(), noAnswerCallHandling: callHandlingWithTimeoutX.optional(), unregisteredCallHandling: callHandlingX.optional()}); export const simultaneousRingEndpointX = z.object({toNumber: z.string().optional(), ringDelay: z.number().int().gte(0).optional(), ringDuration: z.number().int().gte(1).optional(), continueOnBusy: z.boolean().optional()}); export const simultaneousRingCallHandlingX = z.object({forwardToNumberList: z.array(z.string()).optional(), forwardToTimedNumberList: z.array(simultaneousRingEndpointX).optional(), noAnswerCallHandling: callHandlingWithTimeoutX.optional(), continueOnBusy: z.boolean().optional()}); export const findMeEndpointX = z.object({ringUserDevice: z.boolean().optional(), toNumber: z.string().optional(), description: z.string().optional(), timeout: z.number().int().gte(1).lte(240).optional(), toUserId: z.string().optional(), continueOnBusy: z.boolean().optional()}); export const findMeFollowMeCallHandlingX = z.object({findMeEndpoints: z.array(findMeEndpointX).optional(), busyCallHandling: callHandlingX.optional(), timeoutType: z.enum(["Forward", "Voicemail", "Busy", "RingForever"]).optional()}); export const forwardAlwaysNumberTypeX = z.enum(["Extension", "PhoneNumber", "ShortCode"]); export const callHandlingSettingsX = z.object({callWaitingEnabled: z.boolean().optional(), doNotDisturbEnabled: z.boolean().optional(), callHandlingOptionType: z.enum(["RingPhone", "ForwardAlways", "SimultaneousRing", "FindMeFollowMe"]).optional(), forwardAlwaysToNumber: z.string().optional(), forwardAlwaysToNumberDescription: z.string().optional(), ringPhoneCallHandling: ringPhoneCallHandlingX.optional(), simultaneousRingCallHandling: simultaneousRingCallHandlingX.optional(), findMeFollowMeCallHandling: findMeFollowMeCallHandlingX.optional(), forwardAlwaysToNumberType: forwardAlwaysNumberTypeX.optional()}); export const customCallScreenX = z.object({telephoneNumber: z.string().optional(), blockType: z.enum(["Allow", "Block", "Voicemail", "Forward", "VipRing", "BlockWithPrompt"]).optional(), ringType: z.enum(["StandardRing", "Ring1", "Ring2", "Ring3", "Ring4", "Ring5", "Ring6", "Ring7"]).optional()}); export const callScreeningSettingsX = z.object({anonymousCallScreen: z.enum(["Allow", "Block", "Voicemail", "Forward", "VipRing", "BlockWithPrompt"]).optional(), anonymousRingType: z.enum(["StandardRing", "Ring1", "Ring2", "Ring3", "Ring4", "Ring5", "Ring6", "Ring7"]).optional(), tollFreeCallScreen: z.enum(["Allow", "Block", "Voicemail", "Forward", "VipRing", "BlockWithPrompt"]).optional(), tollFreeRingType: z.enum(["StandardRing", "Ring1", "Ring2", "Ring3", "Ring4", "Ring5", "Ring6", "Ring7"]).optional(), defaultCallScreen: z.enum(["Allow", "Block", "Voicemail", "Forward", "VipRing", "BlockWithPrompt"]).optional(), defaultRingType: z.enum(["StandardRing", "Ring1", "Ring2", "Ring3", "Ring4", "Ring5", "Ring6", "Ring7"]).optional(), customCallScreenList: z.array(customCallScreenX).optional(), forwardTn: z.string().optional()}); export const mediaFriendsX = z.object({enabled: z.boolean().optional(), host: z.string().optional(), toNumber: z.string().optional()}); export const weeklyScheduleTimeX = z.object({startTime: z.string(), endTime: z.string()}); export const weeklyScheduleX = z.object({SUN: weeklyScheduleTimeX.optional(), MON: weeklyScheduleTimeX.optional(), TUE: weeklyScheduleTimeX.optional(), WED: weeklyScheduleTimeX.optional(), THU: weeklyScheduleTimeX.optional(), FRI: weeklyScheduleTimeX.optional(), SAT: weeklyScheduleTimeX.optional()}); export const customScheduleX = z.object({date: z.string(), startTime: z.string(), endTime: z.string()}); export const scheduleX = z.object({name: z.string().optional(), type: z.enum(["CUSTOM", "WEEKLY"]).optional(), weekly: z.record(z.string(), weeklyScheduleX).optional(), custom: z.array(customScheduleX).optional()}); export const callHandlingScheduleX = z.object({schedule: scheduleX.optional(), callHandling: callHandlingSettingsX.optional()}); export const endUserPrivacySettingsX = z.object({directoryPrivacyEnabled: z.boolean().optional(), autoAttendantDialByExtensionPrivacyEnabled: z.boolean().optional(), autoAttendantDialByNamePrivacyEnabled: z.boolean().optional(), autoAnswerPrivacyEnabled: z.boolean().optional()}); export const userGroupX = z.object({id: z.string().optional(), name: z.string().optional(), description: z.string().optional()}); export const endUserV2X = z.object({id: z.string().optional(), username: z.string().min(3).max(256).optional(), firstName: z.string().min(3).max(256).optional(), lastName: z.string().min(3).max(256).optional(), emailAddress: z.string().min(3).max(256).optional(), mustChangePassword: z.boolean().optional(), languageTag: z.string().optional(), partitionId: z.string().optional(), accountId: z.string().optional(), callingPlans: z.array(callingPlanX).optional(), devices: z.array(deviceX).optional(), timeZone: z.enum(["US/Samoa", "US/Hawaii", "US/Alaska", "US/Pacific", "US/Arizona", "US/Mountain", "US/Central", "US/Eastern", "America/St_Thomas", "Canada/Pacific", "Canada/Mountain", "Canada/Central", "Canada/Eastern", "Canada/Atlantic", "Canada/Newfoundland"]), extension: z.string().optional(), callerIdConfig: callerIdConfigX.optional(), callHandlingSettings: callHandlingSettingsX.optional(), callScreeningSettings: callScreeningSettingsX.optional(), newCppId: z.string().optional(), mediaFriends: mediaFriendsX.optional(), callHandlingSchedules: z.array(callHandlingScheduleX).optional(), voicemailBoxId: z.string().optional(), endUserType: z.enum(["ADMIN", "ADVANCED_ADMIN", "BASIC_ADMIN", "STANDARD", "STANDARD_ADMIN", "SUPER_ADMIN"]).optional(), userProductPlan: z.enum(["STANDARD", "ADVANCED", "PROFESSIONAL"]).optional(), softphoneClientType: z.enum(["STRETTO", "CYMBUS"]).optional(), pinLockedOut: z.boolean().optional(), privacySettings: endUserPrivacySettingsX.optional(), welcomeEmailSent: z.string().optional(), blockEmail: z.boolean().optional(), allowPortalAccess: z.boolean().optional(), tags: z.string().optional(), group: userGroupX.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 end user * * PUT /v2/partition/{partitionId}/account/{accountId}/user/{userId} */ export const updateApiV2PartitionPartitionIdAccountAccountIdUserUserId = async (args: UpdateApiV2PartitionPartitionIdAccountAccountIdUserUserIdArgs, options?: UpdateApiV2PartitionPartitionIdAccountAccountIdUserUserIdOptions) => { const {baseUrl = "https://api.alianza.com", fetch: fetchFn = fetch, XAuthToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (XAuthToken !== undefined) headers.set("X-AUTH-TOKEN", XAuthToken) const url = `${baseUrl.replace(/\/+$/, '')}/v2/partition/${encodeURIComponent(String(args.partitionId))}/account/${encodeURIComponent(String(args.accountId))}/user/${encodeURIComponent(String(args.userId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(endUserV2X, await res.json()) };