import { P as ProductIdentifier } from './payloads-BYtydfZU.mjs'; import { E as EventBus } from './event-bus-B5oM_0wB.mjs'; import { C as CartItemMapper } from './types-BSTMkzyZ.mjs'; /** * Cart API Interceptor * * Patches window.fetch and XMLHttpRequest to observe cart mutation calls * and emit AddToCart from them. * * Why intercept instead of subscribing to the cart store: the API is the only * place every mutation converges. Theme forms and third-party apps hit * /cart/add directly without ever touching @shopkit/cart, so a store-level * listener misses them. * * Request body tells us WHICH variant and HOW MANY. * Response body (the enriched cart) tells us title, price, currency and totals. * Both are needed, which is why this reads the response rather than observing * timing entries. */ interface InterceptedCartItem { id: string; /** Composite line key (`:`) — what /cart/change sends as id */ key?: string; productId?: string; product_id?: string; variantId?: string; variant_id?: string; sku?: string; title: string; price: number | { amount: number; currencyCode: string; }; quantity: number; image?: string; vendor?: string; product_type?: string; } interface NormalizedCartItem { id: string; key?: string; productId: string; variantId?: string; sku?: string; title: string; price: { amount: number; currencyCode: string; }; quantity: number; image?: string; vendor?: string; product_type?: string; } interface CartApiInterceptorOptions { /** Matches add-to-cart request URLs. Default: /\/cart\/add(\?|$)/ */ addPattern?: RegExp; /** * Matches quantity-change request URLs, which also carry removals as a * change to quantity 0. Default: /\/cart\/change(\?|$)/ */ updatePattern?: RegExp; /** * Matches cart reads. These emit nothing but refresh the quantity baseline, * so a later change reports the increase and not the total. * Default: /\/cart(\/get)?(\?|$)/ */ readPattern?: RegExp; /** Product identifier strategy for content_ids. Defaults to the bus setting. */ productIdentifier?: ProductIdentifier; /** Currency used when the cart response carries none. Default: "INR" */ defaultCurrency?: string; /** * Called when a cart response could not be read. Without it these failures * are silent by design — a broken interceptor must never surface to a * shopper mid-checkout. Wire it to your logger to see them. */ onError?: (error: unknown) => void; } declare function installCartApiInterceptor(bus: EventBus, mapper: CartItemMapper, options?: CartApiInterceptorOptions): () => void; export { type CartApiInterceptorOptions as C, type InterceptedCartItem as I, installCartApiInterceptor as i };