@postnord/pn-marketweb-components 2.0.113 → 2.0.114

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/cjs/{MarketWebLoginManager-2fe6a1a7.js → MarketWebLoginManager-c99961d1.js} +10 -3
  2. package/cjs/pn-language-selector_9.cjs.entry.js +3 -3
  3. package/cjs/pn-marketweb-sitefooter.cjs.entry.js +1 -1
  4. package/cjs/pn-marketweb-siteheader-login-links_2.cjs.entry.js +4 -4
  5. package/cjs/pn-marketweb-siteheader.cjs.entry.js +1 -1
  6. package/collection/components/layout-components/pn-marketweb-sitefooter/pn-marketweb-sitefooter.css +4 -0
  7. package/collection/components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader-login-links.js +2 -2
  8. package/collection/components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader-login-profileselection.js +2 -2
  9. package/collection/components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader-login.js +2 -2
  10. package/collection/components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader.stories.js +1 -1
  11. package/collection/globals/MarketWebLoginManager.js +10 -3
  12. package/custom-elements/index.js +17 -10
  13. package/esm/{MarketWebLoginManager-78e62611.js → MarketWebLoginManager-90a029bb.js} +10 -3
  14. package/esm/pn-language-selector_9.entry.js +3 -3
  15. package/esm/pn-marketweb-sitefooter.entry.js +1 -1
  16. package/esm/pn-marketweb-siteheader-login-links_2.entry.js +4 -4
  17. package/esm/pn-marketweb-siteheader.entry.js +1 -1
  18. package/esm-es5/MarketWebLoginManager-90a029bb.js +1 -0
  19. package/esm-es5/pn-language-selector_9.entry.js +1 -1
  20. package/esm-es5/pn-marketweb-sitefooter.entry.js +1 -1
  21. package/esm-es5/pn-marketweb-siteheader-login-links_2.entry.js +1 -1
  22. package/esm-es5/pn-marketweb-siteheader.entry.js +1 -1
  23. package/package.json +1 -1
  24. package/pn-market-web-components/{p-12190a80.entry.js → p-037f157d.entry.js} +1 -1
  25. package/pn-market-web-components/{p-2138ff10.system.entry.js → p-2287dd4d.system.entry.js} +1 -1
  26. package/pn-market-web-components/p-49ed9f1b.system.js +1 -0
  27. package/pn-market-web-components/{p-01d3d110.system.entry.js → p-4c5041ba.system.entry.js} +1 -1
  28. package/pn-market-web-components/p-67887512.system.js +1 -1
  29. package/pn-market-web-components/{p-f94b22d7.entry.js → p-87ffe37c.entry.js} +1 -1
  30. package/pn-market-web-components/{p-866e6e4c.system.entry.js → p-8ff1cae6.system.entry.js} +1 -1
  31. package/pn-market-web-components/{p-ee34f0e6.entry.js → p-b391533d.entry.js} +1 -1
  32. package/pn-market-web-components/{p-a6a2a32d.entry.js → p-c527fd85.entry.js} +1 -1
  33. package/pn-market-web-components/p-c858d934.js +1 -0
  34. package/pn-market-web-components/p-e4d4bb97.system.entry.js +1 -0
  35. package/pn-market-web-components/pn-market-web-components.esm.js +1 -1
  36. package/types/globals/MarketWebLoginManager.d.ts +1 -1
  37. package/umd/pn-marketweb-init.js +1 -1
  38. package/umd/pn-marketweb-salesforce.js +2 -2
  39. package/esm-es5/MarketWebLoginManager-78e62611.js +0 -1
  40. package/pn-market-web-components/p-d864da57.system.js +0 -1
  41. package/pn-market-web-components/p-da7f1b66.system.entry.js +0 -1
  42. package/pn-market-web-components/p-e999b220.js +0 -1
