@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/src/fetchers.ts CHANGED
@@ -6,14 +6,21 @@ import type {
6
6
  ListingDetail,
7
7
  ListingFilters,
8
8
  ListingsResult,
9
+ QueryListingsParams,
10
+ QueryListingsResult,
9
11
  RequestNextOptions,
10
12
  SearchListingsParams,
11
13
  SearchListingsResult,
14
+ SearchUi,
12
15
  SimilarListingsResult,
13
16
  Site,
14
17
  } from "./types";
15
18
  import { listingLookupKey } from "./listing-path";
16
- import { buildListingFiltersQuery, normalizeBaseUrl } from "./internal/url";
19
+ import {
20
+ buildListingFiltersQuery,
21
+ coerceSiteId,
22
+ normalizeBaseUrl,
23
+ } from "./internal/url";
17
24
 
18
25
  /** Custom fetch implementation. Defaults to the global `fetch`. */
19
26
  export type FetchLike = typeof fetch;
@@ -52,6 +59,15 @@ export interface SearchListingsOptions extends BaseOptions {
52
59
  params: SearchListingsParams;
53
60
  }
54
61
 
62
+ export interface GetSearchUiOptions extends BaseOptions {
63
+ siteId: string;
64
+ }
65
+
66
+ export interface QueryListingsOptions extends BaseOptions {
67
+ siteId: string;
68
+ params?: QueryListingsParams;
69
+ }
70
+
55
71
  export interface GetSimilarListingsOptions extends BaseOptions {
56
72
  siteId: string;
57
73
  listingId: string;
@@ -132,7 +148,8 @@ export class GaragemSdkError extends Error {
132
148
  export async function getListings(
133
149
  options: GetListingsOptions
134
150
  ): Promise<ListingsResult> {
135
- const { siteId, filters, baseUrl, fetch: fetchImpl, next } = options;
151
+ const { filters, baseUrl, fetch: fetchImpl, next } = options;
152
+ const siteId = await coerceSiteId(options.siteId);
136
153
  const base = normalizeBaseUrl(baseUrl);
137
154
  const params = buildListingFiltersQuery(filters);
138
155
  const qs = params.size > 0 ? `?${params.toString()}` : "";
@@ -156,13 +173,8 @@ export async function getListings(
156
173
  export async function getListing(
157
174
  options: GetListingOptions
158
175
  ): Promise<ListingDetail> {
159
- const {
160
- siteId,
161
- listingId: rawListingId,
162
- baseUrl,
163
- fetch: fetchImpl,
164
- next,
165
- } = options;
176
+ const { listingId: rawListingId, baseUrl, fetch: fetchImpl, next } = options;
177
+ const siteId = await coerceSiteId(options.siteId);
166
178
  const listingId = listingLookupKey(rawListingId ?? "");
167
179
  if (!listingId || listingId === "undefined" || listingId === "null") {
168
180
  throw new TypeError("getListing: `listingId` is required");
@@ -188,7 +200,10 @@ export async function getListing(
188
200
  * if (!site) return notFound();
189
201
  */
190
202
  export async function getSite(options: GetSiteOptions): Promise<Site | null> {
191
- const { siteId, domain, baseUrl, fetch: fetchImpl, next } = options;
203
+ const { domain, baseUrl, fetch: fetchImpl, next } = options;
204
+ const siteId = options.siteId
205
+ ? await coerceSiteId(options.siteId)
206
+ : undefined;
192
207
  if (!siteId && !domain) {
193
208
  throw new TypeError(
194
209
  "getSite: provide exactly one of `siteId` or `domain`."
@@ -238,8 +253,8 @@ export async function getSite(options: GetSiteOptions): Promise<Site | null> {
238
253
  *
239
254
  * Calls `POST /api/sites/{siteId}/search` directly and returns the raw
240
255
  * Typesense response (`{ found, page, hits: [{ document, ... }], ... }`).
241
- * Use when the friendly `getListings({ filters })` API isn't expressive
242
- * enough — faceted search, multi-field sort, custom grouping, etc.
256
+ * Use when `queryListings` isn't expressive enough — faceted search,
257
+ * multi-field sort, custom grouping, etc.
243
258
  *
244
259
  * @example
245
260
  * const result = await searchListings({
@@ -261,7 +276,8 @@ export async function getSite(options: GetSiteOptions): Promise<Site | null> {
261
276
  export async function searchListings<TDocument = Record<string, unknown>>(
262
277
  options: SearchListingsOptions
263
278
  ): Promise<SearchListingsResult<TDocument>> {
264
- const { siteId, params, baseUrl, fetch: fetchImpl, next } = options;
279
+ const { params, baseUrl, fetch: fetchImpl, next } = options;
280
+ const siteId = await coerceSiteId(options.siteId);
265
281
  if (!params || typeof params.q !== "string") {
266
282
  throw new TypeError(
267
283
  "Garagem SDK: searchListings requires `params.q` (Typesense query string)."
@@ -281,6 +297,50 @@ export async function searchListings<TDocument = Record<string, unknown>>(
281
297
  );
282
298
  }
283
299
 
300
+ /**
301
+ * Tenant search schema: filters, slugs, sort tokens, defaultLimit 12.
302
+ * Use this to render the search UI — do not hardcode property types.
303
+ */
304
+ export async function getSearchUi(
305
+ options: GetSearchUiOptions
306
+ ): Promise<SearchUi> {
307
+ const { baseUrl, fetch: fetchImpl, next } = options;
308
+ const siteId = await coerceSiteId(options.siteId);
309
+ const base = normalizeBaseUrl(baseUrl);
310
+ const url = `${base}/api/sites/${encodeURIComponent(siteId)}/search-ui`;
311
+ return callJson<SearchUi>(
312
+ url,
313
+ { method: "GET", headers: { Accept: "application/json" }, next },
314
+ fetchImpl ?? fetch
315
+ );
316
+ }
317
+
318
+ /**
319
+ * Friendly catalog search (editor combinators). Prefer this over
320
+ * `searchListings` — that helper is a raw Typesense escape hatch.
321
+ */
322
+ export async function queryListings(
323
+ options: QueryListingsOptions
324
+ ): Promise<QueryListingsResult> {
325
+ const { params, baseUrl, fetch: fetchImpl, next } = options;
326
+ const siteId = await coerceSiteId(options.siteId);
327
+ const base = normalizeBaseUrl(baseUrl);
328
+ const url = `${base}/api/sites/${encodeURIComponent(siteId)}/search/listings`;
329
+ return callJson<QueryListingsResult>(
330
+ url,
331
+ {
332
+ method: "POST",
333
+ headers: {
334
+ Accept: "application/json",
335
+ "Content-Type": "application/json",
336
+ },
337
+ body: JSON.stringify(params ?? {}),
338
+ next,
339
+ },
340
+ fetchImpl ?? fetch
341
+ );
342
+ }
343
+
284
344
  /**
285
345
  * Fetch similar listings for a detail page carousel.
286
346
  * Returns an empty list when the reference listing is missing.
@@ -289,13 +349,13 @@ export async function getSimilarListings(
289
349
  options: GetSimilarListingsOptions
290
350
  ): Promise<SimilarListingsResult> {
291
351
  const {
292
- siteId,
293
352
  listingId: rawListingId,
294
353
  limit,
295
354
  baseUrl,
296
355
  fetch: fetchImpl,
297
356
  next,
298
357
  } = options;
358
+ const siteId = await coerceSiteId(options.siteId);
299
359
  const listingId = listingLookupKey(rawListingId ?? "");
300
360
  if (!listingId || listingId === "undefined" || listingId === "null") {
301
361
  throw new TypeError("getSimilarListings: `listingId` is required");
@@ -325,7 +385,8 @@ export async function getSimilarListings(
325
385
  export async function getCmsCollections(
326
386
  options: GetCmsCollectionsOptions
327
387
  ): Promise<CmsCollection[]> {
328
- const { siteId, baseUrl, fetch: fetchImpl, next } = options;
388
+ const { baseUrl, fetch: fetchImpl, next } = options;
389
+ const siteId = await coerceSiteId(options.siteId);
329
390
  const base = normalizeBaseUrl(baseUrl);
330
391
  const url = `${base}/api/sites/${encodeURIComponent(siteId)}/cms/collections`;
331
392
  const data = await callJson<{ collections?: CmsCollection[] }>(
@@ -340,7 +401,8 @@ export async function getCmsCollections(
340
401
  export async function getCmsCollection(
341
402
  options: GetCmsCollectionOptions
342
403
  ): Promise<CmsCollection> {
343
- const { siteId, slug, baseUrl, fetch: fetchImpl, next } = options;
404
+ const { slug, baseUrl, fetch: fetchImpl, next } = options;
405
+ const siteId = await coerceSiteId(options.siteId);
344
406
  if (!slug) {
345
407
  throw new TypeError("getCmsCollection: `slug` is required");
346
408
  }
@@ -369,7 +431,6 @@ export async function getCmsEntries(
369
431
  options: GetCmsEntriesOptions
370
432
  ): Promise<CmsEntriesResult> {
371
433
  const {
372
- siteId,
373
434
  collection,
374
435
  limit,
375
436
  offset,
@@ -377,6 +438,7 @@ export async function getCmsEntries(
377
438
  fetch: fetchImpl,
378
439
  next,
379
440
  } = options;
441
+ const siteId = await coerceSiteId(options.siteId);
380
442
  if (!collection) {
381
443
  throw new TypeError("getCmsEntries: `collection` is required");
382
444
  }
@@ -410,7 +472,8 @@ export async function getCmsEntries(
410
472
  export async function getCmsEntry(
411
473
  options: GetCmsEntryOptions
412
474
  ): Promise<CmsEntry> {
413
- const { siteId, collection, slug, baseUrl, fetch: fetchImpl, next } = options;
475
+ const { collection, slug, baseUrl, fetch: fetchImpl, next } = options;
476
+ const siteId = await coerceSiteId(options.siteId);
414
477
  if (!collection) {
415
478
  throw new TypeError("getCmsEntry: `collection` is required");
416
479
  }
package/src/index.ts CHANGED
@@ -20,6 +20,8 @@
20
20
  */
21
21
 
22
22
  export type {
23
+ AppliedSearchChange,
24
+ AppliedSearchQuery,
23
25
  CmsCollection,
24
26
  CmsEntriesResult,
25
27
  CmsEntry,
@@ -36,9 +38,19 @@ export type {
36
38
  ListingPriceVisibility,
37
39
  ListingPropertySummary,
38
40
  ListingsResult,
41
+ QueryListingsFilters,
42
+ QueryListingsLocation,
43
+ QueryListingsParams,
44
+ QueryListingsResult,
39
45
  RequestNextOptions,
40
46
  SearchListingsParams,
41
47
  SearchListingsResult,
48
+ SearchPathFilters,
49
+ SearchPathLocation,
50
+ SearchUi,
51
+ SearchUiDictionary,
52
+ SearchUiFilter,
53
+ SearchUiOption,
42
54
  SimilarListingsResult,
43
55
  Site,
44
56
  } from "./types";
@@ -50,8 +62,10 @@ export {
50
62
  getCmsEntry,
51
63
  getListing,
52
64
  getListings,
65
+ getSearchUi,
53
66
  getSimilarListings,
54
67
  getSite,
68
+ queryListings,
55
69
  searchListings,
56
70
  GaragemSdkError,
57
71
  type FetchLike,
@@ -61,13 +75,76 @@ export {
61
75
  type GetCmsEntryOptions,
62
76
  type GetListingOptions,
63
77
  type GetListingsOptions,
78
+ type GetSearchUiOptions,
64
79
  type GetSimilarListingsOptions,
65
80
  type GetSiteOptions,
81
+ type QueryListingsOptions,
66
82
  type SearchListingsOptions,
67
83
  } from "./fetchers";
68
84
 
69
85
  export { listingLookupKey, listingPublicPath } from "./listing-path";
70
86
 
87
+ export {
88
+ toListingCardModel,
89
+ listingLocationLabel,
90
+ type ListingCardModel,
91
+ } from "./listing-card-model";
92
+
93
+ export {
94
+ SEARCH_CSS_RECIPE,
95
+ SEARCH_CSS_VARS,
96
+ formatAreaM2,
97
+ formatGroupedInteger,
98
+ formatListingPrice,
99
+ listingBusinessLabel,
100
+ parseGroupedInteger,
101
+ } from "./presentation";
102
+
103
+ export {
104
+ FORBIDDEN_SEARCH_QUERY_KEYS,
105
+ SEARCH_SORT_RELEVANCE,
106
+ TOOLBAR_PRIMARY_FILTER_IDS,
107
+ applyPathFilter,
108
+ buildQueryListingsParams,
109
+ canonicalizeSearchHref,
110
+ clearStagedPathFilters,
111
+ countFacetChoices,
112
+ countOptionLabel,
113
+ displayPathLocation,
114
+ hrefForAppliedChange,
115
+ hrefForPathFilters,
116
+ isListingDetailPath,
117
+ paginationPages,
118
+ pathFilterHasOption,
119
+ pathFilterValue,
120
+ publicSearchHref,
121
+ readPublicSearch,
122
+ searchHrefUsesLegacyFilterQuery,
123
+ searchSortOptions,
124
+ toolbarFilterIds,
125
+ visibleSearchFilters,
126
+ type LocationNameTables,
127
+ } from "./search-engine";
128
+
129
+ export {
130
+ composeSearchPublicPath,
131
+ parseSearchPublicPath,
132
+ pathFiltersToQueryFilters,
133
+ } from "./path";
134
+
135
+ export {
136
+ composeSearchPublicHref,
137
+ mergeAppliedSearchQueryIntoSearch,
138
+ parseAppliedSearchQuery,
139
+ reduceAppliedSearchQuery,
140
+ serializeAppliedSearchQuery,
141
+ } from "./applied-query";
142
+
143
+ export {
144
+ pathLocationToFilterInput,
145
+ type LocationFilterInput,
146
+ } from "./loc-params";
147
+
71
148
  export {
72
149
  resolvePublicSiteId,
73
150
  isStudioPreviewHost,
@@ -8,6 +8,20 @@ export function normalizeBaseUrl(baseUrl: string | undefined): string {
8
8
  return url.endsWith("/") ? url.slice(0, -1) : url;
9
9
  }
10
10
 
11
+ /**
12
+ * v0 often writes `getListings({ siteId: resolveSiteId(host) })` without
13
+ * await, which interpolates as `/api/sites/[object Promise]/listings`.
14
+ */
15
+ export async function coerceSiteId(siteId: unknown): Promise<string> {
16
+ const value = await Promise.resolve(siteId);
17
+ if (typeof value !== "string" || !value.trim()) {
18
+ throw new TypeError(
19
+ "Garagem SDK: siteId must be a string. Await resolveSiteId(...) before getListings / getSearchUi / queryListings."
20
+ );
21
+ }
22
+ return value;
23
+ }
24
+
11
25
  /**
12
26
  * Serialize listing filters into URLSearchParams. Skips undefined/null
13
27
  * values so the URL stays clean. Kept separate from the fetcher so it's
@@ -0,0 +1,90 @@
1
+ import { listingPublicPath } from "./listing-path";
2
+ import { formatListingPrice, listingBusinessLabel } from "./presentation";
3
+ import type {
4
+ Listing,
5
+ ListingBusinessType,
6
+ ListingPriceVisibility,
7
+ } from "./types";
8
+
9
+ /** Fields every listing card must have — no JSX. */
10
+ export type ListingCardModel = {
11
+ href: string;
12
+ title: string;
13
+ businessType: ListingBusinessType;
14
+ businessLabel: string;
15
+ priceVisibility: ListingPriceVisibility;
16
+ price: number | null;
17
+ priceLabel: string;
18
+ pricePeriod: string | null;
19
+ locationLabel: string;
20
+ propertyType: string | null;
21
+ coverSrc: string | null;
22
+ coverAlt: string;
23
+ bedrooms: number | null;
24
+ bathrooms: number | null;
25
+ parkingSpaces: number | null;
26
+ areaM2: number | null;
27
+ };
28
+
29
+ export function listingLocationLabel(location: {
30
+ neighborhood?: string | null;
31
+ city?: string | null;
32
+ state?: string | null;
33
+ }): string {
34
+ return [location.neighborhood, location.city, location.state]
35
+ .map((part) => (part ? String(part).trim() : ""))
36
+ .filter(Boolean)
37
+ .join(", ");
38
+ }
39
+
40
+ export function toListingCardModel(
41
+ listing: Pick<
42
+ Listing,
43
+ | "id"
44
+ | "listingCode"
45
+ | "path"
46
+ | "title"
47
+ | "businessType"
48
+ | "price"
49
+ | "priceVisibility"
50
+ | "coverImage"
51
+ > & {
52
+ property?: {
53
+ type?: string | null;
54
+ bedrooms?: number | null;
55
+ bathrooms?: number | null;
56
+ parkingSpaces?: number | null;
57
+ usableArea?: number | null;
58
+ totalArea?: number | null;
59
+ };
60
+ location?: {
61
+ neighborhood?: string | null;
62
+ city?: string | null;
63
+ state?: string | null;
64
+ };
65
+ }
66
+ ): ListingCardModel {
67
+ const isPrivate = listing.priceVisibility === "private";
68
+ const area = listing.property?.usableArea ?? listing.property?.totalArea;
69
+ return {
70
+ href: listingPublicPath(listing),
71
+ title: listing.title,
72
+ businessType: listing.businessType,
73
+ businessLabel: listingBusinessLabel(listing.businessType),
74
+ priceVisibility: listing.priceVisibility,
75
+ price: listing.price,
76
+ priceLabel: isPrivate ? "Sob consulta" : formatListingPrice(listing.price),
77
+ pricePeriod:
78
+ listing.businessType === "rental" && !isPrivate && listing.price != null
79
+ ? "/mês"
80
+ : null,
81
+ locationLabel: listingLocationLabel(listing.location || {}),
82
+ propertyType: listing.property?.type ?? null,
83
+ coverSrc: listing.coverImage?.src ?? null,
84
+ coverAlt: listing.coverImage?.alt ?? listing.title,
85
+ bedrooms: listing.property?.bedrooms ?? null,
86
+ bathrooms: listing.property?.bathrooms ?? null,
87
+ parkingSpaces: listing.property?.parkingSpaces ?? null,
88
+ areaM2: area ?? null,
89
+ };
90
+ }
@@ -0,0 +1,36 @@
1
+ // Re-exported from @garagem/site-search to avoid publishing the private package
2
+ export type LocationFilterInput = {
3
+ type: string;
4
+ value: string;
5
+ };
6
+
7
+ /**
8
+ * Convert a SearchPathLocation (from parseSearchPublicPath) to the correct
9
+ * LocationFilterInput format for the friendly search API. This ensures that
10
+ * hierarchical location filters are ANDed correctly instead of ORed.
11
+ */
12
+ export function pathLocationToFilterInput(location: {
13
+ state?: string;
14
+ city?: string;
15
+ neighborhood?: string;
16
+ street?: string;
17
+ }): LocationFilterInput | null {
18
+ if (!location || typeof location !== "object") return null;
19
+
20
+ const { state, city, neighborhood, street } = location;
21
+ const levels: string[] = [];
22
+ if (state) levels.push(state);
23
+ if (city) levels.push(city);
24
+ if (neighborhood) levels.push(neighborhood);
25
+ if (street) levels.push(street);
26
+
27
+ if (levels.length === 0) return null;
28
+ if (levels.length === 1) {
29
+ if (state) return { type: "state", value: state };
30
+ if (city) return { type: "city", value: city };
31
+ if (neighborhood) return { type: "neighborhood", value: neighborhood };
32
+ if (street) return { type: "street", value: street };
33
+ }
34
+
35
+ return { type: "path", value: levels.join("/") };
36
+ }
package/src/path.ts ADDED
@@ -0,0 +1,73 @@
1
+ import {
2
+ composeSearchPublicPath as composePath,
3
+ parseSearchPublicPath as parsePath,
4
+ } from "@garagem/search-url";
5
+ import type {
6
+ QueryListingsFilters,
7
+ SearchPathFilters,
8
+ SearchUiDictionary,
9
+ } from "./types";
10
+
11
+ export function composeSearchPublicPath(
12
+ filters: SearchPathFilters,
13
+ dictionary?: SearchUiDictionary
14
+ ): string {
15
+ return dictionary ? composePath(filters, dictionary) : composePath(filters);
16
+ }
17
+
18
+ export function parseSearchPublicPath(
19
+ pathname: string,
20
+ dictionary?: SearchUiDictionary
21
+ ): SearchPathFilters | null {
22
+ return dictionary ? parsePath(pathname, dictionary) : parsePath(pathname);
23
+ }
24
+
25
+ /**
26
+ * Convert `SearchPathFilters` (returned by `parseSearchPublicPath`) to
27
+ * `QueryListingsFilters` (accepted by `queryListings`).
28
+ *
29
+ * This maps path-based filter keys (`bedrooms`, `parkingSpots`, `area`)
30
+ * to the POST API keys (`property_bedrooms`, `property_parking_spots`,
31
+ * `property_area_total`).
32
+ *
33
+ * Location is **not** included — use `pathLocationToFilterInput` separately
34
+ * and pass the result as the `location` field in `QueryListingsParams`.
35
+ */
36
+ export function pathFiltersToQueryFilters(
37
+ pathFilters: SearchPathFilters
38
+ ): QueryListingsFilters {
39
+ const result: QueryListingsFilters = {};
40
+
41
+ if (pathFilters.listingType !== undefined) {
42
+ result.listing_type = pathFilters.listingType;
43
+ }
44
+ if (pathFilters.propertyType !== undefined) {
45
+ result.property_type = pathFilters.propertyType;
46
+ }
47
+ if (pathFilters.bedrooms !== undefined) {
48
+ result.property_bedrooms = pathFilters.bedrooms;
49
+ }
50
+ if (pathFilters.bathrooms !== undefined) {
51
+ result.property_bathrooms = pathFilters.bathrooms;
52
+ }
53
+ if (pathFilters.suites !== undefined) {
54
+ result.property_suites = pathFilters.suites;
55
+ }
56
+ if (pathFilters.parkingSpots !== undefined) {
57
+ result.property_parking_spots = pathFilters.parkingSpots;
58
+ }
59
+ if (pathFilters.price !== undefined) {
60
+ result.price = pathFilters.price;
61
+ }
62
+ if (pathFilters.area !== undefined) {
63
+ result.property_area_total = pathFilters.area;
64
+ }
65
+ if (pathFilters.propertyFeatures !== undefined) {
66
+ result.propertyFeatures = pathFilters.propertyFeatures;
67
+ }
68
+ if (pathFilters.buildingAmenities !== undefined) {
69
+ result.buildingAmenities = pathFilters.buildingAmenities;
70
+ }
71
+
72
+ return result;
73
+ }
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Presentation helpers with no UI framework.
3
+ * React / React Native / Flutter adapters consume these formatters and
4
+ * CSS custom-property names; they must not live inside JSX.
5
+ */
6
+
7
+ export const SEARCH_CSS_VARS = {
8
+ cardRadius: "--garagem-listing-card-radius",
9
+ cardGap: "--garagem-listing-card-gap",
10
+ priceSize: "--garagem-listing-price-size",
11
+ mediaRatio: "--garagem-listing-media-ratio",
12
+ } as const;
13
+
14
+ export const SEARCH_CSS_RECIPE = `:root {
15
+ ${SEARCH_CSS_VARS.cardRadius}: 0.75rem;
16
+ ${SEARCH_CSS_VARS.cardGap}: 1.5rem;
17
+ ${SEARCH_CSS_VARS.priceSize}: 1.125rem;
18
+ ${SEARCH_CSS_VARS.mediaRatio}: 4 / 3;
19
+ }
20
+ `;
21
+
22
+ export function formatListingPrice(
23
+ amount: number | null | undefined,
24
+ locale = "pt-BR",
25
+ currency = "BRL"
26
+ ): string {
27
+ if (amount == null) return "Sob consulta";
28
+ try {
29
+ return new Intl.NumberFormat(locale, {
30
+ style: "currency",
31
+ currency,
32
+ minimumFractionDigits: 0,
33
+ maximumFractionDigits: 0,
34
+ }).format(amount);
35
+ } catch {
36
+ return `${currency} ${amount}`;
37
+ }
38
+ }
39
+
40
+ /** Input mask: `499000` → `"499.000"` (no currency symbol). */
41
+ export function formatGroupedInteger(
42
+ value: string | number | null | undefined,
43
+ locale = "pt-BR"
44
+ ): string {
45
+ const digits = String(value ?? "").replace(/\D/g, "");
46
+ if (!digits) return "";
47
+ const amount = Number.parseInt(digits, 10);
48
+ if (!Number.isFinite(amount)) return "";
49
+ return new Intl.NumberFormat(locale, { maximumFractionDigits: 0 }).format(
50
+ amount
51
+ );
52
+ }
53
+
54
+ /** Inverse of `formatGroupedInteger`: `"499.000"` / `"499000"` → `499000`. */
55
+ export function parseGroupedInteger(value: unknown): number | undefined {
56
+ if (typeof value === "number") {
57
+ return Number.isFinite(value) ? Math.trunc(value) : undefined;
58
+ }
59
+ const digits = String(value ?? "").replace(/\D/g, "");
60
+ if (!digits) return undefined;
61
+ const amount = Number.parseInt(digits, 10);
62
+ return Number.isFinite(amount) ? amount : undefined;
63
+ }
64
+
65
+ export function formatAreaM2(area: number | null | undefined): string | null {
66
+ if (area == null || !Number.isFinite(area)) return null;
67
+ return `${area} m²`;
68
+ }
69
+
70
+ export function listingBusinessLabel(businessType: string | undefined): string {
71
+ return businessType === "rental" ? "Aluguel" : "Venda";
72
+ }
@@ -0,0 +1,3 @@
1
+ export function cn(...parts: Array<string | false | null | undefined>): string {
2
+ return parts.filter(Boolean).join(" ");
3
+ }