@expressots/core 2.3.0 → 2.5.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/lib/CHANGELOG.md +71 -26
- package/lib/cjs/application/app-container.js +10 -2
- package/lib/cjs/application/application-factory.js +33 -44
- package/lib/cjs/console/console.js +26 -39
- package/lib/cjs/controller/base-controller.js +2 -13
- package/lib/cjs/error/app-error.js +11 -0
- package/lib/cjs/error/report.js +4 -1
- package/lib/cjs/error/status-code.js +8 -2
- package/lib/cjs/middleware/middleware-resolver.js +16 -13
- package/lib/cjs/middleware/middleware-service.js +33 -11
- package/lib/cjs/provider/dto-validator/dto-validator.provider.js +3 -12
- package/lib/cjs/provider/environment/env-validator.provider.js +2 -2
- package/lib/cjs/provider/logger/logger-service.js +1 -0
- package/lib/cjs/provider/provider-service.js +2 -0
- package/lib/cjs/types/application/app-container.d.ts +0 -1
- package/lib/cjs/types/application/application-factory.d.ts +0 -1
- package/lib/cjs/types/application/index.d.ts +0 -1
- package/lib/cjs/types/common/color-service.provider.d.ts +0 -1
- package/lib/cjs/types/common/index.d.ts +0 -1
- package/lib/cjs/types/common/package-resolver.provider.d.ts +0 -1
- package/lib/cjs/types/common/project-config.provider.d.ts +0 -1
- package/lib/cjs/types/console/console.d.ts +0 -1
- package/lib/cjs/types/console/index.d.ts +0 -1
- package/lib/cjs/types/container-module/container-module.d.ts +0 -1
- package/lib/cjs/types/container-module/index.d.ts +0 -1
- package/lib/cjs/types/controller/base-controller.d.ts +2 -3
- package/lib/cjs/types/controller/index.d.ts +0 -1
- package/lib/cjs/types/decorator/index.d.ts +0 -1
- package/lib/cjs/types/decorator/scope-binding.d.ts +0 -1
- package/lib/cjs/types/error/app-error.d.ts +0 -1
- package/lib/cjs/types/error/error-handler-middleware.d.ts +0 -1
- package/lib/cjs/types/error/index.d.ts +0 -1
- package/lib/cjs/types/error/report.d.ts +0 -1
- package/lib/cjs/types/error/status-code.d.ts +0 -1
- package/lib/cjs/types/index.d.ts +0 -1
- package/lib/cjs/types/middleware/index.d.ts +2 -1
- package/lib/cjs/types/middleware/interfaces/body-parser.interface.d.ts +0 -1
- package/lib/cjs/types/middleware/interfaces/compression.interface.d.ts +0 -1
- package/lib/cjs/types/middleware/interfaces/cookie-parser.interface.d.ts +0 -1
- package/lib/cjs/types/middleware/interfaces/cookie-session/cookie-session.interface.d.ts +0 -1
- package/lib/cjs/types/middleware/interfaces/cookie-session/keygrip.interface.d.ts +0 -1
- package/lib/cjs/types/middleware/interfaces/cors.interface.d.ts +0 -1
- package/lib/cjs/types/middleware/interfaces/express-rate-limit.interface.d.ts +292 -0
- package/lib/cjs/types/middleware/interfaces/helmet.interface.d.ts +210 -0
- package/lib/cjs/types/middleware/interfaces/morgan.interface.d.ts +0 -1
- package/lib/cjs/types/middleware/interfaces/serve-favicon.interface.d.ts +0 -1
- package/lib/cjs/types/middleware/interfaces/serve-static.interface.d.ts +0 -1
- package/lib/cjs/types/middleware/middleware-resolver.d.ts +0 -1
- package/lib/cjs/types/middleware/middleware-service.d.ts +24 -1
- package/lib/cjs/types/provider/dto-validator/dto-validator.provider.d.ts +0 -1
- package/lib/cjs/types/provider/environment/env-validator.provider.d.ts +0 -1
- package/lib/cjs/types/provider/index.d.ts +0 -1
- package/lib/cjs/types/provider/logger/logger-service.d.ts +0 -1
- package/lib/cjs/types/provider/provider-service.d.ts +0 -1
- package/lib/cjs/types/render/handlebars.interface.d.ts +0 -1
- package/lib/cjs/types/render/index.d.ts +0 -1
- package/lib/cjs/types/render/render.type.d.ts +0 -1
- package/lib/package.json +7 -8
- package/package.json +7 -8
- package/lib/cjs/types/application/app-container.d.ts.map +0 -1
- package/lib/cjs/types/application/application-factory.d.ts.map +0 -1
- package/lib/cjs/types/application/index.d.ts.map +0 -1
- package/lib/cjs/types/common/color-service.provider.d.ts.map +0 -1
- package/lib/cjs/types/common/index.d.ts.map +0 -1
- package/lib/cjs/types/common/package-resolver.provider.d.ts.map +0 -1
- package/lib/cjs/types/common/project-config.provider.d.ts.map +0 -1
- package/lib/cjs/types/console/console.d.ts.map +0 -1
- package/lib/cjs/types/console/index.d.ts.map +0 -1
- package/lib/cjs/types/container-module/container-module.d.ts.map +0 -1
- package/lib/cjs/types/container-module/index.d.ts.map +0 -1
- package/lib/cjs/types/controller/base-controller.d.ts.map +0 -1
- package/lib/cjs/types/controller/index.d.ts.map +0 -1
- package/lib/cjs/types/decorator/index.d.ts.map +0 -1
- package/lib/cjs/types/decorator/scope-binding.d.ts.map +0 -1
- package/lib/cjs/types/error/app-error.d.ts.map +0 -1
- package/lib/cjs/types/error/error-handler-middleware.d.ts.map +0 -1
- package/lib/cjs/types/error/index.d.ts.map +0 -1
- package/lib/cjs/types/error/report.d.ts.map +0 -1
- package/lib/cjs/types/error/status-code.d.ts.map +0 -1
- package/lib/cjs/types/index.d.ts.map +0 -1
- package/lib/cjs/types/middleware/index.d.ts.map +0 -1
- package/lib/cjs/types/middleware/interfaces/body-parser.interface.d.ts.map +0 -1
- package/lib/cjs/types/middleware/interfaces/compression.interface.d.ts.map +0 -1
- package/lib/cjs/types/middleware/interfaces/cookie-parser.interface.d.ts.map +0 -1
- package/lib/cjs/types/middleware/interfaces/cookie-session/cookie-session.interface.d.ts.map +0 -1
- package/lib/cjs/types/middleware/interfaces/cookie-session/keygrip.interface.d.ts.map +0 -1
- package/lib/cjs/types/middleware/interfaces/cors.interface.d.ts.map +0 -1
- package/lib/cjs/types/middleware/interfaces/morgan.interface.d.ts.map +0 -1
- package/lib/cjs/types/middleware/interfaces/serve-favicon.interface.d.ts.map +0 -1
- package/lib/cjs/types/middleware/interfaces/serve-static.interface.d.ts.map +0 -1
- package/lib/cjs/types/middleware/middleware-resolver.d.ts.map +0 -1
- package/lib/cjs/types/middleware/middleware-service.d.ts.map +0 -1
- package/lib/cjs/types/provider/dto-validator/dto-validator.provider.d.ts.map +0 -1
- package/lib/cjs/types/provider/environment/env-validator.provider.d.ts.map +0 -1
- package/lib/cjs/types/provider/index.d.ts.map +0 -1
- package/lib/cjs/types/provider/logger/logger-service.d.ts.map +0 -1
- package/lib/cjs/types/provider/provider-service.d.ts.map +0 -1
- package/lib/cjs/types/render/handlebars.interface.d.ts.map +0 -1
- package/lib/cjs/types/render/index.d.ts.map +0 -1
- package/lib/cjs/types/render/render.type.d.ts.map +0 -1
- package/lib/esm/application/app-container.js +0 -82
- package/lib/esm/application/application-factory.js +0 -72
- package/lib/esm/application/index.js +0 -7
- package/lib/esm/common/color-service.provider.js +0 -46
- package/lib/esm/common/package-resolver.provider.js +0 -35
- package/lib/esm/console/console.js +0 -61
- package/lib/esm/console/index.js +0 -5
- package/lib/esm/container-module/container-module.js +0 -111
- package/lib/esm/container-module/index.js +0 -6
- package/lib/esm/controller/base-controller.js +0 -75
- package/lib/esm/controller/index.js +0 -5
- package/lib/esm/decorator/index.js +0 -17
- package/lib/esm/decorator/scope-binding.js +0 -44
- package/lib/esm/error/app-error.js +0 -37
- package/lib/esm/error/error-handler-middleware.js +0 -28
- package/lib/esm/error/index.js +0 -9
- package/lib/esm/error/report.js +0 -57
- package/lib/esm/error/status-code.js +0 -89
- package/lib/esm/index.mjs +0 -26
- package/lib/esm/middleware/index.js +0 -29
- package/lib/esm/middleware/interfaces/body-parser.interface.js +0 -2
- package/lib/esm/middleware/interfaces/compression.interface.js +0 -2
- package/lib/esm/middleware/interfaces/cookie-parser.interface.js +0 -2
- package/lib/esm/middleware/interfaces/cookie-session/cookie-session.interface.js +0 -2
- package/lib/esm/middleware/interfaces/cookie-session/keygrip.interface.js +0 -2
- package/lib/esm/middleware/interfaces/cors.interface.js +0 -2
- package/lib/esm/middleware/interfaces/morgan.interface.js +0 -2
- package/lib/esm/middleware/interfaces/serve-favicon.interface.js +0 -2
- package/lib/esm/middleware/interfaces/serve-static.interface.js +0 -2
- package/lib/esm/middleware/middleware-resolver.js +0 -69
- package/lib/esm/middleware/middleware-service.js +0 -258
- package/lib/esm/provider/dto-validator/dto-validator.provider.js +0 -53
- package/lib/esm/provider/environment/env-validator.provider.js +0 -96
- package/lib/esm/provider/index.js +0 -11
- package/lib/esm/provider/logger/logger-service.js +0 -115
- package/lib/esm/provider/provider-service.js +0 -38
- package/lib/esm/render/handlebars.interface.js +0 -2
- package/lib/esm/render/index.js +0 -2
- package/lib/esm/render/render.type.js +0 -2
- package/lib/esm/types/application/app-container.d.ts +0 -126
- package/lib/esm/types/application/app-container.d.ts.map +0 -1
- package/lib/esm/types/application/application-factory.d.ts +0 -34
- package/lib/esm/types/application/application-factory.d.ts.map +0 -1
- package/lib/esm/types/application/index.d.ts +0 -3
- package/lib/esm/types/application/index.d.ts.map +0 -1
- package/lib/esm/types/common/color-service.provider.d.ts +0 -30
- package/lib/esm/types/common/color-service.provider.d.ts.map +0 -1
- package/lib/esm/types/common/index.d.ts +0 -2
- package/lib/esm/types/common/index.d.ts.map +0 -1
- package/lib/esm/types/common/package-resolver.provider.d.ts +0 -9
- package/lib/esm/types/common/package-resolver.provider.d.ts.map +0 -1
- package/lib/esm/types/common/project-config.provider.d.ts +0 -48
- package/lib/esm/types/common/project-config.provider.d.ts.map +0 -1
- package/lib/esm/types/console/console.d.ts +0 -28
- package/lib/esm/types/console/console.d.ts.map +0 -1
- package/lib/esm/types/console/index.d.ts +0 -2
- package/lib/esm/types/console/index.d.ts.map +0 -1
- package/lib/esm/types/container-module/container-module.d.ts +0 -29
- package/lib/esm/types/container-module/container-module.d.ts.map +0 -1
- package/lib/esm/types/container-module/index.d.ts +0 -2
- package/lib/esm/types/container-module/index.d.ts.map +0 -1
- package/lib/esm/types/controller/base-controller.d.ts +0 -49
- package/lib/esm/types/controller/base-controller.d.ts.map +0 -1
- package/lib/esm/types/controller/index.d.ts +0 -2
- package/lib/esm/types/controller/index.d.ts.map +0 -1
- package/lib/esm/types/decorator/index.d.ts +0 -2
- package/lib/esm/types/decorator/index.d.ts.map +0 -1
- package/lib/esm/types/decorator/scope-binding.d.ts +0 -34
- package/lib/esm/types/decorator/scope-binding.d.ts.map +0 -1
- package/lib/esm/types/error/app-error.d.ts +0 -30
- package/lib/esm/types/error/app-error.d.ts.map +0 -1
- package/lib/esm/types/error/error-handler-middleware.d.ts +0 -12
- package/lib/esm/types/error/error-handler-middleware.d.ts.map +0 -1
- package/lib/esm/types/error/index.d.ts +0 -4
- package/lib/esm/types/error/index.d.ts.map +0 -1
- package/lib/esm/types/error/report.d.ts +0 -26
- package/lib/esm/types/error/report.d.ts.map +0 -1
- package/lib/esm/types/error/status-code.d.ts +0 -137
- package/lib/esm/types/error/status-code.d.ts.map +0 -1
- package/lib/esm/types/index.d.ts +0 -11
- package/lib/esm/types/index.d.ts.map +0 -1
- package/lib/esm/types/middleware/index.d.ts +0 -10
- package/lib/esm/types/middleware/index.d.ts.map +0 -1
- package/lib/esm/types/middleware/interfaces/body-parser.interface.d.ts +0 -34
- package/lib/esm/types/middleware/interfaces/body-parser.interface.d.ts.map +0 -1
- package/lib/esm/types/middleware/interfaces/compression.interface.d.ts +0 -99
- package/lib/esm/types/middleware/interfaces/compression.interface.d.ts.map +0 -1
- package/lib/esm/types/middleware/interfaces/cookie-parser.interface.d.ts +0 -10
- package/lib/esm/types/middleware/interfaces/cookie-parser.interface.d.ts.map +0 -1
- package/lib/esm/types/middleware/interfaces/cookie-session/cookie-session.interface.d.ts +0 -58
- package/lib/esm/types/middleware/interfaces/cookie-session/cookie-session.interface.d.ts.map +0 -1
- package/lib/esm/types/middleware/interfaces/cookie-session/keygrip.interface.d.ts +0 -28
- package/lib/esm/types/middleware/interfaces/cookie-session/keygrip.interface.d.ts.map +0 -1
- package/lib/esm/types/middleware/interfaces/cors.interface.d.ts +0 -58
- package/lib/esm/types/middleware/interfaces/cors.interface.d.ts.map +0 -1
- package/lib/esm/types/middleware/interfaces/morgan.interface.d.ts +0 -41
- package/lib/esm/types/middleware/interfaces/morgan.interface.d.ts.map +0 -1
- package/lib/esm/types/middleware/interfaces/serve-favicon.interface.d.ts +0 -12
- package/lib/esm/types/middleware/interfaces/serve-favicon.interface.d.ts.map +0 -1
- package/lib/esm/types/middleware/interfaces/serve-static.interface.d.ts +0 -71
- package/lib/esm/types/middleware/interfaces/serve-static.interface.d.ts.map +0 -1
- package/lib/esm/types/middleware/middleware-resolver.d.ts +0 -12
- package/lib/esm/types/middleware/middleware-resolver.d.ts.map +0 -1
- package/lib/esm/types/middleware/middleware-service.d.ts +0 -237
- package/lib/esm/types/middleware/middleware-service.d.ts.map +0 -1
- package/lib/esm/types/provider/dto-validator/dto-validator.provider.d.ts +0 -12
- package/lib/esm/types/provider/dto-validator/dto-validator.provider.d.ts.map +0 -1
- package/lib/esm/types/provider/environment/env-validator.provider.d.ts +0 -31
- package/lib/esm/types/provider/environment/env-validator.provider.d.ts.map +0 -1
- package/lib/esm/types/provider/index.d.ts +0 -5
- package/lib/esm/types/provider/index.d.ts.map +0 -1
- package/lib/esm/types/provider/logger/logger-service.d.ts +0 -50
- package/lib/esm/types/provider/logger/logger-service.d.ts.map +0 -1
- package/lib/esm/types/provider/provider-service.d.ts +0 -31
- package/lib/esm/types/provider/provider-service.d.ts.map +0 -1
- package/lib/esm/types/render/handlebars.interface.d.ts +0 -47
- package/lib/esm/types/render/handlebars.interface.d.ts.map +0 -1
- package/lib/esm/types/render/index.d.ts +0 -3
- package/lib/esm/types/render/index.d.ts.map +0 -1
- package/lib/esm/types/render/render.type.d.ts +0 -13
- package/lib/esm/types/render/render.type.d.ts.map +0 -1
- /package/lib/{esm/common/index.js → cjs/middleware/interfaces/express-rate-limit.interface.js} +0 -0
- /package/lib/{esm/common/project-config.provider.js → cjs/middleware/interfaces/helmet.interface.js} +0 -0
|
@@ -31,7 +31,7 @@ declare abstract class BaseController implements Controller {
|
|
|
31
31
|
* @param {Object} [options={}] - An optional object containing data to be passed to the template.
|
|
32
32
|
*
|
|
33
33
|
*/
|
|
34
|
-
protected callUseRender(res: Response, template: string, options?:
|
|
34
|
+
protected callUseRender(res: Response, template: string, options?: object): void;
|
|
35
35
|
/**
|
|
36
36
|
* Asynchronously renders a template with the given options using the Express `Response` object's render method.
|
|
37
37
|
*
|
|
@@ -43,7 +43,6 @@ declare abstract class BaseController implements Controller {
|
|
|
43
43
|
* @param {Object} [options={}] - An optional object containing data to be passed to the template.
|
|
44
44
|
*
|
|
45
45
|
*/
|
|
46
|
-
protected callUseRenderAsync(res: Response, template: string, options?:
|
|
46
|
+
protected callUseRenderAsync(res: Response, template: string, options?: object): Promise<string>;
|
|
47
47
|
}
|
|
48
48
|
export { BaseController };
|
|
49
|
-
//# sourceMappingURL=base-controller.d.ts.map
|
package/lib/cjs/types/index.d.ts
CHANGED
|
@@ -3,8 +3,9 @@ export { OptionsJson } from "./interfaces/body-parser.interface";
|
|
|
3
3
|
export { CorsOptions } from "./interfaces/cors.interface";
|
|
4
4
|
export { CompressionOptions } from "./interfaces/compression.interface";
|
|
5
5
|
export { CookieSessionOptions } from "./interfaces/cookie-session/cookie-session.interface";
|
|
6
|
+
export { OptionsHelmet } from "./interfaces/helmet.interface";
|
|
6
7
|
export { Keygrip } from "./interfaces/cookie-session/keygrip.interface";
|
|
7
8
|
export { CookieParserOptions } from "./interfaces/cookie-parser.interface";
|
|
8
9
|
export { ServeFaviconOptions } from "./interfaces/serve-favicon.interface";
|
|
10
|
+
export { RateLimitOptions } from "./interfaces/express-rate-limit.interface";
|
|
9
11
|
export * as IMorgan from "./interfaces/morgan.interface";
|
|
10
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import { Request, Response, NextFunction } from "express";
|
|
2
|
+
/**
|
|
3
|
+
* Method (in the form of middleware) to generate/retrieve a value based on the
|
|
4
|
+
* incoming request.
|
|
5
|
+
*
|
|
6
|
+
* @param request {Request} - The Express request object.
|
|
7
|
+
* @param response {Response} - The Express response object.
|
|
8
|
+
*
|
|
9
|
+
* @returns {T} - The value needed.
|
|
10
|
+
*/
|
|
11
|
+
type ValueDeterminingMiddleware<T> = (request: Request, response: Response) => T | Promise<T>;
|
|
12
|
+
/**
|
|
13
|
+
* Express request handler that sends back a response when a client is
|
|
14
|
+
* rate-limited.
|
|
15
|
+
* @param request {Request} - The Express request object.
|
|
16
|
+
* @param response {Response} - The Express response object.
|
|
17
|
+
* @param next {NextFunction} - The Express `next` function, can be called to skip responding.
|
|
18
|
+
* @param optionsUsed {Options} - The options used to set up the middleware.
|
|
19
|
+
*/
|
|
20
|
+
type RateLimitExceededEventHandler = (request: Request, response: Response, next: NextFunction, optionsUsed: RateLimitOptions) => void;
|
|
21
|
+
/**
|
|
22
|
+
* Data returned from the `Store` when a client's hit counter is incremented.
|
|
23
|
+
*
|
|
24
|
+
* @property totalHits {number} - The number of hits for that client so far.
|
|
25
|
+
* @property resetTime {Date | undefined} - The time when the counter resets.
|
|
26
|
+
*/
|
|
27
|
+
type ClientRateLimitInfo = {
|
|
28
|
+
totalHits: number;
|
|
29
|
+
resetTime: Date | undefined;
|
|
30
|
+
};
|
|
31
|
+
type IncrementResponse = ClientRateLimitInfo;
|
|
32
|
+
/**
|
|
33
|
+
* An interface that all hit counter stores must implement.
|
|
34
|
+
*/
|
|
35
|
+
interface Store {
|
|
36
|
+
/**
|
|
37
|
+
* Method that initializes the store, and has access to the options passed to
|
|
38
|
+
* the middleware too.
|
|
39
|
+
*
|
|
40
|
+
* @param options {Options} - The options used to setup the middleware.
|
|
41
|
+
*/
|
|
42
|
+
init?: (options: RateLimitOptions) => void;
|
|
43
|
+
/**
|
|
44
|
+
* Method to fetch a client's hit count and reset time.
|
|
45
|
+
*
|
|
46
|
+
* @param key {string} - The identifier for a client.
|
|
47
|
+
*
|
|
48
|
+
* @returns {ClientRateLimitInfo} - The number of hits and reset time for that client.
|
|
49
|
+
*/
|
|
50
|
+
get?: (key: string) => Promise<ClientRateLimitInfo | undefined> | ClientRateLimitInfo | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* Method to increment a client's hit counter.
|
|
53
|
+
*
|
|
54
|
+
* @param key {string} - The identifier for a client.
|
|
55
|
+
*
|
|
56
|
+
* @returns {IncrementResponse | undefined} - The number of hits and reset time for that client.
|
|
57
|
+
*/
|
|
58
|
+
increment: (key: string) => Promise<IncrementResponse> | IncrementResponse;
|
|
59
|
+
/**
|
|
60
|
+
* Method to decrement a client's hit counter.
|
|
61
|
+
*
|
|
62
|
+
* @param key {string} - The identifier for a client.
|
|
63
|
+
*/
|
|
64
|
+
decrement: (key: string) => Promise<void> | void;
|
|
65
|
+
/**
|
|
66
|
+
* Method to reset a client's hit counter.
|
|
67
|
+
*
|
|
68
|
+
* @param key {string} - The identifier for a client.
|
|
69
|
+
*/
|
|
70
|
+
resetKey: (key: string) => Promise<void> | void;
|
|
71
|
+
/**
|
|
72
|
+
* Method to reset everyone's hit counter.
|
|
73
|
+
*/
|
|
74
|
+
resetAll?: () => Promise<void> | void;
|
|
75
|
+
/**
|
|
76
|
+
* Method to shutdown the store, stop timers, and release all resources.
|
|
77
|
+
*/
|
|
78
|
+
shutdown?: () => Promise<void> | void;
|
|
79
|
+
/**
|
|
80
|
+
* Flag to indicate that keys incremented in one instance of this store can
|
|
81
|
+
* not affect other instances. Typically false if a database is used, true for
|
|
82
|
+
* MemoryStore.
|
|
83
|
+
*
|
|
84
|
+
* Used to help detect double-counting misconfigurations.
|
|
85
|
+
*/
|
|
86
|
+
localKeys?: boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Optional value that the store prepends to keys
|
|
89
|
+
*
|
|
90
|
+
* Used by the double-count check to avoid false-positives when a key is counted twice, but with different prefixes
|
|
91
|
+
*/
|
|
92
|
+
prefix?: string;
|
|
93
|
+
}
|
|
94
|
+
interface Validations {
|
|
95
|
+
enabled: {
|
|
96
|
+
[key: string]: boolean;
|
|
97
|
+
};
|
|
98
|
+
disable(): void;
|
|
99
|
+
/**
|
|
100
|
+
* Checks whether the IP address is valid, and that it does not have a port
|
|
101
|
+
* number in it.
|
|
102
|
+
*
|
|
103
|
+
* See https://github.com/express-rate-limit/express-rate-limit/wiki/Error-Codes#err_erl_invalid_ip_address.
|
|
104
|
+
*
|
|
105
|
+
* @param ip {string | undefined} - The IP address provided by Express as request.ip.
|
|
106
|
+
*
|
|
107
|
+
* @returns {void}
|
|
108
|
+
*/
|
|
109
|
+
ip(ip: string | undefined): void;
|
|
110
|
+
/**
|
|
111
|
+
* Makes sure the trust proxy setting is not set to `true`.
|
|
112
|
+
*
|
|
113
|
+
* See https://github.com/express-rate-limit/express-rate-limit/wiki/Error-Codes#err_erl_permissive_trust_proxy.
|
|
114
|
+
*
|
|
115
|
+
* @param request {Request} - The Express request object.
|
|
116
|
+
*
|
|
117
|
+
* @returns {void}
|
|
118
|
+
*/
|
|
119
|
+
trustProxy(request: Request): void;
|
|
120
|
+
/**
|
|
121
|
+
* Makes sure the trust proxy setting is set in case the `X-Forwarded-For`
|
|
122
|
+
* header is present.
|
|
123
|
+
*
|
|
124
|
+
* See https://github.com/express-rate-limit/express-rate-limit/wiki/Error-Codes#err_erl_unset_trust_proxy.
|
|
125
|
+
*
|
|
126
|
+
* @param request {Request} - The Express request object.
|
|
127
|
+
*
|
|
128
|
+
* @returns {void}
|
|
129
|
+
*/
|
|
130
|
+
xForwardedForHeader(request: Request): void;
|
|
131
|
+
/**
|
|
132
|
+
* Ensures totalHits value from store is a positive integer.
|
|
133
|
+
*
|
|
134
|
+
* @param hits {any} - The `totalHits` returned by the store.
|
|
135
|
+
*/
|
|
136
|
+
positiveHits(hits: any): void;
|
|
137
|
+
/**
|
|
138
|
+
* Ensures a given key is incremented only once per request.
|
|
139
|
+
*
|
|
140
|
+
* @param request {Request} - The Express request object.
|
|
141
|
+
* @param store {Store} - The store class.
|
|
142
|
+
* @param key {string} - The key used to store the client's hit count.
|
|
143
|
+
*
|
|
144
|
+
* @returns {void}
|
|
145
|
+
*/
|
|
146
|
+
singleCount(request: Request, store: Store, key: string): void;
|
|
147
|
+
/**
|
|
148
|
+
* Warns the user that the behaviour for `max: 0` / `limit: 0` is changing in the next
|
|
149
|
+
* major release.
|
|
150
|
+
*
|
|
151
|
+
* @param limit {number} - The maximum number of hits per client.
|
|
152
|
+
*
|
|
153
|
+
* @returns {void}
|
|
154
|
+
*/
|
|
155
|
+
limit(limit: number): void;
|
|
156
|
+
/**
|
|
157
|
+
* Warns the user that the `draft_polli_ratelimit_headers` option is deprecated
|
|
158
|
+
* and will be removed in the next major release.
|
|
159
|
+
*
|
|
160
|
+
* @param draft_polli_ratelimit_headers {any | undefined} - The now-deprecated setting that was used to enable standard headers.
|
|
161
|
+
*
|
|
162
|
+
* @returns {void}
|
|
163
|
+
*/
|
|
164
|
+
draftPolliHeaders(draft_polli_ratelimit_headers?: any): void;
|
|
165
|
+
/**
|
|
166
|
+
* Warns the user that the `onLimitReached` option is deprecated and will be removed in the next
|
|
167
|
+
* major release.
|
|
168
|
+
*
|
|
169
|
+
* @param onLimitReached {any | undefined} - The maximum number of hits per client.
|
|
170
|
+
*
|
|
171
|
+
* @returns {void}
|
|
172
|
+
*/
|
|
173
|
+
onLimitReached(onLimitReached?: any): void;
|
|
174
|
+
/**
|
|
175
|
+
* Warns the user when the selected headers option requires a reset time but
|
|
176
|
+
* the store does not provide one.
|
|
177
|
+
*
|
|
178
|
+
* @param resetTime {Date | undefined} - The timestamp when the client's hit count will be reset.
|
|
179
|
+
*
|
|
180
|
+
* @returns {void}
|
|
181
|
+
*/
|
|
182
|
+
headersResetTime(resetTime?: Date): void;
|
|
183
|
+
/**
|
|
184
|
+
* Checks the options.validate setting to ensure that only recognized validations are enabled or disabled.
|
|
185
|
+
*
|
|
186
|
+
* If any unrecognized values are found, an error is logged that includes the list of supported vaidations.
|
|
187
|
+
*/
|
|
188
|
+
validationsConfig(): void;
|
|
189
|
+
}
|
|
190
|
+
type DraftHeadersVersion = "draft-6" | "draft-7";
|
|
191
|
+
interface RateLimitOptions {
|
|
192
|
+
/**
|
|
193
|
+
* How long we should remember the requests.
|
|
194
|
+
*
|
|
195
|
+
* Defaults to `60000` ms (= 1 minute).
|
|
196
|
+
*/
|
|
197
|
+
windowMs?: number;
|
|
198
|
+
/**
|
|
199
|
+
* The maximum number of connections to allow during the `window` before
|
|
200
|
+
* rate limiting the client.
|
|
201
|
+
*
|
|
202
|
+
* Can be the limit itself as a number or express middleware that parses
|
|
203
|
+
* the request and then figures out the limit.
|
|
204
|
+
*
|
|
205
|
+
* Defaults to `5`.
|
|
206
|
+
*/
|
|
207
|
+
limit?: number | ValueDeterminingMiddleware<number>;
|
|
208
|
+
/**
|
|
209
|
+
* The response body to send back when a client is rate limited.
|
|
210
|
+
*
|
|
211
|
+
* Defaults to `'Too many requests, please try again later.'`
|
|
212
|
+
*/
|
|
213
|
+
message?: any | ValueDeterminingMiddleware<any>;
|
|
214
|
+
/**
|
|
215
|
+
* The HTTP status code to send back when a client is rate limited.
|
|
216
|
+
*
|
|
217
|
+
* Defaults to `HTTP 429 Too Many Requests` (RFC 6585).
|
|
218
|
+
*/
|
|
219
|
+
statusCode?: number;
|
|
220
|
+
/**
|
|
221
|
+
* Whether to send `X-RateLimit-*` headers with the rate limit and the number
|
|
222
|
+
* of requests.
|
|
223
|
+
*
|
|
224
|
+
* Defaults to `true` (for backward compatibility).
|
|
225
|
+
*/
|
|
226
|
+
legacyHeaders?: boolean;
|
|
227
|
+
/**
|
|
228
|
+
* Whether to enable support for the standardized rate limit headers (`RateLimit-*`).
|
|
229
|
+
*
|
|
230
|
+
* Defaults to `false` (for backward compatibility, but its use is recommended).
|
|
231
|
+
*/
|
|
232
|
+
standardHeaders?: false | DraftHeadersVersion;
|
|
233
|
+
/**
|
|
234
|
+
* The name of the property on the request object to store the rate limit info.
|
|
235
|
+
*
|
|
236
|
+
* Defaults to `rateLimit`.
|
|
237
|
+
*/
|
|
238
|
+
requestPropertyName?: string;
|
|
239
|
+
/**
|
|
240
|
+
* If `true`, the library will (by default) skip all requests that have a 4XX
|
|
241
|
+
* or 5XX status.
|
|
242
|
+
*
|
|
243
|
+
* Defaults to `false`.
|
|
244
|
+
*/
|
|
245
|
+
skipFailedRequests?: boolean;
|
|
246
|
+
/**
|
|
247
|
+
* If `true`, the library will (by default) skip all requests that have a
|
|
248
|
+
* status code less than 400.
|
|
249
|
+
*
|
|
250
|
+
* Defaults to `false`.
|
|
251
|
+
*/
|
|
252
|
+
skipSuccessfulRequests?: boolean;
|
|
253
|
+
/**
|
|
254
|
+
* Method to generate custom identifiers for clients.
|
|
255
|
+
*
|
|
256
|
+
* By default, the client's IP address is used.
|
|
257
|
+
*/
|
|
258
|
+
keyGenerator?: ValueDeterminingMiddleware<string>;
|
|
259
|
+
/**
|
|
260
|
+
* Express request handler that sends back a response when a client is
|
|
261
|
+
* rate-limited.
|
|
262
|
+
*
|
|
263
|
+
* By default, sends back the `statusCode` and `message` set via the options.
|
|
264
|
+
*/
|
|
265
|
+
handler?: RateLimitExceededEventHandler;
|
|
266
|
+
/**
|
|
267
|
+
* Method (in the form of middleware) to determine whether or not this request
|
|
268
|
+
* counts towards a client's quota.
|
|
269
|
+
*
|
|
270
|
+
* By default, skips no requests.
|
|
271
|
+
*/
|
|
272
|
+
skip?: ValueDeterminingMiddleware<boolean>;
|
|
273
|
+
/**
|
|
274
|
+
* Method to determine whether or not the request counts as 'succesful'. Used
|
|
275
|
+
* when either `skipSuccessfulRequests` or `skipFailedRequests` is set to true.
|
|
276
|
+
*
|
|
277
|
+
* By default, requests with a response status code less than 400 are considered
|
|
278
|
+
* successful.
|
|
279
|
+
*/
|
|
280
|
+
requestWasSuccessful?: ValueDeterminingMiddleware<boolean>;
|
|
281
|
+
/**
|
|
282
|
+
* The `Store` to use to store the hit count for each client.
|
|
283
|
+
*
|
|
284
|
+
* By default, the built-in `MemoryStore` will be used.
|
|
285
|
+
*/
|
|
286
|
+
store?: Store;
|
|
287
|
+
/**
|
|
288
|
+
* The list of validation checks that should run.
|
|
289
|
+
*/
|
|
290
|
+
validations?: Validations;
|
|
291
|
+
}
|
|
292
|
+
export { RateLimitOptions };
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { Request, Response } from "express";
|
|
2
|
+
/**
|
|
3
|
+
* @typedef {string} cspDirectiveValue
|
|
4
|
+
* Possible values for Content Security Policy directives.
|
|
5
|
+
* Can be 'self', 'none', or a string.
|
|
6
|
+
*/
|
|
7
|
+
type cspDirectiveValue = "self" | "none" | string;
|
|
8
|
+
/**
|
|
9
|
+
* @interface directiveOptions
|
|
10
|
+
* Options for defining Content Security Policy directives.
|
|
11
|
+
*/
|
|
12
|
+
interface directiveOptions {
|
|
13
|
+
"default-src"?: Array<cspDirectiveValue> | null | Array<(req: Request, res: Response) => string>;
|
|
14
|
+
"base-uri"?: Array<cspDirectiveValue> | null | Array<(req: Request, res: Response) => string>;
|
|
15
|
+
"font-src"?: Array<cspDirectiveValue> | null | Array<(req: Request, res: Response) => string>;
|
|
16
|
+
"form-action"?: Array<cspDirectiveValue> | null | Array<(req: Request, res: Response) => string>;
|
|
17
|
+
"frame-ancestors"?: Array<cspDirectiveValue> | null | Array<(req: Request, res: Response) => string>;
|
|
18
|
+
"img-src"?: Array<cspDirectiveValue> | null | Array<(req: Request, res: Response) => string>;
|
|
19
|
+
"object-src"?: Array<cspDirectiveValue> | null | Array<(req: Request, res: Response) => string>;
|
|
20
|
+
"script-src"?: Array<cspDirectiveValue> | null | Array<(req: Request, res: Response) => string>;
|
|
21
|
+
"script-src-attr"?: Array<cspDirectiveValue> | null | Array<(req: Request, res: Response) => string>;
|
|
22
|
+
"style-src"?: Array<cspDirectiveValue> | null | Array<(req: Request, res: Response) => string>;
|
|
23
|
+
"upgrade-insecure-requests"?: Array<cspDirectiveValue> | null | Array<(req: Request, res: Response) => string>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* @interface ContentSecurityPolicy
|
|
27
|
+
* Defines a Content Security Policy configuration.
|
|
28
|
+
*/
|
|
29
|
+
interface ContentSecurityPolicy {
|
|
30
|
+
/**
|
|
31
|
+
* A function that sets Content Security Policy.
|
|
32
|
+
*
|
|
33
|
+
* @param {directiveOptions} options - Optional configuration options for Content Security Policy.
|
|
34
|
+
* @returns {Function} A middleware function.
|
|
35
|
+
*/
|
|
36
|
+
useDefaults?: false;
|
|
37
|
+
directives?: directiveOptions;
|
|
38
|
+
reportOnly?: boolean;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* @typedef {Object} CrossOriginEmbedderPolicyOptions
|
|
42
|
+
* An optional policy for Cross-Origin Embedder Policy.
|
|
43
|
+
*/
|
|
44
|
+
interface CrossOriginEmbedderPolicyOptions {
|
|
45
|
+
/**
|
|
46
|
+
* An optional policy for Cross-Origin Embedder Policy.
|
|
47
|
+
*/
|
|
48
|
+
policy?: "require-corp" | "credentialless";
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* @typedef {Object} CrossOriginOpenerPolicyOptions
|
|
52
|
+
* An optional policy for Cross-Origin Opener Policy.
|
|
53
|
+
*/
|
|
54
|
+
interface CrossOriginOpenerPolicyOptions {
|
|
55
|
+
/**
|
|
56
|
+
* An optional policy for Cross-Origin Opener Policy.
|
|
57
|
+
*/
|
|
58
|
+
policy?: "same-origin" | "same-origin-allow-popups" | "unsafe-none";
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* @typedef {Object} CrossOriginResourcePolicyOptions
|
|
62
|
+
* An optional policy for Cross-Origin Resource Policy.
|
|
63
|
+
*/
|
|
64
|
+
interface CrossOriginResourcePolicyOptions {
|
|
65
|
+
/**
|
|
66
|
+
* An optional policy for Cross-Origin Resource Policy.
|
|
67
|
+
*/
|
|
68
|
+
policy?: "same-origin" | "same-site" | "cross-origin";
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* @typedef {string} ReferrerPolicyToken
|
|
72
|
+
* A type alias for Referrer Policy tokens.
|
|
73
|
+
*/
|
|
74
|
+
type ReferrerPolicyToken = "no-referrer" | "no-referrer-when-downgrade" | "no-referrer" | "no-referrer-when-downgrade" | "same-origin" | "origin" | "strict-origin" | "origin-when-cross-origin" | "strict-origin-when-cross-origin" | "unsafe-url" | "";
|
|
75
|
+
/**
|
|
76
|
+
* @typedef {Object} ReferrerPolicyOptions
|
|
77
|
+
* An optional policy for Referrer Policy.
|
|
78
|
+
*/
|
|
79
|
+
interface ReferrerPolicyOptions {
|
|
80
|
+
/**
|
|
81
|
+
* An optional policy for Referrer Policy.
|
|
82
|
+
*/
|
|
83
|
+
policy?: ReferrerPolicyToken | Array<ReferrerPolicyToken> | false;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* @typedef {Object} StrictTransportSecurityOptions
|
|
87
|
+
* Options for Strict Transport Security.
|
|
88
|
+
*/
|
|
89
|
+
interface StrictTransportSecurityOptions {
|
|
90
|
+
/**
|
|
91
|
+
* An optional max age for Strict Transport Security.
|
|
92
|
+
*/
|
|
93
|
+
maxAge?: number;
|
|
94
|
+
/**
|
|
95
|
+
* An optional flag to include subdomains.
|
|
96
|
+
*/
|
|
97
|
+
includeSubDomains?: boolean;
|
|
98
|
+
/**
|
|
99
|
+
* An optional flag for preload.
|
|
100
|
+
*/
|
|
101
|
+
preload?: boolean;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* @typedef {boolean|string} xContentTypeOptions
|
|
105
|
+
* Options for X-Content-Type-Options.
|
|
106
|
+
*/
|
|
107
|
+
type xContentTypeOptions = false | "nosniff";
|
|
108
|
+
/**
|
|
109
|
+
* @typedef {Object} XDnsPrefetchControlOptions
|
|
110
|
+
* Options for X-DNS-Prefetch-Control.
|
|
111
|
+
*/
|
|
112
|
+
interface XDnsPrefetchControlOptions {
|
|
113
|
+
/**
|
|
114
|
+
* An optional flag to allow DNS prefetching.
|
|
115
|
+
*/
|
|
116
|
+
allow?: boolean;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* @typedef {Object} XFrameOptionsOptions
|
|
120
|
+
* Options for X-Frame-Options.
|
|
121
|
+
*/
|
|
122
|
+
interface XFrameOptionsOptions {
|
|
123
|
+
/**
|
|
124
|
+
* An optional action for X-Frame-Options.
|
|
125
|
+
*/
|
|
126
|
+
action?: "deny" | "sameorigin" | false;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* @typedef {Object} XPermittedCrossDomainPoliciesOptions
|
|
130
|
+
* Options for X-Permitted-Cross-Domain-Policies.
|
|
131
|
+
*/
|
|
132
|
+
interface XPermittedCrossDomainPoliciesOptions {
|
|
133
|
+
/**
|
|
134
|
+
* An optional policy for X-Permitted-Cross-Domain-Policies.
|
|
135
|
+
*/
|
|
136
|
+
permittedPolicies?: "none" | "master-only" | "by-content-type" | "all";
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* @typedef {boolean} xPoweredByOptions
|
|
140
|
+
* Options for X-Powered-By.
|
|
141
|
+
*/
|
|
142
|
+
type xPoweredByOptions = false;
|
|
143
|
+
/**
|
|
144
|
+
* @typedef {boolean} xXssProtectionOptions
|
|
145
|
+
* Options for X-XSS-Protection.
|
|
146
|
+
*/
|
|
147
|
+
type xXssProtectionOptions = false;
|
|
148
|
+
/**
|
|
149
|
+
* @interface OptionsHelmet
|
|
150
|
+
* Options for Helmet middleware.
|
|
151
|
+
*/
|
|
152
|
+
export interface OptionsHelmet {
|
|
153
|
+
/**
|
|
154
|
+
* An optional Content Security Policy.
|
|
155
|
+
*/
|
|
156
|
+
contentSecurityPolicy?: ContentSecurityPolicy | false;
|
|
157
|
+
/**
|
|
158
|
+
* An optional Cross-Origin Embedder Policy.
|
|
159
|
+
*/
|
|
160
|
+
crossOriginEmbedderPolicy?: CrossOriginEmbedderPolicyOptions | boolean;
|
|
161
|
+
/**
|
|
162
|
+
* An optional Cross-Origin Opener Policy.
|
|
163
|
+
*/
|
|
164
|
+
crossOriginOpenerPolicy?: boolean | CrossOriginOpenerPolicyOptions;
|
|
165
|
+
/**
|
|
166
|
+
* An optional Cross-Origin Resource Policy.
|
|
167
|
+
*/
|
|
168
|
+
crossOriginResourcePolicy?: boolean | CrossOriginResourcePolicyOptions;
|
|
169
|
+
/**
|
|
170
|
+
* An optional flag for originAgentCluster.
|
|
171
|
+
*/
|
|
172
|
+
originAgentCluster?: false;
|
|
173
|
+
/**
|
|
174
|
+
* An optional Referrer Policy.
|
|
175
|
+
*/
|
|
176
|
+
referrerPolicy?: ReferrerPolicyOptions;
|
|
177
|
+
/**
|
|
178
|
+
* An optional Strict Transport Security.
|
|
179
|
+
*/
|
|
180
|
+
strictTransportSecurity?: StrictTransportSecurityOptions;
|
|
181
|
+
/**
|
|
182
|
+
* An optional X-Content-Type-Options.
|
|
183
|
+
*/
|
|
184
|
+
xContentTypeOptions?: xContentTypeOptions;
|
|
185
|
+
/**
|
|
186
|
+
* An optional X-DNS-Prefetch-Control.
|
|
187
|
+
*/
|
|
188
|
+
xDnsPrefetchControl?: XDnsPrefetchControlOptions;
|
|
189
|
+
/**
|
|
190
|
+
* An optional X-Download-Options.
|
|
191
|
+
*/
|
|
192
|
+
xDownloadOptions?: boolean | "noopen";
|
|
193
|
+
/**
|
|
194
|
+
* An optional X-Frame-Options.
|
|
195
|
+
*/
|
|
196
|
+
xFrameOptions?: XFrameOptionsOptions;
|
|
197
|
+
/**
|
|
198
|
+
* An optional X-Permitted-Cross-Domain-Policies.
|
|
199
|
+
*/
|
|
200
|
+
xPermittedCrossDomainPolicies?: XPermittedCrossDomainPoliciesOptions;
|
|
201
|
+
/**
|
|
202
|
+
* An optional X-Powered-By.
|
|
203
|
+
*/
|
|
204
|
+
xPoweredBy?: xPoweredByOptions;
|
|
205
|
+
/**
|
|
206
|
+
* An optional X-XSS-Protection.
|
|
207
|
+
*/
|
|
208
|
+
xXssProtection?: xXssProtectionOptions;
|
|
209
|
+
}
|
|
210
|
+
export {};
|