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