@schibsted/account-sdk-browser 5.0.0-beta.2 → 5.0.1-beta

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
@@ -982,7 +982,7 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
982
982
  * `password` (will force password confirmation, even if user is already logged in), `eid`. Those values might
983
983
  * be mixed as space-separated string. To make sure that user has authenticated with 2FA you need
984
984
  * to verify AMR (Authentication Methods References) claim in ID token.
985
- * Might also be used to ensure additional acr (sms, otp) for already logged in users.
985
+ * Might also be used to ensure additional acr (sms, otp) for already logged-in users.
986
986
  * Supported value is also 'otp-email' means one time password using email.
987
987
  * @property {string} [scope] - The OAuth scopes for the tokens. This is a list of
988
988
  * scopes, separated by space. If the list of scopes contains `openid`, the generated tokens
@@ -1016,7 +1016,7 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
1016
1016
  * `password` (will force password confirmation, even if user is already logged in). Those values might
1017
1017
  * be mixed as space-separated string. To make sure that user has authenticated with 2FA you need
1018
1018
  * to verify AMR (Authentication Methods References) claim in ID token.
1019
- * Might also be used to ensure additional acr (sms, otp) for already logged in users.
1019
+ * Might also be used to ensure additional acr (sms, otp) for already logged-in users.
1020
1020
  * Supported value is also 'otp-email' means one time password using email.
1021
1021
  * @property {string} [scope] - The OAuth scopes for the tokens. This is a list of
1022
1022
  * scopes, separated by space. If the list of scopes contains `openid`, the generated tokens
@@ -1090,7 +1090,7 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
1090
1090
 
1091
1091
  /**
1092
1092
  * @typedef {object} SimplifiedLoginData
1093
- * @property {string} identifier - Deprecated: User UUID, to be be used as `loginHint` for {@link Identity#login}
1093
+ * @property {string} identifier - Deprecated: User UUID, to be as `loginHint` for {@link Identity#login}
1094
1094
  * @property {string} display_text - Human-readable user identifier
1095
1095
  * @property {string} client_name - Client name
1096
1096
  */
@@ -1102,7 +1102,7 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
1102
1102
 
1103
1103
  var HAS_SESSION_CACHE_KEY = 'hasSession-cache';
1104
1104
  var SESSION_CALL_BLOCKED_CACHE_KEY = 'sessionCallBlocked-cache';
1105
- var SESSION_CALL_BLOCKED_TTL = 1000 * 60 * 5;
1105
+ var SESSION_CALL_BLOCKED_TTL = 1000 * 30;
1106
1106
  var TAB_ID_KEY = 'tab-id-cache';
1107
1107
  var TAB_ID = Math.floor(Math.random() * 100000);
1108
1108
  var TAB_ID_TTL = 1000 * 60 * 60 * 24 * 30;
@@ -1111,7 +1111,7 @@ var globalWindow = function globalWindow() {
1111
1111
  };
1112
1112
 
1113
1113
  /**
1114
- * Provides Identity functionalty to a web page
1114
+ * Provides Identity functionality to a web page
1115
1115
  */
