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

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