import {z} from 'zod' export type SiteIddeviceloc = string; export type Filter = unknown; export type Limitdeviceloc = number; export type Next = string; export type GetApiNetworkServicesV1SitesSiteIdDeviceLocationsArgs = {'site-id': SiteIddeviceloc, filter?: Filter | undefined, limit?: Limitdeviceloc | undefined, next?: Next | undefined, 'with-location'?: boolean | undefined}; export type GetApiNetworkServicesV1SitesSiteIdDeviceLocationsOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const locationId = z.string().max(128); export const deviceSerial = z.string().max(16); export const deviceType = z.enum(["ACCESS_POINT", "SWITCH", "GATEWAY"]); export const timestamp = z.unknown(); export const siteIddeviceloc = z.string().max(128); export const buildingId = z.unknown(); export const floorId = z.unknown(); export const floorLevel = z.unknown(); export const cartesianCoordinates = z.object({unit: z.enum(["METERS", "FEET"]).optional(), xPosition: z.unknown(), yPosition: z.unknown()}); export const longitude = z.unknown(); export const latitude = z.unknown(); export const center = z.object({longitude: longitude, latitude: latitude}); export const lCIUncertainty = z.object({longitudeUncertainty: z.unknown(), latitudeUncertainty: z.unknown(), confidenceLevel: z.unknown()}); export const altitude = z.object({elevationType: z.enum(["ABOVE_MEAN_SEA_LEVEL", "ABOVE_GROUND_LEVEL", "UNKNOWN"]), elevation: z.unknown(), elevationUncertainty: z.unknown()}); export const location = z.object({source: z.enum(["ADMIN_SPECIFIED", "SYSTEM_GENERATED"]), timestamp: timestamp, cartesianCoordinates: cartesianCoordinates.optional(), center: center, lciUncertainty: lCIUncertainty.optional(), altitude: altitude.optional()}); export const deviceLocationSummary = z.object({id: locationId, serialNumber: deviceSerial.optional(), type: deviceType, createdAt: timestamp, siteId: siteIddeviceloc, buildingId: buildingId.optional(), floorId: floorId, floorLevel: floorLevel.optional(), tenantId: z.unknown(), ipv4: z.unknown(), ipv6: z.unknown(), macAddress: z.unknown(), model: z.unknown(), deployment: z.unknown(), status: z.enum(["ONLINE", "OFFLINE"]).optional(), consolidatedLocation: location.optional()}); export const listDeviceLocationSummary = z.object({items: z.array(deviceLocationSummary), count: z.number().int().gte(1).lte(2147483647), total: z.number().int().gte(0).lte(9223372036854776000), next: z.string().max(128).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 }; /** * List devices with location information * * GET /network-services/v1/sites/{site-id}/device-locations */ export const getApiNetworkServicesV1SitesSiteIdDeviceLocations = async (args: GetApiNetworkServicesV1SitesSiteIdDeviceLocationsArgs, options?: GetApiNetworkServicesV1SitesSiteIdDeviceLocationsOptions) => { 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.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['with-location'] != null) query.append("with-location", String(args['with-location'])) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/network-services/v1/sites/${encodeURIComponent(String(args['site-id']))}/device-locations${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(listDeviceLocationSummary, await res.json()) };