@edirect/rate-limit-module 11.0.47 → 11.0.49
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 +119 -34
- package/dist/README.md +119 -34
- package/dist/package.json +10 -10
- package/dist/src/rate-limiting.module.d.ts +3 -0
- package/dist/src/rate-limiting.module.d.ts.map +1 -1
- package/dist/src/rate-limiting.module.js +17 -22
- package/dist/src/rules/rule.module.d.ts +1 -1
- package/dist/src/rules/rule.module.d.ts.map +1 -1
- package/dist/src/rules/rule.module.js +10 -12
- package/dist/src/rules/rule.schema.d.ts +16 -16
- package/dist/src/shared/dsl/dsl.service.d.ts.map +1 -1
- package/dist/src/shared/rule-engine/rule-engine.module.d.ts.map +1 -1
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -1,79 +1,164 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @edirect/rate-limit-module
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A flexible **rate-limiting system** where access to operations can be restricted based on dynamic **rule expressions** such as `count_quote( ) > 1`. If the condition evaluates to `true`, access is **blocked**.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Installation
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
```sh
|
|
8
|
+
pnpm add @edirect/rate-limit-module
|
|
9
|
+
# or
|
|
10
|
+
npm install @edirect/rate-limit-module
|
|
11
|
+
```
|
|
8
12
|
|
|
9
|
-
|
|
13
|
+
---
|
|
10
14
|
|
|
11
|
-
|
|
15
|
+
## 🚀 Quick Start
|
|
12
16
|
|
|
13
|
-
|
|
17
|
+
### 1. Create a Global Database Connection Module
|
|
14
18
|
|
|
15
|
-
|
|
19
|
+
**Important:** This module requires a MongoDB connection provider. Create a global module to provide it:
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
// db-provider.module.ts
|
|
23
|
+
import { Global, Module } from '@nestjs/common';
|
|
24
|
+
import { Connection } from 'mongoose';
|
|
25
|
+
import { MongoDBConnection } from './mongodb-connection';
|
|
26
|
+
|
|
27
|
+
export const dbProvider = [
|
|
28
|
+
{
|
|
29
|
+
provide: 'DATABASE_CONNECTION',
|
|
30
|
+
useFactory: async (): Promise<Connection> => {
|
|
31
|
+
return new MongoDBConnection().connect();
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
];
|
|
16
35
|
|
|
17
|
-
|
|
36
|
+
@Global()
|
|
37
|
+
@Module({
|
|
38
|
+
providers: [...dbProvider],
|
|
39
|
+
exports: [...dbProvider],
|
|
40
|
+
})
|
|
41
|
+
export class DbProviderModule {}
|
|
42
|
+
```
|
|
18
43
|
|
|
19
|
-
2.
|
|
44
|
+
### 2. Import Database Module in Root Module
|
|
20
45
|
|
|
21
|
-
|
|
46
|
+
```ts
|
|
47
|
+
// app.module.ts
|
|
48
|
+
import { Module } from '@nestjs/common';
|
|
49
|
+
import { DbProviderModule } from './db-provider.module';
|
|
22
50
|
|
|
23
|
-
|
|
51
|
+
@Module({
|
|
52
|
+
imports: [
|
|
53
|
+
DbProviderModule, // Must be imported first
|
|
54
|
+
// ... other modules
|
|
55
|
+
],
|
|
56
|
+
})
|
|
57
|
+
export class AppModule {}
|
|
58
|
+
```
|
|
24
59
|
|
|
25
|
-
###
|
|
60
|
+
### 3. Import RateLimitingModule in Feature Module
|
|
26
61
|
|
|
27
62
|
```ts
|
|
63
|
+
import {
|
|
64
|
+
RateLimitingModule,
|
|
65
|
+
RuleEngineModule,
|
|
66
|
+
} from '@edirect/rate-limit-module';
|
|
67
|
+
|
|
28
68
|
@Module({
|
|
29
69
|
imports: [
|
|
30
|
-
|
|
70
|
+
// Pass the token name of your existing MongoDB connection provider
|
|
71
|
+
// Default is 'DATABASE_CONNECTION'
|
|
72
|
+
RateLimitingModule.forRoot('DATABASE_CONNECTION'),
|
|
73
|
+
|
|
74
|
+
// Or use a custom token
|
|
75
|
+
RateLimitingModule.forRoot('MY_CUSTOM_DB_CONNECTION'),
|
|
31
76
|
|
|
77
|
+
// Or omit to use default
|
|
78
|
+
RateLimitingModule.forRoot(),
|
|
79
|
+
|
|
80
|
+
// Configure custom functions for rule evaluation
|
|
32
81
|
RuleEngineModule.forFeatureAsync({
|
|
33
|
-
|
|
34
|
-
|
|
82
|
+
imports: [YourFunctionsModule],
|
|
83
|
+
useFactory: async (useCase: YourInjectFunctionsUseCase) => {
|
|
84
|
+
return await useCase.getFunctions();
|
|
35
85
|
},
|
|
36
|
-
|
|
37
|
-
inject: [QuoteService],
|
|
86
|
+
inject: [YourInjectFunctionsUseCase],
|
|
38
87
|
}),
|
|
39
88
|
],
|
|
40
89
|
})
|
|
41
90
|
export class YourFeatureModule {}
|
|
42
91
|
```
|
|
43
92
|
|
|
44
|
-
|
|
93
|
+
### 2. Database Connection Requirement
|
|
45
94
|
|
|
46
|
-
|
|
95
|
+
The module uses the global `DATABASE_CONNECTION` provider created in step 1. It references your connection using the token name, so it doesn't duplicate the connection.
|
|
96
|
+
|
|
97
|
+
### 3. Apply Rate Limiting to Routes
|
|
98
|
+
|
|
99
|
+
Use the `@RateLimitingRuleMetadata` decorator and `@UseGuards(RateLimitingRuleGuard)` to protect your endpoints:
|
|
47
100
|
|
|
48
101
|
```ts
|
|
102
|
+
import { RateLimitingRuleGuard, RateLimitingRuleMetadata } from '@edirect/rate-limit-module';
|
|
49
103
|
|
|
50
|
-
|
|
104
|
+
@RateLimitingRuleMetadata({
|
|
105
|
+
action: 'create_quote',
|
|
106
|
+
partnerPath: 'partner.partnerId',
|
|
107
|
+
providerPath: 'provider',
|
|
108
|
+
productTypePath: 'productType',
|
|
109
|
+
marketPath: 'market',
|
|
110
|
+
})
|
|
111
|
+
@UseGuards(RateLimitingRuleGuard)
|
|
112
|
+
@Post('quotes')
|
|
113
|
+
createQuote(@Body() body: CreateQuoteDto) {
|
|
114
|
+
return this.quoteService.create(body);
|
|
115
|
+
}
|
|
116
|
+
```
|
|
51
117
|
|
|
118
|
+
## ✨ Features
|
|
52
119
|
|
|
120
|
+
- Define rate-limiting rules with custom expressions
|
|
121
|
+
- Dynamically inject context-aware functions for rule evaluation
|
|
122
|
+
- Easily integrate with any resource via decorators
|
|
123
|
+
- Uses existing MongoDB connection (no separate connection required)
|
|
124
|
+
- Global module - configure once, use everywhere
|
|
125
|
+
- Built with extensibility and modularity in mind
|
|
53
126
|
|
|
54
|
-
|
|
127
|
+
## 🧱 How It Works
|
|
55
128
|
|
|
56
|
-
|
|
129
|
+
1. You define a rule using a simple expression (e.g., `count_quote( ) > 1`)
|
|
130
|
+
2. The rule is evaluated at runtime using data injected from the request context
|
|
131
|
+
3. If the expression is true, the action is blocked
|
|
57
132
|
|
|
58
|
-
|
|
133
|
+
## 🛠 Architecture
|
|
59
134
|
|
|
60
|
-
|
|
135
|
+
The module is designed to:
|
|
61
136
|
|
|
62
|
-
|
|
137
|
+
- **Not create its own MongoDB connection** - it uses the application's existing connection
|
|
138
|
+
- **Be a global module** - providers are available throughout the application
|
|
139
|
+
- **Use custom model providers** - creates Mongoose models using the injected `DATABASE_CONNECTION`
|
|
140
|
+
- **Export Reflector** - ensures guards have access to metadata
|
|
63
141
|
|
|
64
|
-
|
|
142
|
+
## 📝 Configuration Details
|
|
65
143
|
|
|
66
|
-
|
|
144
|
+
### Module Structure
|
|
67
145
|
|
|
68
|
-
|
|
146
|
+
```ts
|
|
147
|
+
RateLimitingModule.forRoot(dbProvider) // Global module, accepts DATABASE_CONNECTION provider
|
|
148
|
+
└─ RuleModule.register() // Provides RuleService and RuleRepository
|
|
149
|
+
└─ Custom Model Provider // Uses DATABASE_CONNECTION to create Mongoose models
|
|
150
|
+
```
|
|
69
151
|
|
|
70
|
-
|
|
152
|
+
### Required Providers
|
|
71
153
|
|
|
72
|
-
|
|
154
|
+
The module requires:
|
|
73
155
|
|
|
74
|
-
|
|
156
|
+
1. **DATABASE_CONNECTION**: Mongoose connection instance
|
|
157
|
+
2. **Reflector**: For metadata reflection (provided by the module)
|
|
158
|
+
3. **RuleService**: For accessing rate limiting rules (exported by RuleModule)
|
|
75
159
|
|
|
76
|
-
|
|
160
|
+
````ts
|
|
161
|
+
import { RateLimitingRuleMetadata } from 'path-to-rate-limiting-module';
|
|
77
162
|
|
|
78
163
|
- `action`: Name of the action to be controlled.
|
|
79
164
|
|
|
@@ -97,7 +182,7 @@ RuleEngineModule.forFeatureAsync({
|
|
|
97
182
|
|
|
98
183
|
inject: [RateLimitingInjectFunctionsUseCase],
|
|
99
184
|
});
|
|
100
|
-
|
|
185
|
+
````
|
|
101
186
|
|
|
102
187
|
## 🧪 Example Rule
|
|
103
188
|
|
package/dist/README.md
CHANGED
|
@@ -1,79 +1,164 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @edirect/rate-limit-module
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A flexible **rate-limiting system** where access to operations can be restricted based on dynamic **rule expressions** such as `count_quote( ) > 1`. If the condition evaluates to `true`, access is **blocked**.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Installation
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
```sh
|
|
8
|
+
pnpm add @edirect/rate-limit-module
|
|
9
|
+
# or
|
|
10
|
+
npm install @edirect/rate-limit-module
|
|
11
|
+
```
|
|
8
12
|
|
|
9
|
-
|
|
13
|
+
---
|
|
10
14
|
|
|
11
|
-
|
|
15
|
+
## 🚀 Quick Start
|
|
12
16
|
|
|
13
|
-
|
|
17
|
+
### 1. Create a Global Database Connection Module
|
|
14
18
|
|
|
15
|
-
|
|
19
|
+
**Important:** This module requires a MongoDB connection provider. Create a global module to provide it:
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
// db-provider.module.ts
|
|
23
|
+
import { Global, Module } from '@nestjs/common';
|
|
24
|
+
import { Connection } from 'mongoose';
|
|
25
|
+
import { MongoDBConnection } from './mongodb-connection';
|
|
26
|
+
|
|
27
|
+
export const dbProvider = [
|
|
28
|
+
{
|
|
29
|
+
provide: 'DATABASE_CONNECTION',
|
|
30
|
+
useFactory: async (): Promise<Connection> => {
|
|
31
|
+
return new MongoDBConnection().connect();
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
];
|
|
16
35
|
|
|
17
|
-
|
|
36
|
+
@Global()
|
|
37
|
+
@Module({
|
|
38
|
+
providers: [...dbProvider],
|
|
39
|
+
exports: [...dbProvider],
|
|
40
|
+
})
|
|
41
|
+
export class DbProviderModule {}
|
|
42
|
+
```
|
|
18
43
|
|
|
19
|
-
2.
|
|
44
|
+
### 2. Import Database Module in Root Module
|
|
20
45
|
|
|
21
|
-
|
|
46
|
+
```ts
|
|
47
|
+
// app.module.ts
|
|
48
|
+
import { Module } from '@nestjs/common';
|
|
49
|
+
import { DbProviderModule } from './db-provider.module';
|
|
22
50
|
|
|
23
|
-
|
|
51
|
+
@Module({
|
|
52
|
+
imports: [
|
|
53
|
+
DbProviderModule, // Must be imported first
|
|
54
|
+
// ... other modules
|
|
55
|
+
],
|
|
56
|
+
})
|
|
57
|
+
export class AppModule {}
|
|
58
|
+
```
|
|
24
59
|
|
|
25
|
-
###
|
|
60
|
+
### 3. Import RateLimitingModule in Feature Module
|
|
26
61
|
|
|
27
62
|
```ts
|
|
63
|
+
import {
|
|
64
|
+
RateLimitingModule,
|
|
65
|
+
RuleEngineModule,
|
|
66
|
+
} from '@edirect/rate-limit-module';
|
|
67
|
+
|
|
28
68
|
@Module({
|
|
29
69
|
imports: [
|
|
30
|
-
|
|
70
|
+
// Pass the token name of your existing MongoDB connection provider
|
|
71
|
+
// Default is 'DATABASE_CONNECTION'
|
|
72
|
+
RateLimitingModule.forRoot('DATABASE_CONNECTION'),
|
|
73
|
+
|
|
74
|
+
// Or use a custom token
|
|
75
|
+
RateLimitingModule.forRoot('MY_CUSTOM_DB_CONNECTION'),
|
|
31
76
|
|
|
77
|
+
// Or omit to use default
|
|
78
|
+
RateLimitingModule.forRoot(),
|
|
79
|
+
|
|
80
|
+
// Configure custom functions for rule evaluation
|
|
32
81
|
RuleEngineModule.forFeatureAsync({
|
|
33
|
-
|
|
34
|
-
|
|
82
|
+
imports: [YourFunctionsModule],
|
|
83
|
+
useFactory: async (useCase: YourInjectFunctionsUseCase) => {
|
|
84
|
+
return await useCase.getFunctions();
|
|
35
85
|
},
|
|
36
|
-
|
|
37
|
-
inject: [QuoteService],
|
|
86
|
+
inject: [YourInjectFunctionsUseCase],
|
|
38
87
|
}),
|
|
39
88
|
],
|
|
40
89
|
})
|
|
41
90
|
export class YourFeatureModule {}
|
|
42
91
|
```
|
|
43
92
|
|
|
44
|
-
|
|
93
|
+
### 2. Database Connection Requirement
|
|
45
94
|
|
|
46
|
-
|
|
95
|
+
The module uses the global `DATABASE_CONNECTION` provider created in step 1. It references your connection using the token name, so it doesn't duplicate the connection.
|
|
96
|
+
|
|
97
|
+
### 3. Apply Rate Limiting to Routes
|
|
98
|
+
|
|
99
|
+
Use the `@RateLimitingRuleMetadata` decorator and `@UseGuards(RateLimitingRuleGuard)` to protect your endpoints:
|
|
47
100
|
|
|
48
101
|
```ts
|
|
102
|
+
import { RateLimitingRuleGuard, RateLimitingRuleMetadata } from '@edirect/rate-limit-module';
|
|
49
103
|
|
|
50
|
-
|
|
104
|
+
@RateLimitingRuleMetadata({
|
|
105
|
+
action: 'create_quote',
|
|
106
|
+
partnerPath: 'partner.partnerId',
|
|
107
|
+
providerPath: 'provider',
|
|
108
|
+
productTypePath: 'productType',
|
|
109
|
+
marketPath: 'market',
|
|
110
|
+
})
|
|
111
|
+
@UseGuards(RateLimitingRuleGuard)
|
|
112
|
+
@Post('quotes')
|
|
113
|
+
createQuote(@Body() body: CreateQuoteDto) {
|
|
114
|
+
return this.quoteService.create(body);
|
|
115
|
+
}
|
|
116
|
+
```
|
|
51
117
|
|
|
118
|
+
## ✨ Features
|
|
52
119
|
|
|
120
|
+
- Define rate-limiting rules with custom expressions
|
|
121
|
+
- Dynamically inject context-aware functions for rule evaluation
|
|
122
|
+
- Easily integrate with any resource via decorators
|
|
123
|
+
- Uses existing MongoDB connection (no separate connection required)
|
|
124
|
+
- Global module - configure once, use everywhere
|
|
125
|
+
- Built with extensibility and modularity in mind
|
|
53
126
|
|
|
54
|
-
|
|
127
|
+
## 🧱 How It Works
|
|
55
128
|
|
|
56
|
-
|
|
129
|
+
1. You define a rule using a simple expression (e.g., `count_quote( ) > 1`)
|
|
130
|
+
2. The rule is evaluated at runtime using data injected from the request context
|
|
131
|
+
3. If the expression is true, the action is blocked
|
|
57
132
|
|
|
58
|
-
|
|
133
|
+
## 🛠 Architecture
|
|
59
134
|
|
|
60
|
-
|
|
135
|
+
The module is designed to:
|
|
61
136
|
|
|
62
|
-
|
|
137
|
+
- **Not create its own MongoDB connection** - it uses the application's existing connection
|
|
138
|
+
- **Be a global module** - providers are available throughout the application
|
|
139
|
+
- **Use custom model providers** - creates Mongoose models using the injected `DATABASE_CONNECTION`
|
|
140
|
+
- **Export Reflector** - ensures guards have access to metadata
|
|
63
141
|
|
|
64
|
-
|
|
142
|
+
## 📝 Configuration Details
|
|
65
143
|
|
|
66
|
-
|
|
144
|
+
### Module Structure
|
|
67
145
|
|
|
68
|
-
|
|
146
|
+
```ts
|
|
147
|
+
RateLimitingModule.forRoot(dbProvider) // Global module, accepts DATABASE_CONNECTION provider
|
|
148
|
+
└─ RuleModule.register() // Provides RuleService and RuleRepository
|
|
149
|
+
└─ Custom Model Provider // Uses DATABASE_CONNECTION to create Mongoose models
|
|
150
|
+
```
|
|
69
151
|
|
|
70
|
-
|
|
152
|
+
### Required Providers
|
|
71
153
|
|
|
72
|
-
|
|
154
|
+
The module requires:
|
|
73
155
|
|
|
74
|
-
|
|
156
|
+
1. **DATABASE_CONNECTION**: Mongoose connection instance
|
|
157
|
+
2. **Reflector**: For metadata reflection (provided by the module)
|
|
158
|
+
3. **RuleService**: For accessing rate limiting rules (exported by RuleModule)
|
|
75
159
|
|
|
76
|
-
|
|
160
|
+
````ts
|
|
161
|
+
import { RateLimitingRuleMetadata } from 'path-to-rate-limiting-module';
|
|
77
162
|
|
|
78
163
|
- `action`: Name of the action to be controlled.
|
|
79
164
|
|
|
@@ -97,7 +182,7 @@ RuleEngineModule.forFeatureAsync({
|
|
|
97
182
|
|
|
98
183
|
inject: [RateLimitingInjectFunctionsUseCase],
|
|
99
184
|
});
|
|
100
|
-
|
|
185
|
+
````
|
|
101
186
|
|
|
102
187
|
## 🧪 Example Rule
|
|
103
188
|
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@edirect/rate-limit-module",
|
|
3
|
-
"version": "11.0.
|
|
3
|
+
"version": "11.0.48",
|
|
4
4
|
"main": "./dist/src/index.js",
|
|
5
5
|
"types": "./dist/src/index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -16,21 +16,21 @@
|
|
|
16
16
|
"dist"
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@edirect/auth": "^11.0.
|
|
20
|
-
"@edirect/logger": "^11.0.
|
|
19
|
+
"@edirect/auth": "^11.0.48",
|
|
20
|
+
"@edirect/logger": "^11.0.48",
|
|
21
21
|
"@nestjs/cache-manager": "^3.1.0",
|
|
22
|
-
"@nestjs/common": "^11.1.
|
|
23
|
-
"@nestjs/config": "^4.0.
|
|
24
|
-
"@nestjs/core": "^11.1.
|
|
22
|
+
"@nestjs/common": "^11.1.16",
|
|
23
|
+
"@nestjs/config": "^4.0.3",
|
|
24
|
+
"@nestjs/core": "^11.1.16",
|
|
25
25
|
"@nestjs/mongoose": "^11.0.4",
|
|
26
|
-
"@nestjs/swagger": "^11.2.
|
|
26
|
+
"@nestjs/swagger": "^11.2.6",
|
|
27
27
|
"cache-manager-redis-store": "^3.0.1",
|
|
28
28
|
"class-transformer": "^0.5.1",
|
|
29
|
-
"class-validator": "^0.
|
|
29
|
+
"class-validator": "^0.15.1",
|
|
30
30
|
"dayjs": "^1.11.19",
|
|
31
|
-
"ioredis": "^5.
|
|
31
|
+
"ioredis": "^5.10.0",
|
|
32
32
|
"jexl": "^2.3.0",
|
|
33
|
-
"mongoose": "^9.
|
|
33
|
+
"mongoose": "^9.3.0",
|
|
34
34
|
"tslib": "^2.8.1",
|
|
35
35
|
"uuid": "^13.0.0"
|
|
36
36
|
},
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { DynamicModule } from '@nestjs/common';
|
|
2
|
+
export declare const RATE_LIMIT_DB_CONNECTION = "RATE_LIMIT_DB_CONNECTION";
|
|
1
3
|
export declare class RateLimitingModule {
|
|
4
|
+
static forRoot(connectionToken?: string): DynamicModule;
|
|
2
5
|
}
|
|
3
6
|
//# sourceMappingURL=rate-limiting.module.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rate-limiting.module.d.ts","sourceRoot":"","sources":["../../src/rate-limiting.module.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rate-limiting.module.d.ts","sourceRoot":"","sources":["../../src/rate-limiting.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,aAAa,EAAU,MAAM,gBAAgB,CAAC;AAK/D,eAAO,MAAM,wBAAwB,6BAA6B,CAAC;AAEnE,qBAEa,kBAAkB;IAC7B,MAAM,CAAC,OAAO,CACZ,eAAe,SAAwB,GACtC,aAAa;CASjB"}
|
|
@@ -1,31 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var RateLimitingModule_1;
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RateLimitingModule = void 0;
|
|
4
|
+
exports.RateLimitingModule = exports.RATE_LIMIT_DB_CONNECTION = void 0;
|
|
4
5
|
const tslib_1 = require("tslib");
|
|
5
6
|
const common_1 = require("@nestjs/common");
|
|
6
|
-
const
|
|
7
|
-
const mongoose_1 = require("@nestjs/mongoose");
|
|
7
|
+
const core_1 = require("@nestjs/core");
|
|
8
8
|
const rule_module_1 = require("./rules/rule.module");
|
|
9
9
|
const rule_constraint_1 = require("./validators/rule.constraint");
|
|
10
|
-
|
|
10
|
+
exports.RATE_LIMIT_DB_CONNECTION = 'RATE_LIMIT_DB_CONNECTION';
|
|
11
|
+
let RateLimitingModule = RateLimitingModule_1 = class RateLimitingModule {
|
|
12
|
+
static forRoot(connectionToken = 'DATABASE_CONNECTION') {
|
|
13
|
+
return {
|
|
14
|
+
global: true,
|
|
15
|
+
module: RateLimitingModule_1,
|
|
16
|
+
imports: [rule_module_1.RuleModule.register(connectionToken)],
|
|
17
|
+
providers: [core_1.Reflector, rule_constraint_1.IsValidExpressionConstraint],
|
|
18
|
+
exports: [rule_module_1.RuleModule, core_1.Reflector],
|
|
19
|
+
};
|
|
20
|
+
}
|
|
11
21
|
};
|
|
12
22
|
exports.RateLimitingModule = RateLimitingModule;
|
|
13
|
-
exports.RateLimitingModule = RateLimitingModule = tslib_1.__decorate([
|
|
14
|
-
(0, common_1.
|
|
15
|
-
|
|
16
|
-
rule_module_1.RuleModule.register(),
|
|
17
|
-
config_1.ConfigModule.forRoot({
|
|
18
|
-
isGlobal: true,
|
|
19
|
-
}),
|
|
20
|
-
mongoose_1.MongooseModule.forRootAsync({
|
|
21
|
-
imports: [config_1.ConfigModule],
|
|
22
|
-
useFactory: async (config) => ({
|
|
23
|
-
uri: config.get('MONGO_URL'),
|
|
24
|
-
}),
|
|
25
|
-
inject: [config_1.ConfigService],
|
|
26
|
-
}),
|
|
27
|
-
],
|
|
28
|
-
providers: [rule_constraint_1.IsValidExpressionConstraint],
|
|
29
|
-
exports: [rule_module_1.RuleModule],
|
|
30
|
-
})
|
|
23
|
+
exports.RateLimitingModule = RateLimitingModule = RateLimitingModule_1 = tslib_1.__decorate([
|
|
24
|
+
(0, common_1.Global)(),
|
|
25
|
+
(0, common_1.Module)({})
|
|
31
26
|
], RateLimitingModule);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rule.module.d.ts","sourceRoot":"","sources":["../../../src/rules/rule.module.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAU,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"rule.module.d.ts","sourceRoot":"","sources":["../../../src/rules/rule.module.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAU,MAAM,gBAAgB,CAAC;AASvD,qBACa,UAAU;IACrB,MAAM,CAAC,QAAQ,CAAC,eAAe,EAAE,MAAM,GAAG,aAAa;CAoBxD"}
|
|
@@ -12,22 +12,20 @@ const rule_repository_1 = require("./rule.repository");
|
|
|
12
12
|
const rule_schema_1 = require("./rule.schema");
|
|
13
13
|
const rule_service_1 = require("./rule.service");
|
|
14
14
|
let RuleModule = RuleModule_1 = class RuleModule {
|
|
15
|
-
static register() {
|
|
15
|
+
static register(connectionToken) {
|
|
16
16
|
const enableController = process.env.ENABLE_RATE_LIMITING_RULE_CONTROLLER === 'true';
|
|
17
|
+
const modelProvider = {
|
|
18
|
+
provide: (0, mongoose_1.getModelToken)(rule_schema_1.RateLimitingRule.name),
|
|
19
|
+
useFactory: (connection) => {
|
|
20
|
+
return connection.model(rule_schema_1.RateLimitingRule.name, rule_schema_1.RateLimitingRuleSchema);
|
|
21
|
+
},
|
|
22
|
+
inject: [connectionToken],
|
|
23
|
+
};
|
|
17
24
|
return {
|
|
18
25
|
module: RuleModule_1,
|
|
19
|
-
imports: [
|
|
20
|
-
logger_1.LoggerModule,
|
|
21
|
-
shared_module_1.SharedModule,
|
|
22
|
-
mongoose_1.MongooseModule.forFeature([
|
|
23
|
-
{
|
|
24
|
-
name: rule_schema_1.RateLimitingRule.name,
|
|
25
|
-
schema: rule_schema_1.RateLimitingRuleSchema,
|
|
26
|
-
},
|
|
27
|
-
]),
|
|
28
|
-
],
|
|
26
|
+
imports: [logger_1.LoggerModule, shared_module_1.SharedModule],
|
|
29
27
|
controllers: enableController ? [rule_controller_1.RuleController] : [],
|
|
30
|
-
providers: [rule_service_1.RuleService, rule_repository_1.RuleRepository],
|
|
28
|
+
providers: [modelProvider, rule_service_1.RuleService, rule_repository_1.RuleRepository],
|
|
31
29
|
exports: [rule_service_1.RuleService, rule_repository_1.RuleRepository],
|
|
32
30
|
};
|
|
33
31
|
}
|
|
@@ -30,7 +30,7 @@ export declare const RateLimitingRuleSchema: import("mongoose").Schema<RateLimit
|
|
|
30
30
|
__v: number;
|
|
31
31
|
}), any, RateLimitingRule>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, RateLimitingRule, Document<unknown, {}, RateLimitingRule, {
|
|
32
32
|
id: string;
|
|
33
|
-
}, import("mongoose").
|
|
33
|
+
}, import("mongoose").DefaultSchemaOptions> & Omit<RateLimitingRule & {
|
|
34
34
|
_id: import("mongoose").Types.ObjectId;
|
|
35
35
|
} & {
|
|
36
36
|
__v: number;
|
|
@@ -39,7 +39,7 @@ export declare const RateLimitingRuleSchema: import("mongoose").Schema<RateLimit
|
|
|
39
39
|
}, {
|
|
40
40
|
ruleId?: import("mongoose").SchemaDefinitionProperty<string, RateLimitingRule, Document<unknown, {}, RateLimitingRule, {
|
|
41
41
|
id: string;
|
|
42
|
-
}, import("mongoose").
|
|
42
|
+
}, import("mongoose").DefaultSchemaOptions> & Omit<RateLimitingRule & {
|
|
43
43
|
_id: import("mongoose").Types.ObjectId;
|
|
44
44
|
} & {
|
|
45
45
|
__v: number;
|
|
@@ -48,7 +48,7 @@ export declare const RateLimitingRuleSchema: import("mongoose").Schema<RateLimit
|
|
|
48
48
|
}> | undefined;
|
|
49
49
|
name?: import("mongoose").SchemaDefinitionProperty<string, RateLimitingRule, Document<unknown, {}, RateLimitingRule, {
|
|
50
50
|
id: string;
|
|
51
|
-
}, import("mongoose").
|
|
51
|
+
}, import("mongoose").DefaultSchemaOptions> & Omit<RateLimitingRule & {
|
|
52
52
|
_id: import("mongoose").Types.ObjectId;
|
|
53
53
|
} & {
|
|
54
54
|
__v: number;
|
|
@@ -57,7 +57,7 @@ export declare const RateLimitingRuleSchema: import("mongoose").Schema<RateLimit
|
|
|
57
57
|
}> | undefined;
|
|
58
58
|
targetAction?: import("mongoose").SchemaDefinitionProperty<string | undefined, RateLimitingRule, Document<unknown, {}, RateLimitingRule, {
|
|
59
59
|
id: string;
|
|
60
|
-
}, import("mongoose").
|
|
60
|
+
}, import("mongoose").DefaultSchemaOptions> & Omit<RateLimitingRule & {
|
|
61
61
|
_id: import("mongoose").Types.ObjectId;
|
|
62
62
|
} & {
|
|
63
63
|
__v: number;
|
|
@@ -66,7 +66,7 @@ export declare const RateLimitingRuleSchema: import("mongoose").Schema<RateLimit
|
|
|
66
66
|
}> | undefined;
|
|
67
67
|
expression?: import("mongoose").SchemaDefinitionProperty<string, RateLimitingRule, Document<unknown, {}, RateLimitingRule, {
|
|
68
68
|
id: string;
|
|
69
|
-
}, import("mongoose").
|
|
69
|
+
}, import("mongoose").DefaultSchemaOptions> & Omit<RateLimitingRule & {
|
|
70
70
|
_id: import("mongoose").Types.ObjectId;
|
|
71
71
|
} & {
|
|
72
72
|
__v: number;
|
|
@@ -75,7 +75,7 @@ export declare const RateLimitingRuleSchema: import("mongoose").Schema<RateLimit
|
|
|
75
75
|
}> | undefined;
|
|
76
76
|
enabled?: import("mongoose").SchemaDefinitionProperty<boolean, RateLimitingRule, Document<unknown, {}, RateLimitingRule, {
|
|
77
77
|
id: string;
|
|
78
|
-
}, import("mongoose").
|
|
78
|
+
}, import("mongoose").DefaultSchemaOptions> & Omit<RateLimitingRule & {
|
|
79
79
|
_id: import("mongoose").Types.ObjectId;
|
|
80
80
|
} & {
|
|
81
81
|
__v: number;
|
|
@@ -84,7 +84,7 @@ export declare const RateLimitingRuleSchema: import("mongoose").Schema<RateLimit
|
|
|
84
84
|
}> | undefined;
|
|
85
85
|
market?: import("mongoose").SchemaDefinitionProperty<string, RateLimitingRule, Document<unknown, {}, RateLimitingRule, {
|
|
86
86
|
id: string;
|
|
87
|
-
}, import("mongoose").
|
|
87
|
+
}, import("mongoose").DefaultSchemaOptions> & Omit<RateLimitingRule & {
|
|
88
88
|
_id: import("mongoose").Types.ObjectId;
|
|
89
89
|
} & {
|
|
90
90
|
__v: number;
|
|
@@ -93,7 +93,7 @@ export declare const RateLimitingRuleSchema: import("mongoose").Schema<RateLimit
|
|
|
93
93
|
}> | undefined;
|
|
94
94
|
errorMessage?: import("mongoose").SchemaDefinitionProperty<string | undefined, RateLimitingRule, Document<unknown, {}, RateLimitingRule, {
|
|
95
95
|
id: string;
|
|
96
|
-
}, import("mongoose").
|
|
96
|
+
}, import("mongoose").DefaultSchemaOptions> & Omit<RateLimitingRule & {
|
|
97
97
|
_id: import("mongoose").Types.ObjectId;
|
|
98
98
|
} & {
|
|
99
99
|
__v: number;
|
|
@@ -102,7 +102,7 @@ export declare const RateLimitingRuleSchema: import("mongoose").Schema<RateLimit
|
|
|
102
102
|
}> | undefined;
|
|
103
103
|
partner?: import("mongoose").SchemaDefinitionProperty<string, RateLimitingRule, Document<unknown, {}, RateLimitingRule, {
|
|
104
104
|
id: string;
|
|
105
|
-
}, import("mongoose").
|
|
105
|
+
}, import("mongoose").DefaultSchemaOptions> & Omit<RateLimitingRule & {
|
|
106
106
|
_id: import("mongoose").Types.ObjectId;
|
|
107
107
|
} & {
|
|
108
108
|
__v: number;
|
|
@@ -111,7 +111,7 @@ export declare const RateLimitingRuleSchema: import("mongoose").Schema<RateLimit
|
|
|
111
111
|
}> | undefined;
|
|
112
112
|
provider?: import("mongoose").SchemaDefinitionProperty<string | undefined, RateLimitingRule, Document<unknown, {}, RateLimitingRule, {
|
|
113
113
|
id: string;
|
|
114
|
-
}, import("mongoose").
|
|
114
|
+
}, import("mongoose").DefaultSchemaOptions> & Omit<RateLimitingRule & {
|
|
115
115
|
_id: import("mongoose").Types.ObjectId;
|
|
116
116
|
} & {
|
|
117
117
|
__v: number;
|
|
@@ -120,7 +120,7 @@ export declare const RateLimitingRuleSchema: import("mongoose").Schema<RateLimit
|
|
|
120
120
|
}> | undefined;
|
|
121
121
|
productType?: import("mongoose").SchemaDefinitionProperty<string | undefined, RateLimitingRule, Document<unknown, {}, RateLimitingRule, {
|
|
122
122
|
id: string;
|
|
123
|
-
}, import("mongoose").
|
|
123
|
+
}, import("mongoose").DefaultSchemaOptions> & Omit<RateLimitingRule & {
|
|
124
124
|
_id: import("mongoose").Types.ObjectId;
|
|
125
125
|
} & {
|
|
126
126
|
__v: number;
|
|
@@ -129,7 +129,7 @@ export declare const RateLimitingRuleSchema: import("mongoose").Schema<RateLimit
|
|
|
129
129
|
}> | undefined;
|
|
130
130
|
variables?: import("mongoose").SchemaDefinitionProperty<Record<string, string> | undefined, RateLimitingRule, Document<unknown, {}, RateLimitingRule, {
|
|
131
131
|
id: string;
|
|
132
|
-
}, import("mongoose").
|
|
132
|
+
}, import("mongoose").DefaultSchemaOptions> & Omit<RateLimitingRule & {
|
|
133
133
|
_id: import("mongoose").Types.ObjectId;
|
|
134
134
|
} & {
|
|
135
135
|
__v: number;
|
|
@@ -138,7 +138,7 @@ export declare const RateLimitingRuleSchema: import("mongoose").Schema<RateLimit
|
|
|
138
138
|
}> | undefined;
|
|
139
139
|
variablesRequired?: import("mongoose").SchemaDefinitionProperty<boolean | undefined, RateLimitingRule, Document<unknown, {}, RateLimitingRule, {
|
|
140
140
|
id: string;
|
|
141
|
-
}, import("mongoose").
|
|
141
|
+
}, import("mongoose").DefaultSchemaOptions> & Omit<RateLimitingRule & {
|
|
142
142
|
_id: import("mongoose").Types.ObjectId;
|
|
143
143
|
} & {
|
|
144
144
|
__v: number;
|
|
@@ -147,7 +147,7 @@ export declare const RateLimitingRuleSchema: import("mongoose").Schema<RateLimit
|
|
|
147
147
|
}> | undefined;
|
|
148
148
|
deletedAt?: import("mongoose").SchemaDefinitionProperty<Date | undefined, RateLimitingRule, Document<unknown, {}, RateLimitingRule, {
|
|
149
149
|
id: string;
|
|
150
|
-
}, import("mongoose").
|
|
150
|
+
}, import("mongoose").DefaultSchemaOptions> & Omit<RateLimitingRule & {
|
|
151
151
|
_id: import("mongoose").Types.ObjectId;
|
|
152
152
|
} & {
|
|
153
153
|
__v: number;
|
|
@@ -156,7 +156,7 @@ export declare const RateLimitingRuleSchema: import("mongoose").Schema<RateLimit
|
|
|
156
156
|
}> | undefined;
|
|
157
157
|
createdAt?: import("mongoose").SchemaDefinitionProperty<Date | undefined, RateLimitingRule, Document<unknown, {}, RateLimitingRule, {
|
|
158
158
|
id: string;
|
|
159
|
-
}, import("mongoose").
|
|
159
|
+
}, import("mongoose").DefaultSchemaOptions> & Omit<RateLimitingRule & {
|
|
160
160
|
_id: import("mongoose").Types.ObjectId;
|
|
161
161
|
} & {
|
|
162
162
|
__v: number;
|
|
@@ -165,7 +165,7 @@ export declare const RateLimitingRuleSchema: import("mongoose").Schema<RateLimit
|
|
|
165
165
|
}> | undefined;
|
|
166
166
|
updatedAt?: import("mongoose").SchemaDefinitionProperty<Date | undefined, RateLimitingRule, Document<unknown, {}, RateLimitingRule, {
|
|
167
167
|
id: string;
|
|
168
|
-
}, import("mongoose").
|
|
168
|
+
}, import("mongoose").DefaultSchemaOptions> & Omit<RateLimitingRule & {
|
|
169
169
|
_id: import("mongoose").Types.ObjectId;
|
|
170
170
|
} & {
|
|
171
171
|
__v: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dsl.service.d.ts","sourceRoot":"","sources":["../../../../src/shared/dsl/dsl.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAE3D,qBAAa,UAAU;;IACrB,MAAM,CAAC,WAAW,GAAI,OAAO,aAAa,EAAE,KAAG,SAAS,CAWtD;IAEF,MAAM,CAAC,YAAY,
|
|
1
|
+
{"version":3,"file":"dsl.service.d.ts","sourceRoot":"","sources":["../../../../src/shared/dsl/dsl.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAE3D,qBAAa,UAAU;;IACrB,MAAM,CAAC,WAAW,GAAI,OAAO,aAAa,EAAE,KAAG,SAAS,CAWtD;IAEF,MAAM,CAAC,YAAY,GAAI,QAAQ,SAAS,KAAG,WAAW,CAAC,aAAa,CAAC,CAqDnE;CAuBH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rule-engine.module.d.ts","sourceRoot":"","sources":["../../../../src/shared/rule-engine/rule-engine.module.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"rule-engine.module.d.ts","sourceRoot":"","sources":["../../../../src/shared/rule-engine/rule-engine.module.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAEb,cAAc,EAEd,yBAAyB,EAE1B,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAGlE,qBAEa,gBAAgB;IAC3B,MAAM,CAAC,eAAe,CAAC,OAAO,EAAE;QAC9B,UAAU,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;QACzD,MAAM,CAAC,EAAE,KAAK,CAAC,cAAc,GAAG,yBAAyB,CAAC,CAAC;QAC3D,OAAO,CAAC,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;KACpC,GAAG,aAAa;IAuBjB,MAAM,CAAC,UAAU,CAAC,SAAS,EAAE,aAAa,EAAE,GAAG,aAAa;CAkB7D"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@edirect/rate-limit-module",
|
|
3
|
-
"version": "11.0.
|
|
3
|
+
"version": "11.0.49",
|
|
4
4
|
"packageScope": "@edirect",
|
|
5
5
|
"main": "./dist/src/index.js",
|
|
6
6
|
"types": "./dist/src/index.d.ts",
|
|
@@ -18,22 +18,22 @@
|
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@nestjs/cache-manager": "^3.1.0",
|
|
21
|
-
"@nestjs/common": "^11.1.
|
|
22
|
-
"@nestjs/config": "^4.0.
|
|
23
|
-
"@nestjs/core": "^11.1.
|
|
21
|
+
"@nestjs/common": "^11.1.16",
|
|
22
|
+
"@nestjs/config": "^4.0.3",
|
|
23
|
+
"@nestjs/core": "^11.1.16",
|
|
24
24
|
"@nestjs/mongoose": "^11.0.4",
|
|
25
|
-
"@nestjs/swagger": "^11.2.
|
|
25
|
+
"@nestjs/swagger": "^11.2.6",
|
|
26
26
|
"cache-manager-redis-store": "^3.0.1",
|
|
27
27
|
"class-transformer": "^0.5.1",
|
|
28
|
-
"class-validator": "^0.
|
|
28
|
+
"class-validator": "^0.15.1",
|
|
29
29
|
"dayjs": "^1.11.19",
|
|
30
|
-
"ioredis": "^5.
|
|
30
|
+
"ioredis": "^5.10.0",
|
|
31
31
|
"jexl": "^2.3.0",
|
|
32
|
-
"mongoose": "^9.
|
|
32
|
+
"mongoose": "^9.3.0",
|
|
33
33
|
"tslib": "^2.8.1",
|
|
34
34
|
"uuid": "^13.0.0",
|
|
35
|
-
"@edirect/auth": "11.0.
|
|
36
|
-
"@edirect/logger": "11.0.
|
|
35
|
+
"@edirect/auth": "11.0.49",
|
|
36
|
+
"@edirect/logger": "11.0.49"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/jexl": "^2.3.4"
|