| Current Path : /var/www/homesaver/www/bitrix/js/pull/configholder/dist/ |
| Current File : /var/www/homesaver/www/bitrix/js/pull/configholder/dist/pull.configholder.bundle.min.js |
this.BX=this.BX||{};(function(e){"use strict";function t(){return Date.now()}function i(e){return typeof e==="number"&&Number.isFinite(e)}function n(e){return Boolean(e)&&typeof e==="object"&&e.constructor===Object}const s=19;const o=6e4;const r={ConfigExpired:"configExpired",RevisionChanged:"revisionChanged"};class c extends EventTarget{constructor(e={}){super();this.configGetMethod="pull.config.get";if(e.configGetMethod){this.configGetMethod=e.configGetMethod}this.restClient=e.restClient;for(const t of Object.keys(e.events||{})){this.addEventListener(t,e.events[t])}}loadConfig(e){this.stopCheckConfig();return new Promise(((i,n)=>{this.restClient.callMethod(this.configGetMethod,{CACHE:"N"},undefined,undefined,e).then((e=>{const n=e.data();const s=Math.floor((t()-new Date(n.serverTime).getTime())/1e3);delete n.serverTime;this.config={...n};this.config.server.timeShift=s;this.startCheckConfig();i(this.config)})).catch((e=>{this.config=undefined;const t=e.error();if(t.getError().error==="AUTHORIZE_ERROR"||t.getError().error==="WRONG_AUTH_TYPE"){t.status=403}n(t)}))}))}startCheckConfig(){if(this.checkInterval){clearInterval(this.checkInterval)}this.checkInterval=setInterval((()=>this.checkConfig()),o)}stopCheckConfig(){if(this.checkInterval){clearInterval(this.checkInterval)}this.checkInterval=null}checkConfig(){if(!this.isConfigActual(this.config)){this.dispatchEvent(new CustomEvent(r.ConfigExpired))}else if(this.config.api.revision_web!==s){this.dispatchEvent(new CustomEvent(r.RevisionChanged,{detail:{revision:this.config.api.revision_web}}))}}isConfigActual(e){if(!n(e)){return false}if(e.server.config_timestamp<this.configTimestamp){return false}const t=new Date;if(i(e.exp)&&e.exp>0&&e.exp<t.getTime()/1e3){return false}const s=Object.keys(e.channels||{});if(s.length===0){return false}for(const i of s){const n=e.channels[i];const s=new Date(n.end);if(s<t){return false}}return true}dispose(){this.stopCheckConfig()}}e.ConfigHolderEvents=r;e.ConfigHolder=c})(this.BX.Pull=this.BX.Pull||{});
//# sourceMappingURL=pull.configholder.bundle.map.js