Start building gorgeous audit logs in under 5 minutes
pnpm add @auditr-io/sdk-js
import Auditr from "@auditr-io/sdk-js"; const auditrSecretKey = process.env.AUDITR_SECRET_KEY ?? ""; const auditr = new Auditr(auditrSecretKey, { baseUrl: process.env.AUDITR_API_BASE_URL, });
await auditr.events.createEvent({ org_id: "org_the-boulder-inc", org_name: "The Boulder, Inc", action: "person.get", action_result: "success", actor_type: "user", actor_id: "usr_jwayne-dohnson", actor_name: "Jwayne Dohnson", client_ip: req.ip ?? "", user_agent_raw: req.headers["user-agent"] ?? "", occurred_at: new Date().toISOString(), });
import Auditr from "@auditr-io/sdk-js"; import express from "express"; const PORT = process.env.PORT || 3000; const auditrSecretKey = process.env.AUDITR_SECRET_KEY ?? ""; const auditr = new Auditr(auditrSecretKey, { baseUrl: process.env.AUDITR_API_BASE_URL, }); const app = express(); app.set("trust proxy", true); app.use(express.json()); app.get('/persons/:id', async (req, res) => { res.json({ id: "usr_twift-saylor", name: "Twift Saylor" }); await auditr.events.createEvent({ org_id: "org_the-boulder-inc", org_name: "The Boulder, Inc", action: "person.get", action_result: "success", actor_type: "user", actor_id: "usr_jwayne-dohnson", actor_name: "Jwayne Dohnson", client_ip: req.ip ?? "", user_agent_raw: req.headers["user-agent"] ?? "", occurred_at: new Date().toISOString(), }); }); app.listen(PORT, () => console.log(`Server running on port ${PORT}`));
app.post("/api/tokens", async (req, res) => { const tokRes = await fetch(`${process.env.AUDITR_API_BASE_URL}/tokens`, { method: "POST", headers: new Headers({ Authorization: `Bearer ${process.env.AUDITR_SECRET_KEY}`, "Content-Type": "application/json", }), }); if (!tokRes.ok) { console.error("error getting token", tokRes.status); res.status(500).json(); } const token = await tokRes.json(); res.json(token); });
pnpm add @auditr-io/sdk-react
import "@auditr-io/sdk-react/dist/index.css"; import AuditLogs from "@auditr-io/sdk-react";
async function fetchToken() { const res = await fetch(`/api/tokens`, { method: "POST", headers: new Headers({ "Content-Type": "application/json", }), body: JSON.stringify({ org_id: "org_the-boulder-inc", action: "person.get", }), }); if (!res.ok) { console.error("error getting token", res.status); return undefined; } return await res.json(); }
<AuditLogs className="logs" fetchToken={fetchToken} orgId="org_the-boulder-inc" />
import React, { useState, useEffect } from "react"; import "./App.css"; import "@auditr-io/sdk-react/dist/index.css"; import AuditLogs from "@auditr-io/sdk-react"; interface Person { id: number; name: string; } async function fetchToken() { const res = await fetch(`/api/tokens`, { method: "POST", headers: new Headers({ "Content-Type": "application/json", }), body: JSON.stringify({ org_id: "org_the-boulder-inc", action: "person.get", }), }); if (!res.ok) { console.error("error getting token", res.status); return undefined; } return await res.json(); } function App() { const [person, setPerson] = useState<Person | null>(null); useEffect(() => { fetch("/api/persons/usr_twift-saylor") .then((response) => response.json()) .then((data) => setPerson(data)); }, []); return ( <div className="App"> <header className="App-header"> {person ? <p>Person: {person.name}</p> : <p>Loading...</p>} </header> <AuditLogs className="logs" fetchToken={fetchToken} orgId="org_the-boulder-inc" /> </div> ); } export default App;