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 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 MarkdownFilter = 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 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 EntityArrayFilter = Array | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'Includes', value: Array}; export type BooleanFilter = boolean | {_type: 'EqualTo', value: boolean} | {_type: 'NotEqual', value: boolean} | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'EqualToOrNull', value: boolean}; 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 VeryLongTextFilter = 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 IncidentEpisodeQuerySchema = {_id?: ObjectIDFilter | undefined, createdAt?: DateFilter | undefined, updatedAt?: DateFilter | undefined, deletedAt?: DateFilter | undefined, projectId?: ObjectIDFilter | undefined, title?: LongTextFilter | undefined, description?: MarkdownFilter | undefined, episodeNumber?: NumberFilter | undefined, episodeNumberWithPrefix?: ShortTextFilter | undefined, currentIncidentStateId?: ObjectIDFilter | undefined, incidentSeverityId?: ObjectIDFilter | undefined, rootCause?: MarkdownFilter | undefined, lastIncidentAddedAt?: DateFilter | undefined, resolvedAt?: DateFilter | undefined, allIncidentsResolvedAt?: DateFilter | undefined, firstPagedAt?: DateFilter | undefined, assignedToUserId?: ObjectIDFilter | undefined, assignedToTeamId?: ObjectIDFilter | undefined, onCallDutyPolicies?: EntityArrayFilter | undefined, isOnCallPolicyExecuted?: BooleanFilter | undefined, incidentCount?: NumberFilter | undefined, titleTemplate?: LongTextFilter | undefined, descriptionTemplate?: LongTextFilter | undefined, isManuallyCreated?: BooleanFilter | undefined, labels?: EntityArrayFilter | undefined, createdByUserId?: ObjectIDFilter | undefined, isOwnerNotifiedOfEpisodeCreation?: BooleanFilter | undefined, groupingKey?: LongTextFilter | undefined, incidentGroupingRuleId?: ObjectIDFilter | undefined, remediationNotes?: MarkdownFilter | undefined, postmortemNote?: MarkdownFilter | undefined, postUpdatesToWorkspaceChannels?: JSONFilter | undefined, isVisibleOnStatusPage?: BooleanFilter | undefined, declaredAt?: DateFilter | undefined, shouldStatusPageSubscribersBeNotifiedOnEpisodeCreated?: BooleanFilter | undefined, subscriberNotificationStatusMessage?: VeryLongTextFilter | undefined, isPrivate?: BooleanFilter | 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 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 IncidentEpisodeSelectSchema = {_id?: boolean | undefined, createdAt?: boolean | undefined, updatedAt?: boolean | undefined, deletedAt?: boolean | undefined, projectId?: boolean | undefined, title?: boolean | undefined, description?: boolean | undefined, episodeNumber?: boolean | undefined, episodeNumberWithPrefix?: boolean | undefined, currentIncidentStateId?: boolean | undefined, incidentSeverityId?: boolean | undefined, rootCause?: boolean | undefined, lastIncidentAddedAt?: boolean | undefined, resolvedAt?: boolean | undefined, allIncidentsResolvedAt?: boolean | undefined, firstPagedAt?: boolean | undefined, assignedToUserId?: boolean | undefined, assignedToTeamId?: boolean | undefined, onCallDutyPolicies?: OnCallDutyPolicyRelationSelectSchema | undefined, isOnCallPolicyExecuted?: boolean | undefined, incidentCount?: boolean | undefined, titleTemplate?: boolean | undefined, descriptionTemplate?: boolean | undefined, isManuallyCreated?: boolean | undefined, labels?: LabelRelationSelectSchema | undefined, createdByUserId?: boolean | undefined, isOwnerNotifiedOfEpisodeCreation?: boolean | undefined, groupingKey?: boolean | undefined, incidentGroupingRuleId?: boolean | undefined, remediationNotes?: boolean | undefined, postmortemNote?: boolean | undefined, postUpdatesToWorkspaceChannels?: boolean | undefined, isVisibleOnStatusPage?: boolean | undefined, declaredAt?: boolean | undefined, shouldStatusPageSubscribersBeNotifiedOnEpisodeCreated?: boolean | undefined, subscriberNotificationStatusMessage?: boolean | undefined, isPrivate?: boolean | undefined}; export type SortOrder = 'ASC' | 'DESC'; export type IncidentEpisodeSortSchema = {_id?: SortOrder | undefined, createdAt?: SortOrder | undefined, updatedAt?: SortOrder | undefined, deletedAt?: SortOrder | undefined, projectId?: SortOrder | undefined, title?: SortOrder | undefined, episodeNumber?: SortOrder | undefined, episodeNumberWithPrefix?: SortOrder | undefined, currentIncidentStateId?: SortOrder | undefined, incidentSeverityId?: SortOrder | undefined, lastIncidentAddedAt?: SortOrder | undefined, resolvedAt?: SortOrder | undefined, allIncidentsResolvedAt?: SortOrder | undefined, firstPagedAt?: SortOrder | undefined, assignedToUserId?: SortOrder | undefined, assignedToTeamId?: SortOrder | undefined, isOnCallPolicyExecuted?: SortOrder | undefined, incidentCount?: SortOrder | undefined, titleTemplate?: SortOrder | undefined, descriptionTemplate?: SortOrder | undefined, isManuallyCreated?: SortOrder | undefined, createdByUserId?: SortOrder | undefined, isOwnerNotifiedOfEpisodeCreation?: SortOrder | undefined, groupingKey?: SortOrder | undefined, incidentGroupingRuleId?: SortOrder | undefined, isVisibleOnStatusPage?: SortOrder | undefined, declaredAt?: SortOrder | undefined, shouldStatusPageSubscribersBeNotifiedOnEpisodeCreated?: SortOrder | undefined, subscriberNotificationStatusMessage?: SortOrder | undefined, isPrivate?: SortOrder | undefined}; export type CreateApiIncidentEpisodeGetListArgs = {body: {query?: IncidentEpisodeQuerySchema | undefined, select?: IncidentEpisodeSelectSchema | undefined, sort?: IncidentEpisodeSortSchema | undefined, limit?: number | undefined, skip?: number | undefined}}; export type CreateApiIncidentEpisodeGetListOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const incidentEpisode = 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(), title: z.string(), description: z.string().optional(), episodeNumber: z.number().optional(), episodeNumberWithPrefix: z.string().optional(), currentIncidentStateId: z.string(), incidentSeverityId: z.string().optional(), rootCause: z.string().optional(), lastIncidentAddedAt: z.object({}).optional(), resolvedAt: z.object({}).optional(), allIncidentsResolvedAt: z.object({}).optional(), firstPagedAt: z.object({}).optional(), assignedToUserId: z.string().optional(), assignedToTeamId: z.string().optional(), onCallDutyPolicies: z.array(z.object({_id: z.string().optional()})).optional(), isOnCallPolicyExecuted: z.boolean(), incidentCount: z.number(), titleTemplate: z.string().optional(), descriptionTemplate: z.string().optional(), isManuallyCreated: z.boolean(), labels: z.array(z.object({_id: z.string().optional()})).optional(), createdByUserId: z.string().optional(), isOwnerNotifiedOfEpisodeCreation: z.boolean(), groupingKey: z.string().optional(), incidentGroupingRuleId: z.string().optional(), remediationNotes: z.string().optional(), postmortemNote: z.string().optional(), postUpdatesToWorkspaceChannels: z.object({}).optional(), isVisibleOnStatusPage: z.boolean(), declaredAt: z.object({}).optional(), shouldStatusPageSubscribersBeNotifiedOnEpisodeCreated: z.boolean().optional(), subscriberNotificationStatusOnEpisodeCreated: z.enum(["Skipped", "Pending", "InProgress", "Success", "Failed"]).optional(), subscriberNotificationStatusMessage: z.string().optional(), isPrivate: z.boolean().optional()}); export const createApiIncidentEpisodeGetListResponse = z.object({data: z.array(incidentEpisode).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 Episode * * POST /incident-episode/get-list */ export const createApiIncidentEpisodeGetList = async (args: CreateApiIncidentEpisodeGetListArgs, options?: CreateApiIncidentEpisodeGetListOptions) => { 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-episode/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(createApiIncidentEpisodeGetListResponse, await res.json()) };