@postnord/pn-marketweb-components 1.0.41 → 1.0.44-beta1

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 (110) hide show
  1. package/cjs/{MarketWebLoginManager-859590e2.js → MarketWebLoginManager-1282a883.js} +1 -2
  2. package/cjs/{convert-57b3dd5e.js → convert-b8a6d658.js} +55 -0
  3. package/cjs/loader.cjs.js +1 -1
  4. package/cjs/pn-choice-button.cjs.entry.js +39 -0
  5. package/cjs/pn-find-price-result.cjs.entry.js +44 -0
  6. package/cjs/pn-find-price-store-85b100ba.js +23 -0
  7. package/cjs/pn-find-price.cjs.entry.js +260 -0
  8. package/cjs/{pn-choice-button_2.cjs.entry.js → pn-find-service-and-price-result.cjs.entry.js} +0 -33
  9. package/cjs/pn-find-service-and-price.cjs.entry.js +1 -1
  10. package/cjs/pn-language-selector_9.cjs.entry.js +17 -2
  11. package/cjs/pn-market-web-components.cjs.js +1 -1
  12. package/cjs/pn-marketweb-sitefooter.cjs.entry.js +0 -1
  13. package/cjs/pn-marketweb-siteheader.cjs.entry.js +5 -6
  14. package/cjs/pn-product-pricelist.cjs.entry.js +1 -1
  15. package/cjs/pn-profile-selector.cjs.entry.js +1 -1
  16. package/collection/collection-manifest.json +2 -0
  17. package/collection/components/layout-components/pn-marketweb-sitefooter/pn-marketweb-sitefooter.js +0 -1
  18. package/collection/components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader-login.js +1 -1
  19. package/collection/components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader.js +28 -30
  20. package/collection/components/navigation/pn-language-selector/pn-language-selector.js +15 -0
  21. package/collection/components/widgets/pn-find-price/data.js +68 -0
  22. package/collection/components/widgets/pn-find-price/find-price.stories.js +27 -0
  23. package/collection/components/widgets/pn-find-price/pn-find-price-result.css +3 -0
  24. package/collection/components/widgets/pn-find-price/pn-find-price-result.js +100 -0
  25. package/collection/components/widgets/pn-find-price/pn-find-price-store.js +20 -0
  26. package/collection/components/widgets/pn-find-price/pn-find-price-translations.js +71 -0
  27. package/collection/components/widgets/pn-find-price/pn-find-price-types.js +1 -0
  28. package/collection/components/widgets/pn-find-price/pn-find-price.css +55 -0
  29. package/collection/components/widgets/pn-find-price/pn-find-price.js +212 -0
  30. package/collection/globals/MarketWebLoginManager.js +1 -2
  31. package/collection/globals/shared/productprice/convert.js +55 -1
  32. package/custom-elements/index.d.ts +12 -0
  33. package/custom-elements/index.js +412 -37
  34. package/esm/{MarketWebLoginManager-83f2e86a.js → MarketWebLoginManager-310d2552.js} +1 -2
  35. package/esm/{convert-b49a0857.js → convert-8cce67c4.js} +55 -1
  36. package/esm/loader.js +1 -1
  37. package/esm/{pn-choice-button_2.entry.js → pn-choice-button.entry.js} +1 -39
  38. package/esm/pn-find-price-result.entry.js +40 -0
  39. package/esm/pn-find-price-store-d2053b72.js +21 -0
  40. package/esm/pn-find-price.entry.js +256 -0
  41. package/esm/pn-find-service-and-price-result.entry.js +41 -0
  42. package/esm/pn-find-service-and-price.entry.js +1 -1
  43. package/esm/pn-language-selector_9.entry.js +17 -2
  44. package/esm/pn-market-web-components.js +1 -1
  45. package/esm/pn-marketweb-sitefooter.entry.js +0 -1
  46. package/esm/pn-marketweb-siteheader.entry.js +5 -6
  47. package/esm/pn-product-pricelist.entry.js +1 -1
  48. package/esm/pn-profile-selector.entry.js +1 -1
  49. package/esm-es5/{MarketWebLoginManager-83f2e86a.js → MarketWebLoginManager-310d2552.js} +1 -1
  50. package/esm-es5/{convert-b49a0857.js → convert-8cce67c4.js} +1 -1
  51. package/esm-es5/loader.js +1 -1
  52. package/esm-es5/pn-choice-button.entry.js +1 -0
  53. package/esm-es5/pn-find-price-result.entry.js +1 -0
  54. package/esm-es5/pn-find-price-store-d2053b72.js +1 -0
  55. package/esm-es5/pn-find-price.entry.js +1 -0
  56. package/esm-es5/pn-find-service-and-price-result.entry.js +1 -0
  57. package/esm-es5/pn-find-service-and-price.entry.js +1 -1
  58. package/esm-es5/pn-language-selector_9.entry.js +1 -1
  59. package/esm-es5/pn-market-web-components.js +1 -1
  60. package/esm-es5/pn-marketweb-sitefooter.entry.js +1 -1
  61. package/esm-es5/pn-marketweb-siteheader.entry.js +1 -1
  62. package/esm-es5/pn-product-pricelist.entry.js +1 -1
  63. package/esm-es5/pn-profile-selector.entry.js +1 -1
  64. package/package.json +1 -1
  65. package/pn-market-web-components/{p-e6a209c6.system.entry.js → p-0d0ea574.system.entry.js} +1 -1
  66. package/pn-market-web-components/p-1611123a.system.entry.js +1 -0
  67. package/pn-market-web-components/{p-b8af690a.entry.js → p-22738646.entry.js} +1 -1
  68. package/pn-market-web-components/p-233ca151.system.js +1 -0
  69. package/pn-market-web-components/p-2456901a.js +1 -0
  70. package/pn-market-web-components/p-2e6644ea.system.entry.js +1 -0
  71. package/pn-market-web-components/p-325a7cae.entry.js +1 -0
  72. package/pn-market-web-components/p-38ff23f5.entry.js +1 -0
  73. package/pn-market-web-components/p-4fcabdb8.entry.js +1 -0
  74. package/pn-market-web-components/p-50454694.system.entry.js +1 -0
  75. package/pn-market-web-components/{p-91624bd5.system.js → p-5ce5be4f.system.js} +2 -2
  76. package/pn-market-web-components/p-5f8ef634.entry.js +1 -0
  77. package/pn-market-web-components/p-6ee881ea.system.entry.js +1 -0
  78. package/pn-market-web-components/p-725e4377.entry.js +1 -0
  79. package/pn-market-web-components/{p-21e0e386.js → p-7dd91709.js} +1 -1
  80. package/pn-market-web-components/p-93d8620b.entry.js +1 -0
  81. package/pn-market-web-components/p-a22df959.system.js +1 -1
  82. package/pn-market-web-components/{p-9aca0bae.entry.js → p-a5284c78.entry.js} +1 -1
  83. package/pn-market-web-components/p-b30e348c.system.entry.js +1 -0
  84. package/pn-market-web-components/p-bea2dcc6.entry.js +1 -0
  85. package/pn-market-web-components/p-c30207e6.js +1 -0
  86. package/pn-market-web-components/{p-f4fda846.system.entry.js → p-d133f30d.system.entry.js} +1 -1
  87. package/pn-market-web-components/p-d8882f68.system.entry.js +1 -0
  88. package/pn-market-web-components/p-da370548.system.entry.js +1 -0
  89. package/pn-market-web-components/p-dd4de1a9.entry.js +1 -0
  90. package/pn-market-web-components/{p-e04f8d34.system.entry.js → p-eb75d0cf.system.entry.js} +1 -1
  91. package/pn-market-web-components/{p-58cdf3a6.system.js → p-f1311662.system.js} +1 -1
  92. package/pn-market-web-components/pn-market-web-components.esm.js +1 -1
  93. package/types/components/navigation/pn-language-selector/pn-language-selector.d.ts +1 -0
  94. package/types/components/widgets/pn-find-price/pn-find-price-result.d.ts +9 -0
  95. package/types/components/widgets/pn-find-price/pn-find-price-store.d.ts +33 -0
  96. package/types/components/widgets/pn-find-price/pn-find-price-translations.d.ts +71 -0
  97. package/types/components/widgets/pn-find-price/pn-find-price-types.d.ts +46 -0
  98. package/types/components/widgets/pn-find-price/pn-find-price.d.ts +16 -0
  99. package/types/components.d.ts +37 -0
  100. package/esm-es5/pn-choice-button_2.entry.js +0 -1
  101. package/pn-market-web-components/p-37801e32.entry.js +0 -1
  102. package/pn-market-web-components/p-3f876199.entry.js +0 -1
  103. package/pn-market-web-components/p-4aa3b95d.entry.js +0 -1
  104. package/pn-market-web-components/p-861210ae.entry.js +0 -1
  105. package/pn-market-web-components/p-a924001f.system.entry.js +0 -1
  106. package/pn-market-web-components/p-ac36097e.system.entry.js +0 -1
  107. package/pn-market-web-components/p-b2383083.system.entry.js +0 -1
  108. package/pn-market-web-components/p-c254cfdf.js +0 -1
  109. package/pn-market-web-components/p-e9d8a991.entry.js +0 -1
  110. package/pn-market-web-components/p-ec1127de.system.entry.js +0 -1
@@ -1,6 +1,6 @@
1
1
  import { r as registerInstance, c as createEvent, h, a as Host, g as getElement } from './index-b26d0794.js';
2
2
  import { M as MarketWebContextService } from './MarketWebContextService-ab7796c6.js';
3
- import { M as MarketWebLoginManager } from './MarketWebLoginManager-83f2e86a.js';
3
+ import { M as MarketWebLoginManager } from './MarketWebLoginManager-310d2552.js';
4
4
  import { F as FetchHelper } from './FetchHelper-a0c8aa54.js';
5
5
 
6
6
  const translations = {
@@ -144,7 +144,6 @@ let PnMarketwebSiteheader = class {
144
144
  }
145
145
  }
146
146
  onLanguageSelectorChange(e) {
147
- console.log('onLanguageSelectorChange(e', e);
148
147
  this.language = e.detail;
149
148
  window.dispatchEvent(new CustomEvent('marketweb-languagechange', { detail: this.language }));
150
149
  }
@@ -293,10 +292,10 @@ let PnMarketwebSiteheader = class {
293
292
  }
294
293
  render() {
295
294
  var _a, _b, _c, _d, _e, _f;
296
- return (h(Host, { language: this.language, market: this.market, environment: this.environment }, h("header", null, h("div", { class: "siteheader-row" }, h("div", { class: "siteheader-topleft" }, h("slot", { name: "topleft" }), !this.hideSiteSelector &&
295
+ return (h(Host, { language: this.language, market: this.market, environment: this.environment }, h("header", null, h("div", { class: "siteheader-row" }, h("div", { class: "siteheader-topleft" }, h("slot", { name: "topleft" }), (this.gotData && this.siteSelector && !this.hideSiteSelector) &&
297
296
  h("pn-site-selector", { language: this.language, buttontext: (_b = (_a = this.siteSelector) === null || _a === void 0 ? void 0 : _a.currentSiteTitle) !== null && _b !== void 0 ? _b : 'postnord' }, (this.gotData && ((_c = this.siteSelector) === null || _c === void 0 ? void 0 : _c.currentSiteTitle)) &&
298
297
  h("pn-site-selector-item", { heading: this.siteSelector.currentSiteTitle + ' ', description: this.siteSelector.currentSiteDescription }), (this.gotData && ((_d = this.siteSelector) === null || _d === void 0 ? void 0 : _d.siteSelections)) && this.siteSelector.siteSelections.map((site) => h("pn-site-selector-item", { heading: site.linkText + ' ', description: site.linkDescription, url: this.adjustSiteSelectorUrl(site.href), newwindow: site.openInNewWindow })))), h("div", { class: "siteheader-logocontainer" }, h("a", { href: this.homePageLink, title: "Home", class: "siteheader-logolink" }, h("svg", { class: "siteheader-logo", xmlns: "http://www.w3.org/2000/svg", width: "12.7rem", height: "2.4rem", viewBox: "0 0 141.73 26.65" }, h("path", { d: "M108.84,13.35c0,6.34-5.17,9-10,9S89,19.76,89,13.63c0-6.28,5.08-9,10-9S108.84,7.25,108.84,13.35Zm-6.56.18a3.4,3.4,0,1,0-6.8,0,3.29,3.29,0,0,0,3.42,3.41A3.24,3.24,0,0,0,102.28,13.54Zm-83,0c0,4.83-3.32,8.82-8.49,8.82a6.54,6.54,0,0,1-4.65-1.57v5.86H0V5.16H6.17V6.8a6.43,6.43,0,0,1,5.11-2.18C16.41,4.62,19.31,8.58,19.31,13.54Zm-6.53,0A3.27,3.27,0,0,0,9.4,10,3.28,3.28,0,0,0,6,13.54,3.29,3.29,0,0,0,9.4,16.95,3.24,3.24,0,0,0,12.78,13.54Zm103.69,0.27c0-2.54,1.54-3.32,3.6-3.32a6.56,6.56,0,0,1,2.08.3L122.3,5.1a3.92,3.92,0,0,0-1.45-.18c-3.45,0-4.38,2.18-4.38,2.18V5.16H110.3V21.84h6.17v-8ZM141.73,0V21.84h-6.16V20.21a6.43,6.43,0,0,1-5.11,2.18c-5.14,0-8-4-8-8.91s3.32-8.82,8.49-8.82a6.54,6.54,0,0,1,4.65,1.57v-5Zm-6,13.48a3.28,3.28,0,0,0-3.41-3.41A3.24,3.24,0,0,0,129,13.47,3.4,3.4,0,1,0,135.75,13.47ZM81.35,4.62c-3.6,0-4.9,2.18-4.9,2.18V5.16H70.29V21.84h6.16V13.29c0-2.11.79-3.08,2.69-3.08s2.18,1.57,2.18,3.57v8.07h6.22V11.6C87.55,7,85.34,4.62,81.35,4.62ZM64.07,1.42H57.9V21.84h6.16V10.36H67l2.81-5.2H64.07V1.42ZM50.26,11.21c-2-.3-2.87-0.3-2.87-1.09s0.81-.94,2.42-0.94a16.15,16.15,0,0,1,5.11.91L56,5.41a24.56,24.56,0,0,0-6.13-.75c-5.89,0-9,2.27-9,5.89,0,2.81,1.66,4.47,6.53,5.11,2.06,0.27,2.81.39,2.81,1.15s-0.82,1-2.24,1a16.67,16.67,0,0,1-6-1.3L40.77,21.3a22.14,22.14,0,0,0,6.68,1c6.35,0,9.28-2.24,9.28-5.89C56.72,13.54,55.15,12,50.26,11.21ZM40.19,13.35c0,6.34-5.17,9-10,9s-9.82-2.6-9.82-8.73c0-6.28,5.08-9,10-9S40.19,7.25,40.19,13.35Zm-6.56.18a3.4,3.4,0,1,0-6.8,0,3.28,3.28,0,0,0,3.41,3.41A3.24,3.24,0,0,0,33.63,13.54Z", fill: "#00A0D6", transform: "translate(0 0)" })))), h("div", { class: "siteheader-topright" }, h("slot", { name: "toprightstart" }), (this.gotData && this.loginDialog && !this.hideLogin) && (h("pn-marketweb-siteheader-login", { token: this.token, loginDialog: this.loginDialog, endpoint: this.endpoint, i18n: this.i18n })), (this.gotData && this.languageOptions && this.languageOptions.length) && !this.hideLanguageSelector &&
299
- h("pn-language-selector", { value: this.language }, this.languageOptions.map(language => h("pn-language-selector-option", { name: language.nativeName, code: language.twoLetterISOLanguageName, selected: language.isCurrent, url: this.getLanguageVersionUrl(language) }))), h("slot", { name: "toprightend" }))), h("div", { class: "siteheader-row" }, h("div", { class: "siteheader-menu" }, h("pn-mainnav", { market: this.market, language: this.language, onMenuOpenChange: (e) => {
298
+ h("pn-language-selector", { value: this.language }, this.languageOptions.map(language => h("pn-language-selector-option", { name: language.nativeName, code: language.twoLetterISOLanguageName, selected: language.isCurrent, url: this.getLanguageVersionUrl(language) }))), h("slot", { name: "toprightend" }))), h("div", { class: "siteheader-row" }, h("div", { class: "siteheader-menu" }, (this.gotData && this.menuItems) && (h("pn-mainnav", { market: this.market, language: this.language, onMenuOpenChange: (e) => {
300
299
  document.body.setAttribute("data-siteheader-menuopen", (e.detail + ''));
301
300
  } }, h("pn-mainnav-level", null, h("pn-mainnav-list", null, this.menuItems.map((item) => {
302
301
  var _a, _b;
@@ -306,11 +305,11 @@ let PnMarketwebSiteheader = class {
306
305
  var _a;
307
306
  return (h("pn-mainnav-link", { name: childitem.name, href: childitem.href, target: (_a = childitem.linkTarget) !== null && _a !== void 0 ? _a : "_self", linkid: childitem.trackingId }));
308
307
  })), (item.promotedMenuItems && item.promotedMenuItems.length > 0) &&
309
- h("pn-mainnav-list", { heading: item.promotedMenuItemsHeader }, item.promotedMenuItems.map((childitem) => (h("pn-mainnav-link", { href: childitem.href, name: childitem.linkText, target: childitem.openInNewWindow ? "_blank" : "_self", linkid: this.promotedItemId(childitem) })))))));
308
+ h("pn-mainnav-list", { heading: item.promotedMenuItemsHeader }, item.promotedMenuItems.map((childitem) => (h("pn-mainnav-link", { href: childitem.href, name: childitem.linkText, target: childitem.openInNewWindow ? "_blank" : "_self", linkid: this.promotedItemId(childitem) + item.id })))))));
310
309
  })), h("div", { slot: "footer", class: "siteheader-menu-footer" }, (this.gotData && this.loginDialog && !this.hideLogin) && (h("pn-marketweb-siteheader-login", { emitEvents: false, loginDialog: this.loginDialog, endpoint: this.endpoint, i18n: this.i18n })), (this.gotData && this.languageOptions && this.languageOptions.length) && !this.hideLanguageSelector &&
311
310
  h("pn-language-selector", { value: this.language }, this.languageOptions.map(language => h("pn-language-selector-option", { name: language.nativeName, code: language.twoLetterISOLanguageName, selected: language.isCurrent, url: this.getLanguageVersionUrl(language) }))), !this.hideSiteSelector &&
312
311
  h("pn-site-selector", { language: this.language }, (this.gotData && ((_e = this.siteSelector) === null || _e === void 0 ? void 0 : _e.currentSiteTitle)) &&
313
- h("pn-site-selector-item", { heading: this.siteSelector.currentSiteTitle, description: this.siteSelector.currentSiteDescription }), (this.gotData && ((_f = this.siteSelector) === null || _f === void 0 ? void 0 : _f.siteSelections)) && this.siteSelector.siteSelections.map((site) => h("pn-site-selector-item", { heading: site.linkText, description: site.linkDescription, url: site.pageLink, newwindow: site.openInNewWindow })))), h("div", { slot: "top", class: "siteheader-menu-top" }, h("pn-marketweb-siteheader-search", { search: this.search, "hide-search": this.hideSearch, i18n: this.i18n }))))), h("pn-marketweb-siteheader-search", { search: this.search, "hide-search": this.hideSearch, "show-only-link": this.minimizeSearch, i18n: this.i18n })))));
312
+ h("pn-site-selector-item", { heading: this.siteSelector.currentSiteTitle, description: this.siteSelector.currentSiteDescription }), (this.gotData && ((_f = this.siteSelector) === null || _f === void 0 ? void 0 : _f.siteSelections)) && this.siteSelector.siteSelections.map((site) => h("pn-site-selector-item", { heading: site.linkText, description: site.linkDescription, url: site.pageLink, newwindow: site.openInNewWindow })))), h("div", { slot: "top", class: "siteheader-menu-top" }, h("pn-marketweb-siteheader-search", { search: this.search, "hide-search": this.hideSearch, i18n: this.i18n })))))), h("pn-marketweb-siteheader-search", { search: this.search, "hide-search": this.hideSearch, "show-only-link": this.minimizeSearch, i18n: this.i18n })))));
314
313
  }
315
314
  get hostElement() { return getElement(this); }
316
315
  static get watchers() { return {
@@ -1,5 +1,5 @@
1
1
  import { r as registerInstance, h, a as Host } from './index-b26d0794.js';
2
- import { c as convertFileFromStream } from './convert-b49a0857.js';
2
+ import { a as convertFileFromStream } from './convert-8cce67c4.js';
3
3
  import { s as state } from './pn-product-pricelist-store-a287a3f5.js';
4
4
  import './index-94746173.js';
5
5
 
@@ -1,6 +1,6 @@
1
1
  import { r as registerInstance, h, a as Host, g as getElement } from './index-b26d0794.js';
2
2
  import { M as MarketWebContextService } from './MarketWebContextService-ab7796c6.js';
3
- import { M as MarketWebLoginManager } from './MarketWebLoginManager-83f2e86a.js';
3
+ import { M as MarketWebLoginManager } from './MarketWebLoginManager-310d2552.js';
4
4
 
5
5
  const translations = {
6
6
  'sv': {
@@ -1 +1 @@
1
- var __awaiter=this&&this.__awaiter||function(e,t,n,o){function i(e){return e instanceof n?e:new n((function(t){t(e)}))}return new(n||(n=Promise))((function(n,r){function s(e){try{h(o.next(e))}catch(t){r(t)}}function a(e){try{h(o["throw"](e))}catch(t){r(t)}}function h(e){e.done?n(e.value):i(e.value).then(s,a)}h((o=o.apply(e,t||[])).next())}))};var __generator=this&&this.__generator||function(e,t){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(e){return function(t){return h([e,t])}}function h(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=t.call(e,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 e(e){var t=this;if(e===void 0){e=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(e){var n=window.sessionStorage.getItem(t.storagePrefix+"-"+e);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(e,n){if(typeof n==="object"&&typeof n.length==="undefined"){window.sessionStorage.setItem(t.storagePrefix+"-"+e,JSON.stringify(n));return}window.sessionStorage.setItem(t.storagePrefix+"-"+e,n)},remove:function(e){window.sessionStorage.removeItem(t.storagePrefix+"-"+e)}};if(!e){return}this.eventTarget=e.eventTarget?e.eventTarget:this.eventTarget;this.endpoint=e.endpoint?e.endpoint:window.location.protocol+"//"+window.location.host;(n=this.storagePrefix)!==null&&n!==void 0?n:this.storagePrefix=e.storagePrefix}e.prototype.init=function(e){if(e===void 0){e=true}if(e){this.checkParameters();this.checkExpireTime();if(this.store.get(this.keys.token)&&!this.store.get(this.keys.user)){this.fetchUserInfo()}this.loginStateChange()}};e.prototype.isLoggedIn=function(){var e=this.store.get(this.keys.token)&&this.store.get(this.keys.user)?true:false;return e};e.prototype.registerToken=function(e){if(!e||e===this.getToken()){return}this.clearUserData();this.store.set(this.keys.token,e);this.fetchUserInfo()};e.prototype.getLoginUrl=function(e){if(e===void 0){e=""}var t=window.location.href;e=e?e:t;return""+this.getBaseUrl()+this.endpoints.authorizationEndpoint+"?redirectionUrl="+e};e.prototype.getLogoutUrl=function(e){if(e===void 0){e=""}var t=window.location.href;e=e?e:t;return""+this.getBaseUrl()+this.endpoints.logoutEndpoint+"?redirectionUrl="+e+"&authorization="+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 n=new Date(Math.floor(parseInt(e,10)*1e3));if(t>n){console.info("Login time has expired");this.clearUserData();this.loginStateChange()}};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 n=e.indexOf("?oneTimeCode")!==-1?"?":"&";history.replaceState({},document.querySelector("title").innerText,e.replace(n+"oneTimeCode="+t,""))}))}};e.prototype.fetchUserInfo=function(){return __awaiter(this,void 0,void 0,(function(){var e,t,n,o,i,r,s;return __generator(this,(function(a){switch(a.label){case 0:e=this.store.get(this.keys.token);t={method:"GET",headers:{Accept:"application/json","Content-Type":"application/json",Authorization:e}};return[4,fetch(""+this.getBaseUrl()+this.endpoints.userInfoEndpoint,t)];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(h){console.error("Unable to get user information",h)}}return[2]}}))}))};e.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)};e.prototype.getToken=function(){return this.store.get(this.keys.token)};e.prototype.exchangeToken=function(e){return __awaiter(this,void 0,void 0,(function(){var t,n;return __generator(this,(function(o){switch(o.label){case 0:this.clearUserData();return[4,fetch(""+this.getBaseUrl()+this.endpoints.tokenExchangeEndpoint+"?oneTimeCode="+e)];case 1:t=o.sent();return[4,t.json()];case 2:n=o.sent().token;if(typeof n==="string"&&n){this.store.set(this.keys.token,n)}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 n=t.filter((function(t){return e.endpoint.indexOf(t)!==-1})).length>0;if(n){return this.baseUrls.at}return this.baseUrls.prod};e.prototype.parseUserInfo=function(e){var t=e.split(".")[1];var n=t.replace(/-/g,"+").replace(/_/g,"/");var o=decodeURIComponent(atob(n).split("").map((function(e){return"%"+("00"+e.charCodeAt(0).toString(16)).slice(-2)})).join(""));return JSON.parse(o)};return e}();export{MarketWebLoginManager as M};
1
+ var __awaiter=this&&this.__awaiter||function(e,t,n,o){function i(e){return e instanceof n?e:new n((function(t){t(e)}))}return new(n||(n=Promise))((function(n,r){function s(e){try{h(o.next(e))}catch(t){r(t)}}function a(e){try{h(o["throw"](e))}catch(t){r(t)}}function h(e){e.done?n(e.value):i(e.value).then(s,a)}h((o=o.apply(e,t||[])).next())}))};var __generator=this&&this.__generator||function(e,t){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(e){return function(t){return h([e,t])}}function h(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=t.call(e,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 e(e){var t=this;if(e===void 0){e=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(e){var n=window.sessionStorage.getItem(t.storagePrefix+"-"+e);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(e,n){if(typeof n==="object"&&typeof n.length==="undefined"){window.sessionStorage.setItem(t.storagePrefix+"-"+e,JSON.stringify(n));return}window.sessionStorage.setItem(t.storagePrefix+"-"+e,n)},remove:function(e){window.sessionStorage.removeItem(t.storagePrefix+"-"+e)}};if(!e){return}this.eventTarget=e.eventTarget?e.eventTarget:this.eventTarget;this.endpoint=e.endpoint?e.endpoint:window.location.protocol+"//"+window.location.host;(n=this.storagePrefix)!==null&&n!==void 0?n:this.storagePrefix=e.storagePrefix}e.prototype.init=function(e){if(e===void 0){e=true}if(e){this.checkParameters();this.checkExpireTime();if(this.store.get(this.keys.token)&&!this.store.get(this.keys.user)){this.fetchUserInfo()}this.loginStateChange()}};e.prototype.isLoggedIn=function(){var e=this.store.get(this.keys.token)&&this.store.get(this.keys.user)?true:false;return e};e.prototype.registerToken=function(e){if(!e||e===this.getToken()){return}this.clearUserData();this.store.set(this.keys.token,e);this.fetchUserInfo()};e.prototype.getLoginUrl=function(e){if(e===void 0){e=""}var t=window.location.href;e=e?e:t;return""+this.getBaseUrl()+this.endpoints.authorizationEndpoint+"?redirectionUrl="+e};e.prototype.getLogoutUrl=function(e){if(e===void 0){e=""}e=window.location.origin+"/logout";return""+this.getBaseUrl()+this.endpoints.logoutEndpoint+"?redirectionUrl="+e+"&authorization="+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 n=new Date(Math.floor(parseInt(e,10)*1e3));if(t>n){console.info("Login time has expired");this.clearUserData();this.loginStateChange()}};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 n=e.indexOf("?oneTimeCode")!==-1?"?":"&";history.replaceState({},document.querySelector("title").innerText,e.replace(n+"oneTimeCode="+t,""))}))}};e.prototype.fetchUserInfo=function(){return __awaiter(this,void 0,void 0,(function(){var e,t,n,o,i,r,s;return __generator(this,(function(a){switch(a.label){case 0:e=this.store.get(this.keys.token);t={method:"GET",headers:{Accept:"application/json","Content-Type":"application/json",Authorization:e}};return[4,fetch(""+this.getBaseUrl()+this.endpoints.userInfoEndpoint,t)];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(h){console.error("Unable to get user information",h)}}return[2]}}))}))};e.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)};e.prototype.getToken=function(){return this.store.get(this.keys.token)};e.prototype.exchangeToken=function(e){return __awaiter(this,void 0,void 0,(function(){var t,n;return __generator(this,(function(o){switch(o.label){case 0:this.clearUserData();return[4,fetch(""+this.getBaseUrl()+this.endpoints.tokenExchangeEndpoint+"?oneTimeCode="+e)];case 1:t=o.sent();return[4,t.json()];case 2:n=o.sent().token;if(typeof n==="string"&&n){this.store.set(this.keys.token,n)}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 n=t.filter((function(t){return e.endpoint.indexOf(t)!==-1})).length>0;if(n){return this.baseUrls.at}return this.baseUrls.prod};e.prototype.parseUserInfo=function(e){var t=e.split(".")[1];var n=t.replace(/-/g,"+").replace(/_/g,"/");var o=decodeURIComponent(atob(n).split("").map((function(e){return"%"+("00"+e.charCodeAt(0).toString(16)).slice(-2)})).join(""));return JSON.parse(o)};return e}();export{MarketWebLoginManager as M};