@schibsted/account-sdk-browser 5.2.3 → 5.2.6
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 +79 -59
- package/es5/global.js +127 -60
- 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 +34 -1
- 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 +127 -60
- 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 +615 -554
- 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 +33 -0
- package/es5/payment.js.map +1 -1
- package/es5/payment.min.js +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 +1 -1
- package/payment.js +1 -1
- package/src/global-registry.js +20 -0
- package/src/identity.js +4 -0
- package/src/monetization.js +20 -6
- package/src/payment.js +2 -0
- package/src/version.js +1 -1
package/identity.js
CHANGED
package/index.js
CHANGED
package/monetization.js
CHANGED
package/package.json
CHANGED
package/payment.js
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* Registers a component as a property on the provided global object, if not already registered, and dispatches an event to notify listeners.
|
|
4
|
+
* The event is dispatched on `document` and will have the name `$sch${componentClassName}:ready` and a `detail` property with the instance.
|
|
5
|
+
*
|
|
6
|
+
* @param {any} global typically `window`
|
|
7
|
+
* @param {string} componentClassName the name of the component to register, 'identity', 'monetization' or 'payment'
|
|
8
|
+
* @param {any} instance the instance of the component to register
|
|
9
|
+
* @returns {void}
|
|
10
|
+
*/
|
|
11
|
+
export const registerGlobal = (global, componentClassName, instance) => {
|
|
12
|
+
const prefixedName = `sch${componentClassName}`;
|
|
13
|
+
if (!(global)[prefixedName]) {
|
|
14
|
+
(global)[prefixedName] = instance;
|
|
15
|
+
}
|
|
16
|
+
if (typeof global.dispatchEvent === 'function') {
|
|
17
|
+
global.dispatchEvent(new CustomEvent(`${prefixedName}:ready`, { detail: { instance } }));
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
package/src/identity.js
CHANGED
|
@@ -15,6 +15,7 @@ import RESTClient from './RESTClient.js';
|
|
|
15
15
|
import SDKError from './SDKError.js';
|
|
16
16
|
import * as spidTalk from './spidTalk.js';
|
|
17
17
|
import version from './version.js';
|
|
18
|
+
import { registerGlobal } from './global-registry.js';
|
|
18
19
|
|
|
19
20
|
/**
|
|
20
21
|
* @typedef {object} LoginOptions
|
|
@@ -218,6 +219,9 @@ export class Identity extends EventEmitter {
|
|
|
218
219
|
this._setGlobalSessionServiceUrl(env);
|
|
219
220
|
|
|
220
221
|
this._unblockSessionCall();
|
|
222
|
+
|
|
223
|
+
registerGlobal(window, 'Identity', this);
|
|
224
|
+
|
|
221
225
|
}
|
|
222
226
|
|
|
223
227
|
/**
|
package/src/monetization.js
CHANGED
|
@@ -13,6 +13,7 @@ import Cache from './cache.js';
|
|
|
13
13
|
import * as spidTalk from './spidTalk.js';
|
|
14
14
|
import SDKError from './SDKError.js';
|
|
15
15
|
import version from './version.js';
|
|
16
|
+
import { registerGlobal } from './global-registry.js';
|
|
16
17
|
|
|
17
18
|
const globalWindow = () => window;
|
|
18
19
|
|
|
@@ -39,12 +40,14 @@ export class Monetization extends EventEmitter {
|
|
|
39
40
|
this.clientId = clientId;
|
|
40
41
|
this.env = env;
|
|
41
42
|
this.redirectUri = redirectUri;
|
|
43
|
+
this.pendingHasAccessRequests = {};
|
|
42
44
|
this._setSpidServerUrl(env);
|
|
43
45
|
|
|
44
46
|
if (sessionDomain) {
|
|
45
47
|
assert(isUrl(sessionDomain), 'sessionDomain parameter is not a valid URL');
|
|
46
48
|
this._setSessionServiceUrl(sessionDomain);
|
|
47
49
|
}
|
|
50
|
+
registerGlobal(window, 'Monetization', this);
|
|
48
51
|
}
|
|
49
52
|
|
|
50
53
|
/**
|
|
@@ -97,13 +100,24 @@ export class Monetization extends EventEmitter {
|
|
|
97
100
|
throw new SDKError(`'productIds' must be an array`);
|
|
98
101
|
}
|
|
99
102
|
|
|
100
|
-
const sortedIds = productIds.sort();
|
|
101
|
-
const cacheKey = this._accessCacheKey(
|
|
103
|
+
const sortedIds = [...productIds].sort();
|
|
104
|
+
const cacheKey = this._accessCacheKey(sortedIds, userId);
|
|
102
105
|
let data = this.cache.get(cacheKey);
|
|
103
106
|
if (!data) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
+
if (!this.pendingHasAccessRequests[cacheKey]) {
|
|
108
|
+
this.pendingHasAccessRequests[cacheKey] = this._sessionService.get(`/hasAccess/${sortedIds.join(',')}`);
|
|
109
|
+
}
|
|
110
|
+
const promise = this.pendingHasAccessRequests[cacheKey];
|
|
111
|
+
try {
|
|
112
|
+
data = await promise;
|
|
113
|
+
const expiresSeconds = data.ttl;
|
|
114
|
+
this.cache.set(cacheKey, data, expiresSeconds * 1000);
|
|
115
|
+
} finally {
|
|
116
|
+
// If it rejects, we still want to clear the pending request
|
|
117
|
+
if (this.pendingHasAccessRequests[cacheKey] === promise) {
|
|
118
|
+
delete this.pendingHasAccessRequests[cacheKey];
|
|
119
|
+
}
|
|
120
|
+
}
|
|
107
121
|
}
|
|
108
122
|
|
|
109
123
|
if (!data.entitled) {
|
|
@@ -131,7 +145,7 @@ export class Monetization extends EventEmitter {
|
|
|
131
145
|
* @private
|
|
132
146
|
*/
|
|
133
147
|
_accessCacheKey(productIds, userId) {
|
|
134
|
-
return `prd_${productIds.sort()}_${userId}`;
|
|
148
|
+
return `prd_${[...productIds].sort()}_${userId}`;
|
|
135
149
|
}
|
|
136
150
|
|
|
137
151
|
/**
|
package/src/payment.js
CHANGED
|
@@ -10,6 +10,7 @@ import { ENDPOINTS } from './config.js';
|
|
|
10
10
|
import * as popup from './popup.js';
|
|
11
11
|
import RESTClient from './RESTClient.js';
|
|
12
12
|
import * as spidTalk from './spidTalk.js';
|
|
13
|
+
import { registerGlobal } from './global-registry.js';
|
|
13
14
|
|
|
14
15
|
const globalWindow = () => window;
|
|
15
16
|
|
|
@@ -37,6 +38,7 @@ export class Payment {
|
|
|
37
38
|
this.publisher = publisher;
|
|
38
39
|
this._setSpidServerUrl(env);
|
|
39
40
|
this._setBffServerUrl(env);
|
|
41
|
+
registerGlobal(window, 'Payment', this);
|
|
40
42
|
}
|
|
41
43
|
|
|
42
44
|
/**
|
package/src/version.js
CHANGED