@garagem-ai/site-sdk 0.4.1 → 0.4.3
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 +26 -34
- package/dist/index.d.mts +176 -1
- package/dist/index.d.ts +176 -1
- package/dist/index.js +549 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +527 -0
- 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 +212 -179
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +155 -122
- package/dist/react.mjs.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +51 -0
- package/src/fetchers.ts +2 -1
- package/src/index.ts +45 -0
- package/src/leads.ts +341 -0
- package/src/react/listing-card.tsx +64 -52
- package/src/react/search-chrome.tsx +14 -12
- package/src/react/styles/search-chrome-css.generated.ts +1 -1
- package/src/react/styles/search-chrome-styles.tsx +22 -3
- package/src/schedule.ts +226 -0
- package/src/studio-contract.ts +168 -0
package/dist/index.js
CHANGED
|
@@ -22,20 +22,29 @@ var src_exports = {};
|
|
|
22
22
|
__export(src_exports, {
|
|
23
23
|
FORBIDDEN_SEARCH_QUERY_KEYS: () => FORBIDDEN_SEARCH_QUERY_KEYS,
|
|
24
24
|
GaragemSdkError: () => GaragemSdkError,
|
|
25
|
+
LeadSubmitError: () => LeadSubmitError,
|
|
25
26
|
SEARCH_CSS_RECIPE: () => SEARCH_CSS_RECIPE,
|
|
26
27
|
SEARCH_CSS_VARS: () => SEARCH_CSS_VARS,
|
|
27
28
|
SEARCH_SORT_RELEVANCE: () => SEARCH_SORT_RELEVANCE,
|
|
29
|
+
STUDIO_DEFAULT_VISIT_SCHEDULE: () => STUDIO_DEFAULT_VISIT_SCHEDULE,
|
|
30
|
+
STUDIO_SDK_CONTRACT: () => STUDIO_SDK_CONTRACT,
|
|
31
|
+
STUDIO_SDK_PACKAGE: () => STUDIO_SDK_PACKAGE,
|
|
28
32
|
TOOLBAR_PRIMARY_FILTER_IDS: () => TOOLBAR_PRIMARY_FILTER_IDS,
|
|
33
|
+
VISIT_TIME_ZONE: () => VISIT_TIME_ZONE,
|
|
29
34
|
applyPathFilter: () => applyPathFilter,
|
|
30
35
|
buildQueryListingsParams: () => buildQueryListingsParams,
|
|
31
36
|
canonicalizeSearchHref: () => canonicalizeSearchHref,
|
|
32
37
|
clearStagedPathFilters: () => clearStagedPathFilters,
|
|
38
|
+
coerceNpmVersion: () => coerceNpmVersion,
|
|
39
|
+
compareSemver: () => compareSemver,
|
|
33
40
|
composeSearchPublicHref: () => composeSearchPublicHref2,
|
|
34
41
|
composeSearchPublicPath: () => composeSearchPublicPath2,
|
|
35
42
|
countFacetChoices: () => countFacetChoices,
|
|
36
43
|
countOptionLabel: () => countOptionLabel,
|
|
37
44
|
createGaragemClient: () => createGaragemClient,
|
|
38
45
|
displayPathLocation: () => displayPathLocation,
|
|
46
|
+
expandVisitSchedule: () => expandVisitSchedule,
|
|
47
|
+
expandVisitTimeSlots: () => expandVisitTimeSlots,
|
|
39
48
|
formatAreaM2: () => formatAreaM2,
|
|
40
49
|
formatGroupedInteger: () => formatGroupedInteger,
|
|
41
50
|
formatListingPrice: () => formatListingPrice,
|
|
@@ -43,16 +52,19 @@ __export(src_exports, {
|
|
|
43
52
|
getCmsCollections: () => getCmsCollections,
|
|
44
53
|
getCmsEntries: () => getCmsEntries,
|
|
45
54
|
getCmsEntry: () => getCmsEntry,
|
|
55
|
+
getLeadUi: () => getLeadUi,
|
|
46
56
|
getListing: () => getListing,
|
|
47
57
|
getListings: () => getListings,
|
|
48
58
|
getSearchUi: () => getSearchUi,
|
|
49
59
|
getSimilarListings: () => getSimilarListings,
|
|
50
60
|
getSite: () => getSite,
|
|
61
|
+
hasShowcaseLeadsPostUrl: () => hasShowcaseLeadsPostUrl,
|
|
51
62
|
hrefForAppliedChange: () => hrefForAppliedChange,
|
|
52
63
|
hrefForPathFilters: () => hrefForPathFilters,
|
|
53
64
|
hrefWithExplicitPage: () => hrefWithExplicitPage,
|
|
54
65
|
isListingDetailPath: () => isListingDetailPath,
|
|
55
66
|
isStudioPreviewHost: () => isStudioPreviewHost,
|
|
67
|
+
isVisitSlotAllowed: () => isVisitSlotAllowed,
|
|
56
68
|
listingBusinessLabel: () => listingBusinessLabel,
|
|
57
69
|
listingLocationLabel: () => listingLocationLabel,
|
|
58
70
|
listingLookupKey: () => listingLookupKey,
|
|
@@ -61,6 +73,7 @@ __export(src_exports, {
|
|
|
61
73
|
paginationPages: () => paginationPages,
|
|
62
74
|
parseAppliedSearchQuery: () => parseAppliedSearchQuery2,
|
|
63
75
|
parseGroupedInteger: () => parseGroupedInteger,
|
|
76
|
+
parseReactSdkNamedImports: () => parseReactSdkNamedImports,
|
|
64
77
|
parseSearchPublicPath: () => parseSearchPublicPath2,
|
|
65
78
|
pathFilterHasOption: () => pathFilterHasOption,
|
|
66
79
|
pathFilterValue: () => pathFilterValue,
|
|
@@ -76,8 +89,17 @@ __export(src_exports, {
|
|
|
76
89
|
searchResultsHeading: () => searchResultsHeading,
|
|
77
90
|
searchSortOptions: () => searchSortOptions,
|
|
78
91
|
serializeAppliedSearchQuery: () => serializeAppliedSearchQuery2,
|
|
92
|
+
slotsForDate: () => slotsForDate,
|
|
93
|
+
studioChromeInstruction: () => studioChromeInstruction,
|
|
94
|
+
studioCodegenContractViolations: () => studioCodegenContractViolations,
|
|
95
|
+
studioDefaultLeadUi: () => studioDefaultLeadUi,
|
|
96
|
+
studioLeadInstruction: () => studioLeadInstruction,
|
|
97
|
+
studioSdkPinInstruction: () => studioSdkPinInstruction,
|
|
98
|
+
submitContactLead: () => submitContactLead,
|
|
99
|
+
submitVisitLead: () => submitVisitLead,
|
|
79
100
|
toListingCardModel: () => toListingCardModel,
|
|
80
101
|
toolbarFilterIds: () => toolbarFilterIds,
|
|
102
|
+
unavailableReactImports: () => unavailableReactImports,
|
|
81
103
|
visibleSearchFilters: () => visibleSearchFilters
|
|
82
104
|
});
|
|
83
105
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -398,6 +420,352 @@ async function getCmsEntry(options) {
|
|
|
398
420
|
return data;
|
|
399
421
|
}
|
|
400
422
|
|
|
423
|
+
// src/schedule.ts
|
|
424
|
+
var VISIT_TIME_ZONE = "America/Sao_Paulo";
|
|
425
|
+
var HHMM_RE = /^([01]\d|2[0-3]):([0-5]\d)$/;
|
|
426
|
+
var YMD_RE = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
427
|
+
var WEEKDAY_SHORT = {
|
|
428
|
+
Sun: 0,
|
|
429
|
+
Mon: 1,
|
|
430
|
+
Tue: 2,
|
|
431
|
+
Wed: 3,
|
|
432
|
+
Thu: 4,
|
|
433
|
+
Fri: 5,
|
|
434
|
+
Sat: 6
|
|
435
|
+
};
|
|
436
|
+
function pad2(value) {
|
|
437
|
+
return String(value).padStart(2, "0");
|
|
438
|
+
}
|
|
439
|
+
function parseHHmm(value) {
|
|
440
|
+
const match = HHMM_RE.exec(value);
|
|
441
|
+
if (!match) return null;
|
|
442
|
+
return { hour: Number(match[1]), minute: Number(match[2]) };
|
|
443
|
+
}
|
|
444
|
+
function minutesOfDay(hhmm) {
|
|
445
|
+
const parsed = parseHHmm(hhmm);
|
|
446
|
+
if (!parsed) return null;
|
|
447
|
+
return parsed.hour * 60 + parsed.minute;
|
|
448
|
+
}
|
|
449
|
+
function expandVisitTimeSlots(hours) {
|
|
450
|
+
const start = minutesOfDay(hours.start);
|
|
451
|
+
const end = minutesOfDay(hours.end);
|
|
452
|
+
if (start == null || end == null || start > end) return [];
|
|
453
|
+
const slots = [];
|
|
454
|
+
for (let minutes = start; minutes <= end; minutes += 60) {
|
|
455
|
+
const hour = Math.floor(minutes / 60);
|
|
456
|
+
const minute = minutes % 60;
|
|
457
|
+
slots.push(`${pad2(hour)}:${pad2(minute)}`);
|
|
458
|
+
}
|
|
459
|
+
return slots;
|
|
460
|
+
}
|
|
461
|
+
function unionSorted(left, right) {
|
|
462
|
+
return Array.from(/* @__PURE__ */ new Set([...left, ...right])).sort();
|
|
463
|
+
}
|
|
464
|
+
function expandVisitSchedule(config) {
|
|
465
|
+
const weekendHours = config.weekend ?? (config.saturday || config.sunday ? config.weekday : null);
|
|
466
|
+
const weekdayTimeSlots = expandVisitTimeSlots(config.weekday);
|
|
467
|
+
const weekendTimeSlots = weekendHours ? expandVisitTimeSlots(weekendHours) : [];
|
|
468
|
+
const disabledDays = [];
|
|
469
|
+
if (!config.sunday) disabledDays.push(0);
|
|
470
|
+
if (!config.saturday) disabledDays.push(6);
|
|
471
|
+
return {
|
|
472
|
+
...config,
|
|
473
|
+
weekend: weekendHours,
|
|
474
|
+
disabledDays,
|
|
475
|
+
weekdayTimeSlots,
|
|
476
|
+
weekendTimeSlots,
|
|
477
|
+
timeSlots: unionSorted(weekdayTimeSlots, weekendTimeSlots)
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
var STUDIO_DEFAULT_VISIT_SCHEDULE = expandVisitSchedule(
|
|
481
|
+
{
|
|
482
|
+
timeZone: VISIT_TIME_ZONE,
|
|
483
|
+
saturday: false,
|
|
484
|
+
sunday: false,
|
|
485
|
+
weekday: { start: "06:00", end: "22:00" },
|
|
486
|
+
weekend: null,
|
|
487
|
+
minHoursAhead: 2
|
|
488
|
+
}
|
|
489
|
+
);
|
|
490
|
+
function zonedParts(date, timeZone) {
|
|
491
|
+
const parts = new Intl.DateTimeFormat("en-US", {
|
|
492
|
+
timeZone,
|
|
493
|
+
weekday: "short",
|
|
494
|
+
year: "numeric",
|
|
495
|
+
month: "2-digit",
|
|
496
|
+
day: "2-digit",
|
|
497
|
+
hour: "2-digit",
|
|
498
|
+
minute: "2-digit",
|
|
499
|
+
hourCycle: "h23"
|
|
500
|
+
}).formatToParts(date);
|
|
501
|
+
const get = (type) => parts.find((part) => part.type === type)?.value ?? "";
|
|
502
|
+
const weekday = WEEKDAY_SHORT[get("weekday")] ?? 0;
|
|
503
|
+
return {
|
|
504
|
+
year: Number(get("year")),
|
|
505
|
+
month: Number(get("month")),
|
|
506
|
+
day: Number(get("day")),
|
|
507
|
+
hour: Number(get("hour")),
|
|
508
|
+
minute: Number(get("minute")),
|
|
509
|
+
weekday
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
function calendarYmd(date, timeZone) {
|
|
513
|
+
const parts = zonedParts(date, timeZone);
|
|
514
|
+
return `${parts.year}-${pad2(parts.month)}-${pad2(parts.day)}`;
|
|
515
|
+
}
|
|
516
|
+
function parseYmd(value) {
|
|
517
|
+
const match = YMD_RE.exec(value);
|
|
518
|
+
if (!match) return null;
|
|
519
|
+
const year = Number(match[1]);
|
|
520
|
+
const month = Number(match[2]);
|
|
521
|
+
const day = Number(match[3]);
|
|
522
|
+
const utc = new Date(Date.UTC(year, month - 1, day));
|
|
523
|
+
if (utc.getUTCFullYear() !== year || utc.getUTCMonth() !== month - 1 || utc.getUTCDate() !== day) {
|
|
524
|
+
return null;
|
|
525
|
+
}
|
|
526
|
+
return { year, month, day };
|
|
527
|
+
}
|
|
528
|
+
function toCalendarYmd(date, timeZone) {
|
|
529
|
+
if (typeof date === "string") {
|
|
530
|
+
return parseYmd(date) ? date : null;
|
|
531
|
+
}
|
|
532
|
+
if (date instanceof Date && Number.isFinite(date.getTime())) {
|
|
533
|
+
return calendarYmd(date, timeZone);
|
|
534
|
+
}
|
|
535
|
+
return null;
|
|
536
|
+
}
|
|
537
|
+
function weekdayOfYmd(ymd, timeZone) {
|
|
538
|
+
const parsed = parseYmd(ymd);
|
|
539
|
+
if (!parsed) return null;
|
|
540
|
+
const utcNoonish = new Date(
|
|
541
|
+
Date.UTC(parsed.year, parsed.month - 1, parsed.day, 15, 0, 0)
|
|
542
|
+
);
|
|
543
|
+
return zonedParts(utcNoonish, timeZone).weekday;
|
|
544
|
+
}
|
|
545
|
+
function slotsForDate(schedule, date, now = /* @__PURE__ */ new Date()) {
|
|
546
|
+
const timeZone = schedule.timeZone;
|
|
547
|
+
const ymd = toCalendarYmd(date, timeZone);
|
|
548
|
+
if (!ymd) return [];
|
|
549
|
+
const weekday = weekdayOfYmd(ymd, timeZone);
|
|
550
|
+
if (weekday == null) return [];
|
|
551
|
+
if (weekday === 0 && !schedule.sunday) return [];
|
|
552
|
+
if (weekday === 6 && !schedule.saturday) return [];
|
|
553
|
+
const base = weekday === 0 || weekday === 6 ? schedule.weekendTimeSlots : schedule.weekdayTimeSlots;
|
|
554
|
+
const today = calendarYmd(now, timeZone);
|
|
555
|
+
if (ymd < today) return [];
|
|
556
|
+
if (ymd !== today) return [...base];
|
|
557
|
+
const nowParts = zonedParts(now, timeZone);
|
|
558
|
+
const cutoff = nowParts.hour * 60 + nowParts.minute + schedule.minHoursAhead * 60;
|
|
559
|
+
return base.filter((slot) => {
|
|
560
|
+
const minutes = minutesOfDay(slot);
|
|
561
|
+
return minutes != null && minutes >= cutoff;
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
function isVisitSlotAllowed(schedule, visitDate, visitTime, now = /* @__PURE__ */ new Date()) {
|
|
565
|
+
return slotsForDate(schedule, visitDate, now).includes(visitTime);
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
// src/leads.ts
|
|
569
|
+
var LeadSubmitError = class extends Error {
|
|
570
|
+
code;
|
|
571
|
+
status;
|
|
572
|
+
retryAfterSeconds;
|
|
573
|
+
constructor(message, info) {
|
|
574
|
+
super(message);
|
|
575
|
+
this.name = "LeadSubmitError";
|
|
576
|
+
this.code = info.code;
|
|
577
|
+
if (info.status != null) this.status = info.status;
|
|
578
|
+
if (info.retryAfterSeconds != null) {
|
|
579
|
+
this.retryAfterSeconds = info.retryAfterSeconds;
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
};
|
|
583
|
+
var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
584
|
+
var EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
585
|
+
var MESSAGE_MAX = 2e3;
|
|
586
|
+
var CONTACT_FIELDS = [
|
|
587
|
+
{ id: "name", required: true },
|
|
588
|
+
{ id: "email", required: false },
|
|
589
|
+
{ id: "phone", required: false },
|
|
590
|
+
{ id: "message", required: false }
|
|
591
|
+
];
|
|
592
|
+
function studioDefaultLeadUi() {
|
|
593
|
+
return {
|
|
594
|
+
defaultVariant: "visit",
|
|
595
|
+
timeZone: "America/Sao_Paulo",
|
|
596
|
+
variants: {
|
|
597
|
+
visit: {
|
|
598
|
+
ctaLabel: "Agendar visita",
|
|
599
|
+
requireDateTime: true,
|
|
600
|
+
schedule: STUDIO_DEFAULT_VISIT_SCHEDULE,
|
|
601
|
+
fields: CONTACT_FIELDS
|
|
602
|
+
},
|
|
603
|
+
contact: {
|
|
604
|
+
ctaLabel: "Fale conosco",
|
|
605
|
+
requireDateTime: false,
|
|
606
|
+
whatsappPhone: null,
|
|
607
|
+
fields: CONTACT_FIELDS
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
async function getLeadUi(options) {
|
|
613
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
614
|
+
const url = `${normalizeBaseUrl(options.baseUrl)}/api/sites/${encodeURIComponent(siteId)}/leads/ui`;
|
|
615
|
+
return callJson(
|
|
616
|
+
url,
|
|
617
|
+
{
|
|
618
|
+
method: "GET",
|
|
619
|
+
headers: { Accept: "application/json" },
|
|
620
|
+
next: options.next
|
|
621
|
+
},
|
|
622
|
+
options.fetch ?? fetch
|
|
623
|
+
);
|
|
624
|
+
}
|
|
625
|
+
function assertListingId(listingId) {
|
|
626
|
+
if (!UUID_RE.test(listingId.trim())) {
|
|
627
|
+
throw new LeadSubmitError(
|
|
628
|
+
"Garagem SDK: listingId must be the listing UUID, not a path or code.",
|
|
629
|
+
{ code: "invalid_listing_id" }
|
|
630
|
+
);
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
function normalizeContact(input) {
|
|
634
|
+
const name = input.name.trim();
|
|
635
|
+
if (name.length < 2 || name.length > 200) {
|
|
636
|
+
throw new LeadSubmitError("Garagem SDK: name is required.", {
|
|
637
|
+
code: "invalid_contact"
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
const email = input.email?.trim() || void 0;
|
|
641
|
+
const phone = input.phone?.trim() || void 0;
|
|
642
|
+
if (!email && !phone) {
|
|
643
|
+
throw new LeadSubmitError("Garagem SDK: email and/or phone is required.", {
|
|
644
|
+
code: "invalid_contact"
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
if (email && !EMAIL_RE.test(email)) {
|
|
648
|
+
throw new LeadSubmitError("Garagem SDK: email is invalid.", {
|
|
649
|
+
code: "invalid_contact"
|
|
650
|
+
});
|
|
651
|
+
}
|
|
652
|
+
if (phone && (phone.length < 5 || phone.length > 40)) {
|
|
653
|
+
throw new LeadSubmitError("Garagem SDK: phone is invalid.", {
|
|
654
|
+
code: "invalid_contact"
|
|
655
|
+
});
|
|
656
|
+
}
|
|
657
|
+
const message = input.message?.trim() || void 0;
|
|
658
|
+
if (message && message.length > MESSAGE_MAX) {
|
|
659
|
+
throw new LeadSubmitError("Garagem SDK: message is too long.", {
|
|
660
|
+
code: "invalid_contact"
|
|
661
|
+
});
|
|
662
|
+
}
|
|
663
|
+
return {
|
|
664
|
+
name,
|
|
665
|
+
...email ? { email } : {},
|
|
666
|
+
...phone ? { phone } : {},
|
|
667
|
+
...message ? { message } : {}
|
|
668
|
+
};
|
|
669
|
+
}
|
|
670
|
+
async function postSiteLead(input) {
|
|
671
|
+
const siteId = await coerceSiteId(input.siteId);
|
|
672
|
+
const base = normalizeBaseUrl(input.baseUrl);
|
|
673
|
+
const url = `${base}/api/webhooks/sites/${encodeURIComponent(siteId)}/leads`;
|
|
674
|
+
const f = input.fetch ?? fetch;
|
|
675
|
+
let response;
|
|
676
|
+
try {
|
|
677
|
+
response = await f(url, {
|
|
678
|
+
method: "POST",
|
|
679
|
+
headers: {
|
|
680
|
+
Accept: "application/json",
|
|
681
|
+
"Content-Type": "application/json"
|
|
682
|
+
},
|
|
683
|
+
body: JSON.stringify(input.body)
|
|
684
|
+
});
|
|
685
|
+
} catch (error) {
|
|
686
|
+
throw new LeadSubmitError(
|
|
687
|
+
error instanceof Error ? error.message : "Garagem SDK: network error.",
|
|
688
|
+
{ code: "network" }
|
|
689
|
+
);
|
|
690
|
+
}
|
|
691
|
+
if (response.status === 202) {
|
|
692
|
+
const data = await response.json().catch(() => ({}));
|
|
693
|
+
const id = typeof data.id === "string" && data.id ? data.id : "";
|
|
694
|
+
return { ok: true, status: 202, id };
|
|
695
|
+
}
|
|
696
|
+
const retryAfter = Number(response.headers.get("Retry-After") ?? "");
|
|
697
|
+
if (response.status === 429) {
|
|
698
|
+
throw new LeadSubmitError("Garagem SDK: too many lead submissions.", {
|
|
699
|
+
code: "rate_limited",
|
|
700
|
+
status: 429,
|
|
701
|
+
retryAfterSeconds: Number.isFinite(retryAfter) ? retryAfter : void 0
|
|
702
|
+
});
|
|
703
|
+
}
|
|
704
|
+
if (response.status === 404) {
|
|
705
|
+
throw new LeadSubmitError("Garagem SDK: listing or site not found.", {
|
|
706
|
+
code: "not_found",
|
|
707
|
+
status: 404
|
|
708
|
+
});
|
|
709
|
+
}
|
|
710
|
+
throw new LeadSubmitError(
|
|
711
|
+
`Garagem SDK: lead submit failed (${response.status}).`,
|
|
712
|
+
{ code: "http", status: response.status }
|
|
713
|
+
);
|
|
714
|
+
}
|
|
715
|
+
function leadPostContext(input) {
|
|
716
|
+
assertListingId(input.listingId);
|
|
717
|
+
return {
|
|
718
|
+
listingId: input.listingId.trim(),
|
|
719
|
+
contact: normalizeContact(input),
|
|
720
|
+
extras: {
|
|
721
|
+
...input.visitorId ? { visitorId: input.visitorId } : {},
|
|
722
|
+
...input.brokerRef ? { brokerRef: input.brokerRef } : {},
|
|
723
|
+
...input.referrer ? { referrer: input.referrer } : {}
|
|
724
|
+
}
|
|
725
|
+
};
|
|
726
|
+
}
|
|
727
|
+
async function submitVisitLead(input) {
|
|
728
|
+
const prepared = leadPostContext(input);
|
|
729
|
+
const schedule = input.schedule ?? STUDIO_DEFAULT_VISIT_SCHEDULE;
|
|
730
|
+
if (!isVisitSlotAllowed(schedule, input.visitDate, input.visitTime)) {
|
|
731
|
+
throw new LeadSubmitError(
|
|
732
|
+
"Garagem SDK: visitDate/visitTime is outside the published schedule.",
|
|
733
|
+
{ code: "invalid_slot" }
|
|
734
|
+
);
|
|
735
|
+
}
|
|
736
|
+
return postSiteLead({
|
|
737
|
+
siteId: input.siteId,
|
|
738
|
+
baseUrl: input.baseUrl,
|
|
739
|
+
fetch: input.fetch,
|
|
740
|
+
body: {
|
|
741
|
+
source: "site-sdk",
|
|
742
|
+
leadType: "visit",
|
|
743
|
+
...prepared.contact,
|
|
744
|
+
propertyId: prepared.listingId,
|
|
745
|
+
listingId: prepared.listingId,
|
|
746
|
+
visitDate: input.visitDate,
|
|
747
|
+
visitTime: input.visitTime,
|
|
748
|
+
...prepared.extras
|
|
749
|
+
}
|
|
750
|
+
});
|
|
751
|
+
}
|
|
752
|
+
async function submitContactLead(input) {
|
|
753
|
+
const prepared = leadPostContext(input);
|
|
754
|
+
return postSiteLead({
|
|
755
|
+
siteId: input.siteId,
|
|
756
|
+
baseUrl: input.baseUrl,
|
|
757
|
+
fetch: input.fetch,
|
|
758
|
+
body: {
|
|
759
|
+
source: "site-sdk",
|
|
760
|
+
leadType: "contact",
|
|
761
|
+
...prepared.contact,
|
|
762
|
+
propertyId: prepared.listingId,
|
|
763
|
+
listingId: prepared.listingId,
|
|
764
|
+
...prepared.extras
|
|
765
|
+
}
|
|
766
|
+
});
|
|
767
|
+
}
|
|
768
|
+
|
|
401
769
|
// src/presentation.ts
|
|
402
770
|
var SEARCH_CSS_VARS = {
|
|
403
771
|
cardRadius: "--garagem-listing-card-radius",
|
|
@@ -1283,6 +1651,141 @@ async function resolvePublicSiteId(options) {
|
|
|
1283
1651
|
);
|
|
1284
1652
|
}
|
|
1285
1653
|
|
|
1654
|
+
// src/studio-contract.ts
|
|
1655
|
+
var STUDIO_SDK_PACKAGE = "@garagem-ai/site-sdk";
|
|
1656
|
+
var STUDIO_SDK_CONTRACT = {
|
|
1657
|
+
package: STUDIO_SDK_PACKAGE,
|
|
1658
|
+
/**
|
|
1659
|
+
* Exact pin for generated Studio sites. Must be ≥ `selfInjectSince` so
|
|
1660
|
+
* prompts that skip the layout chrome tag match the tarball v0 installs.
|
|
1661
|
+
* This PR’s changeset publishes that tarball as 0.4.3 — do not generate
|
|
1662
|
+
* against this floor until Version Packages is on npm.
|
|
1663
|
+
*/
|
|
1664
|
+
minNpmVersion: "0.4.3",
|
|
1665
|
+
/** First release where ListingCard and ResultsSkeleton inject the sheet. */
|
|
1666
|
+
selfInjectSince: "0.4.2",
|
|
1667
|
+
chromeStrategy: "self-inject",
|
|
1668
|
+
reactExports: [
|
|
1669
|
+
"SearchPage",
|
|
1670
|
+
"ListingCard",
|
|
1671
|
+
"usePublicSearch",
|
|
1672
|
+
"ResultsSkeleton"
|
|
1673
|
+
],
|
|
1674
|
+
/**
|
|
1675
|
+
* Names that exist in git / the unpublished patch. Completeness treats an
|
|
1676
|
+
* import as `sdk-export-mismatch` when the generated pin is older than
|
|
1677
|
+
* `since`. Studio prompts must not mention these names at all (even as
|
|
1678
|
+
* “never import”) — v0 copies the identifier and the preview ESM loader
|
|
1679
|
+
* throws FatalRendererError.
|
|
1680
|
+
*/
|
|
1681
|
+
optionalReactExports: {
|
|
1682
|
+
SearchPageFallback: "0.4.1",
|
|
1683
|
+
SearchChromeStyles: "0.4.1"
|
|
1684
|
+
},
|
|
1685
|
+
forbiddenImports: ["@garagem-ai/site-sdk/react/search.css"],
|
|
1686
|
+
leadStrategy: "visit-default",
|
|
1687
|
+
leadExports: [
|
|
1688
|
+
"getLeadUi",
|
|
1689
|
+
"submitVisitLead",
|
|
1690
|
+
"submitContactLead",
|
|
1691
|
+
"slotsForDate",
|
|
1692
|
+
"expandVisitSchedule",
|
|
1693
|
+
"expandVisitTimeSlots",
|
|
1694
|
+
"isVisitSlotAllowed",
|
|
1695
|
+
"STUDIO_DEFAULT_VISIT_SCHEDULE"
|
|
1696
|
+
]
|
|
1697
|
+
};
|
|
1698
|
+
var REACT_SDK_NAMED_IMPORT_RE = /(?:^|[\n;])\s*import\s+(?!type\b)(?:type\s+)?\{([^}]+)\}\s+from\s+['"]@garagem-ai\/site-sdk\/react['"]/g;
|
|
1699
|
+
var SHOWCASE_LEADS_POST_URL_RE = /\/api\/sites\/[^\s"']*\/leads(?!\/ui)/;
|
|
1700
|
+
function hasShowcaseLeadsPostUrl(text) {
|
|
1701
|
+
return SHOWCASE_LEADS_POST_URL_RE.test(text);
|
|
1702
|
+
}
|
|
1703
|
+
function coerceNpmVersion(raw) {
|
|
1704
|
+
if (typeof raw !== "string") return null;
|
|
1705
|
+
const match = raw.trim().match(/(\d+)\.(\d+)\.(\d+)/);
|
|
1706
|
+
return match ? `${match[1]}.${match[2]}.${match[3]}` : null;
|
|
1707
|
+
}
|
|
1708
|
+
function compareSemver(a, b) {
|
|
1709
|
+
const left = a.split(".").map((part) => Number(part));
|
|
1710
|
+
const right = b.split(".").map((part) => Number(part));
|
|
1711
|
+
for (let i = 0; i < 3; i += 1) {
|
|
1712
|
+
const delta = (left[i] ?? 0) - (right[i] ?? 0);
|
|
1713
|
+
if (delta !== 0) return delta;
|
|
1714
|
+
}
|
|
1715
|
+
return 0;
|
|
1716
|
+
}
|
|
1717
|
+
function parseReactSdkNamedImports(source) {
|
|
1718
|
+
const names = [];
|
|
1719
|
+
REACT_SDK_NAMED_IMPORT_RE.lastIndex = 0;
|
|
1720
|
+
let match;
|
|
1721
|
+
while ((match = REACT_SDK_NAMED_IMPORT_RE.exec(source)) !== null) {
|
|
1722
|
+
const body = match[1];
|
|
1723
|
+
if (!body) continue;
|
|
1724
|
+
for (const raw of body.split(",")) {
|
|
1725
|
+
const token = raw.trim();
|
|
1726
|
+
if (!token || token.startsWith("type ")) continue;
|
|
1727
|
+
const name = token.split(/\s+as\s+/)[0]?.trim();
|
|
1728
|
+
if (name) names.push(name);
|
|
1729
|
+
}
|
|
1730
|
+
}
|
|
1731
|
+
return names;
|
|
1732
|
+
}
|
|
1733
|
+
function reactExportsAvailableAt(pin) {
|
|
1734
|
+
const available = new Set(STUDIO_SDK_CONTRACT.reactExports);
|
|
1735
|
+
for (const [name, since] of Object.entries(
|
|
1736
|
+
STUDIO_SDK_CONTRACT.optionalReactExports
|
|
1737
|
+
)) {
|
|
1738
|
+
if (compareSemver(pin, since) >= 0) available.add(name);
|
|
1739
|
+
}
|
|
1740
|
+
return available;
|
|
1741
|
+
}
|
|
1742
|
+
function unavailableReactImports(source, pin) {
|
|
1743
|
+
const available = reactExportsAvailableAt(pin);
|
|
1744
|
+
const missing = [];
|
|
1745
|
+
for (const name of parseReactSdkNamedImports(source)) {
|
|
1746
|
+
if (!available.has(name) && !missing.includes(name)) {
|
|
1747
|
+
missing.push(name);
|
|
1748
|
+
}
|
|
1749
|
+
}
|
|
1750
|
+
return missing;
|
|
1751
|
+
}
|
|
1752
|
+
function studioSdkPinInstruction() {
|
|
1753
|
+
const version = STUDIO_SDK_CONTRACT.minNpmVersion;
|
|
1754
|
+
const names = STUDIO_SDK_CONTRACT.reactExports.join(", ");
|
|
1755
|
+
return `In \`package.json\` set \`"@garagem-ai/site-sdk": "${version}"\` (exact). Import only these \`${STUDIO_SDK_PACKAGE}/react\` names: ${names}.`;
|
|
1756
|
+
}
|
|
1757
|
+
function studioLeadInstruction() {
|
|
1758
|
+
const names = STUDIO_SDK_CONTRACT.leadExports.join(", ");
|
|
1759
|
+
return `Listing-detail visit/contact leads: import ${names} from \`${STUDIO_SDK_PACKAGE}\` (the main package, not \`/react\`). Call \`submitVisitLead\` / \`submitContactLead\` \u2014 never concatenate a leads webhook URL and never POST the Showcase demo leads route.`;
|
|
1760
|
+
}
|
|
1761
|
+
function studioChromeInstruction() {
|
|
1762
|
+
const injectors = compareSemver(
|
|
1763
|
+
STUDIO_SDK_CONTRACT.minNpmVersion,
|
|
1764
|
+
STUDIO_SDK_CONTRACT.selfInjectSince
|
|
1765
|
+
) >= 0 ? "`SearchPage`, `ListingCard`, and `ResultsSkeleton`" : "`SearchPage`";
|
|
1766
|
+
return `Search chrome CSS is injected by ${injectors} (JS \`<style>\` tag). Never \`import "@garagem-ai/site-sdk/react/search.css"\` \u2014 v0 preview cannot load npm CSS. Do not copy SDK layout into the app. Theme via CSS variables in \`app/globals.css\` (\`SEARCH_CSS_RECIPE\` / \`--garagem-*\`), \`classNames\`, and \`data-slot\`.`;
|
|
1767
|
+
}
|
|
1768
|
+
function studioCodegenContractViolations(text) {
|
|
1769
|
+
const violations = [];
|
|
1770
|
+
for (const name of Object.keys(STUDIO_SDK_CONTRACT.optionalReactExports)) {
|
|
1771
|
+
if (text.includes(name)) violations.push(name);
|
|
1772
|
+
}
|
|
1773
|
+
const pin = STUDIO_SDK_CONTRACT.minNpmVersion;
|
|
1774
|
+
const available = reactExportsAvailableAt(pin);
|
|
1775
|
+
for (const name of parseReactSdkNamedImports(text)) {
|
|
1776
|
+
if (!available.has(name) && !violations.includes(name)) {
|
|
1777
|
+
violations.push(name);
|
|
1778
|
+
}
|
|
1779
|
+
}
|
|
1780
|
+
if (hasShowcaseLeadsPostUrl(text)) {
|
|
1781
|
+
violations.push("showcase-leads-url");
|
|
1782
|
+
}
|
|
1783
|
+
if (/\btype\s*=\s*["']date["']/.test(text)) {
|
|
1784
|
+
violations.push("native-date-input");
|
|
1785
|
+
}
|
|
1786
|
+
return violations;
|
|
1787
|
+
}
|
|
1788
|
+
|
|
1286
1789
|
// src/client.ts
|
|
1287
1790
|
function createGaragemClient(options = {}) {
|
|
1288
1791
|
const resolveSiteId = (override) => {
|
|
@@ -1411,6 +1914,30 @@ function createGaragemClient(options = {}) {
|
|
|
1411
1914
|
const merged = mergeNext(next);
|
|
1412
1915
|
if (merged !== void 0) opts.next = merged;
|
|
1413
1916
|
return getCmsEntry(opts);
|
|
1917
|
+
},
|
|
1918
|
+
async getLeadUi({ siteId, next } = {}) {
|
|
1919
|
+
const opts = withDefaults({
|
|
1920
|
+
siteId: resolveSiteId(siteId)
|
|
1921
|
+
});
|
|
1922
|
+
const merged = mergeNext(next);
|
|
1923
|
+
if (merged !== void 0) opts.next = merged;
|
|
1924
|
+
return getLeadUi(opts);
|
|
1925
|
+
},
|
|
1926
|
+
async submitVisitLead(args) {
|
|
1927
|
+
return submitVisitLead(
|
|
1928
|
+
withDefaults({
|
|
1929
|
+
...args,
|
|
1930
|
+
siteId: resolveSiteId(args.siteId)
|
|
1931
|
+
})
|
|
1932
|
+
);
|
|
1933
|
+
},
|
|
1934
|
+
async submitContactLead(args) {
|
|
1935
|
+
return submitContactLead(
|
|
1936
|
+
withDefaults({
|
|
1937
|
+
...args,
|
|
1938
|
+
siteId: resolveSiteId(args.siteId)
|
|
1939
|
+
})
|
|
1940
|
+
);
|
|
1414
1941
|
}
|
|
1415
1942
|
};
|
|
1416
1943
|
}
|
|
@@ -1418,20 +1945,29 @@ function createGaragemClient(options = {}) {
|
|
|
1418
1945
|
0 && (module.exports = {
|
|
1419
1946
|
FORBIDDEN_SEARCH_QUERY_KEYS,
|
|
1420
1947
|
GaragemSdkError,
|
|
1948
|
+
LeadSubmitError,
|
|
1421
1949
|
SEARCH_CSS_RECIPE,
|
|
1422
1950
|
SEARCH_CSS_VARS,
|
|
1423
1951
|
SEARCH_SORT_RELEVANCE,
|
|
1952
|
+
STUDIO_DEFAULT_VISIT_SCHEDULE,
|
|
1953
|
+
STUDIO_SDK_CONTRACT,
|
|
1954
|
+
STUDIO_SDK_PACKAGE,
|
|
1424
1955
|
TOOLBAR_PRIMARY_FILTER_IDS,
|
|
1956
|
+
VISIT_TIME_ZONE,
|
|
1425
1957
|
applyPathFilter,
|
|
1426
1958
|
buildQueryListingsParams,
|
|
1427
1959
|
canonicalizeSearchHref,
|
|
1428
1960
|
clearStagedPathFilters,
|
|
1961
|
+
coerceNpmVersion,
|
|
1962
|
+
compareSemver,
|
|
1429
1963
|
composeSearchPublicHref,
|
|
1430
1964
|
composeSearchPublicPath,
|
|
1431
1965
|
countFacetChoices,
|
|
1432
1966
|
countOptionLabel,
|
|
1433
1967
|
createGaragemClient,
|
|
1434
1968
|
displayPathLocation,
|
|
1969
|
+
expandVisitSchedule,
|
|
1970
|
+
expandVisitTimeSlots,
|
|
1435
1971
|
formatAreaM2,
|
|
1436
1972
|
formatGroupedInteger,
|
|
1437
1973
|
formatListingPrice,
|
|
@@ -1439,16 +1975,19 @@ function createGaragemClient(options = {}) {
|
|
|
1439
1975
|
getCmsCollections,
|
|
1440
1976
|
getCmsEntries,
|
|
1441
1977
|
getCmsEntry,
|
|
1978
|
+
getLeadUi,
|
|
1442
1979
|
getListing,
|
|
1443
1980
|
getListings,
|
|
1444
1981
|
getSearchUi,
|
|
1445
1982
|
getSimilarListings,
|
|
1446
1983
|
getSite,
|
|
1984
|
+
hasShowcaseLeadsPostUrl,
|
|
1447
1985
|
hrefForAppliedChange,
|
|
1448
1986
|
hrefForPathFilters,
|
|
1449
1987
|
hrefWithExplicitPage,
|
|
1450
1988
|
isListingDetailPath,
|
|
1451
1989
|
isStudioPreviewHost,
|
|
1990
|
+
isVisitSlotAllowed,
|
|
1452
1991
|
listingBusinessLabel,
|
|
1453
1992
|
listingLocationLabel,
|
|
1454
1993
|
listingLookupKey,
|
|
@@ -1457,6 +1996,7 @@ function createGaragemClient(options = {}) {
|
|
|
1457
1996
|
paginationPages,
|
|
1458
1997
|
parseAppliedSearchQuery,
|
|
1459
1998
|
parseGroupedInteger,
|
|
1999
|
+
parseReactSdkNamedImports,
|
|
1460
2000
|
parseSearchPublicPath,
|
|
1461
2001
|
pathFilterHasOption,
|
|
1462
2002
|
pathFilterValue,
|
|
@@ -1472,8 +2012,17 @@ function createGaragemClient(options = {}) {
|
|
|
1472
2012
|
searchResultsHeading,
|
|
1473
2013
|
searchSortOptions,
|
|
1474
2014
|
serializeAppliedSearchQuery,
|
|
2015
|
+
slotsForDate,
|
|
2016
|
+
studioChromeInstruction,
|
|
2017
|
+
studioCodegenContractViolations,
|
|
2018
|
+
studioDefaultLeadUi,
|
|
2019
|
+
studioLeadInstruction,
|
|
2020
|
+
studioSdkPinInstruction,
|
|
2021
|
+
submitContactLead,
|
|
2022
|
+
submitVisitLead,
|
|
1475
2023
|
toListingCardModel,
|
|
1476
2024
|
toolbarFilterIds,
|
|
2025
|
+
unavailableReactImports,
|
|
1477
2026
|
visibleSearchFilters
|
|
1478
2027
|
});
|
|
1479
2028
|
//# sourceMappingURL=index.js.map
|