Repository navigation
feat(affiliates): public affiliate program page, applications and founder admin - #751
Merged
Merged
Conversation
…r admin - /affiliates landing page (earning examples from PLAN_LIST_PRICES_EUR) and /affiliates/terms - No-account application form -> POST /api/affiliate-applications (validation, honeypot, per-IP rate limit, global hourly cap, pending dedupe by normalized email) - Additive migration 20261006120000_add_affiliate_applications - Founder admin at /dashboard/settings/affiliates: review/approve/reject, referral URL + deep links, create affiliate directly, disable/enable, payouts, resolve needs-attention - Footer link, pricing + docs mentions, sitemap, privacy paragraph (all flag-gated) - Fix: legacy ?signUp=1 / ?signIn=1 redirects kept ref/via - Tests: hold dates, payout hold, Stripe Customer metadata, last-touch, destinations
…where referral capture is on
Merged
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.
Base branch:
develop.Summary
This adds a public affiliate program: a landing page, terms, a no-account application form, and a founder admin UI on top of the existing native affiliate engine. The commission model is unchanged: 30% recurring on hosted Pro/Business, 60-day last-touch window locked at signup, 30-day hold, €50 minimum, manual payouts, no self-referrals, self-hosted never earns.
Everything public is gated on
NEXT_PUBLIC_AFFILIATES_ENABLED(dashboard, build-time) plus the API flag. With the flag off, the pages 404, no links render, the sitemap leaves them out and the application endpoint 404s. No newNEXT_PUBLIC_*variable, so the Dockerfile is unchanged.1.
/affiliates(public, indexable)H1 "Earn 30% recurring commission with Telemetry Tracker". Sections: audiences, earnings, how it works, rules, apply (
#apply), FAQ. Uses the existing Nav, Footer and design tokens. Responsive (no horizontal overflow at 390px) and accessible (labelled fields,aria-invalid/aria-describedby,role="status"success state).Metadata: title, description, absolute canonical, Open Graph with the site OG image, Twitter card,
index, follow.In the sitemap and not blocked by
robots.txt. No FAQ JSON-LD, because the site doesn't use that pattern.Pricing source:
PLAN_LIST_PRICES_EURinapps/dashboard/lib/plan-pricing.ts(the same source as/pricing): Pro 15 €/mo, Business 99 €/mo. Monthly billing only; there are no annual plans.Commission per paid invoice is
floor(price × 30%):Footnote on the page: these are list prices; commission is on what the customer actually pays, excluding VAT and after discounts; billing is monthly only, so "per year" means 12 monthly invoices; Free and self-hosted never earn.
Constants live in
apps/dashboard/lib/affiliate-program.ts.affiliate-program.test.tsis a parity test that reads the API engine sources (DEFAULT_COMMISSION_RATE_BPS,COMMISSION_HOLD_DAYS,PAYOUT_MINIMUM_CENTS,REFERRAL_ATTRIBUTION_WINDOW_DAYS,HOSTED_PAID_PLAN_TIERS) and fails if the marketing numbers drift from them.2. Application form →
POST /api/affiliate-applicationsterms_versionis stored.company_website: gets a fake success and stores nothing.RATE_LIMIT_AFFILIATE_APPLICATION_MAX.AFFILIATE_APPLICATIONS_MAX_PER_HOUR.AFFILIATE_APPLICATION_NOTIFY_EMAILSis set.3. Founder admin:
/dashboard/settings/affiliatesGET /api/meta/affiliates/accessand runsnotFound()unless it gets a 200. The API gate is unchanged: 404 when the flag is off, 401 with no session, 403 when the user is not inAFFILIATE_ADMIN_EMAILS. The "Founder → Affiliates" settings nav group only renders when the same check passes. Nothing appears elsewhere in the product dashboard.code_taken).Affiliatein the same transaction (SELECT … FOR UPDATE), then showshttps://telemetry-tracker.com/?ref=CODEwith a copy button plus copyable deep links./dashboard/settings/affiliates/:id):GET /api/meta/affiliates/accessGET /api/meta/affiliates/applications?status=POST /api/meta/affiliates/applications/:id/approvePOST /api/meta/affiliates/applications/:id/reject4. Referral persistence: verified destinations
ReferralCapturesits in the root layout, so?ref=/?via=is captured on every route.__tests__/referral-destinations.test.tschecks that each destination is a real page and that middleware passes the query through. A browser check against a production build confirmed/pricing?ref=…writes sessionStorage and a second?ref=replaces it (last touch).https://telemetry-tracker.com/?ref=CODEhttps://telemetry-tracker.com/pricing?ref=CODEhttps://telemetry-tracker.com/sentry-alternative?ref=CODEhttps://telemetry-tracker.com/docs/migrate-from-sentry?ref=CODEhttps://telemetry-tracker.com/error-tracking/nextjs?ref=CODEhttps://telemetry-tracker.com/docs/nextjs?ref=CODEhttps://telemetry-tracker.com/self-hosted-error-tracking?ref=CODEhttps://telemetry-tracker.com/register?ref=CODEFixed: legacy
/?signUp=1&ref=CODEand?signIn=1redirects cleared the whole query string and lost the referral. They now keepref/via(checked live:/?signUp=1&ref=legacy→/register?ref=legacy). Thewww.→ apex redirect already kept?ref=.5. Discoverability
6.
/affiliates/terms/privacy#affiliate-applications). Needs founder review.Migration
20261006120000_add_affiliate_applicationsis additive only. It creates theAffiliateApplicationtable with:statusCHECK (pending / approved / rejected)terms_version,terms_accepted_atreviewed_by,reviewed_at,review_noteaffiliate_idFK →Affiliate,ON DELETE SET NULLpending_email_key: non-NULL only while pending, which gives "one pending application per email" and still lets a rejected applicant re-apply(status, created_at),email_normalizedandaffiliate_idNo existing table or column changes. It was tested only against a local Postgres; no production DB access.
How to test
New tests:
affiliate-application.test.ts, 15): parsing, limits, URL normalization, honeypot, IP key, notify-email parsing.affiliate-applications.integration.test.ts, 14): flag off → 404, storage, validation, honeypot, Gmail dedupe and re-apply after rejection, concurrent dedupe, hourly cap, per-IP limit, admin gates (404 / 401 / 403), list/filter/suggested code, approve end-to-end (attribution and self-referral via the new affiliate),code_taken, reject, direct create, disable/enable.affiliates.integration.test.ts, +3):invoice.paidgivespayable_at = paid_at + 30 days.stripe.customers.createwithorganization_id/tt_org_id/tt_affiliate_idmetadata. A plain user doesn't trigger it.?ref=replaces the first, for both sessionStorage and the consented cookie.Manual check against a production build (flags on, local API and DB):
/login.Screenshots
Captured from the local production build. They are on the box at
/workspace/affiliates-public/screens/:affiliates-desktop-1280.png(full page),affiliates-desktop-1280-hero.pngaffiliates-mobile-390.pngaffiliates-terms-1280.pngprivacy-affiliate-paragraph.pngadmin-overview.png,admin-applications-pending-review.png,admin-approved-referral-links.pngadmin-affiliate-detail.png,admin-affiliate-detail-after-payout.pngOpen founder questions
amount_paid − tax). Billing currently has no Stripe Tax, so tax is 0 and commission is 30% of what is charged. Is "excluding VAT / sales tax" the right promise?#affiliate-applications). Please review it, and decide whether to bump the policy's effective date or version (I left both unchanged).trustProxy, so the dashboard server action forwards a validated visitor IP inx-tt-client-ip. A direct API caller could spoof it; the global hourly cap is the backstop. Is that acceptable, or do you wanttrustProxyor a shared secret?/affiliatepage for a signed-in user whose email matches an active affiliate. It would show the code and links, referred and paying org counts, and pending / payable / paid totals, reusingcomputeAffiliateBalance. It needs a decision on whether affiliates should see org names (probably not).Code review (Bugbot)
Checklist
RUN_DB_INTEGRATION_TESTS=true)[Unreleased]docs/AFFILIATES.md,apps/api/.env.example)Security / privacy