@lilbox/client 0.0.0-stage → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 lilbox
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,29 @@
1
- # Temporary Holding Version
1
+ # @lilbox/client
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
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`.
5
+
6
+ ```
7
+ npm install @lilbox/client
8
+ ```
9
+
10
+ ```ts
11
+ import { createLilboxClient, isApiError } from "@lilbox/client";
12
+
13
+ const lilbox = createLilboxClient({ token: process.env.LILBOX_TOKEN }); // an lbx_ API key or an OAuth token
14
+
15
+ const { data, error } = await lilbox.GET("/v1/apps/{app_id}/status", {
16
+ params: { path: { app_id: "app_…" } },
17
+ });
18
+ if (isApiError(error, "not_found")) {
19
+ // …
20
+ }
21
+ ```
22
+
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.
25
+
26
+ Built on [openapi-fetch](https://openapi-ts.dev/openapi-fetch/). MIT licensed.
27
+
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. -->
@@ -0,0 +1,28 @@
1
+ import { type Client } from "openapi-fetch";
2
+ import type { components, operations, paths } from "./openapi.js";
3
+ export type { components, operations, paths };
4
+ export type Schemas = components["schemas"];
5
+ export type ApiError = Schemas["ApiError"];
6
+ export type ErrorResponse = Schemas["ErrorResponse"];
7
+ export type ErrorCode = ApiError["code"];
8
+ export declare const DEFAULT_BASE_URL = "https://api.lilbox.ai";
9
+ export interface LilboxClientOptions {
10
+ /** Default https://api.lilbox.ai. */
11
+ baseUrl?: string;
12
+ /**
13
+ * An API key (lbx_…) or an OAuth access token, sent as a bearer token. A function is called before every
14
+ * request, so a refreshed token is picked up. Leave it out in the dashboard: the session cookie is used.
15
+ */
16
+ token?: string | (() => string | undefined | Promise<string | undefined>);
17
+ /** "include" in the dashboard, so the lilbox_session cookie is sent. */
18
+ credentials?: RequestCredentials;
19
+ /** e.g. "lilbox-cli/1.2.0". Sent as X-Lilbox-Client (browsers don't allow setting User-Agent). */
20
+ userAgent?: string;
21
+ /** Custom fetch, for tests or other runtimes. */
22
+ fetch?: typeof globalThis.fetch;
23
+ headers?: Record<string, string>;
24
+ }
25
+ export type LilboxClient = Client<paths>;
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;
package/dist/index.js ADDED
@@ -0,0 +1,42 @@
1
+ // @lilbox/client: a typed HTTP client for the lilbox API, generated from @lilbox/contracts' openapi.json.
2
+ //
3
+ // const lilbox = createLilboxClient({ token: process.env.LILBOX_TOKEN });
4
+ // const { data, error } = await lilbox.GET("/v1/apps/{app_id}/status", { params: { path: { app_id } } });
5
+ //
6
+ // Paths, inputs and outputs are checked by TypeScript. Calls never throw on API errors: they return
7
+ // { data } or { error } (an ErrorResponse). Network failures still throw.
8
+ import createClient from "openapi-fetch";
9
+ export const DEFAULT_BASE_URL = "https://api.lilbox.ai";
10
+ export function createLilboxClient(options = {}) {
11
+ const client = createClient({
12
+ baseUrl: options.baseUrl ?? DEFAULT_BASE_URL,
13
+ ...(options.credentials ? { credentials: options.credentials } : {}),
14
+ ...(options.fetch ? { fetch: options.fetch } : {}),
15
+ headers: {
16
+ ...options.headers,
17
+ ...(options.userAgent ? { "X-Lilbox-Client": options.userAgent } : {}),
18
+ },
19
+ });
20
+ const { token } = options;
21
+ if (token !== undefined) {
22
+ const auth = {
23
+ async onRequest({ request }) {
24
+ const value = typeof token === "function" ? await token() : token;
25
+ if (value)
26
+ request.headers.set("Authorization", `Bearer ${value}`);
27
+ return request;
28
+ },
29
+ };
30
+ client.use(auth);
31
+ }
32
+ return client;
33
+ }
34
+ /** True when a call's error is a lilbox API error with this code, e.g. isApiError(error, "quota_exceeded"). */
35
+ export function isApiError(error, code) {
36
+ if (typeof error !== "object" || error === null || !("error" in error))
37
+ return false;
38
+ const inner = error.error;
39
+ if (typeof inner !== "object" || inner === null || !("code" in inner))
40
+ return false;
41
+ return code === undefined || inner.code === code;
42
+ }