New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

volos-quota-common

Package Overview
Dependencies
Maintainers
3
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

volos-quota-common - npm Package Compare versions

Comparing version 0.11.9 to 0.11.10

72

lib/memory_buffer.js

@@ -61,12 +61,12 @@ /****************************************************************************

var self = this;
let intervalCount = 0;
self.bucketTimer = setInterval(function() {
if(options.timeUnit === '30days'){
if(++intervalCount === options.interval){
intervalCount=0;
trimTokens(self);
}
} else {
if ( options.timeInterval <= options.maxTimeInterval) {
self.bucketTimer = setInterval(function() {
trimTokens(self);
} }, options.timeInterval);
}, options.timeInterval);
} else {
this.customSetIntervalSet = true;
this.customSetInterval(options.timeInterval, options.maxTimeInterval, function() {
trimTokens(self);
});
}

@@ -80,5 +80,32 @@ if (options.bufferTimeout) {

MemoryBuffer.prototype.customSetInterval = function(timeInterval, maxTimeInterval, cb){
if ( !this.customSetIntervalSet ) {
return;
}
this.customSetTimeOut(timeInterval, maxTimeInterval, () => {
cb();
this.customSetInterval(timeInterval, maxTimeInterval, cb);
});
}
MemoryBuffer.prototype.customSetTimeOut = function(timeInterval, maxTimeInterval, cb){
if ( !this.customSetIntervalSet ) {
return;
}
if ( timeInterval > maxTimeInterval ) {
this.customTimeoutRef = setTimeout(() => {
this.customSetTimeOut( ( timeInterval - maxTimeInterval ), maxTimeInterval, cb);
}, maxTimeInterval );
} else {
this.customTimeoutRef = setTimeout(function() {
cb();
}, timeInterval);
}
}
MemoryBuffer.prototype.destroy = function() {
clearTimeout(this.bucketTimer);
clearTimeout(this.flushTimer);
clearInterval(this.bucketTimer);
clearInterval(this.flushTimer);
this.customSetIntervalSet = false;
clearTimeout(this.customTimeoutRef);
this.spi.destroy();

@@ -137,2 +164,3 @@ };

this.remoteExpiryTimestamp = undefined;
this.calculateExpiration();
};

@@ -142,24 +170,11 @@

var time = this.resetAt + (this.owner.clockOffset || 0);
var startTime = this.owner.options.startTime;
var timeInterval = this.owner.options.timeInterval;
let remaining = 0;
if (startTime) {
// "calendar" start quota -- calculate time until the end of the bucket
var remaining = (time - startTime) % timeInterval;
this.expires = time + timeInterval - remaining;
} else {
if ('month' === this.options.timeUnit) {
var date = new Date(time);
return new Date(date.getFullYear(), date.getMonth() + 1, 1) - 1 + this.owner.clockOffset; // last ms of this month
} else {
// Default quota type -- start counting from now
this.expires = time + timeInterval;
}
remaining = (time - startTime) % timeInterval;
}
this.expires = time + timeInterval - remaining;
debug('Bucket: %s expires set to: %s', this.options.identifier, new Date(this.expires).toISOString());
};

@@ -181,3 +196,2 @@

debug('Bucket:%s applying check,count: %d, allow: %d',this.options.identifier, count, allow);
if (!this.expiryTime) { this.calculateExpiration(); }
var result = {

@@ -184,0 +198,0 @@ allowed: allow,

@@ -28,2 +28,3 @@ /****************************************************************************

var debug = require('debug')('quota');
var logger = null;

@@ -37,2 +38,5 @@ function QuotaConnect(quota, options) {

}
if ( quota.options.logger && typeof quota.options.logger === "object") {
logger = quota.options.logger;
}
this.quota = quota;

@@ -93,2 +97,5 @@ this.options = options || {};

req['quota-failed-open'] = true; // pass the flag to next plugins
if ( logger && logger.warn && typeof logger.warn === 'function') {
logger.warn('bypassing quota checks and setting quota-failed-open for identifier: '+(options.key || options.identifier));
}
debug('bypassing quota checks and setting quota-failed-open for identifier: %s', options.key || options.identifier);

@@ -104,2 +111,5 @@ }

req['quota-failed-open'] = true; // pass the flag to next plugins
if ( logger && logger.warn && typeof logger.warn === 'function') {
logger.warn('remote quota not available so processing locally, setting quota-failed-open for identifier: '+(options.key || options.identifier));
}
debug('remote quota not available so processing locally, setting quota-failed-open for identifier: %s', options.key || options.identifier);

@@ -106,0 +116,0 @@ }

@@ -57,2 +57,4 @@ /****************************************************************************

options.maxTimeInterval = DAY; // to handle TimeoutOverflowWarning
if (TimeUnits.indexOf(options.timeUnit) < 0) {

@@ -98,6 +100,4 @@ throw new Error(util.format('Invalid timeUnit %s', options.timeUnit));

if(options.timeUnit !== '30days') {
options.timeInterval *= options.interval;
}
options.timeInterval *= options.interval;
this.options = options;

@@ -104,0 +104,0 @@ var spi = new Spi(options);

{
"name": "volos-quota-common",
"version": "0.11.9",
"version": "0.11.10",
"lockfileVersion": 1,

@@ -5,0 +5,0 @@ "requires": true,

{
"name": "volos-quota-common",
"version": "0.11.9",
"version": "0.11.10",
"main": "lib/quota.js",

@@ -5,0 +5,0 @@ "license": "MIT",

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