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 - npm Package Compare versions

Comparing version 1.1.1 to 1.2.0

2

index.js

@@ -1,1 +0,1 @@

require('./lib/keymetrics.js');
module.exports = require('./lib/keymetrics.js');

@@ -110,2 +110,3 @@ 'use strict';

var self = this;
cb = function(){} || cb;

@@ -115,3 +116,3 @@ if (!this.access_token)

http
self.http
.post(this.root_url + '/oauth/revoke')

@@ -118,0 +119,0 @@ .set("Content-Type", "application/x-www-form-urlencoded")

@@ -117,3 +117,3 @@ 'use strict';

if (err) return self.bus.emit('error:bucket', err);
self.bus.emit("bucket:active", { id: self.current_raw._id, endpoint: self.current_raw.node_cache.endpoints.web });
self.bus.emit("bucket:active", { id: self.current_raw._id, endpoint: self.current_raw.node_cache.endpoints.web, public_id: self.current_raw.public_id });
});

@@ -153,3 +153,3 @@ },

self.bus.emit("bucket:active", { id: self.current_raw._id, endpoint: self.current_raw.node_cache.endpoints.web });
self.bus.emit("bucket:active", { id: self.current_raw._id, endpoint: self.current_raw.node_cache.endpoints.web, public: self.current_raw.public_id });
});

@@ -156,0 +156,0 @@ },

@@ -11,3 +11,2 @@ 'use strict';

/**

@@ -18,8 +17,7 @@ * @constructor

* @param {object} opts The options are passed to the children instances
* @param {string} opts.refresh_token [Required] Refresh token (retrieved from Keymetrics dashboard)
* @param {string} opts.token_type [Required] Type: 'refresh_token' or 'access_token'
* @param {string} opts.token [Required] Refresh token (retrieved from Keymetrics dashboard)
* @param {string} opts.token_type [Optional] Type: 'refresh_token' or 'access_token'
* @param {string} opts.access_token [Optional] Access token
* @param {string} opts.public_key [Optional] Bucket public key
* @param {string} opts.realtime [Optional] When true, attempts realtime connection on .init()
* @param {string} opts.public_key [Optional] Bucket id
* @param {string} opts.host [Optional] Base url used (default 'http://app.keymetrics.io:3000')

@@ -67,3 +65,2 @@ * @param {string} opts.basePath [Optional] Base API path (default '/api')

*/
Keymetrics.prototype.init = function (public_key, cb) {

@@ -76,2 +73,3 @@ var self = this;

}
cb = cb || function(){};

@@ -85,11 +83,9 @@ this.auth.init(this.options, function(err, res) {

if (err) return cb(err);
var data = { id: res._id, endpoint: res.node_cache.endpoints.web, public_id: res.public_id };
self.bus.emit("bucket:active", { id: res._id, endpoint: res.node_cache.endpoints.web });
self.bus.emit("bucket:active", data);
//If realtime is to be launched at start
if (self.options.realtime)
self.realtime.init(function (err, res) {
return cb(err, res);
});
else
return cb(null, res);
self.realtime.init(data);
return cb(null, res);
});

@@ -103,2 +99,11 @@ }

/**
* Close the Keymetrics connection
*/
Keymetrics.prototype.close = function() {
this.realtime.unregister();
this.auth.logout();
this.bus.removeAllListeners();
};
module.exports = Keymetrics;

@@ -26,7 +26,8 @@ 'use strict';

this.bus.on('bucket:active', function (data) {
this.bus.on('bucket:active', function(data) {
self.bucket_id = data.id;
self.public_id = data.public_id;
});
this.bus.on('auth:ready', function (data) {
this.bus.on('auth:ready', function(data) {
// update Authorization header

@@ -38,3 +39,3 @@ self.http.set('Authorization', 'Bearer ' + data.access_token);

Realtime.prototype.testVerbose = function () {
Realtime.prototype.testVerbose = function() {
if (typeof window != 'undefined' && window.VERBOSE)

@@ -54,118 +55,109 @@ return true;

*/
Realtime.prototype.init = function (cb) {
Realtime.prototype.init = function(data) {
var self = this;
this.http
.post(this.root_url + '/bucket/' + this.bucket_id + '/setActive')
.end(function (err, res) {
if (err) {
if (cb)
return cb(err);
else
return self.bus.emit('error:realtime', { msg: 'Cant subscribe to a bucket', err: err})
}
var bucket = res.body;
var web_url = data.endpoint;
var ws_url = data.endpoint;
var web_url = bucket.node_cache.endpoints.web;
var ws_url = bucket.node_cache.endpoints.web;
/***********************************
* Development url overidde
* test if on client or NodeJs
***********************************/
/***********************************
* Development url overidde
* test if on client or NodeJs
***********************************/
if (typeof window != 'undefined') {
if (window.location.host.indexOf('km.io') > -1) {
web_url = web_url.replace('9001', '3000');
ws_url = ws_url.replace('9001', '4020');
}
window.API_URL = web_url;
} else if (process.env.NODE_ENV == "development") {
web_url = web_url.replace('9001', '3000');
ws_url = ws_url.replace('9001', '4020');
}
if (typeof window != 'undefined') {
if (window.location.host.indexOf('km.io') > -1) {
web_url = web_url.replace('9001', '3000');
ws_url = ws_url.replace('9001', '4020');
}
window.API_URL = web_url;
}
else if (process.env.NODE_ENV == "development") {
web_url = web_url.replace('9001', '3000');
ws_url = ws_url.replace('9001', '4020');
}
if (self.primus)
self.primus.destroy();
if (self.primus)
self.primus.destroy();
var primus = self.primus = Primus.connect(ws_url || '/', {
strategy: ['online', 'timeout', 'disconnect'],
reconnect: {
max: Infinity // Number: The max delay before we try to reconnect.
,
min: 100 // Number: The minimum delay before we try reconnect.
,
retries: 20 // Number: How many times we shoult try to reconnect.
}
});
var primus = self.primus = Primus.connect(ws_url || '/', {
strategy: ['online', 'timeout', 'disconnect'],
reconnect: {
max: Infinity // Number: The max delay before we try to reconnect.
, min: 100 // Number: The minimum delay before we try reconnect.
, retries: 20 // Number: How many times we shoult try to reconnect.
}
});
// used to authenticate
primus.on('outgoing::url', function(url) {
url.query = 'token=' + self.token;
});
// used to authenticate
primus.on('outgoing::url', function (url) {
url.query = 'token=' + self.token;
});
primus.on('open', function() {
if (self.testVerbose())
console.log('[%s] Realtime connected', moment().format());
self.bus.emit('realtime:on');
});
primus.on('open', function () {
if (self.testVerbose())
console.log('[%s] Realtime connected', moment().format());
self.bus.emit('realtime:on');
});
primus.on('close', function() {
if (self.testVerbose())
console.log('[%s] Realtime disconnected', moment().format());
self.bus.emit('realtime:off');
});
primus.on('close', function () {
if (self.testVerbose())
console.log('[%s] Realtime disconnected', moment().format());
self.bus.emit('realtime:off');
});
primus.on('reconnect', function() {
if (self.testVerbose())
console.log('[%s] Realtime re-connection', moment().format());
self.bus.emit('realtime:reconnect');
});
primus.on('reconnect', function () {
if (self.testVerbose())
console.log('[%s] Realtime re-connection', moment().format());
self.bus.emit('realtime:reconnect');
});
primus.on('reconnect timeout', function() {
if (self.testVerbose())
console.log('Websocket reconnect timeout');
self.bus.emit('realtime:reconnect-timeout');
});
primus.on('reconnect timeout', function () {
if (self.testVerbose())
console.log('Websocket reconnect timeout');
self.bus.emit('realtime:reconnect-timeout');
});
primus.on('connection:success', function(myself) {
if (self.testVerbose())
console.log('Websocket user authenticated');
self.bus.emit('realtime:auth');
primus.on('connection:success', function (myself) {
if (self.testVerbose())
console.log('Websocket user authenticated');
self.bus.emit('realtime:auth');
});
self.primus.write({
action: 'active',
public_id: data.public_id
});
});
primus.on('error', function (err) {
self.bus.emit('error:realtime', err);
})
primus.on('error', function(err) {
self.bus.emit('error:realtime', err);
})
primus.on('data:incoming', function (data) {
Object.keys(data).forEach(function (event_key) {
primus.on('data:incoming', function(data) {
Object.keys(data).forEach(function(event_key) {
if (self.testVerbose())
console.log('data:' + data.server_name + ':' + event_key, data[event_key]);
if (self.testVerbose())
console.log('data:' + data.server_name + ':' + event_key, data[event_key]);
if (event_key === 'status')
self.bus.emit('raw:' + data.server_name + ':' + event_key, data[event_key]);
else
self.bus.emit('data:' + data.server_name + ':' + event_key, data[event_key]);
});
});
if (event_key === 'status')
self.bus.emit('raw:' + data.server_name + ':' + event_key, data[event_key]);
else
self.bus.emit('data:' + data.server_name + ':' + event_key, data[event_key]);
});
});
primus.on('heapdump:ready', function (data) {
var event_name = 'data:' + data.server_name + ':' + data.app_name + ':' + data.pm_id + ':' + 'heapdump:ready';
if (self.testVerbose()) console.log(event_name, data);
self.bus.emit(event_name, data);
});
primus.on('heapdump:ready', function(data) {
var event_name = 'data:' + data.server_name + ':' + data.app_name + ':' + data.pm_id + ':' + 'heapdump:ready';
if (self.testVerbose()) console.log(event_name, data);
self.bus.emit(event_name, data);
});
primus.on('cpuprofile:ready', function (data) {
var event_name = 'data:' + data.server_name + ':' + data.app_name + ':' + data.pm_id + ':' + 'cpuprofile:ready';
if (self.testVerbose()) console.log(event_name, data);
self.bus.emit(event_name, data);
});
if (typeof cb != 'undefined' && cb != null)
return cb(null, bucket);
});
primus.on('cpuprofile:ready', function(data) {
var event_name = 'data:' + data.server_name + ':' + data.app_name + ':' + data.pm_id + ':' + 'cpuprofile:ready';
if (self.testVerbose()) console.log(event_name, data);
self.bus.emit(event_name, data);
});
};
Realtime.prototype.close = function () {
Realtime.prototype.close = function() {
if (this.primus)

@@ -179,14 +171,13 @@ this.primus.destroy();

*/
Realtime.prototype.unregister = function (cb) {
Realtime.prototype.unregister = function() {
var self = this;
this.http
.post(this.root_url + '/bucket/' + this.bucket_id + '/setUnactive')
.end(function (err, res) {
if (err) return cb(err);
self.close();
return cb(null, res.body)
if (this.primus)
this.primus.write({
action: 'inactive',
public_id: self.public_id
});
self.close();
};
module.exports = Realtime;
'use strict';
var threads = require('threads');
var Worker = module.exports = function (opts) {

@@ -15,10 +13,9 @@ var self = this;

data.event = this.event;
self.formatStatus.send(data);
self.formatStatus(data, function() {
self.bus.emit(data.event.replace('raw:', 'data:'), data);
});
})
this.formatStatus.on('message', function (data) {
self.bus.emit(data.event.replace('raw:', 'data:'), data);
})
}
Worker.prototype.formatStatus = threads.spawn(function (status, done) {
Worker.prototype.formatStatus = function (status, done) {
var formatted = { servers: {}, _server_list: {}, apps: {}, apps_server: {}, mini_metrics: {}, event: status.event};

@@ -119,2 +116,2 @@

return done(formatted);
})
};
{
"name": "keymetrics-api",
"version": "1.1.1",
"version": "1.2.0",
"description": "Keymetrics API Wrapper",
"main": "index.js",
"scripts": {
"test": "mocha test/keymetrics.mocha.js"
"test": "mocha test/"
},

@@ -31,4 +31,3 @@ "repository": {

"superagent": "^2.2.0",
"ws": "^1.1.1",
"threads": "^0.7.0"
"ws": "^1.1.1"
},

@@ -35,0 +34,0 @@ "devDependencies": {

@@ -23,8 +23,2 @@ # Keymetrics API Wrapper

With YARN:
```bash
$ yarn add keymetrics-api
```
## Usage example

@@ -36,4 +30,3 @@

var km = new Keymetrics({
refresh_token: '[token]',
token_type: 'refresh_token',
token: '[token]',
public_key: '[public_key]',

@@ -59,4 +52,4 @@ realtime: true

* `refresh_token` (Required): Refresh token obtained from the Keymetrics dashboard.
* `token_type` (Required): Token type (`refresh_token` or `access_token`)
* `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.

@@ -79,4 +72,3 @@ * `realtime` (Optional): When defined with public_key, launches the websocket session at start.

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

@@ -83,0 +75,0 @@

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