import {z} from 'zod' export type ServiceLevelObjectiveBurnRateRuleUpdateSchema = {name?: string | undefined, isEnabled?: boolean | undefined, burnRateThreshold?: number | undefined, longWindowInMinutes?: number | undefined, shortWindowInMinutes?: number | undefined, minimumSampleCount?: number | undefined, refireSuppressionMinutes?: number | undefined, shouldCreateAlert?: boolean | undefined, shouldCreateIncident?: boolean | undefined, alertSeverityId?: string | undefined, onCallDutyPolicies?: (Array<{id?: string | undefined}>) | undefined, alertTitleTemplate?: string | undefined, alertDescriptionTemplate?: string | undefined, alertRemediationNotes?: string | undefined, isAlertPrivate?: boolean | undefined, autoResolveAlert?: boolean | undefined, alertLabels?: (Array<{id?: string | undefined}>) | undefined, alertOwnerTeams?: (Array<{id?: string | undefined}>) | undefined, alertOwnerUsers?: (Array<{id?: string | undefined}>) | undefined, incidentSeverityId?: string | undefined, incidentOnCallDutyPolicies?: (Array<{id?: string | undefined}>) | undefined, incidentTitleTemplate?: string | undefined, incidentDescriptionTemplate?: string | undefined, incidentRemediationNotes?: string | undefined, isIncidentPrivate?: boolean | undefined, autoResolveIncident?: boolean | undefined, incidentLabels?: (Array<{id?: string | undefined}>) | undefined, incidentOwnerTeams?: (Array<{id?: string | undefined}>) | undefined, incidentOwnerUsers?: (Array<{id?: string | undefined}>) | undefined, addSloOwnersAsOwners?: boolean | undefined}; export type UpdateApiServiceLevelObjectiveBurnRateRuleIdArgs = {id: string, body: {data: ServiceLevelObjectiveBurnRateRuleUpdateSchema}}; export type UpdateApiServiceLevelObjectiveBurnRateRuleIdOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const serviceLevelObjectiveBurnRateRuleReadSchema = z.object({_id: z.string().optional(), createdAt: z.object({}).optional(), updatedAt: z.object({}).optional(), deletedAt: z.object({}).optional(), projectId: z.string().optional(), serviceLevelObjectiveId: z.string(), name: z.string(), isEnabled: z.boolean().optional(), burnRateThreshold: z.number(), longWindowInMinutes: z.number(), shortWindowInMinutes: z.number(), minimumSampleCount: z.number().optional(), refireSuppressionMinutes: z.number().optional(), shouldCreateAlert: z.boolean().optional(), shouldCreateIncident: z.boolean().optional(), alertSeverityId: z.string().optional(), onCallDutyPolicies: z.array(z.object({id: z.string().optional()})).optional(), alertTitleTemplate: z.string().optional(), alertDescriptionTemplate: z.string().optional(), alertRemediationNotes: z.string().optional(), isAlertPrivate: z.boolean().optional(), autoResolveAlert: z.boolean().optional(), alertLabels: z.array(z.object({id: z.string().optional()})).optional(), alertOwnerTeams: z.array(z.object({id: z.string().optional()})).optional(), alertOwnerUsers: z.array(z.object({id: z.string().optional()})).optional(), incidentSeverityId: z.string().optional(), incidentOnCallDutyPolicies: z.array(z.object({id: z.string().optional()})).optional(), incidentTitleTemplate: z.string().optional(), incidentDescriptionTemplate: z.string().optional(), incidentRemediationNotes: z.string().optional(), isIncidentPrivate: z.boolean().optional(), autoResolveIncident: z.boolean().optional(), incidentLabels: z.array(z.object({id: z.string().optional()})).optional(), incidentOwnerTeams: z.array(z.object({id: z.string().optional()})).optional(), incidentOwnerUsers: z.array(z.object({id: z.string().optional()})).optional(), addSloOwnersAsOwners: z.boolean().optional(), lastAlertCreatedAt: z.object({}).optional(), lastAlertResolvedAt: z.object({}).optional(), lastIncidentCreatedAt: z.object({}).optional(), lastIncidentResolvedAt: z.object({}).optional(), createdByUserId: z.string().optional()}); export const updateApiServiceLevelObjectiveBurnRateRuleIdResponse = z.object({data: serviceLevelObjectiveBurnRateRuleReadSchema.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 SLO Burn Rate Rule * * PUT /service-level-objective-burn-rate-rule/{id} */ export const updateApiServiceLevelObjectiveBurnRateRuleId = async (args: UpdateApiServiceLevelObjectiveBurnRateRuleIdArgs, options?: UpdateApiServiceLevelObjectiveBurnRateRuleIdOptions) => { 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(/\/+$/, '')}/service-level-objective-burn-rate-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(updateApiServiceLevelObjectiveBurnRateRuleIdResponse, await res.json()) };