TypeScript SDK
v1.0.0Fully-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-sdkQuick 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 resultConfiguration
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.
| Module | Coverage | Description |
|---|---|---|
.wallets | 14 methods | Auth, profile, linking, token refresh |
.templates | 7 methods | Template CRUD and variations |
.objects | 9 methods | CRUD, search, graph traversal |
.organizations | 18 methods | Org management, members, roles, invitations |
.payments | 2 methods | Payment config and deposit tracking |
.storage | 5 methods | File upload (FormData) and metadata |
.webhooks | 6 methods | Webhook CRUD and testing |
.notifications | 7 methods | Push messages and message templates |
.eventBus | 8 methods | Actions, batch execution, and action types |
.faces | 6 methods | Face CRUD, by-template lookup |
.sequencer | 4 methods | Batch and checkpoint tracking |
.indexer | 7 methods | Public read-only: templates, objects, stats |
.apiKeys | 3 methods | API key management |
.support | 4 methods | Support messages and access requests |
View the full source on GitHub · 14 modules · Fully typed
Python SDK →