@garagem-ai/site-sdk 0.4.3 → 0.4.4
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 +16 -16
- package/dist/index.d.mts +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.js +12 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +11 -5
- package/dist/index.mjs.map +1 -1
- package/dist/react.js +1 -1
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +1 -1
- package/dist/react.mjs.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/leads.ts +5 -3
- package/src/react/styles/search-chrome-css.generated.ts +1 -1
- package/src/schedule.ts +15 -5
package/README.md
CHANGED
|
@@ -54,22 +54,22 @@ raw escape hatch when you need full control.
|
|
|
54
54
|
|
|
55
55
|
### Friendly layer (recommended for most use cases)
|
|
56
56
|
|
|
57
|
-
| API
|
|
58
|
-
|
|
|
59
|
-
| `getListings({ siteId, filters?, next? })`
|
|
60
|
-
| `getListing({ siteId, listingId, next? })`
|
|
61
|
-
| `getSimilarListings({ siteId, listingId, limit?, next? })`
|
|
62
|
-
| `getSite({ siteId? \| domain?, next? })`
|
|
63
|
-
| `getCmsCollections({ siteId })`
|
|
64
|
-
| `getCmsCollection({ siteId, slug })`
|
|
65
|
-
| `getCmsEntries({ siteId, collection, limit?, offset? })`
|
|
66
|
-
| `getCmsEntry({ siteId, collection, slug })`
|
|
67
|
-
| `getSearchUi({ siteId, next? })`
|
|
68
|
-
| `getLeadUi({ siteId, next? })`
|
|
69
|
-
| `submitVisitLead({ siteId, listingId, … })`
|
|
70
|
-
| `submitContactLead({ siteId, listingId, … })`
|
|
71
|
-
| `slotsForDate` / `expandVisitSchedule`
|
|
72
|
-
| `resolvePublicSiteId({ host?, fallback? })`
|
|
57
|
+
| API | Description |
|
|
58
|
+
| ------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
59
|
+
| `getListings({ siteId, filters?, next? })` | Paginated listings for a site, with simple `filters` (`city`, `businessType`, `propertyType`, `neighborhood`, `minPrice`, `maxPrice`, `limit`, `offset`) |
|
|
60
|
+
| `getListing({ siteId, listingId, next? })` | Full detail of a single listing |
|
|
61
|
+
| `getSimilarListings({ siteId, listingId, limit?, next? })` | Similar listings carousel (same card shape as `getListings`) |
|
|
62
|
+
| `getSite({ siteId? \| domain?, next? })` | Public site profile (returns `null` if unknown) |
|
|
63
|
+
| `getCmsCollections({ siteId })` | List CMS collections |
|
|
64
|
+
| `getCmsCollection({ siteId, slug })` | One CMS collection schema |
|
|
65
|
+
| `getCmsEntries({ siteId, collection, limit?, offset? })` | Published CMS entries only |
|
|
66
|
+
| `getCmsEntry({ siteId, collection, slug })` | One published CMS entry |
|
|
67
|
+
| `getSearchUi({ siteId, next? })` | Tenant search schema (filters, slugs) |
|
|
68
|
+
| `getLeadUi({ siteId, next? })` | Visit-default lead dialog schema (weekday hours, Sat/Sun flags) |
|
|
69
|
+
| `submitVisitLead({ siteId, listingId, … })` | POST a visit lead (`listing.id` UUID; civil `visitDate` or `Date`/ISO instant normalized in the schedule timezone) |
|
|
70
|
+
| `submitContactLead({ siteId, listingId, … })` | POST a contact lead (no date/time) |
|
|
71
|
+
| `slotsForDate` / `normalizeVisitDate` / `expandVisitSchedule` | Pure schedule helpers (`America/Sao_Paulo`, default Mon–Fri 06:00–22:00) |
|
|
72
|
+
| `resolvePublicSiteId({ host?, fallback? })` | Preview uses `fallback` (`GARAGEM_SITE_ID`); live hosts resolve via `getSite({ domain })` |
|
|
73
73
|
|
|
74
74
|
### Advanced layer (when the friendly one isn't enough)
|
|
75
75
|
|
package/dist/index.d.mts
CHANGED
|
@@ -175,8 +175,10 @@ type VisitSchedule = VisitScheduleConfig & {
|
|
|
175
175
|
declare function expandVisitTimeSlots(hours: VisitHours): HHmm[];
|
|
176
176
|
declare function expandVisitSchedule(config: VisitScheduleConfig): VisitSchedule;
|
|
177
177
|
declare const STUDIO_DEFAULT_VISIT_SCHEDULE: VisitSchedule;
|
|
178
|
+
/** Normalize a civil date or ISO instant to YYYY-MM-DD in `timeZone`. */
|
|
179
|
+
declare function normalizeVisitDate(date: Date | string, timeZone?: string): string | null;
|
|
178
180
|
declare function slotsForDate(schedule: VisitSchedule, date: Date | string, now?: Date): HHmm[];
|
|
179
|
-
declare function isVisitSlotAllowed(schedule: VisitSchedule, visitDate: string, visitTime: HHmm, now?: Date): boolean;
|
|
181
|
+
declare function isVisitSlotAllowed(schedule: VisitSchedule, visitDate: Date | string, visitTime: HHmm, now?: Date): boolean;
|
|
180
182
|
|
|
181
183
|
/**
|
|
182
184
|
* Headless visit / contact leads. Schema via GET /leads/ui; POST always
|
|
@@ -228,7 +230,7 @@ type LeadSubmitBase = LeadContact & {
|
|
|
228
230
|
referrer?: string;
|
|
229
231
|
};
|
|
230
232
|
type VisitLeadInput = LeadSubmitBase & {
|
|
231
|
-
visitDate: string;
|
|
233
|
+
visitDate: Date | string;
|
|
232
234
|
visitTime: HHmm;
|
|
233
235
|
schedule?: VisitSchedule;
|
|
234
236
|
};
|
|
@@ -502,4 +504,4 @@ interface GaragemClient {
|
|
|
502
504
|
*/
|
|
503
505
|
declare function createGaragemClient(options?: CreateGaragemClientOptions): GaragemClient;
|
|
504
506
|
|
|
505
|
-
export { AppliedSearchChange, AppliedSearchQuery, CmsCollection, CmsEntriesResult, CmsEntry, type ContactLeadInput, type CreateGaragemClientOptions, type FetchLike, type GaragemClient, GaragemSdkError, type GetCmsCollectionOptions, type GetCmsCollectionsOptions, type GetCmsEntriesOptions, type GetCmsEntryOptions, type GetLeadUiOptions, type GetListingOptions, type GetListingsOptions, type GetSearchUiOptions, type GetSimilarListingsOptions, type GetSiteOptions, type HHmm, type LeadContact, type LeadField, type LeadFieldId, LeadSubmitError, type LeadSubmitErrorCode, type LeadSubmitResult, type LeadUi, ListingDetail, ListingFilters, ListingsResult, type LocationFilterInput, QueryListingsFilters, type QueryListingsOptions, QueryListingsParams, QueryListingsResult, RequestNextOptions, type ResolvePublicSiteIdOptions, SEARCH_CSS_RECIPE, SEARCH_CSS_VARS, STUDIO_DEFAULT_VISIT_SCHEDULE, STUDIO_SDK_CONTRACT, STUDIO_SDK_PACKAGE, type SearchListingsOptions, SearchListingsParams, SearchListingsResult, SearchPathFilters, SearchUi, SearchUiDictionary, SimilarListingsResult, Site, type StudioSdkContract, VISIT_TIME_ZONE, type VisitHours, type VisitLeadInput, type VisitSchedule, type VisitScheduleConfig, coerceNpmVersion, compareSemver, composeSearchPublicHref, composeSearchPublicPath, createGaragemClient, expandVisitSchedule, expandVisitTimeSlots, formatAreaM2, formatGroupedInteger, formatListingPrice, getCmsCollection, getCmsCollections, getCmsEntries, getCmsEntry, getLeadUi, getListing, getListings, getSearchUi, getSimilarListings, getSite, hasShowcaseLeadsPostUrl, isStudioPreviewHost, isVisitSlotAllowed, listingBusinessLabel, listingLookupKey, listingPublicPath, mergeAppliedSearchQueryIntoSearch, parseAppliedSearchQuery, parseGroupedInteger, parseReactSdkNamedImports, parseSearchPublicPath, pathFiltersToQueryFilters, pathLocationToFilterInput, queryListings, reduceAppliedSearchQuery, resolvePublicSiteId, searchListings, serializeAppliedSearchQuery, slotsForDate, studioChromeInstruction, studioCodegenContractViolations, studioDefaultLeadUi, studioLeadInstruction, studioSdkPinInstruction, submitContactLead, submitVisitLead, unavailableReactImports };
|
|
507
|
+
export { AppliedSearchChange, AppliedSearchQuery, CmsCollection, CmsEntriesResult, CmsEntry, type ContactLeadInput, type CreateGaragemClientOptions, type FetchLike, type GaragemClient, GaragemSdkError, type GetCmsCollectionOptions, type GetCmsCollectionsOptions, type GetCmsEntriesOptions, type GetCmsEntryOptions, type GetLeadUiOptions, type GetListingOptions, type GetListingsOptions, type GetSearchUiOptions, type GetSimilarListingsOptions, type GetSiteOptions, type HHmm, type LeadContact, type LeadField, type LeadFieldId, LeadSubmitError, type LeadSubmitErrorCode, type LeadSubmitResult, type LeadUi, ListingDetail, ListingFilters, ListingsResult, type LocationFilterInput, QueryListingsFilters, type QueryListingsOptions, QueryListingsParams, QueryListingsResult, RequestNextOptions, type ResolvePublicSiteIdOptions, SEARCH_CSS_RECIPE, SEARCH_CSS_VARS, STUDIO_DEFAULT_VISIT_SCHEDULE, STUDIO_SDK_CONTRACT, STUDIO_SDK_PACKAGE, type SearchListingsOptions, SearchListingsParams, SearchListingsResult, SearchPathFilters, SearchUi, SearchUiDictionary, SimilarListingsResult, Site, type StudioSdkContract, VISIT_TIME_ZONE, type VisitHours, type VisitLeadInput, type VisitSchedule, type VisitScheduleConfig, coerceNpmVersion, compareSemver, composeSearchPublicHref, composeSearchPublicPath, createGaragemClient, expandVisitSchedule, expandVisitTimeSlots, formatAreaM2, formatGroupedInteger, formatListingPrice, getCmsCollection, getCmsCollections, getCmsEntries, getCmsEntry, getLeadUi, getListing, getListings, getSearchUi, getSimilarListings, getSite, hasShowcaseLeadsPostUrl, isStudioPreviewHost, isVisitSlotAllowed, listingBusinessLabel, listingLookupKey, listingPublicPath, mergeAppliedSearchQueryIntoSearch, normalizeVisitDate, parseAppliedSearchQuery, parseGroupedInteger, parseReactSdkNamedImports, parseSearchPublicPath, pathFiltersToQueryFilters, pathLocationToFilterInput, queryListings, reduceAppliedSearchQuery, resolvePublicSiteId, searchListings, serializeAppliedSearchQuery, slotsForDate, studioChromeInstruction, studioCodegenContractViolations, studioDefaultLeadUi, studioLeadInstruction, studioSdkPinInstruction, submitContactLead, submitVisitLead, unavailableReactImports };
|
package/dist/index.d.ts
CHANGED
|
@@ -175,8 +175,10 @@ type VisitSchedule = VisitScheduleConfig & {
|
|
|
175
175
|
declare function expandVisitTimeSlots(hours: VisitHours): HHmm[];
|
|
176
176
|
declare function expandVisitSchedule(config: VisitScheduleConfig): VisitSchedule;
|
|
177
177
|
declare const STUDIO_DEFAULT_VISIT_SCHEDULE: VisitSchedule;
|
|
178
|
+
/** Normalize a civil date or ISO instant to YYYY-MM-DD in `timeZone`. */
|
|
179
|
+
declare function normalizeVisitDate(date: Date | string, timeZone?: string): string | null;
|
|
178
180
|
declare function slotsForDate(schedule: VisitSchedule, date: Date | string, now?: Date): HHmm[];
|
|
179
|
-
declare function isVisitSlotAllowed(schedule: VisitSchedule, visitDate: string, visitTime: HHmm, now?: Date): boolean;
|
|
181
|
+
declare function isVisitSlotAllowed(schedule: VisitSchedule, visitDate: Date | string, visitTime: HHmm, now?: Date): boolean;
|
|
180
182
|
|
|
181
183
|
/**
|
|
182
184
|
* Headless visit / contact leads. Schema via GET /leads/ui; POST always
|
|
@@ -228,7 +230,7 @@ type LeadSubmitBase = LeadContact & {
|
|
|
228
230
|
referrer?: string;
|
|
229
231
|
};
|
|
230
232
|
type VisitLeadInput = LeadSubmitBase & {
|
|
231
|
-
visitDate: string;
|
|
233
|
+
visitDate: Date | string;
|
|
232
234
|
visitTime: HHmm;
|
|
233
235
|
schedule?: VisitSchedule;
|
|
234
236
|
};
|
|
@@ -502,4 +504,4 @@ interface GaragemClient {
|
|
|
502
504
|
*/
|
|
503
505
|
declare function createGaragemClient(options?: CreateGaragemClientOptions): GaragemClient;
|
|
504
506
|
|
|
505
|
-
export { AppliedSearchChange, AppliedSearchQuery, CmsCollection, CmsEntriesResult, CmsEntry, type ContactLeadInput, type CreateGaragemClientOptions, type FetchLike, type GaragemClient, GaragemSdkError, type GetCmsCollectionOptions, type GetCmsCollectionsOptions, type GetCmsEntriesOptions, type GetCmsEntryOptions, type GetLeadUiOptions, type GetListingOptions, type GetListingsOptions, type GetSearchUiOptions, type GetSimilarListingsOptions, type GetSiteOptions, type HHmm, type LeadContact, type LeadField, type LeadFieldId, LeadSubmitError, type LeadSubmitErrorCode, type LeadSubmitResult, type LeadUi, ListingDetail, ListingFilters, ListingsResult, type LocationFilterInput, QueryListingsFilters, type QueryListingsOptions, QueryListingsParams, QueryListingsResult, RequestNextOptions, type ResolvePublicSiteIdOptions, SEARCH_CSS_RECIPE, SEARCH_CSS_VARS, STUDIO_DEFAULT_VISIT_SCHEDULE, STUDIO_SDK_CONTRACT, STUDIO_SDK_PACKAGE, type SearchListingsOptions, SearchListingsParams, SearchListingsResult, SearchPathFilters, SearchUi, SearchUiDictionary, SimilarListingsResult, Site, type StudioSdkContract, VISIT_TIME_ZONE, type VisitHours, type VisitLeadInput, type VisitSchedule, type VisitScheduleConfig, coerceNpmVersion, compareSemver, composeSearchPublicHref, composeSearchPublicPath, createGaragemClient, expandVisitSchedule, expandVisitTimeSlots, formatAreaM2, formatGroupedInteger, formatListingPrice, getCmsCollection, getCmsCollections, getCmsEntries, getCmsEntry, getLeadUi, getListing, getListings, getSearchUi, getSimilarListings, getSite, hasShowcaseLeadsPostUrl, isStudioPreviewHost, isVisitSlotAllowed, listingBusinessLabel, listingLookupKey, listingPublicPath, mergeAppliedSearchQueryIntoSearch, parseAppliedSearchQuery, parseGroupedInteger, parseReactSdkNamedImports, parseSearchPublicPath, pathFiltersToQueryFilters, pathLocationToFilterInput, queryListings, reduceAppliedSearchQuery, resolvePublicSiteId, searchListings, serializeAppliedSearchQuery, slotsForDate, studioChromeInstruction, studioCodegenContractViolations, studioDefaultLeadUi, studioLeadInstruction, studioSdkPinInstruction, submitContactLead, submitVisitLead, unavailableReactImports };
|
|
507
|
+
export { AppliedSearchChange, AppliedSearchQuery, CmsCollection, CmsEntriesResult, CmsEntry, type ContactLeadInput, type CreateGaragemClientOptions, type FetchLike, type GaragemClient, GaragemSdkError, type GetCmsCollectionOptions, type GetCmsCollectionsOptions, type GetCmsEntriesOptions, type GetCmsEntryOptions, type GetLeadUiOptions, type GetListingOptions, type GetListingsOptions, type GetSearchUiOptions, type GetSimilarListingsOptions, type GetSiteOptions, type HHmm, type LeadContact, type LeadField, type LeadFieldId, LeadSubmitError, type LeadSubmitErrorCode, type LeadSubmitResult, type LeadUi, ListingDetail, ListingFilters, ListingsResult, type LocationFilterInput, QueryListingsFilters, type QueryListingsOptions, QueryListingsParams, QueryListingsResult, RequestNextOptions, type ResolvePublicSiteIdOptions, SEARCH_CSS_RECIPE, SEARCH_CSS_VARS, STUDIO_DEFAULT_VISIT_SCHEDULE, STUDIO_SDK_CONTRACT, STUDIO_SDK_PACKAGE, type SearchListingsOptions, SearchListingsParams, SearchListingsResult, SearchPathFilters, SearchUi, SearchUiDictionary, SimilarListingsResult, Site, type StudioSdkContract, VISIT_TIME_ZONE, type VisitHours, type VisitLeadInput, type VisitSchedule, type VisitScheduleConfig, coerceNpmVersion, compareSemver, composeSearchPublicHref, composeSearchPublicPath, createGaragemClient, expandVisitSchedule, expandVisitTimeSlots, formatAreaM2, formatGroupedInteger, formatListingPrice, getCmsCollection, getCmsCollections, getCmsEntries, getCmsEntry, getLeadUi, getListing, getListings, getSearchUi, getSimilarListings, getSite, hasShowcaseLeadsPostUrl, isStudioPreviewHost, isVisitSlotAllowed, listingBusinessLabel, listingLookupKey, listingPublicPath, mergeAppliedSearchQueryIntoSearch, normalizeVisitDate, parseAppliedSearchQuery, parseGroupedInteger, parseReactSdkNamedImports, parseSearchPublicPath, pathFiltersToQueryFilters, pathLocationToFilterInput, queryListings, reduceAppliedSearchQuery, resolvePublicSiteId, searchListings, serializeAppliedSearchQuery, slotsForDate, studioChromeInstruction, studioCodegenContractViolations, studioDefaultLeadUi, studioLeadInstruction, studioSdkPinInstruction, submitContactLead, submitVisitLead, unavailableReactImports };
|
package/dist/index.js
CHANGED
|
@@ -70,6 +70,7 @@ __export(src_exports, {
|
|
|
70
70
|
listingLookupKey: () => listingLookupKey,
|
|
71
71
|
listingPublicPath: () => listingPublicPath,
|
|
72
72
|
mergeAppliedSearchQueryIntoSearch: () => mergeAppliedSearchQueryIntoSearch2,
|
|
73
|
+
normalizeVisitDate: () => normalizeVisitDate,
|
|
73
74
|
paginationPages: () => paginationPages,
|
|
74
75
|
parseAppliedSearchQuery: () => parseAppliedSearchQuery2,
|
|
75
76
|
parseGroupedInteger: () => parseGroupedInteger,
|
|
@@ -424,6 +425,7 @@ async function getCmsEntry(options) {
|
|
|
424
425
|
var VISIT_TIME_ZONE = "America/Sao_Paulo";
|
|
425
426
|
var HHMM_RE = /^([01]\d|2[0-3]):([0-5]\d)$/;
|
|
426
427
|
var YMD_RE = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
428
|
+
var ISO_INSTANT_RE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/;
|
|
427
429
|
var WEEKDAY_SHORT = {
|
|
428
430
|
Sun: 0,
|
|
429
431
|
Mon: 1,
|
|
@@ -525,9 +527,12 @@ function parseYmd(value) {
|
|
|
525
527
|
}
|
|
526
528
|
return { year, month, day };
|
|
527
529
|
}
|
|
528
|
-
function
|
|
530
|
+
function normalizeVisitDate(date, timeZone = VISIT_TIME_ZONE) {
|
|
529
531
|
if (typeof date === "string") {
|
|
530
|
-
|
|
532
|
+
if (parseYmd(date)) return date;
|
|
533
|
+
if (!ISO_INSTANT_RE.test(date)) return null;
|
|
534
|
+
const instant = new Date(date);
|
|
535
|
+
return Number.isFinite(instant.getTime()) ? calendarYmd(instant, timeZone) : null;
|
|
531
536
|
}
|
|
532
537
|
if (date instanceof Date && Number.isFinite(date.getTime())) {
|
|
533
538
|
return calendarYmd(date, timeZone);
|
|
@@ -544,7 +549,7 @@ function weekdayOfYmd(ymd, timeZone) {
|
|
|
544
549
|
}
|
|
545
550
|
function slotsForDate(schedule, date, now = /* @__PURE__ */ new Date()) {
|
|
546
551
|
const timeZone = schedule.timeZone;
|
|
547
|
-
const ymd =
|
|
552
|
+
const ymd = normalizeVisitDate(date, timeZone);
|
|
548
553
|
if (!ymd) return [];
|
|
549
554
|
const weekday = weekdayOfYmd(ymd, timeZone);
|
|
550
555
|
if (weekday == null) return [];
|
|
@@ -727,7 +732,8 @@ function leadPostContext(input) {
|
|
|
727
732
|
async function submitVisitLead(input) {
|
|
728
733
|
const prepared = leadPostContext(input);
|
|
729
734
|
const schedule = input.schedule ?? STUDIO_DEFAULT_VISIT_SCHEDULE;
|
|
730
|
-
|
|
735
|
+
const visitDate = normalizeVisitDate(input.visitDate, schedule.timeZone);
|
|
736
|
+
if (!visitDate || !isVisitSlotAllowed(schedule, visitDate, input.visitTime)) {
|
|
731
737
|
throw new LeadSubmitError(
|
|
732
738
|
"Garagem SDK: visitDate/visitTime is outside the published schedule.",
|
|
733
739
|
{ code: "invalid_slot" }
|
|
@@ -743,7 +749,7 @@ async function submitVisitLead(input) {
|
|
|
743
749
|
...prepared.contact,
|
|
744
750
|
propertyId: prepared.listingId,
|
|
745
751
|
listingId: prepared.listingId,
|
|
746
|
-
visitDate
|
|
752
|
+
visitDate,
|
|
747
753
|
visitTime: input.visitTime,
|
|
748
754
|
...prepared.extras
|
|
749
755
|
}
|
|
@@ -1993,6 +1999,7 @@ function createGaragemClient(options = {}) {
|
|
|
1993
1999
|
listingLookupKey,
|
|
1994
2000
|
listingPublicPath,
|
|
1995
2001
|
mergeAppliedSearchQueryIntoSearch,
|
|
2002
|
+
normalizeVisitDate,
|
|
1996
2003
|
paginationPages,
|
|
1997
2004
|
parseAppliedSearchQuery,
|
|
1998
2005
|
parseGroupedInteger,
|