import {z} from 'zod' export type ProxmoxClusterUpdateSchema = {name?: string | undefined, description?: string | undefined, otelCollectorStatus?: string | undefined, agentVersion?: string | undefined, pveVersion?: string | undefined, lastSeenAt?: Record | undefined, nodeCount?: number | undefined, onlineNodeCount?: number | undefined, guestCount?: number | undefined, storageCount?: number | undefined, guestsWithoutBackupCount?: number | undefined, cephClusterId?: string | undefined, isArchived?: boolean | undefined, labels?: (Array<{id?: string | undefined}>) | undefined, retainTelemetryDataForDays?: number | undefined, telemetryRetentionConfig?: Record | undefined, isAiInvestigationEnabled?: boolean | undefined, aiRemediationMode?: ('Disabled' | 'RequireApproval' | 'Automatic' | 'BypassApproval') | undefined, aiCommandAllowlist?: Record | undefined}; export type UpdateApiProxmoxClusterIdArgs = {id: string, body: {data: ProxmoxClusterUpdateSchema}}; export type UpdateApiProxmoxClusterIdOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const proxmoxClusterReadSchema = z.object({_id: z.string().optional(), createdAt: z.object({}).optional(), updatedAt: z.object({}).optional(), deletedAt: z.object({}).optional(), projectId: z.string().optional(), name: z.string(), slug: z.string().optional(), description: z.string().optional(), otelCollectorStatus: z.string().optional(), agentVersion: z.string().optional(), pveVersion: z.string().optional(), lastSeenAt: z.object({}).optional(), nodeCount: z.number().optional(), onlineNodeCount: z.number().optional(), guestCount: z.number().optional(), storageCount: z.number().optional(), guestsWithoutBackupCount: z.number().optional(), isQuorate: z.boolean().optional(), lastNotificationAt: z.object({}).optional(), cephClusterId: z.string().optional(), createdByUserId: z.string().optional(), isArchived: z.boolean().optional(), archivedAt: z.object({}).optional(), archivedByUserId: z.string().optional(), deletedByUserId: z.string().optional(), labels: z.array(z.object({id: z.string().optional()})).optional(), retainTelemetryDataForDays: z.number().optional(), telemetryRetentionConfig: z.object({}).optional(), isAiInvestigationEnabled: z.boolean().optional(), aiRemediationMode: z.enum(["Disabled", "RequireApproval", "Automatic", "BypassApproval"]).optional(), aiCommandAllowlist: z.object({}).optional(), aiAccessLastVerifiedAt: z.object({}).optional(), aiAccessLastError: z.string().optional(), aiAccessConfiguredAt: z.object({}).optional()}); export const updateApiProxmoxClusterIdResponse = z.object({data: proxmoxClusterReadSchema.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 }; /** * Update Proxmox Cluster * * PUT /proxmox-cluster/{id} */ export const updateApiProxmoxClusterId = async (args: UpdateApiProxmoxClusterIdArgs, options?: UpdateApiProxmoxClusterIdOptions) => { 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(/\/+$/, '')}/proxmox-cluster/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(updateApiProxmoxClusterIdResponse, await res.json()) };