@krovacloud/sdk 0.1.6 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,44 @@ All notable changes to `@krovacloud/sdk` are documented here. This project adher
4
4
  [Semantic Versioning](https://semver.org/spec/v2.0.0.html) and the
5
5
  [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) format.
6
6
 
7
+ ## 0.3.0
8
+
9
+ ### Added
10
+
11
+ - First-class typed helpers for a Cube's attached resources:
12
+ - `client.domains` — `list` / `create` / `update` / `delete` custom domains.
13
+ - `client.snapshots` — `list` / `create` / `delete`, plus `client.cubes.restore`.
14
+ - `client.tcpMappings` — `list` / `create` / `delete` TCP port mappings.
15
+ - `client.imports` — `create` / `get` / `complete` / `cancel` a `.cube` import.
16
+ - `client.backups.download` — a time-limited backup download URL.
17
+ - Exported `Domain`, `Snapshot`, `TcpMapping`, and the create/update input types.
18
+
19
+ ## 0.2.0
20
+
21
+ ### Added
22
+
23
+ - `client.getSpace()` — resolve the `Space` your API key is scoped to, so you no
24
+ longer have to hardcode a `spaceId`.
25
+ - `client.cubes.ssh(spaceId, cubeId)` — fetch a Cube's SSH connection info
26
+ (`host`, `port`, `user`, and pinned `hostKeys`).
27
+ - Exported `Space` and `CubeSshInfo` types.
28
+
29
+ ### Changed
30
+
31
+ - Refreshed the bundled OpenAPI spec to the current API (26 paths / 35
32
+ operations). `client.raw` can now reach `GET /space`, the cube SSH-info
33
+ endpoint, and the CLI device-auth endpoints, which the stale bundle omitted.
34
+
35
+ ## 0.1.6
36
+
37
+ ### Fixed
38
+
39
+ - Auto-retry no longer throws `TypeError: unusable` on requests with a body
40
+ (POST/PUT/DELETE) — a pristine copy of the request is captured before its body
41
+ is consumed, so retries of the mutating, rate-limited endpoints work.
42
+ - A hostile or misconfigured `Retry-After` is now capped at the maximum backoff
43
+ (10s), so the client can't be parked for minutes/hours.
44
+
7
45
  ## 0.1.5
8
46
 
9
47
  ### Changed
package/README.md CHANGED
@@ -82,7 +82,16 @@ new KrovaClient({
82
82
  });
83
83
  ```
84
84
 
85
- Throws if `apiKey` is missing. Exposes `client.baseUrl` (the resolved base URL), `client.cubes`, `client.catalog`, and `client.raw`.
85
+ Throws if `apiKey` is missing. Exposes `client.baseUrl` (the resolved base URL), `client.getSpace()`, `client.cubes`, `client.catalog`, and `client.raw`.
86
+
87
+ ### `client.getSpace()`
88
+
89
+ Resolve the `Space` your API key is scoped to — so you don't have to hardcode a `spaceId`:
90
+
91
+ ```ts
92
+ const space = await krova.getSpace(); // { id, name, tier, createdAt }
93
+ const cubes = await krova.cubes.list(space.id);
94
+ ```
86
95
 
87
96
  ### `client.cubes`
88
97
 
@@ -97,6 +106,7 @@ Ergonomic helpers for the Cube lifecycle. Each unwraps the response body and thr
97
106
  | `delete` | `(spaceId, cubeId)` | enqueues deletion |
98
107
  | `sleep` | `(spaceId, cubeId)` | enqueues sleep |
99
108
  | `wake` | `(spaceId, cubeId)` | enqueues wake |
109
+ | `ssh` | `(spaceId, cubeId)` | the Cube's SSH connection info (`host`, `port`, `user`, `hostKeys`) |
100
110
 
101
111
  ```ts
102
112
  // create — sshPublicKey is required; region + userData (cloud-init) are optional.
@@ -151,9 +161,54 @@ const images = await krova.catalog.images(); // available OS images
151
161
  const pricing = await krova.catalog.pricing(); // per-resource hourly rates + volume tiers
152
162
  ```
153
163
 
164
+ ### Domains, snapshots & TCP mappings
165
+
166
+ Typed helpers for a Cube's attached resources — each unwraps the response and throws `KrovaError` on failure.
167
+
168
+ ```ts
169
+ // Custom domains
170
+ const domains = await krova.domains.list("space_123", "cube_123");
171
+ const domain = await krova.domains.create("space_123", "cube_123", {
172
+ domain: "app.example.com",
173
+ port: 8080,
174
+ });
175
+ await krova.domains.update("space_123", "cube_123", domain.id, { responseCompression: true });
176
+ await krova.domains.delete("space_123", "cube_123", domain.id);
177
+
178
+ // Snapshots + restore
179
+ const snap = await krova.snapshots.create("space_123", "cube_123", { name: "nightly" });
180
+ const snaps = await krova.snapshots.list("space_123", "cube_123");
181
+ await krova.cubes.restore("space_123", "cube_123", snap.id); // replace the disk from a snapshot
182
+ await krova.snapshots.delete("space_123", "cube_123", snap.id);
183
+
184
+ // TCP port mappings (expose a Cube port on the host)
185
+ const mapping = await krova.tcpMappings.create("space_123", "cube_123", {
186
+ cubePort: 5432,
187
+ whitelistIps: ["203.0.113.4/32"],
188
+ });
189
+ await krova.tcpMappings.list("space_123", "cube_123");
190
+ await krova.tcpMappings.delete("space_123", "cube_123", mapping.id);
191
+ ```
192
+
193
+ `Domain`, `Snapshot`, and `TcpMapping` are exported for your own signatures.
194
+
195
+ ### Imports & backups
196
+
197
+ Move `.cube` archives in and out. `imports.create` returns a multipart upload target; upload the archive to the presigned parts, then call `imports.complete`.
198
+
199
+ ```ts
200
+ const start = await krova.imports.create("space_123", { name: "restored", fileSizeBytes: 1_048_576 });
201
+ // ...upload the archive to start.parts (presigned URLs)...
202
+ await krova.imports.complete("space_123", start.importId, { parts, config });
203
+ const status = await krova.imports.get("space_123", start.importId);
204
+
205
+ // Export: get a time-limited download URL for a backup archive
206
+ const dl = await krova.backups.download("space_123", "backup_123");
207
+ ```
208
+
154
209
  ### `client.raw` — every endpoint
155
210
 
156
- The helpers cover Cubes and the catalog. For everything else — Domains, TCP mappings, Snapshots, Backups, Imports, Webhooks — use `client.raw`, the fully typed [`openapi-fetch`](https://github.com/openapi-ts/openapi-typescript/tree/main/packages/openapi-fetch) client. It returns `{ data, error, response }` and **never throws**:
211
+ The helpers cover Cubes, the catalog, domains, snapshots, TCP mappings, imports, and backups. For anything else — e.g. Webhooks — use `client.raw`, the fully typed [`openapi-fetch`](https://github.com/openapi-ts/openapi-typescript/tree/main/packages/openapi-fetch) client. It returns `{ data, error, response }` and **never throws**:
157
212
 
158
213
  ```ts
159
214
  const { data, error } = await krova.raw.POST("/spaces/{spaceId}/webhooks", {
package/dist/index.cjs CHANGED
@@ -238,6 +238,225 @@ var KrovaClient = class {
238
238
  );
239
239
  if (error !== void 0 || !response.ok) throw krovaErrorFrom(response, error);
240
240
  return data;
241
+ },
242
+ /**
243
+ * Get a Cube's SSH connection info — host, port, login user, and (when
244
+ * available) the pinned host public keys for strict host-key verification.
245
+ */
246
+ ssh: async (spaceId, cubeId) => {
247
+ const { data, error, response } = await this.raw.GET(
248
+ "/spaces/{spaceId}/cubes/{cubeId}/ssh",
249
+ { params: { path: { spaceId, cubeId } } }
250
+ );
251
+ if (error !== void 0 || !response.ok) throw krovaErrorFrom(response, error);
252
+ if (data === void 0)
253
+ throw krovaErrorFrom(response, { error: "Cube SSH-info response was empty." });
254
+ return data;
255
+ },
256
+ /**
257
+ * Restore a Cube's disk from one of its {@link Snapshot}s (asynchronous —
258
+ * the restore is enqueued). The Cube's current disk is replaced.
259
+ */
260
+ restore: async (spaceId, cubeId, snapshotId) => {
261
+ const { data, error, response } = await this.raw.POST(
262
+ "/spaces/{spaceId}/cubes/{cubeId}/restore",
263
+ { params: { path: { spaceId, cubeId } }, body: { snapshotId } }
264
+ );
265
+ if (error !== void 0 || !response.ok) throw krovaErrorFrom(response, error);
266
+ return data;
267
+ }
268
+ };
269
+ /**
270
+ * Resolve the {@link Space} this API key is scoped to — so you don't have to
271
+ * hardcode a `spaceId`. Handy right after constructing the client:
272
+ *
273
+ * @example
274
+ * ```ts
275
+ * const space = await krova.getSpace();
276
+ * const cubes = await krova.cubes.list(space.id);
277
+ * ```
278
+ */
279
+ async getSpace() {
280
+ const { data, error, response } = await this.raw.GET("/space");
281
+ if (error !== void 0 || !response.ok) throw krovaErrorFrom(response, error);
282
+ if (data === void 0)
283
+ throw krovaErrorFrom(response, { error: "Space response was empty." });
284
+ return data;
285
+ }
286
+ // ---------------------------------------------------------------------------
287
+ // Custom domains
288
+ // ---------------------------------------------------------------------------
289
+ domains = {
290
+ /** List the custom domains attached to a Cube. */
291
+ list: async (spaceId, cubeId) => {
292
+ const { data, error, response } = await this.raw.GET(
293
+ "/spaces/{spaceId}/cubes/{cubeId}/domains",
294
+ { params: { path: { spaceId, cubeId } } }
295
+ );
296
+ if (error !== void 0 || !response.ok) throw krovaErrorFrom(response, error);
297
+ return data?.domains ?? [];
298
+ },
299
+ /** Attach a custom domain to a Cube. `domain` + `port` are required. */
300
+ create: async (spaceId, cubeId, body) => {
301
+ const { data, error, response } = await this.raw.POST(
302
+ "/spaces/{spaceId}/cubes/{cubeId}/domains",
303
+ { params: { path: { spaceId, cubeId } }, body }
304
+ );
305
+ if (error !== void 0 || !response.ok) throw krovaErrorFrom(response, error);
306
+ if (!data?.domain)
307
+ throw krovaErrorFrom(response, { error: "Create domain response had no `domain`." });
308
+ return data.domain;
309
+ },
310
+ /** Update a domain's per-domain proxy settings. */
311
+ update: async (spaceId, cubeId, mappingId, body) => {
312
+ const { data, error, response } = await this.raw.PATCH(
313
+ "/spaces/{spaceId}/cubes/{cubeId}/domains/{mappingId}",
314
+ { params: { path: { spaceId, cubeId, mappingId } }, body }
315
+ );
316
+ if (error !== void 0 || !response.ok) throw krovaErrorFrom(response, error);
317
+ if (!data?.domain)
318
+ throw krovaErrorFrom(response, { error: "Update domain response had no `domain`." });
319
+ return data.domain;
320
+ },
321
+ /** Detach a custom domain from a Cube. */
322
+ delete: async (spaceId, cubeId, mappingId) => {
323
+ const { data, error, response } = await this.raw.DELETE(
324
+ "/spaces/{spaceId}/cubes/{cubeId}/domains/{mappingId}",
325
+ { params: { path: { spaceId, cubeId, mappingId } } }
326
+ );
327
+ if (error !== void 0 || !response.ok) throw krovaErrorFrom(response, error);
328
+ return data;
329
+ }
330
+ };
331
+ // ---------------------------------------------------------------------------
332
+ // Snapshots
333
+ // ---------------------------------------------------------------------------
334
+ snapshots = {
335
+ /** List a Cube's snapshots. */
336
+ list: async (spaceId, cubeId) => {
337
+ const { data, error, response } = await this.raw.GET(
338
+ "/spaces/{spaceId}/cubes/{cubeId}/snapshots",
339
+ { params: { path: { spaceId, cubeId } } }
340
+ );
341
+ if (error !== void 0 || !response.ok) throw krovaErrorFrom(response, error);
342
+ return data?.snapshots ?? [];
343
+ },
344
+ /** Create a snapshot of a Cube's disk (asynchronous — enqueued). */
345
+ create: async (spaceId, cubeId, body) => {
346
+ const { data, error, response } = await this.raw.POST(
347
+ "/spaces/{spaceId}/cubes/{cubeId}/snapshots",
348
+ { params: { path: { spaceId, cubeId } }, body: body ?? {} }
349
+ );
350
+ if (error !== void 0 || !response.ok) throw krovaErrorFrom(response, error);
351
+ if (!data?.snapshot)
352
+ throw krovaErrorFrom(response, { error: "Create snapshot response had no `snapshot`." });
353
+ return data.snapshot;
354
+ },
355
+ /** Delete a snapshot. */
356
+ delete: async (spaceId, cubeId, snapshotId) => {
357
+ const { data, error, response } = await this.raw.DELETE(
358
+ "/spaces/{spaceId}/cubes/{cubeId}/snapshots/{snapshotId}",
359
+ { params: { path: { spaceId, cubeId, snapshotId } } }
360
+ );
361
+ if (error !== void 0 || !response.ok) throw krovaErrorFrom(response, error);
362
+ return data;
363
+ }
364
+ };
365
+ // ---------------------------------------------------------------------------
366
+ // TCP port mappings
367
+ // ---------------------------------------------------------------------------
368
+ tcpMappings = {
369
+ /** List a Cube's TCP port mappings. */
370
+ list: async (spaceId, cubeId) => {
371
+ const { data, error, response } = await this.raw.GET(
372
+ "/spaces/{spaceId}/cubes/{cubeId}/tcp-mappings",
373
+ { params: { path: { spaceId, cubeId } } }
374
+ );
375
+ if (error !== void 0 || !response.ok) throw krovaErrorFrom(response, error);
376
+ return data?.tcpMappings ?? [];
377
+ },
378
+ /**
379
+ * Create a TCP port mapping exposing a Cube port on the host. `cubePort` is
380
+ * required; `whitelistIps` optionally restricts who can reach it.
381
+ */
382
+ create: async (spaceId, cubeId, body) => {
383
+ const { data, error, response } = await this.raw.POST(
384
+ "/spaces/{spaceId}/cubes/{cubeId}/tcp-mappings",
385
+ { params: { path: { spaceId, cubeId } }, body }
386
+ );
387
+ if (error !== void 0 || !response.ok) throw krovaErrorFrom(response, error);
388
+ if (!data?.tcpMapping)
389
+ throw krovaErrorFrom(response, { error: "Create TCP mapping response had no `tcpMapping`." });
390
+ return data.tcpMapping;
391
+ },
392
+ /** Delete a TCP port mapping. */
393
+ delete: async (spaceId, cubeId, mappingId) => {
394
+ const { data, error, response } = await this.raw.DELETE(
395
+ "/spaces/{spaceId}/cubes/{cubeId}/tcp-mappings/{mappingId}",
396
+ { params: { path: { spaceId, cubeId, mappingId } } }
397
+ );
398
+ if (error !== void 0 || !response.ok) throw krovaErrorFrom(response, error);
399
+ return data;
400
+ }
401
+ };
402
+ // ---------------------------------------------------------------------------
403
+ // Imports & backups (.cube archive import / export)
404
+ // ---------------------------------------------------------------------------
405
+ imports = {
406
+ /**
407
+ * Start importing a `.cube` archive into a new Cube. Returns the multipart
408
+ * upload target (`importId`, `uploadId`, presigned `parts`, …). Upload the
409
+ * archive to those URLs, then call {@link imports.complete}.
410
+ */
411
+ create: async (spaceId, body) => {
412
+ const { data, error, response } = await this.raw.POST("/spaces/{spaceId}/cubes/imports", {
413
+ params: { path: { spaceId } },
414
+ body
415
+ });
416
+ if (error !== void 0 || !response.ok) throw krovaErrorFrom(response, error);
417
+ return data;
418
+ },
419
+ /** Get an in-progress or completed import by id. */
420
+ get: async (spaceId, importId) => {
421
+ const { data, error, response } = await this.raw.GET(
422
+ "/spaces/{spaceId}/cubes/imports/{importId}",
423
+ { params: { path: { spaceId, importId } } }
424
+ );
425
+ if (error !== void 0 || !response.ok) throw krovaErrorFrom(response, error);
426
+ return data;
427
+ },
428
+ /**
429
+ * Finish an import after the archive has been uploaded — provisions the
430
+ * Cube. Pass the uploaded `parts` (partNumber + etag) and the resolved
431
+ * `config`.
432
+ */
433
+ complete: async (spaceId, importId, body) => {
434
+ const { data, error, response } = await this.raw.POST(
435
+ "/spaces/{spaceId}/cubes/imports/{importId}/complete",
436
+ { params: { path: { spaceId, importId } }, body }
437
+ );
438
+ if (error !== void 0 || !response.ok) throw krovaErrorFrom(response, error);
439
+ return data;
440
+ },
441
+ /** Cancel an in-progress import. */
442
+ cancel: async (spaceId, importId) => {
443
+ const { data, error, response } = await this.raw.DELETE(
444
+ "/spaces/{spaceId}/cubes/imports/{importId}",
445
+ { params: { path: { spaceId, importId } } }
446
+ );
447
+ if (error !== void 0 || !response.ok) throw krovaErrorFrom(response, error);
448
+ return data;
449
+ }
450
+ };
451
+ backups = {
452
+ /** Get a time-limited download URL for a backup `.cube` archive. */
453
+ download: async (spaceId, backupId) => {
454
+ const { data, error, response } = await this.raw.GET(
455
+ "/spaces/{spaceId}/backups/{backupId}/download",
456
+ { params: { path: { spaceId, backupId } } }
457
+ );
458
+ if (error !== void 0 || !response.ok) throw krovaErrorFrom(response, error);
459
+ return data;
241
460
  }
242
461
  };
243
462
  // ---------------------------------------------------------------------------
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/error.ts","../src/client.ts"],"names":["createClient"],"mappings":";;;;;;;;;;;AAoBO,IAAM,UAAA,GAAN,MAAM,WAAA,SAAmB,KAAA,CAAM;AAAA;AAAA,EAE3B,MAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,SAAA;AAAA;AAAA,EAGA,IAAA;AAAA;AAAA,EAGA,QAAA;AAAA,EAET,WAAA,CACE,SACA,IAAA,EAOA;AACA,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,IAAA,GAAO,YAAA;AACZ,IAAA,IAAA,CAAK,SAAS,IAAA,CAAK,MAAA;AACnB,IAAA,IAAA,CAAK,OAAO,IAAA,CAAK,IAAA;AACjB,IAAA,IAAA,CAAK,YAAY,IAAA,CAAK,SAAA;AACtB,IAAA,IAAA,CAAK,OAAO,IAAA,CAAK,IAAA;AACjB,IAAA,IAAA,CAAK,WAAW,IAAA,CAAK,QAAA;AAErB,IAAA,MAAA,CAAO,cAAA,CAAe,IAAA,EAAM,WAAA,CAAW,SAAS,CAAA;AAAA,EAClD;AACF;AAKO,SAAS,cAAA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AS,IAAI,MAAM,cAAA,CAAe,UAAU,KAAK,CAAA;AAC7E,MAAA,IAAI,IAAA,KAAS,MAAA;AACX,QAAA,MAAM,cAAA,CAAe,QAAA,EAAU,EAAE,KAAA,EAAO,+BAA+B,CAAA;AACzE,MAAA,OAAO,IAAA;AAAA,IACT;AAAA,GACF;AACF","file":"index.cjs","sourcesContent":["/**\n * The error body shape returned by the Krova Cloud API.\n *\n * Per the OpenAPI spec (`components.schemas.Error`), every non-2xx response\n * body is `{ \"error\": string }`. Additional fields may appear over time, so\n * we keep the type open.\n */\nexport interface KrovaErrorBody {\n error?: string;\n [key: string]: unknown;\n}\n\n/**\n * Error thrown by the ergonomic {@link KrovaClient} helpers when the API\n * responds with a non-2xx status.\n *\n * The raw openapi-fetch client (`client.raw`) never throws — it returns\n * `{ data, error, response }`. The helpers wrap that and throw `KrovaError`\n * so callers can `try/catch`.\n */\nexport class KrovaError extends Error {\n /** HTTP status code of the failing response. */\n readonly status: number;\n\n /**\n * A machine-readable error code, when the API surfaces one via the\n * `X-Error-Code` response header. The documented error body only carries a\n * human-readable `error` string, so this is best-effort.\n */\n readonly code?: string;\n\n /**\n * The request id from the `X-Request-Id` response header, when present.\n * Useful when contacting Krova Cloud support about a specific failure.\n */\n readonly requestId?: string;\n\n /** The parsed JSON error body, when the response had one. */\n readonly body?: KrovaErrorBody;\n\n /** The raw `Response` object, for callers that need headers/url/etc. */\n readonly response?: Response;\n\n constructor(\n message: string,\n init: {\n status: number;\n code?: string;\n requestId?: string;\n body?: KrovaErrorBody;\n response?: Response;\n },\n ) {\n super(message);\n this.name = \"KrovaError\";\n this.status = init.status;\n this.code = init.code;\n this.requestId = init.requestId;\n this.body = init.body;\n this.response = init.response;\n // Restore prototype chain for instanceof across compilation targets.\n Object.setPrototypeOf(this, KrovaError.prototype);\n }\n}\n\n/**\n * Build a {@link KrovaError} from a failing response + parsed error body.\n */\nexport function krovaErrorFrom(\n response: Response,\n body: KrovaErrorBody | undefined,\n): KrovaError {\n const message =\n (typeof body?.error === \"string\" && body.error) ||\n response.statusText ||\n `Request failed with status ${response.status}`;\n return new KrovaError(message, {\n status: response.status,\n code: response.headers.get(\"x-error-code\") ?? undefined,\n requestId: response.headers.get(\"x-request-id\") ?? undefined,\n body,\n response,\n });\n}\n","import createClient, { type Client, type Middleware } from \"openapi-fetch\";\nimport { krovaErrorFrom } from \"./error.js\";\nimport type { components, paths } from \"./generated/types.js\";\n\n/** The Cube resource, as defined in the Krova Cloud OpenAPI spec. */\nexport type Cube = components[\"schemas\"][\"Cube\"];\n\n/** A region with available capacity (from the catalog). */\nexport type Region = components[\"schemas\"][\"Region\"];\n\n/** A selectable OS image (from the catalog). */\nexport type Image = components[\"schemas\"][\"Image\"];\n\n/** A volume-pricing tier (from the catalog). */\nexport type PricingTier = components[\"schemas\"][\"PricingTier\"];\n\n/** Pagination envelope returned alongside a Cube list. */\nexport type Pagination = components[\"schemas\"][\"Pagination\"];\n\n/** Default API base URL — the single `servers[0].url` from the OpenAPI spec. */\nexport const DEFAULT_BASE_URL = \"https://krova.cloud/api/v1\";\n\n/**\n * How the API key is presented to the server.\n *\n * - `\"x-api-key\"` (default) — `X-API-KEY: <key>`, matching the spec's\n * `components.securitySchemes.ApiKeyAuth` (an `apiKey` header named\n * `X-API-KEY`).\n * - `\"bearer\"` — `Authorization: Bearer <key>`, for gateways that expect it.\n */\nexport type AuthScheme = \"x-api-key\" | \"bearer\";\n\nexport interface KrovaClientOptions {\n /**\n * Your Krova Cloud API key (a `kro_...` token). Keys are scoped per Space\n * and inherit the permissions of the membership that created them.\n */\n apiKey: string;\n /** Override the API base URL. Defaults to {@link DEFAULT_BASE_URL}. */\n baseUrl?: string;\n /**\n * Auth header scheme. Defaults to `\"x-api-key\"` (the spec's scheme).\n */\n authScheme?: AuthScheme;\n /**\n * Max automatic retries on retryable statuses (429, 503).\n * Defaults to 2. Set to 0 to disable retries.\n */\n maxRetries?: number;\n /**\n * A custom `fetch` implementation (e.g. for tests or a proxy). Defaults to\n * the global `fetch`.\n */\n fetch?: typeof fetch;\n}\n\n/** Statuses the retry middleware treats as transient. */\nconst RETRYABLE_STATUSES = new Set([429, 503]);\n/** Fallback backoff (ms) when the server sends no `Retry-After` header. */\nconst BASE_BACKOFF_MS = 500;\n/** Cap on any single backoff wait (ms), to keep retries \"small but real\". */\nconst MAX_BACKOFF_MS = 10_000;\n\nconst sleep = (ms: number): Promise<void> =>\n new Promise((resolve) => setTimeout(resolve, ms));\n\n/**\n * Parse a `Retry-After` header (RFC 7231): either delta-seconds or an\n * HTTP-date. Returns milliseconds to wait, or `null` if absent/unparseable.\n */\nfunction parseRetryAfterMs(headerValue: string | null): number | null {\n if (!headerValue) return null;\n const seconds = Number(headerValue);\n if (Number.isFinite(seconds)) return Math.max(0, seconds * 1000);\n const dateMs = Date.parse(headerValue);\n if (Number.isFinite(dateMs)) return Math.max(0, dateMs - Date.now());\n return null;\n}\n\nfunction authMiddleware(apiKey: string, scheme: AuthScheme): Middleware {\n return {\n onRequest({ request }) {\n if (scheme === \"bearer\") {\n request.headers.set(\"Authorization\", `Bearer ${apiKey}`);\n } else {\n request.headers.set(\"X-API-KEY\", apiKey);\n }\n return request;\n },\n };\n}\n\n/**\n * Retry middleware: on a retryable status, wait (honoring `Retry-After` when\n * present, else exponential backoff) and re-issue the request.\n *\n * A retried request may have a body (POST/PUT/DELETE — exactly the mutating,\n * rate-limited endpoints). By the time `onResponse` runs, the request that was\n * handed to `fetch` has had its body stream consumed, so `request.clone()` here\n * throws `TypeError: unusable`. To re-issue it we stash a *pristine* clone in\n * `onRequest` — captured before the body is read — keyed by openapi-fetch's\n * per-request `id`, and clone from that pristine copy on each attempt.\n */\nfunction retryMiddleware(maxRetries: number, doFetch: typeof fetch): Middleware {\n const pristine = new Map<string, Request>();\n return {\n onRequest({ request, id }) {\n pristine.set(id, request.clone());\n return request;\n },\n onError({ id }) {\n // fetch rejected (network error) — no onResponse will fire; don't leak.\n pristine.delete(id);\n },\n async onResponse({ request, response, id }) {\n const original = pristine.get(id) ?? request;\n pristine.delete(id);\n if (maxRetries <= 0 || !RETRYABLE_STATUSES.has(response.status)) {\n return response;\n }\n let current = response;\n for (let attempt = 1; attempt <= maxRetries; attempt++) {\n if (!RETRYABLE_STATUSES.has(current.status)) break;\n const retryAfterMs = parseRetryAfterMs(current.headers.get(\"retry-after\"));\n const backoff = Math.min(BASE_BACKOFF_MS * 2 ** (attempt - 1), MAX_BACKOFF_MS);\n // Cap the wait — including a server-supplied `Retry-After` — so a hostile\n // or misconfigured server can't park the client for minutes/hours.\n await sleep(Math.min(retryAfterMs ?? backoff, MAX_BACKOFF_MS));\n // Re-issue from the pristine clone; `.clone()` keeps it reusable across\n // multiple attempts.\n current = await doFetch(original.clone());\n }\n return current;\n },\n };\n}\n\n/**\n * A typed client for the Krova Cloud API.\n *\n * @example\n * ```ts\n * const krova = new KrovaClient({ apiKey: \"kro_...\" });\n * const cubes = await krova.cubes.list(\"space_123\");\n * ```\n */\nexport class KrovaClient {\n /**\n * The underlying openapi-fetch client — a fully typed escape hatch to every\n * path in the spec. Returns `{ data, error, response }` and never throws.\n *\n * @example\n * ```ts\n * const { data, error } = await krova.raw.GET(\n * \"/spaces/{spaceId}/cubes/{cubeId}\",\n * { params: { path: { spaceId, cubeId } } },\n * );\n * ```\n */\n readonly raw: Client<paths>;\n\n /** The resolved base URL in use. */\n readonly baseUrl: string;\n\n constructor(options: KrovaClientOptions) {\n if (!options?.apiKey) {\n throw new Error(\"KrovaClient: `apiKey` is required.\");\n }\n this.baseUrl = options.baseUrl ?? DEFAULT_BASE_URL;\n const doFetch = options.fetch ?? globalThis.fetch;\n const maxRetries = options.maxRetries ?? 2;\n\n this.raw = createClient<paths>({\n baseUrl: this.baseUrl,\n // SECURITY: never auto-follow redirects. The Krova Cloud API is a plain\n // JSON API and never legitimately 3xx's a data call. Following a redirect\n // would resend the `X-API-KEY` header to the redirect target — and unlike\n // `Authorization`, `Cookie`, and `Proxy-Authorization`, the Fetch spec does\n // NOT strip a custom header like `X-API-KEY` on a cross-origin redirect\n // (verified against undici/Node fetch). A compromised/misconfigured proxy,\n // an open-redirect on the API, or a MITM could otherwise exfiltrate the key\n // to an attacker's host. With `\"manual\"`, a redirect comes back as a\n // non-ok response and the helpers throw `KrovaError` instead of leaking.\n redirect: \"manual\",\n ...(options.fetch ? { fetch: options.fetch } : {}),\n });\n this.raw.use(authMiddleware(options.apiKey, options.authScheme ?? \"x-api-key\"));\n if (maxRetries > 0) {\n this.raw.use(retryMiddleware(maxRetries, doFetch));\n }\n }\n\n // ---------------------------------------------------------------------------\n // Cubes\n // ---------------------------------------------------------------------------\n\n readonly cubes = {\n /** List Cubes in a Space, with pagination metadata. */\n list: async (spaceId: string) => {\n const { data, error, response } = await this.raw.GET(\"/spaces/{spaceId}/cubes\", {\n params: { path: { spaceId } },\n });\n if (error !== undefined || !response.ok) throw krovaErrorFrom(response, error);\n if (data === undefined)\n throw krovaErrorFrom(response, { error: \"List Cubes response was empty.\" });\n return data;\n },\n\n /**\n * Create a Cube. Returns the created {@link Cube}.\n *\n * @param spaceId Target Space id.\n * @param body Cube spec — `{ name, image, resources, sshPublicKey, ... }`.\n * @param opts Optional `idempotencyKey` (max 255 chars, scoped per space).\n */\n create: async (\n spaceId: string,\n body: NonNullable<\n paths[\"/spaces/{spaceId}/cubes\"][\"post\"][\"requestBody\"]\n >[\"content\"][\"application/json\"],\n opts?: { idempotencyKey?: string },\n ): Promise<Cube> => {\n const { data, error, response } = await this.raw.POST(\"/spaces/{spaceId}/cubes\", {\n params: {\n path: { spaceId },\n ...(opts?.idempotencyKey\n ? { header: { \"Idempotency-Key\": opts.idempotencyKey } }\n : {}),\n },\n body,\n });\n if (error !== undefined || !response.ok) throw krovaErrorFrom(response, error);\n const cube = data?.cube;\n if (!cube) {\n throw krovaErrorFrom(response, { error: \"Create Cube response had no `cube`.\" });\n }\n return cube;\n },\n\n /** Get a single Cube. Returns the {@link Cube}. */\n get: async (spaceId: string, cubeId: string): Promise<Cube> => {\n const { data, error, response } = await this.raw.GET(\n \"/spaces/{spaceId}/cubes/{cubeId}\",\n { params: { path: { spaceId, cubeId } } },\n );\n if (error !== undefined || !response.ok) throw krovaErrorFrom(response, error);\n const cube = data?.cube;\n if (!cube) {\n throw krovaErrorFrom(response, { error: \"Get Cube response had no `cube`.\" });\n }\n return cube;\n },\n\n /**\n * Update a Cube's SSH port.\n *\n * The Krova Cloud API exposes no general Cube-mutation endpoint; the only\n * mutable Cube field over the API is its SSH port, via\n * `PUT /spaces/{spaceId}/cubes/{cubeId}/ssh-port`. This helper maps to that\n * endpoint. (Compute resize / rename are not part of the public API.)\n */\n update: async (\n spaceId: string,\n cubeId: string,\n body: NonNullable<\n paths[\"/spaces/{spaceId}/cubes/{cubeId}/ssh-port\"][\"put\"][\"requestBody\"]\n >[\"content\"][\"application/json\"],\n ): Promise<unknown> => {\n const { data, error, response } = await this.raw.PUT(\n \"/spaces/{spaceId}/cubes/{cubeId}/ssh-port\",\n { params: { path: { spaceId, cubeId } }, body },\n );\n if (error !== undefined || !response.ok) throw krovaErrorFrom(response, error);\n return data;\n },\n\n /** Delete a Cube (asynchronous — deletion is enqueued). */\n delete: async (spaceId: string, cubeId: string) => {\n const { data, error, response } = await this.raw.DELETE(\n \"/spaces/{spaceId}/cubes/{cubeId}\",\n { params: { path: { spaceId, cubeId } } },\n );\n if (error !== undefined || !response.ok) throw krovaErrorFrom(response, error);\n if (data === undefined)\n throw krovaErrorFrom(response, { error: \"Delete Cube response was empty.\" });\n return data;\n },\n\n /** Sleep a running Cube (asynchronous — sleep is enqueued). */\n sleep: async (spaceId: string, cubeId: string): Promise<unknown> => {\n const { data, error, response } = await this.raw.POST(\n \"/spaces/{spaceId}/cubes/{cubeId}/sleep\",\n { params: { path: { spaceId, cubeId } } },\n );\n if (error !== undefined || !response.ok) throw krovaErrorFrom(response, error);\n return data;\n },\n\n /** Wake a sleeping Cube (asynchronous — wake is enqueued). */\n wake: async (spaceId: string, cubeId: string): Promise<unknown> => {\n const { data, error, response } = await this.raw.POST(\n \"/spaces/{spaceId}/cubes/{cubeId}/wake\",\n { params: { path: { spaceId, cubeId } } },\n );\n if (error !== undefined || !response.ok) throw krovaErrorFrom(response, error);\n return data;\n },\n };\n\n // ---------------------------------------------------------------------------\n // Public catalog (no auth required by the API, but the key is harmless)\n // ---------------------------------------------------------------------------\n\n readonly catalog = {\n /** List regions with available capacity. */\n regions: async () => {\n const { data, error, response } = await this.raw.GET(\"/regions\");\n if (error !== undefined || !response.ok) throw krovaErrorFrom(response, error);\n if (data === undefined)\n throw krovaErrorFrom(response, { error: \"Regions response was empty.\" });\n return data;\n },\n\n /** List available OS images. */\n images: async () => {\n const { data, error, response } = await this.raw.GET(\"/images\");\n if (error !== undefined || !response.ok) throw krovaErrorFrom(response, error);\n if (data === undefined)\n throw krovaErrorFrom(response, { error: \"Images response was empty.\" });\n return data;\n },\n\n /** Per-resource hourly rates and volume pricing tiers. */\n pricing: async () => {\n const { data, error, response } = await this.raw.GET(\"/pricing\");\n if (error !== undefined || !response.ok) throw krovaErrorFrom(response, error);\n if (data === undefined)\n throw krovaErrorFrom(response, { error: \"Pricing response was empty.\" });\n return data;\n },\n };\n}\n"]}
1
+ {"version":3,"sources":["../src/error.ts","../src/client.ts"],"names":["createClient"],"mappings":";;;;;;;;;;;AAoBO,IAAM,UAAA,GAAN,MAAM,WAAA,SAAmB,KAAA,CAAM;AAAA;AAAA,EAE3B,MAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,SAAA;AAAA;AAAA,EAGA,IAAA;AAAA;AAAA,EAGA,QAAA;AAAA,EAET,WAAA,CACE,SACA,IAAA,EAOA;AACA,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,IAAA,GAAO,YAAA;AACZ,IAAA,IAAA,CAAK,SAAS,IAAA,CAAK,MAAA;AACnB,IAAA,IAAA,CAAK,OAAO,IAAA,CAA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AM,EAAE,MAAM,KAAA,EAAO,QAAA,KAAa,MAAM,IAAA,CAAK,GAAA,CAAI,GAAA,CAAI,UAAU,CAAA;AAC/D,MAAA,IAAI,KAAA,KAAU,UAAa,CAAC,QAAA,CAAS,IAAI,MAAM,cAAA,CAAe,UAAU,KAAK,CAAA;AAC7E,MAAA,IAAI,IAAA,KAAS,MAAA;AACX,QAAA,MAAM,cAAA,CAAe,QAAA,EAAU,EAAE,KAAA,EAAO,+BAA+B,CAAA;AACzE,MAAA,OAAO,IAAA;AAAA,IACT;AAAA,GACF;AACF","file":"index.cjs","sourcesContent":["/**\n * The error body shape returned by the Krova Cloud API.\n *\n * Per the OpenAPI spec (`components.schemas.Error`), every non-2xx response\n * body is `{ \"error\": string }`. Additional fields may appear over time, so\n * we keep the type open.\n */\nexport interface KrovaErrorBody {\n error?: string;\n [key: string]: unknown;\n}\n\n/**\n * Error thrown by the ergonomic {@link KrovaClient} helpers when the API\n * responds with a non-2xx status.\n *\n * The raw openapi-fetch client (`client.raw`) never throws — it returns\n * `{ data, error, response }`. The helpers wrap that and throw `KrovaError`\n * so callers can `try/catch`.\n */\nexport class KrovaError extends Error {\n /** HTTP status code of the failing response. */\n readonly status: number;\n\n /**\n * A machine-readable error code, when the API surfaces one via the\n * `X-Error-Code` response header. The documented error body only carries a\n * human-readable `error` string, so this is best-effort.\n */\n readonly code?: string;\n\n /**\n * The request id from the `X-Request-Id` response header, when present.\n * Useful when contacting Krova Cloud support about a specific failure.\n */\n readonly requestId?: string;\n\n /** The parsed JSON error body, when the response had one. */\n readonly body?: KrovaErrorBody;\n\n /** The raw `Response` object, for callers that need headers/url/etc. */\n readonly response?: Response;\n\n constructor(\n message: string,\n init: {\n status: number;\n code?: string;\n requestId?: string;\n body?: KrovaErrorBody;\n response?: Response;\n },\n ) {\n super(message);\n this.name = \"KrovaError\";\n this.status = init.status;\n this.code = init.code;\n this.requestId = init.requestId;\n this.body = init.body;\n this.response = init.response;\n // Restore prototype chain for instanceof across compilation targets.\n Object.setPrototypeOf(this, KrovaError.prototype);\n }\n}\n\n/**\n * Build a {@link KrovaError} from a failing response + parsed error body.\n */\nexport function krovaErrorFrom(\n response: Response,\n body: KrovaErrorBody | undefined,\n): KrovaError {\n const message =\n (typeof body?.error === \"string\" && body.error) ||\n response.statusText ||\n `Request failed with status ${response.status}`;\n return new KrovaError(message, {\n status: response.status,\n code: response.headers.get(\"x-error-code\") ?? undefined,\n requestId: response.headers.get(\"x-request-id\") ?? undefined,\n body,\n response,\n });\n}\n","import createClient, { type Client, type Middleware } from \"openapi-fetch\";\nimport { krovaErrorFrom } from \"./error.js\";\nimport type { components, paths } from \"./generated/types.js\";\n\n/** The Cube resource, as defined in the Krova Cloud OpenAPI spec. */\nexport type Cube = components[\"schemas\"][\"Cube\"];\n\n/** A region with available capacity (from the catalog). */\nexport type Region = components[\"schemas\"][\"Region\"];\n\n/** A selectable OS image (from the catalog). */\nexport type Image = components[\"schemas\"][\"Image\"];\n\n/** A volume-pricing tier (from the catalog). */\nexport type PricingTier = components[\"schemas\"][\"PricingTier\"];\n\n/** Pagination envelope returned alongside a Cube list. */\nexport type Pagination = components[\"schemas\"][\"Pagination\"];\n\n/** A Space — the tenancy an API key is scoped to. */\nexport type Space = components[\"schemas\"][\"Space\"];\n\n/** A Cube's SSH connection info (host, port, user, and pinned host keys). */\nexport type CubeSshInfo = components[\"schemas\"][\"CubeSshInfo\"];\n\n/** A custom domain attached to a Cube. */\nexport type Domain = components[\"schemas\"][\"Domain\"];\n\n/** A snapshot of a Cube's disk. */\nexport type Snapshot = components[\"schemas\"][\"Snapshot\"];\n\n/** A TCP port mapping exposing a Cube port on the host. */\nexport type TcpMapping = components[\"schemas\"][\"TcpMapping\"];\n\n/** Request body for attaching a custom domain to a Cube. */\nexport type CreateDomainInput = NonNullable<\n paths[\"/spaces/{spaceId}/cubes/{cubeId}/domains\"][\"post\"][\"requestBody\"]\n>[\"content\"][\"application/json\"];\n\n/** Request body for updating a custom domain's proxy settings. */\nexport type UpdateDomainInput = NonNullable<\n paths[\"/spaces/{spaceId}/cubes/{cubeId}/domains/{mappingId}\"][\"patch\"][\"requestBody\"]\n>[\"content\"][\"application/json\"];\n\n/** Request body for creating a TCP port mapping. */\nexport type CreateTcpMappingInput = NonNullable<\n paths[\"/spaces/{spaceId}/cubes/{cubeId}/tcp-mappings\"][\"post\"][\"requestBody\"]\n>[\"content\"][\"application/json\"];\n\n/** Default API base URL — the single `servers[0].url` from the OpenAPI spec. */\nexport const DEFAULT_BASE_URL = \"https://krova.cloud/api/v1\";\n\n/**\n * How the API key is presented to the server.\n *\n * - `\"x-api-key\"` (default) — `X-API-KEY: <key>`, matching the spec's\n * `components.securitySchemes.ApiKeyAuth` (an `apiKey` header named\n * `X-API-KEY`).\n * - `\"bearer\"` — `Authorization: Bearer <key>`, for gateways that expect it.\n */\nexport type AuthScheme = \"x-api-key\" | \"bearer\";\n\nexport interface KrovaClientOptions {\n /**\n * Your Krova Cloud API key (a `kro_...` token). Keys are scoped per Space\n * and inherit the permissions of the membership that created them.\n */\n apiKey: string;\n /** Override the API base URL. Defaults to {@link DEFAULT_BASE_URL}. */\n baseUrl?: string;\n /**\n * Auth header scheme. Defaults to `\"x-api-key\"` (the spec's scheme).\n */\n authScheme?: AuthScheme;\n /**\n * Max automatic retries on retryable statuses (429, 503).\n * Defaults to 2. Set to 0 to disable retries.\n */\n maxRetries?: number;\n /**\n * A custom `fetch` implementation (e.g. for tests or a proxy). Defaults to\n * the global `fetch`.\n */\n fetch?: typeof fetch;\n}\n\n/** Statuses the retry middleware treats as transient. */\nconst RETRYABLE_STATUSES = new Set([429, 503]);\n/** Fallback backoff (ms) when the server sends no `Retry-After` header. */\nconst BASE_BACKOFF_MS = 500;\n/** Cap on any single backoff wait (ms), to keep retries \"small but real\". */\nconst MAX_BACKOFF_MS = 10_000;\n\nconst sleep = (ms: number): Promise<void> =>\n new Promise((resolve) => setTimeout(resolve, ms));\n\n/**\n * Parse a `Retry-After` header (RFC 7231): either delta-seconds or an\n * HTTP-date. Returns milliseconds to wait, or `null` if absent/unparseable.\n */\nfunction parseRetryAfterMs(headerValue: string | null): number | null {\n if (!headerValue) return null;\n const seconds = Number(headerValue);\n if (Number.isFinite(seconds)) return Math.max(0, seconds * 1000);\n const dateMs = Date.parse(headerValue);\n if (Number.isFinite(dateMs)) return Math.max(0, dateMs - Date.now());\n return null;\n}\n\nfunction authMiddleware(apiKey: string, scheme: AuthScheme): Middleware {\n return {\n onRequest({ request }) {\n if (scheme === \"bearer\") {\n request.headers.set(\"Authorization\", `Bearer ${apiKey}`);\n } else {\n request.headers.set(\"X-API-KEY\", apiKey);\n }\n return request;\n },\n };\n}\n\n/**\n * Retry middleware: on a retryable status, wait (honoring `Retry-After` when\n * present, else exponential backoff) and re-issue the request.\n *\n * A retried request may have a body (POST/PUT/DELETE — exactly the mutating,\n * rate-limited endpoints). By the time `onResponse` runs, the request that was\n * handed to `fetch` has had its body stream consumed, so `request.clone()` here\n * throws `TypeError: unusable`. To re-issue it we stash a *pristine* clone in\n * `onRequest` — captured before the body is read — keyed by openapi-fetch's\n * per-request `id`, and clone from that pristine copy on each attempt.\n */\nfunction retryMiddleware(maxRetries: number, doFetch: typeof fetch): Middleware {\n const pristine = new Map<string, Request>();\n return {\n onRequest({ request, id }) {\n pristine.set(id, request.clone());\n return request;\n },\n onError({ id }) {\n // fetch rejected (network error) — no onResponse will fire; don't leak.\n pristine.delete(id);\n },\n async onResponse({ request, response, id }) {\n const original = pristine.get(id) ?? request;\n pristine.delete(id);\n if (maxRetries <= 0 || !RETRYABLE_STATUSES.has(response.status)) {\n return response;\n }\n let current = response;\n for (let attempt = 1; attempt <= maxRetries; attempt++) {\n if (!RETRYABLE_STATUSES.has(current.status)) break;\n const retryAfterMs = parseRetryAfterMs(current.headers.get(\"retry-after\"));\n const backoff = Math.min(BASE_BACKOFF_MS * 2 ** (attempt - 1), MAX_BACKOFF_MS);\n // Cap the wait — including a server-supplied `Retry-After` — so a hostile\n // or misconfigured server can't park the client for minutes/hours.\n await sleep(Math.min(retryAfterMs ?? backoff, MAX_BACKOFF_MS));\n // Re-issue from the pristine clone; `.clone()` keeps it reusable across\n // multiple attempts.\n current = await doFetch(original.clone());\n }\n return current;\n },\n };\n}\n\n/**\n * A typed client for the Krova Cloud API.\n *\n * @example\n * ```ts\n * const krova = new KrovaClient({ apiKey: \"kro_...\" });\n * const cubes = await krova.cubes.list(\"space_123\");\n * ```\n */\nexport class KrovaClient {\n /**\n * The underlying openapi-fetch client — a fully typed escape hatch to every\n * path in the spec. Returns `{ data, error, response }` and never throws.\n *\n * @example\n * ```ts\n * const { data, error } = await krova.raw.GET(\n * \"/spaces/{spaceId}/cubes/{cubeId}\",\n * { params: { path: { spaceId, cubeId } } },\n * );\n * ```\n */\n readonly raw: Client<paths>;\n\n /** The resolved base URL in use. */\n readonly baseUrl: string;\n\n constructor(options: KrovaClientOptions) {\n if (!options?.apiKey) {\n throw new Error(\"KrovaClient: `apiKey` is required.\");\n }\n this.baseUrl = options.baseUrl ?? DEFAULT_BASE_URL;\n const doFetch = options.fetch ?? globalThis.fetch;\n const maxRetries = options.maxRetries ?? 2;\n\n this.raw = createClient<paths>({\n baseUrl: this.baseUrl,\n // SECURITY: never auto-follow redirects. The Krova Cloud API is a plain\n // JSON API and never legitimately 3xx's a data call. Following a redirect\n // would resend the `X-API-KEY` header to the redirect target — and unlike\n // `Authorization`, `Cookie`, and `Proxy-Authorization`, the Fetch spec does\n // NOT strip a custom header like `X-API-KEY` on a cross-origin redirect\n // (verified against undici/Node fetch). A compromised/misconfigured proxy,\n // an open-redirect on the API, or a MITM could otherwise exfiltrate the key\n // to an attacker's host. With `\"manual\"`, a redirect comes back as a\n // non-ok response and the helpers throw `KrovaError` instead of leaking.\n redirect: \"manual\",\n ...(options.fetch ? { fetch: options.fetch } : {}),\n });\n this.raw.use(authMiddleware(options.apiKey, options.authScheme ?? \"x-api-key\"));\n if (maxRetries > 0) {\n this.raw.use(retryMiddleware(maxRetries, doFetch));\n }\n }\n\n // ---------------------------------------------------------------------------\n // Cubes\n // ---------------------------------------------------------------------------\n\n readonly cubes = {\n /** List Cubes in a Space, with pagination metadata. */\n list: async (spaceId: string) => {\n const { data, error, response } = await this.raw.GET(\"/spaces/{spaceId}/cubes\", {\n params: { path: { spaceId } },\n });\n if (error !== undefined || !response.ok) throw krovaErrorFrom(response, error);\n if (data === undefined)\n throw krovaErrorFrom(response, { error: \"List Cubes response was empty.\" });\n return data;\n },\n\n /**\n * Create a Cube. Returns the created {@link Cube}.\n *\n * @param spaceId Target Space id.\n * @param body Cube spec — `{ name, image, resources, sshPublicKey, ... }`.\n * @param opts Optional `idempotencyKey` (max 255 chars, scoped per space).\n */\n create: async (\n spaceId: string,\n body: NonNullable<\n paths[\"/spaces/{spaceId}/cubes\"][\"post\"][\"requestBody\"]\n >[\"content\"][\"application/json\"],\n opts?: { idempotencyKey?: string },\n ): Promise<Cube> => {\n const { data, error, response } = await this.raw.POST(\"/spaces/{spaceId}/cubes\", {\n params: {\n path: { spaceId },\n ...(opts?.idempotencyKey\n ? { header: { \"Idempotency-Key\": opts.idempotencyKey } }\n : {}),\n },\n body,\n });\n if (error !== undefined || !response.ok) throw krovaErrorFrom(response, error);\n const cube = data?.cube;\n if (!cube) {\n throw krovaErrorFrom(response, { error: \"Create Cube response had no `cube`.\" });\n }\n return cube;\n },\n\n /** Get a single Cube. Returns the {@link Cube}. */\n get: async (spaceId: string, cubeId: string): Promise<Cube> => {\n const { data, error, response } = await this.raw.GET(\n \"/spaces/{spaceId}/cubes/{cubeId}\",\n { params: { path: { spaceId, cubeId } } },\n );\n if (error !== undefined || !response.ok) throw krovaErrorFrom(response, error);\n const cube = data?.cube;\n if (!cube) {\n throw krovaErrorFrom(response, { error: \"Get Cube response had no `cube`.\" });\n }\n return cube;\n },\n\n /**\n * Update a Cube's SSH port.\n *\n * The Krova Cloud API exposes no general Cube-mutation endpoint; the only\n * mutable Cube field over the API is its SSH port, via\n * `PUT /spaces/{spaceId}/cubes/{cubeId}/ssh-port`. This helper maps to that\n * endpoint. (Compute resize / rename are not part of the public API.)\n */\n update: async (\n spaceId: string,\n cubeId: string,\n body: NonNullable<\n paths[\"/spaces/{spaceId}/cubes/{cubeId}/ssh-port\"][\"put\"][\"requestBody\"]\n >[\"content\"][\"application/json\"],\n ): Promise<unknown> => {\n const { data, error, response } = await this.raw.PUT(\n \"/spaces/{spaceId}/cubes/{cubeId}/ssh-port\",\n { params: { path: { spaceId, cubeId } }, body },\n );\n if (error !== undefined || !response.ok) throw krovaErrorFrom(response, error);\n return data;\n },\n\n /** Delete a Cube (asynchronous — deletion is enqueued). */\n delete: async (spaceId: string, cubeId: string) => {\n const { data, error, response } = await this.raw.DELETE(\n \"/spaces/{spaceId}/cubes/{cubeId}\",\n { params: { path: { spaceId, cubeId } } },\n );\n if (error !== undefined || !response.ok) throw krovaErrorFrom(response, error);\n if (data === undefined)\n throw krovaErrorFrom(response, { error: \"Delete Cube response was empty.\" });\n return data;\n },\n\n /** Sleep a running Cube (asynchronous — sleep is enqueued). */\n sleep: async (spaceId: string, cubeId: string): Promise<unknown> => {\n const { data, error, response } = await this.raw.POST(\n \"/spaces/{spaceId}/cubes/{cubeId}/sleep\",\n { params: { path: { spaceId, cubeId } } },\n );\n if (error !== undefined || !response.ok) throw krovaErrorFrom(response, error);\n return data;\n },\n\n /** Wake a sleeping Cube (asynchronous — wake is enqueued). */\n wake: async (spaceId: string, cubeId: string): Promise<unknown> => {\n const { data, error, response } = await this.raw.POST(\n \"/spaces/{spaceId}/cubes/{cubeId}/wake\",\n { params: { path: { spaceId, cubeId } } },\n );\n if (error !== undefined || !response.ok) throw krovaErrorFrom(response, error);\n return data;\n },\n\n /**\n * Get a Cube's SSH connection info — host, port, login user, and (when\n * available) the pinned host public keys for strict host-key verification.\n */\n ssh: async (spaceId: string, cubeId: string): Promise<CubeSshInfo> => {\n const { data, error, response } = await this.raw.GET(\n \"/spaces/{spaceId}/cubes/{cubeId}/ssh\",\n { params: { path: { spaceId, cubeId } } },\n );\n if (error !== undefined || !response.ok) throw krovaErrorFrom(response, error);\n if (data === undefined)\n throw krovaErrorFrom(response, { error: \"Cube SSH-info response was empty.\" });\n return data;\n },\n\n /**\n * Restore a Cube's disk from one of its {@link Snapshot}s (asynchronous —\n * the restore is enqueued). The Cube's current disk is replaced.\n */\n restore: async (spaceId: string, cubeId: string, snapshotId: string) => {\n const { data, error, response } = await this.raw.POST(\n \"/spaces/{spaceId}/cubes/{cubeId}/restore\",\n { params: { path: { spaceId, cubeId } }, body: { snapshotId } },\n );\n if (error !== undefined || !response.ok) throw krovaErrorFrom(response, error);\n return data;\n },\n };\n\n /**\n * Resolve the {@link Space} this API key is scoped to — so you don't have to\n * hardcode a `spaceId`. Handy right after constructing the client:\n *\n * @example\n * ```ts\n * const space = await krova.getSpace();\n * const cubes = await krova.cubes.list(space.id);\n * ```\n */\n async getSpace(): Promise<Space> {\n const { data, error, response } = await this.raw.GET(\"/space\");\n if (error !== undefined || !response.ok) throw krovaErrorFrom(response, error);\n if (data === undefined)\n throw krovaErrorFrom(response, { error: \"Space response was empty.\" });\n return data;\n }\n\n // ---------------------------------------------------------------------------\n // Custom domains\n // ---------------------------------------------------------------------------\n\n readonly domains = {\n /** List the custom domains attached to a Cube. */\n list: async (spaceId: string, cubeId: string): Promise<Domain[]> => {\n const { data, error, response } = await this.raw.GET(\n \"/spaces/{spaceId}/cubes/{cubeId}/domains\",\n { params: { path: { spaceId, cubeId } } },\n );\n if (error !== undefined || !response.ok) throw krovaErrorFrom(response, error);\n return data?.domains ?? [];\n },\n\n /** Attach a custom domain to a Cube. `domain` + `port` are required. */\n create: async (\n spaceId: string,\n cubeId: string,\n body: CreateDomainInput,\n ): Promise<Domain> => {\n const { data, error, response } = await this.raw.POST(\n \"/spaces/{spaceId}/cubes/{cubeId}/domains\",\n { params: { path: { spaceId, cubeId } }, body },\n );\n if (error !== undefined || !response.ok) throw krovaErrorFrom(response, error);\n if (!data?.domain)\n throw krovaErrorFrom(response, { error: \"Create domain response had no `domain`.\" });\n return data.domain;\n },\n\n /** Update a domain's per-domain proxy settings. */\n update: async (\n spaceId: string,\n cubeId: string,\n mappingId: string,\n body: UpdateDomainInput,\n ): Promise<Domain> => {\n const { data, error, response } = await this.raw.PATCH(\n \"/spaces/{spaceId}/cubes/{cubeId}/domains/{mappingId}\",\n { params: { path: { spaceId, cubeId, mappingId } }, body },\n );\n if (error !== undefined || !response.ok) throw krovaErrorFrom(response, error);\n if (!data?.domain)\n throw krovaErrorFrom(response, { error: \"Update domain response had no `domain`.\" });\n return data.domain;\n },\n\n /** Detach a custom domain from a Cube. */\n delete: async (spaceId: string, cubeId: string, mappingId: string) => {\n const { data, error, response } = await this.raw.DELETE(\n \"/spaces/{spaceId}/cubes/{cubeId}/domains/{mappingId}\",\n { params: { path: { spaceId, cubeId, mappingId } } },\n );\n if (error !== undefined || !response.ok) throw krovaErrorFrom(response, error);\n return data;\n },\n };\n\n // ---------------------------------------------------------------------------\n // Snapshots\n // ---------------------------------------------------------------------------\n\n readonly snapshots = {\n /** List a Cube's snapshots. */\n list: async (spaceId: string, cubeId: string): Promise<Snapshot[]> => {\n const { data, error, response } = await this.raw.GET(\n \"/spaces/{spaceId}/cubes/{cubeId}/snapshots\",\n { params: { path: { spaceId, cubeId } } },\n );\n if (error !== undefined || !response.ok) throw krovaErrorFrom(response, error);\n return data?.snapshots ?? [];\n },\n\n /** Create a snapshot of a Cube's disk (asynchronous — enqueued). */\n create: async (\n spaceId: string,\n cubeId: string,\n body?: { name?: string },\n ): Promise<Snapshot> => {\n const { data, error, response } = await this.raw.POST(\n \"/spaces/{spaceId}/cubes/{cubeId}/snapshots\",\n { params: { path: { spaceId, cubeId } }, body: body ?? {} },\n );\n if (error !== undefined || !response.ok) throw krovaErrorFrom(response, error);\n if (!data?.snapshot)\n throw krovaErrorFrom(response, { error: \"Create snapshot response had no `snapshot`.\" });\n return data.snapshot;\n },\n\n /** Delete a snapshot. */\n delete: async (spaceId: string, cubeId: string, snapshotId: string) => {\n const { data, error, response } = await this.raw.DELETE(\n \"/spaces/{spaceId}/cubes/{cubeId}/snapshots/{snapshotId}\",\n { params: { path: { spaceId, cubeId, snapshotId } } },\n );\n if (error !== undefined || !response.ok) throw krovaErrorFrom(response, error);\n return data;\n },\n };\n\n // ---------------------------------------------------------------------------\n // TCP port mappings\n // ---------------------------------------------------------------------------\n\n readonly tcpMappings = {\n /** List a Cube's TCP port mappings. */\n list: async (spaceId: string, cubeId: string): Promise<TcpMapping[]> => {\n const { data, error, response } = await this.raw.GET(\n \"/spaces/{spaceId}/cubes/{cubeId}/tcp-mappings\",\n { params: { path: { spaceId, cubeId } } },\n );\n if (error !== undefined || !response.ok) throw krovaErrorFrom(response, error);\n return data?.tcpMappings ?? [];\n },\n\n /**\n * Create a TCP port mapping exposing a Cube port on the host. `cubePort` is\n * required; `whitelistIps` optionally restricts who can reach it.\n */\n create: async (\n spaceId: string,\n cubeId: string,\n body: CreateTcpMappingInput,\n ): Promise<TcpMapping> => {\n const { data, error, response } = await this.raw.POST(\n \"/spaces/{spaceId}/cubes/{cubeId}/tcp-mappings\",\n { params: { path: { spaceId, cubeId } }, body },\n );\n if (error !== undefined || !response.ok) throw krovaErrorFrom(response, error);\n if (!data?.tcpMapping)\n throw krovaErrorFrom(response, { error: \"Create TCP mapping response had no `tcpMapping`.\" });\n return data.tcpMapping;\n },\n\n /** Delete a TCP port mapping. */\n delete: async (spaceId: string, cubeId: string, mappingId: string) => {\n const { data, error, response } = await this.raw.DELETE(\n \"/spaces/{spaceId}/cubes/{cubeId}/tcp-mappings/{mappingId}\",\n { params: { path: { spaceId, cubeId, mappingId } } },\n );\n if (error !== undefined || !response.ok) throw krovaErrorFrom(response, error);\n return data;\n },\n };\n\n // ---------------------------------------------------------------------------\n // Imports & backups (.cube archive import / export)\n // ---------------------------------------------------------------------------\n\n readonly imports = {\n /**\n * Start importing a `.cube` archive into a new Cube. Returns the multipart\n * upload target (`importId`, `uploadId`, presigned `parts`, …). Upload the\n * archive to those URLs, then call {@link imports.complete}.\n */\n create: async (\n spaceId: string,\n body: NonNullable<\n paths[\"/spaces/{spaceId}/cubes/imports\"][\"post\"][\"requestBody\"]\n >[\"content\"][\"application/json\"],\n ) => {\n const { data, error, response } = await this.raw.POST(\"/spaces/{spaceId}/cubes/imports\", {\n params: { path: { spaceId } },\n body,\n });\n if (error !== undefined || !response.ok) throw krovaErrorFrom(response, error);\n return data;\n },\n\n /** Get an in-progress or completed import by id. */\n get: async (spaceId: string, importId: string) => {\n const { data, error, response } = await this.raw.GET(\n \"/spaces/{spaceId}/cubes/imports/{importId}\",\n { params: { path: { spaceId, importId } } },\n );\n if (error !== undefined || !response.ok) throw krovaErrorFrom(response, error);\n return data;\n },\n\n /**\n * Finish an import after the archive has been uploaded — provisions the\n * Cube. Pass the uploaded `parts` (partNumber + etag) and the resolved\n * `config`.\n */\n complete: async (\n spaceId: string,\n importId: string,\n body: NonNullable<\n paths[\"/spaces/{spaceId}/cubes/imports/{importId}/complete\"][\"post\"][\"requestBody\"]\n >[\"content\"][\"application/json\"],\n ) => {\n const { data, error, response } = await this.raw.POST(\n \"/spaces/{spaceId}/cubes/imports/{importId}/complete\",\n { params: { path: { spaceId, importId } }, body },\n );\n if (error !== undefined || !response.ok) throw krovaErrorFrom(response, error);\n return data;\n },\n\n /** Cancel an in-progress import. */\n cancel: async (spaceId: string, importId: string) => {\n const { data, error, response } = await this.raw.DELETE(\n \"/spaces/{spaceId}/cubes/imports/{importId}\",\n { params: { path: { spaceId, importId } } },\n );\n if (error !== undefined || !response.ok) throw krovaErrorFrom(response, error);\n return data;\n },\n };\n\n readonly backups = {\n /** Get a time-limited download URL for a backup `.cube` archive. */\n download: async (spaceId: string, backupId: string) => {\n const { data, error, response } = await this.raw.GET(\n \"/spaces/{spaceId}/backups/{backupId}/download\",\n { params: { path: { spaceId, backupId } } },\n );\n if (error !== undefined || !response.ok) throw krovaErrorFrom(response, error);\n return data;\n },\n };\n\n // ---------------------------------------------------------------------------\n // Public catalog (no auth required by the API, but the key is harmless)\n // ---------------------------------------------------------------------------\n\n readonly catalog = {\n /** List regions with available capacity. */\n regions: async () => {\n const { data, error, response } = await this.raw.GET(\"/regions\");\n if (error !== undefined || !response.ok) throw krovaErrorFrom(response, error);\n if (data === undefined)\n throw krovaErrorFrom(response, { error: \"Regions response was empty.\" });\n return data;\n },\n\n /** List available OS images. */\n images: async () => {\n const { data, error, response } = await this.raw.GET(\"/images\");\n if (error !== undefined || !response.ok) throw krovaErrorFrom(response, error);\n if (data === undefined)\n throw krovaErrorFrom(response, { error: \"Images response was empty.\" });\n return data;\n },\n\n /** Per-resource hourly rates and volume pricing tiers. */\n pricing: async () => {\n const { data, error, response } = await this.raw.GET(\"/pricing\");\n if (error !== undefined || !response.ok) throw krovaErrorFrom(response, error);\n if (data === undefined)\n throw krovaErrorFrom(response, { error: \"Pricing response was empty.\" });\n return data;\n },\n };\n}\n"]}