@foxford/services 1.4.10 → 1.4.12

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.
package/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  // Generated by dts-bundle-generator v9.5.1
2
2
 
3
+ import { BroadcastChannel as BroadcastChannel$1, BroadcastChannelOptions, LeaderElector } from 'broadcast-channel';
4
+
3
5
  export interface ApiTransformer {
4
6
  (data: any, headers?: any): any;
5
7
  }
@@ -280,7 +282,7 @@ export type SocketServiceConfig = {
280
282
  */
281
283
  export declare class SocketService {
282
284
  private config;
283
- private channel;
285
+ private channel?;
284
286
  private elector;
285
287
  private client;
286
288
  private connected;
@@ -306,6 +308,7 @@ export declare class SocketService {
306
308
  */
307
309
  private subscriptionExists;
308
310
  private join;
311
+ private createChannel;
309
312
  /**
310
313
  * Подписаться на канал
311
314
  */
@@ -315,8 +318,11 @@ export declare class SocketService {
315
318
  */
316
319
  unsubscribe(channelName: string): void;
317
320
  }
321
+ export declare function createBroadcastChannel<T>(name: string, opts?: BroadcastChannelOptions): BroadcastChannel$1<T>;
318
322
 
319
323
  export {
324
+ BroadcastChannel$1 as BroadcastChannel,
325
+ LeaderElector,
320
326
  apiServiceInstance as ApiService,
321
327
  };
322
328
 
package/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var e=require("axios"),t=require("axios-retry"),n=require("broadcast-channel"),i=require("centrifuge");function r(e,t,n,i){return new(n||(n=Promise))((function(r,o){function s(e){try{c(i.next(e))}catch(e){o(e)}}function a(e){try{c(i.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((i=i.apply(e,t||[])).next())}))}function o(e,t,n){return e.headers=Object.assign({"Content-Type":"application/json"},e.headers),window&&window.location&&window.location.pathname&&window.location.origin&&(e.headers=Object.assign(Object.assign({},e.headers),{"X-Referer":window.location.origin+window.location.pathname})),n.length>0?function(e,t,n){return r(this,void 0,void 0,(function*(){for(const i of n)i.isApplicable(e)&&(e=yield i.execute(e,t));return e}))}(e,t,n):e}function s(e,t,n){return n.length>0?function(e,t,n){return r(this,void 0,void 0,(function*(){for(const i of n)i.isApplicable(e)&&(e=yield i.execute(e,t));return e}))}(e,t,n):e}void 0===Promise.withResolvers&&(Promise.withResolvers=()=>{let e,t;return{promise:new Promise(((n,i)=>{e=n,t=i})),reject:t,resolve:e}}),"function"==typeof SuppressedError&&SuppressedError;const a=[422,401];function c(e){return"object"==typeof e&&null!==e&&"url"in e}function l(e,t,n){return r(this,void 0,void 0,(function*(){if("object"!=typeof(i=e)||null===i||!("response"in i)||!("config"in i)||null===i.config||null===i.response)return Promise.reject(e);var i;const o=yield function(e,t,n){return r(this,void 0,void 0,(function*(){let i=e;for(const r of n)if(r.isApplicable(e)&&(i=yield r.execute(e,t),c(i)))return i;return i}))}(e,t,n);if(c(o))return t.request(o);const s=function(e){const{response:t,config:n}=e;return a.includes(t.status)&&(n._retry=!0),Object.assign({errorText:e.toString(),headers:t.headers,status:t.status,statusText:t.statusText},"object"==typeof t.data?t.data:{data:t.data})}(e);return Promise.reject(s)}))}const d=new class{createFoxApiInstance({config:n,plugins:i=[]}){const r=e.create(n),a=this.filterPlugins(i,"request"),c=this.filterPlugins(i,"responseSuccess"),d=this.filterPlugins(i,"responseFail");return r.interceptors.request.use((e=>o(e,r,[...a]))),r.interceptors.response.use((e=>s(e,r,[...c])),(e=>l(e,r,[...d]))),t(r,{retries:3,retryDelay:t.exponentialDelay}),r}createApiInstance({config:t}){return e.create(t)}createStaticApiInstance(){const t=e;return t.isApiError=e=>"object"==typeof e&&!0===e.isAxiosError,t}filterPlugins(e,t){return e?e.filter((e=>e.pluginType===t)):[]}},h="turnstile-container",u="turnstile-widget";var p=`\n<div id="${h}" class="fox-cf-turnstile">\n <div class="fox-cf-turnstile__overlay"></div>\n <div class="fox-cf-turnstile__content">\n <div class="fox-cf-turnstile__content__text">\n <h3>Надо убедиться, что вы человек</h3>\n <span>Поставьте галочку, нажав на белый квадрат ниже — проверка займёт буквально секунду</span>\n </div>\n <div id="${u}">\n <div class="fox-cf-turnstile__loader"></div>\n </div>\n </div>\n</div>\n`;class f extends Error{constructor(e,t="error"){super(e),this.level="error",this.name="CaptchaError",this.message=e,this.level=t}}function g(...e){const t=["[CaptchaService] ",...e];console.debug.apply(console,t)}const v=(...e)=>{};class w{constructor({sitekey:e,locale:t,notify:n,onRenderCaptcha:i,onSuccessChallenge:r,onErrorChallenge:o,onWarnChallenge:s,onBeforeInteractiveChallenge:a,onAfterInteractiveChallenge:c}){this.sitekey=null,this.locale="ru",this.provider="cloudflare_turnstile",this.container=null,this.notifyHandler=null!=n?n:v,this.sitekey=null!=e?e:null,this.onRenderCaptcha=null!=i?i:v,this.onSuccessChallenge=null!=r?r:v,this.onErrorChallenge=null!=o?o:v,this.onWarnChallenge=null!=s?s:v,this.onBeforeInteractiveChallenge=null!=a?a:v,this.onAfterInteractiveChallenge=null!=c?c:v,t&&(this.locale=t),this.addDomElements(),w.DEBUG&&(window.cf=this)}notify(...e){this.notifyHandler&&this.notifyHandler(...e)}addDomElements(){this.container||document.getElementById(h)||(document.body.insertAdjacentHTML("beforeend",p),document.body.insertAdjacentHTML("beforeend","<style>\n.fox-cf-turnstile {\n position: fixed;\n top: 0;\n left: 0;\n display: flex;\n align-items: center;\n justify-content: center;\n width: 100vw;\n height: 100vh;\n z-index: -1;\n}\n.fox-cf-turnstile__noscroll {\n position: fixed; \n top: var(--st, 0);\n inline-size: 100%;\n overflow-y:scroll; \n}\n.fox-cf-turnstile--showing {\n z-index: 9999;\n}\n.fox-cf-turnstile__overlay {\n position: absolute;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n background: rgba(246, 247, 251, 0.9);\n opacity: 0;\n transition: all .3s ease;\n transition-delay: .2s;\n z-index: 0;\n}\n.fox-cf-turnstile__content {\n background: white;\n border-radius: 5px;\n max-width: 500px;\n max-height: 50vh;\n position: relative;\n z-index: 1;\n box-shadow: rgba(0, 0, 0, 0.08) 0px 10px 20px 0px;\n height: 1px;\n width: 1px;\n overflow: hidden;\n transition: all .8s ease, opacity 0.3s ease;\n transition-delay: .3s;\n opacity: 0;\n display: flex;\n align-items: center;\n justify-content: center;\n flex-direction: column;\n font-size: 1.2rem;\n}\n.fox-cf-turnstile__content__text {\n flex: 1;\n margin-bottom: 20px;\n opacity: 1;\n overflow: hidden;\n transition: opacity 0.3s ease;\n text-align: center;\n}\n.fox-cf-turnstile--showing .fox-cf-turnstile__overlay, .fox-cf-turnstile--show .fox-cf-turnstile__overlay {\n opacity: 1;\n}\n.fox-cf-turnstile--showing .fox-cf-turnstile__content, .fox-cf-turnstile--show .fox-cf-turnstile__content {\n width: 100%;\n height: auto;\n min-height: 20vh;\n min-width: 30vw;\n padding: 30px;\n opacity: 1;\n}\n.fox-cf-turnstile__content__text h3 {\n font-size: 1.4rem;\n}\n.fox-cf-turnstile__loader {\n font-size: 10px;\n margin: 50px auto;\n text-indent: -9999em;\n width: 5em;\n height: 5em;\n border-radius: 50%;\n background: #8b1feb;\n background: -moz-linear-gradient(left, #8b1feb 10%, rgba(139,31,235, 0) 42%);\n background: -webkit-linear-gradient(left, #8b1feb 10%, rgba(139,31,235, 0) 42%);\n background: -o-linear-gradient(left, #8b1feb 10%, rgba(139,31,235, 0) 42%);\n background: -ms-linear-gradient(left, #8b1feb 10%, rgba(139,31,235, 0) 42%);\n background: linear-gradient(to right, #8b1feb 10%, rgba(139,31,235, 0) 42%);\n position: relative;\n -webkit-animation: load3 1.4s infinite linear;\n animation: load3 1.4s infinite linear;\n -webkit-transform: translateZ(0);\n -ms-transform: translateZ(0);\n transform: translateZ(0);\n}\n.fox-cf-turnstile__loader:before {\n width: 50%;\n height: 50%;\n background: #8b1feb;\n border-radius: 100% 0 0 0;\n position: absolute;\n top: 0;\n left: 0;\n content: '';\n}\n.fox-cf-turnstile__loader:after {\n background: white;\n width: 75%;\n height: 75%;\n border-radius: 50%;\n content: '';\n margin: auto;\n position: absolute;\n top: 0;\n left: 0;\n bottom: 0;\n right: 0;\n}\n@-webkit-keyframes load3 {\n 0% {\n -webkit-transform: rotate(0deg);\n transform: rotate(0deg);\n }\n 100% {\n -webkit-transform: rotate(360deg);\n transform: rotate(360deg);\n }\n}\n@keyframes load3 {\n 0% {\n -webkit-transform: rotate(0deg);\n transform: rotate(0deg);\n }\n 100% {\n -webkit-transform: rotate(360deg);\n transform: rotate(360deg);\n }\n} \n</style>"),this.container=document.getElementById(h))}static appendScript(e){return r(this,void 0,void 0,(function*(){if("string"!=typeof e||""===e)throw new TypeError("src script is not defined");const t=document.createElement("script");return t.src=e,document.body&&document.body.appendChild(t),new Promise(((e,n)=>{t.addEventListener("load",(()=>{e(!0)})),t.addEventListener("error",(()=>{n()}))}))}))}show(){var e;null===(e=this.container)||void 0===e||e.classList.add("fox-cf-turnstile--showing"),w.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"),w.bodyScrollUnlock()}loadScript(){return r(this,void 0,void 0,(function*(){if(window.turnstile)return Promise.resolve(window.turnstile);const e=()=>r(this,void 0,void 0,(function*(){return yield w.appendScript("https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit&onload=onloadTurnstileCallback")}));return new Promise(((t,n)=>{window.onloadTurnstileCallback=()=>{this.turnstileReady(),window.turnstile?t(window.turnstile):n(new f("Cloudflare Turnstile is not available"))},e().catch((()=>n(new f("Could not load Cloudflare Turnstile"))))}))}))}turnstileReady(){var e,t;g("Cloudflare Turnstile is ready",window.turnstile),null===(t=null===(e=this.container)||void 0===e?void 0:e.querySelector(".fox-cf-turnstile__loader"))||void 0===t||t.remove()}static normalizeLocation(e=""){return e.substring(0,31).replace(/\//g,"_")}static bodyScrollLock(){const e=document.body;e.style.setProperty("--st",`-${document.documentElement.scrollTop}px`),e.classList.add("fox-cf-turnstile__noscroll")}static bodyScrollUnlock(){document.body.classList.remove("fox-cf-turnstile__noscroll")}renderWidget(e){return r(this,void 0,void 0,(function*(){return new Promise(((t,n)=>{var i;let r="";function o(){var e;null===(e=window.turnstile)||void 0===e||e.reset(r),setTimeout((()=>{var e;null===(e=window.turnstile)||void 0===e||e.remove(r)}),500)}r=null===(i=window.turnstile)||void 0===i?void 0:i.render(`#${u}`,{action:w.normalizeLocation(null==e?void 0:e.location),"after-interactive-callback":()=>{g("after-interactive-callback"),this.onAfterInteractiveChallenge(this.provider)},"before-interactive-callback":()=>{g("before-interactive-callback"),this.onBeforeInteractiveChallenge(this.provider),this.show()},callback:e=>{g("Challenge Success"),this.hide(),t(e),o()},"error-callback":e=>{n(e),o()},"expired-callback":()=>{this.hide(),n("expired"),o()},language:this.locale,sitekey:this.sitekey,theme:"light","timeout-callback":()=>{this.hide(),n("timeout"),o()},"unsupported-callback":()=>{n("110500"),o()}})}))}))}errorHandler(e){g("Captcha error with code:",e);let t=[...w.NO_RETRY_ERROR_CODES];if("string"!=typeof e)return void this.notify("Что-то пошло не так. Попробуйте ещё раз. Если не помогает, обратитесь в поддержку.");const n=e;switch(!0){case n.startsWith("110500"):t=t.filter((e=>!e.startsWith("110500"))),this.notify("Ваш браузер устарел. Попробуйте ещё раз, используя другой браузер или устройство.");break;case n.startsWith("110600"):t=t.filter((e=>!e.startsWith("110600"))),this.notify("Прошло слишком много времени с момента начала проверки. Попробуйте еще раз.");break;case n.startsWith("110510"):t=t.filter((e=>!e.startsWith("110510"))),this.notify("Что-то пошло не так — возможно, вы используете технологию подмены User agent. Попробуйте ещё раз или обратитесь в поддержку");break;case n.startsWith("200010"):this.notify('Что-то пошло не так. Попробуйте <a href="https://yandex.ru/support/common/browsers-settings/cache.html" target="_blank" rel="nofollow noopener">очистить кеш браузера</a>. Если не помогает, обратитесь в поддержку.');break;case n.startsWith("200100"):t=t.filter((e=>!e.startsWith("200100"))),this.notify("Кажется, часы на вашем компьютере показывают неправильное время. Настройте часы и попробуйте ещё раз.");break;case n.startsWith("300"):case n.startsWith("600"):t=t.filter((e=>!e.startsWith("300")||!e.startsWith("600"))),this.notify("Потвердите еще раз что вы человек")}t.some((e=>n.startsWith(e)))&&this.notify(`Что-то пошло не так, код ошибки — ${n}. Мы уже знаем о проблеме и скоро всё поправим. Попробуйте ещё раз через некоторое время.`)}execute(e){return r(this,void 0,void 0,(function*(){if(this.sitekey){g("Load cloudflare script");try{yield this.loadScript()}catch(e){const t=e instanceof f?e:new f("Could not load captcha with error: "+e.toString());throw this.onErrorChallenge(this.provider,t),t}if(!window.turnstile){const e=new f("Cloudflare Turnstile is not available in window");throw this.onErrorChallenge(this.provider,e),e}try{g("Render turnstile widget"),this.onRenderCaptcha(this.provider);const t=yield this.renderWidget(e);return this.onSuccessChallenge(this.provider),t}catch(e){if(this.errorHandler(e),"string"!=typeof e){const t=new f("Could not execute captcha with error: "+e.toString());throw this.onErrorChallenge(this.provider,t),t}if(["110200","110100","110110"].some((t=>e.startsWith(t)))){const t=new f("Invalid sitekey or domain is not allowed");throw t.code=e,this.onErrorChallenge(this.provider,t),t}if(w.NO_RETRY_ERROR_CODES.some((t=>e.startsWith(t)))){const t=new f("Captcha challenge is failed");t.code=e,this.onErrorChallenge(this.provider,t)}else{const t=new f("Captcha challenge has error");t.reason=["timeout","expired"].includes(e)?e:void 0,t.code=e,this.onWarnChallenge(this.provider,t)}}}}))}}w.DEBUG=!1,w.NO_RETRY_ERROR_CODES=["100","105","106","110100","110110","110200","110420","110430","110500","110510","120","200010","200100"];const m="recaptcha-widget";function b(){let e=(new Date).getTime(),t="undefined"!=typeof performance&&performance.now&&1e3*performance.now()||0;return"xxxx-xxxx-4xxx-yxxx".replace(/[xy]/g,(function(n){let i=16*Math.random();return e>0?(i=(e+i)%16|0,e=Math.floor(e/16)):(i=(t+i)%16|0,t=Math.floor(t/16)),("x"===n?i:3&i|8).toString(16)}))}const y=(...e)=>{};class C{constructor({sitekey:e,locale:t,notify:n,onRenderCaptcha:i,onSuccessChallenge:r,onWarnChallenge:o,onErrorChallenge:s}){this.sitekey=null,this.locale="ru",this.container=null,this.provider="recaptcha",this.sitekey=null!=e?e:null,this.notifyHandler=null!=n?n:y,this.onRenderCaptcha=null!=i?i:y,this.onSuccessChallenge=null!=r?r:y,this.onWarnChallenge=null!=o?o:y,this.onErrorChallenge=null!=s?s:y,t&&(this.locale=t),this.addDomElements(),C.DEBUG&&(window.gr=this)}recaptchaReady(){g("Google recaptcha is ready",window.grecaptcha,this)}addDomElements(){if(this.container||document.getElementById(m))return;document.body.insertAdjacentHTML("beforeend",`<div id="${m}"></div>`);const e=document.getElementById(m);e.style.display="none",this.container=e}static getGrecaptchaCallbackNames(){return{error:`${C.ERROR_FUNC_NAME}`,expired:`${C.EXPIRED_FUNC_NAME}`,resolve:`${C.RESOLVE_FUNC_NAME}`}}static appendScript(e){return r(this,void 0,void 0,(function*(){if("string"!=typeof e||""===e)throw new TypeError("src script is not defined");const t=document.createElement("script");return t.src=e,document.body&&document.body.appendChild(t),new Promise(((e,n)=>{t.addEventListener("load",(()=>{e(!0)})),t.addEventListener("error",(()=>{n()}))}))}))}loadScript(){return r(this,void 0,void 0,(function*(){if(window.grecaptcha)return Promise.resolve(window.grecaptcha);const e=()=>r(this,void 0,void 0,(function*(){return yield C.appendScript(`https://www.google.com/recaptcha/api.js?hl=${this.locale}&onload=onloadRecaptchaCallback`)}));return new Promise(((t,n)=>{window.onloadRecaptchaCallback=()=>{this.recaptchaReady(),window.grecaptcha?t(window.grecaptcha):n(new f("Recaptcha is not available"))},e().catch((()=>n(new f("Could not load Recaptcha"))))}))}))}notify(...e){this.notifyHandler&&this.notifyHandler(...e)}errorHandler(e){switch(g("Recaptcha error:",e),e){case"expired":this.notify("Прошло слишком много времени с момента начала проверки. Попробуйте еще раз.");break;case"closed":this.notify("Вы не завершили прохождение проверки. Попробуйте еще раз.");break;case"timeout":this.notify("Возможно произшла ошибка с сетевым подключением. Попробуйте ещё раз. Если не помогает, обратитесь в поддержку.");break;default:this.notify("Что-то пошло не так. Попробуйте ещё раз. Если не помогает, обратитесь в поддержку.")}}static detectCaptchaChallengeIsShown(){return new Promise((function(e){const t=document.body;const n=new MutationObserver((function(t){t.forEach((t=>{if(t.addedNodes.length){const i=t.addedNodes[0];if(!i)return;if(i.querySelectorAll('iframe[src^="https://www.google.com/recaptcha"][src*="bframe"]').length){const t=i.firstChild;t&&(n.disconnect(),e(t))}}}))}));n.observe(t,{attributeOldValue:!1,attributes:!1,characterData:!1,characterDataOldValue:!1,childList:!0,subtree:!1})}))}renderWidget(e){return new Promise(((e,t)=>{var n,i,r;const o=document.createElement("div"),s=`${m}_${b()}`;o.id=s,null===(n=document.getElementById(m))||void 0===n||n.appendChild(o);const a=C.getGrecaptchaCallbackNames();let c=NaN;function l(){var e;null===(e=window.grecaptcha)||void 0===e||e.reset(),setTimeout((()=>{o.remove()}),1e3)}C.detectCaptchaChallengeIsShown().then((e=>{if(!e.parentElement)return;const n=new MutationObserver((function(){var i,r;"hidden"!==(null===(i=e.parentElement)||void 0===i?void 0:i.style.visibility)||(null===(r=window.grecaptcha)||void 0===r?void 0:r.getResponse(c))||(n.disconnect(),t("closed"),l())}));n.observe(e.parentElement,{attributeFilter:["style"],attributes:!0})})),window[a.resolve]=()=>{var t;const n=null===(t=window.grecaptcha)||void 0===t?void 0:t.getResponse(c);e(null!=n?n:""),l()},window[a.error]=()=>{t("error"),l()},window[a.expired]=()=>{t("expired"),l()},c=null===(i=window.grecaptcha)||void 0===i?void 0:i.render(s,{callback:a.resolve,"error-callback":a.error,"expired-callback":a.expired,sitekey:this.sitekey,size:"invisible"});const d=null===(r=window.grecaptcha)||void 0===r?void 0:r.execute(c);if(!d)return t(new Error("cannot call method execute from grecaptcha")),void l();d.catch((e=>{t(e instanceof Error?e:new Error(e.toString())),l()}))}))}execute(e){return r(this,void 0,void 0,(function*(){if(this.sitekey){g("Load recaptcha script");try{yield this.loadScript()}catch(e){const t=e instanceof f?e:new f("Could not load captcha with error: "+e.toString());throw this.onErrorChallenge(this.provider,t),t}if(!window.grecaptcha){const e=new f("Recaptcha is not available in window");throw this.onErrorChallenge(this.provider,e),e}try{g("Render Recaptcha widget"),this.onRenderCaptcha(this.provider);const t=yield this.renderWidget(e);return this.onSuccessChallenge(this.provider),t}catch(e){if(this.errorHandler(e),"string"!=typeof e){const t=new f("Could not execute captcha with error: "+e.toString());throw this.onErrorChallenge(this.provider,t),t}if("expired"===e){const e=new f("Challenge or token expired");e.reason="expired",this.onWarnChallenge(this.provider,e)}if("error"===e){const e=new f("Error during captcha execution");this.onErrorChallenge(this.provider,e)}}}}))}}C.RESOLVE_FUNC_NAME="grecaptcha_resolved",C.ERROR_FUNC_NAME="grecaptcha_error",C.EXPIRED_FUNC_NAME="grecaptcha_expired",C.DEBUG=!1;const x="smartcaptcha-container",E=(...e)=>{};class k{constructor({sitekey:e,locale:t,notify:n,onRenderCaptcha:i,onSuccessChallenge:r,onWarnChallenge:o,onErrorChallenge:s,onBeforeInteractiveChallenge:a,onAfterInteractiveChallenge:c}){this.sitekey=null,this.container=null,this.provider="yandex_smart_captcha",this.locale=null!=t?t:"ru",this.sitekey=null!=e?e:null,this.notifyHandler=null!=n?n:E,this.onRenderCaptcha=null!=i?i:E,this.onSuccessChallenge=null!=r?r:E,this.onWarnChallenge=null!=o?o:E,this.onErrorChallenge=null!=s?s:E,this.onBeforeInteractiveChallenge=null!=a?a:E,this.onAfterInteractiveChallenge=null!=c?c:E,this.addDomElements()}smartCaptchaReady(){g("Smart captcha is ready",window.smartCaptcha,this)}addDomElements(){if(this.container||document.getElementById(x))return;document.body.insertAdjacentHTML("beforeend",`<div id="${x}"></div>`);const e=document.getElementById(x);e.style.display="none",this.container=e}static appendScript(e){return r(this,void 0,void 0,(function*(){if("string"!=typeof e||""===e)throw new TypeError("src script is not defined");const t=document.createElement("script");return t.src=e,document.body&&document.body.appendChild(t),new Promise(((e,n)=>{t.addEventListener("load",(()=>{e(!0)})),t.addEventListener("error",(()=>{n()}))}))}))}loadScript(){return r(this,void 0,void 0,(function*(){if(window.smartCaptcha)return Promise.resolve(window.smartCaptcha);const e=()=>r(this,void 0,void 0,(function*(){return yield k.appendScript("https://smartcaptcha.yandexcloud.net/captcha.js?render=onload&onload=onloadSmartCaptchaCallback")}));return new Promise(((t,n)=>{window.onloadSmartCaptchaCallback=()=>{this.smartCaptchaReady(),window.smartCaptcha?t(window.smartCaptcha):n(new f("SmartCaptcha is not available"))},e().catch((()=>n(new f("Could not load SmartCaptcha"))))}))}))}notify(...e){this.notifyHandler&&this.notifyHandler(...e)}errorHandler(e){switch(g("SmartCaptcha error:",e),e){case"closed":this.notify("Вы не завершили прохождение проверки. Попробуйте еще раз.");break;case"timeout":this.notify("Возможно произшла ошибка с сетевым подключением. Попробуйте ещё раз. Если не помогает, обратитесь в поддержку.");break;default:this.notify("Что-то пошло не так. Попробуйте ещё раз. Если не помогает, обратитесь в поддержку.")}}static getDebugValue(){try{if("true"===localStorage.getItem(k.LOCALE_STORAGE_DEBUG_KEY))return!0}catch(e){}return!1}renderWidget(e){var t,n,i,r,o,s,a,c;const{promise:l,resolve:d,reject:h}=Promise.withResolvers(),u=document.createElement("div"),p=`${x}_${b()}`;u.id=p,null===(t=document.getElementById(x))||void 0===t||t.appendChild(u),this.onRenderCaptcha(this.provider);const g=window.smartCaptcha.render(p,{callback:e=>{d(e),function(){var e;null===(e=window.smartCaptcha)||void 0===e||e.destroy(g),setTimeout((()=>{u.remove()}),100)}()},hideShield:!0,hl:this.locale,invisible:!0,sitekey:this.sitekey,test:k.getDebugValue()});return null===(n=window.smartCaptcha)||void 0===n||n.subscribe(g,"challenge-visible",(()=>{this.onBeforeInteractiveChallenge(this.provider)})),null===(i=window.smartCaptcha)||void 0===i||i.subscribe(g,"challenge-hidden",(()=>{this.onAfterInteractiveChallenge(this.provider),h()})),null===(r=window.smartCaptcha)||void 0===r||r.subscribe(g,"token-expired",(()=>{const e=new f("Token expired");e.reason="expired",h(e)})),null===(o=window.smartCaptcha)||void 0===o||o.subscribe(g,"success",(()=>{this.onSuccessChallenge(this.provider)})),null===(s=window.smartCaptcha)||void 0===s||s.subscribe(g,"network-error",(()=>{const e=new f("Network error");e.reason="timeout",h(e)})),null===(a=window.smartCaptcha)||void 0===a||a.subscribe(g,"javascript-error",(e=>{new f("Javascript error","fatal").cause=e,h("javascript-error")})),null===(c=window.smartCaptcha)||void 0===c||c.execute(g),l}execute(e){return r(this,void 0,void 0,(function*(){if(this.sitekey){g("Load smartCaptcha script");try{yield this.loadScript()}catch(e){const t=e instanceof f?e:new f("Could not load captcha with error: "+e.toString());throw this.onErrorChallenge(this.provider,t),t}if(!window.smartCaptcha){const e=new f("SmartCaptcha is not available in window");throw this.onErrorChallenge(this.provider,e),e}try{g("Render SmartCaptcha widget");return yield this.renderWidget(e)}catch(e){if(!e)return;if(e instanceof f)if(this.errorHandler(e),"fatal"===e.level)this.notify("Произошла непредвиденная ошибка. Мы уже делаем все возможное чтобы устранить её."),this.onErrorChallenge(this.provider,e);else switch(e.reason){case"expired":this.notify("Прошло слишком много времени с момента начала проверки. Попробуйте еще раз."),this.onWarnChallenge(this.provider,e);break;case"timeout":this.notify("Вероятно у вас проблемы с подключением к сети. Попробуйте еще раз."),this.onErrorChallenge(this.provider,e)}else{const t=new f("Could not render captcha with error","fatal");t.cause=e,this.onErrorChallenge(this.provider,t)}}}}))}}k.LOCALE_STORAGE_DEBUG_KEY="captcha:smart-captcha:debug";exports.ApiService=d,exports.CaptchaError=f,exports.CaptchaService=class{constructor(e){var t,n;switch(this.sitekey=null,this.provider=null,this.captcha=null,this.sitekey=null!==(t=e.sitekey)&&void 0!==t?t:null,this.provider=null!==(n=e.provider)&&void 0!==n?n:null,e.provider){case"yandex_smart_captcha":this.captcha=new k(e);break;case"cloudflare_turnstile":this.captcha=new w(e);break;case"recaptcha":this.captcha=new C(e)}}isEnabled(){return"string"==typeof this.sitekey&&""!==this.sitekey}execute(e){return r(this,void 0,void 0,(function*(){if(!1===this.isEnabled())return;if(!this.provider)return;if(!this.captcha)return;const t=yield this.captcha.execute(e);return g("Receive answer from captcha provider"),{captcha_provider:this.provider,captcha_token:t||""}}))}},exports.RequestPlugin=class{constructor(){this.pluginType="request"}},exports.ResponseFailPlugin=class{constructor(){this.pluginType="responseFail"}},exports.ResponseSuccessPlugin=class{constructor(){this.pluginType="responseSuccess"}},exports.SocketService=class{constructor(e){var t;this.channel=new n.BroadcastChannel("shared-socket"),this.elector=void 0,this.client=void 0,this.connected=!1,this.logger=console,this.config=e,this.logger=null!==(t=null==e?void 0:e.logger)&&void 0!==t?t:this.logger,globalThis.addEventListener("beforeunload",(()=>{this.disconnect()}))}setToken(e){var t;this.config.token=e,null===(t=this.client)||void 0===t||t.setToken(e)}createClient(){var e,t,n;if(this.connected||void 0!==this.client)return this.client;this.logger.debug("Try to connect with Centrifuge client");const r=null!==(e=this.config.transport)&&void 0!==e?e:[],o=(()=>{const e=r.find((e=>"http_stream"===e.transport));if(e)return`${new URL(e.endpoint).origin}/emulation`})();try{return this.client=new i.Centrifuge(null!==(t=this.config.transport)&&void 0!==t?t:[],{debug:null!==(n=this.config.debug)&&void 0!==n&&n,emulationEndpoint:o,getToken:()=>this.config.refreshToken(),token:this.config.token}),this.logger.debug("Create Centrifuge instance",this.client),this.client.on("disconnected",(e=>{this.connected=!1,this.logger.debug("Centrifuge connection is closed and will not be reconnected",e)})),this.client.on("connected",(e=>{this.connected=!0,this.logger.debug("Centrifuge is connected with context",e)})),this.client}catch(e){this.logger.error("Failed to create the Centrifuge instance",{reason:e.toString()})}}disconnect(){var e;void 0!==this.client&&(null===(e=this.channel)||void 0===e||e.close(),this.client.disconnect(),this.client=void 0,this.elector=void 0,this.connected=!1)}subscriptionExists(e){if(!this.client)return!1;const t=this.client.subscriptions();return Boolean(t[e])}join(e,t){var n;const i=this.createClient();if(!i)return;const r=null===(n=this.client)||void 0===n?void 0:n.newSubscription(e);this.logger.debug("Create centrifuge subscription",r),r&&(r.on("publication",(({data:e})=>{var n;this.logger.debug("Get message from ws: ",e),t(e),null===(n=this.channel)||void 0===n||n.postMessage(e)})),r.subscribe(),i.connect())}subscribe(e,t){return r(this,void 0,void 0,(function*(){this.subscriptionExists(e)?this.logger.debug("Subscription to the channel is exists. Ignore subscribe."):(this.logger.debug("Create broadcast channel with name",e),this.channel=new n.BroadcastChannel(e),this.elector=n.createLeaderElection(this.channel),this.logger.debug("Wait leader",this.elector),this.elector.onduplicate=()=>{this.disconnect(),this.subscribe(e,t)},this.elector.awaitLeadership().then((()=>{this.logger.debug("Current tab is leader",this.elector),this.join(e,t)})),this.channel.addEventListener("message",(e=>{this.logger.debug("Get message from broadcast: ",e),t(e)})))}))}unsubscribe(e){var t;const n=null===(t=this.client)||void 0===t?void 0:t.subscriptions()[e];n&&n.unsubscribe()}};
1
+ "use strict";var e=require("axios"),t=require("axios-retry"),n=require("centrifuge"),i=require("broadcast-channel");function r(e,t,n,i){return new(n||(n=Promise))((function(r,o){function s(e){try{c(i.next(e))}catch(e){o(e)}}function a(e){try{c(i.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((i=i.apply(e,t||[])).next())}))}function o(e,t,n){return e.headers=Object.assign({"Content-Type":"application/json"},e.headers),window&&window.location&&window.location.pathname&&window.location.origin&&(e.headers=Object.assign(Object.assign({},e.headers),{"X-Referer":window.location.origin+window.location.pathname})),n.length>0?function(e,t,n){return r(this,void 0,void 0,(function*(){for(const i of n)i.isApplicable(e)&&(e=yield i.execute(e,t));return e}))}(e,t,n):e}function s(e,t,n){return n.length>0?function(e,t,n){return r(this,void 0,void 0,(function*(){for(const i of n)i.isApplicable(e)&&(e=yield i.execute(e,t));return e}))}(e,t,n):e}void 0===Promise.withResolvers&&(Promise.withResolvers=()=>{let e,t;return{promise:new Promise(((n,i)=>{e=n,t=i})),reject:t,resolve:e}}),"function"==typeof SuppressedError&&SuppressedError;const a=[422,401];function c(e){return"object"==typeof e&&null!==e&&"url"in e}function l(e,t,n){return r(this,void 0,void 0,(function*(){if("object"!=typeof(i=e)||null===i||!("response"in i)||!("config"in i)||null===i.config||null===i.response)return Promise.reject(e);var i;const o=yield function(e,t,n){return r(this,void 0,void 0,(function*(){let i=e;for(const r of n)if(r.isApplicable(e)&&(i=yield r.execute(e,t),c(i)))return i;return i}))}(e,t,n);if(c(o))return t.request(o);const s=function(e){const{response:t,config:n}=e;return a.includes(t.status)&&(n._retry=!0),Object.assign({errorText:e.toString(),headers:t.headers,status:t.status,statusText:t.statusText},"object"==typeof t.data?t.data:{data:t.data})}(e);return Promise.reject(s)}))}const d=new class{createFoxApiInstance({config:n,plugins:i=[]}){const r=e.create(n),a=this.filterPlugins(i,"request"),c=this.filterPlugins(i,"responseSuccess"),d=this.filterPlugins(i,"responseFail");return r.interceptors.request.use((e=>o(e,r,[...a]))),r.interceptors.response.use((e=>s(e,r,[...c])),(e=>l(e,r,[...d]))),t(r,{retries:3,retryDelay:t.exponentialDelay}),r}createApiInstance({config:t}){return e.create(t)}createStaticApiInstance(){const t=e;return t.isApiError=e=>"object"==typeof e&&!0===e.isAxiosError,t}filterPlugins(e,t){return e?e.filter((e=>e.pluginType===t)):[]}},h="turnstile-container",u="turnstile-widget";var p=`\n<div id="${h}" class="fox-cf-turnstile">\n <div class="fox-cf-turnstile__overlay"></div>\n <div class="fox-cf-turnstile__content">\n <div class="fox-cf-turnstile__content__text">\n <h3>Надо убедиться, что вы человек</h3>\n <span>Поставьте галочку, нажав на белый квадрат ниже — проверка займёт буквально секунду</span>\n </div>\n <div id="${u}">\n <div class="fox-cf-turnstile__loader"></div>\n </div>\n </div>\n</div>\n`;class f extends Error{constructor(e,t="error"){super(e),this.level="error",this.name="CaptchaError",this.message=e,this.level=t}}function g(...e){const t=["[CaptchaService] ",...e];console.debug.apply(console,t)}const v=(...e)=>{};class w{constructor({sitekey:e,locale:t,notify:n,onRenderCaptcha:i,onSuccessChallenge:r,onErrorChallenge:o,onWarnChallenge:s,onBeforeInteractiveChallenge:a,onAfterInteractiveChallenge:c}){this.sitekey=null,this.locale="ru",this.provider="cloudflare_turnstile",this.container=null,this.notifyHandler=null!=n?n:v,this.sitekey=null!=e?e:null,this.onRenderCaptcha=null!=i?i:v,this.onSuccessChallenge=null!=r?r:v,this.onErrorChallenge=null!=o?o:v,this.onWarnChallenge=null!=s?s:v,this.onBeforeInteractiveChallenge=null!=a?a:v,this.onAfterInteractiveChallenge=null!=c?c:v,t&&(this.locale=t),this.addDomElements(),w.DEBUG&&(window.cf=this)}notify(...e){this.notifyHandler&&this.notifyHandler(...e)}addDomElements(){this.container||document.getElementById(h)||(document.body.insertAdjacentHTML("beforeend",p),document.body.insertAdjacentHTML("beforeend","<style>\n.fox-cf-turnstile {\n position: fixed;\n top: 0;\n left: 0;\n display: flex;\n align-items: center;\n justify-content: center;\n width: 100vw;\n height: 100vh;\n z-index: -1;\n}\n.fox-cf-turnstile__noscroll {\n position: fixed; \n top: var(--st, 0);\n inline-size: 100%;\n overflow-y:scroll; \n}\n.fox-cf-turnstile--showing {\n z-index: 9999;\n}\n.fox-cf-turnstile__overlay {\n position: absolute;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n background: rgba(246, 247, 251, 0.9);\n opacity: 0;\n transition: all .3s ease;\n transition-delay: .2s;\n z-index: 0;\n}\n.fox-cf-turnstile__content {\n background: white;\n border-radius: 5px;\n max-width: 500px;\n max-height: 50vh;\n position: relative;\n z-index: 1;\n box-shadow: rgba(0, 0, 0, 0.08) 0px 10px 20px 0px;\n height: 1px;\n width: 1px;\n overflow: hidden;\n transition: all .8s ease, opacity 0.3s ease;\n transition-delay: .3s;\n opacity: 0;\n display: flex;\n align-items: center;\n justify-content: center;\n flex-direction: column;\n font-size: 1.2rem;\n}\n.fox-cf-turnstile__content__text {\n flex: 1;\n margin-bottom: 20px;\n opacity: 1;\n overflow: hidden;\n transition: opacity 0.3s ease;\n text-align: center;\n}\n.fox-cf-turnstile--showing .fox-cf-turnstile__overlay, .fox-cf-turnstile--show .fox-cf-turnstile__overlay {\n opacity: 1;\n}\n.fox-cf-turnstile--showing .fox-cf-turnstile__content, .fox-cf-turnstile--show .fox-cf-turnstile__content {\n width: 100%;\n height: auto;\n min-height: 20vh;\n min-width: 30vw;\n padding: 30px;\n opacity: 1;\n}\n.fox-cf-turnstile__content__text h3 {\n font-size: 1.4rem;\n}\n.fox-cf-turnstile__loader {\n font-size: 10px;\n margin: 50px auto;\n text-indent: -9999em;\n width: 5em;\n height: 5em;\n border-radius: 50%;\n background: #8b1feb;\n background: -moz-linear-gradient(left, #8b1feb 10%, rgba(139,31,235, 0) 42%);\n background: -webkit-linear-gradient(left, #8b1feb 10%, rgba(139,31,235, 0) 42%);\n background: -o-linear-gradient(left, #8b1feb 10%, rgba(139,31,235, 0) 42%);\n background: -ms-linear-gradient(left, #8b1feb 10%, rgba(139,31,235, 0) 42%);\n background: linear-gradient(to right, #8b1feb 10%, rgba(139,31,235, 0) 42%);\n position: relative;\n -webkit-animation: load3 1.4s infinite linear;\n animation: load3 1.4s infinite linear;\n -webkit-transform: translateZ(0);\n -ms-transform: translateZ(0);\n transform: translateZ(0);\n}\n.fox-cf-turnstile__loader:before {\n width: 50%;\n height: 50%;\n background: #8b1feb;\n border-radius: 100% 0 0 0;\n position: absolute;\n top: 0;\n left: 0;\n content: '';\n}\n.fox-cf-turnstile__loader:after {\n background: white;\n width: 75%;\n height: 75%;\n border-radius: 50%;\n content: '';\n margin: auto;\n position: absolute;\n top: 0;\n left: 0;\n bottom: 0;\n right: 0;\n}\n@-webkit-keyframes load3 {\n 0% {\n -webkit-transform: rotate(0deg);\n transform: rotate(0deg);\n }\n 100% {\n -webkit-transform: rotate(360deg);\n transform: rotate(360deg);\n }\n}\n@keyframes load3 {\n 0% {\n -webkit-transform: rotate(0deg);\n transform: rotate(0deg);\n }\n 100% {\n -webkit-transform: rotate(360deg);\n transform: rotate(360deg);\n }\n} \n</style>"),this.container=document.getElementById(h))}static appendScript(e){return r(this,void 0,void 0,(function*(){if("string"!=typeof e||""===e)throw new TypeError("src script is not defined");const t=document.createElement("script");return t.src=e,document.body&&document.body.appendChild(t),new Promise(((e,n)=>{t.addEventListener("load",(()=>{e(!0)})),t.addEventListener("error",(()=>{n()}))}))}))}show(){var e;null===(e=this.container)||void 0===e||e.classList.add("fox-cf-turnstile--showing"),w.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"),w.bodyScrollUnlock()}loadScript(){return r(this,void 0,void 0,(function*(){if(window.turnstile)return Promise.resolve(window.turnstile);const e=()=>r(this,void 0,void 0,(function*(){return yield w.appendScript("https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit&onload=onloadTurnstileCallback")}));return new Promise(((t,n)=>{window.onloadTurnstileCallback=()=>{this.turnstileReady(),window.turnstile?t(window.turnstile):n(new f("Cloudflare Turnstile is not available"))},e().catch((()=>n(new f("Could not load Cloudflare Turnstile"))))}))}))}turnstileReady(){var e,t;g("Cloudflare Turnstile is ready",window.turnstile),null===(t=null===(e=this.container)||void 0===e?void 0:e.querySelector(".fox-cf-turnstile__loader"))||void 0===t||t.remove()}static normalizeLocation(e=""){return e.substring(0,31).replace(/\//g,"_")}static bodyScrollLock(){const e=document.body;e.style.setProperty("--st",`-${document.documentElement.scrollTop}px`),e.classList.add("fox-cf-turnstile__noscroll")}static bodyScrollUnlock(){document.body.classList.remove("fox-cf-turnstile__noscroll")}renderWidget(e){return r(this,void 0,void 0,(function*(){return new Promise(((t,n)=>{var i;let r="";function o(){var e;null===(e=window.turnstile)||void 0===e||e.reset(r),setTimeout((()=>{var e;null===(e=window.turnstile)||void 0===e||e.remove(r)}),500)}r=null===(i=window.turnstile)||void 0===i?void 0:i.render(`#${u}`,{action:w.normalizeLocation(null==e?void 0:e.location),"after-interactive-callback":()=>{g("after-interactive-callback"),this.onAfterInteractiveChallenge(this.provider)},"before-interactive-callback":()=>{g("before-interactive-callback"),this.onBeforeInteractiveChallenge(this.provider),this.show()},callback:e=>{g("Challenge Success"),this.hide(),t(e),o()},"error-callback":e=>{n(e),o()},"expired-callback":()=>{this.hide(),n("expired"),o()},language:this.locale,sitekey:this.sitekey,theme:"light","timeout-callback":()=>{this.hide(),n("timeout"),o()},"unsupported-callback":()=>{n("110500"),o()}})}))}))}errorHandler(e){g("Captcha error with code:",e);let t=[...w.NO_RETRY_ERROR_CODES];if("string"!=typeof e)return void this.notify("Что-то пошло не так. Попробуйте ещё раз. Если не помогает, обратитесь в поддержку.");const n=e;switch(!0){case n.startsWith("110500"):t=t.filter((e=>!e.startsWith("110500"))),this.notify("Ваш браузер устарел. Попробуйте ещё раз, используя другой браузер или устройство.");break;case n.startsWith("110600"):t=t.filter((e=>!e.startsWith("110600"))),this.notify("Прошло слишком много времени с момента начала проверки. Попробуйте еще раз.");break;case n.startsWith("110510"):t=t.filter((e=>!e.startsWith("110510"))),this.notify("Что-то пошло не так — возможно, вы используете технологию подмены User agent. Попробуйте ещё раз или обратитесь в поддержку");break;case n.startsWith("200010"):this.notify('Что-то пошло не так. Попробуйте <a href="https://yandex.ru/support/common/browsers-settings/cache.html" target="_blank" rel="nofollow noopener">очистить кеш браузера</a>. Если не помогает, обратитесь в поддержку.');break;case n.startsWith("200100"):t=t.filter((e=>!e.startsWith("200100"))),this.notify("Кажется, часы на вашем компьютере показывают неправильное время. Настройте часы и попробуйте ещё раз.");break;case n.startsWith("300"):case n.startsWith("600"):t=t.filter((e=>!e.startsWith("300")||!e.startsWith("600"))),this.notify("Потвердите еще раз что вы человек")}t.some((e=>n.startsWith(e)))&&this.notify(`Что-то пошло не так, код ошибки — ${n}. Мы уже знаем о проблеме и скоро всё поправим. Попробуйте ещё раз через некоторое время.`)}execute(e){return r(this,void 0,void 0,(function*(){if(this.sitekey){g("Load cloudflare script");try{yield this.loadScript()}catch(e){const t=e instanceof f?e:new f("Could not load captcha with error: "+e.toString());throw this.onErrorChallenge(this.provider,t),t}if(!window.turnstile){const e=new f("Cloudflare Turnstile is not available in window");throw this.onErrorChallenge(this.provider,e),e}try{g("Render turnstile widget"),this.onRenderCaptcha(this.provider);const t=yield this.renderWidget(e);return this.onSuccessChallenge(this.provider),t}catch(e){if(this.errorHandler(e),"string"!=typeof e){const t=new f("Could not execute captcha with error: "+e.toString());throw this.onErrorChallenge(this.provider,t),t}if(["110200","110100","110110"].some((t=>e.startsWith(t)))){const t=new f("Invalid sitekey or domain is not allowed");throw t.code=e,this.onErrorChallenge(this.provider,t),t}if(w.NO_RETRY_ERROR_CODES.some((t=>e.startsWith(t)))){const t=new f("Captcha challenge is failed");t.code=e,this.onErrorChallenge(this.provider,t)}else{const t=new f("Captcha challenge has error");t.reason=["timeout","expired"].includes(e)?e:void 0,t.code=e,this.onWarnChallenge(this.provider,t)}}}}))}}w.DEBUG=!1,w.NO_RETRY_ERROR_CODES=["100","105","106","110100","110110","110200","110420","110430","110500","110510","120","200010","200100"];const b="recaptcha-widget";function m(){let e=(new Date).getTime(),t="undefined"!=typeof performance&&performance.now&&1e3*performance.now()||0;return"xxxx-xxxx-4xxx-yxxx".replace(/[xy]/g,(function(n){let i=16*Math.random();return e>0?(i=(e+i)%16|0,e=Math.floor(e/16)):(i=(t+i)%16|0,t=Math.floor(t/16)),("x"===n?i:3&i|8).toString(16)}))}const y=(...e)=>{};class C{constructor({sitekey:e,locale:t,notify:n,onRenderCaptcha:i,onSuccessChallenge:r,onWarnChallenge:o,onErrorChallenge:s}){this.sitekey=null,this.locale="ru",this.container=null,this.provider="recaptcha",this.sitekey=null!=e?e:null,this.notifyHandler=null!=n?n:y,this.onRenderCaptcha=null!=i?i:y,this.onSuccessChallenge=null!=r?r:y,this.onWarnChallenge=null!=o?o:y,this.onErrorChallenge=null!=s?s:y,t&&(this.locale=t),this.addDomElements(),C.DEBUG&&(window.gr=this)}recaptchaReady(){g("Google recaptcha is ready",window.grecaptcha,this)}addDomElements(){if(this.container||document.getElementById(b))return;document.body.insertAdjacentHTML("beforeend",`<div id="${b}"></div>`);const e=document.getElementById(b);e.style.display="none",this.container=e}static getGrecaptchaCallbackNames(){return{error:`${C.ERROR_FUNC_NAME}`,expired:`${C.EXPIRED_FUNC_NAME}`,resolve:`${C.RESOLVE_FUNC_NAME}`}}static appendScript(e){return r(this,void 0,void 0,(function*(){if("string"!=typeof e||""===e)throw new TypeError("src script is not defined");const t=document.createElement("script");return t.src=e,document.body&&document.body.appendChild(t),new Promise(((e,n)=>{t.addEventListener("load",(()=>{e(!0)})),t.addEventListener("error",(()=>{n()}))}))}))}loadScript(){return r(this,void 0,void 0,(function*(){if(window.grecaptcha)return Promise.resolve(window.grecaptcha);const e=()=>r(this,void 0,void 0,(function*(){return yield C.appendScript(`https://www.google.com/recaptcha/api.js?hl=${this.locale}&onload=onloadRecaptchaCallback`)}));return new Promise(((t,n)=>{window.onloadRecaptchaCallback=()=>{this.recaptchaReady(),window.grecaptcha?t(window.grecaptcha):n(new f("Recaptcha is not available"))},e().catch((()=>n(new f("Could not load Recaptcha"))))}))}))}notify(...e){this.notifyHandler&&this.notifyHandler(...e)}errorHandler(e){switch(g("Recaptcha error:",e),e){case"expired":this.notify("Прошло слишком много времени с момента начала проверки. Попробуйте еще раз.");break;case"closed":this.notify("Вы не завершили прохождение проверки. Попробуйте еще раз.");break;case"timeout":this.notify("Возможно произшла ошибка с сетевым подключением. Попробуйте ещё раз. Если не помогает, обратитесь в поддержку.");break;default:this.notify("Что-то пошло не так. Попробуйте ещё раз. Если не помогает, обратитесь в поддержку.")}}static detectCaptchaChallengeIsShown(){return new Promise((function(e){const t=document.body;const n=new MutationObserver((function(t){t.forEach((t=>{if(t.addedNodes.length){const i=t.addedNodes[0];if(!i)return;if(i.querySelectorAll('iframe[src^="https://www.google.com/recaptcha"][src*="bframe"]').length){const t=i.firstChild;t&&(n.disconnect(),e(t))}}}))}));n.observe(t,{attributeOldValue:!1,attributes:!1,characterData:!1,characterDataOldValue:!1,childList:!0,subtree:!1})}))}renderWidget(e){return new Promise(((e,t)=>{var n,i,r;const o=document.createElement("div"),s=`${b}_${m()}`;o.id=s,null===(n=document.getElementById(b))||void 0===n||n.appendChild(o);const a=C.getGrecaptchaCallbackNames();let c=NaN;function l(){var e;null===(e=window.grecaptcha)||void 0===e||e.reset(),setTimeout((()=>{o.remove()}),1e3)}C.detectCaptchaChallengeIsShown().then((e=>{if(!e.parentElement)return;const n=new MutationObserver((function(){var i,r;"hidden"!==(null===(i=e.parentElement)||void 0===i?void 0:i.style.visibility)||(null===(r=window.grecaptcha)||void 0===r?void 0:r.getResponse(c))||(n.disconnect(),t("closed"),l())}));n.observe(e.parentElement,{attributeFilter:["style"],attributes:!0})})),window[a.resolve]=()=>{var t;const n=null===(t=window.grecaptcha)||void 0===t?void 0:t.getResponse(c);e(null!=n?n:""),l()},window[a.error]=()=>{t("error"),l()},window[a.expired]=()=>{t("expired"),l()},c=null===(i=window.grecaptcha)||void 0===i?void 0:i.render(s,{callback:a.resolve,"error-callback":a.error,"expired-callback":a.expired,sitekey:this.sitekey,size:"invisible"});const d=null===(r=window.grecaptcha)||void 0===r?void 0:r.execute(c);if(!d)return t(new Error("cannot call method execute from grecaptcha")),void l();d.catch((e=>{t(e instanceof Error?e:new Error(e.toString())),l()}))}))}execute(e){return r(this,void 0,void 0,(function*(){if(this.sitekey){g("Load recaptcha script");try{yield this.loadScript()}catch(e){const t=e instanceof f?e:new f("Could not load captcha with error: "+e.toString());throw this.onErrorChallenge(this.provider,t),t}if(!window.grecaptcha){const e=new f("Recaptcha is not available in window");throw this.onErrorChallenge(this.provider,e),e}try{g("Render Recaptcha widget"),this.onRenderCaptcha(this.provider);const t=yield this.renderWidget(e);return this.onSuccessChallenge(this.provider),t}catch(e){if(this.errorHandler(e),"string"!=typeof e){const t=new f("Could not execute captcha with error: "+e.toString());throw this.onErrorChallenge(this.provider,t),t}if("expired"===e){const e=new f("Challenge or token expired");e.reason="expired",this.onWarnChallenge(this.provider,e)}if("error"===e){const e=new f("Error during captcha execution");this.onErrorChallenge(this.provider,e)}}}}))}}C.RESOLVE_FUNC_NAME="grecaptcha_resolved",C.ERROR_FUNC_NAME="grecaptcha_error",C.EXPIRED_FUNC_NAME="grecaptcha_expired",C.DEBUG=!1;const x="smartcaptcha-container",E=(...e)=>{};class k{constructor({sitekey:e,locale:t,notify:n,onRenderCaptcha:i,onSuccessChallenge:r,onWarnChallenge:o,onErrorChallenge:s,onBeforeInteractiveChallenge:a,onAfterInteractiveChallenge:c}){this.sitekey=null,this.container=null,this.provider="yandex_smart_captcha",this.locale=null!=t?t:"ru",this.sitekey=null!=e?e:null,this.notifyHandler=null!=n?n:E,this.onRenderCaptcha=null!=i?i:E,this.onSuccessChallenge=null!=r?r:E,this.onWarnChallenge=null!=o?o:E,this.onErrorChallenge=null!=s?s:E,this.onBeforeInteractiveChallenge=null!=a?a:E,this.onAfterInteractiveChallenge=null!=c?c:E,this.addDomElements()}smartCaptchaReady(){g("Smart captcha is ready",window.smartCaptcha,this)}addDomElements(){if(this.container||document.getElementById(x))return;document.body.insertAdjacentHTML("beforeend",`<div id="${x}"></div>`);const e=document.getElementById(x);e.style.display="none",this.container=e}static appendScript(e){return r(this,void 0,void 0,(function*(){if("string"!=typeof e||""===e)throw new TypeError("src script is not defined");const t=document.createElement("script");return t.src=e,document.body&&document.body.appendChild(t),new Promise(((e,n)=>{t.addEventListener("load",(()=>{e(!0)})),t.addEventListener("error",(()=>{n()}))}))}))}loadScript(){return r(this,void 0,void 0,(function*(){if(window.smartCaptcha)return Promise.resolve(window.smartCaptcha);const e=()=>r(this,void 0,void 0,(function*(){return yield k.appendScript("https://smartcaptcha.yandexcloud.net/captcha.js?render=onload&onload=onloadSmartCaptchaCallback")}));return new Promise(((t,n)=>{window.onloadSmartCaptchaCallback=()=>{this.smartCaptchaReady(),window.smartCaptcha?t(window.smartCaptcha):n(new f("SmartCaptcha is not available"))},e().catch((()=>n(new f("Could not load SmartCaptcha"))))}))}))}notify(...e){this.notifyHandler&&this.notifyHandler(...e)}errorHandler(e){switch(g("SmartCaptcha error:",e),e){case"closed":this.notify("Вы не завершили прохождение проверки. Попробуйте еще раз.");break;case"timeout":this.notify("Возможно произшла ошибка с сетевым подключением. Попробуйте ещё раз. Если не помогает, обратитесь в поддержку.");break;default:this.notify("Что-то пошло не так. Попробуйте ещё раз. Если не помогает, обратитесь в поддержку.")}}static getDebugValue(){try{if("true"===localStorage.getItem(k.LOCALE_STORAGE_DEBUG_KEY))return!0}catch(e){}return!1}renderWidget(e){var t,n,i,r,o,s,a,c;const{promise:l,resolve:d,reject:h}=Promise.withResolvers(),u=document.createElement("div"),p=`${x}_${m()}`;u.id=p,null===(t=document.getElementById(x))||void 0===t||t.appendChild(u),this.onRenderCaptcha(this.provider);const g=window.smartCaptcha.render(p,{callback:e=>{d(e),function(){var e;null===(e=window.smartCaptcha)||void 0===e||e.destroy(g),setTimeout((()=>{u.remove()}),100)}()},hideShield:!0,hl:this.locale,invisible:!0,sitekey:this.sitekey,test:k.getDebugValue()});return null===(n=window.smartCaptcha)||void 0===n||n.subscribe(g,"challenge-visible",(()=>{this.onBeforeInteractiveChallenge(this.provider)})),null===(i=window.smartCaptcha)||void 0===i||i.subscribe(g,"challenge-hidden",(()=>{this.onAfterInteractiveChallenge(this.provider),h()})),null===(r=window.smartCaptcha)||void 0===r||r.subscribe(g,"token-expired",(()=>{const e=new f("Token expired");e.reason="expired",h(e)})),null===(o=window.smartCaptcha)||void 0===o||o.subscribe(g,"success",(()=>{this.onSuccessChallenge(this.provider)})),null===(s=window.smartCaptcha)||void 0===s||s.subscribe(g,"network-error",(()=>{const e=new f("Network error");e.reason="timeout",h(e)})),null===(a=window.smartCaptcha)||void 0===a||a.subscribe(g,"javascript-error",(e=>{new f("Javascript error","fatal").cause=e,h("javascript-error")})),null===(c=window.smartCaptcha)||void 0===c||c.execute(g),l}execute(e){return r(this,void 0,void 0,(function*(){if(this.sitekey){g("Load smartCaptcha script");try{yield this.loadScript()}catch(e){const t=e instanceof f?e:new f("Could not load captcha with error: "+e.toString());throw this.onErrorChallenge(this.provider,t),t}if(!window.smartCaptcha){const e=new f("SmartCaptcha is not available in window");throw this.onErrorChallenge(this.provider,e),e}try{g("Render SmartCaptcha widget");return yield this.renderWidget(e)}catch(e){if(!e)return;if(e instanceof f)if(this.errorHandler(e),"fatal"===e.level)this.notify("Произошла непредвиденная ошибка. Мы уже делаем все возможное чтобы устранить её."),this.onErrorChallenge(this.provider,e);else switch(e.reason){case"expired":this.notify("Прошло слишком много времени с момента начала проверки. Попробуйте еще раз."),this.onWarnChallenge(this.provider,e);break;case"timeout":this.notify("Вероятно у вас проблемы с подключением к сети. Попробуйте еще раз."),this.onErrorChallenge(this.provider,e)}else{const t=new f("Could not render captcha with error","fatal");t.cause=e,this.onErrorChallenge(this.provider,t)}}}}))}}k.LOCALE_STORAGE_DEBUG_KEY="captcha:smart-captcha:debug";function _(e,t){return new i.BroadcastChannel(e,Object.assign(Object.assign({},t),{type:/iP(ad|od|hone)/i.test(window.navigator.userAgent)?"localstorage":void 0}))}exports.ApiService=d,exports.CaptchaError=f,exports.CaptchaService=class{constructor(e){var t,n;switch(this.sitekey=null,this.provider=null,this.captcha=null,this.sitekey=null!==(t=e.sitekey)&&void 0!==t?t:null,this.provider=null!==(n=e.provider)&&void 0!==n?n:null,e.provider){case"yandex_smart_captcha":this.captcha=new k(e);break;case"cloudflare_turnstile":this.captcha=new w(e);break;case"recaptcha":this.captcha=new C(e)}}isEnabled(){return"string"==typeof this.sitekey&&""!==this.sitekey}execute(e){return r(this,void 0,void 0,(function*(){if(!1===this.isEnabled())return;if(!this.provider)return;if(!this.captcha)return;const t=yield this.captcha.execute(e);return g("Receive answer from captcha provider"),{captcha_provider:this.provider,captcha_token:t||""}}))}},exports.RequestPlugin=class{constructor(){this.pluginType="request"}},exports.ResponseFailPlugin=class{constructor(){this.pluginType="responseFail"}},exports.ResponseSuccessPlugin=class{constructor(){this.pluginType="responseSuccess"}},exports.SocketService=class{constructor(e){var t;this.elector=void 0,this.client=void 0,this.connected=!1,this.logger=console,this.config=e,this.logger=null!==(t=null==e?void 0:e.logger)&&void 0!==t?t:this.logger,globalThis.addEventListener("beforeunload",(()=>{this.disconnect()}))}setToken(e){var t;this.config.token=e,null===(t=this.client)||void 0===t||t.setToken(e)}createClient(){var e,t,i;if(this.connected||void 0!==this.client)return this.client;this.logger.debug("Try to connect with Centrifuge client");const r=null!==(e=this.config.transport)&&void 0!==e?e:[],o=(()=>{const e=r.find((e=>"http_stream"===e.transport));if(e)return`${new URL(e.endpoint).origin}/emulation`})();try{return this.client=new n.Centrifuge(null!==(t=this.config.transport)&&void 0!==t?t:[],{debug:null!==(i=this.config.debug)&&void 0!==i&&i,emulationEndpoint:o,getToken:()=>this.config.refreshToken(),token:this.config.token}),this.logger.debug("Create Centrifuge instance",this.client),this.client.on("disconnected",(e=>{this.connected=!1,this.logger.debug("Centrifuge connection is closed and will not be reconnected",e)})),this.client.on("connected",(e=>{this.connected=!0,this.logger.debug("Centrifuge is connected with context",e)})),this.client}catch(e){this.logger.error("Failed to create the Centrifuge instance",{reason:e.toString()})}}disconnect(){var e;void 0!==this.client&&(null===(e=this.channel)||void 0===e||e.close(),this.client.disconnect(),this.client=void 0,this.elector=void 0,this.connected=!1)}subscriptionExists(e){if(!this.client)return!1;const t=this.client.subscriptions();return Boolean(t[e])}join(e,t){var n;const i=this.createClient();if(!i)return;const r=null===(n=this.client)||void 0===n?void 0:n.newSubscription(e);this.logger.debug("Create centrifuge subscription",r),r&&(r.on("publication",(({data:e})=>{var n;this.logger.debug("Get message from ws: ",e),t(e),null===(n=this.channel)||void 0===n||n.postMessage(e)})),r.subscribe(),i.connect())}createChannel(e,t){return _(e,{idb:{onclose:()=>{this.logger.debug("IDB channel is closed");const n=this.subscriptionExists(e);this.disconnect(),n&&this.subscribe(e,t)}}})}subscribe(e,t){return r(this,void 0,void 0,(function*(){this.subscriptionExists(e)?this.logger.debug("Subscription to the channel is exists. Ignore subscribe."):(this.logger.debug("Create broadcast channel with name",e),this.channel=this.createChannel(e,t),this.elector=i.createLeaderElection(this.channel),this.logger.debug("Wait leader",this.elector),this.elector.onduplicate=()=>{this.disconnect(),this.subscribe(e,t)},this.elector.awaitLeadership().then((()=>{this.logger.debug("Current tab is leader",this.elector),this.join(e,t)})),this.channel.addEventListener("message",(e=>{this.logger.debug("Get message from broadcast: ",e),t(e)})))}))}unsubscribe(e){var t;const n=null===(t=this.client)||void 0===t?void 0:t.subscriptions()[e];n&&n.unsubscribe()}},exports.createBroadcastChannel=_;
package/index.js.flow CHANGED
@@ -5,6 +5,8 @@
5
5
  * @flow
6
6
  */
7
7
 
8
+ import { BroadcastChannel as BroadcastChannel$1, LeaderElector } from "broadcast-channel";
9
+ import type { BroadcastChannelOptions } from "broadcast-channel";
8
10
  export interface ApiTransformer {
9
11
  (data: any, headers?: any): any;
10
12
  }
@@ -402,4 +404,12 @@ declare export class SocketService {
402
404
  */
403
405
  unsubscribe(channelName: string): void;
404
406
  }
405
- declare export { apiServiceInstance as ApiService };
407
+ declare export function createBroadcastChannel<T>(
408
+ name: string,
409
+ opts?: BroadcastChannelOptions
410
+ ): BroadcastChannel$1<T>;
411
+ declare export {
412
+ BroadcastChannel$1 as BroadcastChannel,
413
+ LeaderElector,
414
+ apiServiceInstance as ApiService,
415
+ };
package/index.mjs CHANGED
@@ -1 +1 @@
1
- import e from"axios";import t from"axios-retry";import{BroadcastChannel as n,createLeaderElection as i}from"broadcast-channel";import{Centrifuge as r}from"centrifuge";function o(e,t,n,i){return new(n||(n=Promise))((function(r,o){function s(e){try{c(i.next(e))}catch(e){o(e)}}function a(e){try{c(i.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((i=i.apply(e,t||[])).next())}))}function s(e,t,n){return e.headers=Object.assign({"Content-Type":"application/json"},e.headers),window&&window.location&&window.location.pathname&&window.location.origin&&(e.headers=Object.assign(Object.assign({},e.headers),{"X-Referer":window.location.origin+window.location.pathname})),n.length>0?function(e,t,n){return o(this,void 0,void 0,(function*(){for(const i of n)i.isApplicable(e)&&(e=yield i.execute(e,t));return e}))}(e,t,n):e}function a(e,t,n){return n.length>0?function(e,t,n){return o(this,void 0,void 0,(function*(){for(const i of n)i.isApplicable(e)&&(e=yield i.execute(e,t));return e}))}(e,t,n):e}void 0===Promise.withResolvers&&(Promise.withResolvers=()=>{let e,t;return{promise:new Promise(((n,i)=>{e=n,t=i})),reject:t,resolve:e}}),"function"==typeof SuppressedError&&SuppressedError;const c=[422,401];function l(e){return"object"==typeof e&&null!==e&&"url"in e}function d(e,t,n){return o(this,void 0,void 0,(function*(){if("object"!=typeof(i=e)||null===i||!("response"in i)||!("config"in i)||null===i.config||null===i.response)return Promise.reject(e);var i;const r=yield function(e,t,n){return o(this,void 0,void 0,(function*(){let i=e;for(const r of n)if(r.isApplicable(e)&&(i=yield r.execute(e,t),l(i)))return i;return i}))}(e,t,n);if(l(r))return t.request(r);const s=function(e){const{response:t,config:n}=e;return c.includes(t.status)&&(n._retry=!0),Object.assign({errorText:e.toString(),headers:t.headers,status:t.status,statusText:t.statusText},"object"==typeof t.data?t.data:{data:t.data})}(e);return Promise.reject(s)}))}class h{constructor(){this.pluginType="request"}}class u{constructor(){this.pluginType="responseSuccess"}}class p{constructor(){this.pluginType="responseFail"}}const f=new class{createFoxApiInstance({config:n,plugins:i=[]}){const r=e.create(n),o=this.filterPlugins(i,"request"),c=this.filterPlugins(i,"responseSuccess"),l=this.filterPlugins(i,"responseFail");return r.interceptors.request.use((e=>s(e,r,[...o]))),r.interceptors.response.use((e=>a(e,r,[...c])),(e=>d(e,r,[...l]))),t(r,{retries:3,retryDelay:t.exponentialDelay}),r}createApiInstance({config:t}){return e.create(t)}createStaticApiInstance(){const t=e;return t.isApiError=e=>"object"==typeof e&&!0===e.isAxiosError,t}filterPlugins(e,t){return e?e.filter((e=>e.pluginType===t)):[]}},g="turnstile-container",v="turnstile-widget";var w=`\n<div id="${g}" class="fox-cf-turnstile">\n <div class="fox-cf-turnstile__overlay"></div>\n <div class="fox-cf-turnstile__content">\n <div class="fox-cf-turnstile__content__text">\n <h3>Надо убедиться, что вы человек</h3>\n <span>Поставьте галочку, нажав на белый квадрат ниже — проверка займёт буквально секунду</span>\n </div>\n <div id="${v}">\n <div class="fox-cf-turnstile__loader"></div>\n </div>\n </div>\n</div>\n`;class m extends Error{constructor(e,t="error"){super(e),this.level="error",this.name="CaptchaError",this.message=e,this.level=t}}function b(...e){const t=["[CaptchaService] ",...e];console.debug.apply(console,t)}const y=(...e)=>{};class C{constructor({sitekey:e,locale:t,notify:n,onRenderCaptcha:i,onSuccessChallenge:r,onErrorChallenge:o,onWarnChallenge:s,onBeforeInteractiveChallenge:a,onAfterInteractiveChallenge:c}){this.sitekey=null,this.locale="ru",this.provider="cloudflare_turnstile",this.container=null,this.notifyHandler=null!=n?n:y,this.sitekey=null!=e?e:null,this.onRenderCaptcha=null!=i?i:y,this.onSuccessChallenge=null!=r?r:y,this.onErrorChallenge=null!=o?o:y,this.onWarnChallenge=null!=s?s:y,this.onBeforeInteractiveChallenge=null!=a?a:y,this.onAfterInteractiveChallenge=null!=c?c:y,t&&(this.locale=t),this.addDomElements(),C.DEBUG&&(window.cf=this)}notify(...e){this.notifyHandler&&this.notifyHandler(...e)}addDomElements(){this.container||document.getElementById(g)||(document.body.insertAdjacentHTML("beforeend",w),document.body.insertAdjacentHTML("beforeend","<style>\n.fox-cf-turnstile {\n position: fixed;\n top: 0;\n left: 0;\n display: flex;\n align-items: center;\n justify-content: center;\n width: 100vw;\n height: 100vh;\n z-index: -1;\n}\n.fox-cf-turnstile__noscroll {\n position: fixed; \n top: var(--st, 0);\n inline-size: 100%;\n overflow-y:scroll; \n}\n.fox-cf-turnstile--showing {\n z-index: 9999;\n}\n.fox-cf-turnstile__overlay {\n position: absolute;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n background: rgba(246, 247, 251, 0.9);\n opacity: 0;\n transition: all .3s ease;\n transition-delay: .2s;\n z-index: 0;\n}\n.fox-cf-turnstile__content {\n background: white;\n border-radius: 5px;\n max-width: 500px;\n max-height: 50vh;\n position: relative;\n z-index: 1;\n box-shadow: rgba(0, 0, 0, 0.08) 0px 10px 20px 0px;\n height: 1px;\n width: 1px;\n overflow: hidden;\n transition: all .8s ease, opacity 0.3s ease;\n transition-delay: .3s;\n opacity: 0;\n display: flex;\n align-items: center;\n justify-content: center;\n flex-direction: column;\n font-size: 1.2rem;\n}\n.fox-cf-turnstile__content__text {\n flex: 1;\n margin-bottom: 20px;\n opacity: 1;\n overflow: hidden;\n transition: opacity 0.3s ease;\n text-align: center;\n}\n.fox-cf-turnstile--showing .fox-cf-turnstile__overlay, .fox-cf-turnstile--show .fox-cf-turnstile__overlay {\n opacity: 1;\n}\n.fox-cf-turnstile--showing .fox-cf-turnstile__content, .fox-cf-turnstile--show .fox-cf-turnstile__content {\n width: 100%;\n height: auto;\n min-height: 20vh;\n min-width: 30vw;\n padding: 30px;\n opacity: 1;\n}\n.fox-cf-turnstile__content__text h3 {\n font-size: 1.4rem;\n}\n.fox-cf-turnstile__loader {\n font-size: 10px;\n margin: 50px auto;\n text-indent: -9999em;\n width: 5em;\n height: 5em;\n border-radius: 50%;\n background: #8b1feb;\n background: -moz-linear-gradient(left, #8b1feb 10%, rgba(139,31,235, 0) 42%);\n background: -webkit-linear-gradient(left, #8b1feb 10%, rgba(139,31,235, 0) 42%);\n background: -o-linear-gradient(left, #8b1feb 10%, rgba(139,31,235, 0) 42%);\n background: -ms-linear-gradient(left, #8b1feb 10%, rgba(139,31,235, 0) 42%);\n background: linear-gradient(to right, #8b1feb 10%, rgba(139,31,235, 0) 42%);\n position: relative;\n -webkit-animation: load3 1.4s infinite linear;\n animation: load3 1.4s infinite linear;\n -webkit-transform: translateZ(0);\n -ms-transform: translateZ(0);\n transform: translateZ(0);\n}\n.fox-cf-turnstile__loader:before {\n width: 50%;\n height: 50%;\n background: #8b1feb;\n border-radius: 100% 0 0 0;\n position: absolute;\n top: 0;\n left: 0;\n content: '';\n}\n.fox-cf-turnstile__loader:after {\n background: white;\n width: 75%;\n height: 75%;\n border-radius: 50%;\n content: '';\n margin: auto;\n position: absolute;\n top: 0;\n left: 0;\n bottom: 0;\n right: 0;\n}\n@-webkit-keyframes load3 {\n 0% {\n -webkit-transform: rotate(0deg);\n transform: rotate(0deg);\n }\n 100% {\n -webkit-transform: rotate(360deg);\n transform: rotate(360deg);\n }\n}\n@keyframes load3 {\n 0% {\n -webkit-transform: rotate(0deg);\n transform: rotate(0deg);\n }\n 100% {\n -webkit-transform: rotate(360deg);\n transform: rotate(360deg);\n }\n} \n</style>"),this.container=document.getElementById(g))}static appendScript(e){return o(this,void 0,void 0,(function*(){if("string"!=typeof e||""===e)throw new TypeError("src script is not defined");const t=document.createElement("script");return t.src=e,document.body&&document.body.appendChild(t),new Promise(((e,n)=>{t.addEventListener("load",(()=>{e(!0)})),t.addEventListener("error",(()=>{n()}))}))}))}show(){var e;null===(e=this.container)||void 0===e||e.classList.add("fox-cf-turnstile--showing"),C.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"),C.bodyScrollUnlock()}loadScript(){return o(this,void 0,void 0,(function*(){if(window.turnstile)return Promise.resolve(window.turnstile);const e=()=>o(this,void 0,void 0,(function*(){return yield C.appendScript("https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit&onload=onloadTurnstileCallback")}));return new Promise(((t,n)=>{window.onloadTurnstileCallback=()=>{this.turnstileReady(),window.turnstile?t(window.turnstile):n(new m("Cloudflare Turnstile is not available"))},e().catch((()=>n(new m("Could not load Cloudflare Turnstile"))))}))}))}turnstileReady(){var e,t;b("Cloudflare Turnstile is ready",window.turnstile),null===(t=null===(e=this.container)||void 0===e?void 0:e.querySelector(".fox-cf-turnstile__loader"))||void 0===t||t.remove()}static normalizeLocation(e=""){return e.substring(0,31).replace(/\//g,"_")}static bodyScrollLock(){const e=document.body;e.style.setProperty("--st",`-${document.documentElement.scrollTop}px`),e.classList.add("fox-cf-turnstile__noscroll")}static bodyScrollUnlock(){document.body.classList.remove("fox-cf-turnstile__noscroll")}renderWidget(e){return o(this,void 0,void 0,(function*(){return new Promise(((t,n)=>{var i;let r="";function o(){var e;null===(e=window.turnstile)||void 0===e||e.reset(r),setTimeout((()=>{var e;null===(e=window.turnstile)||void 0===e||e.remove(r)}),500)}r=null===(i=window.turnstile)||void 0===i?void 0:i.render(`#${v}`,{action:C.normalizeLocation(null==e?void 0:e.location),"after-interactive-callback":()=>{b("after-interactive-callback"),this.onAfterInteractiveChallenge(this.provider)},"before-interactive-callback":()=>{b("before-interactive-callback"),this.onBeforeInteractiveChallenge(this.provider),this.show()},callback:e=>{b("Challenge Success"),this.hide(),t(e),o()},"error-callback":e=>{n(e),o()},"expired-callback":()=>{this.hide(),n("expired"),o()},language:this.locale,sitekey:this.sitekey,theme:"light","timeout-callback":()=>{this.hide(),n("timeout"),o()},"unsupported-callback":()=>{n("110500"),o()}})}))}))}errorHandler(e){b("Captcha error with code:",e);let t=[...C.NO_RETRY_ERROR_CODES];if("string"!=typeof e)return void this.notify("Что-то пошло не так. Попробуйте ещё раз. Если не помогает, обратитесь в поддержку.");const n=e;switch(!0){case n.startsWith("110500"):t=t.filter((e=>!e.startsWith("110500"))),this.notify("Ваш браузер устарел. Попробуйте ещё раз, используя другой браузер или устройство.");break;case n.startsWith("110600"):t=t.filter((e=>!e.startsWith("110600"))),this.notify("Прошло слишком много времени с момента начала проверки. Попробуйте еще раз.");break;case n.startsWith("110510"):t=t.filter((e=>!e.startsWith("110510"))),this.notify("Что-то пошло не так — возможно, вы используете технологию подмены User agent. Попробуйте ещё раз или обратитесь в поддержку");break;case n.startsWith("200010"):this.notify('Что-то пошло не так. Попробуйте <a href="https://yandex.ru/support/common/browsers-settings/cache.html" target="_blank" rel="nofollow noopener">очистить кеш браузера</a>. Если не помогает, обратитесь в поддержку.');break;case n.startsWith("200100"):t=t.filter((e=>!e.startsWith("200100"))),this.notify("Кажется, часы на вашем компьютере показывают неправильное время. Настройте часы и попробуйте ещё раз.");break;case n.startsWith("300"):case n.startsWith("600"):t=t.filter((e=>!e.startsWith("300")||!e.startsWith("600"))),this.notify("Потвердите еще раз что вы человек")}t.some((e=>n.startsWith(e)))&&this.notify(`Что-то пошло не так, код ошибки — ${n}. Мы уже знаем о проблеме и скоро всё поправим. Попробуйте ещё раз через некоторое время.`)}execute(e){return o(this,void 0,void 0,(function*(){if(this.sitekey){b("Load cloudflare script");try{yield this.loadScript()}catch(e){const t=e instanceof m?e:new m("Could not load captcha with error: "+e.toString());throw this.onErrorChallenge(this.provider,t),t}if(!window.turnstile){const e=new m("Cloudflare Turnstile is not available in window");throw this.onErrorChallenge(this.provider,e),e}try{b("Render turnstile widget"),this.onRenderCaptcha(this.provider);const t=yield this.renderWidget(e);return this.onSuccessChallenge(this.provider),t}catch(e){if(this.errorHandler(e),"string"!=typeof e){const t=new m("Could not execute captcha with error: "+e.toString());throw this.onErrorChallenge(this.provider,t),t}if(["110200","110100","110110"].some((t=>e.startsWith(t)))){const t=new m("Invalid sitekey or domain is not allowed");throw t.code=e,this.onErrorChallenge(this.provider,t),t}if(C.NO_RETRY_ERROR_CODES.some((t=>e.startsWith(t)))){const t=new m("Captcha challenge is failed");t.code=e,this.onErrorChallenge(this.provider,t)}else{const t=new m("Captcha challenge has error");t.reason=["timeout","expired"].includes(e)?e:void 0,t.code=e,this.onWarnChallenge(this.provider,t)}}}}))}}C.DEBUG=!1,C.NO_RETRY_ERROR_CODES=["100","105","106","110100","110110","110200","110420","110430","110500","110510","120","200010","200100"];const x="recaptcha-widget";function E(){let e=(new Date).getTime(),t="undefined"!=typeof performance&&performance.now&&1e3*performance.now()||0;return"xxxx-xxxx-4xxx-yxxx".replace(/[xy]/g,(function(n){let i=16*Math.random();return e>0?(i=(e+i)%16|0,e=Math.floor(e/16)):(i=(t+i)%16|0,t=Math.floor(t/16)),("x"===n?i:3&i|8).toString(16)}))}const k=(...e)=>{};class _{constructor({sitekey:e,locale:t,notify:n,onRenderCaptcha:i,onSuccessChallenge:r,onWarnChallenge:o,onErrorChallenge:s}){this.sitekey=null,this.locale="ru",this.container=null,this.provider="recaptcha",this.sitekey=null!=e?e:null,this.notifyHandler=null!=n?n:k,this.onRenderCaptcha=null!=i?i:k,this.onSuccessChallenge=null!=r?r:k,this.onWarnChallenge=null!=o?o:k,this.onErrorChallenge=null!=s?s:k,t&&(this.locale=t),this.addDomElements(),_.DEBUG&&(window.gr=this)}recaptchaReady(){b("Google recaptcha is ready",window.grecaptcha,this)}addDomElements(){if(this.container||document.getElementById(x))return;document.body.insertAdjacentHTML("beforeend",`<div id="${x}"></div>`);const e=document.getElementById(x);e.style.display="none",this.container=e}static getGrecaptchaCallbackNames(){return{error:`${_.ERROR_FUNC_NAME}`,expired:`${_.EXPIRED_FUNC_NAME}`,resolve:`${_.RESOLVE_FUNC_NAME}`}}static appendScript(e){return o(this,void 0,void 0,(function*(){if("string"!=typeof e||""===e)throw new TypeError("src script is not defined");const t=document.createElement("script");return t.src=e,document.body&&document.body.appendChild(t),new Promise(((e,n)=>{t.addEventListener("load",(()=>{e(!0)})),t.addEventListener("error",(()=>{n()}))}))}))}loadScript(){return o(this,void 0,void 0,(function*(){if(window.grecaptcha)return Promise.resolve(window.grecaptcha);const e=()=>o(this,void 0,void 0,(function*(){return yield _.appendScript(`https://www.google.com/recaptcha/api.js?hl=${this.locale}&onload=onloadRecaptchaCallback`)}));return new Promise(((t,n)=>{window.onloadRecaptchaCallback=()=>{this.recaptchaReady(),window.grecaptcha?t(window.grecaptcha):n(new m("Recaptcha is not available"))},e().catch((()=>n(new m("Could not load Recaptcha"))))}))}))}notify(...e){this.notifyHandler&&this.notifyHandler(...e)}errorHandler(e){switch(b("Recaptcha error:",e),e){case"expired":this.notify("Прошло слишком много времени с момента начала проверки. Попробуйте еще раз.");break;case"closed":this.notify("Вы не завершили прохождение проверки. Попробуйте еще раз.");break;case"timeout":this.notify("Возможно произшла ошибка с сетевым подключением. Попробуйте ещё раз. Если не помогает, обратитесь в поддержку.");break;default:this.notify("Что-то пошло не так. Попробуйте ещё раз. Если не помогает, обратитесь в поддержку.")}}static detectCaptchaChallengeIsShown(){return new Promise((function(e){const t=document.body;const n=new MutationObserver((function(t){t.forEach((t=>{if(t.addedNodes.length){const i=t.addedNodes[0];if(!i)return;if(i.querySelectorAll('iframe[src^="https://www.google.com/recaptcha"][src*="bframe"]').length){const t=i.firstChild;t&&(n.disconnect(),e(t))}}}))}));n.observe(t,{attributeOldValue:!1,attributes:!1,characterData:!1,characterDataOldValue:!1,childList:!0,subtree:!1})}))}renderWidget(e){return new Promise(((e,t)=>{var n,i,r;const o=document.createElement("div"),s=`${x}_${E()}`;o.id=s,null===(n=document.getElementById(x))||void 0===n||n.appendChild(o);const a=_.getGrecaptchaCallbackNames();let c=NaN;function l(){var e;null===(e=window.grecaptcha)||void 0===e||e.reset(),setTimeout((()=>{o.remove()}),1e3)}_.detectCaptchaChallengeIsShown().then((e=>{if(!e.parentElement)return;const n=new MutationObserver((function(){var i,r;"hidden"!==(null===(i=e.parentElement)||void 0===i?void 0:i.style.visibility)||(null===(r=window.grecaptcha)||void 0===r?void 0:r.getResponse(c))||(n.disconnect(),t("closed"),l())}));n.observe(e.parentElement,{attributeFilter:["style"],attributes:!0})})),window[a.resolve]=()=>{var t;const n=null===(t=window.grecaptcha)||void 0===t?void 0:t.getResponse(c);e(null!=n?n:""),l()},window[a.error]=()=>{t("error"),l()},window[a.expired]=()=>{t("expired"),l()},c=null===(i=window.grecaptcha)||void 0===i?void 0:i.render(s,{callback:a.resolve,"error-callback":a.error,"expired-callback":a.expired,sitekey:this.sitekey,size:"invisible"});const d=null===(r=window.grecaptcha)||void 0===r?void 0:r.execute(c);if(!d)return t(new Error("cannot call method execute from grecaptcha")),void l();d.catch((e=>{t(e instanceof Error?e:new Error(e.toString())),l()}))}))}execute(e){return o(this,void 0,void 0,(function*(){if(this.sitekey){b("Load recaptcha script");try{yield this.loadScript()}catch(e){const t=e instanceof m?e:new m("Could not load captcha with error: "+e.toString());throw this.onErrorChallenge(this.provider,t),t}if(!window.grecaptcha){const e=new m("Recaptcha is not available in window");throw this.onErrorChallenge(this.provider,e),e}try{b("Render Recaptcha widget"),this.onRenderCaptcha(this.provider);const t=yield this.renderWidget(e);return this.onSuccessChallenge(this.provider),t}catch(e){if(this.errorHandler(e),"string"!=typeof e){const t=new m("Could not execute captcha with error: "+e.toString());throw this.onErrorChallenge(this.provider,t),t}if("expired"===e){const e=new m("Challenge or token expired");e.reason="expired",this.onWarnChallenge(this.provider,e)}if("error"===e){const e=new m("Error during captcha execution");this.onErrorChallenge(this.provider,e)}}}}))}}_.RESOLVE_FUNC_NAME="grecaptcha_resolved",_.ERROR_FUNC_NAME="grecaptcha_error",_.EXPIRED_FUNC_NAME="grecaptcha_expired",_.DEBUG=!1;const S="smartcaptcha-container",R=(...e)=>{};class T{constructor({sitekey:e,locale:t,notify:n,onRenderCaptcha:i,onSuccessChallenge:r,onWarnChallenge:o,onErrorChallenge:s,onBeforeInteractiveChallenge:a,onAfterInteractiveChallenge:c}){this.sitekey=null,this.container=null,this.provider="yandex_smart_captcha",this.locale=null!=t?t:"ru",this.sitekey=null!=e?e:null,this.notifyHandler=null!=n?n:R,this.onRenderCaptcha=null!=i?i:R,this.onSuccessChallenge=null!=r?r:R,this.onWarnChallenge=null!=o?o:R,this.onErrorChallenge=null!=s?s:R,this.onBeforeInteractiveChallenge=null!=a?a:R,this.onAfterInteractiveChallenge=null!=c?c:R,this.addDomElements()}smartCaptchaReady(){b("Smart captcha is ready",window.smartCaptcha,this)}addDomElements(){if(this.container||document.getElementById(S))return;document.body.insertAdjacentHTML("beforeend",`<div id="${S}"></div>`);const e=document.getElementById(S);e.style.display="none",this.container=e}static appendScript(e){return o(this,void 0,void 0,(function*(){if("string"!=typeof e||""===e)throw new TypeError("src script is not defined");const t=document.createElement("script");return t.src=e,document.body&&document.body.appendChild(t),new Promise(((e,n)=>{t.addEventListener("load",(()=>{e(!0)})),t.addEventListener("error",(()=>{n()}))}))}))}loadScript(){return o(this,void 0,void 0,(function*(){if(window.smartCaptcha)return Promise.resolve(window.smartCaptcha);const e=()=>o(this,void 0,void 0,(function*(){return yield T.appendScript("https://smartcaptcha.yandexcloud.net/captcha.js?render=onload&onload=onloadSmartCaptchaCallback")}));return new Promise(((t,n)=>{window.onloadSmartCaptchaCallback=()=>{this.smartCaptchaReady(),window.smartCaptcha?t(window.smartCaptcha):n(new m("SmartCaptcha is not available"))},e().catch((()=>n(new m("Could not load SmartCaptcha"))))}))}))}notify(...e){this.notifyHandler&&this.notifyHandler(...e)}errorHandler(e){switch(b("SmartCaptcha error:",e),e){case"closed":this.notify("Вы не завершили прохождение проверки. Попробуйте еще раз.");break;case"timeout":this.notify("Возможно произшла ошибка с сетевым подключением. Попробуйте ещё раз. Если не помогает, обратитесь в поддержку.");break;default:this.notify("Что-то пошло не так. Попробуйте ещё раз. Если не помогает, обратитесь в поддержку.")}}static getDebugValue(){try{if("true"===localStorage.getItem(T.LOCALE_STORAGE_DEBUG_KEY))return!0}catch(e){}return!1}renderWidget(e){var t,n,i,r,o,s,a,c;const{promise:l,resolve:d,reject:h}=Promise.withResolvers(),u=document.createElement("div"),p=`${S}_${E()}`;u.id=p,null===(t=document.getElementById(S))||void 0===t||t.appendChild(u),this.onRenderCaptcha(this.provider);const f=window.smartCaptcha.render(p,{callback:e=>{d(e),function(){var e;null===(e=window.smartCaptcha)||void 0===e||e.destroy(f),setTimeout((()=>{u.remove()}),100)}()},hideShield:!0,hl:this.locale,invisible:!0,sitekey:this.sitekey,test:T.getDebugValue()});return null===(n=window.smartCaptcha)||void 0===n||n.subscribe(f,"challenge-visible",(()=>{this.onBeforeInteractiveChallenge(this.provider)})),null===(i=window.smartCaptcha)||void 0===i||i.subscribe(f,"challenge-hidden",(()=>{this.onAfterInteractiveChallenge(this.provider),h()})),null===(r=window.smartCaptcha)||void 0===r||r.subscribe(f,"token-expired",(()=>{const e=new m("Token expired");e.reason="expired",h(e)})),null===(o=window.smartCaptcha)||void 0===o||o.subscribe(f,"success",(()=>{this.onSuccessChallenge(this.provider)})),null===(s=window.smartCaptcha)||void 0===s||s.subscribe(f,"network-error",(()=>{const e=new m("Network error");e.reason="timeout",h(e)})),null===(a=window.smartCaptcha)||void 0===a||a.subscribe(f,"javascript-error",(e=>{new m("Javascript error","fatal").cause=e,h("javascript-error")})),null===(c=window.smartCaptcha)||void 0===c||c.execute(f),l}execute(e){return o(this,void 0,void 0,(function*(){if(this.sitekey){b("Load smartCaptcha script");try{yield this.loadScript()}catch(e){const t=e instanceof m?e:new m("Could not load captcha with error: "+e.toString());throw this.onErrorChallenge(this.provider,t),t}if(!window.smartCaptcha){const e=new m("SmartCaptcha is not available in window");throw this.onErrorChallenge(this.provider,e),e}try{b("Render SmartCaptcha widget");return yield this.renderWidget(e)}catch(e){if(!e)return;if(e instanceof m)if(this.errorHandler(e),"fatal"===e.level)this.notify("Произошла непредвиденная ошибка. Мы уже делаем все возможное чтобы устранить её."),this.onErrorChallenge(this.provider,e);else switch(e.reason){case"expired":this.notify("Прошло слишком много времени с момента начала проверки. Попробуйте еще раз."),this.onWarnChallenge(this.provider,e);break;case"timeout":this.notify("Вероятно у вас проблемы с подключением к сети. Попробуйте еще раз."),this.onErrorChallenge(this.provider,e)}else{const t=new m("Could not render captcha with error","fatal");t.cause=e,this.onErrorChallenge(this.provider,t)}}}}))}}T.LOCALE_STORAGE_DEBUG_KEY="captcha:smart-captcha:debug";class L{constructor(e){var t,n;switch(this.sitekey=null,this.provider=null,this.captcha=null,this.sitekey=null!==(t=e.sitekey)&&void 0!==t?t:null,this.provider=null!==(n=e.provider)&&void 0!==n?n:null,e.provider){case"yandex_smart_captcha":this.captcha=new T(e);break;case"cloudflare_turnstile":this.captcha=new C(e);break;case"recaptcha":this.captcha=new _(e)}}isEnabled(){return"string"==typeof this.sitekey&&""!==this.sitekey}execute(e){return o(this,void 0,void 0,(function*(){if(!1===this.isEnabled())return;if(!this.provider)return;if(!this.captcha)return;const t=yield this.captcha.execute(e);return b("Receive answer from captcha provider"),{captcha_provider:this.provider,captcha_token:t||""}}))}}class W{constructor(e){var t;this.channel=new n("shared-socket"),this.elector=void 0,this.client=void 0,this.connected=!1,this.logger=console,this.config=e,this.logger=null!==(t=null==e?void 0:e.logger)&&void 0!==t?t:this.logger,globalThis.addEventListener("beforeunload",(()=>{this.disconnect()}))}setToken(e){var t;this.config.token=e,null===(t=this.client)||void 0===t||t.setToken(e)}createClient(){var e,t,n;if(this.connected||void 0!==this.client)return this.client;this.logger.debug("Try to connect with Centrifuge client");const i=null!==(e=this.config.transport)&&void 0!==e?e:[],o=(()=>{const e=i.find((e=>"http_stream"===e.transport));if(e)return`${new URL(e.endpoint).origin}/emulation`})();try{return this.client=new r(null!==(t=this.config.transport)&&void 0!==t?t:[],{debug:null!==(n=this.config.debug)&&void 0!==n&&n,emulationEndpoint:o,getToken:()=>this.config.refreshToken(),token:this.config.token}),this.logger.debug("Create Centrifuge instance",this.client),this.client.on("disconnected",(e=>{this.connected=!1,this.logger.debug("Centrifuge connection is closed and will not be reconnected",e)})),this.client.on("connected",(e=>{this.connected=!0,this.logger.debug("Centrifuge is connected with context",e)})),this.client}catch(e){this.logger.error("Failed to create the Centrifuge instance",{reason:e.toString()})}}disconnect(){var e;void 0!==this.client&&(null===(e=this.channel)||void 0===e||e.close(),this.client.disconnect(),this.client=void 0,this.elector=void 0,this.connected=!1)}subscriptionExists(e){if(!this.client)return!1;const t=this.client.subscriptions();return Boolean(t[e])}join(e,t){var n;const i=this.createClient();if(!i)return;const r=null===(n=this.client)||void 0===n?void 0:n.newSubscription(e);this.logger.debug("Create centrifuge subscription",r),r&&(r.on("publication",(({data:e})=>{var n;this.logger.debug("Get message from ws: ",e),t(e),null===(n=this.channel)||void 0===n||n.postMessage(e)})),r.subscribe(),i.connect())}subscribe(e,t){return o(this,void 0,void 0,(function*(){this.subscriptionExists(e)?this.logger.debug("Subscription to the channel is exists. Ignore subscribe."):(this.logger.debug("Create broadcast channel with name",e),this.channel=new n(e),this.elector=i(this.channel),this.logger.debug("Wait leader",this.elector),this.elector.onduplicate=()=>{this.disconnect(),this.subscribe(e,t)},this.elector.awaitLeadership().then((()=>{this.logger.debug("Current tab is leader",this.elector),this.join(e,t)})),this.channel.addEventListener("message",(e=>{this.logger.debug("Get message from broadcast: ",e),t(e)})))}))}unsubscribe(e){var t;const n=null===(t=this.client)||void 0===t?void 0:t.subscriptions()[e];n&&n.unsubscribe()}}export{f as ApiService,m as CaptchaError,L as CaptchaService,h as RequestPlugin,p as ResponseFailPlugin,u as ResponseSuccessPlugin,W as SocketService};
1
+ import e from"axios";import t from"axios-retry";import{Centrifuge as n}from"centrifuge";import{BroadcastChannel as i,createLeaderElection as r}from"broadcast-channel";function o(e,t,n,i){return new(n||(n=Promise))((function(r,o){function s(e){try{c(i.next(e))}catch(e){o(e)}}function a(e){try{c(i.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((i=i.apply(e,t||[])).next())}))}function s(e,t,n){return e.headers=Object.assign({"Content-Type":"application/json"},e.headers),window&&window.location&&window.location.pathname&&window.location.origin&&(e.headers=Object.assign(Object.assign({},e.headers),{"X-Referer":window.location.origin+window.location.pathname})),n.length>0?function(e,t,n){return o(this,void 0,void 0,(function*(){for(const i of n)i.isApplicable(e)&&(e=yield i.execute(e,t));return e}))}(e,t,n):e}function a(e,t,n){return n.length>0?function(e,t,n){return o(this,void 0,void 0,(function*(){for(const i of n)i.isApplicable(e)&&(e=yield i.execute(e,t));return e}))}(e,t,n):e}void 0===Promise.withResolvers&&(Promise.withResolvers=()=>{let e,t;return{promise:new Promise(((n,i)=>{e=n,t=i})),reject:t,resolve:e}}),"function"==typeof SuppressedError&&SuppressedError;const c=[422,401];function l(e){return"object"==typeof e&&null!==e&&"url"in e}function d(e,t,n){return o(this,void 0,void 0,(function*(){if("object"!=typeof(i=e)||null===i||!("response"in i)||!("config"in i)||null===i.config||null===i.response)return Promise.reject(e);var i;const r=yield function(e,t,n){return o(this,void 0,void 0,(function*(){let i=e;for(const r of n)if(r.isApplicable(e)&&(i=yield r.execute(e,t),l(i)))return i;return i}))}(e,t,n);if(l(r))return t.request(r);const s=function(e){const{response:t,config:n}=e;return c.includes(t.status)&&(n._retry=!0),Object.assign({errorText:e.toString(),headers:t.headers,status:t.status,statusText:t.statusText},"object"==typeof t.data?t.data:{data:t.data})}(e);return Promise.reject(s)}))}class h{constructor(){this.pluginType="request"}}class u{constructor(){this.pluginType="responseSuccess"}}class p{constructor(){this.pluginType="responseFail"}}const f=new class{createFoxApiInstance({config:n,plugins:i=[]}){const r=e.create(n),o=this.filterPlugins(i,"request"),c=this.filterPlugins(i,"responseSuccess"),l=this.filterPlugins(i,"responseFail");return r.interceptors.request.use((e=>s(e,r,[...o]))),r.interceptors.response.use((e=>a(e,r,[...c])),(e=>d(e,r,[...l]))),t(r,{retries:3,retryDelay:t.exponentialDelay}),r}createApiInstance({config:t}){return e.create(t)}createStaticApiInstance(){const t=e;return t.isApiError=e=>"object"==typeof e&&!0===e.isAxiosError,t}filterPlugins(e,t){return e?e.filter((e=>e.pluginType===t)):[]}},g="turnstile-container",v="turnstile-widget";var w=`\n<div id="${g}" class="fox-cf-turnstile">\n <div class="fox-cf-turnstile__overlay"></div>\n <div class="fox-cf-turnstile__content">\n <div class="fox-cf-turnstile__content__text">\n <h3>Надо убедиться, что вы человек</h3>\n <span>Поставьте галочку, нажав на белый квадрат ниже — проверка займёт буквально секунду</span>\n </div>\n <div id="${v}">\n <div class="fox-cf-turnstile__loader"></div>\n </div>\n </div>\n</div>\n`;class m extends Error{constructor(e,t="error"){super(e),this.level="error",this.name="CaptchaError",this.message=e,this.level=t}}function b(...e){const t=["[CaptchaService] ",...e];console.debug.apply(console,t)}const y=(...e)=>{};class C{constructor({sitekey:e,locale:t,notify:n,onRenderCaptcha:i,onSuccessChallenge:r,onErrorChallenge:o,onWarnChallenge:s,onBeforeInteractiveChallenge:a,onAfterInteractiveChallenge:c}){this.sitekey=null,this.locale="ru",this.provider="cloudflare_turnstile",this.container=null,this.notifyHandler=null!=n?n:y,this.sitekey=null!=e?e:null,this.onRenderCaptcha=null!=i?i:y,this.onSuccessChallenge=null!=r?r:y,this.onErrorChallenge=null!=o?o:y,this.onWarnChallenge=null!=s?s:y,this.onBeforeInteractiveChallenge=null!=a?a:y,this.onAfterInteractiveChallenge=null!=c?c:y,t&&(this.locale=t),this.addDomElements(),C.DEBUG&&(window.cf=this)}notify(...e){this.notifyHandler&&this.notifyHandler(...e)}addDomElements(){this.container||document.getElementById(g)||(document.body.insertAdjacentHTML("beforeend",w),document.body.insertAdjacentHTML("beforeend","<style>\n.fox-cf-turnstile {\n position: fixed;\n top: 0;\n left: 0;\n display: flex;\n align-items: center;\n justify-content: center;\n width: 100vw;\n height: 100vh;\n z-index: -1;\n}\n.fox-cf-turnstile__noscroll {\n position: fixed; \n top: var(--st, 0);\n inline-size: 100%;\n overflow-y:scroll; \n}\n.fox-cf-turnstile--showing {\n z-index: 9999;\n}\n.fox-cf-turnstile__overlay {\n position: absolute;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n background: rgba(246, 247, 251, 0.9);\n opacity: 0;\n transition: all .3s ease;\n transition-delay: .2s;\n z-index: 0;\n}\n.fox-cf-turnstile__content {\n background: white;\n border-radius: 5px;\n max-width: 500px;\n max-height: 50vh;\n position: relative;\n z-index: 1;\n box-shadow: rgba(0, 0, 0, 0.08) 0px 10px 20px 0px;\n height: 1px;\n width: 1px;\n overflow: hidden;\n transition: all .8s ease, opacity 0.3s ease;\n transition-delay: .3s;\n opacity: 0;\n display: flex;\n align-items: center;\n justify-content: center;\n flex-direction: column;\n font-size: 1.2rem;\n}\n.fox-cf-turnstile__content__text {\n flex: 1;\n margin-bottom: 20px;\n opacity: 1;\n overflow: hidden;\n transition: opacity 0.3s ease;\n text-align: center;\n}\n.fox-cf-turnstile--showing .fox-cf-turnstile__overlay, .fox-cf-turnstile--show .fox-cf-turnstile__overlay {\n opacity: 1;\n}\n.fox-cf-turnstile--showing .fox-cf-turnstile__content, .fox-cf-turnstile--show .fox-cf-turnstile__content {\n width: 100%;\n height: auto;\n min-height: 20vh;\n min-width: 30vw;\n padding: 30px;\n opacity: 1;\n}\n.fox-cf-turnstile__content__text h3 {\n font-size: 1.4rem;\n}\n.fox-cf-turnstile__loader {\n font-size: 10px;\n margin: 50px auto;\n text-indent: -9999em;\n width: 5em;\n height: 5em;\n border-radius: 50%;\n background: #8b1feb;\n background: -moz-linear-gradient(left, #8b1feb 10%, rgba(139,31,235, 0) 42%);\n background: -webkit-linear-gradient(left, #8b1feb 10%, rgba(139,31,235, 0) 42%);\n background: -o-linear-gradient(left, #8b1feb 10%, rgba(139,31,235, 0) 42%);\n background: -ms-linear-gradient(left, #8b1feb 10%, rgba(139,31,235, 0) 42%);\n background: linear-gradient(to right, #8b1feb 10%, rgba(139,31,235, 0) 42%);\n position: relative;\n -webkit-animation: load3 1.4s infinite linear;\n animation: load3 1.4s infinite linear;\n -webkit-transform: translateZ(0);\n -ms-transform: translateZ(0);\n transform: translateZ(0);\n}\n.fox-cf-turnstile__loader:before {\n width: 50%;\n height: 50%;\n background: #8b1feb;\n border-radius: 100% 0 0 0;\n position: absolute;\n top: 0;\n left: 0;\n content: '';\n}\n.fox-cf-turnstile__loader:after {\n background: white;\n width: 75%;\n height: 75%;\n border-radius: 50%;\n content: '';\n margin: auto;\n position: absolute;\n top: 0;\n left: 0;\n bottom: 0;\n right: 0;\n}\n@-webkit-keyframes load3 {\n 0% {\n -webkit-transform: rotate(0deg);\n transform: rotate(0deg);\n }\n 100% {\n -webkit-transform: rotate(360deg);\n transform: rotate(360deg);\n }\n}\n@keyframes load3 {\n 0% {\n -webkit-transform: rotate(0deg);\n transform: rotate(0deg);\n }\n 100% {\n -webkit-transform: rotate(360deg);\n transform: rotate(360deg);\n }\n} \n</style>"),this.container=document.getElementById(g))}static appendScript(e){return o(this,void 0,void 0,(function*(){if("string"!=typeof e||""===e)throw new TypeError("src script is not defined");const t=document.createElement("script");return t.src=e,document.body&&document.body.appendChild(t),new Promise(((e,n)=>{t.addEventListener("load",(()=>{e(!0)})),t.addEventListener("error",(()=>{n()}))}))}))}show(){var e;null===(e=this.container)||void 0===e||e.classList.add("fox-cf-turnstile--showing"),C.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"),C.bodyScrollUnlock()}loadScript(){return o(this,void 0,void 0,(function*(){if(window.turnstile)return Promise.resolve(window.turnstile);const e=()=>o(this,void 0,void 0,(function*(){return yield C.appendScript("https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit&onload=onloadTurnstileCallback")}));return new Promise(((t,n)=>{window.onloadTurnstileCallback=()=>{this.turnstileReady(),window.turnstile?t(window.turnstile):n(new m("Cloudflare Turnstile is not available"))},e().catch((()=>n(new m("Could not load Cloudflare Turnstile"))))}))}))}turnstileReady(){var e,t;b("Cloudflare Turnstile is ready",window.turnstile),null===(t=null===(e=this.container)||void 0===e?void 0:e.querySelector(".fox-cf-turnstile__loader"))||void 0===t||t.remove()}static normalizeLocation(e=""){return e.substring(0,31).replace(/\//g,"_")}static bodyScrollLock(){const e=document.body;e.style.setProperty("--st",`-${document.documentElement.scrollTop}px`),e.classList.add("fox-cf-turnstile__noscroll")}static bodyScrollUnlock(){document.body.classList.remove("fox-cf-turnstile__noscroll")}renderWidget(e){return o(this,void 0,void 0,(function*(){return new Promise(((t,n)=>{var i;let r="";function o(){var e;null===(e=window.turnstile)||void 0===e||e.reset(r),setTimeout((()=>{var e;null===(e=window.turnstile)||void 0===e||e.remove(r)}),500)}r=null===(i=window.turnstile)||void 0===i?void 0:i.render(`#${v}`,{action:C.normalizeLocation(null==e?void 0:e.location),"after-interactive-callback":()=>{b("after-interactive-callback"),this.onAfterInteractiveChallenge(this.provider)},"before-interactive-callback":()=>{b("before-interactive-callback"),this.onBeforeInteractiveChallenge(this.provider),this.show()},callback:e=>{b("Challenge Success"),this.hide(),t(e),o()},"error-callback":e=>{n(e),o()},"expired-callback":()=>{this.hide(),n("expired"),o()},language:this.locale,sitekey:this.sitekey,theme:"light","timeout-callback":()=>{this.hide(),n("timeout"),o()},"unsupported-callback":()=>{n("110500"),o()}})}))}))}errorHandler(e){b("Captcha error with code:",e);let t=[...C.NO_RETRY_ERROR_CODES];if("string"!=typeof e)return void this.notify("Что-то пошло не так. Попробуйте ещё раз. Если не помогает, обратитесь в поддержку.");const n=e;switch(!0){case n.startsWith("110500"):t=t.filter((e=>!e.startsWith("110500"))),this.notify("Ваш браузер устарел. Попробуйте ещё раз, используя другой браузер или устройство.");break;case n.startsWith("110600"):t=t.filter((e=>!e.startsWith("110600"))),this.notify("Прошло слишком много времени с момента начала проверки. Попробуйте еще раз.");break;case n.startsWith("110510"):t=t.filter((e=>!e.startsWith("110510"))),this.notify("Что-то пошло не так — возможно, вы используете технологию подмены User agent. Попробуйте ещё раз или обратитесь в поддержку");break;case n.startsWith("200010"):this.notify('Что-то пошло не так. Попробуйте <a href="https://yandex.ru/support/common/browsers-settings/cache.html" target="_blank" rel="nofollow noopener">очистить кеш браузера</a>. Если не помогает, обратитесь в поддержку.');break;case n.startsWith("200100"):t=t.filter((e=>!e.startsWith("200100"))),this.notify("Кажется, часы на вашем компьютере показывают неправильное время. Настройте часы и попробуйте ещё раз.");break;case n.startsWith("300"):case n.startsWith("600"):t=t.filter((e=>!e.startsWith("300")||!e.startsWith("600"))),this.notify("Потвердите еще раз что вы человек")}t.some((e=>n.startsWith(e)))&&this.notify(`Что-то пошло не так, код ошибки — ${n}. Мы уже знаем о проблеме и скоро всё поправим. Попробуйте ещё раз через некоторое время.`)}execute(e){return o(this,void 0,void 0,(function*(){if(this.sitekey){b("Load cloudflare script");try{yield this.loadScript()}catch(e){const t=e instanceof m?e:new m("Could not load captcha with error: "+e.toString());throw this.onErrorChallenge(this.provider,t),t}if(!window.turnstile){const e=new m("Cloudflare Turnstile is not available in window");throw this.onErrorChallenge(this.provider,e),e}try{b("Render turnstile widget"),this.onRenderCaptcha(this.provider);const t=yield this.renderWidget(e);return this.onSuccessChallenge(this.provider),t}catch(e){if(this.errorHandler(e),"string"!=typeof e){const t=new m("Could not execute captcha with error: "+e.toString());throw this.onErrorChallenge(this.provider,t),t}if(["110200","110100","110110"].some((t=>e.startsWith(t)))){const t=new m("Invalid sitekey or domain is not allowed");throw t.code=e,this.onErrorChallenge(this.provider,t),t}if(C.NO_RETRY_ERROR_CODES.some((t=>e.startsWith(t)))){const t=new m("Captcha challenge is failed");t.code=e,this.onErrorChallenge(this.provider,t)}else{const t=new m("Captcha challenge has error");t.reason=["timeout","expired"].includes(e)?e:void 0,t.code=e,this.onWarnChallenge(this.provider,t)}}}}))}}C.DEBUG=!1,C.NO_RETRY_ERROR_CODES=["100","105","106","110100","110110","110200","110420","110430","110500","110510","120","200010","200100"];const x="recaptcha-widget";function E(){let e=(new Date).getTime(),t="undefined"!=typeof performance&&performance.now&&1e3*performance.now()||0;return"xxxx-xxxx-4xxx-yxxx".replace(/[xy]/g,(function(n){let i=16*Math.random();return e>0?(i=(e+i)%16|0,e=Math.floor(e/16)):(i=(t+i)%16|0,t=Math.floor(t/16)),("x"===n?i:3&i|8).toString(16)}))}const k=(...e)=>{};class _{constructor({sitekey:e,locale:t,notify:n,onRenderCaptcha:i,onSuccessChallenge:r,onWarnChallenge:o,onErrorChallenge:s}){this.sitekey=null,this.locale="ru",this.container=null,this.provider="recaptcha",this.sitekey=null!=e?e:null,this.notifyHandler=null!=n?n:k,this.onRenderCaptcha=null!=i?i:k,this.onSuccessChallenge=null!=r?r:k,this.onWarnChallenge=null!=o?o:k,this.onErrorChallenge=null!=s?s:k,t&&(this.locale=t),this.addDomElements(),_.DEBUG&&(window.gr=this)}recaptchaReady(){b("Google recaptcha is ready",window.grecaptcha,this)}addDomElements(){if(this.container||document.getElementById(x))return;document.body.insertAdjacentHTML("beforeend",`<div id="${x}"></div>`);const e=document.getElementById(x);e.style.display="none",this.container=e}static getGrecaptchaCallbackNames(){return{error:`${_.ERROR_FUNC_NAME}`,expired:`${_.EXPIRED_FUNC_NAME}`,resolve:`${_.RESOLVE_FUNC_NAME}`}}static appendScript(e){return o(this,void 0,void 0,(function*(){if("string"!=typeof e||""===e)throw new TypeError("src script is not defined");const t=document.createElement("script");return t.src=e,document.body&&document.body.appendChild(t),new Promise(((e,n)=>{t.addEventListener("load",(()=>{e(!0)})),t.addEventListener("error",(()=>{n()}))}))}))}loadScript(){return o(this,void 0,void 0,(function*(){if(window.grecaptcha)return Promise.resolve(window.grecaptcha);const e=()=>o(this,void 0,void 0,(function*(){return yield _.appendScript(`https://www.google.com/recaptcha/api.js?hl=${this.locale}&onload=onloadRecaptchaCallback`)}));return new Promise(((t,n)=>{window.onloadRecaptchaCallback=()=>{this.recaptchaReady(),window.grecaptcha?t(window.grecaptcha):n(new m("Recaptcha is not available"))},e().catch((()=>n(new m("Could not load Recaptcha"))))}))}))}notify(...e){this.notifyHandler&&this.notifyHandler(...e)}errorHandler(e){switch(b("Recaptcha error:",e),e){case"expired":this.notify("Прошло слишком много времени с момента начала проверки. Попробуйте еще раз.");break;case"closed":this.notify("Вы не завершили прохождение проверки. Попробуйте еще раз.");break;case"timeout":this.notify("Возможно произшла ошибка с сетевым подключением. Попробуйте ещё раз. Если не помогает, обратитесь в поддержку.");break;default:this.notify("Что-то пошло не так. Попробуйте ещё раз. Если не помогает, обратитесь в поддержку.")}}static detectCaptchaChallengeIsShown(){return new Promise((function(e){const t=document.body;const n=new MutationObserver((function(t){t.forEach((t=>{if(t.addedNodes.length){const i=t.addedNodes[0];if(!i)return;if(i.querySelectorAll('iframe[src^="https://www.google.com/recaptcha"][src*="bframe"]').length){const t=i.firstChild;t&&(n.disconnect(),e(t))}}}))}));n.observe(t,{attributeOldValue:!1,attributes:!1,characterData:!1,characterDataOldValue:!1,childList:!0,subtree:!1})}))}renderWidget(e){return new Promise(((e,t)=>{var n,i,r;const o=document.createElement("div"),s=`${x}_${E()}`;o.id=s,null===(n=document.getElementById(x))||void 0===n||n.appendChild(o);const a=_.getGrecaptchaCallbackNames();let c=NaN;function l(){var e;null===(e=window.grecaptcha)||void 0===e||e.reset(),setTimeout((()=>{o.remove()}),1e3)}_.detectCaptchaChallengeIsShown().then((e=>{if(!e.parentElement)return;const n=new MutationObserver((function(){var i,r;"hidden"!==(null===(i=e.parentElement)||void 0===i?void 0:i.style.visibility)||(null===(r=window.grecaptcha)||void 0===r?void 0:r.getResponse(c))||(n.disconnect(),t("closed"),l())}));n.observe(e.parentElement,{attributeFilter:["style"],attributes:!0})})),window[a.resolve]=()=>{var t;const n=null===(t=window.grecaptcha)||void 0===t?void 0:t.getResponse(c);e(null!=n?n:""),l()},window[a.error]=()=>{t("error"),l()},window[a.expired]=()=>{t("expired"),l()},c=null===(i=window.grecaptcha)||void 0===i?void 0:i.render(s,{callback:a.resolve,"error-callback":a.error,"expired-callback":a.expired,sitekey:this.sitekey,size:"invisible"});const d=null===(r=window.grecaptcha)||void 0===r?void 0:r.execute(c);if(!d)return t(new Error("cannot call method execute from grecaptcha")),void l();d.catch((e=>{t(e instanceof Error?e:new Error(e.toString())),l()}))}))}execute(e){return o(this,void 0,void 0,(function*(){if(this.sitekey){b("Load recaptcha script");try{yield this.loadScript()}catch(e){const t=e instanceof m?e:new m("Could not load captcha with error: "+e.toString());throw this.onErrorChallenge(this.provider,t),t}if(!window.grecaptcha){const e=new m("Recaptcha is not available in window");throw this.onErrorChallenge(this.provider,e),e}try{b("Render Recaptcha widget"),this.onRenderCaptcha(this.provider);const t=yield this.renderWidget(e);return this.onSuccessChallenge(this.provider),t}catch(e){if(this.errorHandler(e),"string"!=typeof e){const t=new m("Could not execute captcha with error: "+e.toString());throw this.onErrorChallenge(this.provider,t),t}if("expired"===e){const e=new m("Challenge or token expired");e.reason="expired",this.onWarnChallenge(this.provider,e)}if("error"===e){const e=new m("Error during captcha execution");this.onErrorChallenge(this.provider,e)}}}}))}}_.RESOLVE_FUNC_NAME="grecaptcha_resolved",_.ERROR_FUNC_NAME="grecaptcha_error",_.EXPIRED_FUNC_NAME="grecaptcha_expired",_.DEBUG=!1;const S="smartcaptcha-container",R=(...e)=>{};class T{constructor({sitekey:e,locale:t,notify:n,onRenderCaptcha:i,onSuccessChallenge:r,onWarnChallenge:o,onErrorChallenge:s,onBeforeInteractiveChallenge:a,onAfterInteractiveChallenge:c}){this.sitekey=null,this.container=null,this.provider="yandex_smart_captcha",this.locale=null!=t?t:"ru",this.sitekey=null!=e?e:null,this.notifyHandler=null!=n?n:R,this.onRenderCaptcha=null!=i?i:R,this.onSuccessChallenge=null!=r?r:R,this.onWarnChallenge=null!=o?o:R,this.onErrorChallenge=null!=s?s:R,this.onBeforeInteractiveChallenge=null!=a?a:R,this.onAfterInteractiveChallenge=null!=c?c:R,this.addDomElements()}smartCaptchaReady(){b("Smart captcha is ready",window.smartCaptcha,this)}addDomElements(){if(this.container||document.getElementById(S))return;document.body.insertAdjacentHTML("beforeend",`<div id="${S}"></div>`);const e=document.getElementById(S);e.style.display="none",this.container=e}static appendScript(e){return o(this,void 0,void 0,(function*(){if("string"!=typeof e||""===e)throw new TypeError("src script is not defined");const t=document.createElement("script");return t.src=e,document.body&&document.body.appendChild(t),new Promise(((e,n)=>{t.addEventListener("load",(()=>{e(!0)})),t.addEventListener("error",(()=>{n()}))}))}))}loadScript(){return o(this,void 0,void 0,(function*(){if(window.smartCaptcha)return Promise.resolve(window.smartCaptcha);const e=()=>o(this,void 0,void 0,(function*(){return yield T.appendScript("https://smartcaptcha.yandexcloud.net/captcha.js?render=onload&onload=onloadSmartCaptchaCallback")}));return new Promise(((t,n)=>{window.onloadSmartCaptchaCallback=()=>{this.smartCaptchaReady(),window.smartCaptcha?t(window.smartCaptcha):n(new m("SmartCaptcha is not available"))},e().catch((()=>n(new m("Could not load SmartCaptcha"))))}))}))}notify(...e){this.notifyHandler&&this.notifyHandler(...e)}errorHandler(e){switch(b("SmartCaptcha error:",e),e){case"closed":this.notify("Вы не завершили прохождение проверки. Попробуйте еще раз.");break;case"timeout":this.notify("Возможно произшла ошибка с сетевым подключением. Попробуйте ещё раз. Если не помогает, обратитесь в поддержку.");break;default:this.notify("Что-то пошло не так. Попробуйте ещё раз. Если не помогает, обратитесь в поддержку.")}}static getDebugValue(){try{if("true"===localStorage.getItem(T.LOCALE_STORAGE_DEBUG_KEY))return!0}catch(e){}return!1}renderWidget(e){var t,n,i,r,o,s,a,c;const{promise:l,resolve:d,reject:h}=Promise.withResolvers(),u=document.createElement("div"),p=`${S}_${E()}`;u.id=p,null===(t=document.getElementById(S))||void 0===t||t.appendChild(u),this.onRenderCaptcha(this.provider);const f=window.smartCaptcha.render(p,{callback:e=>{d(e),function(){var e;null===(e=window.smartCaptcha)||void 0===e||e.destroy(f),setTimeout((()=>{u.remove()}),100)}()},hideShield:!0,hl:this.locale,invisible:!0,sitekey:this.sitekey,test:T.getDebugValue()});return null===(n=window.smartCaptcha)||void 0===n||n.subscribe(f,"challenge-visible",(()=>{this.onBeforeInteractiveChallenge(this.provider)})),null===(i=window.smartCaptcha)||void 0===i||i.subscribe(f,"challenge-hidden",(()=>{this.onAfterInteractiveChallenge(this.provider),h()})),null===(r=window.smartCaptcha)||void 0===r||r.subscribe(f,"token-expired",(()=>{const e=new m("Token expired");e.reason="expired",h(e)})),null===(o=window.smartCaptcha)||void 0===o||o.subscribe(f,"success",(()=>{this.onSuccessChallenge(this.provider)})),null===(s=window.smartCaptcha)||void 0===s||s.subscribe(f,"network-error",(()=>{const e=new m("Network error");e.reason="timeout",h(e)})),null===(a=window.smartCaptcha)||void 0===a||a.subscribe(f,"javascript-error",(e=>{new m("Javascript error","fatal").cause=e,h("javascript-error")})),null===(c=window.smartCaptcha)||void 0===c||c.execute(f),l}execute(e){return o(this,void 0,void 0,(function*(){if(this.sitekey){b("Load smartCaptcha script");try{yield this.loadScript()}catch(e){const t=e instanceof m?e:new m("Could not load captcha with error: "+e.toString());throw this.onErrorChallenge(this.provider,t),t}if(!window.smartCaptcha){const e=new m("SmartCaptcha is not available in window");throw this.onErrorChallenge(this.provider,e),e}try{b("Render SmartCaptcha widget");return yield this.renderWidget(e)}catch(e){if(!e)return;if(e instanceof m)if(this.errorHandler(e),"fatal"===e.level)this.notify("Произошла непредвиденная ошибка. Мы уже делаем все возможное чтобы устранить её."),this.onErrorChallenge(this.provider,e);else switch(e.reason){case"expired":this.notify("Прошло слишком много времени с момента начала проверки. Попробуйте еще раз."),this.onWarnChallenge(this.provider,e);break;case"timeout":this.notify("Вероятно у вас проблемы с подключением к сети. Попробуйте еще раз."),this.onErrorChallenge(this.provider,e)}else{const t=new m("Could not render captcha with error","fatal");t.cause=e,this.onErrorChallenge(this.provider,t)}}}}))}}T.LOCALE_STORAGE_DEBUG_KEY="captcha:smart-captcha:debug";class L{constructor(e){var t,n;switch(this.sitekey=null,this.provider=null,this.captcha=null,this.sitekey=null!==(t=e.sitekey)&&void 0!==t?t:null,this.provider=null!==(n=e.provider)&&void 0!==n?n:null,e.provider){case"yandex_smart_captcha":this.captcha=new T(e);break;case"cloudflare_turnstile":this.captcha=new C(e);break;case"recaptcha":this.captcha=new _(e)}}isEnabled(){return"string"==typeof this.sitekey&&""!==this.sitekey}execute(e){return o(this,void 0,void 0,(function*(){if(!1===this.isEnabled())return;if(!this.provider)return;if(!this.captcha)return;const t=yield this.captcha.execute(e);return b("Receive answer from captcha provider"),{captcha_provider:this.provider,captcha_token:t||""}}))}}function W(e,t){return new i(e,Object.assign(Object.assign({},t),{type:/iP(ad|od|hone)/i.test(window.navigator.userAgent)?"localstorage":void 0}))}class A{constructor(e){var t;this.elector=void 0,this.client=void 0,this.connected=!1,this.logger=console,this.config=e,this.logger=null!==(t=null==e?void 0:e.logger)&&void 0!==t?t:this.logger,globalThis.addEventListener("beforeunload",(()=>{this.disconnect()}))}setToken(e){var t;this.config.token=e,null===(t=this.client)||void 0===t||t.setToken(e)}createClient(){var e,t,i;if(this.connected||void 0!==this.client)return this.client;this.logger.debug("Try to connect with Centrifuge client");const r=null!==(e=this.config.transport)&&void 0!==e?e:[],o=(()=>{const e=r.find((e=>"http_stream"===e.transport));if(e)return`${new URL(e.endpoint).origin}/emulation`})();try{return this.client=new n(null!==(t=this.config.transport)&&void 0!==t?t:[],{debug:null!==(i=this.config.debug)&&void 0!==i&&i,emulationEndpoint:o,getToken:()=>this.config.refreshToken(),token:this.config.token}),this.logger.debug("Create Centrifuge instance",this.client),this.client.on("disconnected",(e=>{this.connected=!1,this.logger.debug("Centrifuge connection is closed and will not be reconnected",e)})),this.client.on("connected",(e=>{this.connected=!0,this.logger.debug("Centrifuge is connected with context",e)})),this.client}catch(e){this.logger.error("Failed to create the Centrifuge instance",{reason:e.toString()})}}disconnect(){var e;void 0!==this.client&&(null===(e=this.channel)||void 0===e||e.close(),this.client.disconnect(),this.client=void 0,this.elector=void 0,this.connected=!1)}subscriptionExists(e){if(!this.client)return!1;const t=this.client.subscriptions();return Boolean(t[e])}join(e,t){var n;const i=this.createClient();if(!i)return;const r=null===(n=this.client)||void 0===n?void 0:n.newSubscription(e);this.logger.debug("Create centrifuge subscription",r),r&&(r.on("publication",(({data:e})=>{var n;this.logger.debug("Get message from ws: ",e),t(e),null===(n=this.channel)||void 0===n||n.postMessage(e)})),r.subscribe(),i.connect())}createChannel(e,t){return W(e,{idb:{onclose:()=>{this.logger.debug("IDB channel is closed");const n=this.subscriptionExists(e);this.disconnect(),n&&this.subscribe(e,t)}}})}subscribe(e,t){return o(this,void 0,void 0,(function*(){this.subscriptionExists(e)?this.logger.debug("Subscription to the channel is exists. Ignore subscribe."):(this.logger.debug("Create broadcast channel with name",e),this.channel=this.createChannel(e,t),this.elector=r(this.channel),this.logger.debug("Wait leader",this.elector),this.elector.onduplicate=()=>{this.disconnect(),this.subscribe(e,t)},this.elector.awaitLeadership().then((()=>{this.logger.debug("Current tab is leader",this.elector),this.join(e,t)})),this.channel.addEventListener("message",(e=>{this.logger.debug("Get message from broadcast: ",e),t(e)})))}))}unsubscribe(e){var t;const n=null===(t=this.client)||void 0===t?void 0:t.subscriptions()[e];n&&n.unsubscribe()}}export{f as ApiService,m as CaptchaError,L as CaptchaService,h as RequestPlugin,p as ResponseFailPlugin,u as ResponseSuccessPlugin,A as SocketService,W as createBroadcastChannel};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@foxford/services",
3
- "version": "1.4.10",
3
+ "version": "1.4.12",
4
4
  "description": "Foxford services",
5
5
  "keywords": [
6
6
  "foxford",
@@ -25,15 +25,15 @@
25
25
  "main": "./index.js",
26
26
  "types": "./index.d.ts",
27
27
  "dependencies": {
28
- "axios": "0.30.2",
28
+ "axios": "0.30.3",
29
29
  "axios-retry": "3.3.1",
30
- "broadcast-channel": "5.5.1",
30
+ "broadcast-channel": "7.1.0",
31
31
  "centrifuge": "5.1.1"
32
32
  },
33
33
  "peerDependencies": {
34
- "axios": "0.30.2",
34
+ "axios": "0.30.3",
35
35
  "axios-retry": "3.3.1",
36
- "broadcast-channel": "5.5.1",
36
+ "broadcast-channel": "7.1.0",
37
37
  "centrifuge": "5.1.1"
38
38
  },
39
39
  "exports": {
@@ -52,6 +52,6 @@
52
52
  "README.md"
53
53
  ],
54
54
  "sideEffects": false,
55
- "sha": "a0362db7",
55
+ "sha": "5dacf87c",
56
56
  "scripts": {}
57
57
  }