Built motion from commit c116dc8b.|2.6.30
[motion2.git] / server / api / intFreshdeskAccount / intFreshdeskAccount.controller.js
index 152bfda..c919ae6 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x4984=['default','custom_text','label','choices','capitalize','test','statusCode','Wrong\x20credentials','eml-format','rimraf','zip-dir','moment','mustache','ejs','crypto','jsforce','desk.js','to-csv','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/utils','../../config/license/util','../../mysqldb','../../components/integrations/configuration','jayson/promise','client','request','then','info','request\x20sent','FreshdeskAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','FreshdeskAccount,\x20%s,\x20%s','result','sendStatus','status','end','json','offset','limit','Content-Range','apply','save','update','destroy','name','send','map','FreshdeskAccount','rawAttributes','fieldName','type','key','model','keys','query','filters','attributes','fields','length','hasOwnProperty','nolimit','sort','where','filter','VIRTUAL','merge','options','count','includeAll','include','findAll','rows','catch','show','params','intersection','create','body','find','getConfigurations','findOne','FreshdeskConfiguration','order','pick','addConfiguration','AccountId','getSubjects','getDescriptions','channel','FreshdeskField','Subjects','Descriptions','getFields','remoteUri','apiKey','slice','substring','lastIndexOf','GET','format','%s/%s','api/v2/ticket_fields','base64','agent','group','source','company','remove'];(function(_0x114cde,_0x309623){var _0x54ac80=function(_0x15cac3){while(--_0x15cac3){_0x114cde['push'](_0x114cde['shift']());}};_0x54ac80(++_0x309623);}(_0x4984,0xee));var _0x4498=function(_0x1cf07c,_0xaca006){_0x1cf07c=_0x1cf07c-0x0;var _0x5627d8=_0x4984[_0x1cf07c];return _0x5627d8;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x4498('0x0'));var rimraf=require(_0x4498('0x1'));var zipdir=require(_0x4498('0x2'));var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require(_0x4498('0x3'));var BPromise=require('bluebird');var Mustache=require(_0x4498('0x4'));var util=require('util');var path=require('path');var sox=require('sox');var csv=require('to-csv');var ejs=require(_0x4498('0x5'));var fs=require('fs');var _=require('lodash');var squel=require('squel');var crypto=require(_0x4498('0x6'));var jsforce=require(_0x4498('0x7'));var deskjs=require(_0x4498('0x8'));var toCsv=require(_0x4498('0x9'));var querystring=require(_0x4498('0xa'));var Papa=require(_0x4498('0xb'));var Redis=require('ioredis');var authService=require(_0x4498('0xc'));var qs=require(_0x4498('0xd'));var as=require(_0x4498('0xe'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')('api');var utils=require(_0x4498('0xf'));var config=require('../../config/environment');var licenseUtil=require(_0x4498('0x10'));var db=require(_0x4498('0x11'))['db'];var integrations=require(_0x4498('0x12'));var jayson=require(_0x4498('0x13'));var client=jayson[_0x4498('0x14')]['http']({'port':0x232a});function respondWithRpcPromise(_0x4b71aa,_0x197502,_0x43eea5,_0x1978ff){return new BPromise(function(_0x525b3b,_0x731627){var _0x44f8ca=_0x1978ff||client;return _0x44f8ca[_0x4498('0x15')](_0x4b71aa,_0x43eea5)[_0x4498('0x16')](function(_0xc947f3){logger[_0x4498('0x17')]('FreshdeskAccount,\x20%s,\x20%s',_0x197502,_0x4498('0x18'));logger['debug'](_0x4498('0x19'),_0x197502,_0x4498('0x18'),JSON[_0x4498('0x1a')](_0xc947f3));if(_0xc947f3[_0x4498('0x1b')]){if(_0xc947f3[_0x4498('0x1b')][_0x4498('0x1c')]===0x1f4){logger['error']('FreshdeskAccount,\x20%s,\x20%s',_0x197502,_0xc947f3['error'][_0x4498('0x1d')]);return _0x731627(_0xc947f3['error']['message']);}logger['error'](_0x4498('0x1e'),_0x197502,_0xc947f3[_0x4498('0x1b')][_0x4498('0x1d')]);return _0x525b3b(_0xc947f3[_0x4498('0x1b')][_0x4498('0x1d')]);}else{logger[_0x4498('0x17')](_0x4498('0x1e'),_0x197502,_0x4498('0x18'));_0x525b3b(_0xc947f3[_0x4498('0x1f')][_0x4498('0x1d')]);}})['catch'](function(_0x4d3c26){logger[_0x4498('0x1b')](_0x4498('0x1e'),_0x197502,_0x4d3c26);_0x731627(_0x4d3c26);});});}function respondWithStatusCode(_0x196dc7,_0x241283){_0x241283=_0x241283||0xcc;return function(_0x1fa7b9){if(_0x1fa7b9){return _0x196dc7[_0x4498('0x20')](_0x241283);}return _0x196dc7[_0x4498('0x21')](_0x241283)[_0x4498('0x22')]();};}function respondWithResult(_0x232995,_0x5a28ca){_0x5a28ca=_0x5a28ca||0xc8;return function(_0x1a973d){if(_0x1a973d){return _0x232995['status'](_0x5a28ca)[_0x4498('0x23')](_0x1a973d);}};}function respondWithFilteredResult(_0x48ac8f,_0x360b6c){return function(_0x389f73){if(_0x389f73){var _0x1c49a4=_0x389f73['count'],_0x1f1d76=_0x360b6c[_0x4498('0x24')],_0x2e6091=_0x360b6c['offset']+_0x360b6c[_0x4498('0x25')],_0x8263e2;if(_0x2e6091>=_0x1c49a4){_0x2e6091=_0x1c49a4;_0x8263e2=0xc8;}else{_0x8263e2=0xce;}_0x48ac8f[_0x4498('0x21')](_0x8263e2);return _0x48ac8f['set'](_0x4498('0x26'),_0x1f1d76+'-'+_0x2e6091+'/'+_0x1c49a4)[_0x4498('0x23')](_0x389f73);}return null;};}function patchUpdates(_0x301b3b){return function(_0x4b1795){try{jsonpatch[_0x4498('0x27')](_0x4b1795,_0x301b3b,!![]);}catch(_0x539073){return BPromise['reject'](_0x539073);}return _0x4b1795[_0x4498('0x28')]();};}function saveUpdates(_0x359c30,_0x2bab5f){return function(_0x3b805f){if(_0x3b805f){return _0x3b805f[_0x4498('0x29')](_0x359c30)['then'](function(_0x3f4511){return _0x3f4511;});}return null;};}function removeEntity(_0x3d73a9,_0x4a502c){return function(_0x19ca31){if(_0x19ca31){return _0x19ca31[_0x4498('0x2a')]()['then'](function(){_0x3d73a9[_0x4498('0x21')](0xcc)[_0x4498('0x22')]();});}};}function handleEntityNotFound(_0x9cec77,_0x8e6566){return function(_0x1d64b7){if(!_0x1d64b7){_0x9cec77[_0x4498('0x20')](0x194);}return _0x1d64b7;};}function handleError(_0x1a7aa5,_0x5aa8f5){_0x5aa8f5=_0x5aa8f5||0x1f4;return function(_0x3dbdc9){logger[_0x4498('0x1b')](_0x3dbdc9['stack']);if(_0x3dbdc9[_0x4498('0x2b')]){delete _0x3dbdc9[_0x4498('0x2b')];}_0x1a7aa5[_0x4498('0x21')](_0x5aa8f5)[_0x4498('0x2c')](_0x3dbdc9);};}exports['index']=function(_0x182ed9,_0x59a688){var _0x1ebcca={},_0x563a20={},_0x2ec270={'count':0x0,'rows':[]};var _0x2109cd=_[_0x4498('0x2d')](db[_0x4498('0x2e')][_0x4498('0x2f')],function(_0x47a8b7){return{'name':_0x47a8b7[_0x4498('0x30')],'type':_0x47a8b7[_0x4498('0x31')][_0x4498('0x32')]};});_0x563a20[_0x4498('0x33')]=_['map'](_0x2109cd,_0x4498('0x2b'));_0x563a20['query']=_[_0x4498('0x34')](_0x182ed9[_0x4498('0x35')]);_0x563a20[_0x4498('0x36')]=_['intersection'](_0x563a20[_0x4498('0x33')],_0x563a20[_0x4498('0x35')]);_0x1ebcca[_0x4498('0x37')]=_['intersection'](_0x563a20[_0x4498('0x33')],qs['fields'](_0x182ed9[_0x4498('0x35')][_0x4498('0x38')]));_0x1ebcca[_0x4498('0x37')]=_0x1ebcca[_0x4498('0x37')][_0x4498('0x39')]?_0x1ebcca[_0x4498('0x37')]:_0x563a20['model'];if(!_0x182ed9[_0x4498('0x35')][_0x4498('0x3a')](_0x4498('0x3b'))){_0x1ebcca[_0x4498('0x25')]=qs[_0x4498('0x25')](_0x182ed9[_0x4498('0x35')]['limit']);_0x1ebcca[_0x4498('0x24')]=qs[_0x4498('0x24')](_0x182ed9[_0x4498('0x35')][_0x4498('0x24')]);}_0x1ebcca['order']=qs['sort'](_0x182ed9[_0x4498('0x35')][_0x4498('0x3c')]);_0x1ebcca[_0x4498('0x3d')]=qs['filters'](_['pick'](_0x182ed9[_0x4498('0x35')],_0x563a20[_0x4498('0x36')]),_0x2109cd);if(_0x182ed9[_0x4498('0x35')][_0x4498('0x3e')]){_0x1ebcca[_0x4498('0x3d')]=_['merge'](_0x1ebcca[_0x4498('0x3d')],{'$or':_['map'](_0x2109cd,function(_0x221c8c){if(_0x221c8c[_0x4498('0x31')]!==_0x4498('0x3f')){var _0x12a364={};_0x12a364[_0x221c8c[_0x4498('0x2b')]]={'$like':'%'+_0x182ed9[_0x4498('0x35')]['filter']+'%'};return _0x12a364;}})});}_0x1ebcca=_[_0x4498('0x40')]({},_0x1ebcca,_0x182ed9[_0x4498('0x41')]);var _0x11e1c2={'where':_0x1ebcca[_0x4498('0x3d')]};return db[_0x4498('0x2e')][_0x4498('0x42')](_0x11e1c2)[_0x4498('0x16')](function(_0x1ca45d){_0x2ec270['count']=_0x1ca45d;if(_0x182ed9[_0x4498('0x35')][_0x4498('0x43')]){_0x1ebcca[_0x4498('0x44')]=[{'all':!![]}];}return db[_0x4498('0x2e')][_0x4498('0x45')](_0x1ebcca);})[_0x4498('0x16')](function(_0x25920a){_0x2ec270[_0x4498('0x46')]=_0x25920a;return _0x2ec270;})[_0x4498('0x16')](respondWithFilteredResult(_0x59a688,_0x1ebcca))[_0x4498('0x47')](handleError(_0x59a688,null));};exports[_0x4498('0x48')]=function(_0x36daad,_0x9c8471){var _0x55a218={'raw':![],'where':{'id':_0x36daad[_0x4498('0x49')]['id']}},_0xd05da1={};_0xd05da1[_0x4498('0x33')]=_[_0x4498('0x34')](db[_0x4498('0x2e')][_0x4498('0x2f')]);_0xd05da1['query']=_[_0x4498('0x34')](_0x36daad[_0x4498('0x35')]);_0xd05da1[_0x4498('0x36')]=_[_0x4498('0x4a')](_0xd05da1[_0x4498('0x33')],_0xd05da1[_0x4498('0x35')]);_0x55a218[_0x4498('0x37')]=_[_0x4498('0x4a')](_0xd05da1[_0x4498('0x33')],qs[_0x4498('0x38')](_0x36daad[_0x4498('0x35')][_0x4498('0x38')]));_0x55a218['attributes']=_0x55a218[_0x4498('0x37')][_0x4498('0x39')]?_0x55a218[_0x4498('0x37')]:_0xd05da1[_0x4498('0x33')];if(_0x36daad[_0x4498('0x35')][_0x4498('0x43')]){_0x55a218[_0x4498('0x44')]=[{'all':!![]}];}_0x55a218=_[_0x4498('0x40')]({},_0x55a218,_0x36daad[_0x4498('0x41')]);return db[_0x4498('0x2e')]['find'](_0x55a218)[_0x4498('0x16')](handleEntityNotFound(_0x9c8471,null))[_0x4498('0x16')](respondWithResult(_0x9c8471,null))[_0x4498('0x47')](handleError(_0x9c8471,null));};exports['create']=function(_0x520f11,_0x2620f0){return db[_0x4498('0x2e')][_0x4498('0x4b')](_0x520f11['body'],{})[_0x4498('0x16')](respondWithResult(_0x2620f0,0xc9))[_0x4498('0x47')](handleError(_0x2620f0,null));};exports[_0x4498('0x29')]=function(_0x4bc845,_0x1706b5){if(_0x4bc845[_0x4498('0x4c')]['id']){delete _0x4bc845[_0x4498('0x4c')]['id'];}return db[_0x4498('0x2e')][_0x4498('0x4d')]({'where':{'id':_0x4bc845[_0x4498('0x49')]['id']}})['then'](handleEntityNotFound(_0x1706b5,null))['then'](saveUpdates(_0x4bc845[_0x4498('0x4c')],null))[_0x4498('0x16')](respondWithResult(_0x1706b5,null))[_0x4498('0x47')](handleError(_0x1706b5,null));};exports[_0x4498('0x2a')]=function(_0x1264a2,_0xf79e42){return db['FreshdeskAccount'][_0x4498('0x4d')]({'where':{'id':_0x1264a2[_0x4498('0x49')]['id']}})[_0x4498('0x16')](handleEntityNotFound(_0xf79e42,null))['then'](removeEntity(_0xf79e42,null))[_0x4498('0x47')](handleError(_0xf79e42,null));};exports[_0x4498('0x4e')]=function(_0x1f7e50,_0x5a71a5,_0x44d3d4){var _0x174a2a={};var _0x5d86ce={};var _0x17b6b8;var _0x3a295d;return db['FreshdeskAccount'][_0x4498('0x4f')]({'where':{'id':_0x1f7e50['params']['id']}})[_0x4498('0x16')](handleEntityNotFound(_0x5a71a5,null))[_0x4498('0x16')](function(_0x2a7e09){if(_0x2a7e09){_0x17b6b8=_0x2a7e09;_0x5d86ce['model']=_['keys'](db[_0x4498('0x50')][_0x4498('0x2f')]);_0x5d86ce[_0x4498('0x35')]=_['keys'](_0x1f7e50[_0x4498('0x35')]);_0x5d86ce[_0x4498('0x36')]=_[_0x4498('0x4a')](_0x5d86ce[_0x4498('0x33')],_0x5d86ce[_0x4498('0x35')]);_0x174a2a[_0x4498('0x37')]=_[_0x4498('0x4a')](_0x5d86ce['model'],qs['fields'](_0x1f7e50[_0x4498('0x35')][_0x4498('0x38')]));_0x174a2a[_0x4498('0x37')]=_0x174a2a[_0x4498('0x37')][_0x4498('0x39')]?_0x174a2a['attributes']:_0x5d86ce['model'];_0x174a2a[_0x4498('0x51')]=qs['sort'](_0x1f7e50[_0x4498('0x35')][_0x4498('0x3c')]);_0x174a2a[_0x4498('0x3d')]=qs[_0x4498('0x36')](_[_0x4498('0x52')](_0x1f7e50[_0x4498('0x35')],_0x5d86ce[_0x4498('0x36')]));if(_0x1f7e50['query'][_0x4498('0x3e')]){_0x174a2a[_0x4498('0x3d')]=_[_0x4498('0x40')](_0x174a2a[_0x4498('0x3d')],{'$or':_[_0x4498('0x2d')](_0x174a2a[_0x4498('0x37')],function(_0x2e36ec){var _0x24cb74={};_0x24cb74[_0x2e36ec]={'$like':'%'+_0x1f7e50['query'][_0x4498('0x3e')]+'%'};return _0x24cb74;})});}_0x174a2a=_[_0x4498('0x40')]({},_0x174a2a,_0x1f7e50[_0x4498('0x41')]);return _0x17b6b8['getConfigurations'](_0x174a2a);}})[_0x4498('0x16')](function(_0x2c0d64){if(_0x2c0d64){_0x3a295d=_0x2c0d64[_0x4498('0x39')];if(!_0x1f7e50[_0x4498('0x35')][_0x4498('0x3a')]('nolimit')){_0x174a2a[_0x4498('0x25')]=qs[_0x4498('0x25')](_0x1f7e50[_0x4498('0x35')]['limit']);_0x174a2a[_0x4498('0x24')]=qs[_0x4498('0x24')](_0x1f7e50[_0x4498('0x35')][_0x4498('0x24')]);}return _0x17b6b8[_0x4498('0x4e')](_0x174a2a);}})[_0x4498('0x16')](function(_0x46f0ca){if(_0x46f0ca){return _0x46f0ca?{'count':_0x3a295d,'rows':_0x46f0ca}:null;}})[_0x4498('0x16')](respondWithResult(_0x5a71a5,null))[_0x4498('0x47')](handleError(_0x5a71a5,null));};exports[_0x4498('0x53')]=function(_0x181e89,_0x20776e,_0x271ef9){if(_0x181e89[_0x4498('0x4c')]['id']){delete _0x181e89[_0x4498('0x4c')]['id'];}return db['FreshdeskAccount'][_0x4498('0x4f')]({'where':{'id':_0x181e89['params']['id']}})[_0x4498('0x16')](handleEntityNotFound(_0x20776e,null))[_0x4498('0x16')](function(_0x20a900){if(_0x20a900){_0x181e89[_0x4498('0x4c')][_0x4498('0x54')]=_0x20a900['id'];_0x181e89[_0x4498('0x4c')]['Subjects']=integrations[_0x4498('0x55')](_0x181e89[_0x4498('0x4c')]['channel'],_0x181e89[_0x4498('0x4c')][_0x4498('0x31')]);_0x181e89[_0x4498('0x4c')]['Descriptions']=integrations[_0x4498('0x56')](_0x181e89['body'][_0x4498('0x57')],_0x181e89[_0x4498('0x4c')][_0x4498('0x31')]);return db['FreshdeskConfiguration'][_0x4498('0x4b')](_0x181e89['body'],{'include':[{'model':db[_0x4498('0x58')],'as':_0x4498('0x59')},{'model':db[_0x4498('0x58')],'as':_0x4498('0x5a')}]});}return null;})[_0x4498('0x16')](respondWithResult(_0x20776e,null))[_0x4498('0x47')](handleError(_0x20776e,null));};exports[_0x4498('0x5b')]=function(_0x456876,_0x4234f1,_0x580c76){var _0x1a6979='';return db[_0x4498('0x2e')][_0x4498('0x4f')]({'where':{'id':_0x456876[_0x4498('0x49')]['id']},'attributes':['id',_0x4498('0x5c'),_0x4498('0x5d')]})[_0x4498('0x16')](handleEntityNotFound(_0x4234f1,null))[_0x4498('0x16')](function(_0x2dd67f){if(_0x2dd67f){_0x1a6979=_0x2dd67f[_0x4498('0x5c')];var _0x2fd9e5=_0x1a6979[_0x4498('0x5e')](-0x1);if(_0x2fd9e5==='/'){_0x1a6979=_0x1a6979[_0x4498('0x5f')](0x0,_0x1a6979[_0x4498('0x60')](_0x2fd9e5));}return rp({'method':_0x4498('0x61'),'uri':util[_0x4498('0x62')](_0x4498('0x63'),_0x1a6979,_0x4498('0x64')),'headers':{'Authorization':util[_0x4498('0x62')]('Basic\x20%s',new Buffer(util[_0x4498('0x62')]('%s:X',_0x2dd67f['apiKey']))['toString'](_0x4498('0x65')))},'json':!![]});}})[_0x4498('0x16')](function(_0x4b37c0){if(_0x4b37c0){var _0x563003=['requester','subject',_0x4498('0x66'),'description',_0x4498('0x21'),'priority',_0x4498('0x67'),_0x4498('0x68'),'ticket_type',_0x4498('0x67'),_0x4498('0x69')];_[_0x4498('0x6a')](_0x4b37c0,function(_0x3b3f5b){return _0x563003['includes'](_0x3b3f5b['name'])||!_0x3b3f5b[_0x4498('0x6b')]&&_0x3b3f5b['type']!==_0x4498('0x6c')&&_0x3b3f5b[_0x4498('0x31')]!=='custom_dropdown';});return{'count':_0x4b37c0[_0x4498('0x39')],'rows':_['map'](_0x4b37c0,function(_0x44788e){return{'id':_0x44788e[_0x4498('0x2b')],'name':_0x44788e[_0x4498('0x6d')],'custom':!_0x44788e[_0x4498('0x6b')],'options':_0x44788e[_0x4498('0x6e')]?_[_0x4498('0x2d')](_0x44788e[_0x4498('0x6e')],function(_0x272836){return{'name':_[_0x4498('0x6f')](_0x272836),'value':_0x272836};}):[]};})};}})[_0x4498('0x16')](respondWithResult(_0x4234f1,null))[_0x4498('0x47')](function(_0x1adc45){var _0x21b3f7=_0x456876[_0x4498('0x35')][_0x4498('0x70')]?0x1f4:_0x1adc45[_0x4498('0x71')]||0x1f4;logger[_0x4498('0x1b')]('getFields,\x20%s,\x20%s,\x20%s',_0x4498('0x5b'),_0x21b3f7,JSON[_0x4498('0x1a')](_0x1adc45));delete _0x1adc45[_0x4498('0x2b')];if(_0x21b3f7===0x191){_0x21b3f7=0x190;}_0x4234f1['status'](_0x21b3f7)[_0x4498('0x2c')](_0x456876['query']['test']?{'message':_0x4498('0x72'),'statusCode':_0x1adc45[_0x4498('0x71')]}:_0x1adc45);});};
\ No newline at end of file
+var _0x5e14=['request-promise','moment','bluebird','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/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','../../components/integrations/configuration','sendStatus','status','end','undefined','limit','count','offset','set','Content-Range','json','apply','reject','save','update','then','destroy','error','stack','name','index','map','FreshdeskAccount','rawAttributes','fieldName','key','query','keys','intersection','attributes','fields','model','sort','pick','filters','where','filter','merge','options','include','findAll','rows','show','params','includeAll','find','create','body','catch','getConfigurations','findOne','FreshdeskConfiguration','length','hasOwnProperty','nolimit','addConfiguration','AccountId','Subjects','getSubjects','channel','type','getDescriptions','FreshdeskField','Descriptions','getFields','remoteUri','apiKey','slice','lastIndexOf','GET','format','api/v2/ticket_fields','%s:X','base64','requester','subject','description','priority','group','source','ticket_type','default','custom_text','custom_dropdown','choices','test','statusCode','getFields,\x20%s,\x20%s,\x20%s','stringify','send','Wrong\x20credentials','eml-format','rimraf','zip-dir','fast-json-patch'];(function(_0x4383e9,_0xa4b307){var _0x355405=function(_0x545b5b){while(--_0x545b5b){_0x4383e9['push'](_0x4383e9['shift']());}};_0x355405(++_0xa4b307);}(_0x5e14,0x164));var _0x45e1=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0x5e14[_0x3dd15e];return _0x231fd0;};'use strict';var emlformat=require(_0x45e1('0x0'));var rimraf=require(_0x45e1('0x1'));var zipdir=require(_0x45e1('0x2'));var jsonpatch=require(_0x45e1('0x3'));var rp=require(_0x45e1('0x4'));var moment=require(_0x45e1('0x5'));var BPromise=require(_0x45e1('0x6'));var Mustache=require(_0x45e1('0x7'));var util=require(_0x45e1('0x8'));var path=require(_0x45e1('0x9'));var sox=require(_0x45e1('0xa'));var csv=require(_0x45e1('0xb'));var ejs=require(_0x45e1('0xc'));var fs=require('fs');var fs_extra=require(_0x45e1('0xd'));var _=require(_0x45e1('0xe'));var squel=require(_0x45e1('0xf'));var crypto=require(_0x45e1('0x10'));var jsforce=require(_0x45e1('0x11'));var deskjs=require(_0x45e1('0x12'));var toCsv=require(_0x45e1('0xb'));var querystring=require(_0x45e1('0x13'));var Papa=require(_0x45e1('0x14'));var Redis=require('ioredis');var authService=require(_0x45e1('0x15'));var qs=require(_0x45e1('0x16'));var as=require(_0x45e1('0x17'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x45e1('0x18'))('api');var utils=require(_0x45e1('0x19'));var config=require(_0x45e1('0x1a'));var licenseUtil=require(_0x45e1('0x1b'));var db=require(_0x45e1('0x1c'))['db'];var integrations=require(_0x45e1('0x1d'));function respondWithStatusCode(_0x2ec2b9,_0x2ab53e){_0x2ab53e=_0x2ab53e||0xcc;return function(_0x59e307){if(_0x59e307){return _0x2ec2b9[_0x45e1('0x1e')](_0x2ab53e);}return _0x2ec2b9[_0x45e1('0x1f')](_0x2ab53e)[_0x45e1('0x20')]();};}function respondWithResult(_0x370297,_0x4364a0){_0x4364a0=_0x4364a0||0xc8;return function(_0x235cb9){if(_0x235cb9){return _0x370297[_0x45e1('0x1f')](_0x4364a0)['json'](_0x235cb9);}};}function respondWithFilteredResult(_0x5d9dba,_0x2de680){return function(_0x53a90e){if(_0x53a90e){var _0x5095be=typeof _0x2de680['offset']===_0x45e1('0x21')&&typeof _0x2de680[_0x45e1('0x22')]===_0x45e1('0x21');var _0x474aa2=_0x53a90e[_0x45e1('0x23')];var _0xb67f34=_0x5095be?0x0:_0x2de680[_0x45e1('0x24')];var _0x22d927=_0x5095be?_0x53a90e['count']:_0x2de680[_0x45e1('0x24')]+_0x2de680['limit'];var _0x3134f4;if(_0x22d927>=_0x474aa2){_0x22d927=_0x474aa2;_0x3134f4=0xc8;}else{_0x3134f4=0xce;}_0x5d9dba[_0x45e1('0x1f')](_0x3134f4);return _0x5d9dba[_0x45e1('0x25')](_0x45e1('0x26'),_0xb67f34+'-'+_0x22d927+'/'+_0x474aa2)[_0x45e1('0x27')](_0x53a90e);}return null;};}function patchUpdates(_0x4f4884){return function(_0x34d043){try{jsonpatch[_0x45e1('0x28')](_0x34d043,_0x4f4884,!![]);}catch(_0x44d900){return BPromise[_0x45e1('0x29')](_0x44d900);}return _0x34d043[_0x45e1('0x2a')]();};}function saveUpdates(_0x32ae6b,_0x477b12){return function(_0x2bdd53){if(_0x2bdd53){return _0x2bdd53[_0x45e1('0x2b')](_0x32ae6b)[_0x45e1('0x2c')](function(_0x2f724b){return _0x2f724b;});}return null;};}function removeEntity(_0x51fb60,_0x3847dd){return function(_0x81ea3c){if(_0x81ea3c){return _0x81ea3c[_0x45e1('0x2d')]()[_0x45e1('0x2c')](function(){_0x51fb60[_0x45e1('0x1f')](0xcc)[_0x45e1('0x20')]();});}};}function handleEntityNotFound(_0x20f986,_0xb92fc){return function(_0x5cd4c6){if(!_0x5cd4c6){_0x20f986[_0x45e1('0x1e')](0x194);}return _0x5cd4c6;};}function handleError(_0x3889bf,_0x668f14){_0x668f14=_0x668f14||0x1f4;return function(_0x284695){logger[_0x45e1('0x2e')](_0x284695[_0x45e1('0x2f')]);if(_0x284695[_0x45e1('0x30')]){delete _0x284695[_0x45e1('0x30')];}_0x3889bf[_0x45e1('0x1f')](_0x668f14)['send'](_0x284695);};}exports[_0x45e1('0x31')]=function(_0x52c7cc,_0x400a20){var _0x1b97ff={},_0x4fccf0={},_0x2f42f2={'count':0x0,'rows':[]};var _0x327b22=_[_0x45e1('0x32')](db[_0x45e1('0x33')][_0x45e1('0x34')],function(_0x290d99){return{'name':_0x290d99[_0x45e1('0x35')],'type':_0x290d99['type'][_0x45e1('0x36')]};});_0x4fccf0['model']=_[_0x45e1('0x32')](_0x327b22,_0x45e1('0x30'));_0x4fccf0[_0x45e1('0x37')]=_[_0x45e1('0x38')](_0x52c7cc['query']);_0x4fccf0['filters']=_[_0x45e1('0x39')](_0x4fccf0['model'],_0x4fccf0[_0x45e1('0x37')]);_0x1b97ff[_0x45e1('0x3a')]=_[_0x45e1('0x39')](_0x4fccf0['model'],qs[_0x45e1('0x3b')](_0x52c7cc[_0x45e1('0x37')][_0x45e1('0x3b')]));_0x1b97ff[_0x45e1('0x3a')]=_0x1b97ff[_0x45e1('0x3a')]['length']?_0x1b97ff[_0x45e1('0x3a')]:_0x4fccf0[_0x45e1('0x3c')];if(!_0x52c7cc[_0x45e1('0x37')]['hasOwnProperty']('nolimit')){_0x1b97ff[_0x45e1('0x22')]=qs[_0x45e1('0x22')](_0x52c7cc['query']['limit']);_0x1b97ff[_0x45e1('0x24')]=qs[_0x45e1('0x24')](_0x52c7cc['query'][_0x45e1('0x24')]);}_0x1b97ff['order']=qs[_0x45e1('0x3d')](_0x52c7cc[_0x45e1('0x37')][_0x45e1('0x3d')]);_0x1b97ff['where']=qs['filters'](_[_0x45e1('0x3e')](_0x52c7cc[_0x45e1('0x37')],_0x4fccf0[_0x45e1('0x3f')]),_0x327b22);if(_0x52c7cc[_0x45e1('0x37')]['filter']){_0x1b97ff['where']=_['merge'](_0x1b97ff[_0x45e1('0x40')],{'$or':_[_0x45e1('0x32')](_0x327b22,function(_0x2c1500){if(_0x2c1500['type']!=='VIRTUAL'){var _0x55f92b={};_0x55f92b[_0x2c1500[_0x45e1('0x30')]]={'$like':'%'+_0x52c7cc[_0x45e1('0x37')][_0x45e1('0x41')]+'%'};return _0x55f92b;}})});}_0x1b97ff=_[_0x45e1('0x42')]({},_0x1b97ff,_0x52c7cc[_0x45e1('0x43')]);var _0x2ef57b={'where':_0x1b97ff['where']};return db[_0x45e1('0x33')][_0x45e1('0x23')](_0x2ef57b)[_0x45e1('0x2c')](function(_0x1a070e){_0x2f42f2['count']=_0x1a070e;if(_0x52c7cc[_0x45e1('0x37')]['includeAll']){_0x1b97ff[_0x45e1('0x44')]=[{'all':!![]}];}return db['FreshdeskAccount'][_0x45e1('0x45')](_0x1b97ff);})[_0x45e1('0x2c')](function(_0xacce1d){_0x2f42f2[_0x45e1('0x46')]=_0xacce1d;return _0x2f42f2;})[_0x45e1('0x2c')](respondWithFilteredResult(_0x400a20,_0x1b97ff))['catch'](handleError(_0x400a20,null));};exports[_0x45e1('0x47')]=function(_0x1dc9fe,_0x11e45b){var _0x46feb6={'raw':![],'where':{'id':_0x1dc9fe[_0x45e1('0x48')]['id']}},_0x1c1a10={};_0x1c1a10['model']=_[_0x45e1('0x38')](db[_0x45e1('0x33')]['rawAttributes']);_0x1c1a10[_0x45e1('0x37')]=_[_0x45e1('0x38')](_0x1dc9fe[_0x45e1('0x37')]);_0x1c1a10[_0x45e1('0x3f')]=_[_0x45e1('0x39')](_0x1c1a10[_0x45e1('0x3c')],_0x1c1a10[_0x45e1('0x37')]);_0x46feb6[_0x45e1('0x3a')]=_[_0x45e1('0x39')](_0x1c1a10[_0x45e1('0x3c')],qs[_0x45e1('0x3b')](_0x1dc9fe[_0x45e1('0x37')][_0x45e1('0x3b')]));_0x46feb6[_0x45e1('0x3a')]=_0x46feb6[_0x45e1('0x3a')]['length']?_0x46feb6[_0x45e1('0x3a')]:_0x1c1a10[_0x45e1('0x3c')];if(_0x1dc9fe[_0x45e1('0x37')][_0x45e1('0x49')]){_0x46feb6[_0x45e1('0x44')]=[{'all':!![]}];}_0x46feb6=_[_0x45e1('0x42')]({},_0x46feb6,_0x1dc9fe[_0x45e1('0x43')]);return db[_0x45e1('0x33')][_0x45e1('0x4a')](_0x46feb6)[_0x45e1('0x2c')](handleEntityNotFound(_0x11e45b,null))[_0x45e1('0x2c')](respondWithResult(_0x11e45b,null))['catch'](handleError(_0x11e45b,null));};exports[_0x45e1('0x4b')]=function(_0x4a6b2e,_0x21f7e9){return db[_0x45e1('0x33')][_0x45e1('0x4b')](_0x4a6b2e[_0x45e1('0x4c')],{})['then'](respondWithResult(_0x21f7e9,0xc9))[_0x45e1('0x4d')](handleError(_0x21f7e9,null));};exports[_0x45e1('0x2b')]=function(_0x17701d,_0x22eb5c){if(_0x17701d[_0x45e1('0x4c')]['id']){delete _0x17701d[_0x45e1('0x4c')]['id'];}return db['FreshdeskAccount'][_0x45e1('0x4a')]({'where':{'id':_0x17701d[_0x45e1('0x48')]['id']}})[_0x45e1('0x2c')](handleEntityNotFound(_0x22eb5c,null))[_0x45e1('0x2c')](saveUpdates(_0x17701d['body'],null))[_0x45e1('0x2c')](respondWithResult(_0x22eb5c,null))[_0x45e1('0x4d')](handleError(_0x22eb5c,null));};exports[_0x45e1('0x2d')]=function(_0x1c1824,_0x10580e){return db[_0x45e1('0x33')][_0x45e1('0x4a')]({'where':{'id':_0x1c1824[_0x45e1('0x48')]['id']}})[_0x45e1('0x2c')](handleEntityNotFound(_0x10580e,null))[_0x45e1('0x2c')](removeEntity(_0x10580e,null))['catch'](handleError(_0x10580e,null));};exports[_0x45e1('0x4e')]=function(_0x273043,_0x3234f1,_0x2126a9){var _0x5f1be7={};var _0x2a5a99={};var _0x10d9ff;var _0x4e0bca;return db[_0x45e1('0x33')][_0x45e1('0x4f')]({'where':{'id':_0x273043[_0x45e1('0x48')]['id']}})[_0x45e1('0x2c')](handleEntityNotFound(_0x3234f1,null))[_0x45e1('0x2c')](function(_0x5e08e1){if(_0x5e08e1){_0x10d9ff=_0x5e08e1;_0x2a5a99[_0x45e1('0x3c')]=_[_0x45e1('0x38')](db[_0x45e1('0x50')][_0x45e1('0x34')]);_0x2a5a99['query']=_[_0x45e1('0x38')](_0x273043[_0x45e1('0x37')]);_0x2a5a99['filters']=_[_0x45e1('0x39')](_0x2a5a99[_0x45e1('0x3c')],_0x2a5a99[_0x45e1('0x37')]);_0x5f1be7[_0x45e1('0x3a')]=_[_0x45e1('0x39')](_0x2a5a99[_0x45e1('0x3c')],qs['fields'](_0x273043['query']['fields']));_0x5f1be7[_0x45e1('0x3a')]=_0x5f1be7['attributes'][_0x45e1('0x51')]?_0x5f1be7[_0x45e1('0x3a')]:_0x2a5a99[_0x45e1('0x3c')];_0x5f1be7['order']=qs[_0x45e1('0x3d')](_0x273043[_0x45e1('0x37')][_0x45e1('0x3d')]);_0x5f1be7[_0x45e1('0x40')]=qs[_0x45e1('0x3f')](_['pick'](_0x273043[_0x45e1('0x37')],_0x2a5a99[_0x45e1('0x3f')]));if(_0x273043[_0x45e1('0x37')][_0x45e1('0x41')]){_0x5f1be7[_0x45e1('0x40')]=_[_0x45e1('0x42')](_0x5f1be7[_0x45e1('0x40')],{'$or':_['map'](_0x5f1be7[_0x45e1('0x3a')],function(_0x256d9c){var _0x194fdd={};_0x194fdd[_0x256d9c]={'$like':'%'+_0x273043[_0x45e1('0x37')][_0x45e1('0x41')]+'%'};return _0x194fdd;})});}_0x5f1be7=_[_0x45e1('0x42')]({},_0x5f1be7,_0x273043[_0x45e1('0x43')]);return _0x10d9ff[_0x45e1('0x4e')](_0x5f1be7);}})[_0x45e1('0x2c')](function(_0x3fd1ca){if(_0x3fd1ca){_0x4e0bca=_0x3fd1ca['length'];if(!_0x273043[_0x45e1('0x37')][_0x45e1('0x52')](_0x45e1('0x53'))){_0x5f1be7[_0x45e1('0x22')]=qs['limit'](_0x273043[_0x45e1('0x37')][_0x45e1('0x22')]);_0x5f1be7['offset']=qs[_0x45e1('0x24')](_0x273043[_0x45e1('0x37')][_0x45e1('0x24')]);}return _0x10d9ff['getConfigurations'](_0x5f1be7);}})[_0x45e1('0x2c')](function(_0x5c4b49){if(_0x5c4b49){return _0x5c4b49?{'count':_0x4e0bca,'rows':_0x5c4b49}:null;}})[_0x45e1('0x2c')](respondWithResult(_0x3234f1,null))[_0x45e1('0x4d')](handleError(_0x3234f1,null));};exports[_0x45e1('0x54')]=function(_0xf19241,_0x50bde2,_0x5b0cf4){if(_0xf19241[_0x45e1('0x4c')]['id']){delete _0xf19241[_0x45e1('0x4c')]['id'];}return db[_0x45e1('0x33')]['findOne']({'where':{'id':_0xf19241[_0x45e1('0x48')]['id']}})[_0x45e1('0x2c')](handleEntityNotFound(_0x50bde2,null))[_0x45e1('0x2c')](function(_0x1e9735){if(_0x1e9735){_0xf19241['body'][_0x45e1('0x55')]=_0x1e9735['id'];_0xf19241[_0x45e1('0x4c')][_0x45e1('0x56')]=integrations[_0x45e1('0x57')](_0xf19241[_0x45e1('0x4c')][_0x45e1('0x58')],_0xf19241[_0x45e1('0x4c')][_0x45e1('0x59')]);_0xf19241[_0x45e1('0x4c')]['Descriptions']=integrations[_0x45e1('0x5a')](_0xf19241['body'][_0x45e1('0x58')],_0xf19241[_0x45e1('0x4c')]['type']);return db[_0x45e1('0x50')][_0x45e1('0x4b')](_0xf19241[_0x45e1('0x4c')],{'include':[{'model':db[_0x45e1('0x5b')],'as':_0x45e1('0x56')},{'model':db[_0x45e1('0x5b')],'as':_0x45e1('0x5c')}]});}return null;})[_0x45e1('0x2c')](respondWithResult(_0x50bde2,null))[_0x45e1('0x4d')](handleError(_0x50bde2,null));};exports[_0x45e1('0x5d')]=function(_0xdd2fd1,_0x2c2b42,_0x47218e){var _0x398cf8='';return db[_0x45e1('0x33')]['findOne']({'where':{'id':_0xdd2fd1[_0x45e1('0x48')]['id']},'attributes':['id',_0x45e1('0x5e'),_0x45e1('0x5f')]})[_0x45e1('0x2c')](handleEntityNotFound(_0x2c2b42,null))[_0x45e1('0x2c')](function(_0xf29469){if(_0xf29469){_0x398cf8=_0xf29469[_0x45e1('0x5e')];var _0x12afc0=_0x398cf8[_0x45e1('0x60')](-0x1);if(_0x12afc0==='/'){_0x398cf8=_0x398cf8['substring'](0x0,_0x398cf8[_0x45e1('0x61')](_0x12afc0));}return rp({'method':_0x45e1('0x62'),'uri':util[_0x45e1('0x63')]('%s/%s',_0x398cf8,_0x45e1('0x64')),'headers':{'Authorization':util['format']('Basic\x20%s',new Buffer(util[_0x45e1('0x63')](_0x45e1('0x65'),_0xf29469['apiKey']))['toString'](_0x45e1('0x66')))},'json':!![]});}})[_0x45e1('0x2c')](function(_0x156479){if(_0x156479){var _0xa4529f=[_0x45e1('0x67'),_0x45e1('0x68'),'agent',_0x45e1('0x69'),_0x45e1('0x1f'),_0x45e1('0x6a'),_0x45e1('0x6b'),_0x45e1('0x6c'),_0x45e1('0x6d'),_0x45e1('0x6b'),'company'];_['remove'](_0x156479,function(_0x22b3d8){return _0xa4529f['includes'](_0x22b3d8['name'])||!_0x22b3d8[_0x45e1('0x6e')]&&_0x22b3d8[_0x45e1('0x59')]!==_0x45e1('0x6f')&&_0x22b3d8[_0x45e1('0x59')]!==_0x45e1('0x70');});return{'count':_0x156479[_0x45e1('0x51')],'rows':_[_0x45e1('0x32')](_0x156479,function(_0x180f2d){return{'id':_0x180f2d[_0x45e1('0x30')],'name':_0x180f2d['label'],'custom':!_0x180f2d[_0x45e1('0x6e')],'options':_0x180f2d[_0x45e1('0x71')]?_[_0x45e1('0x32')](_0x180f2d[_0x45e1('0x71')],function(_0x5759f8){return{'name':_['capitalize'](_0x5759f8),'value':_0x5759f8};}):[]};})};}})['then'](respondWithResult(_0x2c2b42,null))[_0x45e1('0x4d')](function(_0x5700d0){var _0x3f2809=_0xdd2fd1[_0x45e1('0x37')][_0x45e1('0x72')]?0x1f4:_0x5700d0[_0x45e1('0x73')]||0x1f4;logger[_0x45e1('0x2e')](_0x45e1('0x74'),'getFields',_0x3f2809,JSON[_0x45e1('0x75')](_0x5700d0));delete _0x5700d0[_0x45e1('0x30')];if(_0x3f2809===0x191){_0x3f2809=0x190;}_0x2c2b42[_0x45e1('0x1f')](_0x3f2809)[_0x45e1('0x76')](_0xdd2fd1[_0x45e1('0x37')][_0x45e1('0x72')]?{'message':_0x45e1('0x77'),'statusCode':_0x5700d0[_0x45e1('0x73')]}:_0x5700d0);});};
\ No newline at end of file