keymetrics-api
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -48,3 +48,3 @@ 'use strict'; | ||
cb = token; | ||
token = this.refresh_token || ''; | ||
token = this.token || ''; | ||
} | ||
@@ -80,6 +80,6 @@ | ||
// if the user did input a refresh token | ||
if (opts.token_type === 'refresh_token') | ||
this.refresh(opts.refresh_token, function (err, data) { | ||
if (opts.token) | ||
this.refresh(opts.token, function (err, data) { | ||
if (err) { | ||
self.bus.emit('error:auth', { msg: 'Refeshing token failed, maybe invalid/revoked refresh_token ?', err: err }); | ||
self.bus.emit('error:auth', { msg: 'Refeshing token failed, maybe invalid/revoked token ?', err: err }); | ||
return cb(err); | ||
@@ -93,4 +93,4 @@ } | ||
// if the user did input an access_token | ||
else if (opts.token_type === 'access_token') { | ||
var data = { access_token: opts.access_token, refresh_token: '', token_type: opts.token_type } | ||
else if (opts.access_token) { | ||
var data = { access_token: opts.access_token, token: '', token_type: 'access_token' } | ||
self.bus.emit('auth:ready', data); | ||
@@ -119,3 +119,2 @@ return cb(null, data) | ||
.post(this.root_url + '/oauth/revoke') | ||
.send('access_token=' + this.access_token + '&refresh_token=' + this.refresh_token + '&client_id=' + this.client_id) | ||
.set("Content-Type", "application/x-www-form-urlencoded") | ||
@@ -126,3 +125,3 @@ .end(function (err, res) { | ||
self.bus.emit("user:logged_out"); | ||
self.refresh_token = null; | ||
self.token = null; | ||
self.access_token = null; | ||
@@ -129,0 +128,0 @@ self.type = null; |
@@ -48,7 +48,2 @@ 'use strict'; | ||
this.bus.on('bucket:active', function (id) { | ||
self._id = id; | ||
self.URL = self.root_url + '/bucket/' + id; | ||
}); | ||
this.bus.on('auth:ready', function (data) { | ||
@@ -104,3 +99,3 @@ // update Authorization header | ||
self._id = self.current_raw._id; | ||
self.URL = self.root_url + '/bucket/' + self.current_raw._id; | ||
self.URL = self.current_raw.node_cache.endpoints.web + '/api/bucket/' + self.current_raw._id; | ||
return cb(null, self.current_raw); | ||
@@ -124,3 +119,3 @@ } | ||
if (err) return self.bus.emit('error:bucket', err); | ||
self.bus.emit("bucket:active", self.current_raw._id); | ||
self.bus.emit("bucket:active", { id: self.current_raw._id, endpoint: self.current_raw.node_cache.endpoints.web }); | ||
}); | ||
@@ -145,3 +140,3 @@ }, | ||
self._id = self.current_raw._id; | ||
self.URL = self.root_url + '/bucket/' + self.current_raw._id; | ||
self.URL = self.current_raw.node_cache.endpoints.web + '/api/bucket/' + self.current_raw._id; | ||
return cb(null, res.body); | ||
@@ -161,3 +156,3 @@ }); | ||
self.bus.emit("bucket:active", bucket._id); | ||
self.bus.emit("bucket:active", { id: self.current_raw._id, endpoint: self.current_raw.node_cache.endpoints.web }); | ||
}); | ||
@@ -164,0 +159,0 @@ }, |
@@ -59,3 +59,2 @@ 'use strict'; | ||
/** | ||
@@ -68,6 +67,10 @@ * Start the Keymetrics connection | ||
Keymetrics.prototype.init = function (cb) { | ||
Keymetrics.prototype.init = function (public_key, cb) { | ||
var self = this; | ||
var cb = cb || function(){}; | ||
if (typeof (public_key) === 'function') { | ||
cb = public_key; | ||
public_key = this.options.public_key || ''; | ||
} | ||
this.auth.init(this.options, function(err, res) { | ||
@@ -77,7 +80,7 @@ if (err) return cb(err); | ||
//If public key already setup | ||
if (self.options.public_key) { | ||
self.bucket.retrieve(self.options.public_key, function(err, res) { | ||
if (public_key) { | ||
self.bucket.retrieve(public_key, function(err, res) { | ||
if (err) return cb(err); | ||
self.bus.emit("bucket:active", res._id); | ||
self.bus.emit("bucket:active", { id: res._id, endpoint: res.node_cache.endpoints.web }); | ||
//If realtime is to be launched at start | ||
@@ -84,0 +87,0 @@ if (self.options.realtime) |
@@ -20,5 +20,6 @@ 'use strict'; | ||
this.bus.on('bucket:active', function(id) { | ||
self._id = id; | ||
self.URL = self.root_url + '/bucket/' + id; | ||
this.bus.on('bucket:active', function(data) { | ||
self._id = data.id; | ||
self.root_url = data.endpoint + '/api'; | ||
self.URL = self.root_url + '/bucket/' + data.id; | ||
}); | ||
@@ -25,0 +26,0 @@ this.bus.on('auth:ready', function(data) { |
@@ -20,5 +20,6 @@ 'use strict'; | ||
this.bus.on('bucket:active', function(id) { | ||
self._id = id; | ||
self.URL = self.root_url + '/bucket/' + id; | ||
this.bus.on('bucket:active', function(data) { | ||
self._id = data.id; | ||
self.root_url = data.endpoint + '/api'; | ||
self.URL = self.root_url + '/bucket/' + data.id; | ||
}); | ||
@@ -25,0 +26,0 @@ this.bus.on('auth:ready', function(data) { |
@@ -20,5 +20,6 @@ 'use strict'; | ||
this.bus.on('bucket:active', function(id) { | ||
self._id = id; | ||
self.URL = self.root_url + '/bucket/' + id; | ||
this.bus.on('bucket:active', function(data) { | ||
self._id = data.id; | ||
self.root_url = data.endpoint + '/api'; | ||
self.URL = self.root_url + '/bucket/' + data.id; | ||
}); | ||
@@ -25,0 +26,0 @@ this.bus.on('auth:ready', function(data) { |
@@ -21,5 +21,6 @@ 'use strict'; | ||
this.bus.on('bucket:active', function(id) { | ||
self._id = id; | ||
self.URL = self.root_url + '/bucket/' + id; | ||
this.bus.on('bucket:active', function(data) { | ||
self._id = data.id; | ||
self.root_url = data.endpoint + '/api'; | ||
self.URL = self.root_url + '/bucket/' + data.id; | ||
}); | ||
@@ -26,0 +27,0 @@ this.bus.on('auth:ready', function(data) { |
@@ -26,4 +26,4 @@ 'use strict'; | ||
this.bus.on('bucket:active', function (id) { | ||
self.bucket_id = id; | ||
this.bus.on('bucket:active', function (data) { | ||
self.bucket_id = data.id; | ||
}); | ||
@@ -30,0 +30,0 @@ |
{ | ||
"name": "keymetrics-api", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Keymetrics API Wrapper", | ||
"main": "lib/keymetrics.js", | ||
"main": "index.js", | ||
"scripts": { | ||
@@ -7,0 +7,0 @@ "test": "mocha test/keymetrics.mocha.js" |
# Keymetrics API Wrapper | ||
<a href="https://travis-ci.org/keymetrics/keymetrics-api"> | ||
<img src="https://travis-ci.org/keymetrics/keymetrics-api.svg?branch=master" alt="Build Status"/> | ||
</a> | ||
This module lets you implement a fully customizable Keymetrics client, receiving live data from the Keymetrics API. | ||
@@ -11,6 +15,20 @@ | ||
## Basic use - callbacks | ||
## Install | ||
With NPM: | ||
```bash | ||
$ npm install keymetrics-api --save | ||
``` | ||
With YARN: | ||
```bash | ||
$ yarn add keymetrics-api | ||
``` | ||
## Usage example | ||
```javascript | ||
var Keymetrics = require('../lib/keymetrics'); | ||
var Keymetrics = require('keymetrics-api'); | ||
@@ -124,1 +142,5 @@ var km = new Keymetrics({ | ||
`DEBUG=*` allows verbose mode for received realtime data. | ||
## License | ||
Apache 2.0 |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 18 instances in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
2781894
81
19684
145
2
22
21