import {z} from 'zod' export type SiteID = string; export type SiteName = unknown; export type TopAPsLimit = number; export type DateTime = string; export type GetApiNetworkMonitoringV1TopApsByUsageArgs = {'site-id'?: SiteID | undefined, 'site-name'?: SiteName | undefined, limit?: TopAPsLimit | undefined, 'start-at'?: DateTime | undefined, 'end-at'?: DateTime | undefined}; export type GetApiNetworkMonitoringV1TopApsByUsageOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const serialNumberap = z.string().max(16); export const deviceNameap = z.string().max(256); export const iDap = z.string().max(36); export const typeap = z.string().max(36); export const topAccessPoint = z.object({serialNumber: serialNumberap, deviceName: deviceNameap, totalValue: z.number().gte(0).lte(9223372036854776000), units: z.literal("Bytes").max(10), id: iDap, type: typeap}); export const topAccessPointsResponse = z.object({items: z.array(topAccessPoint), count: z.number().int()}); 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 high total bandwidth usage Access Points * * GET /network-monitoring/v1/top-aps-by-usage */ export const getApiNetworkMonitoringV1TopApsByUsage = async (args: GetApiNetworkMonitoringV1TopApsByUsageArgs, options?: GetApiNetworkMonitoringV1TopApsByUsageOptions) => { const {baseUrl = "https://sso.common.cloud.hpe.com", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['site-id'] != null) query.append("site-id", String(args['site-id'])) if (args['site-name'] != null) query.append("site-name", String(args['site-name'])) if (args.limit != null) query.append("limit", String(args.limit)) if (args['start-at'] != null) query.append("start-at", String(args['start-at'])) if (args['end-at'] != null) query.append("end-at", String(args['end-at'])) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/network-monitoring/v1/top-aps-by-usage${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(topAccessPointsResponse, await res.json()) };