@@ -5,6 +5,8 @@ import { normalizeRecipientEmail } from '@threadplane-internal/growth';
55import { matchesSubmittedFormPolicy } from '../../../lib/growth/form-policy' ;
66import {
77 defaultGrowthFormRouteDependencies ,
8+ formAdmissionError ,
9+ trustedFormClientIp ,
810 jsonResponse ,
911 readBoundedJsonObject ,
1012 stalePolicyResponse ,
@@ -39,6 +41,7 @@ export function createWhitepaperSignupRoute(
3941 return jsonResponse ( { error : 'Unable to accept request' } , 503 ) ;
4042 }
4143
44+ let honeypot ;
4245 let submissionId ;
4346 let acquisitionSessionId ;
4447 let name ;
@@ -49,6 +52,7 @@ export function createWhitepaperSignupRoute(
4952 if ( ! matchesSubmittedFormPolicy ( policy , policyVersion || undefined ) ) {
5053 return stalePolicyResponse ( policy ) ;
5154 }
55+ honeypot = strictText ( body , 'website_url' , 200 ) ;
5256 submissionId = strictText ( body , 'submission_id' , 36 ) ;
5357 acquisitionSessionId = strictText ( body , 'acquisition_session_id' , 36 ) ;
5458 name = strictText ( body , 'name' , 200 ) ;
@@ -81,8 +85,13 @@ export function createWhitepaperSignupRoute(
8185 }
8286
8387 let accepted = false ;
88+ const trustedClientIp = trustedFormClientIp ( request ) ;
89+ let deliverySuppressed = false ;
90+ let admissionError : Response | undefined ;
8491 try {
85- await dependencies . accept ( database , {
92+ const result = await dependencies . accept ( database , {
93+ ...( honeypot ? { honeypot } : { } ) ,
94+ ...( trustedClientIp ? { trustedClientIp } : { } ) ,
8695 submissionId,
8796 email : normalizedEmail ,
8897 displayName : name || undefined ,
@@ -97,7 +106,9 @@ export function createWhitepaperSignupRoute(
97106 keyring,
98107 } ) ;
99108 accepted = true ;
100- } catch {
109+ deliverySuppressed = result . deliverySuppressed === true ;
110+ } catch ( error ) {
111+ admissionError = formAdmissionError ( error ) ;
101112 // The response below reports the failure without echoing provider detail.
102113 }
103114
@@ -106,7 +117,9 @@ export function createWhitepaperSignupRoute(
106117 } catch {
107118 return unableToAccept ( ) ;
108119 }
120+ if ( admissionError ) return admissionError ;
109121 if ( ! accepted ) return unableToAccept ( ) ;
122+ if ( deliverySuppressed ) return jsonResponse ( { ok : true } ) ;
110123
111124 // The durable jobs remain available to the scheduled dispatcher.
112125 await dependencies . nudge ( { submissionId } ) . catch ( ( ) => undefined ) ;
0 commit comments