@schibsted/account-sdk-browser 5.0.0 → 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/global.js +60 -45
- package/es5/global.js.map +1 -1
- package/es5/global.min.js +1 -1
- package/es5/global.min.js.map +1 -1
- package/es5/identity.js +60 -45
- package/es5/identity.js.map +1 -1
- package/es5/identity.min.js +1 -1
- package/es5/identity.min.js.map +1 -1
- package/es5/index.js +60 -45
- package/es5/index.js.map +1 -1
- package/es5/index.min.js +1 -1
- package/es5/index.min.js.map +1 -1
- package/es5/monetization.js +1 -4
- package/es5/monetization.js.map +1 -1
- package/es5/monetization.min.js +1 -1
- package/es5/monetization.min.js.map +1 -1
- package/package.json +1 -1
- package/src/cache.d.ts +0 -3
- package/src/cache.js +0 -3
- package/src/identity.d.ts +33 -7
- package/src/identity.js +61 -43
- package/src/version.js +1 -1
package/es5/index.js
CHANGED
|
@@ -988,7 +988,7 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
|
|
|
988
988
|
* `password` (will force password confirmation, even if user is already logged in), `eid`. Those values might
|
|
989
989
|
* be mixed as space-separated string. To make sure that user has authenticated with 2FA you need
|
|
990
990
|
* to verify AMR (Authentication Methods References) claim in ID token.
|
|
991
|
-
* Might also be used to ensure additional acr (sms, otp) for already logged
|
|
991
|
+
* Might also be used to ensure additional acr (sms, otp) for already logged-in users.
|
|
992
992
|
* Supported value is also 'otp-email' means one time password using email.
|
|
993
993
|
* @property {string} [scope] - The OAuth scopes for the tokens. This is a list of
|
|
994
994
|
* scopes, separated by space. If the list of scopes contains `openid`, the generated tokens
|
|
@@ -1022,7 +1022,7 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
|
|
|
1022
1022
|
* `password` (will force password confirmation, even if user is already logged in). Those values might
|
|
1023
1023
|
* be mixed as space-separated string. To make sure that user has authenticated with 2FA you need
|
|
1024
1024
|
* to verify AMR (Authentication Methods References) claim in ID token.
|
|
1025
|
-
* Might also be used to ensure additional acr (sms, otp) for already logged
|
|
1025
|
+
* Might also be used to ensure additional acr (sms, otp) for already logged-in users.
|
|
1026
1026
|
* Supported value is also 'otp-email' means one time password using email.
|
|
1027
1027
|
* @property {string} [scope] - The OAuth scopes for the tokens. This is a list of
|
|
1028
1028
|
* scopes, separated by space. If the list of scopes contains `openid`, the generated tokens
|
|
@@ -1096,7 +1096,7 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
|
|
|
1096
1096
|
|
|
1097
1097
|
/**
|
|
1098
1098
|
* @typedef {object} SimplifiedLoginData
|
|
1099
|
-
* @property {string} identifier - Deprecated: User UUID, to be
|
|
1099
|
+
* @property {string} identifier - Deprecated: User UUID, to be as `loginHint` for {@link Identity#login}
|
|
1100
1100
|
* @property {string} display_text - Human-readable user identifier
|
|
1101
1101
|
* @property {string} client_name - Client name
|
|
1102
1102
|
*/
|
|
@@ -1108,13 +1108,16 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
|
|
|
1108
1108
|
|
|
1109
1109
|
var HAS_SESSION_CACHE_KEY = 'hasSession-cache';
|
|
1110
1110
|
var SESSION_CALL_BLOCKED_CACHE_KEY = 'sessionCallBlocked-cache';
|
|
1111
|
-
var SESSION_CALL_BLOCKED_TTL = 1000 *
|
|
1111
|
+
var SESSION_CALL_BLOCKED_TTL = 1000 * 30;
|
|
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
|
};
|
|
1115
1118
|
|
|
1116
1119
|
/**
|
|
1117
|
-
* Provides Identity
|
|
1120
|
+
* Provides Identity functionality to a web page
|
|
1118
1121
|
*/
|
|
1119
1122
|
var Identity = /*#__PURE__*/function (_EventEmitter) {
|
|
1120
1123
|
_inherits(Identity, _EventEmitter);
|
|
@@ -1150,20 +1153,20 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
|
|
|
1150
1153
|
Object(_validate_js__WEBPACK_IMPORTED_MODULE_55__["assert"])(!redirectUri || Object(_validate_js__WEBPACK_IMPORTED_MODULE_55__["isUrl"])(redirectUri), 'redirectUri parameter is invalid');
|
|
1151
1154
|
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');
|
|
1152
1155
|
_spidTalk_js__WEBPACK_IMPORTED_MODULE_64__["emulate"](window);
|
|
1156
|
+
|
|
1157
|
+
// Internal hack: set as false to always refresh from hasSession
|
|
1158
|
+
_this._enableSessionCaching = true;
|
|
1153
1159
|
_this._sessionInitiatedSent = false;
|
|
1154
1160
|
_this.window = window;
|
|
1155
1161
|
_this.clientId = clientId;
|
|
1156
|
-
_this.
|
|
1157
|
-
|
|
1158
|
-
});
|
|
1162
|
+
_this.sessionStorageCache = new _cache_js__WEBPACK_IMPORTED_MODULE_60__["default"](_this.window && _this.window.sessionStorage);
|
|
1163
|
+
_this.localStorageCache = new _cache_js__WEBPACK_IMPORTED_MODULE_60__["default"](_this.window && _this.window.localStorage);
|
|
1159
1164
|
_this.redirectUri = redirectUri;
|
|
1160
1165
|
_this.env = env;
|
|
1161
1166
|
_this.log = log;
|
|
1162
1167
|
_this.callbackBeforeRedirect = callbackBeforeRedirect;
|
|
1163
1168
|
_this._sessionDomain = sessionDomain;
|
|
1164
|
-
|
|
1165
|
-
// Internal hack: set to false to always refresh from hassession
|
|
1166
|
-
_this._enableSessionCaching = true;
|
|
1169
|
+
_this._tabId = _this._getTabId();
|
|
1167
1170
|
|
|
1168
1171
|
// Old session
|
|
1169
1172
|
_this._session = {};
|
|
@@ -1172,50 +1175,61 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
|
|
|
1172
1175
|
_this._setBffServerUrl(env);
|
|
1173
1176
|
_this._setOauthServerUrl(env);
|
|
1174
1177
|
_this._setGlobalSessionServiceUrl(env);
|
|
1175
|
-
_this.
|
|
1178
|
+
_this._unblockSessionCallByTab();
|
|
1176
1179
|
return _this;
|
|
1177
1180
|
}
|
|
1178
1181
|
|
|
1179
1182
|
/**
|
|
1180
|
-
*
|
|
1183
|
+
* Read tabId from session storage if possible, otherwise save tabId to session storage and return it
|
|
1184
|
+
* @returns {number}
|
|
1181
1185
|
* @private
|
|
1182
|
-
*
|
|
1183
|
-
* @returns {boolean|void}
|
|
1184
1186
|
*/
|
|
1185
1187
|
_createClass(Identity, [{
|
|
1186
|
-
key: "
|
|
1187
|
-
value: function
|
|
1188
|
+
key: "_getTabId",
|
|
1189
|
+
value: function _getTabId() {
|
|
1188
1190
|
if (this._enableSessionCaching) {
|
|
1189
|
-
|
|
1191
|
+
var tabId = this.sessionStorageCache.get(TAB_ID_KEY);
|
|
1192
|
+
if (!tabId) {
|
|
1193
|
+
this.sessionStorageCache.set(TAB_ID_KEY, TAB_ID, TAB_ID_TTL);
|
|
1194
|
+
return TAB_ID;
|
|
1195
|
+
}
|
|
1196
|
+
return tabId;
|
|
1190
1197
|
}
|
|
1198
|
+
return TAB_ID;
|
|
1191
1199
|
}
|
|
1192
1200
|
|
|
1193
1201
|
/**
|
|
1194
|
-
*
|
|
1202
|
+
* Checks if calling GET session is blocked
|
|
1203
|
+
* @private
|
|
1204
|
+
* @returns {number|null}
|
|
1205
|
+
*/
|
|
1206
|
+
}, {
|
|
1207
|
+
key: "_isSessionCallBlocked",
|
|
1208
|
+
value: function _isSessionCallBlocked() {
|
|
1209
|
+
return this.localStorageCache.get(SESSION_CALL_BLOCKED_CACHE_KEY);
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
/**
|
|
1213
|
+
* 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
|
|
1195
1214
|
* @private
|
|
1196
|
-
*
|
|
1197
1215
|
* @returns {void}
|
|
1198
1216
|
*/
|
|
1199
1217
|
}, {
|
|
1200
1218
|
key: "_blockSessionCall",
|
|
1201
1219
|
value: function _blockSessionCall() {
|
|
1202
|
-
|
|
1203
|
-
var SESSION_CALL_BLOCKED = true;
|
|
1204
|
-
this.cache.set(SESSION_CALL_BLOCKED_CACHE_KEY, SESSION_CALL_BLOCKED, SESSION_CALL_BLOCKED_TTL);
|
|
1205
|
-
}
|
|
1220
|
+
this.localStorageCache.set(SESSION_CALL_BLOCKED_CACHE_KEY, this._tabId, SESSION_CALL_BLOCKED_TTL);
|
|
1206
1221
|
}
|
|
1207
1222
|
|
|
1208
1223
|
/**
|
|
1209
|
-
* Unblocks calls to get session
|
|
1224
|
+
* Unblocks calls to get session if the lock was put by the same tab
|
|
1210
1225
|
* @private
|
|
1211
|
-
*
|
|
1212
1226
|
* @returns {void}
|
|
1213
1227
|
*/
|
|
1214
1228
|
}, {
|
|
1215
|
-
key: "
|
|
1216
|
-
value: function
|
|
1217
|
-
if (this.
|
|
1218
|
-
this.
|
|
1229
|
+
key: "_unblockSessionCallByTab",
|
|
1230
|
+
value: function _unblockSessionCallByTab() {
|
|
1231
|
+
if (this._isSessionCallBlocked() === this._tabId) {
|
|
1232
|
+
this.localStorageCache.delete(SESSION_CALL_BLOCKED_CACHE_KEY);
|
|
1219
1233
|
}
|
|
1220
1234
|
}
|
|
1221
1235
|
|
|
@@ -1323,7 +1337,7 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
|
|
|
1323
1337
|
}
|
|
1324
1338
|
|
|
1325
1339
|
/**
|
|
1326
|
-
* Emits the relevant events based on the previous and new reply from
|
|
1340
|
+
* Emits the relevant events based on the previous and new reply from {@link Identity#hasSession}
|
|
1327
1341
|
* @private
|
|
1328
1342
|
* @param {object} previous
|
|
1329
1343
|
* @param {object} current
|
|
@@ -1407,7 +1421,7 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
|
|
|
1407
1421
|
}
|
|
1408
1422
|
|
|
1409
1423
|
/**
|
|
1410
|
-
* Set the Varnish cookie (`SP_ID`) when hasSession
|
|
1424
|
+
* Set the Varnish cookie (`SP_ID`) when {@link Identity#hasSession} is called. Note that most browsers require
|
|
1411
1425
|
* that you are on a "real domain" for this to work — so, **not** `localhost`
|
|
1412
1426
|
* @param {object} [options]
|
|
1413
1427
|
* @param {number} [options.expiresIn] Override this to set number of seconds before the varnish
|
|
@@ -1560,7 +1574,7 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
|
|
|
1560
1574
|
break;
|
|
1561
1575
|
}
|
|
1562
1576
|
// Try to resolve from cache (it has a TTL)
|
|
1563
|
-
cachedSession = _this2.
|
|
1577
|
+
cachedSession = _this2.sessionStorageCache.get(HAS_SESSION_CACHE_KEY);
|
|
1564
1578
|
if (!cachedSession) {
|
|
1565
1579
|
_context.next = 4;
|
|
1566
1580
|
break;
|
|
@@ -1570,7 +1584,9 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
|
|
|
1570
1584
|
sessionData = null;
|
|
1571
1585
|
_context.prev = 5;
|
|
1572
1586
|
_context.next = 8;
|
|
1573
|
-
return _this2._sessionService.get('/v2/session'
|
|
1587
|
+
return _this2._sessionService.get('/v2/session', {
|
|
1588
|
+
tabId: _this2._tabId
|
|
1589
|
+
});
|
|
1574
1590
|
case 8:
|
|
1575
1591
|
sessionData = _context.sent;
|
|
1576
1592
|
_context.next = 15;
|
|
@@ -1580,7 +1596,7 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
|
|
|
1580
1596
|
_context.t0 = _context["catch"](5);
|
|
1581
1597
|
if (_context.t0 && _context.t0.code === 400 && _this2._enableSessionCaching) {
|
|
1582
1598
|
expiresIn = 1000 * (_context.t0.expiresIn || 300);
|
|
1583
|
-
_this2.
|
|
1599
|
+
_this2.sessionStorageCache.set(HAS_SESSION_CACHE_KEY, {
|
|
1584
1600
|
error: _context.t0
|
|
1585
1601
|
}, expiresIn);
|
|
1586
1602
|
}
|
|
@@ -1598,11 +1614,13 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
|
|
|
1598
1614
|
_context.next = 20;
|
|
1599
1615
|
return _this2.callbackBeforeRedirect();
|
|
1600
1616
|
case 20:
|
|
1601
|
-
return _context.abrupt("return", _this2._sessionService.makeUrl(sessionData.redirectURL
|
|
1617
|
+
return _context.abrupt("return", _this2._sessionService.makeUrl(sessionData.redirectURL, {
|
|
1618
|
+
tabId: _this2._getTabId()
|
|
1619
|
+
}));
|
|
1602
1620
|
case 21:
|
|
1603
1621
|
if (_this2._enableSessionCaching) {
|
|
1604
1622
|
_expiresIn = 1000 * (sessionData.expiresIn || 300);
|
|
1605
|
-
_this2.
|
|
1623
|
+
_this2.sessionStorageCache.set(HAS_SESSION_CACHE_KEY, sessionData, _expiresIn);
|
|
1606
1624
|
}
|
|
1607
1625
|
case 22:
|
|
1608
1626
|
return _context.abrupt("return", _postProcess(sessionData));
|
|
@@ -1673,7 +1691,7 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
|
|
|
1673
1691
|
}, {
|
|
1674
1692
|
key: "clearCachedUserSession",
|
|
1675
1693
|
value: function clearCachedUserSession() {
|
|
1676
|
-
this.
|
|
1694
|
+
this.sessionStorageCache.delete(HAS_SESSION_CACHE_KEY);
|
|
1677
1695
|
}
|
|
1678
1696
|
|
|
1679
1697
|
/**
|
|
@@ -1767,7 +1785,7 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
|
|
|
1767
1785
|
* @description This function calls {@link Identity#hasSession} internally and thus has the side
|
|
1768
1786
|
* effect that it might perform an auto-login on the user
|
|
1769
1787
|
* @throws {SDKError} If the user isn't connected to the merchant
|
|
1770
|
-
* @return {
|
|
1788
|
+
* @return {number} The `userId` field (not to be confused with the `uuid`)
|
|
1771
1789
|
*/
|
|
1772
1790
|
}, {
|
|
1773
1791
|
key: "getUserId",
|
|
@@ -2068,7 +2086,7 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
|
|
|
2068
2086
|
_ref4$prompt = _ref4.prompt,
|
|
2069
2087
|
prompt = _ref4$prompt === void 0 ? 'select_account' : _ref4$prompt;
|
|
2070
2088
|
this._closePopup();
|
|
2071
|
-
this.
|
|
2089
|
+
this.sessionStorageCache.delete(HAS_SESSION_CACHE_KEY);
|
|
2072
2090
|
var url = this.loginUrl({
|
|
2073
2091
|
state: state,
|
|
2074
2092
|
acrValues: acrValues,
|
|
@@ -2141,7 +2159,7 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
|
|
|
2141
2159
|
key: "logout",
|
|
2142
2160
|
value: function logout() {
|
|
2143
2161
|
var redirectUri = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.redirectUri;
|
|
2144
|
-
this.
|
|
2162
|
+
this.sessionStorageCache.delete(HAS_SESSION_CACHE_KEY);
|
|
2145
2163
|
this._maybeClearVarnishCookie();
|
|
2146
2164
|
this.emit('logout');
|
|
2147
2165
|
this.window.location.href = this.logoutUrl(redirectUri);
|
|
@@ -10998,7 +11016,6 @@ var Cache = /*#__PURE__*/function () {
|
|
|
10998
11016
|
/**
|
|
10999
11017
|
* Get a value from cache (checks that the object has not expired)
|
|
11000
11018
|
* @param {string} key
|
|
11001
|
-
* @private
|
|
11002
11019
|
* @returns {*} - The value if it exists, otherwise null
|
|
11003
11020
|
*/
|
|
11004
11021
|
_createClass(Cache, [{
|
|
@@ -11034,7 +11051,6 @@ var Cache = /*#__PURE__*/function () {
|
|
|
11034
11051
|
* @param {string} key
|
|
11035
11052
|
* @param {*} value
|
|
11036
11053
|
* @param {Number} expiresIn - Value in milliseconds until the entry expires
|
|
11037
|
-
* @private
|
|
11038
11054
|
* @returns {void}
|
|
11039
11055
|
*/
|
|
11040
11056
|
}, {
|
|
@@ -11063,7 +11079,6 @@ var Cache = /*#__PURE__*/function () {
|
|
|
11063
11079
|
/**
|
|
11064
11080
|
* Delete a cache entry
|
|
11065
11081
|
* @param {string} key
|
|
11066
|
-
* @private
|
|
11067
11082
|
* @returns {void}
|
|
11068
11083
|
*/
|
|
11069
11084
|
}, {
|
|
@@ -11983,7 +11998,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
11983
11998
|
|
|
11984
11999
|
|
|
11985
12000
|
|
|
11986
|
-
var version = '5.0.
|
|
12001
|
+
var version = '5.0.1-beta';
|
|
11987
12002
|
/* harmony default export */ __webpack_exports__["default"] = (version);
|
|
11988
12003
|
|
|
11989
12004
|
/***/ }),
|