@@ -4,11 +4,9 @@ import { NextResponse } from 'next/server'
44import { sanityWriteClient } from '@/lib/sanity-write-client'
55import { generateOutreachEmail } from '@/lib/sponsor/gemini-outreach'
66import { sendSponsorEmail } from '@/lib/sponsor/email-service'
7+ import { getConfig } from '@/lib/config'
78import type { SponsorPoolEntry } from '@/lib/sponsor/gemini-outreach'
89
9- const MAX_PER_RUN = 5
10- const COOLDOWN_DAYS = 14
11-
1210export async function POST ( request : Request ) {
1311 // Auth: Bearer token check against CRON_SECRET
1412 const cronSecret = process . env . CRON_SECRET ;
@@ -25,9 +23,24 @@ export async function POST(request: Request) {
2523 try {
2624 console . log ( '[SPONSOR] Starting outbound sponsor outreach cron...' )
2725
26+ // Fetch sponsor config from Sanity singleton
27+ const sponsorCfg = await getConfig ( "sponsor_config" ) ;
28+ const maxPerRun = sponsorCfg . maxOutreachPerRun ;
29+ const cooldownDays = sponsorCfg . cooldownDays ;
30+
31+ // Build rate card string from config tiers
32+ const rateCard = [
33+ 'CodingCat.dev Sponsorship Tiers:' ,
34+ ...sponsorCfg . rateCardTiers . map (
35+ ( t ) => `- ${ t . name } ($${ t . price . toLocaleString ( ) } ) — ${ t . description } `
36+ ) ,
37+ '' ,
38+ 'Our audience: 50K+ developers interested in web development, JavaScript/TypeScript, React, Next.js, and modern dev tools.' ,
39+ ] . join ( '\n' ) ;
40+
2841 // Calculate the cutoff date for cooldown
2942 const cutoffDate = new Date ( )
30- cutoffDate . setDate ( cutoffDate . getDate ( ) - COOLDOWN_DAYS )
43+ cutoffDate . setDate ( cutoffDate . getDate ( ) - cooldownDays )
3144 const cutoffISO = cutoffDate . toISOString ( )
3245
3346 // Query Sanity for eligible sponsor pool entries
@@ -38,7 +51,7 @@ export async function POST(request: Request) {
3851 !defined(lastContactedAt)
3952 || lastContactedAt < $cutoffDate
4053 )
41- ] | order(relevanceScore desc) [0...${ MAX_PER_RUN - 1 } ] {
54+ ] | order(relevanceScore desc) [0...${ maxPerRun - 1 } ] {
4255 _id,
4356 companyName,
4457 contactName,
@@ -68,7 +81,7 @@ export async function POST(request: Request) {
6881 for ( const sponsor of sponsors ) {
6982 try {
7083 // Generate personalized outreach email
71- const email = await generateOutreachEmail ( sponsor )
84+ const email = await generateOutreachEmail ( sponsor , rateCard )
7285
7386 // Send the email (stubbed)
7487 const sendResult = await sendSponsorEmail (
0 commit comments