@schibsted/account-sdk-browser 5.2.7 → 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
@@ -124,6 +124,84 @@ function userClicksLogIn() {
124
124
  }
125
125
  ```
126
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
+
127
205
  #### Regarding `state`
128
206
 
129
207
  This parameter is an OpenID Connect parameter (described in [this paragraph in the
@@ -310,6 +388,12 @@ browser side. Nevertheless, here is a short description of them.
310
388
  * `referer` (yep, missing the double "rr"..): If this is missing, a call to hassession will
311
389
  return a `401` with a `UserException` that says `No session found`.
312
390
 
391
+ ## Development
392
+
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.
396
+
313
397
  ## Publishing
314
398
 
315
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).