@schibsted/account-sdk-browser 5.2.5 → 6.0.0-alpha.1

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 CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2024 Schibsted Products & Technology AS
1
+ Copyright (c) 2026 Schibsted Products & Technology AS
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
4
4
  associated documentation files (the "Software"), to deal in the Software without restriction,
package/README.md CHANGED
@@ -1,6 +1,4 @@
1
- [![logo](https://www.schibsted.com/Global/LogoTypes/Logos%202014/SMG_Small_2014_RGB.png)](https://github.com/schibsted/account-sdk-browser)
2
-
3
- ![Build Status](https://github.com/schibsted/account-sdk-browser/actions/workflows/pr.yml/badge.svg)
1
+ ![Build Status](https://schibsted.ghe.com/user-identity/account-sdk-browser/actions/workflows/pr.yml/badge.svg)
4
2
  [![Code coverage](https://codecov.io/gh/schibsted/account-sdk-browser/branch/master/graph/badge.svg)](https://codecov.io/gh/schibsted/account-sdk-browser)
5
3
  [![Snyk](https://snyk.io/test/github/schibsted/account-sdk-browser/badge.svg?targetFile=package.json)](https://snyk.io/test/github/schibsted/account-sdk-browser)
6
4
 
@@ -26,14 +24,11 @@ For example if your `pre` domain is pre.sdk-example.com, and it uses id.pre.sdk-
26
24
  domain, your local domain should be local.sdk-example.com.
27
25
 
28
26
  1. Do `npm install --save @schibsted/account-sdk-browser`
29
- 1. Use this library as you would any other npm module: `import { Identity, Monetization, Payment } from '@schibsted/account-sdk-browser'`
30
- With CommonJS it is possible to `require` the modules Identity, Monetization and Payment
31
- by appending `/identity`, `/monetization'` or `/payment'`.
32
- 1. Build your site as you prefer. This library uses modern JavaScript syntax (including async/await
33
- and other ES2017 and WHATWG features) by default. We recommend that you do any transpilation
34
- yourself for the browser versions you need to cater to. See [this paragraph](#polyfills) for
35
- info about our Babel-ified version and info about polyfills.
36
- 1. Initiate the SDK and provide at least `clientId`, `env` and `sessionDomain`.
27
+ 2. Use this library as you would any other npm module: `import { Identity, Monetization, Payment } from '@schibsted/account-sdk-browser'`.
28
+ 3. Build your site as you prefer. This library is published as ES modules and uses modern JavaScript
29
+ syntax (including async/await and other ES2017 and WHATWG features). We recommend that you do
30
+ any transpilation yourself for the browser versions you need to cater to. We do not add polyfills.
31
+ 4. Initiate the SDK and provide at least `clientId`, `env` and `sessionDomain`.
37
32
 
38
33
  If this is for a new site and there is no sessionDomain yet, contact
39
34
  [support](mailto:schibstedaccount@schibsted.com) to initiate the process.
@@ -53,9 +48,9 @@ Follow the [migration guide](./MIGRATION.md).
53
48
  ## Example project
54
49
 
55
50
  There is an example that demonstrates how the SDK can be used. The code is
56
- [here](https://github.com/schibsted/sdk-example), and you can see it live
51
+ [here](https://schibsted.ghe.com/user-identity/sdk-example), and you can see it live
57
52
  [here](https://pro.sdk-example.com). You have a use-case that we haven't thought of? Ask us to add
58
- it by creating an [issue](https://github.com/schibsted/sdk-example/issues/new).
53
+ it by creating an [issue](https://schibsted.ghe.com/user-identity/sdk-example/issues/new).
59
54
 
60
55
  You can use that code as inspiration or just fork and play with it. The account-sdk-browser NPM
61
56
  module is used for authenticating the user with Schibsted account. Take a look at how the SDK is
@@ -184,7 +179,7 @@ signal to your main page — using
184
179
  [postMessage](https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage) or something
185
180
  similar — to indicate that the user is logged in. If the popup window fails to open, it'll
186
181
  automatically fall back to the redirect flow. The SDK Example project mentioned above demonstrates
187
- how it can work. Again, you can see [sdk-example](https://github.com/schibsted/sdk-example) if you
182
+ how it can work. Again, you can see [sdk-example](https://schibsted.ghe.com/user-identity/sdk-example) if you
188
183
  want a working example.
189
184
 
190
185
  #### Is the user logged in?
@@ -264,25 +259,6 @@ const paylinkUrl = paymentSDK.purchasePaylinkUrl(paylink);
264
259
  paymentSDK.payWithPaylink(paylink);
265
260
  ```
266
261
 
267
- ## Appendix
268
-
269
- #### Polyfills
270
-
271
- This SDK uses modern JavaScript features. If you support older browsers, you should use a tool like
272
- babel to transform the JavaScript as needed. However, since certain teams have deployment pipelines
273
- where it's difficult to do their own transpilation, we do provide some opt-in es5 files as well:
274
-
275
- 1. `@schibsted/account-sdk-browser/es5`: Include both `Identity`, `Monetization` and `Payment`.
276
- 1. `@schibsted/account-sdk-browser/es5/global`: Include both `Identity`, `Monetization` and
277
- `Payment`. In addition, add them as variables to the global `window` object.
278
- 1. `@schibsted/account-sdk-browser/es5/identity`, `@schibsted/account-sdk-browser/es5/monetization`
279
- or `@schibsted/account-sdk-browser/es5/payment` can be used to only include each class by itself.
280
-
281
- But then regardless of whether you use the es5 versions or not, you might need to polyfill certain
282
- things that might be missing in the browsers you wish to support. A quick test using IE11 showed
283
- that we needed polyfills for `Promise`, `URL`, `Object.entries`, `fetch`, `Number.isFinite` and
284
- `Number.isInteger`.
285
-
286
262
  #### Cookies
287
263
 
288
264
  There are some cookies used by Schibsted account. They should all be considered opaque on the
@@ -312,23 +288,24 @@ browser side. Nevertheless, here is a short description of them.
312
288
  * `referer` (yep, missing the double "rr"..): If this is missing, a call to hassession will
313
289
  return a `401` with a `UserException` that says `No session found`.
314
290
 
315
- ## Releasing
291
+ ## Publishing
316
292
 
317
- Tags are pushed to NPM via Travis. To release a new version, run in master
293
+ Versioning and changelog are handled by [Release Please (GitHub Action)](https://github.com/googleapis/release-please). Publishing to [npmjs.org](https://www.npmjs.com/package/@schibsted/account-sdk-browser) is handled by the [npm-publish workflow](./.github/workflows/npm-publish.yml). See the [Release Please workflow](./.github/workflows/release-please.yml) and [`release-please-config.json`](./release-please-config.json).
318
294
 
319
- ```bash
320
- $ npm version <major|minor|patch>
321
- ```
295
+ When publishable changes have been merged to `master`, Release Please will create (or update) a release pull request.
296
+ The suggested version is based on the commit messages in accordance with the [Conventional Commits](https://www.conventionalcommits.org/) specification — `fix:` bumps the patch version, `feat:` bumps the minor version, and `feat!:` or a `BREAKING CHANGE:` footer bumps the major version.
297
+ Other prefixes (`chore:`, `docs:`, `test:`, `refactor:`, `ci:`, `build:`, `style:`) do not trigger a release and are hidden from the changelog.
298
+
299
+ To release/publish the changes simply merge the corresponding pull request and wait for the publish workflow to finish.
300
+ Release-please will create a git tag (e.g. `v5.2.7`) and a GitHub Release, and the [publish workflow](./.github/workflows/npm-publish.yml) will push the package to npmjs.org.
322
301
 
323
- which will run the test, update version in package.json, commit, tag the commit
324
- and push.
325
302
 
326
303
  ## LICENSE
327
304
 
328
- Copyright (c) 2024 Schibsted Products & Technology AS
305
+ Copyright (c) 2026 Schibsted Products & Technology AS
329
306
 
330
307
  Licensed under the [MIT
331
- License](https://github.com/schibsted/account-sdk-browser/blob/master/LICENSE.md)
308
+ License](https://schibsted.ghe.com/user-identity/account-sdk-browser/blob/master/LICENSE.md)
332
309
 
333
310
  Unless required by applicable law or agreed to in writing, software distributed under the License is
334
311
  distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
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,20 +1,23 @@
1
1
  {
2
2
  "name": "@schibsted/account-sdk-browser",
3
- "version": "5.2.5",
3
+ "version": "6.0.0-alpha.1",
4
4
  "description": "Schibsted account SDK for browsers",
5
5
  "main": "index.js",
6
6
  "type": "module",
7
+ "exports": {
8
+ ".": "./index.js",
9
+ "./identity": "./identity.js",
10
+ "./monetization": "./monetization.js",
11
+ "./payment": "./payment.js"
12
+ },
7
13
  "scripts": {
8
- "build": "./build.sh",
9
- "clean": "rimraf .cache coverage dist docs",
14
+ "clean": "rimraf .cache coverage docs && npm run clean:legacy",
15
+ "clean:legacy": "rimraf es5",
10
16
  "docs": "rimraf docs && jsdoc -c ./jsdoc.conf.json --verbose",
11
17
  "lint": "eslint .",
12
18
  "lint:fix": "eslint . --fix",
13
- "test": "jest",
14
- "cover": "jest --coverage",
15
- "preversion": "npm run lint && npm test",
16
- "version": "node ./scripts/genversion.js && git add src/version.js",
17
- "postversion": "git push && git push --tags"
19
+ "test": "vitest run",
20
+ "cover": "vitest run --coverage"
18
21
  },
19
22
  "author": "",
20
23
  "license": "MIT",
@@ -22,48 +25,19 @@
22
25
  "tiny-emitter": "^2.1.0"
23
26
  },
24
27
  "devDependencies": {
25
- "@babel/core": "^7.11.4",
26
- "@babel/preset-env": "^7.23.2",
27
- "babel-loader": "^8.1.0",
28
- "core-js": "^3.6.5",
28
+ "@vitest/coverage-v8": "^2.1.9",
29
29
  "docdash": "git+https://github.com/torarvid/docdash.git#v0.5.0",
30
30
  "eslint": "^6.8.0",
31
31
  "eslint-plugin-import": "^2.20.2",
32
- "jest": "^26.4.2",
33
- "jest-junit": "^10.0.0",
34
32
  "jsdoc": "^3.6.11",
33
+ "jsdom": "^25.0.1",
35
34
  "node-fetch": "^2.6.0",
36
- "regenerator-runtime": "^0.13.7",
37
- "webpack": "^4.44.1",
38
- "webpack-cli": "^3.3.12",
35
+ "vitest": "^2.1.9",
39
36
  "whatwg-url": "^8.0.0"
40
37
  },
41
38
  "repository": {
42
39
  "type": "git",
43
- "url": "git://github.com/schibsted/account-sdk-browser.git"
44
- },
45
- "babel": {
46
- "presets": [
47
- [
48
- "@babel/preset-env",
49
- {
50
- "useBuiltIns": "usage",
51
- "corejs": 3,
52
- "targets": {
53
- "browsers": [
54
- "> 1%",
55
- "last 10 chrome major versions",
56
- "last 10 firefox major versions",
57
- "last 10 opera major versions",
58
- "last 2 safari major versions",
59
- "last 2 ios major versions",
60
- "last 2 ie major versions",
61
- "last 5 edge major versions"
62
- ]
63
- }
64
- }
65
- ]
66
- ]
40
+ "url": "git://schibsted.ghe.com/user-identity/account-sdk-browser.git"
67
41
  },
68
42
  "typings": "index.d.ts"
69
43
  }
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/payment.d.ts CHANGED
@@ -74,7 +74,7 @@ export class Payment {
74
74
  */
75
75
  redeemUrl(voucherCode: string, redirectUri?: string): string;
76
76
  /**
77
- * @deprecated https://github.com/schibsted/account-sdk-browser/issues/94
77
+ * @deprecated https://schibsted.ghe.com/user-identity/account-sdk-browser/issues/94
78
78
  *
79
79
  * Get the url for the paylink purchase
80
80
  * @todo Check working-ness for BFF + SPiD
package/src/payment.js CHANGED
@@ -129,7 +129,7 @@ export class Payment {
129
129
  }
130
130
 
131
131
  /**
132
- * @deprecated https://github.com/schibsted/account-sdk-browser/issues/94
132
+ * @deprecated https://schibsted.ghe.com/user-identity/account-sdk-browser/issues/94
133
133
  *
134
134
  * Get the url for the paylink purchase
135
135
  * @todo Check working-ness for BFF + SPiD
package/src/version.js CHANGED
@@ -1,5 +1,5 @@
1
- // Automatically generated in 'npm version' by scripts/genversion.js
1
+ // Version is bumped automatically by release-please. See release-please-config.json.
2
2
 
3
3
  'use strict'
4
- const version = '5.2.5';
4
+ const version = '6.0.0-alpha.1'; // x-release-please-version
5
5
  export default version;