import React__default, { ReactNode } from 'react'; import { E as EventBus } from '../event-bus-B5oM_0wB.mjs'; import { C as CartApiInterceptorOptions } from '../cart-api-interceptor-C_fRxz0A.mjs'; import { a as PixelConfigMap } from '../types-B9JX7zpq.mjs'; import { P as ProductIdentifier, O as OpenStoreEvent, h as OpenStoreEventType, E as EventHandler, g as OpenStoreEventMap } from '../payloads-BYtydfZU.mjs'; import '../types-BSTMkzyZ.mjs'; /** * EventProvider - Root Analytics Provider * * Initializes the EventBus with the middleware pipeline, renders * emitters (PageEmitter, CheckoutEmitter), and optionally activates * the V2 Pixel Runtime for SDK self-registration. * * Should be rendered ONCE in the root layout, wrapping the entire app. * * Usage: * ```tsx * // app/layout.tsx * import { EventProvider } from '@shopkit/events/react'; * * export default function RootLayout({ children }) { * return ( * * * * {children} * * * * ); * } * ``` */ /** * Hook to access the EventBus singleton. * Uses the globalThis singleton directly — no React context needed. */ declare function useEventBus(): EventBus; /** * Hook to access the configured product identifier strategy. * Returns "product_id" | "sku" | "variant_id". Default: "product_id". * Reads directly from the EventBus singleton. */ declare function useProductIdentifier(): ProductIdentifier; interface EventProviderConfig { /** Enable dev tools (event log, console logging). Default: auto-detect from NODE_ENV */ enableDevTools?: boolean; /** Custom EventBus instance (for testing). Default: singleton */ bus?: EventBus; /** Allowed origins for GoKwik checkout/login messages */ checkoutOrigins?: string[]; /** Allowed origins for KwikCart side cart messages (default: same-origin) */ kwikCartOrigins?: string[]; /** Product identifier strategy for Meta Ads content_ids. Default: "product_id" */ productIdentifier?: ProductIdentifier; /** * Cart API interceptor — the sole source of AddToCart. Patches fetch/XHR so * cart mutations are tracked whether they come from @shopkit/cart, a theme * form, or a third-party app. Pass `false` to disable. Default: enabled. */ cartApi?: false | (CartApiInterceptorOptions & { /** Currency used when the cart response carries none. Default: "INR" */ currency?: string; /** * Divisor for minor-unit prices. The OS cart API returns paise * (price: 800 = ₹8.00), so this defaults to 100. Set to 1 for a * backend that already returns major units. */ priceDivisor?: number; }); /** V2 Pixel Runtime configuration. If provided, activates the self-registration runtime. */ pixelConfig?: { /** Map of SDK name → SDK config (or null to disable). Passed to runtime.activate(). */ pixels: PixelConfigMap; /** Consent gate — return true to allow, false to block */ consentCheck?: (sdkName: string, eventType: string) => boolean; /** Max queue size. Default: 200 */ maxQueueSize?: number; /** Registration window in ms. Default: 10_000 */ registrationWindowMs?: number; }; } interface EventProviderProps { /** Provider configuration */ config?: EventProviderConfig; /** Current pathname (from usePathname()) — required for page view tracking */ pathname?: string; /** Current search params (from useSearchParams()?.toString()) */ searchParams?: string; /** Children */ children: ReactNode; } /** * EventProvider — Root analytics provider. * * Initializes the EventBus once with the full middleware pipeline: * 1. Schema Validator (Zod) * 2. Deduplicator (2s window) * 3. User Enricher (cookies + PII hash) * 4. Dev Logger (console in dev) * * Uses bus.initialized flag (on the EventBus itself) to prevent * double-registration of middleware if EventProvider remounts * (e.g., React Strict Mode, error boundaries, route changes). * * Always renders: * - PageEmitter for automatic PageView tracking (requires pathname prop) * - CheckoutEmitter for GoKwik checkout events * - LoginEmitter for GoKwik KwikPass login events * * Optionally activates V2 PixelRuntime for SDK self-registration. */ declare function EventProvider({ config, pathname, searchParams, children, }: EventProviderProps): React__default.JSX.Element; /** * React Hooks for Event System * * Convenience hooks that wrap EventBus operations with React lifecycle management. * All hooks use the EventBus from EventProvider context. */ /** * Hook to emit events. Returns a stable `emit` function. * * Usage: * ```tsx * const emit = useTrackEvent(); * emit(OpenStoreEventType.SEARCH, { search_string: 'shoes', results_count: 42 }); * ``` */ declare function useTrackEvent(): (type: K, data: K extends keyof OpenStoreEventMap ? OpenStoreEventMap[K] : unknown, overrides?: Partial>) => OpenStoreEvent | null; /** * Hook to subscribe to a specific event type. * Automatically unsubscribes on unmount. * * Usage: * ```tsx * useEventSubscribe(OpenStoreEventType.ADD_TO_CART, (event) => { * console.log('Item added:', event.data.items); * }); * ``` */ declare function useEventSubscribe(type: K, handler: EventHandler): void; /** * Hook to subscribe to ALL events. * Automatically unsubscribes on unmount. * * Usage: * ```tsx * useEventSubscribeAll((event) => { * console.log('Event fired:', event.event_type, event.data); * }); * ``` */ declare function useEventSubscribeAll(handler: EventHandler): void; /** * Hook to access the event log (ring buffer of recent events). * Useful for debugging and the Event Inspector. * * Usage: * ```tsx * const eventLog = useEventLog(); * // eventLog is ReadonlyArray * ``` */ declare function useEventLog(): ReadonlyArray; export { EventProvider, type EventProviderConfig, type EventProviderProps, useEventBus, useEventLog, useEventSubscribe, useEventSubscribeAll, useProductIdentifier, useTrackEvent };