@schibsted/account-sdk-browser 6.0.0-alpha.11 → 6.0.0-alpha.12

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