@garagem-ai/site-sdk 0.4.10 → 0.4.12

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.js CHANGED
@@ -24,6 +24,7 @@ __export(src_exports, {
24
24
  FORBIDDEN_SEARCH_QUERY_KEYS: () => FORBIDDEN_SEARCH_QUERY_KEYS,
25
25
  GaragemSdkError: () => GaragemSdkError,
26
26
  LISTING_AMENITY_TITLES: () => LISTING_AMENITY_TITLES,
27
+ LISTING_DESCRIPTION_CLAMP: () => LISTING_DESCRIPTION_CLAMP,
27
28
  LeadSubmitError: () => LeadSubmitError,
28
29
  SEARCH_CSS_RECIPE: () => SEARCH_CSS_RECIPE,
29
30
  SEARCH_CSS_VARS: () => SEARCH_CSS_VARS,
@@ -70,10 +71,18 @@ __export(src_exports, {
70
71
  isVisitSlotAllowed: () => isVisitSlotAllowed,
71
72
  labelAmenities: () => labelAmenities,
72
73
  listingAmenityGroups: () => listingAmenityGroups,
74
+ listingBreadcrumb: () => listingBreadcrumb,
73
75
  listingBusinessLabel: () => listingBusinessLabel,
76
+ listingDescriptionPreview: () => listingDescriptionPreview,
77
+ listingDetailModel: () => listingDetailModel,
78
+ listingFacts: () => listingFacts,
79
+ listingLocationBlock: () => listingLocationBlock,
74
80
  listingLocationLabel: () => listingLocationLabel,
75
81
  listingLookupKey: () => listingLookupKey,
82
+ listingMapsHref: () => listingMapsHref,
83
+ listingMediaOverlays: () => listingMediaOverlays,
76
84
  listingPublicPath: () => listingPublicPath,
85
+ listingValues: () => listingValues,
77
86
  mergeAppliedSearchQueryIntoSearch: () => mergeAppliedSearchQueryIntoSearch2,
78
87
  normalizeVisitDate: () => normalizeVisitDate,
79
88
  normalizeVisitTime: () => normalizeVisitTime,
@@ -103,6 +112,7 @@ __export(src_exports, {
103
112
  studioDefaultLeadUi: () => studioDefaultLeadUi,
104
113
  studioLayoutInstruction: () => studioLayoutInstruction,
105
114
  studioLeadInstruction: () => studioLeadInstruction,
115
+ studioListingDetailInstruction: () => studioListingDetailInstruction,
106
116
  studioSdkPinInstruction: () => studioSdkPinInstruction,
107
117
  studioSearchLandmarkInstruction: () => studioSearchLandmarkInstruction,
108
118
  studioSiteWidthCss: () => studioSiteWidthCss,
@@ -2036,6 +2046,265 @@ function paginationPages(currentPage, totalPages, padding) {
2036
2046
  return pages;
2037
2047
  }
2038
2048
 
2049
+ // src/listing-detail.ts
2050
+ var LISTING_DESCRIPTION_CLAMP = 280;
2051
+ var VIDEO_HOST_HINTS = [
2052
+ "youtube.com",
2053
+ "youtu.be",
2054
+ "vimeo.com",
2055
+ "wistia.com",
2056
+ "wistia.net"
2057
+ ];
2058
+ var BREADCRUMB_LABELS = {
2059
+ imoveis: "Im\xF3veis",
2060
+ venda: "Venda",
2061
+ aluguel: "Aluguel",
2062
+ rental: "Aluguel",
2063
+ sale: "Venda"
2064
+ };
2065
+ function finiteNumber(value) {
2066
+ if (typeof value === "number" && Number.isFinite(value)) return value;
2067
+ if (typeof value === "string" && value.trim() !== "") {
2068
+ const parsed = Number(value);
2069
+ if (Number.isFinite(parsed)) return parsed;
2070
+ }
2071
+ return null;
2072
+ }
2073
+ function positiveCount(value) {
2074
+ const amount = finiteNumber(value);
2075
+ return amount != null && amount > 0 ? amount : null;
2076
+ }
2077
+ function formatFloorFact(value) {
2078
+ if (typeof value === "number" && Number.isFinite(value)) {
2079
+ return value === 0 ? "T\xE9rreo" : String(value);
2080
+ }
2081
+ if (typeof value !== "string") return null;
2082
+ const trimmed = value.trim();
2083
+ if (!trimmed) return null;
2084
+ const parsed = Number(trimmed);
2085
+ if (Number.isFinite(parsed) && trimmed === String(parsed)) {
2086
+ return parsed === 0 ? "T\xE9rreo" : trimmed;
2087
+ }
2088
+ return trimmed;
2089
+ }
2090
+ function httpsUrl(raw) {
2091
+ if (!raw) return null;
2092
+ try {
2093
+ const url = new URL(raw);
2094
+ if (url.protocol !== "https:") return null;
2095
+ return url.toString();
2096
+ } catch {
2097
+ return null;
2098
+ }
2099
+ }
2100
+ function isVideoPlatformUrl(url) {
2101
+ const host = new URL(url).hostname.toLowerCase();
2102
+ return VIDEO_HOST_HINTS.some(
2103
+ (hint) => host === hint || host.endsWith(`.${hint}`)
2104
+ );
2105
+ }
2106
+ function overlayKind(type, src) {
2107
+ if (type === "image" || type === "photo") return null;
2108
+ const host = new URL(src).hostname.toLowerCase();
2109
+ if (type === "tour" || type === "virtual_tour" || host.includes("matterport")) {
2110
+ return "tour";
2111
+ }
2112
+ if (isVideoPlatformUrl(src) || type === "video") return "video";
2113
+ return type ? "tour" : null;
2114
+ }
2115
+ var VIMEO_ID_RE = /vimeo\.com\/(?:video\/|channels\/[^/]+\/|groups\/[^/]+\/videos\/)?(\d+)/i;
2116
+ var WISTIA_ID_RE = /\/(?:medias|embed\/(?:iframe|medias))\/([a-zA-Z0-9]+)/i;
2117
+ function vimeoPrivacyHash(url, id) {
2118
+ const fromQuery = url.searchParams.get("h");
2119
+ if (fromQuery) return fromQuery;
2120
+ const segments = url.pathname.split("/").filter(Boolean);
2121
+ const idIndex = segments.indexOf(id);
2122
+ const next = idIndex >= 0 ? segments[idIndex + 1] : void 0;
2123
+ return next && /^[a-f0-9]{6,12}$/i.test(next) ? next : null;
2124
+ }
2125
+ function embedSrc(src) {
2126
+ const url = new URL(src);
2127
+ const host = url.hostname.toLowerCase();
2128
+ if (host === "youtu.be" || host.endsWith(".youtu.be")) {
2129
+ const id = url.pathname.replace(/^\//, "").split("/")[0];
2130
+ return id ? `https://www.youtube.com/embed/${id}` : src;
2131
+ }
2132
+ if (host.includes("youtube.com")) {
2133
+ const id = url.searchParams.get("v") || url.pathname.split("/").pop();
2134
+ return id ? `https://www.youtube.com/embed/${id}` : src;
2135
+ }
2136
+ if (host.includes("player.vimeo.com")) return src;
2137
+ if (host.includes("vimeo.com")) {
2138
+ const id = src.match(VIMEO_ID_RE)?.[1];
2139
+ if (!id) return src;
2140
+ const hash = vimeoPrivacyHash(url, id);
2141
+ return hash ? `https://player.vimeo.com/video/${id}?h=${encodeURIComponent(hash)}` : `https://player.vimeo.com/video/${id}`;
2142
+ }
2143
+ if (host.includes("wistia.com") || host.includes("wistia.net")) {
2144
+ if (src.includes("/embed/iframe/")) return src;
2145
+ const id = src.match(WISTIA_ID_RE)?.[1];
2146
+ return id ? `https://fast.wistia.net/embed/iframe/${id}` : src;
2147
+ }
2148
+ return src;
2149
+ }
2150
+ function crumbLabel(segment) {
2151
+ const mapped = BREADCRUMB_LABELS[segment];
2152
+ if (mapped) return mapped;
2153
+ if (/^[a-z]{2}$/.test(segment)) return segment.toUpperCase();
2154
+ return segment.split("-").filter(Boolean).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(" ");
2155
+ }
2156
+ function listingValues(listing) {
2157
+ const values = [
2158
+ {
2159
+ key: "price",
2160
+ label: "Pre\xE7o",
2161
+ text: listing.priceVisibility === "private" ? "Sob consulta" : formatListingPrice(listing.price)
2162
+ }
2163
+ ];
2164
+ const condoFee = positiveCount(listing.property?.condoFee);
2165
+ if (condoFee != null) {
2166
+ values.push({
2167
+ key: "condoFee",
2168
+ label: "Condom\xEDnio",
2169
+ text: formatListingPrice(condoFee)
2170
+ });
2171
+ }
2172
+ const propertyTax = positiveCount(listing.property?.propertyTax);
2173
+ if (propertyTax != null) {
2174
+ values.push({
2175
+ key: "propertyTax",
2176
+ label: "IPTU",
2177
+ text: formatListingPrice(propertyTax)
2178
+ });
2179
+ }
2180
+ return values;
2181
+ }
2182
+ function listingFacts(listing) {
2183
+ const property = listing.property ?? {};
2184
+ const facts = [];
2185
+ const area = formatAreaM2(
2186
+ positiveCount(property.usableArea) ?? positiveCount(property.totalArea)
2187
+ );
2188
+ if (area) facts.push({ key: "area", label: "\xC1rea", text: area });
2189
+ const bedrooms = positiveCount(property.bedrooms);
2190
+ if (bedrooms != null) {
2191
+ facts.push({
2192
+ key: "bedrooms",
2193
+ label: "Dormit\xF3rios",
2194
+ text: String(bedrooms)
2195
+ });
2196
+ }
2197
+ const suites = positiveCount(property.suites);
2198
+ if (suites != null) {
2199
+ facts.push({ key: "suites", label: "Su\xEDtes", text: String(suites) });
2200
+ }
2201
+ const parking = positiveCount(property.parkingSpaces);
2202
+ if (parking != null) {
2203
+ facts.push({ key: "parkingSpaces", label: "Vagas", text: String(parking) });
2204
+ }
2205
+ const rooms = positiveCount(property.rooms);
2206
+ if (rooms != null) {
2207
+ facts.push({ key: "rooms", label: "Salas", text: String(rooms) });
2208
+ }
2209
+ const floorText = formatFloorFact(property.floor);
2210
+ if (floorText) {
2211
+ facts.push({ key: "floor", label: "Andar", text: floorText });
2212
+ }
2213
+ return facts;
2214
+ }
2215
+ function listingMapsHref(location) {
2216
+ if (!location) return null;
2217
+ const lat = finiteNumber(location.coordinates?.lat);
2218
+ const lng = finiteNumber(location.coordinates?.lng);
2219
+ if (lat != null && lng != null && !(lat === 0 && lng === 0)) {
2220
+ return `https://www.google.com/maps/search/?api=1&query=${lat},${lng}`;
2221
+ }
2222
+ const query = [
2223
+ [location.street, location.number].filter(Boolean).join(" ").trim(),
2224
+ location.neighborhood,
2225
+ location.city,
2226
+ location.state
2227
+ ].map((part) => part ? String(part).trim() : "").filter(Boolean).join(", ");
2228
+ if (!query) return null;
2229
+ return `https://www.google.com/maps/search/?api=1&query=${encodeURIComponent(query)}`;
2230
+ }
2231
+ function listingLocationBlock(listing) {
2232
+ const location = listing?.location;
2233
+ if (!location) return null;
2234
+ const street = [location.street, location.number].filter(Boolean).join(" ").trim();
2235
+ const label = street || listingLocationLabel(location);
2236
+ const mapsHref = listingMapsHref(location);
2237
+ if (!label && !mapsHref) return null;
2238
+ return { label, mapsHref };
2239
+ }
2240
+ function listingBreadcrumb(listing) {
2241
+ const path = listingPublicPath(listing);
2242
+ const segments = path.split("/").filter(Boolean);
2243
+ if (segments[0] !== "imoveis") return [];
2244
+ const crumbs = [
2245
+ { label: "Im\xF3veis", href: "/imoveis" }
2246
+ ];
2247
+ let href = "/imoveis";
2248
+ for (const segment of segments.slice(1)) {
2249
+ if (segment.startsWith("id-")) break;
2250
+ href = `${href}/${segment}`;
2251
+ if (isListingDetailPath(href)) continue;
2252
+ crumbs.push({ label: crumbLabel(segment), href });
2253
+ }
2254
+ return crumbs;
2255
+ }
2256
+ function listingDescriptionPreview(description, expanded = false) {
2257
+ const text = description?.trim() ?? "";
2258
+ if (!text) return null;
2259
+ if (text.length <= LISTING_DESCRIPTION_CLAMP) {
2260
+ return { text, truncated: false, toggleLabel: null };
2261
+ }
2262
+ if (expanded) {
2263
+ return { text, truncated: true, toggleLabel: "Ler menos" };
2264
+ }
2265
+ return {
2266
+ text: `${text.slice(0, LISTING_DESCRIPTION_CLAMP).trimEnd()}\u2026`,
2267
+ truncated: true,
2268
+ toggleLabel: "Ler mais"
2269
+ };
2270
+ }
2271
+ function listingMediaOverlays(listing) {
2272
+ const overlays = [];
2273
+ const seen = /* @__PURE__ */ new Set();
2274
+ for (const item of listing.media ?? []) {
2275
+ const src = httpsUrl(item.src);
2276
+ if (!src) continue;
2277
+ const kind = overlayKind(item.type, src);
2278
+ if (!kind || seen.has(kind)) continue;
2279
+ seen.add(kind);
2280
+ overlays.push({
2281
+ key: kind,
2282
+ hash: kind,
2283
+ title: kind === "video" ? "V\xEDdeo" : "Tour virtual",
2284
+ href: `#${kind}`,
2285
+ embedSrc: embedSrc(src)
2286
+ });
2287
+ }
2288
+ return overlays;
2289
+ }
2290
+ function listingDetailModel(listing, options) {
2291
+ const descriptionPreview = listingDescriptionPreview(
2292
+ listing.description,
2293
+ options?.descriptionExpanded === true
2294
+ );
2295
+ return {
2296
+ breadcrumb: listingBreadcrumb(listing),
2297
+ values: listingValues(listing),
2298
+ facts: listingFacts(listing),
2299
+ location: listingLocationBlock(listing),
2300
+ /** Clamped (or full) copy — a string so JSX `{model.description}` is safe. */
2301
+ description: descriptionPreview?.text ?? null,
2302
+ descriptionTruncated: descriptionPreview?.truncated === true,
2303
+ descriptionToggleLabel: descriptionPreview?.toggleLabel ?? null,
2304
+ mediaOverlays: listingMediaOverlays(listing)
2305
+ };
2306
+ }
2307
+
2039
2308
  // src/studio-contract.ts
2040
2309
  var STUDIO_SDK_PACKAGE = "@garagem-ai/site-sdk";
2041
2310
  var STUDIO_SDK_CONTRACT = {
@@ -2043,10 +2312,10 @@ var STUDIO_SDK_CONTRACT = {
2043
2312
  /**
2044
2313
  * Exact pin for generated Studio sites. Must be ≥ `selfInjectSince` so
2045
2314
  * prompts that skip the layout chrome tag match the tarball v0 installs.
2046
- * 0.4.9 adds `listingAmenityGroups` so listing detail never prints
2047
- * amenity ids.
2315
+ * 0.4.12 flattens listingDetailModel.description to a string (plus
2316
+ * descriptionToggleLabel) so JSX cannot render the clamp object.
2048
2317
  */
2049
- minNpmVersion: "0.4.9",
2318
+ minNpmVersion: "0.4.12",
2050
2319
  /** First release where ListingCard and ResultsSkeleton inject the sheet. */
2051
2320
  selfInjectSince: "0.4.2",
2052
2321
  chromeStrategy: "self-inject",
@@ -2079,6 +2348,7 @@ var STUDIO_SDK_CONTRACT = {
2079
2348
  "isVisitSlotAllowed",
2080
2349
  "STUDIO_DEFAULT_VISIT_SCHEDULE"
2081
2350
  ],
2351
+ listingDetailExports: ["listingDetailModel", "getSimilarListings"],
2082
2352
  amenityExports: ["listingAmenityGroups"]
2083
2353
  };
2084
2354
  var STUDIO_SITE_LAYOUT = {
@@ -2173,6 +2443,10 @@ function studioLeadInstruction() {
2173
2443
  const names = STUDIO_SDK_CONTRACT.leadExports.join(", ");
2174
2444
  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.`;
2175
2445
  }
2446
+ function studioListingDetailInstruction() {
2447
+ const names = STUDIO_SDK_CONTRACT.listingDetailExports.join(", ");
2448
+ return `Listing detail blocks: import ${names} from \`${STUDIO_SDK_PACKAGE}\` and \`ListingCard\` from \`${STUDIO_SDK_PACKAGE}/react\`. Render \`listingDetailModel(listing)\` for breadcrumb (hrefs are search prefixes of \`listing.path\`, never invented paths), values (price / sob consulta, condo, IPTU), facts (omit empty zeros; bedrooms \u2260 salas), location plus a discreet Google Maps \`<a target="_blank" rel="noopener noreferrer">\`, and description as the string \`model.description\` plus \`model.descriptionToggleLabel\` (keep the full text; do not drop the remainder). Map facts/values/breadcrumb items to \`.label\` / \`.text\` / \`.href\`; use \`model.location.label\` and \`model.location.mapsHref\`. Never interpolate \`model.location\`, \`model.facts\`, \`model.values\`, \`model.breadcrumb\`, \`model.mediaOverlays\`, or amenity groups as a React child. Video/tour: \`model.mediaOverlays\` as hash links (\`#video\` / \`#tour\`) and a fullscreen overlay that closes with browser back; omit when empty. Similar listings: \`getSimilarListings({ siteId, listingId, baseUrl })\` + \`ListingCard\`; hide the section when the list is empty. Do not invent a local recommendation loop.`;
2449
+ }
2176
2450
  function studioAmenityInstruction() {
2177
2451
  const names = STUDIO_SDK_CONTRACT.amenityExports.join(", ");
2178
2452
  return `Listing amenities: import ${names} from \`${STUDIO_SDK_PACKAGE}\`. Render \`listingAmenityGroups(listing)\` (optional second arg: \`getSearchUi().dictionary\`). Use the helper titles (\`Comodidades\` / \`Comodidades do condom\xEDnio\`). Labels are already alphabetical (pt-BR) \u2014 keep that order. Omit empty groups. Never print amenity ids, never invent a local label map, and never title a section "Comodidades da unidade".`;
@@ -2366,6 +2640,7 @@ function createGaragemClient(options = {}) {
2366
2640
  FORBIDDEN_SEARCH_QUERY_KEYS,
2367
2641
  GaragemSdkError,
2368
2642
  LISTING_AMENITY_TITLES,
2643
+ LISTING_DESCRIPTION_CLAMP,
2369
2644
  LeadSubmitError,
2370
2645
  SEARCH_CSS_RECIPE,
2371
2646
  SEARCH_CSS_VARS,
@@ -2412,10 +2687,18 @@ function createGaragemClient(options = {}) {
2412
2687
  isVisitSlotAllowed,
2413
2688
  labelAmenities,
2414
2689
  listingAmenityGroups,
2690
+ listingBreadcrumb,
2415
2691
  listingBusinessLabel,
2692
+ listingDescriptionPreview,
2693
+ listingDetailModel,
2694
+ listingFacts,
2695
+ listingLocationBlock,
2416
2696
  listingLocationLabel,
2417
2697
  listingLookupKey,
2698
+ listingMapsHref,
2699
+ listingMediaOverlays,
2418
2700
  listingPublicPath,
2701
+ listingValues,
2419
2702
  mergeAppliedSearchQueryIntoSearch,
2420
2703
  normalizeVisitDate,
2421
2704
  normalizeVisitTime,
@@ -2445,6 +2728,7 @@ function createGaragemClient(options = {}) {
2445
2728
  studioDefaultLeadUi,
2446
2729
  studioLayoutInstruction,
2447
2730
  studioLeadInstruction,
2731
+ studioListingDetailInstruction,
2448
2732
  studioSdkPinInstruction,
2449
2733
  studioSearchLandmarkInstruction,
2450
2734
  studioSiteWidthCss,