import {z} from 'zod' export type Type = unknown; export type KPIWidgetInput = {kpiWidget?: string | undefined, renderType?: string | undefined, columns?: Array | undefined}; export type ReportPeriodInput = {type: 'SNAPSHOT' | 'LAST_DAY' | 'LAST_WEEK' | 'LAST_MONTH' | 'CUSTOM_RANGE', sliceTime?: ({from?: string | undefined, to?: string | undefined}) | undefined, sliceDays?: (Array<'MON' | 'TUE' | 'WED' | 'THU' | 'FRI' | 'SAT' | 'SUN'>) | undefined, from?: string | undefined, to?: string | undefined}; export type ReportScheduleInput = {recurrenceType: 'EVERY_MONTH' | 'EVERY_WEEK' | 'EVERY_DAY' | 'ONE_TIME', startDate?: string | undefined, endDate?: string | undefined}; export type Filter = unknown; export type Filters = Array; export type Email = string; export type Emails = Array; export type ReportFormat = 'CSV' | 'PDF'; export type ReportFormats = Array; export type CreateReportsInput = {name: string, type: Type, kpiWidgets?: Array | undefined, timeZone: string, reportPeriod: ReportPeriodInput, reportSchedule: ReportScheduleInput, filters: Filters, email?: ({recipients?: Emails | undefined, formats?: ReportFormats | undefined}) | undefined}; export type CreateApiNetworkReportingV1ReportsArgs = {body: {report?: CreateReportsInput | undefined}}; export type CreateApiNetworkReportingV1ReportsOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const reportID = z.string(); export const name = z.string().max(64); export const reportScope = z.object({scopeType: z.string().optional(), values: z.array(z.unknown()).optional()}); export const reportType = z.string(); export const createdBy = z.string(); export const createdAt = z.string().max(30); export const generation = z.number().int().gte(1); export const updatedBy = z.string(); export const updatedAt = z.string().max(20); export const lastModifiedBy = z.string(); export const lastModifiedAt = z.string(); export const scheduleType = z.enum(["ONE_TIME", "EVERY_DAY", "EVERY_WEEK", "EVERY_MONTH"]); export const lastRunTs = z.string(); export const lastRunStatus = z.enum(["NEW", "ACTIVE", "PAUSED", "STOPPED", "COMPLETED", "ERROR"]); export const nextRunTs = z.string(); export const scheduleEnd = z.string(); export const reportSchedule = z.object({scheduleType: scheduleType.optional(), lastRunTs: lastRunTs.optional(), lastRunStatus: lastRunStatus.optional(), nextRunTs: nextRunTs.optional(), completedRuns: z.number().int().optional(), totalRuns: z.number().int().optional(), scheduleEnd: scheduleEnd.optional()}); export const report = z.object({id: reportID, type: z.string(), name: name.optional(), reportScope: reportScope.optional(), reportType: reportType.optional(), createdBy: createdBy.optional(), createdAt: createdAt, generation: generation, updatedBy: updatedBy.optional(), updatedAt: updatedAt, lastModifiedBy: lastModifiedBy.optional(), lastModifiedAt: lastModifiedAt.optional(), reportSchedule: reportSchedule.optional()}); export const createApiNetworkReportingV1ReportsResponse = z.object({report: report}); 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 }; /** * Create Report * * POST /network-reporting/v1/reports */ export const createApiNetworkReportingV1Reports = async (args: CreateApiNetworkReportingV1ReportsArgs, options?: CreateApiNetworkReportingV1ReportsOptions) => { const {baseUrl = "https://sso.common.cloud.hpe.com", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/network-reporting/v1/reports${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(createApiNetworkReportingV1ReportsResponse, await res.json()) };