import {z} from 'zod' export type SerialNumber = unknown; export type SiteIDap = unknown; export type Next = string; export type GetApiNetworkMonitoringV1ApsSerialNumberTunnelsArgs = {'serial-number': SerialNumber, 'site-id'?: SiteIDap | undefined, filter?: unknown | undefined, sort?: unknown | undefined, limit?: number | undefined, next?: Next | undefined}; export type GetApiNetworkMonitoringV1ApsSerialNumberTunnelsOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const tunnelName = z.string().max(256); export const tunnelIndex = z.string().max(32); export const destinationName = z.string().max(128); export const destinationMacAddress = z.string().max(18); export const destinationIpAddress = z.string().max(64); export const tunnelStatus = z.string().max(16); export const encapsulationType = z.string().max(32); export const cryptoType = z.enum(["TUNNEL_CRYPTO_TYPE_UNSPECIFIED", "TUNNEL_CRYPTO_TYPE_CERTIFICATE", "TUNNEL_CRYPTO_TYPE_PSK"]).max(32); export const sourceIpAddress = z.string().max(64); export const tunnelLastChangeReason = z.string().max(128); export const tunnelUptimeInMillis = z.number().int(); export const tunnelActive = z.boolean(); export const tunnelId = z.string().max(256); export const tunnelIdentifier = z.string().max(36); export const typeap = z.string().max(36); export const count = z.number().int(); export const total = z.number().int(); export const accessPointTunnelListResponseV1 = z.object({items: z.array(z.object({tunnelName: tunnelName, index: tunnelIndex, destinationName: destinationName.optional(), destinationMacAddress: destinationMacAddress.optional(), destinationIpAddress: destinationIpAddress.optional(), status: tunnelStatus, encapsulationType: encapsulationType, cryptoType: cryptoType.optional(), sourceIpAddress: sourceIpAddress.optional(), lastChangeReason: tunnelLastChangeReason.optional(), uptimeInMillis: tunnelUptimeInMillis.optional(), active: tunnelActive.optional(), tunnelId: tunnelId, id: tunnelIdentifier, type: typeap})), count: count, total: total.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 }; /** * Get a list of Access Point Tunnels * * GET /network-monitoring/v1/aps/{serial-number}/tunnels */ export const getApiNetworkMonitoringV1ApsSerialNumberTunnels = async (args: GetApiNetworkMonitoringV1ApsSerialNumberTunnelsArgs, options?: GetApiNetworkMonitoringV1ApsSerialNumberTunnelsOptions) => { 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.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/aps/${encodeURIComponent(String(args['serial-number']))}/tunnels${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(accessPointTunnelListResponseV1, await res.json()) };