FIRST LEGO Legaue Correlation
A library for supporting FIRST LEGO League TMS Module Standard correlation section.Usage
There are two options to use this library: with middleware or with domain.Usage with middleware
When having frameworks like express that support middlewares. You can use the middlewarecorrelationMiddleware
this middleware will also take care of
authentication.Usage with domain
When not using the middleware you should open a new domain in your code, and use the functioncorrelateSession
. For example:
const Domain = require('domain')
const { correlateSession } = require('@first-lego-league/ms-correlation')
someEventEmitter.on('someEvent', event => {
const correlationId = getCorrelationId(event)
const authToken = getAuthToken(event)
Domain.create().run(() => {
correlateSession(correlationId, authToken)
handleEvent(event)
})
})
Be aware that both argument of this function are optionals.
Retrieving correlation data
You can use the functiongetCorrelationId
and
getAuthenticationData
to retrive data on the current session.