@schibsted/account-sdk-browser 6.0.0-alpha.4 → 6.0.0-alpha.6

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/dist/account.d.ts CHANGED
@@ -1,30 +1,161 @@
1
- import { AccountConfig, AccountEventHandler, AccountEventName } from './types/account.js';
1
+ import { AccountConfig, AccountEventListener, AccountEventName } from './types/account.js';
2
2
  import { LoginOptions, SimplifiedLoginData, SimplifiedLoginWidgetLoginOptions, SimplifiedLoginWidgetOptions } from './types/login.js';
3
3
  import { HasAccessResult } from './types/monetization.js';
4
4
  import { ConnectedSessionResponse, SessionResponse, SessionUserId } from './types/session.js';
5
5
  /**
6
6
  * Unified client-side interface for a configured Schibsted Account integration.
7
+ *
8
+ * Create an instance with `createAccountSdk()` unless you explicitly need to construct it
9
+ * yourself. The instance coordinates identity, login, session, and access-check features for one
10
+ * configured client.
11
+ *
12
+ * @group Core API
7
13
  */
8
14
  export declare class Account {
9
15
  #private;
10
16
  constructor(config: AccountConfig);
17
+ /**
18
+ * Queries Session Service and returns the current browser session state.
19
+ *
20
+ * This call may trigger a full-page session refresh redirect. Configure
21
+ * `callbackBeforeRedirect` if your app needs to persist state before that navigation.
22
+ *
23
+ * @throws {SDKError} If the Session Service call fails.
24
+ */
11
25
  hasSession(): Promise<SessionResponse>;
26
+ /**
27
+ * Checks whether the browser currently has a Schibsted Account session.
28
+ *
29
+ * Returns `false` instead of throwing when the session lookup fails.
30
+ */
12
31
  isLoggedIn(): Promise<boolean>;
32
+ /**
33
+ * Checks whether the current user is connected to the configured client.
34
+ *
35
+ * A user can be logged in to Schibsted Account without being connected to your client, for
36
+ * example before accepting required terms.
37
+ */
13
38
  isConnected(): Promise<boolean>;
39
+ /**
40
+ * Returns the connected user session data.
41
+ *
42
+ * @throws {SDKError} If the user is not connected to the configured client.
43
+ */
14
44
  getUser(): Promise<ConnectedSessionResponse>;
45
+ /**
46
+ * Returns the realm-specific Schibsted Account user id as a string.
47
+ *
48
+ * Use `getUserUuid()` when you need the globally unique user id.
49
+ *
50
+ * @throws {SDKError} If the user is not connected to the configured client.
51
+ */
15
52
  getUserId(): Promise<string>;
53
+ /**
54
+ * Returns the globally unique user id from the current session.
55
+ *
56
+ * @throws {SDKError} If the user is not connected to the configured client.
57
+ */
58
+ getUserUuid(): Promise<string>;
59
+ /**
60
+ * Returns the user SDRN from the current session.
61
+ *
62
+ * @throws {SDKError} If the SDRN is missing from the session response.
63
+ */
16
64
  getUserSDRN(): Promise<string>;
65
+ /**
66
+ * Returns minimal user context for simplified login prompts.
67
+ *
68
+ * Returns `null` if the global account session cannot be read.
69
+ */
17
70
  getUserContextData(): Promise<SimplifiedLoginData | null>;
71
+ /**
72
+ * Returns the Varnish `sp_id` value from the current session when present.
73
+ */
18
74
  getSpId(): Promise<string | null>;
75
+ /**
76
+ * Starts the login flow with either a full-page redirect or a popup.
77
+ *
78
+ * Call this from a user gesture when `preferPopup` is enabled, otherwise browser popup blockers
79
+ * may block the popup and the SDK will fall back to redirect navigation.
80
+ *
81
+ * @param options - Login URL parameters.
82
+ * @returns A popup window reference when a popup is opened; otherwise `null`.
83
+ */
19
84
  login(options: LoginOptions): Window | null;
85
+ /**
86
+ * Logs the user out from the brand Session Service session and redirects the browser.
87
+ *
88
+ * @param redirectUri - Where Session Service should redirect the browser after logout.
89
+ */
20
90
  logout(redirectUri?: string): void;
91
+ /**
92
+ * Builds the login URL without navigating the browser.
93
+ *
94
+ * @param options - Login URL parameters.
95
+ */
21
96
  loginUrl(options: LoginOptions): string;
97
+ /**
98
+ * Builds the Schibsted Account profile page URL.
99
+ *
100
+ * @param redirectUri - Where the account page should redirect the browser afterwards.
101
+ */
22
102
  accountUrl(redirectUri?: string): string;
103
+ /**
104
+ * Loads and displays the simplified login widget when user context is available.
105
+ *
106
+ * Your application decides how often to call this method. The `state` field in `loginParams`
107
+ * may be a string or a function that resolves to a string.
108
+ * Widget open and cancel events can be observed with `on()`.
109
+ *
110
+ * @returns `true` when the widget was displayed.
111
+ * @throws {SDKError} If user context data is missing or the widget script cannot be loaded.
112
+ */
23
113
  showSimplifiedLoginWidget(loginParams: SimplifiedLoginWidgetLoginOptions, options?: SimplifiedLoginWidgetOptions): Promise<boolean>;
114
+ /**
115
+ * Enables or disables caching for subsequent session lookups.
116
+ *
117
+ * Changing this setting does not remove an existing cached session.
118
+ */
119
+ setSessionCachingEnabled(enabled: boolean): void;
120
+ /**
121
+ * Removes the cached Session Service user session response.
122
+ */
24
123
  clearCachedUserSession(): void;
124
+ /**
125
+ * Checks whether a user has access to any of the requested products or features.
126
+ *
127
+ * Results are cached according to the TTL returned by Session Service.
128
+ *
129
+ * @param productIds - Product or feature ids to check.
130
+ * @param userId - Current user id, usually from `getUserId()`.
131
+ * @returns Access data, or `null` when the user is not entitled.
132
+ * @throws {SDKError} If `sessionDomain` is missing, input is invalid, or the request fails.
133
+ */
25
134
  hasAccess(productIds: string[], userId: SessionUserId): Promise<HasAccessResult | null>;
135
+ /**
136
+ * Removes a cached access-check result.
137
+ *
138
+ * @param productIds - Product or feature ids used for the cached lookup.
139
+ * @param userId - User id used for the cached lookup.
140
+ */
26
141
  clearCachedAccessResult(productIds: string[], userId: SessionUserId): void;
27
- on(event: AccountEventName, callback: AccountEventHandler, ctx?: unknown): this;
28
- off(event: AccountEventName, callback?: AccountEventHandler): this;
142
+ /**
143
+ * Subscribes to Account events.
144
+ *
145
+ * Supported event names are defined by {@link AccountEventName}.
146
+ *
147
+ * @param event - Event name.
148
+ * @param listener - Listener that receives an `Event` or `CustomEvent`.
149
+ */
150
+ on<EventName extends AccountEventName>(event: EventName, listener: AccountEventListener<EventName>): this;
151
+ /**
152
+ * Unsubscribes from Account events.
153
+ *
154
+ * Supported event names are defined by {@link AccountEventName}.
155
+ *
156
+ * @param event - Event name.
157
+ * @param listener - Listener to remove.
158
+ */
159
+ off<EventName extends AccountEventName>(event: EventName, listener: AccountEventListener<EventName>): this;
29
160
  }
30
161
  export default Account;
package/dist/globals.d.ts CHANGED
@@ -1,11 +1,7 @@
1
1
  import { Account } from './account.js';
2
- import { Identity } from './identity.js';
3
- import { Monetization } from './monetization.js';
4
2
  declare global {
5
3
  interface Window {
6
4
  schAccount?: Account;
7
- schIdentity?: Identity;
8
- schMonetization?: Monetization;
9
5
  SPiD?: {
10
6
  Talk?: {
11
7
  response?: (callbackName: string, data: unknown) => unknown;
@@ -1,12 +1,7 @@
1
- import { TinyEmitter } from 'tiny-emitter';
2
- import { default as Cache } from './cache.js';
3
- import { default as RESTClient } from './rest-client.js';
4
- import { LogFunction } from './types/common.js';
5
- import { IdentityBeforeRedirectCallback, IdentityOptions, VarnishCookieOptions } from './types/identity.js';
1
+ import { AccountEventName } from './types/account.js';
2
+ import { IdentityOptions, VarnishCookieOptions } from './types/identity.js';
6
3
  import { LoginOptions, OpenSimplifiedLoginWidget, SimplifiedLoginData, SimplifiedLoginWidgetLoginOptions, SimplifiedLoginWidgetOptions } from './types/login.js';
7
- import { ConnectedSessionResponse, SessionObjectResponse, SessionResponse } from './types/session.js';
8
- export { isConnectedSessionResponse, isSessionSuccessResponse } from './session-response.js';
9
- export type { ConnectedSessionResponse, SessionFailureResponse, SessionObjectResponse, SessionResponse, SessionSuccessResponse, SessionUserId, } from './types/session.js';
4
+ import { ConnectedSessionResponse, SessionResponse } from './types/session.js';
10
5
  declare global {
11
6
  interface Window {
12
7
  openSimplifiedLoginWidget?: OpenSimplifiedLoginWidget;
@@ -15,34 +10,33 @@ declare global {
15
10
  /**
16
11
  * Provides Identity functionalty to a web page
17
12
  */
18
- export declare class Identity extends TinyEmitter {
19
- _sessionInitiatedSent: boolean;
20
- window: Window;
21
- clientId: string;
22
- sessionStorageCache: Cache;
23
- localStorageCache: Cache;
24
- redirectUri: string;
25
- env: string;
26
- log?: LogFunction;
27
- callbackBeforeRedirect: IdentityBeforeRedirectCallback;
28
- _sessionDomain: string;
29
- _enableSessionCaching: boolean;
13
+ export declare class Identity {
14
+ private readonly eventTarget;
15
+ private readonly window;
16
+ private readonly clientId;
17
+ private readonly redirectUri;
18
+ private readonly env;
19
+ private readonly log?;
20
+ private readonly callbackBeforeRedirect;
21
+ private readonly sessionStorageCache;
22
+ private readonly localStorageCache;
23
+ private enableSessionCaching;
24
+ private readonly spid;
25
+ private readonly oauthService;
26
+ private readonly bffService;
27
+ private readonly sessionService;
28
+ private readonly globalSessionService;
29
+ private readonly usedSessionServiceGetSessionEndpoint;
30
30
  /**
31
31
  * @internal Starts as `{}` before the first `hasSession()` call, then stores the latest
32
32
  * object response from hasSession().
33
33
  */
34
- _session: SessionObjectResponse;
35
- _spid: RESTClient;
36
- _oauthService: RESTClient;
37
- _bffService: RESTClient;
38
- _sessionService: RESTClient;
39
- _globalSessionService: RESTClient;
40
- _usedSessionServiceGetSessionEndpoint: 'v2/session' | 'session';
41
- _hasSessionInProgress?: false | Promise<SessionResponse>;
42
- popup?: Window | null;
43
- setVarnishCookie?: boolean;
44
- varnishExpiresIn?: number;
45
- varnishCookieDomain?: string;
34
+ private session;
35
+ private hasSessionInProgress?;
36
+ private popup?;
37
+ private setVarnishCookie?;
38
+ private varnishExpiresIn?;
39
+ private varnishCookieDomain?;
46
40
  /**
47
41
  * @param options
48
42
  * @param options.clientId - Example: "1234567890abcdef12345678"
@@ -56,6 +50,8 @@ export declare class Identity extends TinyEmitter {
56
50
  * @throws {SDKError} - If any of options are invalid
57
51
  */
58
52
  constructor({ clientId, redirectUri, sessionDomain, env, log, window, callbackBeforeRedirect, }: IdentityOptions);
53
+ addEventListener(type: AccountEventName, listener: EventListener): void;
54
+ removeEventListener(type: AccountEventName, listener: EventListener): void;
59
55
  /**
60
56
  * Read tabId from session storage
61
57
  * @private
@@ -79,13 +75,6 @@ export declare class Identity extends TinyEmitter {
79
75
  *
80
76
  */
81
77
  _unblockSessionCall(): void;
82
- /**
83
- * Emits the relevant events based on the previous and new reply from hasSession
84
- * @private
85
- * @param previous
86
- * @param current
87
- */
88
- _emitSessionEvent(previous: object, current: object): void;
89
78
  /**
90
79
  * Close this.popup if it exists and is open
91
80
  * @private
@@ -116,25 +105,12 @@ export declare class Identity extends TinyEmitter {
116
105
  * @private
117
106
  */
118
107
  _clearVarnishCookie(): void;
119
- /**
120
- * Log used settings and version
121
- * @throws {SDKError} - If log method is not provided
122
- */
123
- logSettings(): void;
124
108
  /**
125
109
  * @summary Queries the hassession endpoint and returns information about the status of the user
126
110
  * @remarks When we send a request to this endpoint, cookies sent along with the request
127
111
  * determines the status of the user.
128
112
  * @throws {SDKError} - If the call to the hasSession service fails in any way (this will happen
129
113
  * if, say, the user is not logged in)
130
- * @fires Identity#login
131
- * @fires Identity#logout
132
- * @fires Identity#userChange
133
- * @fires Identity#sessionChange
134
- * @fires Identity#notLoggedin
135
- * @fires Identity#sessionInit
136
- * @fires Identity#statusChange
137
- * @fires Identity#error
138
114
  */
139
115
  hasSession(): Promise<SessionResponse>;
140
116
  /**
@@ -143,6 +119,13 @@ export declare class Identity extends TinyEmitter {
143
119
  * effect that it might perform an auto-login on the user
144
120
  */
145
121
  isLoggedIn(): Promise<boolean>;
122
+ /**
123
+ * Enables or disables caching for subsequent session lookups.
124
+ *
125
+ * Changing this setting does not remove an existing cached session. Use
126
+ * {@link Identity#clearCachedUserSession} to clear the cache explicitly.
127
+ */
128
+ setSessionCachingEnabled(enabled: boolean): void;
146
129
  /**
147
130
  * Removes the cached user session.
148
131
  */
@@ -166,8 +149,7 @@ export declare class Identity extends TinyEmitter {
166
149
  getUser(): Promise<ConnectedSessionResponse>;
167
150
  /**
168
151
  * @summary
169
- * In Schibsted account, there are multiple ways of identifying a user; the `userId`,
170
- * `uuid` and `externalId` used for identifying a user-merchant pair (see {@link Identity#getExternalId}).
152
+ * In Schibsted account, there are multiple ways of identifying a user; the `userId` or `uuid`.
171
153
  * There are reasons for them all to exist. The `userId` is a numeric identifier, but
172
154
  * since Schibsted account is deployed separately in Norway and Sweden, there are a lot of
173
155
  * duplicates. The `userId` was introduced early, so many sites still need to use them for
@@ -179,28 +161,6 @@ export declare class Identity extends TinyEmitter {
179
161
  * @return The `userId` field (not to be confused with the `uuid`)
180
162
  */
181
163
  getUserId(): Promise<string>;
182
- /**
183
- * @function
184
- * @summary
185
- * Retrieves the external identifier (`externalId`) for the authenticated user.
186
- *
187
- * In Schibsted Account there are multiple ways of identifying users, however for integrations with
188
- * third-parties it's recommended to use `externalId` as it does not disclose
189
- * any critical data whilst allowing for user identification.
190
- *
191
- * `externalId` is merchant-scoped using a pairwise identifier (`pairId`),
192
- * meaning the same user's ID will differ between merchants.
193
- * Additionally, this identifier is bound to the external party provided as argument.
194
- *
195
- * @param externalParty
196
- * @param optionalSuffix
197
- * @remarks This function calls {@link Identity#hasSession} internally and thus has the side
198
- * effect that it might perform an auto-login on the user
199
- * @throws {SDKError} If the `pairId` is missing in user session.
200
- * @throws {SDKError} If the `externalParty` is not defined
201
- * @return The merchant- and 3rd-party-specific `externalId`
202
- */
203
- getExternalId(externalParty: string, optionalSuffix?: string): Promise<string>;
204
164
  /**
205
165
  * @summary Enables brands to programmatically get the current the SDRN based on the user's session.
206
166
  * @remarks This function calls {@link Identity#hasSession} internally and thus has the side
@@ -253,6 +213,7 @@ export declare class Identity extends TinyEmitter {
253
213
  * @param options.xDomainId
254
214
  * @param options.xEnvironmentId
255
215
  * @param options.originCampaign
216
+ * @fires Identity#login
256
217
  * @return - Reference to popup window if created (or `null` otherwise)
257
218
  */
258
219
  login({ state, acrValues, scope, redirectUri, preferPopup, loginHint, tag, teaser, maxAge, locale, oneStepLogin, prompt, xDomainId, xEnvironmentId, originCampaign, }: LoginOptions): Window | null;
@@ -265,8 +226,8 @@ export declare class Identity extends TinyEmitter {
265
226
  getSpId(): Promise<string | null>;
266
227
  /**
267
228
  * @summary Logs the user out from the Identity platform
268
- * @param redirectUri - Where to redirect the browser after logging out of Schibsted
269
- * account
229
+ * @param redirectUri - Where to redirect the browser after logging out of Schibsted account
230
+ * @fires Identity#logout
270
231
  */
271
232
  logout(redirectUri?: string): void;
272
233
  /**
@@ -300,11 +261,6 @@ export declare class Identity extends TinyEmitter {
300
261
  * @param redirectUri
301
262
  */
302
263
  accountUrl(redirectUri?: string): string;
303
- /**
304
- * The phone editing page url
305
- * @param redirectUri
306
- */
307
- phonesUrl(redirectUri?: string): string;
308
264
  /**
309
265
  * Function responsible for loading and displaying simplified login widget. How often
310
266
  * widget will be display is up to you. Preferred way would be to show it once per user,
package/dist/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  export { Account } from './account.js';
2
2
  export { createAccountSdk, getAccountSdk } from './account-sdk.js';
3
+ export * from './globals.js';
3
4
  export { default as SDKError } from './sdk-error.js';
4
- export type { AccountConfig, AccountEventHandler, AccountEventName, AccountSessionEventName, } from './types/account.js';
5
+ export type { AccountConfig, AccountEventListener, AccountEventName, } from './types/account.js';
5
6
  export type { AccountEnvironment, LogFunction } from './types/common.js';
6
7
  export type { LoginOptions, SimplifiedLoginData, SimplifiedLoginWidgetLoginOptions, SimplifiedLoginWidgetOptions, } from './types/login.js';
7
8
  export type { HasAccessResult } from './types/monetization.js';