@garagem-ai/site-sdk 0.4.10 → 0.4.11

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,261 @@ 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
+ return {
2292
+ breadcrumb: listingBreadcrumb(listing),
2293
+ values: listingValues(listing),
2294
+ facts: listingFacts(listing),
2295
+ location: listingLocationBlock(listing),
2296
+ description: listingDescriptionPreview(
2297
+ listing.description,
2298
+ options?.descriptionExpanded === true
2299
+ ),
2300
+ mediaOverlays: listingMediaOverlays(listing)
2301
+ };
2302
+ }
2303
+
2039
2304
  // src/studio-contract.ts
2040
2305
  var STUDIO_SDK_PACKAGE = "@garagem-ai/site-sdk";
2041
2306
  var STUDIO_SDK_CONTRACT = {
@@ -2043,8 +2308,9 @@ var STUDIO_SDK_CONTRACT = {
2043
2308
  /**
2044
2309
  * Exact pin for generated Studio sites. Must be ≥ `selfInjectSince` so
2045
2310
  * 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.
2311
+ * 0.4.9 adds listingDetailModel (values, facts, location, breadcrumb,
2312
+ * description clamp, video/tour), getSimilarListings, and
2313
+ * listingAmenityGroups so listing detail never prints amenity ids.
2048
2314
  */
2049
2315
  minNpmVersion: "0.4.9",
2050
2316
  /** First release where ListingCard and ResultsSkeleton inject the sheet. */
@@ -2079,6 +2345,7 @@ var STUDIO_SDK_CONTRACT = {
2079
2345
  "isVisitSlotAllowed",
2080
2346
  "STUDIO_DEFAULT_VISIT_SCHEDULE"
2081
2347
  ],
2348
+ listingDetailExports: ["listingDetailModel", "getSimilarListings"],
2082
2349
  amenityExports: ["listingAmenityGroups"]
2083
2350
  };
2084
2351
  var STUDIO_SITE_LAYOUT = {
@@ -2173,6 +2440,10 @@ function studioLeadInstruction() {
2173
2440
  const names = STUDIO_SDK_CONTRACT.leadExports.join(", ");
2174
2441
  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
2442
  }
2443
+ function studioListingDetailInstruction() {
2444
+ const names = STUDIO_SDK_CONTRACT.listingDetailExports.join(", ");
2445
+ 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 with the helper clamp + toggle (keep the full text; do not drop the remainder). 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.`;
2446
+ }
2176
2447
  function studioAmenityInstruction() {
2177
2448
  const names = STUDIO_SDK_CONTRACT.amenityExports.join(", ");
2178
2449
  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 +2637,7 @@ function createGaragemClient(options = {}) {
2366
2637
  FORBIDDEN_SEARCH_QUERY_KEYS,
2367
2638
  GaragemSdkError,
2368
2639
  LISTING_AMENITY_TITLES,
2640
+ LISTING_DESCRIPTION_CLAMP,
2369
2641
  LeadSubmitError,
2370
2642
  SEARCH_CSS_RECIPE,
2371
2643
  SEARCH_CSS_VARS,
@@ -2412,10 +2684,18 @@ function createGaragemClient(options = {}) {
2412
2684
  isVisitSlotAllowed,
2413
2685
  labelAmenities,
2414
2686
  listingAmenityGroups,
2687
+ listingBreadcrumb,
2415
2688
  listingBusinessLabel,
2689
+ listingDescriptionPreview,
2690
+ listingDetailModel,
2691
+ listingFacts,
2692
+ listingLocationBlock,
2416
2693
  listingLocationLabel,
2417
2694
  listingLookupKey,
2695
+ listingMapsHref,
2696
+ listingMediaOverlays,
2418
2697
  listingPublicPath,
2698
+ listingValues,
2419
2699
  mergeAppliedSearchQueryIntoSearch,
2420
2700
  normalizeVisitDate,
2421
2701
  normalizeVisitTime,
@@ -2445,6 +2725,7 @@ function createGaragemClient(options = {}) {
2445
2725
  studioDefaultLeadUi,
2446
2726
  studioLayoutInstruction,
2447
2727
  studioLeadInstruction,
2728
+ studioListingDetailInstruction,
2448
2729
  studioSdkPinInstruction,
2449
2730
  studioSearchLandmarkInstruction,
2450
2731
  studioSiteWidthCss,