Events receiver client
What is it?
This is the JS client for events-receiver
, the front-end for Kinesis. It is a lot less complex (and a lot smaller) than the older events-client
because it doesn't have the complexity of dealing with Kinesis, and also just does less.
Usage
See scripts/send-test.ts
and testbed/testbed.ts
for inspiration. But basically you want to do something like:
import { createEvent, createClient, ClientPlatform, EventType, EventOrigin, DeviceType } from '@iflix/events-receiver-client'
const queueEvent = createClient({
submitUrl: 'https://events.iflix-staging.com/submit',
client: {
buildName: 'put',
buildNumber: 'real',
buildVersion: 'info',
deviceName: 'in',
deviceType: DeviceType.DESKTOP,
osVersion: 'here',
userAgent: 'please',
platform: ClientPlatform.EVENT_TEST
}
})
const event = createEvent({
contentRegion: 'xx',
type: EventType.APP_EVENT,
name: `test event ${eventCount}`,
origin: EventOrigin.SYSTEM,
data: {}
})
queueEvent(event)
What does it do?
Calling createClient
gives you an "event queuing" function (you can call it what you like but the convention is queueEvent
) you can call with a fully built-out event. This will either store it in a memory buffer, or if available, IndexedDB. This is compatible with the older events-client
so you can switch backwards and forwards cleanly. (Don't run them at the same time on the same DB though!)
createClient
will start a timer in the background that will periodically flush events once an "accumulation" time period has elapsed. If you set priority
to EventPriority.HIGH
for an event, then the timer will send the whole buffer immediately. (also queueEvent
will attempt to fire off an immediate flush as soon as it's queued).
createEvent
takes your PartialEvent
and decorates it with extra info that you probably can't be bothered getting yourself. It returns an Event
suitable for giving to queueEvent
. There is nothing magical about this function though, if you construct an Event
from scratch (don't do this) you don't have to call createEvent
queueEvent
has a few extra functions on it too:
queueEvent.flush(force = false)
- this will basically do the check to see if anything needs flushing, and flush it (or always flush if force=true
). Generally speaking, you don't need to flush
-- just use priority
on events if you want things sent quickly.queueEvent.shutdown()
- this will turn off the timer, and attempt to do a final flush of the buffer
Considerations
Client and server usage
This package is designed to be used in a browser, and in NodeJS. There are a few backend services that might be simplified with this client.
Buffering
This package is more complex than it might otherwise be because of the buffering. It's pretty important though, because of the way iflix uses these events; we can't let them go missing. So it does a lot of work to try and get stuff through.
Simplicity
It probably could do with more Typescript types, some of which are currently in client-web -- perhaps during the refactoring of clients-web, some of those types could move here. What's here currently is pretty basic.
Future
More tests
More tests would definitely be nice. It was intended to build a few more, this is really kind of a very mature prototype.
Event signing
If events-receiver ends up implementing some sort of event signing then this service will need to be updated.