@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/LICENSE.md +1 -1
- package/README.md +12 -12
- package/es5/global.js +1852 -1855
- package/es5/global.js.map +1 -1
- package/es5/global.min.js +1 -1
- package/es5/global.min.js.map +1 -1
- package/es5/identity.js +1590 -1593
- package/es5/identity.js.map +1 -1
- package/es5/identity.min.js +1 -1
- package/es5/identity.min.js.map +1 -1
- package/es5/index.js +1852 -1855
- package/es5/index.js.map +1 -1
- package/es5/index.min.js +1 -1
- package/es5/index.min.js.map +1 -1
- package/es5/monetization.js +20 -21
- package/es5/monetization.js.map +1 -1
- package/es5/monetization.min.js +1 -1
- package/es5/monetization.min.js.map +1 -1
- package/es5/payment.js +19 -20
- package/es5/payment.js.map +1 -1
- package/es5/payment.min.js.map +1 -1
- package/identity.js +1 -1
- package/index.js +1 -1
- package/monetization.js +1 -1
- package/package.json +3 -6
- package/payment.js +1 -1
- package/src/RESTClient.js +1 -1
- package/src/SDKError.js +1 -1
- package/src/cache.js +1 -1
- package/src/config.js +1 -1
- package/src/es5/global.js +1 -1
- package/src/es5/identity.js +1 -1
- package/src/es5/index.js +1 -1
- package/src/es5/monetization.js +1 -1
- package/src/es5/payment.js +1 -1
- package/src/identity.d.ts +6 -1
- package/src/identity.js +28 -15
- package/src/monetization.js +1 -1
- package/src/object.js +9 -9
- package/src/payment.js +1 -1
- package/src/popup.js +1 -1
- package/src/spidTalk.js +1 -1
- package/src/url.js +1 -1
- package/src/validate.js +1 -1
- package/src/version.js +1 -1
package/identity.js
CHANGED
package/index.js
CHANGED
package/monetization.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@schibsted/account-sdk-browser",
|
|
3
|
-
"version": "4.8.
|
|
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
|
-
"
|
|
12
|
+
"lint:fix": "eslint . --fix",
|
|
13
13
|
"test": "jest",
|
|
14
|
-
"precover": "npm run lint",
|
|
15
14
|
"cover": "jest --coverage",
|
|
16
|
-
"
|
|
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
package/src/RESTClient.js
CHANGED
package/src/SDKError.js
CHANGED
package/src/cache.js
CHANGED
package/src/config.js
CHANGED
package/src/es5/global.js
CHANGED
package/src/es5/identity.js
CHANGED
package/src/es5/index.js
CHANGED
package/src/es5/monetization.js
CHANGED
package/src/es5/payment.js
CHANGED
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
|
|
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({
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
package/src/monetization.js
CHANGED
package/src/object.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* Copyright
|
|
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
|
|
31
|
+
const result = {};
|
|
32
32
|
if (!(sources && sources.length)) {
|
|
33
33
|
throw new SDKError('No objects to clone');
|
|
34
34
|
}
|
|
35
|
-
sources.forEach(
|
|
36
|
-
assert(isObject(
|
|
37
|
-
if (isNonEmptyObj(
|
|
38
|
-
Object.entries(
|
|
39
|
-
if (
|
|
40
|
-
|
|
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
|
|
45
|
+
return result;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
/**
|
package/src/payment.js
CHANGED
package/src/popup.js
CHANGED
package/src/spidTalk.js
CHANGED
package/src/url.js
CHANGED
package/src/validate.js
CHANGED
package/src/version.js
CHANGED