@rapidrest/service-core 2.3.0 → 2.5.1
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 +123 -94
- package/dist/lib/decorators/RouteDecorators.js +31 -5
- package/dist/lib/decorators/RouteDecorators.js.map +1 -1
- package/dist/lib/http/MiddlewareChain.js.map +1 -1
- package/dist/lib/http/bun/BunAdapters.js +58 -3
- package/dist/lib/http/bun/BunAdapters.js.map +1 -1
- package/dist/lib/http/bun/BunRouter.js +3 -2
- package/dist/lib/http/bun/BunRouter.js.map +1 -1
- package/dist/lib/http/uWS/Adapters.js +104 -10
- package/dist/lib/http/uWS/Adapters.js.map +1 -1
- package/dist/lib/http/uWS/Router.js +41 -19
- package/dist/lib/http/uWS/Router.js.map +1 -1
- package/dist/lib/routes/BaseAdminRoute.js +53 -7
- package/dist/lib/routes/BaseAdminRoute.js.map +1 -1
- package/dist/lib/routes/RouteUtils.js +133 -2
- package/dist/lib/routes/RouteUtils.js.map +1 -1
- package/dist/types/decorators/RouteDecorators.d.ts +68 -5
- package/dist/types/http/MiddlewareChain.d.ts +6 -2
- package/dist/types/http/bun/BunAdapters.d.ts +18 -1
- package/dist/types/http/uWS/Adapters.d.ts +47 -3
- package/dist/types/routes/BaseAdminRoute.d.ts +15 -2
- package/dist/types/routes/RouteUtils.d.ts +39 -2
- package/package.json +34 -34
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { HttpRequest, RequestHandler } from "../http/types.js";
|
|
2
2
|
import { RateLimiter } from "../RateLimiter.js";
|
|
3
|
-
import { RateLimitOptions } from "../decorators/RouteDecorators.js";
|
|
3
|
+
import { ElevationWindow, RateLimitOptions, WebSocketRouteOptions } from "../decorators/RouteDecorators.js";
|
|
4
4
|
/**
|
|
5
5
|
* Provides a set of utilities for converting Route classes to HTTP middleware.
|
|
6
6
|
*
|
|
@@ -12,15 +12,37 @@ export declare class RouteUtils {
|
|
|
12
12
|
private authMiddleware?;
|
|
13
13
|
private logger?;
|
|
14
14
|
protected rateLimiter?: RateLimiter;
|
|
15
|
+
protected config?: any;
|
|
15
16
|
protected trustedRoles: string[];
|
|
16
17
|
protected trustedProxies: string[];
|
|
17
18
|
protected csrfConfig: any;
|
|
18
19
|
protected corsConfig: any;
|
|
20
|
+
protected wsConfig: any;
|
|
19
21
|
/**
|
|
20
22
|
* Creates a middleware function that checks if the user has elevated privileges and if not
|
|
21
23
|
* throws the `AUTH_REQUIRES_ELEVATION` error.
|
|
22
24
|
*/
|
|
23
|
-
checkElevation(
|
|
25
|
+
checkElevation(window?: number | ElevationWindow): RequestHandler;
|
|
26
|
+
/**
|
|
27
|
+
* Decides whether a WebSocket upgrade request may proceed, based on its `Origin` header. Browsers attach the
|
|
28
|
+
* visitor's cookies to a WebSocket handshake for ANY page, and a sibling subdomain (or the apex) is same-site, so
|
|
29
|
+
* `SameSite` cookies do not stop it: without this check a page on any such host could open an authenticated
|
|
30
|
+
* socket in the victim's browser (cross-site WebSocket hijacking). Browsers always send `Origin` on a handshake and
|
|
31
|
+
* a page cannot forge it, so it is the one reliable signal.
|
|
32
|
+
*
|
|
33
|
+
* The upgrade is allowed when:
|
|
34
|
+
* - the check is disabled with `websocket:checkOrigin: false`; or
|
|
35
|
+
* - there is no `Origin` header (a non-browser client, which has no ambient cookies to abuse); or
|
|
36
|
+
* - the origin's host is the host the request was addressed to (same origin); or
|
|
37
|
+
* - the origin exactly matches an entry of `websocket:allowedOrigins`, or, when that is not set, of `cors:origins`.
|
|
38
|
+
*
|
|
39
|
+
* A `"*"` entry from `cors:origins` is NOT honoured (that setting means "any origin, without credentials", the
|
|
40
|
+
* opposite of what is safe here); `"*"` in `websocket:allowedOrigins` explicitly allows any.
|
|
41
|
+
*
|
|
42
|
+
* Same-origin compares host and port only, not scheme, because TLS is commonly terminated by a proxy in front
|
|
43
|
+
* of the service. If a proxy rewrites `Host`, list the public origin in `websocket:allowedOrigins`.
|
|
44
|
+
*/
|
|
45
|
+
checkWebSocketOrigin(req: HttpRequest): boolean;
|
|
24
46
|
/**
|
|
25
47
|
* Creates a middleware function that enforces CSRF protection for a state-changing request whose only
|
|
26
48
|
* credential came from the `jwt` cookie (`req.auth?.source === "cookie"`.
|
|
@@ -29,6 +51,21 @@ export declare class RouteUtils {
|
|
|
29
51
|
* exposed to this class of forgery and is left untouched here.
|
|
30
52
|
*/
|
|
31
53
|
checkCsrf(): RequestHandler;
|
|
54
|
+
/**
|
|
55
|
+
* Validates the options of a `@WebSocket()` route and returns the object to pass to `app.ws()` as its
|
|
56
|
+
* `wsOptions`, or `undefined` when the route has no options (so it gets the router's defaults, exactly as a route
|
|
57
|
+
* that never had this feature). A field that is `undefined` is left out and keeps its default.
|
|
58
|
+
*
|
|
59
|
+
* Every value must be a finite integer: `maxPayloadLength` from 1 to 16 MiB, `maxBackpressure` from 1 to 64 MiB,
|
|
60
|
+
* and `idleTimeout` `0` (disabled) or from 8 to 960 seconds (uWebSockets.js refuses `1` to `7` and anything over
|
|
61
|
+
* 960 by aborting while the route is being registered, so those are rejected here with a readable error instead).
|
|
62
|
+
* An option name that is not one of the three is rejected too, since it would otherwise be silently ignored.
|
|
63
|
+
*
|
|
64
|
+
* @param options The options declared on the route, if any.
|
|
65
|
+
* @param routeName A description of the route (e.g. `WS /relay/:id`), used in the error message.
|
|
66
|
+
* @throws Error naming the route when an option is invalid.
|
|
67
|
+
*/
|
|
68
|
+
static resolveWebSocketOptions(options: WebSocketRouteOptions | undefined, routeName: string): WebSocketRouteOptions | undefined;
|
|
32
69
|
/**
|
|
33
70
|
* Returns a canonical form of a request path for use in rate limit identifiers. The router percent-decodes
|
|
34
71
|
* `:param` values, so `/clients/%61bc` and `/clients/abc` reach the same handler. Keying on the raw path would
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rapidrest/service-core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.1",
|
|
4
4
|
"description": "Provides all core functionality for RapidREST based backend services.",
|
|
5
5
|
"repository": "https://github.com/rapidrest/service-core.git",
|
|
6
6
|
"author": "RapidREST <rapidrests@gmail.com>",
|
|
@@ -24,18 +24,18 @@
|
|
|
24
24
|
"release": "rapidrest release"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"axios": "^1.
|
|
27
|
+
"axios": "^1.21.0",
|
|
28
28
|
"dayjs": "^1.11.23",
|
|
29
29
|
"deepmerge": "^4.3.1",
|
|
30
|
-
"node-schedule": "^2.1.
|
|
30
|
+
"node-schedule": "^2.1.2",
|
|
31
31
|
"winston-transport": "^4.9.0",
|
|
32
|
-
"ws": "^8.
|
|
32
|
+
"ws": "^8.22.1"
|
|
33
33
|
},
|
|
34
34
|
"optionalDependencies": {
|
|
35
35
|
"uWebSockets.js": "uNetworking/uWebSockets.js#v20.69.0"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"@rapidrest/core": "
|
|
38
|
+
"@rapidrest/core": "6.x",
|
|
39
39
|
"lodash-es": "4.x",
|
|
40
40
|
"mongodb": "^7.0.0",
|
|
41
41
|
"openapi3-ts": "4.x",
|
|
@@ -58,53 +58,53 @@
|
|
|
58
58
|
}
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
|
-
"@rapidrest/cli": "^1.0
|
|
62
|
-
"@rapidrest/core": "^
|
|
63
|
-
"@simplewebauthn/server": "^14.0.
|
|
64
|
-
"@swc/core": "^1.16.
|
|
61
|
+
"@rapidrest/cli": "^2.1.0",
|
|
62
|
+
"@rapidrest/core": "^6.1.0",
|
|
63
|
+
"@simplewebauthn/server": "^14.0.3",
|
|
64
|
+
"@swc/core": "^1.16.21",
|
|
65
65
|
"@types/better-sqlite3": "^9.6.0",
|
|
66
|
-
"@types/bun": "^1.4.
|
|
67
|
-
"@types/node": "^26.
|
|
66
|
+
"@types/bun": "^1.4.4",
|
|
67
|
+
"@types/node": "^26.6.6",
|
|
68
68
|
"@types/node-schedule": "^2.1.8",
|
|
69
69
|
"@types/rimraf": "^4.0.5",
|
|
70
70
|
"@types/semver": "^7.8.0",
|
|
71
71
|
"@types/speakeasy": "^2.0.10",
|
|
72
72
|
"@types/uuid": "^11.0.0",
|
|
73
|
-
"@types/ws": "^8.18.
|
|
74
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
75
|
-
"@typescript-eslint/parser": "^8.
|
|
76
|
-
"@vitest/coverage-v8": "^5.
|
|
73
|
+
"@types/ws": "^8.18.2",
|
|
74
|
+
"@typescript-eslint/eslint-plugin": "^8.72.1",
|
|
75
|
+
"@typescript-eslint/parser": "^8.72.1",
|
|
76
|
+
"@vitest/coverage-v8": "^5.1.0",
|
|
77
77
|
"autocannon": "^8.0.0",
|
|
78
78
|
"better-sqlite3": "^13.0.3",
|
|
79
|
-
"eslint": "^10.
|
|
79
|
+
"eslint": "^10.14.0",
|
|
80
80
|
"eslint-config-prettier": "^10.1.8",
|
|
81
81
|
"eslint-plugin-import": "^2.32.0",
|
|
82
|
-
"eslint-plugin-jsdoc": "^
|
|
83
|
-
"globals": "^17.
|
|
82
|
+
"eslint-plugin-jsdoc": "^65.4.3",
|
|
83
|
+
"globals": "^17.14.0",
|
|
84
84
|
"lodash-es": "^4.18.1",
|
|
85
|
-
"mongodb": "^7.
|
|
86
|
-
"mongodb-memory-server": "^11.
|
|
85
|
+
"mongodb": "^7.8.0",
|
|
86
|
+
"mongodb-memory-server": "^11.3.0",
|
|
87
87
|
"nconf": "^0.13.0",
|
|
88
|
-
"nock": "^
|
|
89
|
-
"openapi3-ts": "^4.6.
|
|
90
|
-
"pg": "^8.23.
|
|
88
|
+
"nock": "^15.0.5",
|
|
89
|
+
"openapi3-ts": "^4.6.2",
|
|
90
|
+
"pg": "^8.23.1",
|
|
91
91
|
"prom-client": "^15.1.3",
|
|
92
|
-
"redis": "^6.
|
|
92
|
+
"redis": "^6.3.1",
|
|
93
93
|
"reflect-metadata": "^0.2.2",
|
|
94
|
-
"rimraf": "^6.1.
|
|
95
|
-
"semver": "^7.8.
|
|
94
|
+
"rimraf": "^6.1.4",
|
|
95
|
+
"semver": "^7.8.6",
|
|
96
96
|
"ts-node": "^10.9.2",
|
|
97
|
-
"tsx": "^4.23.
|
|
97
|
+
"tsx": "^4.23.15",
|
|
98
98
|
"typedoc": "^0.28.20",
|
|
99
|
-
"typedoc-plugin-markdown": "^4.
|
|
100
|
-
"typeorm": "^1.1.
|
|
99
|
+
"typedoc-plugin-markdown": "^4.14.1",
|
|
100
|
+
"typeorm": "^1.1.2",
|
|
101
101
|
"typescript": "^6.0.3",
|
|
102
|
-
"unplugin-swc": "^
|
|
103
|
-
"uuid": "^14.0.
|
|
104
|
-
"vite": "^8.
|
|
105
|
-
"vitest": "^5.
|
|
102
|
+
"unplugin-swc": "^2.0.0",
|
|
103
|
+
"uuid": "^14.0.3",
|
|
104
|
+
"vite": "^8.3.5",
|
|
105
|
+
"vitest": "^5.1.0",
|
|
106
106
|
"winston": "^3.19.0",
|
|
107
|
-
"ws": "^8.
|
|
107
|
+
"ws": "^8.22.1"
|
|
108
108
|
},
|
|
109
109
|
"resolutions": {
|
|
110
110
|
"cross-spawn": "^7.0.5",
|