@universis/janitor 1.8.0 → 1.10.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 +106 -0
- package/dist/index.d.ts +46 -5
- package/dist/index.esm.js +446 -166
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +454 -172
- package/dist/index.js.map +1 -1
- package/package.json +6 -2
- package/public/schemas/v1/rate-limit-service.json +4 -4
- package/public/schemas/v1/speed-limit-service.json +4 -4
- package/src/AppRateLimitService.d.ts +5 -0
- package/src/AppRateLimitService.js +21 -0
- package/src/AppSpeedLimitService.d.ts +5 -0
- package/src/AppSpeedLimitService.js +21 -0
- package/src/RateLimitService.d.ts +20 -1
- package/src/RateLimitService.js +201 -70
- package/src/RedisClientStore.js +1 -1
- package/src/SpeedLimitService.d.ts +20 -2
- package/src/SpeedLimitService.js +207 -83
- package/src/index.d.ts +2 -0
- package/src/index.js +3 -1
- package/src/polyfills.js +0 -10
package/README.md
CHANGED
|
@@ -82,6 +82,57 @@ Rate limit headers will be available only if the request is made from the same o
|
|
|
82
82
|
}
|
|
83
83
|
```
|
|
84
84
|
|
|
85
|
+
## AppRateLimitService
|
|
86
|
+
|
|
87
|
+
`AppRateLimitService` is a configurable extension of [express-rate-limit](https://www.npmjs.com/package/express-rate-limit) for limiting service requests based on application settings.
|
|
88
|
+
`AppRateLimitService` is an alternative to `RateLimitService` that allows you to configure rate limits based on container paths instead of service paths. This allows you to configure rate limits for all services in a container.
|
|
89
|
+
|
|
90
|
+
You can register `AppRateLimitService` under application services:
|
|
91
|
+
|
|
92
|
+
```json
|
|
93
|
+
{
|
|
94
|
+
"services": [
|
|
95
|
+
{
|
|
96
|
+
"serviceType": "@universis/janitor#RateLimitService",
|
|
97
|
+
"strategyType": "@universis/janitor#AppRateLimitService"
|
|
98
|
+
}
|
|
99
|
+
]
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
The configuration should use the same structure as `RateLimitService` but under `settings/universis/rateLimit`:
|
|
104
|
+
|
|
105
|
+
```json
|
|
106
|
+
{
|
|
107
|
+
"settings": {
|
|
108
|
+
"universis": {
|
|
109
|
+
"appRateLimit": {
|
|
110
|
+
"profiles": [
|
|
111
|
+
[
|
|
112
|
+
"appRateLimitProfile",
|
|
113
|
+
{
|
|
114
|
+
"windowMs": 300000,
|
|
115
|
+
"limit": 50,
|
|
116
|
+
"legacyHeaders": true
|
|
117
|
+
}
|
|
118
|
+
]
|
|
119
|
+
],
|
|
120
|
+
"paths": [
|
|
121
|
+
[
|
|
122
|
+
"/api/users/me",
|
|
123
|
+
{
|
|
124
|
+
"profile": "appRateLimitProfile"
|
|
125
|
+
}
|
|
126
|
+
]
|
|
127
|
+
]
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
where paths are the container paths instead of service paths. The `AppRateLimitService` will apply the rate limit to all services in the container that match the path.
|
|
135
|
+
|
|
85
136
|
|
|
86
137
|
## SpeedLimitService
|
|
87
138
|
|
|
@@ -230,6 +281,61 @@ Speed limit headers will be available only if the request is made from the same
|
|
|
230
281
|
}
|
|
231
282
|
```
|
|
232
283
|
|
|
284
|
+
## AppSpeedLimitService
|
|
285
|
+
|
|
286
|
+
`AppSpeedLimitService` is a configurable extension of [express-slow-down](https://www.npmjs.com/package/express-slow-down) for slowing down service responses based on application settings.
|
|
287
|
+
|
|
288
|
+
`AppSpeedLimitService` is an alternative to `SpeedLimitService` that allows you to configure speed limits based on container paths instead of service paths. This allows you to configure speed limits for all services in a container.
|
|
289
|
+
|
|
290
|
+
You can register `AppSpeedLimitService` under application services:
|
|
291
|
+
|
|
292
|
+
```json
|
|
293
|
+
{
|
|
294
|
+
"services": [
|
|
295
|
+
{
|
|
296
|
+
"serviceType": "@universis/janitor#SpeedLimitService",
|
|
297
|
+
"strategyType": "@universis/janitor#AppSpeedLimitService"
|
|
298
|
+
}
|
|
299
|
+
]
|
|
300
|
+
}
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
The configuration should use the same structure as `SpeedLimitService` but under `settings/universis/speedLimit`:
|
|
304
|
+
|
|
305
|
+
```json
|
|
306
|
+
{
|
|
307
|
+
"settings": {
|
|
308
|
+
"universis": {
|
|
309
|
+
"appSpeedLimit": {
|
|
310
|
+
"profiles": [
|
|
311
|
+
[
|
|
312
|
+
"appSpeedLimitProfile",
|
|
313
|
+
{
|
|
314
|
+
"windowMs": 300000,
|
|
315
|
+
"delayAfter": 5,
|
|
316
|
+
"delayMs": 500,
|
|
317
|
+
"maxDelayMs": 20000,
|
|
318
|
+
"headers": true
|
|
319
|
+
}
|
|
320
|
+
]
|
|
321
|
+
],
|
|
322
|
+
"paths": [
|
|
323
|
+
[
|
|
324
|
+
"/api/users/me",
|
|
325
|
+
{
|
|
326
|
+
"profile": "appSpeedLimitProfile"
|
|
327
|
+
}
|
|
328
|
+
]
|
|
329
|
+
]
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
where paths are the container paths instead of service paths. The `AppSpeedLimitService` will apply the speed limit to all services in the container that match the path.
|
|
337
|
+
|
|
338
|
+
|
|
233
339
|
## ScopeAccessConfiguration
|
|
234
340
|
|
|
235
341
|
`ScopeAccessConfiguration` is a configurable application configuration strategy for limiting access to service endpoints based on user scopes.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,47 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as _themost_common from '@themost/common';
|
|
2
|
+
import { ApplicationService, ApplicationBase, ConfigurationStrategy, ConfigurationBase } from '@themost/common';
|
|
3
|
+
import { Router, Application, Handler, Request as Request$1 } from 'express';
|
|
4
|
+
import { Store, Options } from 'express-rate-limit';
|
|
5
|
+
import { BehaviorSubject } from 'rxjs';
|
|
6
|
+
import { Store as Store$1, Options as Options$1 } from 'express-slow-down';
|
|
2
7
|
import RedisStore from 'rate-limit-redis';
|
|
3
|
-
import { Handler, Request as Request$1 } from 'express';
|
|
4
8
|
import { DataContext } from '@themost/data';
|
|
5
9
|
|
|
10
|
+
declare type RateLimitStoreConstructor = new (...arg: unknown[]) => Store;
|
|
11
|
+
|
|
12
|
+
declare interface RateLimitServiceConfiguration {
|
|
13
|
+
extends?: string;
|
|
14
|
+
storeType?: string;
|
|
15
|
+
profiles?: [string, Options][];
|
|
16
|
+
paths?: [string, ({ profile: string } | Options)][];
|
|
17
|
+
}
|
|
18
|
+
|
|
6
19
|
declare class RateLimitService extends ApplicationService {
|
|
20
|
+
constructor(app: _themost_common.ApplicationBase);
|
|
21
|
+
readonly loaded: BehaviorSubject<Router>;
|
|
22
|
+
getServiceContainer(): BehaviorSubject<Router | Application>;
|
|
23
|
+
getServiceName(): string;
|
|
24
|
+
getServiceConfiguration(): RateLimitServiceConfiguration;
|
|
25
|
+
set(path: string, options: { profile?: string } | Options): this;
|
|
26
|
+
unset(path: string): this;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
declare type SpeedLimitStoreConstructor = new (...arg: unknown[]) => Store$1;
|
|
7
30
|
|
|
31
|
+
declare interface SpeedLimitServiceConfiguration {
|
|
32
|
+
extends?: string;
|
|
33
|
+
storeType?: string;
|
|
34
|
+
profiles?: Map<string, Options$1>;
|
|
35
|
+
paths?: Map<string, ({ profile: string } | Options$1)>;
|
|
8
36
|
}
|
|
9
37
|
|
|
10
38
|
declare class SpeedLimitService extends ApplicationService {
|
|
11
|
-
|
|
39
|
+
constructor(app: ApplicationBase);
|
|
40
|
+
getServiceContainer(): BehaviorSubject<Router | Application>;
|
|
41
|
+
getServiceName(): string;
|
|
42
|
+
getServiceConfiguration(): SpeedLimitServiceConfiguration;
|
|
43
|
+
set(path: string, options: { profile?: string } | Options$1): this;
|
|
44
|
+
unset(path: string): this;
|
|
12
45
|
}
|
|
13
46
|
|
|
14
47
|
declare class RedisClientStore extends RedisStore {
|
|
@@ -209,5 +242,13 @@ declare class RemoteAddressValidator extends ApplicationService {
|
|
|
209
242
|
|
|
210
243
|
}
|
|
211
244
|
|
|
212
|
-
|
|
213
|
-
|
|
245
|
+
declare class AppRateLimitService extends RateLimitService {
|
|
246
|
+
constructor(app: _themost_common.ApplicationBase);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
declare class AppSpeedLimitService extends SpeedLimitService {
|
|
250
|
+
constructor(app: _themost_common.ApplicationBase);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
export { AppRateLimitService, AppSpeedLimitService, DefaultScopeAccessConfiguration, EnableScopeAccessConfiguration, ExtendScopeAccessConfiguration, OAuth2ClientService, RateLimitService, RedisClientStore, RemoteAddressValidator, ScopeAccessConfiguration, ScopeString, SpeedLimitService, validateScope };
|
|
254
|
+
export type { GenericUser, OAuth2AuthorizeUser, OAuth2MethodOptions, OAuth2ServiceSettings, OAuth2User, OAuth2UserProfile, RateLimitServiceConfiguration, RateLimitStoreConstructor, ScopeAccessConfigurationElement, ScopeAccessConfigurationSection, SpeedLimitServiceConfiguration, SpeedLimitStoreConstructor, UniversisConfigurationSection };
|