Built motion from commit 10af8726.|2.6.34
[motion2.git] / server / api / intFreshsalesAccount / intFreshsalesAccount.controller.js
index 3e325d5..4297925 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xb58b=['model','query','keys','intersection','fields','attributes','hasOwnProperty','nolimit','sort','where','filters','pick','filter','VIRTUAL','merge','options','FreshsalesAccount','includeAll','include','findAll','rows','show','length','find','create','params','getConfigurations','FreshsalesConfiguration','addConfiguration','body','AccountId','Subjects','getSubjects','channel','Descriptions','getDescriptions','FreshsalesField','findOne','username','remoteUri','apiKey','slice','substring','GET','%s%s','Token\x20token=','users','email','statusCode','getFields,\x20%s,\x20%s,\x20%s','getFields','test','Wrong\x20credentials','eml-format','rimraf','zip-dir','request-promise','moment','mustache','path','sox','to-csv','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','../../components/integrations/configuration','jayson/promise','http','info','FreshsalesAccount,\x20%s,\x20%s','stringify','error','code','message','request\x20sent','result','catch','sendStatus','status','end','json','count','offset','limit','set','apply','reject','save','update','then','destroy','stack','name','send','index','map','rawAttributes','type','key'];(function(_0x4e9d3c,_0x1f4b98){var _0x2d0825=function(_0x384676){while(--_0x384676){_0x4e9d3c['push'](_0x4e9d3c['shift']());}};_0x2d0825(++_0x1f4b98);}(_0xb58b,0x1f1));var _0xbb58=function(_0x17adc9,_0x129be8){_0x17adc9=_0x17adc9-0x0;var _0x5edaff=_0xb58b[_0x17adc9];return _0x5edaff;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0xbb58('0x0'));var rimraf=require(_0xbb58('0x1'));var zipdir=require(_0xbb58('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0xbb58('0x3'));var moment=require(_0xbb58('0x4'));var BPromise=require('bluebird');var Mustache=require(_0xbb58('0x5'));var util=require('util');var path=require(_0xbb58('0x6'));var sox=require(_0xbb58('0x7'));var csv=require(_0xbb58('0x8'));var ejs=require('ejs');var fs=require('fs');var _=require(_0xbb58('0x9'));var squel=require(_0xbb58('0xa'));var crypto=require(_0xbb58('0xb'));var jsforce=require(_0xbb58('0xc'));var deskjs=require(_0xbb58('0xd'));var toCsv=require(_0xbb58('0x8'));var querystring=require(_0xbb58('0xe'));var Papa=require(_0xbb58('0xf'));var Redis=require(_0xbb58('0x10'));var authService=require(_0xbb58('0x11'));var qs=require(_0xbb58('0x12'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xbb58('0x13'));var logger=require('../../config/logger')(_0xbb58('0x14'));var utils=require(_0xbb58('0x15'));var config=require(_0xbb58('0x16'));var licenseUtil=require(_0xbb58('0x17'));var db=require('../../mysqldb')['db'];var integrations=require(_0xbb58('0x18'));var jayson=require(_0xbb58('0x19'));var client=jayson['client'][_0xbb58('0x1a')]({'port':0x232a});function respondWithRpcPromise(_0xdc68b9,_0x14106f,_0x3b9406,_0x19ceda){return new BPromise(function(_0x58245f,_0x110944){var _0x23fd15=_0x19ceda||client;return _0x23fd15['request'](_0xdc68b9,_0x3b9406)['then'](function(_0x33c20f){logger[_0xbb58('0x1b')](_0xbb58('0x1c'),_0x14106f,'request\x20sent');logger['debug']('FreshsalesAccount,\x20%s,\x20%s,\x20%s',_0x14106f,'request\x20sent',JSON[_0xbb58('0x1d')](_0x33c20f));if(_0x33c20f[_0xbb58('0x1e')]){if(_0x33c20f['error'][_0xbb58('0x1f')]===0x1f4){logger['error'](_0xbb58('0x1c'),_0x14106f,_0x33c20f[_0xbb58('0x1e')][_0xbb58('0x20')]);return _0x110944(_0x33c20f[_0xbb58('0x1e')][_0xbb58('0x20')]);}logger[_0xbb58('0x1e')](_0xbb58('0x1c'),_0x14106f,_0x33c20f['error'][_0xbb58('0x20')]);return _0x58245f(_0x33c20f[_0xbb58('0x1e')][_0xbb58('0x20')]);}else{logger[_0xbb58('0x1b')](_0xbb58('0x1c'),_0x14106f,_0xbb58('0x21'));_0x58245f(_0x33c20f[_0xbb58('0x22')][_0xbb58('0x20')]);}})[_0xbb58('0x23')](function(_0x4f74a0){logger[_0xbb58('0x1e')]('FreshsalesAccount,\x20%s,\x20%s',_0x14106f,_0x4f74a0);_0x110944(_0x4f74a0);});});}function respondWithStatusCode(_0x21964d,_0x287822){_0x287822=_0x287822||0xcc;return function(_0x152f22){if(_0x152f22){return _0x21964d[_0xbb58('0x24')](_0x287822);}return _0x21964d[_0xbb58('0x25')](_0x287822)[_0xbb58('0x26')]();};}function respondWithResult(_0x2d556a,_0x15e4c5){_0x15e4c5=_0x15e4c5||0xc8;return function(_0x4e0303){if(_0x4e0303){return _0x2d556a[_0xbb58('0x25')](_0x15e4c5)[_0xbb58('0x27')](_0x4e0303);}};}function respondWithFilteredResult(_0x1be0ae,_0x129094){return function(_0x8e9ed9){if(_0x8e9ed9){var _0x521d0c=_0x8e9ed9[_0xbb58('0x28')],_0x3608dc=_0x129094[_0xbb58('0x29')],_0x2ce7c3=_0x129094[_0xbb58('0x29')]+_0x129094[_0xbb58('0x2a')],_0x16df29;if(_0x2ce7c3>=_0x521d0c){_0x2ce7c3=_0x521d0c;_0x16df29=0xc8;}else{_0x16df29=0xce;}_0x1be0ae[_0xbb58('0x25')](_0x16df29);return _0x1be0ae[_0xbb58('0x2b')]('Content-Range',_0x3608dc+'-'+_0x2ce7c3+'/'+_0x521d0c)[_0xbb58('0x27')](_0x8e9ed9);}return null;};}function patchUpdates(_0xe46bc1){return function(_0x12b3eb){try{jsonpatch[_0xbb58('0x2c')](_0x12b3eb,_0xe46bc1,!![]);}catch(_0x3304b9){return BPromise[_0xbb58('0x2d')](_0x3304b9);}return _0x12b3eb[_0xbb58('0x2e')]();};}function saveUpdates(_0x643e0e,_0x3f8db3){return function(_0x5ac926){if(_0x5ac926){return _0x5ac926[_0xbb58('0x2f')](_0x643e0e)[_0xbb58('0x30')](function(_0x3edc34){return _0x3edc34;});}return null;};}function removeEntity(_0x3a1e46,_0xdbbe7b){return function(_0x33f931){if(_0x33f931){return _0x33f931[_0xbb58('0x31')]()[_0xbb58('0x30')](function(){_0x3a1e46[_0xbb58('0x25')](0xcc)[_0xbb58('0x26')]();});}};}function handleEntityNotFound(_0x389187,_0x34583e){return function(_0x2f5967){if(!_0x2f5967){_0x389187['sendStatus'](0x194);}return _0x2f5967;};}function handleError(_0x51b69f,_0x5a4e76){_0x5a4e76=_0x5a4e76||0x1f4;return function(_0x1def9f){logger[_0xbb58('0x1e')](_0x1def9f[_0xbb58('0x32')]);if(_0x1def9f[_0xbb58('0x33')]){delete _0x1def9f[_0xbb58('0x33')];}_0x51b69f[_0xbb58('0x25')](_0x5a4e76)[_0xbb58('0x34')](_0x1def9f);};}exports[_0xbb58('0x35')]=function(_0x5db313,_0x2fbf90){var _0x230859={},_0x4c2a5b={},_0x33ec68={'count':0x0,'rows':[]};var _0x4da3ed=_[_0xbb58('0x36')](db['FreshsalesAccount'][_0xbb58('0x37')],function(_0x36c7b4){return{'name':_0x36c7b4['fieldName'],'type':_0x36c7b4[_0xbb58('0x38')][_0xbb58('0x39')]};});_0x4c2a5b[_0xbb58('0x3a')]=_[_0xbb58('0x36')](_0x4da3ed,_0xbb58('0x33'));_0x4c2a5b[_0xbb58('0x3b')]=_[_0xbb58('0x3c')](_0x5db313[_0xbb58('0x3b')]);_0x4c2a5b['filters']=_[_0xbb58('0x3d')](_0x4c2a5b[_0xbb58('0x3a')],_0x4c2a5b[_0xbb58('0x3b')]);_0x230859['attributes']=_['intersection'](_0x4c2a5b[_0xbb58('0x3a')],qs['fields'](_0x5db313[_0xbb58('0x3b')][_0xbb58('0x3e')]));_0x230859[_0xbb58('0x3f')]=_0x230859['attributes']['length']?_0x230859[_0xbb58('0x3f')]:_0x4c2a5b[_0xbb58('0x3a')];if(!_0x5db313[_0xbb58('0x3b')][_0xbb58('0x40')](_0xbb58('0x41'))){_0x230859[_0xbb58('0x2a')]=qs['limit'](_0x5db313[_0xbb58('0x3b')][_0xbb58('0x2a')]);_0x230859[_0xbb58('0x29')]=qs[_0xbb58('0x29')](_0x5db313[_0xbb58('0x3b')][_0xbb58('0x29')]);}_0x230859['order']=qs[_0xbb58('0x42')](_0x5db313['query'][_0xbb58('0x42')]);_0x230859[_0xbb58('0x43')]=qs[_0xbb58('0x44')](_[_0xbb58('0x45')](_0x5db313['query'],_0x4c2a5b[_0xbb58('0x44')]),_0x4da3ed);if(_0x5db313[_0xbb58('0x3b')][_0xbb58('0x46')]){_0x230859[_0xbb58('0x43')]=_['merge'](_0x230859[_0xbb58('0x43')],{'$or':_['map'](_0x4da3ed,function(_0x2ffd8b){if(_0x2ffd8b[_0xbb58('0x38')]!==_0xbb58('0x47')){var _0x34c460={};_0x34c460[_0x2ffd8b[_0xbb58('0x33')]]={'$like':'%'+_0x5db313[_0xbb58('0x3b')][_0xbb58('0x46')]+'%'};return _0x34c460;}})});}_0x230859=_[_0xbb58('0x48')]({},_0x230859,_0x5db313[_0xbb58('0x49')]);var _0x444906={'where':_0x230859[_0xbb58('0x43')]};return db[_0xbb58('0x4a')][_0xbb58('0x28')](_0x444906)['then'](function(_0xc690d){_0x33ec68['count']=_0xc690d;if(_0x5db313['query'][_0xbb58('0x4b')]){_0x230859[_0xbb58('0x4c')]=[{'all':!![]}];}return db[_0xbb58('0x4a')][_0xbb58('0x4d')](_0x230859);})[_0xbb58('0x30')](function(_0x2ab2b6){_0x33ec68[_0xbb58('0x4e')]=_0x2ab2b6;return _0x33ec68;})[_0xbb58('0x30')](respondWithFilteredResult(_0x2fbf90,_0x230859))[_0xbb58('0x23')](handleError(_0x2fbf90,null));};exports[_0xbb58('0x4f')]=function(_0x440fb3,_0x59a8cf){var _0x2ec9be={'raw':![],'where':{'id':_0x440fb3['params']['id']}},_0x23871d={};_0x23871d[_0xbb58('0x3a')]=_[_0xbb58('0x3c')](db[_0xbb58('0x4a')][_0xbb58('0x37')]);_0x23871d['query']=_[_0xbb58('0x3c')](_0x440fb3['query']);_0x23871d[_0xbb58('0x44')]=_[_0xbb58('0x3d')](_0x23871d[_0xbb58('0x3a')],_0x23871d['query']);_0x2ec9be[_0xbb58('0x3f')]=_[_0xbb58('0x3d')](_0x23871d['model'],qs[_0xbb58('0x3e')](_0x440fb3['query'][_0xbb58('0x3e')]));_0x2ec9be[_0xbb58('0x3f')]=_0x2ec9be[_0xbb58('0x3f')][_0xbb58('0x50')]?_0x2ec9be[_0xbb58('0x3f')]:_0x23871d[_0xbb58('0x3a')];if(_0x440fb3[_0xbb58('0x3b')]['includeAll']){_0x2ec9be[_0xbb58('0x4c')]=[{'all':!![]}];}_0x2ec9be=_[_0xbb58('0x48')]({},_0x2ec9be,_0x440fb3['options']);return db[_0xbb58('0x4a')][_0xbb58('0x51')](_0x2ec9be)['then'](handleEntityNotFound(_0x59a8cf,null))[_0xbb58('0x30')](respondWithResult(_0x59a8cf,null))[_0xbb58('0x23')](handleError(_0x59a8cf,null));};exports[_0xbb58('0x52')]=function(_0x4e21e0,_0x376569){return db[_0xbb58('0x4a')][_0xbb58('0x52')](_0x4e21e0['body'],{})[_0xbb58('0x30')](respondWithResult(_0x376569,0xc9))['catch'](handleError(_0x376569,null));};exports[_0xbb58('0x2f')]=function(_0x278c43,_0x2395b1){if(_0x278c43['body']['id']){delete _0x278c43['body']['id'];}return db[_0xbb58('0x4a')][_0xbb58('0x51')]({'where':{'id':_0x278c43[_0xbb58('0x53')]['id']}})[_0xbb58('0x30')](handleEntityNotFound(_0x2395b1,null))[_0xbb58('0x30')](saveUpdates(_0x278c43['body'],null))[_0xbb58('0x30')](respondWithResult(_0x2395b1,null))[_0xbb58('0x23')](handleError(_0x2395b1,null));};exports[_0xbb58('0x31')]=function(_0x47cd33,_0x5ad867){return db[_0xbb58('0x4a')][_0xbb58('0x51')]({'where':{'id':_0x47cd33[_0xbb58('0x53')]['id']}})[_0xbb58('0x30')](handleEntityNotFound(_0x5ad867,null))['then'](removeEntity(_0x5ad867,null))[_0xbb58('0x23')](handleError(_0x5ad867,null));};exports[_0xbb58('0x54')]=function(_0x1553d6,_0x20dcaa,_0x445517){var _0x38b1ba={};var _0x85278c={};var _0x58ced2;var _0x55d5be;return db[_0xbb58('0x4a')]['findOne']({'where':{'id':_0x1553d6[_0xbb58('0x53')]['id']}})[_0xbb58('0x30')](handleEntityNotFound(_0x20dcaa,null))[_0xbb58('0x30')](function(_0x2a6963){if(_0x2a6963){_0x58ced2=_0x2a6963;_0x85278c[_0xbb58('0x3a')]=_[_0xbb58('0x3c')](db[_0xbb58('0x55')][_0xbb58('0x37')]);_0x85278c[_0xbb58('0x3b')]=_[_0xbb58('0x3c')](_0x1553d6[_0xbb58('0x3b')]);_0x85278c['filters']=_[_0xbb58('0x3d')](_0x85278c[_0xbb58('0x3a')],_0x85278c[_0xbb58('0x3b')]);_0x38b1ba['attributes']=_[_0xbb58('0x3d')](_0x85278c['model'],qs[_0xbb58('0x3e')](_0x1553d6[_0xbb58('0x3b')]['fields']));_0x38b1ba[_0xbb58('0x3f')]=_0x38b1ba[_0xbb58('0x3f')][_0xbb58('0x50')]?_0x38b1ba[_0xbb58('0x3f')]:_0x85278c[_0xbb58('0x3a')];_0x38b1ba['order']=qs['sort'](_0x1553d6[_0xbb58('0x3b')][_0xbb58('0x42')]);_0x38b1ba[_0xbb58('0x43')]=qs['filters'](_[_0xbb58('0x45')](_0x1553d6[_0xbb58('0x3b')],_0x85278c['filters']));if(_0x1553d6[_0xbb58('0x3b')][_0xbb58('0x46')]){_0x38b1ba['where']=_[_0xbb58('0x48')](_0x38b1ba[_0xbb58('0x43')],{'$or':_[_0xbb58('0x36')](_0x38b1ba[_0xbb58('0x3f')],function(_0x3cface){var _0x5ceae0={};_0x5ceae0[_0x3cface]={'$like':'%'+_0x1553d6[_0xbb58('0x3b')][_0xbb58('0x46')]+'%'};return _0x5ceae0;})});}_0x38b1ba=_[_0xbb58('0x48')]({},_0x38b1ba,_0x1553d6[_0xbb58('0x49')]);return _0x58ced2[_0xbb58('0x54')](_0x38b1ba);}})['then'](function(_0x509d57){if(_0x509d57){_0x55d5be=_0x509d57[_0xbb58('0x50')];if(!_0x1553d6['query'][_0xbb58('0x40')](_0xbb58('0x41'))){_0x38b1ba[_0xbb58('0x2a')]=qs[_0xbb58('0x2a')](_0x1553d6[_0xbb58('0x3b')][_0xbb58('0x2a')]);_0x38b1ba[_0xbb58('0x29')]=qs[_0xbb58('0x29')](_0x1553d6[_0xbb58('0x3b')][_0xbb58('0x29')]);}return _0x58ced2['getConfigurations'](_0x38b1ba);}})[_0xbb58('0x30')](function(_0x30d4c8){if(_0x30d4c8){return _0x30d4c8?{'count':_0x55d5be,'rows':_0x30d4c8}:null;}})[_0xbb58('0x30')](respondWithResult(_0x20dcaa,null))['catch'](handleError(_0x20dcaa,null));};exports[_0xbb58('0x56')]=function(_0x4bdc30,_0x5e9319,_0x1e315e){if(_0x4bdc30[_0xbb58('0x57')]['id']){delete _0x4bdc30[_0xbb58('0x57')]['id'];}return db[_0xbb58('0x4a')]['findOne']({'where':{'id':_0x4bdc30['params']['id']}})[_0xbb58('0x30')](handleEntityNotFound(_0x5e9319,null))[_0xbb58('0x30')](function(_0x4d2091){if(_0x4d2091){_0x4bdc30[_0xbb58('0x57')][_0xbb58('0x58')]=_0x4d2091['id'];_0x4bdc30[_0xbb58('0x57')][_0xbb58('0x59')]=integrations[_0xbb58('0x5a')](_0x4bdc30['body'][_0xbb58('0x5b')],_0x4bdc30['body']['type']);_0x4bdc30[_0xbb58('0x57')][_0xbb58('0x5c')]=integrations[_0xbb58('0x5d')](_0x4bdc30['body'][_0xbb58('0x5b')],_0x4bdc30[_0xbb58('0x57')][_0xbb58('0x38')]);return db[_0xbb58('0x55')]['create'](_0x4bdc30[_0xbb58('0x57')],{'include':[{'model':db['FreshsalesField'],'as':'Subjects'},{'model':db[_0xbb58('0x5e')],'as':_0xbb58('0x5c')}]});}return null;})[_0xbb58('0x30')](respondWithResult(_0x5e9319,null))['catch'](handleError(_0x5e9319,null));};exports['getFields']=function(_0x31def4,_0xb299d7,_0x361d0e){var _0x2627a8='';var _0x171269='';return db[_0xbb58('0x4a')][_0xbb58('0x5f')]({'where':{'id':_0x31def4[_0xbb58('0x53')]['id']},'attributes':['id',_0xbb58('0x60'),_0xbb58('0x61'),_0xbb58('0x62')]})['then'](handleEntityNotFound(_0xb299d7,null))['then'](function(_0x36e2eb){if(_0x36e2eb){_0x171269=_0x36e2eb[_0xbb58('0x60')];_0x2627a8=_0x36e2eb[_0xbb58('0x61')];var _0x54cd7d=_0x36e2eb[_0xbb58('0x61')][_0xbb58('0x63')](-0x1);if(_0x54cd7d==='/'){_0x2627a8=_0x2627a8[_0xbb58('0x64')](0x0,_0x2627a8['lastIndexOf'](_0x54cd7d));}return rp({'method':_0xbb58('0x65'),'uri':util['format'](_0xbb58('0x66'),_0x2627a8,'/api/selector/owners'),'headers':{'Authorization':_0xbb58('0x67')+_0x36e2eb[_0xbb58('0x62')]},'json':!![]});}})[_0xbb58('0x30')](function(_0x1f1b74){if(_0x1f1b74){var _0x26c15a=_0x1f1b74[_0xbb58('0x68')];var _0x4f5cbb=![];var _0x5dc707=null;for(_0x5dc707=0x0;_0x5dc707<_0x26c15a[_0xbb58('0x50')];_0x5dc707++){if(_0x26c15a[_0x5dc707][_0xbb58('0x69')]===_0x171269){_0x4f5cbb=!![];}}if(_0x4f5cbb){return!![];}else{throw new Error({'statusCode':0x194,'message':'Requested\x20Resource\x20not\x20Found'});}}})[_0xbb58('0x30')](respondWithResult(_0xb299d7,null))[_0xbb58('0x23')](function(_0x43eb15){var _0x5604d1=_0x31def4[_0xbb58('0x3b')]['test']?0x1f4:_0x43eb15[_0xbb58('0x6a')]||0x1f4;logger[_0xbb58('0x1e')](_0xbb58('0x6b'),_0xbb58('0x6c'),_0x5604d1,JSON[_0xbb58('0x1d')](_0x43eb15));delete _0x43eb15[_0xbb58('0x33')];if(_0x5604d1===0x191){_0x5604d1=0x190;}_0xb299d7[_0xbb58('0x25')](_0x5604d1)['send'](_0x31def4[_0xbb58('0x3b')][_0xbb58('0x6d')]?{'message':_0xbb58('0x6e'),'statusCode':_0x43eb15['statusCode']}:_0x43eb15);});};
\ No newline at end of file
+var _0x4c6f=['options','findAll','rows','catch','show','params','includeAll','find','create','body','findOne','FreshsalesConfiguration','order','getConfigurations','addConfiguration','AccountId','Subjects','getSubjects','channel','Descriptions','FreshsalesField','username','apiKey','remoteUri','slice','substring','lastIndexOf','format','/api/selector/owners','Token\x20token=','users','email','test','statusCode','getFields,\x20%s,\x20%s,\x20%s','getFields','stringify','rimraf','zip-dir','request-promise','moment','bluebird','mustache','util','path','to-csv','ejs','fs-extra','lodash','squel','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','../../components/integrations/configuration','status','json','offset','undefined','limit','count','apply','reject','save','update','destroy','then','sendStatus','error','stack','name','send','index','map','FreshsalesAccount','rawAttributes','type','key','model','keys','query','filters','attributes','intersection','fields','length','hasOwnProperty','nolimit','sort','where','pick','filter','merge','VIRTUAL'];(function(_0x47df54,_0x1aeb61){var _0x261b87=function(_0x54bc77){while(--_0x54bc77){_0x47df54['push'](_0x47df54['shift']());}};_0x261b87(++_0x1aeb61);}(_0x4c6f,0x157));var _0xf4c6=function(_0x5e1e25,_0xdc1421){_0x5e1e25=_0x5e1e25-0x0;var _0x548e5f=_0x4c6f[_0x5e1e25];return _0x548e5f;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xf4c6('0x0'));var zipdir=require(_0xf4c6('0x1'));var jsonpatch=require('fast-json-patch');var rp=require(_0xf4c6('0x2'));var moment=require(_0xf4c6('0x3'));var BPromise=require(_0xf4c6('0x4'));var Mustache=require(_0xf4c6('0x5'));var util=require(_0xf4c6('0x6'));var path=require(_0xf4c6('0x7'));var sox=require('sox');var csv=require(_0xf4c6('0x8'));var ejs=require(_0xf4c6('0x9'));var fs=require('fs');var fs_extra=require(_0xf4c6('0xa'));var _=require(_0xf4c6('0xb'));var squel=require(_0xf4c6('0xc'));var crypto=require('crypto');var jsforce=require(_0xf4c6('0xd'));var deskjs=require(_0xf4c6('0xe'));var toCsv=require(_0xf4c6('0x8'));var querystring=require('querystring');var Papa=require(_0xf4c6('0xf'));var Redis=require(_0xf4c6('0x10'));var authService=require(_0xf4c6('0x11'));var qs=require(_0xf4c6('0x12'));var as=require(_0xf4c6('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0xf4c6('0x14'));var utils=require(_0xf4c6('0x15'));var config=require(_0xf4c6('0x16'));var licenseUtil=require(_0xf4c6('0x17'));var db=require(_0xf4c6('0x18'))['db'];var integrations=require(_0xf4c6('0x19'));function respondWithStatusCode(_0x2b3fc5,_0x391c8f){_0x391c8f=_0x391c8f||0xcc;return function(_0x13fd11){if(_0x13fd11){return _0x2b3fc5['sendStatus'](_0x391c8f);}return _0x2b3fc5[_0xf4c6('0x1a')](_0x391c8f)['end']();};}function respondWithResult(_0xe0f86b,_0x5edec9){_0x5edec9=_0x5edec9||0xc8;return function(_0x5cde4a){if(_0x5cde4a){return _0xe0f86b[_0xf4c6('0x1a')](_0x5edec9)[_0xf4c6('0x1b')](_0x5cde4a);}};}function respondWithFilteredResult(_0x466a66,_0x30fd34){return function(_0x290b98){if(_0x290b98){var _0x5582fa=typeof _0x30fd34[_0xf4c6('0x1c')]===_0xf4c6('0x1d')&&typeof _0x30fd34[_0xf4c6('0x1e')]==='undefined';var _0x180003=_0x290b98[_0xf4c6('0x1f')];var _0x271c45=_0x5582fa?0x0:_0x30fd34['offset'];var _0x3740b3=_0x5582fa?_0x290b98[_0xf4c6('0x1f')]:_0x30fd34[_0xf4c6('0x1c')]+_0x30fd34[_0xf4c6('0x1e')];var _0x1b9279;if(_0x3740b3>=_0x180003){_0x3740b3=_0x180003;_0x1b9279=0xc8;}else{_0x1b9279=0xce;}_0x466a66[_0xf4c6('0x1a')](_0x1b9279);return _0x466a66['set']('Content-Range',_0x271c45+'-'+_0x3740b3+'/'+_0x180003)['json'](_0x290b98);}return null;};}function patchUpdates(_0x24e5f4){return function(_0x160394){try{jsonpatch[_0xf4c6('0x20')](_0x160394,_0x24e5f4,!![]);}catch(_0x4dc258){return BPromise[_0xf4c6('0x21')](_0x4dc258);}return _0x160394[_0xf4c6('0x22')]();};}function saveUpdates(_0x5e79ab,_0x6b20b){return function(_0xd5691a){if(_0xd5691a){return _0xd5691a[_0xf4c6('0x23')](_0x5e79ab)['then'](function(_0x5c7fbd){return _0x5c7fbd;});}return null;};}function removeEntity(_0x1453c,_0x126c33){return function(_0x3ac0e9){if(_0x3ac0e9){return _0x3ac0e9[_0xf4c6('0x24')]()[_0xf4c6('0x25')](function(){_0x1453c[_0xf4c6('0x1a')](0xcc)['end']();});}};}function handleEntityNotFound(_0x21d260,_0x45f678){return function(_0x50f16f){if(!_0x50f16f){_0x21d260[_0xf4c6('0x26')](0x194);}return _0x50f16f;};}function handleError(_0x31874d,_0x30f0db){_0x30f0db=_0x30f0db||0x1f4;return function(_0xde436a){logger[_0xf4c6('0x27')](_0xde436a[_0xf4c6('0x28')]);if(_0xde436a[_0xf4c6('0x29')]){delete _0xde436a[_0xf4c6('0x29')];}_0x31874d[_0xf4c6('0x1a')](_0x30f0db)[_0xf4c6('0x2a')](_0xde436a);};}exports[_0xf4c6('0x2b')]=function(_0x18ac4c,_0xdde7d8){var _0x1d03e2={},_0x1a6235={},_0x2dc0b1={'count':0x0,'rows':[]};var _0x4afc82=_[_0xf4c6('0x2c')](db[_0xf4c6('0x2d')][_0xf4c6('0x2e')],function(_0x339762){return{'name':_0x339762['fieldName'],'type':_0x339762[_0xf4c6('0x2f')][_0xf4c6('0x30')]};});_0x1a6235[_0xf4c6('0x31')]=_[_0xf4c6('0x2c')](_0x4afc82,_0xf4c6('0x29'));_0x1a6235['query']=_[_0xf4c6('0x32')](_0x18ac4c[_0xf4c6('0x33')]);_0x1a6235[_0xf4c6('0x34')]=_['intersection'](_0x1a6235[_0xf4c6('0x31')],_0x1a6235[_0xf4c6('0x33')]);_0x1d03e2[_0xf4c6('0x35')]=_[_0xf4c6('0x36')](_0x1a6235[_0xf4c6('0x31')],qs['fields'](_0x18ac4c['query'][_0xf4c6('0x37')]));_0x1d03e2[_0xf4c6('0x35')]=_0x1d03e2[_0xf4c6('0x35')][_0xf4c6('0x38')]?_0x1d03e2[_0xf4c6('0x35')]:_0x1a6235['model'];if(!_0x18ac4c[_0xf4c6('0x33')][_0xf4c6('0x39')](_0xf4c6('0x3a'))){_0x1d03e2['limit']=qs['limit'](_0x18ac4c[_0xf4c6('0x33')][_0xf4c6('0x1e')]);_0x1d03e2[_0xf4c6('0x1c')]=qs[_0xf4c6('0x1c')](_0x18ac4c[_0xf4c6('0x33')]['offset']);}_0x1d03e2['order']=qs[_0xf4c6('0x3b')](_0x18ac4c[_0xf4c6('0x33')]['sort']);_0x1d03e2[_0xf4c6('0x3c')]=qs[_0xf4c6('0x34')](_[_0xf4c6('0x3d')](_0x18ac4c['query'],_0x1a6235[_0xf4c6('0x34')]),_0x4afc82);if(_0x18ac4c['query'][_0xf4c6('0x3e')]){_0x1d03e2[_0xf4c6('0x3c')]=_[_0xf4c6('0x3f')](_0x1d03e2[_0xf4c6('0x3c')],{'$or':_[_0xf4c6('0x2c')](_0x4afc82,function(_0x14f3e6){if(_0x14f3e6[_0xf4c6('0x2f')]!==_0xf4c6('0x40')){var _0x216017={};_0x216017[_0x14f3e6[_0xf4c6('0x29')]]={'$like':'%'+_0x18ac4c[_0xf4c6('0x33')][_0xf4c6('0x3e')]+'%'};return _0x216017;}})});}_0x1d03e2=_[_0xf4c6('0x3f')]({},_0x1d03e2,_0x18ac4c[_0xf4c6('0x41')]);var _0x301417={'where':_0x1d03e2[_0xf4c6('0x3c')]};return db[_0xf4c6('0x2d')][_0xf4c6('0x1f')](_0x301417)[_0xf4c6('0x25')](function(_0xe6773b){_0x2dc0b1[_0xf4c6('0x1f')]=_0xe6773b;if(_0x18ac4c[_0xf4c6('0x33')]['includeAll']){_0x1d03e2['include']=[{'all':!![]}];}return db[_0xf4c6('0x2d')][_0xf4c6('0x42')](_0x1d03e2);})['then'](function(_0x3f18b0){_0x2dc0b1[_0xf4c6('0x43')]=_0x3f18b0;return _0x2dc0b1;})['then'](respondWithFilteredResult(_0xdde7d8,_0x1d03e2))[_0xf4c6('0x44')](handleError(_0xdde7d8,null));};exports[_0xf4c6('0x45')]=function(_0x355bcc,_0x38329a){var _0x33b292={'raw':![],'where':{'id':_0x355bcc[_0xf4c6('0x46')]['id']}},_0x2ef48f={};_0x2ef48f[_0xf4c6('0x31')]=_[_0xf4c6('0x32')](db[_0xf4c6('0x2d')][_0xf4c6('0x2e')]);_0x2ef48f['query']=_['keys'](_0x355bcc['query']);_0x2ef48f[_0xf4c6('0x34')]=_['intersection'](_0x2ef48f[_0xf4c6('0x31')],_0x2ef48f[_0xf4c6('0x33')]);_0x33b292[_0xf4c6('0x35')]=_[_0xf4c6('0x36')](_0x2ef48f[_0xf4c6('0x31')],qs[_0xf4c6('0x37')](_0x355bcc[_0xf4c6('0x33')]['fields']));_0x33b292[_0xf4c6('0x35')]=_0x33b292[_0xf4c6('0x35')][_0xf4c6('0x38')]?_0x33b292[_0xf4c6('0x35')]:_0x2ef48f[_0xf4c6('0x31')];if(_0x355bcc[_0xf4c6('0x33')][_0xf4c6('0x47')]){_0x33b292['include']=[{'all':!![]}];}_0x33b292=_[_0xf4c6('0x3f')]({},_0x33b292,_0x355bcc[_0xf4c6('0x41')]);return db[_0xf4c6('0x2d')][_0xf4c6('0x48')](_0x33b292)[_0xf4c6('0x25')](handleEntityNotFound(_0x38329a,null))[_0xf4c6('0x25')](respondWithResult(_0x38329a,null))[_0xf4c6('0x44')](handleError(_0x38329a,null));};exports['create']=function(_0x34a7c0,_0x59b09){return db[_0xf4c6('0x2d')][_0xf4c6('0x49')](_0x34a7c0['body'],{})['then'](respondWithResult(_0x59b09,0xc9))[_0xf4c6('0x44')](handleError(_0x59b09,null));};exports[_0xf4c6('0x23')]=function(_0x128e34,_0x10ecd6){if(_0x128e34[_0xf4c6('0x4a')]['id']){delete _0x128e34['body']['id'];}return db['FreshsalesAccount'][_0xf4c6('0x48')]({'where':{'id':_0x128e34[_0xf4c6('0x46')]['id']}})[_0xf4c6('0x25')](handleEntityNotFound(_0x10ecd6,null))['then'](saveUpdates(_0x128e34[_0xf4c6('0x4a')],null))[_0xf4c6('0x25')](respondWithResult(_0x10ecd6,null))[_0xf4c6('0x44')](handleError(_0x10ecd6,null));};exports['destroy']=function(_0x17469f,_0x5b607c){return db[_0xf4c6('0x2d')][_0xf4c6('0x48')]({'where':{'id':_0x17469f['params']['id']}})[_0xf4c6('0x25')](handleEntityNotFound(_0x5b607c,null))['then'](removeEntity(_0x5b607c,null))[_0xf4c6('0x44')](handleError(_0x5b607c,null));};exports['getConfigurations']=function(_0xc1651d,_0x26b971,_0x362d05){var _0x1c37c0={};var _0x264085={};var _0x313e94;var _0x154f7c;return db['FreshsalesAccount'][_0xf4c6('0x4b')]({'where':{'id':_0xc1651d[_0xf4c6('0x46')]['id']}})[_0xf4c6('0x25')](handleEntityNotFound(_0x26b971,null))[_0xf4c6('0x25')](function(_0x1e7fdb){if(_0x1e7fdb){_0x313e94=_0x1e7fdb;_0x264085['model']=_['keys'](db[_0xf4c6('0x4c')][_0xf4c6('0x2e')]);_0x264085[_0xf4c6('0x33')]=_['keys'](_0xc1651d[_0xf4c6('0x33')]);_0x264085[_0xf4c6('0x34')]=_['intersection'](_0x264085[_0xf4c6('0x31')],_0x264085[_0xf4c6('0x33')]);_0x1c37c0['attributes']=_[_0xf4c6('0x36')](_0x264085[_0xf4c6('0x31')],qs[_0xf4c6('0x37')](_0xc1651d['query']['fields']));_0x1c37c0['attributes']=_0x1c37c0[_0xf4c6('0x35')][_0xf4c6('0x38')]?_0x1c37c0[_0xf4c6('0x35')]:_0x264085[_0xf4c6('0x31')];_0x1c37c0[_0xf4c6('0x4d')]=qs[_0xf4c6('0x3b')](_0xc1651d[_0xf4c6('0x33')][_0xf4c6('0x3b')]);_0x1c37c0[_0xf4c6('0x3c')]=qs[_0xf4c6('0x34')](_[_0xf4c6('0x3d')](_0xc1651d[_0xf4c6('0x33')],_0x264085['filters']));if(_0xc1651d[_0xf4c6('0x33')][_0xf4c6('0x3e')]){_0x1c37c0[_0xf4c6('0x3c')]=_[_0xf4c6('0x3f')](_0x1c37c0[_0xf4c6('0x3c')],{'$or':_[_0xf4c6('0x2c')](_0x1c37c0[_0xf4c6('0x35')],function(_0x804bfa){var _0x119235={};_0x119235[_0x804bfa]={'$like':'%'+_0xc1651d['query'][_0xf4c6('0x3e')]+'%'};return _0x119235;})});}_0x1c37c0=_[_0xf4c6('0x3f')]({},_0x1c37c0,_0xc1651d[_0xf4c6('0x41')]);return _0x313e94['getConfigurations'](_0x1c37c0);}})[_0xf4c6('0x25')](function(_0x233417){if(_0x233417){_0x154f7c=_0x233417['length'];if(!_0xc1651d[_0xf4c6('0x33')][_0xf4c6('0x39')](_0xf4c6('0x3a'))){_0x1c37c0[_0xf4c6('0x1e')]=qs['limit'](_0xc1651d['query'][_0xf4c6('0x1e')]);_0x1c37c0['offset']=qs[_0xf4c6('0x1c')](_0xc1651d['query'][_0xf4c6('0x1c')]);}return _0x313e94[_0xf4c6('0x4e')](_0x1c37c0);}})['then'](function(_0x5ca79a){if(_0x5ca79a){return _0x5ca79a?{'count':_0x154f7c,'rows':_0x5ca79a}:null;}})['then'](respondWithResult(_0x26b971,null))[_0xf4c6('0x44')](handleError(_0x26b971,null));};exports[_0xf4c6('0x4f')]=function(_0x47a5b9,_0x51609f,_0x473aad){if(_0x47a5b9[_0xf4c6('0x4a')]['id']){delete _0x47a5b9[_0xf4c6('0x4a')]['id'];}return db[_0xf4c6('0x2d')][_0xf4c6('0x4b')]({'where':{'id':_0x47a5b9[_0xf4c6('0x46')]['id']}})['then'](handleEntityNotFound(_0x51609f,null))[_0xf4c6('0x25')](function(_0x452bdf){if(_0x452bdf){_0x47a5b9[_0xf4c6('0x4a')][_0xf4c6('0x50')]=_0x452bdf['id'];_0x47a5b9[_0xf4c6('0x4a')][_0xf4c6('0x51')]=integrations[_0xf4c6('0x52')](_0x47a5b9[_0xf4c6('0x4a')][_0xf4c6('0x53')],_0x47a5b9['body'][_0xf4c6('0x2f')]);_0x47a5b9[_0xf4c6('0x4a')][_0xf4c6('0x54')]=integrations['getDescriptions'](_0x47a5b9[_0xf4c6('0x4a')]['channel'],_0x47a5b9['body'][_0xf4c6('0x2f')]);return db[_0xf4c6('0x4c')][_0xf4c6('0x49')](_0x47a5b9['body'],{'include':[{'model':db['FreshsalesField'],'as':_0xf4c6('0x51')},{'model':db[_0xf4c6('0x55')],'as':_0xf4c6('0x54')}]});}return null;})[_0xf4c6('0x25')](respondWithResult(_0x51609f,null))['catch'](handleError(_0x51609f,null));};exports['getFields']=function(_0x79a3b2,_0x3b7599,_0x4a476b){var _0xa5df3c='';var _0x2da35a='';return db[_0xf4c6('0x2d')][_0xf4c6('0x4b')]({'where':{'id':_0x79a3b2[_0xf4c6('0x46')]['id']},'attributes':['id',_0xf4c6('0x56'),'remoteUri',_0xf4c6('0x57')]})[_0xf4c6('0x25')](handleEntityNotFound(_0x3b7599,null))[_0xf4c6('0x25')](function(_0x3694b3){if(_0x3694b3){_0x2da35a=_0x3694b3['username'];_0xa5df3c=_0x3694b3[_0xf4c6('0x58')];var _0x1e9e92=_0x3694b3[_0xf4c6('0x58')][_0xf4c6('0x59')](-0x1);if(_0x1e9e92==='/'){_0xa5df3c=_0xa5df3c[_0xf4c6('0x5a')](0x0,_0xa5df3c[_0xf4c6('0x5b')](_0x1e9e92));}return rp({'method':'GET','uri':util[_0xf4c6('0x5c')]('%s%s',_0xa5df3c,_0xf4c6('0x5d')),'headers':{'Authorization':_0xf4c6('0x5e')+_0x3694b3[_0xf4c6('0x57')]},'json':!![]});}})[_0xf4c6('0x25')](function(_0x291894){if(_0x291894){var _0x5bbfb7=_0x291894[_0xf4c6('0x5f')];var _0x463ae1=![];var _0x18f8ac=null;for(_0x18f8ac=0x0;_0x18f8ac<_0x5bbfb7[_0xf4c6('0x38')];_0x18f8ac++){if(_0x5bbfb7[_0x18f8ac][_0xf4c6('0x60')]===_0x2da35a){_0x463ae1=!![];}}if(_0x463ae1){return!![];}else{throw new Error({'statusCode':0x194,'message':'Requested\x20Resource\x20not\x20Found'});}}})['then'](respondWithResult(_0x3b7599,null))[_0xf4c6('0x44')](function(_0x20753f){var _0x38d4ca=_0x79a3b2[_0xf4c6('0x33')][_0xf4c6('0x61')]?0x1f4:_0x20753f[_0xf4c6('0x62')]||0x1f4;logger['error'](_0xf4c6('0x63'),_0xf4c6('0x64'),_0x38d4ca,JSON[_0xf4c6('0x65')](_0x20753f));delete _0x20753f[_0xf4c6('0x29')];if(_0x38d4ca===0x191){_0x38d4ca=0x190;}_0x3b7599[_0xf4c6('0x1a')](_0x38d4ca)['send'](_0x79a3b2[_0xf4c6('0x33')][_0xf4c6('0x61')]?{'message':'Wrong\x20credentials','statusCode':_0x20753f[_0xf4c6('0x62')]}:_0x20753f);});};
\ No newline at end of file