import {z} from 'zod' export type ScheduledMaintenanceCreateSchema = {projectId?: string | undefined, title: string, description?: string | undefined, monitors?: (Array<{id?: string | undefined}>) | undefined, hosts?: (Array<{id?: string | undefined}>) | undefined, kubernetesClusters?: (Array<{id?: string | undefined}>) | undefined, dockerHosts?: (Array<{id?: string | undefined}>) | undefined, podmanHosts?: (Array<{id?: string | undefined}>) | undefined, proxmoxClusters?: (Array<{id?: string | undefined}>) | undefined, openStackClouds?: (Array<{id?: string | undefined}>) | undefined, vmwareVCenters?: (Array<{id?: string | undefined}>) | undefined, iotFleets?: (Array<{id?: string | undefined}>) | undefined, networkSites?: (Array<{id?: string | undefined}>) | undefined, dockerSwarmClusters?: (Array<{id?: string | undefined}>) | undefined, cephClusters?: (Array<{id?: string | undefined}>) | undefined, storageArrays?: (Array<{id?: string | undefined}>) | undefined, databaseServers?: (Array<{id?: string | undefined}>) | undefined, dataStoreIds?: Record | undefined, openStackParts?: Record | undefined, services?: (Array<{id?: string | undefined}>) | undefined, statusPages?: (Array<{id?: string | undefined}>) | undefined, labels?: (Array<{id?: string | undefined}>) | undefined, currentScheduledMaintenanceStateId?: string | undefined, changeMonitorStatusToId?: string | undefined, startsAt: Record, endsAt: Record, shouldStatusPageSubscribersBeNotifiedOnEventCreated?: boolean | undefined, shouldStatusPageSubscribersBeNotifiedWhenEventChangedToOngoing?: boolean | undefined, shouldStatusPageSubscribersBeNotifiedWhenEventChangedToEnded?: boolean | undefined, customFields?: Record | undefined, sendSubscriberNotificationsOnBeforeTheEvent?: Record | undefined, nextSubscriberNotificationBeforeTheEventAt?: Record | undefined, isVisibleOnStatusPage?: boolean | undefined, publishOnStatusPageAt?: Record | undefined, enableReminders?: boolean | undefined}; export type CreateApiScheduledMaintenanceArgs = {body: {data: ScheduledMaintenanceCreateSchema}}; export type CreateApiScheduledMaintenanceOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const scheduledMaintenanceReadSchema = z.object({_id: z.string().optional(), createdAt: z.object({}).optional(), updatedAt: z.object({}).optional(), deletedAt: z.object({}).optional(), projectId: z.string().optional(), title: z.string(), description: z.string().optional(), slug: z.string().optional(), createdByUserId: z.string().optional(), monitors: z.array(z.object({id: z.string().optional()})).optional(), hosts: z.array(z.object({id: z.string().optional()})).optional(), kubernetesClusters: z.array(z.object({id: z.string().optional()})).optional(), dockerHosts: z.array(z.object({id: z.string().optional()})).optional(), podmanHosts: z.array(z.object({id: z.string().optional()})).optional(), proxmoxClusters: z.array(z.object({id: z.string().optional()})).optional(), openStackClouds: z.array(z.object({id: z.string().optional()})).optional(), vmwareVCenters: z.array(z.object({id: z.string().optional()})).optional(), iotFleets: z.array(z.object({id: z.string().optional()})).optional(), networkSites: z.array(z.object({id: z.string().optional()})).optional(), dockerSwarmClusters: z.array(z.object({id: z.string().optional()})).optional(), cephClusters: z.array(z.object({id: z.string().optional()})).optional(), storageArrays: z.array(z.object({id: z.string().optional()})).optional(), databaseServers: z.array(z.object({id: z.string().optional()})).optional(), dataStoreIds: z.object({}).optional(), openStackParts: z.object({}).optional(), services: z.array(z.object({id: z.string().optional()})).optional(), statusPages: z.array(z.object({id: z.string().optional()})).optional(), labels: z.array(z.object({id: z.string().optional()})).optional(), currentScheduledMaintenanceStateId: z.string().optional(), changeMonitorStatusToId: z.string().optional(), startsAt: z.object({}), endsAt: z.object({}), subscriberNotificationStatusMessage: z.string().optional(), shouldStatusPageSubscribersBeNotifiedOnEventCreated: z.boolean().optional(), shouldStatusPageSubscribersBeNotifiedWhenEventChangedToOngoing: z.boolean().optional(), shouldStatusPageSubscribersBeNotifiedWhenEventChangedToEnded: z.boolean().optional(), customFields: z.object({}).optional(), sendSubscriberNotificationsOnBeforeTheEvent: z.object({}).optional(), nextSubscriberNotificationBeforeTheEventAt: z.object({}).optional(), scheduledMaintenanceNumber: z.number().optional(), scheduledMaintenanceNumberWithPrefix: z.string().optional(), isVisibleOnStatusPage: z.boolean().optional(), publishOnStatusPageAt: z.object({}).optional(), enableReminders: z.boolean().optional(), nextReminderNotificationAt: z.object({}).optional(), reminderNotificationSentCount: z.number().optional()}); export const createApiScheduledMaintenanceResponse = z.object({data: scheduledMaintenanceReadSchema.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 Scheduled Maintenance Event * * POST /scheduled-maintenance */ export const createApiScheduledMaintenance = async (args: CreateApiScheduledMaintenanceArgs, options?: CreateApiScheduledMaintenanceOptions) => { 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(/\/+$/, '')}/scheduled-maintenance${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(createApiScheduledMaintenanceResponse, await res.json()) };