@schibsted/account-sdk-browser 4.8.7-beta.8 → 5.0.0-beta.1

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
@@ -1109,6 +1109,9 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
1109
1109
  var HAS_SESSION_CACHE_KEY = 'hasSession-cache';
1110
1110
  var SESSION_CALL_BLOCKED_CACHE_KEY = 'sessionCallBlocked-cache';
1111
1111
  var SESSION_CALL_BLOCKED_TTL = 1000 * 60 * 5;
1112
+ var TAB_ID_KEY = 'tab-id-cache';
1113
+ var TAB_ID = Math.floor(Math.random() * 100000);
1114
+ var TAB_ID_TTL = 1000 * 60 * 60 * 24 * 30;
1112
1115
  var globalWindow = function globalWindow() {
1113
1116
  return window;
1114
1117
  };
@@ -1153,9 +1156,12 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
1153
1156
  _this._sessionInitiatedSent = false;
1154
1157
  _this.window = window;
1155
1158
  _this.clientId = clientId;
1156
- _this.cache = new _cache_js__WEBPACK_IMPORTED_MODULE_60__["default"](function () {
1159
+ _this.sessionStorageCache = new _cache_js__WEBPACK_IMPORTED_MODULE_60__["default"](function () {
1157
1160
  return _this.window && _this.window.sessionStorage;
1158
1161
  });
1162
+ _this.localStorageCache = new _cache_js__WEBPACK_IMPORTED_MODULE_60__["default"](function () {
1163
+ return _this.window && _this.window.localStorage;
1164
+ });
1159
1165
  _this.redirectUri = redirectUri;
1160
1166
  _this.env = env;
1161
1167
  _this.log = log;
@@ -1177,19 +1183,35 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
1177
1183
  }
1178
1184
 
1179
1185
  /**
1180
- * Checks if getting session is blocked
1186
+ * Read tabId from session storage
1187
+ * @returns {number}
1181
1188
  * @private
1182
- *
1183
- * @returns {boolean|void}
1184
1189
  */
1185
1190
  _createClass(Identity, [{
1186
- key: "_isSessionCallBlocked",
1187
- value: function _isSessionCallBlocked() {
1191
+ key: "_getTabId",
1192
+ value: function _getTabId() {
1188
1193
  if (this._enableSessionCaching) {
1189
- return this.cache.get(SESSION_CALL_BLOCKED_CACHE_KEY);
1194
+ var tabId = this.cache.get(TAB_ID_KEY);
1195
+ if (!tabId) {
1196
+ this.cache.set(TAB_ID_KEY, TAB_ID, TAB_ID_TTL);
1197
+ return TAB_ID;
1198
+ }
1199
+ return tabId;
1190
1200
  }
1191
1201
  }
1192
1202
 
1203
+ /**
1204
+ * Checks if getting session is blocked
1205
+ * @private
1206
+ *
1207
+ * @returns {boolean|void}
1208
+ */
1209
+ }, {
1210
+ key: "_isSessionCallBlocked",
1211
+ value: function _isSessionCallBlocked() {
1212
+ return this.localStorageCache.get(SESSION_CALL_BLOCKED_CACHE_KEY);
1213
+ }
1214
+
1193
1215
  /**
1194
1216
  * Block calls to get session
1195
1217
  * @private
@@ -1199,10 +1221,8 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
1199
1221
  }, {
1200
1222
  key: "_blockSessionCall",
1201
1223
  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
- }
1224
+ var SESSION_CALL_BLOCKED = true;
1225
+ this.localStorageCache.set(SESSION_CALL_BLOCKED_CACHE_KEY, SESSION_CALL_BLOCKED, SESSION_CALL_BLOCKED_TTL);
1206
1226
  }
1207
1227
 
1208
1228
  /**
@@ -1214,9 +1234,7 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
1214
1234
  }, {
1215
1235
  key: "_unblockSessionCall",
1216
1236
  value: function _unblockSessionCall() {
1217
- if (this._enableSessionCaching) {
1218
- this.cache.delete(SESSION_CALL_BLOCKED_CACHE_KEY);
1219
- }
1237
+ this.localStorageCache.delete(SESSION_CALL_BLOCKED_CACHE_KEY);
1220
1238
  }
1221
1239
 
1222
1240
  /**
@@ -1560,7 +1578,7 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
1560
1578
  break;
1561
1579
  }
1562
1580
  // Try to resolve from cache (it has a TTL)
1563
- cachedSession = _this2.cache.get(HAS_SESSION_CACHE_KEY);
1581
+ cachedSession = _this2.sessionStorageCache.get(HAS_SESSION_CACHE_KEY);
1564
1582
  if (!cachedSession) {
1565
1583
  _context.next = 4;
1566
1584
  break;
@@ -1580,7 +1598,7 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
1580
1598
  _context.t0 = _context["catch"](5);
1581
1599
  if (_context.t0 && _context.t0.code === 400 && _this2._enableSessionCaching) {
1582
1600
  expiresIn = 1000 * (_context.t0.expiresIn || 300);
1583
- _this2.cache.set(HAS_SESSION_CACHE_KEY, {
1601
+ _this2.sessionStorageCache.set(HAS_SESSION_CACHE_KEY, {
1584
1602
  error: _context.t0
1585
1603
  }, expiresIn);
1586
1604
  }
@@ -1598,11 +1616,13 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
1598
1616
  _context.next = 20;
1599
1617
  return _this2.callbackBeforeRedirect();
1600
1618
  case 20:
1601
- return _context.abrupt("return", _this2._sessionService.makeUrl(sessionData.redirectURL));
1619
+ return _context.abrupt("return", _this2._sessionService.makeUrl(sessionData.redirectURL, {
1620
+ tabId: _this2._getTabId()
1621
+ }));
1602
1622
  case 21:
1603
1623
  if (_this2._enableSessionCaching) {
1604
1624
  _expiresIn = 1000 * (sessionData.expiresIn || 300);
1605
- _this2.cache.set(HAS_SESSION_CACHE_KEY, sessionData, _expiresIn);
1625
+ _this2.sessionStorageCache.set(HAS_SESSION_CACHE_KEY, sessionData, _expiresIn);
1606
1626
  }
1607
1627
  case 22:
1608
1628
  return _context.abrupt("return", _postProcess(sessionData));
@@ -1673,7 +1693,7 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
1673
1693
  }, {
1674
1694
  key: "clearCachedUserSession",
1675
1695
  value: function clearCachedUserSession() {
1676
- this.cache.delete(HAS_SESSION_CACHE_KEY);
1696
+ this.sessionStorageCache.delete(HAS_SESSION_CACHE_KEY);
1677
1697
  }
1678
1698
 
1679
1699
  /**
@@ -2068,7 +2088,7 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
2068
2088
  _ref4$prompt = _ref4.prompt,
2069
2089
  prompt = _ref4$prompt === void 0 ? 'select_account' : _ref4$prompt;
2070
2090
  this._closePopup();
2071
- this.cache.delete(HAS_SESSION_CACHE_KEY);
2091
+ this.sessionStorageCache.delete(HAS_SESSION_CACHE_KEY);
2072
2092
  var url = this.loginUrl({
2073
2093
  state: state,
2074
2094
  acrValues: acrValues,
@@ -2141,7 +2161,7 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
2141
2161
  key: "logout",
2142
2162
  value: function logout() {
2143
2163
  var redirectUri = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.redirectUri;
2144
- this.cache.delete(HAS_SESSION_CACHE_KEY);
2164
+ this.sessionStorageCache.delete(HAS_SESSION_CACHE_KEY);
2145
2165
  this._maybeClearVarnishCookie();
2146
2166
  this.emit('logout');
2147
2167
  this.window.location.href = this.logoutUrl(redirectUri);
@@ -11983,7 +12003,7 @@ __webpack_require__.r(__webpack_exports__);
11983
12003
 
11984
12004
 
11985
12005
 
11986
- var version = '4.8.7-beta.8';
12006
+ var version = '5.0.0-beta.1';
11987
12007
  /* harmony default export */ __webpack_exports__["default"] = (version);
11988
12008
 
11989
12009
  /***/ }),