import {z} from 'zod' export type GetApiV4OrganizationsOrganizationIdOperationalInsightsClustersArgs = {page?: number | undefined, perPage?: number | undefined, sortBy?: Array | undefined, sortDirection?: ('asc' | 'desc') | undefined}; export type GetApiV4OrganizationsOrganizationIdOperationalInsightsClustersOptions = {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 pages = z.object({page: z.number().int(), next: z.number().int().optional(), previous: z.number().int().optional(), last: z.number().int(), perPage: z.number().int(), totalItems: z.number().int()}); export const hrefs = z.object({first: z.string(), last: z.string(), previous: z.string(), next: z.string()}); export const cursor = z.object({pages: pages, hrefs: hrefs}); export const getColumnarAnalyticsClustersResponse = z.object({data: z.array(getColumnarAnalyticsClusterResponse), cursor: cursor}); 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 }; /** * List Organization Level Operational Insights Clusters * * GET /v4/organizations/{organizationId}/operationalInsightsClusters */ export const getApiV4OrganizationsOrganizationIdOperationalInsightsClusters = async (args: GetApiV4OrganizationsOrganizationIdOperationalInsightsClustersArgs, options?: GetApiV4OrganizationsOrganizationIdOperationalInsightsClustersOptions) => { 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 (args.page != null) query.append("page", String(args.page)) if (args.perPage != null) query.append("perPage", String(args.perPage)) for (const item of args.sortBy ?? []) query.append("sortBy", String(item)) if (args.sortDirection != null) query.append("sortDirection", String(args.sortDirection)) if (token !== undefined) headers.set('authorization', `Bearer ${token}`) const url = `${baseUrl.replace(/\/+$/, '')}/v4/organizations/${encodeURIComponent(String(args.organizationId))}/operationalInsightsClusters${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(getColumnarAnalyticsClustersResponse, await res.json()) };