@nestjs/throttler
Advanced tools
Comparing version 1.1.2 to 1.1.3
@@ -1,2 +0,2 @@ | ||
## [1.1.2](https://github.com/nestjs/throttler/compare/v1.1.1...v1.1.2) (2021-03-24) | ||
## [1.1.3](https://github.com/nestjs/throttler/compare/v1.1.2...v1.1.3) (2021-03-30) | ||
@@ -6,3 +6,3 @@ | ||
* **guard:** fix access to options and service in guard ([6d2cc31](https://github.com/nestjs/throttler/commit/6d2cc31ad1c4e998736aa734c94979eb64cbb07d)) | ||
* expose injection tokens and allow for tracker override ([3444608](https://github.com/nestjs/throttler/commit/34446083b563ea9361c268fc951de79e88c51165)) | ||
@@ -9,0 +9,0 @@ |
@@ -7,2 +7,3 @@ export * from './throttler-module-options.interface'; | ||
export * from './throttler.module'; | ||
export { getOptionsToken, getStorageToken } from './throttler.providers'; | ||
export * from './throttler.service'; |
@@ -13,2 +13,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getStorageToken = exports.getOptionsToken = void 0; | ||
__exportStar(require("./throttler-module-options.interface"), exports); | ||
@@ -20,3 +21,6 @@ __exportStar(require("./throttler-storage.interface"), exports); | ||
__exportStar(require("./throttler.module"), exports); | ||
var throttler_providers_1 = require("./throttler.providers"); | ||
Object.defineProperty(exports, "getOptionsToken", { enumerable: true, get: function () { return throttler_providers_1.getOptionsToken; } }); | ||
Object.defineProperty(exports, "getStorageToken", { enumerable: true, get: function () { return throttler_providers_1.getStorageToken; } }); | ||
__exportStar(require("./throttler.service"), exports); | ||
//# sourceMappingURL=index.js.map |
export declare const Throttle: (limit?: number, ttl?: number) => MethodDecorator & ClassDecorator; | ||
export declare const SkipThrottle: (skip?: boolean) => MethodDecorator & ClassDecorator; | ||
export declare const InjectThrottlerOptions: () => (target: object, key: string | symbol, index?: number) => void; | ||
export declare const InjectThrottlerStorage: () => (target: object, key: string | symbol, index?: number) => void; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SkipThrottle = exports.Throttle = void 0; | ||
exports.InjectThrottlerStorage = exports.InjectThrottlerOptions = exports.SkipThrottle = exports.Throttle = void 0; | ||
const common_1 = require("@nestjs/common"); | ||
const throttler_constants_1 = require("./throttler.constants"); | ||
const throttler_providers_1 = require("./throttler.providers"); | ||
function setThrottlerMetadata(target, limit, ttl) { | ||
@@ -31,2 +33,6 @@ Reflect.defineMetadata(throttler_constants_1.THROTTLER_TTL, ttl, target); | ||
exports.SkipThrottle = SkipThrottle; | ||
const InjectThrottlerOptions = () => common_1.Inject(throttler_providers_1.getOptionsToken()); | ||
exports.InjectThrottlerOptions = InjectThrottlerOptions; | ||
const InjectThrottlerStorage = () => common_1.Inject(throttler_providers_1.getStorageToken()); | ||
exports.InjectThrottlerStorage = InjectThrottlerStorage; | ||
//# sourceMappingURL=throttler.decorator.js.map |
@@ -14,2 +14,3 @@ import { CanActivate, ExecutionContext } from '@nestjs/common'; | ||
protected handleRequest(context: ExecutionContext, limit: number, ttl: number): Promise<boolean>; | ||
protected getTracker(req: Record<string, any>): string; | ||
protected getRequestResponse(context: ExecutionContext): { | ||
@@ -16,0 +17,0 @@ req: Record<string, any>; |
@@ -21,2 +21,3 @@ "use strict"; | ||
const throttler_constants_1 = require("./throttler.constants"); | ||
const throttler_decorator_1 = require("./throttler.decorator"); | ||
const throttler_exception_1 = require("./throttler.exception"); | ||
@@ -58,3 +59,4 @@ let ThrottlerGuard = class ThrottlerGuard { | ||
} | ||
const key = this.generateKey(context, req.ip); | ||
const tracker = this.getTracker(req); | ||
const key = this.generateKey(context, tracker); | ||
const ttls = await this.storageService.getRecord(key); | ||
@@ -72,2 +74,5 @@ const nearestExpiryTime = ttls.length > 0 ? Math.ceil((ttls[0] - Date.now()) / 1000) : 0; | ||
} | ||
getTracker(req) { | ||
return req.ip; | ||
} | ||
getRequestResponse(context) { | ||
@@ -84,4 +89,4 @@ const http = context.switchToHttp(); | ||
common_1.Injectable(), | ||
__param(0, common_1.Inject(throttler_constants_1.THROTTLER_OPTIONS)), | ||
__param(1, common_1.Inject(throttler_storage_interface_1.ThrottlerStorage)), | ||
__param(0, throttler_decorator_1.InjectThrottlerOptions()), | ||
__param(1, throttler_decorator_1.InjectThrottlerStorage()), | ||
__metadata("design:paramtypes", [Object, Object, core_1.Reflector]) | ||
@@ -88,0 +93,0 @@ ], ThrottlerGuard); |
@@ -9,1 +9,3 @@ import { Provider } from '@nestjs/common'; | ||
}; | ||
export declare const getOptionsToken: () => string; | ||
export declare const getStorageToken: () => symbol; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ThrottlerStorageProvider = exports.createThrottlerProviders = void 0; | ||
exports.getStorageToken = exports.getOptionsToken = exports.ThrottlerStorageProvider = exports.createThrottlerProviders = void 0; | ||
const throttler_storage_interface_1 = require("./throttler-storage.interface"); | ||
@@ -23,2 +23,6 @@ const throttler_constants_1 = require("./throttler.constants"); | ||
}; | ||
const getOptionsToken = () => throttler_constants_1.THROTTLER_OPTIONS; | ||
exports.getOptionsToken = getOptionsToken; | ||
const getStorageToken = () => throttler_storage_interface_1.ThrottlerStorage; | ||
exports.getStorageToken = getStorageToken; | ||
//# sourceMappingURL=throttler.providers.js.map |
{ | ||
"name": "@nestjs/throttler", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"description": "A Rate-Limiting module for NestJS to work on Express, Fastify, Websockets, Socket.IO, and GraphQL, all rolled up into a simple package.", | ||
@@ -53,3 +53,3 @@ "author": "Jay McDoniel <me@jaymcdoniel.dev>", | ||
"@commitlint/config-angular": "12.0.1", | ||
"@nestjs/cli": "7.5.6", | ||
"@nestjs/cli": "7.6.0", | ||
"@nestjs/common": "7.6.15", | ||
@@ -62,3 +62,3 @@ "@nestjs/core": "7.6.15", | ||
"@nestjs/platform-ws": "7.6.15", | ||
"@nestjs/schematics": "7.3.0", | ||
"@nestjs/schematics": "7.3.1", | ||
"@nestjs/testing": "7.6.15", | ||
@@ -68,15 +68,15 @@ "@nestjs/websockets": "7.6.15", | ||
"@types/express-serve-static-core": "4.17.19", | ||
"@types/jest": "26.0.21", | ||
"@types/jest": "26.0.22", | ||
"@types/md5": "2.3.0", | ||
"@types/node": "14.14.35", | ||
"@types/node": "14.14.37", | ||
"@types/socket.io": "2.1.13", | ||
"@types/socket.io-client": "1.4.36", | ||
"@types/supertest": "2.0.10", | ||
"@typescript-eslint/eslint-plugin": "4.19.0", | ||
"@typescript-eslint/parser": "4.19.0", | ||
"apollo-server-express": "2.21.2", | ||
"apollo-server-fastify": "2.21.2", | ||
"@typescript-eslint/eslint-plugin": "4.20.0", | ||
"@typescript-eslint/parser": "4.20.0", | ||
"apollo-server-express": "2.22.2", | ||
"apollo-server-fastify": "2.22.2", | ||
"conventional-changelog-cli": "2.1.1", | ||
"cz-conventional-changelog": "3.3.0", | ||
"eslint": "7.22.0", | ||
"eslint": "7.23.0", | ||
"eslint-config-prettier": "7.2.0", | ||
@@ -86,11 +86,11 @@ "eslint-plugin-import": "2.22.1", | ||
"graphql-tools": "7.0.4", | ||
"husky": "^5.2.0", | ||
"husky": "6.0.0", | ||
"jest": "26.6.3", | ||
"lint-staged": "10.5.4", | ||
"nodemon": "2.0.7", | ||
"pinst": "^2.1.6", | ||
"pinst": "2.1.6", | ||
"prettier": "2.2.1", | ||
"reflect-metadata": "0.1.13", | ||
"rimraf": "3.0.2", | ||
"rxjs": "6.6.6", | ||
"rxjs": "6.6.7", | ||
"semantic-release": "17.4.2", | ||
@@ -100,3 +100,3 @@ "socket.io": "4.0.0", | ||
"ts-jest": "26.5.4", | ||
"ts-loader": "8.0.18", | ||
"ts-loader": "8.1.0", | ||
"ts-node": "9.1.1", | ||
@@ -103,0 +103,0 @@ "tsconfig-paths": "3.9.0", |
@@ -45,2 +45,3 @@ <p align="center"> | ||
- [ThrottlerStorage](#throttlerstorage) | ||
- [Proxies](#proxies) | ||
- [Working with Websockets](#working-with-websockets) | ||
@@ -214,2 +215,6 @@ - [Working with GraphQL](#working-with-graphql) | ||
### Proxies | ||
If you are working behind a proxy, check the specific HTTP adapter options ([express](http://expressjs.com/en/guide/behind-proxies.html) and [fastify](https://www.fastify.io/docs/latest/Server/#trustproxy)) for the `trust proxy` option and enable it. Doing so will allow you to get the original IP address from the `X-Forward-For` header, and you can override the `getTracker()` method to pull the value from the header rather than from `req.ip` | ||
### Working with Websockets | ||
@@ -216,0 +221,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
394
277
316507