@sourceregistry/node-webserver 1.4.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.
@@ -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
  */
@@ -10,6 +10,13 @@ export interface Options {
10
10
  * @default crypto.randomUUID
11
11
  */
12
12
  generate?: () => string;
13
+ /**
14
+ * Enable client request ID handling
15
+ * When enabled, checks for X-Client-Request-Id header, validates it contains only ASCII characters and is no more than 512 characters,
16
+ * and uses it if valid. Invalid headers result in a 400 error response.
17
+ * @default false
18
+ */
19
+ clientRequestId?: boolean;
13
20
  }
14
21
  export declare function assign(options?: Options): Middleware<string, {
15
22
  requestId: string;
@@ -98,6 +98,7 @@ export declare class WebServer<TServerConfig extends ServerConfig = ServerConfig
98
98
  private getTrustedForwardedHeader;
99
99
  private isTrustedProxy;
100
100
  private normalizeAddress;
101
+ private isValidIP;
101
102
  private parseForwardedHeader;
102
103
  private toHeaders;
103
104
  private isRequestBodyAllowed;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sourceregistry/node-webserver",
3
- "version": "1.4.0",
3
+ "version": "1.6.0",
4
4
  "description": "TypeScript web server for Node.js with web-standard Request and Response APIs",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs.js",