TypeScript SDK

v3.0.0

Fully-typed TypeScript client library with 102 methods covering every DUAL API endpoint. Includes automatic retry, error handling, and a modular architecture.

Installation

npm install @dual/sdk

Quick Start

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

const client = new DualClient({
  token: 'your-jwt-token',
  baseUrl: 'https://blockv-labs.io'
});

// Get current wallet
const wallet = await client.wallets.getCurrentWallet();

// List templates with pagination
const templates = await client.templates.listTemplates({ limit: 20 });

// Create an object from a template
const obj = await client.objects.createObject({
  templateId: 'tmpl_abc123',
  metadata: { name: 'My First Object' }
});

Configuration

The SDK supports custom timeouts, retry policies, and base URL configuration for different environments.

config.ts
const client = new DualClient({
  token: 'your-jwt',
  timeout: 10000,        // 10 second timeout
  retry: {
    maxAttempts: 3,       // retry up to 3 times
    backoffMs: 1000       // 1 second backoff between retries
  }
});

Error Handling

All API errors are thrown as DualError instances with typed status codes, error codes, and response bodies.

error-handling.ts
import { DualClient, DualError } from '@dual/sdk';

const client = new DualClient({ token: 'your-jwt' });

try {
  const wallet = await client.wallets.getCurrentWallet();
} catch (err) {
  if (err instanceof DualError) {
    console.error(`API Error [${err.status}]: ${err.code}`);
    console.error('Details:', err.body);
  }
}

Modules

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

ModuleCoverageDescription
.wallets10 methodsLogin, registration, profile, token refresh
.templates7 methodsCRUD operations, search, variations
.objects9 methodsCreate, list, transfer, state management
.payments6 methodsPayment intents, subscription, refunds
.organizations10 methodsOrg management, members, invitations
.storage6 methodsFile upload, download, presigned URLs
.webhooks7 methodsCRUD, delivery logs, test endpoint
.notifications5 methodsPush tokens, send, preferences
.eventBus8 methodsActions, event types, subscriptions
.faces5 methodsFace registration, rendering
.sequencer5 methodsBatch submission, checkpoints
.indexer5 methodsPublic API, stats, search
.apiKeys5 methodsCreate, rotate, revoke keys
.support4 methodsTicket management

View the full source on GitHub · 799 lines · 14 modules · 102 methods