@schibsted/account-sdk-browser 6.0.0-alpha.5 → 6.0.0-alpha.7

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,31 +1,167 @@
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
+ */
16
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
+ */
17
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
+ */
18
70
  getUserContextData(): Promise<SimplifiedLoginData | null>;
71
+ /**
72
+ * Returns the Varnish `sp_id` value from the current session when present.
73
+ */
19
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
+ */
20
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
+ */
21
90
  logout(redirectUri?: string): void;
91
+ /**
92
+ * Builds the login URL without navigating the browser.
93
+ *
94
+ * @param options - Login URL parameters.
95
+ */
22
96
  loginUrl(options: LoginOptions): string;
97
+ /**
98
+ * Builds the logout URL without navigating the browser.
99
+ *
100
+ * @param redirectUri - Where Session Service should redirect the browser after logout.
101
+ */
102
+ logoutUrl(redirectUri?: string): string;
103
+ /**
104
+ * Builds the Schibsted Account profile page URL.
105
+ *
106
+ * @param redirectUri - Where the account page should redirect the browser afterwards.
107
+ */
23
108
  accountUrl(redirectUri?: string): string;
109
+ /**
110
+ * Loads and displays the simplified login widget when user context is available.
111
+ *
112
+ * Your application decides how often to call this method. The `state` field in `loginParams`
113
+ * may be a string or a function that resolves to a string.
114
+ * Widget open and cancel events can be observed with `on()`.
115
+ *
116
+ * @returns `true` when the widget was displayed.
117
+ * @throws {SDKError} If user context data is missing or the widget script cannot be loaded.
118
+ */
24
119
  showSimplifiedLoginWidget(loginParams: SimplifiedLoginWidgetLoginOptions, options?: SimplifiedLoginWidgetOptions): Promise<boolean>;
120
+ /**
121
+ * Enables or disables caching for subsequent session lookups.
122
+ *
123
+ * Changing this setting does not remove an existing cached session.
124
+ */
125
+ setSessionCachingEnabled(enabled: boolean): void;
126
+ /**
127
+ * Removes the cached Session Service user session response.
128
+ */
25
129
  clearCachedUserSession(): void;
130
+ /**
131
+ * Checks whether a user has access to any of the requested products or features.
132
+ *
133
+ * Results are cached according to the TTL returned by Session Service.
134
+ *
135
+ * @param productIds - Product or feature ids to check.
136
+ * @param userId - Current user id, usually from `getUserId()`.
137
+ * @returns Access data, or `null` when the user is not entitled.
138
+ * @throws {SDKError} If `sessionDomain` is missing, input is invalid, or the request fails.
139
+ */
26
140
  hasAccess(productIds: string[], userId: SessionUserId): Promise<HasAccessResult | null>;
141
+ /**
142
+ * Removes a cached access-check result.
143
+ *
144
+ * @param productIds - Product or feature ids used for the cached lookup.
145
+ * @param userId - User id used for the cached lookup.
146
+ */
27
147
  clearCachedAccessResult(productIds: string[], userId: SessionUserId): void;
28
- on(event: AccountEventName, callback: AccountEventHandler, ctx?: unknown): this;
29
- off(event: AccountEventName, callback?: AccountEventHandler): this;
148
+ /**
149
+ * Subscribes to Account events.
150
+ *
151
+ * Supported event names are defined by {@link AccountEventName}.
152
+ *
153
+ * @param event - Event name.
154
+ * @param listener - Listener that receives an `Event` or `CustomEvent`.
155
+ */
156
+ on<EventName extends AccountEventName>(event: EventName, listener: AccountEventListener<EventName>): this;
157
+ /**
158
+ * Unsubscribes from Account events.
159
+ *
160
+ * Supported event names are defined by {@link AccountEventName}.
161
+ *
162
+ * @param event - Event name.
163
+ * @param listener - Listener to remove.
164
+ */
165
+ off<EventName extends AccountEventName>(event: EventName, listener: AccountEventListener<EventName>): this;
30
166
  }
31
167
  export default Account;
@@ -1,10 +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';
4
+ import { ConnectedSessionResponse, SessionResponse } from './types/session.js';
8
5
  declare global {
9
6
  interface Window {
10
7
  openSimplifiedLoginWidget?: OpenSimplifiedLoginWidget;
@@ -13,33 +10,33 @@ declare global {
13
10
  /**
14
11
  * Provides Identity functionalty to a web page
15
12
  */
16
- export declare class Identity extends TinyEmitter {
17
- window: Window;
18
- clientId: string;
19
- sessionStorageCache: Cache;
20
- localStorageCache: Cache;
21
- redirectUri: string;
22
- env: string;
23
- log?: LogFunction;
24
- callbackBeforeRedirect: IdentityBeforeRedirectCallback;
25
- _sessionDomain: string;
26
- _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;
27
30
  /**
28
31
  * @internal Starts as `{}` before the first `hasSession()` call, then stores the latest
29
32
  * object response from hasSession().
30
33
  */
31
- _session: SessionObjectResponse;
32
- _spid: RESTClient;
33
- _oauthService: RESTClient;
34
- _bffService: RESTClient;
35
- _sessionService: RESTClient;
36
- _globalSessionService: RESTClient;
37
- _usedSessionServiceGetSessionEndpoint: 'v2/session' | 'session';
38
- _hasSessionInProgress?: false | Promise<SessionResponse>;
39
- popup?: Window | null;
40
- setVarnishCookie?: boolean;
41
- varnishExpiresIn?: number;
42
- varnishCookieDomain?: string;
34
+ private session;
35
+ private hasSessionInProgress?;
36
+ private popup?;
37
+ private setVarnishCookie?;
38
+ private varnishExpiresIn?;
39
+ private varnishCookieDomain?;
43
40
  /**
44
41
  * @param options
45
42
  * @param options.clientId - Example: "1234567890abcdef12345678"
@@ -53,6 +50,8 @@ export declare class Identity extends TinyEmitter {
53
50
  * @throws {SDKError} - If any of options are invalid
54
51
  */
55
52
  constructor({ clientId, redirectUri, sessionDomain, env, log, window, callbackBeforeRedirect, }: IdentityOptions);
53
+ addEventListener(type: AccountEventName, listener: EventListener): void;
54
+ removeEventListener(type: AccountEventName, listener: EventListener): void;
56
55
  /**
57
56
  * Read tabId from session storage
58
57
  * @private
@@ -76,13 +75,6 @@ export declare class Identity extends TinyEmitter {
76
75
  *
77
76
  */
78
77
  _unblockSessionCall(): void;
79
- /**
80
- * Emits the relevant events based on the previous and new reply from hasSession
81
- * @private
82
- * @param previous
83
- * @param current
84
- */
85
- _emitSessionEvent(previous: object, current: object): void;
86
78
  /**
87
79
  * Close this.popup if it exists and is open
88
80
  * @private
@@ -119,8 +111,6 @@ export declare class Identity extends TinyEmitter {
119
111
  * determines the status of the user.
120
112
  * @throws {SDKError} - If the call to the hasSession service fails in any way (this will happen
121
113
  * if, say, the user is not logged in)
122
- * @fires Identity#login
123
- * @fires Identity#logout
124
114
  */
125
115
  hasSession(): Promise<SessionResponse>;
126
116
  /**
@@ -129,6 +119,13 @@ export declare class Identity extends TinyEmitter {
129
119
  * effect that it might perform an auto-login on the user
130
120
  */
131
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;
132
129
  /**
133
130
  * Removes the cached user session.
134
131
  */
@@ -216,6 +213,7 @@ export declare class Identity extends TinyEmitter {
216
213
  * @param options.xDomainId
217
214
  * @param options.xEnvironmentId
218
215
  * @param options.originCampaign
216
+ * @fires Identity#login
219
217
  * @return - Reference to popup window if created (or `null` otherwise)
220
218
  */
221
219
  login({ state, acrValues, scope, redirectUri, preferPopup, loginHint, tag, teaser, maxAge, locale, oneStepLogin, prompt, xDomainId, xEnvironmentId, originCampaign, }: LoginOptions): Window | null;
@@ -228,8 +226,8 @@ export declare class Identity extends TinyEmitter {
228
226
  getSpId(): Promise<string | null>;
229
227
  /**
230
228
  * @summary Logs the user out from the Identity platform
231
- * @param redirectUri - Where to redirect the browser after logging out of Schibsted
232
- * account
229
+ * @param redirectUri - Where to redirect the browser after logging out of Schibsted account
230
+ * @fires Identity#logout
233
231
  */
234
232
  logout(redirectUri?: string): void;
235
233
  /**
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ export { Account } from './account.js';
2
2
  export { createAccountSdk, getAccountSdk } from './account-sdk.js';
3
3
  export * from './globals.js';
4
4
  export { default as SDKError } from './sdk-error.js';
5
- export type { AccountConfig, AccountEventHandler, AccountEventName, } from './types/account.js';
5
+ export type { AccountConfig, AccountEventListener, AccountEventName, } from './types/account.js';
6
6
  export type { AccountEnvironment, LogFunction } from './types/common.js';
7
7
  export type { LoginOptions, SimplifiedLoginData, SimplifiedLoginWidgetLoginOptions, SimplifiedLoginWidgetOptions, } from './types/login.js';
8
8
  export type { HasAccessResult } from './types/monetization.js';