@teikyo/rate-limit 0.3.0 → 0.3.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 +1 -0
- package/lib/index.d.ts +4 -1
- package/lib/index.js +4 -3
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -30,4 +30,5 @@ Clients are keyed on the IP resolved by the server, so set `trustProxy` when run
|
|
|
30
30
|
| --- | --- | --- |
|
|
31
31
|
| `windowMs` | `number` | Length of the window in milliseconds. Must be a positive safe integer. |
|
|
32
32
|
| `limit` | `number` | Maximum requests per client within a window. Must be a positive safe integer. |
|
|
33
|
+
| `path` | `string` (optional) | Limit only this path prefix, matched by segment: `/oauth` covers `/oauth` and `/oauth/...` but not `/oauthx`. Other routes stay unlimited. A server runs one rate limit plugin, so a global limit and a scoped one cannot be combined. |
|
|
33
34
|
| `store` | `Store` (optional) | A `hono-rate-limiter` store, in-memory by default. The plugin calls its `shutdown()` when the server closes, so do not pass a store shared with or owned by something else. |
|
package/lib/index.d.ts
CHANGED
|
@@ -7,6 +7,8 @@ export type RateLimitPluginParams = {
|
|
|
7
7
|
windowMs: number;
|
|
8
8
|
/** Maximum number of requests per client within a window. */
|
|
9
9
|
limit: number;
|
|
10
|
+
/** Limit only this path prefix, segment-aware: `/oauth` covers `/oauth/...` but not `/oauthx`. */
|
|
11
|
+
path?: string;
|
|
10
12
|
/** Bucket by IP (default), principal attribution, or a custom key with nullish IP fallback. */
|
|
11
13
|
key?: 'ip' | 'principal' | ((c: Context) => string | null | undefined | Promise<string | null | undefined>);
|
|
12
14
|
/**
|
|
@@ -17,6 +19,7 @@ export type RateLimitPluginParams = {
|
|
|
17
19
|
};
|
|
18
20
|
/**
|
|
19
21
|
* Rate limit requests by IP, principal attribution, or a custom key, answering `429` with a
|
|
20
|
-
* `Retry-After` header past the limit.
|
|
22
|
+
* `Retry-After` header past the limit. With `path`, only that prefix is limited. Health routes are
|
|
23
|
+
* never limited.
|
|
21
24
|
*/
|
|
22
25
|
export declare function rateLimitPlugin(params: RateLimitPluginParams): HTTPPlugin<'http:rate-limit', void, []>;
|
package/lib/index.js
CHANGED
|
@@ -10,11 +10,12 @@ function assertPositiveInteger(name, value) {
|
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
12
|
* Rate limit requests by IP, principal attribution, or a custom key, answering `429` with a
|
|
13
|
-
* `Retry-After` header past the limit.
|
|
13
|
+
* `Retry-After` header past the limit. With `path`, only that prefix is limited. Health routes are
|
|
14
|
+
* never limited.
|
|
14
15
|
*/ export function rateLimitPlugin(params) {
|
|
15
16
|
assertPositiveInteger('windowMs', params.windowMs);
|
|
16
17
|
assertPositiveInteger('limit', params.limit);
|
|
17
|
-
const { windowMs, limit, key = 'ip' } = params;
|
|
18
|
+
const { windowMs, limit, key = 'ip', path } = params;
|
|
18
19
|
return {
|
|
19
20
|
name: RATE_LIMIT,
|
|
20
21
|
dependsOn: [],
|
|
@@ -37,7 +38,7 @@ function assertPositiveInteger(name, value) {
|
|
|
37
38
|
return `ip:${clientKey(ctx.clientIP(c))}`;
|
|
38
39
|
},
|
|
39
40
|
store
|
|
40
|
-
}));
|
|
41
|
+
}), path);
|
|
41
42
|
ctx.onClose(()=>store.shutdown?.());
|
|
42
43
|
}
|
|
43
44
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teikyo/rate-limit",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Rate limiting plugin for Sozai HTTP servers",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -19,18 +19,18 @@
|
|
|
19
19
|
"lib/*"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@sozai/http-server": "^0.2.
|
|
22
|
+
"@sozai/http-server": "^0.2.2",
|
|
23
23
|
"@teikyo/principal": "^0.1.0",
|
|
24
24
|
"hono-rate-limiter": "^0.5.4"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@types/node": "^26.6.6",
|
|
28
28
|
"del-cli": "^8.0.1",
|
|
29
|
-
"hono": "^4.13.
|
|
29
|
+
"hono": "^4.13.18",
|
|
30
30
|
"vitest": "5.1.0"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"hono": "^4.13.
|
|
33
|
+
"hono": "^4.13.18"
|
|
34
34
|
},
|
|
35
35
|
"engines": {
|
|
36
36
|
"node": ">=24"
|