@voltro/plugin-ratelimit 0.69.1 → 0.71.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.
package/README.md CHANGED
@@ -20,14 +20,6 @@ Installation, guides, the full API reference, and examples all live in the
20
20
  **[Voltro documentation](https://docs.voltro.dev/docs/intro/getting-started)** — the single source of truth. This README is
21
21
  deliberately short so there is nothing here to drift out of date.
22
22
 
23
- ## Inspection
24
-
25
- Both dashboards expose declared rules and process-local decisions under **Rate
26
- limits**, with an explicit choice for multiple instances. The read-only
27
- `GET /state` inspect endpoint distinguishes actual checks from requests passed
28
- through an unbound or failing store. See the [inspection guide](https://docs.voltro.dev/docs/plugins/ratelimit#inspect-rate-limits)
29
- for scope, privacy and custom-store decision reporting.
30
-
31
23
  ## License
32
24
 
33
25
  Proprietary. © 2026 Voltro UG. Your use is governed by the
package/dist/index.d.ts CHANGED
@@ -95,6 +95,15 @@ export declare interface RateLimitContext {
95
95
  /** Convenience: the subject's tenant (`null` only for unscoped anonymous). */
96
96
  readonly tenantId: string | null;
97
97
  readonly traceId: string;
98
+ /** `'rest'` when the call came through the `publicApi` projection; absent
99
+ * on the rpc wire. */
100
+ readonly surface?: 'rest';
101
+ /** The descriptor's own `publicApi.rateLimit`, on a projected call — the
102
+ * endpoint's rule for that surface, ahead of `rules` and `default`. */
103
+ readonly publicApiRateLimit?: {
104
+ readonly limit: number;
105
+ readonly window: string;
106
+ };
98
107
  }
99
108
 
100
109
  export declare interface RateLimitDecision {
package/dist/index.js CHANGED
@@ -177,8 +177,29 @@ var l = (e) => typeof e == "function" ? "dynamic" : e, u = (e) => typeof e == "f
177
177
  kind: e.kind,
178
178
  subject: e.subject,
179
179
  tenantId: e.subject.tenantId ?? null,
180
- traceId: e.traceId
181
- }), A = a({ scope: "voltro:ratelimit" }), j = (n = {}) => {
180
+ traceId: e.traceId,
181
+ ...e.surface === void 0 ? {} : { surface: e.surface },
182
+ ...e.surface === "rest" && e.publicApi?.rateLimit !== void 0 ? { publicApiRateLimit: e.publicApi.rateLimit } : {}
183
+ }), A = (e) => e.publicApiRateLimit === void 0 ? void 0 : {
184
+ ruleId: "publicApi",
185
+ effective: {
186
+ limit: e.publicApiRateLimit.limit,
187
+ window: e.publicApiRateLimit.window,
188
+ algorithm: void 0,
189
+ burst: void 0,
190
+ by: "subject",
191
+ scope: "tag",
192
+ disabled: !1
193
+ }
194
+ }, j = (e) => {
195
+ let t = e, n = Date.now();
196
+ return {
197
+ "retry-after": String(Math.max(1, Math.ceil(t.retryAfterMs / 1e3))),
198
+ "ratelimit-limit": String(t.limit),
199
+ "ratelimit-remaining": "0",
200
+ "ratelimit-reset": String(Math.max(0, Math.ceil((t.resetAtMs - n) / 1e3)))
201
+ };
202
+ }, M = a({ scope: "voltro:ratelimit" }), N = (n = {}) => {
182
203
  let a = n.rules ?? [], l = n.store === void 0 || n.store === "memory" ? m() : n.store === "postgres" ? g() : n.store === "redis" ? r() : n.store, u = p(n, l), d = (e) => {
183
204
  let t = n.enabled;
184
205
  return t === void 0 ? !0 : typeof t == "function" ? t(e) : t;
@@ -205,7 +226,7 @@ var l = (e) => typeof e == "function" ? "dynamic" : e, u = (e) => typeof e == "f
205
226
  }, _ = (t, r) => i.suspend(() => {
206
227
  let o = k(r);
207
228
  if (!d(o)) return u.bypass(), t;
208
- let s = C(a, n.default, o);
229
+ let s = A(o) ?? C(a, n.default, o);
209
230
  if (!s || s.effective.disabled) return u.bypass(), t;
210
231
  let c = E(w(s.effective, o));
211
232
  return h(o, c).pipe(i.flatMap((n) => {
@@ -241,7 +262,7 @@ var l = (e) => typeof e == "function" ? "dynamic" : e, u = (e) => typeof e == "f
241
262
  remaining: 0,
242
263
  resetAtMs: c,
243
264
  retryAfterMs: 0
244
- }), A.warn("http shield store failure — request ALLOWED without a limit check", { cause: String(t) }), e();
265
+ }), M.warn("http shield store failure — request ALLOWED without a limit check", { cause: String(t) }), e();
245
266
  }
246
267
  u.record("http", d);
247
268
  let f = String(Math.max(0, Math.ceil((d.resetAtMs - c) / 1e3)));
@@ -319,6 +340,10 @@ var l = (e) => typeof e == "function" ? "dynamic" : e, u = (e) => typeof e == "f
319
340
  import: {
320
341
  module: "@voltro/plugin-ratelimit/errors",
321
342
  name: "RateLimited"
343
+ },
344
+ rest: {
345
+ status: 429,
346
+ headers: j
322
347
  }
323
348
  }],
324
349
  interceptMutation: _,
@@ -348,4 +373,4 @@ var l = (e) => typeof e == "function" ? "dynamic" : e, u = (e) => typeof e == "f
348
373
  });
349
374
  };
350
375
  //#endregion
351
- export { e as RateLimited, n as consumeBucket, m as memoryStore, t as parseWindow, j as rateLimitPlugin, r as redisStore };
376
+ export { e as RateLimited, n as consumeBucket, m as memoryStore, t as parseWindow, N as rateLimitPlugin, r as redisStore };
@@ -8,28 +8,32 @@ var n = "\nlocal key = KEYS[1]\nlocal algo = ARGV[1]\nlocal limit = tonumber(ARG
8
8
  remaining: e.limit,
9
9
  resetAtMs: t + e.windowMs,
10
10
  retryAfterMs: 0
11
- });
11
+ }), c, l = (e) => r.url ?? e.RATELIMIT_REDIS_URL ?? e.CACHE_REDIS_URL ?? e.REDIS_URL, u = (n) => a ? Promise.resolve() : (c === void 0 && (c = (async () => {
12
+ let i = l(n);
13
+ if (!i) throw Error("@voltro/plugin-ratelimit redisStore: no client and no url (set RATELIMIT_REDIS_URL / REDIS_URL or pass { url }).");
14
+ let s = r.driver ?? ((n.RATELIMIT_REDIS_DRIVER ?? n.CACHE_REDIS_DRIVER) === "http" ? "http" : "resp"), c = r.token ?? n.RATELIMIT_REDIS_TOKEN ?? n.CACHE_REDIS_TOKEN ?? n.UPSTASH_REDIS_REST_TOKEN, u = {
15
+ url: i,
16
+ driver: s,
17
+ ...c === void 0 ? {} : { token: c }
18
+ };
19
+ a = await e.runPromise(t(u)), o = !0;
20
+ })().finally(() => {
21
+ c = void 0;
22
+ })), c), d = (t, r, o) => {
23
+ let c = a;
24
+ return c ? e.tryPromise(async () => {
25
+ let e = await c.eval(n, 1, `${i}${t}`, r.algorithm, r.limit, r.windowMs, r.burst, o);
26
+ return JSON.parse(String(e));
27
+ }).pipe(e.catchAll(() => e.succeed(s(r, o, "store-error")))) : e.succeed(s(r, o, "unbound"));
28
+ };
12
29
  return {
13
- consume: (t, r, o) => {
14
- let c = a;
15
- return c ? e.tryPromise(async () => {
16
- let e = await c.eval(n, 1, `${i}${t}`, r.algorithm, r.limit, r.windowMs, r.burst, o);
17
- return JSON.parse(String(e));
18
- }).pipe(e.catchAll(() => e.succeed(s(r, o, "store-error")))) : e.succeed(s(r, o, "unbound"));
19
- },
30
+ consume: (t, n, r) => a ? d(t, n, r) : l(process.env) === void 0 ? e.succeed(s(n, r, "unbound")) : e.tryPromise(() => u(process.env)).pipe(e.matchEffect({
31
+ onFailure: () => e.succeed(s(n, r, "store-error")),
32
+ onSuccess: () => d(t, n, r)
33
+ })),
20
34
  sweep: () => {},
21
35
  size: () => -1,
22
- activate: async (n) => {
23
- if (a) return;
24
- let i = r.url ?? n.RATELIMIT_REDIS_URL ?? n.CACHE_REDIS_URL ?? n.REDIS_URL;
25
- if (!i) throw Error("@voltro/plugin-ratelimit redisStore: no client and no url (set RATELIMIT_REDIS_URL / REDIS_URL or pass { url }).");
26
- let s = r.driver ?? ((n.RATELIMIT_REDIS_DRIVER ?? n.CACHE_REDIS_DRIVER) === "http" ? "http" : "resp"), c = r.token ?? n.RATELIMIT_REDIS_TOKEN ?? n.CACHE_REDIS_TOKEN ?? n.UPSTASH_REDIS_REST_TOKEN, l = {
27
- url: i,
28
- driver: s,
29
- ...c === void 0 ? {} : { token: c }
30
- };
31
- a = await e.runPromise(t(l)), o = !0;
32
- },
36
+ activate: (e) => u(e),
33
37
  deactivate: async () => {
34
38
  let e = a;
35
39
  a = null, e && o && await e.close();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voltro/plugin-ratelimit",
3
- "version": "0.69.1",
3
+ "version": "0.71.0",
4
4
  "description": "Rate-limiting plugin — per-endpoint, per-subject and per-tenant request limits via the RPC interceptors. Highly configurable rules (fixed-window / sliding-window / token-bucket), composite keying, static per-tenant overrides and a dynamic resolve() hook. Stores: memory (default, single-node), postgres + redis (multi-node, atomic).",
5
5
  "keywords": [
6
6
  "voltro",
@@ -48,9 +48,9 @@
48
48
  "node": ">=24.0.0"
49
49
  },
50
50
  "dependencies": {
51
- "@voltro/kv": "0.69.1",
52
- "@voltro/logger": "0.69.1",
53
- "@voltro/protocol": "0.69.1"
51
+ "@voltro/kv": "0.71.0",
52
+ "@voltro/logger": "0.71.0",
53
+ "@voltro/protocol": "0.71.0"
54
54
  },
55
55
  "optionalDependencies": {
56
56
  "@effect/sql": "^0.52.1"