@krovacloud/sdk 0.1.5 → 0.2.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 +26 -0
- package/README.md +12 -2
- package/dist/index.cjs +44 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +261 -1
- package/dist/index.d.ts +261 -1
- package/dist/index.js +44 -3
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,32 @@ 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.2.0
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- `client.getSpace()` — resolve the `Space` your API key is scoped to, so you no
|
|
12
|
+
longer have to hardcode a `spaceId`.
|
|
13
|
+
- `client.cubes.ssh(spaceId, cubeId)` — fetch a Cube's SSH connection info
|
|
14
|
+
(`host`, `port`, `user`, and pinned `hostKeys`).
|
|
15
|
+
- Exported `Space` and `CubeSshInfo` types.
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
|
|
19
|
+
- Refreshed the bundled OpenAPI spec to the current API (26 paths / 35
|
|
20
|
+
operations). `client.raw` can now reach `GET /space`, the cube SSH-info
|
|
21
|
+
endpoint, and the CLI device-auth endpoints, which the stale bundle omitted.
|
|
22
|
+
|
|
23
|
+
## 0.1.6
|
|
24
|
+
|
|
25
|
+
### Fixed
|
|
26
|
+
|
|
27
|
+
- Auto-retry no longer throws `TypeError: unusable` on requests with a body
|
|
28
|
+
(POST/PUT/DELETE) — a pristine copy of the request is captured before its body
|
|
29
|
+
is consumed, so retries of the mutating, rate-limited endpoints work.
|
|
30
|
+
- A hostile or misconfigured `Retry-After` is now capped at the maximum backoff
|
|
31
|
+
(10s), so the client can't be parked for minutes/hours.
|
|
32
|
+
|
|
7
33
|
## 0.1.5
|
|
8
34
|
|
|
9
35
|
### Changed
|
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ The official TypeScript SDK for the [Krova Cloud](https://krova.cloud) API — a
|
|
|
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
13
|
- **Ergonomic helpers** — `client.cubes.*` and `client.catalog.*` unwrap the response body and throw a typed `KrovaError` on failure.
|
|
14
|
-
- **Full escape hatch** — `client.raw` exposes the underlying typed client for
|
|
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`.
|
|
17
17
|
|
|
@@ -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.
|
package/dist/index.cjs
CHANGED
|
@@ -76,8 +76,18 @@ function authMiddleware(apiKey, scheme) {
|
|
|
76
76
|
};
|
|
77
77
|
}
|
|
78
78
|
function retryMiddleware(maxRetries, doFetch) {
|
|
79
|
+
const pristine = /* @__PURE__ */ new Map();
|
|
79
80
|
return {
|
|
80
|
-
|
|
81
|
+
onRequest({ request, id }) {
|
|
82
|
+
pristine.set(id, request.clone());
|
|
83
|
+
return request;
|
|
84
|
+
},
|
|
85
|
+
onError({ id }) {
|
|
86
|
+
pristine.delete(id);
|
|
87
|
+
},
|
|
88
|
+
async onResponse({ request, response, id }) {
|
|
89
|
+
const original = pristine.get(id) ?? request;
|
|
90
|
+
pristine.delete(id);
|
|
81
91
|
if (maxRetries <= 0 || !RETRYABLE_STATUSES.has(response.status)) {
|
|
82
92
|
return response;
|
|
83
93
|
}
|
|
@@ -86,8 +96,8 @@ function retryMiddleware(maxRetries, doFetch) {
|
|
|
86
96
|
if (!RETRYABLE_STATUSES.has(current.status)) break;
|
|
87
97
|
const retryAfterMs = parseRetryAfterMs(current.headers.get("retry-after"));
|
|
88
98
|
const backoff = Math.min(BASE_BACKOFF_MS * 2 ** (attempt - 1), MAX_BACKOFF_MS);
|
|
89
|
-
await sleep(retryAfterMs ?? backoff);
|
|
90
|
-
current = await doFetch(
|
|
99
|
+
await sleep(Math.min(retryAfterMs ?? backoff, MAX_BACKOFF_MS));
|
|
100
|
+
current = await doFetch(original.clone());
|
|
91
101
|
}
|
|
92
102
|
return current;
|
|
93
103
|
}
|
|
@@ -228,8 +238,39 @@ var KrovaClient = class {
|
|
|
228
238
|
);
|
|
229
239
|
if (error !== void 0 || !response.ok) throw krovaErrorFrom(response, error);
|
|
230
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;
|
|
231
255
|
}
|
|
232
256
|
};
|
|
257
|
+
/**
|
|
258
|
+
* Resolve the {@link Space} this API key is scoped to — so you don't have to
|
|
259
|
+
* hardcode a `spaceId`. Handy right after constructing the client:
|
|
260
|
+
*
|
|
261
|
+
* @example
|
|
262
|
+
* ```ts
|
|
263
|
+
* const space = await krova.getSpace();
|
|
264
|
+
* const cubes = await krova.cubes.list(space.id);
|
|
265
|
+
* ```
|
|
266
|
+
*/
|
|
267
|
+
async getSpace() {
|
|
268
|
+
const { data, error, response } = await this.raw.GET("/space");
|
|
269
|
+
if (error !== void 0 || !response.ok) throw krovaErrorFrom(response, error);
|
|
270
|
+
if (data === void 0)
|
|
271
|
+
throw krovaErrorFrom(response, { error: "Space response was empty." });
|
|
272
|
+
return data;
|
|
273
|
+
}
|
|
233
274
|
// ---------------------------------------------------------------------------
|
|
234
275
|
// Public catalog (no auth required by the API, but the key is harmless)
|
|
235
276
|
// ---------------------------------------------------------------------------
|
package/dist/index.cjs.map
CHANGED
|
@@ -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,CACd,UACA,IAAA,EACY;AACZ,EAAA,MAAM,OAAA,GACH,OAAO,IAAA,EAAM,KAAA,KAAU,QAAA,IAAY,IAAA,CAAK,KAAA,IACzC,QAAA,CAAS,UAAA,IACT,CAAA,2BAAA,EAA8B,QAAA,CAAS,MAAM,CAAA,CAAA;AAC/C,EAAA,OAAO,IAAI,WAAW,OAAA,EAAS;AAAA,IAC7B,QAAQ,QAAA,CAAS,MAAA;AAAA,IACjB,IAAA,EAAM,QAAA,CAAS,OAAA,CAAQ,GAAA,CAAI,cAAc,CAAA,IAAK,MAAA;AAAA,IAC9C,SAAA,EAAW,QAAA,CAAS,OAAA,C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AAA,KAAS,MAAA;AACX,QAAA,MAAM,cAAA,CAAe,QAAA,EAAU,EAAE,KAAA,EAAO,8BAA8B,CAAA;AACxE,MAAA,OAAO,IAAA;AAAA,IACT,CAAA;AAAA;AAAA,IAGA,SAAS,YAAY;AACnB,MAAA,MAAM,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/** 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. openapi-fetch\n * clones the request per attempt, so re-fetching here is safe.\n */\nfunction retryMiddleware(maxRetries: number, doFetch: typeof fetch): Middleware {\n return {\n async onResponse({ request, response }) {\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 await sleep(retryAfterMs ?? backoff);\n current = await doFetch(request.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,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;AAEr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E,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/** 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 /**\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 // 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"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -126,6 +126,187 @@ interface paths {
|
|
|
126
126
|
patch?: never;
|
|
127
127
|
trace?: never;
|
|
128
128
|
};
|
|
129
|
+
"/auth/cli/start": {
|
|
130
|
+
parameters: {
|
|
131
|
+
query?: never;
|
|
132
|
+
header?: never;
|
|
133
|
+
path?: never;
|
|
134
|
+
cookie?: never;
|
|
135
|
+
};
|
|
136
|
+
get?: never;
|
|
137
|
+
put?: never;
|
|
138
|
+
/**
|
|
139
|
+
* Begin a CLI device-authorization login (RFC 8628)
|
|
140
|
+
* @description Public, unauthenticated. Mints a device code (returned once) and a short human user code, and returns the verification URIs the user opens in a browser to approve. The CLI then polls /auth/cli/poll. Rate-limited per client IP.
|
|
141
|
+
*/
|
|
142
|
+
post: {
|
|
143
|
+
parameters: {
|
|
144
|
+
query?: never;
|
|
145
|
+
header?: never;
|
|
146
|
+
path?: never;
|
|
147
|
+
cookie?: never;
|
|
148
|
+
};
|
|
149
|
+
requestBody?: never;
|
|
150
|
+
responses: {
|
|
151
|
+
/** @description Device-authorization request created */
|
|
152
|
+
200: {
|
|
153
|
+
headers: {
|
|
154
|
+
[name: string]: unknown;
|
|
155
|
+
};
|
|
156
|
+
content: {
|
|
157
|
+
"application/json": {
|
|
158
|
+
/** @description High-entropy code the CLI keeps secret and presents on each poll. Only its hash is stored server-side. */
|
|
159
|
+
deviceCode: string;
|
|
160
|
+
/** @description Short human-readable code (KROVA-XXXX-XXXX) the user confirms in the browser. */
|
|
161
|
+
userCode: string;
|
|
162
|
+
/**
|
|
163
|
+
* Format: uri
|
|
164
|
+
* @description Browser URL where the user approves.
|
|
165
|
+
*/
|
|
166
|
+
verificationUri: string;
|
|
167
|
+
/**
|
|
168
|
+
* Format: uri
|
|
169
|
+
* @description verificationUri with the user code pre-filled.
|
|
170
|
+
*/
|
|
171
|
+
verificationUriComplete: string;
|
|
172
|
+
/** @description Seconds to wait between polls. */
|
|
173
|
+
interval: number;
|
|
174
|
+
/** @description Seconds until the device code expires (~600). */
|
|
175
|
+
expiresIn: number;
|
|
176
|
+
};
|
|
177
|
+
};
|
|
178
|
+
};
|
|
179
|
+
429: components["responses"]["RateLimited"];
|
|
180
|
+
/** @description Could not allocate a login code; retry */
|
|
181
|
+
503: {
|
|
182
|
+
headers: {
|
|
183
|
+
[name: string]: unknown;
|
|
184
|
+
};
|
|
185
|
+
content?: never;
|
|
186
|
+
};
|
|
187
|
+
};
|
|
188
|
+
};
|
|
189
|
+
delete?: never;
|
|
190
|
+
options?: never;
|
|
191
|
+
head?: never;
|
|
192
|
+
patch?: never;
|
|
193
|
+
trace?: never;
|
|
194
|
+
};
|
|
195
|
+
"/auth/cli/poll": {
|
|
196
|
+
parameters: {
|
|
197
|
+
query?: never;
|
|
198
|
+
header?: never;
|
|
199
|
+
path?: never;
|
|
200
|
+
cookie?: never;
|
|
201
|
+
};
|
|
202
|
+
get?: never;
|
|
203
|
+
put?: never;
|
|
204
|
+
/**
|
|
205
|
+
* Poll for CLI device-authorization approval (RFC 8628)
|
|
206
|
+
* @description Public, unauthenticated. The CLI submits its deviceCode until the user approves or denies. On approval a real API key is minted ONCE, scoped to the approved Space and the approving user's membership, and returned a single time. Rate-limited per client IP.
|
|
207
|
+
*/
|
|
208
|
+
post: {
|
|
209
|
+
parameters: {
|
|
210
|
+
query?: never;
|
|
211
|
+
header?: never;
|
|
212
|
+
path?: never;
|
|
213
|
+
cookie?: never;
|
|
214
|
+
};
|
|
215
|
+
requestBody: {
|
|
216
|
+
content: {
|
|
217
|
+
"application/json": {
|
|
218
|
+
/** @description The device code from /auth/cli/start. */
|
|
219
|
+
deviceCode: string;
|
|
220
|
+
};
|
|
221
|
+
};
|
|
222
|
+
};
|
|
223
|
+
responses: {
|
|
224
|
+
/** @description Approved — API key minted (returned once) */
|
|
225
|
+
200: {
|
|
226
|
+
headers: {
|
|
227
|
+
[name: string]: unknown;
|
|
228
|
+
};
|
|
229
|
+
content: {
|
|
230
|
+
"application/json": {
|
|
231
|
+
/** @description The full API key. Shown once and never returned again — store it securely. */
|
|
232
|
+
apiKey: string;
|
|
233
|
+
/** @description The Space the key is scoped to. */
|
|
234
|
+
spaceId: string;
|
|
235
|
+
};
|
|
236
|
+
};
|
|
237
|
+
};
|
|
238
|
+
400: components["responses"]["BadRequest"];
|
|
239
|
+
/** @description The user denied the login request */
|
|
240
|
+
403: {
|
|
241
|
+
headers: {
|
|
242
|
+
[name: string]: unknown;
|
|
243
|
+
};
|
|
244
|
+
content?: never;
|
|
245
|
+
};
|
|
246
|
+
/** @description The device code expired, was already consumed, or is unknown */
|
|
247
|
+
410: {
|
|
248
|
+
headers: {
|
|
249
|
+
[name: string]: unknown;
|
|
250
|
+
};
|
|
251
|
+
content?: never;
|
|
252
|
+
};
|
|
253
|
+
/** @description Authorization still pending — keep polling at the given interval */
|
|
254
|
+
428: {
|
|
255
|
+
headers: {
|
|
256
|
+
[name: string]: unknown;
|
|
257
|
+
};
|
|
258
|
+
content?: never;
|
|
259
|
+
};
|
|
260
|
+
429: components["responses"]["RateLimited"];
|
|
261
|
+
};
|
|
262
|
+
};
|
|
263
|
+
delete?: never;
|
|
264
|
+
options?: never;
|
|
265
|
+
head?: never;
|
|
266
|
+
patch?: never;
|
|
267
|
+
trace?: never;
|
|
268
|
+
};
|
|
269
|
+
"/space": {
|
|
270
|
+
parameters: {
|
|
271
|
+
query?: never;
|
|
272
|
+
header?: never;
|
|
273
|
+
path?: never;
|
|
274
|
+
cookie?: never;
|
|
275
|
+
};
|
|
276
|
+
/**
|
|
277
|
+
* Resolve the space this API key is scoped to
|
|
278
|
+
* @description Returns the single space the API key belongs to. Lets a client auto-resolve the space id from the key alone (no spaceId in the URL).
|
|
279
|
+
*/
|
|
280
|
+
get: {
|
|
281
|
+
parameters: {
|
|
282
|
+
query?: never;
|
|
283
|
+
header?: never;
|
|
284
|
+
path?: never;
|
|
285
|
+
cookie?: never;
|
|
286
|
+
};
|
|
287
|
+
requestBody?: never;
|
|
288
|
+
responses: {
|
|
289
|
+
/** @description The key's space */
|
|
290
|
+
200: {
|
|
291
|
+
headers: {
|
|
292
|
+
[name: string]: unknown;
|
|
293
|
+
};
|
|
294
|
+
content: {
|
|
295
|
+
"application/json": components["schemas"]["Space"];
|
|
296
|
+
};
|
|
297
|
+
};
|
|
298
|
+
401: components["responses"]["Unauthorized"];
|
|
299
|
+
404: components["responses"]["NotFound"];
|
|
300
|
+
};
|
|
301
|
+
};
|
|
302
|
+
put?: never;
|
|
303
|
+
post?: never;
|
|
304
|
+
delete?: never;
|
|
305
|
+
options?: never;
|
|
306
|
+
head?: never;
|
|
307
|
+
patch?: never;
|
|
308
|
+
trace?: never;
|
|
309
|
+
};
|
|
129
310
|
"/spaces/{spaceId}/cubes": {
|
|
130
311
|
parameters: {
|
|
131
312
|
query?: never;
|
|
@@ -415,6 +596,49 @@ interface paths {
|
|
|
415
596
|
patch?: never;
|
|
416
597
|
trace?: never;
|
|
417
598
|
};
|
|
599
|
+
"/spaces/{spaceId}/cubes/{cubeId}/ssh": {
|
|
600
|
+
parameters: {
|
|
601
|
+
query?: never;
|
|
602
|
+
header?: never;
|
|
603
|
+
path?: never;
|
|
604
|
+
cookie?: never;
|
|
605
|
+
};
|
|
606
|
+
/**
|
|
607
|
+
* Get a Cube's SSH connection info
|
|
608
|
+
* @description Host (server public IPv4), host SSH port, login user, and any captured SSH host public keys. `hostKeys` is empty until Krova captures cube host keys — clients fall back to trust-on-first-use until then.
|
|
609
|
+
*/
|
|
610
|
+
get: {
|
|
611
|
+
parameters: {
|
|
612
|
+
query?: never;
|
|
613
|
+
header?: never;
|
|
614
|
+
path: {
|
|
615
|
+
spaceId: string;
|
|
616
|
+
cubeId: string;
|
|
617
|
+
};
|
|
618
|
+
cookie?: never;
|
|
619
|
+
};
|
|
620
|
+
requestBody?: never;
|
|
621
|
+
responses: {
|
|
622
|
+
/** @description SSH connection info */
|
|
623
|
+
200: {
|
|
624
|
+
headers: {
|
|
625
|
+
[name: string]: unknown;
|
|
626
|
+
};
|
|
627
|
+
content: {
|
|
628
|
+
"application/json": components["schemas"]["CubeSshInfo"];
|
|
629
|
+
};
|
|
630
|
+
};
|
|
631
|
+
404: components["responses"]["NotFound"];
|
|
632
|
+
};
|
|
633
|
+
};
|
|
634
|
+
put?: never;
|
|
635
|
+
post?: never;
|
|
636
|
+
delete?: never;
|
|
637
|
+
options?: never;
|
|
638
|
+
head?: never;
|
|
639
|
+
patch?: never;
|
|
640
|
+
trace?: never;
|
|
641
|
+
};
|
|
418
642
|
"/spaces/{spaceId}/cubes/{cubeId}/domains": {
|
|
419
643
|
parameters: {
|
|
420
644
|
query?: never;
|
|
@@ -1377,6 +1601,22 @@ interface paths {
|
|
|
1377
1601
|
}
|
|
1378
1602
|
interface components {
|
|
1379
1603
|
schemas: {
|
|
1604
|
+
Space: {
|
|
1605
|
+
id: string;
|
|
1606
|
+
name: string;
|
|
1607
|
+
tier: string;
|
|
1608
|
+
/** Format: date-time */
|
|
1609
|
+
createdAt: string;
|
|
1610
|
+
};
|
|
1611
|
+
CubeSshInfo: {
|
|
1612
|
+
host: string | null;
|
|
1613
|
+
port: number;
|
|
1614
|
+
user: string;
|
|
1615
|
+
hostKeys: {
|
|
1616
|
+
type: string;
|
|
1617
|
+
key: string;
|
|
1618
|
+
}[];
|
|
1619
|
+
};
|
|
1380
1620
|
Cube: {
|
|
1381
1621
|
id: string;
|
|
1382
1622
|
name: string;
|
|
@@ -1571,6 +1811,10 @@ type Image = components["schemas"]["Image"];
|
|
|
1571
1811
|
type PricingTier = components["schemas"]["PricingTier"];
|
|
1572
1812
|
/** Pagination envelope returned alongside a Cube list. */
|
|
1573
1813
|
type Pagination = components["schemas"]["Pagination"];
|
|
1814
|
+
/** A Space — the tenancy an API key is scoped to. */
|
|
1815
|
+
type Space = components["schemas"]["Space"];
|
|
1816
|
+
/** A Cube's SSH connection info (host, port, user, and pinned host keys). */
|
|
1817
|
+
type CubeSshInfo = components["schemas"]["CubeSshInfo"];
|
|
1574
1818
|
/** Default API base URL — the single `servers[0].url` from the OpenAPI spec. */
|
|
1575
1819
|
declare const DEFAULT_BASE_URL = "https://krova.cloud/api/v1";
|
|
1576
1820
|
/**
|
|
@@ -1685,7 +1929,23 @@ declare class KrovaClient {
|
|
|
1685
1929
|
sleep: (spaceId: string, cubeId: string) => Promise<unknown>;
|
|
1686
1930
|
/** Wake a sleeping Cube (asynchronous — wake is enqueued). */
|
|
1687
1931
|
wake: (spaceId: string, cubeId: string) => Promise<unknown>;
|
|
1932
|
+
/**
|
|
1933
|
+
* Get a Cube's SSH connection info — host, port, login user, and (when
|
|
1934
|
+
* available) the pinned host public keys for strict host-key verification.
|
|
1935
|
+
*/
|
|
1936
|
+
ssh: (spaceId: string, cubeId: string) => Promise<CubeSshInfo>;
|
|
1688
1937
|
};
|
|
1938
|
+
/**
|
|
1939
|
+
* Resolve the {@link Space} this API key is scoped to — so you don't have to
|
|
1940
|
+
* hardcode a `spaceId`. Handy right after constructing the client:
|
|
1941
|
+
*
|
|
1942
|
+
* @example
|
|
1943
|
+
* ```ts
|
|
1944
|
+
* const space = await krova.getSpace();
|
|
1945
|
+
* const cubes = await krova.cubes.list(space.id);
|
|
1946
|
+
* ```
|
|
1947
|
+
*/
|
|
1948
|
+
getSpace(): Promise<Space>;
|
|
1689
1949
|
readonly catalog: {
|
|
1690
1950
|
/** List regions with available capacity. */
|
|
1691
1951
|
regions: () => Promise<{
|
|
@@ -1773,4 +2033,4 @@ declare class KrovaError extends Error {
|
|
|
1773
2033
|
*/
|
|
1774
2034
|
declare function krovaErrorFrom(response: Response, body: KrovaErrorBody | undefined): KrovaError;
|
|
1775
2035
|
|
|
1776
|
-
export { type AuthScheme, type Cube, DEFAULT_BASE_URL, type Image, KrovaClient, type KrovaClientOptions, KrovaError, type KrovaErrorBody, type Pagination, type PricingTier, type Region, type components, krovaErrorFrom, type paths };
|
|
2036
|
+
export { type AuthScheme, type Cube, type CubeSshInfo, DEFAULT_BASE_URL, type Image, KrovaClient, type KrovaClientOptions, KrovaError, type KrovaErrorBody, type Pagination, type PricingTier, type Region, type Space, type components, krovaErrorFrom, type paths };
|
package/dist/index.d.ts
CHANGED
|
@@ -126,6 +126,187 @@ interface paths {
|
|
|
126
126
|
patch?: never;
|
|
127
127
|
trace?: never;
|
|
128
128
|
};
|
|
129
|
+
"/auth/cli/start": {
|
|
130
|
+
parameters: {
|
|
131
|
+
query?: never;
|
|
132
|
+
header?: never;
|
|
133
|
+
path?: never;
|
|
134
|
+
cookie?: never;
|
|
135
|
+
};
|
|
136
|
+
get?: never;
|
|
137
|
+
put?: never;
|
|
138
|
+
/**
|
|
139
|
+
* Begin a CLI device-authorization login (RFC 8628)
|
|
140
|
+
* @description Public, unauthenticated. Mints a device code (returned once) and a short human user code, and returns the verification URIs the user opens in a browser to approve. The CLI then polls /auth/cli/poll. Rate-limited per client IP.
|
|
141
|
+
*/
|
|
142
|
+
post: {
|
|
143
|
+
parameters: {
|
|
144
|
+
query?: never;
|
|
145
|
+
header?: never;
|
|
146
|
+
path?: never;
|
|
147
|
+
cookie?: never;
|
|
148
|
+
};
|
|
149
|
+
requestBody?: never;
|
|
150
|
+
responses: {
|
|
151
|
+
/** @description Device-authorization request created */
|
|
152
|
+
200: {
|
|
153
|
+
headers: {
|
|
154
|
+
[name: string]: unknown;
|
|
155
|
+
};
|
|
156
|
+
content: {
|
|
157
|
+
"application/json": {
|
|
158
|
+
/** @description High-entropy code the CLI keeps secret and presents on each poll. Only its hash is stored server-side. */
|
|
159
|
+
deviceCode: string;
|
|
160
|
+
/** @description Short human-readable code (KROVA-XXXX-XXXX) the user confirms in the browser. */
|
|
161
|
+
userCode: string;
|
|
162
|
+
/**
|
|
163
|
+
* Format: uri
|
|
164
|
+
* @description Browser URL where the user approves.
|
|
165
|
+
*/
|
|
166
|
+
verificationUri: string;
|
|
167
|
+
/**
|
|
168
|
+
* Format: uri
|
|
169
|
+
* @description verificationUri with the user code pre-filled.
|
|
170
|
+
*/
|
|
171
|
+
verificationUriComplete: string;
|
|
172
|
+
/** @description Seconds to wait between polls. */
|
|
173
|
+
interval: number;
|
|
174
|
+
/** @description Seconds until the device code expires (~600). */
|
|
175
|
+
expiresIn: number;
|
|
176
|
+
};
|
|
177
|
+
};
|
|
178
|
+
};
|
|
179
|
+
429: components["responses"]["RateLimited"];
|
|
180
|
+
/** @description Could not allocate a login code; retry */
|
|
181
|
+
503: {
|
|
182
|
+
headers: {
|
|
183
|
+
[name: string]: unknown;
|
|
184
|
+
};
|
|
185
|
+
content?: never;
|
|
186
|
+
};
|
|
187
|
+
};
|
|
188
|
+
};
|
|
189
|
+
delete?: never;
|
|
190
|
+
options?: never;
|
|
191
|
+
head?: never;
|
|
192
|
+
patch?: never;
|
|
193
|
+
trace?: never;
|
|
194
|
+
};
|
|
195
|
+
"/auth/cli/poll": {
|
|
196
|
+
parameters: {
|
|
197
|
+
query?: never;
|
|
198
|
+
header?: never;
|
|
199
|
+
path?: never;
|
|
200
|
+
cookie?: never;
|
|
201
|
+
};
|
|
202
|
+
get?: never;
|
|
203
|
+
put?: never;
|
|
204
|
+
/**
|
|
205
|
+
* Poll for CLI device-authorization approval (RFC 8628)
|
|
206
|
+
* @description Public, unauthenticated. The CLI submits its deviceCode until the user approves or denies. On approval a real API key is minted ONCE, scoped to the approved Space and the approving user's membership, and returned a single time. Rate-limited per client IP.
|
|
207
|
+
*/
|
|
208
|
+
post: {
|
|
209
|
+
parameters: {
|
|
210
|
+
query?: never;
|
|
211
|
+
header?: never;
|
|
212
|
+
path?: never;
|
|
213
|
+
cookie?: never;
|
|
214
|
+
};
|
|
215
|
+
requestBody: {
|
|
216
|
+
content: {
|
|
217
|
+
"application/json": {
|
|
218
|
+
/** @description The device code from /auth/cli/start. */
|
|
219
|
+
deviceCode: string;
|
|
220
|
+
};
|
|
221
|
+
};
|
|
222
|
+
};
|
|
223
|
+
responses: {
|
|
224
|
+
/** @description Approved — API key minted (returned once) */
|
|
225
|
+
200: {
|
|
226
|
+
headers: {
|
|
227
|
+
[name: string]: unknown;
|
|
228
|
+
};
|
|
229
|
+
content: {
|
|
230
|
+
"application/json": {
|
|
231
|
+
/** @description The full API key. Shown once and never returned again — store it securely. */
|
|
232
|
+
apiKey: string;
|
|
233
|
+
/** @description The Space the key is scoped to. */
|
|
234
|
+
spaceId: string;
|
|
235
|
+
};
|
|
236
|
+
};
|
|
237
|
+
};
|
|
238
|
+
400: components["responses"]["BadRequest"];
|
|
239
|
+
/** @description The user denied the login request */
|
|
240
|
+
403: {
|
|
241
|
+
headers: {
|
|
242
|
+
[name: string]: unknown;
|
|
243
|
+
};
|
|
244
|
+
content?: never;
|
|
245
|
+
};
|
|
246
|
+
/** @description The device code expired, was already consumed, or is unknown */
|
|
247
|
+
410: {
|
|
248
|
+
headers: {
|
|
249
|
+
[name: string]: unknown;
|
|
250
|
+
};
|
|
251
|
+
content?: never;
|
|
252
|
+
};
|
|
253
|
+
/** @description Authorization still pending — keep polling at the given interval */
|
|
254
|
+
428: {
|
|
255
|
+
headers: {
|
|
256
|
+
[name: string]: unknown;
|
|
257
|
+
};
|
|
258
|
+
content?: never;
|
|
259
|
+
};
|
|
260
|
+
429: components["responses"]["RateLimited"];
|
|
261
|
+
};
|
|
262
|
+
};
|
|
263
|
+
delete?: never;
|
|
264
|
+
options?: never;
|
|
265
|
+
head?: never;
|
|
266
|
+
patch?: never;
|
|
267
|
+
trace?: never;
|
|
268
|
+
};
|
|
269
|
+
"/space": {
|
|
270
|
+
parameters: {
|
|
271
|
+
query?: never;
|
|
272
|
+
header?: never;
|
|
273
|
+
path?: never;
|
|
274
|
+
cookie?: never;
|
|
275
|
+
};
|
|
276
|
+
/**
|
|
277
|
+
* Resolve the space this API key is scoped to
|
|
278
|
+
* @description Returns the single space the API key belongs to. Lets a client auto-resolve the space id from the key alone (no spaceId in the URL).
|
|
279
|
+
*/
|
|
280
|
+
get: {
|
|
281
|
+
parameters: {
|
|
282
|
+
query?: never;
|
|
283
|
+
header?: never;
|
|
284
|
+
path?: never;
|
|
285
|
+
cookie?: never;
|
|
286
|
+
};
|
|
287
|
+
requestBody?: never;
|
|
288
|
+
responses: {
|
|
289
|
+
/** @description The key's space */
|
|
290
|
+
200: {
|
|
291
|
+
headers: {
|
|
292
|
+
[name: string]: unknown;
|
|
293
|
+
};
|
|
294
|
+
content: {
|
|
295
|
+
"application/json": components["schemas"]["Space"];
|
|
296
|
+
};
|
|
297
|
+
};
|
|
298
|
+
401: components["responses"]["Unauthorized"];
|
|
299
|
+
404: components["responses"]["NotFound"];
|
|
300
|
+
};
|
|
301
|
+
};
|
|
302
|
+
put?: never;
|
|
303
|
+
post?: never;
|
|
304
|
+
delete?: never;
|
|
305
|
+
options?: never;
|
|
306
|
+
head?: never;
|
|
307
|
+
patch?: never;
|
|
308
|
+
trace?: never;
|
|
309
|
+
};
|
|
129
310
|
"/spaces/{spaceId}/cubes": {
|
|
130
311
|
parameters: {
|
|
131
312
|
query?: never;
|
|
@@ -415,6 +596,49 @@ interface paths {
|
|
|
415
596
|
patch?: never;
|
|
416
597
|
trace?: never;
|
|
417
598
|
};
|
|
599
|
+
"/spaces/{spaceId}/cubes/{cubeId}/ssh": {
|
|
600
|
+
parameters: {
|
|
601
|
+
query?: never;
|
|
602
|
+
header?: never;
|
|
603
|
+
path?: never;
|
|
604
|
+
cookie?: never;
|
|
605
|
+
};
|
|
606
|
+
/**
|
|
607
|
+
* Get a Cube's SSH connection info
|
|
608
|
+
* @description Host (server public IPv4), host SSH port, login user, and any captured SSH host public keys. `hostKeys` is empty until Krova captures cube host keys — clients fall back to trust-on-first-use until then.
|
|
609
|
+
*/
|
|
610
|
+
get: {
|
|
611
|
+
parameters: {
|
|
612
|
+
query?: never;
|
|
613
|
+
header?: never;
|
|
614
|
+
path: {
|
|
615
|
+
spaceId: string;
|
|
616
|
+
cubeId: string;
|
|
617
|
+
};
|
|
618
|
+
cookie?: never;
|
|
619
|
+
};
|
|
620
|
+
requestBody?: never;
|
|
621
|
+
responses: {
|
|
622
|
+
/** @description SSH connection info */
|
|
623
|
+
200: {
|
|
624
|
+
headers: {
|
|
625
|
+
[name: string]: unknown;
|
|
626
|
+
};
|
|
627
|
+
content: {
|
|
628
|
+
"application/json": components["schemas"]["CubeSshInfo"];
|
|
629
|
+
};
|
|
630
|
+
};
|
|
631
|
+
404: components["responses"]["NotFound"];
|
|
632
|
+
};
|
|
633
|
+
};
|
|
634
|
+
put?: never;
|
|
635
|
+
post?: never;
|
|
636
|
+
delete?: never;
|
|
637
|
+
options?: never;
|
|
638
|
+
head?: never;
|
|
639
|
+
patch?: never;
|
|
640
|
+
trace?: never;
|
|
641
|
+
};
|
|
418
642
|
"/spaces/{spaceId}/cubes/{cubeId}/domains": {
|
|
419
643
|
parameters: {
|
|
420
644
|
query?: never;
|
|
@@ -1377,6 +1601,22 @@ interface paths {
|
|
|
1377
1601
|
}
|
|
1378
1602
|
interface components {
|
|
1379
1603
|
schemas: {
|
|
1604
|
+
Space: {
|
|
1605
|
+
id: string;
|
|
1606
|
+
name: string;
|
|
1607
|
+
tier: string;
|
|
1608
|
+
/** Format: date-time */
|
|
1609
|
+
createdAt: string;
|
|
1610
|
+
};
|
|
1611
|
+
CubeSshInfo: {
|
|
1612
|
+
host: string | null;
|
|
1613
|
+
port: number;
|
|
1614
|
+
user: string;
|
|
1615
|
+
hostKeys: {
|
|
1616
|
+
type: string;
|
|
1617
|
+
key: string;
|
|
1618
|
+
}[];
|
|
1619
|
+
};
|
|
1380
1620
|
Cube: {
|
|
1381
1621
|
id: string;
|
|
1382
1622
|
name: string;
|
|
@@ -1571,6 +1811,10 @@ type Image = components["schemas"]["Image"];
|
|
|
1571
1811
|
type PricingTier = components["schemas"]["PricingTier"];
|
|
1572
1812
|
/** Pagination envelope returned alongside a Cube list. */
|
|
1573
1813
|
type Pagination = components["schemas"]["Pagination"];
|
|
1814
|
+
/** A Space — the tenancy an API key is scoped to. */
|
|
1815
|
+
type Space = components["schemas"]["Space"];
|
|
1816
|
+
/** A Cube's SSH connection info (host, port, user, and pinned host keys). */
|
|
1817
|
+
type CubeSshInfo = components["schemas"]["CubeSshInfo"];
|
|
1574
1818
|
/** Default API base URL — the single `servers[0].url` from the OpenAPI spec. */
|
|
1575
1819
|
declare const DEFAULT_BASE_URL = "https://krova.cloud/api/v1";
|
|
1576
1820
|
/**
|
|
@@ -1685,7 +1929,23 @@ declare class KrovaClient {
|
|
|
1685
1929
|
sleep: (spaceId: string, cubeId: string) => Promise<unknown>;
|
|
1686
1930
|
/** Wake a sleeping Cube (asynchronous — wake is enqueued). */
|
|
1687
1931
|
wake: (spaceId: string, cubeId: string) => Promise<unknown>;
|
|
1932
|
+
/**
|
|
1933
|
+
* Get a Cube's SSH connection info — host, port, login user, and (when
|
|
1934
|
+
* available) the pinned host public keys for strict host-key verification.
|
|
1935
|
+
*/
|
|
1936
|
+
ssh: (spaceId: string, cubeId: string) => Promise<CubeSshInfo>;
|
|
1688
1937
|
};
|
|
1938
|
+
/**
|
|
1939
|
+
* Resolve the {@link Space} this API key is scoped to — so you don't have to
|
|
1940
|
+
* hardcode a `spaceId`. Handy right after constructing the client:
|
|
1941
|
+
*
|
|
1942
|
+
* @example
|
|
1943
|
+
* ```ts
|
|
1944
|
+
* const space = await krova.getSpace();
|
|
1945
|
+
* const cubes = await krova.cubes.list(space.id);
|
|
1946
|
+
* ```
|
|
1947
|
+
*/
|
|
1948
|
+
getSpace(): Promise<Space>;
|
|
1689
1949
|
readonly catalog: {
|
|
1690
1950
|
/** List regions with available capacity. */
|
|
1691
1951
|
regions: () => Promise<{
|
|
@@ -1773,4 +2033,4 @@ declare class KrovaError extends Error {
|
|
|
1773
2033
|
*/
|
|
1774
2034
|
declare function krovaErrorFrom(response: Response, body: KrovaErrorBody | undefined): KrovaError;
|
|
1775
2035
|
|
|
1776
|
-
export { type AuthScheme, type Cube, DEFAULT_BASE_URL, type Image, KrovaClient, type KrovaClientOptions, KrovaError, type KrovaErrorBody, type Pagination, type PricingTier, type Region, type components, krovaErrorFrom, type paths };
|
|
2036
|
+
export { type AuthScheme, type Cube, type CubeSshInfo, DEFAULT_BASE_URL, type Image, KrovaClient, type KrovaClientOptions, KrovaError, type KrovaErrorBody, type Pagination, type PricingTier, type Region, type Space, type components, krovaErrorFrom, type paths };
|
package/dist/index.js
CHANGED
|
@@ -70,8 +70,18 @@ function authMiddleware(apiKey, scheme) {
|
|
|
70
70
|
};
|
|
71
71
|
}
|
|
72
72
|
function retryMiddleware(maxRetries, doFetch) {
|
|
73
|
+
const pristine = /* @__PURE__ */ new Map();
|
|
73
74
|
return {
|
|
74
|
-
|
|
75
|
+
onRequest({ request, id }) {
|
|
76
|
+
pristine.set(id, request.clone());
|
|
77
|
+
return request;
|
|
78
|
+
},
|
|
79
|
+
onError({ id }) {
|
|
80
|
+
pristine.delete(id);
|
|
81
|
+
},
|
|
82
|
+
async onResponse({ request, response, id }) {
|
|
83
|
+
const original = pristine.get(id) ?? request;
|
|
84
|
+
pristine.delete(id);
|
|
75
85
|
if (maxRetries <= 0 || !RETRYABLE_STATUSES.has(response.status)) {
|
|
76
86
|
return response;
|
|
77
87
|
}
|
|
@@ -80,8 +90,8 @@ function retryMiddleware(maxRetries, doFetch) {
|
|
|
80
90
|
if (!RETRYABLE_STATUSES.has(current.status)) break;
|
|
81
91
|
const retryAfterMs = parseRetryAfterMs(current.headers.get("retry-after"));
|
|
82
92
|
const backoff = Math.min(BASE_BACKOFF_MS * 2 ** (attempt - 1), MAX_BACKOFF_MS);
|
|
83
|
-
await sleep(retryAfterMs ?? backoff);
|
|
84
|
-
current = await doFetch(
|
|
93
|
+
await sleep(Math.min(retryAfterMs ?? backoff, MAX_BACKOFF_MS));
|
|
94
|
+
current = await doFetch(original.clone());
|
|
85
95
|
}
|
|
86
96
|
return current;
|
|
87
97
|
}
|
|
@@ -222,8 +232,39 @@ var KrovaClient = class {
|
|
|
222
232
|
);
|
|
223
233
|
if (error !== void 0 || !response.ok) throw krovaErrorFrom(response, error);
|
|
224
234
|
return data;
|
|
235
|
+
},
|
|
236
|
+
/**
|
|
237
|
+
* Get a Cube's SSH connection info — host, port, login user, and (when
|
|
238
|
+
* available) the pinned host public keys for strict host-key verification.
|
|
239
|
+
*/
|
|
240
|
+
ssh: async (spaceId, cubeId) => {
|
|
241
|
+
const { data, error, response } = await this.raw.GET(
|
|
242
|
+
"/spaces/{spaceId}/cubes/{cubeId}/ssh",
|
|
243
|
+
{ params: { path: { spaceId, cubeId } } }
|
|
244
|
+
);
|
|
245
|
+
if (error !== void 0 || !response.ok) throw krovaErrorFrom(response, error);
|
|
246
|
+
if (data === void 0)
|
|
247
|
+
throw krovaErrorFrom(response, { error: "Cube SSH-info response was empty." });
|
|
248
|
+
return data;
|
|
225
249
|
}
|
|
226
250
|
};
|
|
251
|
+
/**
|
|
252
|
+
* Resolve the {@link Space} this API key is scoped to — so you don't have to
|
|
253
|
+
* hardcode a `spaceId`. Handy right after constructing the client:
|
|
254
|
+
*
|
|
255
|
+
* @example
|
|
256
|
+
* ```ts
|
|
257
|
+
* const space = await krova.getSpace();
|
|
258
|
+
* const cubes = await krova.cubes.list(space.id);
|
|
259
|
+
* ```
|
|
260
|
+
*/
|
|
261
|
+
async getSpace() {
|
|
262
|
+
const { data, error, response } = await this.raw.GET("/space");
|
|
263
|
+
if (error !== void 0 || !response.ok) throw krovaErrorFrom(response, error);
|
|
264
|
+
if (data === void 0)
|
|
265
|
+
throw krovaErrorFrom(response, { error: "Space response was empty." });
|
|
266
|
+
return data;
|
|
267
|
+
}
|
|
227
268
|
// ---------------------------------------------------------------------------
|
|
228
269
|
// Public catalog (no auth required by the API, but the key is harmless)
|
|
229
270
|
// ---------------------------------------------------------------------------
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/error.ts","../src/client.ts"],"names":[],"mappings":";;;;;AAoBO,IAAM,UAAA,GAAN,M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,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.js","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. openapi-fetch\n * clones the request per attempt, so re-fetching here is safe.\n */\nfunction retryMiddleware(maxRetries: number, doFetch: typeof fetch): Middleware {\n return {\n async onResponse({ request, response }) {\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 await sleep(retryAfterMs ?? backoff);\n current = await doFetch(request.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":[],"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,CACd,UACA,IAAA,EACY;AACZ,EAAA,MAAM,OAAA,GACH,OAAO,IAAA,EAAM,KAAA,KAAU,QAAA,IAA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,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,CAAA;AAAA;AAAA,IAGA,QAAQ,YAAY;AAClB,MAAA,MAAM,EAAE,MAAM,KAAA,EAAO,QAAA,KAAa,MAAM,IAAA,CAAK,GAAA,CAAI,GAAA,CAAI,SAAS,CAAA;AAC9D,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,8BAA8B,CAAA;AACxE,MAAA,OAAO,IAAA;AAAA,IACT,CAAA;AAAA;AAAA,IAGA,SAAS,YAAY;AACnB,MAAA,MAAM,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.js","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/** 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 /**\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 // 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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@krovacloud/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Official TypeScript SDK for Krova Cloud — a typed client for provisioning and managing Cubes (Firecracker microVMs) on bare-metal.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -61,11 +61,11 @@
|
|
|
61
61
|
"openapi-fetch": "^0.17.0"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
|
-
"@types/node": "^
|
|
64
|
+
"@types/node": "^26.1.0",
|
|
65
65
|
"openapi-typescript": "^7.13.0",
|
|
66
66
|
"tsup": "^8.5.1",
|
|
67
|
-
"tsx": "^4.
|
|
68
|
-
"typescript": "^
|
|
67
|
+
"tsx": "^4.23.0",
|
|
68
|
+
"typescript": "^6.0.3"
|
|
69
69
|
},
|
|
70
70
|
"scripts": {
|
|
71
71
|
"gen": "openapi-typescript openapi.json -o src/generated/types.ts",
|