@garagem-ai/site-sdk 0.6.0 → 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 +330 -166
- package/dist/index.d.ts +330 -166
- package/dist/index.js +365 -24
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +350 -24
- 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 +125 -23
- 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
|
@@ -2592,11 +2592,13 @@ var STUDIO_SDK_CONTRACT = {
|
|
|
2592
2592
|
* Exact pin for generated Studio sites. Must match a tarball already on
|
|
2593
2593
|
* npm — v0 installs this version. After a later changeset publishes, bump
|
|
2594
2594
|
* this and move that release's names from `optionalReactExports` /
|
|
2595
|
-
* `unpublishedSearchExports` into the
|
|
2596
|
-
* until that tarball is on npm.
|
|
2597
|
-
*
|
|
2595
|
+
* `unpublishedSearchExports` / `unpublishedPhoneExports` into the
|
|
2596
|
+
* prompt-safe lists. Do not bump here until that tarball is on npm.
|
|
2597
|
+
* Phone mask helpers shipped in 0.6.0. Search filter helpers
|
|
2598
|
+
* (`visibleSearchFilters` / `toolbarFilterIds`) shipped in 0.4.12 and
|
|
2599
|
+
* remain on this pin.
|
|
2598
2600
|
*/
|
|
2599
|
-
minNpmVersion: "0.
|
|
2601
|
+
minNpmVersion: "0.6.0",
|
|
2600
2602
|
/** Historical: older tarballs inject card CSS when those components mount. */
|
|
2601
2603
|
selfInjectSince: "0.4.2",
|
|
2602
2604
|
chromeStrategy: "app-owned",
|
|
@@ -2608,7 +2610,9 @@ var STUDIO_SDK_CONTRACT = {
|
|
|
2608
2610
|
* “never import”) — v0 copies the identifier and the preview ESM loader
|
|
2609
2611
|
* throws FatalRendererError.
|
|
2610
2612
|
*/
|
|
2611
|
-
optionalReactExports: {
|
|
2613
|
+
optionalReactExports: {
|
|
2614
|
+
usePublicPhotoSearch: "0.7.0"
|
|
2615
|
+
},
|
|
2612
2616
|
/**
|
|
2613
2617
|
* Former `/react` chrome (including card/skeleton inject). Completeness
|
|
2614
2618
|
* flags imports as mismatch (not in `reactExports`). Prompts must not
|
|
@@ -2649,18 +2653,9 @@ var STUDIO_SDK_CONTRACT = {
|
|
|
2649
2653
|
"formatListingPrice"
|
|
2650
2654
|
],
|
|
2651
2655
|
/**
|
|
2652
|
-
* Prompt-safe phone helpers on `minNpmVersion
|
|
2653
|
-
* tarball exports them and this pin bumps — then move names here from
|
|
2654
|
-
* `unpublishedPhoneExports`.
|
|
2656
|
+
* Prompt-safe phone helpers on `minNpmVersion` (published in 0.6.0).
|
|
2655
2657
|
*/
|
|
2656
|
-
phoneExports: [
|
|
2657
|
-
/**
|
|
2658
|
-
* Headless phone mask helpers in git / newer tarballs but not on
|
|
2659
|
-
* `minNpmVersion` (0.4.12). Prompts, completeness, and repair text must
|
|
2660
|
-
* not mention these until the pin bumps — v0 installs the pin and the
|
|
2661
|
-
* ESM loader throws on missing named exports.
|
|
2662
|
-
*/
|
|
2663
|
-
unpublishedPhoneExports: [
|
|
2658
|
+
phoneExports: [
|
|
2664
2659
|
"PHONE_COUNTRIES",
|
|
2665
2660
|
"formatPhoneNational",
|
|
2666
2661
|
"toE164",
|
|
@@ -2670,12 +2665,19 @@ var STUDIO_SDK_CONTRACT = {
|
|
|
2670
2665
|
"findPhoneCountry",
|
|
2671
2666
|
"remaskPhoneForCountry"
|
|
2672
2667
|
],
|
|
2668
|
+
/**
|
|
2669
|
+
* Headless phone helpers in git but not on `minNpmVersion`. Prompts,
|
|
2670
|
+
* completeness, and repair text must not mention these until the pin
|
|
2671
|
+
* bumps — v0 installs the pin and the ESM loader throws on missing
|
|
2672
|
+
* named exports.
|
|
2673
|
+
*/
|
|
2674
|
+
unpublishedPhoneExports: [],
|
|
2673
2675
|
amenityExports: ["listingAmenityGroups"],
|
|
2674
2676
|
/**
|
|
2675
|
-
* Names already on the pinned npm tarball (`minNpmVersion`
|
|
2676
|
-
*
|
|
2677
|
-
* `
|
|
2678
|
-
*
|
|
2677
|
+
* Names already on the pinned npm tarball (`minNpmVersion`) — safe for
|
|
2678
|
+
* Studio prompts and completeness. Includes `visibleSearchFilters` +
|
|
2679
|
+
* `toolbarFilterIds` (shipped in 0.4.12). Do not confuse with
|
|
2680
|
+
* `unpublishedSearchExports` (`searchChromeModel`, …).
|
|
2679
2681
|
*/
|
|
2680
2682
|
searchExports: [
|
|
2681
2683
|
"searchResultsHeading",
|
|
@@ -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,12 +2818,13 @@ 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() {
|
|
2788
2825
|
const names = STUDIO_SDK_CONTRACT.leadExports.join(", ");
|
|
2789
|
-
|
|
2826
|
+
const phone = STUDIO_SDK_CONTRACT.phoneExports.join(", ");
|
|
2827
|
+
return `Listing-detail visit/contact leads: import ${names} from \`${STUDIO_SDK_PACKAGE}\` (the main package, not \`/react\`). Call \`submitVisitLead\` / \`submitContactLead\` \u2014 never concatenate a leads webhook URL and never POST the Showcase demo leads route. Phone fields: import ${phone} from the same package. Display draft is \`formatPhoneNational\` (default country \`BR\`); changing country calls \`remaskPhoneForCountry\`; submit \`toE164\` and require \`isValidPhone\`. Do not invent a second mask and do not import \`@garagem/ui\` PhoneInput.`;
|
|
2790
2828
|
}
|
|
2791
2829
|
function studioListingCardInstruction() {
|
|
2792
2830
|
const names = STUDIO_SDK_CONTRACT.listingCardExports.join(", ");
|
|
@@ -2804,6 +2842,27 @@ function studioSearchInstruction() {
|
|
|
2804
2842
|
const libNames = STUDIO_SDK_CONTRACT.searchExports.join(", ");
|
|
2805
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)}`;
|
|
2806
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
|
+
}
|
|
2807
2866
|
function studioChromeInstruction() {
|
|
2808
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\`.`;
|
|
2809
2868
|
}
|
|
@@ -2812,7 +2871,10 @@ function mentionsExportName(text, name) {
|
|
|
2812
2871
|
}
|
|
2813
2872
|
function studioCodegenContractViolations(text) {
|
|
2814
2873
|
const violations = [];
|
|
2815
|
-
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;
|
|
2816
2878
|
if (mentionsExportName(text, name)) violations.push(name);
|
|
2817
2879
|
}
|
|
2818
2880
|
for (const name of STUDIO_SDK_CONTRACT.retiredReactExports) {
|
|
@@ -2830,7 +2892,21 @@ function studioCodegenContractViolations(text) {
|
|
|
2830
2892
|
violations.push(name);
|
|
2831
2893
|
}
|
|
2832
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
|
+
}
|
|
2833
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
|
+
}
|
|
2834
2910
|
const available = reactExportsAvailableAt(pin);
|
|
2835
2911
|
for (const name of parseReactSdkNamedImports(text)) {
|
|
2836
2912
|
if (!available.has(name) && !violations.includes(name)) {
|
|
@@ -3001,6 +3077,241 @@ function createGaragemClient(options = {}) {
|
|
|
3001
3077
|
}
|
|
3002
3078
|
};
|
|
3003
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
|
+
}
|
|
3004
3315
|
export {
|
|
3005
3316
|
AMENITY_FALLBACK_LABELS,
|
|
3006
3317
|
DEFAULT_PHONE_COUNTRY_CODE,
|
|
@@ -3009,8 +3320,10 @@ export {
|
|
|
3009
3320
|
LISTING_AMENITY_TITLES,
|
|
3010
3321
|
LISTING_DESCRIPTION_CLAMP,
|
|
3011
3322
|
LeadSubmitError,
|
|
3323
|
+
MATCHED_PHOTO_COVER_MAX_DISTANCE,
|
|
3012
3324
|
MAX_NATIONAL_PHONE_DIGITS,
|
|
3013
3325
|
PHONE_COUNTRIES,
|
|
3326
|
+
PHOTO_SEARCH_MIN_QUERY_LENGTH,
|
|
3014
3327
|
SEARCH_EMPTY_COPY,
|
|
3015
3328
|
SEARCH_SORT_RELEVANCE,
|
|
3016
3329
|
STUDIO_DEFAULT_VISIT_SCHEDULE,
|
|
@@ -3019,6 +3332,7 @@ export {
|
|
|
3019
3332
|
STUDIO_SITE_LAYOUT,
|
|
3020
3333
|
TOOLBAR_PRIMARY_FILTER_IDS,
|
|
3021
3334
|
VISIT_TIME_ZONE,
|
|
3335
|
+
applyMatchedPhotoCover,
|
|
3022
3336
|
applyPathFilter,
|
|
3023
3337
|
buildQueryListingsParams,
|
|
3024
3338
|
canonicalizeSearchHref,
|
|
@@ -3046,7 +3360,9 @@ export {
|
|
|
3046
3360
|
getCmsEntry,
|
|
3047
3361
|
getLeadUi,
|
|
3048
3362
|
getListing,
|
|
3363
|
+
getListingMarketPosition,
|
|
3049
3364
|
getListings,
|
|
3365
|
+
getNeighborhoodSummary,
|
|
3050
3366
|
getSearchUi,
|
|
3051
3367
|
getSimilarListings,
|
|
3052
3368
|
getSite,
|
|
@@ -3055,6 +3371,7 @@ export {
|
|
|
3055
3371
|
hrefForPathFilters,
|
|
3056
3372
|
hrefWithExplicitPage,
|
|
3057
3373
|
isListingDetailPath,
|
|
3374
|
+
isPhotoSearchOnPin,
|
|
3058
3375
|
isStudioPreviewHost,
|
|
3059
3376
|
isValidPhone,
|
|
3060
3377
|
isVisitSlotAllowed,
|
|
@@ -3073,6 +3390,8 @@ export {
|
|
|
3073
3390
|
listingMediaOverlays,
|
|
3074
3391
|
listingPublicPath,
|
|
3075
3392
|
listingValues,
|
|
3393
|
+
marketExportsAvailableAt,
|
|
3394
|
+
marketPositionLabel,
|
|
3076
3395
|
mergeAppliedSearchQueryIntoSearch2 as mergeAppliedSearchQueryIntoSearch,
|
|
3077
3396
|
nationalPhoneDigits,
|
|
3078
3397
|
normalizeVisitDate,
|
|
@@ -3088,15 +3407,20 @@ export {
|
|
|
3088
3407
|
pathFiltersToQueryFilters,
|
|
3089
3408
|
pathLocationToFilterInput,
|
|
3090
3409
|
phoneCountrySearchValue,
|
|
3410
|
+
photoSearchUrl,
|
|
3411
|
+
priceBandLabel,
|
|
3091
3412
|
publicSearchHref,
|
|
3092
3413
|
queryListings,
|
|
3093
3414
|
rangeDraftFromPath,
|
|
3094
3415
|
readPublicSearch,
|
|
3095
3416
|
reduceAppliedSearchQuery2 as reduceAppliedSearchQuery,
|
|
3096
3417
|
remaskPhoneForCountry,
|
|
3418
|
+
requestPriceEstimate,
|
|
3419
|
+
resolveMatchedCoverPhoto,
|
|
3097
3420
|
resolvePublicSiteId,
|
|
3098
3421
|
searchChromeModel,
|
|
3099
3422
|
searchHrefUsesLegacyFilterQuery,
|
|
3423
|
+
searchListingPhotos,
|
|
3100
3424
|
searchListings,
|
|
3101
3425
|
searchResultsHeading,
|
|
3102
3426
|
searchSortOptions,
|
|
@@ -3110,6 +3434,8 @@ export {
|
|
|
3110
3434
|
studioLeadInstruction,
|
|
3111
3435
|
studioListingCardInstruction,
|
|
3112
3436
|
studioListingDetailInstruction,
|
|
3437
|
+
studioMarketInstruction,
|
|
3438
|
+
studioPhotoSearchInstruction,
|
|
3113
3439
|
studioSdkPinInstruction,
|
|
3114
3440
|
studioSearchInstruction,
|
|
3115
3441
|
studioSearchLandmarkInstruction,
|