@snapshot-labs/keycard
Advanced tools
Comparing version 0.5.0 to 0.5.1
@@ -64,21 +64,26 @@ "use strict"; | ||
const { secret } = this; | ||
const keyData = activeKeys[key]; | ||
// Unlimited requests to snapshot APIs (example: if hub is sending requests to hub itself or to score-api) | ||
const unlimitedRequests = key === secret; | ||
if (unlimitedRequests) { | ||
return { | ||
valid: true, | ||
rateLimited: false, | ||
remaining: 0, | ||
reset: 0, | ||
limit: 0 | ||
}; | ||
} | ||
const keyData = activeKeys[key]; | ||
// If key is not in active keys, it's not valid. | ||
if (!unlimitedRequests && keyData === undefined) | ||
if (keyData === undefined) | ||
return { valid: false }; | ||
// Increase the total count for this key, but don't wait for it to finish. | ||
this.callAPI('log_req', { key }).catch(console.error); | ||
keyData.month++; | ||
let keyCount = keyData.month; | ||
if (unlimitedRequests) | ||
keyCount = 0; | ||
// Increase the total count for this key, but don't wait for it to finish. | ||
if (!unlimitedRequests) | ||
this.callAPI('log_req', { key }).catch(console.error); | ||
const limit = limits[keyData.tier].monthly; | ||
const rateLimited = keyCount > limit; | ||
const rateLimited = keyData.month > limit; | ||
return { | ||
valid: true, | ||
rateLimited, | ||
remaining: Math.max(0, limit - keyCount), | ||
remaining: Math.max(0, limit - keyData.month), | ||
reset, | ||
@@ -85,0 +90,0 @@ limit |
{ | ||
"name": "@snapshot-labs/keycard", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -84,3 +84,2 @@ import fetch from 'node-fetch'; | ||
const { secret } = this; | ||
const keyData = activeKeys[key]; | ||
@@ -90,18 +89,26 @@ // Unlimited requests to snapshot APIs (example: if hub is sending requests to hub itself or to score-api) | ||
if (unlimitedRequests) { | ||
return { | ||
valid: true, | ||
rateLimited: false, | ||
remaining: 0, | ||
reset: 0, | ||
limit: 0 | ||
}; | ||
} | ||
const keyData = activeKeys[key]; | ||
// If key is not in active keys, it's not valid. | ||
if (!unlimitedRequests && keyData === undefined) return { valid: false }; | ||
if (keyData === undefined) return { valid: false }; | ||
// Increase the total count for this key, but don't wait for it to finish. | ||
this.callAPI('log_req', { key }).catch(console.error); | ||
keyData.month++; | ||
let keyCount = keyData.month; | ||
if (unlimitedRequests) keyCount = 0; | ||
// Increase the total count for this key, but don't wait for it to finish. | ||
if (!unlimitedRequests) this.callAPI('log_req', { key }).catch(console.error); | ||
const limit = limits[keyData.tier].monthly; | ||
const rateLimited = keyCount > limit; | ||
const rateLimited = keyData.month > limit; | ||
return { | ||
valid: true, | ||
rateLimited, | ||
remaining: Math.max(0, limit - keyCount), | ||
remaining: Math.max(0, limit - keyData.month), | ||
reset, | ||
@@ -108,0 +115,0 @@ limit |
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
9624
284