@@ -1 +0,0 @@
1
- var __awaiter=this&&this.__awaiter||function(e,t,o,n){function i(e){return e instanceof o?e:new o((function(t){t(e)}))}return new(o||(o=Promise))((function(o,r){function s(e){try{c(n.next(e))}catch(t){r(t)}}function a(e){try{c(n["throw"](e))}catch(t){r(t)}}function c(e){e.done?o(e.value):i(e.value).then(s,a)}c((n=n.apply(e,t||[])).next())}))};var __generator=this&&this.__generator||function(e,t){var o={label:0,sent:function(){if(r[0]&1)throw r[1];return r[1]},trys:[],ops:[]},n,i,r,s;return s={next:a(0),throw:a(1),return:a(2)},typeof Symbol==="function"&&(s[Symbol.iterator]=function(){return this}),s;function a(e){return function(t){return c([e,t])}}function c(s){if(n)throw new TypeError("Generator is already executing.");while(o)try{if(n=1,i&&(r=s[0]&2?i["return"]:s[0]?i["throw"]||((r=i["return"])&&r.call(i),0):i.next)&&!(r=r.call(i,s[1])).done)return r;if(i=0,r)s=[s[0]&2,r.value];switch(s[0]){case 0:case 1:r=s;break;case 4:o.label++;return{value:s[1],done:false};case 5:o.label++;i=s[1];s=[0];continue;case 7:s=o.ops.pop();o.trys.pop();continue;default:if(!(r=o.trys,r=r.length>0&&r[r.length-1])&&(s[0]===6||s[0]===2)){o=0;continue}if(s[0]===3&&(!r||s[1]>r[0]&&s[1]<r[3])){o.label=s[1];break}if(s[0]===6&&o.label<r[1]){o.label=r[1];r=s;break}if(r&&o.label<r[2]){o.label=r[2];o.ops.push(s);break}if(r[2])o.ops.pop();o.trys.pop();continue}s=t.call(e,o)}catch(a){s=[6,a];i=0}finally{n=r=0}if(s[0]&5)throw s[1];return{value:s[0]?s[1]:void 0,done:true}}};var MarketWebLoginManager=function(){function e(e){var t=this;if(e===void 0){e=null}var o;this.eventTarget=window!==null&&window!==void 0?window:document===null||document===void 0?void 0:document.body;this.endpoint="";this.storagePrefix="pn-user";this.baseUrls={at:"https://atportal.postnord.com/api/unified-login/backend",prod:"https://portal.postnord.com/api/unified-login/backend"};this.events={loginstatechange:"loginstatechange"};this.endpoints={authorizationEndpoint:"/authorization",tokenExchangeEndpoint:"/token",userInfoEndpoint:"/user",logoutEndpoint:"/logout"};this.keys={tokensource:"tokensource",token:"token",accessToken:"accessToken",user:"user",expire:"expire",expireDate:"expiredate"};this.overridetokenValue="overridetokenValue";this.siteUrl=window.location.origin;this.store={get:function(e){var o=window.sessionStorage.getItem("".concat(t.storagePrefix,"-").concat(e));if(!o){return o}if(o.indexOf("{")===0){try{return JSON.parse(o)}catch(n){}}if(o.indexOf(",")!==-1){return o.split(",")}return o},set:function(e,o){if(typeof o==="object"&&typeof o.length==="undefined"){window.sessionStorage.setItem("".concat(t.storagePrefix,"-").concat(e),JSON.stringify(o));return}window.sessionStorage.setItem("".concat(t.storagePrefix,"-").concat(e),o)},remove:function(e){window.sessionStorage.removeItem("".concat(t.storagePrefix,"-").concat(e))}};if(!e){return}this.eventTarget=e.eventTarget?e.eventTarget:this.eventTarget;this.endpoint=e.endpoint?e.endpoint:"".concat(window.location.protocol,"//").concat(window.location.host);(o=this.storagePrefix)!==null&&o!==void 0?o:this.storagePrefix=e.storagePrefix;if(e.userInfo){this.store.set(this.keys.user,e.userInfo);this.registerToken(this.overridetokenValue,"override")}}e.prototype.init=function(e){if(e===void 0){e=true}if(e){this.checkParameters();this.checkPNTopbar();this.checkExpireTime();if(this.store.get(this.keys.token)&&!this.store.get(this.keys.user)){this.fetchUserInfo()}this.loginStateChange()}};e.prototype.setSiteUrl=function(e){if(e){this.siteUrl=e}};e.prototype.isLoggedIn=function(e){if(e===void 0){e=false}if(e){return e}var t=this.store.get(this.keys.token)&&this.store.get(this.keys.user)?true:false;if(!t&&this.store.get(this.keys.token)===this.overridetokenValue){t=true}return t};e.prototype.registerToken=function(e,t){if(e===void 0){e=""}if(t===void 0){t="frontend"}if(!e||e===this.getToken()){return}this.clearUserData();this.store.set(this.keys.tokensource,t);this.store.set(this.keys.token,e);this.fetchUserInfo()};e.prototype.invalidateTokenOfType=function(e){if(e===void 0){e="frontend"}var t=this.store.get(this.keys.token);if(!t){return}var o=this.store.get(this.keys.tokensource);if(o!==e){return}this.clearUserData()};e.prototype.getLoginUrl=function(e){if(e===void 0){e=""}var t=window.location.href;e=e?e:t;return"".concat(this.getBaseUrl()).concat(this.endpoints.authorizationEndpoint,"?redirectionUrl=").concat(e)};e.prototype.getLogoutUrl=function(e){if(e===void 0){e=""}var t=this.siteUrl;try{var o=new URL(this.siteUrl+"");t=o.origin}catch(i){}var n=t.lastIndexOf("/")!==t.length-1;e=t+(n?"/":"")+"logout";return"".concat(e,"?logoutUrl=").concat(this.getBaseUrl()).concat(this.endpoints.logoutEndpoint,"?redirectionUrl=").concat(e,"%26authorization=").concat(this.store.get(this.keys.token))};e.prototype.getUserInfo=function(){if(this.isLoggedIn()){return this.store.get(this.keys.user)}};e.prototype.getEventTarget=function(){return this.eventTarget};e.prototype.checkExpireTime=function(){var e=this.store.get(this.keys.expire);if(!e){return}var t=new Date;var o=new Date(Math.floor(parseInt(e,10)*1e3));if(t>o){console.info("Login time has expired");this.clearUserData();this.loginStateChange()}};e.prototype.checkPNTopbar=function(){if(this.isLoggedIn()||!window["pnTopbar"]||!window["pnTopbar"]["session_id"]){return}this.store.set(this.keys.token,window["pnTopbar"]["session_id"]);this.fetchUserInfo()};e.prototype.checkParameters=function(){if(!(window===null||window===void 0?void 0:window.location)){return}var e=new URLSearchParams(window.location.search);if(e.get("oneTimeCode")){var t=e.get("oneTimeCode");this.exchangeToken(t).then((function(){var e=window.location.href;var o=e.indexOf("?oneTimeCode")!==-1?"?":"&";var n=e.replace("".concat(o,"oneTimeCode=").concat(t),"");history.replaceState({},document.querySelector("title").innerText,n)}))}};e.prototype.fetchUserInfo=function(){return __awaiter(this,void 0,void 0,(function(){var e,t,o,n,i,r,s,a;return __generator(this,(function(c){switch(c.label){case 0:e=this.store.get(this.keys.token);if(this.store.get(this.keys.token)===this.overridetokenValue){console.info("Did not fetch user data since it was set by an override");return[2]}t={method:"GET",headers:{Accept:"application/json","Content-Type":"application/json",Authorization:e}};return[4,fetch("".concat(this.getBaseUrl()).concat(this.endpoints.userInfoEndpoint),t)];case 1:o=c.sent();return[4,o.json()];case 2:n=c.sent();if(n&&n["idToken"]){try{i=n.idToken,r=n.expiryTime,s=n.accessToken;a=this.parseUserInfo(i);if(!a){console.error("Userdata is not valid");this.clearUserData();return[2]}this.store.set(this.keys.user,a);this.store.set(this.keys.accessToken,s);this.store.set(this.keys.expire,r);this.store.set(this.keys.expireDate,new Date(Math.floor(parseInt(r,10)*1e3)));this.loginStateChange()}catch(h){console.error("Unable to get user information",h)}}else{console.error("Unable to get user information. Clearing login state");this.clearUserData()}return[2]}}))}))};e.prototype.clearUserData=function(){this.store.remove(this.keys.user);this.store.remove(this.keys.tokensource);this.store.remove(this.keys.accessToken);this.store.remove(this.keys.token);this.store.remove(this.keys.expire);this.store.remove(this.keys.expireDate)};e.prototype.getToken=function(){return this.store.get(this.keys.token)};e.prototype.getAccessToken=function(){return this.store.get(this.keys.accessToken)};e.prototype.exchangeToken=function(e){return __awaiter(this,void 0,void 0,(function(){var t,o;return __generator(this,(function(n){switch(n.label){case 0:this.clearUserData();return[4,fetch("".concat(this.getBaseUrl()).concat(this.endpoints.tokenExchangeEndpoint,"?oneTimeCode=").concat(e))];case 1:t=n.sent();return[4,t.json()];case 2:o=n.sent().token;if(typeof o==="string"&&o){this.store.set(this.keys.token,o)}this.fetchUserInfo();return[2]}}))}))};e.prototype.loginStateChange=function(){if(!this.eventTarget){return}this.eventTarget.dispatchEvent(new CustomEvent(this.events.loginstatechange,{detail:this.isLoggedIn()}))};e.prototype.getBaseUrl=function(){var e=this;var t=["localhost","integration.","local."];var o=t.filter((function(t){return e.endpoint.indexOf(t)!==-1})).length>0;if(o){return this.baseUrls.at}return this.baseUrls.prod};e.prototype.parseUserInfo=function(e){if(!e){return null}var t=e.split(".")[1];var o=t.replace(/-/g,"+").replace(/_/g,"/");var n=decodeURIComponent(atob(o).split("").map((function(e){return"%"+("00"+e.charCodeAt(0).toString(16)).slice(-2)})).join(""));return JSON.parse(n)};return e}();export{MarketWebLoginManager as M};
@@ -1 +0,0 @@
1
- var __awaiter=this&&this.__awaiter||function(e,t,o,n){function i(e){return e instanceof o?e:new o((function(t){t(e)}))}return new(o||(o=Promise))((function(o,r){function s(e){try{c(n.next(e))}catch(t){r(t)}}function a(e){try{c(n["throw"](e))}catch(t){r(t)}}function c(e){e.done?o(e.value):i(e.value).then(s,a)}c((n=n.apply(e,t||[])).next())}))};var __generator=this&&this.__generator||function(e,t){var o={label:0,sent:function(){if(r[0]&1)throw r[1];return r[1]},trys:[],ops:[]},n,i,r,s;return s={next:a(0),throw:a(1),return:a(2)},typeof Symbol==="function"&&(s[Symbol.iterator]=function(){return this}),s;function a(e){return function(t){return c([e,t])}}function c(s){if(n)throw new TypeError("Generator is already executing.");while(o)try{if(n=1,i&&(r=s[0]&2?i["return"]:s[0]?i["throw"]||((r=i["return"])&&r.call(i),0):i.next)&&!(r=r.call(i,s[1])).done)return r;if(i=0,r)s=[s[0]&2,r.value];switch(s[0]){case 0:case 1:r=s;break;case 4:o.label++;return{value:s[1],done:false};case 5:o.label++;i=s[1];s=[0];continue;case 7:s=o.ops.pop();o.trys.pop();continue;default:if(!(r=o.trys,r=r.length>0&&r[r.length-1])&&(s[0]===6||s[0]===2)){o=0;continue}if(s[0]===3&&(!r||s[1]>r[0]&&s[1]<r[3])){o.label=s[1];break}if(s[0]===6&&o.label<r[1]){o.label=r[1];r=s;break}if(r&&o.label<r[2]){o.label=r[2];o.ops.push(s);break}if(r[2])o.ops.pop();o.trys.pop();continue}s=t.call(e,o)}catch(a){s=[6,a];i=0}finally{n=r=0}if(s[0]&5)throw s[1];return{value:s[0]?s[1]:void 0,done:true}}};System.register([],(function(e){"use strict";return{execute:function(){var t=function(){function e(e){var t=this;if(e===void 0){e=null}var o;this.eventTarget=window!==null&&window!==void 0?window:document===null||document===void 0?void 0:document.body;this.endpoint="";this.storagePrefix="pn-user";this.baseUrls={at:"https://atportal.postnord.com/api/unified-login/backend",prod:"https://portal.postnord.com/api/unified-login/backend"};this.events={loginstatechange:"loginstatechange"};this.endpoints={authorizationEndpoint:"/authorization",tokenExchangeEndpoint:"/token",userInfoEndpoint:"/user",logoutEndpoint:"/logout"};this.keys={tokensource:"tokensource",token:"token",accessToken:"accessToken",user:"user",expire:"expire",expireDate:"expiredate"};this.overridetokenValue="overridetokenValue";this.siteUrl=window.location.origin;this.store={get:function(e){var o=window.sessionStorage.getItem("".concat(t.storagePrefix,"-").concat(e));if(!o){return o}if(o.indexOf("{")===0){try{return JSON.parse(o)}catch(n){}}if(o.indexOf(",")!==-1){return o.split(",")}return o},set:function(e,o){if(typeof o==="object"&&typeof o.length==="undefined"){window.sessionStorage.setItem("".concat(t.storagePrefix,"-").concat(e),JSON.stringify(o));return}window.sessionStorage.setItem("".concat(t.storagePrefix,"-").concat(e),o)},remove:function(e){window.sessionStorage.removeItem("".concat(t.storagePrefix,"-").concat(e))}};if(!e){return}this.eventTarget=e.eventTarget?e.eventTarget:this.eventTarget;this.endpoint=e.endpoint?e.endpoint:"".concat(window.location.protocol,"//").concat(window.location.host);(o=this.storagePrefix)!==null&&o!==void 0?o:this.storagePrefix=e.storagePrefix;if(e.userInfo){this.store.set(this.keys.user,e.userInfo);this.registerToken(this.overridetokenValue,"override")}}e.prototype.init=function(e){if(e===void 0){e=true}if(e){this.checkParameters();this.checkPNTopbar();this.checkExpireTime();if(this.store.get(this.keys.token)&&!this.store.get(this.keys.user)){this.fetchUserInfo()}this.loginStateChange()}};e.prototype.setSiteUrl=function(e){if(e){this.siteUrl=e}};e.prototype.isLoggedIn=function(e){if(e===void 0){e=false}if(e){return e}var t=this.store.get(this.keys.token)&&this.store.get(this.keys.user)?true:false;if(!t&&this.store.get(this.keys.token)===this.overridetokenValue){t=true}return t};e.prototype.registerToken=function(e,t){if(e===void 0){e=""}if(t===void 0){t="frontend"}if(!e||e===this.getToken()){return}this.clearUserData();this.store.set(this.keys.tokensource,t);this.store.set(this.keys.token,e);this.fetchUserInfo()};e.prototype.invalidateTokenOfType=function(e){if(e===void 0){e="frontend"}var t=this.store.get(this.keys.token);if(!t){return}var o=this.store.get(this.keys.tokensource);if(o!==e){return}this.clearUserData()};e.prototype.getLoginUrl=function(e){if(e===void 0){e=""}var t=window.location.href;e=e?e:t;return"".concat(this.getBaseUrl()).concat(this.endpoints.authorizationEndpoint,"?redirectionUrl=").concat(e)};e.prototype.getLogoutUrl=function(e){if(e===void 0){e=""}var t=this.siteUrl;try{var o=new URL(this.siteUrl+"");t=o.origin}catch(i){}var n=t.lastIndexOf("/")!==t.length-1;e=t+(n?"/":"")+"logout";return"".concat(e,"?logoutUrl=").concat(this.getBaseUrl()).concat(this.endpoints.logoutEndpoint,"?redirectionUrl=").concat(e,"%26authorization=").concat(this.store.get(this.keys.token))};e.prototype.getUserInfo=function(){if(this.isLoggedIn()){return this.store.get(this.keys.user)}};e.prototype.getEventTarget=function(){return this.eventTarget};e.prototype.checkExpireTime=function(){var e=this.store.get(this.keys.expire);if(!e){return}var t=new Date;var o=new Date(Math.floor(parseInt(e,10)*1e3));if(t>o){console.info("Login time has expired");this.clearUserData();this.loginStateChange()}};e.prototype.checkPNTopbar=function(){if(this.isLoggedIn()||!window["pnTopbar"]||!window["pnTopbar"]["session_id"]){return}this.store.set(this.keys.token,window["pnTopbar"]["session_id"]);this.fetchUserInfo()};e.prototype.checkParameters=function(){if(!(window===null||window===void 0?void 0:window.location)){return}var e=new URLSearchParams(window.location.search);if(e.get("oneTimeCode")){var t=e.get("oneTimeCode");this.exchangeToken(t).then((function(){var e=window.location.href;var o=e.indexOf("?oneTimeCode")!==-1?"?":"&";var n=e.replace("".concat(o,"oneTimeCode=").concat(t),"");history.replaceState({},document.querySelector("title").innerText,n)}))}};e.prototype.fetchUserInfo=function(){return __awaiter(this,void 0,void 0,(function(){var e,t,o,n,i,r,s,a;return __generator(this,(function(c){switch(c.label){case 0:e=this.store.get(this.keys.token);if(this.store.get(this.keys.token)===this.overridetokenValue){console.info("Did not fetch user data since it was set by an override");return[2]}t={method:"GET",headers:{Accept:"application/json","Content-Type":"application/json",Authorization:e}};return[4,fetch("".concat(this.getBaseUrl()).concat(this.endpoints.userInfoEndpoint),t)];case 1:o=c.sent();return[4,o.json()];case 2:n=c.sent();if(n&&n["idToken"]){try{i=n.idToken,r=n.expiryTime,s=n.accessToken;a=this.parseUserInfo(i);if(!a){console.error("Userdata is not valid");this.clearUserData();return[2]}this.store.set(this.keys.user,a);this.store.set(this.keys.accessToken,s);this.store.set(this.keys.expire,r);this.store.set(this.keys.expireDate,new Date(Math.floor(parseInt(r,10)*1e3)));this.loginStateChange()}catch(h){console.error("Unable to get user information",h)}}else{console.error("Unable to get user information. Clearing login state");this.clearUserData()}return[2]}}))}))};e.prototype.clearUserData=function(){this.store.remove(this.keys.user);this.store.remove(this.keys.tokensource);this.store.remove(this.keys.accessToken);this.store.remove(this.keys.token);this.store.remove(this.keys.expire);this.store.remove(this.keys.expireDate)};e.prototype.getToken=function(){return this.store.get(this.keys.token)};e.prototype.getAccessToken=function(){return this.store.get(this.keys.accessToken)};e.prototype.exchangeToken=function(e){return __awaiter(this,void 0,void 0,(function(){var t,o;return __generator(this,(function(n){switch(n.label){case 0:this.clearUserData();return[4,fetch("".concat(this.getBaseUrl()).concat(this.endpoints.tokenExchangeEndpoint,"?oneTimeCode=").concat(e))];case 1:t=n.sent();return[4,t.json()];case 2:o=n.sent().token;if(typeof o==="string"&&o){this.store.set(this.keys.token,o)}this.fetchUserInfo();return[2]}}))}))};e.prototype.loginStateChange=function(){if(!this.eventTarget){return}this.eventTarget.dispatchEvent(new CustomEvent(this.events.loginstatechange,{detail:this.isLoggedIn()}))};e.prototype.getBaseUrl=function(){var e=this;var t=["localhost","integration.","local."];var o=t.filter((function(t){return e.endpoint.indexOf(t)!==-1})).length>0;if(o){return this.baseUrls.at}return this.baseUrls.prod};e.prototype.parseUserInfo=function(e){if(!e){return null}var t=e.split(".")[1];var o=t.replace(/-/g,"+").replace(/_/g,"/");var n=decodeURIComponent(atob(o).split("").map((function(e){return"%"+("00"+e.charCodeAt(0).toString(16)).slice(-2)})).join(""));return JSON.parse(n)};return e}();e("M",t)}}}));
@@ -1 +0,0 @@
1
- var __awaiter=this&&this.__awaiter||function(e,i,n,t){function o(e){return e instanceof n?e:new n((function(i){i(e)}))}return new(n||(n=Promise))((function(n,r){function l(e){try{s(t.next(e))}catch(i){r(i)}}function a(e){try{s(t["throw"](e))}catch(i){r(i)}}function s(e){e.done?n(e.value):o(e.value).then(l,a)}s((t=t.apply(e,i||[])).next())}))};var __generator=this&&this.__generator||function(e,i){var n={label:0,sent:function(){if(r[0]&1)throw r[1];return r[1]},trys:[],ops:[]},t,o,r,l;return l={next:a(0),throw:a(1),return:a(2)},typeof Symbol==="function"&&(l[Symbol.iterator]=function(){return this}),l;function a(e){return function(i){return s([e,i])}}function s(l){if(t)throw new TypeError("Generator is already executing.");while(n)try{if(t=1,o&&(r=l[0]&2?o["return"]:l[0]?o["throw"]||((r=o["return"])&&r.call(o),0):o.next)&&!(r=r.call(o,l[1])).done)return r;if(o=0,r)l=[l[0]&2,r.value];switch(l[0]){case 0:case 1:r=l;break;case 4:n.label++;return{value:l[1],done:false};case 5:n.label++;o=l[1];l=[0];continue;case 7:l=n.ops.pop();n.trys.pop();continue;default:if(!(r=n.trys,r=r.length>0&&r[r.length-1])&&(l[0]===6||l[0]===2)){n=0;continue}if(l[0]===3&&(!r||l[1]>r[0]&&l[1]<r[3])){n.label=l[1];break}if(l[0]===6&&n.label<r[1]){n.label=r[1];r=l;break}if(r&&n.label<r[2]){n.label=r[2];n.ops.push(l);break}if(r[2])n.ops.pop();n.trys.pop();continue}l=i.call(e,n)}catch(a){l=[6,a];o=0}finally{t=r=0}if(l[0]&5)throw l[1];return{value:l[0]?l[1]:void 0,done:true}}};System.register(["./p-36654f2a.system.js"],(function(e){"use strict";var i,n,t,o;return{setters:[function(e){i=e.r;n=e.h;t=e.a;o=e.g}],execute:function(){var r="";var l=e("pn_marketweb_siteheader_login_links",function(){function e(e){i(this,e);this.loginDialog=null;this.loginManager=null;this.idNamespace="";this.loggedin=false;this.username=""}e.prototype.componentWillLoad=function(){this.init()};e.prototype.init=function(){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(e){this.adjustLoginLinks();return[2]}))}))};e.prototype.adjustLoginLinks=function(){var e=this;var i,n,t,o;if(!this.loginDialog){return}var r=function(i,n){i.isLogoutLink=i.href.indexOf("logout")!==-1;if(i.isLogoutLink){i.href=e.loginManager.getLogoutUrl(i.href.replace("logout","").replace("http://window.location.href/?","").replace("https://window.location.href/?",""))}i.href=i.href.replace("window.location.href",window.location.href);if(n===0&&!i.href){i.href=e.loginManager.getLoginUrl();i.linkType="primary"}if(i.primaryLinkApperance&&!i.linkType){i.linkType="primary"}};if((i=this.loginDialog)===null||i===void 0?void 0:i.loginMenuLinks){(n=this.loginDialog)===null||n===void 0?void 0:n.loginMenuLinks.forEach(r)}if((t=this.loginDialog)===null||t===void 0?void 0:t.loggedInLinks){(o=this.loginDialog)===null||o===void 0?void 0:o.loggedInLinks.forEach(r)}this.loginDialog.legacyLoginLinks=[{href:this.loginManager.getLoginUrl(this.loginDialog.loginUrl),linkText:this.loginDialog.loginLinkText,openInNewWindow:false,isLogoutLink:false,pageLink:null,linkType:"primary",primaryLinkApperance:true},{href:this.loginManager.getLoginUrl(this.loginDialog.registerUrl),linkText:this.loginDialog.createLoginLinkText,openInNewWindow:false,isLogoutLink:false,pageLink:null,primaryLinkApperance:false}]};e.prototype.render=function(){var e;if(!this.loginDialog){return}var i={username:null,loggedin:false};if(this.username){i.username=this.username;i.loggedin=this.loggedin}return n(t,Object.assign({},i),!this.loginDialog.overrideLoginMenu?n("div",{"data-loggedin":this.loggedin+""},this.loggedin?n("pn-marketweb-siteheader-login-linklist",{links:this.loginDialog.loggedInLinks,loginManager:this.loginManager,idNamespace:this.idNamespace}):n("div",null,((e=this.loginDialog.loginMenuLinks)===null||e===void 0?void 0:e.length)>0?n("pn-marketweb-siteheader-login-linklist",{heading:this.loginDialog.loginTitle,links:this.loginDialog.loginMenuLinks,loginManager:this.loginManager,idNamespace:this.idNamespace}):n("pn-marketweb-siteheader-login-linklist",{links:this.loginDialog.legacyLoginLinks,loginManager:this.loginManager,idNamespace:this.idNamespace}))):null,this.loginDialog.overrideLoginMenu?n("pn-marketweb-siteheader-login-linklist",{links:this.loginDialog.loginMenuLinks,loginManager:this.loginManager,idNamespace:this.idNamespace}):null)};Object.defineProperty(e.prototype,"hostElement",{get:function(){return o(this)},enumerable:false,configurable:true});Object.defineProperty(e,"watchers",{get:function(){return{loginDialog:["init"]}},enumerable:false,configurable:true});return e}());l.style=r;var a='.pn-marketweb-siteheader-login-profileselection-heading{display:block;padding:0.5rem 0 1rem}.pn-marketweb-siteheader-login-profileselection-user,.pn-marketweb-siteheader-login-profileselection-currentprofile{margin-top:1rem;margin-bottom:1rem}.pn-marketweb-siteheader-login-profileselection-user-name,.pn-marketweb-siteheader-login-profileselection-currentprofile-name{line-height:1}.pn-marketweb-siteheader-login-profileselection-user-description,.pn-marketweb-siteheader-login-profileselection-currentprofile-description{font-weight:400;white-space:normal;word-break:break-all;color:#5E554A;font-size:0.75em}.pn-marketweb-siteheader-login-profileselection-divider{height:1rem;width:100%;background:#00A0D6;position:relative;margin-left:-1em;margin-top:1.6rem;margin-bottom:1.6rem;border-radius:0 0.6em 0.6em 0;padding:0}.pn-marketweb-siteheader-login-profileselection-divider::after{content:"";width:0.6em;height:0.6em;border-radius:50%;position:absolute;right:0;top:0;background:inherit;-webkit-transform:translateX(calc(100% + 0.2em));transform:translateX(calc(100% + 0.2em))}.pn-marketweb-siteheader-login-profileselection-profileoption-link{display:-ms-flexbox;display:flex;background:#FFFFFF;-webkit-transition:background 0.15s ease-in-out;transition:background 0.15s ease-in-out;margin:0 -1em;padding:0.6rem 1.6rem;text-decoration:none;color:#005D92;-ms-flex-align:center;align-items:center}.pn-marketweb-siteheader-login-profileselection-profileoption-link:hover,.pn-marketweb-siteheader-login-profileselection-profileoption-link:focus,.pn-marketweb-siteheader-login-profileselection-profileoption-link:active{background:#F3F2F2}.pn-marketweb-siteheader-login-profileselection-profileoption-content{-ms-flex-positive:1;flex-grow:1}.pn-marketweb-siteheader-login-profileselection-profileoption-name{font-weight:700}.pn-marketweb-siteheader-login-profileselection-profileoption-description{font-weight:400;white-space:normal;word-break:break-all;color:#5E554A;font-size:0.75em}.pn-marketweb-siteheader-login-profileselection-logout{padding:1.6rem;text-align:center;width:100%}.pn-marketweb-siteheader-login-profileselection-logout-link{display:inline-block;font-weight:500;color:#005D92;text-decoration:none}.pn-marketweb-siteheader-login-profileselection-logout-link:hover,.pn-marketweb-siteheader-login-profileselection-logout-link:focus,.pn-marketweb-siteheader-login-profileselection-logout-link:active{text-decoration:underline}';var s=e("pn_marketweb_siteheader_login_profileselection",function(){function e(e){i(this,e);this.loginDialog=null;this.loginManager=null;this.endpoint="";this.loggedin=false;this.idNamespace="";this.heading=null;this.i18n={searchlabel:"",searchplaceholder:"",searchbuttontext:"",menuHomeButton:"",menuGoBackButton:"",mainMenuButton:"",menuStartButton:"",profileSelectionFlyoutHeading:""};this.user=null;this.logoutLink=null;this.userName=null;this.userEmail="";this.currentProfile=null;this.profileoptions=[]}e.prototype.componentWillLoad=function(){var e;if(this.heading===null&&((e=this.i18n)===null||e===void 0?void 0:e.profileSelectionFlyoutHeading)){this.heading=this.i18n.profileSelectionFlyoutHeading}this.init()};e.prototype.init=function(){this.updateUserInfo();this.adjustLoginLinks();this.fetchProfiles()};e.prototype.fetchProfiles=function(){return __awaiter(this,void 0,void 0,(function(){var e,i,n,t,o,r,l;var a=this;return __generator(this,(function(s){switch(s.label){case 0:if(!this.loggedin||this.profileoptions.length>0){return[2]}e="".concat(this.endpoint).concat(this.endpoint.lastIndexOf("/")>-1&&this.endpoint.lastIndexOf("/")===this.endpoint.length-1?"":"/","api/user/parentorganizations");return[4,fetch(e)];case 1:i=s.sent();return[4,i.json()];case 2:n=s.sent();t={loggedin:true,organizations:[{name:"Forsheda Livs AB",customerNumber:"5564513603",id:"dbba867d-1dff-3dbb-b420-c57b4b828b73",selected:true,profiles:[{name:"Forsheda Livs AB",customerNumber:"20685482",id:"f757ba28-9a73-15a2-f128-4b394d970f3f",ssid:"",selected:false,customerGroup:"Business"},{name:"ICA MAXI KUNGSBACKA",customerNumber:"20831191",id:"5aea41df-32b0-3f7e-2946-78598360177d",ssid:"259686",selected:true,customerGroup:"Agent"}]},{name:"Hem Livs i Kungsbacka AB",customerNumber:"5565271250",id:"97ca363c-40ef-cca9-7a3c-9e7f025567c2",selected:false,profiles:[{name:"ICA KVANTUM KUNGSBACKA",customerNumber:"20831193",id:"fbd61ffd-41c6-2206-b88e-cfef91e1dc39",ssid:"259691",selected:false,customerGroup:"Agent"}]},{name:"ICA SUPERMARKET TORGET",customerNumber:"5568902679",id:"7cb76a94-e1a5-5f57-58fd-bc563851b28e",selected:false,profiles:[{name:"ICA SUPERMARKET TORGET",customerNumber:"20831212",id:"3a2db017-b68f-6fa0-fe70-542c08cd97ce",ssid:"",selected:false,customerGroup:"Agent"}]}]};o=window.location.href.indexOf("localhost:6008")!==-1?t:n;if(!o||!o.organizations||!o.organizations.length){return[2]}o.organizations.forEach((function(e){if(e.selected===true&&e.profiles){var i=e.profiles.filter((function(e){return e.selected===true}));if(i&&i[0]&&i[0].customerGroup.toLocaleLowerCase()==="agent"&&i[0].ssid){e.customerNumber=i[0].ssid}}else{if(e.customerNumber.length===10&&e.customerNumber.substring(0,2)==="55"){e.customerNumber=e.customerNumber.substring(0,6)+"-"+e.customerNumber.substring(6)}a.profileoptions.push(e)}}));r=o.organizations.filter((function(e){return e.selected===true}))[0];l={name:this.userName,customerNumber:"",id:"",selected:!r,profiles:[]};if(!r){r=l}if(r&&r.name){this.currentProfile=r}this.profileoptions.push(l);return[2]}}))}))};e.prototype.adjustLoginLinks=function(){var e=this;var i,n,t,o;var r=function(i,n){i.isLogoutLink=i.href.indexOf("logout")!==-1;if(i.isLogoutLink){i.href=e.loginManager.getLogoutUrl(i.href.replace("logout","").replace("http://window.location.href/?","").replace("https://window.location.href/?",""))}if(n===0&&!i.href){i.href=e.loginManager.getLoginUrl();i.linkType="primary"}if(i.primaryLinkApperance&&!i.linkType){i.linkType="primary"}};if((i=this.loginDialog)===null||i===void 0?void 0:i.loggedInLinks){(n=this.loginDialog)===null||n===void 0?void 0:n.loggedInLinks.forEach(r)}this.logoutLink=(o=(t=this.loginDialog)===null||t===void 0?void 0:t.loggedInLinks.filter((function(e){return e.isLogoutLink}))[0])!==null&&o!==void 0?o:null};e.prototype.updateUserInfo=function(){var e=this.loginManager.getUserInfo();this.user=e;if(!e){return}if(e&&e.email){this.userEmail=e.email}if(e&&e.given_name){this.userName=e.given_name+((e===null||e===void 0?void 0:e.family_name)?" ".concat(e===null||e===void 0?void 0:e.family_name):"")}if(e&&e.given_name){this.userName=e.given_name;return}if(e&&e.family_name){this.userName=e.family_name;return}if(e&&e.username){this.userName=e.username;return}};e.prototype.render=function(){var e=this;if(!this.loginDialog){return}var i={};return n(t,Object.assign({},i),this.heading?n("strong",{class:"pn-marketweb-siteheader-login-profileselection-heading"},this.heading):null,this.currentProfile!==null&&this.currentProfile.name?n("div",{class:"pn-marketweb-siteheader-login-profileselection-currentprofile"},n("div",{class:"pn-marketweb-siteheader-login-profileselection-currentprofile-name"},this.currentProfile.name),n("div",{class:"pn-marketweb-siteheader-login-profileselection-currentprofile-description"},this.currentProfile.customerNumber?this.currentProfile.customerNumber:this.userEmail)):null,n("pn-marketweb-siteheader-login-linklist",{links:this.loginDialog.loggedInLinks.filter((function(e){return e.isLogoutLink===false})),loginManager:this.loginManager,idNamespace:this.idNamespace}),n("div",{class:"pn-marketweb-siteheader-login-profileselection-divider"}),this.profileoptions.filter((function(e){return e.selected!==true})).map((function(i){var t=i.profiles.length>0?i.profiles[0].customerNumber:i.customerNumber;return n("div",{class:"pn-marketweb-siteheader-login-profileselection-profileoption"},n("a",{href:"".concat(e.endpoint,"/api/user/setprofile?customernumber=").concat(t,"&returnUrl=").concat(window.location.href),class:"pn-marketweb-siteheader-login-profileselection-profileoption-link"},n("div",{class:"pn-marketweb-siteheader-login-profileselection-profileoption-content"},n("div",{class:"pn-marketweb-siteheader-login-profileselection-profileoption-name"},i.name),n("div",{class:"pn-marketweb-siteheader-login-profileselection-profileoption-description"},i.customerNumber?i.customerNumber:e.userEmail)),n("pn-icon",{symbol:"arrow-right",small:"false",color:"blue700"})))})),this.logoutLink?n("div",{class:"pn-marketweb-siteheader-login-profileselection-logout"},n("a",{href:this.logoutLink.href,rel:"nofollower noopener",onClick:function(){return e.loginManager.clearUserData()},class:"pn-marketweb-siteheader-login-profileselection-logout-link"},this.logoutLink.linkText)):null)};Object.defineProperty(e.prototype,"hostElement",{get:function(){return o(this)},enumerable:false,configurable:true});return e}());s.style=a}}}));
@@ -1 +0,0 @@
1
- class t{constructor(t=null){var i;this.eventTarget=null!==window&&void 0!==window?window:null===document||void 0===document?void 0:document.body,this.endpoint="",this.storagePrefix="pn-user",this.baseUrls={at:"https://atportal.postnord.com/api/unified-login/backend",prod:"https://portal.postnord.com/api/unified-login/backend"},this.events={loginstatechange:"loginstatechange"},this.endpoints={authorizationEndpoint:"/authorization",tokenExchangeEndpoint:"/token",userInfoEndpoint:"/user",logoutEndpoint:"/logout"},this.keys={tokensource:"tokensource",token:"token",accessToken:"accessToken",user:"user",expire:"expire",expireDate:"expiredate"},this.overridetokenValue="overridetokenValue",this.siteUrl=window.location.origin,this.store={get:t=>{const i=window.sessionStorage.getItem(`${this.storagePrefix}-${t}`);if(!i)return i;if(0===i.indexOf("{"))try{return JSON.parse(i)}catch(e){}return-1!==i.indexOf(",")?i.split(","):i},set:(t,i)=>{"object"!=typeof i||void 0!==i.length?window.sessionStorage.setItem(`${this.storagePrefix}-${t}`,i):window.sessionStorage.setItem(`${this.storagePrefix}-${t}`,JSON.stringify(i))},remove:t=>{window.sessionStorage.removeItem(`${this.storagePrefix}-${t}`)}},t&&(this.eventTarget=t.eventTarget?t.eventTarget:this.eventTarget,this.endpoint=t.endpoint?t.endpoint:`${window.location.protocol}//${window.location.host}`,null!==(i=this.storagePrefix)&&void 0!==i||(this.storagePrefix=t.storagePrefix),t.userInfo&&(this.store.set(this.keys.user,t.userInfo),this.registerToken(this.overridetokenValue,"override")))}init(t=!0){t&&(this.checkParameters(),this.checkPNTopbar(),this.checkExpireTime(),this.store.get(this.keys.token)&&!this.store.get(this.keys.user)&&this.fetchUserInfo(),this.loginStateChange())}setSiteUrl(t){t&&(this.siteUrl=t)}isLoggedIn(t=!1){if(t)return t;let i=!(!this.store.get(this.keys.token)||!this.store.get(this.keys.user));return i||this.store.get(this.keys.token)!==this.overridetokenValue||(i=!0),i}registerToken(t="",i="frontend"){t&&t!==this.getToken()&&(this.clearUserData(),this.store.set(this.keys.tokensource,i),this.store.set(this.keys.token,t),this.fetchUserInfo())}invalidateTokenOfType(t="frontend"){this.store.get(this.keys.token)&&this.store.get(this.keys.tokensource)===t&&this.clearUserData()}getLoginUrl(t=""){const i=window.location.href;return t=t||i,`${this.getBaseUrl()}${this.endpoints.authorizationEndpoint}?redirectionUrl=${t}`}getLogoutUrl(t=""){let i=this.siteUrl;try{i=new URL(this.siteUrl+"").origin}catch(s){}const e=i.lastIndexOf("/")!==i.length-1;return`${t=i+(e?"/":"")+"logout"}?logoutUrl=${this.getBaseUrl()}${this.endpoints.logoutEndpoint}?redirectionUrl=${t}%26authorization=${this.store.get(this.keys.token)}`}getUserInfo(){if(this.isLoggedIn())return this.store.get(this.keys.user)}getEventTarget(){return this.eventTarget}checkExpireTime(){const t=this.store.get(this.keys.expire);t&&new Date>new Date(Math.floor(1e3*parseInt(t,10)))&&(console.info("Login time has expired"),this.clearUserData(),this.loginStateChange())}checkPNTopbar(){!this.isLoggedIn()&&window.pnTopbar&&window.pnTopbar.session_id&&(this.store.set(this.keys.token,window.pnTopbar.session_id),this.fetchUserInfo())}checkParameters(){if(!(null===window||void 0===window?void 0:window.location))return;const t=new URLSearchParams(window.location.search);if(t.get("oneTimeCode")){const i=t.get("oneTimeCode");this.exchangeToken(i).then((()=>{const t=window.location.href,e=-1!==t.indexOf("?oneTimeCode")?"?":"&",s=t.replace(`${e}oneTimeCode=${i}`,"");history.replaceState({},document.querySelector("title").innerText,s)}))}}async fetchUserInfo(){const t=this.store.get(this.keys.token);if(this.store.get(this.keys.token)===this.overridetokenValue)return void console.info("Did not fetch user data since it was set by an override");const i={method:"GET",headers:{Accept:"application/json","Content-Type":"application/json",Authorization:t}},e=await fetch(`${this.getBaseUrl()}${this.endpoints.userInfoEndpoint}`,i),s=await e.json();if(s&&s.idToken)try{const{idToken:t,expiryTime:i,accessToken:e}=s,n=this.parseUserInfo(t);if(!n)return console.error("Userdata is not valid"),void this.clearUserData();this.store.set(this.keys.user,n),this.store.set(this.keys.accessToken,e),this.store.set(this.keys.expire,i),this.store.set(this.keys.expireDate,new Date(Math.floor(1e3*parseInt(i,10)))),this.loginStateChange()}catch(n){console.error("Unable to get user information",n)}else console.error("Unable to get user information. Clearing login state"),this.clearUserData()}clearUserData(){this.store.remove(this.keys.user),this.store.remove(this.keys.tokensource),this.store.remove(this.keys.accessToken),this.store.remove(this.keys.token),this.store.remove(this.keys.expire),this.store.remove(this.keys.expireDate)}getToken(){return this.store.get(this.keys.token)}getAccessToken(){return this.store.get(this.keys.accessToken)}async exchangeToken(t){this.clearUserData();const i=await fetch(`${this.getBaseUrl()}${this.endpoints.tokenExchangeEndpoint}?oneTimeCode=${t}`),{token:e}=await i.json();"string"==typeof e&&e&&this.store.set(this.keys.token,e),this.fetchUserInfo()}loginStateChange(){this.eventTarget&&this.eventTarget.dispatchEvent(new CustomEvent(this.events.loginstatechange,{detail:this.isLoggedIn()}))}getBaseUrl(){return["localhost","integration.","local."].filter((t=>-1!==this.endpoint.indexOf(t))).length>0?this.baseUrls.at:this.baseUrls.prod}parseUserInfo(t){if(!t)return null;var i=t.split(".")[1].replace(/-/g,"+").replace(/_/g,"/"),e=decodeURIComponent(atob(i).split("").map((function(t){return"%"+("00"+t.charCodeAt(0).toString(16)).slice(-2)})).join(""));return JSON.parse(e)}}export{t as M}