@fluid-app/portal-sdk 0.1.65 → 0.1.67

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.
@@ -31,6 +31,5 @@ import "./SpacerWidget-DgVU58BC.mjs";
31
31
  import "./TableWidget-DjYabx1e.mjs";
32
32
  import "./ToDoWidget-Cmvf7I6c.mjs";
33
33
  import "./VideoWidget-51MxnPRZ.mjs";
34
- import "./use-current-user-DnBpWIw6.mjs";
35
34
  import { n as appDownloadScreenPropertySchema, t as AppDownloadScreen } from "./AppDownloadScreen-BXS02LRb.mjs";
36
35
  export { AppDownloadScreen, appDownloadScreenPropertySchema };
@@ -32,7 +32,6 @@ import "./TableWidget-DjYabx1e.mjs";
32
32
  import "./ToDoWidget-Cmvf7I6c.mjs";
33
33
  import "./VideoWidget-51MxnPRZ.mjs";
34
34
  import "./ScreenHeaderContext-CrdfLGKk.mjs";
35
- import "./AppNavigationContext-DJeNcP4Y.mjs";
36
35
  import "./sortable.esm-DreCqRxJ.mjs";
37
36
  import { n as mySiteScreenPropertySchema, t as MySiteScreen } from "./MySiteScreen-DR_xY95c.mjs";
38
37
  export { MySiteScreen, mySiteScreenPropertySchema };
@@ -32,7 +32,6 @@ import "./TableWidget-DjYabx1e.mjs";
32
32
  import "./ToDoWidget-Cmvf7I6c.mjs";
33
33
  import "./VideoWidget-51MxnPRZ.mjs";
34
34
  import "./ScreenHeaderContext-CrdfLGKk.mjs";
35
- import "./AppNavigationContext-DJeNcP4Y.mjs";
36
35
  import "./order-detail-DkMYJvzl.mjs";
37
36
  import { n as ordersScreenPropertySchema, t as OrdersScreen } from "./OrdersScreen-CQzgIEa4.mjs";
38
37
  export { OrdersScreen, ordersScreenPropertySchema };
@@ -32,8 +32,6 @@ import "./TableWidget-DjYabx1e.mjs";
32
32
  import "./ToDoWidget-Cmvf7I6c.mjs";
33
33
  import "./VideoWidget-51MxnPRZ.mjs";
34
34
  import "./ScreenHeaderContext-CrdfLGKk.mjs";
35
- import "./use-current-user-DnBpWIw6.mjs";
36
- import "./AppNavigationContext-DJeNcP4Y.mjs";
37
35
  import "./dist-CMGXkSgZ.mjs";
38
36
  import "./es-CrIkZTQ3.mjs";
39
37
  import "./dist-Cl4FsM3V.mjs";
@@ -32,8 +32,6 @@ import "./TableWidget-DjYabx1e.mjs";
32
32
  import "./ToDoWidget-Cmvf7I6c.mjs";
33
33
  import "./VideoWidget-51MxnPRZ.mjs";
34
34
  import "./ScreenHeaderContext-CrdfLGKk.mjs";
35
- import "./use-current-user-DnBpWIw6.mjs";
36
- import "./AppNavigationContext-DJeNcP4Y.mjs";
37
35
  import "./dist-CMGXkSgZ.mjs";
38
36
  import "./es-CrIkZTQ3.mjs";
39
37
  import "./dist-Cl4FsM3V.mjs";
@@ -33,6 +33,6 @@ require("./TableWidget-Cri6r5Yr.cjs");
33
33
  require("./ToDoWidget-Bv6POc5R.cjs");
34
34
  require("./VideoWidget-DnnuIvW1.cjs");
35
35
  require("./ScreenHeaderContext-eyKPyDoQ.cjs");
36
- const require_ShopScreen = require("./ShopScreen-qgOXPdUf.cjs");
36
+ const require_ShopScreen = require("./ShopScreen-D-1WO4sB.cjs");
37
37
  exports.ShopScreen = require_ShopScreen.ShopScreen;
38
38
  exports.shopScreenPropertySchema = require_ShopScreen.shopScreenPropertySchema;
@@ -32,7 +32,5 @@ import "./TableWidget-DjYabx1e.mjs";
32
32
  import "./ToDoWidget-Cmvf7I6c.mjs";
33
33
  import "./VideoWidget-51MxnPRZ.mjs";
34
34
  import "./ScreenHeaderContext-CrdfLGKk.mjs";
