@garagem-ai/site-sdk 0.13.5 → 0.14.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/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;
@@ -1355,8 +1424,17 @@ function searchChromeModel(schema, pathFilters, locationNames) {
1355
1424
 
1356
1425
  // src/analytics.ts
1357
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
+ }
1358
1432
  function emitSiteEvent(event, properties) {
1359
1433
  if (typeof window === "undefined") return;
1434
+ const href = browserPageHref();
1435
+ if (href && event !== "lead_generated" && !isAnalyticsDocumentUrl(href)) {
1436
+ return;
1437
+ }
1360
1438
  window.dispatchEvent(
1361
1439
  new CustomEvent(SITE_ANALYTICS_EVENT, { detail: { event, properties } })
1362
1440
  );
@@ -2830,9 +2908,21 @@ function listingAmenityGroups(listing, dictionary) {
2830
2908
  function listingLocationLabel(location) {
2831
2909
  return [location.neighborhood, location.city, location.state].map((part) => part ? String(part).trim() : "").filter(Boolean).join(", ");
2832
2910
  }
2911
+ function cardPriceLabel(isPrivate, collapsed, price, formattedPrice) {
2912
+ if (isPrivate) return "Sob consulta";
2913
+ if (collapsed && price != null) return `A partir de ${formattedPrice}`;
2914
+ return formattedPrice;
2915
+ }
2833
2916
  function toListingCardModel(listing) {
2834
2917
  const isPrivate = listing.priceVisibility === "private";
2835
2918
  const area = listing.property?.usableArea ?? listing.property?.totalArea;
2919
+ const unitCount = listing.development?.unitCount;
2920
+ const collapsed = typeof unitCount === "number" && unitCount > 1;
2921
+ const formattedPrice = formatListingPrice(
2922
+ listing.price,
2923
+ "pt-BR",
2924
+ listing.currency ?? "BRL"
2925
+ );
2836
2926
  return {
2837
2927
  href: listingPublicPath(listing),
2838
2928
  title: listing.title,
@@ -2840,7 +2930,12 @@ function toListingCardModel(listing) {
2840
2930
  businessLabel: listingBusinessLabel(listing.businessType),
2841
2931
  priceVisibility: listing.priceVisibility,
2842
2932
  price: listing.price,
2843
- priceLabel: isPrivate ? "Sob consulta" : formatListingPrice(listing.price, "pt-BR", listing.currency ?? "BRL"),
2933
+ priceLabel: cardPriceLabel(
2934
+ isPrivate,
2935
+ collapsed,
2936
+ listing.price,
2937
+ formattedPrice
2938
+ ),
2844
2939
  pricePeriod: listing.businessType === "rental" && !isPrivate && listing.price != null ? "/m\xEAs" : null,
2845
2940
  locationLabel: listingLocationLabel(listing.location || {}),
2846
2941
  propertyType: listing.property?.type ?? null,
@@ -2849,7 +2944,8 @@ function toListingCardModel(listing) {
2849
2944
  bedrooms: listing.property?.bedrooms ?? null,
2850
2945
  bathrooms: listing.property?.bathrooms ?? null,
2851
2946
  parkingSpaces: listing.property?.parkingSpaces ?? null,
2852
- areaM2: area ?? null
2947
+ areaM2: area ?? null,
2948
+ unitCount: collapsed && typeof unitCount === "number" ? unitCount : null
2853
2949
  };
2854
2950
  }
2855
2951
 
@@ -3288,7 +3384,10 @@ var STUDIO_SDK_CONTRACT = {
3288
3384
  "rangeDraftFromPath",
3289
3385
  // `unknownSearchLocation` is in git. Prompts inline the same check with
3290
3386
  // `parseSearchPublicPath` + `locationsPath` until this name is on the pin.
3291
- "unknownSearchLocation"
3387
+ "unknownSearchLocation",
3388
+ // In git. The installed client inlines the check. Naming it in a prompt
3389
+ // makes v0 import it from the pinned tarball, which does not export it.
3390
+ "isAnalyticsDocumentUrl"
3292
3391
  ],
3293
3392
  /**
3294
3393
  * maps.fndn.ai helpers (static map, street view, boundaries, travel
@@ -3380,7 +3479,15 @@ var STUDIO_SDK_CONTRACT = {
3380
3479
  * `studioCodegenContractViolations` flags `trackListingView`.
3381
3480
  */
3382
3481
  analyticsExports: ["trackListingView"],
3383
- analyticsSince: "0.13.0"
3482
+ analyticsSince: "0.13.0",
3483
+ /**
3484
+ * Development cards (`model.unitCount`, "A partir de" on `priceLabel`).
3485
+ * The search API can return `listing.development` before this pin.
3486
+ * Prompts must not name `unitCount` until `minNpmVersion` reaches
3487
+ * `developmentCardSince` — v0 copies the field and an older
3488
+ * `toListingCardModel` does not set it.
3489
+ */
3490
+ developmentCardSince: "0.14.0"
3384
3491
  };
3385
3492
  function isSellerLeadOnPin(pin = STUDIO_SDK_CONTRACT.minNpmVersion) {
3386
3493
  return compareSemver(pin, STUDIO_SDK_CONTRACT.sellerLeadSince) >= 0;
@@ -3505,9 +3612,20 @@ function studioLeadInstruction() {
3505
3612
  const phone = STUDIO_SDK_CONTRACT.phoneExports.join(", ");
3506
3613
  return `Listing-detail visit/contact leads: import ${names} from \`${STUDIO_SDK_PACKAGE}\` (the main package, not \`/react\`). Call \`submitVisitLead\` / \`submitContactLead\` \u2014 never concatenate a leads webhook URL and never POST the Showcase demo leads route. Phone fields: import ${phone} from the same package. Display draft is \`formatPhoneNational\` (default country \`BR\`); changing country calls \`remaskPhoneForCountry\`; submit \`toE164\` and require \`isValidPhone\`. Do not invent a second mask and do not import \`@garagem/ui\` PhoneInput.`;
3507
3614
  }
3508
- function studioListingCardInstruction() {
3615
+ function developmentCardPublished(pin = STUDIO_SDK_CONTRACT.minNpmVersion) {
3616
+ return compareSemver(pin, STUDIO_SDK_CONTRACT.developmentCardSince) >= 0;
3617
+ }
3618
+ function studioDevelopmentCardInstruction(pin = STUDIO_SDK_CONTRACT.minNpmVersion) {
3619
+ if (!developmentCardPublished(pin)) return "";
3620
+ return `Development cards: \`toListingCardModel\` sets \`model.unitCount\` when several primary-market units were collapsed into one card, and \`model.priceLabel\` already starts with "A partir de". When \`model.unitCount\` is greater than 1, show it as "N unidades" and omit that line when it is null. Keep \`model.title\`, \`model.priceLabel\`, and \`model.href\`. Do not group listings in the page.`;
3621
+ }
3622
+ function studioListingCardInstruction(pin = STUDIO_SDK_CONTRACT.minNpmVersion) {
3509
3623
  const names = STUDIO_SDK_CONTRACT.listingCardExports.join(", ");
3510
- return `Listing card (site-wide). WRITE \`components/garagem/listing-card.tsx\` \u2014 one module for home, search results, and similar listings. Do not invent a second card. From \`${STUDIO_SDK_PACKAGE}\` import ${names}. \`const model = toListingCardModel(listing)\`. href is \`model.href\` / \`listingPublicPath(listing)\` \u2014 never \`listing.id\` or \`property.id\`. Skip the card or omit the link when href is empty (no \`href=""\`, no \`href="#"\`). Must show title (\`model.title\`) and price (\`model.priceLabel\` \u2014 \u201CSob consulta\u201D when private; \`model.pricePeriod\` \u201C/m\xEAs\u201D when present, omit when null). Photo: \`model.coverSrc\` as img \`src\`, alt \`model.coverAlt\`; skip the img when cover is missing; an empty-photo block is allowed; never Unsplash, \`/placeholder.svg\`, or invented \`?query=\` images. Show when present, omit the line when missing: \`locationLabel\` (else \`propertyType\`), \`listingBusinessLabel\` / \`model.businessLabel\`, bedrooms, bathrooms, parkingSpaces, area via \`formatAreaM2\`. Never interpolate the listing object as a React child. Design is free (grid vs carousel vs mosaic; radius is site \`--radius\`). WRITE \`components/garagem/listing-card-skeleton.tsx\` only for a slot whose content is still unknown \u2014 never as a \`<Suspense>\` fallback that replaces the catalog, and never the text \u201CCarregando im\xF3veis\u2026\u201D. Do not \`if (search.loading) return\` that skeleton inside the search client.`;
3624
+ const base = `Listing card (site-wide). WRITE \`components/garagem/listing-card.tsx\` \u2014 one module for home, search results, and similar listings. Do not invent a second card. From \`${STUDIO_SDK_PACKAGE}\` import ${names}. \`const model = toListingCardModel(listing)\`. href is \`model.href\` / \`listingPublicPath(listing)\` \u2014 never \`listing.id\` or \`property.id\`. Skip the card or omit the link when href is empty (no \`href=""\`, no \`href="#"\`). Must show title (\`model.title\`) and price (\`model.priceLabel\` \u2014 \u201CSob consulta\u201D when private; \`model.pricePeriod\` \u201C/m\xEAs\u201D when present, omit when null). Photo: \`model.coverSrc\` as img \`src\`, alt \`model.coverAlt\`; skip the img when cover is missing; an empty-photo block is allowed; never Unsplash, \`/placeholder.svg\`, or invented \`?query=\` images. Show when present, omit the line when missing: \`locationLabel\` (else \`propertyType\`), \`listingBusinessLabel\` / \`model.businessLabel\`, bedrooms, bathrooms, parkingSpaces, area via \`formatAreaM2\`. Never interpolate the listing object as a React child. Design is free (grid vs carousel vs mosaic; radius is site \`--radius\`). WRITE \`components/garagem/listing-card-skeleton.tsx\` only for a slot whose content is still unknown \u2014 never as a \`<Suspense>\` fallback that replaces the catalog, and never the text \u201CCarregando im\xF3veis\u2026\u201D. Do not \`if (search.loading) return\` that skeleton inside the search client.`;
3625
+ const development = studioDevelopmentCardInstruction(pin);
3626
+ return development ? `${base}
3627
+
3628
+ ${development}` : base;
3511
3629
  }
3512
3630
  function studioListingDetailInstruction() {
3513
3631
  const names = STUDIO_SDK_CONTRACT.listingDetailExports.join(", ");
@@ -5027,6 +5145,7 @@ export {
5027
5145
  STUDIO_SITE_LAYOUT,
5028
5146
  TOOLBAR_PRIMARY_FILTER_IDS,
5029
5147
  VISIT_TIME_ZONE,
5148
+ analyticsDocumentGuardSource,
5030
5149
  applyMatchedPhotoCover,
5031
5150
  applyPathFilter,
5032
5151
  boundaryCitySlug,
@@ -5053,6 +5172,7 @@ export {
5053
5172
  createGaragemClient,
5054
5173
  createTravelTimeCache,
5055
5174
  defaultPhoneCountry,
5175
+ developmentCardPublished,
5056
5176
  displayPathLocation,
5057
5177
  expandVisitSchedule,
5058
5178
  expandVisitTimeSlots,
@@ -5080,6 +5200,7 @@ export {
5080
5200
  hrefForAppliedChange,
5081
5201
  hrefForPathFilters,
5082
5202
  hrefWithExplicitPage,
5203
+ isAnalyticsDocumentUrl,
5083
5204
  isAnalyticsOnPin,
5084
5205
  isListingDetailPath,
5085
5206
  isMapBounds,
@@ -5167,6 +5288,7 @@ export {
5167
5288
  studioChromeInstruction,
5168
5289
  studioCodegenContractViolations,
5169
5290
  studioDefaultLeadUi,
5291
+ studioDevelopmentCardInstruction,
5170
5292
  studioLayoutInstruction,
5171
5293
  studioLeadInstruction,
5172
5294
  studioListingCardInstruction,