@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/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
  };
@@ -1162,7 +1164,6 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
1162
1164
 
1163
1165
  // Internal hack: set to false to always refresh from hassession
1164
1166
  _this._enableSessionCaching = true;
1165
- _this.cache.delete("sessionFlowOngoing");
1166
1167
 
1167
1168
  // Old session
1168
1169
  _this._session = {};
@@ -1171,16 +1172,60 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
1171
1172
  _this._setBffServerUrl(env);
1172
1173
  _this._setOauthServerUrl(env);
1173
1174
  _this._setGlobalSessionServiceUrl(env);
1175
+ _this._unblockSessionCall();
1174
1176
  return _this;
1175
1177
  }
1176
1178
 
1177
1179
  /**
1178
- * Set SPiD server URL
1180
+ * Checks if getting session is blocked
1179
1181
  * @private
1180
- * @param {string} url - real URL or 'PRE' style key
1181
- * @returns {void}
1182
+ *
1183
+ * @returns {boolean|void}
1182
1184
  */
1183
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
+ }, {
1184
1229
  key: "_setSpidServerUrl",
1185
1230
  value: function _setSpidServerUrl(url) {
1186
1231
  Object(_validate_js__WEBPACK_IMPORTED_MODULE_55__["assert"])(Object(_validate_js__WEBPACK_IMPORTED_MODULE_55__["isStr"])(url), "url parameter is invalid: ".concat(url));
@@ -1483,8 +1528,8 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
1483
1528
  key: "hasSession",
1484
1529
  value: function hasSession() {
1485
1530
  var _this2 = this;
1486
- var checkIfSessionOngoing = this.cache.get("sessionFlowOngoing");
1487
- if (checkIfSessionOngoing) {
1531
+ var isSessionCallBlocked = this._isSessionCallBlocked();
1532
+ if (isSessionCallBlocked) {
1488
1533
  return this._session;
1489
1534
  }
1490
1535
  if (this._hasSessionInProgress) {
@@ -1506,7 +1551,7 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
1506
1551
  };
1507
1552
  var _getSession = /*#__PURE__*/function () {
1508
1553
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
1509
- var cachedSession, sessionData, expiresIn, _expiresIn, _expiresIn2;
1554
+ var cachedSession, sessionData, expiresIn, _expiresIn;
1510
1555
  return _regeneratorRuntime().wrap(function _callee$(_context) {
1511
1556
  while (1) switch (_context.prev = _context.next) {
1512
1557
  case 0:
@@ -1549,18 +1594,15 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
1549
1594
  _context.next = 21;
1550
1595
  break;
1551
1596
  }
1552
- if (_this2._enableSessionCaching) {
1553
- _expiresIn = 1000 * (sessionData.expiresIn || 300);
1554
- _this2.cache.set("sessionFlowOngoing", true, _expiresIn);
1555
- }
1597
+ _this2._blockSessionCall();
1556
1598
  _context.next = 20;
1557
1599
  return _this2.callbackBeforeRedirect();
1558
1600
  case 20:
1559
1601
  return _context.abrupt("return", _this2._sessionService.makeUrl(sessionData.redirectURL));
1560
1602
  case 21:
1561
1603
  if (_this2._enableSessionCaching) {
1562
- _expiresIn2 = 1000 * (sessionData.expiresIn || 300);
1563
- _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);
1564
1606
  }
1565
1607
  case 22:
1566
1608
  return _context.abrupt("return", _postProcess(sessionData));
@@ -1576,7 +1618,7 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
1576
1618
  }();
1577
1619
  this._hasSessionInProgress = _getSession().then(function (sessionData) {
1578
1620
  _this2._hasSessionInProgress = false;
1579
- if (typeof sessionData === 'string' && Object(_validate_js__WEBPACK_IMPORTED_MODULE_55__["isUrl"])(sessionData)) {
1621
+ if (Object(_validate_js__WEBPACK_IMPORTED_MODULE_55__["isUrl"])(sessionData)) {
1580
1622
  return _this2.window.location.href = sessionData;
1581
1623
  }
1582
1624
  return sessionData;
@@ -11941,7 +11983,7 @@ __webpack_require__.r(__webpack_exports__);
11941
11983
 
11942
11984
 
11943
11985
 
11944
- var version = '4.8.7-beta.7';
11986
+ var version = '4.8.7-beta.8';
11945
11987
  /* harmony default export */ __webpack_exports__["default"] = (version);
11946
11988
 
11947
11989
  /***/ }),