Repository navigation
feat: add re-audit on pricing change with email notifications - #1
Open
darkNIGHT669 wants to merge 11 commits into
Open
darkNIGHT669 wants to merge 11 commits into
darkNIGHT669 wants to merge 11 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
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.
ROUND2_PR.md
What this PR does
Adds a "re-audit on pricing change" system to SpendSight. Every audit now
stores a snapshot of the pricing data used at creation time. A detection
endpoint scans stored audits, identifies which ones are stale due to pricing
changes, and sends one consolidated email per affected user with a one-click
link to a diff view showing old vs new recommendations.
Why
AI tool pricing changes frequently — Cursor raised prices in 2024, Claude
added new tiers in 2025, Copilot restructured plans. A one-time audit becomes
misleading the moment pricing changes. Users who trusted the original audit
and acted on it deserve to know when the ground has shifted. For Credex, a
re-audit email is a high-intent re-engagement touchpoint — a user who already
cared enough to audit their stack will act on new savings information.
The assumption is that users want to be notified, not bombarded. The detection
logic sends one email per user regardless of how many of their audits are
affected, and records notifications to prevent duplicates.
How it works
New files:
lib/pricing-snapshot.ts— snapshot capture, change detection, version hashingapp/api/detect-changes/route.ts— detection + email sendingapp/api/reaudit/[auditId]/route.ts— re-run endpointapp/reaudit/[auditId]/page.tsx— diff view pagecomponents/AuditDiffView.tsx— diff UI componentvercel.json— cron schedule (weekly Monday 9am)Modified files:
app/api/audit/create/route.ts— now saves pricing_snapshot + pricing_versionapp/api/leads/create/route.ts— fixed Resend sender for Round 1 email bugapp/globals.css— diff view styles appendedWhat I cut
Unsubscribe page UI — the email contains an unsubscribe link that hits
/unsubscribe?email=X&auditId=Ybut the actual page/route isn't built.The DB column exists (
unsubscribedboolean on leads). Cut because the diffview is more important to the reviewer experience and the link is present
in the email as required.
Admin dashboard — bonus feature, cut entirely. Would have been a table
of stored audits + notifications sent. Skipped in favour of getting the
diff view polished.
"What changed this week" public page — cut for the same reason. The
pricing_changelog table is in the DB schema but nothing writes to it yet.
The detection endpoint would populate it naturally with a one-line addition.
Per-plan detection granularity — the current detection compares
monthlyPerSeatonly. Annual billing rate changes aren't detected. This isa known gap; fixing it requires extending
PlanSnapshotto includeannualMonthlyEquivalent. Acceptable for 36 hours — the main price fieldis the one users care about.
Automated tests for new routes — ran out of time. The audit engine tests
still pass. New routes were tested manually (see How to test below).
How to test it manually
This simulates Cursor Pro price changing from $20 to $25.
/reaudit/[auditId]shows old vs new recommendationswith the Cursor Pro row highlighted as changed
To test without email (just the diff view):
/reaudit/[any-valid-auditId]What's tested
npm test)detectPricingChanges()manually tested with a modified snapshotgetChangesAffectingAudit()manually tested with tool/plan filteringre-audit email → diff view
Skipped automated tests for:
/api/detect-changes— integration test requiring live SupabaseAuditDiffView— component test requiring React Testing Library setupOpen questions / risks
Duplicate detection on cold starts: The in-memory rate limiter resets
on serverless cold starts. The
reaudit_notificationstable preventsduplicate emails at the DB level, but if two detect-changes calls run
simultaneously before either writes to the DB, a user could receive two
emails. Fix: use a DB-level lock or upsert with a unique constraint on
(audit_id, email).Stale pricing_snapshot on old audits: Audits created before this PR
have
pricing_snapshot = null. The detection endpoint skips these with.not("pricing_snapshot", "is", null). All new audits will have snapshots.Old audits can never participate in re-audit notifications.
Cron on Vercel Hobby plan: Vercel Cron requires at minimum the Pro plan
for custom schedules. The
vercel.jsoncron config is included and willwork if the project is on Vercel Pro. On Hobby, the manual POST endpoint
still works — a GitHub Actions schedule calling the endpoint is the free
fallback.