SDK npm package is not published yet and API environments may be unavailable.View status
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/sdk

Requirements: 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

OptionTypeDefaultDescription
apiKeystringRequired. Your API key from the console.
baseUrlstringhttps://api.anankelabs.ioOverride for staging or local development.
retriesnumber0Number of automatic retries on 429 / 5xx.
retryDelayMsnumber500Base delay between retries (doubles each attempt).
timeoutMsnumber0Request timeout in milliseconds (0 = no timeout).
logLevelstring"none"One of none, error, warn, info, debug.
logFnfunctionCustom log function (level, msg, meta) => void.
onRequestfunctionHook to mutate headers/body before each request.
onResponsefunctionHook to inspect or measure responses.
verifierobjectTCode payload verifier options (key caching).

Resources

The client exposes three top-level resource groups:

PropertyDescriptionDocs
client.trustTemplates, documents, verification, bulk jobsSDK — Trust
client.tcodeTemplates, documents, verification, placement, bulk jobs, payload verifierSDK — TCode
client.referenceDataTenant 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 data
  • string — base64-encoded PDF
  • Blob — 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 });