Skip to content

Commit 41653e6

Browse files
authored
Merge branch 'main' into feat/policy-dashboard
2 parents cd25c75 + e3b2d08 commit 41653e6

119 files changed

Lines changed: 26362 additions & 8375 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CONTRIBUTING.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,28 @@ When adding new interactive components:
8383

8484
# Contributing
8585

86+
## Local prerequisites
87+
88+
### API E2E tests
89+
90+
The API E2E suite spins up real Postgres and Redis containers via [Testcontainers](https://testcontainers.com/). You need:
91+
92+
- **Docker Desktop** (or any Docker-compatible daemon) running locally.
93+
- Node 20+.
94+
95+
No `.env` file is needed — the global setup injects all ephemeral credentials at runtime.
96+
97+
```bash
98+
cd backend
99+
npm ci
100+
npx prisma generate
101+
npm run test:e2e
102+
```
103+
104+
The first run pulls `postgres:16-alpine` and `redis:7-alpine` (~100 MB total). Subsequent runs use the local Docker cache and start in seconds.
105+
106+
> **Tip:** If a test hangs, check that Docker is running: `docker info`.
107+
86108
## Soroban ABI golden vectors
87109

88110
The file `backend/src/soroban/golden-vectors.json` records the exact ScVal

TODO.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Issue #54: Backend Global Validation Policy - DTO Whitelisting & Consistent 400s
2+
3+
## Progress Tracker
4+
[DONE] Create branch `blackboxai/issue-54-global-validation-dto-whitelisting`
5+
[PENDING] 1. Update backend/src/common/filters/http-exception.filter.ts (custom ValidationError mapping to stable shape)
6+
[PENDING] 2. Read & decorate remaining DTOs:
7+
- backend/src/dto/policy.dto.ts (interfaces → classes + @Is*)
8+
- backend/src/claims/dto/claim.dto.ts
9+
- backend/src/auth/dto/challenge.dto.ts
10+
- backend/src/notifications/dto/update-preferences.dto.ts
11+
- backend/src/tx/dto/build-tx.dto.ts
12+
- backend/src/tx/dto/submit-tx.dto.ts
13+
- backend/src/support/dto/create-ticket.dto.ts
14+
- backend/src/admin/dto/audit-query.dto.ts, feature-flag.dto.ts, reindex.dto.ts
15+
- Others as found (e.g. health.dto.ts if request DTO)
16+
[PENDING] 3. Create/Update backend/README.md with validation error catalog & security notes
17+
[PENDING] 4. Commit changes
18+
[PENDING] 5. Push branch
19+
[PENDING] 6. Create PR
20+
21+
**Next:** Read key DTOs for decoration planning, then edit filter first.
22+

backend/README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# NiffyInsure Backend
2+
3+
NestJS API for Stellar-based insurance platform.
4+
5+
## Validation
6+
7+
Global `ValidationPipe` enabled with `whitelist: true, forbidNonWhitelisted: true`.
8+
9+
- **Unknown fields:** Rejected (400 VALIDATION_ERROR).
10+
- **Invalid values:** Field-specific errors.
11+
12+
### Error Shape (400 VALIDATION_ERROR)
13+
RFC7807-inspired for frontend i18n:
14+
15+
```json
16+
{
17+
"statusCode": 400,
18+
"error": {
19+
"type": "https://datatracker.ietf.org/doc/html/rfc7807#section-3.1",
20+
"code": "VALIDATION_ERROR",
21+
"title": "One or more validation errors occurred.",
22+
"violations": [
23+
{
24+
"field": "user.email",
25+
"code": "isEmail",
26+
"reason": "email must be an email"
27+
}
28+
]
29+
},
30+
"timestamp": "2024-...",
31+
"path": "/api/..."
32+
}
33+
```
34+
35+
**Common codes (i18n keys):**
36+
| Code | Meaning |
37+
|------|---------|
38+
| isDefined | Field required |
39+
| min | Too small |
40+
| max | Too large |
41+
| isEmail | Invalid email |
42+
| isUUID | Invalid UUID |
43+
| matches | Regex fail (e.g. Stellar pubkey `/^G[A-Z2-7]{55}$/`) |
44+
| isEnum | Invalid enum value |
45+
| isInt/isNumber | Not number |
46+
| length/minLength/maxLength | String length |
47+
| isPositive | ≤0 |
48+
49+
### Auth Errors (401/403)
50+
Generic `{statusCode, message}` (no violations – security: no hints).
51+
52+
### Security
53+
- **Mass-assignment:** Whitelist blocks unexpected fields.
54+
- **Type coercion:** `transform: true` safe (string→bool/num post-validation, no injection).
55+
- **Review:** All DTOs decorated; nested `@ValidateNested/@Type`.
56+
57+
## API
58+
See `/docs`.
59+
60+
## Local Dev
61+
```bash
62+
cd backend
63+
npm i
64+
npm run start:dev
65+
```
66+
67+
## Deployment
68+
Docker: `make docker-up`
69+
70+
See Makefile.
71+

0 commit comments

Comments
 (0)