import {z} from 'zod' export type SerialNumbergw = string; export type GetApiNetworkMonitoringV1GatewaysSerialNumberUplinksArgs = {'serial-number': SerialNumbergw, sort?: string | undefined}; export type GetApiNetworkMonitoringV1GatewaysSerialNumberUplinksOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const linkTag = z.string().max(256); export const publicIp = z.string().max(15); export const privateIp = z.string().max(15); export const vlanIdgw = z.number().int().gte(1).lte(4095); export const iDgw = z.string().max(36); export const typegw = z.string().max(36); export const countgw = z.number().int(); export const totalgw = z.number().int(); export const gatewayUplinkListResponse = z.object({items: z.array(z.object({linkTag: linkTag, status: z.enum(["Up", "Down"]).max(4), wanStatus: z.enum(["Up", "Down"]).max(4), linkStatus: z.enum(["Up", "Down"]).max(4), publicIpAddress: publicIp, privateIpAddress: privateIp, vlanId: vlanIdgw, isBackupUplink: z.boolean(), usage: z.object({received: z.number().int().gte(0), sent: z.number().int().gte(0), total: z.number().int().gte(0)}), throughput: z.object({received: z.number().int().gte(0), sent: z.number().int().gte(0)}), id: iDgw, type: typegw})), count: countgw, total: totalgw.optional(), next: z.string()}); 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 }; /** * List Gateway uplinks * * GET /network-monitoring/v1/gateways/{serial-number}/uplinks */ export const getApiNetworkMonitoringV1GatewaysSerialNumberUplinks = async (args: GetApiNetworkMonitoringV1GatewaysSerialNumberUplinksArgs, options?: GetApiNetworkMonitoringV1GatewaysSerialNumberUplinksOptions) => { 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.sort != null) query.append("sort", String(args.sort)) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/network-monitoring/v1/gateways/${encodeURIComponent(String(args['serial-number']))}/uplinks${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(gatewayUplinkListResponse, await res.json()) };