35
- import "./use-current-user-DnBpWIw6.mjs";
36
- import "./AppNavigationContext-DJeNcP4Y.mjs";
37
- import { n as shopScreenPropertySchema, t as ShopScreen } from "./ShopScreen-DFWQY8hT.mjs";
35
+ import { n as shopScreenPropertySchema, t as ShopScreen } from "./ShopScreen-XGC180Ts.mjs";
38
36
  export { ShopScreen, shopScreenPropertySchema };
@@ -1,4 +1,4 @@
1
- require("./chunk-DAgNkxik.cjs");
1
+ const require_chunk = require("./chunk-DAgNkxik.cjs");
2
2
  const require_FluidProvider = require("./FluidProvider-SnHdl4ww.cjs");
3
3
  const require_src = require("./src-DqIS-4ns.cjs");
4
4
  const require_use_account_clients = require("./use-account-clients-Bem920_7.cjs");
@@ -7,9 +7,11 @@ const require_use_current_user = require("./use-current-user-Bld9wMVT.cjs");
7
7
  const require_AppNavigationContext = require("./AppNavigationContext-B88_pXjo.cjs");
8
8
  const require_products = require("./products-BtHCYNv6.cjs");
9
9
  let react = require("react");
10
+ react = require_chunk.__toESM(react);
10
11
  let _tanstack_react_query = require("@tanstack/react-query");
11
12
  let react_jsx_runtime = require("react/jsx-runtime");
12
13
  let lucide_react = require("lucide-react");
14
+ let react_dom = require("react-dom");
13
15
  let _home_runner__work_fluid_mono_fluid_mono_node_modules__pnpm_zustand_5_0_9__types_react_19_2_13_immer_10_2_0_react_19_2_4_use_sync_external_store_1_6_0_react_19_2_4__node_modules_zustand_esm_index_mjs = require("/home/runner/_work/fluid-mono/fluid-mono/node_modules/.pnpm/zustand@5.0.9_@types+react@19.2.13_immer@10.2.0_react@19.2.4_use-sync-external-store@1.6.0_react@19.2.4_/node_modules/zustand/esm/index.mjs");
14
16
  let _home_runner__work_fluid_mono_fluid_mono_node_modules__pnpm_zustand_5_0_9__types_react_19_2_13_immer_10_2_0_react_19_2_4_use_sync_external_store_1_6_0_react_19_2_4__node_modules_zustand_esm_middleware_mjs = require("/home/runner/_work/fluid-mono/fluid-mono/node_modules/.pnpm/zustand@5.0.9_@types+react@19.2.13_immer@10.2.0_react@19.2.4_use-sync-external-store@1.6.0_react@19.2.4_/node_modules/zustand/esm/middleware.mjs");
15
17
  //#region ../../products/api-client/src/utils/product-price.ts
@@ -1550,13 +1552,165 @@ function ShopApp({ countryCode, companyLogoUrl, renderImage, onAddToCart, produc
1550
1552
  });
1551
1553
  }
1552
1554
  //#endregion
