@garagem-ai/site-sdk 0.6.1 → 0.8.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 +260 -28
- package/dist/index.d.mts +488 -150
- package/dist/index.d.ts +488 -150
- package/dist/index.js +882 -36
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +857 -36
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.mts +46 -2
- package/dist/react.d.ts +46 -2
- package/dist/react.js +334 -14
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +332 -14
- package/dist/react.mjs.map +1 -1
- package/dist/{search-engine-CtnLzmwW.d.mts → types-photo-search-CmGRj6my.d.mts} +229 -1
- package/dist/{search-engine-CtnLzmwW.d.ts → types-photo-search-CmGRj6my.d.ts} +229 -1
- package/package.json +2 -1
- package/src/client.ts +23 -0
- package/src/fetchers-market.ts +216 -0
- package/src/fetchers-photo-search.ts +101 -0
- package/src/fetchers-photos.ts +98 -0
- package/src/fetchers.ts +92 -29
- package/src/index.ts +92 -2
- package/src/internal/sdk-http.ts +122 -0
- package/src/leads.ts +34 -3
- package/src/listing-photos.ts +312 -0
- package/src/market-labels.ts +51 -0
- package/src/photo-search-cover.ts +90 -0
- package/src/react/index.ts +8 -0
- package/src/react/types.ts +5 -0
- package/src/react/use-public-photo-search.ts +165 -0
- package/src/react/use-public-search.ts +23 -5
- package/src/resolve-site-id.ts +3 -0
- package/src/studio-contract.ts +178 -3
- package/src/types-market.ts +138 -0
- package/src/types-photo-search.ts +55 -0
- package/src/types-photos.ts +46 -0
- package/src/types.ts +18 -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,7 +282,8 @@ 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) {
|
|
@@ -188,7 +302,8 @@ async function queryListings(options) {
|
|
|
188
302
|
body: JSON.stringify(params ?? {}),
|
|
189
303
|
next
|
|
190
304
|
},
|
|
191
|
-
fetchImpl ?? fetch
|
|
305
|
+
fetchImpl ?? fetch,
|
|
306
|
+
options.publishableKey
|
|
192
307
|
);
|
|
193
308
|
}
|
|
194
309
|
async function getSimilarListings(options) {
|
|
@@ -216,7 +331,8 @@ async function getSimilarListings(options) {
|
|
|
216
331
|
const data = await callJson(
|
|
217
332
|
url,
|
|
218
333
|
{ method: "GET", headers: { Accept: "application/json" }, next },
|
|
219
|
-
fetchImpl ?? fetch
|
|
334
|
+
fetchImpl ?? fetch,
|
|
335
|
+
options.publishableKey
|
|
220
336
|
);
|
|
221
337
|
return {
|
|
222
338
|
listings: data.listings ?? [],
|
|
@@ -231,7 +347,8 @@ async function getCmsCollections(options) {
|
|
|
231
347
|
const data = await callJson(
|
|
232
348
|
url,
|
|
233
349
|
{ method: "GET", headers: { Accept: "application/json" }, next },
|
|
234
|
-
fetchImpl ?? fetch
|
|
350
|
+
fetchImpl ?? fetch,
|
|
351
|
+
options.publishableKey
|
|
235
352
|
);
|
|
236
353
|
return data.collections ?? [];
|
|
237
354
|
}
|
|
@@ -248,7 +365,8 @@ async function getCmsCollection(options) {
|
|
|
248
365
|
const data = await callJson(
|
|
249
366
|
url,
|
|
250
367
|
{ method: "GET", headers: { Accept: "application/json" }, next },
|
|
251
|
-
fetchImpl ?? fetch
|
|
368
|
+
fetchImpl ?? fetch,
|
|
369
|
+
options.publishableKey
|
|
252
370
|
);
|
|
253
371
|
if (data && typeof data === "object" && "collection" in data && data.collection) {
|
|
254
372
|
return data.collection;
|
|
@@ -283,7 +401,8 @@ async function getCmsEntries(options) {
|
|
|
283
401
|
const data = await callJson(
|
|
284
402
|
url,
|
|
285
403
|
{ method: "GET", headers: { Accept: "application/json" }, next },
|
|
286
|
-
fetchImpl ?? fetch
|
|
404
|
+
fetchImpl ?? fetch,
|
|
405
|
+
options.publishableKey
|
|
287
406
|
);
|
|
288
407
|
return {
|
|
289
408
|
entries: data.entries ?? [],
|
|
@@ -308,7 +427,8 @@ async function getCmsEntry(options) {
|
|
|
308
427
|
const data = await callJson(
|
|
309
428
|
url,
|
|
310
429
|
{ method: "GET", headers: { Accept: "application/json" }, next },
|
|
311
|
-
fetchImpl ?? fetch
|
|
430
|
+
fetchImpl ?? fetch,
|
|
431
|
+
options.publishableKey
|
|
312
432
|
);
|
|
313
433
|
if (data && typeof data === "object" && "entry" in data && data.entry) {
|
|
314
434
|
return data.entry;
|
|
@@ -843,7 +963,8 @@ async function resolvePublicSiteId(options) {
|
|
|
843
963
|
const site = await getSite({
|
|
844
964
|
domain: host,
|
|
845
965
|
baseUrl: options.baseUrl,
|
|
846
|
-
fetch: options.fetch
|
|
966
|
+
fetch: options.fetch,
|
|
967
|
+
publishableKey: options.publishableKey
|
|
847
968
|
});
|
|
848
969
|
if (site?.id) return site.id;
|
|
849
970
|
throw new GaragemSdkError(
|
|
@@ -872,7 +993,8 @@ async function resolveLeadSiteId(input) {
|
|
|
872
993
|
return resolvePublicSiteId({
|
|
873
994
|
host,
|
|
874
995
|
baseUrl: input.baseUrl,
|
|
875
|
-
fetch: input.fetch
|
|
996
|
+
fetch: input.fetch,
|
|
997
|
+
publishableKey: input.publishableKey
|
|
876
998
|
});
|
|
877
999
|
}
|
|
878
1000
|
}
|
|
@@ -880,6 +1002,8 @@ var LeadSubmitError = class extends Error {
|
|
|
880
1002
|
code;
|
|
881
1003
|
status;
|
|
882
1004
|
retryAfterSeconds;
|
|
1005
|
+
/** Seconds to wait. Same value as `retryAfterSeconds`; `null` when unset. */
|
|
1006
|
+
retryAfter;
|
|
883
1007
|
constructor(message, info) {
|
|
884
1008
|
super(message);
|
|
885
1009
|
this.name = "LeadSubmitError";
|
|
@@ -888,6 +1012,7 @@ var LeadSubmitError = class extends Error {
|
|
|
888
1012
|
if (info.retryAfterSeconds != null) {
|
|
889
1013
|
this.retryAfterSeconds = info.retryAfterSeconds;
|
|
890
1014
|
}
|
|
1015
|
+
this.retryAfter = info.retryAfterSeconds ?? null;
|
|
891
1016
|
}
|
|
892
1017
|
};
|
|
893
1018
|
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 +1054,8 @@ async function getLeadUi(options) {
|
|
|
929
1054
|
headers: { Accept: "application/json" },
|
|
930
1055
|
next: options.next
|
|
931
1056
|
},
|
|
932
|
-
options.fetch ?? fetch
|
|
1057
|
+
options.fetch ?? fetch,
|
|
1058
|
+
options.publishableKey
|
|
933
1059
|
);
|
|
934
1060
|
}
|
|
935
1061
|
function assertListingId(listingId) {
|
|
@@ -1002,7 +1128,8 @@ async function postSiteLead(input) {
|
|
|
1002
1128
|
method: "POST",
|
|
1003
1129
|
headers: {
|
|
1004
1130
|
Accept: "application/json",
|
|
1005
|
-
"Content-Type": "application/json"
|
|
1131
|
+
"Content-Type": "application/json",
|
|
1132
|
+
...publishableKeyHeaders(input.publishableKey)
|
|
1006
1133
|
},
|
|
1007
1134
|
body: JSON.stringify(input.body)
|
|
1008
1135
|
});
|
|
@@ -1017,12 +1144,23 @@ async function postSiteLead(input) {
|
|
|
1017
1144
|
const id = typeof data.id === "string" && data.id ? data.id : "";
|
|
1018
1145
|
return { ok: true, status: 202, id };
|
|
1019
1146
|
}
|
|
1020
|
-
|
|
1147
|
+
if (response.status === 401) {
|
|
1148
|
+
throw new LeadSubmitError("Garagem SDK: invalid publishable key.", {
|
|
1149
|
+
code: "unauthorized",
|
|
1150
|
+
status: 401
|
|
1151
|
+
});
|
|
1152
|
+
}
|
|
1021
1153
|
if (response.status === 429) {
|
|
1154
|
+
const text = await response.text().catch(() => "");
|
|
1155
|
+
const parsed = parseSdkErrorBody(text);
|
|
1156
|
+
const retryAfter = retryAfterFromResponse(
|
|
1157
|
+
response,
|
|
1158
|
+
parsed.retryAfterSeconds
|
|
1159
|
+
);
|
|
1022
1160
|
throw new LeadSubmitError("Garagem SDK: too many lead submissions.", {
|
|
1023
1161
|
code: "rate_limited",
|
|
1024
1162
|
status: 429,
|
|
1025
|
-
retryAfterSeconds:
|
|
1163
|
+
...retryAfter != null ? { retryAfterSeconds: retryAfter } : {}
|
|
1026
1164
|
});
|
|
1027
1165
|
}
|
|
1028
1166
|
if (response.status === 404) {
|
|
@@ -1066,6 +1204,7 @@ async function submitVisitLead(input) {
|
|
|
1066
1204
|
siteId: input.siteId,
|
|
1067
1205
|
baseUrl: input.baseUrl,
|
|
1068
1206
|
fetch: input.fetch,
|
|
1207
|
+
publishableKey: input.publishableKey,
|
|
1069
1208
|
body: {
|
|
1070
1209
|
source: "site-sdk",
|
|
1071
1210
|
leadType: "visit",
|
|
@@ -1084,6 +1223,7 @@ async function submitContactLead(input) {
|
|
|
1084
1223
|
siteId: input.siteId,
|
|
1085
1224
|
baseUrl: input.baseUrl,
|
|
1086
1225
|
fetch: input.fetch,
|
|
1226
|
+
publishableKey: input.publishableKey,
|
|
1087
1227
|
body: {
|
|
1088
1228
|
source: "site-sdk",
|
|
1089
1229
|
leadType: "contact",
|
|
@@ -2610,7 +2750,9 @@ var STUDIO_SDK_CONTRACT = {
|
|
|
2610
2750
|
* “never import”) — v0 copies the identifier and the preview ESM loader
|
|
2611
2751
|
* throws FatalRendererError.
|
|
2612
2752
|
*/
|
|
2613
|
-
optionalReactExports: {
|
|
2753
|
+
optionalReactExports: {
|
|
2754
|
+
usePublicPhotoSearch: "0.7.0"
|
|
2755
|
+
},
|
|
2614
2756
|
/**
|
|
2615
2757
|
* Former `/react` chrome (including card/skeleton inject). Completeness
|
|
2616
2758
|
* flags imports as mismatch (not in `reactExports`). Prompts must not
|
|
@@ -2671,6 +2813,29 @@ var STUDIO_SDK_CONTRACT = {
|
|
|
2671
2813
|
*/
|
|
2672
2814
|
unpublishedPhoneExports: [],
|
|
2673
2815
|
amenityExports: ["listingAmenityGroups"],
|
|
2816
|
+
/**
|
|
2817
|
+
* Prompt-safe photo helpers on `minNpmVersion`. Empty until the release
|
|
2818
|
+
* that carries `getSimilarByPhoto` / `listingPhotoGroups` /
|
|
2819
|
+
* `listingVisualHighlights` is on npm; then bump the pin, move the names
|
|
2820
|
+
* here from `unpublishedPhotoExports`, and `studioPhotoInstruction()`
|
|
2821
|
+
* starts teaching the gallery-by-room, highlight chips, and
|
|
2822
|
+
* "imóveis com fotos parecidas" blocks. The caption-based `media[].alt` /
|
|
2823
|
+
* `media[].caption` fields are API data (not tarball exports) and are
|
|
2824
|
+
* documented regardless of the pin.
|
|
2825
|
+
*/
|
|
2826
|
+
photoExports: [],
|
|
2827
|
+
/**
|
|
2828
|
+
* Photo helpers in the repo but not on `minNpmVersion`. Prompts,
|
|
2829
|
+
* completeness, and repair text must not mention these until the pin
|
|
2830
|
+
* bumps — v0 installs the pin and the ESM loader throws on missing named
|
|
2831
|
+
* exports.
|
|
2832
|
+
*/
|
|
2833
|
+
unpublishedPhotoExports: [
|
|
2834
|
+
"getSimilarByPhoto",
|
|
2835
|
+
"listingPhotoGroups",
|
|
2836
|
+
"listingVisualHighlights",
|
|
2837
|
+
"photoRoomLabel"
|
|
2838
|
+
],
|
|
2674
2839
|
/**
|
|
2675
2840
|
* Names already on the pinned npm tarball (`minNpmVersion`) — safe for
|
|
2676
2841
|
* Studio prompts and completeness. Includes `visibleSearchFilters` +
|
|
@@ -2694,8 +2859,43 @@ var STUDIO_SDK_CONTRACT = {
|
|
|
2694
2859
|
unpublishedSearchExports: [
|
|
2695
2860
|
"searchChromeModel",
|
|
2696
2861
|
"rangeDraftFromPath"
|
|
2697
|
-
]
|
|
2862
|
+
],
|
|
2863
|
+
/**
|
|
2864
|
+
* Market-data helpers (neighborhood price summary, listing market
|
|
2865
|
+
* position, visitor price estimate, pt-BR labels). They ship in
|
|
2866
|
+
* `marketExportsSince` and are prompt-safe only once `minNpmVersion`
|
|
2867
|
+
* reaches that release; below it `studioCodegenContractViolations` flags
|
|
2868
|
+
* the names and `studioMarketInstruction()` tells Studio not to generate
|
|
2869
|
+
* the blocks at all. Every helper answers `available: false` unless the
|
|
2870
|
+
* site's organization holds the IPTU module (`iptu_itbi_integration`)
|
|
2871
|
+
* and the city is covered — generated sites render these blocks
|
|
2872
|
+
* conditionally and never show cadastral or transaction data.
|
|
2873
|
+
*/
|
|
2874
|
+
marketExports: [
|
|
2875
|
+
"getNeighborhoodSummary",
|
|
2876
|
+
"getListingMarketPosition",
|
|
2877
|
+
"requestPriceEstimate",
|
|
2878
|
+
"marketPositionLabel",
|
|
2879
|
+
"priceBandLabel"
|
|
2880
|
+
],
|
|
2881
|
+
marketExportsSince: "0.7.0",
|
|
2882
|
+
/**
|
|
2883
|
+
* Photo search ("busca pelo que as fotos mostram"): main-package helpers
|
|
2884
|
+
* that ship together with the `/react` hook listed in
|
|
2885
|
+
* `optionalReactExports` (`usePublicPhotoSearch`). Prompt-safe only once
|
|
2886
|
+
* `minNpmVersion` reaches `photoSearchSince` — `studioPhotoSearchInstruction`
|
|
2887
|
+
* and the Studio guidance print nothing before that, and
|
|
2888
|
+
* `studioCodegenContractViolations` flags the names until then.
|
|
2889
|
+
*/
|
|
2890
|
+
photoSearchExports: [
|
|
2891
|
+
"searchListingPhotos",
|
|
2892
|
+
"applyMatchedPhotoCover"
|
|
2893
|
+
],
|
|
2894
|
+
photoSearchSince: "0.7.0"
|
|
2698
2895
|
};
|
|
2896
|
+
function isPhotoSearchOnPin(pin = STUDIO_SDK_CONTRACT.minNpmVersion) {
|
|
2897
|
+
return compareSemver(pin, STUDIO_SDK_CONTRACT.photoSearchSince) >= 0;
|
|
2898
|
+
}
|
|
2699
2899
|
var STUDIO_SITE_LAYOUT = {
|
|
2700
2900
|
maxWidthRem: "80rem",
|
|
2701
2901
|
maxWidthRemOptions: ["64rem", "80rem", "120rem", "160rem", "240rem"],
|
|
@@ -2779,9 +2979,12 @@ function unavailableReactImports(source, pin) {
|
|
|
2779
2979
|
}
|
|
2780
2980
|
return missing;
|
|
2781
2981
|
}
|
|
2982
|
+
function studioPublishableKeyInstruction() {
|
|
2983
|
+
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.`;
|
|
2984
|
+
}
|
|
2782
2985
|
function studioSdkPinInstruction() {
|
|
2783
2986
|
const version = STUDIO_SDK_CONTRACT.minNpmVersion;
|
|
2784
|
-
const names =
|
|
2987
|
+
const names = [...reactExportsAvailableAt(version)].join(", ");
|
|
2785
2988
|
return `In \`package.json\` set \`"@garagem-ai/site-sdk": "${version}"\` (exact). Import only these \`${STUDIO_SDK_PACKAGE}/react\` names: ${names}.`;
|
|
2786
2989
|
}
|
|
2787
2990
|
function studioLeadInstruction() {
|
|
@@ -2797,6 +3000,31 @@ function studioListingDetailInstruction() {
|
|
|
2797
3000
|
const names = STUDIO_SDK_CONTRACT.listingDetailExports.join(", ");
|
|
2798
3001
|
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.`;
|
|
2799
3002
|
}
|
|
3003
|
+
function studioPhotoInstructionFor(published) {
|
|
3004
|
+
const has = (name) => published.includes(name);
|
|
3005
|
+
const parts = [
|
|
3006
|
+
`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.`
|
|
3007
|
+
];
|
|
3008
|
+
if (has("listingPhotoGroups")) {
|
|
3009
|
+
parts.push(
|
|
3010
|
+
`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.`
|
|
3011
|
+
);
|
|
3012
|
+
}
|
|
3013
|
+
if (has("listingVisualHighlights")) {
|
|
3014
|
+
parts.push(
|
|
3015
|
+
`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.`
|
|
3016
|
+
);
|
|
3017
|
+
}
|
|
3018
|
+
if (has("getSimilarByPhoto")) {
|
|
3019
|
+
parts.push(
|
|
3020
|
+
`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\`.`
|
|
3021
|
+
);
|
|
3022
|
+
}
|
|
3023
|
+
return parts.join(" ");
|
|
3024
|
+
}
|
|
3025
|
+
function studioPhotoInstruction() {
|
|
3026
|
+
return studioPhotoInstructionFor(STUDIO_SDK_CONTRACT.photoExports);
|
|
3027
|
+
}
|
|
2800
3028
|
function studioAmenityInstruction() {
|
|
2801
3029
|
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".`;
|
|
2802
3030
|
}
|
|
@@ -2805,6 +3033,27 @@ function studioSearchInstruction() {
|
|
|
2805
3033
|
const libNames = STUDIO_SDK_CONTRACT.searchExports.join(", ");
|
|
2806
3034
|
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)}`;
|
|
2807
3035
|
}
|
|
3036
|
+
function marketExportsAvailableAt(pin) {
|
|
3037
|
+
return compareSemver(pin, STUDIO_SDK_CONTRACT.marketExportsSince) >= 0;
|
|
3038
|
+
}
|
|
3039
|
+
function studioMarketInstruction(pin = STUDIO_SDK_CONTRACT.minNpmVersion) {
|
|
3040
|
+
if (!marketExportsAvailableAt(pin)) {
|
|
3041
|
+
return `Market data (neighborhood price summary, listing market position, visitor price estimate): NOT available on this SDK pin. Do not generate these blocks and do not invent a local price index. **IPTU module required.** These blocks exist only for a site whose organization holds the IPTU module (\`iptu_itbi_integration\`); without it every helper answers \`{ available: false }\` (HTTP 200) and the section must not render \u2014 omit the heading too. Even when the module is on, the payload is aggregates and a trimmed estimate only: never show cadastral ids, IPTU lookups, ITBI transactions, comparables, or unit inventory.`;
|
|
3042
|
+
}
|
|
3043
|
+
const [summary, position, estimate, positionLabel, bandLabel] = STUDIO_SDK_CONTRACT.marketExports;
|
|
3044
|
+
const names = STUDIO_SDK_CONTRACT.marketExports.join(", ");
|
|
3045
|
+
return `Market data: import ${names} from \`${STUDIO_SDK_PACKAGE}\`. **IPTU module required.** Every helper returns \`{ available: false, reason }\` (HTTP 200, never a throw) unless the site's organization has the IPTU module (\`iptu_itbi_integration\`) and the city is covered \u2014 most sites get \`available: false\`. ALWAYS render these blocks conditionally: \`if (!result.available) return null\` (omit the whole section, heading included); never a placeholder, never \u201Cdados indispon\xEDveis\u201D, never a local fallback number. The payloads carry only aggregates and a trimmed estimate \u2014 never render, request, or invent cadastral ids, IPTU lookups, ITBI transactions, comparables, or addresses from market data. Reasons are codes (\`module_not_enabled\`, \`city_unsupported\`, \`no_data\`, \`rate_limited\`, \u2026) \u2014 do not print them. Three blocks (all optional, design is free):
|
|
3046
|
+
- Neighborhood summary (listing detail, optionally search heading): \`const summary = await ${summary}({ siteId, baseUrl: GARAGEM_API_BASE, query: { city: listing.location.city, neighborhood: listing.location.neighborhood } })\`. Render \`summary.pricePerSqmFormatted.p25\` / \`.p50\` / \`.p75\` (strings, already \`R$ X/m\xB2\`) and \`summary.sampleSize\` (\u201Ccom base em N vendas\u201D); omit the sample line when null.
|
|
3047
|
+
- Listing market position (listing detail, near the price): \`const position = await ${position}({ siteId, baseUrl: GARAGEM_API_BASE, listingId: listing.id })\`. Copy comes from the helpers only: \`${positionLabel}(position)\` (\u201C8% abaixo da mediana do bairro\u201D) and \`${bandLabel}(position)\` (\u201CNa faixa do bairro, abaixo da mediana\u201D); both return \`null\` when unavailable \u2014 hide the line on \`null\`. Show \`position.listingPricePerSqmFormatted\` vs \`position.medianPricePerSqmFormatted\` if a comparison row is wanted. Do not compute the percent in the app.
|
|
3048
|
+
- Visitor price estimate (\`/anunciar\` or a dedicated page, client component): a form with city, bairro, \xE1rea (m\xB2), quartos, vagas, tipo; on submit \`const estimate = await ${estimate}({ siteId, baseUrl: GARAGEM_API_BASE, input: { city, neighborhood, areaSqm, bedrooms, parkingSpots, propertyType } })\`. Render \`estimate.estimatedPriceFormatted\` with the range \`estimate.rangeLowFormatted\` \u2013 \`estimate.rangeHighFormatted\` and \`estimate.confidenceLabel\` mapped to pt-BR (alta / m\xE9dia / baixa). When \`available\` is false show \`estimate.message\` (pt-BR, already written) and the contact CTA. It is rate limited per visitor \u2014 disable the submit while pending. Never call it on page load.
|
|
3049
|
+
Fetch on the server page (\`next: { revalidate: 900 }\`) for the summary and position; the estimate is a user action. Resolve \`siteId\` the same way as every other SDK call.`;
|
|
3050
|
+
}
|
|
3051
|
+
function studioPhotoSearchInstruction(pin = STUDIO_SDK_CONTRACT.minNpmVersion) {
|
|
3052
|
+
if (!isPhotoSearchOnPin(pin)) return "";
|
|
3053
|
+
const hook = "usePublicPhotoSearch";
|
|
3054
|
+
const [fetcher, cover] = STUDIO_SDK_CONTRACT.photoSearchExports;
|
|
3055
|
+
return `Photo search (optional, same page as \`/imoveis\`): visitors can search by what the photos show ("varanda gourmet com churrasqueira"). From \`${STUDIO_SDK_PACKAGE}/react\` import ${hook}; from \`${STUDIO_SDK_PACKAGE}\` import ${fetcher} (server) and ${cover}. Client: \`const photos = ${hook}({ siteId, baseUrl: GARAGEM_API_BASE, query: search.qDraft, enabled: photoMode })\` where \`photoMode\` is a toggle beside the search box ("Buscar pelas fotos"). When \`photos.available === false\` do not render that toggle and keep the regular \`usePublicSearch\` results \u2014 the tenant has no photo lane. When it is on and \`photos.query\` is non-empty, render \`photos.listings\` (nearest first, cover already swapped, \`card.matchedPhoto\` for a small "Combina com a busca" badge) through the site listing-card module instead of \`search.listings\`; while \`photos.loading\` keep the previous cards. Fall back to the regular search results whenever \`photos.items\` is empty or \`photos.error\` is set. To only swap covers on the regular grid, \`${cover}(search.listings, photos.items)\` keeps the grid order and attaches \`matchedPhoto\`. Server pages use \`${fetcher}(siteId, { q, limit, page }, { baseUrl })\`. Cost: every distinct query costs one embedding on the Garagem side (results are cached ten minutes per site and query, and uncached queries are rate limited per visitor and per site), so never call it on every keystroke without the hook's debounce and never for the empty query.`;
|
|
3056
|
+
}
|
|
2808
3057
|
function studioChromeInstruction() {
|
|
2809
3058
|
return `Card, skeleton, and search chrome markup are app-owned. Never \`import "${STUDIO_SDK_CONTRACT.forbiddenImports[0]}"\` \u2014 v0 preview cannot load npm CSS. Do not mount an SDK stylesheet. Theme with site tokens and \`--radius\` in \`app/globals.css\`.`;
|
|
2810
3059
|
}
|
|
@@ -2813,7 +3062,10 @@ function mentionsExportName(text, name) {
|
|
|
2813
3062
|
}
|
|
2814
3063
|
function studioCodegenContractViolations(text) {
|
|
2815
3064
|
const violations = [];
|
|
2816
|
-
for (const name of Object.
|
|
3065
|
+
for (const [name, since] of Object.entries(
|
|
3066
|
+
STUDIO_SDK_CONTRACT.optionalReactExports
|
|
3067
|
+
)) {
|
|
3068
|
+
if (compareSemver(STUDIO_SDK_CONTRACT.minNpmVersion, since) >= 0) continue;
|
|
2817
3069
|
if (mentionsExportName(text, name)) violations.push(name);
|
|
2818
3070
|
}
|
|
2819
3071
|
for (const name of STUDIO_SDK_CONTRACT.retiredReactExports) {
|
|
@@ -2831,7 +3083,26 @@ function studioCodegenContractViolations(text) {
|
|
|
2831
3083
|
violations.push(name);
|
|
2832
3084
|
}
|
|
2833
3085
|
}
|
|
3086
|
+
for (const name of STUDIO_SDK_CONTRACT.unpublishedPhotoExports) {
|
|
3087
|
+
if (mentionsExportName(text, name) && !violations.includes(name)) {
|
|
3088
|
+
violations.push(name);
|
|
3089
|
+
}
|
|
3090
|
+
}
|
|
3091
|
+
if (!isPhotoSearchOnPin()) {
|
|
3092
|
+
for (const name of STUDIO_SDK_CONTRACT.photoSearchExports) {
|
|
3093
|
+
if (mentionsExportName(text, name) && !violations.includes(name)) {
|
|
3094
|
+
violations.push(name);
|
|
3095
|
+
}
|
|
3096
|
+
}
|
|
3097
|
+
}
|
|
2834
3098
|
const pin = STUDIO_SDK_CONTRACT.minNpmVersion;
|
|
3099
|
+
if (!marketExportsAvailableAt(pin)) {
|
|
3100
|
+
for (const name of STUDIO_SDK_CONTRACT.marketExports) {
|
|
3101
|
+
if (mentionsExportName(text, name) && !violations.includes(name)) {
|
|
3102
|
+
violations.push(name);
|
|
3103
|
+
}
|
|
3104
|
+
}
|
|
3105
|
+
}
|
|
2835
3106
|
const available = reactExportsAvailableAt(pin);
|
|
2836
3107
|
for (const name of parseReactSdkNamedImports(text)) {
|
|
2837
3108
|
if (!available.has(name) && !violations.includes(name)) {
|
|
@@ -2866,6 +3137,9 @@ function createGaragemClient(options = {}) {
|
|
|
2866
3137
|
const out = { ...opts };
|
|
2867
3138
|
if (options.baseUrl !== void 0) out.baseUrl = options.baseUrl;
|
|
2868
3139
|
if (options.fetch !== void 0) out.fetch = options.fetch;
|
|
3140
|
+
if (options.publishableKey !== void 0 && out.publishableKey === void 0) {
|
|
3141
|
+
out.publishableKey = options.publishableKey;
|
|
3142
|
+
}
|
|
2869
3143
|
return out;
|
|
2870
3144
|
};
|
|
2871
3145
|
return {
|
|
@@ -2894,6 +3168,9 @@ function createGaragemClient(options = {}) {
|
|
|
2894
3168
|
if (domain !== void 0) opts.domain = domain;
|
|
2895
3169
|
if (options.baseUrl !== void 0) opts.baseUrl = options.baseUrl;
|
|
2896
3170
|
if (options.fetch !== void 0) opts.fetch = options.fetch;
|
|
3171
|
+
if (options.publishableKey !== void 0) {
|
|
3172
|
+
opts.publishableKey = options.publishableKey;
|
|
3173
|
+
}
|
|
2897
3174
|
const merged = mergeNext(next);
|
|
2898
3175
|
if (merged !== void 0) opts.next = merged;
|
|
2899
3176
|
return getSite(opts);
|
|
@@ -3002,6 +3279,525 @@ function createGaragemClient(options = {}) {
|
|
|
3002
3279
|
}
|
|
3003
3280
|
};
|
|
3004
3281
|
}
|
|
3282
|
+
var createClient = createGaragemClient;
|
|
3283
|
+
|
|
3284
|
+
// src/fetchers-photos.ts
|
|
3285
|
+
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;
|
|
3286
|
+
var HIDDEN_SIMILAR_PHOTOS = {
|
|
3287
|
+
available: false,
|
|
3288
|
+
items: []
|
|
3289
|
+
};
|
|
3290
|
+
async function getSimilarByPhoto(siteId, listingId, mediaId, options = {}) {
|
|
3291
|
+
const { baseUrl, fetch: fetchImpl, next, limit } = options;
|
|
3292
|
+
const resolvedSiteId = await coerceSiteId(siteId);
|
|
3293
|
+
const lookupId = listingLookupKey(listingId ?? "");
|
|
3294
|
+
if (!lookupId || lookupId === "undefined" || lookupId === "null") {
|
|
3295
|
+
throw new TypeError("getSimilarByPhoto: `listingId` is required");
|
|
3296
|
+
}
|
|
3297
|
+
const photoId = typeof mediaId === "string" ? mediaId.trim() : "";
|
|
3298
|
+
if (!photoId) {
|
|
3299
|
+
throw new TypeError("getSimilarByPhoto: `mediaId` is required");
|
|
3300
|
+
}
|
|
3301
|
+
if (!MEDIA_UUID_RE.test(photoId)) {
|
|
3302
|
+
return HIDDEN_SIMILAR_PHOTOS;
|
|
3303
|
+
}
|
|
3304
|
+
const base = normalizeBaseUrl(baseUrl);
|
|
3305
|
+
const params = new URLSearchParams({ mediaId: photoId });
|
|
3306
|
+
if (typeof limit === "number" && Number.isFinite(limit) && limit > 0) {
|
|
3307
|
+
params.set("limit", String(Math.floor(limit)));
|
|
3308
|
+
}
|
|
3309
|
+
const url = `${base}/api/sites/${encodeURIComponent(resolvedSiteId)}/listings/${encodeURIComponent(
|
|
3310
|
+
lookupId
|
|
3311
|
+
)}/similar-photos?${params.toString()}`;
|
|
3312
|
+
const data = await callJson(
|
|
3313
|
+
url,
|
|
3314
|
+
{ method: "GET", headers: { Accept: "application/json" }, next },
|
|
3315
|
+
fetchImpl ?? fetch
|
|
3316
|
+
);
|
|
3317
|
+
return {
|
|
3318
|
+
available: data.available !== false,
|
|
3319
|
+
items: Array.isArray(data.items) ? data.items : []
|
|
3320
|
+
};
|
|
3321
|
+
}
|
|
3322
|
+
|
|
3323
|
+
// src/listing-photos.ts
|
|
3324
|
+
var PHOTO_GROUP_OTHER_KEY = "outros";
|
|
3325
|
+
var PHOTO_GROUP_OTHER_LABEL = "Outras fotos";
|
|
3326
|
+
function normalizeRoomLabel(value) {
|
|
3327
|
+
return value.normalize("NFD").replace(/[̀-ͯ]/g, "").toLowerCase().replace(/[^a-z0-9]+/g, " ").trim();
|
|
3328
|
+
}
|
|
3329
|
+
var ROOM_GROUPS = [
|
|
3330
|
+
{
|
|
3331
|
+
key: "fachada",
|
|
3332
|
+
label: "Fachada",
|
|
3333
|
+
members: [
|
|
3334
|
+
"fachada",
|
|
3335
|
+
"exterior",
|
|
3336
|
+
"frente",
|
|
3337
|
+
"facade",
|
|
3338
|
+
"fachada do predio",
|
|
3339
|
+
"predio",
|
|
3340
|
+
"building exterior",
|
|
3341
|
+
"area externa do predio"
|
|
3342
|
+
]
|
|
3343
|
+
},
|
|
3344
|
+
{
|
|
3345
|
+
key: "sala",
|
|
3346
|
+
label: "Sala",
|
|
3347
|
+
members: [
|
|
3348
|
+
"sala",
|
|
3349
|
+
"sala de estar",
|
|
3350
|
+
"living",
|
|
3351
|
+
"estar",
|
|
3352
|
+
"sala de tv",
|
|
3353
|
+
"living room",
|
|
3354
|
+
"sala de estar e jantar",
|
|
3355
|
+
"sala integrada"
|
|
3356
|
+
]
|
|
3357
|
+
},
|
|
3358
|
+
{
|
|
3359
|
+
key: "sala de jantar",
|
|
3360
|
+
label: "Sala de jantar",
|
|
3361
|
+
members: ["sala de jantar", "jantar", "dining room", "copa jantar"]
|
|
3362
|
+
},
|
|
3363
|
+
{
|
|
3364
|
+
key: "cozinha",
|
|
3365
|
+
label: "Cozinha",
|
|
3366
|
+
members: [
|
|
3367
|
+
"cozinha",
|
|
3368
|
+
"copa",
|
|
3369
|
+
"copa cozinha",
|
|
3370
|
+
"cozinha americana",
|
|
3371
|
+
"kitchen"
|
|
3372
|
+
]
|
|
3373
|
+
},
|
|
3374
|
+
{
|
|
3375
|
+
key: "quarto",
|
|
3376
|
+
label: "Quartos",
|
|
3377
|
+
members: [
|
|
3378
|
+
"quarto",
|
|
3379
|
+
"dormitorio",
|
|
3380
|
+
"suite",
|
|
3381
|
+
"suite master",
|
|
3382
|
+
"quarto de casal",
|
|
3383
|
+
"quarto de solteiro",
|
|
3384
|
+
"quarto infantil",
|
|
3385
|
+
"bedroom",
|
|
3386
|
+
"master bedroom"
|
|
3387
|
+
]
|
|
3388
|
+
},
|
|
3389
|
+
{
|
|
3390
|
+
key: "banheiro",
|
|
3391
|
+
label: "Banheiros",
|
|
3392
|
+
members: [
|
|
3393
|
+
"banheiro",
|
|
3394
|
+
"lavabo",
|
|
3395
|
+
"wc",
|
|
3396
|
+
"toalete",
|
|
3397
|
+
"bathroom",
|
|
3398
|
+
"banheiro social",
|
|
3399
|
+
"banheiro da suite"
|
|
3400
|
+
]
|
|
3401
|
+
},
|
|
3402
|
+
{
|
|
3403
|
+
key: "varanda",
|
|
3404
|
+
label: "Varanda",
|
|
3405
|
+
members: ["varanda", "sacada", "terraco", "balcony", "terrace"]
|
|
3406
|
+
},
|
|
3407
|
+
{
|
|
3408
|
+
key: "area gourmet",
|
|
3409
|
+
label: "\xC1rea gourmet",
|
|
3410
|
+
members: [
|
|
3411
|
+
"area gourmet",
|
|
3412
|
+
"varanda gourmet",
|
|
3413
|
+
"espaco gourmet",
|
|
3414
|
+
"churrasqueira",
|
|
3415
|
+
"gourmet",
|
|
3416
|
+
"terraco gourmet"
|
|
3417
|
+
]
|
|
3418
|
+
},
|
|
3419
|
+
{
|
|
3420
|
+
key: "closet",
|
|
3421
|
+
label: "Closet",
|
|
3422
|
+
members: ["closet", "closet da suite", "walk in closet"]
|
|
3423
|
+
},
|
|
3424
|
+
{
|
|
3425
|
+
key: "escritorio",
|
|
3426
|
+
label: "Escrit\xF3rio",
|
|
3427
|
+
members: ["escritorio", "home office", "office"]
|
|
3428
|
+
},
|
|
3429
|
+
{
|
|
3430
|
+
key: "area de servico",
|
|
3431
|
+
label: "\xC1rea de servi\xE7o",
|
|
3432
|
+
members: ["area de servico", "lavanderia", "laundry", "servico"]
|
|
3433
|
+
},
|
|
3434
|
+
{ key: "despensa", label: "Despensa", members: ["despensa", "pantry"] },
|
|
3435
|
+
{
|
|
3436
|
+
key: "corredor",
|
|
3437
|
+
label: "Corredor",
|
|
3438
|
+
members: ["corredor", "circulacao", "hallway"]
|
|
3439
|
+
},
|
|
3440
|
+
{
|
|
3441
|
+
key: "hall",
|
|
3442
|
+
label: "Hall",
|
|
3443
|
+
members: [
|
|
3444
|
+
"hall",
|
|
3445
|
+
"hall de entrada",
|
|
3446
|
+
"entrada",
|
|
3447
|
+
"recepcao",
|
|
3448
|
+
"lobby",
|
|
3449
|
+
"portaria"
|
|
3450
|
+
]
|
|
3451
|
+
},
|
|
3452
|
+
{
|
|
3453
|
+
key: "garagem",
|
|
3454
|
+
label: "Garagem",
|
|
3455
|
+
members: [
|
|
3456
|
+
"garagem",
|
|
3457
|
+
"vaga",
|
|
3458
|
+
"vagas",
|
|
3459
|
+
"estacionamento",
|
|
3460
|
+
"garage",
|
|
3461
|
+
"vaga de garagem"
|
|
3462
|
+
]
|
|
3463
|
+
},
|
|
3464
|
+
{
|
|
3465
|
+
key: "piscina",
|
|
3466
|
+
label: "Piscina",
|
|
3467
|
+
members: ["piscina", "pool", "piscina do condominio"]
|
|
3468
|
+
},
|
|
3469
|
+
{
|
|
3470
|
+
key: "academia",
|
|
3471
|
+
label: "Academia",
|
|
3472
|
+
members: ["academia", "fitness", "gym", "espaco fitness"]
|
|
3473
|
+
},
|
|
3474
|
+
{
|
|
3475
|
+
key: "salao de festas",
|
|
3476
|
+
label: "Sal\xE3o de festas",
|
|
3477
|
+
members: ["salao de festas", "festas", "salao", "party room"]
|
|
3478
|
+
},
|
|
3479
|
+
{
|
|
3480
|
+
key: "playground",
|
|
3481
|
+
label: "Playground",
|
|
3482
|
+
members: ["playground", "brinquedoteca", "espaco kids"]
|
|
3483
|
+
},
|
|
3484
|
+
{
|
|
3485
|
+
key: "jardim",
|
|
3486
|
+
label: "Jardim",
|
|
3487
|
+
members: ["jardim", "quintal", "area externa", "garden", "backyard"]
|
|
3488
|
+
},
|
|
3489
|
+
{
|
|
3490
|
+
key: "vista",
|
|
3491
|
+
label: "Vista",
|
|
3492
|
+
members: ["vista", "view", "vista da varanda"]
|
|
3493
|
+
},
|
|
3494
|
+
{
|
|
3495
|
+
key: "planta",
|
|
3496
|
+
label: "Planta",
|
|
3497
|
+
members: ["planta", "planta baixa", "floorplan", "floor plan"]
|
|
3498
|
+
}
|
|
3499
|
+
];
|
|
3500
|
+
var GROUP_BY_MEMBER = /* @__PURE__ */ new Map();
|
|
3501
|
+
for (const group of ROOM_GROUPS) {
|
|
3502
|
+
for (const member of group.members) {
|
|
3503
|
+
GROUP_BY_MEMBER.set(member, { key: group.key, label: group.label });
|
|
3504
|
+
}
|
|
3505
|
+
}
|
|
3506
|
+
var NON_ROOM_LABELS = /* @__PURE__ */ new Set(["", "outro", "outros", "other", "unknown"]);
|
|
3507
|
+
function capitalize(value) {
|
|
3508
|
+
return value.charAt(0).toUpperCase() + value.slice(1);
|
|
3509
|
+
}
|
|
3510
|
+
function photoRoomLabel(roomType) {
|
|
3511
|
+
const raw = (roomType ?? "").trim();
|
|
3512
|
+
const normalized = normalizeRoomLabel(raw);
|
|
3513
|
+
if (NON_ROOM_LABELS.has(normalized)) {
|
|
3514
|
+
return { key: PHOTO_GROUP_OTHER_KEY, label: PHOTO_GROUP_OTHER_LABEL };
|
|
3515
|
+
}
|
|
3516
|
+
const known = GROUP_BY_MEMBER.get(normalized);
|
|
3517
|
+
if (known) return known;
|
|
3518
|
+
return { key: normalized, label: capitalize(raw) };
|
|
3519
|
+
}
|
|
3520
|
+
function isPhoto(item) {
|
|
3521
|
+
return (item.type || "image") === "image" && typeof item.src === "string";
|
|
3522
|
+
}
|
|
3523
|
+
function listingPhotoGroups(listing) {
|
|
3524
|
+
const groups = /* @__PURE__ */ new Map();
|
|
3525
|
+
const photos = [...listing.media ?? []].filter(isPhoto).sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
|
|
3526
|
+
for (const photo of photos) {
|
|
3527
|
+
const { key, label } = photoRoomLabel(photo.roomType);
|
|
3528
|
+
const group = groups.get(key);
|
|
3529
|
+
if (group) {
|
|
3530
|
+
group.photos.push(photo);
|
|
3531
|
+
} else {
|
|
3532
|
+
groups.set(key, { key, label, photos: [photo] });
|
|
3533
|
+
}
|
|
3534
|
+
}
|
|
3535
|
+
const ordered = [...groups.values()];
|
|
3536
|
+
const otherIndex = ordered.findIndex((g) => g.key === PHOTO_GROUP_OTHER_KEY);
|
|
3537
|
+
if (otherIndex >= 0 && otherIndex !== ordered.length - 1) {
|
|
3538
|
+
const [other] = ordered.splice(otherIndex, 1);
|
|
3539
|
+
ordered.push(other);
|
|
3540
|
+
}
|
|
3541
|
+
return ordered;
|
|
3542
|
+
}
|
|
3543
|
+
function listingVisualHighlights(listing, options) {
|
|
3544
|
+
const limit = Math.max(0, Math.floor(options?.limit ?? 8));
|
|
3545
|
+
if (limit === 0) return [];
|
|
3546
|
+
const counts = /* @__PURE__ */ new Map();
|
|
3547
|
+
let seen = 0;
|
|
3548
|
+
for (const item of listing.media ?? []) {
|
|
3549
|
+
if (!isPhoto(item) || !Array.isArray(item.features)) continue;
|
|
3550
|
+
for (const feature of item.features) {
|
|
3551
|
+
if (typeof feature !== "string") continue;
|
|
3552
|
+
const text = feature.trim();
|
|
3553
|
+
if (!text) continue;
|
|
3554
|
+
const key = normalizeRoomLabel(text);
|
|
3555
|
+
if (!key) continue;
|
|
3556
|
+
const entry = counts.get(key);
|
|
3557
|
+
if (entry) {
|
|
3558
|
+
entry.count += 1;
|
|
3559
|
+
} else {
|
|
3560
|
+
counts.set(key, { text, count: 1, seen: seen++ });
|
|
3561
|
+
}
|
|
3562
|
+
}
|
|
3563
|
+
}
|
|
3564
|
+
return [...counts.values()].sort((a, b) => b.count - a.count || a.seen - b.seen).slice(0, limit).map((entry) => entry.text);
|
|
3565
|
+
}
|
|
3566
|
+
|
|
3567
|
+
// src/fetchers-market.ts
|
|
3568
|
+
var RATE_LIMITED_MESSAGE = "Muitas consultas em pouco tempo. Tente novamente em instantes.";
|
|
3569
|
+
function isRateLimited(error) {
|
|
3570
|
+
return error instanceof GaragemSdkError && error.status === 429;
|
|
3571
|
+
}
|
|
3572
|
+
async function getNeighborhoodSummary(options) {
|
|
3573
|
+
const { query, baseUrl, fetch: fetchImpl, next } = options;
|
|
3574
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
3575
|
+
if (!query?.city?.trim() || !query?.neighborhood?.trim()) {
|
|
3576
|
+
throw new TypeError(
|
|
3577
|
+
"getNeighborhoodSummary: `query.city` and `query.neighborhood` are required"
|
|
3578
|
+
);
|
|
3579
|
+
}
|
|
3580
|
+
const base = normalizeBaseUrl(baseUrl);
|
|
3581
|
+
const params = new URLSearchParams();
|
|
3582
|
+
params.set("city", query.city.trim());
|
|
3583
|
+
params.set("neighborhood", query.neighborhood.trim());
|
|
3584
|
+
if (query.propertyType) params.set("propertyType", query.propertyType);
|
|
3585
|
+
if (query.type) params.set("type", query.type);
|
|
3586
|
+
const url = `${base}/api/sites/${encodeURIComponent(siteId)}/market/neighborhood-summary?${params.toString()}`;
|
|
3587
|
+
try {
|
|
3588
|
+
return await callJson(
|
|
3589
|
+
url,
|
|
3590
|
+
{ method: "GET", headers: { Accept: "application/json" }, next },
|
|
3591
|
+
fetchImpl ?? fetch
|
|
3592
|
+
);
|
|
3593
|
+
} catch (error) {
|
|
3594
|
+
if (!isRateLimited(error)) throw error;
|
|
3595
|
+
return {
|
|
3596
|
+
available: false,
|
|
3597
|
+
reason: "rate_limited",
|
|
3598
|
+
city: query.city,
|
|
3599
|
+
neighborhood: query.neighborhood,
|
|
3600
|
+
propertyType: query.propertyType ?? null,
|
|
3601
|
+
type: query.type ?? "sale",
|
|
3602
|
+
months: 12,
|
|
3603
|
+
pricePerSqmCents: { p25: null, p50: null, p75: null },
|
|
3604
|
+
pricePerSqmFormatted: { p25: "\u2014", p50: "\u2014", p75: "\u2014" },
|
|
3605
|
+
sampleSize: null,
|
|
3606
|
+
message: RATE_LIMITED_MESSAGE
|
|
3607
|
+
};
|
|
3608
|
+
}
|
|
3609
|
+
}
|
|
3610
|
+
async function getListingMarketPosition(options) {
|
|
3611
|
+
const { listingId: rawListingId, baseUrl, fetch: fetchImpl, next } = options;
|
|
3612
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
3613
|
+
const listingId = listingLookupKey(rawListingId ?? "");
|
|
3614
|
+
if (!listingId || listingId === "undefined" || listingId === "null") {
|
|
3615
|
+
throw new TypeError("getListingMarketPosition: `listingId` is required");
|
|
3616
|
+
}
|
|
3617
|
+
const base = normalizeBaseUrl(baseUrl);
|
|
3618
|
+
const url = `${base}/api/sites/${encodeURIComponent(siteId)}/listings/${encodeURIComponent(
|
|
3619
|
+
listingId
|
|
3620
|
+
)}/market-position`;
|
|
3621
|
+
try {
|
|
3622
|
+
return await callJson(
|
|
3623
|
+
url,
|
|
3624
|
+
{ method: "GET", headers: { Accept: "application/json" }, next },
|
|
3625
|
+
fetchImpl ?? fetch
|
|
3626
|
+
);
|
|
3627
|
+
} catch (error) {
|
|
3628
|
+
if (!isRateLimited(error)) throw error;
|
|
3629
|
+
return {
|
|
3630
|
+
available: false,
|
|
3631
|
+
reason: "rate_limited",
|
|
3632
|
+
listingId,
|
|
3633
|
+
city: null,
|
|
3634
|
+
neighborhood: null,
|
|
3635
|
+
months: 12,
|
|
3636
|
+
listingPricePerSqmCents: null,
|
|
3637
|
+
listingPricePerSqmFormatted: "\u2014",
|
|
3638
|
+
medianPricePerSqmCents: null,
|
|
3639
|
+
medianPricePerSqmFormatted: "\u2014",
|
|
3640
|
+
percentVsMedian: null,
|
|
3641
|
+
band: null,
|
|
3642
|
+
sampleSize: null,
|
|
3643
|
+
message: RATE_LIMITED_MESSAGE
|
|
3644
|
+
};
|
|
3645
|
+
}
|
|
3646
|
+
}
|
|
3647
|
+
async function requestPriceEstimate(options) {
|
|
3648
|
+
const { input, baseUrl, fetch: fetchImpl, next } = options;
|
|
3649
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
3650
|
+
if (!input?.city?.trim() || typeof input.areaSqm !== "number") {
|
|
3651
|
+
throw new TypeError(
|
|
3652
|
+
"requestPriceEstimate: `input.city` and `input.areaSqm` are required"
|
|
3653
|
+
);
|
|
3654
|
+
}
|
|
3655
|
+
const base = normalizeBaseUrl(baseUrl);
|
|
3656
|
+
const url = `${base}/api/sites/${encodeURIComponent(siteId)}/market/estimate`;
|
|
3657
|
+
try {
|
|
3658
|
+
return await callJson(
|
|
3659
|
+
url,
|
|
3660
|
+
{
|
|
3661
|
+
method: "POST",
|
|
3662
|
+
headers: {
|
|
3663
|
+
Accept: "application/json",
|
|
3664
|
+
"Content-Type": "application/json"
|
|
3665
|
+
},
|
|
3666
|
+
body: JSON.stringify(input),
|
|
3667
|
+
next
|
|
3668
|
+
},
|
|
3669
|
+
fetchImpl ?? fetch
|
|
3670
|
+
);
|
|
3671
|
+
} catch (error) {
|
|
3672
|
+
if (!isRateLimited(error)) throw error;
|
|
3673
|
+
return {
|
|
3674
|
+
available: false,
|
|
3675
|
+
reason: "rate_limited",
|
|
3676
|
+
city: input.city,
|
|
3677
|
+
neighborhood: input.neighborhood ?? null,
|
|
3678
|
+
estimatedPriceCents: null,
|
|
3679
|
+
estimatedPriceFormatted: "\u2014",
|
|
3680
|
+
rangeLowCents: null,
|
|
3681
|
+
rangeHighCents: null,
|
|
3682
|
+
rangeLowFormatted: "\u2014",
|
|
3683
|
+
rangeHighFormatted: "\u2014",
|
|
3684
|
+
confidenceLabel: null,
|
|
3685
|
+
sampleSize: null,
|
|
3686
|
+
message: RATE_LIMITED_MESSAGE
|
|
3687
|
+
};
|
|
3688
|
+
}
|
|
3689
|
+
}
|
|
3690
|
+
|
|
3691
|
+
// src/market-labels.ts
|
|
3692
|
+
function marketPositionLabel(position) {
|
|
3693
|
+
if (!position?.available) return null;
|
|
3694
|
+
const percent = position.percentVsMedian;
|
|
3695
|
+
if (percent == null || !Number.isFinite(percent)) return null;
|
|
3696
|
+
const rounded = Math.round(percent);
|
|
3697
|
+
if (rounded === 0) return "Na mediana do bairro";
|
|
3698
|
+
const magnitude = Math.abs(rounded);
|
|
3699
|
+
return rounded < 0 ? `${magnitude}% abaixo da mediana do bairro` : `${magnitude}% acima da mediana do bairro`;
|
|
3700
|
+
}
|
|
3701
|
+
var BAND_LABELS = {
|
|
3702
|
+
below_range: "Abaixo da faixa do bairro",
|
|
3703
|
+
lower_range: "Na faixa do bairro, abaixo da mediana",
|
|
3704
|
+
upper_range: "Na faixa do bairro, acima da mediana",
|
|
3705
|
+
above_range: "Acima da faixa do bairro"
|
|
3706
|
+
};
|
|
3707
|
+
function priceBandLabel(input) {
|
|
3708
|
+
if (!input) return null;
|
|
3709
|
+
if (typeof input === "string") return BAND_LABELS[input] ?? null;
|
|
3710
|
+
if (!input.available || !input.band) return null;
|
|
3711
|
+
return BAND_LABELS[input.band] ?? null;
|
|
3712
|
+
}
|
|
3713
|
+
|
|
3714
|
+
// src/fetchers-photo-search.ts
|
|
3715
|
+
var PHOTO_SEARCH_MIN_QUERY_LENGTH = 3;
|
|
3716
|
+
var EMPTY_RESULT = {
|
|
3717
|
+
available: true,
|
|
3718
|
+
items: [],
|
|
3719
|
+
total: 0,
|
|
3720
|
+
page: 1,
|
|
3721
|
+
limit: 12
|
|
3722
|
+
};
|
|
3723
|
+
function positiveInt(value) {
|
|
3724
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < 1) {
|
|
3725
|
+
return null;
|
|
3726
|
+
}
|
|
3727
|
+
return Math.floor(value);
|
|
3728
|
+
}
|
|
3729
|
+
function photoSearchUrl(siteId, params, baseUrl) {
|
|
3730
|
+
const search = new URLSearchParams();
|
|
3731
|
+
search.set("q", params.q.trim());
|
|
3732
|
+
const limit = positiveInt(params.limit);
|
|
3733
|
+
if (limit != null) search.set("limit", String(limit));
|
|
3734
|
+
const page = positiveInt(params.page);
|
|
3735
|
+
if (page != null) search.set("page", String(page));
|
|
3736
|
+
return `${normalizeBaseUrl(baseUrl)}/api/sites/${encodeURIComponent(
|
|
3737
|
+
siteId
|
|
3738
|
+
)}/search/photos?${search.toString()}`;
|
|
3739
|
+
}
|
|
3740
|
+
async function searchListingPhotos(siteId, params, options = {}) {
|
|
3741
|
+
const q = (params?.q ?? "").trim();
|
|
3742
|
+
const limit = positiveInt(params?.limit) ?? EMPTY_RESULT.limit;
|
|
3743
|
+
if (q.length < PHOTO_SEARCH_MIN_QUERY_LENGTH) {
|
|
3744
|
+
return { ...EMPTY_RESULT, limit, page: positiveInt(params?.page) ?? 1 };
|
|
3745
|
+
}
|
|
3746
|
+
const resolvedSiteId = await coerceSiteId(siteId);
|
|
3747
|
+
const url = photoSearchUrl(resolvedSiteId, { ...params, q }, options.baseUrl);
|
|
3748
|
+
const data = await callJson(
|
|
3749
|
+
url,
|
|
3750
|
+
{
|
|
3751
|
+
method: "GET",
|
|
3752
|
+
headers: { Accept: "application/json" },
|
|
3753
|
+
next: options.next
|
|
3754
|
+
},
|
|
3755
|
+
options.fetch ?? fetch
|
|
3756
|
+
);
|
|
3757
|
+
const items = Array.isArray(data.items) ? data.items : [];
|
|
3758
|
+
return {
|
|
3759
|
+
available: data.available !== false,
|
|
3760
|
+
items,
|
|
3761
|
+
total: typeof data.total === "number" ? data.total : items.length,
|
|
3762
|
+
page: typeof data.page === "number" ? data.page : positiveInt(params.page) ?? 1,
|
|
3763
|
+
limit: typeof data.limit === "number" ? data.limit : limit
|
|
3764
|
+
};
|
|
3765
|
+
}
|
|
3766
|
+
|
|
3767
|
+
// src/photo-search-cover.ts
|
|
3768
|
+
var MATCHED_PHOTO_COVER_MAX_DISTANCE = 0.4;
|
|
3769
|
+
function resolveMatchedCoverPhoto(photo, maxDistance = MATCHED_PHOTO_COVER_MAX_DISTANCE) {
|
|
3770
|
+
if (!photo || !photo.src) return null;
|
|
3771
|
+
if (photo.distance == null) return photo;
|
|
3772
|
+
if (!Number.isFinite(photo.distance)) return null;
|
|
3773
|
+
return photo.distance <= maxDistance ? photo : null;
|
|
3774
|
+
}
|
|
3775
|
+
function itemsOf(photoResults) {
|
|
3776
|
+
if (!photoResults) return [];
|
|
3777
|
+
return Array.isArray(photoResults) ? photoResults : photoResults.items ?? [];
|
|
3778
|
+
}
|
|
3779
|
+
function applyMatchedPhotoCover(cards, photoResults, options = {}) {
|
|
3780
|
+
const maxDistance = options.maxDistance ?? MATCHED_PHOTO_COVER_MAX_DISTANCE;
|
|
3781
|
+
const photoByListingId = /* @__PURE__ */ new Map();
|
|
3782
|
+
for (const item of itemsOf(photoResults)) {
|
|
3783
|
+
const id = item?.listing?.id;
|
|
3784
|
+
if (!id || photoByListingId.has(id)) continue;
|
|
3785
|
+
const photo = resolveMatchedCoverPhoto(item.matchedPhoto, maxDistance);
|
|
3786
|
+
if (photo) photoByListingId.set(id, photo);
|
|
3787
|
+
}
|
|
3788
|
+
return cards.map((card) => {
|
|
3789
|
+
const photo = photoByListingId.get(card.id) ?? null;
|
|
3790
|
+
if (!photo) return { ...card, matchedPhoto: null };
|
|
3791
|
+
return {
|
|
3792
|
+
...card,
|
|
3793
|
+
coverImage: {
|
|
3794
|
+
src: photo.src,
|
|
3795
|
+
alt: photo.alt || card.coverImage?.alt || card.title
|
|
3796
|
+
},
|
|
3797
|
+
matchedPhoto: photo
|
|
3798
|
+
};
|
|
3799
|
+
});
|
|
3800
|
+
}
|
|
3005
3801
|
export {
|
|
3006
3802
|
AMENITY_FALLBACK_LABELS,
|
|
3007
3803
|
DEFAULT_PHONE_COUNTRY_CODE,
|
|
@@ -3010,8 +3806,12 @@ export {
|
|
|
3010
3806
|
LISTING_AMENITY_TITLES,
|
|
3011
3807
|
LISTING_DESCRIPTION_CLAMP,
|
|
3012
3808
|
LeadSubmitError,
|
|
3809
|
+
MATCHED_PHOTO_COVER_MAX_DISTANCE,
|
|
3013
3810
|
MAX_NATIONAL_PHONE_DIGITS,
|
|
3014
3811
|
PHONE_COUNTRIES,
|
|
3812
|
+
PHOTO_GROUP_OTHER_KEY,
|
|
3813
|
+
PHOTO_GROUP_OTHER_LABEL,
|
|
3814
|
+
PHOTO_SEARCH_MIN_QUERY_LENGTH,
|
|
3015
3815
|
SEARCH_EMPTY_COPY,
|
|
3016
3816
|
SEARCH_SORT_RELEVANCE,
|
|
3017
3817
|
STUDIO_DEFAULT_VISIT_SCHEDULE,
|
|
@@ -3020,6 +3820,7 @@ export {
|
|
|
3020
3820
|
STUDIO_SITE_LAYOUT,
|
|
3021
3821
|
TOOLBAR_PRIMARY_FILTER_IDS,
|
|
3022
3822
|
VISIT_TIME_ZONE,
|
|
3823
|
+
applyMatchedPhotoCover,
|
|
3023
3824
|
applyPathFilter,
|
|
3024
3825
|
buildQueryListingsParams,
|
|
3025
3826
|
canonicalizeSearchHref,
|
|
@@ -3031,6 +3832,7 @@ export {
|
|
|
3031
3832
|
composeSearchPublicPath2 as composeSearchPublicPath,
|
|
3032
3833
|
countFacetChoices,
|
|
3033
3834
|
countOptionLabel,
|
|
3835
|
+
createClient,
|
|
3034
3836
|
createGaragemClient,
|
|
3035
3837
|
defaultPhoneCountry,
|
|
3036
3838
|
displayPathLocation,
|
|
@@ -3047,8 +3849,11 @@ export {
|
|
|
3047
3849
|
getCmsEntry,
|
|
3048
3850
|
getLeadUi,
|
|
3049
3851
|
getListing,
|
|
3852
|
+
getListingMarketPosition,
|
|
3050
3853
|
getListings,
|
|
3854
|
+
getNeighborhoodSummary,
|
|
3051
3855
|
getSearchUi,
|
|
3856
|
+
getSimilarByPhoto,
|
|
3052
3857
|
getSimilarListings,
|
|
3053
3858
|
getSite,
|
|
3054
3859
|
hasShowcaseLeadsPostUrl,
|
|
@@ -3056,6 +3861,7 @@ export {
|
|
|
3056
3861
|
hrefForPathFilters,
|
|
3057
3862
|
hrefWithExplicitPage,
|
|
3058
3863
|
isListingDetailPath,
|
|
3864
|
+
isPhotoSearchOnPin,
|
|
3059
3865
|
isStudioPreviewHost,
|
|
3060
3866
|
isValidPhone,
|
|
3061
3867
|
isVisitSlotAllowed,
|
|
@@ -3072,8 +3878,12 @@ export {
|
|
|
3072
3878
|
listingLookupKey,
|
|
3073
3879
|
listingMapsHref,
|
|
3074
3880
|
listingMediaOverlays,
|
|
3881
|
+
listingPhotoGroups,
|
|
3075
3882
|
listingPublicPath,
|
|
3076
3883
|
listingValues,
|
|
3884
|
+
listingVisualHighlights,
|
|
3885
|
+
marketExportsAvailableAt,
|
|
3886
|
+
marketPositionLabel,
|
|
3077
3887
|
mergeAppliedSearchQueryIntoSearch2 as mergeAppliedSearchQueryIntoSearch,
|
|
3078
3888
|
nationalPhoneDigits,
|
|
3079
3889
|
normalizeVisitDate,
|
|
@@ -3089,15 +3899,21 @@ export {
|
|
|
3089
3899
|
pathFiltersToQueryFilters,
|
|
3090
3900
|
pathLocationToFilterInput,
|
|
3091
3901
|
phoneCountrySearchValue,
|
|
3902
|
+
photoRoomLabel,
|
|
3903
|
+
photoSearchUrl,
|
|
3904
|
+
priceBandLabel,
|
|
3092
3905
|
publicSearchHref,
|
|
3093
3906
|
queryListings,
|
|
3094
3907
|
rangeDraftFromPath,
|
|
3095
3908
|
readPublicSearch,
|
|
3096
3909
|
reduceAppliedSearchQuery2 as reduceAppliedSearchQuery,
|
|
3097
3910
|
remaskPhoneForCountry,
|
|
3911
|
+
requestPriceEstimate,
|
|
3912
|
+
resolveMatchedCoverPhoto,
|
|
3098
3913
|
resolvePublicSiteId,
|
|
3099
3914
|
searchChromeModel,
|
|
3100
3915
|
searchHrefUsesLegacyFilterQuery,
|
|
3916
|
+
searchListingPhotos,
|
|
3101
3917
|
searchListings,
|
|
3102
3918
|
searchResultsHeading,
|
|
3103
3919
|
searchSortOptions,
|
|
@@ -3111,6 +3927,11 @@ export {
|
|
|
3111
3927
|
studioLeadInstruction,
|
|
3112
3928
|
studioListingCardInstruction,
|
|
3113
3929
|
studioListingDetailInstruction,
|
|
3930
|
+
studioMarketInstruction,
|
|
3931
|
+
studioPhotoInstruction,
|
|
3932
|
+
studioPhotoInstructionFor,
|
|
3933
|
+
studioPhotoSearchInstruction,
|
|
3934
|
+
studioPublishableKeyInstruction,
|
|
3114
3935
|
studioSdkPinInstruction,
|
|
3115
3936
|
studioSearchInstruction,
|
|
3116
3937
|
studioSearchLandmarkInstruction,
|