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

@cortec/polka

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cortec/polka - npm Package Compare versions

Comparing version 1.3.2 to 1.4.0

32

dist/index.js

@@ -10,2 +10,3 @@ "use strict";

const polka_1 = __importDefault(require("polka"));
const rate_limiter_flexible_1 = require("rate-limiter-flexible");
const zod_1 = require("zod");

@@ -38,2 +39,3 @@ const zod_validation_error_1 = require("zod-validation-error");

const logger = ctx.provide('logger');
const redis = ctx.provide('redis');
const polkaConfig = config?.get(this.name);

@@ -76,5 +78,21 @@ const app = (0, polka_1.default)({

const missing = controller.modules?.filter((module) => ctx.has(module));
let rateLimit = null;
if (missing?.length) {
throw new Error(`The following modules are missing: ${missing.join(', ')}`);
}
// Rate limiting
if (controller.rateLimit) {
const client = redis?.cache(controller.rateLimit.cache);
if (!client) {
throw new Error(`Cache '${controller.rateLimit.cache}' is not configured for rate limiting`);
}
rateLimit = new rate_limiter_flexible_1.RateLimiterRedis({
storeClient: client,
duration: controller.rateLimit.duration,
points: controller.rateLimit.limit,
execEvenly: false,
blockDuration: 0,
keyPrefix: controller.rateLimit.keyPrefix ?? `rlflx:${path}:${method}`,
});
}
const METHOD = method.toUpperCase();

@@ -116,3 +134,13 @@ /**

const handler = async (req, res, next) => {
const reqCtx = {
session: req.session,
...controller.ctx?.call(ctx, req),
};
try {
if (rateLimit && controller.rateLimit) {
const rateLimitRes = await rateLimit.consume(controller.rateLimit.count.call(ctx, req, reqCtx));
if (!rateLimitRes) {
throw new ResponseError_1.default(HttpStatusCodes_1.default.TOO_MANY_REQUESTS, 'Too many requests', {});
}
}
if (controller.schema) {

@@ -134,6 +162,2 @@ try {

}
const reqCtx = {
session: req.session,
...controller.ctx?.call(ctx, req),
};
const response = await (nr

@@ -140,0 +164,0 @@ ? nr.api.startSegment('controller', true, () => controller.onRequest.call(ctx, req, reqCtx))

16

package.json
{
"name": "@cortec/polka",
"version": "1.3.2",
"version": "1.4.0",
"description": "<description>",

@@ -27,3 +27,2 @@ "main": "dist/index.js",

"dependencies": {
"@cortec/types": "^1.6.0",
"@total-typescript/ts-reset": "^0.4.2",

@@ -33,2 +32,3 @@ "body-parser": "^1.20.2",

"polka": "^0.5.2",
"rate-limiter-flexible": "^2.4.1",
"zod": "^3.21.4",

@@ -38,6 +38,8 @@ "zod-validation-error": "^1.1.0"

"devDependencies": {
"@cortec/config": "^1.4.2",
"@cortec/logger": "^1.1.1",
"@cortec/newrelic": "^1.4.2",
"@cortec/sentry": "^1.4.2",
"@cortec/config": "^1.4.3",
"@cortec/logger": "^1.1.2",
"@cortec/newrelic": "^1.4.3",
"@cortec/redis": "^1.5.0",
"@cortec/sentry": "^1.4.3",
"@cortec/types": "^1.7.0",
"@types/polka": "^0.5.4"

@@ -49,3 +51,3 @@ },

},
"gitHead": "5611228c3ea48c1bcf27ee8c64423c85cdf50768"
"gitHead": "608a6febeea6c1a7cf4e9984debb51a05832a407"
}
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