@garagem-ai/site-sdk 0.7.0 → 0.9.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 +329 -31
- package/dist/index.d.mts +305 -44
- package/dist/index.d.ts +305 -44
- package/dist/index.js +1282 -34
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1233 -34
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.mts +29 -2
- package/dist/react.d.ts +29 -2
- package/dist/react.js +639 -26
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +638 -26
- package/dist/react.mjs.map +1 -1
- package/dist/{types-photo-search-OeONNDxl.d.mts → types-photo-search-D88oevZv.d.mts} +400 -1
- package/dist/{types-photo-search-OeONNDxl.d.ts → types-photo-search-D88oevZv.d.ts} +400 -1
- package/package.json +1 -1
- package/src/client.ts +23 -0
- package/src/fetchers-photos.ts +98 -0
- package/src/fetchers.ts +96 -30
- package/src/index.ts +120 -2
- package/src/internal/sdk-http.ts +122 -0
- package/src/leads.ts +34 -3
- package/src/listing-photos.ts +312 -0
- package/src/map-search.ts +487 -0
- package/src/maps.ts +743 -0
- package/src/react/index.ts +2 -0
- package/src/react/types.ts +5 -0
- package/src/react/use-map-search.ts +101 -0
- package/src/react/use-public-search.ts +23 -5
- package/src/resolve-site-id.ts +3 -0
- package/src/studio-contract.ts +120 -0
- package/src/types-maps.ts +275 -0
- package/src/types-photos.ts +46 -0
- package/src/types.ts +23 -0
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Headless photo helpers for the listing detail.
|
|
3
|
+
*
|
|
4
|
+
* `listingPhotoGroups` turns the gallery into "Sala (3) · Quartos (4) ·
|
|
5
|
+
* Cozinha (2)" sections from the per-photo `roomType`; `listingVisualHighlights`
|
|
6
|
+
* surfaces the visual features the analysis named most often. Both are pure
|
|
7
|
+
* and only read `ListingDetail.media`.
|
|
8
|
+
*/
|
|
9
|
+
import type { ListingMedia } from "./types";
|
|
10
|
+
import type { ListingPhotoGroup } from "./types-photos";
|
|
11
|
+
|
|
12
|
+
export const PHOTO_GROUP_OTHER_KEY = "outros";
|
|
13
|
+
export const PHOTO_GROUP_OTHER_LABEL = "Outras fotos";
|
|
14
|
+
|
|
15
|
+
function normalizeRoomLabel(value: string): string {
|
|
16
|
+
return value
|
|
17
|
+
.normalize("NFD")
|
|
18
|
+
.replace(/[̀-ͯ]/g, "")
|
|
19
|
+
.toLowerCase()
|
|
20
|
+
.replace(/[^a-z0-9]+/g, " ")
|
|
21
|
+
.trim();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Synonym groups mirrored from the platform's room matching, each with the
|
|
26
|
+
* pt-BR label the site shows. Members are already normalized.
|
|
27
|
+
*/
|
|
28
|
+
const ROOM_GROUPS: ReadonlyArray<{
|
|
29
|
+
key: string;
|
|
30
|
+
label: string;
|
|
31
|
+
members: readonly string[];
|
|
32
|
+
}> = [
|
|
33
|
+
{
|
|
34
|
+
key: "fachada",
|
|
35
|
+
label: "Fachada",
|
|
36
|
+
members: [
|
|
37
|
+
"fachada",
|
|
38
|
+
"exterior",
|
|
39
|
+
"frente",
|
|
40
|
+
"facade",
|
|
41
|
+
"fachada do predio",
|
|
42
|
+
"predio",
|
|
43
|
+
"building exterior",
|
|
44
|
+
"area externa do predio",
|
|
45
|
+
],
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
key: "sala",
|
|
49
|
+
label: "Sala",
|
|
50
|
+
members: [
|
|
51
|
+
"sala",
|
|
52
|
+
"sala de estar",
|
|
53
|
+
"living",
|
|
54
|
+
"estar",
|
|
55
|
+
"sala de tv",
|
|
56
|
+
"living room",
|
|
57
|
+
"sala de estar e jantar",
|
|
58
|
+
"sala integrada",
|
|
59
|
+
],
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
key: "sala de jantar",
|
|
63
|
+
label: "Sala de jantar",
|
|
64
|
+
members: ["sala de jantar", "jantar", "dining room", "copa jantar"],
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
key: "cozinha",
|
|
68
|
+
label: "Cozinha",
|
|
69
|
+
members: [
|
|
70
|
+
"cozinha",
|
|
71
|
+
"copa",
|
|
72
|
+
"copa cozinha",
|
|
73
|
+
"cozinha americana",
|
|
74
|
+
"kitchen",
|
|
75
|
+
],
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
key: "quarto",
|
|
79
|
+
label: "Quartos",
|
|
80
|
+
members: [
|
|
81
|
+
"quarto",
|
|
82
|
+
"dormitorio",
|
|
83
|
+
"suite",
|
|
84
|
+
"suite master",
|
|
85
|
+
"quarto de casal",
|
|
86
|
+
"quarto de solteiro",
|
|
87
|
+
"quarto infantil",
|
|
88
|
+
"bedroom",
|
|
89
|
+
"master bedroom",
|
|
90
|
+
],
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
key: "banheiro",
|
|
94
|
+
label: "Banheiros",
|
|
95
|
+
members: [
|
|
96
|
+
"banheiro",
|
|
97
|
+
"lavabo",
|
|
98
|
+
"wc",
|
|
99
|
+
"toalete",
|
|
100
|
+
"bathroom",
|
|
101
|
+
"banheiro social",
|
|
102
|
+
"banheiro da suite",
|
|
103
|
+
],
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
key: "varanda",
|
|
107
|
+
label: "Varanda",
|
|
108
|
+
members: ["varanda", "sacada", "terraco", "balcony", "terrace"],
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
key: "area gourmet",
|
|
112
|
+
label: "Área gourmet",
|
|
113
|
+
members: [
|
|
114
|
+
"area gourmet",
|
|
115
|
+
"varanda gourmet",
|
|
116
|
+
"espaco gourmet",
|
|
117
|
+
"churrasqueira",
|
|
118
|
+
"gourmet",
|
|
119
|
+
"terraco gourmet",
|
|
120
|
+
],
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
key: "closet",
|
|
124
|
+
label: "Closet",
|
|
125
|
+
members: ["closet", "closet da suite", "walk in closet"],
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
key: "escritorio",
|
|
129
|
+
label: "Escritório",
|
|
130
|
+
members: ["escritorio", "home office", "office"],
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
key: "area de servico",
|
|
134
|
+
label: "Área de serviço",
|
|
135
|
+
members: ["area de servico", "lavanderia", "laundry", "servico"],
|
|
136
|
+
},
|
|
137
|
+
{ key: "despensa", label: "Despensa", members: ["despensa", "pantry"] },
|
|
138
|
+
{
|
|
139
|
+
key: "corredor",
|
|
140
|
+
label: "Corredor",
|
|
141
|
+
members: ["corredor", "circulacao", "hallway"],
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
key: "hall",
|
|
145
|
+
label: "Hall",
|
|
146
|
+
members: [
|
|
147
|
+
"hall",
|
|
148
|
+
"hall de entrada",
|
|
149
|
+
"entrada",
|
|
150
|
+
"recepcao",
|
|
151
|
+
"lobby",
|
|
152
|
+
"portaria",
|
|
153
|
+
],
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
key: "garagem",
|
|
157
|
+
label: "Garagem",
|
|
158
|
+
members: [
|
|
159
|
+
"garagem",
|
|
160
|
+
"vaga",
|
|
161
|
+
"vagas",
|
|
162
|
+
"estacionamento",
|
|
163
|
+
"garage",
|
|
164
|
+
"vaga de garagem",
|
|
165
|
+
],
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
key: "piscina",
|
|
169
|
+
label: "Piscina",
|
|
170
|
+
members: ["piscina", "pool", "piscina do condominio"],
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
key: "academia",
|
|
174
|
+
label: "Academia",
|
|
175
|
+
members: ["academia", "fitness", "gym", "espaco fitness"],
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
key: "salao de festas",
|
|
179
|
+
label: "Salão de festas",
|
|
180
|
+
members: ["salao de festas", "festas", "salao", "party room"],
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
key: "playground",
|
|
184
|
+
label: "Playground",
|
|
185
|
+
members: ["playground", "brinquedoteca", "espaco kids"],
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
key: "jardim",
|
|
189
|
+
label: "Jardim",
|
|
190
|
+
members: ["jardim", "quintal", "area externa", "garden", "backyard"],
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
key: "vista",
|
|
194
|
+
label: "Vista",
|
|
195
|
+
members: ["vista", "view", "vista da varanda"],
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
key: "planta",
|
|
199
|
+
label: "Planta",
|
|
200
|
+
members: ["planta", "planta baixa", "floorplan", "floor plan"],
|
|
201
|
+
},
|
|
202
|
+
];
|
|
203
|
+
|
|
204
|
+
const GROUP_BY_MEMBER = new Map<string, { key: string; label: string }>();
|
|
205
|
+
for (const group of ROOM_GROUPS) {
|
|
206
|
+
for (const member of group.members) {
|
|
207
|
+
GROUP_BY_MEMBER.set(member, { key: group.key, label: group.label });
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** Labels the analysis uses when it saw nothing to classify. */
|
|
212
|
+
const NON_ROOM_LABELS = new Set(["", "outro", "outros", "other", "unknown"]);
|
|
213
|
+
|
|
214
|
+
function capitalize(value: string): string {
|
|
215
|
+
return value.charAt(0).toUpperCase() + value.slice(1);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Group key + pt-BR label for a photo `roomType`. Unknown rooms keep their
|
|
220
|
+
* own (capitalized) label; empty / "other" values go to `Outras fotos`.
|
|
221
|
+
*/
|
|
222
|
+
export function photoRoomLabel(roomType: string | null | undefined): {
|
|
223
|
+
key: string;
|
|
224
|
+
label: string;
|
|
225
|
+
} {
|
|
226
|
+
const raw = (roomType ?? "").trim();
|
|
227
|
+
const normalized = normalizeRoomLabel(raw);
|
|
228
|
+
if (NON_ROOM_LABELS.has(normalized)) {
|
|
229
|
+
return { key: PHOTO_GROUP_OTHER_KEY, label: PHOTO_GROUP_OTHER_LABEL };
|
|
230
|
+
}
|
|
231
|
+
const known = GROUP_BY_MEMBER.get(normalized);
|
|
232
|
+
if (known) return known;
|
|
233
|
+
return { key: normalized, label: capitalize(raw) };
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function isPhoto(item: ListingMedia): boolean {
|
|
237
|
+
return (item.type || "image") === "image" && typeof item.src === "string";
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Gallery photos grouped by room, in first-appearance order with `Outras
|
|
242
|
+
* fotos` last. Videos and tours are skipped. A listing with no analysis at
|
|
243
|
+
* all yields a single `Outras fotos` group (or `[]` when it has no photos),
|
|
244
|
+
* so callers can fall back to the flat gallery when `groups.length <= 1`.
|
|
245
|
+
*/
|
|
246
|
+
export function listingPhotoGroups(listing: {
|
|
247
|
+
media?: ListingMedia[] | null;
|
|
248
|
+
}): ListingPhotoGroup[] {
|
|
249
|
+
const groups = new Map<string, ListingPhotoGroup>();
|
|
250
|
+
const photos = [...(listing.media ?? [])]
|
|
251
|
+
.filter(isPhoto)
|
|
252
|
+
.sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
|
|
253
|
+
for (const photo of photos) {
|
|
254
|
+
const { key, label } = photoRoomLabel(photo.roomType);
|
|
255
|
+
const group = groups.get(key);
|
|
256
|
+
if (group) {
|
|
257
|
+
group.photos.push(photo);
|
|
258
|
+
} else {
|
|
259
|
+
groups.set(key, { key, label, photos: [photo] });
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
const ordered = [...groups.values()];
|
|
263
|
+
const otherIndex = ordered.findIndex((g) => g.key === PHOTO_GROUP_OTHER_KEY);
|
|
264
|
+
if (otherIndex >= 0 && otherIndex !== ordered.length - 1) {
|
|
265
|
+
const [other] = ordered.splice(otherIndex, 1);
|
|
266
|
+
ordered.push(other!);
|
|
267
|
+
}
|
|
268
|
+
return ordered;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
export interface ListingVisualHighlightsOptions {
|
|
272
|
+
/** Max highlights to return. Default 8. */
|
|
273
|
+
limit?: number;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Distinct visual highlights across the gallery, most frequent first (ties
|
|
278
|
+
* keep gallery order). Case- and accent-insensitive dedupe; the first
|
|
279
|
+
* spelling seen wins.
|
|
280
|
+
*/
|
|
281
|
+
export function listingVisualHighlights(
|
|
282
|
+
listing: { media?: ListingMedia[] | null },
|
|
283
|
+
options?: ListingVisualHighlightsOptions
|
|
284
|
+
): string[] {
|
|
285
|
+
const limit = Math.max(0, Math.floor(options?.limit ?? 8));
|
|
286
|
+
if (limit === 0) return [];
|
|
287
|
+
const counts = new Map<
|
|
288
|
+
string,
|
|
289
|
+
{ text: string; count: number; seen: number }
|
|
290
|
+
>();
|
|
291
|
+
let seen = 0;
|
|
292
|
+
for (const item of listing.media ?? []) {
|
|
293
|
+
if (!isPhoto(item) || !Array.isArray(item.features)) continue;
|
|
294
|
+
for (const feature of item.features) {
|
|
295
|
+
if (typeof feature !== "string") continue;
|
|
296
|
+
const text = feature.trim();
|
|
297
|
+
if (!text) continue;
|
|
298
|
+
const key = normalizeRoomLabel(text);
|
|
299
|
+
if (!key) continue;
|
|
300
|
+
const entry = counts.get(key);
|
|
301
|
+
if (entry) {
|
|
302
|
+
entry.count += 1;
|
|
303
|
+
} else {
|
|
304
|
+
counts.set(key, { text, count: 1, seen: seen++ });
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
return [...counts.values()]
|
|
309
|
+
.sort((a, b) => b.count - a.count || a.seen - b.seen)
|
|
310
|
+
.slice(0, limit)
|
|
311
|
+
.map((entry) => entry.text);
|
|
312
|
+
}
|