3183055588ebe8ac5e4059314cd75fc5066de4d8
[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 _0x5a9f=['length','condition','matchPath','noop','findRules','matches','turn','prioritize','toJSON','map','toString','fromJSON','isString','parse','object','exports','lodash','util','EventEmitter','init','isNil','register','ignoreFactChanges','inherits','prototype','rules','activeRules','isArray','concat','isObject','sync','filter','orderBy','asc','execute','result','consequence','ruleRef','nextTick','push','call','next','clone','restart'];(function(_0x196112,_0x247301){var _0xa1ebba=function(_0x71ccec){while(--_0x71ccec){_0x196112['push'](_0x196112['shift']());}};_0xa1ebba(++_0x247301);}(_0x5a9f,0x170));var _0xf5a9=function(_0x327659,_0x388c16){_0x327659=_0x327659-0x0;var _0x2637e7=_0x5a9f[_0x327659];return _0x2637e7;};'use strict';var _=require(_0xf5a9('0x0'));var util=require(_0xf5a9('0x1'));var EventEmitter=require('events')[_0xf5a9('0x2')];function RuleEngine(_0x510ac9,_0x4391ad){this[_0xf5a9('0x3')]();if(!_[_0xf5a9('0x4')](_0x510ac9)){this[_0xf5a9('0x5')](_0x510ac9);}if(_0x4391ad){this['ignoreFactChanges']=_0x4391ad[_0xf5a9('0x6')];}return this;}util[_0xf5a9('0x7')](RuleEngine,EventEmitter);RuleEngine[_0xf5a9('0x8')][_0xf5a9('0x3')]=function(_0x4985f4){this[_0xf5a9('0x9')]=[];this[_0xf5a9('0xa')]=[];};RuleEngine[_0xf5a9('0x8')][_0xf5a9('0x5')]=function(_0x2f505e){if(Array[_0xf5a9('0xb')](_0x2f505e)){this[_0xf5a9('0x9')]=this['rules'][_0xf5a9('0xc')](_0x2f505e);}else if(_0x2f505e!==null&&_[_0xf5a9('0xd')](_0x2f505e)){this[_0xf5a9('0x9')]['push'](_0x2f505e);}this[_0xf5a9('0xe')]();};RuleEngine['prototype']['sync']=function(){this[_0xf5a9('0xa')]=this['rules'][_0xf5a9('0xf')](function(_0x1ca5c0){if(_[_0xf5a9('0x4')](_0x1ca5c0['on'])){_0x1ca5c0['on']=!![];}if(_0x1ca5c0['on']===!![]){return _0x1ca5c0;}});this[_0xf5a9('0xa')]=_[_0xf5a9('0x10')](this[_0xf5a9('0xa')],['p'],[_0xf5a9('0x11')]);};RuleEngine['prototype'][_0xf5a9('0x12')]=function(_0x395591,_0x351cc){var _0x5b619c=![];_0x395591[_0xf5a9('0x13')]=!![];var _0x7a29dc=_['clone'](_0x395591);var _0x2c17df=_['clone'](_0x395591);var _0x1a85c1=this[_0xf5a9('0xa')];var _0x10b8c0=[];var _0x184074=this['ignoreFactChanges'];(function FnRuleLoop(_0x468161){var _0x10c97a={'rules':function(){return _0x1a85c1;},'rule':function(){return _0x1a85c1[_0x468161];},'when':function(_0x383fb0){if(_0x383fb0){var _0x269dd3=_0x1a85c1[_0x468161][_0xf5a9('0x14')];_0x269dd3[_0xf5a9('0x15')]=_0x1a85c1[_0x468161]['id']||_0x1a85c1[_0x468161]['name']||'index_'+_0x468161;process[_0xf5a9('0x16')](function(){_0x10b8c0[_0xf5a9('0x17')](_0x269dd3[_0xf5a9('0x15')]);_0x269dd3[_0xf5a9('0x18')](_0x7a29dc,_0x10c97a);});}else{process[_0xf5a9('0x16')](function(){_0x10c97a[_0xf5a9('0x19')]();});}},'restart':function(){return FnRuleLoop(0x0);},'stop':function(){_0x5b619c=!![];return FnRuleLoop(0x0);},'next':function(_0x48c13a){if(!_0x184074&&!_['isEqual'](_0x2c17df,_0x7a29dc)){_0x2c17df=_[_0xf5a9('0x1a')](_0x7a29dc);process[_0xf5a9('0x16')](function(){_0x10c97a[_0xf5a9('0x1b')]();});}else{process[_0xf5a9('0x16')](function(){if(_[_0xf5a9('0x4')](_0x48c13a)){return FnRuleLoop(_0x468161+0x1);}else{return FnRuleLoop(_0x48c13a);}});}}};if(_0x468161<_0x1a85c1[_0xf5a9('0x1c')]&&_0x5b619c===![]){var _0x29f558=_0x1a85c1[_0x468161][_0xf5a9('0x1d')];_0x29f558['call'](_0x7a29dc,_0x10c97a);}else{process[_0xf5a9('0x16')](function(){_0x7a29dc[_0xf5a9('0x1e')]=_0x10b8c0;return _0x351cc?_0x351cc(_0x7a29dc):_[_0xf5a9('0x1f')]();});}}(0x0));};RuleEngine[_0xf5a9('0x8')][_0xf5a9('0x20')]=function(_0x1b3e5b){if(_[_0xf5a9('0x4')](_0x1b3e5b)){return this['rules'];}else{var _0x587568=_[_0xf5a9('0x21')](_0x1b3e5b);return _['filter'](this['rules'],_0x587568);}};RuleEngine[_0xf5a9('0x8')][_0xf5a9('0x22')]=function(_0x14601f,_0x58436b){var _0x96c5a7=_0x14601f==='on'||_0x14601f==='ON'?!![]:![];var _0x5e31bb=this[_0xf5a9('0x20')](_0x58436b);for(var _0x1648c5=0x0,_0x5b1132=_0x5e31bb[_0xf5a9('0x1c')];_0x1648c5<_0x5b1132;_0x1648c5+=0x1){_0x5e31bb[_0x1648c5]['on']=_0x96c5a7;}this[_0xf5a9('0xe')]();};RuleEngine[_0xf5a9('0x8')][_0xf5a9('0x23')]=function(_0x1f0a04,_0x3f5067){_0x1f0a04=parseInt(_0x1f0a04,0xa);var _0x1073b2=this[_0xf5a9('0x20')](_0x3f5067);for(var _0x40e88d=0x0,_0x20e455=_0x1073b2[_0xf5a9('0x1c')];_0x40e88d<_0x20e455;_0x40e88d+=0x1){_0x1073b2[_0x40e88d]['priority']=_0x1f0a04;}this[_0xf5a9('0xe')]();};RuleEngine['prototype'][_0xf5a9('0x24')]=function(){var _0x3f49dc=this['rules'];if(_0x3f49dc instanceof Array){_0x3f49dc=_0x3f49dc[_0xf5a9('0x25')](function(_0x48771f){_0x48771f['condition']=_0x48771f[_0xf5a9('0x1d')]['toString']();_0x48771f['consequence']=_0x48771f[_0xf5a9('0x14')][_0xf5a9('0x26')]();return _0x48771f;});}else if(!_[_0xf5a9('0x4')](_0x3f49dc)){_0x3f49dc[_0xf5a9('0x1d')]=_0x3f49dc[_0xf5a9('0x1d')][_0xf5a9('0x26')]();_0x3f49dc[_0xf5a9('0x14')]=_0x3f49dc[_0xf5a9('0x14')][_0xf5a9('0x26')]();}return _0x3f49dc;};RuleEngine[_0xf5a9('0x8')][_0xf5a9('0x27')]=function(_0x1923ed){this[_0xf5a9('0x3')]();if(_[_0xf5a9('0x28')](_0x1923ed)){_0x1923ed=JSON[_0xf5a9('0x29')](_0x1923ed);}if(_0x1923ed instanceof Array){_0x1923ed=_0x1923ed[_0xf5a9('0x25')](function(_0x4994e5){_0x4994e5[_0xf5a9('0x1d')]=eval('('+_0x4994e5[_0xf5a9('0x1d')]+')');_0x4994e5[_0xf5a9('0x14')]=eval('('+_0x4994e5[_0xf5a9('0x14')]+')');return _0x4994e5;});}else if(_0x1923ed!==null&&typeof _0x1923ed==_0xf5a9('0x2a')){_0x1923ed['condition']=eval('('+_0x1923ed['condition']+')');_0x1923ed['consequence']=eval('('+_0x1923ed[_0xf5a9('0x14')]+')');}this[_0xf5a9('0x5')](_0x1923ed);};module[_0xf5a9('0x2b')]=RuleEngine;