1116
1116
  var Identity = /*#__PURE__*/function (_EventEmitter) {
1117
1117
  _inherits(Identity, _EventEmitter);
@@ -1147,23 +1147,20 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
1147
1147
  Object(_validate_js__WEBPACK_IMPORTED_MODULE_55__["assert"])(!redirectUri || Object(_validate_js__WEBPACK_IMPORTED_MODULE_55__["isUrl"])(redirectUri), 'redirectUri parameter is invalid');
1148
1148
  Object(_validate_js__WEBPACK_IMPORTED_MODULE_55__["assert"])(sessionDomain && Object(_validate_js__WEBPACK_IMPORTED_MODULE_55__["isUrl"])(sessionDomain), 'sessionDomain parameter is not a valid URL');
1149
1149
  _spidTalk_js__WEBPACK_IMPORTED_MODULE_64__["emulate"](window);
1150
+
1151
+ // Internal hack: set as false to always refresh from hasSession
1152
+ _this._enableSessionCaching = true;
1150
1153
  _this._sessionInitiatedSent = false;
1151
1154
  _this.window = window;
1152
1155
  _this.clientId = clientId;
1153
- _this.sessionStorageCache = new _cache_js__WEBPACK_IMPORTED_MODULE_60__["default"](function () {
1154
- return _this.window && _this.window.sessionStorage;
1155
- });
1156
- _this.localStorageCache = new _cache_js__WEBPACK_IMPORTED_MODULE_60__["default"](function () {
1157
- return _this.window && _this.window.localStorage;
1158
- });
1156
+ _this.sessionStorageCache = new _cache_js__WEBPACK_IMPORTED_MODULE_60__["default"](_this.window && _this.window.sessionStorage);
1157
+ _this.localStorageCache = new _cache_js__WEBPACK_IMPORTED_MODULE_60__["default"](_this.window && _this.window.localStorage);
1159
1158
  _this.redirectUri = redirectUri;
1160
1159
  _this.env = env;
1161
1160
  _this.log = log;
1162
1161
  _this.callbackBeforeRedirect = callbackBeforeRedirect;
1163
1162
  _this._sessionDomain = sessionDomain;
1164
-
1165
- // Internal hack: set to false to always refresh from hassession
1166
- _this._enableSessionCaching = true;
1163
+ _this._tabId = _this._getTabId();
1167
1164
 
1168
1165
  // Old session
1169
1166
  _this._session = {};
@@ -1172,12 +1169,12 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
1172
1169
  _this._setBffServerUrl(env);
1173
1170
  _this._setOauthServerUrl(env);
1174
1171
  _this._setGlobalSessionServiceUrl(env);
1175
- _this._unblockSessionCall();
1172
+ _this._unblockSessionCallByTab();
1176
1173
  return _this;
1177
1174
  }
1178
1175
 
1179
1176
  /**
1180
- * Read tabId from session storage
1177
+ * Read tabId from session storage if possible, otherwise save tabId to session storage and return it
1181
1178
  * @returns {number}
1182
1179
  * @private
1183
1180
  */
@@ -1192,13 +1189,13 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
1192
1189
  }
1193
1190
  return tabId;
1194
1191
  }
1192
+ return TAB_ID;
1195
1193
  }
1196
1194
 
1197
1195
  /**
1198
- * Checks if getting session is blocked
1196
+ * Checks if calling GET session is blocked
1199
1197
  * @private
1200
- *
1201
- * @returns {boolean|void}
1198
+ * @returns {number|null}
1202
1199
  */
1203
1200
  }, {
1204
1201
  key: "_isSessionCallBlocked",
@@ -1207,28 +1204,27 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
1207
1204
  }
1208
1205
 
1209
1206
  /**
1210
- * Block calls to get session
1207
+ * Block calls to get session. This is done to prevent concurrent calls which can log user out if session is refreshed by one of them
1211
1208
  * @private
1212
- *
1213
1209
  * @returns {void}
1214
1210
  */
