Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@snapshot-labs/keycard

Package Overview
Dependencies
Maintainers
2
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@snapshot-labs/keycard - npm Package Compare versions

Comparing version 0.5.0 to 0.5.1

25

dist/index.js

@@ -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

2

package.json
{
"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

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