-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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(api): Add API rate limiting NestJS guard #4910
Merged
Merged
Changes from 172 commits
Commits
Show all changes
191 commits
Select commit
Hold shift + click to select a range
748b194
feat(dal, shared, api): Add DAL fields for rate limiting
rifont 4b47cce
test(api): Add tests for rate limit fields
rifont 75febc1
test(api): Use enum for apiServiceLevel test assertion
rifont 1e06a6d
Merge branch 'next' into nv-3058-rate-limiting-dtos
rifont 15035d0
fix(dal): Use api prefix for rate limits to differentiate from other …
rifont 81ef5b7
fix(dal): Update category enum to also include api prefix
rifont d9d86d9
fix(dal): Make apiRateLimits subdocument optional
rifont 05962ea
feat(shared): Add API rate limiting cache key builder
rifont 975df32
fix(dal): Add fallback unlimited tier
rifont e17ef8e
Merge branch 'nv-3058-rate-limiting-dtos' into nv-3059-get-rate-limit…
rifont 7618b62
feat(shared): Add rate limiting constants
rifont 1d5d7db
feat(api): Add get rate limit use case
rifont 15324a5
fix(api): Fix import path
rifont 642b046
test(application-generic): Refactor mock cache service into separate …
rifont acab424
test(api): Add unit tests for get-api-rate-limit use-case
rifont 167631f
fix(api): Remove unused LOG_CONTEXT declaration in get-api-rate-limit…
rifont 9cde897
feat(api): Add rate limiting module, add get-default-api-rate-limit u…
rifont 5b8a128
feat(shared): Add types for env var format and platform rate limit map
rifont 9f9cd55
refactor(api): Refactor get-api-rate-limit use-case to use the get-de…
rifont 72cf83b
Merge branch 'next' into nv-3059-get-rate-limit-use-case
rifont e5e7357
refactor(api, shared): Rename api rate limiting interface for descrip…
rifont e2a40cd
refactor(api): Rename get-api-rate-limit use-case helper method for c…
rifont 17a3bfb
Merge branch 'nv-3059-get-rate-limit-use-case' of ssh://github.com/no…
rifont de803e3
feat(api): Add logging to get-api-rate-limit use case
rifont d8de11e
fix(shared): Add missing newline
rifont e746b41
fix(api): Typo
rifont ad7e156
fix(api): Removed unused import in get-api-rate-limit use-case
rifont 06ce24b
refactor(api, application-generic): Rename max api rate limit cache key
rifont c065cf0
feat(application-generic): Add evaluate api rate limit cache key builder
rifont 310b877
fix(shared): Remove redundant import rename
rifont 7aa9adb
Merge branch 'nv-3059-get-rate-limit-use-case' into nv-3060-token-buc…
rifont 179586b
chore(shared): Remove redundant constant
rifont d2e6244
Merge branch 'nv-3059-get-rate-limit-use-case' into nv-3060-token-buc…
rifont bfa1fe2
refactor(shared): Create new rate limiting types folder
rifont 6ec497b
Merge branch 'nv-3059-get-rate-limit-use-case' into nv-3060-token-buc…
rifont 3a47eb4
fix(shared): Remove redundant satisfies operator
rifont bfcdc75
Merge branch 'nv-3059-get-rate-limit-use-case' into nv-3060-token-buc…
rifont c4a5120
chore(shared): Remove unused export in organization types
rifont 16703f6
Merge branch 'nv-3059-get-rate-limit-use-case' into nv-3060-token-buc…
rifont 4ea779d
feat(shared): Add api rate limit configuration types and cosntants
rifont 976a36a
feat(api): Add get-api-rate-limit-configuration use-case
rifont e3fb0c4
refactor(api): Move get-api-rate-limit use case to rate-limiting modu…
rifont a7d672b
fix(api): Add module import for get-api-rate-limit use case
rifont 32932a6
fix(api): Remove redundant imports
rifont cd1d75c
Merge branch 'nv-3059-get-rate-limit-use-case' into nv-3060-token-buc…
rifont ea9f0f6
feat(application-generic): Expose SADD and EVAL redis operations on c…
rifont 40e0470
feat(api): Add evaluate-api-rate-limit use cases
rifont 68a0c79
Merge branch 'next' into nv-3060-token-bucket-rate-limiting-use-case
rifont 34368ba
chore: Run pnpm install to resolve merge conflicts on lockfile
rifont dc4abd0
fix(api): Add better logging for rate limit evaluation error
rifont 944df01
test(api): Add tests for evaluate-api-rate-limit use-case
rifont 2831766
docs(api): Fix rate limit mock comment
rifont 2b86538
Merge branch 'next' into nv-3060-token-bucket-rate-limiting-use-case
rifont 104a0e7
docs(api): Add further clarification to rate limit evaluation mock
rifont 7fdb361
docs(api): Further mock redis eval clarification
rifont 530ede7
fix(shared): Adjust typing of IApiRateLimitConfiguration to allow arb…
rifont d6146d4
Merge branch 'next' into nv-3060-token-bucket-rate-limiting-use-case
rifont bd103e5
fix(shared): Rename refillInterval to windowDuration to align with ra…
rifont 5526b97
feat(api): Expose refillRate, windowDuration, and burstLimit from eva…
rifont 6537b71
fix(api): Remove redundant ICacheService import
rifont 232321e
feat(api): Extract evaluate-api-rate-limit use-case typings
rifont 36fa061
feat(api): Add ApiRateLimitGuard and related ThrottleCategory decorator
rifont ece2df4
chore(api): Add @nestjs/throttler library
rifont a7914e7
fix(api): Use enum for rate limit header keys
rifont 37546e8
feat(api): Add runtime feature toggle and fix dependency injection on…
rifont ad84552
feat(api): Add @nestjs/throttler and rate limit guard to RateLimiting…
rifont f63ae19
fix(api): Add rate limiting imports
rifont 4acf5e5
feat(api): Extract default reflector metadata for rate limit guard
rifont 9c6f8b0
fix(application-generic): Use correct method params for eval, add moc…
rifont e8085b0
chore(application-generic): Tidy up cache typings
rifont c8a241b
feat(api): Return algorithm in rate limit execution
rifont 622f0d6
feat(api): Add support for bulk operation cost in rate limit execution
rifont dee2a2b
feat(api): Add variable cost rate limiting algorithm
rifont dc4e664
feat(shared): Add default bulk cost for api rate limiting
rifont e48b042
feat(shared): Add bulk cost typing for api rate limiting
rifont 106a8d8
refactor(shared): Move rate limit flag from system-critical to featur…
rifont 1a8f58c
refactor(application-generic): Convert rate limit flag from system-cr…
rifont 1d45ece
feat(application-generic): Create custom provider for rate limit feat…
rifont 897119b
chore(api, shared, application-generic): Rename api rate limiting fea…
rifont 1087f5c
Merge branch 'next' into nv-3061-convert-rate-limit-ff-for-launchdarkly
rifont 0ed6fe8
fix(app-generic): Rename api rate limiting file
rifont 9bdaf9b
Merge branch 'nv-3061-convert-rate-limit-ff-for-launchdarkly' of ssh:…
rifont 462f2e5
Merge branch 'next' into nv-3061-convert-rate-limit-ff-for-launchdarkly
rifont 093a000
Merge branch 'nv-3060-token-bucket-rate-limiting-use-case' into nv-30…
rifont bdf05ca
Merge branch 'nv-3061-convert-rate-limit-ff-for-launchdarkly' into nv…
rifont ae80b28
feat(api): Add variable request type handling to throttler
rifont 2c609c4
feat(api): Add support use-cases for rate limit evaluation
rifont 137f6f1
chore(api): Revert accidental changes max-rate-limit use case
rifont d5d9203
feat(api): Add bulk support to evaluate rate limit use case
rifont 7db1dba
chore(api, dal, shared): Rename API Rate Limiting enums and typings f…
rifont 760b6fb
Merge branch 'nv-3060-consistent-rate-limit-naming' into nv-3060-toke…
rifont 30f2b5e
fix(shared): Export rate limit types from index
rifont b8b72ed
fix(api): Add get-max-rate-limit command back
rifont c8c5c28
fix(api): Update rate limit use case imports
rifont 10ca9d9
Merge branch 'nv-3060-consistent-rate-limit-naming' into nv-3060-toke…
rifont 7477b17
fix(app-gen): Fix mock cache SADD implementation to match return val …
rifont d941188
fix(api): Fix import for get max rate limit use-case test
rifont 1c24411
Merge branch 'nv-3060-consistent-rate-limit-naming' into nv-3060-toke…
rifont 7378ce4
Merge branch 'next' into nv-3061-rate-limiting-nestjs-guard
rifont e51ceca
Merge branch 'nv-3060-token-bucket-rate-limiting-use-case' into nv-30…
rifont 114e26c
fix(api): Remove unused refillRate result
rifont e6c718f
Merge branch 'next' into nv-3060-consistent-rate-limit-naming
rifont 8e5f87a
fix(api): Use correct cost enum for evaluate rate limit use-case
rifont 5b391e9
Merge branch 'next' into nv-3060-consistent-rate-limit-naming
rifont 20b74e8
fix(api): Tidy up throttler guard
rifont 545aa7e
feat(api): Modify token bucket algorithm to allow for variable cost
rifont fd9962b
Merge branch 'nv-3060-token-bucket-rate-limiting-use-case' into nv-30…
rifont 7f150f9
chore(api): Tidy up algo logic
rifont 9fd767f
chore(api): Fix comments on algo
rifont 925aefa
feat(api): Add local caching back to rate limit algo
rifont f6b6098
chore(api): Refactor token bucket algorithm into separate use-case
rifont 3fa6dff
Merge branch 'nv-3060-consistent-rate-limit-naming' into nv-3060-toke…
rifont f1835b6
Merge branch 'next' into nv-3060-token-bucket-rate-limiting-use-case
rifont 5551104
feat(api): Add modified token bucket rate limiter
rifont e3b5bf9
fix(api): Make cache client adapter static and add tests
rifont 5e2affb
fix(api): Fix use-case tests
rifont 359fed9
fix(api, shared): Use snake_case enum values for rate limit configura…
rifont 95f2ab6
Merge branch 'nv-3060-token-bucket-rate-limiting-use-case' into nv-30…
rifont 0ac42cc
fix(api): Fix evaluate rate limit import
rifont 8c11c8a
fix(api): Use enum value
rifont 0f9b163
Merge branch 'nv-3060-token-bucket-rate-limiting-use-case' into nv-30…
rifont 03ba15a
Merge branch 'nv-3060-modified-token-bucket-algorithm' into nv-3061-r…
rifont bc848ef
fix(api): Fix bad enum reference
rifont 5755611
Merge branch 'nv-3060-token-bucket-rate-limiting-use-case' into nv-30…
rifont c018948
Merge branch 'nv-3060-modified-token-bucket-algorithm' into nv-3061-r…
rifont dfb6c36
fix(api): Fix test describe naming
rifont 29489c7
Merge branch 'nv-3060-token-bucket-rate-limiting-use-case' into nv-30…
rifont b83edde
Merge branch 'nv-3060-modified-token-bucket-algorithm' into nv-3061-r…
rifont c9b89f9
test(api): Add throttler guard test
rifont 5905b2a
test(api): Add more tests
rifont 507a517
feat(api): Add rate limit configuration environment variables
rifont e1ea93e
Merge branch 'nv-3060-token-bucket-rate-limiting-use-case' into nv-30…
rifont ede3228
Merge branch 'nv-3060-modified-token-bucket-algorithm' into nv-3061-r…
rifont a34a946
test(api): Fix burst limit calculation
rifont d9721ab
fix(api): Make the createLimiter method functional
rifont 8615e7e
Merge branch 'nv-3060-token-bucket-rate-limiting-use-case' into nv-30…
rifont e3f3d9e
Merge branch 'nv-3060-modified-token-bucket-algorithm' into nv-3061-r…
rifont 0e8257c
fix(api): Invalidate max rate limit cache entities when loading max l…
rifont be1ca1e
feat(app-gen): Add key builder for service config and tidy up base ke…
rifont 7b2264a
fix(api): Fix get-max-ratelimit usecase CachedEntity builder to use c…
rifont a505889
Merge branch 'nv-3060-token-bucket-rate-limiting-use-case' into nv-30…
rifont 31de2ff
Merge branch 'nv-3060-modified-token-bucket-algorithm' into nv-3061-r…
rifont 301ca33
fix(api): Specify default limits on max-rate-limit class attribute
rifont dd8ccd1
feat(api): Add environment and organization repository methods for ap…
rifont f3c288b
test(api): Add test rate limit controller
rifont 223aee1
feat(api): Add rate limit guard to app module
rifont 97c6c0d
feat(api): Add strong typing to environment variables
rifont 752ade9
feat(api): Convert rate limit guard to interceptor to provide auth co…
rifont c9c8faf
test(api): Add rate limit guard tests
rifont 6c0bd50
fix(api): Fix env vars in tests
rifont d3a04e5
Merge branch 'nv-3060-token-bucket-rate-limiting-use-case' of ssh://g…
rifont 8a86a7f
Merge branch 'nv-3060-modified-token-bucket-algorithm' into nv-3060-t…
rifont a428fe6
fix(api): Consolidate algorithm into use-case
rifont d5ab65f
Merge branch 'nv-3060-token-bucket-rate-limiting-use-case' into nv-30…
rifont 1d7a289
Merge branch 'next' into nv-3060-token-bucket-rate-limiting-use-case
rifont 0509da9
test(api): Rename rate limit test spec to e2e
rifont deb01cf
Merge branch 'nv-3060-token-bucket-rate-limiting-use-case' into nv-30…
rifont 34ea4e6
fix(api): remove redundant e2e gitkeep
rifont ff1955a
test(api): Add tests for variable-cost token bucket rate limiter
rifont 0c18892
fix(api): Revert addition of variable-cost token bucket
rifont 3d83c03
Merge branch 'next' into nv-3060-token-bucket-rate-limiting-use-case
rifont 088cfae
fix(api): Address PR review comments
rifont 8603730
Merge branch 'nv-3060-token-bucket-rate-limiting-use-case' into nv-30…
rifont 5e91dc3
fix(api): Remove e2e tests for rate limiting temporarily
rifont b8ce7a4
fix(api): Remove unused test case and import
rifont 8255c3e
fix(api): Revert package.json change
rifont 7dc1352
Revert "fix(api): Remove unused test case and import"
rifont 4e84a20
Revert "fix(api): Remove e2e tests for rate limiting temporarily"
rifont 04b99f9
fix(api): Remove failing throttler tests and modify expected reset
rifont 9617a9f
test(api): Add throttled request test
rifont 64d6e4e
fix(api): Add cspell definitions for rate limiting
rifont b625403
fix(api): Use rate limiter before idempotency interceptor
rifont ef45dea
fix(api): Add comment on nestjs throttler config
rifont 69360ed
test(api): update test
rifont ac45a0e
test(api): Add tolerance for throttled count
rifont 3dc6a9d
test(api): Fix tolerance for upstash
rifont fab4042
fix(api): Typo
rifont ff165e3
Merge branch 'next' into nv-3061-rate-limiting-nestjs-guard
rifont 7edb9eb
fix(dal): Fix updateApiRateLimits return value
rifont c9ae745
fix(api): Auto-generate name prefix
rifont 650eb3a
fix(api): Use invalidate by key instead of query
rifont 963a041
fix(api): Remove redundant import
rifont 8781404
fix(api): Fix cache invalidation test
rifont 7d63579
Merge branch 'next' into nv-3061-rate-limiting-nestjs-guard
rifont 6af53c1
fix(api): Fix typo
rifont fd05a99
fix(api): Add separate before statements for unit and e2e tests
rifont 8d53cf2
test(api): Use regex for variable policy header values
rifont 588933c
fix(api): Toggle launch darkly off to allow test to define FF state
rifont d987263
fix(api): Fix launch darkly toggle off
rifont 001a40a
Merge branch 'next' into nv-3061-rate-limiting-nestjs-guard
rifont 828b9ad
fix(api): Increase error tolerance on rate limiting to reduce test fl…
rifont File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './throttler.decorator'; | ||
export * from './throttler.guard'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Reflector } from '@nestjs/core'; | ||
import { ApiRateLimitCategoryEnum, ApiRateLimitCostEnum } from '@novu/shared'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
export const ThrottlerCategory = Reflector.createDecorator<ApiRateLimitCategoryEnum>(); | ||
|
||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
export const ThrottlerCost = Reflector.createDecorator<ApiRateLimitCostEnum>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Custom decorators to specify custom costs and categories on both controllers and methods. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Placing before the idempotency interceptor so that idempotent requests are still subject to rate limiting.