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

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
package/dist/account.d.ts CHANGED
@@ -102,10 +102,11 @@ export declare class Account {
102
102
  * Call this from a user gesture when `preferPopup` is enabled, otherwise browser popup blockers
103
103
  * may block the popup and the SDK will fall back to redirect navigation.
104
104
  *
105
- * @param options - Login URL parameters.
105
+ * @param options - Login URL parameters. When `state` is omitted, the configured
106
+ * `generateState` function provides it.
106
107
  * @returns A popup window reference when a popup is opened; otherwise `null`.
107
108
  */
108
- login(options: LoginOptions): Window | null;
109
+ login(options?: LoginOptions): Window | null;
109
110
  /**
110
111
  * Logs the user out from the brand Session Service session and redirects the browser.
111
112
  *
@@ -115,9 +116,10 @@ export declare class Account {
115
116
  /**
116
117
  * Builds the login URL without navigating the browser.
117
118
  *
118
- * @param options - Login URL parameters.
119
+ * @param options - Login URL parameters. When `state` is omitted, the configured
120
+ * `generateState` function provides it.
119
121
  */
120
- loginUrl(options: LoginOptions): string;
122
+ loginUrl(options?: LoginOptions): string;
121
123
  /**
122
124
  * Builds the logout URL without navigating the browser.
123
125
  *
@@ -134,13 +136,14 @@ export declare class Account {
134
136
  * Loads and displays the simplified login widget when user context is available.
135
137
  *
136
138
  * Your application decides how often to call this method. The `state` field in `loginParams`
137
- * may be a string or a function that resolves to a string.
139
+ * may be a string or a function that resolves to a string. When omitted, the configured
140
+ * `generateState` function provides it.
138
141
  * Widget open and cancel events can be observed with `on()`.
139
142
  *
140
143
  * @returns `true` when the widget was displayed.
141
144
  * @throws {SDKError} If user context data is missing or the widget script cannot be loaded.
142
145
  */
143
- showSimplifiedLoginWidget(loginParams: SimplifiedLoginWidgetLoginOptions, options?: SimplifiedLoginWidgetOptions): Promise<boolean>;
146
+ showSimplifiedLoginWidget(loginParams?: SimplifiedLoginWidgetLoginOptions, options?: SimplifiedLoginWidgetOptions): Promise<boolean>;
144
147
  /**
145
148
  * Enables or disables caching for subsequent session lookups.
146
149
  *
@@ -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,8 @@ export declare class Identity {
18
18
  private readonly env;
19
19
  private readonly log?;
20
20
  private readonly callbackBeforeRedirect;
21
+ private readonly getConsents;
22
+ private readonly generateState?;
21
23
  private readonly sessionStorageCache;
22
24
  private readonly localStorageCache;
23
25
  private enableSessionCaching;
@@ -43,13 +45,18 @@ export declare class Identity {
43
45
  * @param options.sessionDomain - Example: "https://id.site.com"
44
46
  * @param options.redirectUri - Example: "https://site.com"
45
47
  * @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
48
+ * @param options.log - Receives debug logs and consent reader errors.
49
+ * Without it, consent reader errors are reported through console.warn.
48
50
  * @param options.window - window object
49
51
  * @param options.callbackBeforeRedirect - callback triggered before session refresh redirect happen
52
+ * @param options.getConsents - reads consents forwarded in login URLs.
53
+ * Defaults to the Schibsted Sourcepoint integration
54
+ * @param options.generateState - generates the OAuth state when login options do not provide one
50
55
  * @throws {SDKError} - If any of options are invalid
51
56
  */
52
- constructor({ clientId, redirectUri, sessionDomain, env, log, window, callbackBeforeRedirect, }: IdentityOptions);
57
+ constructor({ clientId, redirectUri, sessionDomain, env, log, window, callbackBeforeRedirect, getConsents, generateState, }: IdentityOptions);
58
+ /** @internal */
59
+ enableLoginLinkRefresh(): void;
53
60
  addEventListener(type: AccountEventName, listener: EventListener): void;
54
61
  removeEventListener(type: AccountEventName, listener: EventListener): void;
55
62
  /**
@@ -256,7 +263,7 @@ export declare class Identity {
256
263
  /**
257
264
  * Generates the link to the new login page that'll be used in the popup or redirect flow
258
265
  * @param options
259
- * @param options.state
266
+ * @param options.state - defaults to the value returned by `generateState`
260
267
  * @param options.acrValues
261
268
  * @param options.scope
262
269
  * @param options.redirectUri
@@ -273,6 +280,19 @@ export declare class Identity {
273
280
  * @return - The url
274
281
  */
275
282
  loginUrl({ state, acrValues, scope, redirectUri, loginHint, tag, teaser, maxAge, locale, oneStepLogin, prompt, xDomainId, xEnvironmentId, originCampaign, }: LoginOptions): string;
283
+ /**
284
+ * Reads the current consent parameters. A failing consent reader must not prevent a login,
285
+ * so the failure is logged and the login continues without consents.
286
+ * @private
287
+ * @return - Consent query parameters; empty when unavailable
288
+ */
289
+ private getConsentParams;
290
+ /**
291
+ * Tells whether a URL is a login URL generated by this instance
292
+ * @private
293
+ * @param href
294
+ */
295
+ private isLoginUrl;
276
296
  /**
277
297
  * The url for logging the user out
278
298
  * @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 { LoginOptions, SimplifiedLoginData, SimplifiedLoginWidgetLoginOptions, SimplifiedLoginWidgetOptions, } from './types/login.js';
9
+ export type { ConsentReader } from './types/identity.js';
10
+ export type { LoginOptions, SimplifiedLoginData, SimplifiedLoginWidgetLoginOptions, SimplifiedLoginWidgetOptions, StateGenerator, } 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';