@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/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
  };
@@ -1153,10 +1155,6 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
1153
1155
  _this.log = log;
1154
1156
  _this.callbackBeforeRedirect = callbackBeforeRedirect;
1155
1157
  _this._sessionDomain = sessionDomain;
1156
- if (_this._enableSessionCaching) {
1157
- var expiresIn = 1000 * 300;
1158
- _this.cache.set("sessionFlowOngoing", false, expiresIn);
1159
- }
1160
1158
 
1161
1159
  // Internal hack: set to false to always refresh from hassession
1162
1160
  _this._enableSessionCaching = true;
@@ -1168,16 +1166,60 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
1168
1166
  _this._setBffServerUrl(env);
1169
1167
  _this._setOauthServerUrl(env);
1170
1168
  _this._setGlobalSessionServiceUrl(env);
1169
+ _this._unblockSessionCall();
1171
1170
  return _this;
1172
1171
  }
1173
1172
 
1174
1173
  /**
1175
- * Set SPiD server URL
1174
+ * Checks if getting session is blocked
1176
1175
  * @private
1177
- * @param {string} url - real URL or 'PRE' style key
1178
- * @returns {void}
1176
+ *
1177
+ * @returns {boolean|void}
1179
1178
  */
1180
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
+ }, {
1181
1223
  key: "_setSpidServerUrl",
1182
1224
  value: function _setSpidServerUrl(url) {
1183
1225
  Object(_validate_js__WEBPACK_IMPORTED_MODULE_55__["assert"])(Object(_validate_js__WEBPACK_IMPORTED_MODULE_55__["isStr"])(url), "url parameter is invalid: ".concat(url));
@@ -1480,8 +1522,8 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
1480
1522
  key: "hasSession",
1481
1523
  value: function hasSession() {
1482
1524
  var _this2 = this;
1483
- var checkIfSessionOngoing = this.cache.get("sessionFlowOngoing");
1484
- if (checkIfSessionOngoing) {
1525
+ var isSessionCallBlocked = this._isSessionCallBlocked();
1526
+ if (isSessionCallBlocked) {
1485
1527
  return this._session;
1486
1528
  }
1487
1529
  if (this._hasSessionInProgress) {
@@ -1503,7 +1545,7 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
1503
1545
  };
1504
1546
  var _getSession = /*#__PURE__*/function () {
1505
1547
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
1506
- var cachedSession, sessionData, expiresIn, _expiresIn, _expiresIn2;
1548
+ var cachedSession, sessionData, expiresIn, _expiresIn;
1507
1549
  return _regeneratorRuntime().wrap(function _callee$(_context) {
1508
1550
  while (1) switch (_context.prev = _context.next) {
1509
1551
  case 0:
@@ -1546,18 +1588,15 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
1546
1588
  _context.next = 21;
1547
1589
  break;
1548
1590
  }
1549
- if (_this2._enableSessionCaching) {
1550
- _expiresIn = 1000 * 300;
1551
- _this2.cache.set("sessionFlowOngoing", true, _expiresIn);
1552
- }
1591
+ _this2._blockSessionCall();
1553
1592
  _context.next = 20;
1554
1593
  return _this2.callbackBeforeRedirect();
1555
1594
  case 20:
1556
1595
  return _context.abrupt("return", _this2._sessionService.makeUrl(sessionData.redirectURL));
1557
1596
  case 21:
1558
1597
  if (_this2._enableSessionCaching) {
1559
- _expiresIn2 = 1000 * (sessionData.expiresIn || 300);
1560
- _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);
1561
1600
  }
1562
1601
  case 22:
1563
1602
  return _context.abrupt("return", _postProcess(sessionData));
@@ -1573,7 +1612,7 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
1573
1612
  }();
1574
1613
  this._hasSessionInProgress = _getSession().then(function (sessionData) {
1575
1614
  _this2._hasSessionInProgress = false;
1576
- if (typeof sessionData === 'string' && Object(_validate_js__WEBPACK_IMPORTED_MODULE_55__["isUrl"])(sessionData)) {
1615
+ if (Object(_validate_js__WEBPACK_IMPORTED_MODULE_55__["isUrl"])(sessionData)) {
1577
1616
  return _this2.window.location.href = sessionData;
1578
1617
  }
1579
1618
  return sessionData;
@@ -11938,7 +11977,7 @@ __webpack_require__.r(__webpack_exports__);
11938
11977
 
11939
11978
 
11940
11979
 
11941
- var version = '4.8.7-beta.6';
11980
+ var version = '4.8.7-beta.8';
11942
11981
  /* harmony default export */ __webpack_exports__["default"] = (version);
11943
11982
 
11944
11983
  /***/ })