1215
1211
  }, {
1216
1212
  key: "_blockSessionCall",
1217
1213
  value: function _blockSessionCall() {
1218
- var SESSION_CALL_BLOCKED = true;
1219
- this.localStorageCache.set(SESSION_CALL_BLOCKED_CACHE_KEY, SESSION_CALL_BLOCKED, SESSION_CALL_BLOCKED_TTL);
1214
+ this.localStorageCache.set(SESSION_CALL_BLOCKED_CACHE_KEY, this._tabId, SESSION_CALL_BLOCKED_TTL);
1220
1215
  }
1221
1216
 
1222
1217
  /**
1223
- * Unblocks calls to get session
1218
+ * Unblocks calls to get session if the lock was put by the same tab
1224
1219
  * @private
1225
- *
1226
1220
  * @returns {void}
1227
1221
  */
1228
1222
  }, {
1229
- key: "_unblockSessionCall",
1230
- value: function _unblockSessionCall() {
1231
- this.localStorageCache.delete(SESSION_CALL_BLOCKED_CACHE_KEY);
1223
+ key: "_unblockSessionCallByTab",
1224
+ value: function _unblockSessionCallByTab() {
1225
+ if (this._isSessionCallBlocked() === this._tabId) {
1226
+ this.localStorageCache.delete(SESSION_CALL_BLOCKED_CACHE_KEY);
1227
+ }
1232
1228
  }
1233
1229
 
1234
1230
  /**
@@ -1335,7 +1331,7 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
1335
1331
  }
1336
1332
 
1337
1333
  /**
1338
- * Emits the relevant events based on the previous and new reply from hassession
1334
+ * Emits the relevant events based on the previous and new reply from {@link Identity#hasSession}
1339
1335
  * @private
1340
1336
  * @param {object} previous
1341
1337
  * @param {object} current
@@ -1419,7 +1415,7 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
1419
1415
  }
1420
1416
 
1421
1417
  /**
1422
- * Set the Varnish cookie (`SP_ID`) when hasSession() is called. Note that most browsers require
1418
+ * Set the Varnish cookie (`SP_ID`) when {@link Identity#hasSession} is called. Note that most browsers require
1423
1419
  * that you are on a "real domain" for this to work — so, **not** `localhost`
1424
1420
  * @param {object} [options]
1425
1421
  * @param {number} [options.expiresIn] Override this to set number of seconds before the varnish
@@ -1583,7 +1579,7 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
1583
1579
  _context.prev = 5;
1584
1580
  _context.next = 8;
1585
1581
  return _this2._sessionService.get('/v2/session', {
1586
- tabId: _this2._getTabId()
1582
+ tabId: _this2._tabId
1587
1583
  });
1588
1584
  case 8:
1589
1585
  sessionData = _context.sent;
@@ -1783,7 +1779,7 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
1783
1779
  * @description This function calls {@link Identity#hasSession} internally and thus has the side
1784
1780
  * effect that it might perform an auto-login on the user
1785
1781
  * @throws {SDKError} If the user isn't connected to the merchant
1786
- * @return {Promise<string>} The `userId` field (not to be confused with the `uuid`)
1782
+ * @return {number} The `userId` field (not to be confused with the `uuid`)
1787
1783
  */
1788
1784
  }, {
1789
1785
  key: "getUserId",
@@ -11014,7 +11010,6 @@ var Cache = /*#__PURE__*/function () {
11014
11010
  /**
11015
11011
  * Get a value from cache (checks that the object has not expired)
11016
11012
  * @param {string} key
11017
- * @private
11018
11013
  * @returns {*} - The value if it exists, otherwise null
11019
11014
  */
11020
11015
  _createClass(Cache, [{
@@ -11050,7 +11045,6 @@ var Cache = /*#__PURE__*/function () {
11050
11045
  * @param {string} key
11051
11046
  * @param {*} value
11052
11047
  * @param {Number} expiresIn - Value in milliseconds until the entry expires
11053
- * @private
11054
11048
  * @returns {void}
11055
11049
  */
11056
11050
  }, {
@@ -11079,7 +11073,6 @@ var Cache = /*#__PURE__*/function () {
11079
11073
  /**
11080
11074
  * Delete a cache entry
11081
11075
  * @param {string} key
11082
- * @private
11083
11076
  * @returns {void}
11084
11077
  */
11085
11078
  }, {
@@ -11999,7 +11992,7 @@ __webpack_require__.r(__webpack_exports__);
11999
11992
 
12000
11993
 
12001
11994
 
12002
- var version = '5.0.0-beta.2';
11995
+ var version = '5.0.1-beta';
12003
11996
  /* harmony default export */ __webpack_exports__["default"] = (version);
12004
11997
 
12005
11998
  /***/ })