@garagem-ai/site-sdk 0.4.2 → 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 -11
- package/dist/index.d.mts +130 -3
- package/dist/index.d.ts +130 -3
- package/dist/index.js +431 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +417 -3
- 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/client.ts +51 -0
- package/src/fetchers.ts +2 -1
- package/src/index.ts +33 -0
- package/src/leads.ts +343 -0
- package/src/react/styles/search-chrome-css.generated.ts +1 -1
- package/src/schedule.ts +236 -0
- package/src/studio-contract.ts +32 -2
package/dist/index.js
CHANGED
|
@@ -22,12 +22,15 @@ 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,
|
|
28
30
|
STUDIO_SDK_CONTRACT: () => STUDIO_SDK_CONTRACT,
|
|
29
31
|
STUDIO_SDK_PACKAGE: () => STUDIO_SDK_PACKAGE,
|
|
30
32
|
TOOLBAR_PRIMARY_FILTER_IDS: () => TOOLBAR_PRIMARY_FILTER_IDS,
|
|
33
|
+
VISIT_TIME_ZONE: () => VISIT_TIME_ZONE,
|
|
31
34
|
applyPathFilter: () => applyPathFilter,
|
|
32
35
|
buildQueryListingsParams: () => buildQueryListingsParams,
|
|
33
36
|
canonicalizeSearchHref: () => canonicalizeSearchHref,
|
|
@@ -40,6 +43,8 @@ __export(src_exports, {
|
|
|
40
43
|
countOptionLabel: () => countOptionLabel,
|
|
41
44
|
createGaragemClient: () => createGaragemClient,
|
|
42
45
|
displayPathLocation: () => displayPathLocation,
|
|
46
|
+
expandVisitSchedule: () => expandVisitSchedule,
|
|
47
|
+
expandVisitTimeSlots: () => expandVisitTimeSlots,
|
|
43
48
|
formatAreaM2: () => formatAreaM2,
|
|
44
49
|
formatGroupedInteger: () => formatGroupedInteger,
|
|
45
50
|
formatListingPrice: () => formatListingPrice,
|
|
@@ -47,21 +52,25 @@ __export(src_exports, {
|
|
|
47
52
|
getCmsCollections: () => getCmsCollections,
|
|
48
53
|
getCmsEntries: () => getCmsEntries,
|
|
49
54
|
getCmsEntry: () => getCmsEntry,
|
|
55
|
+
getLeadUi: () => getLeadUi,
|
|
50
56
|
getListing: () => getListing,
|
|
51
57
|
getListings: () => getListings,
|
|
52
58
|
getSearchUi: () => getSearchUi,
|
|
53
59
|
getSimilarListings: () => getSimilarListings,
|
|
54
60
|
getSite: () => getSite,
|
|
61
|
+
hasShowcaseLeadsPostUrl: () => hasShowcaseLeadsPostUrl,
|
|
55
62
|
hrefForAppliedChange: () => hrefForAppliedChange,
|
|
56
63
|
hrefForPathFilters: () => hrefForPathFilters,
|
|
57
64
|
hrefWithExplicitPage: () => hrefWithExplicitPage,
|
|
58
65
|
isListingDetailPath: () => isListingDetailPath,
|
|
59
66
|
isStudioPreviewHost: () => isStudioPreviewHost,
|
|
67
|
+
isVisitSlotAllowed: () => isVisitSlotAllowed,
|
|
60
68
|
listingBusinessLabel: () => listingBusinessLabel,
|
|
61
69
|
listingLocationLabel: () => listingLocationLabel,
|
|
62
70
|
listingLookupKey: () => listingLookupKey,
|
|
63
71
|
listingPublicPath: () => listingPublicPath,
|
|
64
72
|
mergeAppliedSearchQueryIntoSearch: () => mergeAppliedSearchQueryIntoSearch2,
|
|
73
|
+
normalizeVisitDate: () => normalizeVisitDate,
|
|
65
74
|
paginationPages: () => paginationPages,
|
|
66
75
|
parseAppliedSearchQuery: () => parseAppliedSearchQuery2,
|
|
67
76
|
parseGroupedInteger: () => parseGroupedInteger,
|
|
@@ -81,9 +90,14 @@ __export(src_exports, {
|
|
|
81
90
|
searchResultsHeading: () => searchResultsHeading,
|
|
82
91
|
searchSortOptions: () => searchSortOptions,
|
|
83
92
|
serializeAppliedSearchQuery: () => serializeAppliedSearchQuery2,
|
|
93
|
+
slotsForDate: () => slotsForDate,
|
|
84
94
|
studioChromeInstruction: () => studioChromeInstruction,
|
|
85
95
|
studioCodegenContractViolations: () => studioCodegenContractViolations,
|
|
96
|
+
studioDefaultLeadUi: () => studioDefaultLeadUi,
|
|
97
|
+
studioLeadInstruction: () => studioLeadInstruction,
|
|
86
98
|
studioSdkPinInstruction: () => studioSdkPinInstruction,
|
|
99
|
+
submitContactLead: () => submitContactLead,
|
|
100
|
+
submitVisitLead: () => submitVisitLead,
|
|
87
101
|
toListingCardModel: () => toListingCardModel,
|
|
88
102
|
toolbarFilterIds: () => toolbarFilterIds,
|
|
89
103
|
unavailableReactImports: () => unavailableReactImports,
|
|
@@ -407,6 +421,357 @@ async function getCmsEntry(options) {
|
|
|
407
421
|
return data;
|
|
408
422
|
}
|
|
409
423
|
|
|
424
|
+
// src/schedule.ts
|
|
425
|
+
var VISIT_TIME_ZONE = "America/Sao_Paulo";
|
|
426
|
+
var HHMM_RE = /^([01]\d|2[0-3]):([0-5]\d)$/;
|
|
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})$/;
|
|
429
|
+
var WEEKDAY_SHORT = {
|
|
430
|
+
Sun: 0,
|
|
431
|
+
Mon: 1,
|
|
432
|
+
Tue: 2,
|
|
433
|
+
Wed: 3,
|
|
434
|
+
Thu: 4,
|
|
435
|
+
Fri: 5,
|
|
436
|
+
Sat: 6
|
|
437
|
+
};
|
|
438
|
+
function pad2(value) {
|
|
439
|
+
return String(value).padStart(2, "0");
|
|
440
|
+
}
|
|
441
|
+
function parseHHmm(value) {
|
|
442
|
+
const match = HHMM_RE.exec(value);
|
|
443
|
+
if (!match) return null;
|
|
444
|
+
return { hour: Number(match[1]), minute: Number(match[2]) };
|
|
445
|
+
}
|
|
446
|
+
function minutesOfDay(hhmm) {
|
|
447
|
+
const parsed = parseHHmm(hhmm);
|
|
448
|
+
if (!parsed) return null;
|
|
449
|
+
return parsed.hour * 60 + parsed.minute;
|
|
450
|
+
}
|
|
451
|
+
function expandVisitTimeSlots(hours) {
|
|
452
|
+
const start = minutesOfDay(hours.start);
|
|
453
|
+
const end = minutesOfDay(hours.end);
|
|
454
|
+
if (start == null || end == null || start > end) return [];
|
|
455
|
+
const slots = [];
|
|
456
|
+
for (let minutes = start; minutes <= end; minutes += 60) {
|
|
457
|
+
const hour = Math.floor(minutes / 60);
|
|
458
|
+
const minute = minutes % 60;
|
|
459
|
+
slots.push(`${pad2(hour)}:${pad2(minute)}`);
|
|
460
|
+
}
|
|
461
|
+
return slots;
|
|
462
|
+
}
|
|
463
|
+
function unionSorted(left, right) {
|
|
464
|
+
return Array.from(/* @__PURE__ */ new Set([...left, ...right])).sort();
|
|
465
|
+
}
|
|
466
|
+
function expandVisitSchedule(config) {
|
|
467
|
+
const weekendHours = config.weekend ?? (config.saturday || config.sunday ? config.weekday : null);
|
|
468
|
+
const weekdayTimeSlots = expandVisitTimeSlots(config.weekday);
|
|
469
|
+
const weekendTimeSlots = weekendHours ? expandVisitTimeSlots(weekendHours) : [];
|
|
470
|
+
const disabledDays = [];
|
|
471
|
+
if (!config.sunday) disabledDays.push(0);
|
|
472
|
+
if (!config.saturday) disabledDays.push(6);
|
|
473
|
+
return {
|
|
474
|
+
...config,
|
|
475
|
+
weekend: weekendHours,
|
|
476
|
+
disabledDays,
|
|
477
|
+
weekdayTimeSlots,
|
|
478
|
+
weekendTimeSlots,
|
|
479
|
+
timeSlots: unionSorted(weekdayTimeSlots, weekendTimeSlots)
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
var STUDIO_DEFAULT_VISIT_SCHEDULE = expandVisitSchedule(
|
|
483
|
+
{
|
|
484
|
+
timeZone: VISIT_TIME_ZONE,
|
|
485
|
+
saturday: false,
|
|
486
|
+
sunday: false,
|
|
487
|
+
weekday: { start: "06:00", end: "22:00" },
|
|
488
|
+
weekend: null,
|
|
489
|
+
minHoursAhead: 2
|
|
490
|
+
}
|
|
491
|
+
);
|
|
492
|
+
function zonedParts(date, timeZone) {
|
|
493
|
+
const parts = new Intl.DateTimeFormat("en-US", {
|
|
494
|
+
timeZone,
|
|
495
|
+
weekday: "short",
|
|
496
|
+
year: "numeric",
|
|
497
|
+
month: "2-digit",
|
|
498
|
+
day: "2-digit",
|
|
499
|
+
hour: "2-digit",
|
|
500
|
+
minute: "2-digit",
|
|
501
|
+
hourCycle: "h23"
|
|
502
|
+
}).formatToParts(date);
|
|
503
|
+
const get = (type) => parts.find((part) => part.type === type)?.value ?? "";
|
|
504
|
+
const weekday = WEEKDAY_SHORT[get("weekday")] ?? 0;
|
|
505
|
+
return {
|
|
506
|
+
year: Number(get("year")),
|
|
507
|
+
month: Number(get("month")),
|
|
508
|
+
day: Number(get("day")),
|
|
509
|
+
hour: Number(get("hour")),
|
|
510
|
+
minute: Number(get("minute")),
|
|
511
|
+
weekday
|
|
512
|
+
};
|
|
513
|
+
}
|
|
514
|
+
function calendarYmd(date, timeZone) {
|
|
515
|
+
const parts = zonedParts(date, timeZone);
|
|
516
|
+
return `${parts.year}-${pad2(parts.month)}-${pad2(parts.day)}`;
|
|
517
|
+
}
|
|
518
|
+
function parseYmd(value) {
|
|
519
|
+
const match = YMD_RE.exec(value);
|
|
520
|
+
if (!match) return null;
|
|
521
|
+
const year = Number(match[1]);
|
|
522
|
+
const month = Number(match[2]);
|
|
523
|
+
const day = Number(match[3]);
|
|
524
|
+
const utc = new Date(Date.UTC(year, month - 1, day));
|
|
525
|
+
if (utc.getUTCFullYear() !== year || utc.getUTCMonth() !== month - 1 || utc.getUTCDate() !== day) {
|
|
526
|
+
return null;
|
|
527
|
+
}
|
|
528
|
+
return { year, month, day };
|
|
529
|
+
}
|
|
530
|
+
function normalizeVisitDate(date, timeZone = VISIT_TIME_ZONE) {
|
|
531
|
+
if (typeof date === "string") {
|
|
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;
|
|
536
|
+
}
|
|
537
|
+
if (date instanceof Date && Number.isFinite(date.getTime())) {
|
|
538
|
+
return calendarYmd(date, timeZone);
|
|
539
|
+
}
|
|
540
|
+
return null;
|
|
541
|
+
}
|
|
542
|
+
function weekdayOfYmd(ymd, timeZone) {
|
|
543
|
+
const parsed = parseYmd(ymd);
|
|
544
|
+
if (!parsed) return null;
|
|
545
|
+
const utcNoonish = new Date(
|
|
546
|
+
Date.UTC(parsed.year, parsed.month - 1, parsed.day, 15, 0, 0)
|
|
547
|
+
);
|
|
548
|
+
return zonedParts(utcNoonish, timeZone).weekday;
|
|
549
|
+
}
|
|
550
|
+
function slotsForDate(schedule, date, now = /* @__PURE__ */ new Date()) {
|
|
551
|
+
const timeZone = schedule.timeZone;
|
|
552
|
+
const ymd = normalizeVisitDate(date, timeZone);
|
|
553
|
+
if (!ymd) return [];
|
|
554
|
+
const weekday = weekdayOfYmd(ymd, timeZone);
|
|
555
|
+
if (weekday == null) return [];
|
|
556
|
+
if (weekday === 0 && !schedule.sunday) return [];
|
|
557
|
+
if (weekday === 6 && !schedule.saturday) return [];
|
|
558
|
+
const base = weekday === 0 || weekday === 6 ? schedule.weekendTimeSlots : schedule.weekdayTimeSlots;
|
|
559
|
+
const today = calendarYmd(now, timeZone);
|
|
560
|
+
if (ymd < today) return [];
|
|
561
|
+
if (ymd !== today) return [...base];
|
|
562
|
+
const nowParts = zonedParts(now, timeZone);
|
|
563
|
+
const cutoff = nowParts.hour * 60 + nowParts.minute + schedule.minHoursAhead * 60;
|
|
564
|
+
return base.filter((slot) => {
|
|
565
|
+
const minutes = minutesOfDay(slot);
|
|
566
|
+
return minutes != null && minutes >= cutoff;
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
function isVisitSlotAllowed(schedule, visitDate, visitTime, now = /* @__PURE__ */ new Date()) {
|
|
570
|
+
return slotsForDate(schedule, visitDate, now).includes(visitTime);
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
// src/leads.ts
|
|
574
|
+
var LeadSubmitError = class extends Error {
|
|
575
|
+
code;
|
|
576
|
+
status;
|
|
577
|
+
retryAfterSeconds;
|
|
578
|
+
constructor(message, info) {
|
|
579
|
+
super(message);
|
|
580
|
+
this.name = "LeadSubmitError";
|
|
581
|
+
this.code = info.code;
|
|
582
|
+
if (info.status != null) this.status = info.status;
|
|
583
|
+
if (info.retryAfterSeconds != null) {
|
|
584
|
+
this.retryAfterSeconds = info.retryAfterSeconds;
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
};
|
|
588
|
+
var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
589
|
+
var EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
590
|
+
var MESSAGE_MAX = 2e3;
|
|
591
|
+
var CONTACT_FIELDS = [
|
|
592
|
+
{ id: "name", required: true },
|
|
593
|
+
{ id: "email", required: false },
|
|
594
|
+
{ id: "phone", required: false },
|
|
595
|
+
{ id: "message", required: false }
|
|
596
|
+
];
|
|
597
|
+
function studioDefaultLeadUi() {
|
|
598
|
+
return {
|
|
599
|
+
defaultVariant: "visit",
|
|
600
|
+
timeZone: "America/Sao_Paulo",
|
|
601
|
+
variants: {
|
|
602
|
+
visit: {
|
|
603
|
+
ctaLabel: "Agendar visita",
|
|
604
|
+
requireDateTime: true,
|
|
605
|
+
schedule: STUDIO_DEFAULT_VISIT_SCHEDULE,
|
|
606
|
+
fields: CONTACT_FIELDS
|
|
607
|
+
},
|
|
608
|
+
contact: {
|
|
609
|
+
ctaLabel: "Fale conosco",
|
|
610
|
+
requireDateTime: false,
|
|
611
|
+
whatsappPhone: null,
|
|
612
|
+
fields: CONTACT_FIELDS
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
};
|
|
616
|
+
}
|
|
617
|
+
async function getLeadUi(options) {
|
|
618
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
619
|
+
const url = `${normalizeBaseUrl(options.baseUrl)}/api/sites/${encodeURIComponent(siteId)}/leads/ui`;
|
|
620
|
+
return callJson(
|
|
621
|
+
url,
|
|
622
|
+
{
|
|
623
|
+
method: "GET",
|
|
624
|
+
headers: { Accept: "application/json" },
|
|
625
|
+
next: options.next
|
|
626
|
+
},
|
|
627
|
+
options.fetch ?? fetch
|
|
628
|
+
);
|
|
629
|
+
}
|
|
630
|
+
function assertListingId(listingId) {
|
|
631
|
+
if (!UUID_RE.test(listingId.trim())) {
|
|
632
|
+
throw new LeadSubmitError(
|
|
633
|
+
"Garagem SDK: listingId must be the listing UUID, not a path or code.",
|
|
634
|
+
{ code: "invalid_listing_id" }
|
|
635
|
+
);
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
function normalizeContact(input) {
|
|
639
|
+
const name = input.name.trim();
|
|
640
|
+
if (name.length < 2 || name.length > 200) {
|
|
641
|
+
throw new LeadSubmitError("Garagem SDK: name is required.", {
|
|
642
|
+
code: "invalid_contact"
|
|
643
|
+
});
|
|
644
|
+
}
|
|
645
|
+
const email = input.email?.trim() || void 0;
|
|
646
|
+
const phone = input.phone?.trim() || void 0;
|
|
647
|
+
if (!email && !phone) {
|
|
648
|
+
throw new LeadSubmitError("Garagem SDK: email and/or phone is required.", {
|
|
649
|
+
code: "invalid_contact"
|
|
650
|
+
});
|
|
651
|
+
}
|
|
652
|
+
if (email && !EMAIL_RE.test(email)) {
|
|
653
|
+
throw new LeadSubmitError("Garagem SDK: email is invalid.", {
|
|
654
|
+
code: "invalid_contact"
|
|
655
|
+
});
|
|
656
|
+
}
|
|
657
|
+
if (phone && (phone.length < 5 || phone.length > 40)) {
|
|
658
|
+
throw new LeadSubmitError("Garagem SDK: phone is invalid.", {
|
|
659
|
+
code: "invalid_contact"
|
|
660
|
+
});
|
|
661
|
+
}
|
|
662
|
+
const message = input.message?.trim() || void 0;
|
|
663
|
+
if (message && message.length > MESSAGE_MAX) {
|
|
664
|
+
throw new LeadSubmitError("Garagem SDK: message is too long.", {
|
|
665
|
+
code: "invalid_contact"
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
return {
|
|
669
|
+
name,
|
|
670
|
+
...email ? { email } : {},
|
|
671
|
+
...phone ? { phone } : {},
|
|
672
|
+
...message ? { message } : {}
|
|
673
|
+
};
|
|
674
|
+
}
|
|
675
|
+
async function postSiteLead(input) {
|
|
676
|
+
const siteId = await coerceSiteId(input.siteId);
|
|
677
|
+
const base = normalizeBaseUrl(input.baseUrl);
|
|
678
|
+
const url = `${base}/api/webhooks/sites/${encodeURIComponent(siteId)}/leads`;
|
|
679
|
+
const f = input.fetch ?? fetch;
|
|
680
|
+
let response;
|
|
681
|
+
try {
|
|
682
|
+
response = await f(url, {
|
|
683
|
+
method: "POST",
|
|
684
|
+
headers: {
|
|
685
|
+
Accept: "application/json",
|
|
686
|
+
"Content-Type": "application/json"
|
|
687
|
+
},
|
|
688
|
+
body: JSON.stringify(input.body)
|
|
689
|
+
});
|
|
690
|
+
} catch (error) {
|
|
691
|
+
throw new LeadSubmitError(
|
|
692
|
+
error instanceof Error ? error.message : "Garagem SDK: network error.",
|
|
693
|
+
{ code: "network" }
|
|
694
|
+
);
|
|
695
|
+
}
|
|
696
|
+
if (response.status === 202) {
|
|
697
|
+
const data = await response.json().catch(() => ({}));
|
|
698
|
+
const id = typeof data.id === "string" && data.id ? data.id : "";
|
|
699
|
+
return { ok: true, status: 202, id };
|
|
700
|
+
}
|
|
701
|
+
const retryAfter = Number(response.headers.get("Retry-After") ?? "");
|
|
702
|
+
if (response.status === 429) {
|
|
703
|
+
throw new LeadSubmitError("Garagem SDK: too many lead submissions.", {
|
|
704
|
+
code: "rate_limited",
|
|
705
|
+
status: 429,
|
|
706
|
+
retryAfterSeconds: Number.isFinite(retryAfter) ? retryAfter : void 0
|
|
707
|
+
});
|
|
708
|
+
}
|
|
709
|
+
if (response.status === 404) {
|
|
710
|
+
throw new LeadSubmitError("Garagem SDK: listing or site not found.", {
|
|
711
|
+
code: "not_found",
|
|
712
|
+
status: 404
|
|
713
|
+
});
|
|
714
|
+
}
|
|
715
|
+
throw new LeadSubmitError(
|
|
716
|
+
`Garagem SDK: lead submit failed (${response.status}).`,
|
|
717
|
+
{ code: "http", status: response.status }
|
|
718
|
+
);
|
|
719
|
+
}
|
|
720
|
+
function leadPostContext(input) {
|
|
721
|
+
assertListingId(input.listingId);
|
|
722
|
+
return {
|
|
723
|
+
listingId: input.listingId.trim(),
|
|
724
|
+
contact: normalizeContact(input),
|
|
725
|
+
extras: {
|
|
726
|
+
...input.visitorId ? { visitorId: input.visitorId } : {},
|
|
727
|
+
...input.brokerRef ? { brokerRef: input.brokerRef } : {},
|
|
728
|
+
...input.referrer ? { referrer: input.referrer } : {}
|
|
729
|
+
}
|
|
730
|
+
};
|
|
731
|
+
}
|
|
732
|
+
async function submitVisitLead(input) {
|
|
733
|
+
const prepared = leadPostContext(input);
|
|
734
|
+
const schedule = input.schedule ?? STUDIO_DEFAULT_VISIT_SCHEDULE;
|
|
735
|
+
const visitDate = normalizeVisitDate(input.visitDate, schedule.timeZone);
|
|
736
|
+
if (!visitDate || !isVisitSlotAllowed(schedule, visitDate, input.visitTime)) {
|
|
737
|
+
throw new LeadSubmitError(
|
|
738
|
+
"Garagem SDK: visitDate/visitTime is outside the published schedule.",
|
|
739
|
+
{ code: "invalid_slot" }
|
|
740
|
+
);
|
|
741
|
+
}
|
|
742
|
+
return postSiteLead({
|
|
743
|
+
siteId: input.siteId,
|
|
744
|
+
baseUrl: input.baseUrl,
|
|
745
|
+
fetch: input.fetch,
|
|
746
|
+
body: {
|
|
747
|
+
source: "site-sdk",
|
|
748
|
+
leadType: "visit",
|
|
749
|
+
...prepared.contact,
|
|
750
|
+
propertyId: prepared.listingId,
|
|
751
|
+
listingId: prepared.listingId,
|
|
752
|
+
visitDate,
|
|
753
|
+
visitTime: input.visitTime,
|
|
754
|
+
...prepared.extras
|
|
755
|
+
}
|
|
756
|
+
});
|
|
757
|
+
}
|
|
758
|
+
async function submitContactLead(input) {
|
|
759
|
+
const prepared = leadPostContext(input);
|
|
760
|
+
return postSiteLead({
|
|
761
|
+
siteId: input.siteId,
|
|
762
|
+
baseUrl: input.baseUrl,
|
|
763
|
+
fetch: input.fetch,
|
|
764
|
+
body: {
|
|
765
|
+
source: "site-sdk",
|
|
766
|
+
leadType: "contact",
|
|
767
|
+
...prepared.contact,
|
|
768
|
+
propertyId: prepared.listingId,
|
|
769
|
+
listingId: prepared.listingId,
|
|
770
|
+
...prepared.extras
|
|
771
|
+
}
|
|
772
|
+
});
|
|
773
|
+
}
|
|
774
|
+
|
|
410
775
|
// src/presentation.ts
|
|
411
776
|
var SEARCH_CSS_VARS = {
|
|
412
777
|
cardRadius: "--garagem-listing-card-radius",
|
|
@@ -1299,10 +1664,10 @@ var STUDIO_SDK_CONTRACT = {
|
|
|
1299
1664
|
/**
|
|
1300
1665
|
* Exact pin for generated Studio sites. Must be ≥ `selfInjectSince` so
|
|
1301
1666
|
* prompts that skip the layout chrome tag match the tarball v0 installs.
|
|
1302
|
-
* This PR’s changeset publishes that tarball as 0.4.
|
|
1667
|
+
* This PR’s changeset publishes that tarball as 0.4.3 — do not generate
|
|
1303
1668
|
* against this floor until Version Packages is on npm.
|
|
1304
1669
|
*/
|
|
1305
|
-
minNpmVersion: "0.4.
|
|
1670
|
+
minNpmVersion: "0.4.3",
|
|
1306
1671
|
/** First release where ListingCard and ResultsSkeleton inject the sheet. */
|
|
1307
1672
|
selfInjectSince: "0.4.2",
|
|
1308
1673
|
chromeStrategy: "self-inject",
|
|
@@ -1323,9 +1688,24 @@ var STUDIO_SDK_CONTRACT = {
|
|
|
1323
1688
|
SearchPageFallback: "0.4.1",
|
|
1324
1689
|
SearchChromeStyles: "0.4.1"
|
|
1325
1690
|
},
|
|
1326
|
-
forbiddenImports: ["@garagem-ai/site-sdk/react/search.css"]
|
|
1691
|
+
forbiddenImports: ["@garagem-ai/site-sdk/react/search.css"],
|
|
1692
|
+
leadStrategy: "visit-default",
|
|
1693
|
+
leadExports: [
|
|
1694
|
+
"getLeadUi",
|
|
1695
|
+
"submitVisitLead",
|
|
1696
|
+
"submitContactLead",
|
|
1697
|
+
"slotsForDate",
|
|
1698
|
+
"expandVisitSchedule",
|
|
1699
|
+
"expandVisitTimeSlots",
|
|
1700
|
+
"isVisitSlotAllowed",
|
|
1701
|
+
"STUDIO_DEFAULT_VISIT_SCHEDULE"
|
|
1702
|
+
]
|
|
1327
1703
|
};
|
|
1328
1704
|
var REACT_SDK_NAMED_IMPORT_RE = /(?:^|[\n;])\s*import\s+(?!type\b)(?:type\s+)?\{([^}]+)\}\s+from\s+['"]@garagem-ai\/site-sdk\/react['"]/g;
|
|
1705
|
+
var SHOWCASE_LEADS_POST_URL_RE = /\/api\/sites\/[^\s"']*\/leads(?!\/ui)/;
|
|
1706
|
+
function hasShowcaseLeadsPostUrl(text) {
|
|
1707
|
+
return SHOWCASE_LEADS_POST_URL_RE.test(text);
|
|
1708
|
+
}
|
|
1329
1709
|
function coerceNpmVersion(raw) {
|
|
1330
1710
|
if (typeof raw !== "string") return null;
|
|
1331
1711
|
const match = raw.trim().match(/(\d+)\.(\d+)\.(\d+)/);
|
|
@@ -1380,6 +1760,10 @@ function studioSdkPinInstruction() {
|
|
|
1380
1760
|
const names = STUDIO_SDK_CONTRACT.reactExports.join(", ");
|
|
1381
1761
|
return `In \`package.json\` set \`"@garagem-ai/site-sdk": "${version}"\` (exact). Import only these \`${STUDIO_SDK_PACKAGE}/react\` names: ${names}.`;
|
|
1382
1762
|
}
|
|
1763
|
+
function studioLeadInstruction() {
|
|
1764
|
+
const names = STUDIO_SDK_CONTRACT.leadExports.join(", ");
|
|
1765
|
+
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.`;
|
|
1766
|
+
}
|
|
1383
1767
|
function studioChromeInstruction() {
|
|
1384
1768
|
const injectors = compareSemver(
|
|
1385
1769
|
STUDIO_SDK_CONTRACT.minNpmVersion,
|
|
@@ -1399,6 +1783,12 @@ function studioCodegenContractViolations(text) {
|
|
|
1399
1783
|
violations.push(name);
|
|
1400
1784
|
}
|
|
1401
1785
|
}
|
|
1786
|
+
if (hasShowcaseLeadsPostUrl(text)) {
|
|
1787
|
+
violations.push("showcase-leads-url");
|
|
1788
|
+
}
|
|
1789
|
+
if (/\btype\s*=\s*["']date["']/.test(text)) {
|
|
1790
|
+
violations.push("native-date-input");
|
|
1791
|
+
}
|
|
1402
1792
|
return violations;
|
|
1403
1793
|
}
|
|
1404
1794
|
|
|
@@ -1530,6 +1920,30 @@ function createGaragemClient(options = {}) {
|
|
|
1530
1920
|
const merged = mergeNext(next);
|
|
1531
1921
|
if (merged !== void 0) opts.next = merged;
|
|
1532
1922
|
return getCmsEntry(opts);
|
|
1923
|
+
},
|
|
1924
|
+
async getLeadUi({ siteId, next } = {}) {
|
|
1925
|
+
const opts = withDefaults({
|
|
1926
|
+
siteId: resolveSiteId(siteId)
|
|
1927
|
+
});
|
|
1928
|
+
const merged = mergeNext(next);
|
|
1929
|
+
if (merged !== void 0) opts.next = merged;
|
|
1930
|
+
return getLeadUi(opts);
|
|
1931
|
+
},
|
|
1932
|
+
async submitVisitLead(args) {
|
|
1933
|
+
return submitVisitLead(
|
|
1934
|
+
withDefaults({
|
|
1935
|
+
...args,
|
|
1936
|
+
siteId: resolveSiteId(args.siteId)
|
|
1937
|
+
})
|
|
1938
|
+
);
|
|
1939
|
+
},
|
|
1940
|
+
async submitContactLead(args) {
|
|
1941
|
+
return submitContactLead(
|
|
1942
|
+
withDefaults({
|
|
1943
|
+
...args,
|
|
1944
|
+
siteId: resolveSiteId(args.siteId)
|
|
1945
|
+
})
|
|
1946
|
+
);
|
|
1533
1947
|
}
|
|
1534
1948
|
};
|
|
1535
1949
|
}
|
|
@@ -1537,12 +1951,15 @@ function createGaragemClient(options = {}) {
|
|
|
1537
1951
|
0 && (module.exports = {
|
|
1538
1952
|
FORBIDDEN_SEARCH_QUERY_KEYS,
|
|
1539
1953
|
GaragemSdkError,
|
|
1954
|
+
LeadSubmitError,
|
|
1540
1955
|
SEARCH_CSS_RECIPE,
|
|
1541
1956
|
SEARCH_CSS_VARS,
|
|
1542
1957
|
SEARCH_SORT_RELEVANCE,
|
|
1958
|
+
STUDIO_DEFAULT_VISIT_SCHEDULE,
|
|
1543
1959
|
STUDIO_SDK_CONTRACT,
|
|
1544
1960
|
STUDIO_SDK_PACKAGE,
|
|
1545
1961
|
TOOLBAR_PRIMARY_FILTER_IDS,
|
|
1962
|
+
VISIT_TIME_ZONE,
|
|
1546
1963
|
applyPathFilter,
|
|
1547
1964
|
buildQueryListingsParams,
|
|
1548
1965
|
canonicalizeSearchHref,
|
|
@@ -1555,6 +1972,8 @@ function createGaragemClient(options = {}) {
|
|
|
1555
1972
|
countOptionLabel,
|
|
1556
1973
|
createGaragemClient,
|
|
1557
1974
|
displayPathLocation,
|
|
1975
|
+
expandVisitSchedule,
|
|
1976
|
+
expandVisitTimeSlots,
|
|
1558
1977
|
formatAreaM2,
|
|
1559
1978
|
formatGroupedInteger,
|
|
1560
1979
|
formatListingPrice,
|
|
@@ -1562,21 +1981,25 @@ function createGaragemClient(options = {}) {
|
|
|
1562
1981
|
getCmsCollections,
|
|
1563
1982
|
getCmsEntries,
|
|
1564
1983
|
getCmsEntry,
|
|
1984
|
+
getLeadUi,
|
|
1565
1985
|
getListing,
|
|
1566
1986
|
getListings,
|
|
1567
1987
|
getSearchUi,
|
|
1568
1988
|
getSimilarListings,
|
|
1569
1989
|
getSite,
|
|
1990
|
+
hasShowcaseLeadsPostUrl,
|
|
1570
1991
|
hrefForAppliedChange,
|
|
1571
1992
|
hrefForPathFilters,
|
|
1572
1993
|
hrefWithExplicitPage,
|
|
1573
1994
|
isListingDetailPath,
|
|
1574
1995
|
isStudioPreviewHost,
|
|
1996
|
+
isVisitSlotAllowed,
|
|
1575
1997
|
listingBusinessLabel,
|
|
1576
1998
|
listingLocationLabel,
|
|
1577
1999
|
listingLookupKey,
|
|
1578
2000
|
listingPublicPath,
|
|
1579
2001
|
mergeAppliedSearchQueryIntoSearch,
|
|
2002
|
+
normalizeVisitDate,
|
|
1580
2003
|
paginationPages,
|
|
1581
2004
|
parseAppliedSearchQuery,
|
|
1582
2005
|
parseGroupedInteger,
|
|
@@ -1596,9 +2019,14 @@ function createGaragemClient(options = {}) {
|
|
|
1596
2019
|
searchResultsHeading,
|
|
1597
2020
|
searchSortOptions,
|
|
1598
2021
|
serializeAppliedSearchQuery,
|
|
2022
|
+
slotsForDate,
|
|
1599
2023
|
studioChromeInstruction,
|
|
1600
2024
|
studioCodegenContractViolations,
|
|
2025
|
+
studioDefaultLeadUi,
|
|
2026
|
+
studioLeadInstruction,
|
|
1601
2027
|
studioSdkPinInstruction,
|
|
2028
|
+
submitContactLead,
|
|
2029
|
+
submitVisitLead,
|
|
1602
2030
|
toListingCardModel,
|
|
1603
2031
|
toolbarFilterIds,
|
|
1604
2032
|
unavailableReactImports,
|