Built motion from commit (unavailable).|2.5.31
[motion2.git] / server / api / intFreshsalesAccount / intFreshsalesAccount.controller.js
index 8cfe346..c52f5ff 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xb4a4=['rows','show','params','includeAll','options','catch','create','update','body','find','findOne','FreshsalesConfiguration','hasOwnProperty','getConfigurations','addConfiguration','Subjects','getSubjects','Descriptions','getDescriptions','channel','FreshsalesField','getFields','remoteUri','apiKey','username','slice','substring','lastIndexOf','GET','format','%s%s','Token\x20token=','email','Requested\x20Resource\x20not\x20Found','test','statusCode','getFields,\x20%s,\x20%s,\x20%s','Wrong\x20credentials','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','fs-extra','squel','crypto','jsforce','querystring','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','jayson/promise','client','http','request','then','FreshsalesAccount,\x20%s,\x20%s','debug','FreshsalesAccount,\x20%s,\x20%s,\x20%s','request\x20sent','stringify','error','code','message','info','result','sendStatus','status','end','json','offset','undefined','count','limit','set','apply','reject','save','destroy','stack','name','send','index','FreshsalesAccount','rawAttributes','fieldName','type','key','model','keys','intersection','query','attributes','fields','length','nolimit','order','sort','filters','pick','filter','merge','where','map','VIRTUAL','include','findAll'];(function(_0x3a9d79,_0x12852f){var _0x5adf19=function(_0x45b569){while(--_0x45b569){_0x3a9d79['push'](_0x3a9d79['shift']());}};_0x5adf19(++_0x12852f);}(_0xb4a4,0x116));var _0x4b4a=function(_0x42a065,_0x4dba3e){_0x42a065=_0x42a065-0x0;var _0x28790e=_0xb4a4[_0x42a065];return _0x28790e;};'use strict';var emlformat=require(_0x4b4a('0x0'));var rimraf=require(_0x4b4a('0x1'));var zipdir=require(_0x4b4a('0x2'));var jsonpatch=require(_0x4b4a('0x3'));var rp=require(_0x4b4a('0x4'));var moment=require(_0x4b4a('0x5'));var BPromise=require(_0x4b4a('0x6'));var Mustache=require(_0x4b4a('0x7'));var util=require(_0x4b4a('0x8'));var path=require(_0x4b4a('0x9'));var sox=require(_0x4b4a('0xa'));var csv=require(_0x4b4a('0xb'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x4b4a('0xc'));var _=require('lodash');var squel=require(_0x4b4a('0xd'));var crypto=require(_0x4b4a('0xe'));var jsforce=require(_0x4b4a('0xf'));var deskjs=require('desk.js');var toCsv=require(_0x4b4a('0xb'));var querystring=require(_0x4b4a('0x10'));var Papa=require('papaparse');var Redis=require(_0x4b4a('0x11'));var authService=require(_0x4b4a('0x12'));var qs=require('../../components/parsers/qs');var as=require(_0x4b4a('0x13'));var hardwareService=require(_0x4b4a('0x14'));var logger=require(_0x4b4a('0x15'))(_0x4b4a('0x16'));var utils=require('../../config/utils');var config=require(_0x4b4a('0x17'));var licenseUtil=require(_0x4b4a('0x18'));var db=require(_0x4b4a('0x19'))['db'];var integrations=require('../../components/integrations/configuration');var jayson=require(_0x4b4a('0x1a'));var client=jayson[_0x4b4a('0x1b')][_0x4b4a('0x1c')]({'port':0x232a});function respondWithRpcPromise(_0x11fffa,_0x30e29a,_0x1c6e06,_0x1220c0){return new BPromise(function(_0x5be79b,_0x300ea1){var _0x367d6e=_0x1220c0||client;return _0x367d6e[_0x4b4a('0x1d')](_0x11fffa,_0x1c6e06)[_0x4b4a('0x1e')](function(_0x457a25){logger['info'](_0x4b4a('0x1f'),_0x30e29a,'request\x20sent');logger[_0x4b4a('0x20')](_0x4b4a('0x21'),_0x30e29a,_0x4b4a('0x22'),JSON[_0x4b4a('0x23')](_0x457a25));if(_0x457a25[_0x4b4a('0x24')]){if(_0x457a25['error'][_0x4b4a('0x25')]===0x1f4){logger['error'](_0x4b4a('0x1f'),_0x30e29a,_0x457a25['error'][_0x4b4a('0x26')]);return _0x300ea1(_0x457a25[_0x4b4a('0x24')][_0x4b4a('0x26')]);}logger['error'](_0x4b4a('0x1f'),_0x30e29a,_0x457a25[_0x4b4a('0x24')][_0x4b4a('0x26')]);return _0x5be79b(_0x457a25[_0x4b4a('0x24')]['message']);}else{logger[_0x4b4a('0x27')]('FreshsalesAccount,\x20%s,\x20%s',_0x30e29a,_0x4b4a('0x22'));_0x5be79b(_0x457a25[_0x4b4a('0x28')][_0x4b4a('0x26')]);}})['catch'](function(_0x455304){logger['error'](_0x4b4a('0x1f'),_0x30e29a,_0x455304);_0x300ea1(_0x455304);});});}function respondWithStatusCode(_0x2e9776,_0x32189e){_0x32189e=_0x32189e||0xcc;return function(_0x1dfd7a){if(_0x1dfd7a){return _0x2e9776[_0x4b4a('0x29')](_0x32189e);}return _0x2e9776[_0x4b4a('0x2a')](_0x32189e)[_0x4b4a('0x2b')]();};}function respondWithResult(_0x484b96,_0x45e22a){_0x45e22a=_0x45e22a||0xc8;return function(_0x4ad1a5){if(_0x4ad1a5){return _0x484b96[_0x4b4a('0x2a')](_0x45e22a)[_0x4b4a('0x2c')](_0x4ad1a5);}};}function respondWithFilteredResult(_0x470361,_0x2a72e5){return function(_0x5bcffd){if(_0x5bcffd){var _0xbc025c=typeof _0x2a72e5[_0x4b4a('0x2d')]==='undefined'&&typeof _0x2a72e5['limit']===_0x4b4a('0x2e');var _0x36c24b=_0x5bcffd[_0x4b4a('0x2f')];var _0x340320=_0xbc025c?0x0:_0x2a72e5[_0x4b4a('0x2d')];var _0x40d3f0=_0xbc025c?_0x5bcffd['count']:_0x2a72e5['offset']+_0x2a72e5[_0x4b4a('0x30')];var _0x3d9e55;if(_0x40d3f0>=_0x36c24b){_0x40d3f0=_0x36c24b;_0x3d9e55=0xc8;}else{_0x3d9e55=0xce;}_0x470361[_0x4b4a('0x2a')](_0x3d9e55);return _0x470361[_0x4b4a('0x31')]('Content-Range',_0x340320+'-'+_0x40d3f0+'/'+_0x36c24b)[_0x4b4a('0x2c')](_0x5bcffd);}return null;};}function patchUpdates(_0x276888){return function(_0x421ee7){try{jsonpatch[_0x4b4a('0x32')](_0x421ee7,_0x276888,!![]);}catch(_0x16bf0f){return BPromise[_0x4b4a('0x33')](_0x16bf0f);}return _0x421ee7[_0x4b4a('0x34')]();};}function saveUpdates(_0x1f4542,_0xa2d43a){return function(_0x46d017){if(_0x46d017){return _0x46d017['update'](_0x1f4542)['then'](function(_0x11d577){return _0x11d577;});}return null;};}function removeEntity(_0x46adaf,_0x421fbd){return function(_0x29157f){if(_0x29157f){return _0x29157f[_0x4b4a('0x35')]()[_0x4b4a('0x1e')](function(){_0x46adaf[_0x4b4a('0x2a')](0xcc)['end']();});}};}function handleEntityNotFound(_0xeb5f50,_0x4029cb){return function(_0x37629c){if(!_0x37629c){_0xeb5f50[_0x4b4a('0x29')](0x194);}return _0x37629c;};}function handleError(_0xaa5a1d,_0x31ecf7){_0x31ecf7=_0x31ecf7||0x1f4;return function(_0x22609b){logger[_0x4b4a('0x24')](_0x22609b[_0x4b4a('0x36')]);if(_0x22609b[_0x4b4a('0x37')]){delete _0x22609b[_0x4b4a('0x37')];}_0xaa5a1d['status'](_0x31ecf7)[_0x4b4a('0x38')](_0x22609b);};}exports[_0x4b4a('0x39')]=function(_0x2e133c,_0x480722){var _0x455ad0={},_0x121d3c={},_0xbad59a={'count':0x0,'rows':[]};var _0x1653aa=_['map'](db[_0x4b4a('0x3a')][_0x4b4a('0x3b')],function(_0x277410){return{'name':_0x277410[_0x4b4a('0x3c')],'type':_0x277410[_0x4b4a('0x3d')][_0x4b4a('0x3e')]};});_0x121d3c[_0x4b4a('0x3f')]=_['map'](_0x1653aa,_0x4b4a('0x37'));_0x121d3c['query']=_[_0x4b4a('0x40')](_0x2e133c['query']);_0x121d3c['filters']=_[_0x4b4a('0x41')](_0x121d3c[_0x4b4a('0x3f')],_0x121d3c[_0x4b4a('0x42')]);_0x455ad0[_0x4b4a('0x43')]=_[_0x4b4a('0x41')](_0x121d3c[_0x4b4a('0x3f')],qs[_0x4b4a('0x44')](_0x2e133c[_0x4b4a('0x42')]['fields']));_0x455ad0[_0x4b4a('0x43')]=_0x455ad0[_0x4b4a('0x43')][_0x4b4a('0x45')]?_0x455ad0[_0x4b4a('0x43')]:_0x121d3c[_0x4b4a('0x3f')];if(!_0x2e133c[_0x4b4a('0x42')]['hasOwnProperty'](_0x4b4a('0x46'))){_0x455ad0[_0x4b4a('0x30')]=qs[_0x4b4a('0x30')](_0x2e133c['query'][_0x4b4a('0x30')]);_0x455ad0['offset']=qs[_0x4b4a('0x2d')](_0x2e133c[_0x4b4a('0x42')][_0x4b4a('0x2d')]);}_0x455ad0[_0x4b4a('0x47')]=qs[_0x4b4a('0x48')](_0x2e133c[_0x4b4a('0x42')]['sort']);_0x455ad0['where']=qs[_0x4b4a('0x49')](_[_0x4b4a('0x4a')](_0x2e133c['query'],_0x121d3c[_0x4b4a('0x49')]),_0x1653aa);if(_0x2e133c['query'][_0x4b4a('0x4b')]){_0x455ad0['where']=_[_0x4b4a('0x4c')](_0x455ad0[_0x4b4a('0x4d')],{'$or':_[_0x4b4a('0x4e')](_0x1653aa,function(_0xdb83c4){if(_0xdb83c4['type']!==_0x4b4a('0x4f')){var _0x37a656={};_0x37a656[_0xdb83c4[_0x4b4a('0x37')]]={'$like':'%'+_0x2e133c['query'][_0x4b4a('0x4b')]+'%'};return _0x37a656;}})});}_0x455ad0=_[_0x4b4a('0x4c')]({},_0x455ad0,_0x2e133c['options']);var _0x343420={'where':_0x455ad0['where']};return db[_0x4b4a('0x3a')][_0x4b4a('0x2f')](_0x343420)[_0x4b4a('0x1e')](function(_0x3032fc){_0xbad59a['count']=_0x3032fc;if(_0x2e133c[_0x4b4a('0x42')]['includeAll']){_0x455ad0[_0x4b4a('0x50')]=[{'all':!![]}];}return db[_0x4b4a('0x3a')][_0x4b4a('0x51')](_0x455ad0);})[_0x4b4a('0x1e')](function(_0x93afcb){_0xbad59a[_0x4b4a('0x52')]=_0x93afcb;return _0xbad59a;})[_0x4b4a('0x1e')](respondWithFilteredResult(_0x480722,_0x455ad0))['catch'](handleError(_0x480722,null));};exports[_0x4b4a('0x53')]=function(_0x1858ee,_0x58a1ba){var _0x4eac9e={'raw':![],'where':{'id':_0x1858ee[_0x4b4a('0x54')]['id']}},_0x5f8903={};_0x5f8903[_0x4b4a('0x3f')]=_['keys'](db[_0x4b4a('0x3a')][_0x4b4a('0x3b')]);_0x5f8903[_0x4b4a('0x42')]=_[_0x4b4a('0x40')](_0x1858ee['query']);_0x5f8903[_0x4b4a('0x49')]=_[_0x4b4a('0x41')](_0x5f8903[_0x4b4a('0x3f')],_0x5f8903[_0x4b4a('0x42')]);_0x4eac9e['attributes']=_['intersection'](_0x5f8903[_0x4b4a('0x3f')],qs['fields'](_0x1858ee['query'][_0x4b4a('0x44')]));_0x4eac9e[_0x4b4a('0x43')]=_0x4eac9e[_0x4b4a('0x43')]['length']?_0x4eac9e['attributes']:_0x5f8903[_0x4b4a('0x3f')];if(_0x1858ee['query'][_0x4b4a('0x55')]){_0x4eac9e[_0x4b4a('0x50')]=[{'all':!![]}];}_0x4eac9e=_['merge']({},_0x4eac9e,_0x1858ee[_0x4b4a('0x56')]);return db[_0x4b4a('0x3a')]['find'](_0x4eac9e)[_0x4b4a('0x1e')](handleEntityNotFound(_0x58a1ba,null))[_0x4b4a('0x1e')](respondWithResult(_0x58a1ba,null))[_0x4b4a('0x57')](handleError(_0x58a1ba,null));};exports[_0x4b4a('0x58')]=function(_0x3ffb37,_0x3e3676){return db['FreshsalesAccount']['create'](_0x3ffb37['body'],{})['then'](respondWithResult(_0x3e3676,0xc9))[_0x4b4a('0x57')](handleError(_0x3e3676,null));};exports[_0x4b4a('0x59')]=function(_0x1e05ef,_0x2d085b){if(_0x1e05ef[_0x4b4a('0x5a')]['id']){delete _0x1e05ef['body']['id'];}return db[_0x4b4a('0x3a')][_0x4b4a('0x5b')]({'where':{'id':_0x1e05ef[_0x4b4a('0x54')]['id']}})['then'](handleEntityNotFound(_0x2d085b,null))[_0x4b4a('0x1e')](saveUpdates(_0x1e05ef['body'],null))[_0x4b4a('0x1e')](respondWithResult(_0x2d085b,null))[_0x4b4a('0x57')](handleError(_0x2d085b,null));};exports[_0x4b4a('0x35')]=function(_0x492e64,_0x504dcb){return db[_0x4b4a('0x3a')][_0x4b4a('0x5b')]({'where':{'id':_0x492e64[_0x4b4a('0x54')]['id']}})[_0x4b4a('0x1e')](handleEntityNotFound(_0x504dcb,null))[_0x4b4a('0x1e')](removeEntity(_0x504dcb,null))[_0x4b4a('0x57')](handleError(_0x504dcb,null));};exports['getConfigurations']=function(_0x272854,_0x2efdcc,_0x4cd965){var _0x397590={};var _0x599e4b={};var _0x322067;var _0x4d316c;return db[_0x4b4a('0x3a')][_0x4b4a('0x5c')]({'where':{'id':_0x272854[_0x4b4a('0x54')]['id']}})[_0x4b4a('0x1e')](handleEntityNotFound(_0x2efdcc,null))[_0x4b4a('0x1e')](function(_0x33db13){if(_0x33db13){_0x322067=_0x33db13;_0x599e4b['model']=_[_0x4b4a('0x40')](db[_0x4b4a('0x5d')][_0x4b4a('0x3b')]);_0x599e4b[_0x4b4a('0x42')]=_[_0x4b4a('0x40')](_0x272854[_0x4b4a('0x42')]);_0x599e4b[_0x4b4a('0x49')]=_['intersection'](_0x599e4b[_0x4b4a('0x3f')],_0x599e4b[_0x4b4a('0x42')]);_0x397590[_0x4b4a('0x43')]=_['intersection'](_0x599e4b[_0x4b4a('0x3f')],qs[_0x4b4a('0x44')](_0x272854[_0x4b4a('0x42')]['fields']));_0x397590[_0x4b4a('0x43')]=_0x397590[_0x4b4a('0x43')][_0x4b4a('0x45')]?_0x397590[_0x4b4a('0x43')]:_0x599e4b['model'];_0x397590[_0x4b4a('0x47')]=qs['sort'](_0x272854[_0x4b4a('0x42')][_0x4b4a('0x48')]);_0x397590['where']=qs[_0x4b4a('0x49')](_[_0x4b4a('0x4a')](_0x272854[_0x4b4a('0x42')],_0x599e4b[_0x4b4a('0x49')]));if(_0x272854[_0x4b4a('0x42')][_0x4b4a('0x4b')]){_0x397590['where']=_[_0x4b4a('0x4c')](_0x397590['where'],{'$or':_[_0x4b4a('0x4e')](_0x397590[_0x4b4a('0x43')],function(_0x41be3a){var _0x2e31b0={};_0x2e31b0[_0x41be3a]={'$like':'%'+_0x272854[_0x4b4a('0x42')][_0x4b4a('0x4b')]+'%'};return _0x2e31b0;})});}_0x397590=_[_0x4b4a('0x4c')]({},_0x397590,_0x272854[_0x4b4a('0x56')]);return _0x322067['getConfigurations'](_0x397590);}})[_0x4b4a('0x1e')](function(_0x14d823){if(_0x14d823){_0x4d316c=_0x14d823[_0x4b4a('0x45')];if(!_0x272854[_0x4b4a('0x42')][_0x4b4a('0x5e')](_0x4b4a('0x46'))){_0x397590[_0x4b4a('0x30')]=qs[_0x4b4a('0x30')](_0x272854['query'][_0x4b4a('0x30')]);_0x397590[_0x4b4a('0x2d')]=qs[_0x4b4a('0x2d')](_0x272854[_0x4b4a('0x42')]['offset']);}return _0x322067[_0x4b4a('0x5f')](_0x397590);}})['then'](function(_0x58905a){if(_0x58905a){return _0x58905a?{'count':_0x4d316c,'rows':_0x58905a}:null;}})[_0x4b4a('0x1e')](respondWithResult(_0x2efdcc,null))[_0x4b4a('0x57')](handleError(_0x2efdcc,null));};exports[_0x4b4a('0x60')]=function(_0x5a977c,_0x319b84,_0x29505b){if(_0x5a977c[_0x4b4a('0x5a')]['id']){delete _0x5a977c['body']['id'];}return db['FreshsalesAccount'][_0x4b4a('0x5c')]({'where':{'id':_0x5a977c[_0x4b4a('0x54')]['id']}})['then'](handleEntityNotFound(_0x319b84,null))['then'](function(_0x369e2e){if(_0x369e2e){_0x5a977c[_0x4b4a('0x5a')]['AccountId']=_0x369e2e['id'];_0x5a977c[_0x4b4a('0x5a')][_0x4b4a('0x61')]=integrations[_0x4b4a('0x62')](_0x5a977c[_0x4b4a('0x5a')]['channel'],_0x5a977c[_0x4b4a('0x5a')][_0x4b4a('0x3d')]);_0x5a977c['body'][_0x4b4a('0x63')]=integrations[_0x4b4a('0x64')](_0x5a977c[_0x4b4a('0x5a')][_0x4b4a('0x65')],_0x5a977c['body'][_0x4b4a('0x3d')]);return db[_0x4b4a('0x5d')][_0x4b4a('0x58')](_0x5a977c[_0x4b4a('0x5a')],{'include':[{'model':db[_0x4b4a('0x66')],'as':_0x4b4a('0x61')},{'model':db['FreshsalesField'],'as':_0x4b4a('0x63')}]});}return null;})[_0x4b4a('0x1e')](respondWithResult(_0x319b84,null))[_0x4b4a('0x57')](handleError(_0x319b84,null));};exports[_0x4b4a('0x67')]=function(_0x24ddd0,_0x3d370d,_0x190fe0){var _0x1b3feb='';var _0x49e7ac='';return db[_0x4b4a('0x3a')][_0x4b4a('0x5c')]({'where':{'id':_0x24ddd0[_0x4b4a('0x54')]['id']},'attributes':['id','username',_0x4b4a('0x68'),_0x4b4a('0x69')]})[_0x4b4a('0x1e')](handleEntityNotFound(_0x3d370d,null))[_0x4b4a('0x1e')](function(_0x5ed7f1){if(_0x5ed7f1){_0x49e7ac=_0x5ed7f1[_0x4b4a('0x6a')];_0x1b3feb=_0x5ed7f1[_0x4b4a('0x68')];var _0x3dcfbd=_0x5ed7f1['remoteUri'][_0x4b4a('0x6b')](-0x1);if(_0x3dcfbd==='/'){_0x1b3feb=_0x1b3feb[_0x4b4a('0x6c')](0x0,_0x1b3feb[_0x4b4a('0x6d')](_0x3dcfbd));}return rp({'method':_0x4b4a('0x6e'),'uri':util[_0x4b4a('0x6f')](_0x4b4a('0x70'),_0x1b3feb,'/api/selector/owners'),'headers':{'Authorization':_0x4b4a('0x71')+_0x5ed7f1[_0x4b4a('0x69')]},'json':!![]});}})[_0x4b4a('0x1e')](function(_0x3a08b7){if(_0x3a08b7){var _0x1b8944=_0x3a08b7['users'];var _0xaca086=![];var _0x11f10d=null;for(_0x11f10d=0x0;_0x11f10d<_0x1b8944[_0x4b4a('0x45')];_0x11f10d++){if(_0x1b8944[_0x11f10d][_0x4b4a('0x72')]===_0x49e7ac){_0xaca086=!![];}}if(_0xaca086){return!![];}else{throw new Error({'statusCode':0x194,'message':_0x4b4a('0x73')});}}})[_0x4b4a('0x1e')](respondWithResult(_0x3d370d,null))['catch'](function(_0x1a302c){var _0x32c07b=_0x24ddd0[_0x4b4a('0x42')][_0x4b4a('0x74')]?0x1f4:_0x1a302c[_0x4b4a('0x75')]||0x1f4;logger[_0x4b4a('0x24')](_0x4b4a('0x76'),_0x4b4a('0x67'),_0x32c07b,JSON['stringify'](_0x1a302c));delete _0x1a302c[_0x4b4a('0x37')];if(_0x32c07b===0x191){_0x32c07b=0x190;}_0x3d370d[_0x4b4a('0x2a')](_0x32c07b)['send'](_0x24ddd0[_0x4b4a('0x42')][_0x4b4a('0x74')]?{'message':_0x4b4a('0x77'),'statusCode':_0x1a302c[_0x4b4a('0x75')]}:_0x1a302c);});};
\ No newline at end of file
+var _0xf88f=['../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','../../components/integrations/configuration','client','http','request','then','FreshsalesAccount,\x20%s,\x20%s','request\x20sent','stringify','error','code','message','info','catch','sendStatus','status','json','undefined','limit','count','set','Content-Range','apply','save','destroy','end','stack','name','send','index','map','FreshsalesAccount','fieldName','type','key','model','query','keys','filters','intersection','fields','attributes','length','hasOwnProperty','offset','order','sort','where','filter','merge','includeAll','include','rows','params','rawAttributes','update','body','find','FreshsalesConfiguration','options','getConfigurations','nolimit','addConfiguration','findOne','Subjects','getSubjects','channel','Descriptions','getDescriptions','FreshsalesField','getFields','username','remoteUri','apiKey','substring','lastIndexOf','GET','%s%s','/api/selector/owners','Token\x20token=','users','email','Requested\x20Resource\x20not\x20Found','test','statusCode','getFields,\x20%s,\x20%s,\x20%s','Wrong\x20credentials','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','path','sox','ejs','fs-extra','lodash','squel','crypto','jsforce','to-csv','querystring','papaparse','ioredis','../../components/auth/service'];(function(_0x2b9e6e,_0x2355e5){var _0x12c3e9=function(_0x4de161){while(--_0x4de161){_0x2b9e6e['push'](_0x2b9e6e['shift']());}};_0x12c3e9(++_0x2355e5);}(_0xf88f,0x1bb));var _0xff88=function(_0x37ed97,_0xe3d3b7){_0x37ed97=_0x37ed97-0x0;var _0x2c042e=_0xf88f[_0x37ed97];return _0x2c042e;};'use strict';var emlformat=require(_0xff88('0x0'));var rimraf=require(_0xff88('0x1'));var zipdir=require(_0xff88('0x2'));var jsonpatch=require(_0xff88('0x3'));var rp=require(_0xff88('0x4'));var moment=require(_0xff88('0x5'));var BPromise=require(_0xff88('0x6'));var Mustache=require('mustache');var util=require(_0xff88('0x7'));var path=require(_0xff88('0x8'));var sox=require(_0xff88('0x9'));var csv=require('to-csv');var ejs=require(_0xff88('0xa'));var fs=require('fs');var fs_extra=require(_0xff88('0xb'));var _=require(_0xff88('0xc'));var squel=require(_0xff88('0xd'));var crypto=require(_0xff88('0xe'));var jsforce=require(_0xff88('0xf'));var deskjs=require('desk.js');var toCsv=require(_0xff88('0x10'));var querystring=require(_0xff88('0x11'));var Papa=require(_0xff88('0x12'));var Redis=require(_0xff88('0x13'));var authService=require(_0xff88('0x14'));var qs=require(_0xff88('0x15'));var as=require(_0xff88('0x16'));var hardwareService=require(_0xff88('0x17'));var logger=require(_0xff88('0x18'))(_0xff88('0x19'));var utils=require(_0xff88('0x1a'));var config=require(_0xff88('0x1b'));var licenseUtil=require(_0xff88('0x1c'));var db=require(_0xff88('0x1d'))['db'];var integrations=require(_0xff88('0x1e'));var jayson=require('jayson/promise');var client=jayson[_0xff88('0x1f')][_0xff88('0x20')]({'port':0x232a});function respondWithRpcPromise(_0x14b38a,_0x50b341,_0x3db338,_0x3ea7fe){return new BPromise(function(_0x44d5f6,_0x116712){var _0xcd256f=_0x3ea7fe||client;return _0xcd256f[_0xff88('0x21')](_0x14b38a,_0x3db338)[_0xff88('0x22')](function(_0x213aa9){logger['info'](_0xff88('0x23'),_0x50b341,_0xff88('0x24'));logger['debug']('FreshsalesAccount,\x20%s,\x20%s,\x20%s',_0x50b341,_0xff88('0x24'),JSON[_0xff88('0x25')](_0x213aa9));if(_0x213aa9['error']){if(_0x213aa9[_0xff88('0x26')][_0xff88('0x27')]===0x1f4){logger['error'](_0xff88('0x23'),_0x50b341,_0x213aa9[_0xff88('0x26')][_0xff88('0x28')]);return _0x116712(_0x213aa9[_0xff88('0x26')][_0xff88('0x28')]);}logger[_0xff88('0x26')](_0xff88('0x23'),_0x50b341,_0x213aa9['error'][_0xff88('0x28')]);return _0x44d5f6(_0x213aa9[_0xff88('0x26')][_0xff88('0x28')]);}else{logger[_0xff88('0x29')](_0xff88('0x23'),_0x50b341,_0xff88('0x24'));_0x44d5f6(_0x213aa9['result'][_0xff88('0x28')]);}})[_0xff88('0x2a')](function(_0x2b8517){logger[_0xff88('0x26')](_0xff88('0x23'),_0x50b341,_0x2b8517);_0x116712(_0x2b8517);});});}function respondWithStatusCode(_0x2faa68,_0x21198b){_0x21198b=_0x21198b||0xcc;return function(_0x57b492){if(_0x57b492){return _0x2faa68[_0xff88('0x2b')](_0x21198b);}return _0x2faa68[_0xff88('0x2c')](_0x21198b)['end']();};}function respondWithResult(_0x87412f,_0x3f7ab7){_0x3f7ab7=_0x3f7ab7||0xc8;return function(_0x2326f2){if(_0x2326f2){return _0x87412f['status'](_0x3f7ab7)[_0xff88('0x2d')](_0x2326f2);}};}function respondWithFilteredResult(_0x126c2d,_0x5e66ef){return function(_0xc5bab0){if(_0xc5bab0){var _0x362d60=typeof _0x5e66ef['offset']===_0xff88('0x2e')&&typeof _0x5e66ef[_0xff88('0x2f')]===_0xff88('0x2e');var _0x320ea0=_0xc5bab0[_0xff88('0x30')];var _0xf04956=_0x362d60?0x0:_0x5e66ef['offset'];var _0x70e676=_0x362d60?_0xc5bab0[_0xff88('0x30')]:_0x5e66ef['offset']+_0x5e66ef[_0xff88('0x2f')];var _0x2356d1;if(_0x70e676>=_0x320ea0){_0x70e676=_0x320ea0;_0x2356d1=0xc8;}else{_0x2356d1=0xce;}_0x126c2d[_0xff88('0x2c')](_0x2356d1);return _0x126c2d[_0xff88('0x31')](_0xff88('0x32'),_0xf04956+'-'+_0x70e676+'/'+_0x320ea0)[_0xff88('0x2d')](_0xc5bab0);}return null;};}function patchUpdates(_0x4e7569){return function(_0x2564b2){try{jsonpatch[_0xff88('0x33')](_0x2564b2,_0x4e7569,!![]);}catch(_0x438949){return BPromise['reject'](_0x438949);}return _0x2564b2[_0xff88('0x34')]();};}function saveUpdates(_0x39ab23,_0x40b059){return function(_0x56a1a5){if(_0x56a1a5){return _0x56a1a5['update'](_0x39ab23)[_0xff88('0x22')](function(_0x41e11d){return _0x41e11d;});}return null;};}function removeEntity(_0xf8a047,_0x382d8a){return function(_0x1c7937){if(_0x1c7937){return _0x1c7937[_0xff88('0x35')]()[_0xff88('0x22')](function(){_0xf8a047[_0xff88('0x2c')](0xcc)[_0xff88('0x36')]();});}};}function handleEntityNotFound(_0x37019d,_0x68cfdb){return function(_0x5630e0){if(!_0x5630e0){_0x37019d[_0xff88('0x2b')](0x194);}return _0x5630e0;};}function handleError(_0x5d5d8c,_0x433485){_0x433485=_0x433485||0x1f4;return function(_0x435779){logger['error'](_0x435779[_0xff88('0x37')]);if(_0x435779[_0xff88('0x38')]){delete _0x435779[_0xff88('0x38')];}_0x5d5d8c['status'](_0x433485)[_0xff88('0x39')](_0x435779);};}exports[_0xff88('0x3a')]=function(_0x28ce5a,_0x46dd29){var _0x127c5a={},_0x3eecd4={},_0x3a5531={'count':0x0,'rows':[]};var _0x34a206=_[_0xff88('0x3b')](db[_0xff88('0x3c')]['rawAttributes'],function(_0x4ed969){return{'name':_0x4ed969[_0xff88('0x3d')],'type':_0x4ed969[_0xff88('0x3e')][_0xff88('0x3f')]};});_0x3eecd4[_0xff88('0x40')]=_['map'](_0x34a206,_0xff88('0x38'));_0x3eecd4[_0xff88('0x41')]=_[_0xff88('0x42')](_0x28ce5a[_0xff88('0x41')]);_0x3eecd4[_0xff88('0x43')]=_[_0xff88('0x44')](_0x3eecd4[_0xff88('0x40')],_0x3eecd4[_0xff88('0x41')]);_0x127c5a['attributes']=_[_0xff88('0x44')](_0x3eecd4['model'],qs[_0xff88('0x45')](_0x28ce5a[_0xff88('0x41')][_0xff88('0x45')]));_0x127c5a[_0xff88('0x46')]=_0x127c5a['attributes'][_0xff88('0x47')]?_0x127c5a['attributes']:_0x3eecd4[_0xff88('0x40')];if(!_0x28ce5a['query'][_0xff88('0x48')]('nolimit')){_0x127c5a[_0xff88('0x2f')]=qs[_0xff88('0x2f')](_0x28ce5a[_0xff88('0x41')][_0xff88('0x2f')]);_0x127c5a[_0xff88('0x49')]=qs[_0xff88('0x49')](_0x28ce5a['query'][_0xff88('0x49')]);}_0x127c5a[_0xff88('0x4a')]=qs['sort'](_0x28ce5a['query'][_0xff88('0x4b')]);_0x127c5a[_0xff88('0x4c')]=qs[_0xff88('0x43')](_['pick'](_0x28ce5a[_0xff88('0x41')],_0x3eecd4[_0xff88('0x43')]),_0x34a206);if(_0x28ce5a['query'][_0xff88('0x4d')]){_0x127c5a[_0xff88('0x4c')]=_[_0xff88('0x4e')](_0x127c5a[_0xff88('0x4c')],{'$or':_['map'](_0x34a206,function(_0x47d01e){if(_0x47d01e[_0xff88('0x3e')]!=='VIRTUAL'){var _0x54dd61={};_0x54dd61[_0x47d01e[_0xff88('0x38')]]={'$like':'%'+_0x28ce5a['query'][_0xff88('0x4d')]+'%'};return _0x54dd61;}})});}_0x127c5a=_[_0xff88('0x4e')]({},_0x127c5a,_0x28ce5a['options']);var _0x416e1d={'where':_0x127c5a[_0xff88('0x4c')]};return db[_0xff88('0x3c')][_0xff88('0x30')](_0x416e1d)['then'](function(_0x38a370){_0x3a5531['count']=_0x38a370;if(_0x28ce5a[_0xff88('0x41')][_0xff88('0x4f')]){_0x127c5a[_0xff88('0x50')]=[{'all':!![]}];}return db[_0xff88('0x3c')]['findAll'](_0x127c5a);})[_0xff88('0x22')](function(_0x374ff0){_0x3a5531[_0xff88('0x51')]=_0x374ff0;return _0x3a5531;})[_0xff88('0x22')](respondWithFilteredResult(_0x46dd29,_0x127c5a))[_0xff88('0x2a')](handleError(_0x46dd29,null));};exports['show']=function(_0x163b3d,_0x506e26){var _0x3654fa={'raw':![],'where':{'id':_0x163b3d[_0xff88('0x52')]['id']}},_0x20b1b7={};_0x20b1b7[_0xff88('0x40')]=_['keys'](db['FreshsalesAccount'][_0xff88('0x53')]);_0x20b1b7['query']=_[_0xff88('0x42')](_0x163b3d[_0xff88('0x41')]);_0x20b1b7[_0xff88('0x43')]=_['intersection'](_0x20b1b7[_0xff88('0x40')],_0x20b1b7[_0xff88('0x41')]);_0x3654fa[_0xff88('0x46')]=_['intersection'](_0x20b1b7['model'],qs[_0xff88('0x45')](_0x163b3d[_0xff88('0x41')][_0xff88('0x45')]));_0x3654fa['attributes']=_0x3654fa[_0xff88('0x46')][_0xff88('0x47')]?_0x3654fa[_0xff88('0x46')]:_0x20b1b7['model'];if(_0x163b3d['query']['includeAll']){_0x3654fa[_0xff88('0x50')]=[{'all':!![]}];}_0x3654fa=_[_0xff88('0x4e')]({},_0x3654fa,_0x163b3d['options']);return db[_0xff88('0x3c')]['find'](_0x3654fa)['then'](handleEntityNotFound(_0x506e26,null))[_0xff88('0x22')](respondWithResult(_0x506e26,null))['catch'](handleError(_0x506e26,null));};exports['create']=function(_0x2fe361,_0xdc043b){return db[_0xff88('0x3c')]['create'](_0x2fe361['body'],{})[_0xff88('0x22')](respondWithResult(_0xdc043b,0xc9))['catch'](handleError(_0xdc043b,null));};exports[_0xff88('0x54')]=function(_0x566d3e,_0x14dbbb){if(_0x566d3e['body']['id']){delete _0x566d3e[_0xff88('0x55')]['id'];}return db[_0xff88('0x3c')][_0xff88('0x56')]({'where':{'id':_0x566d3e['params']['id']}})['then'](handleEntityNotFound(_0x14dbbb,null))[_0xff88('0x22')](saveUpdates(_0x566d3e[_0xff88('0x55')],null))[_0xff88('0x22')](respondWithResult(_0x14dbbb,null))[_0xff88('0x2a')](handleError(_0x14dbbb,null));};exports[_0xff88('0x35')]=function(_0x5a4162,_0x3075e1){return db['FreshsalesAccount'][_0xff88('0x56')]({'where':{'id':_0x5a4162[_0xff88('0x52')]['id']}})[_0xff88('0x22')](handleEntityNotFound(_0x3075e1,null))[_0xff88('0x22')](removeEntity(_0x3075e1,null))['catch'](handleError(_0x3075e1,null));};exports['getConfigurations']=function(_0x389ccc,_0x555270,_0x387ae5){var _0x4c3f66={};var _0x534bd7={};var _0x544d02;var _0x5acce0;return db[_0xff88('0x3c')]['findOne']({'where':{'id':_0x389ccc['params']['id']}})[_0xff88('0x22')](handleEntityNotFound(_0x555270,null))[_0xff88('0x22')](function(_0x54daaa){if(_0x54daaa){_0x544d02=_0x54daaa;_0x534bd7[_0xff88('0x40')]=_['keys'](db[_0xff88('0x57')][_0xff88('0x53')]);_0x534bd7[_0xff88('0x41')]=_['keys'](_0x389ccc['query']);_0x534bd7[_0xff88('0x43')]=_[_0xff88('0x44')](_0x534bd7[_0xff88('0x40')],_0x534bd7[_0xff88('0x41')]);_0x4c3f66[_0xff88('0x46')]=_[_0xff88('0x44')](_0x534bd7[_0xff88('0x40')],qs['fields'](_0x389ccc[_0xff88('0x41')]['fields']));_0x4c3f66[_0xff88('0x46')]=_0x4c3f66[_0xff88('0x46')]['length']?_0x4c3f66['attributes']:_0x534bd7[_0xff88('0x40')];_0x4c3f66[_0xff88('0x4a')]=qs[_0xff88('0x4b')](_0x389ccc[_0xff88('0x41')][_0xff88('0x4b')]);_0x4c3f66[_0xff88('0x4c')]=qs[_0xff88('0x43')](_['pick'](_0x389ccc[_0xff88('0x41')],_0x534bd7[_0xff88('0x43')]));if(_0x389ccc[_0xff88('0x41')][_0xff88('0x4d')]){_0x4c3f66[_0xff88('0x4c')]=_[_0xff88('0x4e')](_0x4c3f66[_0xff88('0x4c')],{'$or':_[_0xff88('0x3b')](_0x4c3f66[_0xff88('0x46')],function(_0x596b6d){var _0x44c2f0={};_0x44c2f0[_0x596b6d]={'$like':'%'+_0x389ccc[_0xff88('0x41')][_0xff88('0x4d')]+'%'};return _0x44c2f0;})});}_0x4c3f66=_[_0xff88('0x4e')]({},_0x4c3f66,_0x389ccc[_0xff88('0x58')]);return _0x544d02[_0xff88('0x59')](_0x4c3f66);}})[_0xff88('0x22')](function(_0x5a30ff){if(_0x5a30ff){_0x5acce0=_0x5a30ff['length'];if(!_0x389ccc['query'][_0xff88('0x48')](_0xff88('0x5a'))){_0x4c3f66[_0xff88('0x2f')]=qs['limit'](_0x389ccc['query'][_0xff88('0x2f')]);_0x4c3f66['offset']=qs[_0xff88('0x49')](_0x389ccc['query']['offset']);}return _0x544d02[_0xff88('0x59')](_0x4c3f66);}})[_0xff88('0x22')](function(_0x85ee06){if(_0x85ee06){return _0x85ee06?{'count':_0x5acce0,'rows':_0x85ee06}:null;}})[_0xff88('0x22')](respondWithResult(_0x555270,null))[_0xff88('0x2a')](handleError(_0x555270,null));};exports[_0xff88('0x5b')]=function(_0x8230ad,_0xe3bb9,_0x4d5986){if(_0x8230ad[_0xff88('0x55')]['id']){delete _0x8230ad[_0xff88('0x55')]['id'];}return db['FreshsalesAccount'][_0xff88('0x5c')]({'where':{'id':_0x8230ad[_0xff88('0x52')]['id']}})[_0xff88('0x22')](handleEntityNotFound(_0xe3bb9,null))['then'](function(_0xe8529){if(_0xe8529){_0x8230ad[_0xff88('0x55')]['AccountId']=_0xe8529['id'];_0x8230ad[_0xff88('0x55')][_0xff88('0x5d')]=integrations[_0xff88('0x5e')](_0x8230ad[_0xff88('0x55')][_0xff88('0x5f')],_0x8230ad[_0xff88('0x55')][_0xff88('0x3e')]);_0x8230ad[_0xff88('0x55')][_0xff88('0x60')]=integrations[_0xff88('0x61')](_0x8230ad[_0xff88('0x55')]['channel'],_0x8230ad['body'][_0xff88('0x3e')]);return db[_0xff88('0x57')]['create'](_0x8230ad[_0xff88('0x55')],{'include':[{'model':db[_0xff88('0x62')],'as':'Subjects'},{'model':db[_0xff88('0x62')],'as':_0xff88('0x60')}]});}return null;})[_0xff88('0x22')](respondWithResult(_0xe3bb9,null))[_0xff88('0x2a')](handleError(_0xe3bb9,null));};exports[_0xff88('0x63')]=function(_0x1fe665,_0x24c9b7,_0x312b83){var _0x501ba8='';var _0x3d5438='';return db[_0xff88('0x3c')][_0xff88('0x5c')]({'where':{'id':_0x1fe665[_0xff88('0x52')]['id']},'attributes':['id',_0xff88('0x64'),_0xff88('0x65'),_0xff88('0x66')]})[_0xff88('0x22')](handleEntityNotFound(_0x24c9b7,null))['then'](function(_0x5a3e29){if(_0x5a3e29){_0x3d5438=_0x5a3e29[_0xff88('0x64')];_0x501ba8=_0x5a3e29[_0xff88('0x65')];var _0xa9bcea=_0x5a3e29['remoteUri']['slice'](-0x1);if(_0xa9bcea==='/'){_0x501ba8=_0x501ba8[_0xff88('0x67')](0x0,_0x501ba8[_0xff88('0x68')](_0xa9bcea));}return rp({'method':_0xff88('0x69'),'uri':util['format'](_0xff88('0x6a'),_0x501ba8,_0xff88('0x6b')),'headers':{'Authorization':_0xff88('0x6c')+_0x5a3e29[_0xff88('0x66')]},'json':!![]});}})['then'](function(_0x57fb92){if(_0x57fb92){var _0x2dbdd6=_0x57fb92[_0xff88('0x6d')];var _0x2297b3=![];var _0x4517b5=null;for(_0x4517b5=0x0;_0x4517b5<_0x2dbdd6[_0xff88('0x47')];_0x4517b5++){if(_0x2dbdd6[_0x4517b5][_0xff88('0x6e')]===_0x3d5438){_0x2297b3=!![];}}if(_0x2297b3){return!![];}else{throw new Error({'statusCode':0x194,'message':_0xff88('0x6f')});}}})[_0xff88('0x22')](respondWithResult(_0x24c9b7,null))[_0xff88('0x2a')](function(_0xb1ba80){var _0x3ef195=_0x1fe665[_0xff88('0x41')][_0xff88('0x70')]?0x1f4:_0xb1ba80[_0xff88('0x71')]||0x1f4;logger['error'](_0xff88('0x72'),'getFields',_0x3ef195,JSON[_0xff88('0x25')](_0xb1ba80));delete _0xb1ba80[_0xff88('0x38')];if(_0x3ef195===0x191){_0x3ef195=0x190;}_0x24c9b7[_0xff88('0x2c')](_0x3ef195)[_0xff88('0x39')](_0x1fe665['query'][_0xff88('0x70')]?{'message':_0xff88('0x73'),'statusCode':_0xb1ba80[_0xff88('0x71')]}:_0xb1ba80);});};
\ No newline at end of file