@postnord/pn-marketweb-components 1.0.44 → 1.0.45

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 (26) hide show
  1. package/cjs/{MarketWebLoginManager-1282a883.js → MarketWebLoginManager-3c2f4423.js} +16 -1
  2. package/cjs/pn-language-selector_9.cjs.entry.js +5 -2
  3. package/cjs/pn-marketweb-siteheader.cjs.entry.js +1 -1
  4. package/collection/components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader-login.js +4 -1
  5. package/collection/components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader.stories.js +1 -1
  6. package/collection/globals/MarketWebLoginManager.js +16 -1
  7. package/custom-elements/index.js +20 -2
  8. package/esm/{MarketWebLoginManager-310d2552.js → MarketWebLoginManager-3bb0a307.js} +16 -1
  9. package/esm/pn-language-selector_9.entry.js +5 -2
  10. package/esm/pn-marketweb-siteheader.entry.js +1 -1
  11. package/esm-es5/MarketWebLoginManager-3bb0a307.js +1 -0
  12. package/esm-es5/pn-language-selector_9.entry.js +1 -1
  13. package/esm-es5/pn-marketweb-siteheader.entry.js +1 -1
  14. package/package.json +2 -2
  15. package/pn-market-web-components/{p-43c40a35.entry.js → p-2b34c4bd.entry.js} +1 -1
  16. package/pn-market-web-components/{p-ca95f857.system.entry.js → p-3826548d.system.entry.js} +1 -1
  17. package/pn-market-web-components/{p-b4dbc84d.system.entry.js → p-48d29c10.system.entry.js} +1 -1
  18. package/pn-market-web-components/p-55513980.system.js +1 -0
  19. package/pn-market-web-components/p-6423bacf.js +1 -0
  20. package/pn-market-web-components/p-7a7f380b.system.js +1 -1
  21. package/pn-market-web-components/{p-0df92840.entry.js → p-f1c3003f.entry.js} +1 -1
  22. package/pn-market-web-components/pn-market-web-components.esm.js +1 -1
  23. package/types/globals/MarketWebLoginManager.d.ts +3 -1
  24. package/esm-es5/MarketWebLoginManager-310d2552.js +0 -1
  25. package/pn-market-web-components/p-2456901a.js +0 -1
  26. package/pn-market-web-components/p-f1311662.system.js +0 -1
