@garagem-ai/site-sdk 0.3.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 +78 -361
- package/dist/index.d.ts +78 -361
- package/dist/index.js +472 -50
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +437 -46
- 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 +34 -1
- package/src/fetchers.ts +27 -18
- package/src/index.ts +42 -0
- package/src/internal/url.ts +14 -0
- package/src/listing-card-model.ts +90 -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/dist/index.mjs
CHANGED
|
@@ -18,6 +18,15 @@ function normalizeBaseUrl(baseUrl) {
|
|
|
18
18
|
const url = baseUrl ?? DEFAULT_BASE_URL;
|
|
19
19
|
return url.endsWith("/") ? url.slice(0, -1) : url;
|
|
20
20
|
}
|
|
21
|
+
async function coerceSiteId(siteId) {
|
|
22
|
+
const value = await Promise.resolve(siteId);
|
|
23
|
+
if (typeof value !== "string" || !value.trim()) {
|
|
24
|
+
throw new TypeError(
|
|
25
|
+
"Garagem SDK: siteId must be a string. Await resolveSiteId(...) before getListings / getSearchUi / queryListings."
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
21
30
|
function buildListingFiltersQuery(filters) {
|
|
22
31
|
const params = new URLSearchParams();
|
|
23
32
|
if (!filters) return params;
|
|
@@ -57,7 +66,8 @@ var GaragemSdkError = class extends Error {
|
|
|
57
66
|
}
|
|
58
67
|
};
|
|
59
68
|
async function getListings(options) {
|
|
60
|
-
const {
|
|
69
|
+
const { filters, baseUrl, fetch: fetchImpl, next } = options;
|
|
70
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
61
71
|
const base = normalizeBaseUrl(baseUrl);
|
|
62
72
|
const params = buildListingFiltersQuery(filters);
|
|
63
73
|
const qs = params.size > 0 ? `?${params.toString()}` : "";
|
|
@@ -73,13 +83,8 @@ async function getListings(options) {
|
|
|
73
83
|
};
|
|
74
84
|
}
|
|
75
85
|
async function getListing(options) {
|
|
76
|
-
const {
|
|
77
|
-
|
|
78
|
-
listingId: rawListingId,
|
|
79
|
-
baseUrl,
|
|
80
|
-
fetch: fetchImpl,
|
|
81
|
-
next
|
|
82
|
-
} = options;
|
|
86
|
+
const { listingId: rawListingId, baseUrl, fetch: fetchImpl, next } = options;
|
|
87
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
83
88
|
const listingId = listingLookupKey(rawListingId ?? "");
|
|
84
89
|
if (!listingId || listingId === "undefined" || listingId === "null") {
|
|
85
90
|
throw new TypeError("getListing: `listingId` is required");
|
|
@@ -95,7 +100,8 @@ async function getListing(options) {
|
|
|
95
100
|
);
|
|
96
101
|
}
|
|
97
102
|
async function getSite(options) {
|
|
98
|
-
const {
|
|
103
|
+
const { domain, baseUrl, fetch: fetchImpl, next } = options;
|
|
104
|
+
const siteId = options.siteId ? await coerceSiteId(options.siteId) : void 0;
|
|
99
105
|
if (!siteId && !domain) {
|
|
100
106
|
throw new TypeError(
|
|
101
107
|
"getSite: provide exactly one of `siteId` or `domain`."
|
|
@@ -133,7 +139,8 @@ async function getSite(options) {
|
|
|
133
139
|
};
|
|
134
140
|
}
|
|
135
141
|
async function searchListings(options) {
|
|
136
|
-
const {
|
|
142
|
+
const { params, baseUrl, fetch: fetchImpl, next } = options;
|
|
143
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
137
144
|
if (!params || typeof params.q !== "string") {
|
|
138
145
|
throw new TypeError(
|
|
139
146
|
"Garagem SDK: searchListings requires `params.q` (Typesense query string)."
|
|
@@ -153,7 +160,8 @@ async function searchListings(options) {
|
|
|
153
160
|
);
|
|
154
161
|
}
|
|
155
162
|
async function getSearchUi(options) {
|
|
156
|
-
const {
|
|
163
|
+
const { baseUrl, fetch: fetchImpl, next } = options;
|
|
164
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
157
165
|
const base = normalizeBaseUrl(baseUrl);
|
|
158
166
|
const url = `${base}/api/sites/${encodeURIComponent(siteId)}/search-ui`;
|
|
159
167
|
return callJson(
|
|
@@ -163,7 +171,8 @@ async function getSearchUi(options) {
|
|
|
163
171
|
);
|
|
164
172
|
}
|
|
165
173
|
async function queryListings(options) {
|
|
166
|
-
const {
|
|
174
|
+
const { params, baseUrl, fetch: fetchImpl, next } = options;
|
|
175
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
167
176
|
const base = normalizeBaseUrl(baseUrl);
|
|
168
177
|
const url = `${base}/api/sites/${encodeURIComponent(siteId)}/search/listings`;
|
|
169
178
|
return callJson(
|
|
@@ -182,13 +191,13 @@ async function queryListings(options) {
|
|
|
182
191
|
}
|
|
183
192
|
async function getSimilarListings(options) {
|
|
184
193
|
const {
|
|
185
|
-
siteId,
|
|
186
194
|
listingId: rawListingId,
|
|
187
195
|
limit,
|
|
188
196
|
baseUrl,
|
|
189
197
|
fetch: fetchImpl,
|
|
190
198
|
next
|
|
191
199
|
} = options;
|
|
200
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
192
201
|
const listingId = listingLookupKey(rawListingId ?? "");
|
|
193
202
|
if (!listingId || listingId === "undefined" || listingId === "null") {
|
|
194
203
|
throw new TypeError("getSimilarListings: `listingId` is required");
|
|
@@ -213,7 +222,8 @@ async function getSimilarListings(options) {
|
|
|
213
222
|
};
|
|
214
223
|
}
|
|
215
224
|
async function getCmsCollections(options) {
|
|
216
|
-
const {
|
|
225
|
+
const { baseUrl, fetch: fetchImpl, next } = options;
|
|
226
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
217
227
|
const base = normalizeBaseUrl(baseUrl);
|
|
218
228
|
const url = `${base}/api/sites/${encodeURIComponent(siteId)}/cms/collections`;
|
|
219
229
|
const data = await callJson(
|
|
@@ -224,7 +234,8 @@ async function getCmsCollections(options) {
|
|
|
224
234
|
return data.collections ?? [];
|
|
225
235
|
}
|
|
226
236
|
async function getCmsCollection(options) {
|
|
227
|
-
const {
|
|
237
|
+
const { slug, baseUrl, fetch: fetchImpl, next } = options;
|
|
238
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
228
239
|
if (!slug) {
|
|
229
240
|
throw new TypeError("getCmsCollection: `slug` is required");
|
|
230
241
|
}
|
|
@@ -244,7 +255,6 @@ async function getCmsCollection(options) {
|
|
|
244
255
|
}
|
|
245
256
|
async function getCmsEntries(options) {
|
|
246
257
|
const {
|
|
247
|
-
siteId,
|
|
248
258
|
collection,
|
|
249
259
|
limit,
|
|
250
260
|
offset,
|
|
@@ -252,6 +262,7 @@ async function getCmsEntries(options) {
|
|
|
252
262
|
fetch: fetchImpl,
|
|
253
263
|
next
|
|
254
264
|
} = options;
|
|
265
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
255
266
|
if (!collection) {
|
|
256
267
|
throw new TypeError("getCmsEntries: `collection` is required");
|
|
257
268
|
}
|
|
@@ -280,7 +291,8 @@ async function getCmsEntries(options) {
|
|
|
280
291
|
};
|
|
281
292
|
}
|
|
282
293
|
async function getCmsEntry(options) {
|
|
283
|
-
const {
|
|
294
|
+
const { collection, slug, baseUrl, fetch: fetchImpl, next } = options;
|
|
295
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
284
296
|
if (!collection) {
|
|
285
297
|
throw new TypeError("getCmsEntry: `collection` is required");
|
|
286
298
|
}
|
|
@@ -302,6 +314,86 @@ async function getCmsEntry(options) {
|
|
|
302
314
|
return data;
|
|
303
315
|
}
|
|
304
316
|
|
|
317
|
+
// src/presentation.ts
|
|
318
|
+
var SEARCH_CSS_VARS = {
|
|
319
|
+
cardRadius: "--garagem-listing-card-radius",
|
|
320
|
+
cardGap: "--garagem-listing-card-gap",
|
|
321
|
+
priceSize: "--garagem-listing-price-size",
|
|
322
|
+
mediaRatio: "--garagem-listing-media-ratio"
|
|
323
|
+
};
|
|
324
|
+
var SEARCH_CSS_RECIPE = `:root {
|
|
325
|
+
${SEARCH_CSS_VARS.cardRadius}: 0.75rem;
|
|
326
|
+
${SEARCH_CSS_VARS.cardGap}: 1.5rem;
|
|
327
|
+
${SEARCH_CSS_VARS.priceSize}: 1.125rem;
|
|
328
|
+
${SEARCH_CSS_VARS.mediaRatio}: 4 / 3;
|
|
329
|
+
}
|
|
330
|
+
`;
|
|
331
|
+
function formatListingPrice(amount, locale = "pt-BR", currency = "BRL") {
|
|
332
|
+
if (amount == null) return "Sob consulta";
|
|
333
|
+
try {
|
|
334
|
+
return new Intl.NumberFormat(locale, {
|
|
335
|
+
style: "currency",
|
|
336
|
+
currency,
|
|
337
|
+
minimumFractionDigits: 0,
|
|
338
|
+
maximumFractionDigits: 0
|
|
339
|
+
}).format(amount);
|
|
340
|
+
} catch {
|
|
341
|
+
return `${currency} ${amount}`;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
function formatGroupedInteger(value, locale = "pt-BR") {
|
|
345
|
+
const digits = String(value ?? "").replace(/\D/g, "");
|
|
346
|
+
if (!digits) return "";
|
|
347
|
+
const amount = Number.parseInt(digits, 10);
|
|
348
|
+
if (!Number.isFinite(amount)) return "";
|
|
349
|
+
return new Intl.NumberFormat(locale, { maximumFractionDigits: 0 }).format(
|
|
350
|
+
amount
|
|
351
|
+
);
|
|
352
|
+
}
|
|
353
|
+
function parseGroupedInteger(value) {
|
|
354
|
+
if (typeof value === "number") {
|
|
355
|
+
return Number.isFinite(value) ? Math.trunc(value) : void 0;
|
|
356
|
+
}
|
|
357
|
+
const digits = String(value ?? "").replace(/\D/g, "");
|
|
358
|
+
if (!digits) return void 0;
|
|
359
|
+
const amount = Number.parseInt(digits, 10);
|
|
360
|
+
return Number.isFinite(amount) ? amount : void 0;
|
|
361
|
+
}
|
|
362
|
+
function formatAreaM2(area) {
|
|
363
|
+
if (area == null || !Number.isFinite(area)) return null;
|
|
364
|
+
return `${area} m\xB2`;
|
|
365
|
+
}
|
|
366
|
+
function listingBusinessLabel(businessType) {
|
|
367
|
+
return businessType === "rental" ? "Aluguel" : "Venda";
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
// src/listing-card-model.ts
|
|
371
|
+
function listingLocationLabel(location) {
|
|
372
|
+
return [location.neighborhood, location.city, location.state].map((part) => part ? String(part).trim() : "").filter(Boolean).join(", ");
|
|
373
|
+
}
|
|
374
|
+
function toListingCardModel(listing) {
|
|
375
|
+
const isPrivate = listing.priceVisibility === "private";
|
|
376
|
+
const area = listing.property?.usableArea ?? listing.property?.totalArea;
|
|
377
|
+
return {
|
|
378
|
+
href: listingPublicPath(listing),
|
|
379
|
+
title: listing.title,
|
|
380
|
+
businessType: listing.businessType,
|
|
381
|
+
businessLabel: listingBusinessLabel(listing.businessType),
|
|
382
|
+
priceVisibility: listing.priceVisibility,
|
|
383
|
+
price: listing.price,
|
|
384
|
+
priceLabel: isPrivate ? "Sob consulta" : formatListingPrice(listing.price),
|
|
385
|
+
pricePeriod: listing.businessType === "rental" && !isPrivate && listing.price != null ? "/m\xEAs" : null,
|
|
386
|
+
locationLabel: listingLocationLabel(listing.location || {}),
|
|
387
|
+
propertyType: listing.property?.type ?? null,
|
|
388
|
+
coverSrc: listing.coverImage?.src ?? null,
|
|
389
|
+
coverAlt: listing.coverImage?.alt ?? listing.title,
|
|
390
|
+
bedrooms: listing.property?.bedrooms ?? null,
|
|
391
|
+
bathrooms: listing.property?.bathrooms ?? null,
|
|
392
|
+
parkingSpaces: listing.property?.parkingSpaces ?? null,
|
|
393
|
+
areaM2: area ?? null
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
|
|
305
397
|
// ../search-url/types.ts
|
|
306
398
|
var SEARCH_BASE_ROUTE = "imoveis";
|
|
307
399
|
var MAX_PAGE = 1e4;
|
|
@@ -675,6 +767,42 @@ function composeSearchPublicHref(pathname, query, existingSearch) {
|
|
|
675
767
|
return qs ? `${pathname}?${qs}` : pathname;
|
|
676
768
|
}
|
|
677
769
|
|
|
770
|
+
// src/applied-query.ts
|
|
771
|
+
function parseAppliedSearchQuery2(search) {
|
|
772
|
+
return parseAppliedSearchQuery(search);
|
|
773
|
+
}
|
|
774
|
+
function serializeAppliedSearchQuery2(query) {
|
|
775
|
+
return serializeAppliedSearchQuery(query);
|
|
776
|
+
}
|
|
777
|
+
function mergeAppliedSearchQueryIntoSearch2(existing, query) {
|
|
778
|
+
return mergeAppliedSearchQueryIntoSearch(existing, query);
|
|
779
|
+
}
|
|
780
|
+
function reduceAppliedSearchQuery2(prev, change) {
|
|
781
|
+
return reduceAppliedSearchQuery(prev, change);
|
|
782
|
+
}
|
|
783
|
+
function composeSearchPublicHref2(pathname, query, existingSearch) {
|
|
784
|
+
return composeSearchPublicHref(pathname, query, existingSearch);
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
// src/loc-params.ts
|
|
788
|
+
function pathLocationToFilterInput(location) {
|
|
789
|
+
if (!location || typeof location !== "object") return null;
|
|
790
|
+
const { state, city, neighborhood, street } = location;
|
|
791
|
+
const levels = [];
|
|
792
|
+
if (state) levels.push(state);
|
|
793
|
+
if (city) levels.push(city);
|
|
794
|
+
if (neighborhood) levels.push(neighborhood);
|
|
795
|
+
if (street) levels.push(street);
|
|
796
|
+
if (levels.length === 0) return null;
|
|
797
|
+
if (levels.length === 1) {
|
|
798
|
+
if (state) return { type: "state", value: state };
|
|
799
|
+
if (city) return { type: "city", value: city };
|
|
800
|
+
if (neighborhood) return { type: "neighborhood", value: neighborhood };
|
|
801
|
+
if (street) return { type: "street", value: street };
|
|
802
|
+
}
|
|
803
|
+
return { type: "path", value: levels.join("/") };
|
|
804
|
+
}
|
|
805
|
+
|
|
678
806
|
// src/path.ts
|
|
679
807
|
function composeSearchPublicPath2(filters, dictionary) {
|
|
680
808
|
return dictionary ? composeSearchPublicPath(filters, dictionary) : composeSearchPublicPath(filters);
|
|
@@ -717,40 +845,272 @@ function pathFiltersToQueryFilters(pathFilters) {
|
|
|
717
845
|
return result;
|
|
718
846
|
}
|
|
719
847
|
|
|
720
|
-
// src/
|
|
721
|
-
|
|
722
|
-
|
|
848
|
+
// src/search-engine.ts
|
|
849
|
+
var PATH_FILTER_IDS = {
|
|
850
|
+
listing_type: "listingType",
|
|
851
|
+
property_type: "propertyType",
|
|
852
|
+
property_bedrooms: "bedrooms",
|
|
853
|
+
property_bathrooms: "bathrooms",
|
|
854
|
+
property_suites: "suites",
|
|
855
|
+
property_parking_spots: "parkingSpots",
|
|
856
|
+
price: "price",
|
|
857
|
+
property_area_total: "area",
|
|
858
|
+
propertyFeatures: "propertyFeatures",
|
|
859
|
+
buildingAmenities: "buildingAmenities"
|
|
860
|
+
};
|
|
861
|
+
var FORBIDDEN_SEARCH_QUERY_KEYS = [
|
|
862
|
+
"tipo",
|
|
863
|
+
"quartos",
|
|
864
|
+
"tipo-imovel",
|
|
865
|
+
"banheiros",
|
|
866
|
+
"vagas"
|
|
867
|
+
];
|
|
868
|
+
var SEARCH_SORT_RELEVANCE = {
|
|
869
|
+
id: "",
|
|
870
|
+
label: "Mais relevantes"
|
|
871
|
+
};
|
|
872
|
+
function searchSortOptions(sorts) {
|
|
873
|
+
const fromApi = (sorts || []).filter((sort) => sort.id);
|
|
874
|
+
return [
|
|
875
|
+
{ id: SEARCH_SORT_RELEVANCE.id, label: SEARCH_SORT_RELEVANCE.label },
|
|
876
|
+
...fromApi
|
|
877
|
+
];
|
|
723
878
|
}
|
|
724
|
-
|
|
725
|
-
|
|
879
|
+
var TOOLBAR_PRIMARY_FILTER_IDS = [
|
|
880
|
+
"price",
|
|
881
|
+
"property_bedrooms"
|
|
882
|
+
];
|
|
883
|
+
var HIDDEN_FILTER_IDS = /* @__PURE__ */ new Set(["property_suites"]);
|
|
884
|
+
function toFiniteNumber(value) {
|
|
885
|
+
if (value === "" || value == null) return void 0;
|
|
886
|
+
const n = Number(value);
|
|
887
|
+
return Number.isFinite(n) ? n : void 0;
|
|
726
888
|
}
|
|
727
|
-
function
|
|
728
|
-
return
|
|
889
|
+
function pathnameOnly(pathname) {
|
|
890
|
+
return String(pathname || "").split(/[?#]/)[0] || "/";
|
|
729
891
|
}
|
|
730
|
-
function
|
|
731
|
-
|
|
892
|
+
function isListingDetailPath(pathname) {
|
|
893
|
+
const parts = pathnameOnly(pathname).split("/").filter(Boolean);
|
|
894
|
+
const last = parts[parts.length - 1] || "";
|
|
895
|
+
return last.toLowerCase().startsWith("id-");
|
|
732
896
|
}
|
|
733
|
-
function
|
|
734
|
-
|
|
897
|
+
function readPublicSearch(pathname, search, dictionary) {
|
|
898
|
+
const pathFilters = parseSearchPublicPath2(pathnameOnly(pathname), dictionary) || {};
|
|
899
|
+
const applied = parseAppliedSearchQuery2(search || "");
|
|
900
|
+
return { pathFilters, applied };
|
|
735
901
|
}
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
902
|
+
function lookupDisplay(table, slug) {
|
|
903
|
+
if (!slug || !table) return slug;
|
|
904
|
+
return table[slug] || table[String(slug).toLowerCase()] || slug;
|
|
905
|
+
}
|
|
906
|
+
function displayPathLocation(location, values) {
|
|
907
|
+
if (!location) return null;
|
|
908
|
+
const table = values || {};
|
|
909
|
+
return {
|
|
910
|
+
state: lookupDisplay(table.states, location.state),
|
|
911
|
+
city: lookupDisplay(table.cities, location.city),
|
|
912
|
+
neighborhood: lookupDisplay(table.neighborhoods, location.neighborhood),
|
|
913
|
+
street: lookupDisplay(table.streets, location.street)
|
|
914
|
+
};
|
|
915
|
+
}
|
|
916
|
+
function buildQueryListingsParams(pathFilters, applied, schema, locationValues) {
|
|
917
|
+
const filters = pathFiltersToQueryFilters(pathFilters || {});
|
|
918
|
+
const locations = [];
|
|
919
|
+
const displayed = displayPathLocation(pathFilters?.location, locationValues);
|
|
920
|
+
const pathLoc = displayed ? pathLocationToFilterInput(displayed) : null;
|
|
921
|
+
if (pathLoc) locations.push(pathLoc);
|
|
922
|
+
for (const value of applied?.loc || []) {
|
|
923
|
+
locations.push({ type: "loc", value });
|
|
752
924
|
}
|
|
753
|
-
|
|
925
|
+
const params = {
|
|
926
|
+
page: applied?.page || 1,
|
|
927
|
+
limit: schema?.defaultLimit || 12,
|
|
928
|
+
filters
|
|
929
|
+
};
|
|
930
|
+
if (applied?.sort) params.sort = applied.sort;
|
|
931
|
+
const hasLocation = locations.length > 0;
|
|
932
|
+
if (applied?.query && !hasLocation) params.q = applied.query;
|
|
933
|
+
if (hasLocation) params.location = locations;
|
|
934
|
+
return params;
|
|
935
|
+
}
|
|
936
|
+
function applyPathFilter(pathFilters, filterId, value) {
|
|
937
|
+
const next = { ...pathFilters || {} };
|
|
938
|
+
const key = PATH_FILTER_IDS[filterId];
|
|
939
|
+
if (!key) return next;
|
|
940
|
+
if (value === "" || value == null) {
|
|
941
|
+
delete next[key];
|
|
942
|
+
return next;
|
|
943
|
+
}
|
|
944
|
+
if (key === "price" || key === "area") {
|
|
945
|
+
const range = value || {};
|
|
946
|
+
const parse = key === "price" ? parseGroupedInteger : toFiniteNumber;
|
|
947
|
+
const min = parse(range.min);
|
|
948
|
+
const max = parse(range.max);
|
|
949
|
+
if (min == null && max == null) {
|
|
950
|
+
delete next[key];
|
|
951
|
+
return next;
|
|
952
|
+
}
|
|
953
|
+
next[key] = {
|
|
954
|
+
...min != null ? { min } : {},
|
|
955
|
+
...max != null ? { max } : {}
|
|
956
|
+
};
|
|
957
|
+
return next;
|
|
958
|
+
}
|
|
959
|
+
if (key === "propertyFeatures" || key === "buildingAmenities") {
|
|
960
|
+
const current = Array.isArray(next[key]) ? [...next[key]] : [];
|
|
961
|
+
const id = String(value);
|
|
962
|
+
const i = current.indexOf(id);
|
|
963
|
+
if (i >= 0) current.splice(i, 1);
|
|
964
|
+
else current.push(id);
|
|
965
|
+
if (current.length) next[key] = current;
|
|
966
|
+
else delete next[key];
|
|
967
|
+
return next;
|
|
968
|
+
}
|
|
969
|
+
if (key === "propertyType") {
|
|
970
|
+
const id = String(value);
|
|
971
|
+
const current = Array.isArray(next.propertyType) ? [...next.propertyType] : next.propertyType ? [String(next.propertyType)] : [];
|
|
972
|
+
const i = current.indexOf(id);
|
|
973
|
+
if (i >= 0) current.splice(i, 1);
|
|
974
|
+
else current.push(id);
|
|
975
|
+
if (current.length === 0) delete next.propertyType;
|
|
976
|
+
else if (current.length === 1) next.propertyType = current[0];
|
|
977
|
+
else next.propertyType = current;
|
|
978
|
+
return next;
|
|
979
|
+
}
|
|
980
|
+
if (key === "listingType") {
|
|
981
|
+
const id = String(value);
|
|
982
|
+
if (next.listingType === id) delete next.listingType;
|
|
983
|
+
else next.listingType = id;
|
|
984
|
+
return next;
|
|
985
|
+
}
|
|
986
|
+
if (key === "bedrooms" || key === "bathrooms" || key === "suites" || key === "parkingSpots") {
|
|
987
|
+
const n = Number(value);
|
|
988
|
+
if (!Number.isFinite(n)) {
|
|
989
|
+
delete next[key];
|
|
990
|
+
return next;
|
|
991
|
+
}
|
|
992
|
+
if (next[key] === n) delete next[key];
|
|
993
|
+
else next[key] = n;
|
|
994
|
+
return next;
|
|
995
|
+
}
|
|
996
|
+
return next;
|
|
997
|
+
}
|
|
998
|
+
function pathFilterValue(pathFilters, filterId) {
|
|
999
|
+
const key = PATH_FILTER_IDS[filterId];
|
|
1000
|
+
const value = pathFilters && key ? pathFilters[key] : void 0;
|
|
1001
|
+
if (value == null) return "";
|
|
1002
|
+
if (Array.isArray(value)) return value[0] != null ? String(value[0]) : "";
|
|
1003
|
+
if (typeof value === "object") return "";
|
|
1004
|
+
return String(value);
|
|
1005
|
+
}
|
|
1006
|
+
function pathFilterHasOption(pathFilters, filterId, optionId) {
|
|
1007
|
+
const key = PATH_FILTER_IDS[filterId];
|
|
1008
|
+
const value = pathFilters && key ? pathFilters[key] : void 0;
|
|
1009
|
+
if (value == null) return false;
|
|
1010
|
+
if (Array.isArray(value)) return value.map(String).includes(optionId);
|
|
1011
|
+
if (typeof value === "object") return false;
|
|
1012
|
+
return String(value) === optionId;
|
|
1013
|
+
}
|
|
1014
|
+
function publicSearchHref(pathFilters, applied, dictionary, existingSearch) {
|
|
1015
|
+
const pathname = composeSearchPublicPath2(pathFilters || {}, dictionary);
|
|
1016
|
+
return composeSearchPublicHref2(pathname, applied || {}, existingSearch);
|
|
1017
|
+
}
|
|
1018
|
+
function hrefForPathFilters(pathname, search, dictionary, nextPathFilters) {
|
|
1019
|
+
const { applied } = readPublicSearch(pathname, search, dictionary);
|
|
1020
|
+
const nextApplied = reduceAppliedSearchQuery2(applied, {
|
|
1021
|
+
type: "applyFilters"
|
|
1022
|
+
});
|
|
1023
|
+
return publicSearchHref(nextPathFilters, nextApplied, dictionary, search);
|
|
1024
|
+
}
|
|
1025
|
+
function hrefForAppliedChange(pathname, search, dictionary, change) {
|
|
1026
|
+
const { pathFilters, applied } = readPublicSearch(
|
|
1027
|
+
pathname,
|
|
1028
|
+
search,
|
|
1029
|
+
dictionary
|
|
1030
|
+
);
|
|
1031
|
+
let nextPath = pathFilters;
|
|
1032
|
+
if (change && change.type === "query") {
|
|
1033
|
+
nextPath = { ...pathFilters };
|
|
1034
|
+
delete nextPath.location;
|
|
1035
|
+
}
|
|
1036
|
+
const nextApplied = reduceAppliedSearchQuery2(applied, change);
|
|
1037
|
+
return publicSearchHref(nextPath, nextApplied, dictionary, search);
|
|
1038
|
+
}
|
|
1039
|
+
function currentSearchHref(pathname, search) {
|
|
1040
|
+
const path = pathnameOnly(pathname);
|
|
1041
|
+
const qs = search.replace(/^\?/, "");
|
|
1042
|
+
return qs ? `${path}?${qs}` : path;
|
|
1043
|
+
}
|
|
1044
|
+
function canonicalizeSearchHref(pathname, search, dictionary) {
|
|
1045
|
+
const { pathFilters, applied } = readPublicSearch(
|
|
1046
|
+
pathname,
|
|
1047
|
+
search,
|
|
1048
|
+
dictionary
|
|
1049
|
+
);
|
|
1050
|
+
const href = publicSearchHref(pathFilters, applied, dictionary, search);
|
|
1051
|
+
if (href === currentSearchHref(pathname, search)) return null;
|
|
1052
|
+
return href;
|
|
1053
|
+
}
|
|
1054
|
+
function searchHrefUsesLegacyFilterQuery(href) {
|
|
1055
|
+
const query = href.split("?")[1] || "";
|
|
1056
|
+
const params = new URLSearchParams(query);
|
|
1057
|
+
return FORBIDDEN_SEARCH_QUERY_KEYS.some((key) => params.has(key));
|
|
1058
|
+
}
|
|
1059
|
+
function clearStagedPathFilters(current, keepFilterIds = []) {
|
|
1060
|
+
const next = current.location ? { location: current.location } : {};
|
|
1061
|
+
for (const id of keepFilterIds) {
|
|
1062
|
+
const key = PATH_FILTER_IDS[id];
|
|
1063
|
+
if (!key || key === "location") continue;
|
|
1064
|
+
const value = current[key];
|
|
1065
|
+
if (value != null) Object.assign(next, { [key]: value });
|
|
1066
|
+
}
|
|
1067
|
+
return next;
|
|
1068
|
+
}
|
|
1069
|
+
function visibleSearchFilters(schema) {
|
|
1070
|
+
if (!schema?.filters) return [];
|
|
1071
|
+
return schema.filters.filter((filter) => {
|
|
1072
|
+
if (HIDDEN_FILTER_IDS.has(filter.id)) return false;
|
|
1073
|
+
if (filter.id === "listing_type" && (filter.options?.length ?? 0) <= 1) {
|
|
1074
|
+
return false;
|
|
1075
|
+
}
|
|
1076
|
+
return true;
|
|
1077
|
+
});
|
|
1078
|
+
}
|
|
1079
|
+
function toolbarFilterIds(schema) {
|
|
1080
|
+
const visible = new Set(visibleSearchFilters(schema).map((f) => f.id));
|
|
1081
|
+
return TOOLBAR_PRIMARY_FILTER_IDS.filter((id) => visible.has(id));
|
|
1082
|
+
}
|
|
1083
|
+
function countOptionLabel(option) {
|
|
1084
|
+
const label = String(option?.label ?? "");
|
|
1085
|
+
if (/^[1-9]\d*$/.test(label)) return `${label}+`;
|
|
1086
|
+
return label;
|
|
1087
|
+
}
|
|
1088
|
+
function countFacetChoices(options) {
|
|
1089
|
+
const list = options || [];
|
|
1090
|
+
const zero = list.find((o) => o.id === "0" || o.label === "Studio");
|
|
1091
|
+
const isStudio = Boolean(
|
|
1092
|
+
zero && /studio/i.test(String(zero.label)) && zero.id === "0"
|
|
1093
|
+
);
|
|
1094
|
+
const max = isStudio ? 3 : 4;
|
|
1095
|
+
const out = [];
|
|
1096
|
+
if (zero) out.push({ id: zero.id, label: countOptionLabel(zero) });
|
|
1097
|
+
for (let n = 1; n <= max; n += 1) {
|
|
1098
|
+
const option = list.find((o) => o.id === String(n));
|
|
1099
|
+
out.push({
|
|
1100
|
+
id: String(n),
|
|
1101
|
+
label: countOptionLabel(option || { label: String(n) })
|
|
1102
|
+
});
|
|
1103
|
+
}
|
|
1104
|
+
return out;
|
|
1105
|
+
}
|
|
1106
|
+
function paginationPages(currentPage, totalPages, padding) {
|
|
1107
|
+
if (totalPages < 1) return [];
|
|
1108
|
+
const current = Math.min(Math.max(1, currentPage), totalPages);
|
|
1109
|
+
const start = Math.max(1, current - padding);
|
|
1110
|
+
const end = Math.min(totalPages, current + padding);
|
|
1111
|
+
const pages = [];
|
|
1112
|
+
for (let i = start; i <= end; i += 1) pages.push(i);
|
|
1113
|
+
return pages;
|
|
754
1114
|
}
|
|
755
1115
|
|
|
756
1116
|
// src/resolve-site-id.ts
|
|
@@ -917,10 +1277,25 @@ function createGaragemClient(options = {}) {
|
|
|
917
1277
|
};
|
|
918
1278
|
}
|
|
919
1279
|
export {
|
|
1280
|
+
FORBIDDEN_SEARCH_QUERY_KEYS,
|
|
920
1281
|
GaragemSdkError,
|
|
1282
|
+
SEARCH_CSS_RECIPE,
|
|
1283
|
+
SEARCH_CSS_VARS,
|
|
1284
|
+
SEARCH_SORT_RELEVANCE,
|
|
1285
|
+
TOOLBAR_PRIMARY_FILTER_IDS,
|
|
1286
|
+
applyPathFilter,
|
|
1287
|
+
buildQueryListingsParams,
|
|
1288
|
+
canonicalizeSearchHref,
|
|
1289
|
+
clearStagedPathFilters,
|
|
921
1290
|
composeSearchPublicHref2 as composeSearchPublicHref,
|
|
922
1291
|
composeSearchPublicPath2 as composeSearchPublicPath,
|
|
1292
|
+
countFacetChoices,
|
|
1293
|
+
countOptionLabel,
|
|
923
1294
|
createGaragemClient,
|
|
1295
|
+
displayPathLocation,
|
|
1296
|
+
formatAreaM2,
|
|
1297
|
+
formatGroupedInteger,
|
|
1298
|
+
formatListingPrice,
|
|
924
1299
|
getCmsCollection,
|
|
925
1300
|
getCmsCollections,
|
|
926
1301
|
getCmsEntries,
|
|
@@ -930,18 +1305,34 @@ export {
|
|
|
930
1305
|
getSearchUi,
|
|
931
1306
|
getSimilarListings,
|
|
932
1307
|
getSite,
|
|
1308
|
+
hrefForAppliedChange,
|
|
1309
|
+
hrefForPathFilters,
|
|
1310
|
+
isListingDetailPath,
|
|
933
1311
|
isStudioPreviewHost,
|
|
1312
|
+
listingBusinessLabel,
|
|
1313
|
+
listingLocationLabel,
|
|
934
1314
|
listingLookupKey,
|
|
935
1315
|
listingPublicPath,
|
|
936
1316
|
mergeAppliedSearchQueryIntoSearch2 as mergeAppliedSearchQueryIntoSearch,
|
|
1317
|
+
paginationPages,
|
|
937
1318
|
parseAppliedSearchQuery2 as parseAppliedSearchQuery,
|
|
1319
|
+
parseGroupedInteger,
|
|
938
1320
|
parseSearchPublicPath2 as parseSearchPublicPath,
|
|
1321
|
+
pathFilterHasOption,
|
|
1322
|
+
pathFilterValue,
|
|
939
1323
|
pathFiltersToQueryFilters,
|
|
940
1324
|
pathLocationToFilterInput,
|
|
1325
|
+
publicSearchHref,
|
|
941
1326
|
queryListings,
|
|
1327
|
+
readPublicSearch,
|
|
942
1328
|
reduceAppliedSearchQuery2 as reduceAppliedSearchQuery,
|
|
943
1329
|
resolvePublicSiteId,
|
|
1330
|
+
searchHrefUsesLegacyFilterQuery,
|
|
944
1331
|
searchListings,
|
|
945
|
-
|
|
1332
|
+
searchSortOptions,
|
|
1333
|
+
serializeAppliedSearchQuery2 as serializeAppliedSearchQuery,
|
|
1334
|
+
toListingCardModel,
|
|
1335
|
+
toolbarFilterIds,
|
|
1336
|
+
visibleSearchFilters
|
|
946
1337
|
};
|
|
947
1338
|
//# sourceMappingURL=index.mjs.map
|