@garagem-ai/site-sdk 0.4.2 → 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 +5 -0
- package/dist/index.d.mts +128 -3
- package/dist/index.d.ts +128 -3
- package/dist/index.js +424 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +411 -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 +32 -0
- package/src/leads.ts +341 -0
- package/src/react/styles/search-chrome-css.generated.ts +1 -1
- package/src/schedule.ts +226 -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,16 +52,19 @@ __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,
|
|
@@ -81,9 +89,14 @@ __export(src_exports, {
|
|
|
81
89
|
searchResultsHeading: () => searchResultsHeading,
|
|
82
90
|
searchSortOptions: () => searchSortOptions,
|
|
83
91
|
serializeAppliedSearchQuery: () => serializeAppliedSearchQuery2,
|
|
92
|
+
slotsForDate: () => slotsForDate,
|
|
84
93
|
studioChromeInstruction: () => studioChromeInstruction,
|
|
85
94
|
studioCodegenContractViolations: () => studioCodegenContractViolations,
|
|
95
|
+
studioDefaultLeadUi: () => studioDefaultLeadUi,
|
|
96
|
+
studioLeadInstruction: () => studioLeadInstruction,
|
|
86
97
|
studioSdkPinInstruction: () => studioSdkPinInstruction,
|
|
98
|
+
submitContactLead: () => submitContactLead,
|
|
99
|
+
submitVisitLead: () => submitVisitLead,
|
|
87
100
|
toListingCardModel: () => toListingCardModel,
|
|
88
101
|
toolbarFilterIds: () => toolbarFilterIds,
|
|
89
102
|
unavailableReactImports: () => unavailableReactImports,
|
|
@@ -407,6 +420,352 @@ async function getCmsEntry(options) {
|
|
|
407
420
|
return data;
|
|
408
421
|
}
|
|
409
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
|
+
|
|
410
769
|
// src/presentation.ts
|
|
411
770
|
var SEARCH_CSS_VARS = {
|
|
412
771
|
cardRadius: "--garagem-listing-card-radius",
|
|
@@ -1299,10 +1658,10 @@ var STUDIO_SDK_CONTRACT = {
|
|
|
1299
1658
|
/**
|
|
1300
1659
|
* Exact pin for generated Studio sites. Must be ≥ `selfInjectSince` so
|
|
1301
1660
|
* prompts that skip the layout chrome tag match the tarball v0 installs.
|
|
1302
|
-
* This PR’s changeset publishes that tarball as 0.4.
|
|
1661
|
+
* This PR’s changeset publishes that tarball as 0.4.3 — do not generate
|
|
1303
1662
|
* against this floor until Version Packages is on npm.
|
|
1304
1663
|
*/
|
|
1305
|
-
minNpmVersion: "0.4.
|
|
1664
|
+
minNpmVersion: "0.4.3",
|
|
1306
1665
|
/** First release where ListingCard and ResultsSkeleton inject the sheet. */
|
|
1307
1666
|
selfInjectSince: "0.4.2",
|
|
1308
1667
|
chromeStrategy: "self-inject",
|
|
@@ -1323,9 +1682,24 @@ var STUDIO_SDK_CONTRACT = {
|
|
|
1323
1682
|
SearchPageFallback: "0.4.1",
|
|
1324
1683
|
SearchChromeStyles: "0.4.1"
|
|
1325
1684
|
},
|
|
1326
|
-
forbiddenImports: ["@garagem-ai/site-sdk/react/search.css"]
|
|
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
|
+
]
|
|
1327
1697
|
};
|
|
1328
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
|
+
}
|
|
1329
1703
|
function coerceNpmVersion(raw) {
|
|
1330
1704
|
if (typeof raw !== "string") return null;
|
|
1331
1705
|
const match = raw.trim().match(/(\d+)\.(\d+)\.(\d+)/);
|
|
@@ -1380,6 +1754,10 @@ function studioSdkPinInstruction() {
|
|
|
1380
1754
|
const names = STUDIO_SDK_CONTRACT.reactExports.join(", ");
|
|
1381
1755
|
return `In \`package.json\` set \`"@garagem-ai/site-sdk": "${version}"\` (exact). Import only these \`${STUDIO_SDK_PACKAGE}/react\` names: ${names}.`;
|
|
1382
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
|
+
}
|
|
1383
1761
|
function studioChromeInstruction() {
|
|
1384
1762
|
const injectors = compareSemver(
|
|
1385
1763
|
STUDIO_SDK_CONTRACT.minNpmVersion,
|
|
@@ -1399,6 +1777,12 @@ function studioCodegenContractViolations(text) {
|
|
|
1399
1777
|
violations.push(name);
|
|
1400
1778
|
}
|
|
1401
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
|
+
}
|
|
1402
1786
|
return violations;
|
|
1403
1787
|
}
|
|
1404
1788
|
|
|
@@ -1530,6 +1914,30 @@ function createGaragemClient(options = {}) {
|
|
|
1530
1914
|
const merged = mergeNext(next);
|
|
1531
1915
|
if (merged !== void 0) opts.next = merged;
|
|
1532
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
|
+
);
|
|
1533
1941
|
}
|
|
1534
1942
|
};
|
|
1535
1943
|
}
|
|
@@ -1537,12 +1945,15 @@ function createGaragemClient(options = {}) {
|
|
|
1537
1945
|
0 && (module.exports = {
|
|
1538
1946
|
FORBIDDEN_SEARCH_QUERY_KEYS,
|
|
1539
1947
|
GaragemSdkError,
|
|
1948
|
+
LeadSubmitError,
|
|
1540
1949
|
SEARCH_CSS_RECIPE,
|
|
1541
1950
|
SEARCH_CSS_VARS,
|
|
1542
1951
|
SEARCH_SORT_RELEVANCE,
|
|
1952
|
+
STUDIO_DEFAULT_VISIT_SCHEDULE,
|
|
1543
1953
|
STUDIO_SDK_CONTRACT,
|
|
1544
1954
|
STUDIO_SDK_PACKAGE,
|
|
1545
1955
|
TOOLBAR_PRIMARY_FILTER_IDS,
|
|
1956
|
+
VISIT_TIME_ZONE,
|
|
1546
1957
|
applyPathFilter,
|
|
1547
1958
|
buildQueryListingsParams,
|
|
1548
1959
|
canonicalizeSearchHref,
|
|
@@ -1555,6 +1966,8 @@ function createGaragemClient(options = {}) {
|
|
|
1555
1966
|
countOptionLabel,
|
|
1556
1967
|
createGaragemClient,
|
|
1557
1968
|
displayPathLocation,
|
|
1969
|
+
expandVisitSchedule,
|
|
1970
|
+
expandVisitTimeSlots,
|
|
1558
1971
|
formatAreaM2,
|
|
1559
1972
|
formatGroupedInteger,
|
|
1560
1973
|
formatListingPrice,
|
|
@@ -1562,16 +1975,19 @@ function createGaragemClient(options = {}) {
|
|
|
1562
1975
|
getCmsCollections,
|
|
1563
1976
|
getCmsEntries,
|
|
1564
1977
|
getCmsEntry,
|
|
1978
|
+
getLeadUi,
|
|
1565
1979
|
getListing,
|
|
1566
1980
|
getListings,
|
|
1567
1981
|
getSearchUi,
|
|
1568
1982
|
getSimilarListings,
|
|
1569
1983
|
getSite,
|
|
1984
|
+
hasShowcaseLeadsPostUrl,
|
|
1570
1985
|
hrefForAppliedChange,
|
|
1571
1986
|
hrefForPathFilters,
|
|
1572
1987
|
hrefWithExplicitPage,
|
|
1573
1988
|
isListingDetailPath,
|
|
1574
1989
|
isStudioPreviewHost,
|
|
1990
|
+
isVisitSlotAllowed,
|
|
1575
1991
|
listingBusinessLabel,
|
|
1576
1992
|
listingLocationLabel,
|
|
1577
1993
|
listingLookupKey,
|
|
@@ -1596,9 +2012,14 @@ function createGaragemClient(options = {}) {
|
|
|
1596
2012
|
searchResultsHeading,
|
|
1597
2013
|
searchSortOptions,
|
|
1598
2014
|
serializeAppliedSearchQuery,
|
|
2015
|
+
slotsForDate,
|
|
1599
2016
|
studioChromeInstruction,
|
|
1600
2017
|
studioCodegenContractViolations,
|
|
2018
|
+
studioDefaultLeadUi,
|
|
2019
|
+
studioLeadInstruction,
|
|
1601
2020
|
studioSdkPinInstruction,
|
|
2021
|
+
submitContactLead,
|
|
2022
|
+
submitVisitLead,
|
|
1602
2023
|
toListingCardModel,
|
|
1603
2024
|
toolbarFilterIds,
|
|
1604
2025
|
unavailableReactImports,
|