Built motion from commit e0fa946e.|2.6.5
[motion2.git] / server / api / intVtigerAccount / intVtigerAccount.controller.js
index 9b835b3..a9e527c 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x5d62=['rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','path','sox','to-csv','fs-extra','squel','crypto','desk.js','querystring','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','sendStatus','end','status','json','offset','undefined','count','Content-Range','apply','reject','update','then','destroy','error','stack','name','send','index','map','VtigerAccount','rawAttributes','fieldName','key','model','keys','query','filters','intersection','fields','attributes','length','hasOwnProperty','limit','sort','filter','where','merge','type','VIRTUAL','options','include','rows','params','includeAll','find','catch','create','body','getConfigurations','findOne','VtigerConfiguration','order','addConfiguration','AccountId','Subjects','getSubjects','getDescriptions','channel','VtigerField','Descriptions','md5','getFields','moduleName','remoteUri','serverUrl','accessKey','username','slice','substring','lastIndexOf','format','%s/webservice.php','GET','getchallenge','success','POST','login','result','describe','autogenerated','reference','owner','remove','includes','editable','false','label','startsWith','cf_','picklist','picklistValues','value','log','vTiger\x20error:\x20','test','getFields,\x20%s,\x20%s,\x20%s','stringify','Wrong\x20credentials','statusCode','eml-format'];(function(_0x56d1f0,_0x729ae0){var _0x343bdb=function(_0x3a2a21){while(--_0x3a2a21){_0x56d1f0['push'](_0x56d1f0['shift']());}};_0x343bdb(++_0x729ae0);}(_0x5d62,0xef));var _0x25d6=function(_0x273b24,_0x2fdea7){_0x273b24=_0x273b24-0x0;var _0x17597d=_0x5d62[_0x273b24];return _0x17597d;};'use strict';var emlformat=require(_0x25d6('0x0'));var rimraf=require(_0x25d6('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x25d6('0x2'));var rp=require(_0x25d6('0x3'));var moment=require(_0x25d6('0x4'));var BPromise=require(_0x25d6('0x5'));var Mustache=require(_0x25d6('0x6'));var util=require('util');var path=require(_0x25d6('0x7'));var sox=require(_0x25d6('0x8'));var csv=require(_0x25d6('0x9'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x25d6('0xa'));var _=require('lodash');var squel=require(_0x25d6('0xb'));var crypto=require(_0x25d6('0xc'));var jsforce=require('jsforce');var deskjs=require(_0x25d6('0xd'));var toCsv=require(_0x25d6('0x9'));var querystring=require(_0x25d6('0xe'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0x25d6('0xf'));var qs=require('../../components/parsers/qs');var as=require(_0x25d6('0x10'));var hardwareService=require(_0x25d6('0x11'));var logger=require(_0x25d6('0x12'))(_0x25d6('0x13'));var utils=require(_0x25d6('0x14'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];var integrations=require('../../components/integrations/configuration');function respondWithStatusCode(_0xf1c805,_0x3966b0){_0x3966b0=_0x3966b0||0xcc;return function(_0x3a518e){if(_0x3a518e){return _0xf1c805[_0x25d6('0x15')](_0x3966b0);}return _0xf1c805['status'](_0x3966b0)[_0x25d6('0x16')]();};}function respondWithResult(_0x3c630e,_0x39732c){_0x39732c=_0x39732c||0xc8;return function(_0x3de8be){if(_0x3de8be){return _0x3c630e[_0x25d6('0x17')](_0x39732c)[_0x25d6('0x18')](_0x3de8be);}};}function respondWithFilteredResult(_0x1eeab9,_0x333097){return function(_0x44dda2){if(_0x44dda2){var _0xe41f78=typeof _0x333097[_0x25d6('0x19')]===_0x25d6('0x1a')&&typeof _0x333097['limit']===_0x25d6('0x1a');var _0x53d832=_0x44dda2[_0x25d6('0x1b')];var _0x2cc0cc=_0xe41f78?0x0:_0x333097[_0x25d6('0x19')];var _0x4b260b=_0xe41f78?_0x44dda2[_0x25d6('0x1b')]:_0x333097[_0x25d6('0x19')]+_0x333097['limit'];var _0x50ff21;if(_0x4b260b>=_0x53d832){_0x4b260b=_0x53d832;_0x50ff21=0xc8;}else{_0x50ff21=0xce;}_0x1eeab9[_0x25d6('0x17')](_0x50ff21);return _0x1eeab9['set'](_0x25d6('0x1c'),_0x2cc0cc+'-'+_0x4b260b+'/'+_0x53d832)['json'](_0x44dda2);}return null;};}function patchUpdates(_0x1b6e04){return function(_0x3d7178){try{jsonpatch[_0x25d6('0x1d')](_0x3d7178,_0x1b6e04,!![]);}catch(_0x3f3ad5){return BPromise[_0x25d6('0x1e')](_0x3f3ad5);}return _0x3d7178['save']();};}function saveUpdates(_0x39c6f5,_0x5eb88a){return function(_0x48ef3e){if(_0x48ef3e){return _0x48ef3e[_0x25d6('0x1f')](_0x39c6f5)[_0x25d6('0x20')](function(_0x3ff7ea){return _0x3ff7ea;});}return null;};}function removeEntity(_0x384187,_0x382796){return function(_0x19a30e){if(_0x19a30e){return _0x19a30e[_0x25d6('0x21')]()['then'](function(){_0x384187['status'](0xcc)[_0x25d6('0x16')]();});}};}function handleEntityNotFound(_0x4eaf69,_0x2b09d9){return function(_0x40a4eb){if(!_0x40a4eb){_0x4eaf69[_0x25d6('0x15')](0x194);}return _0x40a4eb;};}function handleError(_0x328743,_0x380261){_0x380261=_0x380261||0x1f4;return function(_0x4c8b4a){logger[_0x25d6('0x22')](_0x4c8b4a[_0x25d6('0x23')]);if(_0x4c8b4a[_0x25d6('0x24')]){delete _0x4c8b4a[_0x25d6('0x24')];}_0x328743[_0x25d6('0x17')](_0x380261)[_0x25d6('0x25')](_0x4c8b4a);};}exports[_0x25d6('0x26')]=function(_0x511aac,_0x4089af){var _0x5708db={},_0x5e6a0b={},_0x2b81da={'count':0x0,'rows':[]};var _0x1d0ce6=_[_0x25d6('0x27')](db[_0x25d6('0x28')][_0x25d6('0x29')],function(_0x3fe282){return{'name':_0x3fe282[_0x25d6('0x2a')],'type':_0x3fe282['type'][_0x25d6('0x2b')]};});_0x5e6a0b[_0x25d6('0x2c')]=_[_0x25d6('0x27')](_0x1d0ce6,_0x25d6('0x24'));_0x5e6a0b['query']=_[_0x25d6('0x2d')](_0x511aac[_0x25d6('0x2e')]);_0x5e6a0b[_0x25d6('0x2f')]=_[_0x25d6('0x30')](_0x5e6a0b[_0x25d6('0x2c')],_0x5e6a0b[_0x25d6('0x2e')]);_0x5708db['attributes']=_[_0x25d6('0x30')](_0x5e6a0b[_0x25d6('0x2c')],qs[_0x25d6('0x31')](_0x511aac[_0x25d6('0x2e')][_0x25d6('0x31')]));_0x5708db[_0x25d6('0x32')]=_0x5708db[_0x25d6('0x32')][_0x25d6('0x33')]?_0x5708db[_0x25d6('0x32')]:_0x5e6a0b[_0x25d6('0x2c')];if(!_0x511aac[_0x25d6('0x2e')][_0x25d6('0x34')]('nolimit')){_0x5708db['limit']=qs[_0x25d6('0x35')](_0x511aac[_0x25d6('0x2e')][_0x25d6('0x35')]);_0x5708db[_0x25d6('0x19')]=qs[_0x25d6('0x19')](_0x511aac[_0x25d6('0x2e')]['offset']);}_0x5708db['order']=qs[_0x25d6('0x36')](_0x511aac[_0x25d6('0x2e')]['sort']);_0x5708db['where']=qs[_0x25d6('0x2f')](_['pick'](_0x511aac[_0x25d6('0x2e')],_0x5e6a0b['filters']),_0x1d0ce6);if(_0x511aac['query'][_0x25d6('0x37')]){_0x5708db[_0x25d6('0x38')]=_[_0x25d6('0x39')](_0x5708db[_0x25d6('0x38')],{'$or':_[_0x25d6('0x27')](_0x1d0ce6,function(_0xe15375){if(_0xe15375[_0x25d6('0x3a')]!==_0x25d6('0x3b')){var _0x4c30b1={};_0x4c30b1[_0xe15375[_0x25d6('0x24')]]={'$like':'%'+_0x511aac[_0x25d6('0x2e')]['filter']+'%'};return _0x4c30b1;}})});}_0x5708db=_[_0x25d6('0x39')]({},_0x5708db,_0x511aac[_0x25d6('0x3c')]);var _0x194370={'where':_0x5708db[_0x25d6('0x38')]};return db[_0x25d6('0x28')]['count'](_0x194370)[_0x25d6('0x20')](function(_0x323dae){_0x2b81da[_0x25d6('0x1b')]=_0x323dae;if(_0x511aac[_0x25d6('0x2e')]['includeAll']){_0x5708db[_0x25d6('0x3d')]=[{'all':!![]}];}return db[_0x25d6('0x28')]['findAll'](_0x5708db);})['then'](function(_0x22d4d9){_0x2b81da[_0x25d6('0x3e')]=_0x22d4d9;return _0x2b81da;})[_0x25d6('0x20')](respondWithFilteredResult(_0x4089af,_0x5708db))['catch'](handleError(_0x4089af,null));};exports['show']=function(_0x32aa12,_0x33bd3b){var _0x420d19={'raw':![],'where':{'id':_0x32aa12[_0x25d6('0x3f')]['id']}},_0xe6a331={};_0xe6a331[_0x25d6('0x2c')]=_['keys'](db[_0x25d6('0x28')]['rawAttributes']);_0xe6a331[_0x25d6('0x2e')]=_[_0x25d6('0x2d')](_0x32aa12['query']);_0xe6a331[_0x25d6('0x2f')]=_[_0x25d6('0x30')](_0xe6a331[_0x25d6('0x2c')],_0xe6a331[_0x25d6('0x2e')]);_0x420d19[_0x25d6('0x32')]=_[_0x25d6('0x30')](_0xe6a331[_0x25d6('0x2c')],qs[_0x25d6('0x31')](_0x32aa12[_0x25d6('0x2e')][_0x25d6('0x31')]));_0x420d19[_0x25d6('0x32')]=_0x420d19[_0x25d6('0x32')][_0x25d6('0x33')]?_0x420d19[_0x25d6('0x32')]:_0xe6a331[_0x25d6('0x2c')];if(_0x32aa12[_0x25d6('0x2e')][_0x25d6('0x40')]){_0x420d19[_0x25d6('0x3d')]=[{'all':!![]}];}_0x420d19=_[_0x25d6('0x39')]({},_0x420d19,_0x32aa12[_0x25d6('0x3c')]);return db[_0x25d6('0x28')][_0x25d6('0x41')](_0x420d19)['then'](handleEntityNotFound(_0x33bd3b,null))[_0x25d6('0x20')](respondWithResult(_0x33bd3b,null))[_0x25d6('0x42')](handleError(_0x33bd3b,null));};exports[_0x25d6('0x43')]=function(_0x37f5a5,_0x1cdc09){return db['VtigerAccount'][_0x25d6('0x43')](_0x37f5a5[_0x25d6('0x44')],{})[_0x25d6('0x20')](respondWithResult(_0x1cdc09,0xc9))[_0x25d6('0x42')](handleError(_0x1cdc09,null));};exports[_0x25d6('0x1f')]=function(_0x3011cd,_0x53803d){if(_0x3011cd[_0x25d6('0x44')]['id']){delete _0x3011cd[_0x25d6('0x44')]['id'];}return db[_0x25d6('0x28')][_0x25d6('0x41')]({'where':{'id':_0x3011cd[_0x25d6('0x3f')]['id']}})[_0x25d6('0x20')](handleEntityNotFound(_0x53803d,null))[_0x25d6('0x20')](saveUpdates(_0x3011cd[_0x25d6('0x44')],null))[_0x25d6('0x20')](respondWithResult(_0x53803d,null))[_0x25d6('0x42')](handleError(_0x53803d,null));};exports[_0x25d6('0x21')]=function(_0x23d542,_0x5f1c7e){return db['VtigerAccount']['find']({'where':{'id':_0x23d542[_0x25d6('0x3f')]['id']}})['then'](handleEntityNotFound(_0x5f1c7e,null))[_0x25d6('0x20')](removeEntity(_0x5f1c7e,null))[_0x25d6('0x42')](handleError(_0x5f1c7e,null));};exports[_0x25d6('0x45')]=function(_0x2d4c2d,_0x25bd58,_0xa8cfb9){var _0x293443={};var _0x2ef4f6={};var _0x2ff50a;var _0x5529e5;return db['VtigerAccount'][_0x25d6('0x46')]({'where':{'id':_0x2d4c2d[_0x25d6('0x3f')]['id']}})[_0x25d6('0x20')](handleEntityNotFound(_0x25bd58,null))[_0x25d6('0x20')](function(_0x17a846){if(_0x17a846){_0x2ff50a=_0x17a846;_0x2ef4f6['model']=_['keys'](db[_0x25d6('0x47')][_0x25d6('0x29')]);_0x2ef4f6[_0x25d6('0x2e')]=_[_0x25d6('0x2d')](_0x2d4c2d[_0x25d6('0x2e')]);_0x2ef4f6[_0x25d6('0x2f')]=_[_0x25d6('0x30')](_0x2ef4f6[_0x25d6('0x2c')],_0x2ef4f6[_0x25d6('0x2e')]);_0x293443[_0x25d6('0x32')]=_[_0x25d6('0x30')](_0x2ef4f6['model'],qs[_0x25d6('0x31')](_0x2d4c2d[_0x25d6('0x2e')][_0x25d6('0x31')]));_0x293443['attributes']=_0x293443['attributes']['length']?_0x293443[_0x25d6('0x32')]:_0x2ef4f6[_0x25d6('0x2c')];_0x293443[_0x25d6('0x48')]=qs[_0x25d6('0x36')](_0x2d4c2d['query'][_0x25d6('0x36')]);_0x293443[_0x25d6('0x38')]=qs[_0x25d6('0x2f')](_['pick'](_0x2d4c2d[_0x25d6('0x2e')],_0x2ef4f6[_0x25d6('0x2f')]));if(_0x2d4c2d['query'][_0x25d6('0x37')]){_0x293443[_0x25d6('0x38')]=_[_0x25d6('0x39')](_0x293443[_0x25d6('0x38')],{'$or':_[_0x25d6('0x27')](_0x293443['attributes'],function(_0x3d8ca4){var _0x22c486={};_0x22c486[_0x3d8ca4]={'$like':'%'+_0x2d4c2d[_0x25d6('0x2e')]['filter']+'%'};return _0x22c486;})});}_0x293443=_[_0x25d6('0x39')]({},_0x293443,_0x2d4c2d['options']);return _0x2ff50a[_0x25d6('0x45')](_0x293443);}})[_0x25d6('0x20')](function(_0x19a493){if(_0x19a493){_0x5529e5=_0x19a493[_0x25d6('0x33')];if(!_0x2d4c2d[_0x25d6('0x2e')][_0x25d6('0x34')]('nolimit')){_0x293443['limit']=qs[_0x25d6('0x35')](_0x2d4c2d[_0x25d6('0x2e')][_0x25d6('0x35')]);_0x293443[_0x25d6('0x19')]=qs[_0x25d6('0x19')](_0x2d4c2d[_0x25d6('0x2e')]['offset']);}return _0x2ff50a[_0x25d6('0x45')](_0x293443);}})[_0x25d6('0x20')](function(_0x1afca6){if(_0x1afca6){return _0x1afca6?{'count':_0x5529e5,'rows':_0x1afca6}:null;}})['then'](respondWithResult(_0x25bd58,null))[_0x25d6('0x42')](handleError(_0x25bd58,null));};exports[_0x25d6('0x49')]=function(_0x2f2b51,_0x83ec91,_0x44b8b7){if(_0x2f2b51[_0x25d6('0x44')]['id']){delete _0x2f2b51[_0x25d6('0x44')]['id'];}return db[_0x25d6('0x28')][_0x25d6('0x46')]({'where':{'id':_0x2f2b51['params']['id']}})[_0x25d6('0x20')](handleEntityNotFound(_0x83ec91,null))[_0x25d6('0x20')](function(_0x5af10d){if(_0x5af10d){_0x2f2b51[_0x25d6('0x44')][_0x25d6('0x4a')]=_0x5af10d['id'];_0x2f2b51[_0x25d6('0x44')][_0x25d6('0x4b')]=integrations[_0x25d6('0x4c')](_0x2f2b51[_0x25d6('0x44')]['channel'],_0x2f2b51['body'][_0x25d6('0x3a')]);_0x2f2b51[_0x25d6('0x44')]['Descriptions']=integrations[_0x25d6('0x4d')](_0x2f2b51[_0x25d6('0x44')][_0x25d6('0x4e')],_0x2f2b51[_0x25d6('0x44')][_0x25d6('0x3a')]);return db[_0x25d6('0x47')]['create'](_0x2f2b51[_0x25d6('0x44')],{'include':[{'model':db[_0x25d6('0x4f')],'as':'Subjects'},{'model':db[_0x25d6('0x4f')],'as':_0x25d6('0x50')}]});}return null;})['then'](respondWithResult(_0x83ec91,null))[_0x25d6('0x42')](handleError(_0x83ec91,null));};var md5=require(_0x25d6('0x51'));exports[_0x25d6('0x52')]=function(_0x1b8b34,_0x499771,_0x2650d1){var _0x175c26=null;var _0x3f74a7=null;var _0x524a10=null;var _0x182e07=null;var _0x1c0e6d='';return db[_0x25d6('0x28')][_0x25d6('0x46')]({'where':{'id':_0x1b8b34[_0x25d6('0x3f')]['id']},'attributes':['id',_0x25d6('0x24'),'username','description',_0x25d6('0x53'),_0x25d6('0x54'),_0x25d6('0x55'),_0x25d6('0x56')]})[_0x25d6('0x20')](handleEntityNotFound(_0x499771,null))[_0x25d6('0x20')](function(_0xd6f58d){if(_0xd6f58d){_0x175c26=_0xd6f58d[_0x25d6('0x57')];_0x3f74a7=_0xd6f58d['accessKey'];_0x524a10=_0xd6f58d[_0x25d6('0x53')];_0x1c0e6d=_0xd6f58d[_0x25d6('0x54')];var _0x1daa78=_0x1c0e6d[_0x25d6('0x58')](-0x1);if(_0x1daa78==='/'){_0x1c0e6d=_0x1c0e6d[_0x25d6('0x59')](0x0,_0x1c0e6d[_0x25d6('0x5a')](_0x1daa78));}_0x182e07=util[_0x25d6('0x5b')](_0x25d6('0x5c'),_0x1c0e6d);var _0x62fb53={'method':_0x25d6('0x5d'),'uri':_0x182e07,'qs':{'operation':_0x25d6('0x5e'),'username':_0xd6f58d[_0x25d6('0x57')]},'json':!![]};return rp(_0x62fb53);}})[_0x25d6('0x20')](function(_0x46383c){if(_0x46383c[_0x25d6('0x5f')]){var _0x3dec65={'method':_0x25d6('0x60'),'uri':_0x182e07,'form':{'operation':_0x25d6('0x61'),'username':_0x175c26,'accessKey':md5(_0x46383c[_0x25d6('0x62')]['token']+_0x3f74a7)},'json':!![]};return rp(_0x3dec65);}})[_0x25d6('0x20')](function(_0x5b0107){if(_0x5b0107[_0x25d6('0x5f')]){var _0x4fe5cd={'method':_0x25d6('0x5d'),'uri':_0x182e07,'qs':{'operation':_0x25d6('0x63'),'username':_0x175c26,'sessionName':_0x5b0107[_0x25d6('0x62')]['sessionName'],'elementType':_0x524a10},'json':!![]};return rp(_0x4fe5cd);}})[_0x25d6('0x20')](function(_0x29aa39){if(_0x29aa39['success']){var _0x842b3d=[_0x25d6('0x64'),_0x25d6('0x65'),_0x25d6('0x66')];_[_0x25d6('0x67')](_0x29aa39['result'][_0x25d6('0x31')],function(_0x5164de){return _0x842b3d[_0x25d6('0x68')](_0x5164de[_0x25d6('0x3a')][_0x25d6('0x24')]);});_[_0x25d6('0x67')](_0x29aa39['result'][_0x25d6('0x31')],function(_0x3c325b){return _0x3c325b[_0x25d6('0x69')]===_0x25d6('0x6a');});return{'count':_0x29aa39[_0x25d6('0x62')][_0x25d6('0x31')]['length'],'rows':_[_0x25d6('0x27')](_0x29aa39[_0x25d6('0x62')]['fields'],function(_0x30c1cc){return{'id':_0x30c1cc[_0x25d6('0x24')],'name':_0x30c1cc[_0x25d6('0x6b')],'custom':_[_0x25d6('0x6c')](_0x30c1cc[_0x25d6('0x24')],_0x25d6('0x6d'))?!![]:![],'options':_0x30c1cc[_0x25d6('0x3a')][_0x25d6('0x24')]===_0x25d6('0x6e')&&_0x30c1cc[_0x25d6('0x3a')][_0x25d6('0x6f')]['length']>0x0?_[_0x25d6('0x27')](_0x30c1cc['type']['picklistValues'],function(_0x1f33f9){return{'name':_0x1f33f9[_0x25d6('0x6b')],'value':_0x1f33f9[_0x25d6('0x70')]};}):[]};})};}})['then'](respondWithResult(_0x499771,null))[_0x25d6('0x42')](function(_0x31de26){console[_0x25d6('0x71')](_0x25d6('0x72')+_0x31de26);var _0x2c89f8=_0x1b8b34[_0x25d6('0x2e')][_0x25d6('0x73')]?0x1f4:_0x31de26['statusCode']||0x1f4;logger[_0x25d6('0x22')](_0x25d6('0x74'),_0x25d6('0x52'),_0x2c89f8,JSON[_0x25d6('0x75')](_0x31de26));delete _0x31de26['name'];if(_0x2c89f8===0x191){_0x2c89f8=0x190;}_0x499771['status'](_0x2c89f8)[_0x25d6('0x25')](_0x1b8b34['query'][_0x25d6('0x73')]?{'message':_0x25d6('0x76'),'statusCode':_0x31de26[_0x25d6('0x77')]}:_0x31de26);});};
\ No newline at end of file
+var _0xef30=['include','findAll','rows','catch','show','params','keys','fields','find','create','body','findOne','getConfigurations','AccountId','channel','Descriptions','getDescriptions','VtigerConfiguration','VtigerField','Subjects','md5','getFields','username','moduleName','remoteUri','accessKey','slice','lastIndexOf','format','%s/webservice.php','getchallenge','success','login','result','token','describe','sessionName','autogenerated','owner','remove','includes','editable','false','label','startsWith','cf_','picklistValues','value','log','vTiger\x20error:\x20','test','statusCode','error','getFields,\x20%s,\x20%s,\x20%s','stringify','Wrong\x20credentials','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','to-csv','ejs','fs-extra','lodash','squel','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/utils','../../config/environment','../../config/license/util','../../components/integrations/configuration','sendStatus','end','status','json','offset','undefined','count','limit','set','Content-Range','apply','reject','save','update','then','destroy','stack','send','index','VtigerAccount','rawAttributes','fieldName','type','key','model','map','name','query','filters','attributes','intersection','length','hasOwnProperty','nolimit','order','sort','where','pick','VIRTUAL','filter','merge','options','includeAll'];(function(_0x36d9ac,_0x314606){var _0x281977=function(_0x200ae4){while(--_0x200ae4){_0x36d9ac['push'](_0x36d9ac['shift']());}};_0x281977(++_0x314606);}(_0xef30,0xb6));var _0x0ef3=function(_0x5447fd,_0x52a6b5){_0x5447fd=_0x5447fd-0x0;var _0x15b28a=_0xef30[_0x5447fd];return _0x15b28a;};'use strict';var emlformat=require(_0x0ef3('0x0'));var rimraf=require(_0x0ef3('0x1'));var zipdir=require(_0x0ef3('0x2'));var jsonpatch=require(_0x0ef3('0x3'));var rp=require(_0x0ef3('0x4'));var moment=require(_0x0ef3('0x5'));var BPromise=require(_0x0ef3('0x6'));var Mustache=require(_0x0ef3('0x7'));var util=require(_0x0ef3('0x8'));var path=require(_0x0ef3('0x9'));var sox=require('sox');var csv=require(_0x0ef3('0xa'));var ejs=require(_0x0ef3('0xb'));var fs=require('fs');var fs_extra=require(_0x0ef3('0xc'));var _=require(_0x0ef3('0xd'));var squel=require(_0x0ef3('0xe'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0x0ef3('0xf'));var toCsv=require('to-csv');var querystring=require(_0x0ef3('0x10'));var Papa=require(_0x0ef3('0x11'));var Redis=require(_0x0ef3('0x12'));var authService=require(_0x0ef3('0x13'));var qs=require(_0x0ef3('0x14'));var as=require(_0x0ef3('0x15'));var hardwareService=require(_0x0ef3('0x16'));var logger=require('../../config/logger')('api');var utils=require(_0x0ef3('0x17'));var config=require(_0x0ef3('0x18'));var licenseUtil=require(_0x0ef3('0x19'));var db=require('../../mysqldb')['db'];var integrations=require(_0x0ef3('0x1a'));function respondWithStatusCode(_0x5d5545,_0x52020e){_0x52020e=_0x52020e||0xcc;return function(_0x76985e){if(_0x76985e){return _0x5d5545[_0x0ef3('0x1b')](_0x52020e);}return _0x5d5545['status'](_0x52020e)[_0x0ef3('0x1c')]();};}function respondWithResult(_0x4af50d,_0x31bbd1){_0x31bbd1=_0x31bbd1||0xc8;return function(_0x23242e){if(_0x23242e){return _0x4af50d[_0x0ef3('0x1d')](_0x31bbd1)[_0x0ef3('0x1e')](_0x23242e);}};}function respondWithFilteredResult(_0x4f69bf,_0x12a5af){return function(_0x42aeb4){if(_0x42aeb4){var _0x1da77a=typeof _0x12a5af[_0x0ef3('0x1f')]===_0x0ef3('0x20')&&typeof _0x12a5af['limit']===_0x0ef3('0x20');var _0x5d6767=_0x42aeb4[_0x0ef3('0x21')];var _0x21c71b=_0x1da77a?0x0:_0x12a5af[_0x0ef3('0x1f')];var _0x2e1406=_0x1da77a?_0x42aeb4[_0x0ef3('0x21')]:_0x12a5af[_0x0ef3('0x1f')]+_0x12a5af[_0x0ef3('0x22')];var _0x10259f;if(_0x2e1406>=_0x5d6767){_0x2e1406=_0x5d6767;_0x10259f=0xc8;}else{_0x10259f=0xce;}_0x4f69bf[_0x0ef3('0x1d')](_0x10259f);return _0x4f69bf[_0x0ef3('0x23')](_0x0ef3('0x24'),_0x21c71b+'-'+_0x2e1406+'/'+_0x5d6767)[_0x0ef3('0x1e')](_0x42aeb4);}return null;};}function patchUpdates(_0x2ebbbd){return function(_0x4c25c6){try{jsonpatch[_0x0ef3('0x25')](_0x4c25c6,_0x2ebbbd,!![]);}catch(_0xfbfc9e){return BPromise[_0x0ef3('0x26')](_0xfbfc9e);}return _0x4c25c6[_0x0ef3('0x27')]();};}function saveUpdates(_0x1c9eea,_0x3134b8){return function(_0x4ec06a){if(_0x4ec06a){return _0x4ec06a[_0x0ef3('0x28')](_0x1c9eea)[_0x0ef3('0x29')](function(_0x443c66){return _0x443c66;});}return null;};}function removeEntity(_0x18083e,_0x92c08){return function(_0x3a0308){if(_0x3a0308){return _0x3a0308[_0x0ef3('0x2a')]()[_0x0ef3('0x29')](function(){_0x18083e[_0x0ef3('0x1d')](0xcc)[_0x0ef3('0x1c')]();});}};}function handleEntityNotFound(_0x4a23eb,_0x15c2df){return function(_0x32e362){if(!_0x32e362){_0x4a23eb[_0x0ef3('0x1b')](0x194);}return _0x32e362;};}function handleError(_0x514c31,_0x23751d){_0x23751d=_0x23751d||0x1f4;return function(_0x3f1523){logger['error'](_0x3f1523[_0x0ef3('0x2b')]);if(_0x3f1523['name']){delete _0x3f1523['name'];}_0x514c31[_0x0ef3('0x1d')](_0x23751d)[_0x0ef3('0x2c')](_0x3f1523);};}exports[_0x0ef3('0x2d')]=function(_0x69ce92,_0x2a6b6e){var _0x1c11d5={},_0x47b020={},_0x3fb8e5={'count':0x0,'rows':[]};var _0x3d6e14=_['map'](db[_0x0ef3('0x2e')][_0x0ef3('0x2f')],function(_0x1189cb){return{'name':_0x1189cb[_0x0ef3('0x30')],'type':_0x1189cb[_0x0ef3('0x31')][_0x0ef3('0x32')]};});_0x47b020[_0x0ef3('0x33')]=_[_0x0ef3('0x34')](_0x3d6e14,_0x0ef3('0x35'));_0x47b020[_0x0ef3('0x36')]=_['keys'](_0x69ce92['query']);_0x47b020[_0x0ef3('0x37')]=_['intersection'](_0x47b020['model'],_0x47b020['query']);_0x1c11d5[_0x0ef3('0x38')]=_[_0x0ef3('0x39')](_0x47b020[_0x0ef3('0x33')],qs['fields'](_0x69ce92[_0x0ef3('0x36')]['fields']));_0x1c11d5[_0x0ef3('0x38')]=_0x1c11d5[_0x0ef3('0x38')][_0x0ef3('0x3a')]?_0x1c11d5[_0x0ef3('0x38')]:_0x47b020[_0x0ef3('0x33')];if(!_0x69ce92[_0x0ef3('0x36')][_0x0ef3('0x3b')](_0x0ef3('0x3c'))){_0x1c11d5['limit']=qs[_0x0ef3('0x22')](_0x69ce92[_0x0ef3('0x36')][_0x0ef3('0x22')]);_0x1c11d5['offset']=qs[_0x0ef3('0x1f')](_0x69ce92[_0x0ef3('0x36')]['offset']);}_0x1c11d5[_0x0ef3('0x3d')]=qs[_0x0ef3('0x3e')](_0x69ce92[_0x0ef3('0x36')][_0x0ef3('0x3e')]);_0x1c11d5[_0x0ef3('0x3f')]=qs[_0x0ef3('0x37')](_[_0x0ef3('0x40')](_0x69ce92[_0x0ef3('0x36')],_0x47b020['filters']),_0x3d6e14);if(_0x69ce92['query']['filter']){_0x1c11d5[_0x0ef3('0x3f')]=_['merge'](_0x1c11d5[_0x0ef3('0x3f')],{'$or':_[_0x0ef3('0x34')](_0x3d6e14,function(_0x104327){if(_0x104327[_0x0ef3('0x31')]!==_0x0ef3('0x41')){var _0x193452={};_0x193452[_0x104327[_0x0ef3('0x35')]]={'$like':'%'+_0x69ce92[_0x0ef3('0x36')][_0x0ef3('0x42')]+'%'};return _0x193452;}})});}_0x1c11d5=_[_0x0ef3('0x43')]({},_0x1c11d5,_0x69ce92[_0x0ef3('0x44')]);var _0x1287ab={'where':_0x1c11d5[_0x0ef3('0x3f')]};return db[_0x0ef3('0x2e')][_0x0ef3('0x21')](_0x1287ab)[_0x0ef3('0x29')](function(_0x5a6c1f){_0x3fb8e5[_0x0ef3('0x21')]=_0x5a6c1f;if(_0x69ce92[_0x0ef3('0x36')][_0x0ef3('0x45')]){_0x1c11d5[_0x0ef3('0x46')]=[{'all':!![]}];}return db['VtigerAccount'][_0x0ef3('0x47')](_0x1c11d5);})[_0x0ef3('0x29')](function(_0x3cf17f){_0x3fb8e5[_0x0ef3('0x48')]=_0x3cf17f;return _0x3fb8e5;})['then'](respondWithFilteredResult(_0x2a6b6e,_0x1c11d5))[_0x0ef3('0x49')](handleError(_0x2a6b6e,null));};exports[_0x0ef3('0x4a')]=function(_0x472cf8,_0x51d1a1){var _0x26b341={'raw':![],'where':{'id':_0x472cf8[_0x0ef3('0x4b')]['id']}},_0x1e5b87={};_0x1e5b87[_0x0ef3('0x33')]=_['keys'](db[_0x0ef3('0x2e')][_0x0ef3('0x2f')]);_0x1e5b87[_0x0ef3('0x36')]=_[_0x0ef3('0x4c')](_0x472cf8[_0x0ef3('0x36')]);_0x1e5b87['filters']=_[_0x0ef3('0x39')](_0x1e5b87[_0x0ef3('0x33')],_0x1e5b87[_0x0ef3('0x36')]);_0x26b341[_0x0ef3('0x38')]=_['intersection'](_0x1e5b87[_0x0ef3('0x33')],qs[_0x0ef3('0x4d')](_0x472cf8[_0x0ef3('0x36')][_0x0ef3('0x4d')]));_0x26b341[_0x0ef3('0x38')]=_0x26b341['attributes'][_0x0ef3('0x3a')]?_0x26b341[_0x0ef3('0x38')]:_0x1e5b87[_0x0ef3('0x33')];if(_0x472cf8[_0x0ef3('0x36')][_0x0ef3('0x45')]){_0x26b341[_0x0ef3('0x46')]=[{'all':!![]}];}_0x26b341=_[_0x0ef3('0x43')]({},_0x26b341,_0x472cf8[_0x0ef3('0x44')]);return db[_0x0ef3('0x2e')][_0x0ef3('0x4e')](_0x26b341)['then'](handleEntityNotFound(_0x51d1a1,null))[_0x0ef3('0x29')](respondWithResult(_0x51d1a1,null))[_0x0ef3('0x49')](handleError(_0x51d1a1,null));};exports[_0x0ef3('0x4f')]=function(_0x4619c8,_0x15720b){return db['VtigerAccount'][_0x0ef3('0x4f')](_0x4619c8['body'],{})[_0x0ef3('0x29')](respondWithResult(_0x15720b,0xc9))['catch'](handleError(_0x15720b,null));};exports['update']=function(_0x2a1f00,_0x5e4d83){if(_0x2a1f00['body']['id']){delete _0x2a1f00[_0x0ef3('0x50')]['id'];}return db[_0x0ef3('0x2e')][_0x0ef3('0x4e')]({'where':{'id':_0x2a1f00[_0x0ef3('0x4b')]['id']}})[_0x0ef3('0x29')](handleEntityNotFound(_0x5e4d83,null))[_0x0ef3('0x29')](saveUpdates(_0x2a1f00[_0x0ef3('0x50')],null))[_0x0ef3('0x29')](respondWithResult(_0x5e4d83,null))[_0x0ef3('0x49')](handleError(_0x5e4d83,null));};exports[_0x0ef3('0x2a')]=function(_0x40164d,_0x3eca66){return db[_0x0ef3('0x2e')][_0x0ef3('0x4e')]({'where':{'id':_0x40164d[_0x0ef3('0x4b')]['id']}})[_0x0ef3('0x29')](handleEntityNotFound(_0x3eca66,null))[_0x0ef3('0x29')](removeEntity(_0x3eca66,null))['catch'](handleError(_0x3eca66,null));};exports['getConfigurations']=function(_0x4d56fd,_0x1e02bd,_0x289077){var _0x3957b7={};var _0x151928={};var _0x32448b;var _0x4f6ea1;return db['VtigerAccount'][_0x0ef3('0x51')]({'where':{'id':_0x4d56fd[_0x0ef3('0x4b')]['id']}})['then'](handleEntityNotFound(_0x1e02bd,null))[_0x0ef3('0x29')](function(_0x1894ce){if(_0x1894ce){_0x32448b=_0x1894ce;_0x151928['model']=_[_0x0ef3('0x4c')](db['VtigerConfiguration']['rawAttributes']);_0x151928[_0x0ef3('0x36')]=_[_0x0ef3('0x4c')](_0x4d56fd['query']);_0x151928[_0x0ef3('0x37')]=_[_0x0ef3('0x39')](_0x151928[_0x0ef3('0x33')],_0x151928['query']);_0x3957b7[_0x0ef3('0x38')]=_[_0x0ef3('0x39')](_0x151928[_0x0ef3('0x33')],qs[_0x0ef3('0x4d')](_0x4d56fd['query'][_0x0ef3('0x4d')]));_0x3957b7[_0x0ef3('0x38')]=_0x3957b7[_0x0ef3('0x38')]['length']?_0x3957b7['attributes']:_0x151928[_0x0ef3('0x33')];_0x3957b7[_0x0ef3('0x3d')]=qs[_0x0ef3('0x3e')](_0x4d56fd[_0x0ef3('0x36')]['sort']);_0x3957b7['where']=qs[_0x0ef3('0x37')](_[_0x0ef3('0x40')](_0x4d56fd[_0x0ef3('0x36')],_0x151928[_0x0ef3('0x37')]));if(_0x4d56fd[_0x0ef3('0x36')][_0x0ef3('0x42')]){_0x3957b7[_0x0ef3('0x3f')]=_[_0x0ef3('0x43')](_0x3957b7[_0x0ef3('0x3f')],{'$or':_[_0x0ef3('0x34')](_0x3957b7[_0x0ef3('0x38')],function(_0x9de291){var _0x48fdd9={};_0x48fdd9[_0x9de291]={'$like':'%'+_0x4d56fd[_0x0ef3('0x36')][_0x0ef3('0x42')]+'%'};return _0x48fdd9;})});}_0x3957b7=_['merge']({},_0x3957b7,_0x4d56fd[_0x0ef3('0x44')]);return _0x32448b[_0x0ef3('0x52')](_0x3957b7);}})['then'](function(_0x1c1b2f){if(_0x1c1b2f){_0x4f6ea1=_0x1c1b2f[_0x0ef3('0x3a')];if(!_0x4d56fd[_0x0ef3('0x36')][_0x0ef3('0x3b')](_0x0ef3('0x3c'))){_0x3957b7[_0x0ef3('0x22')]=qs['limit'](_0x4d56fd['query'][_0x0ef3('0x22')]);_0x3957b7['offset']=qs[_0x0ef3('0x1f')](_0x4d56fd[_0x0ef3('0x36')][_0x0ef3('0x1f')]);}return _0x32448b[_0x0ef3('0x52')](_0x3957b7);}})[_0x0ef3('0x29')](function(_0x10ef23){if(_0x10ef23){return _0x10ef23?{'count':_0x4f6ea1,'rows':_0x10ef23}:null;}})[_0x0ef3('0x29')](respondWithResult(_0x1e02bd,null))[_0x0ef3('0x49')](handleError(_0x1e02bd,null));};exports['addConfiguration']=function(_0x103e87,_0x2c0506,_0x2b807e){if(_0x103e87['body']['id']){delete _0x103e87[_0x0ef3('0x50')]['id'];}return db[_0x0ef3('0x2e')][_0x0ef3('0x51')]({'where':{'id':_0x103e87['params']['id']}})[_0x0ef3('0x29')](handleEntityNotFound(_0x2c0506,null))[_0x0ef3('0x29')](function(_0x40d01c){if(_0x40d01c){_0x103e87[_0x0ef3('0x50')][_0x0ef3('0x53')]=_0x40d01c['id'];_0x103e87['body']['Subjects']=integrations['getSubjects'](_0x103e87[_0x0ef3('0x50')][_0x0ef3('0x54')],_0x103e87['body'][_0x0ef3('0x31')]);_0x103e87['body'][_0x0ef3('0x55')]=integrations[_0x0ef3('0x56')](_0x103e87[_0x0ef3('0x50')][_0x0ef3('0x54')],_0x103e87[_0x0ef3('0x50')]['type']);return db[_0x0ef3('0x57')][_0x0ef3('0x4f')](_0x103e87[_0x0ef3('0x50')],{'include':[{'model':db[_0x0ef3('0x58')],'as':_0x0ef3('0x59')},{'model':db[_0x0ef3('0x58')],'as':_0x0ef3('0x55')}]});}return null;})[_0x0ef3('0x29')](respondWithResult(_0x2c0506,null))[_0x0ef3('0x49')](handleError(_0x2c0506,null));};var md5=require(_0x0ef3('0x5a'));exports[_0x0ef3('0x5b')]=function(_0x161699,_0x57011c,_0x1a7d19){var _0x1afbda=null;var _0xbee12=null;var _0x5d90fe=null;var _0x50413f=null;var _0x18aa29='';return db[_0x0ef3('0x2e')]['findOne']({'where':{'id':_0x161699[_0x0ef3('0x4b')]['id']},'attributes':['id','name',_0x0ef3('0x5c'),'description',_0x0ef3('0x5d'),_0x0ef3('0x5e'),'serverUrl','accessKey']})['then'](handleEntityNotFound(_0x57011c,null))['then'](function(_0x289e4a){if(_0x289e4a){_0x1afbda=_0x289e4a[_0x0ef3('0x5c')];_0xbee12=_0x289e4a[_0x0ef3('0x5f')];_0x5d90fe=_0x289e4a['moduleName'];_0x18aa29=_0x289e4a[_0x0ef3('0x5e')];var _0x3ac5c6=_0x18aa29[_0x0ef3('0x60')](-0x1);if(_0x3ac5c6==='/'){_0x18aa29=_0x18aa29['substring'](0x0,_0x18aa29[_0x0ef3('0x61')](_0x3ac5c6));}_0x50413f=util[_0x0ef3('0x62')](_0x0ef3('0x63'),_0x18aa29);var _0x415864={'method':'GET','uri':_0x50413f,'qs':{'operation':_0x0ef3('0x64'),'username':_0x289e4a[_0x0ef3('0x5c')]},'json':!![]};return rp(_0x415864);}})[_0x0ef3('0x29')](function(_0x411715){if(_0x411715[_0x0ef3('0x65')]){var _0x24f909={'method':'POST','uri':_0x50413f,'form':{'operation':_0x0ef3('0x66'),'username':_0x1afbda,'accessKey':md5(_0x411715[_0x0ef3('0x67')][_0x0ef3('0x68')]+_0xbee12)},'json':!![]};return rp(_0x24f909);}})['then'](function(_0x2ac852){if(_0x2ac852['success']){var _0xbb53e3={'method':'GET','uri':_0x50413f,'qs':{'operation':_0x0ef3('0x69'),'username':_0x1afbda,'sessionName':_0x2ac852[_0x0ef3('0x67')][_0x0ef3('0x6a')],'elementType':_0x5d90fe},'json':!![]};return rp(_0xbb53e3);}})[_0x0ef3('0x29')](function(_0x4741e8){if(_0x4741e8[_0x0ef3('0x65')]){var _0x5a110d=[_0x0ef3('0x6b'),'reference',_0x0ef3('0x6c')];_[_0x0ef3('0x6d')](_0x4741e8['result'][_0x0ef3('0x4d')],function(_0x346147){return _0x5a110d[_0x0ef3('0x6e')](_0x346147[_0x0ef3('0x31')][_0x0ef3('0x35')]);});_[_0x0ef3('0x6d')](_0x4741e8[_0x0ef3('0x67')][_0x0ef3('0x4d')],function(_0x4b05a1){return _0x4b05a1[_0x0ef3('0x6f')]===_0x0ef3('0x70');});return{'count':_0x4741e8['result'][_0x0ef3('0x4d')]['length'],'rows':_['map'](_0x4741e8[_0x0ef3('0x67')][_0x0ef3('0x4d')],function(_0x3ad129){return{'id':_0x3ad129['name'],'name':_0x3ad129[_0x0ef3('0x71')],'custom':_[_0x0ef3('0x72')](_0x3ad129[_0x0ef3('0x35')],_0x0ef3('0x73'))?!![]:![],'options':_0x3ad129['type'][_0x0ef3('0x35')]==='picklist'&&_0x3ad129['type'][_0x0ef3('0x74')][_0x0ef3('0x3a')]>0x0?_[_0x0ef3('0x34')](_0x3ad129[_0x0ef3('0x31')][_0x0ef3('0x74')],function(_0x3c3a54){return{'name':_0x3c3a54[_0x0ef3('0x71')],'value':_0x3c3a54[_0x0ef3('0x75')]};}):[]};})};}})[_0x0ef3('0x29')](respondWithResult(_0x57011c,null))[_0x0ef3('0x49')](function(_0xf56078){console[_0x0ef3('0x76')](_0x0ef3('0x77')+_0xf56078);var _0x5d8cd2=_0x161699[_0x0ef3('0x36')][_0x0ef3('0x78')]?0x1f4:_0xf56078[_0x0ef3('0x79')]||0x1f4;logger[_0x0ef3('0x7a')](_0x0ef3('0x7b'),_0x0ef3('0x5b'),_0x5d8cd2,JSON[_0x0ef3('0x7c')](_0xf56078));delete _0xf56078['name'];if(_0x5d8cd2===0x191){_0x5d8cd2=0x190;}_0x57011c[_0x0ef3('0x1d')](_0x5d8cd2)[_0x0ef3('0x2c')](_0x161699[_0x0ef3('0x36')][_0x0ef3('0x78')]?{'message':_0x0ef3('0x7d'),'statusCode':_0xf56078['statusCode']}:_0xf56078);});};
\ No newline at end of file