SDK

TypeScript SDK (@sparlby/sdk)

Fully typed OpenAPI client for browser BFF calls and server-to-server integrations.

Creating a client

The @sparlby/sdk package exports every generated API operation alongside createSparlbyClient(). Pass baseUrl: "/api/mera" with X-Mera-Client: "web" in the browser, or point directly to your API origin with an accessToken on the server.

Backward compatibility: existing integrations importing from @sparlby/sdk or calling createSparlbyClient() continue to work without changes — @sparlby/sdk re-exports everything from @sparlby/sdk.

client.ts
import {
  createSparlbyClient,
  listWorkspaces,
  listPostSets,
  type SparlbyErrorEnvelope,
} from "@sparlby/sdk";

const api = createSparlbyClient({
  baseUrl: process.env.SPARLBY_API_URL ?? "https://sparlby.com/api/v1",
  accessToken: () => process.env.SPARLBY_API_KEY,
});

const { data, error } = await listWorkspaces({ client: api });
if (error) {
  const err = error as SparlbyErrorEnvelope;
  console.error(err.error.code, err.error.message);
}

Browser BFF usage

Inside the Sparlby web app, requests go through the Next.js BFF proxy (/api/mera) which attaches httpOnly session cookies automatically and forwards X-Mera-Client: web.

typescript
const bff = createSparlbyClient({
  baseUrl: "/api/mera",
  headers: { "X-Mera-Client": "web" },
});