import {z} from 'zod' export type MaintenanceWindowTagList = Array; export type Model51 = Array; export type Model52 = 'MINOR' | 'MEDIUM' | 'MAJOR' | 'CRITICAL' | null; export type Model53 = Array; export type Model54 = Array; export type Model55 = Array; export type MaintenanceWindowStatusPageVisibility = {enabled?: boolean | undefined, severity?: Model52 | undefined, affectAllServices?: boolean | undefined, notifyOnStart?: boolean | undefined, notifyOnEnd?: boolean | undefined, suppressAutoIncidents?: boolean | undefined, reminderMinutesBefore?: Model53 | undefined, autoStart?: boolean | undefined, autoEnd?: boolean | undefined, showAffectedServices?: boolean | undefined, statusPageIds?: Model54 | undefined, serviceIds?: Model55 | undefined}; export type MaintenanceWindowCreate = {name: string, tags?: MaintenanceWindowTagList | undefined, startsAt: string, endsAt: string, repeatInterval?: (number | null) | undefined, repeatUnit: string, repeatEndsAt?: (string | null) | undefined, timezone?: (string | null) | undefined, pauseAllChecks?: boolean | undefined, silenceAlertsTags?: Model51 | undefined, silenceAllAlerts?: boolean | undefined, description?: (string | null) | undefined, statusPageVisibility?: MaintenanceWindowStatusPageVisibility | undefined}; export type CreateApiV1MaintenanceWindowsArgs = {'x-checkly-account'?: string | undefined, body: MaintenanceWindowCreate}; export type CreateApiV1MaintenanceWindowsOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const maintenanceWindowTagList = z.array(z.string()); export const repeatUnit = z.enum(["DAY", "WEEK", "MONTH"]).nullable(); export const model50 = z.enum(["MINOR", "MEDIUM", "MAJOR", "CRITICAL"]).nullable(); export const reminderMinutesBefore = z.array(z.number().int()); export const statusPageIds = z.array(z.string()); export const serviceIds = z.array(z.string()); export const maintenanceWindowStatusPageVisibilityResponse = z.object({enabled: z.boolean().optional(), severity: model50.optional(), affectAllServices: z.boolean().optional(), suppressAutoIncidents: z.boolean().optional(), notifyOnStart: z.boolean().optional(), notifyOnEnd: z.boolean().optional(), reminderMinutesBefore: reminderMinutesBefore.optional(), autoStart: z.boolean().optional(), autoEnd: z.boolean().optional(), showAffectedServices: z.boolean().optional(), statusPageIds: statusPageIds.optional(), serviceIds: serviceIds.optional()}); export const silenceAlertsTags = z.array(z.string()); export const bindingProjectV1 = z.object({id: z.string(), logicalId: z.string(), name: z.string()}); export const projectBindingDetailsV1 = z.object({logicalId: z.string(), pending: z.boolean(), sourceFile: z.string().nullable().optional()}); export const projectBindingOwnerV1 = z.object({project: bindingProjectV1, binding: projectBindingDetailsV1}).nullable(); export const projectBindingV1 = z.object({project: bindingProjectV1, binding: projectBindingDetailsV1}); export const projectBindingReferencesV1 = z.array(projectBindingV1); export const projectBindingsV1 = z.object({owner: projectBindingOwnerV1, references: projectBindingReferencesV1}); export const maintenanceWindow = z.object({id: z.number(), name: z.string(), tags: maintenanceWindowTagList.optional(), startsAt: z.string(), endsAt: z.string(), repeatInterval: z.number().nullable().optional(), repeatUnit: repeatUnit.optional(), repeatEndsAt: z.string().nullable().optional(), timezone: z.string(), description: z.string().nullable().optional(), statusPageVisibility: maintenanceWindowStatusPageVisibilityResponse.optional(), pauseAllChecks: z.boolean().optional(), silenceAlertsTags: silenceAlertsTags.optional(), silenceAllAlerts: z.boolean().optional(), created_at: z.string(), updated_at: z.string().nullable(), projectBindings: projectBindingsV1.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 a maintenance window * * POST /v1/maintenance-windows */ export const createApiV1MaintenanceWindows = async (args: CreateApiV1MaintenanceWindowsArgs, options?: CreateApiV1MaintenanceWindowsOptions) => { const {baseUrl = "https://api.checklyhq.com", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['x-checkly-account'] != null) headers.set("x-checkly-account", String(args['x-checkly-account'])) if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/maintenance-windows${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(maintenanceWindow, await res.json()) };