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

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@schibsted/account-sdk-browser",
3
- "version": "4.8.7-beta.7",
3
+ "version": "4.8.7-beta.8",
4
4
  "description": "Schibsted account SDK for browsers",
5
5
  "main": "index.js",
6
6
  "type": "module",
package/src/identity.js CHANGED
@@ -145,6 +145,9 @@ import version from './version.js';
145
145
  */
146
146
 
147
147
  const HAS_SESSION_CACHE_KEY = 'hasSession-cache';
148
+ const SESSION_CALL_BLOCKED_CACHE_KEY = 'sessionCallBlocked-cache';
149
+ const SESSION_CALL_BLOCKED_TTL = 1000 * 60 * 5;
150
+
148
151
  const globalWindow = () => window;
149
152
 
150
153
  /**
@@ -191,7 +194,6 @@ export class Identity extends EventEmitter {
191
194
 
192
195
  // Internal hack: set to false to always refresh from hassession
193
196
  this._enableSessionCaching = true;
194
- this.cache.delete("sessionFlowOngoing");
195
197
 
196
198
  // Old session
197
199
  this._session = {};
@@ -201,6 +203,50 @@ export class Identity extends EventEmitter {
201
203
  this._setBffServerUrl(env);
202
204
  this._setOauthServerUrl(env);
203
205
  this._setGlobalSessionServiceUrl(env);
206
+
207
+ this._unblockSessionCall();
208
+ }
209
+
210
+ /**
211
+ * Checks if getting session is blocked
212
+ * @private
213
+ *
214
+ * @returns {boolean|void}
215
+ */
216
+ _isSessionCallBlocked(){
217
+ if (this._enableSessionCaching) {
218
+ return this.cache.get(SESSION_CALL_BLOCKED_CACHE_KEY);
219
+ }
220
+ }
221
+
222
+ /**
223
+ * Block calls to get session
224
+ * @private
225
+ *
226
+ * @returns {void}
227
+ */
228
+ _blockSessionCall(){
229
+ if (this._enableSessionCaching) {
230
+ const SESSION_CALL_BLOCKED = true;
231
+
232
+ this.cache.set(
233
+ SESSION_CALL_BLOCKED_CACHE_KEY,
234
+ SESSION_CALL_BLOCKED,
235
+ SESSION_CALL_BLOCKED_TTL
236
+ );
237
+ }
238
+ }
239
+
240
+ /**
241
+ * Unblocks calls to get session
242
+ * @private
243
+ *
244
+ * @returns {void}
245
+ */
246
+ _unblockSessionCall(){
247
+ if (this._enableSessionCaching) {
248
+ this.cache.delete(SESSION_CALL_BLOCKED_CACHE_KEY);
249
+ }
204
250
  }
205
251
 
206
252
  /**
@@ -491,9 +537,8 @@ export class Identity extends EventEmitter {
491
537
  * @return {Promise<HasSessionSuccessResponse|HasSessionFailureResponse>}
492
538
  */
493
539
  hasSession() {
494
- const checkIfSessionOngoing = this.cache.get("sessionFlowOngoing");
495
- if (checkIfSessionOngoing)
496
- {
540
+ const isSessionCallBlocked = this._isSessionCallBlocked()
541
+ if (isSessionCallBlocked) {
497
542
  return this._session;
498
543
  }
499
544
 
@@ -540,10 +585,7 @@ export class Identity extends EventEmitter {
540
585
  if (sessionData){
541
586
  // for expiring session and safari browser do full page redirect to gain new session
542
587
  if(_checkRedirectionNeed(sessionData)){
543
- if (this._enableSessionCaching) {
544
- const expiresIn = 1000 * (sessionData.expiresIn || 300);
545
- this.cache.set("sessionFlowOngoing", true, expiresIn);
546
- }
588
+ this._blockSessionCall();
547
589
 
548
590
  await this.callbackBeforeRedirect();
549
591
 
@@ -563,7 +605,7 @@ export class Identity extends EventEmitter {
563
605
  sessionData => {
564
606
  this._hasSessionInProgress = false;
565
607
 
566
- if (typeof sessionData === 'string' && isUrl(sessionData)) {
608
+ if (isUrl(sessionData)) {
567
609
  return this.window.location.href = sessionData;
568
610
  }
569
611
 
package/src/version.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // Automatically generated in 'npm version' by scripts/genversion.js
2
2
 
3
3
  'use strict'
4
- const version = '4.8.7-beta.7';
4
+ const version = '4.8.7-beta.8';
5
5
  export default version;