import {z} from 'zod' export type Configv1CollectionReferenceType = 'SIMPLE' | 'SERVICE'; export type Configv1CollectionReference = {type?: Configv1CollectionReferenceType | undefined, slug?: string | undefined}; export type Configv1Dashboard = {slug?: string | undefined, name?: string | undefined, created_at?: string | undefined, updated_at?: string | undefined, collection_slug?: string | undefined, collection?: Configv1CollectionReference | undefined, dashboard_json?: string | undefined, labels?: {[key: string]: string} | undefined}; export type ConfigV1UpdateDashboardBody = {dashboard?: Configv1Dashboard | undefined, create_if_missing?: boolean | undefined, dry_run?: boolean | undefined}; export type UpdateApiApiV1ConfigDashboardsSlugArgs = {slug: string, body: ConfigV1UpdateDashboardBody}; export type UpdateApiApiV1ConfigDashboardsSlugOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const configv1CollectionReferenceType = z.enum(["SIMPLE", "SERVICE"]); export const configv1CollectionReference = z.object({type: configv1CollectionReferenceType.optional(), slug: z.string().optional()}); export const configv1Dashboard = z.object({slug: z.string().optional(), name: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), collection_slug: z.string().optional(), collection: configv1CollectionReference.optional(), dashboard_json: z.string().optional(), labels: z.record(z.string(), z.string()).optional()}); export const configv1UpdateDashboardResponse = 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 }; /** * PUT /api/v1/config/dashboards/{slug} */ export const updateApiApiV1ConfigDashboardsSlug = async (args: UpdateApiApiV1ConfigDashboardsSlugArgs, options: UpdateApiApiV1ConfigDashboardsSlugOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/config/dashboards/${encodeURIComponent(String(args.slug))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(configv1UpdateDashboardResponse, await res.json()) };