import { P as ProductIdentifier, a as ProductFields } from '../payloads-BYtydfZU.js'; import { E as EventBus } from '../event-bus-Cuy2o5Z5.js'; import { C as CartItemMapper } from '../types-DuZsYlDx.js'; export { C as CartApiInterceptorOptions, I as InterceptedCartItem, i as installCartApiInterceptor } from '../cart-api-interceptor-BYMudDk-.js'; /** * Cart Emitter * * Bridges @shopkit/cart's CartEvent system to the EventBus. * Subscribes via the onCartEvent callback in CartConfig. * * CartEvent types (from @shopkit/cart): * - ADD_TO_CART → emits AddToCart * - UPDATE_QUANTITY (increase) → emits AddToCart * * NO changes to @shopkit/cart required. */ /** * CartEvent type matching @shopkit/cart's CartEvent discriminated union. * Defined here to avoid build dependency on @shopkit/cart. */ type CartEvent = { type: "CART_INITIALIZED"; cartToken: string; } | { type: "ADD_TO_CART"; item: CartItemLike; } | { type: "REMOVE_FROM_CART"; item: CartItemLike; } | { type: "UPDATE_QUANTITY"; item: CartItemLike; previousQuantity: number; } | { type: "CLEAR_CART"; itemCount: number; } | { type: "CART_OPENED"; } | { type: "CART_CLOSED"; } | { type: "CART_ERROR"; action: string; error: string; }; interface CartItemLike { id: string; productId?: string; product_id?: string; variantId?: string; variant_id?: string; sku?: string; title: string; price: number | { amount: number; currencyCode: string; }; compareAtPrice?: number | { amount: number; currencyCode: string; }; quantity: number; image?: string; vendor?: string; product_type?: string; } interface CartEmitterOptions { /** Product identifier strategy for content_ids. Default: "product_id" */ productIdentifier?: ProductIdentifier; } /** * Creates a cart event handler function that maps CartEvents to OpenStoreEvents. * * Usage in bootstrap/cart.ts: * ```ts * import { eventBus } from '@shopkit/events'; * import { createShopifyCartMapper } from '@shopkit/events/mappers'; * import { createCartEventHandler } from '@shopkit/events/emitters'; * * const mapper = createShopifyCartMapper('INR'); * const handleCartEvent = createCartEventHandler(eventBus, mapper); * * configureCart({ * // ...existing config... * onCartEvent: handleCartEvent, * }); * ``` */ declare function createCartEventHandler(bus: EventBus, mapper: CartItemMapper, options?: CartEmitterOptions): (event: CartEvent) => void; /** * Page Emitter * * React component that automatically emits page_view events * on every Next.js route change. The storefront never calls this — * it's rendered once by EventProvider in the root layout. * * Features: * - Debounces rapid route changes * - Skips same-path navigations * - Detects page type from path (home, product, collection, etc.) */ interface PageEmitterProps { /** EventBus instance to emit on */ bus: EventBus; /** Current pathname (from usePathname()) */ pathname: string; } /** * PageEmitter component — emits page_view on pathname change only. * * Search params (variant, query, filters) are intentionally ignored. * Changing ?variant=A to ?variant=B is the same product page — sending * Meta PageView on every variant selection inflates analytics and distorts * attribution. * * Must be rendered inside EventProvider which passes pathname * from Next.js usePathname() hook. */ declare function PageEmitter({ bus, pathname }: PageEmitterProps): null; /** * Product Emitter * * React hook that emits ViewContent when a product page is viewed. * Uses the EventBus singleton directly — no React context needed. * * Usage in product pages: * ```tsx * import { useProductViewEmitter } from '@shopkit/events/emitters'; * * function ProductPage({ product }) { * useProductViewEmitter(productFields); * return
...
; * } * ``` */ /** * Hook that emits ViewContent when a product is viewed. * Uses the eventBus singleton directly — avoids React context * boundary issues across separate tsup entry points. * * @param product - ProductFields to track (null = no tracking) * @param options - Optional configuration */ declare function useProductViewEmitter(product: ProductFields | null, options?: { /** Name of the list this product was viewed from (e.g., "Search Results") */ listName?: string; }): void; /** * Search Emitter * * Factory function that returns a handler for emitting search events. * NOT a React component — used by app search forms directly. * * Features: * - Emits OpenStoreEventType.SEARCH with search_term and optional results_count * - Built-in 2-second dedup: ignores identical search_term within window * - Empty/whitespace-only search terms are ignored */ /** * Create a search event handler with built-in 2-second deduplication. * * @param bus - EventBus instance to emit on * @returns Handler function that emits search events * * @example * ```ts * const handleSearch = createSearchEventHandler(bus); * * // In search form onSubmit: * handleSearch(query, resultCount); * ``` */ declare function createSearchEventHandler(bus: EventBus): (searchTerm: string, resultsCount?: number) => void; /** * Checkout Emitter — GoKwik Integration * * React component that listens for postMessage events from the GoKwik * checkout iframe and maps them to standardized analytics events. * * GoKwik postMessage event types (captured from live integration): * * | GoKwik type | eventName | Mapped To | * |------------------|----------------------|----------------------| * | analyticsEvent | otpVerifiedGk | CompleteRegistration | * | analyticsEvent | CheckoutInitiated | InitiateCheckout | * | analyticsEvent | ShippingInfoAdded | AddShippingInfo | * | analyticsEvent | PaymentInfoAdded | AddPaymentInfo | * | analyticsEvent | Purchase | Purchase | * * Features: * - Origin validation: only processes messages from GoKwik domains * - Step deduplication: only emits once per checkout step * - Purchase dedup keyed on order_id and persisted across reloads (localStorage) * - queueMicrotask deferral to avoid INP impact during checkout burst * * Note: GoKwik prices are already in rupees (not paise). No division needed. * Note: GoKwik inconsistently uses `items` vs `line_items` across events. * Note: After coupons, item `price` may be 0 — use `mrp` as fallback for item_price. */ interface CheckoutEmitterProps { /** EventBus instance to emit on */ bus: EventBus; /** Allowed origins for GoKwik messages (default: gokwik.co, gokwik.com) */ allowedOrigins?: string[]; } declare function CheckoutEmitter({ bus, allowedOrigins, }: CheckoutEmitterProps): null; /** * Login Emitter — GoKwik KwikPass Integration * * React component that listens for postMessage events from login * provider iframes (e.g., GoKwik KwikPass) and maps them to * standardized analytics events. * * Currently supported: * * | Provider | Message type | Mapped To | * |------------|-------------|----------------------| * | KwikPass | kp_token | CompleteRegistration | * * Features: * - Origin validation: only processes messages from allowed domains * - Session deduplication: only emits CompleteRegistration once per mount * - Sets window.__openstore_user for UserEnricher PII hashing * - queueMicrotask deferral to avoid INP impact * * Note: Checkout OTP login (otpVerifiedGk) is handled by CheckoutEmitter, * not this emitter. This emitter handles explicit site login only. */ interface LoginEmitterProps { /** EventBus instance to emit on */ bus: EventBus; /** Allowed origins for login provider messages (default: gokwik.co, gokwik.com) */ allowedOrigins?: string[]; } declare function LoginEmitter({ bus, allowedOrigins, }: LoginEmitterProps): null; /** * KwikCart Emitter — GoKwik KwikCart Side Cart Integration * * React component that listens for postMessage events from the KwikCart * side cart and maps them to standardized analytics events. * * KwikCart postMessage format: * { name: "auto_add_to_cart", body: { event, eventType, itemsAdded, items, ... } } * * Captured events: * * | eventType | Mapped To | Description | * |--------------------|-------------|--------------------------------| * | increase_quantity | AddToCart | User clicks "+" in side cart | * * Features: * - Origin validation: only processes messages from allowed domains * - queueMicrotask deferral to avoid INP impact * * Note: KwikCart prices are in paise — divide by 100 for rupees. */ interface KwikCartEmitterProps { /** EventBus instance to emit on */ bus: EventBus; /** Allowed origins for KwikCart messages (default: same-origin) */ allowedOrigins?: string[]; } declare function KwikCartEmitter({ bus, allowedOrigins }: KwikCartEmitterProps): null; export { type CartEmitterOptions, CheckoutEmitter, type CheckoutEmitterProps, KwikCartEmitter, type KwikCartEmitterProps, LoginEmitter, type LoginEmitterProps, PageEmitter, type PageEmitterProps, createCartEventHandler, createSearchEventHandler, useProductViewEmitter };