1555
+ //#region ../../cart/ui/src/components/cart-script.tsx
1556
+ const SCRIPT_ID = "fluid-cdn-script";
1557
+ const LEAD_CAPTURE_ID = "fluid-lead-capture-suppress";
1558
+ const SCRIPT_SRC = "https://assets.fluid.app/scripts/fluid-sdk/latest/web-widgets/index.js";
1559
+ function CartScript({ subdomain, authJwt }) {
1560
+ const authJwtRef = (0, react.useRef)(authJwt);
1561
+ authJwtRef.current = authJwt;
1562
+ (0, react.useEffect)(() => {
1563
+ if (!subdomain) return;
1564
+ if (document.getElementById(SCRIPT_ID)) return;
1565
+ const script = document.createElement("script");
1566
+ script.id = SCRIPT_ID;
1567
+ script.src = SCRIPT_SRC;
1568
+ script.type = "module";
1569
+ script.crossOrigin = "anonymous";
1570
+ script.dataset.fluidShop = subdomain;
1571
+ if (authJwtRef.current) script.dataset.authJwt = authJwtRef.current;
1572
+ document.head.appendChild(script);
1573
+ const leadCapture = document.createElement("fluid-lead-capture");
1574
+ leadCapture.id = LEAD_CAPTURE_ID;
1575
+ leadCapture.setAttribute("hide-widget", "true");
1576
+ document.body.appendChild(leadCapture);
1577
+ return () => {
1578
+ const existing = document.getElementById(SCRIPT_ID);
1579
+ if (existing) existing.remove();
1580
+ const existingLeadCapture = document.getElementById(LEAD_CAPTURE_ID);
1581
+ if (existingLeadCapture) existingLeadCapture.remove();
1582
+ };
1583
+ }, [subdomain]);
1584
+ return null;
1585
+ }
1586
+ //#endregion
1587
+ //#region ../../cart/ui/src/components/cart-widget.tsx
1588
+ function CartWidget({ theme }) {
1589
+ const [mounted, setMounted] = (0, react.useState)(false);
1590
+ const widgetRef = (0, react.useRef)(null);
1591
+ (0, react.useEffect)(() => {
1592
+ setMounted(true);
1593
+ }, []);
1594
+ (0, react.useEffect)(() => {
1595
+ if (!mounted) return;
1596
+ const el = widgetRef.current;
1597
+ if (!el) return;
1598
+ if (theme) el.setAttribute("theme", JSON.stringify(theme));
1599
+ else el.removeAttribute("theme");
1600
+ }, [theme, mounted]);
1601
+ const widget = react.default.createElement("fluid-cart-widget", {
1602
+ ref: (el) => {
1603
+ widgetRef.current = el;
1604
+ },
1605
+ "data-fluid-widget": "true",
1606
+ "hide-widget": "true",
1607
+ "is-primary": "true"
1608
+ });
1609
+ if (mounted) return (0, react_dom.createPortal)(widget, document.body);
1610
+ return null;
1611
+ }
1612
+ //#endregion
1613
+ //#region ../../cart/ui/src/components/cart-button.tsx
1614
+ const MAX_SDK_POLL_ATTEMPTS = 50;
1615
+ function CartButton({ onCheckout }) {
1616
+ const [initialCount, setInitialCount] = (0, react.useState)(0);
1617
+ const navigateToCheckout = (0, react.useCallback)(() => {
1618
+ if (!window.FluidCommerceSDK) {
1619
+ console.error("FluidCommerceSDK not available");
1620
+ return;
1621
+ }
1622
+ try {
1623
+ const checkoutUrl = window.FluidCommerceSDK.getCheckoutUrl();
1624
+ if (!checkoutUrl) {
1625
+ console.error("No checkout URL available");
1626
+ return;
1627
+ }
1628
+ onCheckout?.(checkoutUrl);
1629
+ } catch (error) {
1630
+ console.error("Error getting checkout URL:", error);
1631
+ }
1632
+ }, [onCheckout]);
1633
+ (0, react.useEffect)(() => {
1634
+ let timeoutId = null;
1635
+ let attempts = 0;
1636
+ let cancelled = false;
1637
+ const setupSDK = () => {
1638
+ if (cancelled) return;
1639
+ if (window.FluidCommerceSDK) {
1640
+ if (onCheckout) window.FluidCommerceSDK.setOnCheckout(navigateToCheckout);
1641
+ const count = window.FairShareSDK?.getCartItemCount?.();
1642
+ if (count != null) setInitialCount(count);
1643
+ } else if (attempts < MAX_SDK_POLL_ATTEMPTS) {
1644
+ attempts++;
1645
+ timeoutId = setTimeout(setupSDK, 100);
1646
+ }
1647
+ };
1648
+ setupSDK();
1649
+ return () => {
1650
+ cancelled = true;
1651
+ if (timeoutId) clearTimeout(timeoutId);
1652
+ };
1653
+ }, [navigateToCheckout, onCheckout]);
1654
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_src.Button, {
1655
+ className: "bg-primary text-primary-foreground hover:bg-primary-700 relative flex items-center gap-4 rounded-sm px-4 py-1.5",
1656
+ onClick: () => {
1657
+ window.fluidCart?.open();
1658
+ },
1659
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1660
+ className: "relative",
1661
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.ShoppingCart, { className: "size-5" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1662
+ id: "fluid-cart-count",
1663
+ className: "bg-primary-foreground text-primary absolute -top-1 -right-2 flex h-4 w-4 items-center justify-center rounded-full text-[8px] font-bold",
1664
+ children: initialCount
1665
+ })]
1666
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: "Cart" })]
1667
+ });
1668
+ }
1669
+ //#endregion
1670
+ //#region ../../cart/ui/src/components/shop-container.tsx
1671
+ function ShopContainer({ children, className = "", cartScript, cartWidget }) {
1672
+ const containerRef = (0, react.useRef)(null);
1673
+ const [portalContainer, setPortalContainer] = (0, react.useState)(null);
1674
+ (0, react.useEffect)(() => {
1675
+ const currentContainer = containerRef.current;
1676
+ if (!currentContainer) return;
1677
+ const reactContentWrapper = document.createElement("div");
1678
+ reactContentWrapper.id = "react-content-wrapper";
1679
+ reactContentWrapper.style.cssText = `
1680
+ position: relative;
1681
+ `;
1682
+ reactContentWrapper.className = "min-h-full";
1683
+ currentContainer.appendChild(reactContentWrapper);
1684
+ setPortalContainer(reactContentWrapper);
1685
+ return () => {
1686
+ if (currentContainer && reactContentWrapper) try {
1687
+ currentContainer.removeChild(reactContentWrapper);
1688
+ } catch (e) {
1689
+ console.warn("Failed to cleanup isolated container:", e);
1690
+ }
1691
+ setPortalContainer(null);
1692
+ };
1693
+ }, []);
1694
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1695
+ ref: containerRef,
1696
+ className: `isolated-shop-wrapper ${className} h-full`,
1697
+ children: portalContainer && (0, react_dom.createPortal)(/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
1698
+ cartScript,
1699
+ cartWidget,
1700
+ children
1701
+ ] }), portalContainer)
1702
+ }) });
1703
+ }
1704
+ //#endregion
1553
1705
  //#region src/screens/ShopScreen.tsx
