Skip to content

fix: re-check subscription before SES submission - #462

Open
vladbisceanu wants to merge 2 commits into
useplunk:nextfrom
vladbisceanu:upstream/133-unsubscribe-recheck
Open

fix: re-check subscription before SES submission#462
vladbisceanu wants to merge 2 commits into
useplunk:nextfrom
vladbisceanu:upstream/133-unsubscribe-recheck

Conversation

@vladbisceanu

Copy link
Copy Markdown

Queued marketing emails can outlive the subscription state checked when they were created. A contact who unsubscribes while an email waits in Redis can therefore still receive it.

This change re-reads the contact immediately before the SES call and suppresses the email when the latest state is unsubscribed. It preserves Plunk’s existing exemptions for transactional sends, headless transactional templates, and explicit recipient overrides. Marketing templates sent through the transactional endpoint remain subject to opt-out.

Verification:

  • yarn test:run apps/api/src/jobs/__tests__/email-processor.test.ts --maxWorkers=1 (15 tests)
  • focused ESLint
  • yarn build --filter=api

The final review noted the unavoidable gap between the database read and an external SES request. Holding a database lock across a network call would delay the unsubscribe transaction rather than make the two systems atomic, so this keeps the check at the last practical boundary before submission.

…cribe-recheck

# Conflicts:
#	apps/api/src/jobs/email-processor.ts
@vladbisceanu

Copy link
Copy Markdown
Author

Updated the branch to current next at e587599. The only conflict was the @plunk/db import in the email processor; the resolution keeps both the new campaign-cancellation guard and this PR’s fresh subscription check.

Verification on the merged tree:

  • email processor: 15 passed
  • campaign cancellation: 17 passed
  • focused ESLint: passed
  • yarn build --filter=api: 5/5 tasks passed

GitHub now reports the PR mergeable and waiting only for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant