UNPKG

@seontechnologies/seon-id-verification

Version:

An advanced SDK for natural person identification through document scanning, facial recognition, designed for secure and efficient user verification.

293 lines (292 loc) 11.6 kB
var A = Object.defineProperty; var S = (l, p, i) => p in l ? A(l, p, { enumerable: !0, configurable: !0, writable: !0, value: i }) : l[p] = i; var E = (l, p, i) => S(l, typeof p != "symbol" ? p + "" : p, i); function O(l) { return l && l.__esModule && Object.prototype.hasOwnProperty.call(l, "default") ? l.default : l; } var I = { exports: {} }, x; function L() { return x || (x = 1, function(l) { var p = Object.prototype.hasOwnProperty, i = "~"; function c() { } Object.create && (c.prototype = /* @__PURE__ */ Object.create(null), new c().__proto__ || (i = !1)); function d(s, e, r) { this.fn = s, this.context = e, this.once = r || !1; } function v(s, e, r, o, f) { if (typeof r != "function") throw new TypeError("The listener must be a function"); var t = new d(r, o || s, f), u = i ? i + e : e; return s._events[u] ? s._events[u].fn ? s._events[u] = [s._events[u], t] : s._events[u].push(t) : (s._events[u] = t, s._eventsCount++), s; } function m(s, e) { --s._eventsCount === 0 ? s._events = new c() : delete s._events[e]; } function n() { this._events = new c(), this._eventsCount = 0; } n.prototype.eventNames = function() { var e = [], r, o; if (this._eventsCount === 0) return e; for (o in r = this._events) p.call(r, o) && e.push(i ? o.slice(1) : o); return Object.getOwnPropertySymbols ? e.concat(Object.getOwnPropertySymbols(r)) : e; }, n.prototype.listeners = function(e) { var r = i ? i + e : e, o = this._events[r]; if (!o) return []; if (o.fn) return [o.fn]; for (var f = 0, t = o.length, u = new Array(t); f < t; f++) u[f] = o[f].fn; return u; }, n.prototype.listenerCount = function(e) { var r = i ? i + e : e, o = this._events[r]; return o ? o.fn ? 1 : o.length : 0; }, n.prototype.emit = function(e, r, o, f, t, u) { var w = i ? i + e : e; if (!this._events[w]) return !1; var a = this._events[w], g = arguments.length, y, h; if (a.fn) { switch (a.once && this.removeListener(e, a.fn, void 0, !0), g) { case 1: return a.fn.call(a.context), !0; case 2: return a.fn.call(a.context, r), !0; case 3: return a.fn.call(a.context, r, o), !0; case 4: return a.fn.call(a.context, r, o, f), !0; case 5: return a.fn.call(a.context, r, o, f, t), !0; case 6: return a.fn.call(a.context, r, o, f, t, u), !0; } for (h = 1, y = new Array(g - 1); h < g; h++) y[h - 1] = arguments[h]; a.fn.apply(a.context, y); } else { var C = a.length, b; for (h = 0; h < C; h++) switch (a[h].once && this.removeListener(e, a[h].fn, void 0, !0), g) { case 1: a[h].fn.call(a[h].context); break; case 2: a[h].fn.call(a[h].context, r); break; case 3: a[h].fn.call(a[h].context, r, o); break; case 4: a[h].fn.call(a[h].context, r, o, f); break; default: if (!y) for (b = 1, y = new Array(g - 1); b < g; b++) y[b - 1] = arguments[b]; a[h].fn.apply(a[h].context, y); } } return !0; }, n.prototype.on = function(e, r, o) { return v(this, e, r, o, !1); }, n.prototype.once = function(e, r, o) { return v(this, e, r, o, !0); }, n.prototype.removeListener = function(e, r, o, f) { var t = i ? i + e : e; if (!this._events[t]) return this; if (!r) return m(this, t), this; var u = this._events[t]; if (u.fn) u.fn === r && (!f || u.once) && (!o || u.context === o) && m(this, t); else { for (var w = 0, a = [], g = u.length; w < g; w++) (u[w].fn !== r || f && !u[w].once || o && u[w].context !== o) && a.push(u[w]); a.length ? this._events[t] = a.length === 1 ? a[0] : a : m(this, t); } return this; }, n.prototype.removeAllListeners = function(e) { var r; return e ? (r = i ? i + e : e, this._events[r] && m(this, r)) : (this._events = new c(), this._eventsCount = 0), this; }, n.prototype.off = n.prototype.removeListener, n.prototype.addListener = n.prototype.on, n.prefixed = i, n.EventEmitter = n, l.exports = n; }(I)), I.exports; } var $ = L(); const D = /* @__PURE__ */ O($), _ = (l, p, i) => { try { const c = new URL(l); return c.searchParams.set(p, i), c.toString(); } catch { const d = l.includes("?") ? "&" : "?"; return `${l}${d}${encodeURIComponent(p)}=${encodeURIComponent(i)}`; } }, k = (l) => _(l, "iframe-flow", "true"), T = (l, p) => _( l, "always-transfer-from-desktop", p.toString() ), R = (l, p) => _(l, "country-iso-code", p); class P extends D { constructor() { super(); E(this, "configuration", null); E(this, "isRunning", !1); E(this, "iframeCleanup", null); } initialize(i) { if (this.isRunning) throw new Error("IDV flow is already running."); this.configuration = i; } async start(i) { var v; if (this.isRunning) throw new Error("IDV flow is already running."); if (i && (this.configuration = i), console.log("Start IDV flow", this.configuration), !this.configuration) throw new Error("Configuration is not set."); let { targetUrl: c } = await this.createIDVSession(); const d = this.configuration.seon_test_iframe_url_override; if (d) { const m = new URL(c), n = new URL(d); m.protocol = n.protocol, m.host = n.host, c = m.toString(); } c = k(c), this.configuration.alwaysTransferFromDesktop && (c = T( c, this.configuration.alwaysTransferFromDesktop )), (v = this.configuration.customerData) != null && v.countryISOCode && (c = R( c, this.configuration.customerData.countryISOCode )), this.isRunning = !0, this.doRenderIframe({ targetUrl: c }), this.emit("opened"); } async createIDVSession() { if (!this.configuration) throw new Error("Session is not initialized."); const { baseUrl: i, licenseKey: c, language: d, customerData: v, alwaysTransferFromDesktop: m, ...n } = this.configuration, { countryISOCode: s, ...e } = v || {}, r = "/sessions/flow/start-session-v1", o = { platform: "WEB", language: d || "en", ...n, ...e, supportedCaptureSdks: ["blink-capture", "blinkID"], apiVersion: 2, sdkVersion: "2.0.0" }, f = await fetch(`${i}${r}`, { method: "POST", headers: { "Content-Type": "application/json", "x-api-key": c }, body: JSON.stringify(o) }); if (!f.ok) throw new Error( `Failed to create IDV session: ${f.status} ${f.statusText}` ); const t = await f.json(); if (!t || !t.targetUrl) throw new Error("Invalid response from IDV session creation."); return { targetUrl: t.targetUrl }; } doRenderIframe({ targetUrl: i }) { if (!this.configuration) throw new Error("Session is not initialized."); const c = new URL(i).origin; let d = null; const v = this.configuration.renderingMode || "fullscreen", m = (n) => { if (!d || n.source !== d || typeof n.data != "object" || n.data === null) return; const { event: s, eventData: e } = n.data; typeof s == "string" && this.emit(s, e), ["cancelled", "completed"].includes(s) && this.close(); }; if (v === "inline") { const n = this.configuration.containerId; if (!n) throw new Error("Container ID is required for inline rendering."); const s = document.getElementById(n); if (!s) throw new Error( `Container element with id '${n}' not found.` ); s.innerHTML = ""; const e = document.createElement("iframe"); e.src = i, e.style.display = "block", e.style.width = "100%", e.style.height = "100%", e.style.border = "none", e.allow = `camera ${c}; microphone ${c}; clipboard-write ${c}`, e.setAttribute("data-testid", "seon-idv-iframe"), s.appendChild(e), d = e.contentWindow, window.addEventListener("message", m), this.iframeCleanup = () => { s.removeChild(e), window.removeEventListener("message", m); }; } else if (v === "fullscreen") { const n = document.createElement("iframe"); n.src = i, n.allow = `camera ${c}; microphone ${c}; clipboard-write ${c}`, n.setAttribute("data-testid", "seon-idv-iframe"), Object.assign(n.style, { position: "fixed", top: "0", left: "0", width: "100%", height: "100%", backgroundColor: "rgba(0, 0, 0, 0.8)", border: "none", display: "block", zIndex: "2147483647" }); let s = /* @__PURE__ */ new Set(); const e = () => { Array.from( document.querySelectorAll( "a[href], button, input, select, textarea, [tabindex]" ) ).filter((t) => !t.hasAttribute("disabled") && t.getAttribute("tabindex") !== "-1").forEach((t) => { s.add(t), t.setAttribute( "data-prevTabIndex", t.getAttribute("tabindex") || "" ), t.setAttribute( "data-prevAriaHidden", t.getAttribute("aria-hidden") || "" ), t.setAttribute("tabindex", "-1"), t.setAttribute("aria-hidden", "true"); }); }; e(); const r = setInterval(() => { e(); }, 3e3), o = document.body.style.overflow, f = document.documentElement.style.overflow; document.body.style.overflow = "hidden", document.documentElement.style.overflow = "hidden", document.body.appendChild(n), d = n.contentWindow, window.addEventListener("message", m), this.iframeCleanup = () => { clearInterval(r), document.body.removeChild(n), window.removeEventListener("message", m), document.body.style.overflow = o, document.documentElement.style.overflow = f, s.forEach((t) => { const u = t.getAttribute("data-prevTabIndex"), w = t.getAttribute("data-prevAriaHidden"); u ? t.setAttribute("tabindex", u) : t.removeAttribute("tabindex"), w ? t.setAttribute("aria-hidden", w) : t.removeAttribute("aria-hidden"), t.removeAttribute("data-prevTabIndex"), t.removeAttribute("data-prevAriaHidden"); }); }; } else if (v === "popup") { const e = window.screenX + (window.outerWidth - 800) / 2, r = window.screenY + (window.outerHeight - 600) / 2; if (d = window.open( i, "seon-idv-popup", `width=800,height=600,left=${e},top=${r},resizable,scrollbars` ), !d) throw new Error( "Failed to open popup window. Please allow popups and try again." ); window.addEventListener("message", m); const o = setInterval(() => { d != null && d.closed && (clearInterval(o), console.log("Popup closed by user."), this.emit("cancelled"), this.close()); }, 500); this.iframeCleanup = () => { clearInterval(o), d && !d.closed && d.close(), window.removeEventListener("message", m); }; } else throw new Error("Invalid rendering mode specified."); } close() { var i; this.isRunning = !1, (i = this.iframeCleanup) == null || i.call(this), this.emit("closed"); } } const F = new P(), H = { commitHash: "530ddb9", version: "2.0.0" }; export { F as SeonIdVerification, H as SeonIdVerificationVersion };