@sourceregistry/node-webserver 1.5.0 → 1.6.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 +45 -0
- package/dist/index.cjs.js +2 -2
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +156 -70
- package/dist/index.es.js.map +1 -1
- package/dist/middlewares/ratelimiter/SlidingWindow.d.ts +16 -0
- package/dist/middlewares/ratelimiter/index.d.ts +15 -0
- package/package.json +1 -1
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { RateLimitStore } from './storage';
|
|
2
|
+
export declare class SlidingWindowStore implements RateLimitStore {
|
|
3
|
+
private readonly windowMs;
|
|
4
|
+
private data;
|
|
5
|
+
private cleanupInterval?;
|
|
6
|
+
constructor(opts: {
|
|
7
|
+
windowMs: number;
|
|
8
|
+
});
|
|
9
|
+
incr(key: string): Promise<{
|
|
10
|
+
current: number;
|
|
11
|
+
reset: number;
|
|
12
|
+
}>;
|
|
13
|
+
private startCleanup;
|
|
14
|
+
stop(): void;
|
|
15
|
+
resetAll(): Promise<void>;
|
|
16
|
+
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { RateLimitStore } from './storage';
|
|
2
2
|
import { Middleware, RequestEvent } from '../../types';
|
|
3
|
+
import { MemoryStore } from './InMemory';
|
|
4
|
+
import { SlidingWindowStore } from './SlidingWindow';
|
|
3
5
|
export type Options = {
|
|
4
6
|
/**
|
|
5
7
|
* Window duration in milliseconds
|
|
@@ -37,6 +39,9 @@ export type Options = {
|
|
|
37
39
|
current: number;
|
|
38
40
|
max: number;
|
|
39
41
|
key: string;
|
|
42
|
+
reset: number;
|
|
43
|
+
remaining: number;
|
|
44
|
+
resetTimeMs: number;
|
|
40
45
|
}) => void;
|
|
41
46
|
/**
|
|
42
47
|
* Storage backend
|
|
@@ -44,6 +49,16 @@ export type Options = {
|
|
|
44
49
|
*/
|
|
45
50
|
store?: RateLimitStore;
|
|
46
51
|
};
|
|
52
|
+
export { MemoryStore };
|
|
53
|
+
export { SlidingWindowStore };
|
|
54
|
+
/**
|
|
55
|
+
* Sliding window rate limiter middleware
|
|
56
|
+
*
|
|
57
|
+
* More accurate than fixed window as it tracks individual request timestamps.
|
|
58
|
+
* Uses more memory but avoids the "cliff" effect where all requests at the end
|
|
59
|
+
* of one window and start of next are counted together.
|
|
60
|
+
*/
|
|
61
|
+
export declare function slidingWindowLimit(options: Options): Middleware;
|
|
47
62
|
/**
|
|
48
63
|
* Fixed window rate limiter middleware
|
|
49
64
|
*/
|
package/package.json
CHANGED