import {z} from 'zod' export type GetApiNetworkReportingV1ReportsArgs = {search?: string | undefined, filter?: string | undefined, sort?: string | undefined, next?: string | undefined, limit?: number | undefined}; export type GetApiNetworkReportingV1ReportsOptions = {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 listReports = z.object({items: z.array(report), count: z.number().int(), total: z.number().int().optional(), next: 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 }; /** * List Reports * * GET /network-reporting/v1/reports */ export const getApiNetworkReportingV1Reports = async (args: GetApiNetworkReportingV1ReportsArgs, options?: GetApiNetworkReportingV1ReportsOptions) => { 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.search != null) query.append("search", String(args.search)) if (args.filter != null) query.append("filter", String(args.filter)) if (args.sort != null) query.append("sort", String(args.sort)) if (args.next != null) query.append("next", String(args.next)) if (args.limit != null) query.append("limit", String(args.limit)) 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: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(listReports, await res.json()) };