@garagem-ai/site-sdk 0.13.4 → 0.13.6

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/index.mjs CHANGED
@@ -479,6 +479,75 @@ async function getShareLink(options) {
479
479
  );
480
480
  }
481
481
 
482
+ // src/analytics-document.ts
483
+ var FILTER_SEGMENT_SOURCE = "(?:^|-)(?:quartos|banheiros|suites|suite|vagas)$|(?:^|-)(?:reais|m2)$|^mapa$";
484
+ var CLICK_ID_SOURCE = "^(?:fbclid|gclid|gbraid|wbraid|msclkid|ttclid|igshid|yclid|twclid|mc_eid|mc_cid|gad_source|_gl)$";
485
+ var DOCUMENT_QUERY_KEYS = ["q", "ordenar", "page", "pagina"];
486
+ var FILTER_SEGMENT = new RegExp(FILTER_SEGMENT_SOURCE, "i");
487
+ var CLICK_ID = new RegExp(CLICK_ID_SOURCE);
488
+ function isAnalyticsDocumentUrl(href) {
489
+ let url;
490
+ try {
491
+ url = new URL(href, "https://site.invalid");
492
+ } catch {
493
+ return true;
494
+ }
495
+ const pageRaw = param(url, "page") ?? param(url, "pagina");
496
+ if (pageRaw != null && pageRaw !== "") {
497
+ const page = Number(pageRaw);
498
+ if (!Number.isInteger(page) || page !== 1) return false;
499
+ }
500
+ const path = url.pathname.replace(/\/+$/, "").toLowerCase() || "/";
501
+ if (path !== "/imoveis" && !path.startsWith("/imoveis/")) return true;
502
+ for (const key of url.searchParams.keys()) {
503
+ if (ignoredQuery(key.toLowerCase())) continue;
504
+ return false;
505
+ }
506
+ const segments = path.split("/").filter(Boolean).slice(1);
507
+ return segments.every((segment) => !FILTER_SEGMENT.test(segment));
508
+ }
509
+ function param(url, name) {
510
+ for (const [key, value] of url.searchParams) {
511
+ if (key.toLowerCase() === name) return value;
512
+ }
513
+ return null;
514
+ }
515
+ function ignoredQuery(key) {
516
+ return DOCUMENT_QUERY_KEYS.includes(key) || key.startsWith("utm_") || CLICK_ID.test(key);
517
+ }
518
+ function analyticsDocumentGuardSource() {
519
+ return `const FILTER_SEGMENT = /${FILTER_SEGMENT_SOURCE}/i;
520
+ const CLICK_ID = /${CLICK_ID_SOURCE}/;
521
+ const DOCUMENT_QUERY = ["q", "ordenar", "page", "pagina"];
522
+
523
+ function documentUrl(href) {
524
+ let url;
525
+ try {
526
+ url = new URL(href, "https://site.invalid");
527
+ } catch {
528
+ return true;
529
+ }
530
+ let pageRaw = null;
531
+ for (const [key, value] of url.searchParams) {
532
+ const name = key.toLowerCase();
533
+ if (pageRaw == null && (name === "page" || name === "pagina")) pageRaw = value;
534
+ }
535
+ if (pageRaw != null && pageRaw !== "") {
536
+ const page = Number(pageRaw);
537
+ if (!Number.isInteger(page) || page !== 1) return false;
538
+ }
539
+ const path = url.pathname.replace(/\\/+$/, "").toLowerCase() || "/";
540
+ if (path !== "/imoveis" && !path.startsWith("/imoveis/")) return true;
541
+ for (const key of url.searchParams.keys()) {
542
+ const name = key.toLowerCase();
543
+ if (DOCUMENT_QUERY.includes(name) || name.startsWith("utm_") || CLICK_ID.test(name)) continue;
544
+ return false;
545
+ }
546
+ const segments = path.split("/").filter(Boolean).slice(1);
547
+ return segments.every((segment) => !FILTER_SEGMENT.test(segment));
548
+ }`;
549
+ }
550
+
482
551
  // ../search-url/types.ts
483
552
  var SEARCH_BASE_ROUTE = "imoveis";
484
553
  var MAX_PAGE = 1e4;
@@ -546,6 +615,19 @@ var LISTING_TYPE_ALIASES = {
546
615
  rental: ["alugar"]
547
616
  };
548
617
 
