import {z} from 'zod' export type UpdateAnomalyConfigRequest = {alert_budget_per_day?: (number | null) | undefined, alert_destinations?: (Array | null) | undefined, alert_direction?: (string | null) | undefined, alert_enabled?: (boolean | null) | undefined, alert_window_buckets?: (number | null) | undefined, alert_window_fire_pct?: (number | null) | undefined, alert_window_recover_pct?: (number | null) | undefined, band_width?: (number | null) | undefined, custom_sql?: (string | null) | undefined, description?: (string | null) | undefined, detection_function?: (string | null) | undefined, detection_function_field?: (string | null) | undefined, detection_window_seconds?: (number | null) | undefined, enabled?: (boolean | null) | undefined, filters: unknown, folder_id?: (string | null) | undefined, histogram_interval?: (string | null) | undefined, level_half_width_seconds?: (number | null) | undefined, name?: (string | null) | undefined, owner?: (string | null) | undefined, percentile?: (number | null) | undefined, priority?: (number | null) | undefined, query_mode?: (string | null) | undefined, retrain_interval_days?: (number | null) | undefined, schedule_interval?: (string | null) | undefined, tags?: (Array | null) | undefined, template?: (string | null) | undefined, training_window_days?: (number | null) | undefined}; export type UpdateApiApiOrgIdAnomalyDetectionConfigIdArgs = {org_id: string, config_id: string, body: UpdateAnomalyConfigRequest}; export type UpdateApiApiOrgIdAnomalyDetectionConfigIdOptions = {baseUrl: string, Authorization?: string | undefined, fetch?: typeof fetch | undefined}; export const anomalyConfigResponse = z.object({}); 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 }; /** * Update an existing anomaly detection configuration * * PUT /api/{org_id}/anomaly_detection/{config_id} */ export const updateApiApiOrgIdAnomalyDetectionConfigId = async (args: UpdateApiApiOrgIdAnomalyDetectionConfigIdArgs, options: UpdateApiApiOrgIdAnomalyDetectionConfigIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, Authorization} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Authorization !== undefined) headers.set("Authorization", Authorization) const url = `${baseUrl.replace(/\/+$/, '')}/api/${encodeURIComponent(String(args.org_id))}/anomaly_detection/${encodeURIComponent(String(args.config_id))}${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(anomalyConfigResponse, await res.json()) };