Add KYC expiration automation to kyc.worker - #187
Open
FroDev-CR wants to merge 1 commit into
Open
Conversation
- Add periodic EXPIRE_KYC_SUBMISSIONS job that scans APPROVED KYCSubmission rows with expiresAt <= now and transitions them to EXPIRED (idempotent, keyset-paginated, race-safe re-check inside the write transaction). - Reset the linked beneficiary to PENDING and write a KYC_EXPIRED audit log entry + KYC_STATUS_CHANGED webhook on each transition. - Notify beneficiaries by email/in-app when their KYC expires, and alert active admins/reviewers for high-risk (fraudScore-based) expirations. - Add configurable kycExpiration settings (cron interval, batch size, admin-alert threshold, feature flag). - Add KYC_EXPIRED to the NotificationType/AuditAction enums + migration, new kyc-expiration email template, and wire the worker into startup. - Add unit tests for expiration detection, status transition, idempotency, and notification dispatch; document the automation in ARCHITECTURE.md.
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 #91
Summary
Adds background automation to expire KYC submissions once their
expiresAtwindow has passed, and notifies affected beneficiaries — closing the gap where approved KYC could remain VALID indefinitely.Changes
kyc.worker.ts: new periodicEXPIRE_KYC_SUBMISSIONSjob (configurable cron, hourly by default) that scans APPROVEDKYCSubmissionrows withexpiresAt <= nowand transitions them toEXPIRED.KYC_EXPIREDaudit log entry, and dispatches aKYC_STATUS_CHANGEDwebhook.kycExpirationconfig block (cron interval, batch size, admin-alert threshold, feature flag) — all via env vars.KYC_EXPIREDtoNotificationType/AuditActionenums + migration, newkyc-expirationemail template, and wires the worker into app startup (it wasn't being started before).docs/ARCHITECTURE.md.Testing
Reviewed manually against existing patterns (moderation/analytics workers); added unit tests for
BeneficiaryService.expireKYCSubmissions,kyc.worker.tsjob orchestration, and notification service methods.