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 AlertEpisodeSelectSchema = {_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, currentAlertStateId?: boolean | undefined, alertSeverityId?: boolean | undefined, rootCause?: boolean | undefined, lastAlertAddedAt?: boolean | undefined, resolvedAt?: boolean | undefined, allAlertsResolvedAt?: boolean | undefined, firstPagedAt?: boolean | undefined, assignedToUserId?: boolean | undefined, assignedToTeamId?: boolean | undefined, alertGroupingRuleId?: boolean | undefined, onCallDutyPolicies?: OnCallDutyPolicyRelationSelectSchema | undefined, isOnCallPolicyExecuted?: boolean | undefined, alertCount?: boolean | undefined, titleTemplate?: boolean | undefined, descriptionTemplate?: boolean | undefined, isManuallyCreated?: boolean | undefined, labels?: LabelRelationSelectSchema | undefined, createdByUserId?: boolean | undefined, isOwnerNotifiedOfEpisodeCreation?: boolean | undefined, groupingKey?: boolean | undefined, remediationNotes?: boolean | undefined, postUpdatesToWorkspaceChannels?: boolean | undefined, isPrivate?: boolean | undefined}; export type CreateApiAlertEpisodeIdGetItemArgs = {id: string, body: {select?: AlertEpisodeSelectSchema | undefined}}; export type CreateApiAlertEpisodeIdGetItemOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const alertEpisode = 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(), currentAlertStateId: z.string(), alertSeverityId: z.string().optional(), rootCause: z.string().optional(), lastAlertAddedAt: z.object({}).optional(), resolvedAt: z.object({}).optional(), allAlertsResolvedAt: z.object({}).optional(), firstPagedAt: z.object({}).optional(), assignedToUserId: z.string().optional(), assignedToTeamId: z.string().optional(), alertGroupingRuleId: z.string().optional(), onCallDutyPolicies: z.array(z.object({_id: z.string().optional()})).optional(), isOnCallPolicyExecuted: z.boolean(), alertCount: 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(), remediationNotes: z.string().optional(), postUpdatesToWorkspaceChannels: z.object({}).optional(), isPrivate: z.boolean().optional()}); export const createApiAlertEpisodeIdGetItemResponse = z.object({data: alertEpisode.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 Episode * * POST /alert-episode/{id}/get-item */ export const createApiAlertEpisodeIdGetItem = async (args: CreateApiAlertEpisodeIdGetItemArgs, options?: CreateApiAlertEpisodeIdGetItemOptions) => { 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-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(createApiAlertEpisodeIdGetItemResponse, await res.json()) };