From 62a3ceb8c53569e50d6a697d91e43705f293295b Mon Sep 17 00:00:00 2001 From: katieoh-safelite <76531609+katieoh-safelite@users.noreply.github.com> Date: Thu, 18 Aug 2022 10:44:20 -0400 Subject: [PATCH] Revert "Defect/csr 759" --- .../heritage-integration/cookie-helper.js | 49 +++++-------------- src/helpers/unit-test-helper.js | 4 +- src/mixins/analytics-mixin.js | 8 +-- src/router/index.js | 5 +- 4 files changed, 16 insertions(+), 50 deletions(-) diff --git a/src/helpers/heritage-integration/cookie-helper.js b/src/helpers/heritage-integration/cookie-helper.js index dc1872e74..775a64fec 100644 --- a/src/helpers/heritage-integration/cookie-helper.js +++ b/src/helpers/heritage-integration/cookie-helper.js @@ -9,6 +9,9 @@ export function updateOrCreateFunnelCookie() { const wasClaimRegistrationDelayed = getFunnelCookie()?.HasDelayedClaimRegistration; const shouldSuppressConceptFunnel = getFunnelCookie()?.SuppressConceptFunnel; + // Create the cookie + document.cookie = `${cookieNames.FUNNEL_SESSION_INFO}={}; path=${applicationConfig.COOKIE_PATH}; ${getCookieDomainValue()};`; + // Set up cookie with all the props. setFunnelCookieProperties({ LastTouched: new Date().toUTCString(), @@ -45,14 +48,14 @@ export function getFunnelCookie() { Removes cookie from browser. */ export function deleteFunnelCookie() { - createOrUpdateCookie(cookieNames.FUNNEL_SESSION_INFO, undefined, { maxAge: 0 }); + document.cookie = `${cookieNames.FUNNEL_SESSION_INFO}=; Max-Age=0; path=${applicationConfig.COOKIE_PATH}; ${getCookieDomainValue()}`; } /* Gets cookie domain value. Localhost will be empty "". */ export function getCookieDomainValue() { - return isLocalhost() ? "" : `domain=${getDomainWithoutSubdomain()};`; + return location.hostname.includes("localhost") ? "" : `domain=${getDomainWithoutSubdomain()};`; } /* @@ -103,17 +106,10 @@ export function getSessionIdValue(){ return '00000000-0000-0000-0000-000000000000'; } -/* - Updates session ID cookie with new expiration date -*/ -export function updateSessionIdCookie() { - createOrUpdateCookie(cookieNames.SESSION_ID, getSessionIdValue(), { maxAge: 60 * 30 }); -} - -export function setCookieProperties(properties, { useDefaultFunnelCookieAttributes = true, maxAge, isSecure }) { +export function setCookieProperties(properties) { if (typeof properties == "object") { Object.keys(properties).forEach(key => { - createOrUpdateCookie(key, properties[key], { useDefaultFunnelCookieAttributes, maxAge, isSecure }); + document.cookie = `${key}=${properties[key]}`; }); } } @@ -138,38 +134,19 @@ function setFunnelCookieProperties(properties) { cookie[key] = properties[key]; }); - const cookieValueJson = JSON.stringify(cookie); - createOrUpdateCookie(cookieNames.FUNNEL_SESSION_INFO, cookieValueJson, {}); + const cookieValueJson = JSON.stringify(cookie); + + document.cookie = `${cookieNames.FUNNEL_SESSION_INFO}=${cookieValueJson}; path=${applicationConfig.COOKIE_PATH}; ${getCookieDomainValue()}`; } } } -/* - Used to create a cookie. - `useDefaultFunnelCookieAttributes` will set the path and domain to our defaults -*/ -function createOrUpdateCookie(key, value = "", { useDefaultFunnelCookieAttributes = true, maxAge, isSecure = true }) { - let cookieToAdd = `${key}=${value}; `; - - if (useDefaultFunnelCookieAttributes) { - cookieToAdd += `path=${applicationConfig.COOKIE_PATH}; ${getCookieDomainValue()} `; - } - if (isSecure && !isLocalhost()) { - cookieToAdd += `secure; `; - } - if (!isNaN(maxAge)) { - cookieToAdd += `max-age=${maxAge};`; - } - - document.cookie = cookieToAdd; -} - /* Gets current domain without the subdomain for cookie. */ function getDomainWithoutSubdomain() { let url = location.hostname; - if (isLocalhost()) { + if (url.includes("localhost")) { return "localhost"; } @@ -192,8 +169,4 @@ function getCookieValueByName(name) { return parts.pop().split(";").shift(); } return ""; -} - -function isLocalhost() { - return location.hostname.includes("localhost"); } \ No newline at end of file diff --git a/src/helpers/unit-test-helper.js b/src/helpers/unit-test-helper.js index cc00e49d9..67a3dc8ae 100644 --- a/src/helpers/unit-test-helper.js +++ b/src/helpers/unit-test-helper.js @@ -6,7 +6,7 @@ import { fmgPageValues } from "@/router/router-constants/fmgPage-values"; import { cookieNames } from "@/constants/cookie-names"; import { Form } from "vee-validate"; import baseMixin from "@/mixins/base-mixin"; -import { getCookieDomainValue, setCookieProperties } from "@/helpers/heritage-integration/cookie-helper"; +import { getCookieDomainValue } from "@/helpers/heritage-integration/cookie-helper"; import { analyticsPageEvents, GaCategories, GaActions, GaLabels, GaEvents, ValueToLogTypes } from "@/constants/analytics"; import { queryStrings } from "@/constants/query-strings"; import { routerParams } from "@/router/router-constants/router-params"; @@ -106,7 +106,7 @@ export function setupCookies({ funnelCookieValue = "", includeHeritageCookie = t Object.keys(cookies).forEach(key => { const cookieValue = key == cookieNames.FUNNEL_SESSION_INFO ? funnelCookieValue : cookies[key]; if (includeHeritageCookie || key != cookieNames.FUNNEL_SESSION_INFO) - setCookieProperties({ [key]: cookieValue }, { isSecure: false }); + document.cookie = `${key}=${cookieValue}; path=/; ${getCookieDomainValue()}`; }); } diff --git a/src/mixins/analytics-mixin.js b/src/mixins/analytics-mixin.js index 6eb18e462..142131ae1 100644 --- a/src/mixins/analytics-mixin.js +++ b/src/mixins/analytics-mixin.js @@ -126,14 +126,10 @@ export default { if (response.data) { if (response.data.sessionKey && skey === 0) { - setCookieProperties({ [cookieNames.SESSION_KEY]: response.data.sessionKey}, { - useDefaultFunnelCookieAttributes: false - }); + setCookieProperties({ [cookieNames.SESSION_KEY]: response.data.sessionKey}); } if (response.data.sessionId && sid === '00000000-0000-0000-0000-000000000000') { - setCookieProperties({ [cookieNames.SESSION_ID]: response.data.sessionId}, { - maxAge: 60 * 30 // 30 minutes - }); + setCookieProperties({ [cookieNames.SESSION_ID]: response.data.sessionId}); } } }, diff --git a/src/router/index.js b/src/router/index.js index 46e26baad..5b5c73d75 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -10,7 +10,7 @@ import { getDeviceIdValue } from "@/helpers/heritage-integration/cookie-helper"; // Heritage integration import { isSavedSessionStillActive } from "@/helpers/heritage-integration/session-helper"; -import { updateOrCreateFunnelCookie, getFunnelCookie, updateSessionIdCookie } from "@/helpers/heritage-integration/cookie-helper"; +import { updateOrCreateFunnelCookie, getFunnelCookie } from "@/helpers/heritage-integration/cookie-helper"; import { loadOrderIfPresent, saveOrder } from "@/helpers/heritage-integration/order-helper"; import { getPageToRouteExistingOrderTo, navigateToHeritageFunnel } from "@/helpers/heritage-integration/navigation-helper"; @@ -31,9 +31,6 @@ const routes = [ if (analyticsMixin.methods.noSession()) { await analyticsMixin.methods.initSession(); } - else { - updateSessionIdCookie(); - } if (getFunnelCookie()?.SuppressConceptFunnel) { await navigateToHeritageFunnel(false);