import {z} from 'zod' export type ObjectIDFilter = string | {_type: 'EqualTo', value: string} | {_type: 'NotEqual', value: string} | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'EqualToOrNull', value: string} | {_type: 'Includes', value: Array}; export type DateFilter = string | {_type: 'EqualTo', value: string} | {_type: 'NotEqual', value: string} | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'EqualToOrNull', value: string} | {_type: 'GreaterThan', value: string} | {_type: 'LessThan', value: string} | {_type: 'GreaterThanOrEqual', value: string} | {_type: 'LessThanOrEqual', value: string} | {_type: 'InBetween', startValue: string, endValue: string}; export type JSONFilter = {_type: 'IsNull'} | {_type: 'NotNull'} | {[key: string]: string | number | boolean | {_type: 'EqualTo', value: string | number | boolean} | {_type: 'NotEqual', value: string | number | boolean} | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'EqualToOrNull', value: string | number | boolean} | {_type: 'Search', value: string} | {_type: 'Includes', value: Array} | {_type: 'GreaterThan', value: string | number | boolean} | {_type: 'LessThan', value: string | number | boolean} | {_type: 'GreaterThanOrEqual', value: string | number | boolean} | {_type: 'LessThanOrEqual', value: string | number | boolean} | {_type: 'InBetween', startValue: string | number | boolean, endValue: string | number | boolean}}; export type ShortTextFilter = string | {_type: 'EqualTo', value: string} | {_type: 'NotEqual', value: string} | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'EqualToOrNull', value: string} | {_type: 'Search', value: string} | {_type: 'Includes', value: Array}; export type LongTextFilter = string | {_type: 'EqualTo', value: string} | {_type: 'NotEqual', value: string} | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'EqualToOrNull', value: string} | {_type: 'Search', value: string} | {_type: 'Includes', value: Array}; export type NumberFilter = number | {_type: 'EqualTo', value: number} | {_type: 'NotEqual', value: number} | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'EqualToOrNull', value: number} | {_type: 'GreaterThan', value: number} | {_type: 'LessThan', value: number} | {_type: 'GreaterThanOrEqual', value: number} | {_type: 'LessThanOrEqual', value: number} | {_type: 'InBetween', startValue: number, endValue: number}; export type BooleanFilter = boolean | {_type: 'EqualTo', value: boolean} | {_type: 'NotEqual', value: boolean} | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'EqualToOrNull', value: boolean}; export type EntityArrayFilter = Array | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'Includes', value: Array}; export type IncidentGroupingRuleQuerySchema = {_id?: ObjectIDFilter | undefined, createdAt?: DateFilter | undefined, updatedAt?: DateFilter | undefined, deletedAt?: DateFilter | undefined, criteria?: JSONFilter | undefined, projectId?: ObjectIDFilter | undefined, name?: ShortTextFilter | undefined, description?: LongTextFilter | undefined, priority?: NumberFilter | undefined, isEnabled?: BooleanFilter | undefined, matchCriteria?: JSONFilter | undefined, monitors?: EntityArrayFilter | undefined, incidentSeverities?: EntityArrayFilter | undefined, incidentLabels?: EntityArrayFilter | undefined, monitorLabels?: EntityArrayFilter | undefined, incidentTitlePattern?: LongTextFilter | undefined, incidentDescriptionPattern?: LongTextFilter | undefined, monitorNamePattern?: LongTextFilter | undefined, monitorDescriptionPattern?: LongTextFilter | undefined, groupByMonitor?: BooleanFilter | undefined, groupBySeverity?: BooleanFilter | undefined, groupByIncidentTitle?: BooleanFilter | undefined, groupByIncidentLabels?: BooleanFilter | undefined, groupByMonitorLabels?: BooleanFilter | undefined, enableTimeWindow?: BooleanFilter | undefined, timeWindowMinutes?: NumberFilter | undefined, groupByFields?: JSONFilter | undefined, episodeTitleTemplate?: LongTextFilter | undefined, episodeDescriptionTemplate?: LongTextFilter | undefined, enableResolveDelay?: BooleanFilter | undefined, resolveDelayMinutes?: NumberFilter | undefined, enableReopenWindow?: BooleanFilter | undefined, reopenWindowMinutes?: NumberFilter | undefined, enableInactivityTimeout?: BooleanFilter | undefined, inactivityTimeoutMinutes?: NumberFilter | undefined, onCallDutyPolicies?: EntityArrayFilter | undefined, defaultAssignToUserId?: ObjectIDFilter | undefined, defaultAssignToTeamId?: ObjectIDFilter | undefined, episodeLabels?: EntityArrayFilter | undefined, episodeOwnerUsers?: EntityArrayFilter | undefined, episodeOwnerTeams?: EntityArrayFilter | undefined, episodeMemberRoles?: EntityArrayFilter | undefined, episodeMemberRoleAssignments?: JSONFilter | undefined, createdByUserId?: ObjectIDFilter | undefined, showEpisodeOnStatusPage?: BooleanFilter | 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 IncidentSeverityRelationSelectSchema = {_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 IncidentRoleRelationSelectSchema = {_id?: boolean | undefined, createdAt?: boolean | undefined, updatedAt?: boolean | undefined, deletedAt?: boolean | undefined, projectId?: boolean | undefined, name?: boolean | undefined, color?: boolean | undefined, roleIcon?: boolean | undefined, isArchived?: boolean | undefined}; export type IncidentGroupingRuleSelectSchema = {_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, incidentSeverities?: IncidentSeverityRelationSelectSchema | undefined, incidentLabels?: LabelRelationSelectSchema | undefined, monitorLabels?: LabelRelationSelectSchema | undefined, incidentTitlePattern?: boolean | undefined, incidentDescriptionPattern?: boolean | undefined, monitorNamePattern?: boolean | undefined, monitorDescriptionPattern?: boolean | undefined, groupByMonitor?: boolean | undefined, groupBySeverity?: boolean | undefined, groupByIncidentTitle?: boolean | undefined, groupByIncidentLabels?: 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, episodeMemberRoles?: IncidentRoleRelationSelectSchema | undefined, episodeMemberRoleAssignments?: boolean | undefined, createdByUserId?: boolean | undefined, showEpisodeOnStatusPage?: boolean | undefined}; export type SortOrder = 'ASC' | 'DESC'; export type IncidentGroupingRuleSortSchema = {_id?: SortOrder | undefined, createdAt?: SortOrder | undefined, updatedAt?: SortOrder | undefined, deletedAt?: SortOrder | undefined, projectId?: SortOrder | undefined, name?: SortOrder | undefined, description?: SortOrder | undefined, priority?: SortOrder | undefined, isEnabled?: SortOrder | undefined, incidentTitlePattern?: SortOrder | undefined, incidentDescriptionPattern?: SortOrder | undefined, monitorNamePattern?: SortOrder | undefined, monitorDescriptionPattern?: SortOrder | undefined, groupByMonitor?: SortOrder | undefined, groupBySeverity?: SortOrder | undefined, groupByIncidentTitle?: SortOrder | undefined, groupByIncidentLabels?: SortOrder | undefined, groupByMonitorLabels?: SortOrder | undefined, enableTimeWindow?: SortOrder | undefined, timeWindowMinutes?: SortOrder | undefined, episodeTitleTemplate?: SortOrder | undefined, episodeDescriptionTemplate?: SortOrder | undefined, enableResolveDelay?: SortOrder | undefined, resolveDelayMinutes?: SortOrder | undefined, enableReopenWindow?: SortOrder | undefined, reopenWindowMinutes?: SortOrder | undefined, enableInactivityTimeout?: SortOrder | undefined, inactivityTimeoutMinutes?: SortOrder | undefined, defaultAssignToUserId?: SortOrder | undefined, defaultAssignToTeamId?: SortOrder | undefined, createdByUserId?: SortOrder | undefined, showEpisodeOnStatusPage?: SortOrder | undefined}; export type CreateApiIncidentGroupingRuleGetListArgs = {body: {query?: IncidentGroupingRuleQuerySchema | undefined, select?: IncidentGroupingRuleSelectSchema | undefined, sort?: IncidentGroupingRuleSortSchema | undefined, limit?: number | undefined, skip?: number | undefined}}; export type CreateApiIncidentGroupingRuleGetListOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const incidentGroupingRule = 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(), incidentSeverities: z.array(z.object({_id: z.string().optional()})).optional(), incidentLabels: z.array(z.object({_id: z.string().optional()})).optional(), monitorLabels: z.array(z.object({_id: z.string().optional()})).optional(), incidentTitlePattern: z.string().optional(), incidentDescriptionPattern: z.string().optional(), monitorNamePattern: z.string().optional(), monitorDescriptionPattern: z.string().optional(), groupByMonitor: z.boolean().optional(), groupBySeverity: z.boolean().optional(), groupByIncidentTitle: z.boolean().optional(), groupByIncidentLabels: 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(), episodeMemberRoles: z.array(z.object({_id: z.string().optional()})).optional(), episodeMemberRoleAssignments: z.object({}).optional(), createdByUserId: z.string().optional(), showEpisodeOnStatusPage: z.boolean()}); export const createApiIncidentGroupingRuleGetListResponse = z.object({data: z.array(incidentGroupingRule).optional(), count: z.number().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 }; /** * List Incident Grouping Rule * * POST /incident-grouping-rule/get-list */ export const createApiIncidentGroupingRuleGetList = async (args: CreateApiIncidentGroupingRuleGetListArgs, options?: CreateApiIncidentGroupingRuleGetListOptions) => { 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(/\/+$/, '')}/incident-grouping-rule/get-list${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(createApiIncidentGroupingRuleGetListResponse, await res.json()) };