1554
1706
  function ShopScreen({ background, textColor, accentColor, padding, borderRadius, ...divProps }) {
1555
1707
  const { config } = require_FluidProvider.useFluidContext();
1556
1708
  const domainClient = require_use_account_clients.useSdkClient();
1709
+ const { token } = require_use_account_clients.useFluidAuth();
1557
1710
  const { data: userData } = require_use_current_user.useCurrentUser();
1558
1711
  const { currentSlug, navigate } = require_AppNavigationContext.useAppNavigation();
1559
1712
  const countryCode = config.countryIso ?? userData?.country?.iso ?? "US";
1713
+ const subdomain = userData?.company?.subdomain;
1560
1714
  require_ScreenHeaderContext.useScreenHeaderBreadcrumbs((0, react.useMemo)(() => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.Breadcrumb, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.BreadcrumbList, {
1561
1715
  className: "text-lg",
1562
1716
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.BreadcrumbItem, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.BreadcrumbPage, {
@@ -1564,18 +1718,29 @@ function ShopScreen({ background, textColor, accentColor, padding, borderRadius,
1564
1718
  children: "Shop"
1565
1719
  }) })
1566
1720
  }) }), []));
1721
+ require_ScreenHeaderContext.useScreenHeaderActions((0, react.useMemo)(() => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1722
+ className: "flex items-center gap-4",
1723
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CartButton, {})
1724
+ }), []));
1567
1725
  const productId = currentSlug.split("/")[1] ?? null;
1568
1726
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1569
1727
  ...divProps,
1570
1728
  className: `h-full ${divProps.className ?? ""}`,
1571
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ProductsCoreProvider, {
1572
- client: domainClient,
1573
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ShopApp, {
1574
- countryCode,
1575
- companyLogoUrl: userData?.company?.logo_url,
1576
- productId,
1577
- onSelectProduct: (id) => navigate(`shop/${id}`),
1578
- onBack: () => navigate("shop")
1729
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ShopContainer, {
1730
+ cartScript: subdomain ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CartScript, {
1731
+ subdomain,
1732
+ authJwt: token ?? void 0
1733
+ }) : null,
1734
+ cartWidget: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CartWidget, {}),
1735
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ProductsCoreProvider, {
1736
+ client: domainClient,
1737
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ShopApp, {
1738
+ countryCode,
1739
+ companyLogoUrl: userData?.company?.logo_url,
1740
+ productId,
1741
+ onSelectProduct: (id) => navigate(`shop/${id}`),
1742
+ onBack: () => navigate("shop")
1743
+ })
1579
1744
  })
1580
1745
  })
1581
1746
  });
@@ -1603,4 +1768,4 @@ Object.defineProperty(exports, "shopScreenPropertySchema", {
1603
1768
  }
1604
1769
  });
1605
1770
 
1606
- //# sourceMappingURL=ShopScreen-qgOXPdUf.cjs.map
1771
+ //# sourceMappingURL=ShopScreen-D-1WO4sB.cjs.map