Built motion from commit d5e4af8c.|2.6.23
[motion2.git] / server / api / intSalesforceAccount / intSalesforceAccount.controller.js
index 01db50b..ffce239 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x1b36=['IsRecurrence','Subject','string','email','phone','remove','includes','label','custom','picklistValues','value','boolean','true','False','false','test','statusCode','stringify','zip-dir','request-promise','moment','util','to-csv','fs-extra','squel','crypto','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','../../components/integrations/configuration','sendStatus','status','json','undefined','limit','count','offset','Content-Range','apply','reject','update','then','destroy','end','error','name','send','index','map','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','pick','where','merge','VIRTUAL','filter','options','SalesforceAccount','includeAll','findAll','catch','params','include','find','create','body','getConfigurations','SalesforceConfiguration','addConfiguration','AccountId','Subjects','getSubjects','channel','SalesforceField','Descriptions','getFields','Task','findOne','remoteUri','clientId','clientSecret','username','password','securityToken','slice','substring','Connection','isNil','ticketType','sobject','describe','ActivityDate','IsReminderSet'];(function(_0x485b5a,_0x2b289b){var _0xd2b34d=function(_0x34dcbd){while(--_0x34dcbd){_0x485b5a['push'](_0x485b5a['shift']());}};_0xd2b34d(++_0x2b289b);}(_0x1b36,0xfc));var _0x61b3=function(_0x45a082,_0x396c1c){_0x45a082=_0x45a082-0x0;var _0x22cf7c=_0x1b36[_0x45a082];return _0x22cf7c;};'use strict';var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0x61b3('0x0'));var jsonpatch=require('fast-json-patch');var rp=require(_0x61b3('0x1'));var moment=require(_0x61b3('0x2'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0x61b3('0x3'));var path=require('path');var sox=require('sox');var csv=require(_0x61b3('0x4'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x61b3('0x5'));var _=require('lodash');var squel=require(_0x61b3('0x6'));var crypto=require(_0x61b3('0x7'));var jsforce=require(_0x61b3('0x8'));var deskjs=require(_0x61b3('0x9'));var toCsv=require(_0x61b3('0x4'));var querystring=require(_0x61b3('0xa'));var Papa=require('papaparse');var Redis=require(_0x61b3('0xb'));var authService=require(_0x61b3('0xc'));var qs=require(_0x61b3('0xd'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x61b3('0xe'));var logger=require(_0x61b3('0xf'))(_0x61b3('0x10'));var utils=require(_0x61b3('0x11'));var config=require(_0x61b3('0x12'));var licenseUtil=require(_0x61b3('0x13'));var db=require(_0x61b3('0x14'))['db'];var integrations=require(_0x61b3('0x15'));function respondWithStatusCode(_0x2aee3f,_0x5857e1){_0x5857e1=_0x5857e1||0xcc;return function(_0x39d1cb){if(_0x39d1cb){return _0x2aee3f[_0x61b3('0x16')](_0x5857e1);}return _0x2aee3f[_0x61b3('0x17')](_0x5857e1)['end']();};}function respondWithResult(_0x1d1cef,_0x45d6f1){_0x45d6f1=_0x45d6f1||0xc8;return function(_0x5698e2){if(_0x5698e2){return _0x1d1cef[_0x61b3('0x17')](_0x45d6f1)[_0x61b3('0x18')](_0x5698e2);}};}function respondWithFilteredResult(_0x2dba96,_0x109759){return function(_0x4c7bfb){if(_0x4c7bfb){var _0x4e1eb5=typeof _0x109759['offset']===_0x61b3('0x19')&&typeof _0x109759[_0x61b3('0x1a')]===_0x61b3('0x19');var _0x477ac6=_0x4c7bfb[_0x61b3('0x1b')];var _0x5d76d9=_0x4e1eb5?0x0:_0x109759[_0x61b3('0x1c')];var _0x2e2056=_0x4e1eb5?_0x4c7bfb[_0x61b3('0x1b')]:_0x109759['offset']+_0x109759['limit'];var _0x4d91cf;if(_0x2e2056>=_0x477ac6){_0x2e2056=_0x477ac6;_0x4d91cf=0xc8;}else{_0x4d91cf=0xce;}_0x2dba96[_0x61b3('0x17')](_0x4d91cf);return _0x2dba96['set'](_0x61b3('0x1d'),_0x5d76d9+'-'+_0x2e2056+'/'+_0x477ac6)[_0x61b3('0x18')](_0x4c7bfb);}return null;};}function patchUpdates(_0x1f0023){return function(_0x39079a){try{jsonpatch[_0x61b3('0x1e')](_0x39079a,_0x1f0023,!![]);}catch(_0x1c3d76){return BPromise[_0x61b3('0x1f')](_0x1c3d76);}return _0x39079a['save']();};}function saveUpdates(_0x53c00a,_0xf97917){return function(_0x6b65b8){if(_0x6b65b8){return _0x6b65b8[_0x61b3('0x20')](_0x53c00a)[_0x61b3('0x21')](function(_0x123ded){return _0x123ded;});}return null;};}function removeEntity(_0x2a3305,_0x190334){return function(_0x31fe88){if(_0x31fe88){return _0x31fe88[_0x61b3('0x22')]()['then'](function(){_0x2a3305[_0x61b3('0x17')](0xcc)[_0x61b3('0x23')]();});}};}function handleEntityNotFound(_0x41492c,_0x5823b7){return function(_0x13e8e2){if(!_0x13e8e2){_0x41492c[_0x61b3('0x16')](0x194);}return _0x13e8e2;};}function handleError(_0x19494f,_0x2164e1){_0x2164e1=_0x2164e1||0x1f4;return function(_0x29b10a){logger[_0x61b3('0x24')](_0x29b10a['stack']);if(_0x29b10a[_0x61b3('0x25')]){delete _0x29b10a[_0x61b3('0x25')];}_0x19494f[_0x61b3('0x17')](_0x2164e1)[_0x61b3('0x26')](_0x29b10a);};}exports[_0x61b3('0x27')]=function(_0x189076,_0xb2bc32){var _0x3af444={},_0x107ab5={},_0xc82cd9={'count':0x0,'rows':[]};var _0x5546c4=_[_0x61b3('0x28')](db['SalesforceAccount'][_0x61b3('0x29')],function(_0xa6205a){return{'name':_0xa6205a[_0x61b3('0x2a')],'type':_0xa6205a[_0x61b3('0x2b')][_0x61b3('0x2c')]};});_0x107ab5[_0x61b3('0x2d')]=_[_0x61b3('0x28')](_0x5546c4,_0x61b3('0x25'));_0x107ab5[_0x61b3('0x2e')]=_[_0x61b3('0x2f')](_0x189076[_0x61b3('0x2e')]);_0x107ab5[_0x61b3('0x30')]=_[_0x61b3('0x31')](_0x107ab5[_0x61b3('0x2d')],_0x107ab5[_0x61b3('0x2e')]);_0x3af444[_0x61b3('0x32')]=_[_0x61b3('0x31')](_0x107ab5[_0x61b3('0x2d')],qs[_0x61b3('0x33')](_0x189076[_0x61b3('0x2e')]['fields']));_0x3af444['attributes']=_0x3af444['attributes'][_0x61b3('0x34')]?_0x3af444['attributes']:_0x107ab5[_0x61b3('0x2d')];if(!_0x189076[_0x61b3('0x2e')][_0x61b3('0x35')](_0x61b3('0x36'))){_0x3af444['limit']=qs[_0x61b3('0x1a')](_0x189076['query'][_0x61b3('0x1a')]);_0x3af444[_0x61b3('0x1c')]=qs[_0x61b3('0x1c')](_0x189076[_0x61b3('0x2e')][_0x61b3('0x1c')]);}_0x3af444[_0x61b3('0x37')]=qs[_0x61b3('0x38')](_0x189076[_0x61b3('0x2e')][_0x61b3('0x38')]);_0x3af444['where']=qs[_0x61b3('0x30')](_[_0x61b3('0x39')](_0x189076['query'],_0x107ab5[_0x61b3('0x30')]),_0x5546c4);if(_0x189076[_0x61b3('0x2e')]['filter']){_0x3af444[_0x61b3('0x3a')]=_[_0x61b3('0x3b')](_0x3af444[_0x61b3('0x3a')],{'$or':_[_0x61b3('0x28')](_0x5546c4,function(_0x577737){if(_0x577737[_0x61b3('0x2b')]!==_0x61b3('0x3c')){var _0x184d6a={};_0x184d6a[_0x577737['name']]={'$like':'%'+_0x189076[_0x61b3('0x2e')][_0x61b3('0x3d')]+'%'};return _0x184d6a;}})});}_0x3af444=_[_0x61b3('0x3b')]({},_0x3af444,_0x189076[_0x61b3('0x3e')]);var _0xa94adc={'where':_0x3af444[_0x61b3('0x3a')]};return db[_0x61b3('0x3f')][_0x61b3('0x1b')](_0xa94adc)[_0x61b3('0x21')](function(_0x299d3a){_0xc82cd9[_0x61b3('0x1b')]=_0x299d3a;if(_0x189076[_0x61b3('0x2e')][_0x61b3('0x40')]){_0x3af444['include']=[{'all':!![]}];}return db[_0x61b3('0x3f')][_0x61b3('0x41')](_0x3af444);})[_0x61b3('0x21')](function(_0x228302){_0xc82cd9['rows']=_0x228302;return _0xc82cd9;})['then'](respondWithFilteredResult(_0xb2bc32,_0x3af444))[_0x61b3('0x42')](handleError(_0xb2bc32,null));};exports['show']=function(_0x25fca4,_0xc63f7f){var _0x3c90d6={'raw':![],'where':{'id':_0x25fca4[_0x61b3('0x43')]['id']}},_0x1b3842={};_0x1b3842['model']=_[_0x61b3('0x2f')](db[_0x61b3('0x3f')][_0x61b3('0x29')]);_0x1b3842['query']=_[_0x61b3('0x2f')](_0x25fca4[_0x61b3('0x2e')]);_0x1b3842[_0x61b3('0x30')]=_[_0x61b3('0x31')](_0x1b3842[_0x61b3('0x2d')],_0x1b3842[_0x61b3('0x2e')]);_0x3c90d6[_0x61b3('0x32')]=_['intersection'](_0x1b3842[_0x61b3('0x2d')],qs[_0x61b3('0x33')](_0x25fca4[_0x61b3('0x2e')][_0x61b3('0x33')]));_0x3c90d6[_0x61b3('0x32')]=_0x3c90d6[_0x61b3('0x32')]['length']?_0x3c90d6[_0x61b3('0x32')]:_0x1b3842[_0x61b3('0x2d')];if(_0x25fca4[_0x61b3('0x2e')][_0x61b3('0x40')]){_0x3c90d6[_0x61b3('0x44')]=[{'all':!![]}];}_0x3c90d6=_['merge']({},_0x3c90d6,_0x25fca4[_0x61b3('0x3e')]);return db[_0x61b3('0x3f')][_0x61b3('0x45')](_0x3c90d6)[_0x61b3('0x21')](handleEntityNotFound(_0xc63f7f,null))[_0x61b3('0x21')](respondWithResult(_0xc63f7f,null))[_0x61b3('0x42')](handleError(_0xc63f7f,null));};exports[_0x61b3('0x46')]=function(_0x37db93,_0x38f037){return db[_0x61b3('0x3f')][_0x61b3('0x46')](_0x37db93['body'],{})[_0x61b3('0x21')](respondWithResult(_0x38f037,0xc9))[_0x61b3('0x42')](handleError(_0x38f037,null));};exports[_0x61b3('0x20')]=function(_0x5d8d8c,_0x1ea5f9){if(_0x5d8d8c[_0x61b3('0x47')]['id']){delete _0x5d8d8c[_0x61b3('0x47')]['id'];}return db[_0x61b3('0x3f')][_0x61b3('0x45')]({'where':{'id':_0x5d8d8c[_0x61b3('0x43')]['id']}})[_0x61b3('0x21')](handleEntityNotFound(_0x1ea5f9,null))['then'](saveUpdates(_0x5d8d8c['body'],null))[_0x61b3('0x21')](respondWithResult(_0x1ea5f9,null))[_0x61b3('0x42')](handleError(_0x1ea5f9,null));};exports['destroy']=function(_0x3710e8,_0x39e5bf){return db[_0x61b3('0x3f')][_0x61b3('0x45')]({'where':{'id':_0x3710e8[_0x61b3('0x43')]['id']}})[_0x61b3('0x21')](handleEntityNotFound(_0x39e5bf,null))[_0x61b3('0x21')](removeEntity(_0x39e5bf,null))['catch'](handleError(_0x39e5bf,null));};exports[_0x61b3('0x48')]=function(_0x2ebfe3,_0x929145,_0xf6c254){var _0x246b91={};var _0x3bcd4d={};var _0x12943a;var _0x3b511a;return db['SalesforceAccount']['findOne']({'where':{'id':_0x2ebfe3['params']['id']}})['then'](handleEntityNotFound(_0x929145,null))['then'](function(_0x398a42){if(_0x398a42){_0x12943a=_0x398a42;_0x3bcd4d[_0x61b3('0x2d')]=_[_0x61b3('0x2f')](db[_0x61b3('0x49')]['rawAttributes']);_0x3bcd4d[_0x61b3('0x2e')]=_[_0x61b3('0x2f')](_0x2ebfe3[_0x61b3('0x2e')]);_0x3bcd4d['filters']=_['intersection'](_0x3bcd4d[_0x61b3('0x2d')],_0x3bcd4d[_0x61b3('0x2e')]);_0x246b91[_0x61b3('0x32')]=_[_0x61b3('0x31')](_0x3bcd4d[_0x61b3('0x2d')],qs[_0x61b3('0x33')](_0x2ebfe3[_0x61b3('0x2e')][_0x61b3('0x33')]));_0x246b91[_0x61b3('0x32')]=_0x246b91[_0x61b3('0x32')][_0x61b3('0x34')]?_0x246b91[_0x61b3('0x32')]:_0x3bcd4d[_0x61b3('0x2d')];_0x246b91['order']=qs[_0x61b3('0x38')](_0x2ebfe3[_0x61b3('0x2e')]['sort']);_0x246b91[_0x61b3('0x3a')]=qs[_0x61b3('0x30')](_[_0x61b3('0x39')](_0x2ebfe3[_0x61b3('0x2e')],_0x3bcd4d[_0x61b3('0x30')]));if(_0x2ebfe3[_0x61b3('0x2e')][_0x61b3('0x3d')]){_0x246b91[_0x61b3('0x3a')]=_[_0x61b3('0x3b')](_0x246b91[_0x61b3('0x3a')],{'$or':_[_0x61b3('0x28')](_0x246b91[_0x61b3('0x32')],function(_0x599ad1){var _0x47f081={};_0x47f081[_0x599ad1]={'$like':'%'+_0x2ebfe3[_0x61b3('0x2e')][_0x61b3('0x3d')]+'%'};return _0x47f081;})});}_0x246b91=_[_0x61b3('0x3b')]({},_0x246b91,_0x2ebfe3[_0x61b3('0x3e')]);return _0x12943a[_0x61b3('0x48')](_0x246b91);}})[_0x61b3('0x21')](function(_0x501452){if(_0x501452){_0x3b511a=_0x501452['length'];if(!_0x2ebfe3[_0x61b3('0x2e')][_0x61b3('0x35')](_0x61b3('0x36'))){_0x246b91['limit']=qs[_0x61b3('0x1a')](_0x2ebfe3[_0x61b3('0x2e')][_0x61b3('0x1a')]);_0x246b91[_0x61b3('0x1c')]=qs['offset'](_0x2ebfe3[_0x61b3('0x2e')][_0x61b3('0x1c')]);}return _0x12943a[_0x61b3('0x48')](_0x246b91);}})[_0x61b3('0x21')](function(_0x2a5363){if(_0x2a5363){return _0x2a5363?{'count':_0x3b511a,'rows':_0x2a5363}:null;}})['then'](respondWithResult(_0x929145,null))[_0x61b3('0x42')](handleError(_0x929145,null));};exports[_0x61b3('0x4a')]=function(_0x4c74cc,_0x4d5c51,_0xead944){if(_0x4c74cc[_0x61b3('0x47')]['id']){delete _0x4c74cc[_0x61b3('0x47')]['id'];}return db['SalesforceAccount']['findOne']({'where':{'id':_0x4c74cc[_0x61b3('0x43')]['id']}})[_0x61b3('0x21')](handleEntityNotFound(_0x4d5c51,null))[_0x61b3('0x21')](function(_0x24a7b0){if(_0x24a7b0){_0x4c74cc['body'][_0x61b3('0x4b')]=_0x24a7b0['id'];_0x4c74cc[_0x61b3('0x47')][_0x61b3('0x4c')]=integrations[_0x61b3('0x4d')](_0x4c74cc[_0x61b3('0x47')]['channel'],_0x4c74cc[_0x61b3('0x47')][_0x61b3('0x2b')]);_0x4c74cc[_0x61b3('0x47')]['Descriptions']=integrations['getDescriptions'](_0x4c74cc['body'][_0x61b3('0x4e')],_0x4c74cc['body'][_0x61b3('0x2b')]);return db['SalesforceConfiguration'][_0x61b3('0x46')](_0x4c74cc['body'],{'include':[{'model':db[_0x61b3('0x4f')],'as':_0x61b3('0x4c')},{'model':db[_0x61b3('0x4f')],'as':_0x61b3('0x50')}]});}return null;})[_0x61b3('0x21')](respondWithResult(_0x4d5c51,null))[_0x61b3('0x42')](handleError(_0x4d5c51,null));};exports[_0x61b3('0x51')]=function(_0x2a821b,_0x39a273,_0x75508e){var _0xcabb74;var _0x350e56='';var _0x40795d=_0x61b3('0x52');return db[_0x61b3('0x3f')][_0x61b3('0x53')]({'where':{'id':_0x2a821b[_0x61b3('0x43')]['id']},'attributes':['id',_0x61b3('0x54'),_0x61b3('0x55'),_0x61b3('0x56'),_0x61b3('0x57'),_0x61b3('0x58'),_0x61b3('0x59')]})[_0x61b3('0x21')](handleEntityNotFound(_0x39a273,null))['then'](function(_0x9ac050){if(_0x9ac050){_0x350e56=_0x9ac050['remoteUri'];var _0x17c071=_0x350e56[_0x61b3('0x5a')](-0x1);if(_0x17c071==='/'){_0x350e56=_0x350e56[_0x61b3('0x5b')](0x0,_0x350e56['lastIndexOf'](_0x17c071));}_0xcabb74=new jsforce[(_0x61b3('0x5c'))]({'oauth2':{'loginUrl':_0x350e56,'clientId':_0x9ac050[_0x61b3('0x55')],'clientSecret':_0x9ac050['clientSecret']}});return _0xcabb74['login'](_0x9ac050[_0x61b3('0x57')],_0x9ac050[_0x61b3('0x58')]['concat'](_0x9ac050[_0x61b3('0x59')]));}})[_0x61b3('0x21')](function(_0x4d2b46){if(_0x4d2b46){if(!_[_0x61b3('0x5d')](_0x2a821b[_0x61b3('0x2e')][_0x61b3('0x5e')])){_0x40795d=_0x2a821b[_0x61b3('0x2e')][_0x61b3('0x5e')];}return _0xcabb74[_0x61b3('0x5f')](_0x40795d)[_0x61b3('0x60')]();}})[_0x61b3('0x21')](function(_0x1fdadc){var _0x45975b=['OwnerId',_0x61b3('0x61'),_0x61b3('0x62'),_0x61b3('0x63'),_0x61b3('0x64'),'Description'];var _0x4f8290=[_0x61b3('0x65'),'int','picklist','boolean',_0x61b3('0x66'),'textarea',_0x61b3('0x67')];if(_0x1fdadc){_[_0x61b3('0x68')](_0x1fdadc[_0x61b3('0x33')],function(_0xd478fa){return _0x45975b[_0x61b3('0x69')](_0xd478fa['name'])||!_0x4f8290[_0x61b3('0x69')](_0xd478fa[_0x61b3('0x2b')]);});return{'count':_0x1fdadc['fields']['length'],'rows':_[_0x61b3('0x28')](_0x1fdadc[_0x61b3('0x33')],function(_0x18d1b6){return{'id':_0x18d1b6[_0x61b3('0x25')],'name':_0x18d1b6[_0x61b3('0x6a')],'custom':_0x18d1b6[_0x61b3('0x6b')],'options':_0x18d1b6[_0x61b3('0x6c')][_0x61b3('0x34')]>0x0?_[_0x61b3('0x28')](_0x18d1b6['picklistValues'],function(_0x488865){return{'name':_0x488865[_0x61b3('0x6a')],'value':_0x488865[_0x61b3('0x6d')]};}):_0x18d1b6[_0x61b3('0x2b')]==_0x61b3('0x6e')?[{'name':'True','value':_0x61b3('0x6f')},{'name':_0x61b3('0x70'),'value':_0x61b3('0x71')}]:[]};})};}})[_0x61b3('0x21')](respondWithResult(_0x39a273,null))[_0x61b3('0x42')](function(_0x5a58e6){var _0x34d36b=_0x2a821b[_0x61b3('0x2e')][_0x61b3('0x72')]?0x1f4:_0x5a58e6[_0x61b3('0x73')]||0x1f4;logger['error']('getFields,\x20%s,\x20%s,\x20%s',_0x61b3('0x51'),_0x34d36b,JSON[_0x61b3('0x74')](_0x5a58e6));delete _0x5a58e6[_0x61b3('0x25')];if(_0x34d36b===0x191){_0x34d36b=0x190;}_0x39a273[_0x61b3('0x17')](_0x34d36b)[_0x61b3('0x26')](_0x2a821b[_0x61b3('0x2e')][_0x61b3('0x72')]?{'message':'Wrong\x20credentials','statusCode':_0x5a58e6[_0x61b3('0x73')]}:_0x5a58e6);});};
\ No newline at end of file
+var _0x540f=['clientId','clientSecret','username','securityToken','lastIndexOf','Connection','login','password','isNil','ticketType','sobject','describe','OwnerId','ActivityDate','IsReminderSet','Subject','Description','email','textarea','remove','includes','label','custom','picklistValues','value','boolean','true','False','false','test','statusCode','getFields,\x20%s,\x20%s,\x20%s','stringify','Wrong\x20credentials','rimraf','zip-dir','fast-json-patch','bluebird','mustache','util','path','sox','ejs','fs-extra','crypto','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','undefined','limit','set','Content-Range','reject','save','update','then','destroy','error','stack','name','send','index','fieldName','key','model','map','query','keys','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','filters','pick','where','merge','type','VIRTUAL','filter','SalesforceAccount','count','includeAll','include','findAll','rows','show','rawAttributes','find','catch','create','body','params','getConfigurations','findOne','SalesforceConfiguration','options','addConfiguration','AccountId','Subjects','getSubjects','Descriptions','getDescriptions','SalesforceField','getFields','Task','remoteUri'];(function(_0x25ab75,_0x32b0f6){var _0x42873f=function(_0x56e6e3){while(--_0x56e6e3){_0x25ab75['push'](_0x25ab75['shift']());}};_0x42873f(++_0x32b0f6);}(_0x540f,0x11a));var _0xf540=function(_0x3be7ff,_0x12e714){_0x3be7ff=_0x3be7ff-0x0;var _0x186721=_0x540f[_0x3be7ff];return _0x186721;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xf540('0x0'));var zipdir=require(_0xf540('0x1'));var jsonpatch=require(_0xf540('0x2'));var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0xf540('0x3'));var Mustache=require(_0xf540('0x4'));var util=require(_0xf540('0x5'));var path=require(_0xf540('0x6'));var sox=require(_0xf540('0x7'));var csv=require('to-csv');var ejs=require(_0xf540('0x8'));var fs=require('fs');var fs_extra=require(_0xf540('0x9'));var _=require('lodash');var squel=require('squel');var crypto=require(_0xf540('0xa'));var jsforce=require('jsforce');var deskjs=require(_0xf540('0xb'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0xf540('0xc'));var Redis=require(_0xf540('0xd'));var authService=require(_0xf540('0xe'));var qs=require(_0xf540('0xf'));var as=require(_0xf540('0x10'));var hardwareService=require(_0xf540('0x11'));var logger=require(_0xf540('0x12'))('api');var utils=require(_0xf540('0x13'));var config=require(_0xf540('0x14'));var licenseUtil=require(_0xf540('0x15'));var db=require(_0xf540('0x16'))['db'];var integrations=require('../../components/integrations/configuration');function respondWithStatusCode(_0xee7774,_0x465f41){_0x465f41=_0x465f41||0xcc;return function(_0x38f9d5){if(_0x38f9d5){return _0xee7774[_0xf540('0x17')](_0x465f41);}return _0xee7774[_0xf540('0x18')](_0x465f41)[_0xf540('0x19')]();};}function respondWithResult(_0x5d9287,_0x1f65fb){_0x1f65fb=_0x1f65fb||0xc8;return function(_0x530db9){if(_0x530db9){return _0x5d9287[_0xf540('0x18')](_0x1f65fb)[_0xf540('0x1a')](_0x530db9);}};}function respondWithFilteredResult(_0x54fb93,_0x5a2fad){return function(_0x49518a){if(_0x49518a){var _0x4a1ad6=typeof _0x5a2fad[_0xf540('0x1b')]===_0xf540('0x1c')&&typeof _0x5a2fad[_0xf540('0x1d')]===_0xf540('0x1c');var _0x5bd736=_0x49518a['count'];var _0x2fa0de=_0x4a1ad6?0x0:_0x5a2fad[_0xf540('0x1b')];var _0x190956=_0x4a1ad6?_0x49518a['count']:_0x5a2fad[_0xf540('0x1b')]+_0x5a2fad['limit'];var _0x1fc881;if(_0x190956>=_0x5bd736){_0x190956=_0x5bd736;_0x1fc881=0xc8;}else{_0x1fc881=0xce;}_0x54fb93[_0xf540('0x18')](_0x1fc881);return _0x54fb93[_0xf540('0x1e')](_0xf540('0x1f'),_0x2fa0de+'-'+_0x190956+'/'+_0x5bd736)[_0xf540('0x1a')](_0x49518a);}return null;};}function patchUpdates(_0x1c1a1d){return function(_0x1027a4){try{jsonpatch['apply'](_0x1027a4,_0x1c1a1d,!![]);}catch(_0x5e04be){return BPromise[_0xf540('0x20')](_0x5e04be);}return _0x1027a4[_0xf540('0x21')]();};}function saveUpdates(_0x1bcf3d,_0x4f5d49){return function(_0x320036){if(_0x320036){return _0x320036[_0xf540('0x22')](_0x1bcf3d)[_0xf540('0x23')](function(_0x51f4fb){return _0x51f4fb;});}return null;};}function removeEntity(_0x1c86cd,_0x5a56fa){return function(_0x3131ec){if(_0x3131ec){return _0x3131ec[_0xf540('0x24')]()['then'](function(){_0x1c86cd[_0xf540('0x18')](0xcc)[_0xf540('0x19')]();});}};}function handleEntityNotFound(_0x7949e3,_0xf5770a){return function(_0x26888f){if(!_0x26888f){_0x7949e3[_0xf540('0x17')](0x194);}return _0x26888f;};}function handleError(_0x5b7da6,_0x17f848){_0x17f848=_0x17f848||0x1f4;return function(_0x2bfe2a){logger[_0xf540('0x25')](_0x2bfe2a[_0xf540('0x26')]);if(_0x2bfe2a[_0xf540('0x27')]){delete _0x2bfe2a[_0xf540('0x27')];}_0x5b7da6[_0xf540('0x18')](_0x17f848)[_0xf540('0x28')](_0x2bfe2a);};}exports[_0xf540('0x29')]=function(_0x344dc6,_0x1cb741){var _0x394356={},_0x447aed={},_0x2fada5={'count':0x0,'rows':[]};var _0x1c45b4=_['map'](db['SalesforceAccount']['rawAttributes'],function(_0x3f0667){return{'name':_0x3f0667[_0xf540('0x2a')],'type':_0x3f0667['type'][_0xf540('0x2b')]};});_0x447aed[_0xf540('0x2c')]=_[_0xf540('0x2d')](_0x1c45b4,_0xf540('0x27'));_0x447aed[_0xf540('0x2e')]=_[_0xf540('0x2f')](_0x344dc6[_0xf540('0x2e')]);_0x447aed['filters']=_[_0xf540('0x30')](_0x447aed[_0xf540('0x2c')],_0x447aed[_0xf540('0x2e')]);_0x394356[_0xf540('0x31')]=_['intersection'](_0x447aed[_0xf540('0x2c')],qs['fields'](_0x344dc6[_0xf540('0x2e')][_0xf540('0x32')]));_0x394356[_0xf540('0x31')]=_0x394356[_0xf540('0x31')][_0xf540('0x33')]?_0x394356[_0xf540('0x31')]:_0x447aed['model'];if(!_0x344dc6[_0xf540('0x2e')][_0xf540('0x34')](_0xf540('0x35'))){_0x394356[_0xf540('0x1d')]=qs[_0xf540('0x1d')](_0x344dc6[_0xf540('0x2e')][_0xf540('0x1d')]);_0x394356[_0xf540('0x1b')]=qs[_0xf540('0x1b')](_0x344dc6[_0xf540('0x2e')]['offset']);}_0x394356[_0xf540('0x36')]=qs[_0xf540('0x37')](_0x344dc6[_0xf540('0x2e')][_0xf540('0x37')]);_0x394356['where']=qs[_0xf540('0x38')](_[_0xf540('0x39')](_0x344dc6[_0xf540('0x2e')],_0x447aed[_0xf540('0x38')]),_0x1c45b4);if(_0x344dc6[_0xf540('0x2e')]['filter']){_0x394356[_0xf540('0x3a')]=_[_0xf540('0x3b')](_0x394356['where'],{'$or':_['map'](_0x1c45b4,function(_0x7433f){if(_0x7433f[_0xf540('0x3c')]!==_0xf540('0x3d')){var _0x144098={};_0x144098[_0x7433f[_0xf540('0x27')]]={'$like':'%'+_0x344dc6[_0xf540('0x2e')][_0xf540('0x3e')]+'%'};return _0x144098;}})});}_0x394356=_[_0xf540('0x3b')]({},_0x394356,_0x344dc6['options']);var _0x47ecab={'where':_0x394356[_0xf540('0x3a')]};return db[_0xf540('0x3f')][_0xf540('0x40')](_0x47ecab)[_0xf540('0x23')](function(_0x2358cb){_0x2fada5[_0xf540('0x40')]=_0x2358cb;if(_0x344dc6[_0xf540('0x2e')][_0xf540('0x41')]){_0x394356[_0xf540('0x42')]=[{'all':!![]}];}return db[_0xf540('0x3f')][_0xf540('0x43')](_0x394356);})[_0xf540('0x23')](function(_0x12dab3){_0x2fada5[_0xf540('0x44')]=_0x12dab3;return _0x2fada5;})[_0xf540('0x23')](respondWithFilteredResult(_0x1cb741,_0x394356))['catch'](handleError(_0x1cb741,null));};exports[_0xf540('0x45')]=function(_0x529025,_0x3ba5dd){var _0x240130={'raw':![],'where':{'id':_0x529025['params']['id']}},_0x1a578f={};_0x1a578f[_0xf540('0x2c')]=_[_0xf540('0x2f')](db[_0xf540('0x3f')][_0xf540('0x46')]);_0x1a578f[_0xf540('0x2e')]=_[_0xf540('0x2f')](_0x529025[_0xf540('0x2e')]);_0x1a578f[_0xf540('0x38')]=_[_0xf540('0x30')](_0x1a578f[_0xf540('0x2c')],_0x1a578f[_0xf540('0x2e')]);_0x240130[_0xf540('0x31')]=_[_0xf540('0x30')](_0x1a578f['model'],qs['fields'](_0x529025[_0xf540('0x2e')][_0xf540('0x32')]));_0x240130[_0xf540('0x31')]=_0x240130[_0xf540('0x31')]['length']?_0x240130[_0xf540('0x31')]:_0x1a578f[_0xf540('0x2c')];if(_0x529025[_0xf540('0x2e')][_0xf540('0x41')]){_0x240130['include']=[{'all':!![]}];}_0x240130=_[_0xf540('0x3b')]({},_0x240130,_0x529025['options']);return db[_0xf540('0x3f')][_0xf540('0x47')](_0x240130)[_0xf540('0x23')](handleEntityNotFound(_0x3ba5dd,null))[_0xf540('0x23')](respondWithResult(_0x3ba5dd,null))[_0xf540('0x48')](handleError(_0x3ba5dd,null));};exports[_0xf540('0x49')]=function(_0x21075f,_0x57dd7f){return db['SalesforceAccount'][_0xf540('0x49')](_0x21075f[_0xf540('0x4a')],{})[_0xf540('0x23')](respondWithResult(_0x57dd7f,0xc9))[_0xf540('0x48')](handleError(_0x57dd7f,null));};exports[_0xf540('0x22')]=function(_0x6a3964,_0x5deefe){if(_0x6a3964[_0xf540('0x4a')]['id']){delete _0x6a3964['body']['id'];}return db[_0xf540('0x3f')][_0xf540('0x47')]({'where':{'id':_0x6a3964[_0xf540('0x4b')]['id']}})[_0xf540('0x23')](handleEntityNotFound(_0x5deefe,null))[_0xf540('0x23')](saveUpdates(_0x6a3964['body'],null))[_0xf540('0x23')](respondWithResult(_0x5deefe,null))[_0xf540('0x48')](handleError(_0x5deefe,null));};exports[_0xf540('0x24')]=function(_0x259fa3,_0x4c22af){return db[_0xf540('0x3f')][_0xf540('0x47')]({'where':{'id':_0x259fa3[_0xf540('0x4b')]['id']}})['then'](handleEntityNotFound(_0x4c22af,null))[_0xf540('0x23')](removeEntity(_0x4c22af,null))[_0xf540('0x48')](handleError(_0x4c22af,null));};exports[_0xf540('0x4c')]=function(_0x2bee54,_0x18c258,_0x9b1f15){var _0x59aadb={};var _0x2b8665={};var _0x19e8c8;var _0x461788;return db[_0xf540('0x3f')][_0xf540('0x4d')]({'where':{'id':_0x2bee54[_0xf540('0x4b')]['id']}})[_0xf540('0x23')](handleEntityNotFound(_0x18c258,null))[_0xf540('0x23')](function(_0x3312ac){if(_0x3312ac){_0x19e8c8=_0x3312ac;_0x2b8665[_0xf540('0x2c')]=_[_0xf540('0x2f')](db[_0xf540('0x4e')][_0xf540('0x46')]);_0x2b8665[_0xf540('0x2e')]=_[_0xf540('0x2f')](_0x2bee54[_0xf540('0x2e')]);_0x2b8665[_0xf540('0x38')]=_[_0xf540('0x30')](_0x2b8665[_0xf540('0x2c')],_0x2b8665[_0xf540('0x2e')]);_0x59aadb['attributes']=_[_0xf540('0x30')](_0x2b8665['model'],qs[_0xf540('0x32')](_0x2bee54[_0xf540('0x2e')]['fields']));_0x59aadb[_0xf540('0x31')]=_0x59aadb[_0xf540('0x31')][_0xf540('0x33')]?_0x59aadb['attributes']:_0x2b8665['model'];_0x59aadb['order']=qs[_0xf540('0x37')](_0x2bee54['query'][_0xf540('0x37')]);_0x59aadb['where']=qs[_0xf540('0x38')](_[_0xf540('0x39')](_0x2bee54['query'],_0x2b8665[_0xf540('0x38')]));if(_0x2bee54[_0xf540('0x2e')][_0xf540('0x3e')]){_0x59aadb[_0xf540('0x3a')]=_[_0xf540('0x3b')](_0x59aadb[_0xf540('0x3a')],{'$or':_[_0xf540('0x2d')](_0x59aadb[_0xf540('0x31')],function(_0x3077a7){var _0x36bc45={};_0x36bc45[_0x3077a7]={'$like':'%'+_0x2bee54[_0xf540('0x2e')][_0xf540('0x3e')]+'%'};return _0x36bc45;})});}_0x59aadb=_[_0xf540('0x3b')]({},_0x59aadb,_0x2bee54[_0xf540('0x4f')]);return _0x19e8c8[_0xf540('0x4c')](_0x59aadb);}})[_0xf540('0x23')](function(_0x1f7d3e){if(_0x1f7d3e){_0x461788=_0x1f7d3e[_0xf540('0x33')];if(!_0x2bee54[_0xf540('0x2e')][_0xf540('0x34')](_0xf540('0x35'))){_0x59aadb[_0xf540('0x1d')]=qs['limit'](_0x2bee54['query'][_0xf540('0x1d')]);_0x59aadb['offset']=qs[_0xf540('0x1b')](_0x2bee54[_0xf540('0x2e')][_0xf540('0x1b')]);}return _0x19e8c8[_0xf540('0x4c')](_0x59aadb);}})[_0xf540('0x23')](function(_0x13c8d0){if(_0x13c8d0){return _0x13c8d0?{'count':_0x461788,'rows':_0x13c8d0}:null;}})[_0xf540('0x23')](respondWithResult(_0x18c258,null))[_0xf540('0x48')](handleError(_0x18c258,null));};exports[_0xf540('0x50')]=function(_0x5c1e30,_0x4b137e,_0x312c71){if(_0x5c1e30['body']['id']){delete _0x5c1e30[_0xf540('0x4a')]['id'];}return db[_0xf540('0x3f')]['findOne']({'where':{'id':_0x5c1e30[_0xf540('0x4b')]['id']}})[_0xf540('0x23')](handleEntityNotFound(_0x4b137e,null))[_0xf540('0x23')](function(_0x44b77e){if(_0x44b77e){_0x5c1e30[_0xf540('0x4a')][_0xf540('0x51')]=_0x44b77e['id'];_0x5c1e30[_0xf540('0x4a')][_0xf540('0x52')]=integrations[_0xf540('0x53')](_0x5c1e30[_0xf540('0x4a')]['channel'],_0x5c1e30[_0xf540('0x4a')][_0xf540('0x3c')]);_0x5c1e30[_0xf540('0x4a')][_0xf540('0x54')]=integrations[_0xf540('0x55')](_0x5c1e30[_0xf540('0x4a')]['channel'],_0x5c1e30[_0xf540('0x4a')]['type']);return db[_0xf540('0x4e')][_0xf540('0x49')](_0x5c1e30['body'],{'include':[{'model':db[_0xf540('0x56')],'as':_0xf540('0x52')},{'model':db[_0xf540('0x56')],'as':_0xf540('0x54')}]});}return null;})[_0xf540('0x23')](respondWithResult(_0x4b137e,null))[_0xf540('0x48')](handleError(_0x4b137e,null));};exports[_0xf540('0x57')]=function(_0x379a1c,_0x5c0cf1,_0x41073b){var _0x57ffca;var _0x313764='';var _0x2d46d9=_0xf540('0x58');return db['SalesforceAccount']['findOne']({'where':{'id':_0x379a1c[_0xf540('0x4b')]['id']},'attributes':['id',_0xf540('0x59'),_0xf540('0x5a'),_0xf540('0x5b'),_0xf540('0x5c'),'password',_0xf540('0x5d')]})['then'](handleEntityNotFound(_0x5c0cf1,null))['then'](function(_0x3168bc){if(_0x3168bc){_0x313764=_0x3168bc[_0xf540('0x59')];var _0x237454=_0x313764['slice'](-0x1);if(_0x237454==='/'){_0x313764=_0x313764['substring'](0x0,_0x313764[_0xf540('0x5e')](_0x237454));}_0x57ffca=new jsforce[(_0xf540('0x5f'))]({'oauth2':{'loginUrl':_0x313764,'clientId':_0x3168bc['clientId'],'clientSecret':_0x3168bc[_0xf540('0x5b')]}});return _0x57ffca[_0xf540('0x60')](_0x3168bc[_0xf540('0x5c')],_0x3168bc[_0xf540('0x61')]['concat'](_0x3168bc[_0xf540('0x5d')]));}})['then'](function(_0x208fc6){if(_0x208fc6){if(!_[_0xf540('0x62')](_0x379a1c['query'][_0xf540('0x63')])){_0x2d46d9=_0x379a1c[_0xf540('0x2e')][_0xf540('0x63')];}return _0x57ffca[_0xf540('0x64')](_0x2d46d9)[_0xf540('0x65')]();}})[_0xf540('0x23')](function(_0x57af0d){var _0x356310=[_0xf540('0x66'),_0xf540('0x67'),_0xf540('0x68'),'IsRecurrence',_0xf540('0x69'),_0xf540('0x6a')];var _0x4fffcd=['string','int','picklist','boolean',_0xf540('0x6b'),_0xf540('0x6c'),'phone'];if(_0x57af0d){_[_0xf540('0x6d')](_0x57af0d[_0xf540('0x32')],function(_0xa745fe){return _0x356310[_0xf540('0x6e')](_0xa745fe[_0xf540('0x27')])||!_0x4fffcd['includes'](_0xa745fe[_0xf540('0x3c')]);});return{'count':_0x57af0d[_0xf540('0x32')][_0xf540('0x33')],'rows':_[_0xf540('0x2d')](_0x57af0d['fields'],function(_0x3040d7){return{'id':_0x3040d7[_0xf540('0x27')],'name':_0x3040d7[_0xf540('0x6f')],'custom':_0x3040d7[_0xf540('0x70')],'options':_0x3040d7[_0xf540('0x71')][_0xf540('0x33')]>0x0?_[_0xf540('0x2d')](_0x3040d7[_0xf540('0x71')],function(_0xcde4ce){return{'name':_0xcde4ce['label'],'value':_0xcde4ce[_0xf540('0x72')]};}):_0x3040d7[_0xf540('0x3c')]==_0xf540('0x73')?[{'name':'True','value':_0xf540('0x74')},{'name':_0xf540('0x75'),'value':_0xf540('0x76')}]:[]};})};}})['then'](respondWithResult(_0x5c0cf1,null))[_0xf540('0x48')](function(_0x4bdb5b){var _0x40ba50=_0x379a1c['query'][_0xf540('0x77')]?0x1f4:_0x4bdb5b[_0xf540('0x78')]||0x1f4;logger['error'](_0xf540('0x79'),_0xf540('0x57'),_0x40ba50,JSON[_0xf540('0x7a')](_0x4bdb5b));delete _0x4bdb5b[_0xf540('0x27')];if(_0x40ba50===0x191){_0x40ba50=0x190;}_0x5c0cf1[_0xf540('0x18')](_0x40ba50)['send'](_0x379a1c[_0xf540('0x2e')]['test']?{'message':_0xf540('0x7b'),'statusCode':_0x4bdb5b[_0xf540('0x78')]}:_0x4bdb5b);});};
\ No newline at end of file