export type VmV2CreateRequest = {vmTypeId: number, region: string, name: string, isSpot: boolean, volumeMountPaths?: {[key: string]: string} | undefined}; export type CreateApiV2VmsArgs = {body: VmV2CreateRequest}; export type CreateApiV2VmsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Create VM * * POST /v2/vms */ export const createApiV2Vms = async (args: CreateApiV2VmsArgs, options: CreateApiV2VmsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "*/*") const url = `${baseUrl.replace(/\/+$/, '')}/v2/vms${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 res.blob() };