Built motion from commit (unavailable).|2.5.2
[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 _0xb1a5=['push','sync','filter','orderBy','asc','execute','clone','consequence','ruleRef','index_','call','nextTick','next','restart','matchPath','noop','findRules','turn','length','prioritize','priority','map','toString','condition','isString','parse','object','exports','lodash','events','EventEmitter','init','isNil','ignoreFactChanges','inherits','prototype','rules','activeRules','register','concat','isObject'];(function(_0x1f2df3,_0x1952ca){var _0x87cdd2=function(_0x115344){while(--_0x115344){_0x1f2df3['push'](_0x1f2df3['shift']());}};_0x87cdd2(++_0x1952ca);}(_0xb1a5,0x164));var _0x5b1a=function(_0x1e848f,_0x2bea03){_0x1e848f=_0x1e848f-0x0;var _0x226383=_0xb1a5[_0x1e848f];return _0x226383;};'use strict';var _=require(_0x5b1a('0x0'));var util=require('util');var EventEmitter=require(_0x5b1a('0x1'))[_0x5b1a('0x2')];function RuleEngine(_0xe30fec,_0x277754){this[_0x5b1a('0x3')]();if(!_[_0x5b1a('0x4')](_0xe30fec)){this['register'](_0xe30fec);}if(_0x277754){this[_0x5b1a('0x5')]=_0x277754['ignoreFactChanges'];}return this;}util[_0x5b1a('0x6')](RuleEngine,EventEmitter);RuleEngine[_0x5b1a('0x7')]['init']=function(_0x17ef58){this[_0x5b1a('0x8')]=[];this[_0x5b1a('0x9')]=[];};RuleEngine[_0x5b1a('0x7')][_0x5b1a('0xa')]=function(_0x1d76ec){if(Array['isArray'](_0x1d76ec)){this['rules']=this['rules'][_0x5b1a('0xb')](_0x1d76ec);}else if(_0x1d76ec!==null&&_[_0x5b1a('0xc')](_0x1d76ec)){this[_0x5b1a('0x8')][_0x5b1a('0xd')](_0x1d76ec);}this[_0x5b1a('0xe')]();};RuleEngine[_0x5b1a('0x7')]['sync']=function(){this[_0x5b1a('0x9')]=this[_0x5b1a('0x8')][_0x5b1a('0xf')](function(_0x58d016){if(_[_0x5b1a('0x4')](_0x58d016['on'])){_0x58d016['on']=!![];}if(_0x58d016['on']===!![]){return _0x58d016;}});this[_0x5b1a('0x9')]=_[_0x5b1a('0x10')](this[_0x5b1a('0x9')],['p'],[_0x5b1a('0x11')]);};RuleEngine[_0x5b1a('0x7')][_0x5b1a('0x12')]=function(_0x431feb,_0x26f486){var _0x4f106a=![];_0x431feb['result']=!![];var _0x32fd86=_[_0x5b1a('0x13')](_0x431feb);var _0x10b827=_[_0x5b1a('0x13')](_0x431feb);var _0x58ef8c=this[_0x5b1a('0x9')];var _0x146577=[];var _0x1705f9=this[_0x5b1a('0x5')];(function FnRuleLoop(_0xf247cd){var _0x411681={'rules':function(){return _0x58ef8c;},'rule':function(){return _0x58ef8c[_0xf247cd];},'when':function(_0x4a2783){if(_0x4a2783){var _0x1f2056=_0x58ef8c[_0xf247cd][_0x5b1a('0x14')];_0x1f2056[_0x5b1a('0x15')]=_0x58ef8c[_0xf247cd]['id']||_0x58ef8c[_0xf247cd]['name']||_0x5b1a('0x16')+_0xf247cd;process['nextTick'](function(){_0x146577[_0x5b1a('0xd')](_0x1f2056[_0x5b1a('0x15')]);_0x1f2056[_0x5b1a('0x17')](_0x32fd86,_0x411681);});}else{process[_0x5b1a('0x18')](function(){_0x411681[_0x5b1a('0x19')]();});}},'restart':function(){return FnRuleLoop(0x0);},'stop':function(){_0x4f106a=!![];return FnRuleLoop(0x0);},'next':function(_0x767baa){if(!_0x1705f9&&!_['isEqual'](_0x10b827,_0x32fd86)){_0x10b827=_['clone'](_0x32fd86);process[_0x5b1a('0x18')](function(){_0x411681[_0x5b1a('0x1a')]();});}else{process[_0x5b1a('0x18')](function(){if(_['isNil'](_0x767baa)){return FnRuleLoop(_0xf247cd+0x1);}else{return FnRuleLoop(_0x767baa);}});}}};if(_0xf247cd<_0x58ef8c['length']&&_0x4f106a===![]){var _0x2e9a1c=_0x58ef8c[_0xf247cd]['condition'];_0x2e9a1c[_0x5b1a('0x17')](_0x32fd86,_0x411681);}else{process['nextTick'](function(){_0x32fd86[_0x5b1a('0x1b')]=_0x146577;return _0x26f486?_0x26f486(_0x32fd86):_[_0x5b1a('0x1c')]();});}}(0x0));};RuleEngine['prototype'][_0x5b1a('0x1d')]=function(_0x240553){if(_[_0x5b1a('0x4')](_0x240553)){return this['rules'];}else{var _0x1a4fc4=_['matches'](_0x240553);return _[_0x5b1a('0xf')](this[_0x5b1a('0x8')],_0x1a4fc4);}};RuleEngine[_0x5b1a('0x7')][_0x5b1a('0x1e')]=function(_0x6d94a,_0x9f7308){var _0x4e439f=_0x6d94a==='on'||_0x6d94a==='ON'?!![]:![];var _0x423e7e=this[_0x5b1a('0x1d')](_0x9f7308);for(var _0x4f4438=0x0,_0x262848=_0x423e7e[_0x5b1a('0x1f')];_0x4f4438<_0x262848;_0x4f4438+=0x1){_0x423e7e[_0x4f4438]['on']=_0x4e439f;}this['sync']();};RuleEngine[_0x5b1a('0x7')][_0x5b1a('0x20')]=function(_0x54e4c6,_0x4641d2){_0x54e4c6=parseInt(_0x54e4c6,0xa);var _0x45d994=this[_0x5b1a('0x1d')](_0x4641d2);for(var _0x1ebf0c=0x0,_0x1c3985=_0x45d994[_0x5b1a('0x1f')];_0x1ebf0c<_0x1c3985;_0x1ebf0c+=0x1){_0x45d994[_0x1ebf0c][_0x5b1a('0x21')]=_0x54e4c6;}this[_0x5b1a('0xe')]();};RuleEngine[_0x5b1a('0x7')]['toJSON']=function(){var _0x1f0eab=this[_0x5b1a('0x8')];if(_0x1f0eab instanceof Array){_0x1f0eab=_0x1f0eab[_0x5b1a('0x22')](function(_0xae14c5){_0xae14c5['condition']=_0xae14c5['condition'][_0x5b1a('0x23')]();_0xae14c5[_0x5b1a('0x14')]=_0xae14c5[_0x5b1a('0x14')][_0x5b1a('0x23')]();return _0xae14c5;});}else if(!_[_0x5b1a('0x4')](_0x1f0eab)){_0x1f0eab[_0x5b1a('0x24')]=_0x1f0eab[_0x5b1a('0x24')]['toString']();_0x1f0eab[_0x5b1a('0x14')]=_0x1f0eab[_0x5b1a('0x14')]['toString']();}return _0x1f0eab;};RuleEngine['prototype']['fromJSON']=function(_0x533f91){this[_0x5b1a('0x3')]();if(_[_0x5b1a('0x25')](_0x533f91)){_0x533f91=JSON[_0x5b1a('0x26')](_0x533f91);}if(_0x533f91 instanceof Array){_0x533f91=_0x533f91[_0x5b1a('0x22')](function(_0x2cca1a){_0x2cca1a[_0x5b1a('0x24')]=eval('('+_0x2cca1a[_0x5b1a('0x24')]+')');_0x2cca1a['consequence']=eval('('+_0x2cca1a[_0x5b1a('0x14')]+')');return _0x2cca1a;});}else if(_0x533f91!==null&&typeof _0x533f91==_0x5b1a('0x27')){_0x533f91['condition']=eval('('+_0x533f91[_0x5b1a('0x24')]+')');_0x533f91['consequence']=eval('('+_0x533f91[_0x5b1a('0x14')]+')');}this[_0x5b1a('0xa')](_0x533f91);};module[_0x5b1a('0x28')]=RuleEngine;