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