feat(middleware): conditional execution, timeout, circuit breaker, RBAC & performance docs#386
Merged
phertyameen merged 1 commit intoMindBlockLabs:mainfrom Mar 27, 2026
Conversation
…reaker, RBAC, and performance docs Closes MindBlockLabs#381 — unless()/onlyFor() helpers for conditional middleware execution with exact, regex, and glob pattern support Closes MindBlockLabs#379 — TimeoutMiddleware (503 after configurable threshold) and CircuitBreakerMiddleware/Service (3-state CLOSED→OPEN→HALF_OPEN machine) Closes MindBlockLabs#371 — rbacMiddleware() factory with role hierarchy (ADMIN>MODERATOR>USER), OR logic for multiple roles, and audit logging Closes MindBlockLabs#353 — docs/PERFORMANCE.md with 6 techniques (lazy init, JWT caching, short-circuit, async crypto, GC pressure, circuit breaker) and anti-patterns section 37 unit tests added; micromatch added for glob pattern matching.
|
@BigBen-7 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
phertyameen
approved these changes
Mar 27, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
unless()andonlyFor()higher-order wrappers supporting exact string, regex, and glob (micromatch) patterns with zero overhead on non-matching routesTimeoutMiddleware(503 after configurable ms threshold) +CircuitBreakerMiddleware/CircuitBreakerServiceimplementing the full CLOSED → OPEN → HALF_OPEN state machine with configurable failure threshold, reset timeout, and health-check state accessorrbacMiddleware()factory with ADMIN > MODERATOR > USER hierarchy, OR logic for multi-role routes, 403 with clear messages, and audit logging for unauthorized attemptsdocs/PERFORMANCE.mdwith 6 techniques (lazy init, JWT payload caching, short-circuit, async crypto, GC pressure reduction, circuit breaker under outages) and 3 anti-patterns, each with before/after snippets and benchmark deltasNew files
middleware/src/middleware/utils/conditional.middleware.tsmiddleware/src/middleware/advanced/timeout.middleware.tsmiddleware/src/middleware/advanced/circuit-breaker.middleware.tsmiddleware/src/auth/rbac.middleware.tsmiddleware/docs/PERFORMANCE.mdAll new exports are re-exported from
src/index.tsandsrc/auth/index.ts.Test plan
npm testpasses — 4 suites, 37 tests, 0 failuresunless(['/health'])skips middleware in an integration contextCloses #381
Closes #379
Closes #371
Closes #353