limitwall 1.0.0 → 1.0.2

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.
Files changed (2) hide show
  1. package/README.md +14 -14
  2. package/package.json +11 -9
package/README.md CHANGED
@@ -30,10 +30,10 @@ import { serve } from "@hono/node-server";
30
30
  import { Hono } from "hono";
31
31
  import { Redis } from "ioredis";
32
32
 
33
- import { rateLimiter, RedisStore } from "limitwall";
33
+ import { NodeRedisStore, rateLimiter } from "limitwall";
34
34
 
35
35
  const app = new Hono();
36
- const store = new RedisStore({ client: new Redis() });
36
+ const store = new NodeRedisStore({ client: new Redis() });
37
37
 
38
38
  app.use(
39
39
  "/api/*",
@@ -57,14 +57,14 @@ serve(app);
57
57
  import { Redis } from "@upstash/redis/cloudflare";
58
58
  import { Hono } from "hono";
59
59
 
60
- import { rateLimiter, UpstashStore } from "limitwall";
60
+ import { rateLimiter, UpstashRedisStore } from "limitwall";
61
61
 
62
62
  const app = new Hono<{
63
63
  Bindings: { UPSTASH_URL: string; UPSTASH_TOKEN: string };
64
64
  }>();
65
65
 
66
66
  app.use("/api/*", async (c, next) => {
67
- const store = new UpstashStore({
67
+ const store = new UpstashRedisStore({
68
68
  client: new Redis({ url: c.env.UPSTASH_URL, token: c.env.UPSTASH_TOKEN }),
69
69
  });
70
70
 
@@ -98,18 +98,18 @@ Every algorithm also accepts `ruleName` (required - namespaces its Redis keys) a
98
98
  ## Config reference
99
99
 
100
100
  ```ts
101
- rateLimiter({
102
- algorithm: "tokenBucket" | "fixedWindow" | "slidingWindow" | "leakyBucket",
103
- ruleName: string,
101
+ interface RateLimiterConfig {
102
+ algorithm: "tokenBucket" | "fixedWindow" | "slidingWindow" | "leakyBucket";
103
+ ruleName: string;
104
104
  // ...algorithm-specific fields, see table above
105
- cost?: number,
105
+ cost?: number;
106
106
 
107
- identifier: (c: Context) => string, // required - what to rate limit by
108
- store: RateLimitStore, // RedisStore or UpstashStore
109
- onError: "fail-open" | "fail-closed", // required - no silent default
110
- headerStyle?: "draft-6" | "draft-7", // defaults to "draft-6"
111
- message?: (c: Context) => Response, // overrides the default 429 body
112
- });
107
+ identifier: (c: Context) => string; // required - what to rate limit by
108
+ store: RateLimitStore; // NodeRedisStore or UpstashRedisStore
109
+ onError: "fail-open" | "fail-closed"; // required - no silent default
110
+ headerStyle?: "draft-6" | "draft-7"; // defaults to "draft-6"
111
+ message?: (c: Context) => Response; // overrides the default 429 body
112
+ }
113
113
  ```
114
114
 
115
115
  ## Response headers
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "limitwall",
3
3
  "type": "module",
4
- "version": "1.0.0",
4
+ "version": "1.0.2",
5
+ "packageManager": "pnpm@12.5.1",
5
6
  "description": "Rate limiting middleware for Hono, backed by Redis. Fixed window, sliding window, token bucket, and leaky bucket (GCRA) in one package",
6
7
  "author": "Kevin Rozario",
7
8
  "license": "MIT",
@@ -47,6 +48,14 @@
47
48
  "engines": {
48
49
  "node": ">=20"
49
50
  },
51
+ "scripts": {
52
+ "build": "tsup",
53
+ "dev": "tsup --watch",
54
+ "test": "vitest run",
55
+ "lint": "eslint .",
56
+ "lint:fix": "eslint . --fix",
57
+ "prepublishOnly": "pnpm run build"
58
+ },
50
59
  "peerDependencies": {
51
60
  "@upstash/redis": ">=1",
52
61
  "hono": ">=4",
@@ -72,12 +81,5 @@
72
81
  "tsup": "^8",
73
82
  "typescript": "^5",
74
83
  "vitest": "^2"
75
- },
76
- "scripts": {
77
- "build": "tsup",
78
- "dev": "tsup --watch",
79
- "test": "vitest run",
80
- "lint": "eslint .",
81
- "lint:fix": "eslint . --fix"
82
84
  }
83
- }
85
+ }