@schibsted/account-sdk-browser 4.8.7-beta.8 → 5.0.0-beta.1

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 CHANGED
@@ -1986,6 +1986,9 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
1986
1986
  var HAS_SESSION_CACHE_KEY = 'hasSession-cache';
1987
1987
  var SESSION_CALL_BLOCKED_CACHE_KEY = 'sessionCallBlocked-cache';
1988
1988
  var SESSION_CALL_BLOCKED_TTL = 1000 * 60 * 5;
1989
+ var TAB_ID_KEY = 'tab-id-cache';
1990
+ var TAB_ID = Math.floor(Math.random() * 100000);
1991
+ var TAB_ID_TTL = 1000 * 60 * 60 * 24 * 30;
1989
1992
  var globalWindow = function globalWindow() {
1990
1993
  return window;
1991
1994
  };
@@ -2030,9 +2033,12 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
2030
2033
  _this._sessionInitiatedSent = false;
2031
2034
  _this.window = window;
2032
2035
  _this.clientId = clientId;
2033
- _this.cache = new _cache_js__WEBPACK_IMPORTED_MODULE_60__["default"](function () {
2036
+ _this.sessionStorageCache = new _cache_js__WEBPACK_IMPORTED_MODULE_60__["default"](function () {
2034
2037
  return _this.window && _this.window.sessionStorage;
2035
2038
  });
2039
+ _this.localStorageCache = new _cache_js__WEBPACK_IMPORTED_MODULE_60__["default"](function () {
2040
+ return _this.window && _this.window.localStorage;
2041
+ });
2036
2042
  _this.redirectUri = redirectUri;
2037
2043
  _this.env = env;
2038
2044
  _this.log = log;
@@ -2054,19 +2060,35 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
2054
2060
  }
2055
2061
 
2056
2062
  /**
2057
- * Checks if getting session is blocked
2063
+ * Read tabId from session storage
2064
+ * @returns {number}
2058
2065
  * @private
2059
- *
2060
- * @returns {boolean|void}
2061
2066
  */
2062
2067
  _createClass(Identity, [{
2063
- key: "_isSessionCallBlocked",
2064
- value: function _isSessionCallBlocked() {
2068
+ key: "_getTabId",
2069
+ value: function _getTabId() {
2065
2070
  if (this._enableSessionCaching) {
2066
- return this.cache.get(SESSION_CALL_BLOCKED_CACHE_KEY);
2071
+ var tabId = this.cache.get(TAB_ID_KEY);
2072
+ if (!tabId) {
2073
+ this.cache.set(TAB_ID_KEY, TAB_ID, TAB_ID_TTL);
2074
+ return TAB_ID;
2075
+ }
2076
+ return tabId;
2067
2077
  }
2068
2078
  }
2069
2079
 
2080
+ /**
2081
+ * Checks if getting session is blocked
2082
+ * @private
2083
+ *
2084
+ * @returns {boolean|void}
2085
+ */
2086
+ }, {
2087
+ key: "_isSessionCallBlocked",
2088
+ value: function _isSessionCallBlocked() {
2089
+ return this.localStorageCache.get(SESSION_CALL_BLOCKED_CACHE_KEY);
2090
+ }
2091
+
2070
2092
  /**
2071
2093
  * Block calls to get session
2072
2094
  * @private
@@ -2076,10 +2098,8 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
2076
2098
  }, {
2077
2099
  key: "_blockSessionCall",
2078
2100
  value: function _blockSessionCall() {
2079
- if (this._enableSessionCaching) {
2080
- var SESSION_CALL_BLOCKED = true;
2081
- this.cache.set(SESSION_CALL_BLOCKED_CACHE_KEY, SESSION_CALL_BLOCKED, SESSION_CALL_BLOCKED_TTL);
2082
- }
2101
+ var SESSION_CALL_BLOCKED = true;
2102
+ this.localStorageCache.set(SESSION_CALL_BLOCKED_CACHE_KEY, SESSION_CALL_BLOCKED, SESSION_CALL_BLOCKED_TTL);
2083
2103
  }
2084
2104
 
2085
2105
  /**
@@ -2091,9 +2111,7 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
2091
2111
  }, {
2092
2112
  key: "_unblockSessionCall",
2093
2113
  value: function _unblockSessionCall() {
2094
- if (this._enableSessionCaching) {
2095
- this.cache.delete(SESSION_CALL_BLOCKED_CACHE_KEY);
2096
- }
2114
+ this.localStorageCache.delete(SESSION_CALL_BLOCKED_CACHE_KEY);
2097
2115
  }
2098
2116
 
2099
2117
  /**
@@ -2437,7 +2455,7 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
2437
2455
  break;
2438
2456
  }
2439
2457
  // Try to resolve from cache (it has a TTL)
2440
- cachedSession = _this2.cache.get(HAS_SESSION_CACHE_KEY);
2458
+ cachedSession = _this2.sessionStorageCache.get(HAS_SESSION_CACHE_KEY);
2441
2459
  if (!cachedSession) {
2442
2460
  _context.next = 4;
2443
2461
  break;
@@ -2457,7 +2475,7 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
2457
2475
  _context.t0 = _context["catch"](5);
2458
2476
  if (_context.t0 && _context.t0.code === 400 && _this2._enableSessionCaching) {
2459
2477
  expiresIn = 1000 * (_context.t0.expiresIn || 300);
2460
- _this2.cache.set(HAS_SESSION_CACHE_KEY, {
2478
+ _this2.sessionStorageCache.set(HAS_SESSION_CACHE_KEY, {
2461
2479
  error: _context.t0
2462
2480
  }, expiresIn);
2463
2481
  }
@@ -2475,11 +2493,13 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
2475
2493
  _context.next = 20;
2476
2494
  return _this2.callbackBeforeRedirect();
2477
2495
  case 20:
2478
- return _context.abrupt("return", _this2._sessionService.makeUrl(sessionData.redirectURL));
2496
+ return _context.abrupt("return", _this2._sessionService.makeUrl(sessionData.redirectURL, {
2497
+ tabId: _this2._getTabId()
2498
+ }));
2479
2499
  case 21:
2480
2500
  if (_this2._enableSessionCaching) {
2481
2501
  _expiresIn = 1000 * (sessionData.expiresIn || 300);
2482
- _this2.cache.set(HAS_SESSION_CACHE_KEY, sessionData, _expiresIn);
2502
+ _this2.sessionStorageCache.set(HAS_SESSION_CACHE_KEY, sessionData, _expiresIn);
2483
2503
  }
2484
2504
  case 22:
2485
2505
  return _context.abrupt("return", _postProcess(sessionData));
@@ -2550,7 +2570,7 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
2550
2570
  }, {
2551
2571
  key: "clearCachedUserSession",
2552
2572
  value: function clearCachedUserSession() {
2553
- this.cache.delete(HAS_SESSION_CACHE_KEY);
2573
+ this.sessionStorageCache.delete(HAS_SESSION_CACHE_KEY);
2554
2574
  }
2555
2575
 
2556
2576
  /**
@@ -2945,7 +2965,7 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
2945
2965
  _ref4$prompt = _ref4.prompt,
2946
2966
  prompt = _ref4$prompt === void 0 ? 'select_account' : _ref4$prompt;
2947
2967
  this._closePopup();
2948
- this.cache.delete(HAS_SESSION_CACHE_KEY);
2968
+ this.sessionStorageCache.delete(HAS_SESSION_CACHE_KEY);
2949
2969
  var url = this.loginUrl({
2950
2970
  state: state,
2951
2971
  acrValues: acrValues,
@@ -3018,7 +3038,7 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
3018
3038
  key: "logout",
3019
3039
  value: function logout() {
3020
3040
  var redirectUri = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.redirectUri;
3021
- this.cache.delete(HAS_SESSION_CACHE_KEY);
3041
+ this.sessionStorageCache.delete(HAS_SESSION_CACHE_KEY);
3022
3042
  this._maybeClearVarnishCookie();
3023
3043
  this.emit('logout');
3024
3044
  this.window.location.href = this.logoutUrl(redirectUri);
@@ -12011,7 +12031,7 @@ __webpack_require__.r(__webpack_exports__);
12011
12031
 
12012
12032
 
12013
12033
 
12014
- var version = '4.8.7-beta.8';
12034
+ var version = '5.0.0-beta.1';
12015
12035
  /* harmony default export */ __webpack_exports__["default"] = (version);
12016
12036
 
12017
12037
  /***/ }),