@nucel/sdk-api
v0.3.0
Published
Auto-generated TypeScript client for the nucel.dev REST API
Downloads
368
Readme
@nucel/sdk-api
Auto-generated TypeScript client for the nucel.dev REST API.
DOM-free and runtime-agnostic: works in Node, Bun, Deno, edge runtimes, browsers, and Tauri desktop apps.
Installation
npm install @nucel/sdk-api
# or
bun add @nucel/sdk-api
# or
pnpm add @nucel/sdk-apiUsage
import { makeClient } from "@nucel/sdk-api";
const client = makeClient({
baseUrl: "https://nucel.dev",
token: process.env.NUCEL_TOKEN,
});
// Every endpoint is fully typed on path params, query params, request
// body, and response body.
const { data, error } = await client.GET("/api/v1/repos/{owner}/{repo}", {
params: { path: { owner: "acme", repo: "widgets" } },
});
if (error) {
console.error(error);
} else {
console.log(data);
}Creating an issue
const { data, error } = await client.POST(
"/api/v1/repos/{owner}/{repo}/issues",
{
params: { path: { owner: "acme", repo: "widgets" } },
body: {
title: "Something is broken",
body: "Details...",
labels: ["bug"],
},
},
);Merging a PR
await client.POST("/api/v1/repos/{owner}/{repo}/pulls/{number}/merge", {
params: { path: { owner: "acme", repo: "widgets", number: 42 } },
body: { strategy: "squash" },
});Browser usage
The package itself is DOM-free — you bring your own token. In a browser you typically read the token from localStorage or a cookie and pass it in:
import { makeClient } from "@nucel/sdk-api";
const client = makeClient({
baseUrl: window.location.origin,
token: window.localStorage.getItem("nucel_token") ?? undefined,
});Custom middleware
openapi-fetch supports request/response middleware. You can add your own:
import { makeClient } from "@nucel/sdk-api";
const client = makeClient({ baseUrl: "https://nucel.dev", token: "..." });
client.use({
async onRequest({ request }) {
console.log("→", request.method, request.url);
return request;
},
async onResponse({ response }) {
console.log("←", response.status);
return response;
},
});How the SDK is generated
- The
nucel-servercrate annotates every API v1 handler with#[utoipa::path] cargo run -p nucel-server --bin export-openapiwrites the OpenAPI spec toopenapi/nucel.json- This package's
scripts/openapi-typescriptregeneratessrc/schema.d.tsfrom that spec src/client.tsprovides the thinmakeClientwrapper overopenapi-fetch
To regenerate after API changes:
cd packages/sdk-api
bun run generate
bun run buildRelated packages
nucel-sdk-api— Rust SDK generated from the same OpenAPI spec.
License
MIT
