@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.
@@ -89,13 +89,25 @@ function readBrowserCookie(name) {
89
89
  return null;
90
90
  }
91
91
  }
92
- function readStoredConsent(legacyCookieNames = []) {
92
+ function legacyConsentStorageKey(siteId) {
93
+ return `wr:consent:${siteId?.trim() || "site"}`;
94
+ }
95
+ function readStoredConsent(legacyCookieNames = [], siteId) {
93
96
  const direct = parseConsentValue(readBrowserCookie(CONSENT_COOKIE));
94
97
  if (direct) return direct;
95
98
  for (const legacy of legacyCookieNames) {
96
99
  const migrated = parseConsentValue(readBrowserCookie(legacy));
97
100
  if (migrated) return migrated;
98
101
  }
102
+ if (siteId !== void 0 && typeof window !== "undefined") {
103
+ try {
104
+ const legacyChoice = window.localStorage.getItem(
105
+ legacyConsentStorageKey(siteId)
106
+ );
107
+ if (legacyChoice === "declined") return "analytics:no";
108
+ } catch {
109
+ }
110
+ }
99
111
  return null;
100
112
  }
101
113
  function writeConsentCookie(value) {
@@ -119,7 +131,7 @@ function resolveGeoFromHeaders(headers) {
119
131
 
120
132
  // src/consent/bootstrap.ts
121
133
  function safeJson(value) {
122
- return JSON.stringify(value).replace(/</g, "\\u003c");
134
+ return JSON.stringify(value).replace(/</g, "\\u003c").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
123
135
  }
124
136
  var GTM_ID_RE = /^GTM-[A-Z0-9]{4,16}$/;
125
137
  var GA4_ID_RE = /^G-[A-Z0-9]{4,16}$/;
@@ -153,6 +165,7 @@ function buildConsentBootstrapScript(options) {
153
165
  const ga4Id = sanitizeGa4Id(options.ga4MeasurementId);
154
166
  if (!visitorUrl && !gtmId && !ga4Id) return null;
155
167
  const legacy = options.legacyConsentCookies ?? [];
168
+ const legacyStorageCheck = options.siteId !== void 0 ? `if(!c){try{if(window.localStorage.getItem(${safeJson(legacyConsentStorageKey(options.siteId))})==='declined')c='analytics:no';}catch(e){}}` : "";
156
169
  const loaders = [];
157
170
  if (visitorUrl) {
158
171
  loaders.push(
@@ -169,7 +182,7 @@ function buildConsentBootstrapScript(options) {
169
182
  `if(!document.getElementById('${GA4_SCRIPT_ID}')){window.dataLayer=window.dataLayer||[];function gtag(){window.dataLayer.push(arguments);}window.gtag=window.gtag||gtag;gtag('js',new Date());gtag('config',${safeJson(ga4Id)});var a=document.createElement('script');a.id='${GA4_SCRIPT_ID}';a.async=true;a.src=${safeJson(`https://www.googletagmanager.com/gtag/js?id=${encodeURIComponent(ga4Id)}`)};a.setAttribute('data-consent-category','analytics');document.head.appendChild(a);}`
170
183
  );
171
184
  }
172
- return `(function(){try{var g=function(n){var p=document.cookie.split('; ').find(function(v){return v.indexOf(n+'=')===0});return p?decodeURIComponent(p.slice(n.length+1)):null};var c=g('${CONSENT_COOKIE}');if(!c){var leg=${safeJson(legacy)};for(var i=0;i<leg.length;i++){var lv=g(leg[i]);if(lv){c=lv.indexOf('analytics:yes')>-1?'analytics:yes':lv.indexOf('analytics:no')>-1?'analytics:no':null;if(c)break;}}}if(c==='analytics:no')return;var gpc=navigator.globalPrivacyControl===true;if(c!=='analytics:yes'&&!(g('${MODE_COOKIE}')==='opt-out'&&!gpc))return;${loaders.join("")}}catch(e){}})();`;
185
+ return `(function(){try{var g=function(n){var p=document.cookie.split('; ').find(function(v){return v.indexOf(n+'=')===0});return p?decodeURIComponent(p.slice(n.length+1)):null};var c=g('${CONSENT_COOKIE}');if(!c){var leg=${safeJson(legacy)};for(var i=0;i<leg.length;i++){var lv=g(leg[i]);if(lv){c=lv.indexOf('analytics:yes')>-1?'analytics:yes':lv.indexOf('analytics:no')>-1?'analytics:no':null;if(c)break;}}}${legacyStorageCheck}if(c==='analytics:no')return;var gpc=navigator.globalPrivacyControl===true;if(c!=='analytics:yes'&&!(g('${MODE_COOKIE}')==='opt-out'&&!gpc))return;${loaders.join("")}}catch(e){}})();`;
173
186
  }
174
187
 
175
188
  // src/consent/provider.tsx
@@ -404,7 +417,7 @@ var bookingConfigSchema = z2.object({
404
417
  var consentConfigSchema = z2.object({
405
418
  enabled: z2.boolean().default(true),
406
419
  message: z2.string().trim().optional().default(""),
407
- policyUrl: z2.string().trim().optional().default("/privacy-policy"),
420
+ policyUrl: z2.string().trim().optional().default(""),
408
421
  /** Legacy cookie names to migrate silently for returning visitors (e.g. Brandywine Oak). */
409
422
  legacyConsentCookies: z2.array(z2.string().trim().min(1)).optional().default([]),
410
423
  /** Additional US states requiring opt-in beyond California (CA is always opt-in). */
@@ -414,7 +427,8 @@ var consentConfigSchema = z2.object({
414
427
  });
415
428
  var visitorsConfigSchema = z2.object({
416
429
  enabled: z2.boolean().default(false),
417
- siteScriptUrl: z2.string().trim().optional().default("")
430
+ siteScriptUrl: z2.string().trim().optional().default(""),
431
+ recordings: z2.boolean().optional()
418
432
  });
419
433
  var blogConfigSchema = z2.object({
420
434
  enabled: z2.boolean().optional().default(true),
@@ -463,7 +477,7 @@ var siteConfigSchema = z2.object({
463
477
  consent: consentConfigSchema.optional().default({
464
478
  enabled: true,
465
479
  message: "",
466
- policyUrl: "/privacy-policy",
480
+ policyUrl: "",
467
481
  legacyConsentCookies: [],
468
482
  extraOptInUsRegions: [],
469
483
  hideFloatingPrivacyButton: false
@@ -622,7 +636,7 @@ function ConsentProvider({
622
636
  useEffect(() => {
623
637
  let cancelled = false;
624
638
  const legacyCookies = config.consent?.legacyConsentCookies ?? [];
625
- const storedDecision = readStoredConsent(legacyCookies);
639
+ const storedDecision = readStoredConsent(legacyCookies, config.siteId);
626
640
  const detectedGpc = readGpcSignal();
627
641
  const rawMode = readBrowserCookie(MODE_COOKIE);
628
642
  const finalize = (resolvedMode) => {
@@ -663,6 +677,18 @@ function ConsentProvider({
663
677
  (value2) => {
664
678
  const wasMounted = hasMountedThirdPartyScripts();
665
679
  writeConsentCookie(value2);
680
+ if (typeof window !== "undefined") {
681
+ try {
682
+ const legacyKey = legacyConsentStorageKey(config.siteId);
683
+ if (value2 === "analytics:yes" || readBrowserCookie(CONSENT_COOKIE) === value2) {
684
+ window.localStorage.removeItem(legacyKey);
685
+ }
686
+ } catch {
687
+ }
688
+ window.dispatchEvent(
689
+ new CustomEvent("wr:consent-changed", { detail: { consent: value2 } })
690
+ );
691
+ }
666
692
  setDecision(value2);
667
693
  setBannerOpen(false);
668
694
  setReopened(false);
@@ -757,6 +783,7 @@ export {
757
783
  parseConsentValue,
758
784
  readCookieFromString,
759
785
  readBrowserCookie,
786
+ legacyConsentStorageKey,
760
787
  readStoredConsent,
761
788
  writeConsentCookie,
762
789
  readGpcSignal,
@@ -1,5 +1,5 @@
1
- import { S as SiteConfig } from '../schema-C1ixytx2.js';
2
- export { B as BlogConfig, a as BookingConfig, C as ComplianceConfig, b as ConsentConfig, c as CtaLink, D as DEFAULT_ANALYTICS_ENDPOINT, d as DEFAULT_LEADS_API_URL, F as FooterGroup, I as IntegrationsConfig, N as NavItem, e as SocialLink, V as VisitorsConfig, f as blogConfigSchema, g as bookingConfigSchema, h as complianceConfigSchema, i as consentConfigSchema, j as ctaLinkSchema, k as displayNameFromLegal, l as footerGroupSchema, m as integrationsConfigSchema, n as navItemSchema, s as siteConfigSchema, o as socialLinkSchema, v as visitorsConfigSchema } from '../schema-C1ixytx2.js';
1
+ import { S as SiteConfig } from '../schema-AcsTlgUv.js';
2
+ export { B as BlogConfig, a as BookingConfig, C as ComplianceConfig, b as ConsentConfig, c as CtaLink, D as DEFAULT_ANALYTICS_ENDPOINT, d as DEFAULT_LEADS_API_URL, F as FooterGroup, I as IntegrationsConfig, N as NavItem, e as SocialLink, V as VisitorsConfig, f as blogConfigSchema, g as bookingConfigSchema, h as complianceConfigSchema, i as consentConfigSchema, j as ctaLinkSchema, k as displayNameFromLegal, l as footerGroupSchema, m as integrationsConfigSchema, n as navItemSchema, s as siteConfigSchema, o as socialLinkSchema, v as visitorsConfigSchema } from '../schema-AcsTlgUv.js';
3
3
  import { Metadata } from 'next';
4
4
  import 'zod';
5
5
  import '../regulatory-schema-uDKNJ7q8.js';
@@ -219,7 +219,7 @@ var bookingConfigSchema = z2.object({
219
219
  var consentConfigSchema = z2.object({
220
220
  enabled: z2.boolean().default(true),
221
221
  message: z2.string().trim().optional().default(""),
222
- policyUrl: z2.string().trim().optional().default("/privacy-policy"),
222
+ policyUrl: z2.string().trim().optional().default(""),
223
223
  /** Legacy cookie names to migrate silently for returning visitors (e.g. Brandywine Oak). */
224
224
  legacyConsentCookies: z2.array(z2.string().trim().min(1)).optional().default([]),
225
225
  /** Additional US states requiring opt-in beyond California (CA is always opt-in). */
@@ -229,7 +229,8 @@ var consentConfigSchema = z2.object({
229
229
  });
230
230
  var visitorsConfigSchema = z2.object({
231
231
  enabled: z2.boolean().default(false),
232
- siteScriptUrl: z2.string().trim().optional().default("")
232
+ siteScriptUrl: z2.string().trim().optional().default(""),
233
+ recordings: z2.boolean().optional()
233
234
  });
234
235
  var blogConfigSchema = z2.object({
235
236
  enabled: z2.boolean().optional().default(true),
@@ -278,7 +279,7 @@ var siteConfigSchema = z2.object({
278
279
  consent: consentConfigSchema.optional().default({
279
280
  enabled: true,
280
281
  message: "",
281
- policyUrl: "/privacy-policy",
282
+ policyUrl: "",
282
283
  legacyConsentCookies: [],
283
284
  extraOptInUsRegions: [],
284
285
  hideFloatingPrivacyButton: false
@@ -1,5 +1,5 @@
1
1
  import React__default from 'react';
2
- import { S as SiteConfig } from '../schema-DD0nDOD0.js';
2
+ import { S as SiteConfig } from '../schema-CYsBDpoU.js';
3
3
  import 'zod';
4
4
 
5
5
  /**
@@ -24,7 +24,8 @@ declare function analyticsAllowed(consent: ConsentValue | null, mode: PrivacyMod
24
24
  declare function parseConsentValue(raw: string | null): ConsentValue | null;
25
25
  declare function readCookieFromString(cookieHeader: string, name: string): string | null;
26
26
  declare function readBrowserCookie(name: string): string | null;
27
- declare function readStoredConsent(legacyCookieNames?: readonly string[]): ConsentValue | null;
27
+ declare function legacyConsentStorageKey(siteId?: string): string;
28
+ declare function readStoredConsent(legacyCookieNames?: readonly string[], siteId?: string): ConsentValue | null;
28
29
  declare function writeConsentCookie(value: ConsentValue): void;
29
30
  declare function readGpcSignal(): boolean;
30
31
  declare function resolveGeoFromHeaders(headers: Headers): {
@@ -33,6 +34,7 @@ declare function resolveGeoFromHeaders(headers: Headers): {
33
34
  };
34
35
 
35
36
  interface ConsentBootstrapOptions {
37
+ siteId?: string;
36
38
  visitorScriptUrl?: string;
37
39
  gtmId?: string;
38
40
  ga4MeasurementId?: string;
@@ -99,5 +101,5 @@ interface ConsentBannerProps {
99
101
  */
100
102
  declare function ConsentBanner({ floatingButtonClassName, bannerClassName, }?: ConsentBannerProps): React__default.JSX.Element | null;
101
103
 
102
- export { CONSENT_COOKIE, CONSENT_MAX_AGE, ConsentBanner, ConsentGate, ConsentProvider, DEFAULT_OPT_IN_US_REGIONS, GA4_SCRIPT_ID, GTM_SCRIPT_ID, MODE_COOKIE, MODE_MAX_AGE, OPT_IN_COUNTRIES, PrivacyChoicesButton, VISITOR_SCRIPT_ID, analyticsAllowed, buildConsentBootstrapScript, parseConsentValue, privacyModeForLocation, readBrowserCookie, readCookieFromString, readGpcSignal, readStoredConsent, resolveGeoFromHeaders, sanitizeGa4Id, sanitizeGtmId, sanitizeVisitorScriptUrl, useConsent, writeConsentCookie };
104
+ export { CONSENT_COOKIE, CONSENT_MAX_AGE, ConsentBanner, ConsentGate, ConsentProvider, DEFAULT_OPT_IN_US_REGIONS, GA4_SCRIPT_ID, GTM_SCRIPT_ID, MODE_COOKIE, MODE_MAX_AGE, OPT_IN_COUNTRIES, PrivacyChoicesButton, VISITOR_SCRIPT_ID, analyticsAllowed, buildConsentBootstrapScript, legacyConsentStorageKey, parseConsentValue, privacyModeForLocation, readBrowserCookie, readCookieFromString, readGpcSignal, readStoredConsent, resolveGeoFromHeaders, sanitizeGa4Id, sanitizeGtmId, sanitizeVisitorScriptUrl, useConsent, writeConsentCookie };
103
105
  export type { ConsentBannerProps, ConsentBootstrapOptions, ConsentContextValue, ConsentProviderProps, ConsentValue, PrivacyChoicesButtonProps, PrivacyMode };
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  ConsentBanner,
4
4
  PrivacyChoicesButton
5
- } from "../chunk-Y77ARZE4.js";
5
+ } from "../chunk-DHVKLLL7.js";
6
6
  import {
7
7
  CONSENT_COOKIE,
8
8
  CONSENT_MAX_AGE,
@@ -17,6 +17,7 @@ import {
17
17
  VISITOR_SCRIPT_ID,
18
18
  analyticsAllowed,
19
19
  buildConsentBootstrapScript,
20
+ legacyConsentStorageKey,
20
21
  parseConsentValue,
21
22
  privacyModeForLocation,
22
23
  readBrowserCookie,
@@ -29,7 +30,7 @@ import {
29
30
  sanitizeVisitorScriptUrl,
30
31
  useConsent,
31
32
  writeConsentCookie
32
- } from "../chunk-7GDXQ6UB.js";
33
+ } from "../chunk-T4Q4VJ6K.js";
33
34
  export {
34
35
  CONSENT_COOKIE,
35
36
  CONSENT_MAX_AGE,
@@ -46,6 +47,7 @@ export {
46
47
  VISITOR_SCRIPT_ID,
47
48
  analyticsAllowed,
48
49
  buildConsentBootstrapScript,
50
+ legacyConsentStorageKey,
49
51
  parseConsentValue,
50
52
  privacyModeForLocation,
51
53
  readBrowserCookie,
@@ -27,7 +27,19 @@ interface FormSuccessResult<TData = unknown> {
27
27
  data?: TData;
28
28
  }
29
29
 
30
+ declare const MAX_CUSTOM_FIELDS = 40;
30
31
  declare function isSensitiveFieldKey(key: string): boolean;
32
+ interface SanitizedCustomFieldsResult {
33
+ customFields: Record<string, string | boolean | string[]>;
34
+ blockedSensitiveKeys: string[];
35
+ tooManyCustomFields: boolean;
36
+ }
37
+ /**
38
+ * Sanitizes explicitly separated `customFields` without applying honeypot
39
+ * detection, canonical field aliasing (`email_address` -> `email`), or
40
+ * string-to-boolean `"on"` coercion.
41
+ */
42
+ declare function sanitizeCustomFields(input: Record<string, CustomFieldValue | undefined> | null | undefined): SanitizedCustomFieldsResult;
31
43
  interface PackedFormValues {
32
44
  name?: string;
33
45
  email: string;
@@ -37,6 +49,7 @@ interface PackedFormValues {
37
49
  turnstileToken?: string;
38
50
  customFields: Record<string, string | boolean | string[]>;
39
51
  blockedSensitiveKeys: string[];
52
+ tooManyCustomFields: boolean;
40
53
  }
41
54
  /**
42
55
  * Extracts canonical lead fields (handling real-world aliases like `Full-Name`,
@@ -85,17 +98,16 @@ declare function useWealthReachForm<TData = unknown>(options: UseWealthReachForm
85
98
  phone?: string;
86
99
  message?: string;
87
100
  customFields?: Record<string, CustomFieldValue>;
101
+ honeypot?: string;
88
102
  turnstileToken?: string;
89
103
  }) => Promise<{
90
- ok: false;
91
- error: string;
92
- leadId?: undefined;
93
- data?: undefined;
94
- } | {
95
104
  ok: true;
96
105
  leadId: string;
97
106
  data: TData | undefined;
98
107
  error?: undefined;
108
+ } | {
109
+ ok: false;
110
+ error: string;
99
111
  }>;
100
112
  status: "idle" | "submitting" | "success" | "error";
101
113
  errors: Record<string, string>;
@@ -124,5 +136,5 @@ declare function WealthReachHiddenContext({ formId, formKind, }: {
124
136
  formKind?: FormKind;
125
137
  }): React__default.JSX.Element;
126
138
 
127
- export { FORM_KINDS, WealthReachForm, WealthReachHiddenContext, isSensitiveFieldKey, packFormEntries, useWealthReachForm };
128
- export type { CustomFieldValue, FormKind, FormSuccessResult, NormalizedLeadSubmission, PackedFormValues, UseWealthReachFormOptions, WealthReachFormProps };
139
+ export { FORM_KINDS, MAX_CUSTOM_FIELDS, WealthReachForm, WealthReachHiddenContext, isSensitiveFieldKey, packFormEntries, sanitizeCustomFields, useWealthReachForm };
140
+ export type { CustomFieldValue, FormKind, FormSuccessResult, NormalizedLeadSubmission, PackedFormValues, SanitizedCustomFieldsResult, UseWealthReachFormOptions, WealthReachFormProps };
@@ -3,10 +3,10 @@ import {
3
3
  readAttributionSnapshot,
4
4
  readConsentedWebsiteVisit,
5
5
  trackFormSubmission
6
- } from "../chunk-QQP7VG2C.js";
6
+ } from "../chunk-JPUCXNHR.js";
7
7
  import {
8
8
  useConsent
9
- } from "../chunk-7GDXQ6UB.js";
9
+ } from "../chunk-T4Q4VJ6K.js";
10
10
 
11
11
  // src/forms/types.ts
12
12
  var FORM_KINDS = [
@@ -22,10 +22,13 @@ var FORM_KINDS = [
22
22
  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;
23
23
  var HONEYPOT_KEYS = /* @__PURE__ */ new Set([
24
24
  "website",
25
- "company_website",
26
25
  "wr_hp",
27
26
  "_hp"
28
27
  ]);
28
+ var CUSTOM_FIELD_KEY_RE = /^[a-zA-Z0-9_.-]{1,64}$/;
29
+ var CONTROL_CHARS_RE = /[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g;
30
+ var PROTOTYPE_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
31
+ var MAX_CUSTOM_FIELDS = 40;
29
32
  var INTERNAL_KEYS = /* @__PURE__ */ new Set([
30
33
  "cf-turnstile-response",
31
34
  "turnstileToken",
@@ -37,6 +40,58 @@ function normalizeKey(raw) {
37
40
  function isSensitiveFieldKey(key) {
38
41
  return SENSITIVE_FIELD_RE.test(key);
39
42
  }
43
+ function sanitizeCustomFields(input) {
44
+ const customFields = {};
45
+ const blockedSensitiveKeys = [];
46
+ let tooManyCustomFields = false;
47
+ let fieldCount = 0;
48
+ if (!input || typeof input !== "object" || Array.isArray(input)) {
49
+ return { customFields, blockedSensitiveKeys, tooManyCustomFields };
50
+ }
51
+ for (const [rawKey, rawValue] of Object.entries(input)) {
52
+ if (rawValue === void 0 || rawValue === null) continue;
53
+ const key = rawKey.trim();
54
+ if (!key) continue;
55
+ if (isSensitiveFieldKey(key)) {
56
+ blockedSensitiveKeys.push(key);
57
+ continue;
58
+ }
59
+ if (PROTOTYPE_KEYS.has(key) || !CUSTOM_FIELD_KEY_RE.test(key)) continue;
60
+ let sanitizedValue;
61
+ if (typeof rawValue === "boolean") {
62
+ sanitizedValue = rawValue;
63
+ } else if (Array.isArray(rawValue)) {
64
+ const cleaned = rawValue.map(
65
+ (item) => String(item).trim().replace(CONTROL_CHARS_RE, "").slice(0, 200)
66
+ ).filter((s) => s.length > 0).slice(0, 25);
67
+ if (cleaned.length > 0) {
68
+ sanitizedValue = cleaned;
69
+ }
70
+ } else if (typeof rawValue === "number") {
71
+ if (Number.isFinite(rawValue)) {
72
+ sanitizedValue = String(rawValue);
73
+ }
74
+ } else {
75
+ const cleaned = String(rawValue).trim().replace(CONTROL_CHARS_RE, "").slice(0, 2e3);
76
+ if (cleaned.length > 0) {
77
+ sanitizedValue = cleaned;
78
+ }
79
+ }
80
+ if (sanitizedValue === void 0) continue;
81
+ if (fieldCount >= MAX_CUSTOM_FIELDS) {
82
+ tooManyCustomFields = true;
83
+ continue;
84
+ }
85
+ Object.defineProperty(customFields, key, {
86
+ value: sanitizedValue,
87
+ enumerable: true,
88
+ writable: true,
89
+ configurable: true
90
+ });
91
+ fieldCount += 1;
92
+ }
93
+ return { customFields, blockedSensitiveKeys, tooManyCustomFields };
94
+ }
40
95
  function packFormEntries(entries) {
41
96
  const buckets = /* @__PURE__ */ new Map();
42
97
  let honeypot = "";
@@ -75,6 +130,14 @@ function packFormEntries(entries) {
75
130
  }
76
131
  buckets.set(key, list);
77
132
  }
133
+ const normalizedKeys = /* @__PURE__ */ new Set();
134
+ for (const [rawKey, values] of buckets.entries()) {
135
+ if (values.length > 0) normalizedKeys.add(normalizeKey(rawKey));
136
+ }
137
+ const hasExactName = normalizedKeys.has("name");
138
+ const hasExactEmail = normalizedKeys.has("email");
139
+ const hasExactPhone = normalizedKeys.has("phone");
140
+ const hasExactMessage = normalizedKeys.has("message");
78
141
  let name;
79
142
  let firstName;
80
143
  let lastName;
@@ -82,47 +145,49 @@ function packFormEntries(entries) {
82
145
  let phone;
83
146
  let message;
84
147
  const customFields = {};
148
+ let customFieldCount = 0;
149
+ let tooManyCustomFields = false;
85
150
  for (const [rawKey, values] of buckets.entries()) {
86
151
  if (values.length === 0) continue;
87
152
  const normalized = normalizeKey(rawKey);
88
153
  const firstString = String(values[0] ?? "").trim();
89
- if (normalized === "name" || normalized === "full_name" || normalized === "your_name") {
154
+ if (normalized === "name" || !hasExactName && (normalized === "full_name" || normalized === "your_name")) {
90
155
  name = firstString;
91
156
  continue;
92
157
  }
93
- if (normalized === "first_name" || normalized === "firstname") {
158
+ if (!hasExactName && (normalized === "first_name" || normalized === "firstname")) {
94
159
  firstName = firstString;
95
160
  continue;
96
161
  }
97
- if (normalized === "last_name" || normalized === "lastname") {
162
+ if (!hasExactName && (normalized === "last_name" || normalized === "lastname")) {
98
163
  lastName = firstString;
99
164
  continue;
100
165
  }
101
- if (normalized === "email" || normalized === "email_address" || normalized === "e_mail" || normalized === "e_mail_address") {
166
+ if (normalized === "email" || !hasExactEmail && (normalized === "email_address" || normalized === "e_mail" || normalized === "e_mail_address")) {
102
167
  email = firstString.toLowerCase();
103
168
  continue;
104
169
  }
105
- if (normalized === "phone" || normalized === "phone_number" || normalized === "telephone" || normalized === "tel") {
170
+ if (normalized === "phone" || !hasExactPhone && (normalized === "phone_number" || normalized === "telephone" || normalized === "tel")) {
106
171
  phone = firstString;
107
172
  continue;
108
173
  }
109
- if (normalized === "message" || normalized === "comments" || normalized === "notes" || normalized === "how_can_we_help") {
174
+ if (normalized === "message" || !hasExactMessage && (normalized === "comments" || normalized === "notes" || normalized === "how_can_we_help")) {
110
175
  message = firstString;
111
176
  continue;
112
177
  }
113
- if (!normalized) continue;
114
- if (values.length === 1) {
115
- const v = values[0];
116
- if (typeof v === "boolean") {
117
- customFields[normalized] = v;
118
- } else if (v === "on") {
119
- customFields[normalized] = true;
120
- } else {
121
- customFields[normalized] = v.slice(0, 2e3);
122
- }
123
- } else {
124
- customFields[normalized] = values.map((v) => String(v).slice(0, 200)).slice(0, 25);
178
+ if (!normalized || PROTOTYPE_KEYS.has(normalized)) continue;
179
+ if (customFieldCount >= MAX_CUSTOM_FIELDS) {
180
+ tooManyCustomFields = true;
181
+ continue;
125
182
  }
183
+ const packedValue = values.length === 1 ? typeof values[0] === "boolean" ? values[0] : values[0].replace(CONTROL_CHARS_RE, "").slice(0, 2e3) : values.map((v) => String(v).replace(CONTROL_CHARS_RE, "").slice(0, 200)).slice(0, 25);
184
+ Object.defineProperty(customFields, normalized, {
185
+ value: packedValue,
186
+ enumerable: true,
187
+ writable: true,
188
+ configurable: true
189
+ });
190
+ customFieldCount += 1;
126
191
  }
127
192
  if (!name && (firstName || lastName)) {
128
193
  name = [firstName, lastName].filter(Boolean).join(" ").trim();
@@ -135,7 +200,8 @@ function packFormEntries(entries) {
135
200
  honeypot,
136
201
  ...turnstileToken ? { turnstileToken } : {},
137
202
  customFields,
138
- blockedSensitiveKeys
203
+ blockedSensitiveKeys,
204
+ tooManyCustomFields
139
205
  };
140
206
  }
141
207
 
@@ -198,20 +264,27 @@ function useWealthReachForm(options) {
198
264
  setStatus("error");
199
265
  return { ok: false, error: "Blocked sensitive fields" };
200
266
  }
267
+ if (packed.tooManyCustomFields) {
268
+ setServerError(
269
+ "This form has too many fields to submit (maximum 40 custom fields)."
270
+ );
271
+ setStatus("error");
272
+ return { ok: false, error: "Too many custom fields" };
273
+ }
201
274
  const allowsEmailOnly = formKind === "newsletter" || formKind === "resource";
202
275
  if (!allowsEmailOnly && !packed.name) {
203
276
  nextErrors.name = "Please enter your name.";
204
277
  }
205
- if (!packed.email || !EMAIL_RE.test(packed.email)) {
278
+ if (!packed.email || packed.email.length > 254 || !EMAIL_RE.test(packed.email)) {
206
279
  nextErrors.email = "Please enter a valid email address.";
207
280
  }
208
281
  if (validate) {
209
282
  const flat = {
283
+ ...packed.customFields,
210
284
  ...packed.name ? { name: packed.name } : {},
211
285
  email: packed.email,
212
286
  ...packed.phone ? { phone: packed.phone } : {},
213
- ...packed.message ? { message: packed.message } : {},
214
- ...packed.customFields
287
+ ...packed.message ? { message: packed.message } : {}
215
288
  };
216
289
  Object.assign(nextErrors, validate(flat));
217
290
  }
@@ -259,6 +332,11 @@ function useWealthReachForm(options) {
259
332
  }
260
333
  if (!config.visitors?.enabled && consentAllowed) {
261
334
  trackFormSubmission(formId, pathname ?? "/", config);
335
+ } else if (config.visitors?.enabled && consentAllowed && typeof window !== "undefined") {
336
+ try {
337
+ window.__wrVisitor?.markFormSubmitted?.(formRef.current);
338
+ } catch {
339
+ }
262
340
  }
263
341
  const leadId = data.leadId ?? submissionId;
264
342
  submissionIdRef.current = createSubmissionId();
@@ -294,31 +372,50 @@ function useWealthReachForm(options) {
294
372
  async (event) => {
295
373
  event.preventDefault();
296
374
  if (status === "submitting") return;
297
- const fd = new FormData(event.currentTarget);
298
- const packed = packFormEntries(fd.entries());
375
+ const formEl = event.currentTarget;
376
+ const fd = new FormData(formEl);
377
+ const checkboxNames = /* @__PURE__ */ new Set();
378
+ for (const el of Array.from(formEl.elements)) {
379
+ if (el instanceof HTMLInputElement && el.type === "checkbox" && el.name) {
380
+ checkboxNames.add(el.name);
381
+ }
382
+ }
383
+ const entries = [];
384
+ for (const [k, v] of fd.entries()) {
385
+ if (checkboxNames.has(k) && v === "on") {
386
+ entries.push([k, true]);
387
+ } else {
388
+ entries.push([k, v]);
389
+ }
390
+ }
391
+ const packed = packFormEntries(entries);
299
392
  await sendPayload(packed);
300
393
  },
301
394
  [status, sendPayload]
302
395
  );
303
396
  const submit = useCallback(
304
397
  async (payload) => {
305
- const entries = [
306
- ["email", payload.email]
307
- ];
308
- if (payload.name !== void 0) entries.push(["name", payload.name]);
309
- if (payload.phone !== void 0) entries.push(["phone", payload.phone]);
310
- if (payload.message !== void 0) entries.push(["message", payload.message]);
311
- if (payload.turnstileToken) {
312
- entries.push(["turnstileToken", payload.turnstileToken]);
398
+ if (status === "submitting") {
399
+ return { ok: false, error: "Submission in progress" };
313
400
  }
314
- if (payload.customFields) {
315
- for (const [k, v] of Object.entries(payload.customFields)) {
316
- entries.push([k, v]);
317
- }
318
- }
319
- return sendPayload(packFormEntries(entries));
401
+ const { customFields, blockedSensitiveKeys, tooManyCustomFields } = sanitizeCustomFields(payload.customFields);
402
+ const name = payload.name?.trim();
403
+ const phone = payload.phone?.trim();
404
+ const message = payload.message?.trim();
405
+ const turnstileToken = payload.turnstileToken?.trim();
406
+ return sendPayload({
407
+ ...name ? { name } : {},
408
+ email: payload.email.trim().toLowerCase(),
409
+ ...phone ? { phone } : {},
410
+ ...message ? { message } : {},
411
+ honeypot: (payload.honeypot ?? "").trim(),
412
+ ...turnstileToken ? { turnstileToken } : {},
413
+ customFields,
414
+ blockedSensitiveKeys,
415
+ tooManyCustomFields
416
+ });
320
417
  },
321
- [sendPayload]
418
+ [status, sendPayload]
322
419
  );
323
420
  const getFieldProps = useCallback(
324
421
  (name) => {
@@ -441,9 +538,11 @@ function WealthReachHiddenContext({
441
538
  }
442
539
  export {
443
540
  FORM_KINDS,
541
+ MAX_CUSTOM_FIELDS,
444
542
  WealthReachForm,
445
543
  WealthReachHiddenContext,
446
544
  isSensitiveFieldKey,
447
545
  packFormEntries,
546
+ sanitizeCustomFields,
448
547
  useWealthReachForm
449
548
  };
@@ -27,6 +27,7 @@ __export(config_exports, {
27
27
  withWealthReach: () => withWealthReach
28
28
  });
29
29
  module.exports = __toCommonJS(config_exports);
30
+ var import_config = require("botid/next/config");
30
31
  var SANDBOX_DEV_ORIGINS = [
31
32
  "*.vercel.run",
32
33
  "*.vercel.app",
@@ -78,6 +79,7 @@ function withWealthReach(options = {}) {
78
79
  rootDir,
79
80
  blogPostsDir = "data/blog",
80
81
  extraFrameAncestors,
82
+ botId = true,
81
83
  headers: userHeaders,
82
84
  images: userImages,
83
85
  allowedDevOrigins: userDevOrigins,
@@ -106,7 +108,7 @@ function withWealthReach(options = {}) {
106
108
  /* @__PURE__ */ new Set([defaultTracingGlob, ...userTracing?.["/**"] ?? []])
107
109
  )
108
110
  };
109
- return {
111
+ const baseConfig = {
110
112
  devIndicators: false,
111
113
  poweredByHeader: false,
112
114
  productionBrowserSourceMaps: false,
@@ -129,6 +131,16 @@ function withWealthReach(options = {}) {
129
131
  return [{ source: "/(.*)", headers: baseHeaders }, ...extra];
130
132
  }
131
133
  };
134
+ if (!botId) return baseConfig;
135
+ const userRewrites = baseConfig.rewrites;
136
+ if (!userRewrites) return (0, import_config.withBotId)(baseConfig);
137
+ return (0, import_config.withBotId)({
138
+ ...baseConfig,
139
+ async rewrites() {
140
+ const rewrites = await userRewrites();
141
+ return Array.isArray(rewrites) ? rewrites : { ...rewrites, beforeFiles: rewrites.beforeFiles ?? [] };
142
+ }
143
+ });
132
144
  }
133
145
  // Annotate the CommonJS export names for ESM import in node:
134
146
  0 && (module.exports = {
@@ -23,6 +23,8 @@ interface WithWealthReachOptions extends NextConfig {
23
23
  blogPostsDir?: string;
24
24
  /** Additional CSP frame-ancestors origins beyond `'self'` and `https://*.wealthreach.ai`. */
25
25
  extraFrameAncestors?: string[];
26
+ /** Enable Vercel BotID challenge proxy rewrites for protected mutating routes like `POST /api/leads` (default `true`). Does not affect `GET` routes or AI crawlers. */
27
+ botId?: boolean;
26
28
  }
27
29
  /**
28
30
  * Wraps any client Next.js 16 config with WealthReach security headers, Eve
@@ -23,6 +23,8 @@ interface WithWealthReachOptions extends NextConfig {
23
23
  blogPostsDir?: string;
24
24
  /** Additional CSP frame-ancestors origins beyond `'self'` and `https://*.wealthreach.ai`. */
25
25
  extraFrameAncestors?: string[];
26
+ /** Enable Vercel BotID challenge proxy rewrites for protected mutating routes like `POST /api/leads` (default `true`). Does not affect `GET` routes or AI crawlers. */
27
+ botId?: boolean;
26
28
  }
27
29
  /**
28
30
  * Wraps any client Next.js 16 config with WealthReach security headers, Eve