Built motion from commit 3e059bc2.|2.5.32
[motion2.git] / server / api / intFreshdeskAccount / intFreshdeskAccount.controller.js
index 2b6bdcb..287af87 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x8f78=['index','map','FreshdeskAccount','rawAttributes','fieldName','type','key','model','keys','query','filters','attributes','intersection','fields','length','hasOwnProperty','sort','where','filter','VIRTUAL','merge','options','includeAll','include','findAll','catch','show','params','create','body','update','find','getConfigurations','order','nolimit','addConfiguration','findOne','Subjects','getSubjects','channel','Descriptions','getDescriptions','FreshdeskField','remoteUri','apiKey','substring','lastIndexOf','GET','format','%s/%s','api/v2/ticket_fields','Basic\x20%s','%s:X','toString','requester','subject','agent','description','priority','group','source','ticket_type','company','includes','custom_text','label','default','choices','capitalize','statusCode','getFields,\x20%s,\x20%s,\x20%s','getFields','send','Wrong\x20credentials','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','to-csv','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/environment','../../mysqldb','../../components/integrations/configuration','jayson/promise','client','test','Sequelize','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','FreshdeskAccount,\x20%s,\x20%s','request\x20sent','FreshdeskAccount,\x20%s,\x20%s,\x20%s','stringify','error','message','result','status','end','json','count','offset','limit','Content-Range','apply','reject','destroy','sendStatus','stack','name'];(function(_0x5106c1,_0x13233a){var _0x5bcaac=function(_0x18c12e){while(--_0x18c12e){_0x5106c1['push'](_0x5106c1['shift']());}};_0x5bcaac(++_0x13233a);}(_0x8f78,0xc9));var _0x88f7=function(_0x422905,_0x3bce3a){_0x422905=_0x422905-0x0;var _0x33dc6c=_0x8f78[_0x422905];return _0x33dc6c;};'use strict';var pdf=require(_0x88f7('0x0'));var emlformat=require(_0x88f7('0x1'));var rimraf=require(_0x88f7('0x2'));var zipdir=require(_0x88f7('0x3'));var jsonpatch=require(_0x88f7('0x4'));var rp=require(_0x88f7('0x5'));var moment=require(_0x88f7('0x6'));var BPromise=require(_0x88f7('0x7'));var Mustache=require(_0x88f7('0x8'));var util=require(_0x88f7('0x9'));var path=require(_0x88f7('0xa'));var sox=require('sox');var csv=require(_0x88f7('0xb'));var ejs=require('ejs');var fs=require('fs');var _=require('lodash');var squel=require('squel');var crypto=require(_0x88f7('0xc'));var jsforce=require(_0x88f7('0xd'));var deskjs=require(_0x88f7('0xe'));var toCsv=require(_0x88f7('0xb'));var querystring=require(_0x88f7('0xf'));var Papa=require(_0x88f7('0x10'));var Redis=require(_0x88f7('0x11'));var authService=require(_0x88f7('0x12'));var qs=require('../../components/parsers/qs');var as=require(_0x88f7('0x13'));var hardwareService=require(_0x88f7('0x14'));var logger=require('../../config/logger')(_0x88f7('0x15'));var utils=require('../../config/utils');var config=require(_0x88f7('0x16'));var db=require(_0x88f7('0x17'))['db'];var integrations=require(_0x88f7('0x18'));var jayson=require(_0x88f7('0x19'));var client=jayson[_0x88f7('0x1a')]['http']({'port':0x232a});function checkPasswordPattern(_0x1bb1d8,_0x12377b,_0x32de16){if(_0x32de16){var _0x4b23d1=new RegExp(/(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[?!@#\$%\^&\*~\-_=+[{\]\}])(?=.{8,})/);if(_0x4b23d1[_0x88f7('0x1b')](_0x12377b)){return _0x1bb1d8;}else{throw new db[(_0x88f7('0x1c'))][(_0x88f7('0x1d'))](_0x88f7('0x1e'));}}else{return _0x1bb1d8;}}function respondWithRpcPromise(_0x3a1179,_0x329338,_0x502f7b,_0x445ce3){return new BPromise(function(_0x5bb752,_0x14e8ee){var _0x57caba=_0x445ce3||client;return _0x57caba['request'](_0x3a1179,_0x502f7b)[_0x88f7('0x1f')](function(_0x59b540){logger[_0x88f7('0x20')](_0x88f7('0x21'),_0x329338,_0x88f7('0x22'));logger['debug'](_0x88f7('0x23'),_0x329338,'request\x20sent',JSON[_0x88f7('0x24')](_0x59b540));if(_0x59b540[_0x88f7('0x25')]){if(_0x59b540['error']['code']===0x1f4){logger[_0x88f7('0x25')](_0x88f7('0x21'),_0x329338,_0x59b540['error'][_0x88f7('0x26')]);return _0x14e8ee(_0x59b540[_0x88f7('0x25')][_0x88f7('0x26')]);}logger[_0x88f7('0x25')](_0x88f7('0x21'),_0x329338,_0x59b540[_0x88f7('0x25')][_0x88f7('0x26')]);return _0x5bb752(_0x59b540['error']['message']);}else{logger[_0x88f7('0x20')](_0x88f7('0x21'),_0x329338,_0x88f7('0x22'));_0x5bb752(_0x59b540[_0x88f7('0x27')][_0x88f7('0x26')]);}})['catch'](function(_0x56c197){logger[_0x88f7('0x25')]('FreshdeskAccount,\x20%s,\x20%s',_0x329338,_0x56c197);_0x14e8ee(_0x56c197);});});}function respondWithStatusCode(_0x57d6da,_0x446933){_0x446933=_0x446933||0xcc;return function(_0x2ea65e){if(_0x2ea65e){return _0x57d6da['sendStatus'](_0x446933);}return _0x57d6da[_0x88f7('0x28')](_0x446933)[_0x88f7('0x29')]();};}function respondWithResult(_0x565c2b,_0x4576ab){_0x4576ab=_0x4576ab||0xc8;return function(_0x4c1d51){if(_0x4c1d51){return _0x565c2b[_0x88f7('0x28')](_0x4576ab)[_0x88f7('0x2a')](_0x4c1d51);}};}function respondWithFilteredResult(_0x3ec41d,_0x1f954f){return function(_0x1fc3bc){if(_0x1fc3bc){var _0x44da5a=_0x1fc3bc[_0x88f7('0x2b')],_0x29ca06=_0x1f954f[_0x88f7('0x2c')],_0x1cbdbb=_0x1f954f[_0x88f7('0x2c')]+_0x1f954f[_0x88f7('0x2d')],_0x3c7326;if(_0x1cbdbb>=_0x44da5a){_0x1cbdbb=_0x44da5a;_0x3c7326=0xc8;}else{_0x3c7326=0xce;}_0x3ec41d['status'](_0x3c7326);return _0x3ec41d['set'](_0x88f7('0x2e'),_0x29ca06+'-'+_0x1cbdbb+'/'+_0x44da5a)['json'](_0x1fc3bc);}return null;};}function patchUpdates(_0xf11da9){return function(_0x4c4bba){try{jsonpatch[_0x88f7('0x2f')](_0x4c4bba,_0xf11da9,!![]);}catch(_0x2641d5){return BPromise[_0x88f7('0x30')](_0x2641d5);}return _0x4c4bba['save']();};}function saveUpdates(_0x11e232,_0x17d100){return function(_0x2c0a4b){if(_0x2c0a4b){return _0x2c0a4b['update'](_0x11e232)[_0x88f7('0x1f')](function(_0x246857){return _0x246857;});}return null;};}function removeEntity(_0x1e2d36,_0x3a3591){return function(_0x2de780){if(_0x2de780){return _0x2de780[_0x88f7('0x31')]()[_0x88f7('0x1f')](function(){_0x1e2d36[_0x88f7('0x28')](0xcc)[_0x88f7('0x29')]();});}};}function handleEntityNotFound(_0xdc5483,_0x3069ad){return function(_0x3e23df){if(!_0x3e23df){_0xdc5483[_0x88f7('0x32')](0x194);}return _0x3e23df;};}function handleError(_0x5b9eae,_0x1c1617){_0x1c1617=_0x1c1617||0x1f4;return function(_0xc2b5ff){logger[_0x88f7('0x25')](_0xc2b5ff[_0x88f7('0x33')]);if(_0xc2b5ff[_0x88f7('0x34')]){delete _0xc2b5ff[_0x88f7('0x34')];}_0x5b9eae['status'](_0x1c1617)['send'](_0xc2b5ff);};}exports[_0x88f7('0x35')]=function(_0x28d0ed,_0x459e00){var _0x11a2a1={},_0x128468={},_0x4fb9c4={'count':0x0,'rows':[]};var _0x20707b=_[_0x88f7('0x36')](db[_0x88f7('0x37')][_0x88f7('0x38')],function(_0x4350cb){return{'name':_0x4350cb[_0x88f7('0x39')],'type':_0x4350cb[_0x88f7('0x3a')][_0x88f7('0x3b')]};});_0x128468[_0x88f7('0x3c')]=_['map'](_0x20707b,_0x88f7('0x34'));_0x128468['query']=_[_0x88f7('0x3d')](_0x28d0ed[_0x88f7('0x3e')]);_0x128468[_0x88f7('0x3f')]=_['intersection'](_0x128468[_0x88f7('0x3c')],_0x128468['query']);_0x11a2a1[_0x88f7('0x40')]=_[_0x88f7('0x41')](_0x128468[_0x88f7('0x3c')],qs[_0x88f7('0x42')](_0x28d0ed[_0x88f7('0x3e')][_0x88f7('0x42')]));_0x11a2a1[_0x88f7('0x40')]=_0x11a2a1[_0x88f7('0x40')][_0x88f7('0x43')]?_0x11a2a1[_0x88f7('0x40')]:_0x128468[_0x88f7('0x3c')];if(!_0x28d0ed['query'][_0x88f7('0x44')]('nolimit')){_0x11a2a1[_0x88f7('0x2d')]=qs[_0x88f7('0x2d')](_0x28d0ed[_0x88f7('0x3e')][_0x88f7('0x2d')]);_0x11a2a1['offset']=qs['offset'](_0x28d0ed[_0x88f7('0x3e')][_0x88f7('0x2c')]);}_0x11a2a1['order']=qs[_0x88f7('0x45')](_0x28d0ed[_0x88f7('0x3e')][_0x88f7('0x45')]);_0x11a2a1[_0x88f7('0x46')]=qs[_0x88f7('0x3f')](_['pick'](_0x28d0ed[_0x88f7('0x3e')],_0x128468[_0x88f7('0x3f')]));if(_0x28d0ed[_0x88f7('0x3e')][_0x88f7('0x47')]){_0x11a2a1[_0x88f7('0x46')]=_['merge'](_0x11a2a1['where'],{'$or':_[_0x88f7('0x36')](_0x20707b,function(_0xe65a32){if(_0xe65a32[_0x88f7('0x3a')]!==_0x88f7('0x48')){var _0x5f14c9={};_0x5f14c9[_0xe65a32['name']]={'$like':'%'+_0x28d0ed[_0x88f7('0x3e')][_0x88f7('0x47')]+'%'};return _0x5f14c9;}})});}_0x11a2a1=_[_0x88f7('0x49')]({},_0x11a2a1,_0x28d0ed[_0x88f7('0x4a')]);var _0x4f0c2f={'where':_0x11a2a1[_0x88f7('0x46')]};return db[_0x88f7('0x37')]['count'](_0x4f0c2f)[_0x88f7('0x1f')](function(_0x26f9f2){_0x4fb9c4[_0x88f7('0x2b')]=_0x26f9f2;if(_0x28d0ed[_0x88f7('0x3e')][_0x88f7('0x4b')]){_0x11a2a1[_0x88f7('0x4c')]=[{'all':!![]}];}return db[_0x88f7('0x37')][_0x88f7('0x4d')](_0x11a2a1);})[_0x88f7('0x1f')](function(_0x1a8220){_0x4fb9c4['rows']=_0x1a8220;return _0x4fb9c4;})[_0x88f7('0x1f')](respondWithFilteredResult(_0x459e00,_0x11a2a1))[_0x88f7('0x4e')](handleError(_0x459e00,null));};exports[_0x88f7('0x4f')]=function(_0x58f609,_0x7f9f8){var _0x17a967={'raw':![],'where':{'id':_0x58f609[_0x88f7('0x50')]['id']}},_0x5d7eb7={};_0x5d7eb7[_0x88f7('0x3c')]=_['keys'](db[_0x88f7('0x37')]['rawAttributes']);_0x5d7eb7[_0x88f7('0x3e')]=_[_0x88f7('0x3d')](_0x58f609[_0x88f7('0x3e')]);_0x5d7eb7[_0x88f7('0x3f')]=_[_0x88f7('0x41')](_0x5d7eb7['model'],_0x5d7eb7['query']);_0x17a967['attributes']=_['intersection'](_0x5d7eb7[_0x88f7('0x3c')],qs['fields'](_0x58f609[_0x88f7('0x3e')][_0x88f7('0x42')]));_0x17a967[_0x88f7('0x40')]=_0x17a967[_0x88f7('0x40')][_0x88f7('0x43')]?_0x17a967[_0x88f7('0x40')]:_0x5d7eb7[_0x88f7('0x3c')];if(_0x58f609[_0x88f7('0x3e')]['includeAll']){_0x17a967[_0x88f7('0x4c')]=[{'all':!![]}];}_0x17a967=_[_0x88f7('0x49')]({},_0x17a967,_0x58f609[_0x88f7('0x4a')]);return db['FreshdeskAccount']['find'](_0x17a967)[_0x88f7('0x1f')](handleEntityNotFound(_0x7f9f8,null))[_0x88f7('0x1f')](respondWithResult(_0x7f9f8,null))['catch'](handleError(_0x7f9f8,null));};exports[_0x88f7('0x51')]=function(_0x4142b5,_0x564979){return db['FreshdeskAccount'][_0x88f7('0x51')](_0x4142b5[_0x88f7('0x52')],{})[_0x88f7('0x1f')](respondWithResult(_0x564979,0xc9))[_0x88f7('0x4e')](handleError(_0x564979,null));};exports[_0x88f7('0x53')]=function(_0x44ddab,_0x28c0a5){if(_0x44ddab[_0x88f7('0x52')]['id']){delete _0x44ddab[_0x88f7('0x52')]['id'];}return db['FreshdeskAccount'][_0x88f7('0x54')]({'where':{'id':_0x44ddab['params']['id']}})[_0x88f7('0x1f')](handleEntityNotFound(_0x28c0a5,null))[_0x88f7('0x1f')](saveUpdates(_0x44ddab['body'],null))[_0x88f7('0x1f')](respondWithResult(_0x28c0a5,null))[_0x88f7('0x4e')](handleError(_0x28c0a5,null));};exports['destroy']=function(_0x45b61f,_0xd44015){return db[_0x88f7('0x37')][_0x88f7('0x54')]({'where':{'id':_0x45b61f[_0x88f7('0x50')]['id']}})[_0x88f7('0x1f')](handleEntityNotFound(_0xd44015,null))[_0x88f7('0x1f')](removeEntity(_0xd44015,null))['catch'](handleError(_0xd44015,null));};exports[_0x88f7('0x55')]=function(_0x29c395,_0x1163e1,_0x321884){var _0x184968={};var _0x4e46ba={};var _0x5114a9;var _0x11a5fb;return db['FreshdeskAccount']['findOne']({'where':{'id':_0x29c395[_0x88f7('0x50')]['id']}})[_0x88f7('0x1f')](handleEntityNotFound(_0x1163e1,null))[_0x88f7('0x1f')](function(_0x159290){if(_0x159290){_0x5114a9=_0x159290;_0x4e46ba[_0x88f7('0x3c')]=_[_0x88f7('0x3d')](db['FreshdeskConfiguration'][_0x88f7('0x38')]);_0x4e46ba[_0x88f7('0x3e')]=_[_0x88f7('0x3d')](_0x29c395['query']);_0x4e46ba[_0x88f7('0x3f')]=_[_0x88f7('0x41')](_0x4e46ba[_0x88f7('0x3c')],_0x4e46ba['query']);_0x184968['attributes']=_['intersection'](_0x4e46ba['model'],qs[_0x88f7('0x42')](_0x29c395['query'][_0x88f7('0x42')]));_0x184968['attributes']=_0x184968[_0x88f7('0x40')][_0x88f7('0x43')]?_0x184968['attributes']:_0x4e46ba['model'];_0x184968[_0x88f7('0x56')]=qs[_0x88f7('0x45')](_0x29c395['query'][_0x88f7('0x45')]);_0x184968[_0x88f7('0x46')]=qs[_0x88f7('0x3f')](_['pick'](_0x29c395[_0x88f7('0x3e')],_0x4e46ba[_0x88f7('0x3f')]));if(_0x29c395[_0x88f7('0x3e')][_0x88f7('0x47')]){_0x184968[_0x88f7('0x46')]=_['merge'](_0x184968['where'],{'$or':_[_0x88f7('0x36')](_0x184968['attributes'],function(_0x310882){var _0x8c844a={};_0x8c844a[_0x310882]={'$like':'%'+_0x29c395[_0x88f7('0x3e')][_0x88f7('0x47')]+'%'};return _0x8c844a;})});}_0x184968=_[_0x88f7('0x49')]({},_0x184968,_0x29c395[_0x88f7('0x4a')]);return _0x5114a9[_0x88f7('0x55')](_0x184968);}})[_0x88f7('0x1f')](function(_0x4ba0f9){if(_0x4ba0f9){_0x11a5fb=_0x4ba0f9['length'];if(!_0x29c395['query'][_0x88f7('0x44')](_0x88f7('0x57'))){_0x184968[_0x88f7('0x2d')]=qs[_0x88f7('0x2d')](_0x29c395[_0x88f7('0x3e')][_0x88f7('0x2d')]);_0x184968[_0x88f7('0x2c')]=qs[_0x88f7('0x2c')](_0x29c395[_0x88f7('0x3e')][_0x88f7('0x2c')]);}return _0x5114a9[_0x88f7('0x55')](_0x184968);}})[_0x88f7('0x1f')](function(_0x93a9d6){if(_0x93a9d6){return _0x93a9d6?{'count':_0x11a5fb,'rows':_0x93a9d6}:null;}})[_0x88f7('0x1f')](respondWithResult(_0x1163e1,null))[_0x88f7('0x4e')](handleError(_0x1163e1,null));};exports[_0x88f7('0x58')]=function(_0x154807,_0x128e88,_0x58cf8b){if(_0x154807[_0x88f7('0x52')]['id']){delete _0x154807['body']['id'];}return db[_0x88f7('0x37')][_0x88f7('0x59')]({'where':{'id':_0x154807[_0x88f7('0x50')]['id']}})['then'](handleEntityNotFound(_0x128e88,null))[_0x88f7('0x1f')](function(_0x3ef059){if(_0x3ef059){_0x154807[_0x88f7('0x52')]['AccountId']=_0x3ef059['id'];_0x154807['body'][_0x88f7('0x5a')]=integrations[_0x88f7('0x5b')](_0x154807['body'][_0x88f7('0x5c')],_0x154807[_0x88f7('0x52')][_0x88f7('0x3a')]);_0x154807[_0x88f7('0x52')][_0x88f7('0x5d')]=integrations[_0x88f7('0x5e')](_0x154807[_0x88f7('0x52')][_0x88f7('0x5c')],_0x154807[_0x88f7('0x52')][_0x88f7('0x3a')]);return db['FreshdeskConfiguration'][_0x88f7('0x51')](_0x154807[_0x88f7('0x52')],{'include':[{'model':db[_0x88f7('0x5f')],'as':_0x88f7('0x5a')},{'model':db[_0x88f7('0x5f')],'as':'Descriptions'}]});}return null;})[_0x88f7('0x1f')](respondWithResult(_0x128e88,null))[_0x88f7('0x4e')](handleError(_0x128e88,null));};exports['getFields']=function(_0x565a88,_0x4f5266,_0xf90a73){var _0x4fa87c='';return db[_0x88f7('0x37')][_0x88f7('0x59')]({'where':{'id':_0x565a88[_0x88f7('0x50')]['id']},'attributes':['id',_0x88f7('0x60'),_0x88f7('0x61')]})[_0x88f7('0x1f')](handleEntityNotFound(_0x4f5266,null))[_0x88f7('0x1f')](function(_0x29650b){if(_0x29650b){_0x4fa87c=_0x29650b['remoteUri'];var _0x3fd399=_0x4fa87c['slice'](-0x1);if(_0x3fd399==='/'){_0x4fa87c=_0x4fa87c[_0x88f7('0x62')](0x0,_0x4fa87c[_0x88f7('0x63')](_0x3fd399));}return rp({'method':_0x88f7('0x64'),'uri':util[_0x88f7('0x65')](_0x88f7('0x66'),_0x4fa87c,_0x88f7('0x67')),'headers':{'Authorization':util[_0x88f7('0x65')](_0x88f7('0x68'),new Buffer(util['format'](_0x88f7('0x69'),_0x29650b[_0x88f7('0x61')]))[_0x88f7('0x6a')]('base64'))},'json':!![]});}})[_0x88f7('0x1f')](function(_0x2b0a08){if(_0x2b0a08){var _0x842c20=[_0x88f7('0x6b'),_0x88f7('0x6c'),_0x88f7('0x6d'),_0x88f7('0x6e'),'status',_0x88f7('0x6f'),_0x88f7('0x70'),_0x88f7('0x71'),_0x88f7('0x72'),_0x88f7('0x70'),_0x88f7('0x73')];_['remove'](_0x2b0a08,function(_0x303a03){return _0x842c20[_0x88f7('0x74')](_0x303a03[_0x88f7('0x34')])||!_0x303a03['default']&&_0x303a03['type']!==_0x88f7('0x75')&&_0x303a03[_0x88f7('0x3a')]!=='custom_dropdown';});return{'count':_0x2b0a08[_0x88f7('0x43')],'rows':_[_0x88f7('0x36')](_0x2b0a08,function(_0x5126d7){return{'id':_0x5126d7[_0x88f7('0x34')],'name':_0x5126d7[_0x88f7('0x76')],'custom':!_0x5126d7[_0x88f7('0x77')],'options':_0x5126d7[_0x88f7('0x78')]?_[_0x88f7('0x36')](_0x5126d7[_0x88f7('0x78')],function(_0x318b95){return{'name':_[_0x88f7('0x79')](_0x318b95),'value':_0x318b95};}):[]};})};}})[_0x88f7('0x1f')](respondWithResult(_0x4f5266,null))[_0x88f7('0x4e')](function(_0x38b51c){var _0x2f5300=_0x565a88[_0x88f7('0x3e')]['test']?0x1f4:_0x38b51c[_0x88f7('0x7a')]||0x1f4;logger[_0x88f7('0x25')](_0x88f7('0x7b'),_0x88f7('0x7c'),_0x2f5300,JSON[_0x88f7('0x24')](_0x38b51c));delete _0x38b51c['name'];if(_0x2f5300===0x191){_0x2f5300=0x190;}_0x4f5266[_0x88f7('0x28')](_0x2f5300)[_0x88f7('0x7d')](_0x565a88[_0x88f7('0x3e')][_0x88f7('0x1b')]?{'message':_0x88f7('0x7e'),'statusCode':_0x38b51c[_0x88f7('0x7a')]}:_0x38b51c);});};
\ No newline at end of file
+var _0xc99a=['label','choices','capitalize','test','statusCode','error','getFields,\x20%s,\x20%s,\x20%s','send','Wrong\x20credentials','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../components/integrations/configuration','sendStatus','status','end','offset','undefined','count','set','json','reject','save','update','then','destroy','stack','name','index','rawAttributes','fieldName','model','map','query','keys','filters','intersection','attributes','fields','hasOwnProperty','nolimit','limit','order','sort','where','pick','filter','type','VIRTUAL','merge','options','FreshdeskAccount','includeAll','include','rows','catch','show','params','create','body','find','getConfigurations','findOne','FreshdeskConfiguration','length','AccountId','Subjects','getSubjects','channel','Descriptions','getDescriptions','FreshdeskField','getFields','remoteUri','slice','lastIndexOf','GET','format','%s/%s','api/v2/ticket_fields','%s:X','toString','base64','requester','agent','priority','group','company','remove','includes','default','custom_dropdown'];(function(_0x1b2ff7,_0x12a034){var _0x31656a=function(_0x1165a5){while(--_0x1165a5){_0x1b2ff7['push'](_0x1b2ff7['shift']());}};_0x31656a(++_0x12a034);}(_0xc99a,0x7c));var _0xac99=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0xc99a[_0x3dd15e];return _0x231fd0;};'use strict';var emlformat=require(_0xac99('0x0'));var rimraf=require(_0xac99('0x1'));var zipdir=require(_0xac99('0x2'));var jsonpatch=require(_0xac99('0x3'));var rp=require(_0xac99('0x4'));var moment=require(_0xac99('0x5'));var BPromise=require('bluebird');var Mustache=require(_0xac99('0x6'));var util=require(_0xac99('0x7'));var path=require(_0xac99('0x8'));var sox=require(_0xac99('0x9'));var csv=require(_0xac99('0xa'));var ejs=require(_0xac99('0xb'));var fs=require('fs');var fs_extra=require(_0xac99('0xc'));var _=require(_0xac99('0xd'));var squel=require(_0xac99('0xe'));var crypto=require(_0xac99('0xf'));var jsforce=require(_0xac99('0x10'));var deskjs=require(_0xac99('0x11'));var toCsv=require('to-csv');var querystring=require(_0xac99('0x12'));var Papa=require(_0xac99('0x13'));var Redis=require('ioredis');var authService=require(_0xac99('0x14'));var qs=require(_0xac99('0x15'));var as=require(_0xac99('0x16'));var hardwareService=require(_0xac99('0x17'));var logger=require('../../config/logger')(_0xac99('0x18'));var utils=require(_0xac99('0x19'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];var integrations=require(_0xac99('0x1a'));function respondWithStatusCode(_0x4e51f4,_0x1ae389){_0x1ae389=_0x1ae389||0xcc;return function(_0x43b96c){if(_0x43b96c){return _0x4e51f4[_0xac99('0x1b')](_0x1ae389);}return _0x4e51f4[_0xac99('0x1c')](_0x1ae389)[_0xac99('0x1d')]();};}function respondWithResult(_0x454f0a,_0x534eb1){_0x534eb1=_0x534eb1||0xc8;return function(_0x4564e1){if(_0x4564e1){return _0x454f0a['status'](_0x534eb1)['json'](_0x4564e1);}};}function respondWithFilteredResult(_0x1ea483,_0xd327f4){return function(_0x5cd3fd){if(_0x5cd3fd){var _0x3ff09c=typeof _0xd327f4[_0xac99('0x1e')]===_0xac99('0x1f')&&typeof _0xd327f4['limit']==='undefined';var _0x8a45d3=_0x5cd3fd[_0xac99('0x20')];var _0xa52fe2=_0x3ff09c?0x0:_0xd327f4[_0xac99('0x1e')];var _0x400b29=_0x3ff09c?_0x5cd3fd[_0xac99('0x20')]:_0xd327f4[_0xac99('0x1e')]+_0xd327f4['limit'];var _0x48ed38;if(_0x400b29>=_0x8a45d3){_0x400b29=_0x8a45d3;_0x48ed38=0xc8;}else{_0x48ed38=0xce;}_0x1ea483[_0xac99('0x1c')](_0x48ed38);return _0x1ea483[_0xac99('0x21')]('Content-Range',_0xa52fe2+'-'+_0x400b29+'/'+_0x8a45d3)[_0xac99('0x22')](_0x5cd3fd);}return null;};}function patchUpdates(_0x258eb1){return function(_0x4f9889){try{jsonpatch['apply'](_0x4f9889,_0x258eb1,!![]);}catch(_0x42af82){return BPromise[_0xac99('0x23')](_0x42af82);}return _0x4f9889[_0xac99('0x24')]();};}function saveUpdates(_0x154f4b,_0x2b7e52){return function(_0x22f164){if(_0x22f164){return _0x22f164[_0xac99('0x25')](_0x154f4b)[_0xac99('0x26')](function(_0x3330df){return _0x3330df;});}return null;};}function removeEntity(_0x50866e,_0x45c3c6){return function(_0x41f345){if(_0x41f345){return _0x41f345[_0xac99('0x27')]()[_0xac99('0x26')](function(){_0x50866e[_0xac99('0x1c')](0xcc)[_0xac99('0x1d')]();});}};}function handleEntityNotFound(_0x53bcb5,_0xb8e570){return function(_0x4480fb){if(!_0x4480fb){_0x53bcb5[_0xac99('0x1b')](0x194);}return _0x4480fb;};}function handleError(_0x33b0d9,_0x586fd3){_0x586fd3=_0x586fd3||0x1f4;return function(_0x3191ea){logger['error'](_0x3191ea[_0xac99('0x28')]);if(_0x3191ea[_0xac99('0x29')]){delete _0x3191ea[_0xac99('0x29')];}_0x33b0d9['status'](_0x586fd3)['send'](_0x3191ea);};}exports[_0xac99('0x2a')]=function(_0x4f2e8b,_0x519816){var _0xa4b35e={},_0x38ff85={},_0x599f62={'count':0x0,'rows':[]};var _0x5b6f60=_['map'](db['FreshdeskAccount'][_0xac99('0x2b')],function(_0xe42bcf){return{'name':_0xe42bcf[_0xac99('0x2c')],'type':_0xe42bcf['type']['key']};});_0x38ff85[_0xac99('0x2d')]=_[_0xac99('0x2e')](_0x5b6f60,'name');_0x38ff85[_0xac99('0x2f')]=_[_0xac99('0x30')](_0x4f2e8b[_0xac99('0x2f')]);_0x38ff85[_0xac99('0x31')]=_[_0xac99('0x32')](_0x38ff85[_0xac99('0x2d')],_0x38ff85[_0xac99('0x2f')]);_0xa4b35e[_0xac99('0x33')]=_['intersection'](_0x38ff85[_0xac99('0x2d')],qs['fields'](_0x4f2e8b[_0xac99('0x2f')][_0xac99('0x34')]));_0xa4b35e[_0xac99('0x33')]=_0xa4b35e[_0xac99('0x33')]['length']?_0xa4b35e[_0xac99('0x33')]:_0x38ff85['model'];if(!_0x4f2e8b[_0xac99('0x2f')][_0xac99('0x35')](_0xac99('0x36'))){_0xa4b35e['limit']=qs[_0xac99('0x37')](_0x4f2e8b[_0xac99('0x2f')][_0xac99('0x37')]);_0xa4b35e['offset']=qs['offset'](_0x4f2e8b[_0xac99('0x2f')]['offset']);}_0xa4b35e[_0xac99('0x38')]=qs[_0xac99('0x39')](_0x4f2e8b[_0xac99('0x2f')][_0xac99('0x39')]);_0xa4b35e[_0xac99('0x3a')]=qs[_0xac99('0x31')](_[_0xac99('0x3b')](_0x4f2e8b[_0xac99('0x2f')],_0x38ff85['filters']),_0x5b6f60);if(_0x4f2e8b[_0xac99('0x2f')][_0xac99('0x3c')]){_0xa4b35e['where']=_['merge'](_0xa4b35e[_0xac99('0x3a')],{'$or':_[_0xac99('0x2e')](_0x5b6f60,function(_0x22a279){if(_0x22a279[_0xac99('0x3d')]!==_0xac99('0x3e')){var _0x427c60={};_0x427c60[_0x22a279[_0xac99('0x29')]]={'$like':'%'+_0x4f2e8b[_0xac99('0x2f')][_0xac99('0x3c')]+'%'};return _0x427c60;}})});}_0xa4b35e=_[_0xac99('0x3f')]({},_0xa4b35e,_0x4f2e8b[_0xac99('0x40')]);var _0xf85b9b={'where':_0xa4b35e[_0xac99('0x3a')]};return db[_0xac99('0x41')][_0xac99('0x20')](_0xf85b9b)[_0xac99('0x26')](function(_0x36b99a){_0x599f62[_0xac99('0x20')]=_0x36b99a;if(_0x4f2e8b['query'][_0xac99('0x42')]){_0xa4b35e[_0xac99('0x43')]=[{'all':!![]}];}return db['FreshdeskAccount']['findAll'](_0xa4b35e);})['then'](function(_0x5ff0d2){_0x599f62[_0xac99('0x44')]=_0x5ff0d2;return _0x599f62;})[_0xac99('0x26')](respondWithFilteredResult(_0x519816,_0xa4b35e))[_0xac99('0x45')](handleError(_0x519816,null));};exports[_0xac99('0x46')]=function(_0xc0c223,_0x48d5e8){var _0x593a7f={'raw':![],'where':{'id':_0xc0c223[_0xac99('0x47')]['id']}},_0x113d95={};_0x113d95['model']=_[_0xac99('0x30')](db[_0xac99('0x41')][_0xac99('0x2b')]);_0x113d95['query']=_[_0xac99('0x30')](_0xc0c223[_0xac99('0x2f')]);_0x113d95[_0xac99('0x31')]=_[_0xac99('0x32')](_0x113d95[_0xac99('0x2d')],_0x113d95['query']);_0x593a7f[_0xac99('0x33')]=_[_0xac99('0x32')](_0x113d95['model'],qs['fields'](_0xc0c223['query'][_0xac99('0x34')]));_0x593a7f['attributes']=_0x593a7f['attributes']['length']?_0x593a7f[_0xac99('0x33')]:_0x113d95[_0xac99('0x2d')];if(_0xc0c223[_0xac99('0x2f')][_0xac99('0x42')]){_0x593a7f['include']=[{'all':!![]}];}_0x593a7f=_[_0xac99('0x3f')]({},_0x593a7f,_0xc0c223['options']);return db[_0xac99('0x41')]['find'](_0x593a7f)[_0xac99('0x26')](handleEntityNotFound(_0x48d5e8,null))['then'](respondWithResult(_0x48d5e8,null))['catch'](handleError(_0x48d5e8,null));};exports[_0xac99('0x48')]=function(_0x5c6254,_0x551475){return db[_0xac99('0x41')]['create'](_0x5c6254[_0xac99('0x49')],{})[_0xac99('0x26')](respondWithResult(_0x551475,0xc9))[_0xac99('0x45')](handleError(_0x551475,null));};exports[_0xac99('0x25')]=function(_0x5abedd,_0x5189d1){if(_0x5abedd[_0xac99('0x49')]['id']){delete _0x5abedd[_0xac99('0x49')]['id'];}return db[_0xac99('0x41')][_0xac99('0x4a')]({'where':{'id':_0x5abedd[_0xac99('0x47')]['id']}})[_0xac99('0x26')](handleEntityNotFound(_0x5189d1,null))[_0xac99('0x26')](saveUpdates(_0x5abedd[_0xac99('0x49')],null))[_0xac99('0x26')](respondWithResult(_0x5189d1,null))['catch'](handleError(_0x5189d1,null));};exports[_0xac99('0x27')]=function(_0x47dcb1,_0x148ab4){return db[_0xac99('0x41')][_0xac99('0x4a')]({'where':{'id':_0x47dcb1[_0xac99('0x47')]['id']}})[_0xac99('0x26')](handleEntityNotFound(_0x148ab4,null))[_0xac99('0x26')](removeEntity(_0x148ab4,null))[_0xac99('0x45')](handleError(_0x148ab4,null));};exports[_0xac99('0x4b')]=function(_0x7e5cd4,_0x4cd670,_0xcffb9f){var _0x1412f8={};var _0x586f70={};var _0x379118;var _0x4b8d50;return db[_0xac99('0x41')][_0xac99('0x4c')]({'where':{'id':_0x7e5cd4[_0xac99('0x47')]['id']}})['then'](handleEntityNotFound(_0x4cd670,null))[_0xac99('0x26')](function(_0x4b44ac){if(_0x4b44ac){_0x379118=_0x4b44ac;_0x586f70['model']=_[_0xac99('0x30')](db[_0xac99('0x4d')][_0xac99('0x2b')]);_0x586f70[_0xac99('0x2f')]=_[_0xac99('0x30')](_0x7e5cd4[_0xac99('0x2f')]);_0x586f70[_0xac99('0x31')]=_['intersection'](_0x586f70[_0xac99('0x2d')],_0x586f70[_0xac99('0x2f')]);_0x1412f8[_0xac99('0x33')]=_[_0xac99('0x32')](_0x586f70[_0xac99('0x2d')],qs[_0xac99('0x34')](_0x7e5cd4['query'][_0xac99('0x34')]));_0x1412f8['attributes']=_0x1412f8[_0xac99('0x33')]['length']?_0x1412f8[_0xac99('0x33')]:_0x586f70[_0xac99('0x2d')];_0x1412f8[_0xac99('0x38')]=qs[_0xac99('0x39')](_0x7e5cd4[_0xac99('0x2f')][_0xac99('0x39')]);_0x1412f8[_0xac99('0x3a')]=qs[_0xac99('0x31')](_[_0xac99('0x3b')](_0x7e5cd4[_0xac99('0x2f')],_0x586f70[_0xac99('0x31')]));if(_0x7e5cd4['query'][_0xac99('0x3c')]){_0x1412f8[_0xac99('0x3a')]=_['merge'](_0x1412f8[_0xac99('0x3a')],{'$or':_[_0xac99('0x2e')](_0x1412f8['attributes'],function(_0x127912){var _0x37f803={};_0x37f803[_0x127912]={'$like':'%'+_0x7e5cd4[_0xac99('0x2f')][_0xac99('0x3c')]+'%'};return _0x37f803;})});}_0x1412f8=_[_0xac99('0x3f')]({},_0x1412f8,_0x7e5cd4[_0xac99('0x40')]);return _0x379118[_0xac99('0x4b')](_0x1412f8);}})['then'](function(_0x4c6a1f){if(_0x4c6a1f){_0x4b8d50=_0x4c6a1f[_0xac99('0x4e')];if(!_0x7e5cd4[_0xac99('0x2f')][_0xac99('0x35')](_0xac99('0x36'))){_0x1412f8[_0xac99('0x37')]=qs[_0xac99('0x37')](_0x7e5cd4[_0xac99('0x2f')]['limit']);_0x1412f8[_0xac99('0x1e')]=qs[_0xac99('0x1e')](_0x7e5cd4[_0xac99('0x2f')][_0xac99('0x1e')]);}return _0x379118['getConfigurations'](_0x1412f8);}})[_0xac99('0x26')](function(_0x2dc876){if(_0x2dc876){return _0x2dc876?{'count':_0x4b8d50,'rows':_0x2dc876}:null;}})[_0xac99('0x26')](respondWithResult(_0x4cd670,null))[_0xac99('0x45')](handleError(_0x4cd670,null));};exports['addConfiguration']=function(_0x3a973e,_0x5f2c30,_0x1570cf){if(_0x3a973e[_0xac99('0x49')]['id']){delete _0x3a973e[_0xac99('0x49')]['id'];}return db[_0xac99('0x41')][_0xac99('0x4c')]({'where':{'id':_0x3a973e[_0xac99('0x47')]['id']}})[_0xac99('0x26')](handleEntityNotFound(_0x5f2c30,null))[_0xac99('0x26')](function(_0x5c72bb){if(_0x5c72bb){_0x3a973e[_0xac99('0x49')][_0xac99('0x4f')]=_0x5c72bb['id'];_0x3a973e[_0xac99('0x49')][_0xac99('0x50')]=integrations[_0xac99('0x51')](_0x3a973e[_0xac99('0x49')][_0xac99('0x52')],_0x3a973e[_0xac99('0x49')][_0xac99('0x3d')]);_0x3a973e['body'][_0xac99('0x53')]=integrations[_0xac99('0x54')](_0x3a973e['body']['channel'],_0x3a973e['body'][_0xac99('0x3d')]);return db['FreshdeskConfiguration'][_0xac99('0x48')](_0x3a973e[_0xac99('0x49')],{'include':[{'model':db[_0xac99('0x55')],'as':'Subjects'},{'model':db[_0xac99('0x55')],'as':_0xac99('0x53')}]});}return null;})[_0xac99('0x26')](respondWithResult(_0x5f2c30,null))[_0xac99('0x45')](handleError(_0x5f2c30,null));};exports[_0xac99('0x56')]=function(_0x5d4869,_0x328985,_0x2f79c3){var _0xf91ffe='';return db['FreshdeskAccount'][_0xac99('0x4c')]({'where':{'id':_0x5d4869['params']['id']},'attributes':['id',_0xac99('0x57'),'apiKey']})[_0xac99('0x26')](handleEntityNotFound(_0x328985,null))[_0xac99('0x26')](function(_0x542548){if(_0x542548){_0xf91ffe=_0x542548[_0xac99('0x57')];var _0x468834=_0xf91ffe[_0xac99('0x58')](-0x1);if(_0x468834==='/'){_0xf91ffe=_0xf91ffe['substring'](0x0,_0xf91ffe[_0xac99('0x59')](_0x468834));}return rp({'method':_0xac99('0x5a'),'uri':util[_0xac99('0x5b')](_0xac99('0x5c'),_0xf91ffe,_0xac99('0x5d')),'headers':{'Authorization':util[_0xac99('0x5b')]('Basic\x20%s',new Buffer(util[_0xac99('0x5b')](_0xac99('0x5e'),_0x542548['apiKey']))[_0xac99('0x5f')](_0xac99('0x60')))},'json':!![]});}})['then'](function(_0x96ef3b){if(_0x96ef3b){var _0xc0e329=[_0xac99('0x61'),'subject',_0xac99('0x62'),'description','status',_0xac99('0x63'),'group','source','ticket_type',_0xac99('0x64'),_0xac99('0x65')];_[_0xac99('0x66')](_0x96ef3b,function(_0xd5f4e5){return _0xc0e329[_0xac99('0x67')](_0xd5f4e5[_0xac99('0x29')])||!_0xd5f4e5[_0xac99('0x68')]&&_0xd5f4e5[_0xac99('0x3d')]!=='custom_text'&&_0xd5f4e5['type']!==_0xac99('0x69');});return{'count':_0x96ef3b[_0xac99('0x4e')],'rows':_[_0xac99('0x2e')](_0x96ef3b,function(_0x4e1e7e){return{'id':_0x4e1e7e['name'],'name':_0x4e1e7e[_0xac99('0x6a')],'custom':!_0x4e1e7e[_0xac99('0x68')],'options':_0x4e1e7e[_0xac99('0x6b')]?_[_0xac99('0x2e')](_0x4e1e7e['choices'],function(_0x5ccf40){return{'name':_[_0xac99('0x6c')](_0x5ccf40),'value':_0x5ccf40};}):[]};})};}})['then'](respondWithResult(_0x328985,null))[_0xac99('0x45')](function(_0x32bea5){var _0x5b40c2=_0x5d4869[_0xac99('0x2f')][_0xac99('0x6d')]?0x1f4:_0x32bea5[_0xac99('0x6e')]||0x1f4;logger[_0xac99('0x6f')](_0xac99('0x70'),_0xac99('0x56'),_0x5b40c2,JSON['stringify'](_0x32bea5));delete _0x32bea5[_0xac99('0x29')];if(_0x5b40c2===0x191){_0x5b40c2=0x190;}_0x328985[_0xac99('0x1c')](_0x5b40c2)[_0xac99('0x71')](_0x5d4869[_0xac99('0x2f')][_0xac99('0x6d')]?{'message':_0xac99('0x72'),'statusCode':_0x32bea5['statusCode']}:_0x32bea5);});};
\ No newline at end of file