1function getNewToken(refreshEndpoint, ping_refresh_token) { 2 return fetch(refreshEndpoint + '/shop/rest/V1/refresh-access-token' + (ping_refresh_token ? ('/' + ping_refresh_token) : ''), { 3 method: 'POST', 4 headers: { 5 'Content-Type': 'application/json', 6 'X-Requested-With': 'XMLHttpRequest', 7 } 8 }) 9 .then((response) => response.json()) 10 .then((data) => { 11 return Promise.resolve({ 12 data: data 13 }); 14 }) 15 .catch((error) => { 16 return null; 17 }); 18} 19 20function chatboxObject(customerData) { 21 const intentCode = new URLSearchParams(window.location.search).get('intent'); 22 const chatConfigElement = document.getElementById('chat-config'); 23 const chatConfig = chatConfigElement ? chatConfigElement.dataset : {}; 24 const clientids = chatConfig.harmonyClientId; 25 const authChatEnabled = Boolean(chatConfig.authChatEnabled); 26 let obj; 27 if ((typeof customerData != 'undefined') && authChatEnabled === true) { 28 obj = { 29 APIHostname: chatConfig.chatHostname, 30 AppId: chatConfig.chatAppId, 31 Display: { 32 AlwaysShowMinimize: true, 33 FrameDraggable: false, 34 FrameStyle: "default", 35 }, 36 CustomerId: customerData.dish_customer_id, 37 UserLoginHandler: function () { 38 window.open('/shop/customer/account/login/', "_self") 39 }, 40 ContextProvider: async function (callback, needsRefresh) { 41 var contextObject = { 42 CompanySubdivision: chatConfig.subDivision, 43 ExternalSessionId: customerData.session_id, 44 ExternalSessionType: 'AEM', 45 Auth: { 46 Token: customerData.ping_access_token, 47 ClientId: clientids, 48 Brand: chatConfig.asappBrand, 49 } 50 }; 51 if (needsRefresh) { 52 let tokenData = await getNewToken(chatConfig.refreshEndpoint, customerData.ping_refresh_token); 53 let newToken = tokenData?.data; 54 let cache = JSON.parse(localStorage.getItem("mage-cache-storage")); 55 if (cache?.customer && newToken) { 56 cache.customer.ping_access_token = newToken; 57 localStorage.setItem("mage-cache-storage", JSON.stringify(cache)); 58 } 59 contextObject.Auth.Token = newToken; 60 } 61 callback(contextObject); 62 } 63 } 64 } else if (typeof customerData === 'undefined' || authChatEnabled == false) { 65 var dopwebSessionValue = document.cookie.split('; ').find(row => row.startsWith('dopwebSession=')).split('=')[1]; 66 var date = new Date(dopwebSessionValue); 67 var dopwebSessioninMillisec = date.getTime(); 68 69 var apiHostname = chatConfig.chatHostname; 70 var appId = chatConfig.chatAppId; 71 obj = { 72 APIHostname: apiHostname, 73 AppId: appId, 74 Display: { 75 AlwaysShowMinimize: true, 76 FrameDraggable: false, 77 FrameStyle: "default", 78 }, 79 UserLoginHandler: function () { 80 window.open('/shop/customer/account/login/', "_self") 81 }, 82 ContextProvider: function (callback) { 83 var contextObject = { 84 ExternalSessionId: dopwebSessioninMillisec.toString(), 85 ExternalSessionType: 'AEM' 86 }; 87 callback(contextObject); 88 }, 89 } 90 } 91 if (intentCode) { 92 obj.Intent = { 93 Code: intentCode, 94 } 95 } 96 return obj; 97} 98 99function loadChatScript(lazyLoad) { 100 (function (w, d, h, n, s) { 101 s = d.createElement('script'); 102 w[n] = w[n] || function () { 103 (w[n]._ = w[n]._ || []).push(arguments) 104 }, 105 w[n].Host = h, s.defer = 1, s.src = h + '/chat-sdk.js', s.type = 'text/javascript', d.body.appendChild(s), 106 s.onload = function () { 107 var customerData; 108 if (localStorage.getItem("mage-cache-storage") === null) { 109 ASAPP('load', chatboxObject(customerData)); 110 } else { 111 var storeKey = localStorage.getItem("mage-cache-storage"); 112 var parsedStoreKey = JSON.parse(storeKey); 113 customerData = parsedStoreKey.customer; 114 ASAPP('load', chatboxObject(customerData)); 115 } 116 } 117 118 }(window, document, 'https://sdk.asapp.com', 'ASAPP')); 119 120 if (lazyLoad) { 121 document.removeEventListener('click', lazyLoadChatScript); 122 document.removeEventListener('mousemove', lazyLoadChatScript); 123 document.removeEventListener('keydown', lazyLoadChatScript); 124 document.removeEventListener('touchstart', lazyLoadChatScript); 125 } 126} 127 128function lazyLoadChatScript() { loadChatScript(true); } 129 130document.addEventListener("DOMContentLoaded", function () { 131 if (!document.cookie.split(';').some((item) => item.trim().startsWith('dopwebSession='))) { 132 var date = new Date(); 133 document.cookie = "dopwebSession=" + date + ";secure"; 134 } 135 const chatConfigElement = document.getElementById('chat-config'); 136 const chatConfig = chatConfigElement ? chatConfigElement.dataset : {}; 137 const timeout = chatConfig.asappTimeout == 'yes' ? true : false;
138 if (timeout) { 139 document.addEventListener('click', lazyLoadChatScript, { passive: true }); 140 document.addEventListener('mousemove', lazyLoadChatScript, { passive: true }); 141 document.addEventListener('keydown', lazyLoadChatScript, { passive: true }); 142 document.addEventListener('touchstart', lazyLoadChatScript, { passive: true }); 143 } else { 144 loadChatScript(false); 145 } 146});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.