import {z} from 'zod' export type Configv1CollectionReferenceType = 'SIMPLE' | 'SERVICE'; export type Configv1CollectionReference = {slug?: string | undefined, type?: Configv1CollectionReferenceType | undefined}; export type Configv1Dashboard = {collection?: Configv1CollectionReference | undefined, collection_slug?: string | undefined, created_at?: string | undefined, dashboard_json?: string | undefined, labels?: {[key: string]: string} | undefined, name: string, slug?: string | undefined, updated_at?: string | undefined}; export type Configv1CreateDashboardRequest = {dashboard?: Configv1Dashboard | undefined, dry_run?: boolean | undefined}; export type CreateApiApiV1ConfigDashboardsArgs = {body: Configv1CreateDashboardRequest}; export type CreateApiApiV1ConfigDashboardsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const configv1CollectionReferenceType = z.enum(["SIMPLE", "SERVICE"]); export const configv1CollectionReference = z.object({slug: z.string().optional(), type: configv1CollectionReferenceType.optional()}); export const configv1Dashboard = z.object({collection: configv1CollectionReference.optional(), collection_slug: z.string().optional(), created_at: z.string().optional(), dashboard_json: z.string().optional(), labels: z.record(z.string(), z.string()).optional(), name: z.string(), slug: z.string().optional(), updated_at: z.string().optional()}); export const configv1CreateDashboardResponse = z.object({dashboard: configv1Dashboard.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 }; /** * POST /api/v1/config/dashboards */ export const createApiApiV1ConfigDashboards = async (args: CreateApiApiV1ConfigDashboardsArgs, options?: CreateApiApiV1ConfigDashboardsOptions) => { const {baseUrl = "https://tenant.chronosphere.io", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("API-Token", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/config/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(configv1CreateDashboardResponse, await res.json()) };