Port the single-file landing (2.6 MB of inlined CSS, JS and base64 images, kept as fitnes/legacy/index.html) to Vite + React 19 + TypeScript, with an Express API that files every form submission into amoCRM pipeline 10980758. - Extract the 14 embedded images to src/assets/images and public/ - Rebuild the design system as Tailwind v4 @theme tokens; the stock palette and breakpoints are cleared so only the EXO scale is reachable from utilities - Split the page into 15 components; all copy moves to src/data - Lead endpoint: find-or-create the contact (Russian phone spellings compared on the last 10 digits), create the lead in the pipeline's first stage, map the fields the account already has and put the rest in a note. If amoCRM is unreachable the payload is logged and kept in localStorage rather than lost. - Add a callback modal as a second entry point, tagged separately in the pipeline - Self-host Inter Variable so the layout's 760/850/900 weights render as real weights instead of snapping to bold Fidelity was checked by comparing section offsets and heights against the original at 375/480/640/900/1120/1440 px; every section and the total page height matched exactly. Loading Inter deliberately changes text metrics, so the byte-exact comparison holds against the pre-font build. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
34 lines
1018 B
TypeScript
34 lines
1018 B
TypeScript
interface Bucket {
|
|
count: number
|
|
resetAt: number
|
|
}
|
|
|
|
/**
|
|
* Minimal fixed-window limiter for the public lead endpoint. In-memory on
|
|
* purpose: a single landing page behind one Node process does not warrant a
|
|
* shared store, and losing the counters on restart is harmless.
|
|
*/
|
|
export function createRateLimiter(options: { limit: number; windowMs: number }) {
|
|
const buckets = new Map<string, Bucket>()
|
|
|
|
return function check(key: string): { allowed: boolean; retryAfterSeconds: number } {
|
|
const now = Date.now()
|
|
|
|
if (buckets.size > 5000) {
|
|
for (const [k, bucket] of buckets) if (bucket.resetAt <= now) buckets.delete(k)
|
|
}
|
|
|
|
const bucket = buckets.get(key)
|
|
if (!bucket || bucket.resetAt <= now) {
|
|
buckets.set(key, { count: 1, resetAt: now + options.windowMs })
|
|
return { allowed: true, retryAfterSeconds: 0 }
|
|
}
|
|
|
|
bucket.count += 1
|
|
return {
|
|
allowed: bucket.count <= options.limit,
|
|
retryAfterSeconds: Math.ceil((bucket.resetAt - now) / 1000),
|
|
}
|
|
}
|
|
}
|