@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/global.js +29 -36
- 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 +29 -36
- 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 +29 -36
- 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 +9 -12
- package/src/identity.js +31 -29
- package/src/version.js +1 -1
package/package.json
CHANGED
package/src/cache.d.ts
CHANGED
|
@@ -14,7 +14,6 @@ export default class Cache {
|
|
|
14
14
|
/**
|
|
15
15
|
* Get a value from cache (checks that the object has not expired)
|
|
16
16
|
* @param {string} key
|
|
17
|
-
* @private
|
|
18
17
|
* @returns {*} - The value if it exists, otherwise null
|
|
19
18
|
*/
|
|
20
19
|
private get;
|
|
@@ -23,14 +22,12 @@ export default class Cache {
|
|
|
23
22
|
* @param {string} key
|
|
24
23
|
* @param {*} value
|
|
25
24
|
* @param {Number} expiresIn - Value in milliseconds until the entry expires
|
|
26
|
-
* @private
|
|
27
25
|
* @returns {void}
|
|
28
26
|
*/
|
|
29
27
|
private set;
|
|
30
28
|
/**
|
|
31
29
|
* Delete a cache entry
|
|
32
30
|
* @param {string} key
|
|
33
|
-
* @private
|
|
34
31
|
* @returns {void}
|
|
35
32
|
*/
|
|
36
33
|
private delete;
|
package/src/cache.js
CHANGED
|
@@ -89,7 +89,6 @@ export default class Cache {
|
|
|
89
89
|
/**
|
|
90
90
|
* Get a value from cache (checks that the object has not expired)
|
|
91
91
|
* @param {string} key
|
|
92
|
-
* @private
|
|
93
92
|
* @returns {*} - The value if it exists, otherwise null
|
|
94
93
|
*/
|
|
95
94
|
get(key) {
|
|
@@ -124,7 +123,6 @@ export default class Cache {
|
|
|
124
123
|
* @param {string} key
|
|
125
124
|
* @param {*} value
|
|
126
125
|
* @param {Number} expiresIn - Value in milliseconds until the entry expires
|
|
127
|
-
* @private
|
|
128
126
|
* @returns {void}
|
|
129
127
|
*/
|
|
130
128
|
set(key, value, expiresIn = 0) {
|
|
@@ -145,7 +143,6 @@ export default class Cache {
|
|
|
145
143
|
/**
|
|
146
144
|
* Delete a cache entry
|
|
147
145
|
* @param {string} key
|
|
148
|
-
* @private
|
|
149
146
|
* @returns {void}
|
|
150
147
|
*/
|
|
151
148
|
delete(key) {
|
package/src/identity.d.ts
CHANGED
|
@@ -45,23 +45,20 @@ export class Identity extends TinyEmitter {
|
|
|
45
45
|
*/
|
|
46
46
|
private _getTabId;
|
|
47
47
|
/**
|
|
48
|
-
* Checks if
|
|
48
|
+
* Checks if calling get session is blocked
|
|
49
49
|
* @private
|
|
50
|
-
*
|
|
51
50
|
* @returns {boolean|void}
|
|
52
51
|
*/
|
|
53
52
|
private _isSessionCallBlocked;
|
|
54
53
|
/**
|
|
55
|
-
* Block calls to get session
|
|
54
|
+
* 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
|
|
56
55
|
* @private
|
|
57
|
-
*
|
|
58
56
|
* @returns {void}
|
|
59
57
|
*/
|
|
60
58
|
private _blockSessionCall;
|
|
61
59
|
/**
|
|
62
|
-
* Unblocks calls to get session
|
|
60
|
+
* Unblocks calls to get session if the lock was put by the same tab
|
|
63
61
|
* @private
|
|
64
|
-
*
|
|
65
62
|
* @returns {void}
|
|
66
63
|
*/
|
|
67
64
|
private _unblockSessionCall;
|
|
@@ -106,7 +103,7 @@ export class Identity extends TinyEmitter {
|
|
|
106
103
|
private _setGlobalSessionServiceUrl;
|
|
107
104
|
_globalSessionService: RESTClient;
|
|
108
105
|
/**
|
|
109
|
-
* Emits the relevant events based on the previous and new reply from
|
|
106
|
+
* Emits the relevant events based on the previous and new reply from {@link Identity#hasSession}
|
|
110
107
|
* @private
|
|
111
108
|
* @param {object} previous
|
|
112
109
|
* @param {object} current
|
|
@@ -121,7 +118,7 @@ export class Identity extends TinyEmitter {
|
|
|
121
118
|
private _closePopup;
|
|
122
119
|
popup: Window;
|
|
123
120
|
/**
|
|
124
|
-
* Set the Varnish cookie (`SP_ID`) when hasSession
|
|
121
|
+
* Set the Varnish cookie (`SP_ID`) when {@link Identity#hasSession} is called. Note that most browsers require
|
|
125
122
|
* that you are on a "real domain" for this to work — so, **not** `localhost`
|
|
126
123
|
* @param {object} [options]
|
|
127
124
|
* @param {number} [options.expiresIn] Override this to set number of seconds before the varnish
|
|
@@ -224,7 +221,7 @@ export class Identity extends TinyEmitter {
|
|
|
224
221
|
* @description This function calls {@link Identity#hasSession} internally and thus has the side
|
|
225
222
|
* effect that it might perform an auto-login on the user
|
|
226
223
|
* @throws {SDKError} If the user isn't connected to the merchant
|
|
227
|
-
* @return {
|
|
224
|
+
* @return {number} The `userId` field (not to be confused with the `uuid`)
|
|
228
225
|
*/
|
|
229
226
|
getUserId(): Promise<string>;
|
|
230
227
|
/**
|
|
@@ -384,7 +381,7 @@ export type LoginOptions = {
|
|
|
384
381
|
* `password` (will force password confirmation, even if user is already logged in), `eid`. Those values might
|
|
385
382
|
* be mixed as space-separated string. To make sure that user has authenticated with 2FA you need
|
|
386
383
|
* to verify AMR (Authentication Methods References) claim in ID token.
|
|
387
|
-
* Might also be used to ensure additional acr (sms, otp, eid) for already logged
|
|
384
|
+
* Might also be used to ensure additional acr (sms, otp, eid) for already logged-in users.
|
|
388
385
|
* Supported value is also 'otp-email' means one time password using email.
|
|
389
386
|
*/
|
|
390
387
|
acrValues?: string;
|
|
@@ -453,7 +450,7 @@ export type SimplifiedLoginWidgetLoginOptions = {
|
|
|
453
450
|
* `password` (will force password confirmation, even if user is already logged in). Those values might
|
|
454
451
|
* be mixed as space-separated string. To make sure that user has authenticated with 2FA you need
|
|
455
452
|
* to verify AMR (Authentication Methods References) claim in ID token.
|
|
456
|
-
* Might also be used to ensure additional acr (sms, otp) for already logged
|
|
453
|
+
* Might also be used to ensure additional acr (sms, otp) for already logged-in users.
|
|
457
454
|
* Supported value is also 'otp-email' means one time password using email.
|
|
458
455
|
*/
|
|
459
456
|
acrValues?: string;
|
|
@@ -621,7 +618,7 @@ export type HasSessionFailureResponse = {
|
|
|
621
618
|
};
|
|
622
619
|
export type SimplifiedLoginData = {
|
|
623
620
|
/**
|
|
624
|
-
* - Deprecated: User UUID, to be
|
|
621
|
+
* - Deprecated: User UUID, to be used as `loginHint` for {@link Identity#login}
|
|
625
622
|
*/
|
|
626
623
|
identifier: string;
|
|
627
624
|
/**
|
package/src/identity.js
CHANGED
|
@@ -26,7 +26,7 @@ import version from './version.js';
|
|
|
26
26
|
* `password` (will force password confirmation, even if user is already logged in), `eid`. Those values might
|
|
27
27
|
* be mixed as space-separated string. To make sure that user has authenticated with 2FA you need
|
|
28
28
|
* to verify AMR (Authentication Methods References) claim in ID token.
|
|
29
|
-
* Might also be used to ensure additional acr (sms, otp) for already logged
|
|
29
|
+
* Might also be used to ensure additional acr (sms, otp) for already logged-in users.
|
|
30
30
|
* Supported value is also 'otp-email' means one time password using email.
|
|
31
31
|
* @property {string} [scope] - The OAuth scopes for the tokens. This is a list of
|
|
32
32
|
* scopes, separated by space. If the list of scopes contains `openid`, the generated tokens
|
|
@@ -60,7 +60,7 @@ import version from './version.js';
|
|
|
60
60
|
* `password` (will force password confirmation, even if user is already logged in). Those values might
|
|
61
61
|
* be mixed as space-separated string. To make sure that user has authenticated with 2FA you need
|
|
62
62
|
* to verify AMR (Authentication Methods References) claim in ID token.
|
|
63
|
-
* Might also be used to ensure additional acr (sms, otp) for already logged
|
|
63
|
+
* Might also be used to ensure additional acr (sms, otp) for already logged-in users.
|
|
64
64
|
* Supported value is also 'otp-email' means one time password using email.
|
|
65
65
|
* @property {string} [scope] - The OAuth scopes for the tokens. This is a list of
|
|
66
66
|
* scopes, separated by space. If the list of scopes contains `openid`, the generated tokens
|
|
@@ -134,7 +134,7 @@ import version from './version.js';
|
|
|
134
134
|
|
|
135
135
|
/**
|
|
136
136
|
* @typedef {object} SimplifiedLoginData
|
|
137
|
-
* @property {string} identifier - Deprecated: User UUID, to be
|
|
137
|
+
* @property {string} identifier - Deprecated: User UUID, to be as `loginHint` for {@link Identity#login}
|
|
138
138
|
* @property {string} display_text - Human-readable user identifier
|
|
139
139
|
* @property {string} client_name - Client name
|
|
140
140
|
*/
|
|
@@ -146,7 +146,7 @@ import version from './version.js';
|
|
|
146
146
|
|
|
147
147
|
const HAS_SESSION_CACHE_KEY = 'hasSession-cache';
|
|
148
148
|
const SESSION_CALL_BLOCKED_CACHE_KEY = 'sessionCallBlocked-cache';
|
|
149
|
-
const SESSION_CALL_BLOCKED_TTL = 1000 *
|
|
149
|
+
const SESSION_CALL_BLOCKED_TTL = 1000 * 30;
|
|
150
150
|
|
|
151
151
|
const TAB_ID_KEY = 'tab-id-cache';
|
|
152
152
|
const TAB_ID = Math.floor(Math.random() * 100000)
|
|
@@ -155,7 +155,7 @@ const TAB_ID_TTL = 1000 * 60 * 60 * 24 * 30;
|
|
|
155
155
|
const globalWindow = () => window;
|
|
156
156
|
|
|
157
157
|
/**
|
|
158
|
-
* Provides Identity
|
|
158
|
+
* Provides Identity functionality to a web page
|
|
159
159
|
*/
|
|
160
160
|
export class Identity extends EventEmitter {
|
|
161
161
|
/**
|
|
@@ -186,19 +186,21 @@ export class Identity extends EventEmitter {
|
|
|
186
186
|
assert(sessionDomain && isUrl(sessionDomain), 'sessionDomain parameter is not a valid URL');
|
|
187
187
|
|
|
188
188
|
spidTalk.emulate(window);
|
|
189
|
+
|
|
190
|
+
// Internal hack: set as false to always refresh from hasSession
|
|
191
|
+
this._enableSessionCaching = true;
|
|
192
|
+
|
|
189
193
|
this._sessionInitiatedSent = false;
|
|
190
194
|
this.window = window;
|
|
191
195
|
this.clientId = clientId;
|
|
192
|
-
this.sessionStorageCache = new Cache(
|
|
193
|
-
this.localStorageCache = new Cache(
|
|
196
|
+
this.sessionStorageCache = new Cache(this.window && this.window.sessionStorage);
|
|
197
|
+
this.localStorageCache = new Cache(this.window && this.window.localStorage);
|
|
194
198
|
this.redirectUri = redirectUri;
|
|
195
199
|
this.env = env;
|
|
196
200
|
this.log = log;
|
|
197
201
|
this.callbackBeforeRedirect = callbackBeforeRedirect;
|
|
198
202
|
this._sessionDomain = sessionDomain;
|
|
199
|
-
|
|
200
|
-
// Internal hack: set to false to always refresh from hassession
|
|
201
|
-
this._enableSessionCaching = true;
|
|
203
|
+
this._tabId = this._getTabId();
|
|
202
204
|
|
|
203
205
|
// Old session
|
|
204
206
|
this._session = {};
|
|
@@ -208,12 +210,11 @@ export class Identity extends EventEmitter {
|
|
|
208
210
|
this._setBffServerUrl(env);
|
|
209
211
|
this._setOauthServerUrl(env);
|
|
210
212
|
this._setGlobalSessionServiceUrl(env);
|
|
211
|
-
|
|
212
|
-
this._unblockSessionCall();
|
|
213
|
+
this._unblockSessionCallByTab();
|
|
213
214
|
}
|
|
214
215
|
|
|
215
216
|
/**
|
|
216
|
-
* Read tabId from session storage
|
|
217
|
+
* Read tabId from session storage if possible, otherwise save tabId to session storage and return it
|
|
217
218
|
* @returns {number}
|
|
218
219
|
* @private
|
|
219
220
|
*/
|
|
@@ -222,47 +223,47 @@ export class Identity extends EventEmitter {
|
|
|
222
223
|
const tabId = this.sessionStorageCache.get(TAB_ID_KEY);
|
|
223
224
|
if (!tabId) {
|
|
224
225
|
this.sessionStorageCache.set(TAB_ID_KEY, TAB_ID, TAB_ID_TTL);
|
|
226
|
+
|
|
225
227
|
return TAB_ID;
|
|
226
228
|
}
|
|
227
229
|
|
|
228
230
|
return tabId;
|
|
229
231
|
}
|
|
232
|
+
|
|
233
|
+
return TAB_ID;
|
|
230
234
|
}
|
|
231
235
|
|
|
232
236
|
/**
|
|
233
|
-
* Checks if
|
|
237
|
+
* Checks if calling GET session is blocked
|
|
234
238
|
* @private
|
|
235
|
-
*
|
|
236
|
-
* @returns {boolean|void}
|
|
239
|
+
* @returns {number|null}
|
|
237
240
|
*/
|
|
238
241
|
_isSessionCallBlocked(){
|
|
239
242
|
return this.localStorageCache.get(SESSION_CALL_BLOCKED_CACHE_KEY);
|
|
240
243
|
}
|
|
241
244
|
|
|
242
245
|
/**
|
|
243
|
-
* Block calls to get session
|
|
246
|
+
* 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
|
|
244
247
|
* @private
|
|
245
|
-
*
|
|
246
248
|
* @returns {void}
|
|
247
249
|
*/
|
|
248
250
|
_blockSessionCall(){
|
|
249
|
-
const SESSION_CALL_BLOCKED = true;
|
|
250
|
-
|
|
251
251
|
this.localStorageCache.set(
|
|
252
252
|
SESSION_CALL_BLOCKED_CACHE_KEY,
|
|
253
|
-
|
|
253
|
+
this._tabId,
|
|
254
254
|
SESSION_CALL_BLOCKED_TTL
|
|
255
255
|
);
|
|
256
256
|
}
|
|
257
257
|
|
|
258
258
|
/**
|
|
259
|
-
* Unblocks calls to get session
|
|
259
|
+
* Unblocks calls to get session if the lock was put by the same tab
|
|
260
260
|
* @private
|
|
261
|
-
*
|
|
262
261
|
* @returns {void}
|
|
263
262
|
*/
|
|
264
|
-
|
|
265
|
-
this.
|
|
263
|
+
_unblockSessionCallByTab() {
|
|
264
|
+
if (this._isSessionCallBlocked() === this._tabId) {
|
|
265
|
+
this.localStorageCache.delete(SESSION_CALL_BLOCKED_CACHE_KEY);
|
|
266
|
+
}
|
|
266
267
|
}
|
|
267
268
|
|
|
268
269
|
/**
|
|
@@ -343,7 +344,7 @@ export class Identity extends EventEmitter {
|
|
|
343
344
|
}
|
|
344
345
|
|
|
345
346
|
/**
|
|
346
|
-
* Emits the relevant events based on the previous and new reply from
|
|
347
|
+
* Emits the relevant events based on the previous and new reply from {@link Identity#hasSession}
|
|
347
348
|
* @private
|
|
348
349
|
* @param {object} previous
|
|
349
350
|
* @param {object} current
|
|
@@ -423,7 +424,7 @@ export class Identity extends EventEmitter {
|
|
|
423
424
|
}
|
|
424
425
|
|
|
425
426
|
/**
|
|
426
|
-
* Set the Varnish cookie (`SP_ID`) when hasSession
|
|
427
|
+
* Set the Varnish cookie (`SP_ID`) when {@link Identity#hasSession} is called. Note that most browsers require
|
|
427
428
|
* that you are on a "real domain" for this to work — so, **not** `localhost`
|
|
428
429
|
* @param {object} [options]
|
|
429
430
|
* @param {number} [options.expiresIn] Override this to set number of seconds before the varnish
|
|
@@ -587,9 +588,10 @@ export class Identity extends EventEmitter {
|
|
|
587
588
|
return _postProcess(cachedSession);
|
|
588
589
|
}
|
|
589
590
|
}
|
|
591
|
+
|
|
590
592
|
let sessionData = null;
|
|
591
593
|
try {
|
|
592
|
-
sessionData = await this._sessionService.get('/v2/session', {tabId: this.
|
|
594
|
+
sessionData = await this._sessionService.get('/v2/session', {tabId: this._tabId});
|
|
593
595
|
} catch (err) {
|
|
594
596
|
if (err && err.code === 400 && this._enableSessionCaching) {
|
|
595
597
|
const expiresIn = 1000 * (err.expiresIn || 300);
|
|
@@ -712,7 +714,7 @@ export class Identity extends EventEmitter {
|
|
|
712
714
|
* @description This function calls {@link Identity#hasSession} internally and thus has the side
|
|
713
715
|
* effect that it might perform an auto-login on the user
|
|
714
716
|
* @throws {SDKError} If the user isn't connected to the merchant
|
|
715
|
-
* @return {
|
|
717
|
+
* @return {number} The `userId` field (not to be confused with the `uuid`)
|
|
716
718
|
*/
|
|
717
719
|
async getUserId() {
|
|
718
720
|
const user = await this.hasSession();
|
package/src/version.js
CHANGED