@garagem-ai/site-sdk 0.4.5 → 0.4.6

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/dist/index.mjs CHANGED
@@ -318,8 +318,10 @@ async function getCmsEntry(options) {
318
318
  // src/schedule.ts
319
319
  var VISIT_TIME_ZONE = "America/Sao_Paulo";
320
320
  var HHMM_RE = /^([01]\d|2[0-3]):([0-5]\d)$/;
321
+ var VISIT_TIME_RE = /^([01]\d|2[0-3]):([0-5]\d)(?::[0-5]\d(?:\.\d+)?)?$/;
321
322
  var YMD_RE = /^(\d{4})-(\d{2})-(\d{2})$/;
322
323
  var ISO_INSTANT_RE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/;
324
+ var DATETIME_LOCAL_RE = /^(\d{4}-\d{2}-\d{2})T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?$/;
323
325
  var WEEKDAY_SHORT = {
324
326
  Sun: 0,
325
327
  Mon: 1,
@@ -342,6 +344,10 @@ function minutesOfDay(hhmm) {
342
344
  if (!parsed) return null;
343
345
  return parsed.hour * 60 + parsed.minute;
344
346
  }
347
+ function normalizeVisitTime(value) {
348
+ const match = VISIT_TIME_RE.exec(value.trim());
349
+ return match ? `${match[1]}:${match[2]}` : null;
350
+ }
345
351
  function expandVisitTimeSlots(hours) {
346
352
  const start = minutesOfDay(hours.start);
347
353
  const end = minutesOfDay(hours.end);
@@ -423,10 +429,15 @@ function parseYmd(value) {
423
429
  }
424
430
  function normalizeVisitDate(date, timeZone = VISIT_TIME_ZONE) {
425
431
  if (typeof date === "string") {
426
- if (parseYmd(date)) return date;
427
- if (!ISO_INSTANT_RE.test(date)) return null;
428
- const instant = new Date(date);
429
- return Number.isFinite(instant.getTime()) ? calendarYmd(instant, timeZone) : null;
432
+ const trimmed = date.trim();
433
+ if (parseYmd(trimmed)) return trimmed;
434
+ if (ISO_INSTANT_RE.test(trimmed)) {
435
+ const instant = new Date(trimmed);
436
+ return Number.isFinite(instant.getTime()) ? calendarYmd(instant, timeZone) : null;
437
+ }
438
+ const local = DATETIME_LOCAL_RE.exec(trimmed);
439
+ if (local && parseYmd(local[1])) return local[1];
440
+ return null;
430
441
  }
431
442
  if (date instanceof Date && Number.isFinite(date.getTime())) {
432
443
  return calendarYmd(date, timeZone);
@@ -462,7 +473,9 @@ function slotsForDate(schedule, date, now = /* @__PURE__ */ new Date()) {
462
473
  });
463
474
  }
464
475
  function isVisitSlotAllowed(schedule, visitDate, visitTime, now = /* @__PURE__ */ new Date()) {
465
- return slotsForDate(schedule, visitDate, now).includes(visitTime);
476
+ const time = normalizeVisitTime(visitTime);
477
+ if (!time) return false;
478
+ return slotsForDate(schedule, visitDate, now).includes(time);
466
479
  }
467
480
 
468
481
  // src/resolve-site-id.ts
@@ -677,7 +690,8 @@ async function submitVisitLead(input) {
677
690
  const prepared = leadPostContext(input);
678
691
  const schedule = input.schedule ?? STUDIO_DEFAULT_VISIT_SCHEDULE;
679
692
  const visitDate = normalizeVisitDate(input.visitDate, schedule.timeZone);
680
- if (!visitDate || !isVisitSlotAllowed(schedule, visitDate, input.visitTime)) {
693
+ const visitTime = normalizeVisitTime(input.visitTime);
694
+ if (!visitDate || !visitTime || !isVisitSlotAllowed(schedule, visitDate, visitTime)) {
681
695
  throw new LeadSubmitError(
682
696
  "Garagem SDK: visitDate/visitTime is outside the published schedule.",
683
697
  { code: "invalid_slot" }
@@ -694,7 +708,7 @@ async function submitVisitLead(input) {
694
708
  propertyId: prepared.listingId,
695
709
  listingId: prepared.listingId,
696
710
  visitDate,
697
- visitTime: input.visitTime,
711
+ visitTime,
698
712
  ...prepared.extras
699
713
  }
700
714
  });
@@ -1576,10 +1590,9 @@ var STUDIO_SDK_CONTRACT = {
1576
1590
  /**
1577
1591
  * Exact pin for generated Studio sites. Must be ≥ `selfInjectSince` so
1578
1592
  * prompts that skip the layout chrome tag match the tarball v0 installs.
1579
- * This PR’s changeset publishes that tarball as 0.4.3 — do not generate
1580
- * against this floor until Version Packages is on npm.
1593
+ * 0.4.5 normalizes visit dates and recovers a missing browser siteId.
1581
1594
  */
1582
- minNpmVersion: "0.4.3",
1595
+ minNpmVersion: "0.4.5",
1583
1596
  /** First release where ListingCard and ResultsSkeleton inject the sheet. */
1584
1597
  selfInjectSince: "0.4.2",
1585
1598
  chromeStrategy: "self-inject",
@@ -1911,6 +1924,7 @@ export {
1911
1924
  listingPublicPath,
1912
1925
  mergeAppliedSearchQueryIntoSearch2 as mergeAppliedSearchQueryIntoSearch,
1913
1926
  normalizeVisitDate,
1927
+ normalizeVisitTime,
1914
1928
  paginationPages,
1915
1929
  parseAppliedSearchQuery2 as parseAppliedSearchQuery,
1916
1930
  parseGroupedInteger,