import {z} from 'zod' export type XiqAnomalyType = 'POE_STABILITY' | 'DFS_RECURRENCE' | 'ADVERSE_TRAFFIC' | 'PORT_EFFICIENCY' | 'WIFI_CAPACITY' | 'WIFI_EFFICIENCY' | 'HARDWARE_HEALTH' | 'MISSING_VLAN'; export type XiqAnomalySeverity = 'NONE' | 'LOW' | 'MEDIUM' | 'HIGH'; export type XiqAnomalySortField = 'LOCATION' | 'SEVERITY' | 'TIME' | 'CATEGORY' | 'ANOMALY_TYPE' | 'DEVICE_NAME' | 'MUTED'; export type XiqSortOrder = 'ASC' | 'DESC'; export type GetApiCopilotAnomaliesDevicesWithLocationsArgs = {page?: number | undefined, limit?: number | undefined, anomalyType?: XiqAnomalyType | undefined, startTime: number, endTime: number, buildingId?: number | undefined, severity?: XiqAnomalySeverity | undefined, excludeMuted?: boolean | undefined, sortField?: XiqAnomalySortField | undefined, sortOrder?: XiqSortOrder | undefined, searchKey?: string | undefined}; export type GetApiCopilotAnomaliesDevicesWithLocationsOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const xiqAnomalySeverity = z.enum(["NONE", "LOW", "MEDIUM", "HIGH"]); export const xiqAnomalyType = z.enum(["POE_STABILITY", "DFS_RECURRENCE", "ADVERSE_TRAFFIC", "PORT_EFFICIENCY", "WIFI_CAPACITY", "WIFI_EFFICIENCY", "HARDWARE_HEALTH", "MISSING_VLAN"]); export const xiqDeviceCategory = z.enum(["WIRED", "WIRELESS"]); export const xiqMissingVlanAffectedDeviceEntity = z.object({ap_name: z.string().optional(), ap_device_id: z.string().optional(), upstream_switch_interface: z.string().optional(), interface_name: z.string().optional(), missing_vlans: z.array(z.number().int()).optional()}); export const xiqMissingVlanInfo = z.object({lldp_enabled: z.boolean().optional(), upstream_switch_name: z.string().optional(), floor_name: z.string().optional(), affected_device_entity: z.array(xiqMissingVlanAffectedDeviceEntity).optional()}); export const xiqAnomalyDeviceWithLocation = z.object({building_id: z.number().int(), location_name: z.string(), muted: z.boolean(), severity: xiqAnomalySeverity, anomaly_type: xiqAnomalyType, last_detected_time: z.number().int(), device_id: z.number().int(), device_name: z.string(), device_model: z.string(), device_make: z.string(), switch_stack: z.boolean(), category: xiqDeviceCategory, interface_name: z.string(), location_id: z.number().int().optional(), anomaly_id: z.string().optional(), frequency: z.string().optional(), channel_number: z.number().int().optional(), channel_mode: z.string().optional(), recommended_action: z.string().optional(), issue: z.string().optional(), current_poe_mode: z.string().optional(), device_status: z.boolean().optional(), anomaly_subtypes: z.string().optional(), missing_vlan_info: xiqMissingVlanInfo.optional()}); export const xiqAnomalyAffectedCount = z.object({total_anomaly_count: z.number().int(), affected_location_count: z.number().int(), affected_devices_count: z.number().int()}); export const xiqCopilotPagedXiqAnomalyDeviceWithLocation = z.object({page: z.number().int(), count: z.number().int(), total_pages: z.number().int(), total_count: z.number().int(), data: z.array(xiqAnomalyDeviceWithLocation).optional(), summary: z.string().optional(), affected_count: xiqAnomalyAffectedCount.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 /copilot/anomalies/devices-with-locations */ export const getApiCopilotAnomaliesDevicesWithLocations = async (args: GetApiCopilotAnomaliesDevicesWithLocationsArgs, options?: GetApiCopilotAnomaliesDevicesWithLocationsOptions) => { const {baseUrl = "https://api.extremecloudiq.com", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.anomalyType != null) query.append("anomalyType", String(args.anomalyType)) if (args.startTime != null) query.append("startTime", String(args.startTime)) if (args.endTime != null) query.append("endTime", String(args.endTime)) if (args.buildingId != null) query.append("buildingId", String(args.buildingId)) if (args.severity != null) query.append("severity", String(args.severity)) if (args.excludeMuted != null) query.append("excludeMuted", String(args.excludeMuted)) if (args.sortField != null) query.append("sortField", String(args.sortField)) if (args.sortOrder != null) query.append("sortOrder", String(args.sortOrder)) if (args.searchKey != null) query.append("searchKey", String(args.searchKey)) if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/copilot/anomalies/devices-with-locations${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(xiqCopilotPagedXiqAnomalyDeviceWithLocation, await res.json()) };