import {z} from 'zod' export type CephClusterUpdateSchema = {name?: string | undefined, description?: string | undefined, fsid?: string | undefined, otelCollectorStatus?: string | undefined, agentVersion?: string | undefined, cephVersion?: string | undefined, lastSeenAt?: Record | undefined, monCount?: number | undefined, osdCount?: number | undefined, osdUpCount?: number | undefined, osdInCount?: number | undefined, poolCount?: number | undefined, healthStatus?: number | undefined, capacityUsedPercent?: number | 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 UpdateApiCephClusterIdArgs = {id: string, body: {data: CephClusterUpdateSchema}}; export type UpdateApiCephClusterIdOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const cephClusterReadSchema = 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(), fsid: z.string().optional(), otelCollectorStatus: z.string().optional(), agentVersion: z.string().optional(), cephVersion: z.string().optional(), lastSeenAt: z.object({}).optional(), monCount: z.number().optional(), osdCount: z.number().optional(), osdUpCount: z.number().optional(), osdInCount: z.number().optional(), poolCount: z.number().optional(), healthStatus: z.number().optional(), capacityUsedPercent: z.number().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 updateApiCephClusterIdResponse = z.object({data: cephClusterReadSchema.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 Ceph Cluster * * PUT /ceph-cluster/{id} */ export const updateApiCephClusterId = async (args: UpdateApiCephClusterIdArgs, options?: UpdateApiCephClusterIdOptions) => { 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(/\/+$/, '')}/ceph-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(updateApiCephClusterIdResponse, await res.json()) };