import {z} from 'zod' export type ConfigurationType = 'singleNode' | 'multiNode'; export type CloudProvider = {type: 'aws' | 'gcp' | 'azure', region: string, cidr?: string | undefined}; export type CouchbaseServer = {version?: string | undefined}; export type Compute = {cpu: number, ram: number}; export type DiskAWS = {type: 'gp3' | 'io2', storage: number, iops: number}; export type DiskAzure = {type: 'P6' | 'P10' | 'P15' | 'P20' | 'P30' | 'P40' | 'P50' | 'P60' | 'Ultra', storage?: (64 | 128 | 256 | 512 | 1024 | 2048 | 3072 | 4096 | 5120 | 6144 | 7168 | 8192 | 9216 | 10240 | 11264 | 12288 | 13312 | 14336 | 15360) | undefined, iops?: number | undefined, autoExpansion?: boolean | undefined}; export type DiskGCP = {type: 'pd-ssd', storage: number}; export type Node = {compute: Compute, disk: DiskAWS | DiskAzure | DiskGCP}; export type Service = 'data' | 'query' | 'index' | 'search' | 'analytics' | 'eventing'; export type ServiceGroup = {node?: Node | undefined, numOfNodes?: number | undefined, services?: Array | undefined}; export type Availability = {type: 'single' | 'multi'}; export type SupportPlan = 'basic' | 'developer pro' | 'enterprise'; export type SupportTimezone = 'ET' | 'GMT' | 'IST' | 'PT'; export type Support = {plan: SupportPlan, timezone?: SupportTimezone | undefined}; export type CreateClusterRequest = {name: string, description?: string | undefined, configurationType?: ConfigurationType | undefined, cloudProvider: CloudProvider, couchbaseServer?: CouchbaseServer | undefined, serviceGroups: Array, availability: Availability, support: Support, zones?: Array | undefined, cmekId?: string | undefined, enablePrivateDNSResolution?: boolean | undefined}; export type CreateApiV4OrganizationsOrganizationIdProjectsProjectIdClustersArgs = {body: CreateClusterRequest}; export type CreateApiV4OrganizationsOrganizationIdProjectsProjectIdClustersOptions = {baseUrl?: string | undefined, token?: string | undefined, fetch?: typeof fetch | undefined}; export const createClusterResponse = z.object({id: z.string()}); 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 Cluster * * POST /v4/organizations/{organizationId}/projects/{projectId}/clusters */ export const createApiV4OrganizationsOrganizationIdProjectsProjectIdClusters = async (args: CreateApiV4OrganizationsOrganizationIdProjectsProjectIdClustersArgs, options?: CreateApiV4OrganizationsOrganizationIdProjectsProjectIdClustersOptions) => { const {baseUrl = "https://cloudapi.cloud.couchbase.com", fetch: fetchFn = fetch, token} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") 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))}/clusters${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(createClusterResponse, await res.json()) };