Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): Return api service level in rate limit headers (novuhq#4976)
* feat(shared): Add api rate limit configuration types and cosntants * feat(api): Add get-api-rate-limit-configuration use-case * refactor(api): Move get-api-rate-limit use case to rate-limiting module per PR feedback * fix(api): Add module import for get-api-rate-limit use case * fix(api): Remove redundant imports * feat(application-generic): Expose SADD and EVAL redis operations on cache service * feat(api): Add evaluate-api-rate-limit use cases * chore: Run pnpm install to resolve merge conflicts on lockfile * fix(api): Add better logging for rate limit evaluation error * test(api): Add tests for evaluate-api-rate-limit use-case * docs(api): Fix rate limit mock comment * docs(api): Add further clarification to rate limit evaluation mock * docs(api): Further mock redis eval clarification * fix(shared): Adjust typing of IApiRateLimitConfiguration to allow arbitrary configuration types * fix(shared): Rename refillInterval to windowDuration to align with rate limiting RFC nomenclature * feat(api): Expose refillRate, windowDuration, and burstLimit from evaluate-api-rate-limit use case * fix(api): Remove redundant ICacheService import * feat(api): Extract evaluate-api-rate-limit use-case typings * feat(api): Add ApiRateLimitGuard and related ThrottleCategory decorator * chore(api): Add @nestjs/throttler library * fix(api): Use enum for rate limit header keys * feat(api): Add runtime feature toggle and fix dependency injection on rate limit guard * feat(api): Add @nestjs/throttler and rate limit guard to RateLimitingModule * fix(api): Add rate limiting imports * feat(api): Extract default reflector metadata for rate limit guard * fix(application-generic): Use correct method params for eval, add mock client tests * chore(application-generic): Tidy up cache typings * feat(api): Return algorithm in rate limit execution * feat(api): Add support for bulk operation cost in rate limit execution * feat(api): Add variable cost rate limiting algorithm * feat(shared): Add default bulk cost for api rate limiting * feat(shared): Add bulk cost typing for api rate limiting * refactor(shared): Move rate limit flag from system-critical to feature-flags * refactor(application-generic): Convert rate limit flag from system-critical to feature-flags * feat(application-generic): Create custom provider for rate limit feature flag * chore(api, shared, application-generic): Rename api rate limiting feature flag for consistency * fix(app-generic): Rename api rate limiting file * feat(api): Add variable request type handling to throttler * feat(api): Add support use-cases for rate limit evaluation * chore(api): Revert accidental changes max-rate-limit use case * feat(api): Add bulk support to evaluate rate limit use case * chore(api, dal, shared): Rename API Rate Limiting enums and typings for consistency * fix(shared): Export rate limit types from index * fix(api): Add get-max-rate-limit command back * fix(api): Update rate limit use case imports * fix(app-gen): Fix mock cache SADD implementation to match return val of set operations * fix(api): Fix import for get max rate limit use-case test * fix(api): Remove unused refillRate result * fix(api): Use correct cost enum for evaluate rate limit use-case * fix(api): Tidy up throttler guard * feat(api): Modify token bucket algorithm to allow for variable cost * chore(api): Tidy up algo logic * chore(api): Fix comments on algo * feat(api): Add local caching back to rate limit algo * chore(api): Refactor token bucket algorithm into separate use-case * feat(api): Add modified token bucket rate limiter * fix(api): Make cache client adapter static and add tests * fix(api): Fix use-case tests * fix(api, shared): Use snake_case enum values for rate limit configuration * fix(api): Fix evaluate rate limit import * fix(api): Use enum value * fix(api): Fix bad enum reference * fix(api): Fix test describe naming * test(api): Add throttler guard test * test(api): Add more tests * feat(api): Add rate limit configuration environment variables * test(api): Fix burst limit calculation * fix(api): Make the createLimiter method functional * fix(api): Invalidate max rate limit cache entities when loading max limit config module * feat(app-gen): Add key builder for service config and tidy up base keygen locations * fix(api): Fix get-max-ratelimit usecase CachedEntity builder to use correct environment ID on * fix(api): Specify default limits on max-rate-limit class attribute * feat(api): Add environment and organization repository methods for api rate limits * test(api): Add test rate limit controller * feat(api): Add rate limit guard to app module * feat(api): Add strong typing to environment variables * feat(api): Convert rate limit guard to interceptor to provide auth context * test(api): Add rate limit guard tests * fix(api): Fix env vars in tests * fix(api): Consolidate algorithm into use-case * test(api): Rename rate limit test spec to e2e * fix(api): remove redundant e2e gitkeep * test(api): Add tests for variable-cost token bucket rate limiter * fix(api): Revert addition of variable-cost token bucket * fix(api): Address PR review comments * fix(api): Remove e2e tests for rate limiting temporarily * fix(api): Remove unused test case and import * fix(api): Revert package.json change * Revert "fix(api): Remove unused test case and import" This reverts commit b8ce7a4. * Revert "fix(api): Remove e2e tests for rate limiting temporarily" This reverts commit 5e91dc3. * fix(api): Remove failing throttler tests and modify expected reset * test(api): Add throttled request test * fix(api): Add cspell definitions for rate limiting * fix(api): Use rate limiter before idempotency interceptor * fix(api): Add comment on nestjs throttler config * test(api): update test * test(api): Add tolerance for throttled count * test(api): Fix tolerance for upstash * fix(api): Typo * fix(dal): Fix updateApiRateLimits return value * fix(api): Auto-generate name prefix * fix(api): Use invalidate by key instead of query * fix(api): Remove redundant import * fix(api): Fix cache invalidation test * feat(api): Apply rate limit category and cost decorators to api controllers and methods * fix(api): Fix typo * fix(api): Add separate before statements for unit and e2e tests * test(api): Use regex for variable policy header values * fix(api): Toggle launch darkly off to allow test to define FF state * fix(api): Fix launch darkly toggle off * feat(api): Add eslint rule to block @nestjs swagger ApiResponse decorator imports * feat(api): Add types and constants for common responses and headers * feat(api): Add swagger overrides for response decorators * feat(api): Add new openapi spec endpoint, add more api info * feat(api): Apply ApiCommonHeaders to all relevant controllers * fix(api): Remove unused import and update cspell * fix(api): Remove redundant satisfies * feat(api): Add header type generics * test(api): Add tests for http header enum types * fix(api): Fix spellcheck error * fix(api): Use compound words in spellcheck * fix(api): Increase error tolerance on rate limiting to reduce test flakiness * fix(api): Fix import * fix(api): Use non-ambient type for header enum type check function declaration * fix(api): Update swagger endpoint * fix(api): Rename swagger file in github action * refactor(infra): Rename Swagger to OpenAPI * refactor(infra): Rename again * refactor(infra): Rename gh action from swagger to openapi * docs(api): Add comment on swagger decorators * docs(api): Improve description * docs(api): Use informative description * docs(api): Formalise documentation link * docs(api): Fix description for api key scheme * refactor(api): Move swagger setup to separate module * fix(api): Remove duplication decorator * feat(api): Add descriptions and external reference documentation for each API tag * chore(infra): Use Spectral for API validation and style linting * feat(api): Add Spectral API linting * fix(api): Enable PORT override for package script * fix(api): Fix inconsistent endpoint param and override faulty endpoint * feat(api): Add passport apikey strategy * fix(api): Remove redundant check from roles guard * fix(api): Remove redundant authentication check from root env guard * fix(api): Remove redundant authentication check from session decorator * fix(api): Use user payload in throttler and idempotency interceptors * fix(api): Remove redundant logger assign in jwt strategy * fix(api): Remove redundant logger assign in trigger use-case * fix(app-gen): Update auth service to return expected auth validation user entities * fix(api): Update throttler guard to read from req.user * fix(app-gen): Remove log * fix(api): Add headerapikey to cspell * fix(api): Remove redundant log * revert(api): Auth guard authscheme checl * fix(api): Auth scheme resolution * Update apps/api/src/app/shared/framework/idempotency.interceptor.ts * feat(api): Return api service level in rate limit headers * fix(api): Remove custom from enum * fix(api): Revert accidental change * fix(api): Add catch for apiheader strategy * fix(api): Typesafe user handling in auth guard * feat(app-gen): Add custom user attributes to all logs * fix(api): Return false on error * revert(app-gen): Revert changes to trigger use-case logger assign * chore(api, app-gen, shared): Create reusable enums for auth scheme and auth strategy * chore(api, app-gen): Rename JwtAuthGuard to UserAuthGuard * fix(infra): Fix cspell * fix(api): Fix getApiKeyUser signature to match cache build signature * fix(api): Handle undefined user * test(api): Add auth guard tests * fix(api): More reuse of http header enum * fix(api): Header keys import * Revert "fix(api): Revert accidental change" This reverts commit 48a6805. * Revert "fix(api): Remove custom from enum" This reverts commit 81ef5ac. * revert rate limit change * Revert "revert rate limit change" This reverts commit c50321b. * Revert "Revert "fix(api): Remove custom from enum"" This reverts commit 8762ba2. * Revert "Revert "fix(api): Revert accidental change"" This reverts commit 139e860. * feat(api, app-gen): Add instrumentation for critical paths * chore(app-gen): Fix rxjs type annotation on auth guard * feat(api): Instrument throttler guard canActivate * fix(api): Remove unecessary type annotation * Update package.json
- Loading branch information