Initialization & Configuration
Recommended pattern — create a singleton
typescript
// lib/settle.ts
import { SettleSettle } from 'settlesettle'
if (!process.env.SETTLESETTLE_API_KEY) {
throw new Error('SETTLESETTLE_API_KEY is not set in environment variables')
}
export const settle = new SettleSettle({
apiKey: process.env.SETTLESETTLE_API_KEY,
})Import this singleton wherever you need it:
typescript
import { settle } from '@/lib/settle'Full configuration reference
typescript
const settle = new SettleSettle({
apiKey: 'ss_live_your_key', // Required if not in environment
baseUrl: 'https://api.settlesettle.uno/v1', // Optional: Override API endpoint
timeout: 10000, // Optional: Request timeout in ms (default: 10000)
eventBuffering: {
enabled: true, // Recommended: Process events in the background
maxBatchSize: 50, // Flush when queue reaches 50 events
flushIntervalMs: 2000, // Or flush every 2 seconds
},
retry: {
maxRetries: 3, // Retry on network/5xx/429 errors (default: 3)
backoffFactor: 2, // Exponential backoff multiplier (default: 2)
},
})All config options
| Option | Type | Default | Description |
|---|---|---|---|
apiKey | string | process.env.SETTLESETTLE_API_KEY | Your app API key |
baseUrl | string | https://api.settlesettle.uno/v1 | The central SettleSettle API Base URL |
timeout | number | 10000 | Request timeout in milliseconds |
eventBuffering.enabled | boolean | true | Enable background event batching |
eventBuffering.maxBatchSize | number | 50 | Force flush at this queue size |
eventBuffering.flushIntervalMs | number | 2000 | Background flush interval |
retry.maxRetries | number | 3 | Max retry attempts per request |
retry.backoffFactor | number | 2 | Exponential backoff multiplier |
