{"version":3,"file":"iframe-login-cdc8d67d.js","sources":["../../../client/src/javascripts/customer_pages/_application/iframe-login.js"],"sourcesContent":["// Import Libraries\nimport Cookies from 'js-cookie';\nimport { builderDispatch, WebUI } from '../_utils/ui';\n\nconst MESSAGE_PREFIX = /^login:/;\nconst LOGGED_IN_COOKIE_NAME = 'web-kiosk-logged-in';\n\nconst unableToUsePostMessage = (function() {\n if (navigator.appName === 'Microsoft Internet Explorer') {\n const ua = navigator.userAgent;\n const re = new RegExp('MSIE ([0-9]{1,}[.0-9]{0,})');\n return re.exec(ua) !== null;\n }\n\n if (navigator.appName === 'Netscape') {\n const ua = navigator.userAgent;\n const re = new RegExp('Trident/.*rv:([0-9]{1,}[.0-9]{0,})');\n return re.exec(ua) !== null;\n }\n})();\n\nif (window.opener) {\n // in the launchED page\n window.onLoggedIn = function(props) {\n if (unableToUsePostMessage) {\n Cookies.set(LOGGED_IN_COOKIE_NAME, props);\n\n const objWin = window.self;\n objWin.open('', '_self', '');\n objWin.close();\n } else {\n window.opener.postMessage(`login:${props}`, '*');\n window.close();\n }\n };\n}\n\nif (!window.opener) {\n // in the launchER page\n if (unableToUsePostMessage) {\n cookieListener();\n } else {\n window.addEventListener('message', messageHandler, false);\n }\n}\n\nfunction handleLoggedIn(message) {\n // in the launcher page\n const props = JSON.parse(message.replace(MESSAGE_PREFIX, ''));\n\n if (props.logged_in_user_name || props.login_path) {\n App.order.setProperties(props);\n\n if (props.csrf) {\n // Update the CSRF token meta tag with new value as the session has been reset without page-reload\n // so the current token is invalid\n document\n .querySelector('[name=\"csrf-token\"]')\n .setAttribute('content', props.csrf);\n $.rails.refreshCSRFTokens();\n }\n\n builderDispatch.dispatch({\n type: WebUI.LOGIN,\n basketPath: props.basket_path,\n prodigal: props.prodigal,\n previous_basket_contents: props.previous_basket_contents,\n wmb_user_account_incomplete: props.wmb_user_account_incomplete,\n });\n }\n}\n\nfunction cookieListener() {\n // poll to see if the other end has posted the cookie\n Cookies.remove(LOGGED_IN_COOKIE_NAME);\n const tmr = window.setInterval(checkForLogin, 500);\n\n function checkForLogin() {\n const message = Cookies.get(LOGGED_IN_COOKIE_NAME);\n if (message) {\n handleLoggedIn(message);\n window.clearTimeout(tmr);\n }\n }\n}\n\nfunction messageHandler(event) {\n const ORIGINS = [\n `${window.location.origin}`.replace(/^http:/, 'https:'),\n `${window.location.origin}`.replace(/^https:/, 'http:'),\n ];\n\n const message = event.data;\n\n if (isLoginMessage()) {\n handleLoggedIn(message);\n }\n\n function isLoginMessage() {\n return (\n ORIGINS.indexOf(event.origin) > -1 &&\n typeof message === 'string' &&\n MESSAGE_PREFIX.test(message)\n );\n }\n}\n"],"names":["MESSAGE_PREFIX","LOGGED_IN_COOKIE_NAME","unableToUsePostMessage","ua","props","Cookies","objWin","cookieListener","messageHandler","handleLoggedIn","message","builderDispatch","WebUI","tmr","checkForLogin","event","ORIGINS","isLoginMessage"],"mappings":"wFAIA,MAAMA,EAAiB,UACjBC,EAAwB,sBAExBC,EAA0B,UAAW,CACzC,GAAI,UAAU,UAAY,8BAA+B,CACvD,MAAMC,EAAK,UAAU,UAErB,OADW,IAAI,OAAO,4BAA4B,EACxC,KAAKA,CAAE,IAAM,IACxB,CAED,GAAI,UAAU,UAAY,WAAY,CACpC,MAAMA,EAAK,UAAU,UAErB,OADW,IAAI,OAAO,oCAAoC,EAChD,KAAKA,CAAE,IAAM,IACxB,CACH,IAEI,OAAO,SAET,OAAO,WAAa,SAASC,EAAO,CAClC,GAAIF,EAAwB,CAC1BG,EAAQ,IAAIJ,EAAuBG,CAAK,EAExC,MAAME,EAAS,OAAO,KACtBA,EAAO,KAAK,GAAI,QAAS,EAAE,EAC3BA,EAAO,MAAK,CAClB,MACM,OAAO,OAAO,YAAY,SAASF,CAAK,GAAI,GAAG,EAC/C,OAAO,MAAK,CAElB,GAGK,OAAO,SAENF,EACFK,IAEA,OAAO,iBAAiB,UAAWC,EAAgB,EAAK,GAI5D,SAASC,EAAeC,EAAS,CAE/B,MAAMN,E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