@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/identity.js CHANGED
@@ -1101,6 +1101,8 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
1101
1101
  */
1102
1102
 
1103
1103
  var HAS_SESSION_CACHE_KEY = 'hasSession-cache';
1104
+ var SESSION_CALL_BLOCKED_CACHE_KEY = 'sessionCallBlocked-cache';
1105
+ var SESSION_CALL_BLOCKED_TTL = 1000 * 60 * 5;
1104
1106
  var globalWindow = function globalWindow() {
1105
1107
  return window;
1106
1108
  };
@@ -1156,7 +1158,6 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
1156
1158
 
1157
1159
  // Internal hack: set to false to always refresh from hassession
1158
1160
  _this._enableSessionCaching = true;
1159
- _this.cache.delete("sessionFlowOngoing");
1160
1161
 
1161
1162
  // Old session
1162
1163
  _this._session = {};
@@ -1165,16 +1166,60 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
1165
1166
  _this._setBffServerUrl(env);
1166
1167
  _this._setOauthServerUrl(env);
1167
1168
  _this._setGlobalSessionServiceUrl(env);
1169
+ _this._unblockSessionCall();
1168
1170
  return _this;
1169
1171
  }
1170
1172
 
1171
1173
  /**
1172
- * Set SPiD server URL
1174
+ * Checks if getting session is blocked
1173
1175
  * @private
1174
- * @param {string} url - real URL or 'PRE' style key
1175
- * @returns {void}
1176
+ *
1177
+ * @returns {boolean|void}
1176
1178
  */
1177
1179
  _createClass(Identity, [{
1180
+ key: "_isSessionCallBlocked",
1181
+ value: function _isSessionCallBlocked() {
1182
+ if (this._enableSessionCaching) {
1183
+ return this.cache.get(SESSION_CALL_BLOCKED_CACHE_KEY);
1184
+ }
1185
+ }
1186
+
1187
+ /**
1188
+ * Block calls to get session
1189
+ * @private
1190
+ *
1191
+ * @returns {void}
1192
+ */
1193
+ }, {
1194
+ key: "_blockSessionCall",
1195
+ value: function _blockSessionCall() {
1196
+ if (this._enableSessionCaching) {
1197
+ var SESSION_CALL_BLOCKED = true;
1198
+ this.cache.set(SESSION_CALL_BLOCKED_CACHE_KEY, SESSION_CALL_BLOCKED, SESSION_CALL_BLOCKED_TTL);
1199
+ }
1200
+ }
1201
+
1202
+ /**
1203
+ * Unblocks calls to get session
1204
+ * @private
1205
+ *
1206
+ * @returns {void}
1207
+ */
1208
+ }, {
1209
+ key: "_unblockSessionCall",
1210
+ value: function _unblockSessionCall() {
1211
+ if (this._enableSessionCaching) {
1212
+ this.cache.delete(SESSION_CALL_BLOCKED_CACHE_KEY);
1213
+ }
1214
+ }
1215
+
1216
+ /**
1217
+ * Set SPiD server URL
1218
+ * @private
1219
+ * @param {string} url - real URL or 'PRE' style key
1220
+ * @returns {void}
1221
+ */
1222
+ }, {
1178
1223
  key: "_setSpidServerUrl",
1179
1224
  value: function _setSpidServerUrl(url) {
1180
1225
  Object(_validate_js__WEBPACK_IMPORTED_MODULE_55__["assert"])(Object(_validate_js__WEBPACK_IMPORTED_MODULE_55__["isStr"])(url), "url parameter is invalid: ".concat(url));
@@ -1477,8 +1522,8 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
1477
1522
  key: "hasSession",
1478
1523
  value: function hasSession() {
1479
1524
  var _this2 = this;
1480
- var checkIfSessionOngoing = this.cache.get("sessionFlowOngoing");
1481
- if (checkIfSessionOngoing) {
1525
+ var isSessionCallBlocked = this._isSessionCallBlocked();
1526
+ if (isSessionCallBlocked) {
1482
1527
  return this._session;
1483
1528
  }
1484
1529
  if (this._hasSessionInProgress) {
@@ -1500,7 +1545,7 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
1500
1545
  };
1501
1546
  var _getSession = /*#__PURE__*/function () {
1502
1547
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
1503
- var cachedSession, sessionData, expiresIn, _expiresIn, _expiresIn2;
1548
+ var cachedSession, sessionData, expiresIn, _expiresIn;
1504
1549
  return _regeneratorRuntime().wrap(function _callee$(_context) {
1505
1550
  while (1) switch (_context.prev = _context.next) {
1506
1551
  case 0:
@@ -1543,18 +1588,15 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
1543
1588
  _context.next = 21;
1544
1589
  break;
1545
1590
  }
1546
- if (_this2._enableSessionCaching) {
1547
- _expiresIn = 1000 * (sessionData.expiresIn || 300);
1548
- _this2.cache.set("sessionFlowOngoing", true, _expiresIn);
1549
- }
1591
+ _this2._blockSessionCall();
1550
1592
  _context.next = 20;
1551
1593
  return _this2.callbackBeforeRedirect();
1552
1594
  case 20:
1553
1595
  return _context.abrupt("return", _this2._sessionService.makeUrl(sessionData.redirectURL));
1554
1596
  case 21:
1555
1597
  if (_this2._enableSessionCaching) {
1556
- _expiresIn2 = 1000 * (sessionData.expiresIn || 300);
1557
- _this2.cache.set(HAS_SESSION_CACHE_KEY, sessionData, _expiresIn2);
1598
+ _expiresIn = 1000 * (sessionData.expiresIn || 300);
1599
+ _this2.cache.set(HAS_SESSION_CACHE_KEY, sessionData, _expiresIn);
1558
1600
  }
1559
1601
  case 22:
1560
1602
  return _context.abrupt("return", _postProcess(sessionData));
@@ -1570,7 +1612,7 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
1570
1612
  }();
1571
1613
  this._hasSessionInProgress = _getSession().then(function (sessionData) {
1572
1614
  _this2._hasSessionInProgress = false;
1573
- if (typeof sessionData === 'string' && Object(_validate_js__WEBPACK_IMPORTED_MODULE_55__["isUrl"])(sessionData)) {
1615
+ if (Object(_validate_js__WEBPACK_IMPORTED_MODULE_55__["isUrl"])(sessionData)) {
1574
1616
  return _this2.window.location.href = sessionData;
1575
1617
  }
1576
1618
  return sessionData;
@@ -11935,7 +11977,7 @@ __webpack_require__.r(__webpack_exports__);
11935
11977
 
11936
11978
 
11937
11979
 
11938
- var version = '4.8.7-beta.7';
11980
+ var version = '4.8.7-beta.8';
11939
11981
  /* harmony default export */ __webpack_exports__["default"] = (version);
11940
11982
 
11941
11983
  /***/ })