@schibsted/account-sdk-browser 4.8.7-beta.7 → 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
  };
@@ -2039,7 +2041,6 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
2039
2041
 
2040
2042
  // Internal hack: set to false to always refresh from hassession
2041
2043
  _this._enableSessionCaching = true;
2042
- _this.cache.delete("sessionFlowOngoing");
2043
2044
 
2044
2045
  // Old session
2045
2046
  _this._session = {};
@@ -2048,16 +2049,60 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
2048
2049
  _this._setBffServerUrl(env);
2049
2050
  _this._setOauthServerUrl(env);
2050
2051
  _this._setGlobalSessionServiceUrl(env);
2052
+ _this._unblockSessionCall();
2051
2053
  return _this;
2052
2054
  }
2053
2055
 
2054
2056
  /**
2055
- * Set SPiD server URL
2057
+ * Checks if getting session is blocked
2056
2058
  * @private
2057
- * @param {string} url - real URL or 'PRE' style key
2058
- * @returns {void}
2059
+ *
2060
+ * @returns {boolean|void}
2059
2061
  */
2060
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
+ }, {
2061
2106
  key: "_setSpidServerUrl",
2062
2107
  value: function _setSpidServerUrl(url) {
2063
2108
  Object(_validate_js__WEBPACK_IMPORTED_MODULE_55__["assert"])(Object(_validate_js__WEBPACK_IMPORTED_MODULE_55__["isStr"])(url), "url parameter is invalid: ".concat(url));
@@ -2360,8 +2405,8 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
2360
2405
  key: "hasSession",
2361
2406
  value: function hasSession() {
2362
2407
  var _this2 = this;
2363
- var checkIfSessionOngoing = this.cache.get("sessionFlowOngoing");
2364
- if (checkIfSessionOngoing) {
2408
+ var isSessionCallBlocked = this._isSessionCallBlocked();
2409
+ if (isSessionCallBlocked) {
2365
2410
  return this._session;
2366
2411
  }
2367
2412
  if (this._hasSessionInProgress) {
@@ -2383,7 +2428,7 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
2383
2428
  };
2384
2429
  var _getSession = /*#__PURE__*/function () {
2385
2430
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
2386
- var cachedSession, sessionData, expiresIn, _expiresIn, _expiresIn2;
2431
+ var cachedSession, sessionData, expiresIn, _expiresIn;
2387
2432
  return _regeneratorRuntime().wrap(function _callee$(_context) {
2388
2433
  while (1) switch (_context.prev = _context.next) {
2389
2434
  case 0:
@@ -2426,18 +2471,15 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
2426
2471
  _context.next = 21;
2427
2472
  break;
2428
2473
  }
2429
- if (_this2._enableSessionCaching) {
2430
- _expiresIn = 1000 * (sessionData.expiresIn || 300);
2431
- _this2.cache.set("sessionFlowOngoing", true, _expiresIn);
2432
- }
2474
+ _this2._blockSessionCall();
2433
2475
  _context.next = 20;
2434
2476
  return _this2.callbackBeforeRedirect();
2435
2477
  case 20:
2436
2478
  return _context.abrupt("return", _this2._sessionService.makeUrl(sessionData.redirectURL));
2437
2479
  case 21:
2438
2480
  if (_this2._enableSessionCaching) {
2439
- _expiresIn2 = 1000 * (sessionData.expiresIn || 300);
2440
- _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);
2441
2483
  }
2442
2484
  case 22:
2443
2485
  return _context.abrupt("return", _postProcess(sessionData));
@@ -2453,7 +2495,7 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
2453
2495
  }();
2454
2496
  this._hasSessionInProgress = _getSession().then(function (sessionData) {
2455
2497
  _this2._hasSessionInProgress = false;
2456
- if (typeof sessionData === 'string' && Object(_validate_js__WEBPACK_IMPORTED_MODULE_55__["isUrl"])(sessionData)) {
2498
+ if (Object(_validate_js__WEBPACK_IMPORTED_MODULE_55__["isUrl"])(sessionData)) {
2457
2499
  return _this2.window.location.href = sessionData;
2458
2500
  }
2459
2501
  return sessionData;
@@ -11969,7 +12011,7 @@ __webpack_require__.r(__webpack_exports__);
11969
12011
 
11970
12012
 
11971
12013
 
11972
- var version = '4.8.7-beta.7';
12014
+ var version = '4.8.7-beta.8';
11973
12015
  /* harmony default export */ __webpack_exports__["default"] = (version);
11974
12016
 
11975
12017
  /***/ }),