@postnord/pn-marketweb-components 1.0.35 → 1.0.39
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/FetchHelper-f80943bf.js +87 -0
- package/cjs/{MarketWebLoginManager-8b675eb4.js → MarketWebLoginManager-859590e2.js} +8 -0
- package/cjs/loader.cjs.js +1 -1
- package/cjs/pn-language-selector_9.cjs.entry.js +6 -1
- package/cjs/pn-mainnav-link.cjs.entry.js +1 -1
- package/cjs/pn-market-web-components.cjs.js +1 -1
- package/cjs/pn-marketweb-sitefooter.cjs.entry.js +15 -2
- package/cjs/pn-marketweb-siteheader.cjs.entry.js +50 -22
- package/cjs/pn-profile-selector.cjs.entry.js +21 -13
- package/collection/components/layout-components/pn-marketweb-sitefooter/pn-marketweb-sitefooter.js +33 -2
- package/collection/components/layout-components/pn-marketweb-sitefooter/pn-marketweb-sitefooter.stories.js +3 -3
- package/collection/components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader-login.js +23 -0
- package/collection/components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader.js +95 -23
- package/collection/components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader.stories.js +60 -2
- package/collection/components/navigation/pn-mainnav/pn-mainnav-link.js +1 -1
- package/collection/components/navigation/pn-profile-selector/pn-profile-selector.js +26 -18
- package/collection/globals/FetchHelper.js +84 -0
- package/collection/globals/MarketWebLoginManager.js +8 -0
- package/custom-elements/index.js +375 -232
- package/esm/FetchHelper-a0c8aa54.js +85 -0
- package/esm/{MarketWebLoginManager-dd7ac023.js → MarketWebLoginManager-83f2e86a.js} +8 -0
- package/esm/loader.js +1 -1
- package/esm/pn-language-selector_9.entry.js +6 -1
- package/esm/pn-mainnav-link.entry.js +1 -1
- package/esm/pn-market-web-components.js +1 -1
- package/esm/pn-marketweb-sitefooter.entry.js +15 -2
- package/esm/pn-marketweb-siteheader.entry.js +50 -22
- package/esm/pn-profile-selector.entry.js +21 -13
- package/esm-es5/FetchHelper-a0c8aa54.js +1 -0
- package/esm-es5/MarketWebLoginManager-83f2e86a.js +1 -0
- package/esm-es5/loader.js +1 -1
- package/esm-es5/pn-language-selector_9.entry.js +1 -1
- package/esm-es5/pn-mainnav-link.entry.js +1 -1
- package/esm-es5/pn-market-web-components.js +1 -1
- package/esm-es5/pn-marketweb-sitefooter.entry.js +1 -1
- package/esm-es5/pn-marketweb-siteheader.entry.js +1 -1
- package/esm-es5/pn-profile-selector.entry.js +1 -1
- package/package.json +27 -27
- package/pn-market-web-components/p-02ab0208.entry.js +1 -0
- package/pn-market-web-components/{p-ffdf87ee.entry.js → p-03fb0285.entry.js} +1 -1
- package/pn-market-web-components/p-1649b94a.entry.js +1 -0
- package/pn-market-web-components/p-25bdf3f8.system.js +1 -1
- package/pn-market-web-components/p-4921fcc3.entry.js +1 -0
- package/pn-market-web-components/p-58cdf3a6.system.js +1 -0
- package/pn-market-web-components/{p-6a32362d.system.entry.js → p-7b4c721f.system.entry.js} +1 -1
- package/pn-market-web-components/p-97dc5687.js +1 -0
- package/pn-market-web-components/p-a983c263.system.entry.js +1 -0
- package/pn-market-web-components/p-c254cfdf.js +1 -0
- package/pn-market-web-components/p-d6a17042.system.js +1 -0
- package/pn-market-web-components/p-daa6ddb3.system.entry.js +1 -0
- package/pn-market-web-components/p-dade9bdb.system.entry.js +1 -0
- package/pn-market-web-components/p-dc471243.entry.js +1 -0
- package/pn-market-web-components/{p-251d44f2.system.entry.js → p-e3fb52a6.system.entry.js} +1 -1
- package/pn-market-web-components/pn-market-web-components.esm.js +1 -1
- package/types/components/layout-components/pn-marketweb-sitefooter/pn-marketweb-sitefooter.d.ts +5 -0
- package/types/components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader-login.d.ts +2 -0
- package/types/components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader.d.ts +11 -0
- package/types/components/navigation/pn-profile-selector/pn-profile-selector.d.ts +2 -1
- package/types/components.d.ts +34 -2
- package/types/globals/FetchHelper.d.ts +17 -0
- package/types/globals/MarketWebLoginManager.d.ts +1 -0
- package/esm-es5/MarketWebLoginManager-dd7ac023.js +0 -1
- package/pn-market-web-components/p-031d91aa.entry.js +0 -1
- package/pn-market-web-components/p-134f14eb.system.entry.js +0 -1
- package/pn-market-web-components/p-2f494f64.system.entry.js +0 -1
- package/pn-market-web-components/p-3562a62f.entry.js +0 -1
- package/pn-market-web-components/p-37efd029.entry.js +0 -1
- package/pn-market-web-components/p-4dcea578.js +0 -1
- package/pn-market-web-components/p-51768dc0.system.js +0 -1
- package/pn-market-web-components/p-db7419be.system.entry.js +0 -1
- package/pn-market-web-components/p-e220ea83.entry.js +0 -1
|
@@ -4,6 +4,8 @@ export class PnMarketwebSiteheaderLogin {
|
|
|
4
4
|
constructor() {
|
|
5
5
|
/** Specifies which endpoint domain we should load from */
|
|
6
6
|
this.endpoint = "";
|
|
7
|
+
/** Access token passed from backend */
|
|
8
|
+
this.token = "";
|
|
7
9
|
this.emitEvents = true;
|
|
8
10
|
// Login dialog
|
|
9
11
|
this.loginDialog = null;
|
|
@@ -15,6 +17,9 @@ export class PnMarketwebSiteheaderLogin {
|
|
|
15
17
|
componentWillLoad() {
|
|
16
18
|
this.loginManager = new MarketWebLoginManager({ endpoint: this.endpoint, eventTarget: this.hostElement });
|
|
17
19
|
this.hostElement["loginmanager"] = this.loginManager;
|
|
20
|
+
if (this.token) {
|
|
21
|
+
this.loginManager.registerToken(this.token);
|
|
22
|
+
}
|
|
18
23
|
this.hostElement.addEventListener(this.loginManager.events.loginstatechange, this.onLoginStateChange.bind(this));
|
|
19
24
|
this.init();
|
|
20
25
|
}
|
|
@@ -160,6 +165,24 @@ export class PnMarketwebSiteheaderLogin {
|
|
|
160
165
|
"reflect": false,
|
|
161
166
|
"defaultValue": "\"\""
|
|
162
167
|
},
|
|
168
|
+
"token": {
|
|
169
|
+
"type": "string",
|
|
170
|
+
"mutable": false,
|
|
171
|
+
"complexType": {
|
|
172
|
+
"original": "string",
|
|
173
|
+
"resolved": "string",
|
|
174
|
+
"references": {}
|
|
175
|
+
},
|
|
176
|
+
"required": false,
|
|
177
|
+
"optional": false,
|
|
178
|
+
"docs": {
|
|
179
|
+
"tags": [],
|
|
180
|
+
"text": "Access token passed from backend"
|
|
181
|
+
},
|
|
182
|
+
"attribute": "token",
|
|
183
|
+
"reflect": false,
|
|
184
|
+
"defaultValue": "\"\""
|
|
185
|
+
},
|
|
163
186
|
"i18n": {
|
|
164
187
|
"type": "any",
|
|
165
188
|
"mutable": false,
|
package/collection/components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Component, Prop, h, State, Element, Listen, Watch, Host, Event } from "@stencil/core";
|
|
2
2
|
import { translations } from "./translations";
|
|
3
3
|
import { MarketWebContextService } from "../../../globals/MarketWebContextService";
|
|
4
|
+
import { MarketWebLoginManager } from "../../../globals/MarketWebLoginManager";
|
|
5
|
+
import { FetchHelper } from "../../../globals/FetchHelper";
|
|
4
6
|
export class PnMarketwebSiteheader {
|
|
5
7
|
constructor() {
|
|
6
8
|
this.endpointPath = "/api/navigation/header";
|
|
@@ -12,6 +14,8 @@ export class PnMarketwebSiteheader {
|
|
|
12
14
|
this.language = null; //sv
|
|
13
15
|
/** Specifies which environment we're fetching data from. (production, preproduction, integration, localhost) */
|
|
14
16
|
this.environment = null; //sv
|
|
17
|
+
/** Access token passed from backend */
|
|
18
|
+
this.token = "";
|
|
15
19
|
/** Specifies which endpoint domain we should load from */
|
|
16
20
|
this.endpoint = null;
|
|
17
21
|
/** Hides the site selector if set to true*/
|
|
@@ -24,6 +28,8 @@ export class PnMarketwebSiteheader {
|
|
|
24
28
|
this.hideLogin = false;
|
|
25
29
|
/** Forward session to backend */
|
|
26
30
|
this.sessionForward = false;
|
|
31
|
+
/** If the component should use cached requests */
|
|
32
|
+
this.cache = false;
|
|
27
33
|
/** Event based only language switch */
|
|
28
34
|
this.spaMode = false;
|
|
29
35
|
this.gotData = false;
|
|
@@ -41,8 +47,14 @@ export class PnMarketwebSiteheader {
|
|
|
41
47
|
// Login dialog
|
|
42
48
|
this.loginDialog = null;
|
|
43
49
|
this.minimizeSearch = false;
|
|
50
|
+
this.loggedIn = false;
|
|
51
|
+
// FetchHelper
|
|
52
|
+
this.fetchHelper = new FetchHelper("siteheader");
|
|
53
|
+
// Login manager
|
|
54
|
+
this.loginManager = null;
|
|
44
55
|
}
|
|
45
56
|
componentWillLoad() {
|
|
57
|
+
this.loginManager = new MarketWebLoginManager({ eventTarget: this.hostElement });
|
|
46
58
|
this.setInitialValues().then(() => {
|
|
47
59
|
this.init();
|
|
48
60
|
});
|
|
@@ -79,7 +91,9 @@ export class PnMarketwebSiteheader {
|
|
|
79
91
|
}
|
|
80
92
|
}
|
|
81
93
|
onLanguageSelectorChange(e) {
|
|
94
|
+
console.log('onLanguageSelectorChange(e', e);
|
|
82
95
|
this.language = e.detail;
|
|
96
|
+
window.dispatchEvent(new CustomEvent('marketweb-languagechange', { detail: this.language }));
|
|
83
97
|
}
|
|
84
98
|
onLanguageChange() {
|
|
85
99
|
this.setTranslations();
|
|
@@ -98,12 +112,14 @@ export class PnMarketwebSiteheader {
|
|
|
98
112
|
this.fetchingData = true;
|
|
99
113
|
const endpointBase = (this.endpoint.lastIndexOf("/") === this.endpoint.length - 1) ? this.endpoint.substring(0, this.endpoint.length - 1) : this.endpoint;
|
|
100
114
|
const fetchUrl = `${endpointBase}${this.endpointPath}?market=${this.market}&language=${this.language}`;
|
|
101
|
-
const
|
|
115
|
+
const data = await this.fetchHelper.fetchJson(fetchUrl, {
|
|
102
116
|
'mode': 'cors'
|
|
103
|
-
});
|
|
104
|
-
const data = await response.json();
|
|
117
|
+
}, this.cache, this.onFetchRefreshed.bind(this));
|
|
105
118
|
await this.setStateFromData(data);
|
|
106
119
|
}
|
|
120
|
+
onFetchRefreshed(data) {
|
|
121
|
+
this.setStateFromData(data);
|
|
122
|
+
}
|
|
107
123
|
getLanguageVersionUrl(item) {
|
|
108
124
|
if (this.spaMode) {
|
|
109
125
|
return null;
|
|
@@ -117,7 +133,7 @@ export class PnMarketwebSiteheader {
|
|
|
117
133
|
return siteUrl + ((siteUrl.lastIndexOf("/") !== siteUrl.length - 1) ? "/" : "") + item.twoLetterISOLanguageName;
|
|
118
134
|
}
|
|
119
135
|
async setStateFromData(data) {
|
|
120
|
-
var _a, _b;
|
|
136
|
+
var _a, _b, _c;
|
|
121
137
|
if (typeof data !== "object") {
|
|
122
138
|
console.warn('Data was not valid', data);
|
|
123
139
|
}
|
|
@@ -126,14 +142,16 @@ export class PnMarketwebSiteheader {
|
|
|
126
142
|
// Set navigation information
|
|
127
143
|
this.menuItems = data.mainMenu.menuItems;
|
|
128
144
|
// Create the "Home" link
|
|
129
|
-
this.menuItems.
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
145
|
+
if (!this.menuItems[0] || ((_a = this.menuItems[0]) === null || _a === void 0 ? void 0 : _a.name) !== this.i18n.menuHomeButton) {
|
|
146
|
+
this.menuItems.unshift({
|
|
147
|
+
href: this.siteDefinition.url,
|
|
148
|
+
name: this.i18n.menuHomeButton,
|
|
149
|
+
id: 'homelink',
|
|
150
|
+
open: false,
|
|
151
|
+
selected: false,
|
|
152
|
+
children: []
|
|
153
|
+
});
|
|
154
|
+
}
|
|
137
155
|
// Set search
|
|
138
156
|
this.search = data.search;
|
|
139
157
|
// Set site selector
|
|
@@ -145,7 +163,7 @@ export class PnMarketwebSiteheader {
|
|
|
145
163
|
await this.spaModeAdjustments();
|
|
146
164
|
this.gotData = true;
|
|
147
165
|
this.fetchingData = true;
|
|
148
|
-
this.homePageLink = (
|
|
166
|
+
this.homePageLink = (_c = (_b = this.siteDefinition) === null || _b === void 0 ? void 0 : _b.url) !== null && _c !== void 0 ? _c : document.location.hostname;
|
|
149
167
|
window.setTimeout(() => { this.checkMenuOverflow(); }, 100);
|
|
150
168
|
}
|
|
151
169
|
setLanguageOptions() {
|
|
@@ -155,17 +173,19 @@ export class PnMarketwebSiteheader {
|
|
|
155
173
|
}
|
|
156
174
|
const hrefLangsTags = (_a = Array.prototype.slice.call(document.querySelectorAll('link[rel="alternate"][hreflang]'))) !== null && _a !== void 0 ? _a : [];
|
|
157
175
|
const hrefLangs = hrefLangsTags.map((tag) => { return tag.getAttribute("hreflang"); });
|
|
176
|
+
let languageOptions = []; // Reset language options
|
|
158
177
|
this.languageSelector.languages.map((languageOption) => {
|
|
159
178
|
// In case there are language links present on the page we only show languages that have those tags
|
|
160
179
|
if (hrefLangs && hrefLangs.length > 0) {
|
|
161
180
|
if (hrefLangs.includes(languageOption.twoLetterISOLanguageName)) {
|
|
162
|
-
|
|
181
|
+
languageOptions.push(languageOption);
|
|
163
182
|
}
|
|
164
183
|
}
|
|
165
184
|
else {
|
|
166
|
-
|
|
185
|
+
languageOptions.push(languageOption);
|
|
167
186
|
}
|
|
168
187
|
});
|
|
188
|
+
this.languageOptions = languageOptions; // Replace existing language options so we don't trigger a event change on every push.
|
|
169
189
|
}
|
|
170
190
|
async spaModeAdjustments() {
|
|
171
191
|
if (!this.spaMode) {
|
|
@@ -174,12 +194,15 @@ export class PnMarketwebSiteheader {
|
|
|
174
194
|
return;
|
|
175
195
|
}
|
|
176
196
|
onLoginStateChange(e) {
|
|
177
|
-
var _a, _b;
|
|
178
|
-
if (((_a = e.detail) === null || _a === void 0 ? void 0 : _a.loggedIn) && ((_b = e.detail) === null || _b === void 0 ? void 0 : _b.token)
|
|
179
|
-
|
|
180
|
-
|
|
197
|
+
var _a, _b, _c;
|
|
198
|
+
if (((_a = e.detail) === null || _a === void 0 ? void 0 : _a.loggedIn) && ((_b = e.detail) === null || _b === void 0 ? void 0 : _b.token)) {
|
|
199
|
+
this.loggedIn = ((_c = e.detail) === null || _c === void 0 ? void 0 : _c.loggedIn) === true;
|
|
200
|
+
if (this.sessionForward) {
|
|
201
|
+
try {
|
|
202
|
+
//fetch('/api/userprofile/sync?token=' + e.detail.token);
|
|
203
|
+
}
|
|
204
|
+
catch (e) { }
|
|
181
205
|
}
|
|
182
|
-
catch (e) { }
|
|
183
206
|
}
|
|
184
207
|
}
|
|
185
208
|
promotedItemId(item) {
|
|
@@ -210,6 +233,17 @@ export class PnMarketwebSiteheader {
|
|
|
210
233
|
this.minimizeSearch = true;
|
|
211
234
|
}
|
|
212
235
|
}
|
|
236
|
+
adjustSiteSelectorUrl(href) {
|
|
237
|
+
if (!this.loggedIn) {
|
|
238
|
+
return href;
|
|
239
|
+
}
|
|
240
|
+
const loginDomains = ['portal.postnord.com'];
|
|
241
|
+
const matchedHref = loginDomains.filter((domain) => { return href.indexOf(domain) !== -1; });
|
|
242
|
+
if (matchedHref.length === 0) {
|
|
243
|
+
return href;
|
|
244
|
+
}
|
|
245
|
+
return this.loginManager.getLoginUrl(href);
|
|
246
|
+
}
|
|
213
247
|
render() {
|
|
214
248
|
var _a, _b, _c, _d, _e, _f;
|
|
215
249
|
return (h(Host, { language: this.language, market: this.market, environment: this.environment },
|
|
@@ -221,14 +255,14 @@ export class PnMarketwebSiteheader {
|
|
|
221
255
|
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' },
|
|
222
256
|
(this.gotData && ((_c = this.siteSelector) === null || _c === void 0 ? void 0 : _c.currentSiteTitle)) &&
|
|
223
257
|
h("pn-site-selector-item", { heading: this.siteSelector.currentSiteTitle + ' ', description: this.siteSelector.currentSiteDescription }),
|
|
224
|
-
(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: site.href, newwindow: site.openInNewWindow })))),
|
|
258
|
+
(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 })))),
|
|
225
259
|
h("div", { class: "siteheader-logocontainer" },
|
|
226
260
|
h("a", { href: this.homePageLink, title: "Home", class: "siteheader-logolink" },
|
|
227
261
|
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" },
|
|
228
262
|
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)" })))),
|
|
229
263
|
h("div", { class: "siteheader-topright" },
|
|
230
264
|
h("slot", { name: "toprightstart" }),
|
|
231
|
-
(this.gotData && this.loginDialog && !this.hideLogin) && (h("pn-marketweb-siteheader-login", { loginDialog: this.loginDialog, endpoint: this.endpoint, i18n: this.i18n })),
|
|
265
|
+
(this.gotData && this.loginDialog && !this.hideLogin) && (h("pn-marketweb-siteheader-login", { token: this.token, loginDialog: this.loginDialog, endpoint: this.endpoint, i18n: this.i18n })),
|
|
232
266
|
(this.gotData && this.languageOptions && this.languageOptions.length) && !this.hideLanguageSelector &&
|
|
233
267
|
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) }))),
|
|
234
268
|
h("slot", { name: "toprightend" }))),
|
|
@@ -325,6 +359,24 @@ export class PnMarketwebSiteheader {
|
|
|
325
359
|
"reflect": true,
|
|
326
360
|
"defaultValue": "null"
|
|
327
361
|
},
|
|
362
|
+
"token": {
|
|
363
|
+
"type": "string",
|
|
364
|
+
"mutable": false,
|
|
365
|
+
"complexType": {
|
|
366
|
+
"original": "string",
|
|
367
|
+
"resolved": "string",
|
|
368
|
+
"references": {}
|
|
369
|
+
},
|
|
370
|
+
"required": false,
|
|
371
|
+
"optional": false,
|
|
372
|
+
"docs": {
|
|
373
|
+
"tags": [],
|
|
374
|
+
"text": "Access token passed from backend"
|
|
375
|
+
},
|
|
376
|
+
"attribute": "token",
|
|
377
|
+
"reflect": false,
|
|
378
|
+
"defaultValue": "\"\""
|
|
379
|
+
},
|
|
328
380
|
"endpoint": {
|
|
329
381
|
"type": "string",
|
|
330
382
|
"mutable": false,
|
|
@@ -433,6 +485,24 @@ export class PnMarketwebSiteheader {
|
|
|
433
485
|
"reflect": false,
|
|
434
486
|
"defaultValue": "false"
|
|
435
487
|
},
|
|
488
|
+
"cache": {
|
|
489
|
+
"type": "boolean",
|
|
490
|
+
"mutable": false,
|
|
491
|
+
"complexType": {
|
|
492
|
+
"original": "boolean",
|
|
493
|
+
"resolved": "boolean",
|
|
494
|
+
"references": {}
|
|
495
|
+
},
|
|
496
|
+
"required": false,
|
|
497
|
+
"optional": false,
|
|
498
|
+
"docs": {
|
|
499
|
+
"tags": [],
|
|
500
|
+
"text": "If the component should use cached requests"
|
|
501
|
+
},
|
|
502
|
+
"attribute": "cache",
|
|
503
|
+
"reflect": false,
|
|
504
|
+
"defaultValue": "false"
|
|
505
|
+
},
|
|
436
506
|
"spaMode": {
|
|
437
507
|
"type": "boolean",
|
|
438
508
|
"mutable": false,
|
|
@@ -464,7 +534,9 @@ export class PnMarketwebSiteheader {
|
|
|
464
534
|
"languageSelector": {},
|
|
465
535
|
"languageOptions": {},
|
|
466
536
|
"loginDialog": {},
|
|
467
|
-
"minimizeSearch": {}
|
|
537
|
+
"minimizeSearch": {},
|
|
538
|
+
"loggedIn": {},
|
|
539
|
+
"loginManager": {}
|
|
468
540
|
}; }
|
|
469
541
|
static get events() { return [{
|
|
470
542
|
"method": "changeLanguage",
|
|
@@ -49,6 +49,7 @@ const PrimaryTemplate = ({ ...args }) => {
|
|
|
49
49
|
hide-language-selector="false"
|
|
50
50
|
hide-search="false"
|
|
51
51
|
hide-login="false"
|
|
52
|
+
cache="true"
|
|
52
53
|
session-forward="true">
|
|
53
54
|
<a href="" class="header-cart" slot="toprightend" style="align-self:center;position:relative;text-decoration:none;">
|
|
54
55
|
<span>Varukorg</span>
|
|
@@ -71,8 +72,8 @@ export const Primary = PrimaryTemplate.bind({});
|
|
|
71
72
|
Primary.args = {
|
|
72
73
|
market : "se",
|
|
73
74
|
language: 'sv',
|
|
74
|
-
endpoint: '
|
|
75
|
-
}
|
|
75
|
+
endpoint: 'https://com-production.postnord.com'
|
|
76
|
+
}
|
|
76
77
|
|
|
77
78
|
|
|
78
79
|
const MinimalOptionsTemplate = ({ ...args }) => {
|
|
@@ -96,13 +97,70 @@ const SPAModeOptionsTemplate = ({ ...args }) => {
|
|
|
96
97
|
<div style="background:#ddd;min-height:100vh;">
|
|
97
98
|
<pn-marketweb-siteheader language="sv" spa-mode="true">
|
|
98
99
|
</pn-marketweb-siteheader>
|
|
100
|
+
<script>
|
|
101
|
+
document.addEventListener('DOMContentLoaded', () => {
|
|
102
|
+
if (!window["haslangchange"]) {
|
|
103
|
+
console.log('SPA Mode - attached global market web header language change eventlistener')
|
|
104
|
+
|
|
105
|
+
window.addEventListener('marketweb-languagechange', (e) => {
|
|
106
|
+
console.log('marketweb-languagechange e', e)
|
|
107
|
+
});
|
|
108
|
+
window["haslangchange"] = true;
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
</script>
|
|
99
112
|
</div>
|
|
100
113
|
`;
|
|
101
114
|
};
|
|
102
115
|
|
|
116
|
+
|
|
117
|
+
|
|
103
118
|
export const SPAModeOptions = SPAModeOptionsTemplate.bind({});
|
|
104
119
|
SPAModeOptions.args = {
|
|
105
120
|
market : "",
|
|
106
121
|
language: '',
|
|
107
122
|
endpoint: ''
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const LocalhostTemplate = ({ ...args }) => {
|
|
126
|
+
return `
|
|
127
|
+
<div style="background:#ddd;min-height:100vh;">
|
|
128
|
+
<pn-marketweb-siteheader
|
|
129
|
+
market="${ args.market }"
|
|
130
|
+
language="${ args.language }"
|
|
131
|
+
endpoint="${ args.endpoint }"
|
|
132
|
+
environment="${ args.environment }"
|
|
133
|
+
>
|
|
134
|
+
</pn-marketweb-siteheader>
|
|
135
|
+
</div>
|
|
136
|
+
`;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
export const LocalhostOptions = LocalhostTemplate.bind({});
|
|
140
|
+
LocalhostOptions.args = {
|
|
141
|
+
market : "se",
|
|
142
|
+
language: 'sv',
|
|
143
|
+
endpoint: 'http://localhost:51444/',
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
const LoggedInTemplate = ({ ...args }) => {
|
|
147
|
+
return `
|
|
148
|
+
<div style="background:#ddd;min-height:100vh;">
|
|
149
|
+
<pn-marketweb-siteheader
|
|
150
|
+
market="${ args.market }"
|
|
151
|
+
language="${ args.language }"
|
|
152
|
+
endpoint="${ args.endpoint }"
|
|
153
|
+
token="${ args.token }"
|
|
154
|
+
>
|
|
155
|
+
</pn-marketweb-siteheader>
|
|
156
|
+
</div>
|
|
157
|
+
`;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
export const LoggedIn = LoggedInTemplate.bind({});
|
|
161
|
+
LoggedIn.args = {
|
|
162
|
+
market : "se",
|
|
163
|
+
language: 'sv',
|
|
164
|
+
endpoint: 'https://com-integration.postnord.com',
|
|
165
|
+
token: '12c8287a039c57a87cef023dde90605a6d27b4141f74ff7356347e3',
|
|
108
166
|
};
|
|
@@ -31,7 +31,7 @@ export class PnMainnavLink {
|
|
|
31
31
|
this.hasChildren ? (h("button", { onClick: this.setOpenMenuLevel.bind(this), "aria-controls": this.levelId, "aria-pressed": "", "aria-expanded": ((state.openLevel + "" === this.levelId + "")) + '' },
|
|
32
32
|
this.name,
|
|
33
33
|
h("pn-icon", { class: "first-level_icon", symbol: "angle-small-down", color: "blue700" }),
|
|
34
|
-
h("pn-icon", { class: "first-level_arrow", symbol: "arrow-right", color: "blue700" }))) : (h("a", Object.assign({ href: this.href }, (this.target ? { target: this.target } : {}), (this.linkid ? { id: this.linkid } : {})),
|
|
34
|
+
h("pn-icon", { class: "first-level_arrow", symbol: "arrow-right", color: "blue700" }))) : (h("a", Object.assign({ href: this.href }, (this.target ? { target: this.target } : {}), (this.target === "_blank" ? { rel: "nofollow noopener" } : {}), (this.linkid ? { id: this.linkid } : {})),
|
|
35
35
|
this.name,
|
|
36
36
|
this.target === "_blank" ? (h("pn-icon", { symbol: "open-in-new", color: "blue700" })) : null)),
|
|
37
37
|
h("slot", null)));
|
|
@@ -6,7 +6,8 @@ export class PnProfileSelector {
|
|
|
6
6
|
constructor() {
|
|
7
7
|
this.language = null; //sv
|
|
8
8
|
this.returnUrl = "/"; //sv
|
|
9
|
-
|
|
9
|
+
// @Prop() endpoint = "/api/userprofile/sync"; // Endpoint where we send in the current user session
|
|
10
|
+
this.spamode = false; // Endpoint where we send in the current user session
|
|
10
11
|
this.loginManager = null;
|
|
11
12
|
this.loggedIn = false;
|
|
12
13
|
this.i18n = translations["en"];
|
|
@@ -15,9 +16,10 @@ export class PnProfileSelector {
|
|
|
15
16
|
}
|
|
16
17
|
componentWillLoad() {
|
|
17
18
|
this.loginManager = new MarketWebLoginManager({ eventTarget: this.hostElement });
|
|
18
|
-
this.loginManager.init(
|
|
19
|
+
this.loginManager.init(this.spamode);
|
|
19
20
|
this.hostElement["loginmanager"] = this.loginManager;
|
|
20
21
|
this.hostElement.addEventListener(this.loginManager.events.loginstatechange, this.onLoginStateChange.bind(this));
|
|
22
|
+
this.checkLoggedInState();
|
|
21
23
|
this.setInitialValues().then(() => {
|
|
22
24
|
this.init();
|
|
23
25
|
});
|
|
@@ -37,19 +39,25 @@ export class PnProfileSelector {
|
|
|
37
39
|
init() {
|
|
38
40
|
this.setTranslations();
|
|
39
41
|
}
|
|
42
|
+
checkLoggedInState() {
|
|
43
|
+
if (this.loginManager.getToken() && this.loginManager.getUserInfo()) {
|
|
44
|
+
this.onLoginStateChange({ detail: true });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
40
47
|
async onLoginStateChange(e) {
|
|
41
48
|
if (this.loggedIn !== e.detail) {
|
|
42
49
|
this.loggedIn = e.detail;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
50
|
+
this.isLoading = false;
|
|
51
|
+
this.redirectUser();
|
|
52
|
+
// const token = this.loginManager.getToken();
|
|
53
|
+
// if (this.loggedIn && token) {
|
|
54
|
+
// try {
|
|
55
|
+
// await fetch(this.endpoint + '?token=' + token);
|
|
56
|
+
// if (this.numberOfProfiles === 1) {
|
|
57
|
+
// this.redirectUser();
|
|
58
|
+
// }
|
|
59
|
+
// } catch(e) { }
|
|
60
|
+
// }
|
|
53
61
|
}
|
|
54
62
|
}
|
|
55
63
|
async onLoggedIn() {
|
|
@@ -114,12 +122,12 @@ export class PnProfileSelector {
|
|
|
114
122
|
"reflect": false,
|
|
115
123
|
"defaultValue": "\"/\""
|
|
116
124
|
},
|
|
117
|
-
"
|
|
118
|
-
"type": "
|
|
125
|
+
"spamode": {
|
|
126
|
+
"type": "boolean",
|
|
119
127
|
"mutable": false,
|
|
120
128
|
"complexType": {
|
|
121
|
-
"original": "
|
|
122
|
-
"resolved": "
|
|
129
|
+
"original": "boolean",
|
|
130
|
+
"resolved": "boolean",
|
|
123
131
|
"references": {}
|
|
124
132
|
},
|
|
125
133
|
"required": false,
|
|
@@ -128,9 +136,9 @@ export class PnProfileSelector {
|
|
|
128
136
|
"tags": [],
|
|
129
137
|
"text": ""
|
|
130
138
|
},
|
|
131
|
-
"attribute": "
|
|
139
|
+
"attribute": "spamode",
|
|
132
140
|
"reflect": false,
|
|
133
|
-
"defaultValue": "
|
|
141
|
+
"defaultValue": "false"
|
|
134
142
|
}
|
|
135
143
|
}; }
|
|
136
144
|
static get states() { return {
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
class FetchHelper {
|
|
2
|
+
constructor(namespace = "") {
|
|
3
|
+
this.storagePrefix = "";
|
|
4
|
+
this.store = {
|
|
5
|
+
get: (key, permanentStorageFirst = false) => {
|
|
6
|
+
const firstProfider = permanentStorageFirst ? window.localStorage : window.sessionStorage;
|
|
7
|
+
const secondProvider = permanentStorageFirst ? window.sessionStorage : window.localStorage;
|
|
8
|
+
let value = firstProfider.getItem(`${this.storagePrefix}-${key}`);
|
|
9
|
+
if (!value) {
|
|
10
|
+
value = secondProvider.getItem(`${this.storagePrefix}-${key}`);
|
|
11
|
+
}
|
|
12
|
+
if (!value) {
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
if (value.indexOf('{') === 0) {
|
|
16
|
+
try {
|
|
17
|
+
return JSON.parse(value);
|
|
18
|
+
}
|
|
19
|
+
catch (e) {
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
if (value.indexOf(',') !== -1) {
|
|
23
|
+
return value.split(',');
|
|
24
|
+
}
|
|
25
|
+
return value;
|
|
26
|
+
},
|
|
27
|
+
set: (key, value, permanent = false) => {
|
|
28
|
+
const provider = permanent ? window.localStorage : window.sessionStorage;
|
|
29
|
+
if (typeof value === "object" && typeof value.length === "undefined") {
|
|
30
|
+
provider.setItem(`${this.storagePrefix}-${key}`, JSON.stringify(value));
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
provider.setItem(`${this.storagePrefix}-${key}`, value);
|
|
34
|
+
},
|
|
35
|
+
remove: (key) => {
|
|
36
|
+
window.sessionStorage.removeItem(`${this.storagePrefix}-${key}`);
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
this.storagePrefix = namespace;
|
|
40
|
+
}
|
|
41
|
+
async fetchJson(input, init = {}, useCache = false, onCacheUpdated = null) {
|
|
42
|
+
const requestPromise = new Promise(async (resolve) => {
|
|
43
|
+
let doFetchRequest = true;
|
|
44
|
+
const url = (typeof input === "string") ? input : input.url;
|
|
45
|
+
const cacheKey = url;
|
|
46
|
+
let jsonData = null;
|
|
47
|
+
let cachedData = null;
|
|
48
|
+
if (useCache) {
|
|
49
|
+
cachedData = this.store.get(cacheKey);
|
|
50
|
+
// If the data was stored in session storage, then we don't need to do a full request
|
|
51
|
+
if (cachedData && !cachedData.permanent) {
|
|
52
|
+
doFetchRequest = false;
|
|
53
|
+
}
|
|
54
|
+
if (cachedData && cachedData.data) {
|
|
55
|
+
jsonData = cachedData.data;
|
|
56
|
+
resolve(jsonData);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (doFetchRequest) {
|
|
60
|
+
const response = await window.fetch(input, init);
|
|
61
|
+
jsonData = await response.json();
|
|
62
|
+
resolve(jsonData);
|
|
63
|
+
if (useCache) {
|
|
64
|
+
if (typeof onCacheUpdated === "function" && cachedData != null) {
|
|
65
|
+
onCacheUpdated(jsonData);
|
|
66
|
+
}
|
|
67
|
+
this.store.set(cacheKey, this.wrapJson(jsonData, true), true);
|
|
68
|
+
this.store.set(cacheKey, this.wrapJson(jsonData, false), false);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
return requestPromise;
|
|
73
|
+
}
|
|
74
|
+
wrapJson(data, permanent = false) {
|
|
75
|
+
const now = new Date();
|
|
76
|
+
return {
|
|
77
|
+
timestamp: now.getTime(),
|
|
78
|
+
time: now.toISOString(),
|
|
79
|
+
data: data,
|
|
80
|
+
permanent: permanent
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
export { FetchHelper };
|
|
@@ -73,6 +73,14 @@ class MarketWebLoginManager {
|
|
|
73
73
|
const isLoggedIn = (this.store.get(this.keys.token) && this.store.get(this.keys.user)) ? true : false;
|
|
74
74
|
return isLoggedIn;
|
|
75
75
|
}
|
|
76
|
+
registerToken(token) {
|
|
77
|
+
if (!token || token === this.getToken()) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
this.clearUserData();
|
|
81
|
+
this.store.set(this.keys.token, token);
|
|
82
|
+
this.fetchUserInfo();
|
|
83
|
+
}
|
|
76
84
|
getLoginUrl(redirectPage = "") {
|
|
77
85
|
const currentPage = window.location.href;
|
|
78
86
|
redirectPage = redirectPage ? redirectPage : currentPage;
|