import {z} from 'zod' export type SiteId = unknown; export type Mac = unknown; export type GetApiNetworkMonitoringV1UnmanagedDeviceMacAddressArgs = {'site-id': SiteId, 'mac-address': Mac}; export type GetApiNetworkMonitoringV1UnmanagedDeviceMacAddressOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const id = z.string(); export const unmanagedDevice = z.object({id: id, name: z.string().optional(), serial: z.string().optional(), type: z.string(), mac: z.string().optional(), supportedCapability: z.string().optional(), enabledCapability: z.string().optional(), description: z.string().optional(), vendor: z.string().optional(), status: z.string().optional()}); 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 }; /** * Returns details for an unmanaged device of a given site. * * GET /network-monitoring/v1/unmanaged-device/{mac-address} */ export const getApiNetworkMonitoringV1UnmanagedDeviceMacAddress = async (args: GetApiNetworkMonitoringV1UnmanagedDeviceMacAddressArgs, options?: GetApiNetworkMonitoringV1UnmanagedDeviceMacAddressOptions) => { 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 (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/network-monitoring/v1/unmanaged-device/${encodeURIComponent(String(args['mac-address']))}${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(unmanagedDevice, await res.json()) };