import {z} from 'zod' export type GetApiV2PartitionPartitionIdAccountAccountIdMacaddressMacAddressArgs = {accountId: string, macAddress: string, partitionId: string}; export type GetApiV2PartitionPartitionIdAccountAccountIdMacaddressMacAddressOptions = {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 lineTypeX = z.enum(["AdvancedSharedLine", "CallParkingSpot", "Custom", "IntercomAutoAnswer", "IntercomLine", "Line", "PresenceBlfUser", "ReferencedUser", "SipPaging", "SpeedDialTn", "SpeedDialUser"]); export const sideCarTypeX = z.object({id: z.string().optional(), name: z.string().optional(), numLinesPerPage: z.number().int().optional(), numPages: z.number().int().optional(), lineFunctionality: z.record(z.string(), z.array(lineTypeX)).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 accountDeviceDataX = z.object({referenceType: z.enum(["LINE_HARDWARE", "USER"]).optional(), macAddress: z.string().optional(), deviceType: deviceTypeX.optional(), sideCarType: sideCarTypeX.optional(), numSideCars: z.number().int().optional(), devices: z.array(deviceX).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 }; /** * Get device data by MAC address * * GET /v2/partition/{partitionId}/account/{accountId}/macaddress/{macAddress} */ export const getApiV2PartitionPartitionIdAccountAccountIdMacaddressMacAddress = async (args: GetApiV2PartitionPartitionIdAccountAccountIdMacaddressMacAddressArgs, options?: GetApiV2PartitionPartitionIdAccountAccountIdMacaddressMacAddressOptions) => { 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 (XAuthToken !== undefined) headers.set("X-AUTH-TOKEN", XAuthToken) const url = `${baseUrl.replace(/\/+$/, '')}/v2/partition/${encodeURIComponent(String(args.partitionId))}/account/${encodeURIComponent(String(args.accountId))}/macaddress/${encodeURIComponent(String(args.macAddress))}${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(accountDeviceDataX, await res.json()) };