@garagem-ai/site-sdk 0.9.1 → 0.10.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.js CHANGED
@@ -42,6 +42,10 @@ __export(src_exports, {
42
42
  PHOTO_SEARCH_MIN_QUERY_LENGTH: () => PHOTO_SEARCH_MIN_QUERY_LENGTH,
43
43
  SEARCH_EMPTY_COPY: () => SEARCH_EMPTY_COPY,
44
44
  SEARCH_SORT_RELEVANCE: () => SEARCH_SORT_RELEVANCE,
45
+ SELLER_LEAD_PHOTO_MAX_BYTES: () => SELLER_LEAD_PHOTO_MAX_BYTES,
46
+ SELLER_LEAD_PHOTO_MAX_COUNT: () => SELLER_LEAD_PHOTO_MAX_COUNT,
47
+ SELLER_LEAD_PHOTO_TYPES: () => SELLER_LEAD_PHOTO_TYPES,
48
+ STUDIO_DEFAULT_PHOTO_SCHEDULE_CONFIG: () => STUDIO_DEFAULT_PHOTO_SCHEDULE_CONFIG,
45
49
  STUDIO_DEFAULT_VISIT_SCHEDULE: () => STUDIO_DEFAULT_VISIT_SCHEDULE,
46
50
  STUDIO_SDK_CONTRACT: () => STUDIO_SDK_CONTRACT,
47
51
  STUDIO_SDK_PACKAGE: () => STUDIO_SDK_PACKAGE,
@@ -103,7 +107,10 @@ __export(src_exports, {
103
107
  isMapBounds: () => isMapBounds,
104
108
  isMapPolygon: () => isMapPolygon,
105
109
  isPhotoSearchOnPin: () => isPhotoSearchOnPin,
110
+ isSellerLeadOnPin: () => isSellerLeadOnPin,
106
111
  isStudioPreviewHost: () => isStudioPreviewHost,
112
+ isValidEmail: () => isValidEmail,
113
+ isValidName: () => isValidName,
107
114
  isValidPhone: () => isValidPhone,
108
115
  isVisitSlotAllowed: () => isVisitSlotAllowed,
109
116
  labelAmenities: () => labelAmenities,
@@ -173,6 +180,8 @@ __export(src_exports, {
173
180
  searchListingsInPolygon: () => searchListingsInPolygon,
174
181
  searchResultsHeading: () => searchResultsHeading,
175
182
  searchSortOptions: () => searchSortOptions,
183
+ sellerAddressErrors: () => sellerAddressErrors,
184
+ sellerPhotoSchedule: () => sellerPhotoSchedule,
176
185
  serializeAppliedSearchQuery: () => serializeAppliedSearchQuery2,
177
186
  slotsForDate: () => slotsForDate,
178
187
  studioAmenityInstruction: () => studioAmenityInstruction,
@@ -193,8 +202,10 @@ __export(src_exports, {
193
202
  studioSdkPinInstruction: () => studioSdkPinInstruction,
194
203
  studioSearchInstruction: () => studioSearchInstruction,
195
204
  studioSearchLandmarkInstruction: () => studioSearchLandmarkInstruction,
205
+ studioSellerLeadSdkInstruction: () => studioSellerLeadSdkInstruction,
196
206
  studioSiteWidthCss: () => studioSiteWidthCss,
197
207
  submitContactLead: () => submitContactLead,
208
+ submitSellerLead: () => submitSellerLead,
198
209
  submitVisitLead: () => submitVisitLead,
199
210
  toE164: () => toE164,
200
211
  toListingCardModel: () => toListingCardModel,
@@ -204,6 +215,7 @@ __export(src_exports, {
204
215
  travelTimesFromListing: () => travelTimesFromListing,
205
216
  truncateNationalPhoneDigits: () => truncateNationalPhoneDigits,
206
217
  unavailableReactImports: () => unavailableReactImports,
218
+ uploadSellerLeadPhoto: () => uploadSellerLeadPhoto,
207
219
  visibleSearchFilters: () => visibleSearchFilters
208
220
  });
209
221
  module.exports = __toCommonJS(src_exports);
@@ -268,13 +280,13 @@ function finiteNonNegative(value) {
268
280
  }
269
281
  return null;
270
282
  }
271
- function parseSdkErrorBody(text) {
272
- const raw = text ? text.slice(0, 200) : "";
273
- if (!text) {
283
+ function parseSdkErrorBody(text2) {
284
+ const raw = text2 ? text2.slice(0, 200) : "";
285
+ if (!text2) {
274
286
  return { reason: null, retryAfterSeconds: null, summary: "" };
275
287
  }
276
288
  try {
277
- const body = JSON.parse(text);
289
+ const body = JSON.parse(text2);
278
290
  if (!body || typeof body !== "object") {
279
291
  return { reason: null, retryAfterSeconds: null, summary: raw };
280
292
  }
@@ -370,8 +382,8 @@ var GaragemSdkError = class extends Error {
370
382
  }
371
383
  };
372
384
  async function readGaragemSdkError(response, url) {
373
- const text = await response.text().catch(() => "");
374
- const parsed = parseSdkErrorBody(text);
385
+ const text2 = await response.text().catch(() => "");
386
+ const parsed = parseSdkErrorBody(text2);
375
387
  const retryAfter = response.status === 429 ? retryAfterFromResponse(response, parsed.retryAfterSeconds) : parsed.retryAfterSeconds;
376
388
  const detail = parsed.summary;
377
389
  return new GaragemSdkError(
@@ -1224,7 +1236,15 @@ var LeadSubmitError = class extends Error {
1224
1236
  };
1225
1237
  var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
1226
1238
  var EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
1239
+ var NAME_RE = /^[^\d\s]{2,}.*$/;
1227
1240
  var MESSAGE_MAX = 2e3;
1241
+ function isValidEmail(value) {
1242
+ return EMAIL_RE.test(value.trim());
1243
+ }
1244
+ function isValidName(value) {
1245
+ const name = value.trim();
1246
+ return name.length <= 200 && NAME_RE.test(name);
1247
+ }
1228
1248
  var CONTACT_FIELDS = [
1229
1249
  { id: "name", required: true },
1230
1250
  { id: "email", required: false },
@@ -1324,6 +1344,27 @@ function normalizeSdkBusinessType(value) {
1324
1344
  if (normalized === "sale" || normalized === "venda") return "sale";
1325
1345
  return void 0;
1326
1346
  }
1347
+ var ADDRESS_REJECTIONS = /* @__PURE__ */ new Set([
1348
+ "missing_postal_code",
1349
+ "ungeocoded_address"
1350
+ ]);
1351
+ async function rejectedLeadError(response) {
1352
+ if (response.status !== 400 && response.status !== 409) return null;
1353
+ const parsed = parseSdkErrorBody(await response.text().catch(() => ""));
1354
+ if (response.status === 409 || parsed.reason === "duplicate_property") {
1355
+ return new LeadSubmitError(
1356
+ parsed.summary || "Garagem SDK: property already registered.",
1357
+ { code: "duplicate_property", status: response.status }
1358
+ );
1359
+ }
1360
+ if (parsed.reason && ADDRESS_REJECTIONS.has(parsed.reason)) {
1361
+ return new LeadSubmitError(`Garagem SDK: ${parsed.reason}.`, {
1362
+ code: "invalid_address",
1363
+ status: 400
1364
+ });
1365
+ }
1366
+ return null;
1367
+ }
1327
1368
  async function postSiteLead(input) {
1328
1369
  const siteId = await resolveLeadSiteId(input);
1329
1370
  const base = normalizeBaseUrl(input.baseUrl);
@@ -1358,8 +1399,8 @@ async function postSiteLead(input) {
1358
1399
  });
1359
1400
  }
1360
1401
  if (response.status === 429) {
1361
- const text = await response.text().catch(() => "");
1362
- const parsed = parseSdkErrorBody(text);
1402
+ const text2 = await response.text().catch(() => "");
1403
+ const parsed = parseSdkErrorBody(text2);
1363
1404
  const retryAfter = retryAfterFromResponse(
1364
1405
  response,
1365
1406
  parsed.retryAfterSeconds
@@ -1376,6 +1417,8 @@ async function postSiteLead(input) {
1376
1417
  status: 404
1377
1418
  });
1378
1419
  }
1420
+ const rejected = await rejectedLeadError(response);
1421
+ if (rejected) throw rejected;
1379
1422
  throw new LeadSubmitError(
1380
1423
  `Garagem SDK: lead submit failed (${response.status}).`,
1381
1424
  { code: "http", status: response.status }
@@ -1442,6 +1485,278 @@ async function submitContactLead(input) {
1442
1485
  });
1443
1486
  }
1444
1487
 
1488
+ // src/seller-lead.ts
1489
+ function text(value) {
1490
+ return typeof value === "string" ? value.trim() : "";
1491
+ }
1492
+ function inRange(value, min, max) {
1493
+ return typeof value === "number" && Number.isFinite(value) && value >= min && value <= max;
1494
+ }
1495
+ function sellerAddressErrors(address) {
1496
+ const errors = {};
1497
+ if (!address || !text(address.fullAddress)) {
1498
+ errors.fullAddress = "Informe o endere\xE7o do im\xF3vel.";
1499
+ } else if (!inRange(address.latitude, -90, 90) || !inRange(address.longitude, -180, 180) || !text(address.street) || !text(address.city) || !text(address.neighborhood) || !/^[A-Za-z]{2}$/.test(text(address.state))) {
1500
+ errors.fullAddress = "Selecione o endere\xE7o em uma das sugest\xF5es.";
1501
+ }
1502
+ if (!address?.noNumber && !text(address?.number)) {
1503
+ errors.number = "Informe o n\xFAmero ou marque sem n\xFAmero.";
1504
+ }
1505
+ if (!address?.noBlocoTorre && !text(address?.blocoTorre)) {
1506
+ errors.blocoTorre = "Informe o bloco/torre ou marque que n\xE3o tem.";
1507
+ }
1508
+ if (!address?.noUnidade && !text(address?.unidade)) {
1509
+ errors.unidade = "Informe a unidade ou marque que n\xE3o tem.";
1510
+ }
1511
+ if (text(address?.postalCode).replace(/\D/g, "").length !== 8) {
1512
+ errors.postalCode = "Informe um CEP com 8 d\xEDgitos.";
1513
+ }
1514
+ return errors;
1515
+ }
1516
+ var SELLER_LEAD_PHOTO_MAX_BYTES = 10 * 1024 * 1024;
1517
+ var SELLER_LEAD_PHOTO_MAX_COUNT = 30;
1518
+ var SELLER_LEAD_PHOTO_TYPES = [
1519
+ "image/jpeg",
1520
+ "image/png",
1521
+ "image/webp"
1522
+ ];
1523
+ async function uploadSellerLeadPhoto(input) {
1524
+ const { file } = input;
1525
+ if (!SELLER_LEAD_PHOTO_TYPES.includes(file.type)) {
1526
+ throw new LeadSubmitError("Garagem SDK: photo must be JPG, PNG or WEBP.", {
1527
+ code: "invalid_photo"
1528
+ });
1529
+ }
1530
+ if (file.size <= 0) {
1531
+ throw new LeadSubmitError("Garagem SDK: photo is empty.", {
1532
+ code: "invalid_photo"
1533
+ });
1534
+ }
1535
+ if (file.size > SELLER_LEAD_PHOTO_MAX_BYTES) {
1536
+ throw new LeadSubmitError("Garagem SDK: photo is larger than 10MB.", {
1537
+ code: "invalid_photo"
1538
+ });
1539
+ }
1540
+ const siteId = await resolveLeadSiteId(input);
1541
+ const url = `${normalizeBaseUrl(input.baseUrl)}/api/webhooks/sites/${encodeURIComponent(siteId)}/photos`;
1542
+ const form = new FormData();
1543
+ form.append("file", file);
1544
+ if (file.name) form.append("fileName", file.name);
1545
+ let response;
1546
+ try {
1547
+ response = await (input.fetch ?? fetch)(url, {
1548
+ method: "POST",
1549
+ body: form
1550
+ });
1551
+ } catch (error) {
1552
+ throw new LeadSubmitError(
1553
+ error instanceof Error ? error.message : "Garagem SDK: network error.",
1554
+ { code: "network" }
1555
+ );
1556
+ }
1557
+ if (response.status === 404) {
1558
+ throw new LeadSubmitError("Garagem SDK: site not found.", {
1559
+ code: "not_found",
1560
+ status: 404
1561
+ });
1562
+ }
1563
+ const data = await response.json().catch(() => ({}));
1564
+ if (!response.ok || typeof data.url !== "string" || !data.url) {
1565
+ throw new LeadSubmitError(
1566
+ `Garagem SDK: photo upload failed (${response.status}).`,
1567
+ {
1568
+ code: response.status === 400 ? "invalid_photo" : "http",
1569
+ status: response.status
1570
+ }
1571
+ );
1572
+ }
1573
+ return data.url;
1574
+ }
1575
+ var STUDIO_DEFAULT_PHOTO_SCHEDULE_CONFIG = {
1576
+ disabledDays: [0, 6],
1577
+ weekdayTimeSlots: [
1578
+ "09:00",
1579
+ "10:00",
1580
+ "11:00",
1581
+ "14:00",
1582
+ "15:00",
1583
+ "16:00",
1584
+ "17:00"
1585
+ ],
1586
+ weekendTimeSlots: ["10:00", "11:00", "14:00", "15:00", "16:00"]
1587
+ };
1588
+ function sellerPhotoSchedule(config = STUDIO_DEFAULT_PHOTO_SCHEDULE_CONFIG) {
1589
+ const weekdayTimeSlots = [...config.weekdayTimeSlots].sort();
1590
+ const weekendTimeSlots = [...config.weekendTimeSlots].sort();
1591
+ const hours = (slots) => slots.length > 0 ? { start: slots[0], end: slots[slots.length - 1] } : null;
1592
+ return {
1593
+ timeZone: VISIT_TIME_ZONE,
1594
+ saturday: !config.disabledDays.includes(6),
1595
+ sunday: !config.disabledDays.includes(0),
1596
+ weekday: hours(weekdayTimeSlots) ?? { start: "09:00", end: "09:00" },
1597
+ weekend: hours(weekendTimeSlots),
1598
+ minHoursAhead: 2,
1599
+ disabledDays: [...config.disabledDays],
1600
+ weekdayTimeSlots,
1601
+ weekendTimeSlots,
1602
+ timeSlots: Array.from(
1603
+ /* @__PURE__ */ new Set([...weekdayTimeSlots, ...weekendTimeSlots])
1604
+ ).sort()
1605
+ };
1606
+ }
1607
+ function contactError(message) {
1608
+ return new LeadSubmitError(`Garagem SDK: ${message}`, {
1609
+ code: "invalid_contact"
1610
+ });
1611
+ }
1612
+ function normalizeOwner(owner) {
1613
+ const name = text(owner?.name);
1614
+ const email = text(owner?.email);
1615
+ if (!isValidName(name)) throw contactError("owner name is invalid.");
1616
+ if (!isValidEmail(email)) throw contactError("owner email is invalid.");
1617
+ const phone = toE164(text(owner?.phone));
1618
+ if (!phone || !isValidPhone(phone) || phone.length > 40) {
1619
+ throw contactError("owner phone is invalid.");
1620
+ }
1621
+ return { name, email, phone };
1622
+ }
1623
+ function normalizeAddress(address) {
1624
+ const errors = sellerAddressErrors(address);
1625
+ const first = Object.values(errors)[0];
1626
+ if (first) {
1627
+ throw new LeadSubmitError(`Garagem SDK: ${first}`, {
1628
+ code: "invalid_address"
1629
+ });
1630
+ }
1631
+ const optional = (value) => text(value) ? { value: text(value) } : null;
1632
+ const number = address.noNumber ? null : optional(address.number);
1633
+ const bloco = address.noBlocoTorre ? null : optional(address.blocoTorre);
1634
+ const unidade = address.noUnidade ? null : optional(address.unidade);
1635
+ return {
1636
+ fullAddress: text(address.fullAddress),
1637
+ street: text(address.street),
1638
+ ...number ? { number: number.value } : {},
1639
+ neighborhood: text(address.neighborhood),
1640
+ city: text(address.city),
1641
+ state: text(address.state),
1642
+ postalCode: text(address.postalCode).replace(/\D/g, ""),
1643
+ country: text(address.country) || "BR",
1644
+ latitude: address.latitude,
1645
+ longitude: address.longitude,
1646
+ ...bloco ? { blocoTorre: bloco.value } : {},
1647
+ ...unidade ? { unidade: unidade.value } : {},
1648
+ noNumber: address.noNumber === true,
1649
+ noBlocoTorre: address.noBlocoTorre === true,
1650
+ noUnidade: address.noUnidade === true
1651
+ };
1652
+ }
1653
+ var COUNT_FIELDS = [
1654
+ "bedrooms",
1655
+ "bathrooms",
1656
+ "suites",
1657
+ "parkingSpaces"
1658
+ ];
1659
+ var AMOUNT_FIELDS = [
1660
+ "saleValue",
1661
+ "rentValue",
1662
+ "condoFee",
1663
+ "totalArea"
1664
+ ];
1665
+ function propertyError(message) {
1666
+ return new LeadSubmitError(`Garagem SDK: ${message}`, {
1667
+ code: "invalid_property"
1668
+ });
1669
+ }
1670
+ function normalizeProperty(property) {
1671
+ if (!["sale", "rent", "both"].includes(property?.businessType)) {
1672
+ throw propertyError("businessType must be sale, rent or both.");
1673
+ }
1674
+ for (const field of COUNT_FIELDS) {
1675
+ const value = property[field];
1676
+ if (value != null && (!Number.isInteger(value) || value < 0 || value > 999)) {
1677
+ throw propertyError(`${field} must be a whole number.`);
1678
+ }
1679
+ }
1680
+ for (const field of AMOUNT_FIELDS) {
1681
+ const value = property[field];
1682
+ if (value != null && (!Number.isFinite(value) || value < 0 || value > 1e12)) {
1683
+ throw propertyError(`${field} must be a non-negative number.`);
1684
+ }
1685
+ }
1686
+ const sale = property.businessType === "rent" ? void 0 : property.saleValue;
1687
+ const rent = property.businessType === "sale" ? void 0 : property.rentValue;
1688
+ const price = property.businessType === "rent" ? rent : sale;
1689
+ const counts = Object.fromEntries(
1690
+ COUNT_FIELDS.filter((field) => property[field] != null).map((field) => [
1691
+ field,
1692
+ property[field]
1693
+ ])
1694
+ );
1695
+ return {
1696
+ businessType: property.businessType,
1697
+ ...price != null ? { price } : {},
1698
+ ...property.businessType === "both" && rent != null ? { rentPrice: rent } : {},
1699
+ ...property.condoFee != null ? { condominiumFee: property.condoFee } : {},
1700
+ ...property.totalArea != null ? { totalArea: property.totalArea } : {},
1701
+ ...counts
1702
+ };
1703
+ }
1704
+ function normalizePhotos(photos) {
1705
+ if (!photos?.length) return void 0;
1706
+ if (photos.length > SELLER_LEAD_PHOTO_MAX_COUNT) {
1707
+ throw new LeadSubmitError("Garagem SDK: too many photos (max 30).", {
1708
+ code: "invalid_photo"
1709
+ });
1710
+ }
1711
+ return photos.map((url) => {
1712
+ const trimmed = url.trim();
1713
+ if (!trimmed.startsWith("https://")) {
1714
+ throw new LeadSubmitError("Garagem SDK: photo URL must be https.", {
1715
+ code: "invalid_photo"
1716
+ });
1717
+ }
1718
+ return trimmed;
1719
+ });
1720
+ }
1721
+ function normalizePhotoSession(input) {
1722
+ if (!input.photoSession) return void 0;
1723
+ const schedule = input.photoSchedule ?? sellerPhotoSchedule();
1724
+ const date = normalizeVisitDate(input.photoSession.date, schedule.timeZone);
1725
+ const time = normalizeVisitTime(input.photoSession.time);
1726
+ if (!date || !time || !isVisitSlotAllowed(schedule, date, time)) {
1727
+ throw new LeadSubmitError(
1728
+ "Garagem SDK: photo session slot is outside the schedule.",
1729
+ { code: "invalid_slot" }
1730
+ );
1731
+ }
1732
+ return { date, time };
1733
+ }
1734
+ async function submitSellerLead(input) {
1735
+ const owner = normalizeOwner(input.owner);
1736
+ const address = normalizeAddress(input.address);
1737
+ const property = normalizeProperty(input.property);
1738
+ const photos = normalizePhotos(input.photos);
1739
+ const photoScheduling = normalizePhotoSession(input);
1740
+ return postSiteLead({
1741
+ siteId: input.siteId,
1742
+ baseUrl: input.baseUrl,
1743
+ fetch: input.fetch,
1744
+ publishableKey: input.publishableKey,
1745
+ body: {
1746
+ source: "site-sdk",
1747
+ leadType: "seller_lead",
1748
+ ...owner,
1749
+ address,
1750
+ ...property,
1751
+ ...photos ? { photos } : {},
1752
+ ...photoScheduling ? { photoScheduling } : {},
1753
+ ...input.visitorId ? { visitorId: input.visitorId } : {},
1754
+ ...input.brokerRef ? { brokerRef: input.brokerRef } : {},
1755
+ ...input.referrer ? { referrer: input.referrer } : {}
1756
+ }
1757
+ });
1758
+ }
1759
+
1445
1760
  // src/amenity-labels.ts
1446
1761
  var LISTING_AMENITY_TITLES = {
1447
1762
  unit: "Comodidades",
@@ -1862,9 +2177,9 @@ var SORT_URL_TOKENS = [
1862
2177
  ];
1863
2178
 
1864
2179
  // ../search-url/slugify.ts
1865
- function slugifyForUrl(text) {
1866
- if (!text) return "";
1867
- const withDashes = text.replace(/([a-z])([A-Z])/g, "$1-$2");
2180
+ function slugifyForUrl(text2) {
2181
+ if (!text2) return "";
2182
+ const withDashes = text2.replace(/([a-z])([A-Z])/g, "$1-$2");
1868
2183
  return withDashes.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "").replace(/[^\w\s-]/g, "").replace(/\s+/g, "-").replace(/-+/g, "-").trim();
1869
2184
  }
1870
2185
 
@@ -2141,8 +2456,8 @@ function serializeAppliedSearchQuery(query) {
2141
2456
  if (normalized.sort && isSortToken(normalized.sort)) {
2142
2457
  params.set("ordenar", normalized.sort);
2143
2458
  }
2144
- const text = normalized.query?.trim();
2145
- if (text) params.set("q", text);
2459
+ const text2 = normalized.query?.trim();
2460
+ if (text2) params.set("q", text2);
2146
2461
  for (const value of (normalized.loc ?? []).slice(0, MAX_LOC_GROUPS)) {
2147
2462
  const trimmed = value.trim();
2148
2463
  if (trimmed) params.append("loc", trimmed);
@@ -2559,11 +2874,11 @@ function countFacetChoices(options) {
2559
2874
  }
2560
2875
  var FEMININE_HEADING = /(casa|cobertura|kitnet|loja|sala|fazenda|chácara|chacara)s?$/i;
2561
2876
  function pluralizePt(label) {
2562
- const text = label.trim();
2563
- if (!text || /s$/i.test(text)) return text;
2564
- if (/il$/i.test(text)) return `${text.slice(0, -1)}is`;
2565
- if (/m$/i.test(text)) return `${text.slice(0, -1)}ns`;
2566
- return `${text}s`;
2877
+ const text2 = label.trim();
2878
+ if (!text2 || /s$/i.test(text2)) return text2;
2879
+ if (/il$/i.test(text2)) return `${text2.slice(0, -1)}is`;
2880
+ if (/m$/i.test(text2)) return `${text2.slice(0, -1)}ns`;
2881
+ return `${text2}s`;
2567
2882
  }
2568
2883
  function headingLocationSuffix(location) {
2569
2884
  if (!location) return "";
@@ -2856,16 +3171,16 @@ function listingBreadcrumb(listing) {
2856
3171
  return crumbs;
2857
3172
  }
2858
3173
  function listingDescriptionPreview(description, expanded = false) {
2859
- const text = description?.trim() ?? "";
2860
- if (!text) return null;
2861
- if (text.length <= LISTING_DESCRIPTION_CLAMP) {
2862
- return { text, truncated: false, toggleLabel: null };
3174
+ const text2 = description?.trim() ?? "";
3175
+ if (!text2) return null;
3176
+ if (text2.length <= LISTING_DESCRIPTION_CLAMP) {
3177
+ return { text: text2, truncated: false, toggleLabel: null };
2863
3178
  }
2864
3179
  if (expanded) {
2865
- return { text, truncated: true, toggleLabel: "Ler menos" };
3180
+ return { text: text2, truncated: true, toggleLabel: "Ler menos" };
2866
3181
  }
2867
3182
  return {
2868
- text: `${text.slice(0, LISTING_DESCRIPTION_CLAMP).trimEnd()}\u2026`,
3183
+ text: `${text2.slice(0, LISTING_DESCRIPTION_CLAMP).trimEnd()}\u2026`,
2869
3184
  truncated: true,
2870
3185
  toggleLabel: "Ler mais"
2871
3186
  };
@@ -2890,8 +3205,8 @@ function listingMediaOverlays(listing) {
2890
3205
  return overlays;
2891
3206
  }
2892
3207
  function listingDetailModel(listing, options) {
2893
- const text = listing.description?.trim() ?? "";
2894
- const description = text || null;
3208
+ const text2 = listing.description?.trim() ?? "";
3209
+ const description = text2 || null;
2895
3210
  const truncated = description != null && description.length > LISTING_DESCRIPTION_CLAMP;
2896
3211
  const expanded = options?.descriptionExpanded === true;
2897
3212
  return {
@@ -2916,8 +3231,8 @@ function visibleText(value) {
2916
3231
  function visibleRows(rows) {
2917
3232
  return rows.filter((row) => {
2918
3233
  const label = visibleText(row.label);
2919
- const text = visibleText(row.text);
2920
- return label != null && text != null;
3234
+ const text2 = visibleText(row.text);
3235
+ return label != null && text2 != null;
2921
3236
  });
2922
3237
  }
2923
3238
  function listingDetailFieldsModel(listing, dictionary) {
@@ -3123,8 +3438,31 @@ var STUDIO_SDK_CONTRACT = {
3123
3438
  "searchListingPhotos",
3124
3439
  "applyMatchedPhotoCover"
3125
3440
  ],
3126
- photoSearchSince: "0.7.0"
3441
+ photoSearchSince: "0.7.0",
3442
+ /**
3443
+ * Seller lead (property registration on `/anunciar-imovel`). Prompt-safe
3444
+ * only once `minNpmVersion` reaches `sellerLeadSince`; below it
3445
+ * `studioSellerLeadSdkInstruction` prints nothing and
3446
+ * `studioCodegenContractViolations` flags the names.
3447
+ */
3448
+ sellerLeadExports: [
3449
+ "submitSellerLead",
3450
+ "uploadSellerLeadPhoto",
3451
+ "sellerAddressErrors",
3452
+ "sellerPhotoSchedule",
3453
+ "isValidEmail",
3454
+ "isValidName"
3455
+ ],
3456
+ sellerLeadSince: "0.10.0"
3127
3457
  };
3458
+ function isSellerLeadOnPin(pin = STUDIO_SDK_CONTRACT.minNpmVersion) {
3459
+ return compareSemver(pin, STUDIO_SDK_CONTRACT.sellerLeadSince) >= 0;
3460
+ }
3461
+ function studioSellerLeadSdkInstruction(pin = STUDIO_SDK_CONTRACT.minNpmVersion) {
3462
+ if (!isSellerLeadOnPin(pin)) return "";
3463
+ const names = STUDIO_SDK_CONTRACT.sellerLeadExports.join(", ");
3464
+ return `Property registration (\`/anunciar-imovel\`, client component): import ${names}, isValidPhone, toE164 from \`${STUDIO_SDK_PACKAGE}\`. Address: load Maps JS only through \`<script src="https://maps.fndn.ai/sdk.js?callback=initPlaces" async defer />\` (Places is included; never a Google key, never \`maps.googleapis.com\`), then \`google.maps.places.Autocomplete\` with \`componentRestrictions: { country: "br" }\` and pt-BR. Picking a suggestion fills fullAddress, street, number, neighborhood, city, state (the 2-letter code), postalCode, latitude and longitude from the place; a typed address without a suggestion is not enough. The visitor confirms number or "Sem n\xFAmero", bloco/torre or "N\xE3o tem", unidade or "N\xE3o tem" (noNumber, noBlocoTorre, noUnidade). Block the next group while \`sellerAddressErrors(address)\` has keys and show each message on its field. Owner: name, email and phone are all required \u2014 \`isValidName\`, \`isValidEmail\`, the phone mask with \`isValidPhone(toE164(phone))\`. Photos: \`await uploadSellerLeadPhoto({ siteId, baseUrl: GARAGEM_API_BASE, file, publishableKey })\` per file (JPG/PNG/WEBP, 10MB, up to 30), keep the returned URLs. Photo session: \`const schedule = sellerPhotoSchedule(config)\` and \`slotsForDate(schedule, day)\` for the hours. Submit once with \`await submitSellerLead({ siteId, baseUrl: GARAGEM_API_BASE, publishableKey, owner: { name, email, phone }, address, property: { businessType, saleValue, rentValue, condoFee, totalArea, bedrooms, bathrooms, suites, parkingSpaces }, photos, photoSession: { date, time }, photoSchedule: schedule })\` (omit what the visitor did not fill). Errors are \`LeadSubmitError\`: \`duplicate_property\` \u2192 "Este im\xF3vel j\xE1 est\xE1 cadastrado. Nossa equipe entrar\xE1 em contato."; \`invalid_address\` \u2192 ask to pick the address again; anything else \u2192 a retry message. Disable the submit while pending and show a success state after it resolves. Never POST the leads webhook by hand.`;
3465
+ }
3128
3466
  function isPhotoSearchOnPin(pin = STUDIO_SDK_CONTRACT.minNpmVersion) {
3129
3467
  return compareSemver(pin, STUDIO_SDK_CONTRACT.photoSearchSince) >= 0;
3130
3468
  }
@@ -3159,8 +3497,8 @@ function studioSearchLandmarkInstruction() {
3159
3497
  }
3160
3498
  var REACT_SDK_NAMED_IMPORT_RE = /(?:^|[\n;])\s*import\s+(?!type\b)(?:type\s+)?\{([^}]+)\}\s+from\s+['"]@garagem-ai\/site-sdk\/react['"]/g;
3161
3499
  var SHOWCASE_LEADS_POST_URL_RE = /\/api\/sites\/[^\s"']*\/leads(?!\/ui)/;
3162
- function hasShowcaseLeadsPostUrl(text) {
3163
- return SHOWCASE_LEADS_POST_URL_RE.test(text);
3500
+ function hasShowcaseLeadsPostUrl(text2) {
3501
+ return SHOWCASE_LEADS_POST_URL_RE.test(text2);
3164
3502
  }
3165
3503
  function coerceNpmVersion(raw) {
3166
3504
  if (typeof raw !== "string") return null;
@@ -3301,47 +3639,54 @@ function studioPhotoSearchInstruction(pin = STUDIO_SDK_CONTRACT.minNpmVersion) {
3301
3639
  function studioChromeInstruction() {
3302
3640
  return `Card, skeleton, and search chrome markup are app-owned. Never \`import "${STUDIO_SDK_CONTRACT.forbiddenImports[0]}"\` \u2014 v0 preview cannot load npm CSS. Do not mount an SDK stylesheet. Theme with site tokens and \`--radius\` in \`app/globals.css\`.`;
3303
3641
  }
3304
- function mentionsExportName(text, name) {
3305
- return new RegExp(`\\b${name}\\b`).test(text);
3642
+ function mentionsExportName(text2, name) {
3643
+ return new RegExp(`\\b${name}\\b`).test(text2);
3306
3644
  }
3307
- function studioCodegenContractViolations(text) {
3645
+ function studioCodegenContractViolations(text2) {
3308
3646
  const violations = [];
3309
3647
  for (const [name, since] of Object.entries(
3310
3648
  STUDIO_SDK_CONTRACT.optionalReactExports
3311
3649
  )) {
3312
3650
  if (compareSemver(STUDIO_SDK_CONTRACT.minNpmVersion, since) >= 0) continue;
3313
- if (mentionsExportName(text, name)) violations.push(name);
3651
+ if (mentionsExportName(text2, name)) violations.push(name);
3314
3652
  }
3315
3653
  for (const name of STUDIO_SDK_CONTRACT.retiredReactExports) {
3316
- if (mentionsExportName(text, name) && !violations.includes(name)) {
3654
+ if (mentionsExportName(text2, name) && !violations.includes(name)) {
3317
3655
  violations.push(name);
3318
3656
  }
3319
3657
  }
3320
3658
  for (const name of STUDIO_SDK_CONTRACT.unpublishedSearchExports) {
3321
- if (mentionsExportName(text, name) && !violations.includes(name)) {
3659
+ if (mentionsExportName(text2, name) && !violations.includes(name)) {
3322
3660
  violations.push(name);
3323
3661
  }
3324
3662
  }
3325
3663
  for (const name of STUDIO_SDK_CONTRACT.unpublishedPhoneExports) {
3326
- if (mentionsExportName(text, name) && !violations.includes(name)) {
3664
+ if (mentionsExportName(text2, name) && !violations.includes(name)) {
3327
3665
  violations.push(name);
3328
3666
  }
3329
3667
  }
3330
3668
  if (!mapsExportsPublished()) {
3331
3669
  for (const name of STUDIO_SDK_CONTRACT.mapsExports) {
3332
- if (mentionsExportName(text, name) && !violations.includes(name)) {
3670
+ if (mentionsExportName(text2, name) && !violations.includes(name)) {
3333
3671
  violations.push(name);
3334
3672
  }
3335
3673
  }
3336
3674
  }
3337
3675
  for (const name of STUDIO_SDK_CONTRACT.unpublishedPhotoExports) {
3338
- if (mentionsExportName(text, name) && !violations.includes(name)) {
3676
+ if (mentionsExportName(text2, name) && !violations.includes(name)) {
3339
3677
  violations.push(name);
3340
3678
  }
3341
3679
  }
3342
3680
  if (!isPhotoSearchOnPin()) {
3343
3681
  for (const name of STUDIO_SDK_CONTRACT.photoSearchExports) {
3344
- if (mentionsExportName(text, name) && !violations.includes(name)) {
3682
+ if (mentionsExportName(text2, name) && !violations.includes(name)) {
3683
+ violations.push(name);
3684
+ }
3685
+ }
3686
+ }
3687
+ if (!isSellerLeadOnPin()) {
3688
+ for (const name of STUDIO_SDK_CONTRACT.sellerLeadExports) {
3689
+ if (mentionsExportName(text2, name) && !violations.includes(name)) {
3345
3690
  violations.push(name);
3346
3691
  }
3347
3692
  }
@@ -3349,21 +3694,21 @@ function studioCodegenContractViolations(text) {
3349
3694
  const pin = STUDIO_SDK_CONTRACT.minNpmVersion;
3350
3695
  if (!marketExportsAvailableAt(pin)) {
3351
3696
  for (const name of STUDIO_SDK_CONTRACT.marketExports) {
3352
- if (mentionsExportName(text, name) && !violations.includes(name)) {
3697
+ if (mentionsExportName(text2, name) && !violations.includes(name)) {
3353
3698
  violations.push(name);
3354
3699
  }
3355
3700
  }
3356
3701
  }
3357
3702
  const available = reactExportsAvailableAt(pin);
3358
- for (const name of parseReactSdkNamedImports(text)) {
3703
+ for (const name of parseReactSdkNamedImports(text2)) {
3359
3704
  if (!available.has(name) && !violations.includes(name)) {
3360
3705
  violations.push(name);
3361
3706
  }
3362
3707
  }
3363
- if (hasShowcaseLeadsPostUrl(text)) {
3708
+ if (hasShowcaseLeadsPostUrl(text2)) {
3364
3709
  violations.push("showcase-leads-url");
3365
3710
  }
3366
- if (/\btype\s*=\s*["']date["']/.test(text)) {
3711
+ if (/\btype\s*=\s*["']date["']/.test(text2)) {
3367
3712
  violations.push("native-date-input");
3368
3713
  }
3369
3714
  return violations;
@@ -3556,14 +3901,14 @@ function listingCoordinates(listing) {
3556
3901
  }
3557
3902
  function coordinateDecimals(value) {
3558
3903
  if (!Number.isFinite(value)) return 0;
3559
- const text = Math.abs(value).toString();
3560
- if (text.includes("e")) {
3904
+ const text2 = Math.abs(value).toString();
3905
+ if (text2.includes("e")) {
3561
3906
  const fixed = Math.abs(value).toFixed(12).replace(/0+$/, "");
3562
3907
  const dot2 = fixed.indexOf(".");
3563
3908
  return dot2 === -1 ? 0 : fixed.length - dot2 - 1;
3564
3909
  }
3565
- const dot = text.indexOf(".");
3566
- return dot === -1 ? 0 : text.length - dot - 1;
3910
+ const dot = text2.indexOf(".");
3911
+ return dot === -1 ? 0 : text2.length - dot - 1;
3567
3912
  }
3568
3913
  function roundTo(value, decimals) {
3569
3914
  const factor = 10 ** decimals;
@@ -4427,15 +4772,15 @@ function listingVisualHighlights(listing, options) {
4427
4772
  if (!isPhoto(item) || !Array.isArray(item.features)) continue;
4428
4773
  for (const feature of item.features) {
4429
4774
  if (typeof feature !== "string") continue;
4430
- const text = feature.trim();
4431
- if (!text) continue;
4432
- const key = normalizeRoomLabel(text);
4775
+ const text2 = feature.trim();
4776
+ if (!text2) continue;
4777
+ const key = normalizeRoomLabel(text2);
4433
4778
  if (!key) continue;
4434
4779
  const entry = counts.get(key);
4435
4780
  if (entry) {
4436
4781
  entry.count += 1;
4437
4782
  } else {
4438
- counts.set(key, { text, count: 1, seen: seen++ });
4783
+ counts.set(key, { text: text2, count: 1, seen: seen++ });
4439
4784
  }
4440
4785
  }
4441
4786
  }
@@ -4700,6 +5045,10 @@ function applyMatchedPhotoCover(cards, photoResults, options = {}) {
4700
5045
  PHOTO_SEARCH_MIN_QUERY_LENGTH,
4701
5046
  SEARCH_EMPTY_COPY,
4702
5047
  SEARCH_SORT_RELEVANCE,
5048
+ SELLER_LEAD_PHOTO_MAX_BYTES,
5049
+ SELLER_LEAD_PHOTO_MAX_COUNT,
5050
+ SELLER_LEAD_PHOTO_TYPES,
5051
+ STUDIO_DEFAULT_PHOTO_SCHEDULE_CONFIG,
4703
5052
  STUDIO_DEFAULT_VISIT_SCHEDULE,
4704
5053
  STUDIO_SDK_CONTRACT,
4705
5054
  STUDIO_SDK_PACKAGE,
@@ -4761,7 +5110,10 @@ function applyMatchedPhotoCover(cards, photoResults, options = {}) {
4761
5110
  isMapBounds,
4762
5111
  isMapPolygon,
4763
5112
  isPhotoSearchOnPin,
5113
+ isSellerLeadOnPin,
4764
5114
  isStudioPreviewHost,
5115
+ isValidEmail,
5116
+ isValidName,
4765
5117
  isValidPhone,
4766
5118
  isVisitSlotAllowed,
4767
5119
  labelAmenities,
@@ -4831,6 +5183,8 @@ function applyMatchedPhotoCover(cards, photoResults, options = {}) {
4831
5183
  searchListingsInPolygon,
4832
5184
  searchResultsHeading,
4833
5185
  searchSortOptions,
5186
+ sellerAddressErrors,
5187
+ sellerPhotoSchedule,
4834
5188
  serializeAppliedSearchQuery,
4835
5189
  slotsForDate,
4836
5190
  studioAmenityInstruction,
@@ -4851,8 +5205,10 @@ function applyMatchedPhotoCover(cards, photoResults, options = {}) {
4851
5205
  studioSdkPinInstruction,
4852
5206
  studioSearchInstruction,
4853
5207
  studioSearchLandmarkInstruction,
5208
+ studioSellerLeadSdkInstruction,
4854
5209
  studioSiteWidthCss,
4855
5210
  submitContactLead,
5211
+ submitSellerLead,
4856
5212
  submitVisitLead,
4857
5213
  toE164,
4858
5214
  toListingCardModel,
@@ -4862,6 +5218,7 @@ function applyMatchedPhotoCover(cards, photoResults, options = {}) {
4862
5218
  travelTimesFromListing,
4863
5219
  truncateNationalPhoneDigits,
4864
5220
  unavailableReactImports,
5221
+ uploadSellerLeadPhoto,
4865
5222
  visibleSearchFilters
4866
5223
  });
4867
5224
  //# sourceMappingURL=index.js.map