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

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
@@ -1984,6 +1984,8 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
1984
1984
  */
1985
1985
 
1986
1986
  var HAS_SESSION_CACHE_KEY = 'hasSession-cache';
1987
+ var SESSION_CALL_BLOCKED_CACHE_KEY = 'sessionCallBlocked-cache';
1988
+ var SESSION_CALL_BLOCKED_TTL = 1000 * 60 * 5;
1987
1989
  var globalWindow = function globalWindow() {
1988
1990
  return window;
1989
1991
  };
@@ -2036,10 +2038,6 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
2036
2038
  _this.log = log;
2037
2039
  _this.callbackBeforeRedirect = callbackBeforeRedirect;
2038
2040
  _this._sessionDomain = sessionDomain;
2039
- if (_this._enableSessionCaching) {
2040
- var expiresIn = 1000 * 300;
2041
- _this.cache.set("sessionFlowOngoing", false, expiresIn);
2042
- }
2043
2041
 
2044
2042
  // Internal hack: set to false to always refresh from hassession
2045
2043
  _this._enableSessionCaching = true;
@@ -2051,16 +2049,60 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
2051
2049
  _this._setBffServerUrl(env);
2052
2050
  _this._setOauthServerUrl(env);
2053
2051
  _this._setGlobalSessionServiceUrl(env);
2052
+ _this._unblockSessionCall();
2054
2053
  return _this;
2055
2054
  }
2056
2055
 
2057
2056
  /**
2058
- * Set SPiD server URL
2057
+ * Checks if getting session is blocked
2059
2058
  * @private
2060
- * @param {string} url - real URL or 'PRE' style key
2061
- * @returns {void}
2059
+ *
2060
+ * @returns {boolean|void}
2062
2061
  */
2063
2062
  _createClass(Identity, [{
2063
+ key: "_isSessionCallBlocked",
2064
+ value: function _isSessionCallBlocked() {
2065
+ if (this._enableSessionCaching) {
2066
+ return this.cache.get(SESSION_CALL_BLOCKED_CACHE_KEY);
2067
+ }
2068
+ }
2069
+
2070
+ /**
2071
+ * Block calls to get session
2072
+ * @private
2073
+ *
2074
+ * @returns {void}
2075
+ */
2076
+ }, {
2077
+ key: "_blockSessionCall",
2078
+ 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
+ }
2083
+ }
2084
+
2085
+ /**
2086
+ * Unblocks calls to get session
2087
+ * @private
2088
+ *
2089
+ * @returns {void}
2090
+ */
2091
+ }, {
2092
+ key: "_unblockSessionCall",
2093
+ value: function _unblockSessionCall() {
2094
+ if (this._enableSessionCaching) {
2095
+ this.cache.delete(SESSION_CALL_BLOCKED_CACHE_KEY);
2096
+ }
2097
+ }
2098
+
2099
+ /**
2100
+ * Set SPiD server URL
2101
+ * @private
2102
+ * @param {string} url - real URL or 'PRE' style key
2103
+ * @returns {void}
2104
+ */
2105
+ }, {
2064
2106
  key: "_setSpidServerUrl",
2065
2107
  value: function _setSpidServerUrl(url) {
2066
2108
  Object(_validate_js__WEBPACK_IMPORTED_MODULE_55__["assert"])(Object(_validate_js__WEBPACK_IMPORTED_MODULE_55__["isStr"])(url), "url parameter is invalid: ".concat(url));
@@ -2363,8 +2405,8 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
2363
2405
  key: "hasSession",
2364
2406
  value: function hasSession() {
2365
2407
  var _this2 = this;
2366
- var checkIfSessionOngoing = this.cache.get("sessionFlowOngoing");
2367
- if (checkIfSessionOngoing) {
2408
+ var isSessionCallBlocked = this._isSessionCallBlocked();
2409
+ if (isSessionCallBlocked) {
2368
2410
  return this._session;
2369
2411
  }
2370
2412
  if (this._hasSessionInProgress) {
@@ -2386,7 +2428,7 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
2386
2428
  };
2387
2429
  var _getSession = /*#__PURE__*/function () {
2388
2430
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
2389
- var cachedSession, sessionData, expiresIn, _expiresIn, _expiresIn2;
2431
+ var cachedSession, sessionData, expiresIn, _expiresIn;
2390
2432
  return _regeneratorRuntime().wrap(function _callee$(_context) {
2391
2433
  while (1) switch (_context.prev = _context.next) {
2392
2434
  case 0:
@@ -2429,18 +2471,15 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
2429
2471
  _context.next = 21;
2430
2472
  break;
2431
2473
  }
2432
- if (_this2._enableSessionCaching) {
2433
- _expiresIn = 1000 * 300;
2434
- _this2.cache.set("sessionFlowOngoing", true, _expiresIn);
2435
- }
2474
+ _this2._blockSessionCall();
2436
2475
  _context.next = 20;
2437
2476
  return _this2.callbackBeforeRedirect();
2438
2477
  case 20:
2439
2478
  return _context.abrupt("return", _this2._sessionService.makeUrl(sessionData.redirectURL));
2440
2479
  case 21:
2441
2480
  if (_this2._enableSessionCaching) {
2442
- _expiresIn2 = 1000 * (sessionData.expiresIn || 300);
2443
- _this2.cache.set(HAS_SESSION_CACHE_KEY, sessionData, _expiresIn2);
2481
+ _expiresIn = 1000 * (sessionData.expiresIn || 300);
2482
+ _this2.cache.set(HAS_SESSION_CACHE_KEY, sessionData, _expiresIn);
2444
2483
  }
2445
2484
  case 22:
2446
2485
  return _context.abrupt("return", _postProcess(sessionData));
@@ -2456,7 +2495,7 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
2456
2495
  }();
2457
2496
  this._hasSessionInProgress = _getSession().then(function (sessionData) {
2458
2497
  _this2._hasSessionInProgress = false;
2459
- if (typeof sessionData === 'string' && Object(_validate_js__WEBPACK_IMPORTED_MODULE_55__["isUrl"])(sessionData)) {
2498
+ if (Object(_validate_js__WEBPACK_IMPORTED_MODULE_55__["isUrl"])(sessionData)) {
2460
2499
  return _this2.window.location.href = sessionData;
2461
2500
  }
2462
2501
  return sessionData;
@@ -11972,7 +12011,7 @@ __webpack_require__.r(__webpack_exports__);
11972
12011
 
11973
12012
 
11974
12013
 
11975
- var version = '4.8.7-beta.6';
12014
+ var version = '4.8.7-beta.8';
11976
12015
  /* harmony default export */ __webpack_exports__["default"] = (version);
11977
12016
 
11978
12017
  /***/ }),