import {z} from 'zod' export type OnCallDutyPolicyExecutionLogCreateSchema = {projectId?: string | undefined, onCallDutyPolicyId?: string | undefined, triggeredByIncidentId?: string | undefined, triggeredByAlertId?: string | undefined, triggeredByAlertEpisodeId?: string | undefined, triggeredByIncidentEpisodeId?: string | undefined, status: 'Waiting' | 'Scheduled' | 'Started' | 'Executing' | 'Execution Completed' | 'Execution Completed - No One Notified' | 'Error', statusMessage: string, userNotificationEventType: 'Incident Created' | 'Alert Created' | 'Alert Episode Created' | 'Incident Episode Created', acknowledgedAt?: Record | undefined, acknowledgedByTeamId?: string | undefined, lastExecutedEscalationRuleOrder?: number | undefined, lastEscalationRuleExecutedAt?: Record | undefined, lastExecutedEscalationRuleId?: string | undefined, executeNextEscalationRuleInMinutes?: number | undefined, onCallPolicyExecutionRepeatCount?: number | undefined}; export type CreateApiOnCallDutyPolicyExecutionLogArgs = {body: {data: OnCallDutyPolicyExecutionLogCreateSchema}}; export type CreateApiOnCallDutyPolicyExecutionLogOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const onCallDutyPolicyExecutionLogReadSchema = z.object({_id: z.string().optional(), createdAt: z.object({}).optional(), updatedAt: z.object({}).optional(), deletedAt: z.object({}).optional(), projectId: z.string().optional(), onCallDutyPolicyId: z.string().optional(), triggeredByIncidentId: z.string().optional(), triggeredByAlertId: z.string().optional(), triggeredByAlertEpisodeId: z.string().optional(), triggeredByIncidentEpisodeId: z.string().optional(), status: z.enum(["Waiting", "Scheduled", "Started", "Executing", "Execution Completed", "Execution Completed - No One Notified", "Error"]), statusMessage: z.string(), userNotificationEventType: z.enum(["Incident Created", "Alert Created", "Alert Episode Created", "Incident Episode Created"]), createdByUserId: z.string().optional(), deletedByUserId: z.string().optional(), acknowledgedByUserId: z.string().optional(), acknowledgedAt: z.object({}).optional(), acknowledgedByTeamId: z.string().optional(), lastExecutedEscalationRuleOrder: z.number().optional(), lastExecutedEscalationRuleId: z.string().optional(), onCallPolicyExecutionRepeatCount: z.number().optional(), scheduleGapRetryCount: z.number().optional(), pagingStartsAt: z.object({}).optional(), pagingStartedEarlyReason: z.string().optional(), aiHoldOutcome: z.enum(["Holding", "Resolved by AI", "Recovered on its own", "Handled by a person", "Handed off", "Hold time ran out", "Page now pressed"]).optional(), acknowledgementTimeoutStartedAt: z.object({}).optional(), pageAgainNumber: z.number().optional(), triggeredByUserId: z.string().optional(), triggeredByWorkflowId: z.string().optional(), triggeredByWorkflowName: z.string().optional(), pageMessage: z.string().optional()}); export const createApiOnCallDutyPolicyExecutionLogResponse = z.object({data: onCallDutyPolicyExecutionLogReadSchema.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 }; /** * Create On-Call Duty Execution Log * * POST /on-call-duty-policy-execution-log */ export const createApiOnCallDutyPolicyExecutionLog = async (args: CreateApiOnCallDutyPolicyExecutionLogArgs, options?: CreateApiOnCallDutyPolicyExecutionLogOptions) => { 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(/\/+$/, '')}/on-call-duty-policy-execution-log${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(createApiOnCallDutyPolicyExecutionLogResponse, await res.json()) };