Built motion from commit (unavailable).|2.5.29
[motion2.git] / server / api / intSalesforceAccount / intSalesforceAccount.controller.js
index 267b7f4..bb4facc 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x761f=['lastIndexOf','password','concat','ticketType','sobject','OwnerId','ActivityDate','IsReminderSet','IsRecurrence','int','email','textarea','phone','remove','includes','custom','picklistValues','label','value','boolean','true','False','false','test','statusCode','getFields,\x20%s,\x20%s,\x20%s','send','Wrong\x20credentials','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','bluebird','sox','ejs','lodash','squel','crypto','desk.js','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','../../components/integrations/configuration','jayson/promise','http','request','info','SalesforceAccount,\x20%s,\x20%s','request\x20sent','SalesforceAccount,\x20%s,\x20%s,\x20%s','stringify','error','message','result','sendStatus','status','end','json','count','offset','limit','set','Content-Range','save','update','then','destroy','stack','name','index','SalesforceAccount','rawAttributes','fieldName','key','query','keys','filters','attributes','intersection','model','fields','hasOwnProperty','sort','where','pick','merge','map','type','VIRTUAL','options','includeAll','findAll','rows','show','params','length','create','body','find','catch','getConfigurations','findOne','SalesforceConfiguration','filter','nolimit','addConfiguration','getSubjects','channel','Descriptions','getDescriptions','SalesforceField','Subjects','Task','clientSecret','username','securityToken','remoteUri','substring'];(function(_0x2e7b71,_0x30eb38){var _0x3831b4=function(_0x1015b4){while(--_0x1015b4){_0x2e7b71['push'](_0x2e7b71['shift']());}};_0x3831b4(++_0x30eb38);}(_0x761f,0x11e));var _0xf761=function(_0xd2f4ac,_0x5aa8e5){_0xd2f4ac=_0xd2f4ac-0x0;var _0x9757b2=_0x761f[_0xd2f4ac];return _0x9757b2;};'use strict';var pdf=require(_0xf761('0x0'));var emlformat=require(_0xf761('0x1'));var rimraf=require(_0xf761('0x2'));var zipdir=require(_0xf761('0x3'));var jsonpatch=require(_0xf761('0x4'));var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0xf761('0x5'));var Mustache=require('mustache');var util=require('util');var path=require('path');var sox=require(_0xf761('0x6'));var csv=require('to-csv');var ejs=require(_0xf761('0x7'));var fs=require('fs');var _=require(_0xf761('0x8'));var squel=require(_0xf761('0x9'));var crypto=require(_0xf761('0xa'));var jsforce=require('jsforce');var deskjs=require(_0xf761('0xb'));var toCsv=require(_0xf761('0xc'));var querystring=require(_0xf761('0xd'));var Papa=require(_0xf761('0xe'));var Redis=require(_0xf761('0xf'));var authService=require(_0xf761('0x10'));var qs=require(_0xf761('0x11'));var as=require(_0xf761('0x12'));var hardwareService=require(_0xf761('0x13'));var logger=require(_0xf761('0x14'))(_0xf761('0x15'));var utils=require(_0xf761('0x16'));var config=require('../../config/environment');var licenseUtil=require(_0xf761('0x17'));var db=require(_0xf761('0x18'))['db'];var integrations=require(_0xf761('0x19'));var jayson=require(_0xf761('0x1a'));var client=jayson['client'][_0xf761('0x1b')]({'port':0x232a});function respondWithRpcPromise(_0x15bdbb,_0x36ddca,_0x413e17,_0x28039e){return new BPromise(function(_0x2f6719,_0x55eaa4){var _0x3b49ba=_0x28039e||client;return _0x3b49ba[_0xf761('0x1c')](_0x15bdbb,_0x413e17)['then'](function(_0x3df081){logger[_0xf761('0x1d')](_0xf761('0x1e'),_0x36ddca,_0xf761('0x1f'));logger['debug'](_0xf761('0x20'),_0x36ddca,_0xf761('0x1f'),JSON[_0xf761('0x21')](_0x3df081));if(_0x3df081['error']){if(_0x3df081['error']['code']===0x1f4){logger[_0xf761('0x22')](_0xf761('0x1e'),_0x36ddca,_0x3df081[_0xf761('0x22')][_0xf761('0x23')]);return _0x55eaa4(_0x3df081[_0xf761('0x22')][_0xf761('0x23')]);}logger['error']('SalesforceAccount,\x20%s,\x20%s',_0x36ddca,_0x3df081[_0xf761('0x22')][_0xf761('0x23')]);return _0x2f6719(_0x3df081[_0xf761('0x22')]['message']);}else{logger[_0xf761('0x1d')](_0xf761('0x1e'),_0x36ddca,_0xf761('0x1f'));_0x2f6719(_0x3df081[_0xf761('0x24')]['message']);}})['catch'](function(_0x6fa14a){logger[_0xf761('0x22')](_0xf761('0x1e'),_0x36ddca,_0x6fa14a);_0x55eaa4(_0x6fa14a);});});}function respondWithStatusCode(_0xdf1dad,_0x4253d1){_0x4253d1=_0x4253d1||0xcc;return function(_0x5b627a){if(_0x5b627a){return _0xdf1dad[_0xf761('0x25')](_0x4253d1);}return _0xdf1dad[_0xf761('0x26')](_0x4253d1)[_0xf761('0x27')]();};}function respondWithResult(_0x29fc97,_0x48d7f6){_0x48d7f6=_0x48d7f6||0xc8;return function(_0x4b8bec){if(_0x4b8bec){return _0x29fc97[_0xf761('0x26')](_0x48d7f6)[_0xf761('0x28')](_0x4b8bec);}};}function respondWithFilteredResult(_0x279fb0,_0x5ca468){return function(_0x3eb3e2){if(_0x3eb3e2){var _0x30464c=_0x3eb3e2[_0xf761('0x29')],_0x3d5b2c=_0x5ca468[_0xf761('0x2a')],_0x7ba306=_0x5ca468[_0xf761('0x2a')]+_0x5ca468[_0xf761('0x2b')],_0x3fa2eb;if(_0x7ba306>=_0x30464c){_0x7ba306=_0x30464c;_0x3fa2eb=0xc8;}else{_0x3fa2eb=0xce;}_0x279fb0[_0xf761('0x26')](_0x3fa2eb);return _0x279fb0[_0xf761('0x2c')](_0xf761('0x2d'),_0x3d5b2c+'-'+_0x7ba306+'/'+_0x30464c)[_0xf761('0x28')](_0x3eb3e2);}return null;};}function patchUpdates(_0x4db7df){return function(_0x428f1e){try{jsonpatch['apply'](_0x428f1e,_0x4db7df,!![]);}catch(_0x47f798){return BPromise['reject'](_0x47f798);}return _0x428f1e[_0xf761('0x2e')]();};}function saveUpdates(_0x2891c7,_0x49229b){return function(_0x2758dd){if(_0x2758dd){return _0x2758dd[_0xf761('0x2f')](_0x2891c7)[_0xf761('0x30')](function(_0x34be6b){return _0x34be6b;});}return null;};}function removeEntity(_0x22f418,_0x5021fd){return function(_0x5d0807){if(_0x5d0807){return _0x5d0807[_0xf761('0x31')]()[_0xf761('0x30')](function(){_0x22f418[_0xf761('0x26')](0xcc)[_0xf761('0x27')]();});}};}function handleEntityNotFound(_0x2151ad,_0x3247b4){return function(_0x26f962){if(!_0x26f962){_0x2151ad['sendStatus'](0x194);}return _0x26f962;};}function handleError(_0x376284,_0x3008b2){_0x3008b2=_0x3008b2||0x1f4;return function(_0x306f01){logger[_0xf761('0x22')](_0x306f01[_0xf761('0x32')]);if(_0x306f01[_0xf761('0x33')]){delete _0x306f01[_0xf761('0x33')];}_0x376284[_0xf761('0x26')](_0x3008b2)['send'](_0x306f01);};}exports[_0xf761('0x34')]=function(_0x1fd44e,_0x567b1f){var _0x2596ed={},_0x352095={},_0x3ee17f={'count':0x0,'rows':[]};var _0x2fb701=_['map'](db[_0xf761('0x35')][_0xf761('0x36')],function(_0x56b006){return{'name':_0x56b006[_0xf761('0x37')],'type':_0x56b006['type'][_0xf761('0x38')]};});_0x352095['model']=_['map'](_0x2fb701,_0xf761('0x33'));_0x352095[_0xf761('0x39')]=_[_0xf761('0x3a')](_0x1fd44e['query']);_0x352095[_0xf761('0x3b')]=_['intersection'](_0x352095['model'],_0x352095['query']);_0x2596ed[_0xf761('0x3c')]=_[_0xf761('0x3d')](_0x352095[_0xf761('0x3e')],qs[_0xf761('0x3f')](_0x1fd44e[_0xf761('0x39')][_0xf761('0x3f')]));_0x2596ed[_0xf761('0x3c')]=_0x2596ed['attributes']['length']?_0x2596ed[_0xf761('0x3c')]:_0x352095['model'];if(!_0x1fd44e[_0xf761('0x39')][_0xf761('0x40')]('nolimit')){_0x2596ed[_0xf761('0x2b')]=qs[_0xf761('0x2b')](_0x1fd44e[_0xf761('0x39')][_0xf761('0x2b')]);_0x2596ed[_0xf761('0x2a')]=qs[_0xf761('0x2a')](_0x1fd44e[_0xf761('0x39')]['offset']);}_0x2596ed['order']=qs[_0xf761('0x41')](_0x1fd44e[_0xf761('0x39')][_0xf761('0x41')]);_0x2596ed[_0xf761('0x42')]=qs[_0xf761('0x3b')](_[_0xf761('0x43')](_0x1fd44e[_0xf761('0x39')],_0x352095[_0xf761('0x3b')]),_0x2fb701);if(_0x1fd44e['query']['filter']){_0x2596ed[_0xf761('0x42')]=_[_0xf761('0x44')](_0x2596ed[_0xf761('0x42')],{'$or':_[_0xf761('0x45')](_0x2fb701,function(_0xbeeb1a){if(_0xbeeb1a[_0xf761('0x46')]!==_0xf761('0x47')){var _0x5b6386={};_0x5b6386[_0xbeeb1a['name']]={'$like':'%'+_0x1fd44e[_0xf761('0x39')]['filter']+'%'};return _0x5b6386;}})});}_0x2596ed=_[_0xf761('0x44')]({},_0x2596ed,_0x1fd44e[_0xf761('0x48')]);var _0x3a86a3={'where':_0x2596ed[_0xf761('0x42')]};return db[_0xf761('0x35')][_0xf761('0x29')](_0x3a86a3)['then'](function(_0x3a0b2d){_0x3ee17f[_0xf761('0x29')]=_0x3a0b2d;if(_0x1fd44e[_0xf761('0x39')][_0xf761('0x49')]){_0x2596ed['include']=[{'all':!![]}];}return db[_0xf761('0x35')][_0xf761('0x4a')](_0x2596ed);})[_0xf761('0x30')](function(_0x3bf9e7){_0x3ee17f[_0xf761('0x4b')]=_0x3bf9e7;return _0x3ee17f;})[_0xf761('0x30')](respondWithFilteredResult(_0x567b1f,_0x2596ed))['catch'](handleError(_0x567b1f,null));};exports[_0xf761('0x4c')]=function(_0x530753,_0x40443d){var _0x238f70={'raw':![],'where':{'id':_0x530753[_0xf761('0x4d')]['id']}},_0x27b42c={};_0x27b42c[_0xf761('0x3e')]=_[_0xf761('0x3a')](db['SalesforceAccount'][_0xf761('0x36')]);_0x27b42c['query']=_['keys'](_0x530753[_0xf761('0x39')]);_0x27b42c[_0xf761('0x3b')]=_[_0xf761('0x3d')](_0x27b42c[_0xf761('0x3e')],_0x27b42c['query']);_0x238f70[_0xf761('0x3c')]=_[_0xf761('0x3d')](_0x27b42c[_0xf761('0x3e')],qs[_0xf761('0x3f')](_0x530753[_0xf761('0x39')][_0xf761('0x3f')]));_0x238f70['attributes']=_0x238f70[_0xf761('0x3c')][_0xf761('0x4e')]?_0x238f70[_0xf761('0x3c')]:_0x27b42c[_0xf761('0x3e')];if(_0x530753[_0xf761('0x39')][_0xf761('0x49')]){_0x238f70['include']=[{'all':!![]}];}_0x238f70=_[_0xf761('0x44')]({},_0x238f70,_0x530753[_0xf761('0x48')]);return db['SalesforceAccount']['find'](_0x238f70)[_0xf761('0x30')](handleEntityNotFound(_0x40443d,null))[_0xf761('0x30')](respondWithResult(_0x40443d,null))['catch'](handleError(_0x40443d,null));};exports[_0xf761('0x4f')]=function(_0x3a1267,_0x5a481c){return db[_0xf761('0x35')][_0xf761('0x4f')](_0x3a1267['body'],{})[_0xf761('0x30')](respondWithResult(_0x5a481c,0xc9))['catch'](handleError(_0x5a481c,null));};exports[_0xf761('0x2f')]=function(_0x14db2a,_0x558515){if(_0x14db2a[_0xf761('0x50')]['id']){delete _0x14db2a['body']['id'];}return db['SalesforceAccount'][_0xf761('0x51')]({'where':{'id':_0x14db2a[_0xf761('0x4d')]['id']}})[_0xf761('0x30')](handleEntityNotFound(_0x558515,null))['then'](saveUpdates(_0x14db2a[_0xf761('0x50')],null))[_0xf761('0x30')](respondWithResult(_0x558515,null))['catch'](handleError(_0x558515,null));};exports[_0xf761('0x31')]=function(_0x1eaf16,_0x3d6c07){return db[_0xf761('0x35')][_0xf761('0x51')]({'where':{'id':_0x1eaf16['params']['id']}})['then'](handleEntityNotFound(_0x3d6c07,null))['then'](removeEntity(_0x3d6c07,null))[_0xf761('0x52')](handleError(_0x3d6c07,null));};exports[_0xf761('0x53')]=function(_0x3d1037,_0xc0e378,_0x39663d){var _0x1c4eb3={};var _0x4f74db={};var _0x144735;var _0x5b0b99;return db[_0xf761('0x35')][_0xf761('0x54')]({'where':{'id':_0x3d1037['params']['id']}})[_0xf761('0x30')](handleEntityNotFound(_0xc0e378,null))[_0xf761('0x30')](function(_0x5ae163){if(_0x5ae163){_0x144735=_0x5ae163;_0x4f74db['model']=_['keys'](db[_0xf761('0x55')][_0xf761('0x36')]);_0x4f74db[_0xf761('0x39')]=_['keys'](_0x3d1037[_0xf761('0x39')]);_0x4f74db[_0xf761('0x3b')]=_['intersection'](_0x4f74db[_0xf761('0x3e')],_0x4f74db[_0xf761('0x39')]);_0x1c4eb3[_0xf761('0x3c')]=_[_0xf761('0x3d')](_0x4f74db[_0xf761('0x3e')],qs[_0xf761('0x3f')](_0x3d1037['query'][_0xf761('0x3f')]));_0x1c4eb3['attributes']=_0x1c4eb3[_0xf761('0x3c')][_0xf761('0x4e')]?_0x1c4eb3[_0xf761('0x3c')]:_0x4f74db[_0xf761('0x3e')];_0x1c4eb3['order']=qs[_0xf761('0x41')](_0x3d1037[_0xf761('0x39')][_0xf761('0x41')]);_0x1c4eb3['where']=qs[_0xf761('0x3b')](_['pick'](_0x3d1037[_0xf761('0x39')],_0x4f74db[_0xf761('0x3b')]));if(_0x3d1037[_0xf761('0x39')][_0xf761('0x56')]){_0x1c4eb3[_0xf761('0x42')]=_['merge'](_0x1c4eb3[_0xf761('0x42')],{'$or':_[_0xf761('0x45')](_0x1c4eb3['attributes'],function(_0x317cf9){var _0x5dfc91={};_0x5dfc91[_0x317cf9]={'$like':'%'+_0x3d1037[_0xf761('0x39')][_0xf761('0x56')]+'%'};return _0x5dfc91;})});}_0x1c4eb3=_[_0xf761('0x44')]({},_0x1c4eb3,_0x3d1037[_0xf761('0x48')]);return _0x144735[_0xf761('0x53')](_0x1c4eb3);}})[_0xf761('0x30')](function(_0x2e5578){if(_0x2e5578){_0x5b0b99=_0x2e5578['length'];if(!_0x3d1037['query'][_0xf761('0x40')](_0xf761('0x57'))){_0x1c4eb3[_0xf761('0x2b')]=qs[_0xf761('0x2b')](_0x3d1037[_0xf761('0x39')][_0xf761('0x2b')]);_0x1c4eb3[_0xf761('0x2a')]=qs[_0xf761('0x2a')](_0x3d1037[_0xf761('0x39')][_0xf761('0x2a')]);}return _0x144735['getConfigurations'](_0x1c4eb3);}})[_0xf761('0x30')](function(_0x4f171e){if(_0x4f171e){return _0x4f171e?{'count':_0x5b0b99,'rows':_0x4f171e}:null;}})['then'](respondWithResult(_0xc0e378,null))[_0xf761('0x52')](handleError(_0xc0e378,null));};exports[_0xf761('0x58')]=function(_0x3af3ff,_0x12d74c,_0x4251ff){if(_0x3af3ff['body']['id']){delete _0x3af3ff[_0xf761('0x50')]['id'];}return db[_0xf761('0x35')]['findOne']({'where':{'id':_0x3af3ff['params']['id']}})[_0xf761('0x30')](handleEntityNotFound(_0x12d74c,null))[_0xf761('0x30')](function(_0x4c0186){if(_0x4c0186){_0x3af3ff[_0xf761('0x50')]['AccountId']=_0x4c0186['id'];_0x3af3ff[_0xf761('0x50')]['Subjects']=integrations[_0xf761('0x59')](_0x3af3ff['body'][_0xf761('0x5a')],_0x3af3ff[_0xf761('0x50')][_0xf761('0x46')]);_0x3af3ff[_0xf761('0x50')][_0xf761('0x5b')]=integrations[_0xf761('0x5c')](_0x3af3ff[_0xf761('0x50')][_0xf761('0x5a')],_0x3af3ff['body']['type']);return db['SalesforceConfiguration'][_0xf761('0x4f')](_0x3af3ff['body'],{'include':[{'model':db[_0xf761('0x5d')],'as':_0xf761('0x5e')},{'model':db['SalesforceField'],'as':_0xf761('0x5b')}]});}return null;})['then'](respondWithResult(_0x12d74c,null))[_0xf761('0x52')](handleError(_0x12d74c,null));};exports['getFields']=function(_0x226dcc,_0x3b4209,_0x517310){var _0x44f952;var _0x278308='';var _0x41034c=_0xf761('0x5f');return db[_0xf761('0x35')][_0xf761('0x54')]({'where':{'id':_0x226dcc[_0xf761('0x4d')]['id']},'attributes':['id','remoteUri','clientId',_0xf761('0x60'),_0xf761('0x61'),'password',_0xf761('0x62')]})[_0xf761('0x30')](handleEntityNotFound(_0x3b4209,null))[_0xf761('0x30')](function(_0x2838a4){if(_0x2838a4){_0x278308=_0x2838a4[_0xf761('0x63')];var _0x12eedb=_0x278308['slice'](-0x1);if(_0x12eedb==='/'){_0x278308=_0x278308[_0xf761('0x64')](0x0,_0x278308[_0xf761('0x65')](_0x12eedb));}_0x44f952=new jsforce['Connection']({'oauth2':{'loginUrl':_0x278308,'clientId':_0x2838a4['clientId'],'clientSecret':_0x2838a4[_0xf761('0x60')]}});return _0x44f952['login'](_0x2838a4[_0xf761('0x61')],_0x2838a4[_0xf761('0x66')][_0xf761('0x67')](_0x2838a4['securityToken']));}})[_0xf761('0x30')](function(_0x56acb5){if(_0x56acb5){if(!_['isNil'](_0x226dcc[_0xf761('0x39')]['ticketType'])){_0x41034c=_0x226dcc[_0xf761('0x39')][_0xf761('0x68')];}return _0x44f952[_0xf761('0x69')](_0x41034c)['describe']();}})[_0xf761('0x30')](function(_0x45dca6){var _0x197517=[_0xf761('0x6a'),_0xf761('0x6b'),_0xf761('0x6c'),_0xf761('0x6d'),'Subject','Description'];var _0xa3e1d2=['string',_0xf761('0x6e'),'picklist','boolean',_0xf761('0x6f'),_0xf761('0x70'),_0xf761('0x71')];if(_0x45dca6){_[_0xf761('0x72')](_0x45dca6[_0xf761('0x3f')],function(_0x393328){return _0x197517[_0xf761('0x73')](_0x393328[_0xf761('0x33')])||!_0xa3e1d2['includes'](_0x393328[_0xf761('0x46')]);});return{'count':_0x45dca6[_0xf761('0x3f')][_0xf761('0x4e')],'rows':_['map'](_0x45dca6['fields'],function(_0xfef59f){return{'id':_0xfef59f[_0xf761('0x33')],'name':_0xfef59f['label'],'custom':_0xfef59f[_0xf761('0x74')],'options':_0xfef59f[_0xf761('0x75')]['length']>0x0?_[_0xf761('0x45')](_0xfef59f['picklistValues'],function(_0x75f2d5){return{'name':_0x75f2d5[_0xf761('0x76')],'value':_0x75f2d5[_0xf761('0x77')]};}):_0xfef59f[_0xf761('0x46')]==_0xf761('0x78')?[{'name':'True','value':_0xf761('0x79')},{'name':_0xf761('0x7a'),'value':_0xf761('0x7b')}]:[]};})};}})[_0xf761('0x30')](respondWithResult(_0x3b4209,null))['catch'](function(_0x7ed7c0){var _0x478f8a=_0x226dcc[_0xf761('0x39')][_0xf761('0x7c')]?0x1f4:_0x7ed7c0[_0xf761('0x7d')]||0x1f4;logger[_0xf761('0x22')](_0xf761('0x7e'),'getFields',_0x478f8a,JSON[_0xf761('0x21')](_0x7ed7c0));delete _0x7ed7c0[_0xf761('0x33')];if(_0x478f8a===0x191){_0x478f8a=0x190;}_0x3b4209[_0xf761('0x26')](_0x478f8a)[_0xf761('0x7f')](_0x226dcc[_0xf761('0x39')][_0xf761('0x7c')]?{'message':_0xf761('0x80'),'statusCode':_0x7ed7c0['statusCode']}:_0x7ed7c0);});};
\ No newline at end of file
+var _0xa896=['../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/license/util','../../mysqldb','../../components/integrations/configuration','jayson/promise','client','http','then','SalesforceAccount,\x20%s,\x20%s','request\x20sent','SalesforceAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','info','catch','end','undefined','count','offset','limit','status','set','Content-Range','json','apply','reject','save','update','destroy','sendStatus','stack','name','index','map','SalesforceAccount','rawAttributes','fieldName','type','query','keys','filters','intersection','model','attributes','fields','length','hasOwnProperty','order','sort','pick','filter','where','merge','options','includeAll','include','findAll','params','create','body','find','findOne','SalesforceConfiguration','getConfigurations','addConfiguration','AccountId','channel','Descriptions','getDescriptions','SalesforceField','Subjects','getFields','Task','remoteUri','clientId','clientSecret','username','password','slice','substring','Connection','login','concat','securityToken','ticketType','OwnerId','ActivityDate','IsReminderSet','Subject','string','int','picklist','boolean','textarea','phone','remove','custom','picklistValues','label','True','true','false','test','statusCode','getFields,\x20%s,\x20%s,\x20%s','send','Wrong\x20credentials','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','mustache','path','ejs','squel','crypto','desk.js','to-csv','querystring','papaparse','ioredis','../../components/auth/service'];(function(_0x5d860f,_0x467498){var _0x236490=function(_0x5e045c){while(--_0x5e045c){_0x5d860f['push'](_0x5d860f['shift']());}};_0x236490(++_0x467498);}(_0xa896,0x173));var _0x6a89=function(_0x47fc46,_0x1577f4){_0x47fc46=_0x47fc46-0x0;var _0x5bc3ae=_0xa896[_0x47fc46];return _0x5bc3ae;};'use strict';var emlformat=require(_0x6a89('0x0'));var rimraf=require(_0x6a89('0x1'));var zipdir=require(_0x6a89('0x2'));var jsonpatch=require(_0x6a89('0x3'));var rp=require(_0x6a89('0x4'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0x6a89('0x5'));var util=require('util');var path=require(_0x6a89('0x6'));var sox=require('sox');var csv=require('to-csv');var ejs=require(_0x6a89('0x7'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require(_0x6a89('0x8'));var crypto=require(_0x6a89('0x9'));var jsforce=require('jsforce');var deskjs=require(_0x6a89('0xa'));var toCsv=require(_0x6a89('0xb'));var querystring=require(_0x6a89('0xc'));var Papa=require(_0x6a89('0xd'));var Redis=require(_0x6a89('0xe'));var authService=require(_0x6a89('0xf'));var qs=require(_0x6a89('0x10'));var as=require(_0x6a89('0x11'));var hardwareService=require(_0x6a89('0x12'));var logger=require(_0x6a89('0x13'))('api');var utils=require(_0x6a89('0x14'));var config=require('../../config/environment');var licenseUtil=require(_0x6a89('0x15'));var db=require(_0x6a89('0x16'))['db'];var integrations=require(_0x6a89('0x17'));var jayson=require(_0x6a89('0x18'));var client=jayson[_0x6a89('0x19')][_0x6a89('0x1a')]({'port':0x232a});function respondWithRpcPromise(_0x3677d4,_0x3a722e,_0x32cb49,_0x263d6f){return new BPromise(function(_0x500870,_0x2a8615){var _0x56d9ce=_0x263d6f||client;return _0x56d9ce['request'](_0x3677d4,_0x32cb49)[_0x6a89('0x1b')](function(_0x2ff0d1){logger['info'](_0x6a89('0x1c'),_0x3a722e,_0x6a89('0x1d'));logger['debug'](_0x6a89('0x1e'),_0x3a722e,_0x6a89('0x1d'),JSON[_0x6a89('0x1f')](_0x2ff0d1));if(_0x2ff0d1['error']){if(_0x2ff0d1[_0x6a89('0x20')][_0x6a89('0x21')]===0x1f4){logger[_0x6a89('0x20')](_0x6a89('0x1c'),_0x3a722e,_0x2ff0d1[_0x6a89('0x20')][_0x6a89('0x22')]);return _0x2a8615(_0x2ff0d1['error']['message']);}logger[_0x6a89('0x20')](_0x6a89('0x1c'),_0x3a722e,_0x2ff0d1[_0x6a89('0x20')][_0x6a89('0x22')]);return _0x500870(_0x2ff0d1[_0x6a89('0x20')][_0x6a89('0x22')]);}else{logger[_0x6a89('0x23')](_0x6a89('0x1c'),_0x3a722e,_0x6a89('0x1d'));_0x500870(_0x2ff0d1['result'][_0x6a89('0x22')]);}})[_0x6a89('0x24')](function(_0x28b3a5){logger[_0x6a89('0x20')]('SalesforceAccount,\x20%s,\x20%s',_0x3a722e,_0x28b3a5);_0x2a8615(_0x28b3a5);});});}function respondWithStatusCode(_0x22805e,_0x455c29){_0x455c29=_0x455c29||0xcc;return function(_0x32d59d){if(_0x32d59d){return _0x22805e['sendStatus'](_0x455c29);}return _0x22805e['status'](_0x455c29)[_0x6a89('0x25')]();};}function respondWithResult(_0x5b889a,_0x423309){_0x423309=_0x423309||0xc8;return function(_0x4de10e){if(_0x4de10e){return _0x5b889a['status'](_0x423309)['json'](_0x4de10e);}};}function respondWithFilteredResult(_0x4e0fac,_0x5d729d){return function(_0x50f6fc){if(_0x50f6fc){var _0x515904=typeof _0x5d729d['offset']===_0x6a89('0x26')&&typeof _0x5d729d['limit']==='undefined';var _0x3d644d=_0x50f6fc[_0x6a89('0x27')];var _0x57a577=_0x515904?0x0:_0x5d729d['offset'];var _0x51ca27=_0x515904?_0x50f6fc[_0x6a89('0x27')]:_0x5d729d[_0x6a89('0x28')]+_0x5d729d[_0x6a89('0x29')];var _0x3d9132;if(_0x51ca27>=_0x3d644d){_0x51ca27=_0x3d644d;_0x3d9132=0xc8;}else{_0x3d9132=0xce;}_0x4e0fac[_0x6a89('0x2a')](_0x3d9132);return _0x4e0fac[_0x6a89('0x2b')](_0x6a89('0x2c'),_0x57a577+'-'+_0x51ca27+'/'+_0x3d644d)[_0x6a89('0x2d')](_0x50f6fc);}return null;};}function patchUpdates(_0x1d71f4){return function(_0x471fab){try{jsonpatch[_0x6a89('0x2e')](_0x471fab,_0x1d71f4,!![]);}catch(_0x17c7c2){return BPromise[_0x6a89('0x2f')](_0x17c7c2);}return _0x471fab[_0x6a89('0x30')]();};}function saveUpdates(_0x2beeb2,_0x596903){return function(_0x2ff4fe){if(_0x2ff4fe){return _0x2ff4fe[_0x6a89('0x31')](_0x2beeb2)['then'](function(_0x1ce8fc){return _0x1ce8fc;});}return null;};}function removeEntity(_0x43fb5b,_0x2fad7c){return function(_0x3f1ed9){if(_0x3f1ed9){return _0x3f1ed9[_0x6a89('0x32')]()[_0x6a89('0x1b')](function(){_0x43fb5b[_0x6a89('0x2a')](0xcc)[_0x6a89('0x25')]();});}};}function handleEntityNotFound(_0x7729f8,_0x1022d2){return function(_0x5041b9){if(!_0x5041b9){_0x7729f8[_0x6a89('0x33')](0x194);}return _0x5041b9;};}function handleError(_0x158eb2,_0x428b1b){_0x428b1b=_0x428b1b||0x1f4;return function(_0x4bccb9){logger[_0x6a89('0x20')](_0x4bccb9[_0x6a89('0x34')]);if(_0x4bccb9[_0x6a89('0x35')]){delete _0x4bccb9[_0x6a89('0x35')];}_0x158eb2[_0x6a89('0x2a')](_0x428b1b)['send'](_0x4bccb9);};}exports[_0x6a89('0x36')]=function(_0x13cccd,_0x1e34eb){var _0x21a3cb={},_0x57849c={},_0x481fb1={'count':0x0,'rows':[]};var _0x5a09d9=_[_0x6a89('0x37')](db[_0x6a89('0x38')][_0x6a89('0x39')],function(_0x4f3c5d){return{'name':_0x4f3c5d[_0x6a89('0x3a')],'type':_0x4f3c5d[_0x6a89('0x3b')]['key']};});_0x57849c['model']=_[_0x6a89('0x37')](_0x5a09d9,_0x6a89('0x35'));_0x57849c[_0x6a89('0x3c')]=_[_0x6a89('0x3d')](_0x13cccd['query']);_0x57849c[_0x6a89('0x3e')]=_[_0x6a89('0x3f')](_0x57849c[_0x6a89('0x40')],_0x57849c[_0x6a89('0x3c')]);_0x21a3cb[_0x6a89('0x41')]=_[_0x6a89('0x3f')](_0x57849c[_0x6a89('0x40')],qs[_0x6a89('0x42')](_0x13cccd[_0x6a89('0x3c')][_0x6a89('0x42')]));_0x21a3cb[_0x6a89('0x41')]=_0x21a3cb[_0x6a89('0x41')][_0x6a89('0x43')]?_0x21a3cb[_0x6a89('0x41')]:_0x57849c[_0x6a89('0x40')];if(!_0x13cccd[_0x6a89('0x3c')][_0x6a89('0x44')]('nolimit')){_0x21a3cb[_0x6a89('0x29')]=qs[_0x6a89('0x29')](_0x13cccd[_0x6a89('0x3c')][_0x6a89('0x29')]);_0x21a3cb[_0x6a89('0x28')]=qs[_0x6a89('0x28')](_0x13cccd[_0x6a89('0x3c')][_0x6a89('0x28')]);}_0x21a3cb[_0x6a89('0x45')]=qs[_0x6a89('0x46')](_0x13cccd['query'][_0x6a89('0x46')]);_0x21a3cb['where']=qs['filters'](_[_0x6a89('0x47')](_0x13cccd[_0x6a89('0x3c')],_0x57849c[_0x6a89('0x3e')]),_0x5a09d9);if(_0x13cccd[_0x6a89('0x3c')][_0x6a89('0x48')]){_0x21a3cb[_0x6a89('0x49')]=_[_0x6a89('0x4a')](_0x21a3cb[_0x6a89('0x49')],{'$or':_[_0x6a89('0x37')](_0x5a09d9,function(_0x40a709){if(_0x40a709[_0x6a89('0x3b')]!=='VIRTUAL'){var _0x584ff6={};_0x584ff6[_0x40a709[_0x6a89('0x35')]]={'$like':'%'+_0x13cccd[_0x6a89('0x3c')][_0x6a89('0x48')]+'%'};return _0x584ff6;}})});}_0x21a3cb=_['merge']({},_0x21a3cb,_0x13cccd[_0x6a89('0x4b')]);var _0x49b938={'where':_0x21a3cb[_0x6a89('0x49')]};return db[_0x6a89('0x38')][_0x6a89('0x27')](_0x49b938)['then'](function(_0x1663f0){_0x481fb1[_0x6a89('0x27')]=_0x1663f0;if(_0x13cccd['query'][_0x6a89('0x4c')]){_0x21a3cb[_0x6a89('0x4d')]=[{'all':!![]}];}return db[_0x6a89('0x38')][_0x6a89('0x4e')](_0x21a3cb);})[_0x6a89('0x1b')](function(_0x241041){_0x481fb1['rows']=_0x241041;return _0x481fb1;})[_0x6a89('0x1b')](respondWithFilteredResult(_0x1e34eb,_0x21a3cb))[_0x6a89('0x24')](handleError(_0x1e34eb,null));};exports['show']=function(_0x460c28,_0x547fbe){var _0x405581={'raw':![],'where':{'id':_0x460c28[_0x6a89('0x4f')]['id']}},_0x215100={};_0x215100[_0x6a89('0x40')]=_[_0x6a89('0x3d')](db[_0x6a89('0x38')]['rawAttributes']);_0x215100[_0x6a89('0x3c')]=_[_0x6a89('0x3d')](_0x460c28['query']);_0x215100[_0x6a89('0x3e')]=_[_0x6a89('0x3f')](_0x215100[_0x6a89('0x40')],_0x215100['query']);_0x405581[_0x6a89('0x41')]=_[_0x6a89('0x3f')](_0x215100[_0x6a89('0x40')],qs[_0x6a89('0x42')](_0x460c28[_0x6a89('0x3c')]['fields']));_0x405581[_0x6a89('0x41')]=_0x405581[_0x6a89('0x41')][_0x6a89('0x43')]?_0x405581['attributes']:_0x215100[_0x6a89('0x40')];if(_0x460c28['query'][_0x6a89('0x4c')]){_0x405581[_0x6a89('0x4d')]=[{'all':!![]}];}_0x405581=_['merge']({},_0x405581,_0x460c28['options']);return db['SalesforceAccount']['find'](_0x405581)[_0x6a89('0x1b')](handleEntityNotFound(_0x547fbe,null))[_0x6a89('0x1b')](respondWithResult(_0x547fbe,null))[_0x6a89('0x24')](handleError(_0x547fbe,null));};exports[_0x6a89('0x50')]=function(_0x1bc126,_0x14b3b1){return db[_0x6a89('0x38')][_0x6a89('0x50')](_0x1bc126[_0x6a89('0x51')],{})[_0x6a89('0x1b')](respondWithResult(_0x14b3b1,0xc9))[_0x6a89('0x24')](handleError(_0x14b3b1,null));};exports['update']=function(_0x13d72e,_0xd61694){if(_0x13d72e[_0x6a89('0x51')]['id']){delete _0x13d72e[_0x6a89('0x51')]['id'];}return db[_0x6a89('0x38')][_0x6a89('0x52')]({'where':{'id':_0x13d72e[_0x6a89('0x4f')]['id']}})[_0x6a89('0x1b')](handleEntityNotFound(_0xd61694,null))['then'](saveUpdates(_0x13d72e['body'],null))[_0x6a89('0x1b')](respondWithResult(_0xd61694,null))[_0x6a89('0x24')](handleError(_0xd61694,null));};exports['destroy']=function(_0x291211,_0x576d70){return db['SalesforceAccount']['find']({'where':{'id':_0x291211[_0x6a89('0x4f')]['id']}})['then'](handleEntityNotFound(_0x576d70,null))[_0x6a89('0x1b')](removeEntity(_0x576d70,null))[_0x6a89('0x24')](handleError(_0x576d70,null));};exports['getConfigurations']=function(_0x42b837,_0x3b8b22,_0x5bf8c8){var _0x2f7046={};var _0x29f3be={};var _0x8e611d;var _0x3686e3;return db[_0x6a89('0x38')][_0x6a89('0x53')]({'where':{'id':_0x42b837[_0x6a89('0x4f')]['id']}})[_0x6a89('0x1b')](handleEntityNotFound(_0x3b8b22,null))['then'](function(_0x2c4827){if(_0x2c4827){_0x8e611d=_0x2c4827;_0x29f3be[_0x6a89('0x40')]=_['keys'](db[_0x6a89('0x54')][_0x6a89('0x39')]);_0x29f3be[_0x6a89('0x3c')]=_[_0x6a89('0x3d')](_0x42b837['query']);_0x29f3be[_0x6a89('0x3e')]=_['intersection'](_0x29f3be[_0x6a89('0x40')],_0x29f3be[_0x6a89('0x3c')]);_0x2f7046['attributes']=_[_0x6a89('0x3f')](_0x29f3be[_0x6a89('0x40')],qs[_0x6a89('0x42')](_0x42b837[_0x6a89('0x3c')][_0x6a89('0x42')]));_0x2f7046['attributes']=_0x2f7046[_0x6a89('0x41')][_0x6a89('0x43')]?_0x2f7046[_0x6a89('0x41')]:_0x29f3be['model'];_0x2f7046[_0x6a89('0x45')]=qs[_0x6a89('0x46')](_0x42b837[_0x6a89('0x3c')][_0x6a89('0x46')]);_0x2f7046[_0x6a89('0x49')]=qs['filters'](_[_0x6a89('0x47')](_0x42b837[_0x6a89('0x3c')],_0x29f3be[_0x6a89('0x3e')]));if(_0x42b837['query']['filter']){_0x2f7046['where']=_[_0x6a89('0x4a')](_0x2f7046[_0x6a89('0x49')],{'$or':_['map'](_0x2f7046['attributes'],function(_0x3bfe33){var _0x7b42df={};_0x7b42df[_0x3bfe33]={'$like':'%'+_0x42b837['query'][_0x6a89('0x48')]+'%'};return _0x7b42df;})});}_0x2f7046=_[_0x6a89('0x4a')]({},_0x2f7046,_0x42b837[_0x6a89('0x4b')]);return _0x8e611d[_0x6a89('0x55')](_0x2f7046);}})[_0x6a89('0x1b')](function(_0x1e0919){if(_0x1e0919){_0x3686e3=_0x1e0919[_0x6a89('0x43')];if(!_0x42b837[_0x6a89('0x3c')][_0x6a89('0x44')]('nolimit')){_0x2f7046[_0x6a89('0x29')]=qs['limit'](_0x42b837[_0x6a89('0x3c')][_0x6a89('0x29')]);_0x2f7046[_0x6a89('0x28')]=qs[_0x6a89('0x28')](_0x42b837[_0x6a89('0x3c')][_0x6a89('0x28')]);}return _0x8e611d[_0x6a89('0x55')](_0x2f7046);}})[_0x6a89('0x1b')](function(_0x12bc9d){if(_0x12bc9d){return _0x12bc9d?{'count':_0x3686e3,'rows':_0x12bc9d}:null;}})['then'](respondWithResult(_0x3b8b22,null))['catch'](handleError(_0x3b8b22,null));};exports[_0x6a89('0x56')]=function(_0xf7dd9b,_0x350f63,_0x20ec51){if(_0xf7dd9b[_0x6a89('0x51')]['id']){delete _0xf7dd9b[_0x6a89('0x51')]['id'];}return db[_0x6a89('0x38')][_0x6a89('0x53')]({'where':{'id':_0xf7dd9b[_0x6a89('0x4f')]['id']}})[_0x6a89('0x1b')](handleEntityNotFound(_0x350f63,null))[_0x6a89('0x1b')](function(_0x154c3a){if(_0x154c3a){_0xf7dd9b[_0x6a89('0x51')][_0x6a89('0x57')]=_0x154c3a['id'];_0xf7dd9b[_0x6a89('0x51')]['Subjects']=integrations['getSubjects'](_0xf7dd9b[_0x6a89('0x51')][_0x6a89('0x58')],_0xf7dd9b['body']['type']);_0xf7dd9b[_0x6a89('0x51')][_0x6a89('0x59')]=integrations[_0x6a89('0x5a')](_0xf7dd9b['body'][_0x6a89('0x58')],_0xf7dd9b['body'][_0x6a89('0x3b')]);return db['SalesforceConfiguration']['create'](_0xf7dd9b[_0x6a89('0x51')],{'include':[{'model':db[_0x6a89('0x5b')],'as':_0x6a89('0x5c')},{'model':db[_0x6a89('0x5b')],'as':_0x6a89('0x59')}]});}return null;})[_0x6a89('0x1b')](respondWithResult(_0x350f63,null))[_0x6a89('0x24')](handleError(_0x350f63,null));};exports[_0x6a89('0x5d')]=function(_0x257dfb,_0x2f60cf,_0x22fed2){var _0x4711c6;var _0x5a388a='';var _0x5b95b4=_0x6a89('0x5e');return db['SalesforceAccount'][_0x6a89('0x53')]({'where':{'id':_0x257dfb['params']['id']},'attributes':['id',_0x6a89('0x5f'),_0x6a89('0x60'),_0x6a89('0x61'),_0x6a89('0x62'),_0x6a89('0x63'),'securityToken']})[_0x6a89('0x1b')](handleEntityNotFound(_0x2f60cf,null))[_0x6a89('0x1b')](function(_0x23f8e1){if(_0x23f8e1){_0x5a388a=_0x23f8e1[_0x6a89('0x5f')];var _0x1e21f0=_0x5a388a[_0x6a89('0x64')](-0x1);if(_0x1e21f0==='/'){_0x5a388a=_0x5a388a[_0x6a89('0x65')](0x0,_0x5a388a['lastIndexOf'](_0x1e21f0));}_0x4711c6=new jsforce[(_0x6a89('0x66'))]({'oauth2':{'loginUrl':_0x5a388a,'clientId':_0x23f8e1[_0x6a89('0x60')],'clientSecret':_0x23f8e1[_0x6a89('0x61')]}});return _0x4711c6[_0x6a89('0x67')](_0x23f8e1[_0x6a89('0x62')],_0x23f8e1[_0x6a89('0x63')][_0x6a89('0x68')](_0x23f8e1[_0x6a89('0x69')]));}})[_0x6a89('0x1b')](function(_0x18d430){if(_0x18d430){if(!_['isNil'](_0x257dfb[_0x6a89('0x3c')][_0x6a89('0x6a')])){_0x5b95b4=_0x257dfb[_0x6a89('0x3c')][_0x6a89('0x6a')];}return _0x4711c6['sobject'](_0x5b95b4)['describe']();}})['then'](function(_0x59de41){var _0x1216c2=[_0x6a89('0x6b'),_0x6a89('0x6c'),_0x6a89('0x6d'),'IsRecurrence',_0x6a89('0x6e'),'Description'];var _0x436070=[_0x6a89('0x6f'),_0x6a89('0x70'),_0x6a89('0x71'),_0x6a89('0x72'),'email',_0x6a89('0x73'),_0x6a89('0x74')];if(_0x59de41){_[_0x6a89('0x75')](_0x59de41[_0x6a89('0x42')],function(_0x493f88){return _0x1216c2['includes'](_0x493f88[_0x6a89('0x35')])||!_0x436070['includes'](_0x493f88[_0x6a89('0x3b')]);});return{'count':_0x59de41['fields'][_0x6a89('0x43')],'rows':_['map'](_0x59de41[_0x6a89('0x42')],function(_0x55fa52){return{'id':_0x55fa52[_0x6a89('0x35')],'name':_0x55fa52['label'],'custom':_0x55fa52[_0x6a89('0x76')],'options':_0x55fa52[_0x6a89('0x77')]['length']>0x0?_[_0x6a89('0x37')](_0x55fa52[_0x6a89('0x77')],function(_0x4f4069){return{'name':_0x4f4069[_0x6a89('0x78')],'value':_0x4f4069['value']};}):_0x55fa52['type']==_0x6a89('0x72')?[{'name':_0x6a89('0x79'),'value':_0x6a89('0x7a')},{'name':'False','value':_0x6a89('0x7b')}]:[]};})};}})[_0x6a89('0x1b')](respondWithResult(_0x2f60cf,null))[_0x6a89('0x24')](function(_0x5528b5){var _0xedca7f=_0x257dfb['query'][_0x6a89('0x7c')]?0x1f4:_0x5528b5[_0x6a89('0x7d')]||0x1f4;logger['error'](_0x6a89('0x7e'),_0x6a89('0x5d'),_0xedca7f,JSON[_0x6a89('0x1f')](_0x5528b5));delete _0x5528b5[_0x6a89('0x35')];if(_0xedca7f===0x191){_0xedca7f=0x190;}_0x2f60cf[_0x6a89('0x2a')](_0xedca7f)[_0x6a89('0x7f')](_0x257dfb[_0x6a89('0x3c')][_0x6a89('0x7c')]?{'message':_0x6a89('0x80'),'statusCode':_0x5528b5[_0x6a89('0x7d')]}:_0x5528b5);});};
\ No newline at end of file