Built motion from commit (unavailable).|2.3.1
[motion2.git] / server / api / intSugarcrmAccount / intSugarcrmAccount.controller.js
index f8d9c47..c787b7a 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xc70b=['pick','filter','map','type','key','VIRTUAL','merge','count','includeAll','include','SugarcrmAccount','findAll','rows','params','rawAttributes','find','create','body','getConfigurations','findOne','options','getSubjects','Descriptions','getDescriptions','channel','Subjects','SugarcrmField','getFields','assigned_user_id','created_by','description','date_start','duration_hours','duration_minutes','parent_id','parent_type','parent_name','direction','username','password','remoteUri','format','%s%s','/service/v4_1/rest.php','login','JSON','PLAIN','xCALLY\x20Motion\x20Integration','Invalid\x20Login','Password\x20Expired','POST','get_module_fields','Calls','values','remove','length','label','value','test','statusCode','Wrong\x20credentials','html-pdf','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','papaparse','../../components/auth/service','../../config/license/hardware','ioredis','../../components/parsers/qs','../../config/logger','../../config/utils','../../config/environment','../../components/integrations/configuration','jayson/promise','client','http','then','info','request\x20sent','debug','stringify','error','message','result','catch','SugarcrmAccount,\x20%s,\x20%s','sendStatus','status','end','json','offset','limit','set','Content-Range','apply','reject','update','destroy','stack','name','send','index','keys','query','filters','intersection','model','attributes','fields','hasOwnProperty','nolimit','order','sort','where'];(function(_0x3ec73f,_0x2dce6a){var _0x4b771a=function(_0x4c8d1a){while(--_0x4c8d1a){_0x3ec73f['push'](_0x3ec73f['shift']());}};_0x4b771a(++_0x2dce6a);}(_0xc70b,0x13b));var _0xbc70=function(_0x3c0d98,_0x510a42){_0x3c0d98=_0x3c0d98-0x0;var _0x3fdc28=_0xc70b[_0x3c0d98];return _0x3fdc28;};'use strict';var pdf=require(_0xbc70('0x0'));var emlformat=require('eml-format');var rimraf=require(_0xbc70('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xbc70('0x2'));var rp=require(_0xbc70('0x3'));var moment=require(_0xbc70('0x4'));var BPromise=require(_0xbc70('0x5'));var Mustache=require(_0xbc70('0x6'));var util=require('util');var path=require(_0xbc70('0x7'));var sox=require(_0xbc70('0x8'));var csv=require(_0xbc70('0x9'));var ejs=require(_0xbc70('0xa'));var fs=require('fs');var _=require(_0xbc70('0xb'));var squel=require(_0xbc70('0xc'));var crypto=require(_0xbc70('0xd'));var jsforce=require(_0xbc70('0xe'));var deskjs=require(_0xbc70('0xf'));var toCsv=require(_0xbc70('0x9'));var querystring=require('querystring');var Papa=require(_0xbc70('0x10'));var authService=require(_0xbc70('0x11'));var hardwareService=require(_0xbc70('0x12'));var Redis=require(_0xbc70('0x13'));var qs=require(_0xbc70('0x14'));var logger=require(_0xbc70('0x15'))('api');var utils=require(_0xbc70('0x16'));var config=require(_0xbc70('0x17'));var db=require('../../mysqldb')['db'];var integrations=require(_0xbc70('0x18'));var jayson=require(_0xbc70('0x19'));var client=jayson[_0xbc70('0x1a')][_0xbc70('0x1b')]({'port':0x232a});function respondWithRpcPromise(_0x210013,_0x245b87,_0x1247e6,_0x16d47a){return new BPromise(function(_0x1c5ae8,_0x2a4ed4){var _0x325d8c=_0x16d47a||client;return _0x325d8c['request'](_0x210013,_0x1247e6)[_0xbc70('0x1c')](function(_0x27b9a1){logger[_0xbc70('0x1d')]('SugarcrmAccount,\x20%s,\x20%s',_0x245b87,_0xbc70('0x1e'));logger[_0xbc70('0x1f')]('SugarcrmAccount,\x20%s,\x20%s,\x20%s',_0x245b87,_0xbc70('0x1e'),JSON[_0xbc70('0x20')](_0x27b9a1));if(_0x27b9a1[_0xbc70('0x21')]){if(_0x27b9a1[_0xbc70('0x21')]['code']===0x1f4){logger['error']('SugarcrmAccount,\x20%s,\x20%s',_0x245b87,_0x27b9a1[_0xbc70('0x21')][_0xbc70('0x22')]);return _0x2a4ed4(_0x27b9a1[_0xbc70('0x21')][_0xbc70('0x22')]);}logger['error']('SugarcrmAccount,\x20%s,\x20%s',_0x245b87,_0x27b9a1[_0xbc70('0x21')][_0xbc70('0x22')]);return _0x1c5ae8(_0x27b9a1[_0xbc70('0x21')][_0xbc70('0x22')]);}else{logger['info']('SugarcrmAccount,\x20%s,\x20%s',_0x245b87,_0xbc70('0x1e'));_0x1c5ae8(_0x27b9a1[_0xbc70('0x23')]['message']);}})[_0xbc70('0x24')](function(_0x2d84ab){logger[_0xbc70('0x21')](_0xbc70('0x25'),_0x245b87,_0x2d84ab);_0x2a4ed4(_0x2d84ab);});});}function respondWithStatusCode(_0x56ace2,_0x1e6822){_0x1e6822=_0x1e6822||0xcc;return function(_0x3f8e84){if(_0x3f8e84){return _0x56ace2[_0xbc70('0x26')](_0x1e6822);}return _0x56ace2[_0xbc70('0x27')](_0x1e6822)[_0xbc70('0x28')]();};}function respondWithResult(_0x39c539,_0x577af5){_0x577af5=_0x577af5||0xc8;return function(_0x2bfef6){if(_0x2bfef6){return _0x39c539[_0xbc70('0x27')](_0x577af5)[_0xbc70('0x29')](_0x2bfef6);}};}function respondWithFilteredResult(_0x3bbdf1,_0x15b533){return function(_0x4c999c){if(_0x4c999c){var _0x3f7700=_0x4c999c['count'],_0x7699fa=_0x15b533[_0xbc70('0x2a')],_0x26bc9a=_0x15b533[_0xbc70('0x2a')]+_0x15b533[_0xbc70('0x2b')],_0x1958d5;if(_0x26bc9a>=_0x3f7700){_0x26bc9a=_0x3f7700;_0x1958d5=0xc8;}else{_0x1958d5=0xce;}_0x3bbdf1['status'](_0x1958d5);return _0x3bbdf1[_0xbc70('0x2c')](_0xbc70('0x2d'),_0x7699fa+'-'+_0x26bc9a+'/'+_0x3f7700)[_0xbc70('0x29')](_0x4c999c);}return null;};}function patchUpdates(_0x31311e){return function(_0x5ac54e){try{jsonpatch[_0xbc70('0x2e')](_0x5ac54e,_0x31311e,!![]);}catch(_0x12be13){return BPromise[_0xbc70('0x2f')](_0x12be13);}return _0x5ac54e['save']();};}function saveUpdates(_0x4923bf,_0x4a7121){return function(_0x5e6d03){if(_0x5e6d03){return _0x5e6d03[_0xbc70('0x30')](_0x4923bf)[_0xbc70('0x1c')](function(_0x34d15f){return _0x34d15f;});}return null;};}function removeEntity(_0x5728c6,_0x106675){return function(_0x4c522c){if(_0x4c522c){return _0x4c522c[_0xbc70('0x31')]()[_0xbc70('0x1c')](function(){_0x5728c6['status'](0xcc)[_0xbc70('0x28')]();});}};}function handleEntityNotFound(_0x37a2de,_0x4ada88){return function(_0xb17538){if(!_0xb17538){_0x37a2de[_0xbc70('0x26')](0x194);}return _0xb17538;};}function handleError(_0x33cb86,_0x17ca40){_0x17ca40=_0x17ca40||0x1f4;return function(_0x12e18c){logger['error'](_0x12e18c[_0xbc70('0x32')]);if(_0x12e18c[_0xbc70('0x33')]){delete _0x12e18c[_0xbc70('0x33')];}_0x33cb86[_0xbc70('0x27')](_0x17ca40)[_0xbc70('0x34')](_0x12e18c);};}exports[_0xbc70('0x35')]=function(_0x4b5e61,_0x14d2f6){var _0x3972f7={},_0x547f6c={},_0x5c6348={'count':0x0,'rows':[]};var _0x1c08d5=db['SugarcrmAccount']['rawAttributes'];_0x547f6c['model']=_[_0xbc70('0x36')](_0x1c08d5);_0x547f6c['query']=_[_0xbc70('0x36')](_0x4b5e61[_0xbc70('0x37')]);_0x547f6c[_0xbc70('0x38')]=_[_0xbc70('0x39')](_0x547f6c[_0xbc70('0x3a')],_0x547f6c[_0xbc70('0x37')]);_0x3972f7[_0xbc70('0x3b')]=_[_0xbc70('0x39')](_0x547f6c[_0xbc70('0x3a')],qs[_0xbc70('0x3c')](_0x4b5e61['query'][_0xbc70('0x3c')]));_0x3972f7['attributes']=_0x3972f7[_0xbc70('0x3b')]['length']?_0x3972f7[_0xbc70('0x3b')]:_0x547f6c['model'];if(!_0x4b5e61[_0xbc70('0x37')][_0xbc70('0x3d')](_0xbc70('0x3e'))){_0x3972f7[_0xbc70('0x2b')]=qs['limit'](_0x4b5e61['query']['limit']);_0x3972f7['offset']=qs['offset'](_0x4b5e61[_0xbc70('0x37')][_0xbc70('0x2a')]);}_0x3972f7[_0xbc70('0x3f')]=qs['sort'](_0x4b5e61[_0xbc70('0x37')][_0xbc70('0x40')]);_0x3972f7[_0xbc70('0x41')]=qs[_0xbc70('0x38')](_[_0xbc70('0x42')](_0x4b5e61[_0xbc70('0x37')],_0x547f6c[_0xbc70('0x38')]));if(_0x4b5e61[_0xbc70('0x37')][_0xbc70('0x43')]){_0x3972f7['where']=_['merge'](_0x3972f7[_0xbc70('0x41')],{'$or':_[_0xbc70('0x44')](_0x1c08d5,function(_0x5bffeb){if(_0x5bffeb[_0xbc70('0x45')][_0xbc70('0x46')]!==_0xbc70('0x47')){var _0x863887={};_0x863887[_0x5bffeb['field']]={'$like':'%'+_0x4b5e61[_0xbc70('0x37')]['filter']+'%'};return _0x863887;}})});}_0x3972f7=_[_0xbc70('0x48')]({},_0x3972f7,_0x4b5e61['options']);var _0x43f5ce={'where':_0x3972f7[_0xbc70('0x41')]};return db['SugarcrmAccount'][_0xbc70('0x49')](_0x43f5ce)[_0xbc70('0x1c')](function(_0x4ff234){_0x5c6348[_0xbc70('0x49')]=_0x4ff234;if(_0x4b5e61[_0xbc70('0x37')][_0xbc70('0x4a')]){_0x3972f7[_0xbc70('0x4b')]=[{'all':!![]}];}return db[_0xbc70('0x4c')][_0xbc70('0x4d')](_0x3972f7);})[_0xbc70('0x1c')](function(_0x37ffa7){_0x5c6348[_0xbc70('0x4e')]=_0x37ffa7;return _0x5c6348;})[_0xbc70('0x1c')](respondWithFilteredResult(_0x14d2f6,_0x3972f7))['catch'](handleError(_0x14d2f6,null));};exports['show']=function(_0x30d528,_0x4f1eb9){var _0x97129d={'raw':![],'where':{'id':_0x30d528[_0xbc70('0x4f')]['id']}},_0x594436={};_0x594436[_0xbc70('0x3a')]=_['keys'](db[_0xbc70('0x4c')][_0xbc70('0x50')]);_0x594436[_0xbc70('0x37')]=_[_0xbc70('0x36')](_0x30d528[_0xbc70('0x37')]);_0x594436['filters']=_[_0xbc70('0x39')](_0x594436[_0xbc70('0x3a')],_0x594436['query']);_0x97129d[_0xbc70('0x3b')]=_[_0xbc70('0x39')](_0x594436[_0xbc70('0x3a')],qs[_0xbc70('0x3c')](_0x30d528[_0xbc70('0x37')]['fields']));_0x97129d[_0xbc70('0x3b')]=_0x97129d[_0xbc70('0x3b')]['length']?_0x97129d['attributes']:_0x594436['model'];if(_0x30d528[_0xbc70('0x37')]['includeAll']){_0x97129d['include']=[{'all':!![]}];}_0x97129d=_[_0xbc70('0x48')]({},_0x97129d,_0x30d528['options']);return db[_0xbc70('0x4c')][_0xbc70('0x51')](_0x97129d)[_0xbc70('0x1c')](handleEntityNotFound(_0x4f1eb9,null))[_0xbc70('0x1c')](respondWithResult(_0x4f1eb9,null))[_0xbc70('0x24')](handleError(_0x4f1eb9,null));};exports[_0xbc70('0x52')]=function(_0x1120d3,_0x546a1d){return db['SugarcrmAccount'][_0xbc70('0x52')](_0x1120d3['body'],{})[_0xbc70('0x1c')](respondWithResult(_0x546a1d,0xc9))['catch'](handleError(_0x546a1d,null));};exports[_0xbc70('0x30')]=function(_0x535866,_0x1460db){if(_0x535866['body']['id']){delete _0x535866[_0xbc70('0x53')]['id'];}return db[_0xbc70('0x4c')][_0xbc70('0x51')]({'where':{'id':_0x535866[_0xbc70('0x4f')]['id']}})[_0xbc70('0x1c')](handleEntityNotFound(_0x1460db,null))['then'](saveUpdates(_0x535866[_0xbc70('0x53')],null))[_0xbc70('0x1c')](respondWithResult(_0x1460db,null))[_0xbc70('0x24')](handleError(_0x1460db,null));};exports[_0xbc70('0x31')]=function(_0x389308,_0x1c29e0){return db[_0xbc70('0x4c')][_0xbc70('0x51')]({'where':{'id':_0x389308[_0xbc70('0x4f')]['id']}})[_0xbc70('0x1c')](handleEntityNotFound(_0x1c29e0,null))['then'](removeEntity(_0x1c29e0,null))[_0xbc70('0x24')](handleError(_0x1c29e0,null));};exports[_0xbc70('0x54')]=function(_0x3c9474,_0x280684,_0x4ac729){var _0x105dc0={};var _0x560e53={};var _0x3df172;var _0x56dc33;return db[_0xbc70('0x4c')][_0xbc70('0x55')]({'where':{'id':_0x3c9474[_0xbc70('0x4f')]['id']}})['then'](handleEntityNotFound(_0x280684,null))[_0xbc70('0x1c')](function(_0x512f27){if(_0x512f27){_0x3df172=_0x512f27;_0x560e53[_0xbc70('0x3a')]=_[_0xbc70('0x36')](db['SugarcrmConfiguration'][_0xbc70('0x50')]);_0x560e53[_0xbc70('0x37')]=_[_0xbc70('0x36')](_0x3c9474['query']);_0x560e53[_0xbc70('0x38')]=_[_0xbc70('0x39')](_0x560e53[_0xbc70('0x3a')],_0x560e53[_0xbc70('0x37')]);_0x105dc0['attributes']=_[_0xbc70('0x39')](_0x560e53[_0xbc70('0x3a')],qs[_0xbc70('0x3c')](_0x3c9474[_0xbc70('0x37')][_0xbc70('0x3c')]));_0x105dc0[_0xbc70('0x3b')]=_0x105dc0[_0xbc70('0x3b')]['length']?_0x105dc0[_0xbc70('0x3b')]:_0x560e53['model'];_0x105dc0[_0xbc70('0x3f')]=qs[_0xbc70('0x40')](_0x3c9474[_0xbc70('0x37')][_0xbc70('0x40')]);_0x105dc0['where']=qs[_0xbc70('0x38')](_[_0xbc70('0x42')](_0x3c9474[_0xbc70('0x37')],_0x560e53[_0xbc70('0x38')]));if(_0x3c9474['query'][_0xbc70('0x43')]){_0x105dc0[_0xbc70('0x41')]=_['merge'](_0x105dc0[_0xbc70('0x41')],{'$or':_['map'](_0x105dc0['attributes'],function(_0x317322){var _0x408f90={};_0x408f90[_0x317322]={'$like':'%'+_0x3c9474[_0xbc70('0x37')][_0xbc70('0x43')]+'%'};return _0x408f90;})});}_0x105dc0=_['merge']({},_0x105dc0,_0x3c9474[_0xbc70('0x56')]);return _0x3df172[_0xbc70('0x54')](_0x105dc0);}})['then'](function(_0x3b0116){if(_0x3b0116){_0x56dc33=_0x3b0116['length'];if(!_0x3c9474[_0xbc70('0x37')]['hasOwnProperty'](_0xbc70('0x3e'))){_0x105dc0[_0xbc70('0x2b')]=qs[_0xbc70('0x2b')](_0x3c9474[_0xbc70('0x37')][_0xbc70('0x2b')]);_0x105dc0[_0xbc70('0x2a')]=qs[_0xbc70('0x2a')](_0x3c9474[_0xbc70('0x37')][_0xbc70('0x2a')]);}return _0x3df172['getConfigurations'](_0x105dc0);}})[_0xbc70('0x1c')](function(_0x5a2336){if(_0x5a2336){return _0x5a2336?{'count':_0x56dc33,'rows':_0x5a2336}:null;}})['then'](respondWithResult(_0x280684,null))['catch'](handleError(_0x280684,null));};exports['addConfiguration']=function(_0x125c9d,_0x3dd2b0,_0x5bd9ae){if(_0x125c9d[_0xbc70('0x53')]['id']){delete _0x125c9d[_0xbc70('0x53')]['id'];}return db['SugarcrmAccount'][_0xbc70('0x55')]({'where':{'id':_0x125c9d[_0xbc70('0x4f')]['id']}})[_0xbc70('0x1c')](handleEntityNotFound(_0x3dd2b0,null))[_0xbc70('0x1c')](function(_0x5087cd){if(_0x5087cd){_0x125c9d[_0xbc70('0x53')]['AccountId']=_0x5087cd['id'];_0x125c9d[_0xbc70('0x53')]['Subjects']=integrations[_0xbc70('0x57')](_0x125c9d[_0xbc70('0x53')]['channel'],_0x125c9d[_0xbc70('0x53')][_0xbc70('0x45')]);_0x125c9d[_0xbc70('0x53')][_0xbc70('0x58')]=integrations[_0xbc70('0x59')](_0x125c9d['body'][_0xbc70('0x5a')],_0x125c9d[_0xbc70('0x53')][_0xbc70('0x45')]);return db['SugarcrmConfiguration'][_0xbc70('0x52')](_0x125c9d['body'],{'include':[{'model':db['SugarcrmField'],'as':_0xbc70('0x5b')},{'model':db[_0xbc70('0x5c')],'as':'Descriptions'}]});}return null;})[_0xbc70('0x1c')](respondWithResult(_0x3dd2b0,null))[_0xbc70('0x24')](handleError(_0x3dd2b0,null));};exports[_0xbc70('0x5d')]=function(_0x4c5844,_0x2f7a63,_0x1f4499){var _0x270f5c;var _0x347ed1=['id',_0xbc70('0x33'),_0xbc70('0x5e'),_0xbc70('0x5f'),_0xbc70('0x60'),_0xbc70('0x61'),_0xbc70('0x62'),_0xbc70('0x63'),_0xbc70('0x64'),_0xbc70('0x65'),_0xbc70('0x66'),_0xbc70('0x67')];return db[_0xbc70('0x4c')][_0xbc70('0x55')]({'where':{'id':_0x4c5844[_0xbc70('0x4f')]['id']},'attributes':['id',_0xbc70('0x68'),_0xbc70('0x69'),'remoteUri']})['then'](handleEntityNotFound(_0x2f7a63,null))[_0xbc70('0x1c')](function(_0x4fac47){if(_0x4fac47){_0x270f5c=_0x4fac47[_0xbc70('0x6a')];return rp({'method':'POST','uri':util[_0xbc70('0x6b')](_0xbc70('0x6c'),_0x270f5c,_0xbc70('0x6d')),'json':!![],'form':{'method':_0xbc70('0x6e'),'input_type':_0xbc70('0x6f'),'response_type':_0xbc70('0x6f'),'rest_data':JSON['stringify']({'user_auth':{'user_name':_0x4fac47[_0xbc70('0x68')],'password':_0x4fac47['password'],'encryption':_0xbc70('0x70')},'application':_0xbc70('0x71')})}});}})[_0xbc70('0x1c')](function(_0x274a4d){if(_0x274a4d&&_0x274a4d['name']!==_0xbc70('0x72')&&_0x274a4d[_0xbc70('0x33')]!==_0xbc70('0x73')){return rp({'method':_0xbc70('0x74'),'uri':util[_0xbc70('0x6b')](_0xbc70('0x6c'),_0x270f5c,_0xbc70('0x6d')),'json':!![],'form':{'method':_0xbc70('0x75'),'input_type':_0xbc70('0x6f'),'response_type':_0xbc70('0x6f'),'rest_data':JSON[_0xbc70('0x20')]({'session':_0x274a4d['id'],'module_name':_0xbc70('0x76')})}})['then'](function(_0x48cdb4){if(_0x48cdb4){var _0x42ce38=_[_0xbc70('0x77')](_0x48cdb4['module_fields']);_[_0xbc70('0x78')](_0x42ce38,function(_0x360a14){return _0x347ed1['includes'](_0x360a14[_0xbc70('0x33')]);});return{'count':_0x42ce38[_0xbc70('0x79')],'rows':_[_0xbc70('0x44')](_0x42ce38,function(_0x29c17c){return{'id':_0x29c17c[_0xbc70('0x33')],'name':_0x29c17c[_0xbc70('0x7a')],'custom':_['endsWith'](_0x29c17c['name'],'_c')?!![]:![],'options':_0x29c17c[_0xbc70('0x56')]?_['map'](_[_0xbc70('0x77')](_0x29c17c[_0xbc70('0x56')]),function(_0x5d04a5){return{'name':_0x5d04a5[_0xbc70('0x7b')],'value':_0x5d04a5['name']};}):[]};})};}})['then'](respondWithResult(_0x2f7a63,null))[_0xbc70('0x24')](function(_0x593535){var _0x49d410=_0x4c5844[_0xbc70('0x37')][_0xbc70('0x7c')]?0x1f4:_0x593535[_0xbc70('0x7d')]||0x1f4;logger[_0xbc70('0x21')]('getFields,\x20%s,\x20%s,\x20%s','getFields',_0x49d410,JSON[_0xbc70('0x20')](_0x593535));delete _0x593535['name'];if(_0x49d410===0x191){_0x49d410=0x190;}_0x2f7a63['status'](_0x49d410)[_0xbc70('0x34')](_0x4c5844[_0xbc70('0x37')][_0xbc70('0x7c')]?{'message':_0xbc70('0x7e'),'statusCode':_0x593535['statusCode']}:_0x593535);});}else{var _0x98b2e1=0x1f4;_0x2f7a63[_0xbc70('0x27')](_0x98b2e1)['send']({'message':'Wrong\x20credentials','statusCode':0x190});}});};
\ No newline at end of file
+var _0x0f54=['info','SugarcrmAccount,\x20%s,\x20%s','request\x20sent','debug','SugarcrmAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','status','end','json','count','offset','apply','save','destroy','then','sendStatus','stack','name','send','index','SugarcrmAccount','model','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','limit','order','sort','where','pick','key','VIRTUAL','filter','merge','findAll','rows','show','params','keys','rawAttributes','include','create','body','update','find','getConfigurations','findOne','SugarcrmConfiguration','map','options','AccountId','Subjects','Descriptions','getDescriptions','channel','type','getFields','assigned_user_id','created_by','date_start','duration_hours','duration_minutes','parent_id','parent_type','parent_name','direction','password','remoteUri','format','%s%s','JSON','username','PLAIN','Invalid\x20Login','POST','/service/v4_1/rest.php','Calls','values','module_fields','remove','includes','label','value','statusCode','getFields,\x20%s,\x20%s,\x20%s','test','Wrong\x20credentials','html-pdf','eml-format','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','squel','crypto','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../config/license/hardware','../../components/parsers/qs','../../config/logger','api','../../config/utils','../../mysqldb','../../components/integrations/configuration','jayson/promise','request'];(function(_0x26462c,_0xd20a35){var _0x509a42=function(_0x1b22c9){while(--_0x1b22c9){_0x26462c['push'](_0x26462c['shift']());}};_0x509a42(++_0xd20a35);}(_0x0f54,0x1db));var _0x40f5=function(_0x5d516b,_0x347b84){_0x5d516b=_0x5d516b-0x0;var _0x3cede5=_0x0f54[_0x5d516b];return _0x3cede5;};'use strict';var pdf=require(_0x40f5('0x0'));var emlformat=require(_0x40f5('0x1'));var rimraf=require('rimraf');var zipdir=require(_0x40f5('0x2'));var jsonpatch=require(_0x40f5('0x3'));var rp=require(_0x40f5('0x4'));var moment=require(_0x40f5('0x5'));var BPromise=require(_0x40f5('0x6'));var Mustache=require(_0x40f5('0x7'));var util=require(_0x40f5('0x8'));var path=require(_0x40f5('0x9'));var sox=require(_0x40f5('0xa'));var csv=require(_0x40f5('0xb'));var ejs=require(_0x40f5('0xc'));var fs=require('fs');var _=require('lodash');var squel=require(_0x40f5('0xd'));var crypto=require(_0x40f5('0xe'));var jsforce=require(_0x40f5('0xf'));var deskjs=require(_0x40f5('0x10'));var toCsv=require(_0x40f5('0xb'));var querystring=require(_0x40f5('0x11'));var Papa=require(_0x40f5('0x12'));var authService=require(_0x40f5('0x13'));var hardwareService=require(_0x40f5('0x14'));var Redis=require('ioredis');var qs=require(_0x40f5('0x15'));var logger=require(_0x40f5('0x16'))(_0x40f5('0x17'));var utils=require(_0x40f5('0x18'));var config=require('../../config/environment');var db=require(_0x40f5('0x19'))['db'];var integrations=require(_0x40f5('0x1a'));var jayson=require(_0x40f5('0x1b'));var client=jayson['client']['http']({'port':0x232a});function respondWithRpcPromise(_0x320763,_0x3e690b,_0x526bd1,_0x52489a){return new BPromise(function(_0x5c12ed,_0x10ae08){var _0x3c4913=_0x52489a||client;return _0x3c4913[_0x40f5('0x1c')](_0x320763,_0x526bd1)['then'](function(_0x462cb1){logger[_0x40f5('0x1d')](_0x40f5('0x1e'),_0x3e690b,_0x40f5('0x1f'));logger[_0x40f5('0x20')](_0x40f5('0x21'),_0x3e690b,_0x40f5('0x1f'),JSON[_0x40f5('0x22')](_0x462cb1));if(_0x462cb1[_0x40f5('0x23')]){if(_0x462cb1['error'][_0x40f5('0x24')]===0x1f4){logger[_0x40f5('0x23')](_0x40f5('0x1e'),_0x3e690b,_0x462cb1['error'][_0x40f5('0x25')]);return _0x10ae08(_0x462cb1['error']['message']);}logger[_0x40f5('0x23')](_0x40f5('0x1e'),_0x3e690b,_0x462cb1[_0x40f5('0x23')][_0x40f5('0x25')]);return _0x5c12ed(_0x462cb1['error']['message']);}else{logger[_0x40f5('0x1d')]('SugarcrmAccount,\x20%s,\x20%s',_0x3e690b,'request\x20sent');_0x5c12ed(_0x462cb1[_0x40f5('0x26')][_0x40f5('0x25')]);}})[_0x40f5('0x27')](function(_0x30e8a2){logger[_0x40f5('0x23')](_0x40f5('0x1e'),_0x3e690b,_0x30e8a2);_0x10ae08(_0x30e8a2);});});}function respondWithStatusCode(_0x3a4cc7,_0x337aa4){_0x337aa4=_0x337aa4||0xcc;return function(_0x113fc8){if(_0x113fc8){return _0x3a4cc7['sendStatus'](_0x337aa4);}return _0x3a4cc7[_0x40f5('0x28')](_0x337aa4)[_0x40f5('0x29')]();};}function respondWithResult(_0x199241,_0x309262){_0x309262=_0x309262||0xc8;return function(_0x3db099){if(_0x3db099){return _0x199241['status'](_0x309262)[_0x40f5('0x2a')](_0x3db099);}};}function respondWithFilteredResult(_0x212e98,_0x5eb00d){return function(_0x1161e2){if(_0x1161e2){var _0x50d07d=_0x1161e2[_0x40f5('0x2b')],_0x50d38e=_0x5eb00d[_0x40f5('0x2c')],_0xa36029=_0x5eb00d['offset']+_0x5eb00d['limit'],_0x1a1a22;if(_0xa36029>=_0x50d07d){_0xa36029=_0x50d07d;_0x1a1a22=0xc8;}else{_0x1a1a22=0xce;}_0x212e98[_0x40f5('0x28')](_0x1a1a22);return _0x212e98['set']('Content-Range',_0x50d38e+'-'+_0xa36029+'/'+_0x50d07d)[_0x40f5('0x2a')](_0x1161e2);}return null;};}function patchUpdates(_0x199204){return function(_0x4cf548){try{jsonpatch[_0x40f5('0x2d')](_0x4cf548,_0x199204,!![]);}catch(_0x4a4d9e){return BPromise['reject'](_0x4a4d9e);}return _0x4cf548[_0x40f5('0x2e')]();};}function saveUpdates(_0x1e3c21,_0x201552){return function(_0x57f30f){if(_0x57f30f){return _0x57f30f['update'](_0x1e3c21)['then'](function(_0x277b0f){return _0x277b0f;});}return null;};}function removeEntity(_0x29873f,_0x4d1b66){return function(_0x4d2725){if(_0x4d2725){return _0x4d2725[_0x40f5('0x2f')]()[_0x40f5('0x30')](function(){_0x29873f[_0x40f5('0x28')](0xcc)[_0x40f5('0x29')]();});}};}function handleEntityNotFound(_0x1e41ab,_0x956b6){return function(_0x5d2bf6){if(!_0x5d2bf6){_0x1e41ab[_0x40f5('0x31')](0x194);}return _0x5d2bf6;};}function handleError(_0x2508f6,_0x436c40){_0x436c40=_0x436c40||0x1f4;return function(_0x1b97de){logger['error'](_0x1b97de[_0x40f5('0x32')]);if(_0x1b97de[_0x40f5('0x33')]){delete _0x1b97de[_0x40f5('0x33')];}_0x2508f6[_0x40f5('0x28')](_0x436c40)[_0x40f5('0x34')](_0x1b97de);};}exports[_0x40f5('0x35')]=function(_0x2075c5,_0x5b3458){var _0x2a0d90={},_0xb8947e={},_0x4af8fc={'count':0x0,'rows':[]};var _0x171d8f=db[_0x40f5('0x36')]['rawAttributes'];_0xb8947e[_0x40f5('0x37')]=_['keys'](_0x171d8f);_0xb8947e['query']=_['keys'](_0x2075c5[_0x40f5('0x38')]);_0xb8947e[_0x40f5('0x39')]=_[_0x40f5('0x3a')](_0xb8947e['model'],_0xb8947e['query']);_0x2a0d90[_0x40f5('0x3b')]=_['intersection'](_0xb8947e[_0x40f5('0x37')],qs[_0x40f5('0x3c')](_0x2075c5['query'][_0x40f5('0x3c')]));_0x2a0d90[_0x40f5('0x3b')]=_0x2a0d90[_0x40f5('0x3b')][_0x40f5('0x3d')]?_0x2a0d90[_0x40f5('0x3b')]:_0xb8947e['model'];if(!_0x2075c5[_0x40f5('0x38')][_0x40f5('0x3e')](_0x40f5('0x3f'))){_0x2a0d90[_0x40f5('0x40')]=qs[_0x40f5('0x40')](_0x2075c5['query'][_0x40f5('0x40')]);_0x2a0d90[_0x40f5('0x2c')]=qs[_0x40f5('0x2c')](_0x2075c5[_0x40f5('0x38')][_0x40f5('0x2c')]);}_0x2a0d90[_0x40f5('0x41')]=qs[_0x40f5('0x42')](_0x2075c5[_0x40f5('0x38')][_0x40f5('0x42')]);_0x2a0d90[_0x40f5('0x43')]=qs[_0x40f5('0x39')](_[_0x40f5('0x44')](_0x2075c5[_0x40f5('0x38')],_0xb8947e[_0x40f5('0x39')]));if(_0x2075c5[_0x40f5('0x38')]['filter']){_0x2a0d90[_0x40f5('0x43')]=_['merge'](_0x2a0d90['where'],{'$or':_['map'](_0x171d8f,function(_0x2ee41b){if(_0x2ee41b['type'][_0x40f5('0x45')]!==_0x40f5('0x46')){var _0x3a8e96={};_0x3a8e96[_0x2ee41b['field']]={'$like':'%'+_0x2075c5[_0x40f5('0x38')][_0x40f5('0x47')]+'%'};return _0x3a8e96;}})});}_0x2a0d90=_[_0x40f5('0x48')]({},_0x2a0d90,_0x2075c5['options']);var _0x6aee2d={'where':_0x2a0d90['where']};return db[_0x40f5('0x36')][_0x40f5('0x2b')](_0x6aee2d)['then'](function(_0x560942){_0x4af8fc[_0x40f5('0x2b')]=_0x560942;if(_0x2075c5[_0x40f5('0x38')]['includeAll']){_0x2a0d90['include']=[{'all':!![]}];}return db[_0x40f5('0x36')][_0x40f5('0x49')](_0x2a0d90);})[_0x40f5('0x30')](function(_0x16fec9){_0x4af8fc[_0x40f5('0x4a')]=_0x16fec9;return _0x4af8fc;})['then'](respondWithFilteredResult(_0x5b3458,_0x2a0d90))[_0x40f5('0x27')](handleError(_0x5b3458,null));};exports[_0x40f5('0x4b')]=function(_0x422225,_0x5a1c8f){var _0x20a71c={'raw':![],'where':{'id':_0x422225[_0x40f5('0x4c')]['id']}},_0x2ab929={};_0x2ab929[_0x40f5('0x37')]=_[_0x40f5('0x4d')](db['SugarcrmAccount'][_0x40f5('0x4e')]);_0x2ab929[_0x40f5('0x38')]=_['keys'](_0x422225[_0x40f5('0x38')]);_0x2ab929[_0x40f5('0x39')]=_[_0x40f5('0x3a')](_0x2ab929[_0x40f5('0x37')],_0x2ab929[_0x40f5('0x38')]);_0x20a71c[_0x40f5('0x3b')]=_['intersection'](_0x2ab929['model'],qs[_0x40f5('0x3c')](_0x422225['query'][_0x40f5('0x3c')]));_0x20a71c[_0x40f5('0x3b')]=_0x20a71c['attributes'][_0x40f5('0x3d')]?_0x20a71c[_0x40f5('0x3b')]:_0x2ab929[_0x40f5('0x37')];if(_0x422225['query']['includeAll']){_0x20a71c[_0x40f5('0x4f')]=[{'all':!![]}];}_0x20a71c=_[_0x40f5('0x48')]({},_0x20a71c,_0x422225['options']);return db[_0x40f5('0x36')]['find'](_0x20a71c)[_0x40f5('0x30')](handleEntityNotFound(_0x5a1c8f,null))[_0x40f5('0x30')](respondWithResult(_0x5a1c8f,null))[_0x40f5('0x27')](handleError(_0x5a1c8f,null));};exports[_0x40f5('0x50')]=function(_0x191a86,_0x26e0c3){return db[_0x40f5('0x36')][_0x40f5('0x50')](_0x191a86[_0x40f5('0x51')],{})['then'](respondWithResult(_0x26e0c3,0xc9))['catch'](handleError(_0x26e0c3,null));};exports[_0x40f5('0x52')]=function(_0x21c3ae,_0x404a2d){if(_0x21c3ae[_0x40f5('0x51')]['id']){delete _0x21c3ae[_0x40f5('0x51')]['id'];}return db[_0x40f5('0x36')][_0x40f5('0x53')]({'where':{'id':_0x21c3ae[_0x40f5('0x4c')]['id']}})['then'](handleEntityNotFound(_0x404a2d,null))[_0x40f5('0x30')](saveUpdates(_0x21c3ae[_0x40f5('0x51')],null))[_0x40f5('0x30')](respondWithResult(_0x404a2d,null))[_0x40f5('0x27')](handleError(_0x404a2d,null));};exports['destroy']=function(_0x4352c9,_0x4c2e2c){return db[_0x40f5('0x36')][_0x40f5('0x53')]({'where':{'id':_0x4352c9[_0x40f5('0x4c')]['id']}})[_0x40f5('0x30')](handleEntityNotFound(_0x4c2e2c,null))[_0x40f5('0x30')](removeEntity(_0x4c2e2c,null))['catch'](handleError(_0x4c2e2c,null));};exports[_0x40f5('0x54')]=function(_0x1a9154,_0x3c2cff,_0x3d6cfd){var _0x531a2d={};var _0x4e46cc={};var _0x541870;var _0x55851e;return db['SugarcrmAccount'][_0x40f5('0x55')]({'where':{'id':_0x1a9154[_0x40f5('0x4c')]['id']}})[_0x40f5('0x30')](handleEntityNotFound(_0x3c2cff,null))[_0x40f5('0x30')](function(_0x41a95a){if(_0x41a95a){_0x541870=_0x41a95a;_0x4e46cc['model']=_[_0x40f5('0x4d')](db[_0x40f5('0x56')][_0x40f5('0x4e')]);_0x4e46cc[_0x40f5('0x38')]=_[_0x40f5('0x4d')](_0x1a9154[_0x40f5('0x38')]);_0x4e46cc[_0x40f5('0x39')]=_['intersection'](_0x4e46cc[_0x40f5('0x37')],_0x4e46cc[_0x40f5('0x38')]);_0x531a2d[_0x40f5('0x3b')]=_[_0x40f5('0x3a')](_0x4e46cc[_0x40f5('0x37')],qs[_0x40f5('0x3c')](_0x1a9154[_0x40f5('0x38')]['fields']));_0x531a2d[_0x40f5('0x3b')]=_0x531a2d['attributes'][_0x40f5('0x3d')]?_0x531a2d['attributes']:_0x4e46cc[_0x40f5('0x37')];_0x531a2d[_0x40f5('0x41')]=qs[_0x40f5('0x42')](_0x1a9154[_0x40f5('0x38')][_0x40f5('0x42')]);_0x531a2d[_0x40f5('0x43')]=qs[_0x40f5('0x39')](_['pick'](_0x1a9154['query'],_0x4e46cc[_0x40f5('0x39')]));if(_0x1a9154['query'][_0x40f5('0x47')]){_0x531a2d[_0x40f5('0x43')]=_['merge'](_0x531a2d[_0x40f5('0x43')],{'$or':_[_0x40f5('0x57')](_0x531a2d[_0x40f5('0x3b')],function(_0x220761){var _0x45d33b={};_0x45d33b[_0x220761]={'$like':'%'+_0x1a9154['query']['filter']+'%'};return _0x45d33b;})});}_0x531a2d=_[_0x40f5('0x48')]({},_0x531a2d,_0x1a9154[_0x40f5('0x58')]);return _0x541870[_0x40f5('0x54')](_0x531a2d);}})[_0x40f5('0x30')](function(_0x59b907){if(_0x59b907){_0x55851e=_0x59b907[_0x40f5('0x3d')];if(!_0x1a9154['query'][_0x40f5('0x3e')]('nolimit')){_0x531a2d[_0x40f5('0x40')]=qs[_0x40f5('0x40')](_0x1a9154[_0x40f5('0x38')]['limit']);_0x531a2d[_0x40f5('0x2c')]=qs[_0x40f5('0x2c')](_0x1a9154[_0x40f5('0x38')][_0x40f5('0x2c')]);}return _0x541870[_0x40f5('0x54')](_0x531a2d);}})[_0x40f5('0x30')](function(_0x14b7c2){if(_0x14b7c2){return _0x14b7c2?{'count':_0x55851e,'rows':_0x14b7c2}:null;}})[_0x40f5('0x30')](respondWithResult(_0x3c2cff,null))[_0x40f5('0x27')](handleError(_0x3c2cff,null));};exports['addConfiguration']=function(_0x546726,_0x28a88e,_0x3b2171){if(_0x546726[_0x40f5('0x51')]['id']){delete _0x546726['body']['id'];}return db['SugarcrmAccount'][_0x40f5('0x55')]({'where':{'id':_0x546726['params']['id']}})[_0x40f5('0x30')](handleEntityNotFound(_0x28a88e,null))['then'](function(_0x42f3cb){if(_0x42f3cb){_0x546726['body'][_0x40f5('0x59')]=_0x42f3cb['id'];_0x546726[_0x40f5('0x51')][_0x40f5('0x5a')]=integrations['getSubjects'](_0x546726[_0x40f5('0x51')]['channel'],_0x546726[_0x40f5('0x51')]['type']);_0x546726[_0x40f5('0x51')][_0x40f5('0x5b')]=integrations[_0x40f5('0x5c')](_0x546726[_0x40f5('0x51')][_0x40f5('0x5d')],_0x546726[_0x40f5('0x51')][_0x40f5('0x5e')]);return db['SugarcrmConfiguration'][_0x40f5('0x50')](_0x546726[_0x40f5('0x51')],{'include':[{'model':db['SugarcrmField'],'as':_0x40f5('0x5a')},{'model':db['SugarcrmField'],'as':_0x40f5('0x5b')}]});}return null;})[_0x40f5('0x30')](respondWithResult(_0x28a88e,null))['catch'](handleError(_0x28a88e,null));};exports[_0x40f5('0x5f')]=function(_0x1d9cba,_0x40d673,_0x443044){var _0x2e3602;var _0x24d954=['id',_0x40f5('0x33'),_0x40f5('0x60'),_0x40f5('0x61'),'description',_0x40f5('0x62'),_0x40f5('0x63'),_0x40f5('0x64'),_0x40f5('0x65'),_0x40f5('0x66'),_0x40f5('0x67'),_0x40f5('0x68')];return db[_0x40f5('0x36')][_0x40f5('0x55')]({'where':{'id':_0x1d9cba[_0x40f5('0x4c')]['id']},'attributes':['id','username',_0x40f5('0x69'),'remoteUri']})[_0x40f5('0x30')](handleEntityNotFound(_0x40d673,null))['then'](function(_0x2f23b6){if(_0x2f23b6){_0x2e3602=_0x2f23b6[_0x40f5('0x6a')];return rp({'method':'POST','uri':util[_0x40f5('0x6b')](_0x40f5('0x6c'),_0x2e3602,'/service/v4_1/rest.php'),'json':!![],'form':{'method':'login','input_type':_0x40f5('0x6d'),'response_type':_0x40f5('0x6d'),'rest_data':JSON[_0x40f5('0x22')]({'user_auth':{'user_name':_0x2f23b6[_0x40f5('0x6e')],'password':_0x2f23b6[_0x40f5('0x69')],'encryption':_0x40f5('0x6f')},'application':'xCALLY\x20Motion\x20Integration'})}});}})[_0x40f5('0x30')](function(_0x158fd3){if(_0x158fd3&&_0x158fd3[_0x40f5('0x33')]!==_0x40f5('0x70')&&_0x158fd3[_0x40f5('0x33')]!=='Password\x20Expired'){return rp({'method':_0x40f5('0x71'),'uri':util['format'](_0x40f5('0x6c'),_0x2e3602,_0x40f5('0x72')),'json':!![],'form':{'method':'get_module_fields','input_type':'JSON','response_type':'JSON','rest_data':JSON[_0x40f5('0x22')]({'session':_0x158fd3['id'],'module_name':_0x40f5('0x73')})}})[_0x40f5('0x30')](function(_0x3e029f){if(_0x3e029f){var _0x473998=_[_0x40f5('0x74')](_0x3e029f[_0x40f5('0x75')]);_[_0x40f5('0x76')](_0x473998,function(_0xdcdf83){return _0x24d954[_0x40f5('0x77')](_0xdcdf83[_0x40f5('0x33')]);});return{'count':_0x473998['length'],'rows':_[_0x40f5('0x57')](_0x473998,function(_0xd79031){return{'id':_0xd79031['name'],'name':_0xd79031[_0x40f5('0x78')],'custom':_['endsWith'](_0xd79031[_0x40f5('0x33')],'_c')?!![]:![],'options':_0xd79031[_0x40f5('0x58')]?_[_0x40f5('0x57')](_[_0x40f5('0x74')](_0xd79031['options']),function(_0x30748f){return{'name':_0x30748f[_0x40f5('0x79')],'value':_0x30748f[_0x40f5('0x33')]};}):[]};})};}})[_0x40f5('0x30')](respondWithResult(_0x40d673,null))['catch'](function(_0x150e08){var _0x41e78e=_0x1d9cba['query']['test']?0x1f4:_0x150e08[_0x40f5('0x7a')]||0x1f4;logger[_0x40f5('0x23')](_0x40f5('0x7b'),_0x40f5('0x5f'),_0x41e78e,JSON[_0x40f5('0x22')](_0x150e08));delete _0x150e08[_0x40f5('0x33')];if(_0x41e78e===0x191){_0x41e78e=0x190;}_0x40d673[_0x40f5('0x28')](_0x41e78e)[_0x40f5('0x34')](_0x1d9cba[_0x40f5('0x38')][_0x40f5('0x7c')]?{'message':_0x40f5('0x7d'),'statusCode':_0x150e08[_0x40f5('0x7a')]}:_0x150e08);});}else{var _0x3aea38=0x1f4;_0x40d673[_0x40f5('0x28')](_0x3aea38)[_0x40f5('0x34')]({'message':_0x40f5('0x7d'),'statusCode':0x190});}});};
\ No newline at end of file