{"version":3,"file":"OneTrustHealthDataConsent.js","names":["Component","a","default","deepMerge","execute","OneTrustHealthDataConsent","element","options","arguments","length","_classCallCheck","_callSuper","personalizedAdvertisingStates","collectionPoint","enabledBazaarvoice","numberOfAttempts","_inherits","_createClass","key","value","initState","state","optanonWrapperTimer","bvTimer","afterInit","window","OneTrust","OptanonWrapper","setLayerOptanonWrapper","setInterval","tryToSetLayerOptanonWrapper","bind","clearInterval","tryToInitBazaarvoice","BV","updateBVConsent","originalOptanonWrapper","optanonWrapper","apply","OnConsentChanged","onConsentChanged","updateOptimizelyConsent","isAllowed","OnetrustActiveGroups","includes","cookieConsent","setConsent","bv_metrics","BVBRANDID","BVBRANDSID","optimizely","push","type","startSigning","collectionPointId","UpdateConsent","sessionStorage","setItem","addEventListener","onOnetrustFormLoaded","webform","InstallCP","event","detail","closeButtonSelector","document","querySelector","concat","endSigning","removeItem","checkSigning","isSignNeeded","stateCode","getGeolocationData"],"sources":["components/integration/OneTrustHealthDataConsent.js"],"sourcesContent":["import Component from 'core/Component';\nimport { deepMerge } from 'toolbox/deepMerge';\n\n/**\n * OneTrustHealthDataConsent constructor function.\n * @class\n * @classdesc This class implements the logic for updating cookies depending on whether the customer\n * has confirmed consent to the use of health data.\n * @extends Component\n */\nexport default class OneTrustHealthDataConsent extends Component {\n /**\n * Constructor of the class that mainly merge the options of the components\n * @param {HTMLElement} element HTMLElement of the component\n * @param {object} options options that belongs to the component\n */\n constructor(element, options = {}) {\n super(element, deepMerge({\n personalizedAdvertisingStates: null, // array of states\n collectionPoint: null, // collection point ID\n enabledBazaarvoice: false, // Bazaarvoice flag\n numberOfAttempts: 60, // number of attempts to set the layer handler\n }, options));\n }\n\n /**\n * Init the different state of the component\n * It helps to avoid heavy DOM manipulation\n */\n initState() {\n this.state.optanonWrapperTimer = null;\n this.state.bvTimer = null;\n this.state.numberOfAttempts = this.options.numberOfAttempts;\n }\n\n /**\n * After init\n * Run any script after the component is fully initialized\n */\n afterInit() {\n if (window.OneTrust && window.OptanonWrapper) {\n this.setLayerOptanonWrapper();\n } else {\n this.state.optanonWrapperTimer = setInterval(this.tryToSetLayerOptanonWrapper.bind(this), 1000);\n }\n }\n\n /**\n * Interval callback function that checks if window.OneTrust is initialized.\n */\n tryToSetLayerOptanonWrapper() {\n if (window.OneTrust && window.OptanonWrapper) {\n clearInterval(this.state.optanonWrapperTimer);\n this.setLayerOptanonWrapper();\n this.state.optanonWrapperTimer = null;\n } else if (this.state.numberOfAttempts > 0) {\n this.state.numberOfAttempts -= 1;\n } else {\n clearInterval(this.state.optanonWrapperTimer);\n this.state.optanonWrapperTimer = null;\n }\n }\n\n /**\n * Interval callback function that checks if window.BV is initialized.\n */\n tryToInitBazaarvoice() {\n if (window.BV) {\n clearInterval(this.state.bvTimer);\n this.updateBVConsent();\n this.state.bvTimer = null;\n }\n }\n\n /**\n * Sets layer callback function.\n */\n setLayerOptanonWrapper() {\n const originalOptanonWrapper = window.OptanonWrapper;\n\n window.OptanonWrapper = () => {\n this.optanonWrapper();\n originalOptanonWrapper.apply(this);\n };\n\n this.optanonWrapper();\n\n if (this.options.enabledBazaarvoice) {\n this.state.bvTimer = setInterval(this.tryToInitBazaarvoice.bind(this), 1000);\n }\n }\n\n /**\n * Layer callback function.\n */\n optanonWrapper() {\n window.OneTrust.OnConsentChanged(this.onConsentChanged.bind(this));\n\n this.updateOptimizelyConsent();\n }\n\n /**\n * Updates Bazarvoice consent status\n */\n updateBVConsent() {\n const isAllowed = window.OnetrustActiveGroups.includes(',3,');\n\n if (window.BV) {\n window.BV.cookieConsent.setConsent({\n bv_metrics: isAllowed,\n BVBRANDID: isAllowed,\n BVBRANDSID: isAllowed,\n });\n }\n }\n\n /**\n * Disable Optimizely consent.\n */\n updateOptimizelyConsent() {\n if (!window.OnetrustActiveGroups.includes(',3,') && window.optimizely) {\n window.optimizely.push({\n type: 'disable',\n });\n }\n }\n\n /**\n * Start signing.\n */\n startSigning() {\n const collectionPointId = this.options.collectionPoint;\n window.OneTrust.UpdateConsent('Category', '4:0');\n window.OneTrust.UpdateConsent('Category', '2:0');\n sessionStorage.setItem('signing', 'true');\n window.addEventListener('OnetrustFormLoaded', this.onOnetrustFormLoaded.bind(this));\n if (window.OneTrust.webform) {\n window.OneTrust.webform.InstallCP(collectionPointId);\n }\n }\n\n /**\n * On form loaded event handler.\n * @param {Object} event event data\n */\n onOnetrustFormLoaded(event) {\n if (event.detail[this.options.collectionPoint]) {\n const closeButtonSelector = document.querySelector(`.ot-webform${this.options.collectionPoint} button.ot-close`);\n closeButtonSelector.addEventListener('click', this.endSigning.bind(this), false);\n }\n }\n\n /**\n * End signing.\n */\n endSigning() {\n sessionStorage.removeItem('signing');\n }\n\n /**\n * Check if a customer is signed.\n * @returns {Boolean} true if signing\n */\n checkSigning() {\n return ('signing' in sessionStorage);\n }\n\n /**\n * Check if a customer need to be signed.\n * @returns {Boolean} true if need to be sign\n */\n isSignNeeded() {\n const stateCode = window.OneTrust.getGeolocationData().state;\n\n if (this.options.personalizedAdvertisingStates.includes(stateCode)) {\n return window.OnetrustActiveGroups.includes(',2,') && window.OnetrustActiveGroups.includes(',4,');\n }\n\n return false;\n }\n\n /**\n * On consent changed event handler.\n */\n onConsentChanged() {\n if (this.options.enabledBazaarvoice) {\n this.updateBVConsent();\n }\n\n if (this.options.collectionPoint && this.isSignNeeded()) {\n if (!this.checkSigning()) {\n this.startSigning();\n } else {\n this.endSigning();\n }\n }\n }\n}\n"],"mappings":"6zEAAOA,CAAS,CAAAC,CAAA,CAAAC,OAAA,WAAAD,CAAA,EACPE,CAAS,CAAAF,CAAA,CAATE,SAAS,GAAAC,OAAA,SAAAA,CAAA,EAAAH,CAAA,WASGI,CAAyB,UAAAJ,CAAA,EAM1C,SAAAI,0BAAYC,CAAO,CAAgB,IAAd,CAAAC,CAAO,GAAAC,SAAA,CAAAC,MAAA,WAAAD,SAAA,IAAAA,SAAA,IAAG,CAAC,CAAC,QAAAE,eAAA,MAAAL,yBAAA,EAAAM,UAAA,MAAA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