@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/dist/index.js CHANGED
@@ -18,12 +18,27 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
 
20
20
  // src/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ FORBIDDEN_SEARCH_QUERY_KEYS: () => FORBIDDEN_SEARCH_QUERY_KEYS,
23
24
  GaragemSdkError: () => GaragemSdkError,
25
+ SEARCH_CSS_RECIPE: () => SEARCH_CSS_RECIPE,
26
+ SEARCH_CSS_VARS: () => SEARCH_CSS_VARS,
27
+ SEARCH_SORT_RELEVANCE: () => SEARCH_SORT_RELEVANCE,
28
+ TOOLBAR_PRIMARY_FILTER_IDS: () => TOOLBAR_PRIMARY_FILTER_IDS,
29
+ applyPathFilter: () => applyPathFilter,
30
+ buildQueryListingsParams: () => buildQueryListingsParams,
31
+ canonicalizeSearchHref: () => canonicalizeSearchHref,
32
+ clearStagedPathFilters: () => clearStagedPathFilters,
24
33
  composeSearchPublicHref: () => composeSearchPublicHref2,
25
34
  composeSearchPublicPath: () => composeSearchPublicPath2,
35
+ countFacetChoices: () => countFacetChoices,
36
+ countOptionLabel: () => countOptionLabel,
26
37
  createGaragemClient: () => createGaragemClient,
38
+ displayPathLocation: () => displayPathLocation,
39
+ formatAreaM2: () => formatAreaM2,
40
+ formatGroupedInteger: () => formatGroupedInteger,
41
+ formatListingPrice: () => formatListingPrice,
27
42
  getCmsCollection: () => getCmsCollection,
28
43
  getCmsCollections: () => getCmsCollections,
29
44
  getCmsEntries: () => getCmsEntries,
@@ -33,21 +48,37 @@ __export(index_exports, {
33
48
  getSearchUi: () => getSearchUi,
34
49
  getSimilarListings: () => getSimilarListings,
35
50
  getSite: () => getSite,
51
+ hrefForAppliedChange: () => hrefForAppliedChange,
52
+ hrefForPathFilters: () => hrefForPathFilters,
53
+ isListingDetailPath: () => isListingDetailPath,
36
54
  isStudioPreviewHost: () => isStudioPreviewHost,
55
+ listingBusinessLabel: () => listingBusinessLabel,
56
+ listingLocationLabel: () => listingLocationLabel,
37
57
  listingLookupKey: () => listingLookupKey,
38
58
  listingPublicPath: () => listingPublicPath,
39
59
  mergeAppliedSearchQueryIntoSearch: () => mergeAppliedSearchQueryIntoSearch2,
60
+ paginationPages: () => paginationPages,
40
61
  parseAppliedSearchQuery: () => parseAppliedSearchQuery2,
62
+ parseGroupedInteger: () => parseGroupedInteger,
41
63
  parseSearchPublicPath: () => parseSearchPublicPath2,
64
+ pathFilterHasOption: () => pathFilterHasOption,
65
+ pathFilterValue: () => pathFilterValue,
42
66
  pathFiltersToQueryFilters: () => pathFiltersToQueryFilters,
43
67
  pathLocationToFilterInput: () => pathLocationToFilterInput,
68
+ publicSearchHref: () => publicSearchHref,
44
69
  queryListings: () => queryListings,
70
+ readPublicSearch: () => readPublicSearch,
45
71
  reduceAppliedSearchQuery: () => reduceAppliedSearchQuery2,
46
72
  resolvePublicSiteId: () => resolvePublicSiteId,
73
+ searchHrefUsesLegacyFilterQuery: () => searchHrefUsesLegacyFilterQuery,
47
74
  searchListings: () => searchListings,
48
- serializeAppliedSearchQuery: () => serializeAppliedSearchQuery2
75
+ searchSortOptions: () => searchSortOptions,
76
+ serializeAppliedSearchQuery: () => serializeAppliedSearchQuery2,
77
+ toListingCardModel: () => toListingCardModel,
78
+ toolbarFilterIds: () => toolbarFilterIds,
79
+ visibleSearchFilters: () => visibleSearchFilters
49
80
  });
50
- module.exports = __toCommonJS(index_exports);
81
+ module.exports = __toCommonJS(src_exports);
51
82
 
52
83
  // src/listing-path.ts
53
84
  function listingLookupKey(raw) {
@@ -69,6 +100,15 @@ function normalizeBaseUrl(baseUrl) {
69
100
  const url = baseUrl ?? DEFAULT_BASE_URL;
70
101
  return url.endsWith("/") ? url.slice(0, -1) : url;
71
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
+ }
72
112
  function buildListingFiltersQuery(filters) {
73
113
  const params = new URLSearchParams();
74
114
  if (!filters) return params;
@@ -108,7 +148,8 @@ var GaragemSdkError = class extends Error {
108
148
  }
109
149
  };
110
150
  async function getListings(options) {
111
- const { siteId, filters, baseUrl, fetch: fetchImpl, next } = options;
151
+ const { filters, baseUrl, fetch: fetchImpl, next } = options;
152
+ const siteId = await coerceSiteId(options.siteId);
112
153
  const base = normalizeBaseUrl(baseUrl);
113
154
  const params = buildListingFiltersQuery(filters);
114
155
  const qs = params.size > 0 ? `?${params.toString()}` : "";
@@ -124,13 +165,8 @@ async function getListings(options) {
124
165
  };
125
166
  }
126
167
  async function getListing(options) {
127
- const {
128
- siteId,
129
- listingId: rawListingId,
130
- baseUrl,
131
- fetch: fetchImpl,
132
- next
133
- } = options;
168
+ const { listingId: rawListingId, baseUrl, fetch: fetchImpl, next } = options;
169
+ const siteId = await coerceSiteId(options.siteId);
134
170
  const listingId = listingLookupKey(rawListingId ?? "");
135
171
  if (!listingId || listingId === "undefined" || listingId === "null") {
136
172
  throw new TypeError("getListing: `listingId` is required");
@@ -146,7 +182,8 @@ async function getListing(options) {
146
182
  );
147
183
  }
148
184
  async function getSite(options) {
149
- const { siteId, domain, baseUrl, fetch: fetchImpl, next } = options;
185
+ const { domain, baseUrl, fetch: fetchImpl, next } = options;
186
+ const siteId = options.siteId ? await coerceSiteId(options.siteId) : void 0;
150
187
  if (!siteId && !domain) {
151
188
  throw new TypeError(
152
189
  "getSite: provide exactly one of `siteId` or `domain`."
@@ -184,7 +221,8 @@ async function getSite(options) {
184
221
  };
185
222
  }
186
223
  async function searchListings(options) {
187
- const { siteId, params, baseUrl, fetch: fetchImpl, next } = options;
224
+ const { params, baseUrl, fetch: fetchImpl, next } = options;
225
+ const siteId = await coerceSiteId(options.siteId);
188
226
  if (!params || typeof params.q !== "string") {
189
227
  throw new TypeError(
190
228
  "Garagem SDK: searchListings requires `params.q` (Typesense query string)."
@@ -204,7 +242,8 @@ async function searchListings(options) {
204
242
  );
205
243
  }
206
244
  async function getSearchUi(options) {
207
- const { siteId, baseUrl, fetch: fetchImpl, next } = options;
245
+ const { baseUrl, fetch: fetchImpl, next } = options;
246
+ const siteId = await coerceSiteId(options.siteId);
208
247
  const base = normalizeBaseUrl(baseUrl);
209
248
  const url = `${base}/api/sites/${encodeURIComponent(siteId)}/search-ui`;
210
249
  return callJson(
@@ -214,7 +253,8 @@ async function getSearchUi(options) {
214
253
  );
215
254
  }
216
255
  async function queryListings(options) {
217
- const { siteId, params, baseUrl, fetch: fetchImpl, next } = options;
256
+ const { params, baseUrl, fetch: fetchImpl, next } = options;
257
+ const siteId = await coerceSiteId(options.siteId);
218
258
  const base = normalizeBaseUrl(baseUrl);
219
259
  const url = `${base}/api/sites/${encodeURIComponent(siteId)}/search/listings`;
220
260
  return callJson(
@@ -233,13 +273,13 @@ async function queryListings(options) {
233
273
  }
234
274
  async function getSimilarListings(options) {
235
275
  const {
236
- siteId,
237
276
  listingId: rawListingId,
238
277
  limit,
239
278
  baseUrl,
240
279
  fetch: fetchImpl,
241
280
  next
242
281
  } = options;
282
+ const siteId = await coerceSiteId(options.siteId);
243
283
  const listingId = listingLookupKey(rawListingId ?? "");
244
284
  if (!listingId || listingId === "undefined" || listingId === "null") {
245
285
  throw new TypeError("getSimilarListings: `listingId` is required");
@@ -264,7 +304,8 @@ async function getSimilarListings(options) {
264
304
  };
265
305
  }
266
306
  async function getCmsCollections(options) {
267
- const { siteId, baseUrl, fetch: fetchImpl, next } = options;
307
+ const { baseUrl, fetch: fetchImpl, next } = options;
308
+ const siteId = await coerceSiteId(options.siteId);
268
309
  const base = normalizeBaseUrl(baseUrl);
269
310
  const url = `${base}/api/sites/${encodeURIComponent(siteId)}/cms/collections`;
270
311
  const data = await callJson(
@@ -275,7 +316,8 @@ async function getCmsCollections(options) {
275
316
  return data.collections ?? [];
276
317
  }
277
318
  async function getCmsCollection(options) {
278
- const { siteId, slug, baseUrl, fetch: fetchImpl, next } = options;
319
+ const { slug, baseUrl, fetch: fetchImpl, next } = options;
320
+ const siteId = await coerceSiteId(options.siteId);
279
321
  if (!slug) {
280
322
  throw new TypeError("getCmsCollection: `slug` is required");
281
323
  }
@@ -295,7 +337,6 @@ async function getCmsCollection(options) {
295
337
  }
296
338
  async function getCmsEntries(options) {
297
339
  const {
298
- siteId,
299
340
  collection,
300
341
  limit,
301
342
  offset,
@@ -303,6 +344,7 @@ async function getCmsEntries(options) {
303
344
  fetch: fetchImpl,
304
345
  next
305
346
  } = options;
347
+ const siteId = await coerceSiteId(options.siteId);
306
348
  if (!collection) {
307
349
  throw new TypeError("getCmsEntries: `collection` is required");
308
350
  }
@@ -331,7 +373,8 @@ async function getCmsEntries(options) {
331
373
  };
332
374
  }
333
375
  async function getCmsEntry(options) {
334
- const { siteId, collection, slug, baseUrl, fetch: fetchImpl, next } = options;
376
+ const { collection, slug, baseUrl, fetch: fetchImpl, next } = options;
377
+ const siteId = await coerceSiteId(options.siteId);
335
378
  if (!collection) {
336
379
  throw new TypeError("getCmsEntry: `collection` is required");
337
380
  }
@@ -353,6 +396,86 @@ async function getCmsEntry(options) {
353
396
  return data;
354
397
  }
355
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
+
356
479
  // ../search-url/types.ts
357
480
  var SEARCH_BASE_ROUTE = "imoveis";
358
481
  var MAX_PAGE = 1e4;
@@ -726,6 +849,42 @@ function composeSearchPublicHref(pathname, query, existingSearch) {
726
849
  return qs ? `${pathname}?${qs}` : pathname;
727
850
  }
728
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
+
729
888
  // src/path.ts
730
889
  function composeSearchPublicPath2(filters, dictionary) {
731
890
  return dictionary ? composeSearchPublicPath(filters, dictionary) : composeSearchPublicPath(filters);
@@ -768,40 +927,272 @@ function pathFiltersToQueryFilters(pathFilters) {
768
927
  return result;
769
928
  }
770
929
 
771
- // src/applied-query.ts
772
- function parseAppliedSearchQuery2(search) {
773
- return parseAppliedSearchQuery(search);
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
+ ];
774
960
  }
775
- function serializeAppliedSearchQuery2(query) {
776
- return serializeAppliedSearchQuery(query);
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;
777
970
  }
778
- function mergeAppliedSearchQueryIntoSearch2(existing, query) {
779
- return mergeAppliedSearchQueryIntoSearch(existing, query);
971
+ function pathnameOnly(pathname) {
972
+ return String(pathname || "").split(/[?#]/)[0] || "/";
780
973
  }
781
- function reduceAppliedSearchQuery2(prev, change) {
782
- return reduceAppliedSearchQuery(prev, change);
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-");
783
978
  }
784
- function composeSearchPublicHref2(pathname, query, existingSearch) {
785
- return composeSearchPublicHref(pathname, query, existingSearch);
979
+ function readPublicSearch(pathname, search, dictionary) {
980
+ const pathFilters = parseSearchPublicPath2(pathnameOnly(pathname), dictionary) || {};
981
+ const applied = parseAppliedSearchQuery2(search || "");
982
+ return { pathFilters, applied };
786
983
  }
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 };
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 });
803
1006
  }
804
- return { type: "path", value: levels.join("/") };
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;
805
1196
  }
806
1197
 
807
1198
  // src/resolve-site-id.ts
@@ -969,10 +1360,25 @@ function createGaragemClient(options = {}) {
969
1360
  }
970
1361
  // Annotate the CommonJS export names for ESM import in node:
971
1362
  0 && (module.exports = {
1363
+ FORBIDDEN_SEARCH_QUERY_KEYS,
972
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,
973
1373
  composeSearchPublicHref,
974
1374
  composeSearchPublicPath,
1375
+ countFacetChoices,
1376
+ countOptionLabel,
975
1377
  createGaragemClient,
1378
+ displayPathLocation,
1379
+ formatAreaM2,
1380
+ formatGroupedInteger,
1381
+ formatListingPrice,
976
1382
  getCmsCollection,
977
1383
  getCmsCollections,
978
1384
  getCmsEntries,
@@ -982,18 +1388,34 @@ function createGaragemClient(options = {}) {
982
1388
  getSearchUi,
983
1389
  getSimilarListings,
984
1390
  getSite,
1391
+ hrefForAppliedChange,
1392
+ hrefForPathFilters,
1393
+ isListingDetailPath,
985
1394
  isStudioPreviewHost,
1395
+ listingBusinessLabel,
1396
+ listingLocationLabel,
986
1397
  listingLookupKey,
987
1398
  listingPublicPath,
988
1399
  mergeAppliedSearchQueryIntoSearch,
1400
+ paginationPages,
989
1401
  parseAppliedSearchQuery,
1402
+ parseGroupedInteger,
990
1403
  parseSearchPublicPath,
1404
+ pathFilterHasOption,
1405
+ pathFilterValue,
991
1406
  pathFiltersToQueryFilters,
992
1407
  pathLocationToFilterInput,
1408
+ publicSearchHref,
993
1409
  queryListings,
1410
+ readPublicSearch,
994
1411
  reduceAppliedSearchQuery,
995
1412
  resolvePublicSiteId,
1413
+ searchHrefUsesLegacyFilterQuery,
996
1414
  searchListings,
997
- serializeAppliedSearchQuery
1415
+ searchSortOptions,
1416
+ serializeAppliedSearchQuery,
1417
+ toListingCardModel,
1418
+ toolbarFilterIds,
1419
+ visibleSearchFilters
998
1420
  });
999
1421
  //# sourceMappingURL=index.js.map