@garagem-ai/site-sdk 0.6.1 → 0.7.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 +91 -0
- package/dist/index.d.mts +313 -149
- package/dist/index.d.ts +313 -149
- package/dist/index.js +344 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +329 -4
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.mts +41 -2
- package/dist/react.d.ts +41 -2
- package/dist/react.js +194 -0
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +192 -0
- package/dist/react.mjs.map +1 -1
- package/dist/{search-engine-CtnLzmwW.d.mts → types-photo-search-OeONNDxl.d.mts} +204 -1
- package/dist/{search-engine-CtnLzmwW.d.ts → types-photo-search-OeONNDxl.d.ts} +204 -1
- package/package.json +2 -1
- package/src/fetchers-market.ts +216 -0
- package/src/fetchers-photo-search.ts +101 -0
- package/src/index.ts +61 -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/use-public-photo-search.ts +165 -0
- package/src/studio-contract.ts +104 -3
- package/src/types-market.ts +138 -0
- package/src/types-photo-search.ts +55 -0
- package/src/types.ts +7 -0
package/dist/index.mjs
CHANGED
|
@@ -2610,7 +2610,9 @@ var STUDIO_SDK_CONTRACT = {
|
|
|
2610
2610
|
* “never import”) — v0 copies the identifier and the preview ESM loader
|
|
2611
2611
|
* throws FatalRendererError.
|
|
2612
2612
|
*/
|
|
2613
|
-
optionalReactExports: {
|
|
2613
|
+
optionalReactExports: {
|
|
2614
|
+
usePublicPhotoSearch: "0.7.0"
|
|
2615
|
+
},
|
|
2614
2616
|
/**
|
|
2615
2617
|
* Former `/react` chrome (including card/skeleton inject). Completeness
|
|
2616
2618
|
* flags imports as mismatch (not in `reactExports`). Prompts must not
|
|
@@ -2694,8 +2696,43 @@ var STUDIO_SDK_CONTRACT = {
|
|
|
2694
2696
|
unpublishedSearchExports: [
|
|
2695
2697
|
"searchChromeModel",
|
|
2696
2698
|
"rangeDraftFromPath"
|
|
2697
|
-
]
|
|
2699
|
+
],
|
|
2700
|
+
/**
|
|
2701
|
+
* Market-data helpers (neighborhood price summary, listing market
|
|
2702
|
+
* position, visitor price estimate, pt-BR labels). They ship in
|
|
2703
|
+
* `marketExportsSince` and are prompt-safe only once `minNpmVersion`
|
|
2704
|
+
* reaches that release; below it `studioCodegenContractViolations` flags
|
|
2705
|
+
* the names and `studioMarketInstruction()` tells Studio not to generate
|
|
2706
|
+
* the blocks at all. Every helper answers `available: false` unless the
|
|
2707
|
+
* site's organization holds the IPTU module (`iptu_itbi_integration`)
|
|
2708
|
+
* and the city is covered — generated sites render these blocks
|
|
2709
|
+
* conditionally and never show cadastral or transaction data.
|
|
2710
|
+
*/
|
|
2711
|
+
marketExports: [
|
|
2712
|
+
"getNeighborhoodSummary",
|
|
2713
|
+
"getListingMarketPosition",
|
|
2714
|
+
"requestPriceEstimate",
|
|
2715
|
+
"marketPositionLabel",
|
|
2716
|
+
"priceBandLabel"
|
|
2717
|
+
],
|
|
2718
|
+
marketExportsSince: "0.7.0",
|
|
2719
|
+
/**
|
|
2720
|
+
* Photo search ("busca pelo que as fotos mostram"): main-package helpers
|
|
2721
|
+
* that ship together with the `/react` hook listed in
|
|
2722
|
+
* `optionalReactExports` (`usePublicPhotoSearch`). Prompt-safe only once
|
|
2723
|
+
* `minNpmVersion` reaches `photoSearchSince` — `studioPhotoSearchInstruction`
|
|
2724
|
+
* and the Studio guidance print nothing before that, and
|
|
2725
|
+
* `studioCodegenContractViolations` flags the names until then.
|
|
2726
|
+
*/
|
|
2727
|
+
photoSearchExports: [
|
|
2728
|
+
"searchListingPhotos",
|
|
2729
|
+
"applyMatchedPhotoCover"
|
|
2730
|
+
],
|
|
2731
|
+
photoSearchSince: "0.7.0"
|
|
2698
2732
|
};
|
|
2733
|
+
function isPhotoSearchOnPin(pin = STUDIO_SDK_CONTRACT.minNpmVersion) {
|
|
2734
|
+
return compareSemver(pin, STUDIO_SDK_CONTRACT.photoSearchSince) >= 0;
|
|
2735
|
+
}
|
|
2699
2736
|
var STUDIO_SITE_LAYOUT = {
|
|
2700
2737
|
maxWidthRem: "80rem",
|
|
2701
2738
|
maxWidthRemOptions: ["64rem", "80rem", "120rem", "160rem", "240rem"],
|
|
@@ -2781,7 +2818,7 @@ function unavailableReactImports(source, pin) {
|
|
|
2781
2818
|
}
|
|
2782
2819
|
function studioSdkPinInstruction() {
|
|
2783
2820
|
const version = STUDIO_SDK_CONTRACT.minNpmVersion;
|
|
2784
|
-
const names =
|
|
2821
|
+
const names = [...reactExportsAvailableAt(version)].join(", ");
|
|
2785
2822
|
return `In \`package.json\` set \`"@garagem-ai/site-sdk": "${version}"\` (exact). Import only these \`${STUDIO_SDK_PACKAGE}/react\` names: ${names}.`;
|
|
2786
2823
|
}
|
|
2787
2824
|
function studioLeadInstruction() {
|
|
@@ -2805,6 +2842,27 @@ function studioSearchInstruction() {
|
|
|
2805
2842
|
const libNames = STUDIO_SDK_CONTRACT.searchExports.join(", ");
|
|
2806
2843
|
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
2844
|
}
|
|
2845
|
+
function marketExportsAvailableAt(pin) {
|
|
2846
|
+
return compareSemver(pin, STUDIO_SDK_CONTRACT.marketExportsSince) >= 0;
|
|
2847
|
+
}
|
|
2848
|
+
function studioMarketInstruction(pin = STUDIO_SDK_CONTRACT.minNpmVersion) {
|
|
2849
|
+
if (!marketExportsAvailableAt(pin)) {
|
|
2850
|
+
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.`;
|
|
2851
|
+
}
|
|
2852
|
+
const [summary, position, estimate, positionLabel, bandLabel] = STUDIO_SDK_CONTRACT.marketExports;
|
|
2853
|
+
const names = STUDIO_SDK_CONTRACT.marketExports.join(", ");
|
|
2854
|
+
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):
|
|
2855
|
+
- 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.
|
|
2856
|
+
- 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.
|
|
2857
|
+
- 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.
|
|
2858
|
+
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.`;
|
|
2859
|
+
}
|
|
2860
|
+
function studioPhotoSearchInstruction(pin = STUDIO_SDK_CONTRACT.minNpmVersion) {
|
|
2861
|
+
if (!isPhotoSearchOnPin(pin)) return "";
|
|
2862
|
+
const hook = "usePublicPhotoSearch";
|
|
2863
|
+
const [fetcher, cover] = STUDIO_SDK_CONTRACT.photoSearchExports;
|
|
2864
|
+
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.`;
|
|
2865
|
+
}
|
|
2808
2866
|
function studioChromeInstruction() {
|
|
2809
2867
|
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
2868
|
}
|
|
@@ -2813,7 +2871,10 @@ function mentionsExportName(text, name) {
|
|
|
2813
2871
|
}
|
|
2814
2872
|
function studioCodegenContractViolations(text) {
|
|
2815
2873
|
const violations = [];
|
|
2816
|
-
for (const name of Object.
|
|
2874
|
+
for (const [name, since] of Object.entries(
|
|
2875
|
+
STUDIO_SDK_CONTRACT.optionalReactExports
|
|
2876
|
+
)) {
|
|
2877
|
+
if (compareSemver(STUDIO_SDK_CONTRACT.minNpmVersion, since) >= 0) continue;
|
|
2817
2878
|
if (mentionsExportName(text, name)) violations.push(name);
|
|
2818
2879
|
}
|
|
2819
2880
|
for (const name of STUDIO_SDK_CONTRACT.retiredReactExports) {
|
|
@@ -2831,7 +2892,21 @@ function studioCodegenContractViolations(text) {
|
|
|
2831
2892
|
violations.push(name);
|
|
2832
2893
|
}
|
|
2833
2894
|
}
|
|
2895
|
+
if (!isPhotoSearchOnPin()) {
|
|
2896
|
+
for (const name of STUDIO_SDK_CONTRACT.photoSearchExports) {
|
|
2897
|
+
if (mentionsExportName(text, name) && !violations.includes(name)) {
|
|
2898
|
+
violations.push(name);
|
|
2899
|
+
}
|
|
2900
|
+
}
|
|
2901
|
+
}
|
|
2834
2902
|
const pin = STUDIO_SDK_CONTRACT.minNpmVersion;
|
|
2903
|
+
if (!marketExportsAvailableAt(pin)) {
|
|
2904
|
+
for (const name of STUDIO_SDK_CONTRACT.marketExports) {
|
|
2905
|
+
if (mentionsExportName(text, name) && !violations.includes(name)) {
|
|
2906
|
+
violations.push(name);
|
|
2907
|
+
}
|
|
2908
|
+
}
|
|
2909
|
+
}
|
|
2835
2910
|
const available = reactExportsAvailableAt(pin);
|
|
2836
2911
|
for (const name of parseReactSdkNamedImports(text)) {
|
|
2837
2912
|
if (!available.has(name) && !violations.includes(name)) {
|
|
@@ -3002,6 +3077,241 @@ function createGaragemClient(options = {}) {
|
|
|
3002
3077
|
}
|
|
3003
3078
|
};
|
|
3004
3079
|
}
|
|
3080
|
+
|
|
3081
|
+
// src/fetchers-market.ts
|
|
3082
|
+
var RATE_LIMITED_MESSAGE = "Muitas consultas em pouco tempo. Tente novamente em instantes.";
|
|
3083
|
+
function isRateLimited(error) {
|
|
3084
|
+
return error instanceof GaragemSdkError && error.status === 429;
|
|
3085
|
+
}
|
|
3086
|
+
async function getNeighborhoodSummary(options) {
|
|
3087
|
+
const { query, baseUrl, fetch: fetchImpl, next } = options;
|
|
3088
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
3089
|
+
if (!query?.city?.trim() || !query?.neighborhood?.trim()) {
|
|
3090
|
+
throw new TypeError(
|
|
3091
|
+
"getNeighborhoodSummary: `query.city` and `query.neighborhood` are required"
|
|
3092
|
+
);
|
|
3093
|
+
}
|
|
3094
|
+
const base = normalizeBaseUrl(baseUrl);
|
|
3095
|
+
const params = new URLSearchParams();
|
|
3096
|
+
params.set("city", query.city.trim());
|
|
3097
|
+
params.set("neighborhood", query.neighborhood.trim());
|
|
3098
|
+
if (query.propertyType) params.set("propertyType", query.propertyType);
|
|
3099
|
+
if (query.type) params.set("type", query.type);
|
|
3100
|
+
const url = `${base}/api/sites/${encodeURIComponent(siteId)}/market/neighborhood-summary?${params.toString()}`;
|
|
3101
|
+
try {
|
|
3102
|
+
return await callJson(
|
|
3103
|
+
url,
|
|
3104
|
+
{ method: "GET", headers: { Accept: "application/json" }, next },
|
|
3105
|
+
fetchImpl ?? fetch
|
|
3106
|
+
);
|
|
3107
|
+
} catch (error) {
|
|
3108
|
+
if (!isRateLimited(error)) throw error;
|
|
3109
|
+
return {
|
|
3110
|
+
available: false,
|
|
3111
|
+
reason: "rate_limited",
|
|
3112
|
+
city: query.city,
|
|
3113
|
+
neighborhood: query.neighborhood,
|
|
3114
|
+
propertyType: query.propertyType ?? null,
|
|
3115
|
+
type: query.type ?? "sale",
|
|
3116
|
+
months: 12,
|
|
3117
|
+
pricePerSqmCents: { p25: null, p50: null, p75: null },
|
|
3118
|
+
pricePerSqmFormatted: { p25: "\u2014", p50: "\u2014", p75: "\u2014" },
|
|
3119
|
+
sampleSize: null,
|
|
3120
|
+
message: RATE_LIMITED_MESSAGE
|
|
3121
|
+
};
|
|
3122
|
+
}
|
|
3123
|
+
}
|
|
3124
|
+
async function getListingMarketPosition(options) {
|
|
3125
|
+
const { listingId: rawListingId, baseUrl, fetch: fetchImpl, next } = options;
|
|
3126
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
3127
|
+
const listingId = listingLookupKey(rawListingId ?? "");
|
|
3128
|
+
if (!listingId || listingId === "undefined" || listingId === "null") {
|
|
3129
|
+
throw new TypeError("getListingMarketPosition: `listingId` is required");
|
|
3130
|
+
}
|
|
3131
|
+
const base = normalizeBaseUrl(baseUrl);
|
|
3132
|
+
const url = `${base}/api/sites/${encodeURIComponent(siteId)}/listings/${encodeURIComponent(
|
|
3133
|
+
listingId
|
|
3134
|
+
)}/market-position`;
|
|
3135
|
+
try {
|
|
3136
|
+
return await callJson(
|
|
3137
|
+
url,
|
|
3138
|
+
{ method: "GET", headers: { Accept: "application/json" }, next },
|
|
3139
|
+
fetchImpl ?? fetch
|
|
3140
|
+
);
|
|
3141
|
+
} catch (error) {
|
|
3142
|
+
if (!isRateLimited(error)) throw error;
|
|
3143
|
+
return {
|
|
3144
|
+
available: false,
|
|
3145
|
+
reason: "rate_limited",
|
|
3146
|
+
listingId,
|
|
3147
|
+
city: null,
|
|
3148
|
+
neighborhood: null,
|
|
3149
|
+
months: 12,
|
|
3150
|
+
listingPricePerSqmCents: null,
|
|
3151
|
+
listingPricePerSqmFormatted: "\u2014",
|
|
3152
|
+
medianPricePerSqmCents: null,
|
|
3153
|
+
medianPricePerSqmFormatted: "\u2014",
|
|
3154
|
+
percentVsMedian: null,
|
|
3155
|
+
band: null,
|
|
3156
|
+
sampleSize: null,
|
|
3157
|
+
message: RATE_LIMITED_MESSAGE
|
|
3158
|
+
};
|
|
3159
|
+
}
|
|
3160
|
+
}
|
|
3161
|
+
async function requestPriceEstimate(options) {
|
|
3162
|
+
const { input, baseUrl, fetch: fetchImpl, next } = options;
|
|
3163
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
3164
|
+
if (!input?.city?.trim() || typeof input.areaSqm !== "number") {
|
|
3165
|
+
throw new TypeError(
|
|
3166
|
+
"requestPriceEstimate: `input.city` and `input.areaSqm` are required"
|
|
3167
|
+
);
|
|
3168
|
+
}
|
|
3169
|
+
const base = normalizeBaseUrl(baseUrl);
|
|
3170
|
+
const url = `${base}/api/sites/${encodeURIComponent(siteId)}/market/estimate`;
|
|
3171
|
+
try {
|
|
3172
|
+
return await callJson(
|
|
3173
|
+
url,
|
|
3174
|
+
{
|
|
3175
|
+
method: "POST",
|
|
3176
|
+
headers: {
|
|
3177
|
+
Accept: "application/json",
|
|
3178
|
+
"Content-Type": "application/json"
|
|
3179
|
+
},
|
|
3180
|
+
body: JSON.stringify(input),
|
|
3181
|
+
next
|
|
3182
|
+
},
|
|
3183
|
+
fetchImpl ?? fetch
|
|
3184
|
+
);
|
|
3185
|
+
} catch (error) {
|
|
3186
|
+
if (!isRateLimited(error)) throw error;
|
|
3187
|
+
return {
|
|
3188
|
+
available: false,
|
|
3189
|
+
reason: "rate_limited",
|
|
3190
|
+
city: input.city,
|
|
3191
|
+
neighborhood: input.neighborhood ?? null,
|
|
3192
|
+
estimatedPriceCents: null,
|
|
3193
|
+
estimatedPriceFormatted: "\u2014",
|
|
3194
|
+
rangeLowCents: null,
|
|
3195
|
+
rangeHighCents: null,
|
|
3196
|
+
rangeLowFormatted: "\u2014",
|
|
3197
|
+
rangeHighFormatted: "\u2014",
|
|
3198
|
+
confidenceLabel: null,
|
|
3199
|
+
sampleSize: null,
|
|
3200
|
+
message: RATE_LIMITED_MESSAGE
|
|
3201
|
+
};
|
|
3202
|
+
}
|
|
3203
|
+
}
|
|
3204
|
+
|
|
3205
|
+
// src/market-labels.ts
|
|
3206
|
+
function marketPositionLabel(position) {
|
|
3207
|
+
if (!position?.available) return null;
|
|
3208
|
+
const percent = position.percentVsMedian;
|
|
3209
|
+
if (percent == null || !Number.isFinite(percent)) return null;
|
|
3210
|
+
const rounded = Math.round(percent);
|
|
3211
|
+
if (rounded === 0) return "Na mediana do bairro";
|
|
3212
|
+
const magnitude = Math.abs(rounded);
|
|
3213
|
+
return rounded < 0 ? `${magnitude}% abaixo da mediana do bairro` : `${magnitude}% acima da mediana do bairro`;
|
|
3214
|
+
}
|
|
3215
|
+
var BAND_LABELS = {
|
|
3216
|
+
below_range: "Abaixo da faixa do bairro",
|
|
3217
|
+
lower_range: "Na faixa do bairro, abaixo da mediana",
|
|
3218
|
+
upper_range: "Na faixa do bairro, acima da mediana",
|
|
3219
|
+
above_range: "Acima da faixa do bairro"
|
|
3220
|
+
};
|
|
3221
|
+
function priceBandLabel(input) {
|
|
3222
|
+
if (!input) return null;
|
|
3223
|
+
if (typeof input === "string") return BAND_LABELS[input] ?? null;
|
|
3224
|
+
if (!input.available || !input.band) return null;
|
|
3225
|
+
return BAND_LABELS[input.band] ?? null;
|
|
3226
|
+
}
|
|
3227
|
+
|
|
3228
|
+
// src/fetchers-photo-search.ts
|
|
3229
|
+
var PHOTO_SEARCH_MIN_QUERY_LENGTH = 3;
|
|
3230
|
+
var EMPTY_RESULT = {
|
|
3231
|
+
available: true,
|
|
3232
|
+
items: [],
|
|
3233
|
+
total: 0,
|
|
3234
|
+
page: 1,
|
|
3235
|
+
limit: 12
|
|
3236
|
+
};
|
|
3237
|
+
function positiveInt(value) {
|
|
3238
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < 1) {
|
|
3239
|
+
return null;
|
|
3240
|
+
}
|
|
3241
|
+
return Math.floor(value);
|
|
3242
|
+
}
|
|
3243
|
+
function photoSearchUrl(siteId, params, baseUrl) {
|
|
3244
|
+
const search = new URLSearchParams();
|
|
3245
|
+
search.set("q", params.q.trim());
|
|
3246
|
+
const limit = positiveInt(params.limit);
|
|
3247
|
+
if (limit != null) search.set("limit", String(limit));
|
|
3248
|
+
const page = positiveInt(params.page);
|
|
3249
|
+
if (page != null) search.set("page", String(page));
|
|
3250
|
+
return `${normalizeBaseUrl(baseUrl)}/api/sites/${encodeURIComponent(
|
|
3251
|
+
siteId
|
|
3252
|
+
)}/search/photos?${search.toString()}`;
|
|
3253
|
+
}
|
|
3254
|
+
async function searchListingPhotos(siteId, params, options = {}) {
|
|
3255
|
+
const q = (params?.q ?? "").trim();
|
|
3256
|
+
const limit = positiveInt(params?.limit) ?? EMPTY_RESULT.limit;
|
|
3257
|
+
if (q.length < PHOTO_SEARCH_MIN_QUERY_LENGTH) {
|
|
3258
|
+
return { ...EMPTY_RESULT, limit, page: positiveInt(params?.page) ?? 1 };
|
|
3259
|
+
}
|
|
3260
|
+
const resolvedSiteId = await coerceSiteId(siteId);
|
|
3261
|
+
const url = photoSearchUrl(resolvedSiteId, { ...params, q }, options.baseUrl);
|
|
3262
|
+
const data = await callJson(
|
|
3263
|
+
url,
|
|
3264
|
+
{
|
|
3265
|
+
method: "GET",
|
|
3266
|
+
headers: { Accept: "application/json" },
|
|
3267
|
+
next: options.next
|
|
3268
|
+
},
|
|
3269
|
+
options.fetch ?? fetch
|
|
3270
|
+
);
|
|
3271
|
+
const items = Array.isArray(data.items) ? data.items : [];
|
|
3272
|
+
return {
|
|
3273
|
+
available: data.available !== false,
|
|
3274
|
+
items,
|
|
3275
|
+
total: typeof data.total === "number" ? data.total : items.length,
|
|
3276
|
+
page: typeof data.page === "number" ? data.page : positiveInt(params.page) ?? 1,
|
|
3277
|
+
limit: typeof data.limit === "number" ? data.limit : limit
|
|
3278
|
+
};
|
|
3279
|
+
}
|
|
3280
|
+
|
|
3281
|
+
// src/photo-search-cover.ts
|
|
3282
|
+
var MATCHED_PHOTO_COVER_MAX_DISTANCE = 0.4;
|
|
3283
|
+
function resolveMatchedCoverPhoto(photo, maxDistance = MATCHED_PHOTO_COVER_MAX_DISTANCE) {
|
|
3284
|
+
if (!photo || !photo.src) return null;
|
|
3285
|
+
if (photo.distance == null) return photo;
|
|
3286
|
+
if (!Number.isFinite(photo.distance)) return null;
|
|
3287
|
+
return photo.distance <= maxDistance ? photo : null;
|
|
3288
|
+
}
|
|
3289
|
+
function itemsOf(photoResults) {
|
|
3290
|
+
if (!photoResults) return [];
|
|
3291
|
+
return Array.isArray(photoResults) ? photoResults : photoResults.items ?? [];
|
|
3292
|
+
}
|
|
3293
|
+
function applyMatchedPhotoCover(cards, photoResults, options = {}) {
|
|
3294
|
+
const maxDistance = options.maxDistance ?? MATCHED_PHOTO_COVER_MAX_DISTANCE;
|
|
3295
|
+
const photoByListingId = /* @__PURE__ */ new Map();
|
|
3296
|
+
for (const item of itemsOf(photoResults)) {
|
|
3297
|
+
const id = item?.listing?.id;
|
|
3298
|
+
if (!id || photoByListingId.has(id)) continue;
|
|
3299
|
+
const photo = resolveMatchedCoverPhoto(item.matchedPhoto, maxDistance);
|
|
3300
|
+
if (photo) photoByListingId.set(id, photo);
|
|
3301
|
+
}
|
|
3302
|
+
return cards.map((card) => {
|
|
3303
|
+
const photo = photoByListingId.get(card.id) ?? null;
|
|
3304
|
+
if (!photo) return { ...card, matchedPhoto: null };
|
|
3305
|
+
return {
|
|
3306
|
+
...card,
|
|
3307
|
+
coverImage: {
|
|
3308
|
+
src: photo.src,
|
|
3309
|
+
alt: photo.alt || card.coverImage?.alt || card.title
|
|
3310
|
+
},
|
|
3311
|
+
matchedPhoto: photo
|
|
3312
|
+
};
|
|
3313
|
+
});
|
|
3314
|
+
}
|
|
3005
3315
|
export {
|
|
3006
3316
|
AMENITY_FALLBACK_LABELS,
|
|
3007
3317
|
DEFAULT_PHONE_COUNTRY_CODE,
|
|
@@ -3010,8 +3320,10 @@ export {
|
|
|
3010
3320
|
LISTING_AMENITY_TITLES,
|
|
3011
3321
|
LISTING_DESCRIPTION_CLAMP,
|
|
3012
3322
|
LeadSubmitError,
|
|
3323
|
+
MATCHED_PHOTO_COVER_MAX_DISTANCE,
|
|
3013
3324
|
MAX_NATIONAL_PHONE_DIGITS,
|
|
3014
3325
|
PHONE_COUNTRIES,
|
|
3326
|
+
PHOTO_SEARCH_MIN_QUERY_LENGTH,
|
|
3015
3327
|
SEARCH_EMPTY_COPY,
|
|
3016
3328
|
SEARCH_SORT_RELEVANCE,
|
|
3017
3329
|
STUDIO_DEFAULT_VISIT_SCHEDULE,
|
|
@@ -3020,6 +3332,7 @@ export {
|
|
|
3020
3332
|
STUDIO_SITE_LAYOUT,
|
|
3021
3333
|
TOOLBAR_PRIMARY_FILTER_IDS,
|
|
3022
3334
|
VISIT_TIME_ZONE,
|
|
3335
|
+
applyMatchedPhotoCover,
|
|
3023
3336
|
applyPathFilter,
|
|
3024
3337
|
buildQueryListingsParams,
|
|
3025
3338
|
canonicalizeSearchHref,
|
|
@@ -3047,7 +3360,9 @@ export {
|
|
|
3047
3360
|
getCmsEntry,
|
|
3048
3361
|
getLeadUi,
|
|
3049
3362
|
getListing,
|
|
3363
|
+
getListingMarketPosition,
|
|
3050
3364
|
getListings,
|
|
3365
|
+
getNeighborhoodSummary,
|
|
3051
3366
|
getSearchUi,
|
|
3052
3367
|
getSimilarListings,
|
|
3053
3368
|
getSite,
|
|
@@ -3056,6 +3371,7 @@ export {
|
|
|
3056
3371
|
hrefForPathFilters,
|
|
3057
3372
|
hrefWithExplicitPage,
|
|
3058
3373
|
isListingDetailPath,
|
|
3374
|
+
isPhotoSearchOnPin,
|
|
3059
3375
|
isStudioPreviewHost,
|
|
3060
3376
|
isValidPhone,
|
|
3061
3377
|
isVisitSlotAllowed,
|
|
@@ -3074,6 +3390,8 @@ export {
|
|
|
3074
3390
|
listingMediaOverlays,
|
|
3075
3391
|
listingPublicPath,
|
|
3076
3392
|
listingValues,
|
|
3393
|
+
marketExportsAvailableAt,
|
|
3394
|
+
marketPositionLabel,
|
|
3077
3395
|
mergeAppliedSearchQueryIntoSearch2 as mergeAppliedSearchQueryIntoSearch,
|
|
3078
3396
|
nationalPhoneDigits,
|
|
3079
3397
|
normalizeVisitDate,
|
|
@@ -3089,15 +3407,20 @@ export {
|
|
|
3089
3407
|
pathFiltersToQueryFilters,
|
|
3090
3408
|
pathLocationToFilterInput,
|
|
3091
3409
|
phoneCountrySearchValue,
|
|
3410
|
+
photoSearchUrl,
|
|
3411
|
+
priceBandLabel,
|
|
3092
3412
|
publicSearchHref,
|
|
3093
3413
|
queryListings,
|
|
3094
3414
|
rangeDraftFromPath,
|
|
3095
3415
|
readPublicSearch,
|
|
3096
3416
|
reduceAppliedSearchQuery2 as reduceAppliedSearchQuery,
|
|
3097
3417
|
remaskPhoneForCountry,
|
|
3418
|
+
requestPriceEstimate,
|
|
3419
|
+
resolveMatchedCoverPhoto,
|
|
3098
3420
|
resolvePublicSiteId,
|
|
3099
3421
|
searchChromeModel,
|
|
3100
3422
|
searchHrefUsesLegacyFilterQuery,
|
|
3423
|
+
searchListingPhotos,
|
|
3101
3424
|
searchListings,
|
|
3102
3425
|
searchResultsHeading,
|
|
3103
3426
|
searchSortOptions,
|
|
@@ -3111,6 +3434,8 @@ export {
|
|
|
3111
3434
|
studioLeadInstruction,
|
|
3112
3435
|
studioListingCardInstruction,
|
|
3113
3436
|
studioListingDetailInstruction,
|
|
3437
|
+
studioMarketInstruction,
|
|
3438
|
+
studioPhotoSearchInstruction,
|
|
3114
3439
|
studioSdkPinInstruction,
|
|
3115
3440
|
studioSearchInstruction,
|
|
3116
3441
|
studioSearchLandmarkInstruction,
|