@schibsted/account-sdk-browser 5.0.1 → 5.1.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.1",
3
+ "version": "5.1.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,7 +28,8 @@ export class Identity extends TinyEmitter {
28
28
  _sessionInitiatedSent: boolean;
29
29
  window: any;
30
30
  clientId: string;
31
- cache: any;
31
+ sessionStorageCache: any;
32
+ localStorageCache: any;
32
33
  redirectUri: string;
33
34
  env: string;
34
35
  log: Function;
package/src/identity.js CHANGED
@@ -189,7 +189,8 @@ export class Identity extends EventEmitter {
189
189
  this._sessionInitiatedSent = false;
190
190
  this.window = window;
191
191
  this.clientId = clientId;
192
- this.cache = new Cache(() => this.window && this.window.sessionStorage);
192
+ this.sessionStorageCache = new Cache(() => this.window && this.window.sessionStorage);
193
+ this.localStorageCache = new Cache(() => this.window && this.window.localStorage);
193
194
  this.redirectUri = redirectUri;
194
195
  this.env = env;
195
196
  this.log = log;
@@ -218,9 +219,9 @@ export class Identity extends EventEmitter {
218
219
  */
219
220
  _getTabId() {
220
221
  if (this._enableSessionCaching) {
221
- const tabId = this.cache.get(TAB_ID_KEY);
222
+ const tabId = this.sessionStorageCache.get(TAB_ID_KEY);
222
223
  if (!tabId) {
223
- this.cache.set(TAB_ID_KEY, TAB_ID, TAB_ID_TTL);
224
+ this.sessionStorageCache.set(TAB_ID_KEY, TAB_ID, TAB_ID_TTL);
224
225
  return TAB_ID;
225
226
  }
226
227
 
@@ -235,9 +236,7 @@ export class Identity extends EventEmitter {
235
236
  * @returns {boolean|void}
236
237
  */
237
238
  _isSessionCallBlocked(){
238
- if (this._enableSessionCaching) {
239
- return this.cache.get(SESSION_CALL_BLOCKED_CACHE_KEY);
240
- }
239
+ return this.localStorageCache.get(SESSION_CALL_BLOCKED_CACHE_KEY);
241
240
  }
242
241
 
243
242
  /**
@@ -247,15 +246,13 @@ export class Identity extends EventEmitter {
247
246
  * @returns {void}
248
247
  */
249
248
  _blockSessionCall(){
250
- if (this._enableSessionCaching) {
251
- const SESSION_CALL_BLOCKED = true;
249
+ const SESSION_CALL_BLOCKED = true;
252
250
 
253
- this.cache.set(
254
- SESSION_CALL_BLOCKED_CACHE_KEY,
255
- SESSION_CALL_BLOCKED,
256
- SESSION_CALL_BLOCKED_TTL
257
- );
258
- }
251
+ this.localStorageCache.set(
252
+ SESSION_CALL_BLOCKED_CACHE_KEY,
253
+ SESSION_CALL_BLOCKED,
254
+ SESSION_CALL_BLOCKED_TTL
255
+ );
259
256
  }
260
257
 
261
258
  /**
@@ -265,9 +262,7 @@ export class Identity extends EventEmitter {
265
262
  * @returns {void}
266
263
  */
267
264
  _unblockSessionCall(){
268
- if (this._enableSessionCaching) {
269
- this.cache.delete(SESSION_CALL_BLOCKED_CACHE_KEY);
270
- }
265
+ this.localStorageCache.delete(SESSION_CALL_BLOCKED_CACHE_KEY);
271
266
  }
272
267
 
273
268
  /**
@@ -587,18 +582,18 @@ export class Identity extends EventEmitter {
587
582
  const _getSession = async () => {
588
583
  if (this._enableSessionCaching) {
589
584
  // Try to resolve from cache (it has a TTL)
590
- let cachedSession = this.cache.get(HAS_SESSION_CACHE_KEY);
585
+ let cachedSession = this.sessionStorageCache.get(HAS_SESSION_CACHE_KEY);
591
586
  if (cachedSession) {
592
587
  return _postProcess(cachedSession);
593
588
  }
594
589
  }
595
590
  let sessionData = null;
596
591
  try {
597
- sessionData = await this._sessionService.get('/v2/session', {tabId: this._getTabId()});
592
+ sessionData = await this._sessionService.get('v2/session', {tabId: this._getTabId()});
598
593
  } catch (err) {
599
594
  if (err && err.code === 400 && this._enableSessionCaching) {
600
595
  const expiresIn = 1000 * (err.expiresIn || 300);
601
- this.cache.set(HAS_SESSION_CACHE_KEY, { error: err }, expiresIn);
596
+ this.sessionStorageCache.set(HAS_SESSION_CACHE_KEY, { error: err }, expiresIn);
602
597
  }
603
598
  throw err;
604
599
  }
@@ -615,7 +610,7 @@ export class Identity extends EventEmitter {
615
610
 
616
611
  if (this._enableSessionCaching) {
617
612
  const expiresIn = 1000 * (sessionData.expiresIn || 300);
618
- this.cache.set(HAS_SESSION_CACHE_KEY, sessionData, expiresIn);
613
+ this.sessionStorageCache.set(HAS_SESSION_CACHE_KEY, sessionData, expiresIn);
619
614
  }
620
615
  }
621
616
 
@@ -663,7 +658,7 @@ export class Identity extends EventEmitter {
663
658
  * @returns {void}
664
659
  */
665
660
  clearCachedUserSession() {
666
- this.cache.delete(HAS_SESSION_CACHE_KEY);
661
+ this.sessionStorageCache.delete(HAS_SESSION_CACHE_KEY);
667
662
  }
668
663
 
669
664
  /**
@@ -832,7 +827,7 @@ export class Identity extends EventEmitter {
832
827
  */
833
828
  async getUserContextData() {
834
829
  try {
835
- return await this._globalSessionService.get('/user-context');
830
+ return await this._globalSessionService.get('user-context');
836
831
  } catch (_) {
837
832
  return null;
838
833
  }
@@ -874,7 +869,7 @@ export class Identity extends EventEmitter {
874
869
  prompt = 'select_account'
875
870
  }) {
876
871
  this._closePopup();
877
- this.cache.delete(HAS_SESSION_CACHE_KEY);
872
+ this.sessionStorageCache.delete(HAS_SESSION_CACHE_KEY);
878
873
  const url = this.loginUrl({
879
874
  state,
880
875
  acrValues,
@@ -923,7 +918,7 @@ export class Identity extends EventEmitter {
923
918
  * @return {void}
924
919
  */
925
920
  logout(redirectUri = this.redirectUri) {
926
- this.cache.delete(HAS_SESSION_CACHE_KEY);
921
+ this.sessionStorageCache.delete(HAS_SESSION_CACHE_KEY);
927
922
  this._maybeClearVarnishCookie();
928
923
  this.emit('logout');
929
924
  this.window.location.href = this.logoutUrl(redirectUri);
@@ -969,7 +964,7 @@ export class Identity extends EventEmitter {
969
964
  teaser = arguments[6] || teaser;
970
965
  maxAge = isNaN(arguments[7]) ? maxAge : arguments[7];
971
966
  }
972
- const isValidAcrValue = (acrValue) => isStrIn(acrValue, ['password', 'otp', 'sms', 'eid-no', 'eid-se', 'eid-fi', 'eid'], true);
967
+ const isValidAcrValue = (acrValue) => isStrIn(acrValue, ['password', 'otp', 'sms', 'eid-dk', 'eid-no', 'eid-se', 'eid-fi', 'eid'], true);
973
968
  assert(!acrValues || isStrIn(acrValues, ['', 'otp-email'], true) || acrValues.split(' ').every(isValidAcrValue),
974
969
  `The acrValues parameter is not acceptable: ${acrValues}`);
975
970
  assert(isUrl(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.1';
4
+ const version = '5.1.1';
5
5
  export default version;