@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/dist/index.js CHANGED
@@ -1,38 +1,9 @@
1
- //#region \0rolldown/runtime.js
2
- var e = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t.exports), t = (e, t, n) => {
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
- ], i = class extends Error {
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 e = `${this.name}: ${this.message}`, t = Object.keys(this).filter((e) => e !== "name" && r.includes(typeof this[e])).map((e) => ` ${e}: ${this[e]}`).join("\n");
44
- return t ? `${e}\n${t}` : e;
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 a(e) {
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 o = class {
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
- }, s = class {
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
- }, c = 2 ** 31 - 1, l = class {
51
+ }, a = 2 ** 31 - 1, o = class {
81
52
  cache;
82
53
  type;
83
54
  constructor(e) {
84
- e && a(e) ? (this.cache = new o(e()), this.type = "WebStorage") : (this.cache = new s(), this.type = "ObjectLiteralStorage");
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 t(e) {
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 n = t(this.cache.get(e));
97
- return n && Number.isInteger(n.expiresOn) && n.expiresOn > Date.now() ? n.value : (this.delete(e), null);
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 i(String(e));
70
+ throw new t(String(e));
100
71
  }
101
72
  }
102
- set(e, t, n = 0) {
103
- if (!(n <= 0)) {
104
- n = Math.min(c, n);
73
+ set(e, n, r = 0) {
74
+ if (!(r <= 0)) {
75
+ r = Math.min(a, r);
105
76
  try {
106
- let r = Math.floor(Date.now() + n);
77
+ let t = Math.floor(Date.now() + r);
107
78
  this.cache.set(e, JSON.stringify({
108
- expiresOn: r,
109
- value: t
110
- })), setTimeout(() => this.delete(e), n);
79
+ expiresOn: t,
80
+ value: n
81
+ })), setTimeout(() => this.delete(e), r);
111
82
  } catch (e) {
112
- throw new i(String(e));
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 i(String(e));
91
+ throw new t(String(e));
121
92
  }
122
93
  }
123
- }, u = {
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
- }, d = u.ENDPOINTS, f = u.NAMESPACE;
133
+ }, c = s.ENDPOINTS, l = s.NAMESPACE;
163
134
  //#endregion
164
135
  //#region src/validate.ts
165
- function p(e, t = "Assertion failed") {
166
- if (!e) throw new i(t);
136
+ function u(e, n = "Assertion failed") {
137
+ if (!e) throw new t(n);
167
138
  }
168
- function m(e) {
139
+ function d(e) {
169
140
  return typeof e == "string";
170
141
  }
171
- function h(e) {
142
+ function f(e) {
172
143
  return typeof e == "string" && e.length > 0;
173
144
  }
174
- function g(e) {
145
+ function p(e) {
175
146
  return typeof e == "object" && !!e;
176
147
  }
177
- function _(e) {
178
- return g(e) && Object.keys(e).length > 0;
148
+ function m(e) {
149
+ return p(e) && Object.keys(e).length > 0;
179
150
  }
180
- function v(e, ...t) {
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 y(e) {
159
+ function g(e) {
189
160
  return typeof e == "function";
190
161
  }
191
- function b(e, t, n = !1) {
192
- return m(e) && Array.isArray(t) ? n ? t.indexOf(e) !== -1 : t.some((t) => m(t) && e.toUpperCase() === t.toUpperCase()) : !1;
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 x(...e) {
197
- let t = {};
198
- if (!(e && e.length)) throw new i("No objects to clone");
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(g(e)), _(e) && Object.entries(e).forEach(([e, n]) => {
201
- n !== void 0 && (t[e] = g(n) ? S(n) : n);
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
- }), t;
174
+ }), n;
204
175
  }
205
- function S(e) {
206
- return p(typeof e == "object", `obj should be an object (even null) but it is ${e}`), JSON.parse(JSON.stringify(e)) || e;
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(g(e), `Object must be an object but it is '${e}'`), Object.keys(e).map((t) => `${t}=${e[t]}`).join(",");
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 ne(e, t, n = "", r = {}) {
222
- p(g(e), `window was supposed to be an object but it is ${e}`), p(g(e.screen), "window should be a valid Window object but it lacks a 'screen' property"), p(y(e.open), "window should be a valid Window object but it lacks an 'open' function"), p(v(t), "Invalid URL for popup");
223
- let { height: i, width: a } = e.screen, o = x(te, r), { width: s, height: c } = 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 C(e, t) {
231
- return p(h(e), `"url" param must be a non empty string: ${typeof e}`), _(t) && v(t[e]) ? t[e] : (p(v(e, "hostname"), `Bad URL given: '${e}'`), e);
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 w = (e) => e.map((e) => g(e) ? JSON.stringify(e, null, 2) : e).join(" "), T = (e, ...t) => {
236
- e && e(w(t));
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 E(e) {
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 re = () => window.fetch && window.fetch.bind(window), ie = () => {
251
- throw new i("fetch is not available in this environment");
252
- }, D = class e {
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 = re() ?? ie, log: r, defaultParams: i = {} }) {
258
- p(g(i), "defaultParams should be a non-null object");
259
- let a = C(e, t ?? {}), o = a.endsWith("/") ? a : `${a}/`;
260
- this.url = new URL(o), this.defaultParams = i, r && (p(y(r), `log must be a function but it is ${r}`), this.log = r), this.fetch = n;
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: t, headers: n, pathname: r, data: a = {}, useDefaultParams: o = !0, fetchOptions: s = {
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
- p(h(t), `Method must be a non empty string but it is "${t}"`), p(h(r), `Pathname must be string but it is "${r}"`), p(g(a), "data must be a non-null object"), s.headers = g(n) ? n : {};
268
- let l = this.makeUrl(r, a, o);
269
- T(this.log, "Request:", t.toUpperCase(), l), T(this.log, "Request Headers:", s.headers), T(this.log, "Request Body:", s.body);
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 (T(this.log, "Response Code:", e.status, e.statusText), !e.ok) throw new i(e.statusText, { code: e.status });
273
- let t = await e.json();
274
- return T(this.log, "Response Parsed:", t), c ? c(t) : t;
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 n = m(e) ? e : "Unknown RESTClient error";
277
- g(e) && m(e.message) && (n = e.message);
278
- let r = g(e) ? e : void 0;
279
- throw new i(`Failed to '${t}' '${l}': '${n}'`, r);
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 ? x(n, e) : x(e);
300
- return Object.keys(r).filter((e) => r[e] !== "").map((e) => `${E(e)}=${E(String(r[e]))}`).join("&");
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
- }, O = (e) => Object.hasOwn(f, e), k = (e, t) => (p(h(t), "clientId parameter is required"), p(O(e), `env parameter is invalid: ${e}`), `sdrn:${f[e]}:client:${t}`), A = ({ serverUrl: e, log: t, defaultParams: n }) => new D({
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 g(e) && typeof e.result == "boolean";
287
+ return p(e) && !!e.error;
311
288
  }
312
289
  function M(e) {
313
- return j(e) && e.result === !0;
290
+ return p(e) && Object.keys(e).length === 1 && d(e.redirectURL);
314
291
  }
315
292
  function N(e) {
316
- return g(e) && !!e.error;
293
+ return A(e) && (typeof e.userId == "number" || typeof e.userId == "string");
317
294
  }
318
295
  function P(e) {
319
- return g(e) && Object.keys(e).length === 1 && m(e.redirectURL);
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 L(e) {
330
- (!e.SPiD || typeof e.SPiD != "object") && (e.SPiD = {}), (!e.SPiD.Talk || typeof e.SPiD.Talk != "object") && (e.SPiD.Talk = {}), y(e.SPiD.Talk.response) || (e.SPiD.Talk.response = (t, n) => e[t](n));
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 R = (e) => typeof e.openSimplifiedLoginWidget == "function", z = "6.0.0-alpha.4", B = "hasSession-cache", V = "sessionCallBlocked-cache", H = 1e3 * 60 * 5, U = "tab-id-cache", W = Math.floor(Math.random() * 1e5), G = 1e3 * 60 * 60 * 24 * 30, K = () => window, q = class extends n.TinyEmitter {
335
- _sessionInitiatedSent;
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
- _sessionDomain;
345
- _enableSessionCaching;
346
- _session;
347
- _spid;
348
- _oauthService;
349
- _bffService;
350
- _sessionService;
351
- _globalSessionService;
352
- _usedSessionServiceGetSessionEndpoint;
353
- _hasSessionInProgress;
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: n, sessionDomain: r, env: i = "PRE", log: a, window: o = K(), callbackBeforeRedirect: s = () => {} }) {
359
- super(), p(h(e), "clientId parameter is required"), p(g(o), "The reference to window is missing"), p(!n || v(n), "redirectUri parameter is invalid"), p(h(r) && v(r), "sessionDomain parameter is not a valid URL"), p(m(i), `env parameter is invalid: ${i}`), L(o), this._sessionInitiatedSent = !1, this.window = o, this.clientId = e, this.sessionStorageCache = new l(() => this.window && this.window.sessionStorage), this.localStorageCache = new l(() => this.window && this.window.localStorage), this.redirectUri = n, this.env = i, this.log = a, this.callbackBeforeRedirect = s, this._sessionDomain = r, this._enableSessionCaching = !0, this._session = {};
360
- let c = {
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
- }, u = k(this.env, this.clientId);
364
- this._sessionService = A({
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
- client_sdrn: u,
369
- redirect_uri: this.redirectUri,
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: c
376
- }), this._bffService = A({
377
- serverUrl: C(i, d.BFF),
341
+ defaultParams: l
342
+ }), this.bffService = O({
343
+ serverUrl: x(r, c.BFF),
378
344
  log: this.log,
379
- defaultParams: c
380
- }), this._oauthService = A({
381
- serverUrl: C(i, d.SPiD),
345
+ defaultParams: l
346
+ }), this.sessionService = O({
347
+ serverUrl: n,
382
348
  log: this.log,
383
- defaultParams: c
384
- }), this._globalSessionService = A({
385
- serverUrl: C(i, d.SESSION_SERVICE),
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: u,
389
- sdk_version: z
358
+ client_sdrn: m,
359
+ sdk_version: L
390
360
  }
391
- }), this._unblockSessionCall(), t(o, "schIdentity", 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._enableSessionCaching) {
395
- let e = this.sessionStorageCache.get(U);
396
- return typeof e == "number" ? e : (this.sessionStorageCache.set(U, W, G), W);
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(V);
376
+ return !!this.localStorageCache.get(z);
401
377
  }
402
378
  _blockSessionCall() {
403
- this.localStorageCache.set(V, !0, H);
379
+ this.localStorageCache.set(z, !0, B);
404
380
  }
405
381
  _unblockSessionCall() {
406
- this.localStorageCache.delete(V);
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 i("VarnishCookieOptions must be an object");
417
- let { expiresIn: t = 0, domain: n } = e;
418
- p(Number.isInteger(t), "'expiresIn' must be an integer"), p(t >= 0, "'expiresIn' cannot be negative"), this.setVarnishCookie = !0, this.varnishExpiresIn = t, this.varnishCookieDomain = n;
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 || !j(e)) return;
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._session && j(this._session) && typeof this._session.baseDomain == "string" ? this._session.baseDomain : this.window.location.hostname, t = this.varnishCookieDomain || e || "";
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 = I(this._session);
456
- return Promise.resolve(P(e) ? {} : e);
416
+ let e = P(this.session);
417
+ return Promise.resolve(M(e) ? {} : e);
457
418
  }
458
- if (this._hasSessionInProgress) return this._hasSessionInProgress;
419
+ if (this.hasSessionInProgress) return this.hasSessionInProgress;
459
420
  let e = (e) => {
460
- if (N(e)) throw new i("HasSession failed", g(e.error) ? e.error : { description: String(e.error) });
461
- return this._maybeSetVarnishCookie(e), this._emitSessionEvent(this._session, e), this._session = e, e;
462
- }, t = () => {
463
- let e = this.sessionStorageCache.get(B);
464
- return e ? I(e) : null;
465
- }, n = async () => {
466
- if (this._enableSessionCaching) {
467
- let n = t();
468
- if (n) return P(n) ? {} : e(n);
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 n = null;
431
+ let t = null;
471
432
  try {
472
- n = await this._sessionService.get(this._usedSessionServiceGetSessionEndpoint, { tabId: this._getTabId() }, I);
433
+ t = await this.sessionService.get(this.usedSessionServiceGetSessionEndpoint, { tabId: this._getTabId() }, P);
473
434
  } catch (e) {
474
- let t = g(e) ? e : void 0;
475
- if (t?.code === 400 && this._enableSessionCaching) {
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(B, { error: e }, n);
478
- } else t && typeof t.code == "number" && t.code >= 500 && t.code < 600 && this._enableSessionCaching && this.sessionStorageCache.set(B, { error: e }, 30 * 1e3);
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 (n) {
482
- if (P(n)) return this._blockSessionCall(), await this.callbackBeforeRedirect(), this._sessionService.makeUrl(n.redirectURL, { tabId: this._getTabId() });
483
- if (this._enableSessionCaching) {
484
- let e = 1e3 * (j(n) && n.expiresIn || 300);
485
- this.sessionStorageCache.set(B, n, e);
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(n ?? {});
449
+ return e(t ?? {});
489
450
  };
490
- return this._hasSessionInProgress = n().then((e) => (this._hasSessionInProgress = !1, typeof e == "string" && (this.window.location.href = e), e), (e) => {
491
- throw this.emit("error", e), this._hasSessionInProgress = !1, new i("HasSession failed", e);
492
- }), this._hasSessionInProgress;
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 j(await this.hasSession());
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(B);
466
+ this.sessionStorageCache.delete(R);
503
467
  }
504
468
  async isConnected() {
505
469
  try {
506
- return M(await this.hasSession());
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 (!M(e)) throw new i("The user is not connected to this merchant");
514
- return S(e);
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 (F(e)) return String(e.userId);
519
- throw new i("The user is not connected to this merchant");
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 (j(e) && e.sdrn) return e.sdrn;
531
- throw new i("Failed to get SDRN from user session");
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 (j(e) && e.uuid && e.result) return e.uuid;
536
- throw new i("The user is not connected to this merchant");
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._globalSessionService.get("user-context", void 0, (e) => g(e) && m(e.identifier) ? {
497
+ return await this.globalSessionService.get("user-context", void 0, (e) => p(e) && d(e.identifier) ? {
541
498
  identifier: e.identifier,
542
- display_text: m(e.display_text) ? e.display_text : "",
543
- client_name: m(e.client_name) ? e.client_name : "",
544
- provider_id: m(e.provider_id) ? e.provider_id : void 0
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(B);
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 = ne(this.window, h, "Schibsted account", {
525
+ return i && (this.popup = b(this.window, h, "Schibsted account", {
569
526
  width: 360,
570
527
  height: 570
571
- }), this.popup) ? this.popup : (this.window.location.href = h, null);
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 (j(e)) return e.sp_id || null;
577
- let t = g(e) && "sp_id" in e ? e.sp_id : void 0;
578
- return m(t) ? t : null;
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(B), this._maybeClearVarnishCookie(), this.emit("logout"), this.window.location.href = this.logoutUrl(e);
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: u = "select_account", xDomainId: d = "", xEnvironmentId: f = "", originCampaign: m = "" }) {
587
- return p(!t || b(t, ["", "otp-email"], !0) || t.split(" ").every((e) => b(e, [
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}`), p(v(r), `loginUrl(): redirectUri must be a valid url but is ${r}`), p(h(e), `the state parameter should be a non empty string but it is ${e}`), this._oauthService.makeUrl("oauth/authorize", {
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 ? "" : u,
609
- x_domain_id: d,
610
- x_env_id: f,
611
- utm_campaign: m
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
- p(v(e), "logoutUrl(): redirectUri is invalid");
580
+ u(h(e), "logoutUrl(): redirectUri is invalid");
616
581
  let t = { redirect_uri: e };
617
- return this._sessionService.makeUrl("logout", t);
582
+ return this.sessionService.makeUrl("logout", t);
618
583
  }
619
584
  accountUrl(e = this.redirectUri) {
620
- return this._spid.makeUrl("profile-pages", {
585
+ return this.spid.makeUrl("profile-pages", {
621
586
  response_type: "code",
622
587
  redirect_uri: e
623
588
  });
624
589
  }
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
- 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((r, s) => {
642
- if (!n?.display_text || !n.identifier) {
643
- s(new i("Missing user data"));
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: n.display_text,
606
+ displayText: r.display_text,
648
607
  env: this.env,
649
- clientName: n.client_name || "",
608
+ clientName: r.client_name || "",
650
609
  clientId: this.clientId,
651
- providerId: n.provider_id,
610
+ providerId: r.provider_id,
652
611
  windowWidth: () => window.innerWidth,
653
612
  windowOnResize: (e) => {
654
613
  window.onresize = e;
655
614
  }
656
615
  };
657
- t && t.locale && (c.locale = t.locale);
616
+ n && n.locale && (c.locale = n.locale);
658
617
  let l = async () => {
659
- this.login(Object.assign(await o(e), { loginHint: n.identifier }));
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: n.identifier,
621
+ loginHint: r.identifier,
663
622
  prompt: "login"
664
623
  }));
665
624
  }, d = () => {
666
- this.emit("simplifiedLoginOpened");
625
+ this.eventTarget.dispatchEvent(new Event("simplifiedLoginOpened"));
667
626
  }, f = () => {
668
- this.emit("simplifiedLoginCancelled");
627
+ this.eventTarget.dispatchEvent(new Event("simplifiedLoginCancelled"));
669
628
  };
670
- if (R(window)) return window.openSimplifiedLoginWidget(c, l, u, d, f), r(!0);
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 (!R(window)) {
674
- s(new i("Error when loading simplified login widget content"));
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), r(!0);
636
+ window.openSimplifiedLoginWidget(c, l, u, d, f), i(!0);
678
637
  }, p.onerror = () => {
679
- s(new i("Error when loading simplified login widget content"));
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 J(e) {
687
- if (!g(e)) throw new i("Invalid hasAccess response");
688
- let { entitled: t, ttl: n, allowedFeatures: r, userId: a, uuid: o, sig: s } = e;
689
- if (typeof t != "boolean" || typeof n != "number" || !Array.isArray(r) || typeof a != "number" && typeof a != "string" || !m(o) || !m(s)) throw new i("Invalid hasAccess response");
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: t,
692
- ttl: n,
693
- allowedFeatures: r.filter(m),
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 ae = () => window, oe = class extends n.TinyEmitter {
660
+ var q = () => window, J = class {
702
661
  cache;
703
- clientId;
704
- env;
705
- redirectUri;
706
- _spid;
707
- _sessionService;
662
+ sessionService;
708
663
  pendingHasAccessRequests;
709
- constructor({ clientId: e, redirectUri: n, env: r = "PRE", sessionDomain: i, window: a = ae() }) {
710
- super(), L(a), p(h(e), "clientId parameter is required"), p(m(r), `env parameter is invalid: ${r}`), this.cache = new l(() => a && a.sessionStorage), this.clientId = e, this.env = r, this.redirectUri = n, this.pendingHasAccessRequests = {}, this._spid = A({
711
- serverUrl: C(r, d.SPiD),
712
- defaultParams: {
713
- client_id: this.clientId,
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: k(this.env, this.clientId),
720
- redirect_uri: this.redirectUri,
721
- sdk_version: z
670
+ client_sdrn: a,
671
+ redirect_uri: t,
672
+ sdk_version: L
722
673
  }
723
- })), t(a, "schMonetization", this);
674
+ }));
724
675
  }
725
- async hasAccess(e, t) {
726
- if (!this._sessionService) throw new i("hasAccess can only be called if 'sessionDomain' is configured");
727
- if (!t) throw new i("'userId' must be specified");
728
- if (!Array.isArray(e)) throw new i("'productIds' must be an array");
729
- let n = [...e].sort(), r = this._accessCacheKey(n, t), a = this.cache.get(r);
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[r] || (this.pendingHasAccessRequests[r] = this._sessionService.get(`/hasAccess/${n.join(",")}`, void 0, J));
732
- let e = this.pendingHasAccessRequests[r];
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(r, a, t * 1e3);
687
+ this.cache.set(i, a, t * 1e3);
737
688
  } finally {
738
- this.pendingHasAccessRequests[r] === e && delete this.pendingHasAccessRequests[r];
689
+ this.pendingHasAccessRequests[i] === e && delete this.pendingHasAccessRequests[i];
739
690
  }
740
691
  }
741
- return a.entitled ? (this.emit("hasAccess", {
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._accessCacheKey(e, t));
695
+ this.cache.delete(this.accessCacheKey(e, t));
748
696
  }
749
- _accessCacheKey(e, t) {
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 i("Schibsted Account SDK is not available in this browser context");
764
- if (n.schAccount) throw new i("Schibsted Account SDK has already been initialized");
765
- let { log: r, callbackBeforeRedirect: a, varnish: o } = e, s = {
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 q({
773
- ...s,
714
+ if (this.#e = new G({
715
+ ...o,
774
716
  log: r,
775
- callbackBeforeRedirect: a
776
- }), o) {
777
- if (typeof o != "object" || Array.isArray(o)) throw new i("Account varnish config must be an object");
778
- this.#e.enableVarnishCookie(o);
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 oe(s), t(n, "schAccount", this);
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, n) {
831
- return e === "hasAccess" ? this.#t.on(e, t, n) : this.#e.on(e, t, n), this;
778
+ on(e, t) {
779
+ return this.#e.addEventListener(e, t), this;
832
780
  }
833
781
  off(e, t) {
834
- return e === "hasAccess" ? this.#t.off(e, t) : this.#e.off(e, t), this;
782
+ return this.#e.removeEventListener(e, t), this;
835
783
  }
836
- }, Z = "schAccount:ready", Q = 4e3, $, se = () => /* @__PURE__ */ Error("Schibsted Account SDK is not available in this browser context"), ce = () => /* @__PURE__ */ Error(`Schibsted Account SDK was not initialized within ${Q} ms`);
837
- function le(e) {
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 ue() {
788
+ function se() {
841
789
  let e = Y();
842
790
  if (!e) {
843
- let e = se();
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 = ce();
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, i as SDKError, le as createAccountSdk, ue as getAccountSdk };
808
+ export { X as Account, t as SDKError, oe as createAccountSdk, se as getAccountSdk };
861
809
 
862
810
  //# sourceMappingURL=index.js.map