@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/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
+ }
package/src/types.ts CHANGED
@@ -139,6 +139,110 @@ export interface ListingsResult {
139
139
  offset?: number;
140
140
  }
141
141
 
142
+ export type SearchUiOption = {
143
+ id: string;
144
+ slug: string;
145
+ label: string;
146
+ };
147
+
148
+ export type SearchUiFilter = {
149
+ id: string;
150
+ label: string;
151
+ type: "enum" | "count" | "range";
152
+ options?: SearchUiOption[];
153
+ };
154
+
155
+ export type SearchUiDictionary = {
156
+ listingTypes: SearchUiOption[];
157
+ propertyTypes: SearchUiOption[];
158
+ propertyFeatures: SearchUiOption[];
159
+ buildingAmenities: SearchUiOption[];
160
+ };
161
+
162
+ /** Geo leftovers on a default-V2 search path (`/imoveis/...`). */
163
+ export type SearchPathLocation = {
164
+ state?: string;
165
+ city?: string;
166
+ neighborhood?: string;
167
+ street?: string;
168
+ };
169
+
170
+ /** Filters encoded in the public search pathname (not `?loc=`). */
171
+ export type SearchPathFilters = {
172
+ listingType?: ListingBusinessType | string;
173
+ propertyType?: string | string[];
174
+ location?: SearchPathLocation;
175
+ bedrooms?: number | number[];
176
+ bathrooms?: number | number[];
177
+ suites?: number | number[];
178
+ parkingSpots?: number | number[];
179
+ price?: { min?: number; max?: number };
180
+ area?: { min?: number; max?: number };
181
+ propertyFeatures?: string[];
182
+ buildingAmenities?: string[];
183
+ };
184
+
185
+ /** Query-string state on a search URL (`page`, `ordenar`, `q`, `loc`). */
186
+ export type AppliedSearchQuery = {
187
+ page?: number;
188
+ sort?: string | null;
189
+ query?: string;
190
+ loc?: string[];
191
+ };
192
+
193
+ export type AppliedSearchChange =
194
+ | { type: "sort"; sort: string | null }
195
+ | { type: "page"; page: number }
196
+ | { type: "query"; query: string }
197
+ | { type: "loc"; loc: string[] }
198
+ | { type: "applyFilters" };
199
+
200
+ /** Tenant search schema from `GET /search-ui`. */
201
+ export interface SearchUi {
202
+ defaultLimit: number;
203
+ maxLimit: number;
204
+ sorts: Array<{ id: string; label: string }>;
205
+ filters: SearchUiFilter[];
206
+ dictionary: SearchUiDictionary;
207
+ locationsPath: string;
208
+ }
209
+
210
+ export type QueryListingsFilters = {
211
+ listing_type?: string | string[];
212
+ property_type?: string | string[];
213
+ property_bedrooms?: string | string[] | number | number[];
214
+ property_bathrooms?: string | string[] | number | number[];
215
+ property_suites?: string | string[] | number | number[];
216
+ property_parking_spots?: string | string[] | number | number[];
217
+ propertyFeatures?: string[];
218
+ buildingAmenities?: string[];
219
+ price?: { min?: number; max?: number };
220
+ property_area_total?: { min?: number; max?: number };
221
+ };
222
+
223
+ export type QueryListingsLocation = {
224
+ type: string;
225
+ value: string;
226
+ };
227
+
228
+ /** Friendly search body — Studio must not send Typesense `filter_by`. */
229
+ export interface QueryListingsParams {
230
+ page?: number;
231
+ limit?: number;
232
+ sort?: string;
233
+ q?: string;
234
+ filters?: QueryListingsFilters;
235
+ location?: QueryListingsLocation | QueryListingsLocation[];
236
+ }
237
+
238
+ export interface QueryListingsResult {
239
+ listings: Listing[];
240
+ page: number;
241
+ limit: number;
242
+ total: number;
243
+ totalPages: number;
244
+ }
245
+
142
246
  /**
143
247
  * Raw Typesense search parameters accepted by `searchListings`. Mirrors
144
248
  * the same body the underlying `/api/sites/{siteId}/search` endpoint
@@ -146,10 +250,9 @@ export interface ListingsResult {
146
250
  * `per_page`, `page`, facets, etc.) — see the Typesense docs at
147
251
  * https://typesense.org/docs/latest/api/search.html for the full list.
148
252
  *
149
- * This is the SDK's escape hatch when the friendly `getListings` API
150
- * isn't expressive enough (faceted search, multi-field sort, custom
151
- * grouping). It's an open dictionary on purpose; the only required
152
- * field is `q`.
253
+ * This is the SDK's escape hatch when `queryListings` isn't expressive
254
+ * enough (faceted search, multi-field sort, custom grouping). It's an
255
+ * open dictionary on purpose; the only required field is `q`.
153
256
  */
154
257
  export interface SearchListingsParams {
155
258
  q: string;