1+ import { createLogger } from "@databuddy/shared/logger" ;
12import { type NextRequest , NextResponse } from "next/server" ;
2- import { logger } from "@/lib/discord-webhook" ;
33import { formRateLimit } from "@/lib/rate-limit" ;
44
5- // Type for ambassador form data
6- interface AmbassadorFormData {
5+ const logger = createLogger ( "ambassador-form" ) ;
6+
7+ type AmbassadorFormData = {
78 name : string ;
89 email : string ;
910 xHandle ?: string ;
@@ -115,10 +116,9 @@ export async function POST(request: NextRequest) {
115116 const rateLimitResult = formRateLimit . check ( clientIP ) ;
116117
117118 if ( ! rateLimitResult . allowed ) {
118- await logger . warning (
119- "Ambassador Form Rate Limited" ,
120- `IP ${ clientIP } exceeded rate limit for ambassador form submissions` ,
121- { ip : clientIP , resetTime : rateLimitResult . resetTime }
119+ logger . info (
120+ { ip : clientIP , resetTime : rateLimitResult . resetTime } ,
121+ `IP ${ clientIP } exceeded rate limit for ambassador form submissions`
122122 ) ;
123123
124124 return NextResponse . json (
@@ -135,10 +135,9 @@ export async function POST(request: NextRequest) {
135135 const validation = validateFormData ( formData ) ;
136136
137137 if ( ! validation . valid ) {
138- await logger . warning (
139- "Ambassador Form Validation Failed" ,
140- "Form submission failed validation" ,
141- { errors : validation . errors , ip : clientIP }
138+ logger . info (
139+ { errors : validation . errors , ip : clientIP } ,
140+ "Form submission failed validation"
142141 ) ;
143142
144143 return NextResponse . json (
@@ -149,10 +148,7 @@ export async function POST(request: NextRequest) {
149148
150149 const ambassadorData = formData as AmbassadorFormData ;
151150
152- // Log successful submission
153- await logger . success (
154- "New Ambassador Application" ,
155- `${ ambassadorData . name } (${ ambassadorData . email } ) submitted an ambassador application` ,
151+ logger . info (
156152 {
157153 name : ambassadorData . name ,
158154 email : ambassadorData . email ,
@@ -164,23 +160,22 @@ export async function POST(request: NextRequest) {
164160 referralSource : ambassadorData . referralSource || "Not provided" ,
165161 ip : clientIP ,
166162 userAgent : request . headers . get ( "user-agent" ) ,
167- timestamp : new Date ( ) . toISOString ( ) ,
168- }
163+ } ,
164+ ` ${ ambassadorData . name } ( ${ ambassadorData . email } ) submitted an ambassador application`
169165 ) ;
170166
171167 return NextResponse . json ( {
172168 success : true ,
173169 message : "Ambassador application submitted successfully" ,
174170 } ) ;
175171 } catch ( error ) {
176- await logger . exception (
177- error instanceof Error
178- ? error
179- : new Error ( "Unknown error in ambassador form submission" ) ,
172+ logger . error (
180173 {
181174 ip : getClientIP ( request ) ,
182- userAgent : request . headers . get ( "user-agent" ) ,
183- }
175+ userAgent : request . headers . get ( "user-agent" ) || "unknown" ,
176+ error : error instanceof Error ? error . message : String ( error ) ,
177+ } ,
178+ "Unknown error in ambassador form submission"
184179 ) ;
185180
186181 return NextResponse . json (
0 commit comments