@garagem-ai/site-sdk 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +162 -5
- package/dist/index.d.mts +130 -43
- package/dist/index.d.ts +130 -43
- package/dist/index.js +744 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +705 -2
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.mts +24 -2
- package/dist/react.d.ts +24 -2
- package/dist/react.js +499 -12
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +498 -12
- package/dist/react.mjs.map +1 -1
- package/dist/{types-photo-search-CmGRj6my.d.mts → types-photo-search-D88oevZv.d.mts} +375 -1
- package/dist/{types-photo-search-CmGRj6my.d.ts → types-photo-search-D88oevZv.d.ts} +375 -1
- package/package.json +1 -1
- package/src/fetchers.ts +4 -1
- package/src/index.ts +89 -0
- package/src/map-search.ts +487 -0
- package/src/maps.ts +743 -0
- package/src/react/index.ts +2 -0
- package/src/react/use-map-search.ts +101 -0
- package/src/studio-contract.ts +46 -0
- package/src/types-maps.ts +275 -0
- package/src/types.ts +12 -0
package/dist/index.js
CHANGED
|
@@ -21,12 +21,19 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var src_exports = {};
|
|
22
22
|
__export(src_exports, {
|
|
23
23
|
AMENITY_FALLBACK_LABELS: () => AMENITY_FALLBACK_LABELS,
|
|
24
|
+
DEFAULT_MAPS_BASE_URL: () => DEFAULT_MAPS_BASE_URL,
|
|
24
25
|
DEFAULT_PHONE_COUNTRY_CODE: () => DEFAULT_PHONE_COUNTRY_CODE,
|
|
25
26
|
FORBIDDEN_SEARCH_QUERY_KEYS: () => FORBIDDEN_SEARCH_QUERY_KEYS,
|
|
26
27
|
GaragemSdkError: () => GaragemSdkError,
|
|
27
28
|
LISTING_AMENITY_TITLES: () => LISTING_AMENITY_TITLES,
|
|
28
29
|
LISTING_DESCRIPTION_CLAMP: () => LISTING_DESCRIPTION_CLAMP,
|
|
29
30
|
LeadSubmitError: () => LeadSubmitError,
|
|
31
|
+
MAPS_MAX_IMAGE_EDGE: () => MAPS_MAX_IMAGE_EDGE,
|
|
32
|
+
MAPS_SITE_HEADER: () => MAPS_SITE_HEADER,
|
|
33
|
+
MAP_POLYGON_MAX_VERTICES: () => MAP_POLYGON_MAX_VERTICES,
|
|
34
|
+
MAP_SEARCH_DEFAULT_PAGE_SIZE: () => MAP_SEARCH_DEFAULT_PAGE_SIZE,
|
|
35
|
+
MAP_SEARCH_MAX_PAGE_SIZE: () => MAP_SEARCH_MAX_PAGE_SIZE,
|
|
36
|
+
MAP_VIEWPORT_DEBOUNCE_MS: () => MAP_VIEWPORT_DEBOUNCE_MS,
|
|
30
37
|
MATCHED_PHOTO_COVER_MAX_DISTANCE: () => MATCHED_PHOTO_COVER_MAX_DISTANCE,
|
|
31
38
|
MAX_NATIONAL_PHONE_DIGITS: () => MAX_NATIONAL_PHONE_DIGITS,
|
|
32
39
|
PHONE_COUNTRIES: () => PHONE_COUNTRIES,
|
|
@@ -43,18 +50,28 @@ __export(src_exports, {
|
|
|
43
50
|
VISIT_TIME_ZONE: () => VISIT_TIME_ZONE,
|
|
44
51
|
applyMatchedPhotoCover: () => applyMatchedPhotoCover,
|
|
45
52
|
applyPathFilter: () => applyPathFilter,
|
|
53
|
+
boundaryCitySlug: () => boundaryCitySlug,
|
|
54
|
+
boundaryLayerId: () => boundaryLayerId,
|
|
55
|
+
boundaryLayerUrl: () => boundaryLayerUrl,
|
|
46
56
|
buildQueryListingsParams: () => buildQueryListingsParams,
|
|
47
57
|
canonicalizeSearchHref: () => canonicalizeSearchHref,
|
|
58
|
+
capMapPage: () => capMapPage,
|
|
59
|
+
capMapPageSize: () => capMapPageSize,
|
|
48
60
|
clearStagedPathFilters: () => clearStagedPathFilters,
|
|
61
|
+
clearTravelTimeCache: () => clearTravelTimeCache,
|
|
62
|
+
clusterPins: () => clusterPins,
|
|
63
|
+
coarsenCoordinates: () => coarsenCoordinates,
|
|
49
64
|
coerceNpmVersion: () => coerceNpmVersion,
|
|
50
65
|
collapseDuplicatedBrazilianMobileNine: () => collapseDuplicatedBrazilianMobileNine,
|
|
51
66
|
compareSemver: () => compareSemver,
|
|
52
67
|
composeSearchPublicHref: () => composeSearchPublicHref2,
|
|
53
68
|
composeSearchPublicPath: () => composeSearchPublicPath2,
|
|
69
|
+
coordinateDecimals: () => coordinateDecimals,
|
|
54
70
|
countFacetChoices: () => countFacetChoices,
|
|
55
71
|
countOptionLabel: () => countOptionLabel,
|
|
56
72
|
createClient: () => createClient,
|
|
57
73
|
createGaragemClient: () => createGaragemClient,
|
|
74
|
+
createTravelTimeCache: () => createTravelTimeCache,
|
|
58
75
|
defaultPhoneCountry: () => defaultPhoneCountry,
|
|
59
76
|
displayPathLocation: () => displayPathLocation,
|
|
60
77
|
expandVisitSchedule: () => expandVisitSchedule,
|
|
@@ -64,6 +81,7 @@ __export(src_exports, {
|
|
|
64
81
|
formatGroupedInteger: () => formatGroupedInteger,
|
|
65
82
|
formatListingPrice: () => formatListingPrice,
|
|
66
83
|
formatPhoneNational: () => formatPhoneNational,
|
|
84
|
+
getBoundaryLayer: () => getBoundaryLayer,
|
|
67
85
|
getCmsCollection: () => getCmsCollection,
|
|
68
86
|
getCmsCollections: () => getCmsCollections,
|
|
69
87
|
getCmsEntries: () => getCmsEntries,
|
|
@@ -82,6 +100,8 @@ __export(src_exports, {
|
|
|
82
100
|
hrefForPathFilters: () => hrefForPathFilters,
|
|
83
101
|
hrefWithExplicitPage: () => hrefWithExplicitPage,
|
|
84
102
|
isListingDetailPath: () => isListingDetailPath,
|
|
103
|
+
isMapBounds: () => isMapBounds,
|
|
104
|
+
isMapPolygon: () => isMapPolygon,
|
|
85
105
|
isPhotoSearchOnPin: () => isPhotoSearchOnPin,
|
|
86
106
|
isStudioPreviewHost: () => isStudioPreviewHost,
|
|
87
107
|
isValidPhone: () => isValidPhone,
|
|
@@ -90,6 +110,7 @@ __export(src_exports, {
|
|
|
90
110
|
listingAmenityGroups: () => listingAmenityGroups,
|
|
91
111
|
listingBreadcrumb: () => listingBreadcrumb,
|
|
92
112
|
listingBusinessLabel: () => listingBusinessLabel,
|
|
113
|
+
listingCoordinates: () => listingCoordinates,
|
|
93
114
|
listingDescriptionPreview: () => listingDescriptionPreview,
|
|
94
115
|
listingDetailFieldsModel: () => listingDetailFieldsModel,
|
|
95
116
|
listingDetailModel: () => listingDetailModel,
|
|
@@ -101,12 +122,23 @@ __export(src_exports, {
|
|
|
101
122
|
listingMediaOverlays: () => listingMediaOverlays,
|
|
102
123
|
listingPhotoGroups: () => listingPhotoGroups,
|
|
103
124
|
listingPublicPath: () => listingPublicPath,
|
|
125
|
+
listingStaticMapUrl: () => listingStaticMapUrl,
|
|
126
|
+
listingStreetViewAvailable: () => listingStreetViewAvailable,
|
|
127
|
+
listingStreetViewMetadataUrl: () => listingStreetViewMetadataUrl,
|
|
128
|
+
listingStreetViewUrl: () => listingStreetViewUrl,
|
|
104
129
|
listingValues: () => listingValues,
|
|
105
130
|
listingVisualHighlights: () => listingVisualHighlights,
|
|
131
|
+
mapClusterCellDegrees: () => mapClusterCellDegrees,
|
|
132
|
+
mapSearchPins: () => mapSearchPins,
|
|
133
|
+
mapsExportsPublished: () => mapsExportsPublished,
|
|
106
134
|
marketExportsAvailableAt: () => marketExportsAvailableAt,
|
|
107
135
|
marketPositionLabel: () => marketPositionLabel,
|
|
136
|
+
maxZoomForCoordinates: () => maxZoomForCoordinates,
|
|
108
137
|
mergeAppliedSearchQueryIntoSearch: () => mergeAppliedSearchQueryIntoSearch2,
|
|
109
138
|
nationalPhoneDigits: () => nationalPhoneDigits,
|
|
139
|
+
neighborhoodBoundaryLayer: () => neighborhoodBoundaryLayer,
|
|
140
|
+
neighborhoodBoundaryUrl: () => neighborhoodBoundaryUrl,
|
|
141
|
+
normalizeMapsBaseUrl: () => normalizeMapsBaseUrl,
|
|
110
142
|
normalizeVisitDate: () => normalizeVisitDate,
|
|
111
143
|
normalizeVisitTime: () => normalizeVisitTime,
|
|
112
144
|
paginationPages: () => paginationPages,
|
|
@@ -132,10 +164,13 @@ __export(src_exports, {
|
|
|
132
164
|
requestPriceEstimate: () => requestPriceEstimate,
|
|
133
165
|
resolveMatchedCoverPhoto: () => resolveMatchedCoverPhoto,
|
|
134
166
|
resolvePublicSiteId: () => resolvePublicSiteId,
|
|
167
|
+
resolveTravelDestination: () => resolveTravelDestination,
|
|
135
168
|
searchChromeModel: () => searchChromeModel,
|
|
136
169
|
searchHrefUsesLegacyFilterQuery: () => searchHrefUsesLegacyFilterQuery,
|
|
137
170
|
searchListingPhotos: () => searchListingPhotos,
|
|
138
171
|
searchListings: () => searchListings,
|
|
172
|
+
searchListingsInBounds: () => searchListingsInBounds,
|
|
173
|
+
searchListingsInPolygon: () => searchListingsInPolygon,
|
|
139
174
|
searchResultsHeading: () => searchResultsHeading,
|
|
140
175
|
searchSortOptions: () => searchSortOptions,
|
|
141
176
|
serializeAppliedSearchQuery: () => serializeAppliedSearchQuery2,
|
|
@@ -148,6 +183,7 @@ __export(src_exports, {
|
|
|
148
183
|
studioLeadInstruction: () => studioLeadInstruction,
|
|
149
184
|
studioListingCardInstruction: () => studioListingCardInstruction,
|
|
150
185
|
studioListingDetailInstruction: () => studioListingDetailInstruction,
|
|
186
|
+
studioMapsInstruction: () => studioMapsInstruction,
|
|
151
187
|
studioMarketInstruction: () => studioMarketInstruction,
|
|
152
188
|
studioPhotoInstruction: () => studioPhotoInstruction,
|
|
153
189
|
studioPhotoInstructionFor: () => studioPhotoInstructionFor,
|
|
@@ -162,6 +198,9 @@ __export(src_exports, {
|
|
|
162
198
|
toE164: () => toE164,
|
|
163
199
|
toListingCardModel: () => toListingCardModel,
|
|
164
200
|
toolbarFilterIds: () => toolbarFilterIds,
|
|
201
|
+
travelTimeCacheKey: () => travelTimeCacheKey,
|
|
202
|
+
travelTimeFromListing: () => travelTimeFromListing,
|
|
203
|
+
travelTimesFromListing: () => travelTimesFromListing,
|
|
165
204
|
truncateNationalPhoneDigits: () => truncateNationalPhoneDigits,
|
|
166
205
|
unavailableReactImports: () => unavailableReactImports,
|
|
167
206
|
visibleSearchFilters: () => visibleSearchFilters
|
|
@@ -457,7 +496,7 @@ async function getSearchUi(options) {
|
|
|
457
496
|
);
|
|
458
497
|
}
|
|
459
498
|
async function queryListings(options) {
|
|
460
|
-
const { params, baseUrl, fetch: fetchImpl, next } = options;
|
|
499
|
+
const { params, baseUrl, fetch: fetchImpl, next, signal } = options;
|
|
461
500
|
const siteId = await coerceSiteId(options.siteId);
|
|
462
501
|
const base = normalizeBaseUrl(baseUrl);
|
|
463
502
|
const url = `${base}/api/sites/${encodeURIComponent(siteId)}/search/listings`;
|
|
@@ -470,7 +509,8 @@ async function queryListings(options) {
|
|
|
470
509
|
"Content-Type": "application/json"
|
|
471
510
|
},
|
|
472
511
|
body: JSON.stringify(params ?? {}),
|
|
473
|
-
next
|
|
512
|
+
next,
|
|
513
|
+
signal
|
|
474
514
|
},
|
|
475
515
|
fetchImpl ?? fetch,
|
|
476
516
|
options.publishableKey
|
|
@@ -3026,6 +3066,27 @@ var STUDIO_SDK_CONTRACT = {
|
|
|
3026
3066
|
"searchChromeModel",
|
|
3027
3067
|
"rangeDraftFromPath"
|
|
3028
3068
|
],
|
|
3069
|
+
/**
|
|
3070
|
+
* maps.fndn.ai helpers (static map, street view, boundaries, travel
|
|
3071
|
+
* time) plus friendly map search. They ship in `mapsSince`;
|
|
3072
|
+
* `studioMapsInstruction()` is empty and these names are codegen
|
|
3073
|
+
* violations until `minNpmVersion` reaches that release — bump the pin
|
|
3074
|
+
* after the tarball is on npm and the listing guidance turns on by
|
|
3075
|
+
* itself. `useMapSearch` is a `/react` hook named in that same
|
|
3076
|
+
* instruction; it stays off `reactExports` until the pin moves.
|
|
3077
|
+
*/
|
|
3078
|
+
mapsSince: "0.7.0",
|
|
3079
|
+
mapsExports: [
|
|
3080
|
+
"listingStaticMapUrl",
|
|
3081
|
+
"listingStreetViewUrl",
|
|
3082
|
+
"listingStreetViewAvailable",
|
|
3083
|
+
"neighborhoodBoundaryLayer",
|
|
3084
|
+
"boundaryLayerUrl",
|
|
3085
|
+
"travelTimeFromListing",
|
|
3086
|
+
"searchListingsInBounds",
|
|
3087
|
+
"searchListingsInPolygon",
|
|
3088
|
+
"clusterPins"
|
|
3089
|
+
],
|
|
3029
3090
|
/**
|
|
3030
3091
|
* Market-data helpers (neighborhood price summary, listing market
|
|
3031
3092
|
* position, visitor price estimate, pt-BR labels). They ship in
|
|
@@ -3199,6 +3260,14 @@ function studioSearchInstruction() {
|
|
|
3199
3260
|
const libNames = STUDIO_SDK_CONTRACT.searchExports.join(", ");
|
|
3200
3261
|
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)}`;
|
|
3201
3262
|
}
|
|
3263
|
+
function mapsExportsPublished(pin = STUDIO_SDK_CONTRACT.minNpmVersion) {
|
|
3264
|
+
return compareSemver(pin, STUDIO_SDK_CONTRACT.mapsSince) >= 0;
|
|
3265
|
+
}
|
|
3266
|
+
function studioMapsInstruction(options = {}) {
|
|
3267
|
+
if (!mapsExportsPublished(options.pin)) return "";
|
|
3268
|
+
const names = STUDIO_SDK_CONTRACT.mapsExports.join(", ");
|
|
3269
|
+
return `Maps on listing detail: from \`${STUDIO_SDK_PACKAGE}\` import ${names}. \`listing.location.coordinates\` is already masked by the site's privacy settings (\u2248100 m by default) \u2014 pass the listing object as-is; never un-mask, never re-geocode the street address to get a sharper point, never add decimals (\`maxDecimals\` can only coarsen). Always pass \`siteId\` (the resolved site id / publishable key) so maps.fndn.ai meters the site. Static map: \`const mapSrc = listingStaticMapUrl(listing, { width: 640, height: 320, zoom: 15, style: "roadmap", siteId })\` then \`{mapSrc ? <img src={mapSrc} alt={model.location.label} /> : null}\` \u2014 \`null\` means no coordinates, so omit the block (never a placeholder image). Zoom is capped by the coordinate precision (16 on the default mask); do not work around it. Street View: on the server page \`const sv = await listingStreetViewAvailable(listing, { siteId })\` (metadata is free), and only when \`sv.available\` render \`<img src={listingStreetViewUrl(listing, { width: 640, height: 400, siteId })} alt="Street View" />\` \u2014 the image is billed per load. Neighbourhood outline on an interactive map: load Maps JS ONLY through \`<script src="https://maps.fndn.ai/sdk.js?callback=initMap" async defer />\` (never a Google key in the app, never \`NEXT_PUBLIC_GOOGLE_MAPS_API_KEY\`); in \`initMap\` do \`const outline = await neighborhoodBoundaryLayer(listing.location.city, listing.location.neighborhood, { siteId })\` and \`if (outline.feature) map.data.addGeoJson(outline.feature)\`; with MapLibre the vector source url is \`boundaryLayerUrl(listing.location.city)\`. Travel time (\u201Cquanto tempo at\xE9\u2026\u201D): \`const trip = await travelTimeFromListing(listing, destination, { mode: "driving", siteId })\` gives \`{ minutes, distanceKm }\` or \`null\` (hide the row). Every uncached call is a billed Google Directions request: call it on demand \u2014 a destination the visitor typed, or at most one fixed landmark per listing page \u2014 never per listing card, never inside a search loop, keep the SDK cache on (default 15 min LRU, \`cache: null\` only in tests), and do not re-run it on every render. Map search (search page: search as the map moves, or draw an area): searchListingsInBounds(siteId, { bounds: { north, south, east, west }, zoom, q, sort, location, filters, page, pageSize, publishableKey }) and searchListingsInPolygon(siteId, { polygon: [[lat, lng], ...], q, sort, location, filters, page, pageSize, publishableKey }). Polygon points are [lat, lng], not GeoJSON. The server builds the allowlisted coordinates geo filter from those numbers; do not send a raw filter string from the browser. Pins are { id, lat, lng, price, coverImage } copied from the listings the API returned \u2014 masked pins, plot them as returned, never geocode the street to sharpen one. clusterPins(pins, zoom) is the headless grid: one pin keeps its coordinates, a group centroid is rounded back to the coarsest pin. The React hook useMapSearch (on the /react entry, next to usePublicSearch) debounces viewport changes by 400ms, cancels the stale request, caps pageSize at 100, and returns those pins plus cards from toListingCardModel. Pass the same q, sort, location, filters, and publishableKey as the list (queryListings / usePublicSearch). Dropping them pins listings outside the active query or spends the anonymous listings budget. Cost: every viewport change is a search call \u2014 keep the debounce, do not raise the page size, and do not call travel time or Street View inside that loop.`;
|
|
3270
|
+
}
|
|
3202
3271
|
function marketExportsAvailableAt(pin) {
|
|
3203
3272
|
return compareSemver(pin, STUDIO_SDK_CONTRACT.marketExportsSince) >= 0;
|
|
3204
3273
|
}
|
|
@@ -3249,6 +3318,13 @@ function studioCodegenContractViolations(text) {
|
|
|
3249
3318
|
violations.push(name);
|
|
3250
3319
|
}
|
|
3251
3320
|
}
|
|
3321
|
+
if (!mapsExportsPublished()) {
|
|
3322
|
+
for (const name of STUDIO_SDK_CONTRACT.mapsExports) {
|
|
3323
|
+
if (mentionsExportName(text, name) && !violations.includes(name)) {
|
|
3324
|
+
violations.push(name);
|
|
3325
|
+
}
|
|
3326
|
+
}
|
|
3327
|
+
}
|
|
3252
3328
|
for (const name of STUDIO_SDK_CONTRACT.unpublishedPhotoExports) {
|
|
3253
3329
|
if (mentionsExportName(text, name) && !violations.includes(name)) {
|
|
3254
3330
|
violations.push(name);
|
|
@@ -3447,6 +3523,633 @@ function createGaragemClient(options = {}) {
|
|
|
3447
3523
|
}
|
|
3448
3524
|
var createClient = createGaragemClient;
|
|
3449
3525
|
|
|
3526
|
+
// src/maps.ts
|
|
3527
|
+
var DEFAULT_MAPS_BASE_URL = "https://maps.fndn.ai";
|
|
3528
|
+
var MAPS_SITE_HEADER = "X-Garagem-Site";
|
|
3529
|
+
var MAPS_MAX_IMAGE_EDGE = 640;
|
|
3530
|
+
var TRAVEL_MODES = /* @__PURE__ */ new Set([
|
|
3531
|
+
"driving",
|
|
3532
|
+
"walking",
|
|
3533
|
+
"bicycling",
|
|
3534
|
+
"transit"
|
|
3535
|
+
]);
|
|
3536
|
+
function finite(value) {
|
|
3537
|
+
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
3538
|
+
}
|
|
3539
|
+
function listingCoordinates(listing) {
|
|
3540
|
+
const raw = listing?.location?.coordinates;
|
|
3541
|
+
const lat = finite(raw?.lat);
|
|
3542
|
+
const lng = finite(raw?.lng);
|
|
3543
|
+
if (lat == null || lng == null) return null;
|
|
3544
|
+
if (lat === 0 && lng === 0) return null;
|
|
3545
|
+
if (Math.abs(lat) > 90 || Math.abs(lng) > 180) return null;
|
|
3546
|
+
return { lat, lng };
|
|
3547
|
+
}
|
|
3548
|
+
function coordinateDecimals(value) {
|
|
3549
|
+
if (!Number.isFinite(value)) return 0;
|
|
3550
|
+
const text = Math.abs(value).toString();
|
|
3551
|
+
if (text.includes("e")) {
|
|
3552
|
+
const fixed = Math.abs(value).toFixed(12).replace(/0+$/, "");
|
|
3553
|
+
const dot2 = fixed.indexOf(".");
|
|
3554
|
+
return dot2 === -1 ? 0 : fixed.length - dot2 - 1;
|
|
3555
|
+
}
|
|
3556
|
+
const dot = text.indexOf(".");
|
|
3557
|
+
return dot === -1 ? 0 : text.length - dot - 1;
|
|
3558
|
+
}
|
|
3559
|
+
function roundTo(value, decimals) {
|
|
3560
|
+
const factor = 10 ** decimals;
|
|
3561
|
+
return Math.round(value * factor) / factor;
|
|
3562
|
+
}
|
|
3563
|
+
function coarsenCoordinates(coordinates, maxDecimals) {
|
|
3564
|
+
if (maxDecimals == null || !Number.isFinite(maxDecimals)) return coordinates;
|
|
3565
|
+
const limit = Math.max(0, Math.floor(maxDecimals));
|
|
3566
|
+
return {
|
|
3567
|
+
lat: coordinateDecimals(coordinates.lat) > limit ? roundTo(coordinates.lat, limit) : coordinates.lat,
|
|
3568
|
+
lng: coordinateDecimals(coordinates.lng) > limit ? roundTo(coordinates.lng, limit) : coordinates.lng
|
|
3569
|
+
};
|
|
3570
|
+
}
|
|
3571
|
+
function maxZoomForCoordinates(coordinates) {
|
|
3572
|
+
const decimals = Math.min(
|
|
3573
|
+
coordinateDecimals(coordinates.lat),
|
|
3574
|
+
coordinateDecimals(coordinates.lng)
|
|
3575
|
+
);
|
|
3576
|
+
if (decimals >= 4) return 21;
|
|
3577
|
+
if (decimals === 3) return 16;
|
|
3578
|
+
if (decimals === 2) return 13;
|
|
3579
|
+
return 11;
|
|
3580
|
+
}
|
|
3581
|
+
function clampInt(value, fallback, min, max) {
|
|
3582
|
+
if (value == null || !Number.isFinite(value)) return fallback;
|
|
3583
|
+
return Math.min(max, Math.max(min, Math.round(value)));
|
|
3584
|
+
}
|
|
3585
|
+
function normalizeMapsBaseUrl(baseUrl) {
|
|
3586
|
+
const raw = (baseUrl ?? "").trim();
|
|
3587
|
+
if (!raw) return DEFAULT_MAPS_BASE_URL;
|
|
3588
|
+
return raw.replace(/\/+$/, "") || DEFAULT_MAPS_BASE_URL;
|
|
3589
|
+
}
|
|
3590
|
+
function siteTag(options) {
|
|
3591
|
+
const value = options?.siteId?.trim();
|
|
3592
|
+
return value ? value : null;
|
|
3593
|
+
}
|
|
3594
|
+
function mapsUrl(path, params, options) {
|
|
3595
|
+
const url = new URL(path, `${normalizeMapsBaseUrl(options?.mapsBaseUrl)}/`);
|
|
3596
|
+
for (const [key, value] of Object.entries(params)) {
|
|
3597
|
+
if (value === void 0 || value === "") continue;
|
|
3598
|
+
url.searchParams.set(key, String(value));
|
|
3599
|
+
}
|
|
3600
|
+
const site = siteTag(options);
|
|
3601
|
+
if (site) url.searchParams.set("site", site);
|
|
3602
|
+
return url.toString();
|
|
3603
|
+
}
|
|
3604
|
+
function resolveFetch(options) {
|
|
3605
|
+
const custom = options?.fetch;
|
|
3606
|
+
if (custom) return custom;
|
|
3607
|
+
const global = globalThis.fetch;
|
|
3608
|
+
if (!global) {
|
|
3609
|
+
throw new TypeError(
|
|
3610
|
+
"Garagem SDK: no fetch available. Pass `fetch` in the options."
|
|
3611
|
+
);
|
|
3612
|
+
}
|
|
3613
|
+
return global;
|
|
3614
|
+
}
|
|
3615
|
+
async function mapsFetchJson(url, options, init) {
|
|
3616
|
+
const headers = new Headers(init?.headers);
|
|
3617
|
+
headers.set("accept", "application/json");
|
|
3618
|
+
const site = siteTag(options);
|
|
3619
|
+
if (site) headers.set(MAPS_SITE_HEADER, site);
|
|
3620
|
+
try {
|
|
3621
|
+
const response = await resolveFetch(options)(url, { ...init, headers });
|
|
3622
|
+
if (!response.ok) return null;
|
|
3623
|
+
return await response.json();
|
|
3624
|
+
} catch {
|
|
3625
|
+
return null;
|
|
3626
|
+
}
|
|
3627
|
+
}
|
|
3628
|
+
function listingStaticMapUrl(listing, options = {}) {
|
|
3629
|
+
const raw = listingCoordinates(listing);
|
|
3630
|
+
if (!raw) return null;
|
|
3631
|
+
const coordinates = coarsenCoordinates(raw, options.maxDecimals);
|
|
3632
|
+
const zoomCeiling = maxZoomForCoordinates(coordinates);
|
|
3633
|
+
const zoom = Math.min(zoomCeiling, clampInt(options.zoom, 15, 1, 21));
|
|
3634
|
+
const markerColor = options.markerColor ?? "red";
|
|
3635
|
+
return mapsUrl(
|
|
3636
|
+
"/v1/static-map",
|
|
3637
|
+
{
|
|
3638
|
+
lat: coordinates.lat,
|
|
3639
|
+
lng: coordinates.lng,
|
|
3640
|
+
zoom,
|
|
3641
|
+
width: clampInt(options.width, 600, 1, MAPS_MAX_IMAGE_EDGE),
|
|
3642
|
+
height: clampInt(options.height, 300, 1, MAPS_MAX_IMAGE_EDGE),
|
|
3643
|
+
scale: options.scale === 1 ? 1 : 2,
|
|
3644
|
+
maptype: options.style,
|
|
3645
|
+
markerColor: markerColor !== "red" ? markerColor : void 0,
|
|
3646
|
+
hidePoi: options.hidePoi ? "1" : void 0
|
|
3647
|
+
},
|
|
3648
|
+
options
|
|
3649
|
+
);
|
|
3650
|
+
}
|
|
3651
|
+
function listingStreetViewUrl(listing, options = {}) {
|
|
3652
|
+
const raw = listingCoordinates(listing);
|
|
3653
|
+
if (!raw) return null;
|
|
3654
|
+
const coordinates = coarsenCoordinates(raw, options.maxDecimals);
|
|
3655
|
+
const width = clampInt(options.width, 640, 1, MAPS_MAX_IMAGE_EDGE);
|
|
3656
|
+
const height = clampInt(options.height, 640, 1, MAPS_MAX_IMAGE_EDGE);
|
|
3657
|
+
return mapsUrl(
|
|
3658
|
+
"/v1/street-view",
|
|
3659
|
+
{
|
|
3660
|
+
lat: coordinates.lat,
|
|
3661
|
+
lng: coordinates.lng,
|
|
3662
|
+
size: `${width}x${height}`,
|
|
3663
|
+
fov: clampInt(options.fov, 90, 10, 120),
|
|
3664
|
+
heading: clampInt(options.heading, 0, 0, 360),
|
|
3665
|
+
pitch: clampInt(options.pitch, 10, -90, 90)
|
|
3666
|
+
},
|
|
3667
|
+
options
|
|
3668
|
+
);
|
|
3669
|
+
}
|
|
3670
|
+
function listingStreetViewMetadataUrl(listing, options = {}) {
|
|
3671
|
+
const raw = listingCoordinates(listing);
|
|
3672
|
+
if (!raw) return null;
|
|
3673
|
+
const coordinates = coarsenCoordinates(raw, options.maxDecimals);
|
|
3674
|
+
return mapsUrl(
|
|
3675
|
+
"/v1/street-view/metadata",
|
|
3676
|
+
{ lat: coordinates.lat, lng: coordinates.lng },
|
|
3677
|
+
options
|
|
3678
|
+
);
|
|
3679
|
+
}
|
|
3680
|
+
async function listingStreetViewAvailable(listing, options = {}) {
|
|
3681
|
+
const url = listingStreetViewMetadataUrl(listing, options);
|
|
3682
|
+
if (!url) {
|
|
3683
|
+
return { available: false, status: "NO_COORDINATES", url: "" };
|
|
3684
|
+
}
|
|
3685
|
+
const data = await mapsFetchJson(url, options);
|
|
3686
|
+
const status = typeof data?.status === "string" ? data.status : "ERROR";
|
|
3687
|
+
const result = {
|
|
3688
|
+
available: status === "OK",
|
|
3689
|
+
status,
|
|
3690
|
+
url
|
|
3691
|
+
};
|
|
3692
|
+
if (typeof data?.pano_id === "string") result.panoId = data.pano_id;
|
|
3693
|
+
if (typeof data?.date === "string") result.date = data.date;
|
|
3694
|
+
return result;
|
|
3695
|
+
}
|
|
3696
|
+
function boundaryCitySlug(city) {
|
|
3697
|
+
return city.normalize("NFD").replace(/[̀-ͯ]/g, "").toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "");
|
|
3698
|
+
}
|
|
3699
|
+
function boundaryLayerId(city) {
|
|
3700
|
+
const slug = boundaryCitySlug(city);
|
|
3701
|
+
return slug.endsWith("_boundaries") ? slug : `${slug}_boundaries`;
|
|
3702
|
+
}
|
|
3703
|
+
function boundaryLayerUrl(city, options = {}) {
|
|
3704
|
+
const base = normalizeMapsBaseUrl(options.mapsBaseUrl);
|
|
3705
|
+
const id = boundaryLayerId(city);
|
|
3706
|
+
const slug = id.replace(/_boundaries$/, "");
|
|
3707
|
+
switch (options.kind ?? "tilejson") {
|
|
3708
|
+
case "layer":
|
|
3709
|
+
return `${base}/v1/layers/${id}`;
|
|
3710
|
+
case "tiles":
|
|
3711
|
+
return `${base}/martin/${id}/{z}/{x}/{y}`;
|
|
3712
|
+
case "geojson":
|
|
3713
|
+
return `${base}/api/boundaries/${slug}`;
|
|
3714
|
+
default:
|
|
3715
|
+
return `${base}/martin/${id}`;
|
|
3716
|
+
}
|
|
3717
|
+
}
|
|
3718
|
+
function neighborhoodBoundaryUrl(city, neighborhood, options = {}) {
|
|
3719
|
+
const base = normalizeMapsBaseUrl(options.mapsBaseUrl);
|
|
3720
|
+
const slug = boundaryLayerId(city).replace(/_boundaries$/, "");
|
|
3721
|
+
const url = new URL(
|
|
3722
|
+
`${base}/api/boundaries/${slug}/${encodeURIComponent(neighborhood.trim())}`
|
|
3723
|
+
);
|
|
3724
|
+
if (options.source && options.source !== "listaaberta") {
|
|
3725
|
+
url.searchParams.set("source", options.source);
|
|
3726
|
+
}
|
|
3727
|
+
return url.toString();
|
|
3728
|
+
}
|
|
3729
|
+
function asNumber(value, fallback) {
|
|
3730
|
+
return typeof value === "number" && Number.isFinite(value) ? value : fallback;
|
|
3731
|
+
}
|
|
3732
|
+
async function getBoundaryLayer(city, options = {}) {
|
|
3733
|
+
const data = await mapsFetchJson(
|
|
3734
|
+
boundaryLayerUrl(city, { ...options, kind: "layer" }),
|
|
3735
|
+
options
|
|
3736
|
+
);
|
|
3737
|
+
const layer = data?.layer;
|
|
3738
|
+
if (!data?.ok || !layer || typeof layer.id !== "string") return null;
|
|
3739
|
+
const rawSourceLayers = Array.isArray(layer.source_layers) ? layer.source_layers : [];
|
|
3740
|
+
return {
|
|
3741
|
+
id: layer.id,
|
|
3742
|
+
name: typeof layer.name === "string" ? layer.name : layer.id,
|
|
3743
|
+
description: typeof layer.description === "string" ? layer.description : "",
|
|
3744
|
+
city: typeof layer.city === "string" ? layer.city : void 0,
|
|
3745
|
+
tiles: typeof layer.tiles === "string" ? layer.tiles : "",
|
|
3746
|
+
tilejson: typeof layer.tilejson === "string" ? layer.tilejson : "",
|
|
3747
|
+
geojson: typeof layer.geojson === "string" ? layer.geojson : void 0,
|
|
3748
|
+
sourceLayers: rawSourceLayers.filter(
|
|
3749
|
+
(entry) => !!entry && typeof entry === "object"
|
|
3750
|
+
).map((entry) => ({
|
|
3751
|
+
id: String(entry.id ?? ""),
|
|
3752
|
+
label: String(entry.label ?? entry.id ?? ""),
|
|
3753
|
+
minzoom: typeof entry.minzoom === "number" ? entry.minzoom : void 0,
|
|
3754
|
+
maxzoom: typeof entry.maxzoom === "number" ? entry.maxzoom : void 0
|
|
3755
|
+
})),
|
|
3756
|
+
minzoom: asNumber(layer.minzoom, 0),
|
|
3757
|
+
maxzoom: asNumber(layer.maxzoom, 14),
|
|
3758
|
+
attribution: typeof layer.attribution === "string" ? layer.attribution : void 0,
|
|
3759
|
+
available: layer.available !== false
|
|
3760
|
+
};
|
|
3761
|
+
}
|
|
3762
|
+
function isFeature(value) {
|
|
3763
|
+
return !!value && typeof value === "object" && value.type === "Feature";
|
|
3764
|
+
}
|
|
3765
|
+
async function neighborhoodBoundaryLayer(city, neighborhood, options = {}) {
|
|
3766
|
+
const url = neighborhoodBoundaryUrl(city, neighborhood, options);
|
|
3767
|
+
const slug = boundaryLayerId(city).replace(/_boundaries$/, "");
|
|
3768
|
+
const result = {
|
|
3769
|
+
city: slug,
|
|
3770
|
+
neighborhood: neighborhood.trim(),
|
|
3771
|
+
feature: null,
|
|
3772
|
+
candidates: [],
|
|
3773
|
+
url,
|
|
3774
|
+
tiles: boundaryLayerUrl(city, { ...options, kind: "tiles" })
|
|
3775
|
+
};
|
|
3776
|
+
if (!result.neighborhood) return result;
|
|
3777
|
+
const data = await mapsFetchJson(
|
|
3778
|
+
url,
|
|
3779
|
+
options
|
|
3780
|
+
);
|
|
3781
|
+
if (!data) return result;
|
|
3782
|
+
if (isFeature(data)) {
|
|
3783
|
+
result.feature = data;
|
|
3784
|
+
result.candidates = [data];
|
|
3785
|
+
return result;
|
|
3786
|
+
}
|
|
3787
|
+
const features = Array.isArray(data.features) ? data.features.filter(isFeature) : [];
|
|
3788
|
+
result.candidates = features;
|
|
3789
|
+
const wanted = result.neighborhood.toLocaleLowerCase("pt-BR");
|
|
3790
|
+
result.feature = features.find(
|
|
3791
|
+
(feature) => typeof feature.properties?.name === "string" && feature.properties.name.toLocaleLowerCase("pt-BR") === wanted
|
|
3792
|
+
) ?? (features.length === 1 ? features[0] : null);
|
|
3793
|
+
return result;
|
|
3794
|
+
}
|
|
3795
|
+
function createTravelTimeCache(options = {}) {
|
|
3796
|
+
const maxEntries = Math.max(1, Math.floor(options.maxEntries ?? 200));
|
|
3797
|
+
const ttlMs = Math.max(0, options.ttlMs ?? 15 * 60 * 1e3);
|
|
3798
|
+
const entries = /* @__PURE__ */ new Map();
|
|
3799
|
+
return {
|
|
3800
|
+
get(key) {
|
|
3801
|
+
const hit = entries.get(key);
|
|
3802
|
+
if (!hit) return void 0;
|
|
3803
|
+
if (hit.expiresAt <= Date.now()) {
|
|
3804
|
+
entries.delete(key);
|
|
3805
|
+
return void 0;
|
|
3806
|
+
}
|
|
3807
|
+
entries.delete(key);
|
|
3808
|
+
entries.set(key, hit);
|
|
3809
|
+
return hit.value;
|
|
3810
|
+
},
|
|
3811
|
+
set(key, value) {
|
|
3812
|
+
entries.delete(key);
|
|
3813
|
+
entries.set(key, { value, expiresAt: Date.now() + ttlMs });
|
|
3814
|
+
while (entries.size > maxEntries) {
|
|
3815
|
+
const oldest = entries.keys().next().value;
|
|
3816
|
+
if (oldest === void 0) break;
|
|
3817
|
+
entries.delete(oldest);
|
|
3818
|
+
}
|
|
3819
|
+
},
|
|
3820
|
+
clear() {
|
|
3821
|
+
entries.clear();
|
|
3822
|
+
},
|
|
3823
|
+
get size() {
|
|
3824
|
+
return entries.size;
|
|
3825
|
+
}
|
|
3826
|
+
};
|
|
3827
|
+
}
|
|
3828
|
+
var defaultTravelTimeCache = createTravelTimeCache();
|
|
3829
|
+
function clearTravelTimeCache() {
|
|
3830
|
+
defaultTravelTimeCache.clear();
|
|
3831
|
+
}
|
|
3832
|
+
function travelTimeCacheKey(origin, destination, mode) {
|
|
3833
|
+
return `${origin.lat},${origin.lng}|${destination.lat},${destination.lng}|${mode}`;
|
|
3834
|
+
}
|
|
3835
|
+
function travelTimeQueryCacheKey(origin, query, mode) {
|
|
3836
|
+
return `${origin.lat},${origin.lng}|q:${query}|${mode}`;
|
|
3837
|
+
}
|
|
3838
|
+
function trimmedDestinationQuery(destination) {
|
|
3839
|
+
if (typeof destination !== "string") return null;
|
|
3840
|
+
const query = destination.trim();
|
|
3841
|
+
return query ? query : null;
|
|
3842
|
+
}
|
|
3843
|
+
function recallTravelTime(cache, key) {
|
|
3844
|
+
if (!cache) return null;
|
|
3845
|
+
const hit = cache.get(key);
|
|
3846
|
+
return hit ? { ...hit, cached: true } : null;
|
|
3847
|
+
}
|
|
3848
|
+
function rememberTravelTime(cache, keys, value) {
|
|
3849
|
+
if (!cache) return;
|
|
3850
|
+
for (const key of keys) cache.set(key, value);
|
|
3851
|
+
}
|
|
3852
|
+
function normalizeMode(mode) {
|
|
3853
|
+
return mode && TRAVEL_MODES.has(mode) ? mode : "driving";
|
|
3854
|
+
}
|
|
3855
|
+
async function resolveTravelDestination(destination, options = {}) {
|
|
3856
|
+
if (typeof destination !== "string") {
|
|
3857
|
+
const lat2 = finite(destination?.lat);
|
|
3858
|
+
const lng2 = finite(destination?.lng);
|
|
3859
|
+
return lat2 == null || lng2 == null ? null : { lat: lat2, lng: lng2 };
|
|
3860
|
+
}
|
|
3861
|
+
const query = destination.trim();
|
|
3862
|
+
if (!query) return null;
|
|
3863
|
+
const data = await mapsFetchJson(
|
|
3864
|
+
mapsUrl("/v1/geocode", { q: query }, options),
|
|
3865
|
+
options
|
|
3866
|
+
);
|
|
3867
|
+
const lat = finite(data?.latitude);
|
|
3868
|
+
const lng = finite(data?.longitude);
|
|
3869
|
+
if (!data?.ok || lat == null || lng == null) return null;
|
|
3870
|
+
return { lat, lng };
|
|
3871
|
+
}
|
|
3872
|
+
function minutesFromSeconds(seconds) {
|
|
3873
|
+
return Math.max(1, Math.round(seconds / 60));
|
|
3874
|
+
}
|
|
3875
|
+
async function travelTimeFromListing(listing, destination, options = {}) {
|
|
3876
|
+
const raw = listingCoordinates(listing);
|
|
3877
|
+
if (!raw) return null;
|
|
3878
|
+
const origin = coarsenCoordinates(raw, options.maxDecimals);
|
|
3879
|
+
const mode = normalizeMode(options.mode);
|
|
3880
|
+
const cache = options.cache === void 0 ? defaultTravelTimeCache : options.cache;
|
|
3881
|
+
const query = trimmedDestinationQuery(destination);
|
|
3882
|
+
if (typeof destination === "string" && !query) return null;
|
|
3883
|
+
if (query) {
|
|
3884
|
+
const queryHit = recallTravelTime(
|
|
3885
|
+
cache,
|
|
3886
|
+
travelTimeQueryCacheKey(origin, query, mode)
|
|
3887
|
+
);
|
|
3888
|
+
if (queryHit) return queryHit;
|
|
3889
|
+
}
|
|
3890
|
+
const target = await resolveTravelDestination(query ?? destination, options);
|
|
3891
|
+
if (!target) return null;
|
|
3892
|
+
const coordKey = travelTimeCacheKey(origin, target, mode);
|
|
3893
|
+
const stored = cache?.get(coordKey);
|
|
3894
|
+
if (stored) {
|
|
3895
|
+
if (query) {
|
|
3896
|
+
rememberTravelTime(
|
|
3897
|
+
cache,
|
|
3898
|
+
[travelTimeQueryCacheKey(origin, query, mode)],
|
|
3899
|
+
stored
|
|
3900
|
+
);
|
|
3901
|
+
}
|
|
3902
|
+
return { ...stored, cached: true };
|
|
3903
|
+
}
|
|
3904
|
+
const data = await mapsFetchJson(
|
|
3905
|
+
mapsUrl(
|
|
3906
|
+
"/v1/directions",
|
|
3907
|
+
{
|
|
3908
|
+
origin: `${origin.lat},${origin.lng}`,
|
|
3909
|
+
destination: `${target.lat},${target.lng}`,
|
|
3910
|
+
mode
|
|
3911
|
+
},
|
|
3912
|
+
options
|
|
3913
|
+
),
|
|
3914
|
+
options
|
|
3915
|
+
);
|
|
3916
|
+
const seconds = finite(data?.route?.totalTravelTime);
|
|
3917
|
+
const meters = finite(data?.route?.totalDistance);
|
|
3918
|
+
if (!data?.ok || seconds == null || meters == null) return null;
|
|
3919
|
+
const result = {
|
|
3920
|
+
minutes: minutesFromSeconds(seconds),
|
|
3921
|
+
seconds,
|
|
3922
|
+
distanceMeters: meters,
|
|
3923
|
+
distanceKm: Math.round(meters / 100) / 10,
|
|
3924
|
+
mode,
|
|
3925
|
+
origin,
|
|
3926
|
+
destination: target,
|
|
3927
|
+
cached: false
|
|
3928
|
+
};
|
|
3929
|
+
const keys = query ? [coordKey, travelTimeQueryCacheKey(origin, query, mode)] : [coordKey];
|
|
3930
|
+
rememberTravelTime(cache, keys, result);
|
|
3931
|
+
return result;
|
|
3932
|
+
}
|
|
3933
|
+
async function travelTimesFromListing(listing, destinations, options = {}) {
|
|
3934
|
+
const raw = listingCoordinates(listing);
|
|
3935
|
+
if (!raw) return null;
|
|
3936
|
+
const origin = coarsenCoordinates(raw, options.maxDecimals);
|
|
3937
|
+
const targets = destinations.map((destination) => {
|
|
3938
|
+
const lat = finite(destination?.lat);
|
|
3939
|
+
const lng = finite(destination?.lng);
|
|
3940
|
+
return lat == null || lng == null ? null : { lat, lng };
|
|
3941
|
+
}).filter((item) => item !== null);
|
|
3942
|
+
if (targets.length === 0) return [];
|
|
3943
|
+
const data = await mapsFetchJson(
|
|
3944
|
+
mapsUrl("/v1/route-matrix", {}, options),
|
|
3945
|
+
options,
|
|
3946
|
+
{
|
|
3947
|
+
method: "POST",
|
|
3948
|
+
headers: { "content-type": "application/json" },
|
|
3949
|
+
body: JSON.stringify({ origin, destinations: targets })
|
|
3950
|
+
}
|
|
3951
|
+
);
|
|
3952
|
+
if (!data?.ok || !Array.isArray(data.durations)) return null;
|
|
3953
|
+
return targets.map((destination, index) => {
|
|
3954
|
+
const seconds = finite(
|
|
3955
|
+
data.durations && data.durations[index]
|
|
3956
|
+
);
|
|
3957
|
+
if (seconds == null) return null;
|
|
3958
|
+
return { minutes: minutesFromSeconds(seconds), seconds, destination };
|
|
3959
|
+
});
|
|
3960
|
+
}
|
|
3961
|
+
|
|
3962
|
+
// src/map-search.ts
|
|
3963
|
+
var MAP_SEARCH_MAX_PAGE_SIZE = 100;
|
|
3964
|
+
var MAP_SEARCH_DEFAULT_PAGE_SIZE = 100;
|
|
3965
|
+
var MAP_SEARCH_MAX_PAGE = 1e4;
|
|
3966
|
+
var MAP_VIEWPORT_DEBOUNCE_MS = 400;
|
|
3967
|
+
var MAP_POLYGON_MAX_VERTICES = 64;
|
|
3968
|
+
function capMapPageSize(value) {
|
|
3969
|
+
if (value == null || !Number.isFinite(value) || value <= 0) {
|
|
3970
|
+
return MAP_SEARCH_DEFAULT_PAGE_SIZE;
|
|
3971
|
+
}
|
|
3972
|
+
return Math.min(MAP_SEARCH_MAX_PAGE_SIZE, Math.floor(value));
|
|
3973
|
+
}
|
|
3974
|
+
function capMapPage(value) {
|
|
3975
|
+
if (value == null || !Number.isFinite(value) || value <= 1) return 1;
|
|
3976
|
+
return Math.min(MAP_SEARCH_MAX_PAGE, Math.floor(value));
|
|
3977
|
+
}
|
|
3978
|
+
function finitePair(lat, lng) {
|
|
3979
|
+
if (typeof lat !== "number" || typeof lng !== "number") return null;
|
|
3980
|
+
if (!Number.isFinite(lat) || !Number.isFinite(lng)) return null;
|
|
3981
|
+
if (lat < -90 || lat > 90 || lng < -180 || lng > 180) return null;
|
|
3982
|
+
return [lat, lng];
|
|
3983
|
+
}
|
|
3984
|
+
function isMapBounds(bounds) {
|
|
3985
|
+
if (!bounds) return false;
|
|
3986
|
+
const north = finitePair(bounds.north, bounds.east);
|
|
3987
|
+
const south = finitePair(bounds.south, bounds.west);
|
|
3988
|
+
if (!north || !south) return false;
|
|
3989
|
+
return bounds.north > bounds.south && bounds.east > bounds.west;
|
|
3990
|
+
}
|
|
3991
|
+
function isMapPolygon(polygon) {
|
|
3992
|
+
if (!Array.isArray(polygon)) return false;
|
|
3993
|
+
if (polygon.length < 3 || polygon.length > MAP_POLYGON_MAX_VERTICES + 1) {
|
|
3994
|
+
return false;
|
|
3995
|
+
}
|
|
3996
|
+
let unique = 0;
|
|
3997
|
+
let prev = null;
|
|
3998
|
+
for (const point of polygon) {
|
|
3999
|
+
if (!Array.isArray(point)) return false;
|
|
4000
|
+
const pair = finitePair(point[0], point[1]);
|
|
4001
|
+
if (!pair) return false;
|
|
4002
|
+
if (prev && prev[0] === pair[0] && prev[1] === pair[1]) continue;
|
|
4003
|
+
prev = pair;
|
|
4004
|
+
unique += 1;
|
|
4005
|
+
}
|
|
4006
|
+
if (unique >= 2 && polygon.length >= 2) {
|
|
4007
|
+
const first = finitePair(polygon[0]?.[0], polygon[0]?.[1]);
|
|
4008
|
+
const last = finitePair(
|
|
4009
|
+
polygon[polygon.length - 1]?.[0],
|
|
4010
|
+
polygon[polygon.length - 1]?.[1]
|
|
4011
|
+
);
|
|
4012
|
+
if (first && last && first[0] === last[0] && first[1] === last[1] && unique > 1) {
|
|
4013
|
+
unique -= 1;
|
|
4014
|
+
}
|
|
4015
|
+
}
|
|
4016
|
+
return unique >= 3 && unique <= MAP_POLYGON_MAX_VERTICES;
|
|
4017
|
+
}
|
|
4018
|
+
function mapSearchPins(listings) {
|
|
4019
|
+
const pins = [];
|
|
4020
|
+
for (const listing of listings) {
|
|
4021
|
+
const coords = listingCoordinates(listing);
|
|
4022
|
+
if (!coords || !listing.id) continue;
|
|
4023
|
+
const src = listing.coverImage?.src;
|
|
4024
|
+
pins.push({
|
|
4025
|
+
id: listing.id,
|
|
4026
|
+
lat: coords.lat,
|
|
4027
|
+
lng: coords.lng,
|
|
4028
|
+
price: listing.price ?? null,
|
|
4029
|
+
coverImage: src ? src : null
|
|
4030
|
+
});
|
|
4031
|
+
}
|
|
4032
|
+
return pins;
|
|
4033
|
+
}
|
|
4034
|
+
function listingsResult(listings, meta, requestedPageSize) {
|
|
4035
|
+
return {
|
|
4036
|
+
pins: mapSearchPins(listings),
|
|
4037
|
+
cards: listings.map((listing) => toListingCardModel(listing)),
|
|
4038
|
+
listings,
|
|
4039
|
+
page: meta.page ?? 1,
|
|
4040
|
+
pageSize: meta.limit ?? requestedPageSize,
|
|
4041
|
+
total: meta.total ?? listings.length,
|
|
4042
|
+
totalPages: meta.totalPages ?? 0
|
|
4043
|
+
};
|
|
4044
|
+
}
|
|
4045
|
+
function searchParams(area, options) {
|
|
4046
|
+
const params = {
|
|
4047
|
+
page: capMapPage(options.page),
|
|
4048
|
+
limit: capMapPageSize(options.pageSize)
|
|
4049
|
+
};
|
|
4050
|
+
if (options.q !== void 0) params.q = options.q;
|
|
4051
|
+
if (options.sort !== void 0) params.sort = options.sort;
|
|
4052
|
+
if (options.location !== void 0) params.location = options.location;
|
|
4053
|
+
if (options.filters) params.filters = options.filters;
|
|
4054
|
+
if (area.polygon) params.polygon = area.polygon;
|
|
4055
|
+
else if (area.bounds) params.bounds = area.bounds;
|
|
4056
|
+
return params;
|
|
4057
|
+
}
|
|
4058
|
+
async function runMapSearch(siteId, area, options) {
|
|
4059
|
+
const pageSize = capMapPageSize(options.pageSize);
|
|
4060
|
+
const result = await queryListings({
|
|
4061
|
+
siteId,
|
|
4062
|
+
params: searchParams(area, options),
|
|
4063
|
+
baseUrl: options.baseUrl,
|
|
4064
|
+
fetch: options.fetch,
|
|
4065
|
+
signal: options.signal,
|
|
4066
|
+
publishableKey: options.publishableKey,
|
|
4067
|
+
next: options.next
|
|
4068
|
+
});
|
|
4069
|
+
return listingsResult(result.listings ?? [], result, pageSize);
|
|
4070
|
+
}
|
|
4071
|
+
async function searchListingsInBounds(siteId, options) {
|
|
4072
|
+
if (!isMapBounds(options.bounds)) {
|
|
4073
|
+
throw new TypeError(
|
|
4074
|
+
"searchListingsInBounds: bounds must be a finite rectangle with north > south and east > west (no antimeridian)."
|
|
4075
|
+
);
|
|
4076
|
+
}
|
|
4077
|
+
return runMapSearch(siteId, { bounds: options.bounds }, options);
|
|
4078
|
+
}
|
|
4079
|
+
async function searchListingsInPolygon(siteId, options) {
|
|
4080
|
+
if (!isMapPolygon(options.polygon)) {
|
|
4081
|
+
throw new TypeError(
|
|
4082
|
+
`searchListingsInPolygon: polygon must be 3\u2013${MAP_POLYGON_MAX_VERTICES} finite [lat, lng] points.`
|
|
4083
|
+
);
|
|
4084
|
+
}
|
|
4085
|
+
return runMapSearch(siteId, { polygon: options.polygon }, options);
|
|
4086
|
+
}
|
|
4087
|
+
function clampZoom(zoom) {
|
|
4088
|
+
if (!Number.isFinite(zoom)) return 0;
|
|
4089
|
+
return Math.min(22, Math.max(0, zoom));
|
|
4090
|
+
}
|
|
4091
|
+
function mapClusterCellDegrees(zoom) {
|
|
4092
|
+
return 360 / 2 ** clampZoom(zoom) / 4;
|
|
4093
|
+
}
|
|
4094
|
+
function usablePin(pin) {
|
|
4095
|
+
return finitePair(pin.lat, pin.lng) !== null && !(pin.lat === 0 && pin.lng === 0);
|
|
4096
|
+
}
|
|
4097
|
+
function groupPrecision(group) {
|
|
4098
|
+
let min = 12;
|
|
4099
|
+
for (const pin of group) {
|
|
4100
|
+
min = Math.min(
|
|
4101
|
+
min,
|
|
4102
|
+
coordinateDecimals(pin.lat),
|
|
4103
|
+
coordinateDecimals(pin.lng)
|
|
4104
|
+
);
|
|
4105
|
+
}
|
|
4106
|
+
return min;
|
|
4107
|
+
}
|
|
4108
|
+
function multiCluster(key, group) {
|
|
4109
|
+
const lat = group.reduce((sum, pin) => sum + pin.lat, 0) / group.length;
|
|
4110
|
+
const lng = group.reduce((sum, pin) => sum + pin.lng, 0) / group.length;
|
|
4111
|
+
const center = coarsenCoordinates({ lat, lng }, groupPrecision(group));
|
|
4112
|
+
return {
|
|
4113
|
+
id: key,
|
|
4114
|
+
lat: center.lat,
|
|
4115
|
+
lng: center.lng,
|
|
4116
|
+
count: group.length,
|
|
4117
|
+
pinIds: group.map((pin) => pin.id),
|
|
4118
|
+
pin: null
|
|
4119
|
+
};
|
|
4120
|
+
}
|
|
4121
|
+
function singleCluster(pin) {
|
|
4122
|
+
return {
|
|
4123
|
+
id: pin.id,
|
|
4124
|
+
lat: pin.lat,
|
|
4125
|
+
lng: pin.lng,
|
|
4126
|
+
count: 1,
|
|
4127
|
+
pinIds: [pin.id],
|
|
4128
|
+
pin
|
|
4129
|
+
};
|
|
4130
|
+
}
|
|
4131
|
+
function clusterPins(pins, zoom) {
|
|
4132
|
+
if (pins.length === 0) return [];
|
|
4133
|
+
const cell = mapClusterCellDegrees(zoom);
|
|
4134
|
+
const groups = /* @__PURE__ */ new Map();
|
|
4135
|
+
for (const pin of pins) {
|
|
4136
|
+
if (!usablePin(pin)) continue;
|
|
4137
|
+
const key = `${Math.floor(pin.lat / cell)}:${Math.floor(pin.lng / cell)}`;
|
|
4138
|
+
const list = groups.get(key);
|
|
4139
|
+
if (list) list.push(pin);
|
|
4140
|
+
else groups.set(key, [pin]);
|
|
4141
|
+
}
|
|
4142
|
+
const clusters = [];
|
|
4143
|
+
for (const [key, group] of groups) {
|
|
4144
|
+
const only = group[0];
|
|
4145
|
+
clusters.push(
|
|
4146
|
+
group.length === 1 && only ? singleCluster(only) : multiCluster(key, group)
|
|
4147
|
+
);
|
|
4148
|
+
}
|
|
4149
|
+
clusters.sort((a, b) => a.id.localeCompare(b.id));
|
|
4150
|
+
return clusters;
|
|
4151
|
+
}
|
|
4152
|
+
|
|
3450
4153
|
// src/fetchers-photos.ts
|
|
3451
4154
|
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
4155
|
var HIDDEN_SIMILAR_PHOTOS = {
|
|
@@ -3967,12 +4670,19 @@ function applyMatchedPhotoCover(cards, photoResults, options = {}) {
|
|
|
3967
4670
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3968
4671
|
0 && (module.exports = {
|
|
3969
4672
|
AMENITY_FALLBACK_LABELS,
|
|
4673
|
+
DEFAULT_MAPS_BASE_URL,
|
|
3970
4674
|
DEFAULT_PHONE_COUNTRY_CODE,
|
|
3971
4675
|
FORBIDDEN_SEARCH_QUERY_KEYS,
|
|
3972
4676
|
GaragemSdkError,
|
|
3973
4677
|
LISTING_AMENITY_TITLES,
|
|
3974
4678
|
LISTING_DESCRIPTION_CLAMP,
|
|
3975
4679
|
LeadSubmitError,
|
|
4680
|
+
MAPS_MAX_IMAGE_EDGE,
|
|
4681
|
+
MAPS_SITE_HEADER,
|
|
4682
|
+
MAP_POLYGON_MAX_VERTICES,
|
|
4683
|
+
MAP_SEARCH_DEFAULT_PAGE_SIZE,
|
|
4684
|
+
MAP_SEARCH_MAX_PAGE_SIZE,
|
|
4685
|
+
MAP_VIEWPORT_DEBOUNCE_MS,
|
|
3976
4686
|
MATCHED_PHOTO_COVER_MAX_DISTANCE,
|
|
3977
4687
|
MAX_NATIONAL_PHONE_DIGITS,
|
|
3978
4688
|
PHONE_COUNTRIES,
|
|
@@ -3989,18 +4699,28 @@ function applyMatchedPhotoCover(cards, photoResults, options = {}) {
|
|
|
3989
4699
|
VISIT_TIME_ZONE,
|
|
3990
4700
|
applyMatchedPhotoCover,
|
|
3991
4701
|
applyPathFilter,
|
|
4702
|
+
boundaryCitySlug,
|
|
4703
|
+
boundaryLayerId,
|
|
4704
|
+
boundaryLayerUrl,
|
|
3992
4705
|
buildQueryListingsParams,
|
|
3993
4706
|
canonicalizeSearchHref,
|
|
4707
|
+
capMapPage,
|
|
4708
|
+
capMapPageSize,
|
|
3994
4709
|
clearStagedPathFilters,
|
|
4710
|
+
clearTravelTimeCache,
|
|
4711
|
+
clusterPins,
|
|
4712
|
+
coarsenCoordinates,
|
|
3995
4713
|
coerceNpmVersion,
|
|
3996
4714
|
collapseDuplicatedBrazilianMobileNine,
|
|
3997
4715
|
compareSemver,
|
|
3998
4716
|
composeSearchPublicHref,
|
|
3999
4717
|
composeSearchPublicPath,
|
|
4718
|
+
coordinateDecimals,
|
|
4000
4719
|
countFacetChoices,
|
|
4001
4720
|
countOptionLabel,
|
|
4002
4721
|
createClient,
|
|
4003
4722
|
createGaragemClient,
|
|
4723
|
+
createTravelTimeCache,
|
|
4004
4724
|
defaultPhoneCountry,
|
|
4005
4725
|
displayPathLocation,
|
|
4006
4726
|
expandVisitSchedule,
|
|
@@ -4010,6 +4730,7 @@ function applyMatchedPhotoCover(cards, photoResults, options = {}) {
|
|
|
4010
4730
|
formatGroupedInteger,
|
|
4011
4731
|
formatListingPrice,
|
|
4012
4732
|
formatPhoneNational,
|
|
4733
|
+
getBoundaryLayer,
|
|
4013
4734
|
getCmsCollection,
|
|
4014
4735
|
getCmsCollections,
|
|
4015
4736
|
getCmsEntries,
|
|
@@ -4028,6 +4749,8 @@ function applyMatchedPhotoCover(cards, photoResults, options = {}) {
|
|
|
4028
4749
|
hrefForPathFilters,
|
|
4029
4750
|
hrefWithExplicitPage,
|
|
4030
4751
|
isListingDetailPath,
|
|
4752
|
+
isMapBounds,
|
|
4753
|
+
isMapPolygon,
|
|
4031
4754
|
isPhotoSearchOnPin,
|
|
4032
4755
|
isStudioPreviewHost,
|
|
4033
4756
|
isValidPhone,
|
|
@@ -4036,6 +4759,7 @@ function applyMatchedPhotoCover(cards, photoResults, options = {}) {
|
|
|
4036
4759
|
listingAmenityGroups,
|
|
4037
4760
|
listingBreadcrumb,
|
|
4038
4761
|
listingBusinessLabel,
|
|
4762
|
+
listingCoordinates,
|
|
4039
4763
|
listingDescriptionPreview,
|
|
4040
4764
|
listingDetailFieldsModel,
|
|
4041
4765
|
listingDetailModel,
|
|
@@ -4047,12 +4771,23 @@ function applyMatchedPhotoCover(cards, photoResults, options = {}) {
|
|
|
4047
4771
|
listingMediaOverlays,
|
|
4048
4772
|
listingPhotoGroups,
|
|
4049
4773
|
listingPublicPath,
|
|
4774
|
+
listingStaticMapUrl,
|
|
4775
|
+
listingStreetViewAvailable,
|
|
4776
|
+
listingStreetViewMetadataUrl,
|
|
4777
|
+
listingStreetViewUrl,
|
|
4050
4778
|
listingValues,
|
|
4051
4779
|
listingVisualHighlights,
|
|
4780
|
+
mapClusterCellDegrees,
|
|
4781
|
+
mapSearchPins,
|
|
4782
|
+
mapsExportsPublished,
|
|
4052
4783
|
marketExportsAvailableAt,
|
|
4053
4784
|
marketPositionLabel,
|
|
4785
|
+
maxZoomForCoordinates,
|
|
4054
4786
|
mergeAppliedSearchQueryIntoSearch,
|
|
4055
4787
|
nationalPhoneDigits,
|
|
4788
|
+
neighborhoodBoundaryLayer,
|
|
4789
|
+
neighborhoodBoundaryUrl,
|
|
4790
|
+
normalizeMapsBaseUrl,
|
|
4056
4791
|
normalizeVisitDate,
|
|
4057
4792
|
normalizeVisitTime,
|
|
4058
4793
|
paginationPages,
|
|
@@ -4078,10 +4813,13 @@ function applyMatchedPhotoCover(cards, photoResults, options = {}) {
|
|
|
4078
4813
|
requestPriceEstimate,
|
|
4079
4814
|
resolveMatchedCoverPhoto,
|
|
4080
4815
|
resolvePublicSiteId,
|
|
4816
|
+
resolveTravelDestination,
|
|
4081
4817
|
searchChromeModel,
|
|
4082
4818
|
searchHrefUsesLegacyFilterQuery,
|
|
4083
4819
|
searchListingPhotos,
|
|
4084
4820
|
searchListings,
|
|
4821
|
+
searchListingsInBounds,
|
|
4822
|
+
searchListingsInPolygon,
|
|
4085
4823
|
searchResultsHeading,
|
|
4086
4824
|
searchSortOptions,
|
|
4087
4825
|
serializeAppliedSearchQuery,
|
|
@@ -4094,6 +4832,7 @@ function applyMatchedPhotoCover(cards, photoResults, options = {}) {
|
|
|
4094
4832
|
studioLeadInstruction,
|
|
4095
4833
|
studioListingCardInstruction,
|
|
4096
4834
|
studioListingDetailInstruction,
|
|
4835
|
+
studioMapsInstruction,
|
|
4097
4836
|
studioMarketInstruction,
|
|
4098
4837
|
studioPhotoInstruction,
|
|
4099
4838
|
studioPhotoInstructionFor,
|
|
@@ -4108,6 +4847,9 @@ function applyMatchedPhotoCover(cards, photoResults, options = {}) {
|
|
|
4108
4847
|
toE164,
|
|
4109
4848
|
toListingCardModel,
|
|
4110
4849
|
toolbarFilterIds,
|
|
4850
|
+
travelTimeCacheKey,
|
|
4851
|
+
travelTimeFromListing,
|
|
4852
|
+
travelTimesFromListing,
|
|
4111
4853
|
truncateNationalPhoneDigits,
|
|
4112
4854
|
unavailableReactImports,
|
|
4113
4855
|
visibleSearchFilters
|