@postnord/pn-marketweb-components 2.0.113 → 2.0.115
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.
- package/cjs/{MarketWebLoginManager-2fe6a1a7.js → MarketWebLoginManager-c844354b.js} +11 -3
- package/cjs/pn-language-selector_9.cjs.entry.js +3 -3
- package/cjs/pn-marketweb-sitefooter.cjs.entry.js +1 -1
- package/cjs/pn-marketweb-siteheader-login-links_2.cjs.entry.js +4 -4
- package/cjs/pn-marketweb-siteheader.cjs.entry.js +1 -1
- package/collection/components/layout-components/pn-marketweb-sitefooter/pn-marketweb-sitefooter.css +4 -0
- package/collection/components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader-login-links.js +2 -2
- package/collection/components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader-login-profileselection.js +2 -2
- package/collection/components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader-login.js +2 -2
- package/collection/components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader.stories.js +3 -3
- package/collection/globals/MarketWebLoginManager.js +11 -3
- package/custom-elements/index.js +18 -10
- package/esm/{MarketWebLoginManager-78e62611.js → MarketWebLoginManager-0f9a1dcd.js} +11 -3
- package/esm/pn-language-selector_9.entry.js +3 -3
- package/esm/pn-marketweb-sitefooter.entry.js +1 -1
- package/esm/pn-marketweb-siteheader-login-links_2.entry.js +4 -4
- package/esm/pn-marketweb-siteheader.entry.js +1 -1
- package/esm-es5/MarketWebLoginManager-0f9a1dcd.js +1 -0
- package/esm-es5/pn-language-selector_9.entry.js +1 -1
- package/esm-es5/pn-marketweb-sitefooter.entry.js +1 -1
- package/esm-es5/pn-marketweb-siteheader-login-links_2.entry.js +1 -1
- package/esm-es5/pn-marketweb-siteheader.entry.js +1 -1
- package/package.json +1 -1
- package/pn-market-web-components/{p-2138ff10.system.entry.js → p-2287dd4d.system.entry.js} +1 -1
- package/pn-market-web-components/p-285888b7.system.entry.js +1 -0
- package/pn-market-web-components/p-2897dca0.js +1 -0
- package/pn-market-web-components/{p-01d3d110.system.entry.js → p-33550605.system.entry.js} +1 -1
- package/pn-market-web-components/{p-12190a80.entry.js → p-5124dc7e.entry.js} +1 -1
- package/pn-market-web-components/p-555eac6b.entry.js +1 -0
- package/pn-market-web-components/p-67887512.system.js +1 -1
- package/pn-market-web-components/{p-f94b22d7.entry.js → p-87ffe37c.entry.js} +1 -1
- package/pn-market-web-components/p-9c1d0ba8.system.js +1 -0
- package/pn-market-web-components/{p-ee34f0e6.entry.js → p-cf03d788.entry.js} +1 -1
- package/pn-market-web-components/{p-866e6e4c.system.entry.js → p-fe27a1aa.system.entry.js} +1 -1
- package/pn-market-web-components/pn-market-web-components.esm.js +1 -1
- package/types/globals/MarketWebLoginManager.d.ts +1 -1
- package/umd/pn-marketweb-init.js +1 -1
- package/umd/pn-marketweb-salesforce.js +2 -2
- package/esm-es5/MarketWebLoginManager-78e62611.js +0 -1
- package/pn-market-web-components/p-a6a2a32d.entry.js +0 -1
- package/pn-market-web-components/p-d864da57.system.js +0 -1
- package/pn-market-web-components/p-da7f1b66.system.entry.js +0 -1
- package/pn-market-web-components/p-e999b220.js +0 -1
|
@@ -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}
|