Built motion from commit 85f716e9.|2.6.8
[motion2.git] / server / api / intVtigerAccount / intVtigerAccount.controller.js
index ff2232c..6021bfe 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x9269=['find','create','body','getConfigurations','VtigerConfiguration','AccountId','Subjects','getSubjects','channel','Descriptions','getDescriptions','VtigerField','md5','getFields','username','description','moduleName','remoteUri','serverUrl','accessKey','slice','substring','lastIndexOf','format','getchallenge','login','result','token','success','GET','describe','sessionName','autogenerated','owner','remove','label','cf_','picklist','picklistValues','value','vTiger\x20error:\x20','test','statusCode','stringify','Wrong\x20credentials','eml-format','zip-dir','fast-json-patch','moment','bluebird','mustache','util','to-csv','ejs','fs-extra','lodash','squel','crypto','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../components/integrations/configuration','sendStatus','status','end','json','undefined','offset','count','limit','set','Content-Range','reject','save','update','then','destroy','error','name','send','index','map','VtigerAccount','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','options','includeAll','findAll','catch','show','params','rawAttributes','include'];(function(_0x3b3f4f,_0x403216){var _0x174dbe=function(_0x30e333){while(--_0x30e333){_0x3b3f4f['push'](_0x3b3f4f['shift']());}};_0x174dbe(++_0x403216);}(_0x9269,0x18f));var _0x9926=function(_0x30f87a,_0x2cce5a){_0x30f87a=_0x30f87a-0x0;var _0x3a8efc=_0x9269[_0x30f87a];return _0x3a8efc;};'use strict';var emlformat=require(_0x9926('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x9926('0x1'));var jsonpatch=require(_0x9926('0x2'));var rp=require('request-promise');var moment=require(_0x9926('0x3'));var BPromise=require(_0x9926('0x4'));var Mustache=require(_0x9926('0x5'));var util=require(_0x9926('0x6'));var path=require('path');var sox=require('sox');var csv=require(_0x9926('0x7'));var ejs=require(_0x9926('0x8'));var fs=require('fs');var fs_extra=require(_0x9926('0x9'));var _=require(_0x9926('0xa'));var squel=require(_0x9926('0xb'));var crypto=require(_0x9926('0xc'));var jsforce=require('jsforce');var deskjs=require(_0x9926('0xd'));var toCsv=require(_0x9926('0x7'));var querystring=require(_0x9926('0xe'));var Papa=require('papaparse');var Redis=require(_0x9926('0xf'));var authService=require(_0x9926('0x10'));var qs=require(_0x9926('0x11'));var as=require(_0x9926('0x12'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x9926('0x13'))(_0x9926('0x14'));var utils=require(_0x9926('0x15'));var config=require(_0x9926('0x16'));var licenseUtil=require(_0x9926('0x17'));var db=require('../../mysqldb')['db'];var integrations=require(_0x9926('0x18'));function respondWithStatusCode(_0x1dcb9b,_0x28e39d){_0x28e39d=_0x28e39d||0xcc;return function(_0x519b5a){if(_0x519b5a){return _0x1dcb9b[_0x9926('0x19')](_0x28e39d);}return _0x1dcb9b[_0x9926('0x1a')](_0x28e39d)[_0x9926('0x1b')]();};}function respondWithResult(_0x32b15b,_0x2c3c67){_0x2c3c67=_0x2c3c67||0xc8;return function(_0x1bcd79){if(_0x1bcd79){return _0x32b15b[_0x9926('0x1a')](_0x2c3c67)[_0x9926('0x1c')](_0x1bcd79);}};}function respondWithFilteredResult(_0x2522bb,_0x2394df){return function(_0x1e6b4f){if(_0x1e6b4f){var _0x1ed780=typeof _0x2394df['offset']===_0x9926('0x1d')&&typeof _0x2394df['limit']===_0x9926('0x1d');var _0x344e9a=_0x1e6b4f['count'];var _0x32519c=_0x1ed780?0x0:_0x2394df[_0x9926('0x1e')];var _0x5d2fed=_0x1ed780?_0x1e6b4f[_0x9926('0x1f')]:_0x2394df[_0x9926('0x1e')]+_0x2394df[_0x9926('0x20')];var _0x218193;if(_0x5d2fed>=_0x344e9a){_0x5d2fed=_0x344e9a;_0x218193=0xc8;}else{_0x218193=0xce;}_0x2522bb[_0x9926('0x1a')](_0x218193);return _0x2522bb[_0x9926('0x21')](_0x9926('0x22'),_0x32519c+'-'+_0x5d2fed+'/'+_0x344e9a)[_0x9926('0x1c')](_0x1e6b4f);}return null;};}function patchUpdates(_0x2a7005){return function(_0x3949f0){try{jsonpatch['apply'](_0x3949f0,_0x2a7005,!![]);}catch(_0x4258b5){return BPromise[_0x9926('0x23')](_0x4258b5);}return _0x3949f0[_0x9926('0x24')]();};}function saveUpdates(_0x236ac3,_0x5a168d){return function(_0x2985e9){if(_0x2985e9){return _0x2985e9[_0x9926('0x25')](_0x236ac3)[_0x9926('0x26')](function(_0x488713){return _0x488713;});}return null;};}function removeEntity(_0x4f0f9a,_0x4309ab){return function(_0x358251){if(_0x358251){return _0x358251[_0x9926('0x27')]()[_0x9926('0x26')](function(){_0x4f0f9a[_0x9926('0x1a')](0xcc)[_0x9926('0x1b')]();});}};}function handleEntityNotFound(_0x3ddb4e,_0x54e064){return function(_0x151687){if(!_0x151687){_0x3ddb4e[_0x9926('0x19')](0x194);}return _0x151687;};}function handleError(_0x568e0a,_0xdf1412){_0xdf1412=_0xdf1412||0x1f4;return function(_0x369c0a){logger[_0x9926('0x28')](_0x369c0a['stack']);if(_0x369c0a[_0x9926('0x29')]){delete _0x369c0a['name'];}_0x568e0a['status'](_0xdf1412)[_0x9926('0x2a')](_0x369c0a);};}exports[_0x9926('0x2b')]=function(_0x550e29,_0x97a489){var _0x2c30cb={},_0x1dd0ab={},_0x233441={'count':0x0,'rows':[]};var _0x480143=_[_0x9926('0x2c')](db[_0x9926('0x2d')]['rawAttributes'],function(_0x5c302a){return{'name':_0x5c302a[_0x9926('0x2e')],'type':_0x5c302a[_0x9926('0x2f')][_0x9926('0x30')]};});_0x1dd0ab[_0x9926('0x31')]=_['map'](_0x480143,_0x9926('0x29'));_0x1dd0ab[_0x9926('0x32')]=_[_0x9926('0x33')](_0x550e29[_0x9926('0x32')]);_0x1dd0ab[_0x9926('0x34')]=_[_0x9926('0x35')](_0x1dd0ab['model'],_0x1dd0ab[_0x9926('0x32')]);_0x2c30cb[_0x9926('0x36')]=_['intersection'](_0x1dd0ab[_0x9926('0x31')],qs[_0x9926('0x37')](_0x550e29[_0x9926('0x32')][_0x9926('0x37')]));_0x2c30cb[_0x9926('0x36')]=_0x2c30cb[_0x9926('0x36')][_0x9926('0x38')]?_0x2c30cb[_0x9926('0x36')]:_0x1dd0ab[_0x9926('0x31')];if(!_0x550e29['query'][_0x9926('0x39')](_0x9926('0x3a'))){_0x2c30cb['limit']=qs[_0x9926('0x20')](_0x550e29[_0x9926('0x32')]['limit']);_0x2c30cb[_0x9926('0x1e')]=qs[_0x9926('0x1e')](_0x550e29[_0x9926('0x32')][_0x9926('0x1e')]);}_0x2c30cb[_0x9926('0x3b')]=qs[_0x9926('0x3c')](_0x550e29[_0x9926('0x32')][_0x9926('0x3c')]);_0x2c30cb[_0x9926('0x3d')]=qs[_0x9926('0x34')](_[_0x9926('0x3e')](_0x550e29[_0x9926('0x32')],_0x1dd0ab[_0x9926('0x34')]),_0x480143);if(_0x550e29['query'][_0x9926('0x3f')]){_0x2c30cb['where']=_[_0x9926('0x40')](_0x2c30cb[_0x9926('0x3d')],{'$or':_[_0x9926('0x2c')](_0x480143,function(_0x10e975){if(_0x10e975[_0x9926('0x2f')]!=='VIRTUAL'){var _0x560a8d={};_0x560a8d[_0x10e975['name']]={'$like':'%'+_0x550e29[_0x9926('0x32')][_0x9926('0x3f')]+'%'};return _0x560a8d;}})});}_0x2c30cb=_[_0x9926('0x40')]({},_0x2c30cb,_0x550e29[_0x9926('0x41')]);var _0x284604={'where':_0x2c30cb[_0x9926('0x3d')]};return db['VtigerAccount'][_0x9926('0x1f')](_0x284604)['then'](function(_0x908b46){_0x233441[_0x9926('0x1f')]=_0x908b46;if(_0x550e29[_0x9926('0x32')][_0x9926('0x42')]){_0x2c30cb['include']=[{'all':!![]}];}return db['VtigerAccount'][_0x9926('0x43')](_0x2c30cb);})[_0x9926('0x26')](function(_0x24dbf4){_0x233441['rows']=_0x24dbf4;return _0x233441;})['then'](respondWithFilteredResult(_0x97a489,_0x2c30cb))[_0x9926('0x44')](handleError(_0x97a489,null));};exports[_0x9926('0x45')]=function(_0x19f8e1,_0x56b1ed){var _0x194a13={'raw':![],'where':{'id':_0x19f8e1[_0x9926('0x46')]['id']}},_0xfc6f71={};_0xfc6f71[_0x9926('0x31')]=_[_0x9926('0x33')](db[_0x9926('0x2d')][_0x9926('0x47')]);_0xfc6f71[_0x9926('0x32')]=_[_0x9926('0x33')](_0x19f8e1[_0x9926('0x32')]);_0xfc6f71['filters']=_[_0x9926('0x35')](_0xfc6f71[_0x9926('0x31')],_0xfc6f71['query']);_0x194a13[_0x9926('0x36')]=_['intersection'](_0xfc6f71['model'],qs[_0x9926('0x37')](_0x19f8e1[_0x9926('0x32')]['fields']));_0x194a13[_0x9926('0x36')]=_0x194a13[_0x9926('0x36')][_0x9926('0x38')]?_0x194a13['attributes']:_0xfc6f71[_0x9926('0x31')];if(_0x19f8e1[_0x9926('0x32')][_0x9926('0x42')]){_0x194a13[_0x9926('0x48')]=[{'all':!![]}];}_0x194a13=_[_0x9926('0x40')]({},_0x194a13,_0x19f8e1[_0x9926('0x41')]);return db[_0x9926('0x2d')][_0x9926('0x49')](_0x194a13)[_0x9926('0x26')](handleEntityNotFound(_0x56b1ed,null))[_0x9926('0x26')](respondWithResult(_0x56b1ed,null))[_0x9926('0x44')](handleError(_0x56b1ed,null));};exports[_0x9926('0x4a')]=function(_0x5c80b2,_0x163cc1){return db['VtigerAccount']['create'](_0x5c80b2[_0x9926('0x4b')],{})[_0x9926('0x26')](respondWithResult(_0x163cc1,0xc9))[_0x9926('0x44')](handleError(_0x163cc1,null));};exports[_0x9926('0x25')]=function(_0x2e8c73,_0x174d68){if(_0x2e8c73['body']['id']){delete _0x2e8c73['body']['id'];}return db['VtigerAccount'][_0x9926('0x49')]({'where':{'id':_0x2e8c73['params']['id']}})[_0x9926('0x26')](handleEntityNotFound(_0x174d68,null))[_0x9926('0x26')](saveUpdates(_0x2e8c73[_0x9926('0x4b')],null))[_0x9926('0x26')](respondWithResult(_0x174d68,null))[_0x9926('0x44')](handleError(_0x174d68,null));};exports[_0x9926('0x27')]=function(_0x143f9e,_0x2908a4){return db[_0x9926('0x2d')]['find']({'where':{'id':_0x143f9e['params']['id']}})[_0x9926('0x26')](handleEntityNotFound(_0x2908a4,null))[_0x9926('0x26')](removeEntity(_0x2908a4,null))[_0x9926('0x44')](handleError(_0x2908a4,null));};exports[_0x9926('0x4c')]=function(_0xd5516f,_0x146318,_0x2417ce){var _0xdb2298={};var _0x1c99c5={};var _0x3b98a1;var _0xc486af;return db[_0x9926('0x2d')]['findOne']({'where':{'id':_0xd5516f[_0x9926('0x46')]['id']}})[_0x9926('0x26')](handleEntityNotFound(_0x146318,null))[_0x9926('0x26')](function(_0x10798c){if(_0x10798c){_0x3b98a1=_0x10798c;_0x1c99c5['model']=_[_0x9926('0x33')](db[_0x9926('0x4d')][_0x9926('0x47')]);_0x1c99c5['query']=_[_0x9926('0x33')](_0xd5516f[_0x9926('0x32')]);_0x1c99c5[_0x9926('0x34')]=_[_0x9926('0x35')](_0x1c99c5[_0x9926('0x31')],_0x1c99c5[_0x9926('0x32')]);_0xdb2298[_0x9926('0x36')]=_[_0x9926('0x35')](_0x1c99c5['model'],qs[_0x9926('0x37')](_0xd5516f[_0x9926('0x32')][_0x9926('0x37')]));_0xdb2298[_0x9926('0x36')]=_0xdb2298[_0x9926('0x36')][_0x9926('0x38')]?_0xdb2298[_0x9926('0x36')]:_0x1c99c5[_0x9926('0x31')];_0xdb2298[_0x9926('0x3b')]=qs['sort'](_0xd5516f[_0x9926('0x32')]['sort']);_0xdb2298['where']=qs[_0x9926('0x34')](_[_0x9926('0x3e')](_0xd5516f[_0x9926('0x32')],_0x1c99c5[_0x9926('0x34')]));if(_0xd5516f[_0x9926('0x32')][_0x9926('0x3f')]){_0xdb2298[_0x9926('0x3d')]=_[_0x9926('0x40')](_0xdb2298[_0x9926('0x3d')],{'$or':_[_0x9926('0x2c')](_0xdb2298[_0x9926('0x36')],function(_0x3dfc10){var _0x57c254={};_0x57c254[_0x3dfc10]={'$like':'%'+_0xd5516f[_0x9926('0x32')][_0x9926('0x3f')]+'%'};return _0x57c254;})});}_0xdb2298=_[_0x9926('0x40')]({},_0xdb2298,_0xd5516f[_0x9926('0x41')]);return _0x3b98a1[_0x9926('0x4c')](_0xdb2298);}})[_0x9926('0x26')](function(_0x16f6ac){if(_0x16f6ac){_0xc486af=_0x16f6ac['length'];if(!_0xd5516f[_0x9926('0x32')][_0x9926('0x39')](_0x9926('0x3a'))){_0xdb2298[_0x9926('0x20')]=qs[_0x9926('0x20')](_0xd5516f[_0x9926('0x32')][_0x9926('0x20')]);_0xdb2298[_0x9926('0x1e')]=qs['offset'](_0xd5516f['query'][_0x9926('0x1e')]);}return _0x3b98a1[_0x9926('0x4c')](_0xdb2298);}})[_0x9926('0x26')](function(_0x548528){if(_0x548528){return _0x548528?{'count':_0xc486af,'rows':_0x548528}:null;}})['then'](respondWithResult(_0x146318,null))[_0x9926('0x44')](handleError(_0x146318,null));};exports['addConfiguration']=function(_0x5e8d09,_0x1a76f6,_0x146cc6){if(_0x5e8d09['body']['id']){delete _0x5e8d09[_0x9926('0x4b')]['id'];}return db['VtigerAccount']['findOne']({'where':{'id':_0x5e8d09[_0x9926('0x46')]['id']}})[_0x9926('0x26')](handleEntityNotFound(_0x1a76f6,null))[_0x9926('0x26')](function(_0x223858){if(_0x223858){_0x5e8d09[_0x9926('0x4b')][_0x9926('0x4e')]=_0x223858['id'];_0x5e8d09['body'][_0x9926('0x4f')]=integrations[_0x9926('0x50')](_0x5e8d09[_0x9926('0x4b')][_0x9926('0x51')],_0x5e8d09['body'][_0x9926('0x2f')]);_0x5e8d09[_0x9926('0x4b')][_0x9926('0x52')]=integrations[_0x9926('0x53')](_0x5e8d09[_0x9926('0x4b')][_0x9926('0x51')],_0x5e8d09[_0x9926('0x4b')][_0x9926('0x2f')]);return db['VtigerConfiguration'][_0x9926('0x4a')](_0x5e8d09[_0x9926('0x4b')],{'include':[{'model':db['VtigerField'],'as':'Subjects'},{'model':db[_0x9926('0x54')],'as':_0x9926('0x52')}]});}return null;})[_0x9926('0x26')](respondWithResult(_0x1a76f6,null))['catch'](handleError(_0x1a76f6,null));};var md5=require(_0x9926('0x55'));exports[_0x9926('0x56')]=function(_0x25a1ce,_0x575305,_0x235ff3){var _0x1f6a21=null;var _0x2e3c51=null;var _0x18e65b=null;var _0xe14533=null;var _0x52b4fb='';return db[_0x9926('0x2d')]['findOne']({'where':{'id':_0x25a1ce[_0x9926('0x46')]['id']},'attributes':['id',_0x9926('0x29'),_0x9926('0x57'),_0x9926('0x58'),_0x9926('0x59'),_0x9926('0x5a'),_0x9926('0x5b'),_0x9926('0x5c')]})[_0x9926('0x26')](handleEntityNotFound(_0x575305,null))['then'](function(_0x4e5bf6){if(_0x4e5bf6){_0x1f6a21=_0x4e5bf6[_0x9926('0x57')];_0x2e3c51=_0x4e5bf6['accessKey'];_0x18e65b=_0x4e5bf6[_0x9926('0x59')];_0x52b4fb=_0x4e5bf6['remoteUri'];var _0x311cd0=_0x52b4fb[_0x9926('0x5d')](-0x1);if(_0x311cd0==='/'){_0x52b4fb=_0x52b4fb[_0x9926('0x5e')](0x0,_0x52b4fb[_0x9926('0x5f')](_0x311cd0));}_0xe14533=util[_0x9926('0x60')]('%s/webservice.php',_0x52b4fb);var _0x12f11e={'method':'GET','uri':_0xe14533,'qs':{'operation':_0x9926('0x61'),'username':_0x4e5bf6[_0x9926('0x57')]},'json':!![]};return rp(_0x12f11e);}})[_0x9926('0x26')](function(_0x54787c){if(_0x54787c['success']){var _0x3e00f3={'method':'POST','uri':_0xe14533,'form':{'operation':_0x9926('0x62'),'username':_0x1f6a21,'accessKey':md5(_0x54787c[_0x9926('0x63')][_0x9926('0x64')]+_0x2e3c51)},'json':!![]};return rp(_0x3e00f3);}})[_0x9926('0x26')](function(_0x3aa9a8){if(_0x3aa9a8[_0x9926('0x65')]){var _0x47a513={'method':_0x9926('0x66'),'uri':_0xe14533,'qs':{'operation':_0x9926('0x67'),'username':_0x1f6a21,'sessionName':_0x3aa9a8[_0x9926('0x63')][_0x9926('0x68')],'elementType':_0x18e65b},'json':!![]};return rp(_0x47a513);}})['then'](function(_0x4f5213){if(_0x4f5213[_0x9926('0x65')]){var _0x552ee8=[_0x9926('0x69'),'reference',_0x9926('0x6a')];_[_0x9926('0x6b')](_0x4f5213[_0x9926('0x63')][_0x9926('0x37')],function(_0x608e40){return _0x552ee8['includes'](_0x608e40[_0x9926('0x2f')][_0x9926('0x29')]);});_[_0x9926('0x6b')](_0x4f5213[_0x9926('0x63')][_0x9926('0x37')],function(_0x83993b){return _0x83993b['editable']==='false';});return{'count':_0x4f5213[_0x9926('0x63')]['fields'][_0x9926('0x38')],'rows':_[_0x9926('0x2c')](_0x4f5213['result']['fields'],function(_0x415f38){return{'id':_0x415f38[_0x9926('0x29')],'name':_0x415f38[_0x9926('0x6c')],'custom':_['startsWith'](_0x415f38[_0x9926('0x29')],_0x9926('0x6d'))?!![]:![],'options':_0x415f38[_0x9926('0x2f')]['name']===_0x9926('0x6e')&&_0x415f38['type'][_0x9926('0x6f')][_0x9926('0x38')]>0x0?_[_0x9926('0x2c')](_0x415f38[_0x9926('0x2f')][_0x9926('0x6f')],function(_0x29e14e){return{'name':_0x29e14e[_0x9926('0x6c')],'value':_0x29e14e[_0x9926('0x70')]};}):[]};})};}})['then'](respondWithResult(_0x575305,null))[_0x9926('0x44')](function(_0x2fbe50){console['log'](_0x9926('0x71')+_0x2fbe50);var _0x2de055=_0x25a1ce[_0x9926('0x32')][_0x9926('0x72')]?0x1f4:_0x2fbe50[_0x9926('0x73')]||0x1f4;logger[_0x9926('0x28')]('getFields,\x20%s,\x20%s,\x20%s',_0x9926('0x56'),_0x2de055,JSON[_0x9926('0x74')](_0x2fbe50));delete _0x2fbe50[_0x9926('0x29')];if(_0x2de055===0x191){_0x2de055=0x190;}_0x575305[_0x9926('0x1a')](_0x2de055)[_0x9926('0x2a')](_0x25a1ce[_0x9926('0x32')]['test']?{'message':_0x9926('0x75'),'statusCode':_0x2fbe50['statusCode']}:_0x2fbe50);});};
\ No newline at end of file
+var _0x6f4f=['../../config/logger','../../config/utils','../../config/environment','../../config/license/util','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','apply','reject','save','destroy','error','send','index','map','rawAttributes','fieldName','type','model','query','filters','attributes','fields','length','hasOwnProperty','sort','where','merge','VIRTUAL','name','filter','options','VtigerAccount','then','include','findAll','rows','catch','show','params','keys','intersection','includeAll','create','body','update','find','getConfigurations','findOne','VtigerConfiguration','order','pick','nolimit','addConfiguration','AccountId','Subjects','getSubjects','channel','Descriptions','VtigerField','md5','getFields','username','description','moduleName','remoteUri','serverUrl','accessKey','lastIndexOf','%s/webservice.php','GET','success','POST','login','token','describe','sessionName','autogenerated','reference','owner','remove','result','false','picklist','picklistValues','label','value','log','test','statusCode','getFields,\x20%s,\x20%s,\x20%s','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware'];(function(_0x89cb3a,_0x385fd1){var _0x407cf1=function(_0x61fa77){while(--_0x61fa77){_0x89cb3a['push'](_0x89cb3a['shift']());}};_0x407cf1(++_0x385fd1);}(_0x6f4f,0x1c7));var _0xf6f4=function(_0x40f481,_0x5a01e6){_0x40f481=_0x40f481-0x0;var _0x222abc=_0x6f4f[_0x40f481];return _0x222abc;};'use strict';var emlformat=require(_0xf6f4('0x0'));var rimraf=require(_0xf6f4('0x1'));var zipdir=require(_0xf6f4('0x2'));var jsonpatch=require(_0xf6f4('0x3'));var rp=require('request-promise');var moment=require(_0xf6f4('0x4'));var BPromise=require(_0xf6f4('0x5'));var Mustache=require(_0xf6f4('0x6'));var util=require('util');var path=require('path');var sox=require(_0xf6f4('0x7'));var csv=require(_0xf6f4('0x8'));var ejs=require(_0xf6f4('0x9'));var fs=require('fs');var fs_extra=require(_0xf6f4('0xa'));var _=require(_0xf6f4('0xb'));var squel=require(_0xf6f4('0xc'));var crypto=require(_0xf6f4('0xd'));var jsforce=require(_0xf6f4('0xe'));var deskjs=require('desk.js');var toCsv=require(_0xf6f4('0x8'));var querystring=require(_0xf6f4('0xf'));var Papa=require('papaparse');var Redis=require(_0xf6f4('0x10'));var authService=require(_0xf6f4('0x11'));var qs=require(_0xf6f4('0x12'));var as=require(_0xf6f4('0x13'));var hardwareService=require(_0xf6f4('0x14'));var logger=require(_0xf6f4('0x15'))('api');var utils=require(_0xf6f4('0x16'));var config=require(_0xf6f4('0x17'));var licenseUtil=require(_0xf6f4('0x18'));var db=require('../../mysqldb')['db'];var integrations=require('../../components/integrations/configuration');function respondWithStatusCode(_0x336860,_0x184d3f){_0x184d3f=_0x184d3f||0xcc;return function(_0x2836e4){if(_0x2836e4){return _0x336860[_0xf6f4('0x19')](_0x184d3f);}return _0x336860[_0xf6f4('0x1a')](_0x184d3f)[_0xf6f4('0x1b')]();};}function respondWithResult(_0x352251,_0x2faa14){_0x2faa14=_0x2faa14||0xc8;return function(_0x4f485e){if(_0x4f485e){return _0x352251[_0xf6f4('0x1a')](_0x2faa14)[_0xf6f4('0x1c')](_0x4f485e);}};}function respondWithFilteredResult(_0x2d1f45,_0xe061c7){return function(_0x2d3031){if(_0x2d3031){var _0x414f67=typeof _0xe061c7[_0xf6f4('0x1d')]===_0xf6f4('0x1e')&&typeof _0xe061c7[_0xf6f4('0x1f')]==='undefined';var _0x28c764=_0x2d3031['count'];var _0x3a5db0=_0x414f67?0x0:_0xe061c7[_0xf6f4('0x1d')];var _0x399950=_0x414f67?_0x2d3031[_0xf6f4('0x20')]:_0xe061c7[_0xf6f4('0x1d')]+_0xe061c7[_0xf6f4('0x1f')];var _0x2b9d5f;if(_0x399950>=_0x28c764){_0x399950=_0x28c764;_0x2b9d5f=0xc8;}else{_0x2b9d5f=0xce;}_0x2d1f45[_0xf6f4('0x1a')](_0x2b9d5f);return _0x2d1f45[_0xf6f4('0x21')](_0xf6f4('0x22'),_0x3a5db0+'-'+_0x399950+'/'+_0x28c764)[_0xf6f4('0x1c')](_0x2d3031);}return null;};}function patchUpdates(_0x3929fd){return function(_0x102397){try{jsonpatch[_0xf6f4('0x23')](_0x102397,_0x3929fd,!![]);}catch(_0x5aedb1){return BPromise[_0xf6f4('0x24')](_0x5aedb1);}return _0x102397[_0xf6f4('0x25')]();};}function saveUpdates(_0x1e61fb,_0x1d98ab){return function(_0x599ef5){if(_0x599ef5){return _0x599ef5['update'](_0x1e61fb)['then'](function(_0x542288){return _0x542288;});}return null;};}function removeEntity(_0x3582f0,_0x1e782d){return function(_0x55aed1){if(_0x55aed1){return _0x55aed1[_0xf6f4('0x26')]()['then'](function(){_0x3582f0[_0xf6f4('0x1a')](0xcc)[_0xf6f4('0x1b')]();});}};}function handleEntityNotFound(_0x5428b6,_0x2d2dfa){return function(_0x573345){if(!_0x573345){_0x5428b6[_0xf6f4('0x19')](0x194);}return _0x573345;};}function handleError(_0x1cae60,_0x1b0795){_0x1b0795=_0x1b0795||0x1f4;return function(_0x1e9b48){logger[_0xf6f4('0x27')](_0x1e9b48['stack']);if(_0x1e9b48['name']){delete _0x1e9b48['name'];}_0x1cae60['status'](_0x1b0795)[_0xf6f4('0x28')](_0x1e9b48);};}exports[_0xf6f4('0x29')]=function(_0x5e53ce,_0x221069){var _0x43db4f={},_0x450e9c={},_0x3636f7={'count':0x0,'rows':[]};var _0x4f4640=_[_0xf6f4('0x2a')](db['VtigerAccount'][_0xf6f4('0x2b')],function(_0x242280){return{'name':_0x242280[_0xf6f4('0x2c')],'type':_0x242280[_0xf6f4('0x2d')]['key']};});_0x450e9c[_0xf6f4('0x2e')]=_[_0xf6f4('0x2a')](_0x4f4640,'name');_0x450e9c[_0xf6f4('0x2f')]=_['keys'](_0x5e53ce[_0xf6f4('0x2f')]);_0x450e9c[_0xf6f4('0x30')]=_['intersection'](_0x450e9c[_0xf6f4('0x2e')],_0x450e9c[_0xf6f4('0x2f')]);_0x43db4f[_0xf6f4('0x31')]=_['intersection'](_0x450e9c[_0xf6f4('0x2e')],qs[_0xf6f4('0x32')](_0x5e53ce[_0xf6f4('0x2f')]['fields']));_0x43db4f[_0xf6f4('0x31')]=_0x43db4f[_0xf6f4('0x31')][_0xf6f4('0x33')]?_0x43db4f[_0xf6f4('0x31')]:_0x450e9c[_0xf6f4('0x2e')];if(!_0x5e53ce[_0xf6f4('0x2f')][_0xf6f4('0x34')]('nolimit')){_0x43db4f[_0xf6f4('0x1f')]=qs['limit'](_0x5e53ce[_0xf6f4('0x2f')][_0xf6f4('0x1f')]);_0x43db4f['offset']=qs[_0xf6f4('0x1d')](_0x5e53ce[_0xf6f4('0x2f')][_0xf6f4('0x1d')]);}_0x43db4f['order']=qs[_0xf6f4('0x35')](_0x5e53ce[_0xf6f4('0x2f')][_0xf6f4('0x35')]);_0x43db4f[_0xf6f4('0x36')]=qs[_0xf6f4('0x30')](_['pick'](_0x5e53ce[_0xf6f4('0x2f')],_0x450e9c[_0xf6f4('0x30')]),_0x4f4640);if(_0x5e53ce['query']['filter']){_0x43db4f[_0xf6f4('0x36')]=_[_0xf6f4('0x37')](_0x43db4f['where'],{'$or':_[_0xf6f4('0x2a')](_0x4f4640,function(_0x2f3762){if(_0x2f3762[_0xf6f4('0x2d')]!==_0xf6f4('0x38')){var _0x1a493d={};_0x1a493d[_0x2f3762[_0xf6f4('0x39')]]={'$like':'%'+_0x5e53ce['query'][_0xf6f4('0x3a')]+'%'};return _0x1a493d;}})});}_0x43db4f=_['merge']({},_0x43db4f,_0x5e53ce[_0xf6f4('0x3b')]);var _0xf4ad34={'where':_0x43db4f['where']};return db[_0xf6f4('0x3c')][_0xf6f4('0x20')](_0xf4ad34)[_0xf6f4('0x3d')](function(_0x3c04ea){_0x3636f7['count']=_0x3c04ea;if(_0x5e53ce[_0xf6f4('0x2f')]['includeAll']){_0x43db4f[_0xf6f4('0x3e')]=[{'all':!![]}];}return db[_0xf6f4('0x3c')][_0xf6f4('0x3f')](_0x43db4f);})[_0xf6f4('0x3d')](function(_0xe2ae86){_0x3636f7[_0xf6f4('0x40')]=_0xe2ae86;return _0x3636f7;})[_0xf6f4('0x3d')](respondWithFilteredResult(_0x221069,_0x43db4f))[_0xf6f4('0x41')](handleError(_0x221069,null));};exports[_0xf6f4('0x42')]=function(_0x3cb0f6,_0x14ede1){var _0x1db6aa={'raw':![],'where':{'id':_0x3cb0f6[_0xf6f4('0x43')]['id']}},_0x1d112f={};_0x1d112f[_0xf6f4('0x2e')]=_[_0xf6f4('0x44')](db[_0xf6f4('0x3c')][_0xf6f4('0x2b')]);_0x1d112f[_0xf6f4('0x2f')]=_[_0xf6f4('0x44')](_0x3cb0f6[_0xf6f4('0x2f')]);_0x1d112f[_0xf6f4('0x30')]=_['intersection'](_0x1d112f[_0xf6f4('0x2e')],_0x1d112f['query']);_0x1db6aa['attributes']=_[_0xf6f4('0x45')](_0x1d112f[_0xf6f4('0x2e')],qs[_0xf6f4('0x32')](_0x3cb0f6[_0xf6f4('0x2f')][_0xf6f4('0x32')]));_0x1db6aa[_0xf6f4('0x31')]=_0x1db6aa[_0xf6f4('0x31')][_0xf6f4('0x33')]?_0x1db6aa['attributes']:_0x1d112f[_0xf6f4('0x2e')];if(_0x3cb0f6[_0xf6f4('0x2f')][_0xf6f4('0x46')]){_0x1db6aa[_0xf6f4('0x3e')]=[{'all':!![]}];}_0x1db6aa=_['merge']({},_0x1db6aa,_0x3cb0f6[_0xf6f4('0x3b')]);return db[_0xf6f4('0x3c')]['find'](_0x1db6aa)[_0xf6f4('0x3d')](handleEntityNotFound(_0x14ede1,null))[_0xf6f4('0x3d')](respondWithResult(_0x14ede1,null))[_0xf6f4('0x41')](handleError(_0x14ede1,null));};exports[_0xf6f4('0x47')]=function(_0x317813,_0x4eab92){return db[_0xf6f4('0x3c')]['create'](_0x317813[_0xf6f4('0x48')],{})['then'](respondWithResult(_0x4eab92,0xc9))[_0xf6f4('0x41')](handleError(_0x4eab92,null));};exports[_0xf6f4('0x49')]=function(_0x2514b3,_0x41ff5a){if(_0x2514b3['body']['id']){delete _0x2514b3[_0xf6f4('0x48')]['id'];}return db[_0xf6f4('0x3c')]['find']({'where':{'id':_0x2514b3[_0xf6f4('0x43')]['id']}})[_0xf6f4('0x3d')](handleEntityNotFound(_0x41ff5a,null))['then'](saveUpdates(_0x2514b3[_0xf6f4('0x48')],null))['then'](respondWithResult(_0x41ff5a,null))[_0xf6f4('0x41')](handleError(_0x41ff5a,null));};exports[_0xf6f4('0x26')]=function(_0x5427d1,_0x2b7a4c){return db['VtigerAccount'][_0xf6f4('0x4a')]({'where':{'id':_0x5427d1[_0xf6f4('0x43')]['id']}})[_0xf6f4('0x3d')](handleEntityNotFound(_0x2b7a4c,null))[_0xf6f4('0x3d')](removeEntity(_0x2b7a4c,null))['catch'](handleError(_0x2b7a4c,null));};exports[_0xf6f4('0x4b')]=function(_0x31e783,_0x20cdfa,_0x4f0ec9){var _0x30cb3f={};var _0x3a4ea7={};var _0x5951fe;var _0x53efff;return db[_0xf6f4('0x3c')][_0xf6f4('0x4c')]({'where':{'id':_0x31e783[_0xf6f4('0x43')]['id']}})[_0xf6f4('0x3d')](handleEntityNotFound(_0x20cdfa,null))['then'](function(_0x1af346){if(_0x1af346){_0x5951fe=_0x1af346;_0x3a4ea7[_0xf6f4('0x2e')]=_[_0xf6f4('0x44')](db[_0xf6f4('0x4d')][_0xf6f4('0x2b')]);_0x3a4ea7[_0xf6f4('0x2f')]=_[_0xf6f4('0x44')](_0x31e783[_0xf6f4('0x2f')]);_0x3a4ea7[_0xf6f4('0x30')]=_[_0xf6f4('0x45')](_0x3a4ea7[_0xf6f4('0x2e')],_0x3a4ea7[_0xf6f4('0x2f')]);_0x30cb3f[_0xf6f4('0x31')]=_[_0xf6f4('0x45')](_0x3a4ea7[_0xf6f4('0x2e')],qs['fields'](_0x31e783[_0xf6f4('0x2f')]['fields']));_0x30cb3f['attributes']=_0x30cb3f['attributes'][_0xf6f4('0x33')]?_0x30cb3f['attributes']:_0x3a4ea7[_0xf6f4('0x2e')];_0x30cb3f[_0xf6f4('0x4e')]=qs['sort'](_0x31e783['query'][_0xf6f4('0x35')]);_0x30cb3f[_0xf6f4('0x36')]=qs[_0xf6f4('0x30')](_[_0xf6f4('0x4f')](_0x31e783['query'],_0x3a4ea7['filters']));if(_0x31e783[_0xf6f4('0x2f')][_0xf6f4('0x3a')]){_0x30cb3f[_0xf6f4('0x36')]=_[_0xf6f4('0x37')](_0x30cb3f[_0xf6f4('0x36')],{'$or':_[_0xf6f4('0x2a')](_0x30cb3f['attributes'],function(_0x43ebee){var _0x5d1d7c={};_0x5d1d7c[_0x43ebee]={'$like':'%'+_0x31e783[_0xf6f4('0x2f')]['filter']+'%'};return _0x5d1d7c;})});}_0x30cb3f=_[_0xf6f4('0x37')]({},_0x30cb3f,_0x31e783[_0xf6f4('0x3b')]);return _0x5951fe[_0xf6f4('0x4b')](_0x30cb3f);}})[_0xf6f4('0x3d')](function(_0x3c9507){if(_0x3c9507){_0x53efff=_0x3c9507[_0xf6f4('0x33')];if(!_0x31e783[_0xf6f4('0x2f')][_0xf6f4('0x34')](_0xf6f4('0x50'))){_0x30cb3f['limit']=qs['limit'](_0x31e783[_0xf6f4('0x2f')][_0xf6f4('0x1f')]);_0x30cb3f[_0xf6f4('0x1d')]=qs[_0xf6f4('0x1d')](_0x31e783[_0xf6f4('0x2f')][_0xf6f4('0x1d')]);}return _0x5951fe[_0xf6f4('0x4b')](_0x30cb3f);}})[_0xf6f4('0x3d')](function(_0x9b69a1){if(_0x9b69a1){return _0x9b69a1?{'count':_0x53efff,'rows':_0x9b69a1}:null;}})[_0xf6f4('0x3d')](respondWithResult(_0x20cdfa,null))[_0xf6f4('0x41')](handleError(_0x20cdfa,null));};exports[_0xf6f4('0x51')]=function(_0x2b5bf2,_0x1c6d20,_0x5c72e7){if(_0x2b5bf2[_0xf6f4('0x48')]['id']){delete _0x2b5bf2[_0xf6f4('0x48')]['id'];}return db[_0xf6f4('0x3c')][_0xf6f4('0x4c')]({'where':{'id':_0x2b5bf2['params']['id']}})['then'](handleEntityNotFound(_0x1c6d20,null))['then'](function(_0x423bb6){if(_0x423bb6){_0x2b5bf2[_0xf6f4('0x48')][_0xf6f4('0x52')]=_0x423bb6['id'];_0x2b5bf2[_0xf6f4('0x48')][_0xf6f4('0x53')]=integrations[_0xf6f4('0x54')](_0x2b5bf2[_0xf6f4('0x48')][_0xf6f4('0x55')],_0x2b5bf2[_0xf6f4('0x48')][_0xf6f4('0x2d')]);_0x2b5bf2['body'][_0xf6f4('0x56')]=integrations['getDescriptions'](_0x2b5bf2[_0xf6f4('0x48')]['channel'],_0x2b5bf2[_0xf6f4('0x48')]['type']);return db['VtigerConfiguration'][_0xf6f4('0x47')](_0x2b5bf2[_0xf6f4('0x48')],{'include':[{'model':db[_0xf6f4('0x57')],'as':_0xf6f4('0x53')},{'model':db[_0xf6f4('0x57')],'as':'Descriptions'}]});}return null;})[_0xf6f4('0x3d')](respondWithResult(_0x1c6d20,null))[_0xf6f4('0x41')](handleError(_0x1c6d20,null));};var md5=require(_0xf6f4('0x58'));exports[_0xf6f4('0x59')]=function(_0x461b32,_0x3e69d9,_0xfe6ee6){var _0x2c05c2=null;var _0x55a180=null;var _0x32ca82=null;var _0x2dec49=null;var _0x37acbe='';return db['VtigerAccount'][_0xf6f4('0x4c')]({'where':{'id':_0x461b32[_0xf6f4('0x43')]['id']},'attributes':['id',_0xf6f4('0x39'),_0xf6f4('0x5a'),_0xf6f4('0x5b'),_0xf6f4('0x5c'),_0xf6f4('0x5d'),_0xf6f4('0x5e'),_0xf6f4('0x5f')]})[_0xf6f4('0x3d')](handleEntityNotFound(_0x3e69d9,null))[_0xf6f4('0x3d')](function(_0x191a9a){if(_0x191a9a){_0x2c05c2=_0x191a9a['username'];_0x55a180=_0x191a9a[_0xf6f4('0x5f')];_0x32ca82=_0x191a9a[_0xf6f4('0x5c')];_0x37acbe=_0x191a9a[_0xf6f4('0x5d')];var _0x580bd1=_0x37acbe['slice'](-0x1);if(_0x580bd1==='/'){_0x37acbe=_0x37acbe['substring'](0x0,_0x37acbe[_0xf6f4('0x60')](_0x580bd1));}_0x2dec49=util['format'](_0xf6f4('0x61'),_0x37acbe);var _0x370a3e={'method':_0xf6f4('0x62'),'uri':_0x2dec49,'qs':{'operation':'getchallenge','username':_0x191a9a[_0xf6f4('0x5a')]},'json':!![]};return rp(_0x370a3e);}})[_0xf6f4('0x3d')](function(_0x548bb6){if(_0x548bb6[_0xf6f4('0x63')]){var _0x598ede={'method':_0xf6f4('0x64'),'uri':_0x2dec49,'form':{'operation':_0xf6f4('0x65'),'username':_0x2c05c2,'accessKey':md5(_0x548bb6['result'][_0xf6f4('0x66')]+_0x55a180)},'json':!![]};return rp(_0x598ede);}})[_0xf6f4('0x3d')](function(_0x3ef980){if(_0x3ef980[_0xf6f4('0x63')]){var _0x483a31={'method':_0xf6f4('0x62'),'uri':_0x2dec49,'qs':{'operation':_0xf6f4('0x67'),'username':_0x2c05c2,'sessionName':_0x3ef980['result'][_0xf6f4('0x68')],'elementType':_0x32ca82},'json':!![]};return rp(_0x483a31);}})[_0xf6f4('0x3d')](function(_0x21b564){if(_0x21b564[_0xf6f4('0x63')]){var _0x15efdc=[_0xf6f4('0x69'),_0xf6f4('0x6a'),_0xf6f4('0x6b')];_[_0xf6f4('0x6c')](_0x21b564[_0xf6f4('0x6d')][_0xf6f4('0x32')],function(_0x11c740){return _0x15efdc['includes'](_0x11c740[_0xf6f4('0x2d')][_0xf6f4('0x39')]);});_[_0xf6f4('0x6c')](_0x21b564[_0xf6f4('0x6d')]['fields'],function(_0x509e2d){return _0x509e2d['editable']===_0xf6f4('0x6e');});return{'count':_0x21b564[_0xf6f4('0x6d')][_0xf6f4('0x32')]['length'],'rows':_[_0xf6f4('0x2a')](_0x21b564[_0xf6f4('0x6d')][_0xf6f4('0x32')],function(_0x5d0c0a){return{'id':_0x5d0c0a[_0xf6f4('0x39')],'name':_0x5d0c0a['label'],'custom':_['startsWith'](_0x5d0c0a[_0xf6f4('0x39')],'cf_')?!![]:![],'options':_0x5d0c0a[_0xf6f4('0x2d')]['name']===_0xf6f4('0x6f')&&_0x5d0c0a[_0xf6f4('0x2d')][_0xf6f4('0x70')]['length']>0x0?_[_0xf6f4('0x2a')](_0x5d0c0a[_0xf6f4('0x2d')][_0xf6f4('0x70')],function(_0x5ca7b0){return{'name':_0x5ca7b0[_0xf6f4('0x71')],'value':_0x5ca7b0[_0xf6f4('0x72')]};}):[]};})};}})[_0xf6f4('0x3d')](respondWithResult(_0x3e69d9,null))[_0xf6f4('0x41')](function(_0x5b58bd){console[_0xf6f4('0x73')]('vTiger\x20error:\x20'+_0x5b58bd);var _0x40adc5=_0x461b32[_0xf6f4('0x2f')][_0xf6f4('0x74')]?0x1f4:_0x5b58bd[_0xf6f4('0x75')]||0x1f4;logger[_0xf6f4('0x27')](_0xf6f4('0x76'),_0xf6f4('0x59'),_0x40adc5,JSON['stringify'](_0x5b58bd));delete _0x5b58bd[_0xf6f4('0x39')];if(_0x40adc5===0x191){_0x40adc5=0x190;}_0x3e69d9['status'](_0x40adc5)['send'](_0x461b32[_0xf6f4('0x2f')][_0xf6f4('0x74')]?{'message':'Wrong\x20credentials','statusCode':_0x5b58bd[_0xf6f4('0x75')]}:_0x5b58bd);});};
\ No newline at end of file