Repository navigation
feat(growth): one invite reminder after 5 days, and "your friend joined" notifications (#1397) - #1438
Merged
Merged
Conversation
…ed" notifications (#1397) Reminders: - _shared/invites/reminders.ts: an email invite sent ≥5 days ago that is still pending, unexpired and unreminded gets ONE reminder ("Reminder: <inviter> invited you to Scaffald", same link and note, marketing send). reminder_sent_at is stamped when it goes out and when it never can (suppressed, the person joined meanwhile), so nothing is reminded twice; NevarMail's daily cap or an outage leaves it for tomorrow and the cap ends the run. Phone invites are never reminded (Scaffald doesn't text). With no NevarMail use case configured nothing is sent or stamped. - invites-remind edge function (service-role only), daily 15:00 UTC from pg_cron via core.run_invite_reminders() (migration 400). Added to deploy-functions.sh, config.toml and the functions README. Notifications for the inviter (in-app, "See your invites" → /dashboard/invite): - referral.joined from POST /v1/invites/claim: "Jo joined Scaffald", named from the invite, else the new account. - referral.onboarded from POST /v1/prerequisites/complete: stamps referral_attributions.onboarded_at the first time and says "<Name> set up their profile". Neither can fail the request it rides on. - Migration 400 adds both to core.notification_type. Migration 401 fixes a long-standing bug this surfaced: the dedupe_key unique index (025) is partial, and PostgREST's ON CONFLICT can't target a partial index, so every insertNotification with a dedupe key failed with 42P10 and returned null. notify-publish passes one for every event that has it, so those notifications were never written ("Failed to insert notification"). A plain unique index enforces the same rule (NULLs stay distinct) and is a valid upsert target. Tests: gated invite-reminders-rest (due/too new/already reminded/ accepted/expired/phone/joined/suppressed, never twice, the cap defers, nothing without email config; joined + onboarded notifications through the real api, idempotent, no-invite onboarding untouched); reminder email unit test; notifications-operations, invites, RLS suites still green; edge-fn type ratchet within baseline (invites-remind 0). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
📊 Performance Benchmark Results |
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 #1397. Part of epic #1399. Also fixes an existing bug that silently dropped de-duplicated notifications (migration 401, below).
Reminders
_shared/invites/reminders.tssends one reminder per email invite. An invite qualifies when it was sent at least 5 days ago and is still pending, unexpired and unreminded.reminder_sent_atis stamped when the reminder goes out, and also when it never can: the address is suppressed, or the person joined in the meantime. So nobody is reminded twice.invites-remindedge function (service-role only) runs daily at 15:00 UTC from pg_cron viacore.run_invite_reminders()(migration 400). It has the same shape as 391's account-deletion job, and it's added todeploy-functions.sh,config.tomland the functions README.Notifications for the inviter
These are in-app notifications, de-duplicated per referred user, with a "See your invites" button to
/dashboard/invite.referral.joinedfires fromPOST /v1/invites/claim: "Jo joined Scaffald". The name comes from the invite, or else from the new account.referral.onboardedfires fromPOST /v1/prerequisites/complete. The first time, it stampsreferral_attributions.onboarded_atand sends " set up their profile".core.notification_type.Migration 401: the existing bug
insertNotificationde-duplicates with.upsert(…, { onConflict: 'dedupe_key' }). But the unique index from 025 is partial (WHERE dedupe_key IS NOT NULL), and PostgREST'sON CONFLICTcan't target a partial index. So every insert with a dedupe key has failed with42P10and returned null.notify-publishpasses a key for every event that has one, so those notifications were never written; its result just said "Failed to insert notification". Expect some notifications to start arriving once this ships.The fix replaces the index with a plain unique index. It enforces the same rule (NULLs stay distinct, so rows without a key are unaffected) and works as an upsert target. The old index already kept non-null keys unique, so building the new one can't fail on existing rows.
Tests
invite-reminders-rest.test.ts:notifications-operations,invites-rest,invites-data-rlsand the RLS matrix still pass, run against the API from this branch.check-migrationsandcheck-edge-fn-typespass (within baseline;invites-remindhas 0 errors).Pushed with
SKIP_PREPUSH=1: the shared local edge runtime still serves another session's worktree. CI is the check.🤖 Generated with Claude Code