import {z} from 'zod' export type Configv1LabelFilter = {name?: string | undefined, value_glob?: string | undefined}; export type Configv1DropRuleMode = 'ENABLED' | 'DISABLED' | 'PREVIEW'; export type DropRuleValueBasedDrop = {enabled?: boolean | undefined, target_drop_value?: number | undefined}; export type Configv1DropRule = {created_at?: string | undefined, drop_nan_value?: boolean | undefined, filters?: Array | undefined, mode?: Configv1DropRuleMode | undefined, name: string, slug?: string | undefined, updated_at?: string | undefined, value_based_drop?: DropRuleValueBasedDrop | undefined}; export type Configv1CreateDropRuleRequest = {drop_rule?: Configv1DropRule | undefined, dry_run?: boolean | undefined}; export type CreateApiApiV1ConfigDropRulesArgs = {body: Configv1CreateDropRuleRequest}; export type CreateApiApiV1ConfigDropRulesOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const configv1LabelFilter = z.object({name: z.string().optional(), value_glob: z.string().optional()}); export const configv1DropRuleMode = z.enum(["ENABLED", "DISABLED", "PREVIEW"]); export const dropRuleValueBasedDrop = z.object({enabled: z.boolean().optional(), target_drop_value: z.number().optional()}); export const configv1DropRule = z.object({created_at: z.string().optional(), drop_nan_value: z.boolean().optional(), filters: z.array(configv1LabelFilter).optional(), mode: configv1DropRuleMode.optional(), name: z.string(), slug: z.string().optional(), updated_at: z.string().optional(), value_based_drop: dropRuleValueBasedDrop.optional()}); export const configv1CreateDropRuleResponse = z.object({drop_rule: configv1DropRule.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/drop-rules */ export const createApiApiV1ConfigDropRules = async (args: CreateApiApiV1ConfigDropRulesArgs, options?: CreateApiApiV1ConfigDropRulesOptions) => { 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/drop-rules${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(configv1CreateDropRuleResponse, await res.json()) };