Skip to main content

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",
});
optiondefaultmeaning
apiKeyrequired, non-emptyteam API key (sat_sk_…)
baseUrlhttps://api.santati.iotrailing / ignored; a path prefix is kept
trailnonedefault trail for emits
timeoutMs10000per attempt
maxRetries2retries after the first attempt
initialBackoffMs250backoff base
maxBackoffMs8000backoff cap, and the largest Retry-After
headersnoneextra 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:

kindwhen
ValidationErrorlocal validation (status is null), or HTTP 400, 413, 422
AuthErrorHTTP 401, 403
NotFoundErrorHTTP 404
RateLimitedErrorHTTP 429
ServerErrorHTTP 5xx
TransportErrorno response: refused, DNS, TLS, timeout (status is null)
ApiErrorany 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.