import {z} from 'zod' 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 CreateApiIncidentEpisodeIdGetItemArgs = {id: string, body: {select?: IncidentEpisodeSelectSchema | undefined}}; export type CreateApiIncidentEpisodeIdGetItemOptions = {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 createApiIncidentEpisodeIdGetItemResponse = z.object({data: incidentEpisode.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 Incident Episode * * POST /incident-episode/{id}/get-item */ export const createApiIncidentEpisodeIdGetItem = async (args: CreateApiIncidentEpisodeIdGetItemArgs, options?: CreateApiIncidentEpisodeIdGetItemOptions) => { 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/${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(createApiIncidentEpisodeIdGetItemResponse, await res.json()) };