@garagem-ai/site-sdk 0.3.0 → 0.4.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/README.md +59 -3
- package/dist/index.d.mts +27 -361
- package/dist/index.d.ts +27 -361
- package/dist/index.js +530 -50
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +493 -46
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.mts +163 -0
- package/dist/react.d.ts +163 -0
- package/dist/react.js +2124 -0
- package/dist/react.js.map +1 -0
- package/dist/react.mjs +2083 -0
- package/dist/react.mjs.map +1 -0
- package/dist/search-engine-D4EZkNrQ.d.mts +468 -0
- package/dist/search-engine-D4EZkNrQ.d.ts +468 -0
- package/package.json +42 -4
- package/src/fetchers.ts +27 -18
- package/src/index.ts +44 -0
- package/src/internal/url.ts +14 -0
- package/src/listing-card-model.ts +90 -0
- package/src/presentation.ts +79 -0
- package/src/react/cn.ts +3 -0
- package/src/react/filter-panel.tsx +248 -0
- package/src/react/icons.tsx +46 -0
- package/src/react/index.ts +26 -0
- package/src/react/listing-card.tsx +86 -0
- package/src/react/search-chrome.tsx +73 -0
- package/src/react/search-page.tsx +465 -0
- package/src/react/search-pagination.tsx +120 -0
- package/src/react/search-query-form.tsx +81 -0
- package/src/react/search.css +717 -0
- package/src/react/styles/index.ts +1 -0
- package/src/react/styles/search-chrome-css.generated.ts +5 -0
- package/src/react/styles/search-chrome-styles.tsx +12 -0
- package/src/react/types.ts +106 -0
- package/src/react/use-public-search.ts +304 -0
- package/src/search-engine.ts +483 -0
package/dist/index.mjs
CHANGED
|
@@ -18,6 +18,15 @@ function normalizeBaseUrl(baseUrl) {
|
|
|
18
18
|
const url = baseUrl ?? DEFAULT_BASE_URL;
|
|
19
19
|
return url.endsWith("/") ? url.slice(0, -1) : url;
|
|
20
20
|
}
|
|
21
|
+
async function coerceSiteId(siteId) {
|
|
22
|
+
const value = await Promise.resolve(siteId);
|
|
23
|
+
if (typeof value !== "string" || !value.trim()) {
|
|
24
|
+
throw new TypeError(
|
|
25
|
+
"Garagem SDK: siteId must be a string. Await resolveSiteId(...) before getListings / getSearchUi / queryListings."
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
21
30
|
function buildListingFiltersQuery(filters) {
|
|
22
31
|
const params = new URLSearchParams();
|
|
23
32
|
if (!filters) return params;
|
|
@@ -57,7 +66,8 @@ var GaragemSdkError = class extends Error {
|
|
|
57
66
|
}
|
|
58
67
|
};
|
|
59
68
|
async function getListings(options) {
|
|
60
|
-
const {
|
|
69
|
+
const { filters, baseUrl, fetch: fetchImpl, next } = options;
|
|
70
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
61
71
|
const base = normalizeBaseUrl(baseUrl);
|
|
62
72
|
const params = buildListingFiltersQuery(filters);
|
|
63
73
|
const qs = params.size > 0 ? `?${params.toString()}` : "";
|
|
@@ -73,13 +83,8 @@ async function getListings(options) {
|
|
|
73
83
|
};
|
|
74
84
|
}
|
|
75
85
|
async function getListing(options) {
|
|
76
|
-
const {
|
|
77
|
-
|
|
78
|
-
listingId: rawListingId,
|
|
79
|
-
baseUrl,
|
|
80
|
-
fetch: fetchImpl,
|
|
81
|
-
next
|
|
82
|
-
} = options;
|
|
86
|
+
const { listingId: rawListingId, baseUrl, fetch: fetchImpl, next } = options;
|
|
87
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
83
88
|
const listingId = listingLookupKey(rawListingId ?? "");
|
|
84
89
|
if (!listingId || listingId === "undefined" || listingId === "null") {
|
|
85
90
|
throw new TypeError("getListing: `listingId` is required");
|
|
@@ -95,7 +100,8 @@ async function getListing(options) {
|
|
|
95
100
|
);
|
|
96
101
|
}
|
|
97
102
|
async function getSite(options) {
|
|
98
|
-
const {
|
|
103
|
+
const { domain, baseUrl, fetch: fetchImpl, next } = options;
|
|
104
|
+
const siteId = options.siteId ? await coerceSiteId(options.siteId) : void 0;
|
|
99
105
|
if (!siteId && !domain) {
|
|
100
106
|
throw new TypeError(
|
|
101
107
|
"getSite: provide exactly one of `siteId` or `domain`."
|
|
@@ -133,7 +139,8 @@ async function getSite(options) {
|
|
|
133
139
|
};
|
|
134
140
|
}
|
|
135
141
|
async function searchListings(options) {
|
|
136
|
-
const {
|
|
142
|
+
const { params, baseUrl, fetch: fetchImpl, next } = options;
|
|
143
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
137
144
|
if (!params || typeof params.q !== "string") {
|
|
138
145
|
throw new TypeError(
|
|
139
146
|
"Garagem SDK: searchListings requires `params.q` (Typesense query string)."
|
|
@@ -153,7 +160,8 @@ async function searchListings(options) {
|
|
|
153
160
|
);
|
|
154
161
|
}
|
|
155
162
|
async function getSearchUi(options) {
|
|
156
|
-
const {
|
|
163
|
+
const { baseUrl, fetch: fetchImpl, next } = options;
|
|
164
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
157
165
|
const base = normalizeBaseUrl(baseUrl);
|
|
158
166
|
const url = `${base}/api/sites/${encodeURIComponent(siteId)}/search-ui`;
|
|
159
167
|
return callJson(
|
|
@@ -163,7 +171,8 @@ async function getSearchUi(options) {
|
|
|
163
171
|
);
|
|
164
172
|
}
|
|
165
173
|
async function queryListings(options) {
|
|
166
|
-
const {
|
|
174
|
+
const { params, baseUrl, fetch: fetchImpl, next } = options;
|
|
175
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
167
176
|
const base = normalizeBaseUrl(baseUrl);
|
|
168
177
|
const url = `${base}/api/sites/${encodeURIComponent(siteId)}/search/listings`;
|
|
169
178
|
return callJson(
|
|
@@ -182,13 +191,13 @@ async function queryListings(options) {
|
|
|
182
191
|
}
|
|
183
192
|
async function getSimilarListings(options) {
|
|
184
193
|
const {
|
|
185
|
-
siteId,
|
|
186
194
|
listingId: rawListingId,
|
|
187
195
|
limit,
|
|
188
196
|
baseUrl,
|
|
189
197
|
fetch: fetchImpl,
|
|
190
198
|
next
|
|
191
199
|
} = options;
|
|
200
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
192
201
|
const listingId = listingLookupKey(rawListingId ?? "");
|
|
193
202
|
if (!listingId || listingId === "undefined" || listingId === "null") {
|
|
194
203
|
throw new TypeError("getSimilarListings: `listingId` is required");
|
|
@@ -213,7 +222,8 @@ async function getSimilarListings(options) {
|
|
|
213
222
|
};
|
|
214
223
|
}
|
|
215
224
|
async function getCmsCollections(options) {
|
|
216
|
-
const {
|
|
225
|
+
const { baseUrl, fetch: fetchImpl, next } = options;
|
|
226
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
217
227
|
const base = normalizeBaseUrl(baseUrl);
|
|
218
228
|
const url = `${base}/api/sites/${encodeURIComponent(siteId)}/cms/collections`;
|
|
219
229
|
const data = await callJson(
|
|
@@ -224,7 +234,8 @@ async function getCmsCollections(options) {
|
|
|
224
234
|
return data.collections ?? [];
|
|
225
235
|
}
|
|
226
236
|
async function getCmsCollection(options) {
|
|
227
|
-
const {
|
|
237
|
+
const { slug, baseUrl, fetch: fetchImpl, next } = options;
|
|
238
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
228
239
|
if (!slug) {
|
|
229
240
|
throw new TypeError("getCmsCollection: `slug` is required");
|
|
230
241
|
}
|
|
@@ -244,7 +255,6 @@ async function getCmsCollection(options) {
|
|
|
244
255
|
}
|
|
245
256
|
async function getCmsEntries(options) {
|
|
246
257
|
const {
|
|
247
|
-
siteId,
|
|
248
258
|
collection,
|
|
249
259
|
limit,
|
|
250
260
|
offset,
|
|
@@ -252,6 +262,7 @@ async function getCmsEntries(options) {
|
|
|
252
262
|
fetch: fetchImpl,
|
|
253
263
|
next
|
|
254
264
|
} = options;
|
|
265
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
255
266
|
if (!collection) {
|
|
256
267
|
throw new TypeError("getCmsEntries: `collection` is required");
|
|
257
268
|
}
|
|
@@ -280,7 +291,8 @@ async function getCmsEntries(options) {
|
|
|
280
291
|
};
|
|
281
292
|
}
|
|
282
293
|
async function getCmsEntry(options) {
|
|
283
|
-
const {
|
|
294
|
+
const { collection, slug, baseUrl, fetch: fetchImpl, next } = options;
|
|
295
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
284
296
|
if (!collection) {
|
|
285
297
|
throw new TypeError("getCmsEntry: `collection` is required");
|
|
286
298
|
}
|
|
@@ -302,6 +314,92 @@ async function getCmsEntry(options) {
|
|
|
302
314
|
return data;
|
|
303
315
|
}
|
|
304
316
|
|
|
317
|
+
// src/presentation.ts
|
|
318
|
+
var SEARCH_CSS_VARS = {
|
|
319
|
+
cardRadius: "--garagem-listing-card-radius",
|
|
320
|
+
cardGap: "--garagem-listing-card-gap",
|
|
321
|
+
priceSize: "--garagem-listing-price-size",
|
|
322
|
+
mediaRatio: "--garagem-listing-media-ratio",
|
|
323
|
+
controlHeight: "--garagem-search-control-height",
|
|
324
|
+
iconSize: "--garagem-search-icon-size",
|
|
325
|
+
skeleton: "--garagem-skeleton"
|
|
326
|
+
};
|
|
327
|
+
var SEARCH_CSS_RECIPE = `:root {
|
|
328
|
+
${SEARCH_CSS_VARS.cardRadius}: 0.75rem;
|
|
329
|
+
${SEARCH_CSS_VARS.cardGap}: 1.5rem;
|
|
330
|
+
${SEARCH_CSS_VARS.priceSize}: 1.125rem;
|
|
331
|
+
${SEARCH_CSS_VARS.mediaRatio}: 4 / 3;
|
|
332
|
+
${SEARCH_CSS_VARS.controlHeight}: 2.75rem;
|
|
333
|
+
${SEARCH_CSS_VARS.iconSize}: 1.25rem;
|
|
334
|
+
${SEARCH_CSS_VARS.skeleton}: var(--muted, #e7e5e4);
|
|
335
|
+
}
|
|
336
|
+
`;
|
|
337
|
+
function formatListingPrice(amount, locale = "pt-BR", currency = "BRL") {
|
|
338
|
+
if (amount == null) return "Sob consulta";
|
|
339
|
+
try {
|
|
340
|
+
return new Intl.NumberFormat(locale, {
|
|
341
|
+
style: "currency",
|
|
342
|
+
currency,
|
|
343
|
+
minimumFractionDigits: 0,
|
|
344
|
+
maximumFractionDigits: 0
|
|
345
|
+
}).format(amount);
|
|
346
|
+
} catch {
|
|
347
|
+
return `${currency} ${amount}`;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
function formatGroupedInteger(value, locale = "pt-BR") {
|
|
351
|
+
const digits = String(value ?? "").replace(/\D/g, "");
|
|
352
|
+
if (!digits) return "";
|
|
353
|
+
const amount = Number.parseInt(digits, 10);
|
|
354
|
+
if (!Number.isFinite(amount)) return "";
|
|
355
|
+
return new Intl.NumberFormat(locale, { maximumFractionDigits: 0 }).format(
|
|
356
|
+
amount
|
|
357
|
+
);
|
|
358
|
+
}
|
|
359
|
+
function parseGroupedInteger(value) {
|
|
360
|
+
if (typeof value === "number") {
|
|
361
|
+
return Number.isFinite(value) ? Math.trunc(value) : void 0;
|
|
362
|
+
}
|
|
363
|
+
const digits = String(value ?? "").replace(/\D/g, "");
|
|
364
|
+
if (!digits) return void 0;
|
|
365
|
+
const amount = Number.parseInt(digits, 10);
|
|
366
|
+
return Number.isFinite(amount) ? amount : void 0;
|
|
367
|
+
}
|
|
368
|
+
function formatAreaM2(area) {
|
|
369
|
+
if (area == null || !Number.isFinite(area)) return null;
|
|
370
|
+
return `${area} m\xB2`;
|
|
371
|
+
}
|
|
372
|
+
function listingBusinessLabel(businessType) {
|
|
373
|
+
return businessType === "rental" ? "Aluguel" : "Venda";
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// src/listing-card-model.ts
|
|
377
|
+
function listingLocationLabel(location) {
|
|
378
|
+
return [location.neighborhood, location.city, location.state].map((part) => part ? String(part).trim() : "").filter(Boolean).join(", ");
|
|
379
|
+
}
|
|
380
|
+
function toListingCardModel(listing) {
|
|
381
|
+
const isPrivate = listing.priceVisibility === "private";
|
|
382
|
+
const area = listing.property?.usableArea ?? listing.property?.totalArea;
|
|
383
|
+
return {
|
|
384
|
+
href: listingPublicPath(listing),
|
|
385
|
+
title: listing.title,
|
|
386
|
+
businessType: listing.businessType,
|
|
387
|
+
businessLabel: listingBusinessLabel(listing.businessType),
|
|
388
|
+
priceVisibility: listing.priceVisibility,
|
|
389
|
+
price: listing.price,
|
|
390
|
+
priceLabel: isPrivate ? "Sob consulta" : formatListingPrice(listing.price),
|
|
391
|
+
pricePeriod: listing.businessType === "rental" && !isPrivate && listing.price != null ? "/m\xEAs" : null,
|
|
392
|
+
locationLabel: listingLocationLabel(listing.location || {}),
|
|
393
|
+
propertyType: listing.property?.type ?? null,
|
|
394
|
+
coverSrc: listing.coverImage?.src ?? null,
|
|
395
|
+
coverAlt: listing.coverImage?.alt ?? listing.title,
|
|
396
|
+
bedrooms: listing.property?.bedrooms ?? null,
|
|
397
|
+
bathrooms: listing.property?.bathrooms ?? null,
|
|
398
|
+
parkingSpaces: listing.property?.parkingSpaces ?? null,
|
|
399
|
+
areaM2: area ?? null
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
|
|
305
403
|
// ../search-url/types.ts
|
|
306
404
|
var SEARCH_BASE_ROUTE = "imoveis";
|
|
307
405
|
var MAX_PAGE = 1e4;
|
|
@@ -675,6 +773,42 @@ function composeSearchPublicHref(pathname, query, existingSearch) {
|
|
|
675
773
|
return qs ? `${pathname}?${qs}` : pathname;
|
|
676
774
|
}
|
|
677
775
|
|
|
776
|
+
// src/applied-query.ts
|
|
777
|
+
function parseAppliedSearchQuery2(search) {
|
|
778
|
+
return parseAppliedSearchQuery(search);
|
|
779
|
+
}
|
|
780
|
+
function serializeAppliedSearchQuery2(query) {
|
|
781
|
+
return serializeAppliedSearchQuery(query);
|
|
782
|
+
}
|
|
783
|
+
function mergeAppliedSearchQueryIntoSearch2(existing, query) {
|
|
784
|
+
return mergeAppliedSearchQueryIntoSearch(existing, query);
|
|
785
|
+
}
|
|
786
|
+
function reduceAppliedSearchQuery2(prev, change) {
|
|
787
|
+
return reduceAppliedSearchQuery(prev, change);
|
|
788
|
+
}
|
|
789
|
+
function composeSearchPublicHref2(pathname, query, existingSearch) {
|
|
790
|
+
return composeSearchPublicHref(pathname, query, existingSearch);
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
// src/loc-params.ts
|
|
794
|
+
function pathLocationToFilterInput(location) {
|
|
795
|
+
if (!location || typeof location !== "object") return null;
|
|
796
|
+
const { state, city, neighborhood, street } = location;
|
|
797
|
+
const levels = [];
|
|
798
|
+
if (state) levels.push(state);
|
|
799
|
+
if (city) levels.push(city);
|
|
800
|
+
if (neighborhood) levels.push(neighborhood);
|
|
801
|
+
if (street) levels.push(street);
|
|
802
|
+
if (levels.length === 0) return null;
|
|
803
|
+
if (levels.length === 1) {
|
|
804
|
+
if (state) return { type: "state", value: state };
|
|
805
|
+
if (city) return { type: "city", value: city };
|
|
806
|
+
if (neighborhood) return { type: "neighborhood", value: neighborhood };
|
|
807
|
+
if (street) return { type: "street", value: street };
|
|
808
|
+
}
|
|
809
|
+
return { type: "path", value: levels.join("/") };
|
|
810
|
+
}
|
|
811
|
+
|
|
678
812
|
// src/path.ts
|
|
679
813
|
function composeSearchPublicPath2(filters, dictionary) {
|
|
680
814
|
return dictionary ? composeSearchPublicPath(filters, dictionary) : composeSearchPublicPath(filters);
|
|
@@ -717,40 +851,320 @@ function pathFiltersToQueryFilters(pathFilters) {
|
|
|
717
851
|
return result;
|
|
718
852
|
}
|
|
719
853
|
|
|
720
|
-
// src/
|
|
721
|
-
|
|
722
|
-
|
|
854
|
+
// src/search-engine.ts
|
|
855
|
+
var PATH_FILTER_IDS = {
|
|
856
|
+
listing_type: "listingType",
|
|
857
|
+
property_type: "propertyType",
|
|
858
|
+
property_bedrooms: "bedrooms",
|
|
859
|
+
property_bathrooms: "bathrooms",
|
|
860
|
+
property_suites: "suites",
|
|
861
|
+
property_parking_spots: "parkingSpots",
|
|
862
|
+
price: "price",
|
|
863
|
+
property_area_total: "area",
|
|
864
|
+
propertyFeatures: "propertyFeatures",
|
|
865
|
+
buildingAmenities: "buildingAmenities"
|
|
866
|
+
};
|
|
867
|
+
var FORBIDDEN_SEARCH_QUERY_KEYS = [
|
|
868
|
+
"tipo",
|
|
869
|
+
"quartos",
|
|
870
|
+
"tipo-imovel",
|
|
871
|
+
"banheiros",
|
|
872
|
+
"vagas"
|
|
873
|
+
];
|
|
874
|
+
var SEARCH_SORT_RELEVANCE = {
|
|
875
|
+
id: "",
|
|
876
|
+
label: "Mais relevantes"
|
|
877
|
+
};
|
|
878
|
+
function searchSortOptions(sorts) {
|
|
879
|
+
const fromApi = (sorts || []).filter((sort) => sort.id);
|
|
880
|
+
return [
|
|
881
|
+
{ id: SEARCH_SORT_RELEVANCE.id, label: SEARCH_SORT_RELEVANCE.label },
|
|
882
|
+
...fromApi
|
|
883
|
+
];
|
|
723
884
|
}
|
|
724
|
-
|
|
725
|
-
|
|
885
|
+
var TOOLBAR_PRIMARY_FILTER_IDS = [
|
|
886
|
+
"price",
|
|
887
|
+
"property_bedrooms"
|
|
888
|
+
];
|
|
889
|
+
var HIDDEN_FILTER_IDS = /* @__PURE__ */ new Set(["property_suites"]);
|
|
890
|
+
function toFiniteNumber(value) {
|
|
891
|
+
if (value === "" || value == null) return void 0;
|
|
892
|
+
const n = Number(value);
|
|
893
|
+
return Number.isFinite(n) ? n : void 0;
|
|
726
894
|
}
|
|
727
|
-
function
|
|
728
|
-
return
|
|
895
|
+
function pathnameOnly(pathname) {
|
|
896
|
+
return String(pathname || "").split(/[?#]/)[0] || "/";
|
|
729
897
|
}
|
|
730
|
-
function
|
|
731
|
-
|
|
898
|
+
function isListingDetailPath(pathname) {
|
|
899
|
+
const parts = pathnameOnly(pathname).split("/").filter(Boolean);
|
|
900
|
+
const last = parts[parts.length - 1] || "";
|
|
901
|
+
return last.toLowerCase().startsWith("id-");
|
|
732
902
|
}
|
|
733
|
-
function
|
|
734
|
-
|
|
903
|
+
function readPublicSearch(pathname, search, dictionary) {
|
|
904
|
+
const pathFilters = parseSearchPublicPath2(pathnameOnly(pathname), dictionary) || {};
|
|
905
|
+
const applied = parseAppliedSearchQuery2(search || "");
|
|
906
|
+
return { pathFilters, applied };
|
|
735
907
|
}
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
908
|
+
function lookupDisplay(table, slug) {
|
|
909
|
+
if (!slug || !table) return slug;
|
|
910
|
+
return table[slug] || table[String(slug).toLowerCase()] || slug;
|
|
911
|
+
}
|
|
912
|
+
function displayPathLocation(location, values) {
|
|
913
|
+
if (!location) return null;
|
|
914
|
+
const table = values || {};
|
|
915
|
+
return {
|
|
916
|
+
state: lookupDisplay(table.states, location.state),
|
|
917
|
+
city: lookupDisplay(table.cities, location.city),
|
|
918
|
+
neighborhood: lookupDisplay(table.neighborhoods, location.neighborhood),
|
|
919
|
+
street: lookupDisplay(table.streets, location.street)
|
|
920
|
+
};
|
|
921
|
+
}
|
|
922
|
+
function buildQueryListingsParams(pathFilters, applied, schema, locationValues) {
|
|
923
|
+
const filters = pathFiltersToQueryFilters(pathFilters || {});
|
|
924
|
+
const locations = [];
|
|
925
|
+
const displayed = displayPathLocation(pathFilters?.location, locationValues);
|
|
926
|
+
const pathLoc = displayed ? pathLocationToFilterInput(displayed) : null;
|
|
927
|
+
if (pathLoc) locations.push(pathLoc);
|
|
928
|
+
for (const value of applied?.loc || []) {
|
|
929
|
+
locations.push({ type: "loc", value });
|
|
752
930
|
}
|
|
753
|
-
|
|
931
|
+
const params = {
|
|
932
|
+
page: applied?.page || 1,
|
|
933
|
+
limit: schema?.defaultLimit || 12,
|
|
934
|
+
filters
|
|
935
|
+
};
|
|
936
|
+
if (applied?.sort) params.sort = applied.sort;
|
|
937
|
+
const hasLocation = locations.length > 0;
|
|
938
|
+
if (applied?.query && !hasLocation) params.q = applied.query;
|
|
939
|
+
if (hasLocation) params.location = locations;
|
|
940
|
+
return params;
|
|
941
|
+
}
|
|
942
|
+
function applyPathFilter(pathFilters, filterId, value) {
|
|
943
|
+
const next = { ...pathFilters || {} };
|
|
944
|
+
const key = PATH_FILTER_IDS[filterId];
|
|
945
|
+
if (!key) return next;
|
|
946
|
+
if (value === "" || value == null) {
|
|
947
|
+
delete next[key];
|
|
948
|
+
return next;
|
|
949
|
+
}
|
|
950
|
+
if (key === "price" || key === "area") {
|
|
951
|
+
const range = value || {};
|
|
952
|
+
const parse = key === "price" ? parseGroupedInteger : toFiniteNumber;
|
|
953
|
+
const min = parse(range.min);
|
|
954
|
+
const max = parse(range.max);
|
|
955
|
+
if (min == null && max == null) {
|
|
956
|
+
delete next[key];
|
|
957
|
+
return next;
|
|
958
|
+
}
|
|
959
|
+
next[key] = {
|
|
960
|
+
...min != null ? { min } : {},
|
|
961
|
+
...max != null ? { max } : {}
|
|
962
|
+
};
|
|
963
|
+
return next;
|
|
964
|
+
}
|
|
965
|
+
if (key === "propertyFeatures" || key === "buildingAmenities") {
|
|
966
|
+
const current = Array.isArray(next[key]) ? [...next[key]] : [];
|
|
967
|
+
const id = String(value);
|
|
968
|
+
const i = current.indexOf(id);
|
|
969
|
+
if (i >= 0) current.splice(i, 1);
|
|
970
|
+
else current.push(id);
|
|
971
|
+
if (current.length) next[key] = current;
|
|
972
|
+
else delete next[key];
|
|
973
|
+
return next;
|
|
974
|
+
}
|
|
975
|
+
if (key === "propertyType") {
|
|
976
|
+
const id = String(value);
|
|
977
|
+
const current = Array.isArray(next.propertyType) ? [...next.propertyType] : next.propertyType ? [String(next.propertyType)] : [];
|
|
978
|
+
const i = current.indexOf(id);
|
|
979
|
+
if (i >= 0) current.splice(i, 1);
|
|
980
|
+
else current.push(id);
|
|
981
|
+
if (current.length === 0) delete next.propertyType;
|
|
982
|
+
else if (current.length === 1) next.propertyType = current[0];
|
|
983
|
+
else next.propertyType = current;
|
|
984
|
+
return next;
|
|
985
|
+
}
|
|
986
|
+
if (key === "listingType") {
|
|
987
|
+
const id = String(value);
|
|
988
|
+
if (next.listingType === id) delete next.listingType;
|
|
989
|
+
else next.listingType = id;
|
|
990
|
+
return next;
|
|
991
|
+
}
|
|
992
|
+
if (key === "bedrooms" || key === "bathrooms" || key === "suites" || key === "parkingSpots") {
|
|
993
|
+
const n = Number(value);
|
|
994
|
+
if (!Number.isFinite(n)) {
|
|
995
|
+
delete next[key];
|
|
996
|
+
return next;
|
|
997
|
+
}
|
|
998
|
+
if (next[key] === n) delete next[key];
|
|
999
|
+
else next[key] = n;
|
|
1000
|
+
return next;
|
|
1001
|
+
}
|
|
1002
|
+
return next;
|
|
1003
|
+
}
|
|
1004
|
+
function pathFilterValue(pathFilters, filterId) {
|
|
1005
|
+
const key = PATH_FILTER_IDS[filterId];
|
|
1006
|
+
const value = pathFilters && key ? pathFilters[key] : void 0;
|
|
1007
|
+
if (value == null) return "";
|
|
1008
|
+
if (Array.isArray(value)) return value[0] != null ? String(value[0]) : "";
|
|
1009
|
+
if (typeof value === "object") return "";
|
|
1010
|
+
return String(value);
|
|
1011
|
+
}
|
|
1012
|
+
function pathFilterHasOption(pathFilters, filterId, optionId) {
|
|
1013
|
+
const key = PATH_FILTER_IDS[filterId];
|
|
1014
|
+
const value = pathFilters && key ? pathFilters[key] : void 0;
|
|
1015
|
+
if (value == null) return false;
|
|
1016
|
+
if (Array.isArray(value)) return value.map(String).includes(optionId);
|
|
1017
|
+
if (typeof value === "object") return false;
|
|
1018
|
+
return String(value) === optionId;
|
|
1019
|
+
}
|
|
1020
|
+
function publicSearchHref(pathFilters, applied, dictionary, existingSearch) {
|
|
1021
|
+
const pathname = composeSearchPublicPath2(pathFilters || {}, dictionary);
|
|
1022
|
+
return composeSearchPublicHref2(pathname, applied || {}, existingSearch);
|
|
1023
|
+
}
|
|
1024
|
+
function hrefForPathFilters(pathname, search, dictionary, nextPathFilters) {
|
|
1025
|
+
const { applied } = readPublicSearch(pathname, search, dictionary);
|
|
1026
|
+
const nextApplied = reduceAppliedSearchQuery2(applied, {
|
|
1027
|
+
type: "applyFilters"
|
|
1028
|
+
});
|
|
1029
|
+
return publicSearchHref(nextPathFilters, nextApplied, dictionary, search);
|
|
1030
|
+
}
|
|
1031
|
+
function hrefForAppliedChange(pathname, search, dictionary, change) {
|
|
1032
|
+
const { pathFilters, applied } = readPublicSearch(
|
|
1033
|
+
pathname,
|
|
1034
|
+
search,
|
|
1035
|
+
dictionary
|
|
1036
|
+
);
|
|
1037
|
+
let nextPath = pathFilters;
|
|
1038
|
+
if (change && change.type === "query") {
|
|
1039
|
+
nextPath = { ...pathFilters };
|
|
1040
|
+
delete nextPath.location;
|
|
1041
|
+
}
|
|
1042
|
+
const nextApplied = reduceAppliedSearchQuery2(applied, change);
|
|
1043
|
+
return publicSearchHref(nextPath, nextApplied, dictionary, search);
|
|
1044
|
+
}
|
|
1045
|
+
function currentSearchHref(pathname, search) {
|
|
1046
|
+
const path = pathnameOnly(pathname);
|
|
1047
|
+
const qs = search.replace(/^\?/, "");
|
|
1048
|
+
return qs ? `${path}?${qs}` : path;
|
|
1049
|
+
}
|
|
1050
|
+
function canonicalizeSearchHref(pathname, search, dictionary) {
|
|
1051
|
+
const { pathFilters, applied } = readPublicSearch(
|
|
1052
|
+
pathname,
|
|
1053
|
+
search,
|
|
1054
|
+
dictionary
|
|
1055
|
+
);
|
|
1056
|
+
const href = publicSearchHref(pathFilters, applied, dictionary, search);
|
|
1057
|
+
if (href === currentSearchHref(pathname, search)) return null;
|
|
1058
|
+
return href;
|
|
1059
|
+
}
|
|
1060
|
+
function searchHrefUsesLegacyFilterQuery(href) {
|
|
1061
|
+
const query = href.split("?")[1] || "";
|
|
1062
|
+
const params = new URLSearchParams(query);
|
|
1063
|
+
return FORBIDDEN_SEARCH_QUERY_KEYS.some((key) => params.has(key));
|
|
1064
|
+
}
|
|
1065
|
+
function clearStagedPathFilters(current, keepFilterIds = []) {
|
|
1066
|
+
const next = current.location ? { location: current.location } : {};
|
|
1067
|
+
for (const id of keepFilterIds) {
|
|
1068
|
+
const key = PATH_FILTER_IDS[id];
|
|
1069
|
+
if (!key || key === "location") continue;
|
|
1070
|
+
const value = current[key];
|
|
1071
|
+
if (value != null) Object.assign(next, { [key]: value });
|
|
1072
|
+
}
|
|
1073
|
+
return next;
|
|
1074
|
+
}
|
|
1075
|
+
function visibleSearchFilters(schema) {
|
|
1076
|
+
if (!schema?.filters) return [];
|
|
1077
|
+
return schema.filters.filter((filter) => {
|
|
1078
|
+
if (HIDDEN_FILTER_IDS.has(filter.id)) return false;
|
|
1079
|
+
if (filter.id === "listing_type" && (filter.options?.length ?? 0) <= 1) {
|
|
1080
|
+
return false;
|
|
1081
|
+
}
|
|
1082
|
+
return true;
|
|
1083
|
+
});
|
|
1084
|
+
}
|
|
1085
|
+
function toolbarFilterIds(schema) {
|
|
1086
|
+
const visible = new Set(visibleSearchFilters(schema).map((f) => f.id));
|
|
1087
|
+
return TOOLBAR_PRIMARY_FILTER_IDS.filter((id) => visible.has(id));
|
|
1088
|
+
}
|
|
1089
|
+
function countOptionLabel(option) {
|
|
1090
|
+
const label = String(option?.label ?? "");
|
|
1091
|
+
if (/^[1-9]\d*$/.test(label)) return `${label}+`;
|
|
1092
|
+
return label;
|
|
1093
|
+
}
|
|
1094
|
+
function countFacetChoices(options) {
|
|
1095
|
+
const list = options || [];
|
|
1096
|
+
const zero = list.find((o) => o.id === "0" || o.label === "Studio");
|
|
1097
|
+
const isStudio = Boolean(
|
|
1098
|
+
zero && /studio/i.test(String(zero.label)) && zero.id === "0"
|
|
1099
|
+
);
|
|
1100
|
+
const max = isStudio ? 3 : 4;
|
|
1101
|
+
const out = [];
|
|
1102
|
+
if (zero) out.push({ id: zero.id, label: countOptionLabel(zero) });
|
|
1103
|
+
for (let n = 1; n <= max; n += 1) {
|
|
1104
|
+
const option = list.find((o) => o.id === String(n));
|
|
1105
|
+
out.push({
|
|
1106
|
+
id: String(n),
|
|
1107
|
+
label: countOptionLabel(option || { label: String(n) })
|
|
1108
|
+
});
|
|
1109
|
+
}
|
|
1110
|
+
return out;
|
|
1111
|
+
}
|
|
1112
|
+
var FEMININE_HEADING = /(casa|cobertura|kitnet|loja|sala|fazenda|chácara|chacara)s?$/i;
|
|
1113
|
+
function pluralizePt(label) {
|
|
1114
|
+
const text = label.trim();
|
|
1115
|
+
if (!text || /s$/i.test(text)) return text;
|
|
1116
|
+
if (/il$/i.test(text)) return `${text.slice(0, -1)}is`;
|
|
1117
|
+
if (/m$/i.test(text)) return `${text.slice(0, -1)}ns`;
|
|
1118
|
+
return `${text}s`;
|
|
1119
|
+
}
|
|
1120
|
+
function headingLocationSuffix(location) {
|
|
1121
|
+
if (!location) return "";
|
|
1122
|
+
if (location.street && location.neighborhood) {
|
|
1123
|
+
return `${location.street}, ${location.neighborhood}`;
|
|
1124
|
+
}
|
|
1125
|
+
if (location.neighborhood && location.city) {
|
|
1126
|
+
return `${location.neighborhood}, ${location.city}`;
|
|
1127
|
+
}
|
|
1128
|
+
if (location.city && location.state) {
|
|
1129
|
+
return `${location.city} - ${location.state}`;
|
|
1130
|
+
}
|
|
1131
|
+
return location.city || location.neighborhood || location.street || location.state || "";
|
|
1132
|
+
}
|
|
1133
|
+
function searchResultsHeading(pathFilters, dictionary, locationNames) {
|
|
1134
|
+
const types = [].concat(pathFilters.propertyType || []).filter(Boolean);
|
|
1135
|
+
let noun = "Im\xF3veis";
|
|
1136
|
+
let found = "encontrados";
|
|
1137
|
+
if (types.length === 1) {
|
|
1138
|
+
const id = String(types[0]);
|
|
1139
|
+
const option = dictionary?.propertyTypes?.find(
|
|
1140
|
+
(entry) => entry.id === id || entry.slug === id
|
|
1141
|
+
);
|
|
1142
|
+
const label = option?.label;
|
|
1143
|
+
if (label) {
|
|
1144
|
+
noun = pluralizePt(label.charAt(0).toUpperCase() + label.slice(1));
|
|
1145
|
+
if (FEMININE_HEADING.test(id) || FEMININE_HEADING.test(label)) {
|
|
1146
|
+
found = "encontradas";
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
const place = locationNames ? headingLocationSuffix(
|
|
1151
|
+
displayPathLocation(pathFilters.location, locationNames)
|
|
1152
|
+
) : "";
|
|
1153
|
+
if (place) return `${noun} ${found} em ${place}`;
|
|
1154
|
+
return `${noun} ${found}`;
|
|
1155
|
+
}
|
|
1156
|
+
function hrefWithExplicitPage(href, page) {
|
|
1157
|
+
if (page !== 1 || /(?:\?|&)page=/.test(href)) return href;
|
|
1158
|
+
return href.includes("?") ? `${href}&page=1` : `${href}?page=1`;
|
|
1159
|
+
}
|
|
1160
|
+
function paginationPages(currentPage, totalPages, padding) {
|
|
1161
|
+
if (totalPages < 1) return [];
|
|
1162
|
+
const current = Math.min(Math.max(1, currentPage), totalPages);
|
|
1163
|
+
const start = Math.max(1, current - padding);
|
|
1164
|
+
const end = Math.min(totalPages, current + padding);
|
|
1165
|
+
const pages = [];
|
|
1166
|
+
for (let i = start; i <= end; i += 1) pages.push(i);
|
|
1167
|
+
return pages;
|
|
754
1168
|
}
|
|
755
1169
|
|
|
756
1170
|
// src/resolve-site-id.ts
|
|
@@ -917,10 +1331,25 @@ function createGaragemClient(options = {}) {
|
|
|
917
1331
|
};
|
|
918
1332
|
}
|
|
919
1333
|
export {
|
|
1334
|
+
FORBIDDEN_SEARCH_QUERY_KEYS,
|
|
920
1335
|
GaragemSdkError,
|
|
1336
|
+
SEARCH_CSS_RECIPE,
|
|
1337
|
+
SEARCH_CSS_VARS,
|
|
1338
|
+
SEARCH_SORT_RELEVANCE,
|
|
1339
|
+
TOOLBAR_PRIMARY_FILTER_IDS,
|
|
1340
|
+
applyPathFilter,
|
|
1341
|
+
buildQueryListingsParams,
|
|
1342
|
+
canonicalizeSearchHref,
|
|
1343
|
+
clearStagedPathFilters,
|
|
921
1344
|
composeSearchPublicHref2 as composeSearchPublicHref,
|
|
922
1345
|
composeSearchPublicPath2 as composeSearchPublicPath,
|
|
1346
|
+
countFacetChoices,
|
|
1347
|
+
countOptionLabel,
|
|
923
1348
|
createGaragemClient,
|
|
1349
|
+
displayPathLocation,
|
|
1350
|
+
formatAreaM2,
|
|
1351
|
+
formatGroupedInteger,
|
|
1352
|
+
formatListingPrice,
|
|
924
1353
|
getCmsCollection,
|
|
925
1354
|
getCmsCollections,
|
|
926
1355
|
getCmsEntries,
|
|
@@ -930,18 +1359,36 @@ export {
|
|
|
930
1359
|
getSearchUi,
|
|
931
1360
|
getSimilarListings,
|
|
932
1361
|
getSite,
|
|
1362
|
+
hrefForAppliedChange,
|
|
1363
|
+
hrefForPathFilters,
|
|
1364
|
+
hrefWithExplicitPage,
|
|
1365
|
+
isListingDetailPath,
|
|
933
1366
|
isStudioPreviewHost,
|
|
1367
|
+
listingBusinessLabel,
|
|
1368
|
+
listingLocationLabel,
|
|
934
1369
|
listingLookupKey,
|
|
935
1370
|
listingPublicPath,
|
|
936
1371
|
mergeAppliedSearchQueryIntoSearch2 as mergeAppliedSearchQueryIntoSearch,
|
|
1372
|
+
paginationPages,
|
|
937
1373
|
parseAppliedSearchQuery2 as parseAppliedSearchQuery,
|
|
1374
|
+
parseGroupedInteger,
|
|
938
1375
|
parseSearchPublicPath2 as parseSearchPublicPath,
|
|
1376
|
+
pathFilterHasOption,
|
|
1377
|
+
pathFilterValue,
|
|
939
1378
|
pathFiltersToQueryFilters,
|
|
940
1379
|
pathLocationToFilterInput,
|
|
1380
|
+
publicSearchHref,
|
|
941
1381
|
queryListings,
|
|
1382
|
+
readPublicSearch,
|
|
942
1383
|
reduceAppliedSearchQuery2 as reduceAppliedSearchQuery,
|
|
943
1384
|
resolvePublicSiteId,
|
|
1385
|
+
searchHrefUsesLegacyFilterQuery,
|
|
944
1386
|
searchListings,
|
|
945
|
-
|
|
1387
|
+
searchResultsHeading,
|
|
1388
|
+
searchSortOptions,
|
|
1389
|
+
serializeAppliedSearchQuery2 as serializeAppliedSearchQuery,
|
|
1390
|
+
toListingCardModel,
|
|
1391
|
+
toolbarFilterIds,
|
|
1392
|
+
visibleSearchFilters
|
|
946
1393
|
};
|
|
947
1394
|
//# sourceMappingURL=index.mjs.map
|