@lilbox/client 0.0.2 → 0.0.4
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/README.md +546 -13
- package/dist/index.d.ts +12 -5
- package/dist/index.js +4 -1
- package/dist/openapi.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,29 +1,562 @@
|
|
|
1
1
|
# @lilbox/client
|
|
2
2
|
|
|
3
|
-
A typed HTTP client for the [lilbox](https://lilbox.ai) API.
|
|
4
|
-
TypeScript
|
|
3
|
+
A typed HTTP client for the [lilbox](https://lilbox.ai) API. Every path, parameter, request body and response
|
|
4
|
+
is checked by TypeScript: the types are generated from the OpenAPI document published in
|
|
5
|
+
[`@lilbox/contracts`](https://www.npmjs.com/package/@lilbox/contracts), so the client matches the API version it
|
|
6
|
+
was built for.
|
|
7
|
+
|
|
8
|
+
It's a thin layer over [openapi-fetch](https://openapi-ts.dev/openapi-fetch/) (about 6 kB): no classes, no code
|
|
9
|
+
generation on your side, and the runtime's own `fetch`, so it works in Node.js 18+, browsers, Bun, Deno and edge
|
|
10
|
+
runtimes.
|
|
11
|
+
|
|
12
|
+
- [Install](#install)
|
|
13
|
+
- [Quick start](#quick-start)
|
|
14
|
+
- [Authentication](#authentication)
|
|
15
|
+
- [Options](#options)
|
|
16
|
+
- [Making calls](#making-calls)
|
|
17
|
+
- [Errors](#errors)
|
|
18
|
+
- [Retries and idempotency](#retries-and-idempotency)
|
|
19
|
+
- [Pagination](#pagination)
|
|
20
|
+
- [Recipes](#recipes): create an app, deploy files, deploy a tarball, wait for a deployment, config and secrets,
|
|
21
|
+
roll back, status and logs, usage
|
|
22
|
+
- [Middleware](#middleware)
|
|
23
|
+
- [Types](#types)
|
|
24
|
+
- [Endpoint reference](#endpoint-reference)
|
|
25
|
+
- [Versioning](#versioning)
|
|
26
|
+
|
|
27
|
+
## Install
|
|
5
28
|
|
|
6
29
|
```
|
|
7
30
|
npm install @lilbox/client
|
|
8
31
|
```
|
|
9
32
|
|
|
33
|
+
ESM only. TypeScript 5.0+ is recommended (the types are the point); plain JavaScript works too.
|
|
34
|
+
|
|
35
|
+
## Quick start
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { createLilboxClient } from "@lilbox/client";
|
|
39
|
+
|
|
40
|
+
const lilbox = createLilboxClient({ token: process.env.LILBOX_TOKEN });
|
|
41
|
+
|
|
42
|
+
const { data, error } = await lilbox.GET("/v1/apps");
|
|
43
|
+
if (error) throw new Error(`${error.error.code}: ${error.error.message}`);
|
|
44
|
+
|
|
45
|
+
for (const app of data.apps) console.log(app.name, app.url);
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Authentication
|
|
49
|
+
|
|
50
|
+
The API accepts three kinds of credentials:
|
|
51
|
+
|
|
52
|
+
| Credential | Looks like | Where it comes from | Use it for |
|
|
53
|
+
|---|---|---|---|
|
|
54
|
+
| API key | `lbx_…` | Created by a person in the dashboard, with chosen scopes and an optional expiry | CI, scripts, servers |
|
|
55
|
+
| OAuth access token | opaque | The OAuth flow an MCP client or the lilbox CLI runs when it connects to an account | Agents and the CLI |
|
|
56
|
+
| Dashboard token | a JWT | Signing in at lilbox.ai; lasts 15 minutes and is refreshed by the dashboard | The lilbox dashboard only |
|
|
57
|
+
|
|
58
|
+
All three are sent as a bearer token:
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
const lilbox = createLilboxClient({ token: "lbx_..." });
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
If the token can change (an OAuth token you refresh), pass a function. It's called before every request:
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
const lilbox = createLilboxClient({ token: async () => tokenStore.currentAccessToken() });
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
The lilbox dashboard passes a function that returns the signed-in user's current access token, refreshing it
|
|
71
|
+
when it's about to expire. lilbox uses no cookies.
|
|
72
|
+
|
|
73
|
+
**Scopes.** Each credential carries scopes, and most operations need one (see the
|
|
74
|
+
[endpoint reference](#endpoint-reference)). A call without the right scope fails with `forbidden_scope`, and
|
|
75
|
+
`error.details.required_scopes` lists what's missing.
|
|
76
|
+
|
|
77
|
+
| Scope | Allows |
|
|
78
|
+
|---|---|
|
|
79
|
+
| `apps:read` | List and read apps, status, logs, deployments, config (never secret values), activity |
|
|
80
|
+
| `apps:write` | Create and delete apps; change env vars and secrets |
|
|
81
|
+
| `deploy` | Check, create, cancel and roll back deployments |
|
|
82
|
+
| `billing:read` | Subscription, usage, billing periods, referral; request an upgrade (a person completes it) |
|
|
83
|
+
|
|
84
|
+
Operations marked "dashboard only" (managing API keys and connected agents, the billing portal) accept only the
|
|
85
|
+
dashboard token, never an API key or an agent's token: a credential can never create credentials or widen its
|
|
86
|
+
own access.
|
|
87
|
+
|
|
88
|
+
`GET /v1/whoami` returns the signed-in user and the current credential's kind, scopes and expiry. Call it first
|
|
89
|
+
to check a token.
|
|
90
|
+
|
|
91
|
+
## Options
|
|
92
|
+
|
|
93
|
+
```text
|
|
94
|
+
createLilboxClient(options?: LilboxClientOptions): LilboxClient
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
| Option | Type | Default | |
|
|
98
|
+
|---|---|---|---|
|
|
99
|
+
| `baseUrl` | `string` | `"https://api.lilbox.ai"` | Change it for a local API, e.g. `http://localhost:3000` |
|
|
100
|
+
| `token` | `string \| () => string \| undefined \| Promise<string \| undefined>` | none | Sent as `Authorization: Bearer <token>`. A function is called per request; returning `undefined` sends no header |
|
|
101
|
+
| `credentials` | `RequestCredentials` | fetch's default | fetch's credentials mode. lilbox uses no cookies, so rarely needed |
|
|
102
|
+
| `userAgent` | `string` | none | Sent as `X-Lilbox-Client`, e.g. `"my-ci/1.4.0"`. Helps support find your requests |
|
|
103
|
+
| `headers` | `Record<string, string>` | none | Extra headers on every request |
|
|
104
|
+
| `fetch` | `typeof fetch` | `globalThis.fetch` | A custom fetch, for tests, proxies or older runtimes |
|
|
105
|
+
|
|
106
|
+
`DEFAULT_BASE_URL` is exported too.
|
|
107
|
+
|
|
108
|
+
## Making calls
|
|
109
|
+
|
|
110
|
+
The client has one method per HTTP verb: `GET`, `POST`, `PUT`, `PATCH`, `DELETE`. The first argument is the path
|
|
111
|
+
exactly as written in the [endpoint reference](#endpoint-reference), with its `{placeholders}`; the second holds
|
|
112
|
+
the inputs:
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
const { data, error, response } = await lilbox.GET("/v1/apps/{app_id}/logs", {
|
|
116
|
+
params: {
|
|
117
|
+
path: { app_id: "app_01jabcdefghjkmnpqrst" }, // fills {app_id}
|
|
118
|
+
query: { grep: "timeout", limit: 100 }, // ?grep=timeout&limit=100
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
and, for operations with a request body:
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
await lilbox.POST("/v1/apps", { body: { name: "shop" } });
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
TypeScript knows which `path`, `query`, `header` and `body` fields each operation takes, which are required, and
|
|
130
|
+
what `data` contains. A wrong path or a missing field is a compile error.
|
|
131
|
+
|
|
132
|
+
Every call resolves to:
|
|
133
|
+
|
|
134
|
+
| Field | When | |
|
|
135
|
+
|---|---|---|
|
|
136
|
+
| `data` | 2xx | The parsed response body, typed |
|
|
137
|
+
| `error` | 4xx or 5xx | The parsed [error body](#errors), typed as `ErrorResponse` |
|
|
138
|
+
| `response` | always | The raw `Response` (status, headers) |
|
|
139
|
+
|
|
140
|
+
Exactly one of `data` and `error` is set. Calls **don't throw** on API errors; they do reject on network
|
|
141
|
+
failures, aborts and unparseable responses. Pass `signal` to cancel a call:
|
|
142
|
+
|
|
143
|
+
```ts
|
|
144
|
+
await lilbox.GET("/v1/apps", { signal: AbortSignal.timeout(10_000) });
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## Errors
|
|
148
|
+
|
|
149
|
+
Every error response has the same body:
|
|
150
|
+
|
|
151
|
+
```text
|
|
152
|
+
{
|
|
153
|
+
error: {
|
|
154
|
+
code: "quota_exceeded", // stable: act on this, not on the HTTP status
|
|
155
|
+
message: "…", // for a person
|
|
156
|
+
retryable: false, // true if the same call may succeed later unchanged
|
|
157
|
+
suggestion?: "…", // what to do next
|
|
158
|
+
docs_url?: "https://…",
|
|
159
|
+
request_id?: "…", // quote it to support
|
|
160
|
+
deployment_id?: "dep_…", // for deployment failures
|
|
161
|
+
log_excerpt?: ["…"], // the build or runtime lines that explain a failure
|
|
162
|
+
details?: { … }, // code-specific fields, listed below
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
`isApiError(value, code?)` narrows an unknown value to `ErrorResponse`, optionally checking the code:
|
|
168
|
+
|
|
169
|
+
```ts
|
|
170
|
+
import { isApiError } from "@lilbox/client";
|
|
171
|
+
|
|
172
|
+
const { data, error } = await lilbox.POST("/v1/apps", { body: { name: "shop" } });
|
|
173
|
+
if (isApiError(error, "conflict")) {
|
|
174
|
+
console.log("Not created:", error.error.details?.reason); // name_taken, name_reserved, name_not_allowed, busy
|
|
175
|
+
} else if (error) {
|
|
176
|
+
throw new Error(error.error.message);
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Error codes. New codes may be added; existing ones never change meaning.
|
|
181
|
+
|
|
182
|
+
| Code | Meaning, and what's in `details` |
|
|
183
|
+
|---|---|
|
|
184
|
+
| `unauthenticated` | No valid credentials |
|
|
185
|
+
| `forbidden_scope` | The credential lacks a scope. `required_scopes` |
|
|
186
|
+
| `approval_required` | A person must approve. `approval_url` |
|
|
187
|
+
| `payment_required` | The account must subscribe (trial ended, or the feature needs a paid plan). `checkout_url` when available |
|
|
188
|
+
| `quota_exceeded` | A plan limit is used up this billing period. `meter`, `used`, `limit`, `resets_at` |
|
|
189
|
+
| `rate_limited` | Too many requests from this credential or IP. `retry_after_seconds` |
|
|
190
|
+
| `suspended` | lilbox suspended the app or account. `reason` |
|
|
191
|
+
| `invalid_request` | The input failed validation. `issues`, each with a path |
|
|
192
|
+
| `invalid_manifest` | `app.yaml` is invalid. `issues` |
|
|
193
|
+
| `not_found` | No such resource, or the credential can't see it |
|
|
194
|
+
| `conflict` | Conflicts with the current state. `reason`: `name_taken`, `name_reserved`, `name_not_allowed`, `busy` |
|
|
195
|
+
| `not_available` | Not available yet. `waitlist_url` when there is one |
|
|
196
|
+
| `plan_unavailable` | That plan can't be bought yet. `waitlist_url` |
|
|
197
|
+
| `source_too_large` | The upload or inline files are over the limit. `largest_paths` |
|
|
198
|
+
| `build_failed` | The image build failed. See `log_excerpt`, then the deployment logs |
|
|
199
|
+
| `image_too_large` | The built image is over the runtime's size limit |
|
|
200
|
+
| `migration_failed` | The release's migrate command failed |
|
|
201
|
+
| `healthcheck_failed` | The app started but didn't pass its health check |
|
|
202
|
+
| `app_crashed_on_start` | The app exited before its health check passed |
|
|
203
|
+
| `deploy_timeout` | The deploy didn't finish in time |
|
|
204
|
+
| `capability_requires_plan` | The app needs something the plan's runtime can't do. `issues`, each with both fixes |
|
|
205
|
+
| `capability_unconfirmed` | Unsure whether the app needs a capability: declare it in `app.yaml` or pass `ack` |
|
|
206
|
+
| `internal` | Something failed on lilbox's side. Retry; quote `request_id` if it persists |
|
|
207
|
+
|
|
208
|
+
The authoritative list is `ERROR_CODES` in `@lilbox/contracts`. Deployment failures (`build_failed` and the rows
|
|
209
|
+
after it) usually arrive as `deployment.error` on a deployment whose status is `failed`, rather than as an HTTP
|
|
210
|
+
error.
|
|
211
|
+
|
|
212
|
+
## Retries and idempotency
|
|
213
|
+
|
|
214
|
+
Retry only when `error.error.retryable` is `true`, or on network failures. For `rate_limited`, wait
|
|
215
|
+
`details.retry_after_seconds` first.
|
|
216
|
+
|
|
217
|
+
Every operation that changes something accepts an `Idempotency-Key` header. Send the same key when you retry and
|
|
218
|
+
the API returns the first result instead of repeating the change (no second app, no second deployment):
|
|
219
|
+
|
|
220
|
+
```ts
|
|
221
|
+
const key = crypto.randomUUID(); // one per logical action, reused across its retries
|
|
222
|
+
|
|
223
|
+
await lilbox.POST("/v1/apps/{app_id}/deployments", {
|
|
224
|
+
params: { path: { app_id }, header: { "Idempotency-Key": key } },
|
|
225
|
+
body: { source: { type: "files", files } },
|
|
226
|
+
});
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
Most changing operations also take `dry_run: true`, which validates the call and returns what would happen
|
|
230
|
+
without doing it.
|
|
231
|
+
|
|
232
|
+
## Pagination
|
|
233
|
+
|
|
234
|
+
List operations take `limit` (1–100, default 50) and `cursor`, and return `next_cursor` until the last page:
|
|
235
|
+
|
|
236
|
+
```ts
|
|
237
|
+
async function allApps() {
|
|
238
|
+
const apps = [];
|
|
239
|
+
let cursor: string | undefined;
|
|
240
|
+
do {
|
|
241
|
+
const { data, error } = await lilbox.GET("/v1/apps", { params: { query: { cursor, limit: 100 } } });
|
|
242
|
+
if (error) throw new Error(error.error.message);
|
|
243
|
+
apps.push(...data.apps);
|
|
244
|
+
cursor = data.next_cursor;
|
|
245
|
+
} while (cursor);
|
|
246
|
+
return apps;
|
|
247
|
+
}
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
Lists are newest first, except logs, which are oldest first.
|
|
251
|
+
|
|
252
|
+
## Recipes
|
|
253
|
+
|
|
254
|
+
The snippets assume `const lilbox = createLilboxClient({ token })` and skip error handling where it isn't the
|
|
255
|
+
point.
|
|
256
|
+
|
|
257
|
+
### Create an app
|
|
258
|
+
|
|
259
|
+
```ts
|
|
260
|
+
const { data } = await lilbox.POST("/v1/apps", { body: { name: "shop" } });
|
|
261
|
+
const app = data!.app; // app.url === "https://shop.lilbox.app"; nothing runs until the first deployment
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
Names are 3–32 characters of lowercase letters, digits and single hyphens. The name is the URL.
|
|
265
|
+
|
|
266
|
+
### Deploy files inline
|
|
267
|
+
|
|
268
|
+
For small apps, or agents without a shell: send the files in the call.
|
|
269
|
+
|
|
270
|
+
```ts
|
|
271
|
+
const { data } = await lilbox.POST("/v1/apps/{app_id}/deployments", {
|
|
272
|
+
params: { path: { app_id } },
|
|
273
|
+
body: {
|
|
274
|
+
source: {
|
|
275
|
+
type: "files",
|
|
276
|
+
files: [
|
|
277
|
+
{ path: "package.json", content: JSON.stringify({ name: "shop", scripts: { start: "node index.js" } }) },
|
|
278
|
+
{ path: "index.js", content: "require('http').createServer((_, r) => r.end('hi')).listen(process.env.PORT)" },
|
|
279
|
+
{ path: "logo.png", content: pngBase64, encoding: "base64" },
|
|
280
|
+
],
|
|
281
|
+
},
|
|
282
|
+
},
|
|
283
|
+
});
|
|
284
|
+
const deployment = data!.deployment; // status "queued"
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
To change a few files of an earlier deployment, send only those, plus the paths to remove:
|
|
288
|
+
|
|
289
|
+
```ts
|
|
290
|
+
await lilbox.POST("/v1/apps/{app_id}/deployments", {
|
|
291
|
+
params: { path: { app_id } },
|
|
292
|
+
body: {
|
|
293
|
+
source: {
|
|
294
|
+
type: "files",
|
|
295
|
+
base_deployment_id: deployment.id,
|
|
296
|
+
files: [{ path: "index.js", content: newCode }],
|
|
297
|
+
delete: ["old.js"],
|
|
298
|
+
},
|
|
299
|
+
},
|
|
300
|
+
});
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
Inline source is limited to 2,000 files, and 2 MB on the trial or 4 MB on paid plans.
|
|
304
|
+
|
|
305
|
+
### Deploy a tarball
|
|
306
|
+
|
|
307
|
+
For anything bigger (this is what the lilbox CLI does): create the deployment with the archive's size and
|
|
308
|
+
SHA-256, then `PUT` the `.tar.gz` to the returned URL. The deployment starts when the upload completes.
|
|
309
|
+
|
|
10
310
|
```ts
|
|
11
|
-
import {
|
|
311
|
+
import { createHash } from "node:crypto";
|
|
312
|
+
import { readFile } from "node:fs/promises";
|
|
12
313
|
|
|
13
|
-
const
|
|
314
|
+
const archive = await readFile("app.tar.gz");
|
|
315
|
+
const sha256 = createHash("sha256").update(archive).digest("hex");
|
|
14
316
|
|
|
15
|
-
const { data
|
|
16
|
-
params: { path: { app_id
|
|
317
|
+
const { data } = await lilbox.POST("/v1/apps/{app_id}/deployments", {
|
|
318
|
+
params: { path: { app_id } },
|
|
319
|
+
body: { source: { type: "upload", size_bytes: archive.byteLength, sha256 } },
|
|
17
320
|
});
|
|
18
|
-
|
|
19
|
-
|
|
321
|
+
const { deployment } = data!; // status "awaiting_source"
|
|
322
|
+
|
|
323
|
+
const upload = deployment.upload!; // PUT before upload.expires_at
|
|
324
|
+
await fetch(upload.url, { method: upload.method, headers: upload.headers, body: archive });
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
Upload limits: 50 MB on the trial, 100 MB on Starter, 500 MB on Pro. The upload URL is already signed: don't
|
|
328
|
+
send your lilbox token to it.
|
|
329
|
+
|
|
330
|
+
### Wait for a deployment
|
|
331
|
+
|
|
332
|
+
`GET /v1/deployments/{deployment_id}` with `wait_seconds` holds the request open (up to 25 s) until the status
|
|
333
|
+
changes, so you can wait without sleeping:
|
|
334
|
+
|
|
335
|
+
```ts
|
|
336
|
+
async function waitForDeployment(deployment_id: string) {
|
|
337
|
+
for (;;) {
|
|
338
|
+
const { data, error } = await lilbox.GET("/v1/deployments/{deployment_id}", {
|
|
339
|
+
params: { path: { deployment_id }, query: { wait_seconds: 25 } },
|
|
340
|
+
});
|
|
341
|
+
if (error) throw new Error(error.error.message);
|
|
342
|
+
const d = data.deployment;
|
|
343
|
+
if (d.status === "live") return d; // d.url is the app's URL
|
|
344
|
+
if (d.status === "failed") {
|
|
345
|
+
throw new Error(`${d.error?.code}: ${d.error?.message}\n${d.error?.log_excerpt?.join("\n") ?? ""}`);
|
|
346
|
+
}
|
|
347
|
+
if (d.status === "cancelled" || d.status === "superseded") return d;
|
|
348
|
+
}
|
|
20
349
|
}
|
|
21
350
|
```
|
|
22
351
|
|
|
23
|
-
|
|
24
|
-
|
|
352
|
+
A deployment moves through `awaiting_source` (uploads only) → `queued` → `running` → `live`, or ends `failed` or
|
|
353
|
+
`cancelled`. When a newer deployment goes live, the previous one becomes `superseded`. `deployment.steps` shows
|
|
354
|
+
progress through `receive_source`, `check`, `build`, `smoke_test`, `release`, `route` and `health_check`.
|
|
355
|
+
|
|
356
|
+
For the full build output, `GET /v1/deployments/{deployment_id}/logs` (filter with `step` and `grep`).
|
|
357
|
+
|
|
358
|
+
To find out before deploying whether a source will deploy on the account's plan, `POST /v1/apps/{app_id}/check`
|
|
359
|
+
takes the same `files` (or `github`) source and returns `deployable`, the `issues`, and the options to fix them.
|
|
360
|
+
|
|
361
|
+
### Config and secrets
|
|
362
|
+
|
|
363
|
+
Env vars and secrets make up the app's config. Changing them deploys the change (same image, new config); the
|
|
364
|
+
response includes that deployment, if one was created.
|
|
365
|
+
|
|
366
|
+
```ts
|
|
367
|
+
// Plain env vars, merged with the existing ones
|
|
368
|
+
await lilbox.PATCH("/v1/apps/{app_id}/config/env", {
|
|
369
|
+
params: { path: { app_id } },
|
|
370
|
+
body: { vars: { NODE_ENV: "production", LOG_LEVEL: "info" } },
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
// A secret: stored encrypted, exposed to the app as an env var, never returned
|
|
374
|
+
await lilbox.PUT("/v1/apps/{app_id}/config/secrets/{name}", {
|
|
375
|
+
params: { path: { app_id, name: "STRIPE_KEY" } },
|
|
376
|
+
body: { value: stripeKey },
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
// A random secret generated by lilbox (session keys, signing keys)
|
|
380
|
+
await lilbox.POST("/v1/apps/{app_id}/config/secrets/{name}/generate", {
|
|
381
|
+
params: { path: { app_id, name: "SESSION_SECRET" } },
|
|
382
|
+
body: { length: 48, charset: "base64url" },
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
// Remove env vars or secrets
|
|
386
|
+
await lilbox.POST("/v1/apps/{app_id}/config/unset", {
|
|
387
|
+
params: { path: { app_id } },
|
|
388
|
+
body: { names: ["LOG_LEVEL"] },
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
// Read the config: env values, secret names only
|
|
392
|
+
const { data: config } = await lilbox.GET("/v1/apps/{app_id}/config", { params: { path: { app_id } } });
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
Names are upper-case env var names; names starting with `LILBOX_` or `AWS_` are reserved.
|
|
396
|
+
|
|
397
|
+
### Roll back
|
|
398
|
+
|
|
399
|
+
```ts
|
|
400
|
+
const { data } = await lilbox.GET("/v1/apps/{app_id}/deployments", {
|
|
401
|
+
params: { path: { app_id }, query: { status: "superseded", limit: 1 } },
|
|
402
|
+
});
|
|
403
|
+
const previous = data!.deployments[0]!;
|
|
404
|
+
|
|
405
|
+
await lilbox.POST("/v1/apps/{app_id}/rollback", {
|
|
406
|
+
params: { path: { app_id } },
|
|
407
|
+
body: { to_deployment_id: previous.id },
|
|
408
|
+
});
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
A rollback is a new deployment that reuses the earlier one's image and config, so it needs no build.
|
|
412
|
+
|
|
413
|
+
### Status and logs
|
|
414
|
+
|
|
415
|
+
```ts
|
|
416
|
+
const { data: status } = await lilbox.GET("/v1/apps/{app_id}/status", { params: { path: { app_id } } });
|
|
417
|
+
// status.state: not_deployed | running | stopped | suspended (state_reason says why)
|
|
418
|
+
// status.health.state: healthy | degraded | failing | asleep | unknown, from real traffic
|
|
419
|
+
// status.live_deployment, status.cron, status.conditions
|
|
420
|
+
|
|
421
|
+
const { data: logs } = await lilbox.GET("/v1/apps/{app_id}/logs", {
|
|
422
|
+
params: { path: { app_id }, query: { since: new Date(Date.now() - 3_600_000).toISOString(), grep: "error" } },
|
|
423
|
+
});
|
|
424
|
+
for (const line of logs!.lines) console.log(line.ts, line.stream, line.message);
|
|
425
|
+
```
|
|
426
|
+
|
|
427
|
+
Health is `asleep` when the app has had no recent requests: apps scale to zero, and lilbox never wakes them up
|
|
428
|
+
just to probe them.
|
|
429
|
+
|
|
430
|
+
### Usage and plan
|
|
431
|
+
|
|
432
|
+
```ts
|
|
433
|
+
const { data: sub } = await lilbox.GET("/v1/subscription"); // plan, status, trial end, bonuses
|
|
434
|
+
const { data: usage } = await lilbox.GET("/v1/usage", { params: { query: { by_app: true } } });
|
|
435
|
+
for (const m of usage!.period?.usage ?? []) console.log(m.meter, `${m.used}/${m.limit} ${m.unit}`, m.state);
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
At a limit, builds are refused and apps stop until the period resets or the plan changes; nothing is deleted.
|
|
439
|
+
`POST /v1/subscription/upgrade` returns a Stripe Checkout URL for a person to complete.
|
|
440
|
+
|
|
441
|
+
## Middleware
|
|
442
|
+
|
|
443
|
+
The client is an openapi-fetch client, so openapi-fetch middleware works with it. For example, logging every
|
|
444
|
+
call:
|
|
445
|
+
|
|
446
|
+
```ts
|
|
447
|
+
lilbox.use({
|
|
448
|
+
onResponse({ request, response }) {
|
|
449
|
+
console.log(request.method, new URL(request.url).pathname, response.status);
|
|
450
|
+
},
|
|
451
|
+
});
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
See [openapi-fetch's middleware docs](https://openapi-ts.dev/openapi-fetch/middleware-auth) for `use()` and
|
|
455
|
+
`eject()`.
|
|
456
|
+
|
|
457
|
+
## Types
|
|
458
|
+
|
|
459
|
+
Every schema in the API is available as a type:
|
|
460
|
+
|
|
461
|
+
```ts
|
|
462
|
+
import type { Schemas } from "@lilbox/client";
|
|
463
|
+
|
|
464
|
+
type App = Schemas["App"];
|
|
465
|
+
type Deployment = Schemas["Deployment"];
|
|
466
|
+
type Status = Schemas["AppStatusReport"];
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
| Export | |
|
|
470
|
+
|---|---|
|
|
471
|
+
| `createLilboxClient(options)` | Creates a client |
|
|
472
|
+
| `isApiError(value, code?)` | Narrows a value to `ErrorResponse`, optionally with a given code |
|
|
473
|
+
| `DEFAULT_BASE_URL` | `"https://api.lilbox.ai"` |
|
|
474
|
+
| `LilboxClient`, `LilboxClientOptions` | The client and its options |
|
|
475
|
+
| `Schemas` | Every named schema: `App`, `Deployment`, `AppStatusReport`, `BillingPeriod`, … |
|
|
476
|
+
| `ApiError`, `ErrorResponse`, `ErrorCode` | The error, its wrapper body, and the union of codes |
|
|
477
|
+
| `paths`, `operations`, `components` | The raw generated OpenAPI types |
|
|
478
|
+
|
|
479
|
+
To validate data at runtime (forms, `app.yaml`, inputs), use the zod schemas in `@lilbox/contracts`.
|
|
480
|
+
|
|
481
|
+
## Endpoint reference
|
|
482
|
+
|
|
483
|
+
"Scope" is what an API key or agent token needs. The dashboard token can call everything.
|
|
484
|
+
|
|
485
|
+
**Account**
|
|
486
|
+
|
|
487
|
+
| Method | Path | Operation | Scope |
|
|
488
|
+
|---|---|---|---|
|
|
489
|
+
| `GET` | `/v1/whoami` | `whoami`: the user and this credential's scopes | any |
|
|
490
|
+
| `GET` | `/v1/account/agents` | `list_connected_agents` | dashboard only |
|
|
491
|
+
| `DELETE` | `/v1/account/agents/{agent_id}` | `revoke_connected_agent` | dashboard only |
|
|
492
|
+
| `GET` | `/v1/account/api-keys` | `list_api_keys` | dashboard only |
|
|
493
|
+
| `POST` | `/v1/account/api-keys` | `create_api_key` | dashboard only |
|
|
494
|
+
| `DELETE` | `/v1/account/api-keys/{key_id}` | `revoke_api_key` | dashboard only |
|
|
495
|
+
|
|
496
|
+
**Apps and config**
|
|
497
|
+
|
|
498
|
+
| Method | Path | Operation | Scope |
|
|
499
|
+
|---|---|---|---|
|
|
500
|
+
| `GET` | `/v1/apps` | `list_apps` | `apps:read` |
|
|
501
|
+
| `POST` | `/v1/apps` | `create_app` | `apps:write` |
|
|
502
|
+
| `GET` | `/v1/apps/{app_id}` | `get_app` | `apps:read` |
|
|
503
|
+
| `DELETE` | `/v1/apps/{app_id}` | `delete_app` (query `confirm_name` must equal the app's name) | `apps:write` |
|
|
504
|
+
| `GET` | `/v1/apps/{app_id}/config` | `list_config` | `apps:read` |
|
|
505
|
+
| `PATCH` | `/v1/apps/{app_id}/config/env` | `set_env` | `apps:write` |
|
|
506
|
+
| `POST` | `/v1/apps/{app_id}/config/unset` | `unset_env` | `apps:write` |
|
|
507
|
+
| `PUT` | `/v1/apps/{app_id}/config/secrets/{name}` | `set_secret` | `apps:write` |
|
|
508
|
+
| `POST` | `/v1/apps/{app_id}/config/secrets/{name}/generate` | `generate_secret` | `apps:write` |
|
|
509
|
+
|
|
510
|
+
**Deployments**
|
|
511
|
+
|
|
512
|
+
| Method | Path | Operation | Scope |
|
|
513
|
+
|---|---|---|---|
|
|
514
|
+
| `POST` | `/v1/apps/{app_id}/check` | `check`: would this source deploy? | `deploy` |
|
|
515
|
+
| `POST` | `/v1/apps/{app_id}/deployments` | `create_deployment` | `deploy` |
|
|
516
|
+
| `GET` | `/v1/apps/{app_id}/deployments` | `list_deployments` | `apps:read` |
|
|
517
|
+
| `GET` | `/v1/deployments/{deployment_id}` | `get_deployment` (`wait_seconds` to long-poll) | `apps:read` |
|
|
518
|
+
| `POST` | `/v1/deployments/{deployment_id}/cancel` | `cancel_deployment` | `deploy` |
|
|
519
|
+
| `GET` | `/v1/deployments/{deployment_id}/logs` | `get_deployment_logs`: build and step output | `apps:read` |
|
|
520
|
+
| `POST` | `/v1/apps/{app_id}/rollback` | `rollback` | `deploy` |
|
|
521
|
+
|
|
522
|
+
**Runtime**
|
|
523
|
+
|
|
524
|
+
| Method | Path | Operation | Scope |
|
|
525
|
+
|---|---|---|---|
|
|
526
|
+
| `GET` | `/v1/apps/{app_id}/status` | `get_status`: run state, health, live deployment, cron | `apps:read` |
|
|
527
|
+
| `GET` | `/v1/apps/{app_id}/logs` | `get_logs`: the app's own output | `apps:read` |
|
|
528
|
+
|
|
529
|
+
**Activity**
|
|
530
|
+
|
|
531
|
+
| Method | Path | Operation | Scope |
|
|
532
|
+
|---|---|---|---|
|
|
533
|
+
| `GET` | `/v1/activity` | `list_activity`: every change, who made it and through which credential | `apps:read` |
|
|
534
|
+
|
|
535
|
+
**Billing**
|
|
536
|
+
|
|
537
|
+
| Method | Path | Operation | Scope |
|
|
538
|
+
|---|---|---|---|
|
|
539
|
+
| `GET` | `/v1/plans` | `get_plans` | any |
|
|
540
|
+
| `GET` | `/v1/subscription` | `get_subscription` | `billing:read` |
|
|
541
|
+
| `GET` | `/v1/usage` | `get_usage`: the open billing period | `billing:read` |
|
|
542
|
+
| `GET` | `/v1/billing-periods` | `list_billing_periods`: past periods, usage and invoices | `billing:read` |
|
|
543
|
+
| `POST` | `/v1/subscription/upgrade` | `request_upgrade`: a checkout URL for a person | `billing:read` |
|
|
544
|
+
| `GET` | `/v1/referral` | `get_referral` | `billing:read` |
|
|
545
|
+
| `POST` | `/v1/subscription/portal` | `open_billing_portal` | dashboard only |
|
|
546
|
+
|
|
547
|
+
Each operation's description, inputs and outputs are in the types: hover the path in your editor. The same
|
|
548
|
+
operations are the lilbox MCP server's tools, under the names above (except the dashboard-only ones).
|
|
549
|
+
|
|
550
|
+
## Versioning
|
|
551
|
+
|
|
552
|
+
The client follows semver from 1.0.0. Until then (0.x), a release may change types, so pin an exact version.
|
|
553
|
+
The API itself changes only in compatible ways within `/v1` (new operations, optional inputs, new output fields,
|
|
554
|
+
new error codes), so an older client keeps working against the live API; a newer one adds what's new.
|
|
555
|
+
|
|
556
|
+
## License
|
|
25
557
|
|
|
26
|
-
|
|
558
|
+
MIT
|
|
27
559
|
|
|
28
|
-
<!-- For lilbox contributors:
|
|
29
|
-
libs/contracts/dist/openapi.json. Don't edit it; a test fails if it is out of date.
|
|
560
|
+
<!-- For lilbox contributors: src/openapi.ts is generated by `npm run client:build` (repo root) from
|
|
561
|
+
libs/contracts/dist/openapi.json. Don't edit it; a test fails if it is out of date. Another test checks that
|
|
562
|
+
this README lists every operation in openapi.json and that its code examples type-check. -->
|
package/dist/index.d.ts
CHANGED
|
@@ -10,11 +10,11 @@ export interface LilboxClientOptions {
|
|
|
10
10
|
/** Default https://api.lilbox.ai. */
|
|
11
11
|
baseUrl?: string;
|
|
12
12
|
/**
|
|
13
|
-
* An API key (lbx_…)
|
|
14
|
-
* request, so a refreshed token is picked up.
|
|
13
|
+
* An API key (lbx_…), an OAuth access token, or the dashboard's access JWT, sent as a bearer token. A function
|
|
14
|
+
* is called before every request, so a refreshed token is picked up.
|
|
15
15
|
*/
|
|
16
16
|
token?: string | (() => string | undefined | Promise<string | undefined>);
|
|
17
|
-
/**
|
|
17
|
+
/** fetch's credentials mode. lilbox uses no cookies, so this is rarely needed. */
|
|
18
18
|
credentials?: RequestCredentials;
|
|
19
19
|
/** e.g. "lilbox-cli/1.2.0". Sent as X-Lilbox-Client (browsers don't allow setting User-Agent). */
|
|
20
20
|
userAgent?: string;
|
|
@@ -24,5 +24,12 @@ export interface LilboxClientOptions {
|
|
|
24
24
|
}
|
|
25
25
|
export type LilboxClient = Client<paths>;
|
|
26
26
|
export declare function createLilboxClient(options?: LilboxClientOptions): LilboxClient;
|
|
27
|
-
/**
|
|
28
|
-
|
|
27
|
+
/**
|
|
28
|
+
* True when a value is a lilbox API error body, optionally with a given code: isApiError(error, "quota_exceeded").
|
|
29
|
+
* With a code it narrows to that code only, so an `else` branch still sees the other errors.
|
|
30
|
+
*/
|
|
31
|
+
export declare function isApiError<C extends ErrorCode = ErrorCode>(error: unknown, code?: C): error is ErrorResponse & {
|
|
32
|
+
error: {
|
|
33
|
+
code: C;
|
|
34
|
+
};
|
|
35
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -31,7 +31,10 @@ export function createLilboxClient(options = {}) {
|
|
|
31
31
|
}
|
|
32
32
|
return client;
|
|
33
33
|
}
|
|
34
|
-
/**
|
|
34
|
+
/**
|
|
35
|
+
* True when a value is a lilbox API error body, optionally with a given code: isApiError(error, "quota_exceeded").
|
|
36
|
+
* With a code it narrows to that code only, so an `else` branch still sees the other errors.
|
|
37
|
+
*/
|
|
35
38
|
export function isApiError(error, code) {
|
|
36
39
|
if (typeof error !== "object" || error === null || !("error" in error))
|
|
37
40
|
return false;
|
package/dist/openapi.d.ts
CHANGED
|
@@ -587,7 +587,7 @@ export interface components {
|
|
|
587
587
|
user: components["schemas"]["User"];
|
|
588
588
|
credential: {
|
|
589
589
|
/** @enum {string} */
|
|
590
|
-
kind: "
|
|
590
|
+
kind: "dashboard" | "agent" | "api_key";
|
|
591
591
|
scopes: ("apps:read" | "apps:write" | "deploy" | "billing:read")[];
|
|
592
592
|
expires_at: string | null;
|
|
593
593
|
};
|