@garagem-ai/site-sdk 0.4.3 → 0.4.5
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 +7 -5
- package/dist/index.d.ts +7 -5
- package/dist/index.js +66 -40
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +65 -40
- package/dist/index.mjs.map +1 -1
- package/dist/react.js +3 -2
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +3 -2
- package/dist/react.mjs.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/internal/url.ts +3 -1
- package/src/leads.ts +38 -8
- package/src/react/styles/search-chrome-css.generated.ts +1 -1
- package/src/schedule.ts +16 -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
|
|
@@ -207,7 +209,7 @@ type LeadUi = {
|
|
|
207
209
|
};
|
|
208
210
|
};
|
|
209
211
|
type GetLeadUiOptions = {
|
|
210
|
-
siteId
|
|
212
|
+
siteId?: string | Promise<string>;
|
|
211
213
|
baseUrl?: string;
|
|
212
214
|
fetch?: FetchLike;
|
|
213
215
|
next?: RequestNextOptions;
|
|
@@ -219,7 +221,7 @@ type LeadContact = {
|
|
|
219
221
|
message?: string;
|
|
220
222
|
};
|
|
221
223
|
type LeadSubmitBase = LeadContact & {
|
|
222
|
-
siteId
|
|
224
|
+
siteId?: string | Promise<string>;
|
|
223
225
|
baseUrl?: string;
|
|
224
226
|
fetch?: FetchLike;
|
|
225
227
|
listingId: string;
|
|
@@ -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
|
|
@@ -207,7 +209,7 @@ type LeadUi = {
|
|
|
207
209
|
};
|
|
208
210
|
};
|
|
209
211
|
type GetLeadUiOptions = {
|
|
210
|
-
siteId
|
|
212
|
+
siteId?: string | Promise<string>;
|
|
211
213
|
baseUrl?: string;
|
|
212
214
|
fetch?: FetchLike;
|
|
213
215
|
next?: RequestNextOptions;
|
|
@@ -219,7 +221,7 @@ type LeadContact = {
|
|
|
219
221
|
message?: string;
|
|
220
222
|
};
|
|
221
223
|
type LeadSubmitBase = LeadContact & {
|
|
222
|
-
siteId
|
|
224
|
+
siteId?: string | Promise<string>;
|
|
223
225
|
baseUrl?: string;
|
|
224
226
|
fetch?: FetchLike;
|
|
225
227
|
listingId: string;
|
|
@@ -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,
|
|
@@ -125,7 +126,8 @@ function normalizeBaseUrl(baseUrl) {
|
|
|
125
126
|
return url.endsWith("/") ? url.slice(0, -1) : url;
|
|
126
127
|
}
|
|
127
128
|
async function coerceSiteId(siteId) {
|
|
128
|
-
const
|
|
129
|
+
const raw = typeof siteId === "function" ? siteId() : siteId;
|
|
130
|
+
const value = await Promise.resolve(raw);
|
|
129
131
|
if (typeof value !== "string" || !value.trim()) {
|
|
130
132
|
throw new TypeError(
|
|
131
133
|
"Garagem SDK: siteId must be a string. Await resolveSiteId(...) before getListings / getSearchUi / queryListings."
|
|
@@ -424,6 +426,7 @@ async function getCmsEntry(options) {
|
|
|
424
426
|
var VISIT_TIME_ZONE = "America/Sao_Paulo";
|
|
425
427
|
var HHMM_RE = /^([01]\d|2[0-3]):([0-5]\d)$/;
|
|
426
428
|
var YMD_RE = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
429
|
+
var ISO_INSTANT_RE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/;
|
|
427
430
|
var WEEKDAY_SHORT = {
|
|
428
431
|
Sun: 0,
|
|
429
432
|
Mon: 1,
|
|
@@ -525,9 +528,12 @@ function parseYmd(value) {
|
|
|
525
528
|
}
|
|
526
529
|
return { year, month, day };
|
|
527
530
|
}
|
|
528
|
-
function
|
|
531
|
+
function normalizeVisitDate(date, timeZone = VISIT_TIME_ZONE) {
|
|
529
532
|
if (typeof date === "string") {
|
|
530
|
-
|
|
533
|
+
if (parseYmd(date)) return date;
|
|
534
|
+
if (!ISO_INSTANT_RE.test(date)) return null;
|
|
535
|
+
const instant = new Date(date);
|
|
536
|
+
return Number.isFinite(instant.getTime()) ? calendarYmd(instant, timeZone) : null;
|
|
531
537
|
}
|
|
532
538
|
if (date instanceof Date && Number.isFinite(date.getTime())) {
|
|
533
539
|
return calendarYmd(date, timeZone);
|
|
@@ -544,10 +550,11 @@ function weekdayOfYmd(ymd, timeZone) {
|
|
|
544
550
|
}
|
|
545
551
|
function slotsForDate(schedule, date, now = /* @__PURE__ */ new Date()) {
|
|
546
552
|
const timeZone = schedule.timeZone;
|
|
547
|
-
const ymd =
|
|
553
|
+
const ymd = normalizeVisitDate(date, timeZone);
|
|
548
554
|
if (!ymd) return [];
|
|
549
555
|
const weekday = weekdayOfYmd(ymd, timeZone);
|
|
550
556
|
if (weekday == null) return [];
|
|
557
|
+
if (schedule.disabledDays.includes(weekday)) return [];
|
|
551
558
|
if (weekday === 0 && !schedule.sunday) return [];
|
|
552
559
|
if (weekday === 6 && !schedule.saturday) return [];
|
|
553
560
|
const base = weekday === 0 || weekday === 6 ? schedule.weekendTimeSlots : schedule.weekdayTimeSlots;
|
|
@@ -565,7 +572,56 @@ function isVisitSlotAllowed(schedule, visitDate, visitTime, now = /* @__PURE__ *
|
|
|
565
572
|
return slotsForDate(schedule, visitDate, now).includes(visitTime);
|
|
566
573
|
}
|
|
567
574
|
|
|
575
|
+
// src/resolve-site-id.ts
|
|
576
|
+
var PREVIEW_HOST_SUFFIXES = [".vusercontent.net"];
|
|
577
|
+
function isStudioPreviewHost(host) {
|
|
578
|
+
const normalized = stripPort(host);
|
|
579
|
+
if (normalized === "localhost" || normalized === "127.0.0.1") return true;
|
|
580
|
+
return PREVIEW_HOST_SUFFIXES.some((suffix) => normalized.endsWith(suffix));
|
|
581
|
+
}
|
|
582
|
+
function stripPort(host) {
|
|
583
|
+
return host.trim().toLowerCase().split(":")[0] ?? "";
|
|
584
|
+
}
|
|
585
|
+
async function resolvePublicSiteId(options) {
|
|
586
|
+
const fallback = options.fallback?.trim() ?? "";
|
|
587
|
+
const host = options.host ? stripPort(options.host) : "";
|
|
588
|
+
if (host && !isStudioPreviewHost(host)) {
|
|
589
|
+
const site = await getSite({
|
|
590
|
+
domain: host,
|
|
591
|
+
baseUrl: options.baseUrl,
|
|
592
|
+
fetch: options.fetch
|
|
593
|
+
});
|
|
594
|
+
if (site?.id) return site.id;
|
|
595
|
+
throw new GaragemSdkError(
|
|
596
|
+
`Garagem SDK: no published site found for domain "${host}"`,
|
|
597
|
+
{ status: 404, url: host }
|
|
598
|
+
);
|
|
599
|
+
}
|
|
600
|
+
if (fallback) return fallback;
|
|
601
|
+
throw new GaragemSdkError(
|
|
602
|
+
"Garagem SDK: could not resolve a site id (no host match and no fallback)",
|
|
603
|
+
{ status: 404, url: host || "fallback" }
|
|
604
|
+
);
|
|
605
|
+
}
|
|
606
|
+
|
|
568
607
|
// src/leads.ts
|
|
608
|
+
function browserHost() {
|
|
609
|
+
if (typeof window === "undefined") return "";
|
|
610
|
+
return window.location.host;
|
|
611
|
+
}
|
|
612
|
+
async function resolveLeadSiteId(input) {
|
|
613
|
+
try {
|
|
614
|
+
return await coerceSiteId(input.siteId);
|
|
615
|
+
} catch (error) {
|
|
616
|
+
const host = browserHost();
|
|
617
|
+
if (!host) throw error;
|
|
618
|
+
return resolvePublicSiteId({
|
|
619
|
+
host,
|
|
620
|
+
baseUrl: input.baseUrl,
|
|
621
|
+
fetch: input.fetch
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
}
|
|
569
625
|
var LeadSubmitError = class extends Error {
|
|
570
626
|
code;
|
|
571
627
|
status;
|
|
@@ -610,7 +666,7 @@ function studioDefaultLeadUi() {
|
|
|
610
666
|
};
|
|
611
667
|
}
|
|
612
668
|
async function getLeadUi(options) {
|
|
613
|
-
const siteId = await
|
|
669
|
+
const siteId = await resolveLeadSiteId(options);
|
|
614
670
|
const url = `${normalizeBaseUrl(options.baseUrl)}/api/sites/${encodeURIComponent(siteId)}/leads/ui`;
|
|
615
671
|
return callJson(
|
|
616
672
|
url,
|
|
@@ -668,7 +724,7 @@ function normalizeContact(input) {
|
|
|
668
724
|
};
|
|
669
725
|
}
|
|
670
726
|
async function postSiteLead(input) {
|
|
671
|
-
const siteId = await
|
|
727
|
+
const siteId = await resolveLeadSiteId(input);
|
|
672
728
|
const base = normalizeBaseUrl(input.baseUrl);
|
|
673
729
|
const url = `${base}/api/webhooks/sites/${encodeURIComponent(siteId)}/leads`;
|
|
674
730
|
const f = input.fetch ?? fetch;
|
|
@@ -727,7 +783,8 @@ function leadPostContext(input) {
|
|
|
727
783
|
async function submitVisitLead(input) {
|
|
728
784
|
const prepared = leadPostContext(input);
|
|
729
785
|
const schedule = input.schedule ?? STUDIO_DEFAULT_VISIT_SCHEDULE;
|
|
730
|
-
|
|
786
|
+
const visitDate = normalizeVisitDate(input.visitDate, schedule.timeZone);
|
|
787
|
+
if (!visitDate || !isVisitSlotAllowed(schedule, visitDate, input.visitTime)) {
|
|
731
788
|
throw new LeadSubmitError(
|
|
732
789
|
"Garagem SDK: visitDate/visitTime is outside the published schedule.",
|
|
733
790
|
{ code: "invalid_slot" }
|
|
@@ -743,7 +800,7 @@ async function submitVisitLead(input) {
|
|
|
743
800
|
...prepared.contact,
|
|
744
801
|
propertyId: prepared.listingId,
|
|
745
802
|
listingId: prepared.listingId,
|
|
746
|
-
visitDate
|
|
803
|
+
visitDate,
|
|
747
804
|
visitTime: input.visitTime,
|
|
748
805
|
...prepared.extras
|
|
749
806
|
}
|
|
@@ -1619,38 +1676,6 @@ function paginationPages(currentPage, totalPages, padding) {
|
|
|
1619
1676
|
return pages;
|
|
1620
1677
|
}
|
|
1621
1678
|
|
|
1622
|
-
// src/resolve-site-id.ts
|
|
1623
|
-
var PREVIEW_HOST_SUFFIXES = [".vusercontent.net"];
|
|
1624
|
-
function isStudioPreviewHost(host) {
|
|
1625
|
-
const normalized = stripPort(host);
|
|
1626
|
-
if (normalized === "localhost" || normalized === "127.0.0.1") return true;
|
|
1627
|
-
return PREVIEW_HOST_SUFFIXES.some((suffix) => normalized.endsWith(suffix));
|
|
1628
|
-
}
|
|
1629
|
-
function stripPort(host) {
|
|
1630
|
-
return host.trim().toLowerCase().split(":")[0] ?? "";
|
|
1631
|
-
}
|
|
1632
|
-
async function resolvePublicSiteId(options) {
|
|
1633
|
-
const fallback = options.fallback?.trim() ?? "";
|
|
1634
|
-
const host = options.host ? stripPort(options.host) : "";
|
|
1635
|
-
if (host && !isStudioPreviewHost(host)) {
|
|
1636
|
-
const site = await getSite({
|
|
1637
|
-
domain: host,
|
|
1638
|
-
baseUrl: options.baseUrl,
|
|
1639
|
-
fetch: options.fetch
|
|
1640
|
-
});
|
|
1641
|
-
if (site?.id) return site.id;
|
|
1642
|
-
throw new GaragemSdkError(
|
|
1643
|
-
`Garagem SDK: no published site found for domain "${host}"`,
|
|
1644
|
-
{ status: 404, url: host }
|
|
1645
|
-
);
|
|
1646
|
-
}
|
|
1647
|
-
if (fallback) return fallback;
|
|
1648
|
-
throw new GaragemSdkError(
|
|
1649
|
-
"Garagem SDK: could not resolve a site id (no host match and no fallback)",
|
|
1650
|
-
{ status: 404, url: host || "fallback" }
|
|
1651
|
-
);
|
|
1652
|
-
}
|
|
1653
|
-
|
|
1654
1679
|
// src/studio-contract.ts
|
|
1655
1680
|
var STUDIO_SDK_PACKAGE = "@garagem-ai/site-sdk";
|
|
1656
1681
|
var STUDIO_SDK_CONTRACT = {
|
|
@@ -1993,6 +2018,7 @@ function createGaragemClient(options = {}) {
|
|
|
1993
2018
|
listingLookupKey,
|
|
1994
2019
|
listingPublicPath,
|
|
1995
2020
|
mergeAppliedSearchQueryIntoSearch,
|
|
2021
|
+
normalizeVisitDate,
|
|
1996
2022
|
paginationPages,
|
|
1997
2023
|
parseAppliedSearchQuery,
|
|
1998
2024
|
parseGroupedInteger,
|