EmittableEvent
EmittableEvent
is an opinionated abstraction class for generating rich EventBridge events.
![Build Status](https://github.com/mikaelvesavuori/emittableevent/workflows/main/badge.svg)
![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=mikaelvesavuori_emittableevent&metric=alert_status)
![codecov](https://codecov.io/gh/mikaelvesavuori/emittableevent/branch/main/graph/badge.svg?token=S7D3RM9TO7)
![Maintainability](https://api.codeclimate.com/v1/badges/15a30d2b3f679507fdd0/maintainability)
Note that EmittableEvent
is primarily meant to function in an AWS Lambda context, however it will function just fine also outside of one but will be missing certain metadata.
For a great complementary solution for a Domain Event Publisher and an Event Emitter abstraction using EmittableEvent
, see my related Gist.
Usage
Basic importing and usage
const { EmittableEvent } = require('emittableevent');
import { EmittableEvent } from 'emittableevent';
class MyEvent extends EmittableEvent {
}
const event = new MyEvent(eventInput, awsRequestContext);
Demo
class MyEvent extends EmittableEvent {
}
const getMetadataConfig = (version = 1) => {
return {
version,
eventType: 'DomainEvent',
domain: 'MyDomain',
system: 'MySystem',
service: 'MyService',
team: 'MyTeam',
hostPlatform: 'aws',
owner: 'Sam Person',
jurisdiction: 'eu'
};
};
const eventInput = {
eventName: 'MyEvent',
eventBusName: 'MyEventBus',
data: {
something: 'some value here if you want'
},
metadataConfig: getMetadataConfig()
};
const event = new MyEvent(eventInput, requestContext);
console.log(event.get());
The event will look similar to:
{
"EventBusName": "MyEventBus",
"Source": "mydomain.mysystem.myevent",
"DetailType": "MyEvent",
"Detail": "{\"metadata\":{\"version\":1,\"eventType\":\"DomainEvent\",\"domain\":\"MyDomain\",\"system\":\"MySystem\",\"service\":\"MyService\",\"team\":\"MyTeam\",\"hostPlatform\":\"aws\",\"owner\":\"Sam Person\",\"jurisdiction\":\"eu\",\"eventName\":\"MyEvent\",\"correlationId\":\"26dd1faf-a901-4413-92db-9e09b7915a3c\",\"resource\":\"/\",\"accountId\":\"123412341234\",\"runtime\":\"\",\"functionName\":\"\",\"functionMemorySize\":\"\",\"functionVersion\":\"\",\"lifecycleStage\":\"dev\",\"region\":\"\"},\"data\":{\"something\":\"some value here\"}}"
}