Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@iflix/events-receiver-client

Package Overview
Dependencies
Maintainers
44
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@iflix/events-receiver-client

Decodes (and encodes) user tokens

  • 1.0.0-beta.10
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
33
Maintainers
44
Weekly downloads
 
Created
Source

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 // obviously your platform will be different
  }
})

const event = createEvent({
  contentRegion: 'xx',
  type: EventType.APP_EVENT,
  name: `test event ${eventCount}`,
  origin: EventOrigin.SYSTEM,
  data: {}
})

queueEvent(event) // you can `await` this if you want to make sure it's in the DB before continuing

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.

FAQs

Package last updated on 30 Jan 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc