TypeScript SDK

v1.0.0

Fully-typed client library covering every DUAL API endpoint. Every method returns a concrete TypeScript type — no any. Includes smart retries, rich error hierarchy, and dual auth modes.

Installation

Terminal
npm install dual-sdk

Quick Start

example.ts
import { DualClient } from 'dual-sdk';

const dual = new DualClient({
  token: process.env.DUAL_API_KEY,
  authMode: 'api_key',  // 'api_key' | 'bearer' | 'both'
});

// Every method returns typed responses — no `any`
const wallet = await dual.wallets.me();
console.log(wallet.id, wallet.email);  // Wallet type

// Cursor-based pagination with generics
const page = await dual.templates.list({ limit: 20 });
console.log(page.items[0].name);  // Template type
console.log(page.next);           // string | null

// Mint an object via the Event Bus
const result = await dual.eventBus.execute({
  action: { mint: { template_id: 'tmpl_abc123', custom: { name: 'My First Object' } } }
});
console.log(result.action_id);  // Action result

Configuration

Supports API key, Bearer token, or both auth modes. Smart retries only on 429 and 5xx with exponential backoff. Custom timeouts and base URL for different environments.

config.ts
const dual = new DualClient({
  token: process.env.DUAL_API_KEY,
  authMode: 'api_key',          // 'api_key' | 'bearer' | 'both'
  baseUrl: 'https://gateway-48587430648.europe-west6.run.app',  // default
  timeout: 30_000,              // 30s default
  retry: {
    maxAttempts: 3,             // retries on 429 and 5xx only
    backoffMs: 1000,            // exponential backoff base
  },
});

Error Handling

All API errors are thrown as typed error subclasses. Catch specific error types for targeted handling — DualAuthError (401), DualNotFoundError (404), DualRateLimitError (429).

error-handling.ts
import {
  DualClient,
  DualError,
  DualAuthError,
  DualNotFoundError,
  DualRateLimitError,
} from 'dual-sdk';

const dual = new DualClient({ token: process.env.DUAL_API_KEY, authMode: 'api_key' });

try {
  const obj = await dual.objects.get('missing-id');
} catch (err) {
  if (err instanceof DualNotFoundError) {
    console.error('Not found:', err.code);          // 404
  } else if (err instanceof DualRateLimitError) {
    console.error('Retry after:', err.retryAfter);  // seconds from header
  } else if (err instanceof DualAuthError) {
    console.error('Auth failed — check your token'); // 401
  } else if (err instanceof DualError) {
    console.error('API Error [' + err.status + ']: ' + err.code);
  }
}

Modules

The SDK is organized into 14 modules, each covering a domain of the DUAL API. Access them via client.moduleName.

ModuleCoverageDescription
.wallets14 methodsAuth, profile, linking, token refresh
.templates7 methodsTemplate CRUD and variations
.objects9 methodsCRUD, search, graph traversal
.organizations18 methodsOrg management, members, roles, invitations
.payments2 methodsPayment config and deposit tracking
.storage5 methodsFile upload (FormData) and metadata
.webhooks6 methodsWebhook CRUD and testing
.notifications7 methodsPush messages and message templates
.eventBus8 methodsActions, batch execution, and action types
.faces6 methodsFace CRUD, by-template lookup
.sequencer4 methodsBatch and checkpoint tracking
.indexer7 methodsPublic read-only: templates, objects, stats
.apiKeys3 methodsAPI key management
.support4 methodsSupport messages and access requests

View the full source on GitHub · 14 modules · Fully typed

Python SDK →