@garagem-ai/site-sdk 0.4.5 → 0.4.7

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,10 @@ 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.7 lets SearchPage fill the site wrapper (`as="div"`) with no
1594
+ * nested 80rem inset and no padding on the search slot.
1581
1595
  */
1582
- minNpmVersion: "0.4.3",
1596
+ minNpmVersion: "0.4.7",
1583
1597
  /** First release where ListingCard and ResultsSkeleton inject the sheet. */
1584
1598
  selfInjectSince: "0.4.2",
1585
1599
  chromeStrategy: "self-inject",
@@ -1613,6 +1627,31 @@ var STUDIO_SDK_CONTRACT = {
1613
1627
  "STUDIO_DEFAULT_VISIT_SCHEDULE"
1614
1628
  ]
1615
1629
  };
1630
+ var STUDIO_SITE_LAYOUT = {
1631
+ maxWidthRem: "80rem",
1632
+ maxWidthRemOptions: ["64rem", "80rem", "120rem", "160rem", "240rem"],
1633
+ surfaceClassName: "w-full",
1634
+ wrapperClassName: "mx-auto w-full max-w-site px-4"
1635
+ };
1636
+ function studioSiteWidthCss() {
1637
+ return `:root {
1638
+ --site-max-width: ${STUDIO_SITE_LAYOUT.maxWidthRem};
1639
+ }
1640
+ .max-w-site {
1641
+ max-width: var(--site-max-width);
1642
+ }`;
1643
+ }
1644
+ function studioLayoutInstruction() {
1645
+ const scale = STUDIO_SITE_LAYOUT.maxWidthRemOptions.join(", ");
1646
+ return `Content width (hard rule). In \`app/globals.css\` keep brand tokens and add:
1647
+ \`\`\`css
1648
+ ${studioSiteWidthCss()}
1649
+ \`\`\`
1650
+ Every page section is two layers: (1) surface \u2014 \`section\` / header / footer \`${STUDIO_SITE_LAYOUT.surfaceClassName}\`, background to the viewport edges, no max-width class and no horizontal padding; (2) wrapper \u2014 one child \`${STUDIO_SITE_LAYOUT.wrapperClassName}\`. Header and footer use that same inner wrapper. Components fill the wrapper (\`w-full\`). Never nest a second max-width container with extra horizontal padding. ${studioSearchLandmarkInstruction()} Do not use \`ml-auto\` on the content wrapper. To make the site narrower or wider, change ONLY \`--site-max-width\` in \`app/globals.css\` (allowed: ${scale}; default ${STUDIO_SITE_LAYOUT.maxWidthRem}). Do not edit wrapper class names, padding, or per-page containers.`;
1651
+ }
1652
+ function studioSearchLandmarkInstruction() {
1653
+ return `Search at \`/imoveis\` (hard rule). The page landmark is \`<main className="${STUDIO_SITE_LAYOUT.surfaceClassName}">\` with one child \`${STUDIO_SITE_LAYOUT.wrapperClassName}\`. Pass \`as="div"\` to \`SearchPage\` so it is not a second main. Do not wrap \`SearchPage\` in \`<section>\`. The wrapper has no extra vertical padding class.`;
1654
+ }
1616
1655
  var REACT_SDK_NAMED_IMPORT_RE = /(?:^|[\n;])\s*import\s+(?!type\b)(?:type\s+)?\{([^}]+)\}\s+from\s+['"]@garagem-ai\/site-sdk\/react['"]/g;
1617
1656
  var SHOWCASE_LEADS_POST_URL_RE = /\/api\/sites\/[^\s"']*\/leads(?!\/ui)/;
1618
1657
  function hasShowcaseLeadsPostUrl(text) {
@@ -1681,7 +1720,7 @@ function studioChromeInstruction() {
1681
1720
  STUDIO_SDK_CONTRACT.minNpmVersion,
1682
1721
  STUDIO_SDK_CONTRACT.selfInjectSince
1683
1722
  ) >= 0 ? "`SearchPage`, `ListingCard`, and `ResultsSkeleton`" : "`SearchPage`";
1684
- 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\`.`;
1723
+ 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 card/toolbar layout into the app. Theme via CSS variables in \`app/globals.css\` (\`SEARCH_CSS_RECIPE\` / \`--garagem-*\`), \`classNames\`, and \`data-slot\`.`;
1685
1724
  }
1686
1725
  function studioCodegenContractViolations(text) {
1687
1726
  const violations = [];
@@ -1869,6 +1908,7 @@ export {
1869
1908
  STUDIO_DEFAULT_VISIT_SCHEDULE,
1870
1909
  STUDIO_SDK_CONTRACT,
1871
1910
  STUDIO_SDK_PACKAGE,
1911
+ STUDIO_SITE_LAYOUT,
1872
1912
  TOOLBAR_PRIMARY_FILTER_IDS,
1873
1913
  VISIT_TIME_ZONE,
1874
1914
  applyPathFilter,
@@ -1911,6 +1951,7 @@ export {
1911
1951
  listingPublicPath,
1912
1952
  mergeAppliedSearchQueryIntoSearch2 as mergeAppliedSearchQueryIntoSearch,
1913
1953
  normalizeVisitDate,
1954
+ normalizeVisitTime,
1914
1955
  paginationPages,
1915
1956
  parseAppliedSearchQuery2 as parseAppliedSearchQuery,
1916
1957
  parseGroupedInteger,
@@ -1934,8 +1975,11 @@ export {
1934
1975
  studioChromeInstruction,
1935
1976
  studioCodegenContractViolations,
1936
1977
  studioDefaultLeadUi,
1978
+ studioLayoutInstruction,
1937
1979
  studioLeadInstruction,
1938
1980
  studioSdkPinInstruction,
1981
+ studioSearchLandmarkInstruction,
1982
+ studioSiteWidthCss,
1939
1983
  submitContactLead,
1940
1984
  submitVisitLead,
1941
1985
  toListingCardModel,