feat(backend): platform-wide request validation contracts (#347)#457
Open
NickiM84 wants to merge 3 commits into
Open
feat(backend): platform-wide request validation contracts (#347)#457NickiM84 wants to merge 3 commits into
NickiM84 wants to merge 3 commits into
Conversation
…#347) - Add validation middleware with standardized error responses - Create reusable DTOs for auth, bot, transaction, and horizon proxy endpoints - Replace scattered manual validation with structured validation middleware - Fix orphaned liquidity route in routes.ts - Implement validateBody, validateQuery, validateParams helpers
…idation-v2 feat: platform-wide request validation contracts (gear5labs#347)
) Introduces a unified, typed contract surface for every HTTP request in the platform: ApiError factory + success helpers + reusable DTOs, the validateBody/validateQuery/validateParams middleware (Express 5 safe), and 30 unit tests covering the canonical error envelope and all DTO paths. * src/contracts/{errorContract,responseContract,dtos,index}.ts - ApiError factory + ApiErrorCode enum + success helpers (ok/created/noContent). - Reusable DTOs: IdParamDto, UserIdParamDto, SessionIdParamDto, IpAddressParamDto, UuidParamDto, PaginationQueryDto, PageQueryDto, DateRangeQueryDto, IpAddressBodyDto, BlacklistAddBodyDto, BlacklistBulkAddBodyDto, BlacklistListQueryDto, AuditLogListQueryDto. - @IsOptionalBooleanString + booleanFromStringTransform pair closes the class-transformer truthy-coerce footgun (?activeOnly=garbage). * src/Gateway/middleware/validation.ts - validateBody/Query/Params now throw ApiError.validationFailed, which the central ErrorHandler renders to the canonical envelope. - Shadows Express 5 getter-only req.query via Object.defineProperty. * src/{Auth,AuditLog,Security}/*.routes.ts - Mount the new validate* middleware and use the shared DTOs (LoginDto, PaginationQueryDto, BlacklistListQueryDto, BlacklistBulkAddBodyDto, AuditLogListQueryDto, IdParamDto, UserIdParamDto, IpAddressParamDto, etc.). * src/utils/{error,successResponse,expressAsync}.ts - Thin re-export shims from src/contracts for back-compat. * tests/unit/platformContracts.test.ts - 30 tests: ApiError envelope, ok/created/noContent helpers, every DTO path, garbage-rejection for @IsOptionalBooleanString, central ErrorHandler integration (incl. Postgres 23505 -> DUPLICATE_ENTRY). * docs/PLATFORM_VALIDATION_CONTRACTS.md - Wire-format / SDK-generator / OpenAPI rationale.
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.
Closes #347