import {z} from 'zod' 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 AlertSeverityRelationSelectSchema = {_id?: boolean | undefined, createdAt?: boolean | undefined, updatedAt?: boolean | undefined, deletedAt?: boolean | undefined, projectId?: boolean | undefined, name?: boolean | undefined, color?: boolean | undefined, order?: boolean | undefined, isArchived?: boolean | undefined}; 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 OnCallDutyPolicyRelationSelectSchema = {_id?: boolean | undefined, createdAt?: boolean | undefined, updatedAt?: boolean | undefined, deletedAt?: boolean | undefined, projectId?: boolean | undefined, name?: boolean | undefined, repeatPolicyIfNoOneAcknowledgesNoOfTimes?: boolean | undefined}; export type UserRelationSelectSchema = {_id?: boolean | undefined, createdAt?: boolean | undefined, updatedAt?: boolean | undefined, deletedAt?: boolean | undefined, name?: boolean | undefined, email?: boolean | undefined, profilePictureId?: boolean | undefined, twoFactorAuthEnabled?: boolean | undefined}; export type TeamRelationSelectSchema = {_id?: boolean | undefined, createdAt?: boolean | undefined, updatedAt?: boolean | undefined, deletedAt?: boolean | undefined, projectId?: boolean | undefined, name?: boolean | undefined}; export type AlertGroupingRuleSelectSchema = {_id?: boolean | undefined, createdAt?: boolean | undefined, updatedAt?: boolean | undefined, deletedAt?: boolean | undefined, criteria?: boolean | undefined, projectId?: boolean | undefined, name?: boolean | undefined, description?: boolean | undefined, priority?: boolean | undefined, isEnabled?: boolean | undefined, matchCriteria?: boolean | undefined, monitors?: MonitorRelationSelectSchema | undefined, alertSeverities?: AlertSeverityRelationSelectSchema | undefined, alertLabels?: LabelRelationSelectSchema | undefined, monitorLabels?: LabelRelationSelectSchema | undefined, alertTitlePattern?: boolean | undefined, alertDescriptionPattern?: boolean | undefined, monitorNamePattern?: boolean | undefined, monitorDescriptionPattern?: boolean | undefined, groupByMonitor?: boolean | undefined, groupBySeverity?: boolean | undefined, groupByAlertTitle?: boolean | undefined, groupByAlertLabels?: boolean | undefined, groupByMonitorLabels?: boolean | undefined, enableTimeWindow?: boolean | undefined, timeWindowMinutes?: boolean | undefined, groupByFields?: boolean | undefined, episodeTitleTemplate?: boolean | undefined, episodeDescriptionTemplate?: boolean | undefined, enableResolveDelay?: boolean | undefined, resolveDelayMinutes?: boolean | undefined, enableReopenWindow?: boolean | undefined, reopenWindowMinutes?: boolean | undefined, enableInactivityTimeout?: boolean | undefined, inactivityTimeoutMinutes?: boolean | undefined, onCallDutyPolicies?: OnCallDutyPolicyRelationSelectSchema | undefined, defaultAssignToUserId?: boolean | undefined, defaultAssignToTeamId?: boolean | undefined, episodeLabels?: LabelRelationSelectSchema | undefined, episodeOwnerUsers?: UserRelationSelectSchema | undefined, episodeOwnerTeams?: TeamRelationSelectSchema | undefined, createdByUserId?: boolean | undefined}; export type CreateApiAlertGroupingRuleIdGetItemArgs = {id: string, body: {select?: AlertGroupingRuleSelectSchema | undefined}}; export type CreateApiAlertGroupingRuleIdGetItemOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const alertGroupingRule = z.object({_id: z.string().optional(), createdAt: z.object({}).optional(), updatedAt: z.object({}).optional(), deletedAt: z.object({}).optional(), version: z.number().optional(), criteria: z.object({}).optional(), projectId: z.string(), name: z.string(), description: z.string().optional(), priority: z.number().optional(), isEnabled: z.boolean(), matchCriteria: z.object({}).optional(), monitors: z.array(z.object({_id: z.string().optional()})).optional(), alertSeverities: z.array(z.object({_id: z.string().optional()})).optional(), alertLabels: z.array(z.object({_id: z.string().optional()})).optional(), monitorLabels: z.array(z.object({_id: z.string().optional()})).optional(), alertTitlePattern: z.string().optional(), alertDescriptionPattern: z.string().optional(), monitorNamePattern: z.string().optional(), monitorDescriptionPattern: z.string().optional(), groupByMonitor: z.boolean().optional(), groupBySeverity: z.boolean().optional(), groupByAlertTitle: z.boolean().optional(), groupByAlertLabels: z.boolean().optional(), groupByMonitorLabels: z.boolean().optional(), enableTimeWindow: z.boolean().optional(), timeWindowMinutes: z.number().optional(), groupByFields: z.object({}).optional(), episodeTitleTemplate: z.string().optional(), episodeDescriptionTemplate: z.string().optional(), enableResolveDelay: z.boolean().optional(), resolveDelayMinutes: z.number().optional(), enableReopenWindow: z.boolean().optional(), reopenWindowMinutes: z.number().optional(), enableInactivityTimeout: z.boolean().optional(), inactivityTimeoutMinutes: z.number().optional(), onCallDutyPolicies: z.array(z.object({_id: z.string().optional()})).optional(), defaultAssignToUserId: z.string().optional(), defaultAssignToTeamId: z.string().optional(), episodeLabels: z.array(z.object({_id: z.string().optional()})).optional(), episodeOwnerUsers: z.array(z.object({_id: z.string().optional()})).optional(), episodeOwnerTeams: z.array(z.object({_id: z.string().optional()})).optional(), createdByUserId: z.string().optional()}); export const createApiAlertGroupingRuleIdGetItemResponse = z.object({data: alertGroupingRule.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 Alert Grouping Rule * * POST /alert-grouping-rule/{id}/get-item */ export const createApiAlertGroupingRuleIdGetItem = async (args: CreateApiAlertGroupingRuleIdGetItemArgs, options?: CreateApiAlertGroupingRuleIdGetItemOptions) => { 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(/\/+$/, '')}/alert-grouping-rule/${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(createApiAlertGroupingRuleIdGetItemResponse, await res.json()) };