import {z} from 'zod' export type GetApiNetworkServicesV1AirmatchRfEventsArgs = {'start-at'?: string | undefined, 'end-at'?: string | undefined, limit?: number | undefined, offset?: number | undefined}; export type GetApiNetworkServicesV1AirmatchRfEventsOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const rfEvents = z.object({id: z.string(), type: z.string(), band: z.string().optional(), dbTimestamp: z.number().int().optional(), new: z.object({bandwidth: z.string().optional(), eirpDbm: z.number().optional(), isApm: z.boolean().optional(), channel: z.number().int().optional(), secondaryChannel: z.number().int().optional(), eirp: z.number().int().optional()}).optional(), old: z.object({bandwidth: z.string().optional(), eirpDbm: z.number().optional(), isApm: z.boolean().optional(), channel: z.number().int().optional(), secondaryChannel: z.number().int().optional(), eirp: z.number().int().optional()}).optional(), radioMac: z.string().optional(), reason: z.string().optional(), siteId: z.string().optional(), tenantId: z.string().optional(), updateTimestamp: z.number().int().optional()}); export const rfEventsAll = z.object({id: z.string(), type: z.string(), count: z.number().int(), items: z.array(rfEvents)}); 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 all RF events of a tenant * * GET /network-services/v1/airmatch-rf-events */ export const getApiNetworkServicesV1AirmatchRfEvents = async (args: GetApiNetworkServicesV1AirmatchRfEventsArgs, options?: GetApiNetworkServicesV1AirmatchRfEventsOptions) => { 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['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.offset != null) query.append("offset", String(args.offset)) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/network-services/v1/airmatch-rf-events${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(rfEventsAll, await res.json()) };