JavaScript / TypeScript SDK
The official logit npm package for Node.js, Deno, Bun, and any JS/TS runtime.
Installation
bash
npm install logit
Initialization
ts
import { init } from "logit";
const logit = init({
token: process.env.LOGIT_API_KEY!,
// baseUrl: "https://api.logit.now", // optional override
// projectId: "proj_xxx", // optional, inferred from token
});
Create one instance per project and reuse it across your app. The client is stateless and safe to share across requests.
logit.now()
ts
await logit.now(channel: string, data: LogEventData): Promise<LogitResponse>
// Returns: { success: boolean, id: string, trackingId: string }
LogEventData reference
| Field | Type | Required | Description |
|---|---|---|---|
event | string | Yes | Short human-readable title |
description | string | No | One-line context string |
icon | string | No | Emoji shown in the inbox |
notify | boolean | No | Send a push notification (default: false) |
tags | Record<string, any> | No | Key-value pairs for filtering |
metadata | Record<string, any> | No | Arbitrary JSON object |
trackingId | string | No | First event's id — links events into a timeline |
inbox | boolean | No | Show in realtime inbox (default: true) |
Timelines (trackingId)
Use trackingId to group related events into a single timeline:
ts
// First event — creates a new timeline
const first = await logit.now("payments", {
event: "Payment started",
metadata: { orderId: "ord_123" },
});
// Subsequent events — pass first event's id
await logit.now("payments", {
event: "Payment processing",
trackingId: first.id,
});
await logit.now("payments", {
event: "Payment succeeded",
trackingId: first.id,
notify: true,
});
Error handling
ts
import { init, LogitError } from "logit";
try {
const res = await logit.now("signups", { event: "User signed up" });
console.log(res.id, res.trackingId);
} catch (error) {
if (error instanceof LogitError) {
console.error(error.message, error.statusCode, error.details);
} else {
throw error;
}
}
TypeScript
The SDK ships with full TypeScript definitions — no @types package needed.
ts
import type { LogEventData } from "logit";
const payload: LogEventData = {
event: "Trial started",
icon: "🎁",
notify: true,
tags: { plan: "pro" },
};
await logit.now("trials", payload);