@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/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as e, r as t, t as n } from "./resolve-browser-window-wUnycyxt.js";
|
|
2
2
|
//#region src/cache.ts
|
|
3
|
-
function
|
|
3
|
+
function r(e) {
|
|
4
4
|
if (!e) return !1;
|
|
5
5
|
try {
|
|
6
6
|
let t = e(), n = "x-x-x-x".replace(/x/g, () => String(Math.random())), r = "TEST-VALUE";
|
|
@@ -11,7 +11,7 @@ function d(e) {
|
|
|
11
11
|
return !1;
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
-
var
|
|
14
|
+
var i = class {
|
|
15
15
|
store;
|
|
16
16
|
get;
|
|
17
17
|
set;
|
|
@@ -19,7 +19,7 @@ var f = class {
|
|
|
19
19
|
constructor(e) {
|
|
20
20
|
this.store = e, this.get = (e) => this.store.getItem(e), this.set = (e, t) => this.store.setItem(e, t), this.delete = (e) => this.store.removeItem(e);
|
|
21
21
|
}
|
|
22
|
-
},
|
|
22
|
+
}, a = class {
|
|
23
23
|
store;
|
|
24
24
|
get;
|
|
25
25
|
set;
|
|
@@ -31,14 +31,14 @@ var f = class {
|
|
|
31
31
|
delete this.store[e];
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
|
-
},
|
|
34
|
+
}, o = 2 ** 31 - 1, s = class {
|
|
35
35
|
cache;
|
|
36
36
|
type;
|
|
37
37
|
constructor(e) {
|
|
38
|
-
e &&
|
|
38
|
+
e && r(e) ? (this.cache = new i(e()), this.type = "WebStorage") : (this.cache = new a(), this.type = "ObjectLiteralStorage");
|
|
39
39
|
}
|
|
40
40
|
get(e) {
|
|
41
|
-
function
|
|
41
|
+
function n(e) {
|
|
42
42
|
if (e == null) return null;
|
|
43
43
|
try {
|
|
44
44
|
return JSON.parse(e);
|
|
@@ -47,23 +47,23 @@ var f = class {
|
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
try {
|
|
50
|
-
let
|
|
51
|
-
return
|
|
50
|
+
let t = n(this.cache.get(e));
|
|
51
|
+
return t && Number.isInteger(t.expiresOn) && t.expiresOn > Date.now() ? t.value : (this.delete(e), null);
|
|
52
52
|
} catch (e) {
|
|
53
|
-
throw new
|
|
53
|
+
throw new t(String(e));
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
-
set(e,
|
|
56
|
+
set(e, n, r = 0) {
|
|
57
57
|
if (!(r <= 0)) {
|
|
58
|
-
r = Math.min(
|
|
58
|
+
r = Math.min(o, r);
|
|
59
59
|
try {
|
|
60
|
-
let
|
|
60
|
+
let t = Math.floor(Date.now() + r);
|
|
61
61
|
this.cache.set(e, JSON.stringify({
|
|
62
|
-
expiresOn:
|
|
63
|
-
value:
|
|
62
|
+
expiresOn: t,
|
|
63
|
+
value: n
|
|
64
64
|
})), setTimeout(() => this.delete(e), r);
|
|
65
65
|
} catch (e) {
|
|
66
|
-
throw new
|
|
66
|
+
throw new t(String(e));
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
}
|
|
@@ -71,10 +71,10 @@ var f = class {
|
|
|
71
71
|
try {
|
|
72
72
|
this.cache.delete(e);
|
|
73
73
|
} catch (e) {
|
|
74
|
-
throw new
|
|
74
|
+
throw new t(String(e));
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
|
-
},
|
|
77
|
+
}, c = {
|
|
78
78
|
ENDPOINTS: {
|
|
79
79
|
SPiD: {
|
|
80
80
|
LOCAL: "http://id.localhost",
|
|
@@ -113,25 +113,56 @@ var f = class {
|
|
|
113
113
|
PRO_FI: "schibsted.fi",
|
|
114
114
|
PRO_DK: "schibsted.dk"
|
|
115
115
|
}
|
|
116
|
-
},
|
|
116
|
+
}, l = c.ENDPOINTS, u = c.NAMESPACE;
|
|
117
|
+
//#endregion
|
|
118
|
+
//#region src/validate.ts
|
|
119
|
+
function d(e, n = "Assertion failed") {
|
|
120
|
+
if (!e) throw new t(n);
|
|
121
|
+
}
|
|
122
|
+
function f(e) {
|
|
123
|
+
return typeof e == "string";
|
|
124
|
+
}
|
|
125
|
+
function p(e) {
|
|
126
|
+
return typeof e == "string" && e.length > 0;
|
|
127
|
+
}
|
|
128
|
+
function m(e) {
|
|
129
|
+
return typeof e == "object" && !!e;
|
|
130
|
+
}
|
|
131
|
+
function h(e) {
|
|
132
|
+
return m(e) && Object.keys(e).length > 0;
|
|
133
|
+
}
|
|
134
|
+
function g(e, ...t) {
|
|
135
|
+
try {
|
|
136
|
+
let n = new URL(e);
|
|
137
|
+
return t.every((e) => n[e]);
|
|
138
|
+
} catch {
|
|
139
|
+
return !1;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
function _(e) {
|
|
143
|
+
return typeof e == "function";
|
|
144
|
+
}
|
|
145
|
+
function v(e, t, n = !1) {
|
|
146
|
+
return f(e) && Array.isArray(t) ? n ? t.indexOf(e) !== -1 : t.some((t) => f(t) && e.toUpperCase() === t.toUpperCase()) : !1;
|
|
147
|
+
}
|
|
117
148
|
//#endregion
|
|
118
149
|
//#region src/object.ts
|
|
119
|
-
function y(...
|
|
120
|
-
let
|
|
121
|
-
if (!(
|
|
122
|
-
return
|
|
123
|
-
|
|
124
|
-
t !== void 0 && (
|
|
150
|
+
function y(...e) {
|
|
151
|
+
let n = {};
|
|
152
|
+
if (!(e && e.length)) throw new t("No objects to clone");
|
|
153
|
+
return e.forEach((e) => {
|
|
154
|
+
d(m(e)), h(e) && Object.entries(e).forEach(([e, t]) => {
|
|
155
|
+
t !== void 0 && (n[e] = m(t) ? b(t) : t);
|
|
125
156
|
});
|
|
126
|
-
}),
|
|
157
|
+
}), n;
|
|
127
158
|
}
|
|
128
159
|
function b(e) {
|
|
129
|
-
return
|
|
160
|
+
return d(typeof e == "object", `obj should be an object (even null) but it is ${e}`), JSON.parse(JSON.stringify(e)) || e;
|
|
130
161
|
}
|
|
131
162
|
//#endregion
|
|
132
163
|
//#region src/popup.ts
|
|
133
164
|
function ee(e) {
|
|
134
|
-
return
|
|
165
|
+
return d(m(e), `Object must be an object but it is '${e}'`), Object.keys(e).map((t) => `${t}=${e[t]}`).join(",");
|
|
135
166
|
}
|
|
136
167
|
var te = {
|
|
137
168
|
scrollbars: "yes",
|
|
@@ -141,21 +172,21 @@ var te = {
|
|
|
141
172
|
toolbar: "no",
|
|
142
173
|
resizable: "yes"
|
|
143
174
|
};
|
|
144
|
-
function ne(e, t, n = "",
|
|
145
|
-
|
|
146
|
-
let { height:
|
|
147
|
-
typeof
|
|
148
|
-
let
|
|
149
|
-
return e.open(t, n,
|
|
175
|
+
function ne(e, t, n = "", r = {}) {
|
|
176
|
+
d(m(e), `window was supposed to be an object but it is ${e}`), d(m(e.screen), "window should be a valid Window object but it lacks a 'screen' property"), d(_(e.open), "window should be a valid Window object but it lacks an 'open' function"), d(g(t), "Invalid URL for popup");
|
|
177
|
+
let { height: i, width: a } = e.screen, o = y(te, r), { width: s, height: c } = o;
|
|
178
|
+
typeof s == "number" && Number.isFinite(s) && Number.isFinite(a) && (o.left = (a - s) / 2), typeof c == "number" && Number.isFinite(c) && Number.isFinite(i) && (o.top = (i - c) / 2);
|
|
179
|
+
let l = ee(o);
|
|
180
|
+
return e.open(t, n, l);
|
|
150
181
|
}
|
|
151
182
|
//#endregion
|
|
152
183
|
//#region src/url.ts
|
|
153
|
-
function x(
|
|
154
|
-
return
|
|
184
|
+
function x(e, t) {
|
|
185
|
+
return d(p(e), `"url" param must be a non empty string: ${typeof e}`), h(t) && g(t[e]) ? t[e] : (d(g(e, "hostname"), `Bad URL given: '${e}'`), e);
|
|
155
186
|
}
|
|
156
187
|
//#endregion
|
|
157
188
|
//#region src/rest-client.ts
|
|
158
|
-
var re = (e) => e.map((e) =>
|
|
189
|
+
var re = (e) => e.map((e) => m(e) ? JSON.stringify(e, null, 2) : e).join(" "), S = (e, ...t) => {
|
|
159
190
|
e && e(re(t));
|
|
160
191
|
};
|
|
161
192
|
function C(e) {
|
|
@@ -171,35 +202,35 @@ function C(e) {
|
|
|
171
202
|
return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g, (e) => t[e]);
|
|
172
203
|
}
|
|
173
204
|
var w = () => window.fetch && window.fetch.bind(window), T = () => {
|
|
174
|
-
throw new
|
|
205
|
+
throw new t("fetch is not available in this environment");
|
|
175
206
|
}, E = class e {
|
|
176
207
|
url;
|
|
177
208
|
defaultParams;
|
|
178
209
|
log;
|
|
179
210
|
fetch;
|
|
180
|
-
constructor({ serverUrl: e = "PRE", envDic: t, fetch: n = w() ?? T, log:
|
|
181
|
-
|
|
182
|
-
let
|
|
183
|
-
this.url = new URL(
|
|
211
|
+
constructor({ serverUrl: e = "PRE", envDic: t, fetch: n = w() ?? T, log: r, defaultParams: i = {} }) {
|
|
212
|
+
d(m(i), "defaultParams should be a non-null object");
|
|
213
|
+
let a = x(e, t ?? {}), o = a.endsWith("/") ? a : `${a}/`;
|
|
214
|
+
this.url = new URL(o), this.defaultParams = i, r && (d(_(r), `log must be a function but it is ${r}`), this.log = r), this.fetch = n;
|
|
184
215
|
}
|
|
185
216
|
async go(e) {
|
|
186
|
-
let { method:
|
|
217
|
+
let { method: n, headers: r, pathname: i, data: a = {}, useDefaultParams: o = !0, fetchOptions: s = {
|
|
187
218
|
method: e.method,
|
|
188
219
|
credentials: "include"
|
|
189
|
-
}, parseResponse:
|
|
190
|
-
|
|
191
|
-
let
|
|
192
|
-
S(this.log, "Request:",
|
|
220
|
+
}, parseResponse: c } = e;
|
|
221
|
+
d(p(n), `Method must be a non empty string but it is "${n}"`), d(p(i), `Pathname must be string but it is "${i}"`), d(m(a), "data must be a non-null object"), s.headers = m(r) ? r : {};
|
|
222
|
+
let l = this.makeUrl(i, a, o);
|
|
223
|
+
S(this.log, "Request:", n.toUpperCase(), l), S(this.log, "Request Headers:", s.headers), S(this.log, "Request Body:", s.body);
|
|
193
224
|
try {
|
|
194
|
-
let e = await this.fetch(
|
|
195
|
-
if (S(this.log, "Response Code:", e.status, e.statusText), !e.ok) throw new
|
|
196
|
-
let
|
|
197
|
-
return S(this.log, "Response Parsed:",
|
|
225
|
+
let e = await this.fetch(l, s);
|
|
226
|
+
if (S(this.log, "Response Code:", e.status, e.statusText), !e.ok) throw new t(e.statusText, { code: e.status });
|
|
227
|
+
let n = await e.json();
|
|
228
|
+
return S(this.log, "Response Parsed:", n), c ? c(n) : n;
|
|
198
229
|
} catch (e) {
|
|
199
|
-
let
|
|
200
|
-
|
|
201
|
-
let
|
|
202
|
-
throw new
|
|
230
|
+
let r = f(e) ? e : "Unknown RESTClient error";
|
|
231
|
+
m(e) && f(e.message) && (r = e.message);
|
|
232
|
+
let i = m(e) ? e : void 0;
|
|
233
|
+
throw new t(`Failed to '${n}' '${l}': '${r}'`, i);
|
|
203
234
|
}
|
|
204
235
|
}
|
|
205
236
|
makeUrl(t = "", n = {}, r = !0) {
|
|
@@ -222,7 +253,7 @@ var w = () => window.fetch && window.fetch.bind(window), T = () => {
|
|
|
222
253
|
let r = t ? y(n, e) : y(e);
|
|
223
254
|
return Object.keys(r).filter((e) => r[e] !== "").map((e) => `${C(e)}=${C(String(r[e]))}`).join("&");
|
|
224
255
|
}
|
|
225
|
-
}, D = (e) => Object.hasOwn(
|
|
256
|
+
}, D = (e) => Object.hasOwn(u, e), O = (e, t) => (d(p(t), "clientId parameter is required"), d(D(e), `env parameter is invalid: ${e}`), `sdrn:${u[e]}:client:${t}`), k = ({ serverUrl: e, log: t, defaultParams: n }) => new E({
|
|
226
257
|
serverUrl: e,
|
|
227
258
|
log: t,
|
|
228
259
|
defaultParams: n
|
|
@@ -230,31 +261,31 @@ var w = () => window.fetch && window.fetch.bind(window), T = () => {
|
|
|
230
261
|
//#endregion
|
|
231
262
|
//#region src/session-response.ts
|
|
232
263
|
function A(e) {
|
|
233
|
-
return
|
|
264
|
+
return m(e) && typeof e.result == "boolean";
|
|
234
265
|
}
|
|
235
266
|
function j(e) {
|
|
236
267
|
return A(e) && e.result === !0;
|
|
237
268
|
}
|
|
238
269
|
function M(e) {
|
|
239
|
-
return
|
|
270
|
+
return m(e) && !!e.error;
|
|
240
271
|
}
|
|
241
272
|
function N(e) {
|
|
242
|
-
return
|
|
273
|
+
return m(e) && Object.keys(e).length === 1 && f(e.redirectURL);
|
|
243
274
|
}
|
|
244
275
|
function P(e) {
|
|
245
276
|
return j(e) && typeof e.userId == "number";
|
|
246
277
|
}
|
|
247
278
|
function F(e) {
|
|
248
|
-
return N(e) || M(e) || A(e) ||
|
|
279
|
+
return N(e) || M(e) || A(e) || m(e) ? e : {};
|
|
249
280
|
}
|
|
250
281
|
//#endregion
|
|
251
282
|
//#region src/spid-talk.ts
|
|
252
283
|
function I(e) {
|
|
253
|
-
(!e.SPiD || typeof e.SPiD != "object") && (e.SPiD = {}), (!e.SPiD.Talk || typeof e.SPiD.Talk != "object") && (e.SPiD.Talk = {}),
|
|
284
|
+
(!e.SPiD || typeof e.SPiD != "object") && (e.SPiD = {}), (!e.SPiD.Talk || typeof e.SPiD.Talk != "object") && (e.SPiD.Talk = {}), _(e.SPiD.Talk.response) || (e.SPiD.Talk.response = (t, n) => e[t](n));
|
|
254
285
|
}
|
|
255
286
|
//#endregion
|
|
256
287
|
//#region src/types/login.ts
|
|
257
|
-
var L = (e) => typeof e.openSimplifiedLoginWidget == "function", R = "6.0.0-alpha.
|
|
288
|
+
var L = (e) => typeof e.openSimplifiedLoginWidget == "function", R = "6.0.0-alpha.13", z = "hasSession-cache", B = "sessionCallBlocked-cache", V = 1e3 * 60 * 5, H = "tab-id-cache", U = Math.floor(Math.random() * 1e5), W = 1e3 * 60 * 60 * 24 * 30, G = () => window, K = class {
|
|
258
289
|
eventTarget = new EventTarget();
|
|
259
290
|
window;
|
|
260
291
|
clientId;
|
|
@@ -277,37 +308,37 @@ var L = (e) => typeof e.openSimplifiedLoginWidget == "function", R = "6.0.0-alph
|
|
|
277
308
|
setVarnishCookie;
|
|
278
309
|
varnishExpiresIn;
|
|
279
310
|
varnishCookieDomain;
|
|
280
|
-
constructor({ clientId:
|
|
281
|
-
|
|
282
|
-
let
|
|
311
|
+
constructor({ clientId: t, redirectUri: n, sessionDomain: r, env: i, log: a, window: o = G(), callbackBeforeRedirect: c = () => {} }) {
|
|
312
|
+
d(p(t), "clientId parameter is required"), d(m(o), "The reference to window is missing"), d(!n || g(n), "redirectUri parameter is invalid"), d(p(r) && g(r), "sessionDomain parameter is not a valid URL"), d(f(i), `env parameter is invalid: ${i}`), I(o), this.window = o, this.clientId = t, this.redirectUri = n, this.env = i, this.log = a, this.callbackBeforeRedirect = c, this.sessionStorageCache = new s(() => this.window && this.window.sessionStorage), this.localStorageCache = new s(() => this.window && this.window.localStorage), this.enableSessionCaching = !0, this.session = {}, e.set(this, { getSession: () => this.session });
|
|
313
|
+
let u = {
|
|
283
314
|
client_id: this.clientId,
|
|
284
315
|
redirect_uri: this.redirectUri
|
|
285
|
-
},
|
|
316
|
+
}, h = O(this.env, this.clientId);
|
|
286
317
|
this.spid = k({
|
|
287
|
-
serverUrl: x(i,
|
|
318
|
+
serverUrl: x(i, l.SPiD),
|
|
288
319
|
log: this.log,
|
|
289
|
-
defaultParams:
|
|
320
|
+
defaultParams: u
|
|
290
321
|
}), this.oauthService = k({
|
|
291
|
-
serverUrl: x(i,
|
|
322
|
+
serverUrl: x(i, l.SPiD),
|
|
292
323
|
log: this.log,
|
|
293
|
-
defaultParams:
|
|
324
|
+
defaultParams: u
|
|
294
325
|
}), this.bffService = k({
|
|
295
|
-
serverUrl: x(i,
|
|
326
|
+
serverUrl: x(i, l.BFF),
|
|
296
327
|
log: this.log,
|
|
297
|
-
defaultParams:
|
|
328
|
+
defaultParams: u
|
|
298
329
|
}), this.sessionService = k({
|
|
299
330
|
serverUrl: r,
|
|
300
331
|
log: this.log,
|
|
301
332
|
defaultParams: {
|
|
302
|
-
client_sdrn:
|
|
333
|
+
client_sdrn: h,
|
|
303
334
|
redirect_uri: this.redirectUri,
|
|
304
335
|
sdk_version: R
|
|
305
336
|
}
|
|
306
337
|
}), this.globalSessionService = k({
|
|
307
|
-
serverUrl: x(i,
|
|
338
|
+
serverUrl: x(i, l.SESSION_SERVICE),
|
|
308
339
|
log: this.log,
|
|
309
340
|
defaultParams: {
|
|
310
|
-
client_sdrn:
|
|
341
|
+
client_sdrn: h,
|
|
311
342
|
sdk_version: R
|
|
312
343
|
}
|
|
313
344
|
}), this.usedSessionServiceGetSessionEndpoint = this.sessionService.url.pathname && this.sessionService.url.pathname.length <= 1 ? "v2/session" : "session", this._unblockSessionCall();
|
|
@@ -337,9 +368,9 @@ var L = (e) => typeof e.openSimplifiedLoginWidget == "function", R = "6.0.0-alph
|
|
|
337
368
|
this.popup &&= (this.popup.closed || this.popup.close(), null);
|
|
338
369
|
}
|
|
339
370
|
enableVarnishCookie(e) {
|
|
340
|
-
if (typeof e != "object") throw new
|
|
341
|
-
let { expiresIn:
|
|
342
|
-
|
|
371
|
+
if (typeof e != "object") throw new t("VarnishCookieOptions must be an object");
|
|
372
|
+
let { expiresIn: n = 0, domain: r } = e;
|
|
373
|
+
d(Number.isInteger(n), "'expiresIn' must be an integer"), d(n >= 0, "'expiresIn' cannot be negative"), this.setVarnishCookie = !0, this.varnishExpiresIn = n, this.varnishCookieDomain = r;
|
|
343
374
|
}
|
|
344
375
|
_maybeSetVarnishCookie(e) {
|
|
345
376
|
if (!this.setVarnishCookie || !A(e)) return;
|
|
@@ -369,22 +400,22 @@ var L = (e) => typeof e.openSimplifiedLoginWidget == "function", R = "6.0.0-alph
|
|
|
369
400
|
return Promise.resolve(N(e) ? {} : e);
|
|
370
401
|
}
|
|
371
402
|
if (this.hasSessionInProgress) return this.hasSessionInProgress;
|
|
372
|
-
let
|
|
373
|
-
if (M(
|
|
374
|
-
return this._maybeSetVarnishCookie(
|
|
375
|
-
},
|
|
403
|
+
let n = !1, r = (r) => {
|
|
404
|
+
if (M(r)) throw new t("HasSession failed", m(r.error) ? r.error : { description: String(r.error) });
|
|
405
|
+
return this._maybeSetVarnishCookie(r), n = (A(this.session) && this.session.id) !== (A(r) && r.id), e.get(this)?.beforeUpdate?.(this.session, r), this.session = r, r;
|
|
406
|
+
}, i = () => {
|
|
376
407
|
let e = this.sessionStorageCache.get(z);
|
|
377
408
|
return e ? F(e) : null;
|
|
378
|
-
},
|
|
409
|
+
}, a = async () => {
|
|
379
410
|
if (this.enableSessionCaching) {
|
|
380
|
-
let e =
|
|
381
|
-
if (e) return N(e) ? {} :
|
|
411
|
+
let e = i();
|
|
412
|
+
if (e) return N(e) ? {} : r(e);
|
|
382
413
|
}
|
|
383
414
|
let e = null;
|
|
384
415
|
try {
|
|
385
416
|
e = await this.sessionService.get(this.usedSessionServiceGetSessionEndpoint, { tabId: this._getTabId() }, F);
|
|
386
417
|
} catch (e) {
|
|
387
|
-
let t =
|
|
418
|
+
let t = m(e) ? e : void 0;
|
|
388
419
|
if (t?.code === 400 && this.enableSessionCaching) {
|
|
389
420
|
let n = 1e3 * (typeof t.expiresIn == "number" ? t.expiresIn : 300);
|
|
390
421
|
this.sessionStorageCache.set(z, { error: e }, n);
|
|
@@ -398,10 +429,10 @@ var L = (e) => typeof e.openSimplifiedLoginWidget == "function", R = "6.0.0-alph
|
|
|
398
429
|
this.sessionStorageCache.set(z, e, t);
|
|
399
430
|
}
|
|
400
431
|
}
|
|
401
|
-
return
|
|
432
|
+
return r(e ?? {});
|
|
402
433
|
};
|
|
403
|
-
return this.hasSessionInProgress =
|
|
404
|
-
throw this.hasSessionInProgress = !1, new
|
|
434
|
+
return this.hasSessionInProgress = a().then((e) => (n && typeof e != "string" && this.eventTarget.dispatchEvent(new CustomEvent("sessionUpdated", { detail: e })), this.hasSessionInProgress = !1, typeof e == "string" && (this.window.location.href = e), e), (e) => {
|
|
435
|
+
throw this.hasSessionInProgress = !1, new t("HasSession failed", e);
|
|
405
436
|
}), this.hasSessionInProgress;
|
|
406
437
|
}
|
|
407
438
|
async isLoggedIn() {
|
|
@@ -426,38 +457,38 @@ var L = (e) => typeof e.openSimplifiedLoginWidget == "function", R = "6.0.0-alph
|
|
|
426
457
|
}
|
|
427
458
|
async getUser() {
|
|
428
459
|
let e = await this.hasSession();
|
|
429
|
-
if (!j(e)) throw new
|
|
460
|
+
if (!j(e)) throw new t("The user is not connected to this merchant");
|
|
430
461
|
return b(e);
|
|
431
462
|
}
|
|
432
463
|
async getUserId() {
|
|
433
464
|
let e = await this.hasSession();
|
|
434
465
|
if (P(e)) return e.userId;
|
|
435
|
-
throw new
|
|
466
|
+
throw new t("The user is not connected to this merchant");
|
|
436
467
|
}
|
|
437
|
-
async getExternalId(e,
|
|
468
|
+
async getExternalId(e, n = "") {
|
|
438
469
|
let r = await this.hasSession(), i = A(r) ? r.pairId : void 0;
|
|
439
|
-
if (!i) throw new
|
|
440
|
-
if (!e || e.length === 0) throw new
|
|
470
|
+
if (!i) throw new t("pairId missing in user session!");
|
|
471
|
+
if (!e || e.length === 0) throw new t("externalParty cannot be empty");
|
|
441
472
|
let a = (e) => Array.from(new Uint8Array(e)).map((e) => e.toString(16).padStart(2, "0")).join(""), o = (e) => crypto.subtle.digest("SHA-256", e);
|
|
442
|
-
return (async (e) => o(new TextEncoder().encode(e)).then((e) => a(e)))(((e, t, n) => n ? `${e}:${t}:${n}` : `${e}:${t}`)(i, e,
|
|
473
|
+
return (async (e) => o(new TextEncoder().encode(e)).then((e) => a(e)))(((e, t, n) => n ? `${e}:${t}:${n}` : `${e}:${t}`)(i, e, n));
|
|
443
474
|
}
|
|
444
475
|
async getUserSDRN() {
|
|
445
476
|
let e = await this.hasSession();
|
|
446
477
|
if (A(e) && e.sdrn) return e.sdrn;
|
|
447
|
-
throw new
|
|
478
|
+
throw new t("Failed to get SDRN from user session");
|
|
448
479
|
}
|
|
449
480
|
async getUserUuid() {
|
|
450
481
|
let e = await this.hasSession();
|
|
451
482
|
if (A(e) && e.uuid && e.result) return e.uuid;
|
|
452
|
-
throw new
|
|
483
|
+
throw new t("The user is not connected to this merchant");
|
|
453
484
|
}
|
|
454
485
|
async getUserContextData() {
|
|
455
486
|
try {
|
|
456
|
-
return await this.globalSessionService.get("user-context", void 0, (e) =>
|
|
487
|
+
return await this.globalSessionService.get("user-context", void 0, (e) => m(e) && f(e.identifier) ? {
|
|
457
488
|
identifier: e.identifier,
|
|
458
|
-
display_text:
|
|
459
|
-
client_name:
|
|
460
|
-
provider_id:
|
|
489
|
+
display_text: f(e.display_text) ? e.display_text : "",
|
|
490
|
+
client_name: f(e.client_name) ? e.client_name : "",
|
|
491
|
+
provider_id: f(e.provider_id) ? e.provider_id : void 0
|
|
461
492
|
} : null);
|
|
462
493
|
} catch {
|
|
463
494
|
return null;
|
|
@@ -496,8 +527,8 @@ var L = (e) => typeof e.openSimplifiedLoginWidget == "function", R = "6.0.0-alph
|
|
|
496
527
|
try {
|
|
497
528
|
let e = await this.hasSession();
|
|
498
529
|
if (A(e)) return e.sp_id || null;
|
|
499
|
-
let
|
|
500
|
-
return t
|
|
530
|
+
let t = m(e) && "sp_id" in e ? e.sp_id : void 0;
|
|
531
|
+
return f(t) ? t : null;
|
|
501
532
|
} catch {
|
|
502
533
|
return null;
|
|
503
534
|
}
|
|
@@ -507,8 +538,8 @@ var L = (e) => typeof e.openSimplifiedLoginWidget == "function", R = "6.0.0-alph
|
|
|
507
538
|
let t = this.logoutUrl(e);
|
|
508
539
|
this.eventTarget.dispatchEvent(new CustomEvent("logoutRequested", { detail: { url: t } })), this.window.location.href = t;
|
|
509
540
|
}
|
|
510
|
-
loginUrl({ state: e, acrValues: t = "", scope: n = "openid", redirectUri: r = this.redirectUri, loginHint:
|
|
511
|
-
return
|
|
541
|
+
loginUrl({ state: e, acrValues: t = "", scope: n = "openid", redirectUri: r = this.redirectUri, loginHint: i = "", tag: a = "", teaser: o = "", maxAge: s = "", locale: c, oneStepLogin: l = !1, prompt: u = "select_account", xDomainId: f = "", xEnvironmentId: m = "", originCampaign: h = "" }) {
|
|
542
|
+
return d(!t || v(t, ["", "otp-email"], !0) || t.split(" ").every((e) => v(e, [
|
|
512
543
|
"password",
|
|
513
544
|
"otp",
|
|
514
545
|
"sms",
|
|
@@ -517,26 +548,26 @@ var L = (e) => typeof e.openSimplifiedLoginWidget == "function", R = "6.0.0-alph
|
|
|
517
548
|
"eid-se",
|
|
518
549
|
"eid-fi",
|
|
519
550
|
"eid"
|
|
520
|
-
], !0)), `The acrValues parameter is not acceptable: ${t}`),
|
|
551
|
+
], !0)), `The acrValues parameter is not acceptable: ${t}`), d(g(r), `loginUrl(): redirectUri must be a valid url but is ${r}`), d(p(e), `the state parameter should be a non empty string but it is ${e}`), this.oauthService.makeUrl("oauth/authorize", {
|
|
521
552
|
response_type: "code",
|
|
522
553
|
redirect_uri: r,
|
|
523
554
|
scope: n,
|
|
524
555
|
state: e,
|
|
525
556
|
acr_values: t,
|
|
526
|
-
login_hint:
|
|
527
|
-
tag:
|
|
528
|
-
teaser:
|
|
529
|
-
max_age:
|
|
530
|
-
locale:
|
|
531
|
-
one_step_login:
|
|
532
|
-
prompt: t ? "" :
|
|
533
|
-
x_domain_id:
|
|
534
|
-
x_env_id:
|
|
535
|
-
utm_campaign:
|
|
557
|
+
login_hint: i,
|
|
558
|
+
tag: a,
|
|
559
|
+
teaser: o,
|
|
560
|
+
max_age: s,
|
|
561
|
+
locale: c,
|
|
562
|
+
one_step_login: l || "",
|
|
563
|
+
prompt: t ? "" : u,
|
|
564
|
+
x_domain_id: f,
|
|
565
|
+
x_env_id: m,
|
|
566
|
+
utm_campaign: h
|
|
536
567
|
});
|
|
537
568
|
}
|
|
538
569
|
logoutUrl(e = this.redirectUri) {
|
|
539
|
-
|
|
570
|
+
d(g(e), "logoutUrl(): redirectUri is invalid");
|
|
540
571
|
let t = { redirect_uri: e };
|
|
541
572
|
return this.sessionService.makeUrl("logout", t);
|
|
542
573
|
}
|
|
@@ -546,9 +577,9 @@ var L = (e) => typeof e.openSimplifiedLoginWidget == "function", R = "6.0.0-alph
|
|
|
546
577
|
redirect_uri: e
|
|
547
578
|
});
|
|
548
579
|
}
|
|
549
|
-
async showSimplifiedLoginWidget(e,
|
|
580
|
+
async showSimplifiedLoginWidget(e, n) {
|
|
550
581
|
let r = await this.getUserContextData(), i = { client_id: this.clientId };
|
|
551
|
-
|
|
582
|
+
n && n.encoding && (i.encoding = n.encoding);
|
|
552
583
|
let a = this.bffService.makeUrl("simplified-login-widget", i, !1), o = async (e) => {
|
|
553
584
|
let t = typeof e.state == "function" ? await e.state() : e.state;
|
|
554
585
|
return {
|
|
@@ -558,7 +589,7 @@ var L = (e) => typeof e.openSimplifiedLoginWidget == "function", R = "6.0.0-alph
|
|
|
558
589
|
};
|
|
559
590
|
return new Promise((i, s) => {
|
|
560
591
|
if (!r?.display_text || !r.identifier) {
|
|
561
|
-
s(new
|
|
592
|
+
s(new t("Missing user data"));
|
|
562
593
|
return;
|
|
563
594
|
}
|
|
564
595
|
let c = {
|
|
@@ -572,7 +603,7 @@ var L = (e) => typeof e.openSimplifiedLoginWidget == "function", R = "6.0.0-alph
|
|
|
572
603
|
window.onresize = e;
|
|
573
604
|
}
|
|
574
605
|
};
|
|
575
|
-
|
|
606
|
+
n && n.locale && (c.locale = n.locale);
|
|
576
607
|
let l = async () => {
|
|
577
608
|
this.login(Object.assign(await o(e), { loginHint: r.identifier }));
|
|
578
609
|
}, u = async () => {
|
|
@@ -589,12 +620,12 @@ var L = (e) => typeof e.openSimplifiedLoginWidget == "function", R = "6.0.0-alph
|
|
|
589
620
|
let p = document.createElement("script");
|
|
590
621
|
p.type = "text/javascript", p.src = a, p.onload = () => {
|
|
591
622
|
if (!L(window)) {
|
|
592
|
-
s(new
|
|
623
|
+
s(new t("Error when loading simplified login widget content"));
|
|
593
624
|
return;
|
|
594
625
|
}
|
|
595
626
|
window.openSimplifiedLoginWidget(c, l, u, d, f), i(!0);
|
|
596
627
|
}, p.onerror = () => {
|
|
597
|
-
s(new
|
|
628
|
+
s(new t("Error when loading simplified login widget content"));
|
|
598
629
|
}, document.getElementsByTagName("body")[0].appendChild(p);
|
|
599
630
|
});
|
|
600
631
|
}
|
|
@@ -602,16 +633,16 @@ var L = (e) => typeof e.openSimplifiedLoginWidget == "function", R = "6.0.0-alph
|
|
|
602
633
|
//#endregion
|
|
603
634
|
//#region src/has-access-response.ts
|
|
604
635
|
function q(e) {
|
|
605
|
-
if (!
|
|
606
|
-
let { entitled:
|
|
607
|
-
if (typeof
|
|
636
|
+
if (!m(e)) throw new t("Invalid hasAccess response");
|
|
637
|
+
let { entitled: n, ttl: r, allowedFeatures: i, userId: a, uuid: o, sig: s } = e;
|
|
638
|
+
if (typeof n != "boolean" || typeof r != "number" || !Array.isArray(i) || typeof a != "number" || !f(o) || !f(s)) throw new t("Invalid hasAccess response");
|
|
608
639
|
return {
|
|
609
|
-
entitled:
|
|
610
|
-
ttl:
|
|
611
|
-
allowedFeatures:
|
|
612
|
-
userId:
|
|
613
|
-
uuid:
|
|
614
|
-
sig:
|
|
640
|
+
entitled: n,
|
|
641
|
+
ttl: r,
|
|
642
|
+
allowedFeatures: i.filter(f),
|
|
643
|
+
userId: a,
|
|
644
|
+
uuid: o,
|
|
645
|
+
sig: s
|
|
615
646
|
};
|
|
616
647
|
}
|
|
617
648
|
//#endregion
|
|
@@ -620,23 +651,23 @@ var J = () => window, Y = class {
|
|
|
620
651
|
cache;
|
|
621
652
|
sessionService;
|
|
622
653
|
pendingHasAccessRequests;
|
|
623
|
-
constructor({ clientId: e, redirectUri:
|
|
624
|
-
I(
|
|
625
|
-
let
|
|
626
|
-
this.cache = new
|
|
627
|
-
serverUrl:
|
|
654
|
+
constructor({ clientId: e, redirectUri: t, env: n, sessionDomain: r, window: i = J() }) {
|
|
655
|
+
I(i), d(p(e), "clientId parameter is required"), d(f(n), `env parameter is invalid: ${n}`);
|
|
656
|
+
let a = O(n, e);
|
|
657
|
+
this.cache = new s(() => i && i.sessionStorage), this.pendingHasAccessRequests = {}, r && (d(g(r), "sessionDomain parameter is not a valid URL"), this.sessionService = k({
|
|
658
|
+
serverUrl: r,
|
|
628
659
|
defaultParams: {
|
|
629
|
-
client_sdrn:
|
|
630
|
-
redirect_uri:
|
|
660
|
+
client_sdrn: a,
|
|
661
|
+
redirect_uri: t,
|
|
631
662
|
sdk_version: R
|
|
632
663
|
}
|
|
633
664
|
}));
|
|
634
665
|
}
|
|
635
|
-
async hasAccess(e,
|
|
636
|
-
if (!this.sessionService) throw new
|
|
637
|
-
if (!
|
|
638
|
-
if (!Array.isArray(e)) throw new
|
|
639
|
-
let r = [...e].sort(), i = this.accessCacheKey(r,
|
|
666
|
+
async hasAccess(e, n) {
|
|
667
|
+
if (!this.sessionService) throw new t("hasAccess can only be called if 'sessionDomain' is configured");
|
|
668
|
+
if (!n) throw new t("'userId' must be specified");
|
|
669
|
+
if (!Array.isArray(e)) throw new t("'productIds' must be an array");
|
|
670
|
+
let r = [...e].sort(), i = this.accessCacheKey(r, n), a = this.cache.get(i);
|
|
640
671
|
if (!a) {
|
|
641
672
|
this.pendingHasAccessRequests[i] || (this.pendingHasAccessRequests[i] = this.sessionService.get(`/hasAccess/${r.join(",")}`, void 0, q));
|
|
642
673
|
let e = this.pendingHasAccessRequests[i];
|
|
@@ -660,105 +691,117 @@ var J = () => window, Y = class {
|
|
|
660
691
|
#e;
|
|
661
692
|
#t;
|
|
662
693
|
#n;
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
let
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
694
|
+
#r;
|
|
695
|
+
#i;
|
|
696
|
+
#a;
|
|
697
|
+
constructor(r) {
|
|
698
|
+
let i = n(r.window);
|
|
699
|
+
if (!i) throw new t("Schibsted Account SDK is not available in this browser context");
|
|
700
|
+
if (i.schAccount) throw new t("Schibsted Account SDK has already been initialized");
|
|
701
|
+
let { log: a, callbackBeforeRedirect: o, defaultProductIds: s, varnish: c } = r, l = {
|
|
702
|
+
clientId: r.clientId,
|
|
703
|
+
redirectUri: r.redirectUri,
|
|
704
|
+
sessionDomain: r.sessionDomain,
|
|
705
|
+
env: r.env ?? "PRE",
|
|
706
|
+
window: i
|
|
673
707
|
};
|
|
674
|
-
if (this.#
|
|
675
|
-
...
|
|
676
|
-
log:
|
|
677
|
-
callbackBeforeRedirect:
|
|
678
|
-
}),
|
|
679
|
-
if (
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
}
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
708
|
+
if (this.#i = new K({
|
|
709
|
+
...l,
|
|
710
|
+
log: a,
|
|
711
|
+
callbackBeforeRedirect: o
|
|
712
|
+
}), s !== void 0 && !Array.isArray(s)) throw new t("Account defaultProductIds config must be an array");
|
|
713
|
+
if (c && (typeof c != "object" || Array.isArray(c))) throw new t("Account varnish config must be an object");
|
|
714
|
+
c && this.#i.enableVarnishCookie(c), this.#a = new Y(l), this.#e = l.clientId, this.#t = l.env, this.#n = l.redirectUri, this.#r = s && Object.freeze([...s]);
|
|
715
|
+
let u = e.get(this.#i);
|
|
716
|
+
u && e.set(this, u), i.schAccount = this, i.dispatchEvent(new CustomEvent("schAccount:ready", { detail: { instance: this } }));
|
|
717
|
+
}
|
|
718
|
+
get clientId() {
|
|
719
|
+
return this.#e;
|
|
720
|
+
}
|
|
721
|
+
get env() {
|
|
722
|
+
return this.#t;
|
|
723
|
+
}
|
|
724
|
+
get redirectUri() {
|
|
725
|
+
return this.#n;
|
|
726
|
+
}
|
|
727
|
+
get defaultProductIds() {
|
|
728
|
+
return this.#r;
|
|
686
729
|
}
|
|
687
730
|
hasSession() {
|
|
688
|
-
return this.#
|
|
731
|
+
return this.#i.hasSession();
|
|
689
732
|
}
|
|
690
733
|
isLoggedIn() {
|
|
691
|
-
return this.#
|
|
734
|
+
return this.#i.isLoggedIn();
|
|
692
735
|
}
|
|
693
736
|
isConnected() {
|
|
694
|
-
return this.#
|
|
737
|
+
return this.#i.isConnected();
|
|
695
738
|
}
|
|
696
739
|
getUser() {
|
|
697
|
-
return this.#
|
|
740
|
+
return this.#i.getUser();
|
|
698
741
|
}
|
|
699
742
|
getUserId() {
|
|
700
|
-
return this.#
|
|
743
|
+
return this.#i.getUserId();
|
|
701
744
|
}
|
|
702
745
|
getExternalId(e, t = "") {
|
|
703
|
-
return this.#
|
|
746
|
+
return this.#i.getExternalId(e, t);
|
|
704
747
|
}
|
|
705
748
|
getUserUuid() {
|
|
706
|
-
return this.#
|
|
749
|
+
return this.#i.getUserUuid();
|
|
707
750
|
}
|
|
708
751
|
getUserSDRN() {
|
|
709
|
-
return this.#
|
|
752
|
+
return this.#i.getUserSDRN();
|
|
710
753
|
}
|
|
711
754
|
getUserContextData() {
|
|
712
|
-
return this.#
|
|
755
|
+
return this.#i.getUserContextData();
|
|
713
756
|
}
|
|
714
757
|
getSpId() {
|
|
715
|
-
return this.#
|
|
758
|
+
return this.#i.getSpId();
|
|
716
759
|
}
|
|
717
760
|
login(e) {
|
|
718
|
-
return this.#
|
|
761
|
+
return this.#i.login(e);
|
|
719
762
|
}
|
|
720
763
|
logout(e) {
|
|
721
|
-
this.#
|
|
764
|
+
this.#i.logout(e);
|
|
722
765
|
}
|
|
723
766
|
loginUrl(e) {
|
|
724
|
-
return this.#
|
|
767
|
+
return this.#i.loginUrl(e);
|
|
725
768
|
}
|
|
726
769
|
logoutUrl(e) {
|
|
727
|
-
return this.#
|
|
770
|
+
return this.#i.logoutUrl(e);
|
|
728
771
|
}
|
|
729
772
|
accountUrl(e) {
|
|
730
|
-
return this.#
|
|
773
|
+
return this.#i.accountUrl(e);
|
|
731
774
|
}
|
|
732
775
|
showSimplifiedLoginWidget(e, t) {
|
|
733
|
-
return this.#
|
|
776
|
+
return this.#i.showSimplifiedLoginWidget(e, t);
|
|
734
777
|
}
|
|
735
778
|
setSessionCachingEnabled(e) {
|
|
736
|
-
this.#
|
|
779
|
+
this.#i.setSessionCachingEnabled(e);
|
|
737
780
|
}
|
|
738
781
|
clearCachedUserSession() {
|
|
739
|
-
this.#
|
|
782
|
+
this.#i.clearCachedUserSession();
|
|
740
783
|
}
|
|
741
|
-
async hasAccess(e = this.#
|
|
742
|
-
if (!e) throw new
|
|
784
|
+
async hasAccess(e = this.#r) {
|
|
785
|
+
if (!e) throw new t("hasAccess requires productIds or defaultProductIds in the Account config");
|
|
743
786
|
if (e.length === 0) return null;
|
|
744
|
-
let
|
|
745
|
-
return this.#
|
|
787
|
+
let n = await this.#i.getUserId();
|
|
788
|
+
return this.#a.hasAccess(e, n);
|
|
746
789
|
}
|
|
747
790
|
clearCachedAccessResult(e, t) {
|
|
748
|
-
this.#
|
|
791
|
+
this.#a.clearCachedAccessResult(e, t);
|
|
749
792
|
}
|
|
750
793
|
on(e, t) {
|
|
751
|
-
return this.#
|
|
794
|
+
return this.#i.addEventListener(e, t), this;
|
|
752
795
|
}
|
|
753
796
|
off(e, t) {
|
|
754
|
-
return this.#
|
|
797
|
+
return this.#i.removeEventListener(e, t), this;
|
|
755
798
|
}
|
|
756
799
|
}, Z = "schAccount:ready", Q = 4e3, $, ie = () => /* @__PURE__ */ Error("Schibsted Account SDK is not available in this browser context"), ae = () => /* @__PURE__ */ Error(`Schibsted Account SDK was not initialized within ${Q} ms`);
|
|
757
800
|
function oe(e) {
|
|
758
801
|
return new X(e);
|
|
759
802
|
}
|
|
760
803
|
function se() {
|
|
761
|
-
let e =
|
|
804
|
+
let e = n();
|
|
762
805
|
if (!e) {
|
|
763
806
|
let e = ie();
|
|
764
807
|
return console.error(e.message), Promise.reject(e);
|
|
@@ -777,6 +820,6 @@ function se() {
|
|
|
777
820
|
}), $);
|
|
778
821
|
}
|
|
779
822
|
//#endregion
|
|
780
|
-
export { X as Account,
|
|
823
|
+
export { X as Account, t as SDKError, oe as createAccountSdk, se as getAccountSdk, j as isConnectedSessionResponse, P as isConnectedSessionWithUserIdResponse, M as isSessionFailureResponse, A as isSessionSuccessResponse };
|
|
781
824
|
|
|
782
825
|
//# sourceMappingURL=index.js.map
|