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

keymetrics-api

Package Overview
Dependencies
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

keymetrics-api

Keymetrics API Wrapper

  • 1.3.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
2
Weekly downloads
 
Created
Source

Keymetrics API Wrapper

Build Status

This module lets you implement a fully customizable Keymetrics client, receiving live data from the Keymetrics API.

You will need to retrieve your Keymetrics user token to use it.

For more informations about the data structures and API calls check out the documentation.

We designed 2 ways to start the module: via callback or events.

Install

With NPM:

$ npm install keymetrics-api --save

Usage example

var Keymetrics = require('keymetrics-api');

var km = new Keymetrics({
  token: '[token]',
  public_key: '[public_key]',
  realtime: true
});

km.init(function(err, res) {
  if (err) return console.log(err);
  //Get user role
  km.bucket.fetchUserRole(function(err, res) {
    console.log('Current permissions: ' + res);
  });

  //Print received status
  km.bus.on('data:*:status', function(data) {
    console.log(data);
  });
});

Options

  • token (Required): Refresh token obtained from the Keymetrics dashboard.
  • token_type (Optional): Token type (refresh_token or access_token)
  • public_key (Optional): When defined, lets you retrieve the correct bucket.
  • realtime (Optional): When defined with public_key, launches the websocket session at start.

This snippet makes 3 successive calls (if all options are set):

  • POST to get and access_token from the servers
  • GET to retrieve the correct bucket informations
  • POST to set the Bucket active and initialize the Websocket connection.

Basic use - events

bus is broadcasting events corresponding to every step of the authentication process.

In this example we start the authentication, then retrieve the bucket and finally start the realtime interaction.

var km = new Keymetrics({
  token: '[token]'
});

//When authenticated
km.bus.on('auth:ready', function(token) {
  //Retrieve bucket
  km.bucket.connect('[public_key]');
});

//When bucket is retrieved
km.bus.on('bucket:active', function(id) {
  //Fetch user role
  km.bucket.fetchUserRole(function(err, res) {
    console.log('Current permissions: ' + res);
  });

  //Start realtime
  km.realtime.init();
});

//When realtime starts
km.bus.on('realtime:on', function() {
  console.log('Realtime started!')
});

//Retrieve access_token
km.init();

List of broadcasted events:

Authenticate
  • auth:ready
Bucket
  • bucket:active
Realtime
  • realtime:on
  • realtime:off
  • realtime:reconnect
  • realtime:reconnect-timeout
  • realtime:auth
  • raw:[server_name]:status
  • data:[server_name]:status
  • data:[server_name]:server_name
  • data:[server_name]:monitoring
User
  • user:logged_in
  • user:logged_out
Error
  • error:auth
  • error:realtime
  • error:bucket

DEBUG=* allows verbose mode for received realtime data.

License

Apache 2.0

Keywords

FAQs

Package last updated on 27 Apr 2017

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