Quickstart: TypeScript
@logu/sdk sends asks and waits for the decision, reports events and metrics, and retries safely.
1. Install and connect#
npm install @logu/sdk
npx -y @logu/cli login # connects this computer: approve the code in the app
logu login saves an API key for a new agent on this computer, and the SDK reads it (in Node). In
CI and on servers, create an agent in the app (Agents) and set LOGU_API_KEY=lg_… instead.
2. Ask and wait#
import { approved, Logu } from "@logu/sdk";
const logu = new Logu(); // LOGU_API_KEY, else the API key `logu login` saved
const ask = await logu.ask({
project: "my-app",
title: "Run the database migration in production?",
body: "Adds the refunded_at column. No downtime expected.",
timeoutSeconds: 2 * 60 * 60,
defaultOption: "decline",
});
if (approved(ask)) await migrate();
ask() resolves when the human decides (in the app, a notification, email, Telegram, Slack or WhatsApp), the ask
expires or it's withdrawn. It sends an idempotency key for you, so a retried call never asks twice.
3. Guard a function#
const dropTable = logu.guard((table: string) => db.dropTable(table), {
project: "billing",
title: (table) => `Drop table ${table}?`,
timeoutSeconds: 30 * 60,
});
await dropTable("invoices_old"); // runs once approved; throws NotApprovedError otherwise
4. Events and metrics#
await logu.event({ project: "my-app", title: "Nightly backup finished", icon: "✅" });
await logu.metric({ project: "shop", metric: "orders", value: 42 });
Next#
- Images on asks (
uploadAttachment): Attachments. - Every option of the SDK: @logu/sdk on npm.
- Errors are
LoguErrorsubclasses withcodeandissues: Errors.