/** * 문의 폼 전송. * * 같은 출처의 /api/lead 로 보낸다. 그 함수가 토큰을 붙여 Apps Script 로 넘기고, * 스크립트가 구글시트에 행을 추가하고 알림 메일을 보낸다. * * 2026-10-01 이전에는 브라우저가 Apps Script 주소와 토큰을 직접 들고 호출했다. * 브라우저로 내려간 값은 무엇이든 공개라 토큰이 번들에 평문으로 박혔다(실제로 추출해 확인). * 토큰을 서버로 옮겨 번들에서 없앴고, 그 덕에 클라이언트 환경변수도 필요 없어졌다. */ export interface LeadInput { name: string; company: string; phone: string; email: string; message: string; /** 어느 화면에서 열었는지 (footer · navbar) */ source: string; /** * 허니팟. 사람에게는 보이지 않는 칸이라 항상 빈 문자열이어야 한다. * 값이 차 있으면 Apps Script 가 봇으로 보고 저장하지 않는다. */ website: string; } export type LeadResult = { ok: true } | { ok: false; reason: 'failed' }; export async function submitLead(input: LeadInput): Promise { try { const res = await fetch('/api/lead', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(input), }); const data = await res.json().catch(() => null); // 성공했다고 말할 근거가 없으면 실패로 둔다. 화면은 메일 폴백을 보여준다. return data && data.ok ? { ok: true } : { ok: false, reason: 'failed' }; } catch (e) { console.error('[submitLead] 전송 실패', e); return { ok: false, reason: 'failed' }; } }