@seontechnologies/seon-id-verification
Version:
An advanced SDK for natural person identification through document scanning, facial recognition, designed for secure and efficient user verification.
2 lines (1 loc) • 8.84 kB
JavaScript
(function(m,v){typeof exports=="object"&&typeof module<"u"?v(exports):typeof define=="function"&&define.amd?define(["exports"],v):(m=typeof globalThis<"u"?globalThis:m||self,v(m.index={}))})(this,function(m){"use strict";var F=Object.defineProperty;var j=(m,v,b)=>v in m?F(m,v,{enumerable:!0,configurable:!0,writable:!0,value:b}):m[v]=b;var x=(m,v,b)=>j(m,typeof v!="symbol"?v+"":v,b);function v(h){return h&&h.__esModule&&Object.prototype.hasOwnProperty.call(h,"default")?h.default:h}var b={exports:{}},A;function S(){return A||(A=1,function(h){var g=Object.prototype.hasOwnProperty,a="~";function c(){}Object.create&&(c.prototype=Object.create(null),new c().__proto__||(a=!1));function u(i,e,r){this.fn=i,this.context=e,this.once=r||!1}function y(i,e,r,o,d){if(typeof r!="function")throw new TypeError("The listener must be a function");var t=new u(r,o||i,d),l=a?a+e:e;return i._events[l]?i._events[l].fn?i._events[l]=[i._events[l],t]:i._events[l].push(t):(i._events[l]=t,i._eventsCount++),i}function p(i,e){--i._eventsCount===0?i._events=new c:delete i._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)g.call(r,o)&&e.push(a?o.slice(1):o);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(r)):e},n.prototype.listeners=function(e){var r=a?a+e:e,o=this._events[r];if(!o)return[];if(o.fn)return[o.fn];for(var d=0,t=o.length,l=new Array(t);d<t;d++)l[d]=o[d].fn;return l},n.prototype.listenerCount=function(e){var r=a?a+e:e,o=this._events[r];return o?o.fn?1:o.length:0},n.prototype.emit=function(e,r,o,d,t,l){var w=a?a+e:e;if(!this._events[w])return!1;var s=this._events[w],E=arguments.length,I,f;if(s.fn){switch(s.once&&this.removeListener(e,s.fn,void 0,!0),E){case 1:return s.fn.call(s.context),!0;case 2:return s.fn.call(s.context,r),!0;case 3:return s.fn.call(s.context,r,o),!0;case 4:return s.fn.call(s.context,r,o,d),!0;case 5:return s.fn.call(s.context,r,o,d,t),!0;case 6:return s.fn.call(s.context,r,o,d,t,l),!0}for(f=1,I=new Array(E-1);f<E;f++)I[f-1]=arguments[f];s.fn.apply(s.context,I)}else{var R=s.length,_;for(f=0;f<R;f++)switch(s[f].once&&this.removeListener(e,s[f].fn,void 0,!0),E){case 1:s[f].fn.call(s[f].context);break;case 2:s[f].fn.call(s[f].context,r);break;case 3:s[f].fn.call(s[f].context,r,o);break;case 4:s[f].fn.call(s[f].context,r,o,d);break;default:if(!I)for(_=1,I=new Array(E-1);_<E;_++)I[_-1]=arguments[_];s[f].fn.apply(s[f].context,I)}}return!0},n.prototype.on=function(e,r,o){return y(this,e,r,o,!1)},n.prototype.once=function(e,r,o){return y(this,e,r,o,!0)},n.prototype.removeListener=function(e,r,o,d){var t=a?a+e:e;if(!this._events[t])return this;if(!r)return p(this,t),this;var l=this._events[t];if(l.fn)l.fn===r&&(!d||l.once)&&(!o||l.context===o)&&p(this,t);else{for(var w=0,s=[],E=l.length;w<E;w++)(l[w].fn!==r||d&&!l[w].once||o&&l[w].context!==o)&&s.push(l[w]);s.length?this._events[t]=s.length===1?s[0]:s:p(this,t)}return this},n.prototype.removeAllListeners=function(e){var r;return e?(r=a?a+e:e,this._events[r]&&p(this,r)):(this._events=new c,this._eventsCount=0),this},n.prototype.off=n.prototype.removeListener,n.prototype.addListener=n.prototype.on,n.prefixed=a,n.EventEmitter=n,h.exports=n}(b)),b.exports}var O=S();const L=v(O),C=(h,g,a)=>{try{const c=new URL(h);return c.searchParams.set(g,a),c.toString()}catch{const u=h.includes("?")?"&":"?";return`${h}${u}${encodeURIComponent(g)}=${encodeURIComponent(a)}`}},$=h=>C(h,"iframe-flow","true"),D=(h,g)=>C(h,"always-transfer-from-desktop",g.toString()),T=(h,g)=>C(h,"country-iso-code",g);class k extends L{constructor(){super();x(this,"configuration",null);x(this,"isRunning",!1);x(this,"iframeCleanup",null)}initialize(a){if(this.isRunning)throw new Error("IDV flow is already running.");this.configuration=a}async start(a){var y;if(this.isRunning)throw new Error("IDV flow is already running.");if(a&&(this.configuration=a),console.log("Start IDV flow",this.configuration),!this.configuration)throw new Error("Configuration is not set.");let{targetUrl:c}=await this.createIDVSession();const u=this.configuration.seon_test_iframe_url_override;if(u){const p=new URL(c),n=new URL(u);p.protocol=n.protocol,p.host=n.host,c=p.toString()}c=$(c),this.configuration.alwaysTransferFromDesktop&&(c=D(c,this.configuration.alwaysTransferFromDesktop)),(y=this.configuration.customerData)!=null&&y.countryISOCode&&(c=T(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:a,licenseKey:c,language:u,customerData:y,alwaysTransferFromDesktop:p,...n}=this.configuration,{countryISOCode:i,...e}=y||{},r="/sessions/flow/start-session-v1",o={platform:"WEB",language:u||"en",...n,...e,supportedCaptureSdks:["blink-capture","blinkID"],apiVersion:2,sdkVersion:"2.0.0"},d=await fetch(`${a}${r}`,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":c},body:JSON.stringify(o)});if(!d.ok)throw new Error(`Failed to create IDV session: ${d.status} ${d.statusText}`);const t=await d.json();if(!t||!t.targetUrl)throw new Error("Invalid response from IDV session creation.");return{targetUrl:t.targetUrl}}doRenderIframe({targetUrl:a}){if(!this.configuration)throw new Error("Session is not initialized.");const c=new URL(a).origin;let u=null;const y=this.configuration.renderingMode||"fullscreen",p=n=>{if(!u||n.source!==u||typeof n.data!="object"||n.data===null)return;const{event:i,eventData:e}=n.data;typeof i=="string"&&this.emit(i,e),["cancelled","completed"].includes(i)&&this.close()};if(y==="inline"){const n=this.configuration.containerId;if(!n)throw new Error("Container ID is required for inline rendering.");const i=document.getElementById(n);if(!i)throw new Error(`Container element with id '${n}' not found.`);i.innerHTML="";const e=document.createElement("iframe");e.src=a,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"),i.appendChild(e),u=e.contentWindow,window.addEventListener("message",p),this.iframeCleanup=()=>{i.removeChild(e),window.removeEventListener("message",p)}}else if(y==="fullscreen"){const n=document.createElement("iframe");n.src=a,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 i=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=>{i.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,d=document.documentElement.style.overflow;document.body.style.overflow="hidden",document.documentElement.style.overflow="hidden",document.body.appendChild(n),u=n.contentWindow,window.addEventListener("message",p),this.iframeCleanup=()=>{clearInterval(r),document.body.removeChild(n),window.removeEventListener("message",p),document.body.style.overflow=o,document.documentElement.style.overflow=d,i.forEach(t=>{const l=t.getAttribute("data-prevTabIndex"),w=t.getAttribute("data-prevAriaHidden");l?t.setAttribute("tabindex",l):t.removeAttribute("tabindex"),w?t.setAttribute("aria-hidden",w):t.removeAttribute("aria-hidden"),t.removeAttribute("data-prevTabIndex"),t.removeAttribute("data-prevAriaHidden")})}}else if(y==="popup"){const e=window.screenX+(window.outerWidth-800)/2,r=window.screenY+(window.outerHeight-600)/2;if(u=window.open(a,"seon-idv-popup",`width=800,height=600,left=${e},top=${r},resizable,scrollbars`),!u)throw new Error("Failed to open popup window. Please allow popups and try again.");window.addEventListener("message",p);const o=setInterval(()=>{u!=null&&u.closed&&(clearInterval(o),console.log("Popup closed by user."),this.emit("cancelled"),this.close())},500);this.iframeCleanup=()=>{clearInterval(o),u&&!u.closed&&u.close(),window.removeEventListener("message",p)}}else throw new Error("Invalid rendering mode specified.")}close(){var a;this.isRunning=!1,(a=this.iframeCleanup)==null||a.call(this),this.emit("closed")}}const V=new k,P={commitHash:"530ddb9",version:"2.0.0"};m.SeonIdVerification=V,m.SeonIdVerificationVersion=P,Object.defineProperties(m,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});