Built motion from commit 85328c08.|2.5.50
[motion2.git] / server / api / intFreshdeskAccount / intFreshdeskAccount.controller.js
index 3aafd97..588f888 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x326f=['count','limit','set','apply','reject','save','update','destroy','end','stack','name','send','index','map','rawAttributes','fieldName','type','key','keys','query','filters','intersection','attributes','model','fields','hasOwnProperty','offset','order','sort','where','pick','filter','merge','VIRTUAL','options','includeAll','include','findAll','rows','show','params','FreshdeskAccount','create','body','find','findOne','FreshdeskConfiguration','length','nolimit','getConfigurations','AccountId','Subjects','getSubjects','channel','getDescriptions','FreshdeskField','Descriptions','getFields','remoteUri','substring','lastIndexOf','GET','%s/%s','api/v2/ticket_fields','format','Basic\x20%s','%s:X','base64','subject','description','priority','group','source','ticket_type','company','remove','custom_text','custom_dropdown','label','choices','test','statusCode','getFields,\x20%s,\x20%s,\x20%s','Wrong\x20credentials','eml-format','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','../../config/utils','../../config/license/util','../../components/integrations/configuration','jayson/promise','http','request','then','info','FreshdeskAccount,\x20%s,\x20%s','request\x20sent','debug','FreshdeskAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','catch','sendStatus','status','json'];(function(_0x25b8f0,_0x34d761){var _0xf7f9f9=function(_0x5bbd10){while(--_0x5bbd10){_0x25b8f0['push'](_0x25b8f0['shift']());}};_0xf7f9f9(++_0x34d761);}(_0x326f,0xd1));var _0xf326=function(_0x202f3a,_0x420a8a){_0x202f3a=_0x202f3a-0x0;var _0x2c564e=_0x326f[_0x202f3a];return _0x2c564e;};'use strict';var emlformat=require(_0xf326('0x0'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0xf326('0x1'));var rp=require(_0xf326('0x2'));var moment=require(_0xf326('0x3'));var BPromise=require(_0xf326('0x4'));var Mustache=require(_0xf326('0x5'));var util=require(_0xf326('0x6'));var path=require(_0xf326('0x7'));var sox=require(_0xf326('0x8'));var csv=require(_0xf326('0x9'));var ejs=require(_0xf326('0xa'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xf326('0xb'));var squel=require(_0xf326('0xc'));var crypto=require(_0xf326('0xd'));var jsforce=require(_0xf326('0xe'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0xf326('0xf'));var Redis=require(_0xf326('0x10'));var authService=require(_0xf326('0x11'));var qs=require(_0xf326('0x12'));var as=require(_0xf326('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xf326('0x14'))('api');var utils=require(_0xf326('0x15'));var config=require('../../config/environment');var licenseUtil=require(_0xf326('0x16'));var db=require('../../mysqldb')['db'];var integrations=require(_0xf326('0x17'));var jayson=require(_0xf326('0x18'));var client=jayson['client'][_0xf326('0x19')]({'port':0x232a});function respondWithRpcPromise(_0x472632,_0x3504eb,_0x17a098,_0x5c8483){return new BPromise(function(_0x45c1b6,_0x5204ee){var _0x54bd1a=_0x5c8483||client;return _0x54bd1a[_0xf326('0x1a')](_0x472632,_0x17a098)[_0xf326('0x1b')](function(_0x1f2e5a){logger[_0xf326('0x1c')](_0xf326('0x1d'),_0x3504eb,_0xf326('0x1e'));logger[_0xf326('0x1f')](_0xf326('0x20'),_0x3504eb,'request\x20sent',JSON[_0xf326('0x21')](_0x1f2e5a));if(_0x1f2e5a[_0xf326('0x22')]){if(_0x1f2e5a[_0xf326('0x22')][_0xf326('0x23')]===0x1f4){logger[_0xf326('0x22')](_0xf326('0x1d'),_0x3504eb,_0x1f2e5a['error']['message']);return _0x5204ee(_0x1f2e5a['error'][_0xf326('0x24')]);}logger[_0xf326('0x22')]('FreshdeskAccount,\x20%s,\x20%s',_0x3504eb,_0x1f2e5a['error'][_0xf326('0x24')]);return _0x45c1b6(_0x1f2e5a['error']['message']);}else{logger[_0xf326('0x1c')](_0xf326('0x1d'),_0x3504eb,'request\x20sent');_0x45c1b6(_0x1f2e5a['result'][_0xf326('0x24')]);}})[_0xf326('0x25')](function(_0x5f21a2){logger[_0xf326('0x22')](_0xf326('0x1d'),_0x3504eb,_0x5f21a2);_0x5204ee(_0x5f21a2);});});}function respondWithStatusCode(_0x43c53e,_0x295752){_0x295752=_0x295752||0xcc;return function(_0x17c157){if(_0x17c157){return _0x43c53e[_0xf326('0x26')](_0x295752);}return _0x43c53e['status'](_0x295752)['end']();};}function respondWithResult(_0x4f31f6,_0x520d85){_0x520d85=_0x520d85||0xc8;return function(_0x1a2c4e){if(_0x1a2c4e){return _0x4f31f6[_0xf326('0x27')](_0x520d85)[_0xf326('0x28')](_0x1a2c4e);}};}function respondWithFilteredResult(_0x148953,_0x410237){return function(_0x5217d4){if(_0x5217d4){var _0x201d28=_0x5217d4[_0xf326('0x29')],_0xa3c0b=_0x410237['offset'],_0x212d5d=_0x410237['offset']+_0x410237[_0xf326('0x2a')],_0x581531;if(_0x212d5d>=_0x201d28){_0x212d5d=_0x201d28;_0x581531=0xc8;}else{_0x581531=0xce;}_0x148953[_0xf326('0x27')](_0x581531);return _0x148953[_0xf326('0x2b')]('Content-Range',_0xa3c0b+'-'+_0x212d5d+'/'+_0x201d28)[_0xf326('0x28')](_0x5217d4);}return null;};}function patchUpdates(_0x292500){return function(_0x55790d){try{jsonpatch[_0xf326('0x2c')](_0x55790d,_0x292500,!![]);}catch(_0x119ab8){return BPromise[_0xf326('0x2d')](_0x119ab8);}return _0x55790d[_0xf326('0x2e')]();};}function saveUpdates(_0xa80156,_0x269be9){return function(_0x161143){if(_0x161143){return _0x161143[_0xf326('0x2f')](_0xa80156)[_0xf326('0x1b')](function(_0x349a03){return _0x349a03;});}return null;};}function removeEntity(_0x4b52f2,_0x1035ed){return function(_0x424104){if(_0x424104){return _0x424104[_0xf326('0x30')]()['then'](function(){_0x4b52f2[_0xf326('0x27')](0xcc)[_0xf326('0x31')]();});}};}function handleEntityNotFound(_0x303dc6,_0x4df451){return function(_0x5b101d){if(!_0x5b101d){_0x303dc6[_0xf326('0x26')](0x194);}return _0x5b101d;};}function handleError(_0x46d75e,_0x9c3039){_0x9c3039=_0x9c3039||0x1f4;return function(_0xf53cf3){logger[_0xf326('0x22')](_0xf53cf3[_0xf326('0x32')]);if(_0xf53cf3[_0xf326('0x33')]){delete _0xf53cf3[_0xf326('0x33')];}_0x46d75e['status'](_0x9c3039)[_0xf326('0x34')](_0xf53cf3);};}exports[_0xf326('0x35')]=function(_0x51207a,_0x4083a2){var _0x4e5d7c={},_0xce1cbb={},_0x481b64={'count':0x0,'rows':[]};var _0x51f147=_[_0xf326('0x36')](db['FreshdeskAccount'][_0xf326('0x37')],function(_0x57aa27){return{'name':_0x57aa27[_0xf326('0x38')],'type':_0x57aa27[_0xf326('0x39')][_0xf326('0x3a')]};});_0xce1cbb['model']=_[_0xf326('0x36')](_0x51f147,_0xf326('0x33'));_0xce1cbb['query']=_[_0xf326('0x3b')](_0x51207a[_0xf326('0x3c')]);_0xce1cbb[_0xf326('0x3d')]=_[_0xf326('0x3e')](_0xce1cbb['model'],_0xce1cbb[_0xf326('0x3c')]);_0x4e5d7c[_0xf326('0x3f')]=_[_0xf326('0x3e')](_0xce1cbb[_0xf326('0x40')],qs[_0xf326('0x41')](_0x51207a['query'][_0xf326('0x41')]));_0x4e5d7c[_0xf326('0x3f')]=_0x4e5d7c['attributes']['length']?_0x4e5d7c[_0xf326('0x3f')]:_0xce1cbb['model'];if(!_0x51207a['query'][_0xf326('0x42')]('nolimit')){_0x4e5d7c[_0xf326('0x2a')]=qs[_0xf326('0x2a')](_0x51207a[_0xf326('0x3c')][_0xf326('0x2a')]);_0x4e5d7c['offset']=qs[_0xf326('0x43')](_0x51207a[_0xf326('0x3c')][_0xf326('0x43')]);}_0x4e5d7c[_0xf326('0x44')]=qs[_0xf326('0x45')](_0x51207a[_0xf326('0x3c')][_0xf326('0x45')]);_0x4e5d7c[_0xf326('0x46')]=qs[_0xf326('0x3d')](_[_0xf326('0x47')](_0x51207a[_0xf326('0x3c')],_0xce1cbb[_0xf326('0x3d')]),_0x51f147);if(_0x51207a['query'][_0xf326('0x48')]){_0x4e5d7c[_0xf326('0x46')]=_[_0xf326('0x49')](_0x4e5d7c[_0xf326('0x46')],{'$or':_[_0xf326('0x36')](_0x51f147,function(_0x1a2d0d){if(_0x1a2d0d['type']!==_0xf326('0x4a')){var _0xbacd3c={};_0xbacd3c[_0x1a2d0d['name']]={'$like':'%'+_0x51207a[_0xf326('0x3c')][_0xf326('0x48')]+'%'};return _0xbacd3c;}})});}_0x4e5d7c=_[_0xf326('0x49')]({},_0x4e5d7c,_0x51207a[_0xf326('0x4b')]);var _0x427c34={'where':_0x4e5d7c['where']};return db['FreshdeskAccount'][_0xf326('0x29')](_0x427c34)[_0xf326('0x1b')](function(_0x5ed62e){_0x481b64['count']=_0x5ed62e;if(_0x51207a[_0xf326('0x3c')][_0xf326('0x4c')]){_0x4e5d7c[_0xf326('0x4d')]=[{'all':!![]}];}return db['FreshdeskAccount'][_0xf326('0x4e')](_0x4e5d7c);})[_0xf326('0x1b')](function(_0x2180d6){_0x481b64[_0xf326('0x4f')]=_0x2180d6;return _0x481b64;})[_0xf326('0x1b')](respondWithFilteredResult(_0x4083a2,_0x4e5d7c))[_0xf326('0x25')](handleError(_0x4083a2,null));};exports[_0xf326('0x50')]=function(_0x3b90dc,_0x3df9a8){var _0x27ced1={'raw':![],'where':{'id':_0x3b90dc[_0xf326('0x51')]['id']}},_0x1c76c8={};_0x1c76c8[_0xf326('0x40')]=_[_0xf326('0x3b')](db[_0xf326('0x52')]['rawAttributes']);_0x1c76c8[_0xf326('0x3c')]=_[_0xf326('0x3b')](_0x3b90dc[_0xf326('0x3c')]);_0x1c76c8[_0xf326('0x3d')]=_['intersection'](_0x1c76c8[_0xf326('0x40')],_0x1c76c8[_0xf326('0x3c')]);_0x27ced1[_0xf326('0x3f')]=_[_0xf326('0x3e')](_0x1c76c8['model'],qs[_0xf326('0x41')](_0x3b90dc[_0xf326('0x3c')][_0xf326('0x41')]));_0x27ced1[_0xf326('0x3f')]=_0x27ced1[_0xf326('0x3f')]['length']?_0x27ced1['attributes']:_0x1c76c8[_0xf326('0x40')];if(_0x3b90dc[_0xf326('0x3c')][_0xf326('0x4c')]){_0x27ced1['include']=[{'all':!![]}];}_0x27ced1=_[_0xf326('0x49')]({},_0x27ced1,_0x3b90dc[_0xf326('0x4b')]);return db[_0xf326('0x52')]['find'](_0x27ced1)['then'](handleEntityNotFound(_0x3df9a8,null))[_0xf326('0x1b')](respondWithResult(_0x3df9a8,null))['catch'](handleError(_0x3df9a8,null));};exports[_0xf326('0x53')]=function(_0x554277,_0x458e5f){return db[_0xf326('0x52')][_0xf326('0x53')](_0x554277[_0xf326('0x54')],{})[_0xf326('0x1b')](respondWithResult(_0x458e5f,0xc9))[_0xf326('0x25')](handleError(_0x458e5f,null));};exports[_0xf326('0x2f')]=function(_0x495a16,_0xcdaf3f){if(_0x495a16[_0xf326('0x54')]['id']){delete _0x495a16[_0xf326('0x54')]['id'];}return db['FreshdeskAccount'][_0xf326('0x55')]({'where':{'id':_0x495a16[_0xf326('0x51')]['id']}})[_0xf326('0x1b')](handleEntityNotFound(_0xcdaf3f,null))[_0xf326('0x1b')](saveUpdates(_0x495a16[_0xf326('0x54')],null))['then'](respondWithResult(_0xcdaf3f,null))[_0xf326('0x25')](handleError(_0xcdaf3f,null));};exports[_0xf326('0x30')]=function(_0x287a97,_0x46a21f){return db['FreshdeskAccount'][_0xf326('0x55')]({'where':{'id':_0x287a97[_0xf326('0x51')]['id']}})[_0xf326('0x1b')](handleEntityNotFound(_0x46a21f,null))[_0xf326('0x1b')](removeEntity(_0x46a21f,null))['catch'](handleError(_0x46a21f,null));};exports['getConfigurations']=function(_0x18b46e,_0x44d2ed,_0x55ca96){var _0x3cf6fa={};var _0x29de71={};var _0x316609;var _0x1258d1;return db['FreshdeskAccount'][_0xf326('0x56')]({'where':{'id':_0x18b46e['params']['id']}})['then'](handleEntityNotFound(_0x44d2ed,null))[_0xf326('0x1b')](function(_0x51d466){if(_0x51d466){_0x316609=_0x51d466;_0x29de71[_0xf326('0x40')]=_[_0xf326('0x3b')](db[_0xf326('0x57')]['rawAttributes']);_0x29de71['query']=_[_0xf326('0x3b')](_0x18b46e[_0xf326('0x3c')]);_0x29de71[_0xf326('0x3d')]=_['intersection'](_0x29de71[_0xf326('0x40')],_0x29de71['query']);_0x3cf6fa[_0xf326('0x3f')]=_[_0xf326('0x3e')](_0x29de71[_0xf326('0x40')],qs[_0xf326('0x41')](_0x18b46e[_0xf326('0x3c')][_0xf326('0x41')]));_0x3cf6fa[_0xf326('0x3f')]=_0x3cf6fa[_0xf326('0x3f')][_0xf326('0x58')]?_0x3cf6fa[_0xf326('0x3f')]:_0x29de71[_0xf326('0x40')];_0x3cf6fa[_0xf326('0x44')]=qs[_0xf326('0x45')](_0x18b46e['query'][_0xf326('0x45')]);_0x3cf6fa['where']=qs[_0xf326('0x3d')](_[_0xf326('0x47')](_0x18b46e['query'],_0x29de71[_0xf326('0x3d')]));if(_0x18b46e['query'][_0xf326('0x48')]){_0x3cf6fa[_0xf326('0x46')]=_[_0xf326('0x49')](_0x3cf6fa[_0xf326('0x46')],{'$or':_[_0xf326('0x36')](_0x3cf6fa['attributes'],function(_0x4ec099){var _0x1209ca={};_0x1209ca[_0x4ec099]={'$like':'%'+_0x18b46e[_0xf326('0x3c')][_0xf326('0x48')]+'%'};return _0x1209ca;})});}_0x3cf6fa=_[_0xf326('0x49')]({},_0x3cf6fa,_0x18b46e[_0xf326('0x4b')]);return _0x316609['getConfigurations'](_0x3cf6fa);}})[_0xf326('0x1b')](function(_0x471da8){if(_0x471da8){_0x1258d1=_0x471da8['length'];if(!_0x18b46e['query']['hasOwnProperty'](_0xf326('0x59'))){_0x3cf6fa[_0xf326('0x2a')]=qs[_0xf326('0x2a')](_0x18b46e[_0xf326('0x3c')][_0xf326('0x2a')]);_0x3cf6fa[_0xf326('0x43')]=qs[_0xf326('0x43')](_0x18b46e['query'][_0xf326('0x43')]);}return _0x316609[_0xf326('0x5a')](_0x3cf6fa);}})[_0xf326('0x1b')](function(_0x13cf83){if(_0x13cf83){return _0x13cf83?{'count':_0x1258d1,'rows':_0x13cf83}:null;}})['then'](respondWithResult(_0x44d2ed,null))[_0xf326('0x25')](handleError(_0x44d2ed,null));};exports['addConfiguration']=function(_0x499b59,_0x2dd9e4,_0x540fa0){if(_0x499b59[_0xf326('0x54')]['id']){delete _0x499b59[_0xf326('0x54')]['id'];}return db[_0xf326('0x52')][_0xf326('0x56')]({'where':{'id':_0x499b59[_0xf326('0x51')]['id']}})['then'](handleEntityNotFound(_0x2dd9e4,null))['then'](function(_0x48d84a){if(_0x48d84a){_0x499b59[_0xf326('0x54')][_0xf326('0x5b')]=_0x48d84a['id'];_0x499b59[_0xf326('0x54')][_0xf326('0x5c')]=integrations[_0xf326('0x5d')](_0x499b59['body'][_0xf326('0x5e')],_0x499b59[_0xf326('0x54')][_0xf326('0x39')]);_0x499b59['body']['Descriptions']=integrations[_0xf326('0x5f')](_0x499b59[_0xf326('0x54')]['channel'],_0x499b59['body'][_0xf326('0x39')]);return db['FreshdeskConfiguration'][_0xf326('0x53')](_0x499b59['body'],{'include':[{'model':db['FreshdeskField'],'as':'Subjects'},{'model':db[_0xf326('0x60')],'as':_0xf326('0x61')}]});}return null;})[_0xf326('0x1b')](respondWithResult(_0x2dd9e4,null))['catch'](handleError(_0x2dd9e4,null));};exports[_0xf326('0x62')]=function(_0xdeceb9,_0x35e34d,_0x457f3d){var _0x2dcf6c='';return db[_0xf326('0x52')][_0xf326('0x56')]({'where':{'id':_0xdeceb9[_0xf326('0x51')]['id']},'attributes':['id',_0xf326('0x63'),'apiKey']})[_0xf326('0x1b')](handleEntityNotFound(_0x35e34d,null))['then'](function(_0x2c81a7){if(_0x2c81a7){_0x2dcf6c=_0x2c81a7[_0xf326('0x63')];var _0x40ee66=_0x2dcf6c['slice'](-0x1);if(_0x40ee66==='/'){_0x2dcf6c=_0x2dcf6c[_0xf326('0x64')](0x0,_0x2dcf6c[_0xf326('0x65')](_0x40ee66));}return rp({'method':_0xf326('0x66'),'uri':util['format'](_0xf326('0x67'),_0x2dcf6c,_0xf326('0x68')),'headers':{'Authorization':util[_0xf326('0x69')](_0xf326('0x6a'),new Buffer(util['format'](_0xf326('0x6b'),_0x2c81a7['apiKey']))['toString'](_0xf326('0x6c')))},'json':!![]});}})[_0xf326('0x1b')](function(_0x5af6b7){if(_0x5af6b7){var _0x49f239=['requester',_0xf326('0x6d'),'agent',_0xf326('0x6e'),_0xf326('0x27'),_0xf326('0x6f'),_0xf326('0x70'),_0xf326('0x71'),_0xf326('0x72'),'group',_0xf326('0x73')];_[_0xf326('0x74')](_0x5af6b7,function(_0x5f1724){return _0x49f239['includes'](_0x5f1724[_0xf326('0x33')])||!_0x5f1724['default']&&_0x5f1724[_0xf326('0x39')]!==_0xf326('0x75')&&_0x5f1724[_0xf326('0x39')]!==_0xf326('0x76');});return{'count':_0x5af6b7[_0xf326('0x58')],'rows':_[_0xf326('0x36')](_0x5af6b7,function(_0x293600){return{'id':_0x293600[_0xf326('0x33')],'name':_0x293600[_0xf326('0x77')],'custom':!_0x293600['default'],'options':_0x293600[_0xf326('0x78')]?_[_0xf326('0x36')](_0x293600['choices'],function(_0x3c82cf){return{'name':_['capitalize'](_0x3c82cf),'value':_0x3c82cf};}):[]};})};}})[_0xf326('0x1b')](respondWithResult(_0x35e34d,null))[_0xf326('0x25')](function(_0x14e8c0){var _0x5814ad=_0xdeceb9[_0xf326('0x3c')][_0xf326('0x79')]?0x1f4:_0x14e8c0[_0xf326('0x7a')]||0x1f4;logger[_0xf326('0x22')](_0xf326('0x7b'),_0xf326('0x62'),_0x5814ad,JSON[_0xf326('0x21')](_0x14e8c0));delete _0x14e8c0[_0xf326('0x33')];if(_0x5814ad===0x191){_0x5814ad=0x190;}_0x35e34d[_0xf326('0x27')](_0x5814ad)[_0xf326('0x34')](_0xdeceb9[_0xf326('0x3c')][_0xf326('0x79')]?{'message':_0xf326('0x7c'),'statusCode':_0x14e8c0[_0xf326('0x7a')]}:_0x14e8c0);});};
\ No newline at end of file
+var _0xd240=['description','priority','group','source','ticket_type','company','remove','default','custom_text','label','capitalize','test','statusCode','getFields,\x20%s,\x20%s,\x20%s','stringify','rimraf','request-promise','moment','bluebird','mustache','util','path','ejs','fs-extra','lodash','squel','jsforce','desk.js','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','status','end','json','offset','limit','undefined','count','set','Content-Range','apply','reject','save','update','then','sendStatus','error','stack','name','map','FreshdeskAccount','rawAttributes','fieldName','model','query','keys','intersection','attributes','fields','length','nolimit','sort','where','type','VIRTUAL','filter','options','includeAll','include','findAll','rows','show','merge','find','catch','create','body','params','destroy','findOne','FreshdeskConfiguration','filters','order','pick','addConfiguration','AccountId','Subjects','getSubjects','channel','Descriptions','getDescriptions','FreshdeskField','getFields','remoteUri','apiKey','slice','substring','lastIndexOf','format','%s/%s','toString','subject','agent'];(function(_0xe01d60,_0x340301){var _0x46d858=function(_0x25e8ba){while(--_0x25e8ba){_0xe01d60['push'](_0xe01d60['shift']());}};_0x46d858(++_0x340301);}(_0xd240,0x1c7));var _0x0d24=function(_0x24235c,_0xe0c1b1){_0x24235c=_0x24235c-0x0;var _0x2b8961=_0xd240[_0x24235c];return _0x2b8961;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x0d24('0x0'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0x0d24('0x1'));var moment=require(_0x0d24('0x2'));var BPromise=require(_0x0d24('0x3'));var Mustache=require(_0x0d24('0x4'));var util=require(_0x0d24('0x5'));var path=require(_0x0d24('0x6'));var sox=require('sox');var csv=require('to-csv');var ejs=require(_0x0d24('0x7'));var fs=require('fs');var fs_extra=require(_0x0d24('0x8'));var _=require(_0x0d24('0x9'));var squel=require(_0x0d24('0xa'));var crypto=require('crypto');var jsforce=require(_0x0d24('0xb'));var deskjs=require(_0x0d24('0xc'));var toCsv=require(_0x0d24('0xd'));var querystring=require(_0x0d24('0xe'));var Papa=require(_0x0d24('0xf'));var Redis=require(_0x0d24('0x10'));var authService=require(_0x0d24('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0x0d24('0x12'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x0d24('0x13'))('api');var utils=require(_0x0d24('0x14'));var config=require(_0x0d24('0x15'));var licenseUtil=require(_0x0d24('0x16'));var db=require('../../mysqldb')['db'];var integrations=require('../../components/integrations/configuration');function respondWithStatusCode(_0x29f892,_0x1b6f50){_0x1b6f50=_0x1b6f50||0xcc;return function(_0x41838d){if(_0x41838d){return _0x29f892['sendStatus'](_0x1b6f50);}return _0x29f892[_0x0d24('0x17')](_0x1b6f50)[_0x0d24('0x18')]();};}function respondWithResult(_0x58ac0d,_0x4d24b5){_0x4d24b5=_0x4d24b5||0xc8;return function(_0x13c2ce){if(_0x13c2ce){return _0x58ac0d[_0x0d24('0x17')](_0x4d24b5)[_0x0d24('0x19')](_0x13c2ce);}};}function respondWithFilteredResult(_0x175841,_0xd9a534){return function(_0x6ec239){if(_0x6ec239){var _0xf188c9=typeof _0xd9a534[_0x0d24('0x1a')]==='undefined'&&typeof _0xd9a534[_0x0d24('0x1b')]===_0x0d24('0x1c');var _0x591d04=_0x6ec239[_0x0d24('0x1d')];var _0x1c5899=_0xf188c9?0x0:_0xd9a534[_0x0d24('0x1a')];var _0x151030=_0xf188c9?_0x6ec239['count']:_0xd9a534[_0x0d24('0x1a')]+_0xd9a534[_0x0d24('0x1b')];var _0x527f6b;if(_0x151030>=_0x591d04){_0x151030=_0x591d04;_0x527f6b=0xc8;}else{_0x527f6b=0xce;}_0x175841['status'](_0x527f6b);return _0x175841[_0x0d24('0x1e')](_0x0d24('0x1f'),_0x1c5899+'-'+_0x151030+'/'+_0x591d04)[_0x0d24('0x19')](_0x6ec239);}return null;};}function patchUpdates(_0x2f611b){return function(_0x30e520){try{jsonpatch[_0x0d24('0x20')](_0x30e520,_0x2f611b,!![]);}catch(_0x120625){return BPromise[_0x0d24('0x21')](_0x120625);}return _0x30e520[_0x0d24('0x22')]();};}function saveUpdates(_0x5df68d,_0x2499e1){return function(_0x14108f){if(_0x14108f){return _0x14108f[_0x0d24('0x23')](_0x5df68d)[_0x0d24('0x24')](function(_0x4e6ded){return _0x4e6ded;});}return null;};}function removeEntity(_0x23440c,_0x3cd88f){return function(_0x367028){if(_0x367028){return _0x367028['destroy']()[_0x0d24('0x24')](function(){_0x23440c[_0x0d24('0x17')](0xcc)[_0x0d24('0x18')]();});}};}function handleEntityNotFound(_0x5905c3,_0x26db95){return function(_0xa5d22d){if(!_0xa5d22d){_0x5905c3[_0x0d24('0x25')](0x194);}return _0xa5d22d;};}function handleError(_0x582169,_0x2226d6){_0x2226d6=_0x2226d6||0x1f4;return function(_0x1a5feb){logger[_0x0d24('0x26')](_0x1a5feb[_0x0d24('0x27')]);if(_0x1a5feb[_0x0d24('0x28')]){delete _0x1a5feb[_0x0d24('0x28')];}_0x582169['status'](_0x2226d6)['send'](_0x1a5feb);};}exports['index']=function(_0x1057c3,_0x2064e3){var _0x1a1ef7={},_0xa1bccb={},_0x31ea4b={'count':0x0,'rows':[]};var _0x8f3446=_[_0x0d24('0x29')](db[_0x0d24('0x2a')][_0x0d24('0x2b')],function(_0x45c4bc){return{'name':_0x45c4bc[_0x0d24('0x2c')],'type':_0x45c4bc['type']['key']};});_0xa1bccb[_0x0d24('0x2d')]=_['map'](_0x8f3446,'name');_0xa1bccb[_0x0d24('0x2e')]=_[_0x0d24('0x2f')](_0x1057c3[_0x0d24('0x2e')]);_0xa1bccb['filters']=_[_0x0d24('0x30')](_0xa1bccb['model'],_0xa1bccb[_0x0d24('0x2e')]);_0x1a1ef7[_0x0d24('0x31')]=_[_0x0d24('0x30')](_0xa1bccb[_0x0d24('0x2d')],qs[_0x0d24('0x32')](_0x1057c3['query']['fields']));_0x1a1ef7[_0x0d24('0x31')]=_0x1a1ef7[_0x0d24('0x31')][_0x0d24('0x33')]?_0x1a1ef7[_0x0d24('0x31')]:_0xa1bccb[_0x0d24('0x2d')];if(!_0x1057c3[_0x0d24('0x2e')]['hasOwnProperty'](_0x0d24('0x34'))){_0x1a1ef7[_0x0d24('0x1b')]=qs['limit'](_0x1057c3[_0x0d24('0x2e')][_0x0d24('0x1b')]);_0x1a1ef7['offset']=qs[_0x0d24('0x1a')](_0x1057c3[_0x0d24('0x2e')][_0x0d24('0x1a')]);}_0x1a1ef7['order']=qs[_0x0d24('0x35')](_0x1057c3[_0x0d24('0x2e')][_0x0d24('0x35')]);_0x1a1ef7[_0x0d24('0x36')]=qs['filters'](_['pick'](_0x1057c3[_0x0d24('0x2e')],_0xa1bccb['filters']),_0x8f3446);if(_0x1057c3['query']['filter']){_0x1a1ef7[_0x0d24('0x36')]=_['merge'](_0x1a1ef7[_0x0d24('0x36')],{'$or':_[_0x0d24('0x29')](_0x8f3446,function(_0x37302d){if(_0x37302d[_0x0d24('0x37')]!==_0x0d24('0x38')){var _0x274cf5={};_0x274cf5[_0x37302d[_0x0d24('0x28')]]={'$like':'%'+_0x1057c3[_0x0d24('0x2e')][_0x0d24('0x39')]+'%'};return _0x274cf5;}})});}_0x1a1ef7=_['merge']({},_0x1a1ef7,_0x1057c3[_0x0d24('0x3a')]);var _0x554917={'where':_0x1a1ef7['where']};return db[_0x0d24('0x2a')][_0x0d24('0x1d')](_0x554917)[_0x0d24('0x24')](function(_0x1396cf){_0x31ea4b[_0x0d24('0x1d')]=_0x1396cf;if(_0x1057c3[_0x0d24('0x2e')][_0x0d24('0x3b')]){_0x1a1ef7[_0x0d24('0x3c')]=[{'all':!![]}];}return db[_0x0d24('0x2a')][_0x0d24('0x3d')](_0x1a1ef7);})[_0x0d24('0x24')](function(_0x548fee){_0x31ea4b[_0x0d24('0x3e')]=_0x548fee;return _0x31ea4b;})[_0x0d24('0x24')](respondWithFilteredResult(_0x2064e3,_0x1a1ef7))['catch'](handleError(_0x2064e3,null));};exports[_0x0d24('0x3f')]=function(_0x9dd427,_0x119152){var _0x1fbff7={'raw':![],'where':{'id':_0x9dd427['params']['id']}},_0x4004d7={};_0x4004d7[_0x0d24('0x2d')]=_['keys'](db[_0x0d24('0x2a')][_0x0d24('0x2b')]);_0x4004d7['query']=_[_0x0d24('0x2f')](_0x9dd427[_0x0d24('0x2e')]);_0x4004d7['filters']=_['intersection'](_0x4004d7['model'],_0x4004d7[_0x0d24('0x2e')]);_0x1fbff7[_0x0d24('0x31')]=_[_0x0d24('0x30')](_0x4004d7[_0x0d24('0x2d')],qs[_0x0d24('0x32')](_0x9dd427['query'][_0x0d24('0x32')]));_0x1fbff7[_0x0d24('0x31')]=_0x1fbff7['attributes'][_0x0d24('0x33')]?_0x1fbff7['attributes']:_0x4004d7[_0x0d24('0x2d')];if(_0x9dd427[_0x0d24('0x2e')]['includeAll']){_0x1fbff7[_0x0d24('0x3c')]=[{'all':!![]}];}_0x1fbff7=_[_0x0d24('0x40')]({},_0x1fbff7,_0x9dd427[_0x0d24('0x3a')]);return db[_0x0d24('0x2a')][_0x0d24('0x41')](_0x1fbff7)[_0x0d24('0x24')](handleEntityNotFound(_0x119152,null))[_0x0d24('0x24')](respondWithResult(_0x119152,null))[_0x0d24('0x42')](handleError(_0x119152,null));};exports[_0x0d24('0x43')]=function(_0x211bea,_0x149ea2){return db[_0x0d24('0x2a')]['create'](_0x211bea[_0x0d24('0x44')],{})[_0x0d24('0x24')](respondWithResult(_0x149ea2,0xc9))[_0x0d24('0x42')](handleError(_0x149ea2,null));};exports[_0x0d24('0x23')]=function(_0x39e695,_0xfc9d42){if(_0x39e695[_0x0d24('0x44')]['id']){delete _0x39e695['body']['id'];}return db['FreshdeskAccount'][_0x0d24('0x41')]({'where':{'id':_0x39e695[_0x0d24('0x45')]['id']}})[_0x0d24('0x24')](handleEntityNotFound(_0xfc9d42,null))[_0x0d24('0x24')](saveUpdates(_0x39e695['body'],null))[_0x0d24('0x24')](respondWithResult(_0xfc9d42,null))[_0x0d24('0x42')](handleError(_0xfc9d42,null));};exports[_0x0d24('0x46')]=function(_0x5544ff,_0x1c52f2){return db[_0x0d24('0x2a')][_0x0d24('0x41')]({'where':{'id':_0x5544ff[_0x0d24('0x45')]['id']}})[_0x0d24('0x24')](handleEntityNotFound(_0x1c52f2,null))[_0x0d24('0x24')](removeEntity(_0x1c52f2,null))[_0x0d24('0x42')](handleError(_0x1c52f2,null));};exports['getConfigurations']=function(_0x574242,_0x141c37,_0x3bc338){var _0xbf0dc0={};var _0x5e1df1={};var _0x3d7e8e;var _0x306897;return db[_0x0d24('0x2a')][_0x0d24('0x47')]({'where':{'id':_0x574242[_0x0d24('0x45')]['id']}})[_0x0d24('0x24')](handleEntityNotFound(_0x141c37,null))[_0x0d24('0x24')](function(_0x4e2969){if(_0x4e2969){_0x3d7e8e=_0x4e2969;_0x5e1df1[_0x0d24('0x2d')]=_[_0x0d24('0x2f')](db[_0x0d24('0x48')][_0x0d24('0x2b')]);_0x5e1df1[_0x0d24('0x2e')]=_['keys'](_0x574242[_0x0d24('0x2e')]);_0x5e1df1[_0x0d24('0x49')]=_[_0x0d24('0x30')](_0x5e1df1[_0x0d24('0x2d')],_0x5e1df1[_0x0d24('0x2e')]);_0xbf0dc0['attributes']=_[_0x0d24('0x30')](_0x5e1df1['model'],qs[_0x0d24('0x32')](_0x574242[_0x0d24('0x2e')]['fields']));_0xbf0dc0[_0x0d24('0x31')]=_0xbf0dc0[_0x0d24('0x31')][_0x0d24('0x33')]?_0xbf0dc0[_0x0d24('0x31')]:_0x5e1df1[_0x0d24('0x2d')];_0xbf0dc0[_0x0d24('0x4a')]=qs[_0x0d24('0x35')](_0x574242[_0x0d24('0x2e')][_0x0d24('0x35')]);_0xbf0dc0[_0x0d24('0x36')]=qs[_0x0d24('0x49')](_[_0x0d24('0x4b')](_0x574242[_0x0d24('0x2e')],_0x5e1df1[_0x0d24('0x49')]));if(_0x574242[_0x0d24('0x2e')]['filter']){_0xbf0dc0[_0x0d24('0x36')]=_[_0x0d24('0x40')](_0xbf0dc0[_0x0d24('0x36')],{'$or':_[_0x0d24('0x29')](_0xbf0dc0[_0x0d24('0x31')],function(_0x3a347e){var _0x147461={};_0x147461[_0x3a347e]={'$like':'%'+_0x574242[_0x0d24('0x2e')][_0x0d24('0x39')]+'%'};return _0x147461;})});}_0xbf0dc0=_['merge']({},_0xbf0dc0,_0x574242[_0x0d24('0x3a')]);return _0x3d7e8e['getConfigurations'](_0xbf0dc0);}})[_0x0d24('0x24')](function(_0x24ce98){if(_0x24ce98){_0x306897=_0x24ce98[_0x0d24('0x33')];if(!_0x574242[_0x0d24('0x2e')]['hasOwnProperty'](_0x0d24('0x34'))){_0xbf0dc0[_0x0d24('0x1b')]=qs[_0x0d24('0x1b')](_0x574242[_0x0d24('0x2e')]['limit']);_0xbf0dc0[_0x0d24('0x1a')]=qs[_0x0d24('0x1a')](_0x574242[_0x0d24('0x2e')]['offset']);}return _0x3d7e8e['getConfigurations'](_0xbf0dc0);}})[_0x0d24('0x24')](function(_0x476c62){if(_0x476c62){return _0x476c62?{'count':_0x306897,'rows':_0x476c62}:null;}})[_0x0d24('0x24')](respondWithResult(_0x141c37,null))['catch'](handleError(_0x141c37,null));};exports[_0x0d24('0x4c')]=function(_0x5a91db,_0x4794cf,_0x3f711d){if(_0x5a91db['body']['id']){delete _0x5a91db[_0x0d24('0x44')]['id'];}return db['FreshdeskAccount'][_0x0d24('0x47')]({'where':{'id':_0x5a91db[_0x0d24('0x45')]['id']}})[_0x0d24('0x24')](handleEntityNotFound(_0x4794cf,null))[_0x0d24('0x24')](function(_0x957841){if(_0x957841){_0x5a91db['body'][_0x0d24('0x4d')]=_0x957841['id'];_0x5a91db[_0x0d24('0x44')][_0x0d24('0x4e')]=integrations[_0x0d24('0x4f')](_0x5a91db[_0x0d24('0x44')][_0x0d24('0x50')],_0x5a91db[_0x0d24('0x44')][_0x0d24('0x37')]);_0x5a91db[_0x0d24('0x44')][_0x0d24('0x51')]=integrations[_0x0d24('0x52')](_0x5a91db[_0x0d24('0x44')][_0x0d24('0x50')],_0x5a91db[_0x0d24('0x44')][_0x0d24('0x37')]);return db['FreshdeskConfiguration'][_0x0d24('0x43')](_0x5a91db[_0x0d24('0x44')],{'include':[{'model':db['FreshdeskField'],'as':_0x0d24('0x4e')},{'model':db[_0x0d24('0x53')],'as':_0x0d24('0x51')}]});}return null;})[_0x0d24('0x24')](respondWithResult(_0x4794cf,null))['catch'](handleError(_0x4794cf,null));};exports[_0x0d24('0x54')]=function(_0x3ba9b6,_0x2248bf,_0x24639d){var _0x515309='';return db[_0x0d24('0x2a')][_0x0d24('0x47')]({'where':{'id':_0x3ba9b6[_0x0d24('0x45')]['id']},'attributes':['id',_0x0d24('0x55'),_0x0d24('0x56')]})[_0x0d24('0x24')](handleEntityNotFound(_0x2248bf,null))[_0x0d24('0x24')](function(_0xbe28b9){if(_0xbe28b9){_0x515309=_0xbe28b9[_0x0d24('0x55')];var _0x187cc1=_0x515309[_0x0d24('0x57')](-0x1);if(_0x187cc1==='/'){_0x515309=_0x515309[_0x0d24('0x58')](0x0,_0x515309[_0x0d24('0x59')](_0x187cc1));}return rp({'method':'GET','uri':util[_0x0d24('0x5a')](_0x0d24('0x5b'),_0x515309,'api/v2/ticket_fields'),'headers':{'Authorization':util[_0x0d24('0x5a')]('Basic\x20%s',new Buffer(util[_0x0d24('0x5a')]('%s:X',_0xbe28b9['apiKey']))[_0x0d24('0x5c')]('base64'))},'json':!![]});}})[_0x0d24('0x24')](function(_0xd836d4){if(_0xd836d4){var _0x134063=['requester',_0x0d24('0x5d'),_0x0d24('0x5e'),_0x0d24('0x5f'),'status',_0x0d24('0x60'),_0x0d24('0x61'),_0x0d24('0x62'),_0x0d24('0x63'),_0x0d24('0x61'),_0x0d24('0x64')];_[_0x0d24('0x65')](_0xd836d4,function(_0x31e6c7){return _0x134063['includes'](_0x31e6c7[_0x0d24('0x28')])||!_0x31e6c7[_0x0d24('0x66')]&&_0x31e6c7[_0x0d24('0x37')]!==_0x0d24('0x67')&&_0x31e6c7[_0x0d24('0x37')]!=='custom_dropdown';});return{'count':_0xd836d4[_0x0d24('0x33')],'rows':_[_0x0d24('0x29')](_0xd836d4,function(_0x29a08a){return{'id':_0x29a08a[_0x0d24('0x28')],'name':_0x29a08a[_0x0d24('0x68')],'custom':!_0x29a08a[_0x0d24('0x66')],'options':_0x29a08a['choices']?_[_0x0d24('0x29')](_0x29a08a['choices'],function(_0x4d0314){return{'name':_[_0x0d24('0x69')](_0x4d0314),'value':_0x4d0314};}):[]};})};}})[_0x0d24('0x24')](respondWithResult(_0x2248bf,null))[_0x0d24('0x42')](function(_0x116066){var _0x43bb46=_0x3ba9b6['query'][_0x0d24('0x6a')]?0x1f4:_0x116066[_0x0d24('0x6b')]||0x1f4;logger[_0x0d24('0x26')](_0x0d24('0x6c'),_0x0d24('0x54'),_0x43bb46,JSON[_0x0d24('0x6d')](_0x116066));delete _0x116066[_0x0d24('0x28')];if(_0x43bb46===0x191){_0x43bb46=0x190;}_0x2248bf[_0x0d24('0x17')](_0x43bb46)['send'](_0x3ba9b6['query'][_0x0d24('0x6a')]?{'message':'Wrong\x20credentials','statusCode':_0x116066[_0x0d24('0x6b')]}:_0x116066);});};
\ No newline at end of file