@schibsted/account-sdk-browser 5.0.0 → 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",
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
@@ -36,6 +36,34 @@ export class Identity extends TinyEmitter {
36
36
  _sessionDomain: string;
37
37
  _enableSessionCaching: boolean;
38
38
  _session: {};
39
+
40
+ /**
41
+ * Read tabId from session storage
42
+ * @returns {number}
43
+ * @private
44
+ */
45
+ private _getTabId;
46
+ /**
47
+ * Checks if getting session is blocked
48
+ * @private
49
+ *
50
+ * @returns {boolean|void}
51
+ */
52
+ private _isSessionCallBlocked;
53
+ /**
54
+ * Block calls to get session
55
+ * @private
56
+ *
57
+ * @returns {void}
58
+ */
59
+ private _blockSessionCall;
60
+ /**
61
+ * Unblocks calls to get session
62
+ * @private
63
+ *
64
+ * @returns {void}
65
+ */
66
+ private _unblockSessionCall;
39
67
  /**
40
68
  * Set SPiD server URL
41
69
  * @private
package/src/identity.js CHANGED
@@ -148,6 +148,10 @@ const HAS_SESSION_CACHE_KEY = 'hasSession-cache';
148
148
  const SESSION_CALL_BLOCKED_CACHE_KEY = 'sessionCallBlocked-cache';
149
149
  const SESSION_CALL_BLOCKED_TTL = 1000 * 60 * 5;
150
150
 
151
+ const TAB_ID_KEY = 'tab-id-cache';
152
+ const TAB_ID = Math.floor(Math.random() * 100000)
153
+ const TAB_ID_TTL = 1000 * 60 * 60 * 24 * 30;
154
+
151
155
  const globalWindow = () => window;
152
156
 
153
157
  /**
@@ -207,6 +211,23 @@ export class Identity extends EventEmitter {
207
211
  this._unblockSessionCall();
208
212
  }
209
213
 
214
+ /**
215
+ * Read tabId from session storage
216
+ * @returns {number}
217
+ * @private
218
+ */
219
+ _getTabId() {
220
+ if (this._enableSessionCaching) {
221
+ const tabId = this.cache.get(TAB_ID_KEY);
222
+ if (!tabId) {
223
+ this.cache.set(TAB_ID_KEY, TAB_ID, TAB_ID_TTL);
224
+ return TAB_ID;
225
+ }
226
+
227
+ return tabId;
228
+ }
229
+ }
230
+
210
231
  /**
211
232
  * Checks if getting session is blocked
212
233
  * @private
@@ -573,7 +594,7 @@ export class Identity extends EventEmitter {
573
594
  }
574
595
  let sessionData = null;
575
596
  try {
576
- sessionData = await this._sessionService.get('/v2/session');
597
+ sessionData = await this._sessionService.get('/v2/session', {tabId: this._getTabId()});
577
598
  } catch (err) {
578
599
  if (err && err.code === 400 && this._enableSessionCaching) {
579
600
  const expiresIn = 1000 * (err.expiresIn || 300);
@@ -589,7 +610,7 @@ export class Identity extends EventEmitter {
589
610
 
590
611
  await this.callbackBeforeRedirect();
591
612
 
592
- return this._sessionService.makeUrl(sessionData.redirectURL);
613
+ return this._sessionService.makeUrl(sessionData.redirectURL, {tabId: this._getTabId()});
593
614
  }
594
615
 
595
616
  if (this._enableSessionCaching) {
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';
4
+ const version = '5.0.1';
5
5
  export default version;