Built motion from commit 10af8726.|2.6.34
[motion2.git] / server / api / intFreshdeskAccount / intFreshdeskAccount.controller.js
index 5561f62..e10805f 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xfc3b=['reject','save','update','destroy','stack','name','send','index','map','FreshdeskAccount','fieldName','type','key','model','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','limit','order','sort','where','filter','merge','VIRTUAL','options','includeAll','include','findAll','rows','params','keys','rawAttributes','find','create','body','getConfigurations','findOne','FreshdeskConfiguration','pick','Subjects','getSubjects','Descriptions','channel','FreshdeskField','getFields','remoteUri','apiKey','lastIndexOf','format','%s/%s','api/v2/ticket_fields','%s:X','toString','base64','requester','subject','agent','priority','group','source','ticket_type','company','remove','includes','label','choices','capitalize','test','statusCode','getFields,\x20%s,\x20%s,\x20%s','rimraf','zip-dir','fast-json-patch','request-promise','moment','util','path','sox','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../components/integrations/configuration','client','http','request','then','info','FreshdeskAccount,\x20%s,\x20%s','request\x20sent','debug','FreshdeskAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','sendStatus','status','end','json','count','offset','set','Content-Range','apply'];(function(_0x4719f,_0x361cae){var _0x4ce942=function(_0x768a6b){while(--_0x768a6b){_0x4719f['push'](_0x4719f['shift']());}};_0x4ce942(++_0x361cae);}(_0xfc3b,0xc5));var _0xbfc3=function(_0x38e804,_0x55745b){_0x38e804=_0x38e804-0x0;var _0x4999af=_0xfc3b[_0x38e804];return _0x4999af;};'use strict';var pdf=require('html-pdf');var emlformat=require('eml-format');var rimraf=require(_0xbfc3('0x0'));var zipdir=require(_0xbfc3('0x1'));var jsonpatch=require(_0xbfc3('0x2'));var rp=require(_0xbfc3('0x3'));var moment=require(_0xbfc3('0x4'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0xbfc3('0x5'));var path=require(_0xbfc3('0x6'));var sox=require(_0xbfc3('0x7'));var csv=require('to-csv');var ejs=require(_0xbfc3('0x8'));var fs=require('fs');var _=require(_0xbfc3('0x9'));var squel=require(_0xbfc3('0xa'));var crypto=require(_0xbfc3('0xb'));var jsforce=require(_0xbfc3('0xc'));var deskjs=require(_0xbfc3('0xd'));var toCsv=require('to-csv');var querystring=require(_0xbfc3('0xe'));var Papa=require(_0xbfc3('0xf'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0xbfc3('0x10'));var as=require(_0xbfc3('0x11'));var hardwareService=require(_0xbfc3('0x12'));var logger=require('../../config/logger')(_0xbfc3('0x13'));var utils=require(_0xbfc3('0x14'));var config=require(_0xbfc3('0x15'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];var integrations=require(_0xbfc3('0x16'));var jayson=require('jayson/promise');var client=jayson[_0xbfc3('0x17')][_0xbfc3('0x18')]({'port':0x232a});function respondWithRpcPromise(_0xa9281e,_0x168c95,_0x314a2a,_0x132700){return new BPromise(function(_0x45928a,_0x559571){var _0x5c0692=_0x132700||client;return _0x5c0692[_0xbfc3('0x19')](_0xa9281e,_0x314a2a)[_0xbfc3('0x1a')](function(_0x1543f6){logger[_0xbfc3('0x1b')](_0xbfc3('0x1c'),_0x168c95,_0xbfc3('0x1d'));logger[_0xbfc3('0x1e')](_0xbfc3('0x1f'),_0x168c95,'request\x20sent',JSON[_0xbfc3('0x20')](_0x1543f6));if(_0x1543f6['error']){if(_0x1543f6[_0xbfc3('0x21')][_0xbfc3('0x22')]===0x1f4){logger[_0xbfc3('0x21')](_0xbfc3('0x1c'),_0x168c95,_0x1543f6['error'][_0xbfc3('0x23')]);return _0x559571(_0x1543f6[_0xbfc3('0x21')][_0xbfc3('0x23')]);}logger[_0xbfc3('0x21')]('FreshdeskAccount,\x20%s,\x20%s',_0x168c95,_0x1543f6[_0xbfc3('0x21')][_0xbfc3('0x23')]);return _0x45928a(_0x1543f6[_0xbfc3('0x21')][_0xbfc3('0x23')]);}else{logger[_0xbfc3('0x1b')](_0xbfc3('0x1c'),_0x168c95,_0xbfc3('0x1d'));_0x45928a(_0x1543f6[_0xbfc3('0x24')][_0xbfc3('0x23')]);}})[_0xbfc3('0x25')](function(_0x3e5c78){logger[_0xbfc3('0x21')](_0xbfc3('0x1c'),_0x168c95,_0x3e5c78);_0x559571(_0x3e5c78);});});}function respondWithStatusCode(_0x440842,_0x3691df){_0x3691df=_0x3691df||0xcc;return function(_0x429c01){if(_0x429c01){return _0x440842[_0xbfc3('0x26')](_0x3691df);}return _0x440842[_0xbfc3('0x27')](_0x3691df)[_0xbfc3('0x28')]();};}function respondWithResult(_0x4e5121,_0x46a0d5){_0x46a0d5=_0x46a0d5||0xc8;return function(_0x2c8be6){if(_0x2c8be6){return _0x4e5121[_0xbfc3('0x27')](_0x46a0d5)[_0xbfc3('0x29')](_0x2c8be6);}};}function respondWithFilteredResult(_0x32262f,_0x2171dd){return function(_0xecaf6f){if(_0xecaf6f){var _0x3abd98=_0xecaf6f[_0xbfc3('0x2a')],_0x55c8e0=_0x2171dd['offset'],_0x428201=_0x2171dd[_0xbfc3('0x2b')]+_0x2171dd['limit'],_0x3cc412;if(_0x428201>=_0x3abd98){_0x428201=_0x3abd98;_0x3cc412=0xc8;}else{_0x3cc412=0xce;}_0x32262f[_0xbfc3('0x27')](_0x3cc412);return _0x32262f[_0xbfc3('0x2c')](_0xbfc3('0x2d'),_0x55c8e0+'-'+_0x428201+'/'+_0x3abd98)[_0xbfc3('0x29')](_0xecaf6f);}return null;};}function patchUpdates(_0xbff23b){return function(_0x15d012){try{jsonpatch[_0xbfc3('0x2e')](_0x15d012,_0xbff23b,!![]);}catch(_0xe564db){return BPromise[_0xbfc3('0x2f')](_0xe564db);}return _0x15d012[_0xbfc3('0x30')]();};}function saveUpdates(_0x1be09e,_0x2dea45){return function(_0x13547c){if(_0x13547c){return _0x13547c[_0xbfc3('0x31')](_0x1be09e)[_0xbfc3('0x1a')](function(_0x426d8b){return _0x426d8b;});}return null;};}function removeEntity(_0x2b74cd,_0x20e2ec){return function(_0x3cdf64){if(_0x3cdf64){return _0x3cdf64[_0xbfc3('0x32')]()[_0xbfc3('0x1a')](function(){_0x2b74cd[_0xbfc3('0x27')](0xcc)[_0xbfc3('0x28')]();});}};}function handleEntityNotFound(_0xe5007,_0x21db2d){return function(_0xc2665c){if(!_0xc2665c){_0xe5007[_0xbfc3('0x26')](0x194);}return _0xc2665c;};}function handleError(_0x5bd293,_0x422331){_0x422331=_0x422331||0x1f4;return function(_0x1760a3){logger[_0xbfc3('0x21')](_0x1760a3[_0xbfc3('0x33')]);if(_0x1760a3[_0xbfc3('0x34')]){delete _0x1760a3[_0xbfc3('0x34')];}_0x5bd293['status'](_0x422331)[_0xbfc3('0x35')](_0x1760a3);};}exports[_0xbfc3('0x36')]=function(_0x38dd1b,_0x1b5b88){var _0x58ec39={},_0x260bba={},_0x3380a1={'count':0x0,'rows':[]};var _0x5250ed=_[_0xbfc3('0x37')](db[_0xbfc3('0x38')]['rawAttributes'],function(_0x285ef9){return{'name':_0x285ef9[_0xbfc3('0x39')],'type':_0x285ef9[_0xbfc3('0x3a')][_0xbfc3('0x3b')]};});_0x260bba[_0xbfc3('0x3c')]=_['map'](_0x5250ed,'name');_0x260bba[_0xbfc3('0x3d')]=_['keys'](_0x38dd1b[_0xbfc3('0x3d')]);_0x260bba[_0xbfc3('0x3e')]=_[_0xbfc3('0x3f')](_0x260bba[_0xbfc3('0x3c')],_0x260bba['query']);_0x58ec39[_0xbfc3('0x40')]=_['intersection'](_0x260bba['model'],qs['fields'](_0x38dd1b[_0xbfc3('0x3d')][_0xbfc3('0x41')]));_0x58ec39[_0xbfc3('0x40')]=_0x58ec39['attributes'][_0xbfc3('0x42')]?_0x58ec39[_0xbfc3('0x40')]:_0x260bba[_0xbfc3('0x3c')];if(!_0x38dd1b[_0xbfc3('0x3d')][_0xbfc3('0x43')](_0xbfc3('0x44'))){_0x58ec39[_0xbfc3('0x45')]=qs['limit'](_0x38dd1b[_0xbfc3('0x3d')][_0xbfc3('0x45')]);_0x58ec39[_0xbfc3('0x2b')]=qs[_0xbfc3('0x2b')](_0x38dd1b[_0xbfc3('0x3d')]['offset']);}_0x58ec39[_0xbfc3('0x46')]=qs[_0xbfc3('0x47')](_0x38dd1b[_0xbfc3('0x3d')][_0xbfc3('0x47')]);_0x58ec39[_0xbfc3('0x48')]=qs['filters'](_['pick'](_0x38dd1b[_0xbfc3('0x3d')],_0x260bba[_0xbfc3('0x3e')]),_0x5250ed);if(_0x38dd1b[_0xbfc3('0x3d')][_0xbfc3('0x49')]){_0x58ec39[_0xbfc3('0x48')]=_[_0xbfc3('0x4a')](_0x58ec39['where'],{'$or':_[_0xbfc3('0x37')](_0x5250ed,function(_0x45db04){if(_0x45db04[_0xbfc3('0x3a')]!==_0xbfc3('0x4b')){var _0x214015={};_0x214015[_0x45db04[_0xbfc3('0x34')]]={'$like':'%'+_0x38dd1b[_0xbfc3('0x3d')]['filter']+'%'};return _0x214015;}})});}_0x58ec39=_['merge']({},_0x58ec39,_0x38dd1b[_0xbfc3('0x4c')]);var _0x3c0485={'where':_0x58ec39[_0xbfc3('0x48')]};return db['FreshdeskAccount']['count'](_0x3c0485)[_0xbfc3('0x1a')](function(_0x2386fb){_0x3380a1[_0xbfc3('0x2a')]=_0x2386fb;if(_0x38dd1b[_0xbfc3('0x3d')][_0xbfc3('0x4d')]){_0x58ec39[_0xbfc3('0x4e')]=[{'all':!![]}];}return db[_0xbfc3('0x38')][_0xbfc3('0x4f')](_0x58ec39);})[_0xbfc3('0x1a')](function(_0x13c5d6){_0x3380a1[_0xbfc3('0x50')]=_0x13c5d6;return _0x3380a1;})[_0xbfc3('0x1a')](respondWithFilteredResult(_0x1b5b88,_0x58ec39))['catch'](handleError(_0x1b5b88,null));};exports['show']=function(_0xc2cb86,_0xcfb294){var _0x2807f9={'raw':![],'where':{'id':_0xc2cb86[_0xbfc3('0x51')]['id']}},_0x4d2002={};_0x4d2002[_0xbfc3('0x3c')]=_[_0xbfc3('0x52')](db[_0xbfc3('0x38')][_0xbfc3('0x53')]);_0x4d2002[_0xbfc3('0x3d')]=_[_0xbfc3('0x52')](_0xc2cb86['query']);_0x4d2002[_0xbfc3('0x3e')]=_[_0xbfc3('0x3f')](_0x4d2002[_0xbfc3('0x3c')],_0x4d2002[_0xbfc3('0x3d')]);_0x2807f9[_0xbfc3('0x40')]=_['intersection'](_0x4d2002[_0xbfc3('0x3c')],qs['fields'](_0xc2cb86[_0xbfc3('0x3d')][_0xbfc3('0x41')]));_0x2807f9[_0xbfc3('0x40')]=_0x2807f9[_0xbfc3('0x40')][_0xbfc3('0x42')]?_0x2807f9[_0xbfc3('0x40')]:_0x4d2002[_0xbfc3('0x3c')];if(_0xc2cb86[_0xbfc3('0x3d')][_0xbfc3('0x4d')]){_0x2807f9['include']=[{'all':!![]}];}_0x2807f9=_[_0xbfc3('0x4a')]({},_0x2807f9,_0xc2cb86[_0xbfc3('0x4c')]);return db[_0xbfc3('0x38')][_0xbfc3('0x54')](_0x2807f9)[_0xbfc3('0x1a')](handleEntityNotFound(_0xcfb294,null))[_0xbfc3('0x1a')](respondWithResult(_0xcfb294,null))[_0xbfc3('0x25')](handleError(_0xcfb294,null));};exports[_0xbfc3('0x55')]=function(_0x4360f7,_0x1d5edf){return db[_0xbfc3('0x38')][_0xbfc3('0x55')](_0x4360f7[_0xbfc3('0x56')],{})['then'](respondWithResult(_0x1d5edf,0xc9))[_0xbfc3('0x25')](handleError(_0x1d5edf,null));};exports[_0xbfc3('0x31')]=function(_0x5f1e44,_0x487611){if(_0x5f1e44[_0xbfc3('0x56')]['id']){delete _0x5f1e44['body']['id'];}return db['FreshdeskAccount'][_0xbfc3('0x54')]({'where':{'id':_0x5f1e44[_0xbfc3('0x51')]['id']}})[_0xbfc3('0x1a')](handleEntityNotFound(_0x487611,null))[_0xbfc3('0x1a')](saveUpdates(_0x5f1e44[_0xbfc3('0x56')],null))['then'](respondWithResult(_0x487611,null))['catch'](handleError(_0x487611,null));};exports[_0xbfc3('0x32')]=function(_0x5ee9aa,_0x13d05e){return db[_0xbfc3('0x38')][_0xbfc3('0x54')]({'where':{'id':_0x5ee9aa['params']['id']}})[_0xbfc3('0x1a')](handleEntityNotFound(_0x13d05e,null))['then'](removeEntity(_0x13d05e,null))[_0xbfc3('0x25')](handleError(_0x13d05e,null));};exports[_0xbfc3('0x57')]=function(_0x166f0f,_0x2f2e89,_0x2e17d7){var _0x4f17e8={};var _0x230f97={};var _0x2d05b4;var _0x2d8683;return db['FreshdeskAccount'][_0xbfc3('0x58')]({'where':{'id':_0x166f0f[_0xbfc3('0x51')]['id']}})['then'](handleEntityNotFound(_0x2f2e89,null))[_0xbfc3('0x1a')](function(_0x59ecbe){if(_0x59ecbe){_0x2d05b4=_0x59ecbe;_0x230f97[_0xbfc3('0x3c')]=_[_0xbfc3('0x52')](db[_0xbfc3('0x59')][_0xbfc3('0x53')]);_0x230f97[_0xbfc3('0x3d')]=_[_0xbfc3('0x52')](_0x166f0f[_0xbfc3('0x3d')]);_0x230f97[_0xbfc3('0x3e')]=_['intersection'](_0x230f97[_0xbfc3('0x3c')],_0x230f97[_0xbfc3('0x3d')]);_0x4f17e8['attributes']=_[_0xbfc3('0x3f')](_0x230f97[_0xbfc3('0x3c')],qs[_0xbfc3('0x41')](_0x166f0f[_0xbfc3('0x3d')]['fields']));_0x4f17e8[_0xbfc3('0x40')]=_0x4f17e8[_0xbfc3('0x40')][_0xbfc3('0x42')]?_0x4f17e8['attributes']:_0x230f97[_0xbfc3('0x3c')];_0x4f17e8[_0xbfc3('0x46')]=qs[_0xbfc3('0x47')](_0x166f0f['query'][_0xbfc3('0x47')]);_0x4f17e8[_0xbfc3('0x48')]=qs[_0xbfc3('0x3e')](_[_0xbfc3('0x5a')](_0x166f0f['query'],_0x230f97[_0xbfc3('0x3e')]));if(_0x166f0f['query'][_0xbfc3('0x49')]){_0x4f17e8['where']=_['merge'](_0x4f17e8['where'],{'$or':_['map'](_0x4f17e8[_0xbfc3('0x40')],function(_0xbd5128){var _0x58917f={};_0x58917f[_0xbd5128]={'$like':'%'+_0x166f0f[_0xbfc3('0x3d')]['filter']+'%'};return _0x58917f;})});}_0x4f17e8=_[_0xbfc3('0x4a')]({},_0x4f17e8,_0x166f0f[_0xbfc3('0x4c')]);return _0x2d05b4['getConfigurations'](_0x4f17e8);}})['then'](function(_0x3e7d57){if(_0x3e7d57){_0x2d8683=_0x3e7d57['length'];if(!_0x166f0f[_0xbfc3('0x3d')][_0xbfc3('0x43')]('nolimit')){_0x4f17e8[_0xbfc3('0x45')]=qs[_0xbfc3('0x45')](_0x166f0f['query'][_0xbfc3('0x45')]);_0x4f17e8['offset']=qs['offset'](_0x166f0f[_0xbfc3('0x3d')][_0xbfc3('0x2b')]);}return _0x2d05b4['getConfigurations'](_0x4f17e8);}})['then'](function(_0xfb057f){if(_0xfb057f){return _0xfb057f?{'count':_0x2d8683,'rows':_0xfb057f}:null;}})[_0xbfc3('0x1a')](respondWithResult(_0x2f2e89,null))[_0xbfc3('0x25')](handleError(_0x2f2e89,null));};exports['addConfiguration']=function(_0x374c9b,_0x286054,_0x426ec5){if(_0x374c9b['body']['id']){delete _0x374c9b['body']['id'];}return db[_0xbfc3('0x38')][_0xbfc3('0x58')]({'where':{'id':_0x374c9b[_0xbfc3('0x51')]['id']}})[_0xbfc3('0x1a')](handleEntityNotFound(_0x286054,null))[_0xbfc3('0x1a')](function(_0x4dbe98){if(_0x4dbe98){_0x374c9b[_0xbfc3('0x56')]['AccountId']=_0x4dbe98['id'];_0x374c9b[_0xbfc3('0x56')][_0xbfc3('0x5b')]=integrations[_0xbfc3('0x5c')](_0x374c9b[_0xbfc3('0x56')]['channel'],_0x374c9b[_0xbfc3('0x56')][_0xbfc3('0x3a')]);_0x374c9b[_0xbfc3('0x56')][_0xbfc3('0x5d')]=integrations['getDescriptions'](_0x374c9b[_0xbfc3('0x56')][_0xbfc3('0x5e')],_0x374c9b[_0xbfc3('0x56')]['type']);return db[_0xbfc3('0x59')][_0xbfc3('0x55')](_0x374c9b[_0xbfc3('0x56')],{'include':[{'model':db[_0xbfc3('0x5f')],'as':'Subjects'},{'model':db[_0xbfc3('0x5f')],'as':'Descriptions'}]});}return null;})[_0xbfc3('0x1a')](respondWithResult(_0x286054,null))[_0xbfc3('0x25')](handleError(_0x286054,null));};exports[_0xbfc3('0x60')]=function(_0x132f12,_0x33cb9f,_0x4445f6){var _0xcc8e61='';return db[_0xbfc3('0x38')][_0xbfc3('0x58')]({'where':{'id':_0x132f12[_0xbfc3('0x51')]['id']},'attributes':['id',_0xbfc3('0x61'),_0xbfc3('0x62')]})[_0xbfc3('0x1a')](handleEntityNotFound(_0x33cb9f,null))[_0xbfc3('0x1a')](function(_0x5371aa){if(_0x5371aa){_0xcc8e61=_0x5371aa[_0xbfc3('0x61')];var _0x56582e=_0xcc8e61['slice'](-0x1);if(_0x56582e==='/'){_0xcc8e61=_0xcc8e61['substring'](0x0,_0xcc8e61[_0xbfc3('0x63')](_0x56582e));}return rp({'method':'GET','uri':util[_0xbfc3('0x64')](_0xbfc3('0x65'),_0xcc8e61,_0xbfc3('0x66')),'headers':{'Authorization':util['format']('Basic\x20%s',new Buffer(util[_0xbfc3('0x64')](_0xbfc3('0x67'),_0x5371aa['apiKey']))[_0xbfc3('0x68')](_0xbfc3('0x69')))},'json':!![]});}})[_0xbfc3('0x1a')](function(_0x4214db){if(_0x4214db){var _0x2061d8=[_0xbfc3('0x6a'),_0xbfc3('0x6b'),_0xbfc3('0x6c'),'description','status',_0xbfc3('0x6d'),_0xbfc3('0x6e'),_0xbfc3('0x6f'),_0xbfc3('0x70'),_0xbfc3('0x6e'),_0xbfc3('0x71')];_[_0xbfc3('0x72')](_0x4214db,function(_0x6c5415){return _0x2061d8[_0xbfc3('0x73')](_0x6c5415[_0xbfc3('0x34')])||!_0x6c5415['default']&&_0x6c5415[_0xbfc3('0x3a')]!=='custom_text'&&_0x6c5415[_0xbfc3('0x3a')]!=='custom_dropdown';});return{'count':_0x4214db[_0xbfc3('0x42')],'rows':_[_0xbfc3('0x37')](_0x4214db,function(_0x475836){return{'id':_0x475836['name'],'name':_0x475836[_0xbfc3('0x74')],'custom':!_0x475836['default'],'options':_0x475836['choices']?_[_0xbfc3('0x37')](_0x475836[_0xbfc3('0x75')],function(_0x5d4d32){return{'name':_[_0xbfc3('0x76')](_0x5d4d32),'value':_0x5d4d32};}):[]};})};}})[_0xbfc3('0x1a')](respondWithResult(_0x33cb9f,null))[_0xbfc3('0x25')](function(_0x20632b){var _0x12ab8e=_0x132f12[_0xbfc3('0x3d')][_0xbfc3('0x77')]?0x1f4:_0x20632b[_0xbfc3('0x78')]||0x1f4;logger[_0xbfc3('0x21')](_0xbfc3('0x79'),_0xbfc3('0x60'),_0x12ab8e,JSON[_0xbfc3('0x20')](_0x20632b));delete _0x20632b[_0xbfc3('0x34')];if(_0x12ab8e===0x191){_0x12ab8e=0x190;}_0x33cb9f['status'](_0x12ab8e)[_0xbfc3('0x35')](_0x132f12[_0xbfc3('0x3d')][_0xbfc3('0x77')]?{'message':'Wrong\x20credentials','statusCode':_0x20632b[_0xbfc3('0x78')]}:_0x20632b);});};
\ No newline at end of file
+var _0xb299=['attributes','model','fields','length','hasOwnProperty','order','sort','where','filters','pick','filter','merge','options','includeAll','include','catch','show','params','keys','create','find','getConfigurations','findOne','FreshdeskConfiguration','nolimit','addConfiguration','body','Subjects','getSubjects','channel','getDescriptions','FreshdeskField','Descriptions','remoteUri','apiKey','slice','substring','GET','format','%s/%s','api/v2/ticket_fields','Basic\x20%s','%s:X','toString','base64','requester','agent','group','source','ticket_type','remove','includes','default','custom_text','custom_dropdown','label','choices','capitalize','test','statusCode','getFields,\x20%s,\x20%s,\x20%s','getFields','stringify','eml-format','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','desk.js','papaparse','ioredis','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','../../components/integrations/configuration','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','apply','reject','save','update','then','error','name','send','index','map','FreshdeskAccount','rawAttributes','fieldName','type','key','intersection','query'];(function(_0x5dff07,_0x2a827b){var _0x56151f=function(_0xe4ed17){while(--_0xe4ed17){_0x5dff07['push'](_0x5dff07['shift']());}};_0x56151f(++_0x2a827b);}(_0xb299,0x19b));var _0x9b29=function(_0x5e105c,_0x3846a4){_0x5e105c=_0x5e105c-0x0;var _0x5cc674=_0xb299[_0x5e105c];return _0x5cc674;};'use strict';var emlformat=require(_0x9b29('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x9b29('0x1'));var jsonpatch=require(_0x9b29('0x2'));var rp=require(_0x9b29('0x3'));var moment=require(_0x9b29('0x4'));var BPromise=require(_0x9b29('0x5'));var Mustache=require(_0x9b29('0x6'));var util=require(_0x9b29('0x7'));var path=require('path');var sox=require(_0x9b29('0x8'));var csv=require(_0x9b29('0x9'));var ejs=require(_0x9b29('0xa'));var fs=require('fs');var fs_extra=require(_0x9b29('0xb'));var _=require(_0x9b29('0xc'));var squel=require(_0x9b29('0xd'));var crypto=require(_0x9b29('0xe'));var jsforce=require('jsforce');var deskjs=require(_0x9b29('0xf'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0x9b29('0x10'));var Redis=require(_0x9b29('0x11'));var authService=require('../../components/auth/service');var qs=require(_0x9b29('0x12'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x9b29('0x13'));var logger=require(_0x9b29('0x14'))(_0x9b29('0x15'));var utils=require('../../config/utils');var config=require(_0x9b29('0x16'));var licenseUtil=require(_0x9b29('0x17'));var db=require(_0x9b29('0x18'))['db'];var integrations=require(_0x9b29('0x19'));function respondWithStatusCode(_0x35da05,_0x353308){_0x353308=_0x353308||0xcc;return function(_0x2479a2){if(_0x2479a2){return _0x35da05[_0x9b29('0x1a')](_0x353308);}return _0x35da05[_0x9b29('0x1b')](_0x353308)[_0x9b29('0x1c')]();};}function respondWithResult(_0x370f86,_0x292a5f){_0x292a5f=_0x292a5f||0xc8;return function(_0x355806){if(_0x355806){return _0x370f86[_0x9b29('0x1b')](_0x292a5f)[_0x9b29('0x1d')](_0x355806);}};}function respondWithFilteredResult(_0x2e5976,_0x4773c3){return function(_0x45b857){if(_0x45b857){var _0x31d9a1=typeof _0x4773c3[_0x9b29('0x1e')]===_0x9b29('0x1f')&&typeof _0x4773c3[_0x9b29('0x20')]==='undefined';var _0x48d3b4=_0x45b857['count'];var _0xf8967d=_0x31d9a1?0x0:_0x4773c3[_0x9b29('0x1e')];var _0x24d45d=_0x31d9a1?_0x45b857[_0x9b29('0x21')]:_0x4773c3[_0x9b29('0x1e')]+_0x4773c3[_0x9b29('0x20')];var _0x12c2e4;if(_0x24d45d>=_0x48d3b4){_0x24d45d=_0x48d3b4;_0x12c2e4=0xc8;}else{_0x12c2e4=0xce;}_0x2e5976[_0x9b29('0x1b')](_0x12c2e4);return _0x2e5976[_0x9b29('0x22')](_0x9b29('0x23'),_0xf8967d+'-'+_0x24d45d+'/'+_0x48d3b4)['json'](_0x45b857);}return null;};}function patchUpdates(_0x598d3f){return function(_0xdebf3e){try{jsonpatch[_0x9b29('0x24')](_0xdebf3e,_0x598d3f,!![]);}catch(_0x7b8615){return BPromise[_0x9b29('0x25')](_0x7b8615);}return _0xdebf3e[_0x9b29('0x26')]();};}function saveUpdates(_0x389f27,_0x90a182){return function(_0x3ab389){if(_0x3ab389){return _0x3ab389[_0x9b29('0x27')](_0x389f27)[_0x9b29('0x28')](function(_0x4802f7){return _0x4802f7;});}return null;};}function removeEntity(_0x1d6743,_0x1861a4){return function(_0xeebf6c){if(_0xeebf6c){return _0xeebf6c['destroy']()[_0x9b29('0x28')](function(){_0x1d6743['status'](0xcc)[_0x9b29('0x1c')]();});}};}function handleEntityNotFound(_0x3d05fc,_0x48b85d){return function(_0x4ef61f){if(!_0x4ef61f){_0x3d05fc[_0x9b29('0x1a')](0x194);}return _0x4ef61f;};}function handleError(_0x405f2d,_0x50ea3d){_0x50ea3d=_0x50ea3d||0x1f4;return function(_0x3fa7b6){logger[_0x9b29('0x29')](_0x3fa7b6['stack']);if(_0x3fa7b6[_0x9b29('0x2a')]){delete _0x3fa7b6[_0x9b29('0x2a')];}_0x405f2d[_0x9b29('0x1b')](_0x50ea3d)[_0x9b29('0x2b')](_0x3fa7b6);};}exports[_0x9b29('0x2c')]=function(_0x49025f,_0x25a000){var _0x3cee24={},_0x36fb08={},_0x386c65={'count':0x0,'rows':[]};var _0x512e71=_[_0x9b29('0x2d')](db[_0x9b29('0x2e')][_0x9b29('0x2f')],function(_0x2fe6a5){return{'name':_0x2fe6a5[_0x9b29('0x30')],'type':_0x2fe6a5[_0x9b29('0x31')][_0x9b29('0x32')]};});_0x36fb08['model']=_[_0x9b29('0x2d')](_0x512e71,_0x9b29('0x2a'));_0x36fb08['query']=_['keys'](_0x49025f['query']);_0x36fb08['filters']=_[_0x9b29('0x33')](_0x36fb08['model'],_0x36fb08[_0x9b29('0x34')]);_0x3cee24[_0x9b29('0x35')]=_[_0x9b29('0x33')](_0x36fb08[_0x9b29('0x36')],qs[_0x9b29('0x37')](_0x49025f[_0x9b29('0x34')][_0x9b29('0x37')]));_0x3cee24['attributes']=_0x3cee24['attributes'][_0x9b29('0x38')]?_0x3cee24[_0x9b29('0x35')]:_0x36fb08[_0x9b29('0x36')];if(!_0x49025f[_0x9b29('0x34')][_0x9b29('0x39')]('nolimit')){_0x3cee24[_0x9b29('0x20')]=qs['limit'](_0x49025f['query'][_0x9b29('0x20')]);_0x3cee24[_0x9b29('0x1e')]=qs[_0x9b29('0x1e')](_0x49025f[_0x9b29('0x34')][_0x9b29('0x1e')]);}_0x3cee24[_0x9b29('0x3a')]=qs[_0x9b29('0x3b')](_0x49025f[_0x9b29('0x34')]['sort']);_0x3cee24[_0x9b29('0x3c')]=qs[_0x9b29('0x3d')](_[_0x9b29('0x3e')](_0x49025f[_0x9b29('0x34')],_0x36fb08[_0x9b29('0x3d')]),_0x512e71);if(_0x49025f[_0x9b29('0x34')][_0x9b29('0x3f')]){_0x3cee24[_0x9b29('0x3c')]=_[_0x9b29('0x40')](_0x3cee24[_0x9b29('0x3c')],{'$or':_[_0x9b29('0x2d')](_0x512e71,function(_0x1b7250){if(_0x1b7250[_0x9b29('0x31')]!=='VIRTUAL'){var _0x3a4699={};_0x3a4699[_0x1b7250[_0x9b29('0x2a')]]={'$like':'%'+_0x49025f[_0x9b29('0x34')]['filter']+'%'};return _0x3a4699;}})});}_0x3cee24=_[_0x9b29('0x40')]({},_0x3cee24,_0x49025f[_0x9b29('0x41')]);var _0x3620d9={'where':_0x3cee24['where']};return db[_0x9b29('0x2e')]['count'](_0x3620d9)[_0x9b29('0x28')](function(_0x8e91ed){_0x386c65['count']=_0x8e91ed;if(_0x49025f['query'][_0x9b29('0x42')]){_0x3cee24[_0x9b29('0x43')]=[{'all':!![]}];}return db[_0x9b29('0x2e')]['findAll'](_0x3cee24);})[_0x9b29('0x28')](function(_0x5a79fa){_0x386c65['rows']=_0x5a79fa;return _0x386c65;})[_0x9b29('0x28')](respondWithFilteredResult(_0x25a000,_0x3cee24))[_0x9b29('0x44')](handleError(_0x25a000,null));};exports[_0x9b29('0x45')]=function(_0x2d6be6,_0x59c3b0){var _0x6e0a00={'raw':![],'where':{'id':_0x2d6be6[_0x9b29('0x46')]['id']}},_0x116cb0={};_0x116cb0[_0x9b29('0x36')]=_['keys'](db['FreshdeskAccount'][_0x9b29('0x2f')]);_0x116cb0[_0x9b29('0x34')]=_[_0x9b29('0x47')](_0x2d6be6['query']);_0x116cb0[_0x9b29('0x3d')]=_[_0x9b29('0x33')](_0x116cb0[_0x9b29('0x36')],_0x116cb0['query']);_0x6e0a00[_0x9b29('0x35')]=_[_0x9b29('0x33')](_0x116cb0[_0x9b29('0x36')],qs[_0x9b29('0x37')](_0x2d6be6[_0x9b29('0x34')]['fields']));_0x6e0a00[_0x9b29('0x35')]=_0x6e0a00[_0x9b29('0x35')][_0x9b29('0x38')]?_0x6e0a00['attributes']:_0x116cb0[_0x9b29('0x36')];if(_0x2d6be6[_0x9b29('0x34')][_0x9b29('0x42')]){_0x6e0a00['include']=[{'all':!![]}];}_0x6e0a00=_[_0x9b29('0x40')]({},_0x6e0a00,_0x2d6be6[_0x9b29('0x41')]);return db[_0x9b29('0x2e')]['find'](_0x6e0a00)['then'](handleEntityNotFound(_0x59c3b0,null))['then'](respondWithResult(_0x59c3b0,null))[_0x9b29('0x44')](handleError(_0x59c3b0,null));};exports[_0x9b29('0x48')]=function(_0x31fcf9,_0x13d87d){return db[_0x9b29('0x2e')]['create'](_0x31fcf9['body'],{})[_0x9b29('0x28')](respondWithResult(_0x13d87d,0xc9))[_0x9b29('0x44')](handleError(_0x13d87d,null));};exports[_0x9b29('0x27')]=function(_0x50500e,_0x43508a){if(_0x50500e['body']['id']){delete _0x50500e['body']['id'];}return db[_0x9b29('0x2e')][_0x9b29('0x49')]({'where':{'id':_0x50500e[_0x9b29('0x46')]['id']}})[_0x9b29('0x28')](handleEntityNotFound(_0x43508a,null))[_0x9b29('0x28')](saveUpdates(_0x50500e['body'],null))['then'](respondWithResult(_0x43508a,null))['catch'](handleError(_0x43508a,null));};exports['destroy']=function(_0x2eb99c,_0x225c55){return db[_0x9b29('0x2e')][_0x9b29('0x49')]({'where':{'id':_0x2eb99c[_0x9b29('0x46')]['id']}})[_0x9b29('0x28')](handleEntityNotFound(_0x225c55,null))['then'](removeEntity(_0x225c55,null))[_0x9b29('0x44')](handleError(_0x225c55,null));};exports[_0x9b29('0x4a')]=function(_0x1fd72a,_0x4b53b2,_0x2088b9){var _0x193287={};var _0xab0b76={};var _0x16206c;var _0x3ac328;return db[_0x9b29('0x2e')][_0x9b29('0x4b')]({'where':{'id':_0x1fd72a[_0x9b29('0x46')]['id']}})[_0x9b29('0x28')](handleEntityNotFound(_0x4b53b2,null))['then'](function(_0x46484c){if(_0x46484c){_0x16206c=_0x46484c;_0xab0b76[_0x9b29('0x36')]=_[_0x9b29('0x47')](db[_0x9b29('0x4c')][_0x9b29('0x2f')]);_0xab0b76[_0x9b29('0x34')]=_[_0x9b29('0x47')](_0x1fd72a[_0x9b29('0x34')]);_0xab0b76[_0x9b29('0x3d')]=_[_0x9b29('0x33')](_0xab0b76[_0x9b29('0x36')],_0xab0b76[_0x9b29('0x34')]);_0x193287[_0x9b29('0x35')]=_['intersection'](_0xab0b76['model'],qs[_0x9b29('0x37')](_0x1fd72a[_0x9b29('0x34')]['fields']));_0x193287[_0x9b29('0x35')]=_0x193287[_0x9b29('0x35')][_0x9b29('0x38')]?_0x193287[_0x9b29('0x35')]:_0xab0b76[_0x9b29('0x36')];_0x193287[_0x9b29('0x3a')]=qs[_0x9b29('0x3b')](_0x1fd72a[_0x9b29('0x34')]['sort']);_0x193287['where']=qs[_0x9b29('0x3d')](_[_0x9b29('0x3e')](_0x1fd72a[_0x9b29('0x34')],_0xab0b76[_0x9b29('0x3d')]));if(_0x1fd72a['query'][_0x9b29('0x3f')]){_0x193287[_0x9b29('0x3c')]=_[_0x9b29('0x40')](_0x193287[_0x9b29('0x3c')],{'$or':_[_0x9b29('0x2d')](_0x193287[_0x9b29('0x35')],function(_0x82e152){var _0x297b75={};_0x297b75[_0x82e152]={'$like':'%'+_0x1fd72a[_0x9b29('0x34')][_0x9b29('0x3f')]+'%'};return _0x297b75;})});}_0x193287=_[_0x9b29('0x40')]({},_0x193287,_0x1fd72a['options']);return _0x16206c[_0x9b29('0x4a')](_0x193287);}})['then'](function(_0x28c5e9){if(_0x28c5e9){_0x3ac328=_0x28c5e9['length'];if(!_0x1fd72a[_0x9b29('0x34')][_0x9b29('0x39')](_0x9b29('0x4d'))){_0x193287[_0x9b29('0x20')]=qs[_0x9b29('0x20')](_0x1fd72a[_0x9b29('0x34')][_0x9b29('0x20')]);_0x193287[_0x9b29('0x1e')]=qs['offset'](_0x1fd72a[_0x9b29('0x34')][_0x9b29('0x1e')]);}return _0x16206c[_0x9b29('0x4a')](_0x193287);}})[_0x9b29('0x28')](function(_0x5a68b5){if(_0x5a68b5){return _0x5a68b5?{'count':_0x3ac328,'rows':_0x5a68b5}:null;}})[_0x9b29('0x28')](respondWithResult(_0x4b53b2,null))[_0x9b29('0x44')](handleError(_0x4b53b2,null));};exports[_0x9b29('0x4e')]=function(_0x3e9ff8,_0x1c37ad,_0x11036f){if(_0x3e9ff8[_0x9b29('0x4f')]['id']){delete _0x3e9ff8[_0x9b29('0x4f')]['id'];}return db[_0x9b29('0x2e')][_0x9b29('0x4b')]({'where':{'id':_0x3e9ff8['params']['id']}})[_0x9b29('0x28')](handleEntityNotFound(_0x1c37ad,null))[_0x9b29('0x28')](function(_0x478838){if(_0x478838){_0x3e9ff8[_0x9b29('0x4f')]['AccountId']=_0x478838['id'];_0x3e9ff8[_0x9b29('0x4f')][_0x9b29('0x50')]=integrations[_0x9b29('0x51')](_0x3e9ff8[_0x9b29('0x4f')][_0x9b29('0x52')],_0x3e9ff8[_0x9b29('0x4f')][_0x9b29('0x31')]);_0x3e9ff8[_0x9b29('0x4f')]['Descriptions']=integrations[_0x9b29('0x53')](_0x3e9ff8[_0x9b29('0x4f')]['channel'],_0x3e9ff8['body'][_0x9b29('0x31')]);return db[_0x9b29('0x4c')][_0x9b29('0x48')](_0x3e9ff8['body'],{'include':[{'model':db['FreshdeskField'],'as':_0x9b29('0x50')},{'model':db[_0x9b29('0x54')],'as':_0x9b29('0x55')}]});}return null;})[_0x9b29('0x28')](respondWithResult(_0x1c37ad,null))[_0x9b29('0x44')](handleError(_0x1c37ad,null));};exports['getFields']=function(_0x4248af,_0x4cd0bb,_0x48aa19){var _0x18eb00='';return db['FreshdeskAccount'][_0x9b29('0x4b')]({'where':{'id':_0x4248af[_0x9b29('0x46')]['id']},'attributes':['id',_0x9b29('0x56'),_0x9b29('0x57')]})[_0x9b29('0x28')](handleEntityNotFound(_0x4cd0bb,null))[_0x9b29('0x28')](function(_0x196bb1){if(_0x196bb1){_0x18eb00=_0x196bb1[_0x9b29('0x56')];var _0x5563f7=_0x18eb00[_0x9b29('0x58')](-0x1);if(_0x5563f7==='/'){_0x18eb00=_0x18eb00[_0x9b29('0x59')](0x0,_0x18eb00['lastIndexOf'](_0x5563f7));}return rp({'method':_0x9b29('0x5a'),'uri':util[_0x9b29('0x5b')](_0x9b29('0x5c'),_0x18eb00,_0x9b29('0x5d')),'headers':{'Authorization':util[_0x9b29('0x5b')](_0x9b29('0x5e'),new Buffer(util[_0x9b29('0x5b')](_0x9b29('0x5f'),_0x196bb1[_0x9b29('0x57')]))[_0x9b29('0x60')](_0x9b29('0x61')))},'json':!![]});}})[_0x9b29('0x28')](function(_0x514921){if(_0x514921){var _0x5d931b=[_0x9b29('0x62'),'subject',_0x9b29('0x63'),'description',_0x9b29('0x1b'),'priority',_0x9b29('0x64'),_0x9b29('0x65'),_0x9b29('0x66'),_0x9b29('0x64'),'company'];_[_0x9b29('0x67')](_0x514921,function(_0x2332e7){return _0x5d931b[_0x9b29('0x68')](_0x2332e7[_0x9b29('0x2a')])||!_0x2332e7[_0x9b29('0x69')]&&_0x2332e7[_0x9b29('0x31')]!==_0x9b29('0x6a')&&_0x2332e7[_0x9b29('0x31')]!==_0x9b29('0x6b');});return{'count':_0x514921[_0x9b29('0x38')],'rows':_['map'](_0x514921,function(_0x37e6f0){return{'id':_0x37e6f0['name'],'name':_0x37e6f0[_0x9b29('0x6c')],'custom':!_0x37e6f0['default'],'options':_0x37e6f0['choices']?_[_0x9b29('0x2d')](_0x37e6f0[_0x9b29('0x6d')],function(_0x10c151){return{'name':_[_0x9b29('0x6e')](_0x10c151),'value':_0x10c151};}):[]};})};}})['then'](respondWithResult(_0x4cd0bb,null))[_0x9b29('0x44')](function(_0x43cdf2){var _0x3a00fc=_0x4248af[_0x9b29('0x34')][_0x9b29('0x6f')]?0x1f4:_0x43cdf2[_0x9b29('0x70')]||0x1f4;logger['error'](_0x9b29('0x71'),_0x9b29('0x72'),_0x3a00fc,JSON[_0x9b29('0x73')](_0x43cdf2));delete _0x43cdf2[_0x9b29('0x2a')];if(_0x3a00fc===0x191){_0x3a00fc=0x190;}_0x4cd0bb['status'](_0x3a00fc)[_0x9b29('0x2b')](_0x4248af[_0x9b29('0x34')]['test']?{'message':'Wrong\x20credentials','statusCode':_0x43cdf2[_0x9b29('0x70')]}:_0x43cdf2);});};
\ No newline at end of file