Built motion from commit (unavailable).|2.5.31
[motion2.git] / server / services / routing / lib / rule-engine.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0x1b72=['isString','parse','exports','lodash','events','isNil','register','ignoreFactChanges','inherits','prototype','isArray','rules','concat','isObject','push','sync','activeRules','filter','execute','clone','consequence','ruleRef','name','index_','nextTick','next','isEqual','restart','condition','call','matchPath','noop','findRules','matches','length','prioritize','priority','toJSON','map','toString','init'];(function(_0x2587ab,_0x8f1baa){var _0x457a0e=function(_0x17da09){while(--_0x17da09){_0x2587ab['push'](_0x2587ab['shift']());}};_0x457a0e(++_0x8f1baa);}(_0x1b72,0xa7));var _0x21b7=function(_0x164eca,_0x555e28){_0x164eca=_0x164eca-0x0;var _0x2ce562=_0x1b72[_0x164eca];return _0x2ce562;};'use strict';var _=require(_0x21b7('0x0'));var util=require('util');var EventEmitter=require(_0x21b7('0x1'))['EventEmitter'];function RuleEngine(_0x5bf36a,_0x1f939d){this['init']();if(!_[_0x21b7('0x2')](_0x5bf36a)){this[_0x21b7('0x3')](_0x5bf36a);}if(_0x1f939d){this[_0x21b7('0x4')]=_0x1f939d[_0x21b7('0x4')];}return this;}util[_0x21b7('0x5')](RuleEngine,EventEmitter);RuleEngine[_0x21b7('0x6')]['init']=function(_0x56f3f5){this['rules']=[];this['activeRules']=[];};RuleEngine[_0x21b7('0x6')][_0x21b7('0x3')]=function(_0x1b3d13){if(Array[_0x21b7('0x7')](_0x1b3d13)){this[_0x21b7('0x8')]=this[_0x21b7('0x8')][_0x21b7('0x9')](_0x1b3d13);}else if(_0x1b3d13!==null&&_[_0x21b7('0xa')](_0x1b3d13)){this[_0x21b7('0x8')][_0x21b7('0xb')](_0x1b3d13);}this[_0x21b7('0xc')]();};RuleEngine[_0x21b7('0x6')][_0x21b7('0xc')]=function(){this[_0x21b7('0xd')]=this[_0x21b7('0x8')][_0x21b7('0xe')](function(_0x366587){if(_[_0x21b7('0x2')](_0x366587['on'])){_0x366587['on']=!![];}if(_0x366587['on']===!![]){return _0x366587;}});this[_0x21b7('0xd')]=_['orderBy'](this[_0x21b7('0xd')],['p'],['asc']);};RuleEngine[_0x21b7('0x6')][_0x21b7('0xf')]=function(_0x230f33,_0x593449){var _0x38eb2b=![];_0x230f33['result']=!![];var _0x68be7b=_[_0x21b7('0x10')](_0x230f33);var _0x351b08=_[_0x21b7('0x10')](_0x230f33);var _0x53d050=this['activeRules'];var _0x3fbcaa=[];var _0xb886d8=this[_0x21b7('0x4')];(function FnRuleLoop(_0x381579){var _0x2942ed={'rules':function(){return _0x53d050;},'rule':function(){return _0x53d050[_0x381579];},'when':function(_0x5a6263){if(_0x5a6263){var _0x300abf=_0x53d050[_0x381579][_0x21b7('0x11')];_0x300abf[_0x21b7('0x12')]=_0x53d050[_0x381579]['id']||_0x53d050[_0x381579][_0x21b7('0x13')]||_0x21b7('0x14')+_0x381579;process['nextTick'](function(){_0x3fbcaa[_0x21b7('0xb')](_0x300abf[_0x21b7('0x12')]);_0x300abf['call'](_0x68be7b,_0x2942ed);});}else{process[_0x21b7('0x15')](function(){_0x2942ed[_0x21b7('0x16')]();});}},'restart':function(){return FnRuleLoop(0x0);},'stop':function(){_0x38eb2b=!![];return FnRuleLoop(0x0);},'next':function(_0x2b03de){if(!_0xb886d8&&!_[_0x21b7('0x17')](_0x351b08,_0x68be7b)){_0x351b08=_[_0x21b7('0x10')](_0x68be7b);process['nextTick'](function(){_0x2942ed[_0x21b7('0x18')]();});}else{process['nextTick'](function(){if(_[_0x21b7('0x2')](_0x2b03de)){return FnRuleLoop(_0x381579+0x1);}else{return FnRuleLoop(_0x2b03de);}});}}};if(_0x381579<_0x53d050['length']&&_0x38eb2b===![]){var _0x4e9e8f=_0x53d050[_0x381579][_0x21b7('0x19')];_0x4e9e8f[_0x21b7('0x1a')](_0x68be7b,_0x2942ed);}else{process[_0x21b7('0x15')](function(){_0x68be7b[_0x21b7('0x1b')]=_0x3fbcaa;return _0x593449?_0x593449(_0x68be7b):_[_0x21b7('0x1c')]();});}}(0x0));};RuleEngine[_0x21b7('0x6')][_0x21b7('0x1d')]=function(_0x32dae1){if(_[_0x21b7('0x2')](_0x32dae1)){return this[_0x21b7('0x8')];}else{var _0x25d3c4=_[_0x21b7('0x1e')](_0x32dae1);return _['filter'](this['rules'],_0x25d3c4);}};RuleEngine[_0x21b7('0x6')]['turn']=function(_0x509d52,_0x2103b9){var _0xbbfa13=_0x509d52==='on'||_0x509d52==='ON'?!![]:![];var _0x432c62=this['findRules'](_0x2103b9);for(var _0x2a4690=0x0,_0x533c17=_0x432c62[_0x21b7('0x1f')];_0x2a4690<_0x533c17;_0x2a4690+=0x1){_0x432c62[_0x2a4690]['on']=_0xbbfa13;}this[_0x21b7('0xc')]();};RuleEngine['prototype'][_0x21b7('0x20')]=function(_0x4f75e5,_0x576e98){_0x4f75e5=parseInt(_0x4f75e5,0xa);var _0x460c06=this[_0x21b7('0x1d')](_0x576e98);for(var _0x126cdf=0x0,_0x889d55=_0x460c06[_0x21b7('0x1f')];_0x126cdf<_0x889d55;_0x126cdf+=0x1){_0x460c06[_0x126cdf][_0x21b7('0x21')]=_0x4f75e5;}this['sync']();};RuleEngine[_0x21b7('0x6')][_0x21b7('0x22')]=function(){var _0x31b25a=this['rules'];if(_0x31b25a instanceof Array){_0x31b25a=_0x31b25a[_0x21b7('0x23')](function(_0x4b3cbe){_0x4b3cbe[_0x21b7('0x19')]=_0x4b3cbe[_0x21b7('0x19')][_0x21b7('0x24')]();_0x4b3cbe[_0x21b7('0x11')]=_0x4b3cbe[_0x21b7('0x11')][_0x21b7('0x24')]();return _0x4b3cbe;});}else if(!_[_0x21b7('0x2')](_0x31b25a)){_0x31b25a['condition']=_0x31b25a[_0x21b7('0x19')]['toString']();_0x31b25a[_0x21b7('0x11')]=_0x31b25a[_0x21b7('0x11')][_0x21b7('0x24')]();}return _0x31b25a;};RuleEngine[_0x21b7('0x6')]['fromJSON']=function(_0x2a6b67){this[_0x21b7('0x25')]();if(_[_0x21b7('0x26')](_0x2a6b67)){_0x2a6b67=JSON[_0x21b7('0x27')](_0x2a6b67);}if(_0x2a6b67 instanceof Array){_0x2a6b67=_0x2a6b67['map'](function(_0x74838){_0x74838['condition']=eval('('+_0x74838[_0x21b7('0x19')]+')');_0x74838[_0x21b7('0x11')]=eval('('+_0x74838['consequence']+')');return _0x74838;});}else if(_0x2a6b67!==null&&typeof _0x2a6b67=='object'){_0x2a6b67[_0x21b7('0x19')]=eval('('+_0x2a6b67[_0x21b7('0x19')]+')');_0x2a6b67[_0x21b7('0x11')]=eval('('+_0x2a6b67[_0x21b7('0x11')]+')');}this['register'](_0x2a6b67);};module[_0x21b7('0x28')]=RuleEngine;