@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.js
CHANGED
|
@@ -18,12 +18,27 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
|
|
20
20
|
// src/index.ts
|
|
21
|
-
var
|
|
22
|
-
__export(
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
FORBIDDEN_SEARCH_QUERY_KEYS: () => FORBIDDEN_SEARCH_QUERY_KEYS,
|
|
23
24
|
GaragemSdkError: () => GaragemSdkError,
|
|
25
|
+
SEARCH_CSS_RECIPE: () => SEARCH_CSS_RECIPE,
|
|
26
|
+
SEARCH_CSS_VARS: () => SEARCH_CSS_VARS,
|
|
27
|
+
SEARCH_SORT_RELEVANCE: () => SEARCH_SORT_RELEVANCE,
|
|
28
|
+
TOOLBAR_PRIMARY_FILTER_IDS: () => TOOLBAR_PRIMARY_FILTER_IDS,
|
|
29
|
+
applyPathFilter: () => applyPathFilter,
|
|
30
|
+
buildQueryListingsParams: () => buildQueryListingsParams,
|
|
31
|
+
canonicalizeSearchHref: () => canonicalizeSearchHref,
|
|
32
|
+
clearStagedPathFilters: () => clearStagedPathFilters,
|
|
24
33
|
composeSearchPublicHref: () => composeSearchPublicHref2,
|
|
25
34
|
composeSearchPublicPath: () => composeSearchPublicPath2,
|
|
35
|
+
countFacetChoices: () => countFacetChoices,
|
|
36
|
+
countOptionLabel: () => countOptionLabel,
|
|
26
37
|
createGaragemClient: () => createGaragemClient,
|
|
38
|
+
displayPathLocation: () => displayPathLocation,
|
|
39
|
+
formatAreaM2: () => formatAreaM2,
|
|
40
|
+
formatGroupedInteger: () => formatGroupedInteger,
|
|
41
|
+
formatListingPrice: () => formatListingPrice,
|
|
27
42
|
getCmsCollection: () => getCmsCollection,
|
|
28
43
|
getCmsCollections: () => getCmsCollections,
|
|
29
44
|
getCmsEntries: () => getCmsEntries,
|
|
@@ -33,21 +48,39 @@ __export(index_exports, {
|
|
|
33
48
|
getSearchUi: () => getSearchUi,
|
|
34
49
|
getSimilarListings: () => getSimilarListings,
|
|
35
50
|
getSite: () => getSite,
|
|
51
|
+
hrefForAppliedChange: () => hrefForAppliedChange,
|
|
52
|
+
hrefForPathFilters: () => hrefForPathFilters,
|
|
53
|
+
hrefWithExplicitPage: () => hrefWithExplicitPage,
|
|
54
|
+
isListingDetailPath: () => isListingDetailPath,
|
|
36
55
|
isStudioPreviewHost: () => isStudioPreviewHost,
|
|
56
|
+
listingBusinessLabel: () => listingBusinessLabel,
|
|
57
|
+
listingLocationLabel: () => listingLocationLabel,
|
|
37
58
|
listingLookupKey: () => listingLookupKey,
|
|
38
59
|
listingPublicPath: () => listingPublicPath,
|
|
39
60
|
mergeAppliedSearchQueryIntoSearch: () => mergeAppliedSearchQueryIntoSearch2,
|
|
61
|
+
paginationPages: () => paginationPages,
|
|
40
62
|
parseAppliedSearchQuery: () => parseAppliedSearchQuery2,
|
|
63
|
+
parseGroupedInteger: () => parseGroupedInteger,
|
|
41
64
|
parseSearchPublicPath: () => parseSearchPublicPath2,
|
|
65
|
+
pathFilterHasOption: () => pathFilterHasOption,
|
|
66
|
+
pathFilterValue: () => pathFilterValue,
|
|
42
67
|
pathFiltersToQueryFilters: () => pathFiltersToQueryFilters,
|
|
43
68
|
pathLocationToFilterInput: () => pathLocationToFilterInput,
|
|
69
|
+
publicSearchHref: () => publicSearchHref,
|
|
44
70
|
queryListings: () => queryListings,
|
|
71
|
+
readPublicSearch: () => readPublicSearch,
|
|
45
72
|
reduceAppliedSearchQuery: () => reduceAppliedSearchQuery2,
|
|
46
73
|
resolvePublicSiteId: () => resolvePublicSiteId,
|
|
74
|
+
searchHrefUsesLegacyFilterQuery: () => searchHrefUsesLegacyFilterQuery,
|
|
47
75
|
searchListings: () => searchListings,
|
|
48
|
-
|
|
76
|
+
searchResultsHeading: () => searchResultsHeading,
|
|
77
|
+
searchSortOptions: () => searchSortOptions,
|
|
78
|
+
serializeAppliedSearchQuery: () => serializeAppliedSearchQuery2,
|
|
79
|
+
toListingCardModel: () => toListingCardModel,
|
|
80
|
+
toolbarFilterIds: () => toolbarFilterIds,
|
|
81
|
+
visibleSearchFilters: () => visibleSearchFilters
|
|
49
82
|
});
|
|
50
|
-
module.exports = __toCommonJS(
|
|
83
|
+
module.exports = __toCommonJS(src_exports);
|
|
51
84
|
|
|
52
85
|
// src/listing-path.ts
|
|
53
86
|
function listingLookupKey(raw) {
|
|
@@ -69,6 +102,15 @@ function normalizeBaseUrl(baseUrl) {
|
|
|
69
102
|
const url = baseUrl ?? DEFAULT_BASE_URL;
|
|
70
103
|
return url.endsWith("/") ? url.slice(0, -1) : url;
|
|
71
104
|
}
|
|
105
|
+
async function coerceSiteId(siteId) {
|
|
106
|
+
const value = await Promise.resolve(siteId);
|
|
107
|
+
if (typeof value !== "string" || !value.trim()) {
|
|
108
|
+
throw new TypeError(
|
|
109
|
+
"Garagem SDK: siteId must be a string. Await resolveSiteId(...) before getListings / getSearchUi / queryListings."
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
return value;
|
|
113
|
+
}
|
|
72
114
|
function buildListingFiltersQuery(filters) {
|
|
73
115
|
const params = new URLSearchParams();
|
|
74
116
|
if (!filters) return params;
|
|
@@ -108,7 +150,8 @@ var GaragemSdkError = class extends Error {
|
|
|
108
150
|
}
|
|
109
151
|
};
|
|
110
152
|
async function getListings(options) {
|
|
111
|
-
const {
|
|
153
|
+
const { filters, baseUrl, fetch: fetchImpl, next } = options;
|
|
154
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
112
155
|
const base = normalizeBaseUrl(baseUrl);
|
|
113
156
|
const params = buildListingFiltersQuery(filters);
|
|
114
157
|
const qs = params.size > 0 ? `?${params.toString()}` : "";
|
|
@@ -124,13 +167,8 @@ async function getListings(options) {
|
|
|
124
167
|
};
|
|
125
168
|
}
|
|
126
169
|
async function getListing(options) {
|
|
127
|
-
const {
|
|
128
|
-
|
|
129
|
-
listingId: rawListingId,
|
|
130
|
-
baseUrl,
|
|
131
|
-
fetch: fetchImpl,
|
|
132
|
-
next
|
|
133
|
-
} = options;
|
|
170
|
+
const { listingId: rawListingId, baseUrl, fetch: fetchImpl, next } = options;
|
|
171
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
134
172
|
const listingId = listingLookupKey(rawListingId ?? "");
|
|
135
173
|
if (!listingId || listingId === "undefined" || listingId === "null") {
|
|
136
174
|
throw new TypeError("getListing: `listingId` is required");
|
|
@@ -146,7 +184,8 @@ async function getListing(options) {
|
|
|
146
184
|
);
|
|
147
185
|
}
|
|
148
186
|
async function getSite(options) {
|
|
149
|
-
const {
|
|
187
|
+
const { domain, baseUrl, fetch: fetchImpl, next } = options;
|
|
188
|
+
const siteId = options.siteId ? await coerceSiteId(options.siteId) : void 0;
|
|
150
189
|
if (!siteId && !domain) {
|
|
151
190
|
throw new TypeError(
|
|
152
191
|
"getSite: provide exactly one of `siteId` or `domain`."
|
|
@@ -184,7 +223,8 @@ async function getSite(options) {
|
|
|
184
223
|
};
|
|
185
224
|
}
|
|
186
225
|
async function searchListings(options) {
|
|
187
|
-
const {
|
|
226
|
+
const { params, baseUrl, fetch: fetchImpl, next } = options;
|
|
227
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
188
228
|
if (!params || typeof params.q !== "string") {
|
|
189
229
|
throw new TypeError(
|
|
190
230
|
"Garagem SDK: searchListings requires `params.q` (Typesense query string)."
|
|
@@ -204,7 +244,8 @@ async function searchListings(options) {
|
|
|
204
244
|
);
|
|
205
245
|
}
|
|
206
246
|
async function getSearchUi(options) {
|
|
207
|
-
const {
|
|
247
|
+
const { baseUrl, fetch: fetchImpl, next } = options;
|
|
248
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
208
249
|
const base = normalizeBaseUrl(baseUrl);
|
|
209
250
|
const url = `${base}/api/sites/${encodeURIComponent(siteId)}/search-ui`;
|
|
210
251
|
return callJson(
|
|
@@ -214,7 +255,8 @@ async function getSearchUi(options) {
|
|
|
214
255
|
);
|
|
215
256
|
}
|
|
216
257
|
async function queryListings(options) {
|
|
217
|
-
const {
|
|
258
|
+
const { params, baseUrl, fetch: fetchImpl, next } = options;
|
|
259
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
218
260
|
const base = normalizeBaseUrl(baseUrl);
|
|
219
261
|
const url = `${base}/api/sites/${encodeURIComponent(siteId)}/search/listings`;
|
|
220
262
|
return callJson(
|
|
@@ -233,13 +275,13 @@ async function queryListings(options) {
|
|
|
233
275
|
}
|
|
234
276
|
async function getSimilarListings(options) {
|
|
235
277
|
const {
|
|
236
|
-
siteId,
|
|
237
278
|
listingId: rawListingId,
|
|
238
279
|
limit,
|
|
239
280
|
baseUrl,
|
|
240
281
|
fetch: fetchImpl,
|
|
241
282
|
next
|
|
242
283
|
} = options;
|
|
284
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
243
285
|
const listingId = listingLookupKey(rawListingId ?? "");
|
|
244
286
|
if (!listingId || listingId === "undefined" || listingId === "null") {
|
|
245
287
|
throw new TypeError("getSimilarListings: `listingId` is required");
|
|
@@ -264,7 +306,8 @@ async function getSimilarListings(options) {
|
|
|
264
306
|
};
|
|
265
307
|
}
|
|
266
308
|
async function getCmsCollections(options) {
|
|
267
|
-
const {
|
|
309
|
+
const { baseUrl, fetch: fetchImpl, next } = options;
|
|
310
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
268
311
|
const base = normalizeBaseUrl(baseUrl);
|
|
269
312
|
const url = `${base}/api/sites/${encodeURIComponent(siteId)}/cms/collections`;
|
|
270
313
|
const data = await callJson(
|
|
@@ -275,7 +318,8 @@ async function getCmsCollections(options) {
|
|
|
275
318
|
return data.collections ?? [];
|
|
276
319
|
}
|
|
277
320
|
async function getCmsCollection(options) {
|
|
278
|
-
const {
|
|
321
|
+
const { slug, baseUrl, fetch: fetchImpl, next } = options;
|
|
322
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
279
323
|
if (!slug) {
|
|
280
324
|
throw new TypeError("getCmsCollection: `slug` is required");
|
|
281
325
|
}
|
|
@@ -295,7 +339,6 @@ async function getCmsCollection(options) {
|
|
|
295
339
|
}
|
|
296
340
|
async function getCmsEntries(options) {
|
|
297
341
|
const {
|
|
298
|
-
siteId,
|
|
299
342
|
collection,
|
|
300
343
|
limit,
|
|
301
344
|
offset,
|
|
@@ -303,6 +346,7 @@ async function getCmsEntries(options) {
|
|
|
303
346
|
fetch: fetchImpl,
|
|
304
347
|
next
|
|
305
348
|
} = options;
|
|
349
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
306
350
|
if (!collection) {
|
|
307
351
|
throw new TypeError("getCmsEntries: `collection` is required");
|
|
308
352
|
}
|
|
@@ -331,7 +375,8 @@ async function getCmsEntries(options) {
|
|
|
331
375
|
};
|
|
332
376
|
}
|
|
333
377
|
async function getCmsEntry(options) {
|
|
334
|
-
const {
|
|
378
|
+
const { collection, slug, baseUrl, fetch: fetchImpl, next } = options;
|
|
379
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
335
380
|
if (!collection) {
|
|
336
381
|
throw new TypeError("getCmsEntry: `collection` is required");
|
|
337
382
|
}
|
|
@@ -353,6 +398,92 @@ async function getCmsEntry(options) {
|
|
|
353
398
|
return data;
|
|
354
399
|
}
|
|
355
400
|
|
|
401
|
+
// src/presentation.ts
|
|
402
|
+
var SEARCH_CSS_VARS = {
|
|
403
|
+
cardRadius: "--garagem-listing-card-radius",
|
|
404
|
+
cardGap: "--garagem-listing-card-gap",
|
|
405
|
+
priceSize: "--garagem-listing-price-size",
|
|
406
|
+
mediaRatio: "--garagem-listing-media-ratio",
|
|
407
|
+
controlHeight: "--garagem-search-control-height",
|
|
408
|
+
iconSize: "--garagem-search-icon-size",
|
|
409
|
+
skeleton: "--garagem-skeleton"
|
|
410
|
+
};
|
|
411
|
+
var SEARCH_CSS_RECIPE = `:root {
|
|
412
|
+
${SEARCH_CSS_VARS.cardRadius}: 0.75rem;
|
|
413
|
+
${SEARCH_CSS_VARS.cardGap}: 1.5rem;
|
|
414
|
+
${SEARCH_CSS_VARS.priceSize}: 1.125rem;
|
|
415
|
+
${SEARCH_CSS_VARS.mediaRatio}: 4 / 3;
|
|
416
|
+
${SEARCH_CSS_VARS.controlHeight}: 2.75rem;
|
|
417
|
+
${SEARCH_CSS_VARS.iconSize}: 1.25rem;
|
|
418
|
+
${SEARCH_CSS_VARS.skeleton}: var(--muted, #e7e5e4);
|
|
419
|
+
}
|
|
420
|
+
`;
|
|
421
|
+
function formatListingPrice(amount, locale = "pt-BR", currency = "BRL") {
|
|
422
|
+
if (amount == null) return "Sob consulta";
|
|
423
|
+
try {
|
|
424
|
+
return new Intl.NumberFormat(locale, {
|
|
425
|
+
style: "currency",
|
|
426
|
+
currency,
|
|
427
|
+
minimumFractionDigits: 0,
|
|
428
|
+
maximumFractionDigits: 0
|
|
429
|
+
}).format(amount);
|
|
430
|
+
} catch {
|
|
431
|
+
return `${currency} ${amount}`;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
function formatGroupedInteger(value, locale = "pt-BR") {
|
|
435
|
+
const digits = String(value ?? "").replace(/\D/g, "");
|
|
436
|
+
if (!digits) return "";
|
|
437
|
+
const amount = Number.parseInt(digits, 10);
|
|
438
|
+
if (!Number.isFinite(amount)) return "";
|
|
439
|
+
return new Intl.NumberFormat(locale, { maximumFractionDigits: 0 }).format(
|
|
440
|
+
amount
|
|
441
|
+
);
|
|
442
|
+
}
|
|
443
|
+
function parseGroupedInteger(value) {
|
|
444
|
+
if (typeof value === "number") {
|
|
445
|
+
return Number.isFinite(value) ? Math.trunc(value) : void 0;
|
|
446
|
+
}
|
|
447
|
+
const digits = String(value ?? "").replace(/\D/g, "");
|
|
448
|
+
if (!digits) return void 0;
|
|
449
|
+
const amount = Number.parseInt(digits, 10);
|
|
450
|
+
return Number.isFinite(amount) ? amount : void 0;
|
|
451
|
+
}
|
|
452
|
+
function formatAreaM2(area) {
|
|
453
|
+
if (area == null || !Number.isFinite(area)) return null;
|
|
454
|
+
return `${area} m\xB2`;
|
|
455
|
+
}
|
|
456
|
+
function listingBusinessLabel(businessType) {
|
|
457
|
+
return businessType === "rental" ? "Aluguel" : "Venda";
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
// src/listing-card-model.ts
|
|
461
|
+
function listingLocationLabel(location) {
|
|
462
|
+
return [location.neighborhood, location.city, location.state].map((part) => part ? String(part).trim() : "").filter(Boolean).join(", ");
|
|
463
|
+
}
|
|
464
|
+
function toListingCardModel(listing) {
|
|
465
|
+
const isPrivate = listing.priceVisibility === "private";
|
|
466
|
+
const area = listing.property?.usableArea ?? listing.property?.totalArea;
|
|
467
|
+
return {
|
|
468
|
+
href: listingPublicPath(listing),
|
|
469
|
+
title: listing.title,
|
|
470
|
+
businessType: listing.businessType,
|
|
471
|
+
businessLabel: listingBusinessLabel(listing.businessType),
|
|
472
|
+
priceVisibility: listing.priceVisibility,
|
|
473
|
+
price: listing.price,
|
|
474
|
+
priceLabel: isPrivate ? "Sob consulta" : formatListingPrice(listing.price),
|
|
475
|
+
pricePeriod: listing.businessType === "rental" && !isPrivate && listing.price != null ? "/m\xEAs" : null,
|
|
476
|
+
locationLabel: listingLocationLabel(listing.location || {}),
|
|
477
|
+
propertyType: listing.property?.type ?? null,
|
|
478
|
+
coverSrc: listing.coverImage?.src ?? null,
|
|
479
|
+
coverAlt: listing.coverImage?.alt ?? listing.title,
|
|
480
|
+
bedrooms: listing.property?.bedrooms ?? null,
|
|
481
|
+
bathrooms: listing.property?.bathrooms ?? null,
|
|
482
|
+
parkingSpaces: listing.property?.parkingSpaces ?? null,
|
|
483
|
+
areaM2: area ?? null
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
|
|
356
487
|
// ../search-url/types.ts
|
|
357
488
|
var SEARCH_BASE_ROUTE = "imoveis";
|
|
358
489
|
var MAX_PAGE = 1e4;
|
|
@@ -726,6 +857,42 @@ function composeSearchPublicHref(pathname, query, existingSearch) {
|
|
|
726
857
|
return qs ? `${pathname}?${qs}` : pathname;
|
|
727
858
|
}
|
|
728
859
|
|
|
860
|
+
// src/applied-query.ts
|
|
861
|
+
function parseAppliedSearchQuery2(search) {
|
|
862
|
+
return parseAppliedSearchQuery(search);
|
|
863
|
+
}
|
|
864
|
+
function serializeAppliedSearchQuery2(query) {
|
|
865
|
+
return serializeAppliedSearchQuery(query);
|
|
866
|
+
}
|
|
867
|
+
function mergeAppliedSearchQueryIntoSearch2(existing, query) {
|
|
868
|
+
return mergeAppliedSearchQueryIntoSearch(existing, query);
|
|
869
|
+
}
|
|
870
|
+
function reduceAppliedSearchQuery2(prev, change) {
|
|
871
|
+
return reduceAppliedSearchQuery(prev, change);
|
|
872
|
+
}
|
|
873
|
+
function composeSearchPublicHref2(pathname, query, existingSearch) {
|
|
874
|
+
return composeSearchPublicHref(pathname, query, existingSearch);
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
// src/loc-params.ts
|
|
878
|
+
function pathLocationToFilterInput(location) {
|
|
879
|
+
if (!location || typeof location !== "object") return null;
|
|
880
|
+
const { state, city, neighborhood, street } = location;
|
|
881
|
+
const levels = [];
|
|
882
|
+
if (state) levels.push(state);
|
|
883
|
+
if (city) levels.push(city);
|
|
884
|
+
if (neighborhood) levels.push(neighborhood);
|
|
885
|
+
if (street) levels.push(street);
|
|
886
|
+
if (levels.length === 0) return null;
|
|
887
|
+
if (levels.length === 1) {
|
|
888
|
+
if (state) return { type: "state", value: state };
|
|
889
|
+
if (city) return { type: "city", value: city };
|
|
890
|
+
if (neighborhood) return { type: "neighborhood", value: neighborhood };
|
|
891
|
+
if (street) return { type: "street", value: street };
|
|
892
|
+
}
|
|
893
|
+
return { type: "path", value: levels.join("/") };
|
|
894
|
+
}
|
|
895
|
+
|
|
729
896
|
// src/path.ts
|
|
730
897
|
function composeSearchPublicPath2(filters, dictionary) {
|
|
731
898
|
return dictionary ? composeSearchPublicPath(filters, dictionary) : composeSearchPublicPath(filters);
|
|
@@ -768,40 +935,320 @@ function pathFiltersToQueryFilters(pathFilters) {
|
|
|
768
935
|
return result;
|
|
769
936
|
}
|
|
770
937
|
|
|
771
|
-
// src/
|
|
772
|
-
|
|
773
|
-
|
|
938
|
+
// src/search-engine.ts
|
|
939
|
+
var PATH_FILTER_IDS = {
|
|
940
|
+
listing_type: "listingType",
|
|
941
|
+
property_type: "propertyType",
|
|
942
|
+
property_bedrooms: "bedrooms",
|
|
943
|
+
property_bathrooms: "bathrooms",
|
|
944
|
+
property_suites: "suites",
|
|
945
|
+
property_parking_spots: "parkingSpots",
|
|
946
|
+
price: "price",
|
|
947
|
+
property_area_total: "area",
|
|
948
|
+
propertyFeatures: "propertyFeatures",
|
|
949
|
+
buildingAmenities: "buildingAmenities"
|
|
950
|
+
};
|
|
951
|
+
var FORBIDDEN_SEARCH_QUERY_KEYS = [
|
|
952
|
+
"tipo",
|
|
953
|
+
"quartos",
|
|
954
|
+
"tipo-imovel",
|
|
955
|
+
"banheiros",
|
|
956
|
+
"vagas"
|
|
957
|
+
];
|
|
958
|
+
var SEARCH_SORT_RELEVANCE = {
|
|
959
|
+
id: "",
|
|
960
|
+
label: "Mais relevantes"
|
|
961
|
+
};
|
|
962
|
+
function searchSortOptions(sorts) {
|
|
963
|
+
const fromApi = (sorts || []).filter((sort) => sort.id);
|
|
964
|
+
return [
|
|
965
|
+
{ id: SEARCH_SORT_RELEVANCE.id, label: SEARCH_SORT_RELEVANCE.label },
|
|
966
|
+
...fromApi
|
|
967
|
+
];
|
|
774
968
|
}
|
|
775
|
-
|
|
776
|
-
|
|
969
|
+
var TOOLBAR_PRIMARY_FILTER_IDS = [
|
|
970
|
+
"price",
|
|
971
|
+
"property_bedrooms"
|
|
972
|
+
];
|
|
973
|
+
var HIDDEN_FILTER_IDS = /* @__PURE__ */ new Set(["property_suites"]);
|
|
974
|
+
function toFiniteNumber(value) {
|
|
975
|
+
if (value === "" || value == null) return void 0;
|
|
976
|
+
const n = Number(value);
|
|
977
|
+
return Number.isFinite(n) ? n : void 0;
|
|
777
978
|
}
|
|
778
|
-
function
|
|
779
|
-
return
|
|
979
|
+
function pathnameOnly(pathname) {
|
|
980
|
+
return String(pathname || "").split(/[?#]/)[0] || "/";
|
|
780
981
|
}
|
|
781
|
-
function
|
|
782
|
-
|
|
982
|
+
function isListingDetailPath(pathname) {
|
|
983
|
+
const parts = pathnameOnly(pathname).split("/").filter(Boolean);
|
|
984
|
+
const last = parts[parts.length - 1] || "";
|
|
985
|
+
return last.toLowerCase().startsWith("id-");
|
|
783
986
|
}
|
|
784
|
-
function
|
|
785
|
-
|
|
987
|
+
function readPublicSearch(pathname, search, dictionary) {
|
|
988
|
+
const pathFilters = parseSearchPublicPath2(pathnameOnly(pathname), dictionary) || {};
|
|
989
|
+
const applied = parseAppliedSearchQuery2(search || "");
|
|
990
|
+
return { pathFilters, applied };
|
|
786
991
|
}
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
992
|
+
function lookupDisplay(table, slug) {
|
|
993
|
+
if (!slug || !table) return slug;
|
|
994
|
+
return table[slug] || table[String(slug).toLowerCase()] || slug;
|
|
995
|
+
}
|
|
996
|
+
function displayPathLocation(location, values) {
|
|
997
|
+
if (!location) return null;
|
|
998
|
+
const table = values || {};
|
|
999
|
+
return {
|
|
1000
|
+
state: lookupDisplay(table.states, location.state),
|
|
1001
|
+
city: lookupDisplay(table.cities, location.city),
|
|
1002
|
+
neighborhood: lookupDisplay(table.neighborhoods, location.neighborhood),
|
|
1003
|
+
street: lookupDisplay(table.streets, location.street)
|
|
1004
|
+
};
|
|
1005
|
+
}
|
|
1006
|
+
function buildQueryListingsParams(pathFilters, applied, schema, locationValues) {
|
|
1007
|
+
const filters = pathFiltersToQueryFilters(pathFilters || {});
|
|
1008
|
+
const locations = [];
|
|
1009
|
+
const displayed = displayPathLocation(pathFilters?.location, locationValues);
|
|
1010
|
+
const pathLoc = displayed ? pathLocationToFilterInput(displayed) : null;
|
|
1011
|
+
if (pathLoc) locations.push(pathLoc);
|
|
1012
|
+
for (const value of applied?.loc || []) {
|
|
1013
|
+
locations.push({ type: "loc", value });
|
|
803
1014
|
}
|
|
804
|
-
|
|
1015
|
+
const params = {
|
|
1016
|
+
page: applied?.page || 1,
|
|
1017
|
+
limit: schema?.defaultLimit || 12,
|
|
1018
|
+
filters
|
|
1019
|
+
};
|
|
1020
|
+
if (applied?.sort) params.sort = applied.sort;
|
|
1021
|
+
const hasLocation = locations.length > 0;
|
|
1022
|
+
if (applied?.query && !hasLocation) params.q = applied.query;
|
|
1023
|
+
if (hasLocation) params.location = locations;
|
|
1024
|
+
return params;
|
|
1025
|
+
}
|
|
1026
|
+
function applyPathFilter(pathFilters, filterId, value) {
|
|
1027
|
+
const next = { ...pathFilters || {} };
|
|
1028
|
+
const key = PATH_FILTER_IDS[filterId];
|
|
1029
|
+
if (!key) return next;
|
|
1030
|
+
if (value === "" || value == null) {
|
|
1031
|
+
delete next[key];
|
|
1032
|
+
return next;
|
|
1033
|
+
}
|
|
1034
|
+
if (key === "price" || key === "area") {
|
|
1035
|
+
const range = value || {};
|
|
1036
|
+
const parse = key === "price" ? parseGroupedInteger : toFiniteNumber;
|
|
1037
|
+
const min = parse(range.min);
|
|
1038
|
+
const max = parse(range.max);
|
|
1039
|
+
if (min == null && max == null) {
|
|
1040
|
+
delete next[key];
|
|
1041
|
+
return next;
|
|
1042
|
+
}
|
|
1043
|
+
next[key] = {
|
|
1044
|
+
...min != null ? { min } : {},
|
|
1045
|
+
...max != null ? { max } : {}
|
|
1046
|
+
};
|
|
1047
|
+
return next;
|
|
1048
|
+
}
|
|
1049
|
+
if (key === "propertyFeatures" || key === "buildingAmenities") {
|
|
1050
|
+
const current = Array.isArray(next[key]) ? [...next[key]] : [];
|
|
1051
|
+
const id = String(value);
|
|
1052
|
+
const i = current.indexOf(id);
|
|
1053
|
+
if (i >= 0) current.splice(i, 1);
|
|
1054
|
+
else current.push(id);
|
|
1055
|
+
if (current.length) next[key] = current;
|
|
1056
|
+
else delete next[key];
|
|
1057
|
+
return next;
|
|
1058
|
+
}
|
|
1059
|
+
if (key === "propertyType") {
|
|
1060
|
+
const id = String(value);
|
|
1061
|
+
const current = Array.isArray(next.propertyType) ? [...next.propertyType] : next.propertyType ? [String(next.propertyType)] : [];
|
|
1062
|
+
const i = current.indexOf(id);
|
|
1063
|
+
if (i >= 0) current.splice(i, 1);
|
|
1064
|
+
else current.push(id);
|
|
1065
|
+
if (current.length === 0) delete next.propertyType;
|
|
1066
|
+
else if (current.length === 1) next.propertyType = current[0];
|
|
1067
|
+
else next.propertyType = current;
|
|
1068
|
+
return next;
|
|
1069
|
+
}
|
|
1070
|
+
if (key === "listingType") {
|
|
1071
|
+
const id = String(value);
|
|
1072
|
+
if (next.listingType === id) delete next.listingType;
|
|
1073
|
+
else next.listingType = id;
|
|
1074
|
+
return next;
|
|
1075
|
+
}
|
|
1076
|
+
if (key === "bedrooms" || key === "bathrooms" || key === "suites" || key === "parkingSpots") {
|
|
1077
|
+
const n = Number(value);
|
|
1078
|
+
if (!Number.isFinite(n)) {
|
|
1079
|
+
delete next[key];
|
|
1080
|
+
return next;
|
|
1081
|
+
}
|
|
1082
|
+
if (next[key] === n) delete next[key];
|
|
1083
|
+
else next[key] = n;
|
|
1084
|
+
return next;
|
|
1085
|
+
}
|
|
1086
|
+
return next;
|
|
1087
|
+
}
|
|
1088
|
+
function pathFilterValue(pathFilters, filterId) {
|
|
1089
|
+
const key = PATH_FILTER_IDS[filterId];
|
|
1090
|
+
const value = pathFilters && key ? pathFilters[key] : void 0;
|
|
1091
|
+
if (value == null) return "";
|
|
1092
|
+
if (Array.isArray(value)) return value[0] != null ? String(value[0]) : "";
|
|
1093
|
+
if (typeof value === "object") return "";
|
|
1094
|
+
return String(value);
|
|
1095
|
+
}
|
|
1096
|
+
function pathFilterHasOption(pathFilters, filterId, optionId) {
|
|
1097
|
+
const key = PATH_FILTER_IDS[filterId];
|
|
1098
|
+
const value = pathFilters && key ? pathFilters[key] : void 0;
|
|
1099
|
+
if (value == null) return false;
|
|
1100
|
+
if (Array.isArray(value)) return value.map(String).includes(optionId);
|
|
1101
|
+
if (typeof value === "object") return false;
|
|
1102
|
+
return String(value) === optionId;
|
|
1103
|
+
}
|
|
1104
|
+
function publicSearchHref(pathFilters, applied, dictionary, existingSearch) {
|
|
1105
|
+
const pathname = composeSearchPublicPath2(pathFilters || {}, dictionary);
|
|
1106
|
+
return composeSearchPublicHref2(pathname, applied || {}, existingSearch);
|
|
1107
|
+
}
|
|
1108
|
+
function hrefForPathFilters(pathname, search, dictionary, nextPathFilters) {
|
|
1109
|
+
const { applied } = readPublicSearch(pathname, search, dictionary);
|
|
1110
|
+
const nextApplied = reduceAppliedSearchQuery2(applied, {
|
|
1111
|
+
type: "applyFilters"
|
|
1112
|
+
});
|
|
1113
|
+
return publicSearchHref(nextPathFilters, nextApplied, dictionary, search);
|
|
1114
|
+
}
|
|
1115
|
+
function hrefForAppliedChange(pathname, search, dictionary, change) {
|
|
1116
|
+
const { pathFilters, applied } = readPublicSearch(
|
|
1117
|
+
pathname,
|
|
1118
|
+
search,
|
|
1119
|
+
dictionary
|
|
1120
|
+
);
|
|
1121
|
+
let nextPath = pathFilters;
|
|
1122
|
+
if (change && change.type === "query") {
|
|
1123
|
+
nextPath = { ...pathFilters };
|
|
1124
|
+
delete nextPath.location;
|
|
1125
|
+
}
|
|
1126
|
+
const nextApplied = reduceAppliedSearchQuery2(applied, change);
|
|
1127
|
+
return publicSearchHref(nextPath, nextApplied, dictionary, search);
|
|
1128
|
+
}
|
|
1129
|
+
function currentSearchHref(pathname, search) {
|
|
1130
|
+
const path = pathnameOnly(pathname);
|
|
1131
|
+
const qs = search.replace(/^\?/, "");
|
|
1132
|
+
return qs ? `${path}?${qs}` : path;
|
|
1133
|
+
}
|
|
1134
|
+
function canonicalizeSearchHref(pathname, search, dictionary) {
|
|
1135
|
+
const { pathFilters, applied } = readPublicSearch(
|
|
1136
|
+
pathname,
|
|
1137
|
+
search,
|
|
1138
|
+
dictionary
|
|
1139
|
+
);
|
|
1140
|
+
const href = publicSearchHref(pathFilters, applied, dictionary, search);
|
|
1141
|
+
if (href === currentSearchHref(pathname, search)) return null;
|
|
1142
|
+
return href;
|
|
1143
|
+
}
|
|
1144
|
+
function searchHrefUsesLegacyFilterQuery(href) {
|
|
1145
|
+
const query = href.split("?")[1] || "";
|
|
1146
|
+
const params = new URLSearchParams(query);
|
|
1147
|
+
return FORBIDDEN_SEARCH_QUERY_KEYS.some((key) => params.has(key));
|
|
1148
|
+
}
|
|
1149
|
+
function clearStagedPathFilters(current, keepFilterIds = []) {
|
|
1150
|
+
const next = current.location ? { location: current.location } : {};
|
|
1151
|
+
for (const id of keepFilterIds) {
|
|
1152
|
+
const key = PATH_FILTER_IDS[id];
|
|
1153
|
+
if (!key || key === "location") continue;
|
|
1154
|
+
const value = current[key];
|
|
1155
|
+
if (value != null) Object.assign(next, { [key]: value });
|
|
1156
|
+
}
|
|
1157
|
+
return next;
|
|
1158
|
+
}
|
|
1159
|
+
function visibleSearchFilters(schema) {
|
|
1160
|
+
if (!schema?.filters) return [];
|
|
1161
|
+
return schema.filters.filter((filter) => {
|
|
1162
|
+
if (HIDDEN_FILTER_IDS.has(filter.id)) return false;
|
|
1163
|
+
if (filter.id === "listing_type" && (filter.options?.length ?? 0) <= 1) {
|
|
1164
|
+
return false;
|
|
1165
|
+
}
|
|
1166
|
+
return true;
|
|
1167
|
+
});
|
|
1168
|
+
}
|
|
1169
|
+
function toolbarFilterIds(schema) {
|
|
1170
|
+
const visible = new Set(visibleSearchFilters(schema).map((f) => f.id));
|
|
1171
|
+
return TOOLBAR_PRIMARY_FILTER_IDS.filter((id) => visible.has(id));
|
|
1172
|
+
}
|
|
1173
|
+
function countOptionLabel(option) {
|
|
1174
|
+
const label = String(option?.label ?? "");
|
|
1175
|
+
if (/^[1-9]\d*$/.test(label)) return `${label}+`;
|
|
1176
|
+
return label;
|
|
1177
|
+
}
|
|
1178
|
+
function countFacetChoices(options) {
|
|
1179
|
+
const list = options || [];
|
|
1180
|
+
const zero = list.find((o) => o.id === "0" || o.label === "Studio");
|
|
1181
|
+
const isStudio = Boolean(
|
|
1182
|
+
zero && /studio/i.test(String(zero.label)) && zero.id === "0"
|
|
1183
|
+
);
|
|
1184
|
+
const max = isStudio ? 3 : 4;
|
|
1185
|
+
const out = [];
|
|
1186
|
+
if (zero) out.push({ id: zero.id, label: countOptionLabel(zero) });
|
|
1187
|
+
for (let n = 1; n <= max; n += 1) {
|
|
1188
|
+
const option = list.find((o) => o.id === String(n));
|
|
1189
|
+
out.push({
|
|
1190
|
+
id: String(n),
|
|
1191
|
+
label: countOptionLabel(option || { label: String(n) })
|
|
1192
|
+
});
|
|
1193
|
+
}
|
|
1194
|
+
return out;
|
|
1195
|
+
}
|
|
1196
|
+
var FEMININE_HEADING = /(casa|cobertura|kitnet|loja|sala|fazenda|chácara|chacara)s?$/i;
|
|
1197
|
+
function pluralizePt(label) {
|
|
1198
|
+
const text = label.trim();
|
|
1199
|
+
if (!text || /s$/i.test(text)) return text;
|
|
1200
|
+
if (/il$/i.test(text)) return `${text.slice(0, -1)}is`;
|
|
1201
|
+
if (/m$/i.test(text)) return `${text.slice(0, -1)}ns`;
|
|
1202
|
+
return `${text}s`;
|
|
1203
|
+
}
|
|
1204
|
+
function headingLocationSuffix(location) {
|
|
1205
|
+
if (!location) return "";
|
|
1206
|
+
if (location.street && location.neighborhood) {
|
|
1207
|
+
return `${location.street}, ${location.neighborhood}`;
|
|
1208
|
+
}
|
|
1209
|
+
if (location.neighborhood && location.city) {
|
|
1210
|
+
return `${location.neighborhood}, ${location.city}`;
|
|
1211
|
+
}
|
|
1212
|
+
if (location.city && location.state) {
|
|
1213
|
+
return `${location.city} - ${location.state}`;
|
|
1214
|
+
}
|
|
1215
|
+
return location.city || location.neighborhood || location.street || location.state || "";
|
|
1216
|
+
}
|
|
1217
|
+
function searchResultsHeading(pathFilters, dictionary, locationNames) {
|
|
1218
|
+
const types = [].concat(pathFilters.propertyType || []).filter(Boolean);
|
|
1219
|
+
let noun = "Im\xF3veis";
|
|
1220
|
+
let found = "encontrados";
|
|
1221
|
+
if (types.length === 1) {
|
|
1222
|
+
const id = String(types[0]);
|
|
1223
|
+
const option = dictionary?.propertyTypes?.find(
|
|
1224
|
+
(entry) => entry.id === id || entry.slug === id
|
|
1225
|
+
);
|
|
1226
|
+
const label = option?.label;
|
|
1227
|
+
if (label) {
|
|
1228
|
+
noun = pluralizePt(label.charAt(0).toUpperCase() + label.slice(1));
|
|
1229
|
+
if (FEMININE_HEADING.test(id) || FEMININE_HEADING.test(label)) {
|
|
1230
|
+
found = "encontradas";
|
|
1231
|
+
}
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
const place = locationNames ? headingLocationSuffix(
|
|
1235
|
+
displayPathLocation(pathFilters.location, locationNames)
|
|
1236
|
+
) : "";
|
|
1237
|
+
if (place) return `${noun} ${found} em ${place}`;
|
|
1238
|
+
return `${noun} ${found}`;
|
|
1239
|
+
}
|
|
1240
|
+
function hrefWithExplicitPage(href, page) {
|
|
1241
|
+
if (page !== 1 || /(?:\?|&)page=/.test(href)) return href;
|
|
1242
|
+
return href.includes("?") ? `${href}&page=1` : `${href}?page=1`;
|
|
1243
|
+
}
|
|
1244
|
+
function paginationPages(currentPage, totalPages, padding) {
|
|
1245
|
+
if (totalPages < 1) return [];
|
|
1246
|
+
const current = Math.min(Math.max(1, currentPage), totalPages);
|
|
1247
|
+
const start = Math.max(1, current - padding);
|
|
1248
|
+
const end = Math.min(totalPages, current + padding);
|
|
1249
|
+
const pages = [];
|
|
1250
|
+
for (let i = start; i <= end; i += 1) pages.push(i);
|
|
1251
|
+
return pages;
|
|
805
1252
|
}
|
|
806
1253
|
|
|
807
1254
|
// src/resolve-site-id.ts
|
|
@@ -969,10 +1416,25 @@ function createGaragemClient(options = {}) {
|
|
|
969
1416
|
}
|
|
970
1417
|
// Annotate the CommonJS export names for ESM import in node:
|
|
971
1418
|
0 && (module.exports = {
|
|
1419
|
+
FORBIDDEN_SEARCH_QUERY_KEYS,
|
|
972
1420
|
GaragemSdkError,
|
|
1421
|
+
SEARCH_CSS_RECIPE,
|
|
1422
|
+
SEARCH_CSS_VARS,
|
|
1423
|
+
SEARCH_SORT_RELEVANCE,
|
|
1424
|
+
TOOLBAR_PRIMARY_FILTER_IDS,
|
|
1425
|
+
applyPathFilter,
|
|
1426
|
+
buildQueryListingsParams,
|
|
1427
|
+
canonicalizeSearchHref,
|
|
1428
|
+
clearStagedPathFilters,
|
|
973
1429
|
composeSearchPublicHref,
|
|
974
1430
|
composeSearchPublicPath,
|
|
1431
|
+
countFacetChoices,
|
|
1432
|
+
countOptionLabel,
|
|
975
1433
|
createGaragemClient,
|
|
1434
|
+
displayPathLocation,
|
|
1435
|
+
formatAreaM2,
|
|
1436
|
+
formatGroupedInteger,
|
|
1437
|
+
formatListingPrice,
|
|
976
1438
|
getCmsCollection,
|
|
977
1439
|
getCmsCollections,
|
|
978
1440
|
getCmsEntries,
|
|
@@ -982,18 +1444,36 @@ function createGaragemClient(options = {}) {
|
|
|
982
1444
|
getSearchUi,
|
|
983
1445
|
getSimilarListings,
|
|
984
1446
|
getSite,
|
|
1447
|
+
hrefForAppliedChange,
|
|
1448
|
+
hrefForPathFilters,
|
|
1449
|
+
hrefWithExplicitPage,
|
|
1450
|
+
isListingDetailPath,
|
|
985
1451
|
isStudioPreviewHost,
|
|
1452
|
+
listingBusinessLabel,
|
|
1453
|
+
listingLocationLabel,
|
|
986
1454
|
listingLookupKey,
|
|
987
1455
|
listingPublicPath,
|
|
988
1456
|
mergeAppliedSearchQueryIntoSearch,
|
|
1457
|
+
paginationPages,
|
|
989
1458
|
parseAppliedSearchQuery,
|
|
1459
|
+
parseGroupedInteger,
|
|
990
1460
|
parseSearchPublicPath,
|
|
1461
|
+
pathFilterHasOption,
|
|
1462
|
+
pathFilterValue,
|
|
991
1463
|
pathFiltersToQueryFilters,
|
|
992
1464
|
pathLocationToFilterInput,
|
|
1465
|
+
publicSearchHref,
|
|
993
1466
|
queryListings,
|
|
1467
|
+
readPublicSearch,
|
|
994
1468
|
reduceAppliedSearchQuery,
|
|
995
1469
|
resolvePublicSiteId,
|
|
1470
|
+
searchHrefUsesLegacyFilterQuery,
|
|
996
1471
|
searchListings,
|
|
997
|
-
|
|
1472
|
+
searchResultsHeading,
|
|
1473
|
+
searchSortOptions,
|
|
1474
|
+
serializeAppliedSearchQuery,
|
|
1475
|
+
toListingCardModel,
|
|
1476
|
+
toolbarFilterIds,
|
|
1477
|
+
visibleSearchFilters
|
|
998
1478
|
});
|
|
999
1479
|
//# sourceMappingURL=index.js.map
|