nestjs-security-cli 1.5.8 → 1.5.10
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 +12 -49
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,15 +18,13 @@ import { SecurityModule, BlacklistedIp, BlacklistedIpSchema, SecurityMiddleware
|
|
|
18
18
|
@Module( {
|
|
19
19
|
imports: [
|
|
20
20
|
SecurityModule.forRootAsync( {
|
|
21
|
-
enableAdminPanel: true,
|
|
21
|
+
enableAdminPanel: true,
|
|
22
22
|
useFactory: () => ({
|
|
23
23
|
enableDatabase: true,
|
|
24
24
|
defaultBlockDurationHours: 24,
|
|
25
25
|
enableAutoBlocking: true
|
|
26
26
|
}),
|
|
27
|
-
|
|
28
|
-
// Below required if enableDatabase is true
|
|
29
|
-
imports: [ MongoDbModule ], // This should be your mongoose connection
|
|
27
|
+
imports: [ MongoDbModule ],
|
|
30
28
|
providers: [ ...IpBlockerProvider ]
|
|
31
29
|
} )
|
|
32
30
|
]
|
|
@@ -45,7 +43,7 @@ export class AppModule {
|
|
|
45
43
|
if you're needing to use the database connection, and the import options isn't working, you can try to pass it directly
|
|
46
44
|
into the providers array.
|
|
47
45
|
|
|
48
|
-
```
|
|
46
|
+
```text
|
|
49
47
|
{
|
|
50
48
|
provide: 'DATABASE_CONNECTION',
|
|
51
49
|
inject: [ConfigService],
|
|
@@ -126,7 +124,7 @@ There's a cron that runs to clean up old blocks. By default, it runs every 10 mi
|
|
|
126
124
|
the
|
|
127
125
|
`CLEANUP_CRON` environment variable.
|
|
128
126
|
|
|
129
|
-
```
|
|
127
|
+
```text
|
|
130
128
|
// Cleanup expired entries (runs daily)
|
|
131
129
|
@Cron(CronExpression.EVERY_DAY_AT_MIDNIGHT)
|
|
132
130
|
async cleanupExpiredBlocks(): Promise<void> {
|
|
@@ -138,44 +136,14 @@ the
|
|
|
138
136
|
}
|
|
139
137
|
```
|
|
140
138
|
|
|
141
|
-
##
|
|
139
|
+
## Role type
|
|
142
140
|
|
|
143
141
|
The roles that can be defined in your app. Persist the roles in your user model as an array of strings.
|
|
144
142
|
|
|
145
|
-
```
|
|
143
|
+
```text
|
|
146
144
|
export type Role = 'Admin' | 'User' | 'Moderator' | 'Guest'
|
|
147
145
|
```
|
|
148
146
|
|
|
149
|
-
## Config Options
|
|
150
|
-
|
|
151
|
-
```typescript
|
|
152
|
-
export interface SecurityConfigInterface {
|
|
153
|
-
enableDatabase?: boolean
|
|
154
|
-
mongooseConnection?: string
|
|
155
|
-
cache?: {
|
|
156
|
-
ttl?: number
|
|
157
|
-
max?: number
|
|
158
|
-
store?: any
|
|
159
|
-
}
|
|
160
|
-
enableAdminPanel?: boolean
|
|
161
|
-
adminPath?: string
|
|
162
|
-
enableAutoBlocking?: boolean
|
|
163
|
-
suspiciousPatterns?: Array<{
|
|
164
|
-
pattern: string
|
|
165
|
-
name: string
|
|
166
|
-
blockDurationHours?: number
|
|
167
|
-
}>
|
|
168
|
-
defaultBlockDurationHours?: number
|
|
169
|
-
enableRateLimit?: boolean
|
|
170
|
-
rateLimitOptions?: {
|
|
171
|
-
windowMs?: number
|
|
172
|
-
max?: number
|
|
173
|
-
}
|
|
174
|
-
enableLogging?: boolean
|
|
175
|
-
logLevel?: 'error' | 'warn' | 'info' | 'debug'
|
|
176
|
-
}
|
|
177
|
-
```
|
|
178
|
-
|
|
179
147
|
## Register the IpBlacklistGuard globally
|
|
180
148
|
|
|
181
149
|
```typescript
|
|
@@ -203,9 +171,9 @@ And then in your controllers simply use the `@UseGuards(IpBlacklistGuard)` decor
|
|
|
203
171
|
## Admin & Roles guards
|
|
204
172
|
|
|
205
173
|
* The Admin guard accepts ONLY users with the role `Admin`.
|
|
206
|
-
* The Role guard accepts users with ane of (or all) the type "Roles" [as mentioned above](#
|
|
174
|
+
* The Role guard accepts users with ane of (or all) the type "Roles" [as mentioned above](#role-type).
|
|
207
175
|
* To leverage the admin panel, you'll need to create a role called `Admin`. The user model in your app should have a
|
|
208
|
-
field called "Roles" which is an array of strings.
|
|
176
|
+
field called "Roles", which is an array of strings.
|
|
209
177
|
|
|
210
178
|
To use the `AdminGuard` just add the decorator to your controller method.
|
|
211
179
|
|
|
@@ -233,10 +201,10 @@ const user = await this.jwtService.verifyAsync( token, {
|
|
|
233
201
|
} )
|
|
234
202
|
```
|
|
235
203
|
|
|
236
|
-
## The
|
|
204
|
+
## The admin panel
|
|
237
205
|
|
|
238
|
-
To use the built
|
|
239
|
-
configs [as shown in the](#quick-start)
|
|
206
|
+
To use the built-in admin panel, you can set the `enableAdminPanel: true` in the
|
|
207
|
+
configs [as shown in the](#quick-start) to set the available endpoints.
|
|
240
208
|
|
|
241
209
|
Available endpoints:
|
|
242
210
|
|
|
@@ -300,9 +268,4 @@ export interface SecurityConfigInterface {
|
|
|
300
268
|
|
|
301
269
|
## License
|
|
302
270
|
|
|
303
|
-
MIT
|
|
304
|
-
|
|
305
|
-
## Donate
|
|
306
|
-
|
|
307
|
-
If you like this project, please
|
|
308
|
-
consider [donating to help me keep it up to date](https://buy.stripe.com/eVq00l2Dc4k05Bz9pY4Rq00)
|
|
271
|
+
MIT
|
package/package.json
CHANGED