@krovacloud/sdk 0.5.0 → 0.5.2
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 +6 -0
- package/README.md +47 -1
- package/dist/client-DWShmqpe.d.cts +3337 -0
- package/dist/client-DWShmqpe.d.ts +3337 -0
- package/dist/index.cjs +77 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -3158
- package/dist/index.d.ts +2 -3158
- package/dist/index.js +75 -1
- package/dist/index.js.map +1 -1
- package/dist/rolldown-runtime-CmQyd0Gu.cjs +27 -0
- package/dist/ssh.cjs +349 -0
- package/dist/ssh.cjs.map +1 -0
- package/dist/ssh.d.cts +133 -0
- package/dist/ssh.d.ts +133 -0
- package/dist/ssh.js +335 -0
- package/dist/ssh.js.map +1 -0
- package/package.json +15 -2
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,12 @@ All notable changes to `@krovacloud/sdk` are documented here. This project adher
|
|
|
9
9
|
|
|
10
10
|
### Added
|
|
11
11
|
|
|
12
|
+
- `cubes.setIdleTimeout(spaceId, cubeId, minutes | null)`, `idleTimeoutMinutes?: number | null` on the `cubes.create()` body, and `idleTimeoutMinutes` and `lastActiveAt` on `Cube`: Krova powers a Cube off after that many minutes without activity (10 to 10080, or `null` for off). These need a server with the idle-timeout feature, which krova-cloud has not deployed yet: `setIdleTimeout` gets a `400` from an older server, `create` is silently ignored there, and both `Cube` fields are absent. The OpenAPI snapshot and generated types include them, and `packages/sdk/openapi-pending.json` lists them so the drift check stays green until the deploy.
|
|
13
|
+
|
|
14
|
+
- `cubes.rename(spaceId, cubeId, name)` and `cubes.resize(spaceId, cubeId, { vcpu?, ramGb?, diskGb? }, opts?)`, with the exported types `ResizeCubeInput` and `ResizeCubeResult`. `resize` resolves to `{ success, state: "queued", jobId, isLive, requiresRestart, previous, requested }`; the Cube keeps its size until the worker applies the change. `getSpace()` now returns `apiKey: { name, expiresAt } | null` (`expiresAt` is `null` for a key that never expires; `apiKey` is `null` for an OAuth token and absent on an older server). The OpenAPI snapshot and generated types include these API changes, which krova-cloud has not deployed yet: until it does, `packages/sdk/openapi-pending.json` lists them so the drift check stays green.
|
|
15
|
+
|
|
16
|
+
- `@krovacloud/sdk/ssh`, a Node-only entry for running commands and moving files on a Cube over its own SSH with a private key you supply: `connectCube(krova, spaceId, cubeId, { privateKey, passphrase?, readyTimeoutMs?, hostKeys? })` returns a shell with `run()`, `files.write/read/upload/download` and `close()`. The host key is checked against the keys from `cubes.ssh()` and a mismatch throws `HostKeyMismatchError`; there is no way to skip the check. Also exports `shellQuote`, `RunTimeoutError` and `SshError`. Adds the `ssh2` dependency; the main entry does not load it.
|
|
17
|
+
|
|
12
18
|
- 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
19
|
|
|
14
20
|
- `proxyProtocol` (`"v1"`, `"v2"` or `null`) on `domains.create()` and
|
package/README.md
CHANGED
|
@@ -105,8 +105,12 @@ Throws if `apiKey` is missing. Exposes `client.baseUrl` (the resolved base URL),
|
|
|
105
105
|
Resolve the `Space` your API key is scoped to — so you don't have to hardcode a `spaceId`:
|
|
106
106
|
|
|
107
107
|
```ts
|
|
108
|
-
const space = await krova.getSpace(); // { id, name, tier, createdAt }
|
|
108
|
+
const space = await krova.getSpace(); // { id, name, tier, createdAt, apiKey }
|
|
109
109
|
const cubes = await krova.cubes.list(space.id);
|
|
110
|
+
|
|
111
|
+
// When does this key stop working? null = never. `apiKey` itself is null for an OAuth
|
|
112
|
+
// token, and missing on an older server, so treat missing as unknown.
|
|
113
|
+
const expiresAt = space.apiKey?.expiresAt;
|
|
110
114
|
```
|
|
111
115
|
|
|
112
116
|
### `client.cubes`
|
|
@@ -120,12 +124,23 @@ Ergonomic helpers for the Cube lifecycle. Each unwraps the response body and thr
|
|
|
120
124
|
| `get` | `(spaceId, cubeId)` | the Cube body |
|
|
121
125
|
| `update` | `(spaceId, cubeId, body)` | changes the port sshd listens on inside the Cube |
|
|
122
126
|
| `setTerminationProtection` | `(spaceId, cubeId, enabled)` | the updated `Cube`. While protection is on, `delete` throws `TerminationProtectedError` (a `KrovaError` for the API's `409`) |
|
|
127
|
+
| `rename` | `(spaceId, cubeId, name)` | the updated `Cube`. The name is trimmed, 1 to 64 printable characters, and does not have to be unique |
|
|
128
|
+
| `setIdleTimeout` | `(spaceId, cubeId, minutes \| null)` | the updated `Cube`. Krova powers the Cube off after that many minutes without activity: an integer from 10 to 10080, or `null` for off. Needs a server with the idle-timeout feature (an older one answers `400`) |
|
|
129
|
+
| `resize` | `(spaceId, cubeId, { vcpu?, ramGb?, diskGb? }, opts?)` | enqueues a resize and returns `{ jobId, isLive, requiresRestart, previous, requested }`. `isLive` means no restart; `requiresRestart` is its inverse. Send only what changes; disk can only grow. `opts.idempotencyKey` makes retries safe |
|
|
123
130
|
| `delete` | `(spaceId, cubeId)` | enqueues deletion |
|
|
124
131
|
| `powerOff` | `(spaceId, cubeId)` | enqueues a power-off |
|
|
125
132
|
| `wake` | `(spaceId, cubeId)` | enqueues a start |
|
|
126
133
|
| `ssh` | `(spaceId, cubeId)` | the Cube's SSH connection info — `host` is its stable SSH hostname (falls back to the server's public IPv4 with no DNS record yet), plus `port`, `user`, `hostKeys` |
|
|
127
134
|
| `restore` | `(spaceId, cubeId, snapshotId)` | enqueues a restore — replaces the Cube's disk from a snapshot |
|
|
128
135
|
|
|
136
|
+
```ts
|
|
137
|
+
// rename and resize
|
|
138
|
+
await krova.cubes.rename("space_123", "cube_123", "web-1");
|
|
139
|
+
const job = await krova.cubes.resize("space_123", "cube_123", { ramGb: 4, diskGb: 40 });
|
|
140
|
+
if (job.requiresRestart) console.log("the Cube restarts to apply this");
|
|
141
|
+
// The Cube keeps its size until the worker applies the change; read it again to see the new one.
|
|
142
|
+
```
|
|
143
|
+
|
|
129
144
|
```ts
|
|
130
145
|
// create — sshPublicKey is required; region + userData (cloud-init) are optional.
|
|
131
146
|
// opts.idempotencyKey (≤255 chars, per-space) makes retries safe.
|
|
@@ -139,6 +154,7 @@ const cube = await krova.cubes.create(
|
|
|
139
154
|
region: "us", // optional — slug from catalog.regions()
|
|
140
155
|
userData: "#cloud-config\n", // optional — cloud-init (max 16 KB)
|
|
141
156
|
terminationProtection: true, // optional — refuse deletes until turned off
|
|
157
|
+
idleTimeoutMinutes: 60, // optional — power off after 60 idle minutes (10-10080; null = off)
|
|
142
158
|
},
|
|
143
159
|
{ idempotencyKey: "deploy-2026-07-01" },
|
|
144
160
|
);
|
|
@@ -368,6 +384,36 @@ try {
|
|
|
368
384
|
|
|
369
385
|
Mutating `POST` / `DELETE` endpoints are rate-limited (10 requests / 60s per client IP). The client automatically retries `429` and `503` up to `maxRetries` times, honoring the `Retry-After` header.
|
|
370
386
|
|
|
387
|
+
## Run commands and move files
|
|
388
|
+
|
|
389
|
+
Krova has no exec or files API. Commands and files go over the Cube's own SSH, with a private key you supply, through the Node-only `@krovacloud/sdk/ssh` entry. The main entry never loads it, so browser and edge code is unaffected.
|
|
390
|
+
|
|
391
|
+
```ts
|
|
392
|
+
import { KrovaClient } from "@krovacloud/sdk";
|
|
393
|
+
import { connectCube } from "@krovacloud/sdk/ssh";
|
|
394
|
+
|
|
395
|
+
const krova = new KrovaClient({ apiKey: process.env.KROVA_API_KEY! });
|
|
396
|
+
const shell = await connectCube(krova, spaceId, cubeId, {
|
|
397
|
+
privateKey: process.env.CUBE_SSH_KEY!, // the private half of a key on the Cube
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
try {
|
|
401
|
+
const { stdout, stderr, exitCode } = await shell.run(["ls", "-la"], { cwd: "/srv" });
|
|
402
|
+
await shell.files.write("/srv/hello.txt", "hello");
|
|
403
|
+
const bytes = await shell.files.read("/srv/hello.txt");
|
|
404
|
+
await shell.files.upload("./build.tar.gz", "/srv/build.tar.gz");
|
|
405
|
+
await shell.files.download("/var/log/app.log", "./app.log");
|
|
406
|
+
} finally {
|
|
407
|
+
await shell.close();
|
|
408
|
+
}
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
- `run(command, { cwd?, env?, timeoutMs?, stdin? })` returns `{ stdout, stderr, exitCode, signal? }`. A string runs as written in the Cube's shell. A string array has each argument quoted for you (`shellQuote` is exported), as are `cwd` and the `env` values. A timeout closes the channel and rejects with `RunTimeoutError`.
|
|
412
|
+
- The connection is verified against the Cube's host keys from `krova.cubes.ssh()`. A key that does not match, or a Cube with no keys captured yet, throws `HostKeyMismatchError`. If you keep your own pinned keys, pass them as `hostKeys`. There is no option to skip the check.
|
|
413
|
+
- Your key is used for the connection and never logged or stored by the SDK. An encrypted key takes `passphrase`.
|
|
414
|
+
- `ssh2` has an optional native addon (`cpu-features`) with an install script. The SDK works without it, so pnpm users can leave that script disabled.
|
|
415
|
+
- File paths are literal: `~` and `$VAR` are not expanded. `files.read` and `files.write` hold the whole file in memory; use `upload` and `download` for large files.
|
|
416
|
+
|
|
371
417
|
## Configuration
|
|
372
418
|
|
|
373
419
|
Point the client at a different base URL (self-hosted gateway, staging, a proxy):
|