Built motion from commit (unavailable).|2.5.0
[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 _0xea2e=['events','EventEmitter','isNil','ignoreFactChanges','prototype','rules','register','isArray','concat','sync','orderBy','activeRules','asc','execute','result','clone','consequence','ruleRef','push','nextTick','next','isEqual','restart','length','matchPath','noop','findRules','matches','filter','priority','toJSON','condition','toString','fromJSON','init','isString','parse','map','object','exports','lodash','util'];(function(_0x3e5086,_0x48f4a2){var _0xfeb102=function(_0x5a945f){while(--_0x5a945f){_0x3e5086['push'](_0x3e5086['shift']());}};_0xfeb102(++_0x48f4a2);}(_0xea2e,0x1cc));var _0xeea2=function(_0x1660b6,_0x5ad742){_0x1660b6=_0x1660b6-0x0;var _0x19b321=_0xea2e[_0x1660b6];return _0x19b321;};'use strict';var _=require(_0xeea2('0x0'));var util=require(_0xeea2('0x1'));var EventEmitter=require(_0xeea2('0x2'))[_0xeea2('0x3')];function RuleEngine(_0x1fae05,_0x111409){this['init']();if(!_[_0xeea2('0x4')](_0x1fae05)){this['register'](_0x1fae05);}if(_0x111409){this[_0xeea2('0x5')]=_0x111409[_0xeea2('0x5')];}return this;}util['inherits'](RuleEngine,EventEmitter);RuleEngine[_0xeea2('0x6')]['init']=function(_0x54ad68){this[_0xeea2('0x7')]=[];this['activeRules']=[];};RuleEngine['prototype'][_0xeea2('0x8')]=function(_0x2d6218){if(Array[_0xeea2('0x9')](_0x2d6218)){this[_0xeea2('0x7')]=this['rules'][_0xeea2('0xa')](_0x2d6218);}else if(_0x2d6218!==null&&_['isObject'](_0x2d6218)){this[_0xeea2('0x7')]['push'](_0x2d6218);}this[_0xeea2('0xb')]();};RuleEngine['prototype'][_0xeea2('0xb')]=function(){this['activeRules']=this['rules']['filter'](function(_0x57dfc2){if(_[_0xeea2('0x4')](_0x57dfc2['on'])){_0x57dfc2['on']=!![];}if(_0x57dfc2['on']===!![]){return _0x57dfc2;}});this['activeRules']=_[_0xeea2('0xc')](this[_0xeea2('0xd')],['p'],[_0xeea2('0xe')]);};RuleEngine[_0xeea2('0x6')][_0xeea2('0xf')]=function(_0x1292ae,_0x1d3e8c){var _0xfc0521=![];_0x1292ae[_0xeea2('0x10')]=!![];var _0x5f58c0=_[_0xeea2('0x11')](_0x1292ae);var _0x30884f=_[_0xeea2('0x11')](_0x1292ae);var _0x3e71a6=this[_0xeea2('0xd')];var _0xd3efcc=[];var _0x4a59dd=this['ignoreFactChanges'];(function FnRuleLoop(_0xabb753){var _0x55c7af={'rules':function(){return _0x3e71a6;},'rule':function(){return _0x3e71a6[_0xabb753];},'when':function(_0x3c0d10){if(_0x3c0d10){var _0x45f4b7=_0x3e71a6[_0xabb753][_0xeea2('0x12')];_0x45f4b7[_0xeea2('0x13')]=_0x3e71a6[_0xabb753]['id']||_0x3e71a6[_0xabb753]['name']||'index_'+_0xabb753;process['nextTick'](function(){_0xd3efcc[_0xeea2('0x14')](_0x45f4b7['ruleRef']);_0x45f4b7['call'](_0x5f58c0,_0x55c7af);});}else{process[_0xeea2('0x15')](function(){_0x55c7af[_0xeea2('0x16')]();});}},'restart':function(){return FnRuleLoop(0x0);},'stop':function(){_0xfc0521=!![];return FnRuleLoop(0x0);},'next':function(_0x5855d2){if(!_0x4a59dd&&!_[_0xeea2('0x17')](_0x30884f,_0x5f58c0)){_0x30884f=_[_0xeea2('0x11')](_0x5f58c0);process[_0xeea2('0x15')](function(){_0x55c7af[_0xeea2('0x18')]();});}else{process[_0xeea2('0x15')](function(){if(_[_0xeea2('0x4')](_0x5855d2)){return FnRuleLoop(_0xabb753+0x1);}else{return FnRuleLoop(_0x5855d2);}});}}};if(_0xabb753<_0x3e71a6[_0xeea2('0x19')]&&_0xfc0521===![]){var _0xe31aa7=_0x3e71a6[_0xabb753]['condition'];_0xe31aa7['call'](_0x5f58c0,_0x55c7af);}else{process['nextTick'](function(){_0x5f58c0[_0xeea2('0x1a')]=_0xd3efcc;return _0x1d3e8c?_0x1d3e8c(_0x5f58c0):_[_0xeea2('0x1b')]();});}}(0x0));};RuleEngine[_0xeea2('0x6')][_0xeea2('0x1c')]=function(_0xc85780){if(_[_0xeea2('0x4')](_0xc85780)){return this[_0xeea2('0x7')];}else{var _0x40b36e=_[_0xeea2('0x1d')](_0xc85780);return _[_0xeea2('0x1e')](this['rules'],_0x40b36e);}};RuleEngine['prototype']['turn']=function(_0x3576f6,_0x2aa7ed){var _0x55fe31=_0x3576f6==='on'||_0x3576f6==='ON'?!![]:![];var _0x1e03a9=this[_0xeea2('0x1c')](_0x2aa7ed);for(var _0x546226=0x0,_0x75eac6=_0x1e03a9[_0xeea2('0x19')];_0x546226<_0x75eac6;_0x546226+=0x1){_0x1e03a9[_0x546226]['on']=_0x55fe31;}this[_0xeea2('0xb')]();};RuleEngine[_0xeea2('0x6')]['prioritize']=function(_0x19e946,_0x447f07){_0x19e946=parseInt(_0x19e946,0xa);var _0x3002c3=this[_0xeea2('0x1c')](_0x447f07);for(var _0x52aac1=0x0,_0x4685f6=_0x3002c3['length'];_0x52aac1<_0x4685f6;_0x52aac1+=0x1){_0x3002c3[_0x52aac1][_0xeea2('0x1f')]=_0x19e946;}this[_0xeea2('0xb')]();};RuleEngine['prototype'][_0xeea2('0x20')]=function(){var _0x2df491=this[_0xeea2('0x7')];if(_0x2df491 instanceof Array){_0x2df491=_0x2df491['map'](function(_0x2801fc){_0x2801fc[_0xeea2('0x21')]=_0x2801fc[_0xeea2('0x21')]['toString']();_0x2801fc[_0xeea2('0x12')]=_0x2801fc[_0xeea2('0x12')]['toString']();return _0x2801fc;});}else if(!_[_0xeea2('0x4')](_0x2df491)){_0x2df491[_0xeea2('0x21')]=_0x2df491['condition'][_0xeea2('0x22')]();_0x2df491[_0xeea2('0x12')]=_0x2df491[_0xeea2('0x12')][_0xeea2('0x22')]();}return _0x2df491;};RuleEngine[_0xeea2('0x6')][_0xeea2('0x23')]=function(_0x14f2df){this[_0xeea2('0x24')]();if(_[_0xeea2('0x25')](_0x14f2df)){_0x14f2df=JSON[_0xeea2('0x26')](_0x14f2df);}if(_0x14f2df instanceof Array){_0x14f2df=_0x14f2df[_0xeea2('0x27')](function(_0x1b42a7){_0x1b42a7[_0xeea2('0x21')]=eval('('+_0x1b42a7[_0xeea2('0x21')]+')');_0x1b42a7['consequence']=eval('('+_0x1b42a7['consequence']+')');return _0x1b42a7;});}else if(_0x14f2df!==null&&typeof _0x14f2df==_0xeea2('0x28')){_0x14f2df[_0xeea2('0x21')]=eval('('+_0x14f2df[_0xeea2('0x21')]+')');_0x14f2df[_0xeea2('0x12')]=eval('('+_0x14f2df[_0xeea2('0x12')]+')');}this[_0xeea2('0x8')](_0x14f2df);};module[_0xeea2('0x29')]=RuleEngine;