Skip to content

Commit 05040fa

Browse files
author
Miriad
committed
fix: reconcile sponsor pipeline with content schema field names
1 parent ded7689 commit 05040fa

File tree

10 files changed

+35
-313
lines changed

10 files changed

+35
-313
lines changed

app/api/cron/sponsor-outreach/route.ts

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ export async function POST(request: Request) {
3535
)
3636
] | order(relevanceScore desc) [0...${MAX_PER_RUN - 1}] {
3737
_id,
38-
company,
38+
companyName,
3939
contactName,
4040
contactEmail,
4141
website,
42-
industry,
42+
category,
4343
relevanceScore,
4444
optOutToken
4545
}`
@@ -58,7 +58,7 @@ export async function POST(request: Request) {
5858
})
5959
}
6060

61-
const results: Array<{ company: string; success: boolean; error?: string }> = []
61+
const results: Array<{ companyName: string; success: boolean; error?: string }> = []
6262

6363
for (const sponsor of sponsors) {
6464
try {
@@ -82,36 +82,28 @@ export async function POST(request: Request) {
8282
// Create a sponsorLead with source='outbound'
8383
await sanityWriteClient.create({
8484
_type: 'sponsorLead',
85-
company: sponsor.company,
85+
companyName: sponsor.companyName,
8686
contactName: sponsor.contactName,
8787
contactEmail: sponsor.contactEmail,
8888
source: 'outbound',
8989
status: 'contacted',
90-
threadHistory: [
91-
{
92-
_key: crypto.randomUUID(),
93-
date: new Date().toISOString(),
94-
direction: 'outbound',
95-
subject: email.subject,
96-
body: email.body,
97-
},
98-
],
99-
lastContactedAt: new Date().toISOString(),
90+
threadId: crypto.randomUUID(),
91+
lastEmailAt: new Date().toISOString(),
10092
})
10193

102-
results.push({ company: sponsor.company, success: true })
103-
console.log(`[SPONSOR] Outreach sent to: ${sponsor.company}`)
94+
results.push({ companyName: sponsor.companyName, success: true })
95+
console.log(`[SPONSOR] Outreach sent to: ${sponsor.companyName}`)
10496
} else {
10597
results.push({
106-
company: sponsor.company,
98+
companyName: sponsor.companyName,
10799
success: false,
108100
error: 'Email send failed',
109101
})
110102
}
111103
} catch (error) {
112104
const errorMsg = error instanceof Error ? error.message : String(error)
113-
console.error(`[SPONSOR] Outreach failed for ${sponsor.company}:`, errorMsg)
114-
results.push({ company: sponsor.company, success: false, error: errorMsg })
105+
console.error(`[SPONSOR] Outreach failed for ${sponsor.companyName}:`, errorMsg)
106+
results.push({ companyName: sponsor.companyName, success: false, error: errorMsg })
115107
}
116108
}
117109

app/api/sponsor/opt-out/route.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ export async function GET(request: Request) {
1313

1414
try {
1515
// Query Sanity for sponsorPool entry with matching optOutToken
16-
const query = '*[_type == "sponsorPool" && optOutToken == $token][0]{ _id, company }'
16+
const query = '*[_type == "sponsorPool" && optOutToken == $token][0]{ _id, companyName }'
1717
const params = { token } as Record<string, string>
1818
const sponsor = await sanityWriteClient.fetch(
1919
query,
2020
params
21-
) as { _id: string; company: string } | null
21+
) as { _id: string; companyName: string } | null
2222

2323
if (!sponsor) {
2424
console.warn('[SPONSOR] Opt-out: invalid token:', token)
@@ -31,7 +31,7 @@ export async function GET(request: Request) {
3131
// Set optedOut = true
3232
await sanityWriteClient.patch(sponsor._id).set({ optedOut: true }).commit()
3333

34-
console.log('[SPONSOR] Opt-out processed for:', sponsor.company)
34+
console.log('[SPONSOR] Opt-out processed for:', sponsor.companyName)
3535

3636
return new Response(
3737
renderHtml(

app/api/webhooks/sponsor-inbound/route.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,23 +62,15 @@ export async function POST(request: Request) {
6262
// Create sponsorLead in Sanity
6363
const leadDoc = {
6464
_type: 'sponsorLead',
65-
company: intent.company || company || 'Unknown',
65+
companyName: intent.companyName || company || 'Unknown',
6666
contactName: intent.contactName || fullName,
6767
contactEmail: email,
6868
source: 'inbound',
6969
status: 'new',
7070
intent: intent.intent,
71-
selectedTiers: tiers.length > 0 ? tiers : intent.suggestedTiers,
72-
threadHistory: [
73-
{
74-
_key: crypto.randomUUID(),
75-
date: new Date().toISOString(),
76-
direction: 'inbound',
77-
subject: `Sponsorship inquiry from ${fullName}`,
78-
body: message || '',
79-
},
80-
],
81-
lastContactedAt: new Date().toISOString(),
71+
rateCard: tiers.length > 0 ? tiers.join(', ') : intent.suggestedTiers.join(', '),
72+
threadId: crypto.randomUUID(),
73+
lastEmailAt: new Date().toISOString(),
8274
}
8375

8476
const created = await sanityWriteClient.create(leadDoc)

lib/sanity-write-client.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

lib/sponsor/gemini-intent.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const SPONSORSHIP_TIERS = [
99
] as const
1010

1111
export interface SponsorIntent {
12-
company: string
12+
companyName: string
1313
contactName: string
1414
intent: string
1515
suggestedTiers: string[]
@@ -25,7 +25,7 @@ export async function extractSponsorIntent(message: string): Promise<SponsorInte
2525
if (!apiKey) {
2626
console.warn('[SPONSOR] GEMINI_API_KEY not set — returning default intent extraction')
2727
return {
28-
company: '',
28+
companyName: '',
2929
contactName: '',
3030
intent: message.slice(0, 500),
3131
suggestedTiers: [],
@@ -46,14 +46,14 @@ Available sponsorship tiers:
4646
- video-series (custom pricing) — Multi-video series partnership
4747
4848
Analyze this message and extract:
49-
1. company — The company name (if mentioned)
49+
1. companyName — The company name (if mentioned)
5050
2. contactName — The contact person's name (if mentioned)
5151
3. intent — A brief summary of what they want (1-2 sentences)
5252
4. suggestedTiers — Which tiers seem relevant based on their message (array of tier values from the list above)
5353
5. urgency — How urgent this seems: "low", "medium", or "high"
5454
5555
Respond ONLY with valid JSON, no markdown formatting:
56-
{"company": "", "contactName": "", "intent": "", "suggestedTiers": [], "urgency": "medium"}
56+
{"companyName": "", "contactName": "", "intent": "", "suggestedTiers": [], "urgency": "medium"}
5757
5858
Message to analyze:
5959
${message}`
@@ -78,7 +78,7 @@ ${message}`
7878
}
7979

8080
console.log('[SPONSOR] Gemini intent extraction successful:', {
81-
company: parsed.company,
81+
companyName: parsed.companyName,
8282
tiers: parsed.suggestedTiers,
8383
urgency: parsed.urgency,
8484
})
@@ -87,7 +87,7 @@ ${message}`
8787
} catch (error) {
8888
console.error('[SPONSOR] Gemini intent extraction failed:', error)
8989
return {
90-
company: '',
90+
companyName: '',
9191
contactName: '',
9292
intent: message.slice(0, 500),
9393
suggestedTiers: [],

lib/sponsor/gemini-outreach.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { GoogleGenerativeAI } from '@google/generative-ai'
22

33
export interface SponsorPoolEntry {
44
_id: string
5-
company: string
5+
companyName: string
66
contactName: string
77
contactEmail: string
88
website?: string
9-
industry?: string
9+
category?: string
1010
relevanceScore?: number
1111
optOutToken?: string
1212
}
@@ -51,10 +51,10 @@ export async function generateOutreachEmail(
5151
const prompt = `You are writing a personalized cold outreach email from Alex Patterson, the creator of CodingCat.dev, to a potential sponsor.
5252
5353
Sponsor details:
54-
- Company: ${sponsor.company}
54+
- Company: ${sponsor.companyName}
5555
- Contact: ${sponsor.contactName}
5656
- Website: ${sponsor.website || 'N/A'}
57-
- Industry: ${sponsor.industry || 'Technology'}
57+
- Category: ${sponsor.category || 'Technology'}
5858
5959
Rate card:
6060
${rateCard}
@@ -79,7 +79,7 @@ Respond ONLY with valid JSON, no markdown formatting:
7979
const jsonStr = text.replace(/^\`\`\`json?\n?/i, '').replace(/\n?\`\`\`$/i, '').trim()
8080
const parsed = JSON.parse(jsonStr) as OutreachEmail
8181

82-
console.log('[SPONSOR] Gemini outreach email generated for:', sponsor.company)
82+
console.log('[SPONSOR] Gemini outreach email generated for:', sponsor.companyName)
8383
return parsed
8484
} catch (error) {
8585
console.error('[SPONSOR] Gemini outreach generation failed:', error)
@@ -93,12 +93,12 @@ function getTemplateEmail(sponsor: SponsorPoolEntry, rateCard: string): Outreach
9393
: ''
9494

9595
return {
96-
subject: `Partnership opportunity with CodingCat.dev — ${sponsor.company}`,
96+
subject: `Partnership opportunity with CodingCat.dev — ${sponsor.companyName}`,
9797
body: `Hi ${sponsor.contactName},
9898
9999
I'm Alex Patterson, creator of CodingCat.dev — a developer education platform reaching 50K+ developers through YouTube, podcasts, and newsletters.
100100
101-
I think ${sponsor.company} would be a great fit for our audience of web developers who are always looking for tools to improve their workflow.
101+
I think ${sponsor.companyName} would be a great fit for our audience of web developers who are always looking for tools to improve their workflow.
102102
103103
Here are our current sponsorship options:
104104

lib/sponsor/stripe-service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
export interface SponsorLeadForInvoice {
99
_id: string
10-
company: string
10+
companyName: string
1111
contactName: string
1212
contactEmail: string
1313
}
@@ -34,7 +34,7 @@ export async function createSponsorInvoice(
3434
// const customer = await stripe.customers.create({
3535
// email: lead.contactEmail,
3636
// name: lead.contactName,
37-
// metadata: { company: lead.company, sanityLeadId: lead._id },
37+
// metadata: { companyName: lead.companyName, sanityLeadId: lead._id },
3838
// })
3939
//
4040
// // Create invoice
@@ -59,7 +59,7 @@ export async function createSponsorInvoice(
5959

6060
console.log('[SPONSOR] Invoice creation (stubbed):', {
6161
leadId: lead._id,
62-
company: lead.company,
62+
company: lead.companyName,
6363
amount,
6464
description,
6565
timestamp: new Date().toISOString(),

sanity.config.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ import podcastType from "@/sanity/schemas/documents/podcastType";
4343
import post from "@/sanity/schemas/documents/post";
4444
import settings from "@/sanity/schemas/singletons/settings";
4545
import sponsor from "@/sanity/schemas/documents/sponsor";
46-
import sponsorLead from "@/sanity/schemas/documents/sponsorLead";
47-
import sponsorPool from "@/sanity/schemas/documents/sponsorPool";
46+
4847
import sponsorshipRequest from "@/sanity/schemas/documents/sponsorshipRequest";
4948
import youtubeUpdateTask from "@/sanity/schemas/documents/youtubeUpdateTask";
5049
import { resolveHref } from "@/sanity/lib/utils";
@@ -141,8 +140,6 @@ export default defineConfig({
141140
podcastType,
142141
post,
143142
sponsor,
144-
sponsorLead,
145-
sponsorPool,
146143
youtubeUpdateTask,
147144
previewSession,
148145
sponsorshipRequest,

0 commit comments

Comments
 (0)