@schibsted/account-sdk-browser 5.2.5 → 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/identity.js CHANGED
@@ -1,4 +1,4 @@
1
- /* Copyright 2024 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
1
+ /* Copyright 2026 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 2024 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
1
+ /* Copyright 2026 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 2024 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
1
+ /* Copyright 2026 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": "5.2.5",
3
+ "version": "5.2.6",
4
4
  "description": "Schibsted account SDK for browsers",
5
5
  "main": "index.js",
6
6
  "type": "module",
package/payment.js CHANGED
@@ -1,4 +1,4 @@
1
- /* Copyright 2024 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
1
+ /* Copyright 2026 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
 
@@ -40,6 +40,7 @@ export class Monetization extends EventEmitter {
40
40
  this.clientId = clientId;
41
41
  this.env = env;
42
42
  this.redirectUri = redirectUri;
43
+ this.pendingHasAccessRequests = {};
43
44
  this._setSpidServerUrl(env);
44
45
 
45
46
  if (sessionDomain) {
@@ -99,13 +100,24 @@ export class Monetization extends EventEmitter {
99
100
  throw new SDKError(`'productIds' must be an array`);
100
101
  }
101
102
 
102
- const sortedIds = productIds.sort();
103
- const cacheKey = this._accessCacheKey(productIds, userId);
103
+ const sortedIds = [...productIds].sort();
104
+ const cacheKey = this._accessCacheKey(sortedIds, userId);
104
105
  let data = this.cache.get(cacheKey);
105
106
  if (!data) {
106
- data = await this._sessionService.get(`/hasAccess/${sortedIds.join(',')}`);
107
- const expiresSeconds = data.ttl;
108
- this.cache.set(cacheKey, data, expiresSeconds * 1000);
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
+ }
109
121
  }
110
122
 
111
123
  if (!data.entitled) {
@@ -133,7 +145,7 @@ export class Monetization extends EventEmitter {
133
145
  * @private
134
146
  */
135
147
  _accessCacheKey(productIds, userId) {
136
- return `prd_${productIds.sort()}_${userId}`;
148
+ return `prd_${[...productIds].sort()}_${userId}`;
137
149
  }
138
150
 
139
151
  /**
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.2.5';
4
+ const version = '5.2.6';
5
5
  export default version;