import { Result , TaggingInfo } from '@empathyco/x-types' ; import { namespacedWireCommit , namespacedWireDispatch } from '../../wiring/namespaced-wires.factory' ; import { namespacedDebounce } from '../../wiring/namespaced-wires.operators' ; import { wireServiceWithoutPayload } from '../../wiring/wires.factory' ; import { filter } from '../../wiring/wires.operators' ; import { Wire } from '../../wiring/wiring.types' ; import { createWiring } from '../../wiring/wiring.utils' ; import { DefaultSessionService } from './service/session.service' ; /**
 * `tagging`  XModuleName .
 *
 *  internal const moduleName = 'tagging' ; /**
 * Debounce function for the module.
 */ const moduleDebounce = namespacedDebounce ( moduleName ) ; /**
 * WireCommit for  TaggingXModule .
 *
 *  internal const wireCommit = namespacedWireCommit ( moduleName ) ; /**
 * WireDispatch for  TaggingXModule .
 *
 *  internal const wireDispatch = namespacedWireDispatch ( moduleName ) ; /**
 * Wires without payload factory for  DefaultSessionService .
  const wireSessionServiceWithoutPayload = wireServiceWithoutPayload ( DefaultSessionService . instance ) ; public const clearSessionWire = filter ( wireSessionServiceWithoutPayload ( 'clearSessionId' ) , ( { eventPayload : consent } ) => ! consent ) ; public export const setConsent = wireCommit ( 'setConsent' ) ; public export const setQueryTaggingDebounce = wireCommit ( 'setQueryTaggingDebounce' ) ; public export const setSessionDuration = wireCommit ( 'setSessionDuration' ) ; public export const trackQueryWire = wireDispatch ( 'track' ) ; public export const setQueryTaggingInfo = moduleDebounce ( wireCommit ( 'setQueryTaggingInfo' ) , ( { state } ) => state . config . queryTaggingDebounceMs , { cancelOn : 'UserClearedQuery' , forceOn : [ 'UserClickedAResult' , 'UserClickedAPromoted' , 'UserClickedABanner' , 'UserClickedARedirection' , 'UserReachedResultsListEnd' ] } ) ; public export const trackResultClickedWire = createTrackResultWire ( 'click' ) ; public export const trackAddToCartWire = createTrackResultWire ( 'add2cart' ) ; param property returns internal function createTrackResultWire ( property ) { return filter ( wireDispatch ( 'track' , ( { eventPayload : { tagging } , metadata : { location } } ) => { const taggingInfo = tagging [ property ] ; taggingInfo . params . location = location as string ; return taggingInfo ; } ) , ( { eventPayload : { tagging } } ) => ! ! tagging ?. [ property ] ) ; } /**
 * Wiring configuration for the  TaggingXModule .
 *
 *  internal export const taggingWiring = createWiring ( { ConsentProvided : { setConsent } , ConsentChanged : { clearSessionWire } , QueryTaggingDebounceProvided : { setQueryTaggingDebounce } , SearchTaggingChanged : { setQueryTaggingInfo } , SearchTaggingReceived : { trackQueryWire } , SessionDurationProvided : { setSessionDuration } , UserClickedAResult : { trackResultClickedWire } , UserClickedResultAddToCart : { trackAddToCartWire } } ) ;