@garagem-ai/site-sdk 0.12.1 → 0.13.1
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.d.mts +31 -6
- package/dist/index.d.ts +31 -6
- package/dist/index.js +2166 -2098
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2164 -2100
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.mts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +298 -192
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +298 -192
- package/dist/react.mjs.map +1 -1
- package/dist/{types-photo-search-Bmf1f1-Y.d.mts → types-photo-search-BPLxl65M.d.mts} +41 -41
- package/dist/{types-photo-search-Bmf1f1-Y.d.ts → types-photo-search-BPLxl65M.d.ts} +41 -41
- package/package.json +1 -1
- package/src/analytics.ts +144 -0
- package/src/index.ts +4 -0
- package/src/leads.ts +7 -2
- package/src/react/public-search-snapshot.ts +17 -0
- package/src/react/use-public-search.ts +30 -1
- package/src/search-engine.ts +15 -0
- package/src/studio-contract.ts +36 -3
package/dist/index.js
CHANGED
|
@@ -45,6 +45,7 @@ __export(src_exports, {
|
|
|
45
45
|
SELLER_LEAD_PHOTO_MAX_BYTES: () => SELLER_LEAD_PHOTO_MAX_BYTES,
|
|
46
46
|
SELLER_LEAD_PHOTO_MAX_COUNT: () => SELLER_LEAD_PHOTO_MAX_COUNT,
|
|
47
47
|
SELLER_LEAD_PHOTO_TYPES: () => SELLER_LEAD_PHOTO_TYPES,
|
|
48
|
+
SITE_ANALYTICS_EVENT: () => SITE_ANALYTICS_EVENT,
|
|
48
49
|
STUDIO_DEFAULT_PHOTO_SCHEDULE_CONFIG: () => STUDIO_DEFAULT_PHOTO_SCHEDULE_CONFIG,
|
|
49
50
|
STUDIO_DEFAULT_VISIT_SCHEDULE: () => STUDIO_DEFAULT_VISIT_SCHEDULE,
|
|
50
51
|
STUDIO_SDK_CONTRACT: () => STUDIO_SDK_CONTRACT,
|
|
@@ -105,6 +106,7 @@ __export(src_exports, {
|
|
|
105
106
|
hrefForAppliedChange: () => hrefForAppliedChange,
|
|
106
107
|
hrefForPathFilters: () => hrefForPathFilters,
|
|
107
108
|
hrefWithExplicitPage: () => hrefWithExplicitPage,
|
|
109
|
+
isAnalyticsOnPin: () => isAnalyticsOnPin,
|
|
108
110
|
isListingDetailPath: () => isListingDetailPath,
|
|
109
111
|
isMapBounds: () => isMapBounds,
|
|
110
112
|
isMapPolygon: () => isMapPolygon,
|
|
@@ -195,6 +197,7 @@ __export(src_exports, {
|
|
|
195
197
|
studioLeadInstruction: () => studioLeadInstruction,
|
|
196
198
|
studioListingCardInstruction: () => studioListingCardInstruction,
|
|
197
199
|
studioListingDetailInstruction: () => studioListingDetailInstruction,
|
|
200
|
+
studioListingViewInstruction: () => studioListingViewInstruction,
|
|
198
201
|
studioMapSearchInstruction: () => studioMapSearchInstruction,
|
|
199
202
|
studioMapsInstruction: () => studioMapsInstruction,
|
|
200
203
|
studioMarketInstruction: () => studioMarketInstruction,
|
|
@@ -214,6 +217,7 @@ __export(src_exports, {
|
|
|
214
217
|
toE164: () => toE164,
|
|
215
218
|
toListingCardModel: () => toListingCardModel,
|
|
216
219
|
toolbarFilterIds: () => toolbarFilterIds,
|
|
220
|
+
trackListingView: () => trackListingView,
|
|
217
221
|
travelTimeCacheKey: () => travelTimeCacheKey,
|
|
218
222
|
travelTimeFromListing: () => travelTimeFromListing,
|
|
219
223
|
travelTimesFromListing: () => travelTimesFromListing,
|
|
@@ -705,2303 +709,2338 @@ async function getShareLink(options) {
|
|
|
705
709
|
);
|
|
706
710
|
}
|
|
707
711
|
|
|
708
|
-
//
|
|
709
|
-
var
|
|
710
|
-
var
|
|
711
|
-
var
|
|
712
|
-
var
|
|
713
|
-
var
|
|
714
|
-
var
|
|
715
|
-
var
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
712
|
+
// ../search-url/types.ts
|
|
713
|
+
var SEARCH_BASE_ROUTE = "imoveis";
|
|
714
|
+
var MAX_PAGE = 1e4;
|
|
715
|
+
var MAX_LOC_GROUPS = 20;
|
|
716
|
+
var DEFAULT_MIN_PRICE = 0;
|
|
717
|
+
var DEFAULT_MAX_PRICE = 1e9;
|
|
718
|
+
var DEFAULT_MIN_AREA = 0;
|
|
719
|
+
var DEFAULT_MAX_AREA = 1e5;
|
|
720
|
+
var SORT_URL_TOKENS = [
|
|
721
|
+
"recentes",
|
|
722
|
+
"preco-asc",
|
|
723
|
+
"preco-desc",
|
|
724
|
+
"area-asc",
|
|
725
|
+
"area-desc"
|
|
726
|
+
];
|
|
727
|
+
|
|
728
|
+
// ../search-url/slugify.ts
|
|
729
|
+
function slugifyForUrl(text2) {
|
|
730
|
+
if (!text2) return "";
|
|
731
|
+
const withDashes = text2.replace(/([a-z])([A-Z])/g, "$1-$2");
|
|
732
|
+
return withDashes.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "").replace(/[^\w\s-]/g, "").replace(/\s+/g, "-").replace(/-+/g, "-").trim();
|
|
726
733
|
}
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
734
|
+
|
|
735
|
+
// ../search-url/catalog.ts
|
|
736
|
+
var PROPERTY_TYPE_SLUG_ALIASES = {
|
|
737
|
+
rural: ["chacara", "fazenda", "sitio"]
|
|
738
|
+
};
|
|
739
|
+
function buildListingTypeOptions(enabled) {
|
|
740
|
+
const flags = enabled ?? { sale: true, rental: true };
|
|
741
|
+
const out = [];
|
|
742
|
+
if (flags.sale !== false) {
|
|
743
|
+
out.push({ id: "sale", slug: "venda", label: "Venda" });
|
|
744
|
+
}
|
|
745
|
+
if (flags.rental !== false) {
|
|
746
|
+
out.push({ id: "rental", slug: "aluguel", label: "Aluguel" });
|
|
747
|
+
}
|
|
748
|
+
return out;
|
|
731
749
|
}
|
|
732
|
-
function
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
750
|
+
function emptySearchUrlDictionary() {
|
|
751
|
+
return {
|
|
752
|
+
listingTypes: buildListingTypeOptions(null),
|
|
753
|
+
propertyTypes: [],
|
|
754
|
+
propertyFeatures: [],
|
|
755
|
+
buildingAmenities: []
|
|
756
|
+
};
|
|
736
757
|
}
|
|
737
|
-
function
|
|
738
|
-
|
|
739
|
-
return match ? `${match[1]}:${match[2]}` : null;
|
|
758
|
+
function norm(value) {
|
|
759
|
+
return slugifyForUrl(value) || value.toLowerCase();
|
|
740
760
|
}
|
|
741
|
-
function
|
|
742
|
-
const
|
|
743
|
-
const
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
const hour = Math.floor(minutes / 60);
|
|
748
|
-
const minute = minutes % 60;
|
|
749
|
-
slots.push(`${pad2(hour)}:${pad2(minute)}`);
|
|
761
|
+
function matchOptionId(segment, options, extraAliases) {
|
|
762
|
+
const n = norm(segment);
|
|
763
|
+
for (const option of options) {
|
|
764
|
+
const aliases = extraAliases?.[option.id] ?? [];
|
|
765
|
+
const candidates = [option.id, option.slug, option.label, ...aliases];
|
|
766
|
+
if (candidates.some((c) => norm(c) === n)) return option.id;
|
|
750
767
|
}
|
|
751
|
-
return
|
|
768
|
+
return null;
|
|
752
769
|
}
|
|
753
|
-
function
|
|
754
|
-
|
|
770
|
+
function optionSlugById(id, options) {
|
|
771
|
+
const option = options.find((item) => item.id === id);
|
|
772
|
+
return option?.slug ?? null;
|
|
755
773
|
}
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
return
|
|
764
|
-
|
|
765
|
-
weekend: weekendHours,
|
|
766
|
-
disabledDays,
|
|
767
|
-
weekdayTimeSlots,
|
|
768
|
-
weekendTimeSlots,
|
|
769
|
-
timeSlots: unionSorted(weekdayTimeSlots, weekendTimeSlots)
|
|
770
|
-
};
|
|
774
|
+
var LISTING_TYPE_ALIASES = {
|
|
775
|
+
sale: ["comprar"],
|
|
776
|
+
rental: ["alugar"]
|
|
777
|
+
};
|
|
778
|
+
|
|
779
|
+
// ../search-url/path.ts
|
|
780
|
+
function toArray(value) {
|
|
781
|
+
if (value === void 0) return [];
|
|
782
|
+
return Array.isArray(value) ? value : [value];
|
|
771
783
|
}
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
timeZone: VISIT_TIME_ZONE,
|
|
775
|
-
saturday: false,
|
|
776
|
-
sunday: false,
|
|
777
|
-
weekday: { start: "06:00", end: "22:00" },
|
|
778
|
-
weekend: null,
|
|
779
|
-
minHoursAhead: 2
|
|
780
|
-
}
|
|
781
|
-
);
|
|
782
|
-
function zonedParts(date, timeZone) {
|
|
783
|
-
const parts = new Intl.DateTimeFormat("en-US", {
|
|
784
|
-
timeZone,
|
|
785
|
-
weekday: "short",
|
|
786
|
-
year: "numeric",
|
|
787
|
-
month: "2-digit",
|
|
788
|
-
day: "2-digit",
|
|
789
|
-
hour: "2-digit",
|
|
790
|
-
minute: "2-digit",
|
|
791
|
-
hourCycle: "h23"
|
|
792
|
-
}).formatToParts(date);
|
|
793
|
-
const get = (type) => parts.find((part) => part.type === type)?.value ?? "";
|
|
794
|
-
const weekday = WEEKDAY_SHORT[get("weekday")] ?? 0;
|
|
795
|
-
return {
|
|
796
|
-
year: Number(get("year")),
|
|
797
|
-
month: Number(get("month")),
|
|
798
|
-
day: Number(get("day")),
|
|
799
|
-
hour: Number(get("hour")),
|
|
800
|
-
minute: Number(get("minute")),
|
|
801
|
-
weekday
|
|
802
|
-
};
|
|
784
|
+
function formatNumeric(value) {
|
|
785
|
+
return Array.isArray(value) ? value.join("-") : String(value);
|
|
803
786
|
}
|
|
804
|
-
function
|
|
805
|
-
|
|
806
|
-
return `${parts.year}-${pad2(parts.month)}-${pad2(parts.day)}`;
|
|
787
|
+
function formatRange(min, max, unit) {
|
|
788
|
+
return `de-${min}-a-${max}-${unit}`;
|
|
807
789
|
}
|
|
808
|
-
function
|
|
809
|
-
const
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
const month = Number(match[2]);
|
|
813
|
-
const day = Number(match[3]);
|
|
814
|
-
const utc = new Date(Date.UTC(year, month - 1, day));
|
|
815
|
-
if (utc.getUTCFullYear() !== year || utc.getUTCMonth() !== month - 1 || utc.getUTCDate() !== day) {
|
|
816
|
-
return null;
|
|
817
|
-
}
|
|
818
|
-
return { year, month, day };
|
|
790
|
+
function formatSuiteSuffix(value) {
|
|
791
|
+
const values = Array.isArray(value) ? value : [value];
|
|
792
|
+
const firstValue = values[0] ?? 0;
|
|
793
|
+
return firstValue === 0 || firstValue === 1 ? "suite" : "suites";
|
|
819
794
|
}
|
|
820
|
-
function
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
}
|
|
828
|
-
const local = DATETIME_LOCAL_RE.exec(trimmed);
|
|
829
|
-
if (local && parseYmd(local[1])) return local[1];
|
|
830
|
-
return null;
|
|
795
|
+
function composeSearchPublicPath(filters, dictionary = emptySearchUrlDictionary()) {
|
|
796
|
+
const segments = [];
|
|
797
|
+
const listingType = filters.listingType;
|
|
798
|
+
if (listingType) {
|
|
799
|
+
segments.push(
|
|
800
|
+
optionSlugById(listingType, dictionary.listingTypes) || slugifyForUrl(listingType)
|
|
801
|
+
);
|
|
831
802
|
}
|
|
832
|
-
|
|
833
|
-
|
|
803
|
+
for (const propertyType of toArray(filters.propertyType)) {
|
|
804
|
+
segments.push(
|
|
805
|
+
optionSlugById(propertyType, dictionary.propertyTypes) || slugifyForUrl(propertyType)
|
|
806
|
+
);
|
|
834
807
|
}
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
808
|
+
const location = filters.location;
|
|
809
|
+
if (location) {
|
|
810
|
+
if (location.state) segments.push(slugifyForUrl(location.state));
|
|
811
|
+
if (location.city) segments.push(slugifyForUrl(location.city));
|
|
812
|
+
if (location.neighborhood)
|
|
813
|
+
segments.push(slugifyForUrl(location.neighborhood));
|
|
814
|
+
if (location.street) segments.push(slugifyForUrl(location.street));
|
|
815
|
+
}
|
|
816
|
+
if (filters.bedrooms !== void 0) {
|
|
817
|
+
segments.push(`${formatNumeric(filters.bedrooms)}-quartos`);
|
|
818
|
+
}
|
|
819
|
+
if (filters.bathrooms !== void 0) {
|
|
820
|
+
segments.push(`${formatNumeric(filters.bathrooms)}-banheiros`);
|
|
821
|
+
}
|
|
822
|
+
if (filters.suites !== void 0) {
|
|
823
|
+
const suffix = formatSuiteSuffix(filters.suites);
|
|
824
|
+
segments.push(`${formatNumeric(filters.suites)}-${suffix}`);
|
|
825
|
+
}
|
|
826
|
+
if (filters.parkingSpots !== void 0) {
|
|
827
|
+
segments.push(`${formatNumeric(filters.parkingSpots)}-vagas`);
|
|
828
|
+
}
|
|
829
|
+
if (filters.price && (filters.price.min !== void 0 || filters.price.max !== void 0)) {
|
|
830
|
+
const min = filters.price.min ?? DEFAULT_MIN_PRICE;
|
|
831
|
+
const max = filters.price.max ?? DEFAULT_MAX_PRICE;
|
|
832
|
+
segments.push(formatRange(min, max, "reais"));
|
|
833
|
+
}
|
|
834
|
+
if (filters.area && (filters.area.min !== void 0 || filters.area.max !== void 0)) {
|
|
835
|
+
const min = filters.area.min ?? DEFAULT_MIN_AREA;
|
|
836
|
+
const max = filters.area.max ?? DEFAULT_MAX_AREA;
|
|
837
|
+
segments.push(formatRange(min, max, "m2"));
|
|
838
|
+
}
|
|
839
|
+
const seenAmenities = /* @__PURE__ */ new Set();
|
|
840
|
+
for (const id of filters.propertyFeatures ?? []) {
|
|
841
|
+
const slug = optionSlugById(id, dictionary.propertyFeatures) || slugifyForUrl(id);
|
|
842
|
+
if (!slug || seenAmenities.has(slug)) continue;
|
|
843
|
+
seenAmenities.add(slug);
|
|
844
|
+
segments.push(slug);
|
|
845
|
+
}
|
|
846
|
+
for (const id of filters.buildingAmenities ?? []) {
|
|
847
|
+
const slug = optionSlugById(id, dictionary.buildingAmenities) || slugifyForUrl(id);
|
|
848
|
+
if (!slug || seenAmenities.has(slug)) continue;
|
|
849
|
+
seenAmenities.add(slug);
|
|
850
|
+
segments.push(slug);
|
|
851
|
+
}
|
|
852
|
+
const path = segments.filter(Boolean).join("/");
|
|
853
|
+
return path ? `/${SEARCH_BASE_ROUTE}/${path}` : `/${SEARCH_BASE_ROUTE}`;
|
|
844
854
|
}
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
if (weekday === 6 && !schedule.saturday) return [];
|
|
854
|
-
const base = weekday === 0 || weekday === 6 ? schedule.weekendTimeSlots : schedule.weekdayTimeSlots;
|
|
855
|
-
const today = calendarYmd(now, timeZone);
|
|
856
|
-
if (ymd < today) return [];
|
|
857
|
-
if (ymd !== today) return [...base];
|
|
858
|
-
const nowParts = zonedParts(now, timeZone);
|
|
859
|
-
const cutoff = nowParts.hour * 60 + nowParts.minute + schedule.minHoursAhead * 60;
|
|
860
|
-
return base.filter((slot) => {
|
|
861
|
-
const minutes = minutesOfDay(slot);
|
|
862
|
-
return minutes != null && minutes >= cutoff;
|
|
863
|
-
});
|
|
855
|
+
var BEDROOMS = /^(\d+(?:-\d+)*)-quartos?$/;
|
|
856
|
+
var BATHROOMS = /^(\d+(?:-\d+)*)-banheiros?$/;
|
|
857
|
+
var SUITES = /^(\d+(?:-\d+)*)-suites?$/;
|
|
858
|
+
var PARKING = /^(\d+(?:-\d+)*)-vagas?$/;
|
|
859
|
+
var PRICE = /^de-(\d+)-a-(\d+)-(reais|real)$/;
|
|
860
|
+
var AREA = /^de-(\d+)-a-(\d+)-(m2|m²)$/;
|
|
861
|
+
function parseNumericList(raw) {
|
|
862
|
+
return raw.split("-").map((part) => Number(part)).filter((n) => Number.isFinite(n));
|
|
864
863
|
}
|
|
865
|
-
function
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
864
|
+
function collapse(values) {
|
|
865
|
+
return values.length === 1 ? values[0] : values;
|
|
866
|
+
}
|
|
867
|
+
function parseSearchPublicPath(pathname, dictionary = emptySearchUrlDictionary()) {
|
|
868
|
+
const raw = pathname.split(/[?#]/)[0] ?? "";
|
|
869
|
+
let segments = raw.replace(/^\//, "").split("/").filter(Boolean);
|
|
870
|
+
if (segments[0] === SEARCH_BASE_ROUTE) segments = segments.slice(1);
|
|
871
|
+
if (segments.some((segment) => segment.includes("."))) return null;
|
|
872
|
+
if (segments.some((segment) => segment.toLowerCase().startsWith("id-"))) {
|
|
873
|
+
return null;
|
|
874
|
+
}
|
|
875
|
+
const filters = {};
|
|
876
|
+
const locationParts = [];
|
|
877
|
+
const propertyTypes = [];
|
|
878
|
+
const propertyFeatures = [];
|
|
879
|
+
const buildingAmenities = [];
|
|
880
|
+
for (const segment of segments) {
|
|
881
|
+
const lower = segment.toLowerCase();
|
|
882
|
+
const listingType = matchOptionId(
|
|
883
|
+
segment,
|
|
884
|
+
dictionary.listingTypes,
|
|
885
|
+
LISTING_TYPE_ALIASES
|
|
886
|
+
);
|
|
887
|
+
if (listingType && !filters.listingType) {
|
|
888
|
+
filters.listingType = listingType;
|
|
889
|
+
continue;
|
|
890
|
+
}
|
|
891
|
+
const propertyType = matchOptionId(
|
|
892
|
+
segment,
|
|
893
|
+
dictionary.propertyTypes,
|
|
894
|
+
PROPERTY_TYPE_SLUG_ALIASES
|
|
895
|
+
);
|
|
896
|
+
if (propertyType) {
|
|
897
|
+
propertyTypes.push(propertyType);
|
|
898
|
+
continue;
|
|
899
|
+
}
|
|
900
|
+
const bedrooms = lower.match(BEDROOMS);
|
|
901
|
+
if (bedrooms) {
|
|
902
|
+
filters.bedrooms = collapse(parseNumericList(bedrooms[1]));
|
|
903
|
+
continue;
|
|
904
|
+
}
|
|
905
|
+
const bathrooms = lower.match(BATHROOMS);
|
|
906
|
+
if (bathrooms) {
|
|
907
|
+
filters.bathrooms = collapse(parseNumericList(bathrooms[1]));
|
|
908
|
+
continue;
|
|
909
|
+
}
|
|
910
|
+
const suites = lower.match(SUITES);
|
|
911
|
+
if (suites) {
|
|
912
|
+
filters.suites = collapse(parseNumericList(suites[1]));
|
|
913
|
+
continue;
|
|
914
|
+
}
|
|
915
|
+
const parking = lower.match(PARKING);
|
|
916
|
+
if (parking) {
|
|
917
|
+
filters.parkingSpots = collapse(parseNumericList(parking[1]));
|
|
918
|
+
continue;
|
|
919
|
+
}
|
|
920
|
+
const price = lower.match(PRICE);
|
|
921
|
+
if (price) {
|
|
922
|
+
filters.price = { min: Number(price[1]), max: Number(price[2]) };
|
|
923
|
+
continue;
|
|
924
|
+
}
|
|
925
|
+
const area = lower.match(AREA);
|
|
926
|
+
if (area) {
|
|
927
|
+
filters.area = { min: Number(area[1]), max: Number(area[2]) };
|
|
928
|
+
continue;
|
|
929
|
+
}
|
|
930
|
+
const featureId = matchOptionId(segment, dictionary.propertyFeatures);
|
|
931
|
+
if (featureId) {
|
|
932
|
+
propertyFeatures.push(featureId);
|
|
933
|
+
continue;
|
|
934
|
+
}
|
|
935
|
+
const amenityId = matchOptionId(segment, dictionary.buildingAmenities);
|
|
936
|
+
if (amenityId) {
|
|
937
|
+
buildingAmenities.push(amenityId);
|
|
938
|
+
continue;
|
|
939
|
+
}
|
|
940
|
+
locationParts.push(segment);
|
|
941
|
+
}
|
|
942
|
+
if (propertyTypes.length === 1) filters.propertyType = propertyTypes[0];
|
|
943
|
+
else if (propertyTypes.length > 1) filters.propertyType = propertyTypes;
|
|
944
|
+
if (propertyFeatures.length) filters.propertyFeatures = propertyFeatures;
|
|
945
|
+
if (buildingAmenities.length) filters.buildingAmenities = buildingAmenities;
|
|
946
|
+
const location = locationFromPathLeftovers(locationParts);
|
|
947
|
+
if (location) filters.location = location;
|
|
948
|
+
return filters;
|
|
949
|
+
}
|
|
950
|
+
var PATH_STREET_PREFIX = /^(rua|r|avenida|av|alameda|al|travessa|tv|estrada|rodovia|rod)-/i;
|
|
951
|
+
function locationFromPathLeftovers(parts) {
|
|
952
|
+
if (parts.length === 0) return void 0;
|
|
953
|
+
if (parts.length === 1) {
|
|
954
|
+
const value = parts[0];
|
|
955
|
+
if (PATH_STREET_PREFIX.test(value)) return { street: value };
|
|
956
|
+
if (/^[a-z]{2}$/i.test(value)) return { state: value };
|
|
957
|
+
return { neighborhood: value };
|
|
958
|
+
}
|
|
959
|
+
const [state, city, neighborhood, street] = parts;
|
|
960
|
+
return {
|
|
961
|
+
...state ? { state } : {},
|
|
962
|
+
...city ? { city } : {},
|
|
963
|
+
...neighborhood ? { neighborhood } : {},
|
|
964
|
+
...street ? { street } : {}
|
|
965
|
+
};
|
|
869
966
|
}
|
|
870
967
|
|
|
871
|
-
//
|
|
872
|
-
var
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
var DEFAULT_PHONE_COUNTRY_CODE = "BR";
|
|
876
|
-
var PHONE_COUNTRIES = [
|
|
877
|
-
{ code: "BR", name: "Brasil", dialCode: "55", flag: "\u{1F1E7}\u{1F1F7}" },
|
|
878
|
-
{ code: "US", name: "Estados Unidos", dialCode: "1", flag: "\u{1F1FA}\u{1F1F8}" },
|
|
879
|
-
{ code: "CA", name: "Canad\xE1", dialCode: "1", flag: "\u{1F1E8}\u{1F1E6}" },
|
|
880
|
-
{ code: "MX", name: "M\xE9xico", dialCode: "52", flag: "\u{1F1F2}\u{1F1FD}" },
|
|
881
|
-
{ code: "GT", name: "Guatemala", dialCode: "502", flag: "\u{1F1EC}\u{1F1F9}" },
|
|
882
|
-
{ code: "BZ", name: "Belize", dialCode: "501", flag: "\u{1F1E7}\u{1F1FF}" },
|
|
883
|
-
{ code: "SV", name: "El Salvador", dialCode: "503", flag: "\u{1F1F8}\u{1F1FB}" },
|
|
884
|
-
{ code: "HN", name: "Honduras", dialCode: "504", flag: "\u{1F1ED}\u{1F1F3}" },
|
|
885
|
-
{ code: "NI", name: "Nicar\xE1gua", dialCode: "505", flag: "\u{1F1F3}\u{1F1EE}" },
|
|
886
|
-
{ code: "CR", name: "Costa Rica", dialCode: "506", flag: "\u{1F1E8}\u{1F1F7}" },
|
|
887
|
-
{ code: "PA", name: "Panam\xE1", dialCode: "507", flag: "\u{1F1F5}\u{1F1E6}" },
|
|
888
|
-
{ code: "CU", name: "Cuba", dialCode: "53", flag: "\u{1F1E8}\u{1F1FA}" },
|
|
889
|
-
{ code: "DO", name: "Rep\xFAblica Dominicana", dialCode: "1", flag: "\u{1F1E9}\u{1F1F4}" },
|
|
890
|
-
{ code: "HT", name: "Haiti", dialCode: "509", flag: "\u{1F1ED}\u{1F1F9}" },
|
|
891
|
-
{ code: "AR", name: "Argentina", dialCode: "54", flag: "\u{1F1E6}\u{1F1F7}" },
|
|
892
|
-
{ code: "CL", name: "Chile", dialCode: "56", flag: "\u{1F1E8}\u{1F1F1}" },
|
|
893
|
-
{ code: "CO", name: "Col\xF4mbia", dialCode: "57", flag: "\u{1F1E8}\u{1F1F4}" },
|
|
894
|
-
{ code: "PE", name: "Peru", dialCode: "51", flag: "\u{1F1F5}\u{1F1EA}" },
|
|
895
|
-
{ code: "UY", name: "Uruguai", dialCode: "598", flag: "\u{1F1FA}\u{1F1FE}" },
|
|
896
|
-
{ code: "PY", name: "Paraguai", dialCode: "595", flag: "\u{1F1F5}\u{1F1FE}" },
|
|
897
|
-
{ code: "BO", name: "Bol\xEDvia", dialCode: "591", flag: "\u{1F1E7}\u{1F1F4}" },
|
|
898
|
-
{ code: "EC", name: "Equador", dialCode: "593", flag: "\u{1F1EA}\u{1F1E8}" },
|
|
899
|
-
{ code: "VE", name: "Venezuela", dialCode: "58", flag: "\u{1F1FB}\u{1F1EA}" },
|
|
900
|
-
{ code: "GY", name: "Guiana", dialCode: "592", flag: "\u{1F1EC}\u{1F1FE}" },
|
|
901
|
-
{ code: "SR", name: "Suriname", dialCode: "597", flag: "\u{1F1F8}\u{1F1F7}" },
|
|
902
|
-
{ code: "PT", name: "Portugal", dialCode: "351", flag: "\u{1F1F5}\u{1F1F9}" },
|
|
903
|
-
{ code: "ES", name: "Espanha", dialCode: "34", flag: "\u{1F1EA}\u{1F1F8}" },
|
|
904
|
-
{ code: "FR", name: "Fran\xE7a", dialCode: "33", flag: "\u{1F1EB}\u{1F1F7}" },
|
|
905
|
-
{ code: "UK", name: "Reino Unido", dialCode: "44", flag: "\u{1F1EC}\u{1F1E7}" },
|
|
906
|
-
{ code: "DE", name: "Alemanha", dialCode: "49", flag: "\u{1F1E9}\u{1F1EA}" },
|
|
907
|
-
{ code: "IT", name: "It\xE1lia", dialCode: "39", flag: "\u{1F1EE}\u{1F1F9}" },
|
|
908
|
-
{ code: "NL", name: "Holanda", dialCode: "31", flag: "\u{1F1F3}\u{1F1F1}" },
|
|
909
|
-
{ code: "BE", name: "B\xE9lgica", dialCode: "32", flag: "\u{1F1E7}\u{1F1EA}" },
|
|
910
|
-
{ code: "CH", name: "Su\xED\xE7a", dialCode: "41", flag: "\u{1F1E8}\u{1F1ED}" },
|
|
911
|
-
{ code: "AT", name: "\xC1ustria", dialCode: "43", flag: "\u{1F1E6}\u{1F1F9}" },
|
|
912
|
-
{ code: "SE", name: "Su\xE9cia", dialCode: "46", flag: "\u{1F1F8}\u{1F1EA}" },
|
|
913
|
-
{ code: "NO", name: "Noruega", dialCode: "47", flag: "\u{1F1F3}\u{1F1F4}" },
|
|
914
|
-
{ code: "DK", name: "Dinamarca", dialCode: "45", flag: "\u{1F1E9}\u{1F1F0}" },
|
|
915
|
-
{ code: "FI", name: "Finl\xE2ndia", dialCode: "358", flag: "\u{1F1EB}\u{1F1EE}" },
|
|
916
|
-
{ code: "IE", name: "Irlanda", dialCode: "353", flag: "\u{1F1EE}\u{1F1EA}" },
|
|
917
|
-
{ code: "AU", name: "Austr\xE1lia", dialCode: "61", flag: "\u{1F1E6}\u{1F1FA}" },
|
|
918
|
-
{ code: "NZ", name: "Nova Zel\xE2ndia", dialCode: "64", flag: "\u{1F1F3}\u{1F1FF}" },
|
|
919
|
-
{ code: "JP", name: "Jap\xE3o", dialCode: "81", flag: "\u{1F1EF}\u{1F1F5}" },
|
|
920
|
-
{ code: "KR", name: "Coreia do Sul", dialCode: "82", flag: "\u{1F1F0}\u{1F1F7}" },
|
|
921
|
-
{ code: "CN", name: "China", dialCode: "86", flag: "\u{1F1E8}\u{1F1F3}" },
|
|
922
|
-
{ code: "IN", name: "\xCDndia", dialCode: "91", flag: "\u{1F1EE}\u{1F1F3}" },
|
|
923
|
-
{ code: "RU", name: "R\xFAssia", dialCode: "7", flag: "\u{1F1F7}\u{1F1FA}" },
|
|
924
|
-
{ code: "UA", name: "Ucr\xE2nia", dialCode: "380", flag: "\u{1F1FA}\u{1F1E6}" },
|
|
925
|
-
{ code: "AE", name: "Emirados \xC1rabes", dialCode: "971", flag: "\u{1F1E6}\u{1F1EA}" },
|
|
926
|
-
{ code: "SA", name: "Ar\xE1bia Saudita", dialCode: "966", flag: "\u{1F1F8}\u{1F1E6}" },
|
|
927
|
-
{ code: "QA", name: "Catar", dialCode: "974", flag: "\u{1F1F6}\u{1F1E6}" },
|
|
928
|
-
{ code: "KW", name: "Kuwait", dialCode: "965", flag: "\u{1F1F0}\u{1F1FC}" },
|
|
929
|
-
{ code: "BH", name: "Bahrein", dialCode: "973", flag: "\u{1F1E7}\u{1F1ED}" },
|
|
930
|
-
{ code: "OM", name: "Om\xE3", dialCode: "968", flag: "\u{1F1F4}\u{1F1F2}" },
|
|
931
|
-
{ code: "JO", name: "Jord\xE2nia", dialCode: "962", flag: "\u{1F1EF}\u{1F1F4}" },
|
|
932
|
-
{ code: "LB", name: "L\xEDbano", dialCode: "961", flag: "\u{1F1F1}\u{1F1E7}" },
|
|
933
|
-
{ code: "IL", name: "Israel", dialCode: "972", flag: "\u{1F1EE}\u{1F1F1}" },
|
|
934
|
-
{ code: "TR", name: "Turquia", dialCode: "90", flag: "\u{1F1F9}\u{1F1F7}" },
|
|
935
|
-
{ code: "EG", name: "Egito", dialCode: "20", flag: "\u{1F1EA}\u{1F1EC}" },
|
|
936
|
-
{ code: "ZA", name: "\xC1frica do Sul", dialCode: "27", flag: "\u{1F1FF}\u{1F1E6}" },
|
|
937
|
-
{ code: "AO", name: "Angola", dialCode: "244", flag: "\u{1F1E6}\u{1F1F4}" },
|
|
938
|
-
{ code: "MZ", name: "Mo\xE7ambique", dialCode: "258", flag: "\u{1F1F2}\u{1F1FF}" },
|
|
939
|
-
{ code: "CV", name: "Cabo Verde", dialCode: "238", flag: "\u{1F1E8}\u{1F1FB}" }
|
|
940
|
-
];
|
|
941
|
-
function phoneCountrySearchValue(country) {
|
|
942
|
-
return `${country.name} ${country.code} ${country.dialCode} +${country.dialCode}`;
|
|
968
|
+
// ../search-url/applied-query.ts
|
|
969
|
+
var SORT_SET = new Set(SORT_URL_TOKENS);
|
|
970
|
+
function isSortToken(value) {
|
|
971
|
+
return SORT_SET.has(value);
|
|
943
972
|
}
|
|
944
|
-
function
|
|
945
|
-
if (
|
|
946
|
-
|
|
947
|
-
|
|
973
|
+
function normalizeAppliedSearchQuery(query) {
|
|
974
|
+
if (query.loc && query.loc.length > 0) {
|
|
975
|
+
const { query: _query, ...rest } = query;
|
|
976
|
+
return rest;
|
|
977
|
+
}
|
|
978
|
+
return query;
|
|
948
979
|
}
|
|
949
|
-
function
|
|
950
|
-
|
|
980
|
+
function parseAppliedSearchQuery(search) {
|
|
981
|
+
const params = search instanceof URLSearchParams ? search : new URLSearchParams(search.startsWith("?") ? search.slice(1) : search);
|
|
982
|
+
const result = {};
|
|
983
|
+
const pageRaw = params.get("page");
|
|
984
|
+
if (pageRaw) {
|
|
985
|
+
const page = Number.parseInt(pageRaw, 10);
|
|
986
|
+
if (Number.isFinite(page) && page > 1) {
|
|
987
|
+
result.page = Math.min(page, MAX_PAGE);
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
const sort = params.get("ordenar");
|
|
991
|
+
if (sort && isSortToken(sort)) result.sort = sort;
|
|
992
|
+
const q = params.get("q")?.trim();
|
|
993
|
+
if (q) result.query = q;
|
|
994
|
+
const loc = params.getAll("loc").map((value) => value.trim()).filter(Boolean).slice(0, MAX_LOC_GROUPS);
|
|
995
|
+
if (loc.length > 0) result.loc = loc;
|
|
996
|
+
return normalizeAppliedSearchQuery(result);
|
|
951
997
|
}
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
"13",
|
|
959
|
-
"14",
|
|
960
|
-
"15",
|
|
961
|
-
"16",
|
|
962
|
-
"17",
|
|
963
|
-
"18",
|
|
964
|
-
"19",
|
|
965
|
-
"21",
|
|
966
|
-
"22",
|
|
967
|
-
"24",
|
|
968
|
-
"27",
|
|
969
|
-
"28",
|
|
970
|
-
"31",
|
|
971
|
-
"32",
|
|
972
|
-
"33",
|
|
973
|
-
"34",
|
|
974
|
-
"35",
|
|
975
|
-
"37",
|
|
976
|
-
"38",
|
|
977
|
-
"41",
|
|
978
|
-
"42",
|
|
979
|
-
"43",
|
|
980
|
-
"44",
|
|
981
|
-
"45",
|
|
982
|
-
"46",
|
|
983
|
-
"47",
|
|
984
|
-
"48",
|
|
985
|
-
"49",
|
|
986
|
-
"51",
|
|
987
|
-
"53",
|
|
988
|
-
"54",
|
|
989
|
-
"55",
|
|
990
|
-
"61",
|
|
991
|
-
"62",
|
|
992
|
-
"63",
|
|
993
|
-
"64",
|
|
994
|
-
"65",
|
|
995
|
-
"66",
|
|
996
|
-
"67",
|
|
997
|
-
"68",
|
|
998
|
-
"69",
|
|
999
|
-
"71",
|
|
1000
|
-
"73",
|
|
1001
|
-
"74",
|
|
1002
|
-
"75",
|
|
1003
|
-
"77",
|
|
1004
|
-
"79",
|
|
1005
|
-
"81",
|
|
1006
|
-
"82",
|
|
1007
|
-
"83",
|
|
1008
|
-
"84",
|
|
1009
|
-
"85",
|
|
1010
|
-
"86",
|
|
1011
|
-
"87",
|
|
1012
|
-
"88",
|
|
1013
|
-
"89",
|
|
1014
|
-
"91",
|
|
1015
|
-
"92",
|
|
1016
|
-
"93",
|
|
1017
|
-
"94",
|
|
1018
|
-
"95",
|
|
1019
|
-
"96",
|
|
1020
|
-
"97",
|
|
1021
|
-
"98",
|
|
1022
|
-
"99"
|
|
1023
|
-
]);
|
|
1024
|
-
var PHONE_INPUT_COUNTRY_CODES = new Set(
|
|
1025
|
-
PHONE_COUNTRIES.map((country) => country.code)
|
|
1026
|
-
);
|
|
1027
|
-
var SORTED_PHONE_INPUT_DIAL_CODES = [
|
|
1028
|
-
...new Set(PHONE_COUNTRIES.map((country) => country.dialCode))
|
|
1029
|
-
].sort((a, b) => b.length - a.length);
|
|
1030
|
-
function toLibCountryCode(code) {
|
|
1031
|
-
if (code === "UK") return "GB";
|
|
1032
|
-
return code;
|
|
1033
|
-
}
|
|
1034
|
-
function fromLibCountryCode(code) {
|
|
1035
|
-
if (code === "GB") return "UK";
|
|
1036
|
-
return code;
|
|
1037
|
-
}
|
|
1038
|
-
function nationalPhoneDigits(value) {
|
|
1039
|
-
return String(value ?? "").replace(/\D/g, "");
|
|
1040
|
-
}
|
|
1041
|
-
function truncateNationalPhoneDigits(digits, max = MAX_NATIONAL_PHONE_DIGITS) {
|
|
1042
|
-
return digits.slice(0, max);
|
|
1043
|
-
}
|
|
1044
|
-
function collapseDuplicatedBrazilianMobileNine(digits) {
|
|
1045
|
-
if (digits.length === 14 && digits.startsWith("55")) {
|
|
1046
|
-
const national = collapseDuplicatedBrazilianMobileNine(digits.slice(2));
|
|
1047
|
-
return national === digits.slice(2) ? digits : `55${national}`;
|
|
998
|
+
var APPLIED_QUERY_KEYS = ["page", "ordenar", "q", "loc"];
|
|
999
|
+
function serializeAppliedSearchQuery(query) {
|
|
1000
|
+
const normalized = normalizeAppliedSearchQuery(query);
|
|
1001
|
+
const params = new URLSearchParams();
|
|
1002
|
+
if (normalized.page !== void 0 && normalized.page > 1) {
|
|
1003
|
+
params.set("page", String(Math.min(normalized.page, MAX_PAGE)));
|
|
1048
1004
|
}
|
|
1049
|
-
if (
|
|
1050
|
-
|
|
1051
|
-
if (!VALID_BR_DDDS.has(ddd)) return digits;
|
|
1052
|
-
if (digits.charAt(2) !== "9") return digits;
|
|
1053
|
-
const rest = digits.slice(3);
|
|
1054
|
-
if (rest.length !== 9 || rest.charAt(0) !== "9") return digits;
|
|
1055
|
-
if (ddd === "55") {
|
|
1056
|
-
const subscriberFirst = digits.charAt(4);
|
|
1057
|
-
if (subscriberFirst >= "0" && subscriberFirst <= "5") {
|
|
1058
|
-
return digits;
|
|
1059
|
-
}
|
|
1005
|
+
if (normalized.sort && isSortToken(normalized.sort)) {
|
|
1006
|
+
params.set("ordenar", normalized.sort);
|
|
1060
1007
|
}
|
|
1061
|
-
|
|
1008
|
+
const text2 = normalized.query?.trim();
|
|
1009
|
+
if (text2) params.set("q", text2);
|
|
1010
|
+
for (const value of (normalized.loc ?? []).slice(0, MAX_LOC_GROUPS)) {
|
|
1011
|
+
const trimmed = value.trim();
|
|
1012
|
+
if (trimmed) params.append("loc", trimmed);
|
|
1013
|
+
}
|
|
1014
|
+
return params;
|
|
1062
1015
|
}
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1016
|
+
function mergeAppliedSearchQueryIntoSearch(existing, query) {
|
|
1017
|
+
const params = existing instanceof URLSearchParams ? new URLSearchParams(existing) : new URLSearchParams(
|
|
1018
|
+
existing.startsWith("?") ? existing.slice(1) : existing
|
|
1019
|
+
);
|
|
1020
|
+
for (const key of APPLIED_QUERY_KEYS) {
|
|
1021
|
+
params.delete(key);
|
|
1068
1022
|
}
|
|
1069
|
-
const
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1023
|
+
const serialized = serializeAppliedSearchQuery(query);
|
|
1024
|
+
serialized.forEach((value, key) => {
|
|
1025
|
+
if (key === "loc") {
|
|
1026
|
+
params.append("loc", value);
|
|
1027
|
+
} else {
|
|
1028
|
+
params.set(key, value);
|
|
1075
1029
|
}
|
|
1076
|
-
|
|
1077
|
-
|
|
1030
|
+
});
|
|
1031
|
+
return params;
|
|
1032
|
+
}
|
|
1033
|
+
function reduceAppliedSearchQuery(prev, change) {
|
|
1034
|
+
switch (change.type) {
|
|
1035
|
+
case "sort": {
|
|
1036
|
+
const next = { ...prev };
|
|
1037
|
+
delete next.page;
|
|
1038
|
+
if (change.sort) next.sort = change.sort;
|
|
1039
|
+
else delete next.sort;
|
|
1040
|
+
return normalizeAppliedSearchQuery(next);
|
|
1041
|
+
}
|
|
1042
|
+
case "applyFilters": {
|
|
1043
|
+
const next = { ...prev };
|
|
1044
|
+
delete next.page;
|
|
1045
|
+
return normalizeAppliedSearchQuery(next);
|
|
1046
|
+
}
|
|
1047
|
+
case "query": {
|
|
1048
|
+
const next = { ...prev };
|
|
1049
|
+
delete next.page;
|
|
1050
|
+
const trimmed = change.query.trim();
|
|
1051
|
+
if (trimmed) {
|
|
1052
|
+
next.query = trimmed;
|
|
1053
|
+
delete next.loc;
|
|
1054
|
+
} else {
|
|
1055
|
+
delete next.query;
|
|
1056
|
+
}
|
|
1057
|
+
return normalizeAppliedSearchQuery(next);
|
|
1058
|
+
}
|
|
1059
|
+
case "loc": {
|
|
1060
|
+
const next = { ...prev };
|
|
1061
|
+
delete next.page;
|
|
1062
|
+
delete next.query;
|
|
1063
|
+
const loc = change.loc.map((value) => value.trim()).filter(Boolean).slice(0, MAX_LOC_GROUPS);
|
|
1064
|
+
if (loc.length > 0) next.loc = loc;
|
|
1065
|
+
else delete next.loc;
|
|
1066
|
+
return normalizeAppliedSearchQuery(next);
|
|
1067
|
+
}
|
|
1068
|
+
case "page": {
|
|
1069
|
+
const next = { ...prev };
|
|
1070
|
+
if (change.page <= 1) delete next.page;
|
|
1071
|
+
else next.page = Math.min(change.page, MAX_PAGE);
|
|
1072
|
+
return normalizeAppliedSearchQuery(next);
|
|
1073
|
+
}
|
|
1074
|
+
default: {
|
|
1075
|
+
const _exhaustive = change;
|
|
1076
|
+
return _exhaustive;
|
|
1078
1077
|
}
|
|
1079
|
-
} catch {
|
|
1080
1078
|
}
|
|
1081
|
-
return numbers;
|
|
1082
1079
|
}
|
|
1083
|
-
function
|
|
1084
|
-
const
|
|
1085
|
-
const
|
|
1086
|
-
|
|
1087
|
-
return truncateNationalPhoneDigits(digits);
|
|
1080
|
+
function composeSearchPublicHref(pathname, query, existingSearch) {
|
|
1081
|
+
const params = existingSearch ? mergeAppliedSearchQueryIntoSearch(existingSearch, query) : serializeAppliedSearchQuery(query);
|
|
1082
|
+
const qs = params.toString();
|
|
1083
|
+
return qs ? `${pathname}?${qs}` : pathname;
|
|
1088
1084
|
}
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1085
|
+
|
|
1086
|
+
// src/applied-query.ts
|
|
1087
|
+
function parseAppliedSearchQuery2(search) {
|
|
1088
|
+
return parseAppliedSearchQuery(search);
|
|
1089
|
+
}
|
|
1090
|
+
function serializeAppliedSearchQuery2(query) {
|
|
1091
|
+
return serializeAppliedSearchQuery(query);
|
|
1092
|
+
}
|
|
1093
|
+
function mergeAppliedSearchQueryIntoSearch2(existing, query) {
|
|
1094
|
+
return mergeAppliedSearchQueryIntoSearch(existing, query);
|
|
1095
|
+
}
|
|
1096
|
+
function reduceAppliedSearchQuery2(prev, change) {
|
|
1097
|
+
return reduceAppliedSearchQuery(prev, change);
|
|
1098
|
+
}
|
|
1099
|
+
function composeSearchPublicHref2(pathname, query, existingSearch) {
|
|
1100
|
+
return composeSearchPublicHref(pathname, query, existingSearch);
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
// src/loc-params.ts
|
|
1104
|
+
function pathLocationToFilterInput(location) {
|
|
1105
|
+
if (!location || typeof location !== "object") return null;
|
|
1106
|
+
const { state, city, neighborhood, street } = location;
|
|
1107
|
+
const levels = [];
|
|
1108
|
+
if (state) levels.push(state);
|
|
1109
|
+
if (city) levels.push(city);
|
|
1110
|
+
if (neighborhood) levels.push(neighborhood);
|
|
1111
|
+
if (street) levels.push(street);
|
|
1112
|
+
if (levels.length === 0) return null;
|
|
1113
|
+
if (levels.length === 1) {
|
|
1114
|
+
if (state) return { type: "state", value: state };
|
|
1115
|
+
if (city) return { type: "city", value: city };
|
|
1116
|
+
if (neighborhood) return { type: "neighborhood", value: neighborhood };
|
|
1117
|
+
if (street) return { type: "street", value: street };
|
|
1099
1118
|
}
|
|
1100
|
-
return
|
|
1119
|
+
return { type: "path", value: levels.join("/") };
|
|
1101
1120
|
}
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
formatter.input(`+${country.dialCode}${digits}`);
|
|
1107
|
-
const national = formatter.getNumber()?.formatNational();
|
|
1108
|
-
if (national && nationalPhoneDigits(national) === digits) return national;
|
|
1109
|
-
const asTyped = new import_libphonenumber_js.AsYouType(libCode).input(digits);
|
|
1110
|
-
if (nationalPhoneDigits(asTyped) === digits) return asTyped;
|
|
1111
|
-
return digits;
|
|
1121
|
+
|
|
1122
|
+
// src/path.ts
|
|
1123
|
+
function composeSearchPublicPath2(filters, dictionary) {
|
|
1124
|
+
return dictionary ? composeSearchPublicPath(filters, dictionary) : composeSearchPublicPath(filters);
|
|
1112
1125
|
}
|
|
1113
|
-
function
|
|
1114
|
-
|
|
1115
|
-
return formatNationalDigits(prepareNationalDigits(value, country), country);
|
|
1126
|
+
function parseSearchPublicPath2(pathname, dictionary) {
|
|
1127
|
+
return dictionary ? parseSearchPublicPath(pathname, dictionary) : parseSearchPublicPath(pathname);
|
|
1116
1128
|
}
|
|
1117
|
-
function
|
|
1118
|
-
const
|
|
1119
|
-
if (
|
|
1120
|
-
|
|
1129
|
+
function pathFiltersToQueryFilters(pathFilters) {
|
|
1130
|
+
const result = {};
|
|
1131
|
+
if (pathFilters.listingType !== void 0) {
|
|
1132
|
+
result.listing_type = pathFilters.listingType;
|
|
1121
1133
|
}
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
try {
|
|
1125
|
-
const parsed = (0, import_libphonenumber_js.parsePhoneNumber)(cleaned);
|
|
1126
|
-
if (parsed.country) {
|
|
1127
|
-
const ourCode = fromLibCountryCode(parsed.country);
|
|
1128
|
-
if (PHONE_INPUT_COUNTRY_CODES.has(ourCode)) {
|
|
1129
|
-
return {
|
|
1130
|
-
ddi: parsed.countryCallingCode,
|
|
1131
|
-
national: parsed.nationalNumber,
|
|
1132
|
-
countryCode: ourCode
|
|
1133
|
-
};
|
|
1134
|
-
}
|
|
1135
|
-
}
|
|
1136
|
-
} catch {
|
|
1137
|
-
}
|
|
1138
|
-
const digits = cleaned.slice(1);
|
|
1139
|
-
for (const ddi of SORTED_PHONE_INPUT_DIAL_CODES) {
|
|
1140
|
-
if (digits.startsWith(ddi)) {
|
|
1141
|
-
const national = digits.slice(ddi.length);
|
|
1142
|
-
const match = PHONE_COUNTRIES.find((c) => c.dialCode === ddi);
|
|
1143
|
-
return {
|
|
1144
|
-
ddi,
|
|
1145
|
-
national,
|
|
1146
|
-
countryCode: match?.code ?? null
|
|
1147
|
-
};
|
|
1148
|
-
}
|
|
1149
|
-
}
|
|
1150
|
-
return {
|
|
1151
|
-
ddi: null,
|
|
1152
|
-
national: digits,
|
|
1153
|
-
countryCode: null
|
|
1154
|
-
};
|
|
1134
|
+
if (pathFilters.propertyType !== void 0) {
|
|
1135
|
+
result.property_type = pathFilters.propertyType;
|
|
1155
1136
|
}
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
national: cleaned.replace(/\D/g, ""),
|
|
1159
|
-
countryCode: null
|
|
1160
|
-
};
|
|
1161
|
-
}
|
|
1162
|
-
function preferValidE164(candidate) {
|
|
1163
|
-
try {
|
|
1164
|
-
const number = (0, import_libphonenumber_js.parsePhoneNumber)(candidate);
|
|
1165
|
-
if (number.isValid()) return number.number;
|
|
1166
|
-
} catch {
|
|
1137
|
+
if (pathFilters.bedrooms !== void 0) {
|
|
1138
|
+
result.property_bedrooms = pathFilters.bedrooms;
|
|
1167
1139
|
}
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
function toE164(value, countryCode = DEFAULT_PHONE_COUNTRY_CODE) {
|
|
1171
|
-
const trimmed = String(value ?? "").trim();
|
|
1172
|
-
if (!trimmed) return "";
|
|
1173
|
-
const parsed = parsePhoneInput(trimmed);
|
|
1174
|
-
if (parsed.ddi && parsed.national) {
|
|
1175
|
-
const ddiCountry = parsed.countryCode && findPhoneCountry(parsed.countryCode) || PHONE_COUNTRIES.find((c) => c.dialCode === parsed.ddi) || defaultPhoneCountry();
|
|
1176
|
-
return preferValidE164(
|
|
1177
|
-
`+${parsed.ddi}${prepareNationalDigits(parsed.national, ddiCountry)}`
|
|
1178
|
-
);
|
|
1140
|
+
if (pathFilters.bathrooms !== void 0) {
|
|
1141
|
+
result.property_bathrooms = pathFilters.bathrooms;
|
|
1179
1142
|
}
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
if (!national) return "";
|
|
1183
|
-
return preferValidE164(`+${country.dialCode}${national}`);
|
|
1184
|
-
}
|
|
1185
|
-
function isValidPhone(value, countryCode) {
|
|
1186
|
-
const cleaned = String(value ?? "").trim();
|
|
1187
|
-
if (!cleaned) return false;
|
|
1188
|
-
if (cleaned.startsWith("+")) {
|
|
1189
|
-
const digits2 = prepareInternationalDigits(cleaned);
|
|
1190
|
-
return digits2 ? (0, import_libphonenumber_js.isValidPhoneNumber)(`+${digits2}`) : false;
|
|
1143
|
+
if (pathFilters.suites !== void 0) {
|
|
1144
|
+
result.property_suites = pathFilters.suites;
|
|
1191
1145
|
}
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
const digits = prepareNationalDigits(cleaned, country);
|
|
1195
|
-
if (!digits) return false;
|
|
1196
|
-
if (countryCode) {
|
|
1197
|
-
return (0, import_libphonenumber_js.isValidPhoneNumber)(digits, toLibCountryCode(countryCode));
|
|
1146
|
+
if (pathFilters.parkingSpots !== void 0) {
|
|
1147
|
+
result.property_parking_spots = pathFilters.parkingSpots;
|
|
1198
1148
|
}
|
|
1199
|
-
if (
|
|
1200
|
-
|
|
1201
|
-
}
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1149
|
+
if (pathFilters.price !== void 0) {
|
|
1150
|
+
result.price = pathFilters.price;
|
|
1151
|
+
}
|
|
1152
|
+
if (pathFilters.area !== void 0) {
|
|
1153
|
+
result.property_area_total = pathFilters.area;
|
|
1154
|
+
}
|
|
1155
|
+
if (pathFilters.propertyFeatures !== void 0) {
|
|
1156
|
+
result.propertyFeatures = pathFilters.propertyFeatures;
|
|
1157
|
+
}
|
|
1158
|
+
if (pathFilters.buildingAmenities !== void 0) {
|
|
1159
|
+
result.buildingAmenities = pathFilters.buildingAmenities;
|
|
1160
|
+
}
|
|
1161
|
+
return result;
|
|
1212
1162
|
}
|
|
1213
1163
|
|
|
1214
|
-
// src/
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1164
|
+
// src/presentation.ts
|
|
1165
|
+
function formatListingPrice(amount, locale = "pt-BR", currency = "BRL") {
|
|
1166
|
+
if (amount == null) return "Sob consulta";
|
|
1167
|
+
try {
|
|
1168
|
+
return new Intl.NumberFormat(locale, {
|
|
1169
|
+
style: "currency",
|
|
1170
|
+
currency,
|
|
1171
|
+
minimumFractionDigits: 0,
|
|
1172
|
+
maximumFractionDigits: 0
|
|
1173
|
+
}).format(amount);
|
|
1174
|
+
} catch {
|
|
1175
|
+
return `${currency} ${amount}`;
|
|
1176
|
+
}
|
|
1220
1177
|
}
|
|
1221
|
-
function
|
|
1222
|
-
|
|
1178
|
+
function formatGroupedInteger(value, locale = "pt-BR") {
|
|
1179
|
+
const digits = String(value ?? "").replace(/\D/g, "");
|
|
1180
|
+
if (!digits) return "";
|
|
1181
|
+
const amount = Number.parseInt(digits, 10);
|
|
1182
|
+
if (!Number.isFinite(amount)) return "";
|
|
1183
|
+
return new Intl.NumberFormat(locale, { maximumFractionDigits: 0 }).format(
|
|
1184
|
+
amount
|
|
1185
|
+
);
|
|
1223
1186
|
}
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
if (host && !isStudioPreviewHost(host)) {
|
|
1228
|
-
const site = await getSite({
|
|
1229
|
-
domain: host,
|
|
1230
|
-
baseUrl: options.baseUrl,
|
|
1231
|
-
fetch: options.fetch,
|
|
1232
|
-
publishableKey: options.publishableKey
|
|
1233
|
-
});
|
|
1234
|
-
if (site?.id) return site.id;
|
|
1235
|
-
throw new GaragemSdkError(
|
|
1236
|
-
`Garagem SDK: no published site found for domain "${host}"`,
|
|
1237
|
-
{ status: 404, url: host }
|
|
1238
|
-
);
|
|
1187
|
+
function parseGroupedInteger(value) {
|
|
1188
|
+
if (typeof value === "number") {
|
|
1189
|
+
return Number.isFinite(value) ? Math.trunc(value) : void 0;
|
|
1239
1190
|
}
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
);
|
|
1191
|
+
const digits = String(value ?? "").replace(/\D/g, "");
|
|
1192
|
+
if (!digits) return void 0;
|
|
1193
|
+
const amount = Number.parseInt(digits, 10);
|
|
1194
|
+
return Number.isFinite(amount) ? amount : void 0;
|
|
1245
1195
|
}
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
if (typeof window === "undefined") return "";
|
|
1250
|
-
return window.location.host;
|
|
1196
|
+
function formatAreaM2(area) {
|
|
1197
|
+
if (area == null || !Number.isFinite(area)) return null;
|
|
1198
|
+
return `${area} m\xB2`;
|
|
1251
1199
|
}
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
return await coerceSiteId(input.siteId);
|
|
1255
|
-
} catch (error) {
|
|
1256
|
-
const host = browserHost();
|
|
1257
|
-
if (!host) throw error;
|
|
1258
|
-
return resolvePublicSiteId({
|
|
1259
|
-
host,
|
|
1260
|
-
baseUrl: input.baseUrl,
|
|
1261
|
-
fetch: input.fetch,
|
|
1262
|
-
publishableKey: input.publishableKey
|
|
1263
|
-
});
|
|
1264
|
-
}
|
|
1200
|
+
function listingBusinessLabel(businessType) {
|
|
1201
|
+
return businessType === "rental" ? "Aluguel" : "Venda";
|
|
1265
1202
|
}
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
}
|
|
1280
|
-
this.retryAfter = info.retryAfterSeconds ?? null;
|
|
1281
|
-
}
|
|
1203
|
+
|
|
1204
|
+
// src/search-engine.ts
|
|
1205
|
+
var PATH_FILTER_IDS = {
|
|
1206
|
+
listing_type: "listingType",
|
|
1207
|
+
property_type: "propertyType",
|
|
1208
|
+
property_bedrooms: "bedrooms",
|
|
1209
|
+
property_bathrooms: "bathrooms",
|
|
1210
|
+
property_suites: "suites",
|
|
1211
|
+
property_parking_spots: "parkingSpots",
|
|
1212
|
+
price: "price",
|
|
1213
|
+
property_area_total: "area",
|
|
1214
|
+
propertyFeatures: "propertyFeatures",
|
|
1215
|
+
buildingAmenities: "buildingAmenities"
|
|
1282
1216
|
};
|
|
1283
|
-
var
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1217
|
+
var FORBIDDEN_SEARCH_QUERY_KEYS = [
|
|
1218
|
+
"tipo",
|
|
1219
|
+
"quartos",
|
|
1220
|
+
"tipo-imovel",
|
|
1221
|
+
"banheiros",
|
|
1222
|
+
"vagas"
|
|
1223
|
+
];
|
|
1224
|
+
var SEARCH_SORT_RELEVANCE = {
|
|
1225
|
+
id: "",
|
|
1226
|
+
label: "Mais relevantes"
|
|
1227
|
+
};
|
|
1228
|
+
function searchSortOptions(sorts) {
|
|
1229
|
+
const fromApi = (sorts || []).filter((sort) => sort.id);
|
|
1230
|
+
return [
|
|
1231
|
+
{ id: SEARCH_SORT_RELEVANCE.id, label: SEARCH_SORT_RELEVANCE.label },
|
|
1232
|
+
...fromApi
|
|
1233
|
+
];
|
|
1293
1234
|
}
|
|
1294
|
-
var
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
{ id: "phone", required: false },
|
|
1298
|
-
{ id: "message", required: false }
|
|
1235
|
+
var TOOLBAR_PRIMARY_FILTER_IDS = [
|
|
1236
|
+
"price",
|
|
1237
|
+
"property_bedrooms"
|
|
1299
1238
|
];
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
visit: {
|
|
1306
|
-
ctaLabel: "Agendar visita",
|
|
1307
|
-
requireDateTime: true,
|
|
1308
|
-
schedule: STUDIO_DEFAULT_VISIT_SCHEDULE,
|
|
1309
|
-
fields: CONTACT_FIELDS
|
|
1310
|
-
},
|
|
1311
|
-
contact: {
|
|
1312
|
-
ctaLabel: "Fale conosco",
|
|
1313
|
-
requireDateTime: false,
|
|
1314
|
-
whatsappPhone: null,
|
|
1315
|
-
fields: CONTACT_FIELDS
|
|
1316
|
-
}
|
|
1317
|
-
}
|
|
1318
|
-
};
|
|
1239
|
+
var HIDDEN_FILTER_IDS = /* @__PURE__ */ new Set(["property_suites"]);
|
|
1240
|
+
function toFiniteNumber(value) {
|
|
1241
|
+
if (value === "" || value == null) return void 0;
|
|
1242
|
+
const n = Number(value);
|
|
1243
|
+
return Number.isFinite(n) ? n : void 0;
|
|
1319
1244
|
}
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
const url = `${normalizeBaseUrl(options.baseUrl)}/api/sites/${encodeURIComponent(siteId)}/leads/ui`;
|
|
1323
|
-
return callJson(
|
|
1324
|
-
url,
|
|
1325
|
-
{
|
|
1326
|
-
method: "GET",
|
|
1327
|
-
headers: { Accept: "application/json" },
|
|
1328
|
-
next: options.next
|
|
1329
|
-
},
|
|
1330
|
-
options.fetch ?? fetch,
|
|
1331
|
-
options.publishableKey
|
|
1332
|
-
);
|
|
1245
|
+
function pathnameOnly(pathname) {
|
|
1246
|
+
return String(pathname || "").split(/[?#]/)[0] || "/";
|
|
1333
1247
|
}
|
|
1334
|
-
function
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
{ code: "invalid_listing_id" }
|
|
1339
|
-
);
|
|
1340
|
-
}
|
|
1248
|
+
function isListingDetailPath(pathname) {
|
|
1249
|
+
const parts = pathnameOnly(pathname).split("/").filter(Boolean);
|
|
1250
|
+
const last = parts[parts.length - 1] || "";
|
|
1251
|
+
return last.toLowerCase().startsWith("id-");
|
|
1341
1252
|
}
|
|
1342
|
-
function
|
|
1343
|
-
const
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
});
|
|
1355
|
-
}
|
|
1356
|
-
if (email && !EMAIL_RE.test(email)) {
|
|
1357
|
-
throw new LeadSubmitError("Garagem SDK: email is invalid.", {
|
|
1358
|
-
code: "invalid_contact"
|
|
1359
|
-
});
|
|
1360
|
-
}
|
|
1361
|
-
let normalizedPhone;
|
|
1362
|
-
if (phone) {
|
|
1363
|
-
const e164 = toE164(phone);
|
|
1364
|
-
if (!e164 || !isValidPhone(e164) || e164.length > 40) {
|
|
1365
|
-
throw new LeadSubmitError("Garagem SDK: phone is invalid.", {
|
|
1366
|
-
code: "invalid_contact"
|
|
1367
|
-
});
|
|
1368
|
-
}
|
|
1369
|
-
normalizedPhone = e164;
|
|
1370
|
-
}
|
|
1371
|
-
const message = input.message?.trim() || void 0;
|
|
1372
|
-
if (message && message.length > MESSAGE_MAX) {
|
|
1373
|
-
throw new LeadSubmitError("Garagem SDK: message is too long.", {
|
|
1374
|
-
code: "invalid_contact"
|
|
1375
|
-
});
|
|
1376
|
-
}
|
|
1253
|
+
function readPublicSearch(pathname, search, dictionary) {
|
|
1254
|
+
const pathFilters = parseSearchPublicPath2(pathnameOnly(pathname), dictionary) || {};
|
|
1255
|
+
const applied = parseAppliedSearchQuery2(search || "");
|
|
1256
|
+
return { pathFilters, applied };
|
|
1257
|
+
}
|
|
1258
|
+
function lookupDisplay(table, slug) {
|
|
1259
|
+
if (!slug || !table) return slug;
|
|
1260
|
+
return table[slug] || table[String(slug).toLowerCase()] || slug;
|
|
1261
|
+
}
|
|
1262
|
+
function displayPathLocation(location, values) {
|
|
1263
|
+
if (!location) return null;
|
|
1264
|
+
const table = values || {};
|
|
1377
1265
|
return {
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1266
|
+
state: lookupDisplay(table.states, location.state),
|
|
1267
|
+
city: lookupDisplay(table.cities, location.city),
|
|
1268
|
+
neighborhood: lookupDisplay(table.neighborhoods, location.neighborhood),
|
|
1269
|
+
street: lookupDisplay(table.streets, location.street)
|
|
1382
1270
|
};
|
|
1383
1271
|
}
|
|
1384
|
-
function
|
|
1385
|
-
|
|
1386
|
-
const
|
|
1387
|
-
|
|
1388
|
-
|
|
1272
|
+
function buildQueryListingsParams(pathFilters, applied, schema, locationValues) {
|
|
1273
|
+
const filters = pathFiltersToQueryFilters(pathFilters || {});
|
|
1274
|
+
const locations = [];
|
|
1275
|
+
const displayed = displayPathLocation(pathFilters?.location, locationValues);
|
|
1276
|
+
const pathLoc = displayed ? pathLocationToFilterInput(displayed) : null;
|
|
1277
|
+
if (pathLoc) locations.push(pathLoc);
|
|
1278
|
+
for (const value of applied?.loc || []) {
|
|
1279
|
+
locations.push({ type: "loc", value });
|
|
1389
1280
|
}
|
|
1390
|
-
|
|
1391
|
-
|
|
1281
|
+
const params = {
|
|
1282
|
+
page: applied?.page || 1,
|
|
1283
|
+
limit: schema?.defaultLimit || 12,
|
|
1284
|
+
filters
|
|
1285
|
+
};
|
|
1286
|
+
if (applied?.sort) params.sort = applied.sort;
|
|
1287
|
+
const hasLocation = locations.length > 0;
|
|
1288
|
+
if (applied?.query && !hasLocation) params.q = applied.query;
|
|
1289
|
+
if (hasLocation) params.location = locations;
|
|
1290
|
+
return params;
|
|
1392
1291
|
}
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
if (response.status === 409 || parsed.reason === "duplicate_property") {
|
|
1401
|
-
return new LeadSubmitError(
|
|
1402
|
-
parsed.summary || "Garagem SDK: property already registered.",
|
|
1403
|
-
{ code: "duplicate_property", status: response.status }
|
|
1404
|
-
);
|
|
1405
|
-
}
|
|
1406
|
-
if (parsed.reason && ADDRESS_REJECTIONS.has(parsed.reason)) {
|
|
1407
|
-
return new LeadSubmitError(`Garagem SDK: ${parsed.reason}.`, {
|
|
1408
|
-
code: "invalid_address",
|
|
1409
|
-
status: 400
|
|
1410
|
-
});
|
|
1292
|
+
function applyPathFilter(pathFilters, filterId, value) {
|
|
1293
|
+
const next = { ...pathFilters || {} };
|
|
1294
|
+
const key = PATH_FILTER_IDS[filterId];
|
|
1295
|
+
if (!key) return next;
|
|
1296
|
+
if (value === "" || value == null) {
|
|
1297
|
+
delete next[key];
|
|
1298
|
+
return next;
|
|
1411
1299
|
}
|
|
1412
|
-
|
|
1413
|
-
}
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
...publishableKeyHeaders(input.publishableKey)
|
|
1427
|
-
},
|
|
1428
|
-
body: JSON.stringify(input.body)
|
|
1429
|
-
});
|
|
1430
|
-
} catch (error) {
|
|
1431
|
-
throw new LeadSubmitError(
|
|
1432
|
-
error instanceof Error ? error.message : "Garagem SDK: network error.",
|
|
1433
|
-
{ code: "network" }
|
|
1434
|
-
);
|
|
1300
|
+
if (key === "price" || key === "area") {
|
|
1301
|
+
const range = value || {};
|
|
1302
|
+
const parse = key === "price" ? parseGroupedInteger : toFiniteNumber;
|
|
1303
|
+
const min = parse(range.min);
|
|
1304
|
+
const max = parse(range.max);
|
|
1305
|
+
if (min == null && max == null) {
|
|
1306
|
+
delete next[key];
|
|
1307
|
+
return next;
|
|
1308
|
+
}
|
|
1309
|
+
next[key] = {
|
|
1310
|
+
...min != null ? { min } : {},
|
|
1311
|
+
...max != null ? { max } : {}
|
|
1312
|
+
};
|
|
1313
|
+
return next;
|
|
1435
1314
|
}
|
|
1436
|
-
if (
|
|
1437
|
-
const
|
|
1438
|
-
const id =
|
|
1439
|
-
|
|
1315
|
+
if (key === "propertyFeatures" || key === "buildingAmenities") {
|
|
1316
|
+
const current = Array.isArray(next[key]) ? [...next[key]] : [];
|
|
1317
|
+
const id = String(value);
|
|
1318
|
+
const i = current.indexOf(id);
|
|
1319
|
+
if (i >= 0) current.splice(i, 1);
|
|
1320
|
+
else current.push(id);
|
|
1321
|
+
if (current.length) next[key] = current;
|
|
1322
|
+
else delete next[key];
|
|
1323
|
+
return next;
|
|
1440
1324
|
}
|
|
1441
|
-
if (
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1325
|
+
if (key === "propertyType") {
|
|
1326
|
+
const id = String(value);
|
|
1327
|
+
const current = Array.isArray(next.propertyType) ? [...next.propertyType] : next.propertyType ? [String(next.propertyType)] : [];
|
|
1328
|
+
const i = current.indexOf(id);
|
|
1329
|
+
if (i >= 0) current.splice(i, 1);
|
|
1330
|
+
else current.push(id);
|
|
1331
|
+
if (current.length === 0) delete next.propertyType;
|
|
1332
|
+
else if (current.length === 1) next.propertyType = current[0];
|
|
1333
|
+
else next.propertyType = current;
|
|
1334
|
+
return next;
|
|
1446
1335
|
}
|
|
1447
|
-
if (
|
|
1448
|
-
const
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
parsed.retryAfterSeconds
|
|
1453
|
-
);
|
|
1454
|
-
throw new LeadSubmitError("Garagem SDK: too many lead submissions.", {
|
|
1455
|
-
code: "rate_limited",
|
|
1456
|
-
status: 429,
|
|
1457
|
-
...retryAfter != null ? { retryAfterSeconds: retryAfter } : {}
|
|
1458
|
-
});
|
|
1336
|
+
if (key === "listingType") {
|
|
1337
|
+
const id = String(value);
|
|
1338
|
+
if (next.listingType === id) delete next.listingType;
|
|
1339
|
+
else next.listingType = id;
|
|
1340
|
+
return next;
|
|
1459
1341
|
}
|
|
1460
|
-
if (
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1342
|
+
if (key === "bedrooms" || key === "bathrooms" || key === "suites" || key === "parkingSpots") {
|
|
1343
|
+
const n = Number(value);
|
|
1344
|
+
if (!Number.isFinite(n)) {
|
|
1345
|
+
delete next[key];
|
|
1346
|
+
return next;
|
|
1347
|
+
}
|
|
1348
|
+
if (next[key] === n) delete next[key];
|
|
1349
|
+
else next[key] = n;
|
|
1350
|
+
return next;
|
|
1465
1351
|
}
|
|
1466
|
-
|
|
1467
|
-
if (rejected) throw rejected;
|
|
1468
|
-
throw new LeadSubmitError(
|
|
1469
|
-
`Garagem SDK: lead submit failed (${response.status}).`,
|
|
1470
|
-
{ code: "http", status: response.status }
|
|
1471
|
-
);
|
|
1352
|
+
return next;
|
|
1472
1353
|
}
|
|
1473
|
-
function
|
|
1474
|
-
|
|
1475
|
-
const
|
|
1476
|
-
return
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
...input.visitorId ? { visitorId: input.visitorId } : {},
|
|
1481
|
-
...input.brokerRef ? { brokerRef: input.brokerRef } : {},
|
|
1482
|
-
...input.referrer ? { referrer: input.referrer } : {},
|
|
1483
|
-
...businessType ? { businessType } : {},
|
|
1484
|
-
...input.listingType ? { listingType: input.listingType } : {}
|
|
1485
|
-
}
|
|
1486
|
-
};
|
|
1354
|
+
function pathFilterValue(pathFilters, filterId) {
|
|
1355
|
+
const key = PATH_FILTER_IDS[filterId];
|
|
1356
|
+
const value = pathFilters && key ? pathFilters[key] : void 0;
|
|
1357
|
+
if (value == null) return "";
|
|
1358
|
+
if (Array.isArray(value)) return value[0] != null ? String(value[0]) : "";
|
|
1359
|
+
if (typeof value === "object") return "";
|
|
1360
|
+
return String(value);
|
|
1487
1361
|
}
|
|
1488
|
-
|
|
1489
|
-
const
|
|
1490
|
-
const
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
if (
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
}
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
body: {
|
|
1505
|
-
source: "site-sdk",
|
|
1506
|
-
leadType: "visit",
|
|
1507
|
-
...prepared.contact,
|
|
1508
|
-
propertyId: prepared.listingId,
|
|
1509
|
-
listingId: prepared.listingId,
|
|
1510
|
-
visitDate,
|
|
1511
|
-
visitTime,
|
|
1512
|
-
...prepared.extras
|
|
1513
|
-
}
|
|
1362
|
+
function pathFilterHasOption(pathFilters, filterId, optionId) {
|
|
1363
|
+
const key = PATH_FILTER_IDS[filterId];
|
|
1364
|
+
const value = pathFilters && key ? pathFilters[key] : void 0;
|
|
1365
|
+
if (value == null) return false;
|
|
1366
|
+
if (Array.isArray(value)) return value.map(String).includes(optionId);
|
|
1367
|
+
if (typeof value === "object") return false;
|
|
1368
|
+
return String(value) === optionId;
|
|
1369
|
+
}
|
|
1370
|
+
function publicSearchHref(pathFilters, applied, dictionary, existingSearch) {
|
|
1371
|
+
const pathname = composeSearchPublicPath2(pathFilters || {}, dictionary);
|
|
1372
|
+
return composeSearchPublicHref2(pathname, applied || {}, existingSearch);
|
|
1373
|
+
}
|
|
1374
|
+
function hrefForPathFilters(pathname, search, dictionary, nextPathFilters) {
|
|
1375
|
+
const { applied } = readPublicSearch(pathname, search, dictionary);
|
|
1376
|
+
const nextApplied = reduceAppliedSearchQuery2(applied, {
|
|
1377
|
+
type: "applyFilters"
|
|
1514
1378
|
});
|
|
1379
|
+
return publicSearchHref(nextPathFilters, nextApplied, dictionary, search);
|
|
1515
1380
|
}
|
|
1516
|
-
|
|
1517
|
-
const
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1381
|
+
function hrefForAppliedChange(pathname, search, dictionary, change) {
|
|
1382
|
+
const { pathFilters, applied } = readPublicSearch(
|
|
1383
|
+
pathname,
|
|
1384
|
+
search,
|
|
1385
|
+
dictionary
|
|
1386
|
+
);
|
|
1387
|
+
let nextPath = pathFilters;
|
|
1388
|
+
if (change && change.type === "query") {
|
|
1389
|
+
nextPath = { ...pathFilters };
|
|
1390
|
+
delete nextPath.location;
|
|
1391
|
+
}
|
|
1392
|
+
const nextApplied = reduceAppliedSearchQuery2(applied, change);
|
|
1393
|
+
return publicSearchHref(nextPath, nextApplied, dictionary, search);
|
|
1394
|
+
}
|
|
1395
|
+
function currentSearchHref(pathname, search) {
|
|
1396
|
+
const path = pathnameOnly(pathname);
|
|
1397
|
+
const qs = search.replace(/^\?/, "");
|
|
1398
|
+
return qs ? `${path}?${qs}` : path;
|
|
1399
|
+
}
|
|
1400
|
+
function canonicalizeSearchHref(pathname, search, dictionary) {
|
|
1401
|
+
if (pathname.includes("/api/v0-preview/")) return null;
|
|
1402
|
+
if (isListingDetailPath(pathname)) return null;
|
|
1403
|
+
const { pathFilters, applied } = readPublicSearch(
|
|
1404
|
+
pathname,
|
|
1405
|
+
search,
|
|
1406
|
+
dictionary
|
|
1407
|
+
);
|
|
1408
|
+
const href = publicSearchHref(pathFilters, applied, dictionary, search);
|
|
1409
|
+
if (href === currentSearchHref(pathname, search)) return null;
|
|
1410
|
+
return href;
|
|
1411
|
+
}
|
|
1412
|
+
function searchHrefUsesLegacyFilterQuery(href) {
|
|
1413
|
+
const query = href.split("?")[1] || "";
|
|
1414
|
+
const params = new URLSearchParams(query);
|
|
1415
|
+
return FORBIDDEN_SEARCH_QUERY_KEYS.some((key) => params.has(key));
|
|
1416
|
+
}
|
|
1417
|
+
function clearStagedPathFilters(current, keepFilterIds = []) {
|
|
1418
|
+
const next = current.location ? { location: current.location } : {};
|
|
1419
|
+
for (const id of keepFilterIds) {
|
|
1420
|
+
const key = PATH_FILTER_IDS[id];
|
|
1421
|
+
if (!key || key === "location") continue;
|
|
1422
|
+
const value = current[key];
|
|
1423
|
+
if (value != null) Object.assign(next, { [key]: value });
|
|
1424
|
+
}
|
|
1425
|
+
return next;
|
|
1426
|
+
}
|
|
1427
|
+
function visibleSearchFilters(schema) {
|
|
1428
|
+
if (!schema?.filters) return [];
|
|
1429
|
+
return schema.filters.filter((filter) => {
|
|
1430
|
+
if (HIDDEN_FILTER_IDS.has(filter.id)) return false;
|
|
1431
|
+
if (filter.id === "listing_type" && (filter.options?.length ?? 0) <= 1) {
|
|
1432
|
+
return false;
|
|
1530
1433
|
}
|
|
1434
|
+
return true;
|
|
1531
1435
|
});
|
|
1532
1436
|
}
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
return typeof value === "string" ? value.trim() : "";
|
|
1437
|
+
function toolbarFilterIds(schema) {
|
|
1438
|
+
const visible = new Set(visibleSearchFilters(schema).map((f) => f.id));
|
|
1439
|
+
return TOOLBAR_PRIMARY_FILTER_IDS.filter((id) => visible.has(id));
|
|
1537
1440
|
}
|
|
1538
|
-
function
|
|
1539
|
-
|
|
1441
|
+
function countOptionLabel(option) {
|
|
1442
|
+
const label = String(option?.label ?? "");
|
|
1443
|
+
if (/^[1-9]\d*$/.test(label)) return `${label}+`;
|
|
1444
|
+
return label;
|
|
1540
1445
|
}
|
|
1541
|
-
function
|
|
1542
|
-
const
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
}
|
|
1557
|
-
if (text(address?.postalCode).replace(/\D/g, "").length !== 8) {
|
|
1558
|
-
errors.postalCode = "Informe um CEP com 8 d\xEDgitos.";
|
|
1446
|
+
function countFacetChoices(options) {
|
|
1447
|
+
const list = options || [];
|
|
1448
|
+
const zero = list.find((o) => o.id === "0" || o.label === "Studio");
|
|
1449
|
+
const isStudio = Boolean(
|
|
1450
|
+
zero && /studio/i.test(String(zero.label)) && zero.id === "0"
|
|
1451
|
+
);
|
|
1452
|
+
const max = isStudio ? 3 : 4;
|
|
1453
|
+
const out = [];
|
|
1454
|
+
if (zero) out.push({ id: zero.id, label: countOptionLabel(zero) });
|
|
1455
|
+
for (let n = 1; n <= max; n += 1) {
|
|
1456
|
+
const option = list.find((o) => o.id === String(n));
|
|
1457
|
+
out.push({
|
|
1458
|
+
id: String(n),
|
|
1459
|
+
label: countOptionLabel(option || { label: String(n) })
|
|
1460
|
+
});
|
|
1559
1461
|
}
|
|
1560
|
-
return
|
|
1462
|
+
return out;
|
|
1561
1463
|
}
|
|
1562
|
-
var
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
if (!
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
});
|
|
1464
|
+
var FEMININE_HEADING = /(casa|cobertura|kitnet|loja|sala|fazenda|chácara|chacara)s?$/i;
|
|
1465
|
+
function pluralizePt(label) {
|
|
1466
|
+
const text2 = label.trim();
|
|
1467
|
+
if (!text2 || /s$/i.test(text2)) return text2;
|
|
1468
|
+
if (/il$/i.test(text2)) return `${text2.slice(0, -1)}is`;
|
|
1469
|
+
if (/m$/i.test(text2)) return `${text2.slice(0, -1)}ns`;
|
|
1470
|
+
return `${text2}s`;
|
|
1471
|
+
}
|
|
1472
|
+
function headingLocationSuffix(location) {
|
|
1473
|
+
if (!location) return "";
|
|
1474
|
+
if (location.street && location.neighborhood) {
|
|
1475
|
+
return `${location.street}, ${location.neighborhood}`;
|
|
1575
1476
|
}
|
|
1576
|
-
if (
|
|
1577
|
-
|
|
1578
|
-
code: "invalid_photo"
|
|
1579
|
-
});
|
|
1477
|
+
if (location.neighborhood && location.city) {
|
|
1478
|
+
return `${location.neighborhood}, ${location.city}`;
|
|
1580
1479
|
}
|
|
1581
|
-
if (
|
|
1582
|
-
|
|
1583
|
-
code: "invalid_photo"
|
|
1584
|
-
});
|
|
1480
|
+
if (location.city && location.state) {
|
|
1481
|
+
return `${location.city} - ${location.state}`;
|
|
1585
1482
|
}
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
let
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
});
|
|
1597
|
-
} catch (error) {
|
|
1598
|
-
throw new LeadSubmitError(
|
|
1599
|
-
error instanceof Error ? error.message : "Garagem SDK: network error.",
|
|
1600
|
-
{ code: "network" }
|
|
1483
|
+
return location.city || location.neighborhood || location.street || location.state || "";
|
|
1484
|
+
}
|
|
1485
|
+
function searchResultsHeading(pathFilters, dictionary, locationNames) {
|
|
1486
|
+
const types = [].concat(pathFilters.propertyType || []).filter(Boolean);
|
|
1487
|
+
let noun = "Im\xF3veis";
|
|
1488
|
+
let found = "encontrados";
|
|
1489
|
+
if (types.length === 1) {
|
|
1490
|
+
const id = String(types[0]);
|
|
1491
|
+
const option = dictionary?.propertyTypes?.find(
|
|
1492
|
+
(entry) => entry.id === id || entry.slug === id
|
|
1601
1493
|
);
|
|
1494
|
+
const label = option?.label;
|
|
1495
|
+
if (label) {
|
|
1496
|
+
noun = pluralizePt(label.charAt(0).toUpperCase() + label.slice(1));
|
|
1497
|
+
if (FEMININE_HEADING.test(id) || FEMININE_HEADING.test(label)) {
|
|
1498
|
+
found = "encontradas";
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1602
1501
|
}
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
}
|
|
1609
|
-
const data = await response.json().catch(() => ({}));
|
|
1610
|
-
if (!response.ok || typeof data.url !== "string" || !data.url) {
|
|
1611
|
-
throw new LeadSubmitError(
|
|
1612
|
-
`Garagem SDK: photo upload failed (${response.status}).`,
|
|
1613
|
-
{
|
|
1614
|
-
code: response.status === 400 ? "invalid_photo" : "http",
|
|
1615
|
-
status: response.status
|
|
1616
|
-
}
|
|
1617
|
-
);
|
|
1618
|
-
}
|
|
1619
|
-
return data.url;
|
|
1620
|
-
}
|
|
1621
|
-
var STUDIO_DEFAULT_PHOTO_SCHEDULE_CONFIG = {
|
|
1622
|
-
disabledDays: [0, 6],
|
|
1623
|
-
weekdayTimeSlots: [
|
|
1624
|
-
"09:00",
|
|
1625
|
-
"10:00",
|
|
1626
|
-
"11:00",
|
|
1627
|
-
"14:00",
|
|
1628
|
-
"15:00",
|
|
1629
|
-
"16:00",
|
|
1630
|
-
"17:00"
|
|
1631
|
-
],
|
|
1632
|
-
weekendTimeSlots: ["10:00", "11:00", "14:00", "15:00", "16:00"]
|
|
1633
|
-
};
|
|
1634
|
-
function sellerPhotoSchedule(config = STUDIO_DEFAULT_PHOTO_SCHEDULE_CONFIG) {
|
|
1635
|
-
const weekdayTimeSlots = [...config.weekdayTimeSlots].sort();
|
|
1636
|
-
const weekendTimeSlots = [...config.weekendTimeSlots].sort();
|
|
1637
|
-
const hours = (slots) => slots.length > 0 ? { start: slots[0], end: slots[slots.length - 1] } : null;
|
|
1638
|
-
return {
|
|
1639
|
-
timeZone: VISIT_TIME_ZONE,
|
|
1640
|
-
saturday: !config.disabledDays.includes(6),
|
|
1641
|
-
sunday: !config.disabledDays.includes(0),
|
|
1642
|
-
weekday: hours(weekdayTimeSlots) ?? { start: "09:00", end: "09:00" },
|
|
1643
|
-
weekend: hours(weekendTimeSlots),
|
|
1644
|
-
minHoursAhead: 2,
|
|
1645
|
-
disabledDays: [...config.disabledDays],
|
|
1646
|
-
weekdayTimeSlots,
|
|
1647
|
-
weekendTimeSlots,
|
|
1648
|
-
timeSlots: Array.from(
|
|
1649
|
-
/* @__PURE__ */ new Set([...weekdayTimeSlots, ...weekendTimeSlots])
|
|
1650
|
-
).sort()
|
|
1651
|
-
};
|
|
1502
|
+
const place = locationNames ? headingLocationSuffix(
|
|
1503
|
+
displayPathLocation(pathFilters.location, locationNames)
|
|
1504
|
+
) : "";
|
|
1505
|
+
if (place) return `${noun} ${found} em ${place}`;
|
|
1506
|
+
return `${noun} ${found}`;
|
|
1652
1507
|
}
|
|
1653
|
-
function
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
});
|
|
1508
|
+
function hrefWithExplicitPage(href, page) {
|
|
1509
|
+
if (page !== 1 || /(?:\?|&)page=/.test(href)) return href;
|
|
1510
|
+
return href.includes("?") ? `${href}&page=1` : `${href}?page=1`;
|
|
1657
1511
|
}
|
|
1658
|
-
function
|
|
1659
|
-
|
|
1660
|
-
const
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
const
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
}
|
|
1667
|
-
return { name, email, phone };
|
|
1512
|
+
function paginationPages(currentPage, totalPages, padding) {
|
|
1513
|
+
if (totalPages < 1) return [];
|
|
1514
|
+
const current = Math.min(Math.max(1, currentPage), totalPages);
|
|
1515
|
+
const start = Math.max(1, current - padding);
|
|
1516
|
+
const end = Math.min(totalPages, current + padding);
|
|
1517
|
+
const pages = [];
|
|
1518
|
+
for (let i = start; i <= end; i += 1) pages.push(i);
|
|
1519
|
+
return pages;
|
|
1668
1520
|
}
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
const
|
|
1672
|
-
|
|
1673
|
-
throw new LeadSubmitError(`Garagem SDK: ${first}`, {
|
|
1674
|
-
code: "invalid_address"
|
|
1675
|
-
});
|
|
1676
|
-
}
|
|
1677
|
-
const optional = (value) => text(value) ? { value: text(value) } : null;
|
|
1678
|
-
const number = address.noNumber ? null : optional(address.number);
|
|
1679
|
-
const bloco = address.noBlocoTorre ? null : optional(address.blocoTorre);
|
|
1680
|
-
const unidade = address.noUnidade ? null : optional(address.unidade);
|
|
1521
|
+
var SEARCH_EMPTY_COPY = "Nenhum im\xF3vel encontrado. Ajuste a busca ou os filtros.";
|
|
1522
|
+
function rangeDraftFromPath(pathFilters) {
|
|
1523
|
+
const price = pathFilters.price || {};
|
|
1524
|
+
const area = pathFilters.area || {};
|
|
1681
1525
|
return {
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
latitude: address.latitude,
|
|
1691
|
-
longitude: address.longitude,
|
|
1692
|
-
...bloco ? { blocoTorre: bloco.value } : {},
|
|
1693
|
-
...unidade ? { unidade: unidade.value } : {},
|
|
1694
|
-
noNumber: address.noNumber === true,
|
|
1695
|
-
noBlocoTorre: address.noBlocoTorre === true,
|
|
1696
|
-
noUnidade: address.noUnidade === true
|
|
1526
|
+
price: {
|
|
1527
|
+
min: price.min != null ? formatGroupedInteger(price.min) : "",
|
|
1528
|
+
max: price.max != null ? formatGroupedInteger(price.max) : ""
|
|
1529
|
+
},
|
|
1530
|
+
property_area_total: {
|
|
1531
|
+
min: area.min != null ? String(area.min) : "",
|
|
1532
|
+
max: area.max != null ? String(area.max) : ""
|
|
1533
|
+
}
|
|
1697
1534
|
};
|
|
1698
1535
|
}
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
"suites",
|
|
1703
|
-
"parkingSpaces"
|
|
1704
|
-
];
|
|
1705
|
-
var AMOUNT_FIELDS = [
|
|
1706
|
-
"saleValue",
|
|
1707
|
-
"rentValue",
|
|
1708
|
-
"condoFee",
|
|
1709
|
-
"totalArea"
|
|
1710
|
-
];
|
|
1711
|
-
function propertyError(message) {
|
|
1712
|
-
return new LeadSubmitError(`Garagem SDK: ${message}`, {
|
|
1713
|
-
code: "invalid_property"
|
|
1714
|
-
});
|
|
1715
|
-
}
|
|
1716
|
-
function normalizeProperty(property) {
|
|
1717
|
-
if (!["sale", "rent", "both"].includes(property?.businessType)) {
|
|
1718
|
-
throw propertyError("businessType must be sale, rent or both.");
|
|
1719
|
-
}
|
|
1720
|
-
for (const field of COUNT_FIELDS) {
|
|
1721
|
-
const value = property[field];
|
|
1722
|
-
if (value != null && (!Number.isInteger(value) || value < 0 || value > 999)) {
|
|
1723
|
-
throw propertyError(`${field} must be a whole number.`);
|
|
1724
|
-
}
|
|
1725
|
-
}
|
|
1726
|
-
for (const field of AMOUNT_FIELDS) {
|
|
1727
|
-
const value = property[field];
|
|
1728
|
-
if (value != null && (!Number.isFinite(value) || value < 0 || value > 1e12)) {
|
|
1729
|
-
throw propertyError(`${field} must be a non-negative number.`);
|
|
1730
|
-
}
|
|
1731
|
-
}
|
|
1732
|
-
const sale = property.businessType === "rent" ? void 0 : property.saleValue;
|
|
1733
|
-
const rent = property.businessType === "sale" ? void 0 : property.rentValue;
|
|
1734
|
-
const price = property.businessType === "rent" ? rent : sale;
|
|
1735
|
-
const counts = Object.fromEntries(
|
|
1736
|
-
COUNT_FIELDS.filter((field) => property[field] != null).map((field) => [
|
|
1737
|
-
field,
|
|
1738
|
-
property[field]
|
|
1739
|
-
])
|
|
1740
|
-
);
|
|
1536
|
+
function searchChromeModel(schema, pathFilters, locationNames) {
|
|
1537
|
+
const filters = visibleSearchFilters(schema);
|
|
1538
|
+
const toolbarIds = new Set(toolbarFilterIds(schema));
|
|
1741
1539
|
return {
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1540
|
+
headingTitle: searchResultsHeading(
|
|
1541
|
+
pathFilters,
|
|
1542
|
+
schema?.dictionary,
|
|
1543
|
+
locationNames
|
|
1544
|
+
),
|
|
1545
|
+
toolbarFilters: filters.filter((filter) => toolbarIds.has(filter.id)),
|
|
1546
|
+
extraFilters: filters.filter((filter) => !toolbarIds.has(filter.id)),
|
|
1547
|
+
sortOptions: searchSortOptions(schema?.sorts)
|
|
1748
1548
|
};
|
|
1749
1549
|
}
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
const trimmed = url.trim();
|
|
1759
|
-
if (!trimmed.startsWith("https://")) {
|
|
1760
|
-
throw new LeadSubmitError("Garagem SDK: photo URL must be https.", {
|
|
1761
|
-
code: "invalid_photo"
|
|
1762
|
-
});
|
|
1763
|
-
}
|
|
1764
|
-
return trimmed;
|
|
1765
|
-
});
|
|
1550
|
+
|
|
1551
|
+
// src/analytics.ts
|
|
1552
|
+
var SITE_ANALYTICS_EVENT = "garagem:site-event";
|
|
1553
|
+
function emitSiteEvent(event, properties) {
|
|
1554
|
+
if (typeof window === "undefined") return;
|
|
1555
|
+
window.dispatchEvent(
|
|
1556
|
+
new CustomEvent(SITE_ANALYTICS_EVENT, { detail: { event, properties } })
|
|
1557
|
+
);
|
|
1766
1558
|
}
|
|
1767
|
-
function
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
)
|
|
1777
|
-
|
|
1778
|
-
|
|
1559
|
+
function catalogBusinessType(value) {
|
|
1560
|
+
return value === "sale" || value === "rental" ? value : void 0;
|
|
1561
|
+
}
|
|
1562
|
+
function trackListingView(listing) {
|
|
1563
|
+
if (!listing?.id) return;
|
|
1564
|
+
emitSiteEvent("property_viewed", {
|
|
1565
|
+
property_id: listing.id,
|
|
1566
|
+
listing_code: listing.listingCode ?? void 0,
|
|
1567
|
+
property_type: listing.property?.type || void 0,
|
|
1568
|
+
business_type: catalogBusinessType(listing.businessType),
|
|
1569
|
+
location_city: listing.location?.city || void 0,
|
|
1570
|
+
location_state: listing.location?.state || void 0,
|
|
1571
|
+
location_neighborhood: listing.location?.neighborhood || void 0
|
|
1572
|
+
});
|
|
1779
1573
|
}
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
const photoScheduling = normalizePhotoSession(input);
|
|
1786
|
-
return postSiteLead({
|
|
1787
|
-
siteId: input.siteId,
|
|
1788
|
-
baseUrl: input.baseUrl,
|
|
1789
|
-
fetch: input.fetch,
|
|
1790
|
-
publishableKey: input.publishableKey,
|
|
1791
|
-
body: {
|
|
1792
|
-
source: "site-sdk",
|
|
1793
|
-
leadType: "seller_lead",
|
|
1794
|
-
...owner,
|
|
1795
|
-
address,
|
|
1796
|
-
...property,
|
|
1797
|
-
...photos ? { photos } : {},
|
|
1798
|
-
...photoScheduling ? { photoScheduling } : {},
|
|
1799
|
-
...input.visitorId ? { visitorId: input.visitorId } : {},
|
|
1800
|
-
...input.brokerRef ? { brokerRef: input.brokerRef } : {},
|
|
1801
|
-
...input.referrer ? { referrer: input.referrer } : {}
|
|
1802
|
-
}
|
|
1574
|
+
function trackLeadGenerated(leadType, listingId) {
|
|
1575
|
+
emitSiteEvent("lead_generated", {
|
|
1576
|
+
lead_type: leadType,
|
|
1577
|
+
property_id: listingId,
|
|
1578
|
+
form_location: "property_page"
|
|
1803
1579
|
});
|
|
1804
1580
|
}
|
|
1805
1581
|
|
|
1806
|
-
// src/
|
|
1807
|
-
var
|
|
1808
|
-
|
|
1809
|
-
|
|
1582
|
+
// src/schedule.ts
|
|
1583
|
+
var VISIT_TIME_ZONE = "America/Sao_Paulo";
|
|
1584
|
+
var HHMM_RE = /^([01]\d|2[0-3]):([0-5]\d)$/;
|
|
1585
|
+
var VISIT_TIME_RE = /^([01]\d|2[0-3]):([0-5]\d)(?::[0-5]\d(?:\.\d+)?)?$/;
|
|
1586
|
+
var YMD_RE = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
1587
|
+
var ISO_INSTANT_RE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/;
|
|
1588
|
+
var DATETIME_LOCAL_RE = /^(\d{4}-\d{2}-\d{2})T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?$/;
|
|
1589
|
+
var WEEKDAY_SHORT = {
|
|
1590
|
+
Sun: 0,
|
|
1591
|
+
Mon: 1,
|
|
1592
|
+
Tue: 2,
|
|
1593
|
+
Wed: 3,
|
|
1594
|
+
Thu: 4,
|
|
1595
|
+
Fri: 5,
|
|
1596
|
+
Sat: 6
|
|
1810
1597
|
};
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
// Amenities
|
|
1814
|
-
arCondicionado: "Ar condicionado",
|
|
1815
|
-
banheira: "Banheira",
|
|
1816
|
-
carregadorEletrico: "Carregador el\xE9trico",
|
|
1817
|
-
churrasqueira: "Churrasqueira",
|
|
1818
|
-
chuveiroGas: "Chuveiro a g\xE1s",
|
|
1819
|
-
chuveiroEletrico: "Chuveiro el\xE9trico",
|
|
1820
|
-
energiaSolar: "Energia solar",
|
|
1821
|
-
fechaduraDigital: "Fechadura digital",
|
|
1822
|
-
fechaduraEletronica: "Fechadura eletr\xF4nica",
|
|
1823
|
-
geradorEletrico: "Gerador el\xE9trico",
|
|
1824
|
-
gesso: "Gesso",
|
|
1825
|
-
hidromassagem: "Hidromassagem",
|
|
1826
|
-
lareira: "Lareira",
|
|
1827
|
-
ofuro: "Ofur\xF4",
|
|
1828
|
-
spa: "Spa",
|
|
1829
|
-
painelSolar: "Painel solar",
|
|
1830
|
-
portaoEletronico: "Port\xE3o eletr\xF4nico",
|
|
1831
|
-
sistemaAlarme: "Sistema de alarme",
|
|
1832
|
-
homeTheater: "Home theater",
|
|
1833
|
-
adega: "Adega",
|
|
1834
|
-
split: "Split",
|
|
1835
|
-
arCentral: "Ar central",
|
|
1836
|
-
esperaSplit: "Espera para split",
|
|
1837
|
-
vistaMar: "Vista para o mar",
|
|
1838
|
-
vistaPanoramica: "Vista panor\xE2mica",
|
|
1839
|
-
aguaQuente: "\xC1gua quente",
|
|
1840
|
-
reformado: "Reformado",
|
|
1841
|
-
tvCabo: "TV a cabo",
|
|
1842
|
-
gradeado: "Gradeado",
|
|
1843
|
-
antenaParabolica: "Antena parab\xF3lica",
|
|
1844
|
-
aquecimento: "Aquecimento",
|
|
1845
|
-
aquecimentoEletrico: "Aquecimento el\xE9trico",
|
|
1846
|
-
aquecimentoCentral: "Aquecimento central",
|
|
1847
|
-
cercaEletrica: "Cerca el\xE9trica",
|
|
1848
|
-
monitoramento: "Monitoramento",
|
|
1849
|
-
vigiaInterno: "Vigia interno",
|
|
1850
|
-
vigiaExterno: "Vigia externo",
|
|
1851
|
-
alarme: "Alarme",
|
|
1852
|
-
agua: "\xC1gua",
|
|
1853
|
-
redeEsgoto: "Rede de esgoto",
|
|
1854
|
-
pavimentacao: "Pavimenta\xE7\xE3o",
|
|
1855
|
-
energiaEletrica: "Energia el\xE9trica",
|
|
1856
|
-
// Furniture
|
|
1857
|
-
mobiliado: "Mobiliado",
|
|
1858
|
-
armarioEmbutido: "Arm\xE1rio embutido",
|
|
1859
|
-
armarioEmbutidoQuarto: "Arm\xE1rio embutido quarto",
|
|
1860
|
-
armarioCozinha: "Arm\xE1rio cozinha",
|
|
1861
|
-
armarioBanheiro: "Arm\xE1rio banheiro",
|
|
1862
|
-
cozinhaPlanejada: "Cozinha planejada",
|
|
1863
|
-
fogao: "Fog\xE3o",
|
|
1864
|
-
fornoPizza: "Forno de pizza",
|
|
1865
|
-
freezer: "Freezer",
|
|
1866
|
-
dormitorioComArmario: "Dormit\xF3rio com arm\xE1rio",
|
|
1867
|
-
semiMobiliado: "Semi mobiliado",
|
|
1868
|
-
salaArmarios: "Sala com arm\xE1rios",
|
|
1869
|
-
// Structure
|
|
1870
|
-
piscina: "Piscina",
|
|
1871
|
-
piscinaAquecida: "Piscina aquecida",
|
|
1872
|
-
piscinaCoberta: "Piscina coberta",
|
|
1873
|
-
poco: "Po\xE7o",
|
|
1874
|
-
pocoArtesiano: "Po\xE7o artesiano",
|
|
1875
|
-
bar: "Bar",
|
|
1876
|
-
jardim: "Jardim",
|
|
1877
|
-
lago: "Lago",
|
|
1878
|
-
lavabo: "Lavabo",
|
|
1879
|
-
quintal: "Quintal",
|
|
1880
|
-
solarium: "Solarium",
|
|
1881
|
-
quartoServico: "Quarto de servi\xE7o",
|
|
1882
|
-
varanda: "Varanda",
|
|
1883
|
-
varandaFechadaVidro: "Varanda fechada com vidro",
|
|
1884
|
-
varandaGourmet: "Varanda gourmet",
|
|
1885
|
-
banheiroServico: "Banheiro de servi\xE7o",
|
|
1886
|
-
areaServico: "\xC1rea de servi\xE7o",
|
|
1887
|
-
cinema: "Cinema",
|
|
1888
|
-
closet: "Closet",
|
|
1889
|
-
cozinhaAmericana: "Cozinha americana",
|
|
1890
|
-
cozinhaGourmet: "Cozinha gourmet",
|
|
1891
|
-
despensa: "Despensa",
|
|
1892
|
-
escritorio: "Escrit\xF3rio",
|
|
1893
|
-
edicula: "Ed\xEDcula",
|
|
1894
|
-
horta: "Horta",
|
|
1895
|
-
sacada: "Sacada",
|
|
1896
|
-
salaJantar: "Sala de jantar",
|
|
1897
|
-
cozinha: "Cozinha",
|
|
1898
|
-
banheiroSocial: "Banheiro social",
|
|
1899
|
-
terraco: "Terra\xE7o",
|
|
1900
|
-
copa: "Copa",
|
|
1901
|
-
suiteMaster: "Su\xEDte master",
|
|
1902
|
-
wcEmpregada: "WC empregada",
|
|
1903
|
-
dependenciaEmpregada: "Depend\xEAncia de empregada",
|
|
1904
|
-
dependenciadeEmpregada: "Depend\xEAncia empregada",
|
|
1905
|
-
salaTv: "Sala de TV",
|
|
1906
|
-
copaCozinha: "Copa cozinha",
|
|
1907
|
-
sacadaComChurrasqueira: "Sacada com churrasqueira",
|
|
1908
|
-
hallPrivativo: "Hall privativo",
|
|
1909
|
-
estarIntimo: "Estar \xEDntimo",
|
|
1910
|
-
livingHall: "Living hall",
|
|
1911
|
-
piscinaInterna: "Piscina interna",
|
|
1912
|
-
deck: "Deck",
|
|
1913
|
-
jardimInverno: "Jardim de inverno",
|
|
1914
|
-
rouparia: "Rouparia",
|
|
1915
|
-
living: "Living",
|
|
1916
|
-
familyRoom: "Family room",
|
|
1917
|
-
salafitness: "Sala fitness",
|
|
1918
|
-
salaEstar: "Sala de estar",
|
|
1919
|
-
mezanino: "Mezanino",
|
|
1920
|
-
pisoElevado: "Piso elevado",
|
|
1921
|
-
entradaServicoIndependente: "Entrada de servi\xE7o independente",
|
|
1922
|
-
forro: "Forro",
|
|
1923
|
-
vitrine: "Vitrine",
|
|
1924
|
-
banheiroAuxiliar: "Banheiro auxiliar",
|
|
1925
|
-
gabinete: "Gabinete",
|
|
1926
|
-
quadraTenisPrivativa: "Quadra de t\xEAnis privativa",
|
|
1927
|
-
porao: "Por\xE3o",
|
|
1928
|
-
sotao: "S\xF3t\xE3o",
|
|
1929
|
-
patio: "P\xE1tio",
|
|
1930
|
-
canaletasNoRodape: "Canaletas no rodap\xE9",
|
|
1931
|
-
// Accessibility
|
|
1932
|
-
barraApoioVaso: "Barra de apoio vaso",
|
|
1933
|
-
barraApoioChuveiro: "Barra de apoio chuveiro",
|
|
1934
|
-
entradaSemDegrau: "Entrada sem degrau",
|
|
1935
|
-
rampasAcesso: "Rampas de acesso",
|
|
1936
|
-
vagaDeficientes: "Vaga para deficientes",
|
|
1937
|
-
// Flooring
|
|
1938
|
-
cimentoQueimado: "Cimento queimado",
|
|
1939
|
-
madeira: "Madeira",
|
|
1940
|
-
pisoFrio: "Piso frio",
|
|
1941
|
-
laminado: "Laminado",
|
|
1942
|
-
vinilico: "Vin\xEDlico",
|
|
1943
|
-
porcelanato: "Porcelanato",
|
|
1944
|
-
// ==================== BUILDING FEATURES ====================
|
|
1945
|
-
// Amenities
|
|
1946
|
-
elevador: "Elevador",
|
|
1947
|
-
bicicletario: "Biciclet\xE1rio",
|
|
1948
|
-
carregadorEletronico: "Carregador eletr\xF4nico",
|
|
1949
|
-
concierge: "Concierge",
|
|
1950
|
-
coworking: "Coworking",
|
|
1951
|
-
deposito: "Dep\xF3sito",
|
|
1952
|
-
lavanderia: "Lavanderia",
|
|
1953
|
-
petPlace: "Pet place",
|
|
1954
|
-
recebimentoEncomendas: "Recebimento de encomendas",
|
|
1955
|
-
salaReuniao: "Sala de reuni\xE3o",
|
|
1956
|
-
salaoFestas: "Sal\xE3o de festas",
|
|
1957
|
-
valet: "Valet",
|
|
1958
|
-
garagemCoberta: "Garagem coberta",
|
|
1959
|
-
elevadorServico: "Elevador de servi\xE7o",
|
|
1960
|
-
// Leisure
|
|
1961
|
-
academia: "Academia",
|
|
1962
|
-
campoFutebol: "Campo de futebol",
|
|
1963
|
-
espacoGourmet: "Espa\xE7o gourmet",
|
|
1964
|
-
piscinaInfantil: "Piscina infantil",
|
|
1965
|
-
pistaCaminhada: "Pista de caminhada",
|
|
1966
|
-
playground: "Playground",
|
|
1967
|
-
quadraPoliesportiva: "Quadra poliesportiva",
|
|
1968
|
-
quadraTenis: "Quadra de t\xEAnis",
|
|
1969
|
-
salaJogos: "Sala de jogos",
|
|
1970
|
-
salaVapor: "Sala de vapor",
|
|
1971
|
-
sauna: "Sauna",
|
|
1972
|
-
// Security
|
|
1973
|
-
circuitoTv: "Circuito fechado de TV",
|
|
1974
|
-
controleAcessoEletronico: "Controle de acesso eletr\xF4nico",
|
|
1975
|
-
interfone: "Interfone",
|
|
1976
|
-
portaria24h: "Portaria 24h",
|
|
1977
|
-
porteiroFisico: "Porteiro f\xEDsico",
|
|
1978
|
-
seguranca24h: "Seguran\xE7a 24h",
|
|
1979
|
-
segurancaPatrimonial: "Seguran\xE7a patrimonial",
|
|
1980
|
-
condominioFechado: "Condom\xEDnio fechado",
|
|
1981
|
-
// Accessibility
|
|
1982
|
-
banheiroAcessivel: "Banheiro acess\xEDvel",
|
|
1983
|
-
elevadorAcessivel: "Elevador acess\xEDvel",
|
|
1984
|
-
pisoTatil: "Piso t\xE1til",
|
|
1985
|
-
// ==================== CANONICAL HAS*/IS* KEYS ====================
|
|
1986
|
-
has24hConcierge: "Portaria 24h",
|
|
1987
|
-
has24hSecurity: "Seguran\xE7a 24h",
|
|
1988
|
-
hasAccessRamps: "Rampas de acesso",
|
|
1989
|
-
hasAccessibleBathroom: "Banheiro acess\xEDvel",
|
|
1990
|
-
hasAccessibleElevator: "Elevador acess\xEDvel",
|
|
1991
|
-
hasAirConditioning: "Ar condicionado",
|
|
1992
|
-
hasAlarmSystem: "Sistema de alarme",
|
|
1993
|
-
hasBalcony: "Varanda",
|
|
1994
|
-
hasBikeStorage: "Biciclet\xE1rio",
|
|
1995
|
-
hasBuiltInWardrobe: "Arm\xE1rio embutido",
|
|
1996
|
-
hasCCTV: "CFTV",
|
|
1997
|
-
hasCloset: "Closet",
|
|
1998
|
-
hasConcierge: "Portaria",
|
|
1999
|
-
hasControlledAccess: "Condom\xEDnio fechado",
|
|
2000
|
-
hasCoworking: "Coworking",
|
|
2001
|
-
hasDisabledParking: "Vaga para deficientes",
|
|
2002
|
-
hasElectricCharger: "Carregador eletr\xF4nico",
|
|
2003
|
-
hasElectronicGate: "Port\xE3o eletr\xF4nico",
|
|
2004
|
-
hasElevator: "Elevador",
|
|
2005
|
-
hasFireplace: "Lareira",
|
|
2006
|
-
hasGarden: "Jardim",
|
|
2007
|
-
hasGasShower: "Chuveiro a g\xE1s",
|
|
2008
|
-
hasGenerator: "Gerador",
|
|
2009
|
-
hasGourmetBalcony: "Varanda gourmet",
|
|
2010
|
-
hasGourmetKitchen: "Cozinha gourmet",
|
|
2011
|
-
hasGrill: "Churrasqueira",
|
|
2012
|
-
hasGuestParking: "Estacionamento para visitantes",
|
|
2013
|
-
hasGym: "Academia",
|
|
2014
|
-
hasHeating: "Aquecimento",
|
|
2015
|
-
hasHomeOffice: "Home office",
|
|
2016
|
-
hasIntercom: "Interfone",
|
|
2017
|
-
hasJacuzzi: "Hidromassagem",
|
|
2018
|
-
hasKidsPool: "Piscina infantil",
|
|
2019
|
-
hasLaundry: "Lavanderia",
|
|
2020
|
-
hasMeetingRoom: "Sala de reuni\xE3o",
|
|
2021
|
-
hasOffice: "Escrit\xF3rio",
|
|
2022
|
-
hasOpenKitchen: "Cozinha americana",
|
|
2023
|
-
hasPackageReceival: "Recebimento de encomendas",
|
|
2024
|
-
hasPantry: "Despensa",
|
|
2025
|
-
hasParkingGarage: "Garagem coberta",
|
|
2026
|
-
hasPartySaloon: "Sal\xE3o de festas",
|
|
2027
|
-
hasPetArea: "Pet place",
|
|
2028
|
-
hasPipedGas: "G\xE1s encanado",
|
|
2029
|
-
hasPlayground: "Playground",
|
|
2030
|
-
hasPowderRoom: "Lavabo",
|
|
2031
|
-
hasPrivatePool: "Piscina privativa",
|
|
2032
|
-
hasSauna: "Sauna",
|
|
2033
|
-
hasSecurity: "Seguran\xE7a",
|
|
2034
|
-
hasServiceArea: "\xC1rea de servi\xE7o",
|
|
2035
|
-
hasSolarPanel: "Painel solar",
|
|
2036
|
-
hasSpa: "Spa",
|
|
2037
|
-
hasSportsCourt: "Quadra de esportes",
|
|
2038
|
-
hasStepFreeEntrance: "Entrada sem degrau",
|
|
2039
|
-
hasStorage: "Dep\xF3sito",
|
|
2040
|
-
hasSwimmingPool: "Piscina",
|
|
2041
|
-
hasTennisCourt: "Quadra de t\xEAnis",
|
|
2042
|
-
hasValetParking: "Valet",
|
|
2043
|
-
homeOffice: "Home office",
|
|
2044
|
-
isPetFriendly: "Pet friendly",
|
|
2045
|
-
isFurnished: "Mobiliado",
|
|
2046
|
-
isPartiallyFurnished: "Semi-mobiliado",
|
|
2047
|
-
petFriendly: "Pet friendly",
|
|
2048
|
-
piscinaPrivativa: "Piscina privativa",
|
|
2049
|
-
pisoLaminado: "Piso laminado",
|
|
2050
|
-
pisoMadeira: "Piso de madeira",
|
|
2051
|
-
pisoPorcelanato: "Piso porcelanato",
|
|
2052
|
-
quadraEsportes: "Quadra de esportes",
|
|
2053
|
-
rooftop: "Rooftop",
|
|
2054
|
-
suite: "Su\xEDte",
|
|
2055
|
-
triplex: "Triplex",
|
|
2056
|
-
duplex: "Duplex",
|
|
2057
|
-
cobertura: "Cobertura",
|
|
2058
|
-
forroGesso: "Forro de gesso",
|
|
2059
|
-
gerador: "Gerador",
|
|
2060
|
-
armariosCozinha: "Arm\xE1rios na cozinha",
|
|
2061
|
-
armariosQuarto: "Arm\xE1rios nos quartos",
|
|
2062
|
-
cftv: "CFTV"
|
|
2063
|
-
};
|
|
2064
|
-
function lookupLabel(id, options) {
|
|
2065
|
-
const fromDictionary = options?.find((option) => option.id === id)?.label;
|
|
2066
|
-
if (fromDictionary?.trim()) return fromDictionary.trim();
|
|
2067
|
-
return AMENITY_FALLBACK_LABELS[id];
|
|
1598
|
+
function pad2(value) {
|
|
1599
|
+
return String(value).padStart(2, "0");
|
|
2068
1600
|
}
|
|
2069
|
-
function
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
for (const id of ids) {
|
|
2074
|
-
if (!id) continue;
|
|
2075
|
-
const label = lookupLabel(id, dictionary);
|
|
2076
|
-
if (!label || seen.has(label)) continue;
|
|
2077
|
-
seen.add(label);
|
|
2078
|
-
labels.push(label);
|
|
2079
|
-
}
|
|
2080
|
-
return labels.sort((a, b) => a.localeCompare(b, "pt-BR"));
|
|
1601
|
+
function parseHHmm(value) {
|
|
1602
|
+
const match = HHMM_RE.exec(value);
|
|
1603
|
+
if (!match) return null;
|
|
1604
|
+
return { hour: Number(match[1]), minute: Number(match[2]) };
|
|
2081
1605
|
}
|
|
2082
|
-
function
|
|
2083
|
-
|
|
1606
|
+
function minutesOfDay(hhmm) {
|
|
1607
|
+
const parsed = parseHHmm(hhmm);
|
|
1608
|
+
if (!parsed) return null;
|
|
1609
|
+
return parsed.hour * 60 + parsed.minute;
|
|
2084
1610
|
}
|
|
2085
|
-
function
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
for (const id of unitIds) {
|
|
2089
|
-
unitCounts.set(id, (unitCounts.get(id) ?? 0) + 1);
|
|
2090
|
-
}
|
|
2091
|
-
return listing.amenities.filter((id) => {
|
|
2092
|
-
if (!id) return false;
|
|
2093
|
-
const count = unitCounts.get(id);
|
|
2094
|
-
if (count === void 0 || count === 0) return true;
|
|
2095
|
-
unitCounts.set(id, count - 1);
|
|
2096
|
-
return false;
|
|
2097
|
-
});
|
|
1611
|
+
function normalizeVisitTime(value) {
|
|
1612
|
+
const match = VISIT_TIME_RE.exec(value.trim());
|
|
1613
|
+
return match ? `${match[1]}:${match[2]}` : null;
|
|
2098
1614
|
}
|
|
2099
|
-
function
|
|
2100
|
-
|
|
2101
|
-
|
|
1615
|
+
function expandVisitTimeSlots(hours) {
|
|
1616
|
+
const start = minutesOfDay(hours.start);
|
|
1617
|
+
const end = minutesOfDay(hours.end);
|
|
1618
|
+
if (start == null || end == null || start > end) return [];
|
|
1619
|
+
const slots = [];
|
|
1620
|
+
for (let minutes = start; minutes <= end; minutes += 60) {
|
|
1621
|
+
const hour = Math.floor(minutes / 60);
|
|
1622
|
+
const minute = minutes % 60;
|
|
1623
|
+
slots.push(`${pad2(hour)}:${pad2(minute)}`);
|
|
2102
1624
|
}
|
|
2103
|
-
|
|
2104
|
-
listing.building?.amenities ?? listing.buildingAmenities ?? []
|
|
2105
|
-
);
|
|
2106
|
-
return (listing.amenities ?? []).filter((id) => id && !building.has(id));
|
|
1625
|
+
return slots;
|
|
2107
1626
|
}
|
|
2108
|
-
function
|
|
2109
|
-
|
|
2110
|
-
|
|
1627
|
+
function unionSorted(left, right) {
|
|
1628
|
+
return Array.from(/* @__PURE__ */ new Set([...left, ...right])).sort();
|
|
1629
|
+
}
|
|
1630
|
+
function expandVisitSchedule(config) {
|
|
1631
|
+
const weekendHours = config.weekend ?? (config.saturday || config.sunday ? config.weekday : null);
|
|
1632
|
+
const weekdayTimeSlots = expandVisitTimeSlots(config.weekday);
|
|
1633
|
+
const weekendTimeSlots = weekendHours ? expandVisitTimeSlots(weekendHours) : [];
|
|
1634
|
+
const disabledDays = [];
|
|
1635
|
+
if (!config.sunday) disabledDays.push(0);
|
|
1636
|
+
if (!config.saturday) disabledDays.push(6);
|
|
1637
|
+
return {
|
|
1638
|
+
...config,
|
|
1639
|
+
weekend: weekendHours,
|
|
1640
|
+
disabledDays,
|
|
1641
|
+
weekdayTimeSlots,
|
|
1642
|
+
weekendTimeSlots,
|
|
1643
|
+
timeSlots: unionSorted(weekdayTimeSlots, weekendTimeSlots)
|
|
1644
|
+
};
|
|
1645
|
+
}
|
|
1646
|
+
var STUDIO_DEFAULT_VISIT_SCHEDULE = expandVisitSchedule(
|
|
1647
|
+
{
|
|
1648
|
+
timeZone: VISIT_TIME_ZONE,
|
|
1649
|
+
saturday: false,
|
|
1650
|
+
sunday: false,
|
|
1651
|
+
weekday: { start: "06:00", end: "22:00" },
|
|
1652
|
+
weekend: null,
|
|
1653
|
+
minHoursAhead: 2
|
|
2111
1654
|
}
|
|
2112
|
-
|
|
2113
|
-
|
|
1655
|
+
);
|
|
1656
|
+
function zonedParts(date, timeZone) {
|
|
1657
|
+
const parts = new Intl.DateTimeFormat("en-US", {
|
|
1658
|
+
timeZone,
|
|
1659
|
+
weekday: "short",
|
|
1660
|
+
year: "numeric",
|
|
1661
|
+
month: "2-digit",
|
|
1662
|
+
day: "2-digit",
|
|
1663
|
+
hour: "2-digit",
|
|
1664
|
+
minute: "2-digit",
|
|
1665
|
+
hourCycle: "h23"
|
|
1666
|
+
}).formatToParts(date);
|
|
1667
|
+
const get = (type) => parts.find((part) => part.type === type)?.value ?? "";
|
|
1668
|
+
const weekday = WEEKDAY_SHORT[get("weekday")] ?? 0;
|
|
1669
|
+
return {
|
|
1670
|
+
year: Number(get("year")),
|
|
1671
|
+
month: Number(get("month")),
|
|
1672
|
+
day: Number(get("day")),
|
|
1673
|
+
hour: Number(get("hour")),
|
|
1674
|
+
minute: Number(get("minute")),
|
|
1675
|
+
weekday
|
|
1676
|
+
};
|
|
1677
|
+
}
|
|
1678
|
+
function calendarYmd(date, timeZone) {
|
|
1679
|
+
const parts = zonedParts(date, timeZone);
|
|
1680
|
+
return `${parts.year}-${pad2(parts.month)}-${pad2(parts.day)}`;
|
|
1681
|
+
}
|
|
1682
|
+
function parseYmd(value) {
|
|
1683
|
+
const match = YMD_RE.exec(value);
|
|
1684
|
+
if (!match) return null;
|
|
1685
|
+
const year = Number(match[1]);
|
|
1686
|
+
const month = Number(match[2]);
|
|
1687
|
+
const day = Number(match[3]);
|
|
1688
|
+
const utc = new Date(Date.UTC(year, month - 1, day));
|
|
1689
|
+
if (utc.getUTCFullYear() !== year || utc.getUTCMonth() !== month - 1 || utc.getUTCDate() !== day) {
|
|
1690
|
+
return null;
|
|
2114
1691
|
}
|
|
2115
|
-
return
|
|
1692
|
+
return { year, month, day };
|
|
2116
1693
|
}
|
|
2117
|
-
function
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
const buildingLabels = labelAmenities(
|
|
2129
|
-
buildingAmenityIds(listing),
|
|
2130
|
-
dictionary?.buildingAmenities
|
|
2131
|
-
);
|
|
2132
|
-
if (buildingLabels.length > 0) {
|
|
2133
|
-
groups.push({
|
|
2134
|
-
key: "building",
|
|
2135
|
-
title: dictionary?.amenitySectionTitles?.building ?? LISTING_AMENITY_TITLES.building,
|
|
2136
|
-
labels: buildingLabels
|
|
2137
|
-
});
|
|
1694
|
+
function normalizeVisitDate(date, timeZone = VISIT_TIME_ZONE) {
|
|
1695
|
+
if (typeof date === "string") {
|
|
1696
|
+
const trimmed = date.trim();
|
|
1697
|
+
if (parseYmd(trimmed)) return trimmed;
|
|
1698
|
+
if (ISO_INSTANT_RE.test(trimmed)) {
|
|
1699
|
+
const instant = new Date(trimmed);
|
|
1700
|
+
return Number.isFinite(instant.getTime()) ? calendarYmd(instant, timeZone) : null;
|
|
1701
|
+
}
|
|
1702
|
+
const local = DATETIME_LOCAL_RE.exec(trimmed);
|
|
1703
|
+
if (local && parseYmd(local[1])) return local[1];
|
|
1704
|
+
return null;
|
|
2138
1705
|
}
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
// src/presentation.ts
|
|
2143
|
-
function formatListingPrice(amount, locale = "pt-BR", currency = "BRL") {
|
|
2144
|
-
if (amount == null) return "Sob consulta";
|
|
2145
|
-
try {
|
|
2146
|
-
return new Intl.NumberFormat(locale, {
|
|
2147
|
-
style: "currency",
|
|
2148
|
-
currency,
|
|
2149
|
-
minimumFractionDigits: 0,
|
|
2150
|
-
maximumFractionDigits: 0
|
|
2151
|
-
}).format(amount);
|
|
2152
|
-
} catch {
|
|
2153
|
-
return `${currency} ${amount}`;
|
|
1706
|
+
if (date instanceof Date && Number.isFinite(date.getTime())) {
|
|
1707
|
+
return calendarYmd(date, timeZone);
|
|
2154
1708
|
}
|
|
1709
|
+
return null;
|
|
2155
1710
|
}
|
|
2156
|
-
function
|
|
2157
|
-
const
|
|
2158
|
-
if (!
|
|
2159
|
-
const
|
|
2160
|
-
|
|
2161
|
-
return new Intl.NumberFormat(locale, { maximumFractionDigits: 0 }).format(
|
|
2162
|
-
amount
|
|
1711
|
+
function weekdayOfYmd(ymd, timeZone) {
|
|
1712
|
+
const parsed = parseYmd(ymd);
|
|
1713
|
+
if (!parsed) return null;
|
|
1714
|
+
const utcNoonish = new Date(
|
|
1715
|
+
Date.UTC(parsed.year, parsed.month - 1, parsed.day, 15, 0, 0)
|
|
2163
1716
|
);
|
|
1717
|
+
return zonedParts(utcNoonish, timeZone).weekday;
|
|
2164
1718
|
}
|
|
2165
|
-
function
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
const
|
|
2170
|
-
if (
|
|
2171
|
-
|
|
2172
|
-
|
|
1719
|
+
function slotsForDate(schedule, date, now = /* @__PURE__ */ new Date()) {
|
|
1720
|
+
const timeZone = schedule.timeZone;
|
|
1721
|
+
const ymd = normalizeVisitDate(date, timeZone);
|
|
1722
|
+
if (!ymd) return [];
|
|
1723
|
+
const weekday = weekdayOfYmd(ymd, timeZone);
|
|
1724
|
+
if (weekday == null) return [];
|
|
1725
|
+
if (schedule.disabledDays.includes(weekday)) return [];
|
|
1726
|
+
if (weekday === 0 && !schedule.sunday) return [];
|
|
1727
|
+
if (weekday === 6 && !schedule.saturday) return [];
|
|
1728
|
+
const base = weekday === 0 || weekday === 6 ? schedule.weekendTimeSlots : schedule.weekdayTimeSlots;
|
|
1729
|
+
const today = calendarYmd(now, timeZone);
|
|
1730
|
+
if (ymd < today) return [];
|
|
1731
|
+
if (ymd !== today) return [...base];
|
|
1732
|
+
const nowParts = zonedParts(now, timeZone);
|
|
1733
|
+
const cutoff = nowParts.hour * 60 + nowParts.minute + schedule.minHoursAhead * 60;
|
|
1734
|
+
return base.filter((slot) => {
|
|
1735
|
+
const minutes = minutesOfDay(slot);
|
|
1736
|
+
return minutes != null && minutes >= cutoff;
|
|
1737
|
+
});
|
|
2173
1738
|
}
|
|
2174
|
-
function
|
|
2175
|
-
|
|
2176
|
-
return
|
|
1739
|
+
function isVisitSlotAllowed(schedule, visitDate, visitTime, now = /* @__PURE__ */ new Date()) {
|
|
1740
|
+
const time = normalizeVisitTime(visitTime);
|
|
1741
|
+
if (!time) return false;
|
|
1742
|
+
return slotsForDate(schedule, visitDate, now).includes(time);
|
|
2177
1743
|
}
|
|
2178
|
-
|
|
2179
|
-
|
|
1744
|
+
|
|
1745
|
+
// src/phone.ts
|
|
1746
|
+
var import_libphonenumber_js = require("libphonenumber-js");
|
|
1747
|
+
|
|
1748
|
+
// src/phone-countries.ts
|
|
1749
|
+
var DEFAULT_PHONE_COUNTRY_CODE = "BR";
|
|
1750
|
+
var PHONE_COUNTRIES = [
|
|
1751
|
+
{ code: "BR", name: "Brasil", dialCode: "55", flag: "\u{1F1E7}\u{1F1F7}" },
|
|
1752
|
+
{ code: "US", name: "Estados Unidos", dialCode: "1", flag: "\u{1F1FA}\u{1F1F8}" },
|
|
1753
|
+
{ code: "CA", name: "Canad\xE1", dialCode: "1", flag: "\u{1F1E8}\u{1F1E6}" },
|
|
1754
|
+
{ code: "MX", name: "M\xE9xico", dialCode: "52", flag: "\u{1F1F2}\u{1F1FD}" },
|
|
1755
|
+
{ code: "GT", name: "Guatemala", dialCode: "502", flag: "\u{1F1EC}\u{1F1F9}" },
|
|
1756
|
+
{ code: "BZ", name: "Belize", dialCode: "501", flag: "\u{1F1E7}\u{1F1FF}" },
|
|
1757
|
+
{ code: "SV", name: "El Salvador", dialCode: "503", flag: "\u{1F1F8}\u{1F1FB}" },
|
|
1758
|
+
{ code: "HN", name: "Honduras", dialCode: "504", flag: "\u{1F1ED}\u{1F1F3}" },
|
|
1759
|
+
{ code: "NI", name: "Nicar\xE1gua", dialCode: "505", flag: "\u{1F1F3}\u{1F1EE}" },
|
|
1760
|
+
{ code: "CR", name: "Costa Rica", dialCode: "506", flag: "\u{1F1E8}\u{1F1F7}" },
|
|
1761
|
+
{ code: "PA", name: "Panam\xE1", dialCode: "507", flag: "\u{1F1F5}\u{1F1E6}" },
|
|
1762
|
+
{ code: "CU", name: "Cuba", dialCode: "53", flag: "\u{1F1E8}\u{1F1FA}" },
|
|
1763
|
+
{ code: "DO", name: "Rep\xFAblica Dominicana", dialCode: "1", flag: "\u{1F1E9}\u{1F1F4}" },
|
|
1764
|
+
{ code: "HT", name: "Haiti", dialCode: "509", flag: "\u{1F1ED}\u{1F1F9}" },
|
|
1765
|
+
{ code: "AR", name: "Argentina", dialCode: "54", flag: "\u{1F1E6}\u{1F1F7}" },
|
|
1766
|
+
{ code: "CL", name: "Chile", dialCode: "56", flag: "\u{1F1E8}\u{1F1F1}" },
|
|
1767
|
+
{ code: "CO", name: "Col\xF4mbia", dialCode: "57", flag: "\u{1F1E8}\u{1F1F4}" },
|
|
1768
|
+
{ code: "PE", name: "Peru", dialCode: "51", flag: "\u{1F1F5}\u{1F1EA}" },
|
|
1769
|
+
{ code: "UY", name: "Uruguai", dialCode: "598", flag: "\u{1F1FA}\u{1F1FE}" },
|
|
1770
|
+
{ code: "PY", name: "Paraguai", dialCode: "595", flag: "\u{1F1F5}\u{1F1FE}" },
|
|
1771
|
+
{ code: "BO", name: "Bol\xEDvia", dialCode: "591", flag: "\u{1F1E7}\u{1F1F4}" },
|
|
1772
|
+
{ code: "EC", name: "Equador", dialCode: "593", flag: "\u{1F1EA}\u{1F1E8}" },
|
|
1773
|
+
{ code: "VE", name: "Venezuela", dialCode: "58", flag: "\u{1F1FB}\u{1F1EA}" },
|
|
1774
|
+
{ code: "GY", name: "Guiana", dialCode: "592", flag: "\u{1F1EC}\u{1F1FE}" },
|
|
1775
|
+
{ code: "SR", name: "Suriname", dialCode: "597", flag: "\u{1F1F8}\u{1F1F7}" },
|
|
1776
|
+
{ code: "PT", name: "Portugal", dialCode: "351", flag: "\u{1F1F5}\u{1F1F9}" },
|
|
1777
|
+
{ code: "ES", name: "Espanha", dialCode: "34", flag: "\u{1F1EA}\u{1F1F8}" },
|
|
1778
|
+
{ code: "FR", name: "Fran\xE7a", dialCode: "33", flag: "\u{1F1EB}\u{1F1F7}" },
|
|
1779
|
+
{ code: "UK", name: "Reino Unido", dialCode: "44", flag: "\u{1F1EC}\u{1F1E7}" },
|
|
1780
|
+
{ code: "DE", name: "Alemanha", dialCode: "49", flag: "\u{1F1E9}\u{1F1EA}" },
|
|
1781
|
+
{ code: "IT", name: "It\xE1lia", dialCode: "39", flag: "\u{1F1EE}\u{1F1F9}" },
|
|
1782
|
+
{ code: "NL", name: "Holanda", dialCode: "31", flag: "\u{1F1F3}\u{1F1F1}" },
|
|
1783
|
+
{ code: "BE", name: "B\xE9lgica", dialCode: "32", flag: "\u{1F1E7}\u{1F1EA}" },
|
|
1784
|
+
{ code: "CH", name: "Su\xED\xE7a", dialCode: "41", flag: "\u{1F1E8}\u{1F1ED}" },
|
|
1785
|
+
{ code: "AT", name: "\xC1ustria", dialCode: "43", flag: "\u{1F1E6}\u{1F1F9}" },
|
|
1786
|
+
{ code: "SE", name: "Su\xE9cia", dialCode: "46", flag: "\u{1F1F8}\u{1F1EA}" },
|
|
1787
|
+
{ code: "NO", name: "Noruega", dialCode: "47", flag: "\u{1F1F3}\u{1F1F4}" },
|
|
1788
|
+
{ code: "DK", name: "Dinamarca", dialCode: "45", flag: "\u{1F1E9}\u{1F1F0}" },
|
|
1789
|
+
{ code: "FI", name: "Finl\xE2ndia", dialCode: "358", flag: "\u{1F1EB}\u{1F1EE}" },
|
|
1790
|
+
{ code: "IE", name: "Irlanda", dialCode: "353", flag: "\u{1F1EE}\u{1F1EA}" },
|
|
1791
|
+
{ code: "AU", name: "Austr\xE1lia", dialCode: "61", flag: "\u{1F1E6}\u{1F1FA}" },
|
|
1792
|
+
{ code: "NZ", name: "Nova Zel\xE2ndia", dialCode: "64", flag: "\u{1F1F3}\u{1F1FF}" },
|
|
1793
|
+
{ code: "JP", name: "Jap\xE3o", dialCode: "81", flag: "\u{1F1EF}\u{1F1F5}" },
|
|
1794
|
+
{ code: "KR", name: "Coreia do Sul", dialCode: "82", flag: "\u{1F1F0}\u{1F1F7}" },
|
|
1795
|
+
{ code: "CN", name: "China", dialCode: "86", flag: "\u{1F1E8}\u{1F1F3}" },
|
|
1796
|
+
{ code: "IN", name: "\xCDndia", dialCode: "91", flag: "\u{1F1EE}\u{1F1F3}" },
|
|
1797
|
+
{ code: "RU", name: "R\xFAssia", dialCode: "7", flag: "\u{1F1F7}\u{1F1FA}" },
|
|
1798
|
+
{ code: "UA", name: "Ucr\xE2nia", dialCode: "380", flag: "\u{1F1FA}\u{1F1E6}" },
|
|
1799
|
+
{ code: "AE", name: "Emirados \xC1rabes", dialCode: "971", flag: "\u{1F1E6}\u{1F1EA}" },
|
|
1800
|
+
{ code: "SA", name: "Ar\xE1bia Saudita", dialCode: "966", flag: "\u{1F1F8}\u{1F1E6}" },
|
|
1801
|
+
{ code: "QA", name: "Catar", dialCode: "974", flag: "\u{1F1F6}\u{1F1E6}" },
|
|
1802
|
+
{ code: "KW", name: "Kuwait", dialCode: "965", flag: "\u{1F1F0}\u{1F1FC}" },
|
|
1803
|
+
{ code: "BH", name: "Bahrein", dialCode: "973", flag: "\u{1F1E7}\u{1F1ED}" },
|
|
1804
|
+
{ code: "OM", name: "Om\xE3", dialCode: "968", flag: "\u{1F1F4}\u{1F1F2}" },
|
|
1805
|
+
{ code: "JO", name: "Jord\xE2nia", dialCode: "962", flag: "\u{1F1EF}\u{1F1F4}" },
|
|
1806
|
+
{ code: "LB", name: "L\xEDbano", dialCode: "961", flag: "\u{1F1F1}\u{1F1E7}" },
|
|
1807
|
+
{ code: "IL", name: "Israel", dialCode: "972", flag: "\u{1F1EE}\u{1F1F1}" },
|
|
1808
|
+
{ code: "TR", name: "Turquia", dialCode: "90", flag: "\u{1F1F9}\u{1F1F7}" },
|
|
1809
|
+
{ code: "EG", name: "Egito", dialCode: "20", flag: "\u{1F1EA}\u{1F1EC}" },
|
|
1810
|
+
{ code: "ZA", name: "\xC1frica do Sul", dialCode: "27", flag: "\u{1F1FF}\u{1F1E6}" },
|
|
1811
|
+
{ code: "AO", name: "Angola", dialCode: "244", flag: "\u{1F1E6}\u{1F1F4}" },
|
|
1812
|
+
{ code: "MZ", name: "Mo\xE7ambique", dialCode: "258", flag: "\u{1F1F2}\u{1F1FF}" },
|
|
1813
|
+
{ code: "CV", name: "Cabo Verde", dialCode: "238", flag: "\u{1F1E8}\u{1F1FB}" }
|
|
1814
|
+
];
|
|
1815
|
+
function phoneCountrySearchValue(country) {
|
|
1816
|
+
return `${country.name} ${country.code} ${country.dialCode} +${country.dialCode}`;
|
|
1817
|
+
}
|
|
1818
|
+
function findPhoneCountry(code) {
|
|
1819
|
+
if (!code) return void 0;
|
|
1820
|
+
const normalized = code.trim().toUpperCase();
|
|
1821
|
+
return PHONE_COUNTRIES.find((country) => country.code === normalized);
|
|
1822
|
+
}
|
|
1823
|
+
function defaultPhoneCountry() {
|
|
1824
|
+
return findPhoneCountry(DEFAULT_PHONE_COUNTRY_CODE) ?? PHONE_COUNTRIES[0];
|
|
1825
|
+
}
|
|
1826
|
+
|
|
1827
|
+
// src/phone.ts
|
|
1828
|
+
var MAX_NATIONAL_PHONE_DIGITS = 15;
|
|
1829
|
+
var VALID_BR_DDDS = /* @__PURE__ */ new Set([
|
|
1830
|
+
"11",
|
|
1831
|
+
"12",
|
|
1832
|
+
"13",
|
|
1833
|
+
"14",
|
|
1834
|
+
"15",
|
|
1835
|
+
"16",
|
|
1836
|
+
"17",
|
|
1837
|
+
"18",
|
|
1838
|
+
"19",
|
|
1839
|
+
"21",
|
|
1840
|
+
"22",
|
|
1841
|
+
"24",
|
|
1842
|
+
"27",
|
|
1843
|
+
"28",
|
|
1844
|
+
"31",
|
|
1845
|
+
"32",
|
|
1846
|
+
"33",
|
|
1847
|
+
"34",
|
|
1848
|
+
"35",
|
|
1849
|
+
"37",
|
|
1850
|
+
"38",
|
|
1851
|
+
"41",
|
|
1852
|
+
"42",
|
|
1853
|
+
"43",
|
|
1854
|
+
"44",
|
|
1855
|
+
"45",
|
|
1856
|
+
"46",
|
|
1857
|
+
"47",
|
|
1858
|
+
"48",
|
|
1859
|
+
"49",
|
|
1860
|
+
"51",
|
|
1861
|
+
"53",
|
|
1862
|
+
"54",
|
|
1863
|
+
"55",
|
|
1864
|
+
"61",
|
|
1865
|
+
"62",
|
|
1866
|
+
"63",
|
|
1867
|
+
"64",
|
|
1868
|
+
"65",
|
|
1869
|
+
"66",
|
|
1870
|
+
"67",
|
|
1871
|
+
"68",
|
|
1872
|
+
"69",
|
|
1873
|
+
"71",
|
|
1874
|
+
"73",
|
|
1875
|
+
"74",
|
|
1876
|
+
"75",
|
|
1877
|
+
"77",
|
|
1878
|
+
"79",
|
|
1879
|
+
"81",
|
|
1880
|
+
"82",
|
|
1881
|
+
"83",
|
|
1882
|
+
"84",
|
|
1883
|
+
"85",
|
|
1884
|
+
"86",
|
|
1885
|
+
"87",
|
|
1886
|
+
"88",
|
|
1887
|
+
"89",
|
|
1888
|
+
"91",
|
|
1889
|
+
"92",
|
|
1890
|
+
"93",
|
|
1891
|
+
"94",
|
|
1892
|
+
"95",
|
|
1893
|
+
"96",
|
|
1894
|
+
"97",
|
|
1895
|
+
"98",
|
|
1896
|
+
"99"
|
|
1897
|
+
]);
|
|
1898
|
+
var PHONE_INPUT_COUNTRY_CODES = new Set(
|
|
1899
|
+
PHONE_COUNTRIES.map((country) => country.code)
|
|
1900
|
+
);
|
|
1901
|
+
var SORTED_PHONE_INPUT_DIAL_CODES = [
|
|
1902
|
+
...new Set(PHONE_COUNTRIES.map((country) => country.dialCode))
|
|
1903
|
+
].sort((a, b) => b.length - a.length);
|
|
1904
|
+
function toLibCountryCode(code) {
|
|
1905
|
+
if (code === "UK") return "GB";
|
|
1906
|
+
return code;
|
|
2180
1907
|
}
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
return [location.neighborhood, location.city, location.state].map((part) => part ? String(part).trim() : "").filter(Boolean).join(", ");
|
|
1908
|
+
function fromLibCountryCode(code) {
|
|
1909
|
+
if (code === "GB") return "UK";
|
|
1910
|
+
return code;
|
|
2185
1911
|
}
|
|
2186
|
-
function
|
|
2187
|
-
|
|
2188
|
-
const area = listing.property?.usableArea ?? listing.property?.totalArea;
|
|
2189
|
-
return {
|
|
2190
|
-
href: listingPublicPath(listing),
|
|
2191
|
-
title: listing.title,
|
|
2192
|
-
businessType: listing.businessType,
|
|
2193
|
-
businessLabel: listingBusinessLabel(listing.businessType),
|
|
2194
|
-
priceVisibility: listing.priceVisibility,
|
|
2195
|
-
price: listing.price,
|
|
2196
|
-
priceLabel: isPrivate ? "Sob consulta" : formatListingPrice(listing.price, "pt-BR", listing.currency ?? "BRL"),
|
|
2197
|
-
pricePeriod: listing.businessType === "rental" && !isPrivate && listing.price != null ? "/m\xEAs" : null,
|
|
2198
|
-
locationLabel: listingLocationLabel(listing.location || {}),
|
|
2199
|
-
propertyType: listing.property?.type ?? null,
|
|
2200
|
-
coverSrc: listing.coverImage?.src ?? null,
|
|
2201
|
-
coverAlt: listing.coverImage?.alt ?? listing.title,
|
|
2202
|
-
bedrooms: listing.property?.bedrooms ?? null,
|
|
2203
|
-
bathrooms: listing.property?.bathrooms ?? null,
|
|
2204
|
-
parkingSpaces: listing.property?.parkingSpaces ?? null,
|
|
2205
|
-
areaM2: area ?? null
|
|
2206
|
-
};
|
|
1912
|
+
function nationalPhoneDigits(value) {
|
|
1913
|
+
return String(value ?? "").replace(/\D/g, "");
|
|
2207
1914
|
}
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
var SEARCH_BASE_ROUTE = "imoveis";
|
|
2211
|
-
var MAX_PAGE = 1e4;
|
|
2212
|
-
var MAX_LOC_GROUPS = 20;
|
|
2213
|
-
var DEFAULT_MIN_PRICE = 0;
|
|
2214
|
-
var DEFAULT_MAX_PRICE = 1e9;
|
|
2215
|
-
var DEFAULT_MIN_AREA = 0;
|
|
2216
|
-
var DEFAULT_MAX_AREA = 1e5;
|
|
2217
|
-
var SORT_URL_TOKENS = [
|
|
2218
|
-
"recentes",
|
|
2219
|
-
"preco-asc",
|
|
2220
|
-
"preco-desc",
|
|
2221
|
-
"area-asc",
|
|
2222
|
-
"area-desc"
|
|
2223
|
-
];
|
|
2224
|
-
|
|
2225
|
-
// ../search-url/slugify.ts
|
|
2226
|
-
function slugifyForUrl(text2) {
|
|
2227
|
-
if (!text2) return "";
|
|
2228
|
-
const withDashes = text2.replace(/([a-z])([A-Z])/g, "$1-$2");
|
|
2229
|
-
return withDashes.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "").replace(/[^\w\s-]/g, "").replace(/\s+/g, "-").replace(/-+/g, "-").trim();
|
|
1915
|
+
function truncateNationalPhoneDigits(digits, max = MAX_NATIONAL_PHONE_DIGITS) {
|
|
1916
|
+
return digits.slice(0, max);
|
|
2230
1917
|
}
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
};
|
|
2236
|
-
function buildListingTypeOptions(enabled) {
|
|
2237
|
-
const flags = enabled ?? { sale: true, rental: true };
|
|
2238
|
-
const out = [];
|
|
2239
|
-
if (flags.sale !== false) {
|
|
2240
|
-
out.push({ id: "sale", slug: "venda", label: "Venda" });
|
|
1918
|
+
function collapseDuplicatedBrazilianMobileNine(digits) {
|
|
1919
|
+
if (digits.length === 14 && digits.startsWith("55")) {
|
|
1920
|
+
const national = collapseDuplicatedBrazilianMobileNine(digits.slice(2));
|
|
1921
|
+
return national === digits.slice(2) ? digits : `55${national}`;
|
|
2241
1922
|
}
|
|
2242
|
-
if (
|
|
2243
|
-
|
|
1923
|
+
if (digits.length !== 12) return digits;
|
|
1924
|
+
const ddd = digits.slice(0, 2);
|
|
1925
|
+
if (!VALID_BR_DDDS.has(ddd)) return digits;
|
|
1926
|
+
if (digits.charAt(2) !== "9") return digits;
|
|
1927
|
+
const rest = digits.slice(3);
|
|
1928
|
+
if (rest.length !== 9 || rest.charAt(0) !== "9") return digits;
|
|
1929
|
+
if (ddd === "55") {
|
|
1930
|
+
const subscriberFirst = digits.charAt(4);
|
|
1931
|
+
if (subscriberFirst >= "0" && subscriberFirst <= "5") {
|
|
1932
|
+
return digits;
|
|
1933
|
+
}
|
|
2244
1934
|
}
|
|
2245
|
-
return
|
|
2246
|
-
}
|
|
2247
|
-
function emptySearchUrlDictionary() {
|
|
2248
|
-
return {
|
|
2249
|
-
listingTypes: buildListingTypeOptions(null),
|
|
2250
|
-
propertyTypes: [],
|
|
2251
|
-
propertyFeatures: [],
|
|
2252
|
-
buildingAmenities: []
|
|
2253
|
-
};
|
|
2254
|
-
}
|
|
2255
|
-
function norm(value) {
|
|
2256
|
-
return slugifyForUrl(value) || value.toLowerCase();
|
|
1935
|
+
return `${ddd}${rest}`;
|
|
2257
1936
|
}
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
if (candidates.some((c) => norm(c) === n)) return option.id;
|
|
1937
|
+
var BR_DIAL_CODE = "55";
|
|
1938
|
+
function stripAccidentalDialCodePrefix(numbers, country) {
|
|
1939
|
+
const dial = country.dialCode;
|
|
1940
|
+
if (!numbers.startsWith(dial) || numbers.length <= dial.length) {
|
|
1941
|
+
return numbers;
|
|
2264
1942
|
}
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
1943
|
+
const withoutDial = numbers.slice(dial.length);
|
|
1944
|
+
if (!withoutDial) return numbers;
|
|
1945
|
+
try {
|
|
1946
|
+
const parsed = (0, import_libphonenumber_js.parsePhoneNumber)(numbers, toLibCountryCode(country.code));
|
|
1947
|
+
if (parsed.nationalNumber === numbers) {
|
|
1948
|
+
return numbers;
|
|
1949
|
+
}
|
|
1950
|
+
if (parsed.countryCallingCode === dial && parsed.nationalNumber === withoutDial) {
|
|
1951
|
+
return withoutDial;
|
|
1952
|
+
}
|
|
1953
|
+
} catch {
|
|
1954
|
+
}
|
|
1955
|
+
return numbers;
|
|
2270
1956
|
}
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
// ../search-url/path.ts
|
|
2277
|
-
function toArray(value) {
|
|
2278
|
-
if (value === void 0) return [];
|
|
2279
|
-
return Array.isArray(value) ? value : [value];
|
|
1957
|
+
function prepareNationalDigits(value, country) {
|
|
1958
|
+
const raw = nationalPhoneDigits(value);
|
|
1959
|
+
const stripped = stripAccidentalDialCodePrefix(raw, country);
|
|
1960
|
+
const digits = country.dialCode === BR_DIAL_CODE ? collapseDuplicatedBrazilianMobileNine(stripped) : stripped;
|
|
1961
|
+
return truncateNationalPhoneDigits(digits);
|
|
2280
1962
|
}
|
|
2281
|
-
function
|
|
2282
|
-
|
|
1963
|
+
function prepareInternationalDigits(value) {
|
|
1964
|
+
const digits = nationalPhoneDigits(value);
|
|
1965
|
+
const collapsed = collapseDuplicatedBrazilianMobileNine(digits);
|
|
1966
|
+
if (collapsed === digits) return digits;
|
|
1967
|
+
try {
|
|
1968
|
+
const original = (0, import_libphonenumber_js.parsePhoneNumber)(`+${digits}`);
|
|
1969
|
+
if (original.isValid() && original.countryCallingCode !== BR_DIAL_CODE) {
|
|
1970
|
+
return digits;
|
|
1971
|
+
}
|
|
1972
|
+
} catch {
|
|
1973
|
+
}
|
|
1974
|
+
return collapsed;
|
|
2283
1975
|
}
|
|
2284
|
-
function
|
|
2285
|
-
return
|
|
1976
|
+
function formatNationalDigits(digits, country) {
|
|
1977
|
+
if (!digits) return "";
|
|
1978
|
+
const libCode = toLibCountryCode(country.code);
|
|
1979
|
+
const formatter = new import_libphonenumber_js.AsYouType(libCode);
|
|
1980
|
+
formatter.input(`+${country.dialCode}${digits}`);
|
|
1981
|
+
const national = formatter.getNumber()?.formatNational();
|
|
1982
|
+
if (national && nationalPhoneDigits(national) === digits) return national;
|
|
1983
|
+
const asTyped = new import_libphonenumber_js.AsYouType(libCode).input(digits);
|
|
1984
|
+
if (nationalPhoneDigits(asTyped) === digits) return asTyped;
|
|
1985
|
+
return digits;
|
|
2286
1986
|
}
|
|
2287
|
-
function
|
|
2288
|
-
const
|
|
2289
|
-
|
|
2290
|
-
return firstValue === 0 || firstValue === 1 ? "suite" : "suites";
|
|
1987
|
+
function formatPhoneNational(value, countryCode = DEFAULT_PHONE_COUNTRY_CODE) {
|
|
1988
|
+
const country = findPhoneCountry(countryCode) ?? defaultPhoneCountry();
|
|
1989
|
+
return formatNationalDigits(prepareNationalDigits(value, country), country);
|
|
2291
1990
|
}
|
|
2292
|
-
function
|
|
2293
|
-
const
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
segments.push(
|
|
2297
|
-
optionSlugById(listingType, dictionary.listingTypes) || slugifyForUrl(listingType)
|
|
2298
|
-
);
|
|
2299
|
-
}
|
|
2300
|
-
for (const propertyType of toArray(filters.propertyType)) {
|
|
2301
|
-
segments.push(
|
|
2302
|
-
optionSlugById(propertyType, dictionary.propertyTypes) || slugifyForUrl(propertyType)
|
|
2303
|
-
);
|
|
2304
|
-
}
|
|
2305
|
-
const location = filters.location;
|
|
2306
|
-
if (location) {
|
|
2307
|
-
if (location.state) segments.push(slugifyForUrl(location.state));
|
|
2308
|
-
if (location.city) segments.push(slugifyForUrl(location.city));
|
|
2309
|
-
if (location.neighborhood)
|
|
2310
|
-
segments.push(slugifyForUrl(location.neighborhood));
|
|
2311
|
-
if (location.street) segments.push(slugifyForUrl(location.street));
|
|
2312
|
-
}
|
|
2313
|
-
if (filters.bedrooms !== void 0) {
|
|
2314
|
-
segments.push(`${formatNumeric(filters.bedrooms)}-quartos`);
|
|
2315
|
-
}
|
|
2316
|
-
if (filters.bathrooms !== void 0) {
|
|
2317
|
-
segments.push(`${formatNumeric(filters.bathrooms)}-banheiros`);
|
|
2318
|
-
}
|
|
2319
|
-
if (filters.suites !== void 0) {
|
|
2320
|
-
const suffix = formatSuiteSuffix(filters.suites);
|
|
2321
|
-
segments.push(`${formatNumeric(filters.suites)}-${suffix}`);
|
|
1991
|
+
function parsePhoneInput(input) {
|
|
1992
|
+
const cleaned = String(input ?? "").replace(/[\s\-().]/g, "");
|
|
1993
|
+
if (!cleaned) {
|
|
1994
|
+
return { ddi: null, national: "", countryCode: null };
|
|
2322
1995
|
}
|
|
2323
|
-
|
|
2324
|
-
|
|
1996
|
+
const hasPlus = cleaned.startsWith("+");
|
|
1997
|
+
if (hasPlus) {
|
|
1998
|
+
try {
|
|
1999
|
+
const parsed = (0, import_libphonenumber_js.parsePhoneNumber)(cleaned);
|
|
2000
|
+
if (parsed.country) {
|
|
2001
|
+
const ourCode = fromLibCountryCode(parsed.country);
|
|
2002
|
+
if (PHONE_INPUT_COUNTRY_CODES.has(ourCode)) {
|
|
2003
|
+
return {
|
|
2004
|
+
ddi: parsed.countryCallingCode,
|
|
2005
|
+
national: parsed.nationalNumber,
|
|
2006
|
+
countryCode: ourCode
|
|
2007
|
+
};
|
|
2008
|
+
}
|
|
2009
|
+
}
|
|
2010
|
+
} catch {
|
|
2011
|
+
}
|
|
2012
|
+
const digits = cleaned.slice(1);
|
|
2013
|
+
for (const ddi of SORTED_PHONE_INPUT_DIAL_CODES) {
|
|
2014
|
+
if (digits.startsWith(ddi)) {
|
|
2015
|
+
const national = digits.slice(ddi.length);
|
|
2016
|
+
const match = PHONE_COUNTRIES.find((c) => c.dialCode === ddi);
|
|
2017
|
+
return {
|
|
2018
|
+
ddi,
|
|
2019
|
+
national,
|
|
2020
|
+
countryCode: match?.code ?? null
|
|
2021
|
+
};
|
|
2022
|
+
}
|
|
2023
|
+
}
|
|
2024
|
+
return {
|
|
2025
|
+
ddi: null,
|
|
2026
|
+
national: digits,
|
|
2027
|
+
countryCode: null
|
|
2028
|
+
};
|
|
2325
2029
|
}
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2030
|
+
return {
|
|
2031
|
+
ddi: null,
|
|
2032
|
+
national: cleaned.replace(/\D/g, ""),
|
|
2033
|
+
countryCode: null
|
|
2034
|
+
};
|
|
2035
|
+
}
|
|
2036
|
+
function preferValidE164(candidate) {
|
|
2037
|
+
try {
|
|
2038
|
+
const number = (0, import_libphonenumber_js.parsePhoneNumber)(candidate);
|
|
2039
|
+
if (number.isValid()) return number.number;
|
|
2040
|
+
} catch {
|
|
2330
2041
|
}
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2042
|
+
return candidate;
|
|
2043
|
+
}
|
|
2044
|
+
function toE164(value, countryCode = DEFAULT_PHONE_COUNTRY_CODE) {
|
|
2045
|
+
const trimmed = String(value ?? "").trim();
|
|
2046
|
+
if (!trimmed) return "";
|
|
2047
|
+
const parsed = parsePhoneInput(trimmed);
|
|
2048
|
+
if (parsed.ddi && parsed.national) {
|
|
2049
|
+
const ddiCountry = parsed.countryCode && findPhoneCountry(parsed.countryCode) || PHONE_COUNTRIES.find((c) => c.dialCode === parsed.ddi) || defaultPhoneCountry();
|
|
2050
|
+
return preferValidE164(
|
|
2051
|
+
`+${parsed.ddi}${prepareNationalDigits(parsed.national, ddiCountry)}`
|
|
2052
|
+
);
|
|
2335
2053
|
}
|
|
2336
|
-
const
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2054
|
+
const country = findPhoneCountry(countryCode) ?? defaultPhoneCountry();
|
|
2055
|
+
const national = prepareNationalDigits(parsed.national || trimmed, country);
|
|
2056
|
+
if (!national) return "";
|
|
2057
|
+
return preferValidE164(`+${country.dialCode}${national}`);
|
|
2058
|
+
}
|
|
2059
|
+
function isValidPhone(value, countryCode) {
|
|
2060
|
+
const cleaned = String(value ?? "").trim();
|
|
2061
|
+
if (!cleaned) return false;
|
|
2062
|
+
if (cleaned.startsWith("+")) {
|
|
2063
|
+
const digits2 = prepareInternationalDigits(cleaned);
|
|
2064
|
+
return digits2 ? (0, import_libphonenumber_js.isValidPhoneNumber)(`+${digits2}`) : false;
|
|
2342
2065
|
}
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2066
|
+
const country = countryCode ? findPhoneCountry(countryCode) : defaultPhoneCountry();
|
|
2067
|
+
if (!country) return false;
|
|
2068
|
+
const digits = prepareNationalDigits(cleaned, country);
|
|
2069
|
+
if (!digits) return false;
|
|
2070
|
+
if (countryCode) {
|
|
2071
|
+
return (0, import_libphonenumber_js.isValidPhoneNumber)(digits, toLibCountryCode(countryCode));
|
|
2348
2072
|
}
|
|
2349
|
-
|
|
2350
|
-
return
|
|
2073
|
+
if ((0, import_libphonenumber_js.isValidPhoneNumber)(`+${digits}`)) return true;
|
|
2074
|
+
return (0, import_libphonenumber_js.isValidPhoneNumber)(digits, "BR");
|
|
2351
2075
|
}
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2076
|
+
function remaskPhoneForCountry(nationalOrDraft, countryCode) {
|
|
2077
|
+
const country = findPhoneCountry(countryCode) ?? defaultPhoneCountry();
|
|
2078
|
+
const digits = truncateNationalPhoneDigits(
|
|
2079
|
+
nationalPhoneDigits(nationalOrDraft)
|
|
2080
|
+
);
|
|
2081
|
+
return {
|
|
2082
|
+
display: formatNationalDigits(digits, country),
|
|
2083
|
+
e164: digits ? `+${country.dialCode}${digits}` : "",
|
|
2084
|
+
country
|
|
2085
|
+
};
|
|
2360
2086
|
}
|
|
2361
|
-
|
|
2362
|
-
|
|
2087
|
+
|
|
2088
|
+
// src/resolve-site-id.ts
|
|
2089
|
+
var PREVIEW_HOST_SUFFIXES = [".vusercontent.net"];
|
|
2090
|
+
function isStudioPreviewHost(host) {
|
|
2091
|
+
const normalized = stripPort(host);
|
|
2092
|
+
if (normalized === "localhost" || normalized === "127.0.0.1") return true;
|
|
2093
|
+
return PREVIEW_HOST_SUFFIXES.some((suffix) => normalized.endsWith(suffix));
|
|
2363
2094
|
}
|
|
2364
|
-
function
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
dictionary.listingTypes,
|
|
2382
|
-
LISTING_TYPE_ALIASES
|
|
2383
|
-
);
|
|
2384
|
-
if (listingType && !filters.listingType) {
|
|
2385
|
-
filters.listingType = listingType;
|
|
2386
|
-
continue;
|
|
2387
|
-
}
|
|
2388
|
-
const propertyType = matchOptionId(
|
|
2389
|
-
segment,
|
|
2390
|
-
dictionary.propertyTypes,
|
|
2391
|
-
PROPERTY_TYPE_SLUG_ALIASES
|
|
2095
|
+
function stripPort(host) {
|
|
2096
|
+
return host.trim().toLowerCase().split(":")[0] ?? "";
|
|
2097
|
+
}
|
|
2098
|
+
async function resolvePublicSiteId(options) {
|
|
2099
|
+
const fallback = options.fallback?.trim() ?? "";
|
|
2100
|
+
const host = options.host ? stripPort(options.host) : "";
|
|
2101
|
+
if (host && !isStudioPreviewHost(host)) {
|
|
2102
|
+
const site = await getSite({
|
|
2103
|
+
domain: host,
|
|
2104
|
+
baseUrl: options.baseUrl,
|
|
2105
|
+
fetch: options.fetch,
|
|
2106
|
+
publishableKey: options.publishableKey
|
|
2107
|
+
});
|
|
2108
|
+
if (site?.id) return site.id;
|
|
2109
|
+
throw new GaragemSdkError(
|
|
2110
|
+
`Garagem SDK: no published site found for domain "${host}"`,
|
|
2111
|
+
{ status: 404, url: host }
|
|
2392
2112
|
);
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2113
|
+
}
|
|
2114
|
+
if (fallback) return fallback;
|
|
2115
|
+
throw new GaragemSdkError(
|
|
2116
|
+
"Garagem SDK: could not resolve a site id (no host match and no fallback)",
|
|
2117
|
+
{ status: 404, url: host || "fallback" }
|
|
2118
|
+
);
|
|
2119
|
+
}
|
|
2120
|
+
|
|
2121
|
+
// src/leads.ts
|
|
2122
|
+
function browserHost() {
|
|
2123
|
+
if (typeof window === "undefined") return "";
|
|
2124
|
+
return window.location.host;
|
|
2125
|
+
}
|
|
2126
|
+
async function resolveLeadSiteId(input) {
|
|
2127
|
+
try {
|
|
2128
|
+
return await coerceSiteId(input.siteId);
|
|
2129
|
+
} catch (error) {
|
|
2130
|
+
const host = browserHost();
|
|
2131
|
+
if (!host) throw error;
|
|
2132
|
+
return resolvePublicSiteId({
|
|
2133
|
+
host,
|
|
2134
|
+
baseUrl: input.baseUrl,
|
|
2135
|
+
fetch: input.fetch,
|
|
2136
|
+
publishableKey: input.publishableKey
|
|
2137
|
+
});
|
|
2138
|
+
}
|
|
2139
|
+
}
|
|
2140
|
+
var LeadSubmitError = class extends Error {
|
|
2141
|
+
code;
|
|
2142
|
+
status;
|
|
2143
|
+
retryAfterSeconds;
|
|
2144
|
+
/** Seconds to wait. Same value as `retryAfterSeconds`; `null` when unset. */
|
|
2145
|
+
retryAfter;
|
|
2146
|
+
constructor(message, info) {
|
|
2147
|
+
super(message);
|
|
2148
|
+
this.name = "LeadSubmitError";
|
|
2149
|
+
this.code = info.code;
|
|
2150
|
+
if (info.status != null) this.status = info.status;
|
|
2151
|
+
if (info.retryAfterSeconds != null) {
|
|
2152
|
+
this.retryAfterSeconds = info.retryAfterSeconds;
|
|
2431
2153
|
}
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2154
|
+
this.retryAfter = info.retryAfterSeconds ?? null;
|
|
2155
|
+
}
|
|
2156
|
+
};
|
|
2157
|
+
var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
2158
|
+
var EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
2159
|
+
var NAME_RE = /^[^\d\s]{2,}.*$/;
|
|
2160
|
+
var MESSAGE_MAX = 2e3;
|
|
2161
|
+
function isValidEmail(value) {
|
|
2162
|
+
return EMAIL_RE.test(value.trim());
|
|
2163
|
+
}
|
|
2164
|
+
function isValidName(value) {
|
|
2165
|
+
const name = value.trim();
|
|
2166
|
+
return name.length <= 200 && NAME_RE.test(name);
|
|
2167
|
+
}
|
|
2168
|
+
var CONTACT_FIELDS = [
|
|
2169
|
+
{ id: "name", required: true },
|
|
2170
|
+
{ id: "email", required: false },
|
|
2171
|
+
{ id: "phone", required: false },
|
|
2172
|
+
{ id: "message", required: false }
|
|
2173
|
+
];
|
|
2174
|
+
function studioDefaultLeadUi() {
|
|
2175
|
+
return {
|
|
2176
|
+
defaultVariant: "visit",
|
|
2177
|
+
timeZone: "America/Sao_Paulo",
|
|
2178
|
+
variants: {
|
|
2179
|
+
visit: {
|
|
2180
|
+
ctaLabel: "Agendar visita",
|
|
2181
|
+
requireDateTime: true,
|
|
2182
|
+
schedule: STUDIO_DEFAULT_VISIT_SCHEDULE,
|
|
2183
|
+
fields: CONTACT_FIELDS
|
|
2184
|
+
},
|
|
2185
|
+
contact: {
|
|
2186
|
+
ctaLabel: "Fale conosco",
|
|
2187
|
+
requireDateTime: false,
|
|
2188
|
+
whatsappPhone: null,
|
|
2189
|
+
fields: CONTACT_FIELDS
|
|
2190
|
+
}
|
|
2436
2191
|
}
|
|
2437
|
-
|
|
2192
|
+
};
|
|
2193
|
+
}
|
|
2194
|
+
async function getLeadUi(options) {
|
|
2195
|
+
const siteId = await resolveLeadSiteId(options);
|
|
2196
|
+
const url = `${normalizeBaseUrl(options.baseUrl)}/api/sites/${encodeURIComponent(siteId)}/leads/ui`;
|
|
2197
|
+
return callJson(
|
|
2198
|
+
url,
|
|
2199
|
+
{
|
|
2200
|
+
method: "GET",
|
|
2201
|
+
headers: { Accept: "application/json" },
|
|
2202
|
+
next: options.next
|
|
2203
|
+
},
|
|
2204
|
+
options.fetch ?? fetch,
|
|
2205
|
+
options.publishableKey
|
|
2206
|
+
);
|
|
2207
|
+
}
|
|
2208
|
+
function assertListingId(listingId) {
|
|
2209
|
+
if (!UUID_RE.test(listingId.trim())) {
|
|
2210
|
+
throw new LeadSubmitError(
|
|
2211
|
+
"Garagem SDK: listingId must be the listing UUID, not a path or code.",
|
|
2212
|
+
{ code: "invalid_listing_id" }
|
|
2213
|
+
);
|
|
2438
2214
|
}
|
|
2439
|
-
if (propertyTypes.length === 1) filters.propertyType = propertyTypes[0];
|
|
2440
|
-
else if (propertyTypes.length > 1) filters.propertyType = propertyTypes;
|
|
2441
|
-
if (propertyFeatures.length) filters.propertyFeatures = propertyFeatures;
|
|
2442
|
-
if (buildingAmenities.length) filters.buildingAmenities = buildingAmenities;
|
|
2443
|
-
const location = locationFromPathLeftovers(locationParts);
|
|
2444
|
-
if (location) filters.location = location;
|
|
2445
|
-
return filters;
|
|
2446
2215
|
}
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
if (
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2216
|
+
function normalizeContact(input) {
|
|
2217
|
+
const name = input.name.trim();
|
|
2218
|
+
if (name.length < 2 || name.length > 200) {
|
|
2219
|
+
throw new LeadSubmitError("Garagem SDK: name is required.", {
|
|
2220
|
+
code: "invalid_contact"
|
|
2221
|
+
});
|
|
2222
|
+
}
|
|
2223
|
+
const email = input.email?.trim() || void 0;
|
|
2224
|
+
const phone = input.phone?.trim() || void 0;
|
|
2225
|
+
if (!email && !phone) {
|
|
2226
|
+
throw new LeadSubmitError("Garagem SDK: email and/or phone is required.", {
|
|
2227
|
+
code: "invalid_contact"
|
|
2228
|
+
});
|
|
2229
|
+
}
|
|
2230
|
+
if (email && !EMAIL_RE.test(email)) {
|
|
2231
|
+
throw new LeadSubmitError("Garagem SDK: email is invalid.", {
|
|
2232
|
+
code: "invalid_contact"
|
|
2233
|
+
});
|
|
2234
|
+
}
|
|
2235
|
+
let normalizedPhone;
|
|
2236
|
+
if (phone) {
|
|
2237
|
+
const e164 = toE164(phone);
|
|
2238
|
+
if (!e164 || !isValidPhone(e164) || e164.length > 40) {
|
|
2239
|
+
throw new LeadSubmitError("Garagem SDK: phone is invalid.", {
|
|
2240
|
+
code: "invalid_contact"
|
|
2241
|
+
});
|
|
2242
|
+
}
|
|
2243
|
+
normalizedPhone = e164;
|
|
2244
|
+
}
|
|
2245
|
+
const message = input.message?.trim() || void 0;
|
|
2246
|
+
if (message && message.length > MESSAGE_MAX) {
|
|
2247
|
+
throw new LeadSubmitError("Garagem SDK: message is too long.", {
|
|
2248
|
+
code: "invalid_contact"
|
|
2249
|
+
});
|
|
2455
2250
|
}
|
|
2456
|
-
const [state, city, neighborhood, street] = parts;
|
|
2457
2251
|
return {
|
|
2458
|
-
|
|
2459
|
-
...
|
|
2460
|
-
...
|
|
2461
|
-
...
|
|
2252
|
+
name,
|
|
2253
|
+
...email ? { email } : {},
|
|
2254
|
+
...normalizedPhone ? { phone: normalizedPhone } : {},
|
|
2255
|
+
...message ? { message } : {}
|
|
2462
2256
|
};
|
|
2463
2257
|
}
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
}
|
|
2470
|
-
function normalizeAppliedSearchQuery(query) {
|
|
2471
|
-
if (query.loc && query.loc.length > 0) {
|
|
2472
|
-
const { query: _query, ...rest } = query;
|
|
2473
|
-
return rest;
|
|
2258
|
+
function normalizeSdkBusinessType(value) {
|
|
2259
|
+
if (!value) return void 0;
|
|
2260
|
+
const normalized = value.trim().toLowerCase();
|
|
2261
|
+
if (normalized === "rent" || normalized === "rental" || normalized === "aluguel") {
|
|
2262
|
+
return "rent";
|
|
2474
2263
|
}
|
|
2475
|
-
return
|
|
2264
|
+
if (normalized === "sale" || normalized === "venda") return "sale";
|
|
2265
|
+
return void 0;
|
|
2476
2266
|
}
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2267
|
+
var ADDRESS_REJECTIONS = /* @__PURE__ */ new Set([
|
|
2268
|
+
"missing_postal_code",
|
|
2269
|
+
"ungeocoded_address"
|
|
2270
|
+
]);
|
|
2271
|
+
async function rejectedLeadError(response) {
|
|
2272
|
+
if (response.status !== 400 && response.status !== 409) return null;
|
|
2273
|
+
const parsed = parseSdkErrorBody(await response.text().catch(() => ""));
|
|
2274
|
+
if (response.status === 409 || parsed.reason === "duplicate_property") {
|
|
2275
|
+
return new LeadSubmitError(
|
|
2276
|
+
parsed.summary || "Garagem SDK: property already registered.",
|
|
2277
|
+
{ code: "duplicate_property", status: response.status }
|
|
2278
|
+
);
|
|
2486
2279
|
}
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
return
|
|
2280
|
+
if (parsed.reason && ADDRESS_REJECTIONS.has(parsed.reason)) {
|
|
2281
|
+
return new LeadSubmitError(`Garagem SDK: ${parsed.reason}.`, {
|
|
2282
|
+
code: "invalid_address",
|
|
2283
|
+
status: 400
|
|
2284
|
+
});
|
|
2285
|
+
}
|
|
2286
|
+
return null;
|
|
2494
2287
|
}
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
const
|
|
2498
|
-
const
|
|
2499
|
-
|
|
2500
|
-
|
|
2288
|
+
async function postSiteLead(input) {
|
|
2289
|
+
const siteId = await resolveLeadSiteId(input);
|
|
2290
|
+
const base = normalizeBaseUrl(input.baseUrl);
|
|
2291
|
+
const url = `${base}/api/webhooks/sites/${encodeURIComponent(siteId)}/leads`;
|
|
2292
|
+
const f = input.fetch ?? fetch;
|
|
2293
|
+
let response;
|
|
2294
|
+
try {
|
|
2295
|
+
response = await f(url, {
|
|
2296
|
+
method: "POST",
|
|
2297
|
+
headers: {
|
|
2298
|
+
Accept: "application/json",
|
|
2299
|
+
"Content-Type": "application/json",
|
|
2300
|
+
...publishableKeyHeaders(input.publishableKey)
|
|
2301
|
+
},
|
|
2302
|
+
body: JSON.stringify(input.body)
|
|
2303
|
+
});
|
|
2304
|
+
} catch (error) {
|
|
2305
|
+
throw new LeadSubmitError(
|
|
2306
|
+
error instanceof Error ? error.message : "Garagem SDK: network error.",
|
|
2307
|
+
{ code: "network" }
|
|
2308
|
+
);
|
|
2501
2309
|
}
|
|
2502
|
-
if (
|
|
2503
|
-
|
|
2310
|
+
if (response.status === 202) {
|
|
2311
|
+
const data = await response.json().catch(() => ({}));
|
|
2312
|
+
const id = typeof data.id === "string" && data.id ? data.id : "";
|
|
2313
|
+
return { ok: true, status: 202, id };
|
|
2504
2314
|
}
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2315
|
+
if (response.status === 401) {
|
|
2316
|
+
throw new LeadSubmitError("Garagem SDK: invalid publishable key.", {
|
|
2317
|
+
code: "unauthorized",
|
|
2318
|
+
status: 401
|
|
2319
|
+
});
|
|
2510
2320
|
}
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2321
|
+
if (response.status === 429) {
|
|
2322
|
+
const text2 = await response.text().catch(() => "");
|
|
2323
|
+
const parsed = parseSdkErrorBody(text2);
|
|
2324
|
+
const retryAfter = retryAfterFromResponse(
|
|
2325
|
+
response,
|
|
2326
|
+
parsed.retryAfterSeconds
|
|
2327
|
+
);
|
|
2328
|
+
throw new LeadSubmitError("Garagem SDK: too many lead submissions.", {
|
|
2329
|
+
code: "rate_limited",
|
|
2330
|
+
status: 429,
|
|
2331
|
+
...retryAfter != null ? { retryAfterSeconds: retryAfter } : {}
|
|
2332
|
+
});
|
|
2519
2333
|
}
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
}
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2334
|
+
if (response.status === 404) {
|
|
2335
|
+
throw new LeadSubmitError("Garagem SDK: listing or site not found.", {
|
|
2336
|
+
code: "not_found",
|
|
2337
|
+
status: 404
|
|
2338
|
+
});
|
|
2339
|
+
}
|
|
2340
|
+
const rejected = await rejectedLeadError(response);
|
|
2341
|
+
if (rejected) throw rejected;
|
|
2342
|
+
throw new LeadSubmitError(
|
|
2343
|
+
`Garagem SDK: lead submit failed (${response.status}).`,
|
|
2344
|
+
{ code: "http", status: response.status }
|
|
2345
|
+
);
|
|
2529
2346
|
}
|
|
2530
|
-
function
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
return normalizeAppliedSearchQuery(next);
|
|
2543
|
-
}
|
|
2544
|
-
case "query": {
|
|
2545
|
-
const next = { ...prev };
|
|
2546
|
-
delete next.page;
|
|
2547
|
-
const trimmed = change.query.trim();
|
|
2548
|
-
if (trimmed) {
|
|
2549
|
-
next.query = trimmed;
|
|
2550
|
-
delete next.loc;
|
|
2551
|
-
} else {
|
|
2552
|
-
delete next.query;
|
|
2553
|
-
}
|
|
2554
|
-
return normalizeAppliedSearchQuery(next);
|
|
2555
|
-
}
|
|
2556
|
-
case "loc": {
|
|
2557
|
-
const next = { ...prev };
|
|
2558
|
-
delete next.page;
|
|
2559
|
-
delete next.query;
|
|
2560
|
-
const loc = change.loc.map((value) => value.trim()).filter(Boolean).slice(0, MAX_LOC_GROUPS);
|
|
2561
|
-
if (loc.length > 0) next.loc = loc;
|
|
2562
|
-
else delete next.loc;
|
|
2563
|
-
return normalizeAppliedSearchQuery(next);
|
|
2564
|
-
}
|
|
2565
|
-
case "page": {
|
|
2566
|
-
const next = { ...prev };
|
|
2567
|
-
if (change.page <= 1) delete next.page;
|
|
2568
|
-
else next.page = Math.min(change.page, MAX_PAGE);
|
|
2569
|
-
return normalizeAppliedSearchQuery(next);
|
|
2570
|
-
}
|
|
2571
|
-
default: {
|
|
2572
|
-
const _exhaustive = change;
|
|
2573
|
-
return _exhaustive;
|
|
2347
|
+
function leadPostContext(input) {
|
|
2348
|
+
assertListingId(input.listingId);
|
|
2349
|
+
const businessType = normalizeSdkBusinessType(input.businessType) ?? normalizeSdkBusinessType(input.listingType);
|
|
2350
|
+
return {
|
|
2351
|
+
listingId: input.listingId.trim(),
|
|
2352
|
+
contact: normalizeContact(input),
|
|
2353
|
+
extras: {
|
|
2354
|
+
...input.visitorId ? { visitorId: input.visitorId } : {},
|
|
2355
|
+
...input.brokerRef ? { brokerRef: input.brokerRef } : {},
|
|
2356
|
+
...input.referrer ? { referrer: input.referrer } : {},
|
|
2357
|
+
...businessType ? { businessType } : {},
|
|
2358
|
+
...input.listingType ? { listingType: input.listingType } : {}
|
|
2574
2359
|
}
|
|
2360
|
+
};
|
|
2361
|
+
}
|
|
2362
|
+
async function submitVisitLead(input) {
|
|
2363
|
+
const prepared = leadPostContext(input);
|
|
2364
|
+
const schedule = input.schedule ?? STUDIO_DEFAULT_VISIT_SCHEDULE;
|
|
2365
|
+
const visitDate = normalizeVisitDate(input.visitDate, schedule.timeZone);
|
|
2366
|
+
const visitTime = normalizeVisitTime(input.visitTime);
|
|
2367
|
+
if (!visitDate || !visitTime || !isVisitSlotAllowed(schedule, visitDate, visitTime)) {
|
|
2368
|
+
throw new LeadSubmitError(
|
|
2369
|
+
"Garagem SDK: visitDate/visitTime is outside the published schedule.",
|
|
2370
|
+
{ code: "invalid_slot" }
|
|
2371
|
+
);
|
|
2575
2372
|
}
|
|
2373
|
+
const result = await postSiteLead({
|
|
2374
|
+
siteId: input.siteId,
|
|
2375
|
+
baseUrl: input.baseUrl,
|
|
2376
|
+
fetch: input.fetch,
|
|
2377
|
+
publishableKey: input.publishableKey,
|
|
2378
|
+
body: {
|
|
2379
|
+
source: "site-sdk",
|
|
2380
|
+
leadType: "visit",
|
|
2381
|
+
...prepared.contact,
|
|
2382
|
+
propertyId: prepared.listingId,
|
|
2383
|
+
listingId: prepared.listingId,
|
|
2384
|
+
visitDate,
|
|
2385
|
+
visitTime,
|
|
2386
|
+
...prepared.extras
|
|
2387
|
+
}
|
|
2388
|
+
});
|
|
2389
|
+
trackLeadGenerated("visit", prepared.listingId);
|
|
2390
|
+
return result;
|
|
2576
2391
|
}
|
|
2577
|
-
function
|
|
2578
|
-
const
|
|
2579
|
-
const
|
|
2580
|
-
|
|
2392
|
+
async function submitContactLead(input) {
|
|
2393
|
+
const prepared = leadPostContext(input);
|
|
2394
|
+
const result = await postSiteLead({
|
|
2395
|
+
siteId: input.siteId,
|
|
2396
|
+
baseUrl: input.baseUrl,
|
|
2397
|
+
fetch: input.fetch,
|
|
2398
|
+
publishableKey: input.publishableKey,
|
|
2399
|
+
body: {
|
|
2400
|
+
source: "site-sdk",
|
|
2401
|
+
leadType: "contact",
|
|
2402
|
+
...prepared.contact,
|
|
2403
|
+
propertyId: prepared.listingId,
|
|
2404
|
+
listingId: prepared.listingId,
|
|
2405
|
+
...prepared.extras
|
|
2406
|
+
}
|
|
2407
|
+
});
|
|
2408
|
+
trackLeadGenerated("contact", prepared.listingId);
|
|
2409
|
+
return result;
|
|
2581
2410
|
}
|
|
2582
2411
|
|
|
2583
|
-
// src/
|
|
2584
|
-
function
|
|
2585
|
-
return
|
|
2586
|
-
}
|
|
2587
|
-
function serializeAppliedSearchQuery2(query) {
|
|
2588
|
-
return serializeAppliedSearchQuery(query);
|
|
2589
|
-
}
|
|
2590
|
-
function mergeAppliedSearchQueryIntoSearch2(existing, query) {
|
|
2591
|
-
return mergeAppliedSearchQueryIntoSearch(existing, query);
|
|
2592
|
-
}
|
|
2593
|
-
function reduceAppliedSearchQuery2(prev, change) {
|
|
2594
|
-
return reduceAppliedSearchQuery(prev, change);
|
|
2412
|
+
// src/seller-lead.ts
|
|
2413
|
+
function text(value) {
|
|
2414
|
+
return typeof value === "string" ? value.trim() : "";
|
|
2595
2415
|
}
|
|
2596
|
-
function
|
|
2597
|
-
return
|
|
2416
|
+
function inRange(value, min, max) {
|
|
2417
|
+
return typeof value === "number" && Number.isFinite(value) && value >= min && value <= max;
|
|
2598
2418
|
}
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
if (state) levels.push(state);
|
|
2606
|
-
if (city) levels.push(city);
|
|
2607
|
-
if (neighborhood) levels.push(neighborhood);
|
|
2608
|
-
if (street) levels.push(street);
|
|
2609
|
-
if (levels.length === 0) return null;
|
|
2610
|
-
if (levels.length === 1) {
|
|
2611
|
-
if (state) return { type: "state", value: state };
|
|
2612
|
-
if (city) return { type: "city", value: city };
|
|
2613
|
-
if (neighborhood) return { type: "neighborhood", value: neighborhood };
|
|
2614
|
-
if (street) return { type: "street", value: street };
|
|
2419
|
+
function sellerAddressErrors(address) {
|
|
2420
|
+
const errors = {};
|
|
2421
|
+
if (!address || !text(address.fullAddress)) {
|
|
2422
|
+
errors.fullAddress = "Informe o endere\xE7o do im\xF3vel.";
|
|
2423
|
+
} 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))) {
|
|
2424
|
+
errors.fullAddress = "Selecione o endere\xE7o em uma das sugest\xF5es.";
|
|
2615
2425
|
}
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
// src/path.ts
|
|
2620
|
-
function composeSearchPublicPath2(filters, dictionary) {
|
|
2621
|
-
return dictionary ? composeSearchPublicPath(filters, dictionary) : composeSearchPublicPath(filters);
|
|
2622
|
-
}
|
|
2623
|
-
function parseSearchPublicPath2(pathname, dictionary) {
|
|
2624
|
-
return dictionary ? parseSearchPublicPath(pathname, dictionary) : parseSearchPublicPath(pathname);
|
|
2625
|
-
}
|
|
2626
|
-
function pathFiltersToQueryFilters(pathFilters) {
|
|
2627
|
-
const result = {};
|
|
2628
|
-
if (pathFilters.listingType !== void 0) {
|
|
2629
|
-
result.listing_type = pathFilters.listingType;
|
|
2426
|
+
if (!address?.noNumber && !text(address?.number)) {
|
|
2427
|
+
errors.number = "Informe o n\xFAmero ou marque sem n\xFAmero.";
|
|
2630
2428
|
}
|
|
2631
|
-
if (
|
|
2632
|
-
|
|
2429
|
+
if (!address?.noBlocoTorre && !text(address?.blocoTorre)) {
|
|
2430
|
+
errors.blocoTorre = "Informe o bloco/torre ou marque que n\xE3o tem.";
|
|
2633
2431
|
}
|
|
2634
|
-
if (
|
|
2635
|
-
|
|
2432
|
+
if (!address?.noUnidade && !text(address?.unidade)) {
|
|
2433
|
+
errors.unidade = "Informe a unidade ou marque que n\xE3o tem.";
|
|
2636
2434
|
}
|
|
2637
|
-
if (
|
|
2638
|
-
|
|
2435
|
+
if (text(address?.postalCode).replace(/\D/g, "").length !== 8) {
|
|
2436
|
+
errors.postalCode = "Informe um CEP com 8 d\xEDgitos.";
|
|
2639
2437
|
}
|
|
2640
|
-
|
|
2641
|
-
|
|
2438
|
+
return errors;
|
|
2439
|
+
}
|
|
2440
|
+
var SELLER_LEAD_PHOTO_MAX_BYTES = 10 * 1024 * 1024;
|
|
2441
|
+
var SELLER_LEAD_PHOTO_MAX_COUNT = 30;
|
|
2442
|
+
var SELLER_LEAD_PHOTO_TYPES = [
|
|
2443
|
+
"image/jpeg",
|
|
2444
|
+
"image/png",
|
|
2445
|
+
"image/webp"
|
|
2446
|
+
];
|
|
2447
|
+
async function uploadSellerLeadPhoto(input) {
|
|
2448
|
+
const { file } = input;
|
|
2449
|
+
if (!SELLER_LEAD_PHOTO_TYPES.includes(file.type)) {
|
|
2450
|
+
throw new LeadSubmitError("Garagem SDK: photo must be JPG, PNG or WEBP.", {
|
|
2451
|
+
code: "invalid_photo"
|
|
2452
|
+
});
|
|
2642
2453
|
}
|
|
2643
|
-
if (
|
|
2644
|
-
|
|
2454
|
+
if (file.size <= 0) {
|
|
2455
|
+
throw new LeadSubmitError("Garagem SDK: photo is empty.", {
|
|
2456
|
+
code: "invalid_photo"
|
|
2457
|
+
});
|
|
2645
2458
|
}
|
|
2646
|
-
if (
|
|
2647
|
-
|
|
2459
|
+
if (file.size > SELLER_LEAD_PHOTO_MAX_BYTES) {
|
|
2460
|
+
throw new LeadSubmitError("Garagem SDK: photo is larger than 10MB.", {
|
|
2461
|
+
code: "invalid_photo"
|
|
2462
|
+
});
|
|
2648
2463
|
}
|
|
2649
|
-
|
|
2650
|
-
|
|
2464
|
+
const siteId = await resolveLeadSiteId(input);
|
|
2465
|
+
const url = `${normalizeBaseUrl(input.baseUrl)}/api/webhooks/sites/${encodeURIComponent(siteId)}/photos`;
|
|
2466
|
+
const form = new FormData();
|
|
2467
|
+
form.append("file", file);
|
|
2468
|
+
if (file.name) form.append("fileName", file.name);
|
|
2469
|
+
let response;
|
|
2470
|
+
try {
|
|
2471
|
+
response = await (input.fetch ?? fetch)(url, {
|
|
2472
|
+
method: "POST",
|
|
2473
|
+
body: form
|
|
2474
|
+
});
|
|
2475
|
+
} catch (error) {
|
|
2476
|
+
throw new LeadSubmitError(
|
|
2477
|
+
error instanceof Error ? error.message : "Garagem SDK: network error.",
|
|
2478
|
+
{ code: "network" }
|
|
2479
|
+
);
|
|
2651
2480
|
}
|
|
2652
|
-
if (
|
|
2653
|
-
|
|
2481
|
+
if (response.status === 404) {
|
|
2482
|
+
throw new LeadSubmitError("Garagem SDK: site not found.", {
|
|
2483
|
+
code: "not_found",
|
|
2484
|
+
status: 404
|
|
2485
|
+
});
|
|
2654
2486
|
}
|
|
2655
|
-
|
|
2656
|
-
|
|
2487
|
+
const data = await response.json().catch(() => ({}));
|
|
2488
|
+
if (!response.ok || typeof data.url !== "string" || !data.url) {
|
|
2489
|
+
throw new LeadSubmitError(
|
|
2490
|
+
`Garagem SDK: photo upload failed (${response.status}).`,
|
|
2491
|
+
{
|
|
2492
|
+
code: response.status === 400 ? "invalid_photo" : "http",
|
|
2493
|
+
status: response.status
|
|
2494
|
+
}
|
|
2495
|
+
);
|
|
2657
2496
|
}
|
|
2658
|
-
return
|
|
2497
|
+
return data.url;
|
|
2659
2498
|
}
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
buildingAmenities: "buildingAmenities"
|
|
2673
|
-
};
|
|
2674
|
-
var FORBIDDEN_SEARCH_QUERY_KEYS = [
|
|
2675
|
-
"tipo",
|
|
2676
|
-
"quartos",
|
|
2677
|
-
"tipo-imovel",
|
|
2678
|
-
"banheiros",
|
|
2679
|
-
"vagas"
|
|
2680
|
-
];
|
|
2681
|
-
var SEARCH_SORT_RELEVANCE = {
|
|
2682
|
-
id: "",
|
|
2683
|
-
label: "Mais relevantes"
|
|
2499
|
+
var STUDIO_DEFAULT_PHOTO_SCHEDULE_CONFIG = {
|
|
2500
|
+
disabledDays: [0, 6],
|
|
2501
|
+
weekdayTimeSlots: [
|
|
2502
|
+
"09:00",
|
|
2503
|
+
"10:00",
|
|
2504
|
+
"11:00",
|
|
2505
|
+
"14:00",
|
|
2506
|
+
"15:00",
|
|
2507
|
+
"16:00",
|
|
2508
|
+
"17:00"
|
|
2509
|
+
],
|
|
2510
|
+
weekendTimeSlots: ["10:00", "11:00", "14:00", "15:00", "16:00"]
|
|
2684
2511
|
};
|
|
2685
|
-
function
|
|
2686
|
-
const
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
return String(pathname || "").split(/[?#]/)[0] || "/";
|
|
2704
|
-
}
|
|
2705
|
-
function isListingDetailPath(pathname) {
|
|
2706
|
-
const parts = pathnameOnly(pathname).split("/").filter(Boolean);
|
|
2707
|
-
const last = parts[parts.length - 1] || "";
|
|
2708
|
-
return last.toLowerCase().startsWith("id-");
|
|
2512
|
+
function sellerPhotoSchedule(config = STUDIO_DEFAULT_PHOTO_SCHEDULE_CONFIG) {
|
|
2513
|
+
const weekdayTimeSlots = [...config.weekdayTimeSlots].sort();
|
|
2514
|
+
const weekendTimeSlots = [...config.weekendTimeSlots].sort();
|
|
2515
|
+
const hours = (slots) => slots.length > 0 ? { start: slots[0], end: slots[slots.length - 1] } : null;
|
|
2516
|
+
return {
|
|
2517
|
+
timeZone: VISIT_TIME_ZONE,
|
|
2518
|
+
saturday: !config.disabledDays.includes(6),
|
|
2519
|
+
sunday: !config.disabledDays.includes(0),
|
|
2520
|
+
weekday: hours(weekdayTimeSlots) ?? { start: "09:00", end: "09:00" },
|
|
2521
|
+
weekend: hours(weekendTimeSlots),
|
|
2522
|
+
minHoursAhead: 2,
|
|
2523
|
+
disabledDays: [...config.disabledDays],
|
|
2524
|
+
weekdayTimeSlots,
|
|
2525
|
+
weekendTimeSlots,
|
|
2526
|
+
timeSlots: Array.from(
|
|
2527
|
+
/* @__PURE__ */ new Set([...weekdayTimeSlots, ...weekendTimeSlots])
|
|
2528
|
+
).sort()
|
|
2529
|
+
};
|
|
2709
2530
|
}
|
|
2710
|
-
function
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2531
|
+
function contactError(message) {
|
|
2532
|
+
return new LeadSubmitError(`Garagem SDK: ${message}`, {
|
|
2533
|
+
code: "invalid_contact"
|
|
2534
|
+
});
|
|
2714
2535
|
}
|
|
2715
|
-
function
|
|
2716
|
-
|
|
2717
|
-
|
|
2536
|
+
function normalizeOwner(owner) {
|
|
2537
|
+
const name = text(owner?.name);
|
|
2538
|
+
const email = text(owner?.email);
|
|
2539
|
+
if (!isValidName(name)) throw contactError("owner name is invalid.");
|
|
2540
|
+
if (!isValidEmail(email)) throw contactError("owner email is invalid.");
|
|
2541
|
+
const phone = toE164(text(owner?.phone));
|
|
2542
|
+
if (!phone || !isValidPhone(phone) || phone.length > 40) {
|
|
2543
|
+
throw contactError("owner phone is invalid.");
|
|
2544
|
+
}
|
|
2545
|
+
return { name, email, phone };
|
|
2718
2546
|
}
|
|
2719
|
-
function
|
|
2720
|
-
|
|
2721
|
-
const
|
|
2547
|
+
function normalizeAddress(address) {
|
|
2548
|
+
const errors = sellerAddressErrors(address);
|
|
2549
|
+
const first = Object.values(errors)[0];
|
|
2550
|
+
if (first) {
|
|
2551
|
+
throw new LeadSubmitError(`Garagem SDK: ${first}`, {
|
|
2552
|
+
code: "invalid_address"
|
|
2553
|
+
});
|
|
2554
|
+
}
|
|
2555
|
+
const optional = (value) => text(value) ? { value: text(value) } : null;
|
|
2556
|
+
const number = address.noNumber ? null : optional(address.number);
|
|
2557
|
+
const bloco = address.noBlocoTorre ? null : optional(address.blocoTorre);
|
|
2558
|
+
const unidade = address.noUnidade ? null : optional(address.unidade);
|
|
2722
2559
|
return {
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
2560
|
+
fullAddress: text(address.fullAddress),
|
|
2561
|
+
street: text(address.street),
|
|
2562
|
+
...number ? { number: number.value } : {},
|
|
2563
|
+
neighborhood: text(address.neighborhood),
|
|
2564
|
+
city: text(address.city),
|
|
2565
|
+
state: text(address.state),
|
|
2566
|
+
postalCode: text(address.postalCode).replace(/\D/g, ""),
|
|
2567
|
+
country: text(address.country) || "BR",
|
|
2568
|
+
latitude: address.latitude,
|
|
2569
|
+
longitude: address.longitude,
|
|
2570
|
+
...bloco ? { blocoTorre: bloco.value } : {},
|
|
2571
|
+
...unidade ? { unidade: unidade.value } : {},
|
|
2572
|
+
noNumber: address.noNumber === true,
|
|
2573
|
+
noBlocoTorre: address.noBlocoTorre === true,
|
|
2574
|
+
noUnidade: address.noUnidade === true
|
|
2727
2575
|
};
|
|
2728
2576
|
}
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
}
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
if (applied?.query && !hasLocation) params.q = applied.query;
|
|
2746
|
-
if (hasLocation) params.location = locations;
|
|
2747
|
-
return params;
|
|
2577
|
+
var COUNT_FIELDS = [
|
|
2578
|
+
"bedrooms",
|
|
2579
|
+
"bathrooms",
|
|
2580
|
+
"suites",
|
|
2581
|
+
"parkingSpaces"
|
|
2582
|
+
];
|
|
2583
|
+
var AMOUNT_FIELDS = [
|
|
2584
|
+
"saleValue",
|
|
2585
|
+
"rentValue",
|
|
2586
|
+
"condoFee",
|
|
2587
|
+
"totalArea"
|
|
2588
|
+
];
|
|
2589
|
+
function propertyError(message) {
|
|
2590
|
+
return new LeadSubmitError(`Garagem SDK: ${message}`, {
|
|
2591
|
+
code: "invalid_property"
|
|
2592
|
+
});
|
|
2748
2593
|
}
|
|
2749
|
-
function
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
if (!key) return next;
|
|
2753
|
-
if (value === "" || value == null) {
|
|
2754
|
-
delete next[key];
|
|
2755
|
-
return next;
|
|
2594
|
+
function normalizeProperty(property) {
|
|
2595
|
+
if (!["sale", "rent", "both"].includes(property?.businessType)) {
|
|
2596
|
+
throw propertyError("businessType must be sale, rent or both.");
|
|
2756
2597
|
}
|
|
2757
|
-
|
|
2758
|
-
const
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
const max = parse(range.max);
|
|
2762
|
-
if (min == null && max == null) {
|
|
2763
|
-
delete next[key];
|
|
2764
|
-
return next;
|
|
2598
|
+
for (const field of COUNT_FIELDS) {
|
|
2599
|
+
const value = property[field];
|
|
2600
|
+
if (value != null && (!Number.isInteger(value) || value < 0 || value > 999)) {
|
|
2601
|
+
throw propertyError(`${field} must be a whole number.`);
|
|
2765
2602
|
}
|
|
2766
|
-
next[key] = {
|
|
2767
|
-
...min != null ? { min } : {},
|
|
2768
|
-
...max != null ? { max } : {}
|
|
2769
|
-
};
|
|
2770
|
-
return next;
|
|
2771
|
-
}
|
|
2772
|
-
if (key === "propertyFeatures" || key === "buildingAmenities") {
|
|
2773
|
-
const current = Array.isArray(next[key]) ? [...next[key]] : [];
|
|
2774
|
-
const id = String(value);
|
|
2775
|
-
const i = current.indexOf(id);
|
|
2776
|
-
if (i >= 0) current.splice(i, 1);
|
|
2777
|
-
else current.push(id);
|
|
2778
|
-
if (current.length) next[key] = current;
|
|
2779
|
-
else delete next[key];
|
|
2780
|
-
return next;
|
|
2781
|
-
}
|
|
2782
|
-
if (key === "propertyType") {
|
|
2783
|
-
const id = String(value);
|
|
2784
|
-
const current = Array.isArray(next.propertyType) ? [...next.propertyType] : next.propertyType ? [String(next.propertyType)] : [];
|
|
2785
|
-
const i = current.indexOf(id);
|
|
2786
|
-
if (i >= 0) current.splice(i, 1);
|
|
2787
|
-
else current.push(id);
|
|
2788
|
-
if (current.length === 0) delete next.propertyType;
|
|
2789
|
-
else if (current.length === 1) next.propertyType = current[0];
|
|
2790
|
-
else next.propertyType = current;
|
|
2791
|
-
return next;
|
|
2792
|
-
}
|
|
2793
|
-
if (key === "listingType") {
|
|
2794
|
-
const id = String(value);
|
|
2795
|
-
if (next.listingType === id) delete next.listingType;
|
|
2796
|
-
else next.listingType = id;
|
|
2797
|
-
return next;
|
|
2798
2603
|
}
|
|
2799
|
-
|
|
2800
|
-
const
|
|
2801
|
-
if (!Number.isFinite(
|
|
2802
|
-
|
|
2803
|
-
return next;
|
|
2604
|
+
for (const field of AMOUNT_FIELDS) {
|
|
2605
|
+
const value = property[field];
|
|
2606
|
+
if (value != null && (!Number.isFinite(value) || value < 0 || value > 1e12)) {
|
|
2607
|
+
throw propertyError(`${field} must be a non-negative number.`);
|
|
2804
2608
|
}
|
|
2805
|
-
if (next[key] === n) delete next[key];
|
|
2806
|
-
else next[key] = n;
|
|
2807
|
-
return next;
|
|
2808
2609
|
}
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
const
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2610
|
+
const sale = property.businessType === "rent" ? void 0 : property.saleValue;
|
|
2611
|
+
const rent = property.businessType === "sale" ? void 0 : property.rentValue;
|
|
2612
|
+
const price = property.businessType === "rent" ? rent : sale;
|
|
2613
|
+
const counts = Object.fromEntries(
|
|
2614
|
+
COUNT_FIELDS.filter((field) => property[field] != null).map((field) => [
|
|
2615
|
+
field,
|
|
2616
|
+
property[field]
|
|
2617
|
+
])
|
|
2618
|
+
);
|
|
2619
|
+
return {
|
|
2620
|
+
businessType: property.businessType,
|
|
2621
|
+
...price != null ? { price } : {},
|
|
2622
|
+
...property.businessType === "both" && rent != null ? { rentPrice: rent } : {},
|
|
2623
|
+
...property.condoFee != null ? { condominiumFee: property.condoFee } : {},
|
|
2624
|
+
...property.totalArea != null ? { totalArea: property.totalArea } : {},
|
|
2625
|
+
...counts
|
|
2626
|
+
};
|
|
2818
2627
|
}
|
|
2819
|
-
function
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2628
|
+
function normalizePhotos(photos) {
|
|
2629
|
+
if (!photos?.length) return void 0;
|
|
2630
|
+
if (photos.length > SELLER_LEAD_PHOTO_MAX_COUNT) {
|
|
2631
|
+
throw new LeadSubmitError("Garagem SDK: too many photos (max 30).", {
|
|
2632
|
+
code: "invalid_photo"
|
|
2633
|
+
});
|
|
2634
|
+
}
|
|
2635
|
+
return photos.map((url) => {
|
|
2636
|
+
const trimmed = url.trim();
|
|
2637
|
+
if (!trimmed.startsWith("https://")) {
|
|
2638
|
+
throw new LeadSubmitError("Garagem SDK: photo URL must be https.", {
|
|
2639
|
+
code: "invalid_photo"
|
|
2640
|
+
});
|
|
2641
|
+
}
|
|
2642
|
+
return trimmed;
|
|
2643
|
+
});
|
|
2826
2644
|
}
|
|
2827
|
-
function
|
|
2828
|
-
|
|
2829
|
-
|
|
2645
|
+
function normalizePhotoSession(input) {
|
|
2646
|
+
if (!input.photoSession) return void 0;
|
|
2647
|
+
const schedule = input.photoSchedule ?? sellerPhotoSchedule();
|
|
2648
|
+
const date = normalizeVisitDate(input.photoSession.date, schedule.timeZone);
|
|
2649
|
+
const time = normalizeVisitTime(input.photoSession.time);
|
|
2650
|
+
if (!date || !time || !isVisitSlotAllowed(schedule, date, time)) {
|
|
2651
|
+
throw new LeadSubmitError(
|
|
2652
|
+
"Garagem SDK: photo session slot is outside the schedule.",
|
|
2653
|
+
{ code: "invalid_slot" }
|
|
2654
|
+
);
|
|
2655
|
+
}
|
|
2656
|
+
return { date, time };
|
|
2830
2657
|
}
|
|
2831
|
-
function
|
|
2832
|
-
const
|
|
2833
|
-
const
|
|
2834
|
-
|
|
2658
|
+
async function submitSellerLead(input) {
|
|
2659
|
+
const owner = normalizeOwner(input.owner);
|
|
2660
|
+
const address = normalizeAddress(input.address);
|
|
2661
|
+
const property = normalizeProperty(input.property);
|
|
2662
|
+
const photos = normalizePhotos(input.photos);
|
|
2663
|
+
const photoScheduling = normalizePhotoSession(input);
|
|
2664
|
+
return postSiteLead({
|
|
2665
|
+
siteId: input.siteId,
|
|
2666
|
+
baseUrl: input.baseUrl,
|
|
2667
|
+
fetch: input.fetch,
|
|
2668
|
+
publishableKey: input.publishableKey,
|
|
2669
|
+
body: {
|
|
2670
|
+
source: "site-sdk",
|
|
2671
|
+
leadType: "seller_lead",
|
|
2672
|
+
...owner,
|
|
2673
|
+
address,
|
|
2674
|
+
...property,
|
|
2675
|
+
...photos ? { photos } : {},
|
|
2676
|
+
...photoScheduling ? { photoScheduling } : {},
|
|
2677
|
+
...input.visitorId ? { visitorId: input.visitorId } : {},
|
|
2678
|
+
...input.brokerRef ? { brokerRef: input.brokerRef } : {},
|
|
2679
|
+
...input.referrer ? { referrer: input.referrer } : {}
|
|
2680
|
+
}
|
|
2835
2681
|
});
|
|
2836
|
-
return publicSearchHref(nextPathFilters, nextApplied, dictionary, search);
|
|
2837
2682
|
}
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2683
|
+
|
|
2684
|
+
// src/amenity-labels.ts
|
|
2685
|
+
var LISTING_AMENITY_TITLES = {
|
|
2686
|
+
unit: "Comodidades",
|
|
2687
|
+
building: "Comodidades do condom\xEDnio"
|
|
2688
|
+
};
|
|
2689
|
+
var AMENITY_FALLBACK_LABELS = {
|
|
2690
|
+
// ==================== PROPERTY FEATURES ====================
|
|
2691
|
+
// Amenities
|
|
2692
|
+
arCondicionado: "Ar condicionado",
|
|
2693
|
+
banheira: "Banheira",
|
|
2694
|
+
carregadorEletrico: "Carregador el\xE9trico",
|
|
2695
|
+
churrasqueira: "Churrasqueira",
|
|
2696
|
+
chuveiroGas: "Chuveiro a g\xE1s",
|
|
2697
|
+
chuveiroEletrico: "Chuveiro el\xE9trico",
|
|
2698
|
+
energiaSolar: "Energia solar",
|
|
2699
|
+
fechaduraDigital: "Fechadura digital",
|
|
2700
|
+
fechaduraEletronica: "Fechadura eletr\xF4nica",
|
|
2701
|
+
geradorEletrico: "Gerador el\xE9trico",
|
|
2702
|
+
gesso: "Gesso",
|
|
2703
|
+
hidromassagem: "Hidromassagem",
|
|
2704
|
+
lareira: "Lareira",
|
|
2705
|
+
ofuro: "Ofur\xF4",
|
|
2706
|
+
spa: "Spa",
|
|
2707
|
+
painelSolar: "Painel solar",
|
|
2708
|
+
portaoEletronico: "Port\xE3o eletr\xF4nico",
|
|
2709
|
+
sistemaAlarme: "Sistema de alarme",
|
|
2710
|
+
homeTheater: "Home theater",
|
|
2711
|
+
adega: "Adega",
|
|
2712
|
+
split: "Split",
|
|
2713
|
+
arCentral: "Ar central",
|
|
2714
|
+
esperaSplit: "Espera para split",
|
|
2715
|
+
vistaMar: "Vista para o mar",
|
|
2716
|
+
vistaPanoramica: "Vista panor\xE2mica",
|
|
2717
|
+
aguaQuente: "\xC1gua quente",
|
|
2718
|
+
reformado: "Reformado",
|
|
2719
|
+
tvCabo: "TV a cabo",
|
|
2720
|
+
gradeado: "Gradeado",
|
|
2721
|
+
antenaParabolica: "Antena parab\xF3lica",
|
|
2722
|
+
aquecimento: "Aquecimento",
|
|
2723
|
+
aquecimentoEletrico: "Aquecimento el\xE9trico",
|
|
2724
|
+
aquecimentoCentral: "Aquecimento central",
|
|
2725
|
+
cercaEletrica: "Cerca el\xE9trica",
|
|
2726
|
+
monitoramento: "Monitoramento",
|
|
2727
|
+
vigiaInterno: "Vigia interno",
|
|
2728
|
+
vigiaExterno: "Vigia externo",
|
|
2729
|
+
alarme: "Alarme",
|
|
2730
|
+
agua: "\xC1gua",
|
|
2731
|
+
redeEsgoto: "Rede de esgoto",
|
|
2732
|
+
pavimentacao: "Pavimenta\xE7\xE3o",
|
|
2733
|
+
energiaEletrica: "Energia el\xE9trica",
|
|
2734
|
+
// Furniture
|
|
2735
|
+
mobiliado: "Mobiliado",
|
|
2736
|
+
armarioEmbutido: "Arm\xE1rio embutido",
|
|
2737
|
+
armarioEmbutidoQuarto: "Arm\xE1rio embutido quarto",
|
|
2738
|
+
armarioCozinha: "Arm\xE1rio cozinha",
|
|
2739
|
+
armarioBanheiro: "Arm\xE1rio banheiro",
|
|
2740
|
+
cozinhaPlanejada: "Cozinha planejada",
|
|
2741
|
+
fogao: "Fog\xE3o",
|
|
2742
|
+
fornoPizza: "Forno de pizza",
|
|
2743
|
+
freezer: "Freezer",
|
|
2744
|
+
dormitorioComArmario: "Dormit\xF3rio com arm\xE1rio",
|
|
2745
|
+
semiMobiliado: "Semi mobiliado",
|
|
2746
|
+
salaArmarios: "Sala com arm\xE1rios",
|
|
2747
|
+
// Structure
|
|
2748
|
+
piscina: "Piscina",
|
|
2749
|
+
piscinaAquecida: "Piscina aquecida",
|
|
2750
|
+
piscinaCoberta: "Piscina coberta",
|
|
2751
|
+
poco: "Po\xE7o",
|
|
2752
|
+
pocoArtesiano: "Po\xE7o artesiano",
|
|
2753
|
+
bar: "Bar",
|
|
2754
|
+
jardim: "Jardim",
|
|
2755
|
+
lago: "Lago",
|
|
2756
|
+
lavabo: "Lavabo",
|
|
2757
|
+
quintal: "Quintal",
|
|
2758
|
+
solarium: "Solarium",
|
|
2759
|
+
quartoServico: "Quarto de servi\xE7o",
|
|
2760
|
+
varanda: "Varanda",
|
|
2761
|
+
varandaFechadaVidro: "Varanda fechada com vidro",
|
|
2762
|
+
varandaGourmet: "Varanda gourmet",
|
|
2763
|
+
banheiroServico: "Banheiro de servi\xE7o",
|
|
2764
|
+
areaServico: "\xC1rea de servi\xE7o",
|
|
2765
|
+
cinema: "Cinema",
|
|
2766
|
+
closet: "Closet",
|
|
2767
|
+
cozinhaAmericana: "Cozinha americana",
|
|
2768
|
+
cozinhaGourmet: "Cozinha gourmet",
|
|
2769
|
+
despensa: "Despensa",
|
|
2770
|
+
escritorio: "Escrit\xF3rio",
|
|
2771
|
+
edicula: "Ed\xEDcula",
|
|
2772
|
+
horta: "Horta",
|
|
2773
|
+
sacada: "Sacada",
|
|
2774
|
+
salaJantar: "Sala de jantar",
|
|
2775
|
+
cozinha: "Cozinha",
|
|
2776
|
+
banheiroSocial: "Banheiro social",
|
|
2777
|
+
terraco: "Terra\xE7o",
|
|
2778
|
+
copa: "Copa",
|
|
2779
|
+
suiteMaster: "Su\xEDte master",
|
|
2780
|
+
wcEmpregada: "WC empregada",
|
|
2781
|
+
dependenciaEmpregada: "Depend\xEAncia de empregada",
|
|
2782
|
+
dependenciadeEmpregada: "Depend\xEAncia empregada",
|
|
2783
|
+
salaTv: "Sala de TV",
|
|
2784
|
+
copaCozinha: "Copa cozinha",
|
|
2785
|
+
sacadaComChurrasqueira: "Sacada com churrasqueira",
|
|
2786
|
+
hallPrivativo: "Hall privativo",
|
|
2787
|
+
estarIntimo: "Estar \xEDntimo",
|
|
2788
|
+
livingHall: "Living hall",
|
|
2789
|
+
piscinaInterna: "Piscina interna",
|
|
2790
|
+
deck: "Deck",
|
|
2791
|
+
jardimInverno: "Jardim de inverno",
|
|
2792
|
+
rouparia: "Rouparia",
|
|
2793
|
+
living: "Living",
|
|
2794
|
+
familyRoom: "Family room",
|
|
2795
|
+
salafitness: "Sala fitness",
|
|
2796
|
+
salaEstar: "Sala de estar",
|
|
2797
|
+
mezanino: "Mezanino",
|
|
2798
|
+
pisoElevado: "Piso elevado",
|
|
2799
|
+
entradaServicoIndependente: "Entrada de servi\xE7o independente",
|
|
2800
|
+
forro: "Forro",
|
|
2801
|
+
vitrine: "Vitrine",
|
|
2802
|
+
banheiroAuxiliar: "Banheiro auxiliar",
|
|
2803
|
+
gabinete: "Gabinete",
|
|
2804
|
+
quadraTenisPrivativa: "Quadra de t\xEAnis privativa",
|
|
2805
|
+
porao: "Por\xE3o",
|
|
2806
|
+
sotao: "S\xF3t\xE3o",
|
|
2807
|
+
patio: "P\xE1tio",
|
|
2808
|
+
canaletasNoRodape: "Canaletas no rodap\xE9",
|
|
2809
|
+
// Accessibility
|
|
2810
|
+
barraApoioVaso: "Barra de apoio vaso",
|
|
2811
|
+
barraApoioChuveiro: "Barra de apoio chuveiro",
|
|
2812
|
+
entradaSemDegrau: "Entrada sem degrau",
|
|
2813
|
+
rampasAcesso: "Rampas de acesso",
|
|
2814
|
+
vagaDeficientes: "Vaga para deficientes",
|
|
2815
|
+
// Flooring
|
|
2816
|
+
cimentoQueimado: "Cimento queimado",
|
|
2817
|
+
madeira: "Madeira",
|
|
2818
|
+
pisoFrio: "Piso frio",
|
|
2819
|
+
laminado: "Laminado",
|
|
2820
|
+
vinilico: "Vin\xEDlico",
|
|
2821
|
+
porcelanato: "Porcelanato",
|
|
2822
|
+
// ==================== BUILDING FEATURES ====================
|
|
2823
|
+
// Amenities
|
|
2824
|
+
elevador: "Elevador",
|
|
2825
|
+
bicicletario: "Biciclet\xE1rio",
|
|
2826
|
+
carregadorEletronico: "Carregador eletr\xF4nico",
|
|
2827
|
+
concierge: "Concierge",
|
|
2828
|
+
coworking: "Coworking",
|
|
2829
|
+
deposito: "Dep\xF3sito",
|
|
2830
|
+
lavanderia: "Lavanderia",
|
|
2831
|
+
petPlace: "Pet place",
|
|
2832
|
+
recebimentoEncomendas: "Recebimento de encomendas",
|
|
2833
|
+
salaReuniao: "Sala de reuni\xE3o",
|
|
2834
|
+
salaoFestas: "Sal\xE3o de festas",
|
|
2835
|
+
valet: "Valet",
|
|
2836
|
+
garagemCoberta: "Garagem coberta",
|
|
2837
|
+
elevadorServico: "Elevador de servi\xE7o",
|
|
2838
|
+
// Leisure
|
|
2839
|
+
academia: "Academia",
|
|
2840
|
+
campoFutebol: "Campo de futebol",
|
|
2841
|
+
espacoGourmet: "Espa\xE7o gourmet",
|
|
2842
|
+
piscinaInfantil: "Piscina infantil",
|
|
2843
|
+
pistaCaminhada: "Pista de caminhada",
|
|
2844
|
+
playground: "Playground",
|
|
2845
|
+
quadraPoliesportiva: "Quadra poliesportiva",
|
|
2846
|
+
quadraTenis: "Quadra de t\xEAnis",
|
|
2847
|
+
salaJogos: "Sala de jogos",
|
|
2848
|
+
salaVapor: "Sala de vapor",
|
|
2849
|
+
sauna: "Sauna",
|
|
2850
|
+
// Security
|
|
2851
|
+
circuitoTv: "Circuito fechado de TV",
|
|
2852
|
+
controleAcessoEletronico: "Controle de acesso eletr\xF4nico",
|
|
2853
|
+
interfone: "Interfone",
|
|
2854
|
+
portaria24h: "Portaria 24h",
|
|
2855
|
+
porteiroFisico: "Porteiro f\xEDsico",
|
|
2856
|
+
seguranca24h: "Seguran\xE7a 24h",
|
|
2857
|
+
segurancaPatrimonial: "Seguran\xE7a patrimonial",
|
|
2858
|
+
condominioFechado: "Condom\xEDnio fechado",
|
|
2859
|
+
// Accessibility
|
|
2860
|
+
banheiroAcessivel: "Banheiro acess\xEDvel",
|
|
2861
|
+
elevadorAcessivel: "Elevador acess\xEDvel",
|
|
2862
|
+
pisoTatil: "Piso t\xE1til",
|
|
2863
|
+
// ==================== CANONICAL HAS*/IS* KEYS ====================
|
|
2864
|
+
has24hConcierge: "Portaria 24h",
|
|
2865
|
+
has24hSecurity: "Seguran\xE7a 24h",
|
|
2866
|
+
hasAccessRamps: "Rampas de acesso",
|
|
2867
|
+
hasAccessibleBathroom: "Banheiro acess\xEDvel",
|
|
2868
|
+
hasAccessibleElevator: "Elevador acess\xEDvel",
|
|
2869
|
+
hasAirConditioning: "Ar condicionado",
|
|
2870
|
+
hasAlarmSystem: "Sistema de alarme",
|
|
2871
|
+
hasBalcony: "Varanda",
|
|
2872
|
+
hasBikeStorage: "Biciclet\xE1rio",
|
|
2873
|
+
hasBuiltInWardrobe: "Arm\xE1rio embutido",
|
|
2874
|
+
hasCCTV: "CFTV",
|
|
2875
|
+
hasCloset: "Closet",
|
|
2876
|
+
hasConcierge: "Portaria",
|
|
2877
|
+
hasControlledAccess: "Condom\xEDnio fechado",
|
|
2878
|
+
hasCoworking: "Coworking",
|
|
2879
|
+
hasDisabledParking: "Vaga para deficientes",
|
|
2880
|
+
hasElectricCharger: "Carregador eletr\xF4nico",
|
|
2881
|
+
hasElectronicGate: "Port\xE3o eletr\xF4nico",
|
|
2882
|
+
hasElevator: "Elevador",
|
|
2883
|
+
hasFireplace: "Lareira",
|
|
2884
|
+
hasGarden: "Jardim",
|
|
2885
|
+
hasGasShower: "Chuveiro a g\xE1s",
|
|
2886
|
+
hasGenerator: "Gerador",
|
|
2887
|
+
hasGourmetBalcony: "Varanda gourmet",
|
|
2888
|
+
hasGourmetKitchen: "Cozinha gourmet",
|
|
2889
|
+
hasGrill: "Churrasqueira",
|
|
2890
|
+
hasGuestParking: "Estacionamento para visitantes",
|
|
2891
|
+
hasGym: "Academia",
|
|
2892
|
+
hasHeating: "Aquecimento",
|
|
2893
|
+
hasHomeOffice: "Home office",
|
|
2894
|
+
hasIntercom: "Interfone",
|
|
2895
|
+
hasJacuzzi: "Hidromassagem",
|
|
2896
|
+
hasKidsPool: "Piscina infantil",
|
|
2897
|
+
hasLaundry: "Lavanderia",
|
|
2898
|
+
hasMeetingRoom: "Sala de reuni\xE3o",
|
|
2899
|
+
hasOffice: "Escrit\xF3rio",
|
|
2900
|
+
hasOpenKitchen: "Cozinha americana",
|
|
2901
|
+
hasPackageReceival: "Recebimento de encomendas",
|
|
2902
|
+
hasPantry: "Despensa",
|
|
2903
|
+
hasParkingGarage: "Garagem coberta",
|
|
2904
|
+
hasPartySaloon: "Sal\xE3o de festas",
|
|
2905
|
+
hasPetArea: "Pet place",
|
|
2906
|
+
hasPipedGas: "G\xE1s encanado",
|
|
2907
|
+
hasPlayground: "Playground",
|
|
2908
|
+
hasPowderRoom: "Lavabo",
|
|
2909
|
+
hasPrivatePool: "Piscina privativa",
|
|
2910
|
+
hasSauna: "Sauna",
|
|
2911
|
+
hasSecurity: "Seguran\xE7a",
|
|
2912
|
+
hasServiceArea: "\xC1rea de servi\xE7o",
|
|
2913
|
+
hasSolarPanel: "Painel solar",
|
|
2914
|
+
hasSpa: "Spa",
|
|
2915
|
+
hasSportsCourt: "Quadra de esportes",
|
|
2916
|
+
hasStepFreeEntrance: "Entrada sem degrau",
|
|
2917
|
+
hasStorage: "Dep\xF3sito",
|
|
2918
|
+
hasSwimmingPool: "Piscina",
|
|
2919
|
+
hasTennisCourt: "Quadra de t\xEAnis",
|
|
2920
|
+
hasValetParking: "Valet",
|
|
2921
|
+
homeOffice: "Home office",
|
|
2922
|
+
isPetFriendly: "Pet friendly",
|
|
2923
|
+
isFurnished: "Mobiliado",
|
|
2924
|
+
isPartiallyFurnished: "Semi-mobiliado",
|
|
2925
|
+
petFriendly: "Pet friendly",
|
|
2926
|
+
piscinaPrivativa: "Piscina privativa",
|
|
2927
|
+
pisoLaminado: "Piso laminado",
|
|
2928
|
+
pisoMadeira: "Piso de madeira",
|
|
2929
|
+
pisoPorcelanato: "Piso porcelanato",
|
|
2930
|
+
quadraEsportes: "Quadra de esportes",
|
|
2931
|
+
rooftop: "Rooftop",
|
|
2932
|
+
suite: "Su\xEDte",
|
|
2933
|
+
triplex: "Triplex",
|
|
2934
|
+
duplex: "Duplex",
|
|
2935
|
+
cobertura: "Cobertura",
|
|
2936
|
+
forroGesso: "Forro de gesso",
|
|
2937
|
+
gerador: "Gerador",
|
|
2938
|
+
armariosCozinha: "Arm\xE1rios na cozinha",
|
|
2939
|
+
armariosQuarto: "Arm\xE1rios nos quartos",
|
|
2940
|
+
cftv: "CFTV"
|
|
2941
|
+
};
|
|
2942
|
+
function lookupLabel(id, options) {
|
|
2943
|
+
const fromDictionary = options?.find((option) => option.id === id)?.label;
|
|
2944
|
+
if (fromDictionary?.trim()) return fromDictionary.trim();
|
|
2945
|
+
return AMENITY_FALLBACK_LABELS[id];
|
|
2946
|
+
}
|
|
2947
|
+
function labelAmenities(ids, dictionary) {
|
|
2948
|
+
if (!ids?.length) return [];
|
|
2949
|
+
const labels = [];
|
|
2950
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2951
|
+
for (const id of ids) {
|
|
2952
|
+
if (!id) continue;
|
|
2953
|
+
const label = lookupLabel(id, dictionary);
|
|
2954
|
+
if (!label || seen.has(label)) continue;
|
|
2955
|
+
seen.add(label);
|
|
2956
|
+
labels.push(label);
|
|
2848
2957
|
}
|
|
2849
|
-
|
|
2850
|
-
return publicSearchHref(nextPath, nextApplied, dictionary, search);
|
|
2851
|
-
}
|
|
2852
|
-
function currentSearchHref(pathname, search) {
|
|
2853
|
-
const path = pathnameOnly(pathname);
|
|
2854
|
-
const qs = search.replace(/^\?/, "");
|
|
2855
|
-
return qs ? `${path}?${qs}` : path;
|
|
2856
|
-
}
|
|
2857
|
-
function canonicalizeSearchHref(pathname, search, dictionary) {
|
|
2858
|
-
if (pathname.includes("/api/v0-preview/")) return null;
|
|
2859
|
-
if (isListingDetailPath(pathname)) return null;
|
|
2860
|
-
const { pathFilters, applied } = readPublicSearch(
|
|
2861
|
-
pathname,
|
|
2862
|
-
search,
|
|
2863
|
-
dictionary
|
|
2864
|
-
);
|
|
2865
|
-
const href = publicSearchHref(pathFilters, applied, dictionary, search);
|
|
2866
|
-
if (href === currentSearchHref(pathname, search)) return null;
|
|
2867
|
-
return href;
|
|
2958
|
+
return labels.sort((a, b) => a.localeCompare(b, "pt-BR"));
|
|
2868
2959
|
}
|
|
2869
|
-
function
|
|
2870
|
-
|
|
2871
|
-
const params = new URLSearchParams(query);
|
|
2872
|
-
return FORBIDDEN_SEARCH_QUERY_KEYS.some((key) => params.has(key));
|
|
2960
|
+
function presentIds(ids) {
|
|
2961
|
+
return (ids ?? []).filter((id) => Boolean(id));
|
|
2873
2962
|
}
|
|
2874
|
-
function
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
const value = current[key];
|
|
2880
|
-
if (value != null) Object.assign(next, { [key]: value });
|
|
2963
|
+
function buildingIdsFromMergedAmenities(listing, unitIds) {
|
|
2964
|
+
if (!listing.amenities || listing.propertyFeatures == null) return [];
|
|
2965
|
+
const unitCounts = /* @__PURE__ */ new Map();
|
|
2966
|
+
for (const id of unitIds) {
|
|
2967
|
+
unitCounts.set(id, (unitCounts.get(id) ?? 0) + 1);
|
|
2881
2968
|
}
|
|
2882
|
-
return
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
if (filter.id === "listing_type" && (filter.options?.length ?? 0) <= 1) {
|
|
2889
|
-
return false;
|
|
2890
|
-
}
|
|
2891
|
-
return true;
|
|
2969
|
+
return listing.amenities.filter((id) => {
|
|
2970
|
+
if (!id) return false;
|
|
2971
|
+
const count = unitCounts.get(id);
|
|
2972
|
+
if (count === void 0 || count === 0) return true;
|
|
2973
|
+
unitCounts.set(id, count - 1);
|
|
2974
|
+
return false;
|
|
2892
2975
|
});
|
|
2893
2976
|
}
|
|
2894
|
-
function
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
}
|
|
2898
|
-
function countOptionLabel(option) {
|
|
2899
|
-
const label = String(option?.label ?? "");
|
|
2900
|
-
if (/^[1-9]\d*$/.test(label)) return `${label}+`;
|
|
2901
|
-
return label;
|
|
2902
|
-
}
|
|
2903
|
-
function countFacetChoices(options) {
|
|
2904
|
-
const list = options || [];
|
|
2905
|
-
const zero = list.find((o) => o.id === "0" || o.label === "Studio");
|
|
2906
|
-
const isStudio = Boolean(
|
|
2907
|
-
zero && /studio/i.test(String(zero.label)) && zero.id === "0"
|
|
2908
|
-
);
|
|
2909
|
-
const max = isStudio ? 3 : 4;
|
|
2910
|
-
const out = [];
|
|
2911
|
-
if (zero) out.push({ id: zero.id, label: countOptionLabel(zero) });
|
|
2912
|
-
for (let n = 1; n <= max; n += 1) {
|
|
2913
|
-
const option = list.find((o) => o.id === String(n));
|
|
2914
|
-
out.push({
|
|
2915
|
-
id: String(n),
|
|
2916
|
-
label: countOptionLabel(option || { label: String(n) })
|
|
2917
|
-
});
|
|
2977
|
+
function unitAmenityIds(listing) {
|
|
2978
|
+
if (listing.propertyFeatures != null) {
|
|
2979
|
+
return presentIds(listing.propertyFeatures);
|
|
2918
2980
|
}
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
const text2 = label.trim();
|
|
2924
|
-
if (!text2 || /s$/i.test(text2)) return text2;
|
|
2925
|
-
if (/il$/i.test(text2)) return `${text2.slice(0, -1)}is`;
|
|
2926
|
-
if (/m$/i.test(text2)) return `${text2.slice(0, -1)}ns`;
|
|
2927
|
-
return `${text2}s`;
|
|
2981
|
+
const building = new Set(
|
|
2982
|
+
listing.building?.amenities ?? listing.buildingAmenities ?? []
|
|
2983
|
+
);
|
|
2984
|
+
return (listing.amenities ?? []).filter((id) => id && !building.has(id));
|
|
2928
2985
|
}
|
|
2929
|
-
function
|
|
2930
|
-
if (
|
|
2931
|
-
|
|
2932
|
-
return `${location.street}, ${location.neighborhood}`;
|
|
2933
|
-
}
|
|
2934
|
-
if (location.neighborhood && location.city) {
|
|
2935
|
-
return `${location.neighborhood}, ${location.city}`;
|
|
2986
|
+
function buildingAmenityIds(listing) {
|
|
2987
|
+
if (listing.building != null && listing.building.amenities != null) {
|
|
2988
|
+
return presentIds(listing.building.amenities);
|
|
2936
2989
|
}
|
|
2937
|
-
if (
|
|
2938
|
-
return
|
|
2990
|
+
if (listing.buildingAmenities != null) {
|
|
2991
|
+
return presentIds(listing.buildingAmenities);
|
|
2939
2992
|
}
|
|
2940
|
-
return
|
|
2993
|
+
return buildingIdsFromMergedAmenities(listing, unitAmenityIds(listing));
|
|
2941
2994
|
}
|
|
2942
|
-
function
|
|
2943
|
-
const
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
if (
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
if (label) {
|
|
2953
|
-
noun = pluralizePt(label.charAt(0).toUpperCase() + label.slice(1));
|
|
2954
|
-
if (FEMININE_HEADING.test(id) || FEMININE_HEADING.test(label)) {
|
|
2955
|
-
found = "encontradas";
|
|
2956
|
-
}
|
|
2957
|
-
}
|
|
2995
|
+
function listingAmenityGroups(listing, dictionary) {
|
|
2996
|
+
const groups = [];
|
|
2997
|
+
const unitIds = unitAmenityIds(listing);
|
|
2998
|
+
const unitLabels = labelAmenities(unitIds, dictionary?.propertyFeatures);
|
|
2999
|
+
if (unitLabels.length > 0) {
|
|
3000
|
+
groups.push({
|
|
3001
|
+
key: "unit",
|
|
3002
|
+
title: dictionary?.amenitySectionTitles?.unit ?? LISTING_AMENITY_TITLES.unit,
|
|
3003
|
+
labels: unitLabels
|
|
3004
|
+
});
|
|
2958
3005
|
}
|
|
2959
|
-
const
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
}
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
const current = Math.min(Math.max(1, currentPage), totalPages);
|
|
2972
|
-
const start = Math.max(1, current - padding);
|
|
2973
|
-
const end = Math.min(totalPages, current + padding);
|
|
2974
|
-
const pages = [];
|
|
2975
|
-
for (let i = start; i <= end; i += 1) pages.push(i);
|
|
2976
|
-
return pages;
|
|
3006
|
+
const buildingLabels = labelAmenities(
|
|
3007
|
+
buildingAmenityIds(listing),
|
|
3008
|
+
dictionary?.buildingAmenities
|
|
3009
|
+
);
|
|
3010
|
+
if (buildingLabels.length > 0) {
|
|
3011
|
+
groups.push({
|
|
3012
|
+
key: "building",
|
|
3013
|
+
title: dictionary?.amenitySectionTitles?.building ?? LISTING_AMENITY_TITLES.building,
|
|
3014
|
+
labels: buildingLabels
|
|
3015
|
+
});
|
|
3016
|
+
}
|
|
3017
|
+
return groups;
|
|
2977
3018
|
}
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
return {
|
|
2983
|
-
price: {
|
|
2984
|
-
min: price.min != null ? formatGroupedInteger(price.min) : "",
|
|
2985
|
-
max: price.max != null ? formatGroupedInteger(price.max) : ""
|
|
2986
|
-
},
|
|
2987
|
-
property_area_total: {
|
|
2988
|
-
min: area.min != null ? String(area.min) : "",
|
|
2989
|
-
max: area.max != null ? String(area.max) : ""
|
|
2990
|
-
}
|
|
2991
|
-
};
|
|
3019
|
+
|
|
3020
|
+
// src/listing-card-model.ts
|
|
3021
|
+
function listingLocationLabel(location) {
|
|
3022
|
+
return [location.neighborhood, location.city, location.state].map((part) => part ? String(part).trim() : "").filter(Boolean).join(", ");
|
|
2992
3023
|
}
|
|
2993
|
-
function
|
|
2994
|
-
const
|
|
2995
|
-
const
|
|
3024
|
+
function toListingCardModel(listing) {
|
|
3025
|
+
const isPrivate = listing.priceVisibility === "private";
|
|
3026
|
+
const area = listing.property?.usableArea ?? listing.property?.totalArea;
|
|
2996
3027
|
return {
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3028
|
+
href: listingPublicPath(listing),
|
|
3029
|
+
title: listing.title,
|
|
3030
|
+
businessType: listing.businessType,
|
|
3031
|
+
businessLabel: listingBusinessLabel(listing.businessType),
|
|
3032
|
+
priceVisibility: listing.priceVisibility,
|
|
3033
|
+
price: listing.price,
|
|
3034
|
+
priceLabel: isPrivate ? "Sob consulta" : formatListingPrice(listing.price, "pt-BR", listing.currency ?? "BRL"),
|
|
3035
|
+
pricePeriod: listing.businessType === "rental" && !isPrivate && listing.price != null ? "/m\xEAs" : null,
|
|
3036
|
+
locationLabel: listingLocationLabel(listing.location || {}),
|
|
3037
|
+
propertyType: listing.property?.type ?? null,
|
|
3038
|
+
coverSrc: listing.coverImage?.src ?? null,
|
|
3039
|
+
coverAlt: listing.coverImage?.alt ?? listing.title,
|
|
3040
|
+
bedrooms: listing.property?.bedrooms ?? null,
|
|
3041
|
+
bathrooms: listing.property?.bathrooms ?? null,
|
|
3042
|
+
parkingSpaces: listing.property?.parkingSpaces ?? null,
|
|
3043
|
+
areaM2: area ?? null
|
|
3005
3044
|
};
|
|
3006
3045
|
}
|
|
3007
3046
|
|
|
@@ -3308,10 +3347,12 @@ var STUDIO_SDK_CONTRACT = {
|
|
|
3308
3347
|
* does not export them. Property registration shipped in 0.10.0.
|
|
3309
3348
|
* Weighted map buckets (`map.buckets`, clustered by the hook) shipped
|
|
3310
3349
|
* in 0.11.0. Share links (`getShareLink`, `/p/[token]`) shipped in
|
|
3311
|
-
* 0.12.0.
|
|
3312
|
-
*
|
|
3350
|
+
* 0.12.0. Analytics catalog events (`trackListingView` plus the search
|
|
3351
|
+
* and lead emitters) shipped in 0.13.0. Search filter helpers
|
|
3352
|
+
* (`visibleSearchFilters` / `toolbarFilterIds`) shipped in 0.4.12 and
|
|
3353
|
+
* remain on this pin.
|
|
3313
3354
|
*/
|
|
3314
|
-
minNpmVersion: "0.
|
|
3355
|
+
minNpmVersion: "0.13.0",
|
|
3315
3356
|
/** Historical: older tarballs inject card CSS when those components mount. */
|
|
3316
3357
|
selfInjectSince: "0.4.2",
|
|
3317
3358
|
chromeStrategy: "app-owned",
|
|
@@ -3518,7 +3559,15 @@ var STUDIO_SDK_CONTRACT = {
|
|
|
3518
3559
|
* v0 installs the pin and copies any identifier it sees.
|
|
3519
3560
|
*/
|
|
3520
3561
|
shareExports: ["getShareLink"],
|
|
3521
|
-
shareLinkSince: "0.12.0"
|
|
3562
|
+
shareLinkSince: "0.12.0",
|
|
3563
|
+
/**
|
|
3564
|
+
* Listing-view analytics. Search and lead catalog events need no prompt:
|
|
3565
|
+
* `usePublicSearch` and the lead helpers emit them from `analyticsSince`.
|
|
3566
|
+
* Below it `studioListingViewInstruction` prints nothing and
|
|
3567
|
+
* `studioCodegenContractViolations` flags `trackListingView`.
|
|
3568
|
+
*/
|
|
3569
|
+
analyticsExports: ["trackListingView"],
|
|
3570
|
+
analyticsSince: "0.13.0"
|
|
3522
3571
|
};
|
|
3523
3572
|
function isSellerLeadOnPin(pin = STUDIO_SDK_CONTRACT.minNpmVersion) {
|
|
3524
3573
|
return compareSemver(pin, STUDIO_SDK_CONTRACT.sellerLeadSince) >= 0;
|
|
@@ -3526,6 +3575,14 @@ function isSellerLeadOnPin(pin = STUDIO_SDK_CONTRACT.minNpmVersion) {
|
|
|
3526
3575
|
function isShareLinkOnPin(pin = STUDIO_SDK_CONTRACT.minNpmVersion) {
|
|
3527
3576
|
return compareSemver(pin, STUDIO_SDK_CONTRACT.shareLinkSince) >= 0;
|
|
3528
3577
|
}
|
|
3578
|
+
function isAnalyticsOnPin(pin = STUDIO_SDK_CONTRACT.minNpmVersion) {
|
|
3579
|
+
return compareSemver(pin, STUDIO_SDK_CONTRACT.analyticsSince) >= 0;
|
|
3580
|
+
}
|
|
3581
|
+
function studioListingViewInstruction(pin = STUDIO_SDK_CONTRACT.minNpmVersion) {
|
|
3582
|
+
if (!isAnalyticsOnPin(pin)) return "";
|
|
3583
|
+
const name = STUDIO_SDK_CONTRACT.analyticsExports[0];
|
|
3584
|
+
return `Listing view analytics: import ${name} from \`${STUDIO_SDK_PACKAGE}\` in a client component the listing page already renders (the visit/contact component is the usual place) and call \`useEffect(() => { ${name}(listing); }, [listing.id])\`. Call it once per listing page, never in a card, carousel or similar-listings loop. Do not build or post the event yourself.`;
|
|
3585
|
+
}
|
|
3529
3586
|
function studioShareLinkInstruction(pin = STUDIO_SDK_CONTRACT.minNpmVersion) {
|
|
3530
3587
|
if (!isShareLinkOnPin(pin)) return "";
|
|
3531
3588
|
const name = STUDIO_SDK_CONTRACT.shareExports[0];
|
|
@@ -3783,6 +3840,13 @@ function studioCodegenContractViolations(text2) {
|
|
|
3783
3840
|
}
|
|
3784
3841
|
}
|
|
3785
3842
|
}
|
|
3843
|
+
if (!isAnalyticsOnPin()) {
|
|
3844
|
+
for (const name of STUDIO_SDK_CONTRACT.analyticsExports) {
|
|
3845
|
+
if (mentionsExportName(text2, name) && !violations.includes(name)) {
|
|
3846
|
+
violations.push(name);
|
|
3847
|
+
}
|
|
3848
|
+
}
|
|
3849
|
+
}
|
|
3786
3850
|
const pin = STUDIO_SDK_CONTRACT.minNpmVersion;
|
|
3787
3851
|
if (!marketExportsAvailableAt(pin)) {
|
|
3788
3852
|
for (const name of STUDIO_SDK_CONTRACT.marketExports) {
|
|
@@ -5143,6 +5207,7 @@ function applyMatchedPhotoCover(cards, photoResults, options = {}) {
|
|
|
5143
5207
|
SELLER_LEAD_PHOTO_MAX_BYTES,
|
|
5144
5208
|
SELLER_LEAD_PHOTO_MAX_COUNT,
|
|
5145
5209
|
SELLER_LEAD_PHOTO_TYPES,
|
|
5210
|
+
SITE_ANALYTICS_EVENT,
|
|
5146
5211
|
STUDIO_DEFAULT_PHOTO_SCHEDULE_CONFIG,
|
|
5147
5212
|
STUDIO_DEFAULT_VISIT_SCHEDULE,
|
|
5148
5213
|
STUDIO_SDK_CONTRACT,
|
|
@@ -5203,6 +5268,7 @@ function applyMatchedPhotoCover(cards, photoResults, options = {}) {
|
|
|
5203
5268
|
hrefForAppliedChange,
|
|
5204
5269
|
hrefForPathFilters,
|
|
5205
5270
|
hrefWithExplicitPage,
|
|
5271
|
+
isAnalyticsOnPin,
|
|
5206
5272
|
isListingDetailPath,
|
|
5207
5273
|
isMapBounds,
|
|
5208
5274
|
isMapPolygon,
|
|
@@ -5293,6 +5359,7 @@ function applyMatchedPhotoCover(cards, photoResults, options = {}) {
|
|
|
5293
5359
|
studioLeadInstruction,
|
|
5294
5360
|
studioListingCardInstruction,
|
|
5295
5361
|
studioListingDetailInstruction,
|
|
5362
|
+
studioListingViewInstruction,
|
|
5296
5363
|
studioMapSearchInstruction,
|
|
5297
5364
|
studioMapsInstruction,
|
|
5298
5365
|
studioMarketInstruction,
|
|
@@ -5312,6 +5379,7 @@ function applyMatchedPhotoCover(cards, photoResults, options = {}) {
|
|
|
5312
5379
|
toE164,
|
|
5313
5380
|
toListingCardModel,
|
|
5314
5381
|
toolbarFilterIds,
|
|
5382
|
+
trackListingView,
|
|
5315
5383
|
travelTimeCacheKey,
|
|
5316
5384
|
travelTimeFromListing,
|
|
5317
5385
|
travelTimesFromListing,
|