@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.
- package/dist/account.d.ts +14 -1
- package/dist/compatibility/install-legacy-compatibility.d.ts +1 -1
- package/dist/compatibility/legacy-identity.d.ts +4 -1
- package/dist/compatibility/types.d.ts +6 -3
- package/dist/compatibility.js +75 -71
- package/dist/compatibility.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +236 -193
- package/dist/index.js.map +1 -1
- package/dist/monetization.d.ts +1 -1
- package/dist/resolve-browser-window-wUnycyxt.js +21 -0
- package/dist/resolve-browser-window-wUnycyxt.js.map +1 -0
- package/dist/types/account.d.ts +29 -6
- package/dist/types/common.d.ts +2 -2
- package/dist/types/session.d.ts +2 -0
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/account.ts +39 -6
- package/src/compatibility/install-legacy-compatibility.ts +5 -10
- package/src/compatibility/legacy-identity.ts +14 -5
- package/src/compatibility/types.ts +6 -3
- package/src/identity.ts +1 -1
- package/src/index.ts +3 -0
- package/src/monetization.ts +5 -2
- package/src/types/account.ts +29 -5
- package/src/types/common.ts +2 -2
- package/src/types/session.ts +2 -0
- package/src/version.ts +1 -1
- package/dist/resolve-browser-window-X5jXljW9.js +0 -55
- package/dist/resolve-browser-window-X5jXljW9.js.map +0 -1
package/dist/account.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
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,6 +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;
|
|
24
|
+
/**
|
|
25
|
+
* The product or feature ids `hasAccess()` uses when no ids are passed, if configured.
|
|
26
|
+
*
|
|
27
|
+
* The returned array is a frozen copy; it cannot be mutated.
|
|
28
|
+
*/
|
|
29
|
+
get defaultProductIds(): readonly string[] | undefined;
|
|
17
30
|
/**
|
|
18
31
|
* Queries Session Service and returns the current browser session state.
|
|
19
32
|
*
|
|
@@ -149,7 +162,7 @@ export declare class Account {
|
|
|
149
162
|
* @throws {SDKError} If product ids are not provided or configured, `sessionDomain` is missing,
|
|
150
163
|
* the current user cannot be resolved, input is invalid, or the request fails.
|
|
151
164
|
*/
|
|
152
|
-
hasAccess(productIds?: string[] | undefined): Promise<HasAccessResult | null>;
|
|
165
|
+
hasAccess(productIds?: readonly string[] | undefined): Promise<HasAccessResult | null>;
|
|
153
166
|
/**
|
|
154
167
|
* Removes a cached access-check result.
|
|
155
168
|
*
|
|
@@ -7,4 +7,4 @@ import { LegacyCompatibilityOptions } from './types.js';
|
|
|
7
7
|
*
|
|
8
8
|
* @deprecated Migrate dependencies to the Account API. This entrypoint will be removed in v7.
|
|
9
9
|
*/
|
|
10
|
-
export declare function enableLegacyCompatibility(options
|
|
10
|
+
export declare function enableLegacyCompatibility(options?: LegacyCompatibilityOptions): void;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { Account } from '../account.js';
|
|
2
|
+
import { AccountEnvironment } from '../types/common.js';
|
|
2
3
|
import { LoginOptions } from '../types/login.js';
|
|
3
4
|
import { LegacyIdentity, LegacyLogoutListener } from './types.js';
|
|
4
5
|
export declare class LegacyIdentityAdapter implements LegacyIdentity {
|
|
5
6
|
#private;
|
|
6
|
-
constructor(account: Account
|
|
7
|
+
constructor(account: Account);
|
|
7
8
|
get clientId(): string;
|
|
9
|
+
get env(): AccountEnvironment;
|
|
10
|
+
get redirectUri(): string;
|
|
8
11
|
get _session(): LegacyIdentity['_session'];
|
|
9
12
|
hasSession(): ReturnType<Account['hasSession']>;
|
|
10
13
|
isLoggedIn(): ReturnType<Account['isLoggedIn']>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Account } from '../account.js';
|
|
2
|
+
import { AccountEnvironment } from '../types/common.js';
|
|
2
3
|
import { LoginOptions } from '../types/login.js';
|
|
3
4
|
import { SessionObjectResponse, SessionUserId } from '../types/session.js';
|
|
4
5
|
export type LegacyLogoutListener = (session?: SessionObjectResponse) => void;
|
|
@@ -8,8 +9,12 @@ export type LegacyIdentity = LegacyIdentityMethods & {
|
|
|
8
9
|
loginUrl(options: LoginOptions): string;
|
|
9
10
|
/** @deprecated Pass an options object to `account.loginUrl()`. Removed in v7. */
|
|
10
11
|
loginUrl(state: string, acrValues?: string, scope?: string, redirectUri?: string, loginHint?: string, tag?: string, teaser?: string, maxAge?: number | string): string;
|
|
11
|
-
/** @deprecated
|
|
12
|
+
/** @deprecated Use `account.clientId`. Removed in v7. */
|
|
12
13
|
readonly clientId: string;
|
|
14
|
+
/** @deprecated Use `account.env`. Removed in v7. */
|
|
15
|
+
readonly env: AccountEnvironment;
|
|
16
|
+
/** @deprecated Use `account.redirectUri`. Removed in v7. */
|
|
17
|
+
readonly redirectUri: string;
|
|
13
18
|
/** @deprecated Use the Account session methods and events. Removed in v7. */
|
|
14
19
|
readonly _session: SessionObjectResponse;
|
|
15
20
|
/** @deprecated Only the legacy `logout` event is bridged. Removed in v7. */
|
|
@@ -22,8 +27,6 @@ export interface LegacyMonetization {
|
|
|
22
27
|
clearCachedAccessResult(productIds: string[], userId: SessionUserId): void;
|
|
23
28
|
}
|
|
24
29
|
export type LegacyCompatibilityOptions = {
|
|
25
|
-
/** Client id exposed on the legacy Identity adapter for Sourcepoint compatibility. */
|
|
26
|
-
clientId: string;
|
|
27
30
|
/** Window on which the legacy globals and ready events should be installed. */
|
|
28
31
|
window?: Window;
|
|
29
32
|
};
|
package/dist/compatibility.js
CHANGED
|
@@ -1,68 +1,73 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as e, r as t, t as n } from "./resolve-browser-window-wUnycyxt.js";
|
|
2
2
|
//#region src/compatibility/warnings.ts
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
},
|
|
6
|
-
console.warn(`${
|
|
7
|
-
},
|
|
8
|
-
console.warn(`${
|
|
9
|
-
},
|
|
3
|
+
var r = "[Account SDK compatibility]", i = !1, a = () => {
|
|
4
|
+
i || (i = !0, console.warn(`${r} The legacy compatibility layer is enabled. Migrate application code to the Account API. This compatibility layer will be removed in v7.`));
|
|
5
|
+
}, o = (e, t) => {
|
|
6
|
+
console.warn(`${r} ${e} is deprecated. Use ${t} instead. It will be removed in v7.`);
|
|
7
|
+
}, s = () => {
|
|
8
|
+
console.warn(`${r} schMonetization.hasAccess() ignores the legacy userId argument. Account.hasAccess() resolves the logged-in user automatically. It will be removed in v7.`);
|
|
9
|
+
}, c = class {
|
|
10
10
|
#e;
|
|
11
11
|
#t;
|
|
12
|
-
#n;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}, this.#e.on("logoutRequested", () => this.#o());
|
|
12
|
+
#n = [];
|
|
13
|
+
constructor(n) {
|
|
14
|
+
this.#e = n;
|
|
15
|
+
let r = e.get(n);
|
|
16
|
+
if (!r) throw new t("Legacy compatibility requires an Account from the same SDK build");
|
|
17
|
+
this.#t = r, r.beforeUpdate = (e, t) => {
|
|
18
|
+
"userId" in e && e.userId && !("userId" in t && t.userId) && this.#a(t);
|
|
19
|
+
}, this.#e.on("logoutRequested", () => this.#a());
|
|
21
20
|
}
|
|
22
21
|
get clientId() {
|
|
23
|
-
return
|
|
22
|
+
return o("schIdentity.clientId", "account.clientId"), this.#e.clientId;
|
|
23
|
+
}
|
|
24
|
+
get env() {
|
|
25
|
+
return o("schIdentity.env", "account.env"), this.#e.env;
|
|
26
|
+
}
|
|
27
|
+
get redirectUri() {
|
|
28
|
+
return o("schIdentity.redirectUri", "account.redirectUri"), this.#e.redirectUri;
|
|
24
29
|
}
|
|
25
30
|
get _session() {
|
|
26
|
-
return
|
|
31
|
+
return o("schIdentity._session", "account.hasSession()"), this.#t.getSession();
|
|
27
32
|
}
|
|
28
33
|
hasSession() {
|
|
29
|
-
return this.#
|
|
34
|
+
return this.#r("hasSession"), this.#e.hasSession();
|
|
30
35
|
}
|
|
31
36
|
isLoggedIn() {
|
|
32
|
-
return this.#
|
|
37
|
+
return this.#r("isLoggedIn"), this.#e.isLoggedIn();
|
|
33
38
|
}
|
|
34
39
|
isConnected() {
|
|
35
|
-
return this.#
|
|
40
|
+
return this.#r("isConnected"), this.#e.isConnected();
|
|
36
41
|
}
|
|
37
42
|
getUser() {
|
|
38
|
-
return this.#
|
|
43
|
+
return this.#r("getUser"), this.#e.getUser();
|
|
39
44
|
}
|
|
40
45
|
getUserId() {
|
|
41
|
-
return this.#
|
|
46
|
+
return this.#r("getUserId"), this.#e.getUserId();
|
|
42
47
|
}
|
|
43
48
|
getExternalId(...e) {
|
|
44
|
-
return this.#
|
|
49
|
+
return this.#r("getExternalId"), this.#e.getExternalId(...e);
|
|
45
50
|
}
|
|
46
51
|
getUserUuid() {
|
|
47
|
-
return this.#
|
|
52
|
+
return this.#r("getUserUuid"), this.#e.getUserUuid();
|
|
48
53
|
}
|
|
49
54
|
getUserSDRN() {
|
|
50
|
-
return this.#
|
|
55
|
+
return this.#r("getUserSDRN"), this.#e.getUserSDRN();
|
|
51
56
|
}
|
|
52
57
|
getUserContextData() {
|
|
53
|
-
return this.#
|
|
58
|
+
return this.#r("getUserContextData"), this.#e.getUserContextData();
|
|
54
59
|
}
|
|
55
60
|
getSpId() {
|
|
56
|
-
return this.#
|
|
61
|
+
return this.#r("getSpId"), this.#e.getSpId();
|
|
57
62
|
}
|
|
58
63
|
login(...e) {
|
|
59
|
-
return this.#
|
|
64
|
+
return this.#r("login"), this.#e.login(...e);
|
|
60
65
|
}
|
|
61
66
|
logout(...e) {
|
|
62
|
-
return this.#
|
|
67
|
+
return this.#r("logout"), this.#e.logout(...e);
|
|
63
68
|
}
|
|
64
69
|
loginUrl(e, t, n, r, i, a, o, s) {
|
|
65
|
-
return this.#
|
|
70
|
+
return this.#r("loginUrl"), typeof e == "string" ? this.#e.loginUrl({
|
|
66
71
|
state: e,
|
|
67
72
|
acrValues: t,
|
|
68
73
|
scope: n || void 0,
|
|
@@ -74,94 +79,93 @@ var a = "[Account SDK compatibility]", o = !1, s = () => {
|
|
|
74
79
|
}) : this.#e.loginUrl(e);
|
|
75
80
|
}
|
|
76
81
|
logoutUrl(...e) {
|
|
77
|
-
return this.#
|
|
82
|
+
return this.#r("logoutUrl"), this.#e.logoutUrl(...e);
|
|
78
83
|
}
|
|
79
84
|
accountUrl(...e) {
|
|
80
|
-
return this.#
|
|
85
|
+
return this.#r("accountUrl"), this.#e.accountUrl(...e);
|
|
81
86
|
}
|
|
82
87
|
showSimplifiedLoginWidget(...e) {
|
|
83
|
-
return this.#
|
|
88
|
+
return this.#r("showSimplifiedLoginWidget"), this.#e.showSimplifiedLoginWidget(...e);
|
|
84
89
|
}
|
|
85
90
|
clearCachedUserSession() {
|
|
86
|
-
return this.#
|
|
91
|
+
return this.#r("clearCachedUserSession"), this.#e.clearCachedUserSession();
|
|
87
92
|
}
|
|
88
93
|
on(e, t, n) {
|
|
89
|
-
return
|
|
94
|
+
return o("schIdentity.on('logout')", "account.on('logoutRequested') and account.on('sessionUpdated')"), this.#i(e), this.#n.push({
|
|
90
95
|
listener: t,
|
|
91
96
|
context: n
|
|
92
97
|
}), this;
|
|
93
98
|
}
|
|
94
99
|
off(e, t) {
|
|
95
|
-
return
|
|
100
|
+
return o("schIdentity.off('logout')", "account.off('logoutRequested') and account.off('sessionUpdated')"), this.#i(e), this.#n = t ? this.#n.filter((e) => e.listener !== t) : [], this;
|
|
96
101
|
}
|
|
97
|
-
#
|
|
98
|
-
|
|
102
|
+
#r(e) {
|
|
103
|
+
o(`schIdentity.${e}()`, `account.${e}()`);
|
|
99
104
|
}
|
|
100
|
-
#
|
|
101
|
-
if (
|
|
105
|
+
#i(e) {
|
|
106
|
+
if (e !== "logout") throw new t(`Account SDK legacy compatibility does not support the Identity "${e}" event`);
|
|
102
107
|
}
|
|
103
|
-
#
|
|
104
|
-
for (let { listener: t, context: n } of [...this.#
|
|
108
|
+
#a(...e) {
|
|
109
|
+
for (let { listener: t, context: n } of [...this.#n]) try {
|
|
105
110
|
t.apply(n, e);
|
|
106
111
|
} catch (e) {
|
|
107
112
|
console.error("[Account SDK compatibility] Legacy logout listener failed", e);
|
|
108
113
|
}
|
|
109
114
|
}
|
|
110
|
-
},
|
|
115
|
+
}, l = class {
|
|
111
116
|
#e;
|
|
112
117
|
constructor(e) {
|
|
113
118
|
this.#e = e;
|
|
114
119
|
}
|
|
115
120
|
hasAccess(e, t) {
|
|
116
|
-
return
|
|
121
|
+
return o("schMonetization.hasAccess()", "account.hasAccess()"), s(), this.#e.hasAccess(e);
|
|
117
122
|
}
|
|
118
123
|
clearCachedAccessResult(e, t) {
|
|
119
|
-
|
|
124
|
+
o("schMonetization.clearCachedAccessResult()", "account.clearCachedAccessResult()"), this.#e.clearCachedAccessResult(e, t);
|
|
120
125
|
}
|
|
121
|
-
},
|
|
126
|
+
}, u = "schAccount:ready", d = "schIdentity:ready", f = "schMonetization:ready", p = /* @__PURE__ */ new WeakSet(), m = () => new t("Account SDK legacy compatibility is not available in this browser context"), h = () => new t(`Account SDK legacy compatibility received ${u} without window.schAccount`), g = (e) => new t(`Account SDK legacy compatibility cannot define window.${e} because it already exists`), _ = (e) => {
|
|
122
127
|
for (let t of [
|
|
123
128
|
"schIdentity",
|
|
124
129
|
"Identity",
|
|
125
130
|
"schMonetization"
|
|
126
131
|
]) {
|
|
127
132
|
let n = Object.getOwnPropertyDescriptor(e, t), r = n?.configurable && "value" in n && n.value == null;
|
|
128
|
-
if (n && !r) throw
|
|
133
|
+
if (n && !r) throw g(t);
|
|
129
134
|
}
|
|
130
|
-
},
|
|
135
|
+
}, v = (e, t, n) => ({
|
|
131
136
|
configurable: !0,
|
|
132
137
|
enumerable: !0,
|
|
133
138
|
get: t,
|
|
134
139
|
set: (t) => {
|
|
135
|
-
if (t !== n) throw
|
|
136
|
-
|
|
140
|
+
if (t !== n) throw g(e);
|
|
141
|
+
o(`window.${e}`, "window.schAccount");
|
|
137
142
|
}
|
|
138
|
-
}),
|
|
143
|
+
}), y = (e, t, n) => {
|
|
139
144
|
e.dispatchEvent(new CustomEvent(t, { detail: { instance: n } }));
|
|
140
|
-
},
|
|
141
|
-
|
|
142
|
-
let
|
|
145
|
+
}, b = (e, t) => {
|
|
146
|
+
_(e);
|
|
147
|
+
let n = new c(t), r = new l(t);
|
|
143
148
|
Object.defineProperties(e, {
|
|
144
|
-
schIdentity:
|
|
145
|
-
Identity:
|
|
146
|
-
schMonetization:
|
|
147
|
-
}),
|
|
149
|
+
schIdentity: v("schIdentity", () => (o("window.schIdentity", "window.schAccount"), n), n),
|
|
150
|
+
Identity: v("Identity", () => (o("window.Identity", "window.schAccount"), n), n),
|
|
151
|
+
schMonetization: v("schMonetization", () => (o("window.schMonetization", "window.schAccount"), r), r)
|
|
152
|
+
}), y(e, d, n), y(e, f, r);
|
|
148
153
|
};
|
|
149
|
-
function
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
if (!t)
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
S(t, t.schAccount, e.clientId);
|
|
154
|
+
function x(e = {}) {
|
|
155
|
+
let t = n(e.window);
|
|
156
|
+
if (!t) throw m();
|
|
157
|
+
if (a(), !p.has(t)) {
|
|
158
|
+
if (_(t), p.add(t), t.schAccount) {
|
|
159
|
+
b(t, t.schAccount);
|
|
156
160
|
return;
|
|
157
161
|
}
|
|
158
|
-
t.addEventListener(
|
|
159
|
-
if (!t.schAccount) throw
|
|
160
|
-
|
|
162
|
+
t.addEventListener(u, () => {
|
|
163
|
+
if (!t.schAccount) throw h();
|
|
164
|
+
b(t, t.schAccount);
|
|
161
165
|
}, { once: !0 });
|
|
162
166
|
}
|
|
163
167
|
}
|
|
164
168
|
//#endregion
|
|
165
|
-
export {
|
|
169
|
+
export { x as enableLegacyCompatibility };
|
|
166
170
|
|
|
167
171
|
//# sourceMappingURL=compatibility.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compatibility.js","names":["#account","#clientId","#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 { 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 #clientId: string;\n readonly #sessionState: SessionState;\n #logoutListeners: { listener: LegacyLogoutListener; context?: unknown }[] = [];\n\n constructor(account: Account, clientId: string) {\n this.#account = account;\n this.#clientId = clientId;\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', 'the application Account configuration');\n return this.#clientId;\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 { assert, isNonEmptyString } from '../validate.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, clientId: string): void => {\n assertLegacyGlobalsAvailable(browserWindow);\n\n const identityShim = new LegacyIdentityAdapter(account, clientId);\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 assert(\n isNonEmptyString(options?.clientId),\n 'Account SDK legacy compatibility requires a clientId',\n );\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, options.clientId);\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, options.clientId);\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,GCfa,IAAb,MAA6D;CACzD;CACA;CACA;CACA,KAA4E,CAAC;CAE7E,YAAY,GAAkB,GAAkB;EAE5C,AADA,KAAKA,KAAW,GAChB,KAAKC,KAAY;EAEjB,IAAM,IAAe,EAAc,IAAI,CAAO;EAC9C,IAAI,CAAC,GACD,MAAM,IAAI,EAAS,kEAAkE;EAazF,AAXA,KAAKC,KAAgB,GAErB,EAAa,gBAAgB,GAAU,MAAY;GAC/C,AACI,YAAY,KACZ,EAAS,UACT,EAAE,YAAY,KAAW,EAAQ,WAEjC,KAAKC,GAAkB,CAAO;EAEtC,GACA,KAAKH,GAAS,GAAG,yBAAyB,KAAKG,GAAkB,CAAC;CACtE;CAEA,IAAI,WAAmB;EAEnB,OADA,EAAgB,wBAAwB,uCAAuC,GACxE,KAAKF;CAChB;CAEA,IAAI,WAAuC;EAEv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O,iBAAiB,GAAe;EACnC,aAAa,EAAuB,sBAbpC,EAAgB,sBAAsB,mBAAmB,GAClD,IAY4D,CAAY;EAC/E,UAAU,EAAuB,mBANjC,EAAgB,mBAAmB,mBAAmB,GAC/C,IAK4D,CAAY;EAC/E,iBAAiB,EACb,0BAZJ,EAAgB,0BAA0B,mBAAmB,GACtD,IAaH,CACJ;CACJ,CAAC,GAED,EAAmB,GAAe,GAAsB,CAAY,GACpE,EAAmB,GAAe,GAA0B,CAAgB;AAChF;AAUA,SAAgB,EAA0B,GAA2C;CACjF,EACI,EAAiB,GAAS,QAAQ,GAClC,sDACJ;CACA,IAAM,IAAgB,EAAqB,EAAQ,MAAM;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,YAAY,EAAQ,QAAQ;GAC9E;EACJ;EAEA,EAAc,iBACV,SACM;GACF,IAAI,CAAC,EAAc,YACf,MAAM,EAA0B;GAEpC,EAAqB,GAAe,EAAc,YAAY,EAAQ,QAAQ;EAClF,GACA,EAAE,MAAM,GAAK,CACjB;CAXA;AAYJ"}
|
|
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.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;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,kEAA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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, AccountEventName, } from './types/account.js';
|
|
7
|
+
export type { AccountConfig, AccountEventListener, AccountEventMap, AccountEventName, LoginRequestedEventDetail, LogoutRequestedEventDetail, } from './types/account.js';
|
|
8
8
|
export type { AccountEnvironment, LogFunction } from './types/common.js';
|
|
9
9
|
export type { LoginOptions, SimplifiedLoginData, SimplifiedLoginWidgetLoginOptions, SimplifiedLoginWidgetOptions, } from './types/login.js';
|
|
10
10
|
export type { HasAccessResult } from './types/monetization.js';
|