import { ShopCart, ShopAddress } from '../types.cjs'; export { f as formatMoney } from '../format-C-jtA_-L.cjs'; /** * F136 Phase 1 — Browser-side cart client. * * Talks to the cart HTTP handlers via fetch + JSON. Keeps a lightweight * `CustomEvent` stream so multiple islands on the same page (header * badge, cart drawer, mini-cart) stay in sync without a global state * library. * * Usage from inside an island: * import { ShopClient } from '@webhouse/cms-shop/islands'; * const shop = new ShopClient({ basePath: '/api/shop' }); * await shop.add({ productId, currency: 'DKK', quantity: 1 }); */ interface ShopClientOptions { /** Base path where cart endpoints are mounted. Default: `/api/shop`. */ basePath?: string; /** Custom fetch (testing). Default: globalThis.fetch. */ fetchFn?: typeof fetch; } interface AddPayload { productId: string; currency: string; quantity?: number; variantId?: string; locale?: string; } declare class ShopClient { private base; private fetchFn; private current; constructor(opts?: ShopClientOptions); get cart(): ShopCart | null; on(handler: (cart: ShopCart | null) => void): () => void; private dispatch; private request; refresh(): Promise; add(payload: AddPayload): Promise; update(productId: string, quantity: number, variantId?: string): Promise; remove(productId: string, variantId?: string): Promise; setEmail(email: string): Promise; setAddress(address: ShopAddress): Promise; clear(): Promise; checkout(): Promise<{ url: string; } | { error: string; }>; } declare const SHOP_CART_EVENT = "cms-shop:cart-changed"; /** * F136 Phase 1 — Product card island. * * Mounts inside any element with `data-cms-shop="product-card"`. The * server-rendered markup carries product id + currency in data * attributes; the island wires up the "Add to cart" button. * * Usage: *
* * *
* */ interface MountProductCardsOptions extends ShopClientOptions { /** CSS selector for product card root elements. */ selector?: string; /** Optional callback after successful add — useful for opening the cart drawer. */ onAdded?(productId: string): void; } declare function mountProductCards(opts?: MountProductCardsOptions): () => void; /** * F136 Phase 1 — Cart island. * * Renders into any element with `data-cms-shop="cart"`. Subscribes to * cart changes and re-renders. Includes a Checkout button that POSTs to * `/api/shop/checkout` and redirects to Stripe. * *
* * Styling: minimal inline classes prefixed `cms-shop-` so consumers can * target them from their own CSS. We avoid pulling in any external CSS * — sites style their own shop. */ interface MountCartOptions extends ShopClientOptions { selector?: string; /** Locale for currency formatting. Default: cart.locale or 'da-DK'. */ locale?: string; /** Strings — override for i18n. */ labels?: Partial; } declare const DEFAULT_LABELS$1: { empty: string; remove: string; subtotal: string; shipping: string; tax: string; total: string; checkout: string; checkoutLoading: string; checkoutFailed: string; }; declare function mountCart(opts?: MountCartOptions): () => void; /** * F136 Phase 1 — Checkout status island. * * For the success/cancel page after Stripe redirects back. Reads * `?session_id=…` from the URL, calls `/api/shop/checkout/session/:id` * to look up status, renders one of three states. * *
* * The host MUST mount a `/api/shop/checkout/session/:id` endpoint that * returns `{ status: 'paid' | 'pending' | 'failed', orderSlug?: string }` * — Phase 1 doesn't ship that endpoint inside the npm package because * order persistence is host-side. */ interface MountCheckoutStatusOptions { selector?: string; basePath?: string; labels?: Partial; /** Optional callback when paid — host can clear local cart UI / track conversion. */ onPaid?(orderSlug?: string): void; } declare const DEFAULT_LABELS: { loading: string; paid: string; pending: string; failed: string; retry: string; noSession: string; orderNumber: string; }; declare function mountCheckoutStatus(opts?: MountCheckoutStatusOptions): () => void; /** * F136 Phase 1 — Browser-side shop islands. * * Mount-and-go widgets the host site loads on its product / cart / * checkout pages. Each island is a function that scans the document * for its mount selector and wires up event handlers; the cart-changed * `CustomEvent` keeps multiple islands in sync without a global store. * * Convenience entry-point that mounts all three at once: * import { mountShopIslands } from '@webhouse/cms-shop/islands'; * mountShopIslands(); */ interface MountShopIslandsOptions { productCard?: MountProductCardsOptions; cart?: MountCartOptions; checkoutStatus?: MountCheckoutStatusOptions; } declare function mountShopIslands(opts?: MountShopIslandsOptions): () => void; export { type AddPayload, type MountCartOptions, type MountCheckoutStatusOptions, type MountProductCardsOptions, type MountShopIslandsOptions, SHOP_CART_EVENT, ShopClient, type ShopClientOptions, mountCart, mountCheckoutStatus, mountProductCards, mountShopIslands };