@fonderie/rate-limit 3.0.0 → 4.0.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # @fonderie/rate-limit
2
2
 
3
- Distributed rate limiting for `@fonderie-js` — an atomic token bucket, backed
3
+ Distributed rate limiting for `@fonderiejs` — an atomic token bucket, backed
4
4
  by your PostgreSQL by default, with an in-memory store for single instances
5
5
  and a Redis store for very high volume. Emits standard `RateLimit-*` headers.
6
6
 
@@ -0,0 +1,21 @@
1
+ <!-- GENERATED — do not edit. Regenerate with: npm run docs:signatures -->
2
+
3
+ # @fonderie/rate-limit — outcomes
4
+
5
+ What this package does to a running app: tables its migrations create,
6
+ rows it seeds, routes it registers. Generated from the migration SQL and
7
+ route tables in source — trust this file instead of reading `dist/` or
8
+ downloading tarballs.
9
+
10
+ ## Database tables (after all migrations)
11
+
12
+ ### `fonderie_rate_limits`
13
+
14
+ ```sql
15
+ key TEXT NOT NULL PRIMARY KEY
16
+ tokens DOUBLE PRECISION NOT NULL
17
+ last_refill_ms DOUBLE PRECISION NOT NULL
18
+ granted BOOLEAN NOT NULL DEFAULT TRUE
19
+ ```
20
+
21
+ Raw SQL ships in `node_modules/@fonderie/rate-limit/dist/migrations/sql/` — read it there if you must; never download tarballs.
@@ -0,0 +1,63 @@
1
+ <!-- GENERATED — do not edit. Regenerate with: npm run docs:signatures -->
2
+
3
+ # @fonderie/rate-limit — signatures
4
+
5
+ ## @fonderie/rate-limit
6
+
7
+ Subpath exports: `@fonderie/rate-limit/migrations`
8
+
9
+ ```ts
10
+ interface IRateLimitRule {
11
+ capacity: number;
12
+ refillPerSec: number;
13
+ cost?: number;
14
+ }
15
+
16
+ interface IConsumeResult {
17
+ allowed: boolean;
18
+ remaining: number;
19
+ retryAfterMs: number;
20
+ }
21
+
22
+ interface IRateLimitStore {
23
+ consume(key: string, rule: IRateLimitRule): Promise<IConsumeResult>;
24
+ }
25
+
26
+ interface IRedisEvalClient {
27
+ eval(script: string, numKeys: number, ...keysAndArgs: (string | number)[]): Promise<unknown>;
28
+ }
29
+
30
+ function rateLimit(...limits: IRateLimitOptions[]): Middleware
31
+
32
+ function byIp(scope: string): KeyFn
33
+
34
+ function byBodyField(scope: string, field: string): KeyFn
35
+
36
+ interface IRateLimitOptions {
37
+ store: IRateLimitStore;
38
+ rule: IRateLimitRule;
39
+ key: KeyFn;
40
+ failClosed?: boolean;
41
+ }
42
+
43
+ type KeyFn = (ctx: IFonderieContext) => string | null;
44
+
45
+ new MemoryStore(): MemoryStore
46
+ .consume(key: string, rule: IRateLimitRule): Promise<IConsumeResult>
47
+ .size: number
48
+
49
+ new StoreAdapterStore(store: IStoreAdapter): StoreAdapterStore
50
+ .consume(key: string, rule: IRateLimitRule): Promise<IConsumeResult>
51
+
52
+ new RedisStore(client: IRedisEvalClient, keyPrefix?: string): RedisStore
53
+ .consume(key: string, rule: IRateLimitRule): Promise<IConsumeResult>
54
+
55
+ function consumeFromBucket(state: IBucketState | null, rule: IRateLimitRule, nowMs: number): { next: IBucketState; result: IConsumeResult; }
56
+
57
+ function fullRefillMs(rule: IRateLimitRule): number
58
+
59
+ interface IBucketState {
60
+ tokens: number;
61
+ lastRefillMs: number;
62
+ }
63
+ ```
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@fonderie/rate-limit",
3
- "version": "3.0.0",
4
- "description": "Distributed rate limiting for @fonderie-js — atomic token bucket over memory, PostgreSQL, or Redis, with standard RateLimit-* headers.",
3
+ "version": "4.0.1",
4
+ "description": "Distributed rate limiting for @fonderiejs — atomic token bucket over memory, PostgreSQL, or Redis, with standard RateLimit-* headers.",
5
5
  "keywords": [
6
- "fonderie-js",
6
+ "fonderiejs",
7
7
  "rate-limit",
8
8
  "token-bucket",
9
9
  "throttle",
@@ -39,7 +39,7 @@
39
39
  "check": "biome check --write src"
40
40
  },
41
41
  "peerDependencies": {
42
- "@fonderie/core": "^0.4.0",
42
+ "@fonderie/core": "^0.6.0",
43
43
  "@fonderie/store": "^0.2.0"
44
44
  },
45
45
  "peerDependenciesMeta": {
@@ -50,13 +50,13 @@
50
50
  "devDependencies": {
51
51
  "@fonderie/core": "../core",
52
52
  "@fonderie/store": "../store",
53
- "@types/node": "^25.6.0",
53
+ "@types/node": "^26.4.0",
54
54
  "tsup": "^8.5.1",
55
- "tsx": "^4.21.0",
55
+ "tsx": "^4.23.12",
56
56
  "typescript": "^6.0.3",
57
- "pg": "^8.13.3",
58
- "@types/pg": "^8.11.10",
59
- "redis": "^4.7.0"
57
+ "pg": "^8.23.0",
58
+ "@types/pg": "^8.21.0",
59
+ "redis": "^6.2.1"
60
60
  },
61
61
  "publishConfig": {
62
62
  "access": "public"
@@ -69,11 +69,11 @@
69
69
  ],
70
70
  "repository": {
71
71
  "type": "git",
72
- "url": "git+https://github.com/fonderiejs/sdk.git",
72
+ "url": "git+https://github.com/fonderiejs/fonderie.git",
73
73
  "directory": "packages/rate-limit"
74
74
  },
75
- "homepage": "https://github.com/fonderiejs/sdk/tree/main/packages/rate-limit#readme",
75
+ "homepage": "https://github.com/fonderiejs/fonderie/tree/main/packages/rate-limit#readme",
76
76
  "bugs": {
77
- "url": "https://github.com/fonderiejs/sdk/issues"
77
+ "url": "https://github.com/fonderiejs/fonderie/issues"
78
78
  }
79
79
  }