@schibsted/account-sdk-browser 4.8.5 → 4.8.6-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": "4.8.5",
3
+ "version": "4.8.6-beta.2",
4
4
  "description": "Schibsted account SDK for browsers",
5
5
  "main": "index.js",
6
6
  "type": "module",
package/src/identity.d.ts CHANGED
@@ -553,6 +553,11 @@ export type HasSessionSuccessResponse = {
553
553
  * - (Only for connected users)
554
554
  */
555
555
  defaultAgreementAccepted: boolean;
556
+ } | {
557
+ /**
558
+ * Used for expiring session in Safari browser to indicate redirection need
559
+ */
560
+ redirectURL: string;
556
561
  };
557
562
  export type HasSessionFailureResponse = {
558
563
  error: {
package/src/identity.js CHANGED
@@ -489,6 +489,14 @@ export class Identity extends EventEmitter {
489
489
  this._session = sessionData;
490
490
  return sessionData;
491
491
  };
492
+ const _checkRedirectionNeed = (sessionData={})=>{
493
+ const sessionDataKeys = Object.keys(sessionData);
494
+
495
+ const isRedirectNeeded = sessionDataKeys.length === 1 &&
496
+ sessionDataKeys[0] === 'redirectURL';
497
+
498
+ return isRedirectNeeded;
499
+ }
492
500
  const _getSession = async () => {
493
501
  if (this._enableSessionCaching) {
494
502
  // Try to resolve from cache (it has a TTL)
@@ -508,10 +516,23 @@ export class Identity extends EventEmitter {
508
516
  throw err;
509
517
  }
510
518
 
511
- if (sessionData && this._enableSessionCaching) {
512
- const expiresIn = 1000 * (sessionData.expiresIn || 300);
513
- this.cache.set(HAS_SESSION_CACHE_KEY, sessionData, expiresIn);
519
+ if(sessionData){
520
+ // for expiring session and safari browser do full page redirect to gain new session
521
+ if(_checkRedirectionNeed(sessionData)){
522
+ const client_sdrn = `sdrn:${NAMESPACE[this.env]}:client:${this.clientId}`;
523
+ const redirectBackUrl = this.redirectUri.substring(0 , this.redirectUri.lastIndexOf('/'));
524
+ const params = { redirect_uri: redirectBackUrl, client_sdrn: client_sdrn};
525
+ this.emit('redirectToSessionService');
526
+ this.window.location.href = this._sessionService.makeUrl(sessionData.redirectURL.substring(sessionData.redirectURL.lastIndexOf('/')), params);
527
+ return;
528
+ }
529
+
530
+ if (this._enableSessionCaching) {
531
+ const expiresIn = 1000 * (sessionData.expiresIn || 300);
532
+ this.cache.set(HAS_SESSION_CACHE_KEY, sessionData, expiresIn);
533
+ }
514
534
  }
535
+
515
536
  return _postProcess(sessionData);
516
537
  };
517
538
  this._hasSessionInProgress = _getSession()
@@ -629,6 +650,8 @@ export class Identity extends EventEmitter {
629
650
  * meaning the same user's ID will differ between merchants.
630
651
  * Additionally, this identifier is bound to the external party provided as argument.
631
652
  *
653
+ * @param {string} externalParty
654
+ * @param {string|null} optionalSuffix
632
655
  * @description This function calls {@link Identity#hasSession} internally and thus has the side
633
656
  * effect that it might perform an auto-login on the user
634
657
  * @throws {SDKError} If the `pairId` is missing in user session.
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.5';
4
+ const version = '4.8.6-beta.2';
5
5
  export default version;