@esauti/sdk
v1.0.0
Published
Official JavaScript/TypeScript SDK for eSauti APIs and event injection
Readme
eSauti JavaScript SDK
TypeScript SDK for Node 18+ that supports:
- OpenAPI-backed REST calls via
client.api - Event injection via
client.events
The package builds to both ESM and CJS and includes generated operation + event typings.
Documentation
Read the full documentation for detailed guides:
- Installation — Set up the SDK
- Getting Started — Create your first client
- Authentication — Bearer, HMAC, custom strategies
- API Module — REST API calls
- Events Module — Event sending
- Event Types — Catalog of event types
- Error Handling — Handle errors
- Reliability & Retries — Timeouts and retry behavior
- Logging & Debugging — Debug logs and PII redaction
- Advanced Topics — Custom auth, patterns, testing
Install
npm install @esauti/sdkQuickstart
import { BearerAuth, EsautiClient } from "@esauti/sdk";
const client = new EsautiClient(
"https://example.esauti.com/api",
new BearerAuth("your-token"),
{ source: "my-app" }
);
const contacts = await client.api.call("getContacts", {
query: { limit: 20, start: 0 }
});
await client.events.send("order.created", {
identity: {
customer: { id: "cus_1", email: "[email protected]" },
entity: { id: "ord_1", type: "order" }
},
data: {
currency: "USD",
value: 99.95
}
});Authentication
Bearer
import { BearerAuth } from "@esauti/sdk";
const auth = new BearerAuth("token");HMAC (events)
import { HmacAuth } from "@esauti/sdk";
const auth = new HmacAuth("hmac-secret");HMAC headers:
X-eSauti-Timestamp: <unix-seconds>X-eSauti-Signature: sha256=<hex>
Signature base string:
METHOD + "\\n" + PATH + "\\n" + TIMESTAMP + "\\n" + BODY_JSON
Composite
import { BearerAuth, CompositeAuth, HmacAuth } from "@esauti/sdk";
const auth = new CompositeAuth([
new BearerAuth("token"),
new HmacAuth("hmac-secret")
]);API Module (client.api)
Generic call by operation id:
const oneContact = await client.api.call("getContactsById", {
path: { id: 42 }
});Tag convenience methods:
const reports = await client.api.tags.Reports.getReports();Events Module (client.events)
Build + validate envelope:
const envelope = client.events.build(
"form.submitted",
{ entity: { id: "for_1", type: "form" } },
{ form_id: "abc", form_name: "Contact" }
);Send event:
await client.events.send("form.submitted", {
identity: { entity: { id: "for_1", type: "form" } },
data: { form_id: "abc", form_name: "Contact" }
});Default event endpoint: /v1/inbound/event
Automatic event headers:
Content-Type: application/jsonX-eSauti-SourceX-Request-IdIdempotency-Key- auth + HMAC headers if configured
Dead-letter default path: ./deadletter/events.jsonl
Reliability and Logging
- Retries on: 408, 429, 500, 502, 503, 504 and network errors
- Backoff: exponential + jitter
- Request/response debug logging
- Redacts auth/signature headers and optional PII-like email/phone strings
Development
npm install
npm run generate
npm run lint
npm test
npm run buildExamples
examples/openapi-example.tsexamples/events-example.tsexamples/events-hmac-example.ts
