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