@garagem-ai/site-sdk 0.4.1 → 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 +26 -34
- package/dist/index.d.mts +176 -1
- package/dist/index.d.ts +176 -1
- package/dist/index.js +549 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +527 -0
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.mts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +212 -179
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +155 -122
- 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 +45 -0
- package/src/leads.ts +341 -0
- package/src/react/listing-card.tsx +64 -52
- package/src/react/search-chrome.tsx +14 -12
- package/src/react/styles/search-chrome-css.generated.ts +1 -1
- package/src/react/styles/search-chrome-styles.tsx +22 -3
- package/src/schedule.ts +226 -0
- package/src/studio-contract.ts +168 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* Generated by scripts/build-search-chrome-css.mjs — do not edit. */
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
/* prettier-ignore */
|
|
4
|
-
export const SEARCH_CHROME_CSS_VERSION = "0.4.
|
|
4
|
+
export const SEARCH_CHROME_CSS_VERSION = "0.4.3";
|
|
5
5
|
export const SEARCH_CHROME_CSS = ":root{--garagem-listing-card-radius:0.75rem;--garagem-listing-card-gap:1.5rem;--garagem-listing-price-size:1.125rem;--garagem-listing-media-ratio:4 / 3;--garagem-search-control-height:2.75rem;--garagem-search-icon-size:1.25rem;--garagem-search-radius:var(--radius,0.75rem);--garagem-skeleton:var(--muted,#e7e5e4)}[data-slot=\"search-page\"]{margin-inline:auto;max-width:80rem;padding:3rem 1.5rem}[data-slot=\"search-heading\"]{display:flex;min-width:0;align-items:baseline;gap:0.375rem;font-size:1.25rem;font-weight:600}[data-slot=\"search-heading-count\"]{flex-shrink:0}[data-slot=\"search-heading-title\"]{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:inherit;font-weight:inherit}[data-slot=\"search-query-sort\"]{display:flex;flex-direction:column;gap:1rem}@media (min-width:1024px){[data-slot=\"search-query-sort\"]{flex-direction:row;align-items:flex-end}}[data-slot=\"search-query\"]{flex:1;min-width:0}[data-slot=\"search-query-input\"],[data-slot=\"search-sort-trigger\"],[data-slot=\"search-toolbar-trigger\"],[data-slot=\"search-filters-trigger\"]{min-height:var(--garagem-search-control-height)}[data-slot=\"search-query-field\"]{position:relative}[data-slot=\"search-query-input\"]{width:100%;border-radius:var(--garagem-search-radius);border:1px solid var(--border,#e4e4e7);background:var(--background,#fff);padding:0.5rem 5.5rem 0.5rem 1rem;outline:none}[data-slot=\"search-query-actions\"]{position:absolute;top:50%;right:0.35rem;display:flex;transform:translateY(-50%);align-items:center;gap:0.15rem}[data-slot=\"search-icon-button\"]{display:inline-flex;height:2.25rem;width:2.25rem;cursor:pointer;align-items:center;justify-content:center;border:0;border-radius:999px;background:var(--primary,#111);color:var(--primary-foreground,#fff)}[data-slot=\"search-icon-button\"][data-kind=\"clear\"]{background:transparent;color:var(--muted-foreground,#737373)}[data-slot=\"search-icon\"]{width:var(--garagem-search-icon-size);height:var(--garagem-search-icon-size);display:block}[data-slot=\"search-sort\"]{display:flex;flex-direction:column;gap:0.25rem}[data-slot=\"search-sort-trigger\"]{appearance:none;cursor:pointer;border-radius:var(--garagem-search-radius);border:1px solid var(--border,#e4e4e7);background:var(--background,#fff);padding:0.5rem 2.25rem 0.5rem 0.75rem;background-image:url(\"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%23737373' stroke-width='2' viewBox='0 0 24 24'><path d='m6 9 6 6 6-6'/></svg>\");background-repeat:no-repeat;background-position:right 0.65rem center}[data-slot=\"search-toolbar\"]{display:flex;flex-wrap:wrap;align-items:flex-end;gap:0.5rem}[data-slot=\"search-toolbar-trigger\"],[data-slot=\"search-filters-trigger\"]{cursor:pointer;border-radius:var(--garagem-search-radius);border:1px solid var(--border,#e4e4e7);background:var(--background,#fff);padding:0.5rem 0.75rem;font-size:0.875rem}[data-slot=\"search-popover\"]{position:absolute;z-index:30;margin-top:0.5rem;width:18rem;border-radius:0.75rem;border:1px solid var(--border,#e4e4e7);background:var(--background,#fff);padding:1rem;box-shadow:0 10px 30px rgb(0 0 0 / 0.12);animation:garagem-search-in 140ms ease-out}[data-slot=\"search-grid\"],[data-slot=\"search-skeleton\"]{display:grid;grid-template-columns:1fr;gap:var(--garagem-listing-card-gap)}@media (min-width:640px){[data-slot=\"search-grid\"],[data-slot=\"search-skeleton\"]{grid-template-columns:repeat(2,minmax(0,1fr))}}@media (min-width:1024px){[data-slot=\"search-grid\"],[data-slot=\"search-skeleton\"]{grid-template-columns:repeat(3,minmax(0,1fr))}}[data-slot=\"listing-card\"]{overflow:hidden;border-radius:var(--garagem-listing-card-radius);border:1px solid var(--border,#e4e4e7);background:var(--card,var(--background,#fff))}[data-slot=\"listing-card-price-row\"]{display:inline-flex;align-items:baseline;gap:0.25rem}[data-slot=\"listing-card-price\"]{font-size:var(--garagem-listing-price-size);font-weight:600}[data-slot=\"listing-card-period\"]{font-size:0.75rem;color:var(--muted-foreground,#737373)}[data-slot=\"search-checkbox\"]{appearance:none;width:1.15rem;height:1.15rem;flex-shrink:0;cursor:pointer;border:1px solid var(--primary,#111);border-radius:0.25rem;background:var(--background,#fff)}[data-slot=\"search-checkbox\"]:checked{background-color:var(--primary,#111);background-image:url(\"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3'><path d='M5 12l5 5L20 7'/></svg>\");background-repeat:no-repeat;background-position:center;background-size:0.8rem}[data-slot=\"search-scroll\"]{max-height:12rem;overflow:auto;scrollbar-width:thin;scrollbar-color:var(--muted-foreground,#a1a1aa) transparent}[data-slot=\"search-range-apply\"]{display:inline-flex;min-height:2.5rem;cursor:pointer;align-items:center;justify-content:center;border:0;border-radius:var(--garagem-search-radius);background:var(--primary,#111);color:var(--primary-foreground,#fff);padding:0 0.75rem;font-size:0.75rem;font-weight:600}[data-slot=\"search-sheet\"]{position:fixed;inset:0;z-index:40}[data-slot=\"search-sheet-overlay\"]{position:absolute;inset:0;border:0;cursor:pointer;background:rgb(0 0 0 / 0.4);animation:garagem-search-fade 160ms ease-out}[data-slot=\"search-sheet-panel\"]{position:absolute;top:0;right:0;display:flex;height:100dvh;width:min(22rem,100%);flex-direction:column;background:var(--background,#fff);animation:garagem-search-sheet 180ms ease-out}[data-slot=\"search-sheet-body\"]{min-height:0;flex:1;overflow:auto;padding:1.5rem 1.5rem 0;scrollbar-width:thin}[data-slot=\"search-sheet-footer\"]{display:flex;gap:0.5rem;border-top:1px solid var(--border,#e4e4e7);padding:1rem 1.5rem}[data-slot=\"search-apply-bar\"]{display:flex;width:100%;gap:0.5rem}[data-slot=\"search-apply-bar\"] > button{min-height:2.5rem;flex:1;cursor:pointer;border-radius:var(--garagem-search-radius);padding:0 1rem}[data-slot=\"search-apply-bar\"] > button[data-kind=\"clear\"]{border:1px solid var(--border,#e4e4e7);background:transparent}[data-slot=\"search-apply-bar\"] > button[data-kind=\"apply\"]{border:0;background:var(--primary,#111);color:var(--primary-foreground,#fff);font-weight:600}[data-slot=\"search-pagination\"]{margin-top:2.5rem;display:flex;justify-content:center}[data-slot=\"search-pagination\"] ul{display:flex;flex-wrap:wrap;justify-content:center;gap:0.25rem;padding:0;margin:0;list-style:none}[data-slot=\"search-pagination-item\"]{display:inline-flex;width:2.25rem;height:2.25rem;align-items:center;justify-content:center;border:1px solid var(--border,#e4e4e7);border-radius:0.375rem;font-size:0.75rem;font-weight:500}@media (min-width:768px){[data-slot=\"search-pagination-item\"]{width:2.5rem;height:2.5rem}}[data-slot=\"search-pagination-item\"] a,[data-slot=\"search-pagination-item\"] span{display:flex;width:100%;height:100%;align-items:center;justify-content:center;color:inherit;text-decoration:none}[data-slot=\"search-pagination-item\"][data-current=\"true\"]{background:var(--primary,#111);color:var(--primary-foreground,#fff)}[data-slot=\"search-pagination-item\"][data-disabled=\"true\"]{cursor:not-allowed;color:var(--muted-foreground,#737373)}[data-slot=\"search-toolbar-item\"]{position:relative}[data-slot=\"search-body\"]{margin-top:2rem;display:flex;flex-direction:column;gap:1.5rem}[data-slot=\"search-label\"]{margin-bottom:0.25rem;display:block;font-size:0.875rem;color:var(--muted-foreground,#737373)}[data-slot=\"search-sheet-title\"]{padding:1.5rem 1.5rem 0;font-size:1.125rem;font-weight:600}[data-slot=\"search-layout\"]{display:grid;gap:2rem}[data-slot=\"search-sidebar\"]{display:none}[data-slot=\"search-layout\"] > div > [data-slot=\"search-filters-trigger\"]{margin-bottom:1rem}@media (min-width:1024px){[data-slot=\"search-layout\"]{grid-template-columns:280px minmax(0,1fr)}[data-slot=\"search-sidebar\"]{display:block;position:sticky;top:1.5rem;align-self:start}[data-slot=\"search-layout\"] > div > [data-slot=\"search-filters-trigger\"]{display:none}}[data-slot=\"listing-card-link\"]{display:block;color:inherit;text-decoration:none;cursor:pointer}[data-slot=\"listing-card-media\"]{position:relative;width:100%;overflow:hidden;background:var(--muted,#f5f5f4);aspect-ratio:var(--garagem-listing-media-ratio)}[data-slot=\"listing-card-media\"] img{height:100%;width:100%;object-fit:cover;transition:transform 0.3s}[data-slot=\"listing-card\"]:hover [data-slot=\"listing-card-media\"] img{transform:scale(1.05)}@media (prefers-reduced-motion:reduce){[data-slot=\"listing-card-media\"] img{transition:none}[data-slot=\"listing-card\"]:hover [data-slot=\"listing-card-media\"] img{transform:none}}[data-slot=\"listing-card-empty\"]{display:flex;height:100%;width:100%;align-items:center;justify-content:center;font-size:0.75rem;color:var(--muted-foreground,#737373)}[data-slot=\"listing-card-cta\"]{margin-top:0.75rem}[data-slot=\"search-filters\"]{display:flex;flex-direction:column;gap:1.25rem}[data-slot=\"search-filter\"]{margin:0;padding:0;border:0;font-size:0.875rem}[data-slot=\"search-filter\"] legend{margin-bottom:0.5rem;padding:0;color:var(--muted-foreground,#737373)}[data-slot=\"search-range-row\"]{display:flex;align-items:flex-end;gap:0.5rem}[data-slot=\"search-range-side\"]{min-width:0;flex:1}[data-slot=\"search-range-side\"] > span:first-child{margin-bottom:0.25rem;display:block;font-size:0.75rem;color:var(--muted-foreground,#737373)}[data-slot=\"search-range-affix\"]{position:relative;display:block}[data-slot=\"search-range-prefix\"]{pointer-events:none;position:absolute;inset-block:0;left:0;display:flex;align-items:center;padding-left:0.75rem;color:var(--muted-foreground,#737373)}[data-slot=\"search-range-input\"]{min-height:2.5rem;width:100%;border-radius:var(--garagem-search-radius);border:1px solid var(--border,#e4e4e7);background:var(--background,#fff);padding:0 0.75rem}[data-slot=\"search-range-affix\"] [data-slot=\"search-range-input\"]{padding-left:2.5rem}[data-slot=\"search-count-group\"]{display:flex;flex-wrap:wrap;gap:0.375rem}[data-slot=\"search-count-choice\"]{min-height:2.5rem;cursor:pointer;border-radius:var(--garagem-search-radius);border:1px solid var(--border,#e4e4e7);background:var(--background,#fff);padding:0 0.75rem;font-size:0.875rem}[data-slot=\"search-count-choice\"][data-selected=\"true\"]{border-color:var(--primary,#111);background:color-mix(in srgb,var(--primary,#111) 10%,transparent)}[data-slot=\"search-enum-list\"],[data-slot=\"search-scroll\"]{display:flex;flex-direction:column;gap:0.375rem}[data-slot=\"search-enum-option\"]{display:flex;cursor:pointer;align-items:center;gap:0.5rem}[data-slot=\"listing-card-badge\"]{position:absolute;left:0.75rem;top:0.75rem;border-radius:999px;background:color-mix(in srgb,var(--background,#fff) 90%,transparent);padding:0.25rem 0.5rem;font-size:0.75rem;font-weight:500}[data-slot=\"listing-card-body\"]{padding:1rem}[data-slot=\"listing-card-title\"]{display:-webkit-box;margin-top:0.25rem;overflow:hidden;-webkit-box-orient:vertical;-webkit-line-clamp:1;font-size:0.875rem;font-weight:500}[data-slot=\"listing-card-location\"]{margin-top:0.125rem;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:0.75rem;color:var(--muted-foreground,#737373)}[data-slot=\"listing-card-features\"]{display:flex;flex-wrap:wrap;margin-top:0.75rem;gap:0.25rem 1rem;padding:0;list-style:none;font-size:0.75rem;color:var(--muted-foreground,#737373)}[data-slot=\"search-skeleton-block\"]{animation:garagem-search-pulse 1.2s ease-in-out infinite;background:var(--garagem-skeleton);border-radius:0.375rem}[data-slot=\"search-skeleton-card\"]{overflow:hidden;border-radius:var(--garagem-listing-card-radius);border:1px solid var(--border,#e4e4e7)}[data-slot=\"search-skeleton-body\"]{display:flex;flex-direction:column;gap:0.5rem;padding:1rem}[data-slot=\"search-skeleton-block\"][data-kind=\"media\"]{aspect-ratio:var(--garagem-listing-media-ratio)}[data-slot=\"search-skeleton-block\"][data-kind=\"line-lg\"]{height:1.25rem;width:50%}[data-slot=\"search-skeleton-block\"][data-kind=\"line-md\"]{height:1rem;width:75%}[data-slot=\"search-skeleton-block\"][data-kind=\"line-sm\"]{height:0.75rem;width:66.666667%}[data-slot=\"search-skeleton-block\"][data-kind=\"detail-media\"]{max-width:45rem;aspect-ratio:4 / 3}[data-slot=\"search-skeleton-block\"][data-kind=\"detail-title\"]{width:66.666667%;height:2rem;margin-top:1.5rem}@media (prefers-reduced-motion:reduce){[data-slot=\"search-popover\"],[data-slot=\"search-sheet-overlay\"],[data-slot=\"search-sheet-panel\"],[data-slot=\"search-skeleton-block\"]{animation:none}}@keyframes garagem-search-in{from{opacity:0;transform:translateY(-4px) scale(0.98)}to{opacity:1;transform:none}}@keyframes garagem-search-fade{from{opacity:0}to{opacity:1}}@keyframes garagem-search-sheet{from{transform:translateX(100%)}to{transform:none}}@keyframes garagem-search-pulse{50%{opacity:0.55}}";
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useLayoutEffect, type ReactElement } from "react";
|
|
2
4
|
|
|
3
5
|
import {
|
|
4
6
|
SEARCH_CHROME_CSS,
|
|
@@ -7,6 +9,23 @@ import {
|
|
|
7
9
|
|
|
8
10
|
const STYLE_ID = `garagem-search-chrome-${SEARCH_CHROME_CSS_VERSION}`;
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
/** Append once to document.head — never a React child (unmount must not remove it). */
|
|
13
|
+
function injectSearchChromeOnce(): void {
|
|
14
|
+
if (typeof document === "undefined") return;
|
|
15
|
+
if (document.getElementById(STYLE_ID)) return;
|
|
16
|
+
const el = document.createElement("style");
|
|
17
|
+
el.id = STYLE_ID;
|
|
18
|
+
el.textContent = SEARCH_CHROME_CSS;
|
|
19
|
+
document.head.appendChild(el);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function SearchChromeStyles(): ReactElement | null {
|
|
23
|
+
// Client render: inject before paint (Studio / v0 are client-heavy grids).
|
|
24
|
+
if (typeof document !== "undefined") {
|
|
25
|
+
injectSearchChromeOnce();
|
|
26
|
+
}
|
|
27
|
+
useLayoutEffect(() => {
|
|
28
|
+
injectSearchChromeOnce();
|
|
29
|
+
}, []);
|
|
30
|
+
return null;
|
|
12
31
|
}
|
package/src/schedule.ts
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Visit-lead schedule: hours in, slots out. Pure — no fetch, no React.
|
|
3
|
+
* Calendar dates are civil dates in `timeZone` (America/Sao_Paulo), never
|
|
4
|
+
* UTC midnight from `new Date("YYYY-MM-DD")`.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export const VISIT_TIME_ZONE = "America/Sao_Paulo" as const;
|
|
8
|
+
|
|
9
|
+
export type HHmm = string;
|
|
10
|
+
|
|
11
|
+
export type VisitHours = {
|
|
12
|
+
start: HHmm;
|
|
13
|
+
end: HHmm;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export type VisitScheduleConfig = {
|
|
17
|
+
timeZone: typeof VISIT_TIME_ZONE;
|
|
18
|
+
saturday: boolean;
|
|
19
|
+
sunday: boolean;
|
|
20
|
+
weekday: VisitHours;
|
|
21
|
+
weekend: VisitHours | null;
|
|
22
|
+
minHoursAhead: number;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export type VisitSchedule = VisitScheduleConfig & {
|
|
26
|
+
disabledDays: number[];
|
|
27
|
+
weekdayTimeSlots: HHmm[];
|
|
28
|
+
weekendTimeSlots: HHmm[];
|
|
29
|
+
timeSlots: HHmm[];
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const HHMM_RE = /^([01]\d|2[0-3]):([0-5]\d)$/;
|
|
33
|
+
const YMD_RE = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
34
|
+
|
|
35
|
+
const WEEKDAY_SHORT: Record<string, number> = {
|
|
36
|
+
Sun: 0,
|
|
37
|
+
Mon: 1,
|
|
38
|
+
Tue: 2,
|
|
39
|
+
Wed: 3,
|
|
40
|
+
Thu: 4,
|
|
41
|
+
Fri: 5,
|
|
42
|
+
Sat: 6,
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
function pad2(value: number): string {
|
|
46
|
+
return String(value).padStart(2, "0");
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function parseHHmm(value: string): { hour: number; minute: number } | null {
|
|
50
|
+
const match = HHMM_RE.exec(value);
|
|
51
|
+
if (!match) return null;
|
|
52
|
+
return { hour: Number(match[1]), minute: Number(match[2]) };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function minutesOfDay(hhmm: HHmm): number | null {
|
|
56
|
+
const parsed = parseHHmm(hhmm);
|
|
57
|
+
if (!parsed) return null;
|
|
58
|
+
return parsed.hour * 60 + parsed.minute;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function expandVisitTimeSlots(hours: VisitHours): HHmm[] {
|
|
62
|
+
const start = minutesOfDay(hours.start);
|
|
63
|
+
const end = minutesOfDay(hours.end);
|
|
64
|
+
if (start == null || end == null || start > end) return [];
|
|
65
|
+
const slots: HHmm[] = [];
|
|
66
|
+
for (let minutes = start; minutes <= end; minutes += 60) {
|
|
67
|
+
const hour = Math.floor(minutes / 60);
|
|
68
|
+
const minute = minutes % 60;
|
|
69
|
+
slots.push(`${pad2(hour)}:${pad2(minute)}`);
|
|
70
|
+
}
|
|
71
|
+
return slots;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function unionSorted(left: HHmm[], right: HHmm[]): HHmm[] {
|
|
75
|
+
return Array.from(new Set([...left, ...right])).sort();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function expandVisitSchedule(
|
|
79
|
+
config: VisitScheduleConfig
|
|
80
|
+
): VisitSchedule {
|
|
81
|
+
const weekendHours =
|
|
82
|
+
config.weekend ??
|
|
83
|
+
(config.saturday || config.sunday ? config.weekday : null);
|
|
84
|
+
const weekdayTimeSlots = expandVisitTimeSlots(config.weekday);
|
|
85
|
+
const weekendTimeSlots = weekendHours
|
|
86
|
+
? expandVisitTimeSlots(weekendHours)
|
|
87
|
+
: [];
|
|
88
|
+
const disabledDays: number[] = [];
|
|
89
|
+
if (!config.sunday) disabledDays.push(0);
|
|
90
|
+
if (!config.saturday) disabledDays.push(6);
|
|
91
|
+
return {
|
|
92
|
+
...config,
|
|
93
|
+
weekend: weekendHours,
|
|
94
|
+
disabledDays,
|
|
95
|
+
weekdayTimeSlots,
|
|
96
|
+
weekendTimeSlots,
|
|
97
|
+
timeSlots: unionSorted(weekdayTimeSlots, weekendTimeSlots),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export const STUDIO_DEFAULT_VISIT_SCHEDULE: VisitSchedule = expandVisitSchedule(
|
|
102
|
+
{
|
|
103
|
+
timeZone: VISIT_TIME_ZONE,
|
|
104
|
+
saturday: false,
|
|
105
|
+
sunday: false,
|
|
106
|
+
weekday: { start: "06:00", end: "22:00" },
|
|
107
|
+
weekend: null,
|
|
108
|
+
minHoursAhead: 2,
|
|
109
|
+
}
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
function zonedParts(
|
|
113
|
+
date: Date,
|
|
114
|
+
timeZone: string
|
|
115
|
+
): {
|
|
116
|
+
year: number;
|
|
117
|
+
month: number;
|
|
118
|
+
day: number;
|
|
119
|
+
hour: number;
|
|
120
|
+
minute: number;
|
|
121
|
+
weekday: number;
|
|
122
|
+
} {
|
|
123
|
+
const parts = new Intl.DateTimeFormat("en-US", {
|
|
124
|
+
timeZone,
|
|
125
|
+
weekday: "short",
|
|
126
|
+
year: "numeric",
|
|
127
|
+
month: "2-digit",
|
|
128
|
+
day: "2-digit",
|
|
129
|
+
hour: "2-digit",
|
|
130
|
+
minute: "2-digit",
|
|
131
|
+
hourCycle: "h23",
|
|
132
|
+
}).formatToParts(date);
|
|
133
|
+
const get = (type: Intl.DateTimeFormatPartTypes): string =>
|
|
134
|
+
parts.find((part) => part.type === type)?.value ?? "";
|
|
135
|
+
const weekday = WEEKDAY_SHORT[get("weekday")] ?? 0;
|
|
136
|
+
return {
|
|
137
|
+
year: Number(get("year")),
|
|
138
|
+
month: Number(get("month")),
|
|
139
|
+
day: Number(get("day")),
|
|
140
|
+
hour: Number(get("hour")),
|
|
141
|
+
minute: Number(get("minute")),
|
|
142
|
+
weekday,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function calendarYmd(date: Date, timeZone: string): string {
|
|
147
|
+
const parts = zonedParts(date, timeZone);
|
|
148
|
+
return `${parts.year}-${pad2(parts.month)}-${pad2(parts.day)}`;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function parseYmd(
|
|
152
|
+
value: string
|
|
153
|
+
): { year: number; month: number; day: number } | null {
|
|
154
|
+
const match = YMD_RE.exec(value);
|
|
155
|
+
if (!match) return null;
|
|
156
|
+
const year = Number(match[1]);
|
|
157
|
+
const month = Number(match[2]);
|
|
158
|
+
const day = Number(match[3]);
|
|
159
|
+
const utc = new Date(Date.UTC(year, month - 1, day));
|
|
160
|
+
if (
|
|
161
|
+
utc.getUTCFullYear() !== year ||
|
|
162
|
+
utc.getUTCMonth() !== month - 1 ||
|
|
163
|
+
utc.getUTCDate() !== day
|
|
164
|
+
) {
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
return { year, month, day };
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** Civil YYYY-MM-DD in `timeZone`. String dates must already be YMD. */
|
|
171
|
+
function toCalendarYmd(date: Date | string, timeZone: string): string | null {
|
|
172
|
+
if (typeof date === "string") {
|
|
173
|
+
return parseYmd(date) ? date : null;
|
|
174
|
+
}
|
|
175
|
+
if (date instanceof Date && Number.isFinite(date.getTime())) {
|
|
176
|
+
return calendarYmd(date, timeZone);
|
|
177
|
+
}
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function weekdayOfYmd(ymd: string, timeZone: string): number | null {
|
|
182
|
+
const parsed = parseYmd(ymd);
|
|
183
|
+
if (!parsed) return null;
|
|
184
|
+
// 15:00 UTC is noon in America/Sao_Paulo (UTC−3), same civil day.
|
|
185
|
+
const utcNoonish = new Date(
|
|
186
|
+
Date.UTC(parsed.year, parsed.month - 1, parsed.day, 15, 0, 0)
|
|
187
|
+
);
|
|
188
|
+
return zonedParts(utcNoonish, timeZone).weekday;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export function slotsForDate(
|
|
192
|
+
schedule: VisitSchedule,
|
|
193
|
+
date: Date | string,
|
|
194
|
+
now: Date = new Date()
|
|
195
|
+
): HHmm[] {
|
|
196
|
+
const timeZone = schedule.timeZone;
|
|
197
|
+
const ymd = toCalendarYmd(date, timeZone);
|
|
198
|
+
if (!ymd) return [];
|
|
199
|
+
const weekday = weekdayOfYmd(ymd, timeZone);
|
|
200
|
+
if (weekday == null) return [];
|
|
201
|
+
if (weekday === 0 && !schedule.sunday) return [];
|
|
202
|
+
if (weekday === 6 && !schedule.saturday) return [];
|
|
203
|
+
const base =
|
|
204
|
+
weekday === 0 || weekday === 6
|
|
205
|
+
? schedule.weekendTimeSlots
|
|
206
|
+
: schedule.weekdayTimeSlots;
|
|
207
|
+
const today = calendarYmd(now, timeZone);
|
|
208
|
+
if (ymd < today) return [];
|
|
209
|
+
if (ymd !== today) return [...base];
|
|
210
|
+
const nowParts = zonedParts(now, timeZone);
|
|
211
|
+
const cutoff =
|
|
212
|
+
nowParts.hour * 60 + nowParts.minute + schedule.minHoursAhead * 60;
|
|
213
|
+
return base.filter((slot) => {
|
|
214
|
+
const minutes = minutesOfDay(slot);
|
|
215
|
+
return minutes != null && minutes >= cutoff;
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export function isVisitSlotAllowed(
|
|
220
|
+
schedule: VisitSchedule,
|
|
221
|
+
visitDate: string,
|
|
222
|
+
visitTime: HHmm,
|
|
223
|
+
now: Date = new Date()
|
|
224
|
+
): boolean {
|
|
225
|
+
return slotsForDate(schedule, visitDate, now).includes(visitTime);
|
|
226
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Studio ↔ npm contract. Prompt, completeness, and recipes must read this
|
|
3
|
+
* object — do not keep a second list of required `@garagem-ai/site-sdk/react`
|
|
4
|
+
* names in apps/site.
|
|
5
|
+
*
|
|
6
|
+
* `minNpmVersion` is the tarball v0 actually installs. Optional exports exist
|
|
7
|
+
* in git and may already be on npm, but Studio codegen must not name them
|
|
8
|
+
* while chromeStrategy is self-inject (v0 copies identifiers; a layout tag
|
|
9
|
+
* also breaks the pancake stack).
|
|
10
|
+
*/
|
|
11
|
+
export const STUDIO_SDK_PACKAGE = "@garagem-ai/site-sdk" as const;
|
|
12
|
+
|
|
13
|
+
export const STUDIO_SDK_CONTRACT = {
|
|
14
|
+
package: STUDIO_SDK_PACKAGE,
|
|
15
|
+
/**
|
|
16
|
+
* Exact pin for generated Studio sites. Must be ≥ `selfInjectSince` so
|
|
17
|
+
* prompts that skip the layout chrome tag match the tarball v0 installs.
|
|
18
|
+
* This PR’s changeset publishes that tarball as 0.4.3 — do not generate
|
|
19
|
+
* against this floor until Version Packages is on npm.
|
|
20
|
+
*/
|
|
21
|
+
minNpmVersion: "0.4.3",
|
|
22
|
+
/** First release where ListingCard and ResultsSkeleton inject the sheet. */
|
|
23
|
+
selfInjectSince: "0.4.2",
|
|
24
|
+
chromeStrategy: "self-inject" as const,
|
|
25
|
+
reactExports: [
|
|
26
|
+
"SearchPage",
|
|
27
|
+
"ListingCard",
|
|
28
|
+
"usePublicSearch",
|
|
29
|
+
"ResultsSkeleton",
|
|
30
|
+
] as const,
|
|
31
|
+
/**
|
|
32
|
+
* Names that exist in git / the unpublished patch. Completeness treats an
|
|
33
|
+
* import as `sdk-export-mismatch` when the generated pin is older than
|
|
34
|
+
* `since`. Studio prompts must not mention these names at all (even as
|
|
35
|
+
* “never import”) — v0 copies the identifier and the preview ESM loader
|
|
36
|
+
* throws FatalRendererError.
|
|
37
|
+
*/
|
|
38
|
+
optionalReactExports: {
|
|
39
|
+
SearchPageFallback: "0.4.1",
|
|
40
|
+
SearchChromeStyles: "0.4.1",
|
|
41
|
+
} as const,
|
|
42
|
+
forbiddenImports: ["@garagem-ai/site-sdk/react/search.css"] as const,
|
|
43
|
+
leadStrategy: "visit-default" as const,
|
|
44
|
+
leadExports: [
|
|
45
|
+
"getLeadUi",
|
|
46
|
+
"submitVisitLead",
|
|
47
|
+
"submitContactLead",
|
|
48
|
+
"slotsForDate",
|
|
49
|
+
"expandVisitSchedule",
|
|
50
|
+
"expandVisitTimeSlots",
|
|
51
|
+
"isVisitSlotAllowed",
|
|
52
|
+
"STUDIO_DEFAULT_VISIT_SCHEDULE",
|
|
53
|
+
] as const,
|
|
54
|
+
} as const;
|
|
55
|
+
|
|
56
|
+
export type StudioSdkContract = typeof STUDIO_SDK_CONTRACT;
|
|
57
|
+
|
|
58
|
+
const REACT_SDK_NAMED_IMPORT_RE =
|
|
59
|
+
/(?:^|[\n;])\s*import\s+(?!type\b)(?:type\s+)?\{([^}]+)\}\s+from\s+['"]@garagem-ai\/site-sdk\/react['"]/g;
|
|
60
|
+
|
|
61
|
+
/** Showcase POST route — not GET …/leads/ui (getLeadUi schema). */
|
|
62
|
+
export const SHOWCASE_LEADS_POST_URL_RE =
|
|
63
|
+
/\/api\/sites\/[^\s"']*\/leads(?!\/ui)/;
|
|
64
|
+
|
|
65
|
+
export function hasShowcaseLeadsPostUrl(text: string): boolean {
|
|
66
|
+
return SHOWCASE_LEADS_POST_URL_RE.test(text);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function coerceNpmVersion(raw: unknown): string | null {
|
|
70
|
+
if (typeof raw !== "string") return null;
|
|
71
|
+
const match = raw.trim().match(/(\d+)\.(\d+)\.(\d+)/);
|
|
72
|
+
return match ? `${match[1]}.${match[2]}.${match[3]}` : null;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function compareSemver(a: string, b: string): number {
|
|
76
|
+
const left = a.split(".").map((part) => Number(part));
|
|
77
|
+
const right = b.split(".").map((part) => Number(part));
|
|
78
|
+
for (let i = 0; i < 3; i += 1) {
|
|
79
|
+
const delta = (left[i] ?? 0) - (right[i] ?? 0);
|
|
80
|
+
if (delta !== 0) return delta;
|
|
81
|
+
}
|
|
82
|
+
return 0;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function parseReactSdkNamedImports(source: string): string[] {
|
|
86
|
+
const names: string[] = [];
|
|
87
|
+
REACT_SDK_NAMED_IMPORT_RE.lastIndex = 0;
|
|
88
|
+
let match: RegExpExecArray | null;
|
|
89
|
+
while ((match = REACT_SDK_NAMED_IMPORT_RE.exec(source)) !== null) {
|
|
90
|
+
const body = match[1];
|
|
91
|
+
if (!body) continue;
|
|
92
|
+
for (const raw of body.split(",")) {
|
|
93
|
+
const token = raw.trim();
|
|
94
|
+
if (!token || token.startsWith("type ")) continue;
|
|
95
|
+
const name = token.split(/\s+as\s+/)[0]?.trim();
|
|
96
|
+
if (name) names.push(name);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return names;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function reactExportsAvailableAt(pin: string): Set<string> {
|
|
103
|
+
const available = new Set<string>(STUDIO_SDK_CONTRACT.reactExports);
|
|
104
|
+
for (const [name, since] of Object.entries(
|
|
105
|
+
STUDIO_SDK_CONTRACT.optionalReactExports
|
|
106
|
+
)) {
|
|
107
|
+
if (compareSemver(pin, since) >= 0) available.add(name);
|
|
108
|
+
}
|
|
109
|
+
return available;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function unavailableReactImports(source: string, pin: string): string[] {
|
|
113
|
+
const available = reactExportsAvailableAt(pin);
|
|
114
|
+
const missing: string[] = [];
|
|
115
|
+
for (const name of parseReactSdkNamedImports(source)) {
|
|
116
|
+
if (!available.has(name) && !missing.includes(name)) {
|
|
117
|
+
missing.push(name);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return missing;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function studioSdkPinInstruction(): string {
|
|
124
|
+
const version = STUDIO_SDK_CONTRACT.minNpmVersion;
|
|
125
|
+
const names = STUDIO_SDK_CONTRACT.reactExports.join(", ");
|
|
126
|
+
return `In \`package.json\` set \`"@garagem-ai/site-sdk": "${version}"\` (exact). Import only these \`${STUDIO_SDK_PACKAGE}/react\` names: ${names}.`;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function studioLeadInstruction(): string {
|
|
130
|
+
const names = STUDIO_SDK_CONTRACT.leadExports.join(", ");
|
|
131
|
+
return `Listing-detail visit/contact leads: import ${names} from \`${STUDIO_SDK_PACKAGE}\` (the main package, not \`/react\`). Call \`submitVisitLead\` / \`submitContactLead\` — never concatenate a leads webhook URL and never POST the Showcase demo leads route.`;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export function studioChromeInstruction(): string {
|
|
135
|
+
const injectors =
|
|
136
|
+
compareSemver(
|
|
137
|
+
STUDIO_SDK_CONTRACT.minNpmVersion,
|
|
138
|
+
STUDIO_SDK_CONTRACT.selfInjectSince
|
|
139
|
+
) >= 0
|
|
140
|
+
? "`SearchPage`, `ListingCard`, and `ResultsSkeleton`"
|
|
141
|
+
: "`SearchPage`";
|
|
142
|
+
return `Search chrome CSS is injected by ${injectors} (JS \`<style>\` tag). Never \`import "@garagem-ai/site-sdk/react/search.css"\` — 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\`.`;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Tokens that must not appear in Studio codegen (prompts, recipes, repair).
|
|
147
|
+
* v0 copies identifiers it sees, even inside “never import X”.
|
|
148
|
+
*/
|
|
149
|
+
export function studioCodegenContractViolations(text: string): string[] {
|
|
150
|
+
const violations: string[] = [];
|
|
151
|
+
for (const name of Object.keys(STUDIO_SDK_CONTRACT.optionalReactExports)) {
|
|
152
|
+
if (text.includes(name)) violations.push(name);
|
|
153
|
+
}
|
|
154
|
+
const pin = STUDIO_SDK_CONTRACT.minNpmVersion;
|
|
155
|
+
const available = reactExportsAvailableAt(pin);
|
|
156
|
+
for (const name of parseReactSdkNamedImports(text)) {
|
|
157
|
+
if (!available.has(name) && !violations.includes(name)) {
|
|
158
|
+
violations.push(name);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
if (hasShowcaseLeadsPostUrl(text)) {
|
|
162
|
+
violations.push("showcase-leads-url");
|
|
163
|
+
}
|
|
164
|
+
if (/\btype\s*=\s*["']date["']/.test(text)) {
|
|
165
|
+
violations.push("native-date-input");
|
|
166
|
+
}
|
|
167
|
+
return violations;
|
|
168
|
+
}
|