tracking-service v1.0.2
tracking-service
Route Tracked Events to the single-tenant Brain
IMPORTANT
The src/core
directory will be migrated to a separate npm package
About
This repository is both a POC of the tracking service and an example of the following code design system
Usage
Usage Requirements
- DynamoDb table for fake configuration service with the following records:
{ "key": "customer/<customer id>/aptible/apps/brain/public-key", "key_value": <string of public key> }
{ "key": "customer/<customer id>/aptible/apps/brain/url", "key_value": <any string, this is just logged> }
This table name is stored in the environment variable DYNAMODB_CONFIGURATION_TABLE
- DynamoDb table for fake user identification with the microsoft identity platform:
IMPORTANT: table must be named"<any prefix>_microsoft-identity-platform"
{ "tenant_id": <tenant id>, "customer_id": <customer id> }
The prefix used is stored in the environment variable DYNAMODB_USER_IDENTIFICATION_TABLE_PREFIX
For your convenience the following environment variables can be used:
DYNAMODB_CONFIGURATION_TABLE=tracking-service-configuration-test
DYNAMODB_USER_IDENTIFICATION_TABLE_PREFIX=testing-user-identification
which works with customer_id=123
and tenant_id=1
NOTE: If you want to use the environment variables above, your AWS account that is resolved implicitly needs to have permission to GetItem
on the following tables:
tracking-service-configuration-test
and testing-user-identification_microsoft-identity-platform
AWS lambda - Locally run lambda via Docker Compose
- Build lambda Docker image
# in repository root
./scripts/docker-build-lambda.sh route-tracked-events
- Start Docker Compose
# in repository root
docker-compose up
- Hit lambda endpoint with SQS Event
curl --location --request GET 'http://localhost:9000/2015-03-31/functions/function/invocations' \
--header 'Content-Type: application/json' \
--data-raw '{
"Records": [
{
"messageId": "19dd0b57-b21e-4ac1-bd88-01bbb068cb78",
"receiptHandle": "MessageReceiptHandle",
"body": "{\n \"id\": \"1\",\n \"type\": \"microsoft-teams-call\",\n \"sessions\": [\n {\n \"userIdentification\": {\n \"type\": \"microsoft-identity-platform\",\n \"userId\": \"1\",\n \"tenantId\": \"1\"\n },\n \"start\": \"2021-03-19T23:05:18.660Z\",\n \"end\": \"2021-03-19T23:05:18.660Z\"\n }\n ],\n \"payload\": {\n \"callType\": \"foo\",\n \"originator\": {\n \"type\": \"microsoft-identity-platform\",\n \"userId\": \"1\",\n \"tenantId\": \"1\"\n }\n }\n}",
"attributes": {
"ApproximateReceiveCount": "1",
"SentTimestamp": "1523232000000",
"SenderId": "123456789012",
"ApproximateFirstReceiveTimestamp": "1523232000001"
},
"messageAttributes": {},
"md5OfBody": "{{{md5_of_body}}}",
"eventSource": "aws:sqs",
"eventSourceARN": "arn:aws:sqs:us-west-1:123456789012:MyQueue",
"awsRegion": "us-west-1"
}
]
}'
- See logs in docker compose logging to verify success
Command Line Interface
- Create
tracked-event.json
file
{
"id": "1",
"type": "microsoft-teams-call",
"sessions": [
{
"userIdentification": {
"type": "microsoft-identity-platform",
"userId": "1",
"tenantId": "1"
},
"start": "2021-03-19T23:05:18.660Z",
"end": "2021-03-19T23:05:18.660Z"
}
],
"payload": {
"callType": "foo",
"originator": {
"type": "microsoft-identity-platform",
"userId": "1",
"tenantId": "1"
}
}
}
- Run npm script
npm run script:route-tracked-event -- --file /path/to/tracked-event.json
Web Server
- Build the code
npm run build
- Start the server
npm run server:api-server-v1
- curl the server
curl --location --request POST 'http://localhost:8080/tracked-event' \
--header 'Content-Type: application/json' \
--data-raw '{
"trackedEvents": [
{
"id": "1",
"type": "microsoft-teams-call",
"sessions": [
{
"userIdentification": {
"type": "microsoft-identity-platform",
"userId": "1",
"tenantId": "1"
},
"start": "2021-03-19T23:05:18.660Z",
"end": "2021-03-19T23:05:18.660Z"
}
],
"payload": {
"callType": "foo",
"originator": {
"type": "microsoft-identity-platform",
"userId": "1",
"tenantId": "1"
}
}
}
]
}'
- See response and logs on server process to verify success