Docs / Contact / sdks/javascript/configuration

JavaScript SDK: Configuration

All configuration is passed to the TendrlClient constructor. Only apiKey is required.

Constructor Options

Core

Option Type Default Description
apiKey string Entity API key (required)
apiBaseUrl string "https://app.tendrl.com/api" API base URL
debug bool false Enable console debug logging

Batching & Performance

Option Type Default Description
minBatchSize number 10 Minimum messages per batch
maxBatchSize number 100 Maximum messages per batch
minBatchInterval number 100 Minimum ms between batch sends
maxBatchInterval number 1000 Maximum ms before forced send
maxQueueSize number 1000 Maximum messages in queue

Batch size adjusts dynamically based on queue load. When the queue is under 25% full, batches are sent quickly at minimum interval. When over 75% full, the SDK waits longer to build larger batches for efficiency.

Message Polling

Option Type Default Description
callback function null Catch-all when no client.on() route matches
stateCallback function null Catch-all when no client.onState() handler is set
checkMsgRate number 3000 Milliseconds between message polls
checkMsgLimit number 1 Maximum messages per poll

Offline Storage

Option Type Default Description
offlineStorage bool false Enable IndexedDB persistence
dbName string "tendrl_offline" IndexedDB database name

When enabled, messages that fail to send are stored in IndexedDB with a 1-hour TTL. They're automatically retried in batches of 50 when connectivity returns. Expired messages are cleaned up every 60 seconds.

Environment Variables

Variable Used By Description
REACT_APP_TENDRL_KEY React hook API key for useTendrlClient

React Hook Options

The useTendrlClient hook accepts the same options as the constructor, plus:

Option Type Default Description
onMessage function null Message callback (set as callback)
javascript

const { client, isConnected, publish } = useTendrlClient({
    apiKey: 'your_key',       // Or use REACT_APP_TENDRL_KEY env var
    onMessage: handleMessage,
    offlineStorage: true,
    checkMsgRate: 5000,
    debug: true
});

The hook automatically starts the client on mount and stops it on unmount.

Example Configurations

Development

javascript

const client = new TendrlClient({
    apiKey: 'dev_key',
    debug: true
});

Production Web App

javascript

const client = new TendrlClient({
    apiKey: process.env.REACT_APP_TENDRL_KEY,
    offlineStorage: true,
    maxBatchSize: 200,
    checkMsgRate: 5000,
    checkMsgLimit: 10
});

High-Frequency Node.js Service

javascript

const client = new TendrlClient({
    apiKey: process.env.TENDRL_KEY,
    minBatchSize: 50,
    maxBatchSize: 500,
    maxQueueSize: 5000,
    minBatchInterval: 50,
    maxBatchInterval: 500
});

Request Timeouts

The SDK uses these internal timeouts (not configurable):

Operation Timeout
Single message send 5 seconds
Batch message send 30 seconds
Connection check 2 seconds