twilio-notifications
Advanced tools
Comparing version 0.1.4 to 0.1.5
@@ -7,5 +7,17 @@ 'use strict'; | ||
const Bottleneck = require('bottleneck'); | ||
const NotificationsConfig = require('./configuration'); | ||
const Registrar = require('./registrar'); | ||
function limit(fn, to, per) { | ||
// overflow since no token is passed to arguments | ||
let limiter = new Bottleneck(to, per, 5, Bottleneck.strategy.OVERFLOW); | ||
return function() { | ||
let args = Array.prototype.slice.call(arguments, 0); | ||
args.unshift(fn); | ||
return limiter.schedule.apply(limiter, args); | ||
}; | ||
} | ||
/** | ||
@@ -41,3 +53,4 @@ * @class | ||
_twilsock: { value: twilsock }, | ||
_reliableTransportState: { value: reliableTransportState } | ||
_reliableTransportState: { value: reliableTransportState }, | ||
_currentToken: { value: null, writable: true } | ||
}); | ||
@@ -48,3 +61,6 @@ | ||
accessManager.on('tokenExpired', () => this.emit('tokenExpired', accessManager)); | ||
accessManager.on('tokenUpdated', () => this._updateAuthToken(accessManager.token)); | ||
accessManager.on('tokenUpdated', limit(() => { | ||
this._updateAuthToken(accessManager.token); | ||
return Promise.resolve(); | ||
}, 1, 10000)); | ||
@@ -157,3 +173,6 @@ this._twilsock.on('message', (type, message) => this._routeMessage(type, message)); | ||
log.info('NTFCN I: authTokenUpdated'); | ||
this._registrar.updateToken(); | ||
if (this._currentToken !== this._config.token) { | ||
this._currentToken = this._config.token; | ||
this._registrar.updateToken(); | ||
} | ||
}; | ||
@@ -160,0 +179,0 @@ |
@@ -65,3 +65,3 @@ 'use strict'; | ||
if (this._messageTypes.has(messageType)) { | ||
log.debug('Message type already registered ', messageType); | ||
log.trace('Message type already registered ', messageType); | ||
return false; | ||
@@ -68,0 +68,0 @@ } |
{ | ||
"name": "twilio-notifications", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"description": "Client library for Twilio Notifications service", | ||
@@ -17,2 +17,3 @@ "main": "lib/client.js", | ||
"backoff": "^2.4.1", | ||
"bottleneck": "^1.12.0", | ||
"javascript-state-machine": "^2.3.5", | ||
@@ -19,0 +20,0 @@ "loglevel": "^1.4.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
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
172679
1235
7
+ Addedbottleneck@^1.12.0
+ Addedbottleneck@1.16.0(transitive)