@schibsted/account-sdk-browser 4.8.6-beta → 4.8.7-beta

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/identity.js CHANGED
@@ -1,4 +1,4 @@
1
- /* Copyright 2018 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
1
+ /* Copyright 2024 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
2
2
  * See LICENSE.md in the project root.
3
3
  */
4
4
 
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /* Copyright 2018 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
1
+ /* Copyright 2024 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
2
2
  * See LICENSE.md in the project root.
3
3
  */
4
4
 
package/monetization.js CHANGED
@@ -1,4 +1,4 @@
1
- /* Copyright 2018 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
1
+ /* Copyright 2024 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
2
2
  * See LICENSE.md in the project root.
3
3
  */
4
4
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@schibsted/account-sdk-browser",
3
- "version": "4.8.6-beta",
3
+ "version": "4.8.7-beta",
4
4
  "description": "Schibsted account SDK for browsers",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -9,12 +9,10 @@
9
9
  "clean": "rimraf .cache coverage dist docs",
10
10
  "docs": "rimraf docs && jsdoc -c ./jsdoc.conf.json --verbose",
11
11
  "lint": "eslint .",
12
- "pretest": "npm run lint",
12
+ "lint:fix": "eslint . --fix",
13
13
  "test": "jest",
14
- "precover": "npm run lint",
15
14
  "cover": "jest --coverage",
16
- "postcover": "codecov",
17
- "preversion": "npm test",
15
+ "preversion": "npm run lint && npm test",
18
16
  "version": "node ./scripts/genversion.js && git add src/version.js",
19
17
  "postversion": "git push && git push --tags"
20
18
  },
@@ -27,7 +25,6 @@
27
25
  "@babel/core": "^7.11.4",
28
26
  "@babel/preset-env": "^7.23.2",
29
27
  "babel-loader": "^8.1.0",
30
- "codecov": "^3.6.5",
31
28
  "core-js": "^3.6.5",
32
29
  "docdash": "git+https://github.com/torarvid/docdash.git#v0.5.0",
33
30
  "eslint": "^6.8.0",
package/payment.js CHANGED
@@ -1,4 +1,4 @@
1
- /* Copyright 2018 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
1
+ /* Copyright 2024 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
2
2
  * See LICENSE.md in the project root.
3
3
  */
4
4
 
package/src/RESTClient.js CHANGED
@@ -1,4 +1,4 @@
1
- /* Copyright 2018 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
1
+ /* Copyright 2024 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
2
2
  * See LICENSE.md in the project root.
3
3
  */
4
4
 
package/src/SDKError.js CHANGED
@@ -1,4 +1,4 @@
1
- /* Copyright 2018 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
1
+ /* Copyright 2024 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
2
2
  * See LICENSE.md in the project root.
3
3
  */
4
4
 
package/src/cache.js CHANGED
@@ -1,4 +1,4 @@
1
- /* Copyright 2018 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
1
+ /* Copyright 2024 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
2
2
  * See LICENSE.md in the project root.
3
3
  */
4
4
 
package/src/config.js CHANGED
@@ -1,4 +1,4 @@
1
- /* Copyright 2018 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
1
+ /* Copyright 2024 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
2
2
  * See LICENSE.md in the project root.
3
3
  */
4
4
 
package/src/es5/global.js CHANGED
@@ -1,4 +1,4 @@
1
- /* Copyright 2018 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
1
+ /* Copyright 2024 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
2
2
  * See LICENSE.md in the project root.
3
3
  */
4
4
 
@@ -1,4 +1,4 @@
1
- /* Copyright 2018 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
1
+ /* Copyright 2024 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
2
2
  * See LICENSE.md in the project root.
3
3
  */
4
4
 
package/src/es5/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /* Copyright 2018 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
1
+ /* Copyright 2024 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
2
2
  * See LICENSE.md in the project root.
3
3
  */
4
4
 
@@ -1,4 +1,4 @@
1
- /* Copyright 2018 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
1
+ /* Copyright 2024 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
2
2
  * See LICENSE.md in the project root.
3
3
  */
4
4
 
@@ -1,4 +1,4 @@
1
- /* Copyright 2018 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
1
+ /* Copyright 2024 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
2
2
  * See LICENSE.md in the project root.
3
3
  */
4
4
 
package/src/identity.d.ts CHANGED
@@ -13,15 +13,17 @@ export class Identity extends TinyEmitter {
13
13
  * @param {function} [options.log] - A function that receives debug log information. If not set,
14
14
  * no logging will be done
15
15
  * @param {object} [options.window] - window object
16
+ * @param {function} [options.callbackBeforeRedirect] - callback triggered before session refresh redirect happen
16
17
  * @throws {SDKError} - If any of options are invalid
17
18
  */
18
- constructor({ clientId, redirectUri, sessionDomain, env, log, window }: {
19
+ constructor({ clientId, redirectUri, sessionDomain, env, log, window, callbackBeforeRedirect }: {
19
20
  clientId: string;
20
21
  sessionDomain: string;
21
22
  redirectUri: string;
22
23
  env?: string;
23
24
  log?: Function;
24
25
  window?: any;
26
+ callbackBeforeRedirect?: Function;
25
27
  });
26
28
  _sessionInitiatedSent: boolean;
27
29
  window: any;
@@ -30,6 +32,7 @@ export class Identity extends TinyEmitter {
30
32
  redirectUri: string;
31
33
  env: string;
32
34
  log: Function;
35
+ callbackBeforeRedirect: Function;
33
36
  _sessionDomain: string;
34
37
  _enableSessionCaching: boolean;
35
38
  _session: {};
@@ -236,6 +239,8 @@ export class Identity extends TinyEmitter {
236
239
  *
237
240
  * @description This function calls {@link Identity#hasSession} internally and thus has the side
238
241
  * effect that it might perform an auto-login on the user
242
+ * @param {string} externalParty
243
+ * @param {string|null} optionalSuffix
239
244
  * @throws {SDKError} If the `pairId` is missing in user session.
240
245
  * @throws {SDKError} If the `externalParty` is not defined
241
246
  * @return {Promise<string>} The merchant- and 3rd-party-specific `externalId`
package/src/identity.js CHANGED
@@ -1,4 +1,4 @@
1
- /* Copyright 2018 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
1
+ /* Copyright 2024 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
2
2
  * See LICENSE.md in the project root.
3
3
  */
4
4
 
@@ -160,9 +160,18 @@ export class Identity extends EventEmitter {
160
160
  * @param {function} [options.log] - A function that receives debug log information. If not set,
161
161
  * no logging will be done
162
162
  * @param {object} [options.window] - window object
163
+ * @param {function} [options.callbackBeforeRedirect] - callback triggered before session refresh redirect happen
163
164
  * @throws {SDKError} - If any of options are invalid
164
165
  */
165
- constructor({ clientId, redirectUri, sessionDomain, env = 'PRE', log, window = globalWindow() }) {
166
+ constructor({
167
+ clientId,
168
+ redirectUri,
169
+ sessionDomain,
170
+ env = 'PRE',
171
+ log,
172
+ window = globalWindow(),
173
+ callbackBeforeRedirect = ()=>{}
174
+ }) {
166
175
  super();
167
176
  assert(isNonEmptyString(clientId), 'clientId parameter is required');
168
177
  assert(isObject(window), 'The reference to window is missing');
@@ -177,6 +186,7 @@ export class Identity extends EventEmitter {
177
186
  this.redirectUri = redirectUri;
178
187
  this.env = env;
179
188
  this.log = log;
189
+ this.callbackBeforeRedirect = callbackBeforeRedirect;
180
190
  this._sessionDomain = sessionDomain;
181
191
 
182
192
  // Internal hack: set to false to always refresh from hassession
@@ -365,7 +375,8 @@ export class Identity extends EventEmitter {
365
375
  expiresIn = options;
366
376
  }
367
377
  else if (typeof options == 'object') {
368
- ({ expiresIn = expiresIn, domain = domain } = options);
378
+ expiresIn = options.expiresIn || expiresIn;
379
+ domain = options.domain || domain;
369
380
  }
370
381
 
371
382
  assert(Number.isInteger(expiresIn), `'expiresIn' must be an integer`);
@@ -428,10 +439,12 @@ export class Identity extends EventEmitter {
428
439
  * @returns {void}
429
440
  */
430
441
  _clearVarnishCookie() {
442
+ const baseDomain = this._session && typeof this._session.baseDomain === 'string'
443
+ ? this._session.baseDomain
444
+ : document.domain;
445
+
431
446
  let domain = this.varnishCookieDomain ||
432
- ((this._session && typeof this._session.baseDomain === 'string')
433
- ? this._session.baseDomain
434
- : document.domain) ||
447
+ baseDomain ||
435
448
  '';
436
449
 
437
450
  document.cookie = `SP_ID=nothing; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/; domain=.${domain}`;
@@ -480,6 +493,7 @@ export class Identity extends EventEmitter {
480
493
  if (this._hasSessionInProgress) {
481
494
  return this._hasSessionInProgress;
482
495
  }
496
+
483
497
  const _postProcess = (sessionData) => {
484
498
  if (sessionData.error) {
485
499
  throw new SDKError('HasSession failed', sessionData.error);
@@ -489,18 +503,14 @@ export class Identity extends EventEmitter {
489
503
  this._session = sessionData;
490
504
  return sessionData;
491
505
  };
506
+
492
507
  const _checkRedirectionNeed = (sessionData={})=>{
493
508
  const sessionDataKeys = Object.keys(sessionData);
494
509
 
495
- const isRedirectNeeded = sessionDataKeys.length === 1 &&
510
+ return sessionDataKeys.length === 1 &&
496
511
  sessionDataKeys[0] === 'redirectURL';
497
-
498
- if(isRedirectNeeded && !isUrl(sessionData.redirectURL)){
499
- throw new SDKError('Session refresh url is not valid');
500
- }
501
-
502
- return isRedirectNeeded;
503
512
  }
513
+
504
514
  const _getSession = async () => {
505
515
  if (this._enableSessionCaching) {
506
516
  // Try to resolve from cache (it has a TTL)
@@ -511,7 +521,7 @@ export class Identity extends EventEmitter {
511
521
  }
512
522
  let sessionData = null;
513
523
  try {
514
- sessionData = await this._sessionService.get('/session');
524
+ sessionData = await this._sessionService.get('/v2/session');
515
525
  } catch (err) {
516
526
  if (err && err.code === 400 && this._enableSessionCaching) {
517
527
  const expiresIn = 1000 * (err.expiresIn || 300);
@@ -523,7 +533,10 @@ export class Identity extends EventEmitter {
523
533
  if(sessionData){
524
534
  // for expiring session and safari browser do full page redirect to gain new session
525
535
  if(_checkRedirectionNeed(sessionData)){
526
- window.location.replace(sessionData.redirectURL);
536
+ await this.callbackBeforeRedirect();
537
+
538
+ this.window.location.href = this._sessionService.makeUrl(sessionData.redirectURL, {redirect_uri: this.window.location.origin});
539
+
527
540
  return;
528
541
  }
529
542
 
@@ -1,4 +1,4 @@
1
- /* Copyright 2018 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
1
+ /* Copyright 2024 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
2
2
  * See LICENSE.md in the project root.
3
3
  */
4
4
 
package/src/object.js CHANGED
@@ -1,4 +1,4 @@
1
- /* Copyright 2018 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
1
+ /* Copyright 2024 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
2
2
  * See LICENSE.md in the project root.
3
3
  */
4
4
 
@@ -28,21 +28,21 @@ import SDKError from './SDKError.js';
28
28
  * keys for undefined values are removed.
29
29
  */
30
30
  export function cloneDefined(...sources) {
31
- const dest = {};
31
+ const result = {};
32
32
  if (!(sources && sources.length)) {
33
33
  throw new SDKError('No objects to clone');
34
34
  }
35
- sources.forEach(src => {
36
- assert(isObject(src));
37
- if (isNonEmptyObj(src)) {
38
- Object.entries(src).forEach(([key, val]) => {
39
- if (val !== undefined ) { // eslint-disable-line no-undefined
40
- dest[key] = isObject(val) ? cloneDeep(val) : val;
35
+ sources.forEach(source => {
36
+ assert(isObject(source));
37
+ if (isNonEmptyObj(source)) {
38
+ Object.entries(source).forEach(([key, value]) => {
39
+ if (typeof value !== 'undefined' ) {
40
+ result[key] = isObject(value) ? cloneDeep(value) : value;
41
41
  }
42
42
  });
43
43
  }
44
44
  });
45
- return dest;
45
+ return result;
46
46
  }
47
47
 
48
48
  /**
package/src/payment.js CHANGED
@@ -1,4 +1,4 @@
1
- /* Copyright 2018 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
1
+ /* Copyright 2024 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
2
2
  * See LICENSE.md in the project root.
3
3
  */
4
4
 
package/src/popup.js CHANGED
@@ -1,4 +1,4 @@
1
- /* Copyright 2018 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
1
+ /* Copyright 2024 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
2
2
  * See LICENSE.md in the project root.
3
3
  */
4
4
 
package/src/spidTalk.js CHANGED
@@ -1,4 +1,4 @@
1
- /* Copyright 2018 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
1
+ /* Copyright 2024 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
2
2
  * See LICENSE.md in the project root.
3
3
  */
4
4
 
package/src/url.js CHANGED
@@ -1,4 +1,4 @@
1
- /* Copyright 2018 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
1
+ /* Copyright 2024 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
2
2
  * See LICENSE.md in the project root.
3
3
  */
4
4
 
package/src/validate.js CHANGED
@@ -1,4 +1,4 @@
1
- /* Copyright 2018 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
1
+ /* Copyright 2024 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
2
2
  * See LICENSE.md in the project root.
3
3
  */
4
4
 
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.7-beta';
5
5
  export default version;