🎯 MapView v2.0 - Global Deployment Ready

 MAJOR FEATURES:
• Auto-zoom intelligence với smart bounds fitting
• Enhanced 3D GPS markers với pulsing effects
• Professional route display với 6-layer rendering
• Status-based parking icons với availability indicators
• Production-ready build optimizations

🗺️ AUTO-ZOOM FEATURES:
• Smart bounds fitting cho GPS + selected parking
• Adaptive padding (50px) cho visual balance
• Max zoom control (level 16) để tránh quá gần
• Dynamic centering khi không có selection

🎨 ENHANCED VISUALS:
• 3D GPS marker với multi-layer pulse effects
• Advanced parking icons với status colors
• Selection highlighting với animation
• Dimming system cho non-selected items

🛣️ ROUTE SYSTEM:
• OpenRouteService API integration
• Multi-layer route rendering (glow, shadow, main, animated)
• Real-time distance & duration calculation
• Visual route info trong popup

📱 PRODUCTION READY:
• SSR safe với dynamic imports
• Build errors resolved
• Global deployment via Vercel
• Optimized performance

🌍 DEPLOYMENT:
• Vercel: https://whatever-ctk2auuxr-phong12hexdockworks-projects.vercel.app
• Bundle size: 22.8 kB optimized
• Global CDN distribution
• HTTPS enabled

💾 VERSION CONTROL:
• MapView-v2.0.tsx backup created
• MAPVIEW_VERSIONS.md documentation
• Full version history tracking
This commit is contained in:
2025-07-20 19:52:16 +07:00
parent 3203463a6a
commit c65cc97a33
64624 changed files with 7199453 additions and 6462 deletions

9
backend/node_modules/@nestjs/throttler/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,9 @@
# The MIT License
Copyright 2019-2022 Jay McDoniel, contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

310
backend/node_modules/@nestjs/throttler/README.md generated vendored Normal file
View File

@@ -0,0 +1,310 @@
<p align="center">
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="120" alt="Nest Logo" /></a>
</p>
[travis-image]: https://api.travis-ci.org/nestjs/nest.svg?branch=master
[travis-url]: https://travis-ci.org/nestjs/nest
[linux-image]: https://img.shields.io/travis/nestjs/nest/master.svg?label=linux
[linux-url]: https://travis-ci.org/nestjs/nest
<p align="center">A progressive <a href="http://nodejs.org" target="blank">Node.js</a> framework for building efficient and scalable server-side applications.</p>
<p align="center">
<a href="https://www.npmjs.com/~nestjscore"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
<a href="https://www.npmjs.com/~nestjscore"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
<a href="https://www.npmjs.com/~nestjscore"><img src="https://img.shields.io/npm/dm/@nestjs/core.svg" alt="NPM Downloads" /></a>
<a href="https://travis-ci.org/nestjs/nest"><img src="https://api.travis-ci.org/nestjs/nest.svg?branch=master" alt="Travis" /></a>
<a href="https://travis-ci.org/nestjs/nest"><img src="https://img.shields.io/travis/nestjs/nest/master.svg?label=linux" alt="Linux" /></a>
<a href="https://coveralls.io/github/nestjs/nest?branch=master"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#5" alt="Coverage" /></a>
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
<a href="https://opencollective.com/nest#backer"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
<a href="https://opencollective.com/nest#sponsor"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
<a href="https://twitter.com/nestframework"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow"></a>
</p>
<!--[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer)
[![Sponsors on Open Collective](https://opencollective.com/nest/sponsors/badge.svg)](https://opencollective.com/nest#sponsor)-->
## Description
A Rate-Limiter for NestJS, regardless of the context.
For an overview of the community storage providers, see [Community Storage Providers](#community-storage-providers).
This package comes with a couple of goodies that should be mentioned, first is the `ThrottlerModule`.
## Installation
```bash
$ npm i --save @nestjs/throttler
```
## Versions
`@nestjs/throttler@^1` is compatible with Nest v7 while `@nestjs/throttler@^2` is compatible with Nest v7 and Nest v8, but it is suggested to be used with only v8 in case of breaking changes against v7 that are unseen.
For NestJS v10, please use version 4.1.0 or above
## Table of Contents
- [Description](#description)
- [Versions](#versions)
- [Table of Contents](#table-of-contents)
- [Usage](#usage)
- [ThrottlerModule](#throttlermodule)
- [Decorators](#decorators)
- [@Throttle()](#throttle)
- [@SkipThrottle()](#skipthrottle)
- [Ignoring specific user agents](#ignoring-specific-user-agents)
- [ThrottlerStorage](#throttlerstorage)
- [Proxies](#proxies)
- [Working with Websockets](#working-with-websockets)
- [Working with GraphQL](#working-with-graphql)
- [Community Storage Providers](#community-storage-providers)
## Usage
### ThrottlerModule
The `ThrottleModule` is the main entry point for this package, and can be used
in a synchronous or asynchronous manner. All the needs to be passed is the
`ttl`, the time to live in seconds for the request tracker, and the `limit`, or
how many times an endpoint can be hit before returning a 429.
```ts
import { APP_GUARD } from '@nestjs/core';
import { ThrottlerGuard, ThrottlerModule } from '@nestjs/throttler';
@Module({
imports: [
ThrottlerModule.forRoot({
ttl: 60,
limit: 10,
}),
],
providers: [
{
provide: APP_GUARD,
useClass: ThrottlerGuard,
},
],
})
export class AppModule {}
```
The above would mean that 10 requests from the same IP can be made to a single endpoint in 1 minute.
```ts
@Module({
imports: [
ThrottlerModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: (config: ConfigService) => ({
ttl: config.get('THROTTLE_TTL'),
limit: config.get('THROTTLE_LIMIT'),
}),
}),
],
providers: [
{
provide: APP_GUARD,
useClass: ThrottlerGuard,
},
],
})
export class AppModule {}
```
The above is also a valid configuration for asynchronous registration of the module.
**NOTE:** If you add the `ThrottlerGuard` to your `AppModule` as a global guard
then all the incoming requests will be throttled by default. This can also be
omitted in favor of `@UseGuards(ThrottlerGuard)`. The global guard check can be
skipped using the `@SkipThrottle()` decorator mentioned later.
Example with `@UseGuards(ThrottlerGuard)`:
```ts
// app.module.ts
@Module({
imports: [
ThrottlerModule.forRoot({
ttl: 60,
limit: 10,
}),
],
})
export class AppModule {}
// app.controller.ts
@Controller()
export class AppController {
@UseGuards(ThrottlerGuard)
@Throttle(5, 30)
normal() {}
}
```
### Decorators
#### @Throttle()
```ts
@Throttle(limit: number = 30, ttl: number = 60)
```
This decorator will set `THROTTLER_LIMIT` and `THROTTLER_TTL` metadatas on the
route, for retrieval from the `Reflector` class. Can be applied to controllers
and routes.
#### @SkipThrottle()
```ts
@SkipThrottle(skip = true)
```
This decorator can be used to skip a route or a class **or** to negate the
skipping of a route in a class that is skipped.
```ts
@SkipThrottle()
@Controller()
export class AppController {
@SkipThrottle(false)
dontSkip() {}
doSkip() {}
}
```
In the above controller, `dontSkip` would be counted against and rate-limited
while `doSkip` would not be limited in any way.
### Ignoring specific user agents
You can use the `ignoreUserAgents` key to ignore specific user agents.
```ts
@Module({
imports: [
ThrottlerModule.forRoot({
ttl: 60,
limit: 10,
ignoreUserAgents: [
// Don't throttle request that have 'googlebot' defined in them.
// Example user agent: Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)
/googlebot/gi,
// Don't throttle request that have 'bingbot' defined in them.
// Example user agent: Mozilla/5.0 (compatible; Bingbot/2.0; +http://www.bing.com/bingbot.htm)
new RegExp('bingbot', 'gi'),
],
}),
],
})
export class AppModule {}
```
### ThrottlerStorage
Interface to define the methods to handle the details when it comes to keeping track of the requests.
Currently the key is seen as an `MD5` hash of the `IP` the `ClassName` and the
`MethodName`, to ensure that no unsafe characters are used and to ensure that
the package works for contexts that don't have explicit routes (like Websockets
and GraphQL).
The interface looks like this:
```ts
export interface ThrottlerStorage {
storage: Record<string, ThrottlerStorageOptions>;
increment(key: string, ttl: number): Promise<ThrottlerStorageRecord>;
}
```
So long as the Storage service implements this interface, it should be usable by the `ThrottlerGuard`.
### 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`. The following example works with both express and fastify:
```ts
// throttler-behind-proxy.guard.ts
import { ThrottlerGuard } from '@nestjs/throttler';
import { Injectable } from '@nestjs/common';
@Injectable()
export class ThrottlerBehindProxyGuard extends ThrottlerGuard {
protected getTracker(req: Record<string, any>): string {
return req.ips.length ? req.ips[0] : req.ip; // individualize IP extraction to meet your own needs
}
}
// app.controller.ts
import { ThrottlerBehindProxyGuard } from './throttler-behind-proxy.guard';
@UseGuards(ThrottlerBehindProxyGuard)
```
### Working with Websockets
To work with Websockets you can extend the `ThrottlerGuard` and override the `handleRequest` method with something like the following method
```ts
@Injectable()
export class WsThrottlerGuard extends ThrottlerGuard {
async handleRequest(context: ExecutionContext, limit: number, ttl: number): Promise<boolean> {
const client = context.switchToWs().getClient();
// this is a generic method to switch between `ws` and `socket.io`. You can choose what is appropriate for you
const ip = ['conn', '_socket']
.map((key) => client[key])
.filter((obj) => obj)
.shift().remoteAddress;
const key = this.generateKey(context, ip);
const { totalHits } = await this.storageService.increment(key, ttl);
if (totalHits > limit) {
throw new ThrottlerException();
}
return true;
}
}
```
There are some things to take keep in mind when working with websockets:
- You cannot bind the guard with `APP_GUARD` or `app.useGlobalGuards()` due to how Nest binds global guards.
- When a limit is reached, Nest will emit an `exception` event, so make sure there is a listener ready for this.
### Working with GraphQL
To get the `ThrottlerModule` to work with the GraphQL context, a couple of things must happen.
- You must use `Express` and `apollo-server-express` as your GraphQL server engine. This is
the default for Nest, but the [`apollo-server-fastify`](https://github.com/apollographql/apollo-server/tree/master/packages/apollo-server-fastify) package does not currently support passing `res` to the `context`, meaning headers cannot be properly set.
- When configuring your `GraphQLModule`, you need to pass an option for `context` in the form
of `({ req, res}) => ({ req, res })`. This will allow access to the Express Request and Response
objects, allowing for the reading and writing of headers.
- You must add in some additional context switching to get the `ExecutionContext` to pass back values correctly (or you can override the method entirely)
```ts
@Injectable()
export class GqlThrottlerGuard extends ThrottlerGuard {
getRequestResponse(context: ExecutionContext) {
const gqlCtx = GqlExecutionContext.create(context);
const ctx = gqlCtx.getContext();
return { req: ctx.req, res: ctx.res }; // ctx.request and ctx.reply for fastify
}
}
```
## Community Storage Providers
- [Redis](https://github.com/kkoomen/nestjs-throttler-storage-redis)
- [Mongo](https://www.npmjs.com/package/nestjs-throttler-storage-mongo)
Feel free to submit a PR with your custom storage provider being added to this list.
## License
Nest is [MIT licensed](LICENSE).

View File

@@ -0,0 +1,8 @@
export * from './throttler-module-options.interface';
export * from './throttler-storage.interface';
export * from './throttler.decorator';
export * from './throttler.exception';
export * from './throttler.guard';
export * from './throttler.module';
export { getOptionsToken, getStorageToken } from './throttler.providers';
export * from './throttler.service';

28
backend/node_modules/@nestjs/throttler/dist/index.js generated vendored Normal file
View File

@@ -0,0 +1,28 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getStorageToken = exports.getOptionsToken = void 0;
__exportStar(require("./throttler-module-options.interface"), exports);
__exportStar(require("./throttler-storage.interface"), exports);
__exportStar(require("./throttler.decorator"), exports);
__exportStar(require("./throttler.exception"), exports);
__exportStar(require("./throttler.guard"), 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

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,uEAAqD;AACrD,gEAA8C;AAC9C,wDAAsC;AACtC,wDAAsC;AACtC,oDAAkC;AAClC,qDAAmC;AACnC,6DAAyE;AAAhE,sHAAA,eAAe,OAAA;AAAE,sHAAA,eAAe,OAAA;AACzC,sDAAoC"}

View File

@@ -0,0 +1,17 @@
import { ExecutionContext, ModuleMetadata, Type } from '@nestjs/common/interfaces';
export interface ThrottlerModuleOptions {
limit?: number;
ttl?: number;
ignoreUserAgents?: RegExp[];
storage?: any;
skipIf?: (context: ExecutionContext) => boolean;
}
export interface ThrottlerOptionsFactory {
createThrottlerOptions(): Promise<ThrottlerModuleOptions> | ThrottlerModuleOptions;
}
export interface ThrottlerAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
useExisting?: Type<ThrottlerOptionsFactory>;
useClass?: Type<ThrottlerOptionsFactory>;
useFactory?: (...args: any[]) => Promise<ThrottlerModuleOptions> | ThrottlerModuleOptions;
inject?: any[];
}

View File

@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=throttler-module-options.interface.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"throttler-module-options.interface.js","sourceRoot":"","sources":["../src/throttler-module-options.interface.ts"],"names":[],"mappings":""}

View File

@@ -0,0 +1,5 @@
export interface ThrottlerStorageOptions {
totalHits: number;
expiresAt: number;
}
export declare const ThrottlerStorageOptions: unique symbol;

View File

@@ -0,0 +1,5 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ThrottlerStorageOptions = void 0;
exports.ThrottlerStorageOptions = Symbol('ThrottlerStorageOptions');
//# sourceMappingURL=throttler-storage-options.interface.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"throttler-storage-options.interface.js","sourceRoot":"","sources":["../src/throttler-storage-options.interface.ts"],"names":[],"mappings":";;;AAYa,QAAA,uBAAuB,GAAG,MAAM,CAAC,yBAAyB,CAAC,CAAC"}

View File

@@ -0,0 +1,5 @@
export interface ThrottlerStorageRecord {
totalHits: number;
timeToExpire: number;
}
export declare const ThrottlerStorageRecord: unique symbol;

View File

@@ -0,0 +1,5 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ThrottlerStorageRecord = void 0;
exports.ThrottlerStorageRecord = Symbol('ThrottlerStorageRecord');
//# sourceMappingURL=throttler-storage-record.interface.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"throttler-storage-record.interface.js","sourceRoot":"","sources":["../src/throttler-storage-record.interface.ts"],"names":[],"mappings":";;;AAYa,QAAA,sBAAsB,GAAG,MAAM,CAAC,wBAAwB,CAAC,CAAC"}

View File

@@ -0,0 +1,7 @@
import { ThrottlerStorageOptions } from './throttler-storage-options.interface';
import { ThrottlerStorageRecord } from './throttler-storage-record.interface';
export interface ThrottlerStorage {
storage: Record<string, ThrottlerStorageOptions>;
increment(key: string, ttl: number): Promise<ThrottlerStorageRecord>;
}
export declare const ThrottlerStorage: unique symbol;

View File

@@ -0,0 +1,5 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ThrottlerStorage = void 0;
exports.ThrottlerStorage = Symbol('ThrottlerStorage');
//# sourceMappingURL=throttler-storage.interface.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"throttler-storage.interface.js","sourceRoot":"","sources":["../src/throttler-storage.interface.ts"],"names":[],"mappings":";;;AAiBa,QAAA,gBAAgB,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAC"}

View File

@@ -0,0 +1,4 @@
export declare const THROTTLER_LIMIT = "THROTTLER:LIMIT";
export declare const THROTTLER_TTL = "THROTTLER:TTL";
export declare const THROTTLER_OPTIONS = "THROTTLER:MODULE_OPTIONS";
export declare const THROTTLER_SKIP = "THROTTLER:SKIP";

View File

@@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.THROTTLER_SKIP = exports.THROTTLER_OPTIONS = exports.THROTTLER_TTL = exports.THROTTLER_LIMIT = void 0;
exports.THROTTLER_LIMIT = 'THROTTLER:LIMIT';
exports.THROTTLER_TTL = 'THROTTLER:TTL';
exports.THROTTLER_OPTIONS = 'THROTTLER:MODULE_OPTIONS';
exports.THROTTLER_SKIP = 'THROTTLER:SKIP';
//# sourceMappingURL=throttler.constants.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"throttler.constants.js","sourceRoot":"","sources":["../src/throttler.constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,eAAe,GAAG,iBAAiB,CAAC;AACpC,QAAA,aAAa,GAAG,eAAe,CAAC;AAChC,QAAA,iBAAiB,GAAG,0BAA0B,CAAC;AAC/C,QAAA,cAAc,GAAG,gBAAgB,CAAC"}

View File

@@ -0,0 +1,4 @@
export declare const Throttle: (limit?: number, ttl?: number) => MethodDecorator & ClassDecorator;
export declare const SkipThrottle: (skip?: boolean) => MethodDecorator & ClassDecorator;
export declare const InjectThrottlerOptions: () => PropertyDecorator & ParameterDecorator;
export declare const InjectThrottlerStorage: () => PropertyDecorator & ParameterDecorator;

View File

@@ -0,0 +1,37 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
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) {
Reflect.defineMetadata(throttler_constants_1.THROTTLER_TTL, ttl, target);
Reflect.defineMetadata(throttler_constants_1.THROTTLER_LIMIT, limit, target);
}
const Throttle = (limit = 20, ttl = 60) => {
return (target, propertyKey, descriptor) => {
if (descriptor) {
setThrottlerMetadata(descriptor.value, limit, ttl);
return descriptor;
}
setThrottlerMetadata(target, limit, ttl);
return target;
};
};
exports.Throttle = Throttle;
const SkipThrottle = (skip = true) => {
return (target, propertyKey, descriptor) => {
if (descriptor) {
Reflect.defineMetadata(throttler_constants_1.THROTTLER_SKIP, skip, descriptor.value);
return descriptor;
}
Reflect.defineMetadata(throttler_constants_1.THROTTLER_SKIP, skip, target);
return target;
};
};
exports.SkipThrottle = SkipThrottle;
const InjectThrottlerOptions = () => (0, common_1.Inject)((0, throttler_providers_1.getOptionsToken)());
exports.InjectThrottlerOptions = InjectThrottlerOptions;
const InjectThrottlerStorage = () => (0, common_1.Inject)((0, throttler_providers_1.getStorageToken)());
exports.InjectThrottlerStorage = InjectThrottlerStorage;
//# sourceMappingURL=throttler.decorator.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"throttler.decorator.js","sourceRoot":"","sources":["../src/throttler.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAAwC;AACxC,+DAAuF;AACvF,+DAAyE;AAEzE,SAAS,oBAAoB,CAAC,MAAW,EAAE,KAAa,EAAE,GAAW;IACnE,OAAO,CAAC,cAAc,CAAC,mCAAa,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;IACnD,OA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ottlerException: Too Many Requests";
export declare class ThrottlerException extends HttpException {
constructor(message?: string);
}

View File

@@ -0,0 +1,12 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ThrottlerException = exports.throttlerMessage = void 0;
const common_1 = require("@nestjs/common");
exports.throttlerMessage = 'ThrottlerException: Too Many Requests';
class ThrottlerException extends common_1.HttpException {
constructor(message) {
super(`${message || exports.throttlerMessage}`, common_1.HttpStatus.TOO_MANY_REQUESTS);
}
}
exports.ThrottlerException = ThrottlerException;
//# sourceMappingURL=throttler.exception.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"throttler.exception.js","sourceRoot":"","sources":["../src/throttler.exception.ts"],"names":[],"mappings":";;;AAAA,2CAA2D;AAE9C,QAAA,gBAAgB,GAAG,uCAAuC,CAAC;AAOxE,MAAa,kBAAmB,SAAQ,sBAAa;IACnD,YAAY,OAAgB;QAC1B,KAAK,CAAC,GAAG,OAAO,IAAI,wBAAgB,EAAE,EAAE,mBAAU,CAAC,iBAAiB,CAAC,CAAC;IACxE,CAAC;CACF;AAJD,gDAIC"}

View File

@@ -0,0 +1,21 @@
import { CanActivate, ExecutionContext } from '@nestjs/common';
import { Reflector } from '@nestjs/core';
import { ThrottlerModuleOptions } from './throttler-module-options.interface';
import { ThrottlerStorage } from './throttler-storage.interface';
export declare class ThrottlerGuard implements CanActivate {
protected readonly options: ThrottlerModuleOptions;
protected readonly storageService: ThrottlerStorage;
protected readonly reflector: Reflector;
protected headerPrefix: string;
protected errorMessage: string;
constructor(options: ThrottlerModuleOptions, storageService: ThrottlerStorage, reflector: Reflector);
canActivate(context: ExecutionContext): Promise<boolean>;
protected handleRequest(context: ExecutionContext, limit: number, ttl: number): Promise<boolean>;
protected getTracker(req: Record<string, any>): string;
protected getRequestResponse(context: ExecutionContext): {
req: Record<string, any>;
res: Record<string, any>;
};
protected generateKey(context: ExecutionContext, suffix: string): string;
protected throwThrottlingException(context: ExecutionContext): void;
}

View File

@@ -0,0 +1,93 @@
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ThrottlerGuard = void 0;
const common_1 = require("@nestjs/common");
const core_1 = require("@nestjs/core");
const md5 = require("md5");
const throttler_storage_interface_1 = require("./throttler-storage.interface");
const throttler_constants_1 = require("./throttler.constants");
const throttler_decorator_1 = require("./throttler.decorator");
const throttler_exception_1 = require("./throttler.exception");
let ThrottlerGuard = exports.ThrottlerGuard = class ThrottlerGuard {
constructor(options, storageService, reflector) {
this.options = options;
this.storageService = storageService;
this.reflector = reflector;
this.headerPrefix = 'X-RateLimit';
this.errorMessage = throttler_exception_1.throttlerMessage;
}
async canActivate(context) {
var _a, _b;
const handler = context.getHandler();
const classRef = context.getClass();
if (this.reflector.getAllAndOverride(throttler_constants_1.THROTTLER_SKIP, [handler, classRef]) ||
((_b = (_a = this.options).skipIf) === null || _b === void 0 ? void 0 : _b.call(_a, context))) {
return true;
}
const routeOrClassLimit = this.reflector.getAllAndOverride(throttler_constants_1.THROTTLER_LIMIT, [
handler,
classRef,
]);
const routeOrClassTtl = this.reflector.getAllAndOverride(throttler_constants_1.THROTTLER_TTL, [
handler,
classRef,
]);
const limit = routeOrClassLimit || this.options.limit;
const ttl = routeOrClassTtl || this.options.ttl;
return this.handleRequest(context, limit, ttl);
}
async handleRequest(context, limit, ttl) {
const { req, res } = this.getRequestResponse(context);
if (Array.isArray(this.options.ignoreUserAgents)) {
for (const pattern of this.options.ignoreUserAgents) {
if (pattern.test(req.headers['user-agent'])) {
return true;
}
}
}
const tracker = this.getTracker(req);
const key = this.generateKey(context, tracker);
const { totalHits, timeToExpire } = await this.storageService.increment(key, ttl);
if (totalHits > limit) {
res.header('Retry-After', timeToExpire);
this.throwThrottlingException(context);
}
res.header(`${this.headerPrefix}-Limit`, limit);
res.header(`${this.headerPrefix}-Remaining`, Math.max(0, limit - totalHits));
res.header(`${this.headerPrefix}-Reset`, timeToExpire);
return true;
}
getTracker(req) {
return req.ip;
}
getRequestResponse(context) {
const http = context.switchToHttp();
return { req: http.getRequest(), res: http.getResponse() };
}
generateKey(context, suffix) {
const prefix = `${context.getClass().name}-${context.getHandler().name}`;
return md5(`${prefix}-${suffix}`);
}
throwThrottlingException(context) {
throw new throttler_exception_1.ThrottlerException(this.errorMessage);
}
};
exports.ThrottlerGuard = ThrottlerGuard = __decorate([
(0, common_1.Injectable)(),
__param(0, (0, throttler_decorator_1.InjectThrottlerOptions)()),
__param(1, (0, throttler_decorator_1.InjectThrottlerStorage)()),
__metadata("design:paramtypes", [Object, Object, core_1.Reflector])
], ThrottlerGuard);
//# sourceMappingURL=throttler.guard.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"throttler.guard.js","sourceRoot":"","sources":["../src/throttler.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA2E;AAC3E,uCAAyC;AACzC,2BAA2B;AAE3B,+EAAiE;AACjE,+DAAuF;AACvF,+DAAuF;AACvF,+DAA6E;AAMtE,IAAM,cAAc,4BAApB,MAAM,cAAc;IAGzB,YAC4B,OAAkD,EAClD,cAAmD,EAC1D,SAAoB;QAFM,YAAO,GAAP,OAAO,CAAwB;QAC/B,mBAAc,GAAd,cAAc,CAAkB;QAC1D,cAAS,GAAT,SAAS,CAAW;QAL/B,iBAAY,GAAG,aAAa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AAI,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC,IAAI,EAAE,CAAC;QACzE,OAAO,GAAG,CAAC,GAAG,MAAM,IAAI,MAAM,EAAE,CAAC,CAAC;IACpC,CAAC;IAUS,wBAAwB,CAAC,OAAyB;QAC1D,MAAM,IAAI,wCAAkB,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAClD,CAAC;CACF,CAAA;yBAnHY,cAAc;IAD1B,IAAA,mBAAU,GAAE;IAKR,WAAA,IAAA,4CAAsB,GAAE,CAAA;IACxB,WAAA,IAAA,4CAAsB,GAAE,CAAA;qDACK,gBAAS;GAN9B,cAAc,CAmH1B"}

View File

@@ -0,0 +1,8 @@
import { DynamicModule } from '@nestjs/common';
import { ThrottlerModuleOptions, ThrottlerAsyncOptions } from './throttler-module-options.interface';
export declare class ThrottlerModule {
static forRoot(options?: ThrottlerModuleOptions): DynamicModule;
static forRootAsync(options: ThrottlerAsyncOptions): DynamicModule;
private static createAsyncProviders;
private static createAsyncOptionsProvider;
}

View File

@@ -0,0 +1,63 @@
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var ThrottlerModule_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ThrottlerModule = void 0;
const common_1 = require("@nestjs/common");
const throttler_constants_1 = require("./throttler.constants");
const throttler_providers_1 = require("./throttler.providers");
let ThrottlerModule = exports.ThrottlerModule = ThrottlerModule_1 = class ThrottlerModule {
static forRoot(options = {}) {
const providers = [...(0, throttler_providers_1.createThrottlerProviders)(options), throttler_providers_1.ThrottlerStorageProvider];
return {
module: ThrottlerModule_1,
providers,
exports: providers,
};
}
static forRootAsync(options) {
const providers = [...this.createAsyncProviders(options), throttler_providers_1.ThrottlerStorageProvider];
return {
module: ThrottlerModule_1,
imports: options.imports || [],
providers,
exports: providers,
};
}
static createAsyncProviders(options) {
if (options.useExisting || options.useFactory) {
return [this.createAsyncOptionsProvider(options)];
}
return [
this.createAsyncOptionsProvider(options),
{
provide: options.useClass,
useClass: options.useClass,
},
];
}
static createAsyncOptionsProvider(options) {
if (options.useFactory) {
return {
provide: throttler_constants_1.THROTTLER_OPTIONS,
useFactory: options.useFactory,
inject: options.inject || [],
};
}
return {
provide: throttler_constants_1.THROTTLER_OPTIONS,
useFactory: async (optionsFactory) => await optionsFactory.createThrottlerOptions(),
inject: [options.useExisting || options.useClass],
};
}
};
exports.ThrottlerModule = ThrottlerModule = ThrottlerModule_1 = __decorate([
(0, common_1.Global)(),
(0, common_1.Module)({})
], ThrottlerModule);
//# sourceMappingURL=throttler.module.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"throttler.module.js","sourceRoot":"","sources":["../src/throttler.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAyE;AAMzE,+DAA0D;AAC1D,+DAA2F;AAOpF,IAAM,eAAe,iDAArB,MAAM,eAAe;IAI1B,MAAM,CAAC,OAAO,CAAC,UAAkC,EAAE;QACjD,MAAM,SAAS,GAAG,CAAC,GAAG,IAAA,8CAAwB,EAAC,OAAO,CAAC,EAAE,8CAAwB,CAAC,CAAC;QACnF,OAAO;YACL,MAAM,EAAE,iBAAe;YACvB,SAAS;YACT,OAAO,EAAE,SAAS;SACnB,CAAC;IACJ,CAAC;IAKD,MAAM,CAAC,YAAY,CAAC,OAA8B;QAChD,MAAM,SAAS,GAAG,CAAC,GAAG,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAAC,EAAE,8CAAwB,CAAC,CAAC;QACpF,OAAO;YACL,MAAM,EAAE,iBAAe;YACvB,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,EAAE;YAC9B,SAAS;YACT,OAAO,EAAE,SAAS;SACnB,CAAC;IACJ,CAAC;IAEO,MAAM,CAAC,oBAAoB,CAAC,OAA8B;QAChE,IAAI,OAAO,CAAC,WAAW,IAAI,OAAO,CAAC,UAAU,EAAE;YAC7C,OAAO,CAAC,IAAI,CAAC,0BAA0B,CAAC,OAAO,CAAC,CAAC,CAAC;SACnD;QACD,OAAO;YACL,IAAI,CAAC,0BAA0B,CAAC,OAAO,CAAC;YACxC;gBACE,OAAO,EAAE,OAAO,CAAC,QAAQ;gBACzB,QAAQ,EAAE,OAAO,CAAC,QAAQ;aAC3B;SACF,CAAC;IACJ,CAAC;IAEO,MAAM,CAAC,0BAA0B,CAAC,OAA8B;QACtE,IAAI,OAAO,CAAC,UAAU,EAAE;YACtB,OAAO;gBACL,OAAO,EAAE,uCAAiB;gBAC1B,UAAU,EAAE,OAAO,CAAC,UAAU;gBAC9B,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,EAAE;aAC7B,CAAC;SACH;QACD,OAAO;YACL,OAAO,EAAE,uCAAiB;YAC1B,UAAU,EAAE,KAAK,EAAE,cAAuC,EAAE,EAAE,CAC5D,MAAM,cAAc,CAAC,sBAAsB,EAAE;YAC/C,MAAM,EAAE,CAAC,OAAO,CAAC,WAAW,IAAI,OAAO,CAAC,QAAQ,CAAC;SAClD,CAAC;IACJ,CAAC;CACF,CAAA;0BAtDY,eAAe;IAF3B,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,eAAe,CAsD3B"}

View File

@@ -0,0 +1,10 @@
import { Provider } from '@nestjs/common';
import { ThrottlerModuleOptions } from './throttler-module-options.interface';
export declare function createThrottlerProviders(options: ThrottlerModuleOptions): Provider[];
export declare const ThrottlerStorageProvider: {
provide: symbol;
useFactory: (options: ThrottlerModuleOptions) => any;
inject: string[];
};
export declare const getOptionsToken: () => string;
export declare const getStorageToken: () => symbol;

View File

@@ -0,0 +1,27 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getStorageToken = exports.getOptionsToken = exports.ThrottlerStorageProvider = exports.createThrottlerProviders = void 0;
const throttler_storage_interface_1 = require("./throttler-storage.interface");
const throttler_constants_1 = require("./throttler.constants");
const throttler_service_1 = require("./throttler.service");
function createThrottlerProviders(options) {
return [
{
provide: throttler_constants_1.THROTTLER_OPTIONS,
useValue: options,
},
];
}
exports.createThrottlerProviders = createThrottlerProviders;
exports.ThrottlerStorageProvider = {
provide: throttler_storage_interface_1.ThrottlerStorage,
useFactory: (options) => {
return options.storage ? options.storage : new throttler_service_1.ThrottlerStorageService();
},
inject: [throttler_constants_1.THROTTLER_OPTIONS],
};
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

View File

@@ -0,0 +1 @@
{"version":3,"file":"throttler.providers.js","sourceRoot":"","sources":["../src/throttler.providers.ts"],"names":[],"mappings":";;;AAEA,+EAAiE;AACjE,+DAA0D;AAC1D,2DAA8D;AAE9D,SAAgB,wBAAwB,CAAC,OAA+B;IACtE,OAAO;QACL;YACE,OAAO,EAAE,uCAAiB;YAC1B,QAAQ,EAAE,OAAO;SAClB;KACF,CAAC;AACJ,CAAC;AAPD,4DAOC;AAEY,QAAA,wBAAwB,GAAG;IACtC,OAAO,EAAE,8CAAgB;IACzB,UAAU,EAAE,CAAC,OAA+B,EAAE,EAAE;QAC9C,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,2CAAuB,EAAE,CAAC;IAC3E,CAAC;IACD,MAAM,EAAE,CAAC,uCAAiB,CAAC;CAC5B,CAAC;AAMK,MAAM,eAAe,GAAG,GAAG,EAAE,CAAC,uCAAiB,CAAC;AAA1C,QAAA,eAAe,mBAA2B;AAMhD,MAAM,eAAe,GAAG,GAAG,EAAE,CAAC,8CAAgB,CAAC;AAAzC,QAAA,eAAe,mBAA0B"}

View File

@@ -0,0 +1,13 @@
import { OnApplicationShutdown } from '@nestjs/common';
import { ThrottlerStorageOptions } from './throttler-storage-options.interface';
import { ThrottlerStorageRecord } from './throttler-storage-record.interface';
import { ThrottlerStorage } from './throttler-storage.interface';
export declare class ThrottlerStorageService implements ThrottlerStorage, OnApplicationShutdown {
private _storage;
private timeoutIds;
get storage(): Record<string, ThrottlerStorageOptions>;
private getExpirationTime;
private setExpirationTime;
increment(key: string, ttl: number): Promise<ThrottlerStorageRecord>;
onApplicationShutdown(): void;
}

View File

@@ -0,0 +1,54 @@
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ThrottlerStorageService = void 0;
const common_1 = require("@nestjs/common");
let ThrottlerStorageService = exports.ThrottlerStorageService = class ThrottlerStorageService {
constructor() {
this._storage = {};
this.timeoutIds = [];
}
get storage() {
return this._storage;
}
getExpirationTime(key) {
return Math.floor((this.storage[key].expiresAt - Date.now()) / 1000);
}
setExpirationTime(key, ttlMilliseconds) {
const timeoutId = setTimeout(() => {
this.storage[key].totalHits--;
clearTimeout(timeoutId);
this.timeoutIds = this.timeoutIds.filter((id) => id != timeoutId);
}, ttlMilliseconds);
this.timeoutIds.push(timeoutId);
}
async increment(key, ttl) {
const ttlMilliseconds = ttl * 1000;
if (!this.storage[key]) {
this.storage[key] = { totalHits: 0, expiresAt: Date.now() + ttlMilliseconds };
}
let timeToExpire = this.getExpirationTime(key);
if (timeToExpire <= 0) {
this.storage[key].expiresAt = Date.now() + ttlMilliseconds;
timeToExpire = this.getExpirationTime(key);
}
this.storage[key].totalHits++;
this.setExpirationTime(key, ttlMilliseconds);
return {
totalHits: this.storage[key].totalHits,
timeToExpire,
};
}
onApplicationShutdown() {
this.timeoutIds.forEach(clearTimeout);
}
};
exports.ThrottlerStorageService = ThrottlerStorageService = __decorate([
(0, common_1.Injectable)()
], ThrottlerStorageService);
//# sourceMappingURL=throttler.service.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"throttler.service.js","sourceRoot":"","sources":["../src/throttler.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAmE;AAS5D,IAAM,uBAAuB,qCAA7B,MAAM,uBAAuB;IAA7B;QACG,aAAQ,GAA4C,EAAE,CAAC;QACvD,eAAU,GAAqB,EAAE,CAAC;IAmD5C,CAAC;IAjDC,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAKO,iBAAiB,CAAC,GAAW;QACnC,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;IACvE,CAAC;IAKO,iBAAiB,CAAC,GAAW,EAAE,eAAuB;QAC5D,MAAM,SAAS,GAAG,UAAU,CAAC,GAAG,EAAE;YAChC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,CAAC;YAC9B,YAAY,CAAC,SAAS,CAAC,CAAC;YACxB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,IAAI,SAAS,CAAC,CAAC;QACpE,CAAC,EAAE,eAAe,CAAC,CAAC;QACpB,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAClC,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,GAAW,EAAE,GAAW;QACtC,MAAM,eAAe,GAAG,GAAG,GAAG,IAAI,CAAC;QACnC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;YACtB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,SAAS,EAAE,CAAC,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,eAAe,EAAE,CAAC;SAC/E;QAED,IAAI,YAAY,GAAG,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC;QAG/C,IAAI,YAAY,IAAI,CAAC,EAAE;YACrB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,eAAe,CAAC;YAC3D,YAAY,GAAG,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC;SAC5C;QAED,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,CAAC;QAC9B,IAAI,CAAC,iBAAiB,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC;QAE7C,OAAO;YACL,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,SAAS;YACtC,YAAY;SACb,CAAC;IACJ,CAAC;IAED,qBAAqB;QACnB,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IACxC,CAAC;CACF,CAAA;kCArDY,uBAAuB;IADnC,IAAA,mBAAU,GAAE;GACA,uBAAuB,CAqDnC"}

File diff suppressed because one or more lines are too long

126
backend/node_modules/@nestjs/throttler/package.json generated vendored Normal file
View File

@@ -0,0 +1,126 @@
{
"name": "@nestjs/throttler",
"version": "4.2.1",
"description": "A Rate-Limiting module for NestJS to work on Express, Fastify, Websockets, Socket.IO, and GraphQL, all rolled up into a simple package.",
"author": "Jay McDoniel <me@jaymcdoniel.dev>",
"contributors": [],
"keywords": [
"nestjs",
"rate-limit",
"throttle",
"express",
"fastify",
"ws",
"gql",
"nest"
],
"publishConfig": {
"access": "public"
},
"private": false,
"license": "MIT",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist"
],
"dependencies": {
"md5": "^2.2.1"
},
"devDependencies": {
"@changesets/cli": "2.26.2",
"@commitlint/cli": "17.6.6",
"@commitlint/config-angular": "17.6.6",
"@nestjs/cli": "10.1.7",
"@nestjs/common": "10.0.5",
"@nestjs/core": "10.0.5",
"@nestjs/graphql": "12.0.7",
"@nestjs/platform-express": "10.0.5",
"@nestjs/platform-fastify": "10.0.5",
"@nestjs/platform-socket.io": "10.0.5",
"@nestjs/platform-ws": "10.0.5",
"@nestjs/schematics": "10.0.1",
"@nestjs/testing": "10.0.5",
"@nestjs/websockets": "10.0.5",
"@semantic-release/git": "10.0.1",
"@types/express": "4.17.17",
"@types/express-serve-static-core": "4.17.35",
"@types/jest": "29.5.2",
"@types/md5": "2.3.2",
"@types/node": "18.16.19",
"@types/supertest": "2.0.12",
"@typescript-eslint/eslint-plugin": "5.61.0",
"@typescript-eslint/parser": "5.61.0",
"@apollo/server": "4.7.5",
"apollo-server-fastify": "3.12.0",
"conventional-changelog-cli": "3.0.0",
"cz-conventional-changelog": "3.3.0",
"eslint": "8.44.0",
"eslint-config-prettier": "8.8.0",
"eslint-plugin-import": "2.27.5",
"graphql": "16.7.1",
"graphql-tools": "9.0.0",
"husky": "8.0.3",
"jest": "29.6.1",
"lint-staged": "13.2.3",
"nodemon": "2.0.22",
"pinst": "3.0.0",
"prettier": "3.0.0",
"reflect-metadata": "0.1.13",
"rimraf": "5.0.1",
"rxjs": "7.8.1",
"socket.io": "4.7.1",
"supertest": "6.3.3",
"ts-jest": "29.1.1",
"ts-loader": "9.4.4",
"ts-node": "10.9.1",
"tsconfig-paths": "4.2.0",
"typescript": "5.1.6",
"ws": "8.13.0"
},
"peerDependencies": {
"@nestjs/common": "^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0",
"@nestjs/core": "^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0",
"reflect-metadata": "^0.1.13"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"coverageDirectory": "../coverage",
"testEnvironment": "node"
},
"repository": {
"type": "git",
"url": "git+https://github.com/nestjs/throttler.git"
},
"bugs": {
"url": "https://github.com/nestjs/throttler/issues"
},
"homepage": "https://github.com/nestjs/throttler#readme",
"scripts": {
"prebuild": "rimraf dist",
"preversion": "yarn run format && yarn run lint && yarn build",
"build": "nest build",
"commit": "git-cz",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start:dev": "nodemon --watch '{src,test/app}/**/*.ts' --ignore '**/*.spec.ts' --exec 'ts-node' test/app/main.ts",
"lint": "eslint \"{src,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json --detectOpenHandles",
"test:e2e:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --config test/jest-e2e.json --runInBand",
"test:e2e:dev": "yarn test:e2e --watchAll",
"_postinstall": "husky install",
"release": "changeset publish"
}
}