import {z} from 'zod' export type SerialNumber = unknown; export type SiteId = unknown; export type GetApiNetworkMonitoringV1SwitchesSerialNumberInterfaceTrendsArgs = {'serial-number': SerialNumber, 'site-id'?: SiteId | undefined, 'interface-id'?: string | undefined, uplink?: boolean | undefined, filter?: unknown | undefined}; export type GetApiNetworkMonitoringV1SwitchesSerialNumberInterfaceTrendsOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const sample = z.object({data: z.array(z.number()).optional(), timestamp: z.number().optional()}); export const interfaceTrendsResponse = z.object({id: z.string(), type: z.string(), metric: z.string().optional(), interfaceId: z.string().optional(), uplink: z.boolean().optional(), keys: z.array(z.string()).optional(), samples: z.array(sample).optional(), units: z.array(z.string()).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 interface trends for a Switch * * GET /network-monitoring/v1/switches/{serial-number}/interface-trends */ export const getApiNetworkMonitoringV1SwitchesSerialNumberInterfaceTrends = async (args: GetApiNetworkMonitoringV1SwitchesSerialNumberInterfaceTrendsArgs, options?: GetApiNetworkMonitoringV1SwitchesSerialNumberInterfaceTrendsOptions) => { 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['interface-id'] != null) query.append("interface-id", String(args['interface-id'])) if (args.uplink != null) query.append("uplink", String(args.uplink)) if (args.filter != null) query.append("filter", String(args.filter)) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/network-monitoring/v1/switches/${encodeURIComponent(String(args['serial-number']))}/interface-trends${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(interfaceTrendsResponse, await res.json()) };