TypeScript SDK
TypeScript SDK
Install, configure, and use the official @ananke/sdk to interact with the Ananke Labs platform from Node.js and TypeScript.
Installation
npm
npm install @ananke/sdkRequirements: Node.js ≥ 18 (uses native fetch and crypto.subtle). Ships ESM + CJS bundles with TypeScript declarations.
Quick start
Initialize the client
import { AnankeClient } from "@ananke/sdk";
const client = new AnankeClient({
apiKey: process.env.ANANKE_API_KEY!,
});
// Issue an Ananke Trust document
const issuance = await client.trust.documents.issue({
templateId: "your-template-id",
recipientName: "Jane Doe",
recipientEmail: "jane@example.com",
fields: [{ key: "certNumber", value: "C-2026-001" }],
});
console.log(issuance.reference); // "TRF-ABCD1234"Client options
| Option | Type | Default | Description |
|---|---|---|---|
apiKey | string | — | Required. Your API key from the console. |
baseUrl | string | https://api.anankelabs.io | Override for staging or local development. |
retries | number | 0 | Number of automatic retries on 429 / 5xx. |
retryDelayMs | number | 500 | Base delay between retries (doubles each attempt). |
timeoutMs | number | 0 | Request timeout in milliseconds (0 = no timeout). |
logLevel | string | "none" | One of none, error, warn, info, debug. |
logFn | function | — | Custom log function (level, msg, meta) => void. |
onRequest | function | — | Hook to mutate headers/body before each request. |
onResponse | function | — | Hook to inspect or measure responses. |
verifier | object | — | TCode payload verifier options (key caching). |
Resources
The client exposes three top-level resource groups:
| Property | Description | Docs |
|---|---|---|
client.trust | Templates, documents, verification, bulk jobs | SDK — Trust |
client.tcode | Templates, documents, verification, placement, bulk jobs, payload verifier | SDK — TCode |
client.referenceData | Tenant info, document types, public keys | — |
Pagination
List methods return a PagedResult<T> with items, page, pageSize, and totalCount. To iterate all pages, use the listAll() async generator:
Iterate all pages
// Page-by-page
const page = await client.trust.documents.list({ page: 1, pageSize: 50 });
console.log(page.totalCount, page.items.length);
// All items (async generator)
for await (const doc of client.trust.documents.listAll()) {
console.log(doc.reference);
}Error handling
The SDK throws typed errors you can catch and inspect:
Catching errors
import { AnankeError, AnankeValidationError } from "@ananke/sdk";
try {
await client.trust.documents.issue({ ... });
} catch (err) {
if (err instanceof AnankeValidationError) {
// err.fieldErrors: Record<string, string[]>
console.error("Validation failed:", err.fieldErrors);
} else if (err instanceof AnankeError) {
// err.status, err.code, err.detail, err.traceId
console.error(`[${err.status}] ${err.code}: ${err.detail}`);
} else {
throw err; // Re-throw unexpected errors
}
}Request / response hooks
Add observability or inject headers using hooks:
Hooks example
const client = new AnankeClient({
apiKey: process.env.ANANKE_API_KEY!,
onRequest: async (ctx) => {
ctx.headers.set("X-Correlation-Id", generateCorrelationId());
console.log(`→ ${ctx.method} ${ctx.url}`);
},
onResponse: async (ctx) => {
const remaining = ctx.headers.get("X-RateLimit-Remaining");
console.log(`← ${ctx.status} (rate limit remaining: ${remaining})`);
},
});PDF input
Methods that accept a PDF (issue, stamp, replacePdf) normalize several input types automatically:
Buffer/Uint8Array— binary PDF datastring— base64-encoded PDFBlob— browser or Node 18+ Blob
PDF input examples
import { readFileSync } from "fs";
// From file
const pdf = readFileSync("document.pdf");
await client.trust.documents.issue({ ...fields, pdf });
// From base64
await client.trust.documents.issue({ ...fields, pdf: base64String });