From dd23a46603c2341d07a2f5cc779c438a66c7e282 Mon Sep 17 00:00:00 2001 From: Serge RAKOTO HARRY-NAIVO Date: Thu, 7 May 2026 17:36:25 +0200 Subject: [PATCH] chore: post-review cleanup (3 Important fixes + dead code purge) Addresses the 3 Important issues + 4 follow-ups flagged by the final code review subagent. ## Important fixes - **getNextRef pagination** (cloudflare-worker/hubspot-proxy.js): previously used HubSpot search with limit:100 without pagination, causing reference-number collisions once contact count exceeded 100 (= search results don't guarantee ordering by ref). Now paginates through all results via paging.next.after cursor to find the true numeric maximum. ~10 API calls for 1000 contacts. - **Turnstile reset after Worker calls** (js/form-handler.js): Cloudflare Turnstile tokens are single-use server-side. Without explicit reset, a re-submit would 403 silently from siteverify. New helper resetTurnstile() clears window.turnstileToken and calls window.turnstile.reset() to force a fresh challenge. Called after both requestVerification and sendWelcomeBack flows. - **notifyDuplicateViaFormspree removed** (js/form-handler.js): was actively POSTing returning customers' name+email to Formspree (FORMSPREE_ID='mojrvokp' = real endpoint, sentinel guard never triggered). PII leak to a third-party service inconsistent with the new Resend-only architecture. Function + call site removed. ## Dead code purge - form-handler.js: removed generateRefNumber (= dead, no callers), submitToHubSpot, submitToFormspree, notifyDuplicateViaFormspree functions. Removed constants HUBSPOT_PORTAL_ID, HUBSPOT_FORM_GUID, FORMSPREE_ID, EMAILJS_PUBLIC_KEY, EMAILJS_SERVICE_ID, EMAILJS_TEMPLATE_ID, EMAILJS_TEMPLATE_WELCOME_BACK. Removed emailjs.init() block. Net -111 lines. - contact.html + confirmation.html: removed -