@@ -1 +1 @@
1
- import{d as e,N as n,w as a,p as t,H as i,b as r}from"./p-cf516409.js";const l=e=>{const n=e.cloneNode;e.cloneNode=function(e){if("TEMPLATE"===this.nodeName)return n.call(this,e);const a=n.call(this,!1),t=this.childNodes;if(e)for(let n=0;n<t.length;n++)2!==t[n].nodeType&&a.appendChild(t[n].cloneNode(!0));return a}};(()=>{l(i.prototype);const r=Array.from(e.querySelectorAll("script")).find((e=>new RegExp(`/${n}(\\.esm)?\\.js($|\\?|#)`).test(e.src)||e.getAttribute("data-stencil-namespace")===n)),o={};return"onbeforeload"in r&&!history.scrollRestoration?{then(){}}:(o.resourcesUrl=new URL(".",new URL(r.getAttribute("data-resources-url")||r.src,a.location.href)).href,t(o))})().then((e=>r([["p-0df92840",[[4,"pn-marketweb-siteheader",{market:[1537],language:[1537],environment:[1537],token:[1],endpoint:[1],hideSiteSelector:[1540,"hide-site-selector"],hideLanguageSelector:[1540,"hide-language-selector"],hideSearch:[1540,"hide-search"],hideLogin:[1540,"hide-login"],sessionForward:[4,"session-forward"],cache:[4],spaMode:[4,"spa-mode"],i18n:[32],gotData:[32],fetchingData:[32],homePageLink:[32],menuItems:[32],siteDefinition:[32],search:[32],siteSelector:[32],languageSelector:[32],languageOptions:[32],loginDialog:[32],minimizeSearch:[32],loggedIn:[32],loginManager:[32]},[[0,"setLanguage","onLanguageSelectorChange"],[0,"loginStateChange","onLoginStateChange"],[9,"resize","handleResize"]]]]],["p-c799bf36",[[0,"pn-find-price",{source:[1],language:[1025],market:[1025],filteredItems:[32],weight:[32],weightvalue:[32],sourceData:[32],sizecategory:[32]}]]],["p-4d5aa13e",[[0,"pn-find-service-and-price",{source:[1],language:[1025],market:[1025],filteredItems:[32],postagetype:[32],weight:[32],weightvalue:[32],deliveryscope:[32],sourceData:[32]}]]],["p-71a31b15",[[4,"pn-product-pricelist",{source:[1],language:[1025],market:[1025],productid:[1],filteredItems:[32],sourceData:[32],gotData:[32],loading:[32],postagetype:[32],weight:[32],weightvalue:[32]}]]],["p-cfe1550c",[[0,"pn-marketweb-sitefooter",{market:[1537],language:[1537],environment:[1537],endpoint:[1],cache:[4],siteDefinition:[32],footerContent:[32],i18n:[32],gotData:[32],fetchingData:[32]}]]],["p-aea09ac6",[[4,"pn-bonus-progressbar",{icon:[1],heading:[1],theme:[513],bonuspercentage:[1],currency:[513],value:[1538],min:[1538],max:[1538],valuepercentage:[32],progresspercentage:[32],levelValues:[32],currentLevelAdjustedValue:[32]}]]],["p-ac5a749b",[[1,"pn-filter-checkbox",{value:[520],name:[1],checkboxid:[1],disabled:[4],checked:[4],indeterminate:[1028]},[[0,"change","handlechange"]]]]],["p-66fb0f57",[[1,"pn-filter-search",{disabled:[4],placeholder:[1],inputid:[1],name:[1],autocomplete:[1],value:[1],label:[1],loading:[4],button:[1],light:[4]},[[0,"input","inputHandler"]]]]],["p-1ccd3831",[[0,"pn-pex-pricefinder",{language:[1],currency:[1],apiUrl:[1,"api-url"],i18n:[32],fromzip:[32],tozip:[32],weight:[32],when:[32],response:[32]},[[0,"language","setLanguage"]]]]],["p-3552ae09",[[4,"pn-profile-selector",{language:[1537],returnUrl:[1,"return-url"],i18n:[32],isLoading:[32],numberOfProfiles:[32]}]]],["p-3ba257c5",[[0,"pn-profile-selector-option",{name:[1],identifier:[1],url:[1]}]]],["p-56ba3951",[[4,"pn-sidenav",{language:[1],navLabel:[1,"nav-label"],i18n:[32]},[[0,"language","setLanguage"],[0,"openSubMenuLevelChange","onOpenSubMenuLevelChange"]]]]],["p-d546d0c3",[[4,"pn-sidenav-level",{level:[32],levelId:[32],isOpen:[32],parentName:[32],parentHref:[32],parentLinkId:[32],alignment:[32]}]]],["p-00d6033e",[[4,"pn-sidenav-link",{name:[1],href:[1],target:[1],linkid:[1],icon:[1],current:[4],levelId:[32],open:[32],hasChildren:[32]}]]],["p-45bb8f15",[[0,"pn-find-price-result",{item:[1040],shownitems:[16],weightText:[32]}]]],["p-7fca7510",[[0,"pn-find-service-and-price-result",{item:[1040],shownitems:[16],weightText:[32]}]]],["p-ab699e09",[[0,"pn-product-pricelist-result",{item:[1040],shownitems:[16],weightText:[32]}]]],["p-8325d608",[[0,"pn-bonus-progressbar-level",{current:[516],value:[1538],bonuspercentage:[1537],visualpercentage:[1538],percentage:[32],max:[32],min:[32],currency:[32]}]]],["p-0eef21d9",[[4,"pn-site-footer",{url:[1]}],[4,"pn-site-footer-col"]]],["p-9aac6bd5",[[4,"pn-choice-button",{value:[520],name:[1],choiceid:[1],type:[1],disabled:[4],checked:[4],indeterminate:[1028]},[[0,"change","handlechange"]]]]],["p-544f8fb9",[[4,"pn-mainnav-link",{name:[1],href:[1],target:[1],linkid:[1],levelId:[32],open:[32],hasChildren:[32]}]]],["p-518b1864",[[4,"pn-product-card"],[0,"pn-product-card-info",{rulle:[1],paket:[1],label:[1],text:[1]}],[0,"pn-product-card-price",{label:[1],amount:[1],currency:[1],note:[1],url:[1]}]]],["p-43c40a35",[[4,"pn-mainnav-level",{level:[32],levelId:[32],isOpen:[32],parentName:[32],parentHref:[32],parentLinkId:[32],listCount:[32],alignment:[32]}],[4,"pn-language-selector",{value:[1537],selectedLanguageName:[32],options:[32],i18n:[32]}],[0,"pn-language-selector-option",{name:[1],code:[1],url:[1],selected:[4],currentLanguage:[1,"current-language"]}],[4,"pn-mainnav",{market:[1],language:[1],navigationId:[1,"navigation-id"],openMenu:[1028,"open-menu"],navLabel:[1,"nav-label"]},[[0,"language","setLanguage"],[0,"market","setMarket"],[0,"menuLanguageChange","onLanguageChange"],[0,"setmenuopenstate","setMenuOpenState"],[0,"openMenuLevelChange","onOpenMenuLevelChange"]]],[4,"pn-mainnav-list",{heading:[1],linkCount:[32]}],[0,"pn-marketweb-siteheader-login",{endpoint:[1],token:[1],i18n:[8,"i-1-8n"],emitEvents:[4,"emit-events"],loginDialog:[1040],loginManager:[32],loggedIn:[32],toggleButtonText:[32],username:[32]}],[0,"pn-marketweb-siteheader-search",{i18n:[8,"i-1-8n"],showOnlyLink:[1028,"show-only-link"],hideSearch:[1028,"hide-search"],search:[1040]}],[4,"pn-site-selector",{buttontext:[1537],heading:[1537],language:[1537],i18n:[32]}],[0,"pn-site-selector-item",{url:[1],heading:[1],description:[1],newwindow:[4]}]]],["p-d26967cb",[[4,"pn-product-tile"],[0,"pn-product-tile-info",{label:[1],text:[1],icon:[1]}],[0,"pn-product-tile-price",{label:[1],amount:[1],currency:[1],url:[1]}]]]],e)));
1
+ import{d as e,N as n,w as a,p as t,H as i,b as r}from"./p-cf516409.js";const l=e=>{const n=e.cloneNode;e.cloneNode=function(e){if("TEMPLATE"===this.nodeName)return n.call(this,e);const a=n.call(this,!1),t=this.childNodes;if(e)for(let n=0;n<t.length;n++)2!==t[n].nodeType&&a.appendChild(t[n].cloneNode(!0));return a}};(()=>{l(i.prototype);const r=Array.from(e.querySelectorAll("script")).find((e=>new RegExp(`/${n}(\\.esm)?\\.js($|\\?|#)`).test(e.src)||e.getAttribute("data-stencil-namespace")===n)),o={};return"onbeforeload"in r&&!history.scrollRestoration?{then(){}}:(o.resourcesUrl=new URL(".",new URL(r.getAttribute("data-resources-url")||r.src,a.location.href)).href,t(o))})().then((e=>r([["p-f1c3003f",[[4,"pn-marketweb-siteheader",{market:[1537],language:[1537],environment:[1537],token:[1],endpoint:[1],hideSiteSelector:[1540,"hide-site-selector"],hideLanguageSelector:[1540,"hide-language-selector"],hideSearch:[1540,"hide-search"],hideLogin:[1540,"hide-login"],sessionForward:[4,"session-forward"],cache:[4],spaMode:[4,"spa-mode"],i18n:[32],gotData:[32],fetchingData:[32],homePageLink:[32],menuItems:[32],siteDefinition:[32],search:[32],siteSelector:[32],languageSelector:[32],languageOptions:[32],loginDialog:[32],minimizeSearch:[32],loggedIn:[32],loginManager:[32]},[[0,"setLanguage","onLanguageSelectorChange"],[0,"loginStateChange","onLoginStateChange"],[9,"resize","handleResize"]]]]],["p-c799bf36",[[0,"pn-find-price",{source:[1],language:[1025],market:[1025],filteredItems:[32],weight:[32],weightvalue:[32],sourceData:[32],sizecategory:[32]}]]],["p-4d5aa13e",[[0,"pn-find-service-and-price",{source:[1],language:[1025],market:[1025],filteredItems:[32],postagetype:[32],weight:[32],weightvalue:[32],deliveryscope:[32],sourceData:[32]}]]],["p-71a31b15",[[4,"pn-product-pricelist",{source:[1],language:[1025],market:[1025],productid:[1],filteredItems:[32],sourceData:[32],gotData:[32],loading:[32],postagetype:[32],weight:[32],weightvalue:[32]}]]],["p-cfe1550c",[[0,"pn-marketweb-sitefooter",{market:[1537],language:[1537],environment:[1537],endpoint:[1],cache:[4],siteDefinition:[32],footerContent:[32],i18n:[32],gotData:[32],fetchingData:[32]}]]],["p-aea09ac6",[[4,"pn-bonus-progressbar",{icon:[1],heading:[1],theme:[513],bonuspercentage:[1],currency:[513],value:[1538],min:[1538],max:[1538],valuepercentage:[32],progresspercentage:[32],levelValues:[32],currentLevelAdjustedValue:[32]}]]],["p-ac5a749b",[[1,"pn-filter-checkbox",{value:[520],name:[1],checkboxid:[1],disabled:[4],checked:[4],indeterminate:[1028]},[[0,"change","handlechange"]]]]],["p-66fb0f57",[[1,"pn-filter-search",{disabled:[4],placeholder:[1],inputid:[1],name:[1],autocomplete:[1],value:[1],label:[1],loading:[4],button:[1],light:[4]},[[0,"input","inputHandler"]]]]],["p-1ccd3831",[[0,"pn-pex-pricefinder",{language:[1],currency:[1],apiUrl:[1,"api-url"],i18n:[32],fromzip:[32],tozip:[32],weight:[32],when:[32],response:[32]},[[0,"language","setLanguage"]]]]],["p-3552ae09",[[4,"pn-profile-selector",{language:[1537],returnUrl:[1,"return-url"],i18n:[32],isLoading:[32],numberOfProfiles:[32]}]]],["p-3ba257c5",[[0,"pn-profile-selector-option",{name:[1],identifier:[1],url:[1]}]]],["p-56ba3951",[[4,"pn-sidenav",{language:[1],navLabel:[1,"nav-label"],i18n:[32]},[[0,"language","setLanguage"],[0,"openSubMenuLevelChange","onOpenSubMenuLevelChange"]]]]],["p-d546d0c3",[[4,"pn-sidenav-level",{level:[32],levelId:[32],isOpen:[32],parentName:[32],parentHref:[32],parentLinkId:[32],alignment:[32]}]]],["p-00d6033e",[[4,"pn-sidenav-link",{name:[1],href:[1],target:[1],linkid:[1],icon:[1],current:[4],levelId:[32],open:[32],hasChildren:[32]}]]],["p-45bb8f15",[[0,"pn-find-price-result",{item:[1040],shownitems:[16],weightText:[32]}]]],["p-7fca7510",[[0,"pn-find-service-and-price-result",{item:[1040],shownitems:[16],weightText:[32]}]]],["p-ab699e09",[[0,"pn-product-pricelist-result",{item:[1040],shownitems:[16],weightText:[32]}]]],["p-8325d608",[[0,"pn-bonus-progressbar-level",{current:[516],value:[1538],bonuspercentage:[1537],visualpercentage:[1538],percentage:[32],max:[32],min:[32],currency:[32]}]]],["p-0eef21d9",[[4,"pn-site-footer",{url:[1]}],[4,"pn-site-footer-col"]]],["p-9aac6bd5",[[4,"pn-choice-button",{value:[520],name:[1],choiceid:[1],type:[1],disabled:[4],checked:[4],indeterminate:[1028]},[[0,"change","handlechange"]]]]],["p-544f8fb9",[[4,"pn-mainnav-link",{name:[1],href:[1],target:[1],linkid:[1],levelId:[32],open:[32],hasChildren:[32]}]]],["p-518b1864",[[4,"pn-product-card"],[0,"pn-product-card-info",{rulle:[1],paket:[1],label:[1],text:[1]}],[0,"pn-product-card-price",{label:[1],amount:[1],currency:[1],note:[1],url:[1]}]]],["p-2b34c4bd",[[4,"pn-mainnav-level",{level:[32],levelId:[32],isOpen:[32],parentName:[32],parentHref:[32],parentLinkId:[32],listCount:[32],alignment:[32]}],[4,"pn-language-selector",{value:[1537],selectedLanguageName:[32],options:[32],i18n:[32]}],[0,"pn-language-selector-option",{name:[1],code:[1],url:[1],selected:[4],currentLanguage:[1,"current-language"]}],[4,"pn-mainnav",{market:[1],language:[1],navigationId:[1,"navigation-id"],openMenu:[1028,"open-menu"],navLabel:[1,"nav-label"]},[[0,"language","setLanguage"],[0,"market","setMarket"],[0,"menuLanguageChange","onLanguageChange"],[0,"setmenuopenstate","setMenuOpenState"],[0,"openMenuLevelChange","onOpenMenuLevelChange"]]],[4,"pn-mainnav-list",{heading:[1],linkCount:[32]}],[0,"pn-marketweb-siteheader-login",{endpoint:[1],token:[1],i18n:[8,"i-1-8n"],emitEvents:[4,"emit-events"],loginDialog:[1040],loginManager:[32],loggedIn:[32],toggleButtonText:[32],username:[32]}],[0,"pn-marketweb-siteheader-search",{i18n:[8,"i-1-8n"],showOnlyLink:[1028,"show-only-link"],hideSearch:[1028,"hide-search"],search:[1040]}],[4,"pn-site-selector",{buttontext:[1537],heading:[1537],language:[1537],i18n:[32]}],[0,"pn-site-selector-item",{url:[1],heading:[1],description:[1],newwindow:[4]}]]],["p-d26967cb",[[4,"pn-product-tile"],[0,"pn-product-tile-info",{label:[1],text:[1],icon:[1]}],[0,"pn-product-tile-price",{label:[1],amount:[1],currency:[1],url:[1]}]]]],e)));
@@ -16,6 +16,7 @@ declare class MarketWebLoginManager {
16
16
  logoutEndpoint: string;
17
17
  };
18
18
  keys: {
19
+ tokensource: string;
19
20
  token: string;
20
21
  user: string;
21
22
  expire: string;
@@ -24,7 +25,8 @@ declare class MarketWebLoginManager {
24
25
  constructor(options?: IMarketWebLoginManagerOptions);
25
26
  init(checkParameters?: boolean): void;
26
27
  isLoggedIn(): boolean;
27
- registerToken(token: string): void;
28
+ registerToken(token?: string, tokenSource?: string): void;
29
+ invalidateTokenOfType(tokenSource?: string): void;
28
30
  getLoginUrl(redirectPage?: string): string;
29
31
  getLogoutUrl(redirectPage?: string): string;
30
32
  getUserInfo(): IUserInfo;
@@ -1 +0,0 @@
1
- var __awaiter=this&&this.__awaiter||function(t,e,n,o){function i(t){return t instanceof n?t:new n((function(e){e(t)}))}return new(n||(n=Promise))((function(n,r){function s(t){try{c(o.next(t))}catch(e){r(e)}}function a(t){try{c(o["throw"](t))}catch(e){r(e)}}function c(t){t.done?n(t.value):i(t.value).then(s,a)}c((o=o.apply(t,e||[])).next())}))};var __generator=this&&this.__generator||function(t,e){var n={label:0,sent:function(){if(r[0]&1)throw r[1];return r[1]},trys:[],ops:[]},o,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(t){return function(e){return c([t,e])}}function c(s){if(o)throw new TypeError("Generator is already executing.");while(n)try{if(o=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:n.label++;return{value:s[1],done:false};case 5:n.label++;i=s[1];s=[0];continue;case 7:s=n.ops.pop();n.trys.pop();continue;default:if(!(r=n.trys,r=r.length>0&&r[r.length-1])&&(s[0]===6||s[0]===2)){n=0;continue}if(s[0]===3&&(!r||s[1]>r[0]&&s[1]<r[3])){n.label=s[1];break}if(s[0]===6&&n.label<r[1]){n.label=r[1];r=s;break}if(r&&n.label<r[2]){n.label=r[2];n.ops.push(s);break}if(r[2])n.ops.pop();n.trys.pop();continue}s=e.call(t,n)}catch(a){s=[6,a];i=0}finally{o=r=0}if(s[0]&5)throw s[1];return{value:s[0]?s[1]:void 0,done:true}}};var MarketWebLoginManager=function(){function t(t){var e=this;if(t===void 0){t=null}var n;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={token:"token",user:"user",expire:"expire",expireDate:"expiredate"};this.store={get:function(t){var n=window.sessionStorage.getItem("".concat(e.storagePrefix,"-").concat(t));if(!n){return n}if(n.indexOf("{")===0){try{return JSON.parse(n)}catch(o){}}if(n.indexOf(",")!==-1){return n.split(",")}return n},set:function(t,n){if(typeof n==="object"&&typeof n.length==="undefined"){window.sessionStorage.setItem("".concat(e.storagePrefix,"-").concat(t),JSON.stringify(n));return}window.sessionStorage.setItem("".concat(e.storagePrefix,"-").concat(t),n)},remove:function(t){window.sessionStorage.removeItem("".concat(e.storagePrefix,"-").concat(t))}};if(!t){return}this.eventTarget=t.eventTarget?t.eventTarget:this.eventTarget;this.endpoint=t.endpoint?t.endpoint:"".concat(window.location.protocol,"//").concat(window.location.host);(n=this.storagePrefix)!==null&&n!==void 0?n:this.storagePrefix=t.storagePrefix}t.prototype.init=function(t){if(t===void 0){t=true}if(t){this.checkParameters();this.checkExpireTime();if(this.store.get(this.keys.token)&&!this.store.get(this.keys.user)){this.fetchUserInfo()}this.loginStateChange()}};t.prototype.isLoggedIn=function(){var t=this.store.get(this.keys.token)&&this.store.get(this.keys.user)?true:false;return t};t.prototype.registerToken=function(t){if(!t||t===this.getToken()){return}this.clearUserData();this.store.set(this.keys.token,t);this.fetchUserInfo()};t.prototype.getLoginUrl=function(t){if(t===void 0){t=""}var e=window.location.href;t=t?t:e;return"".concat(this.getBaseUrl()).concat(this.endpoints.authorizationEndpoint,"?redirectionUrl=").concat(t)};t.prototype.getLogoutUrl=function(t){if(t===void 0){t=""}t=window.location.origin+"/logout";return"".concat(this.getBaseUrl()).concat(this.endpoints.logoutEndpoint,"?redirectionUrl=").concat(t,"&authorization=").concat(this.store.get(this.keys.token))};t.prototype.getUserInfo=function(){if(this.isLoggedIn()){return this.store.get(this.keys.user)}};t.prototype.getEventTarget=function(){return this.eventTarget};t.prototype.checkExpireTime=function(){var t=this.store.get(this.keys.expire);if(!t){return}var e=new Date;var n=new Date(Math.floor(parseInt(t,10)*1e3));if(e>n){console.info("Login time has expired");this.clearUserData();this.loginStateChange()}};t.prototype.checkParameters=function(){if(!(window===null||window===void 0?void 0:window.location)){return}var t=new URLSearchParams(window.location.search);if(t.get("oneTimeCode")){var e=t.get("oneTimeCode");this.exchangeToken(e).then((function(){var t=window.location.href;var n=t.indexOf("?oneTimeCode")!==-1?"?":"&";history.replaceState({},document.querySelector("title").innerText,t.replace("".concat(n,"oneTimeCode=").concat(e),""))}))}};t.prototype.fetchUserInfo=function(){return __awaiter(this,void 0,void 0,(function(){var t,e,n,o,i,r,s;return __generator(this,(function(a){switch(a.label){case 0:t=this.store.get(this.keys.token);e={method:"GET",headers:{Accept:"application/json","Content-Type":"application/json",Authorization:t}};return[4,fetch("".concat(this.getBaseUrl()).concat(this.endpoints.userInfoEndpoint),e)];case 1:n=a.sent();return[4,n.json()];case 2:o=a.sent();if(o){try{i=o.idToken,r=o.expiryTime;s=this.parseUserInfo(i);this.store.set(this.keys.user,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(c){console.error("Unable to get user information",c)}}return[2]}}))}))};t.prototype.clearUserData=function(){this.store.remove(this.keys.user);this.store.remove(this.keys.token);this.store.remove(this.keys.expire);this.store.remove(this.keys.expireDate)};t.prototype.getToken=function(){return this.store.get(this.keys.token)};t.prototype.exchangeToken=function(t){return __awaiter(this,void 0,void 0,(function(){var e,n;return __generator(this,(function(o){switch(o.label){case 0:this.clearUserData();return[4,fetch("".concat(this.getBaseUrl()).concat(this.endpoints.tokenExchangeEndpoint,"?oneTimeCode=").concat(t))];case 1:e=o.sent();return[4,e.json()];case 2:n=o.sent().token;if(typeof n==="string"&&n){this.store.set(this.keys.token,n)}this.fetchUserInfo();return[2]}}))}))};t.prototype.loginStateChange=function(){if(!this.eventTarget){return}this.eventTarget.dispatchEvent(new CustomEvent(this.events.loginstatechange,{detail:this.isLoggedIn()}))};t.prototype.getBaseUrl=function(){var t=this;var e=["localhost","integration.","local."];var n=e.filter((function(e){return t.endpoint.indexOf(e)!==-1})).length>0;if(n){return this.baseUrls.at}return this.baseUrls.prod};t.prototype.parseUserInfo=function(t){var e=t.split(".")[1];var n=e.replace(/-/g,"+").replace(/_/g,"/");var o=decodeURIComponent(atob(n).split("").map((function(t){return"%"+("00"+t.charCodeAt(0).toString(16)).slice(-2)})).join(""));return JSON.parse(o)};return t}();export{MarketWebLoginManager as M};
@@ -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={token:"token",user:"user",expire:"expire",expireDate:"expiredate"},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))}init(t=!0){t&&(this.checkParameters(),this.checkExpireTime(),this.store.get(this.keys.token)&&!this.store.get(this.keys.user)&&this.fetchUserInfo(),this.loginStateChange())}isLoggedIn(){return!(!this.store.get(this.keys.token)||!this.store.get(this.keys.user))}registerToken(t){t&&t!==this.getToken()&&(this.clearUserData(),this.store.set(this.keys.token,t),this.fetchUserInfo())}getLoginUrl(t=""){const i=window.location.href;return t=t||i,`${this.getBaseUrl()}${this.endpoints.authorizationEndpoint}?redirectionUrl=${t}`}getLogoutUrl(t=""){return t=window.location.origin+"/logout",`${this.getBaseUrl()}${this.endpoints.logoutEndpoint}?redirectionUrl=${t}&authorization=${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())}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")?"?":"&";history.replaceState({},document.querySelector("title").innerText,t.replace(`${e}oneTimeCode=${i}`,""))}))}}async fetchUserInfo(){const t={method:"GET",headers:{Accept:"application/json","Content-Type":"application/json",Authorization:this.store.get(this.keys.token)}},i=await fetch(`${this.getBaseUrl()}${this.endpoints.userInfoEndpoint}`,t),e=await i.json();if(e)try{const{idToken:t,expiryTime:i}=e,s=this.parseUserInfo(t);this.store.set(this.keys.user,s),this.store.set(this.keys.expire,i),this.store.set(this.keys.expireDate,new Date(Math.floor(1e3*parseInt(i,10)))),this.loginStateChange()}catch(s){console.error("Unable to get user information",s)}}clearUserData(){this.store.remove(this.keys.user),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)}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){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}
@@ -1 +0,0 @@
1
- var __awaiter=this&&this.__awaiter||function(t,e,n,o){function i(t){return t instanceof n?t:new n((function(e){e(t)}))}return new(n||(n=Promise))((function(n,r){function s(t){try{c(o.next(t))}catch(e){r(e)}}function a(t){try{c(o["throw"](t))}catch(e){r(e)}}function c(t){t.done?n(t.value):i(t.value).then(s,a)}c((o=o.apply(t,e||[])).next())}))};var __generator=this&&this.__generator||function(t,e){var n={label:0,sent:function(){if(r[0]&1)throw r[1];return r[1]},trys:[],ops:[]},o,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(t){return function(e){return c([t,e])}}function c(s){if(o)throw new TypeError("Generator is already executing.");while(n)try{if(o=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:n.label++;return{value:s[1],done:false};case 5:n.label++;i=s[1];s=[0];continue;case 7:s=n.ops.pop();n.trys.pop();continue;default:if(!(r=n.trys,r=r.length>0&&r[r.length-1])&&(s[0]===6||s[0]===2)){n=0;continue}if(s[0]===3&&(!r||s[1]>r[0]&&s[1]<r[3])){n.label=s[1];break}if(s[0]===6&&n.label<r[1]){n.label=r[1];r=s;break}if(r&&n.label<r[2]){n.label=r[2];n.ops.push(s);break}if(r[2])n.ops.pop();n.trys.pop();continue}s=e.call(t,n)}catch(a){s=[6,a];i=0}finally{o=r=0}if(s[0]&5)throw s[1];return{value:s[0]?s[1]:void 0,done:true}}};System.register([],(function(t){"use strict";return{execute:function(){var e=function(){function t(t){var e=this;if(t===void 0){t=null}var n;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={token:"token",user:"user",expire:"expire",expireDate:"expiredate"};this.store={get:function(t){var n=window.sessionStorage.getItem("".concat(e.storagePrefix,"-").concat(t));if(!n){return n}if(n.indexOf("{")===0){try{return JSON.parse(n)}catch(o){}}if(n.indexOf(",")!==-1){return n.split(",")}return n},set:function(t,n){if(typeof n==="object"&&typeof n.length==="undefined"){window.sessionStorage.setItem("".concat(e.storagePrefix,"-").concat(t),JSON.stringify(n));return}window.sessionStorage.setItem("".concat(e.storagePrefix,"-").concat(t),n)},remove:function(t){window.sessionStorage.removeItem("".concat(e.storagePrefix,"-").concat(t))}};if(!t){return}this.eventTarget=t.eventTarget?t.eventTarget:this.eventTarget;this.endpoint=t.endpoint?t.endpoint:"".concat(window.location.protocol,"//").concat(window.location.host);(n=this.storagePrefix)!==null&&n!==void 0?n:this.storagePrefix=t.storagePrefix}t.prototype.init=function(t){if(t===void 0){t=true}if(t){this.checkParameters();this.checkExpireTime();if(this.store.get(this.keys.token)&&!this.store.get(this.keys.user)){this.fetchUserInfo()}this.loginStateChange()}};t.prototype.isLoggedIn=function(){var t=this.store.get(this.keys.token)&&this.store.get(this.keys.user)?true:false;return t};t.prototype.registerToken=function(t){if(!t||t===this.getToken()){return}this.clearUserData();this.store.set(this.keys.token,t);this.fetchUserInfo()};t.prototype.getLoginUrl=function(t){if(t===void 0){t=""}var e=window.location.href;t=t?t:e;return"".concat(this.getBaseUrl()).concat(this.endpoints.authorizationEndpoint,"?redirectionUrl=").concat(t)};t.prototype.getLogoutUrl=function(t){if(t===void 0){t=""}t=window.location.origin+"/logout";return"".concat(this.getBaseUrl()).concat(this.endpoints.logoutEndpoint,"?redirectionUrl=").concat(t,"&authorization=").concat(this.store.get(this.keys.token))};t.prototype.getUserInfo=function(){if(this.isLoggedIn()){return this.store.get(this.keys.user)}};t.prototype.getEventTarget=function(){return this.eventTarget};t.prototype.checkExpireTime=function(){var t=this.store.get(this.keys.expire);if(!t){return}var e=new Date;var n=new Date(Math.floor(parseInt(t,10)*1e3));if(e>n){console.info("Login time has expired");this.clearUserData();this.loginStateChange()}};t.prototype.checkParameters=function(){if(!(window===null||window===void 0?void 0:window.location)){return}var t=new URLSearchParams(window.location.search);if(t.get("oneTimeCode")){var e=t.get("oneTimeCode");this.exchangeToken(e).then((function(){var t=window.location.href;var n=t.indexOf("?oneTimeCode")!==-1?"?":"&";history.replaceState({},document.querySelector("title").innerText,t.replace("".concat(n,"oneTimeCode=").concat(e),""))}))}};t.prototype.fetchUserInfo=function(){return __awaiter(this,void 0,void 0,(function(){var t,e,n,o,i,r,s;return __generator(this,(function(a){switch(a.label){case 0:t=this.store.get(this.keys.token);e={method:"GET",headers:{Accept:"application/json","Content-Type":"application/json",Authorization:t}};return[4,fetch("".concat(this.getBaseUrl()).concat(this.endpoints.userInfoEndpoint),e)];case 1:n=a.sent();return[4,n.json()];case 2:o=a.sent();if(o){try{i=o.idToken,r=o.expiryTime;s=this.parseUserInfo(i);this.store.set(this.keys.user,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(c){console.error("Unable to get user information",c)}}return[2]}}))}))};t.prototype.clearUserData=function(){this.store.remove(this.keys.user);this.store.remove(this.keys.token);this.store.remove(this.keys.expire);this.store.remove(this.keys.expireDate)};t.prototype.getToken=function(){return this.store.get(this.keys.token)};t.prototype.exchangeToken=function(t){return __awaiter(this,void 0,void 0,(function(){var e,n;return __generator(this,(function(o){switch(o.label){case 0:this.clearUserData();return[4,fetch("".concat(this.getBaseUrl()).concat(this.endpoints.tokenExchangeEndpoint,"?oneTimeCode=").concat(t))];case 1:e=o.sent();return[4,e.json()];case 2:n=o.sent().token;if(typeof n==="string"&&n){this.store.set(this.keys.token,n)}this.fetchUserInfo();return[2]}}))}))};t.prototype.loginStateChange=function(){if(!this.eventTarget){return}this.eventTarget.dispatchEvent(new CustomEvent(this.events.loginstatechange,{detail:this.isLoggedIn()}))};t.prototype.getBaseUrl=function(){var t=this;var e=["localhost","integration.","local."];var n=e.filter((function(e){return t.endpoint.indexOf(e)!==-1})).length>0;if(n){return this.baseUrls.at}return this.baseUrls.prod};t.prototype.parseUserInfo=function(t){var e=t.split(".")[1];var n=e.replace(/-/g,"+").replace(/_/g,"/");var o=decodeURIComponent(atob(n).split("").map((function(t){return"%"+("00"+t.charCodeAt(0).toString(16)).slice(-2)})).join(""));return JSON.parse(o)};return t}();t("M",e)}}}));