@lunora/ratelimit 1.0.0-alpha.5 → 1.0.0-alpha.6
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/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { availableAt, evaluate } from './packem_shared/availableAt-DN3Z6h_K.mjs';
|
|
2
|
-
export { default as dbRateLimit } from './packem_shared/dbRateLimit-
|
|
2
|
+
export { default as dbRateLimit } from './packem_shared/dbRateLimit-ChciceZm.mjs';
|
|
3
3
|
export { default as RateLimitError } from './packem_shared/RateLimitError-53bWrDuJ.mjs';
|
|
4
|
-
export { rateLimit } from './packem_shared/rateLimit-
|
|
4
|
+
export { rateLimit } from './packem_shared/rateLimit-CTJq6iZx.mjs';
|
|
5
5
|
export { ratelimitPlugin } from './packem_shared/ratelimitPlugin-D5_-KV1T.mjs';
|
|
6
6
|
export { RateLimiter } from './packem_shared/RateLimiter-DQ9Peq-G.mjs';
|
|
7
7
|
export { createDbStore, createMemoryStore, createSqlStore } from './packem_shared/createDbStore-L1kD1g1n.mjs';
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { LunoraError } from '@lunora/errors';
|
|
2
|
+
|
|
1
3
|
const STATUS_BY_REASON = {
|
|
2
4
|
deny: { code: "FORBIDDEN", status: 403 },
|
|
3
5
|
rate: { code: "TOO_MANY_REQUESTS", status: 429 }
|
|
@@ -18,22 +20,15 @@ const rateLimit = (limiter, name, options = {}) => async ({ ctx, next }) => {
|
|
|
18
20
|
if (options.failOpen) {
|
|
19
21
|
return next();
|
|
20
22
|
}
|
|
21
|
-
throw
|
|
22
|
-
cause: error,
|
|
23
|
-
code: "SERVICE_UNAVAILABLE",
|
|
24
|
-
name: "LunoraError",
|
|
25
|
-
status: 503
|
|
26
|
-
});
|
|
23
|
+
throw new LunoraError("SERVICE_UNAVAILABLE", `rate limiter unavailable for "${name}"`, { cause: error, status: 503 });
|
|
27
24
|
}
|
|
28
25
|
if (!status.ok) {
|
|
29
26
|
const reason = status.reason ?? "rate";
|
|
30
27
|
const mapped = STATUS_BY_REASON[reason];
|
|
31
28
|
const retryAfter = Number.isFinite(status.retryAfter) ? Math.ceil(status.retryAfter) : void 0;
|
|
32
|
-
throw
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
retryAfter,
|
|
36
|
-
status: mapped.status
|
|
29
|
+
throw new LunoraError(mapped.code, options.message ?? defaultMessage(name, reason, retryAfter), {
|
|
30
|
+
status: mapped.status,
|
|
31
|
+
data: retryAfter === void 0 ? void 0 : { retryAfter }
|
|
37
32
|
});
|
|
38
33
|
}
|
|
39
34
|
return next();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/ratelimit",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.6",
|
|
4
4
|
"description": "Rate limiting: token-bucket / fixed-window / sliding-window algorithms, deny list, sharding, pluggable stores, and procedure middleware",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"access": "public"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@lunora/errors": "1.0.0-alpha.
|
|
49
|
+
"@lunora/errors": "1.0.0-alpha.3"
|
|
50
50
|
},
|
|
51
51
|
"engines": {
|
|
52
52
|
"node": "^22.15.0 || >=24.11.0"
|