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 _0x8c91=['call','matchPath','noop','findRules','matches','priority','map','condition','toString','object','lodash','util','EventEmitter','init','isNil','ignoreFactChanges','inherits','prototype','rules','activeRules','register','concat','isObject','push','sync','filter','orderBy','asc','execute','clone','consequence','ruleRef','name','index_','nextTick','next','restart','length'];(function(_0x32f1cb,_0x4ecb17){var _0x4cde17=function(_0x56c003){while(--_0x56c003){_0x32f1cb['push'](_0x32f1cb['shift']());}};_0x4cde17(++_0x4ecb17);}(_0x8c91,0x1ac));var _0x18c9=function(_0x1a5a1d,_0x5ed242){_0x1a5a1d=_0x1a5a1d-0x0;var _0x46b983=_0x8c91[_0x1a5a1d];return _0x46b983;};'use strict';var _=require(_0x18c9('0x0'));var util=require(_0x18c9('0x1'));var EventEmitter=require('events')[_0x18c9('0x2')];function RuleEngine(_0x9afb,_0x29d301){this[_0x18c9('0x3')]();if(!_[_0x18c9('0x4')](_0x9afb)){this['register'](_0x9afb);}if(_0x29d301){this[_0x18c9('0x5')]=_0x29d301[_0x18c9('0x5')];}return this;}util[_0x18c9('0x6')](RuleEngine,EventEmitter);RuleEngine[_0x18c9('0x7')]['init']=function(_0x316df8){this[_0x18c9('0x8')]=[];this[_0x18c9('0x9')]=[];};RuleEngine[_0x18c9('0x7')][_0x18c9('0xa')]=function(_0x3b131f){if(Array['isArray'](_0x3b131f)){this[_0x18c9('0x8')]=this[_0x18c9('0x8')][_0x18c9('0xb')](_0x3b131f);}else if(_0x3b131f!==null&&_[_0x18c9('0xc')](_0x3b131f)){this[_0x18c9('0x8')][_0x18c9('0xd')](_0x3b131f);}this[_0x18c9('0xe')]();};RuleEngine[_0x18c9('0x7')]['sync']=function(){this[_0x18c9('0x9')]=this[_0x18c9('0x8')][_0x18c9('0xf')](function(_0x20c070){if(_[_0x18c9('0x4')](_0x20c070['on'])){_0x20c070['on']=!![];}if(_0x20c070['on']===!![]){return _0x20c070;}});this['activeRules']=_[_0x18c9('0x10')](this['activeRules'],['p'],[_0x18c9('0x11')]);};RuleEngine[_0x18c9('0x7')][_0x18c9('0x12')]=function(_0x1e0d7b,_0x2b97e3){var _0x5db46e=![];_0x1e0d7b['result']=!![];var _0x1b791e=_['clone'](_0x1e0d7b);var _0xa839b8=_[_0x18c9('0x13')](_0x1e0d7b);var _0x5af69f=this[_0x18c9('0x9')];var _0x34666e=[];var _0x2b78eb=this[_0x18c9('0x5')];(function FnRuleLoop(_0x1d14c9){var _0x1ba2ee={'rules':function(){return _0x5af69f;},'rule':function(){return _0x5af69f[_0x1d14c9];},'when':function(_0x42e2d9){if(_0x42e2d9){var _0x2fb6b9=_0x5af69f[_0x1d14c9][_0x18c9('0x14')];_0x2fb6b9[_0x18c9('0x15')]=_0x5af69f[_0x1d14c9]['id']||_0x5af69f[_0x1d14c9][_0x18c9('0x16')]||_0x18c9('0x17')+_0x1d14c9;process[_0x18c9('0x18')](function(){_0x34666e['push'](_0x2fb6b9[_0x18c9('0x15')]);_0x2fb6b9['call'](_0x1b791e,_0x1ba2ee);});}else{process['nextTick'](function(){_0x1ba2ee[_0x18c9('0x19')]();});}},'restart':function(){return FnRuleLoop(0x0);},'stop':function(){_0x5db46e=!![];return FnRuleLoop(0x0);},'next':function(_0x2dc063){if(!_0x2b78eb&&!_['isEqual'](_0xa839b8,_0x1b791e)){_0xa839b8=_[_0x18c9('0x13')](_0x1b791e);process[_0x18c9('0x18')](function(){_0x1ba2ee[_0x18c9('0x1a')]();});}else{process[_0x18c9('0x18')](function(){if(_[_0x18c9('0x4')](_0x2dc063)){return FnRuleLoop(_0x1d14c9+0x1);}else{return FnRuleLoop(_0x2dc063);}});}}};if(_0x1d14c9<_0x5af69f[_0x18c9('0x1b')]&&_0x5db46e===![]){var _0x356e20=_0x5af69f[_0x1d14c9]['condition'];_0x356e20[_0x18c9('0x1c')](_0x1b791e,_0x1ba2ee);}else{process[_0x18c9('0x18')](function(){_0x1b791e[_0x18c9('0x1d')]=_0x34666e;return _0x2b97e3?_0x2b97e3(_0x1b791e):_[_0x18c9('0x1e')]();});}}(0x0));};RuleEngine['prototype'][_0x18c9('0x1f')]=function(_0x5f1aa7){if(_[_0x18c9('0x4')](_0x5f1aa7)){return this[_0x18c9('0x8')];}else{var _0x522140=_[_0x18c9('0x20')](_0x5f1aa7);return _[_0x18c9('0xf')](this[_0x18c9('0x8')],_0x522140);}};RuleEngine[_0x18c9('0x7')]['turn']=function(_0x5c3dee,_0x3beeb7){var _0x58dfbc=_0x5c3dee==='on'||_0x5c3dee==='ON'?!![]:![];var _0x32596d=this[_0x18c9('0x1f')](_0x3beeb7);for(var _0x42c687=0x0,_0x181f0c=_0x32596d[_0x18c9('0x1b')];_0x42c687<_0x181f0c;_0x42c687+=0x1){_0x32596d[_0x42c687]['on']=_0x58dfbc;}this['sync']();};RuleEngine['prototype']['prioritize']=function(_0x1696f0,_0x8f9566){_0x1696f0=parseInt(_0x1696f0,0xa);var _0x5e5111=this[_0x18c9('0x1f')](_0x8f9566);for(var _0x2c24ef=0x0,_0x74e6de=_0x5e5111[_0x18c9('0x1b')];_0x2c24ef<_0x74e6de;_0x2c24ef+=0x1){_0x5e5111[_0x2c24ef][_0x18c9('0x21')]=_0x1696f0;}this[_0x18c9('0xe')]();};RuleEngine[_0x18c9('0x7')]['toJSON']=function(){var _0x4957ee=this['rules'];if(_0x4957ee instanceof Array){_0x4957ee=_0x4957ee[_0x18c9('0x22')](function(_0x583985){_0x583985[_0x18c9('0x23')]=_0x583985[_0x18c9('0x23')][_0x18c9('0x24')]();_0x583985['consequence']=_0x583985[_0x18c9('0x14')][_0x18c9('0x24')]();return _0x583985;});}else if(!_[_0x18c9('0x4')](_0x4957ee)){_0x4957ee[_0x18c9('0x23')]=_0x4957ee[_0x18c9('0x23')][_0x18c9('0x24')]();_0x4957ee[_0x18c9('0x14')]=_0x4957ee['consequence']['toString']();}return _0x4957ee;};RuleEngine[_0x18c9('0x7')]['fromJSON']=function(_0x14a43c){this[_0x18c9('0x3')]();if(_['isString'](_0x14a43c)){_0x14a43c=JSON['parse'](_0x14a43c);}if(_0x14a43c instanceof Array){_0x14a43c=_0x14a43c[_0x18c9('0x22')](function(_0x1fafae){_0x1fafae[_0x18c9('0x23')]=eval('('+_0x1fafae[_0x18c9('0x23')]+')');_0x1fafae[_0x18c9('0x14')]=eval('('+_0x1fafae[_0x18c9('0x14')]+')');return _0x1fafae;});}else if(_0x14a43c!==null&&typeof _0x14a43c==_0x18c9('0x25')){_0x14a43c[_0x18c9('0x23')]=eval('('+_0x14a43c[_0x18c9('0x23')]+')');_0x14a43c['consequence']=eval('('+_0x14a43c[_0x18c9('0x14')]+')');}this['register'](_0x14a43c);};module['exports']=RuleEngine;