@postnord/pn-marketweb-components 2.0.148 → 2.0.149
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/loader.cjs.js +1 -1
- package/cjs/pn-language-selector_9.cjs.entry.js +374 -18
- package/cjs/pn-market-web-components.cjs.js +1 -1
- package/cjs/pn-marketweb-siteheader-login-linklist.cjs.entry.js +3 -2
- package/cjs/pn-marketweb-siteheader-login-links_2.cjs.entry.js +15 -15
- package/cjs/pn-marketweb-siteheader-store-5ced6902.js +10 -0
- package/cjs/pn-marketweb-siteheader.cjs.entry.js +11 -6
- package/collection/components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader-login-linklist.js +2 -23
- package/collection/components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader-login-links.js +9 -30
- package/collection/components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader-login-profileselection.js +6 -27
- package/collection/components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader-login.js +36 -17
- package/collection/components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader-search.js +1 -1
- package/collection/components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader-store.js +7 -0
- package/collection/components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader.js +29 -8
- package/collection/components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader.stories.js +13 -1
- package/collection/globals/MarketWebLoginManager.js +77 -0
- package/custom-elements/index.js +729 -645
- package/esm/loader.js +1 -1
- package/esm/pn-language-selector_9.entry.js +374 -18
- package/esm/pn-market-web-components.js +1 -1
- package/esm/pn-marketweb-siteheader-login-linklist.entry.js +3 -2
- package/esm/pn-marketweb-siteheader-login-links_2.entry.js +15 -15
- package/esm/pn-marketweb-siteheader-store-9df5290d.js +8 -0
- package/esm/pn-marketweb-siteheader.entry.js +11 -6
- package/esm-es5/loader.js +1 -1
- package/esm-es5/pn-language-selector_9.entry.js +1 -1
- package/esm-es5/pn-market-web-components.js +1 -1
- package/esm-es5/pn-marketweb-siteheader-login-linklist.entry.js +1 -1
- package/esm-es5/pn-marketweb-siteheader-login-links_2.entry.js +1 -1
- package/esm-es5/pn-marketweb-siteheader-store-9df5290d.js +1 -0
- package/esm-es5/pn-marketweb-siteheader.entry.js +1 -1
- package/package.json +1 -1
- package/pn-market-web-components/p-19db5c15.entry.js +1 -0
- package/pn-market-web-components/p-36ebd0f4.entry.js +1 -0
- package/pn-market-web-components/p-5bdcc423.system.entry.js +1 -0
- package/pn-market-web-components/p-61a28efa.system.entry.js +1 -0
- package/pn-market-web-components/p-8301eb4e.entry.js +1 -0
- package/pn-market-web-components/p-ad308a5e.entry.js +1 -0
- package/pn-market-web-components/p-ad836c55.system.js +1 -0
- package/pn-market-web-components/p-be1e1c64.system.entry.js +1 -0
- package/pn-market-web-components/p-c0db1ffd.js +1 -0
- package/pn-market-web-components/p-d295ef71.system.js +1 -1
- package/pn-market-web-components/p-eb8e21c2.system.entry.js +1 -0
- package/pn-market-web-components/pn-market-web-components.esm.js +1 -1
- package/types/components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader-login-linklist.d.ts +0 -2
- package/types/components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader-login-links.d.ts +0 -2
- package/types/components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader-login-profileselection.d.ts +1 -2
- package/types/components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader-login.d.ts +2 -2
- package/types/components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader-store.d.ts +7 -0
- package/types/components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader.d.ts +3 -3
- package/types/components/widgets/pn-proxio-pricegroup/pn-proxio-pricegroup.d.ts +1 -1
- package/types/components.d.ts +16 -7
- package/types/globals/MarketWebLoginManager.d.ts +8 -0
- package/umd/pn-marketweb-init.js +1 -1
- package/umd/pn-marketweb-salesforce.js +2 -2
- package/cjs/MarketWebLoginManager-2e2c83c4.js +0 -281
- package/esm/MarketWebLoginManager-9499bd89.js +0 -279
- package/esm-es5/MarketWebLoginManager-9499bd89.js +0 -1
- package/pn-market-web-components/p-09d66012.system.entry.js +0 -1
- package/pn-market-web-components/p-0e7900e0.system.entry.js +0 -1
- package/pn-market-web-components/p-22a60cb6.system.entry.js +0 -1
- package/pn-market-web-components/p-34fefe22.entry.js +0 -1
- package/pn-market-web-components/p-4293e33c.js +0 -1
- package/pn-market-web-components/p-7cb63135.entry.js +0 -1
- package/pn-market-web-components/p-8acb60c5.entry.js +0 -1
- package/pn-market-web-components/p-ced9727b.system.js +0 -1
- package/pn-market-web-components/p-d9dec5b8.entry.js +0 -1
- package/pn-market-web-components/p-f9725e57.system.entry.js +0 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { h, Host } from "@stencil/core";
|
|
2
2
|
import { MarketWebLoginManager } from "../../../globals/MarketWebLoginManager";
|
|
3
|
+
import { state as headerState } from "./pn-marketweb-siteheader-store";
|
|
3
4
|
export class PnMarketwebSiteheaderLogin {
|
|
4
5
|
constructor() {
|
|
5
6
|
var _a;
|
|
@@ -12,33 +13,34 @@ export class PnMarketwebSiteheaderLogin {
|
|
|
12
13
|
this.fullname = "";
|
|
13
14
|
this.loggedin = false;
|
|
14
15
|
this.showProfileSelection = false;
|
|
15
|
-
this.
|
|
16
|
+
this.checkUserLoggedInStateInterval = 0;
|
|
16
17
|
this.loginLinks = undefined;
|
|
17
18
|
this.toggleButtonText = (((_a = this.loginDialog) === null || _a === void 0 ? void 0 : _a.loginMenuLinkText) ? this.loginDialog.loginMenuLinkText : "");
|
|
18
19
|
this.username = this.fullname;
|
|
19
20
|
}
|
|
20
21
|
componentWillLoad() {
|
|
21
22
|
const userInfo = this.loggedin && this.fullname ? { given_name: this.fullname } : null;
|
|
22
|
-
|
|
23
|
+
headerState.loginManager = new MarketWebLoginManager({
|
|
23
24
|
endpoint: this.endpoint,
|
|
24
25
|
eventTarget: this.hostElement,
|
|
26
|
+
checkUserLoggedInStateInterval: this.checkUserLoggedInStateInterval,
|
|
25
27
|
userInfo
|
|
26
28
|
});
|
|
27
|
-
|
|
28
|
-
this.hostElement["loginmanager"] =
|
|
29
|
+
headerState.loginManager.setSiteUrl(this.siteUrl);
|
|
30
|
+
this.hostElement["loginmanager"] = headerState.loginManager;
|
|
29
31
|
if (this.token) {
|
|
30
|
-
|
|
32
|
+
headerState.loginManager.registerToken(this.token, 'backend');
|
|
31
33
|
}
|
|
32
34
|
else if (this.emitEvents) { // The primary login instance
|
|
33
|
-
|
|
35
|
+
headerState.loginManager.invalidateTokenOfType('backend');
|
|
34
36
|
}
|
|
35
|
-
this.hostElement.addEventListener(
|
|
37
|
+
this.hostElement.addEventListener(headerState.loginManager.events.loginstatechange, this.onLoginStateChange.bind(this));
|
|
36
38
|
this.init();
|
|
37
39
|
this.setUserName();
|
|
38
40
|
this.setToggleButtonText();
|
|
39
41
|
}
|
|
40
42
|
async init() {
|
|
41
|
-
|
|
43
|
+
headerState.loginManager.init(this.emitEvents);
|
|
42
44
|
this.setToggleButtonText();
|
|
43
45
|
this.adjustLoginLinks();
|
|
44
46
|
}
|
|
@@ -52,10 +54,10 @@ export class PnMarketwebSiteheaderLogin {
|
|
|
52
54
|
link.isLogoutLink = (link.pageLink.indexOf('location.href') !== -1 && link.pageLink.indexOf('logout') !== -1);
|
|
53
55
|
}
|
|
54
56
|
if (link.isLogoutLink) {
|
|
55
|
-
link.href =
|
|
57
|
+
link.href = headerState.loginManager.getLogoutUrl(link.href);
|
|
56
58
|
}
|
|
57
59
|
if (i === 0 && !link.href) {
|
|
58
|
-
link.href =
|
|
60
|
+
link.href = headerState.loginManager.getLoginUrl();
|
|
59
61
|
link.linkType = 'primary';
|
|
60
62
|
}
|
|
61
63
|
if (link.primaryLinkApperance && !link.linkType) {
|
|
@@ -69,7 +71,7 @@ export class PnMarketwebSiteheaderLogin {
|
|
|
69
71
|
}
|
|
70
72
|
this.loginDialog.legacyLoginLinks = [
|
|
71
73
|
{
|
|
72
|
-
href:
|
|
74
|
+
href: headerState.loginManager.getLoginUrl(this.loginDialog.loginUrl),
|
|
73
75
|
linkText: this.loginDialog.loginLinkText,
|
|
74
76
|
openInNewWindow: false,
|
|
75
77
|
isLogoutLink: false,
|
|
@@ -78,7 +80,7 @@ export class PnMarketwebSiteheaderLogin {
|
|
|
78
80
|
primaryLinkApperance: true
|
|
79
81
|
},
|
|
80
82
|
{
|
|
81
|
-
href:
|
|
83
|
+
href: headerState.loginManager.getLoginUrl(this.loginDialog.registerUrl),
|
|
82
84
|
linkText: this.loginDialog.createLoginLinkText,
|
|
83
85
|
openInNewWindow: false,
|
|
84
86
|
isLogoutLink: false,
|
|
@@ -88,7 +90,7 @@ export class PnMarketwebSiteheaderLogin {
|
|
|
88
90
|
];
|
|
89
91
|
}
|
|
90
92
|
setUserName() {
|
|
91
|
-
const userInfo =
|
|
93
|
+
const userInfo = headerState.loginManager.getUserInfo();
|
|
92
94
|
let name = "";
|
|
93
95
|
if (!this.loggedin || !userInfo) {
|
|
94
96
|
this.username = name;
|
|
@@ -118,7 +120,7 @@ export class PnMarketwebSiteheaderLogin {
|
|
|
118
120
|
onLoginStateChange(e) {
|
|
119
121
|
if (this.loggedin !== e.detail && this.emitEvents) {
|
|
120
122
|
this.loggedin = e.detail;
|
|
121
|
-
this.loginStateChange.emit({ loggedIn: this.loggedin, token:
|
|
123
|
+
this.loginStateChange.emit({ loggedIn: this.loggedin, token: headerState.loginManager.getToken() });
|
|
122
124
|
this.setUserName();
|
|
123
125
|
this.setToggleButtonText();
|
|
124
126
|
}
|
|
@@ -136,9 +138,9 @@ export class PnMarketwebSiteheaderLogin {
|
|
|
136
138
|
hostElementAttribute.loggedin = this.loggedin + '';
|
|
137
139
|
}
|
|
138
140
|
return (h(Host, Object.assign({}, hostElementAttribute), h("pn-nav-dropdown", { label: this.toggleButtonText, icon: "user", class: "siteheader-logindialog" }, this.loggedin && this.showProfileSelection ?
|
|
139
|
-
h("pn-marketweb-siteheader-login-profileselection", { loginDialog: this.loginDialog,
|
|
141
|
+
h("pn-marketweb-siteheader-login-profileselection", { loginDialog: this.loginDialog, loggedin: this.loggedin, i18n: this.i18n, idNamespace: this.emitEvents ? '1' : '2', endpoint: this.endpoint })
|
|
140
142
|
:
|
|
141
|
-
h("pn-marketweb-siteheader-login-links", { loginDialog: this.loginDialog,
|
|
143
|
+
h("pn-marketweb-siteheader-login-links", { loginDialog: this.loginDialog, loggedin: this.loggedin, idNamespace: this.emitEvents ? '1' : '2', username: this.username }))));
|
|
142
144
|
}
|
|
143
145
|
static get is() { return "pn-marketweb-siteheader-login"; }
|
|
144
146
|
static get originalStyleUrls() {
|
|
@@ -320,12 +322,29 @@ export class PnMarketwebSiteheaderLogin {
|
|
|
320
322
|
"attribute": "show-profile-selection",
|
|
321
323
|
"reflect": false,
|
|
322
324
|
"defaultValue": "false"
|
|
325
|
+
},
|
|
326
|
+
"checkUserLoggedInStateInterval": {
|
|
327
|
+
"type": "number",
|
|
328
|
+
"mutable": false,
|
|
329
|
+
"complexType": {
|
|
330
|
+
"original": "number",
|
|
331
|
+
"resolved": "number",
|
|
332
|
+
"references": {}
|
|
333
|
+
},
|
|
334
|
+
"required": false,
|
|
335
|
+
"optional": false,
|
|
336
|
+
"docs": {
|
|
337
|
+
"tags": [],
|
|
338
|
+
"text": "Continiously check if a user is logged in *"
|
|
339
|
+
},
|
|
340
|
+
"attribute": "check-user-logged-in-state-interval",
|
|
341
|
+
"reflect": false,
|
|
342
|
+
"defaultValue": "0"
|
|
323
343
|
}
|
|
324
344
|
};
|
|
325
345
|
}
|
|
326
346
|
static get states() {
|
|
327
347
|
return {
|
|
328
|
-
"loginManager": {},
|
|
329
348
|
"loginLinks": {},
|
|
330
349
|
"toggleButtonText": {},
|
|
331
350
|
"username": {}
|
|
@@ -38,7 +38,7 @@ export class PnMarketwebSiteheaderSearch {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
const req = await fetch(autocompleteUrl, { signal: state.requestAbortController.signal }).catch((e) => {
|
|
41
|
-
console.
|
|
41
|
+
console.warn('Unable to fetch autocomplete suggestions', e);
|
|
42
42
|
});
|
|
43
43
|
if (!req) {
|
|
44
44
|
return;
|
package/collection/components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { h, Host, } from '@stencil/core';
|
|
2
2
|
import { FetchHelper } from '../../../globals/FetchHelper';
|
|
3
3
|
import { MarketWebContextService } from '../../../globals/MarketWebContextService';
|
|
4
|
-
import {
|
|
4
|
+
import { state as headerState } from "./pn-marketweb-siteheader-store";
|
|
5
5
|
import { translations } from './translations';
|
|
6
6
|
export class PnMarketwebSiteheader {
|
|
7
7
|
constructor() {
|
|
@@ -28,6 +28,7 @@ export class PnMarketwebSiteheader {
|
|
|
28
28
|
this.cache = false;
|
|
29
29
|
this.searchPlaceholder = '';
|
|
30
30
|
this.spaMode = false;
|
|
31
|
+
this.checkUserLoggedInStateInterval = 0;
|
|
31
32
|
this.i18n = {
|
|
32
33
|
searchlabel: '',
|
|
33
34
|
searchplaceholder: '',
|
|
@@ -50,10 +51,8 @@ export class PnMarketwebSiteheader {
|
|
|
50
51
|
this.loginDialog = null;
|
|
51
52
|
this.minimizeSearch = false;
|
|
52
53
|
this.loggedIn = false;
|
|
53
|
-
this.loginManager = null;
|
|
54
54
|
}
|
|
55
55
|
componentWillLoad() {
|
|
56
|
-
this.loginManager = new MarketWebLoginManager({ eventTarget: this.hostElement });
|
|
57
56
|
this.setInitialValues().then(() => {
|
|
58
57
|
this.init();
|
|
59
58
|
});
|
|
@@ -139,7 +138,9 @@ export class PnMarketwebSiteheader {
|
|
|
139
138
|
}
|
|
140
139
|
// Set site definition
|
|
141
140
|
this.siteDefinition = data.sitedefinition;
|
|
142
|
-
|
|
141
|
+
if (headerState.loginManager) {
|
|
142
|
+
headerState.loginManager.setSiteUrl(this.siteDefinition.url);
|
|
143
|
+
}
|
|
143
144
|
let updatedMenuItems = [];
|
|
144
145
|
// Set navigation information
|
|
145
146
|
if (this.siteDomainInUrls) {
|
|
@@ -293,13 +294,16 @@ export class PnMarketwebSiteheader {
|
|
|
293
294
|
if (matchedHref.length === 0) {
|
|
294
295
|
return href;
|
|
295
296
|
}
|
|
296
|
-
|
|
297
|
+
if (headerState.loginManager) {
|
|
298
|
+
return headerState.loginManager.getLoginUrl(href);
|
|
299
|
+
}
|
|
300
|
+
return href;
|
|
297
301
|
}
|
|
298
302
|
render() {
|
|
299
303
|
var _a, _b, _c, _d, _e, _f;
|
|
300
304
|
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 && (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) && (h("pn-site-selector-item", { heading: this.siteSelector.currentSiteTitle + ' ', description: this.siteSelector.currentSiteDescription })), this.gotData &&
|
|
301
305
|
((_d = this.siteSelector) === null || _d === void 0 ? void 0 : _d.siteSelections) &&
|
|
302
|
-
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("slot", { name: "logo" }, 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.userToken, siteUrl: this.siteDefinition.url, fullname: this.userFullname, loggedin: this.userLoggedin, loginDialog: this.loginDialog, endpoint: this.endpoint, i18n: this.i18n, showProfileSelection: this.showProfileSelection })), this.gotData && this.languageOptions && this.languageOptions.length && !this.hideLanguageSelector && (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-menu-top-search" }, h("pn-marketweb-siteheader-search", { language: this.language, siteid: this.siteid, search: this.search, "hide-search": this.hideSearch, i18n: this.i18n, icononly: false })))), h("slot", { name: "siteheader-menu-top-button" }), 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 => {
|
|
306
|
+
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("slot", { name: "logo" }, 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.userToken, siteUrl: this.siteDefinition.url, fullname: this.userFullname, loggedin: this.userLoggedin, loginDialog: this.loginDialog, endpoint: this.endpoint, i18n: this.i18n, showProfileSelection: this.showProfileSelection, "check-user-logged-in-state-interval": this.checkUserLoggedInStateInterval })), this.gotData && this.languageOptions && this.languageOptions.length && !this.hideLanguageSelector && (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-menu-top-search" }, h("pn-marketweb-siteheader-search", { language: this.language, siteid: this.siteid, search: this.search, "hide-search": this.hideSearch, i18n: this.i18n, icononly: false })))), h("slot", { name: "siteheader-menu-top-button" }), 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 => {
|
|
303
307
|
document.body.setAttribute('data-siteheader-menuopen', e.detail + '');
|
|
304
308
|
} }, h("pn-mainnav-level", null, h("pn-mainnav-list", null, this.menuItems.map(item => {
|
|
305
309
|
var _a, _b;
|
|
@@ -683,6 +687,24 @@ export class PnMarketwebSiteheader {
|
|
|
683
687
|
"attribute": "spa-mode",
|
|
684
688
|
"reflect": false,
|
|
685
689
|
"defaultValue": "false"
|
|
690
|
+
},
|
|
691
|
+
"checkUserLoggedInStateInterval": {
|
|
692
|
+
"type": "number",
|
|
693
|
+
"mutable": false,
|
|
694
|
+
"complexType": {
|
|
695
|
+
"original": "number",
|
|
696
|
+
"resolved": "number",
|
|
697
|
+
"references": {}
|
|
698
|
+
},
|
|
699
|
+
"required": false,
|
|
700
|
+
"optional": false,
|
|
701
|
+
"docs": {
|
|
702
|
+
"tags": [],
|
|
703
|
+
"text": "Continiously check if a user is logged in *"
|
|
704
|
+
},
|
|
705
|
+
"attribute": "check-user-logged-in-state-interval",
|
|
706
|
+
"reflect": false,
|
|
707
|
+
"defaultValue": "0"
|
|
686
708
|
}
|
|
687
709
|
};
|
|
688
710
|
}
|
|
@@ -700,8 +722,7 @@ export class PnMarketwebSiteheader {
|
|
|
700
722
|
"languageOptions": {},
|
|
701
723
|
"loginDialog": {},
|
|
702
724
|
"minimizeSearch": {},
|
|
703
|
-
"loggedIn": {}
|
|
704
|
-
"loginManager": {}
|
|
725
|
+
"loggedIn": {}
|
|
705
726
|
};
|
|
706
727
|
}
|
|
707
728
|
static get events() {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import readme from './readme.md';
|
|
2
2
|
|
|
3
|
-
const usertoken = '
|
|
3
|
+
const usertoken = '6ae6bde345eb68fc0102f4ba256f31e9151db31dc2ea4c23a51917c';
|
|
4
4
|
|
|
5
5
|
export default {
|
|
6
6
|
title: 'Web Components/Market web site Header',
|
|
@@ -380,6 +380,7 @@ const LoggedInTemplate = ({ ...args }) => {
|
|
|
380
380
|
language="${args.language}"
|
|
381
381
|
endpoint="${args.endpoint}"
|
|
382
382
|
user-token="${args.token}"
|
|
383
|
+
check-user-logged-in-state-interval="${args.checkUserLoggedInStateInterval+''}"
|
|
383
384
|
>
|
|
384
385
|
</pn-marketweb-siteheader>
|
|
385
386
|
</div>
|
|
@@ -395,6 +396,16 @@ LoggedIn.args = {
|
|
|
395
396
|
token: usertoken,
|
|
396
397
|
};
|
|
397
398
|
|
|
399
|
+
export const LoggedInWithStatusCheck = LoggedInTemplate.bind({});
|
|
400
|
+
LoggedInWithStatusCheck.args = {
|
|
401
|
+
market: 'se',
|
|
402
|
+
language: 'sv',
|
|
403
|
+
endpoint: 'https://com-integration.postnord.com',
|
|
404
|
+
checkUserLoggedInStateInterval: 10000,
|
|
405
|
+
//endpoint: 'http://localhost:51444',
|
|
406
|
+
token: usertoken,
|
|
407
|
+
};
|
|
408
|
+
|
|
398
409
|
const LoggedInProfileSelectionTemplate = ({ ...args }) => {
|
|
399
410
|
return `
|
|
400
411
|
<div style="background:#ddd;min-height:100vh;">
|
|
@@ -403,6 +414,7 @@ const LoggedInProfileSelectionTemplate = ({ ...args }) => {
|
|
|
403
414
|
language="${args.language}"
|
|
404
415
|
endpoint="${args.endpoint}"
|
|
405
416
|
user-token="${args.token}"
|
|
417
|
+
check-user-logged-in-state-interval="10000"
|
|
406
418
|
show-profile-selection="true"
|
|
407
419
|
>
|
|
408
420
|
</pn-marketweb-siteheader>
|
|
@@ -4,6 +4,7 @@ class MarketWebLoginManager {
|
|
|
4
4
|
this.eventTarget = (window !== null && window !== void 0 ? window : document === null || document === void 0 ? void 0 : document.body);
|
|
5
5
|
this.endpoint = "";
|
|
6
6
|
this.storagePrefix = "pn-user";
|
|
7
|
+
this.checkUserLoggedInStateInterval = 0;
|
|
7
8
|
this.baseUrls = {
|
|
8
9
|
at: 'https://atportal.postnord.com/api/unified-login/backend',
|
|
9
10
|
prod: 'https://portal.postnord.com/api/unified-login/backend',
|
|
@@ -27,6 +28,9 @@ class MarketWebLoginManager {
|
|
|
27
28
|
};
|
|
28
29
|
this.overridetokenValue = 'overridetokenValue';
|
|
29
30
|
this.siteUrl = window.location.origin;
|
|
31
|
+
this.abortSignalForLoginCheck = null;
|
|
32
|
+
this.loginCheckInProgress = false;
|
|
33
|
+
this.loginCheckTimer = null;
|
|
30
34
|
this.store = {
|
|
31
35
|
get: (key) => {
|
|
32
36
|
const value = window.sessionStorage.getItem(`${this.storagePrefix}-${key}`);
|
|
@@ -62,6 +66,7 @@ class MarketWebLoginManager {
|
|
|
62
66
|
this.eventTarget = (options.eventTarget) ? options.eventTarget : this.eventTarget;
|
|
63
67
|
this.endpoint = options.endpoint ? options.endpoint : `${window.location.protocol}//${window.location.host}`;
|
|
64
68
|
(_a = this.storagePrefix) !== null && _a !== void 0 ? _a : (this.storagePrefix = options.storagePrefix);
|
|
69
|
+
this.checkUserLoggedInStateInterval = (options.checkUserLoggedInStateInterval && options.checkUserLoggedInStateInterval > 0) ? parseInt((options.checkUserLoggedInStateInterval + ''), 10) : 0;
|
|
65
70
|
if (options.userInfo) {
|
|
66
71
|
this.store.set(this.keys.user, options.userInfo);
|
|
67
72
|
this.registerToken(this.overridetokenValue, 'override');
|
|
@@ -76,6 +81,9 @@ class MarketWebLoginManager {
|
|
|
76
81
|
this.fetchUserInfo();
|
|
77
82
|
}
|
|
78
83
|
this.loginStateChange();
|
|
84
|
+
if (this.checkUserLoggedInStateInterval > 0) {
|
|
85
|
+
this.initiateLoggedInCheck();
|
|
86
|
+
}
|
|
79
87
|
}
|
|
80
88
|
}
|
|
81
89
|
setSiteUrl(siteUrl) {
|
|
@@ -83,6 +91,75 @@ class MarketWebLoginManager {
|
|
|
83
91
|
this.siteUrl = siteUrl;
|
|
84
92
|
}
|
|
85
93
|
}
|
|
94
|
+
initiateLoggedInCheck() {
|
|
95
|
+
if (this.isLoggedIn()) {
|
|
96
|
+
if (window && window['AbortController']) {
|
|
97
|
+
this.abortSignalForLoginCheck = new AbortController();
|
|
98
|
+
}
|
|
99
|
+
this.loginCheckTimer = window.setInterval(() => {
|
|
100
|
+
this.doExternalLoggedInCheck().then(() => { }).catch(() => { });
|
|
101
|
+
}, this.checkUserLoggedInStateInterval);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
async doExternalLoggedInCheck() {
|
|
105
|
+
if (!window.navigator.onLine) {
|
|
106
|
+
// Don't check if the user is not online
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (!this.getToken()) {
|
|
110
|
+
window.clearInterval(this.checkUserLoggedInStateInterval);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (this.loginCheckInProgress && this.abortSignalForLoginCheck) {
|
|
114
|
+
this.abortSignalForLoginCheck.abort();
|
|
115
|
+
this.abortSignalForLoginCheck = new AbortController();
|
|
116
|
+
}
|
|
117
|
+
this.loginCheckInProgress = true;
|
|
118
|
+
const reqConfig = {
|
|
119
|
+
method: 'GET',
|
|
120
|
+
headers: {
|
|
121
|
+
'Accept': 'application/json',
|
|
122
|
+
'Content-Type': 'application/json',
|
|
123
|
+
'Authorization': this.getToken()
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
if (this.abortSignalForLoginCheck && this.abortSignalForLoginCheck["signal"]) {
|
|
127
|
+
reqConfig["signal"] = this.abortSignalForLoginCheck["signal"];
|
|
128
|
+
}
|
|
129
|
+
const response = await fetch(`${this.getBaseUrl()}${this.endpoints.userInfoEndpoint}`, reqConfig);
|
|
130
|
+
if (response.status === 409) { // This is a status the API returns if a user has been logged out
|
|
131
|
+
window.clearInterval(this.checkUserLoggedInStateInterval);
|
|
132
|
+
console.log('Cleared out user data due to bad response from authentication endpoint');
|
|
133
|
+
this.LogoutUser();
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
if (!response.ok) {
|
|
137
|
+
// The response was "bad". This could be due to bad connectivity or something else.
|
|
138
|
+
// We'll ignore it so we don't unecessarily log users out or have them loose state if they're switching connection
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
const data = await response.json();
|
|
142
|
+
if (!data || !data['accessToken']) {
|
|
143
|
+
window.clearInterval(this.checkUserLoggedInStateInterval);
|
|
144
|
+
console.log('Cleared out user data due to bad response from authentication endpoint');
|
|
145
|
+
this.LogoutUser();
|
|
146
|
+
}
|
|
147
|
+
this.loginCheckInProgress = false;
|
|
148
|
+
}
|
|
149
|
+
LogoutUser() {
|
|
150
|
+
this.clearUserData();
|
|
151
|
+
// Log out user
|
|
152
|
+
if (this.eventTarget) {
|
|
153
|
+
const logoutLink = this.eventTarget.querySelector('#pn-marketweb-header-logoutlink');
|
|
154
|
+
if (logoutLink) {
|
|
155
|
+
logoutLink.click();
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
// If no logout link was found, attempt to change URL to redirect link
|
|
160
|
+
const currentPageHref = window.location.href;
|
|
161
|
+
window.location.href = this.getLogoutUrl(currentPageHref);
|
|
162
|
+
}
|
|
86
163
|
isLoggedIn(override = false) {
|
|
87
164
|
if (override) {
|
|
88
165
|
return override;
|