import {z} from 'zod' export type Limit = number; export type GetApiNetworkMonitoringV1ClientFirewallSessionsArgs = {'site-id': unknown, 'start-at': string, 'end-at': string, 'client-mac': unknown, filter: unknown, limit?: Limit | undefined, next?: string | undefined, offset?: number | undefined}; export type GetApiNetworkMonitoringV1ClientFirewallSessionsOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const sessionItems = z.object({type: z.string().max(13), id: z.string().max(50), timestamp: z.string().max(13).optional(), serialNumber: z.string().max(20).optional(), clientUsername: z.string().max(256).optional(), clientMac: z.string().max(17).optional(), sourceIp: z.string().max(15).optional(), destinationIp: z.string().max(15).optional(), clientRole: z.string().max(256).optional(), ssidName: z.string().max(256).optional(), tunneledTraffic: z.boolean().optional(), clientConnectionType: z.string().max(10).optional(), vlanId: z.number().int().gte(0).lte(10000).optional(), txBytes: z.number().int().gte(0).lte(9223372036854776000).optional(), rxBytes: z.number().int().gte(0).lte(9223372036854776000).optional(), sessionType: z.string().max(7).optional(), applicationName: z.string().max(256).optional(), applicationCategories: z.array(z.string().max(256)).optional(), webUrl: z.string().max(256).optional(), webCategories: z.string().max(256).optional(), webReputation: z.string().max(256).optional(), blockedSessionReason: z.string().max(256).optional(), deviceType: z.string().max(256).optional(), sessionCount: z.number().int().optional(), clientHostname: z.string().max(256).optional(), tlsServerVersion: z.string().max(256).optional(), certificateExpiryDate: z.string().max(256).optional(), destinationLocation: z.string().max(256).optional()}); export const next = z.string(); export const offset = z.number().int(); export const count = z.number().int(); export const total = z.number().int(); export const clientSessionLogResponse = z.object({items: z.array(sessionItems), next: next, offset: offset.optional(), count: count, total: total}); 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 client firewall session logs * * * GET /network-monitoring/v1/client-firewall-sessions */ export const getApiNetworkMonitoringV1ClientFirewallSessions = async (args: GetApiNetworkMonitoringV1ClientFirewallSessionsArgs, options?: GetApiNetworkMonitoringV1ClientFirewallSessionsOptions) => { 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['start-at'] != null) query.append("start-at", String(args['start-at'])) if (args['end-at'] != null) query.append("end-at", String(args['end-at'])) if (args['client-mac'] != null) query.append("client-mac", String(args['client-mac'])) if (args.filter != null) query.append("filter", String(args.filter)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.next != null) query.append("next", String(args.next)) if (args.offset != null) query.append("offset", String(args.offset)) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/network-monitoring/v1/client-firewall-sessions${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(clientSessionLogResponse, await res.json()) };