lezu-sdk
v0.0.58
Published
TypeScript SDK package for Lezu API consumers.
Downloads
2,443
Readme
@lezu/sdk
TypeScript SDK package for Lezu API consumers.
The SDK should wrap public API contracts without bypassing API behavior.
Runtime client
import { createLezuClient, isLezuApiError } from "@lezu/sdk";
const lezu = createLezuClient({
baseUrl: "https://api.lezu.app",
auth: { type: "apiKey", token: process.env.LEZU_API_KEY ?? "" }
});
const { projects } = await lezu.listProjects();
const project = await lezu.createProject({
name: "Website",
sourceLocale: "en"
});
await lezu.createLocale({
projectId: project.project.id,
request: { code: "nl", name: "Dutch" }
});
await lezu.importJson({
projectId: project.project.id,
request: {
locale: "en",
content: { common: { welcome: "Welcome" } }
}
});
const exported = await lezu.exportJson({
projectId: project.project.id,
request: { locale: "nl", format: "xliff" }
});The client supports API key auth (ApiKey <token>), bearer auth, browser session auth with
cookies, and custom default headers. Every method returns the public API response payload from the
standard { data, meta } envelope.
Import and export support includes JSON, CSV, YAML, and XLIFF through the typed format field.
Errors
try {
await lezu.getProject("missing");
} catch (error) {
if (isLezuApiError(error)) {
console.error(error.status, error.code, error.details);
}
}Translation jobs and bundles
const job = await lezu.createTranslationJob({
sourceLocale: "en",
targetLocales: ["nl", "fr"],
items: [{ id: "welcome", text: "Welcome" }]
});
const completed = await lezu.waitForTranslationJob({
jobId: job.id,
intervalMs: 2000,
timeoutMs: 120000
});
const bundle = await lezu.fetchBundle({
projectId: "project_123",
environment: "production",
localeCode: "nl"
});
console.log(completed.status, bundle.cache.etag, bundle.bundle.content);