@schibsted/account-sdk-browser 6.0.0-alpha.12 → 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 +4 -0
- package/dist/account.d.ts +11 -5
- package/dist/compatibility/types.d.ts +3 -3
- package/dist/compatibility.js +3 -3
- package/dist/compatibility.js.map +1 -1
- package/dist/consents.d.ts +29 -0
- package/dist/identity.d.ts +21 -3
- package/dist/index.d.ts +2 -1
- package/dist/index.js +272 -187
- package/dist/index.js.map +1 -1
- package/dist/types/account.d.ts +9 -8
- package/dist/types/common.d.ts +2 -2
- package/dist/types/identity.d.ts +10 -1
- package/dist/version.d.ts +1 -1
- package/package.json +5 -1
- package/src/account.ts +49 -22
- package/src/compatibility/legacy-identity.ts +6 -6
- package/src/compatibility/types.ts +3 -3
- package/src/consents.ts +94 -0
- package/src/identity.ts +94 -20
- package/src/index.ts +1 -1
- package/src/types/account.ts +13 -11
- package/src/types/common.ts +2 -2
- package/src/types/identity.ts +11 -1
- package/src/version.ts +1 -1
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
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { AccountConfig, AccountEventListener, AccountEventName
|
|
1
|
+
import { AccountConfig, AccountEventListener, AccountEventName } from './types/account.js';
|
|
2
|
+
import { AccountEnvironment } from './types/common.js';
|
|
2
3
|
import { LoginOptions, SimplifiedLoginData, SimplifiedLoginWidgetLoginOptions, SimplifiedLoginWidgetOptions } from './types/login.js';
|
|
3
4
|
import { HasAccessResult } from './types/monetization.js';
|
|
4
5
|
import { ConnectedSessionResponse, SessionResponse, SessionUserId } from './types/session.js';
|
|
@@ -14,13 +15,18 @@ import { ConnectedSessionResponse, SessionResponse, SessionUserId } from './type
|
|
|
14
15
|
export declare class Account {
|
|
15
16
|
#private;
|
|
16
17
|
constructor(config: AccountConfig);
|
|
18
|
+
/** The client id this instance was configured with. */
|
|
19
|
+
get clientId(): string;
|
|
20
|
+
/** The Schibsted Account environment this instance was configured with. Defaults to PRE. */
|
|
21
|
+
get env(): AccountEnvironment;
|
|
22
|
+
/** The redirect uri this instance was configured with. */
|
|
23
|
+
get redirectUri(): string;
|
|
17
24
|
/**
|
|
18
|
-
* The
|
|
25
|
+
* The product or feature ids `hasAccess()` uses when no ids are passed, if configured.
|
|
19
26
|
*
|
|
20
|
-
* The returned
|
|
21
|
-
* changing them does not reconfigure the SDK.
|
|
27
|
+
* The returned array is a frozen copy; it cannot be mutated.
|
|
22
28
|
*/
|
|
23
|
-
get
|
|
29
|
+
get defaultProductIds(): readonly string[] | undefined;
|
|
24
30
|
/**
|
|
25
31
|
* Queries Session Service and returns the current browser session state.
|
|
26
32
|
*
|
|
@@ -9,11 +9,11 @@ export type LegacyIdentity = LegacyIdentityMethods & {
|
|
|
9
9
|
loginUrl(options: LoginOptions): string;
|
|
10
10
|
/** @deprecated Pass an options object to `account.loginUrl()`. Removed in v7. */
|
|
11
11
|
loginUrl(state: string, acrValues?: string, scope?: string, redirectUri?: string, loginHint?: string, tag?: string, teaser?: string, maxAge?: number | string): string;
|
|
12
|
-
/** @deprecated Use `account.
|
|
12
|
+
/** @deprecated Use `account.clientId`. Removed in v7. */
|
|
13
13
|
readonly clientId: string;
|
|
14
|
-
/** @deprecated Use `account.
|
|
14
|
+
/** @deprecated Use `account.env`. Removed in v7. */
|
|
15
15
|
readonly env: AccountEnvironment;
|
|
16
|
-
/** @deprecated Use `account.
|
|
16
|
+
/** @deprecated Use `account.redirectUri`. Removed in v7. */
|
|
17
17
|
readonly redirectUri: string;
|
|
18
18
|
/** @deprecated Use the Account session methods and events. Removed in v7. */
|
|
19
19
|
readonly _session: SessionObjectResponse;
|
package/dist/compatibility.js
CHANGED
|
@@ -19,13 +19,13 @@ var r = "[Account SDK compatibility]", i = !1, a = () => {
|
|
|
19
19
|
}, this.#e.on("logoutRequested", () => this.#a());
|
|
20
20
|
}
|
|
21
21
|
get clientId() {
|
|
22
|
-
return o("schIdentity.clientId", "account.
|
|
22
|
+
return o("schIdentity.clientId", "account.clientId"), this.#e.clientId;
|
|
23
23
|
}
|
|
24
24
|
get env() {
|
|
25
|
-
return o("schIdentity.env", "account.
|
|
25
|
+
return o("schIdentity.env", "account.env"), this.#e.env;
|
|
26
26
|
}
|
|
27
27
|
get redirectUri() {
|
|
28
|
-
return o("schIdentity.redirectUri", "account.
|
|
28
|
+
return o("schIdentity.redirectUri", "account.redirectUri"), this.#e.redirectUri;
|
|
29
29
|
}
|
|
30
30
|
get _session() {
|
|
31
31
|
return o("schIdentity._session", "account.hasSession()"), this.#t.getSession();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compatibility.js","names":["#account","#sessionState","#emitLegacyLogout","#warn","#assertLogoutEvent","#logoutListeners","#account"],"sources":["../src/compatibility/warnings.ts","../src/compatibility/legacy-identity.ts","../src/compatibility/legacy-monetization.ts","../src/compatibility/install-legacy-compatibility.ts"],"sourcesContent":["/* Copyright 2026 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.\n * See LICENSE.md in the project root.\n */\n\nconst PREFIX = '[Account SDK compatibility]';\nlet compatibilityWarningEmitted = false;\n\nexport const warnCompatibilityEnabled = (): void => {\n if (compatibilityWarningEmitted) {\n return;\n }\n compatibilityWarningEmitted = true;\n console.warn(\n `${PREFIX} The legacy compatibility layer is enabled. Migrate application code to the Account API. This compatibility layer will be removed in v7.`,\n );\n};\n\nexport const warnLegacyUsage = (legacyApi: string, replacement: string): void => {\n console.warn(\n `${PREFIX} ${legacyApi} is deprecated. Use ${replacement} instead. It will be removed in v7.`,\n );\n};\n\nexport const warnIgnoredHasAccessUserId = (): void => {\n console.warn(\n `${PREFIX} schMonetization.hasAccess() ignores the legacy userId argument. Account.hasAccess() resolves the logged-in user automatically. It will be removed in v7.`,\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 { Account } from '../account.js';\nimport SDKError from '../sdk-error.js';\nimport { type SessionState, sessionStates } from '../session-state.js';\nimport type { AccountEnvironment } from '../types/common.js';\nimport type { LoginOptions } from '../types/login.js';\nimport type { SessionObjectResponse } from '../types/session.js';\nimport type { LegacyIdentity, LegacyLogoutListener } from './types.js';\nimport { warnLegacyUsage } from './warnings.js';\n\nexport class LegacyIdentityAdapter implements LegacyIdentity {\n readonly #account: Account;\n readonly #sessionState: SessionState;\n #logoutListeners: { listener: LegacyLogoutListener; context?: unknown }[] = [];\n\n constructor(account: Account) {\n this.#account = account;\n\n const sessionState = sessionStates.get(account);\n if (!sessionState) {\n throw new SDKError('Legacy compatibility requires an Account from the same SDK build');\n }\n this.#sessionState = sessionState;\n // v5 notified logout listeners before replacing _session, on every session result.\n sessionState.beforeUpdate = (previous, current) => {\n if (\n 'userId' in previous &&\n previous.userId &&\n !('userId' in current && current.userId)\n ) {\n this.#emitLegacyLogout(current);\n }\n };\n this.#account.on('logoutRequested', () => this.#emitLegacyLogout());\n }\n\n get clientId(): string {\n warnLegacyUsage('schIdentity.clientId', 'account.config.clientId');\n return this.#account.config.clientId;\n }\n\n get env(): AccountEnvironment {\n warnLegacyUsage('schIdentity.env', 'account.config.env');\n return this.#account.config.env;\n }\n\n get redirectUri(): string {\n warnLegacyUsage('schIdentity.redirectUri', 'account.config.redirectUri');\n return this.#account.config.redirectUri;\n }\n\n get _session(): LegacyIdentity['_session'] {\n warnLegacyUsage('schIdentity._session', 'account.hasSession()');\n return this.#sessionState.getSession();\n }\n\n hasSession(): ReturnType<Account['hasSession']> {\n this.#warn('hasSession');\n return this.#account.hasSession();\n }\n\n isLoggedIn(): ReturnType<Account['isLoggedIn']> {\n this.#warn('isLoggedIn');\n return this.#account.isLoggedIn();\n }\n\n isConnected(): ReturnType<Account['isConnected']> {\n this.#warn('isConnected');\n return this.#account.isConnected();\n }\n\n getUser(): ReturnType<Account['getUser']> {\n this.#warn('getUser');\n return this.#account.getUser();\n }\n\n getUserId(): ReturnType<Account['getUserId']> {\n this.#warn('getUserId');\n return this.#account.getUserId();\n }\n\n getExternalId(\n ...args: Parameters<Account['getExternalId']>\n ): ReturnType<Account['getExternalId']> {\n this.#warn('getExternalId');\n return this.#account.getExternalId(...args);\n }\n\n getUserUuid(): ReturnType<Account['getUserUuid']> {\n this.#warn('getUserUuid');\n return this.#account.getUserUuid();\n }\n\n getUserSDRN(): ReturnType<Account['getUserSDRN']> {\n this.#warn('getUserSDRN');\n return this.#account.getUserSDRN();\n }\n\n getUserContextData(): ReturnType<Account['getUserContextData']> {\n this.#warn('getUserContextData');\n return this.#account.getUserContextData();\n }\n\n getSpId(): ReturnType<Account['getSpId']> {\n this.#warn('getSpId');\n return this.#account.getSpId();\n }\n\n login(...args: Parameters<Account['login']>): ReturnType<Account['login']> {\n this.#warn('login');\n return this.#account.login(...args);\n }\n\n logout(...args: Parameters<Account['logout']>): ReturnType<Account['logout']> {\n this.#warn('logout');\n return this.#account.logout(...args);\n }\n\n loginUrl(options: LoginOptions): string;\n loginUrl(\n state: string,\n acrValues?: string,\n scope?: string,\n redirectUri?: string,\n loginHint?: string,\n tag?: string,\n teaser?: string,\n maxAge?: number | string,\n ): string;\n loginUrl(\n options: LoginOptions | string,\n acrValues?: string,\n scope?: string,\n redirectUri?: string,\n loginHint?: string,\n tag?: string,\n teaser?: string,\n maxAge?: number | string,\n ): string {\n this.#warn('loginUrl');\n if (typeof options !== 'string') {\n return this.#account.loginUrl(options);\n }\n\n // v5 treated empty positional values as omitted, except for numeric maxAge (including 0).\n return this.#account.loginUrl({\n state: options,\n acrValues,\n scope: scope || undefined,\n redirectUri: redirectUri || undefined,\n loginHint: loginHint || undefined,\n tag: tag || undefined,\n teaser: teaser || undefined,\n maxAge: Number.isNaN(Number(maxAge)) ? undefined : maxAge,\n });\n }\n\n logoutUrl(...args: Parameters<Account['logoutUrl']>): ReturnType<Account['logoutUrl']> {\n this.#warn('logoutUrl');\n return this.#account.logoutUrl(...args);\n }\n\n accountUrl(...args: Parameters<Account['accountUrl']>): ReturnType<Account['accountUrl']> {\n this.#warn('accountUrl');\n return this.#account.accountUrl(...args);\n }\n\n showSimplifiedLoginWidget(\n ...args: Parameters<Account['showSimplifiedLoginWidget']>\n ): ReturnType<Account['showSimplifiedLoginWidget']> {\n this.#warn('showSimplifiedLoginWidget');\n return this.#account.showSimplifiedLoginWidget(...args);\n }\n\n clearCachedUserSession(): ReturnType<Account['clearCachedUserSession']> {\n this.#warn('clearCachedUserSession');\n return this.#account.clearCachedUserSession();\n }\n\n on(event: 'logout', listener: LegacyLogoutListener, context?: unknown): this {\n warnLegacyUsage(\n \"schIdentity.on('logout')\",\n \"account.on('logoutRequested') and account.on('sessionUpdated')\",\n );\n this.#assertLogoutEvent(event);\n\n this.#logoutListeners.push({ listener, context });\n return this;\n }\n\n off(event: 'logout', listener?: LegacyLogoutListener): this {\n warnLegacyUsage(\n \"schIdentity.off('logout')\",\n \"account.off('logoutRequested') and account.off('sessionUpdated')\",\n );\n this.#assertLogoutEvent(event);\n\n this.#logoutListeners = listener\n ? this.#logoutListeners.filter((registered) => registered.listener !== listener)\n : [];\n return this;\n }\n\n #warn(method: keyof LegacyIdentity): void {\n warnLegacyUsage(`schIdentity.${method}()`, `account.${method}()`);\n }\n\n #assertLogoutEvent(event: string): void {\n if (event !== 'logout') {\n throw new SDKError(\n `Account SDK legacy compatibility does not support the Identity \"${event}\" event`,\n );\n }\n }\n\n #emitLegacyLogout(...args: [] | [SessionObjectResponse]): void {\n for (const { listener, context } of [...this.#logoutListeners]) {\n try {\n listener.apply(context, args);\n } catch (error) {\n // A legacy consumer must not prevent Account from updating its session.\n console.error('[Account SDK compatibility] Legacy logout listener failed', error);\n }\n }\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 { Account } from '../account.js';\nimport type { SessionUserId } from '../types/session.js';\nimport type { LegacyMonetization } from './types.js';\nimport { warnIgnoredHasAccessUserId, warnLegacyUsage } from './warnings.js';\n\nexport class LegacyMonetizationAdapter implements LegacyMonetization {\n readonly #account: Account;\n\n constructor(account: Account) {\n this.#account = account;\n }\n\n hasAccess(productIds: string[], _userId: SessionUserId): ReturnType<Account['hasAccess']> {\n warnLegacyUsage('schMonetization.hasAccess()', 'account.hasAccess()');\n warnIgnoredHasAccessUserId();\n return this.#account.hasAccess(productIds);\n }\n\n clearCachedAccessResult(productIds: string[], userId: SessionUserId): void {\n warnLegacyUsage(\n 'schMonetization.clearCachedAccessResult()',\n 'account.clearCachedAccessResult()',\n );\n this.#account.clearCachedAccessResult(productIds, userId);\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 { Account } from '../account.js';\nimport { resolveBrowserWindow } from '../resolve-browser-window.js';\nimport SDKError from '../sdk-error.js';\nimport { LegacyIdentityAdapter } from './legacy-identity.js';\nimport { LegacyMonetizationAdapter } from './legacy-monetization.js';\nimport type { LegacyCompatibilityOptions } from './types.js';\nimport { warnCompatibilityEnabled, warnLegacyUsage } from './warnings.js';\n\nconst ACCOUNT_READY_EVENT = 'schAccount:ready';\nconst IDENTITY_READY_EVENT = 'schIdentity:ready';\nconst MONETIZATION_READY_EVENT = 'schMonetization:ready';\n\nconst enabledWindows = new WeakSet<Window>();\n\nconst createUnavailableError = (): SDKError =>\n new SDKError('Account SDK legacy compatibility is not available in this browser context');\n\nconst createMissingAccountError = (): SDKError =>\n new SDKError(\n `Account SDK legacy compatibility received ${ACCOUNT_READY_EVENT} without window.schAccount`,\n );\n\nconst createGlobalConflictError = (globalName: string): SDKError =>\n new SDKError(\n `Account SDK legacy compatibility cannot define window.${globalName} because it already exists`,\n );\n\nconst assertLegacyGlobalsAvailable = (browserWindow: Window): void => {\n for (const globalName of ['schIdentity', 'Identity', 'schMonetization']) {\n const descriptor = Object.getOwnPropertyDescriptor(browserWindow, globalName);\n const emptyPlaceholder =\n descriptor?.configurable && 'value' in descriptor && descriptor.value == null;\n if (descriptor && !emptyPlaceholder) {\n throw createGlobalConflictError(globalName);\n }\n }\n};\n\nconst legacyGlobalDescriptor = <Instance>(\n globalName: string,\n getter: () => Instance,\n instance: Instance,\n): PropertyDescriptor => ({\n configurable: true,\n enumerable: true,\n get: getter,\n set: (value: Instance) => {\n // Some hosts still assign window.Identity = window.schIdentity after initialization.\n if (value !== instance) {\n throw createGlobalConflictError(globalName);\n }\n warnLegacyUsage(`window.${globalName}`, 'window.schAccount');\n },\n});\n\nconst dispatchReadyEvent = <Instance>(\n browserWindow: Window,\n eventName: string,\n instance: Instance,\n): void => {\n browserWindow.dispatchEvent(new CustomEvent(eventName, { detail: { instance } }));\n};\n\nconst installLegacyGlobals = (browserWindow: Window, account: Account): void => {\n assertLegacyGlobalsAvailable(browserWindow);\n\n const identityShim = new LegacyIdentityAdapter(account);\n const monetizationShim = new LegacyMonetizationAdapter(account);\n const identityGetter = () => {\n warnLegacyUsage('window.schIdentity', 'window.schAccount');\n return identityShim;\n };\n const monetizationGetter = () => {\n warnLegacyUsage('window.schMonetization', 'window.schAccount');\n return monetizationShim;\n };\n const legacyIdentityGetter = () => {\n warnLegacyUsage('window.Identity', 'window.schAccount');\n return identityShim;\n };\n\n Object.defineProperties(browserWindow, {\n schIdentity: legacyGlobalDescriptor('schIdentity', identityGetter, identityShim),\n Identity: legacyGlobalDescriptor('Identity', legacyIdentityGetter, identityShim),\n schMonetization: legacyGlobalDescriptor(\n 'schMonetization',\n monetizationGetter,\n monetizationShim,\n ),\n });\n\n dispatchReadyEvent(browserWindow, IDENTITY_READY_EVENT, identityShim);\n dispatchReadyEvent(browserWindow, MONETIZATION_READY_EVENT, monetizationShim);\n};\n\n/**\n * Enables the temporary v5 global and ready-event compatibility layer for Account SDK v6.\n *\n * Call this before `createAccountSdk()` when a dependency still expects v5 globals. If Account\n * already exists, the legacy shims are installed immediately.\n *\n * @deprecated Migrate dependencies to the Account API. This entrypoint will be removed in v7.\n */\nexport function enableLegacyCompatibility(options: LegacyCompatibilityOptions = {}): void {\n const browserWindow = resolveBrowserWindow(options.window);\n if (!browserWindow) {\n throw createUnavailableError();\n }\n\n warnCompatibilityEnabled();\n\n if (enabledWindows.has(browserWindow)) {\n return;\n }\n\n assertLegacyGlobalsAvailable(browserWindow);\n\n enabledWindows.add(browserWindow);\n\n if (browserWindow.schAccount) {\n installLegacyGlobals(browserWindow, browserWindow.schAccount);\n return;\n }\n\n browserWindow.addEventListener(\n ACCOUNT_READY_EVENT,\n () => {\n if (!browserWindow.schAccount) {\n throw createMissingAccountError();\n }\n installLegacyGlobals(browserWindow, browserWindow.schAccount);\n },\n { once: true },\n );\n}\n"],"mappings":";;AAIA,IAAM,IAAS,+BACX,IAA8B,IAErB,UAAuC;CAC5C,MAGJ,IAA8B,IAC9B,QAAQ,KACJ,GAAG,EAAO,yIACd;AACJ,GAEa,KAAmB,GAAmB,MAA8B;CAC7E,QAAQ,KACJ,GAAG,EAAO,GAAG,EAAU,sBAAsB,EAAY,oCAC7D;AACJ,GAEa,UAAyC;CAClD,QAAQ,KACJ,GAAG,EAAO,0JACd;AACJ,GCda,IAAb,MAA6D;CACzD;CACA;CACA,KAA4E,CAAC;CAE7E,YAAY,GAAkB;EAC1B,KAAKA,KAAW;EAEhB,IAAM,IAAe,EAAc,IAAI,CAAO;EAC9C,IAAI,CAAC,GACD,MAAM,IAAI,EAAS,kEAAkE;EAazF,AAXA,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emitLegacyLogout","#warn","#assertLogoutEvent","#logoutListeners","#account"],"sources":["../src/compatibility/warnings.ts","../src/compatibility/legacy-identity.ts","../src/compatibility/legacy-monetization.ts","../src/compatibility/install-legacy-compatibility.ts"],"sourcesContent":["/* Copyright 2026 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.\n * See LICENSE.md in the project root.\n */\n\nconst PREFIX = '[Account SDK compatibility]';\nlet compatibilityWarningEmitted = false;\n\nexport const warnCompatibilityEnabled = (): void => {\n if (compatibilityWarningEmitted) {\n return;\n }\n compatibilityWarningEmitted = true;\n console.warn(\n `${PREFIX} The legacy compatibility layer is enabled. Migrate application code to the Account API. This compatibility layer will be removed in v7.`,\n );\n};\n\nexport const warnLegacyUsage = (legacyApi: string, replacement: string): void => {\n console.warn(\n `${PREFIX} ${legacyApi} is deprecated. Use ${replacement} instead. It will be removed in v7.`,\n );\n};\n\nexport const warnIgnoredHasAccessUserId = (): void => {\n console.warn(\n `${PREFIX} schMonetization.hasAccess() ignores the legacy userId argument. Account.hasAccess() resolves the logged-in user automatically. It will be removed in v7.`,\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 { Account } from '../account.js';\nimport SDKError from '../sdk-error.js';\nimport { type SessionState, sessionStates } from '../session-state.js';\nimport type { AccountEnvironment } from '../types/common.js';\nimport type { LoginOptions } from '../types/login.js';\nimport type { SessionObjectResponse } from '../types/session.js';\nimport type { LegacyIdentity, LegacyLogoutListener } from './types.js';\nimport { warnLegacyUsage } from './warnings.js';\n\nexport class LegacyIdentityAdapter implements LegacyIdentity {\n readonly #account: Account;\n readonly #sessionState: SessionState;\n #logoutListeners: { listener: LegacyLogoutListener; context?: unknown }[] = [];\n\n constructor(account: Account) {\n this.#account = account;\n\n const sessionState = sessionStates.get(account);\n if (!sessionState) {\n throw new SDKError('Legacy compatibility requires an Account from the same SDK build');\n }\n this.#sessionState = sessionState;\n // v5 notified logout listeners before replacing _session, on every session result.\n sessionState.beforeUpdate = (previous, current) => {\n if (\n 'userId' in previous &&\n previous.userId &&\n !('userId' in current && current.userId)\n ) {\n this.#emitLegacyLogout(current);\n }\n };\n this.#account.on('logoutRequested', () => this.#emitLegacyLogout());\n }\n\n get clientId(): string {\n warnLegacyUsage('schIdentity.clientId', 'account.clientId');\n return this.#account.clientId;\n }\n\n get env(): AccountEnvironment {\n warnLegacyUsage('schIdentity.env', 'account.env');\n return this.#account.env;\n }\n\n get redirectUri(): string {\n warnLegacyUsage('schIdentity.redirectUri', 'account.redirectUri');\n return this.#account.redirectUri;\n }\n\n get _session(): LegacyIdentity['_session'] {\n warnLegacyUsage('schIdentity._session', 'account.hasSession()');\n return this.#sessionState.getSession();\n }\n\n hasSession(): ReturnType<Account['hasSession']> {\n this.#warn('hasSession');\n return this.#account.hasSession();\n }\n\n isLoggedIn(): ReturnType<Account['isLoggedIn']> {\n this.#warn('isLoggedIn');\n return this.#account.isLoggedIn();\n }\n\n isConnected(): ReturnType<Account['isConnected']> {\n this.#warn('isConnected');\n return this.#account.isConnected();\n }\n\n getUser(): ReturnType<Account['getUser']> {\n this.#warn('getUser');\n return this.#account.getUser();\n }\n\n getUserId(): ReturnType<Account['getUserId']> {\n this.#warn('getUserId');\n return this.#account.getUserId();\n }\n\n getExternalId(\n ...args: Parameters<Account['getExternalId']>\n ): ReturnType<Account['getExternalId']> {\n this.#warn('getExternalId');\n return this.#account.getExternalId(...args);\n }\n\n getUserUuid(): ReturnType<Account['getUserUuid']> {\n this.#warn('getUserUuid');\n return this.#account.getUserUuid();\n }\n\n getUserSDRN(): ReturnType<Account['getUserSDRN']> {\n this.#warn('getUserSDRN');\n return this.#account.getUserSDRN();\n }\n\n getUserContextData(): ReturnType<Account['getUserContextData']> {\n this.#warn('getUserContextData');\n return this.#account.getUserContextData();\n }\n\n getSpId(): ReturnType<Account['getSpId']> {\n this.#warn('getSpId');\n return this.#account.getSpId();\n }\n\n login(...args: Parameters<Account['login']>): ReturnType<Account['login']> {\n this.#warn('login');\n return this.#account.login(...args);\n }\n\n logout(...args: Parameters<Account['logout']>): ReturnType<Account['logout']> {\n this.#warn('logout');\n return this.#account.logout(...args);\n }\n\n loginUrl(options: LoginOptions): string;\n loginUrl(\n state: string,\n acrValues?: string,\n scope?: string,\n redirectUri?: string,\n loginHint?: string,\n tag?: string,\n teaser?: string,\n maxAge?: number | string,\n ): string;\n loginUrl(\n options: LoginOptions | string,\n acrValues?: string,\n scope?: string,\n redirectUri?: string,\n loginHint?: string,\n tag?: string,\n teaser?: string,\n maxAge?: number | string,\n ): string {\n this.#warn('loginUrl');\n if (typeof options !== 'string') {\n return this.#account.loginUrl(options);\n }\n\n // v5 treated empty positional values as omitted, except for numeric maxAge (including 0).\n return this.#account.loginUrl({\n state: options,\n acrValues,\n scope: scope || undefined,\n redirectUri: redirectUri || undefined,\n loginHint: loginHint || undefined,\n tag: tag || undefined,\n teaser: teaser || undefined,\n maxAge: Number.isNaN(Number(maxAge)) ? undefined : maxAge,\n });\n }\n\n logoutUrl(...args: Parameters<Account['logoutUrl']>): ReturnType<Account['logoutUrl']> {\n this.#warn('logoutUrl');\n return this.#account.logoutUrl(...args);\n }\n\n accountUrl(...args: Parameters<Account['accountUrl']>): ReturnType<Account['accountUrl']> {\n this.#warn('accountUrl');\n return this.#account.accountUrl(...args);\n }\n\n showSimplifiedLoginWidget(\n ...args: Parameters<Account['showSimplifiedLoginWidget']>\n ): ReturnType<Account['showSimplifiedLoginWidget']> {\n this.#warn('showSimplifiedLoginWidget');\n return this.#account.showSimplifiedLoginWidget(...args);\n }\n\n clearCachedUserSession(): ReturnType<Account['clearCachedUserSession']> {\n this.#warn('clearCachedUserSession');\n return this.#account.clearCachedUserSession();\n }\n\n on(event: 'logout', listener: LegacyLogoutListener, context?: unknown): this {\n warnLegacyUsage(\n \"schIdentity.on('logout')\",\n \"account.on('logoutRequested') and account.on('sessionUpdated')\",\n );\n this.#assertLogoutEvent(event);\n\n this.#logoutListeners.push({ listener, context });\n return this;\n }\n\n off(event: 'logout', listener?: LegacyLogoutListener): this {\n warnLegacyUsage(\n \"schIdentity.off('logout')\",\n \"account.off('logoutRequested') and account.off('sessionUpdated')\",\n );\n this.#assertLogoutEvent(event);\n\n this.#logoutListeners = listener\n ? this.#logoutListeners.filter((registered) => registered.listener !== listener)\n : [];\n return this;\n }\n\n #warn(method: keyof LegacyIdentity): void {\n warnLegacyUsage(`schIdentity.${method}()`, `account.${method}()`);\n }\n\n #assertLogoutEvent(event: string): void {\n if (event !== 'logout') {\n throw new SDKError(\n `Account SDK legacy compatibility does not support the Identity \"${event}\" event`,\n );\n }\n }\n\n #emitLegacyLogout(...args: [] | [SessionObjectResponse]): void {\n for (const { listener, context } of [...this.#logoutListeners]) {\n try {\n listener.apply(context, args);\n } catch (error) {\n // A legacy consumer must not prevent Account from updating its session.\n console.error('[Account SDK compatibility] Legacy logout listener failed', error);\n }\n }\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 { Account } from '../account.js';\nimport type { SessionUserId } from '../types/session.js';\nimport type { LegacyMonetization } from './types.js';\nimport { warnIgnoredHasAccessUserId, warnLegacyUsage } from './warnings.js';\n\nexport class LegacyMonetizationAdapter implements LegacyMonetization {\n readonly #account: Account;\n\n constructor(account: Account) {\n this.#account = account;\n }\n\n hasAccess(productIds: string[], _userId: SessionUserId): ReturnType<Account['hasAccess']> {\n warnLegacyUsage('schMonetization.hasAccess()', 'account.hasAccess()');\n warnIgnoredHasAccessUserId();\n return this.#account.hasAccess(productIds);\n }\n\n clearCachedAccessResult(productIds: string[], userId: SessionUserId): void {\n warnLegacyUsage(\n 'schMonetization.clearCachedAccessResult()',\n 'account.clearCachedAccessResult()',\n );\n this.#account.clearCachedAccessResult(productIds, userId);\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 { Account } from '../account.js';\nimport { resolveBrowserWindow } from '../resolve-browser-window.js';\nimport SDKError from '../sdk-error.js';\nimport { LegacyIdentityAdapter } from './legacy-identity.js';\nimport { LegacyMonetizationAdapter } from './legacy-monetization.js';\nimport type { LegacyCompatibilityOptions } from './types.js';\nimport { warnCompatibilityEnabled, warnLegacyUsage } from './warnings.js';\n\nconst ACCOUNT_READY_EVENT = 'schAccount:ready';\nconst IDENTITY_READY_EVENT = 'schIdentity:ready';\nconst MONETIZATION_READY_EVENT = 'schMonetization:ready';\n\nconst enabledWindows = new WeakSet<Window>();\n\nconst createUnavailableError = (): SDKError =>\n new SDKError('Account SDK legacy compatibility is not available in this browser context');\n\nconst createMissingAccountError = (): SDKError =>\n new SDKError(\n `Account SDK legacy compatibility received ${ACCOUNT_READY_EVENT} without window.schAccount`,\n );\n\nconst createGlobalConflictError = (globalName: string): SDKError =>\n new SDKError(\n `Account SDK legacy compatibility cannot define window.${globalName} because it already exists`,\n );\n\nconst assertLegacyGlobalsAvailable = (browserWindow: Window): void => {\n for (const globalName of ['schIdentity', 'Identity', 'schMonetization']) {\n const descriptor = Object.getOwnPropertyDescriptor(browserWindow, globalName);\n const emptyPlaceholder =\n descriptor?.configurable && 'value' in descriptor && descriptor.value == null;\n if (descriptor && !emptyPlaceholder) {\n throw createGlobalConflictError(globalName);\n }\n }\n};\n\nconst legacyGlobalDescriptor = <Instance>(\n globalName: string,\n getter: () => Instance,\n instance: Instance,\n): PropertyDescriptor => ({\n configurable: true,\n enumerable: true,\n get: getter,\n set: (value: Instance) => {\n // Some hosts still assign window.Identity = window.schIdentity after initialization.\n if (value !== instance) {\n throw createGlobalConflictError(globalName);\n }\n warnLegacyUsage(`window.${globalName}`, 'window.schAccount');\n },\n});\n\nconst dispatchReadyEvent = <Instance>(\n browserWindow: Window,\n eventName: string,\n instance: Instance,\n): void => {\n browserWindow.dispatchEvent(new CustomEvent(eventName, { detail: { instance } }));\n};\n\nconst installLegacyGlobals = (browserWindow: Window, account: Account): void => {\n assertLegacyGlobalsAvailable(browserWindow);\n\n const identityShim = new LegacyIdentityAdapter(account);\n const monetizationShim = new LegacyMonetizationAdapter(account);\n const identityGetter = () => {\n warnLegacyUsage('window.schIdentity', 'window.schAccount');\n return identityShim;\n };\n const monetizationGetter = () => {\n warnLegacyUsage('window.schMonetization', 'window.schAccount');\n return monetizationShim;\n };\n const legacyIdentityGetter = () => {\n warnLegacyUsage('window.Identity', 'window.schAccount');\n return identityShim;\n };\n\n Object.defineProperties(browserWindow, {\n schIdentity: legacyGlobalDescriptor('schIdentity', identityGetter, identityShim),\n Identity: legacyGlobalDescriptor('Identity', legacyIdentityGetter, identityShim),\n schMonetization: legacyGlobalDescriptor(\n 'schMonetization',\n monetizationGetter,\n monetizationShim,\n ),\n });\n\n dispatchReadyEvent(browserWindow, IDENTITY_READY_EVENT, identityShim);\n dispatchReadyEvent(browserWindow, MONETIZATION_READY_EVENT, monetizationShim);\n};\n\n/**\n * Enables the temporary v5 global and ready-event compatibility layer for Account SDK v6.\n *\n * Call this before `createAccountSdk()` when a dependency still expects v5 globals. If Account\n * already exists, the legacy shims are installed immediately.\n *\n * @deprecated Migrate dependencies to the Account API. This entrypoint will be removed in v7.\n */\nexport function enableLegacyCompatibility(options: LegacyCompatibilityOptions = {}): void {\n const browserWindow = resolveBrowserWindow(options.window);\n if (!browserWindow) {\n throw createUnavailableError();\n }\n\n warnCompatibilityEnabled();\n\n if (enabledWindows.has(browserWindow)) {\n return;\n }\n\n assertLegacyGlobalsAvailable(browserWindow);\n\n enabledWindows.add(browserWindow);\n\n if (browserWindow.schAccount) {\n installLegacyGlobals(browserWindow, browserWindow.schAccount);\n return;\n }\n\n browserWindow.addEventListener(\n ACCOUNT_READY_EVENT,\n () => {\n if (!browserWindow.schAccount) {\n throw createMissingAccountError();\n }\n installLegacyGlobals(browserWindow, browserWindow.schAccount);\n },\n { once: true },\n );\n}\n"],"mappings":";;AAIA,IAAM,IAAS,+BACX,IAA8B,IAErB,UAAuC;CAC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CACzD,IAAI,CAAC,GACD,MAAM,EAAuB;CAGjC,MAAyB,GAErB,GAAe,IAAI,CAAa,GAQpC;MAJA,EAA6B,CAAa,GAE1C,EAAe,IAAI,CAAa,GAE5B,EAAc,YAAY;GAC1B,EAAqB,GAAe,EAAc,UAAU;GAC5D;EACJ;EAEA,EAAc,iBACV,SACM;GACF,IAAI,CAAC,EAAc,YACf,MAAM,EAA0B;GAEpC,EAAqB,GAAe,EAAc,UAAU;EAChE,GACA,EAAE,MAAM,GAAK,CACjB;CAXA;AAYJ"}
|
|
@@ -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;
|
package/dist/identity.d.ts
CHANGED
|
@@ -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 -
|
|
47
|
-
*
|
|
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
|
@@ -4,8 +4,9 @@ export * from './globals.js';
|
|
|
4
4
|
export { default as SDKError } from './sdk-error.js';
|
|
5
5
|
/** session response type guards */
|
|
6
6
|
export { isConnectedSessionResponse, isConnectedSessionWithUserIdResponse, isSessionFailureResponse, isSessionSuccessResponse, } from './session-response.js';
|
|
7
|
-
export type { AccountConfig, AccountEventListener, AccountEventMap, AccountEventName, LoginRequestedEventDetail, LogoutRequestedEventDetail,
|
|
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';
|