import {z} from 'zod' export type LogScaleAlertAlertType = 'STANDARD' | 'FILTER'; export type Configv1LogScaleAlert = {alert_type?: LogScaleAlertAlertType | undefined, created_at?: string | undefined, description?: string | undefined, disabled?: boolean | undefined, log_scale_action_slugs?: Array | undefined, log_scale_query?: string | undefined, name: string, repository?: string | undefined, run_as_user?: string | undefined, slug?: string | undefined, tags?: Array | undefined, throttle_field?: string | undefined, throttle_secs?: number | undefined, time_window_secs?: number | undefined, updated_at?: string | undefined}; export type Configv1CreateLogScaleAlertRequest = {dry_run?: boolean | undefined, log_scale_alert?: Configv1LogScaleAlert | undefined}; export type CreateApiApiV1ConfigLogScaleAlertsArgs = {body: Configv1CreateLogScaleAlertRequest}; export type CreateApiApiV1ConfigLogScaleAlertsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const logScaleAlertAlertType = z.enum(["STANDARD", "FILTER"]); export const configv1LogScaleAlert = z.object({alert_type: logScaleAlertAlertType.optional(), created_at: z.string().optional(), description: z.string().optional(), disabled: z.boolean().optional(), log_scale_action_slugs: z.array(z.string()).optional(), log_scale_query: z.string().optional(), name: z.string(), repository: z.string().optional(), run_as_user: z.string().optional(), slug: z.string().optional(), tags: z.array(z.string()).optional(), throttle_field: z.string().optional(), throttle_secs: z.number().int().optional(), time_window_secs: z.number().int().optional(), updated_at: z.string().optional()}); export const configv1CreateLogScaleAlertResponse = z.object({log_scale_alert: configv1LogScaleAlert.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/log-scale-alerts */ export const createApiApiV1ConfigLogScaleAlerts = async (args: CreateApiApiV1ConfigLogScaleAlertsArgs, options?: CreateApiApiV1ConfigLogScaleAlertsOptions) => { 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/log-scale-alerts${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(configv1CreateLogScaleAlertResponse, await res.json()) };