@schibsted/account-sdk-browser 6.0.0-alpha.13 → 6.0.0-alpha.15

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
@@ -115,23 +115,80 @@ var i = class {
115
115
  }
116
116
  }, l = c.ENDPOINTS, u = c.NAMESPACE;
117
117
  //#endregion
118
+ //#region node_modules/@schibsted/consent-url-utils/lib/esm/consent-manager.js
119
+ function d(e = window) {
120
+ let t = e._tcf_ || e._scc_;
121
+ return t ? {
122
+ advertising: t.getPermissionSync("CMP:advertising"),
123
+ analytics: t.getPermissionSync("CMP:analytics"),
124
+ marketing: t.getPermissionSync("CMP:marketing"),
125
+ personalisation: t.getPermissionSync("CMP:personalisation")
126
+ } : (console.warn("Consent-query-utils: getConsentsSync called but no consent manager found on window"), null);
127
+ }
128
+ //#endregion
129
+ //#region node_modules/@schibsted/consent-url-utils/lib/esm/serializeConsents.js
130
+ var f = "rejected", p = "v1";
131
+ function m(e) {
132
+ return Object.values(e).some((e) => e !== null);
133
+ }
134
+ function h(e) {
135
+ let t = new URLSearchParams();
136
+ if (!e || !m(e)) return t;
137
+ let n = [];
138
+ for (let [t, r] of Object.entries(e)) r === "1" && n.push(t);
139
+ n.length === 0 && n.push(f);
140
+ let r = [...new Set(n)].sort();
141
+ return t.set("consents", r.join(",")), t.set("consent_version", p), t;
142
+ }
143
+ //#endregion
144
+ //#region src/consents.ts
145
+ var g = ["click", "auxclick"];
146
+ function ee(e) {
147
+ return !e._tcf_ && !e._scc_ ? null : h(d(e));
148
+ }
149
+ function _(e, t) {
150
+ let n = new URL(e);
151
+ return t.forEach((e, t) => {
152
+ n.searchParams.delete(t);
153
+ }), t.forEach((e, t) => {
154
+ n.searchParams.append(t, e);
155
+ }), n.href;
156
+ }
157
+ function te(e) {
158
+ return (typeof e.composedPath == "function" ? e.composedPath() : [e.target]).find((e) => {
159
+ let t = e;
160
+ return !!t && t.tagName === "A" && typeof t.href == "string";
161
+ });
162
+ }
163
+ function v(e, { isLoginUrl: t, getConsentParams: n }) {
164
+ let r = (e) => {
165
+ let r = te(e);
166
+ if (!r || !t(r.href)) return;
167
+ let i = n();
168
+ i.toString() !== "" && (r.href = _(r.href, i));
169
+ };
170
+ g.forEach((t) => {
171
+ e.addEventListener(t, r, !0);
172
+ });
173
+ }
174
+ //#endregion
118
175
  //#region src/validate.ts
119
- function d(e, n = "Assertion failed") {
176
+ function y(e, n = "Assertion failed") {
120
177
  if (!e) throw new t(n);
121
178
  }
122
- function f(e) {
179
+ function b(e) {
123
180
  return typeof e == "string";
124
181
  }
125
- function p(e) {
182
+ function x(e) {
126
183
  return typeof e == "string" && e.length > 0;
127
184
  }
128
- function m(e) {
185
+ function S(e) {
129
186
  return typeof e == "object" && !!e;
130
187
  }
131
- function h(e) {
132
- return m(e) && Object.keys(e).length > 0;
188
+ function C(e) {
189
+ return S(e) && Object.keys(e).length > 0;
133
190
  }
134
- function g(e, ...t) {
191
+ function w(e, ...t) {
135
192
  try {
136
193
  let n = new URL(e);
137
194
  return t.every((e) => n[e]);
@@ -139,32 +196,32 @@ function g(e, ...t) {
139
196
  return !1;
140
197
  }
141
198
  }
142
- function _(e) {
199
+ function T(e) {
143
200
  return typeof e == "function";
144
201
  }
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;
202
+ function E(e, t, n = !1) {
203
+ return b(e) && Array.isArray(t) ? n ? t.indexOf(e) !== -1 : t.some((t) => b(t) && e.toUpperCase() === t.toUpperCase()) : !1;
147
204
  }
148
205
  //#endregion
149
206
  //#region src/object.ts
150
- function y(...e) {
207
+ function D(...e) {
151
208
  let n = {};
152
209
  if (!(e && e.length)) throw new t("No objects to clone");
153
210
  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);
211
+ y(S(e)), C(e) && Object.entries(e).forEach(([e, t]) => {
212
+ t !== void 0 && (n[e] = S(t) ? O(t) : t);
156
213
  });
157
214
  }), n;
158
215
  }
159
- function b(e) {
160
- return d(typeof e == "object", `obj should be an object (even null) but it is ${e}`), JSON.parse(JSON.stringify(e)) || e;
216
+ function O(e) {
217
+ return y(typeof e == "object", `obj should be an object (even null) but it is ${e}`), JSON.parse(JSON.stringify(e)) || e;
161
218
  }
162
219
  //#endregion
163
220
  //#region src/popup.ts
164
- function ee(e) {
165
- return d(m(e), `Object must be an object but it is '${e}'`), Object.keys(e).map((t) => `${t}=${e[t]}`).join(",");
221
+ function ne(e) {
222
+ return y(S(e), `Object must be an object but it is '${e}'`), Object.keys(e).map((t) => `${t}=${e[t]}`).join(",");
166
223
  }
167
- var te = {
224
+ var re = {
168
225
  scrollbars: "yes",
169
226
  location: "yes",
170
227
  status: "no",
@@ -172,24 +229,24 @@ var te = {
172
229
  toolbar: "no",
173
230
  resizable: "yes"
174
231
  };
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;
232
+ function k(e, t, n = "", r = {}) {
233
+ y(S(e), `window was supposed to be an object but it is ${e}`), y(S(e.screen), "window should be a valid Window object but it lacks a 'screen' property"), y(T(e.open), "window should be a valid Window object but it lacks an 'open' function"), y(w(t), "Invalid URL for popup");
234
+ let { height: i, width: a } = e.screen, o = D(re, r), { width: s, height: c } = o;
178
235
  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);
236
+ let l = ne(o);
180
237
  return e.open(t, n, l);
181
238
  }
182
239
  //#endregion
183
240
  //#region src/url.ts
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);
241
+ function A(e, t) {
242
+ return y(x(e), `"url" param must be a non empty string: ${typeof e}`), C(t) && w(t[e]) ? t[e] : (y(w(e, "hostname"), `Bad URL given: '${e}'`), e);
186
243
  }
187
244
  //#endregion
188
245
  //#region src/rest-client.ts
189
- var re = (e) => e.map((e) => m(e) ? JSON.stringify(e, null, 2) : e).join(" "), S = (e, ...t) => {
190
- e && e(re(t));
246
+ var ie = (e) => e.map((e) => S(e) ? JSON.stringify(e, null, 2) : e).join(" "), j = (e, ...t) => {
247
+ e && e(ie(t));
191
248
  };
192
- function C(e) {
249
+ function M(e) {
193
250
  let t = {
194
251
  "!": "%21",
195
252
  "'": "%27",
@@ -201,35 +258,35 @@ function C(e) {
201
258
  };
202
259
  return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g, (e) => t[e]);
203
260
  }
204
- var w = () => window.fetch && window.fetch.bind(window), T = () => {
261
+ var ae = () => window.fetch && window.fetch.bind(window), N = () => {
205
262
  throw new t("fetch is not available in this environment");
206
- }, E = class e {
263
+ }, P = class e {
207
264
  url;
208
265
  defaultParams;
209
266
  log;
210
267
  fetch;
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;
268
+ constructor({ serverUrl: e = "PRE", envDic: t, fetch: n = ae() ?? N, log: r, defaultParams: i = {} }) {
269
+ y(S(i), "defaultParams should be a non-null object");
270
+ let a = A(e, t ?? {}), o = a.endsWith("/") ? a : `${a}/`;
271
+ this.url = new URL(o), this.defaultParams = i, r && (y(T(r), `log must be a function but it is ${r}`), this.log = r), this.fetch = n;
215
272
  }
216
273
  async go(e) {
217
274
  let { method: n, headers: r, pathname: i, data: a = {}, useDefaultParams: o = !0, fetchOptions: s = {
218
275
  method: e.method,
219
276
  credentials: "include"
220
277
  }, 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 : {};
278
+ y(x(n), `Method must be a non empty string but it is "${n}"`), y(x(i), `Pathname must be string but it is "${i}"`), y(S(a), "data must be a non-null object"), s.headers = S(r) ? r : {};
222
279
  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);
280
+ j(this.log, "Request:", n.toUpperCase(), l), j(this.log, "Request Headers:", s.headers), j(this.log, "Request Body:", s.body);
224
281
  try {
225
282
  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 });
283
+ if (j(this.log, "Response Code:", e.status, e.statusText), !e.ok) throw new t(e.statusText, { code: e.status });
227
284
  let n = await e.json();
228
- return S(this.log, "Response Parsed:", n), c ? c(n) : n;
285
+ return j(this.log, "Response Parsed:", n), c ? c(n) : n;
229
286
  } catch (e) {
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;
287
+ let r = b(e) ? e : "Unknown RESTClient error";
288
+ S(e) && b(e.message) && (r = e.message);
289
+ let i = S(e) ? e : void 0;
233
290
  throw new t(`Failed to '${n}' '${l}': '${r}'`, i);
234
291
  }
235
292
  }
@@ -250,42 +307,42 @@ var w = () => window.fetch && window.fetch.bind(window), T = () => {
250
307
  });
251
308
  }
252
309
  static search(e, t, n) {
253
- let r = t ? y(n, e) : y(e);
254
- return Object.keys(r).filter((e) => r[e] !== "").map((e) => `${C(e)}=${C(String(r[e]))}`).join("&");
310
+ let r = t ? D(n, e) : D(e);
311
+ return Object.keys(r).filter((e) => r[e] !== "").map((e) => `${M(e)}=${M(String(r[e]))}`).join("&");
255
312
  }
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({
313
+ }, oe = (e) => Object.hasOwn(u, e), F = (e, t) => (y(x(t), "clientId parameter is required"), y(oe(e), `env parameter is invalid: ${e}`), `sdrn:${u[e]}:client:${t}`), I = ({ serverUrl: e, log: t, defaultParams: n }) => new P({
257
314
  serverUrl: e,
258
315
  log: t,
259
316
  defaultParams: n
260
317
  });
261
318
  //#endregion
262
319
  //#region src/session-response.ts
263
- function A(e) {
264
- return m(e) && typeof e.result == "boolean";
320
+ function L(e) {
321
+ return S(e) && typeof e.result == "boolean";
265
322
  }
266
- function j(e) {
267
- return A(e) && e.result === !0;
323
+ function R(e) {
324
+ return L(e) && e.result === !0;
268
325
  }
269
- function M(e) {
270
- return m(e) && !!e.error;
326
+ function z(e) {
327
+ return S(e) && !!e.error;
271
328
  }
272
- function N(e) {
273
- return m(e) && Object.keys(e).length === 1 && f(e.redirectURL);
329
+ function B(e) {
330
+ return S(e) && Object.keys(e).length === 1 && b(e.redirectURL);
274
331
  }
275
- function P(e) {
276
- return j(e) && typeof e.userId == "number";
332
+ function V(e) {
333
+ return R(e) && typeof e.userId == "number";
277
334
  }
278
- function F(e) {
279
- return N(e) || M(e) || A(e) || m(e) ? e : {};
335
+ function H(e) {
336
+ return B(e) || z(e) || L(e) || S(e) ? e : {};
280
337
  }
281
338
  //#endregion
282
339
  //#region src/spid-talk.ts
283
- function I(e) {
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));
340
+ function U(e) {
341
+ (!e.SPiD || typeof e.SPiD != "object") && (e.SPiD = {}), (!e.SPiD.Talk || typeof e.SPiD.Talk != "object") && (e.SPiD.Talk = {}), T(e.SPiD.Talk.response) || (e.SPiD.Talk.response = (t, n) => e[t](n));
285
342
  }
286
343
  //#endregion
287
344
  //#region src/types/login.ts
288
- var L = (e) => typeof e.openSimplifiedLoginWidget == "function", R = "6.0.0-alpha.13", 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 {
345
+ var W = (e) => typeof e.openSimplifiedLoginWidget == "function", G = "6.0.0-alpha.15", K = "hasSession-cache", q = "sessionCallBlocked-cache", se = 1e3 * 60 * 5, J = "tab-id-cache", Y = Math.floor(Math.random() * 1e5), ce = 1e3 * 60 * 60 * 24 * 30, le = () => window, ue = class {
289
346
  eventTarget = new EventTarget();
290
347
  window;
291
348
  clientId;
@@ -293,6 +350,8 @@ var L = (e) => typeof e.openSimplifiedLoginWidget == "function", R = "6.0.0-alph
293
350
  env;
294
351
  log;
295
352
  callbackBeforeRedirect;
353
+ getConsents;
354
+ generateState;
296
355
  sessionStorageCache;
297
356
  localStorageCache;
298
357
  enableSessionCaching;
@@ -308,41 +367,48 @@ var L = (e) => typeof e.openSimplifiedLoginWidget == "function", R = "6.0.0-alph
308
367
  setVarnishCookie;
309
368
  varnishExpiresIn;
310
369
  varnishCookieDomain;
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 = {
370
+ constructor({ clientId: t, redirectUri: n, sessionDomain: r, env: i, log: a, window: o = le(), callbackBeforeRedirect: c = () => {}, getConsents: u = () => ee(o), generateState: d }) {
371
+ y(x(t), "clientId parameter is required"), y(S(o), "The reference to window is missing"), y(!n || w(n), "redirectUri parameter is invalid"), y(x(r) && w(r), "sessionDomain parameter is not a valid URL"), y(b(i), `env parameter is invalid: ${i}`), y(T(u), "getConsents parameter must be a function"), y(d === void 0 || T(d), "generateState parameter must be a function"), U(o), this.window = o, this.clientId = t, this.redirectUri = n, this.env = i, this.log = a, this.callbackBeforeRedirect = c, this.getConsents = u, this.generateState = d, 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 });
372
+ let f = {
314
373
  client_id: this.clientId,
315
374
  redirect_uri: this.redirectUri
316
- }, h = O(this.env, this.clientId);
317
- this.spid = k({
318
- serverUrl: x(i, l.SPiD),
375
+ }, p = F(this.env, this.clientId);
376
+ this.spid = I({
377
+ serverUrl: A(i, l.SPiD),
319
378
  log: this.log,
320
- defaultParams: u
321
- }), this.oauthService = k({
322
- serverUrl: x(i, l.SPiD),
379
+ defaultParams: f
380
+ }), this.oauthService = I({
381
+ serverUrl: A(i, l.SPiD),
323
382
  log: this.log,
324
- defaultParams: u
325
- }), this.bffService = k({
326
- serverUrl: x(i, l.BFF),
383
+ defaultParams: f
384
+ }), this.bffService = I({
385
+ serverUrl: A(i, l.BFF),
327
386
  log: this.log,
328
- defaultParams: u
329
- }), this.sessionService = k({
387
+ defaultParams: f
388
+ }), this.sessionService = I({
330
389
  serverUrl: r,
331
390
  log: this.log,
332
391
  defaultParams: {
333
- client_sdrn: h,
392
+ client_sdrn: p,
334
393
  redirect_uri: this.redirectUri,
335
- sdk_version: R
394
+ sdk_version: G
336
395
  }
337
- }), this.globalSessionService = k({
338
- serverUrl: x(i, l.SESSION_SERVICE),
396
+ }), this.globalSessionService = I({
397
+ serverUrl: A(i, l.SESSION_SERVICE),
339
398
  log: this.log,
340
399
  defaultParams: {
341
- client_sdrn: h,
342
- sdk_version: R
400
+ client_sdrn: p,
401
+ sdk_version: G
343
402
  }
344
403
  }), this.usedSessionServiceGetSessionEndpoint = this.sessionService.url.pathname && this.sessionService.url.pathname.length <= 1 ? "v2/session" : "session", this._unblockSessionCall();
345
404
  }
405
+ enableLoginLinkRefresh() {
406
+ let { document: e } = this.window;
407
+ e && T(e.addEventListener) && v(e, {
408
+ isLoginUrl: (e) => this.isLoginUrl(e),
409
+ getConsentParams: () => this.getConsentParams()
410
+ });
411
+ }
346
412
  addEventListener(e, t) {
347
413
  this.eventTarget.addEventListener(e, t);
348
414
  }
@@ -351,18 +417,18 @@ var L = (e) => typeof e.openSimplifiedLoginWidget == "function", R = "6.0.0-alph
351
417
  }
352
418
  _getTabId() {
353
419
  if (this.enableSessionCaching) {
354
- let e = this.sessionStorageCache.get(H);
355
- return typeof e == "number" ? e : (this.sessionStorageCache.set(H, U, W), U);
420
+ let e = this.sessionStorageCache.get(J);
421
+ return typeof e == "number" ? e : (this.sessionStorageCache.set(J, Y, ce), Y);
356
422
  }
357
423
  }
358
424
  _isSessionCallBlocked() {
359
- return !!this.localStorageCache.get(B);
425
+ return !!this.localStorageCache.get(q);
360
426
  }
361
427
  _blockSessionCall() {
362
- this.localStorageCache.set(B, !0, V);
428
+ this.localStorageCache.set(q, !0, se);
363
429
  }
364
430
  _unblockSessionCall() {
365
- this.localStorageCache.delete(B);
431
+ this.localStorageCache.delete(q);
366
432
  }
367
433
  _closePopup() {
368
434
  this.popup &&= (this.popup.closed || this.popup.close(), null);
@@ -370,10 +436,10 @@ var L = (e) => typeof e.openSimplifiedLoginWidget == "function", R = "6.0.0-alph
370
436
  enableVarnishCookie(e) {
371
437
  if (typeof e != "object") throw new t("VarnishCookieOptions must be an object");
372
438
  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;
439
+ y(Number.isInteger(n), "'expiresIn' must be an integer"), y(n >= 0, "'expiresIn' cannot be negative"), this.setVarnishCookie = !0, this.varnishExpiresIn = n, this.varnishCookieDomain = r;
374
440
  }
375
441
  _maybeSetVarnishCookie(e) {
376
- if (!this.setVarnishCookie || !A(e)) return;
442
+ if (!this.setVarnishCookie || !L(e)) return;
377
443
  let t = /* @__PURE__ */ new Date();
378
444
  if (this.varnishExpiresIn || typeof e.expiresIn == "number" && e.expiresIn > 0) {
379
445
  let n = this.varnishExpiresIn || e.expiresIn || 0;
@@ -391,42 +457,42 @@ var L = (e) => typeof e.openSimplifiedLoginWidget == "function", R = "6.0.0-alph
391
457
  this.setVarnishCookie && this._clearVarnishCookie();
392
458
  }
393
459
  _clearVarnishCookie() {
394
- let e = this.session && A(this.session) && typeof this.session.baseDomain == "string" ? this.session.baseDomain : this.window.location.hostname, t = this.varnishCookieDomain || e || "";
460
+ let e = this.session && L(this.session) && typeof this.session.baseDomain == "string" ? this.session.baseDomain : this.window.location.hostname, t = this.varnishCookieDomain || e || "";
395
461
  document.cookie = `SP_ID=nothing; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/; domain=.${t}`;
396
462
  }
397
463
  hasSession() {
398
464
  if (this._isSessionCallBlocked()) {
399
- let e = F(this.session);
400
- return Promise.resolve(N(e) ? {} : e);
465
+ let e = H(this.session);
466
+ return Promise.resolve(B(e) ? {} : e);
401
467
  }
402
468
  if (this.hasSessionInProgress) return this.hasSessionInProgress;
403
469
  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;
470
+ if (z(r)) throw new t("HasSession failed", S(r.error) ? r.error : { description: String(r.error) });
471
+ return this._maybeSetVarnishCookie(r), n = (L(this.session) && this.session.id) !== (L(r) && r.id), e.get(this)?.beforeUpdate?.(this.session, r), this.session = r, r;
406
472
  }, i = () => {
407
- let e = this.sessionStorageCache.get(z);
408
- return e ? F(e) : null;
473
+ let e = this.sessionStorageCache.get(K);
474
+ return e ? H(e) : null;
409
475
  }, a = async () => {
410
476
  if (this.enableSessionCaching) {
411
477
  let e = i();
412
- if (e) return N(e) ? {} : r(e);
478
+ if (e) return B(e) ? {} : r(e);
413
479
  }
414
480
  let e = null;
415
481
  try {
416
- e = await this.sessionService.get(this.usedSessionServiceGetSessionEndpoint, { tabId: this._getTabId() }, F);
482
+ e = await this.sessionService.get(this.usedSessionServiceGetSessionEndpoint, { tabId: this._getTabId() }, H);
417
483
  } catch (e) {
418
- let t = m(e) ? e : void 0;
484
+ let t = S(e) ? e : void 0;
419
485
  if (t?.code === 400 && this.enableSessionCaching) {
420
486
  let n = 1e3 * (typeof t.expiresIn == "number" ? t.expiresIn : 300);
421
- this.sessionStorageCache.set(z, { error: e }, n);
422
- } else t && typeof t.code == "number" && t.code >= 500 && t.code < 600 && this.enableSessionCaching && this.sessionStorageCache.set(z, { error: e }, 30 * 1e3);
487
+ this.sessionStorageCache.set(K, { error: e }, n);
488
+ } else t && typeof t.code == "number" && t.code >= 500 && t.code < 600 && this.enableSessionCaching && this.sessionStorageCache.set(K, { error: e }, 30 * 1e3);
423
489
  throw e;
424
490
  }
425
491
  if (e) {
426
- if (N(e)) return this._blockSessionCall(), await this.callbackBeforeRedirect(), this.sessionService.makeUrl(e.redirectURL, { tabId: this._getTabId() });
492
+ if (B(e)) return this._blockSessionCall(), await this.callbackBeforeRedirect(), this.sessionService.makeUrl(e.redirectURL, { tabId: this._getTabId() });
427
493
  if (this.enableSessionCaching) {
428
- let t = 1e3 * (A(e) && e.expiresIn || 300);
429
- this.sessionStorageCache.set(z, e, t);
494
+ let t = 1e3 * (L(e) && e.expiresIn || 300);
495
+ this.sessionStorageCache.set(K, e, t);
430
496
  }
431
497
  }
432
498
  return r(e ?? {});
@@ -437,7 +503,7 @@ var L = (e) => typeof e.openSimplifiedLoginWidget == "function", R = "6.0.0-alph
437
503
  }
438
504
  async isLoggedIn() {
439
505
  try {
440
- return A(await this.hasSession());
506
+ return L(await this.hasSession());
441
507
  } catch {
442
508
  return !1;
443
509
  }
@@ -446,27 +512,27 @@ var L = (e) => typeof e.openSimplifiedLoginWidget == "function", R = "6.0.0-alph
446
512
  this.enableSessionCaching = e;
447
513
  }
448
514
  clearCachedUserSession() {
449
- this.sessionStorageCache.delete(z);
515
+ this.sessionStorageCache.delete(K);
450
516
  }
451
517
  async isConnected() {
452
518
  try {
453
- return j(await this.hasSession());
519
+ return R(await this.hasSession());
454
520
  } catch {
455
521
  return !1;
456
522
  }
457
523
  }
458
524
  async getUser() {
459
525
  let e = await this.hasSession();
460
- if (!j(e)) throw new t("The user is not connected to this merchant");
461
- return b(e);
526
+ if (!R(e)) throw new t("The user is not connected to this merchant");
527
+ return O(e);
462
528
  }
463
529
  async getUserId() {
464
530
  let e = await this.hasSession();
465
- if (P(e)) return e.userId;
531
+ if (V(e)) return e.userId;
466
532
  throw new t("The user is not connected to this merchant");
467
533
  }
468
534
  async getExternalId(e, n = "") {
469
- let r = await this.hasSession(), i = A(r) ? r.pairId : void 0;
535
+ let r = await this.hasSession(), i = L(r) ? r.pairId : void 0;
470
536
  if (!i) throw new t("pairId missing in user session!");
471
537
  if (!e || e.length === 0) throw new t("externalParty cannot be empty");
472
538
  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);
@@ -474,28 +540,28 @@ var L = (e) => typeof e.openSimplifiedLoginWidget == "function", R = "6.0.0-alph
474
540
  }
475
541
  async getUserSDRN() {
476
542
  let e = await this.hasSession();
477
- if (A(e) && e.sdrn) return e.sdrn;
543
+ if (L(e) && e.sdrn) return e.sdrn;
478
544
  throw new t("Failed to get SDRN from user session");
479
545
  }
480
546
  async getUserUuid() {
481
547
  let e = await this.hasSession();
482
- if (A(e) && e.uuid && e.result) return e.uuid;
548
+ if (L(e) && e.uuid && e.result) return e.uuid;
483
549
  throw new t("The user is not connected to this merchant");
484
550
  }
485
551
  async getUserContextData() {
486
552
  try {
487
- return await this.globalSessionService.get("user-context", void 0, (e) => m(e) && f(e.identifier) ? {
553
+ return await this.globalSessionService.get("user-context", void 0, (e) => S(e) && b(e.identifier) ? {
488
554
  identifier: e.identifier,
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
555
+ display_text: b(e.display_text) ? e.display_text : "",
556
+ client_name: b(e.client_name) ? e.client_name : "",
557
+ provider_id: b(e.provider_id) ? e.provider_id : void 0
492
558
  } : null);
493
559
  } catch {
494
560
  return null;
495
561
  }
496
562
  }
497
563
  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 = "" }) {
498
- this._closePopup(), this.sessionStorageCache.delete(z);
564
+ this._closePopup(), this.sessionStorageCache.delete(K);
499
565
  let h = this.loginUrl({
500
566
  state: e,
501
567
  acrValues: t,
@@ -512,7 +578,7 @@ var L = (e) => typeof e.openSimplifiedLoginWidget == "function", R = "6.0.0-alph
512
578
  xEnvironmentId: p,
513
579
  originCampaign: m
514
580
  });
515
- return i && (this.popup = ne(this.window, h, "Schibsted account", {
581
+ return i && (this.popup = k(this.window, h, "Schibsted account", {
516
582
  width: 360,
517
583
  height: 570
518
584
  }), this.popup) ? (this.eventTarget.dispatchEvent(new CustomEvent("loginRequested", { detail: {
@@ -526,20 +592,20 @@ var L = (e) => typeof e.openSimplifiedLoginWidget == "function", R = "6.0.0-alph
526
592
  async getSpId() {
527
593
  try {
528
594
  let e = await this.hasSession();
529
- if (A(e)) return e.sp_id || null;
530
- let t = m(e) && "sp_id" in e ? e.sp_id : void 0;
531
- return f(t) ? t : null;
595
+ if (L(e)) return e.sp_id || null;
596
+ let t = S(e) && "sp_id" in e ? e.sp_id : void 0;
597
+ return b(t) ? t : null;
532
598
  } catch {
533
599
  return null;
534
600
  }
535
601
  }
536
602
  logout(e = this.redirectUri) {
537
- this.sessionStorageCache.delete(z), this._maybeClearVarnishCookie();
603
+ this.sessionStorageCache.delete(K), this._maybeClearVarnishCookie();
538
604
  let t = this.logoutUrl(e);
539
605
  this.eventTarget.dispatchEvent(new CustomEvent("logoutRequested", { detail: { url: t } })), this.window.location.href = t;
540
606
  }
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, [
607
+ loginUrl({ state: e = this.generateState?.(this.window), 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: p = "" }) {
608
+ return y(!t || E(t, ["", "otp-email"], !0) || t.split(" ").every((e) => E(e, [
543
609
  "password",
544
610
  "otp",
545
611
  "sms",
@@ -548,7 +614,7 @@ var L = (e) => typeof e.openSimplifiedLoginWidget == "function", R = "6.0.0-alph
548
614
  "eid-se",
549
615
  "eid-fi",
550
616
  "eid"
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", {
617
+ ], !0)), `The acrValues parameter is not acceptable: ${t}`), y(w(r), `loginUrl(): redirectUri must be a valid url but is ${r}`), y(x(e), `the state parameter should be a non empty string but it is ${e}`), _(this.oauthService.makeUrl("oauth/authorize", {
552
618
  response_type: "code",
553
619
  redirect_uri: r,
554
620
  scope: n,
@@ -561,13 +627,26 @@ var L = (e) => typeof e.openSimplifiedLoginWidget == "function", R = "6.0.0-alph
561
627
  locale: c,
562
628
  one_step_login: l || "",
563
629
  prompt: t ? "" : u,
564
- x_domain_id: f,
565
- x_env_id: m,
566
- utm_campaign: h
567
- });
630
+ x_domain_id: d,
631
+ x_env_id: f,
632
+ utm_campaign: p
633
+ }), this.getConsentParams());
634
+ }
635
+ getConsentParams() {
636
+ try {
637
+ let e = this.getConsents() || new URLSearchParams();
638
+ return y(e instanceof URLSearchParams, `getConsents must return URLSearchParams but it returned ${e}`), e;
639
+ } catch (e) {
640
+ return (this.log || console.warn)("Schibsted account SDK: could not read consents, logging in without them", e), new URLSearchParams();
641
+ }
642
+ }
643
+ isLoginUrl(e) {
644
+ if (!w(e)) return !1;
645
+ let t = new URL(e), n = new URL(this.oauthService.makeUrl("oauth/authorize", {}, !1));
646
+ return t.origin === n.origin && t.pathname === n.pathname && t.searchParams.get("client_id") === this.clientId;
568
647
  }
569
648
  logoutUrl(e = this.redirectUri) {
570
- d(g(e), "logoutUrl(): redirectUri is invalid");
649
+ y(w(e), "logoutUrl(): redirectUri is invalid");
571
650
  let t = { redirect_uri: e };
572
651
  return this.sessionService.makeUrl("logout", t);
573
652
  }
@@ -616,10 +695,10 @@ var L = (e) => typeof e.openSimplifiedLoginWidget == "function", R = "6.0.0-alph
616
695
  }, f = () => {
617
696
  this.eventTarget.dispatchEvent(new Event("simplifiedLoginCancelled"));
618
697
  };
619
- if (L(window)) return window.openSimplifiedLoginWidget(c, l, u, d, f), i(!0);
698
+ if (W(window)) return window.openSimplifiedLoginWidget(c, l, u, d, f), i(!0);
620
699
  let p = document.createElement("script");
621
700
  p.type = "text/javascript", p.src = a, p.onload = () => {
622
- if (!L(window)) {
701
+ if (!W(window)) {
623
702
  s(new t("Error when loading simplified login widget content"));
624
703
  return;
625
704
  }
@@ -632,14 +711,14 @@ var L = (e) => typeof e.openSimplifiedLoginWidget == "function", R = "6.0.0-alph
632
711
  };
633
712
  //#endregion
634
713
  //#region src/has-access-response.ts
635
- function q(e) {
636
- if (!m(e)) throw new t("Invalid hasAccess response");
714
+ function de(e) {
715
+ if (!S(e)) throw new t("Invalid hasAccess response");
637
716
  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");
717
+ if (typeof n != "boolean" || typeof r != "number" || !Array.isArray(i) || typeof a != "number" || !b(o) || !b(s)) throw new t("Invalid hasAccess response");
639
718
  return {
640
719
  entitled: n,
641
720
  ttl: r,
642
- allowedFeatures: i.filter(f),
721
+ allowedFeatures: i.filter(b),
643
722
  userId: a,
644
723
  uuid: o,
645
724
  sig: s
@@ -647,19 +726,19 @@ function q(e) {
647
726
  }
648
727
  //#endregion
649
728
  //#region src/monetization.ts
650
- var J = () => window, Y = class {
729
+ var fe = () => window, pe = class {
651
730
  cache;
652
731
  sessionService;
653
732
  pendingHasAccessRequests;
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({
733
+ constructor({ clientId: e, redirectUri: t, env: n, sessionDomain: r, window: i = fe() }) {
734
+ U(i), y(x(e), "clientId parameter is required"), y(b(n), `env parameter is invalid: ${n}`);
735
+ let a = F(n, e);
736
+ this.cache = new s(() => i && i.sessionStorage), this.pendingHasAccessRequests = {}, r && (y(w(r), "sessionDomain parameter is not a valid URL"), this.sessionService = I({
658
737
  serverUrl: r,
659
738
  defaultParams: {
660
739
  client_sdrn: a,
661
740
  redirect_uri: t,
662
- sdk_version: R
741
+ sdk_version: G
663
742
  }
664
743
  }));
665
744
  }
@@ -669,7 +748,7 @@ var J = () => window, Y = class {
669
748
  if (!Array.isArray(e)) throw new t("'productIds' must be an array");
670
749
  let r = [...e].sort(), i = this.accessCacheKey(r, n), a = this.cache.get(i);
671
750
  if (!a) {
672
- this.pendingHasAccessRequests[i] || (this.pendingHasAccessRequests[i] = this.sessionService.get(`/hasAccess/${r.join(",")}`, void 0, q));
751
+ this.pendingHasAccessRequests[i] || (this.pendingHasAccessRequests[i] = this.sessionService.get(`/hasAccess/${r.join(",")}`, void 0, de));
673
752
  let e = this.pendingHasAccessRequests[i];
674
753
  try {
675
754
  a = await e;
@@ -698,22 +777,24 @@ var J = () => window, Y = class {
698
777
  let i = n(r.window);
699
778
  if (!i) throw new t("Schibsted Account SDK is not available in this browser context");
700
779
  if (i.schAccount) throw new t("Schibsted Account SDK has already been initialized");
701
- let { log: a, callbackBeforeRedirect: o, defaultProductIds: s, varnish: c } = r, l = {
780
+ let { log: a, callbackBeforeRedirect: o, getConsents: s, generateState: c, refreshLoginLinks: l = !0, defaultProductIds: u, varnish: d } = r, f = {
702
781
  clientId: r.clientId,
703
782
  redirectUri: r.redirectUri,
704
783
  sessionDomain: r.sessionDomain,
705
784
  env: r.env ?? "PRE",
706
785
  window: i
707
786
  };
708
- if (this.#i = new K({
709
- ...l,
787
+ if (y(typeof c == "function", "generateState parameter must be a function"), y(typeof l == "boolean", "refreshLoginLinks parameter must be a boolean"), this.#i = new ue({
788
+ ...f,
710
789
  log: a,
711
- callbackBeforeRedirect: o
712
- }), s !== void 0 && !Array.isArray(s)) throw new t("Account defaultProductIds config must be an array");
713
- if (c && (typeof c != "object" || Array.isArray(c))) throw new t("Account varnish config must be an object");
714
- c && this.#i.enableVarnishCookie(c), this.#a = new Y(l), this.#e = l.clientId, this.#t = l.env, this.#n = l.redirectUri, this.#r = s && Object.freeze([...s]);
715
- let u = e.get(this.#i);
716
- u && e.set(this, u), i.schAccount = this, i.dispatchEvent(new CustomEvent("schAccount:ready", { detail: { instance: this } }));
790
+ callbackBeforeRedirect: o,
791
+ getConsents: s,
792
+ generateState: c
793
+ }), u !== void 0 && !Array.isArray(u)) throw new t("Account defaultProductIds config must be an array");
794
+ if (d && (typeof d != "object" || Array.isArray(d))) throw new t("Account varnish config must be an object");
795
+ d && this.#i.enableVarnishCookie(d), this.#a = new pe(f), this.#e = f.clientId, this.#t = f.env, this.#n = f.redirectUri, this.#r = u && Object.freeze([...u]);
796
+ let p = e.get(this.#i);
797
+ p && e.set(this, p), l && this.#i.enableLoginLinkRefresh(), i.schAccount = this, i.dispatchEvent(new CustomEvent("schAccount:ready", { detail: { instance: this } }));
717
798
  }
718
799
  get clientId() {
719
800
  return this.#e;
@@ -757,13 +838,13 @@ var J = () => window, Y = class {
757
838
  getSpId() {
758
839
  return this.#i.getSpId();
759
840
  }
760
- login(e) {
841
+ login(e = {}) {
761
842
  return this.#i.login(e);
762
843
  }
763
844
  logout(e) {
764
845
  this.#i.logout(e);
765
846
  }
766
- loginUrl(e) {
847
+ loginUrl(e = {}) {
767
848
  return this.#i.loginUrl(e);
768
849
  }
769
850
  logoutUrl(e) {
@@ -772,7 +853,7 @@ var J = () => window, Y = class {
772
853
  accountUrl(e) {
773
854
  return this.#i.accountUrl(e);
774
855
  }
775
- showSimplifiedLoginWidget(e, t) {
856
+ showSimplifiedLoginWidget(e = {}, t) {
776
857
  return this.#i.showSimplifiedLoginWidget(e, t);
777
858
  }
778
859
  setSessionCachingEnabled(e) {
@@ -796,14 +877,14 @@ var J = () => window, Y = class {
796
877
  off(e, t) {
797
878
  return this.#i.removeEventListener(e, t), this;
798
879
  }
799
- }, 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`);
800
- function oe(e) {
880
+ }, Z = "schAccount:ready", Q = 4e3, $, me = () => /* @__PURE__ */ Error("Schibsted Account SDK is not available in this browser context"), he = () => /* @__PURE__ */ Error(`Schibsted Account SDK was not initialized within ${Q} ms`);
881
+ function ge(e) {
801
882
  return new X(e);
802
883
  }
803
- function se() {
884
+ function _e() {
804
885
  let e = n();
805
886
  if (!e) {
806
- let e = ie();
887
+ let e = me();
807
888
  return console.error(e.message), Promise.reject(e);
808
889
  }
809
890
  return e.schAccount ? Promise.resolve(e.schAccount) : $ || ($ = new Promise((t, n) => {
@@ -814,12 +895,12 @@ function se() {
814
895
  n && (i(), t(n));
815
896
  };
816
897
  e.addEventListener(Z, a), r = e.setTimeout(() => {
817
- let e = ae();
898
+ let e = he();
818
899
  console.error(e.message), i(), n(e);
819
900
  }, Q), a();
820
901
  }), $);
821
902
  }
822
903
  //#endregion
823
- 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 };
904
+ export { X as Account, t as SDKError, ge as createAccountSdk, _e as getAccountSdk, R as isConnectedSessionResponse, V as isConnectedSessionWithUserIdResponse, z as isSessionFailureResponse, L as isSessionSuccessResponse };
824
905
 
825
906
  //# sourceMappingURL=index.js.map