@schibsted/account-sdk-browser 5.2.6 → 5.3.0

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/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
 
@@ -53,9 +51,9 @@ Follow the [migration guide](./MIGRATION.md).
53
51
  ## Example project
54
52
 
55
53
  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
54
+ [here](https://schibsted.ghe.com/user-identity/sdk-example), and you can see it live
57
55
  [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).
56
+ it by creating an [issue](https://schibsted.ghe.com/user-identity/sdk-example/issues/new).
59
57
 
60
58
  You can use that code as inspiration or just fork and play with it. The account-sdk-browser NPM
61
59
  module is used for authenticating the user with Schibsted account. Take a look at how the SDK is
@@ -126,6 +124,84 @@ function userClicksLogIn() {
126
124
  }
127
125
  ```
128
126
 
127
+ #### Forward consents to Account
128
+
129
+ The SDK forwards the user's current consents to Schibsted account in every login URL. The consents are
130
+ read by a `getConsents` reader, which returns them serialized as `URLSearchParams`; the SDK appends them
131
+ to the login URL as they are. The reader is called synchronously every time a login URL is created, so it
132
+ must return the current state immediately instead of waiting for the consent dialog.
133
+ `login()` and `loginUrl()` stay synchronous; a login started before the user answers the dialog
134
+ (e.g. from the dialog itself) continues without consents.
135
+
136
+ Login links rendered before the user answered the consent dialog are refreshed when they are clicked:
137
+ the SDK listens to clicks on the document and updates the consents of `<a>` elements that point to its
138
+ own login URL. Links inside iframes and URLs opened with `window.open()` are not refreshed;
139
+ create the URL at the time of the user's action if that matters.
140
+
141
+ ##### Schibsted sites
142
+
143
+ By default, consents are read from the Schibsted Sourcepoint integration (`window._tcf_` or
144
+ `window._scc_`), so Schibsted sites forward consents out of the box, without any configuration:
145
+
146
+ ```javascript
147
+ const identity = new Identity({
148
+ clientId: '56e9a5d1eee0000000000000',
149
+ redirectUri: 'https://awesomenews.site',
150
+ sessionDomain: 'https://id.awesomenews.site',
151
+ // Optional: opt out of refreshing rendered login links
152
+ refreshLoginLinks: false,
153
+ });
154
+ ```
155
+
156
+ ##### Other CMPs
157
+
158
+ Sites without the Schibsted Sourcepoint integration pass their own reader:
159
+
160
+ ```javascript
161
+ const identity = new Identity({
162
+ clientId: '56e9a5d1eee0000000000000',
163
+ redirectUri: 'https://awesomenews.site',
164
+ sessionDomain: 'https://id.awesomenews.site',
165
+ // Reads the decision of your CMP, see the interface below
166
+ getConsents: readConsentsFromMyCmp,
167
+ });
168
+ ```
169
+
170
+ Use `getConsents: () => null` to forward no consents.
171
+
172
+ ##### The `getConsents` interface
173
+
174
+ ```typescript
175
+ type ConsentReader = () => URLSearchParams | null;
176
+ ```
177
+
178
+ A reader must:
179
+
180
+ - **Be synchronous.** Return the decision the CMP already has, e.g. from its in-memory state or its
181
+ stored consent cookie. Do not return a `Promise` or wait for the consent dialog.
182
+ - **Return `URLSearchParams` or `null`.** `null` or empty params mean the decision is unknown, and no consent
183
+ parameters are added. The SDK logs any other return value and any thrown error, and the login continues
184
+ without consents.
185
+ - **Return only consent parameters.** Every key it returns is added to the login URL. When a rendered
186
+ link is refreshed, those keys replace the values already on it, so do not return OAuth parameters such
187
+ as `state` or `redirect_uri`. Repeated keys (e.g. `purpose=a&purpose=b`) are kept.
188
+
189
+ Return these parameters (format `v1`, the only supported version):
190
+
191
+ | Parameter | Value |
192
+ |-------------------|----------------------------------------------------------------------------------------|
193
+ | `consents` | Alphabetically sorted, comma-separated purposes the user granted, or `rejected` if the user rejected all of them. Purposes: `advertising`, `analytics`, `marketing`, `personalisation` |
194
+ | `consent_version` | Version of this parameter format; always `v1` |
195
+
196
+ Examples of serialized params returned by a reader:
197
+
198
+ | User's decision | Returned `URLSearchParams` (serialized) |
199
+ |---------------------------------------|-----------------------------------------------------|
200
+ | Granted advertising and analytics | `consents=advertising%2Canalytics&consent_version=v1` |
201
+ | Granted analytics only | `consents=analytics&consent_version=v1` |
202
+ | Rejected all purposes | `consents=rejected&consent_version=v1` |
203
+ | Not answered yet | `null` (or empty `URLSearchParams`) |
204
+
129
205
  #### Regarding `state`
130
206
 
131
207
  This parameter is an OpenID Connect parameter (described in [this paragraph in the
@@ -184,7 +260,7 @@ signal to your main page — using
184
260
  [postMessage](https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage) or something
185
261
  similar — to indicate that the user is logged in. If the popup window fails to open, it'll
186
262
  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
263
+ how it can work. Again, you can see [sdk-example](https://schibsted.ghe.com/user-identity/sdk-example) if you
188
264
  want a working example.
189
265
 
190
266
  #### Is the user logged in?
@@ -312,23 +388,30 @@ browser side. Nevertheless, here is a short description of them.
312
388
  * `referer` (yep, missing the double "rr"..): If this is missing, a call to hassession will
313
389
  return a `401` with a `UserException` that says `No session found`.
314
390
 
315
- ## Releasing
391
+ ## Development
316
392
 
317
- Tags are pushed to NPM via Travis. To release a new version, run in master
393
+ Dependencies are installed from [Schibsted Artifactory](https://artifactory.schibsted.io) (see [`.npmrc`](./.npmrc)),
394
+ so npm must be authenticated to it before `npm install`. The private `@schibsted/consent-url-utils` package is
395
+ bundled into `src/vendor/` on install (`npm run vendor`), so the published SDK does not depend on it.
318
396
 
319
- ```bash
320
- $ npm version <major|minor|patch>
321
- ```
397
+ ## Publishing
398
+
399
+ 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).
400
+
401
+ When publishable changes have been merged to `master`, Release Please will create (or update) a release pull request.
402
+ 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.
403
+ Other prefixes (`chore:`, `docs:`, `test:`, `refactor:`, `ci:`, `build:`, `style:`) do not trigger a release and are hidden from the changelog.
404
+
405
+ To release/publish the changes simply merge the corresponding pull request and wait for the publish workflow to finish.
406
+ 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
407
 
323
- which will run the test, update version in package.json, commit, tag the commit
324
- and push.
325
408
 
326
409
  ## LICENSE
327
410
 
328
411
  Copyright (c) 2026 Schibsted Products & Technology AS
329
412
 
330
413
  Licensed under the [MIT
331
- License](https://github.com/schibsted/account-sdk-browser/blob/master/LICENSE.md)
414
+ License](https://schibsted.ghe.com/user-identity/account-sdk-browser/blob/master/LICENSE.md)
332
415
 
333
416
  Unless required by applicable law or agreed to in writing, software distributed under the License is
334
417
  distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or