A package for server correlation, working according to the FIRST LEGO League TMS Module Standard correlation section.
The package saves the correlation-id and authentication data using the domain
feature of node.
There are two options to use this library: with middleware or with domain.
When having frameworks like express that
support middlewares. You can use the middleware
correlationMiddleware
this middleware will also take care of
authentication.
When not using the middleware you should open a new domain in your
code, and use the function correlateSession
. 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.
You can use the function getCorrelationId
and
getAuthenticationData
to retrive data on the current session.
To contribute to this repository, simply create a PR and set one of the Code Owners to be a reviewer. Please notice the linting and UT, because they block merge. Keep the package lightweight and easy to use. Thank you for contributing!