@nestjs/throttler 1.1.3 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -31,9 +31,14 @@ For an overview of the community storage providers, see [Community Storage Provi
31
31
 
32
32
  This package comes with a couple of goodies that should be mentioned, first is the `ThrottlerModule`.
33
33
 
34
+ ## Versions
35
+
36
+ `@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.
37
+
34
38
  ## Table of Contents
35
39
 
36
40
  - [Description](#description)
41
+ - [Versions](#versions)
37
42
  - [Table of Contents](#table-of-contents)
38
43
  - [Usage](#usage)
39
44
  - [ThrottlerModule](#throttlermodule)
@@ -58,7 +63,7 @@ how many times an endpoint can be hit before returning a 429.
58
63
 
59
64
  ```ts
60
65
  import { APP_GUARD } from '@nestjs/core';
61
- import { ThrottlerGuard, ThrottlerModule } from 'nestjs-throttler';
66
+ import { ThrottlerGuard, ThrottlerModule } from '@nestjs/throttler';
62
67
 
63
68
  @Module({
64
69
  imports: [
package/dist/index.js CHANGED
@@ -1,24 +1,47 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
- };
12
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ 'use strict';
2
+ var __createBinding =
3
+ (this && this.__createBinding) ||
4
+ (Object.create
5
+ ? function (o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ Object.defineProperty(o, k2, {
8
+ enumerable: true,
9
+ get: function () {
10
+ return m[k];
11
+ },
12
+ });
13
+ }
14
+ : function (o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ o[k2] = m[k];
17
+ });
18
+ var __exportStar =
19
+ (this && this.__exportStar) ||
20
+ function (m, exports) {
21
+ for (var p in m)
22
+ if (p !== 'default' && !Object.prototype.hasOwnProperty.call(exports, p))
23
+ __createBinding(exports, m, p);
24
+ };
25
+ Object.defineProperty(exports, '__esModule', { value: true });
13
26
  exports.getStorageToken = exports.getOptionsToken = void 0;
14
- __exportStar(require("./throttler-module-options.interface"), exports);
15
- __exportStar(require("./throttler-storage.interface"), exports);
16
- __exportStar(require("./throttler.decorator"), exports);
17
- __exportStar(require("./throttler.exception"), exports);
18
- __exportStar(require("./throttler.guard"), exports);
19
- __exportStar(require("./throttler.module"), exports);
20
- var throttler_providers_1 = require("./throttler.providers");
21
- Object.defineProperty(exports, "getOptionsToken", { enumerable: true, get: function () { return throttler_providers_1.getOptionsToken; } });
22
- Object.defineProperty(exports, "getStorageToken", { enumerable: true, get: function () { return throttler_providers_1.getStorageToken; } });
23
- __exportStar(require("./throttler.service"), exports);
24
- //# sourceMappingURL=index.js.map
27
+ __exportStar(require('./throttler-module-options.interface'), exports);
28
+ __exportStar(require('./throttler-storage.interface'), exports);
29
+ __exportStar(require('./throttler.decorator'), exports);
30
+ __exportStar(require('./throttler.exception'), exports);
31
+ __exportStar(require('./throttler.guard'), exports);
32
+ __exportStar(require('./throttler.module'), exports);
33
+ var throttler_providers_1 = require('./throttler.providers');
34
+ Object.defineProperty(exports, 'getOptionsToken', {
35
+ enumerable: true,
36
+ get: function () {
37
+ return throttler_providers_1.getOptionsToken;
38
+ },
39
+ });
40
+ Object.defineProperty(exports, 'getStorageToken', {
41
+ enumerable: true,
42
+ get: function () {
43
+ return throttler_providers_1.getStorageToken;
44
+ },
45
+ });
46
+ __exportStar(require('./throttler.service'), exports);
47
+ //# sourceMappingURL=index.js.map
@@ -1,3 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=throttler-module-options.interface.js.map
1
+ 'use strict';
2
+ Object.defineProperty(exports, '__esModule', { value: true });
3
+ //# sourceMappingURL=throttler-module-options.interface.js.map
@@ -1,5 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ 'use strict';
2
+ Object.defineProperty(exports, '__esModule', { value: true });
3
3
  exports.ThrottlerStorage = void 0;
4
4
  exports.ThrottlerStorage = Symbol('ThrottlerStorage');
5
- //# sourceMappingURL=throttler-storage.interface.js.map
5
+ //# sourceMappingURL=throttler-storage.interface.js.map
@@ -1,8 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.THROTTLER_SKIP = exports.THROTTLER_OPTIONS = exports.THROTTLER_TTL = exports.THROTTLER_LIMIT = void 0;
1
+ 'use strict';
2
+ Object.defineProperty(exports, '__esModule', { value: true });
3
+ exports.THROTTLER_SKIP =
4
+ exports.THROTTLER_OPTIONS =
5
+ exports.THROTTLER_TTL =
6
+ exports.THROTTLER_LIMIT =
7
+ void 0;
4
8
  exports.THROTTLER_LIMIT = 'THROTTLER:LIMIT';
5
9
  exports.THROTTLER_TTL = 'THROTTLER:TTL';
6
10
  exports.THROTTLER_OPTIONS = 'THROTTLER:MODULE_OPTIONS';
7
11
  exports.THROTTLER_SKIP = 'THROTTLER:SKIP';
8
- //# sourceMappingURL=throttler.constants.js.map
12
+ //# sourceMappingURL=throttler.constants.js.map
@@ -1,37 +1,41 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InjectThrottlerStorage = exports.InjectThrottlerOptions = exports.SkipThrottle = exports.Throttle = void 0;
4
- const common_1 = require("@nestjs/common");
5
- const throttler_constants_1 = require("./throttler.constants");
6
- const throttler_providers_1 = require("./throttler.providers");
1
+ 'use strict';
2
+ Object.defineProperty(exports, '__esModule', { value: true });
3
+ exports.InjectThrottlerStorage =
4
+ exports.InjectThrottlerOptions =
5
+ exports.SkipThrottle =
6
+ exports.Throttle =
7
+ void 0;
8
+ const common_1 = require('@nestjs/common');
9
+ const throttler_constants_1 = require('./throttler.constants');
10
+ const throttler_providers_1 = require('./throttler.providers');
7
11
  function setThrottlerMetadata(target, limit, ttl) {
8
- Reflect.defineMetadata(throttler_constants_1.THROTTLER_TTL, ttl, target);
9
- Reflect.defineMetadata(throttler_constants_1.THROTTLER_LIMIT, limit, target);
12
+ Reflect.defineMetadata(throttler_constants_1.THROTTLER_TTL, ttl, target);
13
+ Reflect.defineMetadata(throttler_constants_1.THROTTLER_LIMIT, limit, target);
10
14
  }
11
15
  const Throttle = (limit = 20, ttl = 60) => {
12
- return (target, propertyKey, descriptor) => {
13
- if (descriptor) {
14
- setThrottlerMetadata(descriptor.value, limit, ttl);
15
- return descriptor;
16
- }
17
- setThrottlerMetadata(target, limit, ttl);
18
- return target;
19
- };
16
+ return (target, propertyKey, descriptor) => {
17
+ if (descriptor) {
18
+ setThrottlerMetadata(descriptor.value, limit, ttl);
19
+ return descriptor;
20
+ }
21
+ setThrottlerMetadata(target, limit, ttl);
22
+ return target;
23
+ };
20
24
  };
21
25
  exports.Throttle = Throttle;
22
26
  const SkipThrottle = (skip = true) => {
23
- return (target, propertyKey, descriptor) => {
24
- if (descriptor) {
25
- Reflect.defineMetadata(throttler_constants_1.THROTTLER_SKIP, skip, descriptor.value);
26
- return descriptor;
27
- }
28
- Reflect.defineMetadata(throttler_constants_1.THROTTLER_SKIP, skip, target);
29
- return target;
30
- };
27
+ return (target, propertyKey, descriptor) => {
28
+ if (descriptor) {
29
+ Reflect.defineMetadata(throttler_constants_1.THROTTLER_SKIP, skip, descriptor.value);
30
+ return descriptor;
31
+ }
32
+ Reflect.defineMetadata(throttler_constants_1.THROTTLER_SKIP, skip, target);
33
+ return target;
34
+ };
31
35
  };
32
36
  exports.SkipThrottle = SkipThrottle;
33
37
  const InjectThrottlerOptions = () => common_1.Inject(throttler_providers_1.getOptionsToken());
34
38
  exports.InjectThrottlerOptions = InjectThrottlerOptions;
35
39
  const InjectThrottlerStorage = () => common_1.Inject(throttler_providers_1.getStorageToken());
36
40
  exports.InjectThrottlerStorage = InjectThrottlerStorage;
37
- //# sourceMappingURL=throttler.decorator.js.map
41
+ //# sourceMappingURL=throttler.decorator.js.map
@@ -1,12 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ 'use strict';
2
+ Object.defineProperty(exports, '__esModule', { value: true });
3
3
  exports.ThrottlerException = exports.throttlerMessage = void 0;
4
- const common_1 = require("@nestjs/common");
4
+ const common_1 = require('@nestjs/common');
5
5
  exports.throttlerMessage = 'ThrottlerException: Too Many Requests';
6
6
  class ThrottlerException extends common_1.HttpException {
7
- constructor(message) {
8
- super(`${message || exports.throttlerMessage}`, common_1.HttpStatus.TOO_MANY_REQUESTS);
9
- }
7
+ constructor(message) {
8
+ super(`${message || exports.throttlerMessage}`, common_1.HttpStatus.TOO_MANY_REQUESTS);
9
+ }
10
10
  }
11
11
  exports.ThrottlerException = ThrottlerException;
12
- //# sourceMappingURL=throttler.exception.js.map
12
+ //# sourceMappingURL=throttler.exception.js.map
@@ -17,4 +17,5 @@ export declare class ThrottlerGuard implements CanActivate {
17
17
  res: Record<string, any>;
18
18
  };
19
19
  protected generateKey(context: ExecutionContext, suffix: string): string;
20
+ protected throwThrottlingException(context: ExecutionContext): void;
20
21
  }
@@ -1,91 +1,119 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- 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;
1
+ 'use strict';
2
+ var __decorate =
3
+ (this && this.__decorate) ||
4
+ function (decorators, target, key, desc) {
5
+ var c = arguments.length,
6
+ r =
7
+ c < 3
8
+ ? target
9
+ : desc === null
10
+ ? (desc = Object.getOwnPropertyDescriptor(target, key))
11
+ : desc,
12
+ d;
13
+ if (typeof Reflect === 'object' && typeof Reflect.decorate === 'function')
14
+ r = Reflect.decorate(decorators, target, key, desc);
15
+ else
16
+ for (var i = decorators.length - 1; i >= 0; i--)
17
+ if ((d = decorators[i]))
18
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
19
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- var __param = (this && this.__param) || function (paramIndex, decorator) {
12
- return function (target, key) { decorator(target, key, paramIndex); }
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
20
+ };
21
+ var __metadata =
22
+ (this && this.__metadata) ||
23
+ function (k, v) {
24
+ if (typeof Reflect === 'object' && typeof Reflect.metadata === 'function')
25
+ return Reflect.metadata(k, v);
26
+ };
27
+ var __param =
28
+ (this && this.__param) ||
29
+ function (paramIndex, decorator) {
30
+ return function (target, key) {
31
+ decorator(target, key, paramIndex);
32
+ };
33
+ };
34
+ Object.defineProperty(exports, '__esModule', { value: true });
15
35
  exports.ThrottlerGuard = void 0;
16
- const common_1 = require("@nestjs/common");
17
- const core_1 = require("@nestjs/core");
18
- const md5 = require("md5");
19
- const throttler_storage_interface_1 = require("./throttler-storage.interface");
20
- const throttler_constants_1 = require("./throttler.constants");
21
- const throttler_decorator_1 = require("./throttler.decorator");
22
- const throttler_exception_1 = require("./throttler.exception");
36
+ const common_1 = require('@nestjs/common');
37
+ const core_1 = require('@nestjs/core');
38
+ const md5 = require('md5');
39
+ const throttler_storage_interface_1 = require('./throttler-storage.interface');
40
+ const throttler_constants_1 = require('./throttler.constants');
41
+ const throttler_decorator_1 = require('./throttler.decorator');
42
+ const throttler_exception_1 = require('./throttler.exception');
23
43
  let ThrottlerGuard = class ThrottlerGuard {
24
- constructor(options, storageService, reflector) {
25
- this.options = options;
26
- this.storageService = storageService;
27
- this.reflector = reflector;
28
- this.headerPrefix = 'X-RateLimit';
29
- this.errorMessage = throttler_exception_1.throttlerMessage;
30
- }
31
- async canActivate(context) {
32
- const handler = context.getHandler();
33
- const classRef = context.getClass();
34
- if (this.reflector.getAllAndOverride(throttler_constants_1.THROTTLER_SKIP, [handler, classRef])) {
35
- return true;
36
- }
37
- const routeOrClassLimit = this.reflector.getAllAndOverride(throttler_constants_1.THROTTLER_LIMIT, [
38
- handler,
39
- classRef,
40
- ]);
41
- const routeOrClassTtl = this.reflector.getAllAndOverride(throttler_constants_1.THROTTLER_TTL, [
42
- handler,
43
- classRef,
44
- ]);
45
- const limit = routeOrClassLimit || this.options.limit;
46
- const ttl = routeOrClassTtl || this.options.ttl;
47
- return this.handleRequest(context, limit, ttl);
44
+ constructor(options, storageService, reflector) {
45
+ this.options = options;
46
+ this.storageService = storageService;
47
+ this.reflector = reflector;
48
+ this.headerPrefix = 'X-RateLimit';
49
+ this.errorMessage = throttler_exception_1.throttlerMessage;
50
+ }
51
+ async canActivate(context) {
52
+ const handler = context.getHandler();
53
+ const classRef = context.getClass();
54
+ if (
55
+ this.reflector.getAllAndOverride(throttler_constants_1.THROTTLER_SKIP, [handler, classRef])
56
+ ) {
57
+ return true;
48
58
  }
49
- async handleRequest(context, limit, ttl) {
50
- const { req, res } = this.getRequestResponse(context);
51
- if (Array.isArray(this.options.ignoreUserAgents)) {
52
- for (const pattern of this.options.ignoreUserAgents) {
53
- if (pattern.test(req.headers['user-agent'])) {
54
- return true;
55
- }
56
- }
57
- }
58
- const tracker = this.getTracker(req);
59
- const key = this.generateKey(context, tracker);
60
- const ttls = await this.storageService.getRecord(key);
61
- const nearestExpiryTime = ttls.length > 0 ? Math.ceil((ttls[0] - Date.now()) / 1000) : 0;
62
- if (ttls.length >= limit) {
63
- res.header('Retry-After', nearestExpiryTime);
64
- throw new throttler_exception_1.ThrottlerException(this.errorMessage);
59
+ const routeOrClassLimit = this.reflector.getAllAndOverride(
60
+ throttler_constants_1.THROTTLER_LIMIT,
61
+ [handler, classRef],
62
+ );
63
+ const routeOrClassTtl = this.reflector.getAllAndOverride(throttler_constants_1.THROTTLER_TTL, [
64
+ handler,
65
+ classRef,
66
+ ]);
67
+ const limit = routeOrClassLimit || this.options.limit;
68
+ const ttl = routeOrClassTtl || this.options.ttl;
69
+ return this.handleRequest(context, limit, ttl);
70
+ }
71
+ async handleRequest(context, limit, ttl) {
72
+ const { req, res } = this.getRequestResponse(context);
73
+ if (Array.isArray(this.options.ignoreUserAgents)) {
74
+ for (const pattern of this.options.ignoreUserAgents) {
75
+ if (pattern.test(req.headers['user-agent'])) {
76
+ return true;
65
77
  }
66
- res.header(`${this.headerPrefix}-Limit`, limit);
67
- res.header(`${this.headerPrefix}-Remaining`, Math.max(0, limit - (ttls.length + 1)));
68
- res.header(`${this.headerPrefix}-Reset`, nearestExpiryTime);
69
- await this.storageService.addRecord(key, ttl);
70
- return true;
71
- }
72
- getTracker(req) {
73
- return req.ip;
74
- }
75
- getRequestResponse(context) {
76
- const http = context.switchToHttp();
77
- return { req: http.getRequest(), res: http.getResponse() };
78
+ }
78
79
  }
79
- generateKey(context, suffix) {
80
- const prefix = `${context.getClass().name}-${context.getHandler().name}`;
81
- return md5(`${prefix}-${suffix}`);
80
+ const tracker = this.getTracker(req);
81
+ const key = this.generateKey(context, tracker);
82
+ const ttls = await this.storageService.getRecord(key);
83
+ const nearestExpiryTime = ttls.length > 0 ? Math.ceil((ttls[0] - Date.now()) / 1000) : 0;
84
+ if (ttls.length >= limit) {
85
+ res.header('Retry-After', nearestExpiryTime);
86
+ this.throwThrottlingException(context);
82
87
  }
88
+ res.header(`${this.headerPrefix}-Limit`, limit);
89
+ res.header(`${this.headerPrefix}-Remaining`, Math.max(0, limit - (ttls.length + 1)));
90
+ res.header(`${this.headerPrefix}-Reset`, nearestExpiryTime);
91
+ await this.storageService.addRecord(key, ttl);
92
+ return true;
93
+ }
94
+ getTracker(req) {
95
+ return req.ip;
96
+ }
97
+ getRequestResponse(context) {
98
+ const http = context.switchToHttp();
99
+ return { req: http.getRequest(), res: http.getResponse() };
100
+ }
101
+ generateKey(context, suffix) {
102
+ const prefix = `${context.getClass().name}-${context.getHandler().name}`;
103
+ return md5(`${prefix}-${suffix}`);
104
+ }
105
+ throwThrottlingException(context) {
106
+ throw new throttler_exception_1.ThrottlerException(this.errorMessage);
107
+ }
83
108
  };
84
- ThrottlerGuard = __decorate([
109
+ ThrottlerGuard = __decorate(
110
+ [
85
111
  common_1.Injectable(),
86
112
  __param(0, throttler_decorator_1.InjectThrottlerOptions()),
87
113
  __param(1, throttler_decorator_1.InjectThrottlerStorage()),
88
- __metadata("design:paramtypes", [Object, Object, core_1.Reflector])
89
- ], ThrottlerGuard);
114
+ __metadata('design:paramtypes', [Object, Object, core_1.Reflector]),
115
+ ],
116
+ ThrottlerGuard,
117
+ );
90
118
  exports.ThrottlerGuard = ThrottlerGuard;
91
- //# sourceMappingURL=throttler.guard.js.map
119
+ //# sourceMappingURL=throttler.guard.js.map
@@ -1 +1 @@
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;AAM7E,IAAa,cAAc,GAA3B,MAAa,cAAc;IAGzB,YAC+C,OAA+B,EAC/B,cAAgC,EAC1D,SAAoB;QAFM,YAAO,GAAP,OAAO,CAAwB;QAC/B,mBAAc,GAAd,cAAc,CAAkB;QAC1D,cAAS,GAAT,SAAS,CAAW;QAL/B,iBAAY,GAAG,aAAa,CAAC;QAC7B,iBAAY,GA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AG,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;AAlHY,cAAc;IAD1B,mBAAU,EAAE;IAKR,WAAA,4CAAsB,EAAE,CAAA;IACxB,WAAA,4CAAsB,EAAE,CAAA;qDACK,gBAAS;GAN9B,cAAc,CAkH1B;AAlHY,wCAAc"}
@@ -1,64 +1,83 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- 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;
1
+ 'use strict';
2
+ var __decorate =
3
+ (this && this.__decorate) ||
4
+ function (decorators, target, key, desc) {
5
+ var c = arguments.length,
6
+ r =
7
+ c < 3
8
+ ? target
9
+ : desc === null
10
+ ? (desc = Object.getOwnPropertyDescriptor(target, key))
11
+ : desc,
12
+ d;
13
+ if (typeof Reflect === 'object' && typeof Reflect.decorate === 'function')
14
+ r = Reflect.decorate(decorators, target, key, desc);
15
+ else
16
+ for (var i = decorators.length - 1; i >= 0; i--)
17
+ if ((d = decorators[i]))
18
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
19
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
20
+ };
8
21
  var ThrottlerModule_1;
9
- Object.defineProperty(exports, "__esModule", { value: true });
22
+ Object.defineProperty(exports, '__esModule', { value: true });
10
23
  exports.ThrottlerModule = void 0;
11
- const common_1 = require("@nestjs/common");
12
- const throttler_constants_1 = require("./throttler.constants");
13
- const throttler_providers_1 = require("./throttler.providers");
14
- let ThrottlerModule = ThrottlerModule_1 = class ThrottlerModule {
15
- static forRoot(options = {}) {
16
- const providers = [...throttler_providers_1.createThrottlerProviders(options), throttler_providers_1.ThrottlerStorageProvider];
17
- return {
18
- module: ThrottlerModule_1,
19
- providers,
20
- exports: providers,
21
- };
24
+ const common_1 = require('@nestjs/common');
25
+ const throttler_constants_1 = require('./throttler.constants');
26
+ const throttler_providers_1 = require('./throttler.providers');
27
+ let ThrottlerModule = (ThrottlerModule_1 = class ThrottlerModule {
28
+ static forRoot(options = {}) {
29
+ const providers = [
30
+ ...throttler_providers_1.createThrottlerProviders(options),
31
+ throttler_providers_1.ThrottlerStorageProvider,
32
+ ];
33
+ return {
34
+ module: ThrottlerModule_1,
35
+ providers,
36
+ exports: providers,
37
+ };
38
+ }
39
+ static forRootAsync(options) {
40
+ const providers = [
41
+ ...this.createAsyncProviders(options),
42
+ throttler_providers_1.ThrottlerStorageProvider,
43
+ ];
44
+ return {
45
+ module: ThrottlerModule_1,
46
+ imports: options.imports || [],
47
+ providers,
48
+ exports: providers,
49
+ };
50
+ }
51
+ static createAsyncProviders(options) {
52
+ if (options.useExisting || options.useFactory) {
53
+ return [this.createAsyncOptionsProvider(options)];
22
54
  }
23
- static forRootAsync(options) {
24
- const providers = [...this.createAsyncProviders(options), throttler_providers_1.ThrottlerStorageProvider];
25
- return {
26
- module: ThrottlerModule_1,
27
- imports: options.imports || [],
28
- providers,
29
- exports: providers,
30
- };
55
+ return [
56
+ this.createAsyncOptionsProvider(options),
57
+ {
58
+ provide: options.useClass,
59
+ useClass: options.useClass,
60
+ },
61
+ ];
62
+ }
63
+ static createAsyncOptionsProvider(options) {
64
+ if (options.useFactory) {
65
+ return {
66
+ provide: throttler_constants_1.THROTTLER_OPTIONS,
67
+ useFactory: options.useFactory,
68
+ inject: options.inject || [],
69
+ };
31
70
  }
32
- static createAsyncProviders(options) {
33
- if (options.useExisting || options.useFactory) {
34
- return [this.createAsyncOptionsProvider(options)];
35
- }
36
- return [
37
- this.createAsyncOptionsProvider(options),
38
- {
39
- provide: options.useClass,
40
- useClass: options.useClass,
41
- },
42
- ];
43
- }
44
- static createAsyncOptionsProvider(options) {
45
- if (options.useFactory) {
46
- return {
47
- provide: throttler_constants_1.THROTTLER_OPTIONS,
48
- useFactory: options.useFactory,
49
- inject: options.inject || [],
50
- };
51
- }
52
- return {
53
- provide: throttler_constants_1.THROTTLER_OPTIONS,
54
- useFactory: async (optionsFactory) => await optionsFactory.createThrottlerOptions(),
55
- inject: [options.useExisting || options.useClass],
56
- };
57
- }
58
- };
59
- ThrottlerModule = ThrottlerModule_1 = __decorate([
60
- common_1.Global(),
61
- common_1.Module({})
62
- ], ThrottlerModule);
71
+ return {
72
+ provide: throttler_constants_1.THROTTLER_OPTIONS,
73
+ useFactory: async (optionsFactory) => await optionsFactory.createThrottlerOptions(),
74
+ inject: [options.useExisting || options.useClass],
75
+ };
76
+ }
77
+ });
78
+ ThrottlerModule = ThrottlerModule_1 = __decorate(
79
+ [common_1.Global(), common_1.Module({})],
80
+ ThrottlerModule,
81
+ );
63
82
  exports.ThrottlerModule = ThrottlerModule;
64
- //# sourceMappingURL=throttler.module.js.map
83
+ //# sourceMappingURL=throttler.module.js.map
@@ -1,27 +1,31 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getStorageToken = exports.getOptionsToken = exports.ThrottlerStorageProvider = exports.createThrottlerProviders = void 0;
4
- const throttler_storage_interface_1 = require("./throttler-storage.interface");
5
- const throttler_constants_1 = require("./throttler.constants");
6
- const throttler_service_1 = require("./throttler.service");
1
+ 'use strict';
2
+ Object.defineProperty(exports, '__esModule', { value: true });
3
+ exports.getStorageToken =
4
+ exports.getOptionsToken =
5
+ exports.ThrottlerStorageProvider =
6
+ exports.createThrottlerProviders =
7
+ void 0;
8
+ const throttler_storage_interface_1 = require('./throttler-storage.interface');
9
+ const throttler_constants_1 = require('./throttler.constants');
10
+ const throttler_service_1 = require('./throttler.service');
7
11
  function createThrottlerProviders(options) {
8
- return [
9
- {
10
- provide: throttler_constants_1.THROTTLER_OPTIONS,
11
- useValue: options,
12
- },
13
- ];
12
+ return [
13
+ {
14
+ provide: throttler_constants_1.THROTTLER_OPTIONS,
15
+ useValue: options,
16
+ },
17
+ ];
14
18
  }
15
19
  exports.createThrottlerProviders = createThrottlerProviders;
16
20
  exports.ThrottlerStorageProvider = {
17
- provide: throttler_storage_interface_1.ThrottlerStorage,
18
- useFactory: (options) => {
19
- return options.storage ? options.storage : new throttler_service_1.ThrottlerStorageService();
20
- },
21
- inject: [throttler_constants_1.THROTTLER_OPTIONS],
21
+ provide: throttler_storage_interface_1.ThrottlerStorage,
22
+ useFactory: (options) => {
23
+ return options.storage ? options.storage : new throttler_service_1.ThrottlerStorageService();
24
+ },
25
+ inject: [throttler_constants_1.THROTTLER_OPTIONS],
22
26
  };
23
27
  const getOptionsToken = () => throttler_constants_1.THROTTLER_OPTIONS;
24
28
  exports.getOptionsToken = getOptionsToken;
25
29
  const getStorageToken = () => throttler_storage_interface_1.ThrottlerStorage;
26
30
  exports.getStorageToken = getStorageToken;
27
- //# sourceMappingURL=throttler.providers.js.map
31
+ //# sourceMappingURL=throttler.providers.js.map