Built motion from commit 5b761a7b.|2.5.36
[motion2.git] / server / api / intSugarcrmAccount / intSugarcrmAccount.controller.js
index ec4475b..3169b47 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x65f6=['catch','sendStatus','status','end','json','limit','set','Content-Range','apply','reject','save','then','stack','name','index','map','rawAttributes','fieldName','key','model','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','offset','order','sort','where','pick','merge','type','VIRTUAL','options','SugarcrmAccount','count','includeAll','include','findAll','rows','show','params','keys','find','create','body','update','destroy','getConfigurations','findOne','SugarcrmConfiguration','filter','addConfiguration','channel','Descriptions','getDescriptions','SugarcrmField','getFields','created_by','date_start','parent_id','direction','password','remoteUri','slice','substring','lastIndexOf','/service/v4_1/rest.php','login','JSON','username','PLAIN','xCALLY\x20Motion\x20Integration','Password\x20Expired','POST','format','%s%s','get_module_fields','Calls','values','module_fields','remove','label','endsWith','value','send','test','Wrong\x20credentials','statusCode','html-pdf','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','to-csv','lodash','squel','jsforce','querystring','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','../../components/integrations/configuration','jayson/promise','client','http','request','SugarcrmAccount,\x20%s,\x20%s','request\x20sent','debug','SugarcrmAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','info','result'];(function(_0x3872b4,_0x4d6083){var _0x27a63d=function(_0x7d4be5){while(--_0x7d4be5){_0x3872b4['push'](_0x3872b4['shift']());}};_0x27a63d(++_0x4d6083);}(_0x65f6,0xdb));var _0x665f=function(_0x523d34,_0x5e8c35){_0x523d34=_0x523d34-0x0;var _0x1d044a=_0x65f6[_0x523d34];return _0x1d044a;};'use strict';var pdf=require(_0x665f('0x0'));var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0x665f('0x1'));var jsonpatch=require(_0x665f('0x2'));var rp=require(_0x665f('0x3'));var moment=require(_0x665f('0x4'));var BPromise=require(_0x665f('0x5'));var Mustache=require('mustache');var util=require(_0x665f('0x6'));var path=require('path');var sox=require('sox');var csv=require(_0x665f('0x7'));var ejs=require('ejs');var fs=require('fs');var _=require(_0x665f('0x8'));var squel=require(_0x665f('0x9'));var crypto=require('crypto');var jsforce=require(_0x665f('0xa'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0x665f('0xb'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0x665f('0xc'));var qs=require(_0x665f('0xd'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x665f('0xe'));var logger=require(_0x665f('0xf'))('api');var utils=require(_0x665f('0x10'));var config=require(_0x665f('0x11'));var licenseUtil=require(_0x665f('0x12'));var db=require(_0x665f('0x13'))['db'];var integrations=require(_0x665f('0x14'));var jayson=require(_0x665f('0x15'));var client=jayson[_0x665f('0x16')][_0x665f('0x17')]({'port':0x232a});function respondWithRpcPromise(_0x1d587b,_0x263830,_0x169fb8,_0x2525b0){return new BPromise(function(_0x5681d3,_0x3c8ae2){var _0x551e1c=_0x2525b0||client;return _0x551e1c[_0x665f('0x18')](_0x1d587b,_0x169fb8)['then'](function(_0x24f3b1){logger['info'](_0x665f('0x19'),_0x263830,_0x665f('0x1a'));logger[_0x665f('0x1b')](_0x665f('0x1c'),_0x263830,_0x665f('0x1a'),JSON[_0x665f('0x1d')](_0x24f3b1));if(_0x24f3b1[_0x665f('0x1e')]){if(_0x24f3b1[_0x665f('0x1e')][_0x665f('0x1f')]===0x1f4){logger[_0x665f('0x1e')](_0x665f('0x19'),_0x263830,_0x24f3b1[_0x665f('0x1e')][_0x665f('0x20')]);return _0x3c8ae2(_0x24f3b1[_0x665f('0x1e')][_0x665f('0x20')]);}logger[_0x665f('0x1e')](_0x665f('0x19'),_0x263830,_0x24f3b1[_0x665f('0x1e')][_0x665f('0x20')]);return _0x5681d3(_0x24f3b1[_0x665f('0x1e')][_0x665f('0x20')]);}else{logger[_0x665f('0x21')](_0x665f('0x19'),_0x263830,_0x665f('0x1a'));_0x5681d3(_0x24f3b1[_0x665f('0x22')]['message']);}})[_0x665f('0x23')](function(_0x450cb1){logger[_0x665f('0x1e')](_0x665f('0x19'),_0x263830,_0x450cb1);_0x3c8ae2(_0x450cb1);});});}function respondWithStatusCode(_0x54b1ad,_0x13546c){_0x13546c=_0x13546c||0xcc;return function(_0x504b98){if(_0x504b98){return _0x54b1ad[_0x665f('0x24')](_0x13546c);}return _0x54b1ad[_0x665f('0x25')](_0x13546c)[_0x665f('0x26')]();};}function respondWithResult(_0x5aca4d,_0x259425){_0x259425=_0x259425||0xc8;return function(_0x227e0f){if(_0x227e0f){return _0x5aca4d['status'](_0x259425)[_0x665f('0x27')](_0x227e0f);}};}function respondWithFilteredResult(_0x451fb7,_0x439b5a){return function(_0x3f74eb){if(_0x3f74eb){var _0x390558=_0x3f74eb['count'],_0x1c5fe9=_0x439b5a['offset'],_0x48dae9=_0x439b5a['offset']+_0x439b5a[_0x665f('0x28')],_0xb69e72;if(_0x48dae9>=_0x390558){_0x48dae9=_0x390558;_0xb69e72=0xc8;}else{_0xb69e72=0xce;}_0x451fb7['status'](_0xb69e72);return _0x451fb7[_0x665f('0x29')](_0x665f('0x2a'),_0x1c5fe9+'-'+_0x48dae9+'/'+_0x390558)['json'](_0x3f74eb);}return null;};}function patchUpdates(_0x24f37d){return function(_0x2b5c47){try{jsonpatch[_0x665f('0x2b')](_0x2b5c47,_0x24f37d,!![]);}catch(_0x2a85b7){return BPromise[_0x665f('0x2c')](_0x2a85b7);}return _0x2b5c47[_0x665f('0x2d')]();};}function saveUpdates(_0x142432,_0x1ad384){return function(_0x37bb2d){if(_0x37bb2d){return _0x37bb2d['update'](_0x142432)['then'](function(_0x151742){return _0x151742;});}return null;};}function removeEntity(_0x4eee83,_0x3e1b0c){return function(_0x358e65){if(_0x358e65){return _0x358e65['destroy']()[_0x665f('0x2e')](function(){_0x4eee83[_0x665f('0x25')](0xcc)[_0x665f('0x26')]();});}};}function handleEntityNotFound(_0x541409,_0x281a00){return function(_0x5e891c){if(!_0x5e891c){_0x541409[_0x665f('0x24')](0x194);}return _0x5e891c;};}function handleError(_0x3ce6a7,_0x402973){_0x402973=_0x402973||0x1f4;return function(_0x154619){logger[_0x665f('0x1e')](_0x154619[_0x665f('0x2f')]);if(_0x154619['name']){delete _0x154619[_0x665f('0x30')];}_0x3ce6a7[_0x665f('0x25')](_0x402973)['send'](_0x154619);};}exports[_0x665f('0x31')]=function(_0x5717f7,_0x4b5ba5){var _0x2dbcf4={},_0x1a8a5a={},_0x2fd2de={'count':0x0,'rows':[]};var _0xb62f06=_[_0x665f('0x32')](db['SugarcrmAccount'][_0x665f('0x33')],function(_0x1d47bc){return{'name':_0x1d47bc[_0x665f('0x34')],'type':_0x1d47bc['type'][_0x665f('0x35')]};});_0x1a8a5a[_0x665f('0x36')]=_[_0x665f('0x32')](_0xb62f06,_0x665f('0x30'));_0x1a8a5a['query']=_['keys'](_0x5717f7[_0x665f('0x37')]);_0x1a8a5a[_0x665f('0x38')]=_[_0x665f('0x39')](_0x1a8a5a['model'],_0x1a8a5a[_0x665f('0x37')]);_0x2dbcf4[_0x665f('0x3a')]=_[_0x665f('0x39')](_0x1a8a5a[_0x665f('0x36')],qs[_0x665f('0x3b')](_0x5717f7[_0x665f('0x37')][_0x665f('0x3b')]));_0x2dbcf4[_0x665f('0x3a')]=_0x2dbcf4[_0x665f('0x3a')][_0x665f('0x3c')]?_0x2dbcf4[_0x665f('0x3a')]:_0x1a8a5a[_0x665f('0x36')];if(!_0x5717f7[_0x665f('0x37')][_0x665f('0x3d')](_0x665f('0x3e'))){_0x2dbcf4[_0x665f('0x28')]=qs[_0x665f('0x28')](_0x5717f7[_0x665f('0x37')][_0x665f('0x28')]);_0x2dbcf4[_0x665f('0x3f')]=qs[_0x665f('0x3f')](_0x5717f7[_0x665f('0x37')][_0x665f('0x3f')]);}_0x2dbcf4[_0x665f('0x40')]=qs[_0x665f('0x41')](_0x5717f7[_0x665f('0x37')][_0x665f('0x41')]);_0x2dbcf4[_0x665f('0x42')]=qs['filters'](_[_0x665f('0x43')](_0x5717f7['query'],_0x1a8a5a[_0x665f('0x38')]),_0xb62f06);if(_0x5717f7[_0x665f('0x37')]['filter']){_0x2dbcf4[_0x665f('0x42')]=_[_0x665f('0x44')](_0x2dbcf4['where'],{'$or':_[_0x665f('0x32')](_0xb62f06,function(_0x40b213){if(_0x40b213[_0x665f('0x45')]!==_0x665f('0x46')){var _0x252fdb={};_0x252fdb[_0x40b213[_0x665f('0x30')]]={'$like':'%'+_0x5717f7['query']['filter']+'%'};return _0x252fdb;}})});}_0x2dbcf4=_[_0x665f('0x44')]({},_0x2dbcf4,_0x5717f7[_0x665f('0x47')]);var _0x3db9b9={'where':_0x2dbcf4[_0x665f('0x42')]};return db[_0x665f('0x48')][_0x665f('0x49')](_0x3db9b9)[_0x665f('0x2e')](function(_0x55bd26){_0x2fd2de[_0x665f('0x49')]=_0x55bd26;if(_0x5717f7[_0x665f('0x37')][_0x665f('0x4a')]){_0x2dbcf4[_0x665f('0x4b')]=[{'all':!![]}];}return db[_0x665f('0x48')][_0x665f('0x4c')](_0x2dbcf4);})[_0x665f('0x2e')](function(_0x3bd074){_0x2fd2de[_0x665f('0x4d')]=_0x3bd074;return _0x2fd2de;})[_0x665f('0x2e')](respondWithFilteredResult(_0x4b5ba5,_0x2dbcf4))[_0x665f('0x23')](handleError(_0x4b5ba5,null));};exports[_0x665f('0x4e')]=function(_0x1b4c73,_0x4a27c9){var _0x2dbde7={'raw':![],'where':{'id':_0x1b4c73[_0x665f('0x4f')]['id']}},_0x300c41={};_0x300c41[_0x665f('0x36')]=_[_0x665f('0x50')](db[_0x665f('0x48')][_0x665f('0x33')]);_0x300c41['query']=_[_0x665f('0x50')](_0x1b4c73[_0x665f('0x37')]);_0x300c41[_0x665f('0x38')]=_['intersection'](_0x300c41[_0x665f('0x36')],_0x300c41[_0x665f('0x37')]);_0x2dbde7[_0x665f('0x3a')]=_[_0x665f('0x39')](_0x300c41[_0x665f('0x36')],qs[_0x665f('0x3b')](_0x1b4c73['query']['fields']));_0x2dbde7[_0x665f('0x3a')]=_0x2dbde7['attributes']['length']?_0x2dbde7[_0x665f('0x3a')]:_0x300c41[_0x665f('0x36')];if(_0x1b4c73[_0x665f('0x37')][_0x665f('0x4a')]){_0x2dbde7[_0x665f('0x4b')]=[{'all':!![]}];}_0x2dbde7=_[_0x665f('0x44')]({},_0x2dbde7,_0x1b4c73['options']);return db[_0x665f('0x48')][_0x665f('0x51')](_0x2dbde7)[_0x665f('0x2e')](handleEntityNotFound(_0x4a27c9,null))['then'](respondWithResult(_0x4a27c9,null))[_0x665f('0x23')](handleError(_0x4a27c9,null));};exports[_0x665f('0x52')]=function(_0x3d503e,_0x16a91e){return db['SugarcrmAccount'][_0x665f('0x52')](_0x3d503e[_0x665f('0x53')],{})[_0x665f('0x2e')](respondWithResult(_0x16a91e,0xc9))[_0x665f('0x23')](handleError(_0x16a91e,null));};exports[_0x665f('0x54')]=function(_0x2e6d49,_0x1316c6){if(_0x2e6d49[_0x665f('0x53')]['id']){delete _0x2e6d49[_0x665f('0x53')]['id'];}return db[_0x665f('0x48')][_0x665f('0x51')]({'where':{'id':_0x2e6d49['params']['id']}})[_0x665f('0x2e')](handleEntityNotFound(_0x1316c6,null))[_0x665f('0x2e')](saveUpdates(_0x2e6d49[_0x665f('0x53')],null))[_0x665f('0x2e')](respondWithResult(_0x1316c6,null))[_0x665f('0x23')](handleError(_0x1316c6,null));};exports[_0x665f('0x55')]=function(_0x313fd7,_0x55c0be){return db[_0x665f('0x48')]['find']({'where':{'id':_0x313fd7[_0x665f('0x4f')]['id']}})[_0x665f('0x2e')](handleEntityNotFound(_0x55c0be,null))[_0x665f('0x2e')](removeEntity(_0x55c0be,null))[_0x665f('0x23')](handleError(_0x55c0be,null));};exports[_0x665f('0x56')]=function(_0x4b415b,_0x18a76f,_0x5a4a05){var _0x443508={};var _0x5105b5={};var _0x383d64;var _0x5c5ca3;return db[_0x665f('0x48')][_0x665f('0x57')]({'where':{'id':_0x4b415b['params']['id']}})['then'](handleEntityNotFound(_0x18a76f,null))['then'](function(_0x39a5be){if(_0x39a5be){_0x383d64=_0x39a5be;_0x5105b5[_0x665f('0x36')]=_[_0x665f('0x50')](db[_0x665f('0x58')][_0x665f('0x33')]);_0x5105b5['query']=_[_0x665f('0x50')](_0x4b415b[_0x665f('0x37')]);_0x5105b5[_0x665f('0x38')]=_[_0x665f('0x39')](_0x5105b5['model'],_0x5105b5[_0x665f('0x37')]);_0x443508['attributes']=_[_0x665f('0x39')](_0x5105b5[_0x665f('0x36')],qs[_0x665f('0x3b')](_0x4b415b['query'][_0x665f('0x3b')]));_0x443508[_0x665f('0x3a')]=_0x443508[_0x665f('0x3a')]['length']?_0x443508[_0x665f('0x3a')]:_0x5105b5['model'];_0x443508['order']=qs['sort'](_0x4b415b[_0x665f('0x37')]['sort']);_0x443508['where']=qs[_0x665f('0x38')](_['pick'](_0x4b415b[_0x665f('0x37')],_0x5105b5[_0x665f('0x38')]));if(_0x4b415b[_0x665f('0x37')][_0x665f('0x59')]){_0x443508[_0x665f('0x42')]=_[_0x665f('0x44')](_0x443508['where'],{'$or':_[_0x665f('0x32')](_0x443508[_0x665f('0x3a')],function(_0x704dc2){var _0x2aa11a={};_0x2aa11a[_0x704dc2]={'$like':'%'+_0x4b415b[_0x665f('0x37')][_0x665f('0x59')]+'%'};return _0x2aa11a;})});}_0x443508=_[_0x665f('0x44')]({},_0x443508,_0x4b415b[_0x665f('0x47')]);return _0x383d64[_0x665f('0x56')](_0x443508);}})['then'](function(_0x46882b){if(_0x46882b){_0x5c5ca3=_0x46882b['length'];if(!_0x4b415b[_0x665f('0x37')][_0x665f('0x3d')](_0x665f('0x3e'))){_0x443508[_0x665f('0x28')]=qs[_0x665f('0x28')](_0x4b415b[_0x665f('0x37')]['limit']);_0x443508[_0x665f('0x3f')]=qs[_0x665f('0x3f')](_0x4b415b[_0x665f('0x37')]['offset']);}return _0x383d64['getConfigurations'](_0x443508);}})[_0x665f('0x2e')](function(_0x51075a){if(_0x51075a){return _0x51075a?{'count':_0x5c5ca3,'rows':_0x51075a}:null;}})[_0x665f('0x2e')](respondWithResult(_0x18a76f,null))[_0x665f('0x23')](handleError(_0x18a76f,null));};exports[_0x665f('0x5a')]=function(_0x3c833c,_0x4b3917,_0x35e739){if(_0x3c833c[_0x665f('0x53')]['id']){delete _0x3c833c[_0x665f('0x53')]['id'];}return db[_0x665f('0x48')]['findOne']({'where':{'id':_0x3c833c[_0x665f('0x4f')]['id']}})[_0x665f('0x2e')](handleEntityNotFound(_0x4b3917,null))[_0x665f('0x2e')](function(_0x4a512a){if(_0x4a512a){_0x3c833c[_0x665f('0x53')]['AccountId']=_0x4a512a['id'];_0x3c833c[_0x665f('0x53')]['Subjects']=integrations['getSubjects'](_0x3c833c[_0x665f('0x53')][_0x665f('0x5b')],_0x3c833c[_0x665f('0x53')]['type']);_0x3c833c[_0x665f('0x53')][_0x665f('0x5c')]=integrations[_0x665f('0x5d')](_0x3c833c[_0x665f('0x53')]['channel'],_0x3c833c[_0x665f('0x53')][_0x665f('0x45')]);return db[_0x665f('0x58')][_0x665f('0x52')](_0x3c833c[_0x665f('0x53')],{'include':[{'model':db[_0x665f('0x5e')],'as':'Subjects'},{'model':db[_0x665f('0x5e')],'as':_0x665f('0x5c')}]});}return null;})[_0x665f('0x2e')](respondWithResult(_0x4b3917,null))['catch'](handleError(_0x4b3917,null));};exports[_0x665f('0x5f')]=function(_0x3110ca,_0x3a2634,_0x3934df){var _0x37407a='';var _0x169ab1=['id',_0x665f('0x30'),'assigned_user_id',_0x665f('0x60'),'description',_0x665f('0x61'),'duration_hours','duration_minutes',_0x665f('0x62'),'parent_type','parent_name',_0x665f('0x63')];return db['SugarcrmAccount'][_0x665f('0x57')]({'where':{'id':_0x3110ca[_0x665f('0x4f')]['id']},'attributes':['id','username',_0x665f('0x64'),'remoteUri']})[_0x665f('0x2e')](handleEntityNotFound(_0x3a2634,null))[_0x665f('0x2e')](function(_0x3b988d){if(_0x3b988d){_0x37407a=_0x3b988d[_0x665f('0x65')];var _0x29e6f8=_0x37407a[_0x665f('0x66')](-0x1);if(_0x29e6f8==='/'){_0x37407a=_0x37407a[_0x665f('0x67')](0x0,_0x37407a[_0x665f('0x68')](_0x29e6f8));}return rp({'method':'POST','uri':util['format']('%s%s',_0x37407a,_0x665f('0x69')),'json':!![],'form':{'method':_0x665f('0x6a'),'input_type':_0x665f('0x6b'),'response_type':'JSON','rest_data':JSON[_0x665f('0x1d')]({'user_auth':{'user_name':_0x3b988d[_0x665f('0x6c')],'password':_0x3b988d['password'],'encryption':_0x665f('0x6d')},'application':_0x665f('0x6e')})}});}})[_0x665f('0x2e')](function(_0x1d82ff){if(_0x1d82ff&&_0x1d82ff[_0x665f('0x30')]!=='Invalid\x20Login'&&_0x1d82ff[_0x665f('0x30')]!==_0x665f('0x6f')){return rp({'method':_0x665f('0x70'),'uri':util[_0x665f('0x71')](_0x665f('0x72'),_0x37407a,'/service/v4_1/rest.php'),'json':!![],'form':{'method':_0x665f('0x73'),'input_type':_0x665f('0x6b'),'response_type':_0x665f('0x6b'),'rest_data':JSON['stringify']({'session':_0x1d82ff['id'],'module_name':_0x665f('0x74')})}})[_0x665f('0x2e')](function(_0x267d48){if(_0x267d48){var _0x5b5868=_[_0x665f('0x75')](_0x267d48[_0x665f('0x76')]);_[_0x665f('0x77')](_0x5b5868,function(_0x27e0c8){return _0x169ab1['includes'](_0x27e0c8[_0x665f('0x30')]);});return{'count':_0x5b5868[_0x665f('0x3c')],'rows':_[_0x665f('0x32')](_0x5b5868,function(_0x4554d2){return{'id':_0x4554d2[_0x665f('0x30')],'name':_0x4554d2[_0x665f('0x78')],'custom':_[_0x665f('0x79')](_0x4554d2[_0x665f('0x30')],'_c')?!![]:![],'options':_0x4554d2[_0x665f('0x47')]?_[_0x665f('0x32')](_[_0x665f('0x75')](_0x4554d2['options']),function(_0x37b855){return{'name':_0x37b855[_0x665f('0x7a')],'value':_0x37b855['name']};}):[]};})};}})[_0x665f('0x2e')](respondWithResult(_0x3a2634,null))[_0x665f('0x23')](function(_0x5d87b8){var _0xa14a08=_0x3110ca[_0x665f('0x37')]['test']?0x1f4:_0x5d87b8['statusCode']||0x1f4;logger['error']('getFields,\x20%s,\x20%s,\x20%s','getFields',_0xa14a08,JSON[_0x665f('0x1d')](_0x5d87b8));delete _0x5d87b8['name'];if(_0xa14a08===0x191){_0xa14a08=0x190;}_0x3a2634['status'](_0xa14a08)[_0x665f('0x7b')](_0x3110ca[_0x665f('0x37')][_0x665f('0x7c')]?{'message':_0x665f('0x7d'),'statusCode':_0x5d87b8[_0x665f('0x7e')]}:_0x5d87b8);});}else{var _0x1d631d=0x1f4;_0x3a2634[_0x665f('0x25')](_0x1d631d)['send']({'message':_0x665f('0x7d'),'statusCode':0x190});}});};
\ No newline at end of file
+var _0x3094=['values','module_fields','label','endsWith','value','test','statusCode','error','getFields,\x20%s,\x20%s,\x20%s','getFields','send','rimraf','zip-dir','fast-json-patch','moment','mustache','util','path','to-csv','ejs','lodash','squel','crypto','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','../../components/integrations/configuration','sendStatus','status','json','offset','undefined','limit','count','set','Content-Range','apply','reject','save','update','then','destroy','end','stack','name','index','map','rawAttributes','fieldName','type','query','keys','filters','intersection','model','attributes','hasOwnProperty','nolimit','order','sort','filter','where','merge','VIRTUAL','SugarcrmAccount','include','findAll','rows','catch','show','params','fields','length','includeAll','options','find','create','body','getConfigurations','findOne','SugarcrmConfiguration','addConfiguration','AccountId','Subjects','getSubjects','channel','SugarcrmField','created_by','description','date_start','duration_hours','duration_minutes','parent_id','parent_type','parent_name','direction','username','password','slice','substring','format','%s%s','/service/v4_1/rest.php','login','JSON','stringify','xCALLY\x20Motion\x20Integration','Invalid\x20Login','Password\x20Expired','POST','get_module_fields','Calls'];(function(_0x5b0edd,_0x7efa00){var _0x4ae996=function(_0xc34cc1){while(--_0xc34cc1){_0x5b0edd['push'](_0x5b0edd['shift']());}};_0x4ae996(++_0x7efa00);}(_0x3094,0x86));var _0x4309=function(_0x3ab51d,_0x2fa01d){_0x3ab51d=_0x3ab51d-0x0;var _0x29a04e=_0x3094[_0x3ab51d];return _0x29a04e;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x4309('0x0'));var zipdir=require(_0x4309('0x1'));var jsonpatch=require(_0x4309('0x2'));var rp=require('request-promise');var moment=require(_0x4309('0x3'));var BPromise=require('bluebird');var Mustache=require(_0x4309('0x4'));var util=require(_0x4309('0x5'));var path=require(_0x4309('0x6'));var sox=require('sox');var csv=require(_0x4309('0x7'));var ejs=require(_0x4309('0x8'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x4309('0x9'));var squel=require(_0x4309('0xa'));var crypto=require(_0x4309('0xb'));var jsforce=require('jsforce');var deskjs=require(_0x4309('0xc'));var toCsv=require(_0x4309('0x7'));var querystring=require(_0x4309('0xd'));var Papa=require(_0x4309('0xe'));var Redis=require(_0x4309('0xf'));var authService=require(_0x4309('0x10'));var qs=require(_0x4309('0x11'));var as=require(_0x4309('0x12'));var hardwareService=require(_0x4309('0x13'));var logger=require(_0x4309('0x14'))(_0x4309('0x15'));var utils=require(_0x4309('0x16'));var config=require(_0x4309('0x17'));var licenseUtil=require(_0x4309('0x18'));var db=require(_0x4309('0x19'))['db'];var integrations=require(_0x4309('0x1a'));function respondWithStatusCode(_0x58cea8,_0xd2583b){_0xd2583b=_0xd2583b||0xcc;return function(_0x532034){if(_0x532034){return _0x58cea8[_0x4309('0x1b')](_0xd2583b);}return _0x58cea8['status'](_0xd2583b)['end']();};}function respondWithResult(_0x8f793f,_0x2fa8e6){_0x2fa8e6=_0x2fa8e6||0xc8;return function(_0xb6bc8d){if(_0xb6bc8d){return _0x8f793f[_0x4309('0x1c')](_0x2fa8e6)[_0x4309('0x1d')](_0xb6bc8d);}};}function respondWithFilteredResult(_0x23b976,_0x4ebec1){return function(_0x1538f1){if(_0x1538f1){var _0x18c89b=typeof _0x4ebec1[_0x4309('0x1e')]===_0x4309('0x1f')&&typeof _0x4ebec1[_0x4309('0x20')]==='undefined';var _0x268975=_0x1538f1[_0x4309('0x21')];var _0x27332f=_0x18c89b?0x0:_0x4ebec1[_0x4309('0x1e')];var _0x40e615=_0x18c89b?_0x1538f1['count']:_0x4ebec1['offset']+_0x4ebec1[_0x4309('0x20')];var _0x40fa10;if(_0x40e615>=_0x268975){_0x40e615=_0x268975;_0x40fa10=0xc8;}else{_0x40fa10=0xce;}_0x23b976['status'](_0x40fa10);return _0x23b976[_0x4309('0x22')](_0x4309('0x23'),_0x27332f+'-'+_0x40e615+'/'+_0x268975)[_0x4309('0x1d')](_0x1538f1);}return null;};}function patchUpdates(_0x35322f){return function(_0x5321d5){try{jsonpatch[_0x4309('0x24')](_0x5321d5,_0x35322f,!![]);}catch(_0x13b6b4){return BPromise[_0x4309('0x25')](_0x13b6b4);}return _0x5321d5[_0x4309('0x26')]();};}function saveUpdates(_0x409625,_0x3998e6){return function(_0x1d0bbb){if(_0x1d0bbb){return _0x1d0bbb[_0x4309('0x27')](_0x409625)[_0x4309('0x28')](function(_0x355ff6){return _0x355ff6;});}return null;};}function removeEntity(_0x14d998,_0x442409){return function(_0x10628f){if(_0x10628f){return _0x10628f[_0x4309('0x29')]()[_0x4309('0x28')](function(){_0x14d998[_0x4309('0x1c')](0xcc)[_0x4309('0x2a')]();});}};}function handleEntityNotFound(_0x4a1ba,_0x205f60){return function(_0xaa1110){if(!_0xaa1110){_0x4a1ba[_0x4309('0x1b')](0x194);}return _0xaa1110;};}function handleError(_0x3699fc,_0x43d5f2){_0x43d5f2=_0x43d5f2||0x1f4;return function(_0xf76e70){logger['error'](_0xf76e70[_0x4309('0x2b')]);if(_0xf76e70[_0x4309('0x2c')]){delete _0xf76e70[_0x4309('0x2c')];}_0x3699fc[_0x4309('0x1c')](_0x43d5f2)['send'](_0xf76e70);};}exports[_0x4309('0x2d')]=function(_0x503c01,_0x2e607a){var _0x3e23d5={},_0x56d9cf={},_0x3848fa={'count':0x0,'rows':[]};var _0x3b6112=_[_0x4309('0x2e')](db['SugarcrmAccount'][_0x4309('0x2f')],function(_0x52c6d2){return{'name':_0x52c6d2[_0x4309('0x30')],'type':_0x52c6d2[_0x4309('0x31')]['key']};});_0x56d9cf['model']=_[_0x4309('0x2e')](_0x3b6112,_0x4309('0x2c'));_0x56d9cf[_0x4309('0x32')]=_[_0x4309('0x33')](_0x503c01[_0x4309('0x32')]);_0x56d9cf[_0x4309('0x34')]=_[_0x4309('0x35')](_0x56d9cf[_0x4309('0x36')],_0x56d9cf['query']);_0x3e23d5[_0x4309('0x37')]=_[_0x4309('0x35')](_0x56d9cf[_0x4309('0x36')],qs['fields'](_0x503c01[_0x4309('0x32')]['fields']));_0x3e23d5[_0x4309('0x37')]=_0x3e23d5[_0x4309('0x37')]['length']?_0x3e23d5['attributes']:_0x56d9cf[_0x4309('0x36')];if(!_0x503c01['query'][_0x4309('0x38')](_0x4309('0x39'))){_0x3e23d5[_0x4309('0x20')]=qs[_0x4309('0x20')](_0x503c01[_0x4309('0x32')][_0x4309('0x20')]);_0x3e23d5[_0x4309('0x1e')]=qs[_0x4309('0x1e')](_0x503c01[_0x4309('0x32')][_0x4309('0x1e')]);}_0x3e23d5[_0x4309('0x3a')]=qs[_0x4309('0x3b')](_0x503c01[_0x4309('0x32')][_0x4309('0x3b')]);_0x3e23d5['where']=qs['filters'](_['pick'](_0x503c01[_0x4309('0x32')],_0x56d9cf[_0x4309('0x34')]),_0x3b6112);if(_0x503c01['query'][_0x4309('0x3c')]){_0x3e23d5[_0x4309('0x3d')]=_[_0x4309('0x3e')](_0x3e23d5[_0x4309('0x3d')],{'$or':_[_0x4309('0x2e')](_0x3b6112,function(_0x396722){if(_0x396722[_0x4309('0x31')]!==_0x4309('0x3f')){var _0x259d3b={};_0x259d3b[_0x396722[_0x4309('0x2c')]]={'$like':'%'+_0x503c01['query'][_0x4309('0x3c')]+'%'};return _0x259d3b;}})});}_0x3e23d5=_['merge']({},_0x3e23d5,_0x503c01['options']);var _0x13390f={'where':_0x3e23d5[_0x4309('0x3d')]};return db[_0x4309('0x40')]['count'](_0x13390f)['then'](function(_0x5b088f){_0x3848fa[_0x4309('0x21')]=_0x5b088f;if(_0x503c01['query']['includeAll']){_0x3e23d5[_0x4309('0x41')]=[{'all':!![]}];}return db[_0x4309('0x40')][_0x4309('0x42')](_0x3e23d5);})[_0x4309('0x28')](function(_0x61bcb2){_0x3848fa[_0x4309('0x43')]=_0x61bcb2;return _0x3848fa;})[_0x4309('0x28')](respondWithFilteredResult(_0x2e607a,_0x3e23d5))[_0x4309('0x44')](handleError(_0x2e607a,null));};exports[_0x4309('0x45')]=function(_0x4f11dc,_0x357e4b){var _0x4502a3={'raw':![],'where':{'id':_0x4f11dc[_0x4309('0x46')]['id']}},_0x31ea0f={};_0x31ea0f[_0x4309('0x36')]=_[_0x4309('0x33')](db[_0x4309('0x40')][_0x4309('0x2f')]);_0x31ea0f[_0x4309('0x32')]=_[_0x4309('0x33')](_0x4f11dc['query']);_0x31ea0f['filters']=_[_0x4309('0x35')](_0x31ea0f[_0x4309('0x36')],_0x31ea0f[_0x4309('0x32')]);_0x4502a3['attributes']=_[_0x4309('0x35')](_0x31ea0f['model'],qs[_0x4309('0x47')](_0x4f11dc['query']['fields']));_0x4502a3[_0x4309('0x37')]=_0x4502a3[_0x4309('0x37')][_0x4309('0x48')]?_0x4502a3[_0x4309('0x37')]:_0x31ea0f[_0x4309('0x36')];if(_0x4f11dc['query'][_0x4309('0x49')]){_0x4502a3[_0x4309('0x41')]=[{'all':!![]}];}_0x4502a3=_[_0x4309('0x3e')]({},_0x4502a3,_0x4f11dc[_0x4309('0x4a')]);return db[_0x4309('0x40')][_0x4309('0x4b')](_0x4502a3)[_0x4309('0x28')](handleEntityNotFound(_0x357e4b,null))[_0x4309('0x28')](respondWithResult(_0x357e4b,null))[_0x4309('0x44')](handleError(_0x357e4b,null));};exports['create']=function(_0x161a7e,_0x4c0d15){return db[_0x4309('0x40')][_0x4309('0x4c')](_0x161a7e[_0x4309('0x4d')],{})[_0x4309('0x28')](respondWithResult(_0x4c0d15,0xc9))[_0x4309('0x44')](handleError(_0x4c0d15,null));};exports[_0x4309('0x27')]=function(_0x5e6ec7,_0x1cb701){if(_0x5e6ec7['body']['id']){delete _0x5e6ec7[_0x4309('0x4d')]['id'];}return db[_0x4309('0x40')][_0x4309('0x4b')]({'where':{'id':_0x5e6ec7[_0x4309('0x46')]['id']}})['then'](handleEntityNotFound(_0x1cb701,null))[_0x4309('0x28')](saveUpdates(_0x5e6ec7['body'],null))[_0x4309('0x28')](respondWithResult(_0x1cb701,null))[_0x4309('0x44')](handleError(_0x1cb701,null));};exports[_0x4309('0x29')]=function(_0x59b60c,_0x280476){return db[_0x4309('0x40')][_0x4309('0x4b')]({'where':{'id':_0x59b60c['params']['id']}})['then'](handleEntityNotFound(_0x280476,null))[_0x4309('0x28')](removeEntity(_0x280476,null))[_0x4309('0x44')](handleError(_0x280476,null));};exports[_0x4309('0x4e')]=function(_0x28b74b,_0x3eedd5,_0x31b51b){var _0x528410={};var _0x5a502e={};var _0x165101;var _0x247884;return db['SugarcrmAccount'][_0x4309('0x4f')]({'where':{'id':_0x28b74b[_0x4309('0x46')]['id']}})['then'](handleEntityNotFound(_0x3eedd5,null))[_0x4309('0x28')](function(_0x578c92){if(_0x578c92){_0x165101=_0x578c92;_0x5a502e[_0x4309('0x36')]=_['keys'](db[_0x4309('0x50')]['rawAttributes']);_0x5a502e['query']=_[_0x4309('0x33')](_0x28b74b[_0x4309('0x32')]);_0x5a502e['filters']=_[_0x4309('0x35')](_0x5a502e['model'],_0x5a502e[_0x4309('0x32')]);_0x528410[_0x4309('0x37')]=_['intersection'](_0x5a502e[_0x4309('0x36')],qs[_0x4309('0x47')](_0x28b74b['query'][_0x4309('0x47')]));_0x528410[_0x4309('0x37')]=_0x528410['attributes']['length']?_0x528410[_0x4309('0x37')]:_0x5a502e[_0x4309('0x36')];_0x528410[_0x4309('0x3a')]=qs[_0x4309('0x3b')](_0x28b74b[_0x4309('0x32')][_0x4309('0x3b')]);_0x528410[_0x4309('0x3d')]=qs[_0x4309('0x34')](_['pick'](_0x28b74b['query'],_0x5a502e[_0x4309('0x34')]));if(_0x28b74b[_0x4309('0x32')][_0x4309('0x3c')]){_0x528410['where']=_[_0x4309('0x3e')](_0x528410[_0x4309('0x3d')],{'$or':_[_0x4309('0x2e')](_0x528410[_0x4309('0x37')],function(_0x2bc2be){var _0x1cb30b={};_0x1cb30b[_0x2bc2be]={'$like':'%'+_0x28b74b['query']['filter']+'%'};return _0x1cb30b;})});}_0x528410=_[_0x4309('0x3e')]({},_0x528410,_0x28b74b[_0x4309('0x4a')]);return _0x165101[_0x4309('0x4e')](_0x528410);}})[_0x4309('0x28')](function(_0x1f3cc8){if(_0x1f3cc8){_0x247884=_0x1f3cc8[_0x4309('0x48')];if(!_0x28b74b[_0x4309('0x32')][_0x4309('0x38')](_0x4309('0x39'))){_0x528410['limit']=qs[_0x4309('0x20')](_0x28b74b[_0x4309('0x32')]['limit']);_0x528410['offset']=qs[_0x4309('0x1e')](_0x28b74b[_0x4309('0x32')]['offset']);}return _0x165101['getConfigurations'](_0x528410);}})[_0x4309('0x28')](function(_0x592ece){if(_0x592ece){return _0x592ece?{'count':_0x247884,'rows':_0x592ece}:null;}})[_0x4309('0x28')](respondWithResult(_0x3eedd5,null))['catch'](handleError(_0x3eedd5,null));};exports[_0x4309('0x51')]=function(_0x4b2553,_0x5a73ca,_0x3d8c63){if(_0x4b2553[_0x4309('0x4d')]['id']){delete _0x4b2553[_0x4309('0x4d')]['id'];}return db[_0x4309('0x40')]['findOne']({'where':{'id':_0x4b2553[_0x4309('0x46')]['id']}})[_0x4309('0x28')](handleEntityNotFound(_0x5a73ca,null))[_0x4309('0x28')](function(_0x520ac2){if(_0x520ac2){_0x4b2553[_0x4309('0x4d')][_0x4309('0x52')]=_0x520ac2['id'];_0x4b2553['body'][_0x4309('0x53')]=integrations[_0x4309('0x54')](_0x4b2553[_0x4309('0x4d')][_0x4309('0x55')],_0x4b2553[_0x4309('0x4d')][_0x4309('0x31')]);_0x4b2553[_0x4309('0x4d')]['Descriptions']=integrations['getDescriptions'](_0x4b2553[_0x4309('0x4d')][_0x4309('0x55')],_0x4b2553[_0x4309('0x4d')][_0x4309('0x31')]);return db[_0x4309('0x50')][_0x4309('0x4c')](_0x4b2553['body'],{'include':[{'model':db[_0x4309('0x56')],'as':_0x4309('0x53')},{'model':db[_0x4309('0x56')],'as':'Descriptions'}]});}return null;})['then'](respondWithResult(_0x5a73ca,null))[_0x4309('0x44')](handleError(_0x5a73ca,null));};exports['getFields']=function(_0x3f9b5d,_0x1d76b7,_0x552a61){var _0x158671='';var _0x32af36=['id',_0x4309('0x2c'),'assigned_user_id',_0x4309('0x57'),_0x4309('0x58'),_0x4309('0x59'),_0x4309('0x5a'),_0x4309('0x5b'),_0x4309('0x5c'),_0x4309('0x5d'),_0x4309('0x5e'),_0x4309('0x5f')];return db[_0x4309('0x40')][_0x4309('0x4f')]({'where':{'id':_0x3f9b5d[_0x4309('0x46')]['id']},'attributes':['id',_0x4309('0x60'),_0x4309('0x61'),'remoteUri']})[_0x4309('0x28')](handleEntityNotFound(_0x1d76b7,null))['then'](function(_0x4e7a32){if(_0x4e7a32){_0x158671=_0x4e7a32['remoteUri'];var _0x9d4ed3=_0x158671[_0x4309('0x62')](-0x1);if(_0x9d4ed3==='/'){_0x158671=_0x158671[_0x4309('0x63')](0x0,_0x158671['lastIndexOf'](_0x9d4ed3));}return rp({'method':'POST','uri':util[_0x4309('0x64')](_0x4309('0x65'),_0x158671,_0x4309('0x66')),'json':!![],'form':{'method':_0x4309('0x67'),'input_type':_0x4309('0x68'),'response_type':_0x4309('0x68'),'rest_data':JSON[_0x4309('0x69')]({'user_auth':{'user_name':_0x4e7a32[_0x4309('0x60')],'password':_0x4e7a32['password'],'encryption':'PLAIN'},'application':_0x4309('0x6a')})}});}})['then'](function(_0x16bf19){if(_0x16bf19&&_0x16bf19[_0x4309('0x2c')]!==_0x4309('0x6b')&&_0x16bf19[_0x4309('0x2c')]!==_0x4309('0x6c')){return rp({'method':_0x4309('0x6d'),'uri':util[_0x4309('0x64')](_0x4309('0x65'),_0x158671,_0x4309('0x66')),'json':!![],'form':{'method':_0x4309('0x6e'),'input_type':'JSON','response_type':_0x4309('0x68'),'rest_data':JSON['stringify']({'session':_0x16bf19['id'],'module_name':_0x4309('0x6f')})}})['then'](function(_0x230a24){if(_0x230a24){var _0x2cdc99=_[_0x4309('0x70')](_0x230a24[_0x4309('0x71')]);_['remove'](_0x2cdc99,function(_0x381a0b){return _0x32af36['includes'](_0x381a0b[_0x4309('0x2c')]);});return{'count':_0x2cdc99['length'],'rows':_[_0x4309('0x2e')](_0x2cdc99,function(_0x5334e6){return{'id':_0x5334e6[_0x4309('0x2c')],'name':_0x5334e6[_0x4309('0x72')],'custom':_[_0x4309('0x73')](_0x5334e6['name'],'_c')?!![]:![],'options':_0x5334e6[_0x4309('0x4a')]?_[_0x4309('0x2e')](_[_0x4309('0x70')](_0x5334e6[_0x4309('0x4a')]),function(_0x46062c){return{'name':_0x46062c[_0x4309('0x74')],'value':_0x46062c[_0x4309('0x2c')]};}):[]};})};}})[_0x4309('0x28')](respondWithResult(_0x1d76b7,null))[_0x4309('0x44')](function(_0x5523b0){var _0xd3cd95=_0x3f9b5d['query'][_0x4309('0x75')]?0x1f4:_0x5523b0[_0x4309('0x76')]||0x1f4;logger[_0x4309('0x77')](_0x4309('0x78'),_0x4309('0x79'),_0xd3cd95,JSON[_0x4309('0x69')](_0x5523b0));delete _0x5523b0[_0x4309('0x2c')];if(_0xd3cd95===0x191){_0xd3cd95=0x190;}_0x1d76b7[_0x4309('0x1c')](_0xd3cd95)[_0x4309('0x7a')](_0x3f9b5d[_0x4309('0x32')][_0x4309('0x75')]?{'message':'Wrong\x20credentials','statusCode':_0x5523b0['statusCode']}:_0x5523b0);});}else{var _0x3b1e96=0x1f4;_0x1d76b7[_0x4309('0x1c')](_0x3b1e96)[_0x4309('0x7a')]({'message':'Wrong\x20credentials','statusCode':0x190});}});};
\ No newline at end of file