@garagem-ai/site-sdk 0.4.3 → 0.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -16
- package/dist/index.d.mts +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.js +12 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +11 -5
- package/dist/index.mjs.map +1 -1
- package/dist/react.js +1 -1
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +1 -1
- package/dist/react.mjs.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/leads.ts +5 -3
- package/src/react/styles/search-chrome-css.generated.ts +1 -1
- package/src/schedule.ts +15 -5
package/dist/index.mjs
CHANGED
|
@@ -318,6 +318,7 @@ async function getCmsEntry(options) {
|
|
|
318
318
|
var VISIT_TIME_ZONE = "America/Sao_Paulo";
|
|
319
319
|
var HHMM_RE = /^([01]\d|2[0-3]):([0-5]\d)$/;
|
|
320
320
|
var YMD_RE = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
321
|
+
var ISO_INSTANT_RE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/;
|
|
321
322
|
var WEEKDAY_SHORT = {
|
|
322
323
|
Sun: 0,
|
|
323
324
|
Mon: 1,
|
|
@@ -419,9 +420,12 @@ function parseYmd(value) {
|
|
|
419
420
|
}
|
|
420
421
|
return { year, month, day };
|
|
421
422
|
}
|
|
422
|
-
function
|
|
423
|
+
function normalizeVisitDate(date, timeZone = VISIT_TIME_ZONE) {
|
|
423
424
|
if (typeof date === "string") {
|
|
424
|
-
|
|
425
|
+
if (parseYmd(date)) return date;
|
|
426
|
+
if (!ISO_INSTANT_RE.test(date)) return null;
|
|
427
|
+
const instant = new Date(date);
|
|
428
|
+
return Number.isFinite(instant.getTime()) ? calendarYmd(instant, timeZone) : null;
|
|
425
429
|
}
|
|
426
430
|
if (date instanceof Date && Number.isFinite(date.getTime())) {
|
|
427
431
|
return calendarYmd(date, timeZone);
|
|
@@ -438,7 +442,7 @@ function weekdayOfYmd(ymd, timeZone) {
|
|
|
438
442
|
}
|
|
439
443
|
function slotsForDate(schedule, date, now = /* @__PURE__ */ new Date()) {
|
|
440
444
|
const timeZone = schedule.timeZone;
|
|
441
|
-
const ymd =
|
|
445
|
+
const ymd = normalizeVisitDate(date, timeZone);
|
|
442
446
|
if (!ymd) return [];
|
|
443
447
|
const weekday = weekdayOfYmd(ymd, timeZone);
|
|
444
448
|
if (weekday == null) return [];
|
|
@@ -621,7 +625,8 @@ function leadPostContext(input) {
|
|
|
621
625
|
async function submitVisitLead(input) {
|
|
622
626
|
const prepared = leadPostContext(input);
|
|
623
627
|
const schedule = input.schedule ?? STUDIO_DEFAULT_VISIT_SCHEDULE;
|
|
624
|
-
|
|
628
|
+
const visitDate = normalizeVisitDate(input.visitDate, schedule.timeZone);
|
|
629
|
+
if (!visitDate || !isVisitSlotAllowed(schedule, visitDate, input.visitTime)) {
|
|
625
630
|
throw new LeadSubmitError(
|
|
626
631
|
"Garagem SDK: visitDate/visitTime is outside the published schedule.",
|
|
627
632
|
{ code: "invalid_slot" }
|
|
@@ -637,7 +642,7 @@ async function submitVisitLead(input) {
|
|
|
637
642
|
...prepared.contact,
|
|
638
643
|
propertyId: prepared.listingId,
|
|
639
644
|
listingId: prepared.listingId,
|
|
640
|
-
visitDate
|
|
645
|
+
visitDate,
|
|
641
646
|
visitTime: input.visitTime,
|
|
642
647
|
...prepared.extras
|
|
643
648
|
}
|
|
@@ -1886,6 +1891,7 @@ export {
|
|
|
1886
1891
|
listingLookupKey,
|
|
1887
1892
|
listingPublicPath,
|
|
1888
1893
|
mergeAppliedSearchQueryIntoSearch2 as mergeAppliedSearchQueryIntoSearch,
|
|
1894
|
+
normalizeVisitDate,
|
|
1889
1895
|
paginationPages,
|
|
1890
1896
|
parseAppliedSearchQuery2 as parseAppliedSearchQuery,
|
|
1891
1897
|
parseGroupedInteger,
|