@schibsted/account-sdk-browser 6.0.0-alpha.13 → 6.0.0-alpha.14

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
@@ -31,6 +31,10 @@ If this is a new site and you do not have a `sessionDomain` yet, contact
31
31
 
32
32
  ## Development
33
33
 
34
+ Dependencies are installed from [Schibsted Artifactory](https://artifactory.schibsted.io) (see [`.npmrc`](./.npmrc)),
35
+ so npm must be authenticated to it before `npm install`. The private `@schibsted/consent-url-utils` package is
36
+ bundled into `dist/` by Vite during `npm run build`, so SDK consumers do not need access to it.
37
+
34
38
  Install dependencies and run the standard checks:
35
39
 
36
40
  ```sh
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Reads consents from the Schibsted Sourcepoint integration, the default consent reader.
3
+ * Pages without the integration have no consents to forward, so they are skipped before
4
+ * `getConsentsSync` would warn about the missing consent manager on every login URL.
5
+ * @private
6
+ */
7
+ export declare function readSourcepointConsents(window: Window): URLSearchParams | null;
8
+ /**
9
+ * Sets the given parameters on a URL, replacing previous values of the same parameters.
10
+ * @private
11
+ * @param href
12
+ * @param consentParams
13
+ * @return - The URL with the parameters replaced
14
+ */
15
+ export declare function replaceConsentParams(href: string, consentParams: URLSearchParams): string;
16
+ /**
17
+ * Refreshes consents of already rendered login links right before the browser follows them.
18
+ * Links are often generated before the user answers the consent dialog, so their consents are stale.
19
+ * The listener runs in the capture phase, before page handlers read the link.
20
+ * @private
21
+ * @param document
22
+ * @param options
23
+ * @param options.isLoginUrl - Tells whether a URL is a login URL to refresh
24
+ * @param options.getConsentParams - Current consent parameters
25
+ */
26
+ export declare function refreshLoginLinksOnActivation(document: Document, { isLoginUrl, getConsentParams, }: {
27
+ isLoginUrl: (href: string) => boolean;
28
+ getConsentParams: () => URLSearchParams;
29
+ }): void;
@@ -18,6 +18,7 @@ export declare class Identity {
18
18
  private readonly env;
19
19
  private readonly log?;
20
20
  private readonly callbackBeforeRedirect;
21
+ private readonly getConsents;
21
22
  private readonly sessionStorageCache;
22
23
  private readonly localStorageCache;
23
24
  private enableSessionCaching;
@@ -43,13 +44,17 @@ export declare class Identity {
43
44
  * @param options.sessionDomain - Example: "https://id.site.com"
44
45
  * @param options.redirectUri - Example: "https://site.com"
45
46
  * @param options.env - Schibsted account environment: `PRE` (default), `PRO`, `PRO_NO`, `PRO_FI` or `PRO_DK`
46
- * @param options.log - A function that receives debug log information. If not set,
47
- * no logging will be done
47
+ * @param options.log - Receives debug logs and consent reader errors.
48
+ * Without it, consent reader errors are reported through console.warn.
48
49
  * @param options.window - window object
49
50
  * @param options.callbackBeforeRedirect - callback triggered before session refresh redirect happen
51
+ * @param options.getConsents - reads consents forwarded in login URLs.
52
+ * Defaults to the Schibsted Sourcepoint integration
50
53
  * @throws {SDKError} - If any of options are invalid
51
54
  */
52
- constructor({ clientId, redirectUri, sessionDomain, env, log, window, callbackBeforeRedirect, }: IdentityOptions);
55
+ constructor({ clientId, redirectUri, sessionDomain, env, log, window, callbackBeforeRedirect, getConsents, }: IdentityOptions);
56
+ /** @internal */
57
+ enableLoginLinkRefresh(): void;
53
58
  addEventListener(type: AccountEventName, listener: EventListener): void;
54
59
  removeEventListener(type: AccountEventName, listener: EventListener): void;
55
60
  /**
@@ -273,6 +278,19 @@ export declare class Identity {
273
278
  * @return - The url
274
279
  */
275
280
  loginUrl({ state, acrValues, scope, redirectUri, loginHint, tag, teaser, maxAge, locale, oneStepLogin, prompt, xDomainId, xEnvironmentId, originCampaign, }: LoginOptions): string;
281
+ /**
282
+ * Reads the current consent parameters. A failing consent reader must not prevent a login,
283
+ * so the failure is logged and the login continues without consents.
284
+ * @private
285
+ * @return - Consent query parameters; empty when unavailable
286
+ */
287
+ private getConsentParams;
288
+ /**
289
+ * Tells whether a URL is a login URL generated by this instance
290
+ * @private
291
+ * @param href
292
+ */
293
+ private isLoginUrl;
276
294
  /**
277
295
  * The url for logging the user out
278
296
  * @param redirectUri
package/dist/index.d.ts CHANGED
@@ -6,6 +6,7 @@ export { default as SDKError } from './sdk-error.js';
6
6
  export { isConnectedSessionResponse, isConnectedSessionWithUserIdResponse, isSessionFailureResponse, isSessionSuccessResponse, } from './session-response.js';
7
7
  export type { AccountConfig, AccountEventListener, AccountEventMap, AccountEventName, LoginRequestedEventDetail, LogoutRequestedEventDetail, } from './types/account.js';
8
8
  export type { AccountEnvironment, LogFunction } from './types/common.js';
9
+ export type { ConsentReader } from './types/identity.js';
9
10
  export type { LoginOptions, SimplifiedLoginData, SimplifiedLoginWidgetLoginOptions, SimplifiedLoginWidgetOptions, } from './types/login.js';
10
11
  export type { HasAccessResult } from './types/monetization.js';
11
12
  export type { ConnectedSessionResponse, ConnectedSessionWithUserIdResponse, RedirectSessionResponse, SessionFailureResponse, SessionResponse, SessionSuccessResponse, SessionUserId, } from './types/session.js';