@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/index.js CHANGED
@@ -1107,6 +1107,8 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
1107
1107
  */
1108
1108
 
1109
1109
  var HAS_SESSION_CACHE_KEY = 'hasSession-cache';
1110
+ var SESSION_CALL_BLOCKED_CACHE_KEY = 'sessionCallBlocked-cache';
1111
+ var SESSION_CALL_BLOCKED_TTL = 1000 * 60 * 5;
1110
1112
  var globalWindow = function globalWindow() {
1111
1113
  return window;
1112
1114
  };
@@ -1159,10 +1161,6 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
1159
1161
  _this.log = log;
1160
1162
  _this.callbackBeforeRedirect = callbackBeforeRedirect;
1161
1163
  _this._sessionDomain = sessionDomain;
1162
- if (_this._enableSessionCaching) {
1163
- var expiresIn = 1000 * 300;
1164
- _this.cache.set("sessionFlowOngoing", false, expiresIn);
1165
- }
1166
1164
 
1167
1165
  // Internal hack: set to false to always refresh from hassession
1168
1166
  _this._enableSessionCaching = true;
@@ -1174,16 +1172,60 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
1174
1172
  _this._setBffServerUrl(env);
1175
1173
  _this._setOauthServerUrl(env);
1176
1174
  _this._setGlobalSessionServiceUrl(env);
1175
+ _this._unblockSessionCall();
1177
1176
  return _this;
1178
1177
  }
1179
1178
 
1180
1179
  /**
1181
- * Set SPiD server URL
1180
+ * Checks if getting session is blocked
1182
1181
  * @private
1183
- * @param {string} url - real URL or 'PRE' style key
1184
- * @returns {void}
1182
+ *
1183
+ * @returns {boolean|void}
1185
1184
  */
1186
1185
  _createClass(Identity, [{
1186
+ key: "_isSessionCallBlocked",
1187
+ value: function _isSessionCallBlocked() {
1188
+ if (this._enableSessionCaching) {
1189
+ return this.cache.get(SESSION_CALL_BLOCKED_CACHE_KEY);
1190
+ }
1191
+ }
1192
+
1193
+ /**
1194
+ * Block calls to get session
1195
+ * @private
1196
+ *
1197
+ * @returns {void}
1198
+ */
1199
+ }, {
1200
+ key: "_blockSessionCall",
1201
+ value: function _blockSessionCall() {
1202
+ if (this._enableSessionCaching) {
1203
+ var SESSION_CALL_BLOCKED = true;
1204
+ this.cache.set(SESSION_CALL_BLOCKED_CACHE_KEY, SESSION_CALL_BLOCKED, SESSION_CALL_BLOCKED_TTL);
1205
+ }
1206
+ }
1207
+
1208
+ /**
1209
+ * Unblocks calls to get session
1210
+ * @private
1211
+ *
1212
+ * @returns {void}
1213
+ */
1214
+ }, {
1215
+ key: "_unblockSessionCall",
1216
+ value: function _unblockSessionCall() {
1217
+ if (this._enableSessionCaching) {
1218
+ this.cache.delete(SESSION_CALL_BLOCKED_CACHE_KEY);
1219
+ }
1220
+ }
1221
+
1222
+ /**
1223
+ * Set SPiD server URL
1224
+ * @private
1225
+ * @param {string} url - real URL or 'PRE' style key
1226
+ * @returns {void}
1227
+ */
1228
+ }, {
1187
1229
  key: "_setSpidServerUrl",
1188
1230
  value: function _setSpidServerUrl(url) {
1189
1231
  Object(_validate_js__WEBPACK_IMPORTED_MODULE_55__["assert"])(Object(_validate_js__WEBPACK_IMPORTED_MODULE_55__["isStr"])(url), "url parameter is invalid: ".concat(url));
@@ -1486,8 +1528,8 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
1486
1528
  key: "hasSession",
1487
1529
  value: function hasSession() {
1488
1530
  var _this2 = this;
1489
- var checkIfSessionOngoing = this.cache.get("sessionFlowOngoing");
1490
- if (checkIfSessionOngoing) {
1531
+ var isSessionCallBlocked = this._isSessionCallBlocked();
1532
+ if (isSessionCallBlocked) {
1491
1533
  return this._session;
1492
1534
  }
1493
1535
  if (this._hasSessionInProgress) {
@@ -1509,7 +1551,7 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
1509
1551
  };
1510
1552
  var _getSession = /*#__PURE__*/function () {
1511
1553
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
1512
- var cachedSession, sessionData, expiresIn, _expiresIn, _expiresIn2;
1554
+ var cachedSession, sessionData, expiresIn, _expiresIn;
1513
1555
  return _regeneratorRuntime().wrap(function _callee$(_context) {
1514
1556
  while (1) switch (_context.prev = _context.next) {
1515
1557
  case 0:
@@ -1552,18 +1594,15 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
1552
1594
  _context.next = 21;
1553
1595
  break;
1554
1596
  }
1555
- if (_this2._enableSessionCaching) {
1556
- _expiresIn = 1000 * 300;
1557
- _this2.cache.set("sessionFlowOngoing", true, _expiresIn);
1558
- }
1597
+ _this2._blockSessionCall();
1559
1598
  _context.next = 20;
1560
1599
  return _this2.callbackBeforeRedirect();
1561
1600
  case 20:
1562
1601
  return _context.abrupt("return", _this2._sessionService.makeUrl(sessionData.redirectURL));
1563
1602
  case 21:
1564
1603
  if (_this2._enableSessionCaching) {
1565
- _expiresIn2 = 1000 * (sessionData.expiresIn || 300);
1566
- _this2.cache.set(HAS_SESSION_CACHE_KEY, sessionData, _expiresIn2);
1604
+ _expiresIn = 1000 * (sessionData.expiresIn || 300);
1605
+ _this2.cache.set(HAS_SESSION_CACHE_KEY, sessionData, _expiresIn);
1567
1606
  }
1568
1607
  case 22:
1569
1608
  return _context.abrupt("return", _postProcess(sessionData));
@@ -1579,7 +1618,7 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
1579
1618
  }();
1580
1619
  this._hasSessionInProgress = _getSession().then(function (sessionData) {
1581
1620
  _this2._hasSessionInProgress = false;
1582
- if (typeof sessionData === 'string' && Object(_validate_js__WEBPACK_IMPORTED_MODULE_55__["isUrl"])(sessionData)) {
1621
+ if (Object(_validate_js__WEBPACK_IMPORTED_MODULE_55__["isUrl"])(sessionData)) {
1583
1622
  return _this2.window.location.href = sessionData;
1584
1623
  }
1585
1624
  return sessionData;
@@ -11944,7 +11983,7 @@ __webpack_require__.r(__webpack_exports__);
11944
11983
 
11945
11984
 
11946
11985
 
11947
- var version = '4.8.7-beta.6';
11986
+ var version = '4.8.7-beta.8';
11948
11987
  /* harmony default export */ __webpack_exports__["default"] = (version);
11949
11988
 
11950
11989
  /***/ }),