@garagem-ai/site-sdk 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -3
- package/dist/index.d.mts +146 -249
- package/dist/index.d.ts +146 -249
- package/dist/index.js +960 -20
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +914 -16
- package/dist/index.mjs.map +1 -1
- package/dist/listing-card-model-D7iR4asd.d.mts +402 -0
- package/dist/listing-card-model-D7iR4asd.d.ts +402 -0
- package/dist/react.d.mts +136 -0
- package/dist/react.d.ts +136 -0
- package/dist/react.js +2070 -0
- package/dist/react.js.map +1 -0
- package/dist/react.mjs +2030 -0
- package/dist/react.mjs.map +1 -0
- package/package.json +47 -4
- package/src/applied-query.ts +42 -0
- package/src/client.ts +36 -1
- package/src/fetchers.ts +81 -18
- package/src/index.ts +77 -0
- package/src/internal/url.ts +14 -0
- package/src/listing-card-model.ts +90 -0
- package/src/loc-params.ts +36 -0
- package/src/path.ts +73 -0
- package/src/presentation.ts +72 -0
- package/src/react/cn.ts +3 -0
- package/src/react/filter-panel.tsx +251 -0
- package/src/react/index.ts +20 -0
- package/src/react/listing-card.tsx +143 -0
- package/src/react/search-chrome.tsx +72 -0
- package/src/react/search-page.tsx +366 -0
- package/src/react/search-pagination.tsx +110 -0
- package/src/react/search-query-form.tsx +76 -0
- package/src/react/types.ts +88 -0
- package/src/react/use-public-search.ts +297 -0
- package/src/search-engine.ts +404 -0
- package/src/types.ts +107 -4
package/dist/index.js
CHANGED
|
@@ -18,25 +18,67 @@ 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,
|
|
33
|
+
composeSearchPublicHref: () => composeSearchPublicHref2,
|
|
34
|
+
composeSearchPublicPath: () => composeSearchPublicPath2,
|
|
35
|
+
countFacetChoices: () => countFacetChoices,
|
|
36
|
+
countOptionLabel: () => countOptionLabel,
|
|
24
37
|
createGaragemClient: () => createGaragemClient,
|
|
38
|
+
displayPathLocation: () => displayPathLocation,
|
|
39
|
+
formatAreaM2: () => formatAreaM2,
|
|
40
|
+
formatGroupedInteger: () => formatGroupedInteger,
|
|
41
|
+
formatListingPrice: () => formatListingPrice,
|
|
25
42
|
getCmsCollection: () => getCmsCollection,
|
|
26
43
|
getCmsCollections: () => getCmsCollections,
|
|
27
44
|
getCmsEntries: () => getCmsEntries,
|
|
28
45
|
getCmsEntry: () => getCmsEntry,
|
|
29
46
|
getListing: () => getListing,
|
|
30
47
|
getListings: () => getListings,
|
|
48
|
+
getSearchUi: () => getSearchUi,
|
|
31
49
|
getSimilarListings: () => getSimilarListings,
|
|
32
50
|
getSite: () => getSite,
|
|
51
|
+
hrefForAppliedChange: () => hrefForAppliedChange,
|
|
52
|
+
hrefForPathFilters: () => hrefForPathFilters,
|
|
53
|
+
isListingDetailPath: () => isListingDetailPath,
|
|
33
54
|
isStudioPreviewHost: () => isStudioPreviewHost,
|
|
55
|
+
listingBusinessLabel: () => listingBusinessLabel,
|
|
56
|
+
listingLocationLabel: () => listingLocationLabel,
|
|
34
57
|
listingLookupKey: () => listingLookupKey,
|
|
35
58
|
listingPublicPath: () => listingPublicPath,
|
|
59
|
+
mergeAppliedSearchQueryIntoSearch: () => mergeAppliedSearchQueryIntoSearch2,
|
|
60
|
+
paginationPages: () => paginationPages,
|
|
61
|
+
parseAppliedSearchQuery: () => parseAppliedSearchQuery2,
|
|
62
|
+
parseGroupedInteger: () => parseGroupedInteger,
|
|
63
|
+
parseSearchPublicPath: () => parseSearchPublicPath2,
|
|
64
|
+
pathFilterHasOption: () => pathFilterHasOption,
|
|
65
|
+
pathFilterValue: () => pathFilterValue,
|
|
66
|
+
pathFiltersToQueryFilters: () => pathFiltersToQueryFilters,
|
|
67
|
+
pathLocationToFilterInput: () => pathLocationToFilterInput,
|
|
68
|
+
publicSearchHref: () => publicSearchHref,
|
|
69
|
+
queryListings: () => queryListings,
|
|
70
|
+
readPublicSearch: () => readPublicSearch,
|
|
71
|
+
reduceAppliedSearchQuery: () => reduceAppliedSearchQuery2,
|
|
36
72
|
resolvePublicSiteId: () => resolvePublicSiteId,
|
|
37
|
-
|
|
73
|
+
searchHrefUsesLegacyFilterQuery: () => searchHrefUsesLegacyFilterQuery,
|
|
74
|
+
searchListings: () => searchListings,
|
|
75
|
+
searchSortOptions: () => searchSortOptions,
|
|
76
|
+
serializeAppliedSearchQuery: () => serializeAppliedSearchQuery2,
|
|
77
|
+
toListingCardModel: () => toListingCardModel,
|
|
78
|
+
toolbarFilterIds: () => toolbarFilterIds,
|
|
79
|
+
visibleSearchFilters: () => visibleSearchFilters
|
|
38
80
|
});
|
|
39
|
-
module.exports = __toCommonJS(
|
|
81
|
+
module.exports = __toCommonJS(src_exports);
|
|
40
82
|
|
|
41
83
|
// src/listing-path.ts
|
|
42
84
|
function listingLookupKey(raw) {
|
|
@@ -58,6 +100,15 @@ function normalizeBaseUrl(baseUrl) {
|
|
|
58
100
|
const url = baseUrl ?? DEFAULT_BASE_URL;
|
|
59
101
|
return url.endsWith("/") ? url.slice(0, -1) : url;
|
|
60
102
|
}
|
|
103
|
+
async function coerceSiteId(siteId) {
|
|
104
|
+
const value = await Promise.resolve(siteId);
|
|
105
|
+
if (typeof value !== "string" || !value.trim()) {
|
|
106
|
+
throw new TypeError(
|
|
107
|
+
"Garagem SDK: siteId must be a string. Await resolveSiteId(...) before getListings / getSearchUi / queryListings."
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
return value;
|
|
111
|
+
}
|
|
61
112
|
function buildListingFiltersQuery(filters) {
|
|
62
113
|
const params = new URLSearchParams();
|
|
63
114
|
if (!filters) return params;
|
|
@@ -97,7 +148,8 @@ var GaragemSdkError = class extends Error {
|
|
|
97
148
|
}
|
|
98
149
|
};
|
|
99
150
|
async function getListings(options) {
|
|
100
|
-
const {
|
|
151
|
+
const { filters, baseUrl, fetch: fetchImpl, next } = options;
|
|
152
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
101
153
|
const base = normalizeBaseUrl(baseUrl);
|
|
102
154
|
const params = buildListingFiltersQuery(filters);
|
|
103
155
|
const qs = params.size > 0 ? `?${params.toString()}` : "";
|
|
@@ -113,13 +165,8 @@ async function getListings(options) {
|
|
|
113
165
|
};
|
|
114
166
|
}
|
|
115
167
|
async function getListing(options) {
|
|
116
|
-
const {
|
|
117
|
-
|
|
118
|
-
listingId: rawListingId,
|
|
119
|
-
baseUrl,
|
|
120
|
-
fetch: fetchImpl,
|
|
121
|
-
next
|
|
122
|
-
} = options;
|
|
168
|
+
const { listingId: rawListingId, baseUrl, fetch: fetchImpl, next } = options;
|
|
169
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
123
170
|
const listingId = listingLookupKey(rawListingId ?? "");
|
|
124
171
|
if (!listingId || listingId === "undefined" || listingId === "null") {
|
|
125
172
|
throw new TypeError("getListing: `listingId` is required");
|
|
@@ -135,7 +182,8 @@ async function getListing(options) {
|
|
|
135
182
|
);
|
|
136
183
|
}
|
|
137
184
|
async function getSite(options) {
|
|
138
|
-
const {
|
|
185
|
+
const { domain, baseUrl, fetch: fetchImpl, next } = options;
|
|
186
|
+
const siteId = options.siteId ? await coerceSiteId(options.siteId) : void 0;
|
|
139
187
|
if (!siteId && !domain) {
|
|
140
188
|
throw new TypeError(
|
|
141
189
|
"getSite: provide exactly one of `siteId` or `domain`."
|
|
@@ -173,7 +221,8 @@ async function getSite(options) {
|
|
|
173
221
|
};
|
|
174
222
|
}
|
|
175
223
|
async function searchListings(options) {
|
|
176
|
-
const {
|
|
224
|
+
const { params, baseUrl, fetch: fetchImpl, next } = options;
|
|
225
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
177
226
|
if (!params || typeof params.q !== "string") {
|
|
178
227
|
throw new TypeError(
|
|
179
228
|
"Garagem SDK: searchListings requires `params.q` (Typesense query string)."
|
|
@@ -192,15 +241,45 @@ async function searchListings(options) {
|
|
|
192
241
|
fetchImpl ?? fetch
|
|
193
242
|
);
|
|
194
243
|
}
|
|
244
|
+
async function getSearchUi(options) {
|
|
245
|
+
const { baseUrl, fetch: fetchImpl, next } = options;
|
|
246
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
247
|
+
const base = normalizeBaseUrl(baseUrl);
|
|
248
|
+
const url = `${base}/api/sites/${encodeURIComponent(siteId)}/search-ui`;
|
|
249
|
+
return callJson(
|
|
250
|
+
url,
|
|
251
|
+
{ method: "GET", headers: { Accept: "application/json" }, next },
|
|
252
|
+
fetchImpl ?? fetch
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
async function queryListings(options) {
|
|
256
|
+
const { params, baseUrl, fetch: fetchImpl, next } = options;
|
|
257
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
258
|
+
const base = normalizeBaseUrl(baseUrl);
|
|
259
|
+
const url = `${base}/api/sites/${encodeURIComponent(siteId)}/search/listings`;
|
|
260
|
+
return callJson(
|
|
261
|
+
url,
|
|
262
|
+
{
|
|
263
|
+
method: "POST",
|
|
264
|
+
headers: {
|
|
265
|
+
Accept: "application/json",
|
|
266
|
+
"Content-Type": "application/json"
|
|
267
|
+
},
|
|
268
|
+
body: JSON.stringify(params ?? {}),
|
|
269
|
+
next
|
|
270
|
+
},
|
|
271
|
+
fetchImpl ?? fetch
|
|
272
|
+
);
|
|
273
|
+
}
|
|
195
274
|
async function getSimilarListings(options) {
|
|
196
275
|
const {
|
|
197
|
-
siteId,
|
|
198
276
|
listingId: rawListingId,
|
|
199
277
|
limit,
|
|
200
278
|
baseUrl,
|
|
201
279
|
fetch: fetchImpl,
|
|
202
280
|
next
|
|
203
281
|
} = options;
|
|
282
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
204
283
|
const listingId = listingLookupKey(rawListingId ?? "");
|
|
205
284
|
if (!listingId || listingId === "undefined" || listingId === "null") {
|
|
206
285
|
throw new TypeError("getSimilarListings: `listingId` is required");
|
|
@@ -225,7 +304,8 @@ async function getSimilarListings(options) {
|
|
|
225
304
|
};
|
|
226
305
|
}
|
|
227
306
|
async function getCmsCollections(options) {
|
|
228
|
-
const {
|
|
307
|
+
const { baseUrl, fetch: fetchImpl, next } = options;
|
|
308
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
229
309
|
const base = normalizeBaseUrl(baseUrl);
|
|
230
310
|
const url = `${base}/api/sites/${encodeURIComponent(siteId)}/cms/collections`;
|
|
231
311
|
const data = await callJson(
|
|
@@ -236,7 +316,8 @@ async function getCmsCollections(options) {
|
|
|
236
316
|
return data.collections ?? [];
|
|
237
317
|
}
|
|
238
318
|
async function getCmsCollection(options) {
|
|
239
|
-
const {
|
|
319
|
+
const { slug, baseUrl, fetch: fetchImpl, next } = options;
|
|
320
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
240
321
|
if (!slug) {
|
|
241
322
|
throw new TypeError("getCmsCollection: `slug` is required");
|
|
242
323
|
}
|
|
@@ -256,7 +337,6 @@ async function getCmsCollection(options) {
|
|
|
256
337
|
}
|
|
257
338
|
async function getCmsEntries(options) {
|
|
258
339
|
const {
|
|
259
|
-
siteId,
|
|
260
340
|
collection,
|
|
261
341
|
limit,
|
|
262
342
|
offset,
|
|
@@ -264,6 +344,7 @@ async function getCmsEntries(options) {
|
|
|
264
344
|
fetch: fetchImpl,
|
|
265
345
|
next
|
|
266
346
|
} = options;
|
|
347
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
267
348
|
if (!collection) {
|
|
268
349
|
throw new TypeError("getCmsEntries: `collection` is required");
|
|
269
350
|
}
|
|
@@ -292,7 +373,8 @@ async function getCmsEntries(options) {
|
|
|
292
373
|
};
|
|
293
374
|
}
|
|
294
375
|
async function getCmsEntry(options) {
|
|
295
|
-
const {
|
|
376
|
+
const { collection, slug, baseUrl, fetch: fetchImpl, next } = options;
|
|
377
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
296
378
|
if (!collection) {
|
|
297
379
|
throw new TypeError("getCmsEntry: `collection` is required");
|
|
298
380
|
}
|
|
@@ -314,6 +396,805 @@ async function getCmsEntry(options) {
|
|
|
314
396
|
return data;
|
|
315
397
|
}
|
|
316
398
|
|
|
399
|
+
// src/presentation.ts
|
|
400
|
+
var SEARCH_CSS_VARS = {
|
|
401
|
+
cardRadius: "--garagem-listing-card-radius",
|
|
402
|
+
cardGap: "--garagem-listing-card-gap",
|
|
403
|
+
priceSize: "--garagem-listing-price-size",
|
|
404
|
+
mediaRatio: "--garagem-listing-media-ratio"
|
|
405
|
+
};
|
|
406
|
+
var SEARCH_CSS_RECIPE = `:root {
|
|
407
|
+
${SEARCH_CSS_VARS.cardRadius}: 0.75rem;
|
|
408
|
+
${SEARCH_CSS_VARS.cardGap}: 1.5rem;
|
|
409
|
+
${SEARCH_CSS_VARS.priceSize}: 1.125rem;
|
|
410
|
+
${SEARCH_CSS_VARS.mediaRatio}: 4 / 3;
|
|
411
|
+
}
|
|
412
|
+
`;
|
|
413
|
+
function formatListingPrice(amount, locale = "pt-BR", currency = "BRL") {
|
|
414
|
+
if (amount == null) return "Sob consulta";
|
|
415
|
+
try {
|
|
416
|
+
return new Intl.NumberFormat(locale, {
|
|
417
|
+
style: "currency",
|
|
418
|
+
currency,
|
|
419
|
+
minimumFractionDigits: 0,
|
|
420
|
+
maximumFractionDigits: 0
|
|
421
|
+
}).format(amount);
|
|
422
|
+
} catch {
|
|
423
|
+
return `${currency} ${amount}`;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
function formatGroupedInteger(value, locale = "pt-BR") {
|
|
427
|
+
const digits = String(value ?? "").replace(/\D/g, "");
|
|
428
|
+
if (!digits) return "";
|
|
429
|
+
const amount = Number.parseInt(digits, 10);
|
|
430
|
+
if (!Number.isFinite(amount)) return "";
|
|
431
|
+
return new Intl.NumberFormat(locale, { maximumFractionDigits: 0 }).format(
|
|
432
|
+
amount
|
|
433
|
+
);
|
|
434
|
+
}
|
|
435
|
+
function parseGroupedInteger(value) {
|
|
436
|
+
if (typeof value === "number") {
|
|
437
|
+
return Number.isFinite(value) ? Math.trunc(value) : void 0;
|
|
438
|
+
}
|
|
439
|
+
const digits = String(value ?? "").replace(/\D/g, "");
|
|
440
|
+
if (!digits) return void 0;
|
|
441
|
+
const amount = Number.parseInt(digits, 10);
|
|
442
|
+
return Number.isFinite(amount) ? amount : void 0;
|
|
443
|
+
}
|
|
444
|
+
function formatAreaM2(area) {
|
|
445
|
+
if (area == null || !Number.isFinite(area)) return null;
|
|
446
|
+
return `${area} m\xB2`;
|
|
447
|
+
}
|
|
448
|
+
function listingBusinessLabel(businessType) {
|
|
449
|
+
return businessType === "rental" ? "Aluguel" : "Venda";
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
// src/listing-card-model.ts
|
|
453
|
+
function listingLocationLabel(location) {
|
|
454
|
+
return [location.neighborhood, location.city, location.state].map((part) => part ? String(part).trim() : "").filter(Boolean).join(", ");
|
|
455
|
+
}
|
|
456
|
+
function toListingCardModel(listing) {
|
|
457
|
+
const isPrivate = listing.priceVisibility === "private";
|
|
458
|
+
const area = listing.property?.usableArea ?? listing.property?.totalArea;
|
|
459
|
+
return {
|
|
460
|
+
href: listingPublicPath(listing),
|
|
461
|
+
title: listing.title,
|
|
462
|
+
businessType: listing.businessType,
|
|
463
|
+
businessLabel: listingBusinessLabel(listing.businessType),
|
|
464
|
+
priceVisibility: listing.priceVisibility,
|
|
465
|
+
price: listing.price,
|
|
466
|
+
priceLabel: isPrivate ? "Sob consulta" : formatListingPrice(listing.price),
|
|
467
|
+
pricePeriod: listing.businessType === "rental" && !isPrivate && listing.price != null ? "/m\xEAs" : null,
|
|
468
|
+
locationLabel: listingLocationLabel(listing.location || {}),
|
|
469
|
+
propertyType: listing.property?.type ?? null,
|
|
470
|
+
coverSrc: listing.coverImage?.src ?? null,
|
|
471
|
+
coverAlt: listing.coverImage?.alt ?? listing.title,
|
|
472
|
+
bedrooms: listing.property?.bedrooms ?? null,
|
|
473
|
+
bathrooms: listing.property?.bathrooms ?? null,
|
|
474
|
+
parkingSpaces: listing.property?.parkingSpaces ?? null,
|
|
475
|
+
areaM2: area ?? null
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
// ../search-url/types.ts
|
|
480
|
+
var SEARCH_BASE_ROUTE = "imoveis";
|
|
481
|
+
var MAX_PAGE = 1e4;
|
|
482
|
+
var MAX_LOC_GROUPS = 20;
|
|
483
|
+
var DEFAULT_MIN_PRICE = 0;
|
|
484
|
+
var DEFAULT_MAX_PRICE = 1e9;
|
|
485
|
+
var DEFAULT_MIN_AREA = 0;
|
|
486
|
+
var DEFAULT_MAX_AREA = 1e5;
|
|
487
|
+
var SORT_URL_TOKENS = [
|
|
488
|
+
"preco-asc",
|
|
489
|
+
"preco-desc",
|
|
490
|
+
"area-asc",
|
|
491
|
+
"area-desc"
|
|
492
|
+
];
|
|
493
|
+
|
|
494
|
+
// ../search-url/slugify.ts
|
|
495
|
+
function slugifyForUrl(text) {
|
|
496
|
+
if (!text) return "";
|
|
497
|
+
const withDashes = text.replace(/([a-z])([A-Z])/g, "$1-$2");
|
|
498
|
+
return withDashes.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "").replace(/[^\w\s-]/g, "").replace(/\s+/g, "-").replace(/-+/g, "-").trim();
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
// ../search-url/catalog.ts
|
|
502
|
+
var PROPERTY_TYPE_SLUG_ALIASES = {
|
|
503
|
+
rural: ["chacara", "fazenda", "sitio"]
|
|
504
|
+
};
|
|
505
|
+
function buildListingTypeOptions(enabled) {
|
|
506
|
+
const flags = enabled ?? { sale: true, rental: true };
|
|
507
|
+
const out = [];
|
|
508
|
+
if (flags.sale !== false) {
|
|
509
|
+
out.push({ id: "sale", slug: "venda", label: "Venda" });
|
|
510
|
+
}
|
|
511
|
+
if (flags.rental !== false) {
|
|
512
|
+
out.push({ id: "rental", slug: "aluguel", label: "Aluguel" });
|
|
513
|
+
}
|
|
514
|
+
return out;
|
|
515
|
+
}
|
|
516
|
+
function emptySearchUrlDictionary() {
|
|
517
|
+
return {
|
|
518
|
+
listingTypes: buildListingTypeOptions(null),
|
|
519
|
+
propertyTypes: [],
|
|
520
|
+
propertyFeatures: [],
|
|
521
|
+
buildingAmenities: []
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
function norm(value) {
|
|
525
|
+
return slugifyForUrl(value) || value.toLowerCase();
|
|
526
|
+
}
|
|
527
|
+
function matchOptionId(segment, options, extraAliases) {
|
|
528
|
+
const n = norm(segment);
|
|
529
|
+
for (const option of options) {
|
|
530
|
+
const aliases = extraAliases?.[option.id] ?? [];
|
|
531
|
+
const candidates = [option.id, option.slug, option.label, ...aliases];
|
|
532
|
+
if (candidates.some((c) => norm(c) === n)) return option.id;
|
|
533
|
+
}
|
|
534
|
+
return null;
|
|
535
|
+
}
|
|
536
|
+
function optionSlugById(id, options) {
|
|
537
|
+
const option = options.find((item) => item.id === id);
|
|
538
|
+
return option?.slug ?? null;
|
|
539
|
+
}
|
|
540
|
+
var LISTING_TYPE_ALIASES = {
|
|
541
|
+
sale: ["comprar"],
|
|
542
|
+
rental: ["alugar"]
|
|
543
|
+
};
|
|
544
|
+
|
|
545
|
+
// ../search-url/path.ts
|
|
546
|
+
function toArray(value) {
|
|
547
|
+
if (value === void 0) return [];
|
|
548
|
+
return Array.isArray(value) ? value : [value];
|
|
549
|
+
}
|
|
550
|
+
function formatNumeric(value) {
|
|
551
|
+
return Array.isArray(value) ? value.join("-") : String(value);
|
|
552
|
+
}
|
|
553
|
+
function formatRange(min, max, unit) {
|
|
554
|
+
return `de-${min}-a-${max}-${unit}`;
|
|
555
|
+
}
|
|
556
|
+
function formatSuiteSuffix(value) {
|
|
557
|
+
const values = Array.isArray(value) ? value : [value];
|
|
558
|
+
const firstValue = values[0] ?? 0;
|
|
559
|
+
return firstValue === 0 || firstValue === 1 ? "suite" : "suites";
|
|
560
|
+
}
|
|
561
|
+
function composeSearchPublicPath(filters, dictionary = emptySearchUrlDictionary()) {
|
|
562
|
+
const segments = [];
|
|
563
|
+
const listingType = filters.listingType;
|
|
564
|
+
if (listingType) {
|
|
565
|
+
segments.push(
|
|
566
|
+
optionSlugById(listingType, dictionary.listingTypes) || slugifyForUrl(listingType)
|
|
567
|
+
);
|
|
568
|
+
}
|
|
569
|
+
for (const propertyType of toArray(filters.propertyType)) {
|
|
570
|
+
segments.push(
|
|
571
|
+
optionSlugById(propertyType, dictionary.propertyTypes) || slugifyForUrl(propertyType)
|
|
572
|
+
);
|
|
573
|
+
}
|
|
574
|
+
const location = filters.location;
|
|
575
|
+
if (location) {
|
|
576
|
+
if (location.state) segments.push(slugifyForUrl(location.state));
|
|
577
|
+
if (location.city) segments.push(slugifyForUrl(location.city));
|
|
578
|
+
if (location.neighborhood)
|
|
579
|
+
segments.push(slugifyForUrl(location.neighborhood));
|
|
580
|
+
if (location.street) segments.push(slugifyForUrl(location.street));
|
|
581
|
+
}
|
|
582
|
+
if (filters.bedrooms !== void 0) {
|
|
583
|
+
segments.push(`${formatNumeric(filters.bedrooms)}-quartos`);
|
|
584
|
+
}
|
|
585
|
+
if (filters.bathrooms !== void 0) {
|
|
586
|
+
segments.push(`${formatNumeric(filters.bathrooms)}-banheiros`);
|
|
587
|
+
}
|
|
588
|
+
if (filters.suites !== void 0) {
|
|
589
|
+
const suffix = formatSuiteSuffix(filters.suites);
|
|
590
|
+
segments.push(`${formatNumeric(filters.suites)}-${suffix}`);
|
|
591
|
+
}
|
|
592
|
+
if (filters.parkingSpots !== void 0) {
|
|
593
|
+
segments.push(`${formatNumeric(filters.parkingSpots)}-vagas`);
|
|
594
|
+
}
|
|
595
|
+
if (filters.price && (filters.price.min !== void 0 || filters.price.max !== void 0)) {
|
|
596
|
+
const min = filters.price.min ?? DEFAULT_MIN_PRICE;
|
|
597
|
+
const max = filters.price.max ?? DEFAULT_MAX_PRICE;
|
|
598
|
+
segments.push(formatRange(min, max, "reais"));
|
|
599
|
+
}
|
|
600
|
+
if (filters.area && (filters.area.min !== void 0 || filters.area.max !== void 0)) {
|
|
601
|
+
const min = filters.area.min ?? DEFAULT_MIN_AREA;
|
|
602
|
+
const max = filters.area.max ?? DEFAULT_MAX_AREA;
|
|
603
|
+
segments.push(formatRange(min, max, "m2"));
|
|
604
|
+
}
|
|
605
|
+
const seenAmenities = /* @__PURE__ */ new Set();
|
|
606
|
+
for (const id of filters.propertyFeatures ?? []) {
|
|
607
|
+
const slug = optionSlugById(id, dictionary.propertyFeatures) || slugifyForUrl(id);
|
|
608
|
+
if (!slug || seenAmenities.has(slug)) continue;
|
|
609
|
+
seenAmenities.add(slug);
|
|
610
|
+
segments.push(slug);
|
|
611
|
+
}
|
|
612
|
+
for (const id of filters.buildingAmenities ?? []) {
|
|
613
|
+
const slug = optionSlugById(id, dictionary.buildingAmenities) || slugifyForUrl(id);
|
|
614
|
+
if (!slug || seenAmenities.has(slug)) continue;
|
|
615
|
+
seenAmenities.add(slug);
|
|
616
|
+
segments.push(slug);
|
|
617
|
+
}
|
|
618
|
+
const path = segments.filter(Boolean).join("/");
|
|
619
|
+
return path ? `/${SEARCH_BASE_ROUTE}/${path}` : `/${SEARCH_BASE_ROUTE}`;
|
|
620
|
+
}
|
|
621
|
+
var BEDROOMS = /^(\d+(?:-\d+)*)-quartos?$/;
|
|
622
|
+
var BATHROOMS = /^(\d+(?:-\d+)*)-banheiros?$/;
|
|
623
|
+
var SUITES = /^(\d+(?:-\d+)*)-suites?$/;
|
|
624
|
+
var PARKING = /^(\d+(?:-\d+)*)-vagas?$/;
|
|
625
|
+
var PRICE = /^de-(\d+)-a-(\d+)-(reais|real)$/;
|
|
626
|
+
var AREA = /^de-(\d+)-a-(\d+)-(m2|m²)$/;
|
|
627
|
+
function parseNumericList(raw) {
|
|
628
|
+
return raw.split("-").map((part) => Number(part)).filter((n) => Number.isFinite(n));
|
|
629
|
+
}
|
|
630
|
+
function collapse(values) {
|
|
631
|
+
return values.length === 1 ? values[0] : values;
|
|
632
|
+
}
|
|
633
|
+
function parseSearchPublicPath(pathname, dictionary = emptySearchUrlDictionary()) {
|
|
634
|
+
const raw = pathname.split(/[?#]/)[0] ?? "";
|
|
635
|
+
let segments = raw.replace(/^\//, "").split("/").filter(Boolean);
|
|
636
|
+
if (segments[0] === SEARCH_BASE_ROUTE) segments = segments.slice(1);
|
|
637
|
+
if (segments.some((segment) => segment.includes("."))) return null;
|
|
638
|
+
if (segments.some((segment) => segment.toLowerCase().startsWith("id-"))) {
|
|
639
|
+
return null;
|
|
640
|
+
}
|
|
641
|
+
const filters = {};
|
|
642
|
+
const locationParts = [];
|
|
643
|
+
const propertyTypes = [];
|
|
644
|
+
const propertyFeatures = [];
|
|
645
|
+
const buildingAmenities = [];
|
|
646
|
+
for (const segment of segments) {
|
|
647
|
+
const lower = segment.toLowerCase();
|
|
648
|
+
const listingType = matchOptionId(
|
|
649
|
+
segment,
|
|
650
|
+
dictionary.listingTypes,
|
|
651
|
+
LISTING_TYPE_ALIASES
|
|
652
|
+
);
|
|
653
|
+
if (listingType && !filters.listingType) {
|
|
654
|
+
filters.listingType = listingType;
|
|
655
|
+
continue;
|
|
656
|
+
}
|
|
657
|
+
const propertyType = matchOptionId(
|
|
658
|
+
segment,
|
|
659
|
+
dictionary.propertyTypes,
|
|
660
|
+
PROPERTY_TYPE_SLUG_ALIASES
|
|
661
|
+
);
|
|
662
|
+
if (propertyType) {
|
|
663
|
+
propertyTypes.push(propertyType);
|
|
664
|
+
continue;
|
|
665
|
+
}
|
|
666
|
+
const bedrooms = lower.match(BEDROOMS);
|
|
667
|
+
if (bedrooms) {
|
|
668
|
+
filters.bedrooms = collapse(parseNumericList(bedrooms[1]));
|
|
669
|
+
continue;
|
|
670
|
+
}
|
|
671
|
+
const bathrooms = lower.match(BATHROOMS);
|
|
672
|
+
if (bathrooms) {
|
|
673
|
+
filters.bathrooms = collapse(parseNumericList(bathrooms[1]));
|
|
674
|
+
continue;
|
|
675
|
+
}
|
|
676
|
+
const suites = lower.match(SUITES);
|
|
677
|
+
if (suites) {
|
|
678
|
+
filters.suites = collapse(parseNumericList(suites[1]));
|
|
679
|
+
continue;
|
|
680
|
+
}
|
|
681
|
+
const parking = lower.match(PARKING);
|
|
682
|
+
if (parking) {
|
|
683
|
+
filters.parkingSpots = collapse(parseNumericList(parking[1]));
|
|
684
|
+
continue;
|
|
685
|
+
}
|
|
686
|
+
const price = lower.match(PRICE);
|
|
687
|
+
if (price) {
|
|
688
|
+
filters.price = { min: Number(price[1]), max: Number(price[2]) };
|
|
689
|
+
continue;
|
|
690
|
+
}
|
|
691
|
+
const area = lower.match(AREA);
|
|
692
|
+
if (area) {
|
|
693
|
+
filters.area = { min: Number(area[1]), max: Number(area[2]) };
|
|
694
|
+
continue;
|
|
695
|
+
}
|
|
696
|
+
const featureId = matchOptionId(segment, dictionary.propertyFeatures);
|
|
697
|
+
if (featureId) {
|
|
698
|
+
propertyFeatures.push(featureId);
|
|
699
|
+
continue;
|
|
700
|
+
}
|
|
701
|
+
const amenityId = matchOptionId(segment, dictionary.buildingAmenities);
|
|
702
|
+
if (amenityId) {
|
|
703
|
+
buildingAmenities.push(amenityId);
|
|
704
|
+
continue;
|
|
705
|
+
}
|
|
706
|
+
locationParts.push(segment);
|
|
707
|
+
}
|
|
708
|
+
if (propertyTypes.length === 1) filters.propertyType = propertyTypes[0];
|
|
709
|
+
else if (propertyTypes.length > 1) filters.propertyType = propertyTypes;
|
|
710
|
+
if (propertyFeatures.length) filters.propertyFeatures = propertyFeatures;
|
|
711
|
+
if (buildingAmenities.length) filters.buildingAmenities = buildingAmenities;
|
|
712
|
+
const location = locationFromPathLeftovers(locationParts);
|
|
713
|
+
if (location) filters.location = location;
|
|
714
|
+
return filters;
|
|
715
|
+
}
|
|
716
|
+
var PATH_STREET_PREFIX = /^(rua|r|avenida|av|alameda|al|travessa|tv|estrada|rodovia|rod)-/i;
|
|
717
|
+
function locationFromPathLeftovers(parts) {
|
|
718
|
+
if (parts.length === 0) return void 0;
|
|
719
|
+
if (parts.length === 1) {
|
|
720
|
+
const value = parts[0];
|
|
721
|
+
if (PATH_STREET_PREFIX.test(value)) return { street: value };
|
|
722
|
+
if (/^[a-z]{2}$/i.test(value)) return { state: value };
|
|
723
|
+
return { neighborhood: value };
|
|
724
|
+
}
|
|
725
|
+
const [state, city, neighborhood, street] = parts;
|
|
726
|
+
return {
|
|
727
|
+
...state ? { state } : {},
|
|
728
|
+
...city ? { city } : {},
|
|
729
|
+
...neighborhood ? { neighborhood } : {},
|
|
730
|
+
...street ? { street } : {}
|
|
731
|
+
};
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
// ../search-url/applied-query.ts
|
|
735
|
+
var SORT_SET = new Set(SORT_URL_TOKENS);
|
|
736
|
+
function isSortToken(value) {
|
|
737
|
+
return SORT_SET.has(value);
|
|
738
|
+
}
|
|
739
|
+
function normalizeAppliedSearchQuery(query) {
|
|
740
|
+
if (query.loc && query.loc.length > 0) {
|
|
741
|
+
const { query: _query, ...rest } = query;
|
|
742
|
+
return rest;
|
|
743
|
+
}
|
|
744
|
+
return query;
|
|
745
|
+
}
|
|
746
|
+
function parseAppliedSearchQuery(search) {
|
|
747
|
+
const params = search instanceof URLSearchParams ? search : new URLSearchParams(search.startsWith("?") ? search.slice(1) : search);
|
|
748
|
+
const result = {};
|
|
749
|
+
const pageRaw = params.get("page");
|
|
750
|
+
if (pageRaw) {
|
|
751
|
+
const page = Number.parseInt(pageRaw, 10);
|
|
752
|
+
if (Number.isFinite(page) && page > 1) {
|
|
753
|
+
result.page = Math.min(page, MAX_PAGE);
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
const sort = params.get("ordenar");
|
|
757
|
+
if (sort && isSortToken(sort)) result.sort = sort;
|
|
758
|
+
const q = params.get("q")?.trim();
|
|
759
|
+
if (q) result.query = q;
|
|
760
|
+
const loc = params.getAll("loc").map((value) => value.trim()).filter(Boolean).slice(0, MAX_LOC_GROUPS);
|
|
761
|
+
if (loc.length > 0) result.loc = loc;
|
|
762
|
+
return normalizeAppliedSearchQuery(result);
|
|
763
|
+
}
|
|
764
|
+
var APPLIED_QUERY_KEYS = ["page", "ordenar", "q", "loc"];
|
|
765
|
+
function serializeAppliedSearchQuery(query) {
|
|
766
|
+
const normalized = normalizeAppliedSearchQuery(query);
|
|
767
|
+
const params = new URLSearchParams();
|
|
768
|
+
if (normalized.page !== void 0 && normalized.page > 1) {
|
|
769
|
+
params.set("page", String(Math.min(normalized.page, MAX_PAGE)));
|
|
770
|
+
}
|
|
771
|
+
if (normalized.sort && isSortToken(normalized.sort)) {
|
|
772
|
+
params.set("ordenar", normalized.sort);
|
|
773
|
+
}
|
|
774
|
+
const text = normalized.query?.trim();
|
|
775
|
+
if (text) params.set("q", text);
|
|
776
|
+
for (const value of (normalized.loc ?? []).slice(0, MAX_LOC_GROUPS)) {
|
|
777
|
+
const trimmed = value.trim();
|
|
778
|
+
if (trimmed) params.append("loc", trimmed);
|
|
779
|
+
}
|
|
780
|
+
return params;
|
|
781
|
+
}
|
|
782
|
+
function mergeAppliedSearchQueryIntoSearch(existing, query) {
|
|
783
|
+
const params = existing instanceof URLSearchParams ? new URLSearchParams(existing) : new URLSearchParams(
|
|
784
|
+
existing.startsWith("?") ? existing.slice(1) : existing
|
|
785
|
+
);
|
|
786
|
+
for (const key of APPLIED_QUERY_KEYS) {
|
|
787
|
+
params.delete(key);
|
|
788
|
+
}
|
|
789
|
+
const serialized = serializeAppliedSearchQuery(query);
|
|
790
|
+
serialized.forEach((value, key) => {
|
|
791
|
+
if (key === "loc") {
|
|
792
|
+
params.append("loc", value);
|
|
793
|
+
} else {
|
|
794
|
+
params.set(key, value);
|
|
795
|
+
}
|
|
796
|
+
});
|
|
797
|
+
return params;
|
|
798
|
+
}
|
|
799
|
+
function reduceAppliedSearchQuery(prev, change) {
|
|
800
|
+
switch (change.type) {
|
|
801
|
+
case "sort": {
|
|
802
|
+
const next = { ...prev };
|
|
803
|
+
delete next.page;
|
|
804
|
+
if (change.sort) next.sort = change.sort;
|
|
805
|
+
else delete next.sort;
|
|
806
|
+
return normalizeAppliedSearchQuery(next);
|
|
807
|
+
}
|
|
808
|
+
case "applyFilters": {
|
|
809
|
+
const next = { ...prev };
|
|
810
|
+
delete next.page;
|
|
811
|
+
return normalizeAppliedSearchQuery(next);
|
|
812
|
+
}
|
|
813
|
+
case "query": {
|
|
814
|
+
const next = { ...prev };
|
|
815
|
+
delete next.page;
|
|
816
|
+
const trimmed = change.query.trim();
|
|
817
|
+
if (trimmed) {
|
|
818
|
+
next.query = trimmed;
|
|
819
|
+
delete next.loc;
|
|
820
|
+
} else {
|
|
821
|
+
delete next.query;
|
|
822
|
+
}
|
|
823
|
+
return normalizeAppliedSearchQuery(next);
|
|
824
|
+
}
|
|
825
|
+
case "loc": {
|
|
826
|
+
const next = { ...prev };
|
|
827
|
+
delete next.page;
|
|
828
|
+
delete next.query;
|
|
829
|
+
const loc = change.loc.map((value) => value.trim()).filter(Boolean).slice(0, MAX_LOC_GROUPS);
|
|
830
|
+
if (loc.length > 0) next.loc = loc;
|
|
831
|
+
else delete next.loc;
|
|
832
|
+
return normalizeAppliedSearchQuery(next);
|
|
833
|
+
}
|
|
834
|
+
case "page": {
|
|
835
|
+
const next = { ...prev };
|
|
836
|
+
if (change.page <= 1) delete next.page;
|
|
837
|
+
else next.page = Math.min(change.page, MAX_PAGE);
|
|
838
|
+
return normalizeAppliedSearchQuery(next);
|
|
839
|
+
}
|
|
840
|
+
default: {
|
|
841
|
+
const _exhaustive = change;
|
|
842
|
+
return _exhaustive;
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
function composeSearchPublicHref(pathname, query, existingSearch) {
|
|
847
|
+
const params = existingSearch ? mergeAppliedSearchQueryIntoSearch(existingSearch, query) : serializeAppliedSearchQuery(query);
|
|
848
|
+
const qs = params.toString();
|
|
849
|
+
return qs ? `${pathname}?${qs}` : pathname;
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
// src/applied-query.ts
|
|
853
|
+
function parseAppliedSearchQuery2(search) {
|
|
854
|
+
return parseAppliedSearchQuery(search);
|
|
855
|
+
}
|
|
856
|
+
function serializeAppliedSearchQuery2(query) {
|
|
857
|
+
return serializeAppliedSearchQuery(query);
|
|
858
|
+
}
|
|
859
|
+
function mergeAppliedSearchQueryIntoSearch2(existing, query) {
|
|
860
|
+
return mergeAppliedSearchQueryIntoSearch(existing, query);
|
|
861
|
+
}
|
|
862
|
+
function reduceAppliedSearchQuery2(prev, change) {
|
|
863
|
+
return reduceAppliedSearchQuery(prev, change);
|
|
864
|
+
}
|
|
865
|
+
function composeSearchPublicHref2(pathname, query, existingSearch) {
|
|
866
|
+
return composeSearchPublicHref(pathname, query, existingSearch);
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
// src/loc-params.ts
|
|
870
|
+
function pathLocationToFilterInput(location) {
|
|
871
|
+
if (!location || typeof location !== "object") return null;
|
|
872
|
+
const { state, city, neighborhood, street } = location;
|
|
873
|
+
const levels = [];
|
|
874
|
+
if (state) levels.push(state);
|
|
875
|
+
if (city) levels.push(city);
|
|
876
|
+
if (neighborhood) levels.push(neighborhood);
|
|
877
|
+
if (street) levels.push(street);
|
|
878
|
+
if (levels.length === 0) return null;
|
|
879
|
+
if (levels.length === 1) {
|
|
880
|
+
if (state) return { type: "state", value: state };
|
|
881
|
+
if (city) return { type: "city", value: city };
|
|
882
|
+
if (neighborhood) return { type: "neighborhood", value: neighborhood };
|
|
883
|
+
if (street) return { type: "street", value: street };
|
|
884
|
+
}
|
|
885
|
+
return { type: "path", value: levels.join("/") };
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
// src/path.ts
|
|
889
|
+
function composeSearchPublicPath2(filters, dictionary) {
|
|
890
|
+
return dictionary ? composeSearchPublicPath(filters, dictionary) : composeSearchPublicPath(filters);
|
|
891
|
+
}
|
|
892
|
+
function parseSearchPublicPath2(pathname, dictionary) {
|
|
893
|
+
return dictionary ? parseSearchPublicPath(pathname, dictionary) : parseSearchPublicPath(pathname);
|
|
894
|
+
}
|
|
895
|
+
function pathFiltersToQueryFilters(pathFilters) {
|
|
896
|
+
const result = {};
|
|
897
|
+
if (pathFilters.listingType !== void 0) {
|
|
898
|
+
result.listing_type = pathFilters.listingType;
|
|
899
|
+
}
|
|
900
|
+
if (pathFilters.propertyType !== void 0) {
|
|
901
|
+
result.property_type = pathFilters.propertyType;
|
|
902
|
+
}
|
|
903
|
+
if (pathFilters.bedrooms !== void 0) {
|
|
904
|
+
result.property_bedrooms = pathFilters.bedrooms;
|
|
905
|
+
}
|
|
906
|
+
if (pathFilters.bathrooms !== void 0) {
|
|
907
|
+
result.property_bathrooms = pathFilters.bathrooms;
|
|
908
|
+
}
|
|
909
|
+
if (pathFilters.suites !== void 0) {
|
|
910
|
+
result.property_suites = pathFilters.suites;
|
|
911
|
+
}
|
|
912
|
+
if (pathFilters.parkingSpots !== void 0) {
|
|
913
|
+
result.property_parking_spots = pathFilters.parkingSpots;
|
|
914
|
+
}
|
|
915
|
+
if (pathFilters.price !== void 0) {
|
|
916
|
+
result.price = pathFilters.price;
|
|
917
|
+
}
|
|
918
|
+
if (pathFilters.area !== void 0) {
|
|
919
|
+
result.property_area_total = pathFilters.area;
|
|
920
|
+
}
|
|
921
|
+
if (pathFilters.propertyFeatures !== void 0) {
|
|
922
|
+
result.propertyFeatures = pathFilters.propertyFeatures;
|
|
923
|
+
}
|
|
924
|
+
if (pathFilters.buildingAmenities !== void 0) {
|
|
925
|
+
result.buildingAmenities = pathFilters.buildingAmenities;
|
|
926
|
+
}
|
|
927
|
+
return result;
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
// src/search-engine.ts
|
|
931
|
+
var PATH_FILTER_IDS = {
|
|
932
|
+
listing_type: "listingType",
|
|
933
|
+
property_type: "propertyType",
|
|
934
|
+
property_bedrooms: "bedrooms",
|
|
935
|
+
property_bathrooms: "bathrooms",
|
|
936
|
+
property_suites: "suites",
|
|
937
|
+
property_parking_spots: "parkingSpots",
|
|
938
|
+
price: "price",
|
|
939
|
+
property_area_total: "area",
|
|
940
|
+
propertyFeatures: "propertyFeatures",
|
|
941
|
+
buildingAmenities: "buildingAmenities"
|
|
942
|
+
};
|
|
943
|
+
var FORBIDDEN_SEARCH_QUERY_KEYS = [
|
|
944
|
+
"tipo",
|
|
945
|
+
"quartos",
|
|
946
|
+
"tipo-imovel",
|
|
947
|
+
"banheiros",
|
|
948
|
+
"vagas"
|
|
949
|
+
];
|
|
950
|
+
var SEARCH_SORT_RELEVANCE = {
|
|
951
|
+
id: "",
|
|
952
|
+
label: "Mais relevantes"
|
|
953
|
+
};
|
|
954
|
+
function searchSortOptions(sorts) {
|
|
955
|
+
const fromApi = (sorts || []).filter((sort) => sort.id);
|
|
956
|
+
return [
|
|
957
|
+
{ id: SEARCH_SORT_RELEVANCE.id, label: SEARCH_SORT_RELEVANCE.label },
|
|
958
|
+
...fromApi
|
|
959
|
+
];
|
|
960
|
+
}
|
|
961
|
+
var TOOLBAR_PRIMARY_FILTER_IDS = [
|
|
962
|
+
"price",
|
|
963
|
+
"property_bedrooms"
|
|
964
|
+
];
|
|
965
|
+
var HIDDEN_FILTER_IDS = /* @__PURE__ */ new Set(["property_suites"]);
|
|
966
|
+
function toFiniteNumber(value) {
|
|
967
|
+
if (value === "" || value == null) return void 0;
|
|
968
|
+
const n = Number(value);
|
|
969
|
+
return Number.isFinite(n) ? n : void 0;
|
|
970
|
+
}
|
|
971
|
+
function pathnameOnly(pathname) {
|
|
972
|
+
return String(pathname || "").split(/[?#]/)[0] || "/";
|
|
973
|
+
}
|
|
974
|
+
function isListingDetailPath(pathname) {
|
|
975
|
+
const parts = pathnameOnly(pathname).split("/").filter(Boolean);
|
|
976
|
+
const last = parts[parts.length - 1] || "";
|
|
977
|
+
return last.toLowerCase().startsWith("id-");
|
|
978
|
+
}
|
|
979
|
+
function readPublicSearch(pathname, search, dictionary) {
|
|
980
|
+
const pathFilters = parseSearchPublicPath2(pathnameOnly(pathname), dictionary) || {};
|
|
981
|
+
const applied = parseAppliedSearchQuery2(search || "");
|
|
982
|
+
return { pathFilters, applied };
|
|
983
|
+
}
|
|
984
|
+
function lookupDisplay(table, slug) {
|
|
985
|
+
if (!slug || !table) return slug;
|
|
986
|
+
return table[slug] || table[String(slug).toLowerCase()] || slug;
|
|
987
|
+
}
|
|
988
|
+
function displayPathLocation(location, values) {
|
|
989
|
+
if (!location) return null;
|
|
990
|
+
const table = values || {};
|
|
991
|
+
return {
|
|
992
|
+
state: lookupDisplay(table.states, location.state),
|
|
993
|
+
city: lookupDisplay(table.cities, location.city),
|
|
994
|
+
neighborhood: lookupDisplay(table.neighborhoods, location.neighborhood),
|
|
995
|
+
street: lookupDisplay(table.streets, location.street)
|
|
996
|
+
};
|
|
997
|
+
}
|
|
998
|
+
function buildQueryListingsParams(pathFilters, applied, schema, locationValues) {
|
|
999
|
+
const filters = pathFiltersToQueryFilters(pathFilters || {});
|
|
1000
|
+
const locations = [];
|
|
1001
|
+
const displayed = displayPathLocation(pathFilters?.location, locationValues);
|
|
1002
|
+
const pathLoc = displayed ? pathLocationToFilterInput(displayed) : null;
|
|
1003
|
+
if (pathLoc) locations.push(pathLoc);
|
|
1004
|
+
for (const value of applied?.loc || []) {
|
|
1005
|
+
locations.push({ type: "loc", value });
|
|
1006
|
+
}
|
|
1007
|
+
const params = {
|
|
1008
|
+
page: applied?.page || 1,
|
|
1009
|
+
limit: schema?.defaultLimit || 12,
|
|
1010
|
+
filters
|
|
1011
|
+
};
|
|
1012
|
+
if (applied?.sort) params.sort = applied.sort;
|
|
1013
|
+
const hasLocation = locations.length > 0;
|
|
1014
|
+
if (applied?.query && !hasLocation) params.q = applied.query;
|
|
1015
|
+
if (hasLocation) params.location = locations;
|
|
1016
|
+
return params;
|
|
1017
|
+
}
|
|
1018
|
+
function applyPathFilter(pathFilters, filterId, value) {
|
|
1019
|
+
const next = { ...pathFilters || {} };
|
|
1020
|
+
const key = PATH_FILTER_IDS[filterId];
|
|
1021
|
+
if (!key) return next;
|
|
1022
|
+
if (value === "" || value == null) {
|
|
1023
|
+
delete next[key];
|
|
1024
|
+
return next;
|
|
1025
|
+
}
|
|
1026
|
+
if (key === "price" || key === "area") {
|
|
1027
|
+
const range = value || {};
|
|
1028
|
+
const parse = key === "price" ? parseGroupedInteger : toFiniteNumber;
|
|
1029
|
+
const min = parse(range.min);
|
|
1030
|
+
const max = parse(range.max);
|
|
1031
|
+
if (min == null && max == null) {
|
|
1032
|
+
delete next[key];
|
|
1033
|
+
return next;
|
|
1034
|
+
}
|
|
1035
|
+
next[key] = {
|
|
1036
|
+
...min != null ? { min } : {},
|
|
1037
|
+
...max != null ? { max } : {}
|
|
1038
|
+
};
|
|
1039
|
+
return next;
|
|
1040
|
+
}
|
|
1041
|
+
if (key === "propertyFeatures" || key === "buildingAmenities") {
|
|
1042
|
+
const current = Array.isArray(next[key]) ? [...next[key]] : [];
|
|
1043
|
+
const id = String(value);
|
|
1044
|
+
const i = current.indexOf(id);
|
|
1045
|
+
if (i >= 0) current.splice(i, 1);
|
|
1046
|
+
else current.push(id);
|
|
1047
|
+
if (current.length) next[key] = current;
|
|
1048
|
+
else delete next[key];
|
|
1049
|
+
return next;
|
|
1050
|
+
}
|
|
1051
|
+
if (key === "propertyType") {
|
|
1052
|
+
const id = String(value);
|
|
1053
|
+
const current = Array.isArray(next.propertyType) ? [...next.propertyType] : next.propertyType ? [String(next.propertyType)] : [];
|
|
1054
|
+
const i = current.indexOf(id);
|
|
1055
|
+
if (i >= 0) current.splice(i, 1);
|
|
1056
|
+
else current.push(id);
|
|
1057
|
+
if (current.length === 0) delete next.propertyType;
|
|
1058
|
+
else if (current.length === 1) next.propertyType = current[0];
|
|
1059
|
+
else next.propertyType = current;
|
|
1060
|
+
return next;
|
|
1061
|
+
}
|
|
1062
|
+
if (key === "listingType") {
|
|
1063
|
+
const id = String(value);
|
|
1064
|
+
if (next.listingType === id) delete next.listingType;
|
|
1065
|
+
else next.listingType = id;
|
|
1066
|
+
return next;
|
|
1067
|
+
}
|
|
1068
|
+
if (key === "bedrooms" || key === "bathrooms" || key === "suites" || key === "parkingSpots") {
|
|
1069
|
+
const n = Number(value);
|
|
1070
|
+
if (!Number.isFinite(n)) {
|
|
1071
|
+
delete next[key];
|
|
1072
|
+
return next;
|
|
1073
|
+
}
|
|
1074
|
+
if (next[key] === n) delete next[key];
|
|
1075
|
+
else next[key] = n;
|
|
1076
|
+
return next;
|
|
1077
|
+
}
|
|
1078
|
+
return next;
|
|
1079
|
+
}
|
|
1080
|
+
function pathFilterValue(pathFilters, filterId) {
|
|
1081
|
+
const key = PATH_FILTER_IDS[filterId];
|
|
1082
|
+
const value = pathFilters && key ? pathFilters[key] : void 0;
|
|
1083
|
+
if (value == null) return "";
|
|
1084
|
+
if (Array.isArray(value)) return value[0] != null ? String(value[0]) : "";
|
|
1085
|
+
if (typeof value === "object") return "";
|
|
1086
|
+
return String(value);
|
|
1087
|
+
}
|
|
1088
|
+
function pathFilterHasOption(pathFilters, filterId, optionId) {
|
|
1089
|
+
const key = PATH_FILTER_IDS[filterId];
|
|
1090
|
+
const value = pathFilters && key ? pathFilters[key] : void 0;
|
|
1091
|
+
if (value == null) return false;
|
|
1092
|
+
if (Array.isArray(value)) return value.map(String).includes(optionId);
|
|
1093
|
+
if (typeof value === "object") return false;
|
|
1094
|
+
return String(value) === optionId;
|
|
1095
|
+
}
|
|
1096
|
+
function publicSearchHref(pathFilters, applied, dictionary, existingSearch) {
|
|
1097
|
+
const pathname = composeSearchPublicPath2(pathFilters || {}, dictionary);
|
|
1098
|
+
return composeSearchPublicHref2(pathname, applied || {}, existingSearch);
|
|
1099
|
+
}
|
|
1100
|
+
function hrefForPathFilters(pathname, search, dictionary, nextPathFilters) {
|
|
1101
|
+
const { applied } = readPublicSearch(pathname, search, dictionary);
|
|
1102
|
+
const nextApplied = reduceAppliedSearchQuery2(applied, {
|
|
1103
|
+
type: "applyFilters"
|
|
1104
|
+
});
|
|
1105
|
+
return publicSearchHref(nextPathFilters, nextApplied, dictionary, search);
|
|
1106
|
+
}
|
|
1107
|
+
function hrefForAppliedChange(pathname, search, dictionary, change) {
|
|
1108
|
+
const { pathFilters, applied } = readPublicSearch(
|
|
1109
|
+
pathname,
|
|
1110
|
+
search,
|
|
1111
|
+
dictionary
|
|
1112
|
+
);
|
|
1113
|
+
let nextPath = pathFilters;
|
|
1114
|
+
if (change && change.type === "query") {
|
|
1115
|
+
nextPath = { ...pathFilters };
|
|
1116
|
+
delete nextPath.location;
|
|
1117
|
+
}
|
|
1118
|
+
const nextApplied = reduceAppliedSearchQuery2(applied, change);
|
|
1119
|
+
return publicSearchHref(nextPath, nextApplied, dictionary, search);
|
|
1120
|
+
}
|
|
1121
|
+
function currentSearchHref(pathname, search) {
|
|
1122
|
+
const path = pathnameOnly(pathname);
|
|
1123
|
+
const qs = search.replace(/^\?/, "");
|
|
1124
|
+
return qs ? `${path}?${qs}` : path;
|
|
1125
|
+
}
|
|
1126
|
+
function canonicalizeSearchHref(pathname, search, dictionary) {
|
|
1127
|
+
const { pathFilters, applied } = readPublicSearch(
|
|
1128
|
+
pathname,
|
|
1129
|
+
search,
|
|
1130
|
+
dictionary
|
|
1131
|
+
);
|
|
1132
|
+
const href = publicSearchHref(pathFilters, applied, dictionary, search);
|
|
1133
|
+
if (href === currentSearchHref(pathname, search)) return null;
|
|
1134
|
+
return href;
|
|
1135
|
+
}
|
|
1136
|
+
function searchHrefUsesLegacyFilterQuery(href) {
|
|
1137
|
+
const query = href.split("?")[1] || "";
|
|
1138
|
+
const params = new URLSearchParams(query);
|
|
1139
|
+
return FORBIDDEN_SEARCH_QUERY_KEYS.some((key) => params.has(key));
|
|
1140
|
+
}
|
|
1141
|
+
function clearStagedPathFilters(current, keepFilterIds = []) {
|
|
1142
|
+
const next = current.location ? { location: current.location } : {};
|
|
1143
|
+
for (const id of keepFilterIds) {
|
|
1144
|
+
const key = PATH_FILTER_IDS[id];
|
|
1145
|
+
if (!key || key === "location") continue;
|
|
1146
|
+
const value = current[key];
|
|
1147
|
+
if (value != null) Object.assign(next, { [key]: value });
|
|
1148
|
+
}
|
|
1149
|
+
return next;
|
|
1150
|
+
}
|
|
1151
|
+
function visibleSearchFilters(schema) {
|
|
1152
|
+
if (!schema?.filters) return [];
|
|
1153
|
+
return schema.filters.filter((filter) => {
|
|
1154
|
+
if (HIDDEN_FILTER_IDS.has(filter.id)) return false;
|
|
1155
|
+
if (filter.id === "listing_type" && (filter.options?.length ?? 0) <= 1) {
|
|
1156
|
+
return false;
|
|
1157
|
+
}
|
|
1158
|
+
return true;
|
|
1159
|
+
});
|
|
1160
|
+
}
|
|
1161
|
+
function toolbarFilterIds(schema) {
|
|
1162
|
+
const visible = new Set(visibleSearchFilters(schema).map((f) => f.id));
|
|
1163
|
+
return TOOLBAR_PRIMARY_FILTER_IDS.filter((id) => visible.has(id));
|
|
1164
|
+
}
|
|
1165
|
+
function countOptionLabel(option) {
|
|
1166
|
+
const label = String(option?.label ?? "");
|
|
1167
|
+
if (/^[1-9]\d*$/.test(label)) return `${label}+`;
|
|
1168
|
+
return label;
|
|
1169
|
+
}
|
|
1170
|
+
function countFacetChoices(options) {
|
|
1171
|
+
const list = options || [];
|
|
1172
|
+
const zero = list.find((o) => o.id === "0" || o.label === "Studio");
|
|
1173
|
+
const isStudio = Boolean(
|
|
1174
|
+
zero && /studio/i.test(String(zero.label)) && zero.id === "0"
|
|
1175
|
+
);
|
|
1176
|
+
const max = isStudio ? 3 : 4;
|
|
1177
|
+
const out = [];
|
|
1178
|
+
if (zero) out.push({ id: zero.id, label: countOptionLabel(zero) });
|
|
1179
|
+
for (let n = 1; n <= max; n += 1) {
|
|
1180
|
+
const option = list.find((o) => o.id === String(n));
|
|
1181
|
+
out.push({
|
|
1182
|
+
id: String(n),
|
|
1183
|
+
label: countOptionLabel(option || { label: String(n) })
|
|
1184
|
+
});
|
|
1185
|
+
}
|
|
1186
|
+
return out;
|
|
1187
|
+
}
|
|
1188
|
+
function paginationPages(currentPage, totalPages, padding) {
|
|
1189
|
+
if (totalPages < 1) return [];
|
|
1190
|
+
const current = Math.min(Math.max(1, currentPage), totalPages);
|
|
1191
|
+
const start = Math.max(1, current - padding);
|
|
1192
|
+
const end = Math.min(totalPages, current + padding);
|
|
1193
|
+
const pages = [];
|
|
1194
|
+
for (let i = start; i <= end; i += 1) pages.push(i);
|
|
1195
|
+
return pages;
|
|
1196
|
+
}
|
|
1197
|
+
|
|
317
1198
|
// src/resolve-site-id.ts
|
|
318
1199
|
var PREVIEW_HOST_SUFFIXES = [".vusercontent.net"];
|
|
319
1200
|
function isStudioPreviewHost(host) {
|
|
@@ -410,6 +1291,23 @@ function createGaragemClient(options = {}) {
|
|
|
410
1291
|
if (merged !== void 0) opts.next = merged;
|
|
411
1292
|
return searchListings(opts);
|
|
412
1293
|
},
|
|
1294
|
+
async getSearchUi({ siteId, next } = {}) {
|
|
1295
|
+
const opts = withDefaults({
|
|
1296
|
+
siteId: resolveSiteId(siteId)
|
|
1297
|
+
});
|
|
1298
|
+
const merged = mergeNext(next);
|
|
1299
|
+
if (merged !== void 0) opts.next = merged;
|
|
1300
|
+
return getSearchUi(opts);
|
|
1301
|
+
},
|
|
1302
|
+
async queryListings({ params, siteId, next } = {}) {
|
|
1303
|
+
const opts = withDefaults({
|
|
1304
|
+
siteId: resolveSiteId(siteId)
|
|
1305
|
+
});
|
|
1306
|
+
if (params !== void 0) opts.params = params;
|
|
1307
|
+
const merged = mergeNext(next);
|
|
1308
|
+
if (merged !== void 0) opts.next = merged;
|
|
1309
|
+
return queryListings(opts);
|
|
1310
|
+
},
|
|
413
1311
|
async getSimilarListings({ listingId, limit, siteId, next }) {
|
|
414
1312
|
const opts = withDefaults({
|
|
415
1313
|
siteId: resolveSiteId(siteId),
|
|
@@ -462,20 +1360,62 @@ function createGaragemClient(options = {}) {
|
|
|
462
1360
|
}
|
|
463
1361
|
// Annotate the CommonJS export names for ESM import in node:
|
|
464
1362
|
0 && (module.exports = {
|
|
1363
|
+
FORBIDDEN_SEARCH_QUERY_KEYS,
|
|
465
1364
|
GaragemSdkError,
|
|
1365
|
+
SEARCH_CSS_RECIPE,
|
|
1366
|
+
SEARCH_CSS_VARS,
|
|
1367
|
+
SEARCH_SORT_RELEVANCE,
|
|
1368
|
+
TOOLBAR_PRIMARY_FILTER_IDS,
|
|
1369
|
+
applyPathFilter,
|
|
1370
|
+
buildQueryListingsParams,
|
|
1371
|
+
canonicalizeSearchHref,
|
|
1372
|
+
clearStagedPathFilters,
|
|
1373
|
+
composeSearchPublicHref,
|
|
1374
|
+
composeSearchPublicPath,
|
|
1375
|
+
countFacetChoices,
|
|
1376
|
+
countOptionLabel,
|
|
466
1377
|
createGaragemClient,
|
|
1378
|
+
displayPathLocation,
|
|
1379
|
+
formatAreaM2,
|
|
1380
|
+
formatGroupedInteger,
|
|
1381
|
+
formatListingPrice,
|
|
467
1382
|
getCmsCollection,
|
|
468
1383
|
getCmsCollections,
|
|
469
1384
|
getCmsEntries,
|
|
470
1385
|
getCmsEntry,
|
|
471
1386
|
getListing,
|
|
472
1387
|
getListings,
|
|
1388
|
+
getSearchUi,
|
|
473
1389
|
getSimilarListings,
|
|
474
1390
|
getSite,
|
|
1391
|
+
hrefForAppliedChange,
|
|
1392
|
+
hrefForPathFilters,
|
|
1393
|
+
isListingDetailPath,
|
|
475
1394
|
isStudioPreviewHost,
|
|
1395
|
+
listingBusinessLabel,
|
|
1396
|
+
listingLocationLabel,
|
|
476
1397
|
listingLookupKey,
|
|
477
1398
|
listingPublicPath,
|
|
1399
|
+
mergeAppliedSearchQueryIntoSearch,
|
|
1400
|
+
paginationPages,
|
|
1401
|
+
parseAppliedSearchQuery,
|
|
1402
|
+
parseGroupedInteger,
|
|
1403
|
+
parseSearchPublicPath,
|
|
1404
|
+
pathFilterHasOption,
|
|
1405
|
+
pathFilterValue,
|
|
1406
|
+
pathFiltersToQueryFilters,
|
|
1407
|
+
pathLocationToFilterInput,
|
|
1408
|
+
publicSearchHref,
|
|
1409
|
+
queryListings,
|
|
1410
|
+
readPublicSearch,
|
|
1411
|
+
reduceAppliedSearchQuery,
|
|
478
1412
|
resolvePublicSiteId,
|
|
479
|
-
|
|
1413
|
+
searchHrefUsesLegacyFilterQuery,
|
|
1414
|
+
searchListings,
|
|
1415
|
+
searchSortOptions,
|
|
1416
|
+
serializeAppliedSearchQuery,
|
|
1417
|
+
toListingCardModel,
|
|
1418
|
+
toolbarFilterIds,
|
|
1419
|
+
visibleSearchFilters
|
|
480
1420
|
});
|
|
481
1421
|
//# sourceMappingURL=index.js.map
|