@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 +1 -1
- package/README.md +19 -42
- package/identity.js +1 -1
- package/index.js +1 -1
- package/monetization.js +1 -1
- package/package.json +15 -41
- package/payment.js +1 -1
- package/src/monetization.js +18 -6
- package/src/payment.d.ts +1 -1
- package/src/payment.js +1 -1
- package/src/version.js +2 -2
- package/es5/global.js +0 -12935
- package/es5/global.js.map +0 -1
- package/es5/global.min.js +0 -2
- package/es5/global.min.js.map +0 -1
- package/es5/identity.js +0 -12207
- package/es5/identity.js.map +0 -1
- package/es5/identity.min.js +0 -2
- package/es5/identity.min.js.map +0 -1
- package/es5/index.js +0 -12907
- package/es5/index.js.map +0 -1
- package/es5/index.min.js +0 -2
- package/es5/index.min.js.map +0 -1
- package/es5/monetization.js +0 -9148
- package/es5/monetization.js.map +0 -1
- package/es5/monetization.min.js +0 -2
- package/es5/monetization.min.js.map +0 -1
- package/es5/payment.js +0 -8853
- package/es5/payment.js.map +0 -1
- package/es5/payment.min.js +0 -2
- package/es5/payment.min.js.map +0 -1
- package/src/__mocks__/.eslintrc.yml +0 -8
- package/src/__mocks__/RESTClient.js +0 -54
- package/src/es5/global.js +0 -13
- package/src/es5/identity.js +0 -10
- package/src/es5/index.js +0 -13
- package/src/es5/monetization.js +0 -10
- package/src/es5/payment.js +0 -10
package/LICENSE.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright (c)
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-

|
|
1
|
+

|
|
4
2
|
[](https://codecov.io/gh/schibsted/account-sdk-browser)
|
|
5
3
|
[](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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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://
|
|
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://
|
|
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://
|
|
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
|
-
##
|
|
291
|
+
## Publishing
|
|
316
292
|
|
|
317
|
-
|
|
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
|
-
|
|
320
|
-
|
|
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)
|
|
305
|
+
Copyright (c) 2026 Schibsted Products & Technology AS
|
|
329
306
|
|
|
330
307
|
Licensed under the [MIT
|
|
331
|
-
License](https://
|
|
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
package/index.js
CHANGED
package/monetization.js
CHANGED
package/package.json
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@schibsted/account-sdk-browser",
|
|
3
|
-
"version": "
|
|
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
|
-
"
|
|
9
|
-
"clean": "rimraf
|
|
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": "
|
|
14
|
-
"cover": "
|
|
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
|
-
"@
|
|
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
|
-
"
|
|
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://
|
|
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
package/src/monetization.js
CHANGED
|
@@ -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(
|
|
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
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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://
|
|
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://
|
|
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
|
-
//
|
|
1
|
+
// Version is bumped automatically by release-please. See release-please-config.json.
|
|
2
2
|
|
|
3
3
|
'use strict'
|
|
4
|
-
const version = '
|
|
4
|
+
const version = '6.0.0-alpha.1'; // x-release-please-version
|
|
5
5
|
export default version;
|