import {z} from 'zod' export type GetApiV2RefDevicetypeArgs = {partitionid?: string | undefined}; export type GetApiV2RefDevicetypeOptions = {baseUrl?: string | undefined, XAuthToken?: string | undefined, fetch?: typeof fetch | undefined}; export const ringTypeAlertInfoX = z.object({ringType: z.enum(["StandardRing", "Ring1", "Ring2", "Ring3", "Ring4", "Ring5", "Ring6", "Ring7"]), alertInfoHeaderValue: z.string()}); export const deviceTypeX = z.object({id: z.string().optional(), name: z.string().optional(), numLines: z.number().int().optional(), deviceTypeManufacturer: z.enum(["CISCO_LINKSYS_SIPURA", "POLYCOM", "ARRIS", "OBIHAI", "INNOMEDIA", "THIRD_PARTY", "SOFT_PHONE", "ZTE", "SCIENTIFIC_ATLANTA", "CALIX", "YEALINK", "SNOM", "SMART_RG", "ACROBITS", "GRANDSTREAM", "ADTRAN", "MEDIATRIX", "ALGO", "MITEL", "CLEARLY_IP"]).optional(), acceptsRemoteResync: z.boolean().optional(), faxSupported: z.boolean().optional(), macAddressRequired: z.boolean().optional(), showProvisionStatus: z.boolean().optional(), enforceUniqueAdminPassword: z.boolean().optional(), customEncryptionKeys: z.boolean().optional(), sipPagingEnabled: z.boolean().optional(), distinctiveRingInfo: z.string().optional(), smbDevice: z.boolean().optional(), sideCarTypeIds: z.array(z.string()).optional(), maxSideCars: z.number().int().optional(), ringTypeAlertInfo: z.array(ringTypeAlertInfoX).optional(), sipRegMax: z.number().int().optional(), deviceKind: z.string().optional(), lineFunctionality: z.record(z.string(), z.array(z.enum(["Line", "AdvancedSharedLine", "ReferencedUser", "IntercomLine", "PresenceBlfUser", "SpeedDialUser", "SpeedDialTn", "CallParkingSpot", "SipPaging", "Custom"]))).optional(), disabledProperties: z.array(z.string()).optional()}); export const getApiV2RefDevicetypeResponse = z.array(deviceTypeX); 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 }; /** * DeviceTypes List * * GET /v2/ref/devicetype */ export const getApiV2RefDevicetype = async (args: GetApiV2RefDevicetypeArgs, options?: GetApiV2RefDevicetypeOptions) => { const {baseUrl = "https://api.alianza.com", fetch: fetchFn = fetch, XAuthToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.partitionid != null) query.append("partitionid", String(args.partitionid)) if (XAuthToken !== undefined) headers.set("X-AUTH-TOKEN", XAuthToken) const url = `${baseUrl.replace(/\/+$/, '')}/v2/ref/devicetype${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(getApiV2RefDevicetypeResponse, await res.json()) };