@postnord/pn-marketweb-components 2.0.136 → 2.0.138

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 (35) hide show
  1. package/cjs/{MarketWebLoginManager-c844354b.js → MarketWebLoginManager-2e2c83c4.js} +4 -2
  2. package/cjs/pn-language-selector_9.cjs.entry.js +10 -5
  3. package/cjs/pn-marketweb-siteheader-login-links_2.cjs.entry.js +8 -4
  4. package/cjs/pn-marketweb-siteheader.cjs.entry.js +1 -1
  5. package/collection/components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader-login-links.js +3 -1
  6. package/collection/components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader-login-profileselection.js +7 -3
  7. package/collection/components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader-login.js +9 -4
  8. package/collection/globals/MarketWebLoginManager.js +4 -2
  9. package/custom-elements/index.js +21 -10
  10. package/esm/{MarketWebLoginManager-0f9a1dcd.js → MarketWebLoginManager-9499bd89.js} +4 -2
  11. package/esm/pn-language-selector_9.entry.js +10 -5
  12. package/esm/pn-marketweb-siteheader-login-links_2.entry.js +8 -4
  13. package/esm/pn-marketweb-siteheader.entry.js +1 -1
  14. package/esm-es5/{MarketWebLoginManager-0f9a1dcd.js → MarketWebLoginManager-9499bd89.js} +1 -1
  15. package/esm-es5/pn-language-selector_9.entry.js +1 -1
  16. package/esm-es5/pn-marketweb-siteheader-login-links_2.entry.js +1 -1
  17. package/esm-es5/pn-marketweb-siteheader.entry.js +1 -1
  18. package/package.json +1 -1
  19. package/pn-market-web-components/p-2878af00.system.entry.js +1 -0
  20. package/pn-market-web-components/p-2a23d908.entry.js +1 -0
  21. package/pn-market-web-components/p-4293e33c.js +1 -0
  22. package/pn-market-web-components/{p-33550605.system.entry.js → p-5b05ceb5.system.entry.js} +1 -1
  23. package/pn-market-web-components/p-67887512.system.js +1 -1
  24. package/pn-market-web-components/{p-ef89acea.entry.js → p-7920cff0.entry.js} +1 -1
  25. package/pn-market-web-components/p-8fe91339.entry.js +1 -0
  26. package/pn-market-web-components/{p-6aad9d43.system.entry.js → p-c23004ab.system.entry.js} +1 -1
  27. package/pn-market-web-components/p-ced9727b.system.js +1 -0
  28. package/pn-market-web-components/pn-market-web-components.esm.js +1 -1
  29. package/umd/pn-marketweb-init.js +1 -1
  30. package/umd/pn-marketweb-salesforce.js +2 -2
  31. package/pn-market-web-components/p-285888b7.system.entry.js +0 -1
  32. package/pn-market-web-components/p-2897dca0.js +0 -1
  33. package/pn-market-web-components/p-555eac6b.entry.js +0 -1
  34. package/pn-market-web-components/p-9c1d0ba8.system.js +0 -1
  35. package/pn-market-web-components/p-cf03d788.entry.js +0 -1
@@ -135,7 +135,6 @@ class MarketWebLoginManager {
135
135
  catch (e) { }
136
136
  const addSlash = (rootUrl.lastIndexOf('/') !== (rootUrl.length - 1));
137
137
  const siteUrl = rootUrl + (addSlash ? '/' : '') + 'logout';
138
- console.log('siteUrl', siteUrl);
139
138
  const secondLogoutUrl = `${this.getBaseUrl()}${this.endpoints.logoutEndpoint}?authorization=${this.store.get(this.keys.token)}%26redirectionUrl=${redirectPage}`;
140
139
  const logoutUrl = `${siteUrl}?logoutUrl=${secondLogoutUrl}`;
141
140
  return logoutUrl;
@@ -257,7 +256,10 @@ class MarketWebLoginManager {
257
256
  }
258
257
  getBaseUrl() {
259
258
  const atEnvironments = ["localhost", "integration.", 'local.'];
260
- const useATEnv = atEnvironments.filter(x => this.endpoint.indexOf(x) !== -1).length > 0;
259
+ let useATEnv = atEnvironments.filter(x => this.endpoint.indexOf(x) !== -1).length > 0;
260
+ if (window.location.hostname.indexOf('atportal.postnord.com') === 0) {
261
+ useATEnv = true;
262
+ }
261
263
  if (useATEnv) {
262
264
  return this.baseUrls.at;
263
265
  }
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  const index = require('./index-e3e27c79.js');
6
6
  const pnMainnavStore = require('./pn-mainnav-store-61a75ea0.js');
7
- const MarketWebLoginManager = require('./MarketWebLoginManager-c844354b.js');
7
+ const MarketWebLoginManager = require('./MarketWebLoginManager-2e2c83c4.js');
8
8
  const index$1 = require('./index-28bbc937.js');
9
9
 
10
10
  const translations$1 = {
@@ -395,12 +395,14 @@ let PnMarketwebSiteheaderLogin = class {
395
395
  this.adjustLoginLinks();
396
396
  }
397
397
  adjustLoginLinks() {
398
- var _a, _b, _c;
398
+ var _a;
399
399
  if (!((_a = this.loginDialog) === null || _a === void 0 ? void 0 : _a.loginMenuLinks)) {
400
400
  return;
401
401
  }
402
402
  const adjustLink = (link, i) => {
403
- link.isLogoutLink = (link.href.indexOf('location.href') !== -1 && link.href.indexOf('logout') !== -1);
403
+ if (!link.isLogoutLink) {
404
+ link.isLogoutLink = (link.pageLink.indexOf('location.href') !== -1 && link.pageLink.indexOf('logout') !== -1);
405
+ }
404
406
  if (link.isLogoutLink) {
405
407
  link.href = this.loginManager.getLogoutUrl(link.href);
406
408
  }
@@ -411,9 +413,12 @@ let PnMarketwebSiteheaderLogin = class {
411
413
  if (link.primaryLinkApperance && !link.linkType) {
412
414
  link.linkType = 'primary';
413
415
  }
416
+ return link;
414
417
  };
415
- (_b = this.loginDialog) === null || _b === void 0 ? void 0 : _b.loginMenuLinks.forEach(adjustLink);
416
- (_c = this.loginDialog) === null || _c === void 0 ? void 0 : _c.loggedInLinks.forEach(adjustLink);
418
+ if (this.loginDialog) {
419
+ this.loginDialog.loginMenuLinks = this.loginDialog.loginMenuLinks.map(adjustLink);
420
+ this.loginDialog.loggedInLinks = this.loginDialog.loggedInLinks.map(adjustLink);
421
+ }
417
422
  this.loginDialog.legacyLoginLinks = [
418
423
  {
419
424
  href: this.loginManager.getLoginUrl(this.loginDialog.loginUrl),
@@ -28,7 +28,9 @@ let PnMarketwebSiteheaderLoginLinks = class {
28
28
  return;
29
29
  }
30
30
  const adjustLink = (link, i) => {
31
- link.isLogoutLink = (link.href.indexOf('location.href') !== -1 && link.href.indexOf('logout') !== -1);
31
+ if (!link.isLogoutLink) {
32
+ link.isLogoutLink = (link.pageLink.indexOf('location.href') !== -1 && link.pageLink.indexOf('logout') !== -1);
33
+ }
32
34
  if (link.isLogoutLink) {
33
35
  link.href = this.loginManager.getLogoutUrl(link.href);
34
36
  }
@@ -236,7 +238,9 @@ let PnMarketwebSiteheaderLoginProfileselection = class {
236
238
  adjustLoginLinks() {
237
239
  var _a, _b, _c, _d;
238
240
  const adjustLink = (link, i) => {
239
- link.isLogoutLink = (link.href.indexOf('location.href') !== -1 && link.href.indexOf('logout') !== -1);
241
+ if (!link.isLogoutLink) {
242
+ link.isLogoutLink = (link.pageLink.indexOf('location.href') !== -1 && link.pageLink.indexOf('logout') !== -1);
243
+ }
240
244
  if (link.isLogoutLink) {
241
245
  link.href = this.loginManager.getLogoutUrl(link.href);
242
246
  }
@@ -285,11 +289,11 @@ let PnMarketwebSiteheaderLoginProfileselection = class {
285
289
  let hostElementAttribute = {};
286
290
  return (index.h(index.Host, Object.assign({}, hostElementAttribute), this.heading ? index.h("strong", { class: "pn-marketweb-siteheader-login-profileselection-heading" }, this.heading) : null, this.currentProfile !== null && this.currentProfile.name ?
287
291
  index.h("div", { class: "pn-marketweb-siteheader-login-profileselection-currentprofile" }, index.h("div", { class: "pn-marketweb-siteheader-login-profileselection-currentprofile-name" }, this.currentProfile.name), index.h("div", { class: "pn-marketweb-siteheader-login-profileselection-currentprofile-description" }, this.currentProfile.customerNumber ? this.currentProfile.customerNumber : this.userEmail))
288
- : null, index.h("pn-marketweb-siteheader-login-linklist", { links: this.loginDialog.loggedInLinks.filter(x => x.isLogoutLink === false), loginManager: this.loginManager, idNamespace: this.idNamespace }), index.h("div", { class: "pn-marketweb-siteheader-login-profileselection-divider" }), this.profileoptions.filter(x => x.selected !== true).map((organization) => {
292
+ : null, index.h("pn-marketweb-siteheader-login-linklist", { links: this.loginDialog.loggedInLinks, loginManager: this.loginManager, idNamespace: this.idNamespace }), index.h("div", { class: "pn-marketweb-siteheader-login-profileselection-divider" }), this.profileoptions.filter(x => x.selected !== true).map((organization) => {
289
293
  let customerNumber = (organization.profiles.length > 0) ? organization.profiles[0].customerNumber : organization.customerNumber;
290
294
  return (index.h("div", { class: "pn-marketweb-siteheader-login-profileselection-profileoption" }, index.h("a", { href: `${this.endpoint}/api/user/setprofile?customernumber=${customerNumber}&returnUrl=${window.location.href}`, class: "pn-marketweb-siteheader-login-profileselection-profileoption-link" }, index.h("div", { class: "pn-marketweb-siteheader-login-profileselection-profileoption-content" }, index.h("div", { class: "pn-marketweb-siteheader-login-profileselection-profileoption-name" }, organization.name), index.h("div", { class: "pn-marketweb-siteheader-login-profileselection-profileoption-description" }, organization.customerNumber ? organization.customerNumber : this.userEmail)), index.h("pn-icon", { symbol: "arrow-right", small: "false", color: "blue700" }))));
291
295
  }), this.logoutLink ?
292
- index.h("div", { class: "pn-marketweb-siteheader-login-profileselection-logout" }, index.h("a", { href: this.logoutLink.href, rel: "nofollower noopener", onClick: () => this.loginManager.clearUserData(), class: "pn-marketweb-siteheader-login-profileselection-logout-link" }, this.logoutLink.linkText))
296
+ index.h("div", { class: "pn-marketweb-siteheader-login-profileselection-logout" }, index.h("a", { href: this.logoutLink.href, rel: "nofollower noopener", onClick: () => this.loginManager.clearUserData(), class: "pn-marketweb-siteheader-login-profileselection-logout-link" }, this.logoutLink.linkText, " asdasdfasdf"))
293
297
  : null));
294
298
  }
295
299
  get hostElement() { return index.getElement(this); }
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  const index = require('./index-e3e27c79.js');
6
6
  const MarketWebContextService = require('./MarketWebContextService-392b4585.js');
7
- const MarketWebLoginManager = require('./MarketWebLoginManager-c844354b.js');
7
+ const MarketWebLoginManager = require('./MarketWebLoginManager-2e2c83c4.js');
8
8
 
9
9
  const translations = {
10
10
  'sv': {
@@ -20,7 +20,9 @@ export class PnMarketwebSiteheaderLoginLinks {
20
20
  return;
21
21
  }
22
22
  const adjustLink = (link, i) => {
23
- link.isLogoutLink = (link.href.indexOf('location.href') !== -1 && link.href.indexOf('logout') !== -1);
23
+ if (!link.isLogoutLink) {
24
+ link.isLogoutLink = (link.pageLink.indexOf('location.href') !== -1 && link.pageLink.indexOf('logout') !== -1);
25
+ }
24
26
  if (link.isLogoutLink) {
25
27
  link.href = this.loginManager.getLogoutUrl(link.href);
26
28
  }
@@ -133,7 +133,9 @@ export class PnMarketwebSiteheaderLoginProfileselection {
133
133
  adjustLoginLinks() {
134
134
  var _a, _b, _c, _d;
135
135
  const adjustLink = (link, i) => {
136
- link.isLogoutLink = (link.href.indexOf('location.href') !== -1 && link.href.indexOf('logout') !== -1);
136
+ if (!link.isLogoutLink) {
137
+ link.isLogoutLink = (link.pageLink.indexOf('location.href') !== -1 && link.pageLink.indexOf('logout') !== -1);
138
+ }
137
139
  if (link.isLogoutLink) {
138
140
  link.href = this.loginManager.getLogoutUrl(link.href);
139
141
  }
@@ -187,7 +189,7 @@ export class PnMarketwebSiteheaderLoginProfileselection {
187
189
  h("div", { class: "pn-marketweb-siteheader-login-profileselection-currentprofile-name" }, this.currentProfile.name),
188
190
  h("div", { class: "pn-marketweb-siteheader-login-profileselection-currentprofile-description" }, this.currentProfile.customerNumber ? this.currentProfile.customerNumber : this.userEmail))
189
191
  : null,
190
- h("pn-marketweb-siteheader-login-linklist", { links: this.loginDialog.loggedInLinks.filter(x => x.isLogoutLink === false), loginManager: this.loginManager, idNamespace: this.idNamespace }),
192
+ h("pn-marketweb-siteheader-login-linklist", { links: this.loginDialog.loggedInLinks, loginManager: this.loginManager, idNamespace: this.idNamespace }),
191
193
  h("div", { class: "pn-marketweb-siteheader-login-profileselection-divider" }),
192
194
  this.profileoptions.filter(x => x.selected !== true).map((organization) => {
193
195
  let customerNumber = (organization.profiles.length > 0) ? organization.profiles[0].customerNumber : organization.customerNumber;
@@ -200,7 +202,9 @@ export class PnMarketwebSiteheaderLoginProfileselection {
200
202
  }),
201
203
  this.logoutLink ?
202
204
  h("div", { class: "pn-marketweb-siteheader-login-profileselection-logout" },
203
- h("a", { href: this.logoutLink.href, rel: "nofollower noopener", onClick: () => this.loginManager.clearUserData(), class: "pn-marketweb-siteheader-login-profileselection-logout-link" }, this.logoutLink.linkText))
205
+ h("a", { href: this.logoutLink.href, rel: "nofollower noopener", onClick: () => this.loginManager.clearUserData(), class: "pn-marketweb-siteheader-login-profileselection-logout-link" },
206
+ this.logoutLink.linkText,
207
+ " asdasdfasdf"))
204
208
  : null));
205
209
  }
206
210
  static get is() { return "pn-marketweb-siteheader-login-profileselection"; }
@@ -47,12 +47,14 @@ export class PnMarketwebSiteheaderLogin {
47
47
  this.adjustLoginLinks();
48
48
  }
49
49
  adjustLoginLinks() {
50
- var _a, _b, _c;
50
+ var _a;
51
51
  if (!((_a = this.loginDialog) === null || _a === void 0 ? void 0 : _a.loginMenuLinks)) {
52
52
  return;
53
53
  }
54
54
  const adjustLink = (link, i) => {
55
- link.isLogoutLink = (link.href.indexOf('location.href') !== -1 && link.href.indexOf('logout') !== -1);
55
+ if (!link.isLogoutLink) {
56
+ link.isLogoutLink = (link.pageLink.indexOf('location.href') !== -1 && link.pageLink.indexOf('logout') !== -1);
57
+ }
56
58
  if (link.isLogoutLink) {
57
59
  link.href = this.loginManager.getLogoutUrl(link.href);
58
60
  }
@@ -63,9 +65,12 @@ export class PnMarketwebSiteheaderLogin {
63
65
  if (link.primaryLinkApperance && !link.linkType) {
64
66
  link.linkType = 'primary';
65
67
  }
68
+ return link;
66
69
  };
67
- (_b = this.loginDialog) === null || _b === void 0 ? void 0 : _b.loginMenuLinks.forEach(adjustLink);
68
- (_c = this.loginDialog) === null || _c === void 0 ? void 0 : _c.loggedInLinks.forEach(adjustLink);
70
+ if (this.loginDialog) {
71
+ this.loginDialog.loginMenuLinks = this.loginDialog.loginMenuLinks.map(adjustLink);
72
+ this.loginDialog.loggedInLinks = this.loginDialog.loggedInLinks.map(adjustLink);
73
+ }
69
74
  this.loginDialog.legacyLoginLinks = [
70
75
  {
71
76
  href: this.loginManager.getLoginUrl(this.loginDialog.loginUrl),
@@ -133,7 +133,6 @@ class MarketWebLoginManager {
133
133
  catch (e) { }
134
134
  const addSlash = (rootUrl.lastIndexOf('/') !== (rootUrl.length - 1));
135
135
  const siteUrl = rootUrl + (addSlash ? '/' : '') + 'logout';
136
- console.log('siteUrl', siteUrl);
137
136
  const secondLogoutUrl = `${this.getBaseUrl()}${this.endpoints.logoutEndpoint}?authorization=${this.store.get(this.keys.token)}%26redirectionUrl=${redirectPage}`;
138
137
  const logoutUrl = `${siteUrl}?logoutUrl=${secondLogoutUrl}`;
139
138
  return logoutUrl;
@@ -255,7 +254,10 @@ class MarketWebLoginManager {
255
254
  }
256
255
  getBaseUrl() {
257
256
  const atEnvironments = ["localhost", "integration.", 'local.'];
258
- const useATEnv = atEnvironments.filter(x => this.endpoint.indexOf(x) !== -1).length > 0;
257
+ let useATEnv = atEnvironments.filter(x => this.endpoint.indexOf(x) !== -1).length > 0;
258
+ if (window.location.hostname.indexOf('atportal.postnord.com') === 0) {
259
+ useATEnv = true;
260
+ }
259
261
  if (useATEnv) {
260
262
  return this.baseUrls.at;
261
263
  }
@@ -26257,7 +26257,6 @@ class MarketWebLoginManager {
26257
26257
  catch (e) { }
26258
26258
  const addSlash = (rootUrl.lastIndexOf('/') !== (rootUrl.length - 1));
26259
26259
  const siteUrl = rootUrl + (addSlash ? '/' : '') + 'logout';
26260
- console.log('siteUrl', siteUrl);
26261
26260
  const secondLogoutUrl = `${this.getBaseUrl()}${this.endpoints.logoutEndpoint}?authorization=${this.store.get(this.keys.token)}%26redirectionUrl=${redirectPage}`;
26262
26261
  const logoutUrl = `${siteUrl}?logoutUrl=${secondLogoutUrl}`;
26263
26262
  return logoutUrl;
@@ -26379,7 +26378,10 @@ class MarketWebLoginManager {
26379
26378
  }
26380
26379
  getBaseUrl() {
26381
26380
  const atEnvironments = ["localhost", "integration.", 'local.'];
26382
- const useATEnv = atEnvironments.filter(x => this.endpoint.indexOf(x) !== -1).length > 0;
26381
+ let useATEnv = atEnvironments.filter(x => this.endpoint.indexOf(x) !== -1).length > 0;
26382
+ if (window.location.hostname.indexOf('atportal.postnord.com') === 0) {
26383
+ useATEnv = true;
26384
+ }
26383
26385
  if (useATEnv) {
26384
26386
  return this.baseUrls.at;
26385
26387
  }
@@ -26856,12 +26858,14 @@ let PnMarketwebSiteheaderLogin$1 = class extends HTMLElement {
26856
26858
  this.adjustLoginLinks();
26857
26859
  }
26858
26860
  adjustLoginLinks() {
26859
- var _a, _b, _c;
26861
+ var _a;
26860
26862
  if (!((_a = this.loginDialog) === null || _a === void 0 ? void 0 : _a.loginMenuLinks)) {
26861
26863
  return;
26862
26864
  }
26863
26865
  const adjustLink = (link, i) => {
26864
- link.isLogoutLink = (link.href.indexOf('location.href') !== -1 && link.href.indexOf('logout') !== -1);
26866
+ if (!link.isLogoutLink) {
26867
+ link.isLogoutLink = (link.pageLink.indexOf('location.href') !== -1 && link.pageLink.indexOf('logout') !== -1);
26868
+ }
26865
26869
  if (link.isLogoutLink) {
26866
26870
  link.href = this.loginManager.getLogoutUrl(link.href);
26867
26871
  }
@@ -26872,9 +26876,12 @@ let PnMarketwebSiteheaderLogin$1 = class extends HTMLElement {
26872
26876
  if (link.primaryLinkApperance && !link.linkType) {
26873
26877
  link.linkType = 'primary';
26874
26878
  }
26879
+ return link;
26875
26880
  };
26876
- (_b = this.loginDialog) === null || _b === void 0 ? void 0 : _b.loginMenuLinks.forEach(adjustLink);
26877
- (_c = this.loginDialog) === null || _c === void 0 ? void 0 : _c.loggedInLinks.forEach(adjustLink);
26881
+ if (this.loginDialog) {
26882
+ this.loginDialog.loginMenuLinks = this.loginDialog.loginMenuLinks.map(adjustLink);
26883
+ this.loginDialog.loggedInLinks = this.loginDialog.loggedInLinks.map(adjustLink);
26884
+ }
26878
26885
  this.loginDialog.legacyLoginLinks = [
26879
26886
  {
26880
26887
  href: this.loginManager.getLoginUrl(this.loginDialog.loginUrl),
@@ -27047,7 +27054,9 @@ let PnMarketwebSiteheaderLoginLinks$1 = class extends HTMLElement {
27047
27054
  return;
27048
27055
  }
27049
27056
  const adjustLink = (link, i) => {
27050
- link.isLogoutLink = (link.href.indexOf('location.href') !== -1 && link.href.indexOf('logout') !== -1);
27057
+ if (!link.isLogoutLink) {
27058
+ link.isLogoutLink = (link.pageLink.indexOf('location.href') !== -1 && link.pageLink.indexOf('logout') !== -1);
27059
+ }
27051
27060
  if (link.isLogoutLink) {
27052
27061
  link.href = this.loginManager.getLogoutUrl(link.href);
27053
27062
  }
@@ -27256,7 +27265,9 @@ let PnMarketwebSiteheaderLoginProfileselection$1 = class extends HTMLElement {
27256
27265
  adjustLoginLinks() {
27257
27266
  var _a, _b, _c, _d;
27258
27267
  const adjustLink = (link, i) => {
27259
- link.isLogoutLink = (link.href.indexOf('location.href') !== -1 && link.href.indexOf('logout') !== -1);
27268
+ if (!link.isLogoutLink) {
27269
+ link.isLogoutLink = (link.pageLink.indexOf('location.href') !== -1 && link.pageLink.indexOf('logout') !== -1);
27270
+ }
27260
27271
  if (link.isLogoutLink) {
27261
27272
  link.href = this.loginManager.getLogoutUrl(link.href);
27262
27273
  }
@@ -27305,11 +27316,11 @@ let PnMarketwebSiteheaderLoginProfileselection$1 = class extends HTMLElement {
27305
27316
  let hostElementAttribute = {};
27306
27317
  return (h(Host, Object.assign({}, hostElementAttribute), this.heading ? h("strong", { class: "pn-marketweb-siteheader-login-profileselection-heading" }, this.heading) : null, this.currentProfile !== null && this.currentProfile.name ?
27307
27318
  h("div", { class: "pn-marketweb-siteheader-login-profileselection-currentprofile" }, h("div", { class: "pn-marketweb-siteheader-login-profileselection-currentprofile-name" }, this.currentProfile.name), h("div", { class: "pn-marketweb-siteheader-login-profileselection-currentprofile-description" }, this.currentProfile.customerNumber ? this.currentProfile.customerNumber : this.userEmail))
27308
- : null, h("pn-marketweb-siteheader-login-linklist", { links: this.loginDialog.loggedInLinks.filter(x => x.isLogoutLink === false), loginManager: this.loginManager, idNamespace: this.idNamespace }), h("div", { class: "pn-marketweb-siteheader-login-profileselection-divider" }), this.profileoptions.filter(x => x.selected !== true).map((organization) => {
27319
+ : null, h("pn-marketweb-siteheader-login-linklist", { links: this.loginDialog.loggedInLinks, loginManager: this.loginManager, idNamespace: this.idNamespace }), h("div", { class: "pn-marketweb-siteheader-login-profileselection-divider" }), this.profileoptions.filter(x => x.selected !== true).map((organization) => {
27309
27320
  let customerNumber = (organization.profiles.length > 0) ? organization.profiles[0].customerNumber : organization.customerNumber;
27310
27321
  return (h("div", { class: "pn-marketweb-siteheader-login-profileselection-profileoption" }, h("a", { href: `${this.endpoint}/api/user/setprofile?customernumber=${customerNumber}&returnUrl=${window.location.href}`, class: "pn-marketweb-siteheader-login-profileselection-profileoption-link" }, h("div", { class: "pn-marketweb-siteheader-login-profileselection-profileoption-content" }, h("div", { class: "pn-marketweb-siteheader-login-profileselection-profileoption-name" }, organization.name), h("div", { class: "pn-marketweb-siteheader-login-profileselection-profileoption-description" }, organization.customerNumber ? organization.customerNumber : this.userEmail)), h("pn-icon", { symbol: "arrow-right", small: "false", color: "blue700" }))));
27311
27322
  }), this.logoutLink ?
27312
- h("div", { class: "pn-marketweb-siteheader-login-profileselection-logout" }, h("a", { href: this.logoutLink.href, rel: "nofollower noopener", onClick: () => this.loginManager.clearUserData(), class: "pn-marketweb-siteheader-login-profileselection-logout-link" }, this.logoutLink.linkText))
27323
+ h("div", { class: "pn-marketweb-siteheader-login-profileselection-logout" }, h("a", { href: this.logoutLink.href, rel: "nofollower noopener", onClick: () => this.loginManager.clearUserData(), class: "pn-marketweb-siteheader-login-profileselection-logout-link" }, this.logoutLink.linkText, " asdasdfasdf"))
27313
27324
  : null));
27314
27325
  }
27315
27326
  get hostElement() { return this; }
@@ -133,7 +133,6 @@ class MarketWebLoginManager {
133
133
  catch (e) { }
134
134
  const addSlash = (rootUrl.lastIndexOf('/') !== (rootUrl.length - 1));
135
135
  const siteUrl = rootUrl + (addSlash ? '/' : '') + 'logout';
136
- console.log('siteUrl', siteUrl);
137
136
  const secondLogoutUrl = `${this.getBaseUrl()}${this.endpoints.logoutEndpoint}?authorization=${this.store.get(this.keys.token)}%26redirectionUrl=${redirectPage}`;
138
137
  const logoutUrl = `${siteUrl}?logoutUrl=${secondLogoutUrl}`;
139
138
  return logoutUrl;
@@ -255,7 +254,10 @@ class MarketWebLoginManager {
255
254
  }
256
255
  getBaseUrl() {
257
256
  const atEnvironments = ["localhost", "integration.", 'local.'];
258
- const useATEnv = atEnvironments.filter(x => this.endpoint.indexOf(x) !== -1).length > 0;
257
+ let useATEnv = atEnvironments.filter(x => this.endpoint.indexOf(x) !== -1).length > 0;
258
+ if (window.location.hostname.indexOf('atportal.postnord.com') === 0) {
259
+ useATEnv = true;
260
+ }
259
261
  if (useATEnv) {
260
262
  return this.baseUrls.at;
261
263
  }
@@ -1,6 +1,6 @@
1
1
  import { r as registerInstance, e as createEvent, h, a as Host, g as getElement } from './index-5397620b.js';
2
2
  import { s as state$1, o as onChange$1 } from './pn-mainnav-store-28571e54.js';
3
- import { M as MarketWebLoginManager } from './MarketWebLoginManager-0f9a1dcd.js';
3
+ import { M as MarketWebLoginManager } from './MarketWebLoginManager-9499bd89.js';
4
4
  import { c as createStore } from './index-7b21ecff.js';
5
5
 
6
6
  const translations$1 = {
@@ -391,12 +391,14 @@ let PnMarketwebSiteheaderLogin = class {
391
391
  this.adjustLoginLinks();
392
392
  }
393
393
  adjustLoginLinks() {
394
- var _a, _b, _c;
394
+ var _a;
395
395
  if (!((_a = this.loginDialog) === null || _a === void 0 ? void 0 : _a.loginMenuLinks)) {
396
396
  return;
397
397
  }
398
398
  const adjustLink = (link, i) => {
399
- link.isLogoutLink = (link.href.indexOf('location.href') !== -1 && link.href.indexOf('logout') !== -1);
399
+ if (!link.isLogoutLink) {
400
+ link.isLogoutLink = (link.pageLink.indexOf('location.href') !== -1 && link.pageLink.indexOf('logout') !== -1);
401
+ }
400
402
  if (link.isLogoutLink) {
401
403
  link.href = this.loginManager.getLogoutUrl(link.href);
402
404
  }
@@ -407,9 +409,12 @@ let PnMarketwebSiteheaderLogin = class {
407
409
  if (link.primaryLinkApperance && !link.linkType) {
408
410
  link.linkType = 'primary';
409
411
  }
412
+ return link;
410
413
  };
411
- (_b = this.loginDialog) === null || _b === void 0 ? void 0 : _b.loginMenuLinks.forEach(adjustLink);
412
- (_c = this.loginDialog) === null || _c === void 0 ? void 0 : _c.loggedInLinks.forEach(adjustLink);
414
+ if (this.loginDialog) {
415
+ this.loginDialog.loginMenuLinks = this.loginDialog.loginMenuLinks.map(adjustLink);
416
+ this.loginDialog.loggedInLinks = this.loginDialog.loggedInLinks.map(adjustLink);
417
+ }
413
418
  this.loginDialog.legacyLoginLinks = [
414
419
  {
415
420
  href: this.loginManager.getLoginUrl(this.loginDialog.loginUrl),
@@ -24,7 +24,9 @@ let PnMarketwebSiteheaderLoginLinks = class {
24
24
  return;
25
25
  }
26
26
  const adjustLink = (link, i) => {
27
- link.isLogoutLink = (link.href.indexOf('location.href') !== -1 && link.href.indexOf('logout') !== -1);
27
+ if (!link.isLogoutLink) {
28
+ link.isLogoutLink = (link.pageLink.indexOf('location.href') !== -1 && link.pageLink.indexOf('logout') !== -1);
29
+ }
28
30
  if (link.isLogoutLink) {
29
31
  link.href = this.loginManager.getLogoutUrl(link.href);
30
32
  }
@@ -232,7 +234,9 @@ let PnMarketwebSiteheaderLoginProfileselection = class {
232
234
  adjustLoginLinks() {
233
235
  var _a, _b, _c, _d;
234
236
  const adjustLink = (link, i) => {
235
- link.isLogoutLink = (link.href.indexOf('location.href') !== -1 && link.href.indexOf('logout') !== -1);
237
+ if (!link.isLogoutLink) {
238
+ link.isLogoutLink = (link.pageLink.indexOf('location.href') !== -1 && link.pageLink.indexOf('logout') !== -1);
239
+ }
236
240
  if (link.isLogoutLink) {
237
241
  link.href = this.loginManager.getLogoutUrl(link.href);
238
242
  }
@@ -281,11 +285,11 @@ let PnMarketwebSiteheaderLoginProfileselection = class {
281
285
  let hostElementAttribute = {};
282
286
  return (h(Host, Object.assign({}, hostElementAttribute), this.heading ? h("strong", { class: "pn-marketweb-siteheader-login-profileselection-heading" }, this.heading) : null, this.currentProfile !== null && this.currentProfile.name ?
283
287
  h("div", { class: "pn-marketweb-siteheader-login-profileselection-currentprofile" }, h("div", { class: "pn-marketweb-siteheader-login-profileselection-currentprofile-name" }, this.currentProfile.name), h("div", { class: "pn-marketweb-siteheader-login-profileselection-currentprofile-description" }, this.currentProfile.customerNumber ? this.currentProfile.customerNumber : this.userEmail))
284
- : null, h("pn-marketweb-siteheader-login-linklist", { links: this.loginDialog.loggedInLinks.filter(x => x.isLogoutLink === false), loginManager: this.loginManager, idNamespace: this.idNamespace }), h("div", { class: "pn-marketweb-siteheader-login-profileselection-divider" }), this.profileoptions.filter(x => x.selected !== true).map((organization) => {
288
+ : null, h("pn-marketweb-siteheader-login-linklist", { links: this.loginDialog.loggedInLinks, loginManager: this.loginManager, idNamespace: this.idNamespace }), h("div", { class: "pn-marketweb-siteheader-login-profileselection-divider" }), this.profileoptions.filter(x => x.selected !== true).map((organization) => {
285
289
  let customerNumber = (organization.profiles.length > 0) ? organization.profiles[0].customerNumber : organization.customerNumber;
286
290
  return (h("div", { class: "pn-marketweb-siteheader-login-profileselection-profileoption" }, h("a", { href: `${this.endpoint}/api/user/setprofile?customernumber=${customerNumber}&returnUrl=${window.location.href}`, class: "pn-marketweb-siteheader-login-profileselection-profileoption-link" }, h("div", { class: "pn-marketweb-siteheader-login-profileselection-profileoption-content" }, h("div", { class: "pn-marketweb-siteheader-login-profileselection-profileoption-name" }, organization.name), h("div", { class: "pn-marketweb-siteheader-login-profileselection-profileoption-description" }, organization.customerNumber ? organization.customerNumber : this.userEmail)), h("pn-icon", { symbol: "arrow-right", small: "false", color: "blue700" }))));
287
291
  }), this.logoutLink ?
288
- h("div", { class: "pn-marketweb-siteheader-login-profileselection-logout" }, h("a", { href: this.logoutLink.href, rel: "nofollower noopener", onClick: () => this.loginManager.clearUserData(), class: "pn-marketweb-siteheader-login-profileselection-logout-link" }, this.logoutLink.linkText))
292
+ h("div", { class: "pn-marketweb-siteheader-login-profileselection-logout" }, h("a", { href: this.logoutLink.href, rel: "nofollower noopener", onClick: () => this.loginManager.clearUserData(), class: "pn-marketweb-siteheader-login-profileselection-logout-link" }, this.logoutLink.linkText, " asdasdfasdf"))
289
293
  : null));
290
294
  }
291
295
  get hostElement() { return getElement(this); }
@@ -1,6 +1,6 @@
1
1
  import { r as registerInstance, e as createEvent, h, a as Host, g as getElement } from './index-5397620b.js';
2
2
  import { F as FetchHelper, M as MarketWebContextService } from './MarketWebContextService-872043cc.js';
3
- import { M as MarketWebLoginManager } from './MarketWebLoginManager-0f9a1dcd.js';
3
+ import { M as MarketWebLoginManager } from './MarketWebLoginManager-9499bd89.js';
4
4
 
5
5
  const translations = {
6
6
  'sv': {
@@ -1 +1 @@
1
- var __awaiter=this&&this.__awaiter||function(e,t,o,n){function r(e){return e instanceof o?e:new o((function(t){t(e)}))}return new(o||(o=Promise))((function(o,i){function s(e){try{c(n.next(e))}catch(t){i(t)}}function a(e){try{c(n["throw"](e))}catch(t){i(t)}}function c(e){e.done?o(e.value):r(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(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,r,i,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,r&&(i=s[0]&2?r["return"]:s[0]?r["throw"]||((i=r["return"])&&i.call(r),0):r.next)&&!(i=i.call(r,s[1])).done)return i;if(r=0,i)s=[s[0]&2,i.value];switch(s[0]){case 0:case 1:i=s;break;case 4:o.label++;return{value:s[1],done:false};case 5:o.label++;r=s[1];s=[0];continue;case 7:s=o.ops.pop();o.trys.pop();continue;default:if(!(i=o.trys,i=i.length>0&&i[i.length-1])&&(s[0]===6||s[0]===2)){o=0;continue}if(s[0]===3&&(!i||s[1]>i[0]&&s[1]<i[3])){o.label=s[1];break}if(s[0]===6&&o.label<i[1]){o.label=i[1];i=s;break}if(i&&o.label<i[2]){o.label=i[2];o.ops.push(s);break}if(i[2])o.ops.pop();o.trys.pop();continue}s=t.call(e,o)}catch(a){s=[6,a];r=0}finally{n=i=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=""}if(e.indexOf("logout?logoutUrl")!==-1){return e}var t=e.replace("logout","").replace("http://window.location.href/?",window.location.href).replace("https://window.location.href/?",window.location.href);var o=this.siteUrl;try{var n=new URL(this.siteUrl+"");o=n.origin}catch(c){}var r=o.lastIndexOf("/")!==o.length-1;var i=o+(r?"/":"")+"logout";console.log("siteUrl",i);var s="".concat(this.getBaseUrl()).concat(this.endpoints.logoutEndpoint,"?authorization=").concat(this.store.get(this.keys.token),"%26redirectionUrl=").concat(t);var a="".concat(i,"?logoutUrl=").concat(s);return a};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,r,i,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{r=n.idToken,i=n.expiryTime,s=n.accessToken;a=this.parseUserInfo(r);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,i);this.store.set(this.keys.expireDate,new Date(Math.floor(parseInt(i,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
+ var __awaiter=this&&this.__awaiter||function(e,t,o,n){function r(e){return e instanceof o?e:new o((function(t){t(e)}))}return new(o||(o=Promise))((function(o,i){function s(e){try{c(n.next(e))}catch(t){i(t)}}function a(e){try{c(n["throw"](e))}catch(t){i(t)}}function c(e){e.done?o(e.value):r(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(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,r,i,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,r&&(i=s[0]&2?r["return"]:s[0]?r["throw"]||((i=r["return"])&&i.call(r),0):r.next)&&!(i=i.call(r,s[1])).done)return i;if(r=0,i)s=[s[0]&2,i.value];switch(s[0]){case 0:case 1:i=s;break;case 4:o.label++;return{value:s[1],done:false};case 5:o.label++;r=s[1];s=[0];continue;case 7:s=o.ops.pop();o.trys.pop();continue;default:if(!(i=o.trys,i=i.length>0&&i[i.length-1])&&(s[0]===6||s[0]===2)){o=0;continue}if(s[0]===3&&(!i||s[1]>i[0]&&s[1]<i[3])){o.label=s[1];break}if(s[0]===6&&o.label<i[1]){o.label=i[1];i=s;break}if(i&&o.label<i[2]){o.label=i[2];o.ops.push(s);break}if(i[2])o.ops.pop();o.trys.pop();continue}s=t.call(e,o)}catch(a){s=[6,a];r=0}finally{n=i=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=""}if(e.indexOf("logout?logoutUrl")!==-1){return e}var t=e.replace("logout","").replace("http://window.location.href/?",window.location.href).replace("https://window.location.href/?",window.location.href);var o=this.siteUrl;try{var n=new URL(this.siteUrl+"");o=n.origin}catch(c){}var r=o.lastIndexOf("/")!==o.length-1;var i=o+(r?"/":"")+"logout";var s="".concat(this.getBaseUrl()).concat(this.endpoints.logoutEndpoint,"?authorization=").concat(this.store.get(this.keys.token),"%26redirectionUrl=").concat(t);var a="".concat(i,"?logoutUrl=").concat(s);return a};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,r,i,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{r=n.idToken,i=n.expiryTime,s=n.accessToken;a=this.parseUserInfo(r);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,i);this.store.set(this.keys.expireDate,new Date(Math.floor(parseInt(i,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(window.location.hostname.indexOf("atportal.postnord.com")===0){o=true}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};