@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
package/dist/index.mjs
CHANGED
|
@@ -12,6 +12,90 @@ function listingPublicPath(listing) {
|
|
|
12
12
|
return `/imoveis/id-${identity}`;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
// src/internal/sdk-http.ts
|
|
16
|
+
var PUBLISHABLE_KEY_HEADER = "X-Garagem-Publishable-Key";
|
|
17
|
+
function publishableKeyHeaders(publishableKey) {
|
|
18
|
+
const key = publishableKey?.trim();
|
|
19
|
+
if (!key) return {};
|
|
20
|
+
return { [PUBLISHABLE_KEY_HEADER]: key };
|
|
21
|
+
}
|
|
22
|
+
function withPublishableKeyHeader(init, publishableKey) {
|
|
23
|
+
const extra = publishableKeyHeaders(publishableKey);
|
|
24
|
+
if (Object.keys(extra).length === 0) return init;
|
|
25
|
+
const current = init.headers;
|
|
26
|
+
const base = plainHeaders(current);
|
|
27
|
+
return { ...init, headers: { ...base, ...extra } };
|
|
28
|
+
}
|
|
29
|
+
function plainHeaders(headers) {
|
|
30
|
+
const out = {};
|
|
31
|
+
if (!headers) return out;
|
|
32
|
+
if (typeof Headers !== "undefined" && headers instanceof Headers) {
|
|
33
|
+
headers.forEach((value, name) => {
|
|
34
|
+
out[name] = value;
|
|
35
|
+
});
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
38
|
+
if (Array.isArray(headers)) {
|
|
39
|
+
for (const pair of headers) {
|
|
40
|
+
out[String(pair[0])] = String(pair[1]);
|
|
41
|
+
}
|
|
42
|
+
return out;
|
|
43
|
+
}
|
|
44
|
+
for (const [name, value] of Object.entries(
|
|
45
|
+
headers
|
|
46
|
+
)) {
|
|
47
|
+
if (typeof value === "string") out[name] = value;
|
|
48
|
+
}
|
|
49
|
+
return out;
|
|
50
|
+
}
|
|
51
|
+
function finiteNonNegative(value) {
|
|
52
|
+
if (typeof value === "number" && Number.isFinite(value) && value >= 0) {
|
|
53
|
+
return value;
|
|
54
|
+
}
|
|
55
|
+
if (typeof value === "string" && value.trim()) {
|
|
56
|
+
const parsed = Number(value);
|
|
57
|
+
if (Number.isFinite(parsed) && parsed >= 0) return parsed;
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
function parseSdkErrorBody(text) {
|
|
62
|
+
const raw = text ? text.slice(0, 200) : "";
|
|
63
|
+
if (!text) {
|
|
64
|
+
return { reason: null, retryAfterSeconds: null, summary: "" };
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
const body = JSON.parse(text);
|
|
68
|
+
if (!body || typeof body !== "object") {
|
|
69
|
+
return { reason: null, retryAfterSeconds: null, summary: raw };
|
|
70
|
+
}
|
|
71
|
+
const record = body;
|
|
72
|
+
const reason = typeof record.reason === "string" && record.reason ? record.reason : null;
|
|
73
|
+
const retryAfterSeconds = finiteNonNegative(
|
|
74
|
+
record.retryAfterSeconds ?? record.retryAfter
|
|
75
|
+
);
|
|
76
|
+
const errorText = typeof record.error === "string" && record.error ? record.error : raw;
|
|
77
|
+
return {
|
|
78
|
+
reason,
|
|
79
|
+
retryAfterSeconds,
|
|
80
|
+
summary: errorText.slice(0, 200)
|
|
81
|
+
};
|
|
82
|
+
} catch {
|
|
83
|
+
return { reason: null, retryAfterSeconds: null, summary: raw };
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function retryAfterFromResponse(response, bodySeconds, nowMs = Date.now()) {
|
|
87
|
+
const header = response.headers.get("Retry-After")?.trim();
|
|
88
|
+
if (header) {
|
|
89
|
+
const delta = finiteNonNegative(header);
|
|
90
|
+
if (delta != null) return delta;
|
|
91
|
+
const at = Date.parse(header);
|
|
92
|
+
if (Number.isFinite(at)) {
|
|
93
|
+
return Math.max(0, Math.ceil((at - nowMs) / 1e3));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return bodySeconds;
|
|
97
|
+
}
|
|
98
|
+
|
|
15
99
|
// src/internal/url.ts
|
|
16
100
|
var DEFAULT_BASE_URL = "https://app.garagem.ai";
|
|
17
101
|
var DEFAULT_RESOLVE_BASE_URL = "https://cdn.fndn.ai/site";
|
|
@@ -46,27 +130,50 @@ function buildListingFiltersQuery(filters) {
|
|
|
46
130
|
}
|
|
47
131
|
|
|
48
132
|
// src/fetchers.ts
|
|
49
|
-
async function callJson(url, init, fetchImpl) {
|
|
50
|
-
const response = await fetchImpl(
|
|
133
|
+
async function callJson(url, init, fetchImpl, publishableKey) {
|
|
134
|
+
const response = await fetchImpl(
|
|
135
|
+
url,
|
|
136
|
+
withPublishableKeyHeader(init, publishableKey)
|
|
137
|
+
);
|
|
51
138
|
if (!response.ok) {
|
|
52
|
-
|
|
53
|
-
throw new GaragemSdkError(
|
|
54
|
-
`Garagem SDK: request failed (${response.status} ${response.statusText}) for ${url}${text ? ` \u2014 ${text.slice(0, 200)}` : ""}`,
|
|
55
|
-
{ status: response.status, url }
|
|
56
|
-
);
|
|
139
|
+
throw await readGaragemSdkError(response, url);
|
|
57
140
|
}
|
|
58
141
|
return await response.json();
|
|
59
142
|
}
|
|
60
143
|
var GaragemSdkError = class extends Error {
|
|
61
144
|
status;
|
|
62
145
|
url;
|
|
146
|
+
/** Machine reason from the JSON body (`invalid_publishable_key`, `rate_limited`, …). */
|
|
147
|
+
reason;
|
|
148
|
+
/**
|
|
149
|
+
* Seconds to wait before retrying. Set on HTTP 429 from `Retry-After`
|
|
150
|
+
* or the body's `retryAfterSeconds`. `null` when the response has neither.
|
|
151
|
+
*/
|
|
152
|
+
retryAfter;
|
|
63
153
|
constructor(message, info) {
|
|
64
154
|
super(message);
|
|
65
155
|
this.name = "GaragemSdkError";
|
|
66
156
|
this.status = info.status;
|
|
67
157
|
this.url = info.url;
|
|
158
|
+
this.reason = info.reason ?? null;
|
|
159
|
+
this.retryAfter = info.retryAfter ?? null;
|
|
68
160
|
}
|
|
69
161
|
};
|
|
162
|
+
async function readGaragemSdkError(response, url) {
|
|
163
|
+
const text = await response.text().catch(() => "");
|
|
164
|
+
const parsed = parseSdkErrorBody(text);
|
|
165
|
+
const retryAfter = response.status === 429 ? retryAfterFromResponse(response, parsed.retryAfterSeconds) : parsed.retryAfterSeconds;
|
|
166
|
+
const detail = parsed.summary;
|
|
167
|
+
return new GaragemSdkError(
|
|
168
|
+
`Garagem SDK: request failed (${response.status} ${response.statusText}) for ${url}${detail ? ` \u2014 ${detail}` : ""}`,
|
|
169
|
+
{
|
|
170
|
+
status: response.status,
|
|
171
|
+
url,
|
|
172
|
+
reason: parsed.reason,
|
|
173
|
+
retryAfter
|
|
174
|
+
}
|
|
175
|
+
);
|
|
176
|
+
}
|
|
70
177
|
async function getListings(options) {
|
|
71
178
|
const { filters, baseUrl, fetch: fetchImpl, next } = options;
|
|
72
179
|
const siteId = await coerceSiteId(options.siteId);
|
|
@@ -77,7 +184,8 @@ async function getListings(options) {
|
|
|
77
184
|
const data = await callJson(
|
|
78
185
|
url,
|
|
79
186
|
{ method: "GET", headers: { Accept: "application/json" }, next },
|
|
80
|
-
fetchImpl ?? fetch
|
|
187
|
+
fetchImpl ?? fetch,
|
|
188
|
+
options.publishableKey
|
|
81
189
|
);
|
|
82
190
|
return {
|
|
83
191
|
listings: data.listings ?? [],
|
|
@@ -98,7 +206,8 @@ async function getListing(options) {
|
|
|
98
206
|
return callJson(
|
|
99
207
|
url,
|
|
100
208
|
{ method: "GET", headers: { Accept: "application/json" }, next },
|
|
101
|
-
fetchImpl ?? fetch
|
|
209
|
+
fetchImpl ?? fetch,
|
|
210
|
+
options.publishableKey
|
|
102
211
|
);
|
|
103
212
|
}
|
|
104
213
|
async function getSite(options) {
|
|
@@ -120,17 +229,20 @@ async function getSite(options) {
|
|
|
120
229
|
if (domain) params.set("domain", domain);
|
|
121
230
|
const url = `${base}/api/sites/resolve?${params.toString()}`;
|
|
122
231
|
const f = fetchImpl ?? fetch;
|
|
123
|
-
const response = await f(
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
232
|
+
const response = await f(
|
|
233
|
+
url,
|
|
234
|
+
withPublishableKeyHeader(
|
|
235
|
+
{
|
|
236
|
+
method: "GET",
|
|
237
|
+
headers: { Accept: "application/json" },
|
|
238
|
+
next
|
|
239
|
+
},
|
|
240
|
+
options.publishableKey
|
|
241
|
+
)
|
|
242
|
+
);
|
|
128
243
|
if (response.status === 404) return null;
|
|
129
244
|
if (!response.ok) {
|
|
130
|
-
throw
|
|
131
|
-
`Garagem SDK: getSite failed (${response.status}) for ${url}`,
|
|
132
|
-
{ status: response.status, url }
|
|
133
|
-
);
|
|
245
|
+
throw await readGaragemSdkError(response, url);
|
|
134
246
|
}
|
|
135
247
|
const data = await response.json();
|
|
136
248
|
return {
|
|
@@ -158,7 +270,8 @@ async function searchListings(options) {
|
|
|
158
270
|
body: JSON.stringify(params),
|
|
159
271
|
next
|
|
160
272
|
},
|
|
161
|
-
fetchImpl ?? fetch
|
|
273
|
+
fetchImpl ?? fetch,
|
|
274
|
+
options.publishableKey
|
|
162
275
|
);
|
|
163
276
|
}
|
|
164
277
|
async function getSearchUi(options) {
|
|
@@ -169,11 +282,12 @@ async function getSearchUi(options) {
|
|
|
169
282
|
return callJson(
|
|
170
283
|
url,
|
|
171
284
|
{ method: "GET", headers: { Accept: "application/json" }, next },
|
|
172
|
-
fetchImpl ?? fetch
|
|
285
|
+
fetchImpl ?? fetch,
|
|
286
|
+
options.publishableKey
|
|
173
287
|
);
|
|
174
288
|
}
|
|
175
289
|
async function queryListings(options) {
|
|
176
|
-
const { params, baseUrl, fetch: fetchImpl, next } = options;
|
|
290
|
+
const { params, baseUrl, fetch: fetchImpl, next, signal } = options;
|
|
177
291
|
const siteId = await coerceSiteId(options.siteId);
|
|
178
292
|
const base = normalizeBaseUrl(baseUrl);
|
|
179
293
|
const url = `${base}/api/sites/${encodeURIComponent(siteId)}/search/listings`;
|
|
@@ -186,9 +300,11 @@ async function queryListings(options) {
|
|
|
186
300
|
"Content-Type": "application/json"
|
|
187
301
|
},
|
|
188
302
|
body: JSON.stringify(params ?? {}),
|
|
189
|
-
next
|
|
303
|
+
next,
|
|
304
|
+
signal
|
|
190
305
|
},
|
|
191
|
-
fetchImpl ?? fetch
|
|
306
|
+
fetchImpl ?? fetch,
|
|
307
|
+
options.publishableKey
|
|
192
308
|
);
|
|
193
309
|
}
|
|
194
310
|
async function getSimilarListings(options) {
|
|
@@ -216,7 +332,8 @@ async function getSimilarListings(options) {
|
|
|
216
332
|
const data = await callJson(
|
|
217
333
|
url,
|
|
218
334
|
{ method: "GET", headers: { Accept: "application/json" }, next },
|
|
219
|
-
fetchImpl ?? fetch
|
|
335
|
+
fetchImpl ?? fetch,
|
|
336
|
+
options.publishableKey
|
|
220
337
|
);
|
|
221
338
|
return {
|
|
222
339
|
listings: data.listings ?? [],
|
|
@@ -231,7 +348,8 @@ async function getCmsCollections(options) {
|
|
|
231
348
|
const data = await callJson(
|
|
232
349
|
url,
|
|
233
350
|
{ method: "GET", headers: { Accept: "application/json" }, next },
|
|
234
|
-
fetchImpl ?? fetch
|
|
351
|
+
fetchImpl ?? fetch,
|
|
352
|
+
options.publishableKey
|
|
235
353
|
);
|
|
236
354
|
return data.collections ?? [];
|
|
237
355
|
}
|
|
@@ -248,7 +366,8 @@ async function getCmsCollection(options) {
|
|
|
248
366
|
const data = await callJson(
|
|
249
367
|
url,
|
|
250
368
|
{ method: "GET", headers: { Accept: "application/json" }, next },
|
|
251
|
-
fetchImpl ?? fetch
|
|
369
|
+
fetchImpl ?? fetch,
|
|
370
|
+
options.publishableKey
|
|
252
371
|
);
|
|
253
372
|
if (data && typeof data === "object" && "collection" in data && data.collection) {
|
|
254
373
|
return data.collection;
|
|
@@ -283,7 +402,8 @@ async function getCmsEntries(options) {
|
|
|
283
402
|
const data = await callJson(
|
|
284
403
|
url,
|
|
285
404
|
{ method: "GET", headers: { Accept: "application/json" }, next },
|
|
286
|
-
fetchImpl ?? fetch
|
|
405
|
+
fetchImpl ?? fetch,
|
|
406
|
+
options.publishableKey
|
|
287
407
|
);
|
|
288
408
|
return {
|
|
289
409
|
entries: data.entries ?? [],
|
|
@@ -308,7 +428,8 @@ async function getCmsEntry(options) {
|
|
|
308
428
|
const data = await callJson(
|
|
309
429
|
url,
|
|
310
430
|
{ method: "GET", headers: { Accept: "application/json" }, next },
|
|
311
|
-
fetchImpl ?? fetch
|
|
431
|
+
fetchImpl ?? fetch,
|
|
432
|
+
options.publishableKey
|
|
312
433
|
);
|
|
313
434
|
if (data && typeof data === "object" && "entry" in data && data.entry) {
|
|
314
435
|
return data.entry;
|
|
@@ -843,7 +964,8 @@ async function resolvePublicSiteId(options) {
|
|
|
843
964
|
const site = await getSite({
|
|
844
965
|
domain: host,
|
|
845
966
|
baseUrl: options.baseUrl,
|
|
846
|
-
fetch: options.fetch
|
|
967
|
+
fetch: options.fetch,
|
|
968
|
+
publishableKey: options.publishableKey
|
|
847
969
|
});
|
|
848
970
|
if (site?.id) return site.id;
|
|
849
971
|
throw new GaragemSdkError(
|
|
@@ -872,7 +994,8 @@ async function resolveLeadSiteId(input) {
|
|
|
872
994
|
return resolvePublicSiteId({
|
|
873
995
|
host,
|
|
874
996
|
baseUrl: input.baseUrl,
|
|
875
|
-
fetch: input.fetch
|
|
997
|
+
fetch: input.fetch,
|
|
998
|
+
publishableKey: input.publishableKey
|
|
876
999
|
});
|
|
877
1000
|
}
|
|
878
1001
|
}
|
|
@@ -880,6 +1003,8 @@ var LeadSubmitError = class extends Error {
|
|
|
880
1003
|
code;
|
|
881
1004
|
status;
|
|
882
1005
|
retryAfterSeconds;
|
|
1006
|
+
/** Seconds to wait. Same value as `retryAfterSeconds`; `null` when unset. */
|
|
1007
|
+
retryAfter;
|
|
883
1008
|
constructor(message, info) {
|
|
884
1009
|
super(message);
|
|
885
1010
|
this.name = "LeadSubmitError";
|
|
@@ -888,6 +1013,7 @@ var LeadSubmitError = class extends Error {
|
|
|
888
1013
|
if (info.retryAfterSeconds != null) {
|
|
889
1014
|
this.retryAfterSeconds = info.retryAfterSeconds;
|
|
890
1015
|
}
|
|
1016
|
+
this.retryAfter = info.retryAfterSeconds ?? null;
|
|
891
1017
|
}
|
|
892
1018
|
};
|
|
893
1019
|
var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
@@ -929,7 +1055,8 @@ async function getLeadUi(options) {
|
|
|
929
1055
|
headers: { Accept: "application/json" },
|
|
930
1056
|
next: options.next
|
|
931
1057
|
},
|
|
932
|
-
options.fetch ?? fetch
|
|
1058
|
+
options.fetch ?? fetch,
|
|
1059
|
+
options.publishableKey
|
|
933
1060
|
);
|
|
934
1061
|
}
|
|
935
1062
|
function assertListingId(listingId) {
|
|
@@ -1002,7 +1129,8 @@ async function postSiteLead(input) {
|
|
|
1002
1129
|
method: "POST",
|
|
1003
1130
|
headers: {
|
|
1004
1131
|
Accept: "application/json",
|
|
1005
|
-
"Content-Type": "application/json"
|
|
1132
|
+
"Content-Type": "application/json",
|
|
1133
|
+
...publishableKeyHeaders(input.publishableKey)
|
|
1006
1134
|
},
|
|
1007
1135
|
body: JSON.stringify(input.body)
|
|
1008
1136
|
});
|
|
@@ -1017,12 +1145,23 @@ async function postSiteLead(input) {
|
|
|
1017
1145
|
const id = typeof data.id === "string" && data.id ? data.id : "";
|
|
1018
1146
|
return { ok: true, status: 202, id };
|
|
1019
1147
|
}
|
|
1020
|
-
|
|
1148
|
+
if (response.status === 401) {
|
|
1149
|
+
throw new LeadSubmitError("Garagem SDK: invalid publishable key.", {
|
|
1150
|
+
code: "unauthorized",
|
|
1151
|
+
status: 401
|
|
1152
|
+
});
|
|
1153
|
+
}
|
|
1021
1154
|
if (response.status === 429) {
|
|
1155
|
+
const text = await response.text().catch(() => "");
|
|
1156
|
+
const parsed = parseSdkErrorBody(text);
|
|
1157
|
+
const retryAfter = retryAfterFromResponse(
|
|
1158
|
+
response,
|
|
1159
|
+
parsed.retryAfterSeconds
|
|
1160
|
+
);
|
|
1022
1161
|
throw new LeadSubmitError("Garagem SDK: too many lead submissions.", {
|
|
1023
1162
|
code: "rate_limited",
|
|
1024
1163
|
status: 429,
|
|
1025
|
-
retryAfterSeconds:
|
|
1164
|
+
...retryAfter != null ? { retryAfterSeconds: retryAfter } : {}
|
|
1026
1165
|
});
|
|
1027
1166
|
}
|
|
1028
1167
|
if (response.status === 404) {
|
|
@@ -1066,6 +1205,7 @@ async function submitVisitLead(input) {
|
|
|
1066
1205
|
siteId: input.siteId,
|
|
1067
1206
|
baseUrl: input.baseUrl,
|
|
1068
1207
|
fetch: input.fetch,
|
|
1208
|
+
publishableKey: input.publishableKey,
|
|
1069
1209
|
body: {
|
|
1070
1210
|
source: "site-sdk",
|
|
1071
1211
|
leadType: "visit",
|
|
@@ -1084,6 +1224,7 @@ async function submitContactLead(input) {
|
|
|
1084
1224
|
siteId: input.siteId,
|
|
1085
1225
|
baseUrl: input.baseUrl,
|
|
1086
1226
|
fetch: input.fetch,
|
|
1227
|
+
publishableKey: input.publishableKey,
|
|
1087
1228
|
body: {
|
|
1088
1229
|
source: "site-sdk",
|
|
1089
1230
|
leadType: "contact",
|
|
@@ -2673,6 +2814,29 @@ var STUDIO_SDK_CONTRACT = {
|
|
|
2673
2814
|
*/
|
|
2674
2815
|
unpublishedPhoneExports: [],
|
|
2675
2816
|
amenityExports: ["listingAmenityGroups"],
|
|
2817
|
+
/**
|
|
2818
|
+
* Prompt-safe photo helpers on `minNpmVersion`. Empty until the release
|
|
2819
|
+
* that carries `getSimilarByPhoto` / `listingPhotoGroups` /
|
|
2820
|
+
* `listingVisualHighlights` is on npm; then bump the pin, move the names
|
|
2821
|
+
* here from `unpublishedPhotoExports`, and `studioPhotoInstruction()`
|
|
2822
|
+
* starts teaching the gallery-by-room, highlight chips, and
|
|
2823
|
+
* "imóveis com fotos parecidas" blocks. The caption-based `media[].alt` /
|
|
2824
|
+
* `media[].caption` fields are API data (not tarball exports) and are
|
|
2825
|
+
* documented regardless of the pin.
|
|
2826
|
+
*/
|
|
2827
|
+
photoExports: [],
|
|
2828
|
+
/**
|
|
2829
|
+
* Photo helpers in the repo but not on `minNpmVersion`. Prompts,
|
|
2830
|
+
* completeness, and repair text must not mention these until the pin
|
|
2831
|
+
* bumps — v0 installs the pin and the ESM loader throws on missing named
|
|
2832
|
+
* exports.
|
|
2833
|
+
*/
|
|
2834
|
+
unpublishedPhotoExports: [
|
|
2835
|
+
"getSimilarByPhoto",
|
|
2836
|
+
"listingPhotoGroups",
|
|
2837
|
+
"listingVisualHighlights",
|
|
2838
|
+
"photoRoomLabel"
|
|
2839
|
+
],
|
|
2676
2840
|
/**
|
|
2677
2841
|
* Names already on the pinned npm tarball (`minNpmVersion`) — safe for
|
|
2678
2842
|
* Studio prompts and completeness. Includes `visibleSearchFilters` +
|
|
@@ -2697,6 +2861,27 @@ var STUDIO_SDK_CONTRACT = {
|
|
|
2697
2861
|
"searchChromeModel",
|
|
2698
2862
|
"rangeDraftFromPath"
|
|
2699
2863
|
],
|
|
2864
|
+
/**
|
|
2865
|
+
* maps.fndn.ai helpers (static map, street view, boundaries, travel
|
|
2866
|
+
* time) plus friendly map search. They ship in `mapsSince`;
|
|
2867
|
+
* `studioMapsInstruction()` is empty and these names are codegen
|
|
2868
|
+
* violations until `minNpmVersion` reaches that release — bump the pin
|
|
2869
|
+
* after the tarball is on npm and the listing guidance turns on by
|
|
2870
|
+
* itself. `useMapSearch` is a `/react` hook named in that same
|
|
2871
|
+
* instruction; it stays off `reactExports` until the pin moves.
|
|
2872
|
+
*/
|
|
2873
|
+
mapsSince: "0.7.0",
|
|
2874
|
+
mapsExports: [
|
|
2875
|
+
"listingStaticMapUrl",
|
|
2876
|
+
"listingStreetViewUrl",
|
|
2877
|
+
"listingStreetViewAvailable",
|
|
2878
|
+
"neighborhoodBoundaryLayer",
|
|
2879
|
+
"boundaryLayerUrl",
|
|
2880
|
+
"travelTimeFromListing",
|
|
2881
|
+
"searchListingsInBounds",
|
|
2882
|
+
"searchListingsInPolygon",
|
|
2883
|
+
"clusterPins"
|
|
2884
|
+
],
|
|
2700
2885
|
/**
|
|
2701
2886
|
* Market-data helpers (neighborhood price summary, listing market
|
|
2702
2887
|
* position, visitor price estimate, pt-BR labels). They ship in
|
|
@@ -2816,6 +3001,9 @@ function unavailableReactImports(source, pin) {
|
|
|
2816
3001
|
}
|
|
2817
3002
|
return missing;
|
|
2818
3003
|
}
|
|
3004
|
+
function studioPublishableKeyInstruction() {
|
|
3005
|
+
return `Public site API key (optional, backwards compatible). \`publishableKey\` (\`pk_live_\u2026\`) is not a secret. Create or rotate it in Garagem at Configura\xE7\xF5es \u2192 Sites \u2192 the site \u2192 API p\xFAblica (route \`/configuracoes/sites/[siteId]\`, section API p\xFAblica (SDK)). Pass it to \`createGaragemClient({ siteId, baseUrl: GARAGEM_API_BASE, publishableKey })\` or on each call: \`getListings\`, \`getListing\`, \`getSite\`, \`getSearchUi\`, \`queryListings\`, \`searchListings\`, the CMS helpers, \`getLeadUi\`, \`submitVisitLead\`, \`submitContactLead\`, and \`usePublicSearch\`. The SDK sends header \`X-Garagem-Publishable-Key\` (a Bearer token that starts with \`pk_live_\` is also accepted). Omitting the key still succeeds. Once a site has a key, anonymous traffic uses the stricter per-IP budget (listings/search 30/min, detail 60/min, config 30/min). A site with no key uses the looser anonymous budget (120 / 300 / 120). With the key, budgets are listings/search 600/min, detail 1200/min, config 300/min. Window is 60 seconds. Success and 429 responses carry \`RateLimit-Limit\`, \`RateLimit-Remaining\`, \`RateLimit-Reset\`, and \`RateLimit-Policy\`. HTTP 401 throws \`GaragemSdkError\` with \`status\` 401 and \`reason\` \`invalid_publishable_key\` (wrong key). HTTP 403 has \`reason\` \`origin_not_allowed\` when the site's origin allowlist rejects the browser Origin or Referer. HTTP 429 has \`reason\` \`rate_limited\` and \`retryAfter\` seconds (same value as the \`Retry-After\` header). \`LeadSubmitError\` uses \`code\` \`rate_limited\` or \`unauthorized\`, and \`retryAfter\` / \`retryAfterSeconds\` on 429. A public constant next to \`GARAGEM_API_BASE\` is the right place for the key. Do not invent a second header name.`;
|
|
3006
|
+
}
|
|
2819
3007
|
function studioSdkPinInstruction() {
|
|
2820
3008
|
const version = STUDIO_SDK_CONTRACT.minNpmVersion;
|
|
2821
3009
|
const names = [...reactExportsAvailableAt(version)].join(", ");
|
|
@@ -2834,6 +3022,31 @@ function studioListingDetailInstruction() {
|
|
|
2834
3022
|
const names = STUDIO_SDK_CONTRACT.listingDetailExports.join(", ");
|
|
2835
3023
|
return `Listing detail: import ${names} from \`${STUDIO_SDK_PACKAGE}\`. Render \`listingDetailModel\` leaves: \`model.facts[].label\` / \`.text\`, \`model.values[].label\` / \`.text\`, \`model.location.label\` / \`model.location.mapsHref\`, breadcrumb \`.href\` (search prefixes of \`listing.path\`). The pre\xE7o / sob consulta entry is the primary value; condom\xEDnio and IPTU are secondary and omitted when missing. \`model.description\` is the complete string \u2014 do not slice. A collapsed disclosure uses a container (max-height or overflow), not a cut of the string. Never interpolate \`model.location\`, \`model.facts\`, \`model.values\`, \`model.breadcrumb\`, or \`model.mediaOverlays\` as a React child. Video/tour: \`model.mediaOverlays\` as hash links (\`#video\` / \`#tour\`); player src is \`embedSrc\`; fullscreen overlay closes with browser back; omit when that overlay is absent. Do not key the page on \`location.hash\`. Similar listings: \`getSimilarListings({ siteId, listingId, baseUrl })\` plus the site listing-card module; hide the section when empty. Do not invent a local recommendation loop.`;
|
|
2836
3024
|
}
|
|
3025
|
+
function studioPhotoInstructionFor(published) {
|
|
3026
|
+
const has = (name) => published.includes(name);
|
|
3027
|
+
const parts = [
|
|
3028
|
+
`Gallery photo text: \`item.alt\` on \`listing.media\` is the photo caption when the platform analyzed it (else "<title> - Foto N") \u2014 always pass it as the img alt. \`item.caption\` is optional: show it as the slide / overlay caption when present and omit the element when absent. Never invent captions or room names in generated source.`
|
|
3029
|
+
];
|
|
3030
|
+
if (has("listingPhotoGroups")) {
|
|
3031
|
+
parts.push(
|
|
3032
|
+
`Gallery by room: \`const groups = listingPhotoGroups(listing)\` from \`${STUDIO_SDK_PACKAGE}\` returns \`{ key, label, photos }[]\` (pt-BR labels such as "Sala", "Quartos", "Cozinha"; "Outras fotos" last). Use it only inside the fullscreen photo overlay (room tabs or section headings over the thumbnail strip) \u2014 the page carousel stays one flat section. Render \`group.label\` and \`group.photos.length\`; when \`groups.length <= 1\` render the flat strip without headings. Never read \`item.roomType\` / \`item.sceneType\` directly to build sections and never hardcode room names.`
|
|
3033
|
+
);
|
|
3034
|
+
}
|
|
3035
|
+
if (has("listingVisualHighlights")) {
|
|
3036
|
+
parts.push(
|
|
3037
|
+
`Visual highlights: \`const highlights = listingVisualHighlights(listing, { limit: 6 })\` returns deduped strings ("piso de madeira", "vista livre"). Render them as small chips (site tokens, \`--radius\`) under the gallery or beside the facts, one chip per string, and omit the block when the array is empty. Do not merge them with \`listingAmenityGroups\` and do not read \`item.features\` directly.`
|
|
3038
|
+
);
|
|
3039
|
+
}
|
|
3040
|
+
if (has("getSimilarByPhoto")) {
|
|
3041
|
+
parts.push(
|
|
3042
|
+
`Im\xF3veis com fotos parecidas: on the server page, pick the first image item of \`listing.media\` and \`await getSimilarByPhoto(siteId, listing.id, photo.id, { limit: 6, baseUrl: GARAGEM_API_BASE })\` from \`${STUDIO_SDK_PACKAGE}\` (positional ids; \`listing.id\` is the UUID, never the path). The result is \`{ available, items }\`: when \`available === false\` (tenant without image search, or \`photo.id\` is not a media UUID such as the \`image-N\` / \`external-N\` gallery keys \u2014 that returns locally and does not throw) render nothing \u2014 no heading, no empty state; when \`items.length === 0\` also render nothing. Otherwise a section titled "Im\xF3veis com fotos parecidas" with the site listing-card module (\`toListingCardModel(item.listing)\`), using \`item.matchedPhoto.src\` / \`item.matchedPhoto.alt\` as that card's photo. Keep \`getSimilarListings\` as the default similar carousel; this section is additional, below it. Wrap the call in try/catch and treat an error like \`available: false\`.`
|
|
3043
|
+
);
|
|
3044
|
+
}
|
|
3045
|
+
return parts.join(" ");
|
|
3046
|
+
}
|
|
3047
|
+
function studioPhotoInstruction() {
|
|
3048
|
+
return studioPhotoInstructionFor(STUDIO_SDK_CONTRACT.photoExports);
|
|
3049
|
+
}
|
|
2837
3050
|
function studioAmenityInstruction() {
|
|
2838
3051
|
return `Listing amenities: Portuguese labels from \`listingAmenityGroups(listing, dictionary)\` (pass the dictionary from \`getSearchUi()\` so section titles follow Campos). Each group is \`{ title, labels: string[] }\` \u2014 render \`group.title\` and \`group.labels.map((label) => \u2026)\` and hide a group when \`group.labels.length === 0\`. Do not hardcode section titles. Never print amenity ids, never invent a local label map, and never title a section "Comodidades da unidade".`;
|
|
2839
3052
|
}
|
|
@@ -2842,6 +3055,14 @@ function studioSearchInstruction() {
|
|
|
2842
3055
|
const libNames = STUDIO_SDK_CONTRACT.searchExports.join(", ");
|
|
2843
3056
|
return `Search: import ${reactNames} from \`${STUDIO_SDK_PACKAGE}/react\`. From \`${STUDIO_SDK_PACKAGE}\` import ${libNames}. Prefetch \`getSearchUi\` + \`queryListings\` on the server page. \`const search = usePublicSearch({ siteId, baseUrl: GARAGEM_API_BASE, search: searchFromServer, initial })\` where \`searchFromServer\` is \`new URLSearchParams(await searchParams).toString()\` \u2014 never shorthand \`{ search }\` beside \`const search =\` (temporal dead zone). Do not wrap this UI in \`<Suspense>\` and do not add a route \`loading\` file \u2014 heading and cards are ordinary elements in the document, visible with JavaScript off. Compose the page UI in the app \u2014 do not paste a canonical search TSX. Required chrome (design is free; omit none): query (\`qDraft\` / \`setQDraft\` / form \`preventDefault\` + \`submitQuery\`), heading (count span FIRST then h1 from \`searchResultsHeading(search.pathFilters, search.schema?.dictionary, search.locationNames)\` \u2014 never \`searchResultsHeading({})\`), toolbar (\`toolbarFilterIds\` + \`applyFilter\`; range \u201CAtualizar\u201D on that toolbar item only) vs sheet (\`visibleSearchFilters\` extras, \`stageFilter\`, one footer \`applyStaged\`), sort (\`searchSortOptions\` + \`setSort\`; first option id is \`""\` / \u201CMais relevantes\u201D \u2014 map **only** that empty id to Select sentinel \`"relevancia"\` (\`opt.id || "relevancia"\`), never \`SelectItem value=""\` and never give \u201CMais recentes\u201D (\`id: "recentes"\`, \`?ordenar=recentes\`) that sentinel; on change \`setSort(id === "relevancia" ? "" : id)\` so recentes stays recentes. Closed trigger shows the option \`.label\`, never \`{search.applied.sort}\`), grid (\`listings.map\` + the site listing-card module; listing-card-skeleton only for a slot whose content is still unknown, never as a Suspense fallback; do not \`throw\` in that chrome), pagination (\`paginationPages\` + \`hrefWithExplicitPage\`). Never interpolate \`schema\`, \`pathFilters\`, or a filter object as a React child. \`queryListings\` key is \`params\`. The URL is the document. Count text is \`{search.total}\` only. Heading is one row; font size lives on the container and the span and h1 use \`font-size: inherit\`. Sort trigger shows the option label (\u201CMais relevantes\u201D when \`ordenar\` is absent), chevron at the end, same height as the toolbar controls. Toolbar ranges open a Popover form (not DropdownMenu \u2014 Menu typeahead swallows digit keys) whose submit calls \`applyFilter\`; the popup clips and the two inputs stay inside (\`min-w-0\`, no \`w-64\`). Reset min/max drafts when the popover opens and when the applied path range changes. The sheet omits toolbar ids (price, bedrooms) so Pre\xE7o is never a heading without inputs. Sheet DialogContent uses \`h-[min(640px,85dvh)]\` (not max-h alone) so the body ScrollArea can move. Tipo de im\xF3vel, caracter\xEDsticas and comodidades each use a nested ScrollArea with \`h-56 overflow-hidden\` (viewport \`h-full\`). Area is two inputs in schema order with no \u201CAplicar\u201D; the footer stages then applyStaged. Never read \`staged[filter.id]\` \u2014 path keys are \`bedrooms\` / \`listingType\` / \`bathrooms\`. Bedrooms Select reads \`pathFilters.bedrooms\` so \`/imoveis/4-quartos\` checks \`"4"\` and shows the same trigger dot as price. Bathrooms and parking pressed state uses \`pathFilterHasOption\`. Limpar keeps location plus toolbar price and bedrooms via \`clearStagedPathFilters\` and \`toolbarFilterIds\`; do not call \`clearStaged\` for that button. It enables only when staged has a path filter other than location and those kept toolbar ids. Each multi-select \`stageFilter\` value is one option id, never a concatenated slug; \`checked\` uses \`pathFilterHasOption\`. Listing type does not pass the clicked id: no path value shows every checkbox checked, unchecking one stages the other option's id, and the last box stays checked. Price inputs use formatGroupedInteger. The closed price and bedrooms triggers keep the filter label plus a dot when set \u2014 never the literal range. Empty price calls applyFilter(id, undefined); never send 0 or 1000000000. Area is a plain integer (not that mask). The results button stageFilter property_area_total with both drafts, then applyStaged. Never send 0 or 100000. Count buttons pass the option id (\`"2"\`), never the label \`"2+"\`. Property type, features, and amenities render in pt-BR label order. Do not set \`[data-slot="search-sort"] { flex-direction: column }\` in a \`<style>\` tag; that selector is row so the chevron sits beside the label. Empty copy: ${JSON.stringify(SEARCH_EMPTY_COPY)}`;
|
|
2844
3057
|
}
|
|
3058
|
+
function mapsExportsPublished(pin = STUDIO_SDK_CONTRACT.minNpmVersion) {
|
|
3059
|
+
return compareSemver(pin, STUDIO_SDK_CONTRACT.mapsSince) >= 0;
|
|
3060
|
+
}
|
|
3061
|
+
function studioMapsInstruction(options = {}) {
|
|
3062
|
+
if (!mapsExportsPublished(options.pin)) return "";
|
|
3063
|
+
const names = STUDIO_SDK_CONTRACT.mapsExports.join(", ");
|
|
3064
|
+
return `Maps on listing detail: from \`${STUDIO_SDK_PACKAGE}\` import ${names}. \`listing.location.coordinates\` is already masked by the site's privacy settings (\u2248100 m by default) \u2014 pass the listing object as-is; never un-mask, never re-geocode the street address to get a sharper point, never add decimals (\`maxDecimals\` can only coarsen). Always pass \`siteId\` (the resolved site id / publishable key) so maps.fndn.ai meters the site. Static map: \`const mapSrc = listingStaticMapUrl(listing, { width: 640, height: 320, zoom: 15, style: "roadmap", siteId })\` then \`{mapSrc ? <img src={mapSrc} alt={model.location.label} /> : null}\` \u2014 \`null\` means no coordinates, so omit the block (never a placeholder image). Zoom is capped by the coordinate precision (16 on the default mask); do not work around it. Street View: on the server page \`const sv = await listingStreetViewAvailable(listing, { siteId })\` (metadata is free), and only when \`sv.available\` render \`<img src={listingStreetViewUrl(listing, { width: 640, height: 400, siteId })} alt="Street View" />\` \u2014 the image is billed per load. Neighbourhood outline on an interactive map: load Maps JS ONLY through \`<script src="https://maps.fndn.ai/sdk.js?callback=initMap" async defer />\` (never a Google key in the app, never \`NEXT_PUBLIC_GOOGLE_MAPS_API_KEY\`); in \`initMap\` do \`const outline = await neighborhoodBoundaryLayer(listing.location.city, listing.location.neighborhood, { siteId })\` and \`if (outline.feature) map.data.addGeoJson(outline.feature)\`; with MapLibre the vector source url is \`boundaryLayerUrl(listing.location.city)\`. Travel time (\u201Cquanto tempo at\xE9\u2026\u201D): \`const trip = await travelTimeFromListing(listing, destination, { mode: "driving", siteId })\` gives \`{ minutes, distanceKm }\` or \`null\` (hide the row). Every uncached call is a billed Google Directions request: call it on demand \u2014 a destination the visitor typed, or at most one fixed landmark per listing page \u2014 never per listing card, never inside a search loop, keep the SDK cache on (default 15 min LRU, \`cache: null\` only in tests), and do not re-run it on every render. Map search (search page: search as the map moves, or draw an area): searchListingsInBounds(siteId, { bounds: { north, south, east, west }, zoom, q, sort, location, filters, page, pageSize, publishableKey }) and searchListingsInPolygon(siteId, { polygon: [[lat, lng], ...], q, sort, location, filters, page, pageSize, publishableKey }). Polygon points are [lat, lng], not GeoJSON. The server builds the allowlisted coordinates geo filter from those numbers; do not send a raw filter string from the browser. Pins are { id, lat, lng, price, coverImage } copied from the listings the API returned \u2014 masked pins, plot them as returned, never geocode the street to sharpen one. clusterPins(pins, zoom) is the headless grid: one pin keeps its coordinates, a group centroid is rounded back to the coarsest pin. The React hook useMapSearch (on the /react entry, next to usePublicSearch) debounces viewport changes by 400ms, cancels the stale request, caps pageSize at 100, and returns those pins plus cards from toListingCardModel. Pass the same q, sort, location, filters, and publishableKey as the list (queryListings / usePublicSearch). Dropping them pins listings outside the active query or spends the anonymous listings budget. Cost: every viewport change is a search call \u2014 keep the debounce, do not raise the page size, and do not call travel time or Street View inside that loop.`;
|
|
3065
|
+
}
|
|
2845
3066
|
function marketExportsAvailableAt(pin) {
|
|
2846
3067
|
return compareSemver(pin, STUDIO_SDK_CONTRACT.marketExportsSince) >= 0;
|
|
2847
3068
|
}
|
|
@@ -2892,6 +3113,18 @@ function studioCodegenContractViolations(text) {
|
|
|
2892
3113
|
violations.push(name);
|
|
2893
3114
|
}
|
|
2894
3115
|
}
|
|
3116
|
+
if (!mapsExportsPublished()) {
|
|
3117
|
+
for (const name of STUDIO_SDK_CONTRACT.mapsExports) {
|
|
3118
|
+
if (mentionsExportName(text, name) && !violations.includes(name)) {
|
|
3119
|
+
violations.push(name);
|
|
3120
|
+
}
|
|
3121
|
+
}
|
|
3122
|
+
}
|
|
3123
|
+
for (const name of STUDIO_SDK_CONTRACT.unpublishedPhotoExports) {
|
|
3124
|
+
if (mentionsExportName(text, name) && !violations.includes(name)) {
|
|
3125
|
+
violations.push(name);
|
|
3126
|
+
}
|
|
3127
|
+
}
|
|
2895
3128
|
if (!isPhotoSearchOnPin()) {
|
|
2896
3129
|
for (const name of STUDIO_SDK_CONTRACT.photoSearchExports) {
|
|
2897
3130
|
if (mentionsExportName(text, name) && !violations.includes(name)) {
|
|
@@ -2941,6 +3174,9 @@ function createGaragemClient(options = {}) {
|
|
|
2941
3174
|
const out = { ...opts };
|
|
2942
3175
|
if (options.baseUrl !== void 0) out.baseUrl = options.baseUrl;
|
|
2943
3176
|
if (options.fetch !== void 0) out.fetch = options.fetch;
|
|
3177
|
+
if (options.publishableKey !== void 0 && out.publishableKey === void 0) {
|
|
3178
|
+
out.publishableKey = options.publishableKey;
|
|
3179
|
+
}
|
|
2944
3180
|
return out;
|
|
2945
3181
|
};
|
|
2946
3182
|
return {
|
|
@@ -2969,6 +3205,9 @@ function createGaragemClient(options = {}) {
|
|
|
2969
3205
|
if (domain !== void 0) opts.domain = domain;
|
|
2970
3206
|
if (options.baseUrl !== void 0) opts.baseUrl = options.baseUrl;
|
|
2971
3207
|
if (options.fetch !== void 0) opts.fetch = options.fetch;
|
|
3208
|
+
if (options.publishableKey !== void 0) {
|
|
3209
|
+
opts.publishableKey = options.publishableKey;
|
|
3210
|
+
}
|
|
2972
3211
|
const merged = mergeNext(next);
|
|
2973
3212
|
if (merged !== void 0) opts.next = merged;
|
|
2974
3213
|
return getSite(opts);
|
|
@@ -3077,6 +3316,917 @@ function createGaragemClient(options = {}) {
|
|
|
3077
3316
|
}
|
|
3078
3317
|
};
|
|
3079
3318
|
}
|
|
3319
|
+
var createClient = createGaragemClient;
|
|
3320
|
+
|
|
3321
|
+
// src/maps.ts
|
|
3322
|
+
var DEFAULT_MAPS_BASE_URL = "https://maps.fndn.ai";
|
|
3323
|
+
var MAPS_SITE_HEADER = "X-Garagem-Site";
|
|
3324
|
+
var MAPS_MAX_IMAGE_EDGE = 640;
|
|
3325
|
+
var TRAVEL_MODES = /* @__PURE__ */ new Set([
|
|
3326
|
+
"driving",
|
|
3327
|
+
"walking",
|
|
3328
|
+
"bicycling",
|
|
3329
|
+
"transit"
|
|
3330
|
+
]);
|
|
3331
|
+
function finite(value) {
|
|
3332
|
+
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
3333
|
+
}
|
|
3334
|
+
function listingCoordinates(listing) {
|
|
3335
|
+
const raw = listing?.location?.coordinates;
|
|
3336
|
+
const lat = finite(raw?.lat);
|
|
3337
|
+
const lng = finite(raw?.lng);
|
|
3338
|
+
if (lat == null || lng == null) return null;
|
|
3339
|
+
if (lat === 0 && lng === 0) return null;
|
|
3340
|
+
if (Math.abs(lat) > 90 || Math.abs(lng) > 180) return null;
|
|
3341
|
+
return { lat, lng };
|
|
3342
|
+
}
|
|
3343
|
+
function coordinateDecimals(value) {
|
|
3344
|
+
if (!Number.isFinite(value)) return 0;
|
|
3345
|
+
const text = Math.abs(value).toString();
|
|
3346
|
+
if (text.includes("e")) {
|
|
3347
|
+
const fixed = Math.abs(value).toFixed(12).replace(/0+$/, "");
|
|
3348
|
+
const dot2 = fixed.indexOf(".");
|
|
3349
|
+
return dot2 === -1 ? 0 : fixed.length - dot2 - 1;
|
|
3350
|
+
}
|
|
3351
|
+
const dot = text.indexOf(".");
|
|
3352
|
+
return dot === -1 ? 0 : text.length - dot - 1;
|
|
3353
|
+
}
|
|
3354
|
+
function roundTo(value, decimals) {
|
|
3355
|
+
const factor = 10 ** decimals;
|
|
3356
|
+
return Math.round(value * factor) / factor;
|
|
3357
|
+
}
|
|
3358
|
+
function coarsenCoordinates(coordinates, maxDecimals) {
|
|
3359
|
+
if (maxDecimals == null || !Number.isFinite(maxDecimals)) return coordinates;
|
|
3360
|
+
const limit = Math.max(0, Math.floor(maxDecimals));
|
|
3361
|
+
return {
|
|
3362
|
+
lat: coordinateDecimals(coordinates.lat) > limit ? roundTo(coordinates.lat, limit) : coordinates.lat,
|
|
3363
|
+
lng: coordinateDecimals(coordinates.lng) > limit ? roundTo(coordinates.lng, limit) : coordinates.lng
|
|
3364
|
+
};
|
|
3365
|
+
}
|
|
3366
|
+
function maxZoomForCoordinates(coordinates) {
|
|
3367
|
+
const decimals = Math.min(
|
|
3368
|
+
coordinateDecimals(coordinates.lat),
|
|
3369
|
+
coordinateDecimals(coordinates.lng)
|
|
3370
|
+
);
|
|
3371
|
+
if (decimals >= 4) return 21;
|
|
3372
|
+
if (decimals === 3) return 16;
|
|
3373
|
+
if (decimals === 2) return 13;
|
|
3374
|
+
return 11;
|
|
3375
|
+
}
|
|
3376
|
+
function clampInt(value, fallback, min, max) {
|
|
3377
|
+
if (value == null || !Number.isFinite(value)) return fallback;
|
|
3378
|
+
return Math.min(max, Math.max(min, Math.round(value)));
|
|
3379
|
+
}
|
|
3380
|
+
function normalizeMapsBaseUrl(baseUrl) {
|
|
3381
|
+
const raw = (baseUrl ?? "").trim();
|
|
3382
|
+
if (!raw) return DEFAULT_MAPS_BASE_URL;
|
|
3383
|
+
return raw.replace(/\/+$/, "") || DEFAULT_MAPS_BASE_URL;
|
|
3384
|
+
}
|
|
3385
|
+
function siteTag(options) {
|
|
3386
|
+
const value = options?.siteId?.trim();
|
|
3387
|
+
return value ? value : null;
|
|
3388
|
+
}
|
|
3389
|
+
function mapsUrl(path, params, options) {
|
|
3390
|
+
const url = new URL(path, `${normalizeMapsBaseUrl(options?.mapsBaseUrl)}/`);
|
|
3391
|
+
for (const [key, value] of Object.entries(params)) {
|
|
3392
|
+
if (value === void 0 || value === "") continue;
|
|
3393
|
+
url.searchParams.set(key, String(value));
|
|
3394
|
+
}
|
|
3395
|
+
const site = siteTag(options);
|
|
3396
|
+
if (site) url.searchParams.set("site", site);
|
|
3397
|
+
return url.toString();
|
|
3398
|
+
}
|
|
3399
|
+
function resolveFetch(options) {
|
|
3400
|
+
const custom = options?.fetch;
|
|
3401
|
+
if (custom) return custom;
|
|
3402
|
+
const global = globalThis.fetch;
|
|
3403
|
+
if (!global) {
|
|
3404
|
+
throw new TypeError(
|
|
3405
|
+
"Garagem SDK: no fetch available. Pass `fetch` in the options."
|
|
3406
|
+
);
|
|
3407
|
+
}
|
|
3408
|
+
return global;
|
|
3409
|
+
}
|
|
3410
|
+
async function mapsFetchJson(url, options, init) {
|
|
3411
|
+
const headers = new Headers(init?.headers);
|
|
3412
|
+
headers.set("accept", "application/json");
|
|
3413
|
+
const site = siteTag(options);
|
|
3414
|
+
if (site) headers.set(MAPS_SITE_HEADER, site);
|
|
3415
|
+
try {
|
|
3416
|
+
const response = await resolveFetch(options)(url, { ...init, headers });
|
|
3417
|
+
if (!response.ok) return null;
|
|
3418
|
+
return await response.json();
|
|
3419
|
+
} catch {
|
|
3420
|
+
return null;
|
|
3421
|
+
}
|
|
3422
|
+
}
|
|
3423
|
+
function listingStaticMapUrl(listing, options = {}) {
|
|
3424
|
+
const raw = listingCoordinates(listing);
|
|
3425
|
+
if (!raw) return null;
|
|
3426
|
+
const coordinates = coarsenCoordinates(raw, options.maxDecimals);
|
|
3427
|
+
const zoomCeiling = maxZoomForCoordinates(coordinates);
|
|
3428
|
+
const zoom = Math.min(zoomCeiling, clampInt(options.zoom, 15, 1, 21));
|
|
3429
|
+
const markerColor = options.markerColor ?? "red";
|
|
3430
|
+
return mapsUrl(
|
|
3431
|
+
"/v1/static-map",
|
|
3432
|
+
{
|
|
3433
|
+
lat: coordinates.lat,
|
|
3434
|
+
lng: coordinates.lng,
|
|
3435
|
+
zoom,
|
|
3436
|
+
width: clampInt(options.width, 600, 1, MAPS_MAX_IMAGE_EDGE),
|
|
3437
|
+
height: clampInt(options.height, 300, 1, MAPS_MAX_IMAGE_EDGE),
|
|
3438
|
+
scale: options.scale === 1 ? 1 : 2,
|
|
3439
|
+
maptype: options.style,
|
|
3440
|
+
markerColor: markerColor !== "red" ? markerColor : void 0,
|
|
3441
|
+
hidePoi: options.hidePoi ? "1" : void 0
|
|
3442
|
+
},
|
|
3443
|
+
options
|
|
3444
|
+
);
|
|
3445
|
+
}
|
|
3446
|
+
function listingStreetViewUrl(listing, options = {}) {
|
|
3447
|
+
const raw = listingCoordinates(listing);
|
|
3448
|
+
if (!raw) return null;
|
|
3449
|
+
const coordinates = coarsenCoordinates(raw, options.maxDecimals);
|
|
3450
|
+
const width = clampInt(options.width, 640, 1, MAPS_MAX_IMAGE_EDGE);
|
|
3451
|
+
const height = clampInt(options.height, 640, 1, MAPS_MAX_IMAGE_EDGE);
|
|
3452
|
+
return mapsUrl(
|
|
3453
|
+
"/v1/street-view",
|
|
3454
|
+
{
|
|
3455
|
+
lat: coordinates.lat,
|
|
3456
|
+
lng: coordinates.lng,
|
|
3457
|
+
size: `${width}x${height}`,
|
|
3458
|
+
fov: clampInt(options.fov, 90, 10, 120),
|
|
3459
|
+
heading: clampInt(options.heading, 0, 0, 360),
|
|
3460
|
+
pitch: clampInt(options.pitch, 10, -90, 90)
|
|
3461
|
+
},
|
|
3462
|
+
options
|
|
3463
|
+
);
|
|
3464
|
+
}
|
|
3465
|
+
function listingStreetViewMetadataUrl(listing, options = {}) {
|
|
3466
|
+
const raw = listingCoordinates(listing);
|
|
3467
|
+
if (!raw) return null;
|
|
3468
|
+
const coordinates = coarsenCoordinates(raw, options.maxDecimals);
|
|
3469
|
+
return mapsUrl(
|
|
3470
|
+
"/v1/street-view/metadata",
|
|
3471
|
+
{ lat: coordinates.lat, lng: coordinates.lng },
|
|
3472
|
+
options
|
|
3473
|
+
);
|
|
3474
|
+
}
|
|
3475
|
+
async function listingStreetViewAvailable(listing, options = {}) {
|
|
3476
|
+
const url = listingStreetViewMetadataUrl(listing, options);
|
|
3477
|
+
if (!url) {
|
|
3478
|
+
return { available: false, status: "NO_COORDINATES", url: "" };
|
|
3479
|
+
}
|
|
3480
|
+
const data = await mapsFetchJson(url, options);
|
|
3481
|
+
const status = typeof data?.status === "string" ? data.status : "ERROR";
|
|
3482
|
+
const result = {
|
|
3483
|
+
available: status === "OK",
|
|
3484
|
+
status,
|
|
3485
|
+
url
|
|
3486
|
+
};
|
|
3487
|
+
if (typeof data?.pano_id === "string") result.panoId = data.pano_id;
|
|
3488
|
+
if (typeof data?.date === "string") result.date = data.date;
|
|
3489
|
+
return result;
|
|
3490
|
+
}
|
|
3491
|
+
function boundaryCitySlug(city) {
|
|
3492
|
+
return city.normalize("NFD").replace(/[̀-ͯ]/g, "").toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "");
|
|
3493
|
+
}
|
|
3494
|
+
function boundaryLayerId(city) {
|
|
3495
|
+
const slug = boundaryCitySlug(city);
|
|
3496
|
+
return slug.endsWith("_boundaries") ? slug : `${slug}_boundaries`;
|
|
3497
|
+
}
|
|
3498
|
+
function boundaryLayerUrl(city, options = {}) {
|
|
3499
|
+
const base = normalizeMapsBaseUrl(options.mapsBaseUrl);
|
|
3500
|
+
const id = boundaryLayerId(city);
|
|
3501
|
+
const slug = id.replace(/_boundaries$/, "");
|
|
3502
|
+
switch (options.kind ?? "tilejson") {
|
|
3503
|
+
case "layer":
|
|
3504
|
+
return `${base}/v1/layers/${id}`;
|
|
3505
|
+
case "tiles":
|
|
3506
|
+
return `${base}/martin/${id}/{z}/{x}/{y}`;
|
|
3507
|
+
case "geojson":
|
|
3508
|
+
return `${base}/api/boundaries/${slug}`;
|
|
3509
|
+
default:
|
|
3510
|
+
return `${base}/martin/${id}`;
|
|
3511
|
+
}
|
|
3512
|
+
}
|
|
3513
|
+
function neighborhoodBoundaryUrl(city, neighborhood, options = {}) {
|
|
3514
|
+
const base = normalizeMapsBaseUrl(options.mapsBaseUrl);
|
|
3515
|
+
const slug = boundaryLayerId(city).replace(/_boundaries$/, "");
|
|
3516
|
+
const url = new URL(
|
|
3517
|
+
`${base}/api/boundaries/${slug}/${encodeURIComponent(neighborhood.trim())}`
|
|
3518
|
+
);
|
|
3519
|
+
if (options.source && options.source !== "listaaberta") {
|
|
3520
|
+
url.searchParams.set("source", options.source);
|
|
3521
|
+
}
|
|
3522
|
+
return url.toString();
|
|
3523
|
+
}
|
|
3524
|
+
function asNumber(value, fallback) {
|
|
3525
|
+
return typeof value === "number" && Number.isFinite(value) ? value : fallback;
|
|
3526
|
+
}
|
|
3527
|
+
async function getBoundaryLayer(city, options = {}) {
|
|
3528
|
+
const data = await mapsFetchJson(
|
|
3529
|
+
boundaryLayerUrl(city, { ...options, kind: "layer" }),
|
|
3530
|
+
options
|
|
3531
|
+
);
|
|
3532
|
+
const layer = data?.layer;
|
|
3533
|
+
if (!data?.ok || !layer || typeof layer.id !== "string") return null;
|
|
3534
|
+
const rawSourceLayers = Array.isArray(layer.source_layers) ? layer.source_layers : [];
|
|
3535
|
+
return {
|
|
3536
|
+
id: layer.id,
|
|
3537
|
+
name: typeof layer.name === "string" ? layer.name : layer.id,
|
|
3538
|
+
description: typeof layer.description === "string" ? layer.description : "",
|
|
3539
|
+
city: typeof layer.city === "string" ? layer.city : void 0,
|
|
3540
|
+
tiles: typeof layer.tiles === "string" ? layer.tiles : "",
|
|
3541
|
+
tilejson: typeof layer.tilejson === "string" ? layer.tilejson : "",
|
|
3542
|
+
geojson: typeof layer.geojson === "string" ? layer.geojson : void 0,
|
|
3543
|
+
sourceLayers: rawSourceLayers.filter(
|
|
3544
|
+
(entry) => !!entry && typeof entry === "object"
|
|
3545
|
+
).map((entry) => ({
|
|
3546
|
+
id: String(entry.id ?? ""),
|
|
3547
|
+
label: String(entry.label ?? entry.id ?? ""),
|
|
3548
|
+
minzoom: typeof entry.minzoom === "number" ? entry.minzoom : void 0,
|
|
3549
|
+
maxzoom: typeof entry.maxzoom === "number" ? entry.maxzoom : void 0
|
|
3550
|
+
})),
|
|
3551
|
+
minzoom: asNumber(layer.minzoom, 0),
|
|
3552
|
+
maxzoom: asNumber(layer.maxzoom, 14),
|
|
3553
|
+
attribution: typeof layer.attribution === "string" ? layer.attribution : void 0,
|
|
3554
|
+
available: layer.available !== false
|
|
3555
|
+
};
|
|
3556
|
+
}
|
|
3557
|
+
function isFeature(value) {
|
|
3558
|
+
return !!value && typeof value === "object" && value.type === "Feature";
|
|
3559
|
+
}
|
|
3560
|
+
async function neighborhoodBoundaryLayer(city, neighborhood, options = {}) {
|
|
3561
|
+
const url = neighborhoodBoundaryUrl(city, neighborhood, options);
|
|
3562
|
+
const slug = boundaryLayerId(city).replace(/_boundaries$/, "");
|
|
3563
|
+
const result = {
|
|
3564
|
+
city: slug,
|
|
3565
|
+
neighborhood: neighborhood.trim(),
|
|
3566
|
+
feature: null,
|
|
3567
|
+
candidates: [],
|
|
3568
|
+
url,
|
|
3569
|
+
tiles: boundaryLayerUrl(city, { ...options, kind: "tiles" })
|
|
3570
|
+
};
|
|
3571
|
+
if (!result.neighborhood) return result;
|
|
3572
|
+
const data = await mapsFetchJson(
|
|
3573
|
+
url,
|
|
3574
|
+
options
|
|
3575
|
+
);
|
|
3576
|
+
if (!data) return result;
|
|
3577
|
+
if (isFeature(data)) {
|
|
3578
|
+
result.feature = data;
|
|
3579
|
+
result.candidates = [data];
|
|
3580
|
+
return result;
|
|
3581
|
+
}
|
|
3582
|
+
const features = Array.isArray(data.features) ? data.features.filter(isFeature) : [];
|
|
3583
|
+
result.candidates = features;
|
|
3584
|
+
const wanted = result.neighborhood.toLocaleLowerCase("pt-BR");
|
|
3585
|
+
result.feature = features.find(
|
|
3586
|
+
(feature) => typeof feature.properties?.name === "string" && feature.properties.name.toLocaleLowerCase("pt-BR") === wanted
|
|
3587
|
+
) ?? (features.length === 1 ? features[0] : null);
|
|
3588
|
+
return result;
|
|
3589
|
+
}
|
|
3590
|
+
function createTravelTimeCache(options = {}) {
|
|
3591
|
+
const maxEntries = Math.max(1, Math.floor(options.maxEntries ?? 200));
|
|
3592
|
+
const ttlMs = Math.max(0, options.ttlMs ?? 15 * 60 * 1e3);
|
|
3593
|
+
const entries = /* @__PURE__ */ new Map();
|
|
3594
|
+
return {
|
|
3595
|
+
get(key) {
|
|
3596
|
+
const hit = entries.get(key);
|
|
3597
|
+
if (!hit) return void 0;
|
|
3598
|
+
if (hit.expiresAt <= Date.now()) {
|
|
3599
|
+
entries.delete(key);
|
|
3600
|
+
return void 0;
|
|
3601
|
+
}
|
|
3602
|
+
entries.delete(key);
|
|
3603
|
+
entries.set(key, hit);
|
|
3604
|
+
return hit.value;
|
|
3605
|
+
},
|
|
3606
|
+
set(key, value) {
|
|
3607
|
+
entries.delete(key);
|
|
3608
|
+
entries.set(key, { value, expiresAt: Date.now() + ttlMs });
|
|
3609
|
+
while (entries.size > maxEntries) {
|
|
3610
|
+
const oldest = entries.keys().next().value;
|
|
3611
|
+
if (oldest === void 0) break;
|
|
3612
|
+
entries.delete(oldest);
|
|
3613
|
+
}
|
|
3614
|
+
},
|
|
3615
|
+
clear() {
|
|
3616
|
+
entries.clear();
|
|
3617
|
+
},
|
|
3618
|
+
get size() {
|
|
3619
|
+
return entries.size;
|
|
3620
|
+
}
|
|
3621
|
+
};
|
|
3622
|
+
}
|
|
3623
|
+
var defaultTravelTimeCache = createTravelTimeCache();
|
|
3624
|
+
function clearTravelTimeCache() {
|
|
3625
|
+
defaultTravelTimeCache.clear();
|
|
3626
|
+
}
|
|
3627
|
+
function travelTimeCacheKey(origin, destination, mode) {
|
|
3628
|
+
return `${origin.lat},${origin.lng}|${destination.lat},${destination.lng}|${mode}`;
|
|
3629
|
+
}
|
|
3630
|
+
function travelTimeQueryCacheKey(origin, query, mode) {
|
|
3631
|
+
return `${origin.lat},${origin.lng}|q:${query}|${mode}`;
|
|
3632
|
+
}
|
|
3633
|
+
function trimmedDestinationQuery(destination) {
|
|
3634
|
+
if (typeof destination !== "string") return null;
|
|
3635
|
+
const query = destination.trim();
|
|
3636
|
+
return query ? query : null;
|
|
3637
|
+
}
|
|
3638
|
+
function recallTravelTime(cache, key) {
|
|
3639
|
+
if (!cache) return null;
|
|
3640
|
+
const hit = cache.get(key);
|
|
3641
|
+
return hit ? { ...hit, cached: true } : null;
|
|
3642
|
+
}
|
|
3643
|
+
function rememberTravelTime(cache, keys, value) {
|
|
3644
|
+
if (!cache) return;
|
|
3645
|
+
for (const key of keys) cache.set(key, value);
|
|
3646
|
+
}
|
|
3647
|
+
function normalizeMode(mode) {
|
|
3648
|
+
return mode && TRAVEL_MODES.has(mode) ? mode : "driving";
|
|
3649
|
+
}
|
|
3650
|
+
async function resolveTravelDestination(destination, options = {}) {
|
|
3651
|
+
if (typeof destination !== "string") {
|
|
3652
|
+
const lat2 = finite(destination?.lat);
|
|
3653
|
+
const lng2 = finite(destination?.lng);
|
|
3654
|
+
return lat2 == null || lng2 == null ? null : { lat: lat2, lng: lng2 };
|
|
3655
|
+
}
|
|
3656
|
+
const query = destination.trim();
|
|
3657
|
+
if (!query) return null;
|
|
3658
|
+
const data = await mapsFetchJson(
|
|
3659
|
+
mapsUrl("/v1/geocode", { q: query }, options),
|
|
3660
|
+
options
|
|
3661
|
+
);
|
|
3662
|
+
const lat = finite(data?.latitude);
|
|
3663
|
+
const lng = finite(data?.longitude);
|
|
3664
|
+
if (!data?.ok || lat == null || lng == null) return null;
|
|
3665
|
+
return { lat, lng };
|
|
3666
|
+
}
|
|
3667
|
+
function minutesFromSeconds(seconds) {
|
|
3668
|
+
return Math.max(1, Math.round(seconds / 60));
|
|
3669
|
+
}
|
|
3670
|
+
async function travelTimeFromListing(listing, destination, options = {}) {
|
|
3671
|
+
const raw = listingCoordinates(listing);
|
|
3672
|
+
if (!raw) return null;
|
|
3673
|
+
const origin = coarsenCoordinates(raw, options.maxDecimals);
|
|
3674
|
+
const mode = normalizeMode(options.mode);
|
|
3675
|
+
const cache = options.cache === void 0 ? defaultTravelTimeCache : options.cache;
|
|
3676
|
+
const query = trimmedDestinationQuery(destination);
|
|
3677
|
+
if (typeof destination === "string" && !query) return null;
|
|
3678
|
+
if (query) {
|
|
3679
|
+
const queryHit = recallTravelTime(
|
|
3680
|
+
cache,
|
|
3681
|
+
travelTimeQueryCacheKey(origin, query, mode)
|
|
3682
|
+
);
|
|
3683
|
+
if (queryHit) return queryHit;
|
|
3684
|
+
}
|
|
3685
|
+
const target = await resolveTravelDestination(query ?? destination, options);
|
|
3686
|
+
if (!target) return null;
|
|
3687
|
+
const coordKey = travelTimeCacheKey(origin, target, mode);
|
|
3688
|
+
const stored = cache?.get(coordKey);
|
|
3689
|
+
if (stored) {
|
|
3690
|
+
if (query) {
|
|
3691
|
+
rememberTravelTime(
|
|
3692
|
+
cache,
|
|
3693
|
+
[travelTimeQueryCacheKey(origin, query, mode)],
|
|
3694
|
+
stored
|
|
3695
|
+
);
|
|
3696
|
+
}
|
|
3697
|
+
return { ...stored, cached: true };
|
|
3698
|
+
}
|
|
3699
|
+
const data = await mapsFetchJson(
|
|
3700
|
+
mapsUrl(
|
|
3701
|
+
"/v1/directions",
|
|
3702
|
+
{
|
|
3703
|
+
origin: `${origin.lat},${origin.lng}`,
|
|
3704
|
+
destination: `${target.lat},${target.lng}`,
|
|
3705
|
+
mode
|
|
3706
|
+
},
|
|
3707
|
+
options
|
|
3708
|
+
),
|
|
3709
|
+
options
|
|
3710
|
+
);
|
|
3711
|
+
const seconds = finite(data?.route?.totalTravelTime);
|
|
3712
|
+
const meters = finite(data?.route?.totalDistance);
|
|
3713
|
+
if (!data?.ok || seconds == null || meters == null) return null;
|
|
3714
|
+
const result = {
|
|
3715
|
+
minutes: minutesFromSeconds(seconds),
|
|
3716
|
+
seconds,
|
|
3717
|
+
distanceMeters: meters,
|
|
3718
|
+
distanceKm: Math.round(meters / 100) / 10,
|
|
3719
|
+
mode,
|
|
3720
|
+
origin,
|
|
3721
|
+
destination: target,
|
|
3722
|
+
cached: false
|
|
3723
|
+
};
|
|
3724
|
+
const keys = query ? [coordKey, travelTimeQueryCacheKey(origin, query, mode)] : [coordKey];
|
|
3725
|
+
rememberTravelTime(cache, keys, result);
|
|
3726
|
+
return result;
|
|
3727
|
+
}
|
|
3728
|
+
async function travelTimesFromListing(listing, destinations, options = {}) {
|
|
3729
|
+
const raw = listingCoordinates(listing);
|
|
3730
|
+
if (!raw) return null;
|
|
3731
|
+
const origin = coarsenCoordinates(raw, options.maxDecimals);
|
|
3732
|
+
const targets = destinations.map((destination) => {
|
|
3733
|
+
const lat = finite(destination?.lat);
|
|
3734
|
+
const lng = finite(destination?.lng);
|
|
3735
|
+
return lat == null || lng == null ? null : { lat, lng };
|
|
3736
|
+
}).filter((item) => item !== null);
|
|
3737
|
+
if (targets.length === 0) return [];
|
|
3738
|
+
const data = await mapsFetchJson(
|
|
3739
|
+
mapsUrl("/v1/route-matrix", {}, options),
|
|
3740
|
+
options,
|
|
3741
|
+
{
|
|
3742
|
+
method: "POST",
|
|
3743
|
+
headers: { "content-type": "application/json" },
|
|
3744
|
+
body: JSON.stringify({ origin, destinations: targets })
|
|
3745
|
+
}
|
|
3746
|
+
);
|
|
3747
|
+
if (!data?.ok || !Array.isArray(data.durations)) return null;
|
|
3748
|
+
return targets.map((destination, index) => {
|
|
3749
|
+
const seconds = finite(
|
|
3750
|
+
data.durations && data.durations[index]
|
|
3751
|
+
);
|
|
3752
|
+
if (seconds == null) return null;
|
|
3753
|
+
return { minutes: minutesFromSeconds(seconds), seconds, destination };
|
|
3754
|
+
});
|
|
3755
|
+
}
|
|
3756
|
+
|
|
3757
|
+
// src/map-search.ts
|
|
3758
|
+
var MAP_SEARCH_MAX_PAGE_SIZE = 100;
|
|
3759
|
+
var MAP_SEARCH_DEFAULT_PAGE_SIZE = 100;
|
|
3760
|
+
var MAP_SEARCH_MAX_PAGE = 1e4;
|
|
3761
|
+
var MAP_VIEWPORT_DEBOUNCE_MS = 400;
|
|
3762
|
+
var MAP_POLYGON_MAX_VERTICES = 64;
|
|
3763
|
+
function capMapPageSize(value) {
|
|
3764
|
+
if (value == null || !Number.isFinite(value) || value <= 0) {
|
|
3765
|
+
return MAP_SEARCH_DEFAULT_PAGE_SIZE;
|
|
3766
|
+
}
|
|
3767
|
+
return Math.min(MAP_SEARCH_MAX_PAGE_SIZE, Math.floor(value));
|
|
3768
|
+
}
|
|
3769
|
+
function capMapPage(value) {
|
|
3770
|
+
if (value == null || !Number.isFinite(value) || value <= 1) return 1;
|
|
3771
|
+
return Math.min(MAP_SEARCH_MAX_PAGE, Math.floor(value));
|
|
3772
|
+
}
|
|
3773
|
+
function finitePair(lat, lng) {
|
|
3774
|
+
if (typeof lat !== "number" || typeof lng !== "number") return null;
|
|
3775
|
+
if (!Number.isFinite(lat) || !Number.isFinite(lng)) return null;
|
|
3776
|
+
if (lat < -90 || lat > 90 || lng < -180 || lng > 180) return null;
|
|
3777
|
+
return [lat, lng];
|
|
3778
|
+
}
|
|
3779
|
+
function isMapBounds(bounds) {
|
|
3780
|
+
if (!bounds) return false;
|
|
3781
|
+
const north = finitePair(bounds.north, bounds.east);
|
|
3782
|
+
const south = finitePair(bounds.south, bounds.west);
|
|
3783
|
+
if (!north || !south) return false;
|
|
3784
|
+
return bounds.north > bounds.south && bounds.east > bounds.west;
|
|
3785
|
+
}
|
|
3786
|
+
function isMapPolygon(polygon) {
|
|
3787
|
+
if (!Array.isArray(polygon)) return false;
|
|
3788
|
+
if (polygon.length < 3 || polygon.length > MAP_POLYGON_MAX_VERTICES + 1) {
|
|
3789
|
+
return false;
|
|
3790
|
+
}
|
|
3791
|
+
let unique = 0;
|
|
3792
|
+
let prev = null;
|
|
3793
|
+
for (const point of polygon) {
|
|
3794
|
+
if (!Array.isArray(point)) return false;
|
|
3795
|
+
const pair = finitePair(point[0], point[1]);
|
|
3796
|
+
if (!pair) return false;
|
|
3797
|
+
if (prev && prev[0] === pair[0] && prev[1] === pair[1]) continue;
|
|
3798
|
+
prev = pair;
|
|
3799
|
+
unique += 1;
|
|
3800
|
+
}
|
|
3801
|
+
if (unique >= 2 && polygon.length >= 2) {
|
|
3802
|
+
const first = finitePair(polygon[0]?.[0], polygon[0]?.[1]);
|
|
3803
|
+
const last = finitePair(
|
|
3804
|
+
polygon[polygon.length - 1]?.[0],
|
|
3805
|
+
polygon[polygon.length - 1]?.[1]
|
|
3806
|
+
);
|
|
3807
|
+
if (first && last && first[0] === last[0] && first[1] === last[1] && unique > 1) {
|
|
3808
|
+
unique -= 1;
|
|
3809
|
+
}
|
|
3810
|
+
}
|
|
3811
|
+
return unique >= 3 && unique <= MAP_POLYGON_MAX_VERTICES;
|
|
3812
|
+
}
|
|
3813
|
+
function mapSearchPins(listings) {
|
|
3814
|
+
const pins = [];
|
|
3815
|
+
for (const listing of listings) {
|
|
3816
|
+
const coords = listingCoordinates(listing);
|
|
3817
|
+
if (!coords || !listing.id) continue;
|
|
3818
|
+
const src = listing.coverImage?.src;
|
|
3819
|
+
pins.push({
|
|
3820
|
+
id: listing.id,
|
|
3821
|
+
lat: coords.lat,
|
|
3822
|
+
lng: coords.lng,
|
|
3823
|
+
price: listing.price ?? null,
|
|
3824
|
+
coverImage: src ? src : null
|
|
3825
|
+
});
|
|
3826
|
+
}
|
|
3827
|
+
return pins;
|
|
3828
|
+
}
|
|
3829
|
+
function listingsResult(listings, meta, requestedPageSize) {
|
|
3830
|
+
return {
|
|
3831
|
+
pins: mapSearchPins(listings),
|
|
3832
|
+
cards: listings.map((listing) => toListingCardModel(listing)),
|
|
3833
|
+
listings,
|
|
3834
|
+
page: meta.page ?? 1,
|
|
3835
|
+
pageSize: meta.limit ?? requestedPageSize,
|
|
3836
|
+
total: meta.total ?? listings.length,
|
|
3837
|
+
totalPages: meta.totalPages ?? 0
|
|
3838
|
+
};
|
|
3839
|
+
}
|
|
3840
|
+
function searchParams(area, options) {
|
|
3841
|
+
const params = {
|
|
3842
|
+
page: capMapPage(options.page),
|
|
3843
|
+
limit: capMapPageSize(options.pageSize)
|
|
3844
|
+
};
|
|
3845
|
+
if (options.q !== void 0) params.q = options.q;
|
|
3846
|
+
if (options.sort !== void 0) params.sort = options.sort;
|
|
3847
|
+
if (options.location !== void 0) params.location = options.location;
|
|
3848
|
+
if (options.filters) params.filters = options.filters;
|
|
3849
|
+
if (area.polygon) params.polygon = area.polygon;
|
|
3850
|
+
else if (area.bounds) params.bounds = area.bounds;
|
|
3851
|
+
return params;
|
|
3852
|
+
}
|
|
3853
|
+
async function runMapSearch(siteId, area, options) {
|
|
3854
|
+
const pageSize = capMapPageSize(options.pageSize);
|
|
3855
|
+
const result = await queryListings({
|
|
3856
|
+
siteId,
|
|
3857
|
+
params: searchParams(area, options),
|
|
3858
|
+
baseUrl: options.baseUrl,
|
|
3859
|
+
fetch: options.fetch,
|
|
3860
|
+
signal: options.signal,
|
|
3861
|
+
publishableKey: options.publishableKey,
|
|
3862
|
+
next: options.next
|
|
3863
|
+
});
|
|
3864
|
+
return listingsResult(result.listings ?? [], result, pageSize);
|
|
3865
|
+
}
|
|
3866
|
+
async function searchListingsInBounds(siteId, options) {
|
|
3867
|
+
if (!isMapBounds(options.bounds)) {
|
|
3868
|
+
throw new TypeError(
|
|
3869
|
+
"searchListingsInBounds: bounds must be a finite rectangle with north > south and east > west (no antimeridian)."
|
|
3870
|
+
);
|
|
3871
|
+
}
|
|
3872
|
+
return runMapSearch(siteId, { bounds: options.bounds }, options);
|
|
3873
|
+
}
|
|
3874
|
+
async function searchListingsInPolygon(siteId, options) {
|
|
3875
|
+
if (!isMapPolygon(options.polygon)) {
|
|
3876
|
+
throw new TypeError(
|
|
3877
|
+
`searchListingsInPolygon: polygon must be 3\u2013${MAP_POLYGON_MAX_VERTICES} finite [lat, lng] points.`
|
|
3878
|
+
);
|
|
3879
|
+
}
|
|
3880
|
+
return runMapSearch(siteId, { polygon: options.polygon }, options);
|
|
3881
|
+
}
|
|
3882
|
+
function clampZoom(zoom) {
|
|
3883
|
+
if (!Number.isFinite(zoom)) return 0;
|
|
3884
|
+
return Math.min(22, Math.max(0, zoom));
|
|
3885
|
+
}
|
|
3886
|
+
function mapClusterCellDegrees(zoom) {
|
|
3887
|
+
return 360 / 2 ** clampZoom(zoom) / 4;
|
|
3888
|
+
}
|
|
3889
|
+
function usablePin(pin) {
|
|
3890
|
+
return finitePair(pin.lat, pin.lng) !== null && !(pin.lat === 0 && pin.lng === 0);
|
|
3891
|
+
}
|
|
3892
|
+
function groupPrecision(group) {
|
|
3893
|
+
let min = 12;
|
|
3894
|
+
for (const pin of group) {
|
|
3895
|
+
min = Math.min(
|
|
3896
|
+
min,
|
|
3897
|
+
coordinateDecimals(pin.lat),
|
|
3898
|
+
coordinateDecimals(pin.lng)
|
|
3899
|
+
);
|
|
3900
|
+
}
|
|
3901
|
+
return min;
|
|
3902
|
+
}
|
|
3903
|
+
function multiCluster(key, group) {
|
|
3904
|
+
const lat = group.reduce((sum, pin) => sum + pin.lat, 0) / group.length;
|
|
3905
|
+
const lng = group.reduce((sum, pin) => sum + pin.lng, 0) / group.length;
|
|
3906
|
+
const center = coarsenCoordinates({ lat, lng }, groupPrecision(group));
|
|
3907
|
+
return {
|
|
3908
|
+
id: key,
|
|
3909
|
+
lat: center.lat,
|
|
3910
|
+
lng: center.lng,
|
|
3911
|
+
count: group.length,
|
|
3912
|
+
pinIds: group.map((pin) => pin.id),
|
|
3913
|
+
pin: null
|
|
3914
|
+
};
|
|
3915
|
+
}
|
|
3916
|
+
function singleCluster(pin) {
|
|
3917
|
+
return {
|
|
3918
|
+
id: pin.id,
|
|
3919
|
+
lat: pin.lat,
|
|
3920
|
+
lng: pin.lng,
|
|
3921
|
+
count: 1,
|
|
3922
|
+
pinIds: [pin.id],
|
|
3923
|
+
pin
|
|
3924
|
+
};
|
|
3925
|
+
}
|
|
3926
|
+
function clusterPins(pins, zoom) {
|
|
3927
|
+
if (pins.length === 0) return [];
|
|
3928
|
+
const cell = mapClusterCellDegrees(zoom);
|
|
3929
|
+
const groups = /* @__PURE__ */ new Map();
|
|
3930
|
+
for (const pin of pins) {
|
|
3931
|
+
if (!usablePin(pin)) continue;
|
|
3932
|
+
const key = `${Math.floor(pin.lat / cell)}:${Math.floor(pin.lng / cell)}`;
|
|
3933
|
+
const list = groups.get(key);
|
|
3934
|
+
if (list) list.push(pin);
|
|
3935
|
+
else groups.set(key, [pin]);
|
|
3936
|
+
}
|
|
3937
|
+
const clusters = [];
|
|
3938
|
+
for (const [key, group] of groups) {
|
|
3939
|
+
const only = group[0];
|
|
3940
|
+
clusters.push(
|
|
3941
|
+
group.length === 1 && only ? singleCluster(only) : multiCluster(key, group)
|
|
3942
|
+
);
|
|
3943
|
+
}
|
|
3944
|
+
clusters.sort((a, b) => a.id.localeCompare(b.id));
|
|
3945
|
+
return clusters;
|
|
3946
|
+
}
|
|
3947
|
+
|
|
3948
|
+
// src/fetchers-photos.ts
|
|
3949
|
+
var MEDIA_UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
3950
|
+
var HIDDEN_SIMILAR_PHOTOS = {
|
|
3951
|
+
available: false,
|
|
3952
|
+
items: []
|
|
3953
|
+
};
|
|
3954
|
+
async function getSimilarByPhoto(siteId, listingId, mediaId, options = {}) {
|
|
3955
|
+
const { baseUrl, fetch: fetchImpl, next, limit } = options;
|
|
3956
|
+
const resolvedSiteId = await coerceSiteId(siteId);
|
|
3957
|
+
const lookupId = listingLookupKey(listingId ?? "");
|
|
3958
|
+
if (!lookupId || lookupId === "undefined" || lookupId === "null") {
|
|
3959
|
+
throw new TypeError("getSimilarByPhoto: `listingId` is required");
|
|
3960
|
+
}
|
|
3961
|
+
const photoId = typeof mediaId === "string" ? mediaId.trim() : "";
|
|
3962
|
+
if (!photoId) {
|
|
3963
|
+
throw new TypeError("getSimilarByPhoto: `mediaId` is required");
|
|
3964
|
+
}
|
|
3965
|
+
if (!MEDIA_UUID_RE.test(photoId)) {
|
|
3966
|
+
return HIDDEN_SIMILAR_PHOTOS;
|
|
3967
|
+
}
|
|
3968
|
+
const base = normalizeBaseUrl(baseUrl);
|
|
3969
|
+
const params = new URLSearchParams({ mediaId: photoId });
|
|
3970
|
+
if (typeof limit === "number" && Number.isFinite(limit) && limit > 0) {
|
|
3971
|
+
params.set("limit", String(Math.floor(limit)));
|
|
3972
|
+
}
|
|
3973
|
+
const url = `${base}/api/sites/${encodeURIComponent(resolvedSiteId)}/listings/${encodeURIComponent(
|
|
3974
|
+
lookupId
|
|
3975
|
+
)}/similar-photos?${params.toString()}`;
|
|
3976
|
+
const data = await callJson(
|
|
3977
|
+
url,
|
|
3978
|
+
{ method: "GET", headers: { Accept: "application/json" }, next },
|
|
3979
|
+
fetchImpl ?? fetch
|
|
3980
|
+
);
|
|
3981
|
+
return {
|
|
3982
|
+
available: data.available !== false,
|
|
3983
|
+
items: Array.isArray(data.items) ? data.items : []
|
|
3984
|
+
};
|
|
3985
|
+
}
|
|
3986
|
+
|
|
3987
|
+
// src/listing-photos.ts
|
|
3988
|
+
var PHOTO_GROUP_OTHER_KEY = "outros";
|
|
3989
|
+
var PHOTO_GROUP_OTHER_LABEL = "Outras fotos";
|
|
3990
|
+
function normalizeRoomLabel(value) {
|
|
3991
|
+
return value.normalize("NFD").replace(/[̀-ͯ]/g, "").toLowerCase().replace(/[^a-z0-9]+/g, " ").trim();
|
|
3992
|
+
}
|
|
3993
|
+
var ROOM_GROUPS = [
|
|
3994
|
+
{
|
|
3995
|
+
key: "fachada",
|
|
3996
|
+
label: "Fachada",
|
|
3997
|
+
members: [
|
|
3998
|
+
"fachada",
|
|
3999
|
+
"exterior",
|
|
4000
|
+
"frente",
|
|
4001
|
+
"facade",
|
|
4002
|
+
"fachada do predio",
|
|
4003
|
+
"predio",
|
|
4004
|
+
"building exterior",
|
|
4005
|
+
"area externa do predio"
|
|
4006
|
+
]
|
|
4007
|
+
},
|
|
4008
|
+
{
|
|
4009
|
+
key: "sala",
|
|
4010
|
+
label: "Sala",
|
|
4011
|
+
members: [
|
|
4012
|
+
"sala",
|
|
4013
|
+
"sala de estar",
|
|
4014
|
+
"living",
|
|
4015
|
+
"estar",
|
|
4016
|
+
"sala de tv",
|
|
4017
|
+
"living room",
|
|
4018
|
+
"sala de estar e jantar",
|
|
4019
|
+
"sala integrada"
|
|
4020
|
+
]
|
|
4021
|
+
},
|
|
4022
|
+
{
|
|
4023
|
+
key: "sala de jantar",
|
|
4024
|
+
label: "Sala de jantar",
|
|
4025
|
+
members: ["sala de jantar", "jantar", "dining room", "copa jantar"]
|
|
4026
|
+
},
|
|
4027
|
+
{
|
|
4028
|
+
key: "cozinha",
|
|
4029
|
+
label: "Cozinha",
|
|
4030
|
+
members: [
|
|
4031
|
+
"cozinha",
|
|
4032
|
+
"copa",
|
|
4033
|
+
"copa cozinha",
|
|
4034
|
+
"cozinha americana",
|
|
4035
|
+
"kitchen"
|
|
4036
|
+
]
|
|
4037
|
+
},
|
|
4038
|
+
{
|
|
4039
|
+
key: "quarto",
|
|
4040
|
+
label: "Quartos",
|
|
4041
|
+
members: [
|
|
4042
|
+
"quarto",
|
|
4043
|
+
"dormitorio",
|
|
4044
|
+
"suite",
|
|
4045
|
+
"suite master",
|
|
4046
|
+
"quarto de casal",
|
|
4047
|
+
"quarto de solteiro",
|
|
4048
|
+
"quarto infantil",
|
|
4049
|
+
"bedroom",
|
|
4050
|
+
"master bedroom"
|
|
4051
|
+
]
|
|
4052
|
+
},
|
|
4053
|
+
{
|
|
4054
|
+
key: "banheiro",
|
|
4055
|
+
label: "Banheiros",
|
|
4056
|
+
members: [
|
|
4057
|
+
"banheiro",
|
|
4058
|
+
"lavabo",
|
|
4059
|
+
"wc",
|
|
4060
|
+
"toalete",
|
|
4061
|
+
"bathroom",
|
|
4062
|
+
"banheiro social",
|
|
4063
|
+
"banheiro da suite"
|
|
4064
|
+
]
|
|
4065
|
+
},
|
|
4066
|
+
{
|
|
4067
|
+
key: "varanda",
|
|
4068
|
+
label: "Varanda",
|
|
4069
|
+
members: ["varanda", "sacada", "terraco", "balcony", "terrace"]
|
|
4070
|
+
},
|
|
4071
|
+
{
|
|
4072
|
+
key: "area gourmet",
|
|
4073
|
+
label: "\xC1rea gourmet",
|
|
4074
|
+
members: [
|
|
4075
|
+
"area gourmet",
|
|
4076
|
+
"varanda gourmet",
|
|
4077
|
+
"espaco gourmet",
|
|
4078
|
+
"churrasqueira",
|
|
4079
|
+
"gourmet",
|
|
4080
|
+
"terraco gourmet"
|
|
4081
|
+
]
|
|
4082
|
+
},
|
|
4083
|
+
{
|
|
4084
|
+
key: "closet",
|
|
4085
|
+
label: "Closet",
|
|
4086
|
+
members: ["closet", "closet da suite", "walk in closet"]
|
|
4087
|
+
},
|
|
4088
|
+
{
|
|
4089
|
+
key: "escritorio",
|
|
4090
|
+
label: "Escrit\xF3rio",
|
|
4091
|
+
members: ["escritorio", "home office", "office"]
|
|
4092
|
+
},
|
|
4093
|
+
{
|
|
4094
|
+
key: "area de servico",
|
|
4095
|
+
label: "\xC1rea de servi\xE7o",
|
|
4096
|
+
members: ["area de servico", "lavanderia", "laundry", "servico"]
|
|
4097
|
+
},
|
|
4098
|
+
{ key: "despensa", label: "Despensa", members: ["despensa", "pantry"] },
|
|
4099
|
+
{
|
|
4100
|
+
key: "corredor",
|
|
4101
|
+
label: "Corredor",
|
|
4102
|
+
members: ["corredor", "circulacao", "hallway"]
|
|
4103
|
+
},
|
|
4104
|
+
{
|
|
4105
|
+
key: "hall",
|
|
4106
|
+
label: "Hall",
|
|
4107
|
+
members: [
|
|
4108
|
+
"hall",
|
|
4109
|
+
"hall de entrada",
|
|
4110
|
+
"entrada",
|
|
4111
|
+
"recepcao",
|
|
4112
|
+
"lobby",
|
|
4113
|
+
"portaria"
|
|
4114
|
+
]
|
|
4115
|
+
},
|
|
4116
|
+
{
|
|
4117
|
+
key: "garagem",
|
|
4118
|
+
label: "Garagem",
|
|
4119
|
+
members: [
|
|
4120
|
+
"garagem",
|
|
4121
|
+
"vaga",
|
|
4122
|
+
"vagas",
|
|
4123
|
+
"estacionamento",
|
|
4124
|
+
"garage",
|
|
4125
|
+
"vaga de garagem"
|
|
4126
|
+
]
|
|
4127
|
+
},
|
|
4128
|
+
{
|
|
4129
|
+
key: "piscina",
|
|
4130
|
+
label: "Piscina",
|
|
4131
|
+
members: ["piscina", "pool", "piscina do condominio"]
|
|
4132
|
+
},
|
|
4133
|
+
{
|
|
4134
|
+
key: "academia",
|
|
4135
|
+
label: "Academia",
|
|
4136
|
+
members: ["academia", "fitness", "gym", "espaco fitness"]
|
|
4137
|
+
},
|
|
4138
|
+
{
|
|
4139
|
+
key: "salao de festas",
|
|
4140
|
+
label: "Sal\xE3o de festas",
|
|
4141
|
+
members: ["salao de festas", "festas", "salao", "party room"]
|
|
4142
|
+
},
|
|
4143
|
+
{
|
|
4144
|
+
key: "playground",
|
|
4145
|
+
label: "Playground",
|
|
4146
|
+
members: ["playground", "brinquedoteca", "espaco kids"]
|
|
4147
|
+
},
|
|
4148
|
+
{
|
|
4149
|
+
key: "jardim",
|
|
4150
|
+
label: "Jardim",
|
|
4151
|
+
members: ["jardim", "quintal", "area externa", "garden", "backyard"]
|
|
4152
|
+
},
|
|
4153
|
+
{
|
|
4154
|
+
key: "vista",
|
|
4155
|
+
label: "Vista",
|
|
4156
|
+
members: ["vista", "view", "vista da varanda"]
|
|
4157
|
+
},
|
|
4158
|
+
{
|
|
4159
|
+
key: "planta",
|
|
4160
|
+
label: "Planta",
|
|
4161
|
+
members: ["planta", "planta baixa", "floorplan", "floor plan"]
|
|
4162
|
+
}
|
|
4163
|
+
];
|
|
4164
|
+
var GROUP_BY_MEMBER = /* @__PURE__ */ new Map();
|
|
4165
|
+
for (const group of ROOM_GROUPS) {
|
|
4166
|
+
for (const member of group.members) {
|
|
4167
|
+
GROUP_BY_MEMBER.set(member, { key: group.key, label: group.label });
|
|
4168
|
+
}
|
|
4169
|
+
}
|
|
4170
|
+
var NON_ROOM_LABELS = /* @__PURE__ */ new Set(["", "outro", "outros", "other", "unknown"]);
|
|
4171
|
+
function capitalize(value) {
|
|
4172
|
+
return value.charAt(0).toUpperCase() + value.slice(1);
|
|
4173
|
+
}
|
|
4174
|
+
function photoRoomLabel(roomType) {
|
|
4175
|
+
const raw = (roomType ?? "").trim();
|
|
4176
|
+
const normalized = normalizeRoomLabel(raw);
|
|
4177
|
+
if (NON_ROOM_LABELS.has(normalized)) {
|
|
4178
|
+
return { key: PHOTO_GROUP_OTHER_KEY, label: PHOTO_GROUP_OTHER_LABEL };
|
|
4179
|
+
}
|
|
4180
|
+
const known = GROUP_BY_MEMBER.get(normalized);
|
|
4181
|
+
if (known) return known;
|
|
4182
|
+
return { key: normalized, label: capitalize(raw) };
|
|
4183
|
+
}
|
|
4184
|
+
function isPhoto(item) {
|
|
4185
|
+
return (item.type || "image") === "image" && typeof item.src === "string";
|
|
4186
|
+
}
|
|
4187
|
+
function listingPhotoGroups(listing) {
|
|
4188
|
+
const groups = /* @__PURE__ */ new Map();
|
|
4189
|
+
const photos = [...listing.media ?? []].filter(isPhoto).sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
|
|
4190
|
+
for (const photo of photos) {
|
|
4191
|
+
const { key, label } = photoRoomLabel(photo.roomType);
|
|
4192
|
+
const group = groups.get(key);
|
|
4193
|
+
if (group) {
|
|
4194
|
+
group.photos.push(photo);
|
|
4195
|
+
} else {
|
|
4196
|
+
groups.set(key, { key, label, photos: [photo] });
|
|
4197
|
+
}
|
|
4198
|
+
}
|
|
4199
|
+
const ordered = [...groups.values()];
|
|
4200
|
+
const otherIndex = ordered.findIndex((g) => g.key === PHOTO_GROUP_OTHER_KEY);
|
|
4201
|
+
if (otherIndex >= 0 && otherIndex !== ordered.length - 1) {
|
|
4202
|
+
const [other] = ordered.splice(otherIndex, 1);
|
|
4203
|
+
ordered.push(other);
|
|
4204
|
+
}
|
|
4205
|
+
return ordered;
|
|
4206
|
+
}
|
|
4207
|
+
function listingVisualHighlights(listing, options) {
|
|
4208
|
+
const limit = Math.max(0, Math.floor(options?.limit ?? 8));
|
|
4209
|
+
if (limit === 0) return [];
|
|
4210
|
+
const counts = /* @__PURE__ */ new Map();
|
|
4211
|
+
let seen = 0;
|
|
4212
|
+
for (const item of listing.media ?? []) {
|
|
4213
|
+
if (!isPhoto(item) || !Array.isArray(item.features)) continue;
|
|
4214
|
+
for (const feature of item.features) {
|
|
4215
|
+
if (typeof feature !== "string") continue;
|
|
4216
|
+
const text = feature.trim();
|
|
4217
|
+
if (!text) continue;
|
|
4218
|
+
const key = normalizeRoomLabel(text);
|
|
4219
|
+
if (!key) continue;
|
|
4220
|
+
const entry = counts.get(key);
|
|
4221
|
+
if (entry) {
|
|
4222
|
+
entry.count += 1;
|
|
4223
|
+
} else {
|
|
4224
|
+
counts.set(key, { text, count: 1, seen: seen++ });
|
|
4225
|
+
}
|
|
4226
|
+
}
|
|
4227
|
+
}
|
|
4228
|
+
return [...counts.values()].sort((a, b) => b.count - a.count || a.seen - b.seen).slice(0, limit).map((entry) => entry.text);
|
|
4229
|
+
}
|
|
3080
4230
|
|
|
3081
4231
|
// src/fetchers-market.ts
|
|
3082
4232
|
var RATE_LIMITED_MESSAGE = "Muitas consultas em pouco tempo. Tente novamente em instantes.";
|
|
@@ -3314,15 +4464,24 @@ function applyMatchedPhotoCover(cards, photoResults, options = {}) {
|
|
|
3314
4464
|
}
|
|
3315
4465
|
export {
|
|
3316
4466
|
AMENITY_FALLBACK_LABELS,
|
|
4467
|
+
DEFAULT_MAPS_BASE_URL,
|
|
3317
4468
|
DEFAULT_PHONE_COUNTRY_CODE,
|
|
3318
4469
|
FORBIDDEN_SEARCH_QUERY_KEYS,
|
|
3319
4470
|
GaragemSdkError,
|
|
3320
4471
|
LISTING_AMENITY_TITLES,
|
|
3321
4472
|
LISTING_DESCRIPTION_CLAMP,
|
|
3322
4473
|
LeadSubmitError,
|
|
4474
|
+
MAPS_MAX_IMAGE_EDGE,
|
|
4475
|
+
MAPS_SITE_HEADER,
|
|
4476
|
+
MAP_POLYGON_MAX_VERTICES,
|
|
4477
|
+
MAP_SEARCH_DEFAULT_PAGE_SIZE,
|
|
4478
|
+
MAP_SEARCH_MAX_PAGE_SIZE,
|
|
4479
|
+
MAP_VIEWPORT_DEBOUNCE_MS,
|
|
3323
4480
|
MATCHED_PHOTO_COVER_MAX_DISTANCE,
|
|
3324
4481
|
MAX_NATIONAL_PHONE_DIGITS,
|
|
3325
4482
|
PHONE_COUNTRIES,
|
|
4483
|
+
PHOTO_GROUP_OTHER_KEY,
|
|
4484
|
+
PHOTO_GROUP_OTHER_LABEL,
|
|
3326
4485
|
PHOTO_SEARCH_MIN_QUERY_LENGTH,
|
|
3327
4486
|
SEARCH_EMPTY_COPY,
|
|
3328
4487
|
SEARCH_SORT_RELEVANCE,
|
|
@@ -3334,17 +4493,28 @@ export {
|
|
|
3334
4493
|
VISIT_TIME_ZONE,
|
|
3335
4494
|
applyMatchedPhotoCover,
|
|
3336
4495
|
applyPathFilter,
|
|
4496
|
+
boundaryCitySlug,
|
|
4497
|
+
boundaryLayerId,
|
|
4498
|
+
boundaryLayerUrl,
|
|
3337
4499
|
buildQueryListingsParams,
|
|
3338
4500
|
canonicalizeSearchHref,
|
|
4501
|
+
capMapPage,
|
|
4502
|
+
capMapPageSize,
|
|
3339
4503
|
clearStagedPathFilters,
|
|
4504
|
+
clearTravelTimeCache,
|
|
4505
|
+
clusterPins,
|
|
4506
|
+
coarsenCoordinates,
|
|
3340
4507
|
coerceNpmVersion,
|
|
3341
4508
|
collapseDuplicatedBrazilianMobileNine,
|
|
3342
4509
|
compareSemver,
|
|
3343
4510
|
composeSearchPublicHref2 as composeSearchPublicHref,
|
|
3344
4511
|
composeSearchPublicPath2 as composeSearchPublicPath,
|
|
4512
|
+
coordinateDecimals,
|
|
3345
4513
|
countFacetChoices,
|
|
3346
4514
|
countOptionLabel,
|
|
4515
|
+
createClient,
|
|
3347
4516
|
createGaragemClient,
|
|
4517
|
+
createTravelTimeCache,
|
|
3348
4518
|
defaultPhoneCountry,
|
|
3349
4519
|
displayPathLocation,
|
|
3350
4520
|
expandVisitSchedule,
|
|
@@ -3354,6 +4524,7 @@ export {
|
|
|
3354
4524
|
formatGroupedInteger,
|
|
3355
4525
|
formatListingPrice,
|
|
3356
4526
|
formatPhoneNational,
|
|
4527
|
+
getBoundaryLayer,
|
|
3357
4528
|
getCmsCollection,
|
|
3358
4529
|
getCmsCollections,
|
|
3359
4530
|
getCmsEntries,
|
|
@@ -3364,6 +4535,7 @@ export {
|
|
|
3364
4535
|
getListings,
|
|
3365
4536
|
getNeighborhoodSummary,
|
|
3366
4537
|
getSearchUi,
|
|
4538
|
+
getSimilarByPhoto,
|
|
3367
4539
|
getSimilarListings,
|
|
3368
4540
|
getSite,
|
|
3369
4541
|
hasShowcaseLeadsPostUrl,
|
|
@@ -3371,6 +4543,8 @@ export {
|
|
|
3371
4543
|
hrefForPathFilters,
|
|
3372
4544
|
hrefWithExplicitPage,
|
|
3373
4545
|
isListingDetailPath,
|
|
4546
|
+
isMapBounds,
|
|
4547
|
+
isMapPolygon,
|
|
3374
4548
|
isPhotoSearchOnPin,
|
|
3375
4549
|
isStudioPreviewHost,
|
|
3376
4550
|
isValidPhone,
|
|
@@ -3379,6 +4553,7 @@ export {
|
|
|
3379
4553
|
listingAmenityGroups,
|
|
3380
4554
|
listingBreadcrumb,
|
|
3381
4555
|
listingBusinessLabel,
|
|
4556
|
+
listingCoordinates,
|
|
3382
4557
|
listingDescriptionPreview,
|
|
3383
4558
|
listingDetailFieldsModel,
|
|
3384
4559
|
listingDetailModel,
|
|
@@ -3388,12 +4563,25 @@ export {
|
|
|
3388
4563
|
listingLookupKey,
|
|
3389
4564
|
listingMapsHref,
|
|
3390
4565
|
listingMediaOverlays,
|
|
4566
|
+
listingPhotoGroups,
|
|
3391
4567
|
listingPublicPath,
|
|
4568
|
+
listingStaticMapUrl,
|
|
4569
|
+
listingStreetViewAvailable,
|
|
4570
|
+
listingStreetViewMetadataUrl,
|
|
4571
|
+
listingStreetViewUrl,
|
|
3392
4572
|
listingValues,
|
|
4573
|
+
listingVisualHighlights,
|
|
4574
|
+
mapClusterCellDegrees,
|
|
4575
|
+
mapSearchPins,
|
|
4576
|
+
mapsExportsPublished,
|
|
3393
4577
|
marketExportsAvailableAt,
|
|
3394
4578
|
marketPositionLabel,
|
|
4579
|
+
maxZoomForCoordinates,
|
|
3395
4580
|
mergeAppliedSearchQueryIntoSearch2 as mergeAppliedSearchQueryIntoSearch,
|
|
3396
4581
|
nationalPhoneDigits,
|
|
4582
|
+
neighborhoodBoundaryLayer,
|
|
4583
|
+
neighborhoodBoundaryUrl,
|
|
4584
|
+
normalizeMapsBaseUrl,
|
|
3397
4585
|
normalizeVisitDate,
|
|
3398
4586
|
normalizeVisitTime,
|
|
3399
4587
|
paginationPages,
|
|
@@ -3407,6 +4595,7 @@ export {
|
|
|
3407
4595
|
pathFiltersToQueryFilters,
|
|
3408
4596
|
pathLocationToFilterInput,
|
|
3409
4597
|
phoneCountrySearchValue,
|
|
4598
|
+
photoRoomLabel,
|
|
3410
4599
|
photoSearchUrl,
|
|
3411
4600
|
priceBandLabel,
|
|
3412
4601
|
publicSearchHref,
|
|
@@ -3418,10 +4607,13 @@ export {
|
|
|
3418
4607
|
requestPriceEstimate,
|
|
3419
4608
|
resolveMatchedCoverPhoto,
|
|
3420
4609
|
resolvePublicSiteId,
|
|
4610
|
+
resolveTravelDestination,
|
|
3421
4611
|
searchChromeModel,
|
|
3422
4612
|
searchHrefUsesLegacyFilterQuery,
|
|
3423
4613
|
searchListingPhotos,
|
|
3424
4614
|
searchListings,
|
|
4615
|
+
searchListingsInBounds,
|
|
4616
|
+
searchListingsInPolygon,
|
|
3425
4617
|
searchResultsHeading,
|
|
3426
4618
|
searchSortOptions,
|
|
3427
4619
|
serializeAppliedSearchQuery2 as serializeAppliedSearchQuery,
|
|
@@ -3434,8 +4626,12 @@ export {
|
|
|
3434
4626
|
studioLeadInstruction,
|
|
3435
4627
|
studioListingCardInstruction,
|
|
3436
4628
|
studioListingDetailInstruction,
|
|
4629
|
+
studioMapsInstruction,
|
|
3437
4630
|
studioMarketInstruction,
|
|
4631
|
+
studioPhotoInstruction,
|
|
4632
|
+
studioPhotoInstructionFor,
|
|
3438
4633
|
studioPhotoSearchInstruction,
|
|
4634
|
+
studioPublishableKeyInstruction,
|
|
3439
4635
|
studioSdkPinInstruction,
|
|
3440
4636
|
studioSearchInstruction,
|
|
3441
4637
|
studioSearchLandmarkInstruction,
|
|
@@ -3445,6 +4641,9 @@ export {
|
|
|
3445
4641
|
toE164,
|
|
3446
4642
|
toListingCardModel,
|
|
3447
4643
|
toolbarFilterIds,
|
|
4644
|
+
travelTimeCacheKey,
|
|
4645
|
+
travelTimeFromListing,
|
|
4646
|
+
travelTimesFromListing,
|
|
3448
4647
|
truncateNationalPhoneDigits,
|
|
3449
4648
|
unavailableReactImports,
|
|
3450
4649
|
visibleSearchFilters
|