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

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": "5.0.1-beta",
3
+ "version": "5.0.1-beta.2",
4
4
  "description": "Schibsted account SDK for browsers",
5
5
  "main": "index.js",
6
6
  "type": "module",
package/src/identity.js CHANGED
@@ -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 * 30;
149
+ const SESSION_CALL_BLOCKED_TTL = 1000 * 30; //set to 30s, the default period for a request timeout
150
150
 
151
151
  const TAB_ID_KEY = 'tab-id-cache';
152
152
  const TAB_ID = Math.floor(Math.random() * 100000)
@@ -193,8 +193,8 @@ export class Identity extends EventEmitter {
193
193
  this._sessionInitiatedSent = false;
194
194
  this.window = window;
195
195
  this.clientId = clientId;
196
- this.sessionStorageCache = new Cache(this.window && this.window.sessionStorage);
197
- this.localStorageCache = new Cache(this.window && this.window.localStorage);
196
+ this.sessionStorageCache = new Cache(() => this.window && this.window.sessionStorage);
197
+ this.localStorageCache = new Cache(() =>this.window && this.window.localStorage);
198
198
  this.redirectUri = redirectUri;
199
199
  this.env = env;
200
200
  this.log = log;
@@ -554,11 +554,6 @@ export class Identity extends EventEmitter {
554
554
  * @return {Promise<HasSessionSuccessResponse|HasSessionFailureResponse>}
555
555
  */
556
556
  hasSession() {
557
- const isSessionCallBlocked = this._isSessionCallBlocked()
558
- if (isSessionCallBlocked) {
559
- return this._session;
560
- }
561
-
562
557
  if (this._hasSessionInProgress) {
563
558
  return this._hasSessionInProgress;
564
559
  }
@@ -589,8 +584,16 @@ export class Identity extends EventEmitter {
589
584
  }
590
585
  }
591
586
 
587
+ // Prevent concurrent calls to session-service
588
+ if (this._isSessionCallBlocked()) {
589
+ // Returning data directly, without _postProcess since the data returned is the local copy
590
+ return this._session;
591
+ }
592
+
592
593
  let sessionData = null;
593
594
  try {
595
+ this._blockSessionCall();
596
+
594
597
  sessionData = await this._sessionService.get('/v2/session', {tabId: this._tabId});
595
598
  } catch (err) {
596
599
  if (err && err.code === 400 && this._enableSessionCaching) {
@@ -601,13 +604,10 @@ export class Identity extends EventEmitter {
601
604
  }
602
605
 
603
606
  if (sessionData){
604
- // for expiring session and safari browser do full page redirect to gain new session
607
+ // For expiring session and Safari browser do full page redirect to get new session
605
608
  if(_checkRedirectionNeed(sessionData)){
606
- this._blockSessionCall();
607
-
608
609
  await this.callbackBeforeRedirect();
609
-
610
- return this._sessionService.makeUrl(sessionData.redirectURL, {tabId: this._getTabId()});
610
+ this.window.location.href = this._sessionService.makeUrl(sessionData.redirectURL, {tabId: this._getTabId()});
611
611
  }
612
612
 
613
613
  if (this._enableSessionCaching) {
@@ -623,10 +623,6 @@ export class Identity extends EventEmitter {
623
623
  sessionData => {
624
624
  this._hasSessionInProgress = false;
625
625
 
626
- if (isUrl(sessionData)) {
627
- return this.window.location.href = sessionData;
628
- }
629
-
630
626
  return sessionData;
631
627
  },
632
628
  err => {
@@ -636,6 +632,7 @@ export class Identity extends EventEmitter {
636
632
  }
637
633
  );
638
634
 
635
+ this._unblockSessionCallByTab();
639
636
  return this._hasSessionInProgress;
640
637
  }
641
638
 
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 = '5.0.1-beta';
4
+ const version = '5.0.1-beta.2';
5
5
  export default version;