import {z} from 'zod' export type GetApiNetworkMonitoringV1ApplicationsArgs = {'site-id': unknown, 'client-id'?: unknown | undefined, 'start-at': string, 'end-at': string, limit: number, next?: string | undefined, offset?: number | undefined, filter?: unknown | undefined, sort?: unknown | undefined}; export type GetApiNetworkMonitoringV1ApplicationsOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const applicationItems = z.object({type: z.string().max(13), id: z.string().max(13), name: z.string().max(256).optional(), categories: z.array(z.string().max(256)).optional(), experience: z.object({}).optional(), risk: z.string().max(256).optional(), txBytes: z.number().int().gte(0).lte(9223372036854776000).optional(), rxBytes: z.number().int().gte(0).lte(9223372036854776000).optional(), state: z.string().max(7).optional(), lastUsedTime: z.string().max(13).optional(), tlsVersion: z.string().max(256).optional(), certificateExpiryDate: z.string().max(256).optional(), applicationHostType: z.string().max(256).optional(), destLocation: z.array(z.object({})).optional()}); export const next = z.string(); export const offset = z.number().int(); export const count = z.number().int(); export const totalapp = z.number().int(); export const applicationsResponse = z.object({items: z.array(applicationItems), next: next, offset: offset.optional(), count: count, total: totalapp}); 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 applications accessed in a site * * * GET /network-monitoring/v1/applications */ export const getApiNetworkMonitoringV1Applications = async (args: GetApiNetworkMonitoringV1ApplicationsArgs, options?: GetApiNetworkMonitoringV1ApplicationsOptions) => { 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['client-id'] != null) query.append("client-id", String(args['client-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.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 (args.filter != null) query.append("filter", String(args.filter)) 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/applications${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(applicationsResponse, await res.json()) };