@garagem-ai/site-sdk 0.9.0 → 0.9.1
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/dist/index.d.mts +22 -12
- package/dist/index.d.ts +22 -12
- package/dist/index.js +26 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +25 -16
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.mts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +4 -4
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +4 -4
- package/dist/react.mjs.map +1 -1
- package/dist/{types-photo-search-D88oevZv.d.mts → types-photo-search-DIoV75SN.d.mts} +1 -1
- package/dist/{types-photo-search-D88oevZv.d.ts → types-photo-search-DIoV75SN.d.ts} +1 -1
- package/package.json +2 -2
- package/src/index.ts +1 -0
- package/src/map-search.ts +9 -5
- package/src/studio-contract.ts +29 -11
|
@@ -1018,7 +1018,7 @@ declare function searchListingsInPolygon(siteId: string, options: MapPolygonSear
|
|
|
1018
1018
|
declare function mapClusterCellDegrees(zoom: number): number;
|
|
1019
1019
|
/**
|
|
1020
1020
|
* Headless grid cluster. A cell with one pin keeps that pin's coordinates.
|
|
1021
|
-
* A group centroid is rounded
|
|
1021
|
+
* A group centroid is rounded to the members' own precision so clustering
|
|
1022
1022
|
* cannot invent extra decimals.
|
|
1023
1023
|
*/
|
|
1024
1024
|
declare function clusterPins(pins: readonly MapPin[], zoom: number): MapPinCluster[];
|
|
@@ -1018,7 +1018,7 @@ declare function searchListingsInPolygon(siteId: string, options: MapPolygonSear
|
|
|
1018
1018
|
declare function mapClusterCellDegrees(zoom: number): number;
|
|
1019
1019
|
/**
|
|
1020
1020
|
* Headless grid cluster. A cell with one pin keeps that pin's coordinates.
|
|
1021
|
-
* A group centroid is rounded
|
|
1021
|
+
* A group centroid is rounded to the members' own precision so clustering
|
|
1022
1022
|
* cannot invent extra decimals.
|
|
1023
1023
|
*/
|
|
1024
1024
|
declare function clusterPins(pins: readonly MapPin[], zoom: number): MapPinCluster[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@garagem-ai/site-sdk",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Typed, runtime-agnostic SDK for building custom real estate sites against the Garagem platform. Drop into any Next.js (or other JS) project to fetch listings, sites and CMS data.",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"@types/react": "19.1.4",
|
|
59
59
|
"eslint": "^9.0.0",
|
|
60
60
|
"jsdom": "^26.1.0",
|
|
61
|
-
"next": "16.4.0
|
|
61
|
+
"next": "16.4.0",
|
|
62
62
|
"react": "19.2.1",
|
|
63
63
|
"react-dom": "19.2.1",
|
|
64
64
|
"tsup": "^8.0.1",
|
package/src/index.ts
CHANGED
package/src/map-search.ts
CHANGED
|
@@ -283,16 +283,20 @@ function usablePin(pin: MapPin): boolean {
|
|
|
283
283
|
);
|
|
284
284
|
}
|
|
285
285
|
|
|
286
|
+
/**
|
|
287
|
+
* The finest precision any member shows. A masked `-23.600` prints as
|
|
288
|
+
* `-23.6`, so the coarsest member would round the centroid kilometres away.
|
|
289
|
+
*/
|
|
286
290
|
function groupPrecision(group: readonly MapPin[]): number {
|
|
287
|
-
let
|
|
291
|
+
let max = 0;
|
|
288
292
|
for (const pin of group) {
|
|
289
|
-
|
|
290
|
-
|
|
293
|
+
max = Math.max(
|
|
294
|
+
max,
|
|
291
295
|
coordinateDecimals(pin.lat),
|
|
292
296
|
coordinateDecimals(pin.lng)
|
|
293
297
|
);
|
|
294
298
|
}
|
|
295
|
-
return
|
|
299
|
+
return max;
|
|
296
300
|
}
|
|
297
301
|
|
|
298
302
|
function multiCluster(key: string, group: MapPin[]): MapPinCluster {
|
|
@@ -322,7 +326,7 @@ function singleCluster(pin: MapPin): MapPinCluster {
|
|
|
322
326
|
|
|
323
327
|
/**
|
|
324
328
|
* Headless grid cluster. A cell with one pin keeps that pin's coordinates.
|
|
325
|
-
* A group centroid is rounded
|
|
329
|
+
* A group centroid is rounded to the members' own precision so clustering
|
|
326
330
|
* cannot invent extra decimals.
|
|
327
331
|
*/
|
|
328
332
|
export function clusterPins(
|
package/src/studio-contract.ts
CHANGED
|
@@ -20,11 +20,13 @@ export const STUDIO_SDK_CONTRACT = {
|
|
|
20
20
|
* this and move that release's names from `optionalReactExports` /
|
|
21
21
|
* `unpublishedSearchExports` / `unpublishedPhoneExports` into the
|
|
22
22
|
* prompt-safe lists. Do not bump here until that tarball is on npm.
|
|
23
|
-
* Phone mask helpers shipped in 0.6.0.
|
|
23
|
+
* Phone mask helpers shipped in 0.6.0. Map search
|
|
24
|
+
* (`useMapSearch`, `searchListingsInBounds`) shipped in 0.9.0 — 0.7.0
|
|
25
|
+
* does not export them. Search filter helpers
|
|
24
26
|
* (`visibleSearchFilters` / `toolbarFilterIds`) shipped in 0.4.12 and
|
|
25
27
|
* remain on this pin.
|
|
26
28
|
*/
|
|
27
|
-
minNpmVersion: "0.
|
|
29
|
+
minNpmVersion: "0.9.0",
|
|
28
30
|
/** Historical: older tarballs inject card CSS when those components mount. */
|
|
29
31
|
selfInjectSince: "0.4.2",
|
|
30
32
|
chromeStrategy: "app-owned" as const,
|
|
@@ -38,6 +40,7 @@ export const STUDIO_SDK_CONTRACT = {
|
|
|
38
40
|
*/
|
|
39
41
|
optionalReactExports: {
|
|
40
42
|
usePublicPhotoSearch: "0.7.0",
|
|
43
|
+
useMapSearch: "0.9.0",
|
|
41
44
|
} as Record<string, string>,
|
|
42
45
|
/**
|
|
43
46
|
* Former `/react` chrome (including card/skeleton inject). Completeness
|
|
@@ -148,14 +151,15 @@ export const STUDIO_SDK_CONTRACT = {
|
|
|
148
151
|
] as const,
|
|
149
152
|
/**
|
|
150
153
|
* maps.fndn.ai helpers (static map, street view, boundaries, travel
|
|
151
|
-
* time) plus friendly map search. They ship in `mapsSince
|
|
152
|
-
* `studioMapsInstruction()`
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
154
|
+
* time) plus friendly map search. They ship in npm 0.9.0 (`mapsSince`).
|
|
155
|
+
* Listing-detail map guidance stays empty: `studioMapsInstruction()`
|
|
156
|
+
* keeps the listing contract for a later task and Studio does not
|
|
157
|
+
* inject it. Map search is `studioMapSearchInstruction()`, and only
|
|
158
|
+
* the site that opted into list-and-map may include that text.
|
|
159
|
+
* `useMapSearch` is a `/react` hook in `optionalReactExports`; the
|
|
160
|
+
* pin sentence does not name it.
|
|
157
161
|
*/
|
|
158
|
-
mapsSince: "0.
|
|
162
|
+
mapsSince: "0.9.0",
|
|
159
163
|
mapsExports: [
|
|
160
164
|
"listingStaticMapUrl",
|
|
161
165
|
"listingStreetViewUrl",
|
|
@@ -327,7 +331,10 @@ export function studioPublishableKeyInstruction(): string {
|
|
|
327
331
|
|
|
328
332
|
export function studioSdkPinInstruction(): string {
|
|
329
333
|
const version = STUDIO_SDK_CONTRACT.minNpmVersion;
|
|
330
|
-
|
|
334
|
+
// Base hooks only. Optional hooks (`useMapSearch`, `usePublicPhotoSearch`)
|
|
335
|
+
// are named by the guidance that owns them, so a list-only site never
|
|
336
|
+
// sees the identifier.
|
|
337
|
+
const names = STUDIO_SDK_CONTRACT.reactExports.join(", ");
|
|
331
338
|
return `In \`package.json\` set \`"@garagem-ai/site-sdk": "${version}"\` (exact). Import only these \`${STUDIO_SDK_PACKAGE}/react\` names: ${names}.`;
|
|
332
339
|
}
|
|
333
340
|
|
|
@@ -407,7 +414,18 @@ export function mapsExportsPublished(
|
|
|
407
414
|
export function studioMapsInstruction(options: { pin?: string } = {}): string {
|
|
408
415
|
if (!mapsExportsPublished(options.pin)) return "";
|
|
409
416
|
const names = STUDIO_SDK_CONTRACT.mapsExports.join(", ");
|
|
410
|
-
return `Maps on listing detail: from \`${STUDIO_SDK_PACKAGE}\` import ${names}. \`listing.location.coordinates\` is already masked by the site's privacy settings (≈100 m by default) — 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}\` — \`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" />\` — 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 (“quanto tempo até…”): \`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 — a destination the visitor typed, or at most one fixed landmark per listing page — 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
|
|
417
|
+
return `Maps on listing detail: from \`${STUDIO_SDK_PACKAGE}\` import ${names}. \`listing.location.coordinates\` is already masked by the site's privacy settings (≈100 m by default) — 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}\` — \`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" />\` — 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 (“quanto tempo até…”): \`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 — a destination the visitor typed, or at most one fixed landmark per listing page — 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.`;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Search-page map mode. Empty below `mapsSince`. Studio injects this only
|
|
422
|
+
* when the site chose list and map. Listing-detail helpers stay out of it.
|
|
423
|
+
*/
|
|
424
|
+
export function studioMapSearchInstruction(
|
|
425
|
+
options: { pin?: string } = {}
|
|
426
|
+
): string {
|
|
427
|
+
if (!mapsExportsPublished(options.pin)) return "";
|
|
428
|
+
return `Map search on \`/imoveis\` (list and map of the same query). The list stays: keep \`usePublicSearch\` for the list, including its sort and pagination. The visitor switches on the same page. \`?modo=mapa\` is the map — read it on first paint. The list is the URL without \`modo\`; do not write \`modo=lista\` or \`modo=grade\`. Choosing the map sets \`modo=mapa\` and drops \`page\`. Choosing the list removes \`modo\`. On the map, hide sort and pagination. Do not add a map pager. The heading stays. Filters apply to both. 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\`, never \`maps.googleapis.com\`, never \`@vis.gl/react-google-maps\`. From \`${STUDIO_SDK_PACKAGE}/react\` import useMapSearch; it fetches, debounces, and clusters. \`const map = useMapSearch({ siteId, baseUrl: GARAGEM_API_BASE, bounds, zoom, q, sort, location, filters, publishableKey })\` with the same q, sort, location, filters, and publishableKey as the list. Pass the map's current zoom on every zoom change, including after a cluster click. Changing zoom recomputes \`map.clusters\` and does not refetch; a bounds change refetches. Do not send filter_by, vector_query, or nl_query from the browser. Request page 1 and pageSize at most 100. Do not walk totalPages. Pins are the masked coordinates the API returned — plot them as returned, never geocode the street. Render \`map.clusters\` with \`google.maps.Marker\` (no map id needed), in two styles that never look alike. A cluster (\`count > 1\`) is a filled circle in the brand color with a white border and the white count as its label. A listing (\`count === 1\` with \`cluster.pin\`) is a white rounded-rectangle chip with a brand-color border, labelled with the short price in the brand color ("R$ 850 mil", "R$ 1,2 mi"; "Consulte" when the price is null or 0): \`icon: { path: "M-34,-12 h68 a6,6 0 0 1 6,6 v12 a6,6 0 0 1 -6,6 h-68 a6,6 0 0 1 -6,-6 v-12 a6,6 0 0 1 6,-6 z", fillColor: "#ffffff", fillOpacity: 1, strokeColor: brand, strokeWeight: 1.5, scale: 1, labelOrigin: new google.maps.Point(0, 0) }\`. Never draw a listing as a dot or a circle, and never without its price. Clicking a listing selects it and shows its card. Clicking a cluster opens its members: \`const members = map.pins.filter((pin) => cluster.pinIds.includes(pin.id))\`, then \`fitBounds\` a LatLngBounds of their coordinates with about 64px padding, so the listings land inside the new view and split into chips. Do not step the zoom around \`cluster.lat\`/\`cluster.lng\`: that point is approximate and the area around it can come back empty. When every member has the same coordinates, or the map is already at zoom 18, do not zoom: open a small list of those listings, each with its price and a link. Layout, top to bottom: query, heading, toolbar, then the view. On desktop the toolbar is one row: featured filters on the left, and the list/map toggle immediately beside the sort select on the right. On a narrow screen the filters stay in one horizontal scroll that does not wrap, and the toggle plus the sort sit together on the row below that scroll. On the map the sort is hidden, so the toggle keeps that place beside where the sort was. In map mode the map fills the remaining viewport height, with a minimum of about 240px. Keep the hook's 400ms viewport debounce. A drawn polygon is not required. Do not add a separate /mapa route, a regions page, or a map on the listing page. Do not call Street View or travel time inside the map search.`;
|
|
411
429
|
}
|
|
412
430
|
|
|
413
431
|
/** True when the pinned tarball ships the market-data helpers. */
|