@lilbox/client 0.0.2 → 0.0.3

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