@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
package/types/components.d.ts
CHANGED
|
@@ -8,7 +8,6 @@ import { HTMLStencilElement, JSXBase } from "./stencil-public-runtime";
|
|
|
8
8
|
import { ProductPriceItem } from "./components/widgets/pn-find-price/pn-find-price-types";
|
|
9
9
|
import { ProductPriceItem as ProductPriceItem1 } from "./globals/shared/productprice/product-price-types";
|
|
10
10
|
import { LoginDialog, LoginDialogLink, ProfileSelectorCustomerItem, ProfileSelectorOrganization, SiteHeaderI18N, SiteHeaderSearch } from "./components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader-types";
|
|
11
|
-
import { MarketWebLoginManager } from "./globals/MarketWebLoginManager";
|
|
12
11
|
import { ProductGenericItem } from "./components/widgets/pn-proxio-pricegroup/types";
|
|
13
12
|
export namespace Components {
|
|
14
13
|
interface PnBonusProgressbar {
|
|
@@ -278,6 +277,10 @@ export namespace Components {
|
|
|
278
277
|
* If the component should use cached requests
|
|
279
278
|
*/
|
|
280
279
|
"cache": boolean;
|
|
280
|
+
/**
|
|
281
|
+
* Continiously check if a user is logged in *
|
|
282
|
+
*/
|
|
283
|
+
"checkUserLoggedInStateInterval": number;
|
|
281
284
|
/**
|
|
282
285
|
* Specifies which endpoint domain we should load from
|
|
283
286
|
*/
|
|
@@ -352,6 +355,10 @@ export namespace Components {
|
|
|
352
355
|
"userToken": string;
|
|
353
356
|
}
|
|
354
357
|
interface PnMarketwebSiteheaderLogin {
|
|
358
|
+
/**
|
|
359
|
+
* Continiously check if a user is logged in *
|
|
360
|
+
*/
|
|
361
|
+
"checkUserLoggedInStateInterval": number;
|
|
355
362
|
"emitEvents": boolean;
|
|
356
363
|
/**
|
|
357
364
|
* Specifies which endpoint domain we should load from
|
|
@@ -378,13 +385,11 @@ export namespace Components {
|
|
|
378
385
|
"heading": string;
|
|
379
386
|
"idNamespace": string;
|
|
380
387
|
"links": LoginDialogLink[];
|
|
381
|
-
"loginManager": MarketWebLoginManager;
|
|
382
388
|
}
|
|
383
389
|
interface PnMarketwebSiteheaderLoginLinks {
|
|
384
390
|
"idNamespace": string;
|
|
385
391
|
"loggedin": boolean;
|
|
386
392
|
"loginDialog": LoginDialog;
|
|
387
|
-
"loginManager": MarketWebLoginManager;
|
|
388
393
|
"username": string;
|
|
389
394
|
}
|
|
390
395
|
interface PnMarketwebSiteheaderLoginProfileselection {
|
|
@@ -395,7 +400,6 @@ export namespace Components {
|
|
|
395
400
|
"idNamespace": string;
|
|
396
401
|
"loggedin": boolean;
|
|
397
402
|
"loginDialog": LoginDialog;
|
|
398
|
-
"loginManager": MarketWebLoginManager;
|
|
399
403
|
"profileoptions": ProfileSelectorOrganization[];
|
|
400
404
|
}
|
|
401
405
|
interface PnMarketwebSiteheaderSearch {
|
|
@@ -1426,6 +1430,10 @@ declare namespace LocalJSX {
|
|
|
1426
1430
|
* If the component should use cached requests
|
|
1427
1431
|
*/
|
|
1428
1432
|
"cache"?: boolean;
|
|
1433
|
+
/**
|
|
1434
|
+
* Continiously check if a user is logged in *
|
|
1435
|
+
*/
|
|
1436
|
+
"checkUserLoggedInStateInterval"?: number;
|
|
1429
1437
|
/**
|
|
1430
1438
|
* Specifies which endpoint domain we should load from
|
|
1431
1439
|
*/
|
|
@@ -1502,6 +1510,10 @@ declare namespace LocalJSX {
|
|
|
1502
1510
|
"userToken"?: string;
|
|
1503
1511
|
}
|
|
1504
1512
|
interface PnMarketwebSiteheaderLogin {
|
|
1513
|
+
/**
|
|
1514
|
+
* Continiously check if a user is logged in *
|
|
1515
|
+
*/
|
|
1516
|
+
"checkUserLoggedInStateInterval"?: number;
|
|
1505
1517
|
"emitEvents"?: boolean;
|
|
1506
1518
|
/**
|
|
1507
1519
|
* Specifies which endpoint domain we should load from
|
|
@@ -1529,13 +1541,11 @@ declare namespace LocalJSX {
|
|
|
1529
1541
|
"heading"?: string;
|
|
1530
1542
|
"idNamespace"?: string;
|
|
1531
1543
|
"links"?: LoginDialogLink[];
|
|
1532
|
-
"loginManager"?: MarketWebLoginManager;
|
|
1533
1544
|
}
|
|
1534
1545
|
interface PnMarketwebSiteheaderLoginLinks {
|
|
1535
1546
|
"idNamespace"?: string;
|
|
1536
1547
|
"loggedin"?: boolean;
|
|
1537
1548
|
"loginDialog"?: LoginDialog;
|
|
1538
|
-
"loginManager"?: MarketWebLoginManager;
|
|
1539
1549
|
"username"?: string;
|
|
1540
1550
|
}
|
|
1541
1551
|
interface PnMarketwebSiteheaderLoginProfileselection {
|
|
@@ -1546,7 +1556,6 @@ declare namespace LocalJSX {
|
|
|
1546
1556
|
"idNamespace"?: string;
|
|
1547
1557
|
"loggedin"?: boolean;
|
|
1548
1558
|
"loginDialog"?: LoginDialog;
|
|
1549
|
-
"loginManager"?: MarketWebLoginManager;
|
|
1550
1559
|
"profileoptions"?: ProfileSelectorOrganization[];
|
|
1551
1560
|
}
|
|
1552
1561
|
interface PnMarketwebSiteheaderSearch {
|
|
@@ -2,6 +2,7 @@ declare class MarketWebLoginManager {
|
|
|
2
2
|
eventTarget: EventTarget;
|
|
3
3
|
endpoint: String;
|
|
4
4
|
storagePrefix: String;
|
|
5
|
+
checkUserLoggedInStateInterval: number;
|
|
5
6
|
baseUrls: {
|
|
6
7
|
at: string;
|
|
7
8
|
prod: string;
|
|
@@ -25,9 +26,15 @@ declare class MarketWebLoginManager {
|
|
|
25
26
|
};
|
|
26
27
|
overridetokenValue: string;
|
|
27
28
|
siteUrl: String;
|
|
29
|
+
abortSignalForLoginCheck: any;
|
|
30
|
+
loginCheckInProgress: boolean;
|
|
31
|
+
loginCheckTimer: any;
|
|
28
32
|
constructor(options?: IMarketWebLoginManagerOptions);
|
|
29
33
|
init(checkParameters?: boolean): void;
|
|
30
34
|
setSiteUrl(siteUrl: any): void;
|
|
35
|
+
initiateLoggedInCheck(): void;
|
|
36
|
+
doExternalLoggedInCheck(): Promise<void>;
|
|
37
|
+
LogoutUser(): void;
|
|
31
38
|
isLoggedIn(override?: boolean): boolean;
|
|
32
39
|
registerToken(token?: string, tokenSource?: string): void;
|
|
33
40
|
invalidateTokenOfType(tokenSource?: string): void;
|
|
@@ -57,6 +64,7 @@ interface IMarketWebLoginManagerOptions {
|
|
|
57
64
|
endpoint?: String;
|
|
58
65
|
storagePrefix?: String;
|
|
59
66
|
userInfo?: IUserInfo;
|
|
67
|
+
checkUserLoggedInStateInterval?: number;
|
|
60
68
|
}
|
|
61
69
|
interface IUserInfo {
|
|
62
70
|
acr?: string;
|
package/umd/pn-marketweb-init.js
CHANGED
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
|
|
38
38
|
const s = document.createElement('script');
|
|
39
39
|
const currentScriptTag = document.querySelector('script[src*="pn-marketweb-init.js"]');
|
|
40
|
-
const currentScriptSrc = currentScriptTag.getAttribute('src').replace('@latest', '@2.0.
|
|
40
|
+
const currentScriptSrc = currentScriptTag.getAttribute('src').replace('@latest', '@2.0.149');
|
|
41
41
|
checkParameters(currentScriptSrc);
|
|
42
42
|
const loaderScriptSrc = currentScriptSrc.replace('pn-marketweb-init.js', 'standalone-loader.js');
|
|
43
43
|
s.setAttribute('type', 'module');
|
|
@@ -24,12 +24,12 @@
|
|
|
24
24
|
|
|
25
25
|
const s = document.createElement('script');
|
|
26
26
|
s.setAttribute('type', 'module');
|
|
27
|
-
s.setAttribute('src', 'https://cdn.jsdelivr.net/npm/@postnord/pn-marketweb-components@2.0.
|
|
27
|
+
s.setAttribute('src', 'https://cdn.jsdelivr.net/npm/@postnord/pn-marketweb-components@2.0.149/umd/standalone-loader-salesforce.js');
|
|
28
28
|
document.querySelector('head').appendChild(s);
|
|
29
29
|
|
|
30
30
|
const style = document.createElement('link');
|
|
31
31
|
style.setAttribute('rel', 'stylesheet');
|
|
32
|
-
style.setAttribute('href', 'https://cdn.jsdelivr.net/npm/@postnord/pn-marketweb-components@2.0.
|
|
32
|
+
style.setAttribute('href', 'https://cdn.jsdelivr.net/npm/@postnord/pn-marketweb-components@2.0.149/umd/pn-marketweb-wrongrembase.css');
|
|
33
33
|
document.querySelector('head').appendChild(style);
|
|
34
34
|
|
|
35
35
|
window['bindLanguageSelector'] = function () {
|
|
@@ -1,281 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
class MarketWebLoginManager {
|
|
4
|
-
constructor(options = null) {
|
|
5
|
-
var _a;
|
|
6
|
-
this.eventTarget = (window !== null && window !== void 0 ? window : document === null || document === void 0 ? void 0 : document.body);
|
|
7
|
-
this.endpoint = "";
|
|
8
|
-
this.storagePrefix = "pn-user";
|
|
9
|
-
this.baseUrls = {
|
|
10
|
-
at: 'https://atportal.postnord.com/api/unified-login/backend',
|
|
11
|
-
prod: 'https://portal.postnord.com/api/unified-login/backend',
|
|
12
|
-
};
|
|
13
|
-
this.events = {
|
|
14
|
-
loginstatechange: "loginstatechange"
|
|
15
|
-
};
|
|
16
|
-
this.endpoints = {
|
|
17
|
-
authorizationEndpoint: `/authorization`,
|
|
18
|
-
tokenExchangeEndpoint: `/token`,
|
|
19
|
-
userInfoEndpoint: `/user`,
|
|
20
|
-
logoutEndpoint: `/logout`,
|
|
21
|
-
};
|
|
22
|
-
this.keys = {
|
|
23
|
-
tokensource: 'tokensource',
|
|
24
|
-
token: 'token',
|
|
25
|
-
accessToken: 'accessToken',
|
|
26
|
-
user: 'user',
|
|
27
|
-
expire: 'expire',
|
|
28
|
-
expireDate: 'expiredate'
|
|
29
|
-
};
|
|
30
|
-
this.overridetokenValue = 'overridetokenValue';
|
|
31
|
-
this.siteUrl = window.location.origin;
|
|
32
|
-
this.store = {
|
|
33
|
-
get: (key) => {
|
|
34
|
-
const value = window.sessionStorage.getItem(`${this.storagePrefix}-${key}`);
|
|
35
|
-
if (!value) {
|
|
36
|
-
return value;
|
|
37
|
-
}
|
|
38
|
-
if (value.indexOf('{') === 0) {
|
|
39
|
-
try {
|
|
40
|
-
return JSON.parse(value);
|
|
41
|
-
}
|
|
42
|
-
catch (e) {
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
if (value.indexOf(',') !== -1) {
|
|
46
|
-
return value.split(',');
|
|
47
|
-
}
|
|
48
|
-
return value;
|
|
49
|
-
},
|
|
50
|
-
set: (key, value) => {
|
|
51
|
-
if (typeof value === "object" && typeof value.length === "undefined") {
|
|
52
|
-
window.sessionStorage.setItem(`${this.storagePrefix}-${key}`, JSON.stringify(value));
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
window.sessionStorage.setItem(`${this.storagePrefix}-${key}`, value);
|
|
56
|
-
},
|
|
57
|
-
remove: (key) => {
|
|
58
|
-
window.sessionStorage.removeItem(`${this.storagePrefix}-${key}`);
|
|
59
|
-
},
|
|
60
|
-
};
|
|
61
|
-
if (!options) {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
this.eventTarget = (options.eventTarget) ? options.eventTarget : this.eventTarget;
|
|
65
|
-
this.endpoint = options.endpoint ? options.endpoint : `${window.location.protocol}//${window.location.host}`;
|
|
66
|
-
(_a = this.storagePrefix) !== null && _a !== void 0 ? _a : (this.storagePrefix = options.storagePrefix);
|
|
67
|
-
if (options.userInfo) {
|
|
68
|
-
this.store.set(this.keys.user, options.userInfo);
|
|
69
|
-
this.registerToken(this.overridetokenValue, 'override');
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
init(checkParameters = true) {
|
|
73
|
-
if (checkParameters) {
|
|
74
|
-
this.checkParameters();
|
|
75
|
-
this.checkPNTopbar();
|
|
76
|
-
this.checkExpireTime();
|
|
77
|
-
if (this.store.get(this.keys.token) && !this.store.get(this.keys.user)) {
|
|
78
|
-
this.fetchUserInfo();
|
|
79
|
-
}
|
|
80
|
-
this.loginStateChange();
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
setSiteUrl(siteUrl) {
|
|
84
|
-
if (siteUrl) {
|
|
85
|
-
this.siteUrl = siteUrl;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
isLoggedIn(override = false) {
|
|
89
|
-
if (override) {
|
|
90
|
-
return override;
|
|
91
|
-
}
|
|
92
|
-
let isLoggedIn = (this.store.get(this.keys.token) && this.store.get(this.keys.user)) ? true : false;
|
|
93
|
-
if (!isLoggedIn && this.store.get(this.keys.token) === this.overridetokenValue) {
|
|
94
|
-
isLoggedIn = true;
|
|
95
|
-
}
|
|
96
|
-
return isLoggedIn;
|
|
97
|
-
}
|
|
98
|
-
registerToken(token = '', tokenSource = 'frontend') {
|
|
99
|
-
if (!token || token === this.getToken()) {
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
this.clearUserData();
|
|
103
|
-
this.store.set(this.keys.tokensource, tokenSource);
|
|
104
|
-
this.store.set(this.keys.token, token);
|
|
105
|
-
this.fetchUserInfo();
|
|
106
|
-
}
|
|
107
|
-
invalidateTokenOfType(tokenSource = 'frontend') {
|
|
108
|
-
const currentToken = this.store.get(this.keys.token);
|
|
109
|
-
if (!currentToken) {
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
const currentTokenSource = this.store.get(this.keys.tokensource);
|
|
113
|
-
if (currentTokenSource !== tokenSource) {
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
// If we have a token and the source is set then we will invalidate the user data
|
|
117
|
-
this.clearUserData();
|
|
118
|
-
}
|
|
119
|
-
getLoginUrl(redirectPage = "") {
|
|
120
|
-
const currentPage = window.location.href;
|
|
121
|
-
redirectPage = redirectPage ? redirectPage : currentPage;
|
|
122
|
-
return `${this.getBaseUrl()}${this.endpoints.authorizationEndpoint}?redirectionUrl=${redirectPage}`;
|
|
123
|
-
}
|
|
124
|
-
getLogoutUrl(linkHref = "") {
|
|
125
|
-
if (linkHref.indexOf('logout?logoutUrl') !== -1) {
|
|
126
|
-
// Link has already been formatted.
|
|
127
|
-
return linkHref;
|
|
128
|
-
}
|
|
129
|
-
let redirectPage = linkHref.replace('logout', '').replace('http://window.location.href/?', window.location.href).replace('https://window.location.href/?', window.location.href);
|
|
130
|
-
let rootUrl = this.siteUrl;
|
|
131
|
-
try {
|
|
132
|
-
const url = new URL(this.siteUrl + '');
|
|
133
|
-
rootUrl = url.origin;
|
|
134
|
-
}
|
|
135
|
-
catch (e) { }
|
|
136
|
-
const addSlash = (rootUrl.lastIndexOf('/') !== (rootUrl.length - 1));
|
|
137
|
-
const siteUrl = rootUrl + (addSlash ? '/' : '') + 'logout';
|
|
138
|
-
const secondLogoutUrl = `${this.getBaseUrl()}${this.endpoints.logoutEndpoint}?authorization=${this.store.get(this.keys.token)}%26redirectionUrl=${redirectPage}`;
|
|
139
|
-
const logoutUrl = `${siteUrl}?logoutUrl=${secondLogoutUrl}`;
|
|
140
|
-
return logoutUrl;
|
|
141
|
-
}
|
|
142
|
-
getUserInfo() {
|
|
143
|
-
if (this.isLoggedIn()) {
|
|
144
|
-
return this.store.get(this.keys.user);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
getEventTarget() {
|
|
148
|
-
return this.eventTarget;
|
|
149
|
-
}
|
|
150
|
-
checkExpireTime() {
|
|
151
|
-
const expire = this.store.get(this.keys.expire);
|
|
152
|
-
if (!expire) {
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
const now = new Date();
|
|
156
|
-
const expireDate = new Date(Math.floor(parseInt(expire, 10) * 1000));
|
|
157
|
-
if (now > expireDate) {
|
|
158
|
-
console.info('Login time has expired');
|
|
159
|
-
this.clearUserData();
|
|
160
|
-
this.loginStateChange();
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
checkPNTopbar() {
|
|
164
|
-
if (this.isLoggedIn() || !window['pnTopbar'] || !window['pnTopbar']['session_id']) {
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
this.store.set(this.keys.token, window['pnTopbar']['session_id']);
|
|
168
|
-
this.fetchUserInfo();
|
|
169
|
-
}
|
|
170
|
-
checkParameters() {
|
|
171
|
-
if (!(window === null || window === void 0 ? void 0 : window.location)) {
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
const params = new URLSearchParams(window.location.search);
|
|
175
|
-
if (params.get("oneTimeCode")) {
|
|
176
|
-
const oneTimeCode = params.get("oneTimeCode");
|
|
177
|
-
this.exchangeToken(oneTimeCode).then(() => {
|
|
178
|
-
const currentHref = window.location.href;
|
|
179
|
-
const paramPrefix = (currentHref.indexOf('?oneTimeCode') !== -1) ? "?" : "&";
|
|
180
|
-
const newUrl = currentHref.replace(`${paramPrefix}oneTimeCode=${oneTimeCode}`, '');
|
|
181
|
-
history.replaceState({}, document.querySelector('title').innerText, newUrl);
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
async fetchUserInfo() {
|
|
186
|
-
const token = this.store.get(this.keys.token);
|
|
187
|
-
if (this.store.get(this.keys.token) === this.overridetokenValue) {
|
|
188
|
-
console.info('Did not fetch user data since it was set by an override');
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
const reqConfig = {
|
|
192
|
-
method: 'GET',
|
|
193
|
-
headers: {
|
|
194
|
-
'Accept': 'application/json',
|
|
195
|
-
'Content-Type': 'application/json',
|
|
196
|
-
'Authorization': token
|
|
197
|
-
},
|
|
198
|
-
};
|
|
199
|
-
const response = await fetch(`${this.getBaseUrl()}${this.endpoints.userInfoEndpoint}`, reqConfig);
|
|
200
|
-
const data = await response.json();
|
|
201
|
-
if (data && data["idToken"]) {
|
|
202
|
-
try {
|
|
203
|
-
const { idToken, expiryTime, accessToken } = data;
|
|
204
|
-
const userInfo = this.parseUserInfo(idToken);
|
|
205
|
-
if (!userInfo) {
|
|
206
|
-
console.error('Userdata is not valid');
|
|
207
|
-
this.clearUserData();
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
|
-
this.store.set(this.keys.user, userInfo);
|
|
211
|
-
// 10 Min early expire
|
|
212
|
-
this.store.set(this.keys.accessToken, accessToken);
|
|
213
|
-
this.store.set(this.keys.expire, expiryTime);
|
|
214
|
-
this.store.set(this.keys.expireDate, new Date(Math.floor(parseInt(expiryTime, 10) * 1000)));
|
|
215
|
-
this.loginStateChange();
|
|
216
|
-
}
|
|
217
|
-
catch (e) {
|
|
218
|
-
console.error('Unable to get user information', e);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
else {
|
|
222
|
-
console.error('Unable to get user information. Clearing login state');
|
|
223
|
-
this.clearUserData();
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
clearUserData() {
|
|
227
|
-
this.store.remove(this.keys.user);
|
|
228
|
-
this.store.remove(this.keys.tokensource);
|
|
229
|
-
this.store.remove(this.keys.accessToken);
|
|
230
|
-
this.store.remove(this.keys.token);
|
|
231
|
-
this.store.remove(this.keys.expire);
|
|
232
|
-
this.store.remove(this.keys.expireDate);
|
|
233
|
-
}
|
|
234
|
-
getToken() {
|
|
235
|
-
return this.store.get(this.keys.token);
|
|
236
|
-
}
|
|
237
|
-
getAccessToken() {
|
|
238
|
-
return this.store.get(this.keys.accessToken);
|
|
239
|
-
}
|
|
240
|
-
async exchangeToken(oneTimeCode) {
|
|
241
|
-
this.clearUserData();
|
|
242
|
-
const response = await fetch(`${this.getBaseUrl()}${this.endpoints.tokenExchangeEndpoint}?oneTimeCode=${oneTimeCode}`);
|
|
243
|
-
const { token } = await response.json();
|
|
244
|
-
if (typeof token === "string" && token) {
|
|
245
|
-
this.store.set(this.keys.token, token);
|
|
246
|
-
}
|
|
247
|
-
this.fetchUserInfo();
|
|
248
|
-
}
|
|
249
|
-
loginStateChange() {
|
|
250
|
-
if (!this.eventTarget) {
|
|
251
|
-
return;
|
|
252
|
-
}
|
|
253
|
-
this.eventTarget.dispatchEvent(new CustomEvent(this.events.loginstatechange, {
|
|
254
|
-
detail: this.isLoggedIn()
|
|
255
|
-
}));
|
|
256
|
-
}
|
|
257
|
-
getBaseUrl() {
|
|
258
|
-
const atEnvironments = ["localhost", "integration.", 'local.'];
|
|
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
|
-
}
|
|
263
|
-
if (useATEnv) {
|
|
264
|
-
return this.baseUrls.at;
|
|
265
|
-
}
|
|
266
|
-
return this.baseUrls.prod;
|
|
267
|
-
}
|
|
268
|
-
parseUserInfo(idToken) {
|
|
269
|
-
if (!idToken) {
|
|
270
|
-
return null;
|
|
271
|
-
}
|
|
272
|
-
var base64Url = idToken.split('.')[1];
|
|
273
|
-
var base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
|
|
274
|
-
var jsonPayload = decodeURIComponent(atob(base64).split('').map(function (c) {
|
|
275
|
-
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
|
|
276
|
-
}).join(''));
|
|
277
|
-
return JSON.parse(jsonPayload);
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
exports.MarketWebLoginManager = MarketWebLoginManager;
|