@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/identity.js CHANGED
@@ -1103,6 +1103,9 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
1103
1103
  var HAS_SESSION_CACHE_KEY = 'hasSession-cache';
1104
1104
  var SESSION_CALL_BLOCKED_CACHE_KEY = 'sessionCallBlocked-cache';
1105
1105
  var SESSION_CALL_BLOCKED_TTL = 1000 * 60 * 5;
1106
+ var TAB_ID_KEY = 'tab-id-cache';
1107
+ var TAB_ID = Math.floor(Math.random() * 100000);
1108
+ var TAB_ID_TTL = 1000 * 60 * 60 * 24 * 30;
1106
1109
  var globalWindow = function globalWindow() {
1107
1110
  return window;
1108
1111
  };
@@ -1147,9 +1150,12 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
1147
1150
  _this._sessionInitiatedSent = false;
1148
1151
  _this.window = window;
1149
1152
  _this.clientId = clientId;
1150
- _this.cache = new _cache_js__WEBPACK_IMPORTED_MODULE_60__["default"](function () {
1153
+ _this.sessionStorageCache = new _cache_js__WEBPACK_IMPORTED_MODULE_60__["default"](function () {
1151
1154
  return _this.window && _this.window.sessionStorage;
1152
1155
  });
1156
+ _this.localStorageCache = new _cache_js__WEBPACK_IMPORTED_MODULE_60__["default"](function () {
1157
+ return _this.window && _this.window.localStorage;
1158
+ });
1153
1159
  _this.redirectUri = redirectUri;
1154
1160
  _this.env = env;
1155
1161
  _this.log = log;
@@ -1171,19 +1177,35 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
1171
1177
  }
1172
1178
 
1173
1179
  /**
1174
- * Checks if getting session is blocked
1180
+ * Read tabId from session storage
1181
+ * @returns {number}
1175
1182
  * @private
1176
- *
1177
- * @returns {boolean|void}
1178
1183
  */
1179
1184
  _createClass(Identity, [{
1180
- key: "_isSessionCallBlocked",
1181
- value: function _isSessionCallBlocked() {
1185
+ key: "_getTabId",
1186
+ value: function _getTabId() {
1182
1187
  if (this._enableSessionCaching) {
1183
- return this.cache.get(SESSION_CALL_BLOCKED_CACHE_KEY);
1188
+ var tabId = this.cache.get(TAB_ID_KEY);
1189
+ if (!tabId) {
1190
+ this.cache.set(TAB_ID_KEY, TAB_ID, TAB_ID_TTL);
1191
+ return TAB_ID;
1192
+ }
1193
+ return tabId;
1184
1194
  }
1185
1195
  }
1186
1196
 
1197
+ /**
1198
+ * Checks if getting session is blocked
1199
+ * @private
1200
+ *
1201
+ * @returns {boolean|void}
1202
+ */
1203
+ }, {
1204
+ key: "_isSessionCallBlocked",
1205
+ value: function _isSessionCallBlocked() {
1206
+ return this.localStorageCache.get(SESSION_CALL_BLOCKED_CACHE_KEY);
1207
+ }
1208
+
1187
1209
  /**
1188
1210
  * Block calls to get session
1189
1211
  * @private
@@ -1193,10 +1215,8 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
1193
1215
  }, {
1194
1216
  key: "_blockSessionCall",
1195
1217
  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
- }
1218
+ var SESSION_CALL_BLOCKED = true;
1219
+ this.localStorageCache.set(SESSION_CALL_BLOCKED_CACHE_KEY, SESSION_CALL_BLOCKED, SESSION_CALL_BLOCKED_TTL);
1200
1220
  }
1201
1221
 
1202
1222
  /**
@@ -1208,9 +1228,7 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
1208
1228
  }, {
1209
1229
  key: "_unblockSessionCall",
1210
1230
  value: function _unblockSessionCall() {
1211
- if (this._enableSessionCaching) {
1212
- this.cache.delete(SESSION_CALL_BLOCKED_CACHE_KEY);
1213
- }
1231
+ this.localStorageCache.delete(SESSION_CALL_BLOCKED_CACHE_KEY);
1214
1232
  }
1215
1233
 
1216
1234
  /**
@@ -1554,7 +1572,7 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
1554
1572
  break;
1555
1573
  }
1556
1574
  // Try to resolve from cache (it has a TTL)
1557
- cachedSession = _this2.cache.get(HAS_SESSION_CACHE_KEY);
1575
+ cachedSession = _this2.sessionStorageCache.get(HAS_SESSION_CACHE_KEY);
1558
1576
  if (!cachedSession) {
1559
1577
  _context.next = 4;
1560
1578
  break;
@@ -1574,7 +1592,7 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
1574
1592
  _context.t0 = _context["catch"](5);
1575
1593
  if (_context.t0 && _context.t0.code === 400 && _this2._enableSessionCaching) {
1576
1594
  expiresIn = 1000 * (_context.t0.expiresIn || 300);
1577
- _this2.cache.set(HAS_SESSION_CACHE_KEY, {
1595
+ _this2.sessionStorageCache.set(HAS_SESSION_CACHE_KEY, {
1578
1596
  error: _context.t0
1579
1597
  }, expiresIn);
1580
1598
  }
@@ -1592,11 +1610,13 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
1592
1610
  _context.next = 20;
1593
1611
  return _this2.callbackBeforeRedirect();
1594
1612
  case 20:
1595
- return _context.abrupt("return", _this2._sessionService.makeUrl(sessionData.redirectURL));
1613
+ return _context.abrupt("return", _this2._sessionService.makeUrl(sessionData.redirectURL, {
1614
+ tabId: _this2._getTabId()
1615
+ }));
1596
1616
  case 21:
1597
1617
  if (_this2._enableSessionCaching) {
1598
1618
  _expiresIn = 1000 * (sessionData.expiresIn || 300);
1599
- _this2.cache.set(HAS_SESSION_CACHE_KEY, sessionData, _expiresIn);
1619
+ _this2.sessionStorageCache.set(HAS_SESSION_CACHE_KEY, sessionData, _expiresIn);
1600
1620
  }
1601
1621
  case 22:
1602
1622
  return _context.abrupt("return", _postProcess(sessionData));
@@ -1667,7 +1687,7 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
1667
1687
  }, {
1668
1688
  key: "clearCachedUserSession",
1669
1689
  value: function clearCachedUserSession() {
1670
- this.cache.delete(HAS_SESSION_CACHE_KEY);
1690
+ this.sessionStorageCache.delete(HAS_SESSION_CACHE_KEY);
1671
1691
  }
1672
1692
 
1673
1693
  /**
@@ -2062,7 +2082,7 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
2062
2082
  _ref4$prompt = _ref4.prompt,
2063
2083
  prompt = _ref4$prompt === void 0 ? 'select_account' : _ref4$prompt;
2064
2084
  this._closePopup();
2065
- this.cache.delete(HAS_SESSION_CACHE_KEY);
2085
+ this.sessionStorageCache.delete(HAS_SESSION_CACHE_KEY);
2066
2086
  var url = this.loginUrl({
2067
2087
  state: state,
2068
2088
  acrValues: acrValues,
@@ -2135,7 +2155,7 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
2135
2155
  key: "logout",
2136
2156
  value: function logout() {
2137
2157
  var redirectUri = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.redirectUri;
2138
- this.cache.delete(HAS_SESSION_CACHE_KEY);
2158
+ this.sessionStorageCache.delete(HAS_SESSION_CACHE_KEY);
2139
2159
  this._maybeClearVarnishCookie();
2140
2160
  this.emit('logout');
2141
2161
  this.window.location.href = this.logoutUrl(redirectUri);
@@ -11977,7 +11997,7 @@ __webpack_require__.r(__webpack_exports__);
11977
11997
 
11978
11998
 
11979
11999
 
11980
- var version = '4.8.7-beta.8';
12000
+ var version = '5.0.0-beta.1';
11981
12001
  /* harmony default export */ __webpack_exports__["default"] = (version);
11982
12002
 
11983
12003
  /***/ })