import {z} from 'zod' export type VolumeTelemetryRequestDto = {period: string, serial_numbers: Array, chart_width?: (number | null) | undefined, smart_sampling?: (boolean | null) | undefined}; export type CreateApiTelemetryVolumesVolumeIdSnapshotPropagationByApplianceArgs = {volume_id: string, body: VolumeTelemetryRequestDto}; export type CreateApiTelemetryVolumesVolumeIdSnapshotPropagationByApplianceOptions = {baseUrl?: string | undefined, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const volumeTelemetrySnapshotPropagationRecord = z.object({snapshot_appliance: z.string(), snapshot_serial_number: z.string(), snapshot_time: z.number().int(), snapshot_version: z.number().int(), sync_appliance: z.string(), sync_serial_number: z.string(), sync_time: z.number().int(), propagation_duration: z.number().int(), average_propagation_duration: z.number().int(), deviation: z.number().int()}); export const volumeTelemetrySnapshotPropagationDto = z.object({metadata: z.record(z.string(), z.unknown()).optional(), items: z.array(volumeTelemetrySnapshotPropagationRecord), snapshot_appliances: z.array(z.string()), sync_appliances: z.array(z.string())}); 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 Volume Snapshot Propagation by Appliance * * POST /telemetry/volumes/{volume_id}/snapshot_propagation_by_appliance */ export const createApiTelemetryVolumesVolumeIdSnapshotPropagationByAppliance = async (args: CreateApiTelemetryVolumesVolumeIdSnapshotPropagationByApplianceArgs, options?: CreateApiTelemetryVolumesVolumeIdSnapshotPropagationByApplianceOptions) => { const {baseUrl = "https://am1.portal.api.nasuni.com", fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/telemetry/volumes/${encodeURIComponent(String(args.volume_id))}/snapshot_propagation_by_appliance${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(volumeTelemetrySnapshotPropagationDto, await res.json()) };