import {z} from 'zod' export type SiteIddeviceloc = string; export type LocationId = unknown; export type GetApiNetworkServicesV1SitesSiteIdDeviceLocationsLocationIdArgs = {'site-id': SiteIddeviceloc, 'location-id': LocationId}; export type GetApiNetworkServicesV1SitesSiteIdDeviceLocationsLocationIdOptions = {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 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 location resource * * GET /network-services/v1/sites/{site-id}/device-locations/{location-id} */ export const getApiNetworkServicesV1SitesSiteIdDeviceLocationsLocationId = async (args: GetApiNetworkServicesV1SitesSiteIdDeviceLocationsLocationIdArgs, options?: GetApiNetworkServicesV1SitesSiteIdDeviceLocationsLocationIdOptions) => { 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 (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/network-services/v1/sites/${encodeURIComponent(String(args['site-id']))}/device-locations/${encodeURIComponent(String(args['location-id']))}${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(deviceLocationSummary, await res.json()) };