Built motion from commit (unavailable).|2.5.26
[motion2.git] / server / api / intZendeskAccount / intZendeskAccount.controller.js
index 792853f..25cb5c0 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xe1aa=['title','system_field_options','custom_field_options','statusCode','getFields,\x20%s,\x20%s,\x20%s','Wrong\x20credentials','html-pdf','eml-format','fast-json-patch','request-promise','moment','bluebird','mustache','path','to-csv','ejs','crypto','jsforce','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','../../components/integrations/configuration','jayson/promise','client','http','request','then','info','ZendeskAccount,\x20%s,\x20%s','debug','ZendeskAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','request\x20sent','result','catch','sendStatus','status','json','count','offset','set','Content-Range','apply','save','update','end','name','send','ZendeskAccount','rawAttributes','fieldName','type','key','model','keys','query','filters','intersection','attributes','fields','length','nolimit','limit','order','sort','pick','filter','where','merge','map','includeAll','include','findAll','show','params','options','find','create','body','getConfigurations','findOne','ZendeskConfiguration','Subjects','channel','ZendeskField','Descriptions','getFields','username','token','remoteUri','slice','substring','lastIndexOf','GET','format','%s/%s','authType','password','headers','Basic\x20%s','toString','base64','%s/token:%s','Sequelize','ValidationError','subject','description','group','assignee','remove','includes','ticket_fields','position'];(function(_0x39096d,_0x51f8a0){var _0x13da4f=function(_0x11e6b2){while(--_0x11e6b2){_0x39096d['push'](_0x39096d['shift']());}};_0x13da4f(++_0x51f8a0);}(_0xe1aa,0xfc));var _0xae1a=function(_0x3947c9,_0x4d6c97){_0x3947c9=_0x3947c9-0x0;var _0x2e7871=_0xe1aa[_0x3947c9];return _0x2e7871;};'use strict';var pdf=require(_0xae1a('0x0'));var emlformat=require(_0xae1a('0x1'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0xae1a('0x2'));var rp=require(_0xae1a('0x3'));var moment=require(_0xae1a('0x4'));var BPromise=require(_0xae1a('0x5'));var Mustache=require(_0xae1a('0x6'));var util=require('util');var path=require(_0xae1a('0x7'));var sox=require('sox');var csv=require(_0xae1a('0x8'));var ejs=require(_0xae1a('0x9'));var fs=require('fs');var _=require('lodash');var squel=require('squel');var crypto=require(_0xae1a('0xa'));var jsforce=require(_0xae1a('0xb'));var deskjs=require('desk.js');var toCsv=require(_0xae1a('0x8'));var querystring=require(_0xae1a('0xc'));var Papa=require('papaparse');var Redis=require(_0xae1a('0xd'));var authService=require(_0xae1a('0xe'));var qs=require(_0xae1a('0xf'));var as=require(_0xae1a('0x10'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xae1a('0x11'))(_0xae1a('0x12'));var utils=require('../../config/utils');var config=require(_0xae1a('0x13'));var licenseUtil=require(_0xae1a('0x14'));var db=require(_0xae1a('0x15'))['db'];var integrations=require(_0xae1a('0x16'));var jayson=require(_0xae1a('0x17'));var client=jayson[_0xae1a('0x18')][_0xae1a('0x19')]({'port':0x232a});function respondWithRpcPromise(_0x178163,_0x7f222f,_0x2f9390,_0x47ce8e){return new BPromise(function(_0x53dc19,_0x580f1c){var _0x52ea8a=_0x47ce8e||client;return _0x52ea8a[_0xae1a('0x1a')](_0x178163,_0x2f9390)[_0xae1a('0x1b')](function(_0x2eb725){logger[_0xae1a('0x1c')](_0xae1a('0x1d'),_0x7f222f,'request\x20sent');logger[_0xae1a('0x1e')](_0xae1a('0x1f'),_0x7f222f,'request\x20sent',JSON[_0xae1a('0x20')](_0x2eb725));if(_0x2eb725[_0xae1a('0x21')]){if(_0x2eb725[_0xae1a('0x21')][_0xae1a('0x22')]===0x1f4){logger[_0xae1a('0x21')](_0xae1a('0x1d'),_0x7f222f,_0x2eb725[_0xae1a('0x21')][_0xae1a('0x23')]);return _0x580f1c(_0x2eb725[_0xae1a('0x21')][_0xae1a('0x23')]);}logger['error'](_0xae1a('0x1d'),_0x7f222f,_0x2eb725[_0xae1a('0x21')][_0xae1a('0x23')]);return _0x53dc19(_0x2eb725[_0xae1a('0x21')][_0xae1a('0x23')]);}else{logger['info'](_0xae1a('0x1d'),_0x7f222f,_0xae1a('0x24'));_0x53dc19(_0x2eb725[_0xae1a('0x25')]['message']);}})[_0xae1a('0x26')](function(_0x146964){logger[_0xae1a('0x21')](_0xae1a('0x1d'),_0x7f222f,_0x146964);_0x580f1c(_0x146964);});});}function respondWithStatusCode(_0xb3e00d,_0x29a121){_0x29a121=_0x29a121||0xcc;return function(_0x5c5b60){if(_0x5c5b60){return _0xb3e00d[_0xae1a('0x27')](_0x29a121);}return _0xb3e00d['status'](_0x29a121)['end']();};}function respondWithResult(_0x112838,_0x2f13dc){_0x2f13dc=_0x2f13dc||0xc8;return function(_0x3907c6){if(_0x3907c6){return _0x112838[_0xae1a('0x28')](_0x2f13dc)[_0xae1a('0x29')](_0x3907c6);}};}function respondWithFilteredResult(_0x4ecb5b,_0x270e66){return function(_0x454142){if(_0x454142){var _0x29ed55=_0x454142[_0xae1a('0x2a')],_0x5e472d=_0x270e66[_0xae1a('0x2b')],_0x55e53b=_0x270e66['offset']+_0x270e66['limit'],_0x5e66da;if(_0x55e53b>=_0x29ed55){_0x55e53b=_0x29ed55;_0x5e66da=0xc8;}else{_0x5e66da=0xce;}_0x4ecb5b[_0xae1a('0x28')](_0x5e66da);return _0x4ecb5b[_0xae1a('0x2c')](_0xae1a('0x2d'),_0x5e472d+'-'+_0x55e53b+'/'+_0x29ed55)[_0xae1a('0x29')](_0x454142);}return null;};}function patchUpdates(_0x29fef2){return function(_0x6cec0e){try{jsonpatch[_0xae1a('0x2e')](_0x6cec0e,_0x29fef2,!![]);}catch(_0x564fca){return BPromise['reject'](_0x564fca);}return _0x6cec0e[_0xae1a('0x2f')]();};}function saveUpdates(_0x2e2d5e,_0x6eac43){return function(_0x4be759){if(_0x4be759){return _0x4be759[_0xae1a('0x30')](_0x2e2d5e)[_0xae1a('0x1b')](function(_0x1f6c4c){return _0x1f6c4c;});}return null;};}function removeEntity(_0x59ad9e,_0x2dcf41){return function(_0x10d50b){if(_0x10d50b){return _0x10d50b['destroy']()[_0xae1a('0x1b')](function(){_0x59ad9e[_0xae1a('0x28')](0xcc)[_0xae1a('0x31')]();});}};}function handleEntityNotFound(_0x112ee2,_0x5756ed){return function(_0x5c24ff){if(!_0x5c24ff){_0x112ee2['sendStatus'](0x194);}return _0x5c24ff;};}function handleError(_0x4e95d7,_0x18e8b6){_0x18e8b6=_0x18e8b6||0x1f4;return function(_0x4c3416){logger[_0xae1a('0x21')](_0x4c3416['stack']);if(_0x4c3416['name']){delete _0x4c3416[_0xae1a('0x32')];}_0x4e95d7[_0xae1a('0x28')](_0x18e8b6)[_0xae1a('0x33')](_0x4c3416);};}exports['index']=function(_0x412791,_0xffc156){var _0x14428a={},_0xcc01a7={},_0x511531={'count':0x0,'rows':[]};var _0x4b807f=_['map'](db[_0xae1a('0x34')][_0xae1a('0x35')],function(_0x5effca){return{'name':_0x5effca[_0xae1a('0x36')],'type':_0x5effca[_0xae1a('0x37')][_0xae1a('0x38')]};});_0xcc01a7[_0xae1a('0x39')]=_['map'](_0x4b807f,_0xae1a('0x32'));_0xcc01a7['query']=_[_0xae1a('0x3a')](_0x412791[_0xae1a('0x3b')]);_0xcc01a7[_0xae1a('0x3c')]=_[_0xae1a('0x3d')](_0xcc01a7[_0xae1a('0x39')],_0xcc01a7[_0xae1a('0x3b')]);_0x14428a[_0xae1a('0x3e')]=_['intersection'](_0xcc01a7[_0xae1a('0x39')],qs[_0xae1a('0x3f')](_0x412791[_0xae1a('0x3b')][_0xae1a('0x3f')]));_0x14428a[_0xae1a('0x3e')]=_0x14428a[_0xae1a('0x3e')][_0xae1a('0x40')]?_0x14428a['attributes']:_0xcc01a7['model'];if(!_0x412791[_0xae1a('0x3b')]['hasOwnProperty'](_0xae1a('0x41'))){_0x14428a[_0xae1a('0x42')]=qs[_0xae1a('0x42')](_0x412791[_0xae1a('0x3b')][_0xae1a('0x42')]);_0x14428a['offset']=qs['offset'](_0x412791[_0xae1a('0x3b')]['offset']);}_0x14428a[_0xae1a('0x43')]=qs[_0xae1a('0x44')](_0x412791['query'][_0xae1a('0x44')]);_0x14428a['where']=qs['filters'](_[_0xae1a('0x45')](_0x412791['query'],_0xcc01a7[_0xae1a('0x3c')]),_0x4b807f);if(_0x412791['query'][_0xae1a('0x46')]){_0x14428a[_0xae1a('0x47')]=_[_0xae1a('0x48')](_0x14428a[_0xae1a('0x47')],{'$or':_[_0xae1a('0x49')](_0x4b807f,function(_0x48cd32){if(_0x48cd32['type']!=='VIRTUAL'){var _0x583be5={};_0x583be5[_0x48cd32['name']]={'$like':'%'+_0x412791[_0xae1a('0x3b')][_0xae1a('0x46')]+'%'};return _0x583be5;}})});}_0x14428a=_['merge']({},_0x14428a,_0x412791['options']);var _0x4ef335={'where':_0x14428a[_0xae1a('0x47')]};return db[_0xae1a('0x34')][_0xae1a('0x2a')](_0x4ef335)[_0xae1a('0x1b')](function(_0x41fd75){_0x511531[_0xae1a('0x2a')]=_0x41fd75;if(_0x412791[_0xae1a('0x3b')][_0xae1a('0x4a')]){_0x14428a[_0xae1a('0x4b')]=[{'all':!![]}];}return db[_0xae1a('0x34')][_0xae1a('0x4c')](_0x14428a);})['then'](function(_0xa04f3b){_0x511531['rows']=_0xa04f3b;return _0x511531;})[_0xae1a('0x1b')](respondWithFilteredResult(_0xffc156,_0x14428a))[_0xae1a('0x26')](handleError(_0xffc156,null));};exports[_0xae1a('0x4d')]=function(_0x24017b,_0x1884b){var _0x4dfd5d={'raw':![],'where':{'id':_0x24017b[_0xae1a('0x4e')]['id']}},_0x44e53b={};_0x44e53b[_0xae1a('0x39')]=_['keys'](db['ZendeskAccount']['rawAttributes']);_0x44e53b[_0xae1a('0x3b')]=_[_0xae1a('0x3a')](_0x24017b['query']);_0x44e53b[_0xae1a('0x3c')]=_[_0xae1a('0x3d')](_0x44e53b['model'],_0x44e53b[_0xae1a('0x3b')]);_0x4dfd5d[_0xae1a('0x3e')]=_[_0xae1a('0x3d')](_0x44e53b['model'],qs[_0xae1a('0x3f')](_0x24017b['query']['fields']));_0x4dfd5d[_0xae1a('0x3e')]=_0x4dfd5d[_0xae1a('0x3e')][_0xae1a('0x40')]?_0x4dfd5d[_0xae1a('0x3e')]:_0x44e53b[_0xae1a('0x39')];if(_0x24017b[_0xae1a('0x3b')]['includeAll']){_0x4dfd5d[_0xae1a('0x4b')]=[{'all':!![]}];}_0x4dfd5d=_[_0xae1a('0x48')]({},_0x4dfd5d,_0x24017b[_0xae1a('0x4f')]);return db[_0xae1a('0x34')][_0xae1a('0x50')](_0x4dfd5d)[_0xae1a('0x1b')](handleEntityNotFound(_0x1884b,null))[_0xae1a('0x1b')](respondWithResult(_0x1884b,null))[_0xae1a('0x26')](handleError(_0x1884b,null));};exports[_0xae1a('0x51')]=function(_0x1c7974,_0x39ea9b){return db[_0xae1a('0x34')][_0xae1a('0x51')](_0x1c7974['body'],{})[_0xae1a('0x1b')](respondWithResult(_0x39ea9b,0xc9))[_0xae1a('0x26')](handleError(_0x39ea9b,null));};exports[_0xae1a('0x30')]=function(_0x5e9d35,_0x42e38d){if(_0x5e9d35[_0xae1a('0x52')]['id']){delete _0x5e9d35[_0xae1a('0x52')]['id'];}return db[_0xae1a('0x34')][_0xae1a('0x50')]({'where':{'id':_0x5e9d35[_0xae1a('0x4e')]['id']}})['then'](handleEntityNotFound(_0x42e38d,null))[_0xae1a('0x1b')](saveUpdates(_0x5e9d35[_0xae1a('0x52')],null))['then'](respondWithResult(_0x42e38d,null))[_0xae1a('0x26')](handleError(_0x42e38d,null));};exports['destroy']=function(_0x1bb56b,_0x35bb5b){return db[_0xae1a('0x34')][_0xae1a('0x50')]({'where':{'id':_0x1bb56b[_0xae1a('0x4e')]['id']}})[_0xae1a('0x1b')](handleEntityNotFound(_0x35bb5b,null))['then'](removeEntity(_0x35bb5b,null))[_0xae1a('0x26')](handleError(_0x35bb5b,null));};exports[_0xae1a('0x53')]=function(_0x23d681,_0x47e645,_0xb4bf58){var _0x1abe8d={};var _0xf1b785={};var _0xaf494b;var _0x30eb01;return db[_0xae1a('0x34')][_0xae1a('0x54')]({'where':{'id':_0x23d681[_0xae1a('0x4e')]['id']}})[_0xae1a('0x1b')](handleEntityNotFound(_0x47e645,null))[_0xae1a('0x1b')](function(_0x57e5f7){if(_0x57e5f7){_0xaf494b=_0x57e5f7;_0xf1b785[_0xae1a('0x39')]=_[_0xae1a('0x3a')](db[_0xae1a('0x55')][_0xae1a('0x35')]);_0xf1b785[_0xae1a('0x3b')]=_[_0xae1a('0x3a')](_0x23d681[_0xae1a('0x3b')]);_0xf1b785[_0xae1a('0x3c')]=_[_0xae1a('0x3d')](_0xf1b785[_0xae1a('0x39')],_0xf1b785[_0xae1a('0x3b')]);_0x1abe8d[_0xae1a('0x3e')]=_[_0xae1a('0x3d')](_0xf1b785[_0xae1a('0x39')],qs[_0xae1a('0x3f')](_0x23d681[_0xae1a('0x3b')][_0xae1a('0x3f')]));_0x1abe8d[_0xae1a('0x3e')]=_0x1abe8d[_0xae1a('0x3e')]['length']?_0x1abe8d[_0xae1a('0x3e')]:_0xf1b785[_0xae1a('0x39')];_0x1abe8d[_0xae1a('0x43')]=qs['sort'](_0x23d681[_0xae1a('0x3b')]['sort']);_0x1abe8d[_0xae1a('0x47')]=qs[_0xae1a('0x3c')](_[_0xae1a('0x45')](_0x23d681[_0xae1a('0x3b')],_0xf1b785[_0xae1a('0x3c')]));if(_0x23d681[_0xae1a('0x3b')]['filter']){_0x1abe8d['where']=_[_0xae1a('0x48')](_0x1abe8d[_0xae1a('0x47')],{'$or':_[_0xae1a('0x49')](_0x1abe8d[_0xae1a('0x3e')],function(_0x5e2972){var _0x347b38={};_0x347b38[_0x5e2972]={'$like':'%'+_0x23d681[_0xae1a('0x3b')][_0xae1a('0x46')]+'%'};return _0x347b38;})});}_0x1abe8d=_[_0xae1a('0x48')]({},_0x1abe8d,_0x23d681[_0xae1a('0x4f')]);return _0xaf494b[_0xae1a('0x53')](_0x1abe8d);}})[_0xae1a('0x1b')](function(_0x42197d){if(_0x42197d){_0x30eb01=_0x42197d['length'];if(!_0x23d681[_0xae1a('0x3b')]['hasOwnProperty']('nolimit')){_0x1abe8d[_0xae1a('0x42')]=qs[_0xae1a('0x42')](_0x23d681[_0xae1a('0x3b')][_0xae1a('0x42')]);_0x1abe8d['offset']=qs['offset'](_0x23d681[_0xae1a('0x3b')][_0xae1a('0x2b')]);}return _0xaf494b[_0xae1a('0x53')](_0x1abe8d);}})[_0xae1a('0x1b')](function(_0x59ec71){if(_0x59ec71){return _0x59ec71?{'count':_0x30eb01,'rows':_0x59ec71}:null;}})[_0xae1a('0x1b')](respondWithResult(_0x47e645,null))[_0xae1a('0x26')](handleError(_0x47e645,null));};exports['addConfiguration']=function(_0x12aadf,_0x22198a,_0x4352d5){if(_0x12aadf[_0xae1a('0x52')]['id']){delete _0x12aadf[_0xae1a('0x52')]['id'];}return db[_0xae1a('0x34')][_0xae1a('0x54')]({'where':{'id':_0x12aadf[_0xae1a('0x4e')]['id']}})[_0xae1a('0x1b')](handleEntityNotFound(_0x22198a,null))[_0xae1a('0x1b')](function(_0x52b438){if(_0x52b438){_0x12aadf[_0xae1a('0x52')]['AccountId']=_0x52b438['id'];_0x12aadf[_0xae1a('0x52')][_0xae1a('0x56')]=integrations['getSubjects'](_0x12aadf['body'][_0xae1a('0x57')],_0x12aadf['body']['type']);_0x12aadf[_0xae1a('0x52')]['Descriptions']=integrations['getDescriptions'](_0x12aadf[_0xae1a('0x52')][_0xae1a('0x57')],_0x12aadf[_0xae1a('0x52')][_0xae1a('0x37')]);return db[_0xae1a('0x55')][_0xae1a('0x51')](_0x12aadf[_0xae1a('0x52')],{'include':[{'model':db[_0xae1a('0x58')],'as':_0xae1a('0x56')},{'model':db[_0xae1a('0x58')],'as':_0xae1a('0x59')}]});}return null;})[_0xae1a('0x1b')](respondWithResult(_0x22198a,null))['catch'](handleError(_0x22198a,null));};exports[_0xae1a('0x5a')]=function(_0xcac5c0,_0x43b980,_0x1f216a){var _0x1a3210='';return db[_0xae1a('0x34')][_0xae1a('0x54')]({'where':{'id':_0xcac5c0[_0xae1a('0x4e')]['id']},'attributes':['id',_0xae1a('0x5b'),'password',_0xae1a('0x5c'),'authType',_0xae1a('0x5d')]})[_0xae1a('0x1b')](handleEntityNotFound(_0x43b980,null))[_0xae1a('0x1b')](function(_0x40f978){if(_0x40f978){_0x1a3210=_0x40f978[_0xae1a('0x5d')];var _0x5c6727=_0x1a3210[_0xae1a('0x5e')](-0x1);if(_0x5c6727==='/'){_0x1a3210=_0x1a3210[_0xae1a('0x5f')](0x0,_0x1a3210[_0xae1a('0x60')](_0x5c6727));}var _0x277e08={'method':_0xae1a('0x61'),'uri':util[_0xae1a('0x62')](_0xae1a('0x63'),_0x1a3210,'ticket_fields'),'json':!![]};switch(_0x40f978[_0xae1a('0x64')]){case _0xae1a('0x65'):_0x277e08[_0xae1a('0x66')]={'Authorization':util[_0xae1a('0x62')](_0xae1a('0x67'),new Buffer(util['format']('%s:%s',_0x40f978[_0xae1a('0x5b')],_0x40f978[_0xae1a('0x65')]))[_0xae1a('0x68')](_0xae1a('0x69')))};break;case'token':_0x277e08[_0xae1a('0x66')]={'Authorization':util['format'](_0xae1a('0x67'),new Buffer(util['format'](_0xae1a('0x6a'),_0x40f978[_0xae1a('0x5b')],_0x40f978[_0xae1a('0x5c')]))['toString'](_0xae1a('0x69')))};break;default:throw new db[(_0xae1a('0x6b'))][(_0xae1a('0x6c'))]('Unknown\x20authentication\x20type');}return rp(_0x277e08);}})[_0xae1a('0x1b')](function(_0x56dc33){if(_0x56dc33){var _0x37e90b=[_0xae1a('0x6d'),_0xae1a('0x6e'),_0xae1a('0x6f'),_0xae1a('0x70')];_[_0xae1a('0x71')](_0x56dc33['ticket_fields'],function(_0x189db9){return _0x37e90b[_0xae1a('0x72')](_0x189db9[_0xae1a('0x37')]);});return{'count':_0x56dc33[_0xae1a('0x73')]['length'],'rows':_[_0xae1a('0x49')](_0x56dc33['ticket_fields'],function(_0x1ce796){return{'id':_0x1ce796['id'],'name':_0x1ce796[_0xae1a('0x74')]>0x7?_0x1ce796[_0xae1a('0x75')]:_0x1ce796[_0xae1a('0x37')],'custom':_0x1ce796[_0xae1a('0x74')]>0x7?!![]:![],'options':_0x1ce796[_0xae1a('0x76')]?_0x1ce796['system_field_options']:_0x1ce796[_0xae1a('0x77')]?_0x1ce796[_0xae1a('0x77')]:[]};})};}})['then'](respondWithResult(_0x43b980,null))[_0xae1a('0x26')](function(_0x5c2f16){var _0x49d32f=_0xcac5c0['query']['test']?0x1f4:_0x5c2f16[_0xae1a('0x78')]||0x1f4;logger['error'](_0xae1a('0x79'),_0xae1a('0x5a'),_0x49d32f,JSON[_0xae1a('0x20')](_0x5c2f16));delete _0x5c2f16['name'];if(_0x49d32f===0x191){_0x49d32f=0x190;}_0x43b980[_0xae1a('0x28')](_0x49d32f)[_0xae1a('0x33')](_0xcac5c0[_0xae1a('0x3b')]['test']?{'message':_0xae1a('0x7a'),'statusCode':_0x5c2f16[_0xae1a('0x78')]}:_0x5c2f16);});};
\ No newline at end of file
+var _0xadf0=['show','params','keys','fields','includeAll','include','find','create','body','destroy','getConfigurations','findOne','ZendeskConfiguration','addConfiguration','AccountId','Subjects','Descriptions','getDescriptions','channel','ZendeskField','getFields','username','password','token','remoteUri','slice','substring','GET','%s/%s','ticket_fields','Basic\x20%s','format','toString','headers','%s/token:%s','base64','Sequelize','Unknown\x20authentication\x20type','subject','description','group','assignee','remove','includes','position','title','custom_field_options','test','statusCode','getFields,\x20%s,\x20%s,\x20%s','Wrong\x20credentials','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','path','lodash','squel','desk.js','to-csv','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','jayson/promise','client','request','then','info','ZendeskAccount,\x20%s,\x20%s','debug','ZendeskAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','sendStatus','end','status','json','count','offset','limit','set','Content-Range','apply','reject','save','update','name','send','index','ZendeskAccount','rawAttributes','fieldName','type','map','query','filters','intersection','model','attributes','length','hasOwnProperty','nolimit','order','sort','where','VIRTUAL','filter','merge','options','findAll','rows'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0xadf0,0x12d));var _0x0adf=function(_0x210ff7,_0x45ed46){_0x210ff7=_0x210ff7-0x0;var _0x330a3d=_0xadf0[_0x210ff7];return _0x330a3d;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x0adf('0x0'));var zipdir=require(_0x0adf('0x1'));var jsonpatch=require(_0x0adf('0x2'));var rp=require(_0x0adf('0x3'));var moment=require(_0x0adf('0x4'));var BPromise=require(_0x0adf('0x5'));var Mustache=require(_0x0adf('0x6'));var util=require('util');var path=require(_0x0adf('0x7'));var sox=require('sox');var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x0adf('0x8'));var squel=require(_0x0adf('0x9'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0x0adf('0xa'));var toCsv=require(_0x0adf('0xb'));var querystring=require('querystring');var Papa=require(_0x0adf('0xc'));var Redis=require(_0x0adf('0xd'));var authService=require('../../components/auth/service');var qs=require(_0x0adf('0xe'));var as=require(_0x0adf('0xf'));var hardwareService=require(_0x0adf('0x10'));var logger=require('../../config/logger')(_0x0adf('0x11'));var utils=require(_0x0adf('0x12'));var config=require(_0x0adf('0x13'));var licenseUtil=require(_0x0adf('0x14'));var db=require(_0x0adf('0x15'))['db'];var integrations=require('../../components/integrations/configuration');var jayson=require(_0x0adf('0x16'));var client=jayson[_0x0adf('0x17')]['http']({'port':0x232a});function respondWithRpcPromise(_0x57418c,_0x5637ec,_0xb018be,_0x4d4f0d){return new BPromise(function(_0x75ddac,_0x45bbab){var _0x3d7528=_0x4d4f0d||client;return _0x3d7528[_0x0adf('0x18')](_0x57418c,_0xb018be)[_0x0adf('0x19')](function(_0x2db0a2){logger[_0x0adf('0x1a')](_0x0adf('0x1b'),_0x5637ec,'request\x20sent');logger[_0x0adf('0x1c')](_0x0adf('0x1d'),_0x5637ec,'request\x20sent',JSON[_0x0adf('0x1e')](_0x2db0a2));if(_0x2db0a2['error']){if(_0x2db0a2[_0x0adf('0x1f')][_0x0adf('0x20')]===0x1f4){logger[_0x0adf('0x1f')](_0x0adf('0x1b'),_0x5637ec,_0x2db0a2['error'][_0x0adf('0x21')]);return _0x45bbab(_0x2db0a2[_0x0adf('0x1f')][_0x0adf('0x21')]);}logger[_0x0adf('0x1f')](_0x0adf('0x1b'),_0x5637ec,_0x2db0a2[_0x0adf('0x1f')]['message']);return _0x75ddac(_0x2db0a2[_0x0adf('0x1f')][_0x0adf('0x21')]);}else{logger[_0x0adf('0x1a')](_0x0adf('0x1b'),_0x5637ec,'request\x20sent');_0x75ddac(_0x2db0a2[_0x0adf('0x22')][_0x0adf('0x21')]);}})[_0x0adf('0x23')](function(_0x53bfdd){logger[_0x0adf('0x1f')](_0x0adf('0x1b'),_0x5637ec,_0x53bfdd);_0x45bbab(_0x53bfdd);});});}function respondWithStatusCode(_0x152694,_0x4094ab){_0x4094ab=_0x4094ab||0xcc;return function(_0x2b6a57){if(_0x2b6a57){return _0x152694[_0x0adf('0x24')](_0x4094ab);}return _0x152694['status'](_0x4094ab)[_0x0adf('0x25')]();};}function respondWithResult(_0x314f00,_0x80f962){_0x80f962=_0x80f962||0xc8;return function(_0x39a337){if(_0x39a337){return _0x314f00[_0x0adf('0x26')](_0x80f962)[_0x0adf('0x27')](_0x39a337);}};}function respondWithFilteredResult(_0x4b0076,_0x306f94){return function(_0x2ebba2){if(_0x2ebba2){var _0x272205=_0x2ebba2[_0x0adf('0x28')],_0x5a7992=_0x306f94[_0x0adf('0x29')],_0x4ed6ad=_0x306f94[_0x0adf('0x29')]+_0x306f94[_0x0adf('0x2a')],_0x4e8301;if(_0x4ed6ad>=_0x272205){_0x4ed6ad=_0x272205;_0x4e8301=0xc8;}else{_0x4e8301=0xce;}_0x4b0076[_0x0adf('0x26')](_0x4e8301);return _0x4b0076[_0x0adf('0x2b')](_0x0adf('0x2c'),_0x5a7992+'-'+_0x4ed6ad+'/'+_0x272205)[_0x0adf('0x27')](_0x2ebba2);}return null;};}function patchUpdates(_0x2a0fcc){return function(_0x2b1f14){try{jsonpatch[_0x0adf('0x2d')](_0x2b1f14,_0x2a0fcc,!![]);}catch(_0x3dadfb){return BPromise[_0x0adf('0x2e')](_0x3dadfb);}return _0x2b1f14[_0x0adf('0x2f')]();};}function saveUpdates(_0x46dbba,_0x512260){return function(_0x168f04){if(_0x168f04){return _0x168f04[_0x0adf('0x30')](_0x46dbba)[_0x0adf('0x19')](function(_0x44a2ba){return _0x44a2ba;});}return null;};}function removeEntity(_0x1fe2e5,_0x363959){return function(_0x1931ca){if(_0x1931ca){return _0x1931ca['destroy']()[_0x0adf('0x19')](function(){_0x1fe2e5['status'](0xcc)[_0x0adf('0x25')]();});}};}function handleEntityNotFound(_0x33830c,_0x175d7e){return function(_0x39e5c2){if(!_0x39e5c2){_0x33830c[_0x0adf('0x24')](0x194);}return _0x39e5c2;};}function handleError(_0x35532f,_0x4161cf){_0x4161cf=_0x4161cf||0x1f4;return function(_0x2862fb){logger[_0x0adf('0x1f')](_0x2862fb['stack']);if(_0x2862fb[_0x0adf('0x31')]){delete _0x2862fb[_0x0adf('0x31')];}_0x35532f[_0x0adf('0x26')](_0x4161cf)[_0x0adf('0x32')](_0x2862fb);};}exports[_0x0adf('0x33')]=function(_0x4cdf07,_0x11224d){var _0x201e5d={},_0x38603b={},_0x2069f0={'count':0x0,'rows':[]};var _0x4b9f02=_['map'](db[_0x0adf('0x34')][_0x0adf('0x35')],function(_0x3b0367){return{'name':_0x3b0367[_0x0adf('0x36')],'type':_0x3b0367[_0x0adf('0x37')]['key']};});_0x38603b['model']=_[_0x0adf('0x38')](_0x4b9f02,_0x0adf('0x31'));_0x38603b['query']=_['keys'](_0x4cdf07[_0x0adf('0x39')]);_0x38603b[_0x0adf('0x3a')]=_[_0x0adf('0x3b')](_0x38603b[_0x0adf('0x3c')],_0x38603b[_0x0adf('0x39')]);_0x201e5d[_0x0adf('0x3d')]=_[_0x0adf('0x3b')](_0x38603b[_0x0adf('0x3c')],qs['fields'](_0x4cdf07[_0x0adf('0x39')]['fields']));_0x201e5d[_0x0adf('0x3d')]=_0x201e5d[_0x0adf('0x3d')][_0x0adf('0x3e')]?_0x201e5d[_0x0adf('0x3d')]:_0x38603b['model'];if(!_0x4cdf07[_0x0adf('0x39')][_0x0adf('0x3f')](_0x0adf('0x40'))){_0x201e5d[_0x0adf('0x2a')]=qs['limit'](_0x4cdf07[_0x0adf('0x39')][_0x0adf('0x2a')]);_0x201e5d[_0x0adf('0x29')]=qs['offset'](_0x4cdf07['query'][_0x0adf('0x29')]);}_0x201e5d[_0x0adf('0x41')]=qs[_0x0adf('0x42')](_0x4cdf07[_0x0adf('0x39')][_0x0adf('0x42')]);_0x201e5d[_0x0adf('0x43')]=qs['filters'](_['pick'](_0x4cdf07[_0x0adf('0x39')],_0x38603b[_0x0adf('0x3a')]),_0x4b9f02);if(_0x4cdf07[_0x0adf('0x39')]['filter']){_0x201e5d[_0x0adf('0x43')]=_['merge'](_0x201e5d[_0x0adf('0x43')],{'$or':_['map'](_0x4b9f02,function(_0x11e656){if(_0x11e656[_0x0adf('0x37')]!==_0x0adf('0x44')){var _0x1cad8a={};_0x1cad8a[_0x11e656[_0x0adf('0x31')]]={'$like':'%'+_0x4cdf07[_0x0adf('0x39')][_0x0adf('0x45')]+'%'};return _0x1cad8a;}})});}_0x201e5d=_[_0x0adf('0x46')]({},_0x201e5d,_0x4cdf07[_0x0adf('0x47')]);var _0x1f4429={'where':_0x201e5d[_0x0adf('0x43')]};return db['ZendeskAccount']['count'](_0x1f4429)['then'](function(_0x49a19a){_0x2069f0['count']=_0x49a19a;if(_0x4cdf07[_0x0adf('0x39')]['includeAll']){_0x201e5d['include']=[{'all':!![]}];}return db[_0x0adf('0x34')][_0x0adf('0x48')](_0x201e5d);})[_0x0adf('0x19')](function(_0x3e5907){_0x2069f0[_0x0adf('0x49')]=_0x3e5907;return _0x2069f0;})[_0x0adf('0x19')](respondWithFilteredResult(_0x11224d,_0x201e5d))['catch'](handleError(_0x11224d,null));};exports[_0x0adf('0x4a')]=function(_0x31e964,_0x252ae1){var _0x340049={'raw':![],'where':{'id':_0x31e964[_0x0adf('0x4b')]['id']}},_0x5b077f={};_0x5b077f[_0x0adf('0x3c')]=_[_0x0adf('0x4c')](db[_0x0adf('0x34')][_0x0adf('0x35')]);_0x5b077f[_0x0adf('0x39')]=_['keys'](_0x31e964[_0x0adf('0x39')]);_0x5b077f['filters']=_['intersection'](_0x5b077f[_0x0adf('0x3c')],_0x5b077f['query']);_0x340049['attributes']=_['intersection'](_0x5b077f[_0x0adf('0x3c')],qs[_0x0adf('0x4d')](_0x31e964[_0x0adf('0x39')][_0x0adf('0x4d')]));_0x340049[_0x0adf('0x3d')]=_0x340049[_0x0adf('0x3d')][_0x0adf('0x3e')]?_0x340049[_0x0adf('0x3d')]:_0x5b077f[_0x0adf('0x3c')];if(_0x31e964[_0x0adf('0x39')][_0x0adf('0x4e')]){_0x340049[_0x0adf('0x4f')]=[{'all':!![]}];}_0x340049=_[_0x0adf('0x46')]({},_0x340049,_0x31e964[_0x0adf('0x47')]);return db[_0x0adf('0x34')][_0x0adf('0x50')](_0x340049)[_0x0adf('0x19')](handleEntityNotFound(_0x252ae1,null))['then'](respondWithResult(_0x252ae1,null))['catch'](handleError(_0x252ae1,null));};exports[_0x0adf('0x51')]=function(_0x8c93e9,_0x1eba36){return db[_0x0adf('0x34')][_0x0adf('0x51')](_0x8c93e9[_0x0adf('0x52')],{})['then'](respondWithResult(_0x1eba36,0xc9))['catch'](handleError(_0x1eba36,null));};exports[_0x0adf('0x30')]=function(_0x19245f,_0x3cc263){if(_0x19245f[_0x0adf('0x52')]['id']){delete _0x19245f[_0x0adf('0x52')]['id'];}return db['ZendeskAccount'][_0x0adf('0x50')]({'where':{'id':_0x19245f['params']['id']}})[_0x0adf('0x19')](handleEntityNotFound(_0x3cc263,null))[_0x0adf('0x19')](saveUpdates(_0x19245f['body'],null))[_0x0adf('0x19')](respondWithResult(_0x3cc263,null))['catch'](handleError(_0x3cc263,null));};exports[_0x0adf('0x53')]=function(_0x4a024b,_0x28b9ba){return db[_0x0adf('0x34')][_0x0adf('0x50')]({'where':{'id':_0x4a024b[_0x0adf('0x4b')]['id']}})[_0x0adf('0x19')](handleEntityNotFound(_0x28b9ba,null))[_0x0adf('0x19')](removeEntity(_0x28b9ba,null))[_0x0adf('0x23')](handleError(_0x28b9ba,null));};exports[_0x0adf('0x54')]=function(_0x461586,_0x582351,_0x576c95){var _0x1920ae={};var _0x4fb54b={};var _0x2be6cd;var _0x1597de;return db[_0x0adf('0x34')][_0x0adf('0x55')]({'where':{'id':_0x461586['params']['id']}})[_0x0adf('0x19')](handleEntityNotFound(_0x582351,null))[_0x0adf('0x19')](function(_0x5eb691){if(_0x5eb691){_0x2be6cd=_0x5eb691;_0x4fb54b[_0x0adf('0x3c')]=_[_0x0adf('0x4c')](db[_0x0adf('0x56')][_0x0adf('0x35')]);_0x4fb54b[_0x0adf('0x39')]=_[_0x0adf('0x4c')](_0x461586[_0x0adf('0x39')]);_0x4fb54b['filters']=_[_0x0adf('0x3b')](_0x4fb54b[_0x0adf('0x3c')],_0x4fb54b[_0x0adf('0x39')]);_0x1920ae[_0x0adf('0x3d')]=_['intersection'](_0x4fb54b['model'],qs[_0x0adf('0x4d')](_0x461586[_0x0adf('0x39')]['fields']));_0x1920ae[_0x0adf('0x3d')]=_0x1920ae[_0x0adf('0x3d')][_0x0adf('0x3e')]?_0x1920ae[_0x0adf('0x3d')]:_0x4fb54b[_0x0adf('0x3c')];_0x1920ae[_0x0adf('0x41')]=qs[_0x0adf('0x42')](_0x461586[_0x0adf('0x39')][_0x0adf('0x42')]);_0x1920ae[_0x0adf('0x43')]=qs[_0x0adf('0x3a')](_['pick'](_0x461586[_0x0adf('0x39')],_0x4fb54b['filters']));if(_0x461586[_0x0adf('0x39')][_0x0adf('0x45')]){_0x1920ae[_0x0adf('0x43')]=_[_0x0adf('0x46')](_0x1920ae[_0x0adf('0x43')],{'$or':_[_0x0adf('0x38')](_0x1920ae['attributes'],function(_0x285a06){var _0x4e9efb={};_0x4e9efb[_0x285a06]={'$like':'%'+_0x461586[_0x0adf('0x39')][_0x0adf('0x45')]+'%'};return _0x4e9efb;})});}_0x1920ae=_[_0x0adf('0x46')]({},_0x1920ae,_0x461586['options']);return _0x2be6cd[_0x0adf('0x54')](_0x1920ae);}})[_0x0adf('0x19')](function(_0x457f4a){if(_0x457f4a){_0x1597de=_0x457f4a[_0x0adf('0x3e')];if(!_0x461586[_0x0adf('0x39')][_0x0adf('0x3f')](_0x0adf('0x40'))){_0x1920ae[_0x0adf('0x2a')]=qs[_0x0adf('0x2a')](_0x461586[_0x0adf('0x39')][_0x0adf('0x2a')]);_0x1920ae[_0x0adf('0x29')]=qs[_0x0adf('0x29')](_0x461586['query']['offset']);}return _0x2be6cd['getConfigurations'](_0x1920ae);}})[_0x0adf('0x19')](function(_0x699b7f){if(_0x699b7f){return _0x699b7f?{'count':_0x1597de,'rows':_0x699b7f}:null;}})[_0x0adf('0x19')](respondWithResult(_0x582351,null))[_0x0adf('0x23')](handleError(_0x582351,null));};exports[_0x0adf('0x57')]=function(_0x4c36fc,_0x22d5a6,_0x262e04){if(_0x4c36fc[_0x0adf('0x52')]['id']){delete _0x4c36fc[_0x0adf('0x52')]['id'];}return db[_0x0adf('0x34')][_0x0adf('0x55')]({'where':{'id':_0x4c36fc[_0x0adf('0x4b')]['id']}})['then'](handleEntityNotFound(_0x22d5a6,null))[_0x0adf('0x19')](function(_0x3aa8cd){if(_0x3aa8cd){_0x4c36fc[_0x0adf('0x52')][_0x0adf('0x58')]=_0x3aa8cd['id'];_0x4c36fc['body'][_0x0adf('0x59')]=integrations['getSubjects'](_0x4c36fc[_0x0adf('0x52')]['channel'],_0x4c36fc[_0x0adf('0x52')][_0x0adf('0x37')]);_0x4c36fc[_0x0adf('0x52')][_0x0adf('0x5a')]=integrations[_0x0adf('0x5b')](_0x4c36fc[_0x0adf('0x52')][_0x0adf('0x5c')],_0x4c36fc['body']['type']);return db[_0x0adf('0x56')][_0x0adf('0x51')](_0x4c36fc[_0x0adf('0x52')],{'include':[{'model':db[_0x0adf('0x5d')],'as':_0x0adf('0x59')},{'model':db[_0x0adf('0x5d')],'as':'Descriptions'}]});}return null;})[_0x0adf('0x19')](respondWithResult(_0x22d5a6,null))[_0x0adf('0x23')](handleError(_0x22d5a6,null));};exports[_0x0adf('0x5e')]=function(_0x4c5419,_0x331ead,_0x1e7162){var _0x3df1a7='';return db['ZendeskAccount'][_0x0adf('0x55')]({'where':{'id':_0x4c5419[_0x0adf('0x4b')]['id']},'attributes':['id',_0x0adf('0x5f'),_0x0adf('0x60'),_0x0adf('0x61'),'authType','remoteUri']})['then'](handleEntityNotFound(_0x331ead,null))['then'](function(_0x257fd2){if(_0x257fd2){_0x3df1a7=_0x257fd2[_0x0adf('0x62')];var _0x42d1fd=_0x3df1a7[_0x0adf('0x63')](-0x1);if(_0x42d1fd==='/'){_0x3df1a7=_0x3df1a7[_0x0adf('0x64')](0x0,_0x3df1a7['lastIndexOf'](_0x42d1fd));}var _0x1bffa1={'method':_0x0adf('0x65'),'uri':util['format'](_0x0adf('0x66'),_0x3df1a7,_0x0adf('0x67')),'json':!![]};switch(_0x257fd2['authType']){case _0x0adf('0x60'):_0x1bffa1['headers']={'Authorization':util['format'](_0x0adf('0x68'),new Buffer(util[_0x0adf('0x69')]('%s:%s',_0x257fd2[_0x0adf('0x5f')],_0x257fd2[_0x0adf('0x60')]))[_0x0adf('0x6a')]('base64'))};break;case'token':_0x1bffa1[_0x0adf('0x6b')]={'Authorization':util[_0x0adf('0x69')](_0x0adf('0x68'),new Buffer(util[_0x0adf('0x69')](_0x0adf('0x6c'),_0x257fd2['username'],_0x257fd2[_0x0adf('0x61')]))[_0x0adf('0x6a')](_0x0adf('0x6d')))};break;default:throw new db[(_0x0adf('0x6e'))]['ValidationError'](_0x0adf('0x6f'));}return rp(_0x1bffa1);}})[_0x0adf('0x19')](function(_0x15ad7c){if(_0x15ad7c){var _0x201ac5=[_0x0adf('0x70'),_0x0adf('0x71'),_0x0adf('0x72'),_0x0adf('0x73')];_[_0x0adf('0x74')](_0x15ad7c[_0x0adf('0x67')],function(_0x4c94f0){return _0x201ac5[_0x0adf('0x75')](_0x4c94f0['type']);});return{'count':_0x15ad7c[_0x0adf('0x67')][_0x0adf('0x3e')],'rows':_[_0x0adf('0x38')](_0x15ad7c['ticket_fields'],function(_0x479a34){return{'id':_0x479a34['id'],'name':_0x479a34[_0x0adf('0x76')]>0x7?_0x479a34[_0x0adf('0x77')]:_0x479a34[_0x0adf('0x37')],'custom':_0x479a34[_0x0adf('0x76')]>0x7?!![]:![],'options':_0x479a34['system_field_options']?_0x479a34['system_field_options']:_0x479a34[_0x0adf('0x78')]?_0x479a34['custom_field_options']:[]};})};}})['then'](respondWithResult(_0x331ead,null))[_0x0adf('0x23')](function(_0x6aa492){var _0x5eb3b4=_0x4c5419[_0x0adf('0x39')][_0x0adf('0x79')]?0x1f4:_0x6aa492[_0x0adf('0x7a')]||0x1f4;logger['error'](_0x0adf('0x7b'),_0x0adf('0x5e'),_0x5eb3b4,JSON['stringify'](_0x6aa492));delete _0x6aa492['name'];if(_0x5eb3b4===0x191){_0x5eb3b4=0x190;}_0x331ead[_0x0adf('0x26')](_0x5eb3b4)[_0x0adf('0x32')](_0x4c5419['query'][_0x0adf('0x79')]?{'message':_0x0adf('0x7c'),'statusCode':_0x6aa492['statusCode']}:_0x6aa492);});};
\ No newline at end of file