Built motion from commit 0900f080.|2.5.45
[motion2.git] / server / api / intDeskAccount / intDeskAccount.controller.js
index 19149d6..d9dca0f 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x54f3=['rimraf','fast-json-patch','moment','bluebird','util','sox','to-csv','lodash','squel','desk.js','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','../../components/integrations/configuration','jayson/promise','client','http','test','Sequelize','The\x20password\x20must\x20be\x20at\x20least\x208\x20characters\x20long\x20and\x20have\x201\x20lowercase\x20character,\x201\x20uppercase\x20character,\x201\x20number\x20and\x201\x20special\x20character\x20~!@#$%^&-_=+[{]}.','debug','stringify','error','message','DeskAccount,\x20%s,\x20%s','info','request\x20sent','result','catch','sendStatus','status','end','count','offset','limit','set','Content-Range','json','save','then','destroy','stack','name','send','index','map','DeskAccount','rawAttributes','fieldName','type','query','keys','filters','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','VIRTUAL','merge','options','includeAll','include','findAll','rows','show','params','find','create','body','update','findOne','DeskConfiguration','getConfigurations','addConfiguration','Subjects','getSubjects','Descriptions','getDescriptions','channel','getFields','priority','password','consumerSecret','token','tokenSecret','substring','lastIndexOf','GET','format','application/json','authType','basic','headers','Authorization','Basic\x20%s','%s:%s','username','_embedded','entries','active','label','statusCode','getFields,\x20%s,\x20%s,\x20%s','Wrong\x20credentials','html-pdf','eml-format'];(function(_0x38831b,_0x4611ea){var _0x5a508a=function(_0x2df441){while(--_0x2df441){_0x38831b['push'](_0x38831b['shift']());}};_0x5a508a(++_0x4611ea);}(_0x54f3,0xec));var _0x354f=function(_0x4a9fb1,_0x273043){_0x4a9fb1=_0x4a9fb1-0x0;var _0x348672=_0x54f3[_0x4a9fb1];return _0x348672;};'use strict';var pdf=require(_0x354f('0x0'));var emlformat=require(_0x354f('0x1'));var rimraf=require(_0x354f('0x2'));var zipdir=require('zip-dir');var jsonpatch=require(_0x354f('0x3'));var rp=require('request-promise');var moment=require(_0x354f('0x4'));var BPromise=require(_0x354f('0x5'));var Mustache=require('mustache');var util=require(_0x354f('0x6'));var path=require('path');var sox=require(_0x354f('0x7'));var csv=require(_0x354f('0x8'));var ejs=require('ejs');var fs=require('fs');var _=require(_0x354f('0x9'));var squel=require(_0x354f('0xa'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0x354f('0xb'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0x354f('0xc'));var qs=require(_0x354f('0xd'));var as=require(_0x354f('0xe'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x354f('0xf'))(_0x354f('0x10'));var utils=require(_0x354f('0x11'));var config=require(_0x354f('0x12'));var db=require(_0x354f('0x13'))['db'];var integrations=require(_0x354f('0x14'));var jayson=require(_0x354f('0x15'));var client=jayson[_0x354f('0x16')][_0x354f('0x17')]({'port':0x232a});function checkPasswordPattern(_0x3ffcd2,_0xf8a594,_0x5a647d){if(_0x5a647d){var _0x235eac=new RegExp(/(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[?!@#\$%\^&\*~\-_=+[{\]\}])(?=.{8,})/);if(_0x235eac[_0x354f('0x18')](_0xf8a594)){return _0x3ffcd2;}else{throw new db[(_0x354f('0x19'))]['ValidationError'](_0x354f('0x1a'));}}else{return _0x3ffcd2;}}function respondWithRpcPromise(_0x2c18f6,_0x5407a3,_0x1c9678,_0x2be366){return new BPromise(function(_0x4f3651,_0x55aed7){var _0x1509f2=_0x2be366||client;return _0x1509f2['request'](_0x2c18f6,_0x1c9678)['then'](function(_0xfe9c2d){logger['info']('DeskAccount,\x20%s,\x20%s',_0x5407a3,'request\x20sent');logger[_0x354f('0x1b')]('DeskAccount,\x20%s,\x20%s,\x20%s',_0x5407a3,'request\x20sent',JSON[_0x354f('0x1c')](_0xfe9c2d));if(_0xfe9c2d[_0x354f('0x1d')]){if(_0xfe9c2d[_0x354f('0x1d')]['code']===0x1f4){logger['error']('DeskAccount,\x20%s,\x20%s',_0x5407a3,_0xfe9c2d[_0x354f('0x1d')]['message']);return _0x55aed7(_0xfe9c2d[_0x354f('0x1d')][_0x354f('0x1e')]);}logger['error'](_0x354f('0x1f'),_0x5407a3,_0xfe9c2d[_0x354f('0x1d')][_0x354f('0x1e')]);return _0x4f3651(_0xfe9c2d[_0x354f('0x1d')][_0x354f('0x1e')]);}else{logger[_0x354f('0x20')](_0x354f('0x1f'),_0x5407a3,_0x354f('0x21'));_0x4f3651(_0xfe9c2d[_0x354f('0x22')][_0x354f('0x1e')]);}})[_0x354f('0x23')](function(_0xd5061d){logger[_0x354f('0x1d')](_0x354f('0x1f'),_0x5407a3,_0xd5061d);_0x55aed7(_0xd5061d);});});}function respondWithStatusCode(_0x26bc0e,_0x1f2652){_0x1f2652=_0x1f2652||0xcc;return function(_0x1b9d52){if(_0x1b9d52){return _0x26bc0e[_0x354f('0x24')](_0x1f2652);}return _0x26bc0e[_0x354f('0x25')](_0x1f2652)[_0x354f('0x26')]();};}function respondWithResult(_0x4fab00,_0x47bce3){_0x47bce3=_0x47bce3||0xc8;return function(_0xc0dfea){if(_0xc0dfea){return _0x4fab00[_0x354f('0x25')](_0x47bce3)['json'](_0xc0dfea);}};}function respondWithFilteredResult(_0x3b1a98,_0x2dbcf6){return function(_0x335a9a){if(_0x335a9a){var _0x49296b=_0x335a9a[_0x354f('0x27')],_0x1fabc5=_0x2dbcf6[_0x354f('0x28')],_0x150fba=_0x2dbcf6[_0x354f('0x28')]+_0x2dbcf6[_0x354f('0x29')],_0x3a7ad5;if(_0x150fba>=_0x49296b){_0x150fba=_0x49296b;_0x3a7ad5=0xc8;}else{_0x3a7ad5=0xce;}_0x3b1a98['status'](_0x3a7ad5);return _0x3b1a98[_0x354f('0x2a')](_0x354f('0x2b'),_0x1fabc5+'-'+_0x150fba+'/'+_0x49296b)[_0x354f('0x2c')](_0x335a9a);}return null;};}function patchUpdates(_0x2c1fff){return function(_0x41b01f){try{jsonpatch['apply'](_0x41b01f,_0x2c1fff,!![]);}catch(_0x4fc3be){return BPromise['reject'](_0x4fc3be);}return _0x41b01f[_0x354f('0x2d')]();};}function saveUpdates(_0x1c10ec,_0x5d885e){return function(_0x267055){if(_0x267055){return _0x267055['update'](_0x1c10ec)[_0x354f('0x2e')](function(_0x1b6c08){return _0x1b6c08;});}return null;};}function removeEntity(_0xf1872a,_0x2ed598){return function(_0x3d1937){if(_0x3d1937){return _0x3d1937[_0x354f('0x2f')]()[_0x354f('0x2e')](function(){_0xf1872a[_0x354f('0x25')](0xcc)['end']();});}};}function handleEntityNotFound(_0x44fd7a,_0x7e51b7){return function(_0x5434d7){if(!_0x5434d7){_0x44fd7a[_0x354f('0x24')](0x194);}return _0x5434d7;};}function handleError(_0x40423b,_0x5ba977){_0x5ba977=_0x5ba977||0x1f4;return function(_0x3a6023){logger[_0x354f('0x1d')](_0x3a6023[_0x354f('0x30')]);if(_0x3a6023[_0x354f('0x31')]){delete _0x3a6023[_0x354f('0x31')];}_0x40423b[_0x354f('0x25')](_0x5ba977)[_0x354f('0x32')](_0x3a6023);};}exports[_0x354f('0x33')]=function(_0x20e431,_0x27397e){var _0x498b57={},_0x4dd948={},_0x3c6a10={'count':0x0,'rows':[]};var _0x4a5e1b=_[_0x354f('0x34')](db[_0x354f('0x35')][_0x354f('0x36')],function(_0x237d2b){return{'name':_0x237d2b[_0x354f('0x37')],'type':_0x237d2b[_0x354f('0x38')]['key']};});_0x4dd948['model']=_['map'](_0x4a5e1b,_0x354f('0x31'));_0x4dd948[_0x354f('0x39')]=_[_0x354f('0x3a')](_0x20e431[_0x354f('0x39')]);_0x4dd948[_0x354f('0x3b')]=_[_0x354f('0x3c')](_0x4dd948[_0x354f('0x3d')],_0x4dd948[_0x354f('0x39')]);_0x498b57[_0x354f('0x3e')]=_[_0x354f('0x3c')](_0x4dd948['model'],qs[_0x354f('0x3f')](_0x20e431[_0x354f('0x39')][_0x354f('0x3f')]));_0x498b57[_0x354f('0x3e')]=_0x498b57[_0x354f('0x3e')][_0x354f('0x40')]?_0x498b57[_0x354f('0x3e')]:_0x4dd948['model'];if(!_0x20e431[_0x354f('0x39')][_0x354f('0x41')](_0x354f('0x42'))){_0x498b57[_0x354f('0x29')]=qs[_0x354f('0x29')](_0x20e431['query']['limit']);_0x498b57[_0x354f('0x28')]=qs[_0x354f('0x28')](_0x20e431[_0x354f('0x39')][_0x354f('0x28')]);}_0x498b57[_0x354f('0x43')]=qs[_0x354f('0x44')](_0x20e431[_0x354f('0x39')]['sort']);_0x498b57[_0x354f('0x45')]=qs[_0x354f('0x3b')](_[_0x354f('0x46')](_0x20e431[_0x354f('0x39')],_0x4dd948[_0x354f('0x3b')]));if(_0x20e431[_0x354f('0x39')][_0x354f('0x47')]){_0x498b57[_0x354f('0x45')]=_['merge'](_0x498b57[_0x354f('0x45')],{'$or':_[_0x354f('0x34')](_0x4a5e1b,function(_0x4600f1){if(_0x4600f1[_0x354f('0x38')]!==_0x354f('0x48')){var _0x593dd9={};_0x593dd9[_0x4600f1[_0x354f('0x31')]]={'$like':'%'+_0x20e431['query'][_0x354f('0x47')]+'%'};return _0x593dd9;}})});}_0x498b57=_[_0x354f('0x49')]({},_0x498b57,_0x20e431[_0x354f('0x4a')]);var _0xa9c84b={'where':_0x498b57[_0x354f('0x45')]};return db[_0x354f('0x35')][_0x354f('0x27')](_0xa9c84b)[_0x354f('0x2e')](function(_0x3c35dd){_0x3c6a10['count']=_0x3c35dd;if(_0x20e431[_0x354f('0x39')][_0x354f('0x4b')]){_0x498b57[_0x354f('0x4c')]=[{'all':!![]}];}return db[_0x354f('0x35')][_0x354f('0x4d')](_0x498b57);})[_0x354f('0x2e')](function(_0x528d26){_0x3c6a10[_0x354f('0x4e')]=_0x528d26;return _0x3c6a10;})[_0x354f('0x2e')](respondWithFilteredResult(_0x27397e,_0x498b57))['catch'](handleError(_0x27397e,null));};exports[_0x354f('0x4f')]=function(_0x28f2a1,_0x4bd453){var _0x42afb8={'raw':![],'where':{'id':_0x28f2a1[_0x354f('0x50')]['id']}},_0x1f780d={};_0x1f780d['model']=_[_0x354f('0x3a')](db['DeskAccount'][_0x354f('0x36')]);_0x1f780d['query']=_['keys'](_0x28f2a1[_0x354f('0x39')]);_0x1f780d[_0x354f('0x3b')]=_[_0x354f('0x3c')](_0x1f780d[_0x354f('0x3d')],_0x1f780d[_0x354f('0x39')]);_0x42afb8[_0x354f('0x3e')]=_[_0x354f('0x3c')](_0x1f780d[_0x354f('0x3d')],qs['fields'](_0x28f2a1[_0x354f('0x39')][_0x354f('0x3f')]));_0x42afb8[_0x354f('0x3e')]=_0x42afb8[_0x354f('0x3e')][_0x354f('0x40')]?_0x42afb8['attributes']:_0x1f780d[_0x354f('0x3d')];if(_0x28f2a1[_0x354f('0x39')][_0x354f('0x4b')]){_0x42afb8[_0x354f('0x4c')]=[{'all':!![]}];}_0x42afb8=_[_0x354f('0x49')]({},_0x42afb8,_0x28f2a1[_0x354f('0x4a')]);return db[_0x354f('0x35')][_0x354f('0x51')](_0x42afb8)[_0x354f('0x2e')](handleEntityNotFound(_0x4bd453,null))[_0x354f('0x2e')](respondWithResult(_0x4bd453,null))[_0x354f('0x23')](handleError(_0x4bd453,null));};exports[_0x354f('0x52')]=function(_0x545037,_0x4f8986){return db[_0x354f('0x35')][_0x354f('0x52')](_0x545037[_0x354f('0x53')],{})[_0x354f('0x2e')](respondWithResult(_0x4f8986,0xc9))[_0x354f('0x23')](handleError(_0x4f8986,null));};exports[_0x354f('0x54')]=function(_0x1243d3,_0x12b0cc){if(_0x1243d3['body']['id']){delete _0x1243d3[_0x354f('0x53')]['id'];}return db[_0x354f('0x35')][_0x354f('0x51')]({'where':{'id':_0x1243d3[_0x354f('0x50')]['id']}})[_0x354f('0x2e')](handleEntityNotFound(_0x12b0cc,null))[_0x354f('0x2e')](saveUpdates(_0x1243d3['body'],null))[_0x354f('0x2e')](respondWithResult(_0x12b0cc,null))[_0x354f('0x23')](handleError(_0x12b0cc,null));};exports[_0x354f('0x2f')]=function(_0x254b06,_0x3cd956){return db['DeskAccount'][_0x354f('0x51')]({'where':{'id':_0x254b06[_0x354f('0x50')]['id']}})[_0x354f('0x2e')](handleEntityNotFound(_0x3cd956,null))[_0x354f('0x2e')](removeEntity(_0x3cd956,null))[_0x354f('0x23')](handleError(_0x3cd956,null));};exports['getConfigurations']=function(_0x4f4f52,_0x5dd870,_0x8dc9d9){var _0x3b9c7c={};var _0x20b614={};var _0x371c86;var _0x4126bb;return db[_0x354f('0x35')][_0x354f('0x55')]({'where':{'id':_0x4f4f52[_0x354f('0x50')]['id']}})[_0x354f('0x2e')](handleEntityNotFound(_0x5dd870,null))[_0x354f('0x2e')](function(_0x2d356d){if(_0x2d356d){_0x371c86=_0x2d356d;_0x20b614[_0x354f('0x3d')]=_[_0x354f('0x3a')](db[_0x354f('0x56')][_0x354f('0x36')]);_0x20b614[_0x354f('0x39')]=_[_0x354f('0x3a')](_0x4f4f52[_0x354f('0x39')]);_0x20b614[_0x354f('0x3b')]=_[_0x354f('0x3c')](_0x20b614[_0x354f('0x3d')],_0x20b614['query']);_0x3b9c7c[_0x354f('0x3e')]=_[_0x354f('0x3c')](_0x20b614[_0x354f('0x3d')],qs[_0x354f('0x3f')](_0x4f4f52[_0x354f('0x39')]['fields']));_0x3b9c7c[_0x354f('0x3e')]=_0x3b9c7c[_0x354f('0x3e')][_0x354f('0x40')]?_0x3b9c7c[_0x354f('0x3e')]:_0x20b614['model'];_0x3b9c7c[_0x354f('0x43')]=qs[_0x354f('0x44')](_0x4f4f52['query'][_0x354f('0x44')]);_0x3b9c7c[_0x354f('0x45')]=qs[_0x354f('0x3b')](_[_0x354f('0x46')](_0x4f4f52[_0x354f('0x39')],_0x20b614[_0x354f('0x3b')]));if(_0x4f4f52[_0x354f('0x39')][_0x354f('0x47')]){_0x3b9c7c[_0x354f('0x45')]=_[_0x354f('0x49')](_0x3b9c7c[_0x354f('0x45')],{'$or':_['map'](_0x3b9c7c[_0x354f('0x3e')],function(_0x29a1af){var _0x30c78b={};_0x30c78b[_0x29a1af]={'$like':'%'+_0x4f4f52[_0x354f('0x39')]['filter']+'%'};return _0x30c78b;})});}_0x3b9c7c=_['merge']({},_0x3b9c7c,_0x4f4f52['options']);return _0x371c86[_0x354f('0x57')](_0x3b9c7c);}})['then'](function(_0x1f1261){if(_0x1f1261){_0x4126bb=_0x1f1261[_0x354f('0x40')];if(!_0x4f4f52[_0x354f('0x39')][_0x354f('0x41')](_0x354f('0x42'))){_0x3b9c7c[_0x354f('0x29')]=qs[_0x354f('0x29')](_0x4f4f52[_0x354f('0x39')][_0x354f('0x29')]);_0x3b9c7c[_0x354f('0x28')]=qs['offset'](_0x4f4f52[_0x354f('0x39')][_0x354f('0x28')]);}return _0x371c86[_0x354f('0x57')](_0x3b9c7c);}})[_0x354f('0x2e')](function(_0x8b06cc){if(_0x8b06cc){return _0x8b06cc?{'count':_0x4126bb,'rows':_0x8b06cc}:null;}})[_0x354f('0x2e')](respondWithResult(_0x5dd870,null))[_0x354f('0x23')](handleError(_0x5dd870,null));};exports[_0x354f('0x58')]=function(_0xb6bf3d,_0x540bc7,_0xc3377b){if(_0xb6bf3d[_0x354f('0x53')]['id']){delete _0xb6bf3d[_0x354f('0x53')]['id'];}return db['DeskAccount'][_0x354f('0x55')]({'where':{'id':_0xb6bf3d[_0x354f('0x50')]['id']}})['then'](handleEntityNotFound(_0x540bc7,null))[_0x354f('0x2e')](function(_0x2c9615){if(_0x2c9615){_0xb6bf3d[_0x354f('0x53')]['AccountId']=_0x2c9615['id'];_0xb6bf3d[_0x354f('0x53')][_0x354f('0x59')]=integrations[_0x354f('0x5a')](_0xb6bf3d['body']['channel'],_0xb6bf3d[_0x354f('0x53')]['type']);_0xb6bf3d['body'][_0x354f('0x5b')]=integrations[_0x354f('0x5c')](_0xb6bf3d[_0x354f('0x53')][_0x354f('0x5d')],_0xb6bf3d[_0x354f('0x53')]['type']);return db[_0x354f('0x56')]['create'](_0xb6bf3d[_0x354f('0x53')],{'include':[{'model':db['DeskField'],'as':'Subjects'},{'model':db['DeskField'],'as':_0x354f('0x5b')}]});}return null;})[_0x354f('0x2e')](respondWithResult(_0x540bc7,null))[_0x354f('0x23')](handleError(_0x540bc7,null));};exports[_0x354f('0x5e')]=function(_0xae7cb4,_0x5e3f06,_0x4be3f6){var _0x523ebe=[{'name':_0x354f('0x5f'),'label':_0x354f('0x5f'),'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 _0x3f81b3='';return db[_0x354f('0x35')][_0x354f('0x55')]({'where':{'id':_0xae7cb4[_0x354f('0x50')]['id']},'attributes':['id','remoteUri','authType','username',_0x354f('0x60'),'consumerKey',_0x354f('0x61'),_0x354f('0x62'),_0x354f('0x63')]})[_0x354f('0x2e')](handleEntityNotFound(_0x5e3f06,null))[_0x354f('0x2e')](function(_0x342950){if(_0x342950){_0x3f81b3=_0x342950['remoteUri'];var _0x3901e5=_0x3f81b3['slice'](-0x1);if(_0x3901e5==='/'){_0x3f81b3=_0x3f81b3[_0x354f('0x64')](0x0,_0x3f81b3[_0x354f('0x65')](_0x3901e5));}var _0x14d4f8={'method':_0x354f('0x66'),'uri':util[_0x354f('0x67')]('%s/custom_fields',_0x3f81b3),'headers':{'Content-Type':_0x354f('0x68'),'Accept':_0x354f('0x68')},'json':!![]};if(_0x342950[_0x354f('0x69')]===_0x354f('0x6a')){_0x14d4f8[_0x354f('0x6b')][_0x354f('0x6c')]=util['format'](_0x354f('0x6d'),new Buffer(util[_0x354f('0x67')](_0x354f('0x6e'),_0x342950[_0x354f('0x6f')],_0x342950['password']))['toString']('base64'));}return rp(_0x14d4f8)['then'](function(_0x3b0f0a){return _0x523ebe['concat'](_[_0x354f('0x34')](_0x3b0f0a[_0x354f('0x70')][_0x354f('0x71')],function(_0xddfd11){return{'id':_0xddfd11['name'],'name':_0xddfd11[_0x354f('0x31')],'type':_0xddfd11[_0x354f('0x38')],'active':_0xddfd11[_0x354f('0x72')],'label':_0xddfd11[_0x354f('0x73')],'custom':!![]};}));});}})['then'](function(_0x3dc494){return{'count':_0x3dc494[_0x354f('0x40')],'rows':_0x3dc494};})[_0x354f('0x2e')](respondWithResult(_0x5e3f06,null))[_0x354f('0x23')](function(_0x12cf2a){var _0x136df6=_0xae7cb4[_0x354f('0x39')][_0x354f('0x18')]?0x1f4:_0x12cf2a[_0x354f('0x74')]||0x1f4;logger[_0x354f('0x1d')](_0x354f('0x75'),_0x354f('0x5e'),_0x136df6,JSON[_0x354f('0x1c')](_0x12cf2a));delete _0x12cf2a[_0x354f('0x31')];if(_0x136df6===0x191){_0x136df6=0x190;}_0x5e3f06[_0x354f('0x25')](_0x136df6)[_0x354f('0x32')](_0xae7cb4[_0x354f('0x39')][_0x354f('0x18')]?{'message':_0x354f('0x76'),'statusCode':_0x12cf2a[_0x354f('0x74')]}:_0x12cf2a);});};
\ No newline at end of file
+var _0x3685=['channel','Descriptions','getDescriptions','DeskConfiguration','create','Subjects','DeskField','getFields','priority','remoteUri','authType','username','password','consumerKey','slice','substring','GET','format','%s/custom_fields','application/json','headers','Authorization','Basic\x20%s','base64','entries','active','label','test','statusCode','getFields,\x20%s,\x20%s,\x20%s','stringify','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','mustache','path','to-csv','ejs','fs-extra','squel','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','../../components/integrations/configuration','end','status','json','offset','undefined','count','limit','set','reject','save','update','destroy','then','sendStatus','stack','name','send','index','map','DeskAccount','rawAttributes','fieldName','type','key','query','keys','filters','intersection','model','fields','attributes','length','hasOwnProperty','nolimit','order','sort','pick','filter','where','merge','includeAll','findAll','rows','catch','show','params','options','body','find','getConfigurations','findOne','addConfiguration','AccountId'];(function(_0x1834df,_0x27bad3){var _0x5b3b41=function(_0x5830e7){while(--_0x5830e7){_0x1834df['push'](_0x1834df['shift']());}};_0x5b3b41(++_0x27bad3);}(_0x3685,0x1cf));var _0x5368=function(_0x122ef9,_0x451d2a){_0x122ef9=_0x122ef9-0x0;var _0x42fba0=_0x3685[_0x122ef9];return _0x42fba0;};'use strict';var emlformat=require(_0x5368('0x0'));var rimraf=require(_0x5368('0x1'));var zipdir=require(_0x5368('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x5368('0x3'));var moment=require(_0x5368('0x4'));var BPromise=require(_0x5368('0x5'));var Mustache=require(_0x5368('0x6'));var util=require('util');var path=require(_0x5368('0x7'));var sox=require('sox');var csv=require(_0x5368('0x8'));var ejs=require(_0x5368('0x9'));var fs=require('fs');var fs_extra=require(_0x5368('0xa'));var _=require('lodash');var squel=require(_0x5368('0xb'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0x5368('0xc'));var toCsv=require(_0x5368('0x8'));var querystring=require('querystring');var Papa=require(_0x5368('0xd'));var Redis=require(_0x5368('0xe'));var authService=require(_0x5368('0xf'));var qs=require(_0x5368('0x10'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x5368('0x11'));var logger=require('../../config/logger')(_0x5368('0x12'));var utils=require(_0x5368('0x13'));var config=require(_0x5368('0x14'));var licenseUtil=require(_0x5368('0x15'));var db=require(_0x5368('0x16'))['db'];var integrations=require(_0x5368('0x17'));function respondWithStatusCode(_0x278b5d,_0x13544c){_0x13544c=_0x13544c||0xcc;return function(_0x243346){if(_0x243346){return _0x278b5d['sendStatus'](_0x13544c);}return _0x278b5d['status'](_0x13544c)[_0x5368('0x18')]();};}function respondWithResult(_0x24c2a2,_0x1fe49a){_0x1fe49a=_0x1fe49a||0xc8;return function(_0x871794){if(_0x871794){return _0x24c2a2[_0x5368('0x19')](_0x1fe49a)[_0x5368('0x1a')](_0x871794);}};}function respondWithFilteredResult(_0x125c46,_0x43bb65){return function(_0x22a6de){if(_0x22a6de){var _0x5070f6=typeof _0x43bb65[_0x5368('0x1b')]===_0x5368('0x1c')&&typeof _0x43bb65['limit']==='undefined';var _0x2d37d3=_0x22a6de[_0x5368('0x1d')];var _0x398153=_0x5070f6?0x0:_0x43bb65[_0x5368('0x1b')];var _0x696ac2=_0x5070f6?_0x22a6de[_0x5368('0x1d')]:_0x43bb65[_0x5368('0x1b')]+_0x43bb65[_0x5368('0x1e')];var _0xb501a4;if(_0x696ac2>=_0x2d37d3){_0x696ac2=_0x2d37d3;_0xb501a4=0xc8;}else{_0xb501a4=0xce;}_0x125c46[_0x5368('0x19')](_0xb501a4);return _0x125c46[_0x5368('0x1f')]('Content-Range',_0x398153+'-'+_0x696ac2+'/'+_0x2d37d3)['json'](_0x22a6de);}return null;};}function patchUpdates(_0x2b77ed){return function(_0x3ed694){try{jsonpatch['apply'](_0x3ed694,_0x2b77ed,!![]);}catch(_0x58d361){return BPromise[_0x5368('0x20')](_0x58d361);}return _0x3ed694[_0x5368('0x21')]();};}function saveUpdates(_0x32629b,_0x1f8191){return function(_0xc46930){if(_0xc46930){return _0xc46930[_0x5368('0x22')](_0x32629b)['then'](function(_0xc1c95e){return _0xc1c95e;});}return null;};}function removeEntity(_0x36c812,_0x272ff1){return function(_0x3524c5){if(_0x3524c5){return _0x3524c5[_0x5368('0x23')]()[_0x5368('0x24')](function(){_0x36c812[_0x5368('0x19')](0xcc)[_0x5368('0x18')]();});}};}function handleEntityNotFound(_0x2a6763,_0x51c9c3){return function(_0x42b9d7){if(!_0x42b9d7){_0x2a6763[_0x5368('0x25')](0x194);}return _0x42b9d7;};}function handleError(_0x4b208d,_0x2f5f5b){_0x2f5f5b=_0x2f5f5b||0x1f4;return function(_0x4825ed){logger['error'](_0x4825ed[_0x5368('0x26')]);if(_0x4825ed['name']){delete _0x4825ed[_0x5368('0x27')];}_0x4b208d[_0x5368('0x19')](_0x2f5f5b)[_0x5368('0x28')](_0x4825ed);};}exports[_0x5368('0x29')]=function(_0x44ac24,_0x5a1f61){var _0x18d954={},_0x5b429c={},_0x33f806={'count':0x0,'rows':[]};var _0xd91acd=_[_0x5368('0x2a')](db[_0x5368('0x2b')][_0x5368('0x2c')],function(_0x499e9d){return{'name':_0x499e9d[_0x5368('0x2d')],'type':_0x499e9d[_0x5368('0x2e')][_0x5368('0x2f')]};});_0x5b429c['model']=_[_0x5368('0x2a')](_0xd91acd,_0x5368('0x27'));_0x5b429c[_0x5368('0x30')]=_[_0x5368('0x31')](_0x44ac24[_0x5368('0x30')]);_0x5b429c[_0x5368('0x32')]=_[_0x5368('0x33')](_0x5b429c[_0x5368('0x34')],_0x5b429c[_0x5368('0x30')]);_0x18d954['attributes']=_[_0x5368('0x33')](_0x5b429c[_0x5368('0x34')],qs[_0x5368('0x35')](_0x44ac24[_0x5368('0x30')][_0x5368('0x35')]));_0x18d954['attributes']=_0x18d954[_0x5368('0x36')][_0x5368('0x37')]?_0x18d954['attributes']:_0x5b429c['model'];if(!_0x44ac24[_0x5368('0x30')][_0x5368('0x38')](_0x5368('0x39'))){_0x18d954[_0x5368('0x1e')]=qs[_0x5368('0x1e')](_0x44ac24[_0x5368('0x30')]['limit']);_0x18d954[_0x5368('0x1b')]=qs['offset'](_0x44ac24[_0x5368('0x30')][_0x5368('0x1b')]);}_0x18d954[_0x5368('0x3a')]=qs[_0x5368('0x3b')](_0x44ac24[_0x5368('0x30')][_0x5368('0x3b')]);_0x18d954['where']=qs['filters'](_[_0x5368('0x3c')](_0x44ac24[_0x5368('0x30')],_0x5b429c[_0x5368('0x32')]),_0xd91acd);if(_0x44ac24[_0x5368('0x30')][_0x5368('0x3d')]){_0x18d954[_0x5368('0x3e')]=_['merge'](_0x18d954[_0x5368('0x3e')],{'$or':_['map'](_0xd91acd,function(_0x4a4628){if(_0x4a4628[_0x5368('0x2e')]!=='VIRTUAL'){var _0x112301={};_0x112301[_0x4a4628[_0x5368('0x27')]]={'$like':'%'+_0x44ac24[_0x5368('0x30')]['filter']+'%'};return _0x112301;}})});}_0x18d954=_[_0x5368('0x3f')]({},_0x18d954,_0x44ac24['options']);var _0x462eb0={'where':_0x18d954['where']};return db[_0x5368('0x2b')][_0x5368('0x1d')](_0x462eb0)['then'](function(_0x55d455){_0x33f806[_0x5368('0x1d')]=_0x55d455;if(_0x44ac24[_0x5368('0x30')][_0x5368('0x40')]){_0x18d954['include']=[{'all':!![]}];}return db['DeskAccount'][_0x5368('0x41')](_0x18d954);})[_0x5368('0x24')](function(_0x3d5c88){_0x33f806[_0x5368('0x42')]=_0x3d5c88;return _0x33f806;})['then'](respondWithFilteredResult(_0x5a1f61,_0x18d954))[_0x5368('0x43')](handleError(_0x5a1f61,null));};exports[_0x5368('0x44')]=function(_0x4b7942,_0x2a5e9e){var _0x8604ee={'raw':![],'where':{'id':_0x4b7942[_0x5368('0x45')]['id']}},_0x5a0cc={};_0x5a0cc[_0x5368('0x34')]=_[_0x5368('0x31')](db[_0x5368('0x2b')][_0x5368('0x2c')]);_0x5a0cc[_0x5368('0x30')]=_[_0x5368('0x31')](_0x4b7942[_0x5368('0x30')]);_0x5a0cc[_0x5368('0x32')]=_[_0x5368('0x33')](_0x5a0cc[_0x5368('0x34')],_0x5a0cc[_0x5368('0x30')]);_0x8604ee[_0x5368('0x36')]=_[_0x5368('0x33')](_0x5a0cc['model'],qs[_0x5368('0x35')](_0x4b7942[_0x5368('0x30')][_0x5368('0x35')]));_0x8604ee[_0x5368('0x36')]=_0x8604ee[_0x5368('0x36')][_0x5368('0x37')]?_0x8604ee[_0x5368('0x36')]:_0x5a0cc[_0x5368('0x34')];if(_0x4b7942[_0x5368('0x30')]['includeAll']){_0x8604ee['include']=[{'all':!![]}];}_0x8604ee=_[_0x5368('0x3f')]({},_0x8604ee,_0x4b7942[_0x5368('0x46')]);return db[_0x5368('0x2b')]['find'](_0x8604ee)[_0x5368('0x24')](handleEntityNotFound(_0x2a5e9e,null))[_0x5368('0x24')](respondWithResult(_0x2a5e9e,null))[_0x5368('0x43')](handleError(_0x2a5e9e,null));};exports['create']=function(_0x3c9806,_0x5bbbd2){return db[_0x5368('0x2b')]['create'](_0x3c9806[_0x5368('0x47')],{})[_0x5368('0x24')](respondWithResult(_0x5bbbd2,0xc9))[_0x5368('0x43')](handleError(_0x5bbbd2,null));};exports[_0x5368('0x22')]=function(_0x3028a9,_0x2a5bd0){if(_0x3028a9[_0x5368('0x47')]['id']){delete _0x3028a9[_0x5368('0x47')]['id'];}return db[_0x5368('0x2b')][_0x5368('0x48')]({'where':{'id':_0x3028a9['params']['id']}})[_0x5368('0x24')](handleEntityNotFound(_0x2a5bd0,null))[_0x5368('0x24')](saveUpdates(_0x3028a9[_0x5368('0x47')],null))[_0x5368('0x24')](respondWithResult(_0x2a5bd0,null))[_0x5368('0x43')](handleError(_0x2a5bd0,null));};exports[_0x5368('0x23')]=function(_0xb92fcb,_0x591326){return db[_0x5368('0x2b')][_0x5368('0x48')]({'where':{'id':_0xb92fcb[_0x5368('0x45')]['id']}})[_0x5368('0x24')](handleEntityNotFound(_0x591326,null))[_0x5368('0x24')](removeEntity(_0x591326,null))[_0x5368('0x43')](handleError(_0x591326,null));};exports[_0x5368('0x49')]=function(_0x470f04,_0x4a7fbf,_0x1c2a8a){var _0x3d848b={};var _0x370779={};var _0x52a903;var _0x11bca3;return db[_0x5368('0x2b')][_0x5368('0x4a')]({'where':{'id':_0x470f04[_0x5368('0x45')]['id']}})[_0x5368('0x24')](handleEntityNotFound(_0x4a7fbf,null))['then'](function(_0x227be8){if(_0x227be8){_0x52a903=_0x227be8;_0x370779['model']=_[_0x5368('0x31')](db['DeskConfiguration']['rawAttributes']);_0x370779['query']=_['keys'](_0x470f04[_0x5368('0x30')]);_0x370779['filters']=_[_0x5368('0x33')](_0x370779['model'],_0x370779[_0x5368('0x30')]);_0x3d848b['attributes']=_[_0x5368('0x33')](_0x370779[_0x5368('0x34')],qs['fields'](_0x470f04[_0x5368('0x30')]['fields']));_0x3d848b[_0x5368('0x36')]=_0x3d848b[_0x5368('0x36')]['length']?_0x3d848b[_0x5368('0x36')]:_0x370779[_0x5368('0x34')];_0x3d848b['order']=qs[_0x5368('0x3b')](_0x470f04[_0x5368('0x30')][_0x5368('0x3b')]);_0x3d848b[_0x5368('0x3e')]=qs[_0x5368('0x32')](_['pick'](_0x470f04['query'],_0x370779['filters']));if(_0x470f04['query'][_0x5368('0x3d')]){_0x3d848b['where']=_[_0x5368('0x3f')](_0x3d848b[_0x5368('0x3e')],{'$or':_[_0x5368('0x2a')](_0x3d848b['attributes'],function(_0x198f38){var _0xc639f5={};_0xc639f5[_0x198f38]={'$like':'%'+_0x470f04[_0x5368('0x30')]['filter']+'%'};return _0xc639f5;})});}_0x3d848b=_[_0x5368('0x3f')]({},_0x3d848b,_0x470f04[_0x5368('0x46')]);return _0x52a903[_0x5368('0x49')](_0x3d848b);}})['then'](function(_0x3ae69c){if(_0x3ae69c){_0x11bca3=_0x3ae69c['length'];if(!_0x470f04['query']['hasOwnProperty']('nolimit')){_0x3d848b[_0x5368('0x1e')]=qs[_0x5368('0x1e')](_0x470f04[_0x5368('0x30')]['limit']);_0x3d848b[_0x5368('0x1b')]=qs['offset'](_0x470f04[_0x5368('0x30')][_0x5368('0x1b')]);}return _0x52a903[_0x5368('0x49')](_0x3d848b);}})[_0x5368('0x24')](function(_0x3f0a56){if(_0x3f0a56){return _0x3f0a56?{'count':_0x11bca3,'rows':_0x3f0a56}:null;}})[_0x5368('0x24')](respondWithResult(_0x4a7fbf,null))[_0x5368('0x43')](handleError(_0x4a7fbf,null));};exports[_0x5368('0x4b')]=function(_0x523228,_0x96040d,_0x41492e){if(_0x523228[_0x5368('0x47')]['id']){delete _0x523228[_0x5368('0x47')]['id'];}return db[_0x5368('0x2b')]['findOne']({'where':{'id':_0x523228[_0x5368('0x45')]['id']}})[_0x5368('0x24')](handleEntityNotFound(_0x96040d,null))['then'](function(_0x2302ff){if(_0x2302ff){_0x523228['body'][_0x5368('0x4c')]=_0x2302ff['id'];_0x523228[_0x5368('0x47')]['Subjects']=integrations['getSubjects'](_0x523228[_0x5368('0x47')][_0x5368('0x4d')],_0x523228[_0x5368('0x47')][_0x5368('0x2e')]);_0x523228['body'][_0x5368('0x4e')]=integrations[_0x5368('0x4f')](_0x523228[_0x5368('0x47')][_0x5368('0x4d')],_0x523228[_0x5368('0x47')][_0x5368('0x2e')]);return db[_0x5368('0x50')][_0x5368('0x51')](_0x523228[_0x5368('0x47')],{'include':[{'model':db['DeskField'],'as':_0x5368('0x52')},{'model':db[_0x5368('0x53')],'as':_0x5368('0x4e')}]});}return null;})['then'](respondWithResult(_0x96040d,null))[_0x5368('0x43')](handleError(_0x96040d,null));};exports[_0x5368('0x54')]=function(_0x3d523f,_0x3c7c42,_0x8755b1){var _0x3d172d=[{'name':'priority','label':_0x5368('0x55'),'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 _0x8a6207='';return db[_0x5368('0x2b')]['findOne']({'where':{'id':_0x3d523f[_0x5368('0x45')]['id']},'attributes':['id',_0x5368('0x56'),_0x5368('0x57'),_0x5368('0x58'),_0x5368('0x59'),_0x5368('0x5a'),'consumerSecret','token','tokenSecret']})[_0x5368('0x24')](handleEntityNotFound(_0x3c7c42,null))[_0x5368('0x24')](function(_0x3dc664){if(_0x3dc664){_0x8a6207=_0x3dc664['remoteUri'];var _0x27db54=_0x8a6207[_0x5368('0x5b')](-0x1);if(_0x27db54==='/'){_0x8a6207=_0x8a6207[_0x5368('0x5c')](0x0,_0x8a6207['lastIndexOf'](_0x27db54));}var _0x430f7a={'method':_0x5368('0x5d'),'uri':util[_0x5368('0x5e')](_0x5368('0x5f'),_0x8a6207),'headers':{'Content-Type':_0x5368('0x60'),'Accept':_0x5368('0x60')},'json':!![]};if(_0x3dc664[_0x5368('0x57')]==='basic'){_0x430f7a[_0x5368('0x61')][_0x5368('0x62')]=util[_0x5368('0x5e')](_0x5368('0x63'),new Buffer(util[_0x5368('0x5e')]('%s:%s',_0x3dc664[_0x5368('0x58')],_0x3dc664[_0x5368('0x59')]))['toString'](_0x5368('0x64')));}return rp(_0x430f7a)[_0x5368('0x24')](function(_0x26eae8){return _0x3d172d['concat'](_['map'](_0x26eae8['_embedded'][_0x5368('0x65')],function(_0x529698){return{'id':_0x529698[_0x5368('0x27')],'name':_0x529698['name'],'type':_0x529698['type'],'active':_0x529698[_0x5368('0x66')],'label':_0x529698[_0x5368('0x67')],'custom':!![]};}));});}})[_0x5368('0x24')](function(_0xabc969){return{'count':_0xabc969[_0x5368('0x37')],'rows':_0xabc969};})[_0x5368('0x24')](respondWithResult(_0x3c7c42,null))[_0x5368('0x43')](function(_0x5aafc5){var _0x5e7d8b=_0x3d523f['query'][_0x5368('0x68')]?0x1f4:_0x5aafc5[_0x5368('0x69')]||0x1f4;logger['error'](_0x5368('0x6a'),'getFields',_0x5e7d8b,JSON[_0x5368('0x6b')](_0x5aafc5));delete _0x5aafc5[_0x5368('0x27')];if(_0x5e7d8b===0x191){_0x5e7d8b=0x190;}_0x3c7c42[_0x5368('0x19')](_0x5e7d8b)[_0x5368('0x28')](_0x3d523f[_0x5368('0x30')][_0x5368('0x68')]?{'message':'Wrong\x20credentials','statusCode':_0x5aafc5[_0x5368('0x69')]}:_0x5aafc5);});};
\ No newline at end of file