Developers
Sign inGet API keys
SDKs/TypeScript

TypeScript SDK

Typed requests and responses for every method, for Node.js, edge runtimes and the browser.

@lumora/sdknpm370 methods

Install

Shell
npm install @lumora/sdk

Node.js 18 or later, Deno, Bun, or any runtime with fetch and Web Crypto. No dependencies.

Make a call

Create a client with an access token: an API key (hg_…) from your own business, or an app's OAuth access token (lmo_at_…). Keep it on your server, never in a browser bundle or mobile app.

TypeScript
import { Lumora } from "@lumora/sdk";

const lumora = new Lumora({ accessToken: process.env.LUMORA_ACCESS_TOKEN! });

// Fully typed: request fields autocomplete, responses are typed.
const { orders, nextPageToken } = await lumora.orders.listOrders({ pageSize: 50 });
for (const order of orders ?? []) {
  console.log(order.number, order.totals?.total); // TZS cents
}

Reads that fail on a network error, a rate limit or a server error are retried twice, waiting as long as the API asks; writes are never retried for you, since the API can't tell a repeat from a second request. Pass a base URL to the client to point it somewhere else, such as a local API.

Connect a business with OAuth

When other businesses use your app, they connect it through Lumora's consent screen and you get tokens for their business. The OAuth guide explains each step.

TypeScript
import { OAuth, createPkce, createState } from "@lumora/sdk";

const oauth = new OAuth({
  clientId: process.env.LUMORA_CLIENT_ID!,
  clientSecret: process.env.LUMORA_CLIENT_SECRET, // leave out in a mobile app
});

// 1. Send the business owner to Lumora to approve your app.
const { verifier, challenge } = await createPkce();
const state = createState();
const url = oauth.authorizationUrl({
  redirectUri: "https://yourapp.co.tz/lumora/callback",
  scopes: ["orders.read", "catalog.write"],
  state,
  codeChallenge: challenge,
});

// 2. On the callback, swap the code for tokens.
const tokens = await oauth.exchangeCode({ code, redirectUri: "https://yourapp.co.tz/lumora/callback", codeVerifier: verifier });

// 3. Before tokens.expires_at, refresh. Refresh tokens are single use.
const next = await oauth.refresh(tokens.refresh_token);

Check webhook signatures

Every delivery is signed with your endpoint's secret. Check it against the raw body before you trust the event; the helper also rejects deliveries older than five minutes. See Webhooks.

TypeScript
import { verifyWebhook, SIGNATURE_HEADER } from "@lumora/sdk";

export async function POST(req: Request) {
  const raw = await req.text(); // the exact bytes, before any JSON parsing
  try {
    const event = await verifyWebhook(process.env.LUMORA_WEBHOOK_SECRET!, req.headers.get(SIGNATURE_HEADER), raw);
    if (event.type === "order.updated") {
      // event.data is the whole order after the change
    }
    return new Response(null, { status: 204 });
  } catch {
    return new Response("bad signature", { status: 400 });
  }
}

Errors

Failed calls raise one error type with the API's error code, the HTTP status and, when you hit a rate limit, how long to wait. See Errors and rate limits for the codes.

TypeScript
import { LumoraError } from "@lumora/sdk";

try {
  await lumora.customers.listCustomers({});
} catch (err) {
  if (err instanceof LumoraError) {
    console.log(err.code);       // "permission_denied", "resource_exhausted", ...
    console.log(err.status);     // the HTTP status
    console.log(err.retryAfter); // seconds, when rate limited
  }
}

Services

Every service in the API reference is a property of the client:

PropertyServiceMethods
lumora.ordersOrders11
lumora.catalogCatalog5
lumora.customersCustomers6
lumora.inventoryInventory82
lumora.invoicesInvoices and estimates13
lumora.storefrontOnline store7
lumora.locoPesaLoco Pesa9
lumora.selcomSelcom11
lumora.roomsRooms24
lumora.diningDining1
lumora.appointmentsAppointments9
lumora.jobsJobs8
lumora.teamTeam50
lumora.payrollPayroll38
lumora.ledgerLedger and cash accounts53
lumora.expensesExpenses13
lumora.accountingAccounting7
lumora.forecastForecast8
lumora.searchSearch1
lumora.autopilotAutopilot7
lumora.auditAudit log2
lumora.locationsLocations and devices3
lumora.syncSync and change feed2

Source and versions

The SDK lives in sdks/typescript in the Lumora repository. Its service layer is regenerated whenever the API changes, and versions follow semantic versioning: a new method is a minor release, and nothing is removed without a major one.