import {z} from 'zod' export type LabelRelationSelectSchema = {_id?: boolean | undefined, createdAt?: boolean | undefined, updatedAt?: boolean | undefined, deletedAt?: boolean | undefined, name?: boolean | undefined, projectId?: boolean | undefined, color?: boolean | undefined, isArchived?: boolean | undefined}; export type MonitorRelationSelectSchema = {_id?: boolean | undefined, createdAt?: boolean | undefined, updatedAt?: boolean | undefined, deletedAt?: boolean | undefined, projectId?: boolean | undefined, name?: boolean | undefined, monitorTemplateId?: boolean | undefined, autoProvisionedNetworkDeviceId?: boolean | undefined, networkAlertPolicyId?: boolean | undefined, monitorType?: boolean | undefined, currentMonitorStatusId?: boolean | undefined, monitorSteps?: boolean | undefined}; export type MonitorStatusRelationSelectSchema = {_id?: boolean | undefined, createdAt?: boolean | undefined, updatedAt?: boolean | undefined, deletedAt?: boolean | undefined, projectId?: boolean | undefined, name?: boolean | undefined, color?: boolean | undefined, isOperationalState?: boolean | undefined, isOfflineState?: boolean | undefined, priority?: boolean | undefined, isArchived?: boolean | undefined}; export type ServiceLevelObjectiveSelectSchema = {_id?: boolean | undefined, createdAt?: boolean | undefined, updatedAt?: boolean | undefined, deletedAt?: boolean | undefined, projectId?: boolean | undefined, name?: boolean | undefined, description?: boolean | undefined, slug?: boolean | undefined, labels?: LabelRelationSelectSchema | undefined, isEnabled?: boolean | undefined, isArchived?: boolean | undefined, archivedAt?: boolean | undefined, archivedByUserId?: boolean | undefined, sliType?: boolean | undefined, multiMonitorMode?: boolean | undefined, monitors?: MonitorRelationSelectSchema | undefined, monitorLabels?: LabelRelationSelectSchema | undefined, autoAddedMonitors?: MonitorRelationSelectSchema | undefined, downtimeMonitorStatuses?: MonitorStatusRelationSelectSchema | undefined, metricQueryConfig?: boolean | undefined, targetPercentage?: boolean | undefined, windowType?: boolean | undefined, windowDays?: boolean | undefined, timezone?: boolean | undefined, atRiskThresholdPercentage?: boolean | undefined, currentSliPercentage?: boolean | undefined, errorBudgetRemainingPercentage?: boolean | undefined, errorBudgetRemainingSeconds?: boolean | undefined, errorBudgetTotalSeconds?: boolean | undefined, currentBurnRate?: boolean | undefined, sloStatus?: boolean | undefined, statusChangeNotificationSentAt?: boolean | undefined, lastEvaluatedAt?: boolean | undefined, nextEvaluationAt?: boolean | undefined, lastAccumulatedBucketEndAt?: boolean | undefined, createdByUserId?: boolean | undefined}; export type CreateApiServiceLevelObjectiveIdGetItemArgs = {id: string, body: {select?: ServiceLevelObjectiveSelectSchema | undefined}}; export type CreateApiServiceLevelObjectiveIdGetItemOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const serviceLevelObjective = z.object({_id: z.string().optional(), createdAt: z.object({}).optional(), updatedAt: z.object({}).optional(), deletedAt: z.object({}).optional(), version: z.number().optional(), projectId: z.string(), name: z.string(), description: z.string().optional(), slug: z.string(), labels: z.array(z.object({_id: z.string().optional()})).optional(), isEnabled: z.boolean(), isArchived: z.boolean(), archivedAt: z.object({}).optional(), archivedByUserId: z.string().optional(), sliType: z.enum(["Monitor Uptime", "Metric"]), multiMonitorMode: z.enum(["Any Monitor Down", "Monitor Seconds Average"]), monitors: z.array(z.object({_id: z.string().optional()})).optional(), monitorLabels: z.array(z.object({_id: z.string().optional()})).optional(), autoAddedMonitors: z.array(z.object({_id: z.string().optional()})).optional(), downtimeMonitorStatuses: z.array(z.object({_id: z.string().optional()})).optional(), metricQueryConfig: z.object({}).optional(), targetPercentage: z.number(), windowType: z.enum(["Rolling", "Calendar Month"]), windowDays: z.number(), timezone: z.string().optional(), atRiskThresholdPercentage: z.number(), currentSliPercentage: z.number().optional(), errorBudgetRemainingPercentage: z.number().optional(), errorBudgetRemainingSeconds: z.number().optional(), errorBudgetTotalSeconds: z.number().optional(), currentBurnRate: z.number().optional(), sloStatus: z.enum(["Healthy", "At Risk", "Budget Exhausted", "Misconfigured", "Paused"]), statusChangeNotificationSentAt: z.object({}).optional(), lastEvaluatedAt: z.object({}).optional(), nextEvaluationAt: z.object({}).optional(), lastAccumulatedBucketEndAt: z.object({}).optional(), createdByUserId: z.string().optional()}); export const createApiServiceLevelObjectiveIdGetItemResponse = z.object({data: serviceLevelObjective.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 Service Level Objective * * POST /service-level-objective/{id}/get-item */ export const createApiServiceLevelObjectiveIdGetItem = async (args: CreateApiServiceLevelObjectiveIdGetItemArgs, options?: CreateApiServiceLevelObjectiveIdGetItemOptions) => { 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/${encodeURIComponent(String(args.id))}/get-item${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(createApiServiceLevelObjectiveIdGetItemResponse, await res.json()) };