import {z} from 'zod' export type MetricPipelineRuleUpdateSchema = {serviceId?: string | undefined, name?: string | undefined, description?: string | undefined, ruleType?: ('Filter' | 'Drop' | 'RenameMetric' | 'RenameAttribute' | 'AddAttribute' | 'RemoveAttribute' | 'RedactAttribute' | 'Sample') | undefined, filterCondition?: ('All' | 'Any') | undefined, filters?: Record | undefined, renameFromKey?: string | undefined, renameToKey?: string | undefined, addAttributeKey?: string | undefined, addAttributeValue?: string | undefined, redactReplacement?: string | undefined, samplePercentage?: number | undefined, isEnabled?: boolean | undefined, sortOrder?: number | undefined}; export type UpdateApiMetricPipelineRuleIdArgs = {id: string, body: {data: MetricPipelineRuleUpdateSchema}}; export type UpdateApiMetricPipelineRuleIdOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const metricPipelineRuleReadSchema = z.object({_id: z.string().optional(), createdAt: z.object({}).optional(), updatedAt: z.object({}).optional(), deletedAt: z.object({}).optional(), projectId: z.string().optional(), serviceId: z.string().optional(), name: z.string(), description: z.string().optional(), ruleType: z.enum(["Filter", "Drop", "RenameMetric", "RenameAttribute", "AddAttribute", "RemoveAttribute", "RedactAttribute", "Sample"]), filterCondition: z.enum(["All", "Any"]).optional(), filters: z.object({}).optional(), renameFromKey: z.string().optional(), renameToKey: z.string().optional(), addAttributeKey: z.string().optional(), addAttributeValue: z.string().optional(), redactReplacement: z.string().optional(), samplePercentage: z.number().optional(), isEnabled: z.boolean().optional(), sortOrder: z.number().optional(), createdByUserId: z.string().optional(), deletedByUserId: z.string().optional()}); export const updateApiMetricPipelineRuleIdResponse = z.object({data: metricPipelineRuleReadSchema.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 }; /** * Update Metric Pipeline Rule * * PUT /metric-pipeline-rule/{id} */ export const updateApiMetricPipelineRuleId = async (args: UpdateApiMetricPipelineRuleIdArgs, options?: UpdateApiMetricPipelineRuleIdOptions) => { const {baseUrl = "https://oneuptime.com/api", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKey !== undefined) headers.set("APIKey", ApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/metric-pipeline-rule/${encodeURIComponent(String(args.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(updateApiMetricPipelineRuleIdResponse, await res.json()) };