@wealthreach/site-kit 1.0.2 → 1.0.3

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.
@@ -223,7 +223,7 @@ var bookingConfigSchema = z2.object({
223
223
  var consentConfigSchema = z2.object({
224
224
  enabled: z2.boolean().default(true),
225
225
  message: z2.string().trim().optional().default(""),
226
- policyUrl: z2.string().trim().optional().default("/privacy-policy"),
226
+ policyUrl: z2.string().trim().optional().default(""),
227
227
  /** Legacy cookie names to migrate silently for returning visitors (e.g. Brandywine Oak). */
228
228
  legacyConsentCookies: z2.array(z2.string().trim().min(1)).optional().default([]),
229
229
  /** Additional US states requiring opt-in beyond California (CA is always opt-in). */
@@ -233,7 +233,8 @@ var consentConfigSchema = z2.object({
233
233
  });
234
234
  var visitorsConfigSchema = z2.object({
235
235
  enabled: z2.boolean().default(false),
236
- siteScriptUrl: z2.string().trim().optional().default("")
236
+ siteScriptUrl: z2.string().trim().optional().default(""),
237
+ recordings: z2.boolean().optional()
237
238
  });
238
239
  var blogConfigSchema = z2.object({
239
240
  enabled: z2.boolean().optional().default(true),
@@ -282,7 +283,7 @@ var siteConfigSchema = z2.object({
282
283
  consent: consentConfigSchema.optional().default({
283
284
  enabled: true,
284
285
  message: "",
285
- policyUrl: "/privacy-policy",
286
+ policyUrl: "",
286
287
  legacyConsentCookies: [],
287
288
  extraOptInUsRegions: [],
288
289
  hideFloatingPrivacyButton: false
@@ -355,125 +356,132 @@ function displayNameFromLegal(legalName) {
355
356
  return legalName.trim().replace(LEGAL_SUFFIX_RE, "").trim() || legalName.trim();
356
357
  }
357
358
 
359
+ // src/consent/core.ts
360
+ var CONSENT_MAX_AGE = 60 * 60 * 24 * 180;
361
+ var MODE_MAX_AGE = 60 * 60 * 24;
362
+
363
+ // src/analytics/attribution.ts
364
+ var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
365
+ var VISITOR_KEY_RE = /^[a-zA-Z0-9_-]{16,128}$/;
366
+ 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;
367
+ var SESSION_IDLE_MS = 30 * 60 * 1e3;
368
+ var MAX_JOURNEY_SERIALIZED_BYTES = 16384;
369
+ function sanitizeWebsiteJourney(raw) {
370
+ if (!Array.isArray(raw)) return void 0;
371
+ const entries = [];
372
+ for (const item of raw.slice(-10)) {
373
+ if (!item || typeof item !== "object" || Array.isArray(item)) continue;
374
+ const row = item;
375
+ const sessionId = typeof row.sessionId === "string" ? row.sessionId.trim() : "";
376
+ const startedAt = typeof row.startedAt === "string" ? row.startedAt.trim() : "";
377
+ if (!UUID_RE.test(sessionId) || !ISO_OFFSET_DATETIME_RE.test(startedAt) || Number.isNaN(Date.parse(startedAt))) {
378
+ continue;
379
+ }
380
+ const pages = Array.isArray(row.pages) ? row.pages.filter(
381
+ (page) => typeof page === "string" && page.length > 0 && page.length <= 2048
382
+ ).slice(-100) : [];
383
+ const referrer = typeof row.referrer === "string" && row.referrer.length <= 2048 ? row.referrer : row.referrer === null ? null : void 0;
384
+ const activeMs = typeof row.activeMs === "number" && Number.isFinite(row.activeMs) && row.activeMs >= 0 ? Math.min(864e5, Math.round(row.activeMs)) : void 0;
385
+ entries.push({
386
+ sessionId,
387
+ startedAt,
388
+ pages,
389
+ ...referrer !== void 0 ? { referrer } : {},
390
+ ...activeMs !== void 0 ? { activeMs } : {}
391
+ });
392
+ }
393
+ while (entries.length > 1 && JSON.stringify(entries).length > MAX_JOURNEY_SERIALIZED_BYTES) {
394
+ entries.shift();
395
+ }
396
+ if (entries.length === 1 && JSON.stringify(entries).length > MAX_JOURNEY_SERIALIZED_BYTES) {
397
+ const latest = entries[0];
398
+ while (latest.pages.length > 0 && JSON.stringify(entries).length > MAX_JOURNEY_SERIALIZED_BYTES) {
399
+ latest.pages.shift();
400
+ }
401
+ if (JSON.stringify(entries).length > MAX_JOURNEY_SERIALIZED_BYTES) {
402
+ return void 0;
403
+ }
404
+ }
405
+ return entries.length > 0 ? entries : void 0;
406
+ }
407
+ function sanitizeWebsiteVisit(raw) {
408
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return void 0;
409
+ const obj = raw;
410
+ const visitorKey = typeof obj.visitorKey === "string" ? obj.visitorKey.trim() : "";
411
+ const sessionId = typeof obj.sessionId === "string" ? obj.sessionId.trim() : "";
412
+ if (!VISITOR_KEY_RE.test(visitorKey) || !UUID_RE.test(sessionId)) {
413
+ return void 0;
414
+ }
415
+ const device = obj.device === "mobile" ? "mobile" : "desktop";
416
+ const journey = sanitizeWebsiteJourney(obj.journey);
417
+ return {
418
+ visitorKey,
419
+ sessionId,
420
+ device,
421
+ ...journey ? { journey } : {}
422
+ };
423
+ }
424
+
358
425
  // src/forms/packing.ts
359
426
  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 HONEYPOT_KEYS = /* @__PURE__ */ new Set([
361
- "website",
362
- "company_website",
363
- "wr_hp",
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
- }
427
+ var CUSTOM_FIELD_KEY_RE = /^[a-zA-Z0-9_.-]{1,64}$/;
428
+ var CONTROL_CHARS_RE = /[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g;
429
+ var PROTOTYPE_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
430
+ var MAX_CUSTOM_FIELDS = 40;
374
431
  function isSensitiveFieldKey(key) {
375
432
  return SENSITIVE_FIELD_RE.test(key);
376
433
  }
377
- function packFormEntries(entries) {
378
- const buckets = /* @__PURE__ */ new Map();
379
- let honeypot = "";
380
- let turnstileToken;
434
+ function sanitizeCustomFields(input) {
435
+ const customFields = {};
381
436
  const blockedSensitiveKeys = [];
382
- for (const [rawKey, rawValue] of entries) {
383
- if (typeof File !== "undefined" && rawValue instanceof File) continue;
437
+ let tooManyCustomFields = false;
438
+ let fieldCount = 0;
439
+ if (!input || typeof input !== "object" || Array.isArray(input)) {
440
+ return { customFields, blockedSensitiveKeys, tooManyCustomFields };
441
+ }
442
+ for (const [rawKey, rawValue] of Object.entries(input)) {
443
+ if (rawValue === void 0 || rawValue === null) continue;
384
444
  const key = rawKey.trim();
385
445
  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
446
  if (isSensitiveFieldKey(key)) {
398
447
  blockedSensitiveKeys.push(key);
399
448
  continue;
400
449
  }
401
- const list = buckets.get(key) ?? [];
402
- if (Array.isArray(rawValue)) {
403
- for (const item of rawValue) {
404
- const s = String(item).trim();
405
- if (s) list.push(s);
450
+ if (PROTOTYPE_KEYS.has(key) || !CUSTOM_FIELD_KEY_RE.test(key)) continue;
451
+ let sanitizedValue;
452
+ if (typeof rawValue === "boolean") {
453
+ sanitizedValue = rawValue;
454
+ } else if (Array.isArray(rawValue)) {
455
+ const cleaned = rawValue.map(
456
+ (item) => String(item).trim().replace(CONTROL_CHARS_RE, "").slice(0, 200)
457
+ ).filter((s) => s.length > 0).slice(0, 25);
458
+ if (cleaned.length > 0) {
459
+ sanitizedValue = cleaned;
460
+ }
461
+ } else if (typeof rawValue === "number") {
462
+ if (Number.isFinite(rawValue)) {
463
+ sanitizedValue = String(rawValue);
406
464
  }
407
- } else if (typeof rawValue === "boolean") {
408
- list.push(rawValue);
409
465
  } else {
410
- const s = String(rawValue ?? "").trim();
411
- if (s.length > 0) list.push(s);
412
- }
413
- buckets.set(key, list);
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;
466
+ const cleaned = String(rawValue).trim().replace(CONTROL_CHARS_RE, "").slice(0, 2e3);
467
+ if (cleaned.length > 0) {
468
+ sanitizedValue = cleaned;
469
+ }
445
470
  }
446
- if (normalized === "message" || normalized === "comments" || normalized === "notes" || normalized === "how_can_we_help") {
447
- message = firstString;
471
+ if (sanitizedValue === void 0) continue;
472
+ if (fieldCount >= MAX_CUSTOM_FIELDS) {
473
+ tooManyCustomFields = true;
448
474
  continue;
449
475
  }
450
- if (!normalized) continue;
451
- if (values.length === 1) {
452
- const v = values[0];
453
- if (typeof v === "boolean") {
454
- customFields[normalized] = v;
455
- } else if (v === "on") {
456
- customFields[normalized] = true;
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();
476
+ Object.defineProperty(customFields, key, {
477
+ value: sanitizedValue,
478
+ enumerable: true,
479
+ writable: true,
480
+ configurable: true
481
+ });
482
+ fieldCount += 1;
466
483
  }
467
- return {
468
- ...name ? { name } : {},
469
- email,
470
- ...phone ? { phone } : {},
471
- ...message ? { message } : {},
472
- honeypot,
473
- ...turnstileToken ? { turnstileToken } : {},
474
- customFields,
475
- blockedSensitiveKeys
476
- };
484
+ return { customFields, blockedSensitiveKeys, tooManyCustomFields };
477
485
  }
478
486
 
479
487
  // src/next/leads-route.ts
@@ -660,7 +668,7 @@ function createLeadRouteHandler(getConfig, options) {
660
668
  { status: 400 }
661
669
  );
662
670
  }
663
- const honeypot = String(rawBody.honeypot ?? rawBody.website ?? "").trim();
671
+ const honeypot = String(rawBody.honeypot || rawBody.website || "").trim();
664
672
  if (honeypot.length > 0) {
665
673
  return NextResponse.json({ ok: true, leadId: randomUUID() });
666
674
  }
@@ -686,29 +694,33 @@ function createLeadRouteHandler(getConfig, options) {
686
694
  const formKind = typeof rawBody.formKind === "string" && ["lead", "newsletter", "resource", "calculator", "consultation", "event"].includes(
687
695
  rawBody.formKind
688
696
  ) ? rawBody.formKind : "lead";
689
- const packed = packFormEntries([
690
- ...typeof rawBody.name === "string" ? [["name", rawBody.name]] : [],
691
- ...typeof rawBody.email === "string" ? [["email", rawBody.email]] : [],
692
- ...typeof rawBody.phone === "string" ? [["phone", rawBody.phone]] : [],
693
- ...typeof rawBody.message === "string" ? [["message", rawBody.message]] : [],
694
- ...rawBody.customFields && typeof rawBody.customFields === "object" && !Array.isArray(rawBody.customFields) ? Object.entries(
695
- rawBody.customFields
696
- ) : []
697
- ]);
698
- if (packed.blockedSensitiveKeys.length > 0) {
697
+ const name = typeof rawBody.name === "string" ? rawBody.name.trim().slice(0, 250) || void 0 : void 0;
698
+ const email = typeof rawBody.email === "string" ? rawBody.email.trim().toLowerCase() : "";
699
+ const phone = typeof rawBody.phone === "string" ? rawBody.phone.trim().slice(0, 100) || void 0 : void 0;
700
+ const message = typeof rawBody.message === "string" ? rawBody.message.trim().slice(0, 2e4) || void 0 : void 0;
701
+ const { customFields, blockedSensitiveKeys, tooManyCustomFields } = sanitizeCustomFields(
702
+ rawBody.customFields && typeof rawBody.customFields === "object" && !Array.isArray(rawBody.customFields) ? rawBody.customFields : void 0
703
+ );
704
+ if (blockedSensitiveKeys.length > 0) {
699
705
  return NextResponse.json(
700
706
  { ok: false, error: "Sensitive credential fields are not accepted." },
701
707
  { status: 400 }
702
708
  );
703
709
  }
704
- if (!packed.email || !EMAIL_RE.test(packed.email)) {
710
+ if (tooManyCustomFields) {
711
+ return NextResponse.json(
712
+ { ok: false, error: "Too many custom fields (maximum 40)." },
713
+ { status: 400 }
714
+ );
715
+ }
716
+ if (!email || email.length > 254 || !EMAIL_RE.test(email)) {
705
717
  return NextResponse.json(
706
718
  { ok: false, error: "Please enter a valid email address." },
707
719
  { status: 400 }
708
720
  );
709
721
  }
710
722
  const allowsEmailOnly = formKind === "newsletter" || formKind === "resource";
711
- if (!allowsEmailOnly && !packed.name) {
723
+ if (!allowsEmailOnly && !name) {
712
724
  return NextResponse.json(
713
725
  { ok: false, error: "Please enter your name." },
714
726
  { status: 400 }
@@ -717,19 +729,20 @@ function createLeadRouteHandler(getConfig, options) {
717
729
  const config = getConfig();
718
730
  const submissionId = typeof rawBody.submissionId === "string" && rawBody.submissionId.trim() ? rawBody.submissionId.trim() : randomUUID();
719
731
  const sourceUrl = typeof rawBody.sourceUrl === "string" && rawBody.sourceUrl.startsWith("http") ? rawBody.sourceUrl : config.seo?.siteUrl || "https://example.invalid/";
732
+ const websiteVisit = sanitizeWebsiteVisit(rawBody.websiteVisit);
720
733
  const submission = {
721
734
  formId,
722
735
  formKind,
723
736
  submissionId,
724
737
  ...typeof rawBody.advisorId === "string" ? { advisorId: rawBody.advisorId } : {},
725
- ...packed.name ? { name: packed.name } : {},
726
- email: packed.email,
727
- ...packed.phone ? { phone: packed.phone } : {},
728
- ...packed.message ? { message: packed.message } : {},
729
- ...Object.keys(packed.customFields).length > 0 ? { customFields: packed.customFields } : {},
738
+ ...name ? { name } : {},
739
+ email,
740
+ ...phone ? { phone } : {},
741
+ ...message ? { message } : {},
742
+ ...Object.keys(customFields).length > 0 ? { customFields } : {},
730
743
  sourceUrl,
731
744
  attribution: rawBody.attribution && typeof rawBody.attribution === "object" ? rawBody.attribution : {},
732
- ...rawBody.websiteVisit && typeof rawBody.websiteVisit === "object" ? { websiteVisit: rawBody.websiteVisit } : {}
745
+ ...websiteVisit ? { websiteVisit } : {}
733
746
  };
734
747
  const result = await submitLeadToWealthReach({
735
748
  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.2",
3
+ "version": "1.0.3",
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",