Built motion from commit a679711e.|2.6.15
[motion2.git] / server / api / intZendeskAccount / intZendeskAccount.controller.js
index 7a30dfd..f8710fe 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x826a=['Descriptions','getDescriptions','ZendeskField','getFields','username','password','token','authType','remoteUri','slice','lastIndexOf','GET','format','%s/%s','headers','Basic\x20%s','%s:%s','toString','%s/token:%s','base64','Sequelize','subject','description','group','assignee','remove','ticket_fields','includes','position','title','system_field_options','custom_field_options','test','getFields,\x20%s,\x20%s,\x20%s','Wrong\x20credentials','statusCode','rimraf','fast-json-patch','moment','bluebird','mustache','util','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','../../components/integrations/configuration','jayson/promise','client','request','info','ZendeskAccount,\x20%s,\x20%s','request\x20sent','ZendeskAccount,\x20%s,\x20%s,\x20%s','stringify','error','message','catch','sendStatus','end','json','count','offset','limit','status','set','Content-Range','reject','save','then','destroy','stack','name','send','index','ZendeskAccount','fieldName','type','key','model','map','query','keys','filters','intersection','attributes','fields','hasOwnProperty','nolimit','sort','where','filter','merge','VIRTUAL','includeAll','include','findAll','rows','rawAttributes','length','find','create','body','update','params','getConfigurations','findOne','ZendeskConfiguration','order','options','addConfiguration','AccountId','Subjects','getSubjects'];(function(_0x4bada7,_0x2a529e){var _0x33832f=function(_0x35cd5c){while(--_0x35cd5c){_0x4bada7['push'](_0x4bada7['shift']());}};_0x33832f(++_0x2a529e);}(_0x826a,0x1aa));var _0xa826=function(_0x7a71dc,_0x196f65){_0x7a71dc=_0x7a71dc-0x0;var _0x295fe2=_0x826a[_0x7a71dc];return _0x295fe2;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xa826('0x0'));var zipdir=require('zip-dir');var jsonpatch=require(_0xa826('0x1'));var rp=require('request-promise');var moment=require(_0xa826('0x2'));var BPromise=require(_0xa826('0x3'));var Mustache=require(_0xa826('0x4'));var util=require(_0xa826('0x5'));var path=require('path');var sox=require(_0xa826('0x6'));var csv=require(_0xa826('0x7'));var ejs=require(_0xa826('0x8'));var fs=require('fs');var fs_extra=require(_0xa826('0x9'));var _=require(_0xa826('0xa'));var squel=require(_0xa826('0xb'));var crypto=require(_0xa826('0xc'));var jsforce=require(_0xa826('0xd'));var deskjs=require(_0xa826('0xe'));var toCsv=require(_0xa826('0x7'));var querystring=require(_0xa826('0xf'));var Papa=require(_0xa826('0x10'));var Redis=require(_0xa826('0x11'));var authService=require(_0xa826('0x12'));var qs=require(_0xa826('0x13'));var as=require(_0xa826('0x14'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xa826('0x15'))('api');var utils=require(_0xa826('0x16'));var config=require(_0xa826('0x17'));var licenseUtil=require(_0xa826('0x18'));var db=require(_0xa826('0x19'))['db'];var integrations=require(_0xa826('0x1a'));var jayson=require(_0xa826('0x1b'));var client=jayson[_0xa826('0x1c')]['http']({'port':0x232a});function respondWithRpcPromise(_0x74f6ec,_0x5c6cee,_0x3e99b0,_0x41c0c2){return new BPromise(function(_0x5dc0c7,_0x512ba9){var _0x49c91e=_0x41c0c2||client;return _0x49c91e[_0xa826('0x1d')](_0x74f6ec,_0x3e99b0)['then'](function(_0x4c546b){logger[_0xa826('0x1e')](_0xa826('0x1f'),_0x5c6cee,_0xa826('0x20'));logger['debug'](_0xa826('0x21'),_0x5c6cee,_0xa826('0x20'),JSON[_0xa826('0x22')](_0x4c546b));if(_0x4c546b[_0xa826('0x23')]){if(_0x4c546b[_0xa826('0x23')]['code']===0x1f4){logger[_0xa826('0x23')](_0xa826('0x1f'),_0x5c6cee,_0x4c546b[_0xa826('0x23')]['message']);return _0x512ba9(_0x4c546b['error'][_0xa826('0x24')]);}logger[_0xa826('0x23')](_0xa826('0x1f'),_0x5c6cee,_0x4c546b[_0xa826('0x23')][_0xa826('0x24')]);return _0x5dc0c7(_0x4c546b['error'][_0xa826('0x24')]);}else{logger[_0xa826('0x1e')](_0xa826('0x1f'),_0x5c6cee,'request\x20sent');_0x5dc0c7(_0x4c546b['result'][_0xa826('0x24')]);}})[_0xa826('0x25')](function(_0x3b43da){logger['error'](_0xa826('0x1f'),_0x5c6cee,_0x3b43da);_0x512ba9(_0x3b43da);});});}function respondWithStatusCode(_0x26ef25,_0x1d4ade){_0x1d4ade=_0x1d4ade||0xcc;return function(_0x448b4d){if(_0x448b4d){return _0x26ef25[_0xa826('0x26')](_0x1d4ade);}return _0x26ef25['status'](_0x1d4ade)[_0xa826('0x27')]();};}function respondWithResult(_0x4fa5db,_0x17ef2d){_0x17ef2d=_0x17ef2d||0xc8;return function(_0x174f16){if(_0x174f16){return _0x4fa5db['status'](_0x17ef2d)[_0xa826('0x28')](_0x174f16);}};}function respondWithFilteredResult(_0xfa4d94,_0x38c919){return function(_0xf132e0){if(_0xf132e0){var _0x1107a4=_0xf132e0[_0xa826('0x29')],_0x3c6307=_0x38c919[_0xa826('0x2a')],_0x14e836=_0x38c919[_0xa826('0x2a')]+_0x38c919[_0xa826('0x2b')],_0x3b9c6d;if(_0x14e836>=_0x1107a4){_0x14e836=_0x1107a4;_0x3b9c6d=0xc8;}else{_0x3b9c6d=0xce;}_0xfa4d94[_0xa826('0x2c')](_0x3b9c6d);return _0xfa4d94[_0xa826('0x2d')](_0xa826('0x2e'),_0x3c6307+'-'+_0x14e836+'/'+_0x1107a4)[_0xa826('0x28')](_0xf132e0);}return null;};}function patchUpdates(_0x55886f){return function(_0x19bd84){try{jsonpatch['apply'](_0x19bd84,_0x55886f,!![]);}catch(_0x2dd810){return BPromise[_0xa826('0x2f')](_0x2dd810);}return _0x19bd84[_0xa826('0x30')]();};}function saveUpdates(_0x27d779,_0xddac0f){return function(_0x5d40f5){if(_0x5d40f5){return _0x5d40f5['update'](_0x27d779)[_0xa826('0x31')](function(_0x6bf769){return _0x6bf769;});}return null;};}function removeEntity(_0xd666b7,_0x45a69e){return function(_0x4cec68){if(_0x4cec68){return _0x4cec68[_0xa826('0x32')]()[_0xa826('0x31')](function(){_0xd666b7['status'](0xcc)[_0xa826('0x27')]();});}};}function handleEntityNotFound(_0x56ddc4,_0x189c71){return function(_0x40093a){if(!_0x40093a){_0x56ddc4[_0xa826('0x26')](0x194);}return _0x40093a;};}function handleError(_0x16700f,_0x24efa7){_0x24efa7=_0x24efa7||0x1f4;return function(_0x4c00bd){logger[_0xa826('0x23')](_0x4c00bd[_0xa826('0x33')]);if(_0x4c00bd[_0xa826('0x34')]){delete _0x4c00bd[_0xa826('0x34')];}_0x16700f[_0xa826('0x2c')](_0x24efa7)[_0xa826('0x35')](_0x4c00bd);};}exports[_0xa826('0x36')]=function(_0x1aaeae,_0x3bbbdc){var _0xd2b875={},_0xd82ea2={},_0x5e5916={'count':0x0,'rows':[]};var _0x46f50e=_['map'](db[_0xa826('0x37')]['rawAttributes'],function(_0x179c29){return{'name':_0x179c29[_0xa826('0x38')],'type':_0x179c29[_0xa826('0x39')][_0xa826('0x3a')]};});_0xd82ea2[_0xa826('0x3b')]=_[_0xa826('0x3c')](_0x46f50e,_0xa826('0x34'));_0xd82ea2[_0xa826('0x3d')]=_[_0xa826('0x3e')](_0x1aaeae[_0xa826('0x3d')]);_0xd82ea2[_0xa826('0x3f')]=_[_0xa826('0x40')](_0xd82ea2['model'],_0xd82ea2[_0xa826('0x3d')]);_0xd2b875[_0xa826('0x41')]=_[_0xa826('0x40')](_0xd82ea2['model'],qs[_0xa826('0x42')](_0x1aaeae[_0xa826('0x3d')]['fields']));_0xd2b875[_0xa826('0x41')]=_0xd2b875['attributes']['length']?_0xd2b875[_0xa826('0x41')]:_0xd82ea2[_0xa826('0x3b')];if(!_0x1aaeae[_0xa826('0x3d')][_0xa826('0x43')](_0xa826('0x44'))){_0xd2b875[_0xa826('0x2b')]=qs['limit'](_0x1aaeae[_0xa826('0x3d')][_0xa826('0x2b')]);_0xd2b875[_0xa826('0x2a')]=qs[_0xa826('0x2a')](_0x1aaeae[_0xa826('0x3d')][_0xa826('0x2a')]);}_0xd2b875['order']=qs[_0xa826('0x45')](_0x1aaeae[_0xa826('0x3d')][_0xa826('0x45')]);_0xd2b875[_0xa826('0x46')]=qs[_0xa826('0x3f')](_['pick'](_0x1aaeae[_0xa826('0x3d')],_0xd82ea2[_0xa826('0x3f')]),_0x46f50e);if(_0x1aaeae[_0xa826('0x3d')][_0xa826('0x47')]){_0xd2b875[_0xa826('0x46')]=_[_0xa826('0x48')](_0xd2b875[_0xa826('0x46')],{'$or':_[_0xa826('0x3c')](_0x46f50e,function(_0x459c79){if(_0x459c79[_0xa826('0x39')]!==_0xa826('0x49')){var _0x2921a5={};_0x2921a5[_0x459c79['name']]={'$like':'%'+_0x1aaeae[_0xa826('0x3d')][_0xa826('0x47')]+'%'};return _0x2921a5;}})});}_0xd2b875=_[_0xa826('0x48')]({},_0xd2b875,_0x1aaeae['options']);var _0x24122e={'where':_0xd2b875[_0xa826('0x46')]};return db[_0xa826('0x37')][_0xa826('0x29')](_0x24122e)[_0xa826('0x31')](function(_0x58ac74){_0x5e5916[_0xa826('0x29')]=_0x58ac74;if(_0x1aaeae[_0xa826('0x3d')][_0xa826('0x4a')]){_0xd2b875[_0xa826('0x4b')]=[{'all':!![]}];}return db[_0xa826('0x37')][_0xa826('0x4c')](_0xd2b875);})[_0xa826('0x31')](function(_0x5def02){_0x5e5916[_0xa826('0x4d')]=_0x5def02;return _0x5e5916;})['then'](respondWithFilteredResult(_0x3bbbdc,_0xd2b875))['catch'](handleError(_0x3bbbdc,null));};exports['show']=function(_0x26a858,_0x35d118){var _0x15a137={'raw':![],'where':{'id':_0x26a858['params']['id']}},_0x24143b={};_0x24143b[_0xa826('0x3b')]=_['keys'](db['ZendeskAccount'][_0xa826('0x4e')]);_0x24143b[_0xa826('0x3d')]=_['keys'](_0x26a858[_0xa826('0x3d')]);_0x24143b[_0xa826('0x3f')]=_['intersection'](_0x24143b['model'],_0x24143b['query']);_0x15a137['attributes']=_['intersection'](_0x24143b['model'],qs['fields'](_0x26a858[_0xa826('0x3d')]['fields']));_0x15a137[_0xa826('0x41')]=_0x15a137['attributes'][_0xa826('0x4f')]?_0x15a137[_0xa826('0x41')]:_0x24143b[_0xa826('0x3b')];if(_0x26a858[_0xa826('0x3d')][_0xa826('0x4a')]){_0x15a137['include']=[{'all':!![]}];}_0x15a137=_[_0xa826('0x48')]({},_0x15a137,_0x26a858['options']);return db['ZendeskAccount'][_0xa826('0x50')](_0x15a137)[_0xa826('0x31')](handleEntityNotFound(_0x35d118,null))['then'](respondWithResult(_0x35d118,null))[_0xa826('0x25')](handleError(_0x35d118,null));};exports[_0xa826('0x51')]=function(_0x410840,_0x4be11a){return db[_0xa826('0x37')][_0xa826('0x51')](_0x410840[_0xa826('0x52')],{})[_0xa826('0x31')](respondWithResult(_0x4be11a,0xc9))[_0xa826('0x25')](handleError(_0x4be11a,null));};exports[_0xa826('0x53')]=function(_0x18ffd7,_0x1080d1){if(_0x18ffd7['body']['id']){delete _0x18ffd7[_0xa826('0x52')]['id'];}return db[_0xa826('0x37')][_0xa826('0x50')]({'where':{'id':_0x18ffd7[_0xa826('0x54')]['id']}})[_0xa826('0x31')](handleEntityNotFound(_0x1080d1,null))['then'](saveUpdates(_0x18ffd7[_0xa826('0x52')],null))[_0xa826('0x31')](respondWithResult(_0x1080d1,null))[_0xa826('0x25')](handleError(_0x1080d1,null));};exports['destroy']=function(_0x19f2c0,_0x1623e2){return db['ZendeskAccount'][_0xa826('0x50')]({'where':{'id':_0x19f2c0[_0xa826('0x54')]['id']}})[_0xa826('0x31')](handleEntityNotFound(_0x1623e2,null))[_0xa826('0x31')](removeEntity(_0x1623e2,null))[_0xa826('0x25')](handleError(_0x1623e2,null));};exports[_0xa826('0x55')]=function(_0x21469f,_0x115337,_0x1d5ad1){var _0x2287ea={};var _0x1745ea={};var _0x4a7ba6;var _0x39132b;return db[_0xa826('0x37')][_0xa826('0x56')]({'where':{'id':_0x21469f[_0xa826('0x54')]['id']}})[_0xa826('0x31')](handleEntityNotFound(_0x115337,null))[_0xa826('0x31')](function(_0x2e746a){if(_0x2e746a){_0x4a7ba6=_0x2e746a;_0x1745ea[_0xa826('0x3b')]=_['keys'](db[_0xa826('0x57')][_0xa826('0x4e')]);_0x1745ea[_0xa826('0x3d')]=_['keys'](_0x21469f[_0xa826('0x3d')]);_0x1745ea[_0xa826('0x3f')]=_[_0xa826('0x40')](_0x1745ea['model'],_0x1745ea['query']);_0x2287ea[_0xa826('0x41')]=_[_0xa826('0x40')](_0x1745ea[_0xa826('0x3b')],qs[_0xa826('0x42')](_0x21469f['query'][_0xa826('0x42')]));_0x2287ea[_0xa826('0x41')]=_0x2287ea[_0xa826('0x41')][_0xa826('0x4f')]?_0x2287ea[_0xa826('0x41')]:_0x1745ea[_0xa826('0x3b')];_0x2287ea[_0xa826('0x58')]=qs[_0xa826('0x45')](_0x21469f[_0xa826('0x3d')]['sort']);_0x2287ea['where']=qs['filters'](_['pick'](_0x21469f[_0xa826('0x3d')],_0x1745ea[_0xa826('0x3f')]));if(_0x21469f[_0xa826('0x3d')][_0xa826('0x47')]){_0x2287ea[_0xa826('0x46')]=_[_0xa826('0x48')](_0x2287ea['where'],{'$or':_[_0xa826('0x3c')](_0x2287ea[_0xa826('0x41')],function(_0x33e682){var _0x5a5bce={};_0x5a5bce[_0x33e682]={'$like':'%'+_0x21469f[_0xa826('0x3d')][_0xa826('0x47')]+'%'};return _0x5a5bce;})});}_0x2287ea=_[_0xa826('0x48')]({},_0x2287ea,_0x21469f[_0xa826('0x59')]);return _0x4a7ba6[_0xa826('0x55')](_0x2287ea);}})[_0xa826('0x31')](function(_0x3b440a){if(_0x3b440a){_0x39132b=_0x3b440a[_0xa826('0x4f')];if(!_0x21469f[_0xa826('0x3d')][_0xa826('0x43')](_0xa826('0x44'))){_0x2287ea[_0xa826('0x2b')]=qs[_0xa826('0x2b')](_0x21469f[_0xa826('0x3d')][_0xa826('0x2b')]);_0x2287ea['offset']=qs[_0xa826('0x2a')](_0x21469f['query'][_0xa826('0x2a')]);}return _0x4a7ba6['getConfigurations'](_0x2287ea);}})[_0xa826('0x31')](function(_0x53311f){if(_0x53311f){return _0x53311f?{'count':_0x39132b,'rows':_0x53311f}:null;}})[_0xa826('0x31')](respondWithResult(_0x115337,null))[_0xa826('0x25')](handleError(_0x115337,null));};exports[_0xa826('0x5a')]=function(_0x545eaa,_0x5d41f8,_0x5ea2d2){if(_0x545eaa[_0xa826('0x52')]['id']){delete _0x545eaa[_0xa826('0x52')]['id'];}return db[_0xa826('0x37')]['findOne']({'where':{'id':_0x545eaa[_0xa826('0x54')]['id']}})[_0xa826('0x31')](handleEntityNotFound(_0x5d41f8,null))[_0xa826('0x31')](function(_0x425fe2){if(_0x425fe2){_0x545eaa['body'][_0xa826('0x5b')]=_0x425fe2['id'];_0x545eaa[_0xa826('0x52')][_0xa826('0x5c')]=integrations[_0xa826('0x5d')](_0x545eaa[_0xa826('0x52')]['channel'],_0x545eaa['body'][_0xa826('0x39')]);_0x545eaa[_0xa826('0x52')][_0xa826('0x5e')]=integrations[_0xa826('0x5f')](_0x545eaa[_0xa826('0x52')]['channel'],_0x545eaa['body'][_0xa826('0x39')]);return db[_0xa826('0x57')][_0xa826('0x51')](_0x545eaa[_0xa826('0x52')],{'include':[{'model':db[_0xa826('0x60')],'as':_0xa826('0x5c')},{'model':db['ZendeskField'],'as':_0xa826('0x5e')}]});}return null;})['then'](respondWithResult(_0x5d41f8,null))[_0xa826('0x25')](handleError(_0x5d41f8,null));};exports[_0xa826('0x61')]=function(_0x53b55f,_0x2addbf,_0x556a5d){var _0x108510='';return db['ZendeskAccount'][_0xa826('0x56')]({'where':{'id':_0x53b55f[_0xa826('0x54')]['id']},'attributes':['id',_0xa826('0x62'),_0xa826('0x63'),_0xa826('0x64'),_0xa826('0x65'),'remoteUri']})['then'](handleEntityNotFound(_0x2addbf,null))[_0xa826('0x31')](function(_0x575185){if(_0x575185){_0x108510=_0x575185[_0xa826('0x66')];var _0x1b3c99=_0x108510[_0xa826('0x67')](-0x1);if(_0x1b3c99==='/'){_0x108510=_0x108510['substring'](0x0,_0x108510[_0xa826('0x68')](_0x1b3c99));}var _0x3c4ea8={'method':_0xa826('0x69'),'uri':util[_0xa826('0x6a')](_0xa826('0x6b'),_0x108510,'ticket_fields'),'json':!![]};switch(_0x575185[_0xa826('0x65')]){case _0xa826('0x63'):_0x3c4ea8[_0xa826('0x6c')]={'Authorization':util[_0xa826('0x6a')](_0xa826('0x6d'),new Buffer(util[_0xa826('0x6a')](_0xa826('0x6e'),_0x575185[_0xa826('0x62')],_0x575185[_0xa826('0x63')]))[_0xa826('0x6f')]('base64'))};break;case _0xa826('0x64'):_0x3c4ea8[_0xa826('0x6c')]={'Authorization':util['format']('Basic\x20%s',new Buffer(util[_0xa826('0x6a')](_0xa826('0x70'),_0x575185['username'],_0x575185[_0xa826('0x64')]))[_0xa826('0x6f')](_0xa826('0x71')))};break;default:throw new db[(_0xa826('0x72'))]['ValidationError']('Unknown\x20authentication\x20type');}return rp(_0x3c4ea8);}})[_0xa826('0x31')](function(_0x16056e){if(_0x16056e){var _0x4fb14a=[_0xa826('0x73'),_0xa826('0x74'),_0xa826('0x75'),_0xa826('0x76')];_[_0xa826('0x77')](_0x16056e[_0xa826('0x78')],function(_0x22baee){return _0x4fb14a[_0xa826('0x79')](_0x22baee['type']);});return{'count':_0x16056e[_0xa826('0x78')][_0xa826('0x4f')],'rows':_[_0xa826('0x3c')](_0x16056e[_0xa826('0x78')],function(_0x4c2d51){return{'id':_0x4c2d51['id'],'name':_0x4c2d51[_0xa826('0x7a')]>0x7?_0x4c2d51[_0xa826('0x7b')]:_0x4c2d51[_0xa826('0x39')],'custom':_0x4c2d51[_0xa826('0x7a')]>0x7?!![]:![],'options':_0x4c2d51[_0xa826('0x7c')]?_0x4c2d51[_0xa826('0x7c')]:_0x4c2d51[_0xa826('0x7d')]?_0x4c2d51['custom_field_options']:[]};})};}})[_0xa826('0x31')](respondWithResult(_0x2addbf,null))[_0xa826('0x25')](function(_0x17caf5){var _0x2188b6=_0x53b55f[_0xa826('0x3d')][_0xa826('0x7e')]?0x1f4:_0x17caf5['statusCode']||0x1f4;logger[_0xa826('0x23')](_0xa826('0x7f'),_0xa826('0x61'),_0x2188b6,JSON['stringify'](_0x17caf5));delete _0x17caf5[_0xa826('0x34')];if(_0x2188b6===0x191){_0x2188b6=0x190;}_0x2addbf[_0xa826('0x2c')](_0x2188b6)[_0xa826('0x35')](_0x53b55f[_0xa826('0x3d')]['test']?{'message':_0xa826('0x80'),'statusCode':_0x17caf5[_0xa826('0x81')]}:_0x17caf5);});};
\ No newline at end of file
+var _0xb10b=['sort','where','merge','map','VIRTUAL','filter','options','includeAll','include','findAll','rows','catch','show','params','find','create','body','getConfigurations','findOne','ZendeskConfiguration','rawAttributes','pick','AccountId','Subjects','getSubjects','channel','Descriptions','getDescriptions','ZendeskField','getFields','username','token','authType','remoteUri','slice','substring','lastIndexOf','GET','format','ticket_fields','Basic\x20%s','%s:%s','password','headers','toString','base64','Sequelize','ValidationError','Unknown\x20authentication\x20type','subject','description','group','assignee','remove','includes','position','system_field_options','custom_field_options','test','statusCode','stringify','Wrong\x20credentials','eml-format','zip-dir','fast-json-patch','request-promise','bluebird','mustache','util','path','sox','to-csv','fs-extra','lodash','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../config/license/hardware','../../config/logger','api','../../config/environment','../../mysqldb','../../components/integrations/configuration','sendStatus','end','status','json','undefined','limit','count','offset','set','Content-Range','apply','update','then','destroy','error','stack','name','send','ZendeskAccount','type','key','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','order'];(function(_0x123c1c,_0x373cb5){var _0x5c086a=function(_0x29d787){while(--_0x29d787){_0x123c1c['push'](_0x123c1c['shift']());}};_0x5c086a(++_0x373cb5);}(_0xb10b,0x12a));var _0xbb10=function(_0x5efbd0,_0x299553){_0x5efbd0=_0x5efbd0-0x0;var _0x475ec9=_0xb10b[_0x5efbd0];return _0x475ec9;};'use strict';var emlformat=require(_0xbb10('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xbb10('0x1'));var jsonpatch=require(_0xbb10('0x2'));var rp=require(_0xbb10('0x3'));var moment=require('moment');var BPromise=require(_0xbb10('0x4'));var Mustache=require(_0xbb10('0x5'));var util=require(_0xbb10('0x6'));var path=require(_0xbb10('0x7'));var sox=require(_0xbb10('0x8'));var csv=require(_0xbb10('0x9'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xbb10('0xa'));var _=require(_0xbb10('0xb'));var squel=require('squel');var crypto=require(_0xbb10('0xc'));var jsforce=require(_0xbb10('0xd'));var deskjs=require(_0xbb10('0xe'));var toCsv=require(_0xbb10('0x9'));var querystring=require(_0xbb10('0xf'));var Papa=require(_0xbb10('0x10'));var Redis=require(_0xbb10('0x11'));var authService=require(_0xbb10('0x12'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xbb10('0x13'));var logger=require(_0xbb10('0x14'))(_0xbb10('0x15'));var utils=require('../../config/utils');var config=require(_0xbb10('0x16'));var licenseUtil=require('../../config/license/util');var db=require(_0xbb10('0x17'))['db'];var integrations=require(_0xbb10('0x18'));function respondWithStatusCode(_0x285009,_0x193a27){_0x193a27=_0x193a27||0xcc;return function(_0x442548){if(_0x442548){return _0x285009[_0xbb10('0x19')](_0x193a27);}return _0x285009['status'](_0x193a27)[_0xbb10('0x1a')]();};}function respondWithResult(_0x42d7e4,_0x45b9d6){_0x45b9d6=_0x45b9d6||0xc8;return function(_0x17fd46){if(_0x17fd46){return _0x42d7e4[_0xbb10('0x1b')](_0x45b9d6)[_0xbb10('0x1c')](_0x17fd46);}};}function respondWithFilteredResult(_0x24a57b,_0x36b5e8){return function(_0x3e26f4){if(_0x3e26f4){var _0x2b184e=typeof _0x36b5e8['offset']===_0xbb10('0x1d')&&typeof _0x36b5e8[_0xbb10('0x1e')]===_0xbb10('0x1d');var _0x42db98=_0x3e26f4[_0xbb10('0x1f')];var _0x1682a4=_0x2b184e?0x0:_0x36b5e8[_0xbb10('0x20')];var _0x30efc6=_0x2b184e?_0x3e26f4[_0xbb10('0x1f')]:_0x36b5e8[_0xbb10('0x20')]+_0x36b5e8['limit'];var _0x5ff0cf;if(_0x30efc6>=_0x42db98){_0x30efc6=_0x42db98;_0x5ff0cf=0xc8;}else{_0x5ff0cf=0xce;}_0x24a57b[_0xbb10('0x1b')](_0x5ff0cf);return _0x24a57b[_0xbb10('0x21')](_0xbb10('0x22'),_0x1682a4+'-'+_0x30efc6+'/'+_0x42db98)[_0xbb10('0x1c')](_0x3e26f4);}return null;};}function patchUpdates(_0x44e563){return function(_0x4deb49){try{jsonpatch[_0xbb10('0x23')](_0x4deb49,_0x44e563,!![]);}catch(_0x12ef77){return BPromise['reject'](_0x12ef77);}return _0x4deb49['save']();};}function saveUpdates(_0x8e2b97,_0x311abe){return function(_0x2e911d){if(_0x2e911d){return _0x2e911d[_0xbb10('0x24')](_0x8e2b97)[_0xbb10('0x25')](function(_0x1824b7){return _0x1824b7;});}return null;};}function removeEntity(_0x407cb4,_0x436104){return function(_0x7f2377){if(_0x7f2377){return _0x7f2377[_0xbb10('0x26')]()[_0xbb10('0x25')](function(){_0x407cb4[_0xbb10('0x1b')](0xcc)['end']();});}};}function handleEntityNotFound(_0x4fedac,_0x4fb5e0){return function(_0xc93a04){if(!_0xc93a04){_0x4fedac[_0xbb10('0x19')](0x194);}return _0xc93a04;};}function handleError(_0x2c89b9,_0x4e25ff){_0x4e25ff=_0x4e25ff||0x1f4;return function(_0x2fdde9){logger[_0xbb10('0x27')](_0x2fdde9[_0xbb10('0x28')]);if(_0x2fdde9[_0xbb10('0x29')]){delete _0x2fdde9[_0xbb10('0x29')];}_0x2c89b9[_0xbb10('0x1b')](_0x4e25ff)[_0xbb10('0x2a')](_0x2fdde9);};}exports['index']=function(_0x3796c7,_0x21ac54){var _0xfc3595={},_0x2e0249={},_0x1d30aa={'count':0x0,'rows':[]};var _0x2ff4c1=_['map'](db[_0xbb10('0x2b')]['rawAttributes'],function(_0x448d5c){return{'name':_0x448d5c['fieldName'],'type':_0x448d5c[_0xbb10('0x2c')][_0xbb10('0x2d')]};});_0x2e0249[_0xbb10('0x2e')]=_['map'](_0x2ff4c1,'name');_0x2e0249[_0xbb10('0x2f')]=_[_0xbb10('0x30')](_0x3796c7['query']);_0x2e0249[_0xbb10('0x31')]=_[_0xbb10('0x32')](_0x2e0249[_0xbb10('0x2e')],_0x2e0249[_0xbb10('0x2f')]);_0xfc3595[_0xbb10('0x33')]=_[_0xbb10('0x32')](_0x2e0249[_0xbb10('0x2e')],qs['fields'](_0x3796c7[_0xbb10('0x2f')][_0xbb10('0x34')]));_0xfc3595[_0xbb10('0x33')]=_0xfc3595[_0xbb10('0x33')][_0xbb10('0x35')]?_0xfc3595[_0xbb10('0x33')]:_0x2e0249[_0xbb10('0x2e')];if(!_0x3796c7[_0xbb10('0x2f')][_0xbb10('0x36')]('nolimit')){_0xfc3595[_0xbb10('0x1e')]=qs[_0xbb10('0x1e')](_0x3796c7[_0xbb10('0x2f')][_0xbb10('0x1e')]);_0xfc3595['offset']=qs[_0xbb10('0x20')](_0x3796c7['query']['offset']);}_0xfc3595[_0xbb10('0x37')]=qs[_0xbb10('0x38')](_0x3796c7[_0xbb10('0x2f')][_0xbb10('0x38')]);_0xfc3595[_0xbb10('0x39')]=qs[_0xbb10('0x31')](_['pick'](_0x3796c7[_0xbb10('0x2f')],_0x2e0249[_0xbb10('0x31')]),_0x2ff4c1);if(_0x3796c7['query']['filter']){_0xfc3595['where']=_[_0xbb10('0x3a')](_0xfc3595[_0xbb10('0x39')],{'$or':_[_0xbb10('0x3b')](_0x2ff4c1,function(_0x4d5a9b){if(_0x4d5a9b[_0xbb10('0x2c')]!==_0xbb10('0x3c')){var _0x4345f3={};_0x4345f3[_0x4d5a9b['name']]={'$like':'%'+_0x3796c7[_0xbb10('0x2f')][_0xbb10('0x3d')]+'%'};return _0x4345f3;}})});}_0xfc3595=_[_0xbb10('0x3a')]({},_0xfc3595,_0x3796c7[_0xbb10('0x3e')]);var _0x4f1cdd={'where':_0xfc3595[_0xbb10('0x39')]};return db[_0xbb10('0x2b')]['count'](_0x4f1cdd)[_0xbb10('0x25')](function(_0x2e3214){_0x1d30aa[_0xbb10('0x1f')]=_0x2e3214;if(_0x3796c7[_0xbb10('0x2f')][_0xbb10('0x3f')]){_0xfc3595[_0xbb10('0x40')]=[{'all':!![]}];}return db['ZendeskAccount'][_0xbb10('0x41')](_0xfc3595);})[_0xbb10('0x25')](function(_0x3e7b4c){_0x1d30aa[_0xbb10('0x42')]=_0x3e7b4c;return _0x1d30aa;})['then'](respondWithFilteredResult(_0x21ac54,_0xfc3595))[_0xbb10('0x43')](handleError(_0x21ac54,null));};exports[_0xbb10('0x44')]=function(_0x23dc18,_0x403beb){var _0x5e2cfa={'raw':![],'where':{'id':_0x23dc18[_0xbb10('0x45')]['id']}},_0x351484={};_0x351484['model']=_['keys'](db[_0xbb10('0x2b')]['rawAttributes']);_0x351484[_0xbb10('0x2f')]=_[_0xbb10('0x30')](_0x23dc18['query']);_0x351484[_0xbb10('0x31')]=_[_0xbb10('0x32')](_0x351484[_0xbb10('0x2e')],_0x351484['query']);_0x5e2cfa[_0xbb10('0x33')]=_[_0xbb10('0x32')](_0x351484[_0xbb10('0x2e')],qs[_0xbb10('0x34')](_0x23dc18[_0xbb10('0x2f')][_0xbb10('0x34')]));_0x5e2cfa[_0xbb10('0x33')]=_0x5e2cfa[_0xbb10('0x33')][_0xbb10('0x35')]?_0x5e2cfa[_0xbb10('0x33')]:_0x351484[_0xbb10('0x2e')];if(_0x23dc18[_0xbb10('0x2f')]['includeAll']){_0x5e2cfa[_0xbb10('0x40')]=[{'all':!![]}];}_0x5e2cfa=_[_0xbb10('0x3a')]({},_0x5e2cfa,_0x23dc18['options']);return db[_0xbb10('0x2b')][_0xbb10('0x46')](_0x5e2cfa)[_0xbb10('0x25')](handleEntityNotFound(_0x403beb,null))[_0xbb10('0x25')](respondWithResult(_0x403beb,null))[_0xbb10('0x43')](handleError(_0x403beb,null));};exports[_0xbb10('0x47')]=function(_0x3e06b0,_0x5be85e){return db['ZendeskAccount'][_0xbb10('0x47')](_0x3e06b0[_0xbb10('0x48')],{})[_0xbb10('0x25')](respondWithResult(_0x5be85e,0xc9))['catch'](handleError(_0x5be85e,null));};exports['update']=function(_0x3cd6f3,_0x34cf4e){if(_0x3cd6f3[_0xbb10('0x48')]['id']){delete _0x3cd6f3[_0xbb10('0x48')]['id'];}return db[_0xbb10('0x2b')][_0xbb10('0x46')]({'where':{'id':_0x3cd6f3[_0xbb10('0x45')]['id']}})[_0xbb10('0x25')](handleEntityNotFound(_0x34cf4e,null))[_0xbb10('0x25')](saveUpdates(_0x3cd6f3[_0xbb10('0x48')],null))['then'](respondWithResult(_0x34cf4e,null))['catch'](handleError(_0x34cf4e,null));};exports[_0xbb10('0x26')]=function(_0x467dba,_0x36ab7d){return db[_0xbb10('0x2b')][_0xbb10('0x46')]({'where':{'id':_0x467dba[_0xbb10('0x45')]['id']}})[_0xbb10('0x25')](handleEntityNotFound(_0x36ab7d,null))[_0xbb10('0x25')](removeEntity(_0x36ab7d,null))[_0xbb10('0x43')](handleError(_0x36ab7d,null));};exports[_0xbb10('0x49')]=function(_0x19ca3e,_0x20e18a,_0x61e689){var _0x2e6fd9={};var _0x1d15f4={};var _0x547a7a;var _0x124052;return db['ZendeskAccount'][_0xbb10('0x4a')]({'where':{'id':_0x19ca3e[_0xbb10('0x45')]['id']}})[_0xbb10('0x25')](handleEntityNotFound(_0x20e18a,null))[_0xbb10('0x25')](function(_0x26e66e){if(_0x26e66e){_0x547a7a=_0x26e66e;_0x1d15f4[_0xbb10('0x2e')]=_[_0xbb10('0x30')](db[_0xbb10('0x4b')][_0xbb10('0x4c')]);_0x1d15f4[_0xbb10('0x2f')]=_[_0xbb10('0x30')](_0x19ca3e[_0xbb10('0x2f')]);_0x1d15f4[_0xbb10('0x31')]=_[_0xbb10('0x32')](_0x1d15f4[_0xbb10('0x2e')],_0x1d15f4['query']);_0x2e6fd9[_0xbb10('0x33')]=_[_0xbb10('0x32')](_0x1d15f4[_0xbb10('0x2e')],qs[_0xbb10('0x34')](_0x19ca3e[_0xbb10('0x2f')][_0xbb10('0x34')]));_0x2e6fd9['attributes']=_0x2e6fd9[_0xbb10('0x33')][_0xbb10('0x35')]?_0x2e6fd9[_0xbb10('0x33')]:_0x1d15f4[_0xbb10('0x2e')];_0x2e6fd9[_0xbb10('0x37')]=qs[_0xbb10('0x38')](_0x19ca3e[_0xbb10('0x2f')][_0xbb10('0x38')]);_0x2e6fd9[_0xbb10('0x39')]=qs[_0xbb10('0x31')](_[_0xbb10('0x4d')](_0x19ca3e[_0xbb10('0x2f')],_0x1d15f4[_0xbb10('0x31')]));if(_0x19ca3e['query']['filter']){_0x2e6fd9[_0xbb10('0x39')]=_[_0xbb10('0x3a')](_0x2e6fd9[_0xbb10('0x39')],{'$or':_[_0xbb10('0x3b')](_0x2e6fd9['attributes'],function(_0x506498){var _0x79411e={};_0x79411e[_0x506498]={'$like':'%'+_0x19ca3e[_0xbb10('0x2f')][_0xbb10('0x3d')]+'%'};return _0x79411e;})});}_0x2e6fd9=_[_0xbb10('0x3a')]({},_0x2e6fd9,_0x19ca3e[_0xbb10('0x3e')]);return _0x547a7a[_0xbb10('0x49')](_0x2e6fd9);}})[_0xbb10('0x25')](function(_0x4a5fb9){if(_0x4a5fb9){_0x124052=_0x4a5fb9[_0xbb10('0x35')];if(!_0x19ca3e[_0xbb10('0x2f')]['hasOwnProperty']('nolimit')){_0x2e6fd9['limit']=qs[_0xbb10('0x1e')](_0x19ca3e[_0xbb10('0x2f')][_0xbb10('0x1e')]);_0x2e6fd9['offset']=qs['offset'](_0x19ca3e['query'][_0xbb10('0x20')]);}return _0x547a7a[_0xbb10('0x49')](_0x2e6fd9);}})[_0xbb10('0x25')](function(_0x4e9fbd){if(_0x4e9fbd){return _0x4e9fbd?{'count':_0x124052,'rows':_0x4e9fbd}:null;}})[_0xbb10('0x25')](respondWithResult(_0x20e18a,null))[_0xbb10('0x43')](handleError(_0x20e18a,null));};exports['addConfiguration']=function(_0x4a560c,_0x27d7b9,_0x308896){if(_0x4a560c[_0xbb10('0x48')]['id']){delete _0x4a560c[_0xbb10('0x48')]['id'];}return db['ZendeskAccount'][_0xbb10('0x4a')]({'where':{'id':_0x4a560c[_0xbb10('0x45')]['id']}})[_0xbb10('0x25')](handleEntityNotFound(_0x27d7b9,null))['then'](function(_0x402a01){if(_0x402a01){_0x4a560c[_0xbb10('0x48')][_0xbb10('0x4e')]=_0x402a01['id'];_0x4a560c['body'][_0xbb10('0x4f')]=integrations[_0xbb10('0x50')](_0x4a560c[_0xbb10('0x48')][_0xbb10('0x51')],_0x4a560c['body'][_0xbb10('0x2c')]);_0x4a560c[_0xbb10('0x48')][_0xbb10('0x52')]=integrations[_0xbb10('0x53')](_0x4a560c['body'][_0xbb10('0x51')],_0x4a560c[_0xbb10('0x48')][_0xbb10('0x2c')]);return db[_0xbb10('0x4b')][_0xbb10('0x47')](_0x4a560c[_0xbb10('0x48')],{'include':[{'model':db[_0xbb10('0x54')],'as':'Subjects'},{'model':db['ZendeskField'],'as':'Descriptions'}]});}return null;})[_0xbb10('0x25')](respondWithResult(_0x27d7b9,null))[_0xbb10('0x43')](handleError(_0x27d7b9,null));};exports[_0xbb10('0x55')]=function(_0x5c9afc,_0x5cd089,_0x46f462){var _0x1b11c0='';return db[_0xbb10('0x2b')][_0xbb10('0x4a')]({'where':{'id':_0x5c9afc[_0xbb10('0x45')]['id']},'attributes':['id',_0xbb10('0x56'),'password',_0xbb10('0x57'),_0xbb10('0x58'),_0xbb10('0x59')]})[_0xbb10('0x25')](handleEntityNotFound(_0x5cd089,null))[_0xbb10('0x25')](function(_0x5bfc68){if(_0x5bfc68){_0x1b11c0=_0x5bfc68['remoteUri'];var _0x5ad6ad=_0x1b11c0[_0xbb10('0x5a')](-0x1);if(_0x5ad6ad==='/'){_0x1b11c0=_0x1b11c0[_0xbb10('0x5b')](0x0,_0x1b11c0[_0xbb10('0x5c')](_0x5ad6ad));}var _0x21459e={'method':_0xbb10('0x5d'),'uri':util[_0xbb10('0x5e')]('%s/%s',_0x1b11c0,_0xbb10('0x5f')),'json':!![]};switch(_0x5bfc68['authType']){case'password':_0x21459e['headers']={'Authorization':util[_0xbb10('0x5e')](_0xbb10('0x60'),new Buffer(util[_0xbb10('0x5e')](_0xbb10('0x61'),_0x5bfc68['username'],_0x5bfc68[_0xbb10('0x62')]))['toString']('base64'))};break;case _0xbb10('0x57'):_0x21459e[_0xbb10('0x63')]={'Authorization':util[_0xbb10('0x5e')](_0xbb10('0x60'),new Buffer(util[_0xbb10('0x5e')]('%s/token:%s',_0x5bfc68[_0xbb10('0x56')],_0x5bfc68[_0xbb10('0x57')]))[_0xbb10('0x64')](_0xbb10('0x65')))};break;default:throw new db[(_0xbb10('0x66'))][(_0xbb10('0x67'))](_0xbb10('0x68'));}return rp(_0x21459e);}})['then'](function(_0x387b10){if(_0x387b10){var _0x1f648a=[_0xbb10('0x69'),_0xbb10('0x6a'),_0xbb10('0x6b'),_0xbb10('0x6c')];_[_0xbb10('0x6d')](_0x387b10[_0xbb10('0x5f')],function(_0x5a4429){return _0x1f648a[_0xbb10('0x6e')](_0x5a4429[_0xbb10('0x2c')]);});return{'count':_0x387b10[_0xbb10('0x5f')]['length'],'rows':_['map'](_0x387b10['ticket_fields'],function(_0x23286d){return{'id':_0x23286d['id'],'name':_0x23286d['position']>0x7?_0x23286d['title']:_0x23286d[_0xbb10('0x2c')],'custom':_0x23286d[_0xbb10('0x6f')]>0x7?!![]:![],'options':_0x23286d[_0xbb10('0x70')]?_0x23286d[_0xbb10('0x70')]:_0x23286d[_0xbb10('0x71')]?_0x23286d[_0xbb10('0x71')]:[]};})};}})[_0xbb10('0x25')](respondWithResult(_0x5cd089,null))[_0xbb10('0x43')](function(_0x188b97){var _0x5206e1=_0x5c9afc[_0xbb10('0x2f')][_0xbb10('0x72')]?0x1f4:_0x188b97[_0xbb10('0x73')]||0x1f4;logger[_0xbb10('0x27')]('getFields,\x20%s,\x20%s,\x20%s','getFields',_0x5206e1,JSON[_0xbb10('0x74')](_0x188b97));delete _0x188b97[_0xbb10('0x29')];if(_0x5206e1===0x191){_0x5206e1=0x190;}_0x5cd089[_0xbb10('0x1b')](_0x5206e1)[_0xbb10('0x2a')](_0x5c9afc['query'][_0xbb10('0x72')]?{'message':_0xbb10('0x75'),'statusCode':_0x188b97[_0xbb10('0x73')]}:_0x188b97);});};
\ No newline at end of file