import {z} from 'zod' export type SerialNumber = unknown; export type DeleteApiNetworkMonitoringV1DevicesSerialNumberArgs = {'serial-number': SerialNumber}; export type DeleteApiNetworkMonitoringV1DevicesSerialNumberOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const serialNumber = z.string().max(16); export const macAddress = z.string().min(17).max(17); export const deviceName = z.string().max(256); export const deviceType = z.enum(["ACCESS_POINT", "SWITCH", "GATEWAY"]); export const model = z.string().max(32); export const partNumber = z.string().max(12); export const deployment = z.string().max(16); export const role = z.string().max(16); export const deviceFunction = z.string().max(20); export const firmwareVersion = z.string().max(32); export const iPv4Address = z.string().max(15); export const iPv6Address = z.string().max(39); export const status = z.enum(["ONLINE", "OFFLINE"]); export const uptimeInMillis = z.number().gte(0).lte(9223372036854776000); export const lastSeenAt = z.string().max(128); export const siteIDdevice = z.string().max(128); export const buildingId = z.unknown(); export const floorId = z.unknown(); export const configStatus = z.string().max(256); export const configLastModifiedAt = z.string().max(128); export const siteNamedevice = z.string().max(256); export const clusterName = z.string().max(256); export const notes = z.string().max(256); export const iDdevice = z.string().max(36); export const type = z.string().max(36); export const deviceResponseV1 = z.object({serialNumber: serialNumber, macAddress: macAddress, deviceName: deviceName, deviceType: deviceType, model: model.optional(), partNumber: partNumber.optional(), deployment: deployment.optional(), role: role.optional(), deviceFunction: deviceFunction.optional(), firmwareVersion: firmwareVersion.optional(), ipv4: iPv4Address.optional(), ipv6: iPv6Address.optional(), status: status.optional(), uptimeInMillis: uptimeInMillis.optional(), lastSeenAt: lastSeenAt.optional(), siteId: siteIDdevice, buildingId: buildingId.optional(), floorId: floorId.optional(), configStatus: configStatus.optional(), configLastModifiedAt: configLastModifiedAt.optional(), siteName: siteNamedevice.optional(), clusterName: clusterName.optional(), notes: notes.optional(), id: iDdevice, type: type}); 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 }; /** * Delete a device by serial number * * DELETE /network-monitoring/v1/devices/{serial-number} */ export const deleteApiNetworkMonitoringV1DevicesSerialNumber = async (args: DeleteApiNetworkMonitoringV1DevicesSerialNumberArgs, options?: DeleteApiNetworkMonitoringV1DevicesSerialNumberOptions) => { 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-monitoring/v1/devices/${encodeURIComponent(String(args['serial-number']))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "DELETE", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(deviceResponseV1, await res.json()) };