import {z} from 'zod' export type SerialNumbergw = string; export type GetApiNetworkMonitoringV1GatewaysSerialNumberArgs = {'serial-number': SerialNumbergw}; export type GetApiNetworkMonitoringV1GatewaysSerialNumberOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const serialNumbergw = z.string().max(16); export const macAddressgw = z.string().max(18); export const deviceNamegw = z.string().max(256); export const siteIDgw = z.string().max(128); export const firmwareVersiongw = z.string().max(32); export const ipv4Addressgw = z.string().max(15); export const uptimeInMillisgw = z.number().gte(0).lte(9223372036854776000); export const deploymentgw = z.enum(["Standalone", "Cluster"]).max(10); export const rolegw = z.enum(["Isoleader", "Leader", "Member"]).max(9); export const modelgw = z.string().max(256); export const siteNamegw = z.string().max(256); export const clusterNamegw = z.string().max(256); export const iDgw = z.string().max(36); export const typegw = z.string().max(36); export const gatewayResponse = z.object({serialNumber: serialNumbergw, macAddress: macAddressgw, deviceName: deviceNamegw, cpuUtilization: z.number(), memoryUtilization: z.number(), siteId: siteIDgw, firmwareVersion: firmwareVersiongw, ipAddress: ipv4Addressgw, uptimeInMillis: uptimeInMillisgw, macRange: z.string().max(256), rebootReason: z.string().max(256), deviceFunction: z.enum(["Unspecified", "Mobility Controller", "Branch Gateway", "VPNC"]).max(19), mode: deploymentgw, status: z.enum(["Online", "Offline"]).max(7), role: rolegw, model: modelgw, siteName: siteNamegw, clusterName: clusterNamegw, id: iDgw, type: typegw}); 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 }; /** * Gateway Details * * GET /network-monitoring/v1/gateways/{serial-number} */ export const getApiNetworkMonitoringV1GatewaysSerialNumber = async (args: GetApiNetworkMonitoringV1GatewaysSerialNumberArgs, options?: GetApiNetworkMonitoringV1GatewaysSerialNumberOptions) => { 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 (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/network-monitoring/v1/gateways/${encodeURIComponent(String(args['serial-number']))}${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(gatewayResponse, await res.json()) };