Built motion from commit (unavailable).|2.5.30
[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 _0xe508=['activeRules','isArray','rules','concat','isObject','sync','filter','isNil','asc','result','clone','ignoreFactChanges','consequence','nextTick','push','ruleRef','call','next','condition','matchPath','findRules','matches','length','toJSON','map','toString','fromJSON','isString','parse','object','exports','lodash','util','register','prototype','init'];(function(_0x401d67,_0xeb1592){var _0x25076b=function(_0x233577){while(--_0x233577){_0x401d67['push'](_0x401d67['shift']());}};_0x25076b(++_0xeb1592);}(_0xe508,0x67));var _0x8e50=function(_0x1a2d12,_0xf7379d){_0x1a2d12=_0x1a2d12-0x0;var _0x2d4e19=_0xe508[_0x1a2d12];return _0x2d4e19;};'use strict';var _=require(_0x8e50('0x0'));var util=require(_0x8e50('0x1'));var EventEmitter=require('events')['EventEmitter'];function RuleEngine(_0x5b8f75,_0x4b2aa5){this['init']();if(!_['isNil'](_0x5b8f75)){this[_0x8e50('0x2')](_0x5b8f75);}if(_0x4b2aa5){this['ignoreFactChanges']=_0x4b2aa5['ignoreFactChanges'];}return this;}util['inherits'](RuleEngine,EventEmitter);RuleEngine[_0x8e50('0x3')][_0x8e50('0x4')]=function(_0x2073b4){this['rules']=[];this[_0x8e50('0x5')]=[];};RuleEngine[_0x8e50('0x3')][_0x8e50('0x2')]=function(_0x2570c8){if(Array[_0x8e50('0x6')](_0x2570c8)){this['rules']=this[_0x8e50('0x7')][_0x8e50('0x8')](_0x2570c8);}else if(_0x2570c8!==null&&_[_0x8e50('0x9')](_0x2570c8)){this[_0x8e50('0x7')]['push'](_0x2570c8);}this[_0x8e50('0xa')]();};RuleEngine['prototype'][_0x8e50('0xa')]=function(){this[_0x8e50('0x5')]=this[_0x8e50('0x7')][_0x8e50('0xb')](function(_0x16f43d){if(_[_0x8e50('0xc')](_0x16f43d['on'])){_0x16f43d['on']=!![];}if(_0x16f43d['on']===!![]){return _0x16f43d;}});this[_0x8e50('0x5')]=_['orderBy'](this[_0x8e50('0x5')],['p'],[_0x8e50('0xd')]);};RuleEngine['prototype']['execute']=function(_0x19fb46,_0x1583e5){var _0xf35176=![];_0x19fb46[_0x8e50('0xe')]=!![];var _0x516a41=_[_0x8e50('0xf')](_0x19fb46);var _0x249242=_[_0x8e50('0xf')](_0x19fb46);var _0x20c5cb=this['activeRules'];var _0x30f096=[];var _0x658fe2=this[_0x8e50('0x10')];(function FnRuleLoop(_0x17c7cb){var _0x263e06={'rules':function(){return _0x20c5cb;},'rule':function(){return _0x20c5cb[_0x17c7cb];},'when':function(_0x322d3f){if(_0x322d3f){var _0x1bf3de=_0x20c5cb[_0x17c7cb][_0x8e50('0x11')];_0x1bf3de['ruleRef']=_0x20c5cb[_0x17c7cb]['id']||_0x20c5cb[_0x17c7cb]['name']||'index_'+_0x17c7cb;process[_0x8e50('0x12')](function(){_0x30f096[_0x8e50('0x13')](_0x1bf3de[_0x8e50('0x14')]);_0x1bf3de[_0x8e50('0x15')](_0x516a41,_0x263e06);});}else{process[_0x8e50('0x12')](function(){_0x263e06[_0x8e50('0x16')]();});}},'restart':function(){return FnRuleLoop(0x0);},'stop':function(){_0xf35176=!![];return FnRuleLoop(0x0);},'next':function(_0x1fd9af){if(!_0x658fe2&&!_['isEqual'](_0x249242,_0x516a41)){_0x249242=_[_0x8e50('0xf')](_0x516a41);process[_0x8e50('0x12')](function(){_0x263e06['restart']();});}else{process['nextTick'](function(){if(_[_0x8e50('0xc')](_0x1fd9af)){return FnRuleLoop(_0x17c7cb+0x1);}else{return FnRuleLoop(_0x1fd9af);}});}}};if(_0x17c7cb<_0x20c5cb['length']&&_0xf35176===![]){var _0x288405=_0x20c5cb[_0x17c7cb][_0x8e50('0x17')];_0x288405['call'](_0x516a41,_0x263e06);}else{process['nextTick'](function(){_0x516a41[_0x8e50('0x18')]=_0x30f096;return _0x1583e5?_0x1583e5(_0x516a41):_['noop']();});}}(0x0));};RuleEngine['prototype'][_0x8e50('0x19')]=function(_0x570872){if(_[_0x8e50('0xc')](_0x570872)){return this[_0x8e50('0x7')];}else{var _0x5f8c6=_[_0x8e50('0x1a')](_0x570872);return _[_0x8e50('0xb')](this[_0x8e50('0x7')],_0x5f8c6);}};RuleEngine['prototype']['turn']=function(_0x29ab39,_0x76941a){var _0x1a085b=_0x29ab39==='on'||_0x29ab39==='ON'?!![]:![];var _0xd1befe=this[_0x8e50('0x19')](_0x76941a);for(var _0x2cd03c=0x0,_0x367008=_0xd1befe[_0x8e50('0x1b')];_0x2cd03c<_0x367008;_0x2cd03c+=0x1){_0xd1befe[_0x2cd03c]['on']=_0x1a085b;}this['sync']();};RuleEngine[_0x8e50('0x3')]['prioritize']=function(_0x5eb1c9,_0x27027e){_0x5eb1c9=parseInt(_0x5eb1c9,0xa);var _0x43ef8d=this[_0x8e50('0x19')](_0x27027e);for(var _0x20b28a=0x0,_0x5d84ce=_0x43ef8d[_0x8e50('0x1b')];_0x20b28a<_0x5d84ce;_0x20b28a+=0x1){_0x43ef8d[_0x20b28a]['priority']=_0x5eb1c9;}this[_0x8e50('0xa')]();};RuleEngine[_0x8e50('0x3')][_0x8e50('0x1c')]=function(){var _0x55ae4a=this['rules'];if(_0x55ae4a instanceof Array){_0x55ae4a=_0x55ae4a[_0x8e50('0x1d')](function(_0x4fce58){_0x4fce58[_0x8e50('0x17')]=_0x4fce58['condition'][_0x8e50('0x1e')]();_0x4fce58[_0x8e50('0x11')]=_0x4fce58[_0x8e50('0x11')][_0x8e50('0x1e')]();return _0x4fce58;});}else if(!_[_0x8e50('0xc')](_0x55ae4a)){_0x55ae4a[_0x8e50('0x17')]=_0x55ae4a[_0x8e50('0x17')][_0x8e50('0x1e')]();_0x55ae4a['consequence']=_0x55ae4a['consequence']['toString']();}return _0x55ae4a;};RuleEngine[_0x8e50('0x3')][_0x8e50('0x1f')]=function(_0x5579c5){this[_0x8e50('0x4')]();if(_[_0x8e50('0x20')](_0x5579c5)){_0x5579c5=JSON[_0x8e50('0x21')](_0x5579c5);}if(_0x5579c5 instanceof Array){_0x5579c5=_0x5579c5[_0x8e50('0x1d')](function(_0x1bd3db){_0x1bd3db['condition']=eval('('+_0x1bd3db['condition']+')');_0x1bd3db[_0x8e50('0x11')]=eval('('+_0x1bd3db[_0x8e50('0x11')]+')');return _0x1bd3db;});}else if(_0x5579c5!==null&&typeof _0x5579c5==_0x8e50('0x22')){_0x5579c5[_0x8e50('0x17')]=eval('('+_0x5579c5[_0x8e50('0x17')]+')');_0x5579c5['consequence']=eval('('+_0x5579c5[_0x8e50('0x11')]+')');}this[_0x8e50('0x2')](_0x5579c5);};module[_0x8e50('0x23')]=RuleEngine;