TypeScript SDK
v3.0.0Fully-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.
| Module | Coverage | Description |
|---|---|---|
.wallets | 10 methods | Login, registration, profile, token refresh |
.templates | 7 methods | CRUD operations, search, variations |
.objects | 9 methods | Create, list, transfer, state management |
.payments | 6 methods | Payment intents, subscription, refunds |
.organizations | 10 methods | Org management, members, invitations |
.storage | 6 methods | File upload, download, presigned URLs |
.webhooks | 7 methods | CRUD, delivery logs, test endpoint |
.notifications | 5 methods | Push tokens, send, preferences |
.eventBus | 8 methods | Actions, event types, subscriptions |
.faces | 5 methods | Face registration, rendering |
.sequencer | 5 methods | Batch submission, checkpoints |
.indexer | 5 methods | Public API, stats, search |
.apiKeys | 5 methods | Create, rotate, revoke keys |
.support | 4 methods | Ticket management |
View the full source on GitHub · 799 lines · 14 modules · 102 methods