user-verification
Version:
OTP verification SDK for web applications
3 lines (2 loc) • 24.6 kB
JavaScript
"use strict";function e(e,t,n,r,o,i,a){try{var s=e[i](a),d=s.value}catch(e){return void n(e)}s.done?t(d):Promise.resolve(d).then(r,o)}function t(t){return function(){var n=this,r=arguments;return new Promise((function(o,i){var a=t.apply(n,r);function s(t){e(a,o,i,s,d,"next",t)}function d(t){e(a,o,i,s,d,"throw",t)}s(void 0)}))}}function n(){n=function(){return t};var e,t={},r=Object.prototype,o=r.hasOwnProperty,i=Object.defineProperty||function(e,t,n){e[t]=n.value},a="function"==typeof Symbol?Symbol:{},s=a.iterator||"@@iterator",d=a.asyncIterator||"@@asyncIterator",c=a.toStringTag||"@@toStringTag";function l(e,t,n){return Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{l({},"")}catch(e){l=function(e,t,n){return e[t]=n}}function u(e,t,n,r){var o=Object.create((t&&t.prototype instanceof g?t:g).prototype),a=new C(r||[]);return i(o,"_invoke",{value:T(e,n,a)}),o}function p(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}t.wrap=u;var v="suspendedStart",f="executing",h="completed",y={};function g(){}function b(){}function x(){}var m={};l(m,s,(function(){return this}));var w=Object.getPrototypeOf,k=w&&w(w(P([])));k&&k!==r&&o.call(k,s)&&(m=k);var F=x.prototype=g.prototype=Object.create(m);function E(e){["next","throw","return"].forEach((function(t){l(e,t,(function(e){return this._invoke(t,e)}))}))}function S(e,t){function n(r,i,a,s){var d=p(e[r],e,i);if("throw"!==d.type){var c=d.arg,l=c.value;return l&&"object"==typeof l&&o.call(l,"__await")?t.resolve(l.__await).then((function(e){n("next",e,a,s)}),(function(e){n("throw",e,a,s)})):t.resolve(l).then((function(e){c.value=e,a(c)}),(function(e){return n("throw",e,a,s)}))}s(d.arg)}var r;i(this,"_invoke",{value:function(e,o){function i(){return new t((function(t,r){n(e,o,t,r)}))}return r=r?r.then(i,i):i()}})}function T(t,n,r){var o=v;return function(i,a){if(o===f)throw Error("Generator is already running");if(o===h){if("throw"===i)throw a;return{value:e,done:!0}}for(r.method=i,r.arg=a;;){var s=r.delegate;if(s){var d=B(s,r);if(d){if(d===y)continue;return d}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(o===v)throw o=h,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);o=f;var c=p(t,n,r);if("normal"===c.type){if(o=r.done?h:"suspendedYield",c.arg===y)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(o=h,r.method="throw",r.arg=c.arg)}}}function B(t,n){var r=n.method,o=t.iterator[r];if(o===e)return n.delegate=null,"throw"===r&&t.iterator.return&&(n.method="return",n.arg=e,B(t,n),"throw"===n.method)||"return"!==r&&(n.method="throw",n.arg=new TypeError("The iterator does not provide a '"+r+"' method")),y;var i=p(o,t.iterator,n.arg);if("throw"===i.type)return n.method="throw",n.arg=i.arg,n.delegate=null,y;var a=i.arg;return a?a.done?(n[t.resultName]=a.value,n.next=t.nextLoc,"return"!==n.method&&(n.method="next",n.arg=e),n.delegate=null,y):a:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,y)}function L(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function O(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function C(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(L,this),this.reset(!0)}function P(t){if(t||""===t){var n=t[s];if(n)return n.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var r=-1,i=function n(){for(;++r<t.length;)if(o.call(t,r))return n.value=t[r],n.done=!1,n;return n.value=e,n.done=!0,n};return i.next=i}}throw new TypeError(typeof t+" is not iterable")}return b.prototype=x,i(F,"constructor",{value:x,configurable:!0}),i(x,"constructor",{value:b,configurable:!0}),b.displayName=l(x,c,"GeneratorFunction"),t.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===b||"GeneratorFunction"===(t.displayName||t.name))},t.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,x):(e.__proto__=x,l(e,c,"GeneratorFunction")),e.prototype=Object.create(F),e},t.awrap=function(e){return{__await:e}},E(S.prototype),l(S.prototype,d,(function(){return this})),t.AsyncIterator=S,t.async=function(e,n,r,o,i){void 0===i&&(i=Promise);var a=new S(u(e,n,r,o),i);return t.isGeneratorFunction(n)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},E(F),l(F,c,"Generator"),l(F,s,(function(){return this})),l(F,"toString",(function(){return"[object Generator]"})),t.keys=function(e){var t=Object(e),n=[];for(var r in t)n.push(r);return n.reverse(),function e(){for(;n.length;){var r=n.pop();if(r in t)return e.value=r,e.done=!1,e}return e.done=!0,e}},t.values=P,C.prototype={constructor:C,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(O),!t)for(var n in this)"t"===n.charAt(0)&&o.call(this,n)&&!isNaN(+n.slice(1))&&(this[n]=e)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var n=this;function r(r,o){return s.type="throw",s.arg=t,n.next=r,o&&(n.method="next",n.arg=e),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],s=a.completion;if("root"===a.tryLoc)return r("end");if(a.tryLoc<=this.prev){var d=o.call(a,"catchLoc"),c=o.call(a,"finallyLoc");if(d&&c){if(this.prev<a.catchLoc)return r(a.catchLoc,!0);if(this.prev<a.finallyLoc)return r(a.finallyLoc)}else if(d){if(this.prev<a.catchLoc)return r(a.catchLoc,!0)}else{if(!c)throw Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return r(a.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var r=this.tryEntries[n];if(r.tryLoc<=this.prev&&o.call(r,"finallyLoc")&&this.prev<r.finallyLoc){var i=r;break}}i&&("break"===e||"continue"===e)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=e,a.arg=t,i?(this.method="next",this.next=i.finallyLoc,y):this.complete(a)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),y},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),O(n),y}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var o=r.arg;O(n)}return o}}throw Error("illegal catch attempt")},delegateYield:function(t,n,r){return this.delegate={iterator:P(t),resultName:n,nextLoc:r},"next"===this.method&&(this.arg=e),y}},t}var r="dev-otp-dialog",o=new(function(){function e(){var e=this;this.generateStylesCSS=function(){var t,n,r,o,i,a,s,d,c,l,u,p,v,f,h,y,g,b,x,m,w,k,F,E,S,T,B,L,O,C,P,j,R,I,q,A,z,N,_,M,V,D,G,J,Y,U,H;return"\n "+(e.styles?"\n .dev-otp-input-group {\n position: relative;\n display: flex;\n align-items: center;\n gap: 8px;\n width: 100%;\n }\n .dev-otp-input-group input {\n flex: 1;\n }\n .verify-button {\n background: "+((null==(t=e.styles.verifyButton)?void 0:t.background)||"#cc14ff")+";\n color: "+((null==(n=e.styles.verifyButton)?void 0:n.color)||"#FFFFFF")+";\n padding: "+((null==(r=e.styles.verifyButton)?void 0:r.padding)||"8px 16px")+";\n border-radius: "+((null==(o=e.styles.verifyButton)?void 0:o.borderRadius)||"4px")+";\n border: "+((null==(i=e.styles.verifyButton)?void 0:i.border)||"none")+";\n cursor: pointer;\n display: none;\n width: auto !important;\n }\n .verify-button.visible {\n display: inline-block;\n }\n .success-mark {\n color: "+((null==(a=e.styles.successMark)?void 0:a.color)||"#1dc11a")+";\n font-size: "+((null==(s=e.styles.successMark)?void 0:s.fontSize)||"20px")+";\n margin-left: "+((null==(d=e.styles.successMark)?void 0:d.marginLeft)||"8px")+";\n display: none;\n width: auto;\n line-height: 1;\n }\n .success-mark.visible {\n display: inline-block; \n }\n ":"")+"\n #dev-otp-dialog {\n padding: "+((null==(c=e.styles.dialog)?void 0:c.padding)||"20px")+";\n border-radius: "+((null==(l=e.styles.dialog)?void 0:l.borderRadius)||"8px")+";\n border: "+((null==(u=e.styles.dialog)?void 0:u.border)||"none")+";\n box-shadow: "+((null==(p=e.styles.dialog)?void 0:p.boxShadow)||"0 2px 8px rgba(0, 0, 0, 0.2)")+";\n background: "+((null==(v=e.styles.dialog)?void 0:v.background)||"#FFFFFF")+";\n }\n #dev-otp-dialog::backdrop {\n background: "+((null==(f=e.styles.dialog)?void 0:f.backdrop)||"rgba(0, 0, 0, 0.5)")+";\n }\n #dev-otp-input {\n padding: "+((null==(h=e.styles.input)?void 0:h.padding)||"8px")+";\n font-size: "+((null==(y=e.styles.input)?void 0:y.fontSize)||"16px")+";\n border: "+((null==(g=e.styles.input)?void 0:g.border)||"1px solid #ccc")+";\n border-radius: "+((null==(b=e.styles.input)?void 0:b.borderRadius)||"4px")+";\n margin-bottom: 12px;\n width: 100%;\n box-sizing: border-box;\n color: "+((null==(x=e.styles.input)?void 0:x.color)||"#353a40")+";\n background: "+((null==(m=e.styles.input)?void 0:m.background)||"#F9FAFB")+";\n }\n #dev-otp-verify {\n background: "+((null==(w=e.styles.verifyButton)?void 0:w.background)||"#cc14ff")+";\n color: "+((null==(k=e.styles.verifyButton)?void 0:k.color)||"#FFFFFF")+";\n padding: "+((null==(F=e.styles.verifyButton)?void 0:F.padding)||"8px 16px")+";\n border-radius: "+((null==(E=e.styles.verifyButton)?void 0:E.borderRadius)||"4px")+";\n border: "+((null==(S=e.styles.verifyButton)?void 0:S.border)||"none")+";\n cursor: pointer;\n margin-right: 8px;\n }\n #dev-otp-cancel {\n background: "+((null==(T=e.styles.cancelButton)?void 0:T.background)||"#FFFFFF")+";\n color: "+((null==(B=e.styles.cancelButton)?void 0:B.color)||"#1dc11a")+";\n padding: "+((null==(L=e.styles.cancelButton)?void 0:L.padding)||"8px 16px")+";\n border-radius: "+((null==(O=e.styles.cancelButton)?void 0:O.borderRadius)||"4px")+";\n border: "+((null==(C=e.styles.cancelButton)?void 0:C.border)||"1px solid #1dc11a")+";\n cursor: pointer;\n }\n #dev-otp-resend {\n background: "+((null==(P=e.styles.resendButton)?void 0:P.background)||"#F9FAFB")+";\n color: "+((null==(j=e.styles.resendButton)?void 0:j.color)||"#4B5563")+";\n padding: "+((null==(R=e.styles.resendButton)?void 0:R.padding)||"8px 16px")+";\n border-radius: "+((null==(I=e.styles.resendButton)?void 0:I.borderRadius)||"4px")+";\n border: "+((null==(q=e.styles.resendButton)?void 0:q.border)||"1px solid #4B5563")+";\n cursor: pointer;\n margin-top: 12px;\n width: 100%;\n }\n #dev-otp-resend:disabled {\n opacity: 0.7;\n cursor: not-allowed;\n }\n #dev-otp-error {\n color: "+((null==(A=e.styles.errorMessage)?void 0:A.color)||"#EF4444")+";\n font-size: "+((null==(z=e.styles.errorMessage)?void 0:z.fontSize)||"14px")+";\n margin-top: "+((null==(N=e.styles.errorMessage)?void 0:N.marginTop)||"8px")+";\n text-align: "+((null==(_=e.styles.errorMessage)?void 0:_.textAlign)||"center")+";\n display: none;\n }\n .dev-otp-resend {\n margin-top: 12px;\n text-align: center;\n }\n .dev-otp-timer {\n margin-bottom: 8px;\n color: "+(e.styles.text||"#353a40")+";\n font-size: 14px;\n }\n #dev-otp-countdown {\n font-weight: bold;\n color: "+(e.styles.text||"#353a40")+";\n }\n .verify-button {\n background: "+((null==(M=e.styles.verifyButton)?void 0:M.background)||"#cc14ff")+";\n color: "+((null==(V=e.styles.verifyButton)?void 0:V.color)||"#FFFFFF")+";\n padding: "+((null==(D=e.styles.verifyButton)?void 0:D.padding)||"8px 16px")+";\n border-radius: "+((null==(G=e.styles.verifyButton)?void 0:G.borderRadius)||"4px")+";\n border: "+((null==(J=e.styles.verifyButton)?void 0:J.border)||"none")+";\n cursor: pointer;\n display: none;\n }\n .verify-button.visible {\n display: inline-block;\n }\n .success-mark {\n color: "+((null==(Y=e.styles.successMark)?void 0:Y.color)||"#1dc11a")+";\n font-size: "+((null==(U=e.styles.successMark)?void 0:U.fontSize)||"20px")+";\n margin-left: "+((null==(H=e.styles.successMark)?void 0:H.marginLeft)||"8px")+";\n display: none;\n }\n .success-mark.visible {\n display: inline-block;\n }\n "},this.createDialog=function(){if(!e.styles)throw new Error("Theme styles not initialized");var t=document.getElementById(r);t&&t.remove();var n=document.createElement("dialog");n.id=r,n.innerHTML='\n <div class="dev-otp-content">\n <h2>Enter OTP</h2>\n <p>'+("email"===e.verificationType?"Please enter the verification code sent to your email":"Please enter the verification code sent to your phone")+'</p>\n <input type="text" id="dev-otp-input" maxlength="6" placeholder="Enter OTP">\n <div id="dev-otp-error"></div>\n <div class="dev-otp-buttons">\n <button id="dev-otp-verify">Verify</button>\n <button id="dev-otp-cancel">Cancel</button>\n </div>\n <div class="dev-otp-resend">\n <div class="dev-otp-timer">You can resend OTP in <span id="dev-otp-countdown"></span></div>\n <button id="dev-otp-resend">Resend OTP</button>\n </div>\n </div>\n ';var o=document.createElement("style");o.setAttribute("data-for",r),o.textContent=e.generateStylesCSS();var i=document.head.querySelector('style[data-for="'+r+'"]');return i&&i.remove(),document.head.appendChild(o),document.body.appendChild(n),e.dialog=n,n.querySelector("#dev-otp-verify").addEventListener("click",e.handleOTPVerification),n.querySelector("#dev-otp-cancel").addEventListener("click",(function(){e.hideError(),e.dialog.close()})),n.querySelector("#dev-otp-resend").addEventListener("click",e.handleResendOTP),n.querySelector("#dev-otp-input").addEventListener("input",(function(){e.hideError()})),n},this.startResendTimer=function(){var t=e.dialog.querySelector("#dev-otp-resend"),n=e.dialog.querySelector("#dev-otp-countdown"),r=e.dialog.querySelector(".dev-otp-timer"),o=30;e.resendTimer&&clearInterval(e.resendTimer),t.disabled=!0,t.textContent="Resend OTP";var i=function(){var e=Math.floor(o/60);n.textContent=e+":"+String(o%60).padStart(2,"0")};i(),r.style.display="block",e.resendTimer=setInterval((function(){--o<=0?(clearInterval(e.resendTimer),t.disabled=!1,r.style.display="none"):i()}),1e3)},this.showError=function(t){var n=e.dialog.querySelector("#dev-otp-error");n.textContent=t,n.style.display="block"},this.hideError=function(){e.dialog.querySelector("#dev-otp-error").style.display="none"},this.init=function(){var r=t(n().mark((function t(r){var o,i,a,s,d,c,l,u,p;return n().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,e.siteId=r,t.next=4,e.fetchThemeConfig();case 4:if(e.styles=t.sent,o=document.querySelector('[data-devotp="email"]'),i=document.querySelector('[data-devotp="phone"]'),o||i){t.next=9;break}throw new Error('No verification inputs found with data-devotp="email" or data-devotp="phone"');case 9:o&&(o.closest(".dev-otp-input-group")?console.log("Email verification already initialized, skipping"):((a=document.createElement("div")).className="dev-otp-input-group",o.parentNode.insertBefore(a,o),a.appendChild(o),(s=document.createElement("button")).setAttribute("data-devotp","verify-button"),s.classList.add("verify-button"),s.textContent="Verify Email",a.appendChild(s),(d=document.createElement("span")).className="success-mark",d.textContent="✓",a.appendChild(d),o.addEventListener("input",(function(e){var t=e.target.value.includes("@")&&e.target.value.includes(".");s.classList.toggle("visible",t),d.classList.remove("visible")})),s.addEventListener("click",(function(t){e.handleVerifyClick(t,"email")})))),i&&(i.closest(".dev-otp-input-group")?console.log("Phone verification already initialized, skipping"):((c=document.createElement("div")).className="dev-otp-input-group",i.parentNode.insertBefore(c,i),c.appendChild(i),(l=document.createElement("button")).setAttribute("data-devotp","verify-button"),l.classList.add("verify-button"),l.textContent="Verify Phone",c.appendChild(l),(u=document.createElement("span")).className="success-mark",u.textContent="✓",c.appendChild(u),i.addEventListener("input",(function(e){var t=/^\d{10,}$/.test(e.target.value.replace(/\D/g,""));l.classList.toggle("visible",t),u.classList.remove("visible")})),l.addEventListener("click",(function(t){e.handleVerifyClick(t,"phone")})))),document.addEventListener("dev-otp-verified",(function(t){if(t.detail.verified){var n=document.querySelector('[data-devotp="'+e.verificationType+'"]'),r=null==n?void 0:n.closest(".dev-otp-input-group"),o=null==r?void 0:r.querySelector(".success-mark"),i=null==r?void 0:r.querySelector(".verify-button");i&&o&&(i.classList.remove("visible"),o.classList.add("visible"))}})),(p=document.createElement("style")).textContent=e.generateStylesCSS(),document.head.appendChild(p),t.next=21;break;case 17:throw t.prev=17,t.t0=t.catch(0),e.printError(t.t0.message),t.t0;case 21:case"end":return t.stop()}}),t,null,[[0,17]])})));return function(e){return r.apply(this,arguments)}}(),this.printError=function(e){console.error("VERIFICATION SDK Error: "+e)},this.handleVerifyClick=function(){var r=t(n().mark((function t(r,o){var i,a,s,d,c;return n().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r.preventDefault(),i=document.querySelector('[data-devotp="'+o+'"]'),a=null==i?void 0:i.value){t.next=6;break}return e.printError(o.charAt(0).toUpperCase()+o.slice(1)+" is required"),t.abrupt("return");case 6:return e.verificationType=o,e.identifier=a,t.prev=8,e.dialog||e.createDialog(),t.next=12,fetch("https://user-verification-tawny.vercel.app/api/send-otp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({siteId:e.siteId,identifier:a,type:o})});case 12:if((d=t.sent).ok){t.next=19;break}return t.next=16,d.text();case 16:throw console.error("Error Response:",t.sent),new Error("Failed to send OTP");case 19:return t.next=21,d.json();case 21:(c=t.sent)&&(e.jwt=c.token),null==(s=e.dialog)||s.showModal(),e.startResendTimer(),t.next=30;break;case 27:t.prev=27,t.t0=t.catch(8),e.printError(t.t0 instanceof Error?t.t0.message:"An unknown error occurred");case 30:case"end":return t.stop()}}),t,null,[[8,27]])})));return function(e,t){return r.apply(this,arguments)}}(),this.handleResendOTP=t(n().mark((function t(){var r,o,i,a;return n().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,fetch("https://user-verification-tawny.vercel.app/api/resend-otp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({verification_token:e.jwt})});case 3:if((r=t.sent).ok){t.next=20;break}if(400!==r.status){t.next=17;break}return t.next=8,fetch("https://user-verification-tawny.vercel.app/api/resend-otp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({siteId:e.siteId,identifier:e.identifier,type:e.verificationType})});case 8:if((o=t.sent).ok){t.next=11;break}throw new Error("Failed to resend OTP");case 11:return t.next=13,o.json();case 13:(i=t.sent)&&(e.jwt=i.token),t.next=18;break;case 17:throw new Error("Failed to resend OTP");case 18:t.next=24;break;case 20:return t.next=22,r.json();case 22:(a=t.sent)&&(e.jwt=a.token);case 24:e.resendTimer&&clearInterval(e.resendTimer),e.startResendTimer(),t.next=31;break;case 28:t.prev=28,t.t0=t.catch(0),e.printError(t.t0 instanceof Error?t.t0.message:"An unknown error occurred");case 31:case"end":return t.stop()}}),t,null,[[0,28]])}))),this.handleOTPVerification=t(n().mark((function t(){var r,o,i,a,s,d;return n().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r=document.querySelector("#dev-otp-input"),(o=null==r?void 0:r.value)&&6===o.length){t.next=5;break}return e.showError("Invalid OTP"),t.abrupt("return");case 5:if(e.jwt){t.next=8;break}return e.showError("Verification token is missing"),t.abrupt("return");case 8:return t.prev=8,t.next=11,fetch("https://user-verification-tawny.vercel.app/api/verify-otp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({verification_code:o,verification_token:e.jwt})});case 11:if((a=t.sent).ok){t.next=17;break}if(401!==a.status){t.next=16;break}return e.showError("Invalid OTP"),t.abrupt("return");case 16:throw new Error("OTP verification failed");case 17:return t.next=19,a.json();case 19:s=t.sent.verification_signature,e.hideError(),null==(i=e.dialog)||i.close(),d=new CustomEvent("dev-otp-verified",{detail:{verified:!0,signature:s}}),document.dispatchEvent(d),t.next=29;break;case 26:t.prev=26,t.t0=t.catch(8),e.printError(t.t0 instanceof Error?t.t0.message:"An unknown error occurred");case 29:case"end":return t.stop()}}),t,null,[[8,26]])}))),this.siteId=null,this.jwt=null,this.dialog=null,this.styles=null,this.resendTimer=null,this.identifier=null,this.verificationType=null}var o=e.prototype;return o.fetchThemeConfig=function(){var e=t(n().mark((function e(){var t,r,o;return n().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,fetch("https://user-verification-tawny.vercel.app/api/get-theme/"+this.siteId);case 3:if((t=e.sent)&&t.ok){e.next=6;break}throw new Error("Failed to fetch theme configuration: "+(null==t?void 0:t.status));case 6:return e.next=8,t.json();case 8:if(r=e.sent,console.log("Theme API Response:",r),r&&r.data&&r.data.colors){e.next=12;break}throw new Error("Invalid theme configuration response format");case 12:return e.abrupt("return",{dialog:{padding:"20px",borderRadius:"8px",border:"none",boxShadow:"0 2px 8px rgba(0, 0, 0, 0.2)",backdrop:"rgba(0, 0, 0, 0.5)",background:(o=r.data.colors).cardBackground||"#FFFFFF"},input:{padding:"8px",fontSize:"16px",border:"1px solid #ccc",borderRadius:"4px",color:o.text||"#353a40",background:o.background||"#F9FAFB"},verifyButton:{background:o.primary||"#cc14ff",color:"#FFFFFF",padding:"8px 16px",borderRadius:"4px",border:"none",display:"none"},cancelButton:{background:o.cancelBackground||"#FFFFFF",color:o.cancelButton||"#1dc11a",padding:"8px 16px",borderRadius:"4px",border:"1px solid "+(o.cancelButton||"#1dc11a")},resendButton:{background:o.background||"#F9FAFB",color:o.resendButton||"#4B5563",padding:"8px 16px",borderRadius:"4px",border:"1px solid "+(o.resendButton||"#4B5563")},errorMessage:{color:o.error||"#EF4444",fontSize:"14px",marginTop:"8px",textAlign:"center"},successMark:{color:o.success||"#1dc11a",fontSize:"20px",marginLeft:"8px",display:"none"}});case 16:return e.prev=16,e.t0=e.catch(0),console.error("Theme fetch error:",e.t0),this.printError("Failed to fetch theme configuration: "+e.t0.message),e.abrupt("return",this.getDefaultTheme());case 21:case"end":return e.stop()}}),e,this,[[0,16]])})));return function(){return e.apply(this,arguments)}}(),o.getDefaultTheme=function(){return{dialog:{padding:"20px",borderRadius:"8px",border:"none",boxShadow:"0 2px 8px rgba(0, 0, 0, 0.2)",backdrop:"rgba(0, 0, 0, 0.5)",background:"#FFFFFF"},input:{padding:"8px",fontSize:"16px",border:"1px solid #ccc",borderRadius:"4px",color:"#353a40",background:"#F9FAFB"},verifyButton:{background:"#cc14ff",color:"#FFFFFF",padding:"8px 16px",borderRadius:"4px",border:"none"},cancelButton:{background:"#FFFFFF",color:"#1dc11a",padding:"8px 16px",borderRadius:"4px",border:"1px solid #1dc11a"},resendButton:{background:"#F9FAFB",color:"#4B5563",padding:"8px 16px",borderRadius:"4px",border:"1px solid #4B5563"},errorMessage:{color:"#EF4444",fontSize:"14px",marginTop:"8px",textAlign:"center"},successMark:{color:"#1dc11a",fontSize:"20px",marginLeft:"8px",display:"none"}}},e}());window.devInit=function(e){var t=0,n=function(){if(document.querySelector('[data-devotp="email"]')||document.querySelector('[data-devotp="phone"]'))o.init(e);else{if(t>5)throw o.printError("Unable to find required input email"),new Error("FAILED to initialize");t++,setTimeout(n,100)}};window.addEventListener("load",n)};
//# sourceMappingURL=user-verification.cjs.production.min.js.map