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 GetApiCopilotAnomaliesPoeflappingLldpCdpInfoArgs = {anomalyType: XiqAnomalyType, anomalyId: string, deviceId: number, lastDetectedTime: number}; export type GetApiCopilotAnomaliesPoeflappingLldpCdpInfoOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const xiqAffectedDownlinkDevice = z.object({host_name: z.string().optional(), product_type: z.string().optional(), interface_name: z.string().optional(), port_id: z.string().optional(), last_detected_time: z.number().int().optional()}); export const xiqUnaffectedDownlinkDevice = z.object({host_name: z.string().optional(), product_type: z.string().optional(), interface_name: z.string().optional(), port_id: z.string().optional()}); export const xiqPowerSourceEquipment = z.object({is_lldp_cdp_enabled: z.boolean().optional(), uplink_switch_system_name: z.string().optional(), uplink_switch_system_id: z.string().optional(), location_name: z.string().optional(), floor_name: z.string().optional(), affected_downlink_devices: z.array(xiqAffectedDownlinkDevice).optional(), unaffected_downlink_devices: z.array(xiqUnaffectedDownlinkDevice).optional(), uplink_switch_device_id: z.number().int().optional()}); export const xiqCopilotLldpCdpInfo = z.object({lldp_cdp_info: xiqPowerSourceEquipment.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/poeflapping/lldp-cdp-info */ export const getApiCopilotAnomaliesPoeflappingLldpCdpInfo = async (args: GetApiCopilotAnomaliesPoeflappingLldpCdpInfoArgs, options?: GetApiCopilotAnomaliesPoeflappingLldpCdpInfoOptions) => { 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.anomalyType != null) query.append("anomalyType", String(args.anomalyType)) if (args.anomalyId != null) query.append("anomalyId", String(args.anomalyId)) if (args.deviceId != null) query.append("deviceId", String(args.deviceId)) if (args.lastDetectedTime != null) query.append("lastDetectedTime", String(args.lastDetectedTime)) if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/copilot/anomalies/poeflapping/lldp-cdp-info${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(xiqCopilotLldpCdpInfo, await res.json()) };