@wealthreach/site-kit 1.0.2 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/a11y/index.d.ts +32 -3
- package/dist/a11y/index.js +74 -4
- package/dist/a11y/shell-client.d.ts +1 -1
- package/dist/a11y/shell-client.js +4 -4
- package/dist/analytics/index.d.ts +2 -2
- package/dist/analytics/index.js +9 -3
- package/dist/{attribution-DQaAWtA5.d.ts → attribution-BajAl0tG.d.ts} +17 -7
- package/dist/{chunk-Y77ARZE4.js → chunk-DHVKLLL7.js} +5 -3
- package/dist/{chunk-QQP7VG2C.js → chunk-JPUCXNHR.js} +109 -16
- package/dist/{chunk-4YRCSRZZ.js → chunk-SNTMH6M3.js} +2 -2
- package/dist/{chunk-7GDXQ6UB.js → chunk-T4Q4VJ6K.js} +34 -7
- package/dist/config/index.d.ts +2 -2
- package/dist/config/index.js +4 -3
- package/dist/consent/index.d.ts +5 -3
- package/dist/consent/index.js +4 -2
- package/dist/forms/index.d.ts +19 -7
- package/dist/forms/index.js +141 -42
- package/dist/next/config.cjs +13 -1
- package/dist/next/config.d.cts +2 -0
- package/dist/next/config.d.ts +2 -0
- package/dist/next/config.js +13 -1
- package/dist/next/leads-route.d.ts +29 -6
- package/dist/next/leads-route.js +209 -135
- package/dist/{schema-C1ixytx2.d.ts → schema-AcsTlgUv.d.ts} +4 -0
- package/dist/{schema-DD0nDOD0.d.ts → schema-CYsBDpoU.d.ts} +3 -0
- package/package.json +2 -1
package/dist/next/config.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// src/next/config.ts
|
|
2
|
+
import { withBotId } from "botid/next/config";
|
|
2
3
|
var SANDBOX_DEV_ORIGINS = [
|
|
3
4
|
"*.vercel.run",
|
|
4
5
|
"*.vercel.app",
|
|
@@ -50,6 +51,7 @@ function withWealthReach(options = {}) {
|
|
|
50
51
|
rootDir,
|
|
51
52
|
blogPostsDir = "data/blog",
|
|
52
53
|
extraFrameAncestors,
|
|
54
|
+
botId = true,
|
|
53
55
|
headers: userHeaders,
|
|
54
56
|
images: userImages,
|
|
55
57
|
allowedDevOrigins: userDevOrigins,
|
|
@@ -78,7 +80,7 @@ function withWealthReach(options = {}) {
|
|
|
78
80
|
/* @__PURE__ */ new Set([defaultTracingGlob, ...userTracing?.["/**"] ?? []])
|
|
79
81
|
)
|
|
80
82
|
};
|
|
81
|
-
|
|
83
|
+
const baseConfig = {
|
|
82
84
|
devIndicators: false,
|
|
83
85
|
poweredByHeader: false,
|
|
84
86
|
productionBrowserSourceMaps: false,
|
|
@@ -101,6 +103,16 @@ function withWealthReach(options = {}) {
|
|
|
101
103
|
return [{ source: "/(.*)", headers: baseHeaders }, ...extra];
|
|
102
104
|
}
|
|
103
105
|
};
|
|
106
|
+
if (!botId) return baseConfig;
|
|
107
|
+
const userRewrites = baseConfig.rewrites;
|
|
108
|
+
if (!userRewrites) return withBotId(baseConfig);
|
|
109
|
+
return withBotId({
|
|
110
|
+
...baseConfig,
|
|
111
|
+
async rewrites() {
|
|
112
|
+
const rewrites = await userRewrites();
|
|
113
|
+
return Array.isArray(rewrites) ? rewrites : { ...rewrites, beforeFiles: rewrites.beforeFiles ?? [] };
|
|
114
|
+
}
|
|
115
|
+
});
|
|
104
116
|
}
|
|
105
117
|
export {
|
|
106
118
|
SANDBOX_DEV_ORIGINS,
|
|
@@ -17,15 +17,18 @@ interface AttributionSnapshot {
|
|
|
17
17
|
referrer_host?: string;
|
|
18
18
|
captured_at?: string;
|
|
19
19
|
}
|
|
20
|
+
interface WebsiteVisitJourneyEntry {
|
|
21
|
+
sessionId: string;
|
|
22
|
+
startedAt: string;
|
|
23
|
+
pages: string[];
|
|
24
|
+
referrer?: string | null;
|
|
25
|
+
activeMs?: number;
|
|
26
|
+
}
|
|
20
27
|
interface WebsiteVisitSnapshot {
|
|
21
28
|
visitorKey: string;
|
|
22
29
|
sessionId: string;
|
|
23
30
|
device: "desktop" | "mobile";
|
|
24
|
-
journey?:
|
|
25
|
-
landingPath?: string;
|
|
26
|
-
referrerHost?: string;
|
|
27
|
-
pagesViewed?: string[];
|
|
28
|
-
};
|
|
31
|
+
journey?: WebsiteVisitJourneyEntry[];
|
|
29
32
|
}
|
|
30
33
|
|
|
31
34
|
declare const FORM_KINDS: readonly ["lead", "newsletter", "resource", "calculator", "consultation", "event"];
|
|
@@ -47,6 +50,22 @@ interface NormalizedLeadSubmission {
|
|
|
47
50
|
turnstileToken?: string;
|
|
48
51
|
}
|
|
49
52
|
|
|
53
|
+
interface BotIdVerificationOptions {
|
|
54
|
+
/** Override Vercel BotID check level (`"basic"` is free; `"deepAnalysis"` uses Kasada). Omit to inherit the Vercel project setting. */
|
|
55
|
+
checkLevel?: "basic" | "deepAnalysis";
|
|
56
|
+
/** Reject submissions with 503 if Vercel BotID encounters a transient upstream error (default `false` so legitimate advisor leads are never dropped during a BotID outage). */
|
|
57
|
+
failClosed?: boolean;
|
|
58
|
+
}
|
|
59
|
+
type BotIdCheckFn = (options?: {
|
|
60
|
+
advancedOptions?: {
|
|
61
|
+
checkLevel?: "basic" | "deepAnalysis";
|
|
62
|
+
};
|
|
63
|
+
}) => Promise<{
|
|
64
|
+
isBot: boolean;
|
|
65
|
+
isHuman: boolean;
|
|
66
|
+
isVerifiedBot?: boolean;
|
|
67
|
+
bypassed?: boolean;
|
|
68
|
+
}>;
|
|
50
69
|
interface SubmitLeadToWealthReachArgs {
|
|
51
70
|
config: SiteConfig;
|
|
52
71
|
formId: string;
|
|
@@ -114,6 +133,8 @@ declare function extractWealthReachContext(formData: FormData, fallback: {
|
|
|
114
133
|
sourceUrl: string;
|
|
115
134
|
}): ExtractedWealthReachContext;
|
|
116
135
|
interface LeadRouteHandlerOptions {
|
|
136
|
+
/** Verify Vercel BotID on Vercel deployments (default `true`; skipped locally, in sandbox, or when Vercel OIDC is not enabled on the project). */
|
|
137
|
+
verifyBotId?: boolean | BotIdVerificationOptions;
|
|
117
138
|
/** Verify Cloudflare Turnstile when TURNSTILE_SECRET_KEY is configured (default true). */
|
|
118
139
|
verifyTurnstile?: boolean;
|
|
119
140
|
/** Have WealthReach email the advisor when a server secret (`WR_DRAFT_SECRET`) is configured (set false if onAfterCapture sends a custom CC email). */
|
|
@@ -126,6 +147,8 @@ interface LeadRouteHandlerOptions {
|
|
|
126
147
|
submission: NormalizedLeadSubmission;
|
|
127
148
|
}) => Promise<Record<string, unknown> | void>;
|
|
128
149
|
fetchImpl?: typeof fetch;
|
|
150
|
+
/** Optional test override for `checkBotId()` from `botid/server`. */
|
|
151
|
+
checkBotIdImpl?: BotIdCheckFn;
|
|
129
152
|
}
|
|
130
153
|
/**
|
|
131
154
|
* Creates a same-origin Next.js App Router `POST /api/leads` handler that
|
|
@@ -135,4 +158,4 @@ interface LeadRouteHandlerOptions {
|
|
|
135
158
|
declare function createLeadRouteHandler(getConfig: () => SiteConfig, options?: LeadRouteHandlerOptions): (request: Request) => Promise<Response>;
|
|
136
159
|
|
|
137
160
|
export { computeSiteLeadNotifySignature, createLeadRouteHandler, extractWealthReachContext, resolveSiteLeadsEndpoint, submitLeadToWealthReach };
|
|
138
|
-
export type { ExtractedWealthReachContext, LeadRouteHandlerOptions, SubmitLeadResult, SubmitLeadToWealthReachArgs };
|
|
161
|
+
export type { BotIdCheckFn, BotIdVerificationOptions, ExtractedWealthReachContext, LeadRouteHandlerOptions, SubmitLeadResult, SubmitLeadToWealthReachArgs };
|
package/dist/next/leads-route.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// src/next/leads-route.ts
|
|
2
2
|
import { createHmac, randomUUID } from "crypto";
|
|
3
3
|
import { NextResponse } from "next/server";
|
|
4
|
+
import { checkBotId } from "botid/server";
|
|
4
5
|
|
|
5
6
|
// src/config/schema.ts
|
|
6
7
|
import { z as z2 } from "zod";
|
|
@@ -223,7 +224,7 @@ var bookingConfigSchema = z2.object({
|
|
|
223
224
|
var consentConfigSchema = z2.object({
|
|
224
225
|
enabled: z2.boolean().default(true),
|
|
225
226
|
message: z2.string().trim().optional().default(""),
|
|
226
|
-
policyUrl: z2.string().trim().optional().default("
|
|
227
|
+
policyUrl: z2.string().trim().optional().default(""),
|
|
227
228
|
/** Legacy cookie names to migrate silently for returning visitors (e.g. Brandywine Oak). */
|
|
228
229
|
legacyConsentCookies: z2.array(z2.string().trim().min(1)).optional().default([]),
|
|
229
230
|
/** Additional US states requiring opt-in beyond California (CA is always opt-in). */
|
|
@@ -233,7 +234,8 @@ var consentConfigSchema = z2.object({
|
|
|
233
234
|
});
|
|
234
235
|
var visitorsConfigSchema = z2.object({
|
|
235
236
|
enabled: z2.boolean().default(false),
|
|
236
|
-
siteScriptUrl: z2.string().trim().optional().default("")
|
|
237
|
+
siteScriptUrl: z2.string().trim().optional().default(""),
|
|
238
|
+
recordings: z2.boolean().optional()
|
|
237
239
|
});
|
|
238
240
|
var blogConfigSchema = z2.object({
|
|
239
241
|
enabled: z2.boolean().optional().default(true),
|
|
@@ -282,7 +284,7 @@ var siteConfigSchema = z2.object({
|
|
|
282
284
|
consent: consentConfigSchema.optional().default({
|
|
283
285
|
enabled: true,
|
|
284
286
|
message: "",
|
|
285
|
-
policyUrl: "
|
|
287
|
+
policyUrl: "",
|
|
286
288
|
legacyConsentCookies: [],
|
|
287
289
|
extraOptInUsRegions: [],
|
|
288
290
|
hideFloatingPrivacyButton: false
|
|
@@ -355,125 +357,132 @@ function displayNameFromLegal(legalName) {
|
|
|
355
357
|
return legalName.trim().replace(LEGAL_SUFFIX_RE, "").trim() || legalName.trim();
|
|
356
358
|
}
|
|
357
359
|
|
|
360
|
+
// src/consent/core.ts
|
|
361
|
+
var CONSENT_MAX_AGE = 60 * 60 * 24 * 180;
|
|
362
|
+
var MODE_MAX_AGE = 60 * 60 * 24;
|
|
363
|
+
|
|
364
|
+
// src/analytics/attribution.ts
|
|
365
|
+
var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
366
|
+
var VISITOR_KEY_RE = /^[a-zA-Z0-9_-]{16,128}$/;
|
|
367
|
+
var ISO_OFFSET_DATETIME_RE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/i;
|
|
368
|
+
var SESSION_IDLE_MS = 30 * 60 * 1e3;
|
|
369
|
+
var MAX_JOURNEY_SERIALIZED_BYTES = 16384;
|
|
370
|
+
function sanitizeWebsiteJourney(raw) {
|
|
371
|
+
if (!Array.isArray(raw)) return void 0;
|
|
372
|
+
const entries = [];
|
|
373
|
+
for (const item of raw.slice(-10)) {
|
|
374
|
+
if (!item || typeof item !== "object" || Array.isArray(item)) continue;
|
|
375
|
+
const row = item;
|
|
376
|
+
const sessionId = typeof row.sessionId === "string" ? row.sessionId.trim() : "";
|
|
377
|
+
const startedAt = typeof row.startedAt === "string" ? row.startedAt.trim() : "";
|
|
378
|
+
if (!UUID_RE.test(sessionId) || !ISO_OFFSET_DATETIME_RE.test(startedAt) || Number.isNaN(Date.parse(startedAt))) {
|
|
379
|
+
continue;
|
|
380
|
+
}
|
|
381
|
+
const pages = Array.isArray(row.pages) ? row.pages.filter(
|
|
382
|
+
(page) => typeof page === "string" && page.length > 0 && page.length <= 2048
|
|
383
|
+
).slice(-100) : [];
|
|
384
|
+
const referrer = typeof row.referrer === "string" && row.referrer.length <= 2048 ? row.referrer : row.referrer === null ? null : void 0;
|
|
385
|
+
const activeMs = typeof row.activeMs === "number" && Number.isFinite(row.activeMs) && row.activeMs >= 0 ? Math.min(864e5, Math.round(row.activeMs)) : void 0;
|
|
386
|
+
entries.push({
|
|
387
|
+
sessionId,
|
|
388
|
+
startedAt,
|
|
389
|
+
pages,
|
|
390
|
+
...referrer !== void 0 ? { referrer } : {},
|
|
391
|
+
...activeMs !== void 0 ? { activeMs } : {}
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
while (entries.length > 1 && JSON.stringify(entries).length > MAX_JOURNEY_SERIALIZED_BYTES) {
|
|
395
|
+
entries.shift();
|
|
396
|
+
}
|
|
397
|
+
if (entries.length === 1 && JSON.stringify(entries).length > MAX_JOURNEY_SERIALIZED_BYTES) {
|
|
398
|
+
const latest = entries[0];
|
|
399
|
+
while (latest.pages.length > 0 && JSON.stringify(entries).length > MAX_JOURNEY_SERIALIZED_BYTES) {
|
|
400
|
+
latest.pages.shift();
|
|
401
|
+
}
|
|
402
|
+
if (JSON.stringify(entries).length > MAX_JOURNEY_SERIALIZED_BYTES) {
|
|
403
|
+
return void 0;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
return entries.length > 0 ? entries : void 0;
|
|
407
|
+
}
|
|
408
|
+
function sanitizeWebsiteVisit(raw) {
|
|
409
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return void 0;
|
|
410
|
+
const obj = raw;
|
|
411
|
+
const visitorKey = typeof obj.visitorKey === "string" ? obj.visitorKey.trim() : "";
|
|
412
|
+
const sessionId = typeof obj.sessionId === "string" ? obj.sessionId.trim() : "";
|
|
413
|
+
if (!VISITOR_KEY_RE.test(visitorKey) || !UUID_RE.test(sessionId)) {
|
|
414
|
+
return void 0;
|
|
415
|
+
}
|
|
416
|
+
const device = obj.device === "mobile" ? "mobile" : "desktop";
|
|
417
|
+
const journey = sanitizeWebsiteJourney(obj.journey);
|
|
418
|
+
return {
|
|
419
|
+
visitorKey,
|
|
420
|
+
sessionId,
|
|
421
|
+
device,
|
|
422
|
+
...journey ? { journey } : {}
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
|
|
358
426
|
// src/forms/packing.ts
|
|
359
427
|
var SENSITIVE_FIELD_RE = /(?:^|[_.-])(?:ssn|social[_-]?security|account[_-]?number|routing[_-]?number|password|passwd|secret|credit[_-]?card|card[_-]?number|cvv|cvc|tax[_-]?id|ein|tin)(?:$|[_.-])/i;
|
|
360
|
-
var
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
"_hp"
|
|
365
|
-
]);
|
|
366
|
-
var INTERNAL_KEYS = /* @__PURE__ */ new Set([
|
|
367
|
-
"cf-turnstile-response",
|
|
368
|
-
"turnstileToken",
|
|
369
|
-
"__wr_context"
|
|
370
|
-
]);
|
|
371
|
-
function normalizeKey(raw) {
|
|
372
|
-
return raw.trim().toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "").slice(0, 64);
|
|
373
|
-
}
|
|
428
|
+
var CUSTOM_FIELD_KEY_RE = /^[a-zA-Z0-9_.-]{1,64}$/;
|
|
429
|
+
var CONTROL_CHARS_RE = /[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g;
|
|
430
|
+
var PROTOTYPE_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
431
|
+
var MAX_CUSTOM_FIELDS = 40;
|
|
374
432
|
function isSensitiveFieldKey(key) {
|
|
375
433
|
return SENSITIVE_FIELD_RE.test(key);
|
|
376
434
|
}
|
|
377
|
-
function
|
|
378
|
-
const
|
|
379
|
-
let honeypot = "";
|
|
380
|
-
let turnstileToken;
|
|
435
|
+
function sanitizeCustomFields(input) {
|
|
436
|
+
const customFields = {};
|
|
381
437
|
const blockedSensitiveKeys = [];
|
|
382
|
-
|
|
383
|
-
|
|
438
|
+
let tooManyCustomFields = false;
|
|
439
|
+
let fieldCount = 0;
|
|
440
|
+
if (!input || typeof input !== "object" || Array.isArray(input)) {
|
|
441
|
+
return { customFields, blockedSensitiveKeys, tooManyCustomFields };
|
|
442
|
+
}
|
|
443
|
+
for (const [rawKey, rawValue] of Object.entries(input)) {
|
|
444
|
+
if (rawValue === void 0 || rawValue === null) continue;
|
|
384
445
|
const key = rawKey.trim();
|
|
385
446
|
if (!key) continue;
|
|
386
|
-
if (HONEYPOT_KEYS.has(key.toLowerCase())) {
|
|
387
|
-
const val = String(rawValue ?? "").trim();
|
|
388
|
-
if (val) honeypot = val;
|
|
389
|
-
continue;
|
|
390
|
-
}
|
|
391
|
-
if (key === "cf-turnstile-response" || key === "turnstileToken") {
|
|
392
|
-
const val = String(rawValue ?? "").trim();
|
|
393
|
-
if (val) turnstileToken = val;
|
|
394
|
-
continue;
|
|
395
|
-
}
|
|
396
|
-
if (INTERNAL_KEYS.has(key)) continue;
|
|
397
447
|
if (isSensitiveFieldKey(key)) {
|
|
398
448
|
blockedSensitiveKeys.push(key);
|
|
399
449
|
continue;
|
|
400
450
|
}
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
451
|
+
if (PROTOTYPE_KEYS.has(key) || !CUSTOM_FIELD_KEY_RE.test(key)) continue;
|
|
452
|
+
let sanitizedValue;
|
|
453
|
+
if (typeof rawValue === "boolean") {
|
|
454
|
+
sanitizedValue = rawValue;
|
|
455
|
+
} else if (Array.isArray(rawValue)) {
|
|
456
|
+
const cleaned = rawValue.map(
|
|
457
|
+
(item) => String(item).trim().replace(CONTROL_CHARS_RE, "").slice(0, 200)
|
|
458
|
+
).filter((s) => s.length > 0).slice(0, 25);
|
|
459
|
+
if (cleaned.length > 0) {
|
|
460
|
+
sanitizedValue = cleaned;
|
|
461
|
+
}
|
|
462
|
+
} else if (typeof rawValue === "number") {
|
|
463
|
+
if (Number.isFinite(rawValue)) {
|
|
464
|
+
sanitizedValue = String(rawValue);
|
|
406
465
|
}
|
|
407
|
-
} else if (typeof rawValue === "boolean") {
|
|
408
|
-
list.push(rawValue);
|
|
409
466
|
} else {
|
|
410
|
-
const
|
|
411
|
-
if (
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
}
|
|
415
|
-
let name;
|
|
416
|
-
let firstName;
|
|
417
|
-
let lastName;
|
|
418
|
-
let email = "";
|
|
419
|
-
let phone;
|
|
420
|
-
let message;
|
|
421
|
-
const customFields = {};
|
|
422
|
-
for (const [rawKey, values] of buckets.entries()) {
|
|
423
|
-
if (values.length === 0) continue;
|
|
424
|
-
const normalized = normalizeKey(rawKey);
|
|
425
|
-
const firstString = String(values[0] ?? "").trim();
|
|
426
|
-
if (normalized === "name" || normalized === "full_name" || normalized === "your_name") {
|
|
427
|
-
name = firstString;
|
|
428
|
-
continue;
|
|
429
|
-
}
|
|
430
|
-
if (normalized === "first_name" || normalized === "firstname") {
|
|
431
|
-
firstName = firstString;
|
|
432
|
-
continue;
|
|
433
|
-
}
|
|
434
|
-
if (normalized === "last_name" || normalized === "lastname") {
|
|
435
|
-
lastName = firstString;
|
|
436
|
-
continue;
|
|
437
|
-
}
|
|
438
|
-
if (normalized === "email" || normalized === "email_address" || normalized === "e_mail" || normalized === "e_mail_address") {
|
|
439
|
-
email = firstString.toLowerCase();
|
|
440
|
-
continue;
|
|
441
|
-
}
|
|
442
|
-
if (normalized === "phone" || normalized === "phone_number" || normalized === "telephone" || normalized === "tel") {
|
|
443
|
-
phone = firstString;
|
|
444
|
-
continue;
|
|
467
|
+
const cleaned = String(rawValue).trim().replace(CONTROL_CHARS_RE, "").slice(0, 2e3);
|
|
468
|
+
if (cleaned.length > 0) {
|
|
469
|
+
sanitizedValue = cleaned;
|
|
470
|
+
}
|
|
445
471
|
}
|
|
446
|
-
if (
|
|
447
|
-
|
|
472
|
+
if (sanitizedValue === void 0) continue;
|
|
473
|
+
if (fieldCount >= MAX_CUSTOM_FIELDS) {
|
|
474
|
+
tooManyCustomFields = true;
|
|
448
475
|
continue;
|
|
449
476
|
}
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
} else {
|
|
458
|
-
customFields[normalized] = v.slice(0, 2e3);
|
|
459
|
-
}
|
|
460
|
-
} else {
|
|
461
|
-
customFields[normalized] = values.map((v) => String(v).slice(0, 200)).slice(0, 25);
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
if (!name && (firstName || lastName)) {
|
|
465
|
-
name = [firstName, lastName].filter(Boolean).join(" ").trim();
|
|
477
|
+
Object.defineProperty(customFields, key, {
|
|
478
|
+
value: sanitizedValue,
|
|
479
|
+
enumerable: true,
|
|
480
|
+
writable: true,
|
|
481
|
+
configurable: true
|
|
482
|
+
});
|
|
483
|
+
fieldCount += 1;
|
|
466
484
|
}
|
|
467
|
-
return {
|
|
468
|
-
...name ? { name } : {},
|
|
469
|
-
email,
|
|
470
|
-
...phone ? { phone } : {},
|
|
471
|
-
...message ? { message } : {},
|
|
472
|
-
honeypot,
|
|
473
|
-
...turnstileToken ? { turnstileToken } : {},
|
|
474
|
-
customFields,
|
|
475
|
-
blockedSensitiveKeys
|
|
476
|
-
};
|
|
485
|
+
return { customFields, blockedSensitiveKeys, tooManyCustomFields };
|
|
477
486
|
}
|
|
478
487
|
|
|
479
488
|
// src/next/leads-route.ts
|
|
@@ -492,6 +501,56 @@ function checkLocalRateLimit(key, maxRequests = 15, windowMs = 10 * 60 * 1e3) {
|
|
|
492
501
|
current.count += 1;
|
|
493
502
|
return true;
|
|
494
503
|
}
|
|
504
|
+
var VERCEL_REQUEST_CONTEXT_SYMBOL = /* @__PURE__ */ Symbol.for("@vercel/request-context");
|
|
505
|
+
function hasVercelBotIdRuntimeContext() {
|
|
506
|
+
const ctx = globalThis[VERCEL_REQUEST_CONTEXT_SYMBOL]?.get?.();
|
|
507
|
+
if (!ctx || typeof ctx.mutateResponseHeadersBeforeFlush !== "function") {
|
|
508
|
+
return false;
|
|
509
|
+
}
|
|
510
|
+
const oidcToken = ctx.headers?.["x-vercel-oidc-token"] ?? process.env.VERCEL_OIDC_TOKEN;
|
|
511
|
+
return Boolean(oidcToken);
|
|
512
|
+
}
|
|
513
|
+
async function verifyVercelBotId(option, checkBotIdImpl) {
|
|
514
|
+
if (option === false) return { ok: true };
|
|
515
|
+
if (process.env.WR_SANDBOX === "1" || process.env.WR_SYNTHETIC_LEADS === "1") {
|
|
516
|
+
return { ok: true };
|
|
517
|
+
}
|
|
518
|
+
if (!checkBotIdImpl) {
|
|
519
|
+
if (process.env.VERCEL !== "1" || !hasVercelBotIdRuntimeContext()) {
|
|
520
|
+
return { ok: true };
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
const envLevel = process.env.WR_BOTID_CHECK_LEVEL?.trim();
|
|
524
|
+
const checkLevel = typeof option === "object" && option.checkLevel ? option.checkLevel : envLevel === "basic" || envLevel === "deepAnalysis" ? envLevel : void 0;
|
|
525
|
+
const failClosed = typeof option === "object" && option.failClosed === true;
|
|
526
|
+
try {
|
|
527
|
+
const checker = checkBotIdImpl ?? checkBotId;
|
|
528
|
+
const verdict = await checker(
|
|
529
|
+
checkLevel ? { advancedOptions: { checkLevel } } : void 0
|
|
530
|
+
);
|
|
531
|
+
if (verdict.isBot) {
|
|
532
|
+
return {
|
|
533
|
+
ok: false,
|
|
534
|
+
status: 403,
|
|
535
|
+
error: "Verification failed. Please try again."
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
return { ok: true };
|
|
539
|
+
} catch (err) {
|
|
540
|
+
console.warn(
|
|
541
|
+
"[site-kit/leads] Vercel BotID check failed",
|
|
542
|
+
err instanceof Error ? err.message : "unknown"
|
|
543
|
+
);
|
|
544
|
+
if (failClosed) {
|
|
545
|
+
return {
|
|
546
|
+
ok: false,
|
|
547
|
+
status: 503,
|
|
548
|
+
error: "Verification temporarily unavailable. Please try again."
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
return { ok: true };
|
|
552
|
+
}
|
|
553
|
+
}
|
|
495
554
|
async function verifyTurnstile(token, remoteIp) {
|
|
496
555
|
const secret = process.env.TURNSTILE_SECRET_KEY?.trim();
|
|
497
556
|
if (!secret) return { ok: true };
|
|
@@ -660,22 +719,10 @@ function createLeadRouteHandler(getConfig, options) {
|
|
|
660
719
|
{ status: 400 }
|
|
661
720
|
);
|
|
662
721
|
}
|
|
663
|
-
const honeypot = String(rawBody.honeypot
|
|
722
|
+
const honeypot = String(rawBody.honeypot || rawBody.website || "").trim();
|
|
664
723
|
if (honeypot.length > 0) {
|
|
665
724
|
return NextResponse.json({ ok: true, leadId: randomUUID() });
|
|
666
725
|
}
|
|
667
|
-
if (options?.verifyTurnstile !== false) {
|
|
668
|
-
const turnstile = await verifyTurnstile(
|
|
669
|
-
typeof rawBody.turnstileToken === "string" ? rawBody.turnstileToken : void 0,
|
|
670
|
-
clientIp === "unknown" ? null : clientIp
|
|
671
|
-
);
|
|
672
|
-
if (!turnstile.ok) {
|
|
673
|
-
return NextResponse.json(
|
|
674
|
-
{ ok: false, error: "Verification failed. Please try again." },
|
|
675
|
-
{ status: 400 }
|
|
676
|
-
);
|
|
677
|
-
}
|
|
678
|
-
}
|
|
679
726
|
const formId = typeof rawBody.formId === "string" ? rawBody.formId.trim() : "contact";
|
|
680
727
|
if (!FORM_ID_RE.test(formId)) {
|
|
681
728
|
return NextResponse.json(
|
|
@@ -686,50 +733,77 @@ function createLeadRouteHandler(getConfig, options) {
|
|
|
686
733
|
const formKind = typeof rawBody.formKind === "string" && ["lead", "newsletter", "resource", "calculator", "consultation", "event"].includes(
|
|
687
734
|
rawBody.formKind
|
|
688
735
|
) ? rawBody.formKind : "lead";
|
|
689
|
-
const
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
]);
|
|
698
|
-
if (packed.blockedSensitiveKeys.length > 0) {
|
|
736
|
+
const name = typeof rawBody.name === "string" ? rawBody.name.trim().slice(0, 250) || void 0 : void 0;
|
|
737
|
+
const email = typeof rawBody.email === "string" ? rawBody.email.trim().toLowerCase() : "";
|
|
738
|
+
const phone = typeof rawBody.phone === "string" ? rawBody.phone.trim().slice(0, 100) || void 0 : void 0;
|
|
739
|
+
const message = typeof rawBody.message === "string" ? rawBody.message.trim().slice(0, 2e4) || void 0 : void 0;
|
|
740
|
+
const { customFields, blockedSensitiveKeys, tooManyCustomFields } = sanitizeCustomFields(
|
|
741
|
+
rawBody.customFields && typeof rawBody.customFields === "object" && !Array.isArray(rawBody.customFields) ? rawBody.customFields : void 0
|
|
742
|
+
);
|
|
743
|
+
if (blockedSensitiveKeys.length > 0) {
|
|
699
744
|
return NextResponse.json(
|
|
700
745
|
{ ok: false, error: "Sensitive credential fields are not accepted." },
|
|
701
746
|
{ status: 400 }
|
|
702
747
|
);
|
|
703
748
|
}
|
|
704
|
-
if (
|
|
749
|
+
if (tooManyCustomFields) {
|
|
750
|
+
return NextResponse.json(
|
|
751
|
+
{ ok: false, error: "Too many custom fields (maximum 40)." },
|
|
752
|
+
{ status: 400 }
|
|
753
|
+
);
|
|
754
|
+
}
|
|
755
|
+
if (!email || email.length > 254 || !EMAIL_RE.test(email)) {
|
|
705
756
|
return NextResponse.json(
|
|
706
757
|
{ ok: false, error: "Please enter a valid email address." },
|
|
707
758
|
{ status: 400 }
|
|
708
759
|
);
|
|
709
760
|
}
|
|
710
761
|
const allowsEmailOnly = formKind === "newsletter" || formKind === "resource";
|
|
711
|
-
if (!allowsEmailOnly && !
|
|
762
|
+
if (!allowsEmailOnly && !name) {
|
|
712
763
|
return NextResponse.json(
|
|
713
764
|
{ ok: false, error: "Please enter your name." },
|
|
714
765
|
{ status: 400 }
|
|
715
766
|
);
|
|
716
767
|
}
|
|
768
|
+
const botIdCheck = await verifyVercelBotId(
|
|
769
|
+
options?.verifyBotId,
|
|
770
|
+
options?.checkBotIdImpl
|
|
771
|
+
);
|
|
772
|
+
if (!botIdCheck.ok) {
|
|
773
|
+
return NextResponse.json(
|
|
774
|
+
{ ok: false, error: botIdCheck.error ?? "Verification failed." },
|
|
775
|
+
{ status: botIdCheck.status ?? 403 }
|
|
776
|
+
);
|
|
777
|
+
}
|
|
778
|
+
if (options?.verifyTurnstile !== false) {
|
|
779
|
+
const turnstile = await verifyTurnstile(
|
|
780
|
+
typeof rawBody.turnstileToken === "string" ? rawBody.turnstileToken : void 0,
|
|
781
|
+
clientIp === "unknown" ? null : clientIp
|
|
782
|
+
);
|
|
783
|
+
if (!turnstile.ok) {
|
|
784
|
+
return NextResponse.json(
|
|
785
|
+
{ ok: false, error: "Verification failed. Please try again." },
|
|
786
|
+
{ status: 400 }
|
|
787
|
+
);
|
|
788
|
+
}
|
|
789
|
+
}
|
|
717
790
|
const config = getConfig();
|
|
718
791
|
const submissionId = typeof rawBody.submissionId === "string" && rawBody.submissionId.trim() ? rawBody.submissionId.trim() : randomUUID();
|
|
719
792
|
const sourceUrl = typeof rawBody.sourceUrl === "string" && rawBody.sourceUrl.startsWith("http") ? rawBody.sourceUrl : config.seo?.siteUrl || "https://example.invalid/";
|
|
793
|
+
const websiteVisit = sanitizeWebsiteVisit(rawBody.websiteVisit);
|
|
720
794
|
const submission = {
|
|
721
795
|
formId,
|
|
722
796
|
formKind,
|
|
723
797
|
submissionId,
|
|
724
798
|
...typeof rawBody.advisorId === "string" ? { advisorId: rawBody.advisorId } : {},
|
|
725
|
-
...
|
|
726
|
-
email
|
|
727
|
-
...
|
|
728
|
-
...
|
|
729
|
-
...Object.keys(
|
|
799
|
+
...name ? { name } : {},
|
|
800
|
+
email,
|
|
801
|
+
...phone ? { phone } : {},
|
|
802
|
+
...message ? { message } : {},
|
|
803
|
+
...Object.keys(customFields).length > 0 ? { customFields } : {},
|
|
730
804
|
sourceUrl,
|
|
731
805
|
attribution: rawBody.attribution && typeof rawBody.attribution === "object" ? rawBody.attribution : {},
|
|
732
|
-
...
|
|
806
|
+
...websiteVisit ? { websiteVisit } : {}
|
|
733
807
|
};
|
|
734
808
|
const result = await submitLeadToWealthReach({
|
|
735
809
|
config,
|
|
@@ -51,6 +51,7 @@ type ConsentConfig = z.infer<typeof consentConfigSchema>;
|
|
|
51
51
|
declare const visitorsConfigSchema: z.ZodObject<{
|
|
52
52
|
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
53
53
|
siteScriptUrl: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
54
|
+
recordings: z.ZodOptional<z.ZodBoolean>;
|
|
54
55
|
}, z.core.$strip>;
|
|
55
56
|
type VisitorsConfig = z.infer<typeof visitorsConfigSchema>;
|
|
56
57
|
declare const blogConfigSchema: z.ZodObject<{
|
|
@@ -1213,6 +1214,7 @@ declare const siteConfigSchema: z.ZodPipe<z.ZodObject<{
|
|
|
1213
1214
|
visitors: z.ZodOptional<z.ZodObject<{
|
|
1214
1215
|
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
1215
1216
|
siteScriptUrl: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
1217
|
+
recordings: z.ZodOptional<z.ZodBoolean>;
|
|
1216
1218
|
}, z.core.$strip>>;
|
|
1217
1219
|
integrations: z.ZodDefault<z.ZodOptional<z.ZodObject<{
|
|
1218
1220
|
gtmId: z.ZodOptional<z.ZodString>;
|
|
@@ -2628,6 +2630,7 @@ declare const siteConfigSchema: z.ZodPipe<z.ZodObject<{
|
|
|
2628
2630
|
visitors?: {
|
|
2629
2631
|
enabled: boolean;
|
|
2630
2632
|
siteScriptUrl: string;
|
|
2633
|
+
recordings?: boolean | undefined;
|
|
2631
2634
|
} | undefined;
|
|
2632
2635
|
jsonLd?: {
|
|
2633
2636
|
organization?: {
|
|
@@ -2894,6 +2897,7 @@ declare const siteConfigSchema: z.ZodPipe<z.ZodObject<{
|
|
|
2894
2897
|
visitors?: {
|
|
2895
2898
|
enabled: boolean;
|
|
2896
2899
|
siteScriptUrl: string;
|
|
2900
|
+
recordings?: boolean | undefined;
|
|
2897
2901
|
} | undefined;
|
|
2898
2902
|
jsonLd?: {
|
|
2899
2903
|
organization?: {
|
|
@@ -48,6 +48,7 @@ declare const siteConfigSchema: z.ZodPipe<z.ZodObject<{
|
|
|
48
48
|
visitors: z.ZodOptional<z.ZodObject<{
|
|
49
49
|
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
50
50
|
siteScriptUrl: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
51
|
+
recordings: z.ZodOptional<z.ZodBoolean>;
|
|
51
52
|
}, z.core.$strip>>;
|
|
52
53
|
integrations: z.ZodDefault<z.ZodOptional<z.ZodObject<{
|
|
53
54
|
gtmId: z.ZodOptional<z.ZodString>;
|
|
@@ -1463,6 +1464,7 @@ declare const siteConfigSchema: z.ZodPipe<z.ZodObject<{
|
|
|
1463
1464
|
visitors?: {
|
|
1464
1465
|
enabled: boolean;
|
|
1465
1466
|
siteScriptUrl: string;
|
|
1467
|
+
recordings?: boolean | undefined;
|
|
1466
1468
|
} | undefined;
|
|
1467
1469
|
jsonLd?: {
|
|
1468
1470
|
organization?: {
|
|
@@ -1729,6 +1731,7 @@ declare const siteConfigSchema: z.ZodPipe<z.ZodObject<{
|
|
|
1729
1731
|
visitors?: {
|
|
1730
1732
|
enabled: boolean;
|
|
1731
1733
|
siteScriptUrl: string;
|
|
1734
|
+
recordings?: boolean | undefined;
|
|
1732
1735
|
} | undefined;
|
|
1733
1736
|
jsonLd?: {
|
|
1734
1737
|
organization?: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wealthreach/site-kit",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Shared compliance, universal form tracking, BrandywineOak consent, WCAG 2.2 AA accessibility, blog/draft, and Next.js plumbing for bespoke WealthReach advisor sites.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -71,6 +71,7 @@
|
|
|
71
71
|
}
|
|
72
72
|
},
|
|
73
73
|
"dependencies": {
|
|
74
|
+
"botid": "^1.5.13",
|
|
74
75
|
"gray-matter": "^4.0.3",
|
|
75
76
|
"zod": "^4.6.7"
|
|
76
77
|
},
|