@foxford/services 1.2.0 → 1.2.1
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';Object.defineProperty(exports,'__esModule',{value:true});var e=require('./../../dependencies/@babel/runtime/helpers/esm/asyncToGenerator.js');var t=require('../error.js');var r=require('../log.js');var o=require('./constants.js');var n=require('./style.js');var i=require('./template.js');var
|
|
1
|
+
'use strict';Object.defineProperty(exports,'__esModule',{value:true});var e=require('./../../dependencies/@babel/runtime/helpers/esm/asyncToGenerator.js');var t=require('../error.js');var r=require('../log.js');var o=require('./constants.js');var n=require('./style.js');var i=require('./template.js');var l=function(){};class CloudflareTurnstile{constructor(e){var{sitekey:t,locale:r,notify:o,onFatalError:n,onPotentiallyAutomatedError:i,onRenderCaptcha:a,onSuccessChallenge:s,onFailChallenge:c}=e;this.sitekey=null,this.locale='ru',this.provider='cloudflare_turnstile',this.container=null,this.notifyHandler=l,this.onFatalError=l,this.onPotentiallyAutomatedError=l,this.onRenderCaptcha=void 0,this.onSuccessChallenge=void 0,this.onFailChallenge=void 0,this.notifyHandler=null!=o?o:l,this.sitekey=null!=t?t:null,this.onFatalError=null!=n?n:l,this.onPotentiallyAutomatedError=null!=i?i:l,this.onRenderCaptcha=null!=a?a:l,this.onSuccessChallenge=null!=s?s:l,this.onFailChallenge=null!=c?c:l,r&&(this.locale=r),this.addDomElements(),CloudflareTurnstile.DEBUG&&(window.cf=this)}notify(){this.notifyHandler&&this.notifyHandler(...arguments)}addDomElements(){this.container||document.getElementById(o.CONTAINER_NODE_ID)||(document.body.insertAdjacentHTML('beforeend',i),document.body.insertAdjacentHTML('beforeend',"<style>".concat(n,"</style>")),this.container=document.getElementById(o.CONTAINER_NODE_ID))}appendScript(t){return e((function*(){if('string'!=typeof t||''===t)throw new TypeError('src script is not defined');var e=document.createElement('script');return e.src=t,document.body&&document.body.appendChild(e),new Promise(((t,r)=>{e.addEventListener('load',(()=>{t(true)})),e.addEventListener('error',(()=>{r()}))}))}))()}show(){var e;null===(e=this.container)||void 0===e||e.classList.add('fox-cf-turnstile--showing'),this.bodyScrollLock()}hide(){var e,t;null===(e=this.container)||void 0===e||e.classList.remove('fox-cf-turnstile--show'),null===(t=this.container)||void 0===t||t.classList.remove('fox-cf-turnstile--showing'),this.bodyScrollUnlock()}loadScript(){var r=this;return e((function*(){if(window.turnstile)return Promise.resolve(window.turnstile);var o=function(){var t=e((function*(){return yield r.appendScript("https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit&onload=onloadTurnstileCallback")}));return function(){return t.apply(this,arguments)}}();return new Promise(((e,n)=>{window.onloadTurnstileCallback=()=>{r.turnstileReady(),window.turnstile?e(window.turnstile):n(new t.CaptchaError('Cloudflare Turnstile is not available'))},o().catch((()=>n(new t.CaptchaError('Could not load Cloudflare Turnstile'))))}))}))()}turnstileReady(){var e,t;r.log('Cloudflare Turnstile is ready',window.turnstile),null===(e=this.container)||void 0===e||null===(t=e.querySelector('.fox-cf-turnstile__loader'))||void 0===t||t.remove()}normalizeLocation(){return(arguments.length>0&&void 0!==arguments[0]?arguments[0]:'').substring(0,31).replace(/\//g,'_')}bodyScrollLock(){var e=document.body;e.style.setProperty('--st',"-".concat(document.documentElement.scrollTop,"px")),e.classList.add('fox-cf-turnstile__noscroll')}bodyScrollUnlock(){document.body.classList.remove('fox-cf-turnstile__noscroll')}renderWidget(t){var n=this;return e((function*(){return new Promise(((e,i)=>{var l;n.onRenderCaptcha(n.provider),null===(l=window.turnstile)||void 0===l||l.render("#".concat(o.RENDER_NODE_ID),{action:n.normalizeLocation(null==t?void 0:t.location),'after-interactive-callback':()=>{r.log("after-interactive-callback")},'before-interactive-callback':()=>{r.log("before-interactive-callback"),n.show()},callback:t=>{r.log("Challenge Success"),n.onSuccessChallenge(n.provider),e(t),n.hide()},'error-callback':e=>{n.onFailChallenge(n.provider,'error'),n.errorHandler(e)},'expired-callback':()=>{n.onFailChallenge(n.provider,'expired'),n.hide(),i(new Error('Captcha is expired'))},language:n.locale,sitekey:n.sitekey,theme:'light','timeout-callback':()=>{n.onFailChallenge(n.provider,'timeout'),n.hide(),i(new Error('Captcha is timeout'))},'unsupported-callback':()=>{n.onFailChallenge(n.provider,'error'),i('110500')}})}))}))()}errorHandler(e){switch(r.log("Captcha error with code:",e),true){case e.startsWith('110500'):this.notify('Ваш браузер устарел. Попробуйте ещё раз, используя другой браузер или устройство.'),Promise.reject();break;case e.startsWith('110600'):this.notify('Прошло слишком много времени с момента начала проверки. Обновите страницу и попробуйте ещё раз.');break;case e.startsWith('110510'):this.notify('Что-то пошло не так — возможно, вы используете технологию подмены User agent. Попробуйте ещё раз или обратитесь в поддержку'),Promise.reject();break;case e.startsWith('105'):case e.startsWith('106'):case e.startsWith('110100'):case e.startsWith('110110'):case e.startsWith('110200'):case e.startsWith('110420'):case e.startsWith('110430'):case e.startsWith('110500'):this.notify("Что-то пошло не так, код ошибки — ".concat(e,". Мы уже знаем о проблеме и скоро всё поправим. Попробуйте ещё раз через некоторое время.")),null==this||this.onFatalError(e),Promise.reject();break;case e.startsWith('200100'):this.notify('Кажется, часы на вашем компьютере показывают неправильное время. Настройте часы и попробуйте ещё раз.'),Promise.reject();break;case e.startsWith('120'):this.notify("Что-то пошло не так. Попробуйте <a href=\"https://yandex.ru/support/common/browsers-settings/cache.html\" target=\"_blank\" rel=\"nofollow noopener\">очистить кеш браузера</a>. Если не помогает, обратитесь в поддержку."),Promise.reject();break;case e.startsWith('100'):this.notify('Что-то пошло не так. Попробуйте ещё раз. Если не помогает, обратитесь в поддержку.'),Promise.reject();break;case e.startsWith('300'):case e.startsWith('600'):null==this||this.onPotentiallyAutomatedError(e)}}execute(o){var n=this;return e((function*(){if(n.sitekey){if(r.log('Load cloudflare script'),yield n.loadScript(),!window.turnstile)throw new t.CaptchaError('Cloudflare Turnstile is not available in window');try{return r.log('Render turnstile widget'),yield n.renderWidget(o)}catch(e){e instanceof Error&&console.warn(e),'string'==typeof e&&n.errorHandler(e)}}}))()}}CloudflareTurnstile.DEBUG=false,exports.CloudflareTurnstile=CloudflareTurnstile;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import e from'./../../dependencies/@babel/runtime/helpers/esm/asyncToGenerator.mjs';import{CaptchaError as t}from'../error.mjs';import{log as r}from'../log.mjs';import{CONTAINER_NODE_ID as o,RENDER_NODE_ID as n}from'./constants.mjs';import i from'./style.mjs';import l from'./template.mjs';var s=function(){};class CloudflareTurnstile{constructor(e){var{sitekey:t,locale:r,notify:o,onFatalError:n,onPotentiallyAutomatedError:i,onRenderCaptcha:l,onSuccessChallenge:a,onFailChallenge:c}=e;this.sitekey=null,this.locale='ru',this.provider='cloudflare_turnstile',this.container=null,this.notifyHandler=s,this.onFatalError=s,this.onPotentiallyAutomatedError=s,this.onRenderCaptcha=void 0,this.onSuccessChallenge=void 0,this.onFailChallenge=void 0,this.notifyHandler=null!=o?o:s,this.sitekey=null!=t?t:null,this.onFatalError=null!=n?n:s,this.onPotentiallyAutomatedError=null!=i?i:s,this.onRenderCaptcha=null!=l?l:s,this.onSuccessChallenge=null!=a?a:s,this.onFailChallenge=null!=c?c:s,r&&(this.locale=r),this.addDomElements(),CloudflareTurnstile.DEBUG&&(window.cf=this)}notify(){this.notifyHandler&&this.notifyHandler(...arguments)}addDomElements(){this.container||document.getElementById(o)||(document.body.insertAdjacentHTML('beforeend',l),document.body.insertAdjacentHTML('beforeend',"<style>".concat(i,"</style>")),this.container=document.getElementById(o))}appendScript(t){return e((function*(){if('string'!=typeof t||''===t)throw new TypeError('src script is not defined');var e=document.createElement('script');return e.src=t,document.body&&document.body.appendChild(e),new Promise(((t,r)=>{e.addEventListener('load',(()=>{t(true)})),e.addEventListener('error',(()=>{r()}))}))}))()}show(){var e;null===(e=this.container)||void 0===e||e.classList.add('fox-cf-turnstile--showing'),this.bodyScrollLock()}hide(){var e,t;null===(e=this.container)||void 0===e||e.classList.remove('fox-cf-turnstile--show'),null===(t=this.container)||void 0===t||t.classList.remove('fox-cf-turnstile--showing'),this.bodyScrollUnlock()}loadScript(){var r=this;return e((function*(){if(window.turnstile)return Promise.resolve(window.turnstile);var o=function(){var t=e((function*(){return yield r.appendScript("https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit&onload=onloadTurnstileCallback")}));return function(){return t.apply(this,arguments)}}();return new Promise(((e,n)=>{window.onloadTurnstileCallback=()=>{r.turnstileReady(),window.turnstile?e(window.turnstile):n(new t('Cloudflare Turnstile is not available'))},o().catch((()=>n(new t('Could not load Cloudflare Turnstile'))))}))}))()}turnstileReady(){var e,t;r('Cloudflare Turnstile is ready',window.turnstile),null===(e=this.container)||void 0===e||null===(t=e.querySelector('.fox-cf-turnstile__loader'))||void 0===t||t.remove()}normalizeLocation(){return(arguments.length>0&&void 0!==arguments[0]?arguments[0]:'').substring(0,31).replace(/\//g,'_')}bodyScrollLock(){var e=document.body;e.style.setProperty('--st',"-".concat(document.documentElement.scrollTop,"px")),e.classList.add('fox-cf-turnstile__noscroll')}bodyScrollUnlock(){document.body.classList.remove('fox-cf-turnstile__noscroll')}renderWidget(t){var o=this;return e((function*(){return new Promise(((e,i)=>{var l;o.onRenderCaptcha(o.provider),null===(l=window.turnstile)||void 0===l||l.render("#".concat(n),{action:o.normalizeLocation(null==t?void 0:t.location),'after-interactive-callback':()=>{r("after-interactive-callback")},'before-interactive-callback':()=>{r("before-interactive-callback"),o.show()},callback:t=>{r("Challenge Success"),o.onSuccessChallenge(o.provider),e(t),o.hide()},'error-callback':e=>{o.onFailChallenge(o.provider,'error'),o.errorHandler(e)},'expired-callback':()=>{o.onFailChallenge(o.provider,'expired'),o.hide(),i(new Error('Captcha is expired'))},language:o.locale,sitekey:o.sitekey,theme:'light','timeout-callback':()=>{o.onFailChallenge(o.provider,'timeout'),o.hide(),i(new Error('Captcha is timeout'))},'unsupported-callback':()=>{o.onFailChallenge(o.provider,'error'),i('110500')}})}))}))()}errorHandler(e){switch(r("Captcha error with code:",e),true){case e.startsWith('110500'):this.notify('Ваш браузер устарел. Попробуйте ещё раз, используя другой браузер или устройство.'),Promise.reject();break;case e.startsWith('110600'):this.notify('Прошло слишком много времени с момента начала проверки. Обновите страницу и попробуйте ещё раз.');break;case e.startsWith('110510'):this.notify('Что-то пошло не так — возможно, вы используете технологию подмены User agent. Попробуйте ещё раз или обратитесь в поддержку'),Promise.reject();break;case e.startsWith('105'):case e.startsWith('106'):case e.startsWith('110100'):case e.startsWith('110110'):case e.startsWith('110200'):case e.startsWith('110420'):case e.startsWith('110430'):case e.startsWith('110500'):this.notify("Что-то пошло не так, код ошибки — ".concat(e,". Мы уже знаем о проблеме и скоро всё поправим. Попробуйте ещё раз через некоторое время.")),null==this||this.onFatalError(e),Promise.reject();break;case e.startsWith('200100'):this.notify('Кажется, часы на вашем компьютере показывают неправильное время. Настройте часы и попробуйте ещё раз.'),Promise.reject();break;case e.startsWith('120'):this.notify("Что-то пошло не так. Попробуйте <a href=\"https://yandex.ru/support/common/browsers-settings/cache.html\" target=\"_blank\" rel=\"nofollow noopener\">очистить кеш браузера</a>. Если не помогает, обратитесь в поддержку."),Promise.reject();break;case e.startsWith('100'):this.notify('Что-то пошло не так. Попробуйте ещё раз. Если не помогает, обратитесь в поддержку.'),Promise.reject();break;case e.startsWith('300'):case e.startsWith('600'):null==this||this.onPotentiallyAutomatedError(e)}}execute(o){var n=this;return e((function*(){if(n.sitekey){if(r('Load cloudflare script'),yield n.loadScript(),!window.turnstile)throw new t('Cloudflare Turnstile is not available in window');try{return r('Render turnstile widget'),yield n.renderWidget(o)}catch(e){e instanceof Error&&console.warn(e),'string'==typeof e&&n.errorHandler(e)}}}))()}}CloudflareTurnstile.DEBUG=false;export{CloudflareTurnstile};
|
package/captcha/google/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';Object.defineProperty(exports,'__esModule',{value:true});var e=require('./../../dependencies/@babel/runtime/helpers/esm/asyncToGenerator.js');var r=require('../../utils/uuid.js');var a=require('../error.js');var t=require('../log.js');var o=require('./constants.js');var
|
|
1
|
+
'use strict';Object.defineProperty(exports,'__esModule',{value:true});var e=require('./../../dependencies/@babel/runtime/helpers/esm/asyncToGenerator.js');var r=require('../../utils/uuid.js');var a=require('../error.js');var t=require('../log.js');var o=require('./constants.js');var n=function(){};class GoogleCaptcha{constructor(e){var{sitekey:r,locale:a,notify:t,onFatalError:o,onRenderCaptcha:c,onSuccessChallenge:i,onFailChallenge:l}=e;this.sitekey=null,this.locale='ru',this.container=null,this.provider='recaptcha',this.notifyHandler=n,this.onFatalError=n,this.onRenderCaptcha=n,this.onSuccessChallenge=n,this.onFailChallenge=n,this.sitekey=null!=r?r:null,this.notifyHandler=null!=t?t:n,this.onFatalError=null!=o?o:n,this.onRenderCaptcha=null!=c?c:n,this.onSuccessChallenge=null!=i?i:n,this.onFailChallenge=null!=l?l:n,a&&(this.locale=a),this.addDomElements(),GoogleCaptcha.DEBUG&&(window.gr=this)}recaptchaReady(){t.log('Google recaptcha is ready',window.grecaptcha)}addDomElements(){if(!this.container&&!document.getElementById(o.NODE_ID)){document.body.insertAdjacentHTML('beforeend',"<div id=\"".concat(o.NODE_ID,"\"></div>"));var e=document.getElementById(o.NODE_ID);e.style.display='none',this.container=e}}getGrecaptchaCallbackNames(){return{error:"".concat(GoogleCaptcha.ERROR_FUNC_NAME),expired:"".concat(GoogleCaptcha.EXPIRED_FUNC_NAME),resolve:"".concat(GoogleCaptcha.RESOLVE_FUNC_NAME)}}appendScript(r){return e((function*(){if('string'!=typeof r||''===r)throw new TypeError('src script is not defined');var e=document.createElement('script');return e.src=r,document.body&&document.body.appendChild(e),new Promise(((r,a)=>{e.addEventListener('load',(()=>{r(true)})),e.addEventListener('error',(()=>{a()}))}))}))()}loadScript(){var r=this;return e((function*(){if(window.grecaptcha)return Promise.resolve(window.grecaptcha);var t=function(){var a=e((function*(){return yield r.appendScript("https://www.google.com/recaptcha/api.js?hl=".concat(r.locale,"&onload=onloadRecaptchaCallback"))}));return function(){return a.apply(this,arguments)}}();return new Promise(((e,o)=>{window.onloadRecaptchaCallback=()=>{r.recaptchaReady(),window.grecaptcha?e(window.grecaptcha):o(new a.CaptchaError('Recaptcha is not available'))},t().catch((()=>o(new a.CaptchaError('Could not load Recaptcha'))))}))}))()}notify(){this.notifyHandler&&this.notifyHandler(...arguments)}errorHandler(e){switch(t.log("Recaptcha error:",e),e.toString()){case'recaptcha is expired':case'recaptcha has error':this.notify('Возможно произшла ошибка с сетевым подключением. Попробуйте ещё раз. Если не помогает, обратитесь в поддержку.');break;default:this.notify('Что-то пошло не так. Попробуйте ещё раз. Если не помогает, обратитесь в поддержку.')}}renderWidget(e){return new Promise(((e,t)=>{var n,c,i;var l=document.createElement('div');var s="".concat(o.NODE_ID,"_").concat(r.generateUUID());l.id=s,null===(n=document.getElementById(o.NODE_ID))||void 0===n||n.appendChild(l);var h=this.getGrecaptchaCallbackNames();var d=NaN;window[h.resolve]=()=>{var r;this.onSuccessChallenge(this.provider);var a=null===(r=window.grecaptcha)||void 0===r?void 0:r.getResponse(d);e(null!=a?a:''),l.remove()},window[h.error]=()=>{this.onFailChallenge(this.provider,'error'),t(new a.CaptchaError('recaptcha has error')),l.remove()},window[h.expired]=()=>{this.onFailChallenge(this.provider,'expired'),t(new a.CaptchaError('recaptcha is expired')),l.remove()},this.onRenderCaptcha(this.provider),d=null===(c=window.grecaptcha)||void 0===c?void 0:c.render(s,{callback:h.resolve,'error-callback':h.error,'expired-callback':h.expired,sitekey:this.sitekey,size:'invisible'});var p=null===(i=window.grecaptcha)||void 0===i?void 0:i.execute(d);if(!p)return t(new a.CaptchaError('cannot call method execute from grecaptcha')),void l.remove();p.catch((e=>{e instanceof Error?(t(new a.CaptchaError(e.message)),l.remove()):'string'==typeof e&&(t(new a.CaptchaError(e)),l.remove())}))}))}execute(r){var o=this;return e((function*(){if(o.sitekey){if(t.log('Load recaptcha script'),yield o.loadScript(),!window.grecaptcha)throw new a.CaptchaError('Recaptcha is not available in window');try{return t.log('Render Recaptcha widget'),yield o.renderWidget(r)}catch(e){'string'==typeof e||e instanceof a.CaptchaError?o.errorHandler(e):o.onFatalError(e.toString())}}}))()}}GoogleCaptcha.RESOLVE_FUNC_NAME='grecaptcha_resolved',GoogleCaptcha.ERROR_FUNC_NAME='grecaptcha_error',GoogleCaptcha.EXPIRED_FUNC_NAME='grecaptcha_expired',GoogleCaptcha.DEBUG=false,exports.GoogleCaptcha=GoogleCaptcha;
|
package/captcha/google/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from'./../../dependencies/@babel/runtime/helpers/esm/asyncToGenerator.mjs';import{generateUUID as r}from'../../utils/uuid.mjs';import{CaptchaError as
|
|
1
|
+
import e from'./../../dependencies/@babel/runtime/helpers/esm/asyncToGenerator.mjs';import{generateUUID as r}from'../../utils/uuid.mjs';import{CaptchaError as a}from'../error.mjs';import{log as t}from'../log.mjs';import{NODE_ID as o}from'./constants.mjs';var n=function(){};class GoogleCaptcha{constructor(e){var{sitekey:r,locale:a,notify:t,onFatalError:o,onRenderCaptcha:i,onSuccessChallenge:c,onFailChallenge:l}=e;this.sitekey=null,this.locale='ru',this.container=null,this.provider='recaptcha',this.notifyHandler=n,this.onFatalError=n,this.onRenderCaptcha=n,this.onSuccessChallenge=n,this.onFailChallenge=n,this.sitekey=null!=r?r:null,this.notifyHandler=null!=t?t:n,this.onFatalError=null!=o?o:n,this.onRenderCaptcha=null!=i?i:n,this.onSuccessChallenge=null!=c?c:n,this.onFailChallenge=null!=l?l:n,a&&(this.locale=a),this.addDomElements(),GoogleCaptcha.DEBUG&&(window.gr=this)}recaptchaReady(){t('Google recaptcha is ready',window.grecaptcha)}addDomElements(){if(!this.container&&!document.getElementById(o)){document.body.insertAdjacentHTML('beforeend',"<div id=\"".concat(o,"\"></div>"));var e=document.getElementById(o);e.style.display='none',this.container=e}}getGrecaptchaCallbackNames(){return{error:"".concat(GoogleCaptcha.ERROR_FUNC_NAME),expired:"".concat(GoogleCaptcha.EXPIRED_FUNC_NAME),resolve:"".concat(GoogleCaptcha.RESOLVE_FUNC_NAME)}}appendScript(r){return e((function*(){if('string'!=typeof r||''===r)throw new TypeError('src script is not defined');var e=document.createElement('script');return e.src=r,document.body&&document.body.appendChild(e),new Promise(((r,a)=>{e.addEventListener('load',(()=>{r(true)})),e.addEventListener('error',(()=>{a()}))}))}))()}loadScript(){var r=this;return e((function*(){if(window.grecaptcha)return Promise.resolve(window.grecaptcha);var t=function(){var a=e((function*(){return yield r.appendScript("https://www.google.com/recaptcha/api.js?hl=".concat(r.locale,"&onload=onloadRecaptchaCallback"))}));return function(){return a.apply(this,arguments)}}();return new Promise(((e,o)=>{window.onloadRecaptchaCallback=()=>{r.recaptchaReady(),window.grecaptcha?e(window.grecaptcha):o(new a('Recaptcha is not available'))},t().catch((()=>o(new a('Could not load Recaptcha'))))}))}))()}notify(){this.notifyHandler&&this.notifyHandler(...arguments)}errorHandler(e){switch(t("Recaptcha error:",e),e.toString()){case'recaptcha is expired':case'recaptcha has error':this.notify('Возможно произшла ошибка с сетевым подключением. Попробуйте ещё раз. Если не помогает, обратитесь в поддержку.');break;default:this.notify('Что-то пошло не так. Попробуйте ещё раз. Если не помогает, обратитесь в поддержку.')}}renderWidget(e){return new Promise(((e,t)=>{var n,i,c;var l=document.createElement('div');var s="".concat(o,"_").concat(r());l.id=s,null===(n=document.getElementById(o))||void 0===n||n.appendChild(l);var d=this.getGrecaptchaCallbackNames();var h=NaN;window[d.resolve]=()=>{var r;this.onSuccessChallenge(this.provider);var a=null===(r=window.grecaptcha)||void 0===r?void 0:r.getResponse(h);e(null!=a?a:''),l.remove()},window[d.error]=()=>{this.onFailChallenge(this.provider,'error'),t(new a('recaptcha has error')),l.remove()},window[d.expired]=()=>{this.onFailChallenge(this.provider,'expired'),t(new a('recaptcha is expired')),l.remove()},this.onRenderCaptcha(this.provider),h=null===(i=window.grecaptcha)||void 0===i?void 0:i.render(s,{callback:d.resolve,'error-callback':d.error,'expired-callback':d.expired,sitekey:this.sitekey,size:'invisible'});var p=null===(c=window.grecaptcha)||void 0===c?void 0:c.execute(h);if(!p)return t(new a('cannot call method execute from grecaptcha')),void l.remove();p.catch((e=>{e instanceof Error?(t(new a(e.message)),l.remove()):'string'==typeof e&&(t(new a(e)),l.remove())}))}))}execute(r){var o=this;return e((function*(){if(o.sitekey){if(t('Load recaptcha script'),yield o.loadScript(),!window.grecaptcha)throw new a('Recaptcha is not available in window');try{return t('Render Recaptcha widget'),yield o.renderWidget(r)}catch(e){'string'==typeof e||e instanceof a?o.errorHandler(e):o.onFatalError(e.toString())}}}))()}}GoogleCaptcha.RESOLVE_FUNC_NAME='grecaptcha_resolved',GoogleCaptcha.ERROR_FUNC_NAME='grecaptcha_error',GoogleCaptcha.EXPIRED_FUNC_NAME='grecaptcha_expired',GoogleCaptcha.DEBUG=false;export{GoogleCaptcha};
|
package/index.d.ts
CHANGED
|
@@ -187,9 +187,13 @@ export type CaptchaConfig = {
|
|
|
187
187
|
locale?: string;
|
|
188
188
|
sitekey?: string;
|
|
189
189
|
provider?: CaptchaProviderName;
|
|
190
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
190
191
|
notify?: (...args: any[]) => void;
|
|
191
192
|
onFatalError?: (code: string) => void;
|
|
192
193
|
onPotentiallyAutomatedError?: (code: string) => void;
|
|
194
|
+
onRenderCaptcha?: (provider: CaptchaProviderName) => void;
|
|
195
|
+
onSuccessChallenge?: (provider: CaptchaProviderName) => void;
|
|
196
|
+
onFailChallenge?: (provider: CaptchaProviderName, reason: "error" | "timeout" | "expired") => void;
|
|
193
197
|
};
|
|
194
198
|
type ExecuteMeta = Record<string, unknown>;
|
|
195
199
|
export interface Captcha {
|
package/index.js.flow
CHANGED
|
@@ -258,6 +258,12 @@ export type CaptchaConfig = {|
|
|
|
258
258
|
notify?: (...args: any[]) => void,
|
|
259
259
|
onFatalError?: (code: string) => void,
|
|
260
260
|
onPotentiallyAutomatedError?: (code: string) => void,
|
|
261
|
+
onRenderCaptcha?: (provider: CaptchaProviderName) => void,
|
|
262
|
+
onSuccessChallenge?: (provider: CaptchaProviderName) => void,
|
|
263
|
+
onFailChallenge?: (
|
|
264
|
+
provider: CaptchaProviderName,
|
|
265
|
+
reason: "error" | "timeout" | "expired"
|
|
266
|
+
) => void,
|
|
261
267
|
|};
|
|
262
268
|
declare type ExecuteMeta = { [key: string]: mixed };
|
|
263
269
|
export interface Captcha {
|