Headlines: Added, Changed, Deprecated, Removed, Fixed, Security
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
- Plugins can now use an array of rates for the
rate
property, so limits like "1 per secord, 100 per hour" can be set. - New limiters:
CloudflareIPRateLimiter
andCloudflareIPUARateLimiter
that can be imported fromsveltekit-rate-limiter/limiters
.
- The
RateLimiterStore
interface now usesnumber
as second parameter to theadd
method.
- Some additional rate units:
2m | 5m | 10m | 45m
- Interfaces now uses
MaybePromise
instead ofPromise
.
- Plugins returning
null
weren't fully indeterminate: They will now limit the request only if no other limited have passed. As soon as another plugin passes, any subsequentnull
result will pass (for the current request).
- Added "extra data" type parameter for the rate limiter, so plugins can be provided information outside the request event. See README for an example.
- The "rates" object options (
IP
,IPUA
,cookie
) should now be set in the top of the configuration forRateLimiter
, no need for a nested object. - Deprecated the
ms
rate unit, it's not reliable due to OS timing issues.
- Added more units for milliseconds and seconds.
- Compatibility with SvelteKit 2.
- Hash function is now compatible with any environment that supports Web Crypto API, including Cloudflare workers. (Wasn't working properly in 0.4.0)
limiter.preflight
is now async and must be awaited!- Cookie limiter options now takes a
serializeOptions
, that can be used for customizing the cookie.
hashFunction
option, for custom hashing. Defaults to Web Crypto API SHA-256, will fallback to NodeJS crypto if not available.
- Hash function is now compatible with any environment that supports Web Crypto API, including Cloudflare workers.
- Added a
RetryAfterRateLimiter
, that provides information for setting a Retry-After header. - Added
clear
method to the rate limiters.
- Rate wasn't limited when
null
was returned last in chain.
- Added top-level export, to make vite/vitest satisfied.
- Removed
check
method fromRateLimiterStore
interface.
RateLimiterPlugin
can now returnnull
, as an indeterminate result.
RateLimiter
plugin chain wasn't immutable.
- Moved exports to
sveltekit-rate-limiter/server
.
- Added
isLimited
method.
- Removed
check
method, replaced byisLimited
which has the condition inverted!
RateLimiterPlugin
interface is now using a getter instead of readonly forrate
.
RateLimiterPlugin
can now returnboolean
, not justfalse
.
- Corrected exports
- Package updated
- Hash type is now
string
instead of an alias.