Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: Add fixedWindow, tokenBucket, and slidingWindow primitives #171

Closed
wants to merge 3 commits into from

Conversation

blaine-arcjet
Copy link
Contributor

feat!: Rework primitives to build rules with config & request details

This reworks Primitives to be a class that can construct a Rule based on a context + request details. This is due to including the requested token count on RateLimitRule, but it being passed as extra data to protect().

I think this API is good, but after completing it, I'm wondering if it is actually incorrect for the requested field to be attached to the RateLimitRule in the protobuf. Perhaps it should just be stuffed into our extra field on the request. I want to think about it some more over the weekend, but this is a start.

feat!: Rework primitives to build rules with config & request details
Copy link

trunk-io bot commented Feb 2, 2024

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

@blaine-arcjet
Copy link
Contributor Author

Closing in favor of #184 but this may be useful to review in the future if we need to wrap the rule creation in another factory.

trunk-io bot pushed a commit that referenced this pull request Feb 6, 2024
Replaces #171 

This adds the `fixedWindow`, `tokenBucket` and `slidingWindow` primitives. It keeps the `rateLimit()` primitive for backwards compatibility, but it is breaking because `protectSignup` was altered to require sliding window configurations.

The changes were streamlined by putting `requested` into the `extra` field of the RequestDetails. This allowed us to keep the same structure for specifying our Rules.

Draft because I need to add tests to maintain full test coverage and because it relies on #179, #180, #181, #182, and #183 (after which, I'll rebase all the cherry-picked commits out of this PR).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant