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 TENDRL_APP_URL, else "https://app.tendrl.com/api" API base URL. Accepts a bare origin or a URL ending in /api.
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 Called with every inbound message. Polling only runs when this is set.
checkMsgRate number 3000 Milliseconds between message polls
checkMsgLimit number 1 Maximum messages per poll

There is no tag router and no state handling in this SDK: client.on(), client.onState() and a stateCallback option do not exist. One callback receives everything, and tags arrive as message.context?.tags. See API Reference.

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. The hook reads it from here and nowhere else.
TENDRL_APP_URL Constructor and hook Server URL, used when apiBaseUrl is not passed. Node only — there is no process.env in a browser, so pass apiBaseUrl there. See Testing against a local or staging stack.

React Hook Options#

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

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

const { client, publish } = useTendrlClient({
    onMessage: handleMessage,   // API key comes from REACT_APP_TENDRL_KEY
    offlineStorage: true,
    checkMsgRate: 5000,
    debug: true
});

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

`apiKey` is ignored by the hook

Only process.env.REACT_APP_TENDRL_KEY is read. With that variable unset the hook logs "TENDRL_KEY environment variable is missing." and creates no client, so client stays null and publish does nothing. The returned isConnected is a render-time snapshot rather than reactive state — see API Reference.

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