From 9ea4322701e8653d1d21c91e8cadfad7cc5e2d51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20Sch=C3=BCrch?= Date: Fri, 24 Jan 2025 13:24:04 +0100 Subject: [PATCH 1/3] chore(header): replace persistedState data with design-system message --- .../src/assets/js/klp-login-widget.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/internet-header/src/assets/js/klp-login-widget.js b/packages/internet-header/src/assets/js/klp-login-widget.js index caebc6c8db..0972dfbcc5 100644 --- a/packages/internet-header/src/assets/js/klp-login-widget.js +++ b/packages/internet-header/src/assets/js/klp-login-widget.js @@ -697,13 +697,12 @@ const vertx = window.vertx || {}; if (isHTML5StorageSupported()) { sessionStorage.setItem( persistedStateKey, - '{"ttl": ' + - (new Date().getTime() + ttl) + - ',"sessionData": ' + - JSON.stringify(sessionData) + - ', "address":"' + - address + - '"}', + JSON.stringify({ + ttl: new Date().getTime() + ttl, + sessionData: + "If you're looking for this info, contact the Swiss Post Design System Team!", + address: "If you're looking for this info, contact the Swiss Post Design System Team!", + }), ); log('State persisted'); setControlCookie('hash', encodeURIComponent(hash(sessionData))); From e55ec66b6a0636d10179f2a94d7d6430c98b17ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20Sch=C3=BCrch?= Date: Fri, 24 Jan 2025 13:25:23 +0100 Subject: [PATCH 2/3] chore(header): remove everything which is restoring persistedState related --- .../src/assets/js/klp-login-widget.js | 83 ------------------- 1 file changed, 83 deletions(-) diff --git a/packages/internet-header/src/assets/js/klp-login-widget.js b/packages/internet-header/src/assets/js/klp-login-widget.js index 0972dfbcc5..2299c94da9 100644 --- a/packages/internet-header/src/assets/js/klp-login-widget.js +++ b/packages/internet-header/src/assets/js/klp-login-widget.js @@ -650,49 +650,6 @@ const vertx = window.vertx || {}; isUserActive = true; } - function restoreState() { - const state = loadPersistedState(); - if (state) { - address = state.address; - retrySubscribeOnFail = true; - sessionData = state.sessionData; - renderWidget(); - if (isCurrentLocationPostCh()) { - renderNotificationsWidget(loadDocumentFromCache(documentUnreadNotifications)); - } - } - } - - function loadPersistedState() { - if (isHTML5StorageSupported()) { - const persistedState = sessionStorage.getItem(persistedStateKey); - if (persistedState) { - try { - const state = JSON.parse(persistedState); - if (state.ttl > new Date().getTime() && isPersistedStateValid(state.sessionData)) { - log('Valid persisted state loaded: ' + persistedState); - return state; - } else { - log('Persisted state expired or invalid'); - removePersistedState(); - setControlCookie('all', 'sub'); - } - } catch (err) { - log("Persisted state was invalid due to error '" + err + "'"); - removePersistedState(); - setControlCookie('all', 'sub'); - } - } else { - log('No persisted state found'); - removePersistedState(); - setControlCookie('all', 'sub'); - } - } else { - log('State not loaded because HTML storage not supported'); - } - return null; - } - function persistState(ttl) { if (isHTML5StorageSupported()) { sessionStorage.setItem( @@ -721,32 +678,6 @@ const vertx = window.vertx || {}; } } - function isPersistedStateValid(persistedData) { - const hashPersistedData = hash(persistedData).toString(); - const hashCookie = getControlCookieVal('hash'); - if (hashPersistedData === hashCookie) { - return true; - } - if (hashCookie === undefined && !isCurrentLocationPostCh()) { - log( - 'Cache validated because on a different host=[' + - window.location.hostname + - '] than control cookie domain=[' + - controlCookieDomain + - ']', - ); - return true; - } - log( - 'PersistedData are invalid [hashPersistedData=' + - hashPersistedData + - ',control cookie=' + - hashCookie + - ']', - ); - return false; - } - function isCurrentLocationPostCh() { return controlCookieDomainRegEx.test(window.location.hostname); } @@ -844,19 +775,6 @@ const vertx = window.vertx || {}; } } - function loadDocumentFromCache(documentType) { - const persistedKey = persistedDocumentPrefix + documentType; - if (isHTML5StorageSupported()) { - const persistedDocument = sessionStorage.getItem(persistedKey); - if (persistedDocument) { - const document = $.parseJSON(persistedDocument); - log('Document ' + documentType + ' has been read from cache with value ' + document); - return document; - } - } - return null; - } - function saveDocumentOnCache(document, documentType) { const key = persistedDocumentPrefix + documentType; if (isHTML5StorageSupported()) { @@ -1516,7 +1434,6 @@ const vertx = window.vertx || {}; } function init() { - restoreState(); subscribe(); if (conf.keepAliveOnInit && isUserAuthenticated()) { keepAliveSessionsOnInit(); From e5cf6ddfa58dbb18decd0e6f4d4790e5a2a26085 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20Sch=C3=BCrch?= Date: Fri, 24 Jan 2025 14:35:19 +0100 Subject: [PATCH 3/3] chore: add changeset --- .changeset/short-olives-sleep.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/short-olives-sleep.md diff --git a/.changeset/short-olives-sleep.md b/.changeset/short-olives-sleep.md new file mode 100644 index 0000000000..881c559669 --- /dev/null +++ b/.changeset/short-olives-sleep.md @@ -0,0 +1,6 @@ +--- +'@swisspost/internet-header': patch +--- + +Replaced `sessionData` and `address` properties in the sessionStorage item `klp.widget.state`. +If you're looking for this info, contact the Swiss Post Design System Team!