import {z} from 'zod' export type Next = string; export type GetApiNetworkMonitoringV1GatewaysArgs = {filter?: string | undefined, sort?: string | undefined, limit?: number | undefined, next?: Next | undefined}; export type GetApiNetworkMonitoringV1GatewaysOptions = {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 countgw = z.number().int(); export const totalgw = z.number().int(); export const gatewayListResponse = z.object({items: z.array(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})), 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 Gateways * * GET /network-monitoring/v1/gateways */ export const getApiNetworkMonitoringV1Gateways = async (args: GetApiNetworkMonitoringV1GatewaysArgs, options?: GetApiNetworkMonitoringV1GatewaysOptions) => { 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.filter != null) query.append("filter", String(args.filter)) if (args.sort != null) query.append("sort", String(args.sort)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.next != null) query.append("next", String(args.next)) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/network-monitoring/v1/gateways${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(gatewayListResponse, await res.json()) };