import {z} from 'zod' export type GetApiV1DashboardsDashboardIdArgs = {dashboardId: string}; export type GetApiV1DashboardsDashboardIdOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const dashboardsDashboardCategory = z.object({id: z.string(), name: z.string(), type: z.string(), createdAt: z.string(), updatedAt: z.string()}); export const dashboardsDashboardWidget = z.object({id: z.string(), type: z.string(), title: z.string().nullable(), properties: z.record(z.string(), z.unknown()).nullable()}); export const dashboardsDashboardLayout = z.object({id: z.string(), x: z.number().int(), y: z.number().int(), width: z.number().int(), height: z.number().int()}); export const dashboardsDashboardReportType = z.enum(["Custom", "System", "DemAvailability"]); export const dashboardsDashboardAssociatedReport = z.object({id: z.string(), title: z.string(), type: dashboardsDashboardReportType}); export const dashboardsDashboard = z.object({id: z.string(), version: z.number().int().nullable(), name: z.string(), description: z.string().nullable(), category: dashboardsDashboardCategory.nullable(), systemReference: z.string().nullable(), isPrivate: z.boolean(), widgets: z.array(dashboardsDashboardWidget), layout: z.array(dashboardsDashboardLayout), ownerId: z.string().nullable(), createdAt: z.string(), updatedAt: z.string(), report: dashboardsDashboardAssociatedReport.nullable(), isFavorite: z.boolean()}); 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 a dashboard by ID * * GET /v1/dashboards/{dashboardId} */ export const getApiV1DashboardsDashboardId = async (args: GetApiV1DashboardsDashboardIdArgs, options?: GetApiV1DashboardsDashboardIdOptions) => { const {baseUrl = "https://api.na-01.cloud.solarwinds.com", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/dashboards/${encodeURIComponent(String(args.dashboardId))}${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(dashboardsDashboard, await res.json()) };