import {z} from 'zod' export type HostUpdateSchema = {name?: string | undefined, description?: string | undefined, hostIdentifier?: string | undefined, otelCollectorStatus?: string | undefined, agentVersion?: string | undefined, lastSeenAt?: Record | undefined, osType?: string | undefined, osVersion?: string | undefined, hostId?: string | undefined, hostArch?: string | undefined, hostType?: string | undefined, hostIpAddresses?: string | undefined, cpuCores?: number | undefined, totalMemoryBytes?: number | undefined, processCount?: number | undefined, containerRuntime?: string | undefined, openStackCloudId?: 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, collectorConfigId?: string | undefined, isCollectorConfigPinned?: boolean | undefined, collectorFailedConfigHash?: string | undefined}; export type UpdateApiHostIdArgs = {id: string, body: {data: HostUpdateSchema}}; export type UpdateApiHostIdOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const hostReadSchema = 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(), hostIdentifier: z.string(), otelCollectorStatus: z.string().optional(), agentVersion: z.string().optional(), lastSeenAt: z.object({}).optional(), osType: z.string().optional(), osVersion: z.string().optional(), hostId: z.string().optional(), hostArch: z.string().optional(), hostType: z.string().optional(), hostIpAddresses: z.string().optional(), cpuCores: z.number().optional(), totalMemoryBytes: z.number().optional(), processCount: z.number().optional(), containerRuntime: z.string().optional(), dockerHostId: z.string().optional(), kubernetesClusterId: z.string().optional(), proxmoxClusterId: z.string().optional(), openStackCloudId: 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(), deploymentEnvironment: z.string().optional(), runtimeName: z.string().optional(), runtimeVersion: z.string().optional(), cloudProvider: z.string().optional(), cloudPlatform: z.string().optional(), cloudRegion: z.string().optional(), cloudAccountId: z.string().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(), collectorInstanceUid: z.string().optional(), collectorLastContactAt: z.object({}).optional(), collectorRegisteredAt: z.object({}).optional(), collectorConfigId: z.string().optional(), isCollectorConfigPinned: z.boolean().optional(), collectorConfigVersionId: z.string().optional(), collectorConfigHash: z.string().optional(), collectorConfigStatus: z.enum(["waiting", "applying", "applied", "failed"]).optional(), collectorConfigError: z.string().optional(), collectorFailedConfigHash: z.string().optional(), isCollectorHealthy: z.boolean().optional(), collectorHealthError: z.string().optional(), collectorHostFeatures: z.string().optional(), latestCpuPercent: z.number().optional(), latestMemoryPercent: z.number().optional(), latestSwapPercent: z.number().optional(), latestDiskPercent: z.number().optional(), latestDiskMountpoint: z.string().optional(), latestInodesPercent: z.number().optional(), latestInodesMountpoint: z.string().optional(), latestLoadAverage15m: z.number().optional(), bootedAt: z.object({}).optional(), failedSystemdUnitCount: z.number().optional(), failedSystemdUnits: z.object({}).optional(), readingsUpdatedAt: z.object({}).optional()}); export const updateApiHostIdResponse = z.object({data: hostReadSchema.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 Host * * PUT /host/{id} */ export const updateApiHostId = async (args: UpdateApiHostIdArgs, options?: UpdateApiHostIdOptions) => { 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(/\/+$/, '')}/host/${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(updateApiHostIdResponse, await res.json()) };