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

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.0-beta.2",
3
+ "version": "5.0.1",
4
4
  "description": "Schibsted account SDK for browsers",
5
5
  "main": "index.js",
6
6
  "type": "module",
package/src/identity.d.ts CHANGED
@@ -28,8 +28,7 @@ export class Identity extends TinyEmitter {
28
28
  _sessionInitiatedSent: boolean;
29
29
  window: any;
30
30
  clientId: string;
31
- sessionStorageCache: any;
32
- localStorageCache: any;
31
+ cache: any;
33
32
  redirectUri: string;
34
33
  env: string;
35
34
  log: Function;
package/src/identity.js CHANGED
@@ -189,8 +189,7 @@ export class Identity extends EventEmitter {
189
189
  this._sessionInitiatedSent = false;
190
190
  this.window = window;
191
191
  this.clientId = clientId;
192
- this.sessionStorageCache = new Cache(() => this.window && this.window.sessionStorage);
193
- this.localStorageCache = new Cache(() => this.window && this.window.localStorage);
192
+ this.cache = new Cache(() => this.window && this.window.sessionStorage);
194
193
  this.redirectUri = redirectUri;
195
194
  this.env = env;
196
195
  this.log = log;
@@ -219,9 +218,9 @@ export class Identity extends EventEmitter {
219
218
  */
220
219
  _getTabId() {
221
220
  if (this._enableSessionCaching) {
222
- const tabId = this.sessionStorageCache.get(TAB_ID_KEY);
221
+ const tabId = this.cache.get(TAB_ID_KEY);
223
222
  if (!tabId) {
224
- this.sessionStorageCache.set(TAB_ID_KEY, TAB_ID, TAB_ID_TTL);
223
+ this.cache.set(TAB_ID_KEY, TAB_ID, TAB_ID_TTL);
225
224
  return TAB_ID;
226
225
  }
227
226
 
@@ -236,7 +235,9 @@ export class Identity extends EventEmitter {
236
235
  * @returns {boolean|void}
237
236
  */
238
237
  _isSessionCallBlocked(){
239
- return this.localStorageCache.get(SESSION_CALL_BLOCKED_CACHE_KEY);
238
+ if (this._enableSessionCaching) {
239
+ return this.cache.get(SESSION_CALL_BLOCKED_CACHE_KEY);
240
+ }
240
241
  }
241
242
 
242
243
  /**
@@ -246,13 +247,15 @@ export class Identity extends EventEmitter {
246
247
  * @returns {void}
247
248
  */
248
249
  _blockSessionCall(){
249
- const SESSION_CALL_BLOCKED = true;
250
+ if (this._enableSessionCaching) {
251
+ const SESSION_CALL_BLOCKED = true;
250
252
 
251
- this.localStorageCache.set(
252
- SESSION_CALL_BLOCKED_CACHE_KEY,
253
- SESSION_CALL_BLOCKED,
254
- SESSION_CALL_BLOCKED_TTL
255
- );
253
+ this.cache.set(
254
+ SESSION_CALL_BLOCKED_CACHE_KEY,
255
+ SESSION_CALL_BLOCKED,
256
+ SESSION_CALL_BLOCKED_TTL
257
+ );
258
+ }
256
259
  }
257
260
 
258
261
  /**
@@ -262,7 +265,9 @@ export class Identity extends EventEmitter {
262
265
  * @returns {void}
263
266
  */
264
267
  _unblockSessionCall(){
265
- this.localStorageCache.delete(SESSION_CALL_BLOCKED_CACHE_KEY);
268
+ if (this._enableSessionCaching) {
269
+ this.cache.delete(SESSION_CALL_BLOCKED_CACHE_KEY);
270
+ }
266
271
  }
267
272
 
268
273
  /**
@@ -582,7 +587,7 @@ export class Identity extends EventEmitter {
582
587
  const _getSession = async () => {
583
588
  if (this._enableSessionCaching) {
584
589
  // Try to resolve from cache (it has a TTL)
585
- let cachedSession = this.sessionStorageCache.get(HAS_SESSION_CACHE_KEY);
590
+ let cachedSession = this.cache.get(HAS_SESSION_CACHE_KEY);
586
591
  if (cachedSession) {
587
592
  return _postProcess(cachedSession);
588
593
  }
@@ -593,7 +598,7 @@ export class Identity extends EventEmitter {
593
598
  } catch (err) {
594
599
  if (err && err.code === 400 && this._enableSessionCaching) {
595
600
  const expiresIn = 1000 * (err.expiresIn || 300);
596
- this.sessionStorageCache.set(HAS_SESSION_CACHE_KEY, { error: err }, expiresIn);
601
+ this.cache.set(HAS_SESSION_CACHE_KEY, { error: err }, expiresIn);
597
602
  }
598
603
  throw err;
599
604
  }
@@ -610,7 +615,7 @@ export class Identity extends EventEmitter {
610
615
 
611
616
  if (this._enableSessionCaching) {
612
617
  const expiresIn = 1000 * (sessionData.expiresIn || 300);
613
- this.sessionStorageCache.set(HAS_SESSION_CACHE_KEY, sessionData, expiresIn);
618
+ this.cache.set(HAS_SESSION_CACHE_KEY, sessionData, expiresIn);
614
619
  }
615
620
  }
616
621
 
@@ -658,7 +663,7 @@ export class Identity extends EventEmitter {
658
663
  * @returns {void}
659
664
  */
660
665
  clearCachedUserSession() {
661
- this.sessionStorageCache.delete(HAS_SESSION_CACHE_KEY);
666
+ this.cache.delete(HAS_SESSION_CACHE_KEY);
662
667
  }
663
668
 
664
669
  /**
@@ -869,7 +874,7 @@ export class Identity extends EventEmitter {
869
874
  prompt = 'select_account'
870
875
  }) {
871
876
  this._closePopup();
872
- this.sessionStorageCache.delete(HAS_SESSION_CACHE_KEY);
877
+ this.cache.delete(HAS_SESSION_CACHE_KEY);
873
878
  const url = this.loginUrl({
874
879
  state,
875
880
  acrValues,
@@ -918,7 +923,7 @@ export class Identity extends EventEmitter {
918
923
  * @return {void}
919
924
  */
920
925
  logout(redirectUri = this.redirectUri) {
921
- this.sessionStorageCache.delete(HAS_SESSION_CACHE_KEY);
926
+ this.cache.delete(HAS_SESSION_CACHE_KEY);
922
927
  this._maybeClearVarnishCookie();
923
928
  this.emit('logout');
924
929
  this.window.location.href = this.logoutUrl(redirectUri);
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.0-beta.2';
4
+ const version = '5.0.1';
5
5
  export default version;