Node.js Quickstart
Add license validation to any Node.js app in under 5 minutes.
npm install @traffic-orchestrator/client
Install the SDK
Add the Traffic Orchestrator client to your project via npm or yarn.
# npm
npm install @traffic-orchestrator/client
# yarn
yarn add @traffic-orchestrator/client
# pnpm
pnpm add @traffic-orchestrator/client
Initialize the Client
Create a client instance with your API base URL. For validation-only use, no API key is needed.
import { TrafficOrchestrator } from '@traffic-orchestrator/client'
const client = new TrafficOrchestrator({
baseUrl: 'https://api.trafficorchestrator.com/api/v1'
})
Validate a License Key
Check if a license key is valid and active. Pass the domain for web apps, or a machine ID for desktop apps.
const result = await client.validate({
key: 'TO-XXXX-XXXX-XXXX',
domain: 'example.com'
})
if (result.valid) {
console.log('✅ License active!', result.features)
// Enable premium features based on result.features
} else {
console.error('❌ Invalid license:', result.error)
// Show upgrade prompt or disable features
}
Activate on a Device
Register a device against the license to enforce seat limits. Each activation consumes one slot.
// Generate a unique machine fingerprint
const machineId = await TrafficOrchestrator.generateMachineId()
const activation = await client.activate({
key: 'TO-XXXX-XXXX-XXXX',
machineId
})
console.log('Activated:', activation.id)
console.log('Seats used:', activation.activations, '/', activation.maxActivations)
Verify Offline (Optional)
For apps that need to work without internet, verify licenses using Ed25519 cryptographic signatures — zero network calls required.
// Offline verification — no network required
const isValid = await client.verifyOffline(
'TO-XXXX-XXXX-XXXX',
signature, // from previous online validation
publicKey // your Ed25519 public key
)
if (isValid) {
// License verified without hitting the network
}
Enable Grace Period (Optional)
Protect your app from API outages. When enabled, the SDK caches successful validations in-memory and returns the cached result if the API is unreachable — up to 24 hours by default.
const client = new TrafficOrchestrator({
baseUrl: 'https://api.trafficorchestrator.com/api/v1',
gracePeriod: true, // enable caching
gracePeriodTtl: 86400, // 24 hours (default)
})
const result = await client.validate({ key, domain })
if (result.fromCache) {
console.log('Using cached validation (API unreachable)')
}
// Manually clear the cache when needed
client.clearCache()
Handle Webhooks
Receive real-time notifications when licenses are created, activated, expired, or revoked.
import crypto from 'crypto'
app.post('/webhooks/to', (req, res) => {
const signature = req.headers['x-to-signature']
const timestamp = req.headers['x-to-timestamp']
const body = JSON.stringify(req.body)
// Verify HMAC-SHA256 signature
const expected = crypto
.createHmac('sha256', WEBHOOK_SECRET)
.update(timestamp + '.' + body)
.digest('hex')
if (!crypto.timingSafeEqual(Buffer.from(signature), Buffer.from(expected))) {
return res.status(401).json({ error: 'Invalid signature' })
}
// Process the event
switch (req.body.event) {
case 'license.activated':
console.log('New activation!', req.body.data)
break
case 'license.expired':
console.log('License expired', req.body.data)
break
}
res.status(200).json({ received: true })
})