Built motion from commit (unavailable).|2.5.28
[motion2.git] / server / api / intDeskAccount / intDeskAccount.controller.js
index e74d85b..f21bc86 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xfaf8=['../../mysqldb','../../components/integrations/configuration','jayson/promise','client','http','then','info','DeskAccount,\x20%s,\x20%s','request\x20sent','debug','stringify','error','message','result','catch','sendStatus','status','end','json','count','offset','limit','apply','reject','save','update','destroy','stack','name','send','index','DeskAccount','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','fields','attributes','length','nolimit','sort','where','pick','filter','merge','map','VIRTUAL','includeAll','include','rows','show','params','find','create','body','getConfigurations','findOne','DeskConfiguration','order','options','addConfiguration','Subjects','getSubjects','channel','getDescriptions','DeskField','Descriptions','getFields','priority','authType','username','password','consumerKey','consumerSecret','token','tokenSecret','remoteUri','slice','substring','lastIndexOf','format','%s/custom_fields','application/json','basic','headers','Authorization','Basic\x20%s','%s:%s','base64','concat','_embedded','active','test','statusCode','Wrong\x20credentials','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','to-csv','lodash','squel','crypto','jsforce','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment'];(function(_0x3e3308,_0x22629a){var _0x31a96f=function(_0x5ad856){while(--_0x5ad856){_0x3e3308['push'](_0x3e3308['shift']());}};_0x31a96f(++_0x22629a);}(_0xfaf8,0x64));var _0x8faf=function(_0x3c8e64,_0x5aad5d){_0x3c8e64=_0x3c8e64-0x0;var _0x3f7c73=_0xfaf8[_0x3c8e64];return _0x3f7c73;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x8faf('0x0'));var zipdir=require(_0x8faf('0x1'));var jsonpatch=require(_0x8faf('0x2'));var rp=require(_0x8faf('0x3'));var moment=require(_0x8faf('0x4'));var BPromise=require(_0x8faf('0x5'));var Mustache=require(_0x8faf('0x6'));var util=require(_0x8faf('0x7'));var path=require(_0x8faf('0x8'));var sox=require('sox');var csv=require(_0x8faf('0x9'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x8faf('0xa'));var squel=require(_0x8faf('0xb'));var crypto=require(_0x8faf('0xc'));var jsforce=require(_0x8faf('0xd'));var deskjs=require('desk.js');var toCsv=require(_0x8faf('0x9'));var querystring=require(_0x8faf('0xe'));var Papa=require(_0x8faf('0xf'));var Redis=require('ioredis');var authService=require(_0x8faf('0x10'));var qs=require(_0x8faf('0x11'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x8faf('0x12'));var logger=require(_0x8faf('0x13'))(_0x8faf('0x14'));var utils=require(_0x8faf('0x15'));var config=require(_0x8faf('0x16'));var licenseUtil=require('../../config/license/util');var db=require(_0x8faf('0x17'))['db'];var integrations=require(_0x8faf('0x18'));var jayson=require(_0x8faf('0x19'));var client=jayson[_0x8faf('0x1a')][_0x8faf('0x1b')]({'port':0x232a});function respondWithRpcPromise(_0x1638fb,_0x55ab43,_0x177a95,_0x22fdb6){return new BPromise(function(_0x37dbd6,_0x5e0f48){var _0x15a1f7=_0x22fdb6||client;return _0x15a1f7['request'](_0x1638fb,_0x177a95)[_0x8faf('0x1c')](function(_0x1a6855){logger[_0x8faf('0x1d')](_0x8faf('0x1e'),_0x55ab43,_0x8faf('0x1f'));logger[_0x8faf('0x20')]('DeskAccount,\x20%s,\x20%s,\x20%s',_0x55ab43,_0x8faf('0x1f'),JSON[_0x8faf('0x21')](_0x1a6855));if(_0x1a6855[_0x8faf('0x22')]){if(_0x1a6855[_0x8faf('0x22')]['code']===0x1f4){logger['error'](_0x8faf('0x1e'),_0x55ab43,_0x1a6855[_0x8faf('0x22')][_0x8faf('0x23')]);return _0x5e0f48(_0x1a6855[_0x8faf('0x22')]['message']);}logger['error']('DeskAccount,\x20%s,\x20%s',_0x55ab43,_0x1a6855[_0x8faf('0x22')][_0x8faf('0x23')]);return _0x37dbd6(_0x1a6855['error'][_0x8faf('0x23')]);}else{logger[_0x8faf('0x1d')]('DeskAccount,\x20%s,\x20%s',_0x55ab43,_0x8faf('0x1f'));_0x37dbd6(_0x1a6855[_0x8faf('0x24')][_0x8faf('0x23')]);}})[_0x8faf('0x25')](function(_0x271f0c){logger[_0x8faf('0x22')](_0x8faf('0x1e'),_0x55ab43,_0x271f0c);_0x5e0f48(_0x271f0c);});});}function respondWithStatusCode(_0x2ad7fb,_0x3f3151){_0x3f3151=_0x3f3151||0xcc;return function(_0x48f42f){if(_0x48f42f){return _0x2ad7fb[_0x8faf('0x26')](_0x3f3151);}return _0x2ad7fb[_0x8faf('0x27')](_0x3f3151)[_0x8faf('0x28')]();};}function respondWithResult(_0x497fd6,_0x43578e){_0x43578e=_0x43578e||0xc8;return function(_0x2e4f5c){if(_0x2e4f5c){return _0x497fd6[_0x8faf('0x27')](_0x43578e)[_0x8faf('0x29')](_0x2e4f5c);}};}function respondWithFilteredResult(_0x57ff5f,_0x46c3c7){return function(_0x1511ff){if(_0x1511ff){var _0x2b37e5=_0x1511ff[_0x8faf('0x2a')],_0x388458=_0x46c3c7['offset'],_0x11d330=_0x46c3c7[_0x8faf('0x2b')]+_0x46c3c7[_0x8faf('0x2c')],_0x52871b;if(_0x11d330>=_0x2b37e5){_0x11d330=_0x2b37e5;_0x52871b=0xc8;}else{_0x52871b=0xce;}_0x57ff5f[_0x8faf('0x27')](_0x52871b);return _0x57ff5f['set']('Content-Range',_0x388458+'-'+_0x11d330+'/'+_0x2b37e5)[_0x8faf('0x29')](_0x1511ff);}return null;};}function patchUpdates(_0x1b9f6c){return function(_0x2c66b6){try{jsonpatch[_0x8faf('0x2d')](_0x2c66b6,_0x1b9f6c,!![]);}catch(_0x2c4aa7){return BPromise[_0x8faf('0x2e')](_0x2c4aa7);}return _0x2c66b6[_0x8faf('0x2f')]();};}function saveUpdates(_0x361dda,_0x495e0a){return function(_0x2e41c0){if(_0x2e41c0){return _0x2e41c0[_0x8faf('0x30')](_0x361dda)[_0x8faf('0x1c')](function(_0xbf666a){return _0xbf666a;});}return null;};}function removeEntity(_0x5d064d,_0x453228){return function(_0x3dbf06){if(_0x3dbf06){return _0x3dbf06[_0x8faf('0x31')]()[_0x8faf('0x1c')](function(){_0x5d064d['status'](0xcc)[_0x8faf('0x28')]();});}};}function handleEntityNotFound(_0x4bc818,_0x960566){return function(_0x3b9967){if(!_0x3b9967){_0x4bc818[_0x8faf('0x26')](0x194);}return _0x3b9967;};}function handleError(_0x470a5b,_0x5aa08a){_0x5aa08a=_0x5aa08a||0x1f4;return function(_0x2d4317){logger[_0x8faf('0x22')](_0x2d4317[_0x8faf('0x32')]);if(_0x2d4317[_0x8faf('0x33')]){delete _0x2d4317['name'];}_0x470a5b['status'](_0x5aa08a)[_0x8faf('0x34')](_0x2d4317);};}exports[_0x8faf('0x35')]=function(_0x58ed40,_0x19bac3){var _0x5af868={},_0x5006a6={},_0x2dc01e={'count':0x0,'rows':[]};var _0x92adc0=_['map'](db[_0x8faf('0x36')][_0x8faf('0x37')],function(_0x20d648){return{'name':_0x20d648[_0x8faf('0x38')],'type':_0x20d648[_0x8faf('0x39')][_0x8faf('0x3a')]};});_0x5006a6[_0x8faf('0x3b')]=_['map'](_0x92adc0,_0x8faf('0x33'));_0x5006a6[_0x8faf('0x3c')]=_[_0x8faf('0x3d')](_0x58ed40[_0x8faf('0x3c')]);_0x5006a6[_0x8faf('0x3e')]=_[_0x8faf('0x3f')](_0x5006a6[_0x8faf('0x3b')],_0x5006a6[_0x8faf('0x3c')]);_0x5af868['attributes']=_[_0x8faf('0x3f')](_0x5006a6[_0x8faf('0x3b')],qs[_0x8faf('0x40')](_0x58ed40[_0x8faf('0x3c')][_0x8faf('0x40')]));_0x5af868[_0x8faf('0x41')]=_0x5af868[_0x8faf('0x41')][_0x8faf('0x42')]?_0x5af868[_0x8faf('0x41')]:_0x5006a6[_0x8faf('0x3b')];if(!_0x58ed40['query']['hasOwnProperty'](_0x8faf('0x43'))){_0x5af868[_0x8faf('0x2c')]=qs[_0x8faf('0x2c')](_0x58ed40[_0x8faf('0x3c')][_0x8faf('0x2c')]);_0x5af868[_0x8faf('0x2b')]=qs[_0x8faf('0x2b')](_0x58ed40['query'][_0x8faf('0x2b')]);}_0x5af868['order']=qs['sort'](_0x58ed40[_0x8faf('0x3c')][_0x8faf('0x44')]);_0x5af868[_0x8faf('0x45')]=qs[_0x8faf('0x3e')](_[_0x8faf('0x46')](_0x58ed40['query'],_0x5006a6[_0x8faf('0x3e')]),_0x92adc0);if(_0x58ed40['query'][_0x8faf('0x47')]){_0x5af868[_0x8faf('0x45')]=_[_0x8faf('0x48')](_0x5af868[_0x8faf('0x45')],{'$or':_[_0x8faf('0x49')](_0x92adc0,function(_0x25da8a){if(_0x25da8a[_0x8faf('0x39')]!==_0x8faf('0x4a')){var _0x3eaa42={};_0x3eaa42[_0x25da8a[_0x8faf('0x33')]]={'$like':'%'+_0x58ed40[_0x8faf('0x3c')][_0x8faf('0x47')]+'%'};return _0x3eaa42;}})});}_0x5af868=_[_0x8faf('0x48')]({},_0x5af868,_0x58ed40['options']);var _0x314e93={'where':_0x5af868['where']};return db['DeskAccount'][_0x8faf('0x2a')](_0x314e93)[_0x8faf('0x1c')](function(_0x29a16d){_0x2dc01e[_0x8faf('0x2a')]=_0x29a16d;if(_0x58ed40['query'][_0x8faf('0x4b')]){_0x5af868[_0x8faf('0x4c')]=[{'all':!![]}];}return db['DeskAccount']['findAll'](_0x5af868);})['then'](function(_0x188c1b){_0x2dc01e[_0x8faf('0x4d')]=_0x188c1b;return _0x2dc01e;})['then'](respondWithFilteredResult(_0x19bac3,_0x5af868))[_0x8faf('0x25')](handleError(_0x19bac3,null));};exports[_0x8faf('0x4e')]=function(_0x101dd2,_0x53751a){var _0x545330={'raw':![],'where':{'id':_0x101dd2[_0x8faf('0x4f')]['id']}},_0x41bad7={};_0x41bad7['model']=_[_0x8faf('0x3d')](db[_0x8faf('0x36')][_0x8faf('0x37')]);_0x41bad7[_0x8faf('0x3c')]=_[_0x8faf('0x3d')](_0x101dd2[_0x8faf('0x3c')]);_0x41bad7[_0x8faf('0x3e')]=_[_0x8faf('0x3f')](_0x41bad7[_0x8faf('0x3b')],_0x41bad7[_0x8faf('0x3c')]);_0x545330[_0x8faf('0x41')]=_['intersection'](_0x41bad7[_0x8faf('0x3b')],qs[_0x8faf('0x40')](_0x101dd2[_0x8faf('0x3c')]['fields']));_0x545330['attributes']=_0x545330['attributes']['length']?_0x545330[_0x8faf('0x41')]:_0x41bad7[_0x8faf('0x3b')];if(_0x101dd2['query'][_0x8faf('0x4b')]){_0x545330[_0x8faf('0x4c')]=[{'all':!![]}];}_0x545330=_['merge']({},_0x545330,_0x101dd2['options']);return db[_0x8faf('0x36')][_0x8faf('0x50')](_0x545330)[_0x8faf('0x1c')](handleEntityNotFound(_0x53751a,null))['then'](respondWithResult(_0x53751a,null))[_0x8faf('0x25')](handleError(_0x53751a,null));};exports[_0x8faf('0x51')]=function(_0x6c1d35,_0x578955){return db[_0x8faf('0x36')][_0x8faf('0x51')](_0x6c1d35[_0x8faf('0x52')],{})['then'](respondWithResult(_0x578955,0xc9))['catch'](handleError(_0x578955,null));};exports[_0x8faf('0x30')]=function(_0x1c015c,_0x1869ed){if(_0x1c015c[_0x8faf('0x52')]['id']){delete _0x1c015c[_0x8faf('0x52')]['id'];}return db[_0x8faf('0x36')][_0x8faf('0x50')]({'where':{'id':_0x1c015c[_0x8faf('0x4f')]['id']}})[_0x8faf('0x1c')](handleEntityNotFound(_0x1869ed,null))['then'](saveUpdates(_0x1c015c[_0x8faf('0x52')],null))['then'](respondWithResult(_0x1869ed,null))[_0x8faf('0x25')](handleError(_0x1869ed,null));};exports[_0x8faf('0x31')]=function(_0x5dabd5,_0x5e530c){return db[_0x8faf('0x36')][_0x8faf('0x50')]({'where':{'id':_0x5dabd5[_0x8faf('0x4f')]['id']}})[_0x8faf('0x1c')](handleEntityNotFound(_0x5e530c,null))[_0x8faf('0x1c')](removeEntity(_0x5e530c,null))['catch'](handleError(_0x5e530c,null));};exports[_0x8faf('0x53')]=function(_0x17f221,_0x176293,_0xc25fbb){var _0x270a5c={};var _0x325b52={};var _0x20c378;var _0x4b6000;return db[_0x8faf('0x36')][_0x8faf('0x54')]({'where':{'id':_0x17f221[_0x8faf('0x4f')]['id']}})[_0x8faf('0x1c')](handleEntityNotFound(_0x176293,null))['then'](function(_0x506086){if(_0x506086){_0x20c378=_0x506086;_0x325b52[_0x8faf('0x3b')]=_[_0x8faf('0x3d')](db[_0x8faf('0x55')]['rawAttributes']);_0x325b52[_0x8faf('0x3c')]=_[_0x8faf('0x3d')](_0x17f221[_0x8faf('0x3c')]);_0x325b52[_0x8faf('0x3e')]=_[_0x8faf('0x3f')](_0x325b52['model'],_0x325b52[_0x8faf('0x3c')]);_0x270a5c[_0x8faf('0x41')]=_[_0x8faf('0x3f')](_0x325b52['model'],qs[_0x8faf('0x40')](_0x17f221[_0x8faf('0x3c')][_0x8faf('0x40')]));_0x270a5c[_0x8faf('0x41')]=_0x270a5c[_0x8faf('0x41')][_0x8faf('0x42')]?_0x270a5c[_0x8faf('0x41')]:_0x325b52['model'];_0x270a5c[_0x8faf('0x56')]=qs['sort'](_0x17f221[_0x8faf('0x3c')][_0x8faf('0x44')]);_0x270a5c[_0x8faf('0x45')]=qs[_0x8faf('0x3e')](_['pick'](_0x17f221[_0x8faf('0x3c')],_0x325b52['filters']));if(_0x17f221[_0x8faf('0x3c')][_0x8faf('0x47')]){_0x270a5c[_0x8faf('0x45')]=_[_0x8faf('0x48')](_0x270a5c[_0x8faf('0x45')],{'$or':_[_0x8faf('0x49')](_0x270a5c['attributes'],function(_0x3d1fc8){var _0x2f4710={};_0x2f4710[_0x3d1fc8]={'$like':'%'+_0x17f221['query'][_0x8faf('0x47')]+'%'};return _0x2f4710;})});}_0x270a5c=_[_0x8faf('0x48')]({},_0x270a5c,_0x17f221[_0x8faf('0x57')]);return _0x20c378[_0x8faf('0x53')](_0x270a5c);}})[_0x8faf('0x1c')](function(_0x49d346){if(_0x49d346){_0x4b6000=_0x49d346[_0x8faf('0x42')];if(!_0x17f221['query']['hasOwnProperty']('nolimit')){_0x270a5c['limit']=qs['limit'](_0x17f221[_0x8faf('0x3c')]['limit']);_0x270a5c[_0x8faf('0x2b')]=qs[_0x8faf('0x2b')](_0x17f221[_0x8faf('0x3c')]['offset']);}return _0x20c378['getConfigurations'](_0x270a5c);}})['then'](function(_0x5965f2){if(_0x5965f2){return _0x5965f2?{'count':_0x4b6000,'rows':_0x5965f2}:null;}})[_0x8faf('0x1c')](respondWithResult(_0x176293,null))[_0x8faf('0x25')](handleError(_0x176293,null));};exports[_0x8faf('0x58')]=function(_0x27d94b,_0x3e8c64,_0x1e294c){if(_0x27d94b['body']['id']){delete _0x27d94b[_0x8faf('0x52')]['id'];}return db[_0x8faf('0x36')]['findOne']({'where':{'id':_0x27d94b[_0x8faf('0x4f')]['id']}})['then'](handleEntityNotFound(_0x3e8c64,null))[_0x8faf('0x1c')](function(_0x2c6b80){if(_0x2c6b80){_0x27d94b[_0x8faf('0x52')]['AccountId']=_0x2c6b80['id'];_0x27d94b[_0x8faf('0x52')][_0x8faf('0x59')]=integrations[_0x8faf('0x5a')](_0x27d94b[_0x8faf('0x52')][_0x8faf('0x5b')],_0x27d94b[_0x8faf('0x52')][_0x8faf('0x39')]);_0x27d94b[_0x8faf('0x52')]['Descriptions']=integrations[_0x8faf('0x5c')](_0x27d94b[_0x8faf('0x52')]['channel'],_0x27d94b[_0x8faf('0x52')][_0x8faf('0x39')]);return db[_0x8faf('0x55')][_0x8faf('0x51')](_0x27d94b[_0x8faf('0x52')],{'include':[{'model':db[_0x8faf('0x5d')],'as':_0x8faf('0x59')},{'model':db[_0x8faf('0x5d')],'as':_0x8faf('0x5e')}]});}return null;})['then'](respondWithResult(_0x3e8c64,null))['catch'](handleError(_0x3e8c64,null));};exports[_0x8faf('0x5f')]=function(_0xdfbf57,_0x1e200d,_0xc5e114){var _0x6bf177=[{'name':_0x8faf('0x60'),'label':_0x8faf('0x60'),'custom':![],'options':[{'name':0x1,'value':0x1},{'name':0x2,'value':0x2},{'name':0x3,'value':0x3},{'name':0x4,'value':0x4},{'name':0x5,'value':0x5},{'name':0x6,'value':0x6},{'name':0x7,'value':0x7},{'name':0x8,'value':0x8},{'name':0x9,'value':0x9},{'name':0xa,'value':0xa}]}];var _0x4067cf='';return db[_0x8faf('0x36')][_0x8faf('0x54')]({'where':{'id':_0xdfbf57['params']['id']},'attributes':['id','remoteUri',_0x8faf('0x61'),_0x8faf('0x62'),_0x8faf('0x63'),_0x8faf('0x64'),_0x8faf('0x65'),_0x8faf('0x66'),_0x8faf('0x67')]})['then'](handleEntityNotFound(_0x1e200d,null))[_0x8faf('0x1c')](function(_0x4efc0c){if(_0x4efc0c){_0x4067cf=_0x4efc0c[_0x8faf('0x68')];var _0x3b91ba=_0x4067cf[_0x8faf('0x69')](-0x1);if(_0x3b91ba==='/'){_0x4067cf=_0x4067cf[_0x8faf('0x6a')](0x0,_0x4067cf[_0x8faf('0x6b')](_0x3b91ba));}var _0x53429f={'method':'GET','uri':util[_0x8faf('0x6c')](_0x8faf('0x6d'),_0x4067cf),'headers':{'Content-Type':'application/json','Accept':_0x8faf('0x6e')},'json':!![]};if(_0x4efc0c['authType']===_0x8faf('0x6f')){_0x53429f[_0x8faf('0x70')][_0x8faf('0x71')]=util[_0x8faf('0x6c')](_0x8faf('0x72'),new Buffer(util[_0x8faf('0x6c')](_0x8faf('0x73'),_0x4efc0c[_0x8faf('0x62')],_0x4efc0c['password']))['toString'](_0x8faf('0x74')));}return rp(_0x53429f)[_0x8faf('0x1c')](function(_0x2aa68f){return _0x6bf177[_0x8faf('0x75')](_['map'](_0x2aa68f[_0x8faf('0x76')]['entries'],function(_0x5ec2e0){return{'id':_0x5ec2e0[_0x8faf('0x33')],'name':_0x5ec2e0['name'],'type':_0x5ec2e0['type'],'active':_0x5ec2e0[_0x8faf('0x77')],'label':_0x5ec2e0['label'],'custom':!![]};}));});}})[_0x8faf('0x1c')](function(_0x2c51fd){return{'count':_0x2c51fd[_0x8faf('0x42')],'rows':_0x2c51fd};})['then'](respondWithResult(_0x1e200d,null))['catch'](function(_0x2907b3){var _0x5a4dfa=_0xdfbf57[_0x8faf('0x3c')][_0x8faf('0x78')]?0x1f4:_0x2907b3[_0x8faf('0x79')]||0x1f4;logger['error']('getFields,\x20%s,\x20%s,\x20%s','getFields',_0x5a4dfa,JSON[_0x8faf('0x21')](_0x2907b3));delete _0x2907b3[_0x8faf('0x33')];if(_0x5a4dfa===0x191){_0x5a4dfa=0x190;}_0x1e200d[_0x8faf('0x27')](_0x5a4dfa)[_0x8faf('0x34')](_0xdfbf57[_0x8faf('0x3c')][_0x8faf('0x78')]?{'message':_0x8faf('0x7a'),'statusCode':_0x2907b3[_0x8faf('0x79')]}:_0x2907b3);});};
\ No newline at end of file
+var _0x598c=['channel','Descriptions','getDescriptions','DeskConfiguration','DeskField','getFields','priority','remoteUri','authType','username','consumerKey','consumerSecret','token','tokenSecret','slice','substring','lastIndexOf','GET','format','headers','%s:%s','toString','base64','concat','_embedded','entries','active','test','stringify','Wrong\x20credentials','statusCode','eml-format','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','jsforce','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','../../components/integrations/configuration','client','info','DeskAccount,\x20%s,\x20%s','request\x20sent','debug','DeskAccount,\x20%s,\x20%s,\x20%s','error','code','message','catch','status','end','json','count','offset','limit','set','Content-Range','apply','reject','save','update','then','destroy','sendStatus','stack','name','send','DeskAccount','rawAttributes','fieldName','type','key','query','keys','filters','intersection','model','attributes','fields','hasOwnProperty','nolimit','order','sort','pick','merge','map','VIRTUAL','filter','where','include','findAll','show','params','length','includeAll','options','find','create','body','getConfigurations','findOne','addConfiguration','AccountId','Subjects','getSubjects'];(function(_0xfdfc13,_0x21d9d5){var _0x1f3b70=function(_0x1961f1){while(--_0x1961f1){_0xfdfc13['push'](_0xfdfc13['shift']());}};_0x1f3b70(++_0x21d9d5);}(_0x598c,0x9a));var _0xc598=function(_0x2e0ae4,_0x2aa3ad){_0x2e0ae4=_0x2e0ae4-0x0;var _0x31001a=_0x598c[_0x2e0ae4];return _0x31001a;};'use strict';var emlformat=require(_0xc598('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xc598('0x1'));var jsonpatch=require(_0xc598('0x2'));var rp=require(_0xc598('0x3'));var moment=require(_0xc598('0x4'));var BPromise=require(_0xc598('0x5'));var Mustache=require(_0xc598('0x6'));var util=require(_0xc598('0x7'));var path=require(_0xc598('0x8'));var sox=require(_0xc598('0x9'));var csv=require(_0xc598('0xa'));var ejs=require(_0xc598('0xb'));var fs=require('fs');var fs_extra=require(_0xc598('0xc'));var _=require(_0xc598('0xd'));var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0xc598('0xe'));var deskjs=require('desk.js');var toCsv=require(_0xc598('0xa'));var querystring=require(_0xc598('0xf'));var Papa=require(_0xc598('0x10'));var Redis=require(_0xc598('0x11'));var authService=require('../../components/auth/service');var qs=require(_0xc598('0x12'));var as=require(_0xc598('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xc598('0x14'))(_0xc598('0x15'));var utils=require('../../config/utils');var config=require(_0xc598('0x16'));var licenseUtil=require(_0xc598('0x17'));var db=require(_0xc598('0x18'))['db'];var integrations=require(_0xc598('0x19'));var jayson=require('jayson/promise');var client=jayson[_0xc598('0x1a')]['http']({'port':0x232a});function respondWithRpcPromise(_0x47ce48,_0x185f75,_0x5d1caa,_0x4a0a26){return new BPromise(function(_0x34790d,_0x50b8ed){var _0x3cc8b0=_0x4a0a26||client;return _0x3cc8b0['request'](_0x47ce48,_0x5d1caa)['then'](function(_0x454c3c){logger[_0xc598('0x1b')](_0xc598('0x1c'),_0x185f75,_0xc598('0x1d'));logger[_0xc598('0x1e')](_0xc598('0x1f'),_0x185f75,_0xc598('0x1d'),JSON['stringify'](_0x454c3c));if(_0x454c3c[_0xc598('0x20')]){if(_0x454c3c['error'][_0xc598('0x21')]===0x1f4){logger[_0xc598('0x20')](_0xc598('0x1c'),_0x185f75,_0x454c3c[_0xc598('0x20')][_0xc598('0x22')]);return _0x50b8ed(_0x454c3c[_0xc598('0x20')][_0xc598('0x22')]);}logger[_0xc598('0x20')](_0xc598('0x1c'),_0x185f75,_0x454c3c[_0xc598('0x20')]['message']);return _0x34790d(_0x454c3c['error'][_0xc598('0x22')]);}else{logger['info'](_0xc598('0x1c'),_0x185f75,_0xc598('0x1d'));_0x34790d(_0x454c3c['result'][_0xc598('0x22')]);}})[_0xc598('0x23')](function(_0x5a47c9){logger[_0xc598('0x20')](_0xc598('0x1c'),_0x185f75,_0x5a47c9);_0x50b8ed(_0x5a47c9);});});}function respondWithStatusCode(_0x144505,_0x39bc01){_0x39bc01=_0x39bc01||0xcc;return function(_0x763a96){if(_0x763a96){return _0x144505['sendStatus'](_0x39bc01);}return _0x144505[_0xc598('0x24')](_0x39bc01)[_0xc598('0x25')]();};}function respondWithResult(_0x38401e,_0x5589b6){_0x5589b6=_0x5589b6||0xc8;return function(_0x43af2e){if(_0x43af2e){return _0x38401e[_0xc598('0x24')](_0x5589b6)[_0xc598('0x26')](_0x43af2e);}};}function respondWithFilteredResult(_0x4cb908,_0x50d31c){return function(_0x336c23){if(_0x336c23){var _0x5c2a7e=_0x336c23[_0xc598('0x27')],_0x242685=_0x50d31c[_0xc598('0x28')],_0x3c015d=_0x50d31c[_0xc598('0x28')]+_0x50d31c[_0xc598('0x29')],_0x12b45a;if(_0x3c015d>=_0x5c2a7e){_0x3c015d=_0x5c2a7e;_0x12b45a=0xc8;}else{_0x12b45a=0xce;}_0x4cb908[_0xc598('0x24')](_0x12b45a);return _0x4cb908[_0xc598('0x2a')](_0xc598('0x2b'),_0x242685+'-'+_0x3c015d+'/'+_0x5c2a7e)[_0xc598('0x26')](_0x336c23);}return null;};}function patchUpdates(_0x5a713b){return function(_0x3a8309){try{jsonpatch[_0xc598('0x2c')](_0x3a8309,_0x5a713b,!![]);}catch(_0x1fc073){return BPromise[_0xc598('0x2d')](_0x1fc073);}return _0x3a8309[_0xc598('0x2e')]();};}function saveUpdates(_0x20fa5b,_0x502b72){return function(_0x365319){if(_0x365319){return _0x365319[_0xc598('0x2f')](_0x20fa5b)[_0xc598('0x30')](function(_0x1aec1c){return _0x1aec1c;});}return null;};}function removeEntity(_0x4e424b,_0x3dd109){return function(_0x13b143){if(_0x13b143){return _0x13b143[_0xc598('0x31')]()[_0xc598('0x30')](function(){_0x4e424b[_0xc598('0x24')](0xcc)['end']();});}};}function handleEntityNotFound(_0x57e57c,_0x4a1db1){return function(_0x1f0785){if(!_0x1f0785){_0x57e57c[_0xc598('0x32')](0x194);}return _0x1f0785;};}function handleError(_0x108e5a,_0x58595f){_0x58595f=_0x58595f||0x1f4;return function(_0x406428){logger['error'](_0x406428[_0xc598('0x33')]);if(_0x406428['name']){delete _0x406428[_0xc598('0x34')];}_0x108e5a[_0xc598('0x24')](_0x58595f)[_0xc598('0x35')](_0x406428);};}exports['index']=function(_0x1e0d26,_0x33abd0){var _0x393fc6={},_0x3484c6={},_0x3ff2a7={'count':0x0,'rows':[]};var _0x586bab=_['map'](db[_0xc598('0x36')][_0xc598('0x37')],function(_0xe243b2){return{'name':_0xe243b2[_0xc598('0x38')],'type':_0xe243b2[_0xc598('0x39')][_0xc598('0x3a')]};});_0x3484c6['model']=_['map'](_0x586bab,_0xc598('0x34'));_0x3484c6[_0xc598('0x3b')]=_[_0xc598('0x3c')](_0x1e0d26['query']);_0x3484c6[_0xc598('0x3d')]=_[_0xc598('0x3e')](_0x3484c6[_0xc598('0x3f')],_0x3484c6[_0xc598('0x3b')]);_0x393fc6[_0xc598('0x40')]=_['intersection'](_0x3484c6[_0xc598('0x3f')],qs[_0xc598('0x41')](_0x1e0d26[_0xc598('0x3b')][_0xc598('0x41')]));_0x393fc6[_0xc598('0x40')]=_0x393fc6[_0xc598('0x40')]['length']?_0x393fc6[_0xc598('0x40')]:_0x3484c6['model'];if(!_0x1e0d26[_0xc598('0x3b')][_0xc598('0x42')](_0xc598('0x43'))){_0x393fc6['limit']=qs[_0xc598('0x29')](_0x1e0d26['query'][_0xc598('0x29')]);_0x393fc6[_0xc598('0x28')]=qs[_0xc598('0x28')](_0x1e0d26[_0xc598('0x3b')][_0xc598('0x28')]);}_0x393fc6[_0xc598('0x44')]=qs['sort'](_0x1e0d26['query'][_0xc598('0x45')]);_0x393fc6['where']=qs[_0xc598('0x3d')](_[_0xc598('0x46')](_0x1e0d26['query'],_0x3484c6[_0xc598('0x3d')]),_0x586bab);if(_0x1e0d26[_0xc598('0x3b')]['filter']){_0x393fc6['where']=_[_0xc598('0x47')](_0x393fc6['where'],{'$or':_[_0xc598('0x48')](_0x586bab,function(_0x464801){if(_0x464801[_0xc598('0x39')]!==_0xc598('0x49')){var _0x4bea8b={};_0x4bea8b[_0x464801[_0xc598('0x34')]]={'$like':'%'+_0x1e0d26[_0xc598('0x3b')][_0xc598('0x4a')]+'%'};return _0x4bea8b;}})});}_0x393fc6=_['merge']({},_0x393fc6,_0x1e0d26['options']);var _0x5f4873={'where':_0x393fc6[_0xc598('0x4b')]};return db['DeskAccount'][_0xc598('0x27')](_0x5f4873)[_0xc598('0x30')](function(_0xb286e9){_0x3ff2a7[_0xc598('0x27')]=_0xb286e9;if(_0x1e0d26['query']['includeAll']){_0x393fc6[_0xc598('0x4c')]=[{'all':!![]}];}return db[_0xc598('0x36')][_0xc598('0x4d')](_0x393fc6);})[_0xc598('0x30')](function(_0x140393){_0x3ff2a7['rows']=_0x140393;return _0x3ff2a7;})[_0xc598('0x30')](respondWithFilteredResult(_0x33abd0,_0x393fc6))[_0xc598('0x23')](handleError(_0x33abd0,null));};exports[_0xc598('0x4e')]=function(_0x409eae,_0x188d3f){var _0x4c0c2={'raw':![],'where':{'id':_0x409eae[_0xc598('0x4f')]['id']}},_0x2b5d3e={};_0x2b5d3e[_0xc598('0x3f')]=_[_0xc598('0x3c')](db[_0xc598('0x36')][_0xc598('0x37')]);_0x2b5d3e[_0xc598('0x3b')]=_[_0xc598('0x3c')](_0x409eae[_0xc598('0x3b')]);_0x2b5d3e[_0xc598('0x3d')]=_[_0xc598('0x3e')](_0x2b5d3e[_0xc598('0x3f')],_0x2b5d3e['query']);_0x4c0c2[_0xc598('0x40')]=_['intersection'](_0x2b5d3e[_0xc598('0x3f')],qs[_0xc598('0x41')](_0x409eae[_0xc598('0x3b')]['fields']));_0x4c0c2[_0xc598('0x40')]=_0x4c0c2[_0xc598('0x40')][_0xc598('0x50')]?_0x4c0c2[_0xc598('0x40')]:_0x2b5d3e[_0xc598('0x3f')];if(_0x409eae['query'][_0xc598('0x51')]){_0x4c0c2[_0xc598('0x4c')]=[{'all':!![]}];}_0x4c0c2=_[_0xc598('0x47')]({},_0x4c0c2,_0x409eae[_0xc598('0x52')]);return db[_0xc598('0x36')][_0xc598('0x53')](_0x4c0c2)[_0xc598('0x30')](handleEntityNotFound(_0x188d3f,null))['then'](respondWithResult(_0x188d3f,null))[_0xc598('0x23')](handleError(_0x188d3f,null));};exports[_0xc598('0x54')]=function(_0x247e9b,_0x2fc5f6){return db[_0xc598('0x36')][_0xc598('0x54')](_0x247e9b['body'],{})[_0xc598('0x30')](respondWithResult(_0x2fc5f6,0xc9))[_0xc598('0x23')](handleError(_0x2fc5f6,null));};exports[_0xc598('0x2f')]=function(_0x1e97e2,_0x345be3){if(_0x1e97e2[_0xc598('0x55')]['id']){delete _0x1e97e2['body']['id'];}return db[_0xc598('0x36')]['find']({'where':{'id':_0x1e97e2[_0xc598('0x4f')]['id']}})[_0xc598('0x30')](handleEntityNotFound(_0x345be3,null))[_0xc598('0x30')](saveUpdates(_0x1e97e2[_0xc598('0x55')],null))[_0xc598('0x30')](respondWithResult(_0x345be3,null))[_0xc598('0x23')](handleError(_0x345be3,null));};exports['destroy']=function(_0xf6eef4,_0x1e397a){return db[_0xc598('0x36')]['find']({'where':{'id':_0xf6eef4[_0xc598('0x4f')]['id']}})[_0xc598('0x30')](handleEntityNotFound(_0x1e397a,null))['then'](removeEntity(_0x1e397a,null))[_0xc598('0x23')](handleError(_0x1e397a,null));};exports[_0xc598('0x56')]=function(_0x487de0,_0x76c9fc,_0x49fa5e){var _0x47d702={};var _0x3052ca={};var _0x1f2039;var _0x565c63;return db['DeskAccount'][_0xc598('0x57')]({'where':{'id':_0x487de0['params']['id']}})[_0xc598('0x30')](handleEntityNotFound(_0x76c9fc,null))[_0xc598('0x30')](function(_0x5bc0f2){if(_0x5bc0f2){_0x1f2039=_0x5bc0f2;_0x3052ca[_0xc598('0x3f')]=_[_0xc598('0x3c')](db['DeskConfiguration']['rawAttributes']);_0x3052ca['query']=_['keys'](_0x487de0['query']);_0x3052ca[_0xc598('0x3d')]=_[_0xc598('0x3e')](_0x3052ca[_0xc598('0x3f')],_0x3052ca[_0xc598('0x3b')]);_0x47d702[_0xc598('0x40')]=_[_0xc598('0x3e')](_0x3052ca[_0xc598('0x3f')],qs[_0xc598('0x41')](_0x487de0[_0xc598('0x3b')]['fields']));_0x47d702[_0xc598('0x40')]=_0x47d702[_0xc598('0x40')][_0xc598('0x50')]?_0x47d702[_0xc598('0x40')]:_0x3052ca[_0xc598('0x3f')];_0x47d702['order']=qs['sort'](_0x487de0['query'][_0xc598('0x45')]);_0x47d702[_0xc598('0x4b')]=qs[_0xc598('0x3d')](_[_0xc598('0x46')](_0x487de0[_0xc598('0x3b')],_0x3052ca[_0xc598('0x3d')]));if(_0x487de0[_0xc598('0x3b')][_0xc598('0x4a')]){_0x47d702['where']=_[_0xc598('0x47')](_0x47d702[_0xc598('0x4b')],{'$or':_[_0xc598('0x48')](_0x47d702[_0xc598('0x40')],function(_0x14e824){var _0x4d34de={};_0x4d34de[_0x14e824]={'$like':'%'+_0x487de0['query'][_0xc598('0x4a')]+'%'};return _0x4d34de;})});}_0x47d702=_['merge']({},_0x47d702,_0x487de0[_0xc598('0x52')]);return _0x1f2039[_0xc598('0x56')](_0x47d702);}})[_0xc598('0x30')](function(_0x33d44f){if(_0x33d44f){_0x565c63=_0x33d44f[_0xc598('0x50')];if(!_0x487de0[_0xc598('0x3b')][_0xc598('0x42')](_0xc598('0x43'))){_0x47d702[_0xc598('0x29')]=qs['limit'](_0x487de0[_0xc598('0x3b')]['limit']);_0x47d702[_0xc598('0x28')]=qs[_0xc598('0x28')](_0x487de0[_0xc598('0x3b')][_0xc598('0x28')]);}return _0x1f2039[_0xc598('0x56')](_0x47d702);}})[_0xc598('0x30')](function(_0xfebebf){if(_0xfebebf){return _0xfebebf?{'count':_0x565c63,'rows':_0xfebebf}:null;}})[_0xc598('0x30')](respondWithResult(_0x76c9fc,null))['catch'](handleError(_0x76c9fc,null));};exports[_0xc598('0x58')]=function(_0x4fbecb,_0x25b896,_0x30d21c){if(_0x4fbecb[_0xc598('0x55')]['id']){delete _0x4fbecb['body']['id'];}return db[_0xc598('0x36')][_0xc598('0x57')]({'where':{'id':_0x4fbecb[_0xc598('0x4f')]['id']}})[_0xc598('0x30')](handleEntityNotFound(_0x25b896,null))[_0xc598('0x30')](function(_0x5ed8bf){if(_0x5ed8bf){_0x4fbecb[_0xc598('0x55')][_0xc598('0x59')]=_0x5ed8bf['id'];_0x4fbecb[_0xc598('0x55')][_0xc598('0x5a')]=integrations[_0xc598('0x5b')](_0x4fbecb[_0xc598('0x55')][_0xc598('0x5c')],_0x4fbecb[_0xc598('0x55')][_0xc598('0x39')]);_0x4fbecb[_0xc598('0x55')][_0xc598('0x5d')]=integrations[_0xc598('0x5e')](_0x4fbecb['body']['channel'],_0x4fbecb[_0xc598('0x55')]['type']);return db[_0xc598('0x5f')][_0xc598('0x54')](_0x4fbecb[_0xc598('0x55')],{'include':[{'model':db[_0xc598('0x60')],'as':_0xc598('0x5a')},{'model':db[_0xc598('0x60')],'as':'Descriptions'}]});}return null;})[_0xc598('0x30')](respondWithResult(_0x25b896,null))[_0xc598('0x23')](handleError(_0x25b896,null));};exports[_0xc598('0x61')]=function(_0x3c9e4f,_0x13a880,_0x456af5){var _0x1c612a=[{'name':_0xc598('0x62'),'label':_0xc598('0x62'),'custom':![],'options':[{'name':0x1,'value':0x1},{'name':0x2,'value':0x2},{'name':0x3,'value':0x3},{'name':0x4,'value':0x4},{'name':0x5,'value':0x5},{'name':0x6,'value':0x6},{'name':0x7,'value':0x7},{'name':0x8,'value':0x8},{'name':0x9,'value':0x9},{'name':0xa,'value':0xa}]}];var _0x381c8b='';return db[_0xc598('0x36')][_0xc598('0x57')]({'where':{'id':_0x3c9e4f[_0xc598('0x4f')]['id']},'attributes':['id',_0xc598('0x63'),_0xc598('0x64'),_0xc598('0x65'),'password',_0xc598('0x66'),_0xc598('0x67'),_0xc598('0x68'),_0xc598('0x69')]})[_0xc598('0x30')](handleEntityNotFound(_0x13a880,null))[_0xc598('0x30')](function(_0x35ba94){if(_0x35ba94){_0x381c8b=_0x35ba94[_0xc598('0x63')];var _0x3ddfdc=_0x381c8b[_0xc598('0x6a')](-0x1);if(_0x3ddfdc==='/'){_0x381c8b=_0x381c8b[_0xc598('0x6b')](0x0,_0x381c8b[_0xc598('0x6c')](_0x3ddfdc));}var _0x35bc05={'method':_0xc598('0x6d'),'uri':util[_0xc598('0x6e')]('%s/custom_fields',_0x381c8b),'headers':{'Content-Type':'application/json','Accept':'application/json'},'json':!![]};if(_0x35ba94[_0xc598('0x64')]==='basic'){_0x35bc05[_0xc598('0x6f')]['Authorization']=util[_0xc598('0x6e')]('Basic\x20%s',new Buffer(util['format'](_0xc598('0x70'),_0x35ba94[_0xc598('0x65')],_0x35ba94['password']))[_0xc598('0x71')](_0xc598('0x72')));}return rp(_0x35bc05)[_0xc598('0x30')](function(_0x373d1a){return _0x1c612a[_0xc598('0x73')](_['map'](_0x373d1a[_0xc598('0x74')][_0xc598('0x75')],function(_0x339b21){return{'id':_0x339b21[_0xc598('0x34')],'name':_0x339b21[_0xc598('0x34')],'type':_0x339b21[_0xc598('0x39')],'active':_0x339b21[_0xc598('0x76')],'label':_0x339b21['label'],'custom':!![]};}));});}})[_0xc598('0x30')](function(_0x2d753b){return{'count':_0x2d753b[_0xc598('0x50')],'rows':_0x2d753b};})[_0xc598('0x30')](respondWithResult(_0x13a880,null))['catch'](function(_0x5ac50e){var _0x1ec7ed=_0x3c9e4f[_0xc598('0x3b')][_0xc598('0x77')]?0x1f4:_0x5ac50e['statusCode']||0x1f4;logger[_0xc598('0x20')]('getFields,\x20%s,\x20%s,\x20%s',_0xc598('0x61'),_0x1ec7ed,JSON[_0xc598('0x78')](_0x5ac50e));delete _0x5ac50e[_0xc598('0x34')];if(_0x1ec7ed===0x191){_0x1ec7ed=0x190;}_0x13a880[_0xc598('0x24')](_0x1ec7ed)[_0xc598('0x35')](_0x3c9e4f[_0xc598('0x3b')]['test']?{'message':_0xc598('0x79'),'statusCode':_0x5ac50e[_0xc598('0x7a')]}:_0x5ac50e);});};
\ No newline at end of file