Add transactional outbox table for vault lifecycle events in db/migrations and src/services/eventProcessor.ts
Description
src/services/eventProcessor.ts writes vault state and triggers notifications in the same flow, which loses notifications if the process crashes between the DB commit and the queue push. Add a transactional outbox: write events to a vault_outbox table within the same Prisma transaction, and let a separate worker dispatch them at-least-once.
Requirements and context
- Must be secure, tested, and documented
- Should be efficient and easy to review
- New Knex migration creating
vault_outbox(id, type, payload_json, created_at, dispatched_at)
- Add
OutboxDispatcher worker in src/jobs/handlers.ts
- Add
src/tests/outboxDispatcher.test.ts
- Update
docs/event-processing.md
- Reuse retry strategy from
src/utils/retry.ts
Suggested execution
- Fork the repo and create a branch
git checkout -b feat/vault-outbox
- Implement changes
- Add migration and Prisma model
- Update event processor
- Add tests and docs
- Test and commit
- Run
npm run migrate:latest && npm test
- Include test output and notes
Example commit message
feat: transactional outbox for vault lifecycle events
Guidelines
- Minimum 95 percent test coverage
- Clear documentation
- Timeframe: 96 hours
Add transactional outbox table for vault lifecycle events in db/migrations and src/services/eventProcessor.ts
Description
src/services/eventProcessor.tswrites vault state and triggers notifications in the same flow, which loses notifications if the process crashes between the DB commit and the queue push. Add a transactional outbox: write events to avault_outboxtable within the same Prisma transaction, and let a separate worker dispatch them at-least-once.Requirements and context
vault_outbox(id, type, payload_json, created_at, dispatched_at)OutboxDispatcherworker insrc/jobs/handlers.tssrc/tests/outboxDispatcher.test.tsdocs/event-processing.mdsrc/utils/retry.tsSuggested execution
git checkout -b feat/vault-outboxnpm run migrate:latest && npm testExample commit message
feat: transactional outbox for vault lifecycle eventsGuidelines