@garagem-ai/site-sdk 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +188 -8
- package/dist/index.d.ts +188 -8
- package/dist/index.js +520 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +508 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +14 -4
- package/src/applied-query.ts +42 -0
- package/src/client.ts +36 -1
- package/src/fetchers.ts +56 -2
- package/src/index.ts +35 -0
- package/src/loc-params.ts +36 -0
- package/src/path.ts +73 -0
- package/src/types.ts +107 -4
package/dist/index.js
CHANGED
|
@@ -21,6 +21,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
GaragemSdkError: () => GaragemSdkError,
|
|
24
|
+
composeSearchPublicHref: () => composeSearchPublicHref2,
|
|
25
|
+
composeSearchPublicPath: () => composeSearchPublicPath2,
|
|
24
26
|
createGaragemClient: () => createGaragemClient,
|
|
25
27
|
getCmsCollection: () => getCmsCollection,
|
|
26
28
|
getCmsCollections: () => getCmsCollections,
|
|
@@ -28,13 +30,22 @@ __export(index_exports, {
|
|
|
28
30
|
getCmsEntry: () => getCmsEntry,
|
|
29
31
|
getListing: () => getListing,
|
|
30
32
|
getListings: () => getListings,
|
|
33
|
+
getSearchUi: () => getSearchUi,
|
|
31
34
|
getSimilarListings: () => getSimilarListings,
|
|
32
35
|
getSite: () => getSite,
|
|
33
36
|
isStudioPreviewHost: () => isStudioPreviewHost,
|
|
34
37
|
listingLookupKey: () => listingLookupKey,
|
|
35
38
|
listingPublicPath: () => listingPublicPath,
|
|
39
|
+
mergeAppliedSearchQueryIntoSearch: () => mergeAppliedSearchQueryIntoSearch2,
|
|
40
|
+
parseAppliedSearchQuery: () => parseAppliedSearchQuery2,
|
|
41
|
+
parseSearchPublicPath: () => parseSearchPublicPath2,
|
|
42
|
+
pathFiltersToQueryFilters: () => pathFiltersToQueryFilters,
|
|
43
|
+
pathLocationToFilterInput: () => pathLocationToFilterInput,
|
|
44
|
+
queryListings: () => queryListings,
|
|
45
|
+
reduceAppliedSearchQuery: () => reduceAppliedSearchQuery2,
|
|
36
46
|
resolvePublicSiteId: () => resolvePublicSiteId,
|
|
37
|
-
searchListings: () => searchListings
|
|
47
|
+
searchListings: () => searchListings,
|
|
48
|
+
serializeAppliedSearchQuery: () => serializeAppliedSearchQuery2
|
|
38
49
|
});
|
|
39
50
|
module.exports = __toCommonJS(index_exports);
|
|
40
51
|
|
|
@@ -192,6 +203,34 @@ async function searchListings(options) {
|
|
|
192
203
|
fetchImpl ?? fetch
|
|
193
204
|
);
|
|
194
205
|
}
|
|
206
|
+
async function getSearchUi(options) {
|
|
207
|
+
const { siteId, baseUrl, fetch: fetchImpl, next } = options;
|
|
208
|
+
const base = normalizeBaseUrl(baseUrl);
|
|
209
|
+
const url = `${base}/api/sites/${encodeURIComponent(siteId)}/search-ui`;
|
|
210
|
+
return callJson(
|
|
211
|
+
url,
|
|
212
|
+
{ method: "GET", headers: { Accept: "application/json" }, next },
|
|
213
|
+
fetchImpl ?? fetch
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
async function queryListings(options) {
|
|
217
|
+
const { siteId, params, baseUrl, fetch: fetchImpl, next } = options;
|
|
218
|
+
const base = normalizeBaseUrl(baseUrl);
|
|
219
|
+
const url = `${base}/api/sites/${encodeURIComponent(siteId)}/search/listings`;
|
|
220
|
+
return callJson(
|
|
221
|
+
url,
|
|
222
|
+
{
|
|
223
|
+
method: "POST",
|
|
224
|
+
headers: {
|
|
225
|
+
Accept: "application/json",
|
|
226
|
+
"Content-Type": "application/json"
|
|
227
|
+
},
|
|
228
|
+
body: JSON.stringify(params ?? {}),
|
|
229
|
+
next
|
|
230
|
+
},
|
|
231
|
+
fetchImpl ?? fetch
|
|
232
|
+
);
|
|
233
|
+
}
|
|
195
234
|
async function getSimilarListings(options) {
|
|
196
235
|
const {
|
|
197
236
|
siteId,
|
|
@@ -314,6 +353,457 @@ async function getCmsEntry(options) {
|
|
|
314
353
|
return data;
|
|
315
354
|
}
|
|
316
355
|
|
|
356
|
+
// ../search-url/types.ts
|
|
357
|
+
var SEARCH_BASE_ROUTE = "imoveis";
|
|
358
|
+
var MAX_PAGE = 1e4;
|
|
359
|
+
var MAX_LOC_GROUPS = 20;
|
|
360
|
+
var DEFAULT_MIN_PRICE = 0;
|
|
361
|
+
var DEFAULT_MAX_PRICE = 1e9;
|
|
362
|
+
var DEFAULT_MIN_AREA = 0;
|
|
363
|
+
var DEFAULT_MAX_AREA = 1e5;
|
|
364
|
+
var SORT_URL_TOKENS = [
|
|
365
|
+
"preco-asc",
|
|
366
|
+
"preco-desc",
|
|
367
|
+
"area-asc",
|
|
368
|
+
"area-desc"
|
|
369
|
+
];
|
|
370
|
+
|
|
371
|
+
// ../search-url/slugify.ts
|
|
372
|
+
function slugifyForUrl(text) {
|
|
373
|
+
if (!text) return "";
|
|
374
|
+
const withDashes = text.replace(/([a-z])([A-Z])/g, "$1-$2");
|
|
375
|
+
return withDashes.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "").replace(/[^\w\s-]/g, "").replace(/\s+/g, "-").replace(/-+/g, "-").trim();
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// ../search-url/catalog.ts
|
|
379
|
+
var PROPERTY_TYPE_SLUG_ALIASES = {
|
|
380
|
+
rural: ["chacara", "fazenda", "sitio"]
|
|
381
|
+
};
|
|
382
|
+
function buildListingTypeOptions(enabled) {
|
|
383
|
+
const flags = enabled ?? { sale: true, rental: true };
|
|
384
|
+
const out = [];
|
|
385
|
+
if (flags.sale !== false) {
|
|
386
|
+
out.push({ id: "sale", slug: "venda", label: "Venda" });
|
|
387
|
+
}
|
|
388
|
+
if (flags.rental !== false) {
|
|
389
|
+
out.push({ id: "rental", slug: "aluguel", label: "Aluguel" });
|
|
390
|
+
}
|
|
391
|
+
return out;
|
|
392
|
+
}
|
|
393
|
+
function emptySearchUrlDictionary() {
|
|
394
|
+
return {
|
|
395
|
+
listingTypes: buildListingTypeOptions(null),
|
|
396
|
+
propertyTypes: [],
|
|
397
|
+
propertyFeatures: [],
|
|
398
|
+
buildingAmenities: []
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
function norm(value) {
|
|
402
|
+
return slugifyForUrl(value) || value.toLowerCase();
|
|
403
|
+
}
|
|
404
|
+
function matchOptionId(segment, options, extraAliases) {
|
|
405
|
+
const n = norm(segment);
|
|
406
|
+
for (const option of options) {
|
|
407
|
+
const aliases = extraAliases?.[option.id] ?? [];
|
|
408
|
+
const candidates = [option.id, option.slug, option.label, ...aliases];
|
|
409
|
+
if (candidates.some((c) => norm(c) === n)) return option.id;
|
|
410
|
+
}
|
|
411
|
+
return null;
|
|
412
|
+
}
|
|
413
|
+
function optionSlugById(id, options) {
|
|
414
|
+
const option = options.find((item) => item.id === id);
|
|
415
|
+
return option?.slug ?? null;
|
|
416
|
+
}
|
|
417
|
+
var LISTING_TYPE_ALIASES = {
|
|
418
|
+
sale: ["comprar"],
|
|
419
|
+
rental: ["alugar"]
|
|
420
|
+
};
|
|
421
|
+
|
|
422
|
+
// ../search-url/path.ts
|
|
423
|
+
function toArray(value) {
|
|
424
|
+
if (value === void 0) return [];
|
|
425
|
+
return Array.isArray(value) ? value : [value];
|
|
426
|
+
}
|
|
427
|
+
function formatNumeric(value) {
|
|
428
|
+
return Array.isArray(value) ? value.join("-") : String(value);
|
|
429
|
+
}
|
|
430
|
+
function formatRange(min, max, unit) {
|
|
431
|
+
return `de-${min}-a-${max}-${unit}`;
|
|
432
|
+
}
|
|
433
|
+
function formatSuiteSuffix(value) {
|
|
434
|
+
const values = Array.isArray(value) ? value : [value];
|
|
435
|
+
const firstValue = values[0] ?? 0;
|
|
436
|
+
return firstValue === 0 || firstValue === 1 ? "suite" : "suites";
|
|
437
|
+
}
|
|
438
|
+
function composeSearchPublicPath(filters, dictionary = emptySearchUrlDictionary()) {
|
|
439
|
+
const segments = [];
|
|
440
|
+
const listingType = filters.listingType;
|
|
441
|
+
if (listingType) {
|
|
442
|
+
segments.push(
|
|
443
|
+
optionSlugById(listingType, dictionary.listingTypes) || slugifyForUrl(listingType)
|
|
444
|
+
);
|
|
445
|
+
}
|
|
446
|
+
for (const propertyType of toArray(filters.propertyType)) {
|
|
447
|
+
segments.push(
|
|
448
|
+
optionSlugById(propertyType, dictionary.propertyTypes) || slugifyForUrl(propertyType)
|
|
449
|
+
);
|
|
450
|
+
}
|
|
451
|
+
const location = filters.location;
|
|
452
|
+
if (location) {
|
|
453
|
+
if (location.state) segments.push(slugifyForUrl(location.state));
|
|
454
|
+
if (location.city) segments.push(slugifyForUrl(location.city));
|
|
455
|
+
if (location.neighborhood)
|
|
456
|
+
segments.push(slugifyForUrl(location.neighborhood));
|
|
457
|
+
if (location.street) segments.push(slugifyForUrl(location.street));
|
|
458
|
+
}
|
|
459
|
+
if (filters.bedrooms !== void 0) {
|
|
460
|
+
segments.push(`${formatNumeric(filters.bedrooms)}-quartos`);
|
|
461
|
+
}
|
|
462
|
+
if (filters.bathrooms !== void 0) {
|
|
463
|
+
segments.push(`${formatNumeric(filters.bathrooms)}-banheiros`);
|
|
464
|
+
}
|
|
465
|
+
if (filters.suites !== void 0) {
|
|
466
|
+
const suffix = formatSuiteSuffix(filters.suites);
|
|
467
|
+
segments.push(`${formatNumeric(filters.suites)}-${suffix}`);
|
|
468
|
+
}
|
|
469
|
+
if (filters.parkingSpots !== void 0) {
|
|
470
|
+
segments.push(`${formatNumeric(filters.parkingSpots)}-vagas`);
|
|
471
|
+
}
|
|
472
|
+
if (filters.price && (filters.price.min !== void 0 || filters.price.max !== void 0)) {
|
|
473
|
+
const min = filters.price.min ?? DEFAULT_MIN_PRICE;
|
|
474
|
+
const max = filters.price.max ?? DEFAULT_MAX_PRICE;
|
|
475
|
+
segments.push(formatRange(min, max, "reais"));
|
|
476
|
+
}
|
|
477
|
+
if (filters.area && (filters.area.min !== void 0 || filters.area.max !== void 0)) {
|
|
478
|
+
const min = filters.area.min ?? DEFAULT_MIN_AREA;
|
|
479
|
+
const max = filters.area.max ?? DEFAULT_MAX_AREA;
|
|
480
|
+
segments.push(formatRange(min, max, "m2"));
|
|
481
|
+
}
|
|
482
|
+
const seenAmenities = /* @__PURE__ */ new Set();
|
|
483
|
+
for (const id of filters.propertyFeatures ?? []) {
|
|
484
|
+
const slug = optionSlugById(id, dictionary.propertyFeatures) || slugifyForUrl(id);
|
|
485
|
+
if (!slug || seenAmenities.has(slug)) continue;
|
|
486
|
+
seenAmenities.add(slug);
|
|
487
|
+
segments.push(slug);
|
|
488
|
+
}
|
|
489
|
+
for (const id of filters.buildingAmenities ?? []) {
|
|
490
|
+
const slug = optionSlugById(id, dictionary.buildingAmenities) || slugifyForUrl(id);
|
|
491
|
+
if (!slug || seenAmenities.has(slug)) continue;
|
|
492
|
+
seenAmenities.add(slug);
|
|
493
|
+
segments.push(slug);
|
|
494
|
+
}
|
|
495
|
+
const path = segments.filter(Boolean).join("/");
|
|
496
|
+
return path ? `/${SEARCH_BASE_ROUTE}/${path}` : `/${SEARCH_BASE_ROUTE}`;
|
|
497
|
+
}
|
|
498
|
+
var BEDROOMS = /^(\d+(?:-\d+)*)-quartos?$/;
|
|
499
|
+
var BATHROOMS = /^(\d+(?:-\d+)*)-banheiros?$/;
|
|
500
|
+
var SUITES = /^(\d+(?:-\d+)*)-suites?$/;
|
|
501
|
+
var PARKING = /^(\d+(?:-\d+)*)-vagas?$/;
|
|
502
|
+
var PRICE = /^de-(\d+)-a-(\d+)-(reais|real)$/;
|
|
503
|
+
var AREA = /^de-(\d+)-a-(\d+)-(m2|m²)$/;
|
|
504
|
+
function parseNumericList(raw) {
|
|
505
|
+
return raw.split("-").map((part) => Number(part)).filter((n) => Number.isFinite(n));
|
|
506
|
+
}
|
|
507
|
+
function collapse(values) {
|
|
508
|
+
return values.length === 1 ? values[0] : values;
|
|
509
|
+
}
|
|
510
|
+
function parseSearchPublicPath(pathname, dictionary = emptySearchUrlDictionary()) {
|
|
511
|
+
const raw = pathname.split(/[?#]/)[0] ?? "";
|
|
512
|
+
let segments = raw.replace(/^\//, "").split("/").filter(Boolean);
|
|
513
|
+
if (segments[0] === SEARCH_BASE_ROUTE) segments = segments.slice(1);
|
|
514
|
+
if (segments.some((segment) => segment.includes("."))) return null;
|
|
515
|
+
if (segments.some((segment) => segment.toLowerCase().startsWith("id-"))) {
|
|
516
|
+
return null;
|
|
517
|
+
}
|
|
518
|
+
const filters = {};
|
|
519
|
+
const locationParts = [];
|
|
520
|
+
const propertyTypes = [];
|
|
521
|
+
const propertyFeatures = [];
|
|
522
|
+
const buildingAmenities = [];
|
|
523
|
+
for (const segment of segments) {
|
|
524
|
+
const lower = segment.toLowerCase();
|
|
525
|
+
const listingType = matchOptionId(
|
|
526
|
+
segment,
|
|
527
|
+
dictionary.listingTypes,
|
|
528
|
+
LISTING_TYPE_ALIASES
|
|
529
|
+
);
|
|
530
|
+
if (listingType && !filters.listingType) {
|
|
531
|
+
filters.listingType = listingType;
|
|
532
|
+
continue;
|
|
533
|
+
}
|
|
534
|
+
const propertyType = matchOptionId(
|
|
535
|
+
segment,
|
|
536
|
+
dictionary.propertyTypes,
|
|
537
|
+
PROPERTY_TYPE_SLUG_ALIASES
|
|
538
|
+
);
|
|
539
|
+
if (propertyType) {
|
|
540
|
+
propertyTypes.push(propertyType);
|
|
541
|
+
continue;
|
|
542
|
+
}
|
|
543
|
+
const bedrooms = lower.match(BEDROOMS);
|
|
544
|
+
if (bedrooms) {
|
|
545
|
+
filters.bedrooms = collapse(parseNumericList(bedrooms[1]));
|
|
546
|
+
continue;
|
|
547
|
+
}
|
|
548
|
+
const bathrooms = lower.match(BATHROOMS);
|
|
549
|
+
if (bathrooms) {
|
|
550
|
+
filters.bathrooms = collapse(parseNumericList(bathrooms[1]));
|
|
551
|
+
continue;
|
|
552
|
+
}
|
|
553
|
+
const suites = lower.match(SUITES);
|
|
554
|
+
if (suites) {
|
|
555
|
+
filters.suites = collapse(parseNumericList(suites[1]));
|
|
556
|
+
continue;
|
|
557
|
+
}
|
|
558
|
+
const parking = lower.match(PARKING);
|
|
559
|
+
if (parking) {
|
|
560
|
+
filters.parkingSpots = collapse(parseNumericList(parking[1]));
|
|
561
|
+
continue;
|
|
562
|
+
}
|
|
563
|
+
const price = lower.match(PRICE);
|
|
564
|
+
if (price) {
|
|
565
|
+
filters.price = { min: Number(price[1]), max: Number(price[2]) };
|
|
566
|
+
continue;
|
|
567
|
+
}
|
|
568
|
+
const area = lower.match(AREA);
|
|
569
|
+
if (area) {
|
|
570
|
+
filters.area = { min: Number(area[1]), max: Number(area[2]) };
|
|
571
|
+
continue;
|
|
572
|
+
}
|
|
573
|
+
const featureId = matchOptionId(segment, dictionary.propertyFeatures);
|
|
574
|
+
if (featureId) {
|
|
575
|
+
propertyFeatures.push(featureId);
|
|
576
|
+
continue;
|
|
577
|
+
}
|
|
578
|
+
const amenityId = matchOptionId(segment, dictionary.buildingAmenities);
|
|
579
|
+
if (amenityId) {
|
|
580
|
+
buildingAmenities.push(amenityId);
|
|
581
|
+
continue;
|
|
582
|
+
}
|
|
583
|
+
locationParts.push(segment);
|
|
584
|
+
}
|
|
585
|
+
if (propertyTypes.length === 1) filters.propertyType = propertyTypes[0];
|
|
586
|
+
else if (propertyTypes.length > 1) filters.propertyType = propertyTypes;
|
|
587
|
+
if (propertyFeatures.length) filters.propertyFeatures = propertyFeatures;
|
|
588
|
+
if (buildingAmenities.length) filters.buildingAmenities = buildingAmenities;
|
|
589
|
+
const location = locationFromPathLeftovers(locationParts);
|
|
590
|
+
if (location) filters.location = location;
|
|
591
|
+
return filters;
|
|
592
|
+
}
|
|
593
|
+
var PATH_STREET_PREFIX = /^(rua|r|avenida|av|alameda|al|travessa|tv|estrada|rodovia|rod)-/i;
|
|
594
|
+
function locationFromPathLeftovers(parts) {
|
|
595
|
+
if (parts.length === 0) return void 0;
|
|
596
|
+
if (parts.length === 1) {
|
|
597
|
+
const value = parts[0];
|
|
598
|
+
if (PATH_STREET_PREFIX.test(value)) return { street: value };
|
|
599
|
+
if (/^[a-z]{2}$/i.test(value)) return { state: value };
|
|
600
|
+
return { neighborhood: value };
|
|
601
|
+
}
|
|
602
|
+
const [state, city, neighborhood, street] = parts;
|
|
603
|
+
return {
|
|
604
|
+
...state ? { state } : {},
|
|
605
|
+
...city ? { city } : {},
|
|
606
|
+
...neighborhood ? { neighborhood } : {},
|
|
607
|
+
...street ? { street } : {}
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
// ../search-url/applied-query.ts
|
|
612
|
+
var SORT_SET = new Set(SORT_URL_TOKENS);
|
|
613
|
+
function isSortToken(value) {
|
|
614
|
+
return SORT_SET.has(value);
|
|
615
|
+
}
|
|
616
|
+
function normalizeAppliedSearchQuery(query) {
|
|
617
|
+
if (query.loc && query.loc.length > 0) {
|
|
618
|
+
const { query: _query, ...rest } = query;
|
|
619
|
+
return rest;
|
|
620
|
+
}
|
|
621
|
+
return query;
|
|
622
|
+
}
|
|
623
|
+
function parseAppliedSearchQuery(search) {
|
|
624
|
+
const params = search instanceof URLSearchParams ? search : new URLSearchParams(search.startsWith("?") ? search.slice(1) : search);
|
|
625
|
+
const result = {};
|
|
626
|
+
const pageRaw = params.get("page");
|
|
627
|
+
if (pageRaw) {
|
|
628
|
+
const page = Number.parseInt(pageRaw, 10);
|
|
629
|
+
if (Number.isFinite(page) && page > 1) {
|
|
630
|
+
result.page = Math.min(page, MAX_PAGE);
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
const sort = params.get("ordenar");
|
|
634
|
+
if (sort && isSortToken(sort)) result.sort = sort;
|
|
635
|
+
const q = params.get("q")?.trim();
|
|
636
|
+
if (q) result.query = q;
|
|
637
|
+
const loc = params.getAll("loc").map((value) => value.trim()).filter(Boolean).slice(0, MAX_LOC_GROUPS);
|
|
638
|
+
if (loc.length > 0) result.loc = loc;
|
|
639
|
+
return normalizeAppliedSearchQuery(result);
|
|
640
|
+
}
|
|
641
|
+
var APPLIED_QUERY_KEYS = ["page", "ordenar", "q", "loc"];
|
|
642
|
+
function serializeAppliedSearchQuery(query) {
|
|
643
|
+
const normalized = normalizeAppliedSearchQuery(query);
|
|
644
|
+
const params = new URLSearchParams();
|
|
645
|
+
if (normalized.page !== void 0 && normalized.page > 1) {
|
|
646
|
+
params.set("page", String(Math.min(normalized.page, MAX_PAGE)));
|
|
647
|
+
}
|
|
648
|
+
if (normalized.sort && isSortToken(normalized.sort)) {
|
|
649
|
+
params.set("ordenar", normalized.sort);
|
|
650
|
+
}
|
|
651
|
+
const text = normalized.query?.trim();
|
|
652
|
+
if (text) params.set("q", text);
|
|
653
|
+
for (const value of (normalized.loc ?? []).slice(0, MAX_LOC_GROUPS)) {
|
|
654
|
+
const trimmed = value.trim();
|
|
655
|
+
if (trimmed) params.append("loc", trimmed);
|
|
656
|
+
}
|
|
657
|
+
return params;
|
|
658
|
+
}
|
|
659
|
+
function mergeAppliedSearchQueryIntoSearch(existing, query) {
|
|
660
|
+
const params = existing instanceof URLSearchParams ? new URLSearchParams(existing) : new URLSearchParams(
|
|
661
|
+
existing.startsWith("?") ? existing.slice(1) : existing
|
|
662
|
+
);
|
|
663
|
+
for (const key of APPLIED_QUERY_KEYS) {
|
|
664
|
+
params.delete(key);
|
|
665
|
+
}
|
|
666
|
+
const serialized = serializeAppliedSearchQuery(query);
|
|
667
|
+
serialized.forEach((value, key) => {
|
|
668
|
+
if (key === "loc") {
|
|
669
|
+
params.append("loc", value);
|
|
670
|
+
} else {
|
|
671
|
+
params.set(key, value);
|
|
672
|
+
}
|
|
673
|
+
});
|
|
674
|
+
return params;
|
|
675
|
+
}
|
|
676
|
+
function reduceAppliedSearchQuery(prev, change) {
|
|
677
|
+
switch (change.type) {
|
|
678
|
+
case "sort": {
|
|
679
|
+
const next = { ...prev };
|
|
680
|
+
delete next.page;
|
|
681
|
+
if (change.sort) next.sort = change.sort;
|
|
682
|
+
else delete next.sort;
|
|
683
|
+
return normalizeAppliedSearchQuery(next);
|
|
684
|
+
}
|
|
685
|
+
case "applyFilters": {
|
|
686
|
+
const next = { ...prev };
|
|
687
|
+
delete next.page;
|
|
688
|
+
return normalizeAppliedSearchQuery(next);
|
|
689
|
+
}
|
|
690
|
+
case "query": {
|
|
691
|
+
const next = { ...prev };
|
|
692
|
+
delete next.page;
|
|
693
|
+
const trimmed = change.query.trim();
|
|
694
|
+
if (trimmed) {
|
|
695
|
+
next.query = trimmed;
|
|
696
|
+
delete next.loc;
|
|
697
|
+
} else {
|
|
698
|
+
delete next.query;
|
|
699
|
+
}
|
|
700
|
+
return normalizeAppliedSearchQuery(next);
|
|
701
|
+
}
|
|
702
|
+
case "loc": {
|
|
703
|
+
const next = { ...prev };
|
|
704
|
+
delete next.page;
|
|
705
|
+
delete next.query;
|
|
706
|
+
const loc = change.loc.map((value) => value.trim()).filter(Boolean).slice(0, MAX_LOC_GROUPS);
|
|
707
|
+
if (loc.length > 0) next.loc = loc;
|
|
708
|
+
else delete next.loc;
|
|
709
|
+
return normalizeAppliedSearchQuery(next);
|
|
710
|
+
}
|
|
711
|
+
case "page": {
|
|
712
|
+
const next = { ...prev };
|
|
713
|
+
if (change.page <= 1) delete next.page;
|
|
714
|
+
else next.page = Math.min(change.page, MAX_PAGE);
|
|
715
|
+
return normalizeAppliedSearchQuery(next);
|
|
716
|
+
}
|
|
717
|
+
default: {
|
|
718
|
+
const _exhaustive = change;
|
|
719
|
+
return _exhaustive;
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
function composeSearchPublicHref(pathname, query, existingSearch) {
|
|
724
|
+
const params = existingSearch ? mergeAppliedSearchQueryIntoSearch(existingSearch, query) : serializeAppliedSearchQuery(query);
|
|
725
|
+
const qs = params.toString();
|
|
726
|
+
return qs ? `${pathname}?${qs}` : pathname;
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
// src/path.ts
|
|
730
|
+
function composeSearchPublicPath2(filters, dictionary) {
|
|
731
|
+
return dictionary ? composeSearchPublicPath(filters, dictionary) : composeSearchPublicPath(filters);
|
|
732
|
+
}
|
|
733
|
+
function parseSearchPublicPath2(pathname, dictionary) {
|
|
734
|
+
return dictionary ? parseSearchPublicPath(pathname, dictionary) : parseSearchPublicPath(pathname);
|
|
735
|
+
}
|
|
736
|
+
function pathFiltersToQueryFilters(pathFilters) {
|
|
737
|
+
const result = {};
|
|
738
|
+
if (pathFilters.listingType !== void 0) {
|
|
739
|
+
result.listing_type = pathFilters.listingType;
|
|
740
|
+
}
|
|
741
|
+
if (pathFilters.propertyType !== void 0) {
|
|
742
|
+
result.property_type = pathFilters.propertyType;
|
|
743
|
+
}
|
|
744
|
+
if (pathFilters.bedrooms !== void 0) {
|
|
745
|
+
result.property_bedrooms = pathFilters.bedrooms;
|
|
746
|
+
}
|
|
747
|
+
if (pathFilters.bathrooms !== void 0) {
|
|
748
|
+
result.property_bathrooms = pathFilters.bathrooms;
|
|
749
|
+
}
|
|
750
|
+
if (pathFilters.suites !== void 0) {
|
|
751
|
+
result.property_suites = pathFilters.suites;
|
|
752
|
+
}
|
|
753
|
+
if (pathFilters.parkingSpots !== void 0) {
|
|
754
|
+
result.property_parking_spots = pathFilters.parkingSpots;
|
|
755
|
+
}
|
|
756
|
+
if (pathFilters.price !== void 0) {
|
|
757
|
+
result.price = pathFilters.price;
|
|
758
|
+
}
|
|
759
|
+
if (pathFilters.area !== void 0) {
|
|
760
|
+
result.property_area_total = pathFilters.area;
|
|
761
|
+
}
|
|
762
|
+
if (pathFilters.propertyFeatures !== void 0) {
|
|
763
|
+
result.propertyFeatures = pathFilters.propertyFeatures;
|
|
764
|
+
}
|
|
765
|
+
if (pathFilters.buildingAmenities !== void 0) {
|
|
766
|
+
result.buildingAmenities = pathFilters.buildingAmenities;
|
|
767
|
+
}
|
|
768
|
+
return result;
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
// src/applied-query.ts
|
|
772
|
+
function parseAppliedSearchQuery2(search) {
|
|
773
|
+
return parseAppliedSearchQuery(search);
|
|
774
|
+
}
|
|
775
|
+
function serializeAppliedSearchQuery2(query) {
|
|
776
|
+
return serializeAppliedSearchQuery(query);
|
|
777
|
+
}
|
|
778
|
+
function mergeAppliedSearchQueryIntoSearch2(existing, query) {
|
|
779
|
+
return mergeAppliedSearchQueryIntoSearch(existing, query);
|
|
780
|
+
}
|
|
781
|
+
function reduceAppliedSearchQuery2(prev, change) {
|
|
782
|
+
return reduceAppliedSearchQuery(prev, change);
|
|
783
|
+
}
|
|
784
|
+
function composeSearchPublicHref2(pathname, query, existingSearch) {
|
|
785
|
+
return composeSearchPublicHref(pathname, query, existingSearch);
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
// src/loc-params.ts
|
|
789
|
+
function pathLocationToFilterInput(location) {
|
|
790
|
+
if (!location || typeof location !== "object") return null;
|
|
791
|
+
const { state, city, neighborhood, street } = location;
|
|
792
|
+
const levels = [];
|
|
793
|
+
if (state) levels.push(state);
|
|
794
|
+
if (city) levels.push(city);
|
|
795
|
+
if (neighborhood) levels.push(neighborhood);
|
|
796
|
+
if (street) levels.push(street);
|
|
797
|
+
if (levels.length === 0) return null;
|
|
798
|
+
if (levels.length === 1) {
|
|
799
|
+
if (state) return { type: "state", value: state };
|
|
800
|
+
if (city) return { type: "city", value: city };
|
|
801
|
+
if (neighborhood) return { type: "neighborhood", value: neighborhood };
|
|
802
|
+
if (street) return { type: "street", value: street };
|
|
803
|
+
}
|
|
804
|
+
return { type: "path", value: levels.join("/") };
|
|
805
|
+
}
|
|
806
|
+
|
|
317
807
|
// src/resolve-site-id.ts
|
|
318
808
|
var PREVIEW_HOST_SUFFIXES = [".vusercontent.net"];
|
|
319
809
|
function isStudioPreviewHost(host) {
|
|
@@ -410,6 +900,23 @@ function createGaragemClient(options = {}) {
|
|
|
410
900
|
if (merged !== void 0) opts.next = merged;
|
|
411
901
|
return searchListings(opts);
|
|
412
902
|
},
|
|
903
|
+
async getSearchUi({ siteId, next } = {}) {
|
|
904
|
+
const opts = withDefaults({
|
|
905
|
+
siteId: resolveSiteId(siteId)
|
|
906
|
+
});
|
|
907
|
+
const merged = mergeNext(next);
|
|
908
|
+
if (merged !== void 0) opts.next = merged;
|
|
909
|
+
return getSearchUi(opts);
|
|
910
|
+
},
|
|
911
|
+
async queryListings({ params, siteId, next } = {}) {
|
|
912
|
+
const opts = withDefaults({
|
|
913
|
+
siteId: resolveSiteId(siteId)
|
|
914
|
+
});
|
|
915
|
+
if (params !== void 0) opts.params = params;
|
|
916
|
+
const merged = mergeNext(next);
|
|
917
|
+
if (merged !== void 0) opts.next = merged;
|
|
918
|
+
return queryListings(opts);
|
|
919
|
+
},
|
|
413
920
|
async getSimilarListings({ listingId, limit, siteId, next }) {
|
|
414
921
|
const opts = withDefaults({
|
|
415
922
|
siteId: resolveSiteId(siteId),
|
|
@@ -463,6 +970,8 @@ function createGaragemClient(options = {}) {
|
|
|
463
970
|
// Annotate the CommonJS export names for ESM import in node:
|
|
464
971
|
0 && (module.exports = {
|
|
465
972
|
GaragemSdkError,
|
|
973
|
+
composeSearchPublicHref,
|
|
974
|
+
composeSearchPublicPath,
|
|
466
975
|
createGaragemClient,
|
|
467
976
|
getCmsCollection,
|
|
468
977
|
getCmsCollections,
|
|
@@ -470,12 +979,21 @@ function createGaragemClient(options = {}) {
|
|
|
470
979
|
getCmsEntry,
|
|
471
980
|
getListing,
|
|
472
981
|
getListings,
|
|
982
|
+
getSearchUi,
|
|
473
983
|
getSimilarListings,
|
|
474
984
|
getSite,
|
|
475
985
|
isStudioPreviewHost,
|
|
476
986
|
listingLookupKey,
|
|
477
987
|
listingPublicPath,
|
|
988
|
+
mergeAppliedSearchQueryIntoSearch,
|
|
989
|
+
parseAppliedSearchQuery,
|
|
990
|
+
parseSearchPublicPath,
|
|
991
|
+
pathFiltersToQueryFilters,
|
|
992
|
+
pathLocationToFilterInput,
|
|
993
|
+
queryListings,
|
|
994
|
+
reduceAppliedSearchQuery,
|
|
478
995
|
resolvePublicSiteId,
|
|
479
|
-
searchListings
|
|
996
|
+
searchListings,
|
|
997
|
+
serializeAppliedSearchQuery
|
|
480
998
|
});
|
|
481
999
|
//# sourceMappingURL=index.js.map
|