npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mediavine/kinesis-client

v2.0.0

Published

An AWS Kinesis client for event data collection

Downloads

43

Readme

@mediavine/kinesis-client

npm CircleCI

A client for sending data to AWS Kinesis Data Streams without clients-side authentication. This is particularly useful for collecting browser data. The data can then be directed to S3, RedShift, or ElasticSearch.

Prerequisite Tasks

  • Create a Kinesis stream. You need to include the stream's resource ARN in the browser script. For more information about creating Amazon Kinesis Data Streams, see Managing Kinesis Streams in the Amazon Kinesis Data Streams Developer Guide.
  • Create an Amazon Cognito identity pool with access enabled for unauthenticated identities. You need to include the identity pool ID when instantiating the client. For more information about Amazon Cognito identity pools, see Identity Pools in the Amazon Cognito Developer Guide.
  • Create an IAM role whose policy grants permission to submit data to an Kinesis stream. For more information about creating an IAM role, see Creating a Role to Delegate Permissions to an AWS Service in the IAM User Guide.

Use the following role policy when creating the IAM role.

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "mobileanalytics:PutEvents",
        "cognito-sync:*"
      ],
      "Resource": [
        "*"
      ]
    },
    {
      "Effect": "Allow",
      "Action": [
        "kinesis:Put*"
      ],
      "Resource": [
        "STREAM_RESOURCE_ARN"
      ]
    }
  ]
}

Installation

yarn add @mediavine/kinesis-client

or

npm i @mediavine/kinesis-client

Usage

Import and instantiate the client:

import KinesisClient from '@mediavine/kinesis-client'

const options = {
  debug: false,           // <required> boolean
  identityPoolId: '...',  // <required> string (AWS Cognito Pool ID)
  interval: 5000,         // <optional> number (interval in ms for sending batched data)
  region: '...',          // <required> string (https://docs.aws.amazon.com/general/latest/gr/rande.html)
  sendOnBlur: false,      // <optional> boolean (send events when page is blurred or closed)
  streams: [
    { key: 'k1', name: '...' },  // <required> array<{ key: string, name: string }>
    { key: 'k2', name: '...' }   // (AWS Kinesis streams you wish to track)
  ]
}

// Client can be instantiated normally, but there is will be a small delay
// before AWS Cognito can authenticate.
const client = new KinesisClient(options)

// Client can be initialized asynchronously and will be ready for immediate
// tracking.
KinesisClient.init(options).then((client) => {
  // start tracking...
})

Track events using the stream key corresponding to an AWS Data Stream name with the proper authentication settings, allowing the AWS Cognito role to send data to it.

// Add en event to be sent to a Kinesis stream
client.track('k1', { foo: 'bar' })
client.track('k2', { fizz: 'buzz' })

If an interval options was included in instantiation of the client, data will be sent automatically at regular intervals. To manually trigger a data batch to be sent to Kinesis, use the following. It will clear all pending data.

client.send().then((data) => {
  // do something with AWS data stream response
})