@aeriajs/security 0.0.287 → 0.0.289
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/dist/rateLimiting.js +4 -0
- package/package.json +8 -6
package/dist/rateLimiting.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Result, HTTPStatus, RateLimitingError } from '@aeriajs/types';
|
|
2
|
+
import { getCollection } from '@aeriajs/entrypoint';
|
|
2
3
|
const buildEntryFilter = (params, context) => {
|
|
3
4
|
if (params.strategy === 'ip') {
|
|
4
5
|
const address = context.response.socket.remoteAddress;
|
|
@@ -25,6 +26,9 @@ export const getOrCreateUsageEntry = async (params, context) => {
|
|
|
25
26
|
});
|
|
26
27
|
};
|
|
27
28
|
export const limitRate = async (params, context) => {
|
|
29
|
+
if (!await getCollection('resourceUsage')) {
|
|
30
|
+
throw new Error('the builtin collection "resourceUsage" is required when using this feature');
|
|
31
|
+
}
|
|
28
32
|
const { increment = 1 } = params;
|
|
29
33
|
const entry = await getOrCreateUsageEntry(params, context);
|
|
30
34
|
if (!entry) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeriajs/security",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.289",
|
|
5
5
|
"description": "",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -23,14 +23,16 @@
|
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@aeriajs/core": "link:../core",
|
|
25
25
|
"@aeriajs/common": "link:../common",
|
|
26
|
+
"@aeriajs/entrypoint": "link:../entrypoint",
|
|
26
27
|
"@aeriajs/types": "link:../types",
|
|
27
|
-
"mongodb": "^6.
|
|
28
|
+
"mongodb": "^6.19.0"
|
|
28
29
|
},
|
|
29
30
|
"peerDependencies": {
|
|
30
|
-
"@aeriajs/core": "^0.0.
|
|
31
|
-
"@aeriajs/common": "^0.0.
|
|
32
|
-
"@aeriajs/
|
|
33
|
-
"
|
|
31
|
+
"@aeriajs/core": "^0.0.289",
|
|
32
|
+
"@aeriajs/common": "^0.0.163",
|
|
33
|
+
"@aeriajs/entrypoint": "^0.0.171",
|
|
34
|
+
"@aeriajs/types": "^0.0.138",
|
|
35
|
+
"mongodb": "^6.19.0"
|
|
34
36
|
},
|
|
35
37
|
"scripts": {
|
|
36
38
|
"test": "vitest run",
|