Skip to content

Commit 45b27fc

Browse files
authored
Merge branch 'main' into feat/issue-91-role-based-admin
2 parents 6749e53 + 4cb3024 commit 45b27fc

44 files changed

Lines changed: 3473 additions & 271 deletions

Some content is hidden

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

.gitignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Node.js
2+
node_modules/
3+
4+
# Logs
5+
logs
6+
*.log
7+
npm-debug.log*
8+
9+
# Editor directories and files
10+
.vscode/
11+
.idea/
12+
*.suo
13+
*.ntvs*
14+
*.njsproj
15+
*.sln
16+
*.sw?

.vscode/settings.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{
2+
}

LINTING_FIXES.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Linting Fixes Applied
2+
3+
## Issues Found in CI
4+
5+
### Error (1)
6+
**File**: `apps/backend/src/modules/escrow/services/escrow.service.ts`
7+
**Line**: 297
8+
**Issue**: Unsafe argument of type error typed assigned to a parameter of type `EscrowEventType`
9+
**Error Code**: `@typescript-eslint/no-unsafe-argument`
10+
11+
**Root Cause**: Missing closing parenthesis in `logEvent()` method call
12+
13+
**Fix Applied**:
14+
```typescript
15+
// Before (missing closing parenthesis)
16+
await this.logEvent(
17+
id,
18+
EscrowEventType.EXPIRED,
19+
userId,
20+
{
21+
reason: dto.reason || 'Deadline exceeded',
22+
previousStatus: escrow.status,
23+
expiresAt: escrow.expiresAt,
24+
expiredAt: now,
25+
},
26+
ipAddress,
27+
28+
// After (added closing parenthesis)
29+
await this.logEvent(
30+
id,
31+
EscrowEventType.EXPIRED,
32+
userId,
33+
{
34+
reason: dto.reason || 'Deadline exceeded',
35+
previousStatus: escrow.status,
36+
expiresAt: escrow.expiresAt,
37+
expiredAt: now,
38+
},
39+
ipAddress,
40+
);
41+
```
42+
43+
### Warnings (5)
44+
**File**: `apps/backend/src/modules/escrow/services/escrow.service.spec.ts`
45+
**Lines**: 397, 421, 509, 539, 566
46+
**Issue**: Unsafe argument of type `any` assigned to a parameter of type `UpdateResult | Promise<UpdateResult>`
47+
**Error Code**: `@typescript-eslint/no-unsafe-argument`
48+
49+
**Root Cause**: Using `as any` type casting for UpdateResult mocks
50+
51+
**Fix Applied**:
52+
```typescript
53+
// Before
54+
escrowRepository.update.mockResolvedValue({ affected: 1 } as any);
55+
56+
// After
57+
escrowRepository.update.mockResolvedValue({ affected: 1 } as UpdateResult);
58+
```
59+
60+
**Locations Fixed**:
61+
1. Line 393 - `fileDispute` test
62+
2. Line 419 - `fileDispute` by seller test
63+
3. Line 505 - `resolveDispute` with RELEASED_TO_SELLER test
64+
4. Line 530 - `resolveDispute` with CANCELLED test
65+
5. Line 556 - `resolveDispute` with SPLIT test
66+
67+
## Verification
68+
69+
✅ TypeScript diagnostics: No errors
70+
✅ All type casts properly typed
71+
✅ Syntax errors resolved
72+
✅ Code follows TypeScript strict mode rules
73+
74+
## Commit Details
75+
76+
**Commit**: d7bcb27
77+
**Message**: "fix: resolve linting errors in escrow service"
78+
**Files Changed**: 3
79+
- `PR_DETAILS.md` (new)
80+
- `apps/backend/src/modules/escrow/services/escrow.service.spec.ts` (modified)
81+
- `apps/backend/src/modules/escrow/services/escrow.service.ts` (modified)
82+
83+
## CI Status
84+
85+
The fixes have been pushed to the `feature/deadline-enforcement` branch.
86+
CI should now pass the linting checks.

PR_DETAILS.md

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
# Pull Request: Deadline Enforcement for Escrows
2+
3+
## 🔗 Create PR Link
4+
https://github.com/DavisVT/Vaultix/pull/new/feature/deadline-enforcement
5+
6+
## 📋 PR Title
7+
```
8+
feat: Implement comprehensive deadline enforcement for escrows
9+
```
10+
11+
## 📝 PR Description
12+
13+
```markdown
14+
## Overview
15+
This PR implements comprehensive deadline enforcement to prevent escrows from remaining in limbo indefinitely.
16+
17+
## Changes Made
18+
19+
### Core Implementation
20+
- ✅ Added `EXPIRED` status as a terminal state
21+
- ✅ Created `POST /escrows/:id/expire` endpoint
22+
- ✅ Updated state machine to support expiration transitions
23+
- ✅ Added guards preventing operations on expired escrows
24+
- ✅ Updated scheduler to auto-expire overdue escrows
25+
26+
### Key Features
27+
- **Explicit Lifecycle Rules**: PENDING/ACTIVE/DISPUTED → EXPIRED (terminal)
28+
- **Authorization**: Only depositor (creator) or arbitrator can trigger expiration
29+
- **Deadline Validation**: Must have `expiresAt` and current time must exceed it
30+
- **Automatic Processing**: Hourly cron job auto-expires overdue escrows
31+
- **Operation Guards**: Blocks fulfill, confirm, and release on expired escrows
32+
- **Event Tracking**: Full audit trail with EXPIRED events and webhooks
33+
34+
### Testing
35+
- ✅ 8 comprehensive service tests covering all scenarios
36+
- ✅ 5 state machine tests for EXPIRED transitions
37+
- ✅ All tests validate authorization, timing, and edge cases
38+
- ✅ No TypeScript diagnostics errors
39+
40+
### Documentation
41+
- 📄 `DEADLINE_ENFORCEMENT.md` - Comprehensive implementation guide
42+
- 📄 `EXPIRATION_EXAMPLE.md` - Practical usage examples
43+
- 📄 `QUICK_REFERENCE_EXPIRATION.md` - Developer quick reference
44+
- 📄 `DEADLINE_ENFORCEMENT_CHANGES.md` - Detailed change summary
45+
- 📄 `IMPLEMENTATION_CHECKLIST.md` - Deployment checklist
46+
47+
## Requirements Fulfilled
48+
49+
✅ Define clear lifecycle phases with EXPIRED state
50+
✅ Implement deadline-based behaviors using current time
51+
✅ Allow depositor to trigger timeout resolution
52+
✅ Allow arbitrator to trigger expiration
53+
✅ Enforce invariants (no ops after expiry, no expiry of terminal states)
54+
✅ Emit EXPIRED events with full context
55+
✅ Handle interactions with disputes and conditions
56+
✅ Comprehensive test coverage
57+
58+
## API Changes
59+
60+
### New Endpoint
61+
```http
62+
POST /escrows/:id/expire
63+
Authorization: Bearer <token>
64+
Content-Type: application/json
65+
66+
{
67+
"reason": "optional"
68+
}
69+
```
70+
71+
### New Status
72+
- `EXPIRED` - Terminal state for overdue escrows
73+
74+
### Blocked Operations After Expiry
75+
- ❌ Fulfill conditions
76+
- ❌ Confirm conditions
77+
- ❌ Release escrow
78+
79+
## Files Changed (14 files, +1005 lines, -14 lines)
80+
81+
### New Files
82+
- `apps/backend/DEADLINE_ENFORCEMENT_CHANGES.md`
83+
- `apps/backend/IMPLEMENTATION_CHECKLIST.md`
84+
- `apps/backend/docs/DEADLINE_ENFORCEMENT.md`
85+
- `apps/backend/docs/EXPIRATION_EXAMPLE.md`
86+
- `apps/backend/docs/QUICK_REFERENCE_EXPIRATION.md`
87+
- `apps/backend/src/modules/escrow/dto/expire-escrow.dto.ts`
88+
89+
### Modified Files
90+
- `apps/backend/src/modules/escrow/controllers/escrow.controller.ts`
91+
- `apps/backend/src/modules/escrow/entities/escrow-event.entity.ts`
92+
- `apps/backend/src/modules/escrow/entities/escrow.entity.ts`
93+
- `apps/backend/src/modules/escrow/escrow-state-machine.spec.ts`
94+
- `apps/backend/src/modules/escrow/escrow-state-machine.ts`
95+
- `apps/backend/src/modules/escrow/services/escrow-scheduler.service.ts`
96+
- `apps/backend/src/modules/escrow/services/escrow.service.spec.ts`
97+
- `apps/backend/src/modules/escrow/services/escrow.service.ts`
98+
99+
## Migration Impact
100+
- ✅ Backward compatible
101+
- ✅ No database migration required
102+
- ✅ Existing escrows without `expiresAt` unaffected
103+
- ⚠️ Requires app restart to load new enum values
104+
105+
## Testing Instructions
106+
107+
### Manual Testing
108+
1. Create escrow with deadline in the past
109+
2. Call `POST /escrows/:id/expire` as depositor
110+
3. Verify status changed to EXPIRED
111+
4. Try to fulfill/confirm conditions (should fail with 400)
112+
5. Check events table for EXPIRED event
113+
6. Verify webhook dispatched
114+
115+
### Automated Testing
116+
```bash
117+
cd apps/backend
118+
npm test -- escrow.service.spec.ts
119+
npm test -- escrow-state-machine.spec.ts
120+
```
121+
122+
## Deployment Checklist
123+
- [ ] Review code changes
124+
- [ ] Run full test suite
125+
- [ ] Deploy to staging
126+
- [ ] Test scheduler execution
127+
- [ ] Verify webhook delivery
128+
- [ ] Update API documentation
129+
- [ ] Notify frontend team
130+
- [ ] Deploy to production
131+
- [ ] Monitor logs
132+
133+
## Checklist
134+
- [x] Code follows project style guidelines
135+
- [x] Tests added and passing
136+
- [x] Documentation updated
137+
- [x] No TypeScript errors
138+
- [x] Backward compatible
139+
- [x] Ready for review
140+
141+
## Screenshots/Examples
142+
See `apps/backend/docs/EXPIRATION_EXAMPLE.md` for detailed usage examples.
143+
144+
## Related Issues
145+
Closes deadline enforcement requirements for preventing escrows from remaining in limbo indefinitely.
146+
```
147+
148+
## 🚀 Next Steps
149+
150+
1. Open the link above in your browser
151+
2. Copy the PR description from this file
152+
3. Paste it into the PR description field
153+
4. Click "Create Pull Request"
154+
5. Request reviews from team members
155+
6. Address any feedback
156+
7. Merge when approved
157+
158+
## 📊 Summary
159+
160+
- **Branch**: `feature/deadline-enforcement`
161+
- **Base**: `main`
162+
- **Files Changed**: 14
163+
- **Lines Added**: 1005
164+
- **Lines Removed**: 14
165+
- **Tests Added**: 13
166+
- **Documentation Files**: 5

0 commit comments

Comments
 (0)