Socket
Socket
Sign inDemoInstall

rate-limiter-flexible

Package Overview
Dependencies
0
Maintainers
1
Versions
163
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.2.2 to 2.2.3

40

lib/RateLimiterMongo.js
const RateLimiterStoreAbstract = require('./RateLimiterStoreAbstract');
const RateLimiterRes = require('./RateLimiterRes');
/**
* Get MongoDB driver version as upsert options differ
* @params {Object} Client instance
* @returns {Number|undefined} Major version
*/
function getDriverVersion(client) {
try {
const { version } = client.topology.s.options.metadata.driver;
const majorVersion = parseInt(version);
return majorVersion;
} catch (err) {
return undefined;
}
}
class RateLimiterMongo extends RateLimiterStoreAbstract {

@@ -33,5 +49,7 @@ /**

this._initCollection();
this._driverVersion = getDriverVersion(this.client);
});
} else {
this._initCollection();
this._driverVersion = getDriverVersion(this.client);
}

@@ -155,2 +173,12 @@ }

// Options for collection updates differ between driver versions
const upsertOptions = {
upsert: true,
};
if (this._driverVersion >= 4) {
upsertOptions.returnDocument = 'after';
} else {
upsertOptions.returnOriginal = false;
}
/*

@@ -166,6 +194,3 @@ * 1. Find actual limit and increment points

upsertData,
{
upsert: true,
returnOriginal: false,
} // eslint-disable-line comma-dangle
upsertOptions
).then((res) => {

@@ -192,6 +217,3 @@ resolve(res);

replaceTo,
{
upsert: true,
returnOriginal: false,
} // eslint-disable-line comma-dangle
upsertOptions
).then((res) => {

@@ -242,3 +264,3 @@ resolve(res);

return this._collection.deleteOne(where)
.then(res => res.result.n > 0);
.then(res => res.deletedCount > 0);
}

@@ -245,0 +267,0 @@ }

{
"name": "rate-limiter-flexible",
"version": "2.2.2",
"version": "2.2.3",
"description": "Node.js rate limiter by key and protection from DDoS and Brute-Force attacks in process Memory, Redis, MongoDb, Memcached, MySQL, PostgreSQL, Cluster or PM",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc