@krovacloud/sdk 0.4.12 → 0.4.14

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
@@ -9,6 +9,8 @@ All notable changes to `@krovacloud/sdk` are documented here. This project adher
9
9
 
10
10
  ### Added
11
11
 
12
+ - Backups and sharing them between spaces: `backups.list()`, `backups.get()` and `backups.share()` (with an optional `idempotencyKey`), and a new `backupShares` group with `list()`, `accept()`, `decline()` and `cancel()`. New exported types `Backup`, `BackupShare`, `BackupShareList` and `AcceptedBackupShare`. These endpoints read the Backups permissions (`backup.view`, `backup.manage`), not the Cube ones. The OpenAPI snapshot is refreshed from the live API and the types regenerated.
13
+
12
14
  - `proxyProtocol` (`"v1"`, `"v2"` or `null`) on `domains.create()` and
13
15
  `domains.update()`, and on every returned `Domain`, which now also carries
14
16
  `originScheme`. `confirmMixedProxyProtocol: true` saves a setting that differs
@@ -28,6 +30,10 @@ All notable changes to `@krovacloud/sdk` are documented here. This project adher
28
30
  arbitrary record should narrow to `body?.error` (or cast the body to a
29
31
  concrete shape they actually expect).
30
32
 
33
+ ### Documentation
34
+
35
+ - README documents `cubes.setTerminationProtection` (and `TerminationProtectedError`), `terminationProtection` on `cubes.create()` and on `Cube`, the `resizing` state, and `client.webhooks`. It no longer says webhooks need `client.raw`.
36
+
31
37
  ## 0.4.2
32
38
 
33
39
  ### Changed
package/README.md CHANGED
@@ -10,7 +10,7 @@ The official TypeScript SDK for the [Krova Cloud](https://krova.cloud) API — a
10
10
  ## Highlights
11
11
 
12
12
  - **Fully typed** — request bodies, responses, and path params are generated from the Krova Cloud OpenAPI spec via [`openapi-typescript`](https://github.com/openapi-ts/openapi-typescript) + [`openapi-fetch`](https://github.com/openapi-ts/openapi-typescript/tree/main/packages/openapi-fetch).
13
- - **Ergonomic helpers** — `client.cubes.*` and `client.catalog.*` unwrap the response body and throw a typed `KrovaError` on failure.
13
+ - **Ergonomic helpers** — `client.cubes`, `domains`, `snapshots`, `tcpMappings`, `imports`, `backups`, `webhooks` and `catalog` unwrap the response body and throw a typed `KrovaError` on failure.
14
14
  - **Full escape hatch** — `client.raw` exposes the underlying typed client for every operation in the bundled OpenAPI spec (Domains, TCP mappings, Snapshots, Backups, Imports, Webhooks, and more).
15
15
  - **Zero-config resilience** — automatic retries on `429` / `503`, honoring `Retry-After`.
16
16
  - **ESM + CJS** — ships both, with bundled `.d.ts` declarations. No runtime dependencies beyond `openapi-fetch`.
@@ -118,7 +118,8 @@ Ergonomic helpers for the Cube lifecycle. Each unwraps the response body and thr
118
118
  | `list` | `(spaceId: string)` | the Cube list body |
119
119
  | `create` | `(spaceId, body, opts?)` | the created `Cube` |
120
120
  | `get` | `(spaceId, cubeId)` | the Cube body |
121
- | `update` | `(spaceId, cubeId, body)` | updates the Cube's SSH port |
121
+ | `update` | `(spaceId, cubeId, body)` | changes the port sshd listens on inside the Cube |
122
+ | `setTerminationProtection` | `(spaceId, cubeId, enabled)` | the updated `Cube`. While protection is on, `delete` throws `TerminationProtectedError` (a `KrovaError` for the API's `409`) |
122
123
  | `delete` | `(spaceId, cubeId)` | enqueues deletion |
123
124
  | `powerOff` | `(spaceId, cubeId)` | enqueues a power-off |
124
125
  | `wake` | `(spaceId, cubeId)` | enqueues a start |
@@ -137,6 +138,7 @@ const cube = await krova.cubes.create(
137
138
  sshPublicKey: "ssh-ed25519 AAAA... you@host",
138
139
  region: "us", // optional — slug from catalog.regions()
139
140
  userData: "#cloud-config\n", // optional — cloud-init (max 16 KB)
141
+ terminationProtection: true, // optional — refuse deletes until turned off
140
142
  },
141
143
  { idempotencyKey: "deploy-2026-07-01" },
142
144
  );
@@ -145,9 +147,12 @@ const cube = await krova.cubes.create(
145
147
  const one = await krova.cubes.get("space_123", cube.id);
146
148
  const all = await krova.cubes.list("space_123");
147
149
 
148
- // update — the only mutable Cube field over the public API is the SSH port
150
+ // update — the port sshd listens on inside the Cube
149
151
  await krova.cubes.update("space_123", cube.id, { cubePort: 2222 });
150
152
 
153
+ // termination protection — delete is refused until it is turned off
154
+ await krova.cubes.setTerminationProtection("space_123", cube.id, false);
155
+
151
156
  // lifecycle — powerOff, wake, delete are asynchronous (enqueued)
152
157
  await krova.cubes.powerOff("space_123", cube.id);
153
158
  await krova.cubes.wake("space_123", cube.id);
@@ -165,10 +170,11 @@ The `Cube` type is exported for your own signatures:
165
170
  import type { Cube } from "@krovacloud/sdk";
166
171
  // {
167
172
  // id: string; name: string;
168
- // state: "pending" | "booting" | "running" | "stopped" | "stopping" | "error" | "deleted";
173
+ // state: "pending" | "booting" | "running" | "stopped" | "stopping" | "resizing" | "error" | "deleted";
169
174
  // publicIpv4: string | null;
170
175
  // resources: { vcpu: number; ramGb: number; diskGb: number };
171
176
  // image: string; costPerHour: number;
177
+ // terminationProtection: boolean;
172
178
  // createdAt: string; updatedAt: string;
173
179
  // }
174
180
  ```
@@ -261,18 +267,64 @@ const status = await krova.imports.get("space_123", start.importId);
261
267
  const dl = await krova.backups.download("space_123", "backup_123");
262
268
  ```
263
269
 
270
+ The download URL is valid for 15 minutes and needs no further authentication. Anyone holding it can fetch the whole disk, so treat it as a secret.
271
+
272
+ ### Backups and sharing them with another space
273
+
274
+ A backup is a Cube's disk and configuration, kept after the Cube is gone. You can offer another space its own copy: nothing is copied until that space accepts, within 48 hours, and from then the copy is the destination's own and billed to it. Your backup and bill are unchanged, and deleting either copy leaves the other alone.
275
+
276
+ ```ts
277
+ const backups = await krova.backups.list("space_123");
278
+ const backup = await krova.backups.get("space_123", backups[0]!.id);
279
+
280
+ // Offer a copy. Always a pending request through the API, even when your user owns both spaces.
281
+ const share = await krova.backups.share(
282
+ "space_123",
283
+ backup.id,
284
+ { destinationSpaceId: "space_456" },
285
+ { idempotencyKey: "share-nightly-2026-10-07" },
286
+ );
287
+
288
+ // In the destination space: list what is waiting, then accept or decline.
289
+ const { incoming, outgoing } = await krova.backupShares.list("space_456");
290
+ const { backup: copy } = await krova.backupShares.accept("space_456", share.id);
291
+ // copy.sharedFromBackupId === backup.id
292
+
293
+ // Or: krova.backupShares.decline("space_456", share.id)
294
+ // The source can withdraw it before then: krova.backupShares.cancel("space_123", share.id)
295
+ ```
296
+
297
+ These calls need the **Backups** permissions on the key's member: View Backups to list and get, Manage Backups for everything else. Only the destination space's owner, or a member there with Manage Backups, can accept or decline. `accept` throws a `KrovaError` with status `422` when the destination cannot take the copy (no card or credit, owner not verified, an open abuse notice, or no backup allowance left on its plan).
298
+
299
+ ### Webhooks
300
+
301
+ `client.webhooks` manages a space's webhook endpoints. `create` is the only call that returns the signing secret, so store it straight away. To verify deliveries, use [`@krovacloud/webhook`](https://www.npmjs.com/package/@krovacloud/webhook).
302
+
303
+ ```ts
304
+ const endpoint = await krova.webhooks.create("space_123", {
305
+ url: "https://example.com/hook",
306
+ events: ["cube.running", "cube.stopped"],
307
+ description: "deploy notifier", // optional
308
+ });
309
+ // endpoint.secret is returned only here: store it now
310
+
311
+ await krova.webhooks.list("space_123");
312
+ await krova.webhooks.get("space_123", endpoint.id);
313
+ await krova.webhooks.deliveries("space_123", endpoint.id, { limit: 20 }); // last 30 days
314
+ await krova.webhooks.delete("space_123", endpoint.id);
315
+ ```
316
+
264
317
  ### `client.raw` — every endpoint
265
318
 
266
- 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**:
319
+ The helpers cover Cubes, the catalog, domains, snapshots, TCP mappings, imports, backups, and webhooks. When you would rather handle the error yourself than catch an exception, 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**:
267
320
 
268
321
  ```ts
269
- const { data, error } = await krova.raw.POST("/spaces/{spaceId}/webhooks", {
270
- params: { path: { spaceId: "space_123" } },
271
- body: { url: "https://example.com/hook", events: ["cube.running"] },
322
+ const { data, error } = await krova.raw.GET("/spaces/{spaceId}/cubes/{cubeId}", {
323
+ params: { path: { spaceId: "space_123", cubeId: "cube_123" } },
272
324
  });
273
325
 
274
326
  if (error) {
275
- console.error("Webhook create failed:", error.error);
327
+ console.error("Cube lookup failed:", error.error);
276
328
  } else {
277
329
  console.log(data);
278
330
  }
@@ -287,7 +339,7 @@ type Domain = components["schemas"]["Domain"];
287
339
 
288
340
  ### `KrovaError`
289
341
 
290
- Thrown by the `cubes.*` / `catalog.*` helpers on any non-2xx response. (`client.raw` never throws — it returns the error in `{ error }`.)
342
+ Thrown by every helper on any non-2xx response. (`client.raw` never throws — it returns the error in `{ error }`.)
291
343
 
292
344
  | Field | Type | Source |
293
345
  | --- | --- | --- |
@@ -329,7 +381,7 @@ const krova = new KrovaClient({
329
381
 
330
382
  ## TypeScript
331
383
 
332
- The package ships its own type declarations — no `@types/*` install needed. `Cube`, `KrovaError`, `KrovaClientOptions`, `AuthScheme`, and the generated `paths` / `components` are all exported.
384
+ The package ships its own type declarations — no `@types/*` install needed. `Cube`, `Backup`, `BackupShare`, `KrovaError`, `KrovaClientOptions`, `AuthScheme`, and the generated `paths` / `components` are all exported.
333
385
 
334
386
  ## Related packages
335
387
 
package/dist/index.cjs CHANGED
@@ -672,16 +672,122 @@ var KrovaClient = class {
672
672
  return data;
673
673
  }
674
674
  };
675
- backups = {
676
- /** Get a time-limited download URL for a backup `.cube` archive. */
677
- download: async (spaceId, backupId) => {
678
- const { data, error, response } = await this.raw.GET("/spaces/{spaceId}/backups/{backupId}/download", { params: { path: {
679
- spaceId,
680
- backupId
681
- } } });
682
- if (error !== void 0 || !response.ok) throw krovaErrorFrom(response, error);
683
- return data;
684
- } };
675
+ backups = {
676
+ /** List the space's backups, newest first, including copies shared into it. */
677
+ list: async (spaceId) => {
678
+ const { data, error, response } = await this.raw.GET("/spaces/{spaceId}/backups", { params: { path: { spaceId } } });
679
+ if (error !== void 0 || !response.ok) throw krovaErrorFrom(response, error);
680
+ return data?.backups ?? [];
681
+ },
682
+ /** Get one backup. */
683
+ get: async (spaceId, backupId) => {
684
+ const { data, error, response } = await this.raw.GET("/spaces/{spaceId}/backups/{backupId}", { params: { path: {
685
+ spaceId,
686
+ backupId
687
+ } } });
688
+ if (error !== void 0 || !response.ok) throw krovaErrorFrom(response, error);
689
+ if (!data?.backup) throw krovaErrorFrom(response, { error: "Get backup response had no `backup`." });
690
+ return data.backup;
691
+ },
692
+ /** Get a time-limited download URL for a backup `.cube` archive. */
693
+ download: async (spaceId, backupId) => {
694
+ const { data, error, response } = await this.raw.GET("/spaces/{spaceId}/backups/{backupId}/download", { params: { path: {
695
+ spaceId,
696
+ backupId
697
+ } } });
698
+ if (error !== void 0 || !response.ok) throw krovaErrorFrom(response, error);
699
+ return data;
700
+ },
701
+ /**
702
+ * Offer a copy of a backup to another space. Returns the pending
703
+ * {@link BackupShare}.
704
+ *
705
+ * Nothing is copied until the destination accepts: its owner, or a member
706
+ * there with `backup.manage`, within 48 hours. The accepted copy is the
707
+ * destination's own and is billed to it; this space's backup and bill are
708
+ * unchanged. Through the API a share is always a request, even when your
709
+ * user owns both spaces.
710
+ *
711
+ * A refusal at this step never says anything about the destination's
712
+ * billing or verification; those are checked when it accepts.
713
+ *
714
+ * @param spaceId The space that holds the backup.
715
+ * @param backupId The backup to share.
716
+ * @param body `{ destinationSpaceId }`.
717
+ * @param opts Optional `idempotencyKey` (max 255 chars, scoped per space).
718
+ */
719
+ share: async (spaceId, backupId, body, opts) => {
720
+ const { data, error, response } = await this.raw.POST("/spaces/{spaceId}/backups/{backupId}/shares", {
721
+ params: {
722
+ path: {
723
+ spaceId,
724
+ backupId
725
+ },
726
+ ...opts?.idempotencyKey ? { header: { "Idempotency-Key": opts.idempotencyKey } } : {}
727
+ },
728
+ body
729
+ });
730
+ if (error !== void 0 || !response.ok) throw krovaErrorFrom(response, error);
731
+ if (!data?.share) throw krovaErrorFrom(response, { error: "Share backup response had no `share`." });
732
+ return data.share;
733
+ }
734
+ };
735
+ backupShares = {
736
+ /** Pending, unexpired shares into (`incoming`) and out of (`outgoing`) a space. */
737
+ list: async (spaceId) => {
738
+ const { data, error, response } = await this.raw.GET("/spaces/{spaceId}/backup-shares", { params: { path: { spaceId } } });
739
+ if (error !== void 0 || !response.ok) throw krovaErrorFrom(response, error);
740
+ return {
741
+ incoming: data?.incoming ?? [],
742
+ outgoing: data?.outgoing ?? []
743
+ };
744
+ },
745
+ /**
746
+ * Accept a share offered to this space. Returns the share and the space's
747
+ * new copy of the backup.
748
+ *
749
+ * The copy is billed to this space from now, so only a key of the space's
750
+ * owner, or of a member holding `backup.manage`, may accept. A space that
751
+ * cannot take the copy (no card or credit, owner not verified, an open abuse
752
+ * notice, or no backup allowance left on its plan) is refused with a 422.
753
+ */
754
+ accept: async (spaceId, shareId) => {
755
+ const { data, error, response } = await this.raw.POST("/spaces/{spaceId}/backup-shares/{shareId}/accept", { params: { path: {
756
+ spaceId,
757
+ shareId
758
+ } } });
759
+ if (error !== void 0 || !response.ok) throw krovaErrorFrom(response, error);
760
+ if (!data?.share || !data.backup) throw krovaErrorFrom(response, { error: "Accept backup share response had no `share` or `backup`." });
761
+ return {
762
+ share: data.share,
763
+ backup: data.backup
764
+ };
765
+ },
766
+ /** Decline a share offered to this space. Same permission as {@link accept}. */
767
+ decline: async (spaceId, shareId) => {
768
+ const { data, error, response } = await this.raw.POST("/spaces/{spaceId}/backup-shares/{shareId}/decline", { params: { path: {
769
+ spaceId,
770
+ shareId
771
+ } } });
772
+ if (error !== void 0 || !response.ok) throw krovaErrorFrom(response, error);
773
+ if (!data?.share) throw krovaErrorFrom(response, { error: "Decline backup share response had no `share`." });
774
+ return data.share;
775
+ },
776
+ /**
777
+ * Withdraw a pending share this space offered. Allowed for a key of the
778
+ * space's owner, of a member holding `backup.manage`, or of the member who
779
+ * raised the request.
780
+ */
781
+ cancel: async (spaceId, shareId) => {
782
+ const { data, error, response } = await this.raw.POST("/spaces/{spaceId}/backup-shares/{shareId}/cancel", { params: { path: {
783
+ spaceId,
784
+ shareId
785
+ } } });
786
+ if (error !== void 0 || !response.ok) throw krovaErrorFrom(response, error);
787
+ if (!data?.share) throw krovaErrorFrom(response, { error: "Cancel backup share response had no `share`." });
788
+ return data.share;
789
+ }
790
+ };
685
791
  webhooks = {
686
792
  /** List webhook endpoints in a Space. */
687
793
  list: async (spaceId) => {