import {z} from 'zod' export type GetApiV4OrganizationsOrganizationIdProjectsProjectIdOperationalInsightsClustersAnalyticsClusterIdOptions = {baseUrl?: string | undefined, token?: string | undefined, fetch?: typeof fetch | undefined}; export const currentColumnarState = z.enum(["deploying", "deploymentFailed", "destroying", "destroyFailed", "healthy", "scaling", "scaleFailed", "turningOff", "turningOffFailed", "turnedOff", "turningOn", "turningOnFailed", "restoring", "restoringFailed", "peering", "upgrading"]); export const columnarSupport = z.object({plan: z.enum(["developer pro", "enterprise"]), timezone: z.enum(["ET", "GMT", "IST", "PT"])}); export const compute = z.object({cpu: z.number().int(), ram: z.number().int()}); export const availability = z.object({type: z.enum(["single", "multi"])}); export const getColumnarAnalyticsClusterResponse = z.object({id: z.string(), name: z.string().max(256), description: z.string().max(1024).optional(), cloudProvider: z.string(), region: z.string(), nodes: z.number().int().gte(1).lte(32), currentState: currentColumnarState, support: columnarSupport, compute: compute, availability: availability}); 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 }; /** * Get Operational Insights Cluster Details * * GET /v4/organizations/{organizationId}/projects/{projectId}/operationalInsightsClusters/{analyticsClusterId} */ export const getApiV4OrganizationsOrganizationIdProjectsProjectIdOperationalInsightsClustersAnalyticsClusterId = async (options?: GetApiV4OrganizationsOrganizationIdProjectsProjectIdOperationalInsightsClustersAnalyticsClusterIdOptions) => { const {baseUrl = "https://cloudapi.cloud.couchbase.com", fetch: fetchFn = fetch, token} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (token !== undefined) headers.set('authorization', `Bearer ${token}`) const url = `${baseUrl.replace(/\/+$/, '')}/v4/organizations/${encodeURIComponent(String(args.organizationId))}/projects/${encodeURIComponent(String(args.projectId))}/operationalInsightsClusters/${encodeURIComponent(String(args.analyticsClusterId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getColumnarAnalyticsClusterResponse, await res.json()) };