618
+ // ../search-url/listing-identity.ts
619
+ var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
620
+ var LISTING_CODE_RE = /^(?:[A-Za-z0-9]+|[A-Z0-9]+(?:-[A-Z0-9]+)+)$/;
621
+ var LETTER_CODE_RE = /^[A-Z]{5}$/;
622
+ function isShortListingIdentity(segment) {
623
+ if (UUID_RE.test(segment) || LETTER_CODE_RE.test(segment)) return true;
624
+ return /\d/.test(segment) && LISTING_CODE_RE.test(segment);
625
+ }
626
+ function isShortListingPath(pathname) {
627
+ const parts = (pathname.split(/[?#]/)[0] ?? "").split("/").filter(Boolean);
628
+ return parts.length === 2 && parts[0] === SEARCH_BASE_ROUTE && isShortListingIdentity(parts[1] ?? "");
629
+ }
630
+
549
631
  // ../search-url/path.ts
550
632
  function toArray(value) {
551
633
  if (value === void 0) return [];
@@ -642,6 +724,7 @@ function parseSearchPublicPath(pathname, dictionary = emptySearchUrlDictionary()
642
724
  if (segments.some((segment) => segment.toLowerCase().startsWith("id-"))) {
643
725
  return null;
644
726
  }
727
+ if (isShortListingPath(raw)) return null;
645
728
  const filters = {};
646
729
  const locationParts = [];
647
730
  const propertyTypes = [];
@@ -1016,9 +1099,9 @@ function pathnameOnly(pathname) {
1016
1099
  return String(pathname || "").split(/[?#]/)[0] || "/";
1017
1100
  }
1018
1101
  function isListingDetailPath(pathname) {
1019
- const parts = pathnameOnly(pathname).split("/").filter(Boolean);
1020
- const last = parts[parts.length - 1] || "";
1021
- return last.toLowerCase().startsWith("id-");
1102
+ const path = pathnameOnly(pathname);
1103
+ const last = path.split("/").filter(Boolean).pop() || "";
1104
+ return last.toLowerCase().startsWith("id-") || isShortListingPath(path);
1022
1105
  }
1023
1106
  function readPublicSearch(pathname, search, dictionary) {
1024
1107
  const pathFilters = parseSearchPublicPath2(pathnameOnly(pathname), dictionary) || {};
@@ -1341,8 +1424,17 @@ function searchChromeModel(schema, pathFilters, locationNames) {
1341
1424
 
1342
1425
  // src/analytics.ts
1343
1426
  var SITE_ANALYTICS_EVENT = "garagem:site-event";
1427
+ function browserPageHref() {
1428
+ if (typeof window === "undefined") return null;
1429
+ const location = window.location;
1430
+ return typeof location?.href === "string" ? location.href : null;
1431
+ }
1344
1432
  function emitSiteEvent(event, properties) {
1345
1433
  if (typeof window === "undefined") return;
1434
+ const href = browserPageHref();
1435
+ if (href && event !== "lead_generated" && !isAnalyticsDocumentUrl(href)) {
1436
+ return;
1437
+ }
1346
1438
  window.dispatchEvent(
1347
1439
  new CustomEvent(SITE_ANALYTICS_EVENT, { detail: { event, properties } })
1348
1440
  );
@@ -1949,7 +2041,7 @@ var LeadSubmitError = class extends Error {
1949
2041
  this.retryAfter = info.retryAfterSeconds ?? null;
1950
2042
  }
1951
2043
  };
1952
- var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
2044
+ var UUID_RE2 = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
1953
2045
  var EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
1954
2046
  var NAME_RE = /^[^\d\s]{2,}.*$/;
1955
2047
  var MESSAGE_MAX = 2e3;
@@ -2001,7 +2093,7 @@ async function getLeadUi(options) {
2001
2093
  );
2002
2094
  }
2003
2095
  function assertListingId(listingId) {
2004
- if (!UUID_RE.test(listingId.trim())) {
2096
+ if (!UUID_RE2.test(listingId.trim())) {
2005
2097
  throw new LeadSubmitError(
2006
2098
  "Garagem SDK: listingId must be the listing UUID, not a path or code.",
2007
2099
  { code: "invalid_listing_id" }
@@ -3274,7 +3366,10 @@ var STUDIO_SDK_CONTRACT = {
3274
3366
  "rangeDraftFromPath",
3275
3367
  // `unknownSearchLocation` is in git. Prompts inline the same check with
3276
3368
  // `parseSearchPublicPath` + `locationsPath` until this name is on the pin.
3277
- "unknownSearchLocation"
3369
+ "unknownSearchLocation",
3370
+ // In git. The installed client inlines the check. Naming it in a prompt
3371
+ // makes v0 import it from the pinned tarball, which does not export it.
3372
+ "isAnalyticsDocumentUrl"
3278
3373
  ],
3279
3374
  /**
3280
3375
  * maps.fndn.ai helpers (static map, street view, boundaries, travel
@@ -5013,6 +5108,7 @@ export {
5013
5108
  STUDIO_SITE_LAYOUT,
5014
5109
  TOOLBAR_PRIMARY_FILTER_IDS,
5015
5110
  VISIT_TIME_ZONE,
5111
+ analyticsDocumentGuardSource,
5016
5112
  applyMatchedPhotoCover,
5017
5113
  applyPathFilter,
5018
5114
  boundaryCitySlug,
@@ -5066,6 +5162,7 @@ export {
5066
5162
  hrefForAppliedChange,
5067
5163
  hrefForPathFilters,
5068
5164
  hrefWithExplicitPage,
5165
+ isAnalyticsDocumentUrl,
5069
5166
  isAnalyticsOnPin,
5070
5167
  isListingDetailPath,
5071
5168
  isMapBounds,