import {z} from 'zod' export type DashboardWidgetType = 'insights_vis' | 'alarms' | 'deployments' | 'checkins' | 'uptime' | 'errors'; export type DashboardWidgetInput = {id?: string | undefined, type: DashboardWidgetType, grid?: ({x?: number | undefined, y?: number | undefined, w?: number | undefined, h?: number | undefined}) | undefined, presentation?: ({title?: string | undefined, subtitle?: string | undefined}) | undefined, config?: {[key: string]: unknown} | undefined}; export type DashboardInput = {title: string, default_ts?: (string | null) | undefined, widgets?: Array | undefined}; export type CreateApiProjectsProjectIdDashboardsArgs = {project_id: string, body: DashboardInput}; export type CreateApiProjectsProjectIdDashboardsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const dashboardWidgetType = z.enum(["insights_vis", "alarms", "deployments", "checkins", "uptime", "errors"]); export const dashboardWidget = z.object({id: z.string().optional(), type: dashboardWidgetType, grid: z.object({x: z.number().int().gte(0).optional(), y: z.number().int().gte(0).optional(), w: z.number().int().gte(1).optional(), h: z.number().int().gte(1).optional()}).optional(), presentation: z.object({title: z.string().max(255).optional(), subtitle: z.string().max(255).optional()}).optional(), config: z.record(z.string(), z.unknown()).optional()}); export const webLinks = z.object({web: z.string()}); export const dashboard = z.object({id: z.string(), project_id: z.string(), title: z.string(), widgets: z.array(dashboardWidget), is_default: z.boolean(), shared: z.boolean(), default_ts: z.string().nullable(), created_at: z.string(), updated_at: z.string(), links: webLinks}); export const responseMeta = z.object({request_id: z.string().optional()}); export const createApiProjectsProjectIdDashboardsResponse = z.object({data: dashboard, meta: responseMeta.optional()}); 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 a dashboard * * POST /projects/{project_id}/dashboards */ export const createApiProjectsProjectIdDashboards = async (args: CreateApiProjectsProjectIdDashboardsArgs, options?: CreateApiProjectsProjectIdDashboardsOptions) => { const {baseUrl = "https://app.honeybadger.io/v3", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/projects/${encodeURIComponent(String(args.project_id))}/dashboards${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(createApiProjectsProjectIdDashboardsResponse, await res.json()) };