import {z} from 'zod' export type VMwareVCenterCreateSchema = {projectId?: string | undefined, name: string, description?: string | undefined, isArchived?: boolean | undefined, labels?: (Array<{id?: string | undefined}>) | undefined, retainTelemetryDataForDays?: number | undefined, telemetryRetentionConfig?: Record | undefined, collectionMethod?: ('Agent' | 'Probe') | undefined, vcenterUrl?: string | undefined, vcenterUsername?: string | undefined, vcenterPassword?: string | undefined, collectionProbeId?: string | undefined, trustedCertificateFingerprint?: string | undefined, collectionIntervalInMinutes?: number | undefined}; export type CreateApiVmwareVcenterArgs = {body: {data: VMwareVCenterCreateSchema}}; export type CreateApiVmwareVcenterOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const vMwareVCenterReadSchema = 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(), lastSeenAt: z.object({}).optional(), datacenterCount: z.number().optional(), clusterCount: z.number().optional(), hostCount: z.number().optional(), vmCount: z.number().optional(), poweredOnVmCount: z.number().optional(), datastoreCount: z.number().optional(), resourcePoolCount: z.number().optional(), datastoreCapacityBytes: z.number().optional(), datastoreUsedBytes: 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(), collectionMethod: z.enum(["Agent", "Probe"]).optional(), vcenterUrl: z.string().optional(), vcenterUsername: z.string().optional(), isVCenterPasswordSet: z.boolean().optional(), vcenterCredentialsUpdatedAt: z.object({}).optional(), collectionProbeId: z.string().optional(), trustedCertificateFingerprint: z.string().optional(), collectionIntervalInMinutes: z.number().optional(), collectionStatus: z.enum(["Pending", "Succeeded", "Failed"]).optional(), collectionErrorCode: z.enum(["InvalidAddress", "AddressNotAllowed", "AddressNotFound", "ConnectionRefused", "ConnectionTimedOut", "ConnectionFailed", "TlsFailed", "UntrustedCertificate", "CertificateChanged", "NotVSphere", "InvalidLogin", "NoPermission", "ApiError", "TimedOut", "PayloadTooLarge", "ProbeNotAllowed", "ProbeNotAvailable", "Internal"]).optional(), collectionError: z.string().optional(), presentedCertificate: z.object({}).optional(), collectionSummary: z.object({}).optional(), nextCollectionAt: z.object({}).optional(), lastCollectionAt: z.object({}).optional(), lastSuccessfulCollectionAt: z.object({}).optional(), collectionSettingsVersion: z.number().optional()}); export const createApiVmwareVcenterResponse = z.object({data: vMwareVCenterReadSchema.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 vCenter * * POST /vmware-vcenter */ export const createApiVmwareVcenter = async (args: CreateApiVmwareVcenterArgs, options?: CreateApiVmwareVcenterOptions) => { 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(/\/+$/, '')}/vmware-vcenter${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(createApiVmwareVcenterResponse, await res.json()) };