Built motion from commit da617fac.|2.6.6
[motion2.git] / server / api / intDeskAccount / intDeskAccount.controller.js
index 2ed2e95..dc57cab 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xd0c5=['send','statusCode','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','mustache','util','path','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../mysqldb','../../components/integrations/configuration','jayson/promise','http','test','ValidationError','The\x20password\x20must\x20be\x20at\x20least\x208\x20characters\x20long\x20and\x20have\x201\x20lowercase\x20character,\x201\x20uppercase\x20character,\x201\x20number\x20and\x201\x20special\x20character\x20~!@#$%^&-_=+[{]}.','then','info','request\x20sent','debug','DeskAccount,\x20%s,\x20%s,\x20%s','error','DeskAccount,\x20%s,\x20%s','message','catch','status','json','count','offset','limit','set','apply','save','update','end','stack','name','index','map','DeskAccount','rawAttributes','type','model','keys','query','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','options','includeAll','include','show','params','find','create','body','DeskConfiguration','getConfigurations','findOne','AccountId','Subjects','Descriptions','getDescriptions','channel','DeskField','getFields','priority','remoteUri','username','password','consumerKey','token','tokenSecret','slice','substring','lastIndexOf','%s/custom_fields','application/json','authType','headers','Authorization','format','Basic\x20%s','%s:%s','toString','base64','_embedded','entries','label','getFields,\x20%s,\x20%s,\x20%s'];(function(_0x59e862,_0x477bf2){var _0x1a25ee=function(_0xc61e64){while(--_0xc61e64){_0x59e862['push'](_0x59e862['shift']());}};_0x1a25ee(++_0x477bf2);}(_0xd0c5,0xe8));var _0x5d0c=function(_0x893a9d,_0xda527f){_0x893a9d=_0x893a9d-0x0;var _0x50c299=_0xd0c5[_0x893a9d];return _0x50c299;};'use strict';var pdf=require(_0x5d0c('0x0'));var emlformat=require(_0x5d0c('0x1'));var rimraf=require(_0x5d0c('0x2'));var zipdir=require(_0x5d0c('0x3'));var jsonpatch=require(_0x5d0c('0x4'));var rp=require(_0x5d0c('0x5'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0x5d0c('0x6'));var util=require(_0x5d0c('0x7'));var path=require(_0x5d0c('0x8'));var sox=require('sox');var csv=require(_0x5d0c('0x9'));var ejs=require(_0x5d0c('0xa'));var fs=require('fs');var _=require(_0x5d0c('0xb'));var squel=require(_0x5d0c('0xc'));var crypto=require(_0x5d0c('0xd'));var jsforce=require(_0x5d0c('0xe'));var deskjs=require(_0x5d0c('0xf'));var toCsv=require('to-csv');var querystring=require(_0x5d0c('0x10'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0x5d0c('0x11'));var qs=require(_0x5d0c('0x12'));var as=require(_0x5d0c('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x5d0c('0x14'))(_0x5d0c('0x15'));var utils=require('../../config/utils');var config=require('../../config/environment');var db=require(_0x5d0c('0x16'))['db'];var integrations=require(_0x5d0c('0x17'));var jayson=require(_0x5d0c('0x18'));var client=jayson['client'][_0x5d0c('0x19')]({'port':0x232a});function checkPasswordPattern(_0x74a940,_0x1794ba,_0x5d2ea3){if(_0x5d2ea3){var _0x3d2dbf=new RegExp(/(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[?!@#\$%\^&\*~\-_=+[{\]\}])(?=.{8,})/);if(_0x3d2dbf[_0x5d0c('0x1a')](_0x1794ba)){return _0x74a940;}else{throw new db['Sequelize'][(_0x5d0c('0x1b'))](_0x5d0c('0x1c'));}}else{return _0x74a940;}}function respondWithRpcPromise(_0x483c29,_0x35ffb2,_0x70a0fc,_0x51dcea){return new BPromise(function(_0x245c65,_0x14f571){var _0x1f25ca=_0x51dcea||client;return _0x1f25ca['request'](_0x483c29,_0x70a0fc)[_0x5d0c('0x1d')](function(_0x2d07d9){logger[_0x5d0c('0x1e')]('DeskAccount,\x20%s,\x20%s',_0x35ffb2,_0x5d0c('0x1f'));logger[_0x5d0c('0x20')](_0x5d0c('0x21'),_0x35ffb2,_0x5d0c('0x1f'),JSON['stringify'](_0x2d07d9));if(_0x2d07d9[_0x5d0c('0x22')]){if(_0x2d07d9['error']['code']===0x1f4){logger[_0x5d0c('0x22')](_0x5d0c('0x23'),_0x35ffb2,_0x2d07d9[_0x5d0c('0x22')][_0x5d0c('0x24')]);return _0x14f571(_0x2d07d9[_0x5d0c('0x22')][_0x5d0c('0x24')]);}logger[_0x5d0c('0x22')]('DeskAccount,\x20%s,\x20%s',_0x35ffb2,_0x2d07d9[_0x5d0c('0x22')][_0x5d0c('0x24')]);return _0x245c65(_0x2d07d9[_0x5d0c('0x22')][_0x5d0c('0x24')]);}else{logger[_0x5d0c('0x1e')](_0x5d0c('0x23'),_0x35ffb2,_0x5d0c('0x1f'));_0x245c65(_0x2d07d9['result'][_0x5d0c('0x24')]);}})[_0x5d0c('0x25')](function(_0x1307c5){logger[_0x5d0c('0x22')](_0x5d0c('0x23'),_0x35ffb2,_0x1307c5);_0x14f571(_0x1307c5);});});}function respondWithStatusCode(_0x59f409,_0x5f8c6d){_0x5f8c6d=_0x5f8c6d||0xcc;return function(_0x3c1219){if(_0x3c1219){return _0x59f409['sendStatus'](_0x5f8c6d);}return _0x59f409[_0x5d0c('0x26')](_0x5f8c6d)['end']();};}function respondWithResult(_0x1ba6b1,_0x1c4253){_0x1c4253=_0x1c4253||0xc8;return function(_0x4883ec){if(_0x4883ec){return _0x1ba6b1[_0x5d0c('0x26')](_0x1c4253)[_0x5d0c('0x27')](_0x4883ec);}};}function respondWithFilteredResult(_0x34cded,_0x35b51c){return function(_0x3f12b4){if(_0x3f12b4){var _0x49cf97=_0x3f12b4[_0x5d0c('0x28')],_0x16eeaa=_0x35b51c[_0x5d0c('0x29')],_0x4e51dd=_0x35b51c['offset']+_0x35b51c[_0x5d0c('0x2a')],_0x1e8430;if(_0x4e51dd>=_0x49cf97){_0x4e51dd=_0x49cf97;_0x1e8430=0xc8;}else{_0x1e8430=0xce;}_0x34cded[_0x5d0c('0x26')](_0x1e8430);return _0x34cded[_0x5d0c('0x2b')]('Content-Range',_0x16eeaa+'-'+_0x4e51dd+'/'+_0x49cf97)[_0x5d0c('0x27')](_0x3f12b4);}return null;};}function patchUpdates(_0x5ad884){return function(_0x21c926){try{jsonpatch[_0x5d0c('0x2c')](_0x21c926,_0x5ad884,!![]);}catch(_0x6ac849){return BPromise['reject'](_0x6ac849);}return _0x21c926[_0x5d0c('0x2d')]();};}function saveUpdates(_0x300a41,_0x2af781){return function(_0x44fb48){if(_0x44fb48){return _0x44fb48[_0x5d0c('0x2e')](_0x300a41)[_0x5d0c('0x1d')](function(_0x1bfa1c){return _0x1bfa1c;});}return null;};}function removeEntity(_0x35411f,_0x366b5a){return function(_0x231edd){if(_0x231edd){return _0x231edd['destroy']()['then'](function(){_0x35411f[_0x5d0c('0x26')](0xcc)[_0x5d0c('0x2f')]();});}};}function handleEntityNotFound(_0x3d7aca,_0x522785){return function(_0x5a2c23){if(!_0x5a2c23){_0x3d7aca['sendStatus'](0x194);}return _0x5a2c23;};}function handleError(_0x1c4679,_0x3190bf){_0x3190bf=_0x3190bf||0x1f4;return function(_0x43cf36){logger[_0x5d0c('0x22')](_0x43cf36[_0x5d0c('0x30')]);if(_0x43cf36[_0x5d0c('0x31')]){delete _0x43cf36['name'];}_0x1c4679[_0x5d0c('0x26')](_0x3190bf)['send'](_0x43cf36);};}exports[_0x5d0c('0x32')]=function(_0x5ac986,_0xff88cf){var _0x9dfa80={},_0x224616={},_0x1916c5={'count':0x0,'rows':[]};var _0x534fdb=_[_0x5d0c('0x33')](db[_0x5d0c('0x34')][_0x5d0c('0x35')],function(_0x10b6c9){return{'name':_0x10b6c9['fieldName'],'type':_0x10b6c9[_0x5d0c('0x36')]['key']};});_0x224616[_0x5d0c('0x37')]=_[_0x5d0c('0x33')](_0x534fdb,_0x5d0c('0x31'));_0x224616['query']=_[_0x5d0c('0x38')](_0x5ac986[_0x5d0c('0x39')]);_0x224616[_0x5d0c('0x3a')]=_[_0x5d0c('0x3b')](_0x224616[_0x5d0c('0x37')],_0x224616[_0x5d0c('0x39')]);_0x9dfa80['attributes']=_[_0x5d0c('0x3b')](_0x224616[_0x5d0c('0x37')],qs[_0x5d0c('0x3c')](_0x5ac986[_0x5d0c('0x39')]['fields']));_0x9dfa80[_0x5d0c('0x3d')]=_0x9dfa80[_0x5d0c('0x3d')][_0x5d0c('0x3e')]?_0x9dfa80[_0x5d0c('0x3d')]:_0x224616[_0x5d0c('0x37')];if(!_0x5ac986[_0x5d0c('0x39')][_0x5d0c('0x3f')](_0x5d0c('0x40'))){_0x9dfa80[_0x5d0c('0x2a')]=qs[_0x5d0c('0x2a')](_0x5ac986[_0x5d0c('0x39')][_0x5d0c('0x2a')]);_0x9dfa80[_0x5d0c('0x29')]=qs['offset'](_0x5ac986[_0x5d0c('0x39')][_0x5d0c('0x29')]);}_0x9dfa80[_0x5d0c('0x41')]=qs[_0x5d0c('0x42')](_0x5ac986[_0x5d0c('0x39')][_0x5d0c('0x42')]);_0x9dfa80[_0x5d0c('0x43')]=qs['filters'](_[_0x5d0c('0x44')](_0x5ac986['query'],_0x224616[_0x5d0c('0x3a')]),_0x534fdb);if(_0x5ac986['query'][_0x5d0c('0x45')]){_0x9dfa80[_0x5d0c('0x43')]=_['merge'](_0x9dfa80[_0x5d0c('0x43')],{'$or':_[_0x5d0c('0x33')](_0x534fdb,function(_0x180570){if(_0x180570[_0x5d0c('0x36')]!=='VIRTUAL'){var _0x175d88={};_0x175d88[_0x180570[_0x5d0c('0x31')]]={'$like':'%'+_0x5ac986[_0x5d0c('0x39')][_0x5d0c('0x45')]+'%'};return _0x175d88;}})});}_0x9dfa80=_[_0x5d0c('0x46')]({},_0x9dfa80,_0x5ac986[_0x5d0c('0x47')]);var _0x35952f={'where':_0x9dfa80['where']};return db[_0x5d0c('0x34')][_0x5d0c('0x28')](_0x35952f)[_0x5d0c('0x1d')](function(_0x4d2029){_0x1916c5[_0x5d0c('0x28')]=_0x4d2029;if(_0x5ac986[_0x5d0c('0x39')][_0x5d0c('0x48')]){_0x9dfa80[_0x5d0c('0x49')]=[{'all':!![]}];}return db[_0x5d0c('0x34')]['findAll'](_0x9dfa80);})[_0x5d0c('0x1d')](function(_0x39e15e){_0x1916c5['rows']=_0x39e15e;return _0x1916c5;})[_0x5d0c('0x1d')](respondWithFilteredResult(_0xff88cf,_0x9dfa80))['catch'](handleError(_0xff88cf,null));};exports[_0x5d0c('0x4a')]=function(_0x4d1d83,_0x652be3){var _0x1c73fa={'raw':![],'where':{'id':_0x4d1d83[_0x5d0c('0x4b')]['id']}},_0x4fc782={};_0x4fc782[_0x5d0c('0x37')]=_[_0x5d0c('0x38')](db[_0x5d0c('0x34')][_0x5d0c('0x35')]);_0x4fc782[_0x5d0c('0x39')]=_[_0x5d0c('0x38')](_0x4d1d83['query']);_0x4fc782[_0x5d0c('0x3a')]=_[_0x5d0c('0x3b')](_0x4fc782['model'],_0x4fc782[_0x5d0c('0x39')]);_0x1c73fa['attributes']=_[_0x5d0c('0x3b')](_0x4fc782[_0x5d0c('0x37')],qs[_0x5d0c('0x3c')](_0x4d1d83[_0x5d0c('0x39')][_0x5d0c('0x3c')]));_0x1c73fa[_0x5d0c('0x3d')]=_0x1c73fa[_0x5d0c('0x3d')]['length']?_0x1c73fa['attributes']:_0x4fc782['model'];if(_0x4d1d83[_0x5d0c('0x39')]['includeAll']){_0x1c73fa['include']=[{'all':!![]}];}_0x1c73fa=_['merge']({},_0x1c73fa,_0x4d1d83['options']);return db[_0x5d0c('0x34')][_0x5d0c('0x4c')](_0x1c73fa)[_0x5d0c('0x1d')](handleEntityNotFound(_0x652be3,null))[_0x5d0c('0x1d')](respondWithResult(_0x652be3,null))[_0x5d0c('0x25')](handleError(_0x652be3,null));};exports[_0x5d0c('0x4d')]=function(_0x488948,_0x4194f3){return db[_0x5d0c('0x34')][_0x5d0c('0x4d')](_0x488948['body'],{})[_0x5d0c('0x1d')](respondWithResult(_0x4194f3,0xc9))[_0x5d0c('0x25')](handleError(_0x4194f3,null));};exports[_0x5d0c('0x2e')]=function(_0xc35b0b,_0x28390c){if(_0xc35b0b[_0x5d0c('0x4e')]['id']){delete _0xc35b0b['body']['id'];}return db[_0x5d0c('0x34')][_0x5d0c('0x4c')]({'where':{'id':_0xc35b0b['params']['id']}})['then'](handleEntityNotFound(_0x28390c,null))['then'](saveUpdates(_0xc35b0b[_0x5d0c('0x4e')],null))[_0x5d0c('0x1d')](respondWithResult(_0x28390c,null))[_0x5d0c('0x25')](handleError(_0x28390c,null));};exports['destroy']=function(_0x545ab7,_0x3cf6fa){return db[_0x5d0c('0x34')][_0x5d0c('0x4c')]({'where':{'id':_0x545ab7[_0x5d0c('0x4b')]['id']}})[_0x5d0c('0x1d')](handleEntityNotFound(_0x3cf6fa,null))[_0x5d0c('0x1d')](removeEntity(_0x3cf6fa,null))[_0x5d0c('0x25')](handleError(_0x3cf6fa,null));};exports['getConfigurations']=function(_0x6178ac,_0x415297,_0x367be0){var _0x5e7d15={};var _0x1cad69={};var _0x1eeacc;var _0x4d549c;return db[_0x5d0c('0x34')]['findOne']({'where':{'id':_0x6178ac[_0x5d0c('0x4b')]['id']}})[_0x5d0c('0x1d')](handleEntityNotFound(_0x415297,null))[_0x5d0c('0x1d')](function(_0x3da8c7){if(_0x3da8c7){_0x1eeacc=_0x3da8c7;_0x1cad69[_0x5d0c('0x37')]=_[_0x5d0c('0x38')](db[_0x5d0c('0x4f')]['rawAttributes']);_0x1cad69[_0x5d0c('0x39')]=_[_0x5d0c('0x38')](_0x6178ac[_0x5d0c('0x39')]);_0x1cad69[_0x5d0c('0x3a')]=_[_0x5d0c('0x3b')](_0x1cad69['model'],_0x1cad69[_0x5d0c('0x39')]);_0x5e7d15['attributes']=_[_0x5d0c('0x3b')](_0x1cad69['model'],qs[_0x5d0c('0x3c')](_0x6178ac['query'][_0x5d0c('0x3c')]));_0x5e7d15[_0x5d0c('0x3d')]=_0x5e7d15[_0x5d0c('0x3d')][_0x5d0c('0x3e')]?_0x5e7d15[_0x5d0c('0x3d')]:_0x1cad69[_0x5d0c('0x37')];_0x5e7d15[_0x5d0c('0x41')]=qs[_0x5d0c('0x42')](_0x6178ac[_0x5d0c('0x39')][_0x5d0c('0x42')]);_0x5e7d15[_0x5d0c('0x43')]=qs[_0x5d0c('0x3a')](_[_0x5d0c('0x44')](_0x6178ac[_0x5d0c('0x39')],_0x1cad69[_0x5d0c('0x3a')]));if(_0x6178ac['query'][_0x5d0c('0x45')]){_0x5e7d15[_0x5d0c('0x43')]=_[_0x5d0c('0x46')](_0x5e7d15[_0x5d0c('0x43')],{'$or':_['map'](_0x5e7d15[_0x5d0c('0x3d')],function(_0x3f88aa){var _0x771c4a={};_0x771c4a[_0x3f88aa]={'$like':'%'+_0x6178ac[_0x5d0c('0x39')][_0x5d0c('0x45')]+'%'};return _0x771c4a;})});}_0x5e7d15=_[_0x5d0c('0x46')]({},_0x5e7d15,_0x6178ac[_0x5d0c('0x47')]);return _0x1eeacc[_0x5d0c('0x50')](_0x5e7d15);}})[_0x5d0c('0x1d')](function(_0x45902f){if(_0x45902f){_0x4d549c=_0x45902f[_0x5d0c('0x3e')];if(!_0x6178ac[_0x5d0c('0x39')][_0x5d0c('0x3f')]('nolimit')){_0x5e7d15[_0x5d0c('0x2a')]=qs[_0x5d0c('0x2a')](_0x6178ac[_0x5d0c('0x39')]['limit']);_0x5e7d15[_0x5d0c('0x29')]=qs['offset'](_0x6178ac[_0x5d0c('0x39')][_0x5d0c('0x29')]);}return _0x1eeacc['getConfigurations'](_0x5e7d15);}})[_0x5d0c('0x1d')](function(_0x2fd912){if(_0x2fd912){return _0x2fd912?{'count':_0x4d549c,'rows':_0x2fd912}:null;}})[_0x5d0c('0x1d')](respondWithResult(_0x415297,null))['catch'](handleError(_0x415297,null));};exports['addConfiguration']=function(_0x436291,_0x5e3641,_0x3be270){if(_0x436291[_0x5d0c('0x4e')]['id']){delete _0x436291['body']['id'];}return db['DeskAccount'][_0x5d0c('0x51')]({'where':{'id':_0x436291[_0x5d0c('0x4b')]['id']}})[_0x5d0c('0x1d')](handleEntityNotFound(_0x5e3641,null))[_0x5d0c('0x1d')](function(_0x340ec3){if(_0x340ec3){_0x436291[_0x5d0c('0x4e')][_0x5d0c('0x52')]=_0x340ec3['id'];_0x436291[_0x5d0c('0x4e')][_0x5d0c('0x53')]=integrations['getSubjects'](_0x436291[_0x5d0c('0x4e')]['channel'],_0x436291[_0x5d0c('0x4e')][_0x5d0c('0x36')]);_0x436291[_0x5d0c('0x4e')][_0x5d0c('0x54')]=integrations[_0x5d0c('0x55')](_0x436291[_0x5d0c('0x4e')][_0x5d0c('0x56')],_0x436291['body'][_0x5d0c('0x36')]);return db[_0x5d0c('0x4f')]['create'](_0x436291[_0x5d0c('0x4e')],{'include':[{'model':db[_0x5d0c('0x57')],'as':_0x5d0c('0x53')},{'model':db[_0x5d0c('0x57')],'as':_0x5d0c('0x54')}]});}return null;})[_0x5d0c('0x1d')](respondWithResult(_0x5e3641,null))[_0x5d0c('0x25')](handleError(_0x5e3641,null));};exports[_0x5d0c('0x58')]=function(_0x1517f0,_0x3b9d15,_0x39d690){var _0xb48688=[{'name':_0x5d0c('0x59'),'label':_0x5d0c('0x59'),'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 _0x6d149c='';return db[_0x5d0c('0x34')][_0x5d0c('0x51')]({'where':{'id':_0x1517f0[_0x5d0c('0x4b')]['id']},'attributes':['id',_0x5d0c('0x5a'),'authType',_0x5d0c('0x5b'),_0x5d0c('0x5c'),_0x5d0c('0x5d'),'consumerSecret',_0x5d0c('0x5e'),_0x5d0c('0x5f')]})[_0x5d0c('0x1d')](handleEntityNotFound(_0x3b9d15,null))[_0x5d0c('0x1d')](function(_0xb49dd5){if(_0xb49dd5){_0x6d149c=_0xb49dd5['remoteUri'];var _0x2f1132=_0x6d149c[_0x5d0c('0x60')](-0x1);if(_0x2f1132==='/'){_0x6d149c=_0x6d149c[_0x5d0c('0x61')](0x0,_0x6d149c[_0x5d0c('0x62')](_0x2f1132));}var _0x1e30c5={'method':'GET','uri':util['format'](_0x5d0c('0x63'),_0x6d149c),'headers':{'Content-Type':_0x5d0c('0x64'),'Accept':'application/json'},'json':!![]};if(_0xb49dd5[_0x5d0c('0x65')]==='basic'){_0x1e30c5[_0x5d0c('0x66')][_0x5d0c('0x67')]=util[_0x5d0c('0x68')](_0x5d0c('0x69'),new Buffer(util[_0x5d0c('0x68')](_0x5d0c('0x6a'),_0xb49dd5[_0x5d0c('0x5b')],_0xb49dd5[_0x5d0c('0x5c')]))[_0x5d0c('0x6b')](_0x5d0c('0x6c')));}return rp(_0x1e30c5)[_0x5d0c('0x1d')](function(_0x3cc351){return _0xb48688['concat'](_[_0x5d0c('0x33')](_0x3cc351[_0x5d0c('0x6d')][_0x5d0c('0x6e')],function(_0x184157){return{'id':_0x184157[_0x5d0c('0x31')],'name':_0x184157[_0x5d0c('0x31')],'type':_0x184157['type'],'active':_0x184157['active'],'label':_0x184157[_0x5d0c('0x6f')],'custom':!![]};}));});}})[_0x5d0c('0x1d')](function(_0x236542){return{'count':_0x236542[_0x5d0c('0x3e')],'rows':_0x236542};})[_0x5d0c('0x1d')](respondWithResult(_0x3b9d15,null))[_0x5d0c('0x25')](function(_0x478ac5){var _0xc60b1=_0x1517f0[_0x5d0c('0x39')][_0x5d0c('0x1a')]?0x1f4:_0x478ac5['statusCode']||0x1f4;logger[_0x5d0c('0x22')](_0x5d0c('0x70'),'getFields',_0xc60b1,JSON['stringify'](_0x478ac5));delete _0x478ac5[_0x5d0c('0x31')];if(_0xc60b1===0x191){_0xc60b1=0x190;}_0x3b9d15[_0x5d0c('0x26')](_0xc60b1)[_0x5d0c('0x71')](_0x1517f0['query'][_0x5d0c('0x1a')]?{'message':'Wrong\x20credentials','statusCode':_0x478ac5[_0x5d0c('0x72')]}:_0x478ac5);});};
\ No newline at end of file
+var _0xadc0=['save','update','then','destroy','name','send','index','rawAttributes','fieldName','type','key','query','keys','filters','intersection','model','fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','map','VIRTUAL','include','DeskAccount','rows','catch','show','params','options','find','create','body','getConfigurations','findOne','DeskConfiguration','addConfiguration','AccountId','Subjects','getSubjects','channel','DeskField','getFields','priority','remoteUri','authType','username','consumerKey','consumerSecret','token','tokenSecret','substring','lastIndexOf','format','application/json','basic','headers','Basic\x20%s','password','toString','base64','concat','_embedded','active','test','error','getFields,\x20%s,\x20%s,\x20%s','stringify','Wrong\x20credentials','eml-format','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','sox','ejs','fs-extra','lodash','squel','crypto','jsforce','to-csv','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../components/integrations/configuration','sendStatus','status','json','undefined','limit','count','offset','Content-Range','apply'];(function(_0x25a386,_0x4acd61){var _0x4d3d47=function(_0x2e4efb){while(--_0x2e4efb){_0x25a386['push'](_0x25a386['shift']());}};_0x4d3d47(++_0x4acd61);}(_0xadc0,0x125));var _0x0adc=function(_0x4e9b99,_0x124be9){_0x4e9b99=_0x4e9b99-0x0;var _0x2c63dd=_0xadc0[_0x4e9b99];return _0x2c63dd;};'use strict';var emlformat=require(_0x0adc('0x0'));var rimraf=require(_0x0adc('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x0adc('0x2'));var rp=require(_0x0adc('0x3'));var moment=require(_0x0adc('0x4'));var BPromise=require(_0x0adc('0x5'));var Mustache=require(_0x0adc('0x6'));var util=require('util');var path=require('path');var sox=require(_0x0adc('0x7'));var csv=require('to-csv');var ejs=require(_0x0adc('0x8'));var fs=require('fs');var fs_extra=require(_0x0adc('0x9'));var _=require(_0x0adc('0xa'));var squel=require(_0x0adc('0xb'));var crypto=require(_0x0adc('0xc'));var jsforce=require(_0x0adc('0xd'));var deskjs=require('desk.js');var toCsv=require(_0x0adc('0xe'));var querystring=require('querystring');var Papa=require(_0x0adc('0xf'));var Redis=require(_0x0adc('0x10'));var authService=require(_0x0adc('0x11'));var qs=require(_0x0adc('0x12'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x0adc('0x13'));var logger=require(_0x0adc('0x14'))('api');var utils=require(_0x0adc('0x15'));var config=require(_0x0adc('0x16'));var licenseUtil=require(_0x0adc('0x17'));var db=require('../../mysqldb')['db'];var integrations=require(_0x0adc('0x18'));function respondWithStatusCode(_0x233dda,_0x3d09eb){_0x3d09eb=_0x3d09eb||0xcc;return function(_0x12c998){if(_0x12c998){return _0x233dda[_0x0adc('0x19')](_0x3d09eb);}return _0x233dda[_0x0adc('0x1a')](_0x3d09eb)['end']();};}function respondWithResult(_0x262448,_0x1a669b){_0x1a669b=_0x1a669b||0xc8;return function(_0xea8097){if(_0xea8097){return _0x262448[_0x0adc('0x1a')](_0x1a669b)[_0x0adc('0x1b')](_0xea8097);}};}function respondWithFilteredResult(_0x383a46,_0x25f780){return function(_0x580dc9){if(_0x580dc9){var _0x425126=typeof _0x25f780['offset']===_0x0adc('0x1c')&&typeof _0x25f780[_0x0adc('0x1d')]===_0x0adc('0x1c');var _0x4f566=_0x580dc9[_0x0adc('0x1e')];var _0x4198f5=_0x425126?0x0:_0x25f780[_0x0adc('0x1f')];var _0x2cfd03=_0x425126?_0x580dc9[_0x0adc('0x1e')]:_0x25f780[_0x0adc('0x1f')]+_0x25f780[_0x0adc('0x1d')];var _0x386bba;if(_0x2cfd03>=_0x4f566){_0x2cfd03=_0x4f566;_0x386bba=0xc8;}else{_0x386bba=0xce;}_0x383a46[_0x0adc('0x1a')](_0x386bba);return _0x383a46['set'](_0x0adc('0x20'),_0x4198f5+'-'+_0x2cfd03+'/'+_0x4f566)['json'](_0x580dc9);}return null;};}function patchUpdates(_0x244360){return function(_0x98318c){try{jsonpatch[_0x0adc('0x21')](_0x98318c,_0x244360,!![]);}catch(_0x4cbded){return BPromise['reject'](_0x4cbded);}return _0x98318c[_0x0adc('0x22')]();};}function saveUpdates(_0x30e75d,_0x47ced2){return function(_0x2d373b){if(_0x2d373b){return _0x2d373b[_0x0adc('0x23')](_0x30e75d)[_0x0adc('0x24')](function(_0xd2113a){return _0xd2113a;});}return null;};}function removeEntity(_0x27a7f3,_0x5e4692){return function(_0x1e0581){if(_0x1e0581){return _0x1e0581[_0x0adc('0x25')]()['then'](function(){_0x27a7f3['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x478263,_0x3f0c33){return function(_0x4f4c5a){if(!_0x4f4c5a){_0x478263[_0x0adc('0x19')](0x194);}return _0x4f4c5a;};}function handleError(_0x2715d5,_0x3d74fd){_0x3d74fd=_0x3d74fd||0x1f4;return function(_0x4beb08){logger['error'](_0x4beb08['stack']);if(_0x4beb08[_0x0adc('0x26')]){delete _0x4beb08[_0x0adc('0x26')];}_0x2715d5[_0x0adc('0x1a')](_0x3d74fd)[_0x0adc('0x27')](_0x4beb08);};}exports[_0x0adc('0x28')]=function(_0x1bac44,_0x331689){var _0x41d856={},_0xf74b03={},_0x12fa08={'count':0x0,'rows':[]};var _0x51cdec=_['map'](db['DeskAccount'][_0x0adc('0x29')],function(_0x16e86f){return{'name':_0x16e86f[_0x0adc('0x2a')],'type':_0x16e86f[_0x0adc('0x2b')][_0x0adc('0x2c')]};});_0xf74b03['model']=_['map'](_0x51cdec,_0x0adc('0x26'));_0xf74b03[_0x0adc('0x2d')]=_[_0x0adc('0x2e')](_0x1bac44[_0x0adc('0x2d')]);_0xf74b03[_0x0adc('0x2f')]=_[_0x0adc('0x30')](_0xf74b03['model'],_0xf74b03['query']);_0x41d856['attributes']=_['intersection'](_0xf74b03[_0x0adc('0x31')],qs[_0x0adc('0x32')](_0x1bac44[_0x0adc('0x2d')][_0x0adc('0x32')]));_0x41d856[_0x0adc('0x33')]=_0x41d856[_0x0adc('0x33')][_0x0adc('0x34')]?_0x41d856[_0x0adc('0x33')]:_0xf74b03['model'];if(!_0x1bac44[_0x0adc('0x2d')][_0x0adc('0x35')](_0x0adc('0x36'))){_0x41d856[_0x0adc('0x1d')]=qs[_0x0adc('0x1d')](_0x1bac44[_0x0adc('0x2d')][_0x0adc('0x1d')]);_0x41d856[_0x0adc('0x1f')]=qs[_0x0adc('0x1f')](_0x1bac44[_0x0adc('0x2d')][_0x0adc('0x1f')]);}_0x41d856[_0x0adc('0x37')]=qs[_0x0adc('0x38')](_0x1bac44['query'][_0x0adc('0x38')]);_0x41d856[_0x0adc('0x39')]=qs['filters'](_[_0x0adc('0x3a')](_0x1bac44[_0x0adc('0x2d')],_0xf74b03['filters']),_0x51cdec);if(_0x1bac44['query'][_0x0adc('0x3b')]){_0x41d856[_0x0adc('0x39')]=_[_0x0adc('0x3c')](_0x41d856[_0x0adc('0x39')],{'$or':_[_0x0adc('0x3d')](_0x51cdec,function(_0xe65d38){if(_0xe65d38[_0x0adc('0x2b')]!==_0x0adc('0x3e')){var _0x398a02={};_0x398a02[_0xe65d38[_0x0adc('0x26')]]={'$like':'%'+_0x1bac44[_0x0adc('0x2d')][_0x0adc('0x3b')]+'%'};return _0x398a02;}})});}_0x41d856=_['merge']({},_0x41d856,_0x1bac44['options']);var _0x1f1c69={'where':_0x41d856[_0x0adc('0x39')]};return db['DeskAccount'][_0x0adc('0x1e')](_0x1f1c69)[_0x0adc('0x24')](function(_0x127dec){_0x12fa08[_0x0adc('0x1e')]=_0x127dec;if(_0x1bac44[_0x0adc('0x2d')]['includeAll']){_0x41d856[_0x0adc('0x3f')]=[{'all':!![]}];}return db[_0x0adc('0x40')]['findAll'](_0x41d856);})['then'](function(_0x1476ef){_0x12fa08[_0x0adc('0x41')]=_0x1476ef;return _0x12fa08;})[_0x0adc('0x24')](respondWithFilteredResult(_0x331689,_0x41d856))[_0x0adc('0x42')](handleError(_0x331689,null));};exports[_0x0adc('0x43')]=function(_0x1a2365,_0x3dab35){var _0x27400f={'raw':![],'where':{'id':_0x1a2365[_0x0adc('0x44')]['id']}},_0x97ea4={};_0x97ea4[_0x0adc('0x31')]=_[_0x0adc('0x2e')](db[_0x0adc('0x40')][_0x0adc('0x29')]);_0x97ea4[_0x0adc('0x2d')]=_[_0x0adc('0x2e')](_0x1a2365[_0x0adc('0x2d')]);_0x97ea4[_0x0adc('0x2f')]=_[_0x0adc('0x30')](_0x97ea4['model'],_0x97ea4['query']);_0x27400f[_0x0adc('0x33')]=_[_0x0adc('0x30')](_0x97ea4[_0x0adc('0x31')],qs[_0x0adc('0x32')](_0x1a2365[_0x0adc('0x2d')]['fields']));_0x27400f['attributes']=_0x27400f[_0x0adc('0x33')]['length']?_0x27400f[_0x0adc('0x33')]:_0x97ea4['model'];if(_0x1a2365[_0x0adc('0x2d')]['includeAll']){_0x27400f[_0x0adc('0x3f')]=[{'all':!![]}];}_0x27400f=_[_0x0adc('0x3c')]({},_0x27400f,_0x1a2365[_0x0adc('0x45')]);return db[_0x0adc('0x40')][_0x0adc('0x46')](_0x27400f)['then'](handleEntityNotFound(_0x3dab35,null))[_0x0adc('0x24')](respondWithResult(_0x3dab35,null))[_0x0adc('0x42')](handleError(_0x3dab35,null));};exports[_0x0adc('0x47')]=function(_0x345dc7,_0x17347a){return db[_0x0adc('0x40')]['create'](_0x345dc7[_0x0adc('0x48')],{})[_0x0adc('0x24')](respondWithResult(_0x17347a,0xc9))[_0x0adc('0x42')](handleError(_0x17347a,null));};exports['update']=function(_0x55b9d1,_0x2ed30b){if(_0x55b9d1[_0x0adc('0x48')]['id']){delete _0x55b9d1['body']['id'];}return db[_0x0adc('0x40')][_0x0adc('0x46')]({'where':{'id':_0x55b9d1[_0x0adc('0x44')]['id']}})['then'](handleEntityNotFound(_0x2ed30b,null))[_0x0adc('0x24')](saveUpdates(_0x55b9d1['body'],null))[_0x0adc('0x24')](respondWithResult(_0x2ed30b,null))[_0x0adc('0x42')](handleError(_0x2ed30b,null));};exports[_0x0adc('0x25')]=function(_0x164555,_0x3fc14c){return db[_0x0adc('0x40')][_0x0adc('0x46')]({'where':{'id':_0x164555[_0x0adc('0x44')]['id']}})[_0x0adc('0x24')](handleEntityNotFound(_0x3fc14c,null))[_0x0adc('0x24')](removeEntity(_0x3fc14c,null))[_0x0adc('0x42')](handleError(_0x3fc14c,null));};exports[_0x0adc('0x49')]=function(_0x43e4dd,_0x47083e,_0x41a5b3){var _0x5256c3={};var _0x1da100={};var _0x4c237e;var _0x3ed42d;return db['DeskAccount'][_0x0adc('0x4a')]({'where':{'id':_0x43e4dd['params']['id']}})[_0x0adc('0x24')](handleEntityNotFound(_0x47083e,null))[_0x0adc('0x24')](function(_0x10227d){if(_0x10227d){_0x4c237e=_0x10227d;_0x1da100[_0x0adc('0x31')]=_[_0x0adc('0x2e')](db[_0x0adc('0x4b')][_0x0adc('0x29')]);_0x1da100[_0x0adc('0x2d')]=_[_0x0adc('0x2e')](_0x43e4dd['query']);_0x1da100[_0x0adc('0x2f')]=_[_0x0adc('0x30')](_0x1da100[_0x0adc('0x31')],_0x1da100[_0x0adc('0x2d')]);_0x5256c3[_0x0adc('0x33')]=_[_0x0adc('0x30')](_0x1da100[_0x0adc('0x31')],qs['fields'](_0x43e4dd['query'][_0x0adc('0x32')]));_0x5256c3['attributes']=_0x5256c3['attributes'][_0x0adc('0x34')]?_0x5256c3['attributes']:_0x1da100[_0x0adc('0x31')];_0x5256c3[_0x0adc('0x37')]=qs[_0x0adc('0x38')](_0x43e4dd[_0x0adc('0x2d')][_0x0adc('0x38')]);_0x5256c3['where']=qs[_0x0adc('0x2f')](_['pick'](_0x43e4dd['query'],_0x1da100[_0x0adc('0x2f')]));if(_0x43e4dd['query'][_0x0adc('0x3b')]){_0x5256c3[_0x0adc('0x39')]=_[_0x0adc('0x3c')](_0x5256c3['where'],{'$or':_[_0x0adc('0x3d')](_0x5256c3['attributes'],function(_0x4f888e){var _0x33756c={};_0x33756c[_0x4f888e]={'$like':'%'+_0x43e4dd[_0x0adc('0x2d')][_0x0adc('0x3b')]+'%'};return _0x33756c;})});}_0x5256c3=_[_0x0adc('0x3c')]({},_0x5256c3,_0x43e4dd[_0x0adc('0x45')]);return _0x4c237e[_0x0adc('0x49')](_0x5256c3);}})[_0x0adc('0x24')](function(_0x27619b){if(_0x27619b){_0x3ed42d=_0x27619b[_0x0adc('0x34')];if(!_0x43e4dd['query'][_0x0adc('0x35')](_0x0adc('0x36'))){_0x5256c3[_0x0adc('0x1d')]=qs[_0x0adc('0x1d')](_0x43e4dd['query']['limit']);_0x5256c3[_0x0adc('0x1f')]=qs[_0x0adc('0x1f')](_0x43e4dd[_0x0adc('0x2d')][_0x0adc('0x1f')]);}return _0x4c237e[_0x0adc('0x49')](_0x5256c3);}})[_0x0adc('0x24')](function(_0x2dac70){if(_0x2dac70){return _0x2dac70?{'count':_0x3ed42d,'rows':_0x2dac70}:null;}})['then'](respondWithResult(_0x47083e,null))[_0x0adc('0x42')](handleError(_0x47083e,null));};exports[_0x0adc('0x4c')]=function(_0x4859c7,_0x215847,_0x1323c1){if(_0x4859c7[_0x0adc('0x48')]['id']){delete _0x4859c7['body']['id'];}return db['DeskAccount']['findOne']({'where':{'id':_0x4859c7[_0x0adc('0x44')]['id']}})[_0x0adc('0x24')](handleEntityNotFound(_0x215847,null))[_0x0adc('0x24')](function(_0xe7fa9f){if(_0xe7fa9f){_0x4859c7[_0x0adc('0x48')][_0x0adc('0x4d')]=_0xe7fa9f['id'];_0x4859c7[_0x0adc('0x48')][_0x0adc('0x4e')]=integrations[_0x0adc('0x4f')](_0x4859c7[_0x0adc('0x48')]['channel'],_0x4859c7[_0x0adc('0x48')]['type']);_0x4859c7[_0x0adc('0x48')]['Descriptions']=integrations['getDescriptions'](_0x4859c7[_0x0adc('0x48')][_0x0adc('0x50')],_0x4859c7[_0x0adc('0x48')][_0x0adc('0x2b')]);return db[_0x0adc('0x4b')][_0x0adc('0x47')](_0x4859c7[_0x0adc('0x48')],{'include':[{'model':db[_0x0adc('0x51')],'as':_0x0adc('0x4e')},{'model':db[_0x0adc('0x51')],'as':'Descriptions'}]});}return null;})[_0x0adc('0x24')](respondWithResult(_0x215847,null))[_0x0adc('0x42')](handleError(_0x215847,null));};exports[_0x0adc('0x52')]=function(_0x1dfc11,_0x141304,_0x17fdc9){var _0x353823=[{'name':_0x0adc('0x53'),'label':'priority','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 _0x368120='';return db[_0x0adc('0x40')][_0x0adc('0x4a')]({'where':{'id':_0x1dfc11[_0x0adc('0x44')]['id']},'attributes':['id',_0x0adc('0x54'),_0x0adc('0x55'),_0x0adc('0x56'),'password',_0x0adc('0x57'),_0x0adc('0x58'),_0x0adc('0x59'),_0x0adc('0x5a')]})[_0x0adc('0x24')](handleEntityNotFound(_0x141304,null))[_0x0adc('0x24')](function(_0x48c597){if(_0x48c597){_0x368120=_0x48c597['remoteUri'];var _0x2ecc99=_0x368120['slice'](-0x1);if(_0x2ecc99==='/'){_0x368120=_0x368120[_0x0adc('0x5b')](0x0,_0x368120[_0x0adc('0x5c')](_0x2ecc99));}var _0x5ed466={'method':'GET','uri':util[_0x0adc('0x5d')]('%s/custom_fields',_0x368120),'headers':{'Content-Type':_0x0adc('0x5e'),'Accept':_0x0adc('0x5e')},'json':!![]};if(_0x48c597[_0x0adc('0x55')]===_0x0adc('0x5f')){_0x5ed466[_0x0adc('0x60')]['Authorization']=util[_0x0adc('0x5d')](_0x0adc('0x61'),new Buffer(util[_0x0adc('0x5d')]('%s:%s',_0x48c597['username'],_0x48c597[_0x0adc('0x62')]))[_0x0adc('0x63')](_0x0adc('0x64')));}return rp(_0x5ed466)[_0x0adc('0x24')](function(_0x365655){return _0x353823[_0x0adc('0x65')](_[_0x0adc('0x3d')](_0x365655[_0x0adc('0x66')]['entries'],function(_0x808483){return{'id':_0x808483[_0x0adc('0x26')],'name':_0x808483['name'],'type':_0x808483[_0x0adc('0x2b')],'active':_0x808483[_0x0adc('0x67')],'label':_0x808483['label'],'custom':!![]};}));});}})[_0x0adc('0x24')](function(_0x124a85){return{'count':_0x124a85[_0x0adc('0x34')],'rows':_0x124a85};})[_0x0adc('0x24')](respondWithResult(_0x141304,null))[_0x0adc('0x42')](function(_0x44a9af){var _0x4363e5=_0x1dfc11[_0x0adc('0x2d')][_0x0adc('0x68')]?0x1f4:_0x44a9af['statusCode']||0x1f4;logger[_0x0adc('0x69')](_0x0adc('0x6a'),_0x0adc('0x52'),_0x4363e5,JSON[_0x0adc('0x6b')](_0x44a9af));delete _0x44a9af[_0x0adc('0x26')];if(_0x4363e5===0x191){_0x4363e5=0x190;}_0x141304[_0x0adc('0x1a')](_0x4363e5)[_0x0adc('0x27')](_0x1dfc11[_0x0adc('0x2d')][_0x0adc('0x68')]?{'message':_0x0adc('0x6c'),'statusCode':_0x44a9af['statusCode']}:_0x44a9af);});};
\ No newline at end of file