Built motion from commit 3e059bc2.|2.5.32
[motion2.git] / server / api / intFreshdeskAccount / intFreshdeskAccount.controller.js
index 64d04f6..287af87 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x29cd=['sox','ejs','fs-extra','squel','crypto','desk.js','to-csv','querystring','papaparse','ioredis','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/utils','../../config/license/util','../../mysqldb','jayson/promise','client','http','info','FreshdeskAccount,\x20%s,\x20%s','request\x20sent','debug','FreshdeskAccount,\x20%s,\x20%s,\x20%s','code','error','message','result','status','json','offset','set','Content-Range','apply','reject','save','update','then','destroy','sendStatus','stack','name','send','index','map','FreshdeskAccount','rawAttributes','type','key','model','query','filters','intersection','attributes','length','limit','order','sort','where','VIRTUAL','filter','merge','options','count','includeAll','rows','catch','params','keys','fields','create','body','find','getConfigurations','findOne','FreshdeskConfiguration','hasOwnProperty','nolimit','AccountId','Subjects','getSubjects','channel','Descriptions','getDescriptions','FreshdeskField','remoteUri','substring','lastIndexOf','GET','%s/%s','api/v2/ticket_fields','format','%s:X','apiKey','toString','base64','requester','subject','agent','description','group','source','ticket_type','company','remove','includes','default','custom_dropdown','label','choices','capitalize','test','statusCode','getFields','stringify','Wrong\x20credentials','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','util'];(function(_0x4e1bf4,_0x52aabb){var _0x45250b=function(_0x2902cc){while(--_0x2902cc){_0x4e1bf4['push'](_0x4e1bf4['shift']());}};_0x45250b(++_0x52aabb);}(_0x29cd,0xec));var _0xd29c=function(_0x8b7185,_0x3624ca){_0x8b7185=_0x8b7185-0x0;var _0x33f5bf=_0x29cd[_0x8b7185];return _0x33f5bf;};'use strict';var emlformat=require(_0xd29c('0x0'));var rimraf=require(_0xd29c('0x1'));var zipdir=require(_0xd29c('0x2'));var jsonpatch=require(_0xd29c('0x3'));var rp=require(_0xd29c('0x4'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0xd29c('0x5'));var path=require('path');var sox=require(_0xd29c('0x6'));var csv=require('to-csv');var ejs=require(_0xd29c('0x7'));var fs=require('fs');var fs_extra=require(_0xd29c('0x8'));var _=require('lodash');var squel=require(_0xd29c('0x9'));var crypto=require(_0xd29c('0xa'));var jsforce=require('jsforce');var deskjs=require(_0xd29c('0xb'));var toCsv=require(_0xd29c('0xc'));var querystring=require(_0xd29c('0xd'));var Papa=require(_0xd29c('0xe'));var Redis=require(_0xd29c('0xf'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0xd29c('0x10'));var hardwareService=require(_0xd29c('0x11'));var logger=require('../../config/logger')('api');var utils=require(_0xd29c('0x12'));var config=require('../../config/environment');var licenseUtil=require(_0xd29c('0x13'));var db=require(_0xd29c('0x14'))['db'];var integrations=require('../../components/integrations/configuration');var jayson=require(_0xd29c('0x15'));var client=jayson[_0xd29c('0x16')][_0xd29c('0x17')]({'port':0x232a});function respondWithRpcPromise(_0x12a7aa,_0x14bac9,_0x3a5f12,_0x24c037){return new BPromise(function(_0x35a890,_0x3923bf){var _0xee5126=_0x24c037||client;return _0xee5126['request'](_0x12a7aa,_0x3a5f12)['then'](function(_0x3db53a){logger[_0xd29c('0x18')](_0xd29c('0x19'),_0x14bac9,_0xd29c('0x1a'));logger[_0xd29c('0x1b')](_0xd29c('0x1c'),_0x14bac9,_0xd29c('0x1a'),JSON['stringify'](_0x3db53a));if(_0x3db53a['error']){if(_0x3db53a['error'][_0xd29c('0x1d')]===0x1f4){logger['error'](_0xd29c('0x19'),_0x14bac9,_0x3db53a[_0xd29c('0x1e')]['message']);return _0x3923bf(_0x3db53a[_0xd29c('0x1e')]['message']);}logger[_0xd29c('0x1e')](_0xd29c('0x19'),_0x14bac9,_0x3db53a['error']['message']);return _0x35a890(_0x3db53a[_0xd29c('0x1e')][_0xd29c('0x1f')]);}else{logger[_0xd29c('0x18')](_0xd29c('0x19'),_0x14bac9,_0xd29c('0x1a'));_0x35a890(_0x3db53a[_0xd29c('0x20')][_0xd29c('0x1f')]);}})['catch'](function(_0x10f95c){logger['error'](_0xd29c('0x19'),_0x14bac9,_0x10f95c);_0x3923bf(_0x10f95c);});});}function respondWithStatusCode(_0x109256,_0x2018b6){_0x2018b6=_0x2018b6||0xcc;return function(_0x464308){if(_0x464308){return _0x109256['sendStatus'](_0x2018b6);}return _0x109256[_0xd29c('0x21')](_0x2018b6)['end']();};}function respondWithResult(_0x2dca40,_0x14af61){_0x14af61=_0x14af61||0xc8;return function(_0x412034){if(_0x412034){return _0x2dca40['status'](_0x14af61)[_0xd29c('0x22')](_0x412034);}};}function respondWithFilteredResult(_0x53a129,_0x1464e2){return function(_0x91d001){if(_0x91d001){var _0x1e274d=_0x91d001['count'],_0x3c0f90=_0x1464e2[_0xd29c('0x23')],_0x381921=_0x1464e2[_0xd29c('0x23')]+_0x1464e2['limit'],_0x16be1f;if(_0x381921>=_0x1e274d){_0x381921=_0x1e274d;_0x16be1f=0xc8;}else{_0x16be1f=0xce;}_0x53a129[_0xd29c('0x21')](_0x16be1f);return _0x53a129[_0xd29c('0x24')](_0xd29c('0x25'),_0x3c0f90+'-'+_0x381921+'/'+_0x1e274d)['json'](_0x91d001);}return null;};}function patchUpdates(_0x4f6242){return function(_0x3986a6){try{jsonpatch[_0xd29c('0x26')](_0x3986a6,_0x4f6242,!![]);}catch(_0x256304){return BPromise[_0xd29c('0x27')](_0x256304);}return _0x3986a6[_0xd29c('0x28')]();};}function saveUpdates(_0x144b2f,_0x5c7559){return function(_0x46a284){if(_0x46a284){return _0x46a284[_0xd29c('0x29')](_0x144b2f)[_0xd29c('0x2a')](function(_0x98b035){return _0x98b035;});}return null;};}function removeEntity(_0x5d1de8,_0x29392e){return function(_0x3d1b01){if(_0x3d1b01){return _0x3d1b01[_0xd29c('0x2b')]()[_0xd29c('0x2a')](function(){_0x5d1de8['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x17aa3a,_0x511a23){return function(_0x368ea8){if(!_0x368ea8){_0x17aa3a[_0xd29c('0x2c')](0x194);}return _0x368ea8;};}function handleError(_0x4ffb24,_0x1890bb){_0x1890bb=_0x1890bb||0x1f4;return function(_0x5854e1){logger[_0xd29c('0x1e')](_0x5854e1[_0xd29c('0x2d')]);if(_0x5854e1[_0xd29c('0x2e')]){delete _0x5854e1[_0xd29c('0x2e')];}_0x4ffb24[_0xd29c('0x21')](_0x1890bb)[_0xd29c('0x2f')](_0x5854e1);};}exports[_0xd29c('0x30')]=function(_0x4c0ff6,_0x52a143){var _0x51bb10={},_0x303370={},_0x33c870={'count':0x0,'rows':[]};var _0x3ea2d2=_[_0xd29c('0x31')](db[_0xd29c('0x32')][_0xd29c('0x33')],function(_0x37c611){return{'name':_0x37c611['fieldName'],'type':_0x37c611[_0xd29c('0x34')][_0xd29c('0x35')]};});_0x303370[_0xd29c('0x36')]=_[_0xd29c('0x31')](_0x3ea2d2,_0xd29c('0x2e'));_0x303370['query']=_['keys'](_0x4c0ff6[_0xd29c('0x37')]);_0x303370[_0xd29c('0x38')]=_[_0xd29c('0x39')](_0x303370[_0xd29c('0x36')],_0x303370[_0xd29c('0x37')]);_0x51bb10[_0xd29c('0x3a')]=_[_0xd29c('0x39')](_0x303370[_0xd29c('0x36')],qs['fields'](_0x4c0ff6[_0xd29c('0x37')]['fields']));_0x51bb10[_0xd29c('0x3a')]=_0x51bb10[_0xd29c('0x3a')][_0xd29c('0x3b')]?_0x51bb10[_0xd29c('0x3a')]:_0x303370['model'];if(!_0x4c0ff6[_0xd29c('0x37')]['hasOwnProperty']('nolimit')){_0x51bb10[_0xd29c('0x3c')]=qs['limit'](_0x4c0ff6['query']['limit']);_0x51bb10[_0xd29c('0x23')]=qs['offset'](_0x4c0ff6[_0xd29c('0x37')][_0xd29c('0x23')]);}_0x51bb10[_0xd29c('0x3d')]=qs[_0xd29c('0x3e')](_0x4c0ff6['query'][_0xd29c('0x3e')]);_0x51bb10[_0xd29c('0x3f')]=qs[_0xd29c('0x38')](_['pick'](_0x4c0ff6[_0xd29c('0x37')],_0x303370[_0xd29c('0x38')]),_0x3ea2d2);if(_0x4c0ff6[_0xd29c('0x37')]['filter']){_0x51bb10[_0xd29c('0x3f')]=_['merge'](_0x51bb10[_0xd29c('0x3f')],{'$or':_[_0xd29c('0x31')](_0x3ea2d2,function(_0x518eca){if(_0x518eca[_0xd29c('0x34')]!==_0xd29c('0x40')){var _0x5499cb={};_0x5499cb[_0x518eca[_0xd29c('0x2e')]]={'$like':'%'+_0x4c0ff6[_0xd29c('0x37')][_0xd29c('0x41')]+'%'};return _0x5499cb;}})});}_0x51bb10=_[_0xd29c('0x42')]({},_0x51bb10,_0x4c0ff6[_0xd29c('0x43')]);var _0xfb670b={'where':_0x51bb10[_0xd29c('0x3f')]};return db[_0xd29c('0x32')]['count'](_0xfb670b)['then'](function(_0x710849){_0x33c870[_0xd29c('0x44')]=_0x710849;if(_0x4c0ff6[_0xd29c('0x37')][_0xd29c('0x45')]){_0x51bb10['include']=[{'all':!![]}];}return db['FreshdeskAccount']['findAll'](_0x51bb10);})[_0xd29c('0x2a')](function(_0x2207b4){_0x33c870[_0xd29c('0x46')]=_0x2207b4;return _0x33c870;})[_0xd29c('0x2a')](respondWithFilteredResult(_0x52a143,_0x51bb10))[_0xd29c('0x47')](handleError(_0x52a143,null));};exports['show']=function(_0x214c96,_0x596fa4){var _0x1460b1={'raw':![],'where':{'id':_0x214c96[_0xd29c('0x48')]['id']}},_0x5d66d7={};_0x5d66d7[_0xd29c('0x36')]=_[_0xd29c('0x49')](db[_0xd29c('0x32')][_0xd29c('0x33')]);_0x5d66d7[_0xd29c('0x37')]=_[_0xd29c('0x49')](_0x214c96[_0xd29c('0x37')]);_0x5d66d7['filters']=_['intersection'](_0x5d66d7['model'],_0x5d66d7[_0xd29c('0x37')]);_0x1460b1['attributes']=_[_0xd29c('0x39')](_0x5d66d7[_0xd29c('0x36')],qs[_0xd29c('0x4a')](_0x214c96[_0xd29c('0x37')]['fields']));_0x1460b1[_0xd29c('0x3a')]=_0x1460b1[_0xd29c('0x3a')]['length']?_0x1460b1[_0xd29c('0x3a')]:_0x5d66d7['model'];if(_0x214c96['query'][_0xd29c('0x45')]){_0x1460b1['include']=[{'all':!![]}];}_0x1460b1=_['merge']({},_0x1460b1,_0x214c96['options']);return db[_0xd29c('0x32')]['find'](_0x1460b1)[_0xd29c('0x2a')](handleEntityNotFound(_0x596fa4,null))[_0xd29c('0x2a')](respondWithResult(_0x596fa4,null))['catch'](handleError(_0x596fa4,null));};exports[_0xd29c('0x4b')]=function(_0x17f2a8,_0xc69258){return db['FreshdeskAccount'][_0xd29c('0x4b')](_0x17f2a8[_0xd29c('0x4c')],{})[_0xd29c('0x2a')](respondWithResult(_0xc69258,0xc9))['catch'](handleError(_0xc69258,null));};exports[_0xd29c('0x29')]=function(_0x218a20,_0x486844){if(_0x218a20['body']['id']){delete _0x218a20[_0xd29c('0x4c')]['id'];}return db[_0xd29c('0x32')]['find']({'where':{'id':_0x218a20[_0xd29c('0x48')]['id']}})[_0xd29c('0x2a')](handleEntityNotFound(_0x486844,null))['then'](saveUpdates(_0x218a20[_0xd29c('0x4c')],null))['then'](respondWithResult(_0x486844,null))[_0xd29c('0x47')](handleError(_0x486844,null));};exports[_0xd29c('0x2b')]=function(_0x2534a3,_0x11dadf){return db[_0xd29c('0x32')][_0xd29c('0x4d')]({'where':{'id':_0x2534a3[_0xd29c('0x48')]['id']}})[_0xd29c('0x2a')](handleEntityNotFound(_0x11dadf,null))[_0xd29c('0x2a')](removeEntity(_0x11dadf,null))[_0xd29c('0x47')](handleError(_0x11dadf,null));};exports[_0xd29c('0x4e')]=function(_0x2b6a9c,_0x23b756,_0x33680c){var _0x59be15={};var _0x22949b={};var _0x58322c;var _0x7fdcd0;return db[_0xd29c('0x32')][_0xd29c('0x4f')]({'where':{'id':_0x2b6a9c['params']['id']}})[_0xd29c('0x2a')](handleEntityNotFound(_0x23b756,null))[_0xd29c('0x2a')](function(_0x5c1e46){if(_0x5c1e46){_0x58322c=_0x5c1e46;_0x22949b[_0xd29c('0x36')]=_[_0xd29c('0x49')](db[_0xd29c('0x50')][_0xd29c('0x33')]);_0x22949b[_0xd29c('0x37')]=_[_0xd29c('0x49')](_0x2b6a9c[_0xd29c('0x37')]);_0x22949b[_0xd29c('0x38')]=_[_0xd29c('0x39')](_0x22949b[_0xd29c('0x36')],_0x22949b[_0xd29c('0x37')]);_0x59be15[_0xd29c('0x3a')]=_['intersection'](_0x22949b['model'],qs['fields'](_0x2b6a9c[_0xd29c('0x37')]['fields']));_0x59be15[_0xd29c('0x3a')]=_0x59be15[_0xd29c('0x3a')]['length']?_0x59be15[_0xd29c('0x3a')]:_0x22949b['model'];_0x59be15[_0xd29c('0x3d')]=qs[_0xd29c('0x3e')](_0x2b6a9c[_0xd29c('0x37')][_0xd29c('0x3e')]);_0x59be15['where']=qs[_0xd29c('0x38')](_['pick'](_0x2b6a9c[_0xd29c('0x37')],_0x22949b[_0xd29c('0x38')]));if(_0x2b6a9c[_0xd29c('0x37')][_0xd29c('0x41')]){_0x59be15[_0xd29c('0x3f')]=_[_0xd29c('0x42')](_0x59be15['where'],{'$or':_[_0xd29c('0x31')](_0x59be15[_0xd29c('0x3a')],function(_0xbde5ca){var _0x42fec5={};_0x42fec5[_0xbde5ca]={'$like':'%'+_0x2b6a9c[_0xd29c('0x37')][_0xd29c('0x41')]+'%'};return _0x42fec5;})});}_0x59be15=_[_0xd29c('0x42')]({},_0x59be15,_0x2b6a9c[_0xd29c('0x43')]);return _0x58322c[_0xd29c('0x4e')](_0x59be15);}})[_0xd29c('0x2a')](function(_0x3eae6b){if(_0x3eae6b){_0x7fdcd0=_0x3eae6b[_0xd29c('0x3b')];if(!_0x2b6a9c[_0xd29c('0x37')][_0xd29c('0x51')](_0xd29c('0x52'))){_0x59be15[_0xd29c('0x3c')]=qs['limit'](_0x2b6a9c[_0xd29c('0x37')][_0xd29c('0x3c')]);_0x59be15[_0xd29c('0x23')]=qs[_0xd29c('0x23')](_0x2b6a9c['query']['offset']);}return _0x58322c[_0xd29c('0x4e')](_0x59be15);}})['then'](function(_0x16609b){if(_0x16609b){return _0x16609b?{'count':_0x7fdcd0,'rows':_0x16609b}:null;}})['then'](respondWithResult(_0x23b756,null))['catch'](handleError(_0x23b756,null));};exports['addConfiguration']=function(_0x18a528,_0x2ef948,_0x411046){if(_0x18a528['body']['id']){delete _0x18a528[_0xd29c('0x4c')]['id'];}return db[_0xd29c('0x32')][_0xd29c('0x4f')]({'where':{'id':_0x18a528[_0xd29c('0x48')]['id']}})[_0xd29c('0x2a')](handleEntityNotFound(_0x2ef948,null))[_0xd29c('0x2a')](function(_0x25664f){if(_0x25664f){_0x18a528[_0xd29c('0x4c')][_0xd29c('0x53')]=_0x25664f['id'];_0x18a528[_0xd29c('0x4c')][_0xd29c('0x54')]=integrations[_0xd29c('0x55')](_0x18a528[_0xd29c('0x4c')][_0xd29c('0x56')],_0x18a528[_0xd29c('0x4c')]['type']);_0x18a528[_0xd29c('0x4c')][_0xd29c('0x57')]=integrations[_0xd29c('0x58')](_0x18a528[_0xd29c('0x4c')][_0xd29c('0x56')],_0x18a528[_0xd29c('0x4c')][_0xd29c('0x34')]);return db[_0xd29c('0x50')]['create'](_0x18a528[_0xd29c('0x4c')],{'include':[{'model':db[_0xd29c('0x59')],'as':_0xd29c('0x54')},{'model':db[_0xd29c('0x59')],'as':'Descriptions'}]});}return null;})[_0xd29c('0x2a')](respondWithResult(_0x2ef948,null))[_0xd29c('0x47')](handleError(_0x2ef948,null));};exports['getFields']=function(_0x232d2e,_0x1ae40a,_0xc73fd6){var _0x335d65='';return db[_0xd29c('0x32')][_0xd29c('0x4f')]({'where':{'id':_0x232d2e[_0xd29c('0x48')]['id']},'attributes':['id',_0xd29c('0x5a'),'apiKey']})[_0xd29c('0x2a')](handleEntityNotFound(_0x1ae40a,null))[_0xd29c('0x2a')](function(_0x555c92){if(_0x555c92){_0x335d65=_0x555c92[_0xd29c('0x5a')];var _0x350030=_0x335d65['slice'](-0x1);if(_0x350030==='/'){_0x335d65=_0x335d65[_0xd29c('0x5b')](0x0,_0x335d65[_0xd29c('0x5c')](_0x350030));}return rp({'method':_0xd29c('0x5d'),'uri':util['format'](_0xd29c('0x5e'),_0x335d65,_0xd29c('0x5f')),'headers':{'Authorization':util['format']('Basic\x20%s',new Buffer(util[_0xd29c('0x60')](_0xd29c('0x61'),_0x555c92[_0xd29c('0x62')]))[_0xd29c('0x63')](_0xd29c('0x64')))},'json':!![]});}})[_0xd29c('0x2a')](function(_0x5a6f66){if(_0x5a6f66){var _0x205094=[_0xd29c('0x65'),_0xd29c('0x66'),_0xd29c('0x67'),_0xd29c('0x68'),_0xd29c('0x21'),'priority',_0xd29c('0x69'),_0xd29c('0x6a'),_0xd29c('0x6b'),_0xd29c('0x69'),_0xd29c('0x6c')];_[_0xd29c('0x6d')](_0x5a6f66,function(_0x10dc35){return _0x205094[_0xd29c('0x6e')](_0x10dc35[_0xd29c('0x2e')])||!_0x10dc35[_0xd29c('0x6f')]&&_0x10dc35[_0xd29c('0x34')]!=='custom_text'&&_0x10dc35[_0xd29c('0x34')]!==_0xd29c('0x70');});return{'count':_0x5a6f66[_0xd29c('0x3b')],'rows':_['map'](_0x5a6f66,function(_0x2d72fd){return{'id':_0x2d72fd[_0xd29c('0x2e')],'name':_0x2d72fd[_0xd29c('0x71')],'custom':!_0x2d72fd[_0xd29c('0x6f')],'options':_0x2d72fd[_0xd29c('0x72')]?_[_0xd29c('0x31')](_0x2d72fd[_0xd29c('0x72')],function(_0xc8b870){return{'name':_[_0xd29c('0x73')](_0xc8b870),'value':_0xc8b870};}):[]};})};}})[_0xd29c('0x2a')](respondWithResult(_0x1ae40a,null))[_0xd29c('0x47')](function(_0x4b1eeb){var _0x4bd4b2=_0x232d2e[_0xd29c('0x37')][_0xd29c('0x74')]?0x1f4:_0x4b1eeb[_0xd29c('0x75')]||0x1f4;logger[_0xd29c('0x1e')]('getFields,\x20%s,\x20%s,\x20%s',_0xd29c('0x76'),_0x4bd4b2,JSON[_0xd29c('0x77')](_0x4b1eeb));delete _0x4b1eeb[_0xd29c('0x2e')];if(_0x4bd4b2===0x191){_0x4bd4b2=0x190;}_0x1ae40a['status'](_0x4bd4b2)[_0xd29c('0x2f')](_0x232d2e[_0xd29c('0x37')][_0xd29c('0x74')]?{'message':_0xd29c('0x78'),'statusCode':_0x4b1eeb['statusCode']}:_0x4b1eeb);});};
\ 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