@garagem-ai/site-sdk 0.4.4 → 0.4.5
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.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +54 -35
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +54 -35
- package/dist/index.mjs.map +1 -1
- package/dist/react.js +3 -2
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +3 -2
- package/dist/react.mjs.map +1 -1
- package/package.json +1 -1
- package/src/internal/url.ts +3 -1
- package/src/leads.ts +33 -5
- package/src/react/styles/search-chrome-css.generated.ts +1 -1
- package/src/schedule.ts +1 -0
package/dist/index.mjs
CHANGED
|
@@ -19,7 +19,8 @@ function normalizeBaseUrl(baseUrl) {
|
|
|
19
19
|
return url.endsWith("/") ? url.slice(0, -1) : url;
|
|
20
20
|
}
|
|
21
21
|
async function coerceSiteId(siteId) {
|
|
22
|
-
const
|
|
22
|
+
const raw = typeof siteId === "function" ? siteId() : siteId;
|
|
23
|
+
const value = await Promise.resolve(raw);
|
|
23
24
|
if (typeof value !== "string" || !value.trim()) {
|
|
24
25
|
throw new TypeError(
|
|
25
26
|
"Garagem SDK: siteId must be a string. Await resolveSiteId(...) before getListings / getSearchUi / queryListings."
|
|
@@ -446,6 +447,7 @@ function slotsForDate(schedule, date, now = /* @__PURE__ */ new Date()) {
|
|
|
446
447
|
if (!ymd) return [];
|
|
447
448
|
const weekday = weekdayOfYmd(ymd, timeZone);
|
|
448
449
|
if (weekday == null) return [];
|
|
450
|
+
if (schedule.disabledDays.includes(weekday)) return [];
|
|
449
451
|
if (weekday === 0 && !schedule.sunday) return [];
|
|
450
452
|
if (weekday === 6 && !schedule.saturday) return [];
|
|
451
453
|
const base = weekday === 0 || weekday === 6 ? schedule.weekendTimeSlots : schedule.weekdayTimeSlots;
|
|
@@ -463,7 +465,56 @@ function isVisitSlotAllowed(schedule, visitDate, visitTime, now = /* @__PURE__ *
|
|
|
463
465
|
return slotsForDate(schedule, visitDate, now).includes(visitTime);
|
|
464
466
|
}
|
|
465
467
|
|
|
468
|
+
// src/resolve-site-id.ts
|
|
469
|
+
var PREVIEW_HOST_SUFFIXES = [".vusercontent.net"];
|
|
470
|
+
function isStudioPreviewHost(host) {
|
|
471
|
+
const normalized = stripPort(host);
|
|
472
|
+
if (normalized === "localhost" || normalized === "127.0.0.1") return true;
|
|
473
|
+
return PREVIEW_HOST_SUFFIXES.some((suffix) => normalized.endsWith(suffix));
|
|
474
|
+
}
|
|
475
|
+
function stripPort(host) {
|
|
476
|
+
return host.trim().toLowerCase().split(":")[0] ?? "";
|
|
477
|
+
}
|
|
478
|
+
async function resolvePublicSiteId(options) {
|
|
479
|
+
const fallback = options.fallback?.trim() ?? "";
|
|
480
|
+
const host = options.host ? stripPort(options.host) : "";
|
|
481
|
+
if (host && !isStudioPreviewHost(host)) {
|
|
482
|
+
const site = await getSite({
|
|
483
|
+
domain: host,
|
|
484
|
+
baseUrl: options.baseUrl,
|
|
485
|
+
fetch: options.fetch
|
|
486
|
+
});
|
|
487
|
+
if (site?.id) return site.id;
|
|
488
|
+
throw new GaragemSdkError(
|
|
489
|
+
`Garagem SDK: no published site found for domain "${host}"`,
|
|
490
|
+
{ status: 404, url: host }
|
|
491
|
+
);
|
|
492
|
+
}
|
|
493
|
+
if (fallback) return fallback;
|
|
494
|
+
throw new GaragemSdkError(
|
|
495
|
+
"Garagem SDK: could not resolve a site id (no host match and no fallback)",
|
|
496
|
+
{ status: 404, url: host || "fallback" }
|
|
497
|
+
);
|
|
498
|
+
}
|
|
499
|
+
|
|
466
500
|
// src/leads.ts
|
|
501
|
+
function browserHost() {
|
|
502
|
+
if (typeof window === "undefined") return "";
|
|
503
|
+
return window.location.host;
|
|
504
|
+
}
|
|
505
|
+
async function resolveLeadSiteId(input) {
|
|
506
|
+
try {
|
|
507
|
+
return await coerceSiteId(input.siteId);
|
|
508
|
+
} catch (error) {
|
|
509
|
+
const host = browserHost();
|
|
510
|
+
if (!host) throw error;
|
|
511
|
+
return resolvePublicSiteId({
|
|
512
|
+
host,
|
|
513
|
+
baseUrl: input.baseUrl,
|
|
514
|
+
fetch: input.fetch
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
}
|
|
467
518
|
var LeadSubmitError = class extends Error {
|
|
468
519
|
code;
|
|
469
520
|
status;
|
|
@@ -508,7 +559,7 @@ function studioDefaultLeadUi() {
|
|
|
508
559
|
};
|
|
509
560
|
}
|
|
510
561
|
async function getLeadUi(options) {
|
|
511
|
-
const siteId = await
|
|
562
|
+
const siteId = await resolveLeadSiteId(options);
|
|
512
563
|
const url = `${normalizeBaseUrl(options.baseUrl)}/api/sites/${encodeURIComponent(siteId)}/leads/ui`;
|
|
513
564
|
return callJson(
|
|
514
565
|
url,
|
|
@@ -566,7 +617,7 @@ function normalizeContact(input) {
|
|
|
566
617
|
};
|
|
567
618
|
}
|
|
568
619
|
async function postSiteLead(input) {
|
|
569
|
-
const siteId = await
|
|
620
|
+
const siteId = await resolveLeadSiteId(input);
|
|
570
621
|
const base = normalizeBaseUrl(input.baseUrl);
|
|
571
622
|
const url = `${base}/api/webhooks/sites/${encodeURIComponent(siteId)}/leads`;
|
|
572
623
|
const f = input.fetch ?? fetch;
|
|
@@ -1518,38 +1569,6 @@ function paginationPages(currentPage, totalPages, padding) {
|
|
|
1518
1569
|
return pages;
|
|
1519
1570
|
}
|
|
1520
1571
|
|
|
1521
|
-
// src/resolve-site-id.ts
|
|
1522
|
-
var PREVIEW_HOST_SUFFIXES = [".vusercontent.net"];
|
|
1523
|
-
function isStudioPreviewHost(host) {
|
|
1524
|
-
const normalized = stripPort(host);
|
|
1525
|
-
if (normalized === "localhost" || normalized === "127.0.0.1") return true;
|
|
1526
|
-
return PREVIEW_HOST_SUFFIXES.some((suffix) => normalized.endsWith(suffix));
|
|
1527
|
-
}
|
|
1528
|
-
function stripPort(host) {
|
|
1529
|
-
return host.trim().toLowerCase().split(":")[0] ?? "";
|
|
1530
|
-
}
|
|
1531
|
-
async function resolvePublicSiteId(options) {
|
|
1532
|
-
const fallback = options.fallback?.trim() ?? "";
|
|
1533
|
-
const host = options.host ? stripPort(options.host) : "";
|
|
1534
|
-
if (host && !isStudioPreviewHost(host)) {
|
|
1535
|
-
const site = await getSite({
|
|
1536
|
-
domain: host,
|
|
1537
|
-
baseUrl: options.baseUrl,
|
|
1538
|
-
fetch: options.fetch
|
|
1539
|
-
});
|
|
1540
|
-
if (site?.id) return site.id;
|
|
1541
|
-
throw new GaragemSdkError(
|
|
1542
|
-
`Garagem SDK: no published site found for domain "${host}"`,
|
|
1543
|
-
{ status: 404, url: host }
|
|
1544
|
-
);
|
|
1545
|
-
}
|
|
1546
|
-
if (fallback) return fallback;
|
|
1547
|
-
throw new GaragemSdkError(
|
|
1548
|
-
"Garagem SDK: could not resolve a site id (no host match and no fallback)",
|
|
1549
|
-
{ status: 404, url: host || "fallback" }
|
|
1550
|
-
);
|
|
1551
|
-
}
|
|
1552
|
-
|
|
1553
1572
|
// src/studio-contract.ts
|
|
1554
1573
|
var STUDIO_SDK_PACKAGE = "@garagem-ai/site-sdk";
|
|
1555
1574
|
var STUDIO_SDK_CONTRACT = {
|