// * treaties. The SOFTWARE PRODUCT is licensed, not sold. *
// * *
// *************************************************************************
-var _0x8f49=['FreshsalesConfiguration','FreshsalesField','getFields','username','remoteUri','apiKey','substring','lastIndexOf','GET','%s%s','/api/selector/owners','Token\x20token=','users','email','Requested\x20Resource\x20not\x20Found','getFields,\x20%s,\x20%s,\x20%s','send','Wrong\x20credentials','eml-format','zip-dir','request-promise','bluebird','mustache','util','path','sox','lodash','squel','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','../../components/integrations/configuration','jayson/promise','test','ValidationError','then','info','FreshsalesAccount,\x20%s,\x20%s','request\x20sent','debug','FreshsalesAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','status','end','json','count','offset','set','apply','reject','update','stack','name','FreshsalesAccount','rawAttributes','fieldName','type','key','model','map','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','limit','sort','where','pick','filter','merge','includeAll','include','findAll','params','find','catch','create','body','destroy','getConfigurations','findOne','keys','options','addConfiguration','AccountId','Subjects','channel','Descriptions','getDescriptions'];(function(_0x4531a9,_0xf6386b){var _0x959027=function(_0x343c0b){while(--_0x343c0b){_0x4531a9['push'](_0x4531a9['shift']());}};_0x959027(++_0xf6386b);}(_0x8f49,0x150));var _0x98f4=function(_0x487b43,_0x210e39){_0x487b43=_0x487b43-0x0;var _0x822e7=_0x8f49[_0x487b43];return _0x822e7;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x98f4('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x98f4('0x1'));var jsonpatch=require('fast-json-patch');var rp=require(_0x98f4('0x2'));var moment=require('moment');var BPromise=require(_0x98f4('0x3'));var Mustache=require(_0x98f4('0x4'));var util=require(_0x98f4('0x5'));var path=require(_0x98f4('0x6'));var sox=require(_0x98f4('0x7'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var _=require(_0x98f4('0x8'));var squel=require(_0x98f4('0x9'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0x98f4('0xa'));var querystring=require(_0x98f4('0xb'));var Papa=require(_0x98f4('0xc'));var Redis=require(_0x98f4('0xd'));var authService=require(_0x98f4('0xe'));var qs=require(_0x98f4('0xf'));var as=require(_0x98f4('0x10'));var hardwareService=require(_0x98f4('0x11'));var logger=require(_0x98f4('0x12'))(_0x98f4('0x13'));var utils=require(_0x98f4('0x14'));var config=require(_0x98f4('0x15'));var db=require(_0x98f4('0x16'))['db'];var integrations=require(_0x98f4('0x17'));var jayson=require(_0x98f4('0x18'));var client=jayson['client']['http']({'port':0x232a});function checkPasswordPattern(_0x43cc48,_0x1c953e,_0x2cf87e){if(_0x2cf87e){var _0x37712e=new RegExp(/(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[?!@#\$%\^&\*~\-_=+[{\]\}])(?=.{8,})/);if(_0x37712e[_0x98f4('0x19')](_0x1c953e)){return _0x43cc48;}else{throw new db['Sequelize'][(_0x98f4('0x1a'))]('The\x20password\x20must\x20be\x20at\x20least\x208\x20characters\x20long\x20and\x20have\x201\x20lowercase\x20character,\x201\x20uppercase\x20character,\x201\x20number\x20and\x201\x20special\x20character\x20~!@#$%^&-_=+[{]}.');}}else{return _0x43cc48;}}function respondWithRpcPromise(_0x5f5ba1,_0x507fb5,_0x3755b1,_0x33697a){return new BPromise(function(_0xdc23e6,_0x13a360){var _0x140332=_0x33697a||client;return _0x140332['request'](_0x5f5ba1,_0x3755b1)[_0x98f4('0x1b')](function(_0x5856b1){logger[_0x98f4('0x1c')](_0x98f4('0x1d'),_0x507fb5,_0x98f4('0x1e'));logger[_0x98f4('0x1f')](_0x98f4('0x20'),_0x507fb5,_0x98f4('0x1e'),JSON[_0x98f4('0x21')](_0x5856b1));if(_0x5856b1['error']){if(_0x5856b1[_0x98f4('0x22')][_0x98f4('0x23')]===0x1f4){logger['error'](_0x98f4('0x1d'),_0x507fb5,_0x5856b1[_0x98f4('0x22')]['message']);return _0x13a360(_0x5856b1[_0x98f4('0x22')][_0x98f4('0x24')]);}logger['error'](_0x98f4('0x1d'),_0x507fb5,_0x5856b1['error'][_0x98f4('0x24')]);return _0xdc23e6(_0x5856b1[_0x98f4('0x22')]['message']);}else{logger[_0x98f4('0x1c')]('FreshsalesAccount,\x20%s,\x20%s',_0x507fb5,'request\x20sent');_0xdc23e6(_0x5856b1['result']['message']);}})['catch'](function(_0x47de3b){logger['error'](_0x98f4('0x1d'),_0x507fb5,_0x47de3b);_0x13a360(_0x47de3b);});});}function respondWithStatusCode(_0x11d538,_0x4be1df){_0x4be1df=_0x4be1df||0xcc;return function(_0x2319e2){if(_0x2319e2){return _0x11d538['sendStatus'](_0x4be1df);}return _0x11d538[_0x98f4('0x25')](_0x4be1df)[_0x98f4('0x26')]();};}function respondWithResult(_0x296c76,_0x42aaa8){_0x42aaa8=_0x42aaa8||0xc8;return function(_0x10aa79){if(_0x10aa79){return _0x296c76[_0x98f4('0x25')](_0x42aaa8)[_0x98f4('0x27')](_0x10aa79);}};}function respondWithFilteredResult(_0x2c681f,_0x531786){return function(_0x65f641){if(_0x65f641){var _0x54be8f=_0x65f641[_0x98f4('0x28')],_0x4ff6f6=_0x531786['offset'],_0xdb7b19=_0x531786[_0x98f4('0x29')]+_0x531786['limit'],_0x30bc28;if(_0xdb7b19>=_0x54be8f){_0xdb7b19=_0x54be8f;_0x30bc28=0xc8;}else{_0x30bc28=0xce;}_0x2c681f[_0x98f4('0x25')](_0x30bc28);return _0x2c681f[_0x98f4('0x2a')]('Content-Range',_0x4ff6f6+'-'+_0xdb7b19+'/'+_0x54be8f)[_0x98f4('0x27')](_0x65f641);}return null;};}function patchUpdates(_0x534cc6){return function(_0x38adf0){try{jsonpatch[_0x98f4('0x2b')](_0x38adf0,_0x534cc6,!![]);}catch(_0x27a7a3){return BPromise[_0x98f4('0x2c')](_0x27a7a3);}return _0x38adf0['save']();};}function saveUpdates(_0x1976f1,_0x28537f){return function(_0x47147e){if(_0x47147e){return _0x47147e[_0x98f4('0x2d')](_0x1976f1)[_0x98f4('0x1b')](function(_0x120533){return _0x120533;});}return null;};}function removeEntity(_0x1b13a7,_0x4f079b){return function(_0x6a089e){if(_0x6a089e){return _0x6a089e['destroy']()['then'](function(){_0x1b13a7[_0x98f4('0x25')](0xcc)[_0x98f4('0x26')]();});}};}function handleEntityNotFound(_0x378523,_0x23a192){return function(_0x177b75){if(!_0x177b75){_0x378523['sendStatus'](0x194);}return _0x177b75;};}function handleError(_0xed1ce2,_0x246756){_0x246756=_0x246756||0x1f4;return function(_0xc59d47){logger[_0x98f4('0x22')](_0xc59d47[_0x98f4('0x2e')]);if(_0xc59d47['name']){delete _0xc59d47[_0x98f4('0x2f')];}_0xed1ce2[_0x98f4('0x25')](_0x246756)['send'](_0xc59d47);};}exports['index']=function(_0x276552,_0x4df417){var _0x58e3c7={},_0x787e91={},_0x80bee9={'count':0x0,'rows':[]};var _0x225aa0=_['map'](db[_0x98f4('0x30')][_0x98f4('0x31')],function(_0x4dd66c){return{'name':_0x4dd66c[_0x98f4('0x32')],'type':_0x4dd66c[_0x98f4('0x33')][_0x98f4('0x34')]};});_0x787e91[_0x98f4('0x35')]=_[_0x98f4('0x36')](_0x225aa0,'name');_0x787e91[_0x98f4('0x37')]=_['keys'](_0x276552[_0x98f4('0x37')]);_0x787e91[_0x98f4('0x38')]=_[_0x98f4('0x39')](_0x787e91[_0x98f4('0x35')],_0x787e91[_0x98f4('0x37')]);_0x58e3c7[_0x98f4('0x3a')]=_[_0x98f4('0x39')](_0x787e91[_0x98f4('0x35')],qs[_0x98f4('0x3b')](_0x276552['query'][_0x98f4('0x3b')]));_0x58e3c7[_0x98f4('0x3a')]=_0x58e3c7['attributes'][_0x98f4('0x3c')]?_0x58e3c7[_0x98f4('0x3a')]:_0x787e91[_0x98f4('0x35')];if(!_0x276552[_0x98f4('0x37')][_0x98f4('0x3d')](_0x98f4('0x3e'))){_0x58e3c7[_0x98f4('0x3f')]=qs[_0x98f4('0x3f')](_0x276552['query'][_0x98f4('0x3f')]);_0x58e3c7[_0x98f4('0x29')]=qs[_0x98f4('0x29')](_0x276552['query'][_0x98f4('0x29')]);}_0x58e3c7['order']=qs[_0x98f4('0x40')](_0x276552['query']['sort']);_0x58e3c7[_0x98f4('0x41')]=qs['filters'](_[_0x98f4('0x42')](_0x276552[_0x98f4('0x37')],_0x787e91[_0x98f4('0x38')]),_0x225aa0);if(_0x276552[_0x98f4('0x37')][_0x98f4('0x43')]){_0x58e3c7['where']=_[_0x98f4('0x44')](_0x58e3c7[_0x98f4('0x41')],{'$or':_[_0x98f4('0x36')](_0x225aa0,function(_0x4b44c9){if(_0x4b44c9[_0x98f4('0x33')]!=='VIRTUAL'){var _0x55aa81={};_0x55aa81[_0x4b44c9[_0x98f4('0x2f')]]={'$like':'%'+_0x276552[_0x98f4('0x37')]['filter']+'%'};return _0x55aa81;}})});}_0x58e3c7=_[_0x98f4('0x44')]({},_0x58e3c7,_0x276552['options']);var _0x3cf4cc={'where':_0x58e3c7[_0x98f4('0x41')]};return db['FreshsalesAccount'][_0x98f4('0x28')](_0x3cf4cc)['then'](function(_0x1e74fa){_0x80bee9[_0x98f4('0x28')]=_0x1e74fa;if(_0x276552[_0x98f4('0x37')][_0x98f4('0x45')]){_0x58e3c7[_0x98f4('0x46')]=[{'all':!![]}];}return db[_0x98f4('0x30')][_0x98f4('0x47')](_0x58e3c7);})[_0x98f4('0x1b')](function(_0x263c72){_0x80bee9['rows']=_0x263c72;return _0x80bee9;})['then'](respondWithFilteredResult(_0x4df417,_0x58e3c7))['catch'](handleError(_0x4df417,null));};exports['show']=function(_0x46703d,_0x1fc96f){var _0x384cb4={'raw':![],'where':{'id':_0x46703d[_0x98f4('0x48')]['id']}},_0x26cd6f={};_0x26cd6f[_0x98f4('0x35')]=_['keys'](db[_0x98f4('0x30')][_0x98f4('0x31')]);_0x26cd6f[_0x98f4('0x37')]=_['keys'](_0x46703d['query']);_0x26cd6f['filters']=_[_0x98f4('0x39')](_0x26cd6f[_0x98f4('0x35')],_0x26cd6f[_0x98f4('0x37')]);_0x384cb4[_0x98f4('0x3a')]=_['intersection'](_0x26cd6f['model'],qs[_0x98f4('0x3b')](_0x46703d[_0x98f4('0x37')][_0x98f4('0x3b')]));_0x384cb4[_0x98f4('0x3a')]=_0x384cb4[_0x98f4('0x3a')]['length']?_0x384cb4[_0x98f4('0x3a')]:_0x26cd6f[_0x98f4('0x35')];if(_0x46703d['query']['includeAll']){_0x384cb4[_0x98f4('0x46')]=[{'all':!![]}];}_0x384cb4=_[_0x98f4('0x44')]({},_0x384cb4,_0x46703d['options']);return db[_0x98f4('0x30')][_0x98f4('0x49')](_0x384cb4)['then'](handleEntityNotFound(_0x1fc96f,null))[_0x98f4('0x1b')](respondWithResult(_0x1fc96f,null))[_0x98f4('0x4a')](handleError(_0x1fc96f,null));};exports[_0x98f4('0x4b')]=function(_0x45ad6a,_0x1ddd3e){return db[_0x98f4('0x30')]['create'](_0x45ad6a[_0x98f4('0x4c')],{})['then'](respondWithResult(_0x1ddd3e,0xc9))[_0x98f4('0x4a')](handleError(_0x1ddd3e,null));};exports[_0x98f4('0x2d')]=function(_0x252794,_0x3247ea){if(_0x252794['body']['id']){delete _0x252794[_0x98f4('0x4c')]['id'];}return db[_0x98f4('0x30')][_0x98f4('0x49')]({'where':{'id':_0x252794[_0x98f4('0x48')]['id']}})['then'](handleEntityNotFound(_0x3247ea,null))[_0x98f4('0x1b')](saveUpdates(_0x252794[_0x98f4('0x4c')],null))[_0x98f4('0x1b')](respondWithResult(_0x3247ea,null))['catch'](handleError(_0x3247ea,null));};exports[_0x98f4('0x4d')]=function(_0xdb506,_0x488c3a){return db['FreshsalesAccount']['find']({'where':{'id':_0xdb506[_0x98f4('0x48')]['id']}})[_0x98f4('0x1b')](handleEntityNotFound(_0x488c3a,null))['then'](removeEntity(_0x488c3a,null))['catch'](handleError(_0x488c3a,null));};exports[_0x98f4('0x4e')]=function(_0x39c975,_0x450ca1,_0x1e0f3d){var _0x4ca876={};var _0x5f4c67={};var _0x2e133c;var _0x1ce047;return db[_0x98f4('0x30')][_0x98f4('0x4f')]({'where':{'id':_0x39c975[_0x98f4('0x48')]['id']}})['then'](handleEntityNotFound(_0x450ca1,null))[_0x98f4('0x1b')](function(_0x5e9eea){if(_0x5e9eea){_0x2e133c=_0x5e9eea;_0x5f4c67['model']=_[_0x98f4('0x50')](db['FreshsalesConfiguration'][_0x98f4('0x31')]);_0x5f4c67[_0x98f4('0x37')]=_['keys'](_0x39c975[_0x98f4('0x37')]);_0x5f4c67[_0x98f4('0x38')]=_[_0x98f4('0x39')](_0x5f4c67[_0x98f4('0x35')],_0x5f4c67[_0x98f4('0x37')]);_0x4ca876[_0x98f4('0x3a')]=_[_0x98f4('0x39')](_0x5f4c67['model'],qs[_0x98f4('0x3b')](_0x39c975[_0x98f4('0x37')][_0x98f4('0x3b')]));_0x4ca876[_0x98f4('0x3a')]=_0x4ca876[_0x98f4('0x3a')]['length']?_0x4ca876[_0x98f4('0x3a')]:_0x5f4c67['model'];_0x4ca876['order']=qs[_0x98f4('0x40')](_0x39c975[_0x98f4('0x37')][_0x98f4('0x40')]);_0x4ca876[_0x98f4('0x41')]=qs[_0x98f4('0x38')](_[_0x98f4('0x42')](_0x39c975[_0x98f4('0x37')],_0x5f4c67[_0x98f4('0x38')]));if(_0x39c975[_0x98f4('0x37')][_0x98f4('0x43')]){_0x4ca876[_0x98f4('0x41')]=_[_0x98f4('0x44')](_0x4ca876[_0x98f4('0x41')],{'$or':_[_0x98f4('0x36')](_0x4ca876[_0x98f4('0x3a')],function(_0x485a99){var _0x4b3575={};_0x4b3575[_0x485a99]={'$like':'%'+_0x39c975[_0x98f4('0x37')]['filter']+'%'};return _0x4b3575;})});}_0x4ca876=_[_0x98f4('0x44')]({},_0x4ca876,_0x39c975[_0x98f4('0x51')]);return _0x2e133c[_0x98f4('0x4e')](_0x4ca876);}})[_0x98f4('0x1b')](function(_0x3dc39a){if(_0x3dc39a){_0x1ce047=_0x3dc39a[_0x98f4('0x3c')];if(!_0x39c975['query'][_0x98f4('0x3d')]('nolimit')){_0x4ca876[_0x98f4('0x3f')]=qs[_0x98f4('0x3f')](_0x39c975[_0x98f4('0x37')]['limit']);_0x4ca876['offset']=qs[_0x98f4('0x29')](_0x39c975[_0x98f4('0x37')]['offset']);}return _0x2e133c['getConfigurations'](_0x4ca876);}})[_0x98f4('0x1b')](function(_0x4784bf){if(_0x4784bf){return _0x4784bf?{'count':_0x1ce047,'rows':_0x4784bf}:null;}})[_0x98f4('0x1b')](respondWithResult(_0x450ca1,null))[_0x98f4('0x4a')](handleError(_0x450ca1,null));};exports[_0x98f4('0x52')]=function(_0xf108b,_0x49cfa3,_0xa48f7c){if(_0xf108b[_0x98f4('0x4c')]['id']){delete _0xf108b[_0x98f4('0x4c')]['id'];}return db['FreshsalesAccount']['findOne']({'where':{'id':_0xf108b['params']['id']}})[_0x98f4('0x1b')](handleEntityNotFound(_0x49cfa3,null))['then'](function(_0xdda68a){if(_0xdda68a){_0xf108b[_0x98f4('0x4c')][_0x98f4('0x53')]=_0xdda68a['id'];_0xf108b[_0x98f4('0x4c')][_0x98f4('0x54')]=integrations['getSubjects'](_0xf108b[_0x98f4('0x4c')][_0x98f4('0x55')],_0xf108b['body'][_0x98f4('0x33')]);_0xf108b[_0x98f4('0x4c')][_0x98f4('0x56')]=integrations[_0x98f4('0x57')](_0xf108b[_0x98f4('0x4c')][_0x98f4('0x55')],_0xf108b[_0x98f4('0x4c')][_0x98f4('0x33')]);return db[_0x98f4('0x58')]['create'](_0xf108b[_0x98f4('0x4c')],{'include':[{'model':db[_0x98f4('0x59')],'as':_0x98f4('0x54')},{'model':db['FreshsalesField'],'as':_0x98f4('0x56')}]});}return null;})['then'](respondWithResult(_0x49cfa3,null))['catch'](handleError(_0x49cfa3,null));};exports[_0x98f4('0x5a')]=function(_0x2525d4,_0xa973a3,_0xbee54b){var _0x4f3207='';var _0x517cc4='';return db[_0x98f4('0x30')][_0x98f4('0x4f')]({'where':{'id':_0x2525d4['params']['id']},'attributes':['id',_0x98f4('0x5b'),_0x98f4('0x5c'),_0x98f4('0x5d')]})[_0x98f4('0x1b')](handleEntityNotFound(_0xa973a3,null))[_0x98f4('0x1b')](function(_0x588e01){if(_0x588e01){_0x517cc4=_0x588e01['username'];_0x4f3207=_0x588e01[_0x98f4('0x5c')];var _0x3617ab=_0x588e01['remoteUri']['slice'](-0x1);if(_0x3617ab==='/'){_0x4f3207=_0x4f3207[_0x98f4('0x5e')](0x0,_0x4f3207[_0x98f4('0x5f')](_0x3617ab));}return rp({'method':_0x98f4('0x60'),'uri':util['format'](_0x98f4('0x61'),_0x4f3207,_0x98f4('0x62')),'headers':{'Authorization':_0x98f4('0x63')+_0x588e01['apiKey']},'json':!![]});}})[_0x98f4('0x1b')](function(_0x40d74d){if(_0x40d74d){var _0x1e7f90=_0x40d74d[_0x98f4('0x64')];var _0x112d86=![];var _0x32bc5f=null;for(_0x32bc5f=0x0;_0x32bc5f<_0x1e7f90[_0x98f4('0x3c')];_0x32bc5f++){if(_0x1e7f90[_0x32bc5f][_0x98f4('0x65')]===_0x517cc4){_0x112d86=!![];}}if(_0x112d86){return!![];}else{throw new Error({'statusCode':0x194,'message':_0x98f4('0x66')});}}})[_0x98f4('0x1b')](respondWithResult(_0xa973a3,null))[_0x98f4('0x4a')](function(_0x24962b){var _0x544053=_0x2525d4[_0x98f4('0x37')][_0x98f4('0x19')]?0x1f4:_0x24962b['statusCode']||0x1f4;logger[_0x98f4('0x22')](_0x98f4('0x67'),_0x98f4('0x5a'),_0x544053,JSON['stringify'](_0x24962b));delete _0x24962b[_0x98f4('0x2f')];if(_0x544053===0x191){_0x544053=0x190;}_0xa973a3['status'](_0x544053)[_0x98f4('0x68')](_0x2525d4[_0x98f4('0x37')][_0x98f4('0x19')]?{'message':_0x98f4('0x69'),'statusCode':_0x24962b['statusCode']}:_0x24962b);});};
\ No newline at end of file
+var _0xac3e=['undefined','count','set','apply','save','then','destroy','error','name','send','index','FreshsalesAccount','rawAttributes','fieldName','type','model','map','query','keys','intersection','attributes','fields','nolimit','order','sort','filters','pick','where','filter','merge','includeAll','include','findAll','show','params','length','options','find','catch','create','body','update','getConfigurations','findOne','FreshsalesConfiguration','hasOwnProperty','addConfiguration','AccountId','Subjects','channel','Descriptions','getDescriptions','FreshsalesField','username','remoteUri','apiKey','slice','substring','lastIndexOf','GET','%s%s','Token\x20token=','users','Requested\x20Resource\x20not\x20Found','test','statusCode','stringify','Wrong\x20credentials','eml-format','rimraf','zip-dir','fast-json-patch','moment','mustache','ejs','lodash','squel','crypto','jsforce','desk.js','to-csv','querystring','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','limit'];(function(_0x4fbdc0,_0x5bf025){var _0x2ed5b4=function(_0x1d87f0){while(--_0x1d87f0){_0x4fbdc0['push'](_0x4fbdc0['shift']());}};_0x2ed5b4(++_0x5bf025);}(_0xac3e,0x164));var _0xeac3=function(_0x5db99b,_0xdee23a){_0x5db99b=_0x5db99b-0x0;var _0x4b2d0e=_0xac3e[_0x5db99b];return _0x4b2d0e;};'use strict';var emlformat=require(_0xeac3('0x0'));var rimraf=require(_0xeac3('0x1'));var zipdir=require(_0xeac3('0x2'));var jsonpatch=require(_0xeac3('0x3'));var rp=require('request-promise');var moment=require(_0xeac3('0x4'));var BPromise=require('bluebird');var Mustache=require(_0xeac3('0x5'));var util=require('util');var path=require('path');var sox=require('sox');var csv=require('to-csv');var ejs=require(_0xeac3('0x6'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xeac3('0x7'));var squel=require(_0xeac3('0x8'));var crypto=require(_0xeac3('0x9'));var jsforce=require(_0xeac3('0xa'));var deskjs=require(_0xeac3('0xb'));var toCsv=require(_0xeac3('0xc'));var querystring=require(_0xeac3('0xd'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0xeac3('0xe'));var qs=require(_0xeac3('0xf'));var as=require(_0xeac3('0x10'));var hardwareService=require(_0xeac3('0x11'));var logger=require('../../config/logger')(_0xeac3('0x12'));var utils=require('../../config/utils');var config=require(_0xeac3('0x13'));var licenseUtil=require(_0xeac3('0x14'));var db=require(_0xeac3('0x15'))['db'];var integrations=require('../../components/integrations/configuration');function respondWithStatusCode(_0x2c381f,_0x502d92){_0x502d92=_0x502d92||0xcc;return function(_0x31d63d){if(_0x31d63d){return _0x2c381f[_0xeac3('0x16')](_0x502d92);}return _0x2c381f[_0xeac3('0x17')](_0x502d92)[_0xeac3('0x18')]();};}function respondWithResult(_0x58c186,_0xcf2ac4){_0xcf2ac4=_0xcf2ac4||0xc8;return function(_0x4285b8){if(_0x4285b8){return _0x58c186['status'](_0xcf2ac4)[_0xeac3('0x19')](_0x4285b8);}};}function respondWithFilteredResult(_0x444ded,_0x2e4daa){return function(_0x44b082){if(_0x44b082){var _0x10152b=typeof _0x2e4daa[_0xeac3('0x1a')]==='undefined'&&typeof _0x2e4daa[_0xeac3('0x1b')]===_0xeac3('0x1c');var _0x199108=_0x44b082[_0xeac3('0x1d')];var _0x3404ed=_0x10152b?0x0:_0x2e4daa[_0xeac3('0x1a')];var _0x2267a8=_0x10152b?_0x44b082[_0xeac3('0x1d')]:_0x2e4daa[_0xeac3('0x1a')]+_0x2e4daa['limit'];var _0x43c321;if(_0x2267a8>=_0x199108){_0x2267a8=_0x199108;_0x43c321=0xc8;}else{_0x43c321=0xce;}_0x444ded[_0xeac3('0x17')](_0x43c321);return _0x444ded[_0xeac3('0x1e')]('Content-Range',_0x3404ed+'-'+_0x2267a8+'/'+_0x199108)[_0xeac3('0x19')](_0x44b082);}return null;};}function patchUpdates(_0x269d2c){return function(_0x4d2e66){try{jsonpatch[_0xeac3('0x1f')](_0x4d2e66,_0x269d2c,!![]);}catch(_0xf4a0c3){return BPromise['reject'](_0xf4a0c3);}return _0x4d2e66[_0xeac3('0x20')]();};}function saveUpdates(_0x20e3c2,_0x5efa9e){return function(_0x3ee41e){if(_0x3ee41e){return _0x3ee41e['update'](_0x20e3c2)[_0xeac3('0x21')](function(_0xa82d4b){return _0xa82d4b;});}return null;};}function removeEntity(_0x2a6df0,_0xa66171){return function(_0x3c85a7){if(_0x3c85a7){return _0x3c85a7[_0xeac3('0x22')]()[_0xeac3('0x21')](function(){_0x2a6df0[_0xeac3('0x17')](0xcc)['end']();});}};}function handleEntityNotFound(_0x5c8172,_0x15813e){return function(_0x163f7d){if(!_0x163f7d){_0x5c8172[_0xeac3('0x16')](0x194);}return _0x163f7d;};}function handleError(_0x2fd0a9,_0x28340e){_0x28340e=_0x28340e||0x1f4;return function(_0x34ad48){logger[_0xeac3('0x23')](_0x34ad48['stack']);if(_0x34ad48['name']){delete _0x34ad48[_0xeac3('0x24')];}_0x2fd0a9['status'](_0x28340e)[_0xeac3('0x25')](_0x34ad48);};}exports[_0xeac3('0x26')]=function(_0x30aea,_0x1218a7){var _0x67ec2e={},_0x1d3df3={},_0x213374={'count':0x0,'rows':[]};var _0x53fc59=_['map'](db[_0xeac3('0x27')][_0xeac3('0x28')],function(_0x57d89f){return{'name':_0x57d89f[_0xeac3('0x29')],'type':_0x57d89f[_0xeac3('0x2a')]['key']};});_0x1d3df3[_0xeac3('0x2b')]=_[_0xeac3('0x2c')](_0x53fc59,_0xeac3('0x24'));_0x1d3df3[_0xeac3('0x2d')]=_[_0xeac3('0x2e')](_0x30aea[_0xeac3('0x2d')]);_0x1d3df3['filters']=_[_0xeac3('0x2f')](_0x1d3df3[_0xeac3('0x2b')],_0x1d3df3['query']);_0x67ec2e[_0xeac3('0x30')]=_[_0xeac3('0x2f')](_0x1d3df3[_0xeac3('0x2b')],qs[_0xeac3('0x31')](_0x30aea[_0xeac3('0x2d')][_0xeac3('0x31')]));_0x67ec2e['attributes']=_0x67ec2e[_0xeac3('0x30')]['length']?_0x67ec2e[_0xeac3('0x30')]:_0x1d3df3['model'];if(!_0x30aea['query']['hasOwnProperty'](_0xeac3('0x32'))){_0x67ec2e[_0xeac3('0x1b')]=qs[_0xeac3('0x1b')](_0x30aea[_0xeac3('0x2d')][_0xeac3('0x1b')]);_0x67ec2e[_0xeac3('0x1a')]=qs[_0xeac3('0x1a')](_0x30aea[_0xeac3('0x2d')][_0xeac3('0x1a')]);}_0x67ec2e[_0xeac3('0x33')]=qs[_0xeac3('0x34')](_0x30aea[_0xeac3('0x2d')][_0xeac3('0x34')]);_0x67ec2e['where']=qs[_0xeac3('0x35')](_[_0xeac3('0x36')](_0x30aea[_0xeac3('0x2d')],_0x1d3df3[_0xeac3('0x35')]),_0x53fc59);if(_0x30aea[_0xeac3('0x2d')]['filter']){_0x67ec2e[_0xeac3('0x37')]=_['merge'](_0x67ec2e['where'],{'$or':_[_0xeac3('0x2c')](_0x53fc59,function(_0x1ea804){if(_0x1ea804['type']!=='VIRTUAL'){var _0x30f0d7={};_0x30f0d7[_0x1ea804[_0xeac3('0x24')]]={'$like':'%'+_0x30aea['query'][_0xeac3('0x38')]+'%'};return _0x30f0d7;}})});}_0x67ec2e=_[_0xeac3('0x39')]({},_0x67ec2e,_0x30aea['options']);var _0x150875={'where':_0x67ec2e[_0xeac3('0x37')]};return db['FreshsalesAccount']['count'](_0x150875)[_0xeac3('0x21')](function(_0x83a7fe){_0x213374[_0xeac3('0x1d')]=_0x83a7fe;if(_0x30aea[_0xeac3('0x2d')][_0xeac3('0x3a')]){_0x67ec2e[_0xeac3('0x3b')]=[{'all':!![]}];}return db[_0xeac3('0x27')][_0xeac3('0x3c')](_0x67ec2e);})['then'](function(_0x20295f){_0x213374['rows']=_0x20295f;return _0x213374;})[_0xeac3('0x21')](respondWithFilteredResult(_0x1218a7,_0x67ec2e))['catch'](handleError(_0x1218a7,null));};exports[_0xeac3('0x3d')]=function(_0x51e9ad,_0x248ba1){var _0xbb6c4e={'raw':![],'where':{'id':_0x51e9ad[_0xeac3('0x3e')]['id']}},_0x52be66={};_0x52be66[_0xeac3('0x2b')]=_['keys'](db[_0xeac3('0x27')][_0xeac3('0x28')]);_0x52be66[_0xeac3('0x2d')]=_[_0xeac3('0x2e')](_0x51e9ad[_0xeac3('0x2d')]);_0x52be66[_0xeac3('0x35')]=_['intersection'](_0x52be66[_0xeac3('0x2b')],_0x52be66[_0xeac3('0x2d')]);_0xbb6c4e['attributes']=_[_0xeac3('0x2f')](_0x52be66[_0xeac3('0x2b')],qs[_0xeac3('0x31')](_0x51e9ad[_0xeac3('0x2d')][_0xeac3('0x31')]));_0xbb6c4e['attributes']=_0xbb6c4e[_0xeac3('0x30')][_0xeac3('0x3f')]?_0xbb6c4e[_0xeac3('0x30')]:_0x52be66[_0xeac3('0x2b')];if(_0x51e9ad[_0xeac3('0x2d')][_0xeac3('0x3a')]){_0xbb6c4e[_0xeac3('0x3b')]=[{'all':!![]}];}_0xbb6c4e=_['merge']({},_0xbb6c4e,_0x51e9ad[_0xeac3('0x40')]);return db['FreshsalesAccount'][_0xeac3('0x41')](_0xbb6c4e)[_0xeac3('0x21')](handleEntityNotFound(_0x248ba1,null))[_0xeac3('0x21')](respondWithResult(_0x248ba1,null))[_0xeac3('0x42')](handleError(_0x248ba1,null));};exports['create']=function(_0x319a79,_0x3d9b73){return db[_0xeac3('0x27')][_0xeac3('0x43')](_0x319a79[_0xeac3('0x44')],{})[_0xeac3('0x21')](respondWithResult(_0x3d9b73,0xc9))[_0xeac3('0x42')](handleError(_0x3d9b73,null));};exports[_0xeac3('0x45')]=function(_0x18eac7,_0x343a58){if(_0x18eac7[_0xeac3('0x44')]['id']){delete _0x18eac7[_0xeac3('0x44')]['id'];}return db[_0xeac3('0x27')][_0xeac3('0x41')]({'where':{'id':_0x18eac7[_0xeac3('0x3e')]['id']}})[_0xeac3('0x21')](handleEntityNotFound(_0x343a58,null))[_0xeac3('0x21')](saveUpdates(_0x18eac7[_0xeac3('0x44')],null))[_0xeac3('0x21')](respondWithResult(_0x343a58,null))['catch'](handleError(_0x343a58,null));};exports['destroy']=function(_0x1b4691,_0x21ab1e){return db[_0xeac3('0x27')][_0xeac3('0x41')]({'where':{'id':_0x1b4691[_0xeac3('0x3e')]['id']}})['then'](handleEntityNotFound(_0x21ab1e,null))[_0xeac3('0x21')](removeEntity(_0x21ab1e,null))[_0xeac3('0x42')](handleError(_0x21ab1e,null));};exports[_0xeac3('0x46')]=function(_0x36f83c,_0x8796e5,_0x27c7b2){var _0x1c8852={};var _0x520c66={};var _0x1243ec;var _0x3f3f50;return db['FreshsalesAccount'][_0xeac3('0x47')]({'where':{'id':_0x36f83c[_0xeac3('0x3e')]['id']}})[_0xeac3('0x21')](handleEntityNotFound(_0x8796e5,null))['then'](function(_0x263b6b){if(_0x263b6b){_0x1243ec=_0x263b6b;_0x520c66[_0xeac3('0x2b')]=_[_0xeac3('0x2e')](db[_0xeac3('0x48')]['rawAttributes']);_0x520c66[_0xeac3('0x2d')]=_[_0xeac3('0x2e')](_0x36f83c[_0xeac3('0x2d')]);_0x520c66[_0xeac3('0x35')]=_[_0xeac3('0x2f')](_0x520c66[_0xeac3('0x2b')],_0x520c66['query']);_0x1c8852[_0xeac3('0x30')]=_[_0xeac3('0x2f')](_0x520c66[_0xeac3('0x2b')],qs[_0xeac3('0x31')](_0x36f83c[_0xeac3('0x2d')][_0xeac3('0x31')]));_0x1c8852[_0xeac3('0x30')]=_0x1c8852['attributes'][_0xeac3('0x3f')]?_0x1c8852[_0xeac3('0x30')]:_0x520c66[_0xeac3('0x2b')];_0x1c8852[_0xeac3('0x33')]=qs[_0xeac3('0x34')](_0x36f83c['query'][_0xeac3('0x34')]);_0x1c8852[_0xeac3('0x37')]=qs[_0xeac3('0x35')](_['pick'](_0x36f83c[_0xeac3('0x2d')],_0x520c66[_0xeac3('0x35')]));if(_0x36f83c['query']['filter']){_0x1c8852[_0xeac3('0x37')]=_[_0xeac3('0x39')](_0x1c8852[_0xeac3('0x37')],{'$or':_['map'](_0x1c8852[_0xeac3('0x30')],function(_0x526755){var _0x3fb593={};_0x3fb593[_0x526755]={'$like':'%'+_0x36f83c[_0xeac3('0x2d')]['filter']+'%'};return _0x3fb593;})});}_0x1c8852=_[_0xeac3('0x39')]({},_0x1c8852,_0x36f83c[_0xeac3('0x40')]);return _0x1243ec[_0xeac3('0x46')](_0x1c8852);}})[_0xeac3('0x21')](function(_0x266afe){if(_0x266afe){_0x3f3f50=_0x266afe[_0xeac3('0x3f')];if(!_0x36f83c[_0xeac3('0x2d')][_0xeac3('0x49')](_0xeac3('0x32'))){_0x1c8852['limit']=qs[_0xeac3('0x1b')](_0x36f83c[_0xeac3('0x2d')]['limit']);_0x1c8852[_0xeac3('0x1a')]=qs[_0xeac3('0x1a')](_0x36f83c[_0xeac3('0x2d')]['offset']);}return _0x1243ec[_0xeac3('0x46')](_0x1c8852);}})[_0xeac3('0x21')](function(_0x5d2972){if(_0x5d2972){return _0x5d2972?{'count':_0x3f3f50,'rows':_0x5d2972}:null;}})[_0xeac3('0x21')](respondWithResult(_0x8796e5,null))['catch'](handleError(_0x8796e5,null));};exports[_0xeac3('0x4a')]=function(_0x407de9,_0x4b3f71,_0x47eb58){if(_0x407de9['body']['id']){delete _0x407de9[_0xeac3('0x44')]['id'];}return db[_0xeac3('0x27')][_0xeac3('0x47')]({'where':{'id':_0x407de9[_0xeac3('0x3e')]['id']}})['then'](handleEntityNotFound(_0x4b3f71,null))[_0xeac3('0x21')](function(_0x18bc03){if(_0x18bc03){_0x407de9['body'][_0xeac3('0x4b')]=_0x18bc03['id'];_0x407de9[_0xeac3('0x44')][_0xeac3('0x4c')]=integrations['getSubjects'](_0x407de9[_0xeac3('0x44')][_0xeac3('0x4d')],_0x407de9[_0xeac3('0x44')]['type']);_0x407de9[_0xeac3('0x44')][_0xeac3('0x4e')]=integrations[_0xeac3('0x4f')](_0x407de9[_0xeac3('0x44')][_0xeac3('0x4d')],_0x407de9['body'][_0xeac3('0x2a')]);return db[_0xeac3('0x48')][_0xeac3('0x43')](_0x407de9[_0xeac3('0x44')],{'include':[{'model':db[_0xeac3('0x50')],'as':'Subjects'},{'model':db['FreshsalesField'],'as':'Descriptions'}]});}return null;})[_0xeac3('0x21')](respondWithResult(_0x4b3f71,null))[_0xeac3('0x42')](handleError(_0x4b3f71,null));};exports['getFields']=function(_0x501314,_0x488ff3,_0x5c1002){var _0x398eae='';var _0x4e8a96='';return db[_0xeac3('0x27')][_0xeac3('0x47')]({'where':{'id':_0x501314[_0xeac3('0x3e')]['id']},'attributes':['id',_0xeac3('0x51'),_0xeac3('0x52'),_0xeac3('0x53')]})[_0xeac3('0x21')](handleEntityNotFound(_0x488ff3,null))['then'](function(_0x3e0852){if(_0x3e0852){_0x4e8a96=_0x3e0852[_0xeac3('0x51')];_0x398eae=_0x3e0852[_0xeac3('0x52')];var _0x1c8cfa=_0x3e0852[_0xeac3('0x52')][_0xeac3('0x54')](-0x1);if(_0x1c8cfa==='/'){_0x398eae=_0x398eae[_0xeac3('0x55')](0x0,_0x398eae[_0xeac3('0x56')](_0x1c8cfa));}return rp({'method':_0xeac3('0x57'),'uri':util['format'](_0xeac3('0x58'),_0x398eae,'/api/selector/owners'),'headers':{'Authorization':_0xeac3('0x59')+_0x3e0852[_0xeac3('0x53')]},'json':!![]});}})[_0xeac3('0x21')](function(_0x566f03){if(_0x566f03){var _0x2a970f=_0x566f03[_0xeac3('0x5a')];var _0x580584=![];var _0x445fcb=null;for(_0x445fcb=0x0;_0x445fcb<_0x2a970f['length'];_0x445fcb++){if(_0x2a970f[_0x445fcb]['email']===_0x4e8a96){_0x580584=!![];}}if(_0x580584){return!![];}else{throw new Error({'statusCode':0x194,'message':_0xeac3('0x5b')});}}})[_0xeac3('0x21')](respondWithResult(_0x488ff3,null))[_0xeac3('0x42')](function(_0x312a10){var _0x4cbefc=_0x501314[_0xeac3('0x2d')][_0xeac3('0x5c')]?0x1f4:_0x312a10[_0xeac3('0x5d')]||0x1f4;logger[_0xeac3('0x23')]('getFields,\x20%s,\x20%s,\x20%s','getFields',_0x4cbefc,JSON[_0xeac3('0x5e')](_0x312a10));delete _0x312a10['name'];if(_0x4cbefc===0x191){_0x4cbefc=0x190;}_0x488ff3['status'](_0x4cbefc)[_0xeac3('0x25')](_0x501314[_0xeac3('0x2d')][_0xeac3('0x5c')]?{'message':_0xeac3('0x5f'),'statusCode':_0x312a10[_0xeac3('0x5d')]}:_0x312a10);});};
\ No newline at end of file