@schibsted/account-sdk-browser 6.0.0-alpha.14 → 6.0.0-alpha.16
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/account.d.ts +9 -6
- package/dist/identity.d.ts +4 -2
- package/dist/index.d.ts +3 -3
- package/dist/index.js +144 -142
- package/dist/index.js.map +1 -1
- package/dist/types/account.d.ts +9 -4
- package/dist/types/common.d.ts +17 -2
- package/dist/types/identity.d.ts +12 -10
- package/dist/types/login.d.ts +14 -12
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/account.ts +12 -6
- package/src/identity.ts +11 -4
- package/src/index.ts +9 -2
- package/src/types/account.ts +9 -8
- package/src/types/common.ts +19 -2
- package/src/types/identity.ts +12 -11
- package/src/types/login.ts +14 -12
- package/src/version.ts +1 -1
package/dist/index.js
CHANGED
|
@@ -142,11 +142,11 @@ function h(e) {
|
|
|
142
142
|
}
|
|
143
143
|
//#endregion
|
|
144
144
|
//#region src/consents.ts
|
|
145
|
-
var
|
|
146
|
-
function
|
|
145
|
+
var g = ["click", "auxclick"];
|
|
146
|
+
function ee(e) {
|
|
147
147
|
return !e._tcf_ && !e._scc_ ? null : h(d(e));
|
|
148
148
|
}
|
|
149
|
-
function
|
|
149
|
+
function _(e, t) {
|
|
150
150
|
let n = new URL(e);
|
|
151
151
|
return t.forEach((e, t) => {
|
|
152
152
|
n.searchParams.delete(t);
|
|
@@ -154,41 +154,41 @@ function g(e, t) {
|
|
|
154
154
|
n.searchParams.append(t, e);
|
|
155
155
|
}), n.href;
|
|
156
156
|
}
|
|
157
|
-
function
|
|
157
|
+
function te(e) {
|
|
158
158
|
return (typeof e.composedPath == "function" ? e.composedPath() : [e.target]).find((e) => {
|
|
159
159
|
let t = e;
|
|
160
160
|
return !!t && t.tagName === "A" && typeof t.href == "string";
|
|
161
161
|
});
|
|
162
162
|
}
|
|
163
|
-
function
|
|
163
|
+
function v(e, { isLoginUrl: t, getConsentParams: n }) {
|
|
164
164
|
let r = (e) => {
|
|
165
|
-
let r =
|
|
165
|
+
let r = te(e);
|
|
166
166
|
if (!r || !t(r.href)) return;
|
|
167
167
|
let i = n();
|
|
168
|
-
i.toString() !== "" && (r.href =
|
|
168
|
+
i.toString() !== "" && (r.href = _(r.href, i));
|
|
169
169
|
};
|
|
170
|
-
|
|
170
|
+
g.forEach((t) => {
|
|
171
171
|
e.addEventListener(t, r, !0);
|
|
172
172
|
});
|
|
173
173
|
}
|
|
174
174
|
//#endregion
|
|
175
175
|
//#region src/validate.ts
|
|
176
|
-
function
|
|
176
|
+
function y(e, n = "Assertion failed") {
|
|
177
177
|
if (!e) throw new t(n);
|
|
178
178
|
}
|
|
179
|
-
function
|
|
179
|
+
function b(e) {
|
|
180
180
|
return typeof e == "string";
|
|
181
181
|
}
|
|
182
|
-
function
|
|
182
|
+
function x(e) {
|
|
183
183
|
return typeof e == "string" && e.length > 0;
|
|
184
184
|
}
|
|
185
|
-
function
|
|
185
|
+
function S(e) {
|
|
186
186
|
return typeof e == "object" && !!e;
|
|
187
187
|
}
|
|
188
|
-
function
|
|
189
|
-
return
|
|
188
|
+
function C(e) {
|
|
189
|
+
return S(e) && Object.keys(e).length > 0;
|
|
190
190
|
}
|
|
191
|
-
function
|
|
191
|
+
function w(e, ...t) {
|
|
192
192
|
try {
|
|
193
193
|
let n = new URL(e);
|
|
194
194
|
return t.every((e) => n[e]);
|
|
@@ -196,32 +196,32 @@ function C(e, ...t) {
|
|
|
196
196
|
return !1;
|
|
197
197
|
}
|
|
198
198
|
}
|
|
199
|
-
function
|
|
199
|
+
function T(e) {
|
|
200
200
|
return typeof e == "function";
|
|
201
201
|
}
|
|
202
|
-
function
|
|
203
|
-
return
|
|
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;
|
|
204
204
|
}
|
|
205
205
|
//#endregion
|
|
206
206
|
//#region src/object.ts
|
|
207
|
-
function
|
|
207
|
+
function D(...e) {
|
|
208
208
|
let n = {};
|
|
209
209
|
if (!(e && e.length)) throw new t("No objects to clone");
|
|
210
210
|
return e.forEach((e) => {
|
|
211
|
-
|
|
212
|
-
t !== void 0 && (n[e] =
|
|
211
|
+
y(S(e)), C(e) && Object.entries(e).forEach(([e, t]) => {
|
|
212
|
+
t !== void 0 && (n[e] = S(t) ? O(t) : t);
|
|
213
213
|
});
|
|
214
214
|
}), n;
|
|
215
215
|
}
|
|
216
|
-
function
|
|
217
|
-
return
|
|
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;
|
|
218
218
|
}
|
|
219
219
|
//#endregion
|
|
220
220
|
//#region src/popup.ts
|
|
221
|
-
function
|
|
222
|
-
return
|
|
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(",");
|
|
223
223
|
}
|
|
224
|
-
var
|
|
224
|
+
var re = {
|
|
225
225
|
scrollbars: "yes",
|
|
226
226
|
location: "yes",
|
|
227
227
|
status: "no",
|
|
@@ -230,20 +230,20 @@ var O = {
|
|
|
230
230
|
resizable: "yes"
|
|
231
231
|
};
|
|
232
232
|
function k(e, t, n = "", r = {}) {
|
|
233
|
-
|
|
234
|
-
let { height: i, width: a } = e.screen, o =
|
|
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;
|
|
235
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);
|
|
236
|
-
let l =
|
|
236
|
+
let l = ne(o);
|
|
237
237
|
return e.open(t, n, l);
|
|
238
238
|
}
|
|
239
239
|
//#endregion
|
|
240
240
|
//#region src/url.ts
|
|
241
241
|
function A(e, t) {
|
|
242
|
-
return
|
|
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);
|
|
243
243
|
}
|
|
244
244
|
//#endregion
|
|
245
245
|
//#region src/rest-client.ts
|
|
246
|
-
var ie = (e) => e.map((e) =>
|
|
246
|
+
var ie = (e) => e.map((e) => S(e) ? JSON.stringify(e, null, 2) : e).join(" "), j = (e, ...t) => {
|
|
247
247
|
e && e(ie(t));
|
|
248
248
|
};
|
|
249
249
|
function M(e) {
|
|
@@ -258,24 +258,24 @@ function M(e) {
|
|
|
258
258
|
};
|
|
259
259
|
return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g, (e) => t[e]);
|
|
260
260
|
}
|
|
261
|
-
var ae = () => window.fetch && window.fetch.bind(window),
|
|
261
|
+
var ae = () => window.fetch && window.fetch.bind(window), N = () => {
|
|
262
262
|
throw new t("fetch is not available in this environment");
|
|
263
|
-
},
|
|
263
|
+
}, P = class e {
|
|
264
264
|
url;
|
|
265
265
|
defaultParams;
|
|
266
266
|
log;
|
|
267
267
|
fetch;
|
|
268
|
-
constructor({ serverUrl: e = "PRE", envDic: t, fetch: n = ae() ??
|
|
269
|
-
|
|
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
270
|
let a = A(e, t ?? {}), o = a.endsWith("/") ? a : `${a}/`;
|
|
271
|
-
this.url = new URL(o), this.defaultParams = i, r && (
|
|
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;
|
|
272
272
|
}
|
|
273
273
|
async go(e) {
|
|
274
274
|
let { method: n, headers: r, pathname: i, data: a = {}, useDefaultParams: o = !0, fetchOptions: s = {
|
|
275
275
|
method: e.method,
|
|
276
276
|
credentials: "include"
|
|
277
277
|
}, parseResponse: c } = e;
|
|
278
|
-
|
|
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 : {};
|
|
279
279
|
let l = this.makeUrl(i, a, o);
|
|
280
280
|
j(this.log, "Request:", n.toUpperCase(), l), j(this.log, "Request Headers:", s.headers), j(this.log, "Request Body:", s.body);
|
|
281
281
|
try {
|
|
@@ -284,9 +284,9 @@ var ae = () => window.fetch && window.fetch.bind(window), oe = () => {
|
|
|
284
284
|
let n = await e.json();
|
|
285
285
|
return j(this.log, "Response Parsed:", n), c ? c(n) : n;
|
|
286
286
|
} catch (e) {
|
|
287
|
-
let r =
|
|
288
|
-
|
|
289
|
-
let i =
|
|
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;
|
|
290
290
|
throw new t(`Failed to '${n}' '${l}': '${r}'`, i);
|
|
291
291
|
}
|
|
292
292
|
}
|
|
@@ -307,42 +307,42 @@ var ae = () => window.fetch && window.fetch.bind(window), oe = () => {
|
|
|
307
307
|
});
|
|
308
308
|
}
|
|
309
309
|
static search(e, t, n) {
|
|
310
|
-
let r = t ?
|
|
310
|
+
let r = t ? D(n, e) : D(e);
|
|
311
311
|
return Object.keys(r).filter((e) => r[e] !== "").map((e) => `${M(e)}=${M(String(r[e]))}`).join("&");
|
|
312
312
|
}
|
|
313
|
-
},
|
|
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({
|
|
314
314
|
serverUrl: e,
|
|
315
315
|
log: t,
|
|
316
316
|
defaultParams: n
|
|
317
317
|
});
|
|
318
318
|
//#endregion
|
|
319
319
|
//#region src/session-response.ts
|
|
320
|
-
function I(e) {
|
|
321
|
-
return x(e) && typeof e.result == "boolean";
|
|
322
|
-
}
|
|
323
320
|
function L(e) {
|
|
324
|
-
return
|
|
321
|
+
return S(e) && typeof e.result == "boolean";
|
|
325
322
|
}
|
|
326
323
|
function R(e) {
|
|
327
|
-
return
|
|
324
|
+
return L(e) && e.result === !0;
|
|
328
325
|
}
|
|
329
326
|
function z(e) {
|
|
330
|
-
return
|
|
327
|
+
return S(e) && !!e.error;
|
|
331
328
|
}
|
|
332
329
|
function B(e) {
|
|
333
|
-
return
|
|
330
|
+
return S(e) && Object.keys(e).length === 1 && b(e.redirectURL);
|
|
334
331
|
}
|
|
335
332
|
function V(e) {
|
|
336
|
-
return
|
|
333
|
+
return R(e) && typeof e.userId == "number";
|
|
334
|
+
}
|
|
335
|
+
function H(e) {
|
|
336
|
+
return B(e) || z(e) || L(e) || S(e) ? e : {};
|
|
337
337
|
}
|
|
338
338
|
//#endregion
|
|
339
339
|
//#region src/spid-talk.ts
|
|
340
|
-
function
|
|
341
|
-
(!e.SPiD || typeof e.SPiD != "object") && (e.SPiD = {}), (!e.SPiD.Talk || typeof e.SPiD.Talk != "object") && (e.SPiD.Talk = {}),
|
|
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));
|
|
342
342
|
}
|
|
343
343
|
//#endregion
|
|
344
344
|
//#region src/types/login.ts
|
|
345
|
-
var
|
|
345
|
+
var W = (e) => typeof e.openSimplifiedLoginWidget == "function", G = "6.0.0-alpha.16", 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 {
|
|
346
346
|
eventTarget = new EventTarget();
|
|
347
347
|
window;
|
|
348
348
|
clientId;
|
|
@@ -351,6 +351,7 @@ var U = (e) => typeof e.openSimplifiedLoginWidget == "function", W = "6.0.0-alph
|
|
|
351
351
|
log;
|
|
352
352
|
callbackBeforeRedirect;
|
|
353
353
|
getConsents;
|
|
354
|
+
generateState;
|
|
354
355
|
sessionStorageCache;
|
|
355
356
|
localStorageCache;
|
|
356
357
|
enableSessionCaching;
|
|
@@ -366,44 +367,44 @@ var U = (e) => typeof e.openSimplifiedLoginWidget == "function", W = "6.0.0-alph
|
|
|
366
367
|
setVarnishCookie;
|
|
367
368
|
varnishExpiresIn;
|
|
368
369
|
varnishCookieDomain;
|
|
369
|
-
constructor({ clientId: t, redirectUri: n, sessionDomain: r, env: i, log: a, window: o =
|
|
370
|
-
|
|
371
|
-
let
|
|
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 = {
|
|
372
373
|
client_id: this.clientId,
|
|
373
374
|
redirect_uri: this.redirectUri
|
|
374
|
-
},
|
|
375
|
-
this.spid =
|
|
375
|
+
}, p = F(this.env, this.clientId);
|
|
376
|
+
this.spid = I({
|
|
376
377
|
serverUrl: A(i, l.SPiD),
|
|
377
378
|
log: this.log,
|
|
378
|
-
defaultParams:
|
|
379
|
-
}), this.oauthService =
|
|
379
|
+
defaultParams: f
|
|
380
|
+
}), this.oauthService = I({
|
|
380
381
|
serverUrl: A(i, l.SPiD),
|
|
381
382
|
log: this.log,
|
|
382
|
-
defaultParams:
|
|
383
|
-
}), this.bffService =
|
|
383
|
+
defaultParams: f
|
|
384
|
+
}), this.bffService = I({
|
|
384
385
|
serverUrl: A(i, l.BFF),
|
|
385
386
|
log: this.log,
|
|
386
|
-
defaultParams:
|
|
387
|
-
}), this.sessionService =
|
|
387
|
+
defaultParams: f
|
|
388
|
+
}), this.sessionService = I({
|
|
388
389
|
serverUrl: r,
|
|
389
390
|
log: this.log,
|
|
390
391
|
defaultParams: {
|
|
391
|
-
client_sdrn:
|
|
392
|
+
client_sdrn: p,
|
|
392
393
|
redirect_uri: this.redirectUri,
|
|
393
|
-
sdk_version:
|
|
394
|
+
sdk_version: G
|
|
394
395
|
}
|
|
395
|
-
}), this.globalSessionService =
|
|
396
|
+
}), this.globalSessionService = I({
|
|
396
397
|
serverUrl: A(i, l.SESSION_SERVICE),
|
|
397
398
|
log: this.log,
|
|
398
399
|
defaultParams: {
|
|
399
|
-
client_sdrn:
|
|
400
|
-
sdk_version:
|
|
400
|
+
client_sdrn: p,
|
|
401
|
+
sdk_version: G
|
|
401
402
|
}
|
|
402
403
|
}), this.usedSessionServiceGetSessionEndpoint = this.sessionService.url.pathname && this.sessionService.url.pathname.length <= 1 ? "v2/session" : "session", this._unblockSessionCall();
|
|
403
404
|
}
|
|
404
405
|
enableLoginLinkRefresh() {
|
|
405
406
|
let { document: e } = this.window;
|
|
406
|
-
e &&
|
|
407
|
+
e && T(e.addEventListener) && v(e, {
|
|
407
408
|
isLoginUrl: (e) => this.isLoginUrl(e),
|
|
408
409
|
getConsentParams: () => this.getConsentParams()
|
|
409
410
|
});
|
|
@@ -416,18 +417,18 @@ var U = (e) => typeof e.openSimplifiedLoginWidget == "function", W = "6.0.0-alph
|
|
|
416
417
|
}
|
|
417
418
|
_getTabId() {
|
|
418
419
|
if (this.enableSessionCaching) {
|
|
419
|
-
let e = this.sessionStorageCache.get(
|
|
420
|
-
return typeof e == "number" ? e : (this.sessionStorageCache.set(
|
|
420
|
+
let e = this.sessionStorageCache.get(J);
|
|
421
|
+
return typeof e == "number" ? e : (this.sessionStorageCache.set(J, Y, ce), Y);
|
|
421
422
|
}
|
|
422
423
|
}
|
|
423
424
|
_isSessionCallBlocked() {
|
|
424
|
-
return !!this.localStorageCache.get(
|
|
425
|
+
return !!this.localStorageCache.get(q);
|
|
425
426
|
}
|
|
426
427
|
_blockSessionCall() {
|
|
427
|
-
this.localStorageCache.set(
|
|
428
|
+
this.localStorageCache.set(q, !0, se);
|
|
428
429
|
}
|
|
429
430
|
_unblockSessionCall() {
|
|
430
|
-
this.localStorageCache.delete(
|
|
431
|
+
this.localStorageCache.delete(q);
|
|
431
432
|
}
|
|
432
433
|
_closePopup() {
|
|
433
434
|
this.popup &&= (this.popup.closed || this.popup.close(), null);
|
|
@@ -435,10 +436,10 @@ var U = (e) => typeof e.openSimplifiedLoginWidget == "function", W = "6.0.0-alph
|
|
|
435
436
|
enableVarnishCookie(e) {
|
|
436
437
|
if (typeof e != "object") throw new t("VarnishCookieOptions must be an object");
|
|
437
438
|
let { expiresIn: n = 0, domain: r } = e;
|
|
438
|
-
|
|
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;
|
|
439
440
|
}
|
|
440
441
|
_maybeSetVarnishCookie(e) {
|
|
441
|
-
if (!this.setVarnishCookie || !
|
|
442
|
+
if (!this.setVarnishCookie || !L(e)) return;
|
|
442
443
|
let t = /* @__PURE__ */ new Date();
|
|
443
444
|
if (this.varnishExpiresIn || typeof e.expiresIn == "number" && e.expiresIn > 0) {
|
|
444
445
|
let n = this.varnishExpiresIn || e.expiresIn || 0;
|
|
@@ -456,42 +457,42 @@ var U = (e) => typeof e.openSimplifiedLoginWidget == "function", W = "6.0.0-alph
|
|
|
456
457
|
this.setVarnishCookie && this._clearVarnishCookie();
|
|
457
458
|
}
|
|
458
459
|
_clearVarnishCookie() {
|
|
459
|
-
let e = this.session &&
|
|
460
|
+
let e = this.session && L(this.session) && typeof this.session.baseDomain == "string" ? this.session.baseDomain : this.window.location.hostname, t = this.varnishCookieDomain || e || "";
|
|
460
461
|
document.cookie = `SP_ID=nothing; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/; domain=.${t}`;
|
|
461
462
|
}
|
|
462
463
|
hasSession() {
|
|
463
464
|
if (this._isSessionCallBlocked()) {
|
|
464
|
-
let e =
|
|
465
|
-
return Promise.resolve(
|
|
465
|
+
let e = H(this.session);
|
|
466
|
+
return Promise.resolve(B(e) ? {} : e);
|
|
466
467
|
}
|
|
467
468
|
if (this.hasSessionInProgress) return this.hasSessionInProgress;
|
|
468
469
|
let n = !1, r = (r) => {
|
|
469
|
-
if (
|
|
470
|
-
return this._maybeSetVarnishCookie(r), n = (
|
|
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;
|
|
471
472
|
}, i = () => {
|
|
472
|
-
let e = this.sessionStorageCache.get(
|
|
473
|
-
return e ?
|
|
473
|
+
let e = this.sessionStorageCache.get(K);
|
|
474
|
+
return e ? H(e) : null;
|
|
474
475
|
}, a = async () => {
|
|
475
476
|
if (this.enableSessionCaching) {
|
|
476
477
|
let e = i();
|
|
477
|
-
if (e) return
|
|
478
|
+
if (e) return B(e) ? {} : r(e);
|
|
478
479
|
}
|
|
479
480
|
let e = null;
|
|
480
481
|
try {
|
|
481
|
-
e = await this.sessionService.get(this.usedSessionServiceGetSessionEndpoint, { tabId: this._getTabId() },
|
|
482
|
+
e = await this.sessionService.get(this.usedSessionServiceGetSessionEndpoint, { tabId: this._getTabId() }, H);
|
|
482
483
|
} catch (e) {
|
|
483
|
-
let t =
|
|
484
|
+
let t = S(e) ? e : void 0;
|
|
484
485
|
if (t?.code === 400 && this.enableSessionCaching) {
|
|
485
486
|
let n = 1e3 * (typeof t.expiresIn == "number" ? t.expiresIn : 300);
|
|
486
|
-
this.sessionStorageCache.set(
|
|
487
|
-
} else t && typeof t.code == "number" && t.code >= 500 && t.code < 600 && this.enableSessionCaching && this.sessionStorageCache.set(
|
|
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);
|
|
488
489
|
throw e;
|
|
489
490
|
}
|
|
490
491
|
if (e) {
|
|
491
|
-
if (
|
|
492
|
+
if (B(e)) return this._blockSessionCall(), await this.callbackBeforeRedirect(), this.sessionService.makeUrl(e.redirectURL, { tabId: this._getTabId() });
|
|
492
493
|
if (this.enableSessionCaching) {
|
|
493
|
-
let t = 1e3 * (
|
|
494
|
-
this.sessionStorageCache.set(
|
|
494
|
+
let t = 1e3 * (L(e) && e.expiresIn || 300);
|
|
495
|
+
this.sessionStorageCache.set(K, e, t);
|
|
495
496
|
}
|
|
496
497
|
}
|
|
497
498
|
return r(e ?? {});
|
|
@@ -502,7 +503,7 @@ var U = (e) => typeof e.openSimplifiedLoginWidget == "function", W = "6.0.0-alph
|
|
|
502
503
|
}
|
|
503
504
|
async isLoggedIn() {
|
|
504
505
|
try {
|
|
505
|
-
return
|
|
506
|
+
return L(await this.hasSession());
|
|
506
507
|
} catch {
|
|
507
508
|
return !1;
|
|
508
509
|
}
|
|
@@ -511,27 +512,27 @@ var U = (e) => typeof e.openSimplifiedLoginWidget == "function", W = "6.0.0-alph
|
|
|
511
512
|
this.enableSessionCaching = e;
|
|
512
513
|
}
|
|
513
514
|
clearCachedUserSession() {
|
|
514
|
-
this.sessionStorageCache.delete(
|
|
515
|
+
this.sessionStorageCache.delete(K);
|
|
515
516
|
}
|
|
516
517
|
async isConnected() {
|
|
517
518
|
try {
|
|
518
|
-
return
|
|
519
|
+
return R(await this.hasSession());
|
|
519
520
|
} catch {
|
|
520
521
|
return !1;
|
|
521
522
|
}
|
|
522
523
|
}
|
|
523
524
|
async getUser() {
|
|
524
525
|
let e = await this.hasSession();
|
|
525
|
-
if (!
|
|
526
|
-
return
|
|
526
|
+
if (!R(e)) throw new t("The user is not connected to this merchant");
|
|
527
|
+
return O(e);
|
|
527
528
|
}
|
|
528
529
|
async getUserId() {
|
|
529
530
|
let e = await this.hasSession();
|
|
530
|
-
if (
|
|
531
|
+
if (V(e)) return e.userId;
|
|
531
532
|
throw new t("The user is not connected to this merchant");
|
|
532
533
|
}
|
|
533
534
|
async getExternalId(e, n = "") {
|
|
534
|
-
let r = await this.hasSession(), i =
|
|
535
|
+
let r = await this.hasSession(), i = L(r) ? r.pairId : void 0;
|
|
535
536
|
if (!i) throw new t("pairId missing in user session!");
|
|
536
537
|
if (!e || e.length === 0) throw new t("externalParty cannot be empty");
|
|
537
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);
|
|
@@ -539,28 +540,28 @@ var U = (e) => typeof e.openSimplifiedLoginWidget == "function", W = "6.0.0-alph
|
|
|
539
540
|
}
|
|
540
541
|
async getUserSDRN() {
|
|
541
542
|
let e = await this.hasSession();
|
|
542
|
-
if (
|
|
543
|
+
if (L(e) && e.sdrn) return e.sdrn;
|
|
543
544
|
throw new t("Failed to get SDRN from user session");
|
|
544
545
|
}
|
|
545
546
|
async getUserUuid() {
|
|
546
547
|
let e = await this.hasSession();
|
|
547
|
-
if (
|
|
548
|
+
if (L(e) && e.uuid && e.result) return e.uuid;
|
|
548
549
|
throw new t("The user is not connected to this merchant");
|
|
549
550
|
}
|
|
550
551
|
async getUserContextData() {
|
|
551
552
|
try {
|
|
552
|
-
return await this.globalSessionService.get("user-context", void 0, (e) =>
|
|
553
|
+
return await this.globalSessionService.get("user-context", void 0, (e) => S(e) && b(e.identifier) ? {
|
|
553
554
|
identifier: e.identifier,
|
|
554
|
-
display_text:
|
|
555
|
-
client_name:
|
|
556
|
-
provider_id:
|
|
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
|
|
557
558
|
} : null);
|
|
558
559
|
} catch {
|
|
559
560
|
return null;
|
|
560
561
|
}
|
|
561
562
|
}
|
|
562
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 = "" }) {
|
|
563
|
-
this._closePopup(), this.sessionStorageCache.delete(
|
|
564
|
+
this._closePopup(), this.sessionStorageCache.delete(K);
|
|
564
565
|
let h = this.loginUrl({
|
|
565
566
|
state: e,
|
|
566
567
|
acrValues: t,
|
|
@@ -591,20 +592,20 @@ var U = (e) => typeof e.openSimplifiedLoginWidget == "function", W = "6.0.0-alph
|
|
|
591
592
|
async getSpId() {
|
|
592
593
|
try {
|
|
593
594
|
let e = await this.hasSession();
|
|
594
|
-
if (
|
|
595
|
-
let t =
|
|
596
|
-
return
|
|
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;
|
|
597
598
|
} catch {
|
|
598
599
|
return null;
|
|
599
600
|
}
|
|
600
601
|
}
|
|
601
602
|
logout(e = this.redirectUri) {
|
|
602
|
-
this.sessionStorageCache.delete(
|
|
603
|
+
this.sessionStorageCache.delete(K), this._maybeClearVarnishCookie();
|
|
603
604
|
let t = this.logoutUrl(e);
|
|
604
605
|
this.eventTarget.dispatchEvent(new CustomEvent("logoutRequested", { detail: { url: t } })), this.window.location.href = t;
|
|
605
606
|
}
|
|
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
|
|
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, [
|
|
608
609
|
"password",
|
|
609
610
|
"otp",
|
|
610
611
|
"sms",
|
|
@@ -613,7 +614,7 @@ var U = (e) => typeof e.openSimplifiedLoginWidget == "function", W = "6.0.0-alph
|
|
|
613
614
|
"eid-se",
|
|
614
615
|
"eid-fi",
|
|
615
616
|
"eid"
|
|
616
|
-
], !0)), `The acrValues parameter is not acceptable: ${t}`),
|
|
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", {
|
|
617
618
|
response_type: "code",
|
|
618
619
|
redirect_uri: r,
|
|
619
620
|
scope: n,
|
|
@@ -634,18 +635,18 @@ var U = (e) => typeof e.openSimplifiedLoginWidget == "function", W = "6.0.0-alph
|
|
|
634
635
|
getConsentParams() {
|
|
635
636
|
try {
|
|
636
637
|
let e = this.getConsents() || new URLSearchParams();
|
|
637
|
-
return
|
|
638
|
+
return y(e instanceof URLSearchParams, `getConsents must return URLSearchParams but it returned ${e}`), e;
|
|
638
639
|
} catch (e) {
|
|
639
640
|
return (this.log || console.warn)("Schibsted account SDK: could not read consents, logging in without them", e), new URLSearchParams();
|
|
640
641
|
}
|
|
641
642
|
}
|
|
642
643
|
isLoginUrl(e) {
|
|
643
|
-
if (!
|
|
644
|
+
if (!w(e)) return !1;
|
|
644
645
|
let t = new URL(e), n = new URL(this.oauthService.makeUrl("oauth/authorize", {}, !1));
|
|
645
646
|
return t.origin === n.origin && t.pathname === n.pathname && t.searchParams.get("client_id") === this.clientId;
|
|
646
647
|
}
|
|
647
648
|
logoutUrl(e = this.redirectUri) {
|
|
648
|
-
|
|
649
|
+
y(w(e), "logoutUrl(): redirectUri is invalid");
|
|
649
650
|
let t = { redirect_uri: e };
|
|
650
651
|
return this.sessionService.makeUrl("logout", t);
|
|
651
652
|
}
|
|
@@ -694,10 +695,10 @@ var U = (e) => typeof e.openSimplifiedLoginWidget == "function", W = "6.0.0-alph
|
|
|
694
695
|
}, f = () => {
|
|
695
696
|
this.eventTarget.dispatchEvent(new Event("simplifiedLoginCancelled"));
|
|
696
697
|
};
|
|
697
|
-
if (
|
|
698
|
+
if (W(window)) return window.openSimplifiedLoginWidget(c, l, u, d, f), i(!0);
|
|
698
699
|
let p = document.createElement("script");
|
|
699
700
|
p.type = "text/javascript", p.src = a, p.onload = () => {
|
|
700
|
-
if (!
|
|
701
|
+
if (!W(window)) {
|
|
701
702
|
s(new t("Error when loading simplified login widget content"));
|
|
702
703
|
return;
|
|
703
704
|
}
|
|
@@ -710,14 +711,14 @@ var U = (e) => typeof e.openSimplifiedLoginWidget == "function", W = "6.0.0-alph
|
|
|
710
711
|
};
|
|
711
712
|
//#endregion
|
|
712
713
|
//#region src/has-access-response.ts
|
|
713
|
-
function
|
|
714
|
-
if (!
|
|
714
|
+
function de(e) {
|
|
715
|
+
if (!S(e)) throw new t("Invalid hasAccess response");
|
|
715
716
|
let { entitled: n, ttl: r, allowedFeatures: i, userId: a, uuid: o, sig: s } = e;
|
|
716
|
-
if (typeof n != "boolean" || typeof r != "number" || !Array.isArray(i) || typeof a != "number" || !
|
|
717
|
+
if (typeof n != "boolean" || typeof r != "number" || !Array.isArray(i) || typeof a != "number" || !b(o) || !b(s)) throw new t("Invalid hasAccess response");
|
|
717
718
|
return {
|
|
718
719
|
entitled: n,
|
|
719
720
|
ttl: r,
|
|
720
|
-
allowedFeatures: i.filter(
|
|
721
|
+
allowedFeatures: i.filter(b),
|
|
721
722
|
userId: a,
|
|
722
723
|
uuid: o,
|
|
723
724
|
sig: s
|
|
@@ -725,19 +726,19 @@ function fe(e) {
|
|
|
725
726
|
}
|
|
726
727
|
//#endregion
|
|
727
728
|
//#region src/monetization.ts
|
|
728
|
-
var
|
|
729
|
+
var fe = () => window, pe = class {
|
|
729
730
|
cache;
|
|
730
731
|
sessionService;
|
|
731
732
|
pendingHasAccessRequests;
|
|
732
|
-
constructor({ clientId: e, redirectUri: t, env: n, sessionDomain: r, window: i =
|
|
733
|
-
|
|
734
|
-
let a =
|
|
735
|
-
this.cache = new s(() => i && i.sessionStorage), this.pendingHasAccessRequests = {}, r && (
|
|
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({
|
|
736
737
|
serverUrl: r,
|
|
737
738
|
defaultParams: {
|
|
738
739
|
client_sdrn: a,
|
|
739
740
|
redirect_uri: t,
|
|
740
|
-
sdk_version:
|
|
741
|
+
sdk_version: G
|
|
741
742
|
}
|
|
742
743
|
}));
|
|
743
744
|
}
|
|
@@ -747,7 +748,7 @@ var pe = () => window, Y = class {
|
|
|
747
748
|
if (!Array.isArray(e)) throw new t("'productIds' must be an array");
|
|
748
749
|
let r = [...e].sort(), i = this.accessCacheKey(r, n), a = this.cache.get(i);
|
|
749
750
|
if (!a) {
|
|
750
|
-
this.pendingHasAccessRequests[i] || (this.pendingHasAccessRequests[i] = this.sessionService.get(`/hasAccess/${r.join(",")}`, void 0,
|
|
751
|
+
this.pendingHasAccessRequests[i] || (this.pendingHasAccessRequests[i] = this.sessionService.get(`/hasAccess/${r.join(",")}`, void 0, de));
|
|
751
752
|
let e = this.pendingHasAccessRequests[i];
|
|
752
753
|
try {
|
|
753
754
|
a = await e;
|
|
@@ -776,23 +777,24 @@ var pe = () => window, Y = class {
|
|
|
776
777
|
let i = n(r.window);
|
|
777
778
|
if (!i) throw new t("Schibsted Account SDK is not available in this browser context");
|
|
778
779
|
if (i.schAccount) throw new t("Schibsted Account SDK has already been initialized");
|
|
779
|
-
let { log: a, callbackBeforeRedirect: o, getConsents: s,
|
|
780
|
+
let { log: a, callbackBeforeRedirect: o, getConsents: s, generateState: c, refreshLoginLinks: l = !0, defaultProductIds: u, varnish: d } = r, f = {
|
|
780
781
|
clientId: r.clientId,
|
|
781
782
|
redirectUri: r.redirectUri,
|
|
782
783
|
sessionDomain: r.sessionDomain,
|
|
783
784
|
env: r.env ?? "PRE",
|
|
784
785
|
window: i
|
|
785
786
|
};
|
|
786
|
-
if (
|
|
787
|
-
...
|
|
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,
|
|
788
789
|
log: a,
|
|
789
790
|
callbackBeforeRedirect: o,
|
|
790
|
-
getConsents: s
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
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 } }));
|
|
796
798
|
}
|
|
797
799
|
get clientId() {
|
|
798
800
|
return this.#e;
|
|
@@ -836,13 +838,13 @@ var pe = () => window, Y = class {
|
|
|
836
838
|
getSpId() {
|
|
837
839
|
return this.#i.getSpId();
|
|
838
840
|
}
|
|
839
|
-
login(e) {
|
|
841
|
+
login(e = {}) {
|
|
840
842
|
return this.#i.login(e);
|
|
841
843
|
}
|
|
842
844
|
logout(e) {
|
|
843
845
|
this.#i.logout(e);
|
|
844
846
|
}
|
|
845
|
-
loginUrl(e) {
|
|
847
|
+
loginUrl(e = {}) {
|
|
846
848
|
return this.#i.loginUrl(e);
|
|
847
849
|
}
|
|
848
850
|
logoutUrl(e) {
|
|
@@ -851,7 +853,7 @@ var pe = () => window, Y = class {
|
|
|
851
853
|
accountUrl(e) {
|
|
852
854
|
return this.#i.accountUrl(e);
|
|
853
855
|
}
|
|
854
|
-
showSimplifiedLoginWidget(e, t) {
|
|
856
|
+
showSimplifiedLoginWidget(e = {}, t) {
|
|
855
857
|
return this.#i.showSimplifiedLoginWidget(e, t);
|
|
856
858
|
}
|
|
857
859
|
setSessionCachingEnabled(e) {
|
|
@@ -899,6 +901,6 @@ function _e() {
|
|
|
899
901
|
}), $);
|
|
900
902
|
}
|
|
901
903
|
//#endregion
|
|
902
|
-
export { X as Account, t as SDKError, ge as createAccountSdk, _e as getAccountSdk,
|
|
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 };
|
|
903
905
|
|
|
904
906
|
//# sourceMappingURL=index.js.map
|