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

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.
@@ -21,7 +21,7 @@ export declare class Monetization {
21
21
  * @returns The data object returned from Schibsted account (or `null` if the user
22
22
  * doesn't have access to any of the given products/features)
23
23
  */
24
- hasAccess(productIds: string[], userId: SessionUserId): Promise<HasAccessResult | null>;
24
+ hasAccess(productIds: readonly string[], userId: SessionUserId): Promise<HasAccessResult | null>;
25
25
  /**
26
26
  * Removes the cached access result.
27
27
  * @param productIds - which products/features to check
@@ -0,0 +1,21 @@
1
+ //#region src/sdk-error.ts
2
+ var e = [
3
+ "boolean",
4
+ "number",
5
+ "string"
6
+ ], t = class extends Error {
7
+ code;
8
+ constructor(e, t) {
9
+ if (super(e), this.name = "SDKError", t) try {
10
+ Object.assign(this, t);
11
+ } catch {}
12
+ }
13
+ toString() {
14
+ let t = `${this.name}: ${this.message}`, n = Object.keys(this).filter((t) => t !== "name" && e.includes(typeof this[t])).map((e) => ` ${e}: ${this[e]}`).join("\n");
15
+ return n ? `${t}\n${n}` : t;
16
+ }
17
+ }, n = /* @__PURE__ */ new WeakMap(), r = (e) => e || (typeof window > "u" ? void 0 : window);
18
+ //#endregion
19
+ export { n, t as r, r as t };
20
+
21
+ //# sourceMappingURL=resolve-browser-window-wUnycyxt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-browser-window-wUnycyxt.js","names":[],"sources":["../src/sdk-error.ts","../src/session-state.ts","../src/resolve-browser-window.ts"],"sourcesContent":["/* Copyright 2024 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.\n * See LICENSE.md in the project root.\n */\n\n/*\n * Note: this module can't have any internal dependencies because it's used in ./validate which\n * in turn is used as a dependency to a lot of other modules. Doing so may create a circular\n * dependency that's hard to debug in Node.\n */\n\nconst STRINGIFY_TYPES = ['boolean', 'number', 'string'];\n\n/**\n * Custom error class thrown by all SDK methods on failure.\n *\n * All rejected promises from API calls reject with an instance of this class.\n *\n * @group Errors\n */\nexport default class SDKError extends Error {\n /** HTTP status code from the server error payload;\n * declared explicitly to allow numeric comparisons without type-casting.\n */\n code?: number;\n /**\n * Properties copied from the server error object.\n * @internal\n */\n [key: string]: unknown;\n\n /**\n * @param message - Human-readable error message\n * @param errorObject - Optional server error payload. All enumerable properties are\n * shallow-copied onto this instance.\n */\n constructor(message: string, errorObject?: Record<string, unknown>) {\n super(message);\n this.name = 'SDKError';\n\n if (errorObject) {\n try {\n Object.assign(this, errorObject);\n } catch {\n // silent\n }\n }\n }\n\n /**\n * Returns a multi-line string with the error name, message, and any other properties copied\n * from the server error payload.\n */\n toString(): string {\n const ret = `${this.name}: ${this.message}`;\n const additionalInfo = Object.keys(this)\n .filter((key) => key !== 'name' && STRINGIFY_TYPES.includes(typeof this[key]))\n .map((key) => ` ${key}: ${this[key]}`)\n .join('\\n');\n return additionalInfo ? `${ret}\\n${additionalInfo}` : ret;\n }\n}\n","/* Copyright 2026 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.\n * See LICENSE.md in the project root.\n */\n\nimport type { SessionObjectResponse } from './types/session.js';\n\n/**\n * Minimal core bridge for the optional compatibility layer; not a public API.\n * Sourcepoint reads legacy `_session` synchronously, but Account only exposes async\n * session lookups. Mirroring `sessionUpdated` would miss updates with an unchanged\n * session ID, so the shim reads Identity's actual state instead of keeping a copy.\n * Legacy behavior stays in compatibility; remove this bridge with the shims in v7.\n */\nexport type SessionState = {\n getSession: () => SessionObjectResponse;\n // Lets the shim notify legacy logout listeners before the session is replaced, as in v5.\n beforeUpdate?: (previous: SessionObjectResponse, current: SessionObjectResponse) => void;\n};\n\nexport const sessionStates = new WeakMap<object, SessionState>();\n","/* Copyright 2026 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.\n * See LICENSE.md in the project root.\n */\n\nexport const resolveBrowserWindow = (providedWindow?: Window): Window | undefined => {\n if (providedWindow) {\n return providedWindow;\n }\n\n return typeof window === 'undefined' ? undefined : window;\n};\n"],"mappings":";AAUA,IAAM,IAAkB;CAAC;CAAW;CAAU;AAAQ,GASjC,IAArB,cAAsC,MAAM;CAIxC;CAYA,YAAY,GAAiB,GAAuC;EAIhE,IAHA,MAAM,CAAO,GACb,KAAK,OAAO,YAER,GACA,IAAI;GACA,OAAO,OAAO,MAAM,CAAW;EACnC,QAAQ,CAER;CAER;CAMA,WAAmB;EACf,IAAM,IAAM,GAAG,KAAK,KAAK,IAAI,KAAK,WAC5B,IAAiB,OAAO,KAAK,IAAI,EAClC,QAAQ,MAAQ,MAAQ,UAAU,EAAgB,SAAS,OAAO,KAAK,EAAI,CAAC,EAC5E,KAAK,MAAQ,OAAO,EAAI,IAAI,KAAK,IAAM,EACvC,KAAK,IAAI;EACd,OAAO,IAAiB,GAAG,EAAI,IAAI,MAAmB;CAC1D;AACJ,GCzCa,oBAAgB,IAAI,QAA8B,GCflD,KAAwB,MAC7B,MAIG,OAAO,SAAW,MAAc,KAAA,IAAY"}
@@ -6,23 +6,43 @@ import { SessionResponse } from './session';
6
6
  *
7
7
  * @group Configuration
8
8
  */
9
- export type AccountConfig = AccountBaseConfig & {
9
+ export type AccountConfig = Omit<AccountBaseConfig, 'env'> & {
10
+ /** Schibsted account environment. Defaults to PRE. */
11
+ env?: AccountBaseConfig['env'];
10
12
  /** Receives debug log information. If not set, no logging will be done. */
11
13
  log?: LogFunction;
12
14
  /** Callback triggered before a session refresh redirect happens. */
13
15
  callbackBeforeRedirect?: IdentityBeforeRedirectCallback;
14
16
  /** Product or feature ids used by `hasAccess()` when no ids are passed to the method. */
15
- defaultProductIds?: string[];
17
+ defaultProductIds?: readonly string[];
16
18
  /** Optional Varnish cookie setup applied during Account initialization. */
17
19
  varnish?: VarnishCookieOptions;
18
20
  };
19
- type LoginRequestedEventDetail = {
21
+ /**
22
+ * Detail payload for the `loginRequested` event.
23
+ *
24
+ * @group Events
25
+ */
26
+ export type LoginRequestedEventDetail = {
27
+ /** Authorization URL the login flow navigates to. */
20
28
  url: string;
29
+ /** Whether the login flow opens in a popup or redirects the current window. */
21
30
  method: 'popup' | 'default';
22
31
  };
23
- type LogoutRequestedEventDetail = {
32
+ /**
33
+ * Detail payload for the `logoutRequested` event.
34
+ *
35
+ * @group Events
36
+ */
37
+ export type LogoutRequestedEventDetail = {
38
+ /** Session Service logout URL the browser is redirected to. */
24
39
  url: string;
25
40
  };
41
+ /**
42
+ * Account events emitted by the SDK.
43
+ *
44
+ * @group Events
45
+ */
26
46
  export type AccountEventMap = {
27
47
  /** Emitted with the login URL and method when `login()` initiates a login flow. */
28
48
  loginRequested: CustomEvent<LoginRequestedEventDetail>;
@@ -35,7 +55,11 @@ export type AccountEventMap = {
35
55
  /** Emitted when the simplified login widget is closed. */
36
56
  simplifiedLoginCancelled: Event;
37
57
  };
38
- /** Account event names emitted by the SDK. */
58
+ /**
59
+ * Account event names emitted by the SDK.
60
+ *
61
+ * @group Events
62
+ */
39
63
  export type AccountEventName = keyof AccountEventMap;
40
64
  /**
41
65
  * Native event listener used by Account event subscriptions.
@@ -45,4 +69,3 @@ export type AccountEventName = keyof AccountEventMap;
45
69
  * @group Events
46
70
  */
47
71
  export type AccountEventListener<EventName extends AccountEventName = AccountEventName> = (event: AccountEventMap[EventName]) => void;
48
- export {};
@@ -21,8 +21,8 @@ export type AccountBaseConfig = {
21
21
  redirectUri: string;
22
22
  /** Session Service domain. Example: "https://id.site.com" */
23
23
  sessionDomain: string;
24
- /** Schibsted account environment. Defaults to PRE. */
25
- env?: AccountEnvironment;
24
+ /** Schibsted account environment. */
25
+ env: AccountEnvironment;
26
26
  /** Window object to use. Defaults to the global `window`. */
27
27
  window?: Window;
28
28
  };
@@ -74,6 +74,7 @@ export type SessionSuccessResponse = {
74
74
  * @group Session
75
75
  */
76
76
  export type ConnectedSessionResponse = SessionSuccessResponse & {
77
+ /** Always `true`: the user is connected to the merchant. */
77
78
  result: true;
78
79
  };
79
80
  /**
@@ -82,6 +83,7 @@ export type ConnectedSessionResponse = SessionSuccessResponse & {
82
83
  * @group Session
83
84
  */
84
85
  export type ConnectedSessionWithUserIdResponse = ConnectedSessionResponse & {
86
+ /** A numeric user id which is unique per realm (country). Example: 37162 */
85
87
  userId: SessionUserId;
86
88
  };
87
89
  /**
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- declare const version = "6.0.0-alpha.11";
1
+ declare const version = "6.0.0-alpha.13";
2
2
  export default version;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@schibsted/account-sdk-browser",
3
- "version": "6.0.0-alpha.11",
3
+ "version": "6.0.0-alpha.13",
4
4
  "description": "Schibsted account SDK for browsers",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
package/src/account.ts CHANGED
@@ -8,6 +8,7 @@ import { resolveBrowserWindow } from './resolve-browser-window.js';
8
8
  import SDKError from './sdk-error.js';
9
9
  import { sessionStates } from './session-state.js';
10
10
  import type { AccountConfig, AccountEventListener, AccountEventName } from './types/account.js';
11
+ import type { AccountEnvironment } from './types/common.js';
11
12
  import type {
12
13
  LoginOptions,
13
14
  SimplifiedLoginData,
@@ -27,9 +28,12 @@ import type { ConnectedSessionResponse, SessionResponse, SessionUserId } from '.
27
28
  * @group Core API
28
29
  */
29
30
  export class Account {
31
+ readonly #clientId: string;
32
+ readonly #env: AccountEnvironment;
33
+ readonly #redirectUri: string;
34
+ readonly #defaultProductIds: readonly string[] | undefined;
30
35
  #identity: Identity;
31
36
  #monetization: Monetization;
32
- #defaultProductIds?: string[];
33
37
 
34
38
  constructor(config: AccountConfig) {
35
39
  const browserWindow = resolveBrowserWindow(config.window);
@@ -47,7 +51,7 @@ export class Account {
47
51
  clientId: config.clientId,
48
52
  redirectUri: config.redirectUri,
49
53
  sessionDomain: config.sessionDomain,
50
- env: config.env,
54
+ env: config.env ?? 'PRE',
51
55
  window: browserWindow,
52
56
  };
53
57
 
@@ -60,17 +64,22 @@ export class Account {
60
64
  if (defaultProductIds !== undefined && !Array.isArray(defaultProductIds)) {
61
65
  throw new SDKError('Account defaultProductIds config must be an array');
62
66
  }
63
- this.#defaultProductIds = defaultProductIds;
67
+ if (varnish && (typeof varnish !== 'object' || Array.isArray(varnish))) {
68
+ throw new SDKError('Account varnish config must be an object');
69
+ }
64
70
 
65
71
  if (varnish) {
66
- if (typeof varnish !== 'object' || Array.isArray(varnish)) {
67
- throw new SDKError('Account varnish config must be an object');
68
- }
69
72
  this.#identity.enableVarnishCookie(varnish);
70
73
  }
71
74
 
72
75
  this.#monetization = new Monetization(sharedConfig);
73
76
 
77
+ this.#clientId = sharedConfig.clientId;
78
+ this.#env = sharedConfig.env;
79
+ this.#redirectUri = sharedConfig.redirectUri;
80
+ // Copy and freeze so neither the caller nor readers of `defaultProductIds` can change SDK behavior.
81
+ this.#defaultProductIds = defaultProductIds && Object.freeze([...defaultProductIds]);
82
+
74
83
  const sessionState = sessionStates.get(this.#identity);
75
84
  if (sessionState) {
76
85
  sessionStates.set(this, sessionState);
@@ -81,6 +90,30 @@ export class Account {
81
90
  );
82
91
  }
83
92
 
93
+ /** The client id this instance was configured with. */
94
+ get clientId(): string {
95
+ return this.#clientId;
96
+ }
97
+
98
+ /** The Schibsted Account environment this instance was configured with. Defaults to PRE. */
99
+ get env(): AccountEnvironment {
100
+ return this.#env;
101
+ }
102
+
103
+ /** The redirect uri this instance was configured with. */
104
+ get redirectUri(): string {
105
+ return this.#redirectUri;
106
+ }
107
+
108
+ /**
109
+ * The product or feature ids `hasAccess()` uses when no ids are passed, if configured.
110
+ *
111
+ * The returned array is a frozen copy; it cannot be mutated.
112
+ */
113
+ get defaultProductIds(): readonly string[] | undefined {
114
+ return this.#defaultProductIds;
115
+ }
116
+
84
117
  /**
85
118
  * Queries Session Service and returns the current browser session state.
86
119
  *
@@ -5,7 +5,6 @@
5
5
  import type { Account } from '../account.js';
6
6
  import { resolveBrowserWindow } from '../resolve-browser-window.js';
7
7
  import SDKError from '../sdk-error.js';
8
- import { assert, isNonEmptyString } from '../validate.js';
9
8
  import { LegacyIdentityAdapter } from './legacy-identity.js';
10
9
  import { LegacyMonetizationAdapter } from './legacy-monetization.js';
11
10
  import type { LegacyCompatibilityOptions } from './types.js';
@@ -66,10 +65,10 @@ const dispatchReadyEvent = <Instance>(
66
65
  browserWindow.dispatchEvent(new CustomEvent(eventName, { detail: { instance } }));
67
66
  };
68
67
 
69
- const installLegacyGlobals = (browserWindow: Window, account: Account, clientId: string): void => {
68
+ const installLegacyGlobals = (browserWindow: Window, account: Account): void => {
70
69
  assertLegacyGlobalsAvailable(browserWindow);
71
70
 
72
- const identityShim = new LegacyIdentityAdapter(account, clientId);
71
+ const identityShim = new LegacyIdentityAdapter(account);
73
72
  const monetizationShim = new LegacyMonetizationAdapter(account);
74
73
  const identityGetter = () => {
75
74
  warnLegacyUsage('window.schIdentity', 'window.schAccount');
@@ -106,11 +105,7 @@ const installLegacyGlobals = (browserWindow: Window, account: Account, clientId:
106
105
  *
107
106
  * @deprecated Migrate dependencies to the Account API. This entrypoint will be removed in v7.
108
107
  */
109
- export function enableLegacyCompatibility(options: LegacyCompatibilityOptions): void {
110
- assert(
111
- isNonEmptyString(options?.clientId),
112
- 'Account SDK legacy compatibility requires a clientId',
113
- );
108
+ export function enableLegacyCompatibility(options: LegacyCompatibilityOptions = {}): void {
114
109
  const browserWindow = resolveBrowserWindow(options.window);
115
110
  if (!browserWindow) {
116
111
  throw createUnavailableError();
@@ -127,7 +122,7 @@ export function enableLegacyCompatibility(options: LegacyCompatibilityOptions):
127
122
  enabledWindows.add(browserWindow);
128
123
 
129
124
  if (browserWindow.schAccount) {
130
- installLegacyGlobals(browserWindow, browserWindow.schAccount, options.clientId);
125
+ installLegacyGlobals(browserWindow, browserWindow.schAccount);
131
126
  return;
132
127
  }
133
128
 
@@ -137,7 +132,7 @@ export function enableLegacyCompatibility(options: LegacyCompatibilityOptions):
137
132
  if (!browserWindow.schAccount) {
138
133
  throw createMissingAccountError();
139
134
  }
140
- installLegacyGlobals(browserWindow, browserWindow.schAccount, options.clientId);
135
+ installLegacyGlobals(browserWindow, browserWindow.schAccount);
141
136
  },
142
137
  { once: true },
143
138
  );
@@ -5,6 +5,7 @@
5
5
  import type { Account } from '../account.js';
6
6
  import SDKError from '../sdk-error.js';
7
7
  import { type SessionState, sessionStates } from '../session-state.js';
8
+ import type { AccountEnvironment } from '../types/common.js';
8
9
  import type { LoginOptions } from '../types/login.js';
9
10
  import type { SessionObjectResponse } from '../types/session.js';
10
11
  import type { LegacyIdentity, LegacyLogoutListener } from './types.js';
@@ -12,13 +13,11 @@ import { warnLegacyUsage } from './warnings.js';
12
13
 
13
14
  export class LegacyIdentityAdapter implements LegacyIdentity {
14
15
  readonly #account: Account;
15
- readonly #clientId: string;
16
16
  readonly #sessionState: SessionState;
17
17
  #logoutListeners: { listener: LegacyLogoutListener; context?: unknown }[] = [];
18
18
 
19
- constructor(account: Account, clientId: string) {
19
+ constructor(account: Account) {
20
20
  this.#account = account;
21
- this.#clientId = clientId;
22
21
 
23
22
  const sessionState = sessionStates.get(account);
24
23
  if (!sessionState) {
@@ -39,8 +38,18 @@ export class LegacyIdentityAdapter implements LegacyIdentity {
39
38
  }
40
39
 
41
40
  get clientId(): string {
42
- warnLegacyUsage('schIdentity.clientId', 'the application Account configuration');
43
- return this.#clientId;
41
+ warnLegacyUsage('schIdentity.clientId', 'account.clientId');
42
+ return this.#account.clientId;
43
+ }
44
+
45
+ get env(): AccountEnvironment {
46
+ warnLegacyUsage('schIdentity.env', 'account.env');
47
+ return this.#account.env;
48
+ }
49
+
50
+ get redirectUri(): string {
51
+ warnLegacyUsage('schIdentity.redirectUri', 'account.redirectUri');
52
+ return this.#account.redirectUri;
44
53
  }
45
54
 
46
55
  get _session(): LegacyIdentity['_session'] {
@@ -3,6 +3,7 @@
3
3
  */
4
4
 
5
5
  import type { Account } from '../account.js';
6
+ import type { AccountEnvironment } from '../types/common.js';
6
7
  import type { LoginOptions } from '../types/login.js';
7
8
  import type { SessionObjectResponse, SessionUserId } from '../types/session.js';
8
9
 
@@ -42,8 +43,12 @@ export type LegacyIdentity = LegacyIdentityMethods & {
42
43
  teaser?: string,
43
44
  maxAge?: number | string,
44
45
  ): string;
45
- /** @deprecated Read the client id from application configuration. Removed in v7. */
46
+ /** @deprecated Use `account.clientId`. Removed in v7. */
46
47
  readonly clientId: string;
48
+ /** @deprecated Use `account.env`. Removed in v7. */
49
+ readonly env: AccountEnvironment;
50
+ /** @deprecated Use `account.redirectUri`. Removed in v7. */
51
+ readonly redirectUri: string;
47
52
  /** @deprecated Use the Account session methods and events. Removed in v7. */
48
53
  readonly _session: SessionObjectResponse;
49
54
  /** @deprecated Only the legacy `logout` event is bridged. Removed in v7. */
@@ -58,8 +63,6 @@ export interface LegacyMonetization {
58
63
  }
59
64
 
60
65
  export type LegacyCompatibilityOptions = {
61
- /** Client id exposed on the legacy Identity adapter for Sourcepoint compatibility. */
62
- clientId: string;
63
66
  /** Window on which the legacy globals and ready events should be installed. */
64
67
  window?: Window;
65
68
  };
package/src/identity.ts CHANGED
@@ -119,7 +119,7 @@ export class Identity {
119
119
  clientId,
120
120
  redirectUri,
121
121
  sessionDomain,
122
- env = 'PRE',
122
+ env,
123
123
  log,
124
124
  window = globalWindow(),
125
125
  callbackBeforeRedirect = () => {},
package/src/index.ts CHANGED
@@ -19,7 +19,10 @@ export {
19
19
  export type {
20
20
  AccountConfig,
21
21
  AccountEventListener,
22
+ AccountEventMap,
22
23
  AccountEventName,
24
+ LoginRequestedEventDetail,
25
+ LogoutRequestedEventDetail,
23
26
  } from './types/account.js';
24
27
  export type { AccountEnvironment, LogFunction } from './types/common.js';
25
28
  export type {
@@ -30,7 +30,7 @@ export class Monetization {
30
30
  constructor({
31
31
  clientId,
32
32
  redirectUri,
33
- env = 'PRE',
33
+ env,
34
34
  sessionDomain,
35
35
  window = globalWindow(),
36
36
  }: MonetizationOptions) {
@@ -64,7 +64,10 @@ export class Monetization {
64
64
  * @returns The data object returned from Schibsted account (or `null` if the user
65
65
  * doesn't have access to any of the given products/features)
66
66
  */
67
- async hasAccess(productIds: string[], userId: SessionUserId): Promise<HasAccessResult | null> {
67
+ async hasAccess(
68
+ productIds: readonly string[],
69
+ userId: SessionUserId,
70
+ ): Promise<HasAccessResult | null> {
68
71
  if (!this.sessionService) {
69
72
  throw new SDKError(`hasAccess can only be called if 'sessionDomain' is configured`);
70
73
  }
@@ -7,26 +7,46 @@ import type { SessionResponse } from './session';
7
7
  *
8
8
  * @group Configuration
9
9
  */
10
- export type AccountConfig = AccountBaseConfig & {
10
+ export type AccountConfig = Omit<AccountBaseConfig, 'env'> & {
11
+ /** Schibsted account environment. Defaults to PRE. */
12
+ env?: AccountBaseConfig['env'];
11
13
  /** Receives debug log information. If not set, no logging will be done. */
12
14
  log?: LogFunction;
13
15
  /** Callback triggered before a session refresh redirect happens. */
14
16
  callbackBeforeRedirect?: IdentityBeforeRedirectCallback;
15
17
  /** Product or feature ids used by `hasAccess()` when no ids are passed to the method. */
16
- defaultProductIds?: string[];
18
+ defaultProductIds?: readonly string[];
17
19
  /** Optional Varnish cookie setup applied during Account initialization. */
18
20
  varnish?: VarnishCookieOptions;
19
21
  };
20
22
 
21
- type LoginRequestedEventDetail = {
23
+ /**
24
+ * Detail payload for the `loginRequested` event.
25
+ *
26
+ * @group Events
27
+ */
28
+ export type LoginRequestedEventDetail = {
29
+ /** Authorization URL the login flow navigates to. */
22
30
  url: string;
31
+ /** Whether the login flow opens in a popup or redirects the current window. */
23
32
  method: 'popup' | 'default';
24
33
  };
25
34
 
26
- type LogoutRequestedEventDetail = {
35
+ /**
36
+ * Detail payload for the `logoutRequested` event.
37
+ *
38
+ * @group Events
39
+ */
40
+ export type LogoutRequestedEventDetail = {
41
+ /** Session Service logout URL the browser is redirected to. */
27
42
  url: string;
28
43
  };
29
44
 
45
+ /**
46
+ * Account events emitted by the SDK.
47
+ *
48
+ * @group Events
49
+ */
30
50
  export type AccountEventMap = {
31
51
  /** Emitted with the login URL and method when `login()` initiates a login flow. */
32
52
  loginRequested: CustomEvent<LoginRequestedEventDetail>;
@@ -40,7 +60,11 @@ export type AccountEventMap = {
40
60
  simplifiedLoginCancelled: Event;
41
61
  };
42
62
 
43
- /** Account event names emitted by the SDK. */
63
+ /**
64
+ * Account event names emitted by the SDK.
65
+ *
66
+ * @group Events
67
+ */
44
68
  export type AccountEventName = keyof AccountEventMap;
45
69
 
46
70
  /**
@@ -25,8 +25,8 @@ export type AccountBaseConfig = {
25
25
  redirectUri: string;
26
26
  /** Session Service domain. Example: "https://id.site.com" */
27
27
  sessionDomain: string;
28
- /** Schibsted account environment. Defaults to PRE. */
29
- env?: AccountEnvironment;
28
+ /** Schibsted account environment. */
29
+ env: AccountEnvironment;
30
30
  /** Window object to use. Defaults to the global `window`. */
31
31
  window?: Window;
32
32
  };
@@ -82,6 +82,7 @@ export type SessionSuccessResponse = {
82
82
  * @group Session
83
83
  */
84
84
  export type ConnectedSessionResponse = SessionSuccessResponse & {
85
+ /** Always `true`: the user is connected to the merchant. */
85
86
  result: true;
86
87
  };
87
88
 
@@ -91,6 +92,7 @@ export type ConnectedSessionResponse = SessionSuccessResponse & {
91
92
  * @group Session
92
93
  */
93
94
  export type ConnectedSessionWithUserIdResponse = ConnectedSessionResponse & {
95
+ /** A numeric user id which is unique per realm (country). Example: 37162 */
94
96
  userId: SessionUserId;
95
97
  };
96
98
 
package/src/version.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  // Version is bumped automatically by release-please. See release-please-config.json.
2
2
 
3
- const version = '6.0.0-alpha.11'; // x-release-please-version
3
+ const version = '6.0.0-alpha.13'; // x-release-please-version
4
4
  export default version;
@@ -1,55 +0,0 @@
1
- //#region src/sdk-error.ts
2
- var e = [
3
- "boolean",
4
- "number",
5
- "string"
6
- ], t = class extends Error {
7
- code;
8
- constructor(e, t) {
9
- if (super(e), this.name = "SDKError", t) try {
10
- Object.assign(this, t);
11
- } catch {}
12
- }
13
- toString() {
14
- let t = `${this.name}: ${this.message}`, n = Object.keys(this).filter((t) => t !== "name" && e.includes(typeof this[t])).map((e) => ` ${e}: ${this[e]}`).join("\n");
15
- return n ? `${t}\n${n}` : t;
16
- }
17
- };
18
- //#endregion
19
- //#region src/validate.ts
20
- function n(e, n = "Assertion failed") {
21
- if (!e) throw new t(n);
22
- }
23
- function r(e) {
24
- return typeof e == "string";
25
- }
26
- function i(e) {
27
- return typeof e == "string" && e.length > 0;
28
- }
29
- function a(e) {
30
- return typeof e == "object" && !!e;
31
- }
32
- function o(e) {
33
- return a(e) && Object.keys(e).length > 0;
34
- }
35
- function s(e, ...t) {
36
- try {
37
- let n = new URL(e);
38
- return t.every((e) => n[e]);
39
- } catch {
40
- return !1;
41
- }
42
- }
43
- function c(e) {
44
- return typeof e == "function";
45
- }
46
- function l(e, t, n = !1) {
47
- return r(e) && Array.isArray(t) ? n ? t.indexOf(e) !== -1 : t.some((t) => r(t) && e.toUpperCase() === t.toUpperCase()) : !1;
48
- }
49
- //#endregion
50
- //#region src/session-state.ts
51
- var u = /* @__PURE__ */ new WeakMap(), d = (e) => e || (typeof window > "u" ? void 0 : window);
52
- //#endregion
53
- export { o as a, r as c, t as d, c as i, l, u as n, i as o, n as r, a as s, d as t, s as u };
54
-
55
- //# sourceMappingURL=resolve-browser-window-X5jXljW9.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"resolve-browser-window-X5jXljW9.js","names":[],"sources":["../src/sdk-error.ts","../src/validate.ts","../src/session-state.ts","../src/resolve-browser-window.ts"],"sourcesContent":["/* Copyright 2024 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.\n * See LICENSE.md in the project root.\n */\n\n/*\n * Note: this module can't have any internal dependencies because it's used in ./validate which\n * in turn is used as a dependency to a lot of other modules. Doing so may create a circular\n * dependency that's hard to debug in Node.\n */\n\nconst STRINGIFY_TYPES = ['boolean', 'number', 'string'];\n\n/**\n * Custom error class thrown by all SDK methods on failure.\n *\n * All rejected promises from API calls reject with an instance of this class.\n *\n * @group Errors\n */\nexport default class SDKError extends Error {\n /** HTTP status code from the server error payload;\n * declared explicitly to allow numeric comparisons without type-casting.\n */\n code?: number;\n /**\n * Properties copied from the server error object.\n * @internal\n */\n [key: string]: unknown;\n\n /**\n * @param message - Human-readable error message\n * @param errorObject - Optional server error payload. All enumerable properties are\n * shallow-copied onto this instance.\n */\n constructor(message: string, errorObject?: Record<string, unknown>) {\n super(message);\n this.name = 'SDKError';\n\n if (errorObject) {\n try {\n Object.assign(this, errorObject);\n } catch {\n // silent\n }\n }\n }\n\n /**\n * Returns a multi-line string with the error name, message, and any other properties copied\n * from the server error payload.\n */\n toString(): string {\n const ret = `${this.name}: ${this.message}`;\n const additionalInfo = Object.keys(this)\n .filter((key) => key !== 'name' && STRINGIFY_TYPES.includes(typeof this[key]))\n .map((key) => ` ${key}: ${this[key]}`)\n .join('\\n');\n return additionalInfo ? `${ret}\\n${additionalInfo}` : ret;\n }\n}\n","/* Copyright 2024 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.\n * See LICENSE.md in the project root.\n */\n\nimport SDKError from './sdk-error.js';\n\n/*\n * This module defines a set of validation functions which are used in the rest of the SDK.\n * Why make our own validation module?\n * 1. To implement the validations that we specifically need for the SDK\n * 2. To have one less dependency\n */\n\n/**\n * A utility function that throws an SDKError if an assertion fails. It's mostly useful for\n * validating function inputs.\n *\n * Narrows `condition` for the rest of the enclosing scope (TypeScript assertion signature).\n * @param condition - The condition that we're asserting\n * @param message - The error message\n * @throws {SDKError} - If the condition is falsy it throws the appropriate error\n */\nexport function assert(condition: boolean, message = 'Assertion failed'): asserts condition {\n if (!condition) {\n throw new SDKError(message);\n }\n}\n\n/**\n * Checks if a value is a string or not\n * @param value - The value to check\n */\nexport function isStr(value: unknown): value is string {\n return typeof value === 'string';\n}\n\n/**\n * Checks if a value is a non-empty string\n * @param value - The value to check\n */\nexport function isNonEmptyString(value: unknown): value is string {\n return typeof value === 'string' && value.length > 0;\n}\n\n/**\n * checks if a given value is an object (but not null)\n * @param value - The value to check\n */\nexport function isObject(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null;\n}\n\n/**\n * Checks if a given value is an object with at least one own key\n * @param value - The value to check\n */\nexport function isNonEmptyObj(value: unknown): value is Record<string, unknown> {\n return isObject(value) && Object.keys(value).length > 0;\n}\n\n/**\n * Checks if a given string is a valid URL\n * @param value - The string to be tested\n * @param mandatoryFields - A list of mandatory fields that should exist in the parsed\n * `URL` object\n */\nexport function isUrl(value: string, ...mandatoryFields: (keyof URL)[]): boolean {\n try {\n const parsedUrl = new URL(value);\n return mandatoryFields.every((f) => parsedUrl[f]);\n } catch {\n return false;\n }\n}\n\n/**\n * Checks if a given value is a function\n * @param value - The value to check\n */\nexport function isFunction(value: unknown): value is (...args: unknown[]) => unknown {\n return typeof value === 'function';\n}\n\n/**\n * Checks if a string matches any of the strings in a set of possibilities\n * @param value\n * @param possibilities - An array of strings that'll be used to check the string\n * inclusion. Note that for performance reasons, we don't validate this parameter.\n * @param caseSensitive - Should the check be case sensitive\n */\nexport function isStrIn(value: string, possibilities: string[], caseSensitive = false): boolean {\n const _isSameStrCaseInsensitive = (str: string) =>\n isStr(str) && value.toUpperCase() === str.toUpperCase();\n if (!(isStr(value) && Array.isArray(possibilities))) {\n return false;\n }\n if (caseSensitive) {\n return possibilities.indexOf(value) !== -1;\n }\n return possibilities.some(_isSameStrCaseInsensitive);\n}\n","/* Copyright 2026 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.\n * See LICENSE.md in the project root.\n */\n\nimport type { SessionObjectResponse } from './types/session.js';\n\n/**\n * Minimal core bridge for the optional compatibility layer; not a public API.\n * Sourcepoint reads legacy `_session` synchronously, but Account only exposes async\n * session lookups. Mirroring `sessionUpdated` would miss updates with an unchanged\n * session ID, so the shim reads Identity's actual state instead of keeping a copy.\n * Legacy behavior stays in compatibility; remove this bridge with the shims in v7.\n */\nexport type SessionState = {\n getSession: () => SessionObjectResponse;\n // Lets the shim notify legacy logout listeners before the session is replaced, as in v5.\n beforeUpdate?: (previous: SessionObjectResponse, current: SessionObjectResponse) => void;\n};\n\nexport const sessionStates = new WeakMap<object, SessionState>();\n","/* Copyright 2026 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.\n * See LICENSE.md in the project root.\n */\n\nexport const resolveBrowserWindow = (providedWindow?: Window): Window | undefined => {\n if (providedWindow) {\n return providedWindow;\n }\n\n return typeof window === 'undefined' ? undefined : window;\n};\n"],"mappings":";AAUA,IAAM,IAAkB;CAAC;CAAW;CAAU;AAAQ,GASjC,IAArB,cAAsC,MAAM;CAIxC;CAYA,YAAY,GAAiB,GAAuC;EAIhE,IAHA,MAAM,CAAO,GACb,KAAK,OAAO,YAER,GACA,IAAI;GACA,OAAO,OAAO,MAAM,CAAW;EACnC,QAAQ,CAER;CAER;CAMA,WAAmB;EACf,IAAM,IAAM,GAAG,KAAK,KAAK,IAAI,KAAK,WAC5B,IAAiB,OAAO,KAAK,IAAI,EAClC,QAAQ,MAAQ,MAAQ,UAAU,EAAgB,SAAS,OAAO,KAAK,EAAI,CAAC,EAC5E,KAAK,MAAQ,OAAO,EAAI,IAAI,KAAK,IAAM,EACvC,KAAK,IAAI;EACd,OAAO,IAAiB,GAAG,EAAI,IAAI,MAAmB;CAC1D;AACJ;;;ACtCA,SAAgB,EAAO,GAAoB,IAAU,oBAAuC;CACxF,IAAI,CAAC,GACD,MAAM,IAAI,EAAS,CAAO;AAElC;AAMA,SAAgB,EAAM,GAAiC;CACnD,OAAO,OAAO,KAAU;AAC5B;AAMA,SAAgB,EAAiB,GAAiC;CAC9D,OAAO,OAAO,KAAU,YAAY,EAAM,SAAS;AACvD;AAMA,SAAgB,EAAS,GAAkD;CACvE,OAAO,OAAO,KAAU,cAAY;AACxC;AAMA,SAAgB,EAAc,GAAkD;CAC5E,OAAO,EAAS,CAAK,KAAK,OAAO,KAAK,CAAK,EAAE,SAAS;AAC1D;AAQA,SAAgB,EAAM,GAAe,GAAG,GAAyC;CAC7E,IAAI;EACA,IAAM,IAAY,IAAI,IAAI,CAAK;EAC/B,OAAO,EAAgB,OAAO,MAAM,EAAU,EAAE;CACpD,QAAQ;EACJ,OAAO;CACX;AACJ;AAMA,SAAgB,EAAW,GAA0D;CACjF,OAAO,OAAO,KAAU;AAC5B;AASA,SAAgB,EAAQ,GAAe,GAAyB,IAAgB,IAAgB;CAS5F,OANM,EAAM,CAAK,KAAK,MAAM,QAAQ,CAAa,IAG7C,IACO,EAAc,QAAQ,CAAK,MAAM,KAErC,EAAc,MARc,MAC/B,EAAM,CAAG,KAAK,EAAM,YAAY,MAAM,EAAI,YAAY,CAOP,IALxC;AAMf;;;ACjFA,IAAa,oBAAgB,IAAI,QAA8B,GCflD,KAAwB,MAC7B,MAIG,OAAO,SAAW,MAAc,KAAA,IAAY"}