@sumsub/fisherman
Version:
The Sumsub Fisherman is a powerful tool that helps developers integrate fraud detection capabilities into their applications. With Fisherman, you can easily identify and prevent fraudulent activities within your system, providing a safer and more secure e
809 lines (808 loc) • 24.2 kB
JavaScript
import C from "fingerprintjs2";
import Le from "detectincognitojs";
function ue() {
return Date.now();
}
function ke() {
return (/* @__PURE__ */ new Date()).toISOString();
}
const Fe = "crypto" in window && "randomUUID" in window.crypto;
function Me() {
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (e) => {
const t = Math.random() * 16 | 0;
return (e === "x" ? t : t & 3 | 8).toString(16);
});
}
function Ce() {
return Fe ? crypto.randomUUID() : Me();
}
const Be = {
type: "InvalidToken",
message: "Token is invalid, make sure you generate a new one each time, because the old ones are invalidated upon usage"
}, le = {
type: "NoToken",
message: "Authentication token is required to send requests"
}, qe = {
type: "UpdateTokenRetriesLimitReached",
message: "Token renewal failed after multiple attempts (limit reached). Request aborted to prevent infinite retry loop."
}, Ke = {
type: "NetworkError",
message: "Failed to connect to the server. Possible network or CORS configuration issue."
}, Ve = {
type: "FpDisabled",
message: "You are trying to use FP, which is not enabled for you."
}, $e = {
type: "FpClientTimeout",
message: "Device visitorId calc timeout"
}, je = {
type: "FpRateLimit",
message: "FP request rate limit is exceeded"
}, $ = 0;
async function z({ payload: e, token: t, url: n, onload: o }) {
try {
const r = await fetch(n, {
method: "POST",
body: JSON.stringify(e),
headers: {
"Content-Type": "application/json",
"X-Client-Id": "fisherman",
...t ? { "X-Access-Token": t } : {}
}
});
o(r.status, e);
} catch {
o($, e);
}
}
const He = 2e3, Ge = 3, We = atob("aHR0cHM6Ly9jb2NrcGl0LnN1bXN1Yi5jb20="), Xe = Math.random().toString(36).substring(0, 8), de = `/resources/bhv/evts/${Xe}`, fe = "/resources/di/req";
let h, j, pe, b, y, K, H, J = de, Q = fe, V = 0;
function Ye(e) {
h = e, x(h.token);
}
function ze(e) {
e && (J = e);
}
function Je(e) {
e && (Q = e);
}
function Qe() {
ge(), pe = void 0, x(void 0), j = void 0, J = de, Q = fe;
}
async function P(e, t) {
return await et(
Ze(
e,
{
fpRequestId: t == null ? void 0 : t.fpRequestId,
fpVisitorId: t == null ? void 0 : t.fpVisitorId,
fpSimulation: t == null ? void 0 : t.fpSimulation
},
t == null ? void 0 : t.behavioralDataEnabled
)
);
}
function Ze(e, t = {}, n = !0) {
e.capturedAt = ke();
const o = Ce(), r = "deviceFingerprint" in e || !n, i = {
id: o,
predecessorEventId: j,
deviceSessionId: pe,
...t,
[r ? "initData" : "interactionData"]: e
};
return j = o, i;
}
async function et(e, t) {
y === void 0 && (y = []), !K && e.initData ? (K = !0, y.unshift(e)) : y.push(e), K && (H || (H = setTimeout(tt, He)));
}
function ge() {
y = void 0, H = void 0;
}
async function tt() {
if (y != null && y.length && b) {
const e = [...y];
ge(), await Re(e);
}
}
function B() {
return h.baseUrl !== void 0 ? h.baseUrl : We;
}
async function nt() {
if (h.accessTokenUpdateHandler) {
const e = await h.accessTokenUpdateHandler();
x(e);
}
}
async function Re(e) {
return b ? z({
payload: e,
token: b,
url: `${B()}${J}`,
onload: (t, n) => Ee(t, () => Re(n))
}) : (I(le), Promise.resolve());
}
async function Z(e) {
return b ? z({
payload: e,
token: b,
url: `${B()}${Q}`,
onload: (t, n) => Ee(t, () => Z(n))
}) : (I(le), Promise.resolve());
}
async function Ee(e, t) {
if (e === 401 || e === $) {
let n = V >= Ge;
!n && h.accessTokenUpdateHandler ? (V++, await nt(), await t()) : x(void 0);
let o;
e === $ ? o = Ke : n ? o = qe : o = Be, I(o);
} else e == 200 && (V = 0);
}
function I(e) {
const t = {
errorType: "fishermanError",
errorName: e.type,
message: e.message
};
h.disabledErrorLogging || z({
payload: t,
token: b,
url: `${B()}/resources/serviceLogger/warn`,
onload: () => {
}
}), h.onError && h.onError(e);
}
function x(e) {
b = e;
}
const ve = "focus";
let k, ie = 0;
function rt() {
k = () => {
ie++, P({
event: "focus",
count: ie
});
}, window.addEventListener(ve, k);
}
function ot() {
k && window.removeEventListener(ve, k);
}
function it(e) {
if (e.target instanceof Element) {
const t = e.target, n = t.getAttribute("type"), o = n ? `[${n}]` : "", r = t.id ? `#${t.id}` : "";
return `${t.tagName}${o}${r}`;
}
}
const at = [
// Modifier keys
"Alt",
"Control",
"Meta",
"Shift",
// Whitespace keys
"Enter",
"Tab",
// Navigation keys
"ArrowDown",
"ArrowLeft",
"ArrowRight",
"ArrowUp",
"End",
"Home",
// Editing keys
"Backspace",
"Delete",
// UI keys
"Escape"
];
function st(e) {
if (at.includes(e))
return e;
}
function me(e) {
return e instanceof Element;
}
const ct = typeof window.WeakMap == "function", A = ct ? /* @__PURE__ */ new WeakMap() : void 0;
function ut(e) {
return A == null ? void 0 : A.get(e);
}
function lt(e, t) {
A == null || A.set(e, t);
}
const dt = ["type", "autocomplete", "autofocus", "placeholder", "aria-label"];
function ft(e) {
const t = e.parentNode, n = e.tagName;
if (t) {
const o = Array.from(t.childNodes).filter(
(r) => me(r) && n === r.tagName
);
if (o.length > 1) {
const r = o.indexOf(e);
if (r > -1)
return `:nth-of-type(${r + 1})`;
}
}
return "";
}
function pt(e) {
const t = e.id ? `#${e.id}` : "", n = ft(e), o = dt.map((r) => {
if (e.hasAttribute(r)) {
const i = e.getAttribute(r);
return `[${i ? `${r}="${i}"` : r}]`;
}
}).filter(Boolean).join("");
return (
// INPUT
e.tagName + // #id
t + // :nth-of-type(2)
n + // [type="email"][autocomplete="email"][autofocus][aria-label="Email or username"]
o
);
}
function gt(e) {
const t = [e];
let n = e;
for (; n.parentElement; ) {
const r = n.parentElement;
t.push(r), n = r;
}
const o = t.reverse().map(pt).join(" > ");
return C.x64hash128(o, 31);
}
function Rt(e) {
if (me(e.target)) {
const t = e.target;
let n = ut(t);
return n || (n = gt(t), lt(t, n)), n;
}
}
const he = ["keydown", "keyup"], ye = ["mousemove", "mousedown"], we = ["paste", "focusin", "change", ...ye, ...he];
let E, v;
function Ie() {
E = /* @__PURE__ */ new Map(), v = [];
}
function Et(e) {
let t;
return e.type === "change" && (v && (v == null ? void 0 : v.length) > 0 && (t = v), Ie()), t;
}
function vt({ key: e }) {
E && E.get(e) === void 0 && E.set(e, ue());
}
function mt({ key: e }) {
const t = E == null ? void 0 : E.get(e);
if (E && t) {
v === void 0 && (v = []), E.delete(e);
const n = { start: t, end: ue() }, o = st(e);
o && (n.key = o), v.push(n);
}
}
function ee(e) {
const t = e.type;
if (t === "keydown" ? vt(e) : t === "keyup" && mt(e), !he.includes(t)) {
const n = {
event: t,
trusted: e.isTrusted,
el: it(e),
elUid: Rt(e),
cadence: Et(e)
};
P(n);
}
ye.includes(t) && document.removeEventListener(t, ee);
}
function ht() {
Ie(), we.forEach((e) => document.addEventListener(e, ee));
}
function yt() {
we.forEach((e) => document.removeEventListener(e, ee)), E = void 0, v = void 0;
}
const Oe = "deviceorientation";
let S;
function wt(e) {
const t = e.alpha !== null ? e.alpha : 0, n = e.beta !== null ? e.beta : 0, o = e.gamma !== null ? e.gamma : 0, r = Math.abs(n) > Math.abs(o) ? "portrait" : "landscape";
return {
alpha: t,
beta: n,
gamma: o,
orientation: r
};
}
async function It() {
if (!S) {
const e = "DeviceOrientationEvent" in window;
return e && (S = (t) => {
P({
event: "orientation",
orientation: wt(t)
}), Te();
}, window.addEventListener(Oe, S)), {
supported: e
};
}
}
function Te() {
S && (window.removeEventListener(Oe, S), S = void 0);
}
const Ot = "not available", Tt = [
"userAgent",
"webdriver",
"language",
"colorDepth",
"deviceMemory",
"pixelRatio",
"hardwareConcurrency",
"timezoneOffset",
"timezone",
"sessionStorage",
"localStorage",
"indexedDb",
"openDatabase",
"platform",
"doNotTrack",
"plugins",
"canvas",
"webgl",
"webglVendorAndRenderer",
"adBlock",
"hasLiedOs",
"hasLiedBrowser",
"touchSupport",
"fonts",
"audio"
], G = 200, _t = (e, t) => {
switch (e) {
case "touchSupport":
return St(t);
case "plugins":
return At(t);
case "webgl":
case "canvas":
return Dt(t);
default:
return bt(t);
}
}, bt = (e) => typeof e == "string" ? _e(e) : Array.isArray(e) ? Nt(e) : e, _e = (e) => e.length > G ? be(e) : e, Nt = (e) => ((e == null ? void 0 : e.length) > G && e.splice(0, G), e.map((t) => typeof t == "string" ? _e(t) : t)), At = (e) => {
if (Array.isArray(e) && e.length > 0)
return e.map((t) => Array.isArray(t) ? t[0] : "");
}, St = (e) => {
if ((e == null ? void 0 : e.length) === 3)
try {
return {
maxTouchPoints: Number(e[0]),
touchEvent: !!e[1],
touchStart: !!e[2]
};
} catch {
return;
}
}, be = (e) => C.x64hash128(e, 31), Dt = (e) => {
if (e)
return be(e.toString());
}, Ut = 500;
async function ae(e) {
const t = await xt(), n = [];
t.forEach(({ key: o, value: r }) => {
if (n.push(r), Tt.includes(o) && r !== Ot) {
const i = _t(o, r);
i !== void 0 && (e[o] = i);
}
}), e.deviceFingerprint = C.x64hash128(n.join(""), 31);
}
async function Pt(e) {
return new Promise((t, n) => {
typeof window.requestIdleCallback == "function" ? requestIdleCallback(async () => {
t(await ae(e));
}) : setTimeout(async () => {
t(await ae(e));
}, Ut);
});
}
function xt() {
return new Promise((e) => C.get(e));
}
function L() {
return navigator instanceof window.Navigator;
}
async function Lt(e) {
var t;
return !!(L() && typeof ((t = navigator.permissions) == null ? void 0 : t.query) == "function" && (await navigator.permissions.query({ name: e })).state === "granted");
}
async function kt() {
return new Promise((e) => {
navigator.geolocation.getCurrentPosition(
(t) => {
const n = t.coords.latitude, o = t.coords.longitude;
e(`${n}:${o}`);
},
() => {
e("unknown");
}
);
});
}
async function Ft() {
const e = await Lt("geolocation"), t = {
permissionGranted: e
};
return L() && e && navigator.geolocation && (t.location = await kt()), t;
}
async function Mt() {
if (L() && "getBattery" in navigator && typeof navigator.getBattery == "function") {
const e = await navigator.getBattery();
if (e)
return {
level: e.level,
charging: e.charging
};
}
}
async function Ct() {
var e;
if (L() && typeof ((e = navigator.mediaDevices) == null ? void 0 : e.enumerateDevices) == "function")
return (await navigator.mediaDevices.enumerateDevices()).map(({ kind: n, label: o, deviceId: r, groupId: i }) => ({
kind: n,
// "|| undefined" to eliminate empty strings
label: o || void 0,
deviceId: r || void 0,
groupId: i || void 0
}));
}
function Bt() {
let e;
try {
throw "a";
} catch (t) {
try {
t.toSource(), e = !0;
} catch {
e = !1;
}
}
return e;
}
const qt = "notDetected";
async function Kt() {
try {
return await Le();
} catch {
return {
browserName: qt
};
}
}
async function Vt() {
var d;
const e = {}, { width: t, height: n, availWidth: o, availHeight: r } = window.screen;
e.width = t, e.height = n, e.availableWidth = o, e.availableHeight = r, await Pt(e);
const i = await Kt();
if (e.browser = i.browserName, e.incognito = i.isPrivate, L() && "userAgentData" in navigator) {
const a = navigator.userAgentData;
e.mobile = a == null ? void 0 : a.mobile;
}
(d = navigator.languages) != null && d.length && (e.languages = [...navigator.languages]), e.geolocation = await Ft();
const u = await Mt();
u && (e.battery = u);
const l = await Ct();
l && (e.mediaDevices = l);
const c = await It();
c && (e.orientation = c), e.oscpu = navigator.oscpu, e.productSub = navigator.productSub, e.evalLength = eval.toString().length, e.errFirefox = Bt(), P(e);
}
const Ne = "navigate";
let U, W;
var ce;
const $t = typeof ((ce = window.navigation) == null ? void 0 : ce.addEventListener) == "function";
function jt() {
var e;
$t && (U = () => {
const t = Gt();
t !== W && (W = t, P({ event: "urlchanged" }));
}, (e = window.navigation) == null || e.addEventListener(Ne, U));
}
function Ht() {
var e;
U && ((e = window.navigation) == null || e.removeEventListener(Ne, U), U = void 0, W = void 0);
}
function Gt() {
return window.location.href;
}
var F = function() {
return F = Object.assign || function(t) {
for (var n, o = 1, r = arguments.length; o < r; o++) {
n = arguments[o];
for (var i in n) Object.prototype.hasOwnProperty.call(n, i) && (t[i] = n[i]);
}
return t;
}, F.apply(this, arguments);
};
function Wt(e, t) {
var n = {};
for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && t.indexOf(o) < 0 && (n[o] = e[o]);
if (e != null && typeof Object.getOwnPropertySymbols == "function")
for (var r = 0, o = Object.getOwnPropertySymbols(e); r < o.length; r++)
t.indexOf(o[r]) < 0 && Object.prototype.propertyIsEnumerable.call(e, o[r]) && (n[o[r]] = e[o[r]]);
return n;
}
function Xt(e, t, n) {
if (n || arguments.length === 2) for (var o = 0, r = t.length, i; o < r; o++)
(i || !(o in t)) && (i || (i = Array.prototype.slice.call(t, 0, o)), i[o] = t[o]);
return e.concat(i || Array.prototype.slice.call(t));
}
function Yt(e, t) {
return function(n, o) {
return Object.prototype.hasOwnProperty.call(n, o);
}(e, t) ? e[t] : void 0;
}
function zt(e, t, n, o) {
var r, i = document, u = "securitypolicyviolation", l = function(d) {
var a = new URL(e, location.href), s = d.blockedURI;
s !== a.href && s !== a.protocol.slice(0, -1) && s !== a.origin || (r = d, c());
};
i.addEventListener(u, l);
var c = function() {
return i.removeEventListener(u, l);
};
return Promise.resolve().then(t).then(function(d) {
return c(), d;
}, function(d) {
return new Promise(function(a) {
var s = new MessageChannel();
s.port1.onmessage = function() {
return a();
}, s.port2.postMessage(null);
}).then(function() {
if (c(), r) return n(r);
throw d;
});
});
}
var Jt = { default: "endpoint" }, Qt = { default: "tlsEndpoint" }, Zt = "Client timeout", en = "Network connection error", tn = "Network request aborted", nn = "Response cannot be parsed", te = "Blocked by CSP", ne = "The endpoint parameter is not a valid URL";
function w(e) {
for (var t = "", n = 0; n < e.length; ++n) if (n > 0) {
var o = e[n].toLowerCase();
o !== e[n] ? t += " ".concat(o) : t += e[n];
} else t += e[n].toUpperCase();
return t;
}
var rn = /* @__PURE__ */ w("WrongRegion"), on = /* @__PURE__ */ w("SubscriptionNotActive"), an = /* @__PURE__ */ w("UnsupportedVersion"), sn = /* @__PURE__ */ w("InstallationMethodRestricted"), cn = /* @__PURE__ */ w("HostnameRestricted"), un = /* @__PURE__ */ w("IntegrationFailed"), ln = /* @__PURE__ */ w("NetworkRestricted"), dn = /* @__PURE__ */ w("InvalidProxyIntegrationSecret"), fn = /* @__PURE__ */ w("InvalidProxyIntegrationHeaders"), re = "API key required", Ae = "API key not found", Se = "API key expired", pn = "Request cannot be parsed", gn = "Request failed", Rn = "Request failed to process", En = "Too many requests, rate limit exceeded", vn = "Not available for this origin", mn = "Not available with restricted header", hn = re, yn = Ae, wn = Se, In = "3.11.11", q = "Failed to load the JS script of the agent", oe = "9319";
function On(e, t) {
var n, o, r, i, u, l, c, d = [], a = (n = function(g) {
var p = Xt([], g, !0);
return { current: function() {
return p[0];
}, postpone: function() {
var f = p.shift();
f !== void 0 && p.push(f);
}, exclude: function() {
p.shift();
} };
}(e), i = 100, u = 3e3, l = 0, o = function() {
return Math.random() * Math.min(u, i * Math.pow(2, l++));
}, r = /* @__PURE__ */ new Set(), [n.current(), function(g, p) {
var f, R = p instanceof Error ? p.message : "";
if (R === te || R === ne) n.exclude(), f = 0;
else if (R === oe) n.exclude();
else if (R === q) {
var N = Date.now() - g.getTime() < 50, _ = n.current();
_ && N && !r.has(_) && (r.add(_), f = 0), n.postpone();
} else n.postpone();
var D = n.current();
return D === void 0 ? void 0 : [D, f ?? g.getTime() + o() - Date.now()];
}]), s = a[0], O = a[1];
if (s === void 0) return Promise.reject(new TypeError("The list of script URL patterns is empty"));
var T = function(g) {
var p = /* @__PURE__ */ new Date(), f = function(N) {
return d.push({ url: g, startedAt: p, finishedAt: /* @__PURE__ */ new Date(), error: N });
}, R = t(g);
return R.then(function() {
return f();
}, f), R.catch(function(N) {
if (c != null || (c = N), d.length >= 5) throw c;
var _ = O(p, N);
if (!_) throw c;
var D, Ue = _[0], Pe = _[1];
return (D = Pe, new Promise(function(xe) {
return setTimeout(xe, D);
})).then(function() {
return T(Ue);
});
});
};
return T(s).then(function(g) {
return [g, d];
});
}
var De = "https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js", Tn = De;
function _n(e) {
var t;
e.scriptUrlPattern;
var n = e.token, o = e.apiKey, r = o === void 0 ? n : o, i = Wt(e, ["scriptUrlPattern", "token", "apiKey"]), u = (t = Yt(e, "scriptUrlPattern")) !== null && t !== void 0 ? t : De, l = function() {
var a = [], s = function() {
a.push({ time: /* @__PURE__ */ new Date(), state: document.visibilityState });
}, O = function(T, g, p, f) {
return T.addEventListener(g, p, f), function() {
return T.removeEventListener(g, p, f);
};
}(document, "visibilitychange", s);
return s(), [a, O];
}(), c = l[0], d = l[1];
return Promise.resolve().then(function() {
if (!r || typeof r != "string") throw new Error(re);
var a = function(s, O) {
return (Array.isArray(s) ? s : [s]).map(function(T) {
return function(g, p) {
var f = encodeURIComponent;
return g.replace(/<[^<>]+>/g, function(R) {
return R === "<version>" ? "3" : R === "<apiKey>" ? f(p) : R === "<loaderVersion>" ? f(In) : R;
});
}(String(T), O);
});
}(u, r);
return On(a, bn);
}).catch(function(a) {
throw d(), function(s) {
return s instanceof Error && s.message === oe ? new Error(q) : s;
}(a);
}).then(function(a) {
var s = a[0], O = a[1];
return d(), s.load(F(F({}, i), { ldi: { attempts: O, visibilityStates: c } }));
});
}
function bn(e) {
return zt(e, function() {
return function(t) {
return new Promise(function(n, o) {
if (function(l) {
if (URL.prototype) try {
return new URL(l, location.href), !1;
} catch (c) {
if (c instanceof Error && c.name === "TypeError") return !0;
throw c;
}
}(t)) throw new Error(ne);
var r = document.createElement("script"), i = function() {
var l;
return (l = r.parentNode) === null || l === void 0 ? void 0 : l.removeChild(r);
}, u = document.head || document.getElementsByTagName("head")[0];
r.onload = function() {
i(), n();
}, r.onerror = function() {
i(), o(new Error(q));
}, r.async = !0, r.src = t, u.appendChild(r);
});
}(e);
}, function() {
throw new Error(te);
}).then(Nn);
}
function Nn() {
var e = window, t = "__fpjs_p_l_b", n = e[t];
if (function(o, r) {
var i, u = (i = Object.getOwnPropertyDescriptor) === null || i === void 0 ? void 0 : i.call(Object, o, r);
u != null && u.configurable ? delete o[r] : u && !u.writable || (o[r] = void 0);
}(e, t), typeof (n == null ? void 0 : n.load) != "function") throw new Error(oe);
return n;
}
var X = { load: _n, defaultScriptUrlPattern: Tn, ERROR_SCRIPT_LOAD_FAIL: q, ERROR_API_KEY_EXPIRED: Se, ERROR_API_KEY_INVALID: Ae, ERROR_API_KEY_MISSING: re, ERROR_BAD_REQUEST_FORMAT: pn, ERROR_BAD_RESPONSE_FORMAT: nn, ERROR_CLIENT_TIMEOUT: Zt, ERROR_CSP_BLOCK: te, ERROR_FORBIDDEN_ENDPOINT: cn, ERROR_FORBIDDEN_HEADER: mn, ERROR_FORBIDDEN_ORIGIN: vn, ERROR_GENERAL_SERVER_FAILURE: gn, ERROR_INSTALLATION_METHOD_RESTRICTED: sn, ERROR_INTEGRATION_FAILURE: un, ERROR_INVALID_ENDPOINT: ne, ERROR_INVALID_PROXY_INTEGRATION_HEADERS: fn, ERROR_INVALID_PROXY_INTEGRATION_SECRET: dn, ERROR_NETWORK_ABORT: tn, ERROR_NETWORK_CONNECTION: en, ERROR_NETWORK_RESTRICTED: ln, ERROR_RATE_LIMIT: En, ERROR_SERVER_TIMEOUT: Rn, ERROR_SUBSCRIPTION_NOT_ACTIVE: on, ERROR_TOKEN_EXPIRED: wn, ERROR_TOKEN_INVALID: yn, ERROR_TOKEN_MISSING: hn, ERROR_UNSUPPORTED_VERSION: an, ERROR_WRONG_REGION: rn, defaultEndpoint: Jt, defaultTlsEndpoint: Qt };
async function An(e, t) {
const n = `${t}/resources/di/info`;
return fetch(n, {
headers: {
"Content-Type": "application/json",
"X-Access-Token": e,
"X-Client-Id": "fisherman"
}
}).then((o) => {
if (o.status !== 204)
return o.json();
});
}
const Sn = "https://fpmetrics.sumsub.com";
let M, m;
async function Dn(e, t) {
let n, o, r;
try {
r = await An(e, B());
} catch (c) {
I({ type: "LoadFpConfigError", message: c.message });
}
const i = (r == null ? void 0 : r.fpUrl) || Sn, u = !!(r != null && r.bhvEnabled);
if (n = r == null ? void 0 : r.evRelUrl, o = r == null ? void 0 : r.fpReqRelUrl, r != null && r.fpKey)
try {
M = await X.load({
apiKey: r.fpKey,
scriptUrlPattern: `${i}/web/v<version>/<apiKey>/loader_v<loaderVersion>.js`,
endpoint: i,
region: "eu"
});
} catch (c) {
I({ type: "FpInitError", message: c.message });
}
return t ? m = {
enabled: !0,
conf: t
} : r != null && r.simulation && (m = r.simulation), { isDeviceIntelligenceEnabled: !!(r != null && r.fpKey || m), behavioralDataEnabled: u, eventsRelUrl: n, fpReqRelUrl: o };
}
async function Un(e) {
if (m)
return await Pn();
let t, n;
if (M) {
let o;
try {
o = await M.get({
timeout: 3e4,
linkedId: e == null ? void 0 : e.linkedId
});
} catch (r) {
let i;
switch (r.message) {
case X.ERROR_CLIENT_TIMEOUT:
i = $e;
break;
case X.ERROR_RATE_LIMIT:
i = je;
break;
default:
i = { type: "OtherFpError", message: r.message };
}
I(i);
}
t = o == null ? void 0 : o.visitorId, n = o == null ? void 0 : o.requestId, await Z({
fpVisitorId: t,
fpRequestId: n
});
} else
I(Ve);
return { visitorId: t };
}
async function Pn() {
var n, o;
const e = { visitorId: (n = m == null ? void 0 : m.conf) == null ? void 0 : n.visitorId };
if (!m)
return e;
const t = { ...m };
if (!((o = t.conf) != null && o.requestId)) {
const r = `simulated-${Math.random().toString(36).substring(2, 10)}`;
t.conf = {
...t.conf,
requestId: r
};
}
try {
await Z({
fpSimulation: t
});
} catch (r) {
I({ type: "SimulationError", message: r.message });
}
return e;
}
const xn = () => {
M = void 0, m = void 0;
};
let Y, se = !1;
async function Fn(e) {
let t = !1;
if (!Y) {
Y = !0, Ye(e);
const n = await Dn(e.token, e.simulationConfig);
t = n.isDeviceIntelligenceEnabled, se = n.behavioralDataEnabled, ze(n.eventsRelUrl), Je(n.fpReqRelUrl), se && (await Vt(), rt(), jt(), ht());
}
return {
isDeviceIntelligenceEnabled: t,
async fingerprint(n) {
return Un(n);
}
};
}
function Mn() {
Te(), ot(), Ht(), yt(), Qe(), xn(), Y = !1;
}
function Cn(e) {
x(e);
}
export {
Mn as destroy,
Fn as init,
Cn as updateAccessToken
};