@schibsted/account-sdk-browser 5.0.0 → 5.0.1-beta.2
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/es5/global.js +87 -67
- package/es5/global.js.map +1 -1
- package/es5/global.min.js +1 -1
- package/es5/global.min.js.map +1 -1
- package/es5/identity.js +87 -67
- package/es5/identity.js.map +1 -1
- package/es5/identity.min.js +1 -1
- package/es5/identity.min.js.map +1 -1
- package/es5/index.js +87 -67
- package/es5/index.js.map +1 -1
- package/es5/index.min.js +1 -1
- package/es5/index.min.js.map +1 -1
- package/es5/monetization.js +1 -4
- package/es5/monetization.js.map +1 -1
- package/es5/monetization.min.js +1 -1
- package/es5/monetization.min.js.map +1 -1
- package/package.json +1 -1
- package/src/cache.d.ts +0 -3
- package/src/cache.js +0 -3
- package/src/identity.d.ts +33 -7
- package/src/identity.js +71 -56
- package/src/version.js +1 -1
package/es5/global.js
CHANGED
|
@@ -1865,7 +1865,7 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
|
|
|
1865
1865
|
* `password` (will force password confirmation, even if user is already logged in), `eid`. Those values might
|
|
1866
1866
|
* be mixed as space-separated string. To make sure that user has authenticated with 2FA you need
|
|
1867
1867
|
* to verify AMR (Authentication Methods References) claim in ID token.
|
|
1868
|
-
* Might also be used to ensure additional acr (sms, otp) for already logged
|
|
1868
|
+
* Might also be used to ensure additional acr (sms, otp) for already logged-in users.
|
|
1869
1869
|
* Supported value is also 'otp-email' means one time password using email.
|
|
1870
1870
|
* @property {string} [scope] - The OAuth scopes for the tokens. This is a list of
|
|
1871
1871
|
* scopes, separated by space. If the list of scopes contains `openid`, the generated tokens
|
|
@@ -1899,7 +1899,7 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
|
|
|
1899
1899
|
* `password` (will force password confirmation, even if user is already logged in). Those values might
|
|
1900
1900
|
* be mixed as space-separated string. To make sure that user has authenticated with 2FA you need
|
|
1901
1901
|
* to verify AMR (Authentication Methods References) claim in ID token.
|
|
1902
|
-
* Might also be used to ensure additional acr (sms, otp) for already logged
|
|
1902
|
+
* Might also be used to ensure additional acr (sms, otp) for already logged-in users.
|
|
1903
1903
|
* Supported value is also 'otp-email' means one time password using email.
|
|
1904
1904
|
* @property {string} [scope] - The OAuth scopes for the tokens. This is a list of
|
|
1905
1905
|
* scopes, separated by space. If the list of scopes contains `openid`, the generated tokens
|
|
@@ -1973,7 +1973,7 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
|
|
|
1973
1973
|
|
|
1974
1974
|
/**
|
|
1975
1975
|
* @typedef {object} SimplifiedLoginData
|
|
1976
|
-
* @property {string} identifier - Deprecated: User UUID, to be
|
|
1976
|
+
* @property {string} identifier - Deprecated: User UUID, to be as `loginHint` for {@link Identity#login}
|
|
1977
1977
|
* @property {string} display_text - Human-readable user identifier
|
|
1978
1978
|
* @property {string} client_name - Client name
|
|
1979
1979
|
*/
|
|
@@ -1985,13 +1985,17 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
|
|
|
1985
1985
|
|
|
1986
1986
|
var HAS_SESSION_CACHE_KEY = 'hasSession-cache';
|
|
1987
1987
|
var SESSION_CALL_BLOCKED_CACHE_KEY = 'sessionCallBlocked-cache';
|
|
1988
|
-
var SESSION_CALL_BLOCKED_TTL = 1000 *
|
|
1988
|
+
var SESSION_CALL_BLOCKED_TTL = 1000 * 30; //set to 30s, the default period for a request timeout
|
|
1989
|
+
|
|
1990
|
+
var TAB_ID_KEY = 'tab-id-cache';
|
|
1991
|
+
var TAB_ID = Math.floor(Math.random() * 100000);
|
|
1992
|
+
var TAB_ID_TTL = 1000 * 60 * 60 * 24 * 30;
|
|
1989
1993
|
var globalWindow = function globalWindow() {
|
|
1990
1994
|
return window;
|
|
1991
1995
|
};
|
|
1992
1996
|
|
|
1993
1997
|
/**
|
|
1994
|
-
* Provides Identity
|
|
1998
|
+
* Provides Identity functionality to a web page
|
|
1995
1999
|
*/
|
|
1996
2000
|
var Identity = /*#__PURE__*/function (_EventEmitter) {
|
|
1997
2001
|
_inherits(Identity, _EventEmitter);
|
|
@@ -2027,20 +2031,24 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
|
|
|
2027
2031
|
Object(_validate_js__WEBPACK_IMPORTED_MODULE_55__["assert"])(!redirectUri || Object(_validate_js__WEBPACK_IMPORTED_MODULE_55__["isUrl"])(redirectUri), 'redirectUri parameter is invalid');
|
|
2028
2032
|
Object(_validate_js__WEBPACK_IMPORTED_MODULE_55__["assert"])(sessionDomain && Object(_validate_js__WEBPACK_IMPORTED_MODULE_55__["isUrl"])(sessionDomain), 'sessionDomain parameter is not a valid URL');
|
|
2029
2033
|
_spidTalk_js__WEBPACK_IMPORTED_MODULE_64__["emulate"](window);
|
|
2034
|
+
|
|
2035
|
+
// Internal hack: set as false to always refresh from hasSession
|
|
2036
|
+
_this._enableSessionCaching = true;
|
|
2030
2037
|
_this._sessionInitiatedSent = false;
|
|
2031
2038
|
_this.window = window;
|
|
2032
2039
|
_this.clientId = clientId;
|
|
2033
|
-
_this.
|
|
2040
|
+
_this.sessionStorageCache = new _cache_js__WEBPACK_IMPORTED_MODULE_60__["default"](function () {
|
|
2034
2041
|
return _this.window && _this.window.sessionStorage;
|
|
2035
2042
|
});
|
|
2043
|
+
_this.localStorageCache = new _cache_js__WEBPACK_IMPORTED_MODULE_60__["default"](function () {
|
|
2044
|
+
return _this.window && _this.window.localStorage;
|
|
2045
|
+
});
|
|
2036
2046
|
_this.redirectUri = redirectUri;
|
|
2037
2047
|
_this.env = env;
|
|
2038
2048
|
_this.log = log;
|
|
2039
2049
|
_this.callbackBeforeRedirect = callbackBeforeRedirect;
|
|
2040
2050
|
_this._sessionDomain = sessionDomain;
|
|
2041
|
-
|
|
2042
|
-
// Internal hack: set to false to always refresh from hassession
|
|
2043
|
-
_this._enableSessionCaching = true;
|
|
2051
|
+
_this._tabId = _this._getTabId();
|
|
2044
2052
|
|
|
2045
2053
|
// Old session
|
|
2046
2054
|
_this._session = {};
|
|
@@ -2049,50 +2057,61 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
|
|
|
2049
2057
|
_this._setBffServerUrl(env);
|
|
2050
2058
|
_this._setOauthServerUrl(env);
|
|
2051
2059
|
_this._setGlobalSessionServiceUrl(env);
|
|
2052
|
-
_this.
|
|
2060
|
+
_this._unblockSessionCallByTab();
|
|
2053
2061
|
return _this;
|
|
2054
2062
|
}
|
|
2055
2063
|
|
|
2056
2064
|
/**
|
|
2057
|
-
*
|
|
2065
|
+
* Read tabId from session storage if possible, otherwise save tabId to session storage and return it
|
|
2066
|
+
* @returns {number}
|
|
2058
2067
|
* @private
|
|
2059
|
-
*
|
|
2060
|
-
* @returns {boolean|void}
|
|
2061
2068
|
*/
|
|
2062
2069
|
_createClass(Identity, [{
|
|
2063
|
-
key: "
|
|
2064
|
-
value: function
|
|
2070
|
+
key: "_getTabId",
|
|
2071
|
+
value: function _getTabId() {
|
|
2065
2072
|
if (this._enableSessionCaching) {
|
|
2066
|
-
|
|
2073
|
+
var tabId = this.sessionStorageCache.get(TAB_ID_KEY);
|
|
2074
|
+
if (!tabId) {
|
|
2075
|
+
this.sessionStorageCache.set(TAB_ID_KEY, TAB_ID, TAB_ID_TTL);
|
|
2076
|
+
return TAB_ID;
|
|
2077
|
+
}
|
|
2078
|
+
return tabId;
|
|
2067
2079
|
}
|
|
2080
|
+
return TAB_ID;
|
|
2068
2081
|
}
|
|
2069
2082
|
|
|
2070
2083
|
/**
|
|
2071
|
-
*
|
|
2084
|
+
* Checks if calling GET session is blocked
|
|
2085
|
+
* @private
|
|
2086
|
+
* @returns {number|null}
|
|
2087
|
+
*/
|
|
2088
|
+
}, {
|
|
2089
|
+
key: "_isSessionCallBlocked",
|
|
2090
|
+
value: function _isSessionCallBlocked() {
|
|
2091
|
+
return this.localStorageCache.get(SESSION_CALL_BLOCKED_CACHE_KEY);
|
|
2092
|
+
}
|
|
2093
|
+
|
|
2094
|
+
/**
|
|
2095
|
+
* Block calls to get session. This is done to prevent concurrent calls which can log user out if session is refreshed by one of them
|
|
2072
2096
|
* @private
|
|
2073
|
-
*
|
|
2074
2097
|
* @returns {void}
|
|
2075
2098
|
*/
|
|
2076
2099
|
}, {
|
|
2077
2100
|
key: "_blockSessionCall",
|
|
2078
2101
|
value: function _blockSessionCall() {
|
|
2079
|
-
|
|
2080
|
-
var SESSION_CALL_BLOCKED = true;
|
|
2081
|
-
this.cache.set(SESSION_CALL_BLOCKED_CACHE_KEY, SESSION_CALL_BLOCKED, SESSION_CALL_BLOCKED_TTL);
|
|
2082
|
-
}
|
|
2102
|
+
this.localStorageCache.set(SESSION_CALL_BLOCKED_CACHE_KEY, this._tabId, SESSION_CALL_BLOCKED_TTL);
|
|
2083
2103
|
}
|
|
2084
2104
|
|
|
2085
2105
|
/**
|
|
2086
|
-
* Unblocks calls to get session
|
|
2106
|
+
* Unblocks calls to get session if the lock was put by the same tab
|
|
2087
2107
|
* @private
|
|
2088
|
-
*
|
|
2089
2108
|
* @returns {void}
|
|
2090
2109
|
*/
|
|
2091
2110
|
}, {
|
|
2092
|
-
key: "
|
|
2093
|
-
value: function
|
|
2094
|
-
if (this.
|
|
2095
|
-
this.
|
|
2111
|
+
key: "_unblockSessionCallByTab",
|
|
2112
|
+
value: function _unblockSessionCallByTab() {
|
|
2113
|
+
if (this._isSessionCallBlocked() === this._tabId) {
|
|
2114
|
+
this.localStorageCache.delete(SESSION_CALL_BLOCKED_CACHE_KEY);
|
|
2096
2115
|
}
|
|
2097
2116
|
}
|
|
2098
2117
|
|
|
@@ -2200,7 +2219,7 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
|
|
|
2200
2219
|
}
|
|
2201
2220
|
|
|
2202
2221
|
/**
|
|
2203
|
-
* Emits the relevant events based on the previous and new reply from
|
|
2222
|
+
* Emits the relevant events based on the previous and new reply from {@link Identity#hasSession}
|
|
2204
2223
|
* @private
|
|
2205
2224
|
* @param {object} previous
|
|
2206
2225
|
* @param {object} current
|
|
@@ -2284,7 +2303,7 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
|
|
|
2284
2303
|
}
|
|
2285
2304
|
|
|
2286
2305
|
/**
|
|
2287
|
-
* Set the Varnish cookie (`SP_ID`) when hasSession
|
|
2306
|
+
* Set the Varnish cookie (`SP_ID`) when {@link Identity#hasSession} is called. Note that most browsers require
|
|
2288
2307
|
* that you are on a "real domain" for this to work — so, **not** `localhost`
|
|
2289
2308
|
* @param {object} [options]
|
|
2290
2309
|
* @param {number} [options.expiresIn] Override this to set number of seconds before the varnish
|
|
@@ -2405,10 +2424,6 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
|
|
|
2405
2424
|
key: "hasSession",
|
|
2406
2425
|
value: function hasSession() {
|
|
2407
2426
|
var _this2 = this;
|
|
2408
|
-
var isSessionCallBlocked = this._isSessionCallBlocked();
|
|
2409
|
-
if (isSessionCallBlocked) {
|
|
2410
|
-
return this._session;
|
|
2411
|
-
}
|
|
2412
2427
|
if (this._hasSessionInProgress) {
|
|
2413
2428
|
return this._hasSessionInProgress;
|
|
2414
2429
|
}
|
|
@@ -2437,57 +2452,67 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
|
|
|
2437
2452
|
break;
|
|
2438
2453
|
}
|
|
2439
2454
|
// Try to resolve from cache (it has a TTL)
|
|
2440
|
-
cachedSession = _this2.
|
|
2455
|
+
cachedSession = _this2.sessionStorageCache.get(HAS_SESSION_CACHE_KEY);
|
|
2441
2456
|
if (!cachedSession) {
|
|
2442
2457
|
_context.next = 4;
|
|
2443
2458
|
break;
|
|
2444
2459
|
}
|
|
2445
2460
|
return _context.abrupt("return", _postProcess(cachedSession));
|
|
2446
2461
|
case 4:
|
|
2462
|
+
if (!_this2._isSessionCallBlocked()) {
|
|
2463
|
+
_context.next = 6;
|
|
2464
|
+
break;
|
|
2465
|
+
}
|
|
2466
|
+
return _context.abrupt("return", _this2._session);
|
|
2467
|
+
case 6:
|
|
2447
2468
|
sessionData = null;
|
|
2448
|
-
_context.prev =
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2469
|
+
_context.prev = 7;
|
|
2470
|
+
_this2._blockSessionCall();
|
|
2471
|
+
_context.next = 11;
|
|
2472
|
+
return _this2._sessionService.get('/v2/session', {
|
|
2473
|
+
tabId: _this2._tabId
|
|
2474
|
+
});
|
|
2475
|
+
case 11:
|
|
2452
2476
|
sessionData = _context.sent;
|
|
2453
|
-
_context.next =
|
|
2477
|
+
_context.next = 18;
|
|
2454
2478
|
break;
|
|
2455
|
-
case
|
|
2456
|
-
_context.prev =
|
|
2457
|
-
_context.t0 = _context["catch"](
|
|
2479
|
+
case 14:
|
|
2480
|
+
_context.prev = 14;
|
|
2481
|
+
_context.t0 = _context["catch"](7);
|
|
2458
2482
|
if (_context.t0 && _context.t0.code === 400 && _this2._enableSessionCaching) {
|
|
2459
2483
|
expiresIn = 1000 * (_context.t0.expiresIn || 300);
|
|
2460
|
-
_this2.
|
|
2484
|
+
_this2.sessionStorageCache.set(HAS_SESSION_CACHE_KEY, {
|
|
2461
2485
|
error: _context.t0
|
|
2462
2486
|
}, expiresIn);
|
|
2463
2487
|
}
|
|
2464
2488
|
throw _context.t0;
|
|
2465
|
-
case
|
|
2489
|
+
case 18:
|
|
2466
2490
|
if (!sessionData) {
|
|
2467
|
-
_context.next =
|
|
2491
|
+
_context.next = 24;
|
|
2468
2492
|
break;
|
|
2469
2493
|
}
|
|
2470
2494
|
if (!_checkRedirectionNeed(sessionData)) {
|
|
2471
|
-
_context.next =
|
|
2495
|
+
_context.next = 23;
|
|
2472
2496
|
break;
|
|
2473
2497
|
}
|
|
2474
|
-
|
|
2475
|
-
_context.next = 20;
|
|
2498
|
+
_context.next = 22;
|
|
2476
2499
|
return _this2.callbackBeforeRedirect();
|
|
2477
|
-
case
|
|
2478
|
-
|
|
2479
|
-
|
|
2500
|
+
case 22:
|
|
2501
|
+
_this2.window.location.href = _this2._sessionService.makeUrl(sessionData.redirectURL, {
|
|
2502
|
+
tabId: _this2._getTabId()
|
|
2503
|
+
});
|
|
2504
|
+
case 23:
|
|
2480
2505
|
if (_this2._enableSessionCaching) {
|
|
2481
2506
|
_expiresIn = 1000 * (sessionData.expiresIn || 300);
|
|
2482
|
-
_this2.
|
|
2507
|
+
_this2.sessionStorageCache.set(HAS_SESSION_CACHE_KEY, sessionData, _expiresIn);
|
|
2483
2508
|
}
|
|
2484
|
-
case
|
|
2509
|
+
case 24:
|
|
2485
2510
|
return _context.abrupt("return", _postProcess(sessionData));
|
|
2486
|
-
case
|
|
2511
|
+
case 25:
|
|
2487
2512
|
case "end":
|
|
2488
2513
|
return _context.stop();
|
|
2489
2514
|
}
|
|
2490
|
-
}, _callee, null, [[
|
|
2515
|
+
}, _callee, null, [[7, 14]]);
|
|
2491
2516
|
}));
|
|
2492
2517
|
return function _getSession() {
|
|
2493
2518
|
return _ref2.apply(this, arguments);
|
|
@@ -2495,15 +2520,13 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
|
|
|
2495
2520
|
}();
|
|
2496
2521
|
this._hasSessionInProgress = _getSession().then(function (sessionData) {
|
|
2497
2522
|
_this2._hasSessionInProgress = false;
|
|
2498
|
-
if (Object(_validate_js__WEBPACK_IMPORTED_MODULE_55__["isUrl"])(sessionData)) {
|
|
2499
|
-
return _this2.window.location.href = sessionData;
|
|
2500
|
-
}
|
|
2501
2523
|
return sessionData;
|
|
2502
2524
|
}, function (err) {
|
|
2503
2525
|
_this2.emit('error', err);
|
|
2504
2526
|
_this2._hasSessionInProgress = false;
|
|
2505
2527
|
throw new _SDKError_js__WEBPACK_IMPORTED_MODULE_63__["default"]('HasSession failed', err);
|
|
2506
2528
|
});
|
|
2529
|
+
this._unblockSessionCallByTab();
|
|
2507
2530
|
return this._hasSessionInProgress;
|
|
2508
2531
|
}
|
|
2509
2532
|
|
|
@@ -2550,7 +2573,7 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
|
|
|
2550
2573
|
}, {
|
|
2551
2574
|
key: "clearCachedUserSession",
|
|
2552
2575
|
value: function clearCachedUserSession() {
|
|
2553
|
-
this.
|
|
2576
|
+
this.sessionStorageCache.delete(HAS_SESSION_CACHE_KEY);
|
|
2554
2577
|
}
|
|
2555
2578
|
|
|
2556
2579
|
/**
|
|
@@ -2644,7 +2667,7 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
|
|
|
2644
2667
|
* @description This function calls {@link Identity#hasSession} internally and thus has the side
|
|
2645
2668
|
* effect that it might perform an auto-login on the user
|
|
2646
2669
|
* @throws {SDKError} If the user isn't connected to the merchant
|
|
2647
|
-
* @return {
|
|
2670
|
+
* @return {number} The `userId` field (not to be confused with the `uuid`)
|
|
2648
2671
|
*/
|
|
2649
2672
|
}, {
|
|
2650
2673
|
key: "getUserId",
|
|
@@ -2945,7 +2968,7 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
|
|
|
2945
2968
|
_ref4$prompt = _ref4.prompt,
|
|
2946
2969
|
prompt = _ref4$prompt === void 0 ? 'select_account' : _ref4$prompt;
|
|
2947
2970
|
this._closePopup();
|
|
2948
|
-
this.
|
|
2971
|
+
this.sessionStorageCache.delete(HAS_SESSION_CACHE_KEY);
|
|
2949
2972
|
var url = this.loginUrl({
|
|
2950
2973
|
state: state,
|
|
2951
2974
|
acrValues: acrValues,
|
|
@@ -3018,7 +3041,7 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
|
|
|
3018
3041
|
key: "logout",
|
|
3019
3042
|
value: function logout() {
|
|
3020
3043
|
var redirectUri = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.redirectUri;
|
|
3021
|
-
this.
|
|
3044
|
+
this.sessionStorageCache.delete(HAS_SESSION_CACHE_KEY);
|
|
3022
3045
|
this._maybeClearVarnishCookie();
|
|
3023
3046
|
this.emit('logout');
|
|
3024
3047
|
this.window.location.href = this.logoutUrl(redirectUri);
|
|
@@ -11026,7 +11049,6 @@ var Cache = /*#__PURE__*/function () {
|
|
|
11026
11049
|
/**
|
|
11027
11050
|
* Get a value from cache (checks that the object has not expired)
|
|
11028
11051
|
* @param {string} key
|
|
11029
|
-
* @private
|
|
11030
11052
|
* @returns {*} - The value if it exists, otherwise null
|
|
11031
11053
|
*/
|
|
11032
11054
|
_createClass(Cache, [{
|
|
@@ -11062,7 +11084,6 @@ var Cache = /*#__PURE__*/function () {
|
|
|
11062
11084
|
* @param {string} key
|
|
11063
11085
|
* @param {*} value
|
|
11064
11086
|
* @param {Number} expiresIn - Value in milliseconds until the entry expires
|
|
11065
|
-
* @private
|
|
11066
11087
|
* @returns {void}
|
|
11067
11088
|
*/
|
|
11068
11089
|
}, {
|
|
@@ -11091,7 +11112,6 @@ var Cache = /*#__PURE__*/function () {
|
|
|
11091
11112
|
/**
|
|
11092
11113
|
* Delete a cache entry
|
|
11093
11114
|
* @param {string} key
|
|
11094
|
-
* @private
|
|
11095
11115
|
* @returns {void}
|
|
11096
11116
|
*/
|
|
11097
11117
|
}, {
|
|
@@ -12011,7 +12031,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
12011
12031
|
|
|
12012
12032
|
|
|
12013
12033
|
|
|
12014
|
-
var version = '5.0.
|
|
12034
|
+
var version = '5.0.1-beta.2';
|
|
12015
12035
|
/* harmony default export */ __webpack_exports__["default"] = (version);
|
|
12016
12036
|
|
|
12017
12037
|
/***/ }),
|