@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.js
CHANGED
|
@@ -27,8 +27,12 @@ __export(src_exports, {
|
|
|
27
27
|
LISTING_AMENITY_TITLES: () => LISTING_AMENITY_TITLES,
|
|
28
28
|
LISTING_DESCRIPTION_CLAMP: () => LISTING_DESCRIPTION_CLAMP,
|
|
29
29
|
LeadSubmitError: () => LeadSubmitError,
|
|
30
|
+
MATCHED_PHOTO_COVER_MAX_DISTANCE: () => MATCHED_PHOTO_COVER_MAX_DISTANCE,
|
|
30
31
|
MAX_NATIONAL_PHONE_DIGITS: () => MAX_NATIONAL_PHONE_DIGITS,
|
|
31
32
|
PHONE_COUNTRIES: () => PHONE_COUNTRIES,
|
|
33
|
+
PHOTO_GROUP_OTHER_KEY: () => PHOTO_GROUP_OTHER_KEY,
|
|
34
|
+
PHOTO_GROUP_OTHER_LABEL: () => PHOTO_GROUP_OTHER_LABEL,
|
|
35
|
+
PHOTO_SEARCH_MIN_QUERY_LENGTH: () => PHOTO_SEARCH_MIN_QUERY_LENGTH,
|
|
32
36
|
SEARCH_EMPTY_COPY: () => SEARCH_EMPTY_COPY,
|
|
33
37
|
SEARCH_SORT_RELEVANCE: () => SEARCH_SORT_RELEVANCE,
|
|
34
38
|
STUDIO_DEFAULT_VISIT_SCHEDULE: () => STUDIO_DEFAULT_VISIT_SCHEDULE,
|
|
@@ -37,6 +41,7 @@ __export(src_exports, {
|
|
|
37
41
|
STUDIO_SITE_LAYOUT: () => STUDIO_SITE_LAYOUT,
|
|
38
42
|
TOOLBAR_PRIMARY_FILTER_IDS: () => TOOLBAR_PRIMARY_FILTER_IDS,
|
|
39
43
|
VISIT_TIME_ZONE: () => VISIT_TIME_ZONE,
|
|
44
|
+
applyMatchedPhotoCover: () => applyMatchedPhotoCover,
|
|
40
45
|
applyPathFilter: () => applyPathFilter,
|
|
41
46
|
buildQueryListingsParams: () => buildQueryListingsParams,
|
|
42
47
|
canonicalizeSearchHref: () => canonicalizeSearchHref,
|
|
@@ -48,6 +53,7 @@ __export(src_exports, {
|
|
|
48
53
|
composeSearchPublicPath: () => composeSearchPublicPath2,
|
|
49
54
|
countFacetChoices: () => countFacetChoices,
|
|
50
55
|
countOptionLabel: () => countOptionLabel,
|
|
56
|
+
createClient: () => createClient,
|
|
51
57
|
createGaragemClient: () => createGaragemClient,
|
|
52
58
|
defaultPhoneCountry: () => defaultPhoneCountry,
|
|
53
59
|
displayPathLocation: () => displayPathLocation,
|
|
@@ -64,8 +70,11 @@ __export(src_exports, {
|
|
|
64
70
|
getCmsEntry: () => getCmsEntry,
|
|
65
71
|
getLeadUi: () => getLeadUi,
|
|
66
72
|
getListing: () => getListing,
|
|
73
|
+
getListingMarketPosition: () => getListingMarketPosition,
|
|
67
74
|
getListings: () => getListings,
|
|
75
|
+
getNeighborhoodSummary: () => getNeighborhoodSummary,
|
|
68
76
|
getSearchUi: () => getSearchUi,
|
|
77
|
+
getSimilarByPhoto: () => getSimilarByPhoto,
|
|
69
78
|
getSimilarListings: () => getSimilarListings,
|
|
70
79
|
getSite: () => getSite,
|
|
71
80
|
hasShowcaseLeadsPostUrl: () => hasShowcaseLeadsPostUrl,
|
|
@@ -73,6 +82,7 @@ __export(src_exports, {
|
|
|
73
82
|
hrefForPathFilters: () => hrefForPathFilters,
|
|
74
83
|
hrefWithExplicitPage: () => hrefWithExplicitPage,
|
|
75
84
|
isListingDetailPath: () => isListingDetailPath,
|
|
85
|
+
isPhotoSearchOnPin: () => isPhotoSearchOnPin,
|
|
76
86
|
isStudioPreviewHost: () => isStudioPreviewHost,
|
|
77
87
|
isValidPhone: () => isValidPhone,
|
|
78
88
|
isVisitSlotAllowed: () => isVisitSlotAllowed,
|
|
@@ -89,8 +99,12 @@ __export(src_exports, {
|
|
|
89
99
|
listingLookupKey: () => listingLookupKey,
|
|
90
100
|
listingMapsHref: () => listingMapsHref,
|
|
91
101
|
listingMediaOverlays: () => listingMediaOverlays,
|
|
102
|
+
listingPhotoGroups: () => listingPhotoGroups,
|
|
92
103
|
listingPublicPath: () => listingPublicPath,
|
|
93
104
|
listingValues: () => listingValues,
|
|
105
|
+
listingVisualHighlights: () => listingVisualHighlights,
|
|
106
|
+
marketExportsAvailableAt: () => marketExportsAvailableAt,
|
|
107
|
+
marketPositionLabel: () => marketPositionLabel,
|
|
94
108
|
mergeAppliedSearchQueryIntoSearch: () => mergeAppliedSearchQueryIntoSearch2,
|
|
95
109
|
nationalPhoneDigits: () => nationalPhoneDigits,
|
|
96
110
|
normalizeVisitDate: () => normalizeVisitDate,
|
|
@@ -106,15 +120,21 @@ __export(src_exports, {
|
|
|
106
120
|
pathFiltersToQueryFilters: () => pathFiltersToQueryFilters,
|
|
107
121
|
pathLocationToFilterInput: () => pathLocationToFilterInput,
|
|
108
122
|
phoneCountrySearchValue: () => phoneCountrySearchValue,
|
|
123
|
+
photoRoomLabel: () => photoRoomLabel,
|
|
124
|
+
photoSearchUrl: () => photoSearchUrl,
|
|
125
|
+
priceBandLabel: () => priceBandLabel,
|
|
109
126
|
publicSearchHref: () => publicSearchHref,
|
|
110
127
|
queryListings: () => queryListings,
|
|
111
128
|
rangeDraftFromPath: () => rangeDraftFromPath,
|
|
112
129
|
readPublicSearch: () => readPublicSearch,
|
|
113
130
|
reduceAppliedSearchQuery: () => reduceAppliedSearchQuery2,
|
|
114
131
|
remaskPhoneForCountry: () => remaskPhoneForCountry,
|
|
132
|
+
requestPriceEstimate: () => requestPriceEstimate,
|
|
133
|
+
resolveMatchedCoverPhoto: () => resolveMatchedCoverPhoto,
|
|
115
134
|
resolvePublicSiteId: () => resolvePublicSiteId,
|
|
116
135
|
searchChromeModel: () => searchChromeModel,
|
|
117
136
|
searchHrefUsesLegacyFilterQuery: () => searchHrefUsesLegacyFilterQuery,
|
|
137
|
+
searchListingPhotos: () => searchListingPhotos,
|
|
118
138
|
searchListings: () => searchListings,
|
|
119
139
|
searchResultsHeading: () => searchResultsHeading,
|
|
120
140
|
searchSortOptions: () => searchSortOptions,
|
|
@@ -128,6 +148,11 @@ __export(src_exports, {
|
|
|
128
148
|
studioLeadInstruction: () => studioLeadInstruction,
|
|
129
149
|
studioListingCardInstruction: () => studioListingCardInstruction,
|
|
130
150
|
studioListingDetailInstruction: () => studioListingDetailInstruction,
|
|
151
|
+
studioMarketInstruction: () => studioMarketInstruction,
|
|
152
|
+
studioPhotoInstruction: () => studioPhotoInstruction,
|
|
153
|
+
studioPhotoInstructionFor: () => studioPhotoInstructionFor,
|
|
154
|
+
studioPhotoSearchInstruction: () => studioPhotoSearchInstruction,
|
|
155
|
+
studioPublishableKeyInstruction: () => studioPublishableKeyInstruction,
|
|
131
156
|
studioSdkPinInstruction: () => studioSdkPinInstruction,
|
|
132
157
|
studioSearchInstruction: () => studioSearchInstruction,
|
|
133
158
|
studioSearchLandmarkInstruction: () => studioSearchLandmarkInstruction,
|
|
@@ -157,6 +182,90 @@ function listingPublicPath(listing) {
|
|
|
157
182
|
return `/imoveis/id-${identity}`;
|
|
158
183
|
}
|
|
159
184
|
|
|
185
|
+
// src/internal/sdk-http.ts
|
|
186
|
+
var PUBLISHABLE_KEY_HEADER = "X-Garagem-Publishable-Key";
|
|
187
|
+
function publishableKeyHeaders(publishableKey) {
|
|
188
|
+
const key = publishableKey?.trim();
|
|
189
|
+
if (!key) return {};
|
|
190
|
+
return { [PUBLISHABLE_KEY_HEADER]: key };
|
|
191
|
+
}
|
|
192
|
+
function withPublishableKeyHeader(init, publishableKey) {
|
|
193
|
+
const extra = publishableKeyHeaders(publishableKey);
|
|
194
|
+
if (Object.keys(extra).length === 0) return init;
|
|
195
|
+
const current = init.headers;
|
|
196
|
+
const base = plainHeaders(current);
|
|
197
|
+
return { ...init, headers: { ...base, ...extra } };
|
|
198
|
+
}
|
|
199
|
+
function plainHeaders(headers) {
|
|
200
|
+
const out = {};
|
|
201
|
+
if (!headers) return out;
|
|
202
|
+
if (typeof Headers !== "undefined" && headers instanceof Headers) {
|
|
203
|
+
headers.forEach((value, name) => {
|
|
204
|
+
out[name] = value;
|
|
205
|
+
});
|
|
206
|
+
return out;
|
|
207
|
+
}
|
|
208
|
+
if (Array.isArray(headers)) {
|
|
209
|
+
for (const pair of headers) {
|
|
210
|
+
out[String(pair[0])] = String(pair[1]);
|
|
211
|
+
}
|
|
212
|
+
return out;
|
|
213
|
+
}
|
|
214
|
+
for (const [name, value] of Object.entries(
|
|
215
|
+
headers
|
|
216
|
+
)) {
|
|
217
|
+
if (typeof value === "string") out[name] = value;
|
|
218
|
+
}
|
|
219
|
+
return out;
|
|
220
|
+
}
|
|
221
|
+
function finiteNonNegative(value) {
|
|
222
|
+
if (typeof value === "number" && Number.isFinite(value) && value >= 0) {
|
|
223
|
+
return value;
|
|
224
|
+
}
|
|
225
|
+
if (typeof value === "string" && value.trim()) {
|
|
226
|
+
const parsed = Number(value);
|
|
227
|
+
if (Number.isFinite(parsed) && parsed >= 0) return parsed;
|
|
228
|
+
}
|
|
229
|
+
return null;
|
|
230
|
+
}
|
|
231
|
+
function parseSdkErrorBody(text) {
|
|
232
|
+
const raw = text ? text.slice(0, 200) : "";
|
|
233
|
+
if (!text) {
|
|
234
|
+
return { reason: null, retryAfterSeconds: null, summary: "" };
|
|
235
|
+
}
|
|
236
|
+
try {
|
|
237
|
+
const body = JSON.parse(text);
|
|
238
|
+
if (!body || typeof body !== "object") {
|
|
239
|
+
return { reason: null, retryAfterSeconds: null, summary: raw };
|
|
240
|
+
}
|
|
241
|
+
const record = body;
|
|
242
|
+
const reason = typeof record.reason === "string" && record.reason ? record.reason : null;
|
|
243
|
+
const retryAfterSeconds = finiteNonNegative(
|
|
244
|
+
record.retryAfterSeconds ?? record.retryAfter
|
|
245
|
+
);
|
|
246
|
+
const errorText = typeof record.error === "string" && record.error ? record.error : raw;
|
|
247
|
+
return {
|
|
248
|
+
reason,
|
|
249
|
+
retryAfterSeconds,
|
|
250
|
+
summary: errorText.slice(0, 200)
|
|
251
|
+
};
|
|
252
|
+
} catch {
|
|
253
|
+
return { reason: null, retryAfterSeconds: null, summary: raw };
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
function retryAfterFromResponse(response, bodySeconds, nowMs = Date.now()) {
|
|
257
|
+
const header = response.headers.get("Retry-After")?.trim();
|
|
258
|
+
if (header) {
|
|
259
|
+
const delta = finiteNonNegative(header);
|
|
260
|
+
if (delta != null) return delta;
|
|
261
|
+
const at = Date.parse(header);
|
|
262
|
+
if (Number.isFinite(at)) {
|
|
263
|
+
return Math.max(0, Math.ceil((at - nowMs) / 1e3));
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return bodySeconds;
|
|
267
|
+
}
|
|
268
|
+
|
|
160
269
|
// src/internal/url.ts
|
|
161
270
|
var DEFAULT_BASE_URL = "https://app.garagem.ai";
|
|
162
271
|
var DEFAULT_RESOLVE_BASE_URL = "https://cdn.fndn.ai/site";
|
|
@@ -191,27 +300,50 @@ function buildListingFiltersQuery(filters) {
|
|
|
191
300
|
}
|
|
192
301
|
|
|
193
302
|
// src/fetchers.ts
|
|
194
|
-
async function callJson(url, init, fetchImpl) {
|
|
195
|
-
const response = await fetchImpl(
|
|
303
|
+
async function callJson(url, init, fetchImpl, publishableKey) {
|
|
304
|
+
const response = await fetchImpl(
|
|
305
|
+
url,
|
|
306
|
+
withPublishableKeyHeader(init, publishableKey)
|
|
307
|
+
);
|
|
196
308
|
if (!response.ok) {
|
|
197
|
-
|
|
198
|
-
throw new GaragemSdkError(
|
|
199
|
-
`Garagem SDK: request failed (${response.status} ${response.statusText}) for ${url}${text ? ` \u2014 ${text.slice(0, 200)}` : ""}`,
|
|
200
|
-
{ status: response.status, url }
|
|
201
|
-
);
|
|
309
|
+
throw await readGaragemSdkError(response, url);
|
|
202
310
|
}
|
|
203
311
|
return await response.json();
|
|
204
312
|
}
|
|
205
313
|
var GaragemSdkError = class extends Error {
|
|
206
314
|
status;
|
|
207
315
|
url;
|
|
316
|
+
/** Machine reason from the JSON body (`invalid_publishable_key`, `rate_limited`, …). */
|
|
317
|
+
reason;
|
|
318
|
+
/**
|
|
319
|
+
* Seconds to wait before retrying. Set on HTTP 429 from `Retry-After`
|
|
320
|
+
* or the body's `retryAfterSeconds`. `null` when the response has neither.
|
|
321
|
+
*/
|
|
322
|
+
retryAfter;
|
|
208
323
|
constructor(message, info) {
|
|
209
324
|
super(message);
|
|
210
325
|
this.name = "GaragemSdkError";
|
|
211
326
|
this.status = info.status;
|
|
212
327
|
this.url = info.url;
|
|
328
|
+
this.reason = info.reason ?? null;
|
|
329
|
+
this.retryAfter = info.retryAfter ?? null;
|
|
213
330
|
}
|
|
214
331
|
};
|
|
332
|
+
async function readGaragemSdkError(response, url) {
|
|
333
|
+
const text = await response.text().catch(() => "");
|
|
334
|
+
const parsed = parseSdkErrorBody(text);
|
|
335
|
+
const retryAfter = response.status === 429 ? retryAfterFromResponse(response, parsed.retryAfterSeconds) : parsed.retryAfterSeconds;
|
|
336
|
+
const detail = parsed.summary;
|
|
337
|
+
return new GaragemSdkError(
|
|
338
|
+
`Garagem SDK: request failed (${response.status} ${response.statusText}) for ${url}${detail ? ` \u2014 ${detail}` : ""}`,
|
|
339
|
+
{
|
|
340
|
+
status: response.status,
|
|
341
|
+
url,
|
|
342
|
+
reason: parsed.reason,
|
|
343
|
+
retryAfter
|
|
344
|
+
}
|
|
345
|
+
);
|
|
346
|
+
}
|
|
215
347
|
async function getListings(options) {
|
|
216
348
|
const { filters, baseUrl, fetch: fetchImpl, next } = options;
|
|
217
349
|
const siteId = await coerceSiteId(options.siteId);
|
|
@@ -222,7 +354,8 @@ async function getListings(options) {
|
|
|
222
354
|
const data = await callJson(
|
|
223
355
|
url,
|
|
224
356
|
{ method: "GET", headers: { Accept: "application/json" }, next },
|
|
225
|
-
fetchImpl ?? fetch
|
|
357
|
+
fetchImpl ?? fetch,
|
|
358
|
+
options.publishableKey
|
|
226
359
|
);
|
|
227
360
|
return {
|
|
228
361
|
listings: data.listings ?? [],
|
|
@@ -243,7 +376,8 @@ async function getListing(options) {
|
|
|
243
376
|
return callJson(
|
|
244
377
|
url,
|
|
245
378
|
{ method: "GET", headers: { Accept: "application/json" }, next },
|
|
246
|
-
fetchImpl ?? fetch
|
|
379
|
+
fetchImpl ?? fetch,
|
|
380
|
+
options.publishableKey
|
|
247
381
|
);
|
|
248
382
|
}
|
|
249
383
|
async function getSite(options) {
|
|
@@ -265,17 +399,20 @@ async function getSite(options) {
|
|
|
265
399
|
if (domain) params.set("domain", domain);
|
|
266
400
|
const url = `${base}/api/sites/resolve?${params.toString()}`;
|
|
267
401
|
const f = fetchImpl ?? fetch;
|
|
268
|
-
const response = await f(
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
402
|
+
const response = await f(
|
|
403
|
+
url,
|
|
404
|
+
withPublishableKeyHeader(
|
|
405
|
+
{
|
|
406
|
+
method: "GET",
|
|
407
|
+
headers: { Accept: "application/json" },
|
|
408
|
+
next
|
|
409
|
+
},
|
|
410
|
+
options.publishableKey
|
|
411
|
+
)
|
|
412
|
+
);
|
|
273
413
|
if (response.status === 404) return null;
|
|
274
414
|
if (!response.ok) {
|
|
275
|
-
throw
|
|
276
|
-
`Garagem SDK: getSite failed (${response.status}) for ${url}`,
|
|
277
|
-
{ status: response.status, url }
|
|
278
|
-
);
|
|
415
|
+
throw await readGaragemSdkError(response, url);
|
|
279
416
|
}
|
|
280
417
|
const data = await response.json();
|
|
281
418
|
return {
|
|
@@ -303,7 +440,8 @@ async function searchListings(options) {
|
|
|
303
440
|
body: JSON.stringify(params),
|
|
304
441
|
next
|
|
305
442
|
},
|
|
306
|
-
fetchImpl ?? fetch
|
|
443
|
+
fetchImpl ?? fetch,
|
|
444
|
+
options.publishableKey
|
|
307
445
|
);
|
|
308
446
|
}
|
|
309
447
|
async function getSearchUi(options) {
|
|
@@ -314,7 +452,8 @@ async function getSearchUi(options) {
|
|
|
314
452
|
return callJson(
|
|
315
453
|
url,
|
|
316
454
|
{ method: "GET", headers: { Accept: "application/json" }, next },
|
|
317
|
-
fetchImpl ?? fetch
|
|
455
|
+
fetchImpl ?? fetch,
|
|
456
|
+
options.publishableKey
|
|
318
457
|
);
|
|
319
458
|
}
|
|
320
459
|
async function queryListings(options) {
|
|
@@ -333,7 +472,8 @@ async function queryListings(options) {
|
|
|
333
472
|
body: JSON.stringify(params ?? {}),
|
|
334
473
|
next
|
|
335
474
|
},
|
|
336
|
-
fetchImpl ?? fetch
|
|
475
|
+
fetchImpl ?? fetch,
|
|
476
|
+
options.publishableKey
|
|
337
477
|
);
|
|
338
478
|
}
|
|
339
479
|
async function getSimilarListings(options) {
|
|
@@ -361,7 +501,8 @@ async function getSimilarListings(options) {
|
|
|
361
501
|
const data = await callJson(
|
|
362
502
|
url,
|
|
363
503
|
{ method: "GET", headers: { Accept: "application/json" }, next },
|
|
364
|
-
fetchImpl ?? fetch
|
|
504
|
+
fetchImpl ?? fetch,
|
|
505
|
+
options.publishableKey
|
|
365
506
|
);
|
|
366
507
|
return {
|
|
367
508
|
listings: data.listings ?? [],
|
|
@@ -376,7 +517,8 @@ async function getCmsCollections(options) {
|
|
|
376
517
|
const data = await callJson(
|
|
377
518
|
url,
|
|
378
519
|
{ method: "GET", headers: { Accept: "application/json" }, next },
|
|
379
|
-
fetchImpl ?? fetch
|
|
520
|
+
fetchImpl ?? fetch,
|
|
521
|
+
options.publishableKey
|
|
380
522
|
);
|
|
381
523
|
return data.collections ?? [];
|
|
382
524
|
}
|
|
@@ -393,7 +535,8 @@ async function getCmsCollection(options) {
|
|
|
393
535
|
const data = await callJson(
|
|
394
536
|
url,
|
|
395
537
|
{ method: "GET", headers: { Accept: "application/json" }, next },
|
|
396
|
-
fetchImpl ?? fetch
|
|
538
|
+
fetchImpl ?? fetch,
|
|
539
|
+
options.publishableKey
|
|
397
540
|
);
|
|
398
541
|
if (data && typeof data === "object" && "collection" in data && data.collection) {
|
|
399
542
|
return data.collection;
|
|
@@ -428,7 +571,8 @@ async function getCmsEntries(options) {
|
|
|
428
571
|
const data = await callJson(
|
|
429
572
|
url,
|
|
430
573
|
{ method: "GET", headers: { Accept: "application/json" }, next },
|
|
431
|
-
fetchImpl ?? fetch
|
|
574
|
+
fetchImpl ?? fetch,
|
|
575
|
+
options.publishableKey
|
|
432
576
|
);
|
|
433
577
|
return {
|
|
434
578
|
entries: data.entries ?? [],
|
|
@@ -453,7 +597,8 @@ async function getCmsEntry(options) {
|
|
|
453
597
|
const data = await callJson(
|
|
454
598
|
url,
|
|
455
599
|
{ method: "GET", headers: { Accept: "application/json" }, next },
|
|
456
|
-
fetchImpl ?? fetch
|
|
600
|
+
fetchImpl ?? fetch,
|
|
601
|
+
options.publishableKey
|
|
457
602
|
);
|
|
458
603
|
if (data && typeof data === "object" && "entry" in data && data.entry) {
|
|
459
604
|
return data.entry;
|
|
@@ -984,7 +1129,8 @@ async function resolvePublicSiteId(options) {
|
|
|
984
1129
|
const site = await getSite({
|
|
985
1130
|
domain: host,
|
|
986
1131
|
baseUrl: options.baseUrl,
|
|
987
|
-
fetch: options.fetch
|
|
1132
|
+
fetch: options.fetch,
|
|
1133
|
+
publishableKey: options.publishableKey
|
|
988
1134
|
});
|
|
989
1135
|
if (site?.id) return site.id;
|
|
990
1136
|
throw new GaragemSdkError(
|
|
@@ -1013,7 +1159,8 @@ async function resolveLeadSiteId(input) {
|
|
|
1013
1159
|
return resolvePublicSiteId({
|
|
1014
1160
|
host,
|
|
1015
1161
|
baseUrl: input.baseUrl,
|
|
1016
|
-
fetch: input.fetch
|
|
1162
|
+
fetch: input.fetch,
|
|
1163
|
+
publishableKey: input.publishableKey
|
|
1017
1164
|
});
|
|
1018
1165
|
}
|
|
1019
1166
|
}
|
|
@@ -1021,6 +1168,8 @@ var LeadSubmitError = class extends Error {
|
|
|
1021
1168
|
code;
|
|
1022
1169
|
status;
|
|
1023
1170
|
retryAfterSeconds;
|
|
1171
|
+
/** Seconds to wait. Same value as `retryAfterSeconds`; `null` when unset. */
|
|
1172
|
+
retryAfter;
|
|
1024
1173
|
constructor(message, info) {
|
|
1025
1174
|
super(message);
|
|
1026
1175
|
this.name = "LeadSubmitError";
|
|
@@ -1029,6 +1178,7 @@ var LeadSubmitError = class extends Error {
|
|
|
1029
1178
|
if (info.retryAfterSeconds != null) {
|
|
1030
1179
|
this.retryAfterSeconds = info.retryAfterSeconds;
|
|
1031
1180
|
}
|
|
1181
|
+
this.retryAfter = info.retryAfterSeconds ?? null;
|
|
1032
1182
|
}
|
|
1033
1183
|
};
|
|
1034
1184
|
var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
@@ -1070,7 +1220,8 @@ async function getLeadUi(options) {
|
|
|
1070
1220
|
headers: { Accept: "application/json" },
|
|
1071
1221
|
next: options.next
|
|
1072
1222
|
},
|
|
1073
|
-
options.fetch ?? fetch
|
|
1223
|
+
options.fetch ?? fetch,
|
|
1224
|
+
options.publishableKey
|
|
1074
1225
|
);
|
|
1075
1226
|
}
|
|
1076
1227
|
function assertListingId(listingId) {
|
|
@@ -1143,7 +1294,8 @@ async function postSiteLead(input) {
|
|
|
1143
1294
|
method: "POST",
|
|
1144
1295
|
headers: {
|
|
1145
1296
|
Accept: "application/json",
|
|
1146
|
-
"Content-Type": "application/json"
|
|
1297
|
+
"Content-Type": "application/json",
|
|
1298
|
+
...publishableKeyHeaders(input.publishableKey)
|
|
1147
1299
|
},
|
|
1148
1300
|
body: JSON.stringify(input.body)
|
|
1149
1301
|
});
|
|
@@ -1158,12 +1310,23 @@ async function postSiteLead(input) {
|
|
|
1158
1310
|
const id = typeof data.id === "string" && data.id ? data.id : "";
|
|
1159
1311
|
return { ok: true, status: 202, id };
|
|
1160
1312
|
}
|
|
1161
|
-
|
|
1313
|
+
if (response.status === 401) {
|
|
1314
|
+
throw new LeadSubmitError("Garagem SDK: invalid publishable key.", {
|
|
1315
|
+
code: "unauthorized",
|
|
1316
|
+
status: 401
|
|
1317
|
+
});
|
|
1318
|
+
}
|
|
1162
1319
|
if (response.status === 429) {
|
|
1320
|
+
const text = await response.text().catch(() => "");
|
|
1321
|
+
const parsed = parseSdkErrorBody(text);
|
|
1322
|
+
const retryAfter = retryAfterFromResponse(
|
|
1323
|
+
response,
|
|
1324
|
+
parsed.retryAfterSeconds
|
|
1325
|
+
);
|
|
1163
1326
|
throw new LeadSubmitError("Garagem SDK: too many lead submissions.", {
|
|
1164
1327
|
code: "rate_limited",
|
|
1165
1328
|
status: 429,
|
|
1166
|
-
retryAfterSeconds:
|
|
1329
|
+
...retryAfter != null ? { retryAfterSeconds: retryAfter } : {}
|
|
1167
1330
|
});
|
|
1168
1331
|
}
|
|
1169
1332
|
if (response.status === 404) {
|
|
@@ -1207,6 +1370,7 @@ async function submitVisitLead(input) {
|
|
|
1207
1370
|
siteId: input.siteId,
|
|
1208
1371
|
baseUrl: input.baseUrl,
|
|
1209
1372
|
fetch: input.fetch,
|
|
1373
|
+
publishableKey: input.publishableKey,
|
|
1210
1374
|
body: {
|
|
1211
1375
|
source: "site-sdk",
|
|
1212
1376
|
leadType: "visit",
|
|
@@ -1225,6 +1389,7 @@ async function submitContactLead(input) {
|
|
|
1225
1389
|
siteId: input.siteId,
|
|
1226
1390
|
baseUrl: input.baseUrl,
|
|
1227
1391
|
fetch: input.fetch,
|
|
1392
|
+
publishableKey: input.publishableKey,
|
|
1228
1393
|
body: {
|
|
1229
1394
|
source: "site-sdk",
|
|
1230
1395
|
leadType: "contact",
|
|
@@ -2751,7 +2916,9 @@ var STUDIO_SDK_CONTRACT = {
|
|
|
2751
2916
|
* “never import”) — v0 copies the identifier and the preview ESM loader
|
|
2752
2917
|
* throws FatalRendererError.
|
|
2753
2918
|
*/
|
|
2754
|
-
optionalReactExports: {
|
|
2919
|
+
optionalReactExports: {
|
|
2920
|
+
usePublicPhotoSearch: "0.7.0"
|
|
2921
|
+
},
|
|
2755
2922
|
/**
|
|
2756
2923
|
* Former `/react` chrome (including card/skeleton inject). Completeness
|
|
2757
2924
|
* flags imports as mismatch (not in `reactExports`). Prompts must not
|
|
@@ -2812,6 +2979,29 @@ var STUDIO_SDK_CONTRACT = {
|
|
|
2812
2979
|
*/
|
|
2813
2980
|
unpublishedPhoneExports: [],
|
|
2814
2981
|
amenityExports: ["listingAmenityGroups"],
|
|
2982
|
+
/**
|
|
2983
|
+
* Prompt-safe photo helpers on `minNpmVersion`. Empty until the release
|
|
2984
|
+
* that carries `getSimilarByPhoto` / `listingPhotoGroups` /
|
|
2985
|
+
* `listingVisualHighlights` is on npm; then bump the pin, move the names
|
|
2986
|
+
* here from `unpublishedPhotoExports`, and `studioPhotoInstruction()`
|
|
2987
|
+
* starts teaching the gallery-by-room, highlight chips, and
|
|
2988
|
+
* "imóveis com fotos parecidas" blocks. The caption-based `media[].alt` /
|
|
2989
|
+
* `media[].caption` fields are API data (not tarball exports) and are
|
|
2990
|
+
* documented regardless of the pin.
|
|
2991
|
+
*/
|
|
2992
|
+
photoExports: [],
|
|
2993
|
+
/**
|
|
2994
|
+
* Photo helpers in the repo but not on `minNpmVersion`. Prompts,
|
|
2995
|
+
* completeness, and repair text must not mention these until the pin
|
|
2996
|
+
* bumps — v0 installs the pin and the ESM loader throws on missing named
|
|
2997
|
+
* exports.
|
|
2998
|
+
*/
|
|
2999
|
+
unpublishedPhotoExports: [
|
|
3000
|
+
"getSimilarByPhoto",
|
|
3001
|
+
"listingPhotoGroups",
|
|
3002
|
+
"listingVisualHighlights",
|
|
3003
|
+
"photoRoomLabel"
|
|
3004
|
+
],
|
|
2815
3005
|
/**
|
|
2816
3006
|
* Names already on the pinned npm tarball (`minNpmVersion`) — safe for
|
|
2817
3007
|
* Studio prompts and completeness. Includes `visibleSearchFilters` +
|
|
@@ -2835,8 +3025,43 @@ var STUDIO_SDK_CONTRACT = {
|
|
|
2835
3025
|
unpublishedSearchExports: [
|
|
2836
3026
|
"searchChromeModel",
|
|
2837
3027
|
"rangeDraftFromPath"
|
|
2838
|
-
]
|
|
3028
|
+
],
|
|
3029
|
+
/**
|
|
3030
|
+
* Market-data helpers (neighborhood price summary, listing market
|
|
3031
|
+
* position, visitor price estimate, pt-BR labels). They ship in
|
|
3032
|
+
* `marketExportsSince` and are prompt-safe only once `minNpmVersion`
|
|
3033
|
+
* reaches that release; below it `studioCodegenContractViolations` flags
|
|
3034
|
+
* the names and `studioMarketInstruction()` tells Studio not to generate
|
|
3035
|
+
* the blocks at all. Every helper answers `available: false` unless the
|
|
3036
|
+
* site's organization holds the IPTU module (`iptu_itbi_integration`)
|
|
3037
|
+
* and the city is covered — generated sites render these blocks
|
|
3038
|
+
* conditionally and never show cadastral or transaction data.
|
|
3039
|
+
*/
|
|
3040
|
+
marketExports: [
|
|
3041
|
+
"getNeighborhoodSummary",
|
|
3042
|
+
"getListingMarketPosition",
|
|
3043
|
+
"requestPriceEstimate",
|
|
3044
|
+
"marketPositionLabel",
|
|
3045
|
+
"priceBandLabel"
|
|
3046
|
+
],
|
|
3047
|
+
marketExportsSince: "0.7.0",
|
|
3048
|
+
/**
|
|
3049
|
+
* Photo search ("busca pelo que as fotos mostram"): main-package helpers
|
|
3050
|
+
* that ship together with the `/react` hook listed in
|
|
3051
|
+
* `optionalReactExports` (`usePublicPhotoSearch`). Prompt-safe only once
|
|
3052
|
+
* `minNpmVersion` reaches `photoSearchSince` — `studioPhotoSearchInstruction`
|
|
3053
|
+
* and the Studio guidance print nothing before that, and
|
|
3054
|
+
* `studioCodegenContractViolations` flags the names until then.
|
|
3055
|
+
*/
|
|
3056
|
+
photoSearchExports: [
|
|
3057
|
+
"searchListingPhotos",
|
|
3058
|
+
"applyMatchedPhotoCover"
|
|
3059
|
+
],
|
|
3060
|
+
photoSearchSince: "0.7.0"
|
|
2839
3061
|
};
|
|
3062
|
+
function isPhotoSearchOnPin(pin = STUDIO_SDK_CONTRACT.minNpmVersion) {
|
|
3063
|
+
return compareSemver(pin, STUDIO_SDK_CONTRACT.photoSearchSince) >= 0;
|
|
3064
|
+
}
|
|
2840
3065
|
var STUDIO_SITE_LAYOUT = {
|
|
2841
3066
|
maxWidthRem: "80rem",
|
|
2842
3067
|
maxWidthRemOptions: ["64rem", "80rem", "120rem", "160rem", "240rem"],
|
|
@@ -2920,9 +3145,12 @@ function unavailableReactImports(source, pin) {
|
|
|
2920
3145
|
}
|
|
2921
3146
|
return missing;
|
|
2922
3147
|
}
|
|
3148
|
+
function studioPublishableKeyInstruction() {
|
|
3149
|
+
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.`;
|
|
3150
|
+
}
|
|
2923
3151
|
function studioSdkPinInstruction() {
|
|
2924
3152
|
const version = STUDIO_SDK_CONTRACT.minNpmVersion;
|
|
2925
|
-
const names =
|
|
3153
|
+
const names = [...reactExportsAvailableAt(version)].join(", ");
|
|
2926
3154
|
return `In \`package.json\` set \`"@garagem-ai/site-sdk": "${version}"\` (exact). Import only these \`${STUDIO_SDK_PACKAGE}/react\` names: ${names}.`;
|
|
2927
3155
|
}
|
|
2928
3156
|
function studioLeadInstruction() {
|
|
@@ -2938,6 +3166,31 @@ function studioListingDetailInstruction() {
|
|
|
2938
3166
|
const names = STUDIO_SDK_CONTRACT.listingDetailExports.join(", ");
|
|
2939
3167
|
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.`;
|
|
2940
3168
|
}
|
|
3169
|
+
function studioPhotoInstructionFor(published) {
|
|
3170
|
+
const has = (name) => published.includes(name);
|
|
3171
|
+
const parts = [
|
|
3172
|
+
`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.`
|
|
3173
|
+
];
|
|
3174
|
+
if (has("listingPhotoGroups")) {
|
|
3175
|
+
parts.push(
|
|
3176
|
+
`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.`
|
|
3177
|
+
);
|
|
3178
|
+
}
|
|
3179
|
+
if (has("listingVisualHighlights")) {
|
|
3180
|
+
parts.push(
|
|
3181
|
+
`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.`
|
|
3182
|
+
);
|
|
3183
|
+
}
|
|
3184
|
+
if (has("getSimilarByPhoto")) {
|
|
3185
|
+
parts.push(
|
|
3186
|
+
`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\`.`
|
|
3187
|
+
);
|
|
3188
|
+
}
|
|
3189
|
+
return parts.join(" ");
|
|
3190
|
+
}
|
|
3191
|
+
function studioPhotoInstruction() {
|
|
3192
|
+
return studioPhotoInstructionFor(STUDIO_SDK_CONTRACT.photoExports);
|
|
3193
|
+
}
|
|
2941
3194
|
function studioAmenityInstruction() {
|
|
2942
3195
|
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".`;
|
|
2943
3196
|
}
|
|
@@ -2946,6 +3199,27 @@ function studioSearchInstruction() {
|
|
|
2946
3199
|
const libNames = STUDIO_SDK_CONTRACT.searchExports.join(", ");
|
|
2947
3200
|
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)}`;
|
|
2948
3201
|
}
|
|
3202
|
+
function marketExportsAvailableAt(pin) {
|
|
3203
|
+
return compareSemver(pin, STUDIO_SDK_CONTRACT.marketExportsSince) >= 0;
|
|
3204
|
+
}
|
|
3205
|
+
function studioMarketInstruction(pin = STUDIO_SDK_CONTRACT.minNpmVersion) {
|
|
3206
|
+
if (!marketExportsAvailableAt(pin)) {
|
|
3207
|
+
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.`;
|
|
3208
|
+
}
|
|
3209
|
+
const [summary, position, estimate, positionLabel, bandLabel] = STUDIO_SDK_CONTRACT.marketExports;
|
|
3210
|
+
const names = STUDIO_SDK_CONTRACT.marketExports.join(", ");
|
|
3211
|
+
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):
|
|
3212
|
+
- 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.
|
|
3213
|
+
- 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.
|
|
3214
|
+
- 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.
|
|
3215
|
+
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.`;
|
|
3216
|
+
}
|
|
3217
|
+
function studioPhotoSearchInstruction(pin = STUDIO_SDK_CONTRACT.minNpmVersion) {
|
|
3218
|
+
if (!isPhotoSearchOnPin(pin)) return "";
|
|
3219
|
+
const hook = "usePublicPhotoSearch";
|
|
3220
|
+
const [fetcher, cover] = STUDIO_SDK_CONTRACT.photoSearchExports;
|
|
3221
|
+
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.`;
|
|
3222
|
+
}
|
|
2949
3223
|
function studioChromeInstruction() {
|
|
2950
3224
|
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\`.`;
|
|
2951
3225
|
}
|
|
@@ -2954,7 +3228,10 @@ function mentionsExportName(text, name) {
|
|
|
2954
3228
|
}
|
|
2955
3229
|
function studioCodegenContractViolations(text) {
|
|
2956
3230
|
const violations = [];
|
|
2957
|
-
for (const name of Object.
|
|
3231
|
+
for (const [name, since] of Object.entries(
|
|
3232
|
+
STUDIO_SDK_CONTRACT.optionalReactExports
|
|
3233
|
+
)) {
|
|
3234
|
+
if (compareSemver(STUDIO_SDK_CONTRACT.minNpmVersion, since) >= 0) continue;
|
|
2958
3235
|
if (mentionsExportName(text, name)) violations.push(name);
|
|
2959
3236
|
}
|
|
2960
3237
|
for (const name of STUDIO_SDK_CONTRACT.retiredReactExports) {
|
|
@@ -2972,7 +3249,26 @@ function studioCodegenContractViolations(text) {
|
|
|
2972
3249
|
violations.push(name);
|
|
2973
3250
|
}
|
|
2974
3251
|
}
|
|
3252
|
+
for (const name of STUDIO_SDK_CONTRACT.unpublishedPhotoExports) {
|
|
3253
|
+
if (mentionsExportName(text, name) && !violations.includes(name)) {
|
|
3254
|
+
violations.push(name);
|
|
3255
|
+
}
|
|
3256
|
+
}
|
|
3257
|
+
if (!isPhotoSearchOnPin()) {
|
|
3258
|
+
for (const name of STUDIO_SDK_CONTRACT.photoSearchExports) {
|
|
3259
|
+
if (mentionsExportName(text, name) && !violations.includes(name)) {
|
|
3260
|
+
violations.push(name);
|
|
3261
|
+
}
|
|
3262
|
+
}
|
|
3263
|
+
}
|
|
2975
3264
|
const pin = STUDIO_SDK_CONTRACT.minNpmVersion;
|
|
3265
|
+
if (!marketExportsAvailableAt(pin)) {
|
|
3266
|
+
for (const name of STUDIO_SDK_CONTRACT.marketExports) {
|
|
3267
|
+
if (mentionsExportName(text, name) && !violations.includes(name)) {
|
|
3268
|
+
violations.push(name);
|
|
3269
|
+
}
|
|
3270
|
+
}
|
|
3271
|
+
}
|
|
2976
3272
|
const available = reactExportsAvailableAt(pin);
|
|
2977
3273
|
for (const name of parseReactSdkNamedImports(text)) {
|
|
2978
3274
|
if (!available.has(name) && !violations.includes(name)) {
|
|
@@ -3007,6 +3303,9 @@ function createGaragemClient(options = {}) {
|
|
|
3007
3303
|
const out = { ...opts };
|
|
3008
3304
|
if (options.baseUrl !== void 0) out.baseUrl = options.baseUrl;
|
|
3009
3305
|
if (options.fetch !== void 0) out.fetch = options.fetch;
|
|
3306
|
+
if (options.publishableKey !== void 0 && out.publishableKey === void 0) {
|
|
3307
|
+
out.publishableKey = options.publishableKey;
|
|
3308
|
+
}
|
|
3010
3309
|
return out;
|
|
3011
3310
|
};
|
|
3012
3311
|
return {
|
|
@@ -3035,6 +3334,9 @@ function createGaragemClient(options = {}) {
|
|
|
3035
3334
|
if (domain !== void 0) opts.domain = domain;
|
|
3036
3335
|
if (options.baseUrl !== void 0) opts.baseUrl = options.baseUrl;
|
|
3037
3336
|
if (options.fetch !== void 0) opts.fetch = options.fetch;
|
|
3337
|
+
if (options.publishableKey !== void 0) {
|
|
3338
|
+
opts.publishableKey = options.publishableKey;
|
|
3339
|
+
}
|
|
3038
3340
|
const merged = mergeNext(next);
|
|
3039
3341
|
if (merged !== void 0) opts.next = merged;
|
|
3040
3342
|
return getSite(opts);
|
|
@@ -3143,6 +3445,525 @@ function createGaragemClient(options = {}) {
|
|
|
3143
3445
|
}
|
|
3144
3446
|
};
|
|
3145
3447
|
}
|
|
3448
|
+
var createClient = createGaragemClient;
|
|
3449
|
+
|
|
3450
|
+
// src/fetchers-photos.ts
|
|
3451
|
+
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;
|
|
3452
|
+
var HIDDEN_SIMILAR_PHOTOS = {
|
|
3453
|
+
available: false,
|
|
3454
|
+
items: []
|
|
3455
|
+
};
|
|
3456
|
+
async function getSimilarByPhoto(siteId, listingId, mediaId, options = {}) {
|
|
3457
|
+
const { baseUrl, fetch: fetchImpl, next, limit } = options;
|
|
3458
|
+
const resolvedSiteId = await coerceSiteId(siteId);
|
|
3459
|
+
const lookupId = listingLookupKey(listingId ?? "");
|
|
3460
|
+
if (!lookupId || lookupId === "undefined" || lookupId === "null") {
|
|
3461
|
+
throw new TypeError("getSimilarByPhoto: `listingId` is required");
|
|
3462
|
+
}
|
|
3463
|
+
const photoId = typeof mediaId === "string" ? mediaId.trim() : "";
|
|
3464
|
+
if (!photoId) {
|
|
3465
|
+
throw new TypeError("getSimilarByPhoto: `mediaId` is required");
|
|
3466
|
+
}
|
|
3467
|
+
if (!MEDIA_UUID_RE.test(photoId)) {
|
|
3468
|
+
return HIDDEN_SIMILAR_PHOTOS;
|
|
3469
|
+
}
|
|
3470
|
+
const base = normalizeBaseUrl(baseUrl);
|
|
3471
|
+
const params = new URLSearchParams({ mediaId: photoId });
|
|
3472
|
+
if (typeof limit === "number" && Number.isFinite(limit) && limit > 0) {
|
|
3473
|
+
params.set("limit", String(Math.floor(limit)));
|
|
3474
|
+
}
|
|
3475
|
+
const url = `${base}/api/sites/${encodeURIComponent(resolvedSiteId)}/listings/${encodeURIComponent(
|
|
3476
|
+
lookupId
|
|
3477
|
+
)}/similar-photos?${params.toString()}`;
|
|
3478
|
+
const data = await callJson(
|
|
3479
|
+
url,
|
|
3480
|
+
{ method: "GET", headers: { Accept: "application/json" }, next },
|
|
3481
|
+
fetchImpl ?? fetch
|
|
3482
|
+
);
|
|
3483
|
+
return {
|
|
3484
|
+
available: data.available !== false,
|
|
3485
|
+
items: Array.isArray(data.items) ? data.items : []
|
|
3486
|
+
};
|
|
3487
|
+
}
|
|
3488
|
+
|
|
3489
|
+
// src/listing-photos.ts
|
|
3490
|
+
var PHOTO_GROUP_OTHER_KEY = "outros";
|
|
3491
|
+
var PHOTO_GROUP_OTHER_LABEL = "Outras fotos";
|
|
3492
|
+
function normalizeRoomLabel(value) {
|
|
3493
|
+
return value.normalize("NFD").replace(/[̀-ͯ]/g, "").toLowerCase().replace(/[^a-z0-9]+/g, " ").trim();
|
|
3494
|
+
}
|
|
3495
|
+
var ROOM_GROUPS = [
|
|
3496
|
+
{
|
|
3497
|
+
key: "fachada",
|
|
3498
|
+
label: "Fachada",
|
|
3499
|
+
members: [
|
|
3500
|
+
"fachada",
|
|
3501
|
+
"exterior",
|
|
3502
|
+
"frente",
|
|
3503
|
+
"facade",
|
|
3504
|
+
"fachada do predio",
|
|
3505
|
+
"predio",
|
|
3506
|
+
"building exterior",
|
|
3507
|
+
"area externa do predio"
|
|
3508
|
+
]
|
|
3509
|
+
},
|
|
3510
|
+
{
|
|
3511
|
+
key: "sala",
|
|
3512
|
+
label: "Sala",
|
|
3513
|
+
members: [
|
|
3514
|
+
"sala",
|
|
3515
|
+
"sala de estar",
|
|
3516
|
+
"living",
|
|
3517
|
+
"estar",
|
|
3518
|
+
"sala de tv",
|
|
3519
|
+
"living room",
|
|
3520
|
+
"sala de estar e jantar",
|
|
3521
|
+
"sala integrada"
|
|
3522
|
+
]
|
|
3523
|
+
},
|
|
3524
|
+
{
|
|
3525
|
+
key: "sala de jantar",
|
|
3526
|
+
label: "Sala de jantar",
|
|
3527
|
+
members: ["sala de jantar", "jantar", "dining room", "copa jantar"]
|
|
3528
|
+
},
|
|
3529
|
+
{
|
|
3530
|
+
key: "cozinha",
|
|
3531
|
+
label: "Cozinha",
|
|
3532
|
+
members: [
|
|
3533
|
+
"cozinha",
|
|
3534
|
+
"copa",
|
|
3535
|
+
"copa cozinha",
|
|
3536
|
+
"cozinha americana",
|
|
3537
|
+
"kitchen"
|
|
3538
|
+
]
|
|
3539
|
+
},
|
|
3540
|
+
{
|
|
3541
|
+
key: "quarto",
|
|
3542
|
+
label: "Quartos",
|
|
3543
|
+
members: [
|
|
3544
|
+
"quarto",
|
|
3545
|
+
"dormitorio",
|
|
3546
|
+
"suite",
|
|
3547
|
+
"suite master",
|
|
3548
|
+
"quarto de casal",
|
|
3549
|
+
"quarto de solteiro",
|
|
3550
|
+
"quarto infantil",
|
|
3551
|
+
"bedroom",
|
|
3552
|
+
"master bedroom"
|
|
3553
|
+
]
|
|
3554
|
+
},
|
|
3555
|
+
{
|
|
3556
|
+
key: "banheiro",
|
|
3557
|
+
label: "Banheiros",
|
|
3558
|
+
members: [
|
|
3559
|
+
"banheiro",
|
|
3560
|
+
"lavabo",
|
|
3561
|
+
"wc",
|
|
3562
|
+
"toalete",
|
|
3563
|
+
"bathroom",
|
|
3564
|
+
"banheiro social",
|
|
3565
|
+
"banheiro da suite"
|
|
3566
|
+
]
|
|
3567
|
+
},
|
|
3568
|
+
{
|
|
3569
|
+
key: "varanda",
|
|
3570
|
+
label: "Varanda",
|
|
3571
|
+
members: ["varanda", "sacada", "terraco", "balcony", "terrace"]
|
|
3572
|
+
},
|
|
3573
|
+
{
|
|
3574
|
+
key: "area gourmet",
|
|
3575
|
+
label: "\xC1rea gourmet",
|
|
3576
|
+
members: [
|
|
3577
|
+
"area gourmet",
|
|
3578
|
+
"varanda gourmet",
|
|
3579
|
+
"espaco gourmet",
|
|
3580
|
+
"churrasqueira",
|
|
3581
|
+
"gourmet",
|
|
3582
|
+
"terraco gourmet"
|
|
3583
|
+
]
|
|
3584
|
+
},
|
|
3585
|
+
{
|
|
3586
|
+
key: "closet",
|
|
3587
|
+
label: "Closet",
|
|
3588
|
+
members: ["closet", "closet da suite", "walk in closet"]
|
|
3589
|
+
},
|
|
3590
|
+
{
|
|
3591
|
+
key: "escritorio",
|
|
3592
|
+
label: "Escrit\xF3rio",
|
|
3593
|
+
members: ["escritorio", "home office", "office"]
|
|
3594
|
+
},
|
|
3595
|
+
{
|
|
3596
|
+
key: "area de servico",
|
|
3597
|
+
label: "\xC1rea de servi\xE7o",
|
|
3598
|
+
members: ["area de servico", "lavanderia", "laundry", "servico"]
|
|
3599
|
+
},
|
|
3600
|
+
{ key: "despensa", label: "Despensa", members: ["despensa", "pantry"] },
|
|
3601
|
+
{
|
|
3602
|
+
key: "corredor",
|
|
3603
|
+
label: "Corredor",
|
|
3604
|
+
members: ["corredor", "circulacao", "hallway"]
|
|
3605
|
+
},
|
|
3606
|
+
{
|
|
3607
|
+
key: "hall",
|
|
3608
|
+
label: "Hall",
|
|
3609
|
+
members: [
|
|
3610
|
+
"hall",
|
|
3611
|
+
"hall de entrada",
|
|
3612
|
+
"entrada",
|
|
3613
|
+
"recepcao",
|
|
3614
|
+
"lobby",
|
|
3615
|
+
"portaria"
|
|
3616
|
+
]
|
|
3617
|
+
},
|
|
3618
|
+
{
|
|
3619
|
+
key: "garagem",
|
|
3620
|
+
label: "Garagem",
|
|
3621
|
+
members: [
|
|
3622
|
+
"garagem",
|
|
3623
|
+
"vaga",
|
|
3624
|
+
"vagas",
|
|
3625
|
+
"estacionamento",
|
|
3626
|
+
"garage",
|
|
3627
|
+
"vaga de garagem"
|
|
3628
|
+
]
|
|
3629
|
+
},
|
|
3630
|
+
{
|
|
3631
|
+
key: "piscina",
|
|
3632
|
+
label: "Piscina",
|
|
3633
|
+
members: ["piscina", "pool", "piscina do condominio"]
|
|
3634
|
+
},
|
|
3635
|
+
{
|
|
3636
|
+
key: "academia",
|
|
3637
|
+
label: "Academia",
|
|
3638
|
+
members: ["academia", "fitness", "gym", "espaco fitness"]
|
|
3639
|
+
},
|
|
3640
|
+
{
|
|
3641
|
+
key: "salao de festas",
|
|
3642
|
+
label: "Sal\xE3o de festas",
|
|
3643
|
+
members: ["salao de festas", "festas", "salao", "party room"]
|
|
3644
|
+
},
|
|
3645
|
+
{
|
|
3646
|
+
key: "playground",
|
|
3647
|
+
label: "Playground",
|
|
3648
|
+
members: ["playground", "brinquedoteca", "espaco kids"]
|
|
3649
|
+
},
|
|
3650
|
+
{
|
|
3651
|
+
key: "jardim",
|
|
3652
|
+
label: "Jardim",
|
|
3653
|
+
members: ["jardim", "quintal", "area externa", "garden", "backyard"]
|
|
3654
|
+
},
|
|
3655
|
+
{
|
|
3656
|
+
key: "vista",
|
|
3657
|
+
label: "Vista",
|
|
3658
|
+
members: ["vista", "view", "vista da varanda"]
|
|
3659
|
+
},
|
|
3660
|
+
{
|
|
3661
|
+
key: "planta",
|
|
3662
|
+
label: "Planta",
|
|
3663
|
+
members: ["planta", "planta baixa", "floorplan", "floor plan"]
|
|
3664
|
+
}
|
|
3665
|
+
];
|
|
3666
|
+
var GROUP_BY_MEMBER = /* @__PURE__ */ new Map();
|
|
3667
|
+
for (const group of ROOM_GROUPS) {
|
|
3668
|
+
for (const member of group.members) {
|
|
3669
|
+
GROUP_BY_MEMBER.set(member, { key: group.key, label: group.label });
|
|
3670
|
+
}
|
|
3671
|
+
}
|
|
3672
|
+
var NON_ROOM_LABELS = /* @__PURE__ */ new Set(["", "outro", "outros", "other", "unknown"]);
|
|
3673
|
+
function capitalize(value) {
|
|
3674
|
+
return value.charAt(0).toUpperCase() + value.slice(1);
|
|
3675
|
+
}
|
|
3676
|
+
function photoRoomLabel(roomType) {
|
|
3677
|
+
const raw = (roomType ?? "").trim();
|
|
3678
|
+
const normalized = normalizeRoomLabel(raw);
|
|
3679
|
+
if (NON_ROOM_LABELS.has(normalized)) {
|
|
3680
|
+
return { key: PHOTO_GROUP_OTHER_KEY, label: PHOTO_GROUP_OTHER_LABEL };
|
|
3681
|
+
}
|
|
3682
|
+
const known = GROUP_BY_MEMBER.get(normalized);
|
|
3683
|
+
if (known) return known;
|
|
3684
|
+
return { key: normalized, label: capitalize(raw) };
|
|
3685
|
+
}
|
|
3686
|
+
function isPhoto(item) {
|
|
3687
|
+
return (item.type || "image") === "image" && typeof item.src === "string";
|
|
3688
|
+
}
|
|
3689
|
+
function listingPhotoGroups(listing) {
|
|
3690
|
+
const groups = /* @__PURE__ */ new Map();
|
|
3691
|
+
const photos = [...listing.media ?? []].filter(isPhoto).sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
|
|
3692
|
+
for (const photo of photos) {
|
|
3693
|
+
const { key, label } = photoRoomLabel(photo.roomType);
|
|
3694
|
+
const group = groups.get(key);
|
|
3695
|
+
if (group) {
|
|
3696
|
+
group.photos.push(photo);
|
|
3697
|
+
} else {
|
|
3698
|
+
groups.set(key, { key, label, photos: [photo] });
|
|
3699
|
+
}
|
|
3700
|
+
}
|
|
3701
|
+
const ordered = [...groups.values()];
|
|
3702
|
+
const otherIndex = ordered.findIndex((g) => g.key === PHOTO_GROUP_OTHER_KEY);
|
|
3703
|
+
if (otherIndex >= 0 && otherIndex !== ordered.length - 1) {
|
|
3704
|
+
const [other] = ordered.splice(otherIndex, 1);
|
|
3705
|
+
ordered.push(other);
|
|
3706
|
+
}
|
|
3707
|
+
return ordered;
|
|
3708
|
+
}
|
|
3709
|
+
function listingVisualHighlights(listing, options) {
|
|
3710
|
+
const limit = Math.max(0, Math.floor(options?.limit ?? 8));
|
|
3711
|
+
if (limit === 0) return [];
|
|
3712
|
+
const counts = /* @__PURE__ */ new Map();
|
|
3713
|
+
let seen = 0;
|
|
3714
|
+
for (const item of listing.media ?? []) {
|
|
3715
|
+
if (!isPhoto(item) || !Array.isArray(item.features)) continue;
|
|
3716
|
+
for (const feature of item.features) {
|
|
3717
|
+
if (typeof feature !== "string") continue;
|
|
3718
|
+
const text = feature.trim();
|
|
3719
|
+
if (!text) continue;
|
|
3720
|
+
const key = normalizeRoomLabel(text);
|
|
3721
|
+
if (!key) continue;
|
|
3722
|
+
const entry = counts.get(key);
|
|
3723
|
+
if (entry) {
|
|
3724
|
+
entry.count += 1;
|
|
3725
|
+
} else {
|
|
3726
|
+
counts.set(key, { text, count: 1, seen: seen++ });
|
|
3727
|
+
}
|
|
3728
|
+
}
|
|
3729
|
+
}
|
|
3730
|
+
return [...counts.values()].sort((a, b) => b.count - a.count || a.seen - b.seen).slice(0, limit).map((entry) => entry.text);
|
|
3731
|
+
}
|
|
3732
|
+
|
|
3733
|
+
// src/fetchers-market.ts
|
|
3734
|
+
var RATE_LIMITED_MESSAGE = "Muitas consultas em pouco tempo. Tente novamente em instantes.";
|
|
3735
|
+
function isRateLimited(error) {
|
|
3736
|
+
return error instanceof GaragemSdkError && error.status === 429;
|
|
3737
|
+
}
|
|
3738
|
+
async function getNeighborhoodSummary(options) {
|
|
3739
|
+
const { query, baseUrl, fetch: fetchImpl, next } = options;
|
|
3740
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
3741
|
+
if (!query?.city?.trim() || !query?.neighborhood?.trim()) {
|
|
3742
|
+
throw new TypeError(
|
|
3743
|
+
"getNeighborhoodSummary: `query.city` and `query.neighborhood` are required"
|
|
3744
|
+
);
|
|
3745
|
+
}
|
|
3746
|
+
const base = normalizeBaseUrl(baseUrl);
|
|
3747
|
+
const params = new URLSearchParams();
|
|
3748
|
+
params.set("city", query.city.trim());
|
|
3749
|
+
params.set("neighborhood", query.neighborhood.trim());
|
|
3750
|
+
if (query.propertyType) params.set("propertyType", query.propertyType);
|
|
3751
|
+
if (query.type) params.set("type", query.type);
|
|
3752
|
+
const url = `${base}/api/sites/${encodeURIComponent(siteId)}/market/neighborhood-summary?${params.toString()}`;
|
|
3753
|
+
try {
|
|
3754
|
+
return await callJson(
|
|
3755
|
+
url,
|
|
3756
|
+
{ method: "GET", headers: { Accept: "application/json" }, next },
|
|
3757
|
+
fetchImpl ?? fetch
|
|
3758
|
+
);
|
|
3759
|
+
} catch (error) {
|
|
3760
|
+
if (!isRateLimited(error)) throw error;
|
|
3761
|
+
return {
|
|
3762
|
+
available: false,
|
|
3763
|
+
reason: "rate_limited",
|
|
3764
|
+
city: query.city,
|
|
3765
|
+
neighborhood: query.neighborhood,
|
|
3766
|
+
propertyType: query.propertyType ?? null,
|
|
3767
|
+
type: query.type ?? "sale",
|
|
3768
|
+
months: 12,
|
|
3769
|
+
pricePerSqmCents: { p25: null, p50: null, p75: null },
|
|
3770
|
+
pricePerSqmFormatted: { p25: "\u2014", p50: "\u2014", p75: "\u2014" },
|
|
3771
|
+
sampleSize: null,
|
|
3772
|
+
message: RATE_LIMITED_MESSAGE
|
|
3773
|
+
};
|
|
3774
|
+
}
|
|
3775
|
+
}
|
|
3776
|
+
async function getListingMarketPosition(options) {
|
|
3777
|
+
const { listingId: rawListingId, baseUrl, fetch: fetchImpl, next } = options;
|
|
3778
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
3779
|
+
const listingId = listingLookupKey(rawListingId ?? "");
|
|
3780
|
+
if (!listingId || listingId === "undefined" || listingId === "null") {
|
|
3781
|
+
throw new TypeError("getListingMarketPosition: `listingId` is required");
|
|
3782
|
+
}
|
|
3783
|
+
const base = normalizeBaseUrl(baseUrl);
|
|
3784
|
+
const url = `${base}/api/sites/${encodeURIComponent(siteId)}/listings/${encodeURIComponent(
|
|
3785
|
+
listingId
|
|
3786
|
+
)}/market-position`;
|
|
3787
|
+
try {
|
|
3788
|
+
return await callJson(
|
|
3789
|
+
url,
|
|
3790
|
+
{ method: "GET", headers: { Accept: "application/json" }, next },
|
|
3791
|
+
fetchImpl ?? fetch
|
|
3792
|
+
);
|
|
3793
|
+
} catch (error) {
|
|
3794
|
+
if (!isRateLimited(error)) throw error;
|
|
3795
|
+
return {
|
|
3796
|
+
available: false,
|
|
3797
|
+
reason: "rate_limited",
|
|
3798
|
+
listingId,
|
|
3799
|
+
city: null,
|
|
3800
|
+
neighborhood: null,
|
|
3801
|
+
months: 12,
|
|
3802
|
+
listingPricePerSqmCents: null,
|
|
3803
|
+
listingPricePerSqmFormatted: "\u2014",
|
|
3804
|
+
medianPricePerSqmCents: null,
|
|
3805
|
+
medianPricePerSqmFormatted: "\u2014",
|
|
3806
|
+
percentVsMedian: null,
|
|
3807
|
+
band: null,
|
|
3808
|
+
sampleSize: null,
|
|
3809
|
+
message: RATE_LIMITED_MESSAGE
|
|
3810
|
+
};
|
|
3811
|
+
}
|
|
3812
|
+
}
|
|
3813
|
+
async function requestPriceEstimate(options) {
|
|
3814
|
+
const { input, baseUrl, fetch: fetchImpl, next } = options;
|
|
3815
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
3816
|
+
if (!input?.city?.trim() || typeof input.areaSqm !== "number") {
|
|
3817
|
+
throw new TypeError(
|
|
3818
|
+
"requestPriceEstimate: `input.city` and `input.areaSqm` are required"
|
|
3819
|
+
);
|
|
3820
|
+
}
|
|
3821
|
+
const base = normalizeBaseUrl(baseUrl);
|
|
3822
|
+
const url = `${base}/api/sites/${encodeURIComponent(siteId)}/market/estimate`;
|
|
3823
|
+
try {
|
|
3824
|
+
return await callJson(
|
|
3825
|
+
url,
|
|
3826
|
+
{
|
|
3827
|
+
method: "POST",
|
|
3828
|
+
headers: {
|
|
3829
|
+
Accept: "application/json",
|
|
3830
|
+
"Content-Type": "application/json"
|
|
3831
|
+
},
|
|
3832
|
+
body: JSON.stringify(input),
|
|
3833
|
+
next
|
|
3834
|
+
},
|
|
3835
|
+
fetchImpl ?? fetch
|
|
3836
|
+
);
|
|
3837
|
+
} catch (error) {
|
|
3838
|
+
if (!isRateLimited(error)) throw error;
|
|
3839
|
+
return {
|
|
3840
|
+
available: false,
|
|
3841
|
+
reason: "rate_limited",
|
|
3842
|
+
city: input.city,
|
|
3843
|
+
neighborhood: input.neighborhood ?? null,
|
|
3844
|
+
estimatedPriceCents: null,
|
|
3845
|
+
estimatedPriceFormatted: "\u2014",
|
|
3846
|
+
rangeLowCents: null,
|
|
3847
|
+
rangeHighCents: null,
|
|
3848
|
+
rangeLowFormatted: "\u2014",
|
|
3849
|
+
rangeHighFormatted: "\u2014",
|
|
3850
|
+
confidenceLabel: null,
|
|
3851
|
+
sampleSize: null,
|
|
3852
|
+
message: RATE_LIMITED_MESSAGE
|
|
3853
|
+
};
|
|
3854
|
+
}
|
|
3855
|
+
}
|
|
3856
|
+
|
|
3857
|
+
// src/market-labels.ts
|
|
3858
|
+
function marketPositionLabel(position) {
|
|
3859
|
+
if (!position?.available) return null;
|
|
3860
|
+
const percent = position.percentVsMedian;
|
|
3861
|
+
if (percent == null || !Number.isFinite(percent)) return null;
|
|
3862
|
+
const rounded = Math.round(percent);
|
|
3863
|
+
if (rounded === 0) return "Na mediana do bairro";
|
|
3864
|
+
const magnitude = Math.abs(rounded);
|
|
3865
|
+
return rounded < 0 ? `${magnitude}% abaixo da mediana do bairro` : `${magnitude}% acima da mediana do bairro`;
|
|
3866
|
+
}
|
|
3867
|
+
var BAND_LABELS = {
|
|
3868
|
+
below_range: "Abaixo da faixa do bairro",
|
|
3869
|
+
lower_range: "Na faixa do bairro, abaixo da mediana",
|
|
3870
|
+
upper_range: "Na faixa do bairro, acima da mediana",
|
|
3871
|
+
above_range: "Acima da faixa do bairro"
|
|
3872
|
+
};
|
|
3873
|
+
function priceBandLabel(input) {
|
|
3874
|
+
if (!input) return null;
|
|
3875
|
+
if (typeof input === "string") return BAND_LABELS[input] ?? null;
|
|
3876
|
+
if (!input.available || !input.band) return null;
|
|
3877
|
+
return BAND_LABELS[input.band] ?? null;
|
|
3878
|
+
}
|
|
3879
|
+
|
|
3880
|
+
// src/fetchers-photo-search.ts
|
|
3881
|
+
var PHOTO_SEARCH_MIN_QUERY_LENGTH = 3;
|
|
3882
|
+
var EMPTY_RESULT = {
|
|
3883
|
+
available: true,
|
|
3884
|
+
items: [],
|
|
3885
|
+
total: 0,
|
|
3886
|
+
page: 1,
|
|
3887
|
+
limit: 12
|
|
3888
|
+
};
|
|
3889
|
+
function positiveInt(value) {
|
|
3890
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < 1) {
|
|
3891
|
+
return null;
|
|
3892
|
+
}
|
|
3893
|
+
return Math.floor(value);
|
|
3894
|
+
}
|
|
3895
|
+
function photoSearchUrl(siteId, params, baseUrl) {
|
|
3896
|
+
const search = new URLSearchParams();
|
|
3897
|
+
search.set("q", params.q.trim());
|
|
3898
|
+
const limit = positiveInt(params.limit);
|
|
3899
|
+
if (limit != null) search.set("limit", String(limit));
|
|
3900
|
+
const page = positiveInt(params.page);
|
|
3901
|
+
if (page != null) search.set("page", String(page));
|
|
3902
|
+
return `${normalizeBaseUrl(baseUrl)}/api/sites/${encodeURIComponent(
|
|
3903
|
+
siteId
|
|
3904
|
+
)}/search/photos?${search.toString()}`;
|
|
3905
|
+
}
|
|
3906
|
+
async function searchListingPhotos(siteId, params, options = {}) {
|
|
3907
|
+
const q = (params?.q ?? "").trim();
|
|
3908
|
+
const limit = positiveInt(params?.limit) ?? EMPTY_RESULT.limit;
|
|
3909
|
+
if (q.length < PHOTO_SEARCH_MIN_QUERY_LENGTH) {
|
|
3910
|
+
return { ...EMPTY_RESULT, limit, page: positiveInt(params?.page) ?? 1 };
|
|
3911
|
+
}
|
|
3912
|
+
const resolvedSiteId = await coerceSiteId(siteId);
|
|
3913
|
+
const url = photoSearchUrl(resolvedSiteId, { ...params, q }, options.baseUrl);
|
|
3914
|
+
const data = await callJson(
|
|
3915
|
+
url,
|
|
3916
|
+
{
|
|
3917
|
+
method: "GET",
|
|
3918
|
+
headers: { Accept: "application/json" },
|
|
3919
|
+
next: options.next
|
|
3920
|
+
},
|
|
3921
|
+
options.fetch ?? fetch
|
|
3922
|
+
);
|
|
3923
|
+
const items = Array.isArray(data.items) ? data.items : [];
|
|
3924
|
+
return {
|
|
3925
|
+
available: data.available !== false,
|
|
3926
|
+
items,
|
|
3927
|
+
total: typeof data.total === "number" ? data.total : items.length,
|
|
3928
|
+
page: typeof data.page === "number" ? data.page : positiveInt(params.page) ?? 1,
|
|
3929
|
+
limit: typeof data.limit === "number" ? data.limit : limit
|
|
3930
|
+
};
|
|
3931
|
+
}
|
|
3932
|
+
|
|
3933
|
+
// src/photo-search-cover.ts
|
|
3934
|
+
var MATCHED_PHOTO_COVER_MAX_DISTANCE = 0.4;
|
|
3935
|
+
function resolveMatchedCoverPhoto(photo, maxDistance = MATCHED_PHOTO_COVER_MAX_DISTANCE) {
|
|
3936
|
+
if (!photo || !photo.src) return null;
|
|
3937
|
+
if (photo.distance == null) return photo;
|
|
3938
|
+
if (!Number.isFinite(photo.distance)) return null;
|
|
3939
|
+
return photo.distance <= maxDistance ? photo : null;
|
|
3940
|
+
}
|
|
3941
|
+
function itemsOf(photoResults) {
|
|
3942
|
+
if (!photoResults) return [];
|
|
3943
|
+
return Array.isArray(photoResults) ? photoResults : photoResults.items ?? [];
|
|
3944
|
+
}
|
|
3945
|
+
function applyMatchedPhotoCover(cards, photoResults, options = {}) {
|
|
3946
|
+
const maxDistance = options.maxDistance ?? MATCHED_PHOTO_COVER_MAX_DISTANCE;
|
|
3947
|
+
const photoByListingId = /* @__PURE__ */ new Map();
|
|
3948
|
+
for (const item of itemsOf(photoResults)) {
|
|
3949
|
+
const id = item?.listing?.id;
|
|
3950
|
+
if (!id || photoByListingId.has(id)) continue;
|
|
3951
|
+
const photo = resolveMatchedCoverPhoto(item.matchedPhoto, maxDistance);
|
|
3952
|
+
if (photo) photoByListingId.set(id, photo);
|
|
3953
|
+
}
|
|
3954
|
+
return cards.map((card) => {
|
|
3955
|
+
const photo = photoByListingId.get(card.id) ?? null;
|
|
3956
|
+
if (!photo) return { ...card, matchedPhoto: null };
|
|
3957
|
+
return {
|
|
3958
|
+
...card,
|
|
3959
|
+
coverImage: {
|
|
3960
|
+
src: photo.src,
|
|
3961
|
+
alt: photo.alt || card.coverImage?.alt || card.title
|
|
3962
|
+
},
|
|
3963
|
+
matchedPhoto: photo
|
|
3964
|
+
};
|
|
3965
|
+
});
|
|
3966
|
+
}
|
|
3146
3967
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3147
3968
|
0 && (module.exports = {
|
|
3148
3969
|
AMENITY_FALLBACK_LABELS,
|
|
@@ -3152,8 +3973,12 @@ function createGaragemClient(options = {}) {
|
|
|
3152
3973
|
LISTING_AMENITY_TITLES,
|
|
3153
3974
|
LISTING_DESCRIPTION_CLAMP,
|
|
3154
3975
|
LeadSubmitError,
|
|
3976
|
+
MATCHED_PHOTO_COVER_MAX_DISTANCE,
|
|
3155
3977
|
MAX_NATIONAL_PHONE_DIGITS,
|
|
3156
3978
|
PHONE_COUNTRIES,
|
|
3979
|
+
PHOTO_GROUP_OTHER_KEY,
|
|
3980
|
+
PHOTO_GROUP_OTHER_LABEL,
|
|
3981
|
+
PHOTO_SEARCH_MIN_QUERY_LENGTH,
|
|
3157
3982
|
SEARCH_EMPTY_COPY,
|
|
3158
3983
|
SEARCH_SORT_RELEVANCE,
|
|
3159
3984
|
STUDIO_DEFAULT_VISIT_SCHEDULE,
|
|
@@ -3162,6 +3987,7 @@ function createGaragemClient(options = {}) {
|
|
|
3162
3987
|
STUDIO_SITE_LAYOUT,
|
|
3163
3988
|
TOOLBAR_PRIMARY_FILTER_IDS,
|
|
3164
3989
|
VISIT_TIME_ZONE,
|
|
3990
|
+
applyMatchedPhotoCover,
|
|
3165
3991
|
applyPathFilter,
|
|
3166
3992
|
buildQueryListingsParams,
|
|
3167
3993
|
canonicalizeSearchHref,
|
|
@@ -3173,6 +3999,7 @@ function createGaragemClient(options = {}) {
|
|
|
3173
3999
|
composeSearchPublicPath,
|
|
3174
4000
|
countFacetChoices,
|
|
3175
4001
|
countOptionLabel,
|
|
4002
|
+
createClient,
|
|
3176
4003
|
createGaragemClient,
|
|
3177
4004
|
defaultPhoneCountry,
|
|
3178
4005
|
displayPathLocation,
|
|
@@ -3189,8 +4016,11 @@ function createGaragemClient(options = {}) {
|
|
|
3189
4016
|
getCmsEntry,
|
|
3190
4017
|
getLeadUi,
|
|
3191
4018
|
getListing,
|
|
4019
|
+
getListingMarketPosition,
|
|
3192
4020
|
getListings,
|
|
4021
|
+
getNeighborhoodSummary,
|
|
3193
4022
|
getSearchUi,
|
|
4023
|
+
getSimilarByPhoto,
|
|
3194
4024
|
getSimilarListings,
|
|
3195
4025
|
getSite,
|
|
3196
4026
|
hasShowcaseLeadsPostUrl,
|
|
@@ -3198,6 +4028,7 @@ function createGaragemClient(options = {}) {
|
|
|
3198
4028
|
hrefForPathFilters,
|
|
3199
4029
|
hrefWithExplicitPage,
|
|
3200
4030
|
isListingDetailPath,
|
|
4031
|
+
isPhotoSearchOnPin,
|
|
3201
4032
|
isStudioPreviewHost,
|
|
3202
4033
|
isValidPhone,
|
|
3203
4034
|
isVisitSlotAllowed,
|
|
@@ -3214,8 +4045,12 @@ function createGaragemClient(options = {}) {
|
|
|
3214
4045
|
listingLookupKey,
|
|
3215
4046
|
listingMapsHref,
|
|
3216
4047
|
listingMediaOverlays,
|
|
4048
|
+
listingPhotoGroups,
|
|
3217
4049
|
listingPublicPath,
|
|
3218
4050
|
listingValues,
|
|
4051
|
+
listingVisualHighlights,
|
|
4052
|
+
marketExportsAvailableAt,
|
|
4053
|
+
marketPositionLabel,
|
|
3219
4054
|
mergeAppliedSearchQueryIntoSearch,
|
|
3220
4055
|
nationalPhoneDigits,
|
|
3221
4056
|
normalizeVisitDate,
|
|
@@ -3231,15 +4066,21 @@ function createGaragemClient(options = {}) {
|
|
|
3231
4066
|
pathFiltersToQueryFilters,
|
|
3232
4067
|
pathLocationToFilterInput,
|
|
3233
4068
|
phoneCountrySearchValue,
|
|
4069
|
+
photoRoomLabel,
|
|
4070
|
+
photoSearchUrl,
|
|
4071
|
+
priceBandLabel,
|
|
3234
4072
|
publicSearchHref,
|
|
3235
4073
|
queryListings,
|
|
3236
4074
|
rangeDraftFromPath,
|
|
3237
4075
|
readPublicSearch,
|
|
3238
4076
|
reduceAppliedSearchQuery,
|
|
3239
4077
|
remaskPhoneForCountry,
|
|
4078
|
+
requestPriceEstimate,
|
|
4079
|
+
resolveMatchedCoverPhoto,
|
|
3240
4080
|
resolvePublicSiteId,
|
|
3241
4081
|
searchChromeModel,
|
|
3242
4082
|
searchHrefUsesLegacyFilterQuery,
|
|
4083
|
+
searchListingPhotos,
|
|
3243
4084
|
searchListings,
|
|
3244
4085
|
searchResultsHeading,
|
|
3245
4086
|
searchSortOptions,
|
|
@@ -3253,6 +4094,11 @@ function createGaragemClient(options = {}) {
|
|
|
3253
4094
|
studioLeadInstruction,
|
|
3254
4095
|
studioListingCardInstruction,
|
|
3255
4096
|
studioListingDetailInstruction,
|
|
4097
|
+
studioMarketInstruction,
|
|
4098
|
+
studioPhotoInstruction,
|
|
4099
|
+
studioPhotoInstructionFor,
|
|
4100
|
+
studioPhotoSearchInstruction,
|
|
4101
|
+
studioPublishableKeyInstruction,
|
|
3256
4102
|
studioSdkPinInstruction,
|
|
3257
4103
|
studioSearchInstruction,
|
|
3258
4104
|
studioSearchLandmarkInstruction,
|