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

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 ee = ["click", "auxclick"];
146
+ function te(e) {
147
+ return !e._tcf_ && !e._scc_ ? null : h(d(e));
148
+ }
149
+ function g(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 _(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 ne(e, { isLoginUrl: t, getConsentParams: n }) {
164
+ let r = (e) => {
165
+ let r = _(e);
166
+ if (!r || !t(r.href)) return;
167
+ let i = n();
168
+ i.toString() !== "" && (r.href = g(r.href, i));
169
+ };
170
+ ee.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 v(e, n = "Assertion failed") {
120
177
  if (!e) throw new t(n);
121
178
  }
122
- function f(e) {
179
+ function y(e) {
123
180
  return typeof e == "string";
124
181
  }
125
- function p(e) {
182
+ function b(e) {
126
183
  return typeof e == "string" && e.length > 0;
127
184
  }
128
- function m(e) {
185
+ function x(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 S(e) {
189
+ return x(e) && Object.keys(e).length > 0;
133
190
  }
134
- function g(e, ...t) {
191
+ function C(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 w(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 T(e, t, n = !1) {
203
+ return y(e) && Array.isArray(t) ? n ? t.indexOf(e) !== -1 : t.some((t) => y(t) && e.toUpperCase() === t.toUpperCase()) : !1;
147
204
  }
148
205
  //#endregion
149
206
  //#region src/object.ts
150
- function y(...e) {
207
+ function E(...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
+ v(x(e)), S(e) && Object.entries(e).forEach(([e, t]) => {
212
+ t !== void 0 && (n[e] = x(t) ? D(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 D(e) {
217
+ return v(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 re(e) {
222
+ return v(x(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 O = {
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
+ v(x(e), `window was supposed to be an object but it is ${e}`), v(x(e.screen), "window should be a valid Window object but it lacks a 'screen' property"), v(w(e.open), "window should be a valid Window object but it lacks an 'open' function"), v(C(t), "Invalid URL for popup");
234
+ let { height: i, width: a } = e.screen, o = E(O, 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 = re(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 v(b(e), `"url" param must be a non empty string: ${typeof e}`), S(t) && C(t[e]) ? t[e] : (v(C(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) => x(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), oe = () => {
205
262
  throw new t("fetch is not available in this environment");
206
- }, E = class e {
263
+ }, N = 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() ?? oe, log: r, defaultParams: i = {} }) {
269
+ v(x(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 && (v(w(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
+ v(b(n), `Method must be a non empty string but it is "${n}"`), v(b(i), `Pathname must be string but it is "${i}"`), v(x(a), "data must be a non-null object"), s.headers = x(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 = y(e) ? e : "Unknown RESTClient error";
288
+ x(e) && y(e.message) && (r = e.message);
289
+ let i = x(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 ? E(n, e) : E(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
+ }, se = (e) => Object.hasOwn(u, e), P = (e, t) => (v(b(t), "clientId parameter is required"), v(se(e), `env parameter is invalid: ${e}`), `sdrn:${u[e]}:client:${t}`), F = ({ serverUrl: e, log: t, defaultParams: n }) => new N({
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 I(e) {
321
+ return x(e) && typeof e.result == "boolean";
265
322
  }
266
- function j(e) {
267
- return A(e) && e.result === !0;
323
+ function L(e) {
324
+ return I(e) && e.result === !0;
268
325
  }
269
- function M(e) {
270
- return m(e) && !!e.error;
326
+ function R(e) {
327
+ return x(e) && !!e.error;
271
328
  }
272
- function N(e) {
273
- return m(e) && Object.keys(e).length === 1 && f(e.redirectURL);
329
+ function z(e) {
330
+ return x(e) && Object.keys(e).length === 1 && y(e.redirectURL);
274
331
  }
275
- function P(e) {
276
- return j(e) && typeof e.userId == "number";
332
+ function B(e) {
333
+ return L(e) && typeof e.userId == "number";
277
334
  }
278
- function F(e) {
279
- return N(e) || M(e) || A(e) || m(e) ? e : {};
335
+ function V(e) {
336
+ return z(e) || R(e) || I(e) || x(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 H(e) {
341
+ (!e.SPiD || typeof e.SPiD != "object") && (e.SPiD = {}), (!e.SPiD.Talk || typeof e.SPiD.Talk != "object") && (e.SPiD.Talk = {}), w(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.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 {
345
+ var U = (e) => typeof e.openSimplifiedLoginWidget == "function", W = "6.0.0-alpha.14", G = "hasSession-cache", K = "sessionCallBlocked-cache", ce = 1e3 * 60 * 5, q = "tab-id-cache", J = Math.floor(Math.random() * 1e5), le = 1e3 * 60 * 60 * 24 * 30, ue = () => window, de = class {
289
346
  eventTarget = new EventTarget();
290
347
  window;
291
348
  clientId;
@@ -293,6 +350,7 @@ var L = (e) => typeof e.openSimplifiedLoginWidget == "function", R = "6.0.0-alph
293
350
  env;
294
351
  log;
295
352
  callbackBeforeRedirect;
353
+ getConsents;
296
354
  sessionStorageCache;
297
355
  localStorageCache;
298
356
  enableSessionCaching;
@@ -308,41 +366,48 @@ var L = (e) => typeof e.openSimplifiedLoginWidget == "function", R = "6.0.0-alph
308
366
  setVarnishCookie;
309
367
  varnishExpiresIn;
310
368
  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 = {
369
+ constructor({ clientId: t, redirectUri: n, sessionDomain: r, env: i, log: a, window: o = ue(), callbackBeforeRedirect: c = () => {}, getConsents: u = () => te(o) }) {
370
+ v(b(t), "clientId parameter is required"), v(x(o), "The reference to window is missing"), v(!n || C(n), "redirectUri parameter is invalid"), v(b(r) && C(r), "sessionDomain parameter is not a valid URL"), v(y(i), `env parameter is invalid: ${i}`), v(w(u), "getConsents parameter must be a function"), H(o), this.window = o, this.clientId = t, this.redirectUri = n, this.env = i, this.log = a, this.callbackBeforeRedirect = c, this.getConsents = u, 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 });
371
+ let d = {
314
372
  client_id: this.clientId,
315
373
  redirect_uri: this.redirectUri
316
- }, h = O(this.env, this.clientId);
317
- this.spid = k({
318
- serverUrl: x(i, l.SPiD),
374
+ }, f = P(this.env, this.clientId);
375
+ this.spid = F({
376
+ serverUrl: A(i, l.SPiD),
319
377
  log: this.log,
320
- defaultParams: u
321
- }), this.oauthService = k({
322
- serverUrl: x(i, l.SPiD),
378
+ defaultParams: d
379
+ }), this.oauthService = F({
380
+ serverUrl: A(i, l.SPiD),
323
381
  log: this.log,
324
- defaultParams: u
325
- }), this.bffService = k({
326
- serverUrl: x(i, l.BFF),
382
+ defaultParams: d
383
+ }), this.bffService = F({
384
+ serverUrl: A(i, l.BFF),
327
385
  log: this.log,
328
- defaultParams: u
329
- }), this.sessionService = k({
386
+ defaultParams: d
387
+ }), this.sessionService = F({
330
388
  serverUrl: r,
331
389
  log: this.log,
332
390
  defaultParams: {
333
- client_sdrn: h,
391
+ client_sdrn: f,
334
392
  redirect_uri: this.redirectUri,
335
- sdk_version: R
393
+ sdk_version: W
336
394
  }
337
- }), this.globalSessionService = k({
338
- serverUrl: x(i, l.SESSION_SERVICE),
395
+ }), this.globalSessionService = F({
396
+ serverUrl: A(i, l.SESSION_SERVICE),
339
397
  log: this.log,
340
398
  defaultParams: {
341
- client_sdrn: h,
342
- sdk_version: R
399
+ client_sdrn: f,
400
+ sdk_version: W
343
401
  }
344
402
  }), this.usedSessionServiceGetSessionEndpoint = this.sessionService.url.pathname && this.sessionService.url.pathname.length <= 1 ? "v2/session" : "session", this._unblockSessionCall();
345
403
  }
404
+ enableLoginLinkRefresh() {
405
+ let { document: e } = this.window;
406
+ e && w(e.addEventListener) && ne(e, {
407
+ isLoginUrl: (e) => this.isLoginUrl(e),
408
+ getConsentParams: () => this.getConsentParams()
409
+ });
410
+ }
346
411
  addEventListener(e, t) {
347
412
  this.eventTarget.addEventListener(e, t);
348
413
  }
@@ -351,18 +416,18 @@ var L = (e) => typeof e.openSimplifiedLoginWidget == "function", R = "6.0.0-alph
351
416
  }
352
417
  _getTabId() {
353
418
  if (this.enableSessionCaching) {
354
- let e = this.sessionStorageCache.get(H);
355
- return typeof e == "number" ? e : (this.sessionStorageCache.set(H, U, W), U);
419
+ let e = this.sessionStorageCache.get(q);
420
+ return typeof e == "number" ? e : (this.sessionStorageCache.set(q, J, le), J);
356
421
  }
357
422
  }
358
423
  _isSessionCallBlocked() {
359
- return !!this.localStorageCache.get(B);
424
+ return !!this.localStorageCache.get(K);
360
425
  }
361
426
  _blockSessionCall() {
362
- this.localStorageCache.set(B, !0, V);
427
+ this.localStorageCache.set(K, !0, ce);
363
428
  }
364
429
  _unblockSessionCall() {
365
- this.localStorageCache.delete(B);
430
+ this.localStorageCache.delete(K);
366
431
  }
367
432
  _closePopup() {
368
433
  this.popup &&= (this.popup.closed || this.popup.close(), null);
@@ -370,10 +435,10 @@ var L = (e) => typeof e.openSimplifiedLoginWidget == "function", R = "6.0.0-alph
370
435
  enableVarnishCookie(e) {
371
436
  if (typeof e != "object") throw new t("VarnishCookieOptions must be an object");
372
437
  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;
438
+ v(Number.isInteger(n), "'expiresIn' must be an integer"), v(n >= 0, "'expiresIn' cannot be negative"), this.setVarnishCookie = !0, this.varnishExpiresIn = n, this.varnishCookieDomain = r;
374
439
  }
375
440
  _maybeSetVarnishCookie(e) {
376
- if (!this.setVarnishCookie || !A(e)) return;
441
+ if (!this.setVarnishCookie || !I(e)) return;
377
442
  let t = /* @__PURE__ */ new Date();
378
443
  if (this.varnishExpiresIn || typeof e.expiresIn == "number" && e.expiresIn > 0) {
379
444
  let n = this.varnishExpiresIn || e.expiresIn || 0;
@@ -391,42 +456,42 @@ var L = (e) => typeof e.openSimplifiedLoginWidget == "function", R = "6.0.0-alph
391
456
  this.setVarnishCookie && this._clearVarnishCookie();
392
457
  }
393
458
  _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 || "";
459
+ let e = this.session && I(this.session) && typeof this.session.baseDomain == "string" ? this.session.baseDomain : this.window.location.hostname, t = this.varnishCookieDomain || e || "";
395
460
  document.cookie = `SP_ID=nothing; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/; domain=.${t}`;
396
461
  }
397
462
  hasSession() {
398
463
  if (this._isSessionCallBlocked()) {
399
- let e = F(this.session);
400
- return Promise.resolve(N(e) ? {} : e);
464
+ let e = V(this.session);
465
+ return Promise.resolve(z(e) ? {} : e);
401
466
  }
402
467
  if (this.hasSessionInProgress) return this.hasSessionInProgress;
403
468
  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;
469
+ if (R(r)) throw new t("HasSession failed", x(r.error) ? r.error : { description: String(r.error) });
470
+ return this._maybeSetVarnishCookie(r), n = (I(this.session) && this.session.id) !== (I(r) && r.id), e.get(this)?.beforeUpdate?.(this.session, r), this.session = r, r;
406
471
  }, i = () => {
407
- let e = this.sessionStorageCache.get(z);
408
- return e ? F(e) : null;
472
+ let e = this.sessionStorageCache.get(G);
473
+ return e ? V(e) : null;
409
474
  }, a = async () => {
410
475
  if (this.enableSessionCaching) {
411
476
  let e = i();
412
- if (e) return N(e) ? {} : r(e);
477
+ if (e) return z(e) ? {} : r(e);
413
478
  }
414
479
  let e = null;
415
480
  try {
416
- e = await this.sessionService.get(this.usedSessionServiceGetSessionEndpoint, { tabId: this._getTabId() }, F);
481
+ e = await this.sessionService.get(this.usedSessionServiceGetSessionEndpoint, { tabId: this._getTabId() }, V);
417
482
  } catch (e) {
418
- let t = m(e) ? e : void 0;
483
+ let t = x(e) ? e : void 0;
419
484
  if (t?.code === 400 && this.enableSessionCaching) {
420
485
  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);
486
+ this.sessionStorageCache.set(G, { error: e }, n);
487
+ } else t && typeof t.code == "number" && t.code >= 500 && t.code < 600 && this.enableSessionCaching && this.sessionStorageCache.set(G, { error: e }, 30 * 1e3);
423
488
  throw e;
424
489
  }
425
490
  if (e) {
426
- if (N(e)) return this._blockSessionCall(), await this.callbackBeforeRedirect(), this.sessionService.makeUrl(e.redirectURL, { tabId: this._getTabId() });
491
+ if (z(e)) return this._blockSessionCall(), await this.callbackBeforeRedirect(), this.sessionService.makeUrl(e.redirectURL, { tabId: this._getTabId() });
427
492
  if (this.enableSessionCaching) {
428
- let t = 1e3 * (A(e) && e.expiresIn || 300);
429
- this.sessionStorageCache.set(z, e, t);
493
+ let t = 1e3 * (I(e) && e.expiresIn || 300);
494
+ this.sessionStorageCache.set(G, e, t);
430
495
  }
431
496
  }
432
497
  return r(e ?? {});
@@ -437,7 +502,7 @@ var L = (e) => typeof e.openSimplifiedLoginWidget == "function", R = "6.0.0-alph
437
502
  }
438
503
  async isLoggedIn() {
439
504
  try {
440
- return A(await this.hasSession());
505
+ return I(await this.hasSession());
441
506
  } catch {
442
507
  return !1;
443
508
  }
@@ -446,27 +511,27 @@ var L = (e) => typeof e.openSimplifiedLoginWidget == "function", R = "6.0.0-alph
446
511
  this.enableSessionCaching = e;
447
512
  }
448
513
  clearCachedUserSession() {
449
- this.sessionStorageCache.delete(z);
514
+ this.sessionStorageCache.delete(G);
450
515
  }
451
516
  async isConnected() {
452
517
  try {
453
- return j(await this.hasSession());
518
+ return L(await this.hasSession());
454
519
  } catch {
455
520
  return !1;
456
521
  }
457
522
  }
458
523
  async getUser() {
459
524
  let e = await this.hasSession();
460
- if (!j(e)) throw new t("The user is not connected to this merchant");
461
- return b(e);
525
+ if (!L(e)) throw new t("The user is not connected to this merchant");
526
+ return D(e);
462
527
  }
463
528
  async getUserId() {
464
529
  let e = await this.hasSession();
465
- if (P(e)) return e.userId;
530
+ if (B(e)) return e.userId;
466
531
  throw new t("The user is not connected to this merchant");
467
532
  }
468
533
  async getExternalId(e, n = "") {
469
- let r = await this.hasSession(), i = A(r) ? r.pairId : void 0;
534
+ let r = await this.hasSession(), i = I(r) ? r.pairId : void 0;
470
535
  if (!i) throw new t("pairId missing in user session!");
471
536
  if (!e || e.length === 0) throw new t("externalParty cannot be empty");
472
537
  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 +539,28 @@ var L = (e) => typeof e.openSimplifiedLoginWidget == "function", R = "6.0.0-alph
474
539
  }
475
540
  async getUserSDRN() {
476
541
  let e = await this.hasSession();
477
- if (A(e) && e.sdrn) return e.sdrn;
542
+ if (I(e) && e.sdrn) return e.sdrn;
478
543
  throw new t("Failed to get SDRN from user session");
479
544
  }
480
545
  async getUserUuid() {
481
546
  let e = await this.hasSession();
482
- if (A(e) && e.uuid && e.result) return e.uuid;
547
+ if (I(e) && e.uuid && e.result) return e.uuid;
483
548
  throw new t("The user is not connected to this merchant");
484
549
  }
485
550
  async getUserContextData() {
486
551
  try {
487
- return await this.globalSessionService.get("user-context", void 0, (e) => m(e) && f(e.identifier) ? {
552
+ return await this.globalSessionService.get("user-context", void 0, (e) => x(e) && y(e.identifier) ? {
488
553
  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
554
+ display_text: y(e.display_text) ? e.display_text : "",
555
+ client_name: y(e.client_name) ? e.client_name : "",
556
+ provider_id: y(e.provider_id) ? e.provider_id : void 0
492
557
  } : null);
493
558
  } catch {
494
559
  return null;
495
560
  }
496
561
  }
497
562
  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);
563
+ this._closePopup(), this.sessionStorageCache.delete(G);
499
564
  let h = this.loginUrl({
500
565
  state: e,
501
566
  acrValues: t,
@@ -512,7 +577,7 @@ var L = (e) => typeof e.openSimplifiedLoginWidget == "function", R = "6.0.0-alph
512
577
  xEnvironmentId: p,
513
578
  originCampaign: m
514
579
  });
515
- return i && (this.popup = ne(this.window, h, "Schibsted account", {
580
+ return i && (this.popup = k(this.window, h, "Schibsted account", {
516
581
  width: 360,
517
582
  height: 570
518
583
  }), this.popup) ? (this.eventTarget.dispatchEvent(new CustomEvent("loginRequested", { detail: {
@@ -526,20 +591,20 @@ var L = (e) => typeof e.openSimplifiedLoginWidget == "function", R = "6.0.0-alph
526
591
  async getSpId() {
527
592
  try {
528
593
  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;
594
+ if (I(e)) return e.sp_id || null;
595
+ let t = x(e) && "sp_id" in e ? e.sp_id : void 0;
596
+ return y(t) ? t : null;
532
597
  } catch {
533
598
  return null;
534
599
  }
535
600
  }
536
601
  logout(e = this.redirectUri) {
537
- this.sessionStorageCache.delete(z), this._maybeClearVarnishCookie();
602
+ this.sessionStorageCache.delete(G), this._maybeClearVarnishCookie();
538
603
  let t = this.logoutUrl(e);
539
604
  this.eventTarget.dispatchEvent(new CustomEvent("logoutRequested", { detail: { url: t } })), this.window.location.href = t;
540
605
  }
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, [
606
+ loginUrl({ state: e, acrValues: t = "", scope: n = "openid", redirectUri: r = this.redirectUri, loginHint: i = "", tag: a = "", teaser: o = "", maxAge: s = "", locale: c, oneStepLogin: l = !1, prompt: u = "select_account", xDomainId: d = "", xEnvironmentId: f = "", originCampaign: p = "" }) {
607
+ return v(!t || T(t, ["", "otp-email"], !0) || t.split(" ").every((e) => T(e, [
543
608
  "password",
544
609
  "otp",
545
610
  "sms",
@@ -548,7 +613,7 @@ var L = (e) => typeof e.openSimplifiedLoginWidget == "function", R = "6.0.0-alph
548
613
  "eid-se",
549
614
  "eid-fi",
550
615
  "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", {
616
+ ], !0)), `The acrValues parameter is not acceptable: ${t}`), v(C(r), `loginUrl(): redirectUri must be a valid url but is ${r}`), v(b(e), `the state parameter should be a non empty string but it is ${e}`), g(this.oauthService.makeUrl("oauth/authorize", {
552
617
  response_type: "code",
553
618
  redirect_uri: r,
554
619
  scope: n,
@@ -561,13 +626,26 @@ var L = (e) => typeof e.openSimplifiedLoginWidget == "function", R = "6.0.0-alph
561
626
  locale: c,
562
627
  one_step_login: l || "",
563
628
  prompt: t ? "" : u,
564
- x_domain_id: f,
565
- x_env_id: m,
566
- utm_campaign: h
567
- });
629
+ x_domain_id: d,
630
+ x_env_id: f,
631
+ utm_campaign: p
632
+ }), this.getConsentParams());
633
+ }
634
+ getConsentParams() {
635
+ try {
636
+ let e = this.getConsents() || new URLSearchParams();
637
+ return v(e instanceof URLSearchParams, `getConsents must return URLSearchParams but it returned ${e}`), e;
638
+ } catch (e) {
639
+ return (this.log || console.warn)("Schibsted account SDK: could not read consents, logging in without them", e), new URLSearchParams();
640
+ }
641
+ }
642
+ isLoginUrl(e) {
643
+ if (!C(e)) return !1;
644
+ let t = new URL(e), n = new URL(this.oauthService.makeUrl("oauth/authorize", {}, !1));
645
+ return t.origin === n.origin && t.pathname === n.pathname && t.searchParams.get("client_id") === this.clientId;
568
646
  }
569
647
  logoutUrl(e = this.redirectUri) {
570
- d(g(e), "logoutUrl(): redirectUri is invalid");
648
+ v(C(e), "logoutUrl(): redirectUri is invalid");
571
649
  let t = { redirect_uri: e };
572
650
  return this.sessionService.makeUrl("logout", t);
573
651
  }
@@ -616,10 +694,10 @@ var L = (e) => typeof e.openSimplifiedLoginWidget == "function", R = "6.0.0-alph
616
694
  }, f = () => {
617
695
  this.eventTarget.dispatchEvent(new Event("simplifiedLoginCancelled"));
618
696
  };
619
- if (L(window)) return window.openSimplifiedLoginWidget(c, l, u, d, f), i(!0);
697
+ if (U(window)) return window.openSimplifiedLoginWidget(c, l, u, d, f), i(!0);
620
698
  let p = document.createElement("script");
621
699
  p.type = "text/javascript", p.src = a, p.onload = () => {
622
- if (!L(window)) {
700
+ if (!U(window)) {
623
701
  s(new t("Error when loading simplified login widget content"));
624
702
  return;
625
703
  }
@@ -632,14 +710,14 @@ var L = (e) => typeof e.openSimplifiedLoginWidget == "function", R = "6.0.0-alph
632
710
  };
633
711
  //#endregion
634
712
  //#region src/has-access-response.ts
635
- function q(e) {
636
- if (!m(e)) throw new t("Invalid hasAccess response");
713
+ function fe(e) {
714
+ if (!x(e)) throw new t("Invalid hasAccess response");
637
715
  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");
716
+ if (typeof n != "boolean" || typeof r != "number" || !Array.isArray(i) || typeof a != "number" || !y(o) || !y(s)) throw new t("Invalid hasAccess response");
639
717
  return {
640
718
  entitled: n,
641
719
  ttl: r,
642
- allowedFeatures: i.filter(f),
720
+ allowedFeatures: i.filter(y),
643
721
  userId: a,
644
722
  uuid: o,
645
723
  sig: s
@@ -647,19 +725,19 @@ function q(e) {
647
725
  }
648
726
  //#endregion
649
727
  //#region src/monetization.ts
650
- var J = () => window, Y = class {
728
+ var pe = () => window, Y = class {
651
729
  cache;
652
730
  sessionService;
653
731
  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({
732
+ constructor({ clientId: e, redirectUri: t, env: n, sessionDomain: r, window: i = pe() }) {
733
+ H(i), v(b(e), "clientId parameter is required"), v(y(n), `env parameter is invalid: ${n}`);
734
+ let a = P(n, e);
735
+ this.cache = new s(() => i && i.sessionStorage), this.pendingHasAccessRequests = {}, r && (v(C(r), "sessionDomain parameter is not a valid URL"), this.sessionService = F({
658
736
  serverUrl: r,
659
737
  defaultParams: {
660
738
  client_sdrn: a,
661
739
  redirect_uri: t,
662
- sdk_version: R
740
+ sdk_version: W
663
741
  }
664
742
  }));
665
743
  }
@@ -669,7 +747,7 @@ var J = () => window, Y = class {
669
747
  if (!Array.isArray(e)) throw new t("'productIds' must be an array");
670
748
  let r = [...e].sort(), i = this.accessCacheKey(r, n), a = this.cache.get(i);
671
749
  if (!a) {
672
- this.pendingHasAccessRequests[i] || (this.pendingHasAccessRequests[i] = this.sessionService.get(`/hasAccess/${r.join(",")}`, void 0, q));
750
+ this.pendingHasAccessRequests[i] || (this.pendingHasAccessRequests[i] = this.sessionService.get(`/hasAccess/${r.join(",")}`, void 0, fe));
673
751
  let e = this.pendingHasAccessRequests[i];
674
752
  try {
675
753
  a = await e;
@@ -691,113 +769,120 @@ var J = () => window, Y = class {
691
769
  #e;
692
770
  #t;
693
771
  #n;
772
+ #r;
773
+ #i;
774
+ #a;
694
775
  constructor(r) {
695
776
  let i = n(r.window);
696
777
  if (!i) throw new t("Schibsted Account SDK is not available in this browser context");
697
778
  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 = {
779
+ let { log: a, callbackBeforeRedirect: o, getConsents: s, refreshLoginLinks: c = !0, defaultProductIds: l, varnish: u } = r, d = {
699
780
  clientId: r.clientId,
700
781
  redirectUri: r.redirectUri,
701
782
  sessionDomain: r.sessionDomain,
702
783
  env: r.env ?? "PRE",
703
784
  window: i
704
785
  };
705
- if (this.#t = new K({
706
- ...l,
786
+ if (v(typeof c == "boolean", "refreshLoginLinks parameter must be a boolean"), this.#i = new de({
787
+ ...d,
707
788
  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() {
789
+ callbackBeforeRedirect: o,
790
+ getConsents: s
791
+ }), l !== void 0 && !Array.isArray(l)) throw new t("Account defaultProductIds config must be an array");
792
+ if (u && (typeof u != "object" || Array.isArray(u))) throw new t("Account varnish config must be an object");
793
+ u && this.#i.enableVarnishCookie(u), this.#a = new Y(d), this.#e = d.clientId, this.#t = d.env, this.#n = d.redirectUri, this.#r = l && Object.freeze([...l]);
794
+ let f = e.get(this.#i);
795
+ f && e.set(this, f), c && this.#i.enableLoginLinkRefresh(), i.schAccount = this, i.dispatchEvent(new CustomEvent("schAccount:ready", { detail: { instance: this } }));
796
+ }
797
+ get clientId() {
722
798
  return this.#e;
723
799
  }
800
+ get env() {
801
+ return this.#t;
802
+ }
803
+ get redirectUri() {
804
+ return this.#n;
805
+ }
806
+ get defaultProductIds() {
807
+ return this.#r;
808
+ }
724
809
  hasSession() {
725
- return this.#t.hasSession();
810
+ return this.#i.hasSession();
726
811
  }
727
812
  isLoggedIn() {
728
- return this.#t.isLoggedIn();
813
+ return this.#i.isLoggedIn();
729
814
  }
730
815
  isConnected() {
731
- return this.#t.isConnected();
816
+ return this.#i.isConnected();
732
817
  }
733
818
  getUser() {
734
- return this.#t.getUser();
819
+ return this.#i.getUser();
735
820
  }
736
821
  getUserId() {
737
- return this.#t.getUserId();
822
+ return this.#i.getUserId();
738
823
  }
739
824
  getExternalId(e, t = "") {
740
- return this.#t.getExternalId(e, t);
825
+ return this.#i.getExternalId(e, t);
741
826
  }
742
827
  getUserUuid() {
743
- return this.#t.getUserUuid();
828
+ return this.#i.getUserUuid();
744
829
  }
745
830
  getUserSDRN() {
746
- return this.#t.getUserSDRN();
831
+ return this.#i.getUserSDRN();
747
832
  }
748
833
  getUserContextData() {
749
- return this.#t.getUserContextData();
834
+ return this.#i.getUserContextData();
750
835
  }
751
836
  getSpId() {
752
- return this.#t.getSpId();
837
+ return this.#i.getSpId();
753
838
  }
754
839
  login(e) {
755
- return this.#t.login(e);
840
+ return this.#i.login(e);
756
841
  }
757
842
  logout(e) {
758
- this.#t.logout(e);
843
+ this.#i.logout(e);
759
844
  }
760
845
  loginUrl(e) {
761
- return this.#t.loginUrl(e);
846
+ return this.#i.loginUrl(e);
762
847
  }
763
848
  logoutUrl(e) {
764
- return this.#t.logoutUrl(e);
849
+ return this.#i.logoutUrl(e);
765
850
  }
766
851
  accountUrl(e) {
767
- return this.#t.accountUrl(e);
852
+ return this.#i.accountUrl(e);
768
853
  }
769
854
  showSimplifiedLoginWidget(e, t) {
770
- return this.#t.showSimplifiedLoginWidget(e, t);
855
+ return this.#i.showSimplifiedLoginWidget(e, t);
771
856
  }
772
857
  setSessionCachingEnabled(e) {
773
- this.#t.setSessionCachingEnabled(e);
858
+ this.#i.setSessionCachingEnabled(e);
774
859
  }
775
860
  clearCachedUserSession() {
776
- this.#t.clearCachedUserSession();
861
+ this.#i.clearCachedUserSession();
777
862
  }
778
- async hasAccess(e = this.#e.defaultProductIds) {
863
+ async hasAccess(e = this.#r) {
779
864
  if (!e) throw new t("hasAccess requires productIds or defaultProductIds in the Account config");
780
865
  if (e.length === 0) return null;
781
- let n = await this.#t.getUserId();
782
- return this.#n.hasAccess(e, n);
866
+ let n = await this.#i.getUserId();
867
+ return this.#a.hasAccess(e, n);
783
868
  }
784
869
  clearCachedAccessResult(e, t) {
785
- this.#n.clearCachedAccessResult(e, t);
870
+ this.#a.clearCachedAccessResult(e, t);
786
871
  }
787
872
  on(e, t) {
788
- return this.#t.addEventListener(e, t), this;
873
+ return this.#i.addEventListener(e, t), this;
789
874
  }
790
875
  off(e, t) {
791
- return this.#t.removeEventListener(e, t), this;
876
+ return this.#i.removeEventListener(e, t), this;
792
877
  }
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`);
794
- function oe(e) {
878
+ }, 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`);
879
+ function ge(e) {
795
880
  return new X(e);
796
881
  }
797
- function se() {
882
+ function _e() {
798
883
  let e = n();
799
884
  if (!e) {
800
- let e = ie();
885
+ let e = me();
801
886
  return console.error(e.message), Promise.reject(e);
802
887
  }
803
888
  return e.schAccount ? Promise.resolve(e.schAccount) : $ || ($ = new Promise((t, n) => {
@@ -808,12 +893,12 @@ function se() {
808
893
  n && (i(), t(n));
809
894
  };
810
895
  e.addEventListener(Z, a), r = e.setTimeout(() => {
811
- let e = ae();
896
+ let e = he();
812
897
  console.error(e.message), i(), n(e);
813
898
  }, Q), a();
814
899
  }), $);
815
900
  }
816
901
  //#endregion
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 };
902
+ export { X as Account, t as SDKError, ge as createAccountSdk, _e as getAccountSdk, L as isConnectedSessionResponse, B as isConnectedSessionWithUserIdResponse, R as isSessionFailureResponse, I as isSessionSuccessResponse };
818
903
 
819
904
  //# sourceMappingURL=index.js.map