Built motion from commit (unavailable).|2.5.4
[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 _0x1c32=['fromJSON','isString','parse','exports','lodash','util','EventEmitter','init','isNil','register','ignoreFactChanges','prototype','rules','isObject','push','sync','filter','activeRules','orderBy','asc','execute','result','clone','consequence','name','index_','nextTick','ruleRef','next','isEqual','length','condition','call','noop','findRules','turn','priority','toJSON','map','toString'];(function(_0x204a1a,_0x5aad4f){var _0x4ad386=function(_0x594fc8){while(--_0x594fc8){_0x204a1a['push'](_0x204a1a['shift']());}};_0x4ad386(++_0x5aad4f);}(_0x1c32,0x7c));var _0x21c3=function(_0x4a4922,_0x82cb8f){_0x4a4922=_0x4a4922-0x0;var _0x55a8c6=_0x1c32[_0x4a4922];return _0x55a8c6;};'use strict';var _=require(_0x21c3('0x0'));var util=require(_0x21c3('0x1'));var EventEmitter=require('events')[_0x21c3('0x2')];function RuleEngine(_0x31c14f,_0x3c4be6){this[_0x21c3('0x3')]();if(!_[_0x21c3('0x4')](_0x31c14f)){this[_0x21c3('0x5')](_0x31c14f);}if(_0x3c4be6){this[_0x21c3('0x6')]=_0x3c4be6[_0x21c3('0x6')];}return this;}util['inherits'](RuleEngine,EventEmitter);RuleEngine[_0x21c3('0x7')]['init']=function(_0xf8ac13){this[_0x21c3('0x8')]=[];this['activeRules']=[];};RuleEngine['prototype']['register']=function(_0x18aa06){if(Array['isArray'](_0x18aa06)){this[_0x21c3('0x8')]=this[_0x21c3('0x8')]['concat'](_0x18aa06);}else if(_0x18aa06!==null&&_[_0x21c3('0x9')](_0x18aa06)){this[_0x21c3('0x8')][_0x21c3('0xa')](_0x18aa06);}this[_0x21c3('0xb')]();};RuleEngine[_0x21c3('0x7')][_0x21c3('0xb')]=function(){this['activeRules']=this[_0x21c3('0x8')][_0x21c3('0xc')](function(_0x35e7a5){if(_['isNil'](_0x35e7a5['on'])){_0x35e7a5['on']=!![];}if(_0x35e7a5['on']===!![]){return _0x35e7a5;}});this[_0x21c3('0xd')]=_[_0x21c3('0xe')](this['activeRules'],['p'],[_0x21c3('0xf')]);};RuleEngine[_0x21c3('0x7')][_0x21c3('0x10')]=function(_0x23e444,_0xff6471){var _0xd7ea26=![];_0x23e444[_0x21c3('0x11')]=!![];var _0x5559b4=_[_0x21c3('0x12')](_0x23e444);var _0x16afab=_['clone'](_0x23e444);var _0x193222=this[_0x21c3('0xd')];var _0xa6d894=[];var _0x349c1f=this[_0x21c3('0x6')];(function FnRuleLoop(_0x348e5e){var _0x199164={'rules':function(){return _0x193222;},'rule':function(){return _0x193222[_0x348e5e];},'when':function(_0x275966){if(_0x275966){var _0x2eae41=_0x193222[_0x348e5e][_0x21c3('0x13')];_0x2eae41['ruleRef']=_0x193222[_0x348e5e]['id']||_0x193222[_0x348e5e][_0x21c3('0x14')]||_0x21c3('0x15')+_0x348e5e;process[_0x21c3('0x16')](function(){_0xa6d894[_0x21c3('0xa')](_0x2eae41[_0x21c3('0x17')]);_0x2eae41['call'](_0x5559b4,_0x199164);});}else{process[_0x21c3('0x16')](function(){_0x199164[_0x21c3('0x18')]();});}},'restart':function(){return FnRuleLoop(0x0);},'stop':function(){_0xd7ea26=!![];return FnRuleLoop(0x0);},'next':function(_0x4e4fa9){if(!_0x349c1f&&!_[_0x21c3('0x19')](_0x16afab,_0x5559b4)){_0x16afab=_[_0x21c3('0x12')](_0x5559b4);process[_0x21c3('0x16')](function(){_0x199164['restart']();});}else{process[_0x21c3('0x16')](function(){if(_[_0x21c3('0x4')](_0x4e4fa9)){return FnRuleLoop(_0x348e5e+0x1);}else{return FnRuleLoop(_0x4e4fa9);}});}}};if(_0x348e5e<_0x193222[_0x21c3('0x1a')]&&_0xd7ea26===![]){var _0x52f893=_0x193222[_0x348e5e][_0x21c3('0x1b')];_0x52f893[_0x21c3('0x1c')](_0x5559b4,_0x199164);}else{process[_0x21c3('0x16')](function(){_0x5559b4['matchPath']=_0xa6d894;return _0xff6471?_0xff6471(_0x5559b4):_[_0x21c3('0x1d')]();});}}(0x0));};RuleEngine[_0x21c3('0x7')][_0x21c3('0x1e')]=function(_0x3c6b97){if(_['isNil'](_0x3c6b97)){return this[_0x21c3('0x8')];}else{var _0x1e76d9=_['matches'](_0x3c6b97);return _[_0x21c3('0xc')](this['rules'],_0x1e76d9);}};RuleEngine['prototype'][_0x21c3('0x1f')]=function(_0x51bef5,_0x35e68e){var _0xf3a825=_0x51bef5==='on'||_0x51bef5==='ON'?!![]:![];var _0x5cb18e=this[_0x21c3('0x1e')](_0x35e68e);for(var _0x32114c=0x0,_0x8daf22=_0x5cb18e[_0x21c3('0x1a')];_0x32114c<_0x8daf22;_0x32114c+=0x1){_0x5cb18e[_0x32114c]['on']=_0xf3a825;}this[_0x21c3('0xb')]();};RuleEngine[_0x21c3('0x7')]['prioritize']=function(_0x23cc81,_0x28098a){_0x23cc81=parseInt(_0x23cc81,0xa);var _0x3d3466=this[_0x21c3('0x1e')](_0x28098a);for(var _0x502467=0x0,_0x270ec0=_0x3d3466[_0x21c3('0x1a')];_0x502467<_0x270ec0;_0x502467+=0x1){_0x3d3466[_0x502467][_0x21c3('0x20')]=_0x23cc81;}this['sync']();};RuleEngine[_0x21c3('0x7')][_0x21c3('0x21')]=function(){var _0x1b2c15=this[_0x21c3('0x8')];if(_0x1b2c15 instanceof Array){_0x1b2c15=_0x1b2c15[_0x21c3('0x22')](function(_0x30c6fb){_0x30c6fb[_0x21c3('0x1b')]=_0x30c6fb[_0x21c3('0x1b')][_0x21c3('0x23')]();_0x30c6fb[_0x21c3('0x13')]=_0x30c6fb[_0x21c3('0x13')][_0x21c3('0x23')]();return _0x30c6fb;});}else if(!_[_0x21c3('0x4')](_0x1b2c15)){_0x1b2c15[_0x21c3('0x1b')]=_0x1b2c15[_0x21c3('0x1b')][_0x21c3('0x23')]();_0x1b2c15[_0x21c3('0x13')]=_0x1b2c15[_0x21c3('0x13')][_0x21c3('0x23')]();}return _0x1b2c15;};RuleEngine[_0x21c3('0x7')][_0x21c3('0x24')]=function(_0x53ac15){this['init']();if(_[_0x21c3('0x25')](_0x53ac15)){_0x53ac15=JSON[_0x21c3('0x26')](_0x53ac15);}if(_0x53ac15 instanceof Array){_0x53ac15=_0x53ac15[_0x21c3('0x22')](function(_0x22ba75){_0x22ba75[_0x21c3('0x1b')]=eval('('+_0x22ba75[_0x21c3('0x1b')]+')');_0x22ba75[_0x21c3('0x13')]=eval('('+_0x22ba75['consequence']+')');return _0x22ba75;});}else if(_0x53ac15!==null&&typeof _0x53ac15=='object'){_0x53ac15['condition']=eval('('+_0x53ac15[_0x21c3('0x1b')]+')');_0x53ac15[_0x21c3('0x13')]=eval('('+_0x53ac15[_0x21c3('0x13')]+')');}this[_0x21c3('0x5')](_0x53ac15);};module[_0x21c3('0x27')]=RuleEngine;