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

thisdata

v0.2.7

Published

NodeJs client for tracking events with ThisData

Downloads

5

Readme

thisdata-node Build Status

thisdata-node is a nodejs client for the ThisData Login Intelligence API (https://thisdata.com).

Setup

Install the latest thisdata-node package from npm

npm install thisdata --save

Create a ThisData client

var ThisData = require('thisdata');
var thisdata = ThisData("YOUR API KEY FROM THISDATA");

Track Events

Use this method to asynchronously track events that happen in your app.

thisdata.track(request, options);

To track login related events, find the point in your code just after a login success, failure or password reset and use the track method to send data to the ThisData API.

thisdata.track(req, {
  verb: thisdata.verbs.LOG_IN,
  user: {
    id: 'john123455',
    name: 'John Titor',
    email: '[email protected]'
  }
});

Options

ip and user_agent are extracted from req but you can override these value and supply additional fields using options.

{
  verb: 'transfer',
  ip: '0.0.0.0',
  userAgent: 'Firefox, Windows 98',
  user: {
    id: 'john123455',
    name: 'John Titor',
    email: '[email protected]'
  },
  session: {
    id: 'Optional'
    cookieExpected: true
  },
  device: {
    id: 'mobile-device-id'
  }
}
  • user.name - string The full name of the user
  • user.email - string - An email address for sending unusual activity alerts to
  • user.mobile - E.164 format - An mobile number for sending unusual activity SMS alerts to. e.g. +15555555555
  • session.id - string - Typically a browser session id but it's up to you
  • session.cookieExpected - boolean - Used in combination with ThisData Javascript. Set true if the script is installed
  • device.id - string - A unique device identifier. Typically used for tracking mobile devices.

Event Types

We recommend using verb constants thisdata.verbs.LOG_IN but you can use any verb that represents the type of event that you want to track.

For a full list of verbs see http://help.thisdata.com/v1.0/docs/verbs

Verify Identity

Use the Verify method to enable contextual authentication in your app. It accepts the same parameters as the Track event with the exception of the event type/verb.

thisdata.verify(request, options, callback);

Verify will return a risk score between 0->1 which indicates our level confidence that the user is who they say they are.

{ score: 0, risk_level: 'green', triggers: [], messages: [] }

0.0 - low risk/high confidence it's the real user

1.0 - high risk/low confidence it's the real user

thisdata.verify(req, {
  user: {
    id: 'john123455',
    name: 'John Titor',
    email: '[email protected]'
  }
}, function(err, body){

  if(body.score > 0.9){
    // Step up authentication
  }

});

Get a list of Events

You can get a list of events enriched with their risk score and location data for use in custom audit logs. See the docs for possible query filters and paging params.

thisdata.getEvents(options, callback);

Get last successful log-in time and location for a user.

thisdata.getEvents({
  user_id: 'john123455',
  limit: 1,
  verbs: ['log-in']
}, function(err, body){

  // last login was from
  var loginCity = body.results[0].location.address.city_name;

});

Managing custom Rules

You can get, create, update and delete custom rules.

Create a rule

// returns a rule

thisdata.rules.create({
  name: "Blacklist all ipv4 addresses",
  description: "Blocks every possible ipv4 address",
  type: "blacklist",
  target: "location.ip",
  filters: ["0.0.0.0/0"]
}, function(err, rule){ });

List all rules

thisdata.rules.list(function(err, rules){ });

Find a single rule

thisdata.rules.get("123456", function(err, rule){
  console.log(rule.id);
})

Update a rule

// id is reqired. Other params are optional

thisdata.rules.update({
  id: "123456",
  filters: ["0.0.0.0/0",""]
}, function(err, rule){ });

Delete a rule

// returns deleted as bool
thisdata.rules.delete("123456", function(err, deleted){ })

Webhooks

You should validate incoming webhooks to make sure they're from ThisData. To do this you will enter a secret string in the settings area of your ThisData account and then use that same secret to validate the webhook signature that we send in the X-Signature header.

var valid = thisdata.validateWebhook('your shared secret', 'X-Signature value', 'request body');

For more information about types of webhooks you can receive see http://help.thisdata.com/docs/webhooks

API Documentation

API Documentation is available at http://help.thisdata.com/docs/apiv1events.

Test

Run the unit tests

npm test

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/thisdata/thisdata-node