Node SDK
@santati/node is the official Node client for the Santati audit-log API, published on npm — TypeScript types included, ESM only, no runtime dependencies. Requires Node 22+.
Install
npm install @santati/node
Create a client
import { Santati } from "@santati/node";
const santati = new Santati({
apiKey: process.env.SANTATI_API_KEY!,
trail: "billing",
});
| option | default | meaning |
|---|---|---|
apiKey | required, non-empty | team API key (sat_sk_…) |
baseUrl | https://api.santati.io | trailing / ignored; a path prefix is kept |
trail | none | default trail for emits |
timeoutMs | 10000 | per attempt |
maxRetries | 2 | retries after the first attempt |
initialBackoffMs | 250 | backoff base |
maxBackoffMs | 8000 | backoff cap, and the largest Retry-After |
headers | none | extra headers on every request |
trail is the default trail for emits and is never applied to reads. Construction fails with a ValidationError (with status null) for an empty key or an Authorization header in headers.
Emit an event
const { event, duplicate, idempotencyKey } = await santati.events.emit({
event: "invoice.voided",
organizationId: "org_acme",
actor: { type: "user", id: "usr_123", name: "Valentine Michael Smith" },
targets: [{ type: "invoice", id: "inv_555" }],
});
console.log(event.id, duplicate, idempotencyKey);
Without an idempotencyKey one is generated for you, and duplicate is true when the server replayed an earlier request. See Idempotency and Event envelope.
Emit a batch
const batch = await santati.events.emitBatch([
{ event: "invoice.paid", organizationId: "org_acme" },
{ event: "invoice.voided", organizationId: "org_acme" },
]);
console.log(batch.accepted, batch.rejected, batch.results);
A 202 and a 207 both return a result with per-item status (accepted, duplicate or rejected), and the server enforces 500 events / 1 MiB — a 413 arrives as a validation error. See Batching.
List and iterate
const page = await santati.events.list({ trail: "billing", limit: 50 });
console.log(page.results, page.nextCursor);
for await (const event of santati.events.iterate({ trail: "billing" })) {
console.log(event.id, event.event);
}
list accepts trail, event, eventPrefix, organizationId, actorId, actorType, targetType, targetId, createdAfter, createdBefore, q, sort and limit, plus cursor on list only. iterate is an async generator — use for await. See Searching events.
Errors and retries
Every failure is a SantatiError subclass:
| kind | when |
|---|---|
ValidationError | local validation (status is null), or HTTP 400, 413, 422 |
AuthError | HTTP 401, 403 |
NotFoundError | HTTP 404 |
RateLimitedError | HTTP 429 |
ServerError | HTTP 5xx |
TransportError | no response: refused, DNS, TLS, timeout (status is null) |
ApiError | any other status, an unexpected 2xx, or an undecodable body |
Each carries status, code, field, retryAfter and message.
import { RateLimitedError } from "@santati/node";
try {
await santati.events.emit({ event: "invoice.voided", organizationId: "org_acme" });
} catch (error) {
if (error instanceof RateLimitedError) {
console.log(`retry after ${error.retryAfter}s`);
}
}
An emit, a batch and a list retry transport failures, 500/502/503/504 and 429 (unless the code is quota_exceeded) up to maxRetries times, re-sending the identical request with the same idempotency keys. A Retry-After header is honoured unless it exceeds maxBackoffMs, in which case the error is raised immediately. Redirects are never followed. See Errors and Rate limits.