import {z} from 'zod' export type EmergencyServiceAddressResourceRequest = {street?: string | undefined, street2?: string | undefined, city?: string | undefined, zip?: string | undefined, customerName?: string | undefined, state?: string | undefined, stateId?: string | undefined, country?: string | undefined, countryId?: string | undefined}; export type CommonEmergencyLocationAddressInfoDefault = {country?: string | undefined, countryId?: string | undefined, countryIsoCode?: string | undefined, countryName?: string | undefined, state?: string | undefined, stateId?: string | undefined, stateIsoCode?: string | undefined, stateName?: string | undefined, city?: string | undefined, street?: string | undefined, street2?: string | undefined, zip?: string | undefined, customerName?: string | undefined}; export type DeviceEmergencyLocationInfo = {id?: string | undefined, name?: string | undefined, addressFormatId?: string | undefined}; export type DeviceEmergencyInfo = {address?: CommonEmergencyLocationAddressInfoDefault | undefined, location?: DeviceEmergencyLocationInfo | undefined, outOfCountry?: boolean | undefined, addressStatus?: ('Valid' | 'Invalid' | 'Provisioning') | undefined, visibility?: ('Private' | 'Public') | undefined, syncStatus?: ('Verified' | 'Updated' | 'Deleted' | 'NotRequired' | 'Unsupported' | 'Failed') | undefined, addressEditableStatus?: ('MainDevice' | 'AnyDevice') | undefined}; export type DeviceUpdateExtensionInfo = {id?: string | undefined}; export type UpdateDevicePhoneInfo = {id?: string | undefined}; export type DeviceUpdatePhoneLinesInfo = {phoneLines?: Array | undefined}; export type AccountDeviceUpdate = {emergencyServiceAddress?: EmergencyServiceAddressResourceRequest | undefined, emergency?: DeviceEmergencyInfo | undefined, extension?: DeviceUpdateExtensionInfo | undefined, phoneLines?: DeviceUpdatePhoneLinesInfo | undefined, useAsCommonPhone?: boolean | undefined, name?: string | undefined}; export type UpdateApiRestapiV10AccountAccountIdDeviceDeviceIdEmergencyArgs = {accountId: string, deviceId: string, body: AccountDeviceUpdate}; export type UpdateApiRestapiV10AccountAccountIdDeviceDeviceIdEmergencyOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const addonInfo = z.object({id: z.string().optional(), name: z.string().optional(), count: z.number().int().optional()}); export const deviceFeatureEnum = z.enum(["BLA", "CommonPhone", "Intercom", "Paging", "HELD"]); export const modelInfo = z.object({id: z.string().optional(), name: z.string().optional(), addons: z.array(addonInfo).optional(), deviceClass: z.string().optional(), features: z.array(deviceFeatureEnum).optional(), lineCount: z.number().int().optional()}); export const extensionInfoIntId = z.object({id: z.number().int().optional(), uri: z.string().optional(), extensionNumber: z.string().optional(), partnerId: z.string().optional()}); export const commonEmergencyLocationAddressInfoDefault = z.object({country: z.string().optional(), countryId: z.string().optional(), countryIsoCode: z.string().optional(), countryName: z.string().optional(), state: z.string().optional(), stateId: z.string().optional(), stateIsoCode: z.string().optional(), stateName: z.string().optional(), city: z.string().optional(), street: z.string().optional(), street2: z.string().optional(), zip: z.string().optional(), customerName: z.string().optional()}); export const deviceEmergencyLocationInfo = z.object({id: z.string().optional(), name: z.string().optional(), addressFormatId: z.string().optional()}); export const deviceEmergencyInfo = z.object({address: commonEmergencyLocationAddressInfoDefault.optional(), location: deviceEmergencyLocationInfo.optional(), outOfCountry: z.boolean().optional(), addressStatus: z.enum(["Valid", "Invalid", "Provisioning"]).optional(), visibility: z.enum(["Private", "Public"]).optional(), syncStatus: z.enum(["Verified", "Updated", "Deleted", "NotRequired", "Unsupported", "Failed"]).optional(), addressEditableStatus: z.enum(["MainDevice", "AnyDevice"]).optional()}); export const emergencyServiceAddressResource = z.object({street: z.string().optional(), street2: z.string().optional(), city: z.string().optional(), zip: z.string().optional(), customerName: z.string().optional(), state: z.string().optional(), stateId: z.string().optional(), stateIsoCode: z.string().optional(), stateName: z.string().optional(), countryId: z.string().optional(), countryIsoCode: z.string().optional(), country: z.string().optional(), countryName: z.string().optional(), outOfCountry: z.boolean().optional(), syncStatus: z.enum(["Verified", "Updated", "Deleted", "NotRequired", "Unsupported", "Failed"]).optional(), additionalCustomerName: z.string().optional(), customerEmail: z.string().optional(), additionalCustomerEmail: z.string().optional(), customerPhone: z.string().optional(), additionalCustomerPhone: z.string().optional(), lineProvisioningStatus: z.enum(["Provisioning", "Valid", "Invalid"]).optional(), taxId: z.string().optional()}); export const phoneLineTypeEnum = z.enum(["Unknown", "Standalone", "StandaloneFree", "BlaPrimary", "BlaSecondary"]); export const phoneNumberCountryInfo = z.object({id: z.string().optional(), uri: z.string().optional(), name: z.string().optional()}); export const deviceProvisioningExtensionInfo = z.object({id: z.string().optional(), uri: z.string().optional(), extensionNumber: z.string().optional(), partnerId: z.string().optional()}); export const phoneNumberInfoIntId = z.object({id: z.number().int().optional(), country: phoneNumberCountryInfo.optional(), extension: deviceProvisioningExtensionInfo.optional(), label: z.string().optional(), location: z.string().optional(), paymentType: z.enum(["External", "Local"]).optional(), phoneNumber: z.string().optional(), status: z.string().optional(), type: z.enum(["VoiceFax", "FaxOnly", "VoiceOnly"]).optional(), usageType: z.enum(["MainCompanyNumber", "AdditionalCompanyNumber", "CompanyNumber", "DirectNumber", "CompanyFaxNumber", "ForwardedNumber", "ForwardedCompanyNumber", "ContactCenterNumber"]).optional()}); export const emergencyAddress = z.object({required: z.boolean().optional(), localOnly: z.boolean().optional(), lineProvisioningStatus: z.enum(["Valid", "Provisioning", "Invalid"]).optional()}); export const phoneLinesInfo = z.object({id: z.string().optional(), lineType: phoneLineTypeEnum.optional(), phoneInfo: phoneNumberInfoIntId.optional(), emergencyAddress: emergencyAddress.optional()}); export const shippingStatus = z.enum(["Initial", "Accepted", "Shipped"]); export const shippingMethodInfo = z.object({id: z.enum(["1", "2", "3"]), name: z.enum(["Ground", "2 Day", "Overnight"]).optional()}); export const shippingAddressInfo = z.object({customerName: z.string().optional(), additionalCustomerName: z.string().optional(), customerEmail: z.string().optional(), additionalCustomerEmail: z.string().optional(), customerPhone: z.string().optional(), additionalCustomerPhone: z.string().optional(), street: z.string().optional(), street2: z.string().optional(), city: z.string().optional(), state: z.string().optional(), stateId: z.string().optional(), stateIsoCode: z.string().optional(), stateName: z.string().optional(), countryId: z.string().optional(), countryIsoCode: z.string().optional(), country: z.string().optional(), countryName: z.string().optional(), zip: z.string().optional(), taxId: z.string().optional()}); export const shippingInfo = z.object({status: shippingStatus.optional(), carrier: z.string().optional(), trackingNumber: z.string().optional(), method: shippingMethodInfo.optional(), address: shippingAddressInfo.optional()}); export const deviceSiteInfo = z.object({id: z.string().optional(), name: z.string().optional()}); export const linePoolingEnum = z.enum(["Host", "Guest", "None"]); export const billingStatementCharges = z.object({description: z.string().optional(), amount: z.number().optional(), feature: z.string().optional(), freeServiceCredit: z.number().optional()}); export const billingStatementFees = z.object({description: z.string().optional(), amount: z.number().optional(), freeServiceCredit: z.number().optional()}); export const billingStatementInfo = z.object({currency: z.string().optional(), charges: z.array(billingStatementCharges).optional(), fees: z.array(billingStatementFees).optional(), totalCharged: z.number().optional(), totalCharges: z.number().optional(), totalFees: z.number().optional(), subtotal: z.number().optional(), totalFreeServiceCredit: z.number().optional()}); export const deviceResource = z.object({id: z.string().optional(), uri: z.string().optional(), sku: z.string().optional(), type: z.enum(["BLA", "SoftPhone", "OtherPhone", "HardPhone", "WebPhone", "Paging", "Room", "WebRTC"]).optional(), name: z.string().optional(), serial: z.string().optional(), status: z.enum(["Offline", "Online"]).optional(), computerName: z.string().optional(), model: modelInfo.optional(), extension: extensionInfoIntId.optional(), emergency: deviceEmergencyInfo.optional(), emergencyServiceAddress: emergencyServiceAddressResource.optional(), phoneLines: z.array(phoneLinesInfo).optional(), shipping: shippingInfo.optional(), boxBillingId: z.number().int().optional(), useAsCommonPhone: z.boolean().optional(), hotDeskDevice: z.boolean().optional(), inCompanyNet: z.boolean().optional(), site: deviceSiteInfo.optional(), lastLocationReportTime: z.string().optional(), linePooling: linePoolingEnum.optional(), billingStatement: billingStatementInfo.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 Device Emergency Info * * PUT /restapi/v1.0/account/{accountId}/device/{deviceId}/emergency */ export const updateApiRestapiV10AccountAccountIdDeviceDeviceIdEmergency = async (args: UpdateApiRestapiV10AccountAccountIdDeviceDeviceIdEmergencyArgs, options?: UpdateApiRestapiV10AccountAccountIdDeviceDeviceIdEmergencyOptions) => { 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))}/device/${encodeURIComponent(String(args.deviceId))}/emergency${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(deviceResource, await res.json()) };