import {z} from 'zod' export type GetApiApiV1ConfigLogScaleAlertsSlugArgs = {slug: string}; export type GetApiApiV1ConfigLogScaleAlertsSlugOptions = {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 configv1ReadLogScaleAlertResponse = 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 }; /** * GET /api/v1/config/log-scale-alerts/{slug} */ export const getApiApiV1ConfigLogScaleAlertsSlug = async (args: GetApiApiV1ConfigLogScaleAlertsSlugArgs, options?: GetApiApiV1ConfigLogScaleAlertsSlugOptions) => { const {baseUrl = "https://tenant.chronosphere.io", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("API-Token", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/config/log-scale-alerts/${encodeURIComponent(String(args.slug))}${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(configv1ReadLogScaleAlertResponse